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