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