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