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