/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-2025 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 | | /* Target vectors for HPUX and non-HPUX versions of HPPA ELF binaries. */ |
31 | | extern const bfd_target hppa_elf64_vec; |
32 | | extern const bfd_target hppa_elf64_linux_vec; |
33 | | |
34 | | #define ARCH_SIZE 64 |
35 | | |
36 | 0 | #define PLT_ENTRY_SIZE 0x10 |
37 | 0 | #define DLT_ENTRY_SIZE 0x8 |
38 | 0 | #define OPD_ENTRY_SIZE 0x20 |
39 | | |
40 | 0 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/pa20_64/dld.sl" |
41 | | |
42 | | /* The stub is supposed to load the target address and target's DP |
43 | | value out of the PLT, then do an external branch to the target |
44 | | address. |
45 | | |
46 | | LDD PLTOFF(%r27),%r1 |
47 | | BVE (%r1) |
48 | | LDD PLTOFF+8(%r27),%r27 |
49 | | |
50 | | Note that we must use the LDD with a 14 bit displacement, not the one |
51 | | with a 5 bit displacement. */ |
52 | | static char plt_stub[] = {0x53, 0x61, 0x00, 0x00, 0xe8, 0x20, 0xd0, 0x00, |
53 | | 0x53, 0x7b, 0x00, 0x00 }; |
54 | | |
55 | | struct elf64_hppa_link_hash_entry |
56 | | { |
57 | | struct elf_link_hash_entry eh; |
58 | | |
59 | | /* Offsets for this symbol in various linker sections. */ |
60 | | bfd_vma dlt_offset; |
61 | | bfd_vma plt_offset; |
62 | | bfd_vma opd_offset; |
63 | | bfd_vma stub_offset; |
64 | | |
65 | | /* The index of the (possibly local) symbol in the input bfd and its |
66 | | associated BFD. Needed so that we can have relocs against local |
67 | | symbols in shared libraries. */ |
68 | | long sym_indx; |
69 | | bfd *owner; |
70 | | |
71 | | /* Dynamic symbols may need to have two different values. One for |
72 | | the dynamic symbol table, one for the normal symbol table. |
73 | | |
74 | | In such cases we store the symbol's real value and section |
75 | | index here so we can restore the real value before we write |
76 | | the normal symbol table. */ |
77 | | bfd_vma st_value; |
78 | | int st_shndx; |
79 | | |
80 | | /* Used to count non-got, non-plt relocations for delayed sizing |
81 | | of relocation sections. */ |
82 | | struct elf64_hppa_dyn_reloc_entry |
83 | | { |
84 | | /* Next relocation in the chain. */ |
85 | | struct elf64_hppa_dyn_reloc_entry *next; |
86 | | |
87 | | /* The type of the relocation. */ |
88 | | int type; |
89 | | |
90 | | /* The input section of the relocation. */ |
91 | | asection *sec; |
92 | | |
93 | | /* Number of relocs copied in this section. */ |
94 | | bfd_size_type count; |
95 | | |
96 | | /* The index of the section symbol for the input section of |
97 | | the relocation. Only needed when building shared libraries. */ |
98 | | int sec_symndx; |
99 | | |
100 | | /* The offset within the input section of the relocation. */ |
101 | | bfd_vma offset; |
102 | | |
103 | | /* The addend for the relocation. */ |
104 | | bfd_vma addend; |
105 | | |
106 | | } *reloc_entries; |
107 | | |
108 | | /* Nonzero if this symbol needs an entry in one of the linker |
109 | | sections. */ |
110 | | unsigned want_dlt; |
111 | | unsigned want_plt; |
112 | | unsigned want_opd; |
113 | | unsigned want_stub; |
114 | | }; |
115 | | |
116 | | struct elf64_hppa_link_hash_table |
117 | | { |
118 | | struct elf_link_hash_table root; |
119 | | |
120 | | /* Shortcuts to get to the various linker defined sections. */ |
121 | | asection *dlt_sec; |
122 | | asection *dlt_rel_sec; |
123 | | asection *opd_sec; |
124 | | asection *opd_rel_sec; |
125 | | asection *other_rel_sec; |
126 | | |
127 | | /* Offset of __gp within .plt section. When the PLT gets large we want |
128 | | to slide __gp into the PLT section so that we can continue to use |
129 | | single DP relative instructions to load values out of the PLT. */ |
130 | | bfd_vma gp_offset; |
131 | | |
132 | | /* Note this is not strictly correct. We should create a stub section for |
133 | | each input section with calls. The stub section should be placed before |
134 | | the section with the call. */ |
135 | | asection *stub_sec; |
136 | | |
137 | | bfd_vma text_segment_base; |
138 | | bfd_vma data_segment_base; |
139 | | |
140 | | /* We build tables to map from an input section back to its |
141 | | symbol index. This is the BFD for which we currently have |
142 | | a map. */ |
143 | | bfd *section_syms_bfd; |
144 | | |
145 | | /* Array of symbol numbers for each input section attached to the |
146 | | current BFD. */ |
147 | | int *section_syms; |
148 | | }; |
149 | | |
150 | | #define hppa_link_hash_table(p) \ |
151 | 0 | ((is_elf_hash_table ((p)->hash) \ |
152 | 0 | && elf_hash_table_id (elf_hash_table (p)) == HPPA64_ELF_DATA) \ |
153 | 0 | ? (struct elf64_hppa_link_hash_table *) (p)->hash : NULL) |
154 | | |
155 | | #define hppa_elf_hash_entry(ent) \ |
156 | 0 | ((struct elf64_hppa_link_hash_entry *)(ent)) |
157 | | |
158 | | #define eh_name(eh) \ |
159 | 0 | (eh ? eh->root.root.string : "<undef>") |
160 | | |
161 | | typedef struct bfd_hash_entry *(*new_hash_entry_func) |
162 | | (struct bfd_hash_entry *, struct bfd_hash_table *, const char *); |
163 | | |
164 | | static struct bfd_link_hash_table *elf64_hppa_hash_table_create |
165 | | (bfd *abfd); |
166 | | |
167 | | /* This must follow the definitions of the various derived linker |
168 | | hash tables and shared functions. */ |
169 | | #include "elf-hppa.h" |
170 | | |
171 | | static bool elf64_hppa_object_p |
172 | | (bfd *); |
173 | | |
174 | | static bool elf64_hppa_create_dynamic_sections |
175 | | (bfd *, struct bfd_link_info *); |
176 | | |
177 | | static bool elf64_hppa_adjust_dynamic_symbol |
178 | | (struct bfd_link_info *, struct elf_link_hash_entry *); |
179 | | |
180 | | static bool elf64_hppa_mark_milli_and_exported_functions |
181 | | (struct elf_link_hash_entry *, void *); |
182 | | |
183 | | static int elf64_hppa_link_output_symbol_hook |
184 | | (struct bfd_link_info *, const char *, Elf_Internal_Sym *, |
185 | | asection *, struct elf_link_hash_entry *); |
186 | | |
187 | | static bool elf64_hppa_finish_dynamic_symbol |
188 | | (bfd *, struct bfd_link_info *, |
189 | | struct elf_link_hash_entry *, Elf_Internal_Sym *); |
190 | | |
191 | | static bool elf64_hppa_finish_dynamic_sections |
192 | | (bfd *, struct bfd_link_info *); |
193 | | |
194 | | static bool elf64_hppa_check_relocs |
195 | | (bfd *, struct bfd_link_info *, |
196 | | asection *, const Elf_Internal_Rela *); |
197 | | |
198 | | static bool elf64_hppa_dynamic_symbol_p |
199 | | (struct elf_link_hash_entry *, struct bfd_link_info *); |
200 | | |
201 | | static bool elf64_hppa_mark_exported_functions |
202 | | (struct elf_link_hash_entry *, void *); |
203 | | |
204 | | static bool elf64_hppa_finalize_opd |
205 | | (struct elf_link_hash_entry *, void *); |
206 | | |
207 | | static bool elf64_hppa_finalize_dlt |
208 | | (struct elf_link_hash_entry *, void *); |
209 | | |
210 | | static bool allocate_global_data_dlt |
211 | | (struct elf_link_hash_entry *, void *); |
212 | | |
213 | | static bool allocate_global_data_plt |
214 | | (struct elf_link_hash_entry *, void *); |
215 | | |
216 | | static bool allocate_global_data_stub |
217 | | (struct elf_link_hash_entry *, void *); |
218 | | |
219 | | static bool allocate_global_data_opd |
220 | | (struct elf_link_hash_entry *, void *); |
221 | | |
222 | | static bool get_reloc_section |
223 | | (bfd *, struct elf64_hppa_link_hash_table *, asection *); |
224 | | |
225 | | static bool count_dyn_reloc |
226 | | (bfd *, struct elf64_hppa_link_hash_entry *, |
227 | | int, asection *, int, bfd_vma, bfd_vma); |
228 | | |
229 | | static bool allocate_dynrel_entries |
230 | | (struct elf_link_hash_entry *, void *); |
231 | | |
232 | | static bool elf64_hppa_finalize_dynreloc |
233 | | (struct elf_link_hash_entry *, void *); |
234 | | |
235 | | static bool get_opd |
236 | | (bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *); |
237 | | |
238 | | static bool get_plt |
239 | | (bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *); |
240 | | |
241 | | static bool get_dlt |
242 | | (bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *); |
243 | | |
244 | | static bool get_stub |
245 | | (bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *); |
246 | | |
247 | | static int elf64_hppa_elf_get_symbol_type |
248 | | (Elf_Internal_Sym *, int); |
249 | | |
250 | | /* Initialize an entry in the link hash table. */ |
251 | | |
252 | | static struct bfd_hash_entry * |
253 | | hppa64_link_hash_newfunc (struct bfd_hash_entry *entry, |
254 | | struct bfd_hash_table *table, |
255 | | const char *string) |
256 | 0 | { |
257 | | /* Allocate the structure if it has not already been allocated by a |
258 | | subclass. */ |
259 | 0 | if (entry == NULL) |
260 | 0 | { |
261 | 0 | entry = bfd_hash_allocate (table, |
262 | 0 | sizeof (struct elf64_hppa_link_hash_entry)); |
263 | 0 | if (entry == NULL) |
264 | 0 | return entry; |
265 | 0 | } |
266 | | |
267 | | /* Call the allocation method of the superclass. */ |
268 | 0 | entry = _bfd_elf_link_hash_newfunc (entry, table, string); |
269 | 0 | if (entry != NULL) |
270 | 0 | { |
271 | 0 | struct elf64_hppa_link_hash_entry *hh; |
272 | | |
273 | | /* Initialize our local data. All zeros. */ |
274 | 0 | hh = hppa_elf_hash_entry (entry); |
275 | 0 | memset (&hh->dlt_offset, 0, |
276 | 0 | (sizeof (struct elf64_hppa_link_hash_entry) |
277 | 0 | - offsetof (struct elf64_hppa_link_hash_entry, dlt_offset))); |
278 | 0 | } |
279 | |
|
280 | 0 | return entry; |
281 | 0 | } |
282 | | |
283 | | /* Create the derived linker hash table. The PA64 ELF port uses this |
284 | | derived hash table to keep information specific to the PA ElF |
285 | | linker (without using static variables). */ |
286 | | |
287 | | static struct bfd_link_hash_table* |
288 | | elf64_hppa_hash_table_create (bfd *abfd) |
289 | 0 | { |
290 | 0 | struct elf64_hppa_link_hash_table *htab; |
291 | 0 | size_t amt = sizeof (*htab); |
292 | |
|
293 | 0 | htab = bfd_zmalloc (amt); |
294 | 0 | if (htab == NULL) |
295 | 0 | return NULL; |
296 | | |
297 | 0 | if (!_bfd_elf_link_hash_table_init (&htab->root, abfd, |
298 | 0 | hppa64_link_hash_newfunc, |
299 | 0 | sizeof (struct elf64_hppa_link_hash_entry))) |
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 | 12 | { |
318 | 12 | Elf_Internal_Ehdr * i_ehdrp; |
319 | 12 | unsigned int flags; |
320 | | |
321 | 12 | i_ehdrp = elf_elfheader (abfd); |
322 | 12 | if (abfd->xvec == & hppa_elf64_linux_vec) |
323 | 6 | { |
324 | | /* GCC on hppa-linux produces binaries with OSABI=GNU, |
325 | | but the kernel produces corefiles with OSABI=SysV. */ |
326 | 6 | if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_GNU |
327 | 6 | && i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_NONE) /* aka SYSV */ |
328 | 0 | return false; |
329 | 6 | } |
330 | 6 | else |
331 | 6 | { |
332 | | /* HPUX produces binaries with OSABI=HPUX, |
333 | | but the kernel produces corefiles with OSABI=SysV. */ |
334 | 6 | if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_HPUX |
335 | 6 | && i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_NONE) /* aka SYSV */ |
336 | 0 | return false; |
337 | 6 | } |
338 | | |
339 | 12 | flags = i_ehdrp->e_flags; |
340 | 12 | switch (flags & (EF_PARISC_ARCH | EF_PARISC_WIDE)) |
341 | 12 | { |
342 | 2 | case EFA_PARISC_1_0: |
343 | 2 | return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 10); |
344 | 2 | case EFA_PARISC_1_1: |
345 | 2 | return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 11); |
346 | 2 | case EFA_PARISC_2_0: |
347 | 2 | if (i_ehdrp->e_ident[EI_CLASS] == ELFCLASS64) |
348 | 2 | 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 | 2 | case EFA_PARISC_2_0 | EF_PARISC_WIDE: |
352 | 2 | return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 25); |
353 | 12 | } |
354 | | /* Don't be fussy. */ |
355 | 4 | return true; |
356 | 12 | } |
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_late_size_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 | if (dynobj == NULL) |
1538 | 0 | return true; |
1539 | | |
1540 | | /* Mark each function this program exports so that we will allocate |
1541 | | space in the .opd section for each function's FPTR. If we are |
1542 | | creating dynamic sections, change the dynamic index of millicode |
1543 | | symbols to -1 and remove them from the string table for .dynstr. |
1544 | | |
1545 | | We have to traverse the main linker hash table since we have to |
1546 | | find functions which may not have been mentioned in any relocs. */ |
1547 | 0 | elf_link_hash_traverse (&hppa_info->root, |
1548 | 0 | (hppa_info->root.dynamic_sections_created |
1549 | 0 | ? elf64_hppa_mark_milli_and_exported_functions |
1550 | 0 | : elf64_hppa_mark_exported_functions), |
1551 | 0 | info); |
1552 | |
|
1553 | 0 | if (hppa_info->root.dynamic_sections_created) |
1554 | 0 | { |
1555 | | /* Set the contents of the .interp section to the interpreter. */ |
1556 | 0 | if (bfd_link_executable (info) && !info->nointerp) |
1557 | 0 | { |
1558 | 0 | sec = bfd_get_linker_section (dynobj, ".interp"); |
1559 | 0 | BFD_ASSERT (sec != NULL); |
1560 | 0 | sec->size = sizeof ELF_DYNAMIC_INTERPRETER; |
1561 | 0 | sec->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; |
1562 | 0 | sec->alloced = 1; |
1563 | 0 | } |
1564 | 0 | } |
1565 | 0 | else |
1566 | 0 | { |
1567 | | /* We may have created entries in the .rela.got section. |
1568 | | However, if we are not creating the dynamic sections, we will |
1569 | | not actually use these entries. Reset the size of .rela.dlt, |
1570 | | which will cause it to get stripped from the output file |
1571 | | below. */ |
1572 | 0 | sec = hppa_info->dlt_rel_sec; |
1573 | 0 | if (sec != NULL) |
1574 | 0 | sec->size = 0; |
1575 | 0 | } |
1576 | | |
1577 | | /* Set up DLT, PLT and OPD offsets for local syms, and space for local |
1578 | | dynamic relocs. */ |
1579 | 0 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) |
1580 | 0 | { |
1581 | 0 | bfd_signed_vma *local_dlt; |
1582 | 0 | bfd_signed_vma *end_local_dlt; |
1583 | 0 | bfd_signed_vma *local_plt; |
1584 | 0 | bfd_signed_vma *end_local_plt; |
1585 | 0 | bfd_signed_vma *local_opd; |
1586 | 0 | bfd_signed_vma *end_local_opd; |
1587 | 0 | bfd_size_type locsymcount; |
1588 | 0 | Elf_Internal_Shdr *symtab_hdr; |
1589 | 0 | asection *srel; |
1590 | |
|
1591 | 0 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) |
1592 | 0 | continue; |
1593 | | |
1594 | 0 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) |
1595 | 0 | { |
1596 | 0 | struct elf64_hppa_dyn_reloc_entry *hdh_p; |
1597 | |
|
1598 | 0 | for (hdh_p = ((struct elf64_hppa_dyn_reloc_entry *) |
1599 | 0 | elf_section_data (sec)->local_dynrel); |
1600 | 0 | hdh_p != NULL; |
1601 | 0 | hdh_p = hdh_p->next) |
1602 | 0 | { |
1603 | 0 | if (!bfd_is_abs_section (hdh_p->sec) |
1604 | 0 | && bfd_is_abs_section (hdh_p->sec->output_section)) |
1605 | 0 | { |
1606 | | /* Input section has been discarded, either because |
1607 | | it is a copy of a linkonce section or due to |
1608 | | linker script /DISCARD/, so we'll be discarding |
1609 | | the relocs too. */ |
1610 | 0 | } |
1611 | 0 | else if (hdh_p->count != 0) |
1612 | 0 | { |
1613 | 0 | srel = elf_section_data (hdh_p->sec)->sreloc; |
1614 | 0 | srel->size += hdh_p->count * sizeof (Elf64_External_Rela); |
1615 | 0 | if ((hdh_p->sec->output_section->flags & SEC_READONLY) != 0) |
1616 | 0 | info->flags |= DF_TEXTREL; |
1617 | 0 | } |
1618 | 0 | } |
1619 | 0 | } |
1620 | |
|
1621 | 0 | local_dlt = elf_local_got_refcounts (ibfd); |
1622 | 0 | if (!local_dlt) |
1623 | 0 | continue; |
1624 | | |
1625 | 0 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; |
1626 | 0 | locsymcount = symtab_hdr->sh_info; |
1627 | 0 | end_local_dlt = local_dlt + locsymcount; |
1628 | 0 | sec = hppa_info->dlt_sec; |
1629 | 0 | srel = hppa_info->dlt_rel_sec; |
1630 | 0 | for (; local_dlt < end_local_dlt; ++local_dlt) |
1631 | 0 | { |
1632 | 0 | if (*local_dlt > 0) |
1633 | 0 | { |
1634 | 0 | *local_dlt = sec->size; |
1635 | 0 | sec->size += DLT_ENTRY_SIZE; |
1636 | 0 | if (bfd_link_pic (info)) |
1637 | 0 | { |
1638 | 0 | srel->size += sizeof (Elf64_External_Rela); |
1639 | 0 | } |
1640 | 0 | } |
1641 | 0 | else |
1642 | 0 | *local_dlt = (bfd_vma) -1; |
1643 | 0 | } |
1644 | |
|
1645 | 0 | local_plt = end_local_dlt; |
1646 | 0 | end_local_plt = local_plt + locsymcount; |
1647 | 0 | if (! hppa_info->root.dynamic_sections_created) |
1648 | 0 | { |
1649 | | /* Won't be used, but be safe. */ |
1650 | 0 | for (; local_plt < end_local_plt; ++local_plt) |
1651 | 0 | *local_plt = (bfd_vma) -1; |
1652 | 0 | } |
1653 | 0 | else |
1654 | 0 | { |
1655 | 0 | sec = hppa_info->root.splt; |
1656 | 0 | srel = hppa_info->root.srelplt; |
1657 | 0 | for (; local_plt < end_local_plt; ++local_plt) |
1658 | 0 | { |
1659 | 0 | if (*local_plt > 0) |
1660 | 0 | { |
1661 | 0 | *local_plt = sec->size; |
1662 | 0 | sec->size += PLT_ENTRY_SIZE; |
1663 | 0 | if (bfd_link_pic (info)) |
1664 | 0 | srel->size += sizeof (Elf64_External_Rela); |
1665 | 0 | } |
1666 | 0 | else |
1667 | 0 | *local_plt = (bfd_vma) -1; |
1668 | 0 | } |
1669 | 0 | } |
1670 | |
|
1671 | 0 | local_opd = end_local_plt; |
1672 | 0 | end_local_opd = local_opd + locsymcount; |
1673 | 0 | if (! hppa_info->root.dynamic_sections_created) |
1674 | 0 | { |
1675 | | /* Won't be used, but be safe. */ |
1676 | 0 | for (; local_opd < end_local_opd; ++local_opd) |
1677 | 0 | *local_opd = (bfd_vma) -1; |
1678 | 0 | } |
1679 | 0 | else |
1680 | 0 | { |
1681 | 0 | sec = hppa_info->opd_sec; |
1682 | 0 | srel = hppa_info->opd_rel_sec; |
1683 | 0 | for (; local_opd < end_local_opd; ++local_opd) |
1684 | 0 | { |
1685 | 0 | if (*local_opd > 0) |
1686 | 0 | { |
1687 | 0 | *local_opd = sec->size; |
1688 | 0 | sec->size += OPD_ENTRY_SIZE; |
1689 | 0 | if (bfd_link_pic (info)) |
1690 | 0 | srel->size += sizeof (Elf64_External_Rela); |
1691 | 0 | } |
1692 | 0 | else |
1693 | 0 | *local_opd = (bfd_vma) -1; |
1694 | 0 | } |
1695 | 0 | } |
1696 | 0 | } |
1697 | | |
1698 | | /* Allocate the GOT entries. */ |
1699 | |
|
1700 | 0 | data.info = info; |
1701 | 0 | if (hppa_info->dlt_sec) |
1702 | 0 | { |
1703 | 0 | data.ofs = hppa_info->dlt_sec->size; |
1704 | 0 | elf_link_hash_traverse (&hppa_info->root, |
1705 | 0 | allocate_global_data_dlt, &data); |
1706 | 0 | hppa_info->dlt_sec->size = data.ofs; |
1707 | 0 | } |
1708 | |
|
1709 | 0 | if (hppa_info->root.splt) |
1710 | 0 | { |
1711 | 0 | data.ofs = hppa_info->root.splt->size; |
1712 | 0 | elf_link_hash_traverse (&hppa_info->root, |
1713 | 0 | allocate_global_data_plt, &data); |
1714 | 0 | hppa_info->root.splt->size = data.ofs; |
1715 | 0 | } |
1716 | |
|
1717 | 0 | if (hppa_info->stub_sec) |
1718 | 0 | { |
1719 | 0 | data.ofs = 0x0; |
1720 | 0 | elf_link_hash_traverse (&hppa_info->root, |
1721 | 0 | allocate_global_data_stub, &data); |
1722 | 0 | hppa_info->stub_sec->size = data.ofs; |
1723 | 0 | } |
1724 | | |
1725 | | /* Allocate space for entries in the .opd section. */ |
1726 | 0 | if (hppa_info->opd_sec) |
1727 | 0 | { |
1728 | 0 | data.ofs = hppa_info->opd_sec->size; |
1729 | 0 | elf_link_hash_traverse (&hppa_info->root, |
1730 | 0 | allocate_global_data_opd, &data); |
1731 | 0 | hppa_info->opd_sec->size = data.ofs; |
1732 | 0 | } |
1733 | | |
1734 | | /* Now allocate space for dynamic relocations, if necessary. */ |
1735 | 0 | if (hppa_info->root.dynamic_sections_created) |
1736 | 0 | elf_link_hash_traverse (&hppa_info->root, |
1737 | 0 | allocate_dynrel_entries, &data); |
1738 | | |
1739 | | /* The sizes of all the sections are set. Allocate memory for them. */ |
1740 | 0 | relocs = false; |
1741 | 0 | for (sec = dynobj->sections; sec != NULL; sec = sec->next) |
1742 | 0 | { |
1743 | 0 | const char *name; |
1744 | |
|
1745 | 0 | if ((sec->flags & SEC_LINKER_CREATED) == 0) |
1746 | 0 | continue; |
1747 | | |
1748 | | /* It's OK to base decisions on the section name, because none |
1749 | | of the dynobj section names depend upon the input files. */ |
1750 | 0 | name = bfd_section_name (sec); |
1751 | |
|
1752 | 0 | if (strcmp (name, ".plt") == 0) |
1753 | 0 | { |
1754 | | /* Remember whether there is a PLT. */ |
1755 | 0 | ; |
1756 | 0 | } |
1757 | 0 | else if (strcmp (name, ".opd") == 0 |
1758 | 0 | || startswith (name, ".dlt") |
1759 | 0 | || strcmp (name, ".stub") == 0 |
1760 | 0 | || strcmp (name, ".got") == 0) |
1761 | 0 | { |
1762 | | /* Strip this section if we don't need it; see the comment below. */ |
1763 | 0 | } |
1764 | 0 | else if (startswith (name, ".rela")) |
1765 | 0 | { |
1766 | 0 | if (sec->size != 0) |
1767 | 0 | { |
1768 | | /* Remember whether there are any reloc sections other |
1769 | | than .rela.plt. */ |
1770 | 0 | if (strcmp (name, ".rela.plt") != 0) |
1771 | 0 | relocs = true; |
1772 | | |
1773 | | /* We use the reloc_count field as a counter if we need |
1774 | | to copy relocs into the output file. */ |
1775 | 0 | sec->reloc_count = 0; |
1776 | 0 | } |
1777 | 0 | } |
1778 | 0 | else |
1779 | 0 | { |
1780 | | /* It's not one of our sections, so don't allocate space. */ |
1781 | 0 | continue; |
1782 | 0 | } |
1783 | | |
1784 | 0 | if (sec->size == 0) |
1785 | 0 | { |
1786 | | /* If we don't need this section, strip it from the |
1787 | | output file. This is mostly to handle .rela.bss and |
1788 | | .rela.plt. We must create both sections in |
1789 | | create_dynamic_sections, because they must be created |
1790 | | before the linker maps input sections to output |
1791 | | sections. The linker does that before |
1792 | | adjust_dynamic_symbol is called, and it is that |
1793 | | function which decides whether anything needs to go |
1794 | | into these sections. */ |
1795 | 0 | sec->flags |= SEC_EXCLUDE; |
1796 | 0 | continue; |
1797 | 0 | } |
1798 | | |
1799 | 0 | if ((sec->flags & SEC_HAS_CONTENTS) == 0) |
1800 | 0 | continue; |
1801 | | |
1802 | | /* Allocate memory for the section contents if it has not |
1803 | | been allocated already. We use bfd_zalloc here in case |
1804 | | unused entries are not reclaimed before the section's |
1805 | | contents are written out. This should not happen, but this |
1806 | | way if it does, we get a R_PARISC_NONE reloc instead of |
1807 | | garbage. */ |
1808 | 0 | if (sec->contents == NULL) |
1809 | 0 | { |
1810 | 0 | sec->contents = (bfd_byte *) bfd_zalloc (dynobj, sec->size); |
1811 | 0 | if (sec->contents == NULL) |
1812 | 0 | return false; |
1813 | 0 | sec->alloced = 1; |
1814 | 0 | } |
1815 | 0 | } |
1816 | | |
1817 | 0 | if (hppa_info->root.dynamic_sections_created) |
1818 | 0 | { |
1819 | | /* Always create a DT_PLTGOT. It actually has nothing to do with |
1820 | | the PLT, it is how we communicate the __gp value of a load |
1821 | | module to the dynamic linker. */ |
1822 | 0 | #define add_dynamic_entry(TAG, VAL) \ |
1823 | 0 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) |
1824 | |
|
1825 | 0 | if (!add_dynamic_entry (DT_HP_DLD_FLAGS, 0)) |
1826 | 0 | return false; |
1827 | | |
1828 | | /* Add some entries to the .dynamic section. We fill in the |
1829 | | values later, in elf64_hppa_finish_dynamic_sections, but we |
1830 | | must add the entries now so that we get the correct size for |
1831 | | the .dynamic section. The DT_DEBUG entry is filled in by the |
1832 | | dynamic linker and used by the debugger. */ |
1833 | 0 | if (! bfd_link_pic (info)) |
1834 | 0 | { |
1835 | 0 | if (!add_dynamic_entry (DT_HP_DLD_HOOK, 0) |
1836 | 0 | || !add_dynamic_entry (DT_HP_LOAD_MAP, 0)) |
1837 | 0 | return false; |
1838 | 0 | } |
1839 | | |
1840 | | /* Force DT_FLAGS to always be set. |
1841 | | Required by HPUX 11.00 patch PHSS_26559. |
1842 | | PR 30743: But do not set them for non-HPUX targets. */ |
1843 | 0 | if (output_bfd->xvec == & hppa_elf64_vec) |
1844 | 0 | { |
1845 | 0 | if (!add_dynamic_entry (DT_FLAGS, (info)->flags)) |
1846 | 0 | return false; |
1847 | 0 | } |
1848 | 0 | } |
1849 | 0 | #undef add_dynamic_entry |
1850 | | |
1851 | 0 | return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs); |
1852 | 0 | } |
1853 | | |
1854 | | /* Called after we have output the symbol into the dynamic symbol |
1855 | | table, but before we output the symbol into the normal symbol |
1856 | | table. |
1857 | | |
1858 | | For some symbols we had to change their address when outputting |
1859 | | the dynamic symbol table. We undo that change here so that |
1860 | | the symbols have their expected value in the normal symbol |
1861 | | table. Ick. */ |
1862 | | |
1863 | | static int |
1864 | | elf64_hppa_link_output_symbol_hook (struct bfd_link_info *info ATTRIBUTE_UNUSED, |
1865 | | const char *name, |
1866 | | Elf_Internal_Sym *sym, |
1867 | | asection *input_sec ATTRIBUTE_UNUSED, |
1868 | | struct elf_link_hash_entry *eh) |
1869 | 0 | { |
1870 | 0 | struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); |
1871 | | |
1872 | | /* We may be called with the file symbol or section symbols. |
1873 | | They never need munging, so it is safe to ignore them. */ |
1874 | 0 | if (!name || !eh) |
1875 | 0 | return 1; |
1876 | | |
1877 | | /* Function symbols for which we created .opd entries *may* have been |
1878 | | munged by finish_dynamic_symbol and have to be un-munged here. |
1879 | | |
1880 | | Note that finish_dynamic_symbol sometimes turns dynamic symbols |
1881 | | into non-dynamic ones, so we initialize st_shndx to -1 in |
1882 | | mark_exported_functions and check to see if it was overwritten |
1883 | | here instead of just checking eh->dynindx. */ |
1884 | 0 | if (hh->want_opd && hh->st_shndx != -1) |
1885 | 0 | { |
1886 | | /* Restore the saved value and section index. */ |
1887 | 0 | sym->st_value = hh->st_value; |
1888 | 0 | sym->st_shndx = hh->st_shndx; |
1889 | 0 | } |
1890 | |
|
1891 | 0 | return 1; |
1892 | 0 | } |
1893 | | |
1894 | | /* Finish up dynamic symbol handling. We set the contents of various |
1895 | | dynamic sections here. */ |
1896 | | |
1897 | | static bool |
1898 | | elf64_hppa_finish_dynamic_symbol (bfd *output_bfd, |
1899 | | struct bfd_link_info *info, |
1900 | | struct elf_link_hash_entry *eh, |
1901 | | Elf_Internal_Sym *sym) |
1902 | 0 | { |
1903 | 0 | struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); |
1904 | 0 | asection *stub, *splt, *sopd, *spltrel; |
1905 | 0 | struct elf64_hppa_link_hash_table *hppa_info; |
1906 | |
|
1907 | 0 | hppa_info = hppa_link_hash_table (info); |
1908 | |
|
1909 | 0 | stub = hppa_info->stub_sec; |
1910 | 0 | splt = hppa_info->root.splt; |
1911 | 0 | sopd = hppa_info->opd_sec; |
1912 | 0 | spltrel = hppa_info->root.srelplt; |
1913 | | |
1914 | | /* Incredible. It is actually necessary to NOT use the symbol's real |
1915 | | value when building the dynamic symbol table for a shared library. |
1916 | | At least for symbols that refer to functions. |
1917 | | |
1918 | | We will store a new value and section index into the symbol long |
1919 | | enough to output it into the dynamic symbol table, then we restore |
1920 | | the original values (in elf64_hppa_link_output_symbol_hook). */ |
1921 | 0 | if (hh->want_opd) |
1922 | 0 | { |
1923 | 0 | BFD_ASSERT (sopd != NULL); |
1924 | | |
1925 | | /* Save away the original value and section index so that we |
1926 | | can restore them later. */ |
1927 | 0 | hh->st_value = sym->st_value; |
1928 | 0 | hh->st_shndx = sym->st_shndx; |
1929 | | |
1930 | | /* For the dynamic symbol table entry, we want the value to be |
1931 | | address of this symbol's entry within the .opd section. */ |
1932 | 0 | sym->st_value = (hh->opd_offset |
1933 | 0 | + sopd->output_offset |
1934 | 0 | + sopd->output_section->vma); |
1935 | 0 | sym->st_shndx = _bfd_elf_section_from_bfd_section (output_bfd, |
1936 | 0 | sopd->output_section); |
1937 | 0 | } |
1938 | | |
1939 | | /* Initialize a .plt entry if requested. */ |
1940 | 0 | if (hh->want_plt |
1941 | 0 | && elf64_hppa_dynamic_symbol_p (eh, info)) |
1942 | 0 | { |
1943 | 0 | bfd_vma value; |
1944 | 0 | Elf_Internal_Rela rel; |
1945 | 0 | bfd_byte *loc; |
1946 | |
|
1947 | 0 | BFD_ASSERT (splt != NULL && spltrel != NULL); |
1948 | | |
1949 | | /* We do not actually care about the value in the PLT entry |
1950 | | if we are creating a shared library and the symbol is |
1951 | | still undefined, we create a dynamic relocation to fill |
1952 | | in the correct value. */ |
1953 | 0 | if (bfd_link_pic (info) && eh->root.type == bfd_link_hash_undefined) |
1954 | 0 | value = 0; |
1955 | 0 | else |
1956 | 0 | value = (eh->root.u.def.value + eh->root.u.def.section->vma); |
1957 | | |
1958 | | /* Fill in the entry in the procedure linkage table. |
1959 | | |
1960 | | The format of a plt entry is |
1961 | | <funcaddr> <__gp>. |
1962 | | |
1963 | | plt_offset is the offset within the PLT section at which to |
1964 | | install the PLT entry. |
1965 | | |
1966 | | We are modifying the in-memory PLT contents here, so we do not add |
1967 | | in the output_offset of the PLT section. */ |
1968 | |
|
1969 | 0 | bfd_put_64 (splt->owner, value, splt->contents + hh->plt_offset); |
1970 | 0 | value = _bfd_get_gp_value (info->output_bfd); |
1971 | 0 | bfd_put_64 (splt->owner, value, splt->contents + hh->plt_offset + 0x8); |
1972 | | |
1973 | | /* Create a dynamic IPLT relocation for this entry. |
1974 | | |
1975 | | We are creating a relocation in the output file's PLT section, |
1976 | | which is included within the DLT secton. So we do need to include |
1977 | | the PLT's output_offset in the computation of the relocation's |
1978 | | address. */ |
1979 | 0 | rel.r_offset = (hh->plt_offset + splt->output_offset |
1980 | 0 | + splt->output_section->vma); |
1981 | 0 | rel.r_info = ELF64_R_INFO (hh->eh.dynindx, R_PARISC_IPLT); |
1982 | 0 | rel.r_addend = 0; |
1983 | |
|
1984 | 0 | loc = spltrel->contents; |
1985 | 0 | loc += spltrel->reloc_count++ * sizeof (Elf64_External_Rela); |
1986 | 0 | bfd_elf64_swap_reloca_out (info->output_bfd, &rel, loc); |
1987 | 0 | } |
1988 | | |
1989 | | /* Initialize an external call stub entry if requested. */ |
1990 | 0 | if (hh->want_stub |
1991 | 0 | && elf64_hppa_dynamic_symbol_p (eh, info)) |
1992 | 0 | { |
1993 | 0 | bfd_vma value; |
1994 | 0 | int insn; |
1995 | 0 | unsigned int max_offset; |
1996 | |
|
1997 | 0 | BFD_ASSERT (stub != NULL); |
1998 | | |
1999 | | /* Install the generic stub template. |
2000 | | |
2001 | | We are modifying the contents of the stub section, so we do not |
2002 | | need to include the stub section's output_offset here. */ |
2003 | 0 | memcpy (stub->contents + hh->stub_offset, plt_stub, sizeof (plt_stub)); |
2004 | | |
2005 | | /* Fix up the first ldd instruction. |
2006 | | |
2007 | | We are modifying the contents of the STUB section in memory, |
2008 | | so we do not need to include its output offset in this computation. |
2009 | | |
2010 | | Note the plt_offset value is the value of the PLT entry relative to |
2011 | | the start of the PLT section. These instructions will reference |
2012 | | data relative to the value of __gp, which may not necessarily have |
2013 | | the same address as the start of the PLT section. |
2014 | | |
2015 | | gp_offset contains the offset of __gp within the PLT section. */ |
2016 | 0 | value = hh->plt_offset - hppa_info->gp_offset; |
2017 | |
|
2018 | 0 | insn = bfd_get_32 (stub->owner, stub->contents + hh->stub_offset); |
2019 | 0 | if (output_bfd->arch_info->mach >= 25) |
2020 | 0 | { |
2021 | | /* Wide mode allows 16 bit offsets. */ |
2022 | 0 | max_offset = 32768; |
2023 | 0 | insn &= ~ 0xfff1; |
2024 | 0 | insn |= re_assemble_16 ((int) value); |
2025 | 0 | } |
2026 | 0 | else |
2027 | 0 | { |
2028 | 0 | max_offset = 8192; |
2029 | 0 | insn &= ~ 0x3ff1; |
2030 | 0 | insn |= re_assemble_14 ((int) value); |
2031 | 0 | } |
2032 | |
|
2033 | 0 | if ((value & 7) || value + max_offset >= 2*max_offset - 8) |
2034 | 0 | { |
2035 | 0 | _bfd_error_handler |
2036 | | /* xgettext:c-format */ |
2037 | 0 | (_("stub entry for %s cannot load .plt, dp offset = %" PRId64), |
2038 | 0 | hh->eh.root.root.string, (int64_t) value); |
2039 | 0 | return false; |
2040 | 0 | } |
2041 | | |
2042 | 0 | bfd_put_32 (stub->owner, (bfd_vma) insn, |
2043 | 0 | stub->contents + hh->stub_offset); |
2044 | | |
2045 | | /* Fix up the second ldd instruction. */ |
2046 | 0 | value += 8; |
2047 | 0 | insn = bfd_get_32 (stub->owner, stub->contents + hh->stub_offset + 8); |
2048 | 0 | if (output_bfd->arch_info->mach >= 25) |
2049 | 0 | { |
2050 | 0 | insn &= ~ 0xfff1; |
2051 | 0 | insn |= re_assemble_16 ((int) value); |
2052 | 0 | } |
2053 | 0 | else |
2054 | 0 | { |
2055 | 0 | insn &= ~ 0x3ff1; |
2056 | 0 | insn |= re_assemble_14 ((int) value); |
2057 | 0 | } |
2058 | 0 | bfd_put_32 (stub->owner, (bfd_vma) insn, |
2059 | 0 | stub->contents + hh->stub_offset + 8); |
2060 | 0 | } |
2061 | | |
2062 | 0 | return true; |
2063 | 0 | } |
2064 | | |
2065 | | /* The .opd section contains FPTRs for each function this file |
2066 | | exports. Initialize the FPTR entries. */ |
2067 | | |
2068 | | static bool |
2069 | | elf64_hppa_finalize_opd (struct elf_link_hash_entry *eh, void *data) |
2070 | 0 | { |
2071 | 0 | struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); |
2072 | 0 | struct bfd_link_info *info = (struct bfd_link_info *)data; |
2073 | 0 | struct elf64_hppa_link_hash_table *hppa_info; |
2074 | 0 | asection *sopd; |
2075 | 0 | asection *sopdrel; |
2076 | |
|
2077 | 0 | hppa_info = hppa_link_hash_table (info); |
2078 | 0 | if (hppa_info == NULL) |
2079 | 0 | return false; |
2080 | | |
2081 | 0 | sopd = hppa_info->opd_sec; |
2082 | 0 | sopdrel = hppa_info->opd_rel_sec; |
2083 | |
|
2084 | 0 | if (hh->want_opd) |
2085 | 0 | { |
2086 | 0 | bfd_vma value; |
2087 | | |
2088 | | /* The first two words of an .opd entry are zero. |
2089 | | |
2090 | | We are modifying the contents of the OPD section in memory, so we |
2091 | | do not need to include its output offset in this computation. */ |
2092 | 0 | memset (sopd->contents + hh->opd_offset, 0, 16); |
2093 | |
|
2094 | 0 | value = (eh->root.u.def.value |
2095 | 0 | + eh->root.u.def.section->output_section->vma |
2096 | 0 | + eh->root.u.def.section->output_offset); |
2097 | | |
2098 | | /* The next word is the address of the function. */ |
2099 | 0 | bfd_put_64 (sopd->owner, value, sopd->contents + hh->opd_offset + 16); |
2100 | | |
2101 | | /* The last word is our local __gp value. */ |
2102 | 0 | value = _bfd_get_gp_value (info->output_bfd); |
2103 | 0 | bfd_put_64 (sopd->owner, value, sopd->contents + hh->opd_offset + 24); |
2104 | 0 | } |
2105 | | |
2106 | | /* If we are generating a shared library, we must generate EPLT relocations |
2107 | | for each entry in the .opd, even for static functions (they may have |
2108 | | had their address taken). */ |
2109 | 0 | if (bfd_link_pic (info) && hh->want_opd) |
2110 | 0 | { |
2111 | 0 | Elf_Internal_Rela rel; |
2112 | 0 | bfd_byte *loc; |
2113 | 0 | int dynindx; |
2114 | | |
2115 | | /* We may need to do a relocation against a local symbol, in |
2116 | | which case we have to look up it's dynamic symbol index off |
2117 | | the local symbol hash table. */ |
2118 | 0 | if (eh->dynindx != -1) |
2119 | 0 | dynindx = eh->dynindx; |
2120 | 0 | else |
2121 | 0 | dynindx |
2122 | 0 | = _bfd_elf_link_lookup_local_dynindx (info, hh->owner, |
2123 | 0 | hh->sym_indx); |
2124 | | |
2125 | | /* The offset of this relocation is the absolute address of the |
2126 | | .opd entry for this symbol. */ |
2127 | 0 | rel.r_offset = (hh->opd_offset + sopd->output_offset |
2128 | 0 | + sopd->output_section->vma); |
2129 | | |
2130 | | /* If H is non-null, then we have an external symbol. |
2131 | | |
2132 | | It is imperative that we use a different dynamic symbol for the |
2133 | | EPLT relocation if the symbol has global scope. |
2134 | | |
2135 | | In the dynamic symbol table, the function symbol will have a value |
2136 | | which is address of the function's .opd entry. |
2137 | | |
2138 | | Thus, we can not use that dynamic symbol for the EPLT relocation |
2139 | | (if we did, the data in the .opd would reference itself rather |
2140 | | than the actual address of the function). Instead we have to use |
2141 | | a new dynamic symbol which has the same value as the original global |
2142 | | function symbol. |
2143 | | |
2144 | | We prefix the original symbol with a "." and use the new symbol in |
2145 | | the EPLT relocation. This new symbol has already been recorded in |
2146 | | the symbol table, we just have to look it up and use it. |
2147 | | |
2148 | | We do not have such problems with static functions because we do |
2149 | | not make their addresses in the dynamic symbol table point to |
2150 | | the .opd entry. Ultimately this should be safe since a static |
2151 | | function can not be directly referenced outside of its shared |
2152 | | library. |
2153 | | |
2154 | | We do have to play similar games for FPTR relocations in shared |
2155 | | libraries, including those for static symbols. See the FPTR |
2156 | | handling in elf64_hppa_finalize_dynreloc. */ |
2157 | 0 | if (eh) |
2158 | 0 | { |
2159 | 0 | char *new_name; |
2160 | 0 | struct elf_link_hash_entry *nh; |
2161 | |
|
2162 | 0 | new_name = concat (".", eh->root.root.string, NULL); |
2163 | |
|
2164 | 0 | nh = elf_link_hash_lookup (elf_hash_table (info), |
2165 | 0 | new_name, true, true, false); |
2166 | | |
2167 | | /* All we really want from the new symbol is its dynamic |
2168 | | symbol index. */ |
2169 | 0 | if (nh) |
2170 | 0 | dynindx = nh->dynindx; |
2171 | 0 | free (new_name); |
2172 | 0 | } |
2173 | |
|
2174 | 0 | rel.r_addend = 0; |
2175 | 0 | rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_EPLT); |
2176 | |
|
2177 | 0 | loc = sopdrel->contents; |
2178 | 0 | loc += sopdrel->reloc_count++ * sizeof (Elf64_External_Rela); |
2179 | 0 | bfd_elf64_swap_reloca_out (info->output_bfd, &rel, loc); |
2180 | 0 | } |
2181 | 0 | return true; |
2182 | 0 | } |
2183 | | |
2184 | | /* The .dlt section contains addresses for items referenced through the |
2185 | | dlt. Note that we can have a DLTIND relocation for a local symbol, thus |
2186 | | we can not depend on finish_dynamic_symbol to initialize the .dlt. */ |
2187 | | |
2188 | | static bool |
2189 | | elf64_hppa_finalize_dlt (struct elf_link_hash_entry *eh, void *data) |
2190 | 0 | { |
2191 | 0 | struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); |
2192 | 0 | struct bfd_link_info *info = (struct bfd_link_info *)data; |
2193 | 0 | struct elf64_hppa_link_hash_table *hppa_info; |
2194 | 0 | asection *sdlt, *sdltrel; |
2195 | |
|
2196 | 0 | hppa_info = hppa_link_hash_table (info); |
2197 | 0 | if (hppa_info == NULL) |
2198 | 0 | return false; |
2199 | | |
2200 | 0 | sdlt = hppa_info->dlt_sec; |
2201 | 0 | sdltrel = hppa_info->dlt_rel_sec; |
2202 | | |
2203 | | /* H/DYN_H may refer to a local variable and we know it's |
2204 | | address, so there is no need to create a relocation. Just install |
2205 | | the proper value into the DLT, note this shortcut can not be |
2206 | | skipped when building a shared library. */ |
2207 | 0 | if (! bfd_link_pic (info) && hh && hh->want_dlt) |
2208 | 0 | { |
2209 | 0 | bfd_vma value; |
2210 | | |
2211 | | /* If we had an LTOFF_FPTR style relocation we want the DLT entry |
2212 | | to point to the FPTR entry in the .opd section. |
2213 | | |
2214 | | We include the OPD's output offset in this computation as |
2215 | | we are referring to an absolute address in the resulting |
2216 | | object file. */ |
2217 | 0 | if (hh->want_opd) |
2218 | 0 | { |
2219 | 0 | value = (hh->opd_offset |
2220 | 0 | + hppa_info->opd_sec->output_offset |
2221 | 0 | + hppa_info->opd_sec->output_section->vma); |
2222 | 0 | } |
2223 | 0 | else if ((eh->root.type == bfd_link_hash_defined |
2224 | 0 | || eh->root.type == bfd_link_hash_defweak) |
2225 | 0 | && eh->root.u.def.section) |
2226 | 0 | { |
2227 | 0 | value = eh->root.u.def.value + eh->root.u.def.section->output_offset; |
2228 | 0 | if (eh->root.u.def.section->output_section) |
2229 | 0 | value += eh->root.u.def.section->output_section->vma; |
2230 | 0 | else |
2231 | 0 | value += eh->root.u.def.section->vma; |
2232 | 0 | } |
2233 | 0 | else |
2234 | | /* We have an undefined function reference. */ |
2235 | 0 | value = 0; |
2236 | | |
2237 | | /* We do not need to include the output offset of the DLT section |
2238 | | here because we are modifying the in-memory contents. */ |
2239 | 0 | bfd_put_64 (sdlt->owner, value, sdlt->contents + hh->dlt_offset); |
2240 | 0 | } |
2241 | | |
2242 | | /* Create a relocation for the DLT entry associated with this symbol. |
2243 | | When building a shared library the symbol does not have to be dynamic. */ |
2244 | 0 | if (hh->want_dlt |
2245 | 0 | && (elf64_hppa_dynamic_symbol_p (eh, info) || bfd_link_pic (info))) |
2246 | 0 | { |
2247 | 0 | Elf_Internal_Rela rel; |
2248 | 0 | bfd_byte *loc; |
2249 | 0 | int dynindx; |
2250 | | |
2251 | | /* We may need to do a relocation against a local symbol, in |
2252 | | which case we have to look up it's dynamic symbol index off |
2253 | | the local symbol hash table. */ |
2254 | 0 | if (eh && eh->dynindx != -1) |
2255 | 0 | dynindx = eh->dynindx; |
2256 | 0 | else |
2257 | 0 | dynindx |
2258 | 0 | = _bfd_elf_link_lookup_local_dynindx (info, hh->owner, |
2259 | 0 | hh->sym_indx); |
2260 | | |
2261 | | /* Create a dynamic relocation for this entry. Do include the output |
2262 | | offset of the DLT entry since we need an absolute address in the |
2263 | | resulting object file. */ |
2264 | 0 | rel.r_offset = (hh->dlt_offset + sdlt->output_offset |
2265 | 0 | + sdlt->output_section->vma); |
2266 | 0 | if (eh && eh->type == STT_FUNC) |
2267 | 0 | rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_FPTR64); |
2268 | 0 | else |
2269 | 0 | rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_DIR64); |
2270 | 0 | rel.r_addend = 0; |
2271 | |
|
2272 | 0 | loc = sdltrel->contents; |
2273 | 0 | loc += sdltrel->reloc_count++ * sizeof (Elf64_External_Rela); |
2274 | 0 | bfd_elf64_swap_reloca_out (info->output_bfd, &rel, loc); |
2275 | 0 | } |
2276 | 0 | return true; |
2277 | 0 | } |
2278 | | |
2279 | | /* Finalize the dynamic relocations. Specifically the FPTR relocations |
2280 | | for dynamic functions used to initialize static data. */ |
2281 | | |
2282 | | static bool |
2283 | | elf64_hppa_finalize_dynreloc (struct elf_link_hash_entry *eh, |
2284 | | void *data) |
2285 | 0 | { |
2286 | 0 | struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); |
2287 | 0 | struct bfd_link_info *info = (struct bfd_link_info *)data; |
2288 | 0 | struct elf64_hppa_link_hash_table *hppa_info; |
2289 | 0 | int dynamic_symbol; |
2290 | |
|
2291 | 0 | dynamic_symbol = elf64_hppa_dynamic_symbol_p (eh, info); |
2292 | |
|
2293 | 0 | if (!dynamic_symbol && !bfd_link_pic (info)) |
2294 | 0 | return true; |
2295 | | |
2296 | 0 | if (hh->reloc_entries) |
2297 | 0 | { |
2298 | 0 | struct elf64_hppa_dyn_reloc_entry *rent; |
2299 | 0 | int dynindx; |
2300 | |
|
2301 | 0 | hppa_info = hppa_link_hash_table (info); |
2302 | 0 | if (hppa_info == NULL) |
2303 | 0 | return false; |
2304 | | |
2305 | | /* We may need to do a relocation against a local symbol, in |
2306 | | which case we have to look up it's dynamic symbol index off |
2307 | | the local symbol hash table. */ |
2308 | 0 | if (eh->dynindx != -1) |
2309 | 0 | dynindx = eh->dynindx; |
2310 | 0 | else |
2311 | 0 | dynindx |
2312 | 0 | = _bfd_elf_link_lookup_local_dynindx (info, hh->owner, |
2313 | 0 | hh->sym_indx); |
2314 | |
|
2315 | 0 | for (rent = hh->reloc_entries; rent; rent = rent->next) |
2316 | 0 | { |
2317 | 0 | Elf_Internal_Rela rel; |
2318 | 0 | bfd_byte *loc; |
2319 | | |
2320 | | /* Allocate one iff we are building a shared library, the relocation |
2321 | | isn't a R_PARISC_FPTR64, or we don't want an opd entry. */ |
2322 | 0 | if (!bfd_link_pic (info) |
2323 | 0 | && rent->type == R_PARISC_FPTR64 && hh->want_opd) |
2324 | 0 | continue; |
2325 | | |
2326 | | /* Create a dynamic relocation for this entry. |
2327 | | |
2328 | | We need the output offset for the reloc's section because |
2329 | | we are creating an absolute address in the resulting object |
2330 | | file. */ |
2331 | 0 | rel.r_offset = (rent->offset + rent->sec->output_offset |
2332 | 0 | + rent->sec->output_section->vma); |
2333 | | |
2334 | | /* An FPTR64 relocation implies that we took the address of |
2335 | | a function and that the function has an entry in the .opd |
2336 | | section. We want the FPTR64 relocation to reference the |
2337 | | entry in .opd. |
2338 | | |
2339 | | We could munge the symbol value in the dynamic symbol table |
2340 | | (in fact we already do for functions with global scope) to point |
2341 | | to the .opd entry. Then we could use that dynamic symbol in |
2342 | | this relocation. |
2343 | | |
2344 | | Or we could do something sensible, not munge the symbol's |
2345 | | address and instead just use a different symbol to reference |
2346 | | the .opd entry. At least that seems sensible until you |
2347 | | realize there's no local dynamic symbols we can use for that |
2348 | | purpose. Thus the hair in the check_relocs routine. |
2349 | | |
2350 | | We use a section symbol recorded by check_relocs as the |
2351 | | base symbol for the relocation. The addend is the difference |
2352 | | between the section symbol and the address of the .opd entry. */ |
2353 | 0 | if (bfd_link_pic (info) |
2354 | 0 | && rent->type == R_PARISC_FPTR64 && hh->want_opd) |
2355 | 0 | { |
2356 | 0 | bfd_vma value, value2; |
2357 | | |
2358 | | /* First compute the address of the opd entry for this symbol. */ |
2359 | 0 | value = (hh->opd_offset |
2360 | 0 | + hppa_info->opd_sec->output_section->vma |
2361 | 0 | + hppa_info->opd_sec->output_offset); |
2362 | | |
2363 | | /* Compute the value of the start of the section with |
2364 | | the relocation. */ |
2365 | 0 | value2 = (rent->sec->output_section->vma |
2366 | 0 | + rent->sec->output_offset); |
2367 | | |
2368 | | /* Compute the difference between the start of the section |
2369 | | with the relocation and the opd entry. */ |
2370 | 0 | value -= value2; |
2371 | | |
2372 | | /* The result becomes the addend of the relocation. */ |
2373 | 0 | rel.r_addend = value; |
2374 | | |
2375 | | /* The section symbol becomes the symbol for the dynamic |
2376 | | relocation. */ |
2377 | 0 | dynindx |
2378 | 0 | = _bfd_elf_link_lookup_local_dynindx (info, |
2379 | 0 | rent->sec->owner, |
2380 | 0 | rent->sec_symndx); |
2381 | 0 | } |
2382 | 0 | else |
2383 | 0 | rel.r_addend = rent->addend; |
2384 | |
|
2385 | 0 | rel.r_info = ELF64_R_INFO (dynindx, rent->type); |
2386 | |
|
2387 | 0 | loc = hppa_info->other_rel_sec->contents; |
2388 | 0 | loc += (hppa_info->other_rel_sec->reloc_count++ |
2389 | 0 | * sizeof (Elf64_External_Rela)); |
2390 | 0 | bfd_elf64_swap_reloca_out (info->output_bfd, &rel, loc); |
2391 | 0 | } |
2392 | 0 | } |
2393 | | |
2394 | 0 | return true; |
2395 | 0 | } |
2396 | | |
2397 | | /* Used to decide how to sort relocs in an optimal manner for the |
2398 | | dynamic linker, before writing them out. */ |
2399 | | |
2400 | | static enum elf_reloc_type_class |
2401 | | elf64_hppa_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED, |
2402 | | const asection *rel_sec ATTRIBUTE_UNUSED, |
2403 | | const Elf_Internal_Rela *rela) |
2404 | 0 | { |
2405 | 0 | if (ELF64_R_SYM (rela->r_info) == STN_UNDEF) |
2406 | 0 | return reloc_class_relative; |
2407 | | |
2408 | 0 | switch ((int) ELF64_R_TYPE (rela->r_info)) |
2409 | 0 | { |
2410 | 0 | case R_PARISC_IPLT: |
2411 | 0 | return reloc_class_plt; |
2412 | 0 | case R_PARISC_COPY: |
2413 | 0 | return reloc_class_copy; |
2414 | 0 | default: |
2415 | 0 | return reloc_class_normal; |
2416 | 0 | } |
2417 | 0 | } |
2418 | | |
2419 | | /* Finish up the dynamic sections. */ |
2420 | | |
2421 | | static bool |
2422 | | elf64_hppa_finish_dynamic_sections (bfd *output_bfd, |
2423 | | struct bfd_link_info *info) |
2424 | 0 | { |
2425 | 0 | bfd *dynobj; |
2426 | 0 | asection *sdyn; |
2427 | 0 | struct elf64_hppa_link_hash_table *hppa_info; |
2428 | |
|
2429 | 0 | hppa_info = hppa_link_hash_table (info); |
2430 | 0 | if (hppa_info == NULL) |
2431 | 0 | return false; |
2432 | | |
2433 | | /* Finalize the contents of the .opd section. */ |
2434 | 0 | elf_link_hash_traverse (elf_hash_table (info), |
2435 | 0 | elf64_hppa_finalize_opd, |
2436 | 0 | info); |
2437 | |
|
2438 | 0 | elf_link_hash_traverse (elf_hash_table (info), |
2439 | 0 | elf64_hppa_finalize_dynreloc, |
2440 | 0 | info); |
2441 | | |
2442 | | /* Finalize the contents of the .dlt section. */ |
2443 | 0 | dynobj = elf_hash_table (info)->dynobj; |
2444 | | /* Finalize the contents of the .dlt section. */ |
2445 | 0 | elf_link_hash_traverse (elf_hash_table (info), |
2446 | 0 | elf64_hppa_finalize_dlt, |
2447 | 0 | info); |
2448 | |
|
2449 | 0 | sdyn = bfd_get_linker_section (dynobj, ".dynamic"); |
2450 | |
|
2451 | 0 | if (elf_hash_table (info)->dynamic_sections_created) |
2452 | 0 | { |
2453 | 0 | Elf64_External_Dyn *dyncon, *dynconend; |
2454 | |
|
2455 | 0 | BFD_ASSERT (sdyn != NULL); |
2456 | |
|
2457 | 0 | dyncon = (Elf64_External_Dyn *) sdyn->contents; |
2458 | 0 | dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size); |
2459 | 0 | for (; dyncon < dynconend; dyncon++) |
2460 | 0 | { |
2461 | 0 | Elf_Internal_Dyn dyn; |
2462 | 0 | asection *s; |
2463 | |
|
2464 | 0 | bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn); |
2465 | |
|
2466 | 0 | switch (dyn.d_tag) |
2467 | 0 | { |
2468 | 0 | default: |
2469 | 0 | break; |
2470 | | |
2471 | 0 | case DT_HP_LOAD_MAP: |
2472 | | /* Compute the absolute address of 16byte scratchpad area |
2473 | | for the dynamic linker. |
2474 | | |
2475 | | By convention the linker script will allocate the scratchpad |
2476 | | area at the start of the .data section. So all we have to |
2477 | | to is find the start of the .data section. */ |
2478 | 0 | s = bfd_get_section_by_name (output_bfd, ".data"); |
2479 | 0 | if (!s) |
2480 | 0 | return false; |
2481 | 0 | dyn.d_un.d_ptr = s->vma; |
2482 | 0 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); |
2483 | 0 | break; |
2484 | | |
2485 | 0 | case DT_PLTGOT: |
2486 | | /* HP's use PLTGOT to set the GOT register. */ |
2487 | 0 | dyn.d_un.d_ptr = _bfd_get_gp_value (output_bfd); |
2488 | 0 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); |
2489 | 0 | break; |
2490 | | |
2491 | 0 | case DT_JMPREL: |
2492 | 0 | s = hppa_info->root.srelplt; |
2493 | 0 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
2494 | 0 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); |
2495 | 0 | break; |
2496 | | |
2497 | 0 | case DT_PLTRELSZ: |
2498 | 0 | s = hppa_info->root.srelplt; |
2499 | 0 | dyn.d_un.d_val = s->size; |
2500 | 0 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); |
2501 | 0 | break; |
2502 | | |
2503 | 0 | case DT_RELA: |
2504 | 0 | s = hppa_info->other_rel_sec; |
2505 | 0 | if (! s || ! s->size) |
2506 | 0 | s = hppa_info->dlt_rel_sec; |
2507 | 0 | if (! s || ! s->size) |
2508 | 0 | s = hppa_info->opd_rel_sec; |
2509 | 0 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; |
2510 | 0 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); |
2511 | 0 | break; |
2512 | | |
2513 | 0 | case DT_RELASZ: |
2514 | 0 | s = hppa_info->other_rel_sec; |
2515 | 0 | dyn.d_un.d_val = s->size; |
2516 | 0 | s = hppa_info->dlt_rel_sec; |
2517 | 0 | dyn.d_un.d_val += s->size; |
2518 | 0 | s = hppa_info->opd_rel_sec; |
2519 | 0 | dyn.d_un.d_val += s->size; |
2520 | | /* There is some question about whether or not the size of |
2521 | | the PLT relocs should be included here. HP's tools do |
2522 | | it, so we'll emulate them. */ |
2523 | 0 | s = hppa_info->root.srelplt; |
2524 | 0 | dyn.d_un.d_val += s->size; |
2525 | 0 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); |
2526 | 0 | break; |
2527 | |
|
2528 | 0 | } |
2529 | 0 | } |
2530 | 0 | } |
2531 | | |
2532 | 0 | return true; |
2533 | 0 | } |
2534 | | |
2535 | | /* Support for core dump NOTE sections. */ |
2536 | | |
2537 | | static bool |
2538 | | elf64_hppa_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) |
2539 | 0 | { |
2540 | 0 | int offset; |
2541 | 0 | size_t size; |
2542 | |
|
2543 | 0 | switch (note->descsz) |
2544 | 0 | { |
2545 | 0 | default: |
2546 | 0 | return false; |
2547 | | |
2548 | 0 | case 760: /* Linux/hppa */ |
2549 | | /* pr_cursig */ |
2550 | 0 | elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12); |
2551 | | |
2552 | | /* pr_pid */ |
2553 | 0 | elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 32); |
2554 | | |
2555 | | /* pr_reg */ |
2556 | 0 | offset = 112; |
2557 | 0 | size = 640; |
2558 | |
|
2559 | 0 | break; |
2560 | 0 | } |
2561 | | |
2562 | | /* Make a ".reg/999" section. */ |
2563 | 0 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", |
2564 | 0 | size, note->descpos + offset); |
2565 | 0 | } |
2566 | | |
2567 | | static bool |
2568 | | elf64_hppa_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) |
2569 | 0 | { |
2570 | 0 | char * command; |
2571 | 0 | int n; |
2572 | |
|
2573 | 0 | switch (note->descsz) |
2574 | 0 | { |
2575 | 0 | default: |
2576 | 0 | return false; |
2577 | | |
2578 | 0 | case 136: /* Linux/hppa elf_prpsinfo. */ |
2579 | 0 | elf_tdata (abfd)->core->program |
2580 | 0 | = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16); |
2581 | 0 | elf_tdata (abfd)->core->command |
2582 | 0 | = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80); |
2583 | 0 | } |
2584 | | |
2585 | | /* Note that for some reason, a spurious space is tacked |
2586 | | onto the end of the args in some (at least one anyway) |
2587 | | implementations, so strip it off if it exists. */ |
2588 | 0 | command = elf_tdata (abfd)->core->command; |
2589 | 0 | n = strlen (command); |
2590 | |
|
2591 | 0 | if (0 < n && command[n - 1] == ' ') |
2592 | 0 | command[n - 1] = '\0'; |
2593 | |
|
2594 | 0 | return true; |
2595 | 0 | } |
2596 | | |
2597 | | /* Return the number of additional phdrs we will need. |
2598 | | |
2599 | | The generic ELF code only creates PT_PHDRs for executables. The HP |
2600 | | dynamic linker requires PT_PHDRs for dynamic libraries too. |
2601 | | |
2602 | | This routine indicates that the backend needs one additional program |
2603 | | header for that case. |
2604 | | |
2605 | | Note we do not have access to the link info structure here, so we have |
2606 | | to guess whether or not we are building a shared library based on the |
2607 | | existence of a .interp section. */ |
2608 | | |
2609 | | static int |
2610 | | elf64_hppa_additional_program_headers (bfd *abfd, |
2611 | | struct bfd_link_info *info ATTRIBUTE_UNUSED) |
2612 | 0 | { |
2613 | 0 | asection *s; |
2614 | | |
2615 | | /* If we are creating a shared library, then we have to create a |
2616 | | PT_PHDR segment. HP's dynamic linker chokes without it. */ |
2617 | 0 | s = bfd_get_section_by_name (abfd, ".interp"); |
2618 | 0 | if (! s) |
2619 | 0 | return 1; |
2620 | 0 | return 0; |
2621 | 0 | } |
2622 | | |
2623 | | static bool |
2624 | | elf64_hppa_allow_non_load_phdr (bfd *abfd ATTRIBUTE_UNUSED, |
2625 | | const Elf_Internal_Phdr *phdr ATTRIBUTE_UNUSED, |
2626 | | unsigned int count ATTRIBUTE_UNUSED) |
2627 | 0 | { |
2628 | 0 | return true; |
2629 | 0 | } |
2630 | | |
2631 | | /* Allocate and initialize any program headers required by this |
2632 | | specific backend. |
2633 | | |
2634 | | The generic ELF code only creates PT_PHDRs for executables. The HP |
2635 | | dynamic linker requires PT_PHDRs for dynamic libraries too. |
2636 | | |
2637 | | This allocates the PT_PHDR and initializes it in a manner suitable |
2638 | | for the HP linker. |
2639 | | |
2640 | | Note we do not have access to the link info structure here, so we have |
2641 | | to guess whether or not we are building a shared library based on the |
2642 | | existence of a .interp section. */ |
2643 | | |
2644 | | static bool |
2645 | | elf64_hppa_modify_segment_map (bfd *abfd, struct bfd_link_info *info) |
2646 | 0 | { |
2647 | 0 | struct elf_segment_map *m; |
2648 | |
|
2649 | 0 | m = elf_seg_map (abfd); |
2650 | 0 | if (info != NULL && !info->user_phdrs && m != NULL && m->p_type != PT_PHDR) |
2651 | 0 | { |
2652 | 0 | m = ((struct elf_segment_map *) |
2653 | 0 | bfd_zalloc (abfd, (bfd_size_type) sizeof *m)); |
2654 | 0 | if (m == NULL) |
2655 | 0 | return false; |
2656 | | |
2657 | 0 | m->p_type = PT_PHDR; |
2658 | 0 | m->p_flags = PF_R | PF_X; |
2659 | 0 | m->p_flags_valid = 1; |
2660 | 0 | m->p_paddr_valid = 1; |
2661 | 0 | m->includes_phdrs = 1; |
2662 | |
|
2663 | 0 | m->next = elf_seg_map (abfd); |
2664 | 0 | elf_seg_map (abfd) = m; |
2665 | 0 | } |
2666 | | |
2667 | 0 | for (m = elf_seg_map (abfd) ; m != NULL; m = m->next) |
2668 | 0 | if (m->p_type == PT_LOAD) |
2669 | 0 | { |
2670 | 0 | unsigned int i; |
2671 | |
|
2672 | 0 | for (i = 0; i < m->count; i++) |
2673 | 0 | { |
2674 | | /* The code "hint" is not really a hint. It is a requirement |
2675 | | for certain versions of the HP dynamic linker. Worse yet, |
2676 | | it must be set even if the shared library does not have |
2677 | | any code in its "text" segment (thus the check for .hash |
2678 | | to catch this situation). */ |
2679 | 0 | if (m->sections[i]->flags & SEC_CODE |
2680 | 0 | || (strcmp (m->sections[i]->name, ".hash") == 0)) |
2681 | 0 | m->p_flags |= (PF_X | PF_HP_CODE); |
2682 | 0 | } |
2683 | 0 | } |
2684 | |
|
2685 | 0 | return true; |
2686 | 0 | } |
2687 | | |
2688 | | /* Called when writing out an object file to decide the type of a |
2689 | | symbol. */ |
2690 | | static int |
2691 | | elf64_hppa_elf_get_symbol_type (Elf_Internal_Sym *elf_sym, |
2692 | | int type) |
2693 | 0 | { |
2694 | 0 | if (ELF_ST_TYPE (elf_sym->st_info) == STT_PARISC_MILLI) |
2695 | 0 | return STT_PARISC_MILLI; |
2696 | 0 | else |
2697 | 0 | return type; |
2698 | 0 | } |
2699 | | |
2700 | | /* Support HP specific sections for core files. */ |
2701 | | |
2702 | | static bool |
2703 | | elf64_hppa_section_from_phdr (bfd *abfd, Elf_Internal_Phdr *hdr, int sec_index, |
2704 | | const char *typename) |
2705 | 0 | { |
2706 | 0 | if (hdr->p_type == PT_HP_CORE_KERNEL) |
2707 | 0 | { |
2708 | 0 | asection *sect; |
2709 | |
|
2710 | 0 | if (!_bfd_elf_make_section_from_phdr (abfd, hdr, sec_index, typename)) |
2711 | 0 | return false; |
2712 | | |
2713 | 0 | sect = bfd_make_section_anyway (abfd, ".kernel"); |
2714 | 0 | if (sect == NULL) |
2715 | 0 | return false; |
2716 | 0 | sect->size = hdr->p_filesz; |
2717 | 0 | sect->filepos = hdr->p_offset; |
2718 | 0 | sect->flags = SEC_HAS_CONTENTS | SEC_READONLY; |
2719 | 0 | return true; |
2720 | 0 | } |
2721 | | |
2722 | 0 | if (hdr->p_type == PT_HP_CORE_PROC) |
2723 | 0 | { |
2724 | 0 | int sig; |
2725 | |
|
2726 | 0 | if (bfd_seek (abfd, hdr->p_offset, SEEK_SET) != 0) |
2727 | 0 | return false; |
2728 | 0 | if (bfd_read (&sig, 4, abfd) != 4) |
2729 | 0 | return false; |
2730 | | |
2731 | 0 | elf_tdata (abfd)->core->signal = sig; |
2732 | |
|
2733 | 0 | if (!_bfd_elf_make_section_from_phdr (abfd, hdr, sec_index, typename)) |
2734 | 0 | return false; |
2735 | | |
2736 | | /* GDB uses the ".reg" section to read register contents. */ |
2737 | 0 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", hdr->p_filesz, |
2738 | 0 | hdr->p_offset); |
2739 | 0 | } |
2740 | | |
2741 | 0 | if (hdr->p_type == PT_HP_CORE_LOADABLE |
2742 | 0 | || hdr->p_type == PT_HP_CORE_STACK |
2743 | 0 | || hdr->p_type == PT_HP_CORE_MMF) |
2744 | 0 | hdr->p_type = PT_LOAD; |
2745 | |
|
2746 | 0 | return _bfd_elf_make_section_from_phdr (abfd, hdr, sec_index, typename); |
2747 | 0 | } |
2748 | | |
2749 | | /* Hook called by the linker routine which adds symbols from an object |
2750 | | file. HP's libraries define symbols with HP specific section |
2751 | | indices, which we have to handle. */ |
2752 | | |
2753 | | static bool |
2754 | | elf_hppa_add_symbol_hook (bfd *abfd, |
2755 | | struct bfd_link_info *info ATTRIBUTE_UNUSED, |
2756 | | Elf_Internal_Sym *sym, |
2757 | | const char **namep ATTRIBUTE_UNUSED, |
2758 | | flagword *flagsp ATTRIBUTE_UNUSED, |
2759 | | asection **secp, |
2760 | | bfd_vma *valp) |
2761 | 0 | { |
2762 | 0 | unsigned int sec_index = sym->st_shndx; |
2763 | |
|
2764 | 0 | switch (sec_index) |
2765 | 0 | { |
2766 | 0 | case SHN_PARISC_ANSI_COMMON: |
2767 | 0 | *secp = bfd_make_section_old_way (abfd, ".PARISC.ansi.common"); |
2768 | 0 | (*secp)->flags |= SEC_IS_COMMON; |
2769 | 0 | *valp = sym->st_size; |
2770 | 0 | break; |
2771 | | |
2772 | 0 | case SHN_PARISC_HUGE_COMMON: |
2773 | 0 | *secp = bfd_make_section_old_way (abfd, ".PARISC.huge.common"); |
2774 | 0 | (*secp)->flags |= SEC_IS_COMMON; |
2775 | 0 | *valp = sym->st_size; |
2776 | 0 | break; |
2777 | 0 | } |
2778 | | |
2779 | 0 | return true; |
2780 | 0 | } |
2781 | | |
2782 | | static bool |
2783 | | elf_hppa_unmark_useless_dynamic_symbols (struct elf_link_hash_entry *h, |
2784 | | void *data) |
2785 | 0 | { |
2786 | 0 | struct bfd_link_info *info = data; |
2787 | | |
2788 | | /* If we are not creating a shared library, and this symbol is |
2789 | | referenced by a shared library but is not defined anywhere, then |
2790 | | the generic code will warn that it is undefined. |
2791 | | |
2792 | | This behavior is undesirable on HPs since the standard shared |
2793 | | libraries contain references to undefined symbols. |
2794 | | |
2795 | | So we twiddle the flags associated with such symbols so that they |
2796 | | will not trigger the warning. ?!? FIXME. This is horribly fragile. |
2797 | | |
2798 | | Ultimately we should have better controls over the generic ELF BFD |
2799 | | linker code. */ |
2800 | 0 | if (! bfd_link_relocatable (info) |
2801 | 0 | && info->unresolved_syms_in_shared_libs != RM_IGNORE |
2802 | 0 | && h->root.type == bfd_link_hash_undefined |
2803 | 0 | && h->ref_dynamic |
2804 | 0 | && !h->ref_regular) |
2805 | 0 | { |
2806 | 0 | h->ref_dynamic = 0; |
2807 | 0 | h->pointer_equality_needed = 1; |
2808 | 0 | } |
2809 | |
|
2810 | 0 | return true; |
2811 | 0 | } |
2812 | | |
2813 | | static bool |
2814 | | elf_hppa_remark_useless_dynamic_symbols (struct elf_link_hash_entry *h, |
2815 | | void *data) |
2816 | 0 | { |
2817 | 0 | struct bfd_link_info *info = data; |
2818 | | |
2819 | | /* If we are not creating a shared library, and this symbol is |
2820 | | referenced by a shared library but is not defined anywhere, then |
2821 | | the generic code will warn that it is undefined. |
2822 | | |
2823 | | This behavior is undesirable on HPs since the standard shared |
2824 | | libraries contain references to undefined symbols. |
2825 | | |
2826 | | So we twiddle the flags associated with such symbols so that they |
2827 | | will not trigger the warning. ?!? FIXME. This is horribly fragile. |
2828 | | |
2829 | | Ultimately we should have better controls over the generic ELF BFD |
2830 | | linker code. */ |
2831 | 0 | if (! bfd_link_relocatable (info) |
2832 | 0 | && info->unresolved_syms_in_shared_libs != RM_IGNORE |
2833 | 0 | && h->root.type == bfd_link_hash_undefined |
2834 | 0 | && !h->ref_dynamic |
2835 | 0 | && !h->ref_regular |
2836 | 0 | && h->pointer_equality_needed) |
2837 | 0 | { |
2838 | 0 | h->ref_dynamic = 1; |
2839 | 0 | h->pointer_equality_needed = 0; |
2840 | 0 | } |
2841 | |
|
2842 | 0 | return true; |
2843 | 0 | } |
2844 | | |
2845 | | static bool |
2846 | | elf_hppa_is_dynamic_loader_symbol (const char *name) |
2847 | 0 | { |
2848 | 0 | return (! strcmp (name, "__CPU_REVISION") |
2849 | 0 | || ! strcmp (name, "__CPU_KEYBITS_1") |
2850 | 0 | || ! strcmp (name, "__SYSTEM_ID_D") |
2851 | 0 | || ! strcmp (name, "__FPU_MODEL") |
2852 | 0 | || ! strcmp (name, "__FPU_REVISION") |
2853 | 0 | || ! strcmp (name, "__ARGC") |
2854 | 0 | || ! strcmp (name, "__ARGV") |
2855 | 0 | || ! strcmp (name, "__ENVP") |
2856 | 0 | || ! strcmp (name, "__TLS_SIZE_D") |
2857 | 0 | || ! strcmp (name, "__LOAD_INFO") |
2858 | 0 | || ! strcmp (name, "__systab")); |
2859 | 0 | } |
2860 | | |
2861 | | /* Record the lowest address for the data and text segments. */ |
2862 | | static void |
2863 | | elf_hppa_record_segment_addrs (bfd *abfd, |
2864 | | asection *section, |
2865 | | void *data) |
2866 | 0 | { |
2867 | 0 | struct elf64_hppa_link_hash_table *hppa_info = data; |
2868 | |
|
2869 | 0 | if ((section->flags & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) |
2870 | 0 | { |
2871 | 0 | bfd_vma value; |
2872 | 0 | Elf_Internal_Phdr *p; |
2873 | |
|
2874 | 0 | p = _bfd_elf_find_segment_containing_section (abfd, section->output_section); |
2875 | 0 | BFD_ASSERT (p != NULL); |
2876 | 0 | value = p->p_vaddr; |
2877 | |
|
2878 | 0 | if (section->flags & SEC_READONLY) |
2879 | 0 | { |
2880 | 0 | if (value < hppa_info->text_segment_base) |
2881 | 0 | hppa_info->text_segment_base = value; |
2882 | 0 | } |
2883 | 0 | else |
2884 | 0 | { |
2885 | 0 | if (value < hppa_info->data_segment_base) |
2886 | 0 | hppa_info->data_segment_base = value; |
2887 | 0 | } |
2888 | 0 | } |
2889 | 0 | } |
2890 | | |
2891 | | /* Called after we have seen all the input files/sections, but before |
2892 | | final symbol resolution and section placement has been determined. |
2893 | | |
2894 | | We use this hook to (possibly) provide a value for __gp, then we |
2895 | | fall back to the generic ELF final link routine. */ |
2896 | | |
2897 | | static bool |
2898 | | elf_hppa_final_link (bfd *abfd, struct bfd_link_info *info) |
2899 | 0 | { |
2900 | 0 | struct stat buf; |
2901 | 0 | struct elf64_hppa_link_hash_table *hppa_info = hppa_link_hash_table (info); |
2902 | |
|
2903 | 0 | if (hppa_info == NULL) |
2904 | 0 | return false; |
2905 | | |
2906 | 0 | if (! bfd_link_relocatable (info)) |
2907 | 0 | { |
2908 | 0 | struct elf_link_hash_entry *gp; |
2909 | 0 | bfd_vma gp_val; |
2910 | | |
2911 | | /* The linker script defines a value for __gp iff it was referenced |
2912 | | by one of the objects being linked. First try to find the symbol |
2913 | | in the hash table. If that fails, just compute the value __gp |
2914 | | should have had. */ |
2915 | 0 | gp = elf_link_hash_lookup (elf_hash_table (info), "__gp", false, |
2916 | 0 | false, false); |
2917 | |
|
2918 | 0 | if (gp) |
2919 | 0 | { |
2920 | | |
2921 | | /* Adjust the value of __gp as we may want to slide it into the |
2922 | | .plt section so that the stubs can access PLT entries without |
2923 | | using an addil sequence. */ |
2924 | 0 | gp->root.u.def.value += hppa_info->gp_offset; |
2925 | |
|
2926 | 0 | gp_val = (gp->root.u.def.section->output_section->vma |
2927 | 0 | + gp->root.u.def.section->output_offset |
2928 | 0 | + gp->root.u.def.value); |
2929 | 0 | } |
2930 | 0 | else |
2931 | 0 | { |
2932 | 0 | asection *sec; |
2933 | | |
2934 | | /* First look for a .plt section. If found, then __gp is the |
2935 | | address of the .plt + gp_offset. |
2936 | | |
2937 | | If no .plt is found, then look for .dlt, .opd and .data (in |
2938 | | that order) and set __gp to the base address of whichever |
2939 | | section is found first. */ |
2940 | |
|
2941 | 0 | sec = hppa_info->root.splt; |
2942 | 0 | if (sec && ! (sec->flags & SEC_EXCLUDE)) |
2943 | 0 | gp_val = (sec->output_offset |
2944 | 0 | + sec->output_section->vma |
2945 | 0 | + hppa_info->gp_offset); |
2946 | 0 | else |
2947 | 0 | { |
2948 | 0 | sec = hppa_info->dlt_sec; |
2949 | 0 | if (!sec || (sec->flags & SEC_EXCLUDE)) |
2950 | 0 | sec = hppa_info->opd_sec; |
2951 | 0 | if (!sec || (sec->flags & SEC_EXCLUDE)) |
2952 | 0 | sec = bfd_get_section_by_name (abfd, ".data"); |
2953 | 0 | if (!sec || (sec->flags & SEC_EXCLUDE)) |
2954 | 0 | gp_val = 0; |
2955 | 0 | else |
2956 | 0 | gp_val = sec->output_offset + sec->output_section->vma; |
2957 | 0 | } |
2958 | 0 | } |
2959 | | |
2960 | | /* Install whatever value we found/computed for __gp. */ |
2961 | 0 | _bfd_set_gp_value (abfd, gp_val); |
2962 | 0 | } |
2963 | | |
2964 | | /* We need to know the base of the text and data segments so that we |
2965 | | can perform SEGREL relocations. We will record the base addresses |
2966 | | when we encounter the first SEGREL relocation. */ |
2967 | 0 | hppa_info->text_segment_base = (bfd_vma)-1; |
2968 | 0 | hppa_info->data_segment_base = (bfd_vma)-1; |
2969 | | |
2970 | | /* HP's shared libraries have references to symbols that are not |
2971 | | defined anywhere. The generic ELF BFD linker code will complain |
2972 | | about such symbols. |
2973 | | |
2974 | | So we detect the losing case and arrange for the flags on the symbol |
2975 | | to indicate that it was never referenced. This keeps the generic |
2976 | | ELF BFD link code happy and appears to not create any secondary |
2977 | | problems. Ultimately we need a way to control the behavior of the |
2978 | | generic ELF BFD link code better. */ |
2979 | 0 | elf_link_hash_traverse (elf_hash_table (info), |
2980 | 0 | elf_hppa_unmark_useless_dynamic_symbols, |
2981 | 0 | info); |
2982 | | |
2983 | | /* Invoke the regular ELF backend linker to do all the work. */ |
2984 | 0 | if (!bfd_elf_final_link (abfd, info)) |
2985 | 0 | return false; |
2986 | | |
2987 | 0 | elf_link_hash_traverse (elf_hash_table (info), |
2988 | 0 | elf_hppa_remark_useless_dynamic_symbols, |
2989 | 0 | info); |
2990 | | |
2991 | | /* If we're producing a final executable, sort the contents of the |
2992 | | unwind section. */ |
2993 | 0 | if (bfd_link_relocatable (info)) |
2994 | 0 | return true; |
2995 | | |
2996 | | /* Do not attempt to sort non-regular files. This is here |
2997 | | especially for configure scripts and kernel builds which run |
2998 | | tests with "ld [...] -o /dev/null". */ |
2999 | 0 | if (stat (bfd_get_filename (abfd), &buf) != 0 |
3000 | 0 | || !S_ISREG(buf.st_mode)) |
3001 | 0 | return true; |
3002 | | |
3003 | 0 | return elf_hppa_sort_unwind (abfd); |
3004 | 0 | } |
3005 | | |
3006 | | /* Relocate the given INSN. VALUE should be the actual value we want |
3007 | | to insert into the instruction, ie by this point we should not be |
3008 | | concerned with computing an offset relative to the DLT, PC, etc. |
3009 | | Instead this routine is meant to handle the bit manipulations needed |
3010 | | to insert the relocation into the given instruction. */ |
3011 | | |
3012 | | static int |
3013 | | elf_hppa_relocate_insn (int insn, int sym_value, unsigned int r_type) |
3014 | 0 | { |
3015 | 0 | switch (r_type) |
3016 | 0 | { |
3017 | | /* This is any 22 bit branch. In PA2.0 syntax it corresponds to |
3018 | | the "B" instruction. */ |
3019 | 0 | case R_PARISC_PCREL22F: |
3020 | 0 | case R_PARISC_PCREL22C: |
3021 | 0 | return (insn & ~0x3ff1ffd) | re_assemble_22 (sym_value); |
3022 | | |
3023 | | /* This is any 12 bit branch. */ |
3024 | 0 | case R_PARISC_PCREL12F: |
3025 | 0 | return (insn & ~0x1ffd) | re_assemble_12 (sym_value); |
3026 | | |
3027 | | /* This is any 17 bit branch. In PA2.0 syntax it also corresponds |
3028 | | to the "B" instruction as well as BE. */ |
3029 | 0 | case R_PARISC_PCREL17F: |
3030 | 0 | case R_PARISC_DIR17F: |
3031 | 0 | case R_PARISC_DIR17R: |
3032 | 0 | case R_PARISC_PCREL17C: |
3033 | 0 | case R_PARISC_PCREL17R: |
3034 | 0 | return (insn & ~0x1f1ffd) | re_assemble_17 (sym_value); |
3035 | | |
3036 | | /* ADDIL or LDIL instructions. */ |
3037 | 0 | case R_PARISC_DLTREL21L: |
3038 | 0 | case R_PARISC_DLTIND21L: |
3039 | 0 | case R_PARISC_LTOFF_FPTR21L: |
3040 | 0 | case R_PARISC_PCREL21L: |
3041 | 0 | case R_PARISC_LTOFF_TP21L: |
3042 | 0 | case R_PARISC_DPREL21L: |
3043 | 0 | case R_PARISC_PLTOFF21L: |
3044 | 0 | case R_PARISC_DIR21L: |
3045 | 0 | return (insn & ~0x1fffff) | re_assemble_21 (sym_value); |
3046 | | |
3047 | | /* LDO and integer loads/stores with 14 bit displacements. */ |
3048 | 0 | case R_PARISC_DLTREL14R: |
3049 | 0 | case R_PARISC_DLTREL14F: |
3050 | 0 | case R_PARISC_DLTIND14R: |
3051 | 0 | case R_PARISC_DLTIND14F: |
3052 | 0 | case R_PARISC_LTOFF_FPTR14R: |
3053 | 0 | case R_PARISC_PCREL14R: |
3054 | 0 | case R_PARISC_PCREL14F: |
3055 | 0 | case R_PARISC_LTOFF_TP14R: |
3056 | 0 | case R_PARISC_LTOFF_TP14F: |
3057 | 0 | case R_PARISC_DPREL14R: |
3058 | 0 | case R_PARISC_DPREL14F: |
3059 | 0 | case R_PARISC_PLTOFF14R: |
3060 | 0 | case R_PARISC_PLTOFF14F: |
3061 | 0 | case R_PARISC_DIR14R: |
3062 | 0 | case R_PARISC_DIR14F: |
3063 | 0 | return (insn & ~0x3fff) | low_sign_unext (sym_value, 14); |
3064 | | |
3065 | | /* PA2.0W LDO and integer loads/stores with 16 bit displacements. */ |
3066 | 0 | case R_PARISC_LTOFF_FPTR16F: |
3067 | 0 | case R_PARISC_PCREL16F: |
3068 | 0 | case R_PARISC_LTOFF_TP16F: |
3069 | 0 | case R_PARISC_GPREL16F: |
3070 | 0 | case R_PARISC_PLTOFF16F: |
3071 | 0 | case R_PARISC_DIR16F: |
3072 | 0 | case R_PARISC_LTOFF16F: |
3073 | 0 | return (insn & ~0xffff) | re_assemble_16 (sym_value); |
3074 | | |
3075 | | /* Doubleword loads and stores with a 14 bit displacement. */ |
3076 | 0 | case R_PARISC_DLTREL14DR: |
3077 | 0 | case R_PARISC_DLTIND14DR: |
3078 | 0 | case R_PARISC_LTOFF_FPTR14DR: |
3079 | 0 | case R_PARISC_LTOFF_FPTR16DF: |
3080 | 0 | case R_PARISC_PCREL14DR: |
3081 | 0 | case R_PARISC_PCREL16DF: |
3082 | 0 | case R_PARISC_LTOFF_TP14DR: |
3083 | 0 | case R_PARISC_LTOFF_TP16DF: |
3084 | 0 | case R_PARISC_DPREL14DR: |
3085 | 0 | case R_PARISC_GPREL16DF: |
3086 | 0 | case R_PARISC_PLTOFF14DR: |
3087 | 0 | case R_PARISC_PLTOFF16DF: |
3088 | 0 | case R_PARISC_DIR14DR: |
3089 | 0 | case R_PARISC_DIR16DF: |
3090 | 0 | case R_PARISC_LTOFF16DF: |
3091 | 0 | return (insn & ~0x3ff1) | (((sym_value & 0x2000) >> 13) |
3092 | 0 | | ((sym_value & 0x1ff8) << 1)); |
3093 | | |
3094 | | /* Floating point single word load/store instructions. */ |
3095 | 0 | case R_PARISC_DLTREL14WR: |
3096 | 0 | case R_PARISC_DLTIND14WR: |
3097 | 0 | case R_PARISC_LTOFF_FPTR14WR: |
3098 | 0 | case R_PARISC_LTOFF_FPTR16WF: |
3099 | 0 | case R_PARISC_PCREL14WR: |
3100 | 0 | case R_PARISC_PCREL16WF: |
3101 | 0 | case R_PARISC_LTOFF_TP14WR: |
3102 | 0 | case R_PARISC_LTOFF_TP16WF: |
3103 | 0 | case R_PARISC_DPREL14WR: |
3104 | 0 | case R_PARISC_GPREL16WF: |
3105 | 0 | case R_PARISC_PLTOFF14WR: |
3106 | 0 | case R_PARISC_PLTOFF16WF: |
3107 | 0 | case R_PARISC_DIR16WF: |
3108 | 0 | case R_PARISC_DIR14WR: |
3109 | 0 | case R_PARISC_LTOFF16WF: |
3110 | 0 | return (insn & ~0x3ff9) | (((sym_value & 0x2000) >> 13) |
3111 | 0 | | ((sym_value & 0x1ffc) << 1)); |
3112 | | |
3113 | 0 | default: |
3114 | 0 | return insn; |
3115 | 0 | } |
3116 | 0 | } |
3117 | | |
3118 | | /* Compute the value for a relocation (REL) during a final link stage, |
3119 | | then insert the value into the proper location in CONTENTS. |
3120 | | |
3121 | | VALUE is a tentative value for the relocation and may be overridden |
3122 | | and modified here based on the specific relocation to be performed. |
3123 | | |
3124 | | For example we do conversions for PC-relative branches in this routine |
3125 | | or redirection of calls to external routines to stubs. |
3126 | | |
3127 | | The work of actually applying the relocation is left to a helper |
3128 | | routine in an attempt to reduce the complexity and size of this |
3129 | | function. */ |
3130 | | |
3131 | | static bfd_reloc_status_type |
3132 | | elf_hppa_final_link_relocate (Elf_Internal_Rela *rel, |
3133 | | bfd *input_bfd, |
3134 | | bfd *output_bfd, |
3135 | | asection *input_section, |
3136 | | bfd_byte *contents, |
3137 | | bfd_vma value, |
3138 | | struct bfd_link_info *info, |
3139 | | asection *sym_sec, |
3140 | | struct elf_link_hash_entry *eh) |
3141 | 0 | { |
3142 | 0 | struct elf64_hppa_link_hash_table *hppa_info = hppa_link_hash_table (info); |
3143 | 0 | struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); |
3144 | 0 | bfd_vma *local_offsets; |
3145 | 0 | Elf_Internal_Shdr *symtab_hdr; |
3146 | 0 | int insn; |
3147 | 0 | bfd_vma max_branch_offset = 0; |
3148 | 0 | bfd_vma offset = rel->r_offset; |
3149 | 0 | bfd_signed_vma addend = rel->r_addend; |
3150 | 0 | reloc_howto_type *howto = elf_hppa_howto_table + ELF_R_TYPE (rel->r_info); |
3151 | 0 | unsigned int r_symndx = ELF_R_SYM (rel->r_info); |
3152 | 0 | unsigned int r_type = howto->type; |
3153 | 0 | bfd_byte *hit_data = contents + offset; |
3154 | |
|
3155 | 0 | if (hppa_info == NULL) |
3156 | 0 | return bfd_reloc_notsupported; |
3157 | | |
3158 | 0 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
3159 | 0 | local_offsets = elf_local_got_offsets (input_bfd); |
3160 | 0 | insn = bfd_get_32 (input_bfd, hit_data); |
3161 | |
|
3162 | 0 | switch (r_type) |
3163 | 0 | { |
3164 | 0 | case R_PARISC_NONE: |
3165 | 0 | break; |
3166 | | |
3167 | | /* Basic function call support. |
3168 | | |
3169 | | Note for a call to a function defined in another dynamic library |
3170 | | we want to redirect the call to a stub. */ |
3171 | | |
3172 | | /* PC relative relocs without an implicit offset. */ |
3173 | 0 | case R_PARISC_PCREL21L: |
3174 | 0 | case R_PARISC_PCREL14R: |
3175 | 0 | case R_PARISC_PCREL14F: |
3176 | 0 | case R_PARISC_PCREL14WR: |
3177 | 0 | case R_PARISC_PCREL14DR: |
3178 | 0 | case R_PARISC_PCREL16F: |
3179 | 0 | case R_PARISC_PCREL16WF: |
3180 | 0 | case R_PARISC_PCREL16DF: |
3181 | 0 | { |
3182 | | /* If this is a call to a function defined in another dynamic |
3183 | | library, then redirect the call to the local stub for this |
3184 | | function. */ |
3185 | 0 | if (sym_sec == NULL || sym_sec->output_section == NULL) |
3186 | 0 | value = (hh->stub_offset + hppa_info->stub_sec->output_offset |
3187 | 0 | + hppa_info->stub_sec->output_section->vma); |
3188 | | |
3189 | | /* Turn VALUE into a proper PC relative address. */ |
3190 | 0 | value -= (offset + input_section->output_offset |
3191 | 0 | + input_section->output_section->vma); |
3192 | | |
3193 | | /* Adjust for any field selectors. */ |
3194 | 0 | if (r_type == R_PARISC_PCREL21L) |
3195 | 0 | value = hppa_field_adjust (value, -8 + addend, e_lsel); |
3196 | 0 | else if (r_type == R_PARISC_PCREL14F |
3197 | 0 | || r_type == R_PARISC_PCREL16F |
3198 | 0 | || r_type == R_PARISC_PCREL16WF |
3199 | 0 | || r_type == R_PARISC_PCREL16DF) |
3200 | 0 | value = hppa_field_adjust (value, -8 + addend, e_fsel); |
3201 | 0 | else |
3202 | 0 | value = hppa_field_adjust (value, -8 + addend, e_rsel); |
3203 | | |
3204 | | /* Apply the relocation to the given instruction. */ |
3205 | 0 | insn = elf_hppa_relocate_insn (insn, (int) value, r_type); |
3206 | 0 | break; |
3207 | 0 | } |
3208 | | |
3209 | 0 | case R_PARISC_PCREL12F: |
3210 | 0 | case R_PARISC_PCREL22F: |
3211 | 0 | case R_PARISC_PCREL17F: |
3212 | 0 | case R_PARISC_PCREL22C: |
3213 | 0 | case R_PARISC_PCREL17C: |
3214 | 0 | case R_PARISC_PCREL17R: |
3215 | 0 | { |
3216 | | /* If this is a call to a function defined in another dynamic |
3217 | | library, then redirect the call to the local stub for this |
3218 | | function. */ |
3219 | 0 | if (sym_sec == NULL || sym_sec->output_section == NULL) |
3220 | 0 | value = (hh->stub_offset + hppa_info->stub_sec->output_offset |
3221 | 0 | + hppa_info->stub_sec->output_section->vma); |
3222 | | |
3223 | | /* Turn VALUE into a proper PC relative address. */ |
3224 | 0 | value -= (offset + input_section->output_offset |
3225 | 0 | + input_section->output_section->vma); |
3226 | 0 | addend -= 8; |
3227 | |
|
3228 | 0 | if (r_type == (unsigned int) R_PARISC_PCREL22F) |
3229 | 0 | max_branch_offset = (1 << (22-1)) << 2; |
3230 | 0 | else if (r_type == (unsigned int) R_PARISC_PCREL17F) |
3231 | 0 | max_branch_offset = (1 << (17-1)) << 2; |
3232 | 0 | else if (r_type == (unsigned int) R_PARISC_PCREL12F) |
3233 | 0 | max_branch_offset = (1 << (12-1)) << 2; |
3234 | | |
3235 | | /* Make sure we can reach the branch target. */ |
3236 | 0 | if (max_branch_offset != 0 |
3237 | 0 | && value + addend + max_branch_offset >= 2*max_branch_offset) |
3238 | 0 | { |
3239 | 0 | _bfd_error_handler |
3240 | | /* xgettext:c-format */ |
3241 | 0 | (_("%pB(%pA+%#" PRIx64 "): cannot reach %s"), |
3242 | 0 | input_bfd, |
3243 | 0 | input_section, |
3244 | 0 | (uint64_t) offset, |
3245 | 0 | eh ? eh->root.root.string : "unknown"); |
3246 | 0 | bfd_set_error (bfd_error_bad_value); |
3247 | 0 | return bfd_reloc_overflow; |
3248 | 0 | } |
3249 | | |
3250 | | /* Adjust for any field selectors. */ |
3251 | 0 | if (r_type == R_PARISC_PCREL17R) |
3252 | 0 | value = hppa_field_adjust (value, addend, e_rsel); |
3253 | 0 | else |
3254 | 0 | value = hppa_field_adjust (value, addend, e_fsel); |
3255 | | |
3256 | | /* All branches are implicitly shifted by 2 places. */ |
3257 | 0 | value >>= 2; |
3258 | | |
3259 | | /* Apply the relocation to the given instruction. */ |
3260 | 0 | insn = elf_hppa_relocate_insn (insn, (int) value, r_type); |
3261 | 0 | break; |
3262 | 0 | } |
3263 | | |
3264 | | /* Indirect references to data through the DLT. */ |
3265 | 0 | case R_PARISC_DLTIND14R: |
3266 | 0 | case R_PARISC_DLTIND14F: |
3267 | 0 | case R_PARISC_DLTIND14DR: |
3268 | 0 | case R_PARISC_DLTIND14WR: |
3269 | 0 | case R_PARISC_DLTIND21L: |
3270 | 0 | case R_PARISC_LTOFF_FPTR14R: |
3271 | 0 | case R_PARISC_LTOFF_FPTR14DR: |
3272 | 0 | case R_PARISC_LTOFF_FPTR14WR: |
3273 | 0 | case R_PARISC_LTOFF_FPTR21L: |
3274 | 0 | case R_PARISC_LTOFF_FPTR16F: |
3275 | 0 | case R_PARISC_LTOFF_FPTR16WF: |
3276 | 0 | case R_PARISC_LTOFF_FPTR16DF: |
3277 | 0 | case R_PARISC_LTOFF_TP21L: |
3278 | 0 | case R_PARISC_LTOFF_TP14R: |
3279 | 0 | case R_PARISC_LTOFF_TP14F: |
3280 | 0 | case R_PARISC_LTOFF_TP14WR: |
3281 | 0 | case R_PARISC_LTOFF_TP14DR: |
3282 | 0 | case R_PARISC_LTOFF_TP16F: |
3283 | 0 | case R_PARISC_LTOFF_TP16WF: |
3284 | 0 | case R_PARISC_LTOFF_TP16DF: |
3285 | 0 | case R_PARISC_LTOFF16F: |
3286 | 0 | case R_PARISC_LTOFF16WF: |
3287 | 0 | case R_PARISC_LTOFF16DF: |
3288 | 0 | { |
3289 | 0 | bfd_vma off; |
3290 | | |
3291 | | /* If this relocation was against a local symbol, then we still |
3292 | | have not set up the DLT entry (it's not convenient to do so |
3293 | | in the "finalize_dlt" routine because it is difficult to get |
3294 | | to the local symbol's value). |
3295 | | |
3296 | | So, if this is a local symbol (h == NULL), then we need to |
3297 | | fill in its DLT entry. |
3298 | | |
3299 | | Similarly we may still need to set up an entry in .opd for |
3300 | | a local function which had its address taken. */ |
3301 | 0 | if (hh == NULL) |
3302 | 0 | { |
3303 | 0 | bfd_vma *local_opd_offsets, *local_dlt_offsets; |
3304 | |
|
3305 | 0 | if (local_offsets == NULL) |
3306 | 0 | abort (); |
3307 | | |
3308 | | /* Now do .opd creation if needed. */ |
3309 | 0 | if (r_type == R_PARISC_LTOFF_FPTR14R |
3310 | 0 | || r_type == R_PARISC_LTOFF_FPTR14DR |
3311 | 0 | || r_type == R_PARISC_LTOFF_FPTR14WR |
3312 | 0 | || r_type == R_PARISC_LTOFF_FPTR21L |
3313 | 0 | || r_type == R_PARISC_LTOFF_FPTR16F |
3314 | 0 | || r_type == R_PARISC_LTOFF_FPTR16WF |
3315 | 0 | || r_type == R_PARISC_LTOFF_FPTR16DF) |
3316 | 0 | { |
3317 | 0 | local_opd_offsets = local_offsets + 2 * symtab_hdr->sh_info; |
3318 | 0 | off = local_opd_offsets[r_symndx]; |
3319 | | |
3320 | | /* The last bit records whether we've already initialised |
3321 | | this local .opd entry. */ |
3322 | 0 | if ((off & 1) != 0) |
3323 | 0 | { |
3324 | 0 | BFD_ASSERT (off != (bfd_vma) -1); |
3325 | 0 | off &= ~1; |
3326 | 0 | } |
3327 | 0 | else |
3328 | 0 | { |
3329 | 0 | local_opd_offsets[r_symndx] |= 1; |
3330 | | |
3331 | | /* The first two words of an .opd entry are zero. */ |
3332 | 0 | memset (hppa_info->opd_sec->contents + off, 0, 16); |
3333 | | |
3334 | | /* The next word is the address of the function. */ |
3335 | 0 | bfd_put_64 (hppa_info->opd_sec->owner, value + addend, |
3336 | 0 | (hppa_info->opd_sec->contents + off + 16)); |
3337 | | |
3338 | | /* The last word is our local __gp value. */ |
3339 | 0 | value = _bfd_get_gp_value (info->output_bfd); |
3340 | 0 | bfd_put_64 (hppa_info->opd_sec->owner, value, |
3341 | 0 | (hppa_info->opd_sec->contents + off + 24)); |
3342 | 0 | } |
3343 | | |
3344 | | /* The DLT value is the address of the .opd entry. */ |
3345 | 0 | value = (off |
3346 | 0 | + hppa_info->opd_sec->output_offset |
3347 | 0 | + hppa_info->opd_sec->output_section->vma); |
3348 | 0 | addend = 0; |
3349 | 0 | } |
3350 | |
|
3351 | 0 | local_dlt_offsets = local_offsets; |
3352 | 0 | off = local_dlt_offsets[r_symndx]; |
3353 | |
|
3354 | 0 | if ((off & 1) != 0) |
3355 | 0 | { |
3356 | 0 | BFD_ASSERT (off != (bfd_vma) -1); |
3357 | 0 | off &= ~1; |
3358 | 0 | } |
3359 | 0 | else |
3360 | 0 | { |
3361 | 0 | local_dlt_offsets[r_symndx] |= 1; |
3362 | 0 | bfd_put_64 (hppa_info->dlt_sec->owner, |
3363 | 0 | value + addend, |
3364 | 0 | hppa_info->dlt_sec->contents + off); |
3365 | 0 | } |
3366 | 0 | } |
3367 | 0 | else |
3368 | 0 | off = hh->dlt_offset; |
3369 | | |
3370 | | /* We want the value of the DLT offset for this symbol, not |
3371 | | the symbol's actual address. Note that __gp may not point |
3372 | | to the start of the DLT, so we have to compute the absolute |
3373 | | address, then subtract out the value of __gp. */ |
3374 | 0 | value = (off |
3375 | 0 | + hppa_info->dlt_sec->output_offset |
3376 | 0 | + hppa_info->dlt_sec->output_section->vma); |
3377 | 0 | value -= _bfd_get_gp_value (output_bfd); |
3378 | | |
3379 | | /* All DLTIND relocations are basically the same at this point, |
3380 | | except that we need different field selectors for the 21bit |
3381 | | version vs the 14bit versions. */ |
3382 | 0 | if (r_type == R_PARISC_DLTIND21L |
3383 | 0 | || r_type == R_PARISC_LTOFF_FPTR21L |
3384 | 0 | || r_type == R_PARISC_LTOFF_TP21L) |
3385 | 0 | value = hppa_field_adjust (value, 0, e_lsel); |
3386 | 0 | else if (r_type == R_PARISC_DLTIND14F |
3387 | 0 | || r_type == R_PARISC_LTOFF_FPTR16F |
3388 | 0 | || r_type == R_PARISC_LTOFF_FPTR16WF |
3389 | 0 | || r_type == R_PARISC_LTOFF_FPTR16DF |
3390 | 0 | || r_type == R_PARISC_LTOFF16F |
3391 | 0 | || r_type == R_PARISC_LTOFF16DF |
3392 | 0 | || r_type == R_PARISC_LTOFF16WF |
3393 | 0 | || r_type == R_PARISC_LTOFF_TP16F |
3394 | 0 | || r_type == R_PARISC_LTOFF_TP16WF |
3395 | 0 | || r_type == R_PARISC_LTOFF_TP16DF) |
3396 | 0 | value = hppa_field_adjust (value, 0, e_fsel); |
3397 | 0 | else |
3398 | 0 | value = hppa_field_adjust (value, 0, e_rsel); |
3399 | |
|
3400 | 0 | insn = elf_hppa_relocate_insn (insn, (int) value, r_type); |
3401 | 0 | break; |
3402 | 0 | } |
3403 | | |
3404 | 0 | case R_PARISC_DLTREL14R: |
3405 | 0 | case R_PARISC_DLTREL14F: |
3406 | 0 | case R_PARISC_DLTREL14DR: |
3407 | 0 | case R_PARISC_DLTREL14WR: |
3408 | 0 | case R_PARISC_DLTREL21L: |
3409 | 0 | case R_PARISC_DPREL21L: |
3410 | 0 | case R_PARISC_DPREL14WR: |
3411 | 0 | case R_PARISC_DPREL14DR: |
3412 | 0 | case R_PARISC_DPREL14R: |
3413 | 0 | case R_PARISC_DPREL14F: |
3414 | 0 | case R_PARISC_GPREL16F: |
3415 | 0 | case R_PARISC_GPREL16WF: |
3416 | 0 | case R_PARISC_GPREL16DF: |
3417 | 0 | { |
3418 | | /* Subtract out the global pointer value to make value a DLT |
3419 | | relative address. */ |
3420 | 0 | value -= _bfd_get_gp_value (output_bfd); |
3421 | | |
3422 | | /* All DLTREL relocations are basically the same at this point, |
3423 | | except that we need different field selectors for the 21bit |
3424 | | version vs the 14bit versions. */ |
3425 | 0 | if (r_type == R_PARISC_DLTREL21L |
3426 | 0 | || r_type == R_PARISC_DPREL21L) |
3427 | 0 | value = hppa_field_adjust (value, addend, e_lrsel); |
3428 | 0 | else if (r_type == R_PARISC_DLTREL14F |
3429 | 0 | || r_type == R_PARISC_DPREL14F |
3430 | 0 | || r_type == R_PARISC_GPREL16F |
3431 | 0 | || r_type == R_PARISC_GPREL16WF |
3432 | 0 | || r_type == R_PARISC_GPREL16DF) |
3433 | 0 | value = hppa_field_adjust (value, addend, e_fsel); |
3434 | 0 | else |
3435 | 0 | value = hppa_field_adjust (value, addend, e_rrsel); |
3436 | |
|
3437 | 0 | insn = elf_hppa_relocate_insn (insn, (int) value, r_type); |
3438 | 0 | break; |
3439 | 0 | } |
3440 | | |
3441 | 0 | case R_PARISC_DIR21L: |
3442 | 0 | case R_PARISC_DIR17R: |
3443 | 0 | case R_PARISC_DIR17F: |
3444 | 0 | case R_PARISC_DIR14R: |
3445 | 0 | case R_PARISC_DIR14F: |
3446 | 0 | case R_PARISC_DIR14WR: |
3447 | 0 | case R_PARISC_DIR14DR: |
3448 | 0 | case R_PARISC_DIR16F: |
3449 | 0 | case R_PARISC_DIR16WF: |
3450 | 0 | case R_PARISC_DIR16DF: |
3451 | 0 | { |
3452 | | /* All DIR relocations are basically the same at this point, |
3453 | | except that branch offsets need to be divided by four, and |
3454 | | we need different field selectors. Note that we don't |
3455 | | redirect absolute calls to local stubs. */ |
3456 | |
|
3457 | 0 | if (r_type == R_PARISC_DIR21L) |
3458 | 0 | value = hppa_field_adjust (value, addend, e_lrsel); |
3459 | 0 | else if (r_type == R_PARISC_DIR17F |
3460 | 0 | || r_type == R_PARISC_DIR16F |
3461 | 0 | || r_type == R_PARISC_DIR16WF |
3462 | 0 | || r_type == R_PARISC_DIR16DF |
3463 | 0 | || r_type == R_PARISC_DIR14F) |
3464 | 0 | value = hppa_field_adjust (value, addend, e_fsel); |
3465 | 0 | else |
3466 | 0 | value = hppa_field_adjust (value, addend, e_rrsel); |
3467 | |
|
3468 | 0 | if (r_type == R_PARISC_DIR17R || r_type == R_PARISC_DIR17F) |
3469 | | /* All branches are implicitly shifted by 2 places. */ |
3470 | 0 | value >>= 2; |
3471 | |
|
3472 | 0 | insn = elf_hppa_relocate_insn (insn, (int) value, r_type); |
3473 | 0 | break; |
3474 | 0 | } |
3475 | | |
3476 | 0 | case R_PARISC_PLTOFF21L: |
3477 | 0 | case R_PARISC_PLTOFF14R: |
3478 | 0 | case R_PARISC_PLTOFF14F: |
3479 | 0 | case R_PARISC_PLTOFF14WR: |
3480 | 0 | case R_PARISC_PLTOFF14DR: |
3481 | 0 | case R_PARISC_PLTOFF16F: |
3482 | 0 | case R_PARISC_PLTOFF16WF: |
3483 | 0 | case R_PARISC_PLTOFF16DF: |
3484 | 0 | { |
3485 | | /* We want the value of the PLT offset for this symbol, not |
3486 | | the symbol's actual address. Note that __gp may not point |
3487 | | to the start of the DLT, so we have to compute the absolute |
3488 | | address, then subtract out the value of __gp. */ |
3489 | 0 | value = (hh->plt_offset |
3490 | 0 | + hppa_info->root.splt->output_offset |
3491 | 0 | + hppa_info->root.splt->output_section->vma); |
3492 | 0 | value -= _bfd_get_gp_value (output_bfd); |
3493 | | |
3494 | | /* All PLTOFF relocations are basically the same at this point, |
3495 | | except that we need different field selectors for the 21bit |
3496 | | version vs the 14bit versions. */ |
3497 | 0 | if (r_type == R_PARISC_PLTOFF21L) |
3498 | 0 | value = hppa_field_adjust (value, addend, e_lrsel); |
3499 | 0 | else if (r_type == R_PARISC_PLTOFF14F |
3500 | 0 | || r_type == R_PARISC_PLTOFF16F |
3501 | 0 | || r_type == R_PARISC_PLTOFF16WF |
3502 | 0 | || r_type == R_PARISC_PLTOFF16DF) |
3503 | 0 | value = hppa_field_adjust (value, addend, e_fsel); |
3504 | 0 | else |
3505 | 0 | value = hppa_field_adjust (value, addend, e_rrsel); |
3506 | |
|
3507 | 0 | insn = elf_hppa_relocate_insn (insn, (int) value, r_type); |
3508 | 0 | break; |
3509 | 0 | } |
3510 | | |
3511 | 0 | case R_PARISC_LTOFF_FPTR32: |
3512 | 0 | { |
3513 | | /* FIXME: There used to be code here to create the FPTR itself if |
3514 | | the relocation was against a local symbol. But the code could |
3515 | | never have worked. If the assert below is ever triggered then |
3516 | | the code will need to be reinstated and fixed so that it does |
3517 | | what is needed. */ |
3518 | 0 | BFD_ASSERT (hh != NULL); |
3519 | | |
3520 | | /* We want the value of the DLT offset for this symbol, not |
3521 | | the symbol's actual address. Note that __gp may not point |
3522 | | to the start of the DLT, so we have to compute the absolute |
3523 | | address, then subtract out the value of __gp. */ |
3524 | 0 | value = (hh->dlt_offset |
3525 | 0 | + hppa_info->dlt_sec->output_offset |
3526 | 0 | + hppa_info->dlt_sec->output_section->vma); |
3527 | 0 | value -= _bfd_get_gp_value (output_bfd); |
3528 | 0 | bfd_put_32 (input_bfd, value, hit_data); |
3529 | 0 | return bfd_reloc_ok; |
3530 | 0 | } |
3531 | | |
3532 | 0 | case R_PARISC_LTOFF_FPTR64: |
3533 | 0 | case R_PARISC_LTOFF_TP64: |
3534 | 0 | { |
3535 | | /* We may still need to create the FPTR itself if it was for |
3536 | | a local symbol. */ |
3537 | 0 | if (eh == NULL && r_type == R_PARISC_LTOFF_FPTR64) |
3538 | 0 | { |
3539 | | /* The first two words of an .opd entry are zero. */ |
3540 | 0 | memset (hppa_info->opd_sec->contents + hh->opd_offset, 0, 16); |
3541 | | |
3542 | | /* The next word is the address of the function. */ |
3543 | 0 | bfd_put_64 (hppa_info->opd_sec->owner, value + addend, |
3544 | 0 | (hppa_info->opd_sec->contents |
3545 | 0 | + hh->opd_offset + 16)); |
3546 | | |
3547 | | /* The last word is our local __gp value. */ |
3548 | 0 | value = _bfd_get_gp_value (info->output_bfd); |
3549 | 0 | bfd_put_64 (hppa_info->opd_sec->owner, value, |
3550 | 0 | hppa_info->opd_sec->contents + hh->opd_offset + 24); |
3551 | | |
3552 | | /* The DLT value is the address of the .opd entry. */ |
3553 | 0 | value = (hh->opd_offset |
3554 | 0 | + hppa_info->opd_sec->output_offset |
3555 | 0 | + hppa_info->opd_sec->output_section->vma); |
3556 | |
|
3557 | 0 | bfd_put_64 (hppa_info->dlt_sec->owner, |
3558 | 0 | value, |
3559 | 0 | hppa_info->dlt_sec->contents + hh->dlt_offset); |
3560 | 0 | } |
3561 | | |
3562 | | /* We want the value of the DLT offset for this symbol, not |
3563 | | the symbol's actual address. Note that __gp may not point |
3564 | | to the start of the DLT, so we have to compute the absolute |
3565 | | address, then subtract out the value of __gp. */ |
3566 | 0 | value = (hh->dlt_offset |
3567 | 0 | + hppa_info->dlt_sec->output_offset |
3568 | 0 | + hppa_info->dlt_sec->output_section->vma); |
3569 | 0 | value -= _bfd_get_gp_value (output_bfd); |
3570 | 0 | bfd_put_64 (input_bfd, value, hit_data); |
3571 | 0 | return bfd_reloc_ok; |
3572 | 0 | } |
3573 | | |
3574 | 0 | case R_PARISC_DIR32: |
3575 | 0 | bfd_put_32 (input_bfd, value + addend, hit_data); |
3576 | 0 | return bfd_reloc_ok; |
3577 | | |
3578 | 0 | case R_PARISC_DIR64: |
3579 | 0 | bfd_put_64 (input_bfd, value + addend, hit_data); |
3580 | 0 | return bfd_reloc_ok; |
3581 | | |
3582 | 0 | case R_PARISC_GPREL64: |
3583 | | /* Subtract out the global pointer value to make value a DLT |
3584 | | relative address. */ |
3585 | 0 | value -= _bfd_get_gp_value (output_bfd); |
3586 | |
|
3587 | 0 | bfd_put_64 (input_bfd, value + addend, hit_data); |
3588 | 0 | return bfd_reloc_ok; |
3589 | | |
3590 | 0 | case R_PARISC_LTOFF64: |
3591 | | /* We want the value of the DLT offset for this symbol, not |
3592 | | the symbol's actual address. Note that __gp may not point |
3593 | | to the start of the DLT, so we have to compute the absolute |
3594 | | address, then subtract out the value of __gp. */ |
3595 | 0 | value = (hh->dlt_offset |
3596 | 0 | + hppa_info->dlt_sec->output_offset |
3597 | 0 | + hppa_info->dlt_sec->output_section->vma); |
3598 | 0 | value -= _bfd_get_gp_value (output_bfd); |
3599 | |
|
3600 | 0 | bfd_put_64 (input_bfd, value + addend, hit_data); |
3601 | 0 | return bfd_reloc_ok; |
3602 | | |
3603 | 0 | case R_PARISC_PCREL32: |
3604 | 0 | { |
3605 | | /* If this is a call to a function defined in another dynamic |
3606 | | library, then redirect the call to the local stub for this |
3607 | | function. */ |
3608 | 0 | if (sym_sec == NULL || sym_sec->output_section == NULL) |
3609 | 0 | value = (hh->stub_offset + hppa_info->stub_sec->output_offset |
3610 | 0 | + hppa_info->stub_sec->output_section->vma); |
3611 | | |
3612 | | /* Turn VALUE into a proper PC relative address. */ |
3613 | 0 | value -= (offset + input_section->output_offset |
3614 | 0 | + input_section->output_section->vma); |
3615 | |
|
3616 | 0 | value += addend; |
3617 | 0 | value -= 8; |
3618 | 0 | bfd_put_32 (input_bfd, value, hit_data); |
3619 | 0 | return bfd_reloc_ok; |
3620 | 0 | } |
3621 | | |
3622 | 0 | case R_PARISC_PCREL64: |
3623 | 0 | { |
3624 | | /* If this is a call to a function defined in another dynamic |
3625 | | library, then redirect the call to the local stub for this |
3626 | | function. */ |
3627 | 0 | if (sym_sec == NULL || sym_sec->output_section == NULL) |
3628 | 0 | value = (hh->stub_offset + hppa_info->stub_sec->output_offset |
3629 | 0 | + hppa_info->stub_sec->output_section->vma); |
3630 | | |
3631 | | /* Turn VALUE into a proper PC relative address. */ |
3632 | 0 | value -= (offset + input_section->output_offset |
3633 | 0 | + input_section->output_section->vma); |
3634 | |
|
3635 | 0 | value += addend; |
3636 | 0 | value -= 8; |
3637 | 0 | bfd_put_64 (input_bfd, value, hit_data); |
3638 | 0 | return bfd_reloc_ok; |
3639 | 0 | } |
3640 | | |
3641 | 0 | case R_PARISC_FPTR64: |
3642 | 0 | { |
3643 | 0 | bfd_vma off; |
3644 | | |
3645 | | /* We may still need to create the FPTR itself if it was for |
3646 | | a local symbol. */ |
3647 | 0 | if (hh == NULL) |
3648 | 0 | { |
3649 | 0 | bfd_vma *local_opd_offsets; |
3650 | |
|
3651 | 0 | if (local_offsets == NULL) |
3652 | 0 | abort (); |
3653 | | |
3654 | 0 | local_opd_offsets = local_offsets + 2 * symtab_hdr->sh_info; |
3655 | 0 | off = local_opd_offsets[r_symndx]; |
3656 | | |
3657 | | /* The last bit records whether we've already initialised |
3658 | | this local .opd entry. */ |
3659 | 0 | if ((off & 1) != 0) |
3660 | 0 | { |
3661 | 0 | BFD_ASSERT (off != (bfd_vma) -1); |
3662 | 0 | off &= ~1; |
3663 | 0 | } |
3664 | 0 | else |
3665 | 0 | { |
3666 | | /* The first two words of an .opd entry are zero. */ |
3667 | 0 | memset (hppa_info->opd_sec->contents + off, 0, 16); |
3668 | | |
3669 | | /* The next word is the address of the function. */ |
3670 | 0 | bfd_put_64 (hppa_info->opd_sec->owner, value + addend, |
3671 | 0 | (hppa_info->opd_sec->contents + off + 16)); |
3672 | | |
3673 | | /* The last word is our local __gp value. */ |
3674 | 0 | value = _bfd_get_gp_value (info->output_bfd); |
3675 | 0 | bfd_put_64 (hppa_info->opd_sec->owner, value, |
3676 | 0 | hppa_info->opd_sec->contents + off + 24); |
3677 | 0 | } |
3678 | 0 | } |
3679 | 0 | else |
3680 | 0 | off = hh->opd_offset; |
3681 | | |
3682 | 0 | if (hh == NULL || hh->want_opd) |
3683 | | /* We want the value of the OPD offset for this symbol. */ |
3684 | 0 | value = (off |
3685 | 0 | + hppa_info->opd_sec->output_offset |
3686 | 0 | + hppa_info->opd_sec->output_section->vma); |
3687 | 0 | else |
3688 | | /* We want the address of the symbol. */ |
3689 | 0 | value += addend; |
3690 | |
|
3691 | 0 | bfd_put_64 (input_bfd, value, hit_data); |
3692 | 0 | return bfd_reloc_ok; |
3693 | 0 | } |
3694 | | |
3695 | 0 | case R_PARISC_SECREL32: |
3696 | 0 | if (sym_sec && sym_sec->output_section) |
3697 | 0 | value -= sym_sec->output_section->vma; |
3698 | 0 | bfd_put_32 (input_bfd, value + addend, hit_data); |
3699 | 0 | return bfd_reloc_ok; |
3700 | | |
3701 | 0 | case R_PARISC_SEGREL32: |
3702 | 0 | case R_PARISC_SEGREL64: |
3703 | 0 | { |
3704 | | /* If this is the first SEGREL relocation, then initialize |
3705 | | the segment base values. */ |
3706 | 0 | if (hppa_info->text_segment_base == (bfd_vma) -1) |
3707 | 0 | bfd_map_over_sections (output_bfd, elf_hppa_record_segment_addrs, |
3708 | 0 | hppa_info); |
3709 | | |
3710 | | /* VALUE holds the absolute address. We want to include the |
3711 | | addend, then turn it into a segment relative address. |
3712 | | |
3713 | | The segment is derived from SYM_SEC. We assume that there are |
3714 | | only two segments of note in the resulting executable/shlib. |
3715 | | A readonly segment (.text) and a readwrite segment (.data). */ |
3716 | 0 | value += addend; |
3717 | |
|
3718 | 0 | if (sym_sec->flags & SEC_CODE) |
3719 | 0 | value -= hppa_info->text_segment_base; |
3720 | 0 | else |
3721 | 0 | value -= hppa_info->data_segment_base; |
3722 | |
|
3723 | 0 | if (r_type == R_PARISC_SEGREL32) |
3724 | 0 | bfd_put_32 (input_bfd, value, hit_data); |
3725 | 0 | else |
3726 | 0 | bfd_put_64 (input_bfd, value, hit_data); |
3727 | 0 | return bfd_reloc_ok; |
3728 | 0 | } |
3729 | | |
3730 | | /* Something we don't know how to handle. */ |
3731 | 0 | default: |
3732 | 0 | return bfd_reloc_notsupported; |
3733 | 0 | } |
3734 | | |
3735 | | /* Update the instruction word. */ |
3736 | 0 | bfd_put_32 (input_bfd, (bfd_vma) insn, hit_data); |
3737 | 0 | return bfd_reloc_ok; |
3738 | 0 | } |
3739 | | |
3740 | | /* Relocate an HPPA ELF section. */ |
3741 | | |
3742 | | static int |
3743 | | elf64_hppa_relocate_section (bfd *output_bfd, |
3744 | | struct bfd_link_info *info, |
3745 | | bfd *input_bfd, |
3746 | | asection *input_section, |
3747 | | bfd_byte *contents, |
3748 | | Elf_Internal_Rela *relocs, |
3749 | | Elf_Internal_Sym *local_syms, |
3750 | | asection **local_sections) |
3751 | 0 | { |
3752 | 0 | Elf_Internal_Shdr *symtab_hdr; |
3753 | 0 | Elf_Internal_Rela *rel; |
3754 | 0 | Elf_Internal_Rela *relend; |
3755 | 0 | struct elf64_hppa_link_hash_table *hppa_info; |
3756 | |
|
3757 | 0 | hppa_info = hppa_link_hash_table (info); |
3758 | 0 | if (hppa_info == NULL) |
3759 | 0 | return false; |
3760 | | |
3761 | 0 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
3762 | |
|
3763 | 0 | rel = relocs; |
3764 | 0 | relend = relocs + input_section->reloc_count; |
3765 | 0 | for (; rel < relend; rel++) |
3766 | 0 | { |
3767 | 0 | int r_type; |
3768 | 0 | reloc_howto_type *howto = elf_hppa_howto_table + ELF_R_TYPE (rel->r_info); |
3769 | 0 | unsigned long r_symndx; |
3770 | 0 | struct elf_link_hash_entry *eh; |
3771 | 0 | Elf_Internal_Sym *sym; |
3772 | 0 | asection *sym_sec; |
3773 | 0 | bfd_vma relocation; |
3774 | 0 | bfd_reloc_status_type r; |
3775 | |
|
3776 | 0 | r_type = ELF_R_TYPE (rel->r_info); |
3777 | 0 | if (r_type < 0 || r_type >= (int) R_PARISC_UNIMPLEMENTED) |
3778 | 0 | { |
3779 | 0 | bfd_set_error (bfd_error_bad_value); |
3780 | 0 | return false; |
3781 | 0 | } |
3782 | 0 | if (r_type == (unsigned int) R_PARISC_GNU_VTENTRY |
3783 | 0 | || r_type == (unsigned int) R_PARISC_GNU_VTINHERIT) |
3784 | 0 | continue; |
3785 | | |
3786 | | /* This is a final link. */ |
3787 | 0 | r_symndx = ELF_R_SYM (rel->r_info); |
3788 | 0 | eh = NULL; |
3789 | 0 | sym = NULL; |
3790 | 0 | sym_sec = NULL; |
3791 | 0 | if (r_symndx < symtab_hdr->sh_info) |
3792 | 0 | { |
3793 | | /* This is a local symbol, hh defaults to NULL. */ |
3794 | 0 | sym = local_syms + r_symndx; |
3795 | 0 | sym_sec = local_sections[r_symndx]; |
3796 | 0 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sym_sec, rel); |
3797 | 0 | } |
3798 | 0 | else |
3799 | 0 | { |
3800 | | /* This is not a local symbol. */ |
3801 | 0 | struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd); |
3802 | | |
3803 | | /* It seems this can happen with erroneous or unsupported |
3804 | | input (mixing a.out and elf in an archive, for example.) */ |
3805 | 0 | if (sym_hashes == NULL) |
3806 | 0 | return false; |
3807 | | |
3808 | 0 | eh = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
3809 | |
|
3810 | 0 | if (info->wrap_hash != NULL |
3811 | 0 | && (input_section->flags & SEC_DEBUGGING) != 0) |
3812 | 0 | eh = ((struct elf_link_hash_entry *) |
3813 | 0 | unwrap_hash_lookup (info, input_bfd, &eh->root)); |
3814 | |
|
3815 | 0 | while (eh->root.type == bfd_link_hash_indirect |
3816 | 0 | || eh->root.type == bfd_link_hash_warning) |
3817 | 0 | eh = (struct elf_link_hash_entry *) eh->root.u.i.link; |
3818 | |
|
3819 | 0 | relocation = 0; |
3820 | 0 | if (eh->root.type == bfd_link_hash_defined |
3821 | 0 | || eh->root.type == bfd_link_hash_defweak) |
3822 | 0 | { |
3823 | 0 | sym_sec = eh->root.u.def.section; |
3824 | 0 | if (sym_sec != NULL |
3825 | 0 | && sym_sec->output_section != NULL) |
3826 | 0 | relocation = (eh->root.u.def.value |
3827 | 0 | + sym_sec->output_section->vma |
3828 | 0 | + sym_sec->output_offset); |
3829 | 0 | } |
3830 | 0 | else if (eh->root.type == bfd_link_hash_undefweak) |
3831 | 0 | ; |
3832 | 0 | else if (info->unresolved_syms_in_objects == RM_IGNORE |
3833 | 0 | && ELF_ST_VISIBILITY (eh->other) == STV_DEFAULT) |
3834 | 0 | ; |
3835 | 0 | else if (!bfd_link_relocatable (info) |
3836 | 0 | && elf_hppa_is_dynamic_loader_symbol (eh->root.root.string)) |
3837 | 0 | continue; |
3838 | 0 | else if (!bfd_link_relocatable (info)) |
3839 | 0 | { |
3840 | 0 | bool err; |
3841 | |
|
3842 | 0 | err = (info->unresolved_syms_in_objects == RM_DIAGNOSE |
3843 | 0 | && !info->warn_unresolved_syms) |
3844 | 0 | || ELF_ST_VISIBILITY (eh->other) != STV_DEFAULT; |
3845 | |
|
3846 | 0 | info->callbacks->undefined_symbol |
3847 | 0 | (info, eh->root.root.string, input_bfd, |
3848 | 0 | input_section, rel->r_offset, err); |
3849 | 0 | } |
3850 | | |
3851 | 0 | if (!bfd_link_relocatable (info) |
3852 | 0 | && relocation == 0 |
3853 | 0 | && eh->root.type != bfd_link_hash_defined |
3854 | 0 | && eh->root.type != bfd_link_hash_defweak |
3855 | 0 | && eh->root.type != bfd_link_hash_undefweak) |
3856 | 0 | { |
3857 | 0 | if (info->unresolved_syms_in_objects == RM_IGNORE |
3858 | 0 | && ELF_ST_VISIBILITY (eh->other) == STV_DEFAULT |
3859 | 0 | && eh->type == STT_PARISC_MILLI) |
3860 | 0 | info->callbacks->undefined_symbol |
3861 | 0 | (info, eh_name (eh), input_bfd, |
3862 | 0 | input_section, rel->r_offset, false); |
3863 | 0 | } |
3864 | 0 | } |
3865 | | |
3866 | 0 | if (sym_sec != NULL && discarded_section (sym_sec)) |
3867 | 0 | RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, |
3868 | 0 | rel, 1, relend, howto, 0, contents); |
3869 | |
|
3870 | 0 | if (bfd_link_relocatable (info)) |
3871 | 0 | continue; |
3872 | | |
3873 | 0 | r = elf_hppa_final_link_relocate (rel, input_bfd, output_bfd, |
3874 | 0 | input_section, contents, |
3875 | 0 | relocation, info, sym_sec, |
3876 | 0 | eh); |
3877 | |
|
3878 | 0 | if (r != bfd_reloc_ok) |
3879 | 0 | { |
3880 | 0 | switch (r) |
3881 | 0 | { |
3882 | 0 | default: |
3883 | 0 | abort (); |
3884 | 0 | case bfd_reloc_overflow: |
3885 | 0 | { |
3886 | 0 | const char *sym_name; |
3887 | |
|
3888 | 0 | if (eh != NULL) |
3889 | 0 | sym_name = NULL; |
3890 | 0 | else |
3891 | 0 | { |
3892 | 0 | sym_name = bfd_elf_string_from_elf_section (input_bfd, |
3893 | 0 | symtab_hdr->sh_link, |
3894 | 0 | sym->st_name); |
3895 | 0 | if (sym_name == NULL) |
3896 | 0 | return false; |
3897 | 0 | if (*sym_name == '\0') |
3898 | 0 | sym_name = bfd_section_name (sym_sec); |
3899 | 0 | } |
3900 | | |
3901 | 0 | (*info->callbacks->reloc_overflow) |
3902 | 0 | (info, (eh ? &eh->root : NULL), sym_name, howto->name, |
3903 | 0 | (bfd_vma) 0, input_bfd, input_section, rel->r_offset); |
3904 | 0 | } |
3905 | 0 | break; |
3906 | 0 | } |
3907 | 0 | } |
3908 | 0 | } |
3909 | 0 | return true; |
3910 | 0 | } |
3911 | | |
3912 | | static const struct bfd_elf_special_section elf64_hppa_special_sections[] = |
3913 | | { |
3914 | | { STRING_COMMA_LEN (".tbss"), 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_HP_TLS }, |
3915 | | { STRING_COMMA_LEN (".fini"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, |
3916 | | { STRING_COMMA_LEN (".init"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, |
3917 | | { STRING_COMMA_LEN (".plt"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT }, |
3918 | | { STRING_COMMA_LEN (".dlt"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT }, |
3919 | | { STRING_COMMA_LEN (".sdata"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT }, |
3920 | | { STRING_COMMA_LEN (".sbss"), 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT }, |
3921 | | { NULL, 0, 0, 0, 0 } |
3922 | | }; |
3923 | | |
3924 | | /* The hash bucket size is the standard one, namely 4. */ |
3925 | | |
3926 | | const struct elf_size_info hppa64_elf_size_info = |
3927 | | { |
3928 | | sizeof (Elf64_External_Ehdr), |
3929 | | sizeof (Elf64_External_Phdr), |
3930 | | sizeof (Elf64_External_Shdr), |
3931 | | sizeof (Elf64_External_Rel), |
3932 | | sizeof (Elf64_External_Rela), |
3933 | | sizeof (Elf64_External_Sym), |
3934 | | sizeof (Elf64_External_Dyn), |
3935 | | sizeof (Elf_External_Note), |
3936 | | 4, |
3937 | | 1, |
3938 | | 64, 3, |
3939 | | ELFCLASS64, EV_CURRENT, |
3940 | | bfd_elf64_write_out_phdrs, |
3941 | | bfd_elf64_write_shdrs_and_ehdr, |
3942 | | bfd_elf64_checksum_contents, |
3943 | | bfd_elf64_write_relocs, |
3944 | | bfd_elf64_swap_symbol_in, |
3945 | | bfd_elf64_swap_symbol_out, |
3946 | | bfd_elf64_slurp_reloc_table, |
3947 | | bfd_elf64_slurp_symbol_table, |
3948 | | bfd_elf64_swap_dyn_in, |
3949 | | bfd_elf64_swap_dyn_out, |
3950 | | bfd_elf64_swap_reloc_in, |
3951 | | bfd_elf64_swap_reloc_out, |
3952 | | bfd_elf64_swap_reloca_in, |
3953 | | bfd_elf64_swap_reloca_out |
3954 | | }; |
3955 | | |
3956 | | #define TARGET_BIG_SYM hppa_elf64_vec |
3957 | | #define TARGET_BIG_NAME "elf64-hppa" |
3958 | | #define ELF_ARCH bfd_arch_hppa |
3959 | | #define ELF_TARGET_ID HPPA64_ELF_DATA |
3960 | | #define ELF_MACHINE_CODE EM_PARISC |
3961 | | /* This is not strictly correct. The maximum page size for PA2.0 is |
3962 | | 64M. But everything still uses 4k. */ |
3963 | | #define ELF_MAXPAGESIZE 0x1000 |
3964 | | #define ELF_OSABI ELFOSABI_HPUX |
3965 | | |
3966 | | #define bfd_elf64_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup |
3967 | | #define bfd_elf64_bfd_reloc_name_lookup elf_hppa_reloc_name_lookup |
3968 | | #define bfd_elf64_bfd_is_local_label_name elf_hppa_is_local_label_name |
3969 | | #define elf_info_to_howto elf_hppa_info_to_howto |
3970 | | #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel |
3971 | | |
3972 | | #define elf_backend_section_from_shdr elf64_hppa_section_from_shdr |
3973 | | #define elf_backend_object_p elf64_hppa_object_p |
3974 | | #define elf_backend_final_write_processing \ |
3975 | | elf_hppa_final_write_processing |
3976 | | #define elf_backend_fake_sections elf_hppa_fake_sections |
3977 | | #define elf_backend_add_symbol_hook elf_hppa_add_symbol_hook |
3978 | | |
3979 | | #define elf_backend_relocate_section elf_hppa_relocate_section |
3980 | | |
3981 | | #define bfd_elf64_bfd_final_link elf_hppa_final_link |
3982 | | |
3983 | | #define elf_backend_create_dynamic_sections \ |
3984 | | elf64_hppa_create_dynamic_sections |
3985 | | #define elf_backend_init_file_header elf64_hppa_init_file_header |
3986 | | |
3987 | | #define elf_backend_omit_section_dynsym _bfd_elf_omit_section_dynsym_all |
3988 | | |
3989 | | #define elf_backend_adjust_dynamic_symbol \ |
3990 | | elf64_hppa_adjust_dynamic_symbol |
3991 | | |
3992 | | #define elf_backend_late_size_sections elf64_hppa_late_size_sections |
3993 | | |
3994 | | #define elf_backend_finish_dynamic_symbol \ |
3995 | | elf64_hppa_finish_dynamic_symbol |
3996 | | #define elf_backend_finish_dynamic_sections \ |
3997 | | elf64_hppa_finish_dynamic_sections |
3998 | | #define elf_backend_grok_prstatus elf64_hppa_grok_prstatus |
3999 | | #define elf_backend_grok_psinfo elf64_hppa_grok_psinfo |
4000 | | |
4001 | | /* Stuff for the BFD linker: */ |
4002 | | #define bfd_elf64_bfd_link_hash_table_create \ |
4003 | | elf64_hppa_hash_table_create |
4004 | | |
4005 | | #define elf_backend_check_relocs \ |
4006 | | elf64_hppa_check_relocs |
4007 | | |
4008 | | #define elf_backend_size_info \ |
4009 | | hppa64_elf_size_info |
4010 | | |
4011 | | #define elf_backend_additional_program_headers \ |
4012 | | elf64_hppa_additional_program_headers |
4013 | | |
4014 | | #define elf_backend_modify_segment_map \ |
4015 | | elf64_hppa_modify_segment_map |
4016 | | |
4017 | | #define elf_backend_allow_non_load_phdr \ |
4018 | | elf64_hppa_allow_non_load_phdr |
4019 | | |
4020 | | #define elf_backend_link_output_symbol_hook \ |
4021 | | elf64_hppa_link_output_symbol_hook |
4022 | | |
4023 | | #define elf_backend_want_got_plt 0 |
4024 | | #define elf_backend_plt_readonly 0 |
4025 | | #define elf_backend_want_plt_sym 0 |
4026 | | #define elf_backend_got_header_size 0 |
4027 | | #define elf_backend_type_change_ok true |
4028 | | #define elf_backend_get_symbol_type elf64_hppa_elf_get_symbol_type |
4029 | | #define elf_backend_reloc_type_class elf64_hppa_reloc_type_class |
4030 | | #define elf_backend_rela_normal 1 |
4031 | | #define elf_backend_special_sections elf64_hppa_special_sections |
4032 | | #define elf_backend_action_discarded elf_hppa_action_discarded |
4033 | | #define elf_backend_section_from_phdr elf64_hppa_section_from_phdr |
4034 | | |
4035 | | #define elf64_bed elf64_hppa_hpux_bed |
4036 | | |
4037 | | #include "elf64-target.h" |
4038 | | |
4039 | | #undef TARGET_BIG_SYM |
4040 | | #define TARGET_BIG_SYM hppa_elf64_linux_vec |
4041 | | #undef TARGET_BIG_NAME |
4042 | | #define TARGET_BIG_NAME "elf64-hppa-linux" |
4043 | | #undef ELF_OSABI |
4044 | | #define ELF_OSABI ELFOSABI_GNU |
4045 | | #undef elf64_bed |
4046 | | #define elf64_bed elf64_hppa_linux_bed |
4047 | | #undef elf_backend_special_sections |
4048 | | #define elf_backend_special_sections (elf64_hppa_special_sections + 1) |
4049 | | |
4050 | | #include "elf64-target.h" |