| 1 | /* Support for HPPA 64-bit ELF | 
|---|
| 2 | Copyright 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. | 
|---|
| 3 |  | 
|---|
| 4 | This file is part of BFD, the Binary File Descriptor library. | 
|---|
| 5 |  | 
|---|
| 6 | This program is free software; you can redistribute it and/or modify | 
|---|
| 7 | it under the terms of the GNU General Public License as published by | 
|---|
| 8 | the Free Software Foundation; either version 2 of the License, or | 
|---|
| 9 | (at your option) any later version. | 
|---|
| 10 |  | 
|---|
| 11 | This program is distributed in the hope that it will be useful, | 
|---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 14 | GNU General Public License for more details. | 
|---|
| 15 |  | 
|---|
| 16 | You should have received a copy of the GNU General Public License | 
|---|
| 17 | along with this program; if not, write to the Free Software | 
|---|
| 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */ | 
|---|
| 19 |  | 
|---|
| 20 | #include "alloca-conf.h" | 
|---|
| 21 | #include "bfd.h" | 
|---|
| 22 | #include "sysdep.h" | 
|---|
| 23 | #include "libbfd.h" | 
|---|
| 24 | #include "elf-bfd.h" | 
|---|
| 25 | #include "elf/hppa.h" | 
|---|
| 26 | #include "libhppa.h" | 
|---|
| 27 | #include "elf64-hppa.h" | 
|---|
| 28 | #define ARCH_SIZE              64 | 
|---|
| 29 |  | 
|---|
| 30 | #define PLT_ENTRY_SIZE 0x10 | 
|---|
| 31 | #define DLT_ENTRY_SIZE 0x8 | 
|---|
| 32 | #define OPD_ENTRY_SIZE 0x20 | 
|---|
| 33 |  | 
|---|
| 34 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/pa20_64/dld.sl" | 
|---|
| 35 |  | 
|---|
| 36 | /* The stub is supposed to load the target address and target's DP | 
|---|
| 37 | value out of the PLT, then do an external branch to the target | 
|---|
| 38 | address. | 
|---|
| 39 |  | 
|---|
| 40 | LDD PLTOFF(%r27),%r1 | 
|---|
| 41 | BVE (%r1) | 
|---|
| 42 | LDD PLTOFF+8(%r27),%r27 | 
|---|
| 43 |  | 
|---|
| 44 | Note that we must use the LDD with a 14 bit displacement, not the one | 
|---|
| 45 | with a 5 bit displacement.  */ | 
|---|
| 46 | static char plt_stub[] = {0x53, 0x61, 0x00, 0x00, 0xe8, 0x20, 0xd0, 0x00, | 
|---|
| 47 | 0x53, 0x7b, 0x00, 0x00 }; | 
|---|
| 48 |  | 
|---|
| 49 | struct elf64_hppa_dyn_hash_entry | 
|---|
| 50 | { | 
|---|
| 51 | struct bfd_hash_entry root; | 
|---|
| 52 |  | 
|---|
| 53 | /* Offsets for this symbol in various linker sections.  */ | 
|---|
| 54 | bfd_vma dlt_offset; | 
|---|
| 55 | bfd_vma plt_offset; | 
|---|
| 56 | bfd_vma opd_offset; | 
|---|
| 57 | bfd_vma stub_offset; | 
|---|
| 58 |  | 
|---|
| 59 | /* The symbol table entry, if any, that this was derived from.  */ | 
|---|
| 60 | struct elf_link_hash_entry *h; | 
|---|
| 61 |  | 
|---|
| 62 | /* The index of the (possibly local) symbol in the input bfd and its | 
|---|
| 63 | associated BFD.  Needed so that we can have relocs against local | 
|---|
| 64 | symbols in shared libraries.  */ | 
|---|
| 65 | long sym_indx; | 
|---|
| 66 | bfd *owner; | 
|---|
| 67 |  | 
|---|
| 68 | /* Dynamic symbols may need to have two different values.  One for | 
|---|
| 69 | the dynamic symbol table, one for the normal symbol table. | 
|---|
| 70 |  | 
|---|
| 71 | In such cases we store the symbol's real value and section | 
|---|
| 72 | index here so we can restore the real value before we write | 
|---|
| 73 | the normal symbol table.  */ | 
|---|
| 74 | bfd_vma st_value; | 
|---|
| 75 | int st_shndx; | 
|---|
| 76 |  | 
|---|
| 77 | /* Used to count non-got, non-plt relocations for delayed sizing | 
|---|
| 78 | of relocation sections.  */ | 
|---|
| 79 | struct elf64_hppa_dyn_reloc_entry | 
|---|
| 80 | { | 
|---|
| 81 | /* Next relocation in the chain.  */ | 
|---|
| 82 | struct elf64_hppa_dyn_reloc_entry *next; | 
|---|
| 83 |  | 
|---|
| 84 | /* The type of the relocation.  */ | 
|---|
| 85 | int type; | 
|---|
| 86 |  | 
|---|
| 87 | /* The input section of the relocation.  */ | 
|---|
| 88 | asection *sec; | 
|---|
| 89 |  | 
|---|
| 90 | /* The index of the section symbol for the input section of | 
|---|
| 91 | the relocation.  Only needed when building shared libraries.  */ | 
|---|
| 92 | int sec_symndx; | 
|---|
| 93 |  | 
|---|
| 94 | /* The offset within the input section of the relocation.  */ | 
|---|
| 95 | bfd_vma offset; | 
|---|
| 96 |  | 
|---|
| 97 | /* The addend for the relocation.  */ | 
|---|
| 98 | bfd_vma addend; | 
|---|
| 99 |  | 
|---|
| 100 | } *reloc_entries; | 
|---|
| 101 |  | 
|---|
| 102 | /* Nonzero if this symbol needs an entry in one of the linker | 
|---|
| 103 | sections.  */ | 
|---|
| 104 | unsigned want_dlt; | 
|---|
| 105 | unsigned want_plt; | 
|---|
| 106 | unsigned want_opd; | 
|---|
| 107 | unsigned want_stub; | 
|---|
| 108 | }; | 
|---|
| 109 |  | 
|---|
| 110 | struct elf64_hppa_dyn_hash_table | 
|---|
| 111 | { | 
|---|
| 112 | struct bfd_hash_table root; | 
|---|
| 113 | }; | 
|---|
| 114 |  | 
|---|
| 115 | struct elf64_hppa_link_hash_table | 
|---|
| 116 | { | 
|---|
| 117 | struct elf_link_hash_table root; | 
|---|
| 118 |  | 
|---|
| 119 | /* Shortcuts to get to the various linker defined sections.  */ | 
|---|
| 120 | asection *dlt_sec; | 
|---|
| 121 | asection *dlt_rel_sec; | 
|---|
| 122 | asection *plt_sec; | 
|---|
| 123 | asection *plt_rel_sec; | 
|---|
| 124 | asection *opd_sec; | 
|---|
| 125 | asection *opd_rel_sec; | 
|---|
| 126 | asection *other_rel_sec; | 
|---|
| 127 |  | 
|---|
| 128 | /* Offset of __gp within .plt section.  When the PLT gets large we want | 
|---|
| 129 | to slide __gp into the PLT section so that we can continue to use | 
|---|
| 130 | single DP relative instructions to load values out of the PLT.  */ | 
|---|
| 131 | bfd_vma gp_offset; | 
|---|
| 132 |  | 
|---|
| 133 | /* Note this is not strictly correct.  We should create a stub section for | 
|---|
| 134 | each input section with calls.  The stub section should be placed before | 
|---|
| 135 | the section with the call.  */ | 
|---|
| 136 | asection *stub_sec; | 
|---|
| 137 |  | 
|---|
| 138 | bfd_vma text_segment_base; | 
|---|
| 139 | bfd_vma data_segment_base; | 
|---|
| 140 |  | 
|---|
| 141 | struct elf64_hppa_dyn_hash_table dyn_hash_table; | 
|---|
| 142 |  | 
|---|
| 143 | /* We build tables to map from an input section back to its | 
|---|
| 144 | symbol index.  This is the BFD for which we currently have | 
|---|
| 145 | a map.  */ | 
|---|
| 146 | bfd *section_syms_bfd; | 
|---|
| 147 |  | 
|---|
| 148 | /* Array of symbol numbers for each input section attached to the | 
|---|
| 149 | current BFD.  */ | 
|---|
| 150 | int *section_syms; | 
|---|
| 151 | }; | 
|---|
| 152 |  | 
|---|
| 153 | #define elf64_hppa_hash_table(p) \ | 
|---|
| 154 | ((struct elf64_hppa_link_hash_table *) ((p)->hash)) | 
|---|
| 155 |  | 
|---|
| 156 | typedef struct bfd_hash_entry *(*new_hash_entry_func) | 
|---|
| 157 | PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); | 
|---|
| 158 |  | 
|---|
| 159 | static bfd_boolean elf64_hppa_dyn_hash_table_init | 
|---|
| 160 | PARAMS ((struct elf64_hppa_dyn_hash_table *ht, bfd *abfd, | 
|---|
| 161 | new_hash_entry_func new)); | 
|---|
| 162 | static struct bfd_hash_entry *elf64_hppa_new_dyn_hash_entry | 
|---|
| 163 | PARAMS ((struct bfd_hash_entry *entry, struct bfd_hash_table *table, | 
|---|
| 164 | const char *string)); | 
|---|
| 165 | static struct bfd_link_hash_table *elf64_hppa_hash_table_create | 
|---|
| 166 | PARAMS ((bfd *abfd)); | 
|---|
| 167 | static struct elf64_hppa_dyn_hash_entry *elf64_hppa_dyn_hash_lookup | 
|---|
| 168 | PARAMS ((struct elf64_hppa_dyn_hash_table *table, const char *string, | 
|---|
| 169 | bfd_boolean create, bfd_boolean copy)); | 
|---|
| 170 | static void elf64_hppa_dyn_hash_traverse | 
|---|
| 171 | PARAMS ((struct elf64_hppa_dyn_hash_table *table, | 
|---|
| 172 | bfd_boolean (*func) (struct elf64_hppa_dyn_hash_entry *, PTR), | 
|---|
| 173 | PTR info)); | 
|---|
| 174 |  | 
|---|
| 175 | static const char *get_dyn_name | 
|---|
| 176 | PARAMS ((asection *, struct elf_link_hash_entry *, | 
|---|
| 177 | const Elf_Internal_Rela *, char **, size_t *)); | 
|---|
| 178 |  | 
|---|
| 179 | /* This must follow the definitions of the various derived linker | 
|---|
| 180 | hash tables and shared functions.  */ | 
|---|
| 181 | #include "elf-hppa.h" | 
|---|
| 182 |  | 
|---|
| 183 | static bfd_boolean elf64_hppa_object_p | 
|---|
| 184 | PARAMS ((bfd *)); | 
|---|
| 185 |  | 
|---|
| 186 | static bfd_boolean elf64_hppa_section_from_shdr | 
|---|
| 187 | PARAMS ((bfd *, Elf_Internal_Shdr *, const char *)); | 
|---|
| 188 |  | 
|---|
| 189 | static void elf64_hppa_post_process_headers | 
|---|
| 190 | PARAMS ((bfd *, struct bfd_link_info *)); | 
|---|
| 191 |  | 
|---|
| 192 | static bfd_boolean elf64_hppa_create_dynamic_sections | 
|---|
| 193 | PARAMS ((bfd *, struct bfd_link_info *)); | 
|---|
| 194 |  | 
|---|
| 195 | static bfd_boolean elf64_hppa_adjust_dynamic_symbol | 
|---|
| 196 | PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *)); | 
|---|
| 197 |  | 
|---|
| 198 | static bfd_boolean elf64_hppa_mark_milli_and_exported_functions | 
|---|
| 199 | PARAMS ((struct elf_link_hash_entry *, PTR)); | 
|---|
| 200 |  | 
|---|
| 201 | static bfd_boolean elf64_hppa_size_dynamic_sections | 
|---|
| 202 | PARAMS ((bfd *, struct bfd_link_info *)); | 
|---|
| 203 |  | 
|---|
| 204 | static bfd_boolean elf64_hppa_link_output_symbol_hook | 
|---|
| 205 | PARAMS ((bfd *abfd, struct bfd_link_info *, const char *, | 
|---|
| 206 | Elf_Internal_Sym *, asection *input_sec)); | 
|---|
| 207 |  | 
|---|
| 208 | static bfd_boolean elf64_hppa_finish_dynamic_symbol | 
|---|
| 209 | PARAMS ((bfd *, struct bfd_link_info *, | 
|---|
| 210 | struct elf_link_hash_entry *, Elf_Internal_Sym *)); | 
|---|
| 211 |  | 
|---|
| 212 | static int elf64_hppa_additional_program_headers | 
|---|
| 213 | PARAMS ((bfd *)); | 
|---|
| 214 |  | 
|---|
| 215 | static bfd_boolean elf64_hppa_modify_segment_map | 
|---|
| 216 | PARAMS ((bfd *)); | 
|---|
| 217 |  | 
|---|
| 218 | static enum elf_reloc_type_class elf64_hppa_reloc_type_class | 
|---|
| 219 | PARAMS ((const Elf_Internal_Rela *)); | 
|---|
| 220 |  | 
|---|
| 221 | static bfd_boolean elf64_hppa_finish_dynamic_sections | 
|---|
| 222 | PARAMS ((bfd *, struct bfd_link_info *)); | 
|---|
| 223 |  | 
|---|
| 224 | static bfd_boolean elf64_hppa_check_relocs | 
|---|
| 225 | PARAMS ((bfd *, struct bfd_link_info *, | 
|---|
| 226 | asection *, const Elf_Internal_Rela *)); | 
|---|
| 227 |  | 
|---|
| 228 | static bfd_boolean elf64_hppa_dynamic_symbol_p | 
|---|
| 229 | PARAMS ((struct elf_link_hash_entry *, struct bfd_link_info *)); | 
|---|
| 230 |  | 
|---|
| 231 | static bfd_boolean elf64_hppa_mark_exported_functions | 
|---|
| 232 | PARAMS ((struct elf_link_hash_entry *, PTR)); | 
|---|
| 233 |  | 
|---|
| 234 | static bfd_boolean elf64_hppa_finalize_opd | 
|---|
| 235 | PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR)); | 
|---|
| 236 |  | 
|---|
| 237 | static bfd_boolean elf64_hppa_finalize_dlt | 
|---|
| 238 | PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR)); | 
|---|
| 239 |  | 
|---|
| 240 | static bfd_boolean allocate_global_data_dlt | 
|---|
| 241 | PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR)); | 
|---|
| 242 |  | 
|---|
| 243 | static bfd_boolean allocate_global_data_plt | 
|---|
| 244 | PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR)); | 
|---|
| 245 |  | 
|---|
| 246 | static bfd_boolean allocate_global_data_stub | 
|---|
| 247 | PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR)); | 
|---|
| 248 |  | 
|---|
| 249 | static bfd_boolean allocate_global_data_opd | 
|---|
| 250 | PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR)); | 
|---|
| 251 |  | 
|---|
| 252 | static bfd_boolean get_reloc_section | 
|---|
| 253 | PARAMS ((bfd *, struct elf64_hppa_link_hash_table *, asection *)); | 
|---|
| 254 |  | 
|---|
| 255 | static bfd_boolean count_dyn_reloc | 
|---|
| 256 | PARAMS ((bfd *, struct elf64_hppa_dyn_hash_entry *, | 
|---|
| 257 | int, asection *, int, bfd_vma, bfd_vma)); | 
|---|
| 258 |  | 
|---|
| 259 | static bfd_boolean allocate_dynrel_entries | 
|---|
| 260 | PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR)); | 
|---|
| 261 |  | 
|---|
| 262 | static bfd_boolean elf64_hppa_finalize_dynreloc | 
|---|
| 263 | PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR)); | 
|---|
| 264 |  | 
|---|
| 265 | static bfd_boolean get_opd | 
|---|
| 266 | PARAMS ((bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *)); | 
|---|
| 267 |  | 
|---|
| 268 | static bfd_boolean get_plt | 
|---|
| 269 | PARAMS ((bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *)); | 
|---|
| 270 |  | 
|---|
| 271 | static bfd_boolean get_dlt | 
|---|
| 272 | PARAMS ((bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *)); | 
|---|
| 273 |  | 
|---|
| 274 | static bfd_boolean get_stub | 
|---|
| 275 | PARAMS ((bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *)); | 
|---|
| 276 |  | 
|---|
| 277 | static int elf64_hppa_elf_get_symbol_type | 
|---|
| 278 | PARAMS ((Elf_Internal_Sym *, int)); | 
|---|
| 279 |  | 
|---|
| 280 | static bfd_boolean | 
|---|
| 281 | elf64_hppa_dyn_hash_table_init (ht, abfd, new) | 
|---|
| 282 | struct elf64_hppa_dyn_hash_table *ht; | 
|---|
| 283 | bfd *abfd ATTRIBUTE_UNUSED; | 
|---|
| 284 | new_hash_entry_func new; | 
|---|
| 285 | { | 
|---|
| 286 | memset (ht, 0, sizeof (*ht)); | 
|---|
| 287 | return bfd_hash_table_init (&ht->root, new); | 
|---|
| 288 | } | 
|---|
| 289 |  | 
|---|
| 290 | static struct bfd_hash_entry* | 
|---|
| 291 | elf64_hppa_new_dyn_hash_entry (entry, table, string) | 
|---|
| 292 | struct bfd_hash_entry *entry; | 
|---|
| 293 | struct bfd_hash_table *table; | 
|---|
| 294 | const char *string; | 
|---|
| 295 | { | 
|---|
| 296 | struct elf64_hppa_dyn_hash_entry *ret; | 
|---|
| 297 | ret = (struct elf64_hppa_dyn_hash_entry *) entry; | 
|---|
| 298 |  | 
|---|
| 299 | /* Allocate the structure if it has not already been allocated by a | 
|---|
| 300 | subclass.  */ | 
|---|
| 301 | if (!ret) | 
|---|
| 302 | ret = bfd_hash_allocate (table, sizeof (*ret)); | 
|---|
| 303 |  | 
|---|
| 304 | if (!ret) | 
|---|
| 305 | return 0; | 
|---|
| 306 |  | 
|---|
| 307 | /* Initialize our local data.  All zeros, and definitely easier | 
|---|
| 308 | than setting 8 bit fields.  */ | 
|---|
| 309 | memset (ret, 0, sizeof (*ret)); | 
|---|
| 310 |  | 
|---|
| 311 | /* Call the allocation method of the superclass.  */ | 
|---|
| 312 | ret = ((struct elf64_hppa_dyn_hash_entry *) | 
|---|
| 313 | bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string)); | 
|---|
| 314 |  | 
|---|
| 315 | return &ret->root; | 
|---|
| 316 | } | 
|---|
| 317 |  | 
|---|
| 318 | /* Create the derived linker hash table.  The PA64 ELF port uses this | 
|---|
| 319 | derived hash table to keep information specific to the PA ElF | 
|---|
| 320 | linker (without using static variables).  */ | 
|---|
| 321 |  | 
|---|
| 322 | static struct bfd_link_hash_table* | 
|---|
| 323 | elf64_hppa_hash_table_create (abfd) | 
|---|
| 324 | bfd *abfd; | 
|---|
| 325 | { | 
|---|
| 326 | struct elf64_hppa_link_hash_table *ret; | 
|---|
| 327 |  | 
|---|
| 328 | ret = bfd_zalloc (abfd, (bfd_size_type) sizeof (*ret)); | 
|---|
| 329 | if (!ret) | 
|---|
| 330 | return 0; | 
|---|
| 331 | if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, | 
|---|
| 332 | _bfd_elf_link_hash_newfunc)) | 
|---|
| 333 | { | 
|---|
| 334 | bfd_release (abfd, ret); | 
|---|
| 335 | return 0; | 
|---|
| 336 | } | 
|---|
| 337 |  | 
|---|
| 338 | if (!elf64_hppa_dyn_hash_table_init (&ret->dyn_hash_table, abfd, | 
|---|
| 339 | elf64_hppa_new_dyn_hash_entry)) | 
|---|
| 340 | return 0; | 
|---|
| 341 | return &ret->root.root; | 
|---|
| 342 | } | 
|---|
| 343 |  | 
|---|
| 344 | /* Look up an entry in a PA64 ELF linker hash table.  */ | 
|---|
| 345 |  | 
|---|
| 346 | static struct elf64_hppa_dyn_hash_entry * | 
|---|
| 347 | elf64_hppa_dyn_hash_lookup(table, string, create, copy) | 
|---|
| 348 | struct elf64_hppa_dyn_hash_table *table; | 
|---|
| 349 | const char *string; | 
|---|
| 350 | bfd_boolean create, copy; | 
|---|
| 351 | { | 
|---|
| 352 | return ((struct elf64_hppa_dyn_hash_entry *) | 
|---|
| 353 | bfd_hash_lookup (&table->root, string, create, copy)); | 
|---|
| 354 | } | 
|---|
| 355 |  | 
|---|
| 356 | /* Traverse a PA64 ELF linker hash table.  */ | 
|---|
| 357 |  | 
|---|
| 358 | static void | 
|---|
| 359 | elf64_hppa_dyn_hash_traverse (table, func, info) | 
|---|
| 360 | struct elf64_hppa_dyn_hash_table *table; | 
|---|
| 361 | bfd_boolean (*func) PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR)); | 
|---|
| 362 | PTR info; | 
|---|
| 363 | { | 
|---|
| 364 | (bfd_hash_traverse | 
|---|
| 365 | (&table->root, | 
|---|
| 366 | (bfd_boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) func, | 
|---|
| 367 | info)); | 
|---|
| 368 | } | 
|---|
| 369 |  | 
|---|
| 370 |  | 
|---|
| 371 | /* Return nonzero if ABFD represents a PA2.0 ELF64 file. | 
|---|
| 372 |  | 
|---|
| 373 | Additionally we set the default architecture and machine.  */ | 
|---|
| 374 | static bfd_boolean | 
|---|
| 375 | elf64_hppa_object_p (abfd) | 
|---|
| 376 | bfd *abfd; | 
|---|
| 377 | { | 
|---|
| 378 | Elf_Internal_Ehdr * i_ehdrp; | 
|---|
| 379 | unsigned int flags; | 
|---|
| 380 |  | 
|---|
| 381 | i_ehdrp = elf_elfheader (abfd); | 
|---|
| 382 | if (strcmp (bfd_get_target (abfd), "elf64-hppa-linux") == 0) | 
|---|
| 383 | { | 
|---|
| 384 | if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_LINUX) | 
|---|
| 385 | return FALSE; | 
|---|
| 386 | } | 
|---|
| 387 | else | 
|---|
| 388 | { | 
|---|
| 389 | if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_HPUX) | 
|---|
| 390 | return FALSE; | 
|---|
| 391 | } | 
|---|
| 392 |  | 
|---|
| 393 | flags = i_ehdrp->e_flags; | 
|---|
| 394 | switch (flags & (EF_PARISC_ARCH | EF_PARISC_WIDE)) | 
|---|
| 395 | { | 
|---|
| 396 | case EFA_PARISC_1_0: | 
|---|
| 397 | return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 10); | 
|---|
| 398 | case EFA_PARISC_1_1: | 
|---|
| 399 | return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 11); | 
|---|
| 400 | case EFA_PARISC_2_0: | 
|---|
| 401 | return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 20); | 
|---|
| 402 | case EFA_PARISC_2_0 | EF_PARISC_WIDE: | 
|---|
| 403 | return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 25); | 
|---|
| 404 | } | 
|---|
| 405 | /* Don't be fussy.  */ | 
|---|
| 406 | return TRUE; | 
|---|
| 407 | } | 
|---|
| 408 |  | 
|---|
| 409 | /* Given section type (hdr->sh_type), return a boolean indicating | 
|---|
| 410 | whether or not the section is an elf64-hppa specific section.  */ | 
|---|
| 411 | static bfd_boolean | 
|---|
| 412 | elf64_hppa_section_from_shdr (abfd, hdr, name) | 
|---|
| 413 | bfd *abfd; | 
|---|
| 414 | Elf_Internal_Shdr *hdr; | 
|---|
| 415 | const char *name; | 
|---|
| 416 | { | 
|---|
| 417 | asection *newsect; | 
|---|
| 418 |  | 
|---|
| 419 | switch (hdr->sh_type) | 
|---|
| 420 | { | 
|---|
| 421 | case SHT_PARISC_EXT: | 
|---|
| 422 | if (strcmp (name, ".PARISC.archext") != 0) | 
|---|
| 423 | return FALSE; | 
|---|
| 424 | break; | 
|---|
| 425 | case SHT_PARISC_UNWIND: | 
|---|
| 426 | if (strcmp (name, ".PARISC.unwind") != 0) | 
|---|
| 427 | return FALSE; | 
|---|
| 428 | break; | 
|---|
| 429 | case SHT_PARISC_DOC: | 
|---|
| 430 | case SHT_PARISC_ANNOT: | 
|---|
| 431 | default: | 
|---|
| 432 | return FALSE; | 
|---|
| 433 | } | 
|---|
| 434 |  | 
|---|
| 435 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name)) | 
|---|
| 436 | return FALSE; | 
|---|
| 437 | newsect = hdr->bfd_section; | 
|---|
| 438 |  | 
|---|
| 439 | return TRUE; | 
|---|
| 440 | } | 
|---|
| 441 |  | 
|---|
| 442 | /* Construct a string for use in the elf64_hppa_dyn_hash_table.  The | 
|---|
| 443 | name describes what was once potentially anonymous memory.  We | 
|---|
| 444 | allocate memory as necessary, possibly reusing PBUF/PLEN.  */ | 
|---|
| 445 |  | 
|---|
| 446 | static const char * | 
|---|
| 447 | get_dyn_name (sec, h, rel, pbuf, plen) | 
|---|
| 448 | asection *sec; | 
|---|
| 449 | struct elf_link_hash_entry *h; | 
|---|
| 450 | const Elf_Internal_Rela *rel; | 
|---|
| 451 | char **pbuf; | 
|---|
| 452 | size_t *plen; | 
|---|
| 453 | { | 
|---|
| 454 | size_t nlen, tlen; | 
|---|
| 455 | char *buf; | 
|---|
| 456 | size_t len; | 
|---|
| 457 |  | 
|---|
| 458 | if (h && rel->r_addend == 0) | 
|---|
| 459 | return h->root.root.string; | 
|---|
| 460 |  | 
|---|
| 461 | if (h) | 
|---|
| 462 | nlen = strlen (h->root.root.string); | 
|---|
| 463 | else | 
|---|
| 464 | nlen = 8 + 1 + sizeof (rel->r_info) * 2 - 8; | 
|---|
| 465 | tlen = nlen + 1 + sizeof (rel->r_addend) * 2 + 1; | 
|---|
| 466 |  | 
|---|
| 467 | len = *plen; | 
|---|
| 468 | buf = *pbuf; | 
|---|
| 469 | if (len < tlen) | 
|---|
| 470 | { | 
|---|
| 471 | if (buf) | 
|---|
| 472 | free (buf); | 
|---|
| 473 | *pbuf = buf = malloc (tlen); | 
|---|
| 474 | *plen = len = tlen; | 
|---|
| 475 | if (!buf) | 
|---|
| 476 | return NULL; | 
|---|
| 477 | } | 
|---|
| 478 |  | 
|---|
| 479 | if (h) | 
|---|
| 480 | { | 
|---|
| 481 | memcpy (buf, h->root.root.string, nlen); | 
|---|
| 482 | buf[nlen++] = '+'; | 
|---|
| 483 | sprintf_vma (buf + nlen, rel->r_addend); | 
|---|
| 484 | } | 
|---|
| 485 | else | 
|---|
| 486 | { | 
|---|
| 487 | nlen = sprintf (buf, "%x:%lx", | 
|---|
| 488 | sec->id & 0xffffffff, | 
|---|
| 489 | (long) ELF64_R_SYM (rel->r_info)); | 
|---|
| 490 | if (rel->r_addend) | 
|---|
| 491 | { | 
|---|
| 492 | buf[nlen++] = '+'; | 
|---|
| 493 | sprintf_vma (buf + nlen, rel->r_addend); | 
|---|
| 494 | } | 
|---|
| 495 | } | 
|---|
| 496 |  | 
|---|
| 497 | return buf; | 
|---|
| 498 | } | 
|---|
| 499 |  | 
|---|
| 500 | /* SEC is a section containing relocs for an input BFD when linking; return | 
|---|
| 501 | a suitable section for holding relocs in the output BFD for a link.  */ | 
|---|
| 502 |  | 
|---|
| 503 | static bfd_boolean | 
|---|
| 504 | get_reloc_section (abfd, hppa_info, sec) | 
|---|
| 505 | bfd *abfd; | 
|---|
| 506 | struct elf64_hppa_link_hash_table *hppa_info; | 
|---|
| 507 | asection *sec; | 
|---|
| 508 | { | 
|---|
| 509 | const char *srel_name; | 
|---|
| 510 | asection *srel; | 
|---|
| 511 | bfd *dynobj; | 
|---|
| 512 |  | 
|---|
| 513 | srel_name = (bfd_elf_string_from_elf_section | 
|---|
| 514 | (abfd, elf_elfheader(abfd)->e_shstrndx, | 
|---|
| 515 | elf_section_data(sec)->rel_hdr.sh_name)); | 
|---|
| 516 | if (srel_name == NULL) | 
|---|
| 517 | return FALSE; | 
|---|
| 518 |  | 
|---|
| 519 | BFD_ASSERT ((strncmp (srel_name, ".rela", 5) == 0 | 
|---|
| 520 | && strcmp (bfd_get_section_name (abfd, sec), | 
|---|
| 521 | srel_name+5) == 0) | 
|---|
| 522 | || (strncmp (srel_name, ".rel", 4) == 0 | 
|---|
| 523 | && strcmp (bfd_get_section_name (abfd, sec), | 
|---|
| 524 | srel_name+4) == 0)); | 
|---|
| 525 |  | 
|---|
| 526 | dynobj = hppa_info->root.dynobj; | 
|---|
| 527 | if (!dynobj) | 
|---|
| 528 | hppa_info->root.dynobj = dynobj = abfd; | 
|---|
| 529 |  | 
|---|
| 530 | srel = bfd_get_section_by_name (dynobj, srel_name); | 
|---|
| 531 | if (srel == NULL) | 
|---|
| 532 | { | 
|---|
| 533 | srel = bfd_make_section (dynobj, srel_name); | 
|---|
| 534 | if (srel == NULL | 
|---|
| 535 | || !bfd_set_section_flags (dynobj, srel, | 
|---|
| 536 | (SEC_ALLOC | 
|---|
| 537 | | SEC_LOAD | 
|---|
| 538 | | SEC_HAS_CONTENTS | 
|---|
| 539 | | SEC_IN_MEMORY | 
|---|
| 540 | | SEC_LINKER_CREATED | 
|---|
| 541 | | SEC_READONLY)) | 
|---|
| 542 | || !bfd_set_section_alignment (dynobj, srel, 3)) | 
|---|
| 543 | return FALSE; | 
|---|
| 544 | } | 
|---|
| 545 |  | 
|---|
| 546 | hppa_info->other_rel_sec = srel; | 
|---|
| 547 | return TRUE; | 
|---|
| 548 | } | 
|---|
| 549 |  | 
|---|
| 550 | /* Add a new entry to the list of dynamic relocations against DYN_H. | 
|---|
| 551 |  | 
|---|
| 552 | We use this to keep a record of all the FPTR relocations against a | 
|---|
| 553 | particular symbol so that we can create FPTR relocations in the | 
|---|
| 554 | output file.  */ | 
|---|
| 555 |  | 
|---|
| 556 | static bfd_boolean | 
|---|
| 557 | count_dyn_reloc (abfd, dyn_h, type, sec, sec_symndx, offset, addend) | 
|---|
| 558 | bfd *abfd; | 
|---|
| 559 | struct elf64_hppa_dyn_hash_entry *dyn_h; | 
|---|
| 560 | int type; | 
|---|
| 561 | asection *sec; | 
|---|
| 562 | int sec_symndx; | 
|---|
| 563 | bfd_vma offset; | 
|---|
| 564 | bfd_vma addend; | 
|---|
| 565 | { | 
|---|
| 566 | struct elf64_hppa_dyn_reloc_entry *rent; | 
|---|
| 567 |  | 
|---|
| 568 | rent = (struct elf64_hppa_dyn_reloc_entry *) | 
|---|
| 569 | bfd_alloc (abfd, (bfd_size_type) sizeof (*rent)); | 
|---|
| 570 | if (!rent) | 
|---|
| 571 | return FALSE; | 
|---|
| 572 |  | 
|---|
| 573 | rent->next = dyn_h->reloc_entries; | 
|---|
| 574 | rent->type = type; | 
|---|
| 575 | rent->sec = sec; | 
|---|
| 576 | rent->sec_symndx = sec_symndx; | 
|---|
| 577 | rent->offset = offset; | 
|---|
| 578 | rent->addend = addend; | 
|---|
| 579 | dyn_h->reloc_entries = rent; | 
|---|
| 580 |  | 
|---|
| 581 | return TRUE; | 
|---|
| 582 | } | 
|---|
| 583 |  | 
|---|
| 584 | /* Scan the RELOCS and record the type of dynamic entries that each | 
|---|
| 585 | referenced symbol needs.  */ | 
|---|
| 586 |  | 
|---|
| 587 | static bfd_boolean | 
|---|
| 588 | elf64_hppa_check_relocs (abfd, info, sec, relocs) | 
|---|
| 589 | bfd *abfd; | 
|---|
| 590 | struct bfd_link_info *info; | 
|---|
| 591 | asection *sec; | 
|---|
| 592 | const Elf_Internal_Rela *relocs; | 
|---|
| 593 | { | 
|---|
| 594 | struct elf64_hppa_link_hash_table *hppa_info; | 
|---|
| 595 | const Elf_Internal_Rela *relend; | 
|---|
| 596 | Elf_Internal_Shdr *symtab_hdr; | 
|---|
| 597 | const Elf_Internal_Rela *rel; | 
|---|
| 598 | asection *dlt, *plt, *stubs; | 
|---|
| 599 | char *buf; | 
|---|
| 600 | size_t buf_len; | 
|---|
| 601 | int sec_symndx; | 
|---|
| 602 |  | 
|---|
| 603 | if (info->relocateable) | 
|---|
| 604 | return TRUE; | 
|---|
| 605 |  | 
|---|
| 606 | /* If this is the first dynamic object found in the link, create | 
|---|
| 607 | the special sections required for dynamic linking.  */ | 
|---|
| 608 | if (! elf_hash_table (info)->dynamic_sections_created) | 
|---|
| 609 | { | 
|---|
| 610 | if (! bfd_elf64_link_create_dynamic_sections (abfd, info)) | 
|---|
| 611 | return FALSE; | 
|---|
| 612 | } | 
|---|
| 613 |  | 
|---|
| 614 | hppa_info = elf64_hppa_hash_table (info); | 
|---|
| 615 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | 
|---|
| 616 |  | 
|---|
| 617 | /* If necessary, build a new table holding section symbols indices | 
|---|
| 618 | for this BFD.  */ | 
|---|
| 619 |  | 
|---|
| 620 | if (info->shared && hppa_info->section_syms_bfd != abfd) | 
|---|
| 621 | { | 
|---|
| 622 | unsigned long i; | 
|---|
| 623 | unsigned int highest_shndx; | 
|---|
| 624 | Elf_Internal_Sym *local_syms = NULL; | 
|---|
| 625 | Elf_Internal_Sym *isym, *isymend; | 
|---|
| 626 | bfd_size_type amt; | 
|---|
| 627 |  | 
|---|
| 628 | /* We're done with the old cache of section index to section symbol | 
|---|
| 629 | index information.  Free it. | 
|---|
| 630 |  | 
|---|
| 631 | ?!? Note we leak the last section_syms array.  Presumably we | 
|---|
| 632 | could free it in one of the later routines in this file.  */ | 
|---|
| 633 | if (hppa_info->section_syms) | 
|---|
| 634 | free (hppa_info->section_syms); | 
|---|
| 635 |  | 
|---|
| 636 | /* Read this BFD's local symbols.  */ | 
|---|
| 637 | if (symtab_hdr->sh_info != 0) | 
|---|
| 638 | { | 
|---|
| 639 | local_syms = (Elf_Internal_Sym *) symtab_hdr->contents; | 
|---|
| 640 | if (local_syms == NULL) | 
|---|
| 641 | local_syms = bfd_elf_get_elf_syms (abfd, symtab_hdr, | 
|---|
| 642 | symtab_hdr->sh_info, 0, | 
|---|
| 643 | NULL, NULL, NULL); | 
|---|
| 644 | if (local_syms == NULL) | 
|---|
| 645 | return FALSE; | 
|---|
| 646 | } | 
|---|
| 647 |  | 
|---|
| 648 | /* Record the highest section index referenced by the local symbols.  */ | 
|---|
| 649 | highest_shndx = 0; | 
|---|
| 650 | isymend = local_syms + symtab_hdr->sh_info; | 
|---|
| 651 | for (isym = local_syms; isym < isymend; isym++) | 
|---|
| 652 | { | 
|---|
| 653 | if (isym->st_shndx > highest_shndx) | 
|---|
| 654 | highest_shndx = isym->st_shndx; | 
|---|
| 655 | } | 
|---|
| 656 |  | 
|---|
| 657 | /* Allocate an array to hold the section index to section symbol index | 
|---|
| 658 | mapping.  Bump by one since we start counting at zero.  */ | 
|---|
| 659 | highest_shndx++; | 
|---|
| 660 | amt = highest_shndx; | 
|---|
| 661 | amt *= sizeof (int); | 
|---|
| 662 | hppa_info->section_syms = (int *) bfd_malloc (amt); | 
|---|
| 663 |  | 
|---|
| 664 | /* Now walk the local symbols again.  If we find a section symbol, | 
|---|
| 665 | record the index of the symbol into the section_syms array.  */ | 
|---|
| 666 | for (i = 0, isym = local_syms; isym < isymend; i++, isym++) | 
|---|
| 667 | { | 
|---|
| 668 | if (ELF_ST_TYPE (isym->st_info) == STT_SECTION) | 
|---|
| 669 | hppa_info->section_syms[isym->st_shndx] = i; | 
|---|
| 670 | } | 
|---|
| 671 |  | 
|---|
| 672 | /* We are finished with the local symbols.  */ | 
|---|
| 673 | if (local_syms != NULL | 
|---|
| 674 | && symtab_hdr->contents != (unsigned char *) local_syms) | 
|---|
| 675 | { | 
|---|
| 676 | if (! info->keep_memory) | 
|---|
| 677 | free (local_syms); | 
|---|
| 678 | else | 
|---|
| 679 | { | 
|---|
| 680 | /* Cache the symbols for elf_link_input_bfd.  */ | 
|---|
| 681 | symtab_hdr->contents = (unsigned char *) local_syms; | 
|---|
| 682 | } | 
|---|
| 683 | } | 
|---|
| 684 |  | 
|---|
| 685 | /* Record which BFD we built the section_syms mapping for.  */ | 
|---|
| 686 | hppa_info->section_syms_bfd = abfd; | 
|---|
| 687 | } | 
|---|
| 688 |  | 
|---|
| 689 | /* Record the symbol index for this input section.  We may need it for | 
|---|
| 690 | relocations when building shared libraries.  When not building shared | 
|---|
| 691 | libraries this value is never really used, but assign it to zero to | 
|---|
| 692 | prevent out of bounds memory accesses in other routines.  */ | 
|---|
| 693 | if (info->shared) | 
|---|
| 694 | { | 
|---|
| 695 | sec_symndx = _bfd_elf_section_from_bfd_section (abfd, sec); | 
|---|
| 696 |  | 
|---|
| 697 | /* If we did not find a section symbol for this section, then | 
|---|
| 698 | something went terribly wrong above.  */ | 
|---|
| 699 | if (sec_symndx == -1) | 
|---|
| 700 | return FALSE; | 
|---|
| 701 |  | 
|---|
| 702 | sec_symndx = hppa_info->section_syms[sec_symndx]; | 
|---|
| 703 | } | 
|---|
| 704 | else | 
|---|
| 705 | sec_symndx = 0; | 
|---|
| 706 |  | 
|---|
| 707 | dlt = plt = stubs = NULL; | 
|---|
| 708 | buf = NULL; | 
|---|
| 709 | buf_len = 0; | 
|---|
| 710 |  | 
|---|
| 711 | relend = relocs + sec->reloc_count; | 
|---|
| 712 | for (rel = relocs; rel < relend; ++rel) | 
|---|
| 713 | { | 
|---|
| 714 | enum { | 
|---|
| 715 | NEED_DLT = 1, | 
|---|
| 716 | NEED_PLT = 2, | 
|---|
| 717 | NEED_STUB = 4, | 
|---|
| 718 | NEED_OPD = 8, | 
|---|
| 719 | NEED_DYNREL = 16, | 
|---|
| 720 | }; | 
|---|
| 721 |  | 
|---|
| 722 | struct elf_link_hash_entry *h = NULL; | 
|---|
| 723 | unsigned long r_symndx = ELF64_R_SYM (rel->r_info); | 
|---|
| 724 | struct elf64_hppa_dyn_hash_entry *dyn_h; | 
|---|
| 725 | int need_entry; | 
|---|
| 726 | const char *addr_name; | 
|---|
| 727 | bfd_boolean maybe_dynamic; | 
|---|
| 728 | int dynrel_type = R_PARISC_NONE; | 
|---|
| 729 | static reloc_howto_type *howto; | 
|---|
| 730 |  | 
|---|
| 731 | if (r_symndx >= symtab_hdr->sh_info) | 
|---|
| 732 | { | 
|---|
| 733 | /* We're dealing with a global symbol -- find its hash entry | 
|---|
| 734 | and mark it as being referenced.  */ | 
|---|
| 735 | long indx = r_symndx - symtab_hdr->sh_info; | 
|---|
| 736 | h = elf_sym_hashes (abfd)[indx]; | 
|---|
| 737 | while (h->root.type == bfd_link_hash_indirect | 
|---|
| 738 | || h->root.type == bfd_link_hash_warning) | 
|---|
| 739 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | 
|---|
| 740 |  | 
|---|
| 741 | h->elf_link_hash_flags |= ELF_LINK_HASH_REF_REGULAR; | 
|---|
| 742 | } | 
|---|
| 743 |  | 
|---|
| 744 | /* We can only get preliminary data on whether a symbol is | 
|---|
| 745 | locally or externally defined, as not all of the input files | 
|---|
| 746 | have yet been processed.  Do something with what we know, as | 
|---|
| 747 | this may help reduce memory usage and processing time later.  */ | 
|---|
| 748 | maybe_dynamic = FALSE; | 
|---|
| 749 | if (h && ((info->shared | 
|---|
| 750 | && (!info->symbolic || info->allow_shlib_undefined) ) | 
|---|
| 751 | || ! (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) | 
|---|
| 752 | || h->root.type == bfd_link_hash_defweak)) | 
|---|
| 753 | maybe_dynamic = TRUE; | 
|---|
| 754 |  | 
|---|
| 755 | howto = elf_hppa_howto_table + ELF64_R_TYPE (rel->r_info); | 
|---|
| 756 | need_entry = 0; | 
|---|
| 757 | switch (howto->type) | 
|---|
| 758 | { | 
|---|
| 759 | /* These are simple indirect references to symbols through the | 
|---|
| 760 | DLT.  We need to create a DLT entry for any symbols which | 
|---|
| 761 | appears in a DLTIND relocation.  */ | 
|---|
| 762 | case R_PARISC_DLTIND21L: | 
|---|
| 763 | case R_PARISC_DLTIND14R: | 
|---|
| 764 | case R_PARISC_DLTIND14F: | 
|---|
| 765 | case R_PARISC_DLTIND14WR: | 
|---|
| 766 | case R_PARISC_DLTIND14DR: | 
|---|
| 767 | need_entry = NEED_DLT; | 
|---|
| 768 | break; | 
|---|
| 769 |  | 
|---|
| 770 | /* ?!?  These need a DLT entry.  But I have no idea what to do with | 
|---|
| 771 | the "link time TP value.  */ | 
|---|
| 772 | case R_PARISC_LTOFF_TP21L: | 
|---|
| 773 | case R_PARISC_LTOFF_TP14R: | 
|---|
| 774 | case R_PARISC_LTOFF_TP14F: | 
|---|
| 775 | case R_PARISC_LTOFF_TP64: | 
|---|
| 776 | case R_PARISC_LTOFF_TP14WR: | 
|---|
| 777 | case R_PARISC_LTOFF_TP14DR: | 
|---|
| 778 | case R_PARISC_LTOFF_TP16F: | 
|---|
| 779 | case R_PARISC_LTOFF_TP16WF: | 
|---|
| 780 | case R_PARISC_LTOFF_TP16DF: | 
|---|
| 781 | need_entry = NEED_DLT; | 
|---|
| 782 | break; | 
|---|
| 783 |  | 
|---|
| 784 | /* These are function calls.  Depending on their precise target we | 
|---|
| 785 | may need to make a stub for them.  The stub uses the PLT, so we | 
|---|
| 786 | need to create PLT entries for these symbols too.  */ | 
|---|
| 787 | case R_PARISC_PCREL12F: | 
|---|
| 788 | case R_PARISC_PCREL17F: | 
|---|
| 789 | case R_PARISC_PCREL22F: | 
|---|
| 790 | case R_PARISC_PCREL32: | 
|---|
| 791 | case R_PARISC_PCREL64: | 
|---|
| 792 | case R_PARISC_PCREL21L: | 
|---|
| 793 | case R_PARISC_PCREL17R: | 
|---|
| 794 | case R_PARISC_PCREL17C: | 
|---|
| 795 | case R_PARISC_PCREL14R: | 
|---|
| 796 | case R_PARISC_PCREL14F: | 
|---|
| 797 | case R_PARISC_PCREL22C: | 
|---|
| 798 | case R_PARISC_PCREL14WR: | 
|---|
| 799 | case R_PARISC_PCREL14DR: | 
|---|
| 800 | case R_PARISC_PCREL16F: | 
|---|
| 801 | case R_PARISC_PCREL16WF: | 
|---|
| 802 | case R_PARISC_PCREL16DF: | 
|---|
| 803 | need_entry = (NEED_PLT | NEED_STUB); | 
|---|
| 804 | break; | 
|---|
| 805 |  | 
|---|
| 806 | case R_PARISC_PLTOFF21L: | 
|---|
| 807 | case R_PARISC_PLTOFF14R: | 
|---|
| 808 | case R_PARISC_PLTOFF14F: | 
|---|
| 809 | case R_PARISC_PLTOFF14WR: | 
|---|
| 810 | case R_PARISC_PLTOFF14DR: | 
|---|
| 811 | case R_PARISC_PLTOFF16F: | 
|---|
| 812 | case R_PARISC_PLTOFF16WF: | 
|---|
| 813 | case R_PARISC_PLTOFF16DF: | 
|---|
| 814 | need_entry = (NEED_PLT); | 
|---|
| 815 | break; | 
|---|
| 816 |  | 
|---|
| 817 | case R_PARISC_DIR64: | 
|---|
| 818 | if (info->shared || maybe_dynamic) | 
|---|
| 819 | need_entry = (NEED_DYNREL); | 
|---|
| 820 | dynrel_type = R_PARISC_DIR64; | 
|---|
| 821 | break; | 
|---|
| 822 |  | 
|---|
| 823 | /* This is an indirect reference through the DLT to get the address | 
|---|
| 824 | of a OPD descriptor.  Thus we need to make a DLT entry that points | 
|---|
| 825 | to an OPD entry.  */ | 
|---|
| 826 | case R_PARISC_LTOFF_FPTR21L: | 
|---|
| 827 | case R_PARISC_LTOFF_FPTR14R: | 
|---|
| 828 | case R_PARISC_LTOFF_FPTR14WR: | 
|---|
| 829 | case R_PARISC_LTOFF_FPTR14DR: | 
|---|
| 830 | case R_PARISC_LTOFF_FPTR32: | 
|---|
| 831 | case R_PARISC_LTOFF_FPTR64: | 
|---|
| 832 | case R_PARISC_LTOFF_FPTR16F: | 
|---|
| 833 | case R_PARISC_LTOFF_FPTR16WF: | 
|---|
| 834 | case R_PARISC_LTOFF_FPTR16DF: | 
|---|
| 835 | if (info->shared || maybe_dynamic) | 
|---|
| 836 | need_entry = (NEED_DLT | NEED_OPD); | 
|---|
| 837 | else | 
|---|
| 838 | need_entry = (NEED_DLT | NEED_OPD); | 
|---|
| 839 | dynrel_type = R_PARISC_FPTR64; | 
|---|
| 840 | break; | 
|---|
| 841 |  | 
|---|
| 842 | /* This is a simple OPD entry.  */ | 
|---|
| 843 | case R_PARISC_FPTR64: | 
|---|
| 844 | if (info->shared || maybe_dynamic) | 
|---|
| 845 | need_entry = (NEED_OPD | NEED_DYNREL); | 
|---|
| 846 | else | 
|---|
| 847 | need_entry = (NEED_OPD); | 
|---|
| 848 | dynrel_type = R_PARISC_FPTR64; | 
|---|
| 849 | break; | 
|---|
| 850 |  | 
|---|
| 851 | /* Add more cases as needed.  */ | 
|---|
| 852 | } | 
|---|
| 853 |  | 
|---|
| 854 | if (!need_entry) | 
|---|
| 855 | continue; | 
|---|
| 856 |  | 
|---|
| 857 | /* Collect a canonical name for this address.  */ | 
|---|
| 858 | addr_name = get_dyn_name (sec, h, rel, &buf, &buf_len); | 
|---|
| 859 |  | 
|---|
| 860 | /* Collect the canonical entry data for this address.  */ | 
|---|
| 861 | dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table, | 
|---|
| 862 | addr_name, TRUE, TRUE); | 
|---|
| 863 | BFD_ASSERT (dyn_h); | 
|---|
| 864 |  | 
|---|
| 865 | /* Stash away enough information to be able to find this symbol | 
|---|
| 866 | regardless of whether or not it is local or global.  */ | 
|---|
| 867 | dyn_h->h = h; | 
|---|
| 868 | dyn_h->owner = abfd; | 
|---|
| 869 | dyn_h->sym_indx = r_symndx; | 
|---|
| 870 |  | 
|---|
| 871 | /* ?!? We may need to do some error checking in here.  */ | 
|---|
| 872 | /* Create what's needed.  */ | 
|---|
| 873 | if (need_entry & NEED_DLT) | 
|---|
| 874 | { | 
|---|
| 875 | if (! hppa_info->dlt_sec | 
|---|
| 876 | && ! get_dlt (abfd, info, hppa_info)) | 
|---|
| 877 | goto err_out; | 
|---|
| 878 | dyn_h->want_dlt = 1; | 
|---|
| 879 | } | 
|---|
| 880 |  | 
|---|
| 881 | if (need_entry & NEED_PLT) | 
|---|
| 882 | { | 
|---|
| 883 | if (! hppa_info->plt_sec | 
|---|
| 884 | && ! get_plt (abfd, info, hppa_info)) | 
|---|
| 885 | goto err_out; | 
|---|
| 886 | dyn_h->want_plt = 1; | 
|---|
| 887 | } | 
|---|
| 888 |  | 
|---|
| 889 | if (need_entry & NEED_STUB) | 
|---|
| 890 | { | 
|---|
| 891 | if (! hppa_info->stub_sec | 
|---|
| 892 | && ! get_stub (abfd, info, hppa_info)) | 
|---|
| 893 | goto err_out; | 
|---|
| 894 | dyn_h->want_stub = 1; | 
|---|
| 895 | } | 
|---|
| 896 |  | 
|---|
| 897 | if (need_entry & NEED_OPD) | 
|---|
| 898 | { | 
|---|
| 899 | if (! hppa_info->opd_sec | 
|---|
| 900 | && ! get_opd (abfd, info, hppa_info)) | 
|---|
| 901 | goto err_out; | 
|---|
| 902 |  | 
|---|
| 903 | dyn_h->want_opd = 1; | 
|---|
| 904 |  | 
|---|
| 905 | /* FPTRs are not allocated by the dynamic linker for PA64, though | 
|---|
| 906 | it is possible that will change in the future.  */ | 
|---|
| 907 |  | 
|---|
| 908 | /* This could be a local function that had its address taken, in | 
|---|
| 909 | which case H will be NULL.  */ | 
|---|
| 910 | if (h) | 
|---|
| 911 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; | 
|---|
| 912 | } | 
|---|
| 913 |  | 
|---|
| 914 | /* Add a new dynamic relocation to the chain of dynamic | 
|---|
| 915 | relocations for this symbol.  */ | 
|---|
| 916 | if ((need_entry & NEED_DYNREL) && (sec->flags & SEC_ALLOC)) | 
|---|
| 917 | { | 
|---|
| 918 | if (! hppa_info->other_rel_sec | 
|---|
| 919 | && ! get_reloc_section (abfd, hppa_info, sec)) | 
|---|
| 920 | goto err_out; | 
|---|
| 921 |  | 
|---|
| 922 | if (!count_dyn_reloc (abfd, dyn_h, dynrel_type, sec, | 
|---|
| 923 | sec_symndx, rel->r_offset, rel->r_addend)) | 
|---|
| 924 | goto err_out; | 
|---|
| 925 |  | 
|---|
| 926 | /* If we are building a shared library and we just recorded | 
|---|
| 927 | a dynamic R_PARISC_FPTR64 relocation, then make sure the | 
|---|
| 928 | section symbol for this section ends up in the dynamic | 
|---|
| 929 | symbol table.  */ | 
|---|
| 930 | if (info->shared && dynrel_type == R_PARISC_FPTR64 | 
|---|
| 931 | && ! (_bfd_elf64_link_record_local_dynamic_symbol | 
|---|
| 932 | (info, abfd, sec_symndx))) | 
|---|
| 933 | return FALSE; | 
|---|
| 934 | } | 
|---|
| 935 | } | 
|---|
| 936 |  | 
|---|
| 937 | if (buf) | 
|---|
| 938 | free (buf); | 
|---|
| 939 | return TRUE; | 
|---|
| 940 |  | 
|---|
| 941 | err_out: | 
|---|
| 942 | if (buf) | 
|---|
| 943 | free (buf); | 
|---|
| 944 | return FALSE; | 
|---|
| 945 | } | 
|---|
| 946 |  | 
|---|
| 947 | struct elf64_hppa_allocate_data | 
|---|
| 948 | { | 
|---|
| 949 | struct bfd_link_info *info; | 
|---|
| 950 | bfd_size_type ofs; | 
|---|
| 951 | }; | 
|---|
| 952 |  | 
|---|
| 953 | /* Should we do dynamic things to this symbol?  */ | 
|---|
| 954 |  | 
|---|
| 955 | static bfd_boolean | 
|---|
| 956 | elf64_hppa_dynamic_symbol_p (h, info) | 
|---|
| 957 | struct elf_link_hash_entry *h; | 
|---|
| 958 | struct bfd_link_info *info; | 
|---|
| 959 | { | 
|---|
| 960 | if (h == NULL) | 
|---|
| 961 | return FALSE; | 
|---|
| 962 |  | 
|---|
| 963 | while (h->root.type == bfd_link_hash_indirect | 
|---|
| 964 | || h->root.type == bfd_link_hash_warning) | 
|---|
| 965 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | 
|---|
| 966 |  | 
|---|
| 967 | if (h->dynindx == -1) | 
|---|
| 968 | return FALSE; | 
|---|
| 969 |  | 
|---|
| 970 | if (h->root.type == bfd_link_hash_undefweak | 
|---|
| 971 | || h->root.type == bfd_link_hash_defweak) | 
|---|
| 972 | return TRUE; | 
|---|
| 973 |  | 
|---|
| 974 | if (h->root.root.string[0] == '$' && h->root.root.string[1] == '$') | 
|---|
| 975 | return FALSE; | 
|---|
| 976 |  | 
|---|
| 977 | if ((info->shared && (!info->symbolic || info->allow_shlib_undefined)) | 
|---|
| 978 | || ((h->elf_link_hash_flags | 
|---|
| 979 | & (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR)) | 
|---|
| 980 | == (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR))) | 
|---|
| 981 | return TRUE; | 
|---|
| 982 |  | 
|---|
| 983 | return FALSE; | 
|---|
| 984 | } | 
|---|
| 985 |  | 
|---|
| 986 | /* Mark all funtions exported by this file so that we can later allocate | 
|---|
| 987 | entries in .opd for them.  */ | 
|---|
| 988 |  | 
|---|
| 989 | static bfd_boolean | 
|---|
| 990 | elf64_hppa_mark_exported_functions (h, data) | 
|---|
| 991 | struct elf_link_hash_entry *h; | 
|---|
| 992 | PTR data; | 
|---|
| 993 | { | 
|---|
| 994 | struct bfd_link_info *info = (struct bfd_link_info *)data; | 
|---|
| 995 | struct elf64_hppa_link_hash_table *hppa_info; | 
|---|
| 996 |  | 
|---|
| 997 | hppa_info = elf64_hppa_hash_table (info); | 
|---|
| 998 |  | 
|---|
| 999 | if (h->root.type == bfd_link_hash_warning) | 
|---|
| 1000 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | 
|---|
| 1001 |  | 
|---|
| 1002 | if (h | 
|---|
| 1003 | && (h->root.type == bfd_link_hash_defined | 
|---|
| 1004 | || h->root.type == bfd_link_hash_defweak) | 
|---|
| 1005 | && h->root.u.def.section->output_section != NULL | 
|---|
| 1006 | && h->type == STT_FUNC) | 
|---|
| 1007 | { | 
|---|
| 1008 | struct elf64_hppa_dyn_hash_entry *dyn_h; | 
|---|
| 1009 |  | 
|---|
| 1010 | /* Add this symbol to the PA64 linker hash table.  */ | 
|---|
| 1011 | dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table, | 
|---|
| 1012 | h->root.root.string, TRUE, TRUE); | 
|---|
| 1013 | BFD_ASSERT (dyn_h); | 
|---|
| 1014 | dyn_h->h = h; | 
|---|
| 1015 |  | 
|---|
| 1016 | if (! hppa_info->opd_sec | 
|---|
| 1017 | && ! get_opd (hppa_info->root.dynobj, info, hppa_info)) | 
|---|
| 1018 | return FALSE; | 
|---|
| 1019 |  | 
|---|
| 1020 | dyn_h->want_opd = 1; | 
|---|
| 1021 | /* Put a flag here for output_symbol_hook.  */ | 
|---|
| 1022 | dyn_h->st_shndx = -1; | 
|---|
| 1023 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; | 
|---|
| 1024 | } | 
|---|
| 1025 |  | 
|---|
| 1026 | return TRUE; | 
|---|
| 1027 | } | 
|---|
| 1028 |  | 
|---|
| 1029 | /* Allocate space for a DLT entry.  */ | 
|---|
| 1030 |  | 
|---|
| 1031 | static bfd_boolean | 
|---|
| 1032 | allocate_global_data_dlt (dyn_h, data) | 
|---|
| 1033 | struct elf64_hppa_dyn_hash_entry *dyn_h; | 
|---|
| 1034 | PTR data; | 
|---|
| 1035 | { | 
|---|
| 1036 | struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data; | 
|---|
| 1037 |  | 
|---|
| 1038 | if (dyn_h->want_dlt) | 
|---|
| 1039 | { | 
|---|
| 1040 | struct elf_link_hash_entry *h = dyn_h->h; | 
|---|
| 1041 |  | 
|---|
| 1042 | if (x->info->shared) | 
|---|
| 1043 | { | 
|---|
| 1044 | /* Possibly add the symbol to the local dynamic symbol | 
|---|
| 1045 | table since we might need to create a dynamic relocation | 
|---|
| 1046 | against it.  */ | 
|---|
| 1047 | if (! h | 
|---|
| 1048 | || (h->dynindx == -1 && h->type != STT_PARISC_MILLI)) | 
|---|
| 1049 | { | 
|---|
| 1050 | bfd *owner; | 
|---|
| 1051 | owner = (h ? h->root.u.def.section->owner : dyn_h->owner); | 
|---|
| 1052 |  | 
|---|
| 1053 | if (! (_bfd_elf64_link_record_local_dynamic_symbol | 
|---|
| 1054 | (x->info, owner, dyn_h->sym_indx))) | 
|---|
| 1055 | return FALSE; | 
|---|
| 1056 | } | 
|---|
| 1057 | } | 
|---|
| 1058 |  | 
|---|
| 1059 | dyn_h->dlt_offset = x->ofs; | 
|---|
| 1060 | x->ofs += DLT_ENTRY_SIZE; | 
|---|
| 1061 | } | 
|---|
| 1062 | return TRUE; | 
|---|
| 1063 | } | 
|---|
| 1064 |  | 
|---|
| 1065 | /* Allocate space for a DLT.PLT entry.  */ | 
|---|
| 1066 |  | 
|---|
| 1067 | static bfd_boolean | 
|---|
| 1068 | allocate_global_data_plt (dyn_h, data) | 
|---|
| 1069 | struct elf64_hppa_dyn_hash_entry *dyn_h; | 
|---|
| 1070 | PTR data; | 
|---|
| 1071 | { | 
|---|
| 1072 | struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data; | 
|---|
| 1073 |  | 
|---|
| 1074 | if (dyn_h->want_plt | 
|---|
| 1075 | && elf64_hppa_dynamic_symbol_p (dyn_h->h, x->info) | 
|---|
| 1076 | && !((dyn_h->h->root.type == bfd_link_hash_defined | 
|---|
| 1077 | || dyn_h->h->root.type == bfd_link_hash_defweak) | 
|---|
| 1078 | && dyn_h->h->root.u.def.section->output_section != NULL)) | 
|---|
| 1079 | { | 
|---|
| 1080 | dyn_h->plt_offset = x->ofs; | 
|---|
| 1081 | x->ofs += PLT_ENTRY_SIZE; | 
|---|
| 1082 | if (dyn_h->plt_offset < 0x2000) | 
|---|
| 1083 | elf64_hppa_hash_table (x->info)->gp_offset = dyn_h->plt_offset; | 
|---|
| 1084 | } | 
|---|
| 1085 | else | 
|---|
| 1086 | dyn_h->want_plt = 0; | 
|---|
| 1087 |  | 
|---|
| 1088 | return TRUE; | 
|---|
| 1089 | } | 
|---|
| 1090 |  | 
|---|
| 1091 | /* Allocate space for a STUB entry.  */ | 
|---|
| 1092 |  | 
|---|
| 1093 | static bfd_boolean | 
|---|
| 1094 | allocate_global_data_stub (dyn_h, data) | 
|---|
| 1095 | struct elf64_hppa_dyn_hash_entry *dyn_h; | 
|---|
| 1096 | PTR data; | 
|---|
| 1097 | { | 
|---|
| 1098 | struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data; | 
|---|
| 1099 |  | 
|---|
| 1100 | if (dyn_h->want_stub | 
|---|
| 1101 | && elf64_hppa_dynamic_symbol_p (dyn_h->h, x->info) | 
|---|
| 1102 | && !((dyn_h->h->root.type == bfd_link_hash_defined | 
|---|
| 1103 | || dyn_h->h->root.type == bfd_link_hash_defweak) | 
|---|
| 1104 | && dyn_h->h->root.u.def.section->output_section != NULL)) | 
|---|
| 1105 | { | 
|---|
| 1106 | dyn_h->stub_offset = x->ofs; | 
|---|
| 1107 | x->ofs += sizeof (plt_stub); | 
|---|
| 1108 | } | 
|---|
| 1109 | else | 
|---|
| 1110 | dyn_h->want_stub = 0; | 
|---|
| 1111 | return TRUE; | 
|---|
| 1112 | } | 
|---|
| 1113 |  | 
|---|
| 1114 | /* Allocate space for a FPTR entry.  */ | 
|---|
| 1115 |  | 
|---|
| 1116 | static bfd_boolean | 
|---|
| 1117 | allocate_global_data_opd (dyn_h, data) | 
|---|
| 1118 | struct elf64_hppa_dyn_hash_entry *dyn_h; | 
|---|
| 1119 | PTR data; | 
|---|
| 1120 | { | 
|---|
| 1121 | struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data; | 
|---|
| 1122 |  | 
|---|
| 1123 | if (dyn_h->want_opd) | 
|---|
| 1124 | { | 
|---|
| 1125 | struct elf_link_hash_entry *h = dyn_h->h; | 
|---|
| 1126 |  | 
|---|
| 1127 | if (h) | 
|---|
| 1128 | while (h->root.type == bfd_link_hash_indirect | 
|---|
| 1129 | || h->root.type == bfd_link_hash_warning) | 
|---|
| 1130 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | 
|---|
| 1131 |  | 
|---|
| 1132 | /* We never need an opd entry for a symbol which is not | 
|---|
| 1133 | defined by this output file.  */ | 
|---|
| 1134 | if (h && (h->root.type == bfd_link_hash_undefined | 
|---|
| 1135 | || h->root.u.def.section->output_section == NULL)) | 
|---|
| 1136 | dyn_h->want_opd = 0; | 
|---|
| 1137 |  | 
|---|
| 1138 | /* If we are creating a shared library, took the address of a local | 
|---|
| 1139 | function or might export this function from this object file, then | 
|---|
| 1140 | we have to create an opd descriptor.  */ | 
|---|
| 1141 | else if (x->info->shared | 
|---|
| 1142 | || h == NULL | 
|---|
| 1143 | || (h->dynindx == -1 && h->type != STT_PARISC_MILLI) | 
|---|
| 1144 | || (h->root.type == bfd_link_hash_defined | 
|---|
| 1145 | || h->root.type == bfd_link_hash_defweak)) | 
|---|
| 1146 | { | 
|---|
| 1147 | /* If we are creating a shared library, then we will have to | 
|---|
| 1148 | create a runtime relocation for the symbol to properly | 
|---|
| 1149 | initialize the .opd entry.  Make sure the symbol gets | 
|---|
| 1150 | added to the dynamic symbol table.  */ | 
|---|
| 1151 | if (x->info->shared | 
|---|
| 1152 | && (h == NULL || (h->dynindx == -1))) | 
|---|
| 1153 | { | 
|---|
| 1154 | bfd *owner; | 
|---|
| 1155 | owner = (h ? h->root.u.def.section->owner : dyn_h->owner); | 
|---|
| 1156 |  | 
|---|
| 1157 | if (!_bfd_elf64_link_record_local_dynamic_symbol | 
|---|
| 1158 | (x->info, owner, dyn_h->sym_indx)) | 
|---|
| 1159 | return FALSE; | 
|---|
| 1160 | } | 
|---|
| 1161 |  | 
|---|
| 1162 | /* This may not be necessary or desirable anymore now that | 
|---|
| 1163 | we have some support for dealing with section symbols | 
|---|
| 1164 | in dynamic relocs.  But name munging does make the result | 
|---|
| 1165 | much easier to debug.  ie, the EPLT reloc will reference | 
|---|
| 1166 | a symbol like .foobar, instead of .text + offset.  */ | 
|---|
| 1167 | if (x->info->shared && h) | 
|---|
| 1168 | { | 
|---|
| 1169 | char *new_name; | 
|---|
| 1170 | struct elf_link_hash_entry *nh; | 
|---|
| 1171 |  | 
|---|
| 1172 | new_name = alloca (strlen (h->root.root.string) + 2); | 
|---|
| 1173 | new_name[0] = '.'; | 
|---|
| 1174 | strcpy (new_name + 1, h->root.root.string); | 
|---|
| 1175 |  | 
|---|
| 1176 | nh = elf_link_hash_lookup (elf_hash_table (x->info), | 
|---|
| 1177 | new_name, TRUE, TRUE, TRUE); | 
|---|
| 1178 |  | 
|---|
| 1179 | nh->root.type = h->root.type; | 
|---|
| 1180 | nh->root.u.def.value = h->root.u.def.value; | 
|---|
| 1181 | nh->root.u.def.section = h->root.u.def.section; | 
|---|
| 1182 |  | 
|---|
| 1183 | if (! bfd_elf64_link_record_dynamic_symbol (x->info, nh)) | 
|---|
| 1184 | return FALSE; | 
|---|
| 1185 |  | 
|---|
| 1186 | } | 
|---|
| 1187 | dyn_h->opd_offset = x->ofs; | 
|---|
| 1188 | x->ofs += OPD_ENTRY_SIZE; | 
|---|
| 1189 | } | 
|---|
| 1190 |  | 
|---|
| 1191 | /* Otherwise we do not need an opd entry.  */ | 
|---|
| 1192 | else | 
|---|
| 1193 | dyn_h->want_opd = 0; | 
|---|
| 1194 | } | 
|---|
| 1195 | return TRUE; | 
|---|
| 1196 | } | 
|---|
| 1197 |  | 
|---|
| 1198 | /* HP requires the EI_OSABI field to be filled in.  The assignment to | 
|---|
| 1199 | EI_ABIVERSION may not be strictly necessary.  */ | 
|---|
| 1200 |  | 
|---|
| 1201 | static void | 
|---|
| 1202 | elf64_hppa_post_process_headers (abfd, link_info) | 
|---|
| 1203 | bfd * abfd; | 
|---|
| 1204 | struct bfd_link_info * link_info ATTRIBUTE_UNUSED; | 
|---|
| 1205 | { | 
|---|
| 1206 | Elf_Internal_Ehdr * i_ehdrp; | 
|---|
| 1207 |  | 
|---|
| 1208 | i_ehdrp = elf_elfheader (abfd); | 
|---|
| 1209 |  | 
|---|
| 1210 | if (strcmp (bfd_get_target (abfd), "elf64-hppa-linux") == 0) | 
|---|
| 1211 | { | 
|---|
| 1212 | i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_LINUX; | 
|---|
| 1213 | } | 
|---|
| 1214 | else | 
|---|
| 1215 | { | 
|---|
| 1216 | i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_HPUX; | 
|---|
| 1217 | i_ehdrp->e_ident[EI_ABIVERSION] = 1; | 
|---|
| 1218 | } | 
|---|
| 1219 | } | 
|---|
| 1220 |  | 
|---|
| 1221 | /* Create function descriptor section (.opd).  This section is called .opd | 
|---|
| 1222 | because it contains "official prodecure descriptors".  The "official" | 
|---|
| 1223 | refers to the fact that these descriptors are used when taking the address | 
|---|
| 1224 | of a procedure, thus ensuring a unique address for each procedure.  */ | 
|---|
| 1225 |  | 
|---|
| 1226 | static bfd_boolean | 
|---|
| 1227 | get_opd (abfd, info, hppa_info) | 
|---|
| 1228 | bfd *abfd; | 
|---|
| 1229 | struct bfd_link_info *info ATTRIBUTE_UNUSED; | 
|---|
| 1230 | struct elf64_hppa_link_hash_table *hppa_info; | 
|---|
| 1231 | { | 
|---|
| 1232 | asection *opd; | 
|---|
| 1233 | bfd *dynobj; | 
|---|
| 1234 |  | 
|---|
| 1235 | opd = hppa_info->opd_sec; | 
|---|
| 1236 | if (!opd) | 
|---|
| 1237 | { | 
|---|
| 1238 | dynobj = hppa_info->root.dynobj; | 
|---|
| 1239 | if (!dynobj) | 
|---|
| 1240 | hppa_info->root.dynobj = dynobj = abfd; | 
|---|
| 1241 |  | 
|---|
| 1242 | opd = bfd_make_section (dynobj, ".opd"); | 
|---|
| 1243 | if (!opd | 
|---|
| 1244 | || !bfd_set_section_flags (dynobj, opd, | 
|---|
| 1245 | (SEC_ALLOC | 
|---|
| 1246 | | SEC_LOAD | 
|---|
| 1247 | | SEC_HAS_CONTENTS | 
|---|
| 1248 | | SEC_IN_MEMORY | 
|---|
| 1249 | | SEC_LINKER_CREATED)) | 
|---|
| 1250 | || !bfd_set_section_alignment (abfd, opd, 3)) | 
|---|
| 1251 | { | 
|---|
| 1252 | BFD_ASSERT (0); | 
|---|
| 1253 | return FALSE; | 
|---|
| 1254 | } | 
|---|
| 1255 |  | 
|---|
| 1256 | hppa_info->opd_sec = opd; | 
|---|
| 1257 | } | 
|---|
| 1258 |  | 
|---|
| 1259 | return TRUE; | 
|---|
| 1260 | } | 
|---|
| 1261 |  | 
|---|
| 1262 | /* Create the PLT section.  */ | 
|---|
| 1263 |  | 
|---|
| 1264 | static bfd_boolean | 
|---|
| 1265 | get_plt (abfd, info, hppa_info) | 
|---|
| 1266 | bfd *abfd; | 
|---|
| 1267 | struct bfd_link_info *info ATTRIBUTE_UNUSED; | 
|---|
| 1268 | struct elf64_hppa_link_hash_table *hppa_info; | 
|---|
| 1269 | { | 
|---|
| 1270 | asection *plt; | 
|---|
| 1271 | bfd *dynobj; | 
|---|
| 1272 |  | 
|---|
| 1273 | plt = hppa_info->plt_sec; | 
|---|
| 1274 | if (!plt) | 
|---|
| 1275 | { | 
|---|
| 1276 | dynobj = hppa_info->root.dynobj; | 
|---|
| 1277 | if (!dynobj) | 
|---|
| 1278 | hppa_info->root.dynobj = dynobj = abfd; | 
|---|
| 1279 |  | 
|---|
| 1280 | plt = bfd_make_section (dynobj, ".plt"); | 
|---|
| 1281 | if (!plt | 
|---|
| 1282 | || !bfd_set_section_flags (dynobj, plt, | 
|---|
| 1283 | (SEC_ALLOC | 
|---|
| 1284 | | SEC_LOAD | 
|---|
| 1285 | | SEC_HAS_CONTENTS | 
|---|
| 1286 | | SEC_IN_MEMORY | 
|---|
| 1287 | | SEC_LINKER_CREATED)) | 
|---|
| 1288 | || !bfd_set_section_alignment (abfd, plt, 3)) | 
|---|
| 1289 | { | 
|---|
| 1290 | BFD_ASSERT (0); | 
|---|
| 1291 | return FALSE; | 
|---|
| 1292 | } | 
|---|
| 1293 |  | 
|---|
| 1294 | hppa_info->plt_sec = plt; | 
|---|
| 1295 | } | 
|---|
| 1296 |  | 
|---|
| 1297 | return TRUE; | 
|---|
| 1298 | } | 
|---|
| 1299 |  | 
|---|
| 1300 | /* Create the DLT section.  */ | 
|---|
| 1301 |  | 
|---|
| 1302 | static bfd_boolean | 
|---|
| 1303 | get_dlt (abfd, info, hppa_info) | 
|---|
| 1304 | bfd *abfd; | 
|---|
| 1305 | struct bfd_link_info *info ATTRIBUTE_UNUSED; | 
|---|
| 1306 | struct elf64_hppa_link_hash_table *hppa_info; | 
|---|
| 1307 | { | 
|---|
| 1308 | asection *dlt; | 
|---|
| 1309 | bfd *dynobj; | 
|---|
| 1310 |  | 
|---|
| 1311 | dlt = hppa_info->dlt_sec; | 
|---|
| 1312 | if (!dlt) | 
|---|
| 1313 | { | 
|---|
| 1314 | dynobj = hppa_info->root.dynobj; | 
|---|
| 1315 | if (!dynobj) | 
|---|
| 1316 | hppa_info->root.dynobj = dynobj = abfd; | 
|---|
| 1317 |  | 
|---|
| 1318 | dlt = bfd_make_section (dynobj, ".dlt"); | 
|---|
| 1319 | if (!dlt | 
|---|
| 1320 | || !bfd_set_section_flags (dynobj, dlt, | 
|---|
| 1321 | (SEC_ALLOC | 
|---|
| 1322 | | SEC_LOAD | 
|---|
| 1323 | | SEC_HAS_CONTENTS | 
|---|
| 1324 | | SEC_IN_MEMORY | 
|---|
| 1325 | | SEC_LINKER_CREATED)) | 
|---|
| 1326 | || !bfd_set_section_alignment (abfd, dlt, 3)) | 
|---|
| 1327 | { | 
|---|
| 1328 | BFD_ASSERT (0); | 
|---|
| 1329 | return FALSE; | 
|---|
| 1330 | } | 
|---|
| 1331 |  | 
|---|
| 1332 | hppa_info->dlt_sec = dlt; | 
|---|
| 1333 | } | 
|---|
| 1334 |  | 
|---|
| 1335 | return TRUE; | 
|---|
| 1336 | } | 
|---|
| 1337 |  | 
|---|
| 1338 | /* Create the stubs section.  */ | 
|---|
| 1339 |  | 
|---|
| 1340 | static bfd_boolean | 
|---|
| 1341 | get_stub (abfd, info, hppa_info) | 
|---|
| 1342 | bfd *abfd; | 
|---|
| 1343 | struct bfd_link_info *info ATTRIBUTE_UNUSED; | 
|---|
| 1344 | struct elf64_hppa_link_hash_table *hppa_info; | 
|---|
| 1345 | { | 
|---|
| 1346 | asection *stub; | 
|---|
| 1347 | bfd *dynobj; | 
|---|
| 1348 |  | 
|---|
| 1349 | stub = hppa_info->stub_sec; | 
|---|
| 1350 | if (!stub) | 
|---|
| 1351 | { | 
|---|
| 1352 | dynobj = hppa_info->root.dynobj; | 
|---|
| 1353 | if (!dynobj) | 
|---|
| 1354 | hppa_info->root.dynobj = dynobj = abfd; | 
|---|
| 1355 |  | 
|---|
| 1356 | stub = bfd_make_section (dynobj, ".stub"); | 
|---|
| 1357 | if (!stub | 
|---|
| 1358 | || !bfd_set_section_flags (dynobj, stub, | 
|---|
| 1359 | (SEC_ALLOC | 
|---|
| 1360 | | SEC_LOAD | 
|---|
| 1361 | | SEC_HAS_CONTENTS | 
|---|
| 1362 | | SEC_IN_MEMORY | 
|---|
| 1363 | | SEC_READONLY | 
|---|
| 1364 | | SEC_LINKER_CREATED)) | 
|---|
| 1365 | || !bfd_set_section_alignment (abfd, stub, 3)) | 
|---|
| 1366 | { | 
|---|
| 1367 | BFD_ASSERT (0); | 
|---|
| 1368 | return FALSE; | 
|---|
| 1369 | } | 
|---|
| 1370 |  | 
|---|
| 1371 | hppa_info->stub_sec = stub; | 
|---|
| 1372 | } | 
|---|
| 1373 |  | 
|---|
| 1374 | return TRUE; | 
|---|
| 1375 | } | 
|---|
| 1376 |  | 
|---|
| 1377 | /* Create sections necessary for dynamic linking.  This is only a rough | 
|---|
| 1378 | cut and will likely change as we learn more about the somewhat | 
|---|
| 1379 | unusual dynamic linking scheme HP uses. | 
|---|
| 1380 |  | 
|---|
| 1381 | .stub: | 
|---|
| 1382 | Contains code to implement cross-space calls.  The first time one | 
|---|
| 1383 | of the stubs is used it will call into the dynamic linker, later | 
|---|
| 1384 | calls will go straight to the target. | 
|---|
| 1385 |  | 
|---|
| 1386 | The only stub we support right now looks like | 
|---|
| 1387 |  | 
|---|
| 1388 | ldd OFFSET(%dp),%r1 | 
|---|
| 1389 | bve %r0(%r1) | 
|---|
| 1390 | ldd OFFSET+8(%dp),%dp | 
|---|
| 1391 |  | 
|---|
| 1392 | Other stubs may be needed in the future.  We may want the remove | 
|---|
| 1393 | the break/nop instruction.  It is only used right now to keep the | 
|---|
| 1394 | offset of a .plt entry and a .stub entry in sync. | 
|---|
| 1395 |  | 
|---|
| 1396 | .dlt: | 
|---|
| 1397 | This is what most people call the .got.  HP used a different name. | 
|---|
| 1398 | Losers. | 
|---|
| 1399 |  | 
|---|
| 1400 | .rela.dlt: | 
|---|
| 1401 | Relocations for the DLT. | 
|---|
| 1402 |  | 
|---|
| 1403 | .plt: | 
|---|
| 1404 | Function pointers as address,gp pairs. | 
|---|
| 1405 |  | 
|---|
| 1406 | .rela.plt: | 
|---|
| 1407 | Should contain dynamic IPLT (and EPLT?) relocations. | 
|---|
| 1408 |  | 
|---|
| 1409 | .opd: | 
|---|
| 1410 | FPTRS | 
|---|
| 1411 |  | 
|---|
| 1412 | .rela.opd: | 
|---|
| 1413 | EPLT relocations for symbols exported from shared libraries.  */ | 
|---|
| 1414 |  | 
|---|
| 1415 | static bfd_boolean | 
|---|
| 1416 | elf64_hppa_create_dynamic_sections (abfd, info) | 
|---|
| 1417 | bfd *abfd; | 
|---|
| 1418 | struct bfd_link_info *info; | 
|---|
| 1419 | { | 
|---|
| 1420 | asection *s; | 
|---|
| 1421 |  | 
|---|
| 1422 | if (! get_stub (abfd, info, elf64_hppa_hash_table (info))) | 
|---|
| 1423 | return FALSE; | 
|---|
| 1424 |  | 
|---|
| 1425 | if (! get_dlt (abfd, info, elf64_hppa_hash_table (info))) | 
|---|
| 1426 | return FALSE; | 
|---|
| 1427 |  | 
|---|
| 1428 | if (! get_plt (abfd, info, elf64_hppa_hash_table (info))) | 
|---|
| 1429 | return FALSE; | 
|---|
| 1430 |  | 
|---|
| 1431 | if (! get_opd (abfd, info, elf64_hppa_hash_table (info))) | 
|---|
| 1432 | return FALSE; | 
|---|
| 1433 |  | 
|---|
| 1434 | s = bfd_make_section(abfd, ".rela.dlt"); | 
|---|
| 1435 | if (s == NULL | 
|---|
| 1436 | || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD | 
|---|
| 1437 | | SEC_HAS_CONTENTS | 
|---|
| 1438 | | SEC_IN_MEMORY | 
|---|
| 1439 | | SEC_READONLY | 
|---|
| 1440 | | SEC_LINKER_CREATED)) | 
|---|
| 1441 | || !bfd_set_section_alignment (abfd, s, 3)) | 
|---|
| 1442 | return FALSE; | 
|---|
| 1443 | elf64_hppa_hash_table (info)->dlt_rel_sec = s; | 
|---|
| 1444 |  | 
|---|
| 1445 | s = bfd_make_section(abfd, ".rela.plt"); | 
|---|
| 1446 | if (s == NULL | 
|---|
| 1447 | || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD | 
|---|
| 1448 | | SEC_HAS_CONTENTS | 
|---|
| 1449 | | SEC_IN_MEMORY | 
|---|
| 1450 | | SEC_READONLY | 
|---|
| 1451 | | SEC_LINKER_CREATED)) | 
|---|
| 1452 | || !bfd_set_section_alignment (abfd, s, 3)) | 
|---|
| 1453 | return FALSE; | 
|---|
| 1454 | elf64_hppa_hash_table (info)->plt_rel_sec = s; | 
|---|
| 1455 |  | 
|---|
| 1456 | s = bfd_make_section(abfd, ".rela.data"); | 
|---|
| 1457 | if (s == NULL | 
|---|
| 1458 | || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD | 
|---|
| 1459 | | SEC_HAS_CONTENTS | 
|---|
| 1460 | | SEC_IN_MEMORY | 
|---|
| 1461 | | SEC_READONLY | 
|---|
| 1462 | | SEC_LINKER_CREATED)) | 
|---|
| 1463 | || !bfd_set_section_alignment (abfd, s, 3)) | 
|---|
| 1464 | return FALSE; | 
|---|
| 1465 | elf64_hppa_hash_table (info)->other_rel_sec = s; | 
|---|
| 1466 |  | 
|---|
| 1467 | s = bfd_make_section(abfd, ".rela.opd"); | 
|---|
| 1468 | if (s == NULL | 
|---|
| 1469 | || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD | 
|---|
| 1470 | | SEC_HAS_CONTENTS | 
|---|
| 1471 | | SEC_IN_MEMORY | 
|---|
| 1472 | | SEC_READONLY | 
|---|
| 1473 | | SEC_LINKER_CREATED)) | 
|---|
| 1474 | || !bfd_set_section_alignment (abfd, s, 3)) | 
|---|
| 1475 | return FALSE; | 
|---|
| 1476 | elf64_hppa_hash_table (info)->opd_rel_sec = s; | 
|---|
| 1477 |  | 
|---|
| 1478 | return TRUE; | 
|---|
| 1479 | } | 
|---|
| 1480 |  | 
|---|
| 1481 | /* Allocate dynamic relocations for those symbols that turned out | 
|---|
| 1482 | to be dynamic.  */ | 
|---|
| 1483 |  | 
|---|
| 1484 | static bfd_boolean | 
|---|
| 1485 | allocate_dynrel_entries (dyn_h, data) | 
|---|
| 1486 | struct elf64_hppa_dyn_hash_entry *dyn_h; | 
|---|
| 1487 | PTR data; | 
|---|
| 1488 | { | 
|---|
| 1489 | struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data; | 
|---|
| 1490 | struct elf64_hppa_link_hash_table *hppa_info; | 
|---|
| 1491 | struct elf64_hppa_dyn_reloc_entry *rent; | 
|---|
| 1492 | bfd_boolean dynamic_symbol, shared; | 
|---|
| 1493 |  | 
|---|
| 1494 | hppa_info = elf64_hppa_hash_table (x->info); | 
|---|
| 1495 | dynamic_symbol = elf64_hppa_dynamic_symbol_p (dyn_h->h, x->info); | 
|---|
| 1496 | shared = x->info->shared; | 
|---|
| 1497 |  | 
|---|
| 1498 | /* We may need to allocate relocations for a non-dynamic symbol | 
|---|
| 1499 | when creating a shared library.  */ | 
|---|
| 1500 | if (!dynamic_symbol && !shared) | 
|---|
| 1501 | return TRUE; | 
|---|
| 1502 |  | 
|---|
| 1503 | /* Take care of the normal data relocations.  */ | 
|---|
| 1504 |  | 
|---|
| 1505 | for (rent = dyn_h->reloc_entries; rent; rent = rent->next) | 
|---|
| 1506 | { | 
|---|
| 1507 | /* Allocate one iff we are building a shared library, the relocation | 
|---|
| 1508 | isn't a R_PARISC_FPTR64, or we don't want an opd entry.  */ | 
|---|
| 1509 | if (!shared && rent->type == R_PARISC_FPTR64 && dyn_h->want_opd) | 
|---|
| 1510 | continue; | 
|---|
| 1511 |  | 
|---|
| 1512 | hppa_info->other_rel_sec->_raw_size += sizeof (Elf64_External_Rela); | 
|---|
| 1513 |  | 
|---|
| 1514 | /* Make sure this symbol gets into the dynamic symbol table if it is | 
|---|
| 1515 | not already recorded.  ?!? This should not be in the loop since | 
|---|
| 1516 | the symbol need only be added once.  */ | 
|---|
| 1517 | if (dyn_h->h == 0 | 
|---|
| 1518 | || (dyn_h->h->dynindx == -1 && dyn_h->h->type != STT_PARISC_MILLI)) | 
|---|
| 1519 | if (!_bfd_elf64_link_record_local_dynamic_symbol | 
|---|
| 1520 | (x->info, rent->sec->owner, dyn_h->sym_indx)) | 
|---|
| 1521 | return FALSE; | 
|---|
| 1522 | } | 
|---|
| 1523 |  | 
|---|
| 1524 | /* Take care of the GOT and PLT relocations.  */ | 
|---|
| 1525 |  | 
|---|
| 1526 | if ((dynamic_symbol || shared) && dyn_h->want_dlt) | 
|---|
| 1527 | hppa_info->dlt_rel_sec->_raw_size += sizeof (Elf64_External_Rela); | 
|---|
| 1528 |  | 
|---|
| 1529 | /* If we are building a shared library, then every symbol that has an | 
|---|
| 1530 | opd entry will need an EPLT relocation to relocate the symbol's address | 
|---|
| 1531 | and __gp value based on the runtime load address.  */ | 
|---|
| 1532 | if (shared && dyn_h->want_opd) | 
|---|
| 1533 | hppa_info->opd_rel_sec->_raw_size += sizeof (Elf64_External_Rela); | 
|---|
| 1534 |  | 
|---|
| 1535 | if (dyn_h->want_plt && dynamic_symbol) | 
|---|
| 1536 | { | 
|---|
| 1537 | bfd_size_type t = 0; | 
|---|
| 1538 |  | 
|---|
| 1539 | /* Dynamic symbols get one IPLT relocation.  Local symbols in | 
|---|
| 1540 | shared libraries get two REL relocations.  Local symbols in | 
|---|
| 1541 | main applications get nothing.  */ | 
|---|
| 1542 | if (dynamic_symbol) | 
|---|
| 1543 | t = sizeof (Elf64_External_Rela); | 
|---|
| 1544 | else if (shared) | 
|---|
| 1545 | t = 2 * sizeof (Elf64_External_Rela); | 
|---|
| 1546 |  | 
|---|
| 1547 | hppa_info->plt_rel_sec->_raw_size += t; | 
|---|
| 1548 | } | 
|---|
| 1549 |  | 
|---|
| 1550 | return TRUE; | 
|---|
| 1551 | } | 
|---|
| 1552 |  | 
|---|
| 1553 | /* Adjust a symbol defined by a dynamic object and referenced by a | 
|---|
| 1554 | regular object.  */ | 
|---|
| 1555 |  | 
|---|
| 1556 | static bfd_boolean | 
|---|
| 1557 | elf64_hppa_adjust_dynamic_symbol (info, h) | 
|---|
| 1558 | struct bfd_link_info *info ATTRIBUTE_UNUSED; | 
|---|
| 1559 | struct elf_link_hash_entry *h; | 
|---|
| 1560 | { | 
|---|
| 1561 | /* ??? Undefined symbols with PLT entries should be re-defined | 
|---|
| 1562 | to be the PLT entry.  */ | 
|---|
| 1563 |  | 
|---|
| 1564 | /* If this is a weak symbol, and there is a real definition, the | 
|---|
| 1565 | processor independent code will have arranged for us to see the | 
|---|
| 1566 | real definition first, and we can just use the same value.  */ | 
|---|
| 1567 | if (h->weakdef != NULL) | 
|---|
| 1568 | { | 
|---|
| 1569 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined | 
|---|
| 1570 | || h->weakdef->root.type == bfd_link_hash_defweak); | 
|---|
| 1571 | h->root.u.def.section = h->weakdef->root.u.def.section; | 
|---|
| 1572 | h->root.u.def.value = h->weakdef->root.u.def.value; | 
|---|
| 1573 | return TRUE; | 
|---|
| 1574 | } | 
|---|
| 1575 |  | 
|---|
| 1576 | /* If this is a reference to a symbol defined by a dynamic object which | 
|---|
| 1577 | is not a function, we might allocate the symbol in our .dynbss section | 
|---|
| 1578 | and allocate a COPY dynamic relocation. | 
|---|
| 1579 |  | 
|---|
| 1580 | But PA64 code is canonically PIC, so as a rule we can avoid this sort | 
|---|
| 1581 | of hackery.  */ | 
|---|
| 1582 |  | 
|---|
| 1583 | return TRUE; | 
|---|
| 1584 | } | 
|---|
| 1585 |  | 
|---|
| 1586 | /* This function is called via elf_link_hash_traverse to mark millicode | 
|---|
| 1587 | symbols with a dynindx of -1 and to remove the string table reference | 
|---|
| 1588 | from the dynamic symbol table.  If the symbol is not a millicode symbol, | 
|---|
| 1589 | elf64_hppa_mark_exported_functions is called.  */ | 
|---|
| 1590 |  | 
|---|
| 1591 | static bfd_boolean | 
|---|
| 1592 | elf64_hppa_mark_milli_and_exported_functions (h, data) | 
|---|
| 1593 | struct elf_link_hash_entry *h; | 
|---|
| 1594 | PTR data; | 
|---|
| 1595 | { | 
|---|
| 1596 | struct bfd_link_info *info = (struct bfd_link_info *)data; | 
|---|
| 1597 | struct elf_link_hash_entry *elf = h; | 
|---|
| 1598 |  | 
|---|
| 1599 | if (elf->root.type == bfd_link_hash_warning) | 
|---|
| 1600 | elf = (struct elf_link_hash_entry *) elf->root.u.i.link; | 
|---|
| 1601 |  | 
|---|
| 1602 | if (elf->type == STT_PARISC_MILLI) | 
|---|
| 1603 | { | 
|---|
| 1604 | if (elf->dynindx != -1) | 
|---|
| 1605 | { | 
|---|
| 1606 | elf->dynindx = -1; | 
|---|
| 1607 | _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr, | 
|---|
| 1608 | elf->dynstr_index); | 
|---|
| 1609 | } | 
|---|
| 1610 | return TRUE; | 
|---|
| 1611 | } | 
|---|
| 1612 |  | 
|---|
| 1613 | return elf64_hppa_mark_exported_functions (h, data); | 
|---|
| 1614 | } | 
|---|
| 1615 |  | 
|---|
| 1616 | /* Set the final sizes of the dynamic sections and allocate memory for | 
|---|
| 1617 | the contents of our special sections.  */ | 
|---|
| 1618 |  | 
|---|
| 1619 | static bfd_boolean | 
|---|
| 1620 | elf64_hppa_size_dynamic_sections (output_bfd, info) | 
|---|
| 1621 | bfd *output_bfd; | 
|---|
| 1622 | struct bfd_link_info *info; | 
|---|
| 1623 | { | 
|---|
| 1624 | bfd *dynobj; | 
|---|
| 1625 | asection *s; | 
|---|
| 1626 | bfd_boolean plt; | 
|---|
| 1627 | bfd_boolean relocs; | 
|---|
| 1628 | bfd_boolean reltext; | 
|---|
| 1629 | struct elf64_hppa_allocate_data data; | 
|---|
| 1630 | struct elf64_hppa_link_hash_table *hppa_info; | 
|---|
| 1631 |  | 
|---|
| 1632 | hppa_info = elf64_hppa_hash_table (info); | 
|---|
| 1633 |  | 
|---|
| 1634 | dynobj = elf_hash_table (info)->dynobj; | 
|---|
| 1635 | BFD_ASSERT (dynobj != NULL); | 
|---|
| 1636 |  | 
|---|
| 1637 | /* Mark each function this program exports so that we will allocate | 
|---|
| 1638 | space in the .opd section for each function's FPTR.  If we are | 
|---|
| 1639 | creating dynamic sections, change the dynamic index of millicode | 
|---|
| 1640 | symbols to -1 and remove them from the string table for .dynstr. | 
|---|
| 1641 |  | 
|---|
| 1642 | We have to traverse the main linker hash table since we have to | 
|---|
| 1643 | find functions which may not have been mentioned in any relocs.  */ | 
|---|
| 1644 | elf_link_hash_traverse (elf_hash_table (info), | 
|---|
| 1645 | (elf_hash_table (info)->dynamic_sections_created | 
|---|
| 1646 | ? elf64_hppa_mark_milli_and_exported_functions | 
|---|
| 1647 | : elf64_hppa_mark_exported_functions), | 
|---|
| 1648 | info); | 
|---|
| 1649 |  | 
|---|
| 1650 | if (elf_hash_table (info)->dynamic_sections_created) | 
|---|
| 1651 | { | 
|---|
| 1652 | /* Set the contents of the .interp section to the interpreter.  */ | 
|---|
| 1653 | if (! info->shared) | 
|---|
| 1654 | { | 
|---|
| 1655 | s = bfd_get_section_by_name (dynobj, ".interp"); | 
|---|
| 1656 | BFD_ASSERT (s != NULL); | 
|---|
| 1657 | s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER; | 
|---|
| 1658 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; | 
|---|
| 1659 | } | 
|---|
| 1660 | } | 
|---|
| 1661 | else | 
|---|
| 1662 | { | 
|---|
| 1663 | /* We may have created entries in the .rela.got section. | 
|---|
| 1664 | However, if we are not creating the dynamic sections, we will | 
|---|
| 1665 | not actually use these entries.  Reset the size of .rela.dlt, | 
|---|
| 1666 | which will cause it to get stripped from the output file | 
|---|
| 1667 | below.  */ | 
|---|
| 1668 | s = bfd_get_section_by_name (dynobj, ".rela.dlt"); | 
|---|
| 1669 | if (s != NULL) | 
|---|
| 1670 | s->_raw_size = 0; | 
|---|
| 1671 | } | 
|---|
| 1672 |  | 
|---|
| 1673 | /* Allocate the GOT entries.  */ | 
|---|
| 1674 |  | 
|---|
| 1675 | data.info = info; | 
|---|
| 1676 | if (elf64_hppa_hash_table (info)->dlt_sec) | 
|---|
| 1677 | { | 
|---|
| 1678 | data.ofs = 0x0; | 
|---|
| 1679 | elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table, | 
|---|
| 1680 | allocate_global_data_dlt, &data); | 
|---|
| 1681 | hppa_info->dlt_sec->_raw_size = data.ofs; | 
|---|
| 1682 |  | 
|---|
| 1683 | data.ofs = 0x0; | 
|---|
| 1684 | elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table, | 
|---|
| 1685 | allocate_global_data_plt, &data); | 
|---|
| 1686 | hppa_info->plt_sec->_raw_size = data.ofs; | 
|---|
| 1687 |  | 
|---|
| 1688 | data.ofs = 0x0; | 
|---|
| 1689 | elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table, | 
|---|
| 1690 | allocate_global_data_stub, &data); | 
|---|
| 1691 | hppa_info->stub_sec->_raw_size = data.ofs; | 
|---|
| 1692 | } | 
|---|
| 1693 |  | 
|---|
| 1694 | /* Allocate space for entries in the .opd section.  */ | 
|---|
| 1695 | if (elf64_hppa_hash_table (info)->opd_sec) | 
|---|
| 1696 | { | 
|---|
| 1697 | data.ofs = 0; | 
|---|
| 1698 | elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table, | 
|---|
| 1699 | allocate_global_data_opd, &data); | 
|---|
| 1700 | hppa_info->opd_sec->_raw_size = data.ofs; | 
|---|
| 1701 | } | 
|---|
| 1702 |  | 
|---|
| 1703 | /* Now allocate space for dynamic relocations, if necessary.  */ | 
|---|
| 1704 | if (hppa_info->root.dynamic_sections_created) | 
|---|
| 1705 | elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table, | 
|---|
| 1706 | allocate_dynrel_entries, &data); | 
|---|
| 1707 |  | 
|---|
| 1708 | /* The sizes of all the sections are set.  Allocate memory for them.  */ | 
|---|
| 1709 | plt = FALSE; | 
|---|
| 1710 | relocs = FALSE; | 
|---|
| 1711 | reltext = FALSE; | 
|---|
| 1712 | for (s = dynobj->sections; s != NULL; s = s->next) | 
|---|
| 1713 | { | 
|---|
| 1714 | const char *name; | 
|---|
| 1715 | bfd_boolean strip; | 
|---|
| 1716 |  | 
|---|
| 1717 | if ((s->flags & SEC_LINKER_CREATED) == 0) | 
|---|
| 1718 | continue; | 
|---|
| 1719 |  | 
|---|
| 1720 | /* It's OK to base decisions on the section name, because none | 
|---|
| 1721 | of the dynobj section names depend upon the input files.  */ | 
|---|
| 1722 | name = bfd_get_section_name (dynobj, s); | 
|---|
| 1723 |  | 
|---|
| 1724 | strip = 0; | 
|---|
| 1725 |  | 
|---|
| 1726 | if (strcmp (name, ".plt") == 0) | 
|---|
| 1727 | { | 
|---|
| 1728 | /* Strip this section if we don't need it; see the comment below.  */ | 
|---|
| 1729 | if (s->_raw_size == 0) | 
|---|
| 1730 | { | 
|---|
| 1731 | strip = TRUE; | 
|---|
| 1732 | } | 
|---|
| 1733 | else | 
|---|
| 1734 | { | 
|---|
| 1735 | /* Remember whether there is a PLT.  */ | 
|---|
| 1736 | plt = TRUE; | 
|---|
| 1737 | } | 
|---|
| 1738 | } | 
|---|
| 1739 | else if (strcmp (name, ".dlt") == 0) | 
|---|
| 1740 | { | 
|---|
| 1741 | /* Strip this section if we don't need it; see the comment below.  */ | 
|---|
| 1742 | if (s->_raw_size == 0) | 
|---|
| 1743 | { | 
|---|
| 1744 | strip = TRUE; | 
|---|
| 1745 | } | 
|---|
| 1746 | } | 
|---|
| 1747 | else if (strcmp (name, ".opd") == 0) | 
|---|
| 1748 | { | 
|---|
| 1749 | /* Strip this section if we don't need it; see the comment below.  */ | 
|---|
| 1750 | if (s->_raw_size == 0) | 
|---|
| 1751 | { | 
|---|
| 1752 | strip = TRUE; | 
|---|
| 1753 | } | 
|---|
| 1754 | } | 
|---|
| 1755 | else if (strncmp (name, ".rela", 5) == 0) | 
|---|
| 1756 | { | 
|---|
| 1757 | /* If we don't need this section, strip it from the output file. | 
|---|
| 1758 | This is mostly to handle .rela.bss and .rela.plt.  We must | 
|---|
| 1759 | create both sections in create_dynamic_sections, because they | 
|---|
| 1760 | must be created before the linker maps input sections to output | 
|---|
| 1761 | sections.  The linker does that before adjust_dynamic_symbol | 
|---|
| 1762 | is called, and it is that function which decides whether | 
|---|
| 1763 | anything needs to go into these sections.  */ | 
|---|
| 1764 | if (s->_raw_size == 0) | 
|---|
| 1765 | { | 
|---|
| 1766 | /* If we don't need this section, strip it from the | 
|---|
| 1767 | output file.  This is mostly to handle .rela.bss and | 
|---|
| 1768 | .rela.plt.  We must create both sections in | 
|---|
| 1769 | create_dynamic_sections, because they must be created | 
|---|
| 1770 | before the linker maps input sections to output | 
|---|
| 1771 | sections.  The linker does that before | 
|---|
| 1772 | adjust_dynamic_symbol is called, and it is that | 
|---|
| 1773 | function which decides whether anything needs to go | 
|---|
| 1774 | into these sections.  */ | 
|---|
| 1775 | strip = TRUE; | 
|---|
| 1776 | } | 
|---|
| 1777 | else | 
|---|
| 1778 | { | 
|---|
| 1779 | asection *target; | 
|---|
| 1780 |  | 
|---|
| 1781 | /* Remember whether there are any reloc sections other | 
|---|
| 1782 | than .rela.plt.  */ | 
|---|
| 1783 | if (strcmp (name, ".rela.plt") != 0) | 
|---|
| 1784 | { | 
|---|
| 1785 | const char *outname; | 
|---|
| 1786 |  | 
|---|
| 1787 | relocs = TRUE; | 
|---|
| 1788 |  | 
|---|
| 1789 | /* If this relocation section applies to a read only | 
|---|
| 1790 | section, then we probably need a DT_TEXTREL | 
|---|
| 1791 | entry.  The entries in the .rela.plt section | 
|---|
| 1792 | really apply to the .got section, which we | 
|---|
| 1793 | created ourselves and so know is not readonly.  */ | 
|---|
| 1794 | outname = bfd_get_section_name (output_bfd, | 
|---|
| 1795 | s->output_section); | 
|---|
| 1796 | target = bfd_get_section_by_name (output_bfd, outname + 4); | 
|---|
| 1797 | if (target != NULL | 
|---|
| 1798 | && (target->flags & SEC_READONLY) != 0 | 
|---|
| 1799 | && (target->flags & SEC_ALLOC) != 0) | 
|---|
| 1800 | reltext = TRUE; | 
|---|
| 1801 | } | 
|---|
| 1802 |  | 
|---|
| 1803 | /* We use the reloc_count field as a counter if we need | 
|---|
| 1804 | to copy relocs into the output file.  */ | 
|---|
| 1805 | s->reloc_count = 0; | 
|---|
| 1806 | } | 
|---|
| 1807 | } | 
|---|
| 1808 | else if (strncmp (name, ".dlt", 4) != 0 | 
|---|
| 1809 | && strcmp (name, ".stub") != 0 | 
|---|
| 1810 | && strcmp (name, ".got") != 0) | 
|---|
| 1811 | { | 
|---|
| 1812 | /* It's not one of our sections, so don't allocate space.  */ | 
|---|
| 1813 | continue; | 
|---|
| 1814 | } | 
|---|
| 1815 |  | 
|---|
| 1816 | if (strip) | 
|---|
| 1817 | { | 
|---|
| 1818 | _bfd_strip_section_from_output (info, s); | 
|---|
| 1819 | continue; | 
|---|
| 1820 | } | 
|---|
| 1821 |  | 
|---|
| 1822 | /* Allocate memory for the section contents if it has not | 
|---|
| 1823 | been allocated already.  We use bfd_zalloc here in case | 
|---|
| 1824 | unused entries are not reclaimed before the section's | 
|---|
| 1825 | contents are written out.  This should not happen, but this | 
|---|
| 1826 | way if it does, we get a R_PARISC_NONE reloc instead of | 
|---|
| 1827 | garbage.  */ | 
|---|
| 1828 | if (s->contents == NULL) | 
|---|
| 1829 | { | 
|---|
| 1830 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size); | 
|---|
| 1831 | if (s->contents == NULL && s->_raw_size != 0) | 
|---|
| 1832 | return FALSE; | 
|---|
| 1833 | } | 
|---|
| 1834 | } | 
|---|
| 1835 |  | 
|---|
| 1836 | if (elf_hash_table (info)->dynamic_sections_created) | 
|---|
| 1837 | { | 
|---|
| 1838 | /* Always create a DT_PLTGOT.  It actually has nothing to do with | 
|---|
| 1839 | the PLT, it is how we communicate the __gp value of a load | 
|---|
| 1840 | module to the dynamic linker.  */ | 
|---|
| 1841 | #define add_dynamic_entry(TAG, VAL) \ | 
|---|
| 1842 | bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL)) | 
|---|
| 1843 |  | 
|---|
| 1844 | if (!add_dynamic_entry (DT_HP_DLD_FLAGS, 0) | 
|---|
| 1845 | || !add_dynamic_entry (DT_PLTGOT, 0)) | 
|---|
| 1846 | return FALSE; | 
|---|
| 1847 |  | 
|---|
| 1848 | /* Add some entries to the .dynamic section.  We fill in the | 
|---|
| 1849 | values later, in elf64_hppa_finish_dynamic_sections, but we | 
|---|
| 1850 | must add the entries now so that we get the correct size for | 
|---|
| 1851 | the .dynamic section.  The DT_DEBUG entry is filled in by the | 
|---|
| 1852 | dynamic linker and used by the debugger.  */ | 
|---|
| 1853 | if (! info->shared) | 
|---|
| 1854 | { | 
|---|
| 1855 | if (!add_dynamic_entry (DT_DEBUG, 0) | 
|---|
| 1856 | || !add_dynamic_entry (DT_HP_DLD_HOOK, 0) | 
|---|
| 1857 | || !add_dynamic_entry (DT_HP_LOAD_MAP, 0)) | 
|---|
| 1858 | return FALSE; | 
|---|
| 1859 | } | 
|---|
| 1860 |  | 
|---|
| 1861 | /* Force DT_FLAGS to always be set. | 
|---|
| 1862 | Required by HPUX 11.00 patch PHSS_26559.  */ | 
|---|
| 1863 | if (!add_dynamic_entry (DT_FLAGS, (info)->flags)) | 
|---|
| 1864 | return FALSE; | 
|---|
| 1865 |  | 
|---|
| 1866 | if (plt) | 
|---|
| 1867 | { | 
|---|
| 1868 | if (!add_dynamic_entry (DT_PLTRELSZ, 0) | 
|---|
| 1869 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) | 
|---|
| 1870 | || !add_dynamic_entry (DT_JMPREL, 0)) | 
|---|
| 1871 | return FALSE; | 
|---|
| 1872 | } | 
|---|
| 1873 |  | 
|---|
| 1874 | if (relocs) | 
|---|
| 1875 | { | 
|---|
| 1876 | if (!add_dynamic_entry (DT_RELA, 0) | 
|---|
| 1877 | || !add_dynamic_entry (DT_RELASZ, 0) | 
|---|
| 1878 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela))) | 
|---|
| 1879 | return FALSE; | 
|---|
| 1880 | } | 
|---|
| 1881 |  | 
|---|
| 1882 | if (reltext) | 
|---|
| 1883 | { | 
|---|
| 1884 | if (!add_dynamic_entry (DT_TEXTREL, 0)) | 
|---|
| 1885 | return FALSE; | 
|---|
| 1886 | info->flags |= DF_TEXTREL; | 
|---|
| 1887 | } | 
|---|
| 1888 | } | 
|---|
| 1889 | #undef add_dynamic_entry | 
|---|
| 1890 |  | 
|---|
| 1891 | return TRUE; | 
|---|
| 1892 | } | 
|---|
| 1893 |  | 
|---|
| 1894 | /* Called after we have output the symbol into the dynamic symbol | 
|---|
| 1895 | table, but before we output the symbol into the normal symbol | 
|---|
| 1896 | table. | 
|---|
| 1897 |  | 
|---|
| 1898 | For some symbols we had to change their address when outputting | 
|---|
| 1899 | the dynamic symbol table.  We undo that change here so that | 
|---|
| 1900 | the symbols have their expected value in the normal symbol | 
|---|
| 1901 | table.  Ick.  */ | 
|---|
| 1902 |  | 
|---|
| 1903 | static bfd_boolean | 
|---|
| 1904 | elf64_hppa_link_output_symbol_hook (abfd, info, name, sym, input_sec) | 
|---|
| 1905 | bfd *abfd ATTRIBUTE_UNUSED; | 
|---|
| 1906 | struct bfd_link_info *info; | 
|---|
| 1907 | const char *name; | 
|---|
| 1908 | Elf_Internal_Sym *sym; | 
|---|
| 1909 | asection *input_sec ATTRIBUTE_UNUSED; | 
|---|
| 1910 | { | 
|---|
| 1911 | struct elf64_hppa_link_hash_table *hppa_info; | 
|---|
| 1912 | struct elf64_hppa_dyn_hash_entry *dyn_h; | 
|---|
| 1913 |  | 
|---|
| 1914 | /* We may be called with the file symbol or section symbols. | 
|---|
| 1915 | They never need munging, so it is safe to ignore them.  */ | 
|---|
| 1916 | if (!name) | 
|---|
| 1917 | return TRUE; | 
|---|
| 1918 |  | 
|---|
| 1919 | /* Get the PA dyn_symbol (if any) associated with NAME.  */ | 
|---|
| 1920 | hppa_info = elf64_hppa_hash_table (info); | 
|---|
| 1921 | dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table, | 
|---|
| 1922 | name, FALSE, FALSE); | 
|---|
| 1923 |  | 
|---|
| 1924 | /* Function symbols for which we created .opd entries *may* have been | 
|---|
| 1925 | munged by finish_dynamic_symbol and have to be un-munged here. | 
|---|
| 1926 |  | 
|---|
| 1927 | Note that finish_dynamic_symbol sometimes turns dynamic symbols | 
|---|
| 1928 | into non-dynamic ones, so we initialize st_shndx to -1 in | 
|---|
| 1929 | mark_exported_functions and check to see if it was overwritten | 
|---|
| 1930 | here instead of just checking dyn_h->h->dynindx.  */ | 
|---|
| 1931 | if (dyn_h && dyn_h->want_opd && dyn_h->st_shndx != -1) | 
|---|
| 1932 | { | 
|---|
| 1933 | /* Restore the saved value and section index.  */ | 
|---|
| 1934 | sym->st_value = dyn_h->st_value; | 
|---|
| 1935 | sym->st_shndx = dyn_h->st_shndx; | 
|---|
| 1936 | } | 
|---|
| 1937 |  | 
|---|
| 1938 | return TRUE; | 
|---|
| 1939 | } | 
|---|
| 1940 |  | 
|---|
| 1941 | /* Finish up dynamic symbol handling.  We set the contents of various | 
|---|
| 1942 | dynamic sections here.  */ | 
|---|
| 1943 |  | 
|---|
| 1944 | static bfd_boolean | 
|---|
| 1945 | elf64_hppa_finish_dynamic_symbol (output_bfd, info, h, sym) | 
|---|
| 1946 | bfd *output_bfd; | 
|---|
| 1947 | struct bfd_link_info *info; | 
|---|
| 1948 | struct elf_link_hash_entry *h; | 
|---|
| 1949 | Elf_Internal_Sym *sym; | 
|---|
| 1950 | { | 
|---|
| 1951 | asection *stub, *splt, *sdlt, *sopd, *spltrel, *sdltrel; | 
|---|
| 1952 | struct elf64_hppa_link_hash_table *hppa_info; | 
|---|
| 1953 | struct elf64_hppa_dyn_hash_entry *dyn_h; | 
|---|
| 1954 |  | 
|---|
| 1955 | hppa_info = elf64_hppa_hash_table (info); | 
|---|
| 1956 | dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table, | 
|---|
| 1957 | h->root.root.string, FALSE, FALSE); | 
|---|
| 1958 |  | 
|---|
| 1959 | stub = hppa_info->stub_sec; | 
|---|
| 1960 | splt = hppa_info->plt_sec; | 
|---|
| 1961 | sdlt = hppa_info->dlt_sec; | 
|---|
| 1962 | sopd = hppa_info->opd_sec; | 
|---|
| 1963 | spltrel = hppa_info->plt_rel_sec; | 
|---|
| 1964 | sdltrel = hppa_info->dlt_rel_sec; | 
|---|
| 1965 |  | 
|---|
| 1966 | /* Incredible.  It is actually necessary to NOT use the symbol's real | 
|---|
| 1967 | value when building the dynamic symbol table for a shared library. | 
|---|
| 1968 | At least for symbols that refer to functions. | 
|---|
| 1969 |  | 
|---|
| 1970 | We will store a new value and section index into the symbol long | 
|---|
| 1971 | enough to output it into the dynamic symbol table, then we restore | 
|---|
| 1972 | the original values (in elf64_hppa_link_output_symbol_hook).  */ | 
|---|
| 1973 | if (dyn_h && dyn_h->want_opd) | 
|---|
| 1974 | { | 
|---|
| 1975 | BFD_ASSERT (sopd != NULL) | 
|---|
| 1976 |  | 
|---|
| 1977 | /* Save away the original value and section index so that we | 
|---|
| 1978 | can restore them later.  */ | 
|---|
| 1979 | dyn_h->st_value = sym->st_value; | 
|---|
| 1980 | dyn_h->st_shndx = sym->st_shndx; | 
|---|
| 1981 |  | 
|---|
| 1982 | /* For the dynamic symbol table entry, we want the value to be | 
|---|
| 1983 | address of this symbol's entry within the .opd section.  */ | 
|---|
| 1984 | sym->st_value = (dyn_h->opd_offset | 
|---|
| 1985 | + sopd->output_offset | 
|---|
| 1986 | + sopd->output_section->vma); | 
|---|
| 1987 | sym->st_shndx = _bfd_elf_section_from_bfd_section (output_bfd, | 
|---|
| 1988 | sopd->output_section); | 
|---|
| 1989 | } | 
|---|
| 1990 |  | 
|---|
| 1991 | /* Initialize a .plt entry if requested.  */ | 
|---|
| 1992 | if (dyn_h && dyn_h->want_plt | 
|---|
| 1993 | && elf64_hppa_dynamic_symbol_p (dyn_h->h, info)) | 
|---|
| 1994 | { | 
|---|
| 1995 | bfd_vma value; | 
|---|
| 1996 | Elf_Internal_Rela rel; | 
|---|
| 1997 | bfd_byte *loc; | 
|---|
| 1998 |  | 
|---|
| 1999 | BFD_ASSERT (splt != NULL && spltrel != NULL) | 
|---|
| 2000 |  | 
|---|
| 2001 | /* We do not actually care about the value in the PLT entry | 
|---|
| 2002 | if we are creating a shared library and the symbol is | 
|---|
| 2003 | still undefined, we create a dynamic relocation to fill | 
|---|
| 2004 | in the correct value.  */ | 
|---|
| 2005 | if (info->shared && h->root.type == bfd_link_hash_undefined) | 
|---|
| 2006 | value = 0; | 
|---|
| 2007 | else | 
|---|
| 2008 | value = (h->root.u.def.value + h->root.u.def.section->vma); | 
|---|
| 2009 |  | 
|---|
| 2010 | /* Fill in the entry in the procedure linkage table. | 
|---|
| 2011 |  | 
|---|
| 2012 | The format of a plt entry is | 
|---|
| 2013 | <funcaddr> <__gp>. | 
|---|
| 2014 |  | 
|---|
| 2015 | plt_offset is the offset within the PLT section at which to | 
|---|
| 2016 | install the PLT entry. | 
|---|
| 2017 |  | 
|---|
| 2018 | We are modifying the in-memory PLT contents here, so we do not add | 
|---|
| 2019 | in the output_offset of the PLT section.  */ | 
|---|
| 2020 |  | 
|---|
| 2021 | bfd_put_64 (splt->owner, value, splt->contents + dyn_h->plt_offset); | 
|---|
| 2022 | value = _bfd_get_gp_value (splt->output_section->owner); | 
|---|
| 2023 | bfd_put_64 (splt->owner, value, splt->contents + dyn_h->plt_offset + 0x8); | 
|---|
| 2024 |  | 
|---|
| 2025 | /* Create a dynamic IPLT relocation for this entry. | 
|---|
| 2026 |  | 
|---|
| 2027 | We are creating a relocation in the output file's PLT section, | 
|---|
| 2028 | which is included within the DLT secton.  So we do need to include | 
|---|
| 2029 | the PLT's output_offset in the computation of the relocation's | 
|---|
| 2030 | address.  */ | 
|---|
| 2031 | rel.r_offset = (dyn_h->plt_offset + splt->output_offset | 
|---|
| 2032 | + splt->output_section->vma); | 
|---|
| 2033 | rel.r_info = ELF64_R_INFO (h->dynindx, R_PARISC_IPLT); | 
|---|
| 2034 | rel.r_addend = 0; | 
|---|
| 2035 |  | 
|---|
| 2036 | loc = spltrel->contents; | 
|---|
| 2037 | loc += spltrel->reloc_count++ * sizeof (Elf64_External_Rela); | 
|---|
| 2038 | bfd_elf64_swap_reloca_out (splt->output_section->owner, &rel, loc); | 
|---|
| 2039 | } | 
|---|
| 2040 |  | 
|---|
| 2041 | /* Initialize an external call stub entry if requested.  */ | 
|---|
| 2042 | if (dyn_h && dyn_h->want_stub | 
|---|
| 2043 | && elf64_hppa_dynamic_symbol_p (dyn_h->h, info)) | 
|---|
| 2044 | { | 
|---|
| 2045 | bfd_vma value; | 
|---|
| 2046 | int insn; | 
|---|
| 2047 | unsigned int max_offset; | 
|---|
| 2048 |  | 
|---|
| 2049 | BFD_ASSERT (stub != NULL) | 
|---|
| 2050 |  | 
|---|
| 2051 | /* Install the generic stub template. | 
|---|
| 2052 |  | 
|---|
| 2053 | We are modifying the contents of the stub section, so we do not | 
|---|
| 2054 | need to include the stub section's output_offset here.  */ | 
|---|
| 2055 | memcpy (stub->contents + dyn_h->stub_offset, plt_stub, sizeof (plt_stub)); | 
|---|
| 2056 |  | 
|---|
| 2057 | /* Fix up the first ldd instruction. | 
|---|
| 2058 |  | 
|---|
| 2059 | We are modifying the contents of the STUB section in memory, | 
|---|
| 2060 | so we do not need to include its output offset in this computation. | 
|---|
| 2061 |  | 
|---|
| 2062 | Note the plt_offset value is the value of the PLT entry relative to | 
|---|
| 2063 | the start of the PLT section.  These instructions will reference | 
|---|
| 2064 | data relative to the value of __gp, which may not necessarily have | 
|---|
| 2065 | the same address as the start of the PLT section. | 
|---|
| 2066 |  | 
|---|
| 2067 | gp_offset contains the offset of __gp within the PLT section.  */ | 
|---|
| 2068 | value = dyn_h->plt_offset - hppa_info->gp_offset; | 
|---|
| 2069 |  | 
|---|
| 2070 | insn = bfd_get_32 (stub->owner, stub->contents + dyn_h->stub_offset); | 
|---|
| 2071 | if (output_bfd->arch_info->mach >= 25) | 
|---|
| 2072 | { | 
|---|
| 2073 | /* Wide mode allows 16 bit offsets.  */ | 
|---|
| 2074 | max_offset = 32768; | 
|---|
| 2075 | insn &= ~ 0xfff1; | 
|---|
| 2076 | insn |= re_assemble_16 ((int) value); | 
|---|
| 2077 | } | 
|---|
| 2078 | else | 
|---|
| 2079 | { | 
|---|
| 2080 | max_offset = 8192; | 
|---|
| 2081 | insn &= ~ 0x3ff1; | 
|---|
| 2082 | insn |= re_assemble_14 ((int) value); | 
|---|
| 2083 | } | 
|---|
| 2084 |  | 
|---|
| 2085 | if ((value & 7) || value + max_offset >= 2*max_offset - 8) | 
|---|
| 2086 | { | 
|---|
| 2087 | (*_bfd_error_handler) (_("stub entry for %s cannot load .plt, dp offset = %ld"), | 
|---|
| 2088 | dyn_h->root.string, | 
|---|
| 2089 | (long) value); | 
|---|
| 2090 | return FALSE; | 
|---|
| 2091 | } | 
|---|
| 2092 |  | 
|---|
| 2093 | bfd_put_32 (stub->owner, (bfd_vma) insn, | 
|---|
| 2094 | stub->contents + dyn_h->stub_offset); | 
|---|
| 2095 |  | 
|---|
| 2096 | /* Fix up the second ldd instruction.  */ | 
|---|
| 2097 | value += 8; | 
|---|
| 2098 | insn = bfd_get_32 (stub->owner, stub->contents + dyn_h->stub_offset + 8); | 
|---|
| 2099 | if (output_bfd->arch_info->mach >= 25) | 
|---|
| 2100 | { | 
|---|
| 2101 | insn &= ~ 0xfff1; | 
|---|
| 2102 | insn |= re_assemble_16 ((int) value); | 
|---|
| 2103 | } | 
|---|
| 2104 | else | 
|---|
| 2105 | { | 
|---|
| 2106 | insn &= ~ 0x3ff1; | 
|---|
| 2107 | insn |= re_assemble_14 ((int) value); | 
|---|
| 2108 | } | 
|---|
| 2109 | bfd_put_32 (stub->owner, (bfd_vma) insn, | 
|---|
| 2110 | stub->contents + dyn_h->stub_offset + 8); | 
|---|
| 2111 | } | 
|---|
| 2112 |  | 
|---|
| 2113 | return TRUE; | 
|---|
| 2114 | } | 
|---|
| 2115 |  | 
|---|
| 2116 | /* The .opd section contains FPTRs for each function this file | 
|---|
| 2117 | exports.  Initialize the FPTR entries.  */ | 
|---|
| 2118 |  | 
|---|
| 2119 | static bfd_boolean | 
|---|
| 2120 | elf64_hppa_finalize_opd (dyn_h, data) | 
|---|
| 2121 | struct elf64_hppa_dyn_hash_entry *dyn_h; | 
|---|
| 2122 | PTR data; | 
|---|
| 2123 | { | 
|---|
| 2124 | struct bfd_link_info *info = (struct bfd_link_info *)data; | 
|---|
| 2125 | struct elf64_hppa_link_hash_table *hppa_info; | 
|---|
| 2126 | struct elf_link_hash_entry *h = dyn_h ? dyn_h->h : NULL; | 
|---|
| 2127 | asection *sopd; | 
|---|
| 2128 | asection *sopdrel; | 
|---|
| 2129 |  | 
|---|
| 2130 | hppa_info = elf64_hppa_hash_table (info); | 
|---|
| 2131 | sopd = hppa_info->opd_sec; | 
|---|
| 2132 | sopdrel = hppa_info->opd_rel_sec; | 
|---|
| 2133 |  | 
|---|
| 2134 | if (h && dyn_h->want_opd) | 
|---|
| 2135 | { | 
|---|
| 2136 | bfd_vma value; | 
|---|
| 2137 |  | 
|---|
| 2138 | /* The first two words of an .opd entry are zero. | 
|---|
| 2139 |  | 
|---|
| 2140 | We are modifying the contents of the OPD section in memory, so we | 
|---|
| 2141 | do not need to include its output offset in this computation.  */ | 
|---|
| 2142 | memset (sopd->contents + dyn_h->opd_offset, 0, 16); | 
|---|
| 2143 |  | 
|---|
| 2144 | value = (h->root.u.def.value | 
|---|
| 2145 | + h->root.u.def.section->output_section->vma | 
|---|
| 2146 | + h->root.u.def.section->output_offset); | 
|---|
| 2147 |  | 
|---|
| 2148 | /* The next word is the address of the function.  */ | 
|---|
| 2149 | bfd_put_64 (sopd->owner, value, sopd->contents + dyn_h->opd_offset + 16); | 
|---|
| 2150 |  | 
|---|
| 2151 | /* The last word is our local __gp value.  */ | 
|---|
| 2152 | value = _bfd_get_gp_value (sopd->output_section->owner); | 
|---|
| 2153 | bfd_put_64 (sopd->owner, value, sopd->contents + dyn_h->opd_offset + 24); | 
|---|
| 2154 | } | 
|---|
| 2155 |  | 
|---|
| 2156 | /* If we are generating a shared library, we must generate EPLT relocations | 
|---|
| 2157 | for each entry in the .opd, even for static functions (they may have | 
|---|
| 2158 | had their address taken).  */ | 
|---|
| 2159 | if (info->shared && dyn_h && dyn_h->want_opd) | 
|---|
| 2160 | { | 
|---|
| 2161 | Elf_Internal_Rela rel; | 
|---|
| 2162 | bfd_byte *loc; | 
|---|
| 2163 | int dynindx; | 
|---|
| 2164 |  | 
|---|
| 2165 | /* We may need to do a relocation against a local symbol, in | 
|---|
| 2166 | which case we have to look up it's dynamic symbol index off | 
|---|
| 2167 | the local symbol hash table.  */ | 
|---|
| 2168 | if (h && h->dynindx != -1) | 
|---|
| 2169 | dynindx = h->dynindx; | 
|---|
| 2170 | else | 
|---|
| 2171 | dynindx | 
|---|
| 2172 | = _bfd_elf_link_lookup_local_dynindx (info, dyn_h->owner, | 
|---|
| 2173 | dyn_h->sym_indx); | 
|---|
| 2174 |  | 
|---|
| 2175 | /* The offset of this relocation is the absolute address of the | 
|---|
| 2176 | .opd entry for this symbol.  */ | 
|---|
| 2177 | rel.r_offset = (dyn_h->opd_offset + sopd->output_offset | 
|---|
| 2178 | + sopd->output_section->vma); | 
|---|
| 2179 |  | 
|---|
| 2180 | /* If H is non-null, then we have an external symbol. | 
|---|
| 2181 |  | 
|---|
| 2182 | It is imperative that we use a different dynamic symbol for the | 
|---|
| 2183 | EPLT relocation if the symbol has global scope. | 
|---|
| 2184 |  | 
|---|
| 2185 | In the dynamic symbol table, the function symbol will have a value | 
|---|
| 2186 | which is address of the function's .opd entry. | 
|---|
| 2187 |  | 
|---|
| 2188 | Thus, we can not use that dynamic symbol for the EPLT relocation | 
|---|
| 2189 | (if we did, the data in the .opd would reference itself rather | 
|---|
| 2190 | than the actual address of the function).  Instead we have to use | 
|---|
| 2191 | a new dynamic symbol which has the same value as the original global | 
|---|
| 2192 | function symbol. | 
|---|
| 2193 |  | 
|---|
| 2194 | We prefix the original symbol with a "." and use the new symbol in | 
|---|
| 2195 | the EPLT relocation.  This new symbol has already been recorded in | 
|---|
| 2196 | the symbol table, we just have to look it up and use it. | 
|---|
| 2197 |  | 
|---|
| 2198 | We do not have such problems with static functions because we do | 
|---|
| 2199 | not make their addresses in the dynamic symbol table point to | 
|---|
| 2200 | the .opd entry.  Ultimately this should be safe since a static | 
|---|
| 2201 | function can not be directly referenced outside of its shared | 
|---|
| 2202 | library. | 
|---|
| 2203 |  | 
|---|
| 2204 | We do have to play similar games for FPTR relocations in shared | 
|---|
| 2205 | libraries, including those for static symbols.  See the FPTR | 
|---|
| 2206 | handling in elf64_hppa_finalize_dynreloc.  */ | 
|---|
| 2207 | if (h) | 
|---|
| 2208 | { | 
|---|
| 2209 | char *new_name; | 
|---|
| 2210 | struct elf_link_hash_entry *nh; | 
|---|
| 2211 |  | 
|---|
| 2212 | new_name = alloca (strlen (h->root.root.string) + 2); | 
|---|
| 2213 | new_name[0] = '.'; | 
|---|
| 2214 | strcpy (new_name + 1, h->root.root.string); | 
|---|
| 2215 |  | 
|---|
| 2216 | nh = elf_link_hash_lookup (elf_hash_table (info), | 
|---|
| 2217 | new_name, FALSE, FALSE, FALSE); | 
|---|
| 2218 |  | 
|---|
| 2219 | /* All we really want from the new symbol is its dynamic | 
|---|
| 2220 | symbol index.  */ | 
|---|
| 2221 | dynindx = nh->dynindx; | 
|---|
| 2222 | } | 
|---|
| 2223 |  | 
|---|
| 2224 | rel.r_addend = 0; | 
|---|
| 2225 | rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_EPLT); | 
|---|
| 2226 |  | 
|---|
| 2227 | loc = sopdrel->contents; | 
|---|
| 2228 | loc += sopdrel->reloc_count++ * sizeof (Elf64_External_Rela); | 
|---|
| 2229 | bfd_elf64_swap_reloca_out (sopd->output_section->owner, &rel, loc); | 
|---|
| 2230 | } | 
|---|
| 2231 | return TRUE; | 
|---|
| 2232 | } | 
|---|
| 2233 |  | 
|---|
| 2234 | /* The .dlt section contains addresses for items referenced through the | 
|---|
| 2235 | dlt.  Note that we can have a DLTIND relocation for a local symbol, thus | 
|---|
| 2236 | we can not depend on finish_dynamic_symbol to initialize the .dlt.  */ | 
|---|
| 2237 |  | 
|---|
| 2238 | static bfd_boolean | 
|---|
| 2239 | elf64_hppa_finalize_dlt (dyn_h, data) | 
|---|
| 2240 | struct elf64_hppa_dyn_hash_entry *dyn_h; | 
|---|
| 2241 | PTR data; | 
|---|
| 2242 | { | 
|---|
| 2243 | struct bfd_link_info *info = (struct bfd_link_info *)data; | 
|---|
| 2244 | struct elf64_hppa_link_hash_table *hppa_info; | 
|---|
| 2245 | asection *sdlt, *sdltrel; | 
|---|
| 2246 | struct elf_link_hash_entry *h = dyn_h ? dyn_h->h : NULL; | 
|---|
| 2247 |  | 
|---|
| 2248 | hppa_info = elf64_hppa_hash_table (info); | 
|---|
| 2249 |  | 
|---|
| 2250 | sdlt = hppa_info->dlt_sec; | 
|---|
| 2251 | sdltrel = hppa_info->dlt_rel_sec; | 
|---|
| 2252 |  | 
|---|
| 2253 | /* H/DYN_H may refer to a local variable and we know it's | 
|---|
| 2254 | address, so there is no need to create a relocation.  Just install | 
|---|
| 2255 | the proper value into the DLT, note this shortcut can not be | 
|---|
| 2256 | skipped when building a shared library.  */ | 
|---|
| 2257 | if (! info->shared && h && dyn_h->want_dlt) | 
|---|
| 2258 | { | 
|---|
| 2259 | bfd_vma value; | 
|---|
| 2260 |  | 
|---|
| 2261 | /* If we had an LTOFF_FPTR style relocation we want the DLT entry | 
|---|
| 2262 | to point to the FPTR entry in the .opd section. | 
|---|
| 2263 |  | 
|---|
| 2264 | We include the OPD's output offset in this computation as | 
|---|
| 2265 | we are referring to an absolute address in the resulting | 
|---|
| 2266 | object file.  */ | 
|---|
| 2267 | if (dyn_h->want_opd) | 
|---|
| 2268 | { | 
|---|
| 2269 | value = (dyn_h->opd_offset | 
|---|
| 2270 | + hppa_info->opd_sec->output_offset | 
|---|
| 2271 | + hppa_info->opd_sec->output_section->vma); | 
|---|
| 2272 | } | 
|---|
| 2273 | else if (h->root.u.def.section) | 
|---|
| 2274 | { | 
|---|
| 2275 | value = h->root.u.def.value + h->root.u.def.section->output_offset; | 
|---|
| 2276 | if (h->root.u.def.section->output_section) | 
|---|
| 2277 | value += h->root.u.def.section->output_section->vma; | 
|---|
| 2278 | else | 
|---|
| 2279 | value += h->root.u.def.section->vma; | 
|---|
| 2280 | } | 
|---|
| 2281 | else | 
|---|
| 2282 | /* We have an undefined function reference.  */ | 
|---|
| 2283 | value = 0; | 
|---|
| 2284 |  | 
|---|
| 2285 | /* We do not need to include the output offset of the DLT section | 
|---|
| 2286 | here because we are modifying the in-memory contents.  */ | 
|---|
| 2287 | bfd_put_64 (sdlt->owner, value, sdlt->contents + dyn_h->dlt_offset); | 
|---|
| 2288 | } | 
|---|
| 2289 |  | 
|---|
| 2290 | /* Create a relocation for the DLT entry assocated with this symbol. | 
|---|
| 2291 | When building a shared library the symbol does not have to be dynamic.  */ | 
|---|
| 2292 | if (dyn_h->want_dlt | 
|---|
| 2293 | && (elf64_hppa_dynamic_symbol_p (dyn_h->h, info) || info->shared)) | 
|---|
| 2294 | { | 
|---|
| 2295 | Elf_Internal_Rela rel; | 
|---|
| 2296 | bfd_byte *loc; | 
|---|
| 2297 | int dynindx; | 
|---|
| 2298 |  | 
|---|
| 2299 | /* We may need to do a relocation against a local symbol, in | 
|---|
| 2300 | which case we have to look up it's dynamic symbol index off | 
|---|
| 2301 | the local symbol hash table.  */ | 
|---|
| 2302 | if (h && h->dynindx != -1) | 
|---|
| 2303 | dynindx = h->dynindx; | 
|---|
| 2304 | else | 
|---|
| 2305 | dynindx | 
|---|
| 2306 | = _bfd_elf_link_lookup_local_dynindx (info, dyn_h->owner, | 
|---|
| 2307 | dyn_h->sym_indx); | 
|---|
| 2308 |  | 
|---|
| 2309 | /* Create a dynamic relocation for this entry.  Do include the output | 
|---|
| 2310 | offset of the DLT entry since we need an absolute address in the | 
|---|
| 2311 | resulting object file.  */ | 
|---|
| 2312 | rel.r_offset = (dyn_h->dlt_offset + sdlt->output_offset | 
|---|
| 2313 | + sdlt->output_section->vma); | 
|---|
| 2314 | if (h && h->type == STT_FUNC) | 
|---|
| 2315 | rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_FPTR64); | 
|---|
| 2316 | else | 
|---|
| 2317 | rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_DIR64); | 
|---|
| 2318 | rel.r_addend = 0; | 
|---|
| 2319 |  | 
|---|
| 2320 | loc = sdltrel->contents; | 
|---|
| 2321 | loc += sdltrel->reloc_count++ * sizeof (Elf64_External_Rela); | 
|---|
| 2322 | bfd_elf64_swap_reloca_out (sdlt->output_section->owner, &rel, loc); | 
|---|
| 2323 | } | 
|---|
| 2324 | return TRUE; | 
|---|
| 2325 | } | 
|---|
| 2326 |  | 
|---|
| 2327 | /* Finalize the dynamic relocations.  Specifically the FPTR relocations | 
|---|
| 2328 | for dynamic functions used to initialize static data.  */ | 
|---|
| 2329 |  | 
|---|
| 2330 | static bfd_boolean | 
|---|
| 2331 | elf64_hppa_finalize_dynreloc (dyn_h, data) | 
|---|
| 2332 | struct elf64_hppa_dyn_hash_entry *dyn_h; | 
|---|
| 2333 | PTR data; | 
|---|
| 2334 | { | 
|---|
| 2335 | struct bfd_link_info *info = (struct bfd_link_info *)data; | 
|---|
| 2336 | struct elf64_hppa_link_hash_table *hppa_info; | 
|---|
| 2337 | struct elf_link_hash_entry *h; | 
|---|
| 2338 | int dynamic_symbol; | 
|---|
| 2339 |  | 
|---|
| 2340 | dynamic_symbol = elf64_hppa_dynamic_symbol_p (dyn_h->h, info); | 
|---|
| 2341 |  | 
|---|
| 2342 | if (!dynamic_symbol && !info->shared) | 
|---|
| 2343 | return TRUE; | 
|---|
| 2344 |  | 
|---|
| 2345 | if (dyn_h->reloc_entries) | 
|---|
| 2346 | { | 
|---|
| 2347 | struct elf64_hppa_dyn_reloc_entry *rent; | 
|---|
| 2348 | int dynindx; | 
|---|
| 2349 |  | 
|---|
| 2350 | hppa_info = elf64_hppa_hash_table (info); | 
|---|
| 2351 | h = dyn_h->h; | 
|---|
| 2352 |  | 
|---|
| 2353 | /* We may need to do a relocation against a local symbol, in | 
|---|
| 2354 | which case we have to look up it's dynamic symbol index off | 
|---|
| 2355 | the local symbol hash table.  */ | 
|---|
| 2356 | if (h && h->dynindx != -1) | 
|---|
| 2357 | dynindx = h->dynindx; | 
|---|
| 2358 | else | 
|---|
| 2359 | dynindx | 
|---|
| 2360 | = _bfd_elf_link_lookup_local_dynindx (info, dyn_h->owner, | 
|---|
| 2361 | dyn_h->sym_indx); | 
|---|
| 2362 |  | 
|---|
| 2363 | for (rent = dyn_h->reloc_entries; rent; rent = rent->next) | 
|---|
| 2364 | { | 
|---|
| 2365 | Elf_Internal_Rela rel; | 
|---|
| 2366 | bfd_byte *loc; | 
|---|
| 2367 |  | 
|---|
| 2368 | /* Allocate one iff we are building a shared library, the relocation | 
|---|
| 2369 | isn't a R_PARISC_FPTR64, or we don't want an opd entry.  */ | 
|---|
| 2370 | if (!info->shared && rent->type == R_PARISC_FPTR64 && dyn_h->want_opd) | 
|---|
| 2371 | continue; | 
|---|
| 2372 |  | 
|---|
| 2373 | /* Create a dynamic relocation for this entry. | 
|---|
| 2374 |  | 
|---|
| 2375 | We need the output offset for the reloc's section because | 
|---|
| 2376 | we are creating an absolute address in the resulting object | 
|---|
| 2377 | file.  */ | 
|---|
| 2378 | rel.r_offset = (rent->offset + rent->sec->output_offset | 
|---|
| 2379 | + rent->sec->output_section->vma); | 
|---|
| 2380 |  | 
|---|
| 2381 | /* An FPTR64 relocation implies that we took the address of | 
|---|
| 2382 | a function and that the function has an entry in the .opd | 
|---|
| 2383 | section.  We want the FPTR64 relocation to reference the | 
|---|
| 2384 | entry in .opd. | 
|---|
| 2385 |  | 
|---|
| 2386 | We could munge the symbol value in the dynamic symbol table | 
|---|
| 2387 | (in fact we already do for functions with global scope) to point | 
|---|
| 2388 | to the .opd entry.  Then we could use that dynamic symbol in | 
|---|
| 2389 | this relocation. | 
|---|
| 2390 |  | 
|---|
| 2391 | Or we could do something sensible, not munge the symbol's | 
|---|
| 2392 | address and instead just use a different symbol to reference | 
|---|
| 2393 | the .opd entry.  At least that seems sensible until you | 
|---|
| 2394 | realize there's no local dynamic symbols we can use for that | 
|---|
| 2395 | purpose.  Thus the hair in the check_relocs routine. | 
|---|
| 2396 |  | 
|---|
| 2397 | We use a section symbol recorded by check_relocs as the | 
|---|
| 2398 | base symbol for the relocation.  The addend is the difference | 
|---|
| 2399 | between the section symbol and the address of the .opd entry.  */ | 
|---|
| 2400 | if (info->shared && rent->type == R_PARISC_FPTR64 && dyn_h->want_opd) | 
|---|
| 2401 | { | 
|---|
| 2402 | bfd_vma value, value2; | 
|---|
| 2403 |  | 
|---|
| 2404 | /* First compute the address of the opd entry for this symbol.  */ | 
|---|
| 2405 | value = (dyn_h->opd_offset | 
|---|
| 2406 | + hppa_info->opd_sec->output_section->vma | 
|---|
| 2407 | + hppa_info->opd_sec->output_offset); | 
|---|
| 2408 |  | 
|---|
| 2409 | /* Compute the value of the start of the section with | 
|---|
| 2410 | the relocation.  */ | 
|---|
| 2411 | value2 = (rent->sec->output_section->vma | 
|---|
| 2412 | + rent->sec->output_offset); | 
|---|
| 2413 |  | 
|---|
| 2414 | /* Compute the difference between the start of the section | 
|---|
| 2415 | with the relocation and the opd entry.  */ | 
|---|
| 2416 | value -= value2; | 
|---|
| 2417 |  | 
|---|
| 2418 | /* The result becomes the addend of the relocation.  */ | 
|---|
| 2419 | rel.r_addend = value; | 
|---|
| 2420 |  | 
|---|
| 2421 | /* The section symbol becomes the symbol for the dynamic | 
|---|
| 2422 | relocation.  */ | 
|---|
| 2423 | dynindx | 
|---|
| 2424 | = _bfd_elf_link_lookup_local_dynindx (info, | 
|---|
| 2425 | rent->sec->owner, | 
|---|
| 2426 | rent->sec_symndx); | 
|---|
| 2427 | } | 
|---|
| 2428 | else | 
|---|
| 2429 | rel.r_addend = rent->addend; | 
|---|
| 2430 |  | 
|---|
| 2431 | rel.r_info = ELF64_R_INFO (dynindx, rent->type); | 
|---|
| 2432 |  | 
|---|
| 2433 | loc = hppa_info->other_rel_sec->contents; | 
|---|
| 2434 | loc += (hppa_info->other_rel_sec->reloc_count++ | 
|---|
| 2435 | * sizeof (Elf64_External_Rela)); | 
|---|
| 2436 | bfd_elf64_swap_reloca_out (hppa_info->other_rel_sec->output_section->owner, | 
|---|
| 2437 | &rel, loc); | 
|---|
| 2438 | } | 
|---|
| 2439 | } | 
|---|
| 2440 |  | 
|---|
| 2441 | return TRUE; | 
|---|
| 2442 | } | 
|---|
| 2443 |  | 
|---|
| 2444 | /* Used to decide how to sort relocs in an optimal manner for the | 
|---|
| 2445 | dynamic linker, before writing them out.  */ | 
|---|
| 2446 |  | 
|---|
| 2447 | static enum elf_reloc_type_class | 
|---|
| 2448 | elf64_hppa_reloc_type_class (rela) | 
|---|
| 2449 | const Elf_Internal_Rela *rela; | 
|---|
| 2450 | { | 
|---|
| 2451 | if (ELF64_R_SYM (rela->r_info) == 0) | 
|---|
| 2452 | return reloc_class_relative; | 
|---|
| 2453 |  | 
|---|
| 2454 | switch ((int) ELF64_R_TYPE (rela->r_info)) | 
|---|
| 2455 | { | 
|---|
| 2456 | case R_PARISC_IPLT: | 
|---|
| 2457 | return reloc_class_plt; | 
|---|
| 2458 | case R_PARISC_COPY: | 
|---|
| 2459 | return reloc_class_copy; | 
|---|
| 2460 | default: | 
|---|
| 2461 | return reloc_class_normal; | 
|---|
| 2462 | } | 
|---|
| 2463 | } | 
|---|
| 2464 |  | 
|---|
| 2465 | /* Finish up the dynamic sections.  */ | 
|---|
| 2466 |  | 
|---|
| 2467 | static bfd_boolean | 
|---|
| 2468 | elf64_hppa_finish_dynamic_sections (output_bfd, info) | 
|---|
| 2469 | bfd *output_bfd; | 
|---|
| 2470 | struct bfd_link_info *info; | 
|---|
| 2471 | { | 
|---|
| 2472 | bfd *dynobj; | 
|---|
| 2473 | asection *sdyn; | 
|---|
| 2474 | struct elf64_hppa_link_hash_table *hppa_info; | 
|---|
| 2475 |  | 
|---|
| 2476 | hppa_info = elf64_hppa_hash_table (info); | 
|---|
| 2477 |  | 
|---|
| 2478 | /* Finalize the contents of the .opd section.  */ | 
|---|
| 2479 | elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table, | 
|---|
| 2480 | elf64_hppa_finalize_opd, | 
|---|
| 2481 | info); | 
|---|
| 2482 |  | 
|---|
| 2483 | elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table, | 
|---|
| 2484 | elf64_hppa_finalize_dynreloc, | 
|---|
| 2485 | info); | 
|---|
| 2486 |  | 
|---|
| 2487 | /* Finalize the contents of the .dlt section.  */ | 
|---|
| 2488 | dynobj = elf_hash_table (info)->dynobj; | 
|---|
| 2489 | /* Finalize the contents of the .dlt section.  */ | 
|---|
| 2490 | elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table, | 
|---|
| 2491 | elf64_hppa_finalize_dlt, | 
|---|
| 2492 | info); | 
|---|
| 2493 |  | 
|---|
| 2494 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); | 
|---|
| 2495 |  | 
|---|
| 2496 | if (elf_hash_table (info)->dynamic_sections_created) | 
|---|
| 2497 | { | 
|---|
| 2498 | Elf64_External_Dyn *dyncon, *dynconend; | 
|---|
| 2499 |  | 
|---|
| 2500 | BFD_ASSERT (sdyn != NULL); | 
|---|
| 2501 |  | 
|---|
| 2502 | dyncon = (Elf64_External_Dyn *) sdyn->contents; | 
|---|
| 2503 | dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size); | 
|---|
| 2504 | for (; dyncon < dynconend; dyncon++) | 
|---|
| 2505 | { | 
|---|
| 2506 | Elf_Internal_Dyn dyn; | 
|---|
| 2507 | asection *s; | 
|---|
| 2508 |  | 
|---|
| 2509 | bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn); | 
|---|
| 2510 |  | 
|---|
| 2511 | switch (dyn.d_tag) | 
|---|
| 2512 | { | 
|---|
| 2513 | default: | 
|---|
| 2514 | break; | 
|---|
| 2515 |  | 
|---|
| 2516 | case DT_HP_LOAD_MAP: | 
|---|
| 2517 | /* Compute the absolute address of 16byte scratchpad area | 
|---|
| 2518 | for the dynamic linker. | 
|---|
| 2519 |  | 
|---|
| 2520 | By convention the linker script will allocate the scratchpad | 
|---|
| 2521 | area at the start of the .data section.  So all we have to | 
|---|
| 2522 | to is find the start of the .data section.  */ | 
|---|
| 2523 | s = bfd_get_section_by_name (output_bfd, ".data"); | 
|---|
| 2524 | dyn.d_un.d_ptr = s->vma; | 
|---|
| 2525 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); | 
|---|
| 2526 | break; | 
|---|
| 2527 |  | 
|---|
| 2528 | case DT_PLTGOT: | 
|---|
| 2529 | /* HP's use PLTGOT to set the GOT register.  */ | 
|---|
| 2530 | dyn.d_un.d_ptr = _bfd_get_gp_value (output_bfd); | 
|---|
| 2531 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); | 
|---|
| 2532 | break; | 
|---|
| 2533 |  | 
|---|
| 2534 | case DT_JMPREL: | 
|---|
| 2535 | s = hppa_info->plt_rel_sec; | 
|---|
| 2536 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; | 
|---|
| 2537 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); | 
|---|
| 2538 | break; | 
|---|
| 2539 |  | 
|---|
| 2540 | case DT_PLTRELSZ: | 
|---|
| 2541 | s = hppa_info->plt_rel_sec; | 
|---|
| 2542 | dyn.d_un.d_val = s->_raw_size; | 
|---|
| 2543 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); | 
|---|
| 2544 | break; | 
|---|
| 2545 |  | 
|---|
| 2546 | case DT_RELA: | 
|---|
| 2547 | s = hppa_info->other_rel_sec; | 
|---|
| 2548 | if (! s || ! s->_raw_size) | 
|---|
| 2549 | s = hppa_info->dlt_rel_sec; | 
|---|
| 2550 | if (! s || ! s->_raw_size) | 
|---|
| 2551 | s = hppa_info->opd_rel_sec; | 
|---|
| 2552 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; | 
|---|
| 2553 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); | 
|---|
| 2554 | break; | 
|---|
| 2555 |  | 
|---|
| 2556 | case DT_RELASZ: | 
|---|
| 2557 | s = hppa_info->other_rel_sec; | 
|---|
| 2558 | dyn.d_un.d_val = s->_raw_size; | 
|---|
| 2559 | s = hppa_info->dlt_rel_sec; | 
|---|
| 2560 | dyn.d_un.d_val += s->_raw_size; | 
|---|
| 2561 | s = hppa_info->opd_rel_sec; | 
|---|
| 2562 | dyn.d_un.d_val += s->_raw_size; | 
|---|
| 2563 | /* There is some question about whether or not the size of | 
|---|
| 2564 | the PLT relocs should be included here.  HP's tools do | 
|---|
| 2565 | it, so we'll emulate them.  */ | 
|---|
| 2566 | s = hppa_info->plt_rel_sec; | 
|---|
| 2567 | dyn.d_un.d_val += s->_raw_size; | 
|---|
| 2568 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); | 
|---|
| 2569 | break; | 
|---|
| 2570 |  | 
|---|
| 2571 | } | 
|---|
| 2572 | } | 
|---|
| 2573 | } | 
|---|
| 2574 |  | 
|---|
| 2575 | return TRUE; | 
|---|
| 2576 | } | 
|---|
| 2577 |  | 
|---|
| 2578 | /* Return the number of additional phdrs we will need. | 
|---|
| 2579 |  | 
|---|
| 2580 | The generic ELF code only creates PT_PHDRs for executables.  The HP | 
|---|
| 2581 | dynamic linker requires PT_PHDRs for dynamic libraries too. | 
|---|
| 2582 |  | 
|---|
| 2583 | This routine indicates that the backend needs one additional program | 
|---|
| 2584 | header for that case. | 
|---|
| 2585 |  | 
|---|
| 2586 | Note we do not have access to the link info structure here, so we have | 
|---|
| 2587 | to guess whether or not we are building a shared library based on the | 
|---|
| 2588 | existence of a .interp section.  */ | 
|---|
| 2589 |  | 
|---|
| 2590 | static int | 
|---|
| 2591 | elf64_hppa_additional_program_headers (abfd) | 
|---|
| 2592 | bfd *abfd; | 
|---|
| 2593 | { | 
|---|
| 2594 | asection *s; | 
|---|
| 2595 |  | 
|---|
| 2596 | /* If we are creating a shared library, then we have to create a | 
|---|
| 2597 | PT_PHDR segment.  HP's dynamic linker chokes without it.  */ | 
|---|
| 2598 | s = bfd_get_section_by_name (abfd, ".interp"); | 
|---|
| 2599 | if (! s) | 
|---|
| 2600 | return 1; | 
|---|
| 2601 | return 0; | 
|---|
| 2602 | } | 
|---|
| 2603 |  | 
|---|
| 2604 | /* Allocate and initialize any program headers required by this | 
|---|
| 2605 | specific backend. | 
|---|
| 2606 |  | 
|---|
| 2607 | The generic ELF code only creates PT_PHDRs for executables.  The HP | 
|---|
| 2608 | dynamic linker requires PT_PHDRs for dynamic libraries too. | 
|---|
| 2609 |  | 
|---|
| 2610 | This allocates the PT_PHDR and initializes it in a manner suitable | 
|---|
| 2611 | for the HP linker. | 
|---|
| 2612 |  | 
|---|
| 2613 | Note we do not have access to the link info structure here, so we have | 
|---|
| 2614 | to guess whether or not we are building a shared library based on the | 
|---|
| 2615 | existence of a .interp section.  */ | 
|---|
| 2616 |  | 
|---|
| 2617 | static bfd_boolean | 
|---|
| 2618 | elf64_hppa_modify_segment_map (abfd) | 
|---|
| 2619 | bfd *abfd; | 
|---|
| 2620 | { | 
|---|
| 2621 | struct elf_segment_map *m; | 
|---|
| 2622 | asection *s; | 
|---|
| 2623 |  | 
|---|
| 2624 | s = bfd_get_section_by_name (abfd, ".interp"); | 
|---|
| 2625 | if (! s) | 
|---|
| 2626 | { | 
|---|
| 2627 | for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next) | 
|---|
| 2628 | if (m->p_type == PT_PHDR) | 
|---|
| 2629 | break; | 
|---|
| 2630 | if (m == NULL) | 
|---|
| 2631 | { | 
|---|
| 2632 | m = ((struct elf_segment_map *) | 
|---|
| 2633 | bfd_zalloc (abfd, (bfd_size_type) sizeof *m)); | 
|---|
| 2634 | if (m == NULL) | 
|---|
| 2635 | return FALSE; | 
|---|
| 2636 |  | 
|---|
| 2637 | m->p_type = PT_PHDR; | 
|---|
| 2638 | m->p_flags = PF_R | PF_X; | 
|---|
| 2639 | m->p_flags_valid = 1; | 
|---|
| 2640 | m->p_paddr_valid = 1; | 
|---|
| 2641 | m->includes_phdrs = 1; | 
|---|
| 2642 |  | 
|---|
| 2643 | m->next = elf_tdata (abfd)->segment_map; | 
|---|
| 2644 | elf_tdata (abfd)->segment_map = m; | 
|---|
| 2645 | } | 
|---|
| 2646 | } | 
|---|
| 2647 |  | 
|---|
| 2648 | for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next) | 
|---|
| 2649 | if (m->p_type == PT_LOAD) | 
|---|
| 2650 | { | 
|---|
| 2651 | unsigned int i; | 
|---|
| 2652 |  | 
|---|
| 2653 | for (i = 0; i < m->count; i++) | 
|---|
| 2654 | { | 
|---|
| 2655 | /* The code "hint" is not really a hint.  It is a requirement | 
|---|
| 2656 | for certain versions of the HP dynamic linker.  Worse yet, | 
|---|
| 2657 | it must be set even if the shared library does not have | 
|---|
| 2658 | any code in its "text" segment (thus the check for .hash | 
|---|
| 2659 | to catch this situation).  */ | 
|---|
| 2660 | if (m->sections[i]->flags & SEC_CODE | 
|---|
| 2661 | || (strcmp (m->sections[i]->name, ".hash") == 0)) | 
|---|
| 2662 | m->p_flags |= (PF_X | PF_HP_CODE); | 
|---|
| 2663 | } | 
|---|
| 2664 | } | 
|---|
| 2665 |  | 
|---|
| 2666 | return TRUE; | 
|---|
| 2667 | } | 
|---|
| 2668 |  | 
|---|
| 2669 | /* Called when writing out an object file to decide the type of a | 
|---|
| 2670 | symbol.  */ | 
|---|
| 2671 | static int | 
|---|
| 2672 | elf64_hppa_elf_get_symbol_type (elf_sym, type) | 
|---|
| 2673 | Elf_Internal_Sym *elf_sym; | 
|---|
| 2674 | int type; | 
|---|
| 2675 | { | 
|---|
| 2676 | if (ELF_ST_TYPE (elf_sym->st_info) == STT_PARISC_MILLI) | 
|---|
| 2677 | return STT_PARISC_MILLI; | 
|---|
| 2678 | else | 
|---|
| 2679 | return type; | 
|---|
| 2680 | } | 
|---|
| 2681 |  | 
|---|
| 2682 | /* The hash bucket size is the standard one, namely 4.  */ | 
|---|
| 2683 |  | 
|---|
| 2684 | const struct elf_size_info hppa64_elf_size_info = | 
|---|
| 2685 | { | 
|---|
| 2686 | sizeof (Elf64_External_Ehdr), | 
|---|
| 2687 | sizeof (Elf64_External_Phdr), | 
|---|
| 2688 | sizeof (Elf64_External_Shdr), | 
|---|
| 2689 | sizeof (Elf64_External_Rel), | 
|---|
| 2690 | sizeof (Elf64_External_Rela), | 
|---|
| 2691 | sizeof (Elf64_External_Sym), | 
|---|
| 2692 | sizeof (Elf64_External_Dyn), | 
|---|
| 2693 | sizeof (Elf_External_Note), | 
|---|
| 2694 | 4, | 
|---|
| 2695 | 1, | 
|---|
| 2696 | 64, 8, | 
|---|
| 2697 | ELFCLASS64, EV_CURRENT, | 
|---|
| 2698 | bfd_elf64_write_out_phdrs, | 
|---|
| 2699 | bfd_elf64_write_shdrs_and_ehdr, | 
|---|
| 2700 | bfd_elf64_write_relocs, | 
|---|
| 2701 | bfd_elf64_swap_symbol_in, | 
|---|
| 2702 | bfd_elf64_swap_symbol_out, | 
|---|
| 2703 | bfd_elf64_slurp_reloc_table, | 
|---|
| 2704 | bfd_elf64_slurp_symbol_table, | 
|---|
| 2705 | bfd_elf64_swap_dyn_in, | 
|---|
| 2706 | bfd_elf64_swap_dyn_out, | 
|---|
| 2707 | bfd_elf64_swap_reloc_in, | 
|---|
| 2708 | bfd_elf64_swap_reloc_out, | 
|---|
| 2709 | bfd_elf64_swap_reloca_in, | 
|---|
| 2710 | bfd_elf64_swap_reloca_out | 
|---|
| 2711 | }; | 
|---|
| 2712 |  | 
|---|
| 2713 | #define TARGET_BIG_SYM                  bfd_elf64_hppa_vec | 
|---|
| 2714 | #define TARGET_BIG_NAME                 "elf64-hppa" | 
|---|
| 2715 | #define ELF_ARCH                        bfd_arch_hppa | 
|---|
| 2716 | #define ELF_MACHINE_CODE                EM_PARISC | 
|---|
| 2717 | /* This is not strictly correct.  The maximum page size for PA2.0 is | 
|---|
| 2718 | 64M.  But everything still uses 4k.  */ | 
|---|
| 2719 | #define ELF_MAXPAGESIZE                 0x1000 | 
|---|
| 2720 | #define bfd_elf64_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup | 
|---|
| 2721 | #define bfd_elf64_bfd_is_local_label_name       elf_hppa_is_local_label_name | 
|---|
| 2722 | #define elf_info_to_howto               elf_hppa_info_to_howto | 
|---|
| 2723 | #define elf_info_to_howto_rel           elf_hppa_info_to_howto_rel | 
|---|
| 2724 |  | 
|---|
| 2725 | #define elf_backend_section_from_shdr   elf64_hppa_section_from_shdr | 
|---|
| 2726 | #define elf_backend_object_p            elf64_hppa_object_p | 
|---|
| 2727 | #define elf_backend_final_write_processing \ | 
|---|
| 2728 | elf_hppa_final_write_processing | 
|---|
| 2729 | #define elf_backend_fake_sections       elf_hppa_fake_sections | 
|---|
| 2730 | #define elf_backend_add_symbol_hook     elf_hppa_add_symbol_hook | 
|---|
| 2731 |  | 
|---|
| 2732 | #define elf_backend_relocate_section    elf_hppa_relocate_section | 
|---|
| 2733 |  | 
|---|
| 2734 | #define bfd_elf64_bfd_final_link        elf_hppa_final_link | 
|---|
| 2735 |  | 
|---|
| 2736 | #define elf_backend_create_dynamic_sections \ | 
|---|
| 2737 | elf64_hppa_create_dynamic_sections | 
|---|
| 2738 | #define elf_backend_post_process_headers        elf64_hppa_post_process_headers | 
|---|
| 2739 |  | 
|---|
| 2740 | #define elf_backend_adjust_dynamic_symbol \ | 
|---|
| 2741 | elf64_hppa_adjust_dynamic_symbol | 
|---|
| 2742 |  | 
|---|
| 2743 | #define elf_backend_size_dynamic_sections \ | 
|---|
| 2744 | elf64_hppa_size_dynamic_sections | 
|---|
| 2745 |  | 
|---|
| 2746 | #define elf_backend_finish_dynamic_symbol \ | 
|---|
| 2747 | elf64_hppa_finish_dynamic_symbol | 
|---|
| 2748 | #define elf_backend_finish_dynamic_sections \ | 
|---|
| 2749 | elf64_hppa_finish_dynamic_sections | 
|---|
| 2750 |  | 
|---|
| 2751 | /* Stuff for the BFD linker: */ | 
|---|
| 2752 | #define bfd_elf64_bfd_link_hash_table_create \ | 
|---|
| 2753 | elf64_hppa_hash_table_create | 
|---|
| 2754 |  | 
|---|
| 2755 | #define elf_backend_check_relocs \ | 
|---|
| 2756 | elf64_hppa_check_relocs | 
|---|
| 2757 |  | 
|---|
| 2758 | #define elf_backend_size_info \ | 
|---|
| 2759 | hppa64_elf_size_info | 
|---|
| 2760 |  | 
|---|
| 2761 | #define elf_backend_additional_program_headers \ | 
|---|
| 2762 | elf64_hppa_additional_program_headers | 
|---|
| 2763 |  | 
|---|
| 2764 | #define elf_backend_modify_segment_map \ | 
|---|
| 2765 | elf64_hppa_modify_segment_map | 
|---|
| 2766 |  | 
|---|
| 2767 | #define elf_backend_link_output_symbol_hook \ | 
|---|
| 2768 | elf64_hppa_link_output_symbol_hook | 
|---|
| 2769 |  | 
|---|
| 2770 | #define elf_backend_want_got_plt        0 | 
|---|
| 2771 | #define elf_backend_plt_readonly        0 | 
|---|
| 2772 | #define elf_backend_want_plt_sym        0 | 
|---|
| 2773 | #define elf_backend_got_header_size     0 | 
|---|
| 2774 | #define elf_backend_plt_header_size     0 | 
|---|
| 2775 | #define elf_backend_type_change_ok      TRUE | 
|---|
| 2776 | #define elf_backend_get_symbol_type     elf64_hppa_elf_get_symbol_type | 
|---|
| 2777 | #define elf_backend_reloc_type_class    elf64_hppa_reloc_type_class | 
|---|
| 2778 | #define elf_backend_rela_normal         1 | 
|---|
| 2779 |  | 
|---|
| 2780 | #include "elf64-target.h" | 
|---|
| 2781 |  | 
|---|
| 2782 | #undef TARGET_BIG_SYM | 
|---|
| 2783 | #define TARGET_BIG_SYM                  bfd_elf64_hppa_linux_vec | 
|---|
| 2784 | #undef TARGET_BIG_NAME | 
|---|
| 2785 | #define TARGET_BIG_NAME                 "elf64-hppa-linux" | 
|---|
| 2786 |  | 
|---|
| 2787 | #define INCLUDED_TARGET_FILE 1 | 
|---|
| 2788 | #include "elf64-target.h" | 
|---|