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