1 1.1 matt /* RISC-V ELF specific backend routines. 2 1.9 christos Copyright (C) 2011-2026 Free Software Foundation, Inc. 3 1.1 matt 4 1.3 christos Contributed by Andrew Waterman (andrew (at) sifive.com). 5 1.1 matt Based on MIPS target. 6 1.1 matt 7 1.1 matt This file is part of BFD, the Binary File Descriptor library. 8 1.1 matt 9 1.1 matt This program is free software; you can redistribute it and/or modify 10 1.1 matt it under the terms of the GNU General Public License as published by 11 1.1 matt the Free Software Foundation; either version 3 of the License, or 12 1.1 matt (at your option) any later version. 13 1.1 matt 14 1.1 matt This program is distributed in the hope that it will be useful, 15 1.1 matt but WITHOUT ANY WARRANTY; without even the implied warranty of 16 1.1 matt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 1.1 matt GNU General Public License for more details. 18 1.1 matt 19 1.1 matt You should have received a copy of the GNU General Public License 20 1.3 christos along with this program; see the file COPYING3. If not, 21 1.3 christos see <http://www.gnu.org/licenses/>. */ 22 1.1 matt 23 1.1 matt #include "elf/common.h" 24 1.1 matt #include "elf/internal.h" 25 1.6 christos #include "opcode/riscv.h" 26 1.6 christos #include "cpu-riscv.h" 27 1.6 christos 28 1.6 christos #define RISCV_UNKNOWN_VERSION -1 29 1.1 matt 30 1.8 christos typedef enum 31 1.8 christos { 32 1.8 christos PLT_NORMAL = 0x0, /* Normal plts. */ 33 1.8 christos PLT_ZICFILP_UNLABELED = 0x1 /* Landing pad unlabeled plts. */ 34 1.8 christos } riscv_plt_type; 35 1.8 christos 36 1.7 christos struct riscv_elf_params 37 1.7 christos { 38 1.7 christos /* Whether to relax code sequences to GP-relative addressing. */ 39 1.7 christos bool relax_gp; 40 1.7 christos /* Whether to check if SUB_ULEB128 relocation has non-zero addend. */ 41 1.7 christos bool check_uleb128; 42 1.7 christos }; 43 1.7 christos 44 1.7 christos extern void riscv_elf32_set_options (struct bfd_link_info *, 45 1.7 christos struct riscv_elf_params *); 46 1.7 christos extern void riscv_elf64_set_options (struct bfd_link_info *, 47 1.7 christos struct riscv_elf_params *); 48 1.7 christos 49 1.2 matt extern reloc_howto_type * 50 1.9 christos riscv_reloc_name_lookup (bfd *, const char *) ATTRIBUTE_HIDDEN; 51 1.1 matt 52 1.2 matt extern reloc_howto_type * 53 1.9 christos riscv_reloc_type_lookup (bfd *, bfd_reloc_code_real_type) ATTRIBUTE_HIDDEN; 54 1.1 matt 55 1.2 matt extern reloc_howto_type * 56 1.9 christos riscv_elf_rtype_to_howto (bfd *, unsigned int r_type) ATTRIBUTE_HIDDEN; 57 1.5 christos 58 1.5 christos /* The information of architecture attribute. */ 59 1.5 christos struct riscv_subset_t 60 1.5 christos { 61 1.5 christos const char *name; 62 1.5 christos int major_version; 63 1.5 christos int minor_version; 64 1.5 christos struct riscv_subset_t *next; 65 1.5 christos }; 66 1.5 christos 67 1.5 christos typedef struct riscv_subset_t riscv_subset_t; 68 1.5 christos 69 1.6 christos typedef struct 70 1.6 christos { 71 1.5 christos riscv_subset_t *head; 72 1.5 christos riscv_subset_t *tail; 73 1.7 christos const char *arch_str; 74 1.5 christos } riscv_subset_list_t; 75 1.5 christos 76 1.5 christos extern void 77 1.5 christos riscv_release_subset_list (riscv_subset_list_t *); 78 1.5 christos 79 1.5 christos extern void 80 1.5 christos riscv_add_subset (riscv_subset_list_t *, 81 1.5 christos const char *, 82 1.9 christos int, int) ATTRIBUTE_HIDDEN; 83 1.5 christos 84 1.6 christos extern bool 85 1.5 christos riscv_lookup_subset (const riscv_subset_list_t *, 86 1.6 christos const char *, 87 1.9 christos riscv_subset_t **) ATTRIBUTE_HIDDEN; 88 1.5 christos 89 1.6 christos typedef struct 90 1.6 christos { 91 1.5 christos riscv_subset_list_t *subset_list; 92 1.5 christos void (*error_handler) (const char *, 93 1.5 christos ...) ATTRIBUTE_PRINTF_1; 94 1.5 christos unsigned *xlen; 95 1.6 christos enum riscv_spec_class *isa_spec; 96 1.6 christos bool check_unknown_prefixed_ext; 97 1.5 christos } riscv_parse_subset_t; 98 1.5 christos 99 1.6 christos extern bool 100 1.5 christos riscv_parse_subset (riscv_parse_subset_t *, 101 1.5 christos const char *); 102 1.5 christos 103 1.5 christos extern void 104 1.5 christos riscv_release_subset_list (riscv_subset_list_t *); 105 1.5 christos 106 1.5 christos extern char * 107 1.8 christos riscv_arch_str (unsigned, riscv_subset_list_t *, bool); 108 1.6 christos 109 1.6 christos extern size_t 110 1.9 christos riscv_estimate_digit (unsigned) ATTRIBUTE_HIDDEN; 111 1.6 christos 112 1.6 christos extern int 113 1.9 christos riscv_compare_subsets (const char *, const char *) ATTRIBUTE_HIDDEN; 114 1.6 christos 115 1.6 christos extern riscv_subset_list_t * 116 1.6 christos riscv_copy_subset_list (riscv_subset_list_t *); 117 1.6 christos 118 1.6 christos extern bool 119 1.6 christos riscv_update_subset (riscv_parse_subset_t *, const char *); 120 1.6 christos 121 1.6 christos extern bool 122 1.8 christos riscv_update_subset_norvc (riscv_parse_subset_t *); 123 1.8 christos 124 1.8 christos extern bool 125 1.6 christos riscv_subset_supports (riscv_parse_subset_t *, const char *); 126 1.6 christos 127 1.6 christos extern bool 128 1.6 christos riscv_multi_subset_supports (riscv_parse_subset_t *, enum riscv_insn_class); 129 1.6 christos 130 1.6 christos extern const char * 131 1.6 christos riscv_multi_subset_supports_ext (riscv_parse_subset_t *, enum riscv_insn_class); 132 1.6 christos 133 1.6 christos extern void 134 1.8 christos riscv_print_extensions (void); 135 1.8 christos 136 1.8 christos extern void 137 1.6 christos bfd_elf32_riscv_set_data_segment_info (struct bfd_link_info *, int *); 138 1.6 christos extern void 139 1.6 christos bfd_elf64_riscv_set_data_segment_info (struct bfd_link_info *, int *); 140 1.8 christos 141 1.8 christos extern bfd * 142 1.9 christos _bfd_riscv_elf_link_setup_gnu_properties (struct bfd_link_info *, uint32_t *) ATTRIBUTE_HIDDEN; 143 1.8 christos 144 1.8 christos extern enum elf_property_kind 145 1.8 christos _bfd_riscv_elf_parse_gnu_properties (bfd *, unsigned int, bfd_byte *, 146 1.9 christos unsigned int) ATTRIBUTE_HIDDEN; 147 1.8 christos 148 1.8 christos extern bool 149 1.8 christos _bfd_riscv_elf_merge_gnu_properties (struct bfd_link_info *, bfd *, 150 1.9 christos elf_property *, elf_property *, uint32_t) ATTRIBUTE_HIDDEN; 151 1.8 christos 152 1.8 christos #define elf_backend_parse_gnu_properties _bfd_riscv_elf_parse_gnu_properties 153