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