1 1.1 christos /* Support for HPPA 64-bit ELF 2 1.11 christos Copyright (C) 1999-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 "elf/hppa.h" 26 1.1 christos #include "libhppa.h" 27 1.1 christos #include "elf64-hppa.h" 28 1.6 christos #include "libiberty.h" 29 1.1 christos 30 1.11 christos /* Target vectors for HPUX and non-HPUX versions of HPPA ELF binaries. */ 31 1.11 christos extern const bfd_target hppa_elf64_vec; 32 1.11 christos extern const bfd_target hppa_elf64_linux_vec; 33 1.11 christos 34 1.1 christos #define ARCH_SIZE 64 35 1.1 christos 36 1.1 christos #define PLT_ENTRY_SIZE 0x10 37 1.1 christos #define DLT_ENTRY_SIZE 0x8 38 1.1 christos #define OPD_ENTRY_SIZE 0x20 39 1.1 christos 40 1.1 christos #define ELF_DYNAMIC_INTERPRETER "/usr/lib/pa20_64/dld.sl" 41 1.1 christos 42 1.1 christos /* The stub is supposed to load the target address and target's DP 43 1.1 christos value out of the PLT, then do an external branch to the target 44 1.1 christos address. 45 1.1 christos 46 1.1 christos LDD PLTOFF(%r27),%r1 47 1.1 christos BVE (%r1) 48 1.1 christos LDD PLTOFF+8(%r27),%r27 49 1.1 christos 50 1.1 christos Note that we must use the LDD with a 14 bit displacement, not the one 51 1.1 christos with a 5 bit displacement. */ 52 1.1 christos static char plt_stub[] = {0x53, 0x61, 0x00, 0x00, 0xe8, 0x20, 0xd0, 0x00, 53 1.1 christos 0x53, 0x7b, 0x00, 0x00 }; 54 1.1 christos 55 1.1 christos struct elf64_hppa_link_hash_entry 56 1.1 christos { 57 1.1 christos struct elf_link_hash_entry eh; 58 1.1 christos 59 1.1 christos /* Offsets for this symbol in various linker sections. */ 60 1.1 christos bfd_vma dlt_offset; 61 1.1 christos bfd_vma plt_offset; 62 1.1 christos bfd_vma opd_offset; 63 1.1 christos bfd_vma stub_offset; 64 1.1 christos 65 1.1 christos /* The index of the (possibly local) symbol in the input bfd and its 66 1.1 christos associated BFD. Needed so that we can have relocs against local 67 1.1 christos symbols in shared libraries. */ 68 1.1 christos long sym_indx; 69 1.1 christos bfd *owner; 70 1.1 christos 71 1.1 christos /* Dynamic symbols may need to have two different values. One for 72 1.1 christos the dynamic symbol table, one for the normal symbol table. 73 1.1 christos 74 1.1 christos In such cases we store the symbol's real value and section 75 1.1 christos index here so we can restore the real value before we write 76 1.1 christos the normal symbol table. */ 77 1.1 christos bfd_vma st_value; 78 1.1 christos int st_shndx; 79 1.1 christos 80 1.1 christos /* Used to count non-got, non-plt relocations for delayed sizing 81 1.1 christos of relocation sections. */ 82 1.1 christos struct elf64_hppa_dyn_reloc_entry 83 1.1 christos { 84 1.1 christos /* Next relocation in the chain. */ 85 1.1 christos struct elf64_hppa_dyn_reloc_entry *next; 86 1.1 christos 87 1.1 christos /* The type of the relocation. */ 88 1.1 christos int type; 89 1.1 christos 90 1.1 christos /* The input section of the relocation. */ 91 1.1 christos asection *sec; 92 1.1 christos 93 1.1 christos /* Number of relocs copied in this section. */ 94 1.1 christos bfd_size_type count; 95 1.1 christos 96 1.1 christos /* The index of the section symbol for the input section of 97 1.1 christos the relocation. Only needed when building shared libraries. */ 98 1.1 christos int sec_symndx; 99 1.1 christos 100 1.1 christos /* The offset within the input section of the relocation. */ 101 1.1 christos bfd_vma offset; 102 1.1 christos 103 1.1 christos /* The addend for the relocation. */ 104 1.1 christos bfd_vma addend; 105 1.1 christos 106 1.1 christos } *reloc_entries; 107 1.1 christos 108 1.1 christos /* Nonzero if this symbol needs an entry in one of the linker 109 1.1 christos sections. */ 110 1.1 christos unsigned want_dlt; 111 1.1 christos unsigned want_plt; 112 1.1 christos unsigned want_opd; 113 1.1 christos unsigned want_stub; 114 1.1 christos }; 115 1.1 christos 116 1.1 christos struct elf64_hppa_link_hash_table 117 1.1 christos { 118 1.1 christos struct elf_link_hash_table root; 119 1.1 christos 120 1.1 christos /* Shortcuts to get to the various linker defined sections. */ 121 1.1 christos asection *dlt_sec; 122 1.1 christos asection *dlt_rel_sec; 123 1.1 christos asection *opd_sec; 124 1.1 christos asection *opd_rel_sec; 125 1.1 christos asection *other_rel_sec; 126 1.1 christos 127 1.1 christos /* Offset of __gp within .plt section. When the PLT gets large we want 128 1.1 christos to slide __gp into the PLT section so that we can continue to use 129 1.1 christos single DP relative instructions to load values out of the PLT. */ 130 1.1 christos bfd_vma gp_offset; 131 1.1 christos 132 1.1 christos /* Note this is not strictly correct. We should create a stub section for 133 1.1 christos each input section with calls. The stub section should be placed before 134 1.1 christos the section with the call. */ 135 1.1 christos asection *stub_sec; 136 1.1 christos 137 1.1 christos bfd_vma text_segment_base; 138 1.1 christos bfd_vma data_segment_base; 139 1.1 christos 140 1.1 christos /* We build tables to map from an input section back to its 141 1.1 christos symbol index. This is the BFD for which we currently have 142 1.1 christos a map. */ 143 1.1 christos bfd *section_syms_bfd; 144 1.1 christos 145 1.1 christos /* Array of symbol numbers for each input section attached to the 146 1.1 christos current BFD. */ 147 1.1 christos int *section_syms; 148 1.1 christos }; 149 1.1 christos 150 1.1 christos #define hppa_link_hash_table(p) \ 151 1.9 christos ((is_elf_hash_table ((p)->hash) \ 152 1.9 christos && elf_hash_table_id (elf_hash_table (p)) == HPPA64_ELF_DATA) \ 153 1.9 christos ? (struct elf64_hppa_link_hash_table *) (p)->hash : NULL) 154 1.1 christos 155 1.1 christos #define hppa_elf_hash_entry(ent) \ 156 1.1 christos ((struct elf64_hppa_link_hash_entry *)(ent)) 157 1.1 christos 158 1.1 christos #define eh_name(eh) \ 159 1.1 christos (eh ? eh->root.root.string : "<undef>") 160 1.1 christos 161 1.1 christos typedef struct bfd_hash_entry *(*new_hash_entry_func) 162 1.1 christos (struct bfd_hash_entry *, struct bfd_hash_table *, const char *); 163 1.1 christos 164 1.1 christos static struct bfd_link_hash_table *elf64_hppa_hash_table_create 165 1.1 christos (bfd *abfd); 166 1.1 christos 167 1.1 christos /* This must follow the definitions of the various derived linker 168 1.1 christos hash tables and shared functions. */ 169 1.1 christos #include "elf-hppa.h" 170 1.1 christos 171 1.10 christos static bool elf64_hppa_object_p 172 1.1 christos (bfd *); 173 1.1 christos 174 1.10 christos static bool elf64_hppa_create_dynamic_sections 175 1.1 christos (bfd *, struct bfd_link_info *); 176 1.1 christos 177 1.10 christos static bool elf64_hppa_adjust_dynamic_symbol 178 1.1 christos (struct bfd_link_info *, struct elf_link_hash_entry *); 179 1.1 christos 180 1.10 christos static bool elf64_hppa_mark_milli_and_exported_functions 181 1.1 christos (struct elf_link_hash_entry *, void *); 182 1.1 christos 183 1.1 christos static int elf64_hppa_link_output_symbol_hook 184 1.1 christos (struct bfd_link_info *, const char *, Elf_Internal_Sym *, 185 1.1 christos asection *, struct elf_link_hash_entry *); 186 1.1 christos 187 1.10 christos static bool elf64_hppa_finish_dynamic_symbol 188 1.1 christos (bfd *, struct bfd_link_info *, 189 1.1 christos struct elf_link_hash_entry *, Elf_Internal_Sym *); 190 1.1 christos 191 1.10 christos static bool elf64_hppa_finish_dynamic_sections 192 1.1 christos (bfd *, struct bfd_link_info *); 193 1.1 christos 194 1.10 christos static bool elf64_hppa_check_relocs 195 1.1 christos (bfd *, struct bfd_link_info *, 196 1.1 christos asection *, const Elf_Internal_Rela *); 197 1.1 christos 198 1.10 christos static bool elf64_hppa_dynamic_symbol_p 199 1.1 christos (struct elf_link_hash_entry *, struct bfd_link_info *); 200 1.1 christos 201 1.10 christos static bool elf64_hppa_mark_exported_functions 202 1.1 christos (struct elf_link_hash_entry *, void *); 203 1.1 christos 204 1.10 christos static bool elf64_hppa_finalize_opd 205 1.1 christos (struct elf_link_hash_entry *, void *); 206 1.1 christos 207 1.10 christos static bool elf64_hppa_finalize_dlt 208 1.1 christos (struct elf_link_hash_entry *, void *); 209 1.1 christos 210 1.10 christos static bool allocate_global_data_dlt 211 1.1 christos (struct elf_link_hash_entry *, void *); 212 1.1 christos 213 1.10 christos static bool allocate_global_data_plt 214 1.1 christos (struct elf_link_hash_entry *, void *); 215 1.1 christos 216 1.10 christos static bool allocate_global_data_stub 217 1.1 christos (struct elf_link_hash_entry *, void *); 218 1.1 christos 219 1.10 christos static bool allocate_global_data_opd 220 1.1 christos (struct elf_link_hash_entry *, void *); 221 1.1 christos 222 1.10 christos static bool get_reloc_section 223 1.1 christos (bfd *, struct elf64_hppa_link_hash_table *, asection *); 224 1.1 christos 225 1.10 christos static bool count_dyn_reloc 226 1.1 christos (bfd *, struct elf64_hppa_link_hash_entry *, 227 1.1 christos int, asection *, int, bfd_vma, bfd_vma); 228 1.1 christos 229 1.10 christos static bool allocate_dynrel_entries 230 1.1 christos (struct elf_link_hash_entry *, void *); 231 1.1 christos 232 1.10 christos static bool elf64_hppa_finalize_dynreloc 233 1.1 christos (struct elf_link_hash_entry *, void *); 234 1.1 christos 235 1.10 christos static bool get_opd 236 1.1 christos (bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *); 237 1.1 christos 238 1.10 christos static bool get_plt 239 1.1 christos (bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *); 240 1.1 christos 241 1.10 christos static bool get_dlt 242 1.1 christos (bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *); 243 1.1 christos 244 1.10 christos static bool get_stub 245 1.1 christos (bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *); 246 1.1 christos 247 1.1 christos static int elf64_hppa_elf_get_symbol_type 248 1.1 christos (Elf_Internal_Sym *, int); 249 1.1 christos 250 1.1 christos /* Initialize an entry in the link hash table. */ 251 1.1 christos 252 1.1 christos static struct bfd_hash_entry * 253 1.1 christos hppa64_link_hash_newfunc (struct bfd_hash_entry *entry, 254 1.1 christos struct bfd_hash_table *table, 255 1.1 christos const char *string) 256 1.1 christos { 257 1.1 christos /* Allocate the structure if it has not already been allocated by a 258 1.1 christos subclass. */ 259 1.1 christos if (entry == NULL) 260 1.1 christos { 261 1.1 christos entry = bfd_hash_allocate (table, 262 1.1 christos sizeof (struct elf64_hppa_link_hash_entry)); 263 1.1 christos if (entry == NULL) 264 1.8 christos return entry; 265 1.1 christos } 266 1.1 christos 267 1.1 christos /* Call the allocation method of the superclass. */ 268 1.1 christos entry = _bfd_elf_link_hash_newfunc (entry, table, string); 269 1.1 christos if (entry != NULL) 270 1.1 christos { 271 1.1 christos struct elf64_hppa_link_hash_entry *hh; 272 1.1 christos 273 1.1 christos /* Initialize our local data. All zeros. */ 274 1.1 christos hh = hppa_elf_hash_entry (entry); 275 1.1 christos memset (&hh->dlt_offset, 0, 276 1.1 christos (sizeof (struct elf64_hppa_link_hash_entry) 277 1.1 christos - offsetof (struct elf64_hppa_link_hash_entry, dlt_offset))); 278 1.1 christos } 279 1.1 christos 280 1.1 christos return entry; 281 1.1 christos } 282 1.1 christos 283 1.1 christos /* Create the derived linker hash table. The PA64 ELF port uses this 284 1.1 christos derived hash table to keep information specific to the PA ElF 285 1.1 christos linker (without using static variables). */ 286 1.1 christos 287 1.1 christos static struct bfd_link_hash_table* 288 1.1 christos elf64_hppa_hash_table_create (bfd *abfd) 289 1.1 christos { 290 1.1 christos struct elf64_hppa_link_hash_table *htab; 291 1.9 christos size_t amt = sizeof (*htab); 292 1.1 christos 293 1.1 christos htab = bfd_zmalloc (amt); 294 1.1 christos if (htab == NULL) 295 1.1 christos return NULL; 296 1.1 christos 297 1.1 christos if (!_bfd_elf_link_hash_table_init (&htab->root, abfd, 298 1.1 christos hppa64_link_hash_newfunc, 299 1.1 christos sizeof (struct elf64_hppa_link_hash_entry), 300 1.1 christos HPPA64_ELF_DATA)) 301 1.1 christos { 302 1.1 christos free (htab); 303 1.1 christos return NULL; 304 1.1 christos } 305 1.1 christos 306 1.10 christos htab->root.dt_pltgot_required = true; 307 1.1 christos htab->text_segment_base = (bfd_vma) -1; 308 1.1 christos htab->data_segment_base = (bfd_vma) -1; 309 1.1 christos 310 1.1 christos return &htab->root.root; 311 1.1 christos } 312 1.1 christos 313 1.1 christos /* Return nonzero if ABFD represents a PA2.0 ELF64 file. 315 1.1 christos 316 1.10 christos Additionally we set the default architecture and machine. */ 317 1.1 christos static bool 318 1.1 christos elf64_hppa_object_p (bfd *abfd) 319 1.1 christos { 320 1.1 christos Elf_Internal_Ehdr * i_ehdrp; 321 1.1 christos unsigned int flags; 322 1.1 christos 323 1.11 christos i_ehdrp = elf_elfheader (abfd); 324 1.1 christos if (abfd->xvec == & hppa_elf64_linux_vec) 325 1.1 christos { 326 1.1 christos /* GCC on hppa-linux produces binaries with OSABI=GNU, 327 1.1 christos but the kernel produces corefiles with OSABI=SysV. */ 328 1.1 christos if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_GNU 329 1.10 christos && i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_NONE) /* aka SYSV */ 330 1.1 christos return false; 331 1.1 christos } 332 1.1 christos else 333 1.1 christos { 334 1.1 christos /* HPUX produces binaries with OSABI=HPUX, 335 1.1 christos but the kernel produces corefiles with OSABI=SysV. */ 336 1.1 christos if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_HPUX 337 1.10 christos && i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_NONE) /* aka SYSV */ 338 1.1 christos return false; 339 1.1 christos } 340 1.1 christos 341 1.1 christos flags = i_ehdrp->e_flags; 342 1.1 christos switch (flags & (EF_PARISC_ARCH | EF_PARISC_WIDE)) 343 1.1 christos { 344 1.1 christos case EFA_PARISC_1_0: 345 1.1 christos return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 10); 346 1.1 christos case EFA_PARISC_1_1: 347 1.1 christos return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 11); 348 1.1 christos case EFA_PARISC_2_0: 349 1.8 christos if (i_ehdrp->e_ident[EI_CLASS] == ELFCLASS64) 350 1.1 christos return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 25); 351 1.8 christos else 352 1.1 christos return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 20); 353 1.1 christos case EFA_PARISC_2_0 | EF_PARISC_WIDE: 354 1.1 christos return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 25); 355 1.1 christos } 356 1.10 christos /* Don't be fussy. */ 357 1.1 christos return true; 358 1.1 christos } 359 1.1 christos 360 1.1 christos /* Given section type (hdr->sh_type), return a boolean indicating 361 1.10 christos whether or not the section is an elf64-hppa specific section. */ 362 1.1 christos static bool 363 1.1 christos elf64_hppa_section_from_shdr (bfd *abfd, 364 1.1 christos Elf_Internal_Shdr *hdr, 365 1.1 christos const char *name, 366 1.1 christos int shindex) 367 1.1 christos { 368 1.1 christos switch (hdr->sh_type) 369 1.1 christos { 370 1.1 christos case SHT_PARISC_EXT: 371 1.10 christos if (strcmp (name, ".PARISC.archext") != 0) 372 1.1 christos return false; 373 1.1 christos break; 374 1.1 christos case SHT_PARISC_UNWIND: 375 1.10 christos if (strcmp (name, ".PARISC.unwind") != 0) 376 1.1 christos return false; 377 1.1 christos break; 378 1.1 christos case SHT_PARISC_DOC: 379 1.1 christos case SHT_PARISC_ANNOT: 380 1.10 christos default: 381 1.1 christos return false; 382 1.1 christos } 383 1.1 christos 384 1.10 christos if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) 385 1.1 christos return false; 386 1.9 christos 387 1.9 christos return ((hdr->sh_flags & SHF_PARISC_SHORT) == 0 388 1.9 christos || bfd_set_section_flags (hdr->bfd_section, 389 1.1 christos hdr->bfd_section->flags | SEC_SMALL_DATA)); 390 1.1 christos } 391 1.1 christos 392 1.1 christos /* SEC is a section containing relocs for an input BFD when linking; return 393 1.1 christos a suitable section for holding relocs in the output BFD for a link. */ 394 1.10 christos 395 1.1 christos static bool 396 1.1 christos get_reloc_section (bfd *abfd, 397 1.1 christos struct elf64_hppa_link_hash_table *hppa_info, 398 1.1 christos asection *sec) 399 1.1 christos { 400 1.1 christos const char *srel_name; 401 1.1 christos asection *srel; 402 1.1 christos bfd *dynobj; 403 1.1 christos 404 1.1 christos srel_name = (bfd_elf_string_from_elf_section 405 1.1 christos (abfd, elf_elfheader(abfd)->e_shstrndx, 406 1.1 christos _bfd_elf_single_rel_hdr(sec)->sh_name)); 407 1.10 christos if (srel_name == NULL) 408 1.1 christos return false; 409 1.1 christos 410 1.1 christos dynobj = hppa_info->root.dynobj; 411 1.1 christos if (!dynobj) 412 1.1 christos hppa_info->root.dynobj = dynobj = abfd; 413 1.1 christos 414 1.1 christos srel = bfd_get_linker_section (dynobj, srel_name); 415 1.1 christos if (srel == NULL) 416 1.1 christos { 417 1.1 christos srel = bfd_make_section_anyway_with_flags (dynobj, srel_name, 418 1.1 christos (SEC_ALLOC 419 1.1 christos | SEC_LOAD 420 1.1 christos | SEC_HAS_CONTENTS 421 1.1 christos | SEC_IN_MEMORY 422 1.1 christos | SEC_LINKER_CREATED 423 1.1 christos | SEC_READONLY)); 424 1.9 christos if (srel == NULL 425 1.10 christos || !bfd_set_section_alignment (srel, 3)) 426 1.1 christos return false; 427 1.1 christos } 428 1.1 christos 429 1.10 christos hppa_info->other_rel_sec = srel; 430 1.1 christos return true; 431 1.1 christos } 432 1.1 christos 433 1.1 christos /* Add a new entry to the list of dynamic relocations against DYN_H. 434 1.1 christos 435 1.1 christos We use this to keep a record of all the FPTR relocations against a 436 1.1 christos particular symbol so that we can create FPTR relocations in the 437 1.1 christos output file. */ 438 1.10 christos 439 1.1 christos static bool 440 1.1 christos count_dyn_reloc (bfd *abfd, 441 1.1 christos struct elf64_hppa_link_hash_entry *hh, 442 1.1 christos int type, 443 1.8 christos asection *sec, 444 1.8 christos int sec_symndx, 445 1.1 christos bfd_vma offset, 446 1.1 christos bfd_vma addend) 447 1.1 christos { 448 1.1 christos struct elf64_hppa_dyn_reloc_entry *rent; 449 1.1 christos 450 1.1 christos rent = (struct elf64_hppa_dyn_reloc_entry *) 451 1.1 christos bfd_alloc (abfd, (bfd_size_type) sizeof (*rent)); 452 1.10 christos if (!rent) 453 1.1 christos return false; 454 1.1 christos 455 1.1 christos rent->next = hh->reloc_entries; 456 1.1 christos rent->type = type; 457 1.1 christos rent->sec = sec; 458 1.1 christos rent->sec_symndx = sec_symndx; 459 1.1 christos rent->offset = offset; 460 1.1 christos rent->addend = addend; 461 1.1 christos hh->reloc_entries = rent; 462 1.10 christos 463 1.1 christos return true; 464 1.1 christos } 465 1.1 christos 466 1.1 christos /* Return a pointer to the local DLT, PLT and OPD reference counts 467 1.1 christos for ABFD. Returns NULL if the storage allocation fails. */ 468 1.1 christos 469 1.1 christos static bfd_signed_vma * 470 1.1 christos hppa64_elf_local_refcounts (bfd *abfd) 471 1.1 christos { 472 1.1 christos Elf_Internal_Shdr *symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 473 1.1 christos bfd_signed_vma *local_refcounts; 474 1.1 christos 475 1.1 christos local_refcounts = elf_local_got_refcounts (abfd); 476 1.1 christos if (local_refcounts == NULL) 477 1.1 christos { 478 1.1 christos bfd_size_type size; 479 1.1 christos 480 1.1 christos /* Allocate space for local DLT, PLT and OPD reference 481 1.1 christos counts. Done this way to save polluting elf_obj_tdata 482 1.1 christos with another target specific pointer. */ 483 1.1 christos size = symtab_hdr->sh_info; 484 1.1 christos size *= 3 * sizeof (bfd_signed_vma); 485 1.1 christos local_refcounts = bfd_zalloc (abfd, size); 486 1.1 christos elf_local_got_refcounts (abfd) = local_refcounts; 487 1.1 christos } 488 1.1 christos return local_refcounts; 489 1.1 christos } 490 1.1 christos 491 1.1 christos /* Scan the RELOCS and record the type of dynamic entries that each 492 1.1 christos referenced symbol needs. */ 493 1.10 christos 494 1.1 christos static bool 495 1.1 christos elf64_hppa_check_relocs (bfd *abfd, 496 1.1 christos struct bfd_link_info *info, 497 1.1 christos asection *sec, 498 1.1 christos const Elf_Internal_Rela *relocs) 499 1.1 christos { 500 1.1 christos struct elf64_hppa_link_hash_table *hppa_info; 501 1.1 christos const Elf_Internal_Rela *relend; 502 1.1 christos Elf_Internal_Shdr *symtab_hdr; 503 1.1 christos const Elf_Internal_Rela *rel; 504 1.1 christos unsigned int sec_symndx; 505 1.6 christos 506 1.10 christos if (bfd_link_relocatable (info)) 507 1.1 christos return true; 508 1.1 christos 509 1.1 christos /* If this is the first dynamic object found in the link, create 510 1.1 christos the special sections required for dynamic linking. */ 511 1.1 christos if (! elf_hash_table (info)->dynamic_sections_created) 512 1.1 christos { 513 1.10 christos if (! _bfd_elf_link_create_dynamic_sections (abfd, info)) 514 1.1 christos return false; 515 1.1 christos } 516 1.1 christos 517 1.1 christos hppa_info = hppa_link_hash_table (info); 518 1.10 christos if (hppa_info == NULL) 519 1.1 christos return false; 520 1.1 christos symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 521 1.1 christos 522 1.1 christos /* If necessary, build a new table holding section symbols indices 523 1.1 christos for this BFD. */ 524 1.6 christos 525 1.1 christos if (bfd_link_pic (info) && hppa_info->section_syms_bfd != abfd) 526 1.1 christos { 527 1.1 christos unsigned long i; 528 1.1 christos unsigned int highest_shndx; 529 1.1 christos Elf_Internal_Sym *local_syms = NULL; 530 1.1 christos Elf_Internal_Sym *isym, *isymend; 531 1.1 christos bfd_size_type amt; 532 1.1 christos 533 1.1 christos /* We're done with the old cache of section index to section symbol 534 1.1 christos index information. Free it. 535 1.1 christos 536 1.1 christos ?!? Note we leak the last section_syms array. Presumably we 537 1.9 christos could free it in one of the later routines in this file. */ 538 1.1 christos free (hppa_info->section_syms); 539 1.1 christos 540 1.1 christos /* Read this BFD's local symbols. */ 541 1.1 christos if (symtab_hdr->sh_info != 0) 542 1.1 christos { 543 1.1 christos local_syms = (Elf_Internal_Sym *) symtab_hdr->contents; 544 1.1 christos if (local_syms == NULL) 545 1.1 christos local_syms = bfd_elf_get_elf_syms (abfd, symtab_hdr, 546 1.1 christos symtab_hdr->sh_info, 0, 547 1.1 christos NULL, NULL, NULL); 548 1.10 christos if (local_syms == NULL) 549 1.1 christos return false; 550 1.1 christos } 551 1.1 christos 552 1.1 christos /* Record the highest section index referenced by the local symbols. */ 553 1.1 christos highest_shndx = 0; 554 1.1 christos isymend = local_syms + symtab_hdr->sh_info; 555 1.1 christos for (isym = local_syms; isym < isymend; isym++) 556 1.1 christos { 557 1.1 christos if (isym->st_shndx > highest_shndx 558 1.1 christos && isym->st_shndx < SHN_LORESERVE) 559 1.1 christos highest_shndx = isym->st_shndx; 560 1.1 christos } 561 1.1 christos 562 1.1 christos /* Allocate an array to hold the section index to section symbol index 563 1.1 christos mapping. Bump by one since we start counting at zero. */ 564 1.1 christos highest_shndx++; 565 1.1 christos amt = highest_shndx; 566 1.1 christos amt *= sizeof (int); 567 1.1 christos hppa_info->section_syms = (int *) bfd_malloc (amt); 568 1.1 christos 569 1.1 christos /* Now walk the local symbols again. If we find a section symbol, 570 1.1 christos record the index of the symbol into the section_syms array. */ 571 1.1 christos for (i = 0, isym = local_syms; isym < isymend; i++, isym++) 572 1.1 christos { 573 1.1 christos if (ELF_ST_TYPE (isym->st_info) == STT_SECTION) 574 1.1 christos hppa_info->section_syms[isym->st_shndx] = i; 575 1.1 christos } 576 1.1 christos 577 1.1 christos /* We are finished with the local symbols. */ 578 1.1 christos if (local_syms != NULL 579 1.1 christos && symtab_hdr->contents != (unsigned char *) local_syms) 580 1.1 christos { 581 1.1 christos if (! info->keep_memory) 582 1.1 christos free (local_syms); 583 1.1 christos else 584 1.1 christos { 585 1.1 christos /* Cache the symbols for elf_link_input_bfd. */ 586 1.1 christos symtab_hdr->contents = (unsigned char *) local_syms; 587 1.1 christos } 588 1.1 christos } 589 1.1 christos 590 1.1 christos /* Record which BFD we built the section_syms mapping for. */ 591 1.1 christos hppa_info->section_syms_bfd = abfd; 592 1.1 christos } 593 1.1 christos 594 1.1 christos /* Record the symbol index for this input section. We may need it for 595 1.1 christos relocations when building shared libraries. When not building shared 596 1.1 christos libraries this value is never really used, but assign it to zero to 597 1.6 christos prevent out of bounds memory accesses in other routines. */ 598 1.1 christos if (bfd_link_pic (info)) 599 1.1 christos { 600 1.1 christos sec_symndx = _bfd_elf_section_from_bfd_section (abfd, sec); 601 1.1 christos 602 1.1 christos /* If we did not find a section symbol for this section, then 603 1.1 christos something went terribly wrong above. */ 604 1.10 christos if (sec_symndx == SHN_BAD) 605 1.1 christos return false; 606 1.1 christos 607 1.1 christos if (sec_symndx < SHN_LORESERVE) 608 1.1 christos sec_symndx = hppa_info->section_syms[sec_symndx]; 609 1.1 christos else 610 1.1 christos sec_symndx = 0; 611 1.1 christos } 612 1.1 christos else 613 1.1 christos sec_symndx = 0; 614 1.1 christos 615 1.1 christos relend = relocs + sec->reloc_count; 616 1.1 christos for (rel = relocs; rel < relend; ++rel) 617 1.1 christos { 618 1.1 christos enum 619 1.1 christos { 620 1.1 christos NEED_DLT = 1, 621 1.1 christos NEED_PLT = 2, 622 1.1 christos NEED_STUB = 4, 623 1.1 christos NEED_OPD = 8, 624 1.1 christos NEED_DYNREL = 16, 625 1.1 christos }; 626 1.1 christos 627 1.1 christos unsigned long r_symndx = ELF64_R_SYM (rel->r_info); 628 1.1 christos struct elf64_hppa_link_hash_entry *hh; 629 1.10 christos int need_entry; 630 1.1 christos bool maybe_dynamic; 631 1.1 christos int dynrel_type = R_PARISC_NONE; 632 1.1 christos static reloc_howto_type *howto; 633 1.1 christos 634 1.1 christos if (r_symndx >= symtab_hdr->sh_info) 635 1.1 christos { 636 1.1 christos /* We're dealing with a global symbol -- find its hash entry 637 1.1 christos and mark it as being referenced. */ 638 1.1 christos long indx = r_symndx - symtab_hdr->sh_info; 639 1.1 christos hh = hppa_elf_hash_entry (elf_sym_hashes (abfd)[indx]); 640 1.1 christos while (hh->eh.root.type == bfd_link_hash_indirect 641 1.1 christos || hh->eh.root.type == bfd_link_hash_warning) 642 1.1 christos hh = hppa_elf_hash_entry (hh->eh.root.u.i.link); 643 1.1 christos 644 1.1 christos /* PR15323, ref flags aren't set for references in the same 645 1.1 christos object. */ 646 1.1 christos hh->eh.ref_regular = 1; 647 1.1 christos } 648 1.1 christos else 649 1.1 christos hh = NULL; 650 1.1 christos 651 1.1 christos /* We can only get preliminary data on whether a symbol is 652 1.1 christos locally or externally defined, as not all of the input files 653 1.1 christos have yet been processed. Do something with what we know, as 654 1.10 christos this may help reduce memory usage and processing time later. */ 655 1.6 christos maybe_dynamic = false; 656 1.1 christos if (hh && ((bfd_link_pic (info) 657 1.1 christos && (!info->symbolic 658 1.1 christos || info->unresolved_syms_in_shared_libs == RM_IGNORE)) 659 1.1 christos || !hh->eh.def_regular 660 1.10 christos || hh->eh.root.type == bfd_link_hash_defweak)) 661 1.1 christos maybe_dynamic = true; 662 1.1 christos 663 1.1 christos howto = elf_hppa_howto_table + ELF64_R_TYPE (rel->r_info); 664 1.1 christos need_entry = 0; 665 1.1 christos switch (howto->type) 666 1.1 christos { 667 1.1 christos /* These are simple indirect references to symbols through the 668 1.1 christos DLT. We need to create a DLT entry for any symbols which 669 1.1 christos appears in a DLTIND relocation. */ 670 1.1 christos case R_PARISC_DLTIND21L: 671 1.1 christos case R_PARISC_DLTIND14R: 672 1.1 christos case R_PARISC_DLTIND14F: 673 1.1 christos case R_PARISC_DLTIND14WR: 674 1.1 christos case R_PARISC_DLTIND14DR: 675 1.1 christos need_entry = NEED_DLT; 676 1.1 christos break; 677 1.1 christos 678 1.1 christos /* ?!? These need a DLT entry. But I have no idea what to do with 679 1.1 christos the "link time TP value. */ 680 1.1 christos case R_PARISC_LTOFF_TP21L: 681 1.1 christos case R_PARISC_LTOFF_TP14R: 682 1.1 christos case R_PARISC_LTOFF_TP14F: 683 1.1 christos case R_PARISC_LTOFF_TP64: 684 1.1 christos case R_PARISC_LTOFF_TP14WR: 685 1.1 christos case R_PARISC_LTOFF_TP14DR: 686 1.1 christos case R_PARISC_LTOFF_TP16F: 687 1.1 christos case R_PARISC_LTOFF_TP16WF: 688 1.1 christos case R_PARISC_LTOFF_TP16DF: 689 1.1 christos need_entry = NEED_DLT; 690 1.1 christos break; 691 1.1 christos 692 1.1 christos /* These are function calls. Depending on their precise target we 693 1.1 christos may need to make a stub for them. The stub uses the PLT, so we 694 1.1 christos need to create PLT entries for these symbols too. */ 695 1.1 christos case R_PARISC_PCREL12F: 696 1.1 christos case R_PARISC_PCREL17F: 697 1.1 christos case R_PARISC_PCREL22F: 698 1.1 christos case R_PARISC_PCREL32: 699 1.1 christos case R_PARISC_PCREL64: 700 1.1 christos case R_PARISC_PCREL21L: 701 1.1 christos case R_PARISC_PCREL17R: 702 1.1 christos case R_PARISC_PCREL17C: 703 1.1 christos case R_PARISC_PCREL14R: 704 1.1 christos case R_PARISC_PCREL14F: 705 1.1 christos case R_PARISC_PCREL22C: 706 1.1 christos case R_PARISC_PCREL14WR: 707 1.1 christos case R_PARISC_PCREL14DR: 708 1.1 christos case R_PARISC_PCREL16F: 709 1.1 christos case R_PARISC_PCREL16WF: 710 1.1 christos case R_PARISC_PCREL16DF: 711 1.1 christos /* Function calls might need to go through the .plt, and 712 1.1 christos might need a long branch stub. */ 713 1.1 christos if (hh != NULL && hh->eh.type != STT_PARISC_MILLI) 714 1.1 christos need_entry = (NEED_PLT | NEED_STUB); 715 1.1 christos else 716 1.1 christos need_entry = 0; 717 1.1 christos break; 718 1.1 christos 719 1.1 christos case R_PARISC_PLTOFF21L: 720 1.1 christos case R_PARISC_PLTOFF14R: 721 1.1 christos case R_PARISC_PLTOFF14F: 722 1.1 christos case R_PARISC_PLTOFF14WR: 723 1.1 christos case R_PARISC_PLTOFF14DR: 724 1.1 christos case R_PARISC_PLTOFF16F: 725 1.1 christos case R_PARISC_PLTOFF16WF: 726 1.1 christos case R_PARISC_PLTOFF16DF: 727 1.1 christos need_entry = (NEED_PLT); 728 1.1 christos break; 729 1.1 christos 730 1.6 christos case R_PARISC_DIR64: 731 1.1 christos if (bfd_link_pic (info) || maybe_dynamic) 732 1.1 christos need_entry = (NEED_DYNREL); 733 1.1 christos dynrel_type = R_PARISC_DIR64; 734 1.1 christos break; 735 1.1 christos 736 1.1 christos /* This is an indirect reference through the DLT to get the address 737 1.1 christos of a OPD descriptor. Thus we need to make a DLT entry that points 738 1.1 christos to an OPD entry. */ 739 1.1 christos case R_PARISC_LTOFF_FPTR21L: 740 1.1 christos case R_PARISC_LTOFF_FPTR14R: 741 1.1 christos case R_PARISC_LTOFF_FPTR14WR: 742 1.1 christos case R_PARISC_LTOFF_FPTR14DR: 743 1.1 christos case R_PARISC_LTOFF_FPTR32: 744 1.1 christos case R_PARISC_LTOFF_FPTR64: 745 1.1 christos case R_PARISC_LTOFF_FPTR16F: 746 1.1 christos case R_PARISC_LTOFF_FPTR16WF: 747 1.6 christos case R_PARISC_LTOFF_FPTR16DF: 748 1.1 christos if (bfd_link_pic (info) || maybe_dynamic) 749 1.1 christos need_entry = (NEED_DLT | NEED_OPD | NEED_PLT); 750 1.1 christos else 751 1.1 christos need_entry = (NEED_DLT | NEED_OPD | NEED_PLT); 752 1.1 christos dynrel_type = R_PARISC_FPTR64; 753 1.1 christos break; 754 1.1 christos 755 1.1 christos /* This is a simple OPD entry. */ 756 1.6 christos case R_PARISC_FPTR64: 757 1.1 christos if (bfd_link_pic (info) || maybe_dynamic) 758 1.1 christos need_entry = (NEED_OPD | NEED_PLT | NEED_DYNREL); 759 1.1 christos else 760 1.1 christos need_entry = (NEED_OPD | NEED_PLT); 761 1.1 christos dynrel_type = R_PARISC_FPTR64; 762 1.1 christos break; 763 1.1 christos 764 1.1 christos /* Add more cases as needed. */ 765 1.1 christos } 766 1.1 christos 767 1.1 christos if (!need_entry) 768 1.1 christos continue; 769 1.1 christos 770 1.1 christos if (hh) 771 1.1 christos { 772 1.1 christos /* Stash away enough information to be able to find this symbol 773 1.1 christos regardless of whether or not it is local or global. */ 774 1.1 christos hh->owner = abfd; 775 1.1 christos hh->sym_indx = r_symndx; 776 1.1 christos } 777 1.1 christos 778 1.1 christos /* Create what's needed. */ 779 1.1 christos if (need_entry & NEED_DLT) 780 1.1 christos { 781 1.1 christos /* Allocate space for a DLT entry, as well as a dynamic 782 1.1 christos relocation for this entry. */ 783 1.1 christos if (! hppa_info->dlt_sec 784 1.1 christos && ! get_dlt (abfd, info, hppa_info)) 785 1.1 christos goto err_out; 786 1.1 christos 787 1.1 christos if (hh != NULL) 788 1.1 christos { 789 1.1 christos hh->want_dlt = 1; 790 1.1 christos hh->eh.got.refcount += 1; 791 1.1 christos } 792 1.1 christos else 793 1.1 christos { 794 1.1 christos bfd_signed_vma *local_dlt_refcounts; 795 1.1 christos 796 1.1 christos /* This is a DLT entry for a local symbol. */ 797 1.1 christos local_dlt_refcounts = hppa64_elf_local_refcounts (abfd); 798 1.10 christos if (local_dlt_refcounts == NULL) 799 1.1 christos return false; 800 1.1 christos local_dlt_refcounts[r_symndx] += 1; 801 1.1 christos } 802 1.1 christos } 803 1.1 christos 804 1.1 christos if (need_entry & NEED_PLT) 805 1.9 christos { 806 1.1 christos if (! hppa_info->root.splt 807 1.1 christos && ! get_plt (abfd, info, hppa_info)) 808 1.1 christos goto err_out; 809 1.1 christos 810 1.1 christos if (hh != NULL) 811 1.1 christos { 812 1.1 christos hh->want_plt = 1; 813 1.1 christos hh->eh.needs_plt = 1; 814 1.1 christos hh->eh.plt.refcount += 1; 815 1.1 christos } 816 1.1 christos else 817 1.1 christos { 818 1.1 christos bfd_signed_vma *local_dlt_refcounts; 819 1.1 christos bfd_signed_vma *local_plt_refcounts; 820 1.1 christos 821 1.1 christos /* This is a PLT entry for a local symbol. */ 822 1.1 christos local_dlt_refcounts = hppa64_elf_local_refcounts (abfd); 823 1.10 christos if (local_dlt_refcounts == NULL) 824 1.1 christos return false; 825 1.1 christos local_plt_refcounts = local_dlt_refcounts + symtab_hdr->sh_info; 826 1.1 christos local_plt_refcounts[r_symndx] += 1; 827 1.1 christos } 828 1.1 christos } 829 1.1 christos 830 1.1 christos if (need_entry & NEED_STUB) 831 1.1 christos { 832 1.1 christos if (! hppa_info->stub_sec 833 1.1 christos && ! get_stub (abfd, info, hppa_info)) 834 1.1 christos goto err_out; 835 1.1 christos if (hh) 836 1.1 christos hh->want_stub = 1; 837 1.1 christos } 838 1.1 christos 839 1.1 christos if (need_entry & NEED_OPD) 840 1.1 christos { 841 1.1 christos if (! hppa_info->opd_sec 842 1.1 christos && ! get_opd (abfd, info, hppa_info)) 843 1.1 christos goto err_out; 844 1.1 christos 845 1.1 christos /* FPTRs are not allocated by the dynamic linker for PA64, 846 1.1 christos though it is possible that will change in the future. */ 847 1.1 christos 848 1.1 christos if (hh != NULL) 849 1.1 christos hh->want_opd = 1; 850 1.1 christos else 851 1.1 christos { 852 1.1 christos bfd_signed_vma *local_dlt_refcounts; 853 1.1 christos bfd_signed_vma *local_opd_refcounts; 854 1.1 christos 855 1.1 christos /* This is a OPD for a local symbol. */ 856 1.1 christos local_dlt_refcounts = hppa64_elf_local_refcounts (abfd); 857 1.10 christos if (local_dlt_refcounts == NULL) 858 1.1 christos return false; 859 1.1 christos local_opd_refcounts = (local_dlt_refcounts 860 1.1 christos + 2 * symtab_hdr->sh_info); 861 1.1 christos local_opd_refcounts[r_symndx] += 1; 862 1.1 christos } 863 1.1 christos } 864 1.1 christos 865 1.1 christos /* Add a new dynamic relocation to the chain of dynamic 866 1.1 christos relocations for this symbol. */ 867 1.1 christos if ((need_entry & NEED_DYNREL) && (sec->flags & SEC_ALLOC)) 868 1.1 christos { 869 1.1 christos if (! hppa_info->other_rel_sec 870 1.1 christos && ! get_reloc_section (abfd, hppa_info, sec)) 871 1.1 christos goto err_out; 872 1.1 christos 873 1.1 christos /* Count dynamic relocations against global symbols. */ 874 1.1 christos if (hh != NULL 875 1.1 christos && !count_dyn_reloc (abfd, hh, dynrel_type, sec, 876 1.1 christos sec_symndx, rel->r_offset, rel->r_addend)) 877 1.1 christos goto err_out; 878 1.1 christos 879 1.1 christos /* If we are building a shared library and we just recorded 880 1.1 christos a dynamic R_PARISC_FPTR64 relocation, then make sure the 881 1.1 christos section symbol for this section ends up in the dynamic 882 1.6 christos symbol table. */ 883 1.1 christos if (bfd_link_pic (info) && dynrel_type == R_PARISC_FPTR64 884 1.1 christos && ! (bfd_elf_link_record_local_dynamic_symbol 885 1.10 christos (info, abfd, sec_symndx))) 886 1.1 christos return false; 887 1.1 christos } 888 1.1 christos } 889 1.10 christos 890 1.1 christos return true; 891 1.1 christos 892 1.10 christos err_out: 893 1.1 christos return false; 894 1.1 christos } 895 1.1 christos 896 1.1 christos struct elf64_hppa_allocate_data 897 1.1 christos { 898 1.1 christos struct bfd_link_info *info; 899 1.1 christos bfd_size_type ofs; 900 1.1 christos }; 901 1.1 christos 902 1.1 christos /* Should we do dynamic things to this symbol? */ 903 1.10 christos 904 1.1 christos static bool 905 1.1 christos elf64_hppa_dynamic_symbol_p (struct elf_link_hash_entry *eh, 906 1.1 christos struct bfd_link_info *info) 907 1.1 christos { 908 1.1 christos /* ??? What, if anything, needs to happen wrt STV_PROTECTED symbols 909 1.1 christos and relocations that retrieve a function descriptor? Assume the 910 1.1 christos worst for now. */ 911 1.1 christos if (_bfd_elf_dynamic_symbol_p (eh, info, 1)) 912 1.1 christos { 913 1.1 christos /* ??? Why is this here and not elsewhere is_local_label_name. */ 914 1.10 christos if (eh->root.root.string[0] == '$' && eh->root.root.string[1] == '$') 915 1.1 christos return false; 916 1.10 christos 917 1.1 christos return true; 918 1.1 christos } 919 1.10 christos else 920 1.1 christos return false; 921 1.1 christos } 922 1.1 christos 923 1.1 christos /* Mark all functions exported by this file so that we can later allocate 924 1.1 christos entries in .opd for them. */ 925 1.10 christos 926 1.1 christos static bool 927 1.1 christos elf64_hppa_mark_exported_functions (struct elf_link_hash_entry *eh, void *data) 928 1.1 christos { 929 1.1 christos struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); 930 1.1 christos struct bfd_link_info *info = (struct bfd_link_info *)data; 931 1.1 christos struct elf64_hppa_link_hash_table *hppa_info; 932 1.1 christos 933 1.1 christos hppa_info = hppa_link_hash_table (info); 934 1.10 christos if (hppa_info == NULL) 935 1.1 christos return false; 936 1.1 christos 937 1.1 christos if (eh 938 1.1 christos && (eh->root.type == bfd_link_hash_defined 939 1.1 christos || eh->root.type == bfd_link_hash_defweak) 940 1.1 christos && eh->root.u.def.section->output_section != NULL 941 1.1 christos && eh->type == STT_FUNC) 942 1.1 christos { 943 1.1 christos if (! hppa_info->opd_sec 944 1.10 christos && ! get_opd (hppa_info->root.dynobj, info, hppa_info)) 945 1.1 christos return false; 946 1.1 christos 947 1.1 christos hh->want_opd = 1; 948 1.1 christos 949 1.1 christos /* Put a flag here for output_symbol_hook. */ 950 1.1 christos hh->st_shndx = -1; 951 1.1 christos eh->needs_plt = 1; 952 1.1 christos } 953 1.10 christos 954 1.1 christos return true; 955 1.1 christos } 956 1.1 christos 957 1.1 christos /* Allocate space for a DLT entry. */ 958 1.10 christos 959 1.1 christos static bool 960 1.1 christos allocate_global_data_dlt (struct elf_link_hash_entry *eh, void *data) 961 1.1 christos { 962 1.1 christos struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); 963 1.1 christos struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data; 964 1.1 christos 965 1.1 christos if (hh->want_dlt) 966 1.6 christos { 967 1.1 christos if (bfd_link_pic (x->info)) 968 1.1 christos { 969 1.1 christos /* Possibly add the symbol to the local dynamic symbol 970 1.1 christos table since we might need to create a dynamic relocation 971 1.1 christos against it. */ 972 1.1 christos if (eh->dynindx == -1 && eh->type != STT_PARISC_MILLI) 973 1.1 christos { 974 1.1 christos bfd *owner = eh->root.u.def.section->owner; 975 1.1 christos 976 1.1 christos if (! (bfd_elf_link_record_local_dynamic_symbol 977 1.10 christos (x->info, owner, hh->sym_indx))) 978 1.1 christos return false; 979 1.1 christos } 980 1.1 christos } 981 1.1 christos 982 1.1 christos hh->dlt_offset = x->ofs; 983 1.1 christos x->ofs += DLT_ENTRY_SIZE; 984 1.10 christos } 985 1.1 christos return true; 986 1.1 christos } 987 1.1 christos 988 1.1 christos /* Allocate space for a DLT.PLT entry. */ 989 1.10 christos 990 1.1 christos static bool 991 1.1 christos allocate_global_data_plt (struct elf_link_hash_entry *eh, void *data) 992 1.1 christos { 993 1.1 christos struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); 994 1.1 christos struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *) data; 995 1.1 christos 996 1.1 christos if (hh->want_plt 997 1.1 christos && elf64_hppa_dynamic_symbol_p (eh, x->info) 998 1.1 christos && !((eh->root.type == bfd_link_hash_defined 999 1.1 christos || eh->root.type == bfd_link_hash_defweak) 1000 1.1 christos && eh->root.u.def.section->output_section != NULL)) 1001 1.1 christos { 1002 1.1 christos hh->plt_offset = x->ofs; 1003 1.1 christos x->ofs += PLT_ENTRY_SIZE; 1004 1.1 christos if (hh->plt_offset < 0x2000) 1005 1.1 christos { 1006 1.1 christos struct elf64_hppa_link_hash_table *hppa_info; 1007 1.1 christos 1008 1.1 christos hppa_info = hppa_link_hash_table (x->info); 1009 1.10 christos if (hppa_info == NULL) 1010 1.1 christos return false; 1011 1.1 christos 1012 1.1 christos hppa_info->gp_offset = hh->plt_offset; 1013 1.1 christos } 1014 1.1 christos } 1015 1.1 christos else 1016 1.1 christos hh->want_plt = 0; 1017 1.10 christos 1018 1.1 christos return true; 1019 1.1 christos } 1020 1.1 christos 1021 1.1 christos /* Allocate space for a STUB entry. */ 1022 1.10 christos 1023 1.1 christos static bool 1024 1.1 christos allocate_global_data_stub (struct elf_link_hash_entry *eh, void *data) 1025 1.1 christos { 1026 1.1 christos struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); 1027 1.1 christos struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data; 1028 1.1 christos 1029 1.1 christos if (hh->want_stub 1030 1.1 christos && elf64_hppa_dynamic_symbol_p (eh, x->info) 1031 1.1 christos && !((eh->root.type == bfd_link_hash_defined 1032 1.1 christos || eh->root.type == bfd_link_hash_defweak) 1033 1.1 christos && eh->root.u.def.section->output_section != NULL)) 1034 1.1 christos { 1035 1.1 christos hh->stub_offset = x->ofs; 1036 1.1 christos x->ofs += sizeof (plt_stub); 1037 1.1 christos } 1038 1.1 christos else 1039 1.10 christos hh->want_stub = 0; 1040 1.1 christos return true; 1041 1.1 christos } 1042 1.1 christos 1043 1.1 christos /* Allocate space for a FPTR entry. */ 1044 1.10 christos 1045 1.1 christos static bool 1046 1.1 christos allocate_global_data_opd (struct elf_link_hash_entry *eh, void *data) 1047 1.1 christos { 1048 1.1 christos struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); 1049 1.1 christos struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data; 1050 1.1 christos 1051 1.1 christos if (hh && hh->want_opd) 1052 1.1 christos { 1053 1.1 christos /* We never need an opd entry for a symbol which is not 1054 1.1 christos defined by this output file. */ 1055 1.1 christos if (hh && (hh->eh.root.type == bfd_link_hash_undefined 1056 1.1 christos || hh->eh.root.type == bfd_link_hash_undefweak 1057 1.1 christos || hh->eh.root.u.def.section->output_section == NULL)) 1058 1.1 christos hh->want_opd = 0; 1059 1.1 christos 1060 1.1 christos /* If we are creating a shared library, took the address of a local 1061 1.1 christos function or might export this function from this object file, then 1062 1.6 christos we have to create an opd descriptor. */ 1063 1.1 christos else if (bfd_link_pic (x->info) 1064 1.1 christos || hh == NULL 1065 1.1 christos || (hh->eh.dynindx == -1 && hh->eh.type != STT_PARISC_MILLI) 1066 1.1 christos || (hh->eh.root.type == bfd_link_hash_defined 1067 1.1 christos || hh->eh.root.type == bfd_link_hash_defweak)) 1068 1.1 christos { 1069 1.1 christos /* If we are creating a shared library, then we will have to 1070 1.1 christos create a runtime relocation for the symbol to properly 1071 1.1 christos initialize the .opd entry. Make sure the symbol gets 1072 1.6 christos added to the dynamic symbol table. */ 1073 1.1 christos if (bfd_link_pic (x->info) 1074 1.1 christos && (hh == NULL || (hh->eh.dynindx == -1))) 1075 1.1 christos { 1076 1.1 christos bfd *owner; 1077 1.1 christos /* PR 6511: Default to using the dynamic symbol table. */ 1078 1.1 christos owner = (hh->owner ? hh->owner: eh->root.u.def.section->owner); 1079 1.1 christos 1080 1.1 christos if (!bfd_elf_link_record_local_dynamic_symbol 1081 1.10 christos (x->info, owner, hh->sym_indx)) 1082 1.1 christos return false; 1083 1.1 christos } 1084 1.1 christos 1085 1.1 christos /* This may not be necessary or desirable anymore now that 1086 1.1 christos we have some support for dealing with section symbols 1087 1.1 christos in dynamic relocs. But name munging does make the result 1088 1.1 christos much easier to debug. ie, the EPLT reloc will reference 1089 1.6 christos a symbol like .foobar, instead of .text + offset. */ 1090 1.1 christos if (bfd_link_pic (x->info) && eh) 1091 1.1 christos { 1092 1.1 christos char *new_name; 1093 1.1 christos struct elf_link_hash_entry *nh; 1094 1.6 christos 1095 1.1 christos new_name = concat (".", eh->root.root.string, NULL); 1096 1.1 christos 1097 1.10 christos nh = elf_link_hash_lookup (elf_hash_table (x->info), 1098 1.1 christos new_name, true, true, true); 1099 1.6 christos 1100 1.1 christos free (new_name); 1101 1.1 christos nh->root.type = eh->root.type; 1102 1.1 christos nh->root.u.def.value = eh->root.u.def.value; 1103 1.1 christos nh->root.u.def.section = eh->root.u.def.section; 1104 1.1 christos 1105 1.10 christos if (! bfd_elf_link_record_dynamic_symbol (x->info, nh)) 1106 1.1 christos return false; 1107 1.1 christos } 1108 1.1 christos hh->opd_offset = x->ofs; 1109 1.1 christos x->ofs += OPD_ENTRY_SIZE; 1110 1.1 christos } 1111 1.1 christos 1112 1.1 christos /* Otherwise we do not need an opd entry. */ 1113 1.1 christos else 1114 1.1 christos hh->want_opd = 0; 1115 1.10 christos } 1116 1.1 christos return true; 1117 1.1 christos } 1118 1.1 christos 1119 1.1 christos /* HP requires the EI_OSABI field to be filled in. The assignment to 1120 1.1 christos EI_ABIVERSION may not be strictly necessary. */ 1121 1.10 christos 1122 1.9 christos static bool 1123 1.1 christos elf64_hppa_init_file_header (bfd *abfd, struct bfd_link_info *info) 1124 1.9 christos { 1125 1.9 christos Elf_Internal_Ehdr *i_ehdrp; 1126 1.9 christos 1127 1.10 christos if (!_bfd_elf_init_file_header (abfd, info)) 1128 1.1 christos return false; 1129 1.1 christos 1130 1.1 christos i_ehdrp = elf_elfheader (abfd); 1131 1.1 christos i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi; 1132 1.10 christos i_ehdrp->e_ident[EI_ABIVERSION] = 1; 1133 1.1 christos return true; 1134 1.1 christos } 1135 1.1 christos 1136 1.1 christos /* Create function descriptor section (.opd). This section is called .opd 1137 1.1 christos because it contains "official procedure descriptors". The "official" 1138 1.1 christos refers to the fact that these descriptors are used when taking the address 1139 1.1 christos of a procedure, thus ensuring a unique address for each procedure. */ 1140 1.10 christos 1141 1.1 christos static bool 1142 1.1 christos get_opd (bfd *abfd, 1143 1.1 christos struct bfd_link_info *info ATTRIBUTE_UNUSED, 1144 1.1 christos struct elf64_hppa_link_hash_table *hppa_info) 1145 1.1 christos { 1146 1.1 christos asection *opd; 1147 1.1 christos bfd *dynobj; 1148 1.1 christos 1149 1.1 christos opd = hppa_info->opd_sec; 1150 1.1 christos if (!opd) 1151 1.1 christos { 1152 1.1 christos dynobj = hppa_info->root.dynobj; 1153 1.1 christos if (!dynobj) 1154 1.1 christos hppa_info->root.dynobj = dynobj = abfd; 1155 1.1 christos 1156 1.1 christos opd = bfd_make_section_anyway_with_flags (dynobj, ".opd", 1157 1.1 christos (SEC_ALLOC 1158 1.1 christos | SEC_LOAD 1159 1.1 christos | SEC_HAS_CONTENTS 1160 1.1 christos | SEC_IN_MEMORY 1161 1.1 christos | SEC_LINKER_CREATED)); 1162 1.9 christos if (!opd 1163 1.1 christos || !bfd_set_section_alignment (opd, 3)) 1164 1.1 christos { 1165 1.10 christos BFD_ASSERT (0); 1166 1.1 christos return false; 1167 1.1 christos } 1168 1.1 christos 1169 1.1 christos hppa_info->opd_sec = opd; 1170 1.1 christos } 1171 1.10 christos 1172 1.1 christos return true; 1173 1.1 christos } 1174 1.1 christos 1175 1.1 christos /* Create the PLT section. */ 1176 1.10 christos 1177 1.1 christos static bool 1178 1.1 christos get_plt (bfd *abfd, 1179 1.1 christos struct bfd_link_info *info ATTRIBUTE_UNUSED, 1180 1.1 christos struct elf64_hppa_link_hash_table *hppa_info) 1181 1.1 christos { 1182 1.1 christos asection *plt; 1183 1.1 christos bfd *dynobj; 1184 1.9 christos 1185 1.1 christos plt = hppa_info->root.splt; 1186 1.1 christos if (!plt) 1187 1.1 christos { 1188 1.1 christos dynobj = hppa_info->root.dynobj; 1189 1.1 christos if (!dynobj) 1190 1.1 christos hppa_info->root.dynobj = dynobj = abfd; 1191 1.1 christos 1192 1.1 christos plt = bfd_make_section_anyway_with_flags (dynobj, ".plt", 1193 1.1 christos (SEC_ALLOC 1194 1.1 christos | SEC_LOAD 1195 1.1 christos | SEC_HAS_CONTENTS 1196 1.1 christos | SEC_IN_MEMORY 1197 1.1 christos | SEC_LINKER_CREATED)); 1198 1.9 christos if (!plt 1199 1.1 christos || !bfd_set_section_alignment (plt, 3)) 1200 1.1 christos { 1201 1.10 christos BFD_ASSERT (0); 1202 1.1 christos return false; 1203 1.1 christos } 1204 1.9 christos 1205 1.1 christos hppa_info->root.splt = plt; 1206 1.1 christos } 1207 1.10 christos 1208 1.1 christos return true; 1209 1.1 christos } 1210 1.1 christos 1211 1.1 christos /* Create the DLT section. */ 1212 1.10 christos 1213 1.1 christos static bool 1214 1.1 christos get_dlt (bfd *abfd, 1215 1.1 christos struct bfd_link_info *info ATTRIBUTE_UNUSED, 1216 1.1 christos struct elf64_hppa_link_hash_table *hppa_info) 1217 1.1 christos { 1218 1.1 christos asection *dlt; 1219 1.1 christos bfd *dynobj; 1220 1.1 christos 1221 1.1 christos dlt = hppa_info->dlt_sec; 1222 1.1 christos if (!dlt) 1223 1.1 christos { 1224 1.1 christos dynobj = hppa_info->root.dynobj; 1225 1.1 christos if (!dynobj) 1226 1.1 christos hppa_info->root.dynobj = dynobj = abfd; 1227 1.1 christos 1228 1.1 christos dlt = bfd_make_section_anyway_with_flags (dynobj, ".dlt", 1229 1.1 christos (SEC_ALLOC 1230 1.1 christos | SEC_LOAD 1231 1.1 christos | SEC_HAS_CONTENTS 1232 1.1 christos | SEC_IN_MEMORY 1233 1.1 christos | SEC_LINKER_CREATED)); 1234 1.9 christos if (!dlt 1235 1.1 christos || !bfd_set_section_alignment (dlt, 3)) 1236 1.1 christos { 1237 1.10 christos BFD_ASSERT (0); 1238 1.1 christos return false; 1239 1.1 christos } 1240 1.1 christos 1241 1.1 christos hppa_info->dlt_sec = dlt; 1242 1.1 christos } 1243 1.10 christos 1244 1.1 christos return true; 1245 1.1 christos } 1246 1.1 christos 1247 1.1 christos /* Create the stubs section. */ 1248 1.10 christos 1249 1.1 christos static bool 1250 1.1 christos get_stub (bfd *abfd, 1251 1.1 christos struct bfd_link_info *info ATTRIBUTE_UNUSED, 1252 1.1 christos struct elf64_hppa_link_hash_table *hppa_info) 1253 1.1 christos { 1254 1.1 christos asection *stub; 1255 1.1 christos bfd *dynobj; 1256 1.1 christos 1257 1.1 christos stub = hppa_info->stub_sec; 1258 1.1 christos if (!stub) 1259 1.1 christos { 1260 1.1 christos dynobj = hppa_info->root.dynobj; 1261 1.1 christos if (!dynobj) 1262 1.1 christos hppa_info->root.dynobj = dynobj = abfd; 1263 1.1 christos 1264 1.1 christos stub = bfd_make_section_anyway_with_flags (dynobj, ".stub", 1265 1.1 christos (SEC_ALLOC | SEC_LOAD 1266 1.1 christos | SEC_HAS_CONTENTS 1267 1.1 christos | SEC_IN_MEMORY 1268 1.1 christos | SEC_READONLY 1269 1.1 christos | SEC_LINKER_CREATED)); 1270 1.9 christos if (!stub 1271 1.1 christos || !bfd_set_section_alignment (stub, 3)) 1272 1.1 christos { 1273 1.10 christos BFD_ASSERT (0); 1274 1.1 christos return false; 1275 1.1 christos } 1276 1.1 christos 1277 1.1 christos hppa_info->stub_sec = stub; 1278 1.1 christos } 1279 1.10 christos 1280 1.1 christos return true; 1281 1.1 christos } 1282 1.1 christos 1283 1.1 christos /* Create sections necessary for dynamic linking. This is only a rough 1284 1.1 christos cut and will likely change as we learn more about the somewhat 1285 1.1 christos unusual dynamic linking scheme HP uses. 1286 1.1 christos 1287 1.1 christos .stub: 1288 1.1 christos Contains code to implement cross-space calls. The first time one 1289 1.1 christos of the stubs is used it will call into the dynamic linker, later 1290 1.1 christos calls will go straight to the target. 1291 1.1 christos 1292 1.1 christos The only stub we support right now looks like 1293 1.1 christos 1294 1.1 christos ldd OFFSET(%dp),%r1 1295 1.1 christos bve %r0(%r1) 1296 1.1 christos ldd OFFSET+8(%dp),%dp 1297 1.1 christos 1298 1.1 christos Other stubs may be needed in the future. We may want the remove 1299 1.1 christos the break/nop instruction. It is only used right now to keep the 1300 1.1 christos offset of a .plt entry and a .stub entry in sync. 1301 1.1 christos 1302 1.1 christos .dlt: 1303 1.1 christos This is what most people call the .got. HP used a different name. 1304 1.1 christos Losers. 1305 1.1 christos 1306 1.1 christos .rela.dlt: 1307 1.1 christos Relocations for the DLT. 1308 1.1 christos 1309 1.1 christos .plt: 1310 1.1 christos Function pointers as address,gp pairs. 1311 1.1 christos 1312 1.1 christos .rela.plt: 1313 1.1 christos Should contain dynamic IPLT (and EPLT?) relocations. 1314 1.1 christos 1315 1.1 christos .opd: 1316 1.1 christos FPTRS 1317 1.1 christos 1318 1.1 christos .rela.opd: 1319 1.1 christos EPLT relocations for symbols exported from shared libraries. */ 1320 1.10 christos 1321 1.1 christos static bool 1322 1.1 christos elf64_hppa_create_dynamic_sections (bfd *abfd, 1323 1.1 christos struct bfd_link_info *info) 1324 1.1 christos { 1325 1.1 christos asection *s; 1326 1.1 christos struct elf64_hppa_link_hash_table *hppa_info; 1327 1.1 christos 1328 1.1 christos hppa_info = hppa_link_hash_table (info); 1329 1.10 christos if (hppa_info == NULL) 1330 1.1 christos return false; 1331 1.1 christos 1332 1.10 christos if (! get_stub (abfd, info, hppa_info)) 1333 1.1 christos return false; 1334 1.1 christos 1335 1.10 christos if (! get_dlt (abfd, info, hppa_info)) 1336 1.1 christos return false; 1337 1.1 christos 1338 1.10 christos if (! get_plt (abfd, info, hppa_info)) 1339 1.1 christos return false; 1340 1.1 christos 1341 1.10 christos if (! get_opd (abfd, info, hppa_info)) 1342 1.1 christos return false; 1343 1.1 christos 1344 1.1 christos s = bfd_make_section_anyway_with_flags (abfd, ".rela.dlt", 1345 1.1 christos (SEC_ALLOC | SEC_LOAD 1346 1.1 christos | SEC_HAS_CONTENTS 1347 1.1 christos | SEC_IN_MEMORY 1348 1.1 christos | SEC_READONLY 1349 1.1 christos | SEC_LINKER_CREATED)); 1350 1.9 christos if (s == NULL 1351 1.10 christos || !bfd_set_section_alignment (s, 3)) 1352 1.1 christos return false; 1353 1.1 christos hppa_info->dlt_rel_sec = s; 1354 1.1 christos 1355 1.1 christos s = bfd_make_section_anyway_with_flags (abfd, ".rela.plt", 1356 1.1 christos (SEC_ALLOC | SEC_LOAD 1357 1.1 christos | SEC_HAS_CONTENTS 1358 1.1 christos | SEC_IN_MEMORY 1359 1.1 christos | SEC_READONLY 1360 1.1 christos | SEC_LINKER_CREATED)); 1361 1.9 christos if (s == NULL 1362 1.10 christos || !bfd_set_section_alignment (s, 3)) 1363 1.9 christos return false; 1364 1.1 christos hppa_info->root.srelplt = s; 1365 1.1 christos 1366 1.1 christos s = bfd_make_section_anyway_with_flags (abfd, ".rela.data", 1367 1.1 christos (SEC_ALLOC | SEC_LOAD 1368 1.1 christos | SEC_HAS_CONTENTS 1369 1.1 christos | SEC_IN_MEMORY 1370 1.1 christos | SEC_READONLY 1371 1.1 christos | SEC_LINKER_CREATED)); 1372 1.9 christos if (s == NULL 1373 1.10 christos || !bfd_set_section_alignment (s, 3)) 1374 1.1 christos return false; 1375 1.1 christos hppa_info->other_rel_sec = s; 1376 1.1 christos 1377 1.1 christos s = bfd_make_section_anyway_with_flags (abfd, ".rela.opd", 1378 1.1 christos (SEC_ALLOC | SEC_LOAD 1379 1.1 christos | SEC_HAS_CONTENTS 1380 1.1 christos | SEC_IN_MEMORY 1381 1.1 christos | SEC_READONLY 1382 1.1 christos | SEC_LINKER_CREATED)); 1383 1.9 christos if (s == NULL 1384 1.10 christos || !bfd_set_section_alignment (s, 3)) 1385 1.1 christos return false; 1386 1.1 christos hppa_info->opd_rel_sec = s; 1387 1.10 christos 1388 1.1 christos return true; 1389 1.1 christos } 1390 1.1 christos 1391 1.1 christos /* Allocate dynamic relocations for those symbols that turned out 1392 1.1 christos to be dynamic. */ 1393 1.10 christos 1394 1.1 christos static bool 1395 1.1 christos allocate_dynrel_entries (struct elf_link_hash_entry *eh, void *data) 1396 1.1 christos { 1397 1.1 christos struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); 1398 1.1 christos struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data; 1399 1.1 christos struct elf64_hppa_link_hash_table *hppa_info; 1400 1.10 christos struct elf64_hppa_dyn_reloc_entry *rent; 1401 1.1 christos bool dynamic_symbol, shared; 1402 1.1 christos 1403 1.1 christos hppa_info = hppa_link_hash_table (x->info); 1404 1.10 christos if (hppa_info == NULL) 1405 1.1 christos return false; 1406 1.1 christos 1407 1.6 christos dynamic_symbol = elf64_hppa_dynamic_symbol_p (eh, x->info); 1408 1.1 christos shared = bfd_link_pic (x->info); 1409 1.1 christos 1410 1.1 christos /* We may need to allocate relocations for a non-dynamic symbol 1411 1.1 christos when creating a shared library. */ 1412 1.10 christos if (!dynamic_symbol && !shared) 1413 1.1 christos return true; 1414 1.1 christos 1415 1.1 christos /* Take care of the normal data relocations. */ 1416 1.1 christos 1417 1.1 christos for (rent = hh->reloc_entries; rent; rent = rent->next) 1418 1.1 christos { 1419 1.1 christos /* Allocate one iff we are building a shared library, the relocation 1420 1.1 christos isn't a R_PARISC_FPTR64, or we don't want an opd entry. */ 1421 1.1 christos if (!shared && rent->type == R_PARISC_FPTR64 && hh->want_opd) 1422 1.1 christos continue; 1423 1.1 christos 1424 1.1 christos hppa_info->other_rel_sec->size += sizeof (Elf64_External_Rela); 1425 1.1 christos 1426 1.1 christos /* Make sure this symbol gets into the dynamic symbol table if it is 1427 1.1 christos not already recorded. ?!? This should not be in the loop since 1428 1.1 christos the symbol need only be added once. */ 1429 1.1 christos if (eh->dynindx == -1 && eh->type != STT_PARISC_MILLI) 1430 1.1 christos if (!bfd_elf_link_record_local_dynamic_symbol 1431 1.10 christos (x->info, rent->sec->owner, hh->sym_indx)) 1432 1.1 christos return false; 1433 1.1 christos } 1434 1.1 christos 1435 1.1 christos /* Take care of the GOT and PLT relocations. */ 1436 1.1 christos 1437 1.1 christos if ((dynamic_symbol || shared) && hh->want_dlt) 1438 1.1 christos hppa_info->dlt_rel_sec->size += sizeof (Elf64_External_Rela); 1439 1.1 christos 1440 1.1 christos /* If we are building a shared library, then every symbol that has an 1441 1.1 christos opd entry will need an EPLT relocation to relocate the symbol's address 1442 1.1 christos and __gp value based on the runtime load address. */ 1443 1.1 christos if (shared && hh->want_opd) 1444 1.1 christos hppa_info->opd_rel_sec->size += sizeof (Elf64_External_Rela); 1445 1.1 christos 1446 1.1 christos if (hh->want_plt && dynamic_symbol) 1447 1.1 christos { 1448 1.1 christos bfd_size_type t = 0; 1449 1.1 christos 1450 1.1 christos /* Dynamic symbols get one IPLT relocation. Local symbols in 1451 1.1 christos shared libraries get two REL relocations. Local symbols in 1452 1.1 christos main applications get nothing. */ 1453 1.1 christos if (dynamic_symbol) 1454 1.1 christos t = sizeof (Elf64_External_Rela); 1455 1.1 christos else if (shared) 1456 1.1 christos t = 2 * sizeof (Elf64_External_Rela); 1457 1.9 christos 1458 1.1 christos hppa_info->root.srelplt->size += t; 1459 1.1 christos } 1460 1.10 christos 1461 1.1 christos return true; 1462 1.1 christos } 1463 1.1 christos 1464 1.1 christos /* Adjust a symbol defined by a dynamic object and referenced by a 1465 1.1 christos regular object. */ 1466 1.10 christos 1467 1.1 christos static bool 1468 1.1 christos elf64_hppa_adjust_dynamic_symbol (struct bfd_link_info *info ATTRIBUTE_UNUSED, 1469 1.1 christos struct elf_link_hash_entry *eh) 1470 1.1 christos { 1471 1.1 christos /* ??? Undefined symbols with PLT entries should be re-defined 1472 1.1 christos to be the PLT entry. */ 1473 1.1 christos 1474 1.1 christos /* If this is a weak symbol, and there is a real definition, the 1475 1.1 christos processor independent code will have arranged for us to see the 1476 1.8 christos real definition first, and we can just use the same value. */ 1477 1.1 christos if (eh->is_weakalias) 1478 1.8 christos { 1479 1.8 christos struct elf_link_hash_entry *def = weakdef (eh); 1480 1.8 christos BFD_ASSERT (def->root.type == bfd_link_hash_defined); 1481 1.8 christos eh->root.u.def.section = def->root.u.def.section; 1482 1.10 christos eh->root.u.def.value = def->root.u.def.value; 1483 1.1 christos return true; 1484 1.1 christos } 1485 1.1 christos 1486 1.1 christos /* If this is a reference to a symbol defined by a dynamic object which 1487 1.1 christos is not a function, we might allocate the symbol in our .dynbss section 1488 1.1 christos and allocate a COPY dynamic relocation. 1489 1.1 christos 1490 1.1 christos But PA64 code is canonically PIC, so as a rule we can avoid this sort 1491 1.1 christos of hackery. */ 1492 1.10 christos 1493 1.1 christos return true; 1494 1.1 christos } 1495 1.1 christos 1496 1.1 christos /* This function is called via elf_link_hash_traverse to mark millicode 1497 1.1 christos symbols with a dynindx of -1 and to remove the string table reference 1498 1.1 christos from the dynamic symbol table. If the symbol is not a millicode symbol, 1499 1.1 christos elf64_hppa_mark_exported_functions is called. */ 1500 1.10 christos 1501 1.1 christos static bool 1502 1.1 christos elf64_hppa_mark_milli_and_exported_functions (struct elf_link_hash_entry *eh, 1503 1.1 christos void *data) 1504 1.1 christos { 1505 1.1 christos struct bfd_link_info *info = (struct bfd_link_info *) data; 1506 1.1 christos 1507 1.1 christos if (eh->type == STT_PARISC_MILLI) 1508 1.1 christos { 1509 1.1 christos if (eh->dynindx != -1) 1510 1.1 christos { 1511 1.1 christos eh->dynindx = -1; 1512 1.1 christos _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr, 1513 1.1 christos eh->dynstr_index); 1514 1.10 christos } 1515 1.1 christos return true; 1516 1.1 christos } 1517 1.1 christos 1518 1.1 christos return elf64_hppa_mark_exported_functions (eh, data); 1519 1.1 christos } 1520 1.1 christos 1521 1.1 christos /* Set the final sizes of the dynamic sections and allocate memory for 1522 1.1 christos the contents of our special sections. */ 1523 1.10 christos 1524 1.11 christos static bool 1525 1.1 christos elf64_hppa_late_size_sections (bfd *output_bfd, struct bfd_link_info *info) 1526 1.1 christos { 1527 1.1 christos struct elf64_hppa_link_hash_table *hppa_info; 1528 1.1 christos struct elf64_hppa_allocate_data data; 1529 1.1 christos bfd *dynobj; 1530 1.1 christos bfd *ibfd; 1531 1.10 christos asection *sec; 1532 1.1 christos bool relocs; 1533 1.1 christos 1534 1.1 christos hppa_info = hppa_link_hash_table (info); 1535 1.10 christos if (hppa_info == NULL) 1536 1.1 christos return false; 1537 1.7 christos 1538 1.11 christos dynobj = hppa_info->root.dynobj; 1539 1.11 christos if (dynobj == NULL) 1540 1.1 christos return true; 1541 1.1 christos 1542 1.1 christos /* Mark each function this program exports so that we will allocate 1543 1.1 christos space in the .opd section for each function's FPTR. If we are 1544 1.1 christos creating dynamic sections, change the dynamic index of millicode 1545 1.1 christos symbols to -1 and remove them from the string table for .dynstr. 1546 1.1 christos 1547 1.1 christos We have to traverse the main linker hash table since we have to 1548 1.7 christos find functions which may not have been mentioned in any relocs. */ 1549 1.7 christos elf_link_hash_traverse (&hppa_info->root, 1550 1.1 christos (hppa_info->root.dynamic_sections_created 1551 1.1 christos ? elf64_hppa_mark_milli_and_exported_functions 1552 1.1 christos : elf64_hppa_mark_exported_functions), 1553 1.1 christos info); 1554 1.7 christos 1555 1.1 christos if (hppa_info->root.dynamic_sections_created) 1556 1.1 christos { 1557 1.6 christos /* Set the contents of the .interp section to the interpreter. */ 1558 1.1 christos if (bfd_link_executable (info) && !info->nointerp) 1559 1.1 christos { 1560 1.1 christos sec = bfd_get_linker_section (dynobj, ".interp"); 1561 1.1 christos BFD_ASSERT (sec != NULL); 1562 1.1 christos sec->size = sizeof ELF_DYNAMIC_INTERPRETER; 1563 1.1 christos sec->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; 1564 1.1 christos } 1565 1.1 christos } 1566 1.1 christos else 1567 1.1 christos { 1568 1.1 christos /* We may have created entries in the .rela.got section. 1569 1.1 christos However, if we are not creating the dynamic sections, we will 1570 1.1 christos not actually use these entries. Reset the size of .rela.dlt, 1571 1.1 christos which will cause it to get stripped from the output file 1572 1.7 christos below. */ 1573 1.1 christos sec = hppa_info->dlt_rel_sec; 1574 1.1 christos if (sec != NULL) 1575 1.1 christos sec->size = 0; 1576 1.1 christos } 1577 1.1 christos 1578 1.1 christos /* Set up DLT, PLT and OPD offsets for local syms, and space for local 1579 1.3 christos dynamic relocs. */ 1580 1.1 christos for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) 1581 1.1 christos { 1582 1.1 christos bfd_signed_vma *local_dlt; 1583 1.1 christos bfd_signed_vma *end_local_dlt; 1584 1.1 christos bfd_signed_vma *local_plt; 1585 1.1 christos bfd_signed_vma *end_local_plt; 1586 1.1 christos bfd_signed_vma *local_opd; 1587 1.1 christos bfd_signed_vma *end_local_opd; 1588 1.1 christos bfd_size_type locsymcount; 1589 1.1 christos Elf_Internal_Shdr *symtab_hdr; 1590 1.1 christos asection *srel; 1591 1.1 christos 1592 1.1 christos if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) 1593 1.1 christos continue; 1594 1.1 christos 1595 1.1 christos for (sec = ibfd->sections; sec != NULL; sec = sec->next) 1596 1.1 christos { 1597 1.1 christos struct elf64_hppa_dyn_reloc_entry *hdh_p; 1598 1.1 christos 1599 1.1 christos for (hdh_p = ((struct elf64_hppa_dyn_reloc_entry *) 1600 1.1 christos elf_section_data (sec)->local_dynrel); 1601 1.1 christos hdh_p != NULL; 1602 1.1 christos hdh_p = hdh_p->next) 1603 1.1 christos { 1604 1.1 christos if (!bfd_is_abs_section (hdh_p->sec) 1605 1.1 christos && bfd_is_abs_section (hdh_p->sec->output_section)) 1606 1.1 christos { 1607 1.1 christos /* Input section has been discarded, either because 1608 1.1 christos it is a copy of a linkonce section or due to 1609 1.1 christos linker script /DISCARD/, so we'll be discarding 1610 1.1 christos the relocs too. */ 1611 1.1 christos } 1612 1.1 christos else if (hdh_p->count != 0) 1613 1.1 christos { 1614 1.1 christos srel = elf_section_data (hdh_p->sec)->sreloc; 1615 1.1 christos srel->size += hdh_p->count * sizeof (Elf64_External_Rela); 1616 1.1 christos if ((hdh_p->sec->output_section->flags & SEC_READONLY) != 0) 1617 1.1 christos info->flags |= DF_TEXTREL; 1618 1.1 christos } 1619 1.1 christos } 1620 1.1 christos } 1621 1.1 christos 1622 1.1 christos local_dlt = elf_local_got_refcounts (ibfd); 1623 1.1 christos if (!local_dlt) 1624 1.1 christos continue; 1625 1.1 christos 1626 1.1 christos symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; 1627 1.1 christos locsymcount = symtab_hdr->sh_info; 1628 1.1 christos end_local_dlt = local_dlt + locsymcount; 1629 1.1 christos sec = hppa_info->dlt_sec; 1630 1.1 christos srel = hppa_info->dlt_rel_sec; 1631 1.1 christos for (; local_dlt < end_local_dlt; ++local_dlt) 1632 1.1 christos { 1633 1.1 christos if (*local_dlt > 0) 1634 1.1 christos { 1635 1.1 christos *local_dlt = sec->size; 1636 1.6 christos sec->size += DLT_ENTRY_SIZE; 1637 1.8 christos if (bfd_link_pic (info)) 1638 1.1 christos { 1639 1.8 christos srel->size += sizeof (Elf64_External_Rela); 1640 1.1 christos } 1641 1.1 christos } 1642 1.1 christos else 1643 1.1 christos *local_dlt = (bfd_vma) -1; 1644 1.1 christos } 1645 1.1 christos 1646 1.1 christos local_plt = end_local_dlt; 1647 1.1 christos end_local_plt = local_plt + locsymcount; 1648 1.1 christos if (! hppa_info->root.dynamic_sections_created) 1649 1.1 christos { 1650 1.1 christos /* Won't be used, but be safe. */ 1651 1.1 christos for (; local_plt < end_local_plt; ++local_plt) 1652 1.1 christos *local_plt = (bfd_vma) -1; 1653 1.1 christos } 1654 1.1 christos else 1655 1.9 christos { 1656 1.9 christos sec = hppa_info->root.splt; 1657 1.1 christos srel = hppa_info->root.srelplt; 1658 1.1 christos for (; local_plt < end_local_plt; ++local_plt) 1659 1.1 christos { 1660 1.1 christos if (*local_plt > 0) 1661 1.1 christos { 1662 1.1 christos *local_plt = sec->size; 1663 1.6 christos sec->size += PLT_ENTRY_SIZE; 1664 1.1 christos if (bfd_link_pic (info)) 1665 1.1 christos srel->size += sizeof (Elf64_External_Rela); 1666 1.1 christos } 1667 1.1 christos else 1668 1.1 christos *local_plt = (bfd_vma) -1; 1669 1.1 christos } 1670 1.1 christos } 1671 1.1 christos 1672 1.1 christos local_opd = end_local_plt; 1673 1.1 christos end_local_opd = local_opd + locsymcount; 1674 1.1 christos if (! hppa_info->root.dynamic_sections_created) 1675 1.1 christos { 1676 1.1 christos /* Won't be used, but be safe. */ 1677 1.1 christos for (; local_opd < end_local_opd; ++local_opd) 1678 1.1 christos *local_opd = (bfd_vma) -1; 1679 1.1 christos } 1680 1.1 christos else 1681 1.1 christos { 1682 1.1 christos sec = hppa_info->opd_sec; 1683 1.1 christos srel = hppa_info->opd_rel_sec; 1684 1.1 christos for (; local_opd < end_local_opd; ++local_opd) 1685 1.1 christos { 1686 1.1 christos if (*local_opd > 0) 1687 1.1 christos { 1688 1.1 christos *local_opd = sec->size; 1689 1.6 christos sec->size += OPD_ENTRY_SIZE; 1690 1.1 christos if (bfd_link_pic (info)) 1691 1.1 christos srel->size += sizeof (Elf64_External_Rela); 1692 1.1 christos } 1693 1.1 christos else 1694 1.1 christos *local_opd = (bfd_vma) -1; 1695 1.1 christos } 1696 1.1 christos } 1697 1.1 christos } 1698 1.1 christos 1699 1.1 christos /* Allocate the GOT entries. */ 1700 1.1 christos 1701 1.1 christos data.info = info; 1702 1.1 christos if (hppa_info->dlt_sec) 1703 1.1 christos { 1704 1.7 christos data.ofs = hppa_info->dlt_sec->size; 1705 1.1 christos elf_link_hash_traverse (&hppa_info->root, 1706 1.1 christos allocate_global_data_dlt, &data); 1707 1.1 christos hppa_info->dlt_sec->size = data.ofs; 1708 1.1 christos } 1709 1.9 christos 1710 1.1 christos if (hppa_info->root.splt) 1711 1.9 christos { 1712 1.7 christos data.ofs = hppa_info->root.splt->size; 1713 1.8 christos elf_link_hash_traverse (&hppa_info->root, 1714 1.9 christos allocate_global_data_plt, &data); 1715 1.1 christos hppa_info->root.splt->size = data.ofs; 1716 1.1 christos } 1717 1.1 christos 1718 1.1 christos if (hppa_info->stub_sec) 1719 1.1 christos { 1720 1.7 christos data.ofs = 0x0; 1721 1.1 christos elf_link_hash_traverse (&hppa_info->root, 1722 1.1 christos allocate_global_data_stub, &data); 1723 1.1 christos hppa_info->stub_sec->size = data.ofs; 1724 1.1 christos } 1725 1.1 christos 1726 1.1 christos /* Allocate space for entries in the .opd section. */ 1727 1.1 christos if (hppa_info->opd_sec) 1728 1.1 christos { 1729 1.7 christos data.ofs = hppa_info->opd_sec->size; 1730 1.1 christos elf_link_hash_traverse (&hppa_info->root, 1731 1.1 christos allocate_global_data_opd, &data); 1732 1.1 christos hppa_info->opd_sec->size = data.ofs; 1733 1.1 christos } 1734 1.1 christos 1735 1.1 christos /* Now allocate space for dynamic relocations, if necessary. */ 1736 1.7 christos if (hppa_info->root.dynamic_sections_created) 1737 1.1 christos elf_link_hash_traverse (&hppa_info->root, 1738 1.1 christos allocate_dynrel_entries, &data); 1739 1.1 christos 1740 1.10 christos /* The sizes of all the sections are set. Allocate memory for them. */ 1741 1.1 christos relocs = false; 1742 1.1 christos for (sec = dynobj->sections; sec != NULL; sec = sec->next) 1743 1.1 christos { 1744 1.1 christos const char *name; 1745 1.1 christos 1746 1.1 christos if ((sec->flags & SEC_LINKER_CREATED) == 0) 1747 1.1 christos continue; 1748 1.1 christos 1749 1.1 christos /* It's OK to base decisions on the section name, because none 1750 1.9 christos of the dynobj section names depend upon the input files. */ 1751 1.1 christos name = bfd_section_name (sec); 1752 1.1 christos 1753 1.1 christos if (strcmp (name, ".plt") == 0) 1754 1.1 christos { 1755 1.9 christos /* Remember whether there is a PLT. */ 1756 1.1 christos ; 1757 1.1 christos } 1758 1.10 christos else if (strcmp (name, ".opd") == 0 1759 1.1 christos || startswith (name, ".dlt") 1760 1.1 christos || strcmp (name, ".stub") == 0 1761 1.1 christos || strcmp (name, ".got") == 0) 1762 1.1 christos { 1763 1.1 christos /* Strip this section if we don't need it; see the comment below. */ 1764 1.10 christos } 1765 1.1 christos else if (startswith (name, ".rela")) 1766 1.1 christos { 1767 1.1 christos if (sec->size != 0) 1768 1.1 christos { 1769 1.1 christos /* Remember whether there are any reloc sections other 1770 1.1 christos than .rela.plt. */ 1771 1.10 christos if (strcmp (name, ".rela.plt") != 0) 1772 1.1 christos relocs = true; 1773 1.1 christos 1774 1.1 christos /* We use the reloc_count field as a counter if we need 1775 1.1 christos to copy relocs into the output file. */ 1776 1.1 christos sec->reloc_count = 0; 1777 1.1 christos } 1778 1.1 christos } 1779 1.1 christos else 1780 1.1 christos { 1781 1.1 christos /* It's not one of our sections, so don't allocate space. */ 1782 1.1 christos continue; 1783 1.1 christos } 1784 1.1 christos 1785 1.1 christos if (sec->size == 0) 1786 1.1 christos { 1787 1.1 christos /* If we don't need this section, strip it from the 1788 1.1 christos output file. This is mostly to handle .rela.bss and 1789 1.1 christos .rela.plt. We must create both sections in 1790 1.1 christos create_dynamic_sections, because they must be created 1791 1.1 christos before the linker maps input sections to output 1792 1.1 christos sections. The linker does that before 1793 1.1 christos adjust_dynamic_symbol is called, and it is that 1794 1.1 christos function which decides whether anything needs to go 1795 1.1 christos into these sections. */ 1796 1.1 christos sec->flags |= SEC_EXCLUDE; 1797 1.1 christos continue; 1798 1.1 christos } 1799 1.1 christos 1800 1.1 christos if ((sec->flags & SEC_HAS_CONTENTS) == 0) 1801 1.1 christos continue; 1802 1.1 christos 1803 1.1 christos /* Allocate memory for the section contents if it has not 1804 1.1 christos been allocated already. We use bfd_zalloc here in case 1805 1.1 christos unused entries are not reclaimed before the section's 1806 1.1 christos contents are written out. This should not happen, but this 1807 1.1 christos way if it does, we get a R_PARISC_NONE reloc instead of 1808 1.1 christos garbage. */ 1809 1.1 christos if (sec->contents == NULL) 1810 1.1 christos { 1811 1.1 christos sec->contents = (bfd_byte *) bfd_zalloc (dynobj, sec->size); 1812 1.10 christos if (sec->contents == NULL) 1813 1.1 christos return false; 1814 1.1 christos } 1815 1.1 christos } 1816 1.7 christos 1817 1.1 christos if (hppa_info->root.dynamic_sections_created) 1818 1.1 christos { 1819 1.1 christos /* Always create a DT_PLTGOT. It actually has nothing to do with 1820 1.1 christos the PLT, it is how we communicate the __gp value of a load 1821 1.1 christos module to the dynamic linker. */ 1822 1.1 christos #define add_dynamic_entry(TAG, VAL) \ 1823 1.1 christos _bfd_elf_add_dynamic_entry (info, TAG, VAL) 1824 1.9 christos 1825 1.10 christos if (!add_dynamic_entry (DT_HP_DLD_FLAGS, 0)) 1826 1.1 christos return false; 1827 1.1 christos 1828 1.1 christos /* Add some entries to the .dynamic section. We fill in the 1829 1.1 christos values later, in elf64_hppa_finish_dynamic_sections, but we 1830 1.1 christos must add the entries now so that we get the correct size for 1831 1.1 christos the .dynamic section. The DT_DEBUG entry is filled in by the 1832 1.6 christos dynamic linker and used by the debugger. */ 1833 1.1 christos if (! bfd_link_pic (info)) 1834 1.9 christos { 1835 1.1 christos if (!add_dynamic_entry (DT_HP_DLD_HOOK, 0) 1836 1.10 christos || !add_dynamic_entry (DT_HP_LOAD_MAP, 0)) 1837 1.1 christos return false; 1838 1.1 christos } 1839 1.1 christos 1840 1.11 christos /* Force DT_FLAGS to always be set. 1841 1.11 christos Required by HPUX 11.00 patch PHSS_26559. 1842 1.11 christos PR 30743: But do not set them for non-HPUX targets. */ 1843 1.11 christos if (output_bfd->xvec == & hppa_elf64_vec) 1844 1.11 christos { 1845 1.11 christos if (!add_dynamic_entry (DT_FLAGS, (info)->flags)) 1846 1.11 christos return false; 1847 1.1 christos } 1848 1.1 christos } 1849 1.1 christos #undef add_dynamic_entry 1850 1.9 christos 1851 1.1 christos return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs); 1852 1.1 christos } 1853 1.1 christos 1854 1.1 christos /* Called after we have output the symbol into the dynamic symbol 1855 1.1 christos table, but before we output the symbol into the normal symbol 1856 1.1 christos table. 1857 1.1 christos 1858 1.1 christos For some symbols we had to change their address when outputting 1859 1.1 christos the dynamic symbol table. We undo that change here so that 1860 1.1 christos the symbols have their expected value in the normal symbol 1861 1.1 christos table. Ick. */ 1862 1.1 christos 1863 1.1 christos static int 1864 1.1 christos elf64_hppa_link_output_symbol_hook (struct bfd_link_info *info ATTRIBUTE_UNUSED, 1865 1.1 christos const char *name, 1866 1.1 christos Elf_Internal_Sym *sym, 1867 1.1 christos asection *input_sec ATTRIBUTE_UNUSED, 1868 1.1 christos struct elf_link_hash_entry *eh) 1869 1.1 christos { 1870 1.1 christos struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); 1871 1.1 christos 1872 1.1 christos /* We may be called with the file symbol or section symbols. 1873 1.1 christos They never need munging, so it is safe to ignore them. */ 1874 1.1 christos if (!name || !eh) 1875 1.1 christos return 1; 1876 1.1 christos 1877 1.1 christos /* Function symbols for which we created .opd entries *may* have been 1878 1.1 christos munged by finish_dynamic_symbol and have to be un-munged here. 1879 1.1 christos 1880 1.1 christos Note that finish_dynamic_symbol sometimes turns dynamic symbols 1881 1.1 christos into non-dynamic ones, so we initialize st_shndx to -1 in 1882 1.1 christos mark_exported_functions and check to see if it was overwritten 1883 1.1 christos here instead of just checking eh->dynindx. */ 1884 1.1 christos if (hh->want_opd && hh->st_shndx != -1) 1885 1.1 christos { 1886 1.1 christos /* Restore the saved value and section index. */ 1887 1.1 christos sym->st_value = hh->st_value; 1888 1.1 christos sym->st_shndx = hh->st_shndx; 1889 1.1 christos } 1890 1.1 christos 1891 1.1 christos return 1; 1892 1.1 christos } 1893 1.1 christos 1894 1.1 christos /* Finish up dynamic symbol handling. We set the contents of various 1895 1.1 christos dynamic sections here. */ 1896 1.10 christos 1897 1.1 christos static bool 1898 1.1 christos elf64_hppa_finish_dynamic_symbol (bfd *output_bfd, 1899 1.1 christos struct bfd_link_info *info, 1900 1.1 christos struct elf_link_hash_entry *eh, 1901 1.1 christos Elf_Internal_Sym *sym) 1902 1.1 christos { 1903 1.1 christos struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); 1904 1.1 christos asection *stub, *splt, *sopd, *spltrel; 1905 1.1 christos struct elf64_hppa_link_hash_table *hppa_info; 1906 1.1 christos 1907 1.1 christos hppa_info = hppa_link_hash_table (info); 1908 1.1 christos 1909 1.9 christos stub = hppa_info->stub_sec; 1910 1.1 christos splt = hppa_info->root.splt; 1911 1.9 christos sopd = hppa_info->opd_sec; 1912 1.1 christos spltrel = hppa_info->root.srelplt; 1913 1.1 christos 1914 1.1 christos /* Incredible. It is actually necessary to NOT use the symbol's real 1915 1.1 christos value when building the dynamic symbol table for a shared library. 1916 1.1 christos At least for symbols that refer to functions. 1917 1.1 christos 1918 1.1 christos We will store a new value and section index into the symbol long 1919 1.1 christos enough to output it into the dynamic symbol table, then we restore 1920 1.1 christos the original values (in elf64_hppa_link_output_symbol_hook). */ 1921 1.1 christos if (hh->want_opd) 1922 1.1 christos { 1923 1.1 christos BFD_ASSERT (sopd != NULL); 1924 1.1 christos 1925 1.1 christos /* Save away the original value and section index so that we 1926 1.1 christos can restore them later. */ 1927 1.1 christos hh->st_value = sym->st_value; 1928 1.1 christos hh->st_shndx = sym->st_shndx; 1929 1.1 christos 1930 1.1 christos /* For the dynamic symbol table entry, we want the value to be 1931 1.1 christos address of this symbol's entry within the .opd section. */ 1932 1.1 christos sym->st_value = (hh->opd_offset 1933 1.1 christos + sopd->output_offset 1934 1.1 christos + sopd->output_section->vma); 1935 1.1 christos sym->st_shndx = _bfd_elf_section_from_bfd_section (output_bfd, 1936 1.1 christos sopd->output_section); 1937 1.1 christos } 1938 1.1 christos 1939 1.1 christos /* Initialize a .plt entry if requested. */ 1940 1.1 christos if (hh->want_plt 1941 1.1 christos && elf64_hppa_dynamic_symbol_p (eh, info)) 1942 1.1 christos { 1943 1.1 christos bfd_vma value; 1944 1.1 christos Elf_Internal_Rela rel; 1945 1.1 christos bfd_byte *loc; 1946 1.1 christos 1947 1.1 christos BFD_ASSERT (splt != NULL && spltrel != NULL); 1948 1.1 christos 1949 1.1 christos /* We do not actually care about the value in the PLT entry 1950 1.1 christos if we are creating a shared library and the symbol is 1951 1.1 christos still undefined, we create a dynamic relocation to fill 1952 1.6 christos in the correct value. */ 1953 1.1 christos if (bfd_link_pic (info) && eh->root.type == bfd_link_hash_undefined) 1954 1.1 christos value = 0; 1955 1.1 christos else 1956 1.1 christos value = (eh->root.u.def.value + eh->root.u.def.section->vma); 1957 1.1 christos 1958 1.1 christos /* Fill in the entry in the procedure linkage table. 1959 1.1 christos 1960 1.1 christos The format of a plt entry is 1961 1.1 christos <funcaddr> <__gp>. 1962 1.1 christos 1963 1.1 christos plt_offset is the offset within the PLT section at which to 1964 1.1 christos install the PLT entry. 1965 1.1 christos 1966 1.1 christos We are modifying the in-memory PLT contents here, so we do not add 1967 1.1 christos in the output_offset of the PLT section. */ 1968 1.1 christos 1969 1.9 christos bfd_put_64 (splt->owner, value, splt->contents + hh->plt_offset); 1970 1.1 christos value = _bfd_get_gp_value (info->output_bfd); 1971 1.1 christos bfd_put_64 (splt->owner, value, splt->contents + hh->plt_offset + 0x8); 1972 1.1 christos 1973 1.1 christos /* Create a dynamic IPLT relocation for this entry. 1974 1.1 christos 1975 1.1 christos We are creating a relocation in the output file's PLT section, 1976 1.1 christos which is included within the DLT secton. So we do need to include 1977 1.1 christos the PLT's output_offset in the computation of the relocation's 1978 1.1 christos address. */ 1979 1.1 christos rel.r_offset = (hh->plt_offset + splt->output_offset 1980 1.1 christos + splt->output_section->vma); 1981 1.1 christos rel.r_info = ELF64_R_INFO (hh->eh.dynindx, R_PARISC_IPLT); 1982 1.1 christos rel.r_addend = 0; 1983 1.1 christos 1984 1.1 christos loc = spltrel->contents; 1985 1.9 christos loc += spltrel->reloc_count++ * sizeof (Elf64_External_Rela); 1986 1.1 christos bfd_elf64_swap_reloca_out (info->output_bfd, &rel, loc); 1987 1.1 christos } 1988 1.1 christos 1989 1.1 christos /* Initialize an external call stub entry if requested. */ 1990 1.1 christos if (hh->want_stub 1991 1.1 christos && elf64_hppa_dynamic_symbol_p (eh, info)) 1992 1.1 christos { 1993 1.1 christos bfd_vma value; 1994 1.1 christos int insn; 1995 1.1 christos unsigned int max_offset; 1996 1.1 christos 1997 1.1 christos BFD_ASSERT (stub != NULL); 1998 1.1 christos 1999 1.1 christos /* Install the generic stub template. 2000 1.1 christos 2001 1.1 christos We are modifying the contents of the stub section, so we do not 2002 1.1 christos need to include the stub section's output_offset here. */ 2003 1.1 christos memcpy (stub->contents + hh->stub_offset, plt_stub, sizeof (plt_stub)); 2004 1.1 christos 2005 1.1 christos /* Fix up the first ldd instruction. 2006 1.1 christos 2007 1.1 christos We are modifying the contents of the STUB section in memory, 2008 1.1 christos so we do not need to include its output offset in this computation. 2009 1.1 christos 2010 1.1 christos Note the plt_offset value is the value of the PLT entry relative to 2011 1.1 christos the start of the PLT section. These instructions will reference 2012 1.1 christos data relative to the value of __gp, which may not necessarily have 2013 1.1 christos the same address as the start of the PLT section. 2014 1.1 christos 2015 1.1 christos gp_offset contains the offset of __gp within the PLT section. */ 2016 1.1 christos value = hh->plt_offset - hppa_info->gp_offset; 2017 1.1 christos 2018 1.1 christos insn = bfd_get_32 (stub->owner, stub->contents + hh->stub_offset); 2019 1.1 christos if (output_bfd->arch_info->mach >= 25) 2020 1.1 christos { 2021 1.1 christos /* Wide mode allows 16 bit offsets. */ 2022 1.1 christos max_offset = 32768; 2023 1.1 christos insn &= ~ 0xfff1; 2024 1.1 christos insn |= re_assemble_16 ((int) value); 2025 1.1 christos } 2026 1.1 christos else 2027 1.1 christos { 2028 1.1 christos max_offset = 8192; 2029 1.1 christos insn &= ~ 0x3ff1; 2030 1.1 christos insn |= re_assemble_14 ((int) value); 2031 1.1 christos } 2032 1.1 christos 2033 1.1 christos if ((value & 7) || value + max_offset >= 2*max_offset - 8) 2034 1.7 christos { 2035 1.7 christos _bfd_error_handler 2036 1.8 christos /* xgettext:c-format */ 2037 1.8 christos (_("stub entry for %s cannot load .plt, dp offset = %" PRId64), 2038 1.10 christos hh->eh.root.root.string, (int64_t) value); 2039 1.1 christos return false; 2040 1.1 christos } 2041 1.1 christos 2042 1.1 christos bfd_put_32 (stub->owner, (bfd_vma) insn, 2043 1.1 christos stub->contents + hh->stub_offset); 2044 1.1 christos 2045 1.1 christos /* Fix up the second ldd instruction. */ 2046 1.1 christos value += 8; 2047 1.1 christos insn = bfd_get_32 (stub->owner, stub->contents + hh->stub_offset + 8); 2048 1.1 christos if (output_bfd->arch_info->mach >= 25) 2049 1.1 christos { 2050 1.1 christos insn &= ~ 0xfff1; 2051 1.1 christos insn |= re_assemble_16 ((int) value); 2052 1.1 christos } 2053 1.1 christos else 2054 1.1 christos { 2055 1.1 christos insn &= ~ 0x3ff1; 2056 1.1 christos insn |= re_assemble_14 ((int) value); 2057 1.1 christos } 2058 1.1 christos bfd_put_32 (stub->owner, (bfd_vma) insn, 2059 1.1 christos stub->contents + hh->stub_offset + 8); 2060 1.1 christos } 2061 1.10 christos 2062 1.1 christos return true; 2063 1.1 christos } 2064 1.1 christos 2065 1.1 christos /* The .opd section contains FPTRs for each function this file 2066 1.1 christos exports. Initialize the FPTR entries. */ 2067 1.10 christos 2068 1.1 christos static bool 2069 1.1 christos elf64_hppa_finalize_opd (struct elf_link_hash_entry *eh, void *data) 2070 1.1 christos { 2071 1.1 christos struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); 2072 1.1 christos struct bfd_link_info *info = (struct bfd_link_info *)data; 2073 1.1 christos struct elf64_hppa_link_hash_table *hppa_info; 2074 1.1 christos asection *sopd; 2075 1.1 christos asection *sopdrel; 2076 1.1 christos 2077 1.1 christos hppa_info = hppa_link_hash_table (info); 2078 1.10 christos if (hppa_info == NULL) 2079 1.1 christos return false; 2080 1.1 christos 2081 1.1 christos sopd = hppa_info->opd_sec; 2082 1.1 christos sopdrel = hppa_info->opd_rel_sec; 2083 1.1 christos 2084 1.1 christos if (hh->want_opd) 2085 1.1 christos { 2086 1.1 christos bfd_vma value; 2087 1.1 christos 2088 1.1 christos /* The first two words of an .opd entry are zero. 2089 1.1 christos 2090 1.1 christos We are modifying the contents of the OPD section in memory, so we 2091 1.1 christos do not need to include its output offset in this computation. */ 2092 1.1 christos memset (sopd->contents + hh->opd_offset, 0, 16); 2093 1.1 christos 2094 1.1 christos value = (eh->root.u.def.value 2095 1.1 christos + eh->root.u.def.section->output_section->vma 2096 1.1 christos + eh->root.u.def.section->output_offset); 2097 1.1 christos 2098 1.1 christos /* The next word is the address of the function. */ 2099 1.1 christos bfd_put_64 (sopd->owner, value, sopd->contents + hh->opd_offset + 16); 2100 1.1 christos 2101 1.9 christos /* The last word is our local __gp value. */ 2102 1.1 christos value = _bfd_get_gp_value (info->output_bfd); 2103 1.1 christos bfd_put_64 (sopd->owner, value, sopd->contents + hh->opd_offset + 24); 2104 1.1 christos } 2105 1.1 christos 2106 1.1 christos /* If we are generating a shared library, we must generate EPLT relocations 2107 1.1 christos for each entry in the .opd, even for static functions (they may have 2108 1.6 christos had their address taken). */ 2109 1.1 christos if (bfd_link_pic (info) && hh->want_opd) 2110 1.1 christos { 2111 1.1 christos Elf_Internal_Rela rel; 2112 1.1 christos bfd_byte *loc; 2113 1.1 christos int dynindx; 2114 1.1 christos 2115 1.1 christos /* We may need to do a relocation against a local symbol, in 2116 1.1 christos which case we have to look up it's dynamic symbol index off 2117 1.1 christos the local symbol hash table. */ 2118 1.1 christos if (eh->dynindx != -1) 2119 1.1 christos dynindx = eh->dynindx; 2120 1.1 christos else 2121 1.1 christos dynindx 2122 1.1 christos = _bfd_elf_link_lookup_local_dynindx (info, hh->owner, 2123 1.1 christos hh->sym_indx); 2124 1.1 christos 2125 1.1 christos /* The offset of this relocation is the absolute address of the 2126 1.1 christos .opd entry for this symbol. */ 2127 1.1 christos rel.r_offset = (hh->opd_offset + sopd->output_offset 2128 1.1 christos + sopd->output_section->vma); 2129 1.1 christos 2130 1.1 christos /* If H is non-null, then we have an external symbol. 2131 1.1 christos 2132 1.1 christos It is imperative that we use a different dynamic symbol for the 2133 1.1 christos EPLT relocation if the symbol has global scope. 2134 1.1 christos 2135 1.1 christos In the dynamic symbol table, the function symbol will have a value 2136 1.1 christos which is address of the function's .opd entry. 2137 1.1 christos 2138 1.1 christos Thus, we can not use that dynamic symbol for the EPLT relocation 2139 1.1 christos (if we did, the data in the .opd would reference itself rather 2140 1.1 christos than the actual address of the function). Instead we have to use 2141 1.1 christos a new dynamic symbol which has the same value as the original global 2142 1.1 christos function symbol. 2143 1.1 christos 2144 1.1 christos We prefix the original symbol with a "." and use the new symbol in 2145 1.1 christos the EPLT relocation. This new symbol has already been recorded in 2146 1.1 christos the symbol table, we just have to look it up and use it. 2147 1.1 christos 2148 1.1 christos We do not have such problems with static functions because we do 2149 1.1 christos not make their addresses in the dynamic symbol table point to 2150 1.1 christos the .opd entry. Ultimately this should be safe since a static 2151 1.1 christos function can not be directly referenced outside of its shared 2152 1.1 christos library. 2153 1.1 christos 2154 1.1 christos We do have to play similar games for FPTR relocations in shared 2155 1.1 christos libraries, including those for static symbols. See the FPTR 2156 1.1 christos handling in elf64_hppa_finalize_dynreloc. */ 2157 1.1 christos if (eh) 2158 1.1 christos { 2159 1.1 christos char *new_name; 2160 1.1 christos struct elf_link_hash_entry *nh; 2161 1.6 christos 2162 1.1 christos new_name = concat (".", eh->root.root.string, NULL); 2163 1.1 christos 2164 1.10 christos nh = elf_link_hash_lookup (elf_hash_table (info), 2165 1.1 christos new_name, true, true, false); 2166 1.1 christos 2167 1.1 christos /* All we really want from the new symbol is its dynamic 2168 1.1 christos symbol index. */ 2169 1.1 christos if (nh) 2170 1.6 christos dynindx = nh->dynindx; 2171 1.1 christos free (new_name); 2172 1.1 christos } 2173 1.1 christos 2174 1.1 christos rel.r_addend = 0; 2175 1.1 christos rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_EPLT); 2176 1.1 christos 2177 1.1 christos loc = sopdrel->contents; 2178 1.9 christos loc += sopdrel->reloc_count++ * sizeof (Elf64_External_Rela); 2179 1.1 christos bfd_elf64_swap_reloca_out (info->output_bfd, &rel, loc); 2180 1.10 christos } 2181 1.1 christos return true; 2182 1.1 christos } 2183 1.1 christos 2184 1.1 christos /* The .dlt section contains addresses for items referenced through the 2185 1.1 christos dlt. Note that we can have a DLTIND relocation for a local symbol, thus 2186 1.1 christos we can not depend on finish_dynamic_symbol to initialize the .dlt. */ 2187 1.10 christos 2188 1.1 christos static bool 2189 1.1 christos elf64_hppa_finalize_dlt (struct elf_link_hash_entry *eh, void *data) 2190 1.1 christos { 2191 1.1 christos struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); 2192 1.1 christos struct bfd_link_info *info = (struct bfd_link_info *)data; 2193 1.1 christos struct elf64_hppa_link_hash_table *hppa_info; 2194 1.1 christos asection *sdlt, *sdltrel; 2195 1.1 christos 2196 1.1 christos hppa_info = hppa_link_hash_table (info); 2197 1.10 christos if (hppa_info == NULL) 2198 1.1 christos return false; 2199 1.1 christos 2200 1.1 christos sdlt = hppa_info->dlt_sec; 2201 1.1 christos sdltrel = hppa_info->dlt_rel_sec; 2202 1.1 christos 2203 1.1 christos /* H/DYN_H may refer to a local variable and we know it's 2204 1.1 christos address, so there is no need to create a relocation. Just install 2205 1.1 christos the proper value into the DLT, note this shortcut can not be 2206 1.6 christos skipped when building a shared library. */ 2207 1.1 christos if (! bfd_link_pic (info) && hh && hh->want_dlt) 2208 1.1 christos { 2209 1.1 christos bfd_vma value; 2210 1.1 christos 2211 1.1 christos /* If we had an LTOFF_FPTR style relocation we want the DLT entry 2212 1.1 christos to point to the FPTR entry in the .opd section. 2213 1.1 christos 2214 1.1 christos We include the OPD's output offset in this computation as 2215 1.1 christos we are referring to an absolute address in the resulting 2216 1.1 christos object file. */ 2217 1.1 christos if (hh->want_opd) 2218 1.1 christos { 2219 1.1 christos value = (hh->opd_offset 2220 1.1 christos + hppa_info->opd_sec->output_offset 2221 1.1 christos + hppa_info->opd_sec->output_section->vma); 2222 1.1 christos } 2223 1.1 christos else if ((eh->root.type == bfd_link_hash_defined 2224 1.1 christos || eh->root.type == bfd_link_hash_defweak) 2225 1.1 christos && eh->root.u.def.section) 2226 1.1 christos { 2227 1.1 christos value = eh->root.u.def.value + eh->root.u.def.section->output_offset; 2228 1.1 christos if (eh->root.u.def.section->output_section) 2229 1.1 christos value += eh->root.u.def.section->output_section->vma; 2230 1.1 christos else 2231 1.1 christos value += eh->root.u.def.section->vma; 2232 1.1 christos } 2233 1.1 christos else 2234 1.1 christos /* We have an undefined function reference. */ 2235 1.1 christos value = 0; 2236 1.1 christos 2237 1.1 christos /* We do not need to include the output offset of the DLT section 2238 1.1 christos here because we are modifying the in-memory contents. */ 2239 1.1 christos bfd_put_64 (sdlt->owner, value, sdlt->contents + hh->dlt_offset); 2240 1.1 christos } 2241 1.1 christos 2242 1.1 christos /* Create a relocation for the DLT entry associated with this symbol. 2243 1.1 christos When building a shared library the symbol does not have to be dynamic. */ 2244 1.6 christos if (hh->want_dlt 2245 1.1 christos && (elf64_hppa_dynamic_symbol_p (eh, info) || bfd_link_pic (info))) 2246 1.1 christos { 2247 1.1 christos Elf_Internal_Rela rel; 2248 1.1 christos bfd_byte *loc; 2249 1.1 christos int dynindx; 2250 1.1 christos 2251 1.1 christos /* We may need to do a relocation against a local symbol, in 2252 1.1 christos which case we have to look up it's dynamic symbol index off 2253 1.1 christos the local symbol hash table. */ 2254 1.1 christos if (eh && eh->dynindx != -1) 2255 1.1 christos dynindx = eh->dynindx; 2256 1.1 christos else 2257 1.1 christos dynindx 2258 1.1 christos = _bfd_elf_link_lookup_local_dynindx (info, hh->owner, 2259 1.1 christos hh->sym_indx); 2260 1.1 christos 2261 1.1 christos /* Create a dynamic relocation for this entry. Do include the output 2262 1.1 christos offset of the DLT entry since we need an absolute address in the 2263 1.1 christos resulting object file. */ 2264 1.1 christos rel.r_offset = (hh->dlt_offset + sdlt->output_offset 2265 1.1 christos + sdlt->output_section->vma); 2266 1.1 christos if (eh && eh->type == STT_FUNC) 2267 1.1 christos rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_FPTR64); 2268 1.1 christos else 2269 1.1 christos rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_DIR64); 2270 1.1 christos rel.r_addend = 0; 2271 1.1 christos 2272 1.1 christos loc = sdltrel->contents; 2273 1.9 christos loc += sdltrel->reloc_count++ * sizeof (Elf64_External_Rela); 2274 1.1 christos bfd_elf64_swap_reloca_out (info->output_bfd, &rel, loc); 2275 1.10 christos } 2276 1.1 christos return true; 2277 1.1 christos } 2278 1.1 christos 2279 1.1 christos /* Finalize the dynamic relocations. Specifically the FPTR relocations 2280 1.1 christos for dynamic functions used to initialize static data. */ 2281 1.10 christos 2282 1.1 christos static bool 2283 1.1 christos elf64_hppa_finalize_dynreloc (struct elf_link_hash_entry *eh, 2284 1.1 christos void *data) 2285 1.1 christos { 2286 1.1 christos struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); 2287 1.1 christos struct bfd_link_info *info = (struct bfd_link_info *)data; 2288 1.1 christos struct elf64_hppa_link_hash_table *hppa_info; 2289 1.1 christos int dynamic_symbol; 2290 1.1 christos 2291 1.1 christos dynamic_symbol = elf64_hppa_dynamic_symbol_p (eh, info); 2292 1.6 christos 2293 1.10 christos if (!dynamic_symbol && !bfd_link_pic (info)) 2294 1.1 christos return true; 2295 1.1 christos 2296 1.1 christos if (hh->reloc_entries) 2297 1.1 christos { 2298 1.1 christos struct elf64_hppa_dyn_reloc_entry *rent; 2299 1.1 christos int dynindx; 2300 1.1 christos 2301 1.1 christos hppa_info = hppa_link_hash_table (info); 2302 1.10 christos if (hppa_info == NULL) 2303 1.1 christos return false; 2304 1.1 christos 2305 1.1 christos /* We may need to do a relocation against a local symbol, in 2306 1.1 christos which case we have to look up it's dynamic symbol index off 2307 1.1 christos the local symbol hash table. */ 2308 1.1 christos if (eh->dynindx != -1) 2309 1.1 christos dynindx = eh->dynindx; 2310 1.1 christos else 2311 1.1 christos dynindx 2312 1.1 christos = _bfd_elf_link_lookup_local_dynindx (info, hh->owner, 2313 1.1 christos hh->sym_indx); 2314 1.1 christos 2315 1.1 christos for (rent = hh->reloc_entries; rent; rent = rent->next) 2316 1.1 christos { 2317 1.1 christos Elf_Internal_Rela rel; 2318 1.1 christos bfd_byte *loc; 2319 1.1 christos 2320 1.1 christos /* Allocate one iff we are building a shared library, the relocation 2321 1.6 christos isn't a R_PARISC_FPTR64, or we don't want an opd entry. */ 2322 1.6 christos if (!bfd_link_pic (info) 2323 1.1 christos && rent->type == R_PARISC_FPTR64 && hh->want_opd) 2324 1.1 christos continue; 2325 1.1 christos 2326 1.1 christos /* Create a dynamic relocation for this entry. 2327 1.1 christos 2328 1.1 christos We need the output offset for the reloc's section because 2329 1.1 christos we are creating an absolute address in the resulting object 2330 1.1 christos file. */ 2331 1.1 christos rel.r_offset = (rent->offset + rent->sec->output_offset 2332 1.1 christos + rent->sec->output_section->vma); 2333 1.1 christos 2334 1.1 christos /* An FPTR64 relocation implies that we took the address of 2335 1.1 christos a function and that the function has an entry in the .opd 2336 1.1 christos section. We want the FPTR64 relocation to reference the 2337 1.1 christos entry in .opd. 2338 1.1 christos 2339 1.1 christos We could munge the symbol value in the dynamic symbol table 2340 1.1 christos (in fact we already do for functions with global scope) to point 2341 1.1 christos to the .opd entry. Then we could use that dynamic symbol in 2342 1.1 christos this relocation. 2343 1.1 christos 2344 1.1 christos Or we could do something sensible, not munge the symbol's 2345 1.1 christos address and instead just use a different symbol to reference 2346 1.1 christos the .opd entry. At least that seems sensible until you 2347 1.1 christos realize there's no local dynamic symbols we can use for that 2348 1.1 christos purpose. Thus the hair in the check_relocs routine. 2349 1.1 christos 2350 1.1 christos We use a section symbol recorded by check_relocs as the 2351 1.1 christos base symbol for the relocation. The addend is the difference 2352 1.6 christos between the section symbol and the address of the .opd entry. */ 2353 1.6 christos if (bfd_link_pic (info) 2354 1.1 christos && rent->type == R_PARISC_FPTR64 && hh->want_opd) 2355 1.1 christos { 2356 1.1 christos bfd_vma value, value2; 2357 1.1 christos 2358 1.1 christos /* First compute the address of the opd entry for this symbol. */ 2359 1.1 christos value = (hh->opd_offset 2360 1.1 christos + hppa_info->opd_sec->output_section->vma 2361 1.1 christos + hppa_info->opd_sec->output_offset); 2362 1.1 christos 2363 1.1 christos /* Compute the value of the start of the section with 2364 1.1 christos the relocation. */ 2365 1.1 christos value2 = (rent->sec->output_section->vma 2366 1.1 christos + rent->sec->output_offset); 2367 1.1 christos 2368 1.1 christos /* Compute the difference between the start of the section 2369 1.1 christos with the relocation and the opd entry. */ 2370 1.1 christos value -= value2; 2371 1.1 christos 2372 1.1 christos /* The result becomes the addend of the relocation. */ 2373 1.1 christos rel.r_addend = value; 2374 1.1 christos 2375 1.1 christos /* The section symbol becomes the symbol for the dynamic 2376 1.1 christos relocation. */ 2377 1.1 christos dynindx 2378 1.1 christos = _bfd_elf_link_lookup_local_dynindx (info, 2379 1.1 christos rent->sec->owner, 2380 1.1 christos rent->sec_symndx); 2381 1.1 christos } 2382 1.1 christos else 2383 1.1 christos rel.r_addend = rent->addend; 2384 1.1 christos 2385 1.1 christos rel.r_info = ELF64_R_INFO (dynindx, rent->type); 2386 1.1 christos 2387 1.1 christos loc = hppa_info->other_rel_sec->contents; 2388 1.1 christos loc += (hppa_info->other_rel_sec->reloc_count++ 2389 1.9 christos * sizeof (Elf64_External_Rela)); 2390 1.1 christos bfd_elf64_swap_reloca_out (info->output_bfd, &rel, loc); 2391 1.1 christos } 2392 1.1 christos } 2393 1.10 christos 2394 1.1 christos return true; 2395 1.1 christos } 2396 1.1 christos 2397 1.1 christos /* Used to decide how to sort relocs in an optimal manner for the 2398 1.1 christos dynamic linker, before writing them out. */ 2399 1.1 christos 2400 1.1 christos static enum elf_reloc_type_class 2401 1.1 christos elf64_hppa_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED, 2402 1.1 christos const asection *rel_sec ATTRIBUTE_UNUSED, 2403 1.1 christos const Elf_Internal_Rela *rela) 2404 1.1 christos { 2405 1.1 christos if (ELF64_R_SYM (rela->r_info) == STN_UNDEF) 2406 1.1 christos return reloc_class_relative; 2407 1.1 christos 2408 1.1 christos switch ((int) ELF64_R_TYPE (rela->r_info)) 2409 1.1 christos { 2410 1.1 christos case R_PARISC_IPLT: 2411 1.1 christos return reloc_class_plt; 2412 1.1 christos case R_PARISC_COPY: 2413 1.1 christos return reloc_class_copy; 2414 1.1 christos default: 2415 1.1 christos return reloc_class_normal; 2416 1.1 christos } 2417 1.1 christos } 2418 1.1 christos 2419 1.1 christos /* Finish up the dynamic sections. */ 2420 1.10 christos 2421 1.1 christos static bool 2422 1.1 christos elf64_hppa_finish_dynamic_sections (bfd *output_bfd, 2423 1.1 christos struct bfd_link_info *info) 2424 1.1 christos { 2425 1.1 christos bfd *dynobj; 2426 1.1 christos asection *sdyn; 2427 1.1 christos struct elf64_hppa_link_hash_table *hppa_info; 2428 1.1 christos 2429 1.1 christos hppa_info = hppa_link_hash_table (info); 2430 1.10 christos if (hppa_info == NULL) 2431 1.1 christos return false; 2432 1.1 christos 2433 1.1 christos /* Finalize the contents of the .opd section. */ 2434 1.1 christos elf_link_hash_traverse (elf_hash_table (info), 2435 1.1 christos elf64_hppa_finalize_opd, 2436 1.1 christos info); 2437 1.1 christos 2438 1.1 christos elf_link_hash_traverse (elf_hash_table (info), 2439 1.1 christos elf64_hppa_finalize_dynreloc, 2440 1.1 christos info); 2441 1.1 christos 2442 1.1 christos /* Finalize the contents of the .dlt section. */ 2443 1.1 christos dynobj = elf_hash_table (info)->dynobj; 2444 1.1 christos /* Finalize the contents of the .dlt section. */ 2445 1.1 christos elf_link_hash_traverse (elf_hash_table (info), 2446 1.1 christos elf64_hppa_finalize_dlt, 2447 1.1 christos info); 2448 1.1 christos 2449 1.1 christos sdyn = bfd_get_linker_section (dynobj, ".dynamic"); 2450 1.1 christos 2451 1.1 christos if (elf_hash_table (info)->dynamic_sections_created) 2452 1.1 christos { 2453 1.1 christos Elf64_External_Dyn *dyncon, *dynconend; 2454 1.1 christos 2455 1.1 christos BFD_ASSERT (sdyn != NULL); 2456 1.1 christos 2457 1.1 christos dyncon = (Elf64_External_Dyn *) sdyn->contents; 2458 1.1 christos dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size); 2459 1.1 christos for (; dyncon < dynconend; dyncon++) 2460 1.1 christos { 2461 1.1 christos Elf_Internal_Dyn dyn; 2462 1.1 christos asection *s; 2463 1.1 christos 2464 1.1 christos bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn); 2465 1.1 christos 2466 1.1 christos switch (dyn.d_tag) 2467 1.1 christos { 2468 1.1 christos default: 2469 1.1 christos break; 2470 1.1 christos 2471 1.1 christos case DT_HP_LOAD_MAP: 2472 1.1 christos /* Compute the absolute address of 16byte scratchpad area 2473 1.1 christos for the dynamic linker. 2474 1.1 christos 2475 1.1 christos By convention the linker script will allocate the scratchpad 2476 1.1 christos area at the start of the .data section. So all we have to 2477 1.1 christos to is find the start of the .data section. */ 2478 1.1 christos s = bfd_get_section_by_name (output_bfd, ".data"); 2479 1.10 christos if (!s) 2480 1.1 christos return false; 2481 1.1 christos dyn.d_un.d_ptr = s->vma; 2482 1.1 christos bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); 2483 1.1 christos break; 2484 1.1 christos 2485 1.1 christos case DT_PLTGOT: 2486 1.1 christos /* HP's use PLTGOT to set the GOT register. */ 2487 1.1 christos dyn.d_un.d_ptr = _bfd_get_gp_value (output_bfd); 2488 1.1 christos bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); 2489 1.1 christos break; 2490 1.1 christos 2491 1.9 christos case DT_JMPREL: 2492 1.1 christos s = hppa_info->root.srelplt; 2493 1.1 christos dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; 2494 1.1 christos bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); 2495 1.1 christos break; 2496 1.1 christos 2497 1.9 christos case DT_PLTRELSZ: 2498 1.1 christos s = hppa_info->root.srelplt; 2499 1.1 christos dyn.d_un.d_val = s->size; 2500 1.1 christos bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); 2501 1.1 christos break; 2502 1.1 christos 2503 1.1 christos case DT_RELA: 2504 1.1 christos s = hppa_info->other_rel_sec; 2505 1.1 christos if (! s || ! s->size) 2506 1.1 christos s = hppa_info->dlt_rel_sec; 2507 1.1 christos if (! s || ! s->size) 2508 1.1 christos s = hppa_info->opd_rel_sec; 2509 1.1 christos dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; 2510 1.1 christos bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); 2511 1.1 christos break; 2512 1.1 christos 2513 1.1 christos case DT_RELASZ: 2514 1.1 christos s = hppa_info->other_rel_sec; 2515 1.1 christos dyn.d_un.d_val = s->size; 2516 1.1 christos s = hppa_info->dlt_rel_sec; 2517 1.1 christos dyn.d_un.d_val += s->size; 2518 1.1 christos s = hppa_info->opd_rel_sec; 2519 1.1 christos dyn.d_un.d_val += s->size; 2520 1.1 christos /* There is some question about whether or not the size of 2521 1.1 christos the PLT relocs should be included here. HP's tools do 2522 1.9 christos it, so we'll emulate them. */ 2523 1.1 christos s = hppa_info->root.srelplt; 2524 1.1 christos dyn.d_un.d_val += s->size; 2525 1.1 christos bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); 2526 1.1 christos break; 2527 1.1 christos 2528 1.1 christos } 2529 1.1 christos } 2530 1.1 christos } 2531 1.10 christos 2532 1.1 christos return true; 2533 1.1 christos } 2534 1.1 christos 2535 1.1 christos /* Support for core dump NOTE sections. */ 2536 1.10 christos 2537 1.1 christos static bool 2538 1.1 christos elf64_hppa_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) 2539 1.1 christos { 2540 1.1 christos int offset; 2541 1.1 christos size_t size; 2542 1.1 christos 2543 1.1 christos switch (note->descsz) 2544 1.1 christos { 2545 1.10 christos default: 2546 1.1 christos return false; 2547 1.1 christos 2548 1.1 christos case 760: /* Linux/hppa */ 2549 1.1 christos /* pr_cursig */ 2550 1.1 christos elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12); 2551 1.1 christos 2552 1.1 christos /* pr_pid */ 2553 1.1 christos elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 32); 2554 1.1 christos 2555 1.1 christos /* pr_reg */ 2556 1.1 christos offset = 112; 2557 1.1 christos size = 640; 2558 1.1 christos 2559 1.1 christos break; 2560 1.1 christos } 2561 1.1 christos 2562 1.1 christos /* Make a ".reg/999" section. */ 2563 1.1 christos return _bfd_elfcore_make_pseudosection (abfd, ".reg", 2564 1.1 christos size, note->descpos + offset); 2565 1.1 christos } 2566 1.10 christos 2567 1.1 christos static bool 2568 1.1 christos elf64_hppa_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) 2569 1.1 christos { 2570 1.1 christos char * command; 2571 1.1 christos int n; 2572 1.1 christos 2573 1.1 christos switch (note->descsz) 2574 1.1 christos { 2575 1.10 christos default: 2576 1.1 christos return false; 2577 1.1 christos 2578 1.1 christos case 136: /* Linux/hppa elf_prpsinfo. */ 2579 1.1 christos elf_tdata (abfd)->core->program 2580 1.1 christos = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16); 2581 1.1 christos elf_tdata (abfd)->core->command 2582 1.1 christos = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80); 2583 1.1 christos } 2584 1.1 christos 2585 1.1 christos /* Note that for some reason, a spurious space is tacked 2586 1.1 christos onto the end of the args in some (at least one anyway) 2587 1.1 christos implementations, so strip it off if it exists. */ 2588 1.1 christos command = elf_tdata (abfd)->core->command; 2589 1.1 christos n = strlen (command); 2590 1.1 christos 2591 1.1 christos if (0 < n && command[n - 1] == ' ') 2592 1.1 christos command[n - 1] = '\0'; 2593 1.10 christos 2594 1.1 christos return true; 2595 1.1 christos } 2596 1.1 christos 2597 1.1 christos /* Return the number of additional phdrs we will need. 2598 1.1 christos 2599 1.1 christos The generic ELF code only creates PT_PHDRs for executables. The HP 2600 1.1 christos dynamic linker requires PT_PHDRs for dynamic libraries too. 2601 1.1 christos 2602 1.1 christos This routine indicates that the backend needs one additional program 2603 1.1 christos header for that case. 2604 1.1 christos 2605 1.1 christos Note we do not have access to the link info structure here, so we have 2606 1.1 christos to guess whether or not we are building a shared library based on the 2607 1.1 christos existence of a .interp section. */ 2608 1.1 christos 2609 1.1 christos static int 2610 1.1 christos elf64_hppa_additional_program_headers (bfd *abfd, 2611 1.1 christos struct bfd_link_info *info ATTRIBUTE_UNUSED) 2612 1.1 christos { 2613 1.1 christos asection *s; 2614 1.1 christos 2615 1.1 christos /* If we are creating a shared library, then we have to create a 2616 1.1 christos PT_PHDR segment. HP's dynamic linker chokes without it. */ 2617 1.1 christos s = bfd_get_section_by_name (abfd, ".interp"); 2618 1.1 christos if (! s) 2619 1.1 christos return 1; 2620 1.1 christos return 0; 2621 1.1 christos } 2622 1.10 christos 2623 1.7 christos static bool 2624 1.7 christos elf64_hppa_allow_non_load_phdr (bfd *abfd ATTRIBUTE_UNUSED, 2625 1.7 christos const Elf_Internal_Phdr *phdr ATTRIBUTE_UNUSED, 2626 1.7 christos unsigned int count ATTRIBUTE_UNUSED) 2627 1.10 christos { 2628 1.7 christos return true; 2629 1.7 christos } 2630 1.1 christos 2631 1.1 christos /* Allocate and initialize any program headers required by this 2632 1.1 christos specific backend. 2633 1.1 christos 2634 1.1 christos The generic ELF code only creates PT_PHDRs for executables. The HP 2635 1.1 christos dynamic linker requires PT_PHDRs for dynamic libraries too. 2636 1.1 christos 2637 1.1 christos This allocates the PT_PHDR and initializes it in a manner suitable 2638 1.1 christos for the HP linker. 2639 1.1 christos 2640 1.1 christos Note we do not have access to the link info structure here, so we have 2641 1.1 christos to guess whether or not we are building a shared library based on the 2642 1.1 christos existence of a .interp section. */ 2643 1.10 christos 2644 1.7 christos static bool 2645 1.1 christos elf64_hppa_modify_segment_map (bfd *abfd, struct bfd_link_info *info) 2646 1.1 christos { 2647 1.1 christos struct elf_segment_map *m; 2648 1.7 christos 2649 1.7 christos m = elf_seg_map (abfd); 2650 1.1 christos if (info != NULL && !info->user_phdrs && m != NULL && m->p_type != PT_PHDR) 2651 1.7 christos { 2652 1.7 christos m = ((struct elf_segment_map *) 2653 1.1 christos bfd_zalloc (abfd, (bfd_size_type) sizeof *m)); 2654 1.10 christos if (m == NULL) 2655 1.1 christos return false; 2656 1.7 christos 2657 1.7 christos m->p_type = PT_PHDR; 2658 1.7 christos m->p_flags = PF_R | PF_X; 2659 1.7 christos m->p_flags_valid = 1; 2660 1.7 christos m->p_paddr_valid = 1; 2661 1.1 christos m->includes_phdrs = 1; 2662 1.7 christos 2663 1.7 christos m->next = elf_seg_map (abfd); 2664 1.1 christos elf_seg_map (abfd) = m; 2665 1.1 christos } 2666 1.7 christos 2667 1.1 christos for (m = elf_seg_map (abfd) ; m != NULL; m = m->next) 2668 1.1 christos if (m->p_type == PT_LOAD) 2669 1.1 christos { 2670 1.1 christos unsigned int i; 2671 1.1 christos 2672 1.1 christos for (i = 0; i < m->count; i++) 2673 1.1 christos { 2674 1.1 christos /* The code "hint" is not really a hint. It is a requirement 2675 1.1 christos for certain versions of the HP dynamic linker. Worse yet, 2676 1.1 christos it must be set even if the shared library does not have 2677 1.1 christos any code in its "text" segment (thus the check for .hash 2678 1.1 christos to catch this situation). */ 2679 1.1 christos if (m->sections[i]->flags & SEC_CODE 2680 1.1 christos || (strcmp (m->sections[i]->name, ".hash") == 0)) 2681 1.1 christos m->p_flags |= (PF_X | PF_HP_CODE); 2682 1.1 christos } 2683 1.1 christos } 2684 1.10 christos 2685 1.1 christos return true; 2686 1.1 christos } 2687 1.1 christos 2688 1.1 christos /* Called when writing out an object file to decide the type of a 2689 1.1 christos symbol. */ 2690 1.1 christos static int 2691 1.1 christos elf64_hppa_elf_get_symbol_type (Elf_Internal_Sym *elf_sym, 2692 1.1 christos int type) 2693 1.1 christos { 2694 1.1 christos if (ELF_ST_TYPE (elf_sym->st_info) == STT_PARISC_MILLI) 2695 1.1 christos return STT_PARISC_MILLI; 2696 1.1 christos else 2697 1.1 christos return type; 2698 1.1 christos } 2699 1.1 christos 2700 1.1 christos /* Support HP specific sections for core files. */ 2701 1.10 christos 2702 1.1 christos static bool 2703 1.1 christos elf64_hppa_section_from_phdr (bfd *abfd, Elf_Internal_Phdr *hdr, int sec_index, 2704 1.1 christos const char *typename) 2705 1.1 christos { 2706 1.1 christos if (hdr->p_type == PT_HP_CORE_KERNEL) 2707 1.1 christos { 2708 1.1 christos asection *sect; 2709 1.1 christos 2710 1.10 christos if (!_bfd_elf_make_section_from_phdr (abfd, hdr, sec_index, typename)) 2711 1.1 christos return false; 2712 1.1 christos 2713 1.1 christos sect = bfd_make_section_anyway (abfd, ".kernel"); 2714 1.10 christos if (sect == NULL) 2715 1.1 christos return false; 2716 1.1 christos sect->size = hdr->p_filesz; 2717 1.1 christos sect->filepos = hdr->p_offset; 2718 1.10 christos sect->flags = SEC_HAS_CONTENTS | SEC_READONLY; 2719 1.1 christos return true; 2720 1.1 christos } 2721 1.1 christos 2722 1.1 christos if (hdr->p_type == PT_HP_CORE_PROC) 2723 1.1 christos { 2724 1.1 christos int sig; 2725 1.1 christos 2726 1.10 christos if (bfd_seek (abfd, hdr->p_offset, SEEK_SET) != 0) 2727 1.11 christos return false; 2728 1.10 christos if (bfd_read (&sig, 4, abfd) != 4) 2729 1.1 christos return false; 2730 1.1 christos 2731 1.1 christos elf_tdata (abfd)->core->signal = sig; 2732 1.1 christos 2733 1.10 christos if (!_bfd_elf_make_section_from_phdr (abfd, hdr, sec_index, typename)) 2734 1.1 christos return false; 2735 1.1 christos 2736 1.1 christos /* GDB uses the ".reg" section to read register contents. */ 2737 1.1 christos return _bfd_elfcore_make_pseudosection (abfd, ".reg", hdr->p_filesz, 2738 1.1 christos hdr->p_offset); 2739 1.1 christos } 2740 1.1 christos 2741 1.1 christos if (hdr->p_type == PT_HP_CORE_LOADABLE 2742 1.1 christos || hdr->p_type == PT_HP_CORE_STACK 2743 1.1 christos || hdr->p_type == PT_HP_CORE_MMF) 2744 1.1 christos hdr->p_type = PT_LOAD; 2745 1.1 christos 2746 1.1 christos return _bfd_elf_make_section_from_phdr (abfd, hdr, sec_index, typename); 2747 1.1 christos } 2748 1.1 christos 2749 1.1 christos /* Hook called by the linker routine which adds symbols from an object 2750 1.1 christos file. HP's libraries define symbols with HP specific section 2751 1.1 christos indices, which we have to handle. */ 2752 1.10 christos 2753 1.1 christos static bool 2754 1.1 christos elf_hppa_add_symbol_hook (bfd *abfd, 2755 1.1 christos struct bfd_link_info *info ATTRIBUTE_UNUSED, 2756 1.1 christos Elf_Internal_Sym *sym, 2757 1.1 christos const char **namep ATTRIBUTE_UNUSED, 2758 1.1 christos flagword *flagsp ATTRIBUTE_UNUSED, 2759 1.1 christos asection **secp, 2760 1.1 christos bfd_vma *valp) 2761 1.1 christos { 2762 1.1 christos unsigned int sec_index = sym->st_shndx; 2763 1.1 christos 2764 1.1 christos switch (sec_index) 2765 1.1 christos { 2766 1.1 christos case SHN_PARISC_ANSI_COMMON: 2767 1.1 christos *secp = bfd_make_section_old_way (abfd, ".PARISC.ansi.common"); 2768 1.1 christos (*secp)->flags |= SEC_IS_COMMON; 2769 1.1 christos *valp = sym->st_size; 2770 1.1 christos break; 2771 1.1 christos 2772 1.1 christos case SHN_PARISC_HUGE_COMMON: 2773 1.1 christos *secp = bfd_make_section_old_way (abfd, ".PARISC.huge.common"); 2774 1.1 christos (*secp)->flags |= SEC_IS_COMMON; 2775 1.1 christos *valp = sym->st_size; 2776 1.1 christos break; 2777 1.1 christos } 2778 1.10 christos 2779 1.1 christos return true; 2780 1.1 christos } 2781 1.10 christos 2782 1.1 christos static bool 2783 1.1 christos elf_hppa_unmark_useless_dynamic_symbols (struct elf_link_hash_entry *h, 2784 1.1 christos void *data) 2785 1.1 christos { 2786 1.1 christos struct bfd_link_info *info = data; 2787 1.1 christos 2788 1.1 christos /* If we are not creating a shared library, and this symbol is 2789 1.1 christos referenced by a shared library but is not defined anywhere, then 2790 1.1 christos the generic code will warn that it is undefined. 2791 1.1 christos 2792 1.1 christos This behavior is undesirable on HPs since the standard shared 2793 1.1 christos libraries contain references to undefined symbols. 2794 1.1 christos 2795 1.1 christos So we twiddle the flags associated with such symbols so that they 2796 1.1 christos will not trigger the warning. ?!? FIXME. This is horribly fragile. 2797 1.1 christos 2798 1.1 christos Ultimately we should have better controls over the generic ELF BFD 2799 1.6 christos linker code. */ 2800 1.1 christos if (! bfd_link_relocatable (info) 2801 1.1 christos && info->unresolved_syms_in_shared_libs != RM_IGNORE 2802 1.1 christos && h->root.type == bfd_link_hash_undefined 2803 1.1 christos && h->ref_dynamic 2804 1.1 christos && !h->ref_regular) 2805 1.1 christos { 2806 1.1 christos h->ref_dynamic = 0; 2807 1.1 christos h->pointer_equality_needed = 1; 2808 1.1 christos } 2809 1.10 christos 2810 1.1 christos return true; 2811 1.1 christos } 2812 1.10 christos 2813 1.1 christos static bool 2814 1.1 christos elf_hppa_remark_useless_dynamic_symbols (struct elf_link_hash_entry *h, 2815 1.1 christos void *data) 2816 1.1 christos { 2817 1.1 christos struct bfd_link_info *info = data; 2818 1.1 christos 2819 1.1 christos /* If we are not creating a shared library, and this symbol is 2820 1.1 christos referenced by a shared library but is not defined anywhere, then 2821 1.1 christos the generic code will warn that it is undefined. 2822 1.1 christos 2823 1.1 christos This behavior is undesirable on HPs since the standard shared 2824 1.1 christos libraries contain references to undefined symbols. 2825 1.1 christos 2826 1.1 christos So we twiddle the flags associated with such symbols so that they 2827 1.1 christos will not trigger the warning. ?!? FIXME. This is horribly fragile. 2828 1.1 christos 2829 1.1 christos Ultimately we should have better controls over the generic ELF BFD 2830 1.6 christos linker code. */ 2831 1.1 christos if (! bfd_link_relocatable (info) 2832 1.1 christos && info->unresolved_syms_in_shared_libs != RM_IGNORE 2833 1.1 christos && h->root.type == bfd_link_hash_undefined 2834 1.1 christos && !h->ref_dynamic 2835 1.1 christos && !h->ref_regular 2836 1.1 christos && h->pointer_equality_needed) 2837 1.1 christos { 2838 1.1 christos h->ref_dynamic = 1; 2839 1.1 christos h->pointer_equality_needed = 0; 2840 1.1 christos } 2841 1.10 christos 2842 1.1 christos return true; 2843 1.1 christos } 2844 1.10 christos 2845 1.1 christos static bool 2846 1.1 christos elf_hppa_is_dynamic_loader_symbol (const char *name) 2847 1.1 christos { 2848 1.1 christos return (! strcmp (name, "__CPU_REVISION") 2849 1.1 christos || ! strcmp (name, "__CPU_KEYBITS_1") 2850 1.1 christos || ! strcmp (name, "__SYSTEM_ID_D") 2851 1.1 christos || ! strcmp (name, "__FPU_MODEL") 2852 1.1 christos || ! strcmp (name, "__FPU_REVISION") 2853 1.1 christos || ! strcmp (name, "__ARGC") 2854 1.1 christos || ! strcmp (name, "__ARGV") 2855 1.1 christos || ! strcmp (name, "__ENVP") 2856 1.1 christos || ! strcmp (name, "__TLS_SIZE_D") 2857 1.1 christos || ! strcmp (name, "__LOAD_INFO") 2858 1.1 christos || ! strcmp (name, "__systab")); 2859 1.1 christos } 2860 1.1 christos 2861 1.1 christos /* Record the lowest address for the data and text segments. */ 2862 1.1 christos static void 2863 1.1 christos elf_hppa_record_segment_addrs (bfd *abfd, 2864 1.1 christos asection *section, 2865 1.1 christos void *data) 2866 1.1 christos { 2867 1.1 christos struct elf64_hppa_link_hash_table *hppa_info = data; 2868 1.1 christos 2869 1.1 christos if ((section->flags & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) 2870 1.1 christos { 2871 1.1 christos bfd_vma value; 2872 1.1 christos Elf_Internal_Phdr *p; 2873 1.1 christos 2874 1.1 christos p = _bfd_elf_find_segment_containing_section (abfd, section->output_section); 2875 1.1 christos BFD_ASSERT (p != NULL); 2876 1.1 christos value = p->p_vaddr; 2877 1.1 christos 2878 1.1 christos if (section->flags & SEC_READONLY) 2879 1.1 christos { 2880 1.1 christos if (value < hppa_info->text_segment_base) 2881 1.1 christos hppa_info->text_segment_base = value; 2882 1.1 christos } 2883 1.1 christos else 2884 1.1 christos { 2885 1.1 christos if (value < hppa_info->data_segment_base) 2886 1.1 christos hppa_info->data_segment_base = value; 2887 1.1 christos } 2888 1.1 christos } 2889 1.1 christos } 2890 1.1 christos 2891 1.1 christos /* Called after we have seen all the input files/sections, but before 2892 1.1 christos final symbol resolution and section placement has been determined. 2893 1.1 christos 2894 1.1 christos We use this hook to (possibly) provide a value for __gp, then we 2895 1.1 christos fall back to the generic ELF final link routine. */ 2896 1.10 christos 2897 1.1 christos static bool 2898 1.1 christos elf_hppa_final_link (bfd *abfd, struct bfd_link_info *info) 2899 1.6 christos { 2900 1.1 christos struct stat buf; 2901 1.1 christos struct elf64_hppa_link_hash_table *hppa_info = hppa_link_hash_table (info); 2902 1.1 christos 2903 1.10 christos if (hppa_info == NULL) 2904 1.1 christos return false; 2905 1.6 christos 2906 1.1 christos if (! bfd_link_relocatable (info)) 2907 1.1 christos { 2908 1.1 christos struct elf_link_hash_entry *gp; 2909 1.1 christos bfd_vma gp_val; 2910 1.1 christos 2911 1.1 christos /* The linker script defines a value for __gp iff it was referenced 2912 1.1 christos by one of the objects being linked. First try to find the symbol 2913 1.1 christos in the hash table. If that fails, just compute the value __gp 2914 1.10 christos should have had. */ 2915 1.10 christos gp = elf_link_hash_lookup (elf_hash_table (info), "__gp", false, 2916 1.1 christos false, false); 2917 1.1 christos 2918 1.1 christos if (gp) 2919 1.1 christos { 2920 1.1 christos 2921 1.1 christos /* Adjust the value of __gp as we may want to slide it into the 2922 1.1 christos .plt section so that the stubs can access PLT entries without 2923 1.1 christos using an addil sequence. */ 2924 1.1 christos gp->root.u.def.value += hppa_info->gp_offset; 2925 1.1 christos 2926 1.1 christos gp_val = (gp->root.u.def.section->output_section->vma 2927 1.1 christos + gp->root.u.def.section->output_offset 2928 1.1 christos + gp->root.u.def.value); 2929 1.1 christos } 2930 1.1 christos else 2931 1.1 christos { 2932 1.1 christos asection *sec; 2933 1.1 christos 2934 1.1 christos /* First look for a .plt section. If found, then __gp is the 2935 1.1 christos address of the .plt + gp_offset. 2936 1.1 christos 2937 1.1 christos If no .plt is found, then look for .dlt, .opd and .data (in 2938 1.1 christos that order) and set __gp to the base address of whichever 2939 1.1 christos section is found first. */ 2940 1.9 christos 2941 1.1 christos sec = hppa_info->root.splt; 2942 1.1 christos if (sec && ! (sec->flags & SEC_EXCLUDE)) 2943 1.1 christos gp_val = (sec->output_offset 2944 1.1 christos + sec->output_section->vma 2945 1.1 christos + hppa_info->gp_offset); 2946 1.1 christos else 2947 1.1 christos { 2948 1.1 christos sec = hppa_info->dlt_sec; 2949 1.1 christos if (!sec || (sec->flags & SEC_EXCLUDE)) 2950 1.1 christos sec = hppa_info->opd_sec; 2951 1.1 christos if (!sec || (sec->flags & SEC_EXCLUDE)) 2952 1.1 christos sec = bfd_get_section_by_name (abfd, ".data"); 2953 1.1 christos if (!sec || (sec->flags & SEC_EXCLUDE)) 2954 1.1 christos gp_val = 0; 2955 1.1 christos else 2956 1.1 christos gp_val = sec->output_offset + sec->output_section->vma; 2957 1.1 christos } 2958 1.1 christos } 2959 1.1 christos 2960 1.1 christos /* Install whatever value we found/computed for __gp. */ 2961 1.1 christos _bfd_set_gp_value (abfd, gp_val); 2962 1.1 christos } 2963 1.1 christos 2964 1.1 christos /* We need to know the base of the text and data segments so that we 2965 1.1 christos can perform SEGREL relocations. We will record the base addresses 2966 1.1 christos when we encounter the first SEGREL relocation. */ 2967 1.1 christos hppa_info->text_segment_base = (bfd_vma)-1; 2968 1.1 christos hppa_info->data_segment_base = (bfd_vma)-1; 2969 1.1 christos 2970 1.1 christos /* HP's shared libraries have references to symbols that are not 2971 1.1 christos defined anywhere. The generic ELF BFD linker code will complain 2972 1.1 christos about such symbols. 2973 1.1 christos 2974 1.1 christos So we detect the losing case and arrange for the flags on the symbol 2975 1.1 christos to indicate that it was never referenced. This keeps the generic 2976 1.1 christos ELF BFD link code happy and appears to not create any secondary 2977 1.1 christos problems. Ultimately we need a way to control the behavior of the 2978 1.1 christos generic ELF BFD link code better. */ 2979 1.1 christos elf_link_hash_traverse (elf_hash_table (info), 2980 1.1 christos elf_hppa_unmark_useless_dynamic_symbols, 2981 1.1 christos info); 2982 1.1 christos 2983 1.6 christos /* Invoke the regular ELF backend linker to do all the work. */ 2984 1.10 christos if (!bfd_elf_final_link (abfd, info)) 2985 1.1 christos return false; 2986 1.1 christos 2987 1.1 christos elf_link_hash_traverse (elf_hash_table (info), 2988 1.1 christos elf_hppa_remark_useless_dynamic_symbols, 2989 1.1 christos info); 2990 1.1 christos 2991 1.1 christos /* If we're producing a final executable, sort the contents of the 2992 1.6 christos unwind section. */ 2993 1.10 christos if (bfd_link_relocatable (info)) 2994 1.1 christos return true; 2995 1.6 christos 2996 1.6 christos /* Do not attempt to sort non-regular files. This is here 2997 1.6 christos especially for configure scripts and kernel builds which run 2998 1.9 christos tests with "ld [...] -o /dev/null". */ 2999 1.6 christos if (stat (bfd_get_filename (abfd), &buf) != 0 3000 1.10 christos || !S_ISREG(buf.st_mode)) 3001 1.6 christos return true; 3002 1.6 christos 3003 1.1 christos return elf_hppa_sort_unwind (abfd); 3004 1.1 christos } 3005 1.1 christos 3006 1.1 christos /* Relocate the given INSN. VALUE should be the actual value we want 3007 1.1 christos to insert into the instruction, ie by this point we should not be 3008 1.1 christos concerned with computing an offset relative to the DLT, PC, etc. 3009 1.1 christos Instead this routine is meant to handle the bit manipulations needed 3010 1.1 christos to insert the relocation into the given instruction. */ 3011 1.1 christos 3012 1.1 christos static int 3013 1.1 christos elf_hppa_relocate_insn (int insn, int sym_value, unsigned int r_type) 3014 1.1 christos { 3015 1.1 christos switch (r_type) 3016 1.1 christos { 3017 1.1 christos /* This is any 22 bit branch. In PA2.0 syntax it corresponds to 3018 1.1 christos the "B" instruction. */ 3019 1.1 christos case R_PARISC_PCREL22F: 3020 1.1 christos case R_PARISC_PCREL22C: 3021 1.1 christos return (insn & ~0x3ff1ffd) | re_assemble_22 (sym_value); 3022 1.1 christos 3023 1.1 christos /* This is any 12 bit branch. */ 3024 1.1 christos case R_PARISC_PCREL12F: 3025 1.1 christos return (insn & ~0x1ffd) | re_assemble_12 (sym_value); 3026 1.1 christos 3027 1.1 christos /* This is any 17 bit branch. In PA2.0 syntax it also corresponds 3028 1.1 christos to the "B" instruction as well as BE. */ 3029 1.1 christos case R_PARISC_PCREL17F: 3030 1.1 christos case R_PARISC_DIR17F: 3031 1.1 christos case R_PARISC_DIR17R: 3032 1.1 christos case R_PARISC_PCREL17C: 3033 1.1 christos case R_PARISC_PCREL17R: 3034 1.1 christos return (insn & ~0x1f1ffd) | re_assemble_17 (sym_value); 3035 1.1 christos 3036 1.1 christos /* ADDIL or LDIL instructions. */ 3037 1.1 christos case R_PARISC_DLTREL21L: 3038 1.1 christos case R_PARISC_DLTIND21L: 3039 1.1 christos case R_PARISC_LTOFF_FPTR21L: 3040 1.1 christos case R_PARISC_PCREL21L: 3041 1.1 christos case R_PARISC_LTOFF_TP21L: 3042 1.1 christos case R_PARISC_DPREL21L: 3043 1.1 christos case R_PARISC_PLTOFF21L: 3044 1.1 christos case R_PARISC_DIR21L: 3045 1.1 christos return (insn & ~0x1fffff) | re_assemble_21 (sym_value); 3046 1.1 christos 3047 1.1 christos /* LDO and integer loads/stores with 14 bit displacements. */ 3048 1.1 christos case R_PARISC_DLTREL14R: 3049 1.1 christos case R_PARISC_DLTREL14F: 3050 1.1 christos case R_PARISC_DLTIND14R: 3051 1.1 christos case R_PARISC_DLTIND14F: 3052 1.1 christos case R_PARISC_LTOFF_FPTR14R: 3053 1.1 christos case R_PARISC_PCREL14R: 3054 1.1 christos case R_PARISC_PCREL14F: 3055 1.1 christos case R_PARISC_LTOFF_TP14R: 3056 1.1 christos case R_PARISC_LTOFF_TP14F: 3057 1.1 christos case R_PARISC_DPREL14R: 3058 1.1 christos case R_PARISC_DPREL14F: 3059 1.1 christos case R_PARISC_PLTOFF14R: 3060 1.1 christos case R_PARISC_PLTOFF14F: 3061 1.1 christos case R_PARISC_DIR14R: 3062 1.1 christos case R_PARISC_DIR14F: 3063 1.1 christos return (insn & ~0x3fff) | low_sign_unext (sym_value, 14); 3064 1.1 christos 3065 1.1 christos /* PA2.0W LDO and integer loads/stores with 16 bit displacements. */ 3066 1.1 christos case R_PARISC_LTOFF_FPTR16F: 3067 1.1 christos case R_PARISC_PCREL16F: 3068 1.1 christos case R_PARISC_LTOFF_TP16F: 3069 1.1 christos case R_PARISC_GPREL16F: 3070 1.1 christos case R_PARISC_PLTOFF16F: 3071 1.1 christos case R_PARISC_DIR16F: 3072 1.1 christos case R_PARISC_LTOFF16F: 3073 1.1 christos return (insn & ~0xffff) | re_assemble_16 (sym_value); 3074 1.1 christos 3075 1.1 christos /* Doubleword loads and stores with a 14 bit displacement. */ 3076 1.1 christos case R_PARISC_DLTREL14DR: 3077 1.1 christos case R_PARISC_DLTIND14DR: 3078 1.1 christos case R_PARISC_LTOFF_FPTR14DR: 3079 1.1 christos case R_PARISC_LTOFF_FPTR16DF: 3080 1.1 christos case R_PARISC_PCREL14DR: 3081 1.1 christos case R_PARISC_PCREL16DF: 3082 1.1 christos case R_PARISC_LTOFF_TP14DR: 3083 1.1 christos case R_PARISC_LTOFF_TP16DF: 3084 1.1 christos case R_PARISC_DPREL14DR: 3085 1.1 christos case R_PARISC_GPREL16DF: 3086 1.1 christos case R_PARISC_PLTOFF14DR: 3087 1.1 christos case R_PARISC_PLTOFF16DF: 3088 1.1 christos case R_PARISC_DIR14DR: 3089 1.1 christos case R_PARISC_DIR16DF: 3090 1.1 christos case R_PARISC_LTOFF16DF: 3091 1.1 christos return (insn & ~0x3ff1) | (((sym_value & 0x2000) >> 13) 3092 1.1 christos | ((sym_value & 0x1ff8) << 1)); 3093 1.1 christos 3094 1.1 christos /* Floating point single word load/store instructions. */ 3095 1.1 christos case R_PARISC_DLTREL14WR: 3096 1.1 christos case R_PARISC_DLTIND14WR: 3097 1.1 christos case R_PARISC_LTOFF_FPTR14WR: 3098 1.1 christos case R_PARISC_LTOFF_FPTR16WF: 3099 1.1 christos case R_PARISC_PCREL14WR: 3100 1.1 christos case R_PARISC_PCREL16WF: 3101 1.1 christos case R_PARISC_LTOFF_TP14WR: 3102 1.1 christos case R_PARISC_LTOFF_TP16WF: 3103 1.1 christos case R_PARISC_DPREL14WR: 3104 1.1 christos case R_PARISC_GPREL16WF: 3105 1.1 christos case R_PARISC_PLTOFF14WR: 3106 1.1 christos case R_PARISC_PLTOFF16WF: 3107 1.1 christos case R_PARISC_DIR16WF: 3108 1.1 christos case R_PARISC_DIR14WR: 3109 1.1 christos case R_PARISC_LTOFF16WF: 3110 1.1 christos return (insn & ~0x3ff9) | (((sym_value & 0x2000) >> 13) 3111 1.1 christos | ((sym_value & 0x1ffc) << 1)); 3112 1.1 christos 3113 1.1 christos default: 3114 1.1 christos return insn; 3115 1.1 christos } 3116 1.1 christos } 3117 1.1 christos 3118 1.1 christos /* Compute the value for a relocation (REL) during a final link stage, 3119 1.1 christos then insert the value into the proper location in CONTENTS. 3120 1.1 christos 3121 1.1 christos VALUE is a tentative value for the relocation and may be overridden 3122 1.1 christos and modified here based on the specific relocation to be performed. 3123 1.1 christos 3124 1.1 christos For example we do conversions for PC-relative branches in this routine 3125 1.1 christos or redirection of calls to external routines to stubs. 3126 1.1 christos 3127 1.1 christos The work of actually applying the relocation is left to a helper 3128 1.1 christos routine in an attempt to reduce the complexity and size of this 3129 1.1 christos function. */ 3130 1.1 christos 3131 1.1 christos static bfd_reloc_status_type 3132 1.1 christos elf_hppa_final_link_relocate (Elf_Internal_Rela *rel, 3133 1.1 christos bfd *input_bfd, 3134 1.1 christos bfd *output_bfd, 3135 1.1 christos asection *input_section, 3136 1.1 christos bfd_byte *contents, 3137 1.1 christos bfd_vma value, 3138 1.1 christos struct bfd_link_info *info, 3139 1.1 christos asection *sym_sec, 3140 1.1 christos struct elf_link_hash_entry *eh) 3141 1.1 christos { 3142 1.1 christos struct elf64_hppa_link_hash_table *hppa_info = hppa_link_hash_table (info); 3143 1.1 christos struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); 3144 1.1 christos bfd_vma *local_offsets; 3145 1.1 christos Elf_Internal_Shdr *symtab_hdr; 3146 1.1 christos int insn; 3147 1.1 christos bfd_vma max_branch_offset = 0; 3148 1.1 christos bfd_vma offset = rel->r_offset; 3149 1.1 christos bfd_signed_vma addend = rel->r_addend; 3150 1.1 christos reloc_howto_type *howto = elf_hppa_howto_table + ELF_R_TYPE (rel->r_info); 3151 1.1 christos unsigned int r_symndx = ELF_R_SYM (rel->r_info); 3152 1.1 christos unsigned int r_type = howto->type; 3153 1.1 christos bfd_byte *hit_data = contents + offset; 3154 1.1 christos 3155 1.1 christos if (hppa_info == NULL) 3156 1.1 christos return bfd_reloc_notsupported; 3157 1.1 christos 3158 1.1 christos symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; 3159 1.1 christos local_offsets = elf_local_got_offsets (input_bfd); 3160 1.1 christos insn = bfd_get_32 (input_bfd, hit_data); 3161 1.1 christos 3162 1.1 christos switch (r_type) 3163 1.1 christos { 3164 1.1 christos case R_PARISC_NONE: 3165 1.1 christos break; 3166 1.1 christos 3167 1.1 christos /* Basic function call support. 3168 1.1 christos 3169 1.1 christos Note for a call to a function defined in another dynamic library 3170 1.1 christos we want to redirect the call to a stub. */ 3171 1.1 christos 3172 1.1 christos /* PC relative relocs without an implicit offset. */ 3173 1.1 christos case R_PARISC_PCREL21L: 3174 1.1 christos case R_PARISC_PCREL14R: 3175 1.1 christos case R_PARISC_PCREL14F: 3176 1.1 christos case R_PARISC_PCREL14WR: 3177 1.1 christos case R_PARISC_PCREL14DR: 3178 1.1 christos case R_PARISC_PCREL16F: 3179 1.1 christos case R_PARISC_PCREL16WF: 3180 1.1 christos case R_PARISC_PCREL16DF: 3181 1.1 christos { 3182 1.1 christos /* If this is a call to a function defined in another dynamic 3183 1.1 christos library, then redirect the call to the local stub for this 3184 1.1 christos function. */ 3185 1.1 christos if (sym_sec == NULL || sym_sec->output_section == NULL) 3186 1.1 christos value = (hh->stub_offset + hppa_info->stub_sec->output_offset 3187 1.1 christos + hppa_info->stub_sec->output_section->vma); 3188 1.1 christos 3189 1.1 christos /* Turn VALUE into a proper PC relative address. */ 3190 1.1 christos value -= (offset + input_section->output_offset 3191 1.1 christos + input_section->output_section->vma); 3192 1.1 christos 3193 1.1 christos /* Adjust for any field selectors. */ 3194 1.1 christos if (r_type == R_PARISC_PCREL21L) 3195 1.1 christos value = hppa_field_adjust (value, -8 + addend, e_lsel); 3196 1.1 christos else if (r_type == R_PARISC_PCREL14F 3197 1.1 christos || r_type == R_PARISC_PCREL16F 3198 1.1 christos || r_type == R_PARISC_PCREL16WF 3199 1.1 christos || r_type == R_PARISC_PCREL16DF) 3200 1.1 christos value = hppa_field_adjust (value, -8 + addend, e_fsel); 3201 1.1 christos else 3202 1.1 christos value = hppa_field_adjust (value, -8 + addend, e_rsel); 3203 1.1 christos 3204 1.1 christos /* Apply the relocation to the given instruction. */ 3205 1.1 christos insn = elf_hppa_relocate_insn (insn, (int) value, r_type); 3206 1.1 christos break; 3207 1.1 christos } 3208 1.1 christos 3209 1.1 christos case R_PARISC_PCREL12F: 3210 1.1 christos case R_PARISC_PCREL22F: 3211 1.1 christos case R_PARISC_PCREL17F: 3212 1.1 christos case R_PARISC_PCREL22C: 3213 1.1 christos case R_PARISC_PCREL17C: 3214 1.1 christos case R_PARISC_PCREL17R: 3215 1.1 christos { 3216 1.1 christos /* If this is a call to a function defined in another dynamic 3217 1.1 christos library, then redirect the call to the local stub for this 3218 1.1 christos function. */ 3219 1.1 christos if (sym_sec == NULL || sym_sec->output_section == NULL) 3220 1.1 christos value = (hh->stub_offset + hppa_info->stub_sec->output_offset 3221 1.1 christos + hppa_info->stub_sec->output_section->vma); 3222 1.1 christos 3223 1.1 christos /* Turn VALUE into a proper PC relative address. */ 3224 1.1 christos value -= (offset + input_section->output_offset 3225 1.1 christos + input_section->output_section->vma); 3226 1.1 christos addend -= 8; 3227 1.1 christos 3228 1.1 christos if (r_type == (unsigned int) R_PARISC_PCREL22F) 3229 1.1 christos max_branch_offset = (1 << (22-1)) << 2; 3230 1.1 christos else if (r_type == (unsigned int) R_PARISC_PCREL17F) 3231 1.1 christos max_branch_offset = (1 << (17-1)) << 2; 3232 1.1 christos else if (r_type == (unsigned int) R_PARISC_PCREL12F) 3233 1.1 christos max_branch_offset = (1 << (12-1)) << 2; 3234 1.1 christos 3235 1.1 christos /* Make sure we can reach the branch target. */ 3236 1.1 christos if (max_branch_offset != 0 3237 1.1 christos && value + addend + max_branch_offset >= 2*max_branch_offset) 3238 1.7 christos { 3239 1.7 christos _bfd_error_handler 3240 1.8 christos /* xgettext:c-format */ 3241 1.1 christos (_("%pB(%pA+%#" PRIx64 "): cannot reach %s"), 3242 1.1 christos input_bfd, 3243 1.8 christos input_section, 3244 1.1 christos (uint64_t) offset, 3245 1.1 christos eh ? eh->root.root.string : "unknown"); 3246 1.1 christos bfd_set_error (bfd_error_bad_value); 3247 1.1 christos return bfd_reloc_overflow; 3248 1.1 christos } 3249 1.1 christos 3250 1.1 christos /* Adjust for any field selectors. */ 3251 1.1 christos if (r_type == R_PARISC_PCREL17R) 3252 1.1 christos value = hppa_field_adjust (value, addend, e_rsel); 3253 1.1 christos else 3254 1.1 christos value = hppa_field_adjust (value, addend, e_fsel); 3255 1.1 christos 3256 1.1 christos /* All branches are implicitly shifted by 2 places. */ 3257 1.1 christos value >>= 2; 3258 1.1 christos 3259 1.1 christos /* Apply the relocation to the given instruction. */ 3260 1.1 christos insn = elf_hppa_relocate_insn (insn, (int) value, r_type); 3261 1.1 christos break; 3262 1.1 christos } 3263 1.1 christos 3264 1.1 christos /* Indirect references to data through the DLT. */ 3265 1.1 christos case R_PARISC_DLTIND14R: 3266 1.1 christos case R_PARISC_DLTIND14F: 3267 1.1 christos case R_PARISC_DLTIND14DR: 3268 1.1 christos case R_PARISC_DLTIND14WR: 3269 1.1 christos case R_PARISC_DLTIND21L: 3270 1.1 christos case R_PARISC_LTOFF_FPTR14R: 3271 1.1 christos case R_PARISC_LTOFF_FPTR14DR: 3272 1.1 christos case R_PARISC_LTOFF_FPTR14WR: 3273 1.1 christos case R_PARISC_LTOFF_FPTR21L: 3274 1.1 christos case R_PARISC_LTOFF_FPTR16F: 3275 1.1 christos case R_PARISC_LTOFF_FPTR16WF: 3276 1.1 christos case R_PARISC_LTOFF_FPTR16DF: 3277 1.1 christos case R_PARISC_LTOFF_TP21L: 3278 1.1 christos case R_PARISC_LTOFF_TP14R: 3279 1.1 christos case R_PARISC_LTOFF_TP14F: 3280 1.1 christos case R_PARISC_LTOFF_TP14WR: 3281 1.1 christos case R_PARISC_LTOFF_TP14DR: 3282 1.1 christos case R_PARISC_LTOFF_TP16F: 3283 1.1 christos case R_PARISC_LTOFF_TP16WF: 3284 1.1 christos case R_PARISC_LTOFF_TP16DF: 3285 1.1 christos case R_PARISC_LTOFF16F: 3286 1.1 christos case R_PARISC_LTOFF16WF: 3287 1.1 christos case R_PARISC_LTOFF16DF: 3288 1.1 christos { 3289 1.1 christos bfd_vma off; 3290 1.1 christos 3291 1.1 christos /* If this relocation was against a local symbol, then we still 3292 1.1 christos have not set up the DLT entry (it's not convenient to do so 3293 1.1 christos in the "finalize_dlt" routine because it is difficult to get 3294 1.1 christos to the local symbol's value). 3295 1.1 christos 3296 1.1 christos So, if this is a local symbol (h == NULL), then we need to 3297 1.1 christos fill in its DLT entry. 3298 1.1 christos 3299 1.1 christos Similarly we may still need to set up an entry in .opd for 3300 1.1 christos a local function which had its address taken. */ 3301 1.1 christos if (hh == NULL) 3302 1.1 christos { 3303 1.1 christos bfd_vma *local_opd_offsets, *local_dlt_offsets; 3304 1.8 christos 3305 1.8 christos if (local_offsets == NULL) 3306 1.1 christos abort (); 3307 1.1 christos 3308 1.1 christos /* Now do .opd creation if needed. */ 3309 1.1 christos if (r_type == R_PARISC_LTOFF_FPTR14R 3310 1.1 christos || r_type == R_PARISC_LTOFF_FPTR14DR 3311 1.1 christos || r_type == R_PARISC_LTOFF_FPTR14WR 3312 1.1 christos || r_type == R_PARISC_LTOFF_FPTR21L 3313 1.1 christos || r_type == R_PARISC_LTOFF_FPTR16F 3314 1.1 christos || r_type == R_PARISC_LTOFF_FPTR16WF 3315 1.1 christos || r_type == R_PARISC_LTOFF_FPTR16DF) 3316 1.1 christos { 3317 1.1 christos local_opd_offsets = local_offsets + 2 * symtab_hdr->sh_info; 3318 1.1 christos off = local_opd_offsets[r_symndx]; 3319 1.1 christos 3320 1.1 christos /* The last bit records whether we've already initialised 3321 1.1 christos this local .opd entry. */ 3322 1.1 christos if ((off & 1) != 0) 3323 1.1 christos { 3324 1.1 christos BFD_ASSERT (off != (bfd_vma) -1); 3325 1.1 christos off &= ~1; 3326 1.1 christos } 3327 1.1 christos else 3328 1.1 christos { 3329 1.1 christos local_opd_offsets[r_symndx] |= 1; 3330 1.1 christos 3331 1.1 christos /* The first two words of an .opd entry are zero. */ 3332 1.1 christos memset (hppa_info->opd_sec->contents + off, 0, 16); 3333 1.1 christos 3334 1.1 christos /* The next word is the address of the function. */ 3335 1.1 christos bfd_put_64 (hppa_info->opd_sec->owner, value + addend, 3336 1.1 christos (hppa_info->opd_sec->contents + off + 16)); 3337 1.1 christos 3338 1.9 christos /* The last word is our local __gp value. */ 3339 1.1 christos value = _bfd_get_gp_value (info->output_bfd); 3340 1.1 christos bfd_put_64 (hppa_info->opd_sec->owner, value, 3341 1.1 christos (hppa_info->opd_sec->contents + off + 24)); 3342 1.1 christos } 3343 1.1 christos 3344 1.1 christos /* The DLT value is the address of the .opd entry. */ 3345 1.1 christos value = (off 3346 1.1 christos + hppa_info->opd_sec->output_offset 3347 1.1 christos + hppa_info->opd_sec->output_section->vma); 3348 1.1 christos addend = 0; 3349 1.1 christos } 3350 1.1 christos 3351 1.1 christos local_dlt_offsets = local_offsets; 3352 1.1 christos off = local_dlt_offsets[r_symndx]; 3353 1.1 christos 3354 1.1 christos if ((off & 1) != 0) 3355 1.1 christos { 3356 1.1 christos BFD_ASSERT (off != (bfd_vma) -1); 3357 1.1 christos off &= ~1; 3358 1.1 christos } 3359 1.1 christos else 3360 1.1 christos { 3361 1.1 christos local_dlt_offsets[r_symndx] |= 1; 3362 1.1 christos bfd_put_64 (hppa_info->dlt_sec->owner, 3363 1.1 christos value + addend, 3364 1.1 christos hppa_info->dlt_sec->contents + off); 3365 1.1 christos } 3366 1.1 christos } 3367 1.1 christos else 3368 1.1 christos off = hh->dlt_offset; 3369 1.1 christos 3370 1.1 christos /* We want the value of the DLT offset for this symbol, not 3371 1.1 christos the symbol's actual address. Note that __gp may not point 3372 1.1 christos to the start of the DLT, so we have to compute the absolute 3373 1.1 christos address, then subtract out the value of __gp. */ 3374 1.1 christos value = (off 3375 1.1 christos + hppa_info->dlt_sec->output_offset 3376 1.1 christos + hppa_info->dlt_sec->output_section->vma); 3377 1.1 christos value -= _bfd_get_gp_value (output_bfd); 3378 1.1 christos 3379 1.1 christos /* All DLTIND relocations are basically the same at this point, 3380 1.1 christos except that we need different field selectors for the 21bit 3381 1.1 christos version vs the 14bit versions. */ 3382 1.1 christos if (r_type == R_PARISC_DLTIND21L 3383 1.1 christos || r_type == R_PARISC_LTOFF_FPTR21L 3384 1.1 christos || r_type == R_PARISC_LTOFF_TP21L) 3385 1.1 christos value = hppa_field_adjust (value, 0, e_lsel); 3386 1.1 christos else if (r_type == R_PARISC_DLTIND14F 3387 1.1 christos || r_type == R_PARISC_LTOFF_FPTR16F 3388 1.1 christos || r_type == R_PARISC_LTOFF_FPTR16WF 3389 1.1 christos || r_type == R_PARISC_LTOFF_FPTR16DF 3390 1.1 christos || r_type == R_PARISC_LTOFF16F 3391 1.1 christos || r_type == R_PARISC_LTOFF16DF 3392 1.1 christos || r_type == R_PARISC_LTOFF16WF 3393 1.1 christos || r_type == R_PARISC_LTOFF_TP16F 3394 1.1 christos || r_type == R_PARISC_LTOFF_TP16WF 3395 1.1 christos || r_type == R_PARISC_LTOFF_TP16DF) 3396 1.1 christos value = hppa_field_adjust (value, 0, e_fsel); 3397 1.1 christos else 3398 1.1 christos value = hppa_field_adjust (value, 0, e_rsel); 3399 1.1 christos 3400 1.1 christos insn = elf_hppa_relocate_insn (insn, (int) value, r_type); 3401 1.1 christos break; 3402 1.1 christos } 3403 1.1 christos 3404 1.1 christos case R_PARISC_DLTREL14R: 3405 1.1 christos case R_PARISC_DLTREL14F: 3406 1.1 christos case R_PARISC_DLTREL14DR: 3407 1.1 christos case R_PARISC_DLTREL14WR: 3408 1.1 christos case R_PARISC_DLTREL21L: 3409 1.1 christos case R_PARISC_DPREL21L: 3410 1.1 christos case R_PARISC_DPREL14WR: 3411 1.1 christos case R_PARISC_DPREL14DR: 3412 1.1 christos case R_PARISC_DPREL14R: 3413 1.1 christos case R_PARISC_DPREL14F: 3414 1.1 christos case R_PARISC_GPREL16F: 3415 1.1 christos case R_PARISC_GPREL16WF: 3416 1.1 christos case R_PARISC_GPREL16DF: 3417 1.1 christos { 3418 1.1 christos /* Subtract out the global pointer value to make value a DLT 3419 1.1 christos relative address. */ 3420 1.1 christos value -= _bfd_get_gp_value (output_bfd); 3421 1.1 christos 3422 1.1 christos /* All DLTREL relocations are basically the same at this point, 3423 1.1 christos except that we need different field selectors for the 21bit 3424 1.1 christos version vs the 14bit versions. */ 3425 1.1 christos if (r_type == R_PARISC_DLTREL21L 3426 1.1 christos || r_type == R_PARISC_DPREL21L) 3427 1.1 christos value = hppa_field_adjust (value, addend, e_lrsel); 3428 1.1 christos else if (r_type == R_PARISC_DLTREL14F 3429 1.1 christos || r_type == R_PARISC_DPREL14F 3430 1.1 christos || r_type == R_PARISC_GPREL16F 3431 1.1 christos || r_type == R_PARISC_GPREL16WF 3432 1.1 christos || r_type == R_PARISC_GPREL16DF) 3433 1.1 christos value = hppa_field_adjust (value, addend, e_fsel); 3434 1.1 christos else 3435 1.1 christos value = hppa_field_adjust (value, addend, e_rrsel); 3436 1.1 christos 3437 1.1 christos insn = elf_hppa_relocate_insn (insn, (int) value, r_type); 3438 1.1 christos break; 3439 1.1 christos } 3440 1.1 christos 3441 1.1 christos case R_PARISC_DIR21L: 3442 1.1 christos case R_PARISC_DIR17R: 3443 1.1 christos case R_PARISC_DIR17F: 3444 1.1 christos case R_PARISC_DIR14R: 3445 1.1 christos case R_PARISC_DIR14F: 3446 1.1 christos case R_PARISC_DIR14WR: 3447 1.1 christos case R_PARISC_DIR14DR: 3448 1.1 christos case R_PARISC_DIR16F: 3449 1.1 christos case R_PARISC_DIR16WF: 3450 1.1 christos case R_PARISC_DIR16DF: 3451 1.1 christos { 3452 1.1 christos /* All DIR relocations are basically the same at this point, 3453 1.1 christos except that branch offsets need to be divided by four, and 3454 1.1 christos we need different field selectors. Note that we don't 3455 1.1 christos redirect absolute calls to local stubs. */ 3456 1.1 christos 3457 1.1 christos if (r_type == R_PARISC_DIR21L) 3458 1.1 christos value = hppa_field_adjust (value, addend, e_lrsel); 3459 1.1 christos else if (r_type == R_PARISC_DIR17F 3460 1.1 christos || r_type == R_PARISC_DIR16F 3461 1.1 christos || r_type == R_PARISC_DIR16WF 3462 1.1 christos || r_type == R_PARISC_DIR16DF 3463 1.1 christos || r_type == R_PARISC_DIR14F) 3464 1.1 christos value = hppa_field_adjust (value, addend, e_fsel); 3465 1.1 christos else 3466 1.1 christos value = hppa_field_adjust (value, addend, e_rrsel); 3467 1.1 christos 3468 1.1 christos if (r_type == R_PARISC_DIR17R || r_type == R_PARISC_DIR17F) 3469 1.1 christos /* All branches are implicitly shifted by 2 places. */ 3470 1.1 christos value >>= 2; 3471 1.1 christos 3472 1.1 christos insn = elf_hppa_relocate_insn (insn, (int) value, r_type); 3473 1.1 christos break; 3474 1.1 christos } 3475 1.1 christos 3476 1.1 christos case R_PARISC_PLTOFF21L: 3477 1.1 christos case R_PARISC_PLTOFF14R: 3478 1.1 christos case R_PARISC_PLTOFF14F: 3479 1.1 christos case R_PARISC_PLTOFF14WR: 3480 1.1 christos case R_PARISC_PLTOFF14DR: 3481 1.1 christos case R_PARISC_PLTOFF16F: 3482 1.1 christos case R_PARISC_PLTOFF16WF: 3483 1.1 christos case R_PARISC_PLTOFF16DF: 3484 1.1 christos { 3485 1.1 christos /* We want the value of the PLT offset for this symbol, not 3486 1.1 christos the symbol's actual address. Note that __gp may not point 3487 1.1 christos to the start of the DLT, so we have to compute the absolute 3488 1.1 christos address, then subtract out the value of __gp. */ 3489 1.9 christos value = (hh->plt_offset 3490 1.9 christos + hppa_info->root.splt->output_offset 3491 1.1 christos + hppa_info->root.splt->output_section->vma); 3492 1.1 christos value -= _bfd_get_gp_value (output_bfd); 3493 1.1 christos 3494 1.1 christos /* All PLTOFF relocations are basically the same at this point, 3495 1.1 christos except that we need different field selectors for the 21bit 3496 1.1 christos version vs the 14bit versions. */ 3497 1.1 christos if (r_type == R_PARISC_PLTOFF21L) 3498 1.1 christos value = hppa_field_adjust (value, addend, e_lrsel); 3499 1.1 christos else if (r_type == R_PARISC_PLTOFF14F 3500 1.1 christos || r_type == R_PARISC_PLTOFF16F 3501 1.1 christos || r_type == R_PARISC_PLTOFF16WF 3502 1.1 christos || r_type == R_PARISC_PLTOFF16DF) 3503 1.1 christos value = hppa_field_adjust (value, addend, e_fsel); 3504 1.1 christos else 3505 1.1 christos value = hppa_field_adjust (value, addend, e_rrsel); 3506 1.1 christos 3507 1.1 christos insn = elf_hppa_relocate_insn (insn, (int) value, r_type); 3508 1.1 christos break; 3509 1.1 christos } 3510 1.1 christos 3511 1.1 christos case R_PARISC_LTOFF_FPTR32: 3512 1.8 christos { 3513 1.8 christos /* FIXME: There used to be code here to create the FPTR itself if 3514 1.8 christos the relocation was against a local symbol. But the code could 3515 1.8 christos never have worked. If the assert below is ever triggered then 3516 1.8 christos the code will need to be reinstated and fixed so that it does 3517 1.8 christos what is needed. */ 3518 1.1 christos BFD_ASSERT (hh != NULL); 3519 1.1 christos 3520 1.1 christos /* We want the value of the DLT offset for this symbol, not 3521 1.1 christos the symbol's actual address. Note that __gp may not point 3522 1.1 christos to the start of the DLT, so we have to compute the absolute 3523 1.1 christos address, then subtract out the value of __gp. */ 3524 1.1 christos value = (hh->dlt_offset 3525 1.1 christos + hppa_info->dlt_sec->output_offset 3526 1.1 christos + hppa_info->dlt_sec->output_section->vma); 3527 1.1 christos value -= _bfd_get_gp_value (output_bfd); 3528 1.1 christos bfd_put_32 (input_bfd, value, hit_data); 3529 1.1 christos return bfd_reloc_ok; 3530 1.1 christos } 3531 1.1 christos 3532 1.1 christos case R_PARISC_LTOFF_FPTR64: 3533 1.1 christos case R_PARISC_LTOFF_TP64: 3534 1.1 christos { 3535 1.1 christos /* We may still need to create the FPTR itself if it was for 3536 1.1 christos a local symbol. */ 3537 1.1 christos if (eh == NULL && r_type == R_PARISC_LTOFF_FPTR64) 3538 1.1 christos { 3539 1.1 christos /* The first two words of an .opd entry are zero. */ 3540 1.1 christos memset (hppa_info->opd_sec->contents + hh->opd_offset, 0, 16); 3541 1.1 christos 3542 1.1 christos /* The next word is the address of the function. */ 3543 1.1 christos bfd_put_64 (hppa_info->opd_sec->owner, value + addend, 3544 1.1 christos (hppa_info->opd_sec->contents 3545 1.1 christos + hh->opd_offset + 16)); 3546 1.1 christos 3547 1.9 christos /* The last word is our local __gp value. */ 3548 1.1 christos value = _bfd_get_gp_value (info->output_bfd); 3549 1.1 christos bfd_put_64 (hppa_info->opd_sec->owner, value, 3550 1.1 christos hppa_info->opd_sec->contents + hh->opd_offset + 24); 3551 1.1 christos 3552 1.1 christos /* The DLT value is the address of the .opd entry. */ 3553 1.1 christos value = (hh->opd_offset 3554 1.1 christos + hppa_info->opd_sec->output_offset 3555 1.1 christos + hppa_info->opd_sec->output_section->vma); 3556 1.1 christos 3557 1.1 christos bfd_put_64 (hppa_info->dlt_sec->owner, 3558 1.1 christos value, 3559 1.1 christos hppa_info->dlt_sec->contents + hh->dlt_offset); 3560 1.1 christos } 3561 1.1 christos 3562 1.1 christos /* We want the value of the DLT offset for this symbol, not 3563 1.1 christos the symbol's actual address. Note that __gp may not point 3564 1.1 christos to the start of the DLT, so we have to compute the absolute 3565 1.1 christos address, then subtract out the value of __gp. */ 3566 1.1 christos value = (hh->dlt_offset 3567 1.1 christos + hppa_info->dlt_sec->output_offset 3568 1.1 christos + hppa_info->dlt_sec->output_section->vma); 3569 1.1 christos value -= _bfd_get_gp_value (output_bfd); 3570 1.1 christos bfd_put_64 (input_bfd, value, hit_data); 3571 1.1 christos return bfd_reloc_ok; 3572 1.1 christos } 3573 1.1 christos 3574 1.1 christos case R_PARISC_DIR32: 3575 1.1 christos bfd_put_32 (input_bfd, value + addend, hit_data); 3576 1.1 christos return bfd_reloc_ok; 3577 1.1 christos 3578 1.1 christos case R_PARISC_DIR64: 3579 1.1 christos bfd_put_64 (input_bfd, value + addend, hit_data); 3580 1.1 christos return bfd_reloc_ok; 3581 1.1 christos 3582 1.1 christos case R_PARISC_GPREL64: 3583 1.1 christos /* Subtract out the global pointer value to make value a DLT 3584 1.1 christos relative address. */ 3585 1.1 christos value -= _bfd_get_gp_value (output_bfd); 3586 1.1 christos 3587 1.1 christos bfd_put_64 (input_bfd, value + addend, hit_data); 3588 1.1 christos return bfd_reloc_ok; 3589 1.1 christos 3590 1.1 christos case R_PARISC_LTOFF64: 3591 1.1 christos /* We want the value of the DLT offset for this symbol, not 3592 1.1 christos the symbol's actual address. Note that __gp may not point 3593 1.1 christos to the start of the DLT, so we have to compute the absolute 3594 1.1 christos address, then subtract out the value of __gp. */ 3595 1.1 christos value = (hh->dlt_offset 3596 1.1 christos + hppa_info->dlt_sec->output_offset 3597 1.1 christos + hppa_info->dlt_sec->output_section->vma); 3598 1.1 christos value -= _bfd_get_gp_value (output_bfd); 3599 1.1 christos 3600 1.1 christos bfd_put_64 (input_bfd, value + addend, hit_data); 3601 1.1 christos return bfd_reloc_ok; 3602 1.1 christos 3603 1.1 christos case R_PARISC_PCREL32: 3604 1.1 christos { 3605 1.1 christos /* If this is a call to a function defined in another dynamic 3606 1.1 christos library, then redirect the call to the local stub for this 3607 1.1 christos function. */ 3608 1.1 christos if (sym_sec == NULL || sym_sec->output_section == NULL) 3609 1.1 christos value = (hh->stub_offset + hppa_info->stub_sec->output_offset 3610 1.1 christos + hppa_info->stub_sec->output_section->vma); 3611 1.1 christos 3612 1.1 christos /* Turn VALUE into a proper PC relative address. */ 3613 1.1 christos value -= (offset + input_section->output_offset 3614 1.1 christos + input_section->output_section->vma); 3615 1.1 christos 3616 1.1 christos value += addend; 3617 1.1 christos value -= 8; 3618 1.1 christos bfd_put_32 (input_bfd, value, hit_data); 3619 1.1 christos return bfd_reloc_ok; 3620 1.1 christos } 3621 1.1 christos 3622 1.1 christos case R_PARISC_PCREL64: 3623 1.1 christos { 3624 1.1 christos /* If this is a call to a function defined in another dynamic 3625 1.1 christos library, then redirect the call to the local stub for this 3626 1.1 christos function. */ 3627 1.1 christos if (sym_sec == NULL || sym_sec->output_section == NULL) 3628 1.1 christos value = (hh->stub_offset + hppa_info->stub_sec->output_offset 3629 1.1 christos + hppa_info->stub_sec->output_section->vma); 3630 1.1 christos 3631 1.1 christos /* Turn VALUE into a proper PC relative address. */ 3632 1.1 christos value -= (offset + input_section->output_offset 3633 1.1 christos + input_section->output_section->vma); 3634 1.1 christos 3635 1.1 christos value += addend; 3636 1.1 christos value -= 8; 3637 1.1 christos bfd_put_64 (input_bfd, value, hit_data); 3638 1.1 christos return bfd_reloc_ok; 3639 1.1 christos } 3640 1.1 christos 3641 1.1 christos case R_PARISC_FPTR64: 3642 1.1 christos { 3643 1.1 christos bfd_vma off; 3644 1.1 christos 3645 1.1 christos /* We may still need to create the FPTR itself if it was for 3646 1.1 christos a local symbol. */ 3647 1.1 christos if (hh == NULL) 3648 1.1 christos { 3649 1.1 christos bfd_vma *local_opd_offsets; 3650 1.8 christos 3651 1.8 christos if (local_offsets == NULL) 3652 1.1 christos abort (); 3653 1.1 christos 3654 1.1 christos local_opd_offsets = local_offsets + 2 * symtab_hdr->sh_info; 3655 1.1 christos off = local_opd_offsets[r_symndx]; 3656 1.1 christos 3657 1.1 christos /* The last bit records whether we've already initialised 3658 1.1 christos this local .opd entry. */ 3659 1.1 christos if ((off & 1) != 0) 3660 1.1 christos { 3661 1.8 christos BFD_ASSERT (off != (bfd_vma) -1); 3662 1.1 christos off &= ~1; 3663 1.1 christos } 3664 1.1 christos else 3665 1.1 christos { 3666 1.1 christos /* The first two words of an .opd entry are zero. */ 3667 1.1 christos memset (hppa_info->opd_sec->contents + off, 0, 16); 3668 1.1 christos 3669 1.1 christos /* The next word is the address of the function. */ 3670 1.1 christos bfd_put_64 (hppa_info->opd_sec->owner, value + addend, 3671 1.1 christos (hppa_info->opd_sec->contents + off + 16)); 3672 1.1 christos 3673 1.9 christos /* The last word is our local __gp value. */ 3674 1.1 christos value = _bfd_get_gp_value (info->output_bfd); 3675 1.1 christos bfd_put_64 (hppa_info->opd_sec->owner, value, 3676 1.1 christos hppa_info->opd_sec->contents + off + 24); 3677 1.1 christos } 3678 1.1 christos } 3679 1.1 christos else 3680 1.1 christos off = hh->opd_offset; 3681 1.1 christos 3682 1.1 christos if (hh == NULL || hh->want_opd) 3683 1.1 christos /* We want the value of the OPD offset for this symbol. */ 3684 1.1 christos value = (off 3685 1.1 christos + hppa_info->opd_sec->output_offset 3686 1.1 christos + hppa_info->opd_sec->output_section->vma); 3687 1.1 christos else 3688 1.1 christos /* We want the address of the symbol. */ 3689 1.1 christos value += addend; 3690 1.1 christos 3691 1.1 christos bfd_put_64 (input_bfd, value, hit_data); 3692 1.1 christos return bfd_reloc_ok; 3693 1.1 christos } 3694 1.1 christos 3695 1.10 christos case R_PARISC_SECREL32: 3696 1.1 christos if (sym_sec && sym_sec->output_section) 3697 1.1 christos value -= sym_sec->output_section->vma; 3698 1.1 christos bfd_put_32 (input_bfd, value + addend, hit_data); 3699 1.1 christos return bfd_reloc_ok; 3700 1.1 christos 3701 1.1 christos case R_PARISC_SEGREL32: 3702 1.1 christos case R_PARISC_SEGREL64: 3703 1.1 christos { 3704 1.1 christos /* If this is the first SEGREL relocation, then initialize 3705 1.1 christos the segment base values. */ 3706 1.1 christos if (hppa_info->text_segment_base == (bfd_vma) -1) 3707 1.1 christos bfd_map_over_sections (output_bfd, elf_hppa_record_segment_addrs, 3708 1.1 christos hppa_info); 3709 1.1 christos 3710 1.1 christos /* VALUE holds the absolute address. We want to include the 3711 1.1 christos addend, then turn it into a segment relative address. 3712 1.1 christos 3713 1.1 christos The segment is derived from SYM_SEC. We assume that there are 3714 1.1 christos only two segments of note in the resulting executable/shlib. 3715 1.1 christos A readonly segment (.text) and a readwrite segment (.data). */ 3716 1.1 christos value += addend; 3717 1.1 christos 3718 1.1 christos if (sym_sec->flags & SEC_CODE) 3719 1.1 christos value -= hppa_info->text_segment_base; 3720 1.1 christos else 3721 1.1 christos value -= hppa_info->data_segment_base; 3722 1.1 christos 3723 1.1 christos if (r_type == R_PARISC_SEGREL32) 3724 1.1 christos bfd_put_32 (input_bfd, value, hit_data); 3725 1.1 christos else 3726 1.1 christos bfd_put_64 (input_bfd, value, hit_data); 3727 1.1 christos return bfd_reloc_ok; 3728 1.1 christos } 3729 1.1 christos 3730 1.1 christos /* Something we don't know how to handle. */ 3731 1.1 christos default: 3732 1.1 christos return bfd_reloc_notsupported; 3733 1.1 christos } 3734 1.1 christos 3735 1.1 christos /* Update the instruction word. */ 3736 1.1 christos bfd_put_32 (input_bfd, (bfd_vma) insn, hit_data); 3737 1.1 christos return bfd_reloc_ok; 3738 1.1 christos } 3739 1.1 christos 3740 1.1 christos /* Relocate an HPPA ELF section. */ 3741 1.10 christos 3742 1.1 christos static int 3743 1.1 christos elf64_hppa_relocate_section (bfd *output_bfd, 3744 1.1 christos struct bfd_link_info *info, 3745 1.1 christos bfd *input_bfd, 3746 1.1 christos asection *input_section, 3747 1.1 christos bfd_byte *contents, 3748 1.1 christos Elf_Internal_Rela *relocs, 3749 1.1 christos Elf_Internal_Sym *local_syms, 3750 1.1 christos asection **local_sections) 3751 1.1 christos { 3752 1.1 christos Elf_Internal_Shdr *symtab_hdr; 3753 1.1 christos Elf_Internal_Rela *rel; 3754 1.1 christos Elf_Internal_Rela *relend; 3755 1.1 christos struct elf64_hppa_link_hash_table *hppa_info; 3756 1.1 christos 3757 1.1 christos hppa_info = hppa_link_hash_table (info); 3758 1.10 christos if (hppa_info == NULL) 3759 1.1 christos return false; 3760 1.1 christos 3761 1.1 christos symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; 3762 1.1 christos 3763 1.1 christos rel = relocs; 3764 1.1 christos relend = relocs + input_section->reloc_count; 3765 1.1 christos for (; rel < relend; rel++) 3766 1.1 christos { 3767 1.1 christos int r_type; 3768 1.1 christos reloc_howto_type *howto = elf_hppa_howto_table + ELF_R_TYPE (rel->r_info); 3769 1.1 christos unsigned long r_symndx; 3770 1.1 christos struct elf_link_hash_entry *eh; 3771 1.1 christos Elf_Internal_Sym *sym; 3772 1.1 christos asection *sym_sec; 3773 1.1 christos bfd_vma relocation; 3774 1.1 christos bfd_reloc_status_type r; 3775 1.1 christos 3776 1.1 christos r_type = ELF_R_TYPE (rel->r_info); 3777 1.1 christos if (r_type < 0 || r_type >= (int) R_PARISC_UNIMPLEMENTED) 3778 1.1 christos { 3779 1.10 christos bfd_set_error (bfd_error_bad_value); 3780 1.1 christos return false; 3781 1.1 christos } 3782 1.1 christos if (r_type == (unsigned int) R_PARISC_GNU_VTENTRY 3783 1.1 christos || r_type == (unsigned int) R_PARISC_GNU_VTINHERIT) 3784 1.1 christos continue; 3785 1.1 christos 3786 1.1 christos /* This is a final link. */ 3787 1.1 christos r_symndx = ELF_R_SYM (rel->r_info); 3788 1.1 christos eh = NULL; 3789 1.1 christos sym = NULL; 3790 1.1 christos sym_sec = NULL; 3791 1.1 christos if (r_symndx < symtab_hdr->sh_info) 3792 1.1 christos { 3793 1.1 christos /* This is a local symbol, hh defaults to NULL. */ 3794 1.1 christos sym = local_syms + r_symndx; 3795 1.1 christos sym_sec = local_sections[r_symndx]; 3796 1.1 christos relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sym_sec, rel); 3797 1.1 christos } 3798 1.1 christos else 3799 1.1 christos { 3800 1.1 christos /* This is not a local symbol. */ 3801 1.1 christos struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd); 3802 1.1 christos 3803 1.1 christos /* It seems this can happen with erroneous or unsupported 3804 1.1 christos input (mixing a.out and elf in an archive, for example.) */ 3805 1.10 christos if (sym_hashes == NULL) 3806 1.1 christos return false; 3807 1.1 christos 3808 1.1 christos eh = sym_hashes[r_symndx - symtab_hdr->sh_info]; 3809 1.3 christos 3810 1.3 christos if (info->wrap_hash != NULL 3811 1.3 christos && (input_section->flags & SEC_DEBUGGING) != 0) 3812 1.3 christos eh = ((struct elf_link_hash_entry *) 3813 1.3 christos unwrap_hash_lookup (info, input_bfd, &eh->root)); 3814 1.1 christos 3815 1.1 christos while (eh->root.type == bfd_link_hash_indirect 3816 1.1 christos || eh->root.type == bfd_link_hash_warning) 3817 1.1 christos eh = (struct elf_link_hash_entry *) eh->root.u.i.link; 3818 1.1 christos 3819 1.1 christos relocation = 0; 3820 1.1 christos if (eh->root.type == bfd_link_hash_defined 3821 1.1 christos || eh->root.type == bfd_link_hash_defweak) 3822 1.1 christos { 3823 1.1 christos sym_sec = eh->root.u.def.section; 3824 1.1 christos if (sym_sec != NULL 3825 1.1 christos && sym_sec->output_section != NULL) 3826 1.1 christos relocation = (eh->root.u.def.value 3827 1.1 christos + sym_sec->output_section->vma 3828 1.1 christos + sym_sec->output_offset); 3829 1.1 christos } 3830 1.1 christos else if (eh->root.type == bfd_link_hash_undefweak) 3831 1.1 christos ; 3832 1.1 christos else if (info->unresolved_syms_in_objects == RM_IGNORE 3833 1.1 christos && ELF_ST_VISIBILITY (eh->other) == STV_DEFAULT) 3834 1.6 christos ; 3835 1.1 christos else if (!bfd_link_relocatable (info) 3836 1.1 christos && elf_hppa_is_dynamic_loader_symbol (eh->root.root.string)) 3837 1.6 christos continue; 3838 1.1 christos else if (!bfd_link_relocatable (info)) 3839 1.10 christos { 3840 1.9 christos bool err; 3841 1.9 christos 3842 1.9 christos err = (info->unresolved_syms_in_objects == RM_DIAGNOSE 3843 1.9 christos && !info->warn_unresolved_syms) 3844 1.9 christos || ELF_ST_VISIBILITY (eh->other) != STV_DEFAULT; 3845 1.9 christos 3846 1.9 christos info->callbacks->undefined_symbol 3847 1.9 christos (info, eh->root.root.string, input_bfd, 3848 1.1 christos input_section, rel->r_offset, err); 3849 1.1 christos } 3850 1.8 christos 3851 1.8 christos if (!bfd_link_relocatable (info) 3852 1.8 christos && relocation == 0 3853 1.8 christos && eh->root.type != bfd_link_hash_defined 3854 1.8 christos && eh->root.type != bfd_link_hash_defweak 3855 1.8 christos && eh->root.type != bfd_link_hash_undefweak) 3856 1.8 christos { 3857 1.8 christos if (info->unresolved_syms_in_objects == RM_IGNORE 3858 1.8 christos && ELF_ST_VISIBILITY (eh->other) == STV_DEFAULT 3859 1.9 christos && eh->type == STT_PARISC_MILLI) 3860 1.6 christos info->callbacks->undefined_symbol 3861 1.10 christos (info, eh_name (eh), input_bfd, 3862 1.8 christos input_section, rel->r_offset, false); 3863 1.1 christos } 3864 1.1 christos } 3865 1.1 christos 3866 1.1 christos if (sym_sec != NULL && discarded_section (sym_sec)) 3867 1.1 christos RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, 3868 1.1 christos rel, 1, relend, howto, 0, contents); 3869 1.6 christos 3870 1.1 christos if (bfd_link_relocatable (info)) 3871 1.1 christos continue; 3872 1.1 christos 3873 1.1 christos r = elf_hppa_final_link_relocate (rel, input_bfd, output_bfd, 3874 1.1 christos input_section, contents, 3875 1.1 christos relocation, info, sym_sec, 3876 1.1 christos eh); 3877 1.1 christos 3878 1.1 christos if (r != bfd_reloc_ok) 3879 1.1 christos { 3880 1.1 christos switch (r) 3881 1.1 christos { 3882 1.1 christos default: 3883 1.1 christos abort (); 3884 1.1 christos case bfd_reloc_overflow: 3885 1.1 christos { 3886 1.1 christos const char *sym_name; 3887 1.1 christos 3888 1.1 christos if (eh != NULL) 3889 1.1 christos sym_name = NULL; 3890 1.1 christos else 3891 1.1 christos { 3892 1.1 christos sym_name = bfd_elf_string_from_elf_section (input_bfd, 3893 1.1 christos symtab_hdr->sh_link, 3894 1.1 christos sym->st_name); 3895 1.10 christos if (sym_name == NULL) 3896 1.1 christos return false; 3897 1.9 christos if (*sym_name == '\0') 3898 1.1 christos sym_name = bfd_section_name (sym_sec); 3899 1.1 christos } 3900 1.6 christos 3901 1.6 christos (*info->callbacks->reloc_overflow) 3902 1.6 christos (info, (eh ? &eh->root : NULL), sym_name, howto->name, 3903 1.1 christos (bfd_vma) 0, input_bfd, input_section, rel->r_offset); 3904 1.1 christos } 3905 1.1 christos break; 3906 1.1 christos } 3907 1.1 christos } 3908 1.10 christos } 3909 1.1 christos return true; 3910 1.1 christos } 3911 1.1 christos 3912 1.1 christos static const struct bfd_elf_special_section elf64_hppa_special_sections[] = 3913 1.9 christos { 3914 1.8 christos { STRING_COMMA_LEN (".tbss"), 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_HP_TLS }, 3915 1.8 christos { STRING_COMMA_LEN (".fini"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, 3916 1.8 christos { STRING_COMMA_LEN (".init"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, 3917 1.8 christos { STRING_COMMA_LEN (".plt"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT }, 3918 1.1 christos { STRING_COMMA_LEN (".dlt"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT }, 3919 1.8 christos { STRING_COMMA_LEN (".sdata"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT }, 3920 1.8 christos { STRING_COMMA_LEN (".sbss"), 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT }, 3921 1.1 christos { NULL, 0, 0, 0, 0 } 3922 1.1 christos }; 3923 1.1 christos 3924 1.1 christos /* The hash bucket size is the standard one, namely 4. */ 3925 1.1 christos 3926 1.1 christos const struct elf_size_info hppa64_elf_size_info = 3927 1.1 christos { 3928 1.1 christos sizeof (Elf64_External_Ehdr), 3929 1.1 christos sizeof (Elf64_External_Phdr), 3930 1.1 christos sizeof (Elf64_External_Shdr), 3931 1.1 christos sizeof (Elf64_External_Rel), 3932 1.1 christos sizeof (Elf64_External_Rela), 3933 1.1 christos sizeof (Elf64_External_Sym), 3934 1.1 christos sizeof (Elf64_External_Dyn), 3935 1.1 christos sizeof (Elf_External_Note), 3936 1.1 christos 4, 3937 1.1 christos 1, 3938 1.1 christos 64, 3, 3939 1.1 christos ELFCLASS64, EV_CURRENT, 3940 1.1 christos bfd_elf64_write_out_phdrs, 3941 1.1 christos bfd_elf64_write_shdrs_and_ehdr, 3942 1.1 christos bfd_elf64_checksum_contents, 3943 1.1 christos bfd_elf64_write_relocs, 3944 1.1 christos bfd_elf64_swap_symbol_in, 3945 1.1 christos bfd_elf64_swap_symbol_out, 3946 1.1 christos bfd_elf64_slurp_reloc_table, 3947 1.1 christos bfd_elf64_slurp_symbol_table, 3948 1.1 christos bfd_elf64_swap_dyn_in, 3949 1.1 christos bfd_elf64_swap_dyn_out, 3950 1.1 christos bfd_elf64_swap_reloc_in, 3951 1.1 christos bfd_elf64_swap_reloc_out, 3952 1.1 christos bfd_elf64_swap_reloca_in, 3953 1.1 christos bfd_elf64_swap_reloca_out 3954 1.1 christos }; 3955 1.3 christos 3956 1.1 christos #define TARGET_BIG_SYM hppa_elf64_vec 3957 1.1 christos #define TARGET_BIG_NAME "elf64-hppa" 3958 1.1 christos #define ELF_ARCH bfd_arch_hppa 3959 1.1 christos #define ELF_TARGET_ID HPPA64_ELF_DATA 3960 1.1 christos #define ELF_MACHINE_CODE EM_PARISC 3961 1.1 christos /* This is not strictly correct. The maximum page size for PA2.0 is 3962 1.1 christos 64M. But everything still uses 4k. */ 3963 1.1 christos #define ELF_MAXPAGESIZE 0x1000 3964 1.1 christos #define ELF_OSABI ELFOSABI_HPUX 3965 1.1 christos 3966 1.1 christos #define bfd_elf64_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup 3967 1.1 christos #define bfd_elf64_bfd_reloc_name_lookup elf_hppa_reloc_name_lookup 3968 1.1 christos #define bfd_elf64_bfd_is_local_label_name elf_hppa_is_local_label_name 3969 1.1 christos #define elf_info_to_howto elf_hppa_info_to_howto 3970 1.1 christos #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel 3971 1.1 christos 3972 1.1 christos #define elf_backend_section_from_shdr elf64_hppa_section_from_shdr 3973 1.1 christos #define elf_backend_object_p elf64_hppa_object_p 3974 1.1 christos #define elf_backend_final_write_processing \ 3975 1.1 christos elf_hppa_final_write_processing 3976 1.1 christos #define elf_backend_fake_sections elf_hppa_fake_sections 3977 1.1 christos #define elf_backend_add_symbol_hook elf_hppa_add_symbol_hook 3978 1.1 christos 3979 1.1 christos #define elf_backend_relocate_section elf_hppa_relocate_section 3980 1.1 christos 3981 1.1 christos #define bfd_elf64_bfd_final_link elf_hppa_final_link 3982 1.1 christos 3983 1.1 christos #define elf_backend_create_dynamic_sections \ 3984 1.9 christos elf64_hppa_create_dynamic_sections 3985 1.1 christos #define elf_backend_init_file_header elf64_hppa_init_file_header 3986 1.8 christos 3987 1.8 christos #define elf_backend_omit_section_dynsym _bfd_elf_omit_section_dynsym_all 3988 1.1 christos 3989 1.1 christos #define elf_backend_adjust_dynamic_symbol \ 3990 1.1 christos elf64_hppa_adjust_dynamic_symbol 3991 1.11 christos 3992 1.1 christos #define elf_backend_late_size_sections elf64_hppa_late_size_sections 3993 1.1 christos 3994 1.1 christos #define elf_backend_finish_dynamic_symbol \ 3995 1.1 christos elf64_hppa_finish_dynamic_symbol 3996 1.1 christos #define elf_backend_finish_dynamic_sections \ 3997 1.1 christos elf64_hppa_finish_dynamic_sections 3998 1.1 christos #define elf_backend_grok_prstatus elf64_hppa_grok_prstatus 3999 1.1 christos #define elf_backend_grok_psinfo elf64_hppa_grok_psinfo 4000 1.1 christos 4001 1.1 christos /* Stuff for the BFD linker: */ 4002 1.1 christos #define bfd_elf64_bfd_link_hash_table_create \ 4003 1.1 christos elf64_hppa_hash_table_create 4004 1.1 christos 4005 1.1 christos #define elf_backend_check_relocs \ 4006 1.1 christos elf64_hppa_check_relocs 4007 1.1 christos 4008 1.1 christos #define elf_backend_size_info \ 4009 1.1 christos hppa64_elf_size_info 4010 1.1 christos 4011 1.1 christos #define elf_backend_additional_program_headers \ 4012 1.1 christos elf64_hppa_additional_program_headers 4013 1.1 christos 4014 1.1 christos #define elf_backend_modify_segment_map \ 4015 1.1 christos elf64_hppa_modify_segment_map 4016 1.7 christos 4017 1.7 christos #define elf_backend_allow_non_load_phdr \ 4018 1.7 christos elf64_hppa_allow_non_load_phdr 4019 1.1 christos 4020 1.1 christos #define elf_backend_link_output_symbol_hook \ 4021 1.1 christos elf64_hppa_link_output_symbol_hook 4022 1.1 christos 4023 1.1 christos #define elf_backend_want_got_plt 0 4024 1.1 christos #define elf_backend_plt_readonly 0 4025 1.1 christos #define elf_backend_want_plt_sym 0 4026 1.10 christos #define elf_backend_got_header_size 0 4027 1.1 christos #define elf_backend_type_change_ok true 4028 1.1 christos #define elf_backend_get_symbol_type elf64_hppa_elf_get_symbol_type 4029 1.1 christos #define elf_backend_reloc_type_class elf64_hppa_reloc_type_class 4030 1.1 christos #define elf_backend_rela_normal 1 4031 1.1 christos #define elf_backend_special_sections elf64_hppa_special_sections 4032 1.1 christos #define elf_backend_action_discarded elf_hppa_action_discarded 4033 1.1 christos #define elf_backend_section_from_phdr elf64_hppa_section_from_phdr 4034 1.1 christos 4035 1.1 christos #define elf64_bed elf64_hppa_hpux_bed 4036 1.1 christos 4037 1.1 christos #include "elf64-target.h" 4038 1.1 christos 4039 1.3 christos #undef TARGET_BIG_SYM 4040 1.1 christos #define TARGET_BIG_SYM hppa_elf64_linux_vec 4041 1.1 christos #undef TARGET_BIG_NAME 4042 1.1 christos #define TARGET_BIG_NAME "elf64-hppa-linux" 4043 1.1 christos #undef ELF_OSABI 4044 1.1 christos #define ELF_OSABI ELFOSABI_GNU 4045 1.1 christos #undef elf64_bed 4046 1.9 christos #define elf64_bed elf64_hppa_linux_bed 4047 1.9 christos #undef elf_backend_special_sections 4048 1.1 christos #define elf_backend_special_sections (elf64_hppa_special_sections + 1) 4049 1.1 christos 4050 #include "elf64-target.h" 4051