| 1 | /* IA-64 support for 64-bit ELF |
| 2 | Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc. |
| 3 | Contributed by David Mosberger-Tang <davidm@hpl.hp.com> |
| 4 | |
| 5 | This file is part of BFD, the Binary File Descriptor library. |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
| 20 | |
| 21 | #include "bfd.h" |
| 22 | #include "sysdep.h" |
| 23 | #include "libbfd.h" |
| 24 | #include "elf-bfd.h" |
| 25 | #include "opcode/ia64.h" |
| 26 | #include "elf/ia64.h" |
| 27 | |
| 28 | /* |
| 29 | * THE RULES for all the stuff the linker creates -- |
| 30 | * |
| 31 | * GOT Entries created in response to LTOFF or LTOFF_FPTR |
| 32 | * relocations. Dynamic relocs created for dynamic |
| 33 | * symbols in an application; REL relocs for locals |
| 34 | * in a shared library. |
| 35 | * |
| 36 | * FPTR The canonical function descriptor. Created for local |
| 37 | * symbols in applications. Descriptors for dynamic symbols |
| 38 | * and local symbols in shared libraries are created by |
| 39 | * ld.so. Thus there are no dynamic relocs against these |
| 40 | * objects. The FPTR relocs for such _are_ passed through |
| 41 | * to the dynamic relocation tables. |
| 42 | * |
| 43 | * FULL_PLT Created for a PCREL21B relocation against a dynamic symbol. |
| 44 | * Requires the creation of a PLTOFF entry. This does not |
| 45 | * require any dynamic relocations. |
| 46 | * |
| 47 | * PLTOFF Created by PLTOFF relocations. For local symbols, this |
| 48 | * is an alternate function descriptor, and in shared libraries |
| 49 | * requires two REL relocations. Note that this cannot be |
| 50 | * transformed into an FPTR relocation, since it must be in |
| 51 | * range of the GP. For dynamic symbols, this is a function |
| 52 | * descriptor for a MIN_PLT entry, and requires one IPLT reloc. |
| 53 | * |
| 54 | * MIN_PLT Created by PLTOFF entries against dynamic symbols. This |
| 55 | * does not reqire dynamic relocations. |
| 56 | */ |
| 57 | |
| 58 | #define USE_RELA /* we want RELA relocs, not REL */ |
| 59 | |
| 60 | #define NELEMS(a) ((int) (sizeof (a) / sizeof ((a)[0]))) |
| 61 | |
| 62 | typedef struct bfd_hash_entry *(*new_hash_entry_func) |
| 63 | PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); |
| 64 | |
| 65 | /* In dynamically (linker-) created sections, we generally need to keep track |
| 66 | of the place a symbol or expression got allocated to. This is done via hash |
| 67 | tables that store entries of the following type. */ |
| 68 | |
| 69 | struct elfNN_ia64_dyn_sym_info |
| 70 | { |
| 71 | /* The addend for which this entry is relevant. */ |
| 72 | bfd_vma addend; |
| 73 | |
| 74 | /* Next addend in the list. */ |
| 75 | struct elfNN_ia64_dyn_sym_info *next; |
| 76 | |
| 77 | bfd_vma got_offset; |
| 78 | bfd_vma fptr_offset; |
| 79 | bfd_vma pltoff_offset; |
| 80 | bfd_vma plt_offset; |
| 81 | bfd_vma plt2_offset; |
| 82 | |
| 83 | /* The symbol table entry, if any, that this was derrived from. */ |
| 84 | struct elf_link_hash_entry *h; |
| 85 | |
| 86 | /* Used to count non-got, non-plt relocations for delayed sizing |
| 87 | of relocation sections. */ |
| 88 | struct elfNN_ia64_dyn_reloc_entry |
| 89 | { |
| 90 | struct elfNN_ia64_dyn_reloc_entry *next; |
| 91 | asection *srel; |
| 92 | int type; |
| 93 | int count; |
| 94 | } *reloc_entries; |
| 95 | |
| 96 | /* True when the section contents have been updated. */ |
| 97 | unsigned got_done : 1; |
| 98 | unsigned fptr_done : 1; |
| 99 | unsigned pltoff_done : 1; |
| 100 | |
| 101 | /* True for the different kinds of linker data we want created. */ |
| 102 | unsigned want_got : 1; |
| 103 | unsigned want_fptr : 1; |
| 104 | unsigned want_ltoff_fptr : 1; |
| 105 | unsigned want_plt : 1; |
| 106 | unsigned want_plt2 : 1; |
| 107 | unsigned want_pltoff : 1; |
| 108 | }; |
| 109 | |
| 110 | struct elfNN_ia64_local_hash_entry |
| 111 | { |
| 112 | struct bfd_hash_entry root; |
| 113 | struct elfNN_ia64_dyn_sym_info *info; |
| 114 | }; |
| 115 | |
| 116 | struct elfNN_ia64_local_hash_table |
| 117 | { |
| 118 | struct bfd_hash_table root; |
| 119 | /* No additional fields for now. */ |
| 120 | }; |
| 121 | |
| 122 | struct elfNN_ia64_link_hash_entry |
| 123 | { |
| 124 | struct elf_link_hash_entry root; |
| 125 | struct elfNN_ia64_dyn_sym_info *info; |
| 126 | }; |
| 127 | |
| 128 | struct elfNN_ia64_link_hash_table |
| 129 | { |
| 130 | /* The main hash table */ |
| 131 | struct elf_link_hash_table root; |
| 132 | |
| 133 | asection *got_sec; /* the linkage table section (or NULL) */ |
| 134 | asection *rel_got_sec; /* dynamic relocation section for same */ |
| 135 | asection *fptr_sec; /* function descriptor table (or NULL) */ |
| 136 | asection *plt_sec; /* the primary plt section (or NULL) */ |
| 137 | asection *pltoff_sec; /* private descriptors for plt (or NULL) */ |
| 138 | asection *rel_pltoff_sec; /* dynamic relocation section for same */ |
| 139 | |
| 140 | bfd_size_type minplt_entries; /* number of minplt entries */ |
| 141 | |
| 142 | struct elfNN_ia64_local_hash_table loc_hash_table; |
| 143 | }; |
| 144 | |
| 145 | #define elfNN_ia64_hash_table(p) \ |
| 146 | ((struct elfNN_ia64_link_hash_table *) ((p)->hash)) |
| 147 | |
| 148 | static bfd_reloc_status_type elfNN_ia64_reloc |
| 149 | PARAMS ((bfd *abfd, arelent *reloc, asymbol *sym, PTR data, |
| 150 | asection *input_section, bfd *output_bfd, char **error_message)); |
| 151 | static reloc_howto_type * lookup_howto |
| 152 | PARAMS ((unsigned int rtype)); |
| 153 | static reloc_howto_type *elfNN_ia64_reloc_type_lookup |
| 154 | PARAMS ((bfd *abfd, bfd_reloc_code_real_type bfd_code)); |
| 155 | static void elfNN_ia64_info_to_howto |
| 156 | PARAMS ((bfd *abfd, arelent *bfd_reloc, ElfNN_Internal_Rela *elf_reloc)); |
| 157 | static boolean elfNN_ia64_relax_section |
| 158 | PARAMS((bfd *abfd, asection *sec, struct bfd_link_info *link_info, |
| 159 | boolean *again)); |
| 160 | static boolean is_unwind_section_name |
| 161 | PARAMS ((const char *)); |
| 162 | static boolean elfNN_ia64_section_from_shdr |
| 163 | PARAMS ((bfd *, ElfNN_Internal_Shdr *, char *)); |
| 164 | static boolean elfNN_ia64_fake_sections |
| 165 | PARAMS ((bfd *abfd, ElfNN_Internal_Shdr *hdr, asection *sec)); |
| 166 | static void elfNN_ia64_final_write_processing |
| 167 | PARAMS ((bfd *abfd, boolean linker)); |
| 168 | static boolean elfNN_ia64_add_symbol_hook |
| 169 | PARAMS ((bfd *abfd, struct bfd_link_info *info, const Elf_Internal_Sym *sym, |
| 170 | const char **namep, flagword *flagsp, asection **secp, |
| 171 | bfd_vma *valp)); |
| 172 | static boolean elfNN_ia64_aix_vec |
| 173 | PARAMS ((const bfd_target *vec)); |
| 174 | static boolean elfNN_ia64_aix_add_symbol_hook |
| 175 | PARAMS ((bfd *abfd, struct bfd_link_info *info, const Elf_Internal_Sym *sym, |
| 176 | const char **namep, flagword *flagsp, asection **secp, |
| 177 | bfd_vma *valp)); |
| 178 | static boolean elfNN_ia64_aix_link_add_symbols |
| 179 | PARAMS ((bfd *abfd, struct bfd_link_info *info)); |
| 180 | static int elfNN_ia64_additional_program_headers |
| 181 | PARAMS ((bfd *abfd)); |
| 182 | static boolean elfNN_ia64_is_local_label_name |
| 183 | PARAMS ((bfd *abfd, const char *name)); |
| 184 | static boolean elfNN_ia64_dynamic_symbol_p |
| 185 | PARAMS ((struct elf_link_hash_entry *h, struct bfd_link_info *info)); |
| 186 | static boolean elfNN_ia64_local_hash_table_init |
| 187 | PARAMS ((struct elfNN_ia64_local_hash_table *ht, bfd *abfd, |
| 188 | new_hash_entry_func new)); |
| 189 | static struct bfd_hash_entry *elfNN_ia64_new_loc_hash_entry |
| 190 | PARAMS ((struct bfd_hash_entry *entry, struct bfd_hash_table *table, |
| 191 | const char *string)); |
| 192 | static struct bfd_hash_entry *elfNN_ia64_new_elf_hash_entry |
| 193 | PARAMS ((struct bfd_hash_entry *entry, struct bfd_hash_table *table, |
| 194 | const char *string)); |
| 195 | static struct bfd_link_hash_table *elfNN_ia64_hash_table_create |
| 196 | PARAMS ((bfd *abfd)); |
| 197 | static struct elfNN_ia64_local_hash_entry *elfNN_ia64_local_hash_lookup |
| 198 | PARAMS ((struct elfNN_ia64_local_hash_table *table, const char *string, |
| 199 | boolean create, boolean copy)); |
| 200 | static void elfNN_ia64_dyn_sym_traverse |
| 201 | PARAMS ((struct elfNN_ia64_link_hash_table *ia64_info, |
| 202 | boolean (*func) (struct elfNN_ia64_dyn_sym_info *, PTR), |
| 203 | PTR info)); |
| 204 | static boolean elfNN_ia64_create_dynamic_sections |
| 205 | PARAMS ((bfd *abfd, struct bfd_link_info *info)); |
| 206 | static struct elfNN_ia64_dyn_sym_info * get_dyn_sym_info |
| 207 | PARAMS ((struct elfNN_ia64_link_hash_table *ia64_info, |
| 208 | struct elf_link_hash_entry *h, |
| 209 | bfd *abfd, const Elf_Internal_Rela *rel, boolean create)); |
| 210 | static asection *get_got |
| 211 | PARAMS ((bfd *abfd, struct bfd_link_info *info, |
| 212 | struct elfNN_ia64_link_hash_table *ia64_info)); |
| 213 | static asection *get_fptr |
| 214 | PARAMS ((bfd *abfd, struct bfd_link_info *info, |
| 215 | struct elfNN_ia64_link_hash_table *ia64_info)); |
| 216 | static asection *get_pltoff |
| 217 | PARAMS ((bfd *abfd, struct bfd_link_info *info, |
| 218 | struct elfNN_ia64_link_hash_table *ia64_info)); |
| 219 | static asection *get_reloc_section |
| 220 | PARAMS ((bfd *abfd, struct elfNN_ia64_link_hash_table *ia64_info, |
| 221 | asection *sec, boolean create)); |
| 222 | static boolean count_dyn_reloc |
| 223 | PARAMS ((bfd *abfd, struct elfNN_ia64_dyn_sym_info *dyn_i, |
| 224 | asection *srel, int type)); |
| 225 | static boolean elfNN_ia64_check_relocs |
| 226 | PARAMS ((bfd *abfd, struct bfd_link_info *info, asection *sec, |
| 227 | const Elf_Internal_Rela *relocs)); |
| 228 | static boolean elfNN_ia64_adjust_dynamic_symbol |
| 229 | PARAMS ((struct bfd_link_info *info, struct elf_link_hash_entry *h)); |
| 230 | static unsigned long global_sym_index |
| 231 | PARAMS ((struct elf_link_hash_entry *h)); |
| 232 | static boolean allocate_fptr |
| 233 | PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data)); |
| 234 | static boolean allocate_global_data_got |
| 235 | PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data)); |
| 236 | static boolean allocate_global_fptr_got |
| 237 | PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data)); |
| 238 | static boolean allocate_local_got |
| 239 | PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data)); |
| 240 | static boolean allocate_pltoff_entries |
| 241 | PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data)); |
| 242 | static boolean allocate_plt_entries |
| 243 | PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data)); |
| 244 | static boolean allocate_plt2_entries |
| 245 | PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data)); |
| 246 | static boolean allocate_dynrel_entries |
| 247 | PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data)); |
| 248 | static boolean elfNN_ia64_size_dynamic_sections |
| 249 | PARAMS ((bfd *output_bfd, struct bfd_link_info *info)); |
| 250 | static bfd_reloc_status_type elfNN_ia64_install_value |
| 251 | PARAMS ((bfd *abfd, bfd_byte *hit_addr, bfd_vma val, unsigned int r_type)); |
| 252 | static void elfNN_ia64_install_dyn_reloc |
| 253 | PARAMS ((bfd *abfd, struct bfd_link_info *info, asection *sec, |
| 254 | asection *srel, bfd_vma offset, unsigned int type, |
| 255 | long dynindx, bfd_vma addend)); |
| 256 | static bfd_vma set_got_entry |
| 257 | PARAMS ((bfd *abfd, struct bfd_link_info *info, |
| 258 | struct elfNN_ia64_dyn_sym_info *dyn_i, long dynindx, |
| 259 | bfd_vma addend, bfd_vma value, unsigned int dyn_r_type)); |
| 260 | static bfd_vma set_fptr_entry |
| 261 | PARAMS ((bfd *abfd, struct bfd_link_info *info, |
| 262 | struct elfNN_ia64_dyn_sym_info *dyn_i, |
| 263 | bfd_vma value)); |
| 264 | static bfd_vma set_pltoff_entry |
| 265 | PARAMS ((bfd *abfd, struct bfd_link_info *info, |
| 266 | struct elfNN_ia64_dyn_sym_info *dyn_i, |
| 267 | bfd_vma value, boolean)); |
| 268 | static boolean elfNN_ia64_final_link |
| 269 | PARAMS ((bfd *abfd, struct bfd_link_info *info)); |
| 270 | static boolean elfNN_ia64_relocate_section |
| 271 | PARAMS ((bfd *output_bfd, struct bfd_link_info *info, bfd *input_bfd, |
| 272 | asection *input_section, bfd_byte *contents, |
| 273 | Elf_Internal_Rela *relocs, Elf_Internal_Sym *local_syms, |
| 274 | asection **local_sections)); |
| 275 | static boolean elfNN_ia64_finish_dynamic_symbol |
| 276 | PARAMS ((bfd *output_bfd, struct bfd_link_info *info, |
| 277 | struct elf_link_hash_entry *h, Elf_Internal_Sym *sym)); |
| 278 | static boolean elfNN_ia64_finish_dynamic_sections |
| 279 | PARAMS ((bfd *abfd, struct bfd_link_info *info)); |
| 280 | static boolean elfNN_ia64_set_private_flags |
| 281 | PARAMS ((bfd *abfd, flagword flags)); |
| 282 | static boolean elfNN_ia64_copy_private_bfd_data |
| 283 | PARAMS ((bfd *ibfd, bfd *obfd)); |
| 284 | static boolean elfNN_ia64_merge_private_bfd_data |
| 285 | PARAMS ((bfd *ibfd, bfd *obfd)); |
| 286 | static boolean elfNN_ia64_print_private_bfd_data |
| 287 | PARAMS ((bfd *abfd, PTR ptr)); |
| 288 | \f |
| 289 | /* ia64-specific relocation */ |
| 290 | |
| 291 | /* Perform a relocation. Not much to do here as all the hard work is |
| 292 | done in elfNN_ia64_final_link_relocate. */ |
| 293 | static bfd_reloc_status_type |
| 294 | elfNN_ia64_reloc (abfd, reloc, sym, data, input_section, |
| 295 | output_bfd, error_message) |
| 296 | bfd *abfd ATTRIBUTE_UNUSED; |
| 297 | arelent *reloc; |
| 298 | asymbol *sym ATTRIBUTE_UNUSED; |
| 299 | PTR data ATTRIBUTE_UNUSED; |
| 300 | asection *input_section; |
| 301 | bfd *output_bfd; |
| 302 | char **error_message; |
| 303 | { |
| 304 | if (output_bfd) |
| 305 | { |
| 306 | reloc->address += input_section->output_offset; |
| 307 | return bfd_reloc_ok; |
| 308 | } |
| 309 | *error_message = "Unsupported call to elfNN_ia64_reloc"; |
| 310 | return bfd_reloc_notsupported; |
| 311 | } |
| 312 | |
| 313 | #define IA64_HOWTO(TYPE, NAME, SIZE, PCREL, IN) \ |
| 314 | HOWTO (TYPE, 0, SIZE, 0, PCREL, 0, complain_overflow_signed, \ |
| 315 | elfNN_ia64_reloc, NAME, false, 0, 0, IN) |
| 316 | |
| 317 | /* This table has to be sorted according to increasing number of the |
| 318 | TYPE field. */ |
| 319 | static reloc_howto_type ia64_howto_table[] = |
| 320 | { |
| 321 | IA64_HOWTO (R_IA64_NONE, "NONE", 0, false, true), |
| 322 | |
| 323 | IA64_HOWTO (R_IA64_IMM14, "IMM14", 0, false, true), |
| 324 | IA64_HOWTO (R_IA64_IMM22, "IMM22", 0, false, true), |
| 325 | IA64_HOWTO (R_IA64_IMM64, "IMM64", 0, false, true), |
| 326 | IA64_HOWTO (R_IA64_DIR32MSB, "DIR32MSB", 2, false, true), |
| 327 | IA64_HOWTO (R_IA64_DIR32LSB, "DIR32LSB", 2, false, true), |
| 328 | IA64_HOWTO (R_IA64_DIR64MSB, "DIR64MSB", 4, false, true), |
| 329 | IA64_HOWTO (R_IA64_DIR64LSB, "DIR64LSB", 4, false, true), |
| 330 | |
| 331 | IA64_HOWTO (R_IA64_GPREL22, "GPREL22", 0, false, true), |
| 332 | IA64_HOWTO (R_IA64_GPREL64I, "GPREL64I", 0, false, true), |
| 333 | IA64_HOWTO (R_IA64_GPREL32MSB, "GPREL32MSB", 2, false, true), |
| 334 | IA64_HOWTO (R_IA64_GPREL32LSB, "GPREL32LSB", 2, false, true), |
| 335 | IA64_HOWTO (R_IA64_GPREL64MSB, "GPREL64MSB", 4, false, true), |
| 336 | IA64_HOWTO (R_IA64_GPREL64LSB, "GPREL64LSB", 4, false, true), |
| 337 | |
| 338 | IA64_HOWTO (R_IA64_LTOFF22, "LTOFF22", 0, false, true), |
| 339 | IA64_HOWTO (R_IA64_LTOFF64I, "LTOFF64I", 0, false, true), |
| 340 | |
| 341 | IA64_HOWTO (R_IA64_PLTOFF22, "PLTOFF22", 0, false, true), |
| 342 | IA64_HOWTO (R_IA64_PLTOFF64I, "PLTOFF64I", 0, false, true), |
| 343 | IA64_HOWTO (R_IA64_PLTOFF64MSB, "PLTOFF64MSB", 4, false, true), |
| 344 | IA64_HOWTO (R_IA64_PLTOFF64LSB, "PLTOFF64LSB", 4, false, true), |
| 345 | |
| 346 | IA64_HOWTO (R_IA64_FPTR64I, "FPTR64I", 0, false, true), |
| 347 | IA64_HOWTO (R_IA64_FPTR32MSB, "FPTR32MSB", 2, false, true), |
| 348 | IA64_HOWTO (R_IA64_FPTR32LSB, "FPTR32LSB", 2, false, true), |
| 349 | IA64_HOWTO (R_IA64_FPTR64MSB, "FPTR64MSB", 4, false, true), |
| 350 | IA64_HOWTO (R_IA64_FPTR64LSB, "FPTR64LSB", 4, false, true), |
| 351 | |
| 352 | IA64_HOWTO (R_IA64_PCREL60B, "PCREL60B", 0, true, true), |
| 353 | IA64_HOWTO (R_IA64_PCREL21B, "PCREL21B", 0, true, true), |
| 354 | IA64_HOWTO (R_IA64_PCREL21M, "PCREL21M", 0, true, true), |
| 355 | IA64_HOWTO (R_IA64_PCREL21F, "PCREL21F", 0, true, true), |
| 356 | IA64_HOWTO (R_IA64_PCREL32MSB, "PCREL32MSB", 2, true, true), |
| 357 | IA64_HOWTO (R_IA64_PCREL32LSB, "PCREL32LSB", 2, true, true), |
| 358 | IA64_HOWTO (R_IA64_PCREL64MSB, "PCREL64MSB", 4, true, true), |
| 359 | IA64_HOWTO (R_IA64_PCREL64LSB, "PCREL64LSB", 4, true, true), |
| 360 | |
| 361 | IA64_HOWTO (R_IA64_LTOFF_FPTR22, "LTOFF_FPTR22", 0, false, true), |
| 362 | IA64_HOWTO (R_IA64_LTOFF_FPTR64I, "LTOFF_FPTR64I", 0, false, true), |
| 363 | IA64_HOWTO (R_IA64_LTOFF_FPTR32MSB, "LTOFF_FPTR32MSB", 2, false, true), |
| 364 | IA64_HOWTO (R_IA64_LTOFF_FPTR32LSB, "LTOFF_FPTR32LSB", 2, false, true), |
| 365 | IA64_HOWTO (R_IA64_LTOFF_FPTR64MSB, "LTOFF_FPTR64MSB", 4, false, true), |
| 366 | IA64_HOWTO (R_IA64_LTOFF_FPTR64LSB, "LTOFF_FPTR64LSB", 4, false, true), |
| 367 | |
| 368 | IA64_HOWTO (R_IA64_SEGREL32MSB, "SEGREL32MSB", 2, false, true), |
| 369 | IA64_HOWTO (R_IA64_SEGREL32LSB, "SEGREL32LSB", 2, false, true), |
| 370 | IA64_HOWTO (R_IA64_SEGREL64MSB, "SEGREL64MSB", 4, false, true), |
| 371 | IA64_HOWTO (R_IA64_SEGREL64LSB, "SEGREL64LSB", 4, false, true), |
| 372 | |
| 373 | IA64_HOWTO (R_IA64_SECREL32MSB, "SECREL32MSB", 2, false, true), |
| 374 | IA64_HOWTO (R_IA64_SECREL32LSB, "SECREL32LSB", 2, false, true), |
| 375 | IA64_HOWTO (R_IA64_SECREL64MSB, "SECREL64MSB", 4, false, true), |
| 376 | IA64_HOWTO (R_IA64_SECREL64LSB, "SECREL64LSB", 4, false, true), |
| 377 | |
| 378 | IA64_HOWTO (R_IA64_REL32MSB, "REL32MSB", 2, false, true), |
| 379 | IA64_HOWTO (R_IA64_REL32LSB, "REL32LSB", 2, false, true), |
| 380 | IA64_HOWTO (R_IA64_REL64MSB, "REL64MSB", 4, false, true), |
| 381 | IA64_HOWTO (R_IA64_REL64LSB, "REL64LSB", 4, false, true), |
| 382 | |
| 383 | IA64_HOWTO (R_IA64_LTV32MSB, "LTV32MSB", 2, false, true), |
| 384 | IA64_HOWTO (R_IA64_LTV32LSB, "LTV32LSB", 2, false, true), |
| 385 | IA64_HOWTO (R_IA64_LTV64MSB, "LTV64MSB", 4, false, true), |
| 386 | IA64_HOWTO (R_IA64_LTV64LSB, "LTV64LSB", 4, false, true), |
| 387 | |
| 388 | IA64_HOWTO (R_IA64_PCREL21BI, "PCREL21BI", 0, true, true), |
| 389 | IA64_HOWTO (R_IA64_PCREL22, "PCREL22", 0, true, true), |
| 390 | IA64_HOWTO (R_IA64_PCREL64I, "PCREL64I", 0, true, true), |
| 391 | |
| 392 | IA64_HOWTO (R_IA64_IPLTMSB, "IPLTMSB", 4, false, true), |
| 393 | IA64_HOWTO (R_IA64_IPLTLSB, "IPLTLSB", 4, false, true), |
| 394 | IA64_HOWTO (R_IA64_COPY, "COPY", 4, false, true), |
| 395 | IA64_HOWTO (R_IA64_LTOFF22X, "LTOFF22X", 0, false, true), |
| 396 | IA64_HOWTO (R_IA64_LDXMOV, "LDXMOV", 0, false, true), |
| 397 | |
| 398 | IA64_HOWTO (R_IA64_TPREL22, "TPREL22", 0, false, false), |
| 399 | IA64_HOWTO (R_IA64_TPREL64MSB, "TPREL64MSB", 8, false, false), |
| 400 | IA64_HOWTO (R_IA64_TPREL64LSB, "TPREL64LSB", 8, false, false), |
| 401 | IA64_HOWTO (R_IA64_LTOFF_TP22, "LTOFF_TP22", 0, false, false), |
| 402 | }; |
| 403 | |
| 404 | static unsigned char elf_code_to_howto_index[R_IA64_MAX_RELOC_CODE + 1]; |
| 405 | |
| 406 | /* Given a BFD reloc type, return the matching HOWTO structure. */ |
| 407 | |
| 408 | static reloc_howto_type* |
| 409 | lookup_howto (rtype) |
| 410 | unsigned int rtype; |
| 411 | { |
| 412 | static int inited = 0; |
| 413 | int i; |
| 414 | |
| 415 | if (!inited) |
| 416 | { |
| 417 | inited = 1; |
| 418 | |
| 419 | memset (elf_code_to_howto_index, 0xff, sizeof (elf_code_to_howto_index)); |
| 420 | for (i = 0; i < NELEMS (ia64_howto_table); ++i) |
| 421 | elf_code_to_howto_index[ia64_howto_table[i].type] = i; |
| 422 | } |
| 423 | |
| 424 | BFD_ASSERT (rtype <= R_IA64_MAX_RELOC_CODE); |
| 425 | i = elf_code_to_howto_index[rtype]; |
| 426 | if (i >= NELEMS (ia64_howto_table)) |
| 427 | return 0; |
| 428 | return ia64_howto_table + i; |
| 429 | } |
| 430 | |
| 431 | static reloc_howto_type* |
| 432 | elfNN_ia64_reloc_type_lookup (abfd, bfd_code) |
| 433 | bfd *abfd ATTRIBUTE_UNUSED; |
| 434 | bfd_reloc_code_real_type bfd_code; |
| 435 | { |
| 436 | unsigned int rtype; |
| 437 | |
| 438 | switch (bfd_code) |
| 439 | { |
| 440 | case BFD_RELOC_NONE: rtype = R_IA64_NONE; break; |
| 441 | |
| 442 | case BFD_RELOC_IA64_IMM14: rtype = R_IA64_IMM14; break; |
| 443 | case BFD_RELOC_IA64_IMM22: rtype = R_IA64_IMM22; break; |
| 444 | case BFD_RELOC_IA64_IMM64: rtype = R_IA64_IMM64; break; |
| 445 | |
| 446 | case BFD_RELOC_IA64_DIR32MSB: rtype = R_IA64_DIR32MSB; break; |
| 447 | case BFD_RELOC_IA64_DIR32LSB: rtype = R_IA64_DIR32LSB; break; |
| 448 | case BFD_RELOC_IA64_DIR64MSB: rtype = R_IA64_DIR64MSB; break; |
| 449 | case BFD_RELOC_IA64_DIR64LSB: rtype = R_IA64_DIR64LSB; break; |
| 450 | |
| 451 | case BFD_RELOC_IA64_GPREL22: rtype = R_IA64_GPREL22; break; |
| 452 | case BFD_RELOC_IA64_GPREL64I: rtype = R_IA64_GPREL64I; break; |
| 453 | case BFD_RELOC_IA64_GPREL32MSB: rtype = R_IA64_GPREL32MSB; break; |
| 454 | case BFD_RELOC_IA64_GPREL32LSB: rtype = R_IA64_GPREL32LSB; break; |
| 455 | case BFD_RELOC_IA64_GPREL64MSB: rtype = R_IA64_GPREL64MSB; break; |
| 456 | case BFD_RELOC_IA64_GPREL64LSB: rtype = R_IA64_GPREL64LSB; break; |
| 457 | |
| 458 | case BFD_RELOC_IA64_LTOFF22: rtype = R_IA64_LTOFF22; break; |
| 459 | case BFD_RELOC_IA64_LTOFF64I: rtype = R_IA64_LTOFF64I; break; |
| 460 | |
| 461 | case BFD_RELOC_IA64_PLTOFF22: rtype = R_IA64_PLTOFF22; break; |
| 462 | case BFD_RELOC_IA64_PLTOFF64I: rtype = R_IA64_PLTOFF64I; break; |
| 463 | case BFD_RELOC_IA64_PLTOFF64MSB: rtype = R_IA64_PLTOFF64MSB; break; |
| 464 | case BFD_RELOC_IA64_PLTOFF64LSB: rtype = R_IA64_PLTOFF64LSB; break; |
| 465 | case BFD_RELOC_IA64_FPTR64I: rtype = R_IA64_FPTR64I; break; |
| 466 | case BFD_RELOC_IA64_FPTR32MSB: rtype = R_IA64_FPTR32MSB; break; |
| 467 | case BFD_RELOC_IA64_FPTR32LSB: rtype = R_IA64_FPTR32LSB; break; |
| 468 | case BFD_RELOC_IA64_FPTR64MSB: rtype = R_IA64_FPTR64MSB; break; |
| 469 | case BFD_RELOC_IA64_FPTR64LSB: rtype = R_IA64_FPTR64LSB; break; |
| 470 | |
| 471 | case BFD_RELOC_IA64_PCREL21B: rtype = R_IA64_PCREL21B; break; |
| 472 | case BFD_RELOC_IA64_PCREL21BI: rtype = R_IA64_PCREL21BI; break; |
| 473 | case BFD_RELOC_IA64_PCREL21M: rtype = R_IA64_PCREL21M; break; |
| 474 | case BFD_RELOC_IA64_PCREL21F: rtype = R_IA64_PCREL21F; break; |
| 475 | case BFD_RELOC_IA64_PCREL22: rtype = R_IA64_PCREL22; break; |
| 476 | case BFD_RELOC_IA64_PCREL60B: rtype = R_IA64_PCREL60B; break; |
| 477 | case BFD_RELOC_IA64_PCREL64I: rtype = R_IA64_PCREL64I; break; |
| 478 | case BFD_RELOC_IA64_PCREL32MSB: rtype = R_IA64_PCREL32MSB; break; |
| 479 | case BFD_RELOC_IA64_PCREL32LSB: rtype = R_IA64_PCREL32LSB; break; |
| 480 | case BFD_RELOC_IA64_PCREL64MSB: rtype = R_IA64_PCREL64MSB; break; |
| 481 | case BFD_RELOC_IA64_PCREL64LSB: rtype = R_IA64_PCREL64LSB; break; |
| 482 | |
| 483 | case BFD_RELOC_IA64_LTOFF_FPTR22: rtype = R_IA64_LTOFF_FPTR22; break; |
| 484 | case BFD_RELOC_IA64_LTOFF_FPTR64I: rtype = R_IA64_LTOFF_FPTR64I; break; |
| 485 | case BFD_RELOC_IA64_LTOFF_FPTR32MSB: rtype = R_IA64_LTOFF_FPTR32MSB; break; |
| 486 | case BFD_RELOC_IA64_LTOFF_FPTR32LSB: rtype = R_IA64_LTOFF_FPTR32LSB; break; |
| 487 | case BFD_RELOC_IA64_LTOFF_FPTR64MSB: rtype = R_IA64_LTOFF_FPTR64MSB; break; |
| 488 | case BFD_RELOC_IA64_LTOFF_FPTR64LSB: rtype = R_IA64_LTOFF_FPTR64LSB; break; |
| 489 | |
| 490 | case BFD_RELOC_IA64_SEGREL32MSB: rtype = R_IA64_SEGREL32MSB; break; |
| 491 | case BFD_RELOC_IA64_SEGREL32LSB: rtype = R_IA64_SEGREL32LSB; break; |
| 492 | case BFD_RELOC_IA64_SEGREL64MSB: rtype = R_IA64_SEGREL64MSB; break; |
| 493 | case BFD_RELOC_IA64_SEGREL64LSB: rtype = R_IA64_SEGREL64LSB; break; |
| 494 | |
| 495 | case BFD_RELOC_IA64_SECREL32MSB: rtype = R_IA64_SECREL32MSB; break; |
| 496 | case BFD_RELOC_IA64_SECREL32LSB: rtype = R_IA64_SECREL32LSB; break; |
| 497 | case BFD_RELOC_IA64_SECREL64MSB: rtype = R_IA64_SECREL64MSB; break; |
| 498 | case BFD_RELOC_IA64_SECREL64LSB: rtype = R_IA64_SECREL64LSB; break; |
| 499 | |
| 500 | case BFD_RELOC_IA64_REL32MSB: rtype = R_IA64_REL32MSB; break; |
| 501 | case BFD_RELOC_IA64_REL32LSB: rtype = R_IA64_REL32LSB; break; |
| 502 | case BFD_RELOC_IA64_REL64MSB: rtype = R_IA64_REL64MSB; break; |
| 503 | case BFD_RELOC_IA64_REL64LSB: rtype = R_IA64_REL64LSB; break; |
| 504 | |
| 505 | case BFD_RELOC_IA64_LTV32MSB: rtype = R_IA64_LTV32MSB; break; |
| 506 | case BFD_RELOC_IA64_LTV32LSB: rtype = R_IA64_LTV32LSB; break; |
| 507 | case BFD_RELOC_IA64_LTV64MSB: rtype = R_IA64_LTV64MSB; break; |
| 508 | case BFD_RELOC_IA64_LTV64LSB: rtype = R_IA64_LTV64LSB; break; |
| 509 | |
| 510 | case BFD_RELOC_IA64_IPLTMSB: rtype = R_IA64_IPLTMSB; break; |
| 511 | case BFD_RELOC_IA64_IPLTLSB: rtype = R_IA64_IPLTLSB; break; |
| 512 | case BFD_RELOC_IA64_COPY: rtype = R_IA64_COPY; break; |
| 513 | case BFD_RELOC_IA64_LTOFF22X: rtype = R_IA64_LTOFF22X; break; |
| 514 | case BFD_RELOC_IA64_LDXMOV: rtype = R_IA64_LDXMOV; break; |
| 515 | |
| 516 | case BFD_RELOC_IA64_TPREL22: rtype = R_IA64_TPREL22; break; |
| 517 | case BFD_RELOC_IA64_TPREL64MSB: rtype = R_IA64_TPREL64MSB; break; |
| 518 | case BFD_RELOC_IA64_TPREL64LSB: rtype = R_IA64_TPREL64LSB; break; |
| 519 | case BFD_RELOC_IA64_LTOFF_TP22: rtype = R_IA64_LTOFF_TP22; break; |
| 520 | |
| 521 | default: return 0; |
| 522 | } |
| 523 | return lookup_howto (rtype); |
| 524 | } |
| 525 | |
| 526 | /* Given a ELF reloc, return the matching HOWTO structure. */ |
| 527 | |
| 528 | static void |
| 529 | elfNN_ia64_info_to_howto (abfd, bfd_reloc, elf_reloc) |
| 530 | bfd *abfd ATTRIBUTE_UNUSED; |
| 531 | arelent *bfd_reloc; |
| 532 | ElfNN_Internal_Rela *elf_reloc; |
| 533 | { |
| 534 | bfd_reloc->howto = lookup_howto (ELFNN_R_TYPE (elf_reloc->r_info)); |
| 535 | } |
| 536 | \f |
| 537 | #define PLT_HEADER_SIZE (3 * 16) |
| 538 | #define PLT_MIN_ENTRY_SIZE (1 * 16) |
| 539 | #define PLT_FULL_ENTRY_SIZE (2 * 16) |
| 540 | #define PLT_RESERVED_WORDS 3 |
| 541 | |
| 542 | static const bfd_byte plt_header[PLT_HEADER_SIZE] = |
| 543 | { |
| 544 | 0x0b, 0x10, 0x00, 0x1c, 0x00, 0x21, /* [MMI] mov r2=r14;; */ |
| 545 | 0xe0, 0x00, 0x08, 0x00, 0x48, 0x00, /* addl r14=0,r2 */ |
| 546 | 0x00, 0x00, 0x04, 0x00, /* nop.i 0x0;; */ |
| 547 | 0x0b, 0x80, 0x20, 0x1c, 0x18, 0x14, /* [MMI] ld8 r16=[r14],8;; */ |
| 548 | 0x10, 0x41, 0x38, 0x30, 0x28, 0x00, /* ld8 r17=[r14],8 */ |
| 549 | 0x00, 0x00, 0x04, 0x00, /* nop.i 0x0;; */ |
| 550 | 0x11, 0x08, 0x00, 0x1c, 0x18, 0x10, /* [MIB] ld8 r1=[r14] */ |
| 551 | 0x60, 0x88, 0x04, 0x80, 0x03, 0x00, /* mov b6=r17 */ |
| 552 | 0x60, 0x00, 0x80, 0x00 /* br.few b6;; */ |
| 553 | }; |
| 554 | |
| 555 | static const bfd_byte plt_min_entry[PLT_MIN_ENTRY_SIZE] = |
| 556 | { |
| 557 | 0x11, 0x78, 0x00, 0x00, 0x00, 0x24, /* [MIB] mov r15=0 */ |
| 558 | 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, /* nop.i 0x0 */ |
| 559 | 0x00, 0x00, 0x00, 0x40 /* br.few 0 <PLT0>;; */ |
| 560 | }; |
| 561 | |
| 562 | static const bfd_byte plt_full_entry[PLT_FULL_ENTRY_SIZE] = |
| 563 | { |
| 564 | 0x0b, 0x78, 0x00, 0x02, 0x00, 0x24, /* [MMI] addl r15=0,r1;; */ |
| 565 | 0x00, 0x41, 0x3c, 0x30, 0x28, 0xc0, /* ld8 r16=[r15],8 */ |
| 566 | 0x01, 0x08, 0x00, 0x84, /* mov r14=r1;; */ |
| 567 | 0x11, 0x08, 0x00, 0x1e, 0x18, 0x10, /* [MIB] ld8 r1=[r15] */ |
| 568 | 0x60, 0x80, 0x04, 0x80, 0x03, 0x00, /* mov b6=r16 */ |
| 569 | 0x60, 0x00, 0x80, 0x00 /* br.few b6;; */ |
| 570 | }; |
| 571 | |
| 572 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" |
| 573 | #define AIX_DYNAMIC_INTERPRETER "/usr/lib/ia64l64/libc.so.1" |
| 574 | #define DYNAMIC_INTERPRETER(abfd) \ |
| 575 | (elfNN_ia64_aix_vec (abfd->xvec) ? AIX_DYNAMIC_INTERPRETER : ELF_DYNAMIC_INTERPRETER) |
| 576 | |
| 577 | /* Select out of range branch fixup type. Note that Itanium does |
| 578 | not support brl, and so it gets emulated by the kernel. */ |
| 579 | #undef USE_BRL |
| 580 | |
| 581 | static const bfd_byte oor_brl[16] = |
| 582 | { |
| 583 | 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MLX] nop.m 0 */ |
| 584 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* brl.sptk.few tgt;; */ |
| 585 | 0x00, 0x00, 0x00, 0xc0 |
| 586 | }; |
| 587 | |
| 588 | static const bfd_byte oor_ip[48] = |
| 589 | { |
| 590 | 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MLX] nop.m 0 */ |
| 591 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, /* movl r15=0 */ |
| 592 | 0x01, 0x00, 0x00, 0x60, |
| 593 | 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MII] nop.m 0 */ |
| 594 | 0x00, 0x01, 0x00, 0x60, 0x00, 0x00, /* mov r16=ip;; */ |
| 595 | 0xf2, 0x80, 0x00, 0x80, /* add r16=r15,r16;; */ |
| 596 | 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MIB] nop.m 0 */ |
| 597 | 0x60, 0x80, 0x04, 0x80, 0x03, 0x00, /* mov b6=r16 */ |
| 598 | 0x60, 0x00, 0x80, 0x00 /* br b6;; */ |
| 599 | }; |
| 600 | \f |
| 601 | /* These functions do relaxation for IA-64 ELF. |
| 602 | |
| 603 | This is primarily to support branches to targets out of range; |
| 604 | relaxation of R_IA64_LTOFF22X and R_IA64_LDXMOV not yet supported. */ |
| 605 | |
| 606 | static boolean |
| 607 | elfNN_ia64_relax_section (abfd, sec, link_info, again) |
| 608 | bfd *abfd; |
| 609 | asection *sec; |
| 610 | struct bfd_link_info *link_info; |
| 611 | boolean *again; |
| 612 | { |
| 613 | struct one_fixup |
| 614 | { |
| 615 | struct one_fixup *next; |
| 616 | asection *tsec; |
| 617 | bfd_vma toff; |
| 618 | bfd_vma trampoff; |
| 619 | }; |
| 620 | |
| 621 | Elf_Internal_Shdr *symtab_hdr; |
| 622 | Elf_Internal_Rela *internal_relocs; |
| 623 | Elf_Internal_Rela *free_relocs = NULL; |
| 624 | Elf_Internal_Rela *irel, *irelend; |
| 625 | bfd_byte *contents; |
| 626 | bfd_byte *free_contents = NULL; |
| 627 | ElfNN_External_Sym *extsyms; |
| 628 | ElfNN_External_Sym *free_extsyms = NULL; |
| 629 | struct elfNN_ia64_link_hash_table *ia64_info; |
| 630 | struct one_fixup *fixups = NULL; |
| 631 | boolean changed_contents = false; |
| 632 | boolean changed_relocs = false; |
| 633 | |
| 634 | /* Assume we're not going to change any sizes, and we'll only need |
| 635 | one pass. */ |
| 636 | *again = false; |
| 637 | |
| 638 | /* Nothing to do if there are no relocations. */ |
| 639 | if ((sec->flags & SEC_RELOC) == 0 |
| 640 | || sec->reloc_count == 0) |
| 641 | return true; |
| 642 | |
| 643 | /* If this is the first time we have been called for this section, |
| 644 | initialize the cooked size. */ |
| 645 | if (sec->_cooked_size == 0) |
| 646 | sec->_cooked_size = sec->_raw_size; |
| 647 | |
| 648 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
| 649 | |
| 650 | /* Load the relocations for this section. */ |
| 651 | internal_relocs = (_bfd_elfNN_link_read_relocs |
| 652 | (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL, |
| 653 | link_info->keep_memory)); |
| 654 | if (internal_relocs == NULL) |
| 655 | goto error_return; |
| 656 | |
| 657 | if (! link_info->keep_memory) |
| 658 | free_relocs = internal_relocs; |
| 659 | |
| 660 | ia64_info = elfNN_ia64_hash_table (link_info); |
| 661 | irelend = internal_relocs + sec->reloc_count; |
| 662 | |
| 663 | for (irel = internal_relocs; irel < irelend; irel++) |
| 664 | if (ELFNN_R_TYPE (irel->r_info) == (int) R_IA64_PCREL21B) |
| 665 | break; |
| 666 | |
| 667 | /* No branch-type relocations. */ |
| 668 | if (irel == irelend) |
| 669 | { |
| 670 | if (free_relocs != NULL) |
| 671 | free (free_relocs); |
| 672 | return true; |
| 673 | } |
| 674 | |
| 675 | /* Get the section contents. */ |
| 676 | if (elf_section_data (sec)->this_hdr.contents != NULL) |
| 677 | contents = elf_section_data (sec)->this_hdr.contents; |
| 678 | else |
| 679 | { |
| 680 | contents = (bfd_byte *) bfd_malloc (sec->_raw_size); |
| 681 | if (contents == NULL) |
| 682 | goto error_return; |
| 683 | free_contents = contents; |
| 684 | |
| 685 | if (! bfd_get_section_contents (abfd, sec, contents, |
| 686 | (file_ptr) 0, sec->_raw_size)) |
| 687 | goto error_return; |
| 688 | } |
| 689 | |
| 690 | /* Read this BFD's symbols. */ |
| 691 | if (symtab_hdr->contents != NULL) |
| 692 | extsyms = (ElfNN_External_Sym *) symtab_hdr->contents; |
| 693 | else |
| 694 | { |
| 695 | extsyms = (ElfNN_External_Sym *) bfd_malloc (symtab_hdr->sh_size); |
| 696 | if (extsyms == NULL) |
| 697 | goto error_return; |
| 698 | free_extsyms = extsyms; |
| 699 | if (bfd_seek (abfd, symtab_hdr->sh_offset, SEEK_SET) != 0 |
| 700 | || (bfd_read (extsyms, 1, symtab_hdr->sh_size, abfd) |
| 701 | != symtab_hdr->sh_size)) |
| 702 | goto error_return; |
| 703 | } |
| 704 | |
| 705 | for (; irel < irelend; irel++) |
| 706 | { |
| 707 | bfd_vma symaddr, reladdr, trampoff, toff, roff; |
| 708 | Elf_Internal_Sym isym; |
| 709 | asection *tsec; |
| 710 | struct one_fixup *f; |
| 711 | |
| 712 | if (ELFNN_R_TYPE (irel->r_info) != (int) R_IA64_PCREL21B) |
| 713 | continue; |
| 714 | |
| 715 | /* Get the value of the symbol referred to by the reloc. */ |
| 716 | if (ELFNN_R_SYM (irel->r_info) < symtab_hdr->sh_info) |
| 717 | { |
| 718 | /* A local symbol. */ |
| 719 | bfd_elfNN_swap_symbol_in (abfd, |
| 720 | extsyms + ELFNN_R_SYM (irel->r_info), |
| 721 | &isym); |
| 722 | if (isym.st_shndx == SHN_UNDEF) |
| 723 | continue; /* We can't do anthing with undefined symbols. */ |
| 724 | else if (isym.st_shndx == SHN_ABS) |
| 725 | tsec = bfd_abs_section_ptr; |
| 726 | else if (isym.st_shndx == SHN_COMMON) |
| 727 | tsec = bfd_com_section_ptr; |
| 728 | else if (isym.st_shndx > 0 && isym.st_shndx < SHN_LORESERVE) |
| 729 | tsec = bfd_section_from_elf_index (abfd, isym.st_shndx); |
| 730 | else |
| 731 | continue; /* who knows. */ |
| 732 | |
| 733 | toff = isym.st_value; |
| 734 | } |
| 735 | else |
| 736 | { |
| 737 | unsigned long indx; |
| 738 | struct elf_link_hash_entry *h; |
| 739 | struct elfNN_ia64_dyn_sym_info *dyn_i; |
| 740 | |
| 741 | indx = ELFNN_R_SYM (irel->r_info) - symtab_hdr->sh_info; |
| 742 | h = elf_sym_hashes (abfd)[indx]; |
| 743 | BFD_ASSERT (h != NULL); |
| 744 | |
| 745 | while (h->root.type == bfd_link_hash_indirect |
| 746 | || h->root.type == bfd_link_hash_warning) |
| 747 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 748 | |
| 749 | dyn_i = get_dyn_sym_info (ia64_info, h, abfd, irel, false); |
| 750 | |
| 751 | /* For branches to dynamic symbols, we're interested instead |
| 752 | in a branch to the PLT entry. */ |
| 753 | if (dyn_i && dyn_i->want_plt2) |
| 754 | { |
| 755 | tsec = ia64_info->plt_sec; |
| 756 | toff = dyn_i->plt2_offset; |
| 757 | } |
| 758 | else |
| 759 | { |
| 760 | /* We can't do anthing with undefined symbols. */ |
| 761 | if (h->root.type == bfd_link_hash_undefined |
| 762 | || h->root.type == bfd_link_hash_undefweak) |
| 763 | continue; |
| 764 | |
| 765 | tsec = h->root.u.def.section; |
| 766 | toff = h->root.u.def.value; |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | symaddr = (tsec->output_section->vma |
| 771 | + tsec->output_offset |
| 772 | + toff |
| 773 | + irel->r_addend); |
| 774 | |
| 775 | roff = irel->r_offset; |
| 776 | reladdr = (sec->output_section->vma |
| 777 | + sec->output_offset |
| 778 | + roff) & -4; |
| 779 | |
| 780 | /* If the branch is in range, no need to do anything. */ |
| 781 | if ((bfd_signed_vma) (symaddr - reladdr) >= -0x1000000 |
| 782 | && (bfd_signed_vma) (symaddr - reladdr) <= 0x0FFFFF0) |
| 783 | continue; |
| 784 | |
| 785 | /* If the branch and target are in the same section, you've |
| 786 | got one honking big section and we can't help you. You'll |
| 787 | get an error message later. */ |
| 788 | if (tsec == sec) |
| 789 | continue; |
| 790 | |
| 791 | /* Look for an existing fixup to this address. */ |
| 792 | for (f = fixups; f ; f = f->next) |
| 793 | if (f->tsec == tsec && f->toff == toff) |
| 794 | break; |
| 795 | |
| 796 | if (f == NULL) |
| 797 | { |
| 798 | /* Two alternatives: If it's a branch to a PLT entry, we can |
| 799 | make a copy of the FULL_PLT entry. Otherwise, we'll have |
| 800 | to use a `brl' insn to get where we're going. */ |
| 801 | |
| 802 | int size; |
| 803 | |
| 804 | if (tsec == ia64_info->plt_sec) |
| 805 | size = sizeof (plt_full_entry); |
| 806 | else |
| 807 | { |
| 808 | #ifdef USE_BRL |
| 809 | size = sizeof (oor_brl); |
| 810 | #else |
| 811 | size = sizeof (oor_ip); |
| 812 | #endif |
| 813 | } |
| 814 | |
| 815 | /* Resize the current section to make room for the new branch. */ |
| 816 | trampoff = (sec->_cooked_size + 15) & -16; |
| 817 | contents = (bfd_byte *) bfd_realloc (contents, trampoff + size); |
| 818 | if (contents == NULL) |
| 819 | goto error_return; |
| 820 | sec->_cooked_size = trampoff + size; |
| 821 | |
| 822 | if (tsec == ia64_info->plt_sec) |
| 823 | { |
| 824 | memcpy (contents + trampoff, plt_full_entry, size); |
| 825 | |
| 826 | /* Hijack the old relocation for use as the PLTOFF reloc. */ |
| 827 | irel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (irel->r_info), |
| 828 | R_IA64_PLTOFF22); |
| 829 | irel->r_offset = trampoff; |
| 830 | } |
| 831 | else |
| 832 | { |
| 833 | #ifdef USE_BRL |
| 834 | memcpy (contents + trampoff, oor_brl, size); |
| 835 | irel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (irel->r_info), |
| 836 | R_IA64_PCREL60B); |
| 837 | irel->r_offset = trampoff + 2; |
| 838 | #else |
| 839 | memcpy (contents + trampoff, oor_ip, size); |
| 840 | irel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (irel->r_info), |
| 841 | R_IA64_PCREL64I); |
| 842 | irel->r_addend -= 16; |
| 843 | irel->r_offset = trampoff + 2; |
| 844 | #endif |
| 845 | } |
| 846 | |
| 847 | /* Record the fixup so we don't do it again this section. */ |
| 848 | f = (struct one_fixup *) bfd_malloc (sizeof (*f)); |
| 849 | f->next = fixups; |
| 850 | f->tsec = tsec; |
| 851 | f->toff = toff; |
| 852 | f->trampoff = trampoff; |
| 853 | fixups = f; |
| 854 | } |
| 855 | else |
| 856 | { |
| 857 | /* Nop out the reloc, since we're finalizing things here. */ |
| 858 | irel->r_info = ELFNN_R_INFO (0, R_IA64_NONE); |
| 859 | } |
| 860 | |
| 861 | /* Fix up the existing branch to hit the trampoline. Hope like |
| 862 | hell this doesn't overflow too. */ |
| 863 | if (elfNN_ia64_install_value (abfd, contents + roff, |
| 864 | f->trampoff - (roff & -4), |
| 865 | R_IA64_PCREL21B) != bfd_reloc_ok) |
| 866 | goto error_return; |
| 867 | |
| 868 | changed_contents = true; |
| 869 | changed_relocs = true; |
| 870 | } |
| 871 | |
| 872 | /* Clean up and go home. */ |
| 873 | while (fixups) |
| 874 | { |
| 875 | struct one_fixup *f = fixups; |
| 876 | fixups = fixups->next; |
| 877 | free (f); |
| 878 | } |
| 879 | |
| 880 | if (changed_relocs) |
| 881 | elf_section_data (sec)->relocs = internal_relocs; |
| 882 | else if (free_relocs != NULL) |
| 883 | free (free_relocs); |
| 884 | |
| 885 | if (changed_contents) |
| 886 | elf_section_data (sec)->this_hdr.contents = contents; |
| 887 | else if (free_contents != NULL) |
| 888 | { |
| 889 | if (! link_info->keep_memory) |
| 890 | free (free_contents); |
| 891 | else |
| 892 | { |
| 893 | /* Cache the section contents for elf_link_input_bfd. */ |
| 894 | elf_section_data (sec)->this_hdr.contents = contents; |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | if (free_extsyms != NULL) |
| 899 | { |
| 900 | if (! link_info->keep_memory) |
| 901 | free (free_extsyms); |
| 902 | else |
| 903 | { |
| 904 | /* Cache the symbols for elf_link_input_bfd. */ |
| 905 | symtab_hdr->contents = extsyms; |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | *again = changed_contents || changed_relocs; |
| 910 | return true; |
| 911 | |
| 912 | error_return: |
| 913 | if (free_relocs != NULL) |
| 914 | free (free_relocs); |
| 915 | if (free_contents != NULL) |
| 916 | free (free_contents); |
| 917 | if (free_extsyms != NULL) |
| 918 | free (free_extsyms); |
| 919 | return false; |
| 920 | } |
| 921 | \f |
| 922 | /* Return true if NAME is an unwind table section name. */ |
| 923 | |
| 924 | static inline boolean |
| 925 | is_unwind_section_name (name) |
| 926 | const char *name; |
| 927 | { |
| 928 | size_t len1, len2, len3; |
| 929 | |
| 930 | len1 = sizeof (ELF_STRING_ia64_unwind) - 1; |
| 931 | len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1; |
| 932 | len3 = sizeof (ELF_STRING_ia64_unwind_once) - 1; |
| 933 | return ((strncmp (name, ELF_STRING_ia64_unwind, len1) == 0 |
| 934 | && strncmp (name, ELF_STRING_ia64_unwind_info, len2) != 0) |
| 935 | || strncmp (name, ELF_STRING_ia64_unwind_once, len3) == 0); |
| 936 | } |
| 937 | |
| 938 | /* Handle an IA-64 specific section when reading an object file. This |
| 939 | is called when elfcode.h finds a section with an unknown type. */ |
| 940 | |
| 941 | static boolean |
| 942 | elfNN_ia64_section_from_shdr (abfd, hdr, name) |
| 943 | bfd *abfd; |
| 944 | ElfNN_Internal_Shdr *hdr; |
| 945 | char *name; |
| 946 | { |
| 947 | asection *newsect; |
| 948 | |
| 949 | /* There ought to be a place to keep ELF backend specific flags, but |
| 950 | at the moment there isn't one. We just keep track of the |
| 951 | sections by their name, instead. Fortunately, the ABI gives |
| 952 | suggested names for all the MIPS specific sections, so we will |
| 953 | probably get away with this. */ |
| 954 | switch (hdr->sh_type) |
| 955 | { |
| 956 | case SHT_IA_64_UNWIND: |
| 957 | break; |
| 958 | |
| 959 | case SHT_IA_64_EXT: |
| 960 | if (strcmp (name, ELF_STRING_ia64_archext) != 0) |
| 961 | return false; |
| 962 | break; |
| 963 | |
| 964 | default: |
| 965 | return false; |
| 966 | } |
| 967 | |
| 968 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name)) |
| 969 | return false; |
| 970 | newsect = hdr->bfd_section; |
| 971 | |
| 972 | return true; |
| 973 | } |
| 974 | |
| 975 | /* Convert IA-64 specific section flags to bfd internal section flags. */ |
| 976 | |
| 977 | /* ??? There is no bfd internal flag equivalent to the SHF_IA_64_NORECOV |
| 978 | flag. */ |
| 979 | |
| 980 | static boolean |
| 981 | elfNN_ia64_section_flags (flags, hdr) |
| 982 | flagword *flags; |
| 983 | ElfNN_Internal_Shdr *hdr; |
| 984 | { |
| 985 | if (hdr->sh_flags & SHF_IA_64_SHORT) |
| 986 | *flags |= SEC_SMALL_DATA; |
| 987 | |
| 988 | return true; |
| 989 | } |
| 990 | |
| 991 | /* Set the correct type for an IA-64 ELF section. We do this by the |
| 992 | section name, which is a hack, but ought to work. */ |
| 993 | |
| 994 | static boolean |
| 995 | elfNN_ia64_fake_sections (abfd, hdr, sec) |
| 996 | bfd *abfd ATTRIBUTE_UNUSED; |
| 997 | ElfNN_Internal_Shdr *hdr; |
| 998 | asection *sec; |
| 999 | { |
| 1000 | register const char *name; |
| 1001 | |
| 1002 | name = bfd_get_section_name (abfd, sec); |
| 1003 | |
| 1004 | if (is_unwind_section_name (name)) |
| 1005 | { |
| 1006 | /* We don't have the sections numbered at this point, so sh_info |
| 1007 | is set later, in elfNN_ia64_final_write_processing. */ |
| 1008 | hdr->sh_type = SHT_IA_64_UNWIND; |
| 1009 | hdr->sh_flags |= SHF_LINK_ORDER; |
| 1010 | } |
| 1011 | else if (strcmp (name, ELF_STRING_ia64_archext) == 0) |
| 1012 | hdr->sh_type = SHT_IA_64_EXT; |
| 1013 | else if (strcmp (name, ".reloc") == 0) |
| 1014 | /* |
| 1015 | * This is an ugly, but unfortunately necessary hack that is |
| 1016 | * needed when producing EFI binaries on IA-64. It tells |
| 1017 | * elf.c:elf_fake_sections() not to consider ".reloc" as a section |
| 1018 | * containing ELF relocation info. We need this hack in order to |
| 1019 | * be able to generate ELF binaries that can be translated into |
| 1020 | * EFI applications (which are essentially COFF objects). Those |
| 1021 | * files contain a COFF ".reloc" section inside an ELFNN object, |
| 1022 | * which would normally cause BFD to segfault because it would |
| 1023 | * attempt to interpret this section as containing relocation |
| 1024 | * entries for section "oc". With this hack enabled, ".reloc" |
| 1025 | * will be treated as a normal data section, which will avoid the |
| 1026 | * segfault. However, you won't be able to create an ELFNN binary |
| 1027 | * with a section named "oc" that needs relocations, but that's |
| 1028 | * the kind of ugly side-effects you get when detecting section |
| 1029 | * types based on their names... In practice, this limitation is |
| 1030 | * unlikely to bite. |
| 1031 | */ |
| 1032 | hdr->sh_type = SHT_PROGBITS; |
| 1033 | |
| 1034 | if (sec->flags & SEC_SMALL_DATA) |
| 1035 | hdr->sh_flags |= SHF_IA_64_SHORT; |
| 1036 | |
| 1037 | return true; |
| 1038 | } |
| 1039 | |
| 1040 | /* The final processing done just before writing out an IA-64 ELF |
| 1041 | object file. */ |
| 1042 | |
| 1043 | static void |
| 1044 | elfNN_ia64_final_write_processing (abfd, linker) |
| 1045 | bfd *abfd; |
| 1046 | boolean linker ATTRIBUTE_UNUSED; |
| 1047 | { |
| 1048 | Elf_Internal_Shdr *hdr; |
| 1049 | const char *sname; |
| 1050 | asection *text_sect, *s; |
| 1051 | size_t len; |
| 1052 | |
| 1053 | for (s = abfd->sections; s; s = s->next) |
| 1054 | { |
| 1055 | hdr = &elf_section_data (s)->this_hdr; |
| 1056 | switch (hdr->sh_type) |
| 1057 | { |
| 1058 | case SHT_IA_64_UNWIND: |
| 1059 | /* See comments in gas/config/tc-ia64.c:dot_endp on why we |
| 1060 | have to do this. */ |
| 1061 | sname = bfd_get_section_name (abfd, s); |
| 1062 | len = sizeof (ELF_STRING_ia64_unwind) - 1; |
| 1063 | if (sname && strncmp (sname, ELF_STRING_ia64_unwind, len) == 0) |
| 1064 | { |
| 1065 | sname += len; |
| 1066 | |
| 1067 | if (sname[0] == '\0') |
| 1068 | /* .IA_64.unwind -> .text */ |
| 1069 | text_sect = bfd_get_section_by_name (abfd, ".text"); |
| 1070 | else |
| 1071 | /* .IA_64.unwindFOO -> FOO */ |
| 1072 | text_sect = bfd_get_section_by_name (abfd, sname); |
| 1073 | } |
| 1074 | else if (sname |
| 1075 | && (len = sizeof (ELF_STRING_ia64_unwind_once) - 1, |
| 1076 | strncmp (sname, ELF_STRING_ia64_unwind_once, len)) == 0) |
| 1077 | { |
| 1078 | /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.t.FOO */ |
| 1079 | size_t len2 = sizeof (".gnu.linkonce.t.") - 1; |
| 1080 | char *once_name = alloca (len2 + strlen (sname) - len + 1); |
| 1081 | |
| 1082 | memcpy (once_name, ".gnu.linkonce.t.", len2); |
| 1083 | strcpy (once_name + len2, sname + len); |
| 1084 | text_sect = bfd_get_section_by_name (abfd, once_name); |
| 1085 | } |
| 1086 | else |
| 1087 | /* last resort: fall back on .text */ |
| 1088 | text_sect = bfd_get_section_by_name (abfd, ".text"); |
| 1089 | |
| 1090 | if (text_sect) |
| 1091 | { |
| 1092 | /* The IA-64 processor-specific ABI requires setting |
| 1093 | sh_link to the unwind section, whereas HP-UX requires |
| 1094 | sh_info to do so. For maximum compatibility, we'll |
| 1095 | set both for now... */ |
| 1096 | hdr->sh_link = elf_section_data (text_sect)->this_idx; |
| 1097 | hdr->sh_info = elf_section_data (text_sect)->this_idx; |
| 1098 | } |
| 1099 | break; |
| 1100 | } |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | /* Hook called by the linker routine which adds symbols from an object |
| 1105 | file. We use it to put .comm items in .sbss, and not .bss. */ |
| 1106 | |
| 1107 | static boolean |
| 1108 | elfNN_ia64_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp) |
| 1109 | bfd *abfd; |
| 1110 | struct bfd_link_info *info; |
| 1111 | const Elf_Internal_Sym *sym; |
| 1112 | const char **namep ATTRIBUTE_UNUSED; |
| 1113 | flagword *flagsp ATTRIBUTE_UNUSED; |
| 1114 | asection **secp; |
| 1115 | bfd_vma *valp; |
| 1116 | { |
| 1117 | if (sym->st_shndx == SHN_COMMON |
| 1118 | && !info->relocateable |
| 1119 | && sym->st_size <= (unsigned) bfd_get_gp_size (abfd)) |
| 1120 | { |
| 1121 | /* Common symbols less than or equal to -G nn bytes are |
| 1122 | automatically put into .sbss. */ |
| 1123 | |
| 1124 | asection *scomm = bfd_get_section_by_name (abfd, ".scommon"); |
| 1125 | |
| 1126 | if (scomm == NULL) |
| 1127 | { |
| 1128 | scomm = bfd_make_section (abfd, ".scommon"); |
| 1129 | if (scomm == NULL |
| 1130 | || !bfd_set_section_flags (abfd, scomm, (SEC_ALLOC |
| 1131 | | SEC_IS_COMMON |
| 1132 | | SEC_LINKER_CREATED))) |
| 1133 | return false; |
| 1134 | } |
| 1135 | |
| 1136 | *secp = scomm; |
| 1137 | *valp = sym->st_size; |
| 1138 | } |
| 1139 | |
| 1140 | return true; |
| 1141 | } |
| 1142 | |
| 1143 | static boolean |
| 1144 | elfNN_ia64_aix_vec (const bfd_target *vec) |
| 1145 | { |
| 1146 | extern const bfd_target bfd_elfNN_ia64_aix_little_vec; |
| 1147 | extern const bfd_target bfd_elfNN_ia64_aix_big_vec; |
| 1148 | |
| 1149 | return (/**/vec == & bfd_elfNN_ia64_aix_little_vec |
| 1150 | || vec == & bfd_elfNN_ia64_aix_big_vec); |
| 1151 | } |
| 1152 | |
| 1153 | /* Hook called by the linker routine which adds symbols from an object |
| 1154 | file. We use it to handle OS-specific symbols. */ |
| 1155 | |
| 1156 | static boolean |
| 1157 | elfNN_ia64_aix_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp) |
| 1158 | bfd *abfd; |
| 1159 | struct bfd_link_info *info; |
| 1160 | const Elf_Internal_Sym *sym; |
| 1161 | const char **namep; |
| 1162 | flagword *flagsp; |
| 1163 | asection **secp; |
| 1164 | bfd_vma *valp; |
| 1165 | { |
| 1166 | if (strcmp (*namep, "__GLOB_DATA_PTR") == 0) |
| 1167 | { |
| 1168 | /* Define __GLOB_DATA_PTR when it is encountered. This is expected to |
| 1169 | be a linker-defined symbol by the Aix C runtime startup code. IBM sez |
| 1170 | no one else should use it b/c it is undocumented. */ |
| 1171 | struct elf_link_hash_entry *h; |
| 1172 | |
| 1173 | h = (struct elf_link_hash_entry *) bfd_link_hash_lookup (info->hash, *namep, false, false, false); |
| 1174 | if (h == NULL) |
| 1175 | { |
| 1176 | struct elf_backend_data *bed; |
| 1177 | struct elfNN_ia64_link_hash_table *ia64_info; |
| 1178 | |
| 1179 | bed = get_elf_backend_data (abfd); |
| 1180 | ia64_info = elfNN_ia64_hash_table (info); |
| 1181 | |
| 1182 | if (!(_bfd_generic_link_add_one_symbol |
| 1183 | (info, abfd, *namep, BSF_GLOBAL, |
| 1184 | bfd_get_section_by_name (abfd, ".bss"), |
| 1185 | bed->got_symbol_offset, (const char *) NULL, false, |
| 1186 | bed->collect, (struct bfd_link_hash_entry **) &h))) |
| 1187 | return false; |
| 1188 | |
| 1189 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; |
| 1190 | h->type = STT_OBJECT; |
| 1191 | |
| 1192 | if (! _bfd_elf_link_record_dynamic_symbol (info, h)) |
| 1193 | return false; |
| 1194 | } |
| 1195 | |
| 1196 | return true; |
| 1197 | } |
| 1198 | else if (sym->st_shndx == SHN_LOOS) |
| 1199 | { |
| 1200 | int i; |
| 1201 | |
| 1202 | /* SHN_AIX_SYSCALL: Treat this as any other symbol. The special symbol |
| 1203 | is only relevant when compiling code for extended system calls. |
| 1204 | Replace the "special" section with .text, if possible. |
| 1205 | Note that these symbols are always assumed to be in .text. */ |
| 1206 | for (i = 1; i < elf_elfheader (abfd)->e_shnum; i++) |
| 1207 | { |
| 1208 | asection * sec = bfd_section_from_elf_index (abfd, i); |
| 1209 | |
| 1210 | if (sec && strcmp (sec->name, ".text") == 0) |
| 1211 | { |
| 1212 | *secp = sec; |
| 1213 | break; |
| 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | if (*secp == NULL) |
| 1218 | *secp = bfd_abs_section_ptr; |
| 1219 | |
| 1220 | *valp = sym->st_size; |
| 1221 | |
| 1222 | return true; |
| 1223 | } |
| 1224 | else |
| 1225 | { |
| 1226 | return elfNN_ia64_add_symbol_hook (abfd, info, sym, |
| 1227 | namep, flagsp, secp, valp); |
| 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | boolean |
| 1232 | elfNN_ia64_aix_link_add_symbols (abfd, info) |
| 1233 | bfd *abfd; |
| 1234 | struct bfd_link_info *info; |
| 1235 | { |
| 1236 | /* Make sure dynamic sections are always created. */ |
| 1237 | if (! elf_hash_table (info)->dynamic_sections_created |
| 1238 | && abfd->xvec == info->hash->creator) |
| 1239 | { |
| 1240 | if (! bfd_elfNN_link_create_dynamic_sections (abfd, info)) |
| 1241 | return false; |
| 1242 | } |
| 1243 | |
| 1244 | /* Now do the standard call. */ |
| 1245 | return bfd_elfNN_bfd_link_add_symbols (abfd, info); |
| 1246 | } |
| 1247 | |
| 1248 | /* Return the number of additional phdrs we will need. */ |
| 1249 | |
| 1250 | static int |
| 1251 | elfNN_ia64_additional_program_headers (abfd) |
| 1252 | bfd *abfd; |
| 1253 | { |
| 1254 | asection *s; |
| 1255 | int ret = 0; |
| 1256 | |
| 1257 | /* See if we need a PT_IA_64_ARCHEXT segment. */ |
| 1258 | s = bfd_get_section_by_name (abfd, ELF_STRING_ia64_archext); |
| 1259 | if (s && (s->flags & SEC_LOAD)) |
| 1260 | ++ret; |
| 1261 | |
| 1262 | /* Count how many PT_IA_64_UNWIND segments we need. */ |
| 1263 | for (s = abfd->sections; s; s = s->next) |
| 1264 | if (is_unwind_section_name(s->name) && (s->flags & SEC_LOAD)) |
| 1265 | ++ret; |
| 1266 | |
| 1267 | return ret; |
| 1268 | } |
| 1269 | |
| 1270 | static boolean |
| 1271 | elfNN_ia64_modify_segment_map (abfd) |
| 1272 | bfd *abfd; |
| 1273 | { |
| 1274 | struct elf_segment_map *m, **pm; |
| 1275 | Elf_Internal_Shdr *hdr; |
| 1276 | asection *s; |
| 1277 | |
| 1278 | /* If we need a PT_IA_64_ARCHEXT segment, it must come before |
| 1279 | all PT_LOAD segments. */ |
| 1280 | s = bfd_get_section_by_name (abfd, ELF_STRING_ia64_archext); |
| 1281 | if (s && (s->flags & SEC_LOAD)) |
| 1282 | { |
| 1283 | for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next) |
| 1284 | if (m->p_type == PT_IA_64_ARCHEXT) |
| 1285 | break; |
| 1286 | if (m == NULL) |
| 1287 | { |
| 1288 | m = (struct elf_segment_map *) bfd_zalloc (abfd, sizeof *m); |
| 1289 | if (m == NULL) |
| 1290 | return false; |
| 1291 | |
| 1292 | m->p_type = PT_IA_64_ARCHEXT; |
| 1293 | m->count = 1; |
| 1294 | m->sections[0] = s; |
| 1295 | |
| 1296 | /* We want to put it after the PHDR and INTERP segments. */ |
| 1297 | pm = &elf_tdata (abfd)->segment_map; |
| 1298 | while (*pm != NULL |
| 1299 | && ((*pm)->p_type == PT_PHDR |
| 1300 | || (*pm)->p_type == PT_INTERP)) |
| 1301 | pm = &(*pm)->next; |
| 1302 | |
| 1303 | m->next = *pm; |
| 1304 | *pm = m; |
| 1305 | } |
| 1306 | } |
| 1307 | |
| 1308 | /* Install PT_IA_64_UNWIND segments, if needed. */ |
| 1309 | for (s = abfd->sections; s; s = s->next) |
| 1310 | { |
| 1311 | hdr = &elf_section_data (s)->this_hdr; |
| 1312 | if (hdr->sh_type != SHT_IA_64_UNWIND) |
| 1313 | continue; |
| 1314 | |
| 1315 | if (s && (s->flags & SEC_LOAD)) |
| 1316 | { |
| 1317 | for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next) |
| 1318 | if (m->p_type == PT_IA_64_UNWIND && m->sections[0] == s) |
| 1319 | break; |
| 1320 | |
| 1321 | if (m == NULL) |
| 1322 | { |
| 1323 | m = (struct elf_segment_map *) bfd_zalloc (abfd, sizeof *m); |
| 1324 | if (m == NULL) |
| 1325 | return false; |
| 1326 | |
| 1327 | m->p_type = PT_IA_64_UNWIND; |
| 1328 | m->count = 1; |
| 1329 | m->sections[0] = s; |
| 1330 | m->next = NULL; |
| 1331 | |
| 1332 | /* We want to put it last. */ |
| 1333 | pm = &elf_tdata (abfd)->segment_map; |
| 1334 | while (*pm != NULL) |
| 1335 | pm = &(*pm)->next; |
| 1336 | *pm = m; |
| 1337 | } |
| 1338 | } |
| 1339 | } |
| 1340 | |
| 1341 | /* Turn on PF_IA_64_NORECOV if needed. This involves traversing all of |
| 1342 | the input sections for each output section in the segment and testing |
| 1343 | for SHF_IA_64_NORECOV on each. */ |
| 1344 | for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next) |
| 1345 | if (m->p_type == PT_LOAD) |
| 1346 | { |
| 1347 | int i; |
| 1348 | for (i = m->count - 1; i >= 0; --i) |
| 1349 | { |
| 1350 | struct bfd_link_order *order = m->sections[i]->link_order_head; |
| 1351 | while (order) |
| 1352 | { |
| 1353 | if (order->type == bfd_indirect_link_order) |
| 1354 | { |
| 1355 | asection *is = order->u.indirect.section; |
| 1356 | bfd_vma flags = elf_section_data(is)->this_hdr.sh_flags; |
| 1357 | if (flags & SHF_IA_64_NORECOV) |
| 1358 | { |
| 1359 | m->p_flags |= PF_IA_64_NORECOV; |
| 1360 | goto found; |
| 1361 | } |
| 1362 | } |
| 1363 | order = order->next; |
| 1364 | } |
| 1365 | } |
| 1366 | found:; |
| 1367 | } |
| 1368 | |
| 1369 | return true; |
| 1370 | } |
| 1371 | |
| 1372 | /* According to the Tahoe assembler spec, all labels starting with a |
| 1373 | '.' are local. */ |
| 1374 | |
| 1375 | static boolean |
| 1376 | elfNN_ia64_is_local_label_name (abfd, name) |
| 1377 | bfd *abfd ATTRIBUTE_UNUSED; |
| 1378 | const char *name; |
| 1379 | { |
| 1380 | return name[0] == '.'; |
| 1381 | } |
| 1382 | |
| 1383 | /* Should we do dynamic things to this symbol? */ |
| 1384 | |
| 1385 | static boolean |
| 1386 | elfNN_ia64_dynamic_symbol_p (h, info) |
| 1387 | struct elf_link_hash_entry *h; |
| 1388 | struct bfd_link_info *info; |
| 1389 | { |
| 1390 | if (h == NULL) |
| 1391 | return false; |
| 1392 | |
| 1393 | while (h->root.type == bfd_link_hash_indirect |
| 1394 | || h->root.type == bfd_link_hash_warning) |
| 1395 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 1396 | |
| 1397 | if (h->dynindx == -1) |
| 1398 | return false; |
| 1399 | switch (ELF_ST_VISIBILITY (h->other)) |
| 1400 | { |
| 1401 | case STV_INTERNAL: |
| 1402 | case STV_HIDDEN: |
| 1403 | return false; |
| 1404 | } |
| 1405 | |
| 1406 | if (h->root.type == bfd_link_hash_undefweak |
| 1407 | || h->root.type == bfd_link_hash_defweak) |
| 1408 | return true; |
| 1409 | |
| 1410 | if ((info->shared && !info->symbolic) |
| 1411 | || ((h->elf_link_hash_flags |
| 1412 | & (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR)) |
| 1413 | == (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR))) |
| 1414 | return true; |
| 1415 | |
| 1416 | return false; |
| 1417 | } |
| 1418 | \f |
| 1419 | static boolean |
| 1420 | elfNN_ia64_local_hash_table_init (ht, abfd, new) |
| 1421 | struct elfNN_ia64_local_hash_table *ht; |
| 1422 | bfd *abfd ATTRIBUTE_UNUSED; |
| 1423 | new_hash_entry_func new; |
| 1424 | { |
| 1425 | memset (ht, 0, sizeof (*ht)); |
| 1426 | return bfd_hash_table_init (&ht->root, new); |
| 1427 | } |
| 1428 | |
| 1429 | static struct bfd_hash_entry* |
| 1430 | elfNN_ia64_new_loc_hash_entry (entry, table, string) |
| 1431 | struct bfd_hash_entry *entry; |
| 1432 | struct bfd_hash_table *table; |
| 1433 | const char *string; |
| 1434 | { |
| 1435 | struct elfNN_ia64_local_hash_entry *ret; |
| 1436 | ret = (struct elfNN_ia64_local_hash_entry *) entry; |
| 1437 | |
| 1438 | /* Allocate the structure if it has not already been allocated by a |
| 1439 | subclass. */ |
| 1440 | if (!ret) |
| 1441 | ret = bfd_hash_allocate (table, sizeof (*ret)); |
| 1442 | |
| 1443 | if (!ret) |
| 1444 | return 0; |
| 1445 | |
| 1446 | /* Initialize our local data. All zeros, and definitely easier |
| 1447 | than setting a handful of bit fields. */ |
| 1448 | memset (ret, 0, sizeof (*ret)); |
| 1449 | |
| 1450 | /* Call the allocation method of the superclass. */ |
| 1451 | ret = ((struct elfNN_ia64_local_hash_entry *) |
| 1452 | bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string)); |
| 1453 | |
| 1454 | return (struct bfd_hash_entry *) ret; |
| 1455 | } |
| 1456 | |
| 1457 | static struct bfd_hash_entry* |
| 1458 | elfNN_ia64_new_elf_hash_entry (entry, table, string) |
| 1459 | struct bfd_hash_entry *entry; |
| 1460 | struct bfd_hash_table *table; |
| 1461 | const char *string; |
| 1462 | { |
| 1463 | struct elfNN_ia64_link_hash_entry *ret; |
| 1464 | ret = (struct elfNN_ia64_link_hash_entry *) entry; |
| 1465 | |
| 1466 | /* Allocate the structure if it has not already been allocated by a |
| 1467 | subclass. */ |
| 1468 | if (!ret) |
| 1469 | ret = bfd_hash_allocate (table, sizeof (*ret)); |
| 1470 | |
| 1471 | if (!ret) |
| 1472 | return 0; |
| 1473 | |
| 1474 | /* Initialize our local data. All zeros, and definitely easier |
| 1475 | than setting a handful of bit fields. */ |
| 1476 | memset (ret, 0, sizeof (*ret)); |
| 1477 | |
| 1478 | /* Call the allocation method of the superclass. */ |
| 1479 | ret = ((struct elfNN_ia64_link_hash_entry *) |
| 1480 | _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, |
| 1481 | table, string)); |
| 1482 | |
| 1483 | return (struct bfd_hash_entry *) ret; |
| 1484 | } |
| 1485 | |
| 1486 | static void |
| 1487 | elfNN_ia64_hash_copy_indirect (xdir, xind) |
| 1488 | struct elf_link_hash_entry *xdir, *xind; |
| 1489 | { |
| 1490 | struct elfNN_ia64_link_hash_entry *dir, *ind; |
| 1491 | |
| 1492 | dir = (struct elfNN_ia64_link_hash_entry *)xdir; |
| 1493 | ind = (struct elfNN_ia64_link_hash_entry *)xind; |
| 1494 | |
| 1495 | /* Copy down any references that we may have already seen to the |
| 1496 | symbol which just became indirect. */ |
| 1497 | |
| 1498 | dir->root.elf_link_hash_flags |= |
| 1499 | (ind->root.elf_link_hash_flags |
| 1500 | & (ELF_LINK_HASH_REF_DYNAMIC |
| 1501 | | ELF_LINK_HASH_REF_REGULAR |
| 1502 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK)); |
| 1503 | |
| 1504 | /* Copy over the got and plt data. This would have been done |
| 1505 | by check_relocs. */ |
| 1506 | |
| 1507 | if (dir->info == NULL) |
| 1508 | { |
| 1509 | struct elfNN_ia64_dyn_sym_info *dyn_i; |
| 1510 | |
| 1511 | dir->info = dyn_i = ind->info; |
| 1512 | ind->info = NULL; |
| 1513 | |
| 1514 | /* Fix up the dyn_sym_info pointers to the global symbol. */ |
| 1515 | for (; dyn_i; dyn_i = dyn_i->next) |
| 1516 | dyn_i->h = &dir->root; |
| 1517 | } |
| 1518 | BFD_ASSERT (ind->info == NULL); |
| 1519 | |
| 1520 | /* Copy over the dynindx. */ |
| 1521 | |
| 1522 | if (dir->root.dynindx == -1) |
| 1523 | { |
| 1524 | dir->root.dynindx = ind->root.dynindx; |
| 1525 | dir->root.dynstr_index = ind->root.dynstr_index; |
| 1526 | ind->root.dynindx = -1; |
| 1527 | ind->root.dynstr_index = 0; |
| 1528 | } |
| 1529 | BFD_ASSERT (ind->root.dynindx == -1); |
| 1530 | } |
| 1531 | |
| 1532 | static void |
| 1533 | elfNN_ia64_hash_hide_symbol (info, xh) |
| 1534 | struct bfd_link_info *info ATTRIBUTE_UNUSED; |
| 1535 | struct elf_link_hash_entry *xh; |
| 1536 | { |
| 1537 | struct elfNN_ia64_link_hash_entry *h; |
| 1538 | struct elfNN_ia64_dyn_sym_info *dyn_i; |
| 1539 | |
| 1540 | h = (struct elfNN_ia64_link_hash_entry *)xh; |
| 1541 | |
| 1542 | h->root.elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
| 1543 | if ((h->root.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0) |
| 1544 | h->root.dynindx = -1; |
| 1545 | |
| 1546 | for (dyn_i = h->info; dyn_i; dyn_i = dyn_i->next) |
| 1547 | dyn_i->want_plt2 = 0; |
| 1548 | } |
| 1549 | |
| 1550 | /* Create the derived linker hash table. The IA-64 ELF port uses this |
| 1551 | derived hash table to keep information specific to the IA-64 ElF |
| 1552 | linker (without using static variables). */ |
| 1553 | |
| 1554 | static struct bfd_link_hash_table* |
| 1555 | elfNN_ia64_hash_table_create (abfd) |
| 1556 | bfd *abfd; |
| 1557 | { |
| 1558 | struct elfNN_ia64_link_hash_table *ret; |
| 1559 | |
| 1560 | ret = bfd_alloc (abfd, sizeof (*ret)); |
| 1561 | if (!ret) |
| 1562 | return 0; |
| 1563 | if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, |
| 1564 | elfNN_ia64_new_elf_hash_entry)) |
| 1565 | { |
| 1566 | bfd_release (abfd, ret); |
| 1567 | return 0; |
| 1568 | } |
| 1569 | |
| 1570 | if (!elfNN_ia64_local_hash_table_init (&ret->loc_hash_table, abfd, |
| 1571 | elfNN_ia64_new_loc_hash_entry)) |
| 1572 | return 0; |
| 1573 | return &ret->root.root; |
| 1574 | } |
| 1575 | |
| 1576 | /* Look up an entry in a Alpha ELF linker hash table. */ |
| 1577 | |
| 1578 | static INLINE struct elfNN_ia64_local_hash_entry * |
| 1579 | elfNN_ia64_local_hash_lookup(table, string, create, copy) |
| 1580 | struct elfNN_ia64_local_hash_table *table; |
| 1581 | const char *string; |
| 1582 | boolean create, copy; |
| 1583 | { |
| 1584 | return ((struct elfNN_ia64_local_hash_entry *) |
| 1585 | bfd_hash_lookup (&table->root, string, create, copy)); |
| 1586 | } |
| 1587 | |
| 1588 | /* Traverse both local and global hash tables. */ |
| 1589 | |
| 1590 | struct elfNN_ia64_dyn_sym_traverse_data |
| 1591 | { |
| 1592 | boolean (*func) PARAMS ((struct elfNN_ia64_dyn_sym_info *, PTR)); |
| 1593 | PTR data; |
| 1594 | }; |
| 1595 | |
| 1596 | static boolean |
| 1597 | elfNN_ia64_global_dyn_sym_thunk (xentry, xdata) |
| 1598 | struct bfd_hash_entry *xentry; |
| 1599 | PTR xdata; |
| 1600 | { |
| 1601 | struct elfNN_ia64_link_hash_entry *entry |
| 1602 | = (struct elfNN_ia64_link_hash_entry *) xentry; |
| 1603 | struct elfNN_ia64_dyn_sym_traverse_data *data |
| 1604 | = (struct elfNN_ia64_dyn_sym_traverse_data *) xdata; |
| 1605 | struct elfNN_ia64_dyn_sym_info *dyn_i; |
| 1606 | |
| 1607 | for (dyn_i = entry->info; dyn_i; dyn_i = dyn_i->next) |
| 1608 | if (! (*data->func) (dyn_i, data->data)) |
| 1609 | return false; |
| 1610 | return true; |
| 1611 | } |
| 1612 | |
| 1613 | static boolean |
| 1614 | elfNN_ia64_local_dyn_sym_thunk (xentry, xdata) |
| 1615 | struct bfd_hash_entry *xentry; |
| 1616 | PTR xdata; |
| 1617 | { |
| 1618 | struct elfNN_ia64_local_hash_entry *entry |
| 1619 | = (struct elfNN_ia64_local_hash_entry *) xentry; |
| 1620 | struct elfNN_ia64_dyn_sym_traverse_data *data |
| 1621 | = (struct elfNN_ia64_dyn_sym_traverse_data *) xdata; |
| 1622 | struct elfNN_ia64_dyn_sym_info *dyn_i; |
| 1623 | |
| 1624 | for (dyn_i = entry->info; dyn_i; dyn_i = dyn_i->next) |
| 1625 | if (! (*data->func) (dyn_i, data->data)) |
| 1626 | return false; |
| 1627 | return true; |
| 1628 | } |
| 1629 | |
| 1630 | static void |
| 1631 | elfNN_ia64_dyn_sym_traverse (ia64_info, func, data) |
| 1632 | struct elfNN_ia64_link_hash_table *ia64_info; |
| 1633 | boolean (*func) PARAMS ((struct elfNN_ia64_dyn_sym_info *, PTR)); |
| 1634 | PTR data; |
| 1635 | { |
| 1636 | struct elfNN_ia64_dyn_sym_traverse_data xdata; |
| 1637 | |
| 1638 | xdata.func = func; |
| 1639 | xdata.data = data; |
| 1640 | |
| 1641 | elf_link_hash_traverse (&ia64_info->root, |
| 1642 | elfNN_ia64_global_dyn_sym_thunk, &xdata); |
| 1643 | bfd_hash_traverse (&ia64_info->loc_hash_table.root, |
| 1644 | elfNN_ia64_local_dyn_sym_thunk, &xdata); |
| 1645 | } |
| 1646 | \f |
| 1647 | static boolean |
| 1648 | elfNN_ia64_create_dynamic_sections (abfd, info) |
| 1649 | bfd *abfd; |
| 1650 | struct bfd_link_info *info; |
| 1651 | { |
| 1652 | struct elfNN_ia64_link_hash_table *ia64_info; |
| 1653 | asection *s; |
| 1654 | |
| 1655 | if (! _bfd_elf_create_dynamic_sections (abfd, info)) |
| 1656 | return false; |
| 1657 | |
| 1658 | ia64_info = elfNN_ia64_hash_table (info); |
| 1659 | |
| 1660 | ia64_info->plt_sec = bfd_get_section_by_name (abfd, ".plt"); |
| 1661 | ia64_info->got_sec = bfd_get_section_by_name (abfd, ".got"); |
| 1662 | |
| 1663 | { |
| 1664 | flagword flags = bfd_get_section_flags (abfd, ia64_info->got_sec); |
| 1665 | bfd_set_section_flags (abfd, ia64_info->got_sec, SEC_SMALL_DATA | flags); |
| 1666 | } |
| 1667 | |
| 1668 | if (!get_pltoff (abfd, info, ia64_info)) |
| 1669 | return false; |
| 1670 | |
| 1671 | s = bfd_make_section(abfd, ".rela.IA_64.pltoff"); |
| 1672 | if (s == NULL |
| 1673 | || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD |
| 1674 | | SEC_HAS_CONTENTS |
| 1675 | | SEC_IN_MEMORY |
| 1676 | | SEC_LINKER_CREATED |
| 1677 | | SEC_READONLY)) |
| 1678 | || !bfd_set_section_alignment (abfd, s, 3)) |
| 1679 | return false; |
| 1680 | ia64_info->rel_pltoff_sec = s; |
| 1681 | |
| 1682 | s = bfd_make_section(abfd, ".rela.got"); |
| 1683 | if (s == NULL |
| 1684 | || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD |
| 1685 | | SEC_HAS_CONTENTS |
| 1686 | | SEC_IN_MEMORY |
| 1687 | | SEC_LINKER_CREATED |
| 1688 | | SEC_READONLY)) |
| 1689 | || !bfd_set_section_alignment (abfd, s, 3)) |
| 1690 | return false; |
| 1691 | ia64_info->rel_got_sec = s; |
| 1692 | |
| 1693 | return true; |
| 1694 | } |
| 1695 | |
| 1696 | /* Find and/or create a descriptor for dynamic symbol info. This will |
| 1697 | vary based on global or local symbol, and the addend to the reloc. */ |
| 1698 | |
| 1699 | static struct elfNN_ia64_dyn_sym_info * |
| 1700 | get_dyn_sym_info (ia64_info, h, abfd, rel, create) |
| 1701 | struct elfNN_ia64_link_hash_table *ia64_info; |
| 1702 | struct elf_link_hash_entry *h; |
| 1703 | bfd *abfd; |
| 1704 | const Elf_Internal_Rela *rel; |
| 1705 | boolean create; |
| 1706 | { |
| 1707 | struct elfNN_ia64_dyn_sym_info **pp; |
| 1708 | struct elfNN_ia64_dyn_sym_info *dyn_i; |
| 1709 | bfd_vma addend = rel ? rel->r_addend : 0; |
| 1710 | |
| 1711 | if (h) |
| 1712 | pp = &((struct elfNN_ia64_link_hash_entry *)h)->info; |
| 1713 | else |
| 1714 | { |
| 1715 | struct elfNN_ia64_local_hash_entry *loc_h; |
| 1716 | char *addr_name; |
| 1717 | size_t len; |
| 1718 | |
| 1719 | /* Construct a string for use in the elfNN_ia64_local_hash_table. |
| 1720 | The name describes what was once anonymous memory. */ |
| 1721 | |
| 1722 | len = sizeof (void*)*2 + 1 + sizeof (bfd_vma)*4 + 1 + 1; |
| 1723 | len += 10; /* %p slop */ |
| 1724 | |
| 1725 | addr_name = alloca (len); |
| 1726 | sprintf (addr_name, "%p:%lx", (void *) abfd, ELFNN_R_SYM (rel->r_info)); |
| 1727 | |
| 1728 | /* Collect the canonical entry data for this address. */ |
| 1729 | loc_h = elfNN_ia64_local_hash_lookup (&ia64_info->loc_hash_table, |
| 1730 | addr_name, create, create); |
| 1731 | BFD_ASSERT (loc_h); |
| 1732 | |
| 1733 | pp = &loc_h->info; |
| 1734 | } |
| 1735 | |
| 1736 | for (dyn_i = *pp; dyn_i && dyn_i->addend != addend; dyn_i = *pp) |
| 1737 | pp = &dyn_i->next; |
| 1738 | |
| 1739 | if (dyn_i == NULL && create) |
| 1740 | { |
| 1741 | dyn_i = (struct elfNN_ia64_dyn_sym_info *) |
| 1742 | bfd_zalloc (abfd, sizeof *dyn_i); |
| 1743 | *pp = dyn_i; |
| 1744 | dyn_i->addend = addend; |
| 1745 | } |
| 1746 | |
| 1747 | return dyn_i; |
| 1748 | } |
| 1749 | |
| 1750 | static asection * |
| 1751 | get_got (abfd, info, ia64_info) |
| 1752 | bfd *abfd; |
| 1753 | struct bfd_link_info *info; |
| 1754 | struct elfNN_ia64_link_hash_table *ia64_info; |
| 1755 | { |
| 1756 | asection *got; |
| 1757 | bfd *dynobj; |
| 1758 | |
| 1759 | got = ia64_info->got_sec; |
| 1760 | if (!got) |
| 1761 | { |
| 1762 | flagword flags; |
| 1763 | |
| 1764 | dynobj = ia64_info->root.dynobj; |
| 1765 | if (!dynobj) |
| 1766 | ia64_info->root.dynobj = dynobj = abfd; |
| 1767 | if (!_bfd_elf_create_got_section (dynobj, info)) |
| 1768 | return 0; |
| 1769 | |
| 1770 | got = bfd_get_section_by_name (dynobj, ".got"); |
| 1771 | BFD_ASSERT (got); |
| 1772 | ia64_info->got_sec = got; |
| 1773 | |
| 1774 | flags = bfd_get_section_flags (abfd, got); |
| 1775 | bfd_set_section_flags (abfd, got, SEC_SMALL_DATA | flags); |
| 1776 | } |
| 1777 | |
| 1778 | return got; |
| 1779 | } |
| 1780 | |
| 1781 | /* Create function descriptor section (.opd). This section is called .opd |
| 1782 | because it contains "official prodecure descriptors". The "official" |
| 1783 | refers to the fact that these descriptors are used when taking the address |
| 1784 | of a procedure, thus ensuring a unique address for each procedure. */ |
| 1785 | |
| 1786 | static asection * |
| 1787 | get_fptr (abfd, info, ia64_info) |
| 1788 | bfd *abfd; |
| 1789 | struct bfd_link_info *info ATTRIBUTE_UNUSED; |
| 1790 | struct elfNN_ia64_link_hash_table *ia64_info; |
| 1791 | { |
| 1792 | asection *fptr; |
| 1793 | bfd *dynobj; |
| 1794 | |
| 1795 | fptr = ia64_info->fptr_sec; |
| 1796 | if (!fptr) |
| 1797 | { |
| 1798 | dynobj = ia64_info->root.dynobj; |
| 1799 | if (!dynobj) |
| 1800 | ia64_info->root.dynobj = dynobj = abfd; |
| 1801 | |
| 1802 | fptr = bfd_make_section (dynobj, ".opd"); |
| 1803 | if (!fptr |
| 1804 | || !bfd_set_section_flags (dynobj, fptr, |
| 1805 | (SEC_ALLOC |
| 1806 | | SEC_LOAD |
| 1807 | | SEC_HAS_CONTENTS |
| 1808 | | SEC_IN_MEMORY |
| 1809 | | SEC_READONLY |
| 1810 | | SEC_LINKER_CREATED)) |
| 1811 | || !bfd_set_section_alignment (abfd, fptr, 4)) |
| 1812 | { |
| 1813 | BFD_ASSERT (0); |
| 1814 | return NULL; |
| 1815 | } |
| 1816 | |
| 1817 | ia64_info->fptr_sec = fptr; |
| 1818 | } |
| 1819 | |
| 1820 | return fptr; |
| 1821 | } |
| 1822 | |
| 1823 | static asection * |
| 1824 | get_pltoff (abfd, info, ia64_info) |
| 1825 | bfd *abfd; |
| 1826 | struct bfd_link_info *info ATTRIBUTE_UNUSED; |
| 1827 | struct elfNN_ia64_link_hash_table *ia64_info; |
| 1828 | { |
| 1829 | asection *pltoff; |
| 1830 | bfd *dynobj; |
| 1831 | |
| 1832 | pltoff = ia64_info->pltoff_sec; |
| 1833 | if (!pltoff) |
| 1834 | { |
| 1835 | dynobj = ia64_info->root.dynobj; |
| 1836 | if (!dynobj) |
| 1837 | ia64_info->root.dynobj = dynobj = abfd; |
| 1838 | |
| 1839 | pltoff = bfd_make_section (dynobj, ELF_STRING_ia64_pltoff); |
| 1840 | if (!pltoff |
| 1841 | || !bfd_set_section_flags (dynobj, pltoff, |
| 1842 | (SEC_ALLOC |
| 1843 | | SEC_LOAD |
| 1844 | | SEC_HAS_CONTENTS |
| 1845 | | SEC_IN_MEMORY |
| 1846 | | SEC_SMALL_DATA |
| 1847 | | SEC_LINKER_CREATED)) |
| 1848 | || !bfd_set_section_alignment (abfd, pltoff, 4)) |
| 1849 | { |
| 1850 | BFD_ASSERT (0); |
| 1851 | return NULL; |
| 1852 | } |
| 1853 | |
| 1854 | ia64_info->pltoff_sec = pltoff; |
| 1855 | } |
| 1856 | |
| 1857 | return pltoff; |
| 1858 | } |
| 1859 | |
| 1860 | static asection * |
| 1861 | get_reloc_section (abfd, ia64_info, sec, create) |
| 1862 | bfd *abfd; |
| 1863 | struct elfNN_ia64_link_hash_table *ia64_info; |
| 1864 | asection *sec; |
| 1865 | boolean create; |
| 1866 | { |
| 1867 | const char *srel_name; |
| 1868 | asection *srel; |
| 1869 | bfd *dynobj; |
| 1870 | |
| 1871 | srel_name = (bfd_elf_string_from_elf_section |
| 1872 | (abfd, elf_elfheader(abfd)->e_shstrndx, |
| 1873 | elf_section_data(sec)->rel_hdr.sh_name)); |
| 1874 | if (srel_name == NULL) |
| 1875 | return NULL; |
| 1876 | |
| 1877 | BFD_ASSERT ((strncmp (srel_name, ".rela", 5) == 0 |
| 1878 | && strcmp (bfd_get_section_name (abfd, sec), |
| 1879 | srel_name+5) == 0) |
| 1880 | || (strncmp (srel_name, ".rel", 4) == 0 |
| 1881 | && strcmp (bfd_get_section_name (abfd, sec), |
| 1882 | srel_name+4) == 0)); |
| 1883 | |
| 1884 | dynobj = ia64_info->root.dynobj; |
| 1885 | if (!dynobj) |
| 1886 | ia64_info->root.dynobj = dynobj = abfd; |
| 1887 | |
| 1888 | srel = bfd_get_section_by_name (dynobj, srel_name); |
| 1889 | if (srel == NULL && create) |
| 1890 | { |
| 1891 | srel = bfd_make_section (dynobj, srel_name); |
| 1892 | if (srel == NULL |
| 1893 | || !bfd_set_section_flags (dynobj, srel, |
| 1894 | (SEC_ALLOC |
| 1895 | | SEC_LOAD |
| 1896 | | SEC_HAS_CONTENTS |
| 1897 | | SEC_IN_MEMORY |
| 1898 | | SEC_LINKER_CREATED |
| 1899 | | SEC_READONLY)) |
| 1900 | || !bfd_set_section_alignment (dynobj, srel, 3)) |
| 1901 | return NULL; |
| 1902 | } |
| 1903 | |
| 1904 | return srel; |
| 1905 | } |
| 1906 | |
| 1907 | static boolean |
| 1908 | count_dyn_reloc (abfd, dyn_i, srel, type) |
| 1909 | bfd *abfd; |
| 1910 | struct elfNN_ia64_dyn_sym_info *dyn_i; |
| 1911 | asection *srel; |
| 1912 | int type; |
| 1913 | { |
| 1914 | struct elfNN_ia64_dyn_reloc_entry *rent; |
| 1915 | |
| 1916 | for (rent = dyn_i->reloc_entries; rent; rent = rent->next) |
| 1917 | if (rent->srel == srel && rent->type == type) |
| 1918 | break; |
| 1919 | |
| 1920 | if (!rent) |
| 1921 | { |
| 1922 | rent = (struct elfNN_ia64_dyn_reloc_entry *) |
| 1923 | bfd_alloc (abfd, sizeof (*rent)); |
| 1924 | if (!rent) |
| 1925 | return false; |
| 1926 | |
| 1927 | rent->next = dyn_i->reloc_entries; |
| 1928 | rent->srel = srel; |
| 1929 | rent->type = type; |
| 1930 | rent->count = 0; |
| 1931 | dyn_i->reloc_entries = rent; |
| 1932 | } |
| 1933 | rent->count++; |
| 1934 | |
| 1935 | return true; |
| 1936 | } |
| 1937 | |
| 1938 | static boolean |
| 1939 | elfNN_ia64_check_relocs (abfd, info, sec, relocs) |
| 1940 | bfd *abfd; |
| 1941 | struct bfd_link_info *info; |
| 1942 | asection *sec; |
| 1943 | const Elf_Internal_Rela *relocs; |
| 1944 | { |
| 1945 | struct elfNN_ia64_link_hash_table *ia64_info; |
| 1946 | const Elf_Internal_Rela *relend; |
| 1947 | Elf_Internal_Shdr *symtab_hdr; |
| 1948 | const Elf_Internal_Rela *rel; |
| 1949 | asection *got, *fptr, *srel; |
| 1950 | |
| 1951 | if (info->relocateable) |
| 1952 | return true; |
| 1953 | |
| 1954 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
| 1955 | ia64_info = elfNN_ia64_hash_table (info); |
| 1956 | |
| 1957 | got = fptr = srel = NULL; |
| 1958 | |
| 1959 | relend = relocs + sec->reloc_count; |
| 1960 | for (rel = relocs; rel < relend; ++rel) |
| 1961 | { |
| 1962 | enum { |
| 1963 | NEED_GOT = 1, |
| 1964 | NEED_FPTR = 2, |
| 1965 | NEED_PLTOFF = 4, |
| 1966 | NEED_MIN_PLT = 8, |
| 1967 | NEED_FULL_PLT = 16, |
| 1968 | NEED_DYNREL = 32, |
| 1969 | NEED_LTOFF_FPTR = 64, |
| 1970 | }; |
| 1971 | |
| 1972 | struct elf_link_hash_entry *h = NULL; |
| 1973 | unsigned long r_symndx = ELFNN_R_SYM (rel->r_info); |
| 1974 | struct elfNN_ia64_dyn_sym_info *dyn_i; |
| 1975 | int need_entry; |
| 1976 | boolean maybe_dynamic; |
| 1977 | int dynrel_type = R_IA64_NONE; |
| 1978 | |
| 1979 | if (r_symndx >= symtab_hdr->sh_info) |
| 1980 | { |
| 1981 | /* We're dealing with a global symbol -- find its hash entry |
| 1982 | and mark it as being referenced. */ |
| 1983 | long indx = r_symndx - symtab_hdr->sh_info; |
| 1984 | h = elf_sym_hashes (abfd)[indx]; |
| 1985 | while (h->root.type == bfd_link_hash_indirect |
| 1986 | || h->root.type == bfd_link_hash_warning) |
| 1987 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 1988 | |
| 1989 | h->elf_link_hash_flags |= ELF_LINK_HASH_REF_REGULAR; |
| 1990 | } |
| 1991 | |
| 1992 | /* We can only get preliminary data on whether a symbol is |
| 1993 | locally or externally defined, as not all of the input files |
| 1994 | have yet been processed. Do something with what we know, as |
| 1995 | this may help reduce memory usage and processing time later. */ |
| 1996 | maybe_dynamic = false; |
| 1997 | if (h && ((info->shared && ! info->symbolic) |
| 1998 | || ! (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) |
| 1999 | || h->root.type == bfd_link_hash_defweak |
| 2000 | || elfNN_ia64_aix_vec (abfd->xvec))) |
| 2001 | maybe_dynamic = true; |
| 2002 | |
| 2003 | need_entry = 0; |
| 2004 | switch (ELFNN_R_TYPE (rel->r_info)) |
| 2005 | { |
| 2006 | case R_IA64_TPREL22: |
| 2007 | case R_IA64_TPREL64MSB: |
| 2008 | case R_IA64_TPREL64LSB: |
| 2009 | case R_IA64_LTOFF_TP22: |
| 2010 | return false; |
| 2011 | |
| 2012 | case R_IA64_LTOFF_FPTR22: |
| 2013 | case R_IA64_LTOFF_FPTR64I: |
| 2014 | case R_IA64_LTOFF_FPTR32MSB: |
| 2015 | case R_IA64_LTOFF_FPTR32LSB: |
| 2016 | case R_IA64_LTOFF_FPTR64MSB: |
| 2017 | case R_IA64_LTOFF_FPTR64LSB: |
| 2018 | need_entry = NEED_FPTR | NEED_GOT | NEED_LTOFF_FPTR; |
| 2019 | break; |
| 2020 | |
| 2021 | case R_IA64_FPTR64I: |
| 2022 | case R_IA64_FPTR32MSB: |
| 2023 | case R_IA64_FPTR32LSB: |
| 2024 | case R_IA64_FPTR64MSB: |
| 2025 | case R_IA64_FPTR64LSB: |
| 2026 | if (info->shared || h || elfNN_ia64_aix_vec (abfd->xvec)) |
| 2027 | need_entry = NEED_FPTR | NEED_DYNREL; |
| 2028 | else |
| 2029 | need_entry = NEED_FPTR; |
| 2030 | dynrel_type = R_IA64_FPTR64LSB; |
| 2031 | break; |
| 2032 | |
| 2033 | case R_IA64_LTOFF22: |
| 2034 | case R_IA64_LTOFF22X: |
| 2035 | case R_IA64_LTOFF64I: |
| 2036 | need_entry = NEED_GOT; |
| 2037 | break; |
| 2038 | |
| 2039 | case R_IA64_PLTOFF22: |
| 2040 | case R_IA64_PLTOFF64I: |
| 2041 | case R_IA64_PLTOFF64MSB: |
| 2042 | case R_IA64_PLTOFF64LSB: |
| 2043 | need_entry = NEED_PLTOFF; |
| 2044 | if (h) |
| 2045 | { |
| 2046 | if (maybe_dynamic) |
| 2047 | need_entry |= NEED_MIN_PLT; |
| 2048 | } |
| 2049 | else |
| 2050 | { |
| 2051 | (*info->callbacks->warning) |
| 2052 | (info, _("@pltoff reloc against local symbol"), 0, |
| 2053 | abfd, 0, 0); |
| 2054 | } |
| 2055 | break; |
| 2056 | |
| 2057 | case R_IA64_PCREL21B: |
| 2058 | case R_IA64_PCREL60B: |
| 2059 | /* Depending on where this symbol is defined, we may or may not |
| 2060 | need a full plt entry. Only skip if we know we'll not need |
| 2061 | the entry -- static or symbolic, and the symbol definition |
| 2062 | has already been seen. */ |
| 2063 | if (maybe_dynamic && rel->r_addend == 0) |
| 2064 | need_entry = NEED_FULL_PLT; |
| 2065 | break; |
| 2066 | |
| 2067 | case R_IA64_IMM14: |
| 2068 | case R_IA64_IMM22: |
| 2069 | case R_IA64_IMM64: |
| 2070 | case R_IA64_DIR32MSB: |
| 2071 | case R_IA64_DIR32LSB: |
| 2072 | case R_IA64_DIR64MSB: |
| 2073 | case R_IA64_DIR64LSB: |
| 2074 | /* Shared objects will always need at least a REL relocation. */ |
| 2075 | if (info->shared || maybe_dynamic |
| 2076 | || (elfNN_ia64_aix_vec (abfd->xvec) |
| 2077 | && (!h || strcmp (h->root.root.string, |
| 2078 | "__GLOB_DATA_PTR") != 0))) |
| 2079 | need_entry = NEED_DYNREL; |
| 2080 | dynrel_type = R_IA64_DIR64LSB; |
| 2081 | break; |
| 2082 | |
| 2083 | case R_IA64_IPLTMSB: |
| 2084 | case R_IA64_IPLTLSB: |
| 2085 | /* Shared objects will always need at least a REL relocation. */ |
| 2086 | if (info->shared || maybe_dynamic) |
| 2087 | need_entry = NEED_DYNREL; |
| 2088 | dynrel_type = R_IA64_IPLTLSB; |
| 2089 | break; |
| 2090 | |
| 2091 | case R_IA64_PCREL22: |
| 2092 | case R_IA64_PCREL64I: |
| 2093 | case R_IA64_PCREL32MSB: |
| 2094 | case R_IA64_PCREL32LSB: |
| 2095 | case R_IA64_PCREL64MSB: |
| 2096 | case R_IA64_PCREL64LSB: |
| 2097 | if (maybe_dynamic) |
| 2098 | need_entry = NEED_DYNREL; |
| 2099 | dynrel_type = R_IA64_PCREL64LSB; |
| 2100 | break; |
| 2101 | } |
| 2102 | |
| 2103 | if (!need_entry) |
| 2104 | continue; |
| 2105 | |
| 2106 | if ((need_entry & NEED_FPTR) != 0 |
| 2107 | && rel->r_addend) |
| 2108 | { |
| 2109 | (*info->callbacks->warning) |
| 2110 | (info, _("non-zero addend in @fptr reloc"), 0, |
| 2111 | abfd, 0, 0); |
| 2112 | } |
| 2113 | |
| 2114 | dyn_i = get_dyn_sym_info (ia64_info, h, abfd, rel, true); |
| 2115 | |
| 2116 | /* Record whether or not this is a local symbol. */ |
| 2117 | dyn_i->h = h; |
| 2118 | |
| 2119 | /* Create what's needed. */ |
| 2120 | if (need_entry & NEED_GOT) |
| 2121 | { |
| 2122 | if (!got) |
| 2123 | { |
| 2124 | got = get_got (abfd, info, ia64_info); |
| 2125 | if (!got) |
| 2126 | return false; |
| 2127 | } |
| 2128 | dyn_i->want_got = 1; |
| 2129 | } |
| 2130 | if (need_entry & NEED_FPTR) |
| 2131 | { |
| 2132 | if (!fptr) |
| 2133 | { |
| 2134 | fptr = get_fptr (abfd, info, ia64_info); |
| 2135 | if (!fptr) |
| 2136 | return false; |
| 2137 | } |
| 2138 | |
| 2139 | /* FPTRs for shared libraries are allocated by the dynamic |
| 2140 | linker. Make sure this local symbol will appear in the |
| 2141 | dynamic symbol table. */ |
| 2142 | if (!h && (info->shared |
| 2143 | /* AIX also needs one */ |
| 2144 | || elfNN_ia64_aix_vec (abfd->xvec))) |
| 2145 | { |
| 2146 | if (! (_bfd_elfNN_link_record_local_dynamic_symbol |
| 2147 | (info, abfd, r_symndx))) |
| 2148 | return false; |
| 2149 | } |
| 2150 | |
| 2151 | dyn_i->want_fptr = 1; |
| 2152 | } |
| 2153 | if (need_entry & NEED_LTOFF_FPTR) |
| 2154 | dyn_i->want_ltoff_fptr = 1; |
| 2155 | if (need_entry & (NEED_MIN_PLT | NEED_FULL_PLT)) |
| 2156 | { |
| 2157 | if (!ia64_info->root.dynobj) |
| 2158 | ia64_info->root.dynobj = abfd; |
| 2159 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; |
| 2160 | dyn_i->want_plt = 1; |
| 2161 | } |
| 2162 | if (need_entry & NEED_FULL_PLT) |
| 2163 | dyn_i->want_plt2 = 1; |
| 2164 | if (need_entry & NEED_PLTOFF) |
| 2165 | dyn_i->want_pltoff = 1; |
| 2166 | if ((need_entry & NEED_DYNREL) && (sec->flags & SEC_ALLOC)) |
| 2167 | { |
| 2168 | if (!srel) |
| 2169 | { |
| 2170 | srel = get_reloc_section (abfd, ia64_info, sec, true); |
| 2171 | if (!srel) |
| 2172 | return false; |
| 2173 | } |
| 2174 | if (!count_dyn_reloc (abfd, dyn_i, srel, dynrel_type)) |
| 2175 | return false; |
| 2176 | } |
| 2177 | } |
| 2178 | |
| 2179 | return true; |
| 2180 | } |
| 2181 | |
| 2182 | struct elfNN_ia64_allocate_data |
| 2183 | { |
| 2184 | struct bfd_link_info *info; |
| 2185 | bfd_size_type ofs; |
| 2186 | }; |
| 2187 | |
| 2188 | /* For cleanliness, and potentially faster dynamic loading, allocate |
| 2189 | external GOT entries first. */ |
| 2190 | |
| 2191 | static boolean |
| 2192 | allocate_global_data_got (dyn_i, data) |
| 2193 | struct elfNN_ia64_dyn_sym_info *dyn_i; |
| 2194 | PTR data; |
| 2195 | { |
| 2196 | struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data; |
| 2197 | |
| 2198 | if (dyn_i->want_got |
| 2199 | && ! dyn_i->want_fptr |
| 2200 | && (elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info) |
| 2201 | || (elfNN_ia64_aix_vec (x->info->hash->creator) |
| 2202 | && (!dyn_i->h || strcmp (dyn_i->h->root.root.string, |
| 2203 | "__GLOB_DATA_PTR") != 0)))) |
| 2204 | { |
| 2205 | dyn_i->got_offset = x->ofs; |
| 2206 | x->ofs += 8; |
| 2207 | } |
| 2208 | return true; |
| 2209 | } |
| 2210 | |
| 2211 | /* Next, allocate all the GOT entries used by LTOFF_FPTR relocs. */ |
| 2212 | |
| 2213 | static boolean |
| 2214 | allocate_global_fptr_got (dyn_i, data) |
| 2215 | struct elfNN_ia64_dyn_sym_info *dyn_i; |
| 2216 | PTR data; |
| 2217 | { |
| 2218 | struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data; |
| 2219 | |
| 2220 | if (dyn_i->want_got |
| 2221 | && dyn_i->want_fptr |
| 2222 | && (elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info) |
| 2223 | || elfNN_ia64_aix_vec (x->info->hash->creator))) |
| 2224 | { |
| 2225 | dyn_i->got_offset = x->ofs; |
| 2226 | x->ofs += 8; |
| 2227 | } |
| 2228 | return true; |
| 2229 | } |
| 2230 | |
| 2231 | /* Lastly, allocate all the GOT entries for local data. */ |
| 2232 | |
| 2233 | static boolean |
| 2234 | allocate_local_got (dyn_i, data) |
| 2235 | struct elfNN_ia64_dyn_sym_info *dyn_i; |
| 2236 | PTR data; |
| 2237 | { |
| 2238 | struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data; |
| 2239 | |
| 2240 | if (dyn_i->want_got |
| 2241 | && ! (elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info) |
| 2242 | || elfNN_ia64_aix_vec (x->info->hash->creator))) |
| 2243 | { |
| 2244 | dyn_i->got_offset = x->ofs; |
| 2245 | x->ofs += 8; |
| 2246 | } |
| 2247 | return true; |
| 2248 | } |
| 2249 | |
| 2250 | /* Search for the index of a global symbol in it's defining object file. */ |
| 2251 | |
| 2252 | static unsigned long |
| 2253 | global_sym_index (h) |
| 2254 | struct elf_link_hash_entry *h; |
| 2255 | { |
| 2256 | struct elf_link_hash_entry **p; |
| 2257 | bfd *obj; |
| 2258 | |
| 2259 | BFD_ASSERT (h->root.type == bfd_link_hash_defined |
| 2260 | || h->root.type == bfd_link_hash_defweak); |
| 2261 | |
| 2262 | obj = h->root.u.def.section->owner; |
| 2263 | for (p = elf_sym_hashes (obj); *p != h; ++p) |
| 2264 | continue; |
| 2265 | |
| 2266 | return p - elf_sym_hashes (obj) + elf_tdata (obj)->symtab_hdr.sh_info; |
| 2267 | } |
| 2268 | |
| 2269 | /* Allocate function descriptors. We can do these for every function |
| 2270 | in a main executable that is not exported. */ |
| 2271 | |
| 2272 | static boolean |
| 2273 | allocate_fptr (dyn_i, data) |
| 2274 | struct elfNN_ia64_dyn_sym_info *dyn_i; |
| 2275 | PTR data; |
| 2276 | { |
| 2277 | struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data; |
| 2278 | |
| 2279 | if (dyn_i->want_fptr) |
| 2280 | { |
| 2281 | struct elf_link_hash_entry *h = dyn_i->h; |
| 2282 | |
| 2283 | if (h) |
| 2284 | while (h->root.type == bfd_link_hash_indirect |
| 2285 | || h->root.type == bfd_link_hash_warning) |
| 2286 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 2287 | |
| 2288 | if (x->info->shared |
| 2289 | /* AIX needs an FPTR in this case. */ |
| 2290 | || (elfNN_ia64_aix_vec (x->info->hash->creator) |
| 2291 | && (!h |
| 2292 | || h->root.type == bfd_link_hash_defined |
| 2293 | || h->root.type == bfd_link_hash_defweak))) |
| 2294 | { |
| 2295 | if (h && h->dynindx == -1) |
| 2296 | { |
| 2297 | BFD_ASSERT ((h->root.type == bfd_link_hash_defined) |
| 2298 | || (h->root.type == bfd_link_hash_defweak)); |
| 2299 | |
| 2300 | if (!_bfd_elfNN_link_record_local_dynamic_symbol |
| 2301 | (x->info, h->root.u.def.section->owner, |
| 2302 | global_sym_index (h))) |
| 2303 | return false; |
| 2304 | } |
| 2305 | |
| 2306 | dyn_i->want_fptr = 0; |
| 2307 | } |
| 2308 | else if (h == NULL || h->dynindx == -1) |
| 2309 | { |
| 2310 | dyn_i->fptr_offset = x->ofs; |
| 2311 | x->ofs += 16; |
| 2312 | } |
| 2313 | else |
| 2314 | dyn_i->want_fptr = 0; |
| 2315 | } |
| 2316 | return true; |
| 2317 | } |
| 2318 | |
| 2319 | /* Allocate all the minimal PLT entries. */ |
| 2320 | |
| 2321 | static boolean |
| 2322 | allocate_plt_entries (dyn_i, data) |
| 2323 | struct elfNN_ia64_dyn_sym_info *dyn_i; |
| 2324 | PTR data; |
| 2325 | { |
| 2326 | struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data; |
| 2327 | |
| 2328 | if (dyn_i->want_plt) |
| 2329 | { |
| 2330 | struct elf_link_hash_entry *h = dyn_i->h; |
| 2331 | |
| 2332 | if (h) |
| 2333 | while (h->root.type == bfd_link_hash_indirect |
| 2334 | || h->root.type == bfd_link_hash_warning) |
| 2335 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 2336 | |
| 2337 | /* ??? Versioned symbols seem to lose ELF_LINK_HASH_NEEDS_PLT. */ |
| 2338 | if (elfNN_ia64_dynamic_symbol_p (h, x->info)) |
| 2339 | { |
| 2340 | bfd_size_type offset = x->ofs; |
| 2341 | if (offset == 0) |
| 2342 | offset = PLT_HEADER_SIZE; |
| 2343 | dyn_i->plt_offset = offset; |
| 2344 | x->ofs = offset + PLT_MIN_ENTRY_SIZE; |
| 2345 | |
| 2346 | dyn_i->want_pltoff = 1; |
| 2347 | } |
| 2348 | else |
| 2349 | { |
| 2350 | dyn_i->want_plt = 0; |
| 2351 | dyn_i->want_plt2 = 0; |
| 2352 | } |
| 2353 | } |
| 2354 | return true; |
| 2355 | } |
| 2356 | |
| 2357 | /* Allocate all the full PLT entries. */ |
| 2358 | |
| 2359 | static boolean |
| 2360 | allocate_plt2_entries (dyn_i, data) |
| 2361 | struct elfNN_ia64_dyn_sym_info *dyn_i; |
| 2362 | PTR data; |
| 2363 | { |
| 2364 | struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data; |
| 2365 | |
| 2366 | if (dyn_i->want_plt2) |
| 2367 | { |
| 2368 | struct elf_link_hash_entry *h = dyn_i->h; |
| 2369 | bfd_size_type ofs = x->ofs; |
| 2370 | |
| 2371 | dyn_i->plt2_offset = ofs; |
| 2372 | x->ofs = ofs + PLT_FULL_ENTRY_SIZE; |
| 2373 | |
| 2374 | while (h->root.type == bfd_link_hash_indirect |
| 2375 | || h->root.type == bfd_link_hash_warning) |
| 2376 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 2377 | dyn_i->h->plt.offset = ofs; |
| 2378 | } |
| 2379 | return true; |
| 2380 | } |
| 2381 | |
| 2382 | /* Allocate all the PLTOFF entries requested by relocations and |
| 2383 | plt entries. We can't share space with allocated FPTR entries, |
| 2384 | because the latter are not necessarily addressable by the GP. |
| 2385 | ??? Relaxation might be able to determine that they are. */ |
| 2386 | |
| 2387 | static boolean |
| 2388 | allocate_pltoff_entries (dyn_i, data) |
| 2389 | struct elfNN_ia64_dyn_sym_info *dyn_i; |
| 2390 | PTR data; |
| 2391 | { |
| 2392 | struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data; |
| 2393 | |
| 2394 | if (dyn_i->want_pltoff) |
| 2395 | { |
| 2396 | dyn_i->pltoff_offset = x->ofs; |
| 2397 | x->ofs += 16; |
| 2398 | } |
| 2399 | return true; |
| 2400 | } |
| 2401 | |
| 2402 | /* Allocate dynamic relocations for those symbols that turned out |
| 2403 | to be dynamic. */ |
| 2404 | |
| 2405 | static boolean |
| 2406 | allocate_dynrel_entries (dyn_i, data) |
| 2407 | struct elfNN_ia64_dyn_sym_info *dyn_i; |
| 2408 | PTR data; |
| 2409 | { |
| 2410 | struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data; |
| 2411 | struct elfNN_ia64_link_hash_table *ia64_info; |
| 2412 | struct elfNN_ia64_dyn_reloc_entry *rent; |
| 2413 | boolean dynamic_symbol, shared; |
| 2414 | |
| 2415 | ia64_info = elfNN_ia64_hash_table (x->info); |
| 2416 | dynamic_symbol = elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info) |
| 2417 | || (elfNN_ia64_aix_vec (x->info->hash->creator) |
| 2418 | /* Don't allocate an entry for __GLOB_DATA_PTR */ |
| 2419 | && (!dyn_i->h || strcmp (dyn_i->h->root.root.string, |
| 2420 | "__GLOB_DATA_PTR") != 0)); |
| 2421 | shared = x->info->shared; |
| 2422 | |
| 2423 | /* Take care of the normal data relocations. */ |
| 2424 | |
| 2425 | for (rent = dyn_i->reloc_entries; rent; rent = rent->next) |
| 2426 | { |
| 2427 | int count = rent->count; |
| 2428 | |
| 2429 | switch (rent->type) |
| 2430 | { |
| 2431 | case R_IA64_FPTR64LSB: |
| 2432 | /* Allocate one iff !want_fptr, which by this point will |
| 2433 | be true only if we're actually allocating one statically |
| 2434 | in the main executable. */ |
| 2435 | if (dyn_i->want_fptr) |
| 2436 | continue; |
| 2437 | break; |
| 2438 | case R_IA64_PCREL64LSB: |
| 2439 | if (!dynamic_symbol) |
| 2440 | continue; |
| 2441 | break; |
| 2442 | case R_IA64_DIR64LSB: |
| 2443 | if (!dynamic_symbol && !shared) |
| 2444 | continue; |
| 2445 | break; |
| 2446 | case R_IA64_IPLTLSB: |
| 2447 | if (!dynamic_symbol && !shared) |
| 2448 | continue; |
| 2449 | /* Use two REL relocations for IPLT relocations |
| 2450 | against local symbols. */ |
| 2451 | if (!dynamic_symbol) |
| 2452 | count *= 2; |
| 2453 | break; |
| 2454 | default: |
| 2455 | abort (); |
| 2456 | } |
| 2457 | rent->srel->_raw_size += sizeof (ElfNN_External_Rela) * count; |
| 2458 | } |
| 2459 | |
| 2460 | /* Take care of the GOT and PLT relocations. */ |
| 2461 | |
| 2462 | if (((dynamic_symbol || shared) && dyn_i->want_got) |
| 2463 | || (dyn_i->want_ltoff_fptr && dyn_i->h && dyn_i->h->dynindx != -1)) |
| 2464 | ia64_info->rel_got_sec->_raw_size += sizeof (ElfNN_External_Rela); |
| 2465 | |
| 2466 | if (dyn_i->want_pltoff) |
| 2467 | { |
| 2468 | bfd_size_type t = 0; |
| 2469 | |
| 2470 | /* Dynamic symbols get one IPLT relocation. Local symbols in |
| 2471 | shared libraries get two REL relocations. Local symbols in |
| 2472 | main applications get nothing. */ |
| 2473 | if (dynamic_symbol) |
| 2474 | t = sizeof (ElfNN_External_Rela); |
| 2475 | else if (shared) |
| 2476 | t = 2 * sizeof (ElfNN_External_Rela); |
| 2477 | |
| 2478 | ia64_info->rel_pltoff_sec->_raw_size += t; |
| 2479 | } |
| 2480 | |
| 2481 | return true; |
| 2482 | } |
| 2483 | |
| 2484 | static boolean |
| 2485 | elfNN_ia64_adjust_dynamic_symbol (info, h) |
| 2486 | struct bfd_link_info *info ATTRIBUTE_UNUSED; |
| 2487 | struct elf_link_hash_entry *h; |
| 2488 | { |
| 2489 | /* ??? Undefined symbols with PLT entries should be re-defined |
| 2490 | to be the PLT entry. */ |
| 2491 | |
| 2492 | /* If this is a weak symbol, and there is a real definition, the |
| 2493 | processor independent code will have arranged for us to see the |
| 2494 | real definition first, and we can just use the same value. */ |
| 2495 | if (h->weakdef != NULL) |
| 2496 | { |
| 2497 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined |
| 2498 | || h->weakdef->root.type == bfd_link_hash_defweak); |
| 2499 | h->root.u.def.section = h->weakdef->root.u.def.section; |
| 2500 | h->root.u.def.value = h->weakdef->root.u.def.value; |
| 2501 | return true; |
| 2502 | } |
| 2503 | |
| 2504 | /* If this is a reference to a symbol defined by a dynamic object which |
| 2505 | is not a function, we might allocate the symbol in our .dynbss section |
| 2506 | and allocate a COPY dynamic relocation. |
| 2507 | |
| 2508 | But IA-64 code is canonically PIC, so as a rule we can avoid this sort |
| 2509 | of hackery. */ |
| 2510 | |
| 2511 | return true; |
| 2512 | } |
| 2513 | |
| 2514 | static boolean |
| 2515 | elfNN_ia64_size_dynamic_sections (output_bfd, info) |
| 2516 | bfd *output_bfd; |
| 2517 | struct bfd_link_info *info; |
| 2518 | { |
| 2519 | struct elfNN_ia64_allocate_data data; |
| 2520 | struct elfNN_ia64_link_hash_table *ia64_info; |
| 2521 | asection *sec; |
| 2522 | bfd *dynobj; |
| 2523 | boolean reltext = false; |
| 2524 | boolean relplt = false; |
| 2525 | |
| 2526 | dynobj = elf_hash_table(info)->dynobj; |
| 2527 | ia64_info = elfNN_ia64_hash_table (info); |
| 2528 | BFD_ASSERT(dynobj != NULL); |
| 2529 | data.info = info; |
| 2530 | |
| 2531 | /* Set the contents of the .interp section to the interpreter. */ |
| 2532 | if (ia64_info->root.dynamic_sections_created |
| 2533 | && !info->shared) |
| 2534 | { |
| 2535 | sec = bfd_get_section_by_name (dynobj, ".interp"); |
| 2536 | BFD_ASSERT (sec != NULL); |
| 2537 | sec->contents = (bfd_byte *) DYNAMIC_INTERPRETER (output_bfd); |
| 2538 | sec->_raw_size = strlen (DYNAMIC_INTERPRETER (output_bfd)) + 1; |
| 2539 | } |
| 2540 | |
| 2541 | /* Allocate the GOT entries. */ |
| 2542 | |
| 2543 | if (ia64_info->got_sec) |
| 2544 | { |
| 2545 | data.ofs = 0; |
| 2546 | elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_global_data_got, &data); |
| 2547 | elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_global_fptr_got, &data); |
| 2548 | elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_local_got, &data); |
| 2549 | ia64_info->got_sec->_raw_size = data.ofs; |
| 2550 | } |
| 2551 | |
| 2552 | /* Allocate the FPTR entries. */ |
| 2553 | |
| 2554 | if (ia64_info->fptr_sec) |
| 2555 | { |
| 2556 | data.ofs = 0; |
| 2557 | elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_fptr, &data); |
| 2558 | ia64_info->fptr_sec->_raw_size = data.ofs; |
| 2559 | } |
| 2560 | |
| 2561 | /* Now that we've seen all of the input files, we can decide which |
| 2562 | symbols need plt entries. Allocate the minimal PLT entries first. |
| 2563 | We do this even though dynamic_sections_created may be false, because |
| 2564 | this has the side-effect of clearing want_plt and want_plt2. */ |
| 2565 | |
| 2566 | data.ofs = 0; |
| 2567 | elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_plt_entries, &data); |
| 2568 | |
| 2569 | ia64_info->minplt_entries = 0; |
| 2570 | if (data.ofs) |
| 2571 | { |
| 2572 | ia64_info->minplt_entries |
| 2573 | = (data.ofs - PLT_HEADER_SIZE) / PLT_MIN_ENTRY_SIZE; |
| 2574 | } |
| 2575 | |
| 2576 | /* Align the pointer for the plt2 entries. */ |
| 2577 | data.ofs = (data.ofs + 31) & -32; |
| 2578 | |
| 2579 | elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_plt2_entries, &data); |
| 2580 | if (data.ofs != 0) |
| 2581 | { |
| 2582 | BFD_ASSERT (ia64_info->root.dynamic_sections_created); |
| 2583 | |
| 2584 | ia64_info->plt_sec->_raw_size = data.ofs; |
| 2585 | |
| 2586 | /* If we've got a .plt, we need some extra memory for the dynamic |
| 2587 | linker. We stuff these in .got.plt. */ |
| 2588 | sec = bfd_get_section_by_name (dynobj, ".got.plt"); |
| 2589 | sec->_raw_size = 8 * PLT_RESERVED_WORDS; |
| 2590 | } |
| 2591 | |
| 2592 | /* Allocate the PLTOFF entries. */ |
| 2593 | |
| 2594 | if (ia64_info->pltoff_sec) |
| 2595 | { |
| 2596 | data.ofs = 0; |
| 2597 | elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_pltoff_entries, &data); |
| 2598 | ia64_info->pltoff_sec->_raw_size = data.ofs; |
| 2599 | } |
| 2600 | |
| 2601 | if (ia64_info->root.dynamic_sections_created) |
| 2602 | { |
| 2603 | /* Allocate space for the dynamic relocations that turned out to be |
| 2604 | required. */ |
| 2605 | |
| 2606 | elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_dynrel_entries, &data); |
| 2607 | } |
| 2608 | |
| 2609 | /* We have now determined the sizes of the various dynamic sections. |
| 2610 | Allocate memory for them. */ |
| 2611 | for (sec = dynobj->sections; sec != NULL; sec = sec->next) |
| 2612 | { |
| 2613 | boolean strip; |
| 2614 | |
| 2615 | if (!(sec->flags & SEC_LINKER_CREATED)) |
| 2616 | continue; |
| 2617 | |
| 2618 | /* If we don't need this section, strip it from the output file. |
| 2619 | There were several sections primarily related to dynamic |
| 2620 | linking that must be create before the linker maps input |
| 2621 | sections to output sections. The linker does that before |
| 2622 | bfd_elf_size_dynamic_sections is called, and it is that |
| 2623 | function which decides whether anything needs to go into |
| 2624 | these sections. */ |
| 2625 | |
| 2626 | strip = (sec->_raw_size == 0); |
| 2627 | |
| 2628 | if (sec == ia64_info->got_sec) |
| 2629 | strip = false; |
| 2630 | else if (sec == ia64_info->rel_got_sec) |
| 2631 | { |
| 2632 | if (strip) |
| 2633 | ia64_info->rel_got_sec = NULL; |
| 2634 | else |
| 2635 | /* We use the reloc_count field as a counter if we need to |
| 2636 | copy relocs into the output file. */ |
| 2637 | sec->reloc_count = 0; |
| 2638 | } |
| 2639 | else if (sec == ia64_info->fptr_sec) |
| 2640 | { |
| 2641 | if (strip) |
| 2642 | ia64_info->fptr_sec = NULL; |
| 2643 | } |
| 2644 | else if (sec == ia64_info->plt_sec) |
| 2645 | { |
| 2646 | if (strip) |
| 2647 | ia64_info->plt_sec = NULL; |
| 2648 | } |
| 2649 | else if (sec == ia64_info->pltoff_sec) |
| 2650 | { |
| 2651 | if (strip) |
| 2652 | ia64_info->pltoff_sec = NULL; |
| 2653 | } |
| 2654 | else if (sec == ia64_info->rel_pltoff_sec) |
| 2655 | { |
| 2656 | if (strip) |
| 2657 | ia64_info->rel_pltoff_sec = NULL; |
| 2658 | else |
| 2659 | { |
| 2660 | relplt = true; |
| 2661 | /* We use the reloc_count field as a counter if we need to |
| 2662 | copy relocs into the output file. */ |
| 2663 | sec->reloc_count = 0; |
| 2664 | } |
| 2665 | } |
| 2666 | else |
| 2667 | { |
| 2668 | const char *name; |
| 2669 | |
| 2670 | /* It's OK to base decisions on the section name, because none |
| 2671 | of the dynobj section names depend upon the input files. */ |
| 2672 | name = bfd_get_section_name (dynobj, sec); |
| 2673 | |
| 2674 | if (strcmp (name, ".got.plt") == 0) |
| 2675 | strip = false; |
| 2676 | else if (strncmp (name, ".rel", 4) == 0) |
| 2677 | { |
| 2678 | if (!strip) |
| 2679 | { |
| 2680 | const char *outname; |
| 2681 | asection *target; |
| 2682 | |
| 2683 | /* If this relocation section applies to a read only |
| 2684 | section, then we probably need a DT_TEXTREL entry. */ |
| 2685 | outname = bfd_get_section_name (output_bfd, |
| 2686 | sec->output_section); |
| 2687 | if (outname[4] == 'a') |
| 2688 | outname += 5; |
| 2689 | else |
| 2690 | outname += 4; |
| 2691 | |
| 2692 | target = bfd_get_section_by_name (output_bfd, outname); |
| 2693 | if (target != NULL |
| 2694 | && (target->flags & SEC_READONLY) != 0 |
| 2695 | && (target->flags & SEC_ALLOC) != 0) |
| 2696 | reltext = true; |
| 2697 | |
| 2698 | /* We use the reloc_count field as a counter if we need to |
| 2699 | copy relocs into the output file. */ |
| 2700 | sec->reloc_count = 0; |
| 2701 | } |
| 2702 | } |
| 2703 | else |
| 2704 | continue; |
| 2705 | } |
| 2706 | |
| 2707 | if (strip) |
| 2708 | _bfd_strip_section_from_output (info, sec); |
| 2709 | else |
| 2710 | { |
| 2711 | /* Allocate memory for the section contents. */ |
| 2712 | sec->contents = (bfd_byte *) bfd_zalloc(dynobj, sec->_raw_size); |
| 2713 | if (sec->contents == NULL && sec->_raw_size != 0) |
| 2714 | return false; |
| 2715 | } |
| 2716 | } |
| 2717 | |
| 2718 | if (elf_hash_table (info)->dynamic_sections_created) |
| 2719 | { |
| 2720 | /* Add some entries to the .dynamic section. We fill in the values |
| 2721 | later (in finish_dynamic_sections) but we must add the entries now |
| 2722 | so that we get the correct size for the .dynamic section. */ |
| 2723 | |
| 2724 | if (!info->shared) |
| 2725 | { |
| 2726 | /* The DT_DEBUG entry is filled in by the dynamic linker and used |
| 2727 | by the debugger. */ |
| 2728 | if (!bfd_elfNN_add_dynamic_entry (info, DT_DEBUG, 0)) |
| 2729 | return false; |
| 2730 | } |
| 2731 | |
| 2732 | if (! bfd_elfNN_add_dynamic_entry (info, DT_IA_64_PLT_RESERVE, 0)) |
| 2733 | return false; |
| 2734 | if (! bfd_elfNN_add_dynamic_entry (info, DT_PLTGOT, 0)) |
| 2735 | return false; |
| 2736 | |
| 2737 | if (relplt) |
| 2738 | { |
| 2739 | if (! bfd_elfNN_add_dynamic_entry (info, DT_PLTRELSZ, 0) |
| 2740 | || ! bfd_elfNN_add_dynamic_entry (info, DT_PLTREL, DT_RELA) |
| 2741 | || ! bfd_elfNN_add_dynamic_entry (info, DT_JMPREL, 0)) |
| 2742 | return false; |
| 2743 | } |
| 2744 | |
| 2745 | if (! bfd_elfNN_add_dynamic_entry (info, DT_RELA, 0) |
| 2746 | || ! bfd_elfNN_add_dynamic_entry (info, DT_RELASZ, 0) |
| 2747 | || ! bfd_elfNN_add_dynamic_entry (info, DT_RELAENT, |
| 2748 | sizeof (ElfNN_External_Rela))) |
| 2749 | return false; |
| 2750 | |
| 2751 | if (reltext) |
| 2752 | { |
| 2753 | if (! bfd_elfNN_add_dynamic_entry (info, DT_TEXTREL, 0)) |
| 2754 | return false; |
| 2755 | info->flags |= DF_TEXTREL; |
| 2756 | } |
| 2757 | } |
| 2758 | |
| 2759 | /* ??? Perhaps force __gp local. */ |
| 2760 | |
| 2761 | return true; |
| 2762 | } |
| 2763 | |
| 2764 | static bfd_reloc_status_type |
| 2765 | elfNN_ia64_install_value (abfd, hit_addr, val, r_type) |
| 2766 | bfd *abfd; |
| 2767 | bfd_byte *hit_addr; |
| 2768 | bfd_vma val; |
| 2769 | unsigned int r_type; |
| 2770 | { |
| 2771 | const struct ia64_operand *op; |
| 2772 | int bigendian = 0, shift = 0; |
| 2773 | bfd_vma t0, t1, insn, dword; |
| 2774 | enum ia64_opnd opnd; |
| 2775 | const char *err; |
| 2776 | size_t size = 8; |
| 2777 | |
| 2778 | opnd = IA64_OPND_NIL; |
| 2779 | switch (r_type) |
| 2780 | { |
| 2781 | case R_IA64_NONE: |
| 2782 | case R_IA64_LDXMOV: |
| 2783 | return bfd_reloc_ok; |
| 2784 | |
| 2785 | /* Instruction relocations. */ |
| 2786 | |
| 2787 | case R_IA64_IMM14: opnd = IA64_OPND_IMM14; break; |
| 2788 | |
| 2789 | case R_IA64_PCREL21F: opnd = IA64_OPND_TGT25; break; |
| 2790 | case R_IA64_PCREL21M: opnd = IA64_OPND_TGT25b; break; |
| 2791 | case R_IA64_PCREL60B: opnd = IA64_OPND_TGT64; break; |
| 2792 | case R_IA64_PCREL21B: |
| 2793 | case R_IA64_PCREL21BI: |
| 2794 | opnd = IA64_OPND_TGT25c; |
| 2795 | break; |
| 2796 | |
| 2797 | case R_IA64_IMM22: |
| 2798 | case R_IA64_GPREL22: |
| 2799 | case R_IA64_LTOFF22: |
| 2800 | case R_IA64_LTOFF22X: |
| 2801 | case R_IA64_PLTOFF22: |
| 2802 | case R_IA64_PCREL22: |
| 2803 | case R_IA64_LTOFF_FPTR22: |
| 2804 | opnd = IA64_OPND_IMM22; |
| 2805 | break; |
| 2806 | |
| 2807 | case R_IA64_IMM64: |
| 2808 | case R_IA64_GPREL64I: |
| 2809 | case R_IA64_LTOFF64I: |
| 2810 | case R_IA64_PLTOFF64I: |
| 2811 | case R_IA64_PCREL64I: |
| 2812 | case R_IA64_FPTR64I: |
| 2813 | case R_IA64_LTOFF_FPTR64I: |
| 2814 | opnd = IA64_OPND_IMMU64; |
| 2815 | break; |
| 2816 | |
| 2817 | /* Data relocations. */ |
| 2818 | |
| 2819 | case R_IA64_DIR32MSB: |
| 2820 | case R_IA64_GPREL32MSB: |
| 2821 | case R_IA64_FPTR32MSB: |
| 2822 | case R_IA64_PCREL32MSB: |
| 2823 | case R_IA64_LTOFF_FPTR32MSB: |
| 2824 | case R_IA64_SEGREL32MSB: |
| 2825 | case R_IA64_SECREL32MSB: |
| 2826 | case R_IA64_LTV32MSB: |
| 2827 | size = 4; bigendian = 1; |
| 2828 | break; |
| 2829 | |
| 2830 | case R_IA64_DIR32LSB: |
| 2831 | case R_IA64_GPREL32LSB: |
| 2832 | case R_IA64_FPTR32LSB: |
| 2833 | case R_IA64_PCREL32LSB: |
| 2834 | case R_IA64_LTOFF_FPTR32LSB: |
| 2835 | case R_IA64_SEGREL32LSB: |
| 2836 | case R_IA64_SECREL32LSB: |
| 2837 | case R_IA64_LTV32LSB: |
| 2838 | size = 4; bigendian = 0; |
| 2839 | break; |
| 2840 | |
| 2841 | case R_IA64_DIR64MSB: |
| 2842 | case R_IA64_GPREL64MSB: |
| 2843 | case R_IA64_PLTOFF64MSB: |
| 2844 | case R_IA64_FPTR64MSB: |
| 2845 | case R_IA64_PCREL64MSB: |
| 2846 | case R_IA64_LTOFF_FPTR64MSB: |
| 2847 | case R_IA64_SEGREL64MSB: |
| 2848 | case R_IA64_SECREL64MSB: |
| 2849 | case R_IA64_LTV64MSB: |
| 2850 | size = 8; bigendian = 1; |
| 2851 | break; |
| 2852 | |
| 2853 | case R_IA64_DIR64LSB: |
| 2854 | case R_IA64_GPREL64LSB: |
| 2855 | case R_IA64_PLTOFF64LSB: |
| 2856 | case R_IA64_FPTR64LSB: |
| 2857 | case R_IA64_PCREL64LSB: |
| 2858 | case R_IA64_LTOFF_FPTR64LSB: |
| 2859 | case R_IA64_SEGREL64LSB: |
| 2860 | case R_IA64_SECREL64LSB: |
| 2861 | case R_IA64_LTV64LSB: |
| 2862 | size = 8; bigendian = 0; |
| 2863 | break; |
| 2864 | |
| 2865 | /* Unsupported / Dynamic relocations. */ |
| 2866 | default: |
| 2867 | return bfd_reloc_notsupported; |
| 2868 | } |
| 2869 | |
| 2870 | switch (opnd) |
| 2871 | { |
| 2872 | case IA64_OPND_IMMU64: |
| 2873 | hit_addr -= (long) hit_addr & 0x3; |
| 2874 | t0 = bfd_get_64 (abfd, hit_addr); |
| 2875 | t1 = bfd_get_64 (abfd, hit_addr + 8); |
| 2876 | |
| 2877 | /* tmpl/s: bits 0.. 5 in t0 |
| 2878 | slot 0: bits 5..45 in t0 |
| 2879 | slot 1: bits 46..63 in t0, bits 0..22 in t1 |
| 2880 | slot 2: bits 23..63 in t1 */ |
| 2881 | |
| 2882 | /* First, clear the bits that form the 64 bit constant. */ |
| 2883 | t0 &= ~(0x3ffffLL << 46); |
| 2884 | t1 &= ~(0x7fffffLL |
| 2885 | | (( (0x07fLL << 13) | (0x1ffLL << 27) |
| 2886 | | (0x01fLL << 22) | (0x001LL << 21) |
| 2887 | | (0x001LL << 36)) << 23)); |
| 2888 | |
| 2889 | t0 |= ((val >> 22) & 0x03ffffLL) << 46; /* 18 lsbs of imm41 */ |
| 2890 | t1 |= ((val >> 40) & 0x7fffffLL) << 0; /* 23 msbs of imm41 */ |
| 2891 | t1 |= ( (((val >> 0) & 0x07f) << 13) /* imm7b */ |
| 2892 | | (((val >> 7) & 0x1ff) << 27) /* imm9d */ |
| 2893 | | (((val >> 16) & 0x01f) << 22) /* imm5c */ |
| 2894 | | (((val >> 21) & 0x001) << 21) /* ic */ |
| 2895 | | (((val >> 63) & 0x001) << 36)) << 23; /* i */ |
| 2896 | |
| 2897 | bfd_put_64 (abfd, t0, hit_addr); |
| 2898 | bfd_put_64 (abfd, t1, hit_addr + 8); |
| 2899 | break; |
| 2900 | |
| 2901 | case IA64_OPND_TGT64: |
| 2902 | hit_addr -= (long) hit_addr & 0x3; |
| 2903 | t0 = bfd_get_64 (abfd, hit_addr); |
| 2904 | t1 = bfd_get_64 (abfd, hit_addr + 8); |
| 2905 | |
| 2906 | /* tmpl/s: bits 0.. 5 in t0 |
| 2907 | slot 0: bits 5..45 in t0 |
| 2908 | slot 1: bits 46..63 in t0, bits 0..22 in t1 |
| 2909 | slot 2: bits 23..63 in t1 */ |
| 2910 | |
| 2911 | /* First, clear the bits that form the 64 bit constant. */ |
| 2912 | t0 &= ~(0x3ffffLL << 46); |
| 2913 | t1 &= ~(0x7fffffLL |
| 2914 | | ((1LL << 36 | 0xfffffLL << 13) << 23)); |
| 2915 | |
| 2916 | val >>= 4; |
| 2917 | t0 |= ((val >> 20) & 0xffffLL) << 2 << 46; /* 16 lsbs of imm39 */ |
| 2918 | t1 |= ((val >> 36) & 0x7fffffLL) << 0; /* 23 msbs of imm39 */ |
| 2919 | t1 |= ((((val >> 0) & 0xfffffLL) << 13) /* imm20b */ |
| 2920 | | (((val >> 59) & 0x1LL) << 36)) << 23; /* i */ |
| 2921 | |
| 2922 | bfd_put_64 (abfd, t0, hit_addr); |
| 2923 | bfd_put_64 (abfd, t1, hit_addr + 8); |
| 2924 | break; |
| 2925 | |
| 2926 | default: |
| 2927 | switch ((long) hit_addr & 0x3) |
| 2928 | { |
| 2929 | case 0: shift = 5; break; |
| 2930 | case 1: shift = 14; hit_addr += 3; break; |
| 2931 | case 2: shift = 23; hit_addr += 6; break; |
| 2932 | case 3: return bfd_reloc_notsupported; /* shouldn't happen... */ |
| 2933 | } |
| 2934 | dword = bfd_get_64 (abfd, hit_addr); |
| 2935 | insn = (dword >> shift) & 0x1ffffffffffLL; |
| 2936 | |
| 2937 | op = elf64_ia64_operands + opnd; |
| 2938 | err = (*op->insert) (op, val, &insn); |
| 2939 | if (err) |
| 2940 | return bfd_reloc_overflow; |
| 2941 | |
| 2942 | dword &= ~(0x1ffffffffffLL << shift); |
| 2943 | dword |= (insn << shift); |
| 2944 | bfd_put_64 (abfd, dword, hit_addr); |
| 2945 | break; |
| 2946 | |
| 2947 | case IA64_OPND_NIL: |
| 2948 | /* A data relocation. */ |
| 2949 | if (bigendian) |
| 2950 | if (size == 4) |
| 2951 | bfd_putb32 (val, hit_addr); |
| 2952 | else |
| 2953 | bfd_putb64 (val, hit_addr); |
| 2954 | else |
| 2955 | if (size == 4) |
| 2956 | bfd_putl32 (val, hit_addr); |
| 2957 | else |
| 2958 | bfd_putl64 (val, hit_addr); |
| 2959 | break; |
| 2960 | } |
| 2961 | |
| 2962 | return bfd_reloc_ok; |
| 2963 | } |
| 2964 | |
| 2965 | static void |
| 2966 | elfNN_ia64_install_dyn_reloc (abfd, info, sec, srel, offset, type, |
| 2967 | dynindx, addend) |
| 2968 | bfd *abfd; |
| 2969 | struct bfd_link_info *info; |
| 2970 | asection *sec; |
| 2971 | asection *srel; |
| 2972 | bfd_vma offset; |
| 2973 | unsigned int type; |
| 2974 | long dynindx; |
| 2975 | bfd_vma addend; |
| 2976 | { |
| 2977 | Elf_Internal_Rela outrel; |
| 2978 | |
| 2979 | outrel.r_offset = (sec->output_section->vma |
| 2980 | + sec->output_offset |
| 2981 | + offset); |
| 2982 | |
| 2983 | BFD_ASSERT (dynindx != -1); |
| 2984 | outrel.r_info = ELFNN_R_INFO (dynindx, type); |
| 2985 | outrel.r_addend = addend; |
| 2986 | |
| 2987 | if (elf_section_data (sec)->stab_info != NULL) |
| 2988 | { |
| 2989 | /* This may be NULL for linker-generated relocations, as it is |
| 2990 | inconvenient to pass all the bits around. And this shouldn't |
| 2991 | happen. */ |
| 2992 | BFD_ASSERT (info != NULL); |
| 2993 | |
| 2994 | offset = (_bfd_stab_section_offset |
| 2995 | (abfd, &elf_hash_table (info)->stab_info, sec, |
| 2996 | &elf_section_data (sec)->stab_info, offset)); |
| 2997 | if (offset == (bfd_vma) -1) |
| 2998 | { |
| 2999 | /* Run for the hills. We shouldn't be outputting a relocation |
| 3000 | for this. So do what everyone else does and output a no-op. */ |
| 3001 | outrel.r_info = ELFNN_R_INFO (0, R_IA64_NONE); |
| 3002 | outrel.r_addend = 0; |
| 3003 | offset = 0; |
| 3004 | } |
| 3005 | outrel.r_offset = offset; |
| 3006 | } |
| 3007 | |
| 3008 | bfd_elfNN_swap_reloca_out (abfd, &outrel, |
| 3009 | ((ElfNN_External_Rela *) srel->contents |
| 3010 | + srel->reloc_count++)); |
| 3011 | BFD_ASSERT (sizeof (ElfNN_External_Rela) * srel->reloc_count |
| 3012 | <= srel->_cooked_size); |
| 3013 | } |
| 3014 | |
| 3015 | /* Store an entry for target address TARGET_ADDR in the linkage table |
| 3016 | and return the gp-relative address of the linkage table entry. */ |
| 3017 | |
| 3018 | static bfd_vma |
| 3019 | set_got_entry (abfd, info, dyn_i, dynindx, addend, value, dyn_r_type) |
| 3020 | bfd *abfd; |
| 3021 | struct bfd_link_info *info; |
| 3022 | struct elfNN_ia64_dyn_sym_info *dyn_i; |
| 3023 | long dynindx; |
| 3024 | bfd_vma addend; |
| 3025 | bfd_vma value; |
| 3026 | unsigned int dyn_r_type; |
| 3027 | { |
| 3028 | struct elfNN_ia64_link_hash_table *ia64_info; |
| 3029 | asection *got_sec; |
| 3030 | |
| 3031 | ia64_info = elfNN_ia64_hash_table (info); |
| 3032 | got_sec = ia64_info->got_sec; |
| 3033 | |
| 3034 | BFD_ASSERT ((dyn_i->got_offset & 7) == 0); |
| 3035 | |
| 3036 | if (! dyn_i->got_done) |
| 3037 | { |
| 3038 | dyn_i->got_done = true; |
| 3039 | |
| 3040 | /* Store the target address in the linkage table entry. */ |
| 3041 | bfd_put_64 (abfd, value, got_sec->contents + dyn_i->got_offset); |
| 3042 | |
| 3043 | /* Install a dynamic relocation if needed. */ |
| 3044 | if (info->shared |
| 3045 | || elfNN_ia64_dynamic_symbol_p (dyn_i->h, info) |
| 3046 | || elfNN_ia64_aix_vec (abfd->xvec) |
| 3047 | || (dynindx != -1 && dyn_r_type == R_IA64_FPTR64LSB)) |
| 3048 | { |
| 3049 | if (dynindx == -1) |
| 3050 | { |
| 3051 | dyn_r_type = R_IA64_REL64LSB; |
| 3052 | dynindx = 0; |
| 3053 | addend = value; |
| 3054 | } |
| 3055 | |
| 3056 | if (bfd_big_endian (abfd)) |
| 3057 | { |
| 3058 | switch (dyn_r_type) |
| 3059 | { |
| 3060 | case R_IA64_REL64LSB: |
| 3061 | dyn_r_type = R_IA64_REL64MSB; |
| 3062 | break; |
| 3063 | case R_IA64_DIR64LSB: |
| 3064 | dyn_r_type = R_IA64_DIR64MSB; |
| 3065 | break; |
| 3066 | case R_IA64_FPTR64LSB: |
| 3067 | dyn_r_type = R_IA64_FPTR64MSB; |
| 3068 | break; |
| 3069 | default: |
| 3070 | BFD_ASSERT (false); |
| 3071 | break; |
| 3072 | } |
| 3073 | } |
| 3074 | |
| 3075 | elfNN_ia64_install_dyn_reloc (abfd, NULL, got_sec, |
| 3076 | ia64_info->rel_got_sec, |
| 3077 | dyn_i->got_offset, dyn_r_type, |
| 3078 | dynindx, addend); |
| 3079 | } |
| 3080 | } |
| 3081 | |
| 3082 | /* Return the address of the linkage table entry. */ |
| 3083 | value = (got_sec->output_section->vma |
| 3084 | + got_sec->output_offset |
| 3085 | + dyn_i->got_offset); |
| 3086 | |
| 3087 | return value; |
| 3088 | } |
| 3089 | |
| 3090 | /* Fill in a function descriptor consisting of the function's code |
| 3091 | address and its global pointer. Return the descriptor's address. */ |
| 3092 | |
| 3093 | static bfd_vma |
| 3094 | set_fptr_entry (abfd, info, dyn_i, value) |
| 3095 | bfd *abfd; |
| 3096 | struct bfd_link_info *info; |
| 3097 | struct elfNN_ia64_dyn_sym_info *dyn_i; |
| 3098 | bfd_vma value; |
| 3099 | { |
| 3100 | struct elfNN_ia64_link_hash_table *ia64_info; |
| 3101 | asection *fptr_sec; |
| 3102 | |
| 3103 | ia64_info = elfNN_ia64_hash_table (info); |
| 3104 | fptr_sec = ia64_info->fptr_sec; |
| 3105 | |
| 3106 | if (!dyn_i->fptr_done) |
| 3107 | { |
| 3108 | dyn_i->fptr_done = 1; |
| 3109 | |
| 3110 | /* Fill in the function descriptor. */ |
| 3111 | bfd_put_64 (abfd, value, fptr_sec->contents + dyn_i->fptr_offset); |
| 3112 | bfd_put_64 (abfd, _bfd_get_gp_value (abfd), |
| 3113 | fptr_sec->contents + dyn_i->fptr_offset + 8); |
| 3114 | } |
| 3115 | |
| 3116 | /* Return the descriptor's address. */ |
| 3117 | value = (fptr_sec->output_section->vma |
| 3118 | + fptr_sec->output_offset |
| 3119 | + dyn_i->fptr_offset); |
| 3120 | |
| 3121 | return value; |
| 3122 | } |
| 3123 | |
| 3124 | /* Fill in a PLTOFF entry consisting of the function's code address |
| 3125 | and its global pointer. Return the descriptor's address. */ |
| 3126 | |
| 3127 | static bfd_vma |
| 3128 | set_pltoff_entry (abfd, info, dyn_i, value, is_plt) |
| 3129 | bfd *abfd; |
| 3130 | struct bfd_link_info *info; |
| 3131 | struct elfNN_ia64_dyn_sym_info *dyn_i; |
| 3132 | bfd_vma value; |
| 3133 | boolean is_plt; |
| 3134 | { |
| 3135 | struct elfNN_ia64_link_hash_table *ia64_info; |
| 3136 | asection *pltoff_sec; |
| 3137 | |
| 3138 | ia64_info = elfNN_ia64_hash_table (info); |
| 3139 | pltoff_sec = ia64_info->pltoff_sec; |
| 3140 | |
| 3141 | /* Don't do anything if this symbol uses a real PLT entry. In |
| 3142 | that case, we'll fill this in during finish_dynamic_symbol. */ |
| 3143 | if ((! dyn_i->want_plt || is_plt) |
| 3144 | && !dyn_i->pltoff_done) |
| 3145 | { |
| 3146 | bfd_vma gp = _bfd_get_gp_value (abfd); |
| 3147 | |
| 3148 | /* Fill in the function descriptor. */ |
| 3149 | bfd_put_64 (abfd, value, pltoff_sec->contents + dyn_i->pltoff_offset); |
| 3150 | bfd_put_64 (abfd, gp, pltoff_sec->contents + dyn_i->pltoff_offset + 8); |
| 3151 | |
| 3152 | /* Install dynamic relocations if needed. */ |
| 3153 | if (!is_plt && info->shared) |
| 3154 | { |
| 3155 | unsigned int dyn_r_type; |
| 3156 | |
| 3157 | if (bfd_big_endian (abfd)) |
| 3158 | dyn_r_type = R_IA64_REL64MSB; |
| 3159 | else |
| 3160 | dyn_r_type = R_IA64_REL64LSB; |
| 3161 | |
| 3162 | elfNN_ia64_install_dyn_reloc (abfd, NULL, pltoff_sec, |
| 3163 | ia64_info->rel_pltoff_sec, |
| 3164 | dyn_i->pltoff_offset, |
| 3165 | dyn_r_type, 0, value); |
| 3166 | elfNN_ia64_install_dyn_reloc (abfd, NULL, pltoff_sec, |
| 3167 | ia64_info->rel_pltoff_sec, |
| 3168 | dyn_i->pltoff_offset + 8, |
| 3169 | dyn_r_type, 0, gp); |
| 3170 | } |
| 3171 | |
| 3172 | dyn_i->pltoff_done = 1; |
| 3173 | } |
| 3174 | |
| 3175 | /* Return the descriptor's address. */ |
| 3176 | value = (pltoff_sec->output_section->vma |
| 3177 | + pltoff_sec->output_offset |
| 3178 | + dyn_i->pltoff_offset); |
| 3179 | |
| 3180 | return value; |
| 3181 | } |
| 3182 | |
| 3183 | /* Called through qsort to sort the .IA_64.unwind section during a |
| 3184 | non-relocatable link. Set elfNN_ia64_unwind_entry_compare_bfd |
| 3185 | to the output bfd so we can do proper endianness frobbing. */ |
| 3186 | |
| 3187 | static bfd *elfNN_ia64_unwind_entry_compare_bfd; |
| 3188 | |
| 3189 | static int |
| 3190 | elfNN_ia64_unwind_entry_compare (a, b) |
| 3191 | PTR a; |
| 3192 | PTR b; |
| 3193 | { |
| 3194 | bfd_vma av, bv; |
| 3195 | |
| 3196 | av = bfd_get_64 (elfNN_ia64_unwind_entry_compare_bfd, a); |
| 3197 | bv = bfd_get_64 (elfNN_ia64_unwind_entry_compare_bfd, b); |
| 3198 | |
| 3199 | return (av < bv ? -1 : av > bv ? 1 : 0); |
| 3200 | } |
| 3201 | |
| 3202 | static boolean |
| 3203 | elfNN_ia64_final_link (abfd, info) |
| 3204 | bfd *abfd; |
| 3205 | struct bfd_link_info *info; |
| 3206 | { |
| 3207 | struct elfNN_ia64_link_hash_table *ia64_info; |
| 3208 | asection *unwind_output_sec; |
| 3209 | |
| 3210 | ia64_info = elfNN_ia64_hash_table (info); |
| 3211 | |
| 3212 | /* Make sure we've got ourselves a nice fat __gp value. */ |
| 3213 | if (!info->relocateable) |
| 3214 | { |
| 3215 | bfd_vma min_vma = (bfd_vma) -1, max_vma = 0; |
| 3216 | bfd_vma min_short_vma = min_vma, max_short_vma = 0; |
| 3217 | struct elf_link_hash_entry *gp; |
| 3218 | bfd_vma gp_val; |
| 3219 | asection *os; |
| 3220 | |
| 3221 | /* Find the min and max vma of all sections marked short. Also |
| 3222 | collect min and max vma of any type, for use in selecting a |
| 3223 | nice gp. */ |
| 3224 | for (os = abfd->sections; os ; os = os->next) |
| 3225 | { |
| 3226 | bfd_vma lo, hi; |
| 3227 | |
| 3228 | if ((os->flags & SEC_ALLOC) == 0) |
| 3229 | continue; |
| 3230 | |
| 3231 | lo = os->vma; |
| 3232 | hi = os->vma + os->_raw_size; |
| 3233 | if (hi < lo) |
| 3234 | hi = (bfd_vma) -1; |
| 3235 | |
| 3236 | if (min_vma > lo) |
| 3237 | min_vma = lo; |
| 3238 | if (max_vma < hi) |
| 3239 | max_vma = hi; |
| 3240 | if (os->flags & SEC_SMALL_DATA) |
| 3241 | { |
| 3242 | if (min_short_vma > lo) |
| 3243 | min_short_vma = lo; |
| 3244 | if (max_short_vma < hi) |
| 3245 | max_short_vma = hi; |
| 3246 | } |
| 3247 | } |
| 3248 | |
| 3249 | /* See if the user wants to force a value. */ |
| 3250 | gp = elf_link_hash_lookup (elf_hash_table (info), "__gp", false, |
| 3251 | false, false); |
| 3252 | |
| 3253 | if (gp |
| 3254 | && (gp->root.type == bfd_link_hash_defined |
| 3255 | || gp->root.type == bfd_link_hash_defweak)) |
| 3256 | { |
| 3257 | asection *gp_sec = gp->root.u.def.section; |
| 3258 | gp_val = (gp->root.u.def.value |
| 3259 | + gp_sec->output_section->vma |
| 3260 | + gp_sec->output_offset); |
| 3261 | } |
| 3262 | else |
| 3263 | { |
| 3264 | /* Pick a sensible value. */ |
| 3265 | |
| 3266 | asection *got_sec = ia64_info->got_sec; |
| 3267 | |
| 3268 | /* Start with just the address of the .got. */ |
| 3269 | if (got_sec) |
| 3270 | gp_val = got_sec->output_section->vma; |
| 3271 | else if (max_short_vma != 0) |
| 3272 | gp_val = min_short_vma; |
| 3273 | else |
| 3274 | gp_val = min_vma; |
| 3275 | |
| 3276 | /* If it is possible to address the entire image, but we |
| 3277 | don't with the choice above, adjust. */ |
| 3278 | if (max_vma - min_vma < 0x400000 |
| 3279 | && max_vma - gp_val <= 0x200000 |
| 3280 | && gp_val - min_vma > 0x200000) |
| 3281 | gp_val = min_vma + 0x200000; |
| 3282 | else if (max_short_vma != 0) |
| 3283 | { |
| 3284 | /* If we don't cover all the short data, adjust. */ |
| 3285 | if (max_short_vma - gp_val >= 0x200000) |
| 3286 | gp_val = min_short_vma + 0x200000; |
| 3287 | |
| 3288 | /* If we're addressing stuff past the end, adjust back. */ |
| 3289 | if (gp_val > max_vma) |
| 3290 | gp_val = max_vma - 0x200000 + 8; |
| 3291 | } |
| 3292 | } |
| 3293 | |
| 3294 | /* Validate whether all SHF_IA_64_SHORT sections are within |
| 3295 | range of the chosen GP. */ |
| 3296 | |
| 3297 | if (max_short_vma != 0) |
| 3298 | { |
| 3299 | if (max_short_vma - min_short_vma >= 0x400000) |
| 3300 | { |
| 3301 | (*_bfd_error_handler) |
| 3302 | (_("%s: short data segment overflowed (0x%lx >= 0x400000)"), |
| 3303 | bfd_get_filename (abfd), |
| 3304 | (unsigned long) (max_short_vma - min_short_vma)); |
| 3305 | return false; |
| 3306 | } |
| 3307 | else if ((gp_val > min_short_vma |
| 3308 | && gp_val - min_short_vma > 0x200000) |
| 3309 | || (gp_val < max_short_vma |
| 3310 | && max_short_vma - gp_val >= 0x200000)) |
| 3311 | { |
| 3312 | (*_bfd_error_handler) |
| 3313 | (_("%s: __gp does not cover short data segment"), |
| 3314 | bfd_get_filename (abfd)); |
| 3315 | return false; |
| 3316 | } |
| 3317 | } |
| 3318 | |
| 3319 | _bfd_set_gp_value (abfd, gp_val); |
| 3320 | |
| 3321 | if (gp) |
| 3322 | { |
| 3323 | gp->root.type = bfd_link_hash_defined; |
| 3324 | gp->root.u.def.value = gp_val; |
| 3325 | gp->root.u.def.section = bfd_abs_section_ptr; |
| 3326 | } |
| 3327 | } |
| 3328 | |
| 3329 | /* If we're producing a final executable, we need to sort the contents |
| 3330 | of the .IA_64.unwind section. Force this section to be relocated |
| 3331 | into memory rather than written immediately to the output file. */ |
| 3332 | unwind_output_sec = NULL; |
| 3333 | if (!info->relocateable) |
| 3334 | { |
| 3335 | asection *s = bfd_get_section_by_name (abfd, ELF_STRING_ia64_unwind); |
| 3336 | if (s) |
| 3337 | { |
| 3338 | unwind_output_sec = s->output_section; |
| 3339 | unwind_output_sec->contents |
| 3340 | = bfd_malloc (unwind_output_sec->_raw_size); |
| 3341 | if (unwind_output_sec->contents == NULL) |
| 3342 | return false; |
| 3343 | } |
| 3344 | } |
| 3345 | |
| 3346 | /* Invoke the regular ELF backend linker to do all the work. */ |
| 3347 | if (!bfd_elfNN_bfd_final_link (abfd, info)) |
| 3348 | return false; |
| 3349 | |
| 3350 | if (unwind_output_sec) |
| 3351 | { |
| 3352 | elfNN_ia64_unwind_entry_compare_bfd = abfd; |
| 3353 | qsort (unwind_output_sec->contents, unwind_output_sec->_raw_size / 24, |
| 3354 | 24, elfNN_ia64_unwind_entry_compare); |
| 3355 | |
| 3356 | if (! bfd_set_section_contents (abfd, unwind_output_sec, |
| 3357 | unwind_output_sec->contents, 0, |
| 3358 | unwind_output_sec->_raw_size)) |
| 3359 | return false; |
| 3360 | } |
| 3361 | |
| 3362 | return true; |
| 3363 | } |
| 3364 | |
| 3365 | static boolean |
| 3366 | elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section, |
| 3367 | contents, relocs, local_syms, local_sections) |
| 3368 | bfd *output_bfd; |
| 3369 | struct bfd_link_info *info; |
| 3370 | bfd *input_bfd; |
| 3371 | asection *input_section; |
| 3372 | bfd_byte *contents; |
| 3373 | Elf_Internal_Rela *relocs; |
| 3374 | Elf_Internal_Sym *local_syms; |
| 3375 | asection **local_sections; |
| 3376 | { |
| 3377 | struct elfNN_ia64_link_hash_table *ia64_info; |
| 3378 | Elf_Internal_Shdr *symtab_hdr; |
| 3379 | Elf_Internal_Rela *rel; |
| 3380 | Elf_Internal_Rela *relend; |
| 3381 | asection *srel; |
| 3382 | boolean ret_val = true; /* for non-fatal errors */ |
| 3383 | bfd_vma gp_val; |
| 3384 | |
| 3385 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
| 3386 | ia64_info = elfNN_ia64_hash_table (info); |
| 3387 | |
| 3388 | /* Infect various flags from the input section to the output section. */ |
| 3389 | if (info->relocateable) |
| 3390 | { |
| 3391 | bfd_vma flags; |
| 3392 | |
| 3393 | flags = elf_section_data(input_section)->this_hdr.sh_flags; |
| 3394 | flags &= SHF_IA_64_NORECOV; |
| 3395 | |
| 3396 | elf_section_data(input_section->output_section) |
| 3397 | ->this_hdr.sh_flags |= flags; |
| 3398 | } |
| 3399 | |
| 3400 | gp_val = _bfd_get_gp_value (output_bfd); |
| 3401 | srel = get_reloc_section (input_bfd, ia64_info, input_section, false); |
| 3402 | |
| 3403 | rel = relocs; |
| 3404 | relend = relocs + input_section->reloc_count; |
| 3405 | for (; rel < relend; ++rel) |
| 3406 | { |
| 3407 | struct elf_link_hash_entry *h; |
| 3408 | struct elfNN_ia64_dyn_sym_info *dyn_i; |
| 3409 | bfd_reloc_status_type r; |
| 3410 | reloc_howto_type *howto; |
| 3411 | unsigned long r_symndx; |
| 3412 | Elf_Internal_Sym *sym; |
| 3413 | unsigned int r_type; |
| 3414 | bfd_vma value; |
| 3415 | asection *sym_sec; |
| 3416 | bfd_byte *hit_addr; |
| 3417 | boolean dynamic_symbol_p; |
| 3418 | boolean undef_weak_ref; |
| 3419 | |
| 3420 | r_type = ELFNN_R_TYPE (rel->r_info); |
| 3421 | if (r_type > R_IA64_MAX_RELOC_CODE) |
| 3422 | { |
| 3423 | (*_bfd_error_handler) |
| 3424 | (_("%s: unknown relocation type %d"), |
| 3425 | bfd_get_filename (input_bfd), (int)r_type); |
| 3426 | bfd_set_error (bfd_error_bad_value); |
| 3427 | ret_val = false; |
| 3428 | continue; |
| 3429 | } |
| 3430 | howto = lookup_howto (r_type); |
| 3431 | r_symndx = ELFNN_R_SYM (rel->r_info); |
| 3432 | |
| 3433 | if (info->relocateable) |
| 3434 | { |
| 3435 | /* This is a relocateable link. We don't have to change |
| 3436 | anything, unless the reloc is against a section symbol, |
| 3437 | in which case we have to adjust according to where the |
| 3438 | section symbol winds up in the output section. */ |
| 3439 | if (r_symndx < symtab_hdr->sh_info) |
| 3440 | { |
| 3441 | sym = local_syms + r_symndx; |
| 3442 | if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) |
| 3443 | { |
| 3444 | sym_sec = local_sections[r_symndx]; |
| 3445 | rel->r_addend += sym_sec->output_offset; |
| 3446 | } |
| 3447 | } |
| 3448 | continue; |
| 3449 | } |
| 3450 | |
| 3451 | /* This is a final link. */ |
| 3452 | |
| 3453 | h = NULL; |
| 3454 | sym = NULL; |
| 3455 | sym_sec = NULL; |
| 3456 | undef_weak_ref = false; |
| 3457 | |
| 3458 | if (r_symndx < symtab_hdr->sh_info) |
| 3459 | { |
| 3460 | /* Reloc against local symbol. */ |
| 3461 | sym = local_syms + r_symndx; |
| 3462 | sym_sec = local_sections[r_symndx]; |
| 3463 | value = (sym_sec->output_section->vma |
| 3464 | + sym_sec->output_offset |
| 3465 | + sym->st_value); |
| 3466 | } |
| 3467 | else |
| 3468 | { |
| 3469 | long indx; |
| 3470 | |
| 3471 | /* Reloc against global symbol. */ |
| 3472 | indx = r_symndx - symtab_hdr->sh_info; |
| 3473 | h = elf_sym_hashes (input_bfd)[indx]; |
| 3474 | while (h->root.type == bfd_link_hash_indirect |
| 3475 | || h->root.type == bfd_link_hash_warning) |
| 3476 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 3477 | |
| 3478 | value = 0; |
| 3479 | if (h->root.type == bfd_link_hash_defined |
| 3480 | || h->root.type == bfd_link_hash_defweak) |
| 3481 | { |
| 3482 | sym_sec = h->root.u.def.section; |
| 3483 | |
| 3484 | /* Detect the cases that sym_sec->output_section is |
| 3485 | expected to be NULL -- all cases in which the symbol |
| 3486 | is defined in another shared module. This includes |
| 3487 | PLT relocs for which we've created a PLT entry and |
| 3488 | other relocs for which we're prepared to create |
| 3489 | dynamic relocations. */ |
| 3490 | /* ??? Just accept it NULL and continue. */ |
| 3491 | |
| 3492 | if (sym_sec->output_section != NULL) |
| 3493 | { |
| 3494 | value = (h->root.u.def.value |
| 3495 | + sym_sec->output_section->vma |
| 3496 | + sym_sec->output_offset); |
| 3497 | } |
| 3498 | } |
| 3499 | else if (h->root.type == bfd_link_hash_undefweak) |
| 3500 | undef_weak_ref = true; |
| 3501 | else if (info->shared && !info->symbolic |
| 3502 | && !info->no_undefined |
| 3503 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) |
| 3504 | ; |
| 3505 | else |
| 3506 | { |
| 3507 | if (! ((*info->callbacks->undefined_symbol) |
| 3508 | (info, h->root.root.string, input_bfd, |
| 3509 | input_section, rel->r_offset, |
| 3510 | (!info->shared || info->no_undefined |
| 3511 | || ELF_ST_VISIBILITY (h->other))))) |
| 3512 | return false; |
| 3513 | ret_val = false; |
| 3514 | continue; |
| 3515 | } |
| 3516 | } |
| 3517 | |
| 3518 | hit_addr = contents + rel->r_offset; |
| 3519 | value += rel->r_addend; |
| 3520 | dynamic_symbol_p = elfNN_ia64_dynamic_symbol_p (h, info); |
| 3521 | |
| 3522 | switch (r_type) |
| 3523 | { |
| 3524 | case R_IA64_NONE: |
| 3525 | case R_IA64_LDXMOV: |
| 3526 | continue; |
| 3527 | |
| 3528 | case R_IA64_IMM14: |
| 3529 | case R_IA64_IMM22: |
| 3530 | case R_IA64_IMM64: |
| 3531 | case R_IA64_DIR32MSB: |
| 3532 | case R_IA64_DIR32LSB: |
| 3533 | case R_IA64_DIR64MSB: |
| 3534 | case R_IA64_DIR64LSB: |
| 3535 | /* Install a dynamic relocation for this reloc. */ |
| 3536 | if ((dynamic_symbol_p || info->shared |
| 3537 | || (elfNN_ia64_aix_vec (info->hash->creator) |
| 3538 | /* Don't emit relocs for __GLOB_DATA_PTR on AIX. */ |
| 3539 | && (!h || strcmp (h->root.root.string, |
| 3540 | "__GLOB_DATA_PTR") != 0))) |
| 3541 | && (input_section->flags & SEC_ALLOC) != 0) |
| 3542 | { |
| 3543 | unsigned int dyn_r_type; |
| 3544 | long dynindx; |
| 3545 | bfd_vma addend; |
| 3546 | |
| 3547 | BFD_ASSERT (srel != NULL); |
| 3548 | |
| 3549 | /* If we don't need dynamic symbol lookup, find a |
| 3550 | matching RELATIVE relocation. */ |
| 3551 | dyn_r_type = r_type; |
| 3552 | if (dynamic_symbol_p) |
| 3553 | { |
| 3554 | dynindx = h->dynindx; |
| 3555 | addend = rel->r_addend; |
| 3556 | value = 0; |
| 3557 | } |
| 3558 | else |
| 3559 | { |
| 3560 | switch (r_type) |
| 3561 | { |
| 3562 | case R_IA64_DIR32MSB: |
| 3563 | dyn_r_type = R_IA64_REL32MSB; |
| 3564 | break; |
| 3565 | case R_IA64_DIR32LSB: |
| 3566 | dyn_r_type = R_IA64_REL32LSB; |
| 3567 | break; |
| 3568 | case R_IA64_DIR64MSB: |
| 3569 | dyn_r_type = R_IA64_REL64MSB; |
| 3570 | break; |
| 3571 | case R_IA64_DIR64LSB: |
| 3572 | dyn_r_type = R_IA64_REL64LSB; |
| 3573 | break; |
| 3574 | |
| 3575 | default: |
| 3576 | /* We can't represent this without a dynamic symbol. |
| 3577 | Adjust the relocation to be against an output |
| 3578 | section symbol, which are always present in the |
| 3579 | dynamic symbol table. */ |
| 3580 | /* ??? People shouldn't be doing non-pic code in |
| 3581 | shared libraries. Hork. */ |
| 3582 | (*_bfd_error_handler) |
| 3583 | (_("%s: linking non-pic code in a shared library"), |
| 3584 | bfd_get_filename (input_bfd)); |
| 3585 | ret_val = false; |
| 3586 | continue; |
| 3587 | } |
| 3588 | dynindx = 0; |
| 3589 | addend = value; |
| 3590 | } |
| 3591 | |
| 3592 | if (elfNN_ia64_aix_vec (info->hash->creator)) |
| 3593 | rel->r_addend = value; |
| 3594 | elfNN_ia64_install_dyn_reloc (output_bfd, info, input_section, |
| 3595 | srel, rel->r_offset, dyn_r_type, |
| 3596 | dynindx, addend); |
| 3597 | } |
| 3598 | /* FALLTHRU */ |
| 3599 | |
| 3600 | case R_IA64_LTV32MSB: |
| 3601 | case R_IA64_LTV32LSB: |
| 3602 | case R_IA64_LTV64MSB: |
| 3603 | case R_IA64_LTV64LSB: |
| 3604 | r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type); |
| 3605 | break; |
| 3606 | |
| 3607 | case R_IA64_GPREL22: |
| 3608 | case R_IA64_GPREL64I: |
| 3609 | case R_IA64_GPREL32MSB: |
| 3610 | case R_IA64_GPREL32LSB: |
| 3611 | case R_IA64_GPREL64MSB: |
| 3612 | case R_IA64_GPREL64LSB: |
| 3613 | if (dynamic_symbol_p) |
| 3614 | { |
| 3615 | (*_bfd_error_handler) |
| 3616 | (_("%s: @gprel relocation against dynamic symbol %s"), |
| 3617 | bfd_get_filename (input_bfd), h->root.root.string); |
| 3618 | ret_val = false; |
| 3619 | continue; |
| 3620 | } |
| 3621 | value -= gp_val; |
| 3622 | r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type); |
| 3623 | break; |
| 3624 | |
| 3625 | case R_IA64_LTOFF22: |
| 3626 | case R_IA64_LTOFF22X: |
| 3627 | case R_IA64_LTOFF64I: |
| 3628 | dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, false); |
| 3629 | value = set_got_entry (input_bfd, info, dyn_i, (h ? h->dynindx : -1), |
| 3630 | rel->r_addend, value, R_IA64_DIR64LSB); |
| 3631 | value -= gp_val; |
| 3632 | r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type); |
| 3633 | break; |
| 3634 | |
| 3635 | case R_IA64_PLTOFF22: |
| 3636 | case R_IA64_PLTOFF64I: |
| 3637 | case R_IA64_PLTOFF64MSB: |
| 3638 | case R_IA64_PLTOFF64LSB: |
| 3639 | dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, false); |
| 3640 | value = set_pltoff_entry (output_bfd, info, dyn_i, value, false); |
| 3641 | value -= gp_val; |
| 3642 | r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type); |
| 3643 | break; |
| 3644 | |
| 3645 | case R_IA64_FPTR64I: |
| 3646 | case R_IA64_FPTR32MSB: |
| 3647 | case R_IA64_FPTR32LSB: |
| 3648 | case R_IA64_FPTR64MSB: |
| 3649 | case R_IA64_FPTR64LSB: |
| 3650 | dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, false); |
| 3651 | if (dyn_i->want_fptr) |
| 3652 | { |
| 3653 | if (!undef_weak_ref) |
| 3654 | value = set_fptr_entry (output_bfd, info, dyn_i, value); |
| 3655 | } |
| 3656 | else |
| 3657 | { |
| 3658 | long dynindx; |
| 3659 | |
| 3660 | /* Otherwise, we expect the dynamic linker to create |
| 3661 | the entry. */ |
| 3662 | |
| 3663 | if (h) |
| 3664 | { |
| 3665 | if (h->dynindx != -1) |
| 3666 | dynindx = h->dynindx; |
| 3667 | else |
| 3668 | dynindx = (_bfd_elf_link_lookup_local_dynindx |
| 3669 | (info, h->root.u.def.section->owner, |
| 3670 | global_sym_index (h))); |
| 3671 | } |
| 3672 | else |
| 3673 | { |
| 3674 | dynindx = (_bfd_elf_link_lookup_local_dynindx |
| 3675 | (info, input_bfd, r_symndx)); |
| 3676 | } |
| 3677 | |
| 3678 | elfNN_ia64_install_dyn_reloc (output_bfd, info, input_section, |
| 3679 | srel, rel->r_offset, r_type, |
| 3680 | dynindx, rel->r_addend); |
| 3681 | value = 0; |
| 3682 | } |
| 3683 | |
| 3684 | r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type); |
| 3685 | break; |
| 3686 | |
| 3687 | case R_IA64_LTOFF_FPTR22: |
| 3688 | case R_IA64_LTOFF_FPTR64I: |
| 3689 | case R_IA64_LTOFF_FPTR32MSB: |
| 3690 | case R_IA64_LTOFF_FPTR32LSB: |
| 3691 | case R_IA64_LTOFF_FPTR64MSB: |
| 3692 | case R_IA64_LTOFF_FPTR64LSB: |
| 3693 | { |
| 3694 | long dynindx; |
| 3695 | |
| 3696 | dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, false); |
| 3697 | if (dyn_i->want_fptr) |
| 3698 | { |
| 3699 | BFD_ASSERT (h == NULL || h->dynindx == -1) |
| 3700 | if (!undef_weak_ref) |
| 3701 | value = set_fptr_entry (output_bfd, info, dyn_i, value); |
| 3702 | dynindx = -1; |
| 3703 | } |
| 3704 | else |
| 3705 | { |
| 3706 | /* Otherwise, we expect the dynamic linker to create |
| 3707 | the entry. */ |
| 3708 | if (h) |
| 3709 | { |
| 3710 | if (h->dynindx != -1) |
| 3711 | dynindx = h->dynindx; |
| 3712 | else |
| 3713 | dynindx = (_bfd_elf_link_lookup_local_dynindx |
| 3714 | (info, h->root.u.def.section->owner, |
| 3715 | global_sym_index (h))); |
| 3716 | } |
| 3717 | else |
| 3718 | dynindx = (_bfd_elf_link_lookup_local_dynindx |
| 3719 | (info, input_bfd, r_symndx)); |
| 3720 | value = 0; |
| 3721 | } |
| 3722 | |
| 3723 | value = set_got_entry (output_bfd, info, dyn_i, dynindx, |
| 3724 | rel->r_addend, value, R_IA64_FPTR64LSB); |
| 3725 | value -= gp_val; |
| 3726 | r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type); |
| 3727 | } |
| 3728 | break; |
| 3729 | |
| 3730 | case R_IA64_PCREL32MSB: |
| 3731 | case R_IA64_PCREL32LSB: |
| 3732 | case R_IA64_PCREL64MSB: |
| 3733 | case R_IA64_PCREL64LSB: |
| 3734 | /* Install a dynamic relocation for this reloc. */ |
| 3735 | if (dynamic_symbol_p |
| 3736 | || elfNN_ia64_aix_vec (info->hash->creator)) |
| 3737 | { |
| 3738 | BFD_ASSERT (srel != NULL); |
| 3739 | |
| 3740 | elfNN_ia64_install_dyn_reloc (output_bfd, info, input_section, |
| 3741 | srel, rel->r_offset, r_type, |
| 3742 | h->dynindx, rel->r_addend); |
| 3743 | } |
| 3744 | goto finish_pcrel; |
| 3745 | |
| 3746 | case R_IA64_PCREL21BI: |
| 3747 | case R_IA64_PCREL21F: |
| 3748 | case R_IA64_PCREL21M: |
| 3749 | /* ??? These two are only used for speculation fixup code. |
| 3750 | They should never be dynamic. */ |
| 3751 | if (dynamic_symbol_p) |
| 3752 | { |
| 3753 | (*_bfd_error_handler) |
| 3754 | (_("%s: dynamic relocation against speculation fixup"), |
| 3755 | bfd_get_filename (input_bfd)); |
| 3756 | ret_val = false; |
| 3757 | continue; |
| 3758 | } |
| 3759 | if (undef_weak_ref) |
| 3760 | { |
| 3761 | (*_bfd_error_handler) |
| 3762 | (_("%s: speculation fixup against undefined weak symbol"), |
| 3763 | bfd_get_filename (input_bfd)); |
| 3764 | ret_val = false; |
| 3765 | continue; |
| 3766 | } |
| 3767 | goto finish_pcrel; |
| 3768 | |
| 3769 | case R_IA64_PCREL21B: |
| 3770 | case R_IA64_PCREL60B: |
| 3771 | /* We should have created a PLT entry for any dynamic symbol. */ |
| 3772 | dyn_i = NULL; |
| 3773 | if (h) |
| 3774 | dyn_i = get_dyn_sym_info (ia64_info, h, NULL, NULL, false); |
| 3775 | |
| 3776 | if (dyn_i && dyn_i->want_plt2) |
| 3777 | { |
| 3778 | /* Should have caught this earlier. */ |
| 3779 | BFD_ASSERT (rel->r_addend == 0); |
| 3780 | |
| 3781 | value = (ia64_info->plt_sec->output_section->vma |
| 3782 | + ia64_info->plt_sec->output_offset |
| 3783 | + dyn_i->plt2_offset); |
| 3784 | } |
| 3785 | else |
| 3786 | { |
| 3787 | /* Since there's no PLT entry, Validate that this is |
| 3788 | locally defined. */ |
| 3789 | BFD_ASSERT (undef_weak_ref || sym_sec->output_section != NULL); |
| 3790 | |
| 3791 | /* If the symbol is undef_weak, we shouldn't be trying |
| 3792 | to call it. There's every chance that we'd wind up |
| 3793 | with an out-of-range fixup here. Don't bother setting |
| 3794 | any value at all. */ |
| 3795 | if (undef_weak_ref) |
| 3796 | continue; |
| 3797 | } |
| 3798 | goto finish_pcrel; |
| 3799 | |
| 3800 | case R_IA64_PCREL22: |
| 3801 | case R_IA64_PCREL64I: |
| 3802 | finish_pcrel: |
| 3803 | /* Make pc-relative. */ |
| 3804 | value -= (input_section->output_section->vma |
| 3805 | + input_section->output_offset |
| 3806 | + rel->r_offset) & ~ (bfd_vma) 0x3; |
| 3807 | r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type); |
| 3808 | break; |
| 3809 | |
| 3810 | case R_IA64_SEGREL32MSB: |
| 3811 | case R_IA64_SEGREL32LSB: |
| 3812 | case R_IA64_SEGREL64MSB: |
| 3813 | case R_IA64_SEGREL64LSB: |
| 3814 | { |
| 3815 | struct elf_segment_map *m; |
| 3816 | Elf_Internal_Phdr *p; |
| 3817 | |
| 3818 | /* Find the segment that contains the output_section. */ |
| 3819 | for (m = elf_tdata (output_bfd)->segment_map, |
| 3820 | p = elf_tdata (output_bfd)->phdr; |
| 3821 | m != NULL; |
| 3822 | m = m->next, p++) |
| 3823 | { |
| 3824 | int i; |
| 3825 | for (i = m->count - 1; i >= 0; i--) |
| 3826 | if (m->sections[i] == sym_sec->output_section) |
| 3827 | break; |
| 3828 | if (i >= 0) |
| 3829 | break; |
| 3830 | } |
| 3831 | |
| 3832 | if (m == NULL) |
| 3833 | { |
| 3834 | /* If the input section was discarded from the output, then |
| 3835 | do nothing. */ |
| 3836 | |
| 3837 | if (bfd_is_abs_section (sym_sec->output_section)) |
| 3838 | r = bfd_reloc_ok; |
| 3839 | else |
| 3840 | r = bfd_reloc_notsupported; |
| 3841 | } |
| 3842 | else |
| 3843 | { |
| 3844 | /* The VMA of the segment is the vaddr of the associated |
| 3845 | program header. */ |
| 3846 | if (value > p->p_vaddr) |
| 3847 | value -= p->p_vaddr; |
| 3848 | else |
| 3849 | value = 0; |
| 3850 | r = elfNN_ia64_install_value (output_bfd, hit_addr, value, |
| 3851 | r_type); |
| 3852 | } |
| 3853 | break; |
| 3854 | } |
| 3855 | |
| 3856 | case R_IA64_SECREL32MSB: |
| 3857 | case R_IA64_SECREL32LSB: |
| 3858 | case R_IA64_SECREL64MSB: |
| 3859 | case R_IA64_SECREL64LSB: |
| 3860 | /* Make output-section relative. */ |
| 3861 | if (value > input_section->output_section->vma) |
| 3862 | value -= input_section->output_section->vma; |
| 3863 | else |
| 3864 | value = 0; |
| 3865 | r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type); |
| 3866 | break; |
| 3867 | |
| 3868 | case R_IA64_IPLTMSB: |
| 3869 | case R_IA64_IPLTLSB: |
| 3870 | /* Install a dynamic relocation for this reloc. */ |
| 3871 | if ((dynamic_symbol_p || info->shared) |
| 3872 | && (input_section->flags & SEC_ALLOC) != 0) |
| 3873 | { |
| 3874 | BFD_ASSERT (srel != NULL); |
| 3875 | |
| 3876 | /* If we don't need dynamic symbol lookup, install two |
| 3877 | RELATIVE relocations. */ |
| 3878 | if (! dynamic_symbol_p) |
| 3879 | { |
| 3880 | unsigned int dyn_r_type; |
| 3881 | |
| 3882 | if (r_type == R_IA64_IPLTMSB) |
| 3883 | dyn_r_type = R_IA64_REL64MSB; |
| 3884 | else |
| 3885 | dyn_r_type = R_IA64_REL64LSB; |
| 3886 | |
| 3887 | elfNN_ia64_install_dyn_reloc (output_bfd, info, |
| 3888 | input_section, |
| 3889 | srel, rel->r_offset, |
| 3890 | dyn_r_type, 0, value); |
| 3891 | elfNN_ia64_install_dyn_reloc (output_bfd, info, |
| 3892 | input_section, |
| 3893 | srel, rel->r_offset + 8, |
| 3894 | dyn_r_type, 0, gp_val); |
| 3895 | } |
| 3896 | else |
| 3897 | elfNN_ia64_install_dyn_reloc (output_bfd, info, input_section, |
| 3898 | srel, rel->r_offset, r_type, |
| 3899 | h->dynindx, rel->r_addend); |
| 3900 | } |
| 3901 | |
| 3902 | if (r_type == R_IA64_IPLTMSB) |
| 3903 | r_type = R_IA64_DIR64MSB; |
| 3904 | else |
| 3905 | r_type = R_IA64_DIR64LSB; |
| 3906 | elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type); |
| 3907 | r = elfNN_ia64_install_value (output_bfd, hit_addr + 8, gp_val, |
| 3908 | r_type); |
| 3909 | break; |
| 3910 | |
| 3911 | default: |
| 3912 | r = bfd_reloc_notsupported; |
| 3913 | break; |
| 3914 | } |
| 3915 | |
| 3916 | switch (r) |
| 3917 | { |
| 3918 | case bfd_reloc_ok: |
| 3919 | break; |
| 3920 | |
| 3921 | case bfd_reloc_undefined: |
| 3922 | /* This can happen for global table relative relocs if |
| 3923 | __gp is undefined. This is a panic situation so we |
| 3924 | don't try to continue. */ |
| 3925 | (*info->callbacks->undefined_symbol) |
| 3926 | (info, "__gp", input_bfd, input_section, rel->r_offset, 1); |
| 3927 | return false; |
| 3928 | |
| 3929 | case bfd_reloc_notsupported: |
| 3930 | { |
| 3931 | const char *name; |
| 3932 | |
| 3933 | if (h) |
| 3934 | name = h->root.root.string; |
| 3935 | else |
| 3936 | { |
| 3937 | name = bfd_elf_string_from_elf_section (input_bfd, |
| 3938 | symtab_hdr->sh_link, |
| 3939 | sym->st_name); |
| 3940 | if (name == NULL) |
| 3941 | return false; |
| 3942 | if (*name == '\0') |
| 3943 | name = bfd_section_name (input_bfd, input_section); |
| 3944 | } |
| 3945 | if (!(*info->callbacks->warning) (info, _("unsupported reloc"), |
| 3946 | name, input_bfd, |
| 3947 | input_section, rel->r_offset)) |
| 3948 | return false; |
| 3949 | ret_val = false; |
| 3950 | } |
| 3951 | break; |
| 3952 | |
| 3953 | case bfd_reloc_dangerous: |
| 3954 | case bfd_reloc_outofrange: |
| 3955 | case bfd_reloc_overflow: |
| 3956 | default: |
| 3957 | { |
| 3958 | const char *name; |
| 3959 | |
| 3960 | if (h) |
| 3961 | name = h->root.root.string; |
| 3962 | else |
| 3963 | { |
| 3964 | name = bfd_elf_string_from_elf_section (input_bfd, |
| 3965 | symtab_hdr->sh_link, |
| 3966 | sym->st_name); |
| 3967 | if (name == NULL) |
| 3968 | return false; |
| 3969 | if (*name == '\0') |
| 3970 | name = bfd_section_name (input_bfd, input_section); |
| 3971 | } |
| 3972 | if (!(*info->callbacks->reloc_overflow) (info, name, |
| 3973 | howto->name, 0, |
| 3974 | input_bfd, |
| 3975 | input_section, |
| 3976 | rel->r_offset)) |
| 3977 | return false; |
| 3978 | ret_val = false; |
| 3979 | } |
| 3980 | break; |
| 3981 | } |
| 3982 | } |
| 3983 | |
| 3984 | return ret_val; |
| 3985 | } |
| 3986 | |
| 3987 | static boolean |
| 3988 | elfNN_ia64_finish_dynamic_symbol (output_bfd, info, h, sym) |
| 3989 | bfd *output_bfd; |
| 3990 | struct bfd_link_info *info; |
| 3991 | struct elf_link_hash_entry *h; |
| 3992 | Elf_Internal_Sym *sym; |
| 3993 | { |
| 3994 | struct elfNN_ia64_link_hash_table *ia64_info; |
| 3995 | struct elfNN_ia64_dyn_sym_info *dyn_i; |
| 3996 | |
| 3997 | ia64_info = elfNN_ia64_hash_table (info); |
| 3998 | dyn_i = get_dyn_sym_info (ia64_info, h, NULL, NULL, false); |
| 3999 | |
| 4000 | /* Fill in the PLT data, if required. */ |
| 4001 | if (dyn_i && dyn_i->want_plt) |
| 4002 | { |
| 4003 | Elf_Internal_Rela outrel; |
| 4004 | bfd_byte *loc; |
| 4005 | asection *plt_sec; |
| 4006 | bfd_vma plt_addr, pltoff_addr, gp_val, index; |
| 4007 | ElfNN_External_Rela *rel; |
| 4008 | |
| 4009 | gp_val = _bfd_get_gp_value (output_bfd); |
| 4010 | |
| 4011 | /* Initialize the minimal PLT entry. */ |
| 4012 | |
| 4013 | index = (dyn_i->plt_offset - PLT_HEADER_SIZE) / PLT_MIN_ENTRY_SIZE; |
| 4014 | plt_sec = ia64_info->plt_sec; |
| 4015 | loc = plt_sec->contents + dyn_i->plt_offset; |
| 4016 | |
| 4017 | memcpy (loc, plt_min_entry, PLT_MIN_ENTRY_SIZE); |
| 4018 | elfNN_ia64_install_value (output_bfd, loc, index, R_IA64_IMM22); |
| 4019 | elfNN_ia64_install_value (output_bfd, loc+2, -dyn_i->plt_offset, |
| 4020 | R_IA64_PCREL21B); |
| 4021 | |
| 4022 | plt_addr = (plt_sec->output_section->vma |
| 4023 | + plt_sec->output_offset |
| 4024 | + dyn_i->plt_offset); |
| 4025 | pltoff_addr = set_pltoff_entry (output_bfd, info, dyn_i, plt_addr, true); |
| 4026 | |
| 4027 | /* Initialize the FULL PLT entry, if needed. */ |
| 4028 | if (dyn_i->want_plt2) |
| 4029 | { |
| 4030 | loc = plt_sec->contents + dyn_i->plt2_offset; |
| 4031 | |
| 4032 | memcpy (loc, plt_full_entry, PLT_FULL_ENTRY_SIZE); |
| 4033 | elfNN_ia64_install_value (output_bfd, loc, pltoff_addr - gp_val, |
| 4034 | R_IA64_IMM22); |
| 4035 | |
| 4036 | /* Mark the symbol as undefined, rather than as defined in the |
| 4037 | plt section. Leave the value alone. */ |
| 4038 | /* ??? We didn't redefine it in adjust_dynamic_symbol in the |
| 4039 | first place. But perhaps elflink.h did some for us. */ |
| 4040 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) |
| 4041 | sym->st_shndx = SHN_UNDEF; |
| 4042 | } |
| 4043 | |
| 4044 | /* Create the dynamic relocation. */ |
| 4045 | outrel.r_offset = pltoff_addr; |
| 4046 | if (bfd_little_endian (output_bfd)) |
| 4047 | outrel.r_info = ELFNN_R_INFO (h->dynindx, R_IA64_IPLTLSB); |
| 4048 | else |
| 4049 | outrel.r_info = ELFNN_R_INFO (h->dynindx, R_IA64_IPLTMSB); |
| 4050 | outrel.r_addend = 0; |
| 4051 | |
| 4052 | /* This is fun. In the .IA_64.pltoff section, we've got entries |
| 4053 | that correspond both to real PLT entries, and those that |
| 4054 | happened to resolve to local symbols but need to be created |
| 4055 | to satisfy @pltoff relocations. The .rela.IA_64.pltoff |
| 4056 | relocations for the real PLT should come at the end of the |
| 4057 | section, so that they can be indexed by plt entry at runtime. |
| 4058 | |
| 4059 | We emitted all of the relocations for the non-PLT @pltoff |
| 4060 | entries during relocate_section. So we can consider the |
| 4061 | existing sec->reloc_count to be the base of the array of |
| 4062 | PLT relocations. */ |
| 4063 | |
| 4064 | rel = (ElfNN_External_Rela *)ia64_info->rel_pltoff_sec->contents; |
| 4065 | rel += ia64_info->rel_pltoff_sec->reloc_count; |
| 4066 | |
| 4067 | bfd_elfNN_swap_reloca_out (output_bfd, &outrel, rel + index); |
| 4068 | } |
| 4069 | |
| 4070 | /* Mark some specially defined symbols as absolute. */ |
| 4071 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0 |
| 4072 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0 |
| 4073 | || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0) |
| 4074 | sym->st_shndx = SHN_ABS; |
| 4075 | |
| 4076 | return true; |
| 4077 | } |
| 4078 | |
| 4079 | static boolean |
| 4080 | elfNN_ia64_finish_dynamic_sections (abfd, info) |
| 4081 | bfd *abfd; |
| 4082 | struct bfd_link_info *info; |
| 4083 | { |
| 4084 | struct elfNN_ia64_link_hash_table *ia64_info; |
| 4085 | bfd *dynobj; |
| 4086 | |
| 4087 | ia64_info = elfNN_ia64_hash_table (info); |
| 4088 | dynobj = ia64_info->root.dynobj; |
| 4089 | |
| 4090 | if (elf_hash_table (info)->dynamic_sections_created) |
| 4091 | { |
| 4092 | ElfNN_External_Dyn *dyncon, *dynconend; |
| 4093 | asection *sdyn, *sgotplt; |
| 4094 | bfd_vma gp_val; |
| 4095 | |
| 4096 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
| 4097 | sgotplt = bfd_get_section_by_name (dynobj, ".got.plt"); |
| 4098 | BFD_ASSERT (sdyn != NULL); |
| 4099 | dyncon = (ElfNN_External_Dyn *) sdyn->contents; |
| 4100 | dynconend = (ElfNN_External_Dyn *) (sdyn->contents + sdyn->_raw_size); |
| 4101 | |
| 4102 | gp_val = _bfd_get_gp_value (abfd); |
| 4103 | |
| 4104 | for (; dyncon < dynconend; dyncon++) |
| 4105 | { |
| 4106 | Elf_Internal_Dyn dyn; |
| 4107 | |
| 4108 | bfd_elfNN_swap_dyn_in (dynobj, dyncon, &dyn); |
| 4109 | |
| 4110 | switch (dyn.d_tag) |
| 4111 | { |
| 4112 | case DT_PLTGOT: |
| 4113 | dyn.d_un.d_ptr = gp_val; |
| 4114 | break; |
| 4115 | |
| 4116 | case DT_PLTRELSZ: |
| 4117 | dyn.d_un.d_val = (ia64_info->minplt_entries |
| 4118 | * sizeof (ElfNN_External_Rela)); |
| 4119 | break; |
| 4120 | |
| 4121 | case DT_JMPREL: |
| 4122 | /* See the comment above in finish_dynamic_symbol. */ |
| 4123 | dyn.d_un.d_ptr = (ia64_info->rel_pltoff_sec->output_section->vma |
| 4124 | + ia64_info->rel_pltoff_sec->output_offset |
| 4125 | + (ia64_info->rel_pltoff_sec->reloc_count |
| 4126 | * sizeof (ElfNN_External_Rela))); |
| 4127 | break; |
| 4128 | |
| 4129 | case DT_IA_64_PLT_RESERVE: |
| 4130 | dyn.d_un.d_ptr = (sgotplt->output_section->vma |
| 4131 | + sgotplt->output_offset); |
| 4132 | break; |
| 4133 | |
| 4134 | case DT_RELASZ: |
| 4135 | /* Do not have RELASZ include JMPREL. This makes things |
| 4136 | easier on ld.so. This is not what the rest of BFD set up. */ |
| 4137 | dyn.d_un.d_val -= (ia64_info->minplt_entries |
| 4138 | * sizeof (ElfNN_External_Rela)); |
| 4139 | break; |
| 4140 | } |
| 4141 | |
| 4142 | bfd_elfNN_swap_dyn_out (abfd, &dyn, dyncon); |
| 4143 | } |
| 4144 | |
| 4145 | /* Initialize the PLT0 entry */ |
| 4146 | if (ia64_info->plt_sec) |
| 4147 | { |
| 4148 | bfd_byte *loc = ia64_info->plt_sec->contents; |
| 4149 | bfd_vma pltres; |
| 4150 | |
| 4151 | memcpy (loc, plt_header, PLT_HEADER_SIZE); |
| 4152 | |
| 4153 | pltres = (sgotplt->output_section->vma |
| 4154 | + sgotplt->output_offset |
| 4155 | - gp_val); |
| 4156 | |
| 4157 | elfNN_ia64_install_value (abfd, loc+1, pltres, R_IA64_GPREL22); |
| 4158 | } |
| 4159 | } |
| 4160 | |
| 4161 | return true; |
| 4162 | } |
| 4163 | \f |
| 4164 | /* ELF file flag handling: */ |
| 4165 | |
| 4166 | /* Function to keep IA-64 specific file flags. */ |
| 4167 | static boolean |
| 4168 | elfNN_ia64_set_private_flags (abfd, flags) |
| 4169 | bfd *abfd; |
| 4170 | flagword flags; |
| 4171 | { |
| 4172 | BFD_ASSERT (!elf_flags_init (abfd) |
| 4173 | || elf_elfheader (abfd)->e_flags == flags); |
| 4174 | |
| 4175 | elf_elfheader (abfd)->e_flags = flags; |
| 4176 | elf_flags_init (abfd) = true; |
| 4177 | return true; |
| 4178 | } |
| 4179 | |
| 4180 | /* Copy backend specific data from one object module to another */ |
| 4181 | static boolean |
| 4182 | elfNN_ia64_copy_private_bfd_data (ibfd, obfd) |
| 4183 | bfd *ibfd, *obfd; |
| 4184 | { |
| 4185 | if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
| 4186 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) |
| 4187 | return true; |
| 4188 | |
| 4189 | BFD_ASSERT (!elf_flags_init (obfd) |
| 4190 | || (elf_elfheader (obfd)->e_flags |
| 4191 | == elf_elfheader (ibfd)->e_flags)); |
| 4192 | |
| 4193 | elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags; |
| 4194 | elf_flags_init (obfd) = true; |
| 4195 | return true; |
| 4196 | } |
| 4197 | |
| 4198 | /* Merge backend specific data from an object file to the output |
| 4199 | object file when linking. */ |
| 4200 | static boolean |
| 4201 | elfNN_ia64_merge_private_bfd_data (ibfd, obfd) |
| 4202 | bfd *ibfd, *obfd; |
| 4203 | { |
| 4204 | flagword out_flags; |
| 4205 | flagword in_flags; |
| 4206 | boolean ok = true; |
| 4207 | |
| 4208 | /* Don't even pretend to support mixed-format linking. */ |
| 4209 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
| 4210 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) |
| 4211 | return false; |
| 4212 | |
| 4213 | in_flags = elf_elfheader (ibfd)->e_flags; |
| 4214 | out_flags = elf_elfheader (obfd)->e_flags; |
| 4215 | |
| 4216 | if (! elf_flags_init (obfd)) |
| 4217 | { |
| 4218 | elf_flags_init (obfd) = true; |
| 4219 | elf_elfheader (obfd)->e_flags = in_flags; |
| 4220 | |
| 4221 | if (bfd_get_arch (obfd) == bfd_get_arch (ibfd) |
| 4222 | && bfd_get_arch_info (obfd)->the_default) |
| 4223 | { |
| 4224 | return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), |
| 4225 | bfd_get_mach (ibfd)); |
| 4226 | } |
| 4227 | |
| 4228 | return true; |
| 4229 | } |
| 4230 | |
| 4231 | /* Check flag compatibility. */ |
| 4232 | if (in_flags == out_flags) |
| 4233 | return true; |
| 4234 | |
| 4235 | /* Output has EF_IA_64_REDUCEDFP set only if all inputs have it set. */ |
| 4236 | if (!(in_flags & EF_IA_64_REDUCEDFP) && (out_flags & EF_IA_64_REDUCEDFP)) |
| 4237 | elf_elfheader (obfd)->e_flags &= ~EF_IA_64_REDUCEDFP; |
| 4238 | |
| 4239 | if ((in_flags & EF_IA_64_TRAPNIL) != (out_flags & EF_IA_64_TRAPNIL)) |
| 4240 | { |
| 4241 | (*_bfd_error_handler) |
| 4242 | (_("%s: linking trap-on-NULL-dereference with non-trapping files"), |
| 4243 | bfd_get_filename (ibfd)); |
| 4244 | |
| 4245 | bfd_set_error (bfd_error_bad_value); |
| 4246 | ok = false; |
| 4247 | } |
| 4248 | if ((in_flags & EF_IA_64_BE) != (out_flags & EF_IA_64_BE)) |
| 4249 | { |
| 4250 | (*_bfd_error_handler) |
| 4251 | (_("%s: linking big-endian files with little-endian files"), |
| 4252 | bfd_get_filename (ibfd)); |
| 4253 | |
| 4254 | bfd_set_error (bfd_error_bad_value); |
| 4255 | ok = false; |
| 4256 | } |
| 4257 | if ((in_flags & EF_IA_64_ABI64) != (out_flags & EF_IA_64_ABI64)) |
| 4258 | { |
| 4259 | (*_bfd_error_handler) |
| 4260 | (_("%s: linking 64-bit files with 32-bit files"), |
| 4261 | bfd_get_filename (ibfd)); |
| 4262 | |
| 4263 | bfd_set_error (bfd_error_bad_value); |
| 4264 | ok = false; |
| 4265 | } |
| 4266 | if ((in_flags & EF_IA_64_CONS_GP) != (out_flags & EF_IA_64_CONS_GP)) |
| 4267 | { |
| 4268 | (*_bfd_error_handler) |
| 4269 | (_("%s: linking constant-gp files with non-constant-gp files"), |
| 4270 | bfd_get_filename (ibfd)); |
| 4271 | |
| 4272 | bfd_set_error (bfd_error_bad_value); |
| 4273 | ok = false; |
| 4274 | } |
| 4275 | if ((in_flags & EF_IA_64_NOFUNCDESC_CONS_GP) |
| 4276 | != (out_flags & EF_IA_64_NOFUNCDESC_CONS_GP)) |
| 4277 | { |
| 4278 | (*_bfd_error_handler) |
| 4279 | (_("%s: linking auto-pic files with non-auto-pic files"), |
| 4280 | bfd_get_filename (ibfd)); |
| 4281 | |
| 4282 | bfd_set_error (bfd_error_bad_value); |
| 4283 | ok = false; |
| 4284 | } |
| 4285 | |
| 4286 | return ok; |
| 4287 | } |
| 4288 | |
| 4289 | static boolean |
| 4290 | elfNN_ia64_print_private_bfd_data (abfd, ptr) |
| 4291 | bfd *abfd; |
| 4292 | PTR ptr; |
| 4293 | { |
| 4294 | FILE *file = (FILE *) ptr; |
| 4295 | flagword flags = elf_elfheader (abfd)->e_flags; |
| 4296 | |
| 4297 | BFD_ASSERT (abfd != NULL && ptr != NULL); |
| 4298 | |
| 4299 | fprintf (file, "private flags = %s%s%s%s%s%s%s%s\n", |
| 4300 | (flags & EF_IA_64_TRAPNIL) ? "TRAPNIL, " : "", |
| 4301 | (flags & EF_IA_64_EXT) ? "EXT, " : "", |
| 4302 | (flags & EF_IA_64_BE) ? "BE, " : "LE, ", |
| 4303 | (flags & EF_IA_64_REDUCEDFP) ? "REDUCEDFP, " : "", |
| 4304 | (flags & EF_IA_64_CONS_GP) ? "CONS_GP, " : "", |
| 4305 | (flags & EF_IA_64_NOFUNCDESC_CONS_GP) ? "NOFUNCDESC_CONS_GP, " : "", |
| 4306 | (flags & EF_IA_64_ABSOLUTE) ? "ABSOLUTE, " : "", |
| 4307 | (flags & EF_IA_64_ABI64) ? "ABI64" : "ABI32"); |
| 4308 | |
| 4309 | _bfd_elf_print_private_bfd_data (abfd, ptr); |
| 4310 | return true; |
| 4311 | } |
| 4312 | \f |
| 4313 | #define TARGET_LITTLE_SYM bfd_elfNN_ia64_little_vec |
| 4314 | #define TARGET_LITTLE_NAME "elfNN-ia64-little" |
| 4315 | #define TARGET_BIG_SYM bfd_elfNN_ia64_big_vec |
| 4316 | #define TARGET_BIG_NAME "elfNN-ia64-big" |
| 4317 | #define ELF_ARCH bfd_arch_ia64 |
| 4318 | #define ELF_MACHINE_CODE EM_IA_64 |
| 4319 | #define ELF_MACHINE_ALT1 1999 /* EAS2.3 */ |
| 4320 | #define ELF_MACHINE_ALT2 1998 /* EAS2.2 */ |
| 4321 | #define ELF_MAXPAGESIZE 0x10000 /* 64KB */ |
| 4322 | |
| 4323 | #define elf_backend_section_from_shdr \ |
| 4324 | elfNN_ia64_section_from_shdr |
| 4325 | #define elf_backend_section_flags \ |
| 4326 | elfNN_ia64_section_flags |
| 4327 | #define elf_backend_fake_sections \ |
| 4328 | elfNN_ia64_fake_sections |
| 4329 | #define elf_backend_final_write_processing \ |
| 4330 | elfNN_ia64_final_write_processing |
| 4331 | #define elf_backend_add_symbol_hook \ |
| 4332 | elfNN_ia64_add_symbol_hook |
| 4333 | #define elf_backend_additional_program_headers \ |
| 4334 | elfNN_ia64_additional_program_headers |
| 4335 | #define elf_backend_modify_segment_map \ |
| 4336 | elfNN_ia64_modify_segment_map |
| 4337 | #define elf_info_to_howto \ |
| 4338 | elfNN_ia64_info_to_howto |
| 4339 | |
| 4340 | #define bfd_elfNN_bfd_reloc_type_lookup \ |
| 4341 | elfNN_ia64_reloc_type_lookup |
| 4342 | #define bfd_elfNN_bfd_is_local_label_name \ |
| 4343 | elfNN_ia64_is_local_label_name |
| 4344 | #define bfd_elfNN_bfd_relax_section \ |
| 4345 | elfNN_ia64_relax_section |
| 4346 | |
| 4347 | /* Stuff for the BFD linker: */ |
| 4348 | #define bfd_elfNN_bfd_link_hash_table_create \ |
| 4349 | elfNN_ia64_hash_table_create |
| 4350 | #define elf_backend_create_dynamic_sections \ |
| 4351 | elfNN_ia64_create_dynamic_sections |
| 4352 | #define elf_backend_check_relocs \ |
| 4353 | elfNN_ia64_check_relocs |
| 4354 | #define elf_backend_adjust_dynamic_symbol \ |
| 4355 | elfNN_ia64_adjust_dynamic_symbol |
| 4356 | #define elf_backend_size_dynamic_sections \ |
| 4357 | elfNN_ia64_size_dynamic_sections |
| 4358 | #define elf_backend_relocate_section \ |
| 4359 | elfNN_ia64_relocate_section |
| 4360 | #define elf_backend_finish_dynamic_symbol \ |
| 4361 | elfNN_ia64_finish_dynamic_symbol |
| 4362 | #define elf_backend_finish_dynamic_sections \ |
| 4363 | elfNN_ia64_finish_dynamic_sections |
| 4364 | #define bfd_elfNN_bfd_final_link \ |
| 4365 | elfNN_ia64_final_link |
| 4366 | |
| 4367 | #define bfd_elfNN_bfd_copy_private_bfd_data \ |
| 4368 | elfNN_ia64_copy_private_bfd_data |
| 4369 | #define bfd_elfNN_bfd_merge_private_bfd_data \ |
| 4370 | elfNN_ia64_merge_private_bfd_data |
| 4371 | #define bfd_elfNN_bfd_set_private_flags \ |
| 4372 | elfNN_ia64_set_private_flags |
| 4373 | #define bfd_elfNN_bfd_print_private_bfd_data \ |
| 4374 | elfNN_ia64_print_private_bfd_data |
| 4375 | |
| 4376 | #define elf_backend_plt_readonly 1 |
| 4377 | #define elf_backend_want_plt_sym 0 |
| 4378 | #define elf_backend_plt_alignment 5 |
| 4379 | #define elf_backend_got_header_size 0 |
| 4380 | #define elf_backend_plt_header_size PLT_HEADER_SIZE |
| 4381 | #define elf_backend_want_got_plt 1 |
| 4382 | #define elf_backend_may_use_rel_p 1 |
| 4383 | #define elf_backend_may_use_rela_p 1 |
| 4384 | #define elf_backend_default_use_rela_p 1 |
| 4385 | #define elf_backend_want_dynbss 0 |
| 4386 | #define elf_backend_copy_indirect_symbol elfNN_ia64_hash_copy_indirect |
| 4387 | #define elf_backend_hide_symbol elfNN_ia64_hash_hide_symbol |
| 4388 | |
| 4389 | #include "elfNN-target.h" |
| 4390 | |
| 4391 | /* AIX-specific vectors. */ |
| 4392 | |
| 4393 | #undef TARGET_LITTLE_SYM |
| 4394 | #define TARGET_LITTLE_SYM bfd_elfNN_ia64_aix_little_vec |
| 4395 | #undef TARGET_LITTLE_NAME |
| 4396 | #define TARGET_LITTLE_NAME "elfNN-ia64-aix-little" |
| 4397 | #undef TARGET_BIG_SYM |
| 4398 | #define TARGET_BIG_SYM bfd_elfNN_ia64_aix_big_vec |
| 4399 | #undef TARGET_BIG_NAME |
| 4400 | #define TARGET_BIG_NAME "elfNN-ia64-aix-big" |
| 4401 | |
| 4402 | #undef elf_backend_add_symbol_hook |
| 4403 | #define elf_backend_add_symbol_hook elfNN_ia64_aix_add_symbol_hook |
| 4404 | |
| 4405 | #undef bfd_elfNN_bfd_link_add_symbols |
| 4406 | #define bfd_elfNN_bfd_link_add_symbols elfNN_ia64_aix_link_add_symbols |
| 4407 | |
| 4408 | #define elfNN_bed elfNN_ia64_aix_bed |
| 4409 | |
| 4410 | #include "elfNN-target.h" |