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