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