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