1 1.1 christos /* IA-64 support for OpenVMS 2 1.11 christos Copyright (C) 1998-2024 Free Software Foundation, Inc. 3 1.1 christos 4 1.1 christos This file is part of BFD, the Binary File Descriptor library. 5 1.1 christos 6 1.1 christos This program is free software; you can redistribute it and/or modify 7 1.1 christos it under the terms of the GNU General Public License as published by 8 1.1 christos the Free Software Foundation; either version 3 of the License, or 9 1.1 christos (at your option) any later version. 10 1.1 christos 11 1.1 christos This program is distributed in the hope that it will be useful, 12 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 13 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 1.1 christos GNU General Public License for more details. 15 1.1 christos 16 1.1 christos You should have received a copy of the GNU General Public License 17 1.1 christos along with this program; if not, write to the Free Software 18 1.1 christos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 19 1.1 christos MA 02110-1301, USA. */ 20 1.1 christos 21 1.1 christos #include "sysdep.h" 22 1.1 christos #include "bfd.h" 23 1.1 christos #include "libbfd.h" 24 1.1 christos #include "elf-bfd.h" 25 1.1 christos #include "opcode/ia64.h" 26 1.1 christos #include "elf/ia64.h" 27 1.1 christos #include "objalloc.h" 28 1.1 christos #include "hashtab.h" 29 1.1 christos #include "elfxx-ia64.h" 30 1.1 christos #include "vms.h" 31 1.1 christos #include "bfdver.h" 32 1.1 christos 33 1.1 christos /* THE RULES for all the stuff the linker creates -- 34 1.1 christos 35 1.1 christos GOT Entries created in response to LTOFF or LTOFF_FPTR 36 1.1 christos relocations. Dynamic relocs created for dynamic 37 1.1 christos symbols in an application; REL relocs for locals 38 1.1 christos in a shared library. 39 1.1 christos 40 1.1 christos FPTR The canonical function descriptor. Created for local 41 1.1 christos symbols in applications. Descriptors for dynamic symbols 42 1.1 christos and local symbols in shared libraries are created by 43 1.1 christos ld.so. Thus there are no dynamic relocs against these 44 1.1 christos objects. The FPTR relocs for such _are_ passed through 45 1.1 christos to the dynamic relocation tables. 46 1.1 christos 47 1.1 christos FULL_PLT Created for a PCREL21B relocation against a dynamic symbol. 48 1.1 christos Requires the creation of a PLTOFF entry. This does not 49 1.1 christos require any dynamic relocations. 50 1.1 christos 51 1.1 christos PLTOFF Created by PLTOFF relocations. For local symbols, this 52 1.1 christos is an alternate function descriptor, and in shared libraries 53 1.1 christos requires two REL relocations. Note that this cannot be 54 1.1 christos transformed into an FPTR relocation, since it must be in 55 1.1 christos range of the GP. For dynamic symbols, this is a function 56 1.1 christos descriptor. */ 57 1.1 christos 58 1.1 christos typedef struct bfd_hash_entry *(*new_hash_entry_func) 59 1.1 christos (struct bfd_hash_entry *, struct bfd_hash_table *, const char *); 60 1.1 christos 61 1.1 christos /* In dynamically (linker-) created sections, we generally need to keep track 62 1.1 christos of the place a symbol or expression got allocated to. This is done via hash 63 1.1 christos tables that store entries of the following type. */ 64 1.1 christos 65 1.1 christos struct elf64_ia64_dyn_sym_info 66 1.1 christos { 67 1.1 christos /* The addend for which this entry is relevant. */ 68 1.1 christos bfd_vma addend; 69 1.1 christos 70 1.1 christos bfd_vma got_offset; 71 1.1 christos bfd_vma fptr_offset; 72 1.1 christos bfd_vma pltoff_offset; 73 1.1 christos bfd_vma plt_offset; 74 1.1 christos bfd_vma plt2_offset; 75 1.1 christos 76 1.1 christos /* The symbol table entry, if any, that this was derived from. */ 77 1.1 christos struct elf_link_hash_entry *h; 78 1.1 christos 79 1.1 christos /* Used to count non-got, non-plt relocations for delayed sizing 80 1.1 christos of relocation sections. */ 81 1.1 christos struct elf64_ia64_dyn_reloc_entry 82 1.1 christos { 83 1.1 christos struct elf64_ia64_dyn_reloc_entry *next; 84 1.1 christos asection *srel; 85 1.1 christos int type; 86 1.1 christos int count; 87 1.1 christos } *reloc_entries; 88 1.1 christos 89 1.1 christos /* TRUE when the section contents have been updated. */ 90 1.1 christos unsigned got_done : 1; 91 1.1 christos unsigned fptr_done : 1; 92 1.1 christos unsigned pltoff_done : 1; 93 1.1 christos 94 1.1 christos /* TRUE for the different kinds of linker data we want created. */ 95 1.1 christos unsigned want_got : 1; 96 1.1 christos unsigned want_gotx : 1; 97 1.1 christos unsigned want_fptr : 1; 98 1.1 christos unsigned want_ltoff_fptr : 1; 99 1.1 christos unsigned want_plt : 1; /* A MIN_PLT entry. */ 100 1.1 christos unsigned want_plt2 : 1; /* A FULL_PLT. */ 101 1.1 christos unsigned want_pltoff : 1; 102 1.1 christos }; 103 1.1 christos 104 1.1 christos struct elf64_ia64_local_hash_entry 105 1.1 christos { 106 1.1 christos int id; 107 1.1 christos unsigned int r_sym; 108 1.1 christos /* The number of elements in elf64_ia64_dyn_sym_info array. */ 109 1.1 christos unsigned int count; 110 1.1 christos /* The number of sorted elements in elf64_ia64_dyn_sym_info array. */ 111 1.1 christos unsigned int sorted_count; 112 1.1 christos /* The size of elf64_ia64_dyn_sym_info array. */ 113 1.1 christos unsigned int size; 114 1.1 christos /* The array of elf64_ia64_dyn_sym_info. */ 115 1.1 christos struct elf64_ia64_dyn_sym_info *info; 116 1.1 christos 117 1.1 christos /* TRUE if this hash entry's addends was translated for 118 1.1 christos SHF_MERGE optimization. */ 119 1.1 christos unsigned sec_merge_done : 1; 120 1.1 christos }; 121 1.1 christos 122 1.1 christos struct elf64_ia64_link_hash_entry 123 1.1 christos { 124 1.1 christos struct elf_link_hash_entry root; 125 1.1 christos 126 1.1 christos /* Set if this symbol is defined in a shared library. 127 1.1 christos We can't use root.u.def.section->owner as the symbol is an absolute 128 1.1 christos symbol. */ 129 1.1 christos bfd *shl; 130 1.1 christos 131 1.1 christos /* The number of elements in elf64_ia64_dyn_sym_info array. */ 132 1.1 christos unsigned int count; 133 1.1 christos /* The number of sorted elements in elf64_ia64_dyn_sym_info array. */ 134 1.1 christos unsigned int sorted_count; 135 1.1 christos /* The size of elf64_ia64_dyn_sym_info array. */ 136 1.1 christos unsigned int size; 137 1.1 christos /* The array of elf64_ia64_dyn_sym_info. */ 138 1.1 christos struct elf64_ia64_dyn_sym_info *info; 139 1.1 christos }; 140 1.1 christos 141 1.1 christos struct elf64_ia64_link_hash_table 142 1.1 christos { 143 1.1 christos /* The main hash table. */ 144 1.1 christos struct elf_link_hash_table root; 145 1.1 christos 146 1.1 christos asection *fptr_sec; /* Function descriptor table (or NULL). */ 147 1.1 christos asection *rel_fptr_sec; /* Dynamic relocation section for same. */ 148 1.1 christos asection *pltoff_sec; /* Private descriptors for plt (or NULL). */ 149 1.1 christos asection *fixups_sec; /* Fixups section. */ 150 1.1 christos asection *transfer_sec; /* Transfer vector section. */ 151 1.1 christos asection *note_sec; /* .note section. */ 152 1.1 christos 153 1.1 christos /* There are maybe R_IA64_GPREL22 relocations, including those 154 1.1 christos optimized from R_IA64_LTOFF22X, against non-SHF_IA_64_SHORT 155 1.1 christos sections. We need to record those sections so that we can choose 156 1.1 christos a proper GP to cover all R_IA64_GPREL22 relocations. */ 157 1.1 christos asection *max_short_sec; /* Maximum short output section. */ 158 1.1 christos bfd_vma max_short_offset; /* Maximum short offset. */ 159 1.1 christos asection *min_short_sec; /* Minimum short output section. */ 160 1.1 christos bfd_vma min_short_offset; /* Minimum short offset. */ 161 1.1 christos 162 1.1 christos htab_t loc_hash_table; 163 1.1 christos void *loc_hash_memory; 164 1.1 christos }; 165 1.1 christos 166 1.1 christos struct elf64_ia64_allocate_data 167 1.1 christos { 168 1.1 christos struct bfd_link_info *info; 169 1.1 christos bfd_size_type ofs; 170 1.1 christos }; 171 1.1 christos 172 1.1 christos #define elf64_ia64_hash_table(p) \ 173 1.9 christos ((is_elf_hash_table ((p)->hash) \ 174 1.9 christos && elf_hash_table_id (elf_hash_table (p)) == IA64_ELF_DATA) \ 175 1.9 christos ? (struct elf64_ia64_link_hash_table *) (p)->hash : NULL) 176 1.1 christos 177 1.1 christos struct elf64_ia64_vms_obj_tdata 178 1.1 christos { 179 1.1 christos struct elf_obj_tdata root; 180 1.1 christos 181 1.1 christos /* Ident for shared library. */ 182 1.10 christos uint64_t ident; 183 1.1 christos 184 1.1 christos /* Used only during link: offset in the .fixups section for this bfd. */ 185 1.1 christos bfd_vma fixups_off; 186 1.1 christos 187 1.1 christos /* Max number of shared libraries. */ 188 1.1 christos unsigned int needed_count; 189 1.1 christos }; 190 1.1 christos 191 1.1 christos #define elf_ia64_vms_tdata(abfd) \ 192 1.1 christos ((struct elf64_ia64_vms_obj_tdata *)((abfd)->tdata.any)) 193 1.1 christos #define elf_ia64_vms_ident(abfd) (elf_ia64_vms_tdata(abfd)->ident) 194 1.1 christos 195 1.1 christos struct elf64_vms_transfer 196 1.1 christos { 197 1.1 christos unsigned char size[4]; 198 1.1 christos unsigned char spare[4]; 199 1.1 christos unsigned char tfradr1[8]; 200 1.1 christos unsigned char tfradr2[8]; 201 1.1 christos unsigned char tfradr3[8]; 202 1.1 christos unsigned char tfradr4[8]; 203 1.1 christos unsigned char tfradr5[8]; 204 1.1 christos 205 1.1 christos /* Local function descriptor for tfr3. */ 206 1.1 christos unsigned char tfr3_func[8]; 207 1.1 christos unsigned char tfr3_gp[8]; 208 1.1 christos }; 209 1.1 christos 210 1.1 christos typedef struct 211 1.1 christos { 212 1.1 christos Elf64_External_Ehdr ehdr; 213 1.1 christos unsigned char vms_needed_count[8]; 214 1.1 christos } Elf64_External_VMS_Ehdr; 215 1.1 christos 216 1.1 christos static struct elf64_ia64_dyn_sym_info * get_dyn_sym_info 217 1.1 christos (struct elf64_ia64_link_hash_table *, 218 1.1 christos struct elf_link_hash_entry *, 219 1.10 christos bfd *, const Elf_Internal_Rela *, bool); 220 1.10 christos static bool elf64_ia64_dynamic_symbol_p 221 1.1 christos (struct elf_link_hash_entry *); 222 1.10 christos static bool elf64_ia64_choose_gp 223 1.10 christos (bfd *, struct bfd_link_info *, bool); 224 1.1 christos static void elf64_ia64_dyn_sym_traverse 225 1.1 christos (struct elf64_ia64_link_hash_table *, 226 1.10 christos bool (*) (struct elf64_ia64_dyn_sym_info *, void *), 227 1.1 christos void *); 228 1.10 christos static bool allocate_global_data_got 229 1.1 christos (struct elf64_ia64_dyn_sym_info *, void *); 230 1.10 christos static bool allocate_global_fptr_got 231 1.1 christos (struct elf64_ia64_dyn_sym_info *, void *); 232 1.10 christos static bool allocate_local_got 233 1.1 christos (struct elf64_ia64_dyn_sym_info *, void *); 234 1.10 christos static bool allocate_dynrel_entries 235 1.1 christos (struct elf64_ia64_dyn_sym_info *, void *); 236 1.1 christos static asection *get_pltoff 237 1.1 christos (bfd *, struct elf64_ia64_link_hash_table *); 238 1.1 christos static asection *get_got 239 1.1 christos (bfd *, struct elf64_ia64_link_hash_table *); 240 1.1 christos 241 1.1 christos 242 1.1 christos /* Given a ELF reloc, return the matching HOWTO structure. */ 243 1.1 christos 244 1.10 christos static bool 245 1.1 christos elf64_ia64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, 246 1.1 christos arelent *bfd_reloc, 247 1.1 christos Elf_Internal_Rela *elf_reloc) 248 1.1 christos { 249 1.8 christos unsigned int r_type = ELF32_R_TYPE (elf_reloc->r_info); 250 1.8 christos 251 1.8 christos bfd_reloc->howto = ia64_elf_lookup_howto (r_type); 252 1.8 christos if (bfd_reloc->howto == NULL) 253 1.8 christos { 254 1.8 christos /* xgettext:c-format */ 255 1.8 christos _bfd_error_handler (_("%pB: unsupported relocation type %#x"), 256 1.8 christos abfd, r_type); 257 1.8 christos bfd_set_error (bfd_error_bad_value); 258 1.10 christos return false; 259 1.8 christos } 260 1.8 christos 261 1.10 christos return true; 262 1.1 christos } 263 1.1 christos 264 1.1 christos 265 1.1 christos #define PLT_FULL_ENTRY_SIZE (2 * 16) 266 1.1 christos 267 1.1 christos static const bfd_byte plt_full_entry[PLT_FULL_ENTRY_SIZE] = 268 1.1 christos { 269 1.8 christos 0x0b, 0x78, 0x00, 0x02, 0x00, 0x24, /* [MMI] addl r15=0,r1;; */ 270 1.8 christos 0x00, 0x41, 0x3c, 0x70, 0x29, 0xc0, /* ld8.acq r16=[r15],8*/ 271 1.8 christos 0x01, 0x08, 0x00, 0x84, /* mov r14=r1;; */ 272 1.8 christos 0x11, 0x08, 0x00, 0x1e, 0x18, 0x10, /* [MIB] ld8 r1=[r15] */ 273 1.8 christos 0x60, 0x80, 0x04, 0x80, 0x03, 0x00, /* mov b6=r16 */ 274 1.8 christos 0x60, 0x00, 0x80, 0x00 /* br.few b6;; */ 275 1.1 christos }; 276 1.1 christos 277 1.1 christos static const bfd_byte oor_brl[16] = 278 1.1 christos { 279 1.8 christos 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MLX] nop.m 0 */ 280 1.8 christos 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* brl.sptk.few tgt;;*/ 281 1.1 christos 0x00, 0x00, 0x00, 0xc0 282 1.1 christos }; 283 1.1 christos 284 1.1 christos 285 1.1 christos /* These functions do relaxation for IA-64 ELF. */ 286 1.1 christos 287 1.1 christos /* Rename some of the generic section flags to better document how they 288 1.1 christos are used here. */ 289 1.1 christos #define skip_relax_pass_0 sec_flg0 290 1.1 christos #define skip_relax_pass_1 sec_flg1 291 1.1 christos 292 1.1 christos static void 293 1.1 christos elf64_ia64_update_short_info (asection *sec, bfd_vma offset, 294 1.1 christos struct elf64_ia64_link_hash_table *ia64_info) 295 1.1 christos { 296 1.1 christos /* Skip ABS and SHF_IA_64_SHORT sections. */ 297 1.1 christos if (sec == bfd_abs_section_ptr 298 1.1 christos || (sec->flags & SEC_SMALL_DATA) != 0) 299 1.1 christos return; 300 1.1 christos 301 1.1 christos if (!ia64_info->min_short_sec) 302 1.1 christos { 303 1.1 christos ia64_info->max_short_sec = sec; 304 1.1 christos ia64_info->max_short_offset = offset; 305 1.1 christos ia64_info->min_short_sec = sec; 306 1.1 christos ia64_info->min_short_offset = offset; 307 1.1 christos } 308 1.1 christos else if (sec == ia64_info->max_short_sec 309 1.1 christos && offset > ia64_info->max_short_offset) 310 1.1 christos ia64_info->max_short_offset = offset; 311 1.1 christos else if (sec == ia64_info->min_short_sec 312 1.1 christos && offset < ia64_info->min_short_offset) 313 1.1 christos ia64_info->min_short_offset = offset; 314 1.1 christos else if (sec->output_section->vma 315 1.1 christos > ia64_info->max_short_sec->vma) 316 1.1 christos { 317 1.1 christos ia64_info->max_short_sec = sec; 318 1.1 christos ia64_info->max_short_offset = offset; 319 1.1 christos } 320 1.1 christos else if (sec->output_section->vma 321 1.1 christos < ia64_info->min_short_sec->vma) 322 1.1 christos { 323 1.1 christos ia64_info->min_short_sec = sec; 324 1.1 christos ia64_info->min_short_offset = offset; 325 1.1 christos } 326 1.1 christos } 327 1.1 christos 328 1.1 christos /* Use a two passes algorithm. In the first pass, branches are relaxed 329 1.1 christos (which may increase the size of the section). In the second pass, 330 1.1 christos the other relaxations are done. 331 1.1 christos */ 332 1.1 christos 333 1.10 christos static bool 334 1.1 christos elf64_ia64_relax_section (bfd *abfd, asection *sec, 335 1.1 christos struct bfd_link_info *link_info, 336 1.10 christos bool *again) 337 1.1 christos { 338 1.1 christos struct one_fixup 339 1.1 christos { 340 1.1 christos struct one_fixup *next; 341 1.1 christos asection *tsec; 342 1.1 christos bfd_vma toff; 343 1.1 christos bfd_vma trampoff; 344 1.1 christos }; 345 1.1 christos 346 1.1 christos Elf_Internal_Shdr *symtab_hdr; 347 1.1 christos Elf_Internal_Rela *internal_relocs; 348 1.1 christos Elf_Internal_Rela *irel, *irelend; 349 1.1 christos bfd_byte *contents; 350 1.1 christos Elf_Internal_Sym *isymbuf = NULL; 351 1.1 christos struct elf64_ia64_link_hash_table *ia64_info; 352 1.1 christos struct one_fixup *fixups = NULL; 353 1.10 christos bool changed_contents = false; 354 1.10 christos bool changed_relocs = false; 355 1.10 christos bool skip_relax_pass_0 = true; 356 1.10 christos bool skip_relax_pass_1 = true; 357 1.1 christos bfd_vma gp = 0; 358 1.1 christos 359 1.1 christos /* Assume we're not going to change any sizes, and we'll only need 360 1.1 christos one pass. */ 361 1.10 christos *again = false; 362 1.1 christos 363 1.6 christos if (bfd_link_relocatable (link_info)) 364 1.1 christos (*link_info->callbacks->einfo) 365 1.1 christos (_("%P%F: --relax and -r may not be used together\n")); 366 1.1 christos 367 1.1 christos /* Don't even try to relax for non-ELF outputs. */ 368 1.1 christos if (!is_elf_hash_table (link_info->hash)) 369 1.10 christos return false; 370 1.1 christos 371 1.1 christos /* Nothing to do if there are no relocations or there is no need for 372 1.1 christos the current pass. */ 373 1.11 christos if (sec->reloc_count == 0 374 1.11 christos || (sec->flags & SEC_RELOC) == 0 375 1.11 christos || (sec->flags & SEC_HAS_CONTENTS) == 0 376 1.1 christos || (link_info->relax_pass == 0 && sec->skip_relax_pass_0) 377 1.1 christos || (link_info->relax_pass == 1 && sec->skip_relax_pass_1)) 378 1.10 christos return true; 379 1.1 christos 380 1.1 christos ia64_info = elf64_ia64_hash_table (link_info); 381 1.1 christos if (ia64_info == NULL) 382 1.10 christos return false; 383 1.1 christos 384 1.1 christos symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 385 1.1 christos 386 1.1 christos /* Load the relocations for this section. */ 387 1.1 christos internal_relocs = (_bfd_elf_link_read_relocs 388 1.1 christos (abfd, sec, NULL, (Elf_Internal_Rela *) NULL, 389 1.1 christos link_info->keep_memory)); 390 1.1 christos if (internal_relocs == NULL) 391 1.10 christos return false; 392 1.1 christos 393 1.1 christos irelend = internal_relocs + sec->reloc_count; 394 1.1 christos 395 1.1 christos /* Get the section contents. */ 396 1.1 christos if (elf_section_data (sec)->this_hdr.contents != NULL) 397 1.1 christos contents = elf_section_data (sec)->this_hdr.contents; 398 1.1 christos else 399 1.1 christos { 400 1.1 christos if (!bfd_malloc_and_get_section (abfd, sec, &contents)) 401 1.1 christos goto error_return; 402 1.1 christos } 403 1.1 christos 404 1.1 christos for (irel = internal_relocs; irel < irelend; irel++) 405 1.1 christos { 406 1.1 christos unsigned long r_type = ELF64_R_TYPE (irel->r_info); 407 1.1 christos bfd_vma symaddr, reladdr, trampoff, toff, roff; 408 1.1 christos asection *tsec; 409 1.1 christos struct one_fixup *f; 410 1.1 christos bfd_size_type amt; 411 1.10 christos bool is_branch; 412 1.1 christos struct elf64_ia64_dyn_sym_info *dyn_i; 413 1.1 christos 414 1.1 christos switch (r_type) 415 1.1 christos { 416 1.1 christos case R_IA64_PCREL21B: 417 1.1 christos case R_IA64_PCREL21BI: 418 1.1 christos case R_IA64_PCREL21M: 419 1.1 christos case R_IA64_PCREL21F: 420 1.1 christos /* In pass 1, all br relaxations are done. We can skip it. */ 421 1.1 christos if (link_info->relax_pass == 1) 422 1.1 christos continue; 423 1.10 christos skip_relax_pass_0 = false; 424 1.10 christos is_branch = true; 425 1.1 christos break; 426 1.1 christos 427 1.1 christos case R_IA64_PCREL60B: 428 1.1 christos /* We can't optimize brl to br in pass 0 since br relaxations 429 1.1 christos will increase the code size. Defer it to pass 1. */ 430 1.1 christos if (link_info->relax_pass == 0) 431 1.1 christos { 432 1.10 christos skip_relax_pass_1 = false; 433 1.1 christos continue; 434 1.1 christos } 435 1.10 christos is_branch = true; 436 1.1 christos break; 437 1.1 christos 438 1.1 christos case R_IA64_GPREL22: 439 1.1 christos /* Update max_short_sec/min_short_sec. */ 440 1.1 christos 441 1.1 christos case R_IA64_LTOFF22X: 442 1.1 christos case R_IA64_LDXMOV: 443 1.1 christos /* We can't relax ldx/mov in pass 0 since br relaxations will 444 1.1 christos increase the code size. Defer it to pass 1. */ 445 1.1 christos if (link_info->relax_pass == 0) 446 1.1 christos { 447 1.10 christos skip_relax_pass_1 = false; 448 1.1 christos continue; 449 1.1 christos } 450 1.10 christos is_branch = false; 451 1.1 christos break; 452 1.1 christos 453 1.1 christos default: 454 1.1 christos continue; 455 1.1 christos } 456 1.1 christos 457 1.1 christos /* Get the value of the symbol referred to by the reloc. */ 458 1.1 christos if (ELF64_R_SYM (irel->r_info) < symtab_hdr->sh_info) 459 1.1 christos { 460 1.1 christos /* A local symbol. */ 461 1.1 christos Elf_Internal_Sym *isym; 462 1.1 christos 463 1.1 christos /* Read this BFD's local symbols. */ 464 1.1 christos if (isymbuf == NULL) 465 1.1 christos { 466 1.1 christos isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; 467 1.1 christos if (isymbuf == NULL) 468 1.1 christos isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, 469 1.1 christos symtab_hdr->sh_info, 0, 470 1.1 christos NULL, NULL, NULL); 471 1.1 christos if (isymbuf == 0) 472 1.1 christos goto error_return; 473 1.1 christos } 474 1.1 christos 475 1.1 christos isym = isymbuf + ELF64_R_SYM (irel->r_info); 476 1.1 christos if (isym->st_shndx == SHN_UNDEF) 477 1.1 christos continue; /* We can't do anything with undefined symbols. */ 478 1.1 christos else if (isym->st_shndx == SHN_ABS) 479 1.1 christos tsec = bfd_abs_section_ptr; 480 1.1 christos else if (isym->st_shndx == SHN_COMMON) 481 1.1 christos tsec = bfd_com_section_ptr; 482 1.1 christos else if (isym->st_shndx == SHN_IA_64_ANSI_COMMON) 483 1.1 christos tsec = bfd_com_section_ptr; 484 1.1 christos else 485 1.1 christos tsec = bfd_section_from_elf_index (abfd, isym->st_shndx); 486 1.1 christos 487 1.1 christos toff = isym->st_value; 488 1.10 christos dyn_i = get_dyn_sym_info (ia64_info, NULL, abfd, irel, false); 489 1.1 christos } 490 1.1 christos else 491 1.1 christos { 492 1.1 christos unsigned long indx; 493 1.1 christos struct elf_link_hash_entry *h; 494 1.1 christos 495 1.1 christos indx = ELF64_R_SYM (irel->r_info) - symtab_hdr->sh_info; 496 1.1 christos h = elf_sym_hashes (abfd)[indx]; 497 1.1 christos BFD_ASSERT (h != NULL); 498 1.1 christos 499 1.1 christos while (h->root.type == bfd_link_hash_indirect 500 1.1 christos || h->root.type == bfd_link_hash_warning) 501 1.1 christos h = (struct elf_link_hash_entry *) h->root.u.i.link; 502 1.1 christos 503 1.10 christos dyn_i = get_dyn_sym_info (ia64_info, h, abfd, irel, false); 504 1.1 christos 505 1.1 christos /* For branches to dynamic symbols, we're interested instead 506 1.1 christos in a branch to the PLT entry. */ 507 1.1 christos if (is_branch && dyn_i && dyn_i->want_plt2) 508 1.1 christos { 509 1.1 christos /* Internal branches shouldn't be sent to the PLT. 510 1.1 christos Leave this for now and we'll give an error later. */ 511 1.1 christos if (r_type != R_IA64_PCREL21B) 512 1.1 christos continue; 513 1.1 christos 514 1.1 christos tsec = ia64_info->root.splt; 515 1.1 christos toff = dyn_i->plt2_offset; 516 1.1 christos BFD_ASSERT (irel->r_addend == 0); 517 1.1 christos } 518 1.1 christos 519 1.1 christos /* Can't do anything else with dynamic symbols. */ 520 1.1 christos else if (elf64_ia64_dynamic_symbol_p (h)) 521 1.1 christos continue; 522 1.1 christos 523 1.1 christos else 524 1.1 christos { 525 1.1 christos /* We can't do anything with undefined symbols. */ 526 1.1 christos if (h->root.type == bfd_link_hash_undefined 527 1.1 christos || h->root.type == bfd_link_hash_undefweak) 528 1.1 christos continue; 529 1.1 christos 530 1.1 christos tsec = h->root.u.def.section; 531 1.1 christos toff = h->root.u.def.value; 532 1.1 christos } 533 1.1 christos } 534 1.1 christos 535 1.1 christos toff += irel->r_addend; 536 1.1 christos 537 1.1 christos symaddr = tsec->output_section->vma + tsec->output_offset + toff; 538 1.1 christos 539 1.1 christos roff = irel->r_offset; 540 1.1 christos 541 1.1 christos if (is_branch) 542 1.1 christos { 543 1.1 christos bfd_signed_vma offset; 544 1.1 christos 545 1.1 christos reladdr = (sec->output_section->vma 546 1.1 christos + sec->output_offset 547 1.1 christos + roff) & (bfd_vma) -4; 548 1.1 christos 549 1.1 christos /* The .plt section is aligned at 32byte and the .text section 550 1.1 christos is aligned at 64byte. The .text section is right after the 551 1.1 christos .plt section. After the first relaxation pass, linker may 552 1.1 christos increase the gap between the .plt and .text sections up 553 1.1 christos to 32byte. We assume linker will always insert 32byte 554 1.1 christos between the .plt and .text sections after the first 555 1.1 christos relaxation pass. */ 556 1.1 christos if (tsec == ia64_info->root.splt) 557 1.1 christos offset = -0x1000000 + 32; 558 1.1 christos else 559 1.1 christos offset = -0x1000000; 560 1.1 christos 561 1.1 christos /* If the branch is in range, no need to do anything. */ 562 1.1 christos if ((bfd_signed_vma) (symaddr - reladdr) >= offset 563 1.1 christos && (bfd_signed_vma) (symaddr - reladdr) <= 0x0FFFFF0) 564 1.1 christos { 565 1.1 christos /* If the 60-bit branch is in 21-bit range, optimize it. */ 566 1.1 christos if (r_type == R_IA64_PCREL60B) 567 1.1 christos { 568 1.1 christos ia64_elf_relax_brl (contents, roff); 569 1.1 christos 570 1.1 christos irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info), 571 1.8 christos R_IA64_PCREL21B); 572 1.1 christos 573 1.1 christos /* If the original relocation offset points to slot 574 1.1 christos 1, change it to slot 2. */ 575 1.1 christos if ((irel->r_offset & 3) == 1) 576 1.1 christos irel->r_offset += 1; 577 1.1 christos } 578 1.1 christos 579 1.1 christos continue; 580 1.1 christos } 581 1.1 christos else if (r_type == R_IA64_PCREL60B) 582 1.1 christos continue; 583 1.1 christos else if (ia64_elf_relax_br (contents, roff)) 584 1.1 christos { 585 1.1 christos irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info), 586 1.8 christos R_IA64_PCREL60B); 587 1.1 christos 588 1.1 christos /* Make the relocation offset point to slot 1. */ 589 1.1 christos irel->r_offset = (irel->r_offset & ~((bfd_vma) 0x3)) + 1; 590 1.1 christos continue; 591 1.1 christos } 592 1.1 christos 593 1.1 christos /* We can't put a trampoline in a .init/.fini section. Issue 594 1.1 christos an error. */ 595 1.1 christos if (strcmp (sec->output_section->name, ".init") == 0 596 1.1 christos || strcmp (sec->output_section->name, ".fini") == 0) 597 1.1 christos { 598 1.7 christos _bfd_error_handler 599 1.7 christos /* xgettext:c-format */ 600 1.8 christos (_("%pB: can't relax br at %#" PRIx64 " in section `%pA';" 601 1.8 christos " please use brl or indirect branch"), 602 1.8 christos sec->owner, (uint64_t) roff, sec); 603 1.1 christos bfd_set_error (bfd_error_bad_value); 604 1.1 christos goto error_return; 605 1.1 christos } 606 1.1 christos 607 1.1 christos /* If the branch and target are in the same section, you've 608 1.1 christos got one honking big section and we can't help you unless 609 1.1 christos you are branching backwards. You'll get an error message 610 1.1 christos later. */ 611 1.1 christos if (tsec == sec && toff > roff) 612 1.1 christos continue; 613 1.1 christos 614 1.1 christos /* Look for an existing fixup to this address. */ 615 1.1 christos for (f = fixups; f ; f = f->next) 616 1.1 christos if (f->tsec == tsec && f->toff == toff) 617 1.1 christos break; 618 1.1 christos 619 1.1 christos if (f == NULL) 620 1.1 christos { 621 1.1 christos /* Two alternatives: If it's a branch to a PLT entry, we can 622 1.1 christos make a copy of the FULL_PLT entry. Otherwise, we'll have 623 1.1 christos to use a `brl' insn to get where we're going. */ 624 1.1 christos 625 1.1 christos size_t size; 626 1.1 christos 627 1.1 christos if (tsec == ia64_info->root.splt) 628 1.1 christos size = sizeof (plt_full_entry); 629 1.1 christos else 630 1.1 christos size = sizeof (oor_brl); 631 1.1 christos 632 1.1 christos /* Resize the current section to make room for the new branch. */ 633 1.1 christos trampoff = (sec->size + 15) & (bfd_vma) -16; 634 1.1 christos 635 1.1 christos /* If trampoline is out of range, there is nothing we 636 1.1 christos can do. */ 637 1.1 christos offset = trampoff - (roff & (bfd_vma) -4); 638 1.1 christos if (offset < -0x1000000 || offset > 0x0FFFFF0) 639 1.1 christos continue; 640 1.1 christos 641 1.1 christos amt = trampoff + size; 642 1.1 christos contents = (bfd_byte *) bfd_realloc (contents, amt); 643 1.1 christos if (contents == NULL) 644 1.1 christos goto error_return; 645 1.1 christos sec->size = amt; 646 1.1 christos 647 1.1 christos if (tsec == ia64_info->root.splt) 648 1.1 christos { 649 1.1 christos memcpy (contents + trampoff, plt_full_entry, size); 650 1.1 christos 651 1.1 christos /* Hijack the old relocation for use as the PLTOFF reloc. */ 652 1.1 christos irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info), 653 1.1 christos R_IA64_PLTOFF22); 654 1.1 christos irel->r_offset = trampoff; 655 1.1 christos } 656 1.1 christos else 657 1.1 christos { 658 1.8 christos memcpy (contents + trampoff, oor_brl, size); 659 1.8 christos irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info), 660 1.8 christos R_IA64_PCREL60B); 661 1.8 christos irel->r_offset = trampoff + 2; 662 1.1 christos } 663 1.1 christos 664 1.1 christos /* Record the fixup so we don't do it again this section. */ 665 1.1 christos f = (struct one_fixup *) 666 1.1 christos bfd_malloc ((bfd_size_type) sizeof (*f)); 667 1.1 christos f->next = fixups; 668 1.1 christos f->tsec = tsec; 669 1.1 christos f->toff = toff; 670 1.1 christos f->trampoff = trampoff; 671 1.1 christos fixups = f; 672 1.1 christos } 673 1.1 christos else 674 1.1 christos { 675 1.1 christos /* If trampoline is out of range, there is nothing we 676 1.1 christos can do. */ 677 1.1 christos offset = f->trampoff - (roff & (bfd_vma) -4); 678 1.1 christos if (offset < -0x1000000 || offset > 0x0FFFFF0) 679 1.1 christos continue; 680 1.1 christos 681 1.1 christos /* Nop out the reloc, since we're finalizing things here. */ 682 1.1 christos irel->r_info = ELF64_R_INFO (0, R_IA64_NONE); 683 1.1 christos } 684 1.1 christos 685 1.1 christos /* Fix up the existing branch to hit the trampoline. */ 686 1.1 christos if (ia64_elf_install_value (contents + roff, offset, r_type) 687 1.1 christos != bfd_reloc_ok) 688 1.1 christos goto error_return; 689 1.1 christos 690 1.10 christos changed_contents = true; 691 1.10 christos changed_relocs = true; 692 1.1 christos } 693 1.1 christos else 694 1.1 christos { 695 1.1 christos /* Fetch the gp. */ 696 1.1 christos if (gp == 0) 697 1.1 christos { 698 1.1 christos bfd *obfd = sec->output_section->owner; 699 1.1 christos gp = _bfd_get_gp_value (obfd); 700 1.1 christos if (gp == 0) 701 1.1 christos { 702 1.10 christos if (!elf64_ia64_choose_gp (obfd, link_info, false)) 703 1.1 christos goto error_return; 704 1.1 christos gp = _bfd_get_gp_value (obfd); 705 1.1 christos } 706 1.1 christos } 707 1.1 christos 708 1.1 christos /* If the data is out of range, do nothing. */ 709 1.1 christos if ((bfd_signed_vma) (symaddr - gp) >= 0x200000 710 1.1 christos ||(bfd_signed_vma) (symaddr - gp) < -0x200000) 711 1.1 christos continue; 712 1.1 christos 713 1.1 christos if (r_type == R_IA64_GPREL22) 714 1.1 christos elf64_ia64_update_short_info (tsec->output_section, 715 1.1 christos tsec->output_offset + toff, 716 1.1 christos ia64_info); 717 1.1 christos else if (r_type == R_IA64_LTOFF22X) 718 1.1 christos { 719 1.8 christos /* Can't deal yet correctly with ABS symbols. */ 720 1.8 christos if (bfd_is_abs_section (tsec)) 721 1.8 christos continue; 722 1.1 christos 723 1.1 christos irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info), 724 1.1 christos R_IA64_GPREL22); 725 1.10 christos changed_relocs = true; 726 1.1 christos 727 1.1 christos elf64_ia64_update_short_info (tsec->output_section, 728 1.1 christos tsec->output_offset + toff, 729 1.1 christos ia64_info); 730 1.1 christos } 731 1.1 christos else 732 1.1 christos { 733 1.1 christos ia64_elf_relax_ldxmov (contents, roff); 734 1.1 christos irel->r_info = ELF64_R_INFO (0, R_IA64_NONE); 735 1.10 christos changed_contents = true; 736 1.10 christos changed_relocs = true; 737 1.1 christos } 738 1.1 christos } 739 1.1 christos } 740 1.1 christos 741 1.1 christos /* ??? If we created fixups, this may push the code segment large 742 1.1 christos enough that the data segment moves, which will change the GP. 743 1.1 christos Reset the GP so that we re-calculate next round. We need to 744 1.1 christos do this at the _beginning_ of the next round; now will not do. */ 745 1.1 christos 746 1.1 christos /* Clean up and go home. */ 747 1.1 christos while (fixups) 748 1.1 christos { 749 1.1 christos struct one_fixup *f = fixups; 750 1.1 christos fixups = fixups->next; 751 1.1 christos free (f); 752 1.1 christos } 753 1.1 christos 754 1.1 christos if (isymbuf != NULL 755 1.1 christos && symtab_hdr->contents != (unsigned char *) isymbuf) 756 1.1 christos { 757 1.1 christos if (! link_info->keep_memory) 758 1.1 christos free (isymbuf); 759 1.1 christos else 760 1.1 christos { 761 1.1 christos /* Cache the symbols for elf_link_input_bfd. */ 762 1.1 christos symtab_hdr->contents = (unsigned char *) isymbuf; 763 1.1 christos } 764 1.1 christos } 765 1.1 christos 766 1.1 christos if (contents != NULL 767 1.1 christos && elf_section_data (sec)->this_hdr.contents != contents) 768 1.1 christos { 769 1.1 christos if (!changed_contents && !link_info->keep_memory) 770 1.1 christos free (contents); 771 1.1 christos else 772 1.1 christos { 773 1.1 christos /* Cache the section contents for elf_link_input_bfd. */ 774 1.1 christos elf_section_data (sec)->this_hdr.contents = contents; 775 1.1 christos } 776 1.1 christos } 777 1.1 christos 778 1.1 christos if (elf_section_data (sec)->relocs != internal_relocs) 779 1.1 christos { 780 1.1 christos if (!changed_relocs) 781 1.1 christos free (internal_relocs); 782 1.1 christos else 783 1.1 christos elf_section_data (sec)->relocs = internal_relocs; 784 1.1 christos } 785 1.1 christos 786 1.1 christos if (link_info->relax_pass == 0) 787 1.1 christos { 788 1.1 christos /* Pass 0 is only needed to relax br. */ 789 1.1 christos sec->skip_relax_pass_0 = skip_relax_pass_0; 790 1.1 christos sec->skip_relax_pass_1 = skip_relax_pass_1; 791 1.1 christos } 792 1.1 christos 793 1.1 christos *again = changed_contents || changed_relocs; 794 1.10 christos return true; 795 1.1 christos 796 1.1 christos error_return: 797 1.9 christos if ((unsigned char *) isymbuf != symtab_hdr->contents) 798 1.1 christos free (isymbuf); 799 1.9 christos if (elf_section_data (sec)->this_hdr.contents != contents) 800 1.1 christos free (contents); 801 1.9 christos if (elf_section_data (sec)->relocs != internal_relocs) 802 1.1 christos free (internal_relocs); 803 1.10 christos return false; 804 1.1 christos } 805 1.1 christos #undef skip_relax_pass_0 806 1.1 christos #undef skip_relax_pass_1 807 1.1 christos 808 1.1 christos /* Return TRUE if NAME is an unwind table section name. */ 809 1.1 christos 810 1.10 christos static inline bool 811 1.1 christos is_unwind_section_name (bfd *abfd ATTRIBUTE_UNUSED, const char *name) 812 1.1 christos { 813 1.10 christos return ((startswith (name, ELF_STRING_ia64_unwind) 814 1.10 christos && ! startswith (name, ELF_STRING_ia64_unwind_info)) 815 1.10 christos || startswith (name, ELF_STRING_ia64_unwind_once)); 816 1.1 christos } 817 1.1 christos 818 1.1 christos 819 1.1 christos /* Convert IA-64 specific section flags to bfd internal section flags. */ 820 1.1 christos 821 1.1 christos /* ??? There is no bfd internal flag equivalent to the SHF_IA_64_NORECOV 822 1.1 christos flag. */ 823 1.1 christos 824 1.10 christos static bool 825 1.9 christos elf64_ia64_section_flags (const Elf_Internal_Shdr *hdr) 826 1.1 christos { 827 1.1 christos if (hdr->sh_flags & SHF_IA_64_SHORT) 828 1.9 christos hdr->bfd_section->flags |= SEC_SMALL_DATA; 829 1.1 christos 830 1.10 christos return true; 831 1.1 christos } 832 1.1 christos 833 1.1 christos /* Set the correct type for an IA-64 ELF section. We do this by the 834 1.1 christos section name, which is a hack, but ought to work. */ 835 1.1 christos 836 1.10 christos static bool 837 1.1 christos elf64_ia64_fake_sections (bfd *abfd, Elf_Internal_Shdr *hdr, 838 1.1 christos asection *sec) 839 1.1 christos { 840 1.1 christos const char *name; 841 1.1 christos 842 1.9 christos name = bfd_section_name (sec); 843 1.1 christos 844 1.1 christos if (is_unwind_section_name (abfd, name)) 845 1.1 christos { 846 1.1 christos /* We don't have the sections numbered at this point, so sh_info 847 1.1 christos is set later, in elf64_ia64_final_write_processing. */ 848 1.1 christos hdr->sh_type = SHT_IA_64_UNWIND; 849 1.1 christos hdr->sh_flags |= SHF_LINK_ORDER; 850 1.1 christos } 851 1.1 christos else if (strcmp (name, ELF_STRING_ia64_archext) == 0) 852 1.1 christos hdr->sh_type = SHT_IA_64_EXT; 853 1.1 christos 854 1.1 christos if (sec->flags & SEC_SMALL_DATA) 855 1.1 christos hdr->sh_flags |= SHF_IA_64_SHORT; 856 1.1 christos 857 1.10 christos return true; 858 1.1 christos } 859 1.1 christos 860 1.1 christos /* Hook called by the linker routine which adds symbols from an object 861 1.1 christos file. We use it to put .comm items in .sbss, and not .bss. */ 862 1.1 christos 863 1.10 christos static bool 864 1.1 christos elf64_ia64_add_symbol_hook (bfd *abfd, 865 1.1 christos struct bfd_link_info *info, 866 1.1 christos Elf_Internal_Sym *sym, 867 1.1 christos const char **namep ATTRIBUTE_UNUSED, 868 1.1 christos flagword *flagsp ATTRIBUTE_UNUSED, 869 1.1 christos asection **secp, 870 1.1 christos bfd_vma *valp) 871 1.1 christos { 872 1.1 christos if (sym->st_shndx == SHN_COMMON 873 1.6 christos && !bfd_link_relocatable (info) 874 1.1 christos && sym->st_size <= elf_gp_size (abfd)) 875 1.1 christos { 876 1.1 christos /* Common symbols less than or equal to -G nn bytes are 877 1.1 christos automatically put into .sbss. */ 878 1.1 christos 879 1.1 christos asection *scomm = bfd_get_section_by_name (abfd, ".scommon"); 880 1.1 christos 881 1.1 christos if (scomm == NULL) 882 1.1 christos { 883 1.1 christos scomm = bfd_make_section_with_flags (abfd, ".scommon", 884 1.1 christos (SEC_ALLOC 885 1.1 christos | SEC_IS_COMMON 886 1.9 christos | SEC_SMALL_DATA 887 1.1 christos | SEC_LINKER_CREATED)); 888 1.1 christos if (scomm == NULL) 889 1.10 christos return false; 890 1.1 christos } 891 1.1 christos 892 1.1 christos *secp = scomm; 893 1.1 christos *valp = sym->st_size; 894 1.1 christos } 895 1.1 christos 896 1.10 christos return true; 897 1.1 christos } 898 1.1 christos 899 1.1 christos /* According to the Tahoe assembler spec, all labels starting with a 900 1.1 christos '.' are local. */ 901 1.1 christos 902 1.10 christos static bool 903 1.1 christos elf64_ia64_is_local_label_name (bfd *abfd ATTRIBUTE_UNUSED, 904 1.1 christos const char *name) 905 1.1 christos { 906 1.1 christos return name[0] == '.'; 907 1.1 christos } 908 1.1 christos 909 1.1 christos /* Should we do dynamic things to this symbol? */ 910 1.1 christos 911 1.10 christos static bool 912 1.1 christos elf64_ia64_dynamic_symbol_p (struct elf_link_hash_entry *h) 913 1.1 christos { 914 1.1 christos return h != NULL && h->def_dynamic; 915 1.1 christos } 916 1.1 christos 917 1.1 christos static struct bfd_hash_entry* 918 1.1 christos elf64_ia64_new_elf_hash_entry (struct bfd_hash_entry *entry, 919 1.1 christos struct bfd_hash_table *table, 920 1.1 christos const char *string) 921 1.1 christos { 922 1.1 christos struct elf64_ia64_link_hash_entry *ret; 923 1.1 christos ret = (struct elf64_ia64_link_hash_entry *) entry; 924 1.1 christos 925 1.1 christos /* Allocate the structure if it has not already been allocated by a 926 1.1 christos subclass. */ 927 1.1 christos if (!ret) 928 1.1 christos ret = bfd_hash_allocate (table, sizeof (*ret)); 929 1.1 christos 930 1.1 christos if (!ret) 931 1.1 christos return 0; 932 1.1 christos 933 1.1 christos /* Call the allocation method of the superclass. */ 934 1.1 christos ret = ((struct elf64_ia64_link_hash_entry *) 935 1.1 christos _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, 936 1.1 christos table, string)); 937 1.1 christos 938 1.1 christos ret->info = NULL; 939 1.1 christos ret->count = 0; 940 1.1 christos ret->sorted_count = 0; 941 1.1 christos ret->size = 0; 942 1.1 christos return (struct bfd_hash_entry *) ret; 943 1.1 christos } 944 1.1 christos 945 1.1 christos static void 946 1.1 christos elf64_ia64_hash_hide_symbol (struct bfd_link_info *info, 947 1.1 christos struct elf_link_hash_entry *xh, 948 1.10 christos bool force_local) 949 1.1 christos { 950 1.1 christos struct elf64_ia64_link_hash_entry *h; 951 1.1 christos struct elf64_ia64_dyn_sym_info *dyn_i; 952 1.1 christos unsigned int count; 953 1.1 christos 954 1.1 christos h = (struct elf64_ia64_link_hash_entry *)xh; 955 1.1 christos 956 1.1 christos _bfd_elf_link_hash_hide_symbol (info, &h->root, force_local); 957 1.1 christos 958 1.1 christos for (count = h->count, dyn_i = h->info; 959 1.1 christos count != 0; 960 1.1 christos count--, dyn_i++) 961 1.1 christos { 962 1.1 christos dyn_i->want_plt2 = 0; 963 1.1 christos dyn_i->want_plt = 0; 964 1.1 christos } 965 1.1 christos } 966 1.1 christos 967 1.1 christos /* Compute a hash of a local hash entry. */ 968 1.1 christos 969 1.1 christos static hashval_t 970 1.1 christos elf64_ia64_local_htab_hash (const void *ptr) 971 1.1 christos { 972 1.1 christos struct elf64_ia64_local_hash_entry *entry 973 1.1 christos = (struct elf64_ia64_local_hash_entry *) ptr; 974 1.1 christos 975 1.1 christos return ELF_LOCAL_SYMBOL_HASH (entry->id, entry->r_sym); 976 1.1 christos } 977 1.1 christos 978 1.1 christos /* Compare local hash entries. */ 979 1.1 christos 980 1.1 christos static int 981 1.1 christos elf64_ia64_local_htab_eq (const void *ptr1, const void *ptr2) 982 1.1 christos { 983 1.1 christos struct elf64_ia64_local_hash_entry *entry1 984 1.1 christos = (struct elf64_ia64_local_hash_entry *) ptr1; 985 1.1 christos struct elf64_ia64_local_hash_entry *entry2 986 1.1 christos = (struct elf64_ia64_local_hash_entry *) ptr2; 987 1.1 christos 988 1.1 christos return entry1->id == entry2->id && entry1->r_sym == entry2->r_sym; 989 1.1 christos } 990 1.1 christos 991 1.1 christos /* Free the global elf64_ia64_dyn_sym_info array. */ 992 1.1 christos 993 1.10 christos static bool 994 1.10 christos elf64_ia64_global_dyn_info_free (struct elf_link_hash_entry *xentry, 995 1.1 christos void * unused ATTRIBUTE_UNUSED) 996 1.1 christos { 997 1.1 christos struct elf64_ia64_link_hash_entry *entry 998 1.1 christos = (struct elf64_ia64_link_hash_entry *) xentry; 999 1.1 christos 1000 1.1 christos if (entry->root.root.type == bfd_link_hash_warning) 1001 1.1 christos entry = (struct elf64_ia64_link_hash_entry *) entry->root.root.u.i.link; 1002 1.1 christos 1003 1.9 christos free (entry->info); 1004 1.9 christos entry->info = NULL; 1005 1.9 christos entry->count = 0; 1006 1.9 christos entry->sorted_count = 0; 1007 1.9 christos entry->size = 0; 1008 1.1 christos 1009 1.10 christos return true; 1010 1.1 christos } 1011 1.1 christos 1012 1.1 christos /* Free the local elf64_ia64_dyn_sym_info array. */ 1013 1.1 christos 1014 1.10 christos static int 1015 1.1 christos elf64_ia64_local_dyn_info_free (void **slot, 1016 1.1 christos void * unused ATTRIBUTE_UNUSED) 1017 1.1 christos { 1018 1.1 christos struct elf64_ia64_local_hash_entry *entry 1019 1.1 christos = (struct elf64_ia64_local_hash_entry *) *slot; 1020 1.1 christos 1021 1.9 christos free (entry->info); 1022 1.9 christos entry->info = NULL; 1023 1.9 christos entry->count = 0; 1024 1.9 christos entry->sorted_count = 0; 1025 1.9 christos entry->size = 0; 1026 1.1 christos 1027 1.10 christos return true; 1028 1.1 christos } 1029 1.1 christos 1030 1.1 christos /* Destroy IA-64 linker hash table. */ 1031 1.1 christos 1032 1.1 christos static void 1033 1.3 christos elf64_ia64_link_hash_table_free (bfd *obfd) 1034 1.1 christos { 1035 1.1 christos struct elf64_ia64_link_hash_table *ia64_info 1036 1.3 christos = (struct elf64_ia64_link_hash_table *) obfd->link.hash; 1037 1.1 christos if (ia64_info->loc_hash_table) 1038 1.1 christos { 1039 1.1 christos htab_traverse (ia64_info->loc_hash_table, 1040 1.1 christos elf64_ia64_local_dyn_info_free, NULL); 1041 1.1 christos htab_delete (ia64_info->loc_hash_table); 1042 1.1 christos } 1043 1.1 christos if (ia64_info->loc_hash_memory) 1044 1.1 christos objalloc_free ((struct objalloc *) ia64_info->loc_hash_memory); 1045 1.1 christos elf_link_hash_traverse (&ia64_info->root, 1046 1.1 christos elf64_ia64_global_dyn_info_free, NULL); 1047 1.3 christos _bfd_elf_link_hash_table_free (obfd); 1048 1.3 christos } 1049 1.3 christos 1050 1.3 christos /* Create the derived linker hash table. The IA-64 ELF port uses this 1051 1.3 christos derived hash table to keep information specific to the IA-64 ElF 1052 1.3 christos linker (without using static variables). */ 1053 1.3 christos 1054 1.3 christos static struct bfd_link_hash_table * 1055 1.3 christos elf64_ia64_hash_table_create (bfd *abfd) 1056 1.3 christos { 1057 1.3 christos struct elf64_ia64_link_hash_table *ret; 1058 1.3 christos 1059 1.3 christos ret = bfd_zmalloc ((bfd_size_type) sizeof (*ret)); 1060 1.3 christos if (!ret) 1061 1.3 christos return NULL; 1062 1.3 christos 1063 1.3 christos if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, 1064 1.3 christos elf64_ia64_new_elf_hash_entry, 1065 1.12 christos sizeof (struct elf64_ia64_link_hash_entry))) 1066 1.3 christos { 1067 1.3 christos free (ret); 1068 1.3 christos return NULL; 1069 1.3 christos } 1070 1.3 christos 1071 1.3 christos ret->loc_hash_table = htab_try_create (1024, elf64_ia64_local_htab_hash, 1072 1.3 christos elf64_ia64_local_htab_eq, NULL); 1073 1.3 christos ret->loc_hash_memory = objalloc_create (); 1074 1.3 christos if (!ret->loc_hash_table || !ret->loc_hash_memory) 1075 1.3 christos { 1076 1.3 christos elf64_ia64_link_hash_table_free (abfd); 1077 1.3 christos return NULL; 1078 1.3 christos } 1079 1.3 christos ret->root.root.hash_table_free = elf64_ia64_link_hash_table_free; 1080 1.3 christos 1081 1.3 christos return &ret->root.root; 1082 1.1 christos } 1083 1.1 christos 1084 1.1 christos /* Traverse both local and global hash tables. */ 1085 1.1 christos 1086 1.1 christos struct elf64_ia64_dyn_sym_traverse_data 1087 1.1 christos { 1088 1.10 christos bool (*func) (struct elf64_ia64_dyn_sym_info *, void *); 1089 1.1 christos void * data; 1090 1.1 christos }; 1091 1.1 christos 1092 1.10 christos static bool 1093 1.10 christos elf64_ia64_global_dyn_sym_thunk (struct elf_link_hash_entry *xentry, 1094 1.1 christos void * xdata) 1095 1.1 christos { 1096 1.1 christos struct elf64_ia64_link_hash_entry *entry 1097 1.1 christos = (struct elf64_ia64_link_hash_entry *) xentry; 1098 1.1 christos struct elf64_ia64_dyn_sym_traverse_data *data 1099 1.1 christos = (struct elf64_ia64_dyn_sym_traverse_data *) xdata; 1100 1.1 christos struct elf64_ia64_dyn_sym_info *dyn_i; 1101 1.1 christos unsigned int count; 1102 1.1 christos 1103 1.1 christos if (entry->root.root.type == bfd_link_hash_warning) 1104 1.1 christos entry = (struct elf64_ia64_link_hash_entry *) entry->root.root.u.i.link; 1105 1.1 christos 1106 1.1 christos for (count = entry->count, dyn_i = entry->info; 1107 1.1 christos count != 0; 1108 1.1 christos count--, dyn_i++) 1109 1.1 christos if (! (*data->func) (dyn_i, data->data)) 1110 1.10 christos return false; 1111 1.10 christos return true; 1112 1.1 christos } 1113 1.1 christos 1114 1.10 christos static int 1115 1.1 christos elf64_ia64_local_dyn_sym_thunk (void **slot, void * xdata) 1116 1.1 christos { 1117 1.1 christos struct elf64_ia64_local_hash_entry *entry 1118 1.1 christos = (struct elf64_ia64_local_hash_entry *) *slot; 1119 1.1 christos struct elf64_ia64_dyn_sym_traverse_data *data 1120 1.1 christos = (struct elf64_ia64_dyn_sym_traverse_data *) xdata; 1121 1.1 christos struct elf64_ia64_dyn_sym_info *dyn_i; 1122 1.1 christos unsigned int count; 1123 1.1 christos 1124 1.1 christos for (count = entry->count, dyn_i = entry->info; 1125 1.1 christos count != 0; 1126 1.1 christos count--, dyn_i++) 1127 1.1 christos if (! (*data->func) (dyn_i, data->data)) 1128 1.10 christos return false; 1129 1.10 christos return true; 1130 1.1 christos } 1131 1.1 christos 1132 1.1 christos static void 1133 1.1 christos elf64_ia64_dyn_sym_traverse (struct elf64_ia64_link_hash_table *ia64_info, 1134 1.10 christos bool (*func) (struct elf64_ia64_dyn_sym_info *, void *), 1135 1.1 christos void * data) 1136 1.1 christos { 1137 1.1 christos struct elf64_ia64_dyn_sym_traverse_data xdata; 1138 1.1 christos 1139 1.1 christos xdata.func = func; 1140 1.1 christos xdata.data = data; 1141 1.1 christos 1142 1.1 christos elf_link_hash_traverse (&ia64_info->root, 1143 1.1 christos elf64_ia64_global_dyn_sym_thunk, &xdata); 1144 1.1 christos htab_traverse (ia64_info->loc_hash_table, 1145 1.1 christos elf64_ia64_local_dyn_sym_thunk, &xdata); 1146 1.1 christos } 1147 1.1 christos 1148 1.1 christos #define NOTE_NAME "IPF/VMS" 1149 1.1 christos 1150 1.10 christos static bool 1151 1.1 christos create_ia64_vms_notes (bfd *abfd, struct bfd_link_info *info, 1152 1.8 christos unsigned int time_hi, unsigned int time_lo) 1153 1.1 christos { 1154 1.1 christos #define NBR_NOTES 7 1155 1.1 christos Elf_Internal_Note notes[NBR_NOTES]; 1156 1.1 christos char *module_name; 1157 1.1 christos int module_name_len; 1158 1.1 christos unsigned char cur_time[8]; 1159 1.1 christos Elf64_External_VMS_ORIG_DYN_Note *orig_dyn; 1160 1.1 christos unsigned int orig_dyn_size; 1161 1.1 christos unsigned int note_size; 1162 1.1 christos int i; 1163 1.1 christos unsigned char *noteptr; 1164 1.1 christos unsigned char *note_contents; 1165 1.1 christos struct elf64_ia64_link_hash_table *ia64_info; 1166 1.1 christos 1167 1.1 christos ia64_info = elf64_ia64_hash_table (info); 1168 1.1 christos 1169 1.10 christos module_name = vms_get_module_name (bfd_get_filename (abfd), true); 1170 1.1 christos module_name_len = strlen (module_name) + 1; 1171 1.1 christos 1172 1.1 christos bfd_putl32 (time_lo, cur_time + 0); 1173 1.1 christos bfd_putl32 (time_hi, cur_time + 4); 1174 1.1 christos 1175 1.1 christos /* Note 0: IMGNAM. */ 1176 1.1 christos notes[0].type = NT_VMS_IMGNAM; 1177 1.1 christos notes[0].descdata = module_name; 1178 1.1 christos notes[0].descsz = module_name_len; 1179 1.1 christos 1180 1.1 christos /* Note 1: GSTNAM. */ 1181 1.1 christos notes[1].type = NT_VMS_GSTNAM; 1182 1.1 christos notes[1].descdata = module_name; 1183 1.1 christos notes[1].descsz = module_name_len; 1184 1.1 christos 1185 1.1 christos /* Note 2: IMGID. */ 1186 1.1 christos #define IMG_ID "V1.0" 1187 1.1 christos notes[2].type = NT_VMS_IMGID; 1188 1.1 christos notes[2].descdata = IMG_ID; 1189 1.1 christos notes[2].descsz = sizeof (IMG_ID); 1190 1.1 christos 1191 1.1 christos /* Note 3: Linktime. */ 1192 1.1 christos notes[3].type = NT_VMS_LINKTIME; 1193 1.1 christos notes[3].descdata = (char *)cur_time; 1194 1.1 christos notes[3].descsz = sizeof (cur_time); 1195 1.1 christos 1196 1.1 christos /* Note 4: Linker id. */ 1197 1.1 christos notes[4].type = NT_VMS_LINKID; 1198 1.1 christos notes[4].descdata = "GNU ld " BFD_VERSION_STRING; 1199 1.1 christos notes[4].descsz = strlen (notes[4].descdata) + 1; 1200 1.1 christos 1201 1.1 christos /* Note 5: Original dyn. */ 1202 1.1 christos orig_dyn_size = (sizeof (*orig_dyn) + sizeof (IMG_ID) - 1 + 7) & ~7; 1203 1.1 christos orig_dyn = bfd_zalloc (abfd, orig_dyn_size); 1204 1.1 christos if (orig_dyn == NULL) 1205 1.10 christos return false; 1206 1.1 christos bfd_putl32 (1, orig_dyn->major_id); 1207 1.1 christos bfd_putl32 (3, orig_dyn->minor_id); 1208 1.1 christos memcpy (orig_dyn->manipulation_date, cur_time, sizeof (cur_time)); 1209 1.1 christos bfd_putl64 (VMS_LF_IMGSTA | VMS_LF_MAIN, orig_dyn->link_flags); 1210 1.1 christos bfd_putl32 (EF_IA_64_ABI64, orig_dyn->elf_flags); 1211 1.1 christos memcpy (orig_dyn->imgid, IMG_ID, sizeof (IMG_ID)); 1212 1.1 christos notes[5].type = NT_VMS_ORIG_DYN; 1213 1.1 christos notes[5].descdata = (char *)orig_dyn; 1214 1.1 christos notes[5].descsz = orig_dyn_size; 1215 1.1 christos 1216 1.1 christos /* Note 3: Patchtime. */ 1217 1.1 christos notes[6].type = NT_VMS_PATCHTIME; 1218 1.1 christos notes[6].descdata = (char *)cur_time; 1219 1.1 christos notes[6].descsz = sizeof (cur_time); 1220 1.1 christos 1221 1.1 christos /* Compute notes size. */ 1222 1.1 christos note_size = 0; 1223 1.1 christos for (i = 0; i < NBR_NOTES; i++) 1224 1.1 christos note_size += sizeof (Elf64_External_VMS_Note) - 1 1225 1.1 christos + ((sizeof (NOTE_NAME) - 1 + 7) & ~7) 1226 1.1 christos + ((notes[i].descsz + 7) & ~7); 1227 1.1 christos 1228 1.1 christos /* Malloc a temporary buffer large enough for most notes */ 1229 1.1 christos note_contents = (unsigned char *) bfd_zalloc (abfd, note_size); 1230 1.1 christos if (note_contents == NULL) 1231 1.10 christos return false; 1232 1.1 christos noteptr = note_contents; 1233 1.1 christos 1234 1.1 christos /* Fill notes. */ 1235 1.1 christos for (i = 0; i < NBR_NOTES; i++) 1236 1.1 christos { 1237 1.1 christos Elf64_External_VMS_Note *enote = (Elf64_External_VMS_Note *) noteptr; 1238 1.1 christos 1239 1.1 christos bfd_putl64 (sizeof (NOTE_NAME) - 1, enote->namesz); 1240 1.1 christos bfd_putl64 (notes[i].descsz, enote->descsz); 1241 1.1 christos bfd_putl64 (notes[i].type, enote->type); 1242 1.1 christos 1243 1.1 christos noteptr = (unsigned char *)enote->name; 1244 1.1 christos memcpy (noteptr, NOTE_NAME, sizeof (NOTE_NAME) - 1); 1245 1.1 christos noteptr += (sizeof (NOTE_NAME) - 1 + 7) & ~7; 1246 1.1 christos memcpy (noteptr, notes[i].descdata, notes[i].descsz); 1247 1.1 christos noteptr += (notes[i].descsz + 7) & ~7; 1248 1.1 christos } 1249 1.1 christos 1250 1.1 christos ia64_info->note_sec->contents = note_contents; 1251 1.1 christos ia64_info->note_sec->size = note_size; 1252 1.1 christos 1253 1.1 christos free (module_name); 1254 1.1 christos 1255 1.10 christos return true; 1256 1.1 christos } 1257 1.1 christos 1258 1.10 christos static bool 1259 1.1 christos elf64_ia64_create_dynamic_sections (bfd *abfd, 1260 1.1 christos struct bfd_link_info *info) 1261 1.1 christos { 1262 1.1 christos struct elf64_ia64_link_hash_table *ia64_info; 1263 1.1 christos asection *s; 1264 1.1 christos flagword flags; 1265 1.1 christos const struct elf_backend_data *bed; 1266 1.1 christos 1267 1.1 christos ia64_info = elf64_ia64_hash_table (info); 1268 1.1 christos if (ia64_info == NULL) 1269 1.10 christos return false; 1270 1.1 christos 1271 1.1 christos if (elf_hash_table (info)->dynamic_sections_created) 1272 1.10 christos return true; 1273 1.1 christos 1274 1.1 christos abfd = elf_hash_table (info)->dynobj; 1275 1.1 christos bed = get_elf_backend_data (abfd); 1276 1.1 christos 1277 1.1 christos flags = bed->dynamic_sec_flags; 1278 1.1 christos 1279 1.1 christos s = bfd_make_section_anyway_with_flags (abfd, ".dynamic", 1280 1.1 christos flags | SEC_READONLY); 1281 1.1 christos if (s == NULL 1282 1.9 christos || !bfd_set_section_alignment (s, bed->s->log_file_align)) 1283 1.10 christos return false; 1284 1.1 christos 1285 1.1 christos s = bfd_make_section_anyway_with_flags (abfd, ".plt", flags | SEC_READONLY); 1286 1.1 christos if (s == NULL 1287 1.9 christos || !bfd_set_section_alignment (s, bed->plt_alignment)) 1288 1.10 christos return false; 1289 1.1 christos ia64_info->root.splt = s; 1290 1.1 christos 1291 1.1 christos if (!get_got (abfd, ia64_info)) 1292 1.10 christos return false; 1293 1.1 christos 1294 1.1 christos if (!get_pltoff (abfd, ia64_info)) 1295 1.10 christos return false; 1296 1.1 christos 1297 1.1 christos s = bfd_make_section_anyway_with_flags (abfd, ".vmsdynstr", 1298 1.1 christos (SEC_ALLOC 1299 1.1 christos | SEC_HAS_CONTENTS 1300 1.1 christos | SEC_IN_MEMORY 1301 1.1 christos | SEC_LINKER_CREATED)); 1302 1.1 christos if (s == NULL 1303 1.9 christos || !bfd_set_section_alignment (s, 0)) 1304 1.10 christos return false; 1305 1.1 christos 1306 1.1 christos /* Create a fixup section. */ 1307 1.1 christos s = bfd_make_section_anyway_with_flags (abfd, ".fixups", 1308 1.1 christos (SEC_ALLOC 1309 1.1 christos | SEC_HAS_CONTENTS 1310 1.1 christos | SEC_IN_MEMORY 1311 1.1 christos | SEC_LINKER_CREATED)); 1312 1.1 christos if (s == NULL 1313 1.9 christos || !bfd_set_section_alignment (s, 3)) 1314 1.10 christos return false; 1315 1.1 christos ia64_info->fixups_sec = s; 1316 1.1 christos 1317 1.1 christos /* Create the transfer fixup section. */ 1318 1.1 christos s = bfd_make_section_anyway_with_flags (abfd, ".transfer", 1319 1.1 christos (SEC_ALLOC 1320 1.1 christos | SEC_HAS_CONTENTS 1321 1.1 christos | SEC_IN_MEMORY 1322 1.1 christos | SEC_LINKER_CREATED)); 1323 1.1 christos if (s == NULL 1324 1.9 christos || !bfd_set_section_alignment (s, 3)) 1325 1.10 christos return false; 1326 1.1 christos s->size = sizeof (struct elf64_vms_transfer); 1327 1.1 christos ia64_info->transfer_sec = s; 1328 1.1 christos 1329 1.1 christos /* Create note section. */ 1330 1.1 christos s = bfd_make_section_anyway_with_flags (abfd, ".vms.note", 1331 1.8 christos (SEC_LINKER_CREATED 1332 1.8 christos | SEC_HAS_CONTENTS 1333 1.8 christos | SEC_IN_MEMORY 1334 1.8 christos | SEC_READONLY)); 1335 1.1 christos if (s == NULL 1336 1.9 christos || !bfd_set_section_alignment (s, 3)) 1337 1.10 christos return false; 1338 1.1 christos ia64_info->note_sec = s; 1339 1.1 christos 1340 1.10 christos elf_hash_table (info)->dynamic_sections_created = true; 1341 1.10 christos return true; 1342 1.1 christos } 1343 1.1 christos 1344 1.1 christos /* Find and/or create a hash entry for local symbol. */ 1345 1.1 christos static struct elf64_ia64_local_hash_entry * 1346 1.1 christos get_local_sym_hash (struct elf64_ia64_link_hash_table *ia64_info, 1347 1.1 christos bfd *abfd, const Elf_Internal_Rela *rel, 1348 1.10 christos bool create) 1349 1.1 christos { 1350 1.1 christos struct elf64_ia64_local_hash_entry e, *ret; 1351 1.1 christos asection *sec = abfd->sections; 1352 1.1 christos hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id, 1353 1.1 christos ELF64_R_SYM (rel->r_info)); 1354 1.1 christos void **slot; 1355 1.1 christos 1356 1.1 christos e.id = sec->id; 1357 1.1 christos e.r_sym = ELF64_R_SYM (rel->r_info); 1358 1.1 christos slot = htab_find_slot_with_hash (ia64_info->loc_hash_table, &e, h, 1359 1.1 christos create ? INSERT : NO_INSERT); 1360 1.1 christos 1361 1.1 christos if (!slot) 1362 1.1 christos return NULL; 1363 1.1 christos 1364 1.1 christos if (*slot) 1365 1.1 christos return (struct elf64_ia64_local_hash_entry *) *slot; 1366 1.1 christos 1367 1.1 christos ret = (struct elf64_ia64_local_hash_entry *) 1368 1.1 christos objalloc_alloc ((struct objalloc *) ia64_info->loc_hash_memory, 1369 1.1 christos sizeof (struct elf64_ia64_local_hash_entry)); 1370 1.1 christos if (ret) 1371 1.1 christos { 1372 1.1 christos memset (ret, 0, sizeof (*ret)); 1373 1.1 christos ret->id = sec->id; 1374 1.1 christos ret->r_sym = ELF64_R_SYM (rel->r_info); 1375 1.1 christos *slot = ret; 1376 1.1 christos } 1377 1.1 christos return ret; 1378 1.1 christos } 1379 1.1 christos 1380 1.1 christos /* Used to sort elf64_ia64_dyn_sym_info array. */ 1381 1.1 christos 1382 1.1 christos static int 1383 1.1 christos addend_compare (const void *xp, const void *yp) 1384 1.1 christos { 1385 1.1 christos const struct elf64_ia64_dyn_sym_info *x 1386 1.1 christos = (const struct elf64_ia64_dyn_sym_info *) xp; 1387 1.1 christos const struct elf64_ia64_dyn_sym_info *y 1388 1.1 christos = (const struct elf64_ia64_dyn_sym_info *) yp; 1389 1.1 christos 1390 1.1 christos return x->addend < y->addend ? -1 : x->addend > y->addend ? 1 : 0; 1391 1.1 christos } 1392 1.1 christos 1393 1.1 christos /* Sort elf64_ia64_dyn_sym_info array and remove duplicates. */ 1394 1.1 christos 1395 1.1 christos static unsigned int 1396 1.1 christos sort_dyn_sym_info (struct elf64_ia64_dyn_sym_info *info, 1397 1.1 christos unsigned int count) 1398 1.1 christos { 1399 1.1 christos bfd_vma curr, prev, got_offset; 1400 1.1 christos unsigned int i, kept, dupes, diff, dest, src, len; 1401 1.1 christos 1402 1.1 christos qsort (info, count, sizeof (*info), addend_compare); 1403 1.1 christos 1404 1.1 christos /* Find the first duplicate. */ 1405 1.1 christos prev = info [0].addend; 1406 1.1 christos got_offset = info [0].got_offset; 1407 1.1 christos for (i = 1; i < count; i++) 1408 1.1 christos { 1409 1.1 christos curr = info [i].addend; 1410 1.1 christos if (curr == prev) 1411 1.1 christos { 1412 1.1 christos /* For duplicates, make sure that GOT_OFFSET is valid. */ 1413 1.1 christos if (got_offset == (bfd_vma) -1) 1414 1.1 christos got_offset = info [i].got_offset; 1415 1.1 christos break; 1416 1.1 christos } 1417 1.1 christos got_offset = info [i].got_offset; 1418 1.1 christos prev = curr; 1419 1.1 christos } 1420 1.1 christos 1421 1.1 christos /* We may move a block of elements to here. */ 1422 1.1 christos dest = i++; 1423 1.1 christos 1424 1.1 christos /* Remove duplicates. */ 1425 1.1 christos if (i < count) 1426 1.1 christos { 1427 1.1 christos while (i < count) 1428 1.1 christos { 1429 1.1 christos /* For duplicates, make sure that the kept one has a valid 1430 1.1 christos got_offset. */ 1431 1.1 christos kept = dest - 1; 1432 1.1 christos if (got_offset != (bfd_vma) -1) 1433 1.1 christos info [kept].got_offset = got_offset; 1434 1.1 christos 1435 1.1 christos curr = info [i].addend; 1436 1.1 christos got_offset = info [i].got_offset; 1437 1.1 christos 1438 1.1 christos /* Move a block of elements whose first one is different from 1439 1.1 christos the previous. */ 1440 1.1 christos if (curr == prev) 1441 1.1 christos { 1442 1.1 christos for (src = i + 1; src < count; src++) 1443 1.1 christos { 1444 1.1 christos if (info [src].addend != curr) 1445 1.1 christos break; 1446 1.1 christos /* For duplicates, make sure that GOT_OFFSET is 1447 1.1 christos valid. */ 1448 1.1 christos if (got_offset == (bfd_vma) -1) 1449 1.1 christos got_offset = info [src].got_offset; 1450 1.1 christos } 1451 1.1 christos 1452 1.1 christos /* Make sure that the kept one has a valid got_offset. */ 1453 1.1 christos if (got_offset != (bfd_vma) -1) 1454 1.1 christos info [kept].got_offset = got_offset; 1455 1.1 christos } 1456 1.1 christos else 1457 1.1 christos src = i; 1458 1.1 christos 1459 1.1 christos if (src >= count) 1460 1.1 christos break; 1461 1.1 christos 1462 1.1 christos /* Find the next duplicate. SRC will be kept. */ 1463 1.1 christos prev = info [src].addend; 1464 1.1 christos got_offset = info [src].got_offset; 1465 1.1 christos for (dupes = src + 1; dupes < count; dupes ++) 1466 1.1 christos { 1467 1.1 christos curr = info [dupes].addend; 1468 1.1 christos if (curr == prev) 1469 1.1 christos { 1470 1.1 christos /* Make sure that got_offset is valid. */ 1471 1.1 christos if (got_offset == (bfd_vma) -1) 1472 1.1 christos got_offset = info [dupes].got_offset; 1473 1.1 christos 1474 1.1 christos /* For duplicates, make sure that the kept one has 1475 1.1 christos a valid got_offset. */ 1476 1.1 christos if (got_offset != (bfd_vma) -1) 1477 1.1 christos info [dupes - 1].got_offset = got_offset; 1478 1.1 christos break; 1479 1.1 christos } 1480 1.1 christos got_offset = info [dupes].got_offset; 1481 1.1 christos prev = curr; 1482 1.1 christos } 1483 1.1 christos 1484 1.1 christos /* How much to move. */ 1485 1.1 christos len = dupes - src; 1486 1.1 christos i = dupes + 1; 1487 1.1 christos 1488 1.1 christos if (len == 1 && dupes < count) 1489 1.1 christos { 1490 1.1 christos /* If we only move 1 element, we combine it with the next 1491 1.1 christos one. There must be at least a duplicate. Find the 1492 1.1 christos next different one. */ 1493 1.1 christos for (diff = dupes + 1, src++; diff < count; diff++, src++) 1494 1.1 christos { 1495 1.1 christos if (info [diff].addend != curr) 1496 1.1 christos break; 1497 1.1 christos /* Make sure that got_offset is valid. */ 1498 1.1 christos if (got_offset == (bfd_vma) -1) 1499 1.1 christos got_offset = info [diff].got_offset; 1500 1.1 christos } 1501 1.1 christos 1502 1.1 christos /* Makre sure that the last duplicated one has an valid 1503 1.1 christos offset. */ 1504 1.1 christos BFD_ASSERT (curr == prev); 1505 1.1 christos if (got_offset != (bfd_vma) -1) 1506 1.1 christos info [diff - 1].got_offset = got_offset; 1507 1.1 christos 1508 1.1 christos if (diff < count) 1509 1.1 christos { 1510 1.1 christos /* Find the next duplicate. Track the current valid 1511 1.1 christos offset. */ 1512 1.1 christos prev = info [diff].addend; 1513 1.1 christos got_offset = info [diff].got_offset; 1514 1.1 christos for (dupes = diff + 1; dupes < count; dupes ++) 1515 1.1 christos { 1516 1.1 christos curr = info [dupes].addend; 1517 1.1 christos if (curr == prev) 1518 1.1 christos { 1519 1.1 christos /* For duplicates, make sure that GOT_OFFSET 1520 1.1 christos is valid. */ 1521 1.1 christos if (got_offset == (bfd_vma) -1) 1522 1.1 christos got_offset = info [dupes].got_offset; 1523 1.1 christos break; 1524 1.1 christos } 1525 1.1 christos got_offset = info [dupes].got_offset; 1526 1.1 christos prev = curr; 1527 1.1 christos diff++; 1528 1.1 christos } 1529 1.1 christos 1530 1.1 christos len = diff - src + 1; 1531 1.1 christos i = diff + 1; 1532 1.1 christos } 1533 1.1 christos } 1534 1.1 christos 1535 1.1 christos memmove (&info [dest], &info [src], len * sizeof (*info)); 1536 1.1 christos 1537 1.1 christos dest += len; 1538 1.1 christos } 1539 1.1 christos 1540 1.1 christos count = dest; 1541 1.1 christos } 1542 1.1 christos else 1543 1.1 christos { 1544 1.1 christos /* When we get here, either there is no duplicate at all or 1545 1.1 christos the only duplicate is the last element. */ 1546 1.1 christos if (dest < count) 1547 1.1 christos { 1548 1.1 christos /* If the last element is a duplicate, make sure that the 1549 1.1 christos kept one has a valid got_offset. We also update count. */ 1550 1.1 christos if (got_offset != (bfd_vma) -1) 1551 1.1 christos info [dest - 1].got_offset = got_offset; 1552 1.1 christos count = dest; 1553 1.1 christos } 1554 1.1 christos } 1555 1.1 christos 1556 1.1 christos return count; 1557 1.1 christos } 1558 1.1 christos 1559 1.1 christos /* Find and/or create a descriptor for dynamic symbol info. This will 1560 1.1 christos vary based on global or local symbol, and the addend to the reloc. 1561 1.1 christos 1562 1.1 christos We don't sort when inserting. Also, we sort and eliminate 1563 1.1 christos duplicates if there is an unsorted section. Typically, this will 1564 1.1 christos only happen once, because we do all insertions before lookups. We 1565 1.1 christos then use bsearch to do a lookup. This also allows lookups to be 1566 1.1 christos fast. So we have fast insertion (O(log N) due to duplicate check), 1567 1.1 christos fast lookup (O(log N)) and one sort (O(N log N) expected time). 1568 1.1 christos Previously, all lookups were O(N) because of the use of the linked 1569 1.1 christos list and also all insertions were O(N) because of the check for 1570 1.1 christos duplicates. There are some complications here because the array 1571 1.1 christos size grows occasionally, which may add an O(N) factor, but this 1572 1.1 christos should be rare. Also, we free the excess array allocation, which 1573 1.1 christos requires a copy which is O(N), but this only happens once. */ 1574 1.1 christos 1575 1.1 christos static struct elf64_ia64_dyn_sym_info * 1576 1.1 christos get_dyn_sym_info (struct elf64_ia64_link_hash_table *ia64_info, 1577 1.1 christos struct elf_link_hash_entry *h, bfd *abfd, 1578 1.10 christos const Elf_Internal_Rela *rel, bool create) 1579 1.1 christos { 1580 1.1 christos struct elf64_ia64_dyn_sym_info **info_p, *info, *dyn_i, key; 1581 1.1 christos unsigned int *count_p, *sorted_count_p, *size_p; 1582 1.1 christos unsigned int count, sorted_count, size; 1583 1.1 christos bfd_vma addend = rel ? rel->r_addend : 0; 1584 1.1 christos bfd_size_type amt; 1585 1.1 christos 1586 1.1 christos if (h) 1587 1.1 christos { 1588 1.1 christos struct elf64_ia64_link_hash_entry *global_h; 1589 1.1 christos 1590 1.1 christos global_h = (struct elf64_ia64_link_hash_entry *) h; 1591 1.1 christos info_p = &global_h->info; 1592 1.1 christos count_p = &global_h->count; 1593 1.1 christos sorted_count_p = &global_h->sorted_count; 1594 1.1 christos size_p = &global_h->size; 1595 1.1 christos } 1596 1.1 christos else 1597 1.1 christos { 1598 1.1 christos struct elf64_ia64_local_hash_entry *loc_h; 1599 1.1 christos 1600 1.1 christos loc_h = get_local_sym_hash (ia64_info, abfd, rel, create); 1601 1.1 christos if (!loc_h) 1602 1.1 christos { 1603 1.1 christos BFD_ASSERT (!create); 1604 1.1 christos return NULL; 1605 1.1 christos } 1606 1.1 christos 1607 1.1 christos info_p = &loc_h->info; 1608 1.1 christos count_p = &loc_h->count; 1609 1.1 christos sorted_count_p = &loc_h->sorted_count; 1610 1.1 christos size_p = &loc_h->size; 1611 1.1 christos } 1612 1.1 christos 1613 1.1 christos count = *count_p; 1614 1.1 christos sorted_count = *sorted_count_p; 1615 1.1 christos size = *size_p; 1616 1.1 christos info = *info_p; 1617 1.1 christos if (create) 1618 1.1 christos { 1619 1.1 christos /* When we create the array, we don't check for duplicates, 1620 1.8 christos except in the previously sorted section if one exists, and 1621 1.1 christos against the last inserted entry. This allows insertions to 1622 1.1 christos be fast. */ 1623 1.1 christos if (info) 1624 1.1 christos { 1625 1.1 christos if (sorted_count) 1626 1.1 christos { 1627 1.1 christos /* Try bsearch first on the sorted section. */ 1628 1.1 christos key.addend = addend; 1629 1.1 christos dyn_i = bsearch (&key, info, sorted_count, 1630 1.1 christos sizeof (*info), addend_compare); 1631 1.1 christos 1632 1.1 christos if (dyn_i) 1633 1.1 christos { 1634 1.1 christos return dyn_i; 1635 1.1 christos } 1636 1.1 christos } 1637 1.1 christos 1638 1.1 christos /* Do a quick check for the last inserted entry. */ 1639 1.1 christos dyn_i = info + count - 1; 1640 1.1 christos if (dyn_i->addend == addend) 1641 1.1 christos { 1642 1.1 christos return dyn_i; 1643 1.1 christos } 1644 1.1 christos } 1645 1.1 christos 1646 1.1 christos if (size == 0) 1647 1.1 christos { 1648 1.1 christos /* It is the very first element. We create the array of size 1649 1.1 christos 1. */ 1650 1.1 christos size = 1; 1651 1.1 christos amt = size * sizeof (*info); 1652 1.1 christos info = bfd_malloc (amt); 1653 1.1 christos } 1654 1.1 christos else if (size <= count) 1655 1.1 christos { 1656 1.1 christos /* We double the array size every time when we reach the 1657 1.1 christos size limit. */ 1658 1.1 christos size += size; 1659 1.1 christos amt = size * sizeof (*info); 1660 1.1 christos info = bfd_realloc (info, amt); 1661 1.1 christos } 1662 1.1 christos else 1663 1.1 christos goto has_space; 1664 1.1 christos 1665 1.1 christos if (info == NULL) 1666 1.1 christos return NULL; 1667 1.1 christos *size_p = size; 1668 1.1 christos *info_p = info; 1669 1.1 christos 1670 1.9 christos has_space: 1671 1.1 christos /* Append the new one to the array. */ 1672 1.1 christos dyn_i = info + count; 1673 1.1 christos memset (dyn_i, 0, sizeof (*dyn_i)); 1674 1.1 christos dyn_i->got_offset = (bfd_vma) -1; 1675 1.1 christos dyn_i->addend = addend; 1676 1.1 christos 1677 1.1 christos /* We increment count only since the new ones are unsorted and 1678 1.1 christos may have duplicate. */ 1679 1.1 christos (*count_p)++; 1680 1.1 christos } 1681 1.1 christos else 1682 1.1 christos { 1683 1.1 christos /* It is a lookup without insertion. Sort array if part of the 1684 1.1 christos array isn't sorted. */ 1685 1.1 christos if (count != sorted_count) 1686 1.1 christos { 1687 1.1 christos count = sort_dyn_sym_info (info, count); 1688 1.1 christos *count_p = count; 1689 1.1 christos *sorted_count_p = count; 1690 1.1 christos } 1691 1.1 christos 1692 1.1 christos /* Free unused memory. */ 1693 1.1 christos if (size != count) 1694 1.1 christos { 1695 1.1 christos amt = count * sizeof (*info); 1696 1.1 christos info = bfd_malloc (amt); 1697 1.1 christos if (info != NULL) 1698 1.1 christos { 1699 1.1 christos memcpy (info, *info_p, amt); 1700 1.1 christos free (*info_p); 1701 1.1 christos *size_p = count; 1702 1.1 christos *info_p = info; 1703 1.1 christos } 1704 1.1 christos } 1705 1.1 christos 1706 1.1 christos key.addend = addend; 1707 1.1 christos dyn_i = bsearch (&key, info, count, 1708 1.1 christos sizeof (*info), addend_compare); 1709 1.1 christos } 1710 1.1 christos 1711 1.1 christos return dyn_i; 1712 1.1 christos } 1713 1.1 christos 1714 1.1 christos static asection * 1715 1.1 christos get_got (bfd *abfd, struct elf64_ia64_link_hash_table *ia64_info) 1716 1.1 christos { 1717 1.1 christos asection *got; 1718 1.1 christos bfd *dynobj; 1719 1.1 christos 1720 1.1 christos got = ia64_info->root.sgot; 1721 1.1 christos if (!got) 1722 1.1 christos { 1723 1.1 christos flagword flags; 1724 1.1 christos 1725 1.1 christos dynobj = ia64_info->root.dynobj; 1726 1.1 christos if (!dynobj) 1727 1.1 christos ia64_info->root.dynobj = dynobj = abfd; 1728 1.1 christos 1729 1.1 christos /* The .got section is always aligned at 8 bytes. */ 1730 1.1 christos flags = get_elf_backend_data (dynobj)->dynamic_sec_flags; 1731 1.1 christos got = bfd_make_section_anyway_with_flags (dynobj, ".got", 1732 1.1 christos flags | SEC_SMALL_DATA); 1733 1.1 christos if (got == NULL 1734 1.9 christos || !bfd_set_section_alignment (got, 3)) 1735 1.8 christos return NULL; 1736 1.1 christos ia64_info->root.sgot = got; 1737 1.1 christos } 1738 1.1 christos 1739 1.1 christos return got; 1740 1.1 christos } 1741 1.1 christos 1742 1.1 christos /* Create function descriptor section (.opd). This section is called .opd 1743 1.1 christos because it contains "official procedure descriptors". The "official" 1744 1.1 christos refers to the fact that these descriptors are used when taking the address 1745 1.1 christos of a procedure, thus ensuring a unique address for each procedure. */ 1746 1.1 christos 1747 1.1 christos static asection * 1748 1.1 christos get_fptr (bfd *abfd, struct bfd_link_info *info, 1749 1.1 christos struct elf64_ia64_link_hash_table *ia64_info) 1750 1.1 christos { 1751 1.1 christos asection *fptr; 1752 1.1 christos bfd *dynobj; 1753 1.1 christos 1754 1.1 christos fptr = ia64_info->fptr_sec; 1755 1.1 christos if (!fptr) 1756 1.1 christos { 1757 1.1 christos dynobj = ia64_info->root.dynobj; 1758 1.1 christos if (!dynobj) 1759 1.1 christos ia64_info->root.dynobj = dynobj = abfd; 1760 1.1 christos 1761 1.1 christos fptr = bfd_make_section_anyway_with_flags (dynobj, ".opd", 1762 1.1 christos (SEC_ALLOC 1763 1.1 christos | SEC_LOAD 1764 1.1 christos | SEC_HAS_CONTENTS 1765 1.1 christos | SEC_IN_MEMORY 1766 1.6 christos | (bfd_link_pie (info) ? 0 1767 1.1 christos : SEC_READONLY) 1768 1.1 christos | SEC_LINKER_CREATED)); 1769 1.1 christos if (!fptr 1770 1.9 christos || !bfd_set_section_alignment (fptr, 4)) 1771 1.1 christos { 1772 1.1 christos BFD_ASSERT (0); 1773 1.1 christos return NULL; 1774 1.1 christos } 1775 1.1 christos 1776 1.1 christos ia64_info->fptr_sec = fptr; 1777 1.1 christos 1778 1.6 christos if (bfd_link_pie (info)) 1779 1.1 christos { 1780 1.1 christos asection *fptr_rel; 1781 1.1 christos fptr_rel = bfd_make_section_anyway_with_flags (dynobj, ".rela.opd", 1782 1.1 christos (SEC_ALLOC | SEC_LOAD 1783 1.1 christos | SEC_HAS_CONTENTS 1784 1.1 christos | SEC_IN_MEMORY 1785 1.1 christos | SEC_LINKER_CREATED 1786 1.1 christos | SEC_READONLY)); 1787 1.1 christos if (fptr_rel == NULL 1788 1.9 christos || !bfd_set_section_alignment (fptr_rel, 3)) 1789 1.1 christos { 1790 1.1 christos BFD_ASSERT (0); 1791 1.1 christos return NULL; 1792 1.1 christos } 1793 1.1 christos 1794 1.1 christos ia64_info->rel_fptr_sec = fptr_rel; 1795 1.1 christos } 1796 1.1 christos } 1797 1.1 christos 1798 1.1 christos return fptr; 1799 1.1 christos } 1800 1.1 christos 1801 1.1 christos static asection * 1802 1.1 christos get_pltoff (bfd *abfd, struct elf64_ia64_link_hash_table *ia64_info) 1803 1.1 christos { 1804 1.1 christos asection *pltoff; 1805 1.1 christos bfd *dynobj; 1806 1.1 christos 1807 1.1 christos pltoff = ia64_info->pltoff_sec; 1808 1.1 christos if (!pltoff) 1809 1.1 christos { 1810 1.1 christos dynobj = ia64_info->root.dynobj; 1811 1.1 christos if (!dynobj) 1812 1.1 christos ia64_info->root.dynobj = dynobj = abfd; 1813 1.1 christos 1814 1.1 christos pltoff = bfd_make_section_anyway_with_flags (dynobj, 1815 1.1 christos ELF_STRING_ia64_pltoff, 1816 1.1 christos (SEC_ALLOC 1817 1.1 christos | SEC_LOAD 1818 1.1 christos | SEC_HAS_CONTENTS 1819 1.1 christos | SEC_IN_MEMORY 1820 1.1 christos | SEC_SMALL_DATA 1821 1.1 christos | SEC_LINKER_CREATED)); 1822 1.1 christos if (!pltoff 1823 1.9 christos || !bfd_set_section_alignment (pltoff, 4)) 1824 1.1 christos { 1825 1.1 christos BFD_ASSERT (0); 1826 1.1 christos return NULL; 1827 1.1 christos } 1828 1.1 christos 1829 1.1 christos ia64_info->pltoff_sec = pltoff; 1830 1.1 christos } 1831 1.1 christos 1832 1.1 christos return pltoff; 1833 1.1 christos } 1834 1.1 christos 1835 1.1 christos static asection * 1836 1.1 christos get_reloc_section (bfd *abfd, 1837 1.1 christos struct elf64_ia64_link_hash_table *ia64_info, 1838 1.10 christos asection *sec, bool create) 1839 1.1 christos { 1840 1.1 christos const char *srel_name; 1841 1.1 christos asection *srel; 1842 1.1 christos bfd *dynobj; 1843 1.1 christos 1844 1.1 christos srel_name = (bfd_elf_string_from_elf_section 1845 1.1 christos (abfd, elf_elfheader(abfd)->e_shstrndx, 1846 1.1 christos _bfd_elf_single_rel_hdr (sec)->sh_name)); 1847 1.1 christos if (srel_name == NULL) 1848 1.1 christos return NULL; 1849 1.1 christos 1850 1.10 christos BFD_ASSERT ((startswith (srel_name, ".rela") 1851 1.9 christos && strcmp (bfd_section_name (sec), srel_name+5) == 0) 1852 1.10 christos || (startswith (srel_name, ".rel") 1853 1.9 christos && strcmp (bfd_section_name (sec), srel_name+4) == 0)); 1854 1.1 christos 1855 1.1 christos dynobj = ia64_info->root.dynobj; 1856 1.1 christos if (!dynobj) 1857 1.1 christos ia64_info->root.dynobj = dynobj = abfd; 1858 1.1 christos 1859 1.1 christos srel = bfd_get_linker_section (dynobj, srel_name); 1860 1.1 christos if (srel == NULL && create) 1861 1.1 christos { 1862 1.1 christos srel = bfd_make_section_anyway_with_flags (dynobj, srel_name, 1863 1.1 christos (SEC_ALLOC | SEC_LOAD 1864 1.1 christos | SEC_HAS_CONTENTS 1865 1.1 christos | SEC_IN_MEMORY 1866 1.1 christos | SEC_LINKER_CREATED 1867 1.1 christos | SEC_READONLY)); 1868 1.1 christos if (srel == NULL 1869 1.9 christos || !bfd_set_section_alignment (srel, 3)) 1870 1.1 christos return NULL; 1871 1.1 christos } 1872 1.1 christos 1873 1.1 christos return srel; 1874 1.1 christos } 1875 1.1 christos 1876 1.10 christos static bool 1877 1.1 christos count_dyn_reloc (bfd *abfd, struct elf64_ia64_dyn_sym_info *dyn_i, 1878 1.1 christos asection *srel, int type) 1879 1.1 christos { 1880 1.1 christos struct elf64_ia64_dyn_reloc_entry *rent; 1881 1.1 christos 1882 1.1 christos for (rent = dyn_i->reloc_entries; rent; rent = rent->next) 1883 1.1 christos if (rent->srel == srel && rent->type == type) 1884 1.1 christos break; 1885 1.1 christos 1886 1.1 christos if (!rent) 1887 1.1 christos { 1888 1.1 christos rent = ((struct elf64_ia64_dyn_reloc_entry *) 1889 1.1 christos bfd_alloc (abfd, (bfd_size_type) sizeof (*rent))); 1890 1.1 christos if (!rent) 1891 1.10 christos return false; 1892 1.1 christos 1893 1.1 christos rent->next = dyn_i->reloc_entries; 1894 1.1 christos rent->srel = srel; 1895 1.1 christos rent->type = type; 1896 1.1 christos rent->count = 0; 1897 1.1 christos dyn_i->reloc_entries = rent; 1898 1.1 christos } 1899 1.1 christos rent->count++; 1900 1.1 christos 1901 1.10 christos return true; 1902 1.1 christos } 1903 1.1 christos 1904 1.10 christos static bool 1905 1.1 christos elf64_ia64_check_relocs (bfd *abfd, struct bfd_link_info *info, 1906 1.1 christos asection *sec, 1907 1.1 christos const Elf_Internal_Rela *relocs) 1908 1.1 christos { 1909 1.1 christos struct elf64_ia64_link_hash_table *ia64_info; 1910 1.1 christos const Elf_Internal_Rela *relend; 1911 1.1 christos Elf_Internal_Shdr *symtab_hdr; 1912 1.1 christos const Elf_Internal_Rela *rel; 1913 1.1 christos asection *got, *fptr, *srel, *pltoff; 1914 1.1 christos enum { 1915 1.1 christos NEED_GOT = 1, 1916 1.1 christos NEED_GOTX = 2, 1917 1.1 christos NEED_FPTR = 4, 1918 1.1 christos NEED_PLTOFF = 8, 1919 1.1 christos NEED_MIN_PLT = 16, 1920 1.1 christos NEED_FULL_PLT = 32, 1921 1.1 christos NEED_DYNREL = 64, 1922 1.1 christos NEED_LTOFF_FPTR = 128 1923 1.1 christos }; 1924 1.1 christos int need_entry; 1925 1.1 christos struct elf_link_hash_entry *h; 1926 1.1 christos unsigned long r_symndx; 1927 1.10 christos bool maybe_dynamic; 1928 1.1 christos 1929 1.6 christos if (bfd_link_relocatable (info)) 1930 1.10 christos return true; 1931 1.1 christos 1932 1.1 christos symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 1933 1.1 christos ia64_info = elf64_ia64_hash_table (info); 1934 1.1 christos if (ia64_info == NULL) 1935 1.10 christos return false; 1936 1.1 christos 1937 1.1 christos got = fptr = srel = pltoff = NULL; 1938 1.1 christos 1939 1.1 christos relend = relocs + sec->reloc_count; 1940 1.1 christos 1941 1.1 christos /* We scan relocations first to create dynamic relocation arrays. We 1942 1.1 christos modified get_dyn_sym_info to allow fast insertion and support fast 1943 1.1 christos lookup in the next loop. */ 1944 1.1 christos for (rel = relocs; rel < relend; ++rel) 1945 1.1 christos { 1946 1.1 christos r_symndx = ELF64_R_SYM (rel->r_info); 1947 1.1 christos if (r_symndx >= symtab_hdr->sh_info) 1948 1.1 christos { 1949 1.1 christos long indx = r_symndx - symtab_hdr->sh_info; 1950 1.1 christos h = elf_sym_hashes (abfd)[indx]; 1951 1.1 christos while (h->root.type == bfd_link_hash_indirect 1952 1.1 christos || h->root.type == bfd_link_hash_warning) 1953 1.1 christos h = (struct elf_link_hash_entry *) h->root.u.i.link; 1954 1.1 christos } 1955 1.1 christos else 1956 1.1 christos h = NULL; 1957 1.1 christos 1958 1.1 christos /* We can only get preliminary data on whether a symbol is 1959 1.1 christos locally or externally defined, as not all of the input files 1960 1.1 christos have yet been processed. Do something with what we know, as 1961 1.1 christos this may help reduce memory usage and processing time later. */ 1962 1.6 christos maybe_dynamic = (h && ((!bfd_link_executable (info) 1963 1.1 christos && (!SYMBOLIC_BIND (info, h) 1964 1.1 christos || info->unresolved_syms_in_shared_libs == RM_IGNORE)) 1965 1.1 christos || !h->def_regular 1966 1.1 christos || h->root.type == bfd_link_hash_defweak)); 1967 1.1 christos 1968 1.1 christos need_entry = 0; 1969 1.1 christos switch (ELF64_R_TYPE (rel->r_info)) 1970 1.1 christos { 1971 1.1 christos case R_IA64_TPREL64MSB: 1972 1.1 christos case R_IA64_TPREL64LSB: 1973 1.1 christos case R_IA64_LTOFF_TPREL22: 1974 1.1 christos case R_IA64_DTPREL32MSB: 1975 1.1 christos case R_IA64_DTPREL32LSB: 1976 1.1 christos case R_IA64_DTPREL64MSB: 1977 1.1 christos case R_IA64_DTPREL64LSB: 1978 1.1 christos case R_IA64_LTOFF_DTPREL22: 1979 1.1 christos case R_IA64_DTPMOD64MSB: 1980 1.1 christos case R_IA64_DTPMOD64LSB: 1981 1.1 christos case R_IA64_LTOFF_DTPMOD22: 1982 1.8 christos abort (); 1983 1.1 christos break; 1984 1.1 christos 1985 1.1 christos case R_IA64_IPLTMSB: 1986 1.1 christos case R_IA64_IPLTLSB: 1987 1.8 christos break; 1988 1.1 christos 1989 1.1 christos case R_IA64_LTOFF_FPTR22: 1990 1.1 christos case R_IA64_LTOFF_FPTR64I: 1991 1.1 christos case R_IA64_LTOFF_FPTR32MSB: 1992 1.1 christos case R_IA64_LTOFF_FPTR32LSB: 1993 1.1 christos case R_IA64_LTOFF_FPTR64MSB: 1994 1.1 christos case R_IA64_LTOFF_FPTR64LSB: 1995 1.1 christos need_entry = NEED_FPTR | NEED_GOT | NEED_LTOFF_FPTR; 1996 1.1 christos break; 1997 1.1 christos 1998 1.1 christos case R_IA64_FPTR64I: 1999 1.1 christos case R_IA64_FPTR32MSB: 2000 1.1 christos case R_IA64_FPTR32LSB: 2001 1.1 christos case R_IA64_FPTR64MSB: 2002 1.1 christos case R_IA64_FPTR64LSB: 2003 1.6 christos if (bfd_link_pic (info) || h) 2004 1.1 christos need_entry = NEED_FPTR | NEED_DYNREL; 2005 1.1 christos else 2006 1.1 christos need_entry = NEED_FPTR; 2007 1.1 christos break; 2008 1.1 christos 2009 1.1 christos case R_IA64_LTOFF22: 2010 1.1 christos case R_IA64_LTOFF64I: 2011 1.1 christos need_entry = NEED_GOT; 2012 1.1 christos break; 2013 1.1 christos 2014 1.1 christos case R_IA64_LTOFF22X: 2015 1.1 christos need_entry = NEED_GOTX; 2016 1.1 christos break; 2017 1.1 christos 2018 1.1 christos case R_IA64_PLTOFF22: 2019 1.1 christos case R_IA64_PLTOFF64I: 2020 1.1 christos case R_IA64_PLTOFF64MSB: 2021 1.1 christos case R_IA64_PLTOFF64LSB: 2022 1.1 christos need_entry = NEED_PLTOFF; 2023 1.1 christos if (h) 2024 1.1 christos { 2025 1.1 christos if (maybe_dynamic) 2026 1.1 christos need_entry |= NEED_MIN_PLT; 2027 1.1 christos } 2028 1.1 christos else 2029 1.1 christos { 2030 1.1 christos (*info->callbacks->warning) 2031 1.1 christos (info, _("@pltoff reloc against local symbol"), 0, 2032 1.1 christos abfd, 0, (bfd_vma) 0); 2033 1.1 christos } 2034 1.1 christos break; 2035 1.1 christos 2036 1.1 christos case R_IA64_PCREL21B: 2037 1.8 christos case R_IA64_PCREL60B: 2038 1.1 christos /* Depending on where this symbol is defined, we may or may not 2039 1.1 christos need a full plt entry. Only skip if we know we'll not need 2040 1.1 christos the entry -- static or symbolic, and the symbol definition 2041 1.1 christos has already been seen. */ 2042 1.1 christos if (maybe_dynamic && rel->r_addend == 0) 2043 1.1 christos need_entry = NEED_FULL_PLT; 2044 1.1 christos break; 2045 1.1 christos 2046 1.1 christos case R_IA64_IMM14: 2047 1.1 christos case R_IA64_IMM22: 2048 1.1 christos case R_IA64_IMM64: 2049 1.1 christos case R_IA64_DIR32MSB: 2050 1.1 christos case R_IA64_DIR32LSB: 2051 1.1 christos case R_IA64_DIR64MSB: 2052 1.1 christos case R_IA64_DIR64LSB: 2053 1.1 christos /* Shared objects will always need at least a REL relocation. */ 2054 1.6 christos if (bfd_link_pic (info) || maybe_dynamic) 2055 1.1 christos need_entry = NEED_DYNREL; 2056 1.1 christos break; 2057 1.1 christos 2058 1.1 christos case R_IA64_PCREL22: 2059 1.1 christos case R_IA64_PCREL64I: 2060 1.1 christos case R_IA64_PCREL32MSB: 2061 1.1 christos case R_IA64_PCREL32LSB: 2062 1.1 christos case R_IA64_PCREL64MSB: 2063 1.1 christos case R_IA64_PCREL64LSB: 2064 1.1 christos if (maybe_dynamic) 2065 1.1 christos need_entry = NEED_DYNREL; 2066 1.1 christos break; 2067 1.1 christos } 2068 1.1 christos 2069 1.1 christos if (!need_entry) 2070 1.1 christos continue; 2071 1.1 christos 2072 1.1 christos if ((need_entry & NEED_FPTR) != 0 2073 1.1 christos && rel->r_addend) 2074 1.1 christos { 2075 1.1 christos (*info->callbacks->warning) 2076 1.1 christos (info, _("non-zero addend in @fptr reloc"), 0, 2077 1.1 christos abfd, 0, (bfd_vma) 0); 2078 1.1 christos } 2079 1.1 christos 2080 1.10 christos if (get_dyn_sym_info (ia64_info, h, abfd, rel, true) == NULL) 2081 1.10 christos return false; 2082 1.1 christos } 2083 1.1 christos 2084 1.1 christos /* Now, we only do lookup without insertion, which is very fast 2085 1.1 christos with the modified get_dyn_sym_info. */ 2086 1.1 christos for (rel = relocs; rel < relend; ++rel) 2087 1.1 christos { 2088 1.1 christos struct elf64_ia64_dyn_sym_info *dyn_i; 2089 1.1 christos int dynrel_type = R_IA64_NONE; 2090 1.1 christos 2091 1.1 christos r_symndx = ELF64_R_SYM (rel->r_info); 2092 1.1 christos if (r_symndx >= symtab_hdr->sh_info) 2093 1.1 christos { 2094 1.1 christos /* We're dealing with a global symbol -- find its hash entry 2095 1.1 christos and mark it as being referenced. */ 2096 1.1 christos long indx = r_symndx - symtab_hdr->sh_info; 2097 1.1 christos h = elf_sym_hashes (abfd)[indx]; 2098 1.1 christos while (h->root.type == bfd_link_hash_indirect 2099 1.1 christos || h->root.type == bfd_link_hash_warning) 2100 1.1 christos h = (struct elf_link_hash_entry *) h->root.u.i.link; 2101 1.1 christos 2102 1.1 christos /* PR15323, ref flags aren't set for references in the same 2103 1.1 christos object. */ 2104 1.1 christos h->ref_regular = 1; 2105 1.1 christos } 2106 1.1 christos else 2107 1.1 christos h = NULL; 2108 1.1 christos 2109 1.1 christos /* We can only get preliminary data on whether a symbol is 2110 1.1 christos locally or externally defined, as not all of the input files 2111 1.1 christos have yet been processed. Do something with what we know, as 2112 1.1 christos this may help reduce memory usage and processing time later. */ 2113 1.6 christos maybe_dynamic = (h && ((!bfd_link_executable (info) 2114 1.1 christos && (!SYMBOLIC_BIND (info, h) 2115 1.1 christos || info->unresolved_syms_in_shared_libs == RM_IGNORE)) 2116 1.1 christos || !h->def_regular 2117 1.1 christos || h->root.type == bfd_link_hash_defweak)); 2118 1.1 christos 2119 1.1 christos need_entry = 0; 2120 1.1 christos switch (ELF64_R_TYPE (rel->r_info)) 2121 1.1 christos { 2122 1.1 christos case R_IA64_TPREL64MSB: 2123 1.1 christos case R_IA64_TPREL64LSB: 2124 1.1 christos case R_IA64_LTOFF_TPREL22: 2125 1.1 christos case R_IA64_DTPREL32MSB: 2126 1.1 christos case R_IA64_DTPREL32LSB: 2127 1.1 christos case R_IA64_DTPREL64MSB: 2128 1.1 christos case R_IA64_DTPREL64LSB: 2129 1.1 christos case R_IA64_LTOFF_DTPREL22: 2130 1.1 christos case R_IA64_DTPMOD64MSB: 2131 1.1 christos case R_IA64_DTPMOD64LSB: 2132 1.1 christos case R_IA64_LTOFF_DTPMOD22: 2133 1.8 christos abort (); 2134 1.1 christos break; 2135 1.1 christos 2136 1.1 christos case R_IA64_LTOFF_FPTR22: 2137 1.1 christos case R_IA64_LTOFF_FPTR64I: 2138 1.1 christos case R_IA64_LTOFF_FPTR32MSB: 2139 1.1 christos case R_IA64_LTOFF_FPTR32LSB: 2140 1.1 christos case R_IA64_LTOFF_FPTR64MSB: 2141 1.1 christos case R_IA64_LTOFF_FPTR64LSB: 2142 1.1 christos need_entry = NEED_FPTR | NEED_GOT | NEED_LTOFF_FPTR; 2143 1.1 christos break; 2144 1.1 christos 2145 1.1 christos case R_IA64_FPTR64I: 2146 1.1 christos case R_IA64_FPTR32MSB: 2147 1.1 christos case R_IA64_FPTR32LSB: 2148 1.1 christos case R_IA64_FPTR64MSB: 2149 1.1 christos case R_IA64_FPTR64LSB: 2150 1.6 christos if (bfd_link_pic (info) || h) 2151 1.1 christos need_entry = NEED_FPTR | NEED_DYNREL; 2152 1.1 christos else 2153 1.1 christos need_entry = NEED_FPTR; 2154 1.1 christos dynrel_type = R_IA64_FPTR64LSB; 2155 1.1 christos break; 2156 1.1 christos 2157 1.1 christos case R_IA64_LTOFF22: 2158 1.1 christos case R_IA64_LTOFF64I: 2159 1.1 christos need_entry = NEED_GOT; 2160 1.1 christos break; 2161 1.1 christos 2162 1.1 christos case R_IA64_LTOFF22X: 2163 1.1 christos need_entry = NEED_GOTX; 2164 1.1 christos break; 2165 1.1 christos 2166 1.1 christos case R_IA64_PLTOFF22: 2167 1.1 christos case R_IA64_PLTOFF64I: 2168 1.1 christos case R_IA64_PLTOFF64MSB: 2169 1.1 christos case R_IA64_PLTOFF64LSB: 2170 1.1 christos need_entry = NEED_PLTOFF; 2171 1.1 christos if (h) 2172 1.1 christos { 2173 1.1 christos if (maybe_dynamic) 2174 1.1 christos need_entry |= NEED_MIN_PLT; 2175 1.1 christos } 2176 1.1 christos break; 2177 1.1 christos 2178 1.1 christos case R_IA64_PCREL21B: 2179 1.8 christos case R_IA64_PCREL60B: 2180 1.1 christos /* Depending on where this symbol is defined, we may or may not 2181 1.1 christos need a full plt entry. Only skip if we know we'll not need 2182 1.1 christos the entry -- static or symbolic, and the symbol definition 2183 1.1 christos has already been seen. */ 2184 1.1 christos if (maybe_dynamic && rel->r_addend == 0) 2185 1.1 christos need_entry = NEED_FULL_PLT; 2186 1.1 christos break; 2187 1.1 christos 2188 1.1 christos case R_IA64_IMM14: 2189 1.1 christos case R_IA64_IMM22: 2190 1.1 christos case R_IA64_IMM64: 2191 1.1 christos case R_IA64_DIR32MSB: 2192 1.1 christos case R_IA64_DIR32LSB: 2193 1.1 christos case R_IA64_DIR64MSB: 2194 1.1 christos case R_IA64_DIR64LSB: 2195 1.1 christos /* Shared objects will always need at least a REL relocation. */ 2196 1.6 christos if (bfd_link_pic (info) || maybe_dynamic) 2197 1.1 christos need_entry = NEED_DYNREL; 2198 1.1 christos dynrel_type = R_IA64_DIR64LSB; 2199 1.1 christos break; 2200 1.1 christos 2201 1.1 christos case R_IA64_IPLTMSB: 2202 1.1 christos case R_IA64_IPLTLSB: 2203 1.1 christos break; 2204 1.1 christos 2205 1.1 christos case R_IA64_PCREL22: 2206 1.1 christos case R_IA64_PCREL64I: 2207 1.1 christos case R_IA64_PCREL32MSB: 2208 1.1 christos case R_IA64_PCREL32LSB: 2209 1.1 christos case R_IA64_PCREL64MSB: 2210 1.1 christos case R_IA64_PCREL64LSB: 2211 1.1 christos if (maybe_dynamic) 2212 1.1 christos need_entry = NEED_DYNREL; 2213 1.1 christos dynrel_type = R_IA64_PCREL64LSB; 2214 1.1 christos break; 2215 1.1 christos } 2216 1.1 christos 2217 1.1 christos if (!need_entry) 2218 1.1 christos continue; 2219 1.1 christos 2220 1.10 christos dyn_i = get_dyn_sym_info (ia64_info, h, abfd, rel, false); 2221 1.1 christos 2222 1.1 christos /* Record whether or not this is a local symbol. */ 2223 1.1 christos dyn_i->h = h; 2224 1.1 christos 2225 1.1 christos /* Create what's needed. */ 2226 1.1 christos if (need_entry & (NEED_GOT | NEED_GOTX)) 2227 1.1 christos { 2228 1.1 christos if (!got) 2229 1.1 christos { 2230 1.1 christos got = get_got (abfd, ia64_info); 2231 1.1 christos if (!got) 2232 1.10 christos return false; 2233 1.1 christos } 2234 1.1 christos if (need_entry & NEED_GOT) 2235 1.1 christos dyn_i->want_got = 1; 2236 1.1 christos if (need_entry & NEED_GOTX) 2237 1.1 christos dyn_i->want_gotx = 1; 2238 1.1 christos } 2239 1.1 christos if (need_entry & NEED_FPTR) 2240 1.1 christos { 2241 1.8 christos /* Create the .opd section. */ 2242 1.1 christos if (!fptr) 2243 1.1 christos { 2244 1.1 christos fptr = get_fptr (abfd, info, ia64_info); 2245 1.1 christos if (!fptr) 2246 1.10 christos return false; 2247 1.1 christos } 2248 1.1 christos dyn_i->want_fptr = 1; 2249 1.1 christos } 2250 1.1 christos if (need_entry & NEED_LTOFF_FPTR) 2251 1.1 christos dyn_i->want_ltoff_fptr = 1; 2252 1.1 christos if (need_entry & (NEED_MIN_PLT | NEED_FULL_PLT)) 2253 1.1 christos { 2254 1.8 christos if (!ia64_info->root.dynobj) 2255 1.1 christos ia64_info->root.dynobj = abfd; 2256 1.1 christos h->needs_plt = 1; 2257 1.1 christos dyn_i->want_plt = 1; 2258 1.1 christos } 2259 1.1 christos if (need_entry & NEED_FULL_PLT) 2260 1.1 christos dyn_i->want_plt2 = 1; 2261 1.1 christos if (need_entry & NEED_PLTOFF) 2262 1.1 christos { 2263 1.1 christos /* This is needed here, in case @pltoff is used in a non-shared 2264 1.1 christos link. */ 2265 1.1 christos if (!pltoff) 2266 1.1 christos { 2267 1.1 christos pltoff = get_pltoff (abfd, ia64_info); 2268 1.1 christos if (!pltoff) 2269 1.10 christos return false; 2270 1.1 christos } 2271 1.1 christos 2272 1.1 christos dyn_i->want_pltoff = 1; 2273 1.1 christos } 2274 1.1 christos if ((need_entry & NEED_DYNREL) && (sec->flags & SEC_ALLOC)) 2275 1.1 christos { 2276 1.1 christos if (!srel) 2277 1.1 christos { 2278 1.10 christos srel = get_reloc_section (abfd, ia64_info, sec, true); 2279 1.1 christos if (!srel) 2280 1.10 christos return false; 2281 1.1 christos } 2282 1.1 christos if (!count_dyn_reloc (abfd, dyn_i, srel, dynrel_type)) 2283 1.10 christos return false; 2284 1.1 christos } 2285 1.1 christos } 2286 1.1 christos 2287 1.10 christos return true; 2288 1.1 christos } 2289 1.1 christos 2290 1.1 christos /* For cleanliness, and potentially faster dynamic loading, allocate 2291 1.1 christos external GOT entries first. */ 2292 1.1 christos 2293 1.10 christos static bool 2294 1.1 christos allocate_global_data_got (struct elf64_ia64_dyn_sym_info *dyn_i, 2295 1.1 christos void * data) 2296 1.1 christos { 2297 1.1 christos struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *)data; 2298 1.1 christos 2299 1.1 christos if ((dyn_i->want_got || dyn_i->want_gotx) 2300 1.1 christos && ! dyn_i->want_fptr 2301 1.1 christos && elf64_ia64_dynamic_symbol_p (dyn_i->h)) 2302 1.1 christos { 2303 1.1 christos /* GOT entry with FPTR is done by allocate_global_fptr_got. */ 2304 1.1 christos dyn_i->got_offset = x->ofs; 2305 1.1 christos x->ofs += 8; 2306 1.1 christos } 2307 1.10 christos return true; 2308 1.1 christos } 2309 1.1 christos 2310 1.1 christos /* Next, allocate all the GOT entries used by LTOFF_FPTR relocs. */ 2311 1.1 christos 2312 1.10 christos static bool 2313 1.1 christos allocate_global_fptr_got (struct elf64_ia64_dyn_sym_info *dyn_i, 2314 1.1 christos void * data) 2315 1.1 christos { 2316 1.1 christos struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *)data; 2317 1.1 christos 2318 1.1 christos if (dyn_i->want_got 2319 1.1 christos && dyn_i->want_fptr 2320 1.1 christos && elf64_ia64_dynamic_symbol_p (dyn_i->h)) 2321 1.1 christos { 2322 1.1 christos dyn_i->got_offset = x->ofs; 2323 1.1 christos x->ofs += 8; 2324 1.1 christos } 2325 1.10 christos return true; 2326 1.1 christos } 2327 1.1 christos 2328 1.1 christos /* Lastly, allocate all the GOT entries for local data. */ 2329 1.1 christos 2330 1.10 christos static bool 2331 1.1 christos allocate_local_got (struct elf64_ia64_dyn_sym_info *dyn_i, 2332 1.1 christos void * data) 2333 1.1 christos { 2334 1.1 christos struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *) data; 2335 1.1 christos 2336 1.1 christos if ((dyn_i->want_got || dyn_i->want_gotx) 2337 1.1 christos && !elf64_ia64_dynamic_symbol_p (dyn_i->h)) 2338 1.1 christos { 2339 1.1 christos dyn_i->got_offset = x->ofs; 2340 1.1 christos x->ofs += 8; 2341 1.1 christos } 2342 1.10 christos return true; 2343 1.1 christos } 2344 1.1 christos 2345 1.1 christos /* Allocate function descriptors. We can do these for every function 2346 1.1 christos in a main executable that is not exported. */ 2347 1.1 christos 2348 1.10 christos static bool 2349 1.1 christos allocate_fptr (struct elf64_ia64_dyn_sym_info *dyn_i, void * data) 2350 1.1 christos { 2351 1.1 christos struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *) data; 2352 1.1 christos 2353 1.1 christos if (dyn_i->want_fptr) 2354 1.1 christos { 2355 1.1 christos struct elf_link_hash_entry *h = dyn_i->h; 2356 1.1 christos 2357 1.1 christos if (h) 2358 1.1 christos while (h->root.type == bfd_link_hash_indirect 2359 1.1 christos || h->root.type == bfd_link_hash_warning) 2360 1.1 christos h = (struct elf_link_hash_entry *) h->root.u.i.link; 2361 1.1 christos 2362 1.1 christos if (h == NULL || !h->def_dynamic) 2363 1.1 christos { 2364 1.8 christos /* A non dynamic symbol. */ 2365 1.1 christos dyn_i->fptr_offset = x->ofs; 2366 1.1 christos x->ofs += 16; 2367 1.1 christos } 2368 1.1 christos else 2369 1.1 christos dyn_i->want_fptr = 0; 2370 1.1 christos } 2371 1.10 christos return true; 2372 1.1 christos } 2373 1.1 christos 2374 1.1 christos /* Allocate all the minimal PLT entries. */ 2375 1.1 christos 2376 1.10 christos static bool 2377 1.1 christos allocate_plt_entries (struct elf64_ia64_dyn_sym_info *dyn_i, 2378 1.1 christos void * data ATTRIBUTE_UNUSED) 2379 1.1 christos { 2380 1.1 christos if (dyn_i->want_plt) 2381 1.1 christos { 2382 1.1 christos struct elf_link_hash_entry *h = dyn_i->h; 2383 1.1 christos 2384 1.1 christos if (h) 2385 1.1 christos while (h->root.type == bfd_link_hash_indirect 2386 1.1 christos || h->root.type == bfd_link_hash_warning) 2387 1.1 christos h = (struct elf_link_hash_entry *) h->root.u.i.link; 2388 1.1 christos 2389 1.1 christos /* ??? Versioned symbols seem to lose NEEDS_PLT. */ 2390 1.1 christos if (elf64_ia64_dynamic_symbol_p (h)) 2391 1.1 christos { 2392 1.1 christos dyn_i->want_pltoff = 1; 2393 1.1 christos } 2394 1.1 christos else 2395 1.1 christos { 2396 1.1 christos dyn_i->want_plt = 0; 2397 1.1 christos dyn_i->want_plt2 = 0; 2398 1.1 christos } 2399 1.1 christos } 2400 1.10 christos return true; 2401 1.1 christos } 2402 1.1 christos 2403 1.1 christos /* Allocate all the full PLT entries. */ 2404 1.1 christos 2405 1.10 christos static bool 2406 1.1 christos allocate_plt2_entries (struct elf64_ia64_dyn_sym_info *dyn_i, 2407 1.1 christos void * data) 2408 1.1 christos { 2409 1.1 christos struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *)data; 2410 1.1 christos 2411 1.1 christos if (dyn_i->want_plt2) 2412 1.1 christos { 2413 1.1 christos struct elf_link_hash_entry *h = dyn_i->h; 2414 1.1 christos bfd_size_type ofs = x->ofs; 2415 1.1 christos 2416 1.1 christos dyn_i->plt2_offset = ofs; 2417 1.1 christos x->ofs = ofs + PLT_FULL_ENTRY_SIZE; 2418 1.1 christos 2419 1.1 christos while (h->root.type == bfd_link_hash_indirect 2420 1.1 christos || h->root.type == bfd_link_hash_warning) 2421 1.1 christos h = (struct elf_link_hash_entry *) h->root.u.i.link; 2422 1.1 christos dyn_i->h->plt.offset = ofs; 2423 1.1 christos } 2424 1.10 christos return true; 2425 1.1 christos } 2426 1.1 christos 2427 1.1 christos /* Allocate all the PLTOFF entries requested by relocations and 2428 1.1 christos plt entries. We can't share space with allocated FPTR entries, 2429 1.1 christos because the latter are not necessarily addressable by the GP. 2430 1.1 christos ??? Relaxation might be able to determine that they are. */ 2431 1.1 christos 2432 1.10 christos static bool 2433 1.1 christos allocate_pltoff_entries (struct elf64_ia64_dyn_sym_info *dyn_i, 2434 1.1 christos void * data) 2435 1.1 christos { 2436 1.1 christos struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *)data; 2437 1.1 christos 2438 1.1 christos if (dyn_i->want_pltoff) 2439 1.1 christos { 2440 1.1 christos dyn_i->pltoff_offset = x->ofs; 2441 1.1 christos x->ofs += 16; 2442 1.1 christos } 2443 1.10 christos return true; 2444 1.1 christos } 2445 1.1 christos 2446 1.1 christos /* Allocate dynamic relocations for those symbols that turned out 2447 1.1 christos to be dynamic. */ 2448 1.1 christos 2449 1.10 christos static bool 2450 1.1 christos allocate_dynrel_entries (struct elf64_ia64_dyn_sym_info *dyn_i, 2451 1.1 christos void * data) 2452 1.1 christos { 2453 1.1 christos struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *)data; 2454 1.1 christos struct elf64_ia64_link_hash_table *ia64_info; 2455 1.1 christos struct elf64_ia64_dyn_reloc_entry *rent; 2456 1.10 christos bool dynamic_symbol, shared, resolved_zero; 2457 1.1 christos struct elf64_ia64_link_hash_entry *h_ia64; 2458 1.1 christos 2459 1.1 christos ia64_info = elf64_ia64_hash_table (x->info); 2460 1.1 christos if (ia64_info == NULL) 2461 1.10 christos return false; 2462 1.1 christos 2463 1.1 christos /* Note that this can't be used in relation to FPTR relocs below. */ 2464 1.1 christos dynamic_symbol = elf64_ia64_dynamic_symbol_p (dyn_i->h); 2465 1.1 christos 2466 1.6 christos shared = bfd_link_pic (x->info); 2467 1.1 christos resolved_zero = (dyn_i->h 2468 1.1 christos && ELF_ST_VISIBILITY (dyn_i->h->other) 2469 1.1 christos && dyn_i->h->root.type == bfd_link_hash_undefweak); 2470 1.1 christos 2471 1.1 christos /* Take care of the GOT and PLT relocations. */ 2472 1.1 christos 2473 1.1 christos if ((!resolved_zero 2474 1.1 christos && (dynamic_symbol || shared) 2475 1.1 christos && (dyn_i->want_got || dyn_i->want_gotx)) 2476 1.1 christos || (dyn_i->want_ltoff_fptr 2477 1.1 christos && dyn_i->h 2478 1.1 christos && dyn_i->h->def_dynamic)) 2479 1.1 christos { 2480 1.1 christos /* VMS: FIX64. */ 2481 1.1 christos if (dyn_i->h != NULL && dyn_i->h->def_dynamic) 2482 1.8 christos { 2483 1.8 christos h_ia64 = (struct elf64_ia64_link_hash_entry *) dyn_i->h; 2484 1.8 christos elf_ia64_vms_tdata (h_ia64->shl)->fixups_off += 2485 1.8 christos sizeof (Elf64_External_VMS_IMAGE_FIXUP); 2486 1.8 christos ia64_info->fixups_sec->size += 2487 1.8 christos sizeof (Elf64_External_VMS_IMAGE_FIXUP); 2488 1.8 christos } 2489 1.1 christos } 2490 1.1 christos 2491 1.1 christos if (ia64_info->rel_fptr_sec && dyn_i->want_fptr) 2492 1.1 christos { 2493 1.1 christos /* VMS: only image reloc. */ 2494 1.1 christos if (dyn_i->h == NULL || dyn_i->h->root.type != bfd_link_hash_undefweak) 2495 1.1 christos ia64_info->rel_fptr_sec->size += sizeof (Elf64_External_Rela); 2496 1.1 christos } 2497 1.1 christos 2498 1.1 christos if (!resolved_zero && dyn_i->want_pltoff) 2499 1.1 christos { 2500 1.1 christos /* VMS: FIXFD. */ 2501 1.1 christos if (dyn_i->h != NULL && dyn_i->h->def_dynamic) 2502 1.8 christos { 2503 1.8 christos h_ia64 = (struct elf64_ia64_link_hash_entry *) dyn_i->h; 2504 1.8 christos elf_ia64_vms_tdata (h_ia64->shl)->fixups_off += 2505 1.8 christos sizeof (Elf64_External_VMS_IMAGE_FIXUP); 2506 1.8 christos ia64_info->fixups_sec->size += 2507 1.8 christos sizeof (Elf64_External_VMS_IMAGE_FIXUP); 2508 1.8 christos } 2509 1.1 christos } 2510 1.1 christos 2511 1.1 christos /* Take care of the normal data relocations. */ 2512 1.1 christos 2513 1.1 christos for (rent = dyn_i->reloc_entries; rent; rent = rent->next) 2514 1.1 christos { 2515 1.1 christos switch (rent->type) 2516 1.1 christos { 2517 1.1 christos case R_IA64_FPTR32LSB: 2518 1.1 christos case R_IA64_FPTR64LSB: 2519 1.1 christos /* Allocate one iff !want_fptr and not PIE, which by this point 2520 1.1 christos will be true only if we're actually allocating one statically 2521 1.1 christos in the main executable. Position independent executables 2522 1.1 christos need a relative reloc. */ 2523 1.6 christos if (dyn_i->want_fptr && !bfd_link_pie (x->info)) 2524 1.1 christos continue; 2525 1.1 christos break; 2526 1.1 christos case R_IA64_PCREL32LSB: 2527 1.1 christos case R_IA64_PCREL64LSB: 2528 1.1 christos if (!dynamic_symbol) 2529 1.1 christos continue; 2530 1.1 christos break; 2531 1.1 christos case R_IA64_DIR32LSB: 2532 1.1 christos case R_IA64_DIR64LSB: 2533 1.1 christos if (!dynamic_symbol && !shared) 2534 1.1 christos continue; 2535 1.1 christos break; 2536 1.1 christos case R_IA64_IPLTLSB: 2537 1.1 christos if (!dynamic_symbol && !shared) 2538 1.1 christos continue; 2539 1.1 christos break; 2540 1.1 christos case R_IA64_DTPREL32LSB: 2541 1.1 christos case R_IA64_TPREL64LSB: 2542 1.1 christos case R_IA64_DTPREL64LSB: 2543 1.1 christos case R_IA64_DTPMOD64LSB: 2544 1.1 christos break; 2545 1.1 christos default: 2546 1.1 christos abort (); 2547 1.1 christos } 2548 1.1 christos 2549 1.1 christos /* Add a fixup. */ 2550 1.1 christos if (!dynamic_symbol) 2551 1.8 christos abort (); 2552 1.1 christos 2553 1.1 christos h_ia64 = (struct elf64_ia64_link_hash_entry *) dyn_i->h; 2554 1.1 christos elf_ia64_vms_tdata (h_ia64->shl)->fixups_off += 2555 1.8 christos sizeof (Elf64_External_VMS_IMAGE_FIXUP); 2556 1.1 christos ia64_info->fixups_sec->size += 2557 1.8 christos sizeof (Elf64_External_VMS_IMAGE_FIXUP); 2558 1.1 christos } 2559 1.1 christos 2560 1.10 christos return true; 2561 1.1 christos } 2562 1.1 christos 2563 1.10 christos static bool 2564 1.1 christos elf64_ia64_adjust_dynamic_symbol (struct bfd_link_info *info ATTRIBUTE_UNUSED, 2565 1.1 christos struct elf_link_hash_entry *h) 2566 1.1 christos { 2567 1.1 christos /* ??? Undefined symbols with PLT entries should be re-defined 2568 1.1 christos to be the PLT entry. */ 2569 1.1 christos 2570 1.1 christos /* If this is a weak symbol, and there is a real definition, the 2571 1.1 christos processor independent code will have arranged for us to see the 2572 1.1 christos real definition first, and we can just use the same value. */ 2573 1.8 christos if (h->is_weakalias) 2574 1.1 christos { 2575 1.8 christos struct elf_link_hash_entry *def = weakdef (h); 2576 1.8 christos BFD_ASSERT (def->root.type == bfd_link_hash_defined); 2577 1.8 christos h->root.u.def.section = def->root.u.def.section; 2578 1.8 christos h->root.u.def.value = def->root.u.def.value; 2579 1.10 christos return true; 2580 1.1 christos } 2581 1.1 christos 2582 1.1 christos /* If this is a reference to a symbol defined by a dynamic object which 2583 1.1 christos is not a function, we might allocate the symbol in our .dynbss section 2584 1.1 christos and allocate a COPY dynamic relocation. 2585 1.1 christos 2586 1.1 christos But IA-64 code is canonically PIC, so as a rule we can avoid this sort 2587 1.1 christos of hackery. */ 2588 1.1 christos 2589 1.10 christos return true; 2590 1.1 christos } 2591 1.1 christos 2592 1.10 christos static bool 2593 1.11 christos elf64_ia64_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED, 2594 1.11 christos struct bfd_link_info *info) 2595 1.1 christos { 2596 1.1 christos struct elf64_ia64_allocate_data data; 2597 1.1 christos struct elf64_ia64_link_hash_table *ia64_info; 2598 1.1 christos asection *sec; 2599 1.1 christos bfd *dynobj; 2600 1.1 christos struct elf_link_hash_table *hash_table; 2601 1.1 christos 2602 1.1 christos hash_table = elf_hash_table (info); 2603 1.1 christos ia64_info = elf64_ia64_hash_table (info); 2604 1.1 christos if (ia64_info == NULL) 2605 1.10 christos return false; 2606 1.11 christos dynobj = hash_table->dynobj; 2607 1.11 christos if (dynobj == NULL) 2608 1.11 christos return true; 2609 1.1 christos data.info = info; 2610 1.1 christos 2611 1.1 christos /* Allocate the GOT entries. */ 2612 1.1 christos 2613 1.1 christos if (ia64_info->root.sgot) 2614 1.1 christos { 2615 1.1 christos data.ofs = 0; 2616 1.1 christos elf64_ia64_dyn_sym_traverse (ia64_info, allocate_global_data_got, &data); 2617 1.1 christos elf64_ia64_dyn_sym_traverse (ia64_info, allocate_global_fptr_got, &data); 2618 1.1 christos elf64_ia64_dyn_sym_traverse (ia64_info, allocate_local_got, &data); 2619 1.1 christos ia64_info->root.sgot->size = data.ofs; 2620 1.1 christos } 2621 1.1 christos 2622 1.1 christos /* Allocate the FPTR entries. */ 2623 1.1 christos 2624 1.1 christos if (ia64_info->fptr_sec) 2625 1.1 christos { 2626 1.1 christos data.ofs = 0; 2627 1.1 christos elf64_ia64_dyn_sym_traverse (ia64_info, allocate_fptr, &data); 2628 1.1 christos ia64_info->fptr_sec->size = data.ofs; 2629 1.1 christos } 2630 1.1 christos 2631 1.1 christos /* Now that we've seen all of the input files, we can decide which 2632 1.1 christos symbols need plt entries. Allocate the minimal PLT entries first. 2633 1.1 christos We do this even though dynamic_sections_created may be FALSE, because 2634 1.1 christos this has the side-effect of clearing want_plt and want_plt2. */ 2635 1.1 christos 2636 1.1 christos data.ofs = 0; 2637 1.1 christos elf64_ia64_dyn_sym_traverse (ia64_info, allocate_plt_entries, &data); 2638 1.1 christos 2639 1.1 christos /* Align the pointer for the plt2 entries. */ 2640 1.1 christos data.ofs = (data.ofs + 31) & (bfd_vma) -32; 2641 1.1 christos 2642 1.1 christos elf64_ia64_dyn_sym_traverse (ia64_info, allocate_plt2_entries, &data); 2643 1.1 christos if (data.ofs != 0 || ia64_info->root.dynamic_sections_created) 2644 1.1 christos { 2645 1.1 christos /* FIXME: we always reserve the memory for dynamic linker even if 2646 1.1 christos there are no PLT entries since dynamic linker may assume the 2647 1.1 christos reserved memory always exists. */ 2648 1.1 christos 2649 1.1 christos BFD_ASSERT (ia64_info->root.dynamic_sections_created); 2650 1.1 christos 2651 1.1 christos ia64_info->root.splt->size = data.ofs; 2652 1.1 christos } 2653 1.1 christos 2654 1.1 christos /* Allocate the PLTOFF entries. */ 2655 1.1 christos 2656 1.1 christos if (ia64_info->pltoff_sec) 2657 1.1 christos { 2658 1.1 christos data.ofs = 0; 2659 1.1 christos elf64_ia64_dyn_sym_traverse (ia64_info, allocate_pltoff_entries, &data); 2660 1.1 christos ia64_info->pltoff_sec->size = data.ofs; 2661 1.1 christos } 2662 1.1 christos 2663 1.1 christos if (ia64_info->root.dynamic_sections_created) 2664 1.1 christos { 2665 1.1 christos /* Allocate space for the dynamic relocations that turned out to be 2666 1.1 christos required. */ 2667 1.1 christos elf64_ia64_dyn_sym_traverse (ia64_info, allocate_dynrel_entries, &data); 2668 1.1 christos } 2669 1.1 christos 2670 1.1 christos /* We have now determined the sizes of the various dynamic sections. 2671 1.1 christos Allocate memory for them. */ 2672 1.1 christos for (sec = dynobj->sections; sec != NULL; sec = sec->next) 2673 1.1 christos { 2674 1.10 christos bool strip; 2675 1.1 christos 2676 1.1 christos if (!(sec->flags & SEC_LINKER_CREATED)) 2677 1.1 christos continue; 2678 1.1 christos 2679 1.1 christos /* If we don't need this section, strip it from the output file. 2680 1.1 christos There were several sections primarily related to dynamic 2681 1.1 christos linking that must be create before the linker maps input 2682 1.1 christos sections to output sections. The linker does that before 2683 1.1 christos bfd_elf_size_dynamic_sections is called, and it is that 2684 1.1 christos function which decides whether anything needs to go into 2685 1.1 christos these sections. */ 2686 1.1 christos 2687 1.1 christos strip = (sec->size == 0); 2688 1.1 christos 2689 1.1 christos if (sec == ia64_info->root.sgot) 2690 1.10 christos strip = false; 2691 1.1 christos else if (sec == ia64_info->root.srelgot) 2692 1.1 christos { 2693 1.1 christos if (strip) 2694 1.1 christos ia64_info->root.srelgot = NULL; 2695 1.1 christos else 2696 1.1 christos /* We use the reloc_count field as a counter if we need to 2697 1.1 christos copy relocs into the output file. */ 2698 1.1 christos sec->reloc_count = 0; 2699 1.1 christos } 2700 1.1 christos else if (sec == ia64_info->fptr_sec) 2701 1.1 christos { 2702 1.1 christos if (strip) 2703 1.1 christos ia64_info->fptr_sec = NULL; 2704 1.1 christos } 2705 1.1 christos else if (sec == ia64_info->rel_fptr_sec) 2706 1.1 christos { 2707 1.1 christos if (strip) 2708 1.1 christos ia64_info->rel_fptr_sec = NULL; 2709 1.1 christos else 2710 1.1 christos /* We use the reloc_count field as a counter if we need to 2711 1.1 christos copy relocs into the output file. */ 2712 1.1 christos sec->reloc_count = 0; 2713 1.1 christos } 2714 1.1 christos else if (sec == ia64_info->root.splt) 2715 1.1 christos { 2716 1.1 christos if (strip) 2717 1.1 christos ia64_info->root.splt = NULL; 2718 1.1 christos } 2719 1.1 christos else if (sec == ia64_info->pltoff_sec) 2720 1.1 christos { 2721 1.1 christos if (strip) 2722 1.1 christos ia64_info->pltoff_sec = NULL; 2723 1.1 christos } 2724 1.1 christos else if (sec == ia64_info->fixups_sec) 2725 1.1 christos { 2726 1.8 christos if (strip) 2727 1.8 christos ia64_info->fixups_sec = NULL; 2728 1.1 christos } 2729 1.1 christos else if (sec == ia64_info->transfer_sec) 2730 1.8 christos { 2731 1.8 christos ; 2732 1.8 christos } 2733 1.1 christos else 2734 1.1 christos { 2735 1.1 christos const char *name; 2736 1.1 christos 2737 1.1 christos /* It's OK to base decisions on the section name, because none 2738 1.1 christos of the dynobj section names depend upon the input files. */ 2739 1.9 christos name = bfd_section_name (sec); 2740 1.1 christos 2741 1.1 christos if (strcmp (name, ".got.plt") == 0) 2742 1.10 christos strip = false; 2743 1.10 christos else if (startswith (name, ".rel")) 2744 1.1 christos { 2745 1.1 christos if (!strip) 2746 1.1 christos { 2747 1.1 christos /* We use the reloc_count field as a counter if we need to 2748 1.1 christos copy relocs into the output file. */ 2749 1.1 christos sec->reloc_count = 0; 2750 1.1 christos } 2751 1.1 christos } 2752 1.1 christos else 2753 1.1 christos continue; 2754 1.1 christos } 2755 1.1 christos 2756 1.1 christos if (strip) 2757 1.1 christos sec->flags |= SEC_EXCLUDE; 2758 1.1 christos else 2759 1.1 christos { 2760 1.1 christos /* Allocate memory for the section contents. */ 2761 1.1 christos sec->contents = (bfd_byte *) bfd_zalloc (dynobj, sec->size); 2762 1.1 christos if (sec->contents == NULL && sec->size != 0) 2763 1.10 christos return false; 2764 1.1 christos } 2765 1.1 christos } 2766 1.1 christos 2767 1.1 christos if (elf_hash_table (info)->dynamic_sections_created) 2768 1.1 christos { 2769 1.1 christos bfd *abfd; 2770 1.1 christos asection *dynsec; 2771 1.1 christos asection *dynstrsec; 2772 1.1 christos Elf_Internal_Dyn dyn; 2773 1.1 christos const struct elf_backend_data *bed; 2774 1.1 christos unsigned int shl_num = 0; 2775 1.1 christos bfd_vma fixups_off = 0; 2776 1.1 christos bfd_vma strdyn_off; 2777 1.1 christos unsigned int time_hi, time_lo; 2778 1.1 christos 2779 1.1 christos /* The .dynamic section must exist and be empty. */ 2780 1.1 christos dynsec = bfd_get_linker_section (hash_table->dynobj, ".dynamic"); 2781 1.1 christos BFD_ASSERT (dynsec != NULL); 2782 1.1 christos BFD_ASSERT (dynsec->size == 0); 2783 1.1 christos 2784 1.1 christos dynstrsec = bfd_get_linker_section (hash_table->dynobj, ".vmsdynstr"); 2785 1.1 christos BFD_ASSERT (dynstrsec != NULL); 2786 1.1 christos BFD_ASSERT (dynstrsec->size == 0); 2787 1.1 christos dynstrsec->size = 1; /* Initial blank. */ 2788 1.1 christos 2789 1.1 christos /* Ident + link time. */ 2790 1.1 christos vms_get_time (&time_hi, &time_lo); 2791 1.1 christos 2792 1.1 christos if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_IDENT, 0)) 2793 1.10 christos return false; 2794 1.1 christos if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_LINKTIME, 2795 1.10 christos ((uint64_t) time_hi << 32) 2796 1.8 christos + time_lo)) 2797 1.10 christos return false; 2798 1.1 christos 2799 1.1 christos /* Strtab. */ 2800 1.1 christos strdyn_off = dynsec->size; 2801 1.1 christos if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_STRTAB_OFFSET, 0)) 2802 1.10 christos return false; 2803 1.1 christos if (!_bfd_elf_add_dynamic_entry (info, DT_STRSZ, 0)) 2804 1.10 christos return false; 2805 1.1 christos 2806 1.1 christos /* PLTGOT */ 2807 1.1 christos if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_PLTGOT_SEG, 0)) 2808 1.10 christos return false; 2809 1.1 christos if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_PLTGOT_OFFSET, 0)) 2810 1.10 christos return false; 2811 1.1 christos 2812 1.1 christos /* Misc. */ 2813 1.1 christos if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_FPMODE, 0x9800000)) 2814 1.10 christos return false; 2815 1.1 christos if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_LNKFLAGS, 2816 1.8 christos VMS_LF_IMGSTA | VMS_LF_MAIN)) 2817 1.10 christos return false; 2818 1.1 christos 2819 1.1 christos /* Add entries for shared libraries. */ 2820 1.3 christos for (abfd = info->input_bfds; abfd; abfd = abfd->link.next) 2821 1.8 christos { 2822 1.8 christos char *soname; 2823 1.8 christos size_t soname_len; 2824 1.8 christos bfd_size_type strindex; 2825 1.8 christos bfd_byte *newcontents; 2826 1.8 christos bfd_vma fixups_shl_off; 2827 1.8 christos 2828 1.8 christos if (!(abfd->flags & DYNAMIC)) 2829 1.8 christos continue; 2830 1.8 christos BFD_ASSERT (abfd->xvec == output_bfd->xvec); 2831 1.8 christos 2832 1.8 christos if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_NEEDED_IDENT, 2833 1.8 christos elf_ia64_vms_ident (abfd))) 2834 1.10 christos return false; 2835 1.8 christos 2836 1.10 christos soname = vms_get_module_name (bfd_get_filename (abfd), true); 2837 1.8 christos if (soname == NULL) 2838 1.10 christos return false; 2839 1.8 christos strindex = dynstrsec->size; 2840 1.8 christos soname_len = strlen (soname) + 1; 2841 1.8 christos newcontents = (bfd_byte *) bfd_realloc (dynstrsec->contents, 2842 1.8 christos strindex + soname_len); 2843 1.8 christos if (newcontents == NULL) 2844 1.10 christos return false; 2845 1.8 christos memcpy (newcontents + strindex, soname, soname_len); 2846 1.8 christos dynstrsec->size += soname_len; 2847 1.8 christos dynstrsec->contents = newcontents; 2848 1.8 christos 2849 1.8 christos if (!_bfd_elf_add_dynamic_entry (info, DT_NEEDED, strindex)) 2850 1.10 christos return false; 2851 1.8 christos 2852 1.8 christos if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_FIXUP_NEEDED, 2853 1.8 christos shl_num)) 2854 1.10 christos return false; 2855 1.8 christos shl_num++; 2856 1.8 christos 2857 1.8 christos /* The fixups_off was in fact containing the size of the fixup 2858 1.8 christos section. Remap into the offset. */ 2859 1.8 christos fixups_shl_off = elf_ia64_vms_tdata (abfd)->fixups_off; 2860 1.8 christos elf_ia64_vms_tdata (abfd)->fixups_off = fixups_off; 2861 1.8 christos 2862 1.8 christos if (!_bfd_elf_add_dynamic_entry 2863 1.8 christos (info, DT_IA_64_VMS_FIXUP_RELA_CNT, 2864 1.8 christos fixups_shl_off / sizeof (Elf64_External_VMS_IMAGE_FIXUP))) 2865 1.10 christos return false; 2866 1.8 christos if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_FIXUP_RELA_OFF, 2867 1.8 christos fixups_off)) 2868 1.10 christos return false; 2869 1.8 christos fixups_off += fixups_shl_off; 2870 1.8 christos } 2871 1.1 christos 2872 1.1 christos /* Unwind. */ 2873 1.1 christos if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_UNWINDSZ, 0)) 2874 1.10 christos return false; 2875 1.1 christos if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_UNWIND_CODSEG, 0)) 2876 1.10 christos return false; 2877 1.1 christos if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_UNWIND_INFOSEG, 0)) 2878 1.10 christos return false; 2879 1.1 christos if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_UNWIND_OFFSET, 0)) 2880 1.10 christos return false; 2881 1.1 christos if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_UNWIND_SEG, 0)) 2882 1.10 christos return false; 2883 1.1 christos 2884 1.1 christos if (!_bfd_elf_add_dynamic_entry (info, DT_NULL, 0xdead)) 2885 1.10 christos return false; 2886 1.1 christos 2887 1.1 christos /* Fix the strtab entries. */ 2888 1.1 christos bed = get_elf_backend_data (hash_table->dynobj); 2889 1.1 christos 2890 1.1 christos if (dynstrsec->size > 1) 2891 1.8 christos dynstrsec->contents[0] = 0; 2892 1.1 christos else 2893 1.8 christos dynstrsec->size = 0; 2894 1.1 christos 2895 1.1 christos /* Note: one 'spare' (ie DT_NULL) entry is added by 2896 1.8 christos bfd_elf_size_dynsym_hash_dynstr. */ 2897 1.1 christos dyn.d_tag = DT_IA_64_VMS_STRTAB_OFFSET; 2898 1.1 christos dyn.d_un.d_val = dynsec->size /* + sizeof (Elf64_External_Dyn) */; 2899 1.1 christos bed->s->swap_dyn_out (hash_table->dynobj, &dyn, 2900 1.8 christos dynsec->contents + strdyn_off); 2901 1.1 christos 2902 1.1 christos dyn.d_tag = DT_STRSZ; 2903 1.1 christos dyn.d_un.d_val = dynstrsec->size; 2904 1.1 christos bed->s->swap_dyn_out (hash_table->dynobj, &dyn, 2905 1.8 christos dynsec->contents + strdyn_off + bed->s->sizeof_dyn); 2906 1.1 christos 2907 1.1 christos elf_ia64_vms_tdata (output_bfd)->needed_count = shl_num; 2908 1.1 christos 2909 1.1 christos /* Note section. */ 2910 1.1 christos if (!create_ia64_vms_notes (output_bfd, info, time_hi, time_lo)) 2911 1.10 christos return false; 2912 1.1 christos } 2913 1.1 christos 2914 1.1 christos /* ??? Perhaps force __gp local. */ 2915 1.1 christos 2916 1.10 christos return true; 2917 1.1 christos } 2918 1.1 christos 2919 1.1 christos static void 2920 1.1 christos elf64_ia64_install_fixup (bfd *output_bfd, 2921 1.8 christos struct elf64_ia64_link_hash_table *ia64_info, 2922 1.8 christos struct elf_link_hash_entry *h, 2923 1.8 christos unsigned int type, asection *sec, bfd_vma offset, 2924 1.8 christos bfd_vma addend) 2925 1.1 christos { 2926 1.1 christos asection *relsec; 2927 1.1 christos Elf64_External_VMS_IMAGE_FIXUP *fixup; 2928 1.1 christos struct elf64_ia64_link_hash_entry *h_ia64; 2929 1.1 christos bfd_vma fixoff; 2930 1.1 christos Elf_Internal_Phdr *phdr; 2931 1.1 christos 2932 1.1 christos if (h == NULL || !h->def_dynamic) 2933 1.1 christos abort (); 2934 1.1 christos 2935 1.1 christos h_ia64 = (struct elf64_ia64_link_hash_entry *) h; 2936 1.1 christos fixoff = elf_ia64_vms_tdata (h_ia64->shl)->fixups_off; 2937 1.1 christos elf_ia64_vms_tdata (h_ia64->shl)->fixups_off += 2938 1.1 christos sizeof (Elf64_External_VMS_IMAGE_FIXUP); 2939 1.1 christos relsec = ia64_info->fixups_sec; 2940 1.1 christos 2941 1.1 christos fixup = (Elf64_External_VMS_IMAGE_FIXUP *)(relsec->contents + fixoff); 2942 1.1 christos offset += sec->output_section->vma + sec->output_offset; 2943 1.1 christos 2944 1.1 christos /* FIXME: this is slow. We should cache the last one used, or create a 2945 1.1 christos map. */ 2946 1.1 christos phdr = _bfd_elf_find_segment_containing_section 2947 1.1 christos (output_bfd, sec->output_section); 2948 1.1 christos BFD_ASSERT (phdr != NULL); 2949 1.1 christos 2950 1.1 christos bfd_putl64 (offset - phdr->p_vaddr, fixup->fixup_offset); 2951 1.1 christos bfd_putl32 (type, fixup->type); 2952 1.1 christos bfd_putl32 (phdr - elf_tdata (output_bfd)->phdr, fixup->fixup_seg); 2953 1.1 christos bfd_putl64 (addend, fixup->addend); 2954 1.1 christos bfd_putl32 (h->root.u.def.value, fixup->symvec_index); 2955 1.1 christos bfd_putl32 (2, fixup->data_type); 2956 1.1 christos } 2957 1.1 christos 2958 1.1 christos /* Store an entry for target address TARGET_ADDR in the linkage table 2959 1.1 christos and return the gp-relative address of the linkage table entry. */ 2960 1.1 christos 2961 1.1 christos static bfd_vma 2962 1.1 christos set_got_entry (bfd *abfd, struct bfd_link_info *info, 2963 1.1 christos struct elf64_ia64_dyn_sym_info *dyn_i, 2964 1.1 christos bfd_vma addend, bfd_vma value, unsigned int dyn_r_type) 2965 1.1 christos { 2966 1.1 christos struct elf64_ia64_link_hash_table *ia64_info; 2967 1.1 christos asection *got_sec; 2968 1.10 christos bool done; 2969 1.1 christos bfd_vma got_offset; 2970 1.1 christos 2971 1.1 christos ia64_info = elf64_ia64_hash_table (info); 2972 1.1 christos if (ia64_info == NULL) 2973 1.1 christos return 0; 2974 1.1 christos 2975 1.1 christos got_sec = ia64_info->root.sgot; 2976 1.1 christos 2977 1.1 christos switch (dyn_r_type) 2978 1.1 christos { 2979 1.1 christos case R_IA64_TPREL64LSB: 2980 1.1 christos case R_IA64_DTPMOD64LSB: 2981 1.1 christos case R_IA64_DTPREL32LSB: 2982 1.1 christos case R_IA64_DTPREL64LSB: 2983 1.1 christos abort (); 2984 1.1 christos break; 2985 1.1 christos default: 2986 1.1 christos done = dyn_i->got_done; 2987 1.10 christos dyn_i->got_done = true; 2988 1.1 christos got_offset = dyn_i->got_offset; 2989 1.1 christos break; 2990 1.1 christos } 2991 1.1 christos 2992 1.1 christos BFD_ASSERT ((got_offset & 7) == 0); 2993 1.1 christos 2994 1.1 christos if (! done) 2995 1.1 christos { 2996 1.1 christos /* Store the target address in the linkage table entry. */ 2997 1.1 christos bfd_put_64 (abfd, value, got_sec->contents + got_offset); 2998 1.1 christos 2999 1.1 christos /* Install a dynamic relocation if needed. */ 3000 1.6 christos if (((bfd_link_pic (info) 3001 1.1 christos && (!dyn_i->h 3002 1.1 christos || ELF_ST_VISIBILITY (dyn_i->h->other) == STV_DEFAULT 3003 1.1 christos || dyn_i->h->root.type != bfd_link_hash_undefweak)) 3004 1.8 christos || elf64_ia64_dynamic_symbol_p (dyn_i->h)) 3005 1.1 christos && (!dyn_i->want_ltoff_fptr 3006 1.6 christos || !bfd_link_pie (info) 3007 1.1 christos || !dyn_i->h 3008 1.1 christos || dyn_i->h->root.type != bfd_link_hash_undefweak)) 3009 1.1 christos { 3010 1.1 christos if (!dyn_i->h || !dyn_i->h->def_dynamic) 3011 1.1 christos { 3012 1.1 christos dyn_r_type = R_IA64_REL64LSB; 3013 1.1 christos addend = value; 3014 1.1 christos } 3015 1.1 christos 3016 1.8 christos /* VMS: install a FIX32 or FIX64. */ 3017 1.8 christos switch (dyn_r_type) 3018 1.8 christos { 3019 1.8 christos case R_IA64_DIR32LSB: 3020 1.8 christos case R_IA64_FPTR32LSB: 3021 1.8 christos dyn_r_type = R_IA64_VMS_FIX32; 3022 1.8 christos break; 3023 1.8 christos case R_IA64_DIR64LSB: 3024 1.8 christos case R_IA64_FPTR64LSB: 3025 1.8 christos dyn_r_type = R_IA64_VMS_FIX64; 3026 1.8 christos break; 3027 1.8 christos default: 3028 1.10 christos BFD_ASSERT (false); 3029 1.8 christos break; 3030 1.8 christos } 3031 1.8 christos elf64_ia64_install_fixup 3032 1.8 christos (info->output_bfd, ia64_info, dyn_i->h, 3033 1.8 christos dyn_r_type, got_sec, got_offset, addend); 3034 1.8 christos } 3035 1.1 christos } 3036 1.1 christos 3037 1.1 christos /* Return the address of the linkage table entry. */ 3038 1.1 christos value = (got_sec->output_section->vma 3039 1.1 christos + got_sec->output_offset 3040 1.1 christos + got_offset); 3041 1.1 christos 3042 1.1 christos return value; 3043 1.1 christos } 3044 1.1 christos 3045 1.1 christos /* Fill in a function descriptor consisting of the function's code 3046 1.1 christos address and its global pointer. Return the descriptor's address. */ 3047 1.1 christos 3048 1.1 christos static bfd_vma 3049 1.1 christos set_fptr_entry (bfd *abfd, struct bfd_link_info *info, 3050 1.1 christos struct elf64_ia64_dyn_sym_info *dyn_i, 3051 1.1 christos bfd_vma value) 3052 1.1 christos { 3053 1.1 christos struct elf64_ia64_link_hash_table *ia64_info; 3054 1.1 christos asection *fptr_sec; 3055 1.1 christos 3056 1.1 christos ia64_info = elf64_ia64_hash_table (info); 3057 1.1 christos if (ia64_info == NULL) 3058 1.1 christos return 0; 3059 1.1 christos 3060 1.1 christos fptr_sec = ia64_info->fptr_sec; 3061 1.1 christos 3062 1.1 christos if (!dyn_i->fptr_done) 3063 1.1 christos { 3064 1.1 christos dyn_i->fptr_done = 1; 3065 1.1 christos 3066 1.1 christos /* Fill in the function descriptor. */ 3067 1.1 christos bfd_put_64 (abfd, value, fptr_sec->contents + dyn_i->fptr_offset); 3068 1.1 christos bfd_put_64 (abfd, _bfd_get_gp_value (abfd), 3069 1.1 christos fptr_sec->contents + dyn_i->fptr_offset + 8); 3070 1.1 christos } 3071 1.1 christos 3072 1.1 christos /* Return the descriptor's address. */ 3073 1.1 christos value = (fptr_sec->output_section->vma 3074 1.1 christos + fptr_sec->output_offset 3075 1.1 christos + dyn_i->fptr_offset); 3076 1.1 christos 3077 1.1 christos return value; 3078 1.1 christos } 3079 1.1 christos 3080 1.1 christos /* Fill in a PLTOFF entry consisting of the function's code address 3081 1.1 christos and its global pointer. Return the descriptor's address. */ 3082 1.1 christos 3083 1.1 christos static bfd_vma 3084 1.1 christos set_pltoff_entry (bfd *abfd, struct bfd_link_info *info, 3085 1.1 christos struct elf64_ia64_dyn_sym_info *dyn_i, 3086 1.10 christos bfd_vma value, bool is_plt) 3087 1.1 christos { 3088 1.1 christos struct elf64_ia64_link_hash_table *ia64_info; 3089 1.1 christos asection *pltoff_sec; 3090 1.1 christos 3091 1.1 christos ia64_info = elf64_ia64_hash_table (info); 3092 1.1 christos if (ia64_info == NULL) 3093 1.1 christos return 0; 3094 1.1 christos 3095 1.1 christos pltoff_sec = ia64_info->pltoff_sec; 3096 1.1 christos 3097 1.1 christos /* Don't do anything if this symbol uses a real PLT entry. In 3098 1.1 christos that case, we'll fill this in during finish_dynamic_symbol. */ 3099 1.1 christos if ((! dyn_i->want_plt || is_plt) 3100 1.1 christos && !dyn_i->pltoff_done) 3101 1.1 christos { 3102 1.1 christos bfd_vma gp = _bfd_get_gp_value (abfd); 3103 1.1 christos 3104 1.1 christos /* Fill in the function descriptor. */ 3105 1.1 christos bfd_put_64 (abfd, value, pltoff_sec->contents + dyn_i->pltoff_offset); 3106 1.1 christos bfd_put_64 (abfd, gp, pltoff_sec->contents + dyn_i->pltoff_offset + 8); 3107 1.1 christos 3108 1.1 christos /* Install dynamic relocations if needed. */ 3109 1.1 christos if (!is_plt 3110 1.6 christos && bfd_link_pic (info) 3111 1.1 christos && (!dyn_i->h 3112 1.1 christos || ELF_ST_VISIBILITY (dyn_i->h->other) == STV_DEFAULT 3113 1.1 christos || dyn_i->h->root.type != bfd_link_hash_undefweak)) 3114 1.1 christos { 3115 1.8 christos /* VMS: */ 3116 1.8 christos abort (); 3117 1.1 christos } 3118 1.1 christos 3119 1.1 christos dyn_i->pltoff_done = 1; 3120 1.1 christos } 3121 1.1 christos 3122 1.1 christos /* Return the descriptor's address. */ 3123 1.1 christos value = (pltoff_sec->output_section->vma 3124 1.1 christos + pltoff_sec->output_offset 3125 1.1 christos + dyn_i->pltoff_offset); 3126 1.1 christos 3127 1.1 christos return value; 3128 1.1 christos } 3129 1.1 christos 3130 1.1 christos /* Called through qsort to sort the .IA_64.unwind section during a 3131 1.1 christos non-relocatable link. Set elf64_ia64_unwind_entry_compare_bfd 3132 1.1 christos to the output bfd so we can do proper endianness frobbing. */ 3133 1.1 christos 3134 1.1 christos static bfd *elf64_ia64_unwind_entry_compare_bfd; 3135 1.1 christos 3136 1.1 christos static int 3137 1.1 christos elf64_ia64_unwind_entry_compare (const void * a, const void * b) 3138 1.1 christos { 3139 1.1 christos bfd_vma av, bv; 3140 1.1 christos 3141 1.1 christos av = bfd_get_64 (elf64_ia64_unwind_entry_compare_bfd, a); 3142 1.1 christos bv = bfd_get_64 (elf64_ia64_unwind_entry_compare_bfd, b); 3143 1.1 christos 3144 1.1 christos return (av < bv ? -1 : av > bv ? 1 : 0); 3145 1.1 christos } 3146 1.1 christos 3147 1.1 christos /* Make sure we've got ourselves a nice fat __gp value. */ 3148 1.10 christos static bool 3149 1.10 christos elf64_ia64_choose_gp (bfd *abfd, struct bfd_link_info *info, bool final) 3150 1.1 christos { 3151 1.1 christos bfd_vma min_vma = (bfd_vma) -1, max_vma = 0; 3152 1.1 christos bfd_vma min_short_vma = min_vma, max_short_vma = 0; 3153 1.1 christos struct elf_link_hash_entry *gp; 3154 1.1 christos bfd_vma gp_val; 3155 1.1 christos asection *os; 3156 1.1 christos struct elf64_ia64_link_hash_table *ia64_info; 3157 1.1 christos 3158 1.1 christos ia64_info = elf64_ia64_hash_table (info); 3159 1.1 christos if (ia64_info == NULL) 3160 1.10 christos return false; 3161 1.1 christos 3162 1.1 christos /* Find the min and max vma of all sections marked short. Also collect 3163 1.1 christos min and max vma of any type, for use in selecting a nice gp. */ 3164 1.1 christos for (os = abfd->sections; os ; os = os->next) 3165 1.1 christos { 3166 1.1 christos bfd_vma lo, hi; 3167 1.1 christos 3168 1.1 christos if ((os->flags & SEC_ALLOC) == 0) 3169 1.1 christos continue; 3170 1.1 christos 3171 1.1 christos lo = os->vma; 3172 1.1 christos /* When this function is called from elfNN_ia64_final_link 3173 1.1 christos the correct value to use is os->size. When called from 3174 1.1 christos elfNN_ia64_relax_section we are in the middle of section 3175 1.1 christos sizing; some sections will already have os->size set, others 3176 1.1 christos will have os->size zero and os->rawsize the previous size. */ 3177 1.1 christos hi = os->vma + (!final && os->rawsize ? os->rawsize : os->size); 3178 1.1 christos if (hi < lo) 3179 1.1 christos hi = (bfd_vma) -1; 3180 1.1 christos 3181 1.1 christos if (min_vma > lo) 3182 1.1 christos min_vma = lo; 3183 1.1 christos if (max_vma < hi) 3184 1.1 christos max_vma = hi; 3185 1.1 christos if (os->flags & SEC_SMALL_DATA) 3186 1.1 christos { 3187 1.1 christos if (min_short_vma > lo) 3188 1.1 christos min_short_vma = lo; 3189 1.1 christos if (max_short_vma < hi) 3190 1.1 christos max_short_vma = hi; 3191 1.1 christos } 3192 1.1 christos } 3193 1.1 christos 3194 1.1 christos if (ia64_info->min_short_sec) 3195 1.1 christos { 3196 1.1 christos if (min_short_vma 3197 1.1 christos > (ia64_info->min_short_sec->vma 3198 1.1 christos + ia64_info->min_short_offset)) 3199 1.1 christos min_short_vma = (ia64_info->min_short_sec->vma 3200 1.1 christos + ia64_info->min_short_offset); 3201 1.1 christos if (max_short_vma 3202 1.1 christos < (ia64_info->max_short_sec->vma 3203 1.1 christos + ia64_info->max_short_offset)) 3204 1.1 christos max_short_vma = (ia64_info->max_short_sec->vma 3205 1.1 christos + ia64_info->max_short_offset); 3206 1.1 christos } 3207 1.1 christos 3208 1.1 christos /* See if the user wants to force a value. */ 3209 1.10 christos gp = elf_link_hash_lookup (elf_hash_table (info), "__gp", false, 3210 1.10 christos false, false); 3211 1.1 christos 3212 1.1 christos if (gp 3213 1.1 christos && (gp->root.type == bfd_link_hash_defined 3214 1.1 christos || gp->root.type == bfd_link_hash_defweak)) 3215 1.1 christos { 3216 1.1 christos asection *gp_sec = gp->root.u.def.section; 3217 1.1 christos gp_val = (gp->root.u.def.value 3218 1.1 christos + gp_sec->output_section->vma 3219 1.1 christos + gp_sec->output_offset); 3220 1.1 christos } 3221 1.1 christos else 3222 1.1 christos { 3223 1.1 christos /* Pick a sensible value. */ 3224 1.1 christos 3225 1.1 christos if (ia64_info->min_short_sec) 3226 1.1 christos { 3227 1.1 christos bfd_vma short_range = max_short_vma - min_short_vma; 3228 1.1 christos 3229 1.1 christos /* If min_short_sec is set, pick one in the middle bewteen 3230 1.1 christos min_short_vma and max_short_vma. */ 3231 1.1 christos if (short_range >= 0x400000) 3232 1.1 christos goto overflow; 3233 1.1 christos gp_val = min_short_vma + short_range / 2; 3234 1.1 christos } 3235 1.1 christos else 3236 1.1 christos { 3237 1.1 christos asection *got_sec = ia64_info->root.sgot; 3238 1.1 christos 3239 1.1 christos /* Start with just the address of the .got. */ 3240 1.1 christos if (got_sec) 3241 1.1 christos gp_val = got_sec->output_section->vma; 3242 1.1 christos else if (max_short_vma != 0) 3243 1.1 christos gp_val = min_short_vma; 3244 1.1 christos else if (max_vma - min_vma < 0x200000) 3245 1.1 christos gp_val = min_vma; 3246 1.1 christos else 3247 1.1 christos gp_val = max_vma - 0x200000 + 8; 3248 1.1 christos } 3249 1.1 christos 3250 1.1 christos /* If it is possible to address the entire image, but we 3251 1.1 christos don't with the choice above, adjust. */ 3252 1.1 christos if (max_vma - min_vma < 0x400000 3253 1.1 christos && (max_vma - gp_val >= 0x200000 3254 1.1 christos || gp_val - min_vma > 0x200000)) 3255 1.1 christos gp_val = min_vma + 0x200000; 3256 1.1 christos else if (max_short_vma != 0) 3257 1.1 christos { 3258 1.1 christos /* If we don't cover all the short data, adjust. */ 3259 1.1 christos if (max_short_vma - gp_val >= 0x200000) 3260 1.1 christos gp_val = min_short_vma + 0x200000; 3261 1.1 christos 3262 1.1 christos /* If we're addressing stuff past the end, adjust back. */ 3263 1.1 christos if (gp_val > max_vma) 3264 1.1 christos gp_val = max_vma - 0x200000 + 8; 3265 1.1 christos } 3266 1.1 christos } 3267 1.1 christos 3268 1.1 christos /* Validate whether all SHF_IA_64_SHORT sections are within 3269 1.1 christos range of the chosen GP. */ 3270 1.1 christos 3271 1.1 christos if (max_short_vma != 0) 3272 1.1 christos { 3273 1.1 christos if (max_short_vma - min_short_vma >= 0x400000) 3274 1.1 christos { 3275 1.9 christos overflow: 3276 1.7 christos _bfd_error_handler 3277 1.7 christos /* xgettext:c-format */ 3278 1.8 christos (_("%pB: short data segment overflowed (%#" PRIx64 " >= 0x400000)"), 3279 1.8 christos abfd, (uint64_t) (max_short_vma - min_short_vma)); 3280 1.10 christos return false; 3281 1.1 christos } 3282 1.1 christos else if ((gp_val > min_short_vma 3283 1.1 christos && gp_val - min_short_vma > 0x200000) 3284 1.1 christos || (gp_val < max_short_vma 3285 1.1 christos && max_short_vma - gp_val >= 0x200000)) 3286 1.1 christos { 3287 1.7 christos _bfd_error_handler 3288 1.8 christos (_("%pB: __gp does not cover short data segment"), abfd); 3289 1.10 christos return false; 3290 1.1 christos } 3291 1.1 christos } 3292 1.1 christos 3293 1.1 christos _bfd_set_gp_value (abfd, gp_val); 3294 1.1 christos 3295 1.10 christos return true; 3296 1.1 christos } 3297 1.1 christos 3298 1.10 christos static bool 3299 1.1 christos elf64_ia64_final_link (bfd *abfd, struct bfd_link_info *info) 3300 1.1 christos { 3301 1.1 christos struct elf64_ia64_link_hash_table *ia64_info; 3302 1.1 christos asection *unwind_output_sec; 3303 1.1 christos 3304 1.1 christos ia64_info = elf64_ia64_hash_table (info); 3305 1.1 christos if (ia64_info == NULL) 3306 1.10 christos return false; 3307 1.1 christos 3308 1.1 christos /* Make sure we've got ourselves a nice fat __gp value. */ 3309 1.6 christos if (!bfd_link_relocatable (info)) 3310 1.1 christos { 3311 1.1 christos bfd_vma gp_val; 3312 1.1 christos struct elf_link_hash_entry *gp; 3313 1.1 christos 3314 1.1 christos /* We assume after gp is set, section size will only decrease. We 3315 1.1 christos need to adjust gp for it. */ 3316 1.1 christos _bfd_set_gp_value (abfd, 0); 3317 1.10 christos if (! elf64_ia64_choose_gp (abfd, info, true)) 3318 1.10 christos return false; 3319 1.1 christos gp_val = _bfd_get_gp_value (abfd); 3320 1.1 christos 3321 1.10 christos gp = elf_link_hash_lookup (elf_hash_table (info), "__gp", false, 3322 1.10 christos false, false); 3323 1.1 christos if (gp) 3324 1.1 christos { 3325 1.1 christos gp->root.type = bfd_link_hash_defined; 3326 1.1 christos gp->root.u.def.value = gp_val; 3327 1.1 christos gp->root.u.def.section = bfd_abs_section_ptr; 3328 1.1 christos } 3329 1.1 christos } 3330 1.1 christos 3331 1.1 christos /* If we're producing a final executable, we need to sort the contents 3332 1.1 christos of the .IA_64.unwind section. Force this section to be relocated 3333 1.1 christos into memory rather than written immediately to the output file. */ 3334 1.1 christos unwind_output_sec = NULL; 3335 1.6 christos if (!bfd_link_relocatable (info)) 3336 1.1 christos { 3337 1.1 christos asection *s = bfd_get_section_by_name (abfd, ELF_STRING_ia64_unwind); 3338 1.1 christos if (s) 3339 1.1 christos { 3340 1.1 christos unwind_output_sec = s->output_section; 3341 1.1 christos unwind_output_sec->contents 3342 1.1 christos = bfd_malloc (unwind_output_sec->size); 3343 1.1 christos if (unwind_output_sec->contents == NULL) 3344 1.10 christos return false; 3345 1.1 christos } 3346 1.1 christos } 3347 1.1 christos 3348 1.1 christos /* Invoke the regular ELF backend linker to do all the work. */ 3349 1.1 christos if (!bfd_elf_final_link (abfd, info)) 3350 1.10 christos return false; 3351 1.1 christos 3352 1.1 christos if (unwind_output_sec) 3353 1.1 christos { 3354 1.1 christos elf64_ia64_unwind_entry_compare_bfd = abfd; 3355 1.1 christos qsort (unwind_output_sec->contents, 3356 1.1 christos (size_t) (unwind_output_sec->size / 24), 3357 1.1 christos 24, 3358 1.1 christos elf64_ia64_unwind_entry_compare); 3359 1.1 christos 3360 1.1 christos if (! bfd_set_section_contents (abfd, unwind_output_sec, 3361 1.1 christos unwind_output_sec->contents, (bfd_vma) 0, 3362 1.1 christos unwind_output_sec->size)) 3363 1.10 christos return false; 3364 1.1 christos } 3365 1.1 christos 3366 1.10 christos return true; 3367 1.1 christos } 3368 1.1 christos 3369 1.10 christos static int 3370 1.1 christos elf64_ia64_relocate_section (bfd *output_bfd, 3371 1.1 christos struct bfd_link_info *info, 3372 1.1 christos bfd *input_bfd, 3373 1.1 christos asection *input_section, 3374 1.1 christos bfd_byte *contents, 3375 1.1 christos Elf_Internal_Rela *relocs, 3376 1.1 christos Elf_Internal_Sym *local_syms, 3377 1.1 christos asection **local_sections) 3378 1.1 christos { 3379 1.1 christos struct elf64_ia64_link_hash_table *ia64_info; 3380 1.1 christos Elf_Internal_Shdr *symtab_hdr; 3381 1.1 christos Elf_Internal_Rela *rel; 3382 1.1 christos Elf_Internal_Rela *relend; 3383 1.10 christos bool ret_val = true; /* for non-fatal errors */ 3384 1.1 christos bfd_vma gp_val; 3385 1.1 christos 3386 1.1 christos symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; 3387 1.1 christos ia64_info = elf64_ia64_hash_table (info); 3388 1.1 christos if (ia64_info == NULL) 3389 1.10 christos return false; 3390 1.1 christos 3391 1.1 christos /* Infect various flags from the input section to the output section. */ 3392 1.6 christos if (bfd_link_relocatable (info)) 3393 1.1 christos { 3394 1.1 christos bfd_vma flags; 3395 1.1 christos 3396 1.1 christos flags = elf_section_data(input_section)->this_hdr.sh_flags; 3397 1.1 christos flags &= SHF_IA_64_NORECOV; 3398 1.1 christos 3399 1.1 christos elf_section_data(input_section->output_section) 3400 1.1 christos ->this_hdr.sh_flags |= flags; 3401 1.1 christos } 3402 1.1 christos 3403 1.1 christos gp_val = _bfd_get_gp_value (output_bfd); 3404 1.1 christos 3405 1.1 christos rel = relocs; 3406 1.1 christos relend = relocs + input_section->reloc_count; 3407 1.1 christos for (; rel < relend; ++rel) 3408 1.1 christos { 3409 1.1 christos struct elf_link_hash_entry *h; 3410 1.1 christos struct elf64_ia64_dyn_sym_info *dyn_i; 3411 1.1 christos bfd_reloc_status_type r; 3412 1.1 christos reloc_howto_type *howto; 3413 1.1 christos unsigned long r_symndx; 3414 1.1 christos Elf_Internal_Sym *sym; 3415 1.1 christos unsigned int r_type; 3416 1.1 christos bfd_vma value; 3417 1.1 christos asection *sym_sec; 3418 1.1 christos bfd_byte *hit_addr; 3419 1.10 christos bool dynamic_symbol_p; 3420 1.10 christos bool undef_weak_ref; 3421 1.1 christos 3422 1.1 christos r_type = ELF64_R_TYPE (rel->r_info); 3423 1.1 christos if (r_type > R_IA64_MAX_RELOC_CODE) 3424 1.1 christos { 3425 1.8 christos /* xgettext:c-format */ 3426 1.8 christos _bfd_error_handler (_("%pB: unsupported relocation type %#x"), 3427 1.8 christos input_bfd, (int) r_type); 3428 1.1 christos bfd_set_error (bfd_error_bad_value); 3429 1.10 christos ret_val = false; 3430 1.1 christos continue; 3431 1.1 christos } 3432 1.1 christos 3433 1.1 christos howto = ia64_elf_lookup_howto (r_type); 3434 1.8 christos if (howto == NULL) 3435 1.8 christos { 3436 1.10 christos ret_val = false; 3437 1.8 christos continue; 3438 1.8 christos } 3439 1.1 christos r_symndx = ELF64_R_SYM (rel->r_info); 3440 1.1 christos h = NULL; 3441 1.1 christos sym = NULL; 3442 1.1 christos sym_sec = NULL; 3443 1.10 christos undef_weak_ref = false; 3444 1.1 christos 3445 1.1 christos if (r_symndx < symtab_hdr->sh_info) 3446 1.1 christos { 3447 1.1 christos /* Reloc against local symbol. */ 3448 1.1 christos asection *msec; 3449 1.1 christos sym = local_syms + r_symndx; 3450 1.1 christos sym_sec = local_sections[r_symndx]; 3451 1.1 christos msec = sym_sec; 3452 1.1 christos value = _bfd_elf_rela_local_sym (output_bfd, sym, &msec, rel); 3453 1.6 christos if (!bfd_link_relocatable (info) 3454 1.1 christos && (sym_sec->flags & SEC_MERGE) != 0 3455 1.1 christos && ELF_ST_TYPE (sym->st_info) == STT_SECTION 3456 1.1 christos && sym_sec->sec_info_type == SEC_INFO_TYPE_MERGE) 3457 1.1 christos { 3458 1.1 christos struct elf64_ia64_local_hash_entry *loc_h; 3459 1.1 christos 3460 1.10 christos loc_h = get_local_sym_hash (ia64_info, input_bfd, rel, false); 3461 1.1 christos if (loc_h && ! loc_h->sec_merge_done) 3462 1.1 christos { 3463 1.1 christos struct elf64_ia64_dyn_sym_info *dynent; 3464 1.1 christos unsigned int count; 3465 1.1 christos 3466 1.1 christos for (count = loc_h->count, dynent = loc_h->info; 3467 1.1 christos count != 0; 3468 1.1 christos count--, dynent++) 3469 1.1 christos { 3470 1.1 christos msec = sym_sec; 3471 1.1 christos dynent->addend = 3472 1.1 christos _bfd_merged_section_offset (output_bfd, &msec, 3473 1.1 christos elf_section_data (msec)-> 3474 1.1 christos sec_info, 3475 1.1 christos sym->st_value 3476 1.1 christos + dynent->addend); 3477 1.1 christos dynent->addend -= sym->st_value; 3478 1.1 christos dynent->addend += msec->output_section->vma 3479 1.1 christos + msec->output_offset 3480 1.1 christos - sym_sec->output_section->vma 3481 1.1 christos - sym_sec->output_offset; 3482 1.1 christos } 3483 1.1 christos 3484 1.1 christos /* We may have introduced duplicated entries. We need 3485 1.1 christos to remove them properly. */ 3486 1.1 christos count = sort_dyn_sym_info (loc_h->info, loc_h->count); 3487 1.1 christos if (count != loc_h->count) 3488 1.1 christos { 3489 1.1 christos loc_h->count = count; 3490 1.1 christos loc_h->sorted_count = count; 3491 1.1 christos } 3492 1.1 christos 3493 1.1 christos loc_h->sec_merge_done = 1; 3494 1.1 christos } 3495 1.1 christos } 3496 1.1 christos } 3497 1.1 christos else 3498 1.1 christos { 3499 1.10 christos bool unresolved_reloc; 3500 1.10 christos bool warned, ignored; 3501 1.1 christos struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd); 3502 1.1 christos 3503 1.1 christos RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, 3504 1.1 christos r_symndx, symtab_hdr, sym_hashes, 3505 1.1 christos h, sym_sec, value, 3506 1.1 christos unresolved_reloc, warned, ignored); 3507 1.1 christos 3508 1.1 christos if (h->root.type == bfd_link_hash_undefweak) 3509 1.10 christos undef_weak_ref = true; 3510 1.1 christos else if (warned) 3511 1.1 christos continue; 3512 1.1 christos } 3513 1.1 christos 3514 1.1 christos /* For relocs against symbols from removed linkonce sections, 3515 1.1 christos or sections discarded by a linker script, we just want the 3516 1.1 christos section contents zeroed. Avoid any special processing. */ 3517 1.1 christos if (sym_sec != NULL && discarded_section (sym_sec)) 3518 1.1 christos RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, 3519 1.1 christos rel, 1, relend, howto, 0, contents); 3520 1.1 christos 3521 1.6 christos if (bfd_link_relocatable (info)) 3522 1.1 christos continue; 3523 1.1 christos 3524 1.1 christos hit_addr = contents + rel->r_offset; 3525 1.1 christos value += rel->r_addend; 3526 1.1 christos dynamic_symbol_p = elf64_ia64_dynamic_symbol_p (h); 3527 1.1 christos 3528 1.1 christos switch (r_type) 3529 1.1 christos { 3530 1.1 christos case R_IA64_NONE: 3531 1.1 christos case R_IA64_LDXMOV: 3532 1.1 christos continue; 3533 1.1 christos 3534 1.1 christos case R_IA64_IMM14: 3535 1.1 christos case R_IA64_IMM22: 3536 1.1 christos case R_IA64_IMM64: 3537 1.1 christos case R_IA64_DIR32MSB: 3538 1.1 christos case R_IA64_DIR32LSB: 3539 1.1 christos case R_IA64_DIR64MSB: 3540 1.1 christos case R_IA64_DIR64LSB: 3541 1.1 christos /* Install a dynamic relocation for this reloc. */ 3542 1.6 christos if ((dynamic_symbol_p || bfd_link_pic (info)) 3543 1.1 christos && r_symndx != 0 3544 1.1 christos && (input_section->flags & SEC_ALLOC) != 0) 3545 1.1 christos { 3546 1.1 christos unsigned int dyn_r_type; 3547 1.1 christos bfd_vma addend; 3548 1.1 christos 3549 1.1 christos switch (r_type) 3550 1.1 christos { 3551 1.1 christos case R_IA64_IMM14: 3552 1.1 christos case R_IA64_IMM22: 3553 1.1 christos case R_IA64_IMM64: 3554 1.1 christos /* ??? People shouldn't be doing non-pic code in 3555 1.1 christos shared libraries nor dynamic executables. */ 3556 1.7 christos _bfd_error_handler 3557 1.7 christos /* xgettext:c-format */ 3558 1.8 christos (_("%pB: non-pic code with imm relocation against" 3559 1.7 christos " dynamic symbol `%s'"), 3560 1.1 christos input_bfd, 3561 1.1 christos h ? h->root.root.string 3562 1.1 christos : bfd_elf_sym_name (input_bfd, symtab_hdr, sym, 3563 1.1 christos sym_sec)); 3564 1.10 christos ret_val = false; 3565 1.1 christos continue; 3566 1.1 christos 3567 1.1 christos default: 3568 1.1 christos break; 3569 1.1 christos } 3570 1.1 christos 3571 1.1 christos /* If we don't need dynamic symbol lookup, find a 3572 1.1 christos matching RELATIVE relocation. */ 3573 1.1 christos dyn_r_type = r_type; 3574 1.1 christos if (dynamic_symbol_p) 3575 1.1 christos { 3576 1.1 christos addend = rel->r_addend; 3577 1.1 christos value = 0; 3578 1.1 christos } 3579 1.1 christos else 3580 1.1 christos { 3581 1.1 christos addend = value; 3582 1.1 christos } 3583 1.1 christos 3584 1.8 christos /* VMS: install a FIX64. */ 3585 1.8 christos switch (dyn_r_type) 3586 1.8 christos { 3587 1.8 christos case R_IA64_DIR32LSB: 3588 1.8 christos dyn_r_type = R_IA64_VMS_FIX32; 3589 1.8 christos break; 3590 1.8 christos case R_IA64_DIR64LSB: 3591 1.8 christos dyn_r_type = R_IA64_VMS_FIX64; 3592 1.8 christos break; 3593 1.8 christos default: 3594 1.10 christos BFD_ASSERT (false); 3595 1.8 christos break; 3596 1.8 christos } 3597 1.8 christos elf64_ia64_install_fixup 3598 1.8 christos (output_bfd, ia64_info, h, 3599 1.8 christos dyn_r_type, input_section, rel->r_offset, addend); 3600 1.8 christos r = bfd_reloc_ok; 3601 1.8 christos break; 3602 1.1 christos } 3603 1.1 christos /* Fall through. */ 3604 1.1 christos 3605 1.1 christos case R_IA64_LTV32MSB: 3606 1.1 christos case R_IA64_LTV32LSB: 3607 1.1 christos case R_IA64_LTV64MSB: 3608 1.1 christos case R_IA64_LTV64LSB: 3609 1.1 christos r = ia64_elf_install_value (hit_addr, value, r_type); 3610 1.1 christos break; 3611 1.1 christos 3612 1.1 christos case R_IA64_GPREL22: 3613 1.1 christos case R_IA64_GPREL64I: 3614 1.1 christos case R_IA64_GPREL32MSB: 3615 1.1 christos case R_IA64_GPREL32LSB: 3616 1.1 christos case R_IA64_GPREL64MSB: 3617 1.1 christos case R_IA64_GPREL64LSB: 3618 1.1 christos if (dynamic_symbol_p) 3619 1.1 christos { 3620 1.7 christos _bfd_error_handler 3621 1.7 christos /* xgettext:c-format */ 3622 1.8 christos (_("%pB: @gprel relocation against dynamic symbol %s"), 3623 1.1 christos input_bfd, 3624 1.1 christos h ? h->root.root.string 3625 1.1 christos : bfd_elf_sym_name (input_bfd, symtab_hdr, sym, 3626 1.1 christos sym_sec)); 3627 1.10 christos ret_val = false; 3628 1.1 christos continue; 3629 1.1 christos } 3630 1.1 christos value -= gp_val; 3631 1.1 christos r = ia64_elf_install_value (hit_addr, value, r_type); 3632 1.1 christos break; 3633 1.1 christos 3634 1.1 christos case R_IA64_LTOFF22: 3635 1.1 christos case R_IA64_LTOFF22X: 3636 1.1 christos case R_IA64_LTOFF64I: 3637 1.10 christos dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, false); 3638 1.1 christos value = set_got_entry (input_bfd, info, dyn_i, 3639 1.1 christos rel->r_addend, value, R_IA64_DIR64LSB); 3640 1.1 christos value -= gp_val; 3641 1.1 christos r = ia64_elf_install_value (hit_addr, value, r_type); 3642 1.1 christos break; 3643 1.1 christos 3644 1.1 christos case R_IA64_PLTOFF22: 3645 1.1 christos case R_IA64_PLTOFF64I: 3646 1.1 christos case R_IA64_PLTOFF64MSB: 3647 1.1 christos case R_IA64_PLTOFF64LSB: 3648 1.10 christos dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, false); 3649 1.10 christos value = set_pltoff_entry (output_bfd, info, dyn_i, value, false); 3650 1.1 christos value -= gp_val; 3651 1.1 christos r = ia64_elf_install_value (hit_addr, value, r_type); 3652 1.1 christos break; 3653 1.1 christos 3654 1.1 christos case R_IA64_FPTR64I: 3655 1.1 christos case R_IA64_FPTR32MSB: 3656 1.1 christos case R_IA64_FPTR32LSB: 3657 1.1 christos case R_IA64_FPTR64MSB: 3658 1.1 christos case R_IA64_FPTR64LSB: 3659 1.10 christos dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, false); 3660 1.1 christos if (dyn_i->want_fptr) 3661 1.1 christos { 3662 1.1 christos if (!undef_weak_ref) 3663 1.1 christos value = set_fptr_entry (output_bfd, info, dyn_i, value); 3664 1.1 christos } 3665 1.6 christos if (!dyn_i->want_fptr || bfd_link_pie (info)) 3666 1.1 christos { 3667 1.1 christos /* Otherwise, we expect the dynamic linker to create 3668 1.1 christos the entry. */ 3669 1.1 christos 3670 1.1 christos if (dyn_i->want_fptr) 3671 1.1 christos { 3672 1.1 christos if (r_type == R_IA64_FPTR64I) 3673 1.1 christos { 3674 1.1 christos /* We can't represent this without a dynamic symbol. 3675 1.1 christos Adjust the relocation to be against an output 3676 1.1 christos section symbol, which are always present in the 3677 1.1 christos dynamic symbol table. */ 3678 1.1 christos /* ??? People shouldn't be doing non-pic code in 3679 1.1 christos shared libraries. Hork. */ 3680 1.7 christos _bfd_error_handler 3681 1.8 christos (_("%pB: linking non-pic code in a position independent executable"), 3682 1.1 christos input_bfd); 3683 1.10 christos ret_val = false; 3684 1.1 christos continue; 3685 1.1 christos } 3686 1.1 christos } 3687 1.1 christos else 3688 1.1 christos { 3689 1.1 christos value = 0; 3690 1.1 christos } 3691 1.1 christos 3692 1.8 christos /* VMS: FIXFD. */ 3693 1.8 christos elf64_ia64_install_fixup 3694 1.8 christos (output_bfd, ia64_info, h, R_IA64_VMS_FIXFD, 3695 1.8 christos input_section, rel->r_offset, 0); 3696 1.8 christos r = bfd_reloc_ok; 3697 1.8 christos break; 3698 1.1 christos } 3699 1.1 christos 3700 1.1 christos r = ia64_elf_install_value (hit_addr, value, r_type); 3701 1.1 christos break; 3702 1.1 christos 3703 1.1 christos case R_IA64_LTOFF_FPTR22: 3704 1.1 christos case R_IA64_LTOFF_FPTR64I: 3705 1.1 christos case R_IA64_LTOFF_FPTR32MSB: 3706 1.1 christos case R_IA64_LTOFF_FPTR32LSB: 3707 1.1 christos case R_IA64_LTOFF_FPTR64MSB: 3708 1.1 christos case R_IA64_LTOFF_FPTR64LSB: 3709 1.10 christos dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, false); 3710 1.8 christos if (dyn_i->want_fptr) 3711 1.8 christos { 3712 1.8 christos BFD_ASSERT (h == NULL || !h->def_dynamic); 3713 1.8 christos if (!undef_weak_ref) 3714 1.8 christos value = set_fptr_entry (output_bfd, info, dyn_i, value); 3715 1.8 christos } 3716 1.8 christos else 3717 1.8 christos value = 0; 3718 1.8 christos 3719 1.8 christos value = set_got_entry (output_bfd, info, dyn_i, 3720 1.8 christos rel->r_addend, value, R_IA64_FPTR64LSB); 3721 1.8 christos value -= gp_val; 3722 1.8 christos r = ia64_elf_install_value (hit_addr, value, r_type); 3723 1.1 christos break; 3724 1.1 christos 3725 1.1 christos case R_IA64_PCREL32MSB: 3726 1.1 christos case R_IA64_PCREL32LSB: 3727 1.1 christos case R_IA64_PCREL64MSB: 3728 1.1 christos case R_IA64_PCREL64LSB: 3729 1.1 christos /* Install a dynamic relocation for this reloc. */ 3730 1.1 christos if (dynamic_symbol_p && r_symndx != 0) 3731 1.1 christos { 3732 1.8 christos /* VMS: doesn't exist ??? */ 3733 1.8 christos abort (); 3734 1.1 christos } 3735 1.1 christos goto finish_pcrel; 3736 1.1 christos 3737 1.1 christos case R_IA64_PCREL21B: 3738 1.1 christos case R_IA64_PCREL60B: 3739 1.1 christos /* We should have created a PLT entry for any dynamic symbol. */ 3740 1.1 christos dyn_i = NULL; 3741 1.1 christos if (h) 3742 1.10 christos dyn_i = get_dyn_sym_info (ia64_info, h, NULL, NULL, false); 3743 1.1 christos 3744 1.1 christos if (dyn_i && dyn_i->want_plt2) 3745 1.1 christos { 3746 1.1 christos /* Should have caught this earlier. */ 3747 1.1 christos BFD_ASSERT (rel->r_addend == 0); 3748 1.1 christos 3749 1.1 christos value = (ia64_info->root.splt->output_section->vma 3750 1.1 christos + ia64_info->root.splt->output_offset 3751 1.1 christos + dyn_i->plt2_offset); 3752 1.1 christos } 3753 1.1 christos else 3754 1.1 christos { 3755 1.1 christos /* Since there's no PLT entry, Validate that this is 3756 1.1 christos locally defined. */ 3757 1.1 christos BFD_ASSERT (undef_weak_ref || sym_sec->output_section != NULL); 3758 1.1 christos 3759 1.1 christos /* If the symbol is undef_weak, we shouldn't be trying 3760 1.1 christos to call it. There's every chance that we'd wind up 3761 1.1 christos with an out-of-range fixup here. Don't bother setting 3762 1.1 christos any value at all. */ 3763 1.1 christos if (undef_weak_ref) 3764 1.1 christos continue; 3765 1.1 christos } 3766 1.1 christos goto finish_pcrel; 3767 1.1 christos 3768 1.1 christos case R_IA64_PCREL21BI: 3769 1.1 christos case R_IA64_PCREL21F: 3770 1.1 christos case R_IA64_PCREL21M: 3771 1.1 christos case R_IA64_PCREL22: 3772 1.1 christos case R_IA64_PCREL64I: 3773 1.1 christos /* The PCREL21BI reloc is specifically not intended for use with 3774 1.1 christos dynamic relocs. PCREL21F and PCREL21M are used for speculation 3775 1.1 christos fixup code, and thus probably ought not be dynamic. The 3776 1.1 christos PCREL22 and PCREL64I relocs aren't emitted as dynamic relocs. */ 3777 1.1 christos if (dynamic_symbol_p) 3778 1.1 christos { 3779 1.1 christos const char *msg; 3780 1.1 christos 3781 1.1 christos if (r_type == R_IA64_PCREL21BI) 3782 1.7 christos /* xgettext:c-format */ 3783 1.8 christos msg = _("%pB: @internal branch to dynamic symbol %s"); 3784 1.1 christos else if (r_type == R_IA64_PCREL21F || r_type == R_IA64_PCREL21M) 3785 1.7 christos /* xgettext:c-format */ 3786 1.8 christos msg = _("%pB: speculation fixup to dynamic symbol %s"); 3787 1.1 christos else 3788 1.7 christos /* xgettext:c-format */ 3789 1.8 christos msg = _("%pB: @pcrel relocation against dynamic symbol %s"); 3790 1.7 christos _bfd_error_handler (msg, input_bfd, 3791 1.7 christos h ? h->root.root.string 3792 1.7 christos : bfd_elf_sym_name (input_bfd, 3793 1.7 christos symtab_hdr, 3794 1.7 christos sym, 3795 1.7 christos sym_sec)); 3796 1.10 christos ret_val = false; 3797 1.1 christos continue; 3798 1.1 christos } 3799 1.1 christos goto finish_pcrel; 3800 1.1 christos 3801 1.1 christos finish_pcrel: 3802 1.1 christos /* Make pc-relative. */ 3803 1.1 christos value -= (input_section->output_section->vma 3804 1.1 christos + input_section->output_offset 3805 1.1 christos + rel->r_offset) & ~ (bfd_vma) 0x3; 3806 1.1 christos r = ia64_elf_install_value (hit_addr, value, r_type); 3807 1.1 christos break; 3808 1.1 christos 3809 1.1 christos case R_IA64_SEGREL32MSB: 3810 1.1 christos case R_IA64_SEGREL32LSB: 3811 1.1 christos case R_IA64_SEGREL64MSB: 3812 1.1 christos case R_IA64_SEGREL64LSB: 3813 1.1 christos { 3814 1.1 christos /* Find the segment that contains the output_section. */ 3815 1.1 christos Elf_Internal_Phdr *p = _bfd_elf_find_segment_containing_section 3816 1.1 christos (output_bfd, sym_sec->output_section); 3817 1.1 christos 3818 1.1 christos if (p == NULL) 3819 1.1 christos { 3820 1.1 christos r = bfd_reloc_notsupported; 3821 1.1 christos } 3822 1.1 christos else 3823 1.1 christos { 3824 1.1 christos /* The VMA of the segment is the vaddr of the associated 3825 1.1 christos program header. */ 3826 1.1 christos if (value > p->p_vaddr) 3827 1.1 christos value -= p->p_vaddr; 3828 1.1 christos else 3829 1.1 christos value = 0; 3830 1.1 christos r = ia64_elf_install_value (hit_addr, value, r_type); 3831 1.1 christos } 3832 1.1 christos break; 3833 1.1 christos } 3834 1.1 christos 3835 1.1 christos case R_IA64_SECREL32MSB: 3836 1.1 christos case R_IA64_SECREL32LSB: 3837 1.1 christos case R_IA64_SECREL64MSB: 3838 1.1 christos case R_IA64_SECREL64LSB: 3839 1.1 christos /* Make output-section relative to section where the symbol 3840 1.1 christos is defined. PR 475 */ 3841 1.1 christos if (sym_sec) 3842 1.1 christos value -= sym_sec->output_section->vma; 3843 1.1 christos r = ia64_elf_install_value (hit_addr, value, r_type); 3844 1.1 christos break; 3845 1.1 christos 3846 1.1 christos case R_IA64_IPLTMSB: 3847 1.1 christos case R_IA64_IPLTLSB: 3848 1.1 christos /* Install a dynamic relocation for this reloc. */ 3849 1.6 christos if ((dynamic_symbol_p || bfd_link_pic (info)) 3850 1.1 christos && (input_section->flags & SEC_ALLOC) != 0) 3851 1.1 christos { 3852 1.8 christos /* VMS: FIXFD ?? */ 3853 1.8 christos abort (); 3854 1.1 christos } 3855 1.1 christos 3856 1.1 christos if (r_type == R_IA64_IPLTMSB) 3857 1.1 christos r_type = R_IA64_DIR64MSB; 3858 1.1 christos else 3859 1.1 christos r_type = R_IA64_DIR64LSB; 3860 1.1 christos ia64_elf_install_value (hit_addr, value, r_type); 3861 1.1 christos r = ia64_elf_install_value (hit_addr + 8, gp_val, r_type); 3862 1.1 christos break; 3863 1.1 christos 3864 1.1 christos case R_IA64_TPREL14: 3865 1.1 christos case R_IA64_TPREL22: 3866 1.1 christos case R_IA64_TPREL64I: 3867 1.1 christos r = bfd_reloc_notsupported; 3868 1.1 christos break; 3869 1.1 christos 3870 1.1 christos case R_IA64_DTPREL14: 3871 1.1 christos case R_IA64_DTPREL22: 3872 1.1 christos case R_IA64_DTPREL64I: 3873 1.1 christos case R_IA64_DTPREL32LSB: 3874 1.1 christos case R_IA64_DTPREL32MSB: 3875 1.1 christos case R_IA64_DTPREL64LSB: 3876 1.1 christos case R_IA64_DTPREL64MSB: 3877 1.1 christos r = bfd_reloc_notsupported; 3878 1.1 christos break; 3879 1.1 christos 3880 1.1 christos case R_IA64_LTOFF_TPREL22: 3881 1.1 christos case R_IA64_LTOFF_DTPMOD22: 3882 1.1 christos case R_IA64_LTOFF_DTPREL22: 3883 1.1 christos r = bfd_reloc_notsupported; 3884 1.1 christos break; 3885 1.1 christos 3886 1.1 christos default: 3887 1.1 christos r = bfd_reloc_notsupported; 3888 1.1 christos break; 3889 1.1 christos } 3890 1.1 christos 3891 1.1 christos switch (r) 3892 1.1 christos { 3893 1.1 christos case bfd_reloc_ok: 3894 1.1 christos break; 3895 1.1 christos 3896 1.1 christos case bfd_reloc_undefined: 3897 1.1 christos /* This can happen for global table relative relocs if 3898 1.1 christos __gp is undefined. This is a panic situation so we 3899 1.1 christos don't try to continue. */ 3900 1.1 christos (*info->callbacks->undefined_symbol) 3901 1.1 christos (info, "__gp", input_bfd, input_section, rel->r_offset, 1); 3902 1.10 christos return false; 3903 1.1 christos 3904 1.1 christos case bfd_reloc_notsupported: 3905 1.1 christos { 3906 1.1 christos const char *name; 3907 1.1 christos 3908 1.1 christos if (h) 3909 1.1 christos name = h->root.root.string; 3910 1.1 christos else 3911 1.1 christos name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, 3912 1.1 christos sym_sec); 3913 1.6 christos (*info->callbacks->warning) (info, _("unsupported reloc"), 3914 1.6 christos name, input_bfd, 3915 1.6 christos input_section, rel->r_offset); 3916 1.10 christos ret_val = false; 3917 1.1 christos } 3918 1.1 christos break; 3919 1.1 christos 3920 1.1 christos case bfd_reloc_dangerous: 3921 1.1 christos case bfd_reloc_outofrange: 3922 1.1 christos case bfd_reloc_overflow: 3923 1.1 christos default: 3924 1.1 christos { 3925 1.1 christos const char *name; 3926 1.1 christos 3927 1.1 christos if (h) 3928 1.1 christos name = h->root.root.string; 3929 1.1 christos else 3930 1.1 christos name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, 3931 1.1 christos sym_sec); 3932 1.1 christos 3933 1.1 christos switch (r_type) 3934 1.1 christos { 3935 1.1 christos case R_IA64_TPREL14: 3936 1.1 christos case R_IA64_TPREL22: 3937 1.1 christos case R_IA64_TPREL64I: 3938 1.1 christos case R_IA64_DTPREL14: 3939 1.1 christos case R_IA64_DTPREL22: 3940 1.1 christos case R_IA64_DTPREL64I: 3941 1.1 christos case R_IA64_DTPREL32LSB: 3942 1.1 christos case R_IA64_DTPREL32MSB: 3943 1.1 christos case R_IA64_DTPREL64LSB: 3944 1.1 christos case R_IA64_DTPREL64MSB: 3945 1.1 christos case R_IA64_LTOFF_TPREL22: 3946 1.1 christos case R_IA64_LTOFF_DTPMOD22: 3947 1.1 christos case R_IA64_LTOFF_DTPREL22: 3948 1.7 christos _bfd_error_handler 3949 1.7 christos /* xgettext:c-format */ 3950 1.8 christos (_("%pB: missing TLS section for relocation %s against `%s'" 3951 1.8 christos " at %#" PRIx64 " in section `%pA'."), 3952 1.7 christos input_bfd, howto->name, name, 3953 1.8 christos (uint64_t) rel->r_offset, input_section); 3954 1.1 christos break; 3955 1.1 christos 3956 1.1 christos case R_IA64_PCREL21B: 3957 1.1 christos case R_IA64_PCREL21BI: 3958 1.1 christos case R_IA64_PCREL21M: 3959 1.1 christos case R_IA64_PCREL21F: 3960 1.1 christos if (is_elf_hash_table (info->hash)) 3961 1.1 christos { 3962 1.1 christos /* Relaxtion is always performed for ELF output. 3963 1.1 christos Overflow failures for those relocations mean 3964 1.1 christos that the section is too big to relax. */ 3965 1.7 christos _bfd_error_handler 3966 1.7 christos /* xgettext:c-format */ 3967 1.8 christos (_("%pB: Can't relax br (%s) to `%s' " 3968 1.8 christos "at %#" PRIx64 " in section `%pA' " 3969 1.8 christos "with size %#" PRIx64 " (> 0x1000000)."), 3970 1.8 christos input_bfd, howto->name, name, (uint64_t) rel->r_offset, 3971 1.8 christos input_section, (uint64_t) input_section->size); 3972 1.1 christos break; 3973 1.1 christos } 3974 1.7 christos /* Fall through. */ 3975 1.1 christos default: 3976 1.6 christos (*info->callbacks->reloc_overflow) (info, 3977 1.6 christos &h->root, 3978 1.6 christos name, 3979 1.6 christos howto->name, 3980 1.6 christos (bfd_vma) 0, 3981 1.6 christos input_bfd, 3982 1.6 christos input_section, 3983 1.6 christos rel->r_offset); 3984 1.1 christos break; 3985 1.1 christos } 3986 1.1 christos 3987 1.10 christos ret_val = false; 3988 1.1 christos } 3989 1.1 christos break; 3990 1.1 christos } 3991 1.1 christos } 3992 1.1 christos 3993 1.1 christos return ret_val; 3994 1.1 christos } 3995 1.1 christos 3996 1.10 christos static bool 3997 1.1 christos elf64_ia64_finish_dynamic_symbol (bfd *output_bfd, 3998 1.1 christos struct bfd_link_info *info, 3999 1.1 christos struct elf_link_hash_entry *h, 4000 1.1 christos Elf_Internal_Sym *sym) 4001 1.1 christos { 4002 1.1 christos struct elf64_ia64_link_hash_table *ia64_info; 4003 1.1 christos struct elf64_ia64_dyn_sym_info *dyn_i; 4004 1.1 christos 4005 1.1 christos ia64_info = elf64_ia64_hash_table (info); 4006 1.1 christos 4007 1.10 christos dyn_i = get_dyn_sym_info (ia64_info, h, NULL, NULL, false); 4008 1.1 christos 4009 1.1 christos /* Fill in the PLT data, if required. */ 4010 1.1 christos if (dyn_i && dyn_i->want_plt) 4011 1.1 christos { 4012 1.1 christos bfd_byte *loc; 4013 1.1 christos asection *plt_sec; 4014 1.1 christos bfd_vma plt_addr, pltoff_addr, gp_val; 4015 1.1 christos 4016 1.1 christos gp_val = _bfd_get_gp_value (output_bfd); 4017 1.1 christos 4018 1.1 christos plt_sec = ia64_info->root.splt; 4019 1.1 christos plt_addr = 0; /* Not used as overriden by FIXUPs. */ 4020 1.10 christos pltoff_addr = set_pltoff_entry (output_bfd, info, dyn_i, plt_addr, true); 4021 1.1 christos 4022 1.1 christos /* Initialize the FULL PLT entry, if needed. */ 4023 1.1 christos if (dyn_i->want_plt2) 4024 1.1 christos { 4025 1.1 christos loc = plt_sec->contents + dyn_i->plt2_offset; 4026 1.1 christos 4027 1.1 christos memcpy (loc, plt_full_entry, PLT_FULL_ENTRY_SIZE); 4028 1.1 christos ia64_elf_install_value (loc, pltoff_addr - gp_val, R_IA64_IMM22); 4029 1.1 christos 4030 1.1 christos /* Mark the symbol as undefined, rather than as defined in the 4031 1.1 christos plt section. Leave the value alone. */ 4032 1.1 christos /* ??? We didn't redefine it in adjust_dynamic_symbol in the 4033 1.1 christos first place. But perhaps elflink.c did some for us. */ 4034 1.1 christos if (!h->def_regular) 4035 1.1 christos sym->st_shndx = SHN_UNDEF; 4036 1.1 christos } 4037 1.1 christos 4038 1.1 christos /* VMS: FIXFD. */ 4039 1.1 christos elf64_ia64_install_fixup 4040 1.8 christos (output_bfd, ia64_info, h, R_IA64_VMS_FIXFD, ia64_info->pltoff_sec, 4041 1.8 christos pltoff_addr - (ia64_info->pltoff_sec->output_section->vma 4042 1.8 christos + ia64_info->pltoff_sec->output_offset), 0); 4043 1.1 christos } 4044 1.1 christos 4045 1.1 christos /* Mark some specially defined symbols as absolute. */ 4046 1.1 christos if (h == ia64_info->root.hdynamic 4047 1.1 christos || h == ia64_info->root.hgot 4048 1.1 christos || h == ia64_info->root.hplt) 4049 1.1 christos sym->st_shndx = SHN_ABS; 4050 1.1 christos 4051 1.10 christos return true; 4052 1.1 christos } 4053 1.1 christos 4054 1.10 christos static bool 4055 1.1 christos elf64_ia64_finish_dynamic_sections (bfd *abfd, 4056 1.1 christos struct bfd_link_info *info) 4057 1.1 christos { 4058 1.1 christos struct elf64_ia64_link_hash_table *ia64_info; 4059 1.1 christos bfd *dynobj; 4060 1.1 christos 4061 1.1 christos ia64_info = elf64_ia64_hash_table (info); 4062 1.1 christos if (ia64_info == NULL) 4063 1.10 christos return false; 4064 1.1 christos 4065 1.1 christos dynobj = ia64_info->root.dynobj; 4066 1.1 christos 4067 1.1 christos if (elf_hash_table (info)->dynamic_sections_created) 4068 1.1 christos { 4069 1.1 christos Elf64_External_Dyn *dyncon, *dynconend; 4070 1.1 christos asection *sdyn; 4071 1.1 christos asection *unwind_sec; 4072 1.1 christos bfd_vma gp_val; 4073 1.1 christos unsigned int gp_seg; 4074 1.1 christos bfd_vma gp_off; 4075 1.1 christos Elf_Internal_Phdr *phdr; 4076 1.1 christos Elf_Internal_Phdr *base_phdr; 4077 1.1 christos unsigned int unwind_seg = 0; 4078 1.1 christos unsigned int code_seg = 0; 4079 1.1 christos 4080 1.1 christos sdyn = bfd_get_linker_section (dynobj, ".dynamic"); 4081 1.1 christos BFD_ASSERT (sdyn != NULL); 4082 1.1 christos dyncon = (Elf64_External_Dyn *) sdyn->contents; 4083 1.1 christos dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size); 4084 1.1 christos 4085 1.1 christos gp_val = _bfd_get_gp_value (abfd); 4086 1.1 christos phdr = _bfd_elf_find_segment_containing_section 4087 1.8 christos (info->output_bfd, ia64_info->pltoff_sec->output_section); 4088 1.1 christos BFD_ASSERT (phdr != NULL); 4089 1.1 christos base_phdr = elf_tdata (info->output_bfd)->phdr; 4090 1.1 christos gp_seg = phdr - base_phdr; 4091 1.1 christos gp_off = gp_val - phdr->p_vaddr; 4092 1.1 christos 4093 1.1 christos unwind_sec = bfd_get_section_by_name (abfd, ELF_STRING_ia64_unwind); 4094 1.1 christos if (unwind_sec != NULL) 4095 1.8 christos { 4096 1.8 christos asection *code_sec; 4097 1.1 christos 4098 1.8 christos phdr = _bfd_elf_find_segment_containing_section (abfd, unwind_sec); 4099 1.8 christos BFD_ASSERT (phdr != NULL); 4100 1.8 christos unwind_seg = phdr - base_phdr; 4101 1.8 christos 4102 1.8 christos code_sec = bfd_get_section_by_name (abfd, "$CODE$"); 4103 1.8 christos phdr = _bfd_elf_find_segment_containing_section (abfd, code_sec); 4104 1.8 christos BFD_ASSERT (phdr != NULL); 4105 1.8 christos code_seg = phdr - base_phdr; 4106 1.8 christos } 4107 1.1 christos 4108 1.1 christos for (; dyncon < dynconend; dyncon++) 4109 1.1 christos { 4110 1.1 christos Elf_Internal_Dyn dyn; 4111 1.1 christos 4112 1.1 christos bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn); 4113 1.1 christos 4114 1.1 christos switch (dyn.d_tag) 4115 1.1 christos { 4116 1.8 christos case DT_IA_64_VMS_FIXUP_RELA_OFF: 4117 1.8 christos dyn.d_un.d_val += 4118 1.8 christos (ia64_info->fixups_sec->output_section->vma 4119 1.8 christos + ia64_info->fixups_sec->output_offset) 4120 1.8 christos - (sdyn->output_section->vma + sdyn->output_offset); 4121 1.8 christos break; 4122 1.8 christos 4123 1.8 christos case DT_IA_64_VMS_PLTGOT_OFFSET: 4124 1.8 christos dyn.d_un.d_val = gp_off; 4125 1.8 christos break; 4126 1.8 christos 4127 1.8 christos case DT_IA_64_VMS_PLTGOT_SEG: 4128 1.8 christos dyn.d_un.d_val = gp_seg; 4129 1.8 christos break; 4130 1.8 christos 4131 1.8 christos case DT_IA_64_VMS_UNWINDSZ: 4132 1.8 christos if (unwind_sec == NULL) 4133 1.8 christos { 4134 1.8 christos dyn.d_tag = DT_NULL; 4135 1.8 christos dyn.d_un.d_val = 0xdead; 4136 1.8 christos } 4137 1.8 christos else 4138 1.8 christos dyn.d_un.d_val = unwind_sec->size; 4139 1.8 christos break; 4140 1.8 christos 4141 1.8 christos case DT_IA_64_VMS_UNWIND_CODSEG: 4142 1.8 christos dyn.d_un.d_val = code_seg; 4143 1.8 christos break; 4144 1.8 christos 4145 1.8 christos case DT_IA_64_VMS_UNWIND_INFOSEG: 4146 1.8 christos case DT_IA_64_VMS_UNWIND_SEG: 4147 1.8 christos dyn.d_un.d_val = unwind_seg; 4148 1.8 christos break; 4149 1.8 christos 4150 1.8 christos case DT_IA_64_VMS_UNWIND_OFFSET: 4151 1.8 christos break; 4152 1.8 christos 4153 1.8 christos default: 4154 1.8 christos /* No need to rewrite the entry. */ 4155 1.8 christos continue; 4156 1.1 christos } 4157 1.1 christos 4158 1.1 christos bfd_elf64_swap_dyn_out (abfd, &dyn, dyncon); 4159 1.1 christos } 4160 1.1 christos } 4161 1.1 christos 4162 1.1 christos /* Handle transfer addresses. */ 4163 1.1 christos { 4164 1.1 christos asection *tfr_sec = ia64_info->transfer_sec; 4165 1.1 christos struct elf64_vms_transfer *tfr; 4166 1.1 christos struct elf_link_hash_entry *tfr3; 4167 1.1 christos 4168 1.1 christos tfr = (struct elf64_vms_transfer *)tfr_sec->contents; 4169 1.1 christos bfd_putl32 (6 * 8, tfr->size); 4170 1.1 christos bfd_putl64 (tfr_sec->output_section->vma 4171 1.8 christos + tfr_sec->output_offset 4172 1.8 christos + 6 * 8, tfr->tfradr3); 4173 1.1 christos 4174 1.10 christos tfr3 = elf_link_hash_lookup (elf_hash_table (info), "ELF$TFRADR", false, 4175 1.10 christos false, false); 4176 1.1 christos 4177 1.1 christos if (tfr3 4178 1.8 christos && (tfr3->root.type == bfd_link_hash_defined 4179 1.8 christos || tfr3->root.type == bfd_link_hash_defweak)) 4180 1.1 christos { 4181 1.8 christos asection *tfr3_sec = tfr3->root.u.def.section; 4182 1.8 christos bfd_vma tfr3_val; 4183 1.1 christos 4184 1.8 christos tfr3_val = (tfr3->root.u.def.value 4185 1.8 christos + tfr3_sec->output_section->vma 4186 1.8 christos + tfr3_sec->output_offset); 4187 1.1 christos 4188 1.8 christos bfd_putl64 (tfr3_val, tfr->tfr3_func); 4189 1.8 christos bfd_putl64 (_bfd_get_gp_value (info->output_bfd), tfr->tfr3_gp); 4190 1.1 christos } 4191 1.1 christos 4192 1.1 christos /* FIXME: set linker flags, 4193 1.1 christos handle lib$initialize. */ 4194 1.1 christos } 4195 1.1 christos 4196 1.10 christos return true; 4197 1.1 christos } 4198 1.1 christos 4199 1.1 christos /* ELF file flag handling: */ 4200 1.1 christos 4201 1.1 christos /* Function to keep IA-64 specific file flags. */ 4202 1.10 christos static bool 4203 1.1 christos elf64_ia64_set_private_flags (bfd *abfd, flagword flags) 4204 1.1 christos { 4205 1.1 christos BFD_ASSERT (!elf_flags_init (abfd) 4206 1.1 christos || elf_elfheader (abfd)->e_flags == flags); 4207 1.1 christos 4208 1.1 christos elf_elfheader (abfd)->e_flags = flags; 4209 1.10 christos elf_flags_init (abfd) = true; 4210 1.10 christos return true; 4211 1.1 christos } 4212 1.1 christos 4213 1.1 christos /* Merge backend specific data from an object file to the output 4214 1.1 christos object file when linking. */ 4215 1.10 christos static bool 4216 1.7 christos elf64_ia64_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info) 4217 1.1 christos { 4218 1.7 christos bfd *obfd = info->output_bfd; 4219 1.1 christos flagword out_flags; 4220 1.1 christos flagword in_flags; 4221 1.10 christos bool ok = true; 4222 1.1 christos 4223 1.9 christos /* FIXME: What should be checked when linking shared libraries? */ 4224 1.9 christos if ((ibfd->flags & DYNAMIC) != 0) 4225 1.10 christos return true; 4226 1.9 christos 4227 1.1 christos /* Don't even pretend to support mixed-format linking. */ 4228 1.1 christos if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour 4229 1.1 christos || bfd_get_flavour (obfd) != bfd_target_elf_flavour) 4230 1.10 christos return false; 4231 1.1 christos 4232 1.1 christos in_flags = elf_elfheader (ibfd)->e_flags; 4233 1.1 christos out_flags = elf_elfheader (obfd)->e_flags; 4234 1.1 christos 4235 1.1 christos if (! elf_flags_init (obfd)) 4236 1.1 christos { 4237 1.10 christos elf_flags_init (obfd) = true; 4238 1.1 christos elf_elfheader (obfd)->e_flags = in_flags; 4239 1.1 christos 4240 1.1 christos if (bfd_get_arch (obfd) == bfd_get_arch (ibfd) 4241 1.1 christos && bfd_get_arch_info (obfd)->the_default) 4242 1.1 christos { 4243 1.1 christos return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), 4244 1.1 christos bfd_get_mach (ibfd)); 4245 1.1 christos } 4246 1.1 christos 4247 1.10 christos return true; 4248 1.1 christos } 4249 1.1 christos 4250 1.1 christos /* Check flag compatibility. */ 4251 1.1 christos if (in_flags == out_flags) 4252 1.10 christos return true; 4253 1.1 christos 4254 1.1 christos /* Output has EF_IA_64_REDUCEDFP set only if all inputs have it set. */ 4255 1.1 christos if (!(in_flags & EF_IA_64_REDUCEDFP) && (out_flags & EF_IA_64_REDUCEDFP)) 4256 1.1 christos elf_elfheader (obfd)->e_flags &= ~EF_IA_64_REDUCEDFP; 4257 1.1 christos 4258 1.1 christos if ((in_flags & EF_IA_64_TRAPNIL) != (out_flags & EF_IA_64_TRAPNIL)) 4259 1.1 christos { 4260 1.7 christos _bfd_error_handler 4261 1.8 christos (_("%pB: linking trap-on-NULL-dereference with non-trapping files"), 4262 1.1 christos ibfd); 4263 1.1 christos 4264 1.1 christos bfd_set_error (bfd_error_bad_value); 4265 1.10 christos ok = false; 4266 1.1 christos } 4267 1.1 christos if ((in_flags & EF_IA_64_BE) != (out_flags & EF_IA_64_BE)) 4268 1.1 christos { 4269 1.7 christos _bfd_error_handler 4270 1.8 christos (_("%pB: linking big-endian files with little-endian files"), 4271 1.1 christos ibfd); 4272 1.1 christos 4273 1.1 christos bfd_set_error (bfd_error_bad_value); 4274 1.10 christos ok = false; 4275 1.1 christos } 4276 1.1 christos if ((in_flags & EF_IA_64_ABI64) != (out_flags & EF_IA_64_ABI64)) 4277 1.1 christos { 4278 1.7 christos _bfd_error_handler 4279 1.8 christos (_("%pB: linking 64-bit files with 32-bit files"), 4280 1.1 christos ibfd); 4281 1.1 christos 4282 1.1 christos bfd_set_error (bfd_error_bad_value); 4283 1.10 christos ok = false; 4284 1.1 christos } 4285 1.1 christos if ((in_flags & EF_IA_64_CONS_GP) != (out_flags & EF_IA_64_CONS_GP)) 4286 1.1 christos { 4287 1.7 christos _bfd_error_handler 4288 1.8 christos (_("%pB: linking constant-gp files with non-constant-gp files"), 4289 1.1 christos ibfd); 4290 1.1 christos 4291 1.1 christos bfd_set_error (bfd_error_bad_value); 4292 1.10 christos ok = false; 4293 1.1 christos } 4294 1.1 christos if ((in_flags & EF_IA_64_NOFUNCDESC_CONS_GP) 4295 1.1 christos != (out_flags & EF_IA_64_NOFUNCDESC_CONS_GP)) 4296 1.1 christos { 4297 1.7 christos _bfd_error_handler 4298 1.8 christos (_("%pB: linking auto-pic files with non-auto-pic files"), 4299 1.1 christos ibfd); 4300 1.1 christos 4301 1.1 christos bfd_set_error (bfd_error_bad_value); 4302 1.10 christos ok = false; 4303 1.1 christos } 4304 1.1 christos 4305 1.1 christos return ok; 4306 1.1 christos } 4307 1.1 christos 4308 1.10 christos static bool 4309 1.1 christos elf64_ia64_print_private_bfd_data (bfd *abfd, void * ptr) 4310 1.1 christos { 4311 1.1 christos FILE *file = (FILE *) ptr; 4312 1.1 christos flagword flags = elf_elfheader (abfd)->e_flags; 4313 1.1 christos 4314 1.1 christos BFD_ASSERT (abfd != NULL && ptr != NULL); 4315 1.1 christos 4316 1.1 christos fprintf (file, "private flags = %s%s%s%s%s%s%s%s\n", 4317 1.1 christos (flags & EF_IA_64_TRAPNIL) ? "TRAPNIL, " : "", 4318 1.1 christos (flags & EF_IA_64_EXT) ? "EXT, " : "", 4319 1.1 christos (flags & EF_IA_64_BE) ? "BE, " : "LE, ", 4320 1.1 christos (flags & EF_IA_64_REDUCEDFP) ? "REDUCEDFP, " : "", 4321 1.1 christos (flags & EF_IA_64_CONS_GP) ? "CONS_GP, " : "", 4322 1.1 christos (flags & EF_IA_64_NOFUNCDESC_CONS_GP) ? "NOFUNCDESC_CONS_GP, " : "", 4323 1.1 christos (flags & EF_IA_64_ABSOLUTE) ? "ABSOLUTE, " : "", 4324 1.1 christos (flags & EF_IA_64_ABI64) ? "ABI64" : "ABI32"); 4325 1.1 christos 4326 1.1 christos _bfd_elf_print_private_bfd_data (abfd, ptr); 4327 1.10 christos return true; 4328 1.1 christos } 4329 1.1 christos 4330 1.1 christos static enum elf_reloc_type_class 4331 1.1 christos elf64_ia64_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED, 4332 1.1 christos const asection *rel_sec ATTRIBUTE_UNUSED, 4333 1.1 christos const Elf_Internal_Rela *rela) 4334 1.1 christos { 4335 1.1 christos switch ((int) ELF64_R_TYPE (rela->r_info)) 4336 1.1 christos { 4337 1.1 christos case R_IA64_REL32MSB: 4338 1.1 christos case R_IA64_REL32LSB: 4339 1.1 christos case R_IA64_REL64MSB: 4340 1.1 christos case R_IA64_REL64LSB: 4341 1.1 christos return reloc_class_relative; 4342 1.1 christos case R_IA64_IPLTMSB: 4343 1.1 christos case R_IA64_IPLTLSB: 4344 1.1 christos return reloc_class_plt; 4345 1.1 christos case R_IA64_COPY: 4346 1.1 christos return reloc_class_copy; 4347 1.1 christos default: 4348 1.1 christos return reloc_class_normal; 4349 1.1 christos } 4350 1.1 christos } 4351 1.1 christos 4352 1.1 christos static const struct bfd_elf_special_section elf64_ia64_special_sections[] = 4353 1.1 christos { 4354 1.8 christos { STRING_COMMA_LEN (".sbss"), -1, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT }, 4355 1.1 christos { STRING_COMMA_LEN (".sdata"), -1, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT }, 4356 1.8 christos { NULL, 0, 0, 0, 0 } 4357 1.1 christos }; 4358 1.1 christos 4359 1.10 christos static bool 4360 1.1 christos elf64_ia64_object_p (bfd *abfd) 4361 1.1 christos { 4362 1.1 christos asection *sec; 4363 1.1 christos asection *group, *unwi, *unw; 4364 1.1 christos flagword flags; 4365 1.1 christos const char *name; 4366 1.1 christos char *unwi_name, *unw_name; 4367 1.9 christos size_t amt; 4368 1.1 christos 4369 1.1 christos if (abfd->flags & DYNAMIC) 4370 1.10 christos return true; 4371 1.1 christos 4372 1.1 christos /* Flags for fake group section. */ 4373 1.1 christos flags = (SEC_LINKER_CREATED | SEC_GROUP | SEC_LINK_ONCE 4374 1.1 christos | SEC_EXCLUDE); 4375 1.1 christos 4376 1.1 christos /* We add a fake section group for each .gnu.linkonce.t.* section, 4377 1.1 christos which isn't in a section group, and its unwind sections. */ 4378 1.1 christos for (sec = abfd->sections; sec != NULL; sec = sec->next) 4379 1.1 christos { 4380 1.1 christos if (elf_sec_group (sec) == NULL 4381 1.1 christos && ((sec->flags & (SEC_LINK_ONCE | SEC_CODE | SEC_GROUP)) 4382 1.1 christos == (SEC_LINK_ONCE | SEC_CODE)) 4383 1.10 christos && startswith (sec->name, ".gnu.linkonce.t.")) 4384 1.1 christos { 4385 1.1 christos name = sec->name + 16; 4386 1.1 christos 4387 1.1 christos amt = strlen (name) + sizeof (".gnu.linkonce.ia64unwi."); 4388 1.1 christos unwi_name = bfd_alloc (abfd, amt); 4389 1.1 christos if (!unwi_name) 4390 1.10 christos return false; 4391 1.1 christos 4392 1.1 christos strcpy (stpcpy (unwi_name, ".gnu.linkonce.ia64unwi."), name); 4393 1.1 christos unwi = bfd_get_section_by_name (abfd, unwi_name); 4394 1.1 christos 4395 1.1 christos amt = strlen (name) + sizeof (".gnu.linkonce.ia64unw."); 4396 1.1 christos unw_name = bfd_alloc (abfd, amt); 4397 1.1 christos if (!unw_name) 4398 1.10 christos return false; 4399 1.1 christos 4400 1.1 christos strcpy (stpcpy (unw_name, ".gnu.linkonce.ia64unw."), name); 4401 1.1 christos unw = bfd_get_section_by_name (abfd, unw_name); 4402 1.1 christos 4403 1.1 christos /* We need to create a fake group section for it and its 4404 1.1 christos unwind sections. */ 4405 1.1 christos group = bfd_make_section_anyway_with_flags (abfd, name, 4406 1.1 christos flags); 4407 1.1 christos if (group == NULL) 4408 1.10 christos return false; 4409 1.1 christos 4410 1.1 christos /* Move the fake group section to the beginning. */ 4411 1.1 christos bfd_section_list_remove (abfd, group); 4412 1.1 christos bfd_section_list_prepend (abfd, group); 4413 1.1 christos 4414 1.1 christos elf_next_in_group (group) = sec; 4415 1.1 christos 4416 1.1 christos elf_group_name (sec) = name; 4417 1.1 christos elf_next_in_group (sec) = sec; 4418 1.1 christos elf_sec_group (sec) = group; 4419 1.1 christos 4420 1.1 christos if (unwi) 4421 1.1 christos { 4422 1.1 christos elf_group_name (unwi) = name; 4423 1.1 christos elf_next_in_group (unwi) = sec; 4424 1.1 christos elf_next_in_group (sec) = unwi; 4425 1.1 christos elf_sec_group (unwi) = group; 4426 1.1 christos } 4427 1.1 christos 4428 1.1 christos if (unw) 4429 1.1 christos { 4430 1.1 christos elf_group_name (unw) = name; 4431 1.1 christos if (unwi) 4432 1.1 christos { 4433 1.1 christos elf_next_in_group (unw) = elf_next_in_group (unwi); 4434 1.1 christos elf_next_in_group (unwi) = unw; 4435 1.1 christos } 4436 1.1 christos else 4437 1.1 christos { 4438 1.1 christos elf_next_in_group (unw) = sec; 4439 1.1 christos elf_next_in_group (sec) = unw; 4440 1.1 christos } 4441 1.1 christos elf_sec_group (unw) = group; 4442 1.1 christos } 4443 1.1 christos 4444 1.1 christos /* Fake SHT_GROUP section header. */ 4445 1.1 christos elf_section_data (group)->this_hdr.bfd_section = group; 4446 1.1 christos elf_section_data (group)->this_hdr.sh_type = SHT_GROUP; 4447 1.1 christos } 4448 1.1 christos } 4449 1.10 christos return true; 4450 1.1 christos } 4451 1.1 christos 4452 1.1 christos /* Handle an IA-64 specific section when reading an object file. This 4453 1.1 christos is called when bfd_section_from_shdr finds a section with an unknown 4454 1.1 christos type. */ 4455 1.1 christos 4456 1.10 christos static bool 4457 1.1 christos elf64_vms_section_from_shdr (bfd *abfd, 4458 1.1 christos Elf_Internal_Shdr *hdr, 4459 1.1 christos const char *name, 4460 1.1 christos int shindex) 4461 1.1 christos { 4462 1.1 christos flagword secflags = 0; 4463 1.1 christos 4464 1.1 christos switch (hdr->sh_type) 4465 1.1 christos { 4466 1.1 christos case SHT_IA_64_VMS_TRACE: 4467 1.1 christos case SHT_IA_64_VMS_DEBUG: 4468 1.1 christos case SHT_IA_64_VMS_DEBUG_STR: 4469 1.1 christos secflags = SEC_DEBUGGING; 4470 1.1 christos break; 4471 1.1 christos 4472 1.1 christos case SHT_IA_64_UNWIND: 4473 1.1 christos case SHT_IA_64_HP_OPT_ANOT: 4474 1.1 christos break; 4475 1.1 christos 4476 1.1 christos case SHT_IA_64_EXT: 4477 1.1 christos if (strcmp (name, ELF_STRING_ia64_archext) != 0) 4478 1.10 christos return false; 4479 1.1 christos break; 4480 1.1 christos 4481 1.1 christos default: 4482 1.10 christos return false; 4483 1.1 christos } 4484 1.1 christos 4485 1.1 christos if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) 4486 1.10 christos return false; 4487 1.1 christos 4488 1.1 christos if (secflags != 0) 4489 1.1 christos { 4490 1.1 christos asection *newsect = hdr->bfd_section; 4491 1.1 christos 4492 1.9 christos if (!bfd_set_section_flags (newsect, 4493 1.9 christos bfd_section_flags (newsect) | secflags)) 4494 1.10 christos return false; 4495 1.1 christos } 4496 1.1 christos 4497 1.10 christos return true; 4498 1.1 christos } 4499 1.1 christos 4500 1.10 christos static bool 4501 1.1 christos elf64_vms_object_p (bfd *abfd) 4502 1.1 christos { 4503 1.1 christos Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd); 4504 1.1 christos Elf_Internal_Phdr *i_phdr = elf_tdata (abfd)->phdr; 4505 1.1 christos unsigned int i; 4506 1.1 christos unsigned int num_text = 0; 4507 1.1 christos unsigned int num_data = 0; 4508 1.1 christos unsigned int num_rodata = 0; 4509 1.1 christos char name[16]; 4510 1.1 christos 4511 1.1 christos if (!elf64_ia64_object_p (abfd)) 4512 1.10 christos return false; 4513 1.1 christos 4514 1.1 christos /* Many VMS compilers do not generate sections for the corresponding 4515 1.1 christos segment. This is boring as binutils tools won't be able to disassemble 4516 1.1 christos the code. So we simply create all the missing sections. */ 4517 1.1 christos for (i = 0; i < i_ehdrp->e_phnum; i++, i_phdr++) 4518 1.1 christos { 4519 1.1 christos /* Is there a section for this segment? */ 4520 1.1 christos bfd_vma base_vma = i_phdr->p_vaddr; 4521 1.1 christos bfd_vma limit_vma = base_vma + i_phdr->p_filesz; 4522 1.1 christos 4523 1.1 christos if (i_phdr->p_type != PT_LOAD) 4524 1.1 christos continue; 4525 1.1 christos 4526 1.1 christos /* We need to cover from base_vms to limit_vma. */ 4527 1.1 christos again: 4528 1.1 christos while (base_vma < limit_vma) 4529 1.1 christos { 4530 1.1 christos bfd_vma next_vma = limit_vma; 4531 1.1 christos asection *nsec; 4532 1.1 christos asection *sec; 4533 1.1 christos flagword flags; 4534 1.1 christos char *nname = NULL; 4535 1.1 christos 4536 1.1 christos /* Find a section covering [base_vma;limit_vma) */ 4537 1.1 christos for (sec = abfd->sections; sec != NULL; sec = sec->next) 4538 1.1 christos { 4539 1.1 christos /* Skip uninteresting sections (either not in memory or 4540 1.1 christos below base_vma. */ 4541 1.1 christos if ((sec->flags & (SEC_ALLOC | SEC_LOAD)) == 0 4542 1.1 christos || sec->vma + sec->size <= base_vma) 4543 1.1 christos continue; 4544 1.1 christos if (sec->vma <= base_vma) 4545 1.1 christos { 4546 1.1 christos /* This section covers (maybe partially) the beginning 4547 1.1 christos of the range. */ 4548 1.1 christos base_vma = sec->vma + sec->size; 4549 1.1 christos goto again; 4550 1.1 christos } 4551 1.1 christos if (sec->vma < next_vma) 4552 1.1 christos { 4553 1.1 christos /* This section partially covers the end of the range. 4554 1.1 christos Used to compute the size of the hole. */ 4555 1.1 christos next_vma = sec->vma; 4556 1.1 christos } 4557 1.1 christos } 4558 1.1 christos 4559 1.1 christos /* No section covering [base_vma; next_vma). Create a fake one. */ 4560 1.1 christos flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS; 4561 1.1 christos if (i_phdr->p_flags & PF_X) 4562 1.1 christos { 4563 1.1 christos flags |= SEC_CODE; 4564 1.1 christos if (num_text++ == 0) 4565 1.1 christos nname = ".text"; 4566 1.1 christos else 4567 1.1 christos sprintf (name, ".text$%u", num_text); 4568 1.1 christos } 4569 1.1 christos else if ((i_phdr->p_flags & (PF_R | PF_W)) == PF_R) 4570 1.1 christos { 4571 1.1 christos flags |= SEC_READONLY; 4572 1.1 christos sprintf (name, ".rodata$%u", num_rodata++); 4573 1.1 christos } 4574 1.1 christos else 4575 1.1 christos { 4576 1.1 christos flags |= SEC_DATA; 4577 1.1 christos sprintf (name, ".data$%u", num_data++); 4578 1.1 christos } 4579 1.1 christos 4580 1.1 christos /* Allocate name. */ 4581 1.1 christos if (nname == NULL) 4582 1.1 christos { 4583 1.1 christos size_t name_len = strlen (name) + 1; 4584 1.1 christos nname = bfd_alloc (abfd, name_len); 4585 1.1 christos if (nname == NULL) 4586 1.10 christos return false; 4587 1.1 christos memcpy (nname, name, name_len); 4588 1.1 christos } 4589 1.1 christos 4590 1.1 christos /* Create and fill new section. */ 4591 1.1 christos nsec = bfd_make_section_anyway_with_flags (abfd, nname, flags); 4592 1.1 christos if (nsec == NULL) 4593 1.10 christos return false; 4594 1.1 christos nsec->vma = base_vma; 4595 1.1 christos nsec->size = next_vma - base_vma; 4596 1.1 christos nsec->filepos = i_phdr->p_offset + (base_vma - i_phdr->p_vaddr); 4597 1.1 christos 4598 1.1 christos base_vma = next_vma; 4599 1.1 christos } 4600 1.1 christos } 4601 1.10 christos return true; 4602 1.1 christos } 4603 1.1 christos 4604 1.10 christos static bool 4605 1.9 christos elf64_vms_init_file_header (bfd *abfd, struct bfd_link_info *info) 4606 1.1 christos { 4607 1.9 christos Elf_Internal_Ehdr *i_ehdrp; 4608 1.9 christos 4609 1.9 christos if (!_bfd_elf_init_file_header (abfd, info)) 4610 1.10 christos return false; 4611 1.1 christos 4612 1.9 christos i_ehdrp = elf_elfheader (abfd); 4613 1.1 christos i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_OPENVMS; 4614 1.1 christos i_ehdrp->e_ident[EI_ABIVERSION] = 2; 4615 1.10 christos return true; 4616 1.1 christos } 4617 1.1 christos 4618 1.10 christos static bool 4619 1.1 christos elf64_vms_section_processing (bfd *abfd ATTRIBUTE_UNUSED, 4620 1.1 christos Elf_Internal_Shdr *hdr) 4621 1.1 christos { 4622 1.1 christos if (hdr->bfd_section != NULL) 4623 1.1 christos { 4624 1.9 christos const char *name = bfd_section_name (hdr->bfd_section); 4625 1.1 christos 4626 1.1 christos if (strcmp (name, ".text") == 0) 4627 1.1 christos hdr->sh_flags |= SHF_IA_64_VMS_SHARED; 4628 1.1 christos else if ((strcmp (name, ".debug") == 0) 4629 1.1 christos || (strcmp (name, ".debug_abbrev") == 0) 4630 1.1 christos || (strcmp (name, ".debug_aranges") == 0) 4631 1.1 christos || (strcmp (name, ".debug_frame") == 0) 4632 1.1 christos || (strcmp (name, ".debug_info") == 0) 4633 1.1 christos || (strcmp (name, ".debug_loc") == 0) 4634 1.1 christos || (strcmp (name, ".debug_macinfo") == 0) 4635 1.1 christos || (strcmp (name, ".debug_pubnames") == 0) 4636 1.1 christos || (strcmp (name, ".debug_pubtypes") == 0)) 4637 1.1 christos hdr->sh_type = SHT_IA_64_VMS_DEBUG; 4638 1.1 christos else if ((strcmp (name, ".debug_line") == 0) 4639 1.1 christos || (strcmp (name, ".debug_ranges") == 0) 4640 1.1 christos || (strcmp (name, ".trace_info") == 0) 4641 1.1 christos || (strcmp (name, ".trace_abbrev") == 0) 4642 1.1 christos || (strcmp (name, ".trace_aranges") == 0)) 4643 1.1 christos hdr->sh_type = SHT_IA_64_VMS_TRACE; 4644 1.1 christos else if (strcmp (name, ".debug_str") == 0) 4645 1.1 christos hdr->sh_type = SHT_IA_64_VMS_DEBUG_STR; 4646 1.1 christos } 4647 1.1 christos 4648 1.10 christos return true; 4649 1.1 christos } 4650 1.1 christos 4651 1.1 christos /* The final processing done just before writing out a VMS IA-64 ELF 4652 1.1 christos object file. */ 4653 1.1 christos 4654 1.10 christos static bool 4655 1.9 christos elf64_vms_final_write_processing (bfd *abfd) 4656 1.1 christos { 4657 1.1 christos Elf_Internal_Shdr *hdr; 4658 1.1 christos asection *s; 4659 1.1 christos int unwind_info_sect_idx = 0; 4660 1.1 christos 4661 1.1 christos for (s = abfd->sections; s; s = s->next) 4662 1.1 christos { 4663 1.1 christos hdr = &elf_section_data (s)->this_hdr; 4664 1.1 christos 4665 1.9 christos if (strcmp (bfd_section_name (hdr->bfd_section), 4666 1.1 christos ".IA_64.unwind_info") == 0) 4667 1.1 christos unwind_info_sect_idx = elf_section_data (s)->this_idx; 4668 1.1 christos 4669 1.1 christos switch (hdr->sh_type) 4670 1.1 christos { 4671 1.1 christos case SHT_IA_64_UNWIND: 4672 1.1 christos /* VMS requires sh_info to point to the unwind info section. */ 4673 1.8 christos hdr->sh_info = unwind_info_sect_idx; 4674 1.1 christos break; 4675 1.1 christos } 4676 1.1 christos } 4677 1.1 christos 4678 1.1 christos if (! elf_flags_init (abfd)) 4679 1.1 christos { 4680 1.1 christos unsigned long flags = 0; 4681 1.1 christos 4682 1.1 christos if (abfd->xvec->byteorder == BFD_ENDIAN_BIG) 4683 1.1 christos flags |= EF_IA_64_BE; 4684 1.1 christos if (bfd_get_mach (abfd) == bfd_mach_ia64_elf64) 4685 1.1 christos flags |= EF_IA_64_ABI64; 4686 1.1 christos 4687 1.1 christos elf_elfheader (abfd)->e_flags = flags; 4688 1.10 christos elf_flags_init (abfd) = true; 4689 1.1 christos } 4690 1.9 christos return _bfd_elf_final_write_processing (abfd); 4691 1.1 christos } 4692 1.1 christos 4693 1.10 christos static bool 4694 1.1 christos elf64_vms_write_shdrs_and_ehdr (bfd *abfd) 4695 1.1 christos { 4696 1.1 christos unsigned char needed_count[8]; 4697 1.1 christos 4698 1.1 christos if (!bfd_elf64_write_shdrs_and_ehdr (abfd)) 4699 1.10 christos return false; 4700 1.1 christos 4701 1.1 christos bfd_putl64 (elf_ia64_vms_tdata (abfd)->needed_count, needed_count); 4702 1.1 christos 4703 1.1 christos if (bfd_seek (abfd, sizeof (Elf64_External_Ehdr), SEEK_SET) != 0 4704 1.11 christos || bfd_write (needed_count, 8, abfd) != 8) 4705 1.10 christos return false; 4706 1.1 christos 4707 1.10 christos return true; 4708 1.1 christos } 4709 1.1 christos 4710 1.10 christos static bool 4711 1.1 christos elf64_vms_close_and_cleanup (bfd *abfd) 4712 1.1 christos { 4713 1.11 christos bool ret = true; 4714 1.11 christos if (bfd_get_format (abfd) == bfd_object 4715 1.11 christos && bfd_write_p (abfd)) 4716 1.1 christos { 4717 1.1 christos long isize; 4718 1.1 christos 4719 1.1 christos /* Pad to 8 byte boundary for IPF/VMS. */ 4720 1.1 christos isize = bfd_get_size (abfd); 4721 1.1 christos if ((isize & 7) != 0) 4722 1.1 christos { 4723 1.11 christos unsigned int ishort = 8 - (isize & 7); 4724 1.10 christos uint64_t pad = 0; 4725 1.1 christos 4726 1.11 christos if (bfd_seek (abfd, isize, SEEK_SET) != 0 4727 1.11 christos || bfd_write (&pad, ishort, abfd) != ishort) 4728 1.11 christos ret = false; 4729 1.1 christos } 4730 1.1 christos } 4731 1.1 christos 4732 1.11 christos return _bfd_generic_close_and_cleanup (abfd) && ret; 4733 1.1 christos } 4734 1.1 christos 4735 1.1 christos /* Add symbols from an ELF object file to the linker hash table. */ 4736 1.1 christos 4737 1.10 christos static bool 4738 1.1 christos elf64_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) 4739 1.1 christos { 4740 1.1 christos Elf_Internal_Shdr *hdr; 4741 1.1 christos bfd_size_type symcount; 4742 1.1 christos bfd_size_type extsymcount; 4743 1.1 christos bfd_size_type extsymoff; 4744 1.1 christos struct elf_link_hash_entry **sym_hash; 4745 1.10 christos bool dynamic; 4746 1.1 christos Elf_Internal_Sym *isymbuf = NULL; 4747 1.1 christos Elf_Internal_Sym *isym; 4748 1.1 christos Elf_Internal_Sym *isymend; 4749 1.1 christos const struct elf_backend_data *bed; 4750 1.1 christos struct elf_link_hash_table *htab; 4751 1.1 christos bfd_size_type amt; 4752 1.1 christos 4753 1.1 christos htab = elf_hash_table (info); 4754 1.1 christos bed = get_elf_backend_data (abfd); 4755 1.1 christos 4756 1.1 christos if ((abfd->flags & DYNAMIC) == 0) 4757 1.10 christos dynamic = false; 4758 1.1 christos else 4759 1.1 christos { 4760 1.10 christos dynamic = true; 4761 1.1 christos 4762 1.1 christos /* You can't use -r against a dynamic object. Also, there's no 4763 1.1 christos hope of using a dynamic object which does not exactly match 4764 1.1 christos the format of the output file. */ 4765 1.6 christos if (bfd_link_relocatable (info) 4766 1.10 christos || !is_elf_hash_table (&htab->root) 4767 1.1 christos || info->output_bfd->xvec != abfd->xvec) 4768 1.1 christos { 4769 1.6 christos if (bfd_link_relocatable (info)) 4770 1.1 christos bfd_set_error (bfd_error_invalid_operation); 4771 1.1 christos else 4772 1.1 christos bfd_set_error (bfd_error_wrong_format); 4773 1.1 christos goto error_return; 4774 1.1 christos } 4775 1.1 christos } 4776 1.1 christos 4777 1.1 christos if (! dynamic) 4778 1.1 christos { 4779 1.1 christos /* If we are creating a shared library, create all the dynamic 4780 1.1 christos sections immediately. We need to attach them to something, 4781 1.1 christos so we attach them to this BFD, provided it is the right 4782 1.1 christos format. FIXME: If there are no input BFD's of the same 4783 1.1 christos format as the output, we can't make a shared library. */ 4784 1.6 christos if (bfd_link_pic (info) 4785 1.10 christos && is_elf_hash_table (&htab->root) 4786 1.1 christos && info->output_bfd->xvec == abfd->xvec 4787 1.1 christos && !htab->dynamic_sections_created) 4788 1.1 christos { 4789 1.1 christos if (! elf64_ia64_create_dynamic_sections (abfd, info)) 4790 1.1 christos goto error_return; 4791 1.1 christos } 4792 1.1 christos } 4793 1.10 christos else if (!is_elf_hash_table (&htab->root)) 4794 1.1 christos goto error_return; 4795 1.1 christos else 4796 1.1 christos { 4797 1.1 christos asection *s; 4798 1.1 christos bfd_byte *dynbuf; 4799 1.1 christos bfd_byte *extdyn; 4800 1.1 christos 4801 1.1 christos /* ld --just-symbols and dynamic objects don't mix very well. 4802 1.1 christos ld shouldn't allow it. */ 4803 1.1 christos if ((s = abfd->sections) != NULL 4804 1.1 christos && s->sec_info_type == SEC_INFO_TYPE_JUST_SYMS) 4805 1.1 christos abort (); 4806 1.1 christos 4807 1.1 christos /* Be sure there are dynamic sections. */ 4808 1.1 christos if (! elf64_ia64_create_dynamic_sections (htab->dynobj, info)) 4809 1.8 christos goto error_return; 4810 1.1 christos 4811 1.1 christos s = bfd_get_section_by_name (abfd, ".dynamic"); 4812 1.1 christos if (s == NULL) 4813 1.8 christos { 4814 1.8 christos /* VMS libraries do not have dynamic sections. Create one from 4815 1.8 christos the segment. */ 4816 1.8 christos Elf_Internal_Phdr *phdr; 4817 1.8 christos unsigned int i, phnum; 4818 1.8 christos 4819 1.8 christos phdr = elf_tdata (abfd)->phdr; 4820 1.8 christos if (phdr == NULL) 4821 1.8 christos goto error_return; 4822 1.8 christos phnum = elf_elfheader (abfd)->e_phnum; 4823 1.8 christos for (i = 0; i < phnum; phdr++) 4824 1.8 christos if (phdr->p_type == PT_DYNAMIC) 4825 1.8 christos { 4826 1.8 christos s = bfd_make_section (abfd, ".dynamic"); 4827 1.8 christos if (s == NULL) 4828 1.8 christos goto error_return; 4829 1.8 christos s->vma = phdr->p_vaddr; 4830 1.8 christos s->lma = phdr->p_paddr; 4831 1.8 christos s->size = phdr->p_filesz; 4832 1.8 christos s->filepos = phdr->p_offset; 4833 1.8 christos s->flags |= SEC_HAS_CONTENTS; 4834 1.8 christos s->alignment_power = bfd_log2 (phdr->p_align); 4835 1.8 christos break; 4836 1.8 christos } 4837 1.8 christos if (s == NULL) 4838 1.8 christos goto error_return; 4839 1.8 christos } 4840 1.1 christos 4841 1.1 christos /* Extract IDENT. */ 4842 1.1 christos if (!bfd_malloc_and_get_section (abfd, s, &dynbuf)) 4843 1.8 christos { 4844 1.9 christos error_free_dyn: 4845 1.8 christos free (dynbuf); 4846 1.8 christos goto error_return; 4847 1.8 christos } 4848 1.1 christos 4849 1.1 christos for (extdyn = dynbuf; 4850 1.10 christos (size_t) (dynbuf + s->size - extdyn) >= bed->s->sizeof_dyn; 4851 1.8 christos extdyn += bed->s->sizeof_dyn) 4852 1.8 christos { 4853 1.8 christos Elf_Internal_Dyn dyn; 4854 1.8 christos 4855 1.8 christos bed->s->swap_dyn_in (abfd, extdyn, &dyn); 4856 1.8 christos if (dyn.d_tag == DT_IA_64_VMS_IDENT) 4857 1.8 christos { 4858 1.10 christos uint64_t tagv = dyn.d_un.d_val; 4859 1.8 christos elf_ia64_vms_ident (abfd) = tagv; 4860 1.8 christos break; 4861 1.8 christos } 4862 1.8 christos } 4863 1.1 christos if (extdyn >= dynbuf + s->size) 4864 1.8 christos { 4865 1.8 christos /* Ident not found. */ 4866 1.8 christos goto error_free_dyn; 4867 1.8 christos } 4868 1.1 christos free (dynbuf); 4869 1.1 christos 4870 1.1 christos /* We do not want to include any of the sections in a dynamic 4871 1.1 christos object in the output file. We hack by simply clobbering the 4872 1.1 christos list of sections in the BFD. This could be handled more 4873 1.1 christos cleanly by, say, a new section flag; the existing 4874 1.1 christos SEC_NEVER_LOAD flag is not the one we want, because that one 4875 1.1 christos still implies that the section takes up space in the output 4876 1.1 christos file. */ 4877 1.1 christos bfd_section_list_clear (abfd); 4878 1.1 christos 4879 1.1 christos /* FIXME: should we detect if this library is already included ? 4880 1.8 christos This should be harmless and shouldn't happen in practice. */ 4881 1.1 christos } 4882 1.1 christos 4883 1.1 christos hdr = &elf_tdata (abfd)->symtab_hdr; 4884 1.1 christos symcount = hdr->sh_size / bed->s->sizeof_sym; 4885 1.1 christos 4886 1.1 christos /* The sh_info field of the symtab header tells us where the 4887 1.1 christos external symbols start. We don't care about the local symbols at 4888 1.1 christos this point. */ 4889 1.1 christos extsymcount = symcount - hdr->sh_info; 4890 1.1 christos extsymoff = hdr->sh_info; 4891 1.1 christos 4892 1.1 christos sym_hash = NULL; 4893 1.1 christos if (extsymcount != 0) 4894 1.1 christos { 4895 1.1 christos isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff, 4896 1.1 christos NULL, NULL, NULL); 4897 1.1 christos if (isymbuf == NULL) 4898 1.1 christos goto error_return; 4899 1.1 christos 4900 1.1 christos /* We store a pointer to the hash table entry for each external 4901 1.1 christos symbol. */ 4902 1.1 christos amt = extsymcount * sizeof (struct elf_link_hash_entry *); 4903 1.1 christos sym_hash = (struct elf_link_hash_entry **) bfd_alloc (abfd, amt); 4904 1.1 christos if (sym_hash == NULL) 4905 1.1 christos goto error_free_sym; 4906 1.1 christos elf_sym_hashes (abfd) = sym_hash; 4907 1.1 christos } 4908 1.1 christos 4909 1.1 christos for (isym = isymbuf, isymend = isymbuf + extsymcount; 4910 1.1 christos isym < isymend; 4911 1.1 christos isym++, sym_hash++) 4912 1.1 christos { 4913 1.1 christos int bind; 4914 1.1 christos bfd_vma value; 4915 1.1 christos asection *sec, *new_sec; 4916 1.1 christos flagword flags; 4917 1.1 christos const char *name; 4918 1.1 christos struct elf_link_hash_entry *h; 4919 1.10 christos bool definition; 4920 1.10 christos bool size_change_ok; 4921 1.10 christos bool type_change_ok; 4922 1.10 christos bool common; 4923 1.1 christos unsigned int old_alignment; 4924 1.1 christos bfd *old_bfd; 4925 1.1 christos 4926 1.1 christos flags = BSF_NO_FLAGS; 4927 1.1 christos sec = NULL; 4928 1.1 christos value = isym->st_value; 4929 1.1 christos *sym_hash = NULL; 4930 1.1 christos common = bed->common_definition (isym); 4931 1.1 christos 4932 1.1 christos bind = ELF_ST_BIND (isym->st_info); 4933 1.1 christos switch (bind) 4934 1.1 christos { 4935 1.1 christos case STB_LOCAL: 4936 1.1 christos /* This should be impossible, since ELF requires that all 4937 1.1 christos global symbols follow all local symbols, and that sh_info 4938 1.1 christos point to the first global symbol. Unfortunately, Irix 5 4939 1.1 christos screws this up. */ 4940 1.1 christos continue; 4941 1.1 christos 4942 1.1 christos case STB_GLOBAL: 4943 1.1 christos if (isym->st_shndx != SHN_UNDEF && !common) 4944 1.1 christos flags = BSF_GLOBAL; 4945 1.1 christos break; 4946 1.1 christos 4947 1.1 christos case STB_WEAK: 4948 1.1 christos flags = BSF_WEAK; 4949 1.1 christos break; 4950 1.1 christos 4951 1.1 christos case STB_GNU_UNIQUE: 4952 1.1 christos flags = BSF_GNU_UNIQUE; 4953 1.1 christos break; 4954 1.1 christos 4955 1.1 christos default: 4956 1.1 christos /* Leave it up to the processor backend. */ 4957 1.1 christos break; 4958 1.1 christos } 4959 1.1 christos 4960 1.1 christos if (isym->st_shndx == SHN_UNDEF) 4961 1.1 christos sec = bfd_und_section_ptr; 4962 1.1 christos else if (isym->st_shndx == SHN_ABS) 4963 1.1 christos sec = bfd_abs_section_ptr; 4964 1.1 christos else if (isym->st_shndx == SHN_COMMON) 4965 1.1 christos { 4966 1.1 christos sec = bfd_com_section_ptr; 4967 1.1 christos /* What ELF calls the size we call the value. What ELF 4968 1.1 christos calls the value we call the alignment. */ 4969 1.1 christos value = isym->st_size; 4970 1.1 christos } 4971 1.1 christos else 4972 1.1 christos { 4973 1.1 christos sec = bfd_section_from_elf_index (abfd, isym->st_shndx); 4974 1.1 christos if (sec == NULL) 4975 1.1 christos sec = bfd_abs_section_ptr; 4976 1.1 christos else if (sec->kept_section) 4977 1.1 christos { 4978 1.1 christos /* Symbols from discarded section are undefined. We keep 4979 1.1 christos its visibility. */ 4980 1.1 christos sec = bfd_und_section_ptr; 4981 1.1 christos isym->st_shndx = SHN_UNDEF; 4982 1.1 christos } 4983 1.1 christos else if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0) 4984 1.1 christos value -= sec->vma; 4985 1.1 christos } 4986 1.1 christos 4987 1.1 christos name = bfd_elf_string_from_elf_section (abfd, hdr->sh_link, 4988 1.1 christos isym->st_name); 4989 1.1 christos if (name == NULL) 4990 1.1 christos goto error_free_vers; 4991 1.1 christos 4992 1.1 christos if (bed->elf_add_symbol_hook) 4993 1.1 christos { 4994 1.1 christos if (! (*bed->elf_add_symbol_hook) (abfd, info, isym, &name, &flags, 4995 1.1 christos &sec, &value)) 4996 1.1 christos goto error_free_vers; 4997 1.1 christos 4998 1.1 christos /* The hook function sets the name to NULL if this symbol 4999 1.1 christos should be skipped for some reason. */ 5000 1.1 christos if (name == NULL) 5001 1.1 christos continue; 5002 1.1 christos } 5003 1.1 christos 5004 1.1 christos /* Sanity check that all possibilities were handled. */ 5005 1.1 christos if (sec == NULL) 5006 1.1 christos { 5007 1.1 christos bfd_set_error (bfd_error_bad_value); 5008 1.1 christos goto error_free_vers; 5009 1.1 christos } 5010 1.1 christos 5011 1.1 christos if (bfd_is_und_section (sec) 5012 1.1 christos || bfd_is_com_section (sec)) 5013 1.10 christos definition = false; 5014 1.1 christos else 5015 1.10 christos definition = true; 5016 1.1 christos 5017 1.10 christos size_change_ok = false; 5018 1.1 christos type_change_ok = bed->type_change_ok; 5019 1.1 christos old_alignment = 0; 5020 1.1 christos old_bfd = NULL; 5021 1.1 christos new_sec = sec; 5022 1.1 christos 5023 1.1 christos if (! bfd_is_und_section (sec)) 5024 1.10 christos h = elf_link_hash_lookup (htab, name, true, false, false); 5025 1.1 christos else 5026 1.8 christos h = ((struct elf_link_hash_entry *) bfd_wrapped_link_hash_lookup 5027 1.10 christos (abfd, info, name, true, false, false)); 5028 1.1 christos if (h == NULL) 5029 1.8 christos goto error_free_sym; 5030 1.1 christos 5031 1.1 christos *sym_hash = h; 5032 1.1 christos 5033 1.10 christos if (is_elf_hash_table (&htab->root)) 5034 1.1 christos { 5035 1.1 christos while (h->root.type == bfd_link_hash_indirect 5036 1.1 christos || h->root.type == bfd_link_hash_warning) 5037 1.1 christos h = (struct elf_link_hash_entry *) h->root.u.i.link; 5038 1.1 christos 5039 1.1 christos /* Remember the old alignment if this is a common symbol, so 5040 1.1 christos that we don't reduce the alignment later on. We can't 5041 1.1 christos check later, because _bfd_generic_link_add_one_symbol 5042 1.1 christos will set a default for the alignment which we want to 5043 1.1 christos override. We also remember the old bfd where the existing 5044 1.1 christos definition comes from. */ 5045 1.1 christos switch (h->root.type) 5046 1.1 christos { 5047 1.1 christos default: 5048 1.1 christos break; 5049 1.1 christos 5050 1.1 christos case bfd_link_hash_defined: 5051 1.8 christos if (abfd->selective_search) 5052 1.8 christos continue; 5053 1.8 christos /* Fall-through. */ 5054 1.1 christos case bfd_link_hash_defweak: 5055 1.1 christos old_bfd = h->root.u.def.section->owner; 5056 1.1 christos break; 5057 1.1 christos 5058 1.1 christos case bfd_link_hash_common: 5059 1.1 christos old_bfd = h->root.u.c.p->section->owner; 5060 1.1 christos old_alignment = h->root.u.c.p->alignment_power; 5061 1.1 christos break; 5062 1.1 christos } 5063 1.1 christos } 5064 1.1 christos 5065 1.1 christos if (! (_bfd_generic_link_add_one_symbol 5066 1.10 christos (info, abfd, name, flags, sec, value, NULL, false, bed->collect, 5067 1.1 christos (struct bfd_link_hash_entry **) sym_hash))) 5068 1.1 christos goto error_free_vers; 5069 1.1 christos 5070 1.1 christos h = *sym_hash; 5071 1.1 christos while (h->root.type == bfd_link_hash_indirect 5072 1.1 christos || h->root.type == bfd_link_hash_warning) 5073 1.1 christos h = (struct elf_link_hash_entry *) h->root.u.i.link; 5074 1.1 christos 5075 1.1 christos *sym_hash = h; 5076 1.1 christos if (definition) 5077 1.1 christos h->unique_global = (flags & BSF_GNU_UNIQUE) != 0; 5078 1.1 christos 5079 1.1 christos /* Set the alignment of a common symbol. */ 5080 1.1 christos if ((common || bfd_is_com_section (sec)) 5081 1.1 christos && h->root.type == bfd_link_hash_common) 5082 1.1 christos { 5083 1.1 christos unsigned int align; 5084 1.1 christos 5085 1.1 christos if (common) 5086 1.1 christos align = bfd_log2 (isym->st_value); 5087 1.1 christos else 5088 1.1 christos { 5089 1.1 christos /* The new symbol is a common symbol in a shared object. 5090 1.1 christos We need to get the alignment from the section. */ 5091 1.1 christos align = new_sec->alignment_power; 5092 1.1 christos } 5093 1.1 christos if (align > old_alignment 5094 1.1 christos /* Permit an alignment power of zero if an alignment of one 5095 1.1 christos is specified and no other alignments have been specified. */ 5096 1.1 christos || (isym->st_value == 1 && old_alignment == 0)) 5097 1.1 christos h->root.u.c.p->alignment_power = align; 5098 1.1 christos else 5099 1.1 christos h->root.u.c.p->alignment_power = old_alignment; 5100 1.1 christos } 5101 1.1 christos 5102 1.10 christos if (is_elf_hash_table (&htab->root)) 5103 1.1 christos { 5104 1.1 christos /* Check the alignment when a common symbol is involved. This 5105 1.1 christos can change when a common symbol is overridden by a normal 5106 1.1 christos definition or a common symbol is ignored due to the old 5107 1.1 christos normal definition. We need to make sure the maximum 5108 1.1 christos alignment is maintained. */ 5109 1.1 christos if ((old_alignment || common) 5110 1.1 christos && h->root.type != bfd_link_hash_common) 5111 1.1 christos { 5112 1.1 christos unsigned int common_align; 5113 1.1 christos unsigned int normal_align; 5114 1.1 christos unsigned int symbol_align; 5115 1.1 christos bfd *normal_bfd; 5116 1.1 christos bfd *common_bfd; 5117 1.1 christos 5118 1.1 christos symbol_align = ffs (h->root.u.def.value) - 1; 5119 1.1 christos if (h->root.u.def.section->owner != NULL 5120 1.1 christos && (h->root.u.def.section->owner->flags & DYNAMIC) == 0) 5121 1.1 christos { 5122 1.1 christos normal_align = h->root.u.def.section->alignment_power; 5123 1.1 christos if (normal_align > symbol_align) 5124 1.1 christos normal_align = symbol_align; 5125 1.1 christos } 5126 1.1 christos else 5127 1.1 christos normal_align = symbol_align; 5128 1.1 christos 5129 1.1 christos if (old_alignment) 5130 1.1 christos { 5131 1.1 christos common_align = old_alignment; 5132 1.1 christos common_bfd = old_bfd; 5133 1.1 christos normal_bfd = abfd; 5134 1.1 christos } 5135 1.1 christos else 5136 1.1 christos { 5137 1.1 christos common_align = bfd_log2 (isym->st_value); 5138 1.1 christos common_bfd = abfd; 5139 1.1 christos normal_bfd = old_bfd; 5140 1.1 christos } 5141 1.1 christos 5142 1.1 christos if (normal_align < common_align) 5143 1.1 christos { 5144 1.1 christos /* PR binutils/2735 */ 5145 1.1 christos if (normal_bfd == NULL) 5146 1.7 christos _bfd_error_handler 5147 1.7 christos /* xgettext:c-format */ 5148 1.8 christos (_("warning: alignment %u of common symbol `%s' in %pB" 5149 1.8 christos " is greater than the alignment (%u) of its section %pA"), 5150 1.7 christos 1 << common_align, name, common_bfd, 5151 1.7 christos 1 << normal_align, h->root.u.def.section); 5152 1.1 christos else 5153 1.7 christos _bfd_error_handler 5154 1.7 christos /* xgettext:c-format */ 5155 1.8 christos (_("warning: alignment %u of symbol `%s' in %pB" 5156 1.8 christos " is smaller than %u in %pB"), 5157 1.7 christos 1 << normal_align, name, normal_bfd, 5158 1.7 christos 1 << common_align, common_bfd); 5159 1.1 christos } 5160 1.1 christos } 5161 1.1 christos 5162 1.1 christos /* Remember the symbol size if it isn't undefined. */ 5163 1.1 christos if ((isym->st_size != 0 && isym->st_shndx != SHN_UNDEF) 5164 1.1 christos && (definition || h->size == 0)) 5165 1.1 christos { 5166 1.1 christos if (h->size != 0 5167 1.1 christos && h->size != isym->st_size 5168 1.1 christos && ! size_change_ok) 5169 1.7 christos _bfd_error_handler 5170 1.7 christos /* xgettext:c-format */ 5171 1.8 christos (_("warning: size of symbol `%s' changed" 5172 1.8 christos " from %" PRIu64 " in %pB to %" PRIu64 " in %pB"), 5173 1.8 christos name, (uint64_t) h->size, old_bfd, 5174 1.8 christos (uint64_t) isym->st_size, abfd); 5175 1.1 christos 5176 1.1 christos h->size = isym->st_size; 5177 1.1 christos } 5178 1.1 christos 5179 1.1 christos /* If this is a common symbol, then we always want H->SIZE 5180 1.1 christos to be the size of the common symbol. The code just above 5181 1.1 christos won't fix the size if a common symbol becomes larger. We 5182 1.1 christos don't warn about a size change here, because that is 5183 1.1 christos covered by --warn-common. Allow changed between different 5184 1.1 christos function types. */ 5185 1.1 christos if (h->root.type == bfd_link_hash_common) 5186 1.1 christos h->size = h->root.u.c.size; 5187 1.1 christos 5188 1.1 christos if (ELF_ST_TYPE (isym->st_info) != STT_NOTYPE 5189 1.1 christos && (definition || h->type == STT_NOTYPE)) 5190 1.1 christos { 5191 1.1 christos unsigned int type = ELF_ST_TYPE (isym->st_info); 5192 1.1 christos 5193 1.1 christos if (h->type != type) 5194 1.1 christos { 5195 1.1 christos if (h->type != STT_NOTYPE && ! type_change_ok) 5196 1.7 christos _bfd_error_handler 5197 1.7 christos /* xgettext:c-format */ 5198 1.8 christos (_("warning: type of symbol `%s' changed" 5199 1.8 christos " from %d to %d in %pB"), 5200 1.7 christos name, h->type, type, abfd); 5201 1.1 christos 5202 1.1 christos h->type = type; 5203 1.1 christos } 5204 1.1 christos } 5205 1.1 christos 5206 1.1 christos /* Set a flag in the hash table entry indicating the type of 5207 1.1 christos reference or definition we just found. Keep a count of 5208 1.1 christos the number of dynamic symbols we find. A dynamic symbol 5209 1.1 christos is one which is referenced or defined by both a regular 5210 1.1 christos object and a shared object. */ 5211 1.1 christos if (! dynamic) 5212 1.1 christos { 5213 1.1 christos if (! definition) 5214 1.1 christos { 5215 1.1 christos h->ref_regular = 1; 5216 1.1 christos if (bind != STB_WEAK) 5217 1.1 christos h->ref_regular_nonweak = 1; 5218 1.1 christos } 5219 1.1 christos else 5220 1.1 christos { 5221 1.8 christos BFD_ASSERT (!h->def_dynamic); 5222 1.1 christos h->def_regular = 1; 5223 1.1 christos } 5224 1.1 christos } 5225 1.1 christos else 5226 1.1 christos { 5227 1.1 christos BFD_ASSERT (definition); 5228 1.8 christos h->def_dynamic = 1; 5229 1.8 christos h->dynindx = -2; 5230 1.8 christos ((struct elf64_ia64_link_hash_entry *)h)->shl = abfd; 5231 1.1 christos } 5232 1.1 christos } 5233 1.1 christos } 5234 1.1 christos 5235 1.9 christos free (isymbuf); 5236 1.9 christos isymbuf = NULL; 5237 1.1 christos 5238 1.1 christos /* If this object is the same format as the output object, and it is 5239 1.1 christos not a shared library, then let the backend look through the 5240 1.1 christos relocs. 5241 1.1 christos 5242 1.1 christos This is required to build global offset table entries and to 5243 1.1 christos arrange for dynamic relocs. It is not required for the 5244 1.1 christos particular common case of linking non PIC code, even when linking 5245 1.1 christos against shared libraries, but unfortunately there is no way of 5246 1.1 christos knowing whether an object file has been compiled PIC or not. 5247 1.1 christos Looking through the relocs is not particularly time consuming. 5248 1.1 christos The problem is that we must either (1) keep the relocs in memory, 5249 1.1 christos which causes the linker to require additional runtime memory or 5250 1.1 christos (2) read the relocs twice from the input file, which wastes time. 5251 1.1 christos This would be a good case for using mmap. 5252 1.1 christos 5253 1.1 christos I have no idea how to handle linking PIC code into a file of a 5254 1.1 christos different format. It probably can't be done. */ 5255 1.1 christos if (! dynamic 5256 1.10 christos && is_elf_hash_table (&htab->root) 5257 1.1 christos && bed->check_relocs != NULL 5258 1.1 christos && (*bed->relocs_compatible) (abfd->xvec, info->output_bfd->xvec)) 5259 1.1 christos { 5260 1.1 christos asection *o; 5261 1.1 christos 5262 1.1 christos for (o = abfd->sections; o != NULL; o = o->next) 5263 1.1 christos { 5264 1.1 christos Elf_Internal_Rela *internal_relocs; 5265 1.10 christos bool ok; 5266 1.1 christos 5267 1.1 christos if ((o->flags & SEC_RELOC) == 0 5268 1.1 christos || o->reloc_count == 0 5269 1.1 christos || ((info->strip == strip_all || info->strip == strip_debugger) 5270 1.1 christos && (o->flags & SEC_DEBUGGING) != 0) 5271 1.1 christos || bfd_is_abs_section (o->output_section)) 5272 1.1 christos continue; 5273 1.1 christos 5274 1.1 christos internal_relocs = _bfd_elf_link_read_relocs (abfd, o, NULL, NULL, 5275 1.1 christos info->keep_memory); 5276 1.1 christos if (internal_relocs == NULL) 5277 1.1 christos goto error_return; 5278 1.1 christos 5279 1.1 christos ok = (*bed->check_relocs) (abfd, info, o, internal_relocs); 5280 1.1 christos 5281 1.1 christos if (elf_section_data (o)->relocs != internal_relocs) 5282 1.1 christos free (internal_relocs); 5283 1.1 christos 5284 1.1 christos if (! ok) 5285 1.1 christos goto error_return; 5286 1.1 christos } 5287 1.1 christos } 5288 1.1 christos 5289 1.10 christos return true; 5290 1.1 christos 5291 1.1 christos error_free_vers: 5292 1.1 christos error_free_sym: 5293 1.9 christos free (isymbuf); 5294 1.1 christos error_return: 5295 1.10 christos return false; 5296 1.1 christos } 5297 1.1 christos 5298 1.10 christos static bool 5299 1.1 christos elf64_vms_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info) 5300 1.1 christos { 5301 1.1 christos int pass; 5302 1.1 christos struct bfd_link_hash_entry **pundef; 5303 1.1 christos struct bfd_link_hash_entry **next_pundef; 5304 1.1 christos 5305 1.1 christos /* We only accept VMS libraries. */ 5306 1.1 christos if (info->output_bfd->xvec != abfd->xvec) 5307 1.1 christos { 5308 1.1 christos bfd_set_error (bfd_error_wrong_format); 5309 1.10 christos return false; 5310 1.1 christos } 5311 1.1 christos 5312 1.1 christos /* The archive_pass field in the archive itself is used to 5313 1.1 christos initialize PASS, since we may search the same archive multiple 5314 1.1 christos times. */ 5315 1.1 christos pass = ++abfd->archive_pass; 5316 1.1 christos 5317 1.1 christos /* Look through the list of undefined symbols. */ 5318 1.1 christos for (pundef = &info->hash->undefs; *pundef != NULL; pundef = next_pundef) 5319 1.1 christos { 5320 1.1 christos struct bfd_link_hash_entry *h; 5321 1.1 christos symindex symidx; 5322 1.1 christos bfd *element; 5323 1.1 christos bfd *orig_element; 5324 1.1 christos 5325 1.1 christos h = *pundef; 5326 1.1 christos next_pundef = &(*pundef)->u.undef.next; 5327 1.1 christos 5328 1.1 christos /* When a symbol is defined, it is not necessarily removed from 5329 1.1 christos the list. */ 5330 1.1 christos if (h->type != bfd_link_hash_undefined 5331 1.1 christos && h->type != bfd_link_hash_common) 5332 1.1 christos { 5333 1.1 christos /* Remove this entry from the list, for general cleanliness 5334 1.1 christos and because we are going to look through the list again 5335 1.1 christos if we search any more libraries. We can't remove the 5336 1.1 christos entry if it is the tail, because that would lose any 5337 1.1 christos entries we add to the list later on. */ 5338 1.1 christos if (*pundef != info->hash->undefs_tail) 5339 1.8 christos { 5340 1.8 christos *pundef = *next_pundef; 5341 1.8 christos next_pundef = pundef; 5342 1.8 christos } 5343 1.1 christos continue; 5344 1.1 christos } 5345 1.1 christos 5346 1.1 christos /* Look for this symbol in the archive hash table. */ 5347 1.1 christos symidx = _bfd_vms_lib_find_symbol (abfd, h->root.string); 5348 1.1 christos if (symidx == BFD_NO_MORE_SYMBOLS) 5349 1.1 christos { 5350 1.1 christos /* Nothing in this slot. */ 5351 1.1 christos continue; 5352 1.1 christos } 5353 1.1 christos 5354 1.1 christos element = bfd_get_elt_at_index (abfd, symidx); 5355 1.1 christos if (element == NULL) 5356 1.10 christos return false; 5357 1.1 christos 5358 1.1 christos if (element->archive_pass == -1 || element->archive_pass == pass) 5359 1.8 christos { 5360 1.8 christos /* Next symbol if this archive is wrong or already handled. */ 5361 1.8 christos continue; 5362 1.8 christos } 5363 1.1 christos 5364 1.1 christos orig_element = element; 5365 1.1 christos if (bfd_is_thin_archive (abfd)) 5366 1.8 christos { 5367 1.8 christos element = _bfd_vms_lib_get_imagelib_file (element); 5368 1.8 christos if (element == NULL || !bfd_check_format (element, bfd_object)) 5369 1.8 christos { 5370 1.8 christos orig_element->archive_pass = -1; 5371 1.10 christos return false; 5372 1.8 christos } 5373 1.8 christos } 5374 1.1 christos else if (! bfd_check_format (element, bfd_object)) 5375 1.8 christos { 5376 1.8 christos element->archive_pass = -1; 5377 1.10 christos return false; 5378 1.8 christos } 5379 1.1 christos 5380 1.1 christos /* Unlike the generic linker, we know that this element provides 5381 1.1 christos a definition for an undefined symbol and we know that we want 5382 1.1 christos to include it. We don't need to check anything. */ 5383 1.1 christos if (! (*info->callbacks->add_archive_element) (info, element, 5384 1.8 christos h->root.string, &element)) 5385 1.6 christos continue; 5386 1.1 christos if (! elf64_vms_link_add_object_symbols (element, info)) 5387 1.10 christos return false; 5388 1.1 christos 5389 1.1 christos orig_element->archive_pass = pass; 5390 1.1 christos } 5391 1.1 christos 5392 1.10 christos return true; 5393 1.1 christos } 5394 1.1 christos 5395 1.10 christos static bool 5396 1.1 christos elf64_vms_bfd_link_add_symbols (bfd *abfd, struct bfd_link_info *info) 5397 1.1 christos { 5398 1.1 christos switch (bfd_get_format (abfd)) 5399 1.1 christos { 5400 1.1 christos case bfd_object: 5401 1.1 christos return elf64_vms_link_add_object_symbols (abfd, info); 5402 1.1 christos break; 5403 1.1 christos case bfd_archive: 5404 1.1 christos return elf64_vms_link_add_archive_symbols (abfd, info); 5405 1.1 christos break; 5406 1.1 christos default: 5407 1.1 christos bfd_set_error (bfd_error_wrong_format); 5408 1.10 christos return false; 5409 1.1 christos } 5410 1.1 christos } 5411 1.1 christos 5412 1.10 christos static bool 5413 1.1 christos elf64_ia64_vms_mkobject (bfd *abfd) 5414 1.1 christos { 5415 1.12 christos return bfd_elf_allocate_object (abfd, 5416 1.12 christos sizeof (struct elf64_ia64_vms_obj_tdata)); 5417 1.1 christos } 5418 1.1 christos 5419 1.1 christos 5420 1.1 christos /* Size-dependent data and functions. */ 5421 1.1 christos static const struct elf_size_info elf64_ia64_vms_size_info = { 5422 1.1 christos sizeof (Elf64_External_VMS_Ehdr), 5423 1.1 christos sizeof (Elf64_External_Phdr), 5424 1.1 christos sizeof (Elf64_External_Shdr), 5425 1.1 christos sizeof (Elf64_External_Rel), 5426 1.1 christos sizeof (Elf64_External_Rela), 5427 1.1 christos sizeof (Elf64_External_Sym), 5428 1.1 christos sizeof (Elf64_External_Dyn), 5429 1.1 christos sizeof (Elf_External_Note), 5430 1.1 christos 4, 5431 1.1 christos 1, 5432 1.1 christos 64, 3, /* ARCH_SIZE, LOG_FILE_ALIGN */ 5433 1.1 christos ELFCLASS64, EV_CURRENT, 5434 1.1 christos bfd_elf64_write_out_phdrs, 5435 1.1 christos elf64_vms_write_shdrs_and_ehdr, 5436 1.1 christos bfd_elf64_checksum_contents, 5437 1.1 christos bfd_elf64_write_relocs, 5438 1.1 christos bfd_elf64_swap_symbol_in, 5439 1.1 christos bfd_elf64_swap_symbol_out, 5440 1.1 christos bfd_elf64_slurp_reloc_table, 5441 1.1 christos bfd_elf64_slurp_symbol_table, 5442 1.1 christos bfd_elf64_swap_dyn_in, 5443 1.1 christos bfd_elf64_swap_dyn_out, 5444 1.1 christos bfd_elf64_swap_reloc_in, 5445 1.1 christos bfd_elf64_swap_reloc_out, 5446 1.1 christos bfd_elf64_swap_reloca_in, 5447 1.1 christos bfd_elf64_swap_reloca_out 5448 1.1 christos }; 5449 1.1 christos 5450 1.1 christos #define ELF_ARCH bfd_arch_ia64 5451 1.12 christos #define ELF_TARGET_ID IA64_ELF_DATA 5452 1.1 christos #define ELF_MACHINE_CODE EM_IA_64 5453 1.1 christos #define ELF_MAXPAGESIZE 0x10000 /* 64KB */ 5454 1.1 christos #define ELF_COMMONPAGESIZE 0x200 /* 16KB */ 5455 1.1 christos 5456 1.1 christos #define elf_backend_section_from_shdr \ 5457 1.1 christos elf64_ia64_section_from_shdr 5458 1.1 christos #define elf_backend_section_flags \ 5459 1.1 christos elf64_ia64_section_flags 5460 1.1 christos #define elf_backend_fake_sections \ 5461 1.1 christos elf64_ia64_fake_sections 5462 1.1 christos #define elf_backend_final_write_processing \ 5463 1.1 christos elf64_ia64_final_write_processing 5464 1.1 christos #define elf_backend_add_symbol_hook \ 5465 1.1 christos elf64_ia64_add_symbol_hook 5466 1.1 christos #define elf_info_to_howto \ 5467 1.1 christos elf64_ia64_info_to_howto 5468 1.1 christos 5469 1.1 christos #define bfd_elf64_bfd_reloc_type_lookup \ 5470 1.1 christos ia64_elf_reloc_type_lookup 5471 1.1 christos #define bfd_elf64_bfd_reloc_name_lookup \ 5472 1.1 christos ia64_elf_reloc_name_lookup 5473 1.1 christos #define bfd_elf64_bfd_is_local_label_name \ 5474 1.1 christos elf64_ia64_is_local_label_name 5475 1.1 christos #define bfd_elf64_bfd_relax_section \ 5476 1.1 christos elf64_ia64_relax_section 5477 1.1 christos 5478 1.1 christos #define elf_backend_object_p \ 5479 1.1 christos elf64_ia64_object_p 5480 1.1 christos 5481 1.1 christos /* Stuff for the BFD linker: */ 5482 1.1 christos #define bfd_elf64_bfd_link_hash_table_create \ 5483 1.1 christos elf64_ia64_hash_table_create 5484 1.1 christos #define elf_backend_create_dynamic_sections \ 5485 1.1 christos elf64_ia64_create_dynamic_sections 5486 1.1 christos #define elf_backend_check_relocs \ 5487 1.1 christos elf64_ia64_check_relocs 5488 1.1 christos #define elf_backend_adjust_dynamic_symbol \ 5489 1.1 christos elf64_ia64_adjust_dynamic_symbol 5490 1.11 christos #define elf_backend_late_size_sections \ 5491 1.11 christos elf64_ia64_late_size_sections 5492 1.1 christos #define elf_backend_omit_section_dynsym \ 5493 1.8 christos _bfd_elf_omit_section_dynsym_all 5494 1.1 christos #define elf_backend_relocate_section \ 5495 1.1 christos elf64_ia64_relocate_section 5496 1.1 christos #define elf_backend_finish_dynamic_symbol \ 5497 1.1 christos elf64_ia64_finish_dynamic_symbol 5498 1.1 christos #define elf_backend_finish_dynamic_sections \ 5499 1.1 christos elf64_ia64_finish_dynamic_sections 5500 1.1 christos #define bfd_elf64_bfd_final_link \ 5501 1.1 christos elf64_ia64_final_link 5502 1.1 christos 5503 1.1 christos #define bfd_elf64_bfd_merge_private_bfd_data \ 5504 1.1 christos elf64_ia64_merge_private_bfd_data 5505 1.1 christos #define bfd_elf64_bfd_set_private_flags \ 5506 1.1 christos elf64_ia64_set_private_flags 5507 1.1 christos #define bfd_elf64_bfd_print_private_bfd_data \ 5508 1.1 christos elf64_ia64_print_private_bfd_data 5509 1.1 christos 5510 1.1 christos #define elf_backend_plt_readonly 1 5511 1.1 christos #define elf_backend_want_plt_sym 0 5512 1.1 christos #define elf_backend_plt_alignment 5 5513 1.1 christos #define elf_backend_got_header_size 0 5514 1.1 christos #define elf_backend_want_got_plt 1 5515 1.1 christos #define elf_backend_may_use_rel_p 1 5516 1.1 christos #define elf_backend_may_use_rela_p 1 5517 1.1 christos #define elf_backend_default_use_rela_p 1 5518 1.1 christos #define elf_backend_want_dynbss 0 5519 1.1 christos #define elf_backend_hide_symbol elf64_ia64_hash_hide_symbol 5520 1.1 christos #define elf_backend_fixup_symbol _bfd_elf_link_hash_fixup_symbol 5521 1.1 christos #define elf_backend_reloc_type_class elf64_ia64_reloc_type_class 5522 1.1 christos #define elf_backend_rela_normal 1 5523 1.1 christos #define elf_backend_special_sections elf64_ia64_special_sections 5524 1.1 christos #define elf_backend_default_execstack 0 5525 1.1 christos 5526 1.1 christos /* FIXME: PR 290: The Intel C compiler generates SHT_IA_64_UNWIND with 5527 1.1 christos SHF_LINK_ORDER. But it doesn't set the sh_link or sh_info fields. 5528 1.1 christos We don't want to flood users with so many error messages. We turn 5529 1.1 christos off the warning for now. It will be turned on later when the Intel 5530 1.1 christos compiler is fixed. */ 5531 1.1 christos #define elf_backend_link_order_error_handler NULL 5532 1.1 christos 5533 1.1 christos /* VMS-specific vectors. */ 5534 1.1 christos 5535 1.1 christos #undef TARGET_LITTLE_SYM 5536 1.3 christos #define TARGET_LITTLE_SYM ia64_elf64_vms_vec 5537 1.1 christos #undef TARGET_LITTLE_NAME 5538 1.1 christos #define TARGET_LITTLE_NAME "elf64-ia64-vms" 5539 1.1 christos #undef TARGET_BIG_SYM 5540 1.1 christos #undef TARGET_BIG_NAME 5541 1.1 christos 5542 1.1 christos /* These are VMS specific functions. */ 5543 1.1 christos 5544 1.1 christos #undef elf_backend_object_p 5545 1.1 christos #define elf_backend_object_p elf64_vms_object_p 5546 1.1 christos 5547 1.1 christos #undef elf_backend_section_from_shdr 5548 1.1 christos #define elf_backend_section_from_shdr elf64_vms_section_from_shdr 5549 1.1 christos 5550 1.9 christos #undef elf_backend_init_file_header 5551 1.9 christos #define elf_backend_init_file_header elf64_vms_init_file_header 5552 1.1 christos 5553 1.1 christos #undef elf_backend_section_processing 5554 1.1 christos #define elf_backend_section_processing elf64_vms_section_processing 5555 1.1 christos 5556 1.1 christos #undef elf_backend_final_write_processing 5557 1.1 christos #define elf_backend_final_write_processing elf64_vms_final_write_processing 5558 1.1 christos 5559 1.1 christos #undef bfd_elf64_close_and_cleanup 5560 1.1 christos #define bfd_elf64_close_and_cleanup elf64_vms_close_and_cleanup 5561 1.1 christos 5562 1.1 christos #undef elf_backend_section_from_bfd_section 5563 1.1 christos 5564 1.1 christos #undef elf_backend_symbol_processing 5565 1.1 christos 5566 1.1 christos #undef elf_backend_want_p_paddr_set_to_zero 5567 1.1 christos 5568 1.1 christos #undef ELF_OSABI 5569 1.1 christos #define ELF_OSABI ELFOSABI_OPENVMS 5570 1.1 christos 5571 1.1 christos #undef ELF_MAXPAGESIZE 5572 1.1 christos #define ELF_MAXPAGESIZE 0x10000 /* 64KB */ 5573 1.1 christos 5574 1.1 christos #undef elf64_bed 5575 1.1 christos #define elf64_bed elf64_ia64_vms_bed 5576 1.1 christos 5577 1.1 christos #define elf_backend_size_info elf64_ia64_vms_size_info 5578 1.1 christos 5579 1.1 christos /* Use VMS-style archives (in particular, don't use the standard coff 5580 1.1 christos archive format). */ 5581 1.1 christos #define bfd_elf64_archive_functions 5582 1.1 christos 5583 1.1 christos #undef bfd_elf64_archive_p 5584 1.1 christos #define bfd_elf64_archive_p _bfd_vms_lib_ia64_archive_p 5585 1.1 christos #undef bfd_elf64_write_archive_contents 5586 1.1 christos #define bfd_elf64_write_archive_contents _bfd_vms_lib_write_archive_contents 5587 1.1 christos #undef bfd_elf64_mkarchive 5588 1.1 christos #define bfd_elf64_mkarchive _bfd_vms_lib_ia64_mkarchive 5589 1.1 christos 5590 1.1 christos #define bfd_elf64_archive_slurp_armap \ 5591 1.1 christos _bfd_vms_lib_slurp_armap 5592 1.1 christos #define bfd_elf64_archive_slurp_extended_name_table \ 5593 1.1 christos _bfd_vms_lib_slurp_extended_name_table 5594 1.1 christos #define bfd_elf64_archive_construct_extended_name_table \ 5595 1.1 christos _bfd_vms_lib_construct_extended_name_table 5596 1.1 christos #define bfd_elf64_archive_truncate_arname \ 5597 1.1 christos _bfd_vms_lib_truncate_arname 5598 1.1 christos #define bfd_elf64_archive_write_armap \ 5599 1.1 christos _bfd_vms_lib_write_armap 5600 1.1 christos #define bfd_elf64_archive_read_ar_hdr \ 5601 1.1 christos _bfd_vms_lib_read_ar_hdr 5602 1.1 christos #define bfd_elf64_archive_write_ar_hdr \ 5603 1.1 christos _bfd_vms_lib_write_ar_hdr 5604 1.1 christos #define bfd_elf64_archive_openr_next_archived_file \ 5605 1.1 christos _bfd_vms_lib_openr_next_archived_file 5606 1.1 christos #define bfd_elf64_archive_get_elt_at_index \ 5607 1.1 christos _bfd_vms_lib_get_elt_at_index 5608 1.1 christos #define bfd_elf64_archive_generic_stat_arch_elt \ 5609 1.1 christos _bfd_vms_lib_generic_stat_arch_elt 5610 1.1 christos #define bfd_elf64_archive_update_armap_timestamp \ 5611 1.1 christos _bfd_vms_lib_update_armap_timestamp 5612 1.1 christos 5613 1.1 christos /* VMS link methods. */ 5614 1.1 christos #undef bfd_elf64_bfd_link_add_symbols 5615 1.8 christos #define bfd_elf64_bfd_link_add_symbols elf64_vms_bfd_link_add_symbols 5616 1.1 christos 5617 1.1 christos #undef elf_backend_want_got_sym 5618 1.8 christos #define elf_backend_want_got_sym 0 5619 1.1 christos 5620 1.1 christos #undef bfd_elf64_mkobject 5621 1.1 christos #define bfd_elf64_mkobject elf64_ia64_vms_mkobject 5622 1.1 christos 5623 1.1 christos /* Redefine to align segments on block size. */ 5624 1.1 christos #undef ELF_MAXPAGESIZE 5625 1.1 christos #define ELF_MAXPAGESIZE 0x200 /* 512B */ 5626 1.1 christos 5627 1.1 christos #undef elf_backend_want_got_plt 5628 1.1 christos #define elf_backend_want_got_plt 0 5629 1.1 christos 5630 1.1 christos #include "elf64-target.h" 5631