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