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