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