1 /* Support for HPPA 64-bit ELF
2 Copyright (C) 1999-2019 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
22 #include "alloca-conf.h"
28 #include "elf64-hppa.h"
29 #include "libiberty.h"
33 #define PLT_ENTRY_SIZE 0x10
34 #define DLT_ENTRY_SIZE 0x8
35 #define OPD_ENTRY_SIZE 0x20
37 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/pa20_64/dld.sl"
39 /* The stub is supposed to load the target address and target's DP
40 value out of the PLT, then do an external branch to the target
45 LDD PLTOFF+8(%r27),%r27
47 Note that we must use the LDD with a 14 bit displacement, not the one
48 with a 5 bit displacement. */
49 static char plt_stub
[] = {0x53, 0x61, 0x00, 0x00, 0xe8, 0x20, 0xd0, 0x00,
50 0x53, 0x7b, 0x00, 0x00 };
52 struct elf64_hppa_link_hash_entry
54 struct elf_link_hash_entry eh
;
56 /* Offsets for this symbol in various linker sections. */
62 /* The index of the (possibly local) symbol in the input bfd and its
63 associated BFD. Needed so that we can have relocs against local
64 symbols in shared libraries. */
68 /* Dynamic symbols may need to have two different values. One for
69 the dynamic symbol table, one for the normal symbol table.
71 In such cases we store the symbol's real value and section
72 index here so we can restore the real value before we write
73 the normal symbol table. */
77 /* Used to count non-got, non-plt relocations for delayed sizing
78 of relocation sections. */
79 struct elf64_hppa_dyn_reloc_entry
81 /* Next relocation in the chain. */
82 struct elf64_hppa_dyn_reloc_entry
*next
;
84 /* The type of the relocation. */
87 /* The input section of the relocation. */
90 /* Number of relocs copied in this section. */
93 /* The index of the section symbol for the input section of
94 the relocation. Only needed when building shared libraries. */
97 /* The offset within the input section of the relocation. */
100 /* The addend for the relocation. */
105 /* Nonzero if this symbol needs an entry in one of the linker
113 struct elf64_hppa_link_hash_table
115 struct elf_link_hash_table root
;
117 /* Shortcuts to get to the various linker defined sections. */
119 asection
*dlt_rel_sec
;
121 asection
*plt_rel_sec
;
123 asection
*opd_rel_sec
;
124 asection
*other_rel_sec
;
126 /* Offset of __gp within .plt section. When the PLT gets large we want
127 to slide __gp into the PLT section so that we can continue to use
128 single DP relative instructions to load values out of the PLT. */
131 /* Note this is not strictly correct. We should create a stub section for
132 each input section with calls. The stub section should be placed before
133 the section with the call. */
136 bfd_vma text_segment_base
;
137 bfd_vma data_segment_base
;
139 /* We build tables to map from an input section back to its
140 symbol index. This is the BFD for which we currently have
142 bfd
*section_syms_bfd
;
144 /* Array of symbol numbers for each input section attached to the
149 #define hppa_link_hash_table(p) \
150 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
151 == HPPA64_ELF_DATA ? ((struct elf64_hppa_link_hash_table *) ((p)->hash)) : NULL)
153 #define hppa_elf_hash_entry(ent) \
154 ((struct elf64_hppa_link_hash_entry *)(ent))
156 #define eh_name(eh) \
157 (eh ? eh->root.root.string : "<undef>")
159 typedef struct bfd_hash_entry
*(*new_hash_entry_func
)
160 (struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *);
162 static struct bfd_link_hash_table
*elf64_hppa_hash_table_create
165 /* This must follow the definitions of the various derived linker
166 hash tables and shared functions. */
167 #include "elf-hppa.h"
169 static bfd_boolean elf64_hppa_object_p
172 static bfd_boolean elf64_hppa_create_dynamic_sections
173 (bfd
*, struct bfd_link_info
*);
175 static bfd_boolean elf64_hppa_adjust_dynamic_symbol
176 (struct bfd_link_info
*, struct elf_link_hash_entry
*);
178 static bfd_boolean elf64_hppa_mark_milli_and_exported_functions
179 (struct elf_link_hash_entry
*, void *);
181 static bfd_boolean elf64_hppa_size_dynamic_sections
182 (bfd
*, struct bfd_link_info
*);
184 static int elf64_hppa_link_output_symbol_hook
185 (struct bfd_link_info
*, const char *, Elf_Internal_Sym
*,
186 asection
*, struct elf_link_hash_entry
*);
188 static bfd_boolean elf64_hppa_finish_dynamic_symbol
189 (bfd
*, struct bfd_link_info
*,
190 struct elf_link_hash_entry
*, Elf_Internal_Sym
*);
192 static bfd_boolean elf64_hppa_finish_dynamic_sections
193 (bfd
*, struct bfd_link_info
*);
195 static bfd_boolean elf64_hppa_check_relocs
196 (bfd
*, struct bfd_link_info
*,
197 asection
*, const Elf_Internal_Rela
*);
199 static bfd_boolean elf64_hppa_dynamic_symbol_p
200 (struct elf_link_hash_entry
*, struct bfd_link_info
*);
202 static bfd_boolean elf64_hppa_mark_exported_functions
203 (struct elf_link_hash_entry
*, void *);
205 static bfd_boolean elf64_hppa_finalize_opd
206 (struct elf_link_hash_entry
*, void *);
208 static bfd_boolean elf64_hppa_finalize_dlt
209 (struct elf_link_hash_entry
*, void *);
211 static bfd_boolean allocate_global_data_dlt
212 (struct elf_link_hash_entry
*, void *);
214 static bfd_boolean allocate_global_data_plt
215 (struct elf_link_hash_entry
*, void *);
217 static bfd_boolean allocate_global_data_stub
218 (struct elf_link_hash_entry
*, void *);
220 static bfd_boolean allocate_global_data_opd
221 (struct elf_link_hash_entry
*, void *);
223 static bfd_boolean get_reloc_section
224 (bfd
*, struct elf64_hppa_link_hash_table
*, asection
*);
226 static bfd_boolean count_dyn_reloc
227 (bfd
*, struct elf64_hppa_link_hash_entry
*,
228 int, asection
*, int, bfd_vma
, bfd_vma
);
230 static bfd_boolean allocate_dynrel_entries
231 (struct elf_link_hash_entry
*, void *);
233 static bfd_boolean elf64_hppa_finalize_dynreloc
234 (struct elf_link_hash_entry
*, void *);
236 static bfd_boolean get_opd
237 (bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*);
239 static bfd_boolean get_plt
240 (bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*);
242 static bfd_boolean get_dlt
243 (bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*);
245 static bfd_boolean get_stub
246 (bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*);
248 static int elf64_hppa_elf_get_symbol_type
249 (Elf_Internal_Sym
*, int);
251 /* Initialize an entry in the link hash table. */
253 static struct bfd_hash_entry
*
254 hppa64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
255 struct bfd_hash_table
*table
,
258 /* Allocate the structure if it has not already been allocated by a
262 entry
= bfd_hash_allocate (table
,
263 sizeof (struct elf64_hppa_link_hash_entry
));
268 /* Call the allocation method of the superclass. */
269 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
272 struct elf64_hppa_link_hash_entry
*hh
;
274 /* Initialize our local data. All zeros. */
275 hh
= hppa_elf_hash_entry (entry
);
276 memset (&hh
->dlt_offset
, 0,
277 (sizeof (struct elf64_hppa_link_hash_entry
)
278 - offsetof (struct elf64_hppa_link_hash_entry
, dlt_offset
)));
284 /* Create the derived linker hash table. The PA64 ELF port uses this
285 derived hash table to keep information specific to the PA ElF
286 linker (without using static variables). */
288 static struct bfd_link_hash_table
*
289 elf64_hppa_hash_table_create (bfd
*abfd
)
291 struct elf64_hppa_link_hash_table
*htab
;
292 bfd_size_type amt
= sizeof (*htab
);
294 htab
= bfd_zmalloc (amt
);
298 if (!_bfd_elf_link_hash_table_init (&htab
->root
, abfd
,
299 hppa64_link_hash_newfunc
,
300 sizeof (struct elf64_hppa_link_hash_entry
),
307 htab
->text_segment_base
= (bfd_vma
) -1;
308 htab
->data_segment_base
= (bfd_vma
) -1;
310 return &htab
->root
.root
;
313 /* Return nonzero if ABFD represents a PA2.0 ELF64 file.
315 Additionally we set the default architecture and machine. */
317 elf64_hppa_object_p (bfd
*abfd
)
319 Elf_Internal_Ehdr
* i_ehdrp
;
322 i_ehdrp
= elf_elfheader (abfd
);
323 if (strcmp (bfd_get_target (abfd
), "elf64-hppa-linux") == 0)
325 /* GCC on hppa-linux produces binaries with OSABI=GNU,
326 but the kernel produces corefiles with OSABI=SysV. */
327 if (i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_GNU
328 && i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_NONE
) /* aka SYSV */
333 /* HPUX produces binaries with OSABI=HPUX,
334 but the kernel produces corefiles with OSABI=SysV. */
335 if (i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_HPUX
336 && i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_NONE
) /* aka SYSV */
340 flags
= i_ehdrp
->e_flags
;
341 switch (flags
& (EF_PARISC_ARCH
| EF_PARISC_WIDE
))
344 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 10);
346 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 11);
348 if (i_ehdrp
->e_ident
[EI_CLASS
] == ELFCLASS64
)
349 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 25);
351 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 20);
352 case EFA_PARISC_2_0
| EF_PARISC_WIDE
:
353 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 25);
355 /* Don't be fussy. */
359 /* Given section type (hdr->sh_type), return a boolean indicating
360 whether or not the section is an elf64-hppa specific section. */
362 elf64_hppa_section_from_shdr (bfd
*abfd
,
363 Elf_Internal_Shdr
*hdr
,
367 switch (hdr
->sh_type
)
370 if (strcmp (name
, ".PARISC.archext") != 0)
373 case SHT_PARISC_UNWIND
:
374 if (strcmp (name
, ".PARISC.unwind") != 0)
378 case SHT_PARISC_ANNOT
:
383 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
389 /* SEC is a section containing relocs for an input BFD when linking; return
390 a suitable section for holding relocs in the output BFD for a link. */
393 get_reloc_section (bfd
*abfd
,
394 struct elf64_hppa_link_hash_table
*hppa_info
,
397 const char *srel_name
;
401 srel_name
= (bfd_elf_string_from_elf_section
402 (abfd
, elf_elfheader(abfd
)->e_shstrndx
,
403 _bfd_elf_single_rel_hdr(sec
)->sh_name
));
404 if (srel_name
== NULL
)
407 dynobj
= hppa_info
->root
.dynobj
;
409 hppa_info
->root
.dynobj
= dynobj
= abfd
;
411 srel
= bfd_get_linker_section (dynobj
, srel_name
);
414 srel
= bfd_make_section_anyway_with_flags (dynobj
, srel_name
,
422 || !bfd_set_section_alignment (srel
, 3))
426 hppa_info
->other_rel_sec
= srel
;
430 /* Add a new entry to the list of dynamic relocations against DYN_H.
432 We use this to keep a record of all the FPTR relocations against a
433 particular symbol so that we can create FPTR relocations in the
437 count_dyn_reloc (bfd
*abfd
,
438 struct elf64_hppa_link_hash_entry
*hh
,
445 struct elf64_hppa_dyn_reloc_entry
*rent
;
447 rent
= (struct elf64_hppa_dyn_reloc_entry
*)
448 bfd_alloc (abfd
, (bfd_size_type
) sizeof (*rent
));
452 rent
->next
= hh
->reloc_entries
;
455 rent
->sec_symndx
= sec_symndx
;
456 rent
->offset
= offset
;
457 rent
->addend
= addend
;
458 hh
->reloc_entries
= rent
;
463 /* Return a pointer to the local DLT, PLT and OPD reference counts
464 for ABFD. Returns NULL if the storage allocation fails. */
466 static bfd_signed_vma
*
467 hppa64_elf_local_refcounts (bfd
*abfd
)
469 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
470 bfd_signed_vma
*local_refcounts
;
472 local_refcounts
= elf_local_got_refcounts (abfd
);
473 if (local_refcounts
== NULL
)
477 /* Allocate space for local DLT, PLT and OPD reference
478 counts. Done this way to save polluting elf_obj_tdata
479 with another target specific pointer. */
480 size
= symtab_hdr
->sh_info
;
481 size
*= 3 * sizeof (bfd_signed_vma
);
482 local_refcounts
= bfd_zalloc (abfd
, size
);
483 elf_local_got_refcounts (abfd
) = local_refcounts
;
485 return local_refcounts
;
488 /* Scan the RELOCS and record the type of dynamic entries that each
489 referenced symbol needs. */
492 elf64_hppa_check_relocs (bfd
*abfd
,
493 struct bfd_link_info
*info
,
495 const Elf_Internal_Rela
*relocs
)
497 struct elf64_hppa_link_hash_table
*hppa_info
;
498 const Elf_Internal_Rela
*relend
;
499 Elf_Internal_Shdr
*symtab_hdr
;
500 const Elf_Internal_Rela
*rel
;
501 unsigned int sec_symndx
;
503 if (bfd_link_relocatable (info
))
506 /* If this is the first dynamic object found in the link, create
507 the special sections required for dynamic linking. */
508 if (! elf_hash_table (info
)->dynamic_sections_created
)
510 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
514 hppa_info
= hppa_link_hash_table (info
);
515 if (hppa_info
== NULL
)
517 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
519 /* If necessary, build a new table holding section symbols indices
522 if (bfd_link_pic (info
) && hppa_info
->section_syms_bfd
!= abfd
)
525 unsigned int highest_shndx
;
526 Elf_Internal_Sym
*local_syms
= NULL
;
527 Elf_Internal_Sym
*isym
, *isymend
;
530 /* We're done with the old cache of section index to section symbol
531 index information. Free it.
533 ?!? Note we leak the last section_syms array. Presumably we
534 could free it in one of the later routines in this file. */
535 if (hppa_info
->section_syms
)
536 free (hppa_info
->section_syms
);
538 /* Read this BFD's local symbols. */
539 if (symtab_hdr
->sh_info
!= 0)
541 local_syms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
542 if (local_syms
== NULL
)
543 local_syms
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
544 symtab_hdr
->sh_info
, 0,
546 if (local_syms
== NULL
)
550 /* Record the highest section index referenced by the local symbols. */
552 isymend
= local_syms
+ symtab_hdr
->sh_info
;
553 for (isym
= local_syms
; isym
< isymend
; isym
++)
555 if (isym
->st_shndx
> highest_shndx
556 && isym
->st_shndx
< SHN_LORESERVE
)
557 highest_shndx
= isym
->st_shndx
;
560 /* Allocate an array to hold the section index to section symbol index
561 mapping. Bump by one since we start counting at zero. */
565 hppa_info
->section_syms
= (int *) bfd_malloc (amt
);
567 /* Now walk the local symbols again. If we find a section symbol,
568 record the index of the symbol into the section_syms array. */
569 for (i
= 0, isym
= local_syms
; isym
< isymend
; i
++, isym
++)
571 if (ELF_ST_TYPE (isym
->st_info
) == STT_SECTION
)
572 hppa_info
->section_syms
[isym
->st_shndx
] = i
;
575 /* We are finished with the local symbols. */
576 if (local_syms
!= NULL
577 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
579 if (! info
->keep_memory
)
583 /* Cache the symbols for elf_link_input_bfd. */
584 symtab_hdr
->contents
= (unsigned char *) local_syms
;
588 /* Record which BFD we built the section_syms mapping for. */
589 hppa_info
->section_syms_bfd
= abfd
;
592 /* Record the symbol index for this input section. We may need it for
593 relocations when building shared libraries. When not building shared
594 libraries this value is never really used, but assign it to zero to
595 prevent out of bounds memory accesses in other routines. */
596 if (bfd_link_pic (info
))
598 sec_symndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
600 /* If we did not find a section symbol for this section, then
601 something went terribly wrong above. */
602 if (sec_symndx
== SHN_BAD
)
605 if (sec_symndx
< SHN_LORESERVE
)
606 sec_symndx
= hppa_info
->section_syms
[sec_symndx
];
613 relend
= relocs
+ sec
->reloc_count
;
614 for (rel
= relocs
; rel
< relend
; ++rel
)
625 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
626 struct elf64_hppa_link_hash_entry
*hh
;
628 bfd_boolean maybe_dynamic
;
629 int dynrel_type
= R_PARISC_NONE
;
630 static reloc_howto_type
*howto
;
632 if (r_symndx
>= symtab_hdr
->sh_info
)
634 /* We're dealing with a global symbol -- find its hash entry
635 and mark it as being referenced. */
636 long indx
= r_symndx
- symtab_hdr
->sh_info
;
637 hh
= hppa_elf_hash_entry (elf_sym_hashes (abfd
)[indx
]);
638 while (hh
->eh
.root
.type
== bfd_link_hash_indirect
639 || hh
->eh
.root
.type
== bfd_link_hash_warning
)
640 hh
= hppa_elf_hash_entry (hh
->eh
.root
.u
.i
.link
);
642 /* PR15323, ref flags aren't set for references in the same
644 hh
->eh
.ref_regular
= 1;
649 /* We can only get preliminary data on whether a symbol is
650 locally or externally defined, as not all of the input files
651 have yet been processed. Do something with what we know, as
652 this may help reduce memory usage and processing time later. */
653 maybe_dynamic
= FALSE
;
654 if (hh
&& ((bfd_link_pic (info
)
656 || info
->unresolved_syms_in_shared_libs
== RM_IGNORE
))
657 || !hh
->eh
.def_regular
658 || hh
->eh
.root
.type
== bfd_link_hash_defweak
))
659 maybe_dynamic
= TRUE
;
661 howto
= elf_hppa_howto_table
+ ELF64_R_TYPE (rel
->r_info
);
665 /* These are simple indirect references to symbols through the
666 DLT. We need to create a DLT entry for any symbols which
667 appears in a DLTIND relocation. */
668 case R_PARISC_DLTIND21L
:
669 case R_PARISC_DLTIND14R
:
670 case R_PARISC_DLTIND14F
:
671 case R_PARISC_DLTIND14WR
:
672 case R_PARISC_DLTIND14DR
:
673 need_entry
= NEED_DLT
;
676 /* ?!? These need a DLT entry. But I have no idea what to do with
677 the "link time TP value. */
678 case R_PARISC_LTOFF_TP21L
:
679 case R_PARISC_LTOFF_TP14R
:
680 case R_PARISC_LTOFF_TP14F
:
681 case R_PARISC_LTOFF_TP64
:
682 case R_PARISC_LTOFF_TP14WR
:
683 case R_PARISC_LTOFF_TP14DR
:
684 case R_PARISC_LTOFF_TP16F
:
685 case R_PARISC_LTOFF_TP16WF
:
686 case R_PARISC_LTOFF_TP16DF
:
687 need_entry
= NEED_DLT
;
690 /* These are function calls. Depending on their precise target we
691 may need to make a stub for them. The stub uses the PLT, so we
692 need to create PLT entries for these symbols too. */
693 case R_PARISC_PCREL12F
:
694 case R_PARISC_PCREL17F
:
695 case R_PARISC_PCREL22F
:
696 case R_PARISC_PCREL32
:
697 case R_PARISC_PCREL64
:
698 case R_PARISC_PCREL21L
:
699 case R_PARISC_PCREL17R
:
700 case R_PARISC_PCREL17C
:
701 case R_PARISC_PCREL14R
:
702 case R_PARISC_PCREL14F
:
703 case R_PARISC_PCREL22C
:
704 case R_PARISC_PCREL14WR
:
705 case R_PARISC_PCREL14DR
:
706 case R_PARISC_PCREL16F
:
707 case R_PARISC_PCREL16WF
:
708 case R_PARISC_PCREL16DF
:
709 /* Function calls might need to go through the .plt, and
710 might need a long branch stub. */
711 if (hh
!= NULL
&& hh
->eh
.type
!= STT_PARISC_MILLI
)
712 need_entry
= (NEED_PLT
| NEED_STUB
);
717 case R_PARISC_PLTOFF21L
:
718 case R_PARISC_PLTOFF14R
:
719 case R_PARISC_PLTOFF14F
:
720 case R_PARISC_PLTOFF14WR
:
721 case R_PARISC_PLTOFF14DR
:
722 case R_PARISC_PLTOFF16F
:
723 case R_PARISC_PLTOFF16WF
:
724 case R_PARISC_PLTOFF16DF
:
725 need_entry
= (NEED_PLT
);
729 if (bfd_link_pic (info
) || maybe_dynamic
)
730 need_entry
= (NEED_DYNREL
);
731 dynrel_type
= R_PARISC_DIR64
;
734 /* This is an indirect reference through the DLT to get the address
735 of a OPD descriptor. Thus we need to make a DLT entry that points
737 case R_PARISC_LTOFF_FPTR21L
:
738 case R_PARISC_LTOFF_FPTR14R
:
739 case R_PARISC_LTOFF_FPTR14WR
:
740 case R_PARISC_LTOFF_FPTR14DR
:
741 case R_PARISC_LTOFF_FPTR32
:
742 case R_PARISC_LTOFF_FPTR64
:
743 case R_PARISC_LTOFF_FPTR16F
:
744 case R_PARISC_LTOFF_FPTR16WF
:
745 case R_PARISC_LTOFF_FPTR16DF
:
746 if (bfd_link_pic (info
) || maybe_dynamic
)
747 need_entry
= (NEED_DLT
| NEED_OPD
| NEED_PLT
);
749 need_entry
= (NEED_DLT
| NEED_OPD
| NEED_PLT
);
750 dynrel_type
= R_PARISC_FPTR64
;
753 /* This is a simple OPD entry. */
754 case R_PARISC_FPTR64
:
755 if (bfd_link_pic (info
) || maybe_dynamic
)
756 need_entry
= (NEED_OPD
| NEED_PLT
| NEED_DYNREL
);
758 need_entry
= (NEED_OPD
| NEED_PLT
);
759 dynrel_type
= R_PARISC_FPTR64
;
762 /* Add more cases as needed. */
770 /* Stash away enough information to be able to find this symbol
771 regardless of whether or not it is local or global. */
773 hh
->sym_indx
= r_symndx
;
776 /* Create what's needed. */
777 if (need_entry
& NEED_DLT
)
779 /* Allocate space for a DLT entry, as well as a dynamic
780 relocation for this entry. */
781 if (! hppa_info
->dlt_sec
782 && ! get_dlt (abfd
, info
, hppa_info
))
788 hh
->eh
.got
.refcount
+= 1;
792 bfd_signed_vma
*local_dlt_refcounts
;
794 /* This is a DLT entry for a local symbol. */
795 local_dlt_refcounts
= hppa64_elf_local_refcounts (abfd
);
796 if (local_dlt_refcounts
== NULL
)
798 local_dlt_refcounts
[r_symndx
] += 1;
802 if (need_entry
& NEED_PLT
)
804 if (! hppa_info
->plt_sec
805 && ! get_plt (abfd
, info
, hppa_info
))
811 hh
->eh
.needs_plt
= 1;
812 hh
->eh
.plt
.refcount
+= 1;
816 bfd_signed_vma
*local_dlt_refcounts
;
817 bfd_signed_vma
*local_plt_refcounts
;
819 /* This is a PLT entry for a local symbol. */
820 local_dlt_refcounts
= hppa64_elf_local_refcounts (abfd
);
821 if (local_dlt_refcounts
== NULL
)
823 local_plt_refcounts
= local_dlt_refcounts
+ symtab_hdr
->sh_info
;
824 local_plt_refcounts
[r_symndx
] += 1;
828 if (need_entry
& NEED_STUB
)
830 if (! hppa_info
->stub_sec
831 && ! get_stub (abfd
, info
, hppa_info
))
837 if (need_entry
& NEED_OPD
)
839 if (! hppa_info
->opd_sec
840 && ! get_opd (abfd
, info
, hppa_info
))
843 /* FPTRs are not allocated by the dynamic linker for PA64,
844 though it is possible that will change in the future. */
850 bfd_signed_vma
*local_dlt_refcounts
;
851 bfd_signed_vma
*local_opd_refcounts
;
853 /* This is a OPD for a local symbol. */
854 local_dlt_refcounts
= hppa64_elf_local_refcounts (abfd
);
855 if (local_dlt_refcounts
== NULL
)
857 local_opd_refcounts
= (local_dlt_refcounts
858 + 2 * symtab_hdr
->sh_info
);
859 local_opd_refcounts
[r_symndx
] += 1;
863 /* Add a new dynamic relocation to the chain of dynamic
864 relocations for this symbol. */
865 if ((need_entry
& NEED_DYNREL
) && (sec
->flags
& SEC_ALLOC
))
867 if (! hppa_info
->other_rel_sec
868 && ! get_reloc_section (abfd
, hppa_info
, sec
))
871 /* Count dynamic relocations against global symbols. */
873 && !count_dyn_reloc (abfd
, hh
, dynrel_type
, sec
,
874 sec_symndx
, rel
->r_offset
, rel
->r_addend
))
877 /* If we are building a shared library and we just recorded
878 a dynamic R_PARISC_FPTR64 relocation, then make sure the
879 section symbol for this section ends up in the dynamic
881 if (bfd_link_pic (info
) && dynrel_type
== R_PARISC_FPTR64
882 && ! (bfd_elf_link_record_local_dynamic_symbol
883 (info
, abfd
, sec_symndx
)))
894 struct elf64_hppa_allocate_data
896 struct bfd_link_info
*info
;
900 /* Should we do dynamic things to this symbol? */
903 elf64_hppa_dynamic_symbol_p (struct elf_link_hash_entry
*eh
,
904 struct bfd_link_info
*info
)
906 /* ??? What, if anything, needs to happen wrt STV_PROTECTED symbols
907 and relocations that retrieve a function descriptor? Assume the
909 if (_bfd_elf_dynamic_symbol_p (eh
, info
, 1))
911 /* ??? Why is this here and not elsewhere is_local_label_name. */
912 if (eh
->root
.root
.string
[0] == '$' && eh
->root
.root
.string
[1] == '$')
921 /* Mark all functions exported by this file so that we can later allocate
922 entries in .opd for them. */
925 elf64_hppa_mark_exported_functions (struct elf_link_hash_entry
*eh
, void *data
)
927 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
928 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
929 struct elf64_hppa_link_hash_table
*hppa_info
;
931 hppa_info
= hppa_link_hash_table (info
);
932 if (hppa_info
== NULL
)
936 && (eh
->root
.type
== bfd_link_hash_defined
937 || eh
->root
.type
== bfd_link_hash_defweak
)
938 && eh
->root
.u
.def
.section
->output_section
!= NULL
939 && eh
->type
== STT_FUNC
)
941 if (! hppa_info
->opd_sec
942 && ! get_opd (hppa_info
->root
.dynobj
, info
, hppa_info
))
947 /* Put a flag here for output_symbol_hook. */
955 /* Allocate space for a DLT entry. */
958 allocate_global_data_dlt (struct elf_link_hash_entry
*eh
, void *data
)
960 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
961 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
965 if (bfd_link_pic (x
->info
))
967 /* Possibly add the symbol to the local dynamic symbol
968 table since we might need to create a dynamic relocation
970 if (eh
->dynindx
== -1 && eh
->type
!= STT_PARISC_MILLI
)
972 bfd
*owner
= eh
->root
.u
.def
.section
->owner
;
974 if (! (bfd_elf_link_record_local_dynamic_symbol
975 (x
->info
, owner
, hh
->sym_indx
)))
980 hh
->dlt_offset
= x
->ofs
;
981 x
->ofs
+= DLT_ENTRY_SIZE
;
986 /* Allocate space for a DLT.PLT entry. */
989 allocate_global_data_plt (struct elf_link_hash_entry
*eh
, void *data
)
991 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
992 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*) data
;
995 && elf64_hppa_dynamic_symbol_p (eh
, x
->info
)
996 && !((eh
->root
.type
== bfd_link_hash_defined
997 || eh
->root
.type
== bfd_link_hash_defweak
)
998 && eh
->root
.u
.def
.section
->output_section
!= NULL
))
1000 hh
->plt_offset
= x
->ofs
;
1001 x
->ofs
+= PLT_ENTRY_SIZE
;
1002 if (hh
->plt_offset
< 0x2000)
1004 struct elf64_hppa_link_hash_table
*hppa_info
;
1006 hppa_info
= hppa_link_hash_table (x
->info
);
1007 if (hppa_info
== NULL
)
1010 hppa_info
->gp_offset
= hh
->plt_offset
;
1019 /* Allocate space for a STUB entry. */
1022 allocate_global_data_stub (struct elf_link_hash_entry
*eh
, void *data
)
1024 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
1025 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1028 && elf64_hppa_dynamic_symbol_p (eh
, x
->info
)
1029 && !((eh
->root
.type
== bfd_link_hash_defined
1030 || eh
->root
.type
== bfd_link_hash_defweak
)
1031 && eh
->root
.u
.def
.section
->output_section
!= NULL
))
1033 hh
->stub_offset
= x
->ofs
;
1034 x
->ofs
+= sizeof (plt_stub
);
1041 /* Allocate space for a FPTR entry. */
1044 allocate_global_data_opd (struct elf_link_hash_entry
*eh
, void *data
)
1046 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
1047 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1049 if (hh
&& hh
->want_opd
)
1051 /* We never need an opd entry for a symbol which is not
1052 defined by this output file. */
1053 if (hh
&& (hh
->eh
.root
.type
== bfd_link_hash_undefined
1054 || hh
->eh
.root
.type
== bfd_link_hash_undefweak
1055 || hh
->eh
.root
.u
.def
.section
->output_section
== NULL
))
1058 /* If we are creating a shared library, took the address of a local
1059 function or might export this function from this object file, then
1060 we have to create an opd descriptor. */
1061 else if (bfd_link_pic (x
->info
)
1063 || (hh
->eh
.dynindx
== -1 && hh
->eh
.type
!= STT_PARISC_MILLI
)
1064 || (hh
->eh
.root
.type
== bfd_link_hash_defined
1065 || hh
->eh
.root
.type
== bfd_link_hash_defweak
))
1067 /* If we are creating a shared library, then we will have to
1068 create a runtime relocation for the symbol to properly
1069 initialize the .opd entry. Make sure the symbol gets
1070 added to the dynamic symbol table. */
1071 if (bfd_link_pic (x
->info
)
1072 && (hh
== NULL
|| (hh
->eh
.dynindx
== -1)))
1075 /* PR 6511: Default to using the dynamic symbol table. */
1076 owner
= (hh
->owner
? hh
->owner
: eh
->root
.u
.def
.section
->owner
);
1078 if (!bfd_elf_link_record_local_dynamic_symbol
1079 (x
->info
, owner
, hh
->sym_indx
))
1083 /* This may not be necessary or desirable anymore now that
1084 we have some support for dealing with section symbols
1085 in dynamic relocs. But name munging does make the result
1086 much easier to debug. ie, the EPLT reloc will reference
1087 a symbol like .foobar, instead of .text + offset. */
1088 if (bfd_link_pic (x
->info
) && eh
)
1091 struct elf_link_hash_entry
*nh
;
1093 new_name
= concat (".", eh
->root
.root
.string
, NULL
);
1095 nh
= elf_link_hash_lookup (elf_hash_table (x
->info
),
1096 new_name
, TRUE
, TRUE
, TRUE
);
1099 nh
->root
.type
= eh
->root
.type
;
1100 nh
->root
.u
.def
.value
= eh
->root
.u
.def
.value
;
1101 nh
->root
.u
.def
.section
= eh
->root
.u
.def
.section
;
1103 if (! bfd_elf_link_record_dynamic_symbol (x
->info
, nh
))
1106 hh
->opd_offset
= x
->ofs
;
1107 x
->ofs
+= OPD_ENTRY_SIZE
;
1110 /* Otherwise we do not need an opd entry. */
1117 /* HP requires the EI_OSABI field to be filled in. The assignment to
1118 EI_ABIVERSION may not be strictly necessary. */
1121 elf64_hppa_init_file_header (bfd
*abfd
, struct bfd_link_info
*info
)
1123 Elf_Internal_Ehdr
*i_ehdrp
;
1125 if (!_bfd_elf_init_file_header (abfd
, info
))
1128 i_ehdrp
= elf_elfheader (abfd
);
1129 i_ehdrp
->e_ident
[EI_OSABI
] = get_elf_backend_data (abfd
)->elf_osabi
;
1130 i_ehdrp
->e_ident
[EI_ABIVERSION
] = 1;
1134 /* Create function descriptor section (.opd). This section is called .opd
1135 because it contains "official procedure descriptors". The "official"
1136 refers to the fact that these descriptors are used when taking the address
1137 of a procedure, thus ensuring a unique address for each procedure. */
1141 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1142 struct elf64_hppa_link_hash_table
*hppa_info
)
1147 opd
= hppa_info
->opd_sec
;
1150 dynobj
= hppa_info
->root
.dynobj
;
1152 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1154 opd
= bfd_make_section_anyway_with_flags (dynobj
, ".opd",
1159 | SEC_LINKER_CREATED
));
1161 || !bfd_set_section_alignment (opd
, 3))
1167 hppa_info
->opd_sec
= opd
;
1173 /* Create the PLT section. */
1177 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1178 struct elf64_hppa_link_hash_table
*hppa_info
)
1183 plt
= hppa_info
->plt_sec
;
1186 dynobj
= hppa_info
->root
.dynobj
;
1188 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1190 plt
= bfd_make_section_anyway_with_flags (dynobj
, ".plt",
1195 | SEC_LINKER_CREATED
));
1197 || !bfd_set_section_alignment (plt
, 3))
1203 hppa_info
->plt_sec
= plt
;
1209 /* Create the DLT section. */
1213 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1214 struct elf64_hppa_link_hash_table
*hppa_info
)
1219 dlt
= hppa_info
->dlt_sec
;
1222 dynobj
= hppa_info
->root
.dynobj
;
1224 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1226 dlt
= bfd_make_section_anyway_with_flags (dynobj
, ".dlt",
1231 | SEC_LINKER_CREATED
));
1233 || !bfd_set_section_alignment (dlt
, 3))
1239 hppa_info
->dlt_sec
= dlt
;
1245 /* Create the stubs section. */
1248 get_stub (bfd
*abfd
,
1249 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1250 struct elf64_hppa_link_hash_table
*hppa_info
)
1255 stub
= hppa_info
->stub_sec
;
1258 dynobj
= hppa_info
->root
.dynobj
;
1260 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1262 stub
= bfd_make_section_anyway_with_flags (dynobj
, ".stub",
1263 (SEC_ALLOC
| SEC_LOAD
1267 | SEC_LINKER_CREATED
));
1269 || !bfd_set_section_alignment (stub
, 3))
1275 hppa_info
->stub_sec
= stub
;
1281 /* Create sections necessary for dynamic linking. This is only a rough
1282 cut and will likely change as we learn more about the somewhat
1283 unusual dynamic linking scheme HP uses.
1286 Contains code to implement cross-space calls. The first time one
1287 of the stubs is used it will call into the dynamic linker, later
1288 calls will go straight to the target.
1290 The only stub we support right now looks like
1294 ldd OFFSET+8(%dp),%dp
1296 Other stubs may be needed in the future. We may want the remove
1297 the break/nop instruction. It is only used right now to keep the
1298 offset of a .plt entry and a .stub entry in sync.
1301 This is what most people call the .got. HP used a different name.
1305 Relocations for the DLT.
1308 Function pointers as address,gp pairs.
1311 Should contain dynamic IPLT (and EPLT?) relocations.
1317 EPLT relocations for symbols exported from shared libraries. */
1320 elf64_hppa_create_dynamic_sections (bfd
*abfd
,
1321 struct bfd_link_info
*info
)
1324 struct elf64_hppa_link_hash_table
*hppa_info
;
1326 hppa_info
= hppa_link_hash_table (info
);
1327 if (hppa_info
== NULL
)
1330 if (! get_stub (abfd
, info
, hppa_info
))
1333 if (! get_dlt (abfd
, info
, hppa_info
))
1336 if (! get_plt (abfd
, info
, hppa_info
))
1339 if (! get_opd (abfd
, info
, hppa_info
))
1342 s
= bfd_make_section_anyway_with_flags (abfd
, ".rela.dlt",
1343 (SEC_ALLOC
| SEC_LOAD
1347 | SEC_LINKER_CREATED
));
1349 || !bfd_set_section_alignment (s
, 3))
1351 hppa_info
->dlt_rel_sec
= s
;
1353 s
= bfd_make_section_anyway_with_flags (abfd
, ".rela.plt",
1354 (SEC_ALLOC
| SEC_LOAD
1358 | SEC_LINKER_CREATED
));
1360 || !bfd_set_section_alignment (s
, 3))
1362 hppa_info
->plt_rel_sec
= s
;
1364 s
= bfd_make_section_anyway_with_flags (abfd
, ".rela.data",
1365 (SEC_ALLOC
| SEC_LOAD
1369 | SEC_LINKER_CREATED
));
1371 || !bfd_set_section_alignment (s
, 3))
1373 hppa_info
->other_rel_sec
= s
;
1375 s
= bfd_make_section_anyway_with_flags (abfd
, ".rela.opd",
1376 (SEC_ALLOC
| SEC_LOAD
1380 | SEC_LINKER_CREATED
));
1382 || !bfd_set_section_alignment (s
, 3))
1384 hppa_info
->opd_rel_sec
= s
;
1389 /* Allocate dynamic relocations for those symbols that turned out
1393 allocate_dynrel_entries (struct elf_link_hash_entry
*eh
, void *data
)
1395 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
1396 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1397 struct elf64_hppa_link_hash_table
*hppa_info
;
1398 struct elf64_hppa_dyn_reloc_entry
*rent
;
1399 bfd_boolean dynamic_symbol
, shared
;
1401 hppa_info
= hppa_link_hash_table (x
->info
);
1402 if (hppa_info
== NULL
)
1405 dynamic_symbol
= elf64_hppa_dynamic_symbol_p (eh
, x
->info
);
1406 shared
= bfd_link_pic (x
->info
);
1408 /* We may need to allocate relocations for a non-dynamic symbol
1409 when creating a shared library. */
1410 if (!dynamic_symbol
&& !shared
)
1413 /* Take care of the normal data relocations. */
1415 for (rent
= hh
->reloc_entries
; rent
; rent
= rent
->next
)
1417 /* Allocate one iff we are building a shared library, the relocation
1418 isn't a R_PARISC_FPTR64, or we don't want an opd entry. */
1419 if (!shared
&& rent
->type
== R_PARISC_FPTR64
&& hh
->want_opd
)
1422 hppa_info
->other_rel_sec
->size
+= sizeof (Elf64_External_Rela
);
1424 /* Make sure this symbol gets into the dynamic symbol table if it is
1425 not already recorded. ?!? This should not be in the loop since
1426 the symbol need only be added once. */
1427 if (eh
->dynindx
== -1 && eh
->type
!= STT_PARISC_MILLI
)
1428 if (!bfd_elf_link_record_local_dynamic_symbol
1429 (x
->info
, rent
->sec
->owner
, hh
->sym_indx
))
1433 /* Take care of the GOT and PLT relocations. */
1435 if ((dynamic_symbol
|| shared
) && hh
->want_dlt
)
1436 hppa_info
->dlt_rel_sec
->size
+= sizeof (Elf64_External_Rela
);
1438 /* If we are building a shared library, then every symbol that has an
1439 opd entry will need an EPLT relocation to relocate the symbol's address
1440 and __gp value based on the runtime load address. */
1441 if (shared
&& hh
->want_opd
)
1442 hppa_info
->opd_rel_sec
->size
+= sizeof (Elf64_External_Rela
);
1444 if (hh
->want_plt
&& dynamic_symbol
)
1446 bfd_size_type t
= 0;
1448 /* Dynamic symbols get one IPLT relocation. Local symbols in
1449 shared libraries get two REL relocations. Local symbols in
1450 main applications get nothing. */
1452 t
= sizeof (Elf64_External_Rela
);
1454 t
= 2 * sizeof (Elf64_External_Rela
);
1456 hppa_info
->plt_rel_sec
->size
+= t
;
1462 /* Adjust a symbol defined by a dynamic object and referenced by a
1466 elf64_hppa_adjust_dynamic_symbol (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1467 struct elf_link_hash_entry
*eh
)
1469 /* ??? Undefined symbols with PLT entries should be re-defined
1470 to be the PLT entry. */
1472 /* If this is a weak symbol, and there is a real definition, the
1473 processor independent code will have arranged for us to see the
1474 real definition first, and we can just use the same value. */
1475 if (eh
->is_weakalias
)
1477 struct elf_link_hash_entry
*def
= weakdef (eh
);
1478 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
1479 eh
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
1480 eh
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
1484 /* If this is a reference to a symbol defined by a dynamic object which
1485 is not a function, we might allocate the symbol in our .dynbss section
1486 and allocate a COPY dynamic relocation.
1488 But PA64 code is canonically PIC, so as a rule we can avoid this sort
1494 /* This function is called via elf_link_hash_traverse to mark millicode
1495 symbols with a dynindx of -1 and to remove the string table reference
1496 from the dynamic symbol table. If the symbol is not a millicode symbol,
1497 elf64_hppa_mark_exported_functions is called. */
1500 elf64_hppa_mark_milli_and_exported_functions (struct elf_link_hash_entry
*eh
,
1503 struct bfd_link_info
*info
= (struct bfd_link_info
*) data
;
1505 if (eh
->type
== STT_PARISC_MILLI
)
1507 if (eh
->dynindx
!= -1)
1510 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
1516 return elf64_hppa_mark_exported_functions (eh
, data
);
1519 /* Set the final sizes of the dynamic sections and allocate memory for
1520 the contents of our special sections. */
1523 elf64_hppa_size_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
1525 struct elf64_hppa_link_hash_table
*hppa_info
;
1526 struct elf64_hppa_allocate_data data
;
1532 bfd_boolean reltext
;
1534 hppa_info
= hppa_link_hash_table (info
);
1535 if (hppa_info
== NULL
)
1538 dynobj
= hppa_info
->root
.dynobj
;
1539 BFD_ASSERT (dynobj
!= NULL
);
1541 /* Mark each function this program exports so that we will allocate
1542 space in the .opd section for each function's FPTR. If we are
1543 creating dynamic sections, change the dynamic index of millicode
1544 symbols to -1 and remove them from the string table for .dynstr.
1546 We have to traverse the main linker hash table since we have to
1547 find functions which may not have been mentioned in any relocs. */
1548 elf_link_hash_traverse (&hppa_info
->root
,
1549 (hppa_info
->root
.dynamic_sections_created
1550 ? elf64_hppa_mark_milli_and_exported_functions
1551 : elf64_hppa_mark_exported_functions
),
1554 if (hppa_info
->root
.dynamic_sections_created
)
1556 /* Set the contents of the .interp section to the interpreter. */
1557 if (bfd_link_executable (info
) && !info
->nointerp
)
1559 sec
= bfd_get_linker_section (dynobj
, ".interp");
1560 BFD_ASSERT (sec
!= NULL
);
1561 sec
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1562 sec
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1567 /* We may have created entries in the .rela.got section.
1568 However, if we are not creating the dynamic sections, we will
1569 not actually use these entries. Reset the size of .rela.dlt,
1570 which will cause it to get stripped from the output file
1572 sec
= hppa_info
->dlt_rel_sec
;
1577 /* Set up DLT, PLT and OPD offsets for local syms, and space for local
1579 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
1581 bfd_signed_vma
*local_dlt
;
1582 bfd_signed_vma
*end_local_dlt
;
1583 bfd_signed_vma
*local_plt
;
1584 bfd_signed_vma
*end_local_plt
;
1585 bfd_signed_vma
*local_opd
;
1586 bfd_signed_vma
*end_local_opd
;
1587 bfd_size_type locsymcount
;
1588 Elf_Internal_Shdr
*symtab_hdr
;
1591 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
1594 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1596 struct elf64_hppa_dyn_reloc_entry
*hdh_p
;
1598 for (hdh_p
= ((struct elf64_hppa_dyn_reloc_entry
*)
1599 elf_section_data (sec
)->local_dynrel
);
1601 hdh_p
= hdh_p
->next
)
1603 if (!bfd_is_abs_section (hdh_p
->sec
)
1604 && bfd_is_abs_section (hdh_p
->sec
->output_section
))
1606 /* Input section has been discarded, either because
1607 it is a copy of a linkonce section or due to
1608 linker script /DISCARD/, so we'll be discarding
1611 else if (hdh_p
->count
!= 0)
1613 srel
= elf_section_data (hdh_p
->sec
)->sreloc
;
1614 srel
->size
+= hdh_p
->count
* sizeof (Elf64_External_Rela
);
1615 if ((hdh_p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
1616 info
->flags
|= DF_TEXTREL
;
1621 local_dlt
= elf_local_got_refcounts (ibfd
);
1625 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
1626 locsymcount
= symtab_hdr
->sh_info
;
1627 end_local_dlt
= local_dlt
+ locsymcount
;
1628 sec
= hppa_info
->dlt_sec
;
1629 srel
= hppa_info
->dlt_rel_sec
;
1630 for (; local_dlt
< end_local_dlt
; ++local_dlt
)
1634 *local_dlt
= sec
->size
;
1635 sec
->size
+= DLT_ENTRY_SIZE
;
1636 if (bfd_link_pic (info
))
1638 srel
->size
+= sizeof (Elf64_External_Rela
);
1642 *local_dlt
= (bfd_vma
) -1;
1645 local_plt
= end_local_dlt
;
1646 end_local_plt
= local_plt
+ locsymcount
;
1647 if (! hppa_info
->root
.dynamic_sections_created
)
1649 /* Won't be used, but be safe. */
1650 for (; local_plt
< end_local_plt
; ++local_plt
)
1651 *local_plt
= (bfd_vma
) -1;
1655 sec
= hppa_info
->plt_sec
;
1656 srel
= hppa_info
->plt_rel_sec
;
1657 for (; local_plt
< end_local_plt
; ++local_plt
)
1661 *local_plt
= sec
->size
;
1662 sec
->size
+= PLT_ENTRY_SIZE
;
1663 if (bfd_link_pic (info
))
1664 srel
->size
+= sizeof (Elf64_External_Rela
);
1667 *local_plt
= (bfd_vma
) -1;
1671 local_opd
= end_local_plt
;
1672 end_local_opd
= local_opd
+ locsymcount
;
1673 if (! hppa_info
->root
.dynamic_sections_created
)
1675 /* Won't be used, but be safe. */
1676 for (; local_opd
< end_local_opd
; ++local_opd
)
1677 *local_opd
= (bfd_vma
) -1;
1681 sec
= hppa_info
->opd_sec
;
1682 srel
= hppa_info
->opd_rel_sec
;
1683 for (; local_opd
< end_local_opd
; ++local_opd
)
1687 *local_opd
= sec
->size
;
1688 sec
->size
+= OPD_ENTRY_SIZE
;
1689 if (bfd_link_pic (info
))
1690 srel
->size
+= sizeof (Elf64_External_Rela
);
1693 *local_opd
= (bfd_vma
) -1;
1698 /* Allocate the GOT entries. */
1701 if (hppa_info
->dlt_sec
)
1703 data
.ofs
= hppa_info
->dlt_sec
->size
;
1704 elf_link_hash_traverse (&hppa_info
->root
,
1705 allocate_global_data_dlt
, &data
);
1706 hppa_info
->dlt_sec
->size
= data
.ofs
;
1709 if (hppa_info
->plt_sec
)
1711 data
.ofs
= hppa_info
->plt_sec
->size
;
1712 elf_link_hash_traverse (&hppa_info
->root
,
1713 allocate_global_data_plt
, &data
);
1714 hppa_info
->plt_sec
->size
= data
.ofs
;
1717 if (hppa_info
->stub_sec
)
1720 elf_link_hash_traverse (&hppa_info
->root
,
1721 allocate_global_data_stub
, &data
);
1722 hppa_info
->stub_sec
->size
= data
.ofs
;
1725 /* Allocate space for entries in the .opd section. */
1726 if (hppa_info
->opd_sec
)
1728 data
.ofs
= hppa_info
->opd_sec
->size
;
1729 elf_link_hash_traverse (&hppa_info
->root
,
1730 allocate_global_data_opd
, &data
);
1731 hppa_info
->opd_sec
->size
= data
.ofs
;
1734 /* Now allocate space for dynamic relocations, if necessary. */
1735 if (hppa_info
->root
.dynamic_sections_created
)
1736 elf_link_hash_traverse (&hppa_info
->root
,
1737 allocate_dynrel_entries
, &data
);
1739 /* The sizes of all the sections are set. Allocate memory for them. */
1743 for (sec
= dynobj
->sections
; sec
!= NULL
; sec
= sec
->next
)
1747 if ((sec
->flags
& SEC_LINKER_CREATED
) == 0)
1750 /* It's OK to base decisions on the section name, because none
1751 of the dynobj section names depend upon the input files. */
1752 name
= bfd_section_name (sec
);
1754 if (strcmp (name
, ".plt") == 0)
1756 /* Remember whether there is a PLT. */
1757 plt
= sec
->size
!= 0;
1759 else if (strcmp (name
, ".opd") == 0
1760 || CONST_STRNEQ (name
, ".dlt")
1761 || strcmp (name
, ".stub") == 0
1762 || strcmp (name
, ".got") == 0)
1764 /* Strip this section if we don't need it; see the comment below. */
1766 else if (CONST_STRNEQ (name
, ".rela"))
1772 /* Remember whether there are any reloc sections other
1774 if (strcmp (name
, ".rela.plt") != 0)
1776 const char *outname
;
1780 /* If this relocation section applies to a read only
1781 section, then we probably need a DT_TEXTREL
1782 entry. The entries in the .rela.plt section
1783 really apply to the .got section, which we
1784 created ourselves and so know is not readonly. */
1785 outname
= bfd_section_name (sec
->output_section
);
1786 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
1788 && (target
->flags
& SEC_READONLY
) != 0
1789 && (target
->flags
& SEC_ALLOC
) != 0)
1793 /* We use the reloc_count field as a counter if we need
1794 to copy relocs into the output file. */
1795 sec
->reloc_count
= 0;
1800 /* It's not one of our sections, so don't allocate space. */
1806 /* If we don't need this section, strip it from the
1807 output file. This is mostly to handle .rela.bss and
1808 .rela.plt. We must create both sections in
1809 create_dynamic_sections, because they must be created
1810 before the linker maps input sections to output
1811 sections. The linker does that before
1812 adjust_dynamic_symbol is called, and it is that
1813 function which decides whether anything needs to go
1814 into these sections. */
1815 sec
->flags
|= SEC_EXCLUDE
;
1819 if ((sec
->flags
& SEC_HAS_CONTENTS
) == 0)
1822 /* Allocate memory for the section contents if it has not
1823 been allocated already. We use bfd_zalloc here in case
1824 unused entries are not reclaimed before the section's
1825 contents are written out. This should not happen, but this
1826 way if it does, we get a R_PARISC_NONE reloc instead of
1828 if (sec
->contents
== NULL
)
1830 sec
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, sec
->size
);
1831 if (sec
->contents
== NULL
)
1836 if (hppa_info
->root
.dynamic_sections_created
)
1838 /* Always create a DT_PLTGOT. It actually has nothing to do with
1839 the PLT, it is how we communicate the __gp value of a load
1840 module to the dynamic linker. */
1841 #define add_dynamic_entry(TAG, VAL) \
1842 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
1844 if (!add_dynamic_entry (DT_HP_DLD_FLAGS
, 0)
1845 || !add_dynamic_entry (DT_PLTGOT
, 0))
1848 /* Add some entries to the .dynamic section. We fill in the
1849 values later, in elf64_hppa_finish_dynamic_sections, but we
1850 must add the entries now so that we get the correct size for
1851 the .dynamic section. The DT_DEBUG entry is filled in by the
1852 dynamic linker and used by the debugger. */
1853 if (! bfd_link_pic (info
))
1855 if (!add_dynamic_entry (DT_DEBUG
, 0)
1856 || !add_dynamic_entry (DT_HP_DLD_HOOK
, 0)
1857 || !add_dynamic_entry (DT_HP_LOAD_MAP
, 0))
1861 /* Force DT_FLAGS to always be set.
1862 Required by HPUX 11.00 patch PHSS_26559. */
1863 if (!add_dynamic_entry (DT_FLAGS
, (info
)->flags
))
1868 if (!add_dynamic_entry (DT_PLTRELSZ
, 0)
1869 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
1870 || !add_dynamic_entry (DT_JMPREL
, 0))
1876 if (!add_dynamic_entry (DT_RELA
, 0)
1877 || !add_dynamic_entry (DT_RELASZ
, 0)
1878 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
1884 if (!add_dynamic_entry (DT_TEXTREL
, 0))
1886 info
->flags
|= DF_TEXTREL
;
1889 #undef add_dynamic_entry
1894 /* Called after we have output the symbol into the dynamic symbol
1895 table, but before we output the symbol into the normal symbol
1898 For some symbols we had to change their address when outputting
1899 the dynamic symbol table. We undo that change here so that
1900 the symbols have their expected value in the normal symbol
1904 elf64_hppa_link_output_symbol_hook (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1906 Elf_Internal_Sym
*sym
,
1907 asection
*input_sec ATTRIBUTE_UNUSED
,
1908 struct elf_link_hash_entry
*eh
)
1910 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
1912 /* We may be called with the file symbol or section symbols.
1913 They never need munging, so it is safe to ignore them. */
1917 /* Function symbols for which we created .opd entries *may* have been
1918 munged by finish_dynamic_symbol and have to be un-munged here.
1920 Note that finish_dynamic_symbol sometimes turns dynamic symbols
1921 into non-dynamic ones, so we initialize st_shndx to -1 in
1922 mark_exported_functions and check to see if it was overwritten
1923 here instead of just checking eh->dynindx. */
1924 if (hh
->want_opd
&& hh
->st_shndx
!= -1)
1926 /* Restore the saved value and section index. */
1927 sym
->st_value
= hh
->st_value
;
1928 sym
->st_shndx
= hh
->st_shndx
;
1934 /* Finish up dynamic symbol handling. We set the contents of various
1935 dynamic sections here. */
1938 elf64_hppa_finish_dynamic_symbol (bfd
*output_bfd
,
1939 struct bfd_link_info
*info
,
1940 struct elf_link_hash_entry
*eh
,
1941 Elf_Internal_Sym
*sym
)
1943 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
1944 asection
*stub
, *splt
, *sopd
, *spltrel
;
1945 struct elf64_hppa_link_hash_table
*hppa_info
;
1947 hppa_info
= hppa_link_hash_table (info
);
1948 if (hppa_info
== NULL
)
1951 stub
= hppa_info
->stub_sec
;
1952 splt
= hppa_info
->plt_sec
;
1953 sopd
= hppa_info
->opd_sec
;
1954 spltrel
= hppa_info
->plt_rel_sec
;
1956 /* Incredible. It is actually necessary to NOT use the symbol's real
1957 value when building the dynamic symbol table for a shared library.
1958 At least for symbols that refer to functions.
1960 We will store a new value and section index into the symbol long
1961 enough to output it into the dynamic symbol table, then we restore
1962 the original values (in elf64_hppa_link_output_symbol_hook). */
1965 BFD_ASSERT (sopd
!= NULL
);
1967 /* Save away the original value and section index so that we
1968 can restore them later. */
1969 hh
->st_value
= sym
->st_value
;
1970 hh
->st_shndx
= sym
->st_shndx
;
1972 /* For the dynamic symbol table entry, we want the value to be
1973 address of this symbol's entry within the .opd section. */
1974 sym
->st_value
= (hh
->opd_offset
1975 + sopd
->output_offset
1976 + sopd
->output_section
->vma
);
1977 sym
->st_shndx
= _bfd_elf_section_from_bfd_section (output_bfd
,
1978 sopd
->output_section
);
1981 /* Initialize a .plt entry if requested. */
1983 && elf64_hppa_dynamic_symbol_p (eh
, info
))
1986 Elf_Internal_Rela rel
;
1989 BFD_ASSERT (splt
!= NULL
&& spltrel
!= NULL
);
1991 /* We do not actually care about the value in the PLT entry
1992 if we are creating a shared library and the symbol is
1993 still undefined, we create a dynamic relocation to fill
1994 in the correct value. */
1995 if (bfd_link_pic (info
) && eh
->root
.type
== bfd_link_hash_undefined
)
1998 value
= (eh
->root
.u
.def
.value
+ eh
->root
.u
.def
.section
->vma
);
2000 /* Fill in the entry in the procedure linkage table.
2002 The format of a plt entry is
2005 plt_offset is the offset within the PLT section at which to
2006 install the PLT entry.
2008 We are modifying the in-memory PLT contents here, so we do not add
2009 in the output_offset of the PLT section. */
2011 bfd_put_64 (splt
->owner
, value
, splt
->contents
+ hh
->plt_offset
);
2012 value
= _bfd_get_gp_value (info
->output_bfd
);
2013 bfd_put_64 (splt
->owner
, value
, splt
->contents
+ hh
->plt_offset
+ 0x8);
2015 /* Create a dynamic IPLT relocation for this entry.
2017 We are creating a relocation in the output file's PLT section,
2018 which is included within the DLT secton. So we do need to include
2019 the PLT's output_offset in the computation of the relocation's
2021 rel
.r_offset
= (hh
->plt_offset
+ splt
->output_offset
2022 + splt
->output_section
->vma
);
2023 rel
.r_info
= ELF64_R_INFO (hh
->eh
.dynindx
, R_PARISC_IPLT
);
2026 loc
= spltrel
->contents
;
2027 loc
+= spltrel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2028 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rel
, loc
);
2031 /* Initialize an external call stub entry if requested. */
2033 && elf64_hppa_dynamic_symbol_p (eh
, info
))
2037 unsigned int max_offset
;
2039 BFD_ASSERT (stub
!= NULL
);
2041 /* Install the generic stub template.
2043 We are modifying the contents of the stub section, so we do not
2044 need to include the stub section's output_offset here. */
2045 memcpy (stub
->contents
+ hh
->stub_offset
, plt_stub
, sizeof (plt_stub
));
2047 /* Fix up the first ldd instruction.
2049 We are modifying the contents of the STUB section in memory,
2050 so we do not need to include its output offset in this computation.
2052 Note the plt_offset value is the value of the PLT entry relative to
2053 the start of the PLT section. These instructions will reference
2054 data relative to the value of __gp, which may not necessarily have
2055 the same address as the start of the PLT section.
2057 gp_offset contains the offset of __gp within the PLT section. */
2058 value
= hh
->plt_offset
- hppa_info
->gp_offset
;
2060 insn
= bfd_get_32 (stub
->owner
, stub
->contents
+ hh
->stub_offset
);
2061 if (output_bfd
->arch_info
->mach
>= 25)
2063 /* Wide mode allows 16 bit offsets. */
2066 insn
|= re_assemble_16 ((int) value
);
2072 insn
|= re_assemble_14 ((int) value
);
2075 if ((value
& 7) || value
+ max_offset
>= 2*max_offset
- 8)
2078 /* xgettext:c-format */
2079 (_("stub entry for %s cannot load .plt, dp offset = %" PRId64
),
2080 hh
->eh
.root
.root
.string
, (int64_t) value
);
2084 bfd_put_32 (stub
->owner
, (bfd_vma
) insn
,
2085 stub
->contents
+ hh
->stub_offset
);
2087 /* Fix up the second ldd instruction. */
2089 insn
= bfd_get_32 (stub
->owner
, stub
->contents
+ hh
->stub_offset
+ 8);
2090 if (output_bfd
->arch_info
->mach
>= 25)
2093 insn
|= re_assemble_16 ((int) value
);
2098 insn
|= re_assemble_14 ((int) value
);
2100 bfd_put_32 (stub
->owner
, (bfd_vma
) insn
,
2101 stub
->contents
+ hh
->stub_offset
+ 8);
2107 /* The .opd section contains FPTRs for each function this file
2108 exports. Initialize the FPTR entries. */
2111 elf64_hppa_finalize_opd (struct elf_link_hash_entry
*eh
, void *data
)
2113 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
2114 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
2115 struct elf64_hppa_link_hash_table
*hppa_info
;
2119 hppa_info
= hppa_link_hash_table (info
);
2120 if (hppa_info
== NULL
)
2123 sopd
= hppa_info
->opd_sec
;
2124 sopdrel
= hppa_info
->opd_rel_sec
;
2130 /* The first two words of an .opd entry are zero.
2132 We are modifying the contents of the OPD section in memory, so we
2133 do not need to include its output offset in this computation. */
2134 memset (sopd
->contents
+ hh
->opd_offset
, 0, 16);
2136 value
= (eh
->root
.u
.def
.value
2137 + eh
->root
.u
.def
.section
->output_section
->vma
2138 + eh
->root
.u
.def
.section
->output_offset
);
2140 /* The next word is the address of the function. */
2141 bfd_put_64 (sopd
->owner
, value
, sopd
->contents
+ hh
->opd_offset
+ 16);
2143 /* The last word is our local __gp value. */
2144 value
= _bfd_get_gp_value (info
->output_bfd
);
2145 bfd_put_64 (sopd
->owner
, value
, sopd
->contents
+ hh
->opd_offset
+ 24);
2148 /* If we are generating a shared library, we must generate EPLT relocations
2149 for each entry in the .opd, even for static functions (they may have
2150 had their address taken). */
2151 if (bfd_link_pic (info
) && hh
->want_opd
)
2153 Elf_Internal_Rela rel
;
2157 /* We may need to do a relocation against a local symbol, in
2158 which case we have to look up it's dynamic symbol index off
2159 the local symbol hash table. */
2160 if (eh
->dynindx
!= -1)
2161 dynindx
= eh
->dynindx
;
2164 = _bfd_elf_link_lookup_local_dynindx (info
, hh
->owner
,
2167 /* The offset of this relocation is the absolute address of the
2168 .opd entry for this symbol. */
2169 rel
.r_offset
= (hh
->opd_offset
+ sopd
->output_offset
2170 + sopd
->output_section
->vma
);
2172 /* If H is non-null, then we have an external symbol.
2174 It is imperative that we use a different dynamic symbol for the
2175 EPLT relocation if the symbol has global scope.
2177 In the dynamic symbol table, the function symbol will have a value
2178 which is address of the function's .opd entry.
2180 Thus, we can not use that dynamic symbol for the EPLT relocation
2181 (if we did, the data in the .opd would reference itself rather
2182 than the actual address of the function). Instead we have to use
2183 a new dynamic symbol which has the same value as the original global
2186 We prefix the original symbol with a "." and use the new symbol in
2187 the EPLT relocation. This new symbol has already been recorded in
2188 the symbol table, we just have to look it up and use it.
2190 We do not have such problems with static functions because we do
2191 not make their addresses in the dynamic symbol table point to
2192 the .opd entry. Ultimately this should be safe since a static
2193 function can not be directly referenced outside of its shared
2196 We do have to play similar games for FPTR relocations in shared
2197 libraries, including those for static symbols. See the FPTR
2198 handling in elf64_hppa_finalize_dynreloc. */
2202 struct elf_link_hash_entry
*nh
;
2204 new_name
= concat (".", eh
->root
.root
.string
, NULL
);
2206 nh
= elf_link_hash_lookup (elf_hash_table (info
),
2207 new_name
, TRUE
, TRUE
, FALSE
);
2209 /* All we really want from the new symbol is its dynamic
2212 dynindx
= nh
->dynindx
;
2217 rel
.r_info
= ELF64_R_INFO (dynindx
, R_PARISC_EPLT
);
2219 loc
= sopdrel
->contents
;
2220 loc
+= sopdrel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2221 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rel
, loc
);
2226 /* The .dlt section contains addresses for items referenced through the
2227 dlt. Note that we can have a DLTIND relocation for a local symbol, thus
2228 we can not depend on finish_dynamic_symbol to initialize the .dlt. */
2231 elf64_hppa_finalize_dlt (struct elf_link_hash_entry
*eh
, void *data
)
2233 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
2234 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
2235 struct elf64_hppa_link_hash_table
*hppa_info
;
2236 asection
*sdlt
, *sdltrel
;
2238 hppa_info
= hppa_link_hash_table (info
);
2239 if (hppa_info
== NULL
)
2242 sdlt
= hppa_info
->dlt_sec
;
2243 sdltrel
= hppa_info
->dlt_rel_sec
;
2245 /* H/DYN_H may refer to a local variable and we know it's
2246 address, so there is no need to create a relocation. Just install
2247 the proper value into the DLT, note this shortcut can not be
2248 skipped when building a shared library. */
2249 if (! bfd_link_pic (info
) && hh
&& hh
->want_dlt
)
2253 /* If we had an LTOFF_FPTR style relocation we want the DLT entry
2254 to point to the FPTR entry in the .opd section.
2256 We include the OPD's output offset in this computation as
2257 we are referring to an absolute address in the resulting
2261 value
= (hh
->opd_offset
2262 + hppa_info
->opd_sec
->output_offset
2263 + hppa_info
->opd_sec
->output_section
->vma
);
2265 else if ((eh
->root
.type
== bfd_link_hash_defined
2266 || eh
->root
.type
== bfd_link_hash_defweak
)
2267 && eh
->root
.u
.def
.section
)
2269 value
= eh
->root
.u
.def
.value
+ eh
->root
.u
.def
.section
->output_offset
;
2270 if (eh
->root
.u
.def
.section
->output_section
)
2271 value
+= eh
->root
.u
.def
.section
->output_section
->vma
;
2273 value
+= eh
->root
.u
.def
.section
->vma
;
2276 /* We have an undefined function reference. */
2279 /* We do not need to include the output offset of the DLT section
2280 here because we are modifying the in-memory contents. */
2281 bfd_put_64 (sdlt
->owner
, value
, sdlt
->contents
+ hh
->dlt_offset
);
2284 /* Create a relocation for the DLT entry associated with this symbol.
2285 When building a shared library the symbol does not have to be dynamic. */
2287 && (elf64_hppa_dynamic_symbol_p (eh
, info
) || bfd_link_pic (info
)))
2289 Elf_Internal_Rela rel
;
2293 /* We may need to do a relocation against a local symbol, in
2294 which case we have to look up it's dynamic symbol index off
2295 the local symbol hash table. */
2296 if (eh
&& eh
->dynindx
!= -1)
2297 dynindx
= eh
->dynindx
;
2300 = _bfd_elf_link_lookup_local_dynindx (info
, hh
->owner
,
2303 /* Create a dynamic relocation for this entry. Do include the output
2304 offset of the DLT entry since we need an absolute address in the
2305 resulting object file. */
2306 rel
.r_offset
= (hh
->dlt_offset
+ sdlt
->output_offset
2307 + sdlt
->output_section
->vma
);
2308 if (eh
&& eh
->type
== STT_FUNC
)
2309 rel
.r_info
= ELF64_R_INFO (dynindx
, R_PARISC_FPTR64
);
2311 rel
.r_info
= ELF64_R_INFO (dynindx
, R_PARISC_DIR64
);
2314 loc
= sdltrel
->contents
;
2315 loc
+= sdltrel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2316 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rel
, loc
);
2321 /* Finalize the dynamic relocations. Specifically the FPTR relocations
2322 for dynamic functions used to initialize static data. */
2325 elf64_hppa_finalize_dynreloc (struct elf_link_hash_entry
*eh
,
2328 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
2329 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
2330 struct elf64_hppa_link_hash_table
*hppa_info
;
2333 dynamic_symbol
= elf64_hppa_dynamic_symbol_p (eh
, info
);
2335 if (!dynamic_symbol
&& !bfd_link_pic (info
))
2338 if (hh
->reloc_entries
)
2340 struct elf64_hppa_dyn_reloc_entry
*rent
;
2343 hppa_info
= hppa_link_hash_table (info
);
2344 if (hppa_info
== NULL
)
2347 /* We may need to do a relocation against a local symbol, in
2348 which case we have to look up it's dynamic symbol index off
2349 the local symbol hash table. */
2350 if (eh
->dynindx
!= -1)
2351 dynindx
= eh
->dynindx
;
2354 = _bfd_elf_link_lookup_local_dynindx (info
, hh
->owner
,
2357 for (rent
= hh
->reloc_entries
; rent
; rent
= rent
->next
)
2359 Elf_Internal_Rela rel
;
2362 /* Allocate one iff we are building a shared library, the relocation
2363 isn't a R_PARISC_FPTR64, or we don't want an opd entry. */
2364 if (!bfd_link_pic (info
)
2365 && rent
->type
== R_PARISC_FPTR64
&& hh
->want_opd
)
2368 /* Create a dynamic relocation for this entry.
2370 We need the output offset for the reloc's section because
2371 we are creating an absolute address in the resulting object
2373 rel
.r_offset
= (rent
->offset
+ rent
->sec
->output_offset
2374 + rent
->sec
->output_section
->vma
);
2376 /* An FPTR64 relocation implies that we took the address of
2377 a function and that the function has an entry in the .opd
2378 section. We want the FPTR64 relocation to reference the
2381 We could munge the symbol value in the dynamic symbol table
2382 (in fact we already do for functions with global scope) to point
2383 to the .opd entry. Then we could use that dynamic symbol in
2386 Or we could do something sensible, not munge the symbol's
2387 address and instead just use a different symbol to reference
2388 the .opd entry. At least that seems sensible until you
2389 realize there's no local dynamic symbols we can use for that
2390 purpose. Thus the hair in the check_relocs routine.
2392 We use a section symbol recorded by check_relocs as the
2393 base symbol for the relocation. The addend is the difference
2394 between the section symbol and the address of the .opd entry. */
2395 if (bfd_link_pic (info
)
2396 && rent
->type
== R_PARISC_FPTR64
&& hh
->want_opd
)
2398 bfd_vma value
, value2
;
2400 /* First compute the address of the opd entry for this symbol. */
2401 value
= (hh
->opd_offset
2402 + hppa_info
->opd_sec
->output_section
->vma
2403 + hppa_info
->opd_sec
->output_offset
);
2405 /* Compute the value of the start of the section with
2407 value2
= (rent
->sec
->output_section
->vma
2408 + rent
->sec
->output_offset
);
2410 /* Compute the difference between the start of the section
2411 with the relocation and the opd entry. */
2414 /* The result becomes the addend of the relocation. */
2415 rel
.r_addend
= value
;
2417 /* The section symbol becomes the symbol for the dynamic
2420 = _bfd_elf_link_lookup_local_dynindx (info
,
2425 rel
.r_addend
= rent
->addend
;
2427 rel
.r_info
= ELF64_R_INFO (dynindx
, rent
->type
);
2429 loc
= hppa_info
->other_rel_sec
->contents
;
2430 loc
+= (hppa_info
->other_rel_sec
->reloc_count
++
2431 * sizeof (Elf64_External_Rela
));
2432 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rel
, loc
);
2439 /* Used to decide how to sort relocs in an optimal manner for the
2440 dynamic linker, before writing them out. */
2442 static enum elf_reloc_type_class
2443 elf64_hppa_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2444 const asection
*rel_sec ATTRIBUTE_UNUSED
,
2445 const Elf_Internal_Rela
*rela
)
2447 if (ELF64_R_SYM (rela
->r_info
) == STN_UNDEF
)
2448 return reloc_class_relative
;
2450 switch ((int) ELF64_R_TYPE (rela
->r_info
))
2453 return reloc_class_plt
;
2455 return reloc_class_copy
;
2457 return reloc_class_normal
;
2461 /* Finish up the dynamic sections. */
2464 elf64_hppa_finish_dynamic_sections (bfd
*output_bfd
,
2465 struct bfd_link_info
*info
)
2469 struct elf64_hppa_link_hash_table
*hppa_info
;
2471 hppa_info
= hppa_link_hash_table (info
);
2472 if (hppa_info
== NULL
)
2475 /* Finalize the contents of the .opd section. */
2476 elf_link_hash_traverse (elf_hash_table (info
),
2477 elf64_hppa_finalize_opd
,
2480 elf_link_hash_traverse (elf_hash_table (info
),
2481 elf64_hppa_finalize_dynreloc
,
2484 /* Finalize the contents of the .dlt section. */
2485 dynobj
= elf_hash_table (info
)->dynobj
;
2486 /* Finalize the contents of the .dlt section. */
2487 elf_link_hash_traverse (elf_hash_table (info
),
2488 elf64_hppa_finalize_dlt
,
2491 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
2493 if (elf_hash_table (info
)->dynamic_sections_created
)
2495 Elf64_External_Dyn
*dyncon
, *dynconend
;
2497 BFD_ASSERT (sdyn
!= NULL
);
2499 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
2500 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
2501 for (; dyncon
< dynconend
; dyncon
++)
2503 Elf_Internal_Dyn dyn
;
2506 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2513 case DT_HP_LOAD_MAP
:
2514 /* Compute the absolute address of 16byte scratchpad area
2515 for the dynamic linker.
2517 By convention the linker script will allocate the scratchpad
2518 area at the start of the .data section. So all we have to
2519 to is find the start of the .data section. */
2520 s
= bfd_get_section_by_name (output_bfd
, ".data");
2523 dyn
.d_un
.d_ptr
= s
->vma
;
2524 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2528 /* HP's use PLTGOT to set the GOT register. */
2529 dyn
.d_un
.d_ptr
= _bfd_get_gp_value (output_bfd
);
2530 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2534 s
= hppa_info
->plt_rel_sec
;
2535 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
2536 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2540 s
= hppa_info
->plt_rel_sec
;
2541 dyn
.d_un
.d_val
= s
->size
;
2542 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2546 s
= hppa_info
->other_rel_sec
;
2547 if (! s
|| ! s
->size
)
2548 s
= hppa_info
->dlt_rel_sec
;
2549 if (! s
|| ! s
->size
)
2550 s
= hppa_info
->opd_rel_sec
;
2551 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
2552 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2556 s
= hppa_info
->other_rel_sec
;
2557 dyn
.d_un
.d_val
= s
->size
;
2558 s
= hppa_info
->dlt_rel_sec
;
2559 dyn
.d_un
.d_val
+= s
->size
;
2560 s
= hppa_info
->opd_rel_sec
;
2561 dyn
.d_un
.d_val
+= s
->size
;
2562 /* There is some question about whether or not the size of
2563 the PLT relocs should be included here. HP's tools do
2564 it, so we'll emulate them. */
2565 s
= hppa_info
->plt_rel_sec
;
2566 dyn
.d_un
.d_val
+= s
->size
;
2567 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2577 /* Support for core dump NOTE sections. */
2580 elf64_hppa_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
2585 switch (note
->descsz
)
2590 case 760: /* Linux/hppa */
2592 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
2595 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
2604 /* Make a ".reg/999" section. */
2605 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
2606 size
, note
->descpos
+ offset
);
2610 elf64_hppa_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
2615 switch (note
->descsz
)
2620 case 136: /* Linux/hppa elf_prpsinfo. */
2621 elf_tdata (abfd
)->core
->program
2622 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
2623 elf_tdata (abfd
)->core
->command
2624 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
2627 /* Note that for some reason, a spurious space is tacked
2628 onto the end of the args in some (at least one anyway)
2629 implementations, so strip it off if it exists. */
2630 command
= elf_tdata (abfd
)->core
->command
;
2631 n
= strlen (command
);
2633 if (0 < n
&& command
[n
- 1] == ' ')
2634 command
[n
- 1] = '\0';
2639 /* Return the number of additional phdrs we will need.
2641 The generic ELF code only creates PT_PHDRs for executables. The HP
2642 dynamic linker requires PT_PHDRs for dynamic libraries too.
2644 This routine indicates that the backend needs one additional program
2645 header for that case.
2647 Note we do not have access to the link info structure here, so we have
2648 to guess whether or not we are building a shared library based on the
2649 existence of a .interp section. */
2652 elf64_hppa_additional_program_headers (bfd
*abfd
,
2653 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2657 /* If we are creating a shared library, then we have to create a
2658 PT_PHDR segment. HP's dynamic linker chokes without it. */
2659 s
= bfd_get_section_by_name (abfd
, ".interp");
2666 elf64_hppa_allow_non_load_phdr (bfd
*abfd ATTRIBUTE_UNUSED
,
2667 const Elf_Internal_Phdr
*phdr ATTRIBUTE_UNUSED
,
2668 unsigned int count ATTRIBUTE_UNUSED
)
2673 /* Allocate and initialize any program headers required by this
2676 The generic ELF code only creates PT_PHDRs for executables. The HP
2677 dynamic linker requires PT_PHDRs for dynamic libraries too.
2679 This allocates the PT_PHDR and initializes it in a manner suitable
2682 Note we do not have access to the link info structure here, so we have
2683 to guess whether or not we are building a shared library based on the
2684 existence of a .interp section. */
2687 elf64_hppa_modify_segment_map (bfd
*abfd
, struct bfd_link_info
*info
)
2689 struct elf_segment_map
*m
;
2691 m
= elf_seg_map (abfd
);
2692 if (info
!= NULL
&& !info
->user_phdrs
&& m
!= NULL
&& m
->p_type
!= PT_PHDR
)
2694 m
= ((struct elf_segment_map
*)
2695 bfd_zalloc (abfd
, (bfd_size_type
) sizeof *m
));
2699 m
->p_type
= PT_PHDR
;
2700 m
->p_flags
= PF_R
| PF_X
;
2701 m
->p_flags_valid
= 1;
2702 m
->p_paddr_valid
= 1;
2703 m
->includes_phdrs
= 1;
2705 m
->next
= elf_seg_map (abfd
);
2706 elf_seg_map (abfd
) = m
;
2709 for (m
= elf_seg_map (abfd
) ; m
!= NULL
; m
= m
->next
)
2710 if (m
->p_type
== PT_LOAD
)
2714 for (i
= 0; i
< m
->count
; i
++)
2716 /* The code "hint" is not really a hint. It is a requirement
2717 for certain versions of the HP dynamic linker. Worse yet,
2718 it must be set even if the shared library does not have
2719 any code in its "text" segment (thus the check for .hash
2720 to catch this situation). */
2721 if (m
->sections
[i
]->flags
& SEC_CODE
2722 || (strcmp (m
->sections
[i
]->name
, ".hash") == 0))
2723 m
->p_flags
|= (PF_X
| PF_HP_CODE
);
2730 /* Called when writing out an object file to decide the type of a
2733 elf64_hppa_elf_get_symbol_type (Elf_Internal_Sym
*elf_sym
,
2736 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_PARISC_MILLI
)
2737 return STT_PARISC_MILLI
;
2742 /* Support HP specific sections for core files. */
2745 elf64_hppa_section_from_phdr (bfd
*abfd
, Elf_Internal_Phdr
*hdr
, int sec_index
,
2746 const char *typename
)
2748 if (hdr
->p_type
== PT_HP_CORE_KERNEL
)
2752 if (!_bfd_elf_make_section_from_phdr (abfd
, hdr
, sec_index
, typename
))
2755 sect
= bfd_make_section_anyway (abfd
, ".kernel");
2758 sect
->size
= hdr
->p_filesz
;
2759 sect
->filepos
= hdr
->p_offset
;
2760 sect
->flags
= SEC_HAS_CONTENTS
| SEC_READONLY
;
2764 if (hdr
->p_type
== PT_HP_CORE_PROC
)
2768 if (bfd_seek (abfd
, hdr
->p_offset
, SEEK_SET
) != 0)
2770 if (bfd_bread (&sig
, 4, abfd
) != 4)
2773 elf_tdata (abfd
)->core
->signal
= sig
;
2775 if (!_bfd_elf_make_section_from_phdr (abfd
, hdr
, sec_index
, typename
))
2778 /* GDB uses the ".reg" section to read register contents. */
2779 return _bfd_elfcore_make_pseudosection (abfd
, ".reg", hdr
->p_filesz
,
2783 if (hdr
->p_type
== PT_HP_CORE_LOADABLE
2784 || hdr
->p_type
== PT_HP_CORE_STACK
2785 || hdr
->p_type
== PT_HP_CORE_MMF
)
2786 hdr
->p_type
= PT_LOAD
;
2788 return _bfd_elf_make_section_from_phdr (abfd
, hdr
, sec_index
, typename
);
2791 /* Hook called by the linker routine which adds symbols from an object
2792 file. HP's libraries define symbols with HP specific section
2793 indices, which we have to handle. */
2796 elf_hppa_add_symbol_hook (bfd
*abfd
,
2797 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2798 Elf_Internal_Sym
*sym
,
2799 const char **namep ATTRIBUTE_UNUSED
,
2800 flagword
*flagsp ATTRIBUTE_UNUSED
,
2804 unsigned int sec_index
= sym
->st_shndx
;
2808 case SHN_PARISC_ANSI_COMMON
:
2809 *secp
= bfd_make_section_old_way (abfd
, ".PARISC.ansi.common");
2810 (*secp
)->flags
|= SEC_IS_COMMON
;
2811 *valp
= sym
->st_size
;
2814 case SHN_PARISC_HUGE_COMMON
:
2815 *secp
= bfd_make_section_old_way (abfd
, ".PARISC.huge.common");
2816 (*secp
)->flags
|= SEC_IS_COMMON
;
2817 *valp
= sym
->st_size
;
2825 elf_hppa_unmark_useless_dynamic_symbols (struct elf_link_hash_entry
*h
,
2828 struct bfd_link_info
*info
= data
;
2830 /* If we are not creating a shared library, and this symbol is
2831 referenced by a shared library but is not defined anywhere, then
2832 the generic code will warn that it is undefined.
2834 This behavior is undesirable on HPs since the standard shared
2835 libraries contain references to undefined symbols.
2837 So we twiddle the flags associated with such symbols so that they
2838 will not trigger the warning. ?!? FIXME. This is horribly fragile.
2840 Ultimately we should have better controls over the generic ELF BFD
2842 if (! bfd_link_relocatable (info
)
2843 && info
->unresolved_syms_in_shared_libs
!= RM_IGNORE
2844 && h
->root
.type
== bfd_link_hash_undefined
2849 h
->pointer_equality_needed
= 1;
2856 elf_hppa_remark_useless_dynamic_symbols (struct elf_link_hash_entry
*h
,
2859 struct bfd_link_info
*info
= data
;
2861 /* If we are not creating a shared library, and this symbol is
2862 referenced by a shared library but is not defined anywhere, then
2863 the generic code will warn that it is undefined.
2865 This behavior is undesirable on HPs since the standard shared
2866 libraries contain references to undefined symbols.
2868 So we twiddle the flags associated with such symbols so that they
2869 will not trigger the warning. ?!? FIXME. This is horribly fragile.
2871 Ultimately we should have better controls over the generic ELF BFD
2873 if (! bfd_link_relocatable (info
)
2874 && info
->unresolved_syms_in_shared_libs
!= RM_IGNORE
2875 && h
->root
.type
== bfd_link_hash_undefined
2878 && h
->pointer_equality_needed
)
2881 h
->pointer_equality_needed
= 0;
2888 elf_hppa_is_dynamic_loader_symbol (const char *name
)
2890 return (! strcmp (name
, "__CPU_REVISION")
2891 || ! strcmp (name
, "__CPU_KEYBITS_1")
2892 || ! strcmp (name
, "__SYSTEM_ID_D")
2893 || ! strcmp (name
, "__FPU_MODEL")
2894 || ! strcmp (name
, "__FPU_REVISION")
2895 || ! strcmp (name
, "__ARGC")
2896 || ! strcmp (name
, "__ARGV")
2897 || ! strcmp (name
, "__ENVP")
2898 || ! strcmp (name
, "__TLS_SIZE_D")
2899 || ! strcmp (name
, "__LOAD_INFO")
2900 || ! strcmp (name
, "__systab"));
2903 /* Record the lowest address for the data and text segments. */
2905 elf_hppa_record_segment_addrs (bfd
*abfd
,
2909 struct elf64_hppa_link_hash_table
*hppa_info
= data
;
2911 if ((section
->flags
& (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
2914 Elf_Internal_Phdr
*p
;
2916 p
= _bfd_elf_find_segment_containing_section (abfd
, section
->output_section
);
2917 BFD_ASSERT (p
!= NULL
);
2920 if (section
->flags
& SEC_READONLY
)
2922 if (value
< hppa_info
->text_segment_base
)
2923 hppa_info
->text_segment_base
= value
;
2927 if (value
< hppa_info
->data_segment_base
)
2928 hppa_info
->data_segment_base
= value
;
2933 /* Called after we have seen all the input files/sections, but before
2934 final symbol resolution and section placement has been determined.
2936 We use this hook to (possibly) provide a value for __gp, then we
2937 fall back to the generic ELF final link routine. */
2940 elf_hppa_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
2943 struct elf64_hppa_link_hash_table
*hppa_info
= hppa_link_hash_table (info
);
2945 if (hppa_info
== NULL
)
2948 if (! bfd_link_relocatable (info
))
2950 struct elf_link_hash_entry
*gp
;
2953 /* The linker script defines a value for __gp iff it was referenced
2954 by one of the objects being linked. First try to find the symbol
2955 in the hash table. If that fails, just compute the value __gp
2957 gp
= elf_link_hash_lookup (elf_hash_table (info
), "__gp", FALSE
,
2963 /* Adjust the value of __gp as we may want to slide it into the
2964 .plt section so that the stubs can access PLT entries without
2965 using an addil sequence. */
2966 gp
->root
.u
.def
.value
+= hppa_info
->gp_offset
;
2968 gp_val
= (gp
->root
.u
.def
.section
->output_section
->vma
2969 + gp
->root
.u
.def
.section
->output_offset
2970 + gp
->root
.u
.def
.value
);
2976 /* First look for a .plt section. If found, then __gp is the
2977 address of the .plt + gp_offset.
2979 If no .plt is found, then look for .dlt, .opd and .data (in
2980 that order) and set __gp to the base address of whichever
2981 section is found first. */
2983 sec
= hppa_info
->plt_sec
;
2984 if (sec
&& ! (sec
->flags
& SEC_EXCLUDE
))
2985 gp_val
= (sec
->output_offset
2986 + sec
->output_section
->vma
2987 + hppa_info
->gp_offset
);
2990 sec
= hppa_info
->dlt_sec
;
2991 if (!sec
|| (sec
->flags
& SEC_EXCLUDE
))
2992 sec
= hppa_info
->opd_sec
;
2993 if (!sec
|| (sec
->flags
& SEC_EXCLUDE
))
2994 sec
= bfd_get_section_by_name (abfd
, ".data");
2995 if (!sec
|| (sec
->flags
& SEC_EXCLUDE
))
2998 gp_val
= sec
->output_offset
+ sec
->output_section
->vma
;
3002 /* Install whatever value we found/computed for __gp. */
3003 _bfd_set_gp_value (abfd
, gp_val
);
3006 /* We need to know the base of the text and data segments so that we
3007 can perform SEGREL relocations. We will record the base addresses
3008 when we encounter the first SEGREL relocation. */
3009 hppa_info
->text_segment_base
= (bfd_vma
)-1;
3010 hppa_info
->data_segment_base
= (bfd_vma
)-1;
3012 /* HP's shared libraries have references to symbols that are not
3013 defined anywhere. The generic ELF BFD linker code will complain
3016 So we detect the losing case and arrange for the flags on the symbol
3017 to indicate that it was never referenced. This keeps the generic
3018 ELF BFD link code happy and appears to not create any secondary
3019 problems. Ultimately we need a way to control the behavior of the
3020 generic ELF BFD link code better. */
3021 elf_link_hash_traverse (elf_hash_table (info
),
3022 elf_hppa_unmark_useless_dynamic_symbols
,
3025 /* Invoke the regular ELF backend linker to do all the work. */
3026 if (!bfd_elf_final_link (abfd
, info
))
3029 elf_link_hash_traverse (elf_hash_table (info
),
3030 elf_hppa_remark_useless_dynamic_symbols
,
3033 /* If we're producing a final executable, sort the contents of the
3035 if (bfd_link_relocatable (info
))
3038 /* Do not attempt to sort non-regular files. This is here
3039 especially for configure scripts and kernel builds which run
3040 tests with "ld [...] -o /dev/null". */
3041 if (stat (abfd
->filename
, &buf
) != 0
3042 || !S_ISREG(buf
.st_mode
))
3045 return elf_hppa_sort_unwind (abfd
);
3048 /* Relocate the given INSN. VALUE should be the actual value we want
3049 to insert into the instruction, ie by this point we should not be
3050 concerned with computing an offset relative to the DLT, PC, etc.
3051 Instead this routine is meant to handle the bit manipulations needed
3052 to insert the relocation into the given instruction. */
3055 elf_hppa_relocate_insn (int insn
, int sym_value
, unsigned int r_type
)
3059 /* This is any 22 bit branch. In PA2.0 syntax it corresponds to
3060 the "B" instruction. */
3061 case R_PARISC_PCREL22F
:
3062 case R_PARISC_PCREL22C
:
3063 return (insn
& ~0x3ff1ffd) | re_assemble_22 (sym_value
);
3065 /* This is any 12 bit branch. */
3066 case R_PARISC_PCREL12F
:
3067 return (insn
& ~0x1ffd) | re_assemble_12 (sym_value
);
3069 /* This is any 17 bit branch. In PA2.0 syntax it also corresponds
3070 to the "B" instruction as well as BE. */
3071 case R_PARISC_PCREL17F
:
3072 case R_PARISC_DIR17F
:
3073 case R_PARISC_DIR17R
:
3074 case R_PARISC_PCREL17C
:
3075 case R_PARISC_PCREL17R
:
3076 return (insn
& ~0x1f1ffd) | re_assemble_17 (sym_value
);
3078 /* ADDIL or LDIL instructions. */
3079 case R_PARISC_DLTREL21L
:
3080 case R_PARISC_DLTIND21L
:
3081 case R_PARISC_LTOFF_FPTR21L
:
3082 case R_PARISC_PCREL21L
:
3083 case R_PARISC_LTOFF_TP21L
:
3084 case R_PARISC_DPREL21L
:
3085 case R_PARISC_PLTOFF21L
:
3086 case R_PARISC_DIR21L
:
3087 return (insn
& ~0x1fffff) | re_assemble_21 (sym_value
);
3089 /* LDO and integer loads/stores with 14 bit displacements. */
3090 case R_PARISC_DLTREL14R
:
3091 case R_PARISC_DLTREL14F
:
3092 case R_PARISC_DLTIND14R
:
3093 case R_PARISC_DLTIND14F
:
3094 case R_PARISC_LTOFF_FPTR14R
:
3095 case R_PARISC_PCREL14R
:
3096 case R_PARISC_PCREL14F
:
3097 case R_PARISC_LTOFF_TP14R
:
3098 case R_PARISC_LTOFF_TP14F
:
3099 case R_PARISC_DPREL14R
:
3100 case R_PARISC_DPREL14F
:
3101 case R_PARISC_PLTOFF14R
:
3102 case R_PARISC_PLTOFF14F
:
3103 case R_PARISC_DIR14R
:
3104 case R_PARISC_DIR14F
:
3105 return (insn
& ~0x3fff) | low_sign_unext (sym_value
, 14);
3107 /* PA2.0W LDO and integer loads/stores with 16 bit displacements. */
3108 case R_PARISC_LTOFF_FPTR16F
:
3109 case R_PARISC_PCREL16F
:
3110 case R_PARISC_LTOFF_TP16F
:
3111 case R_PARISC_GPREL16F
:
3112 case R_PARISC_PLTOFF16F
:
3113 case R_PARISC_DIR16F
:
3114 case R_PARISC_LTOFF16F
:
3115 return (insn
& ~0xffff) | re_assemble_16 (sym_value
);
3117 /* Doubleword loads and stores with a 14 bit displacement. */
3118 case R_PARISC_DLTREL14DR
:
3119 case R_PARISC_DLTIND14DR
:
3120 case R_PARISC_LTOFF_FPTR14DR
:
3121 case R_PARISC_LTOFF_FPTR16DF
:
3122 case R_PARISC_PCREL14DR
:
3123 case R_PARISC_PCREL16DF
:
3124 case R_PARISC_LTOFF_TP14DR
:
3125 case R_PARISC_LTOFF_TP16DF
:
3126 case R_PARISC_DPREL14DR
:
3127 case R_PARISC_GPREL16DF
:
3128 case R_PARISC_PLTOFF14DR
:
3129 case R_PARISC_PLTOFF16DF
:
3130 case R_PARISC_DIR14DR
:
3131 case R_PARISC_DIR16DF
:
3132 case R_PARISC_LTOFF16DF
:
3133 return (insn
& ~0x3ff1) | (((sym_value
& 0x2000) >> 13)
3134 | ((sym_value
& 0x1ff8) << 1));
3136 /* Floating point single word load/store instructions. */
3137 case R_PARISC_DLTREL14WR
:
3138 case R_PARISC_DLTIND14WR
:
3139 case R_PARISC_LTOFF_FPTR14WR
:
3140 case R_PARISC_LTOFF_FPTR16WF
:
3141 case R_PARISC_PCREL14WR
:
3142 case R_PARISC_PCREL16WF
:
3143 case R_PARISC_LTOFF_TP14WR
:
3144 case R_PARISC_LTOFF_TP16WF
:
3145 case R_PARISC_DPREL14WR
:
3146 case R_PARISC_GPREL16WF
:
3147 case R_PARISC_PLTOFF14WR
:
3148 case R_PARISC_PLTOFF16WF
:
3149 case R_PARISC_DIR16WF
:
3150 case R_PARISC_DIR14WR
:
3151 case R_PARISC_LTOFF16WF
:
3152 return (insn
& ~0x3ff9) | (((sym_value
& 0x2000) >> 13)
3153 | ((sym_value
& 0x1ffc) << 1));
3160 /* Compute the value for a relocation (REL) during a final link stage,
3161 then insert the value into the proper location in CONTENTS.
3163 VALUE is a tentative value for the relocation and may be overridden
3164 and modified here based on the specific relocation to be performed.
3166 For example we do conversions for PC-relative branches in this routine
3167 or redirection of calls to external routines to stubs.
3169 The work of actually applying the relocation is left to a helper
3170 routine in an attempt to reduce the complexity and size of this
3173 static bfd_reloc_status_type
3174 elf_hppa_final_link_relocate (Elf_Internal_Rela
*rel
,
3177 asection
*input_section
,
3180 struct bfd_link_info
*info
,
3182 struct elf_link_hash_entry
*eh
)
3184 struct elf64_hppa_link_hash_table
*hppa_info
= hppa_link_hash_table (info
);
3185 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
3186 bfd_vma
*local_offsets
;
3187 Elf_Internal_Shdr
*symtab_hdr
;
3189 bfd_vma max_branch_offset
= 0;
3190 bfd_vma offset
= rel
->r_offset
;
3191 bfd_signed_vma addend
= rel
->r_addend
;
3192 reloc_howto_type
*howto
= elf_hppa_howto_table
+ ELF_R_TYPE (rel
->r_info
);
3193 unsigned int r_symndx
= ELF_R_SYM (rel
->r_info
);
3194 unsigned int r_type
= howto
->type
;
3195 bfd_byte
*hit_data
= contents
+ offset
;
3197 if (hppa_info
== NULL
)
3198 return bfd_reloc_notsupported
;
3200 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3201 local_offsets
= elf_local_got_offsets (input_bfd
);
3202 insn
= bfd_get_32 (input_bfd
, hit_data
);
3209 /* Basic function call support.
3211 Note for a call to a function defined in another dynamic library
3212 we want to redirect the call to a stub. */
3214 /* PC relative relocs without an implicit offset. */
3215 case R_PARISC_PCREL21L
:
3216 case R_PARISC_PCREL14R
:
3217 case R_PARISC_PCREL14F
:
3218 case R_PARISC_PCREL14WR
:
3219 case R_PARISC_PCREL14DR
:
3220 case R_PARISC_PCREL16F
:
3221 case R_PARISC_PCREL16WF
:
3222 case R_PARISC_PCREL16DF
:
3224 /* If this is a call to a function defined in another dynamic
3225 library, then redirect the call to the local stub for this
3227 if (sym_sec
== NULL
|| sym_sec
->output_section
== NULL
)
3228 value
= (hh
->stub_offset
+ hppa_info
->stub_sec
->output_offset
3229 + hppa_info
->stub_sec
->output_section
->vma
);
3231 /* Turn VALUE into a proper PC relative address. */
3232 value
-= (offset
+ input_section
->output_offset
3233 + input_section
->output_section
->vma
);
3235 /* Adjust for any field selectors. */
3236 if (r_type
== R_PARISC_PCREL21L
)
3237 value
= hppa_field_adjust (value
, -8 + addend
, e_lsel
);
3238 else if (r_type
== R_PARISC_PCREL14F
3239 || r_type
== R_PARISC_PCREL16F
3240 || r_type
== R_PARISC_PCREL16WF
3241 || r_type
== R_PARISC_PCREL16DF
)
3242 value
= hppa_field_adjust (value
, -8 + addend
, e_fsel
);
3244 value
= hppa_field_adjust (value
, -8 + addend
, e_rsel
);
3246 /* Apply the relocation to the given instruction. */
3247 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3251 case R_PARISC_PCREL12F
:
3252 case R_PARISC_PCREL22F
:
3253 case R_PARISC_PCREL17F
:
3254 case R_PARISC_PCREL22C
:
3255 case R_PARISC_PCREL17C
:
3256 case R_PARISC_PCREL17R
:
3258 /* If this is a call to a function defined in another dynamic
3259 library, then redirect the call to the local stub for this
3261 if (sym_sec
== NULL
|| sym_sec
->output_section
== NULL
)
3262 value
= (hh
->stub_offset
+ hppa_info
->stub_sec
->output_offset
3263 + hppa_info
->stub_sec
->output_section
->vma
);
3265 /* Turn VALUE into a proper PC relative address. */
3266 value
-= (offset
+ input_section
->output_offset
3267 + input_section
->output_section
->vma
);
3270 if (r_type
== (unsigned int) R_PARISC_PCREL22F
)
3271 max_branch_offset
= (1 << (22-1)) << 2;
3272 else if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
3273 max_branch_offset
= (1 << (17-1)) << 2;
3274 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
3275 max_branch_offset
= (1 << (12-1)) << 2;
3277 /* Make sure we can reach the branch target. */
3278 if (max_branch_offset
!= 0
3279 && value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3282 /* xgettext:c-format */
3283 (_("%pB(%pA+%#" PRIx64
"): cannot reach %s"),
3287 eh
? eh
->root
.root
.string
: "unknown");
3288 bfd_set_error (bfd_error_bad_value
);
3289 return bfd_reloc_overflow
;
3292 /* Adjust for any field selectors. */
3293 if (r_type
== R_PARISC_PCREL17R
)
3294 value
= hppa_field_adjust (value
, addend
, e_rsel
);
3296 value
= hppa_field_adjust (value
, addend
, e_fsel
);
3298 /* All branches are implicitly shifted by 2 places. */
3301 /* Apply the relocation to the given instruction. */
3302 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3306 /* Indirect references to data through the DLT. */
3307 case R_PARISC_DLTIND14R
:
3308 case R_PARISC_DLTIND14F
:
3309 case R_PARISC_DLTIND14DR
:
3310 case R_PARISC_DLTIND14WR
:
3311 case R_PARISC_DLTIND21L
:
3312 case R_PARISC_LTOFF_FPTR14R
:
3313 case R_PARISC_LTOFF_FPTR14DR
:
3314 case R_PARISC_LTOFF_FPTR14WR
:
3315 case R_PARISC_LTOFF_FPTR21L
:
3316 case R_PARISC_LTOFF_FPTR16F
:
3317 case R_PARISC_LTOFF_FPTR16WF
:
3318 case R_PARISC_LTOFF_FPTR16DF
:
3319 case R_PARISC_LTOFF_TP21L
:
3320 case R_PARISC_LTOFF_TP14R
:
3321 case R_PARISC_LTOFF_TP14F
:
3322 case R_PARISC_LTOFF_TP14WR
:
3323 case R_PARISC_LTOFF_TP14DR
:
3324 case R_PARISC_LTOFF_TP16F
:
3325 case R_PARISC_LTOFF_TP16WF
:
3326 case R_PARISC_LTOFF_TP16DF
:
3327 case R_PARISC_LTOFF16F
:
3328 case R_PARISC_LTOFF16WF
:
3329 case R_PARISC_LTOFF16DF
:
3333 /* If this relocation was against a local symbol, then we still
3334 have not set up the DLT entry (it's not convenient to do so
3335 in the "finalize_dlt" routine because it is difficult to get
3336 to the local symbol's value).
3338 So, if this is a local symbol (h == NULL), then we need to
3339 fill in its DLT entry.
3341 Similarly we may still need to set up an entry in .opd for
3342 a local function which had its address taken. */
3345 bfd_vma
*local_opd_offsets
, *local_dlt_offsets
;
3347 if (local_offsets
== NULL
)
3350 /* Now do .opd creation if needed. */
3351 if (r_type
== R_PARISC_LTOFF_FPTR14R
3352 || r_type
== R_PARISC_LTOFF_FPTR14DR
3353 || r_type
== R_PARISC_LTOFF_FPTR14WR
3354 || r_type
== R_PARISC_LTOFF_FPTR21L
3355 || r_type
== R_PARISC_LTOFF_FPTR16F
3356 || r_type
== R_PARISC_LTOFF_FPTR16WF
3357 || r_type
== R_PARISC_LTOFF_FPTR16DF
)
3359 local_opd_offsets
= local_offsets
+ 2 * symtab_hdr
->sh_info
;
3360 off
= local_opd_offsets
[r_symndx
];
3362 /* The last bit records whether we've already initialised
3363 this local .opd entry. */
3366 BFD_ASSERT (off
!= (bfd_vma
) -1);
3371 local_opd_offsets
[r_symndx
] |= 1;
3373 /* The first two words of an .opd entry are zero. */
3374 memset (hppa_info
->opd_sec
->contents
+ off
, 0, 16);
3376 /* The next word is the address of the function. */
3377 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
+ addend
,
3378 (hppa_info
->opd_sec
->contents
+ off
+ 16));
3380 /* The last word is our local __gp value. */
3381 value
= _bfd_get_gp_value (info
->output_bfd
);
3382 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
,
3383 (hppa_info
->opd_sec
->contents
+ off
+ 24));
3386 /* The DLT value is the address of the .opd entry. */
3388 + hppa_info
->opd_sec
->output_offset
3389 + hppa_info
->opd_sec
->output_section
->vma
);
3393 local_dlt_offsets
= local_offsets
;
3394 off
= local_dlt_offsets
[r_symndx
];
3398 BFD_ASSERT (off
!= (bfd_vma
) -1);
3403 local_dlt_offsets
[r_symndx
] |= 1;
3404 bfd_put_64 (hppa_info
->dlt_sec
->owner
,
3406 hppa_info
->dlt_sec
->contents
+ off
);
3410 off
= hh
->dlt_offset
;
3412 /* We want the value of the DLT offset for this symbol, not
3413 the symbol's actual address. Note that __gp may not point
3414 to the start of the DLT, so we have to compute the absolute
3415 address, then subtract out the value of __gp. */
3417 + hppa_info
->dlt_sec
->output_offset
3418 + hppa_info
->dlt_sec
->output_section
->vma
);
3419 value
-= _bfd_get_gp_value (output_bfd
);
3421 /* All DLTIND relocations are basically the same at this point,
3422 except that we need different field selectors for the 21bit
3423 version vs the 14bit versions. */
3424 if (r_type
== R_PARISC_DLTIND21L
3425 || r_type
== R_PARISC_LTOFF_FPTR21L
3426 || r_type
== R_PARISC_LTOFF_TP21L
)
3427 value
= hppa_field_adjust (value
, 0, e_lsel
);
3428 else if (r_type
== R_PARISC_DLTIND14F
3429 || r_type
== R_PARISC_LTOFF_FPTR16F
3430 || r_type
== R_PARISC_LTOFF_FPTR16WF
3431 || r_type
== R_PARISC_LTOFF_FPTR16DF
3432 || r_type
== R_PARISC_LTOFF16F
3433 || r_type
== R_PARISC_LTOFF16DF
3434 || r_type
== R_PARISC_LTOFF16WF
3435 || r_type
== R_PARISC_LTOFF_TP16F
3436 || r_type
== R_PARISC_LTOFF_TP16WF
3437 || r_type
== R_PARISC_LTOFF_TP16DF
)
3438 value
= hppa_field_adjust (value
, 0, e_fsel
);
3440 value
= hppa_field_adjust (value
, 0, e_rsel
);
3442 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3446 case R_PARISC_DLTREL14R
:
3447 case R_PARISC_DLTREL14F
:
3448 case R_PARISC_DLTREL14DR
:
3449 case R_PARISC_DLTREL14WR
:
3450 case R_PARISC_DLTREL21L
:
3451 case R_PARISC_DPREL21L
:
3452 case R_PARISC_DPREL14WR
:
3453 case R_PARISC_DPREL14DR
:
3454 case R_PARISC_DPREL14R
:
3455 case R_PARISC_DPREL14F
:
3456 case R_PARISC_GPREL16F
:
3457 case R_PARISC_GPREL16WF
:
3458 case R_PARISC_GPREL16DF
:
3460 /* Subtract out the global pointer value to make value a DLT
3461 relative address. */
3462 value
-= _bfd_get_gp_value (output_bfd
);
3464 /* All DLTREL relocations are basically the same at this point,
3465 except that we need different field selectors for the 21bit
3466 version vs the 14bit versions. */
3467 if (r_type
== R_PARISC_DLTREL21L
3468 || r_type
== R_PARISC_DPREL21L
)
3469 value
= hppa_field_adjust (value
, addend
, e_lrsel
);
3470 else if (r_type
== R_PARISC_DLTREL14F
3471 || r_type
== R_PARISC_DPREL14F
3472 || r_type
== R_PARISC_GPREL16F
3473 || r_type
== R_PARISC_GPREL16WF
3474 || r_type
== R_PARISC_GPREL16DF
)
3475 value
= hppa_field_adjust (value
, addend
, e_fsel
);
3477 value
= hppa_field_adjust (value
, addend
, e_rrsel
);
3479 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3483 case R_PARISC_DIR21L
:
3484 case R_PARISC_DIR17R
:
3485 case R_PARISC_DIR17F
:
3486 case R_PARISC_DIR14R
:
3487 case R_PARISC_DIR14F
:
3488 case R_PARISC_DIR14WR
:
3489 case R_PARISC_DIR14DR
:
3490 case R_PARISC_DIR16F
:
3491 case R_PARISC_DIR16WF
:
3492 case R_PARISC_DIR16DF
:
3494 /* All DIR relocations are basically the same at this point,
3495 except that branch offsets need to be divided by four, and
3496 we need different field selectors. Note that we don't
3497 redirect absolute calls to local stubs. */
3499 if (r_type
== R_PARISC_DIR21L
)
3500 value
= hppa_field_adjust (value
, addend
, e_lrsel
);
3501 else if (r_type
== R_PARISC_DIR17F
3502 || r_type
== R_PARISC_DIR16F
3503 || r_type
== R_PARISC_DIR16WF
3504 || r_type
== R_PARISC_DIR16DF
3505 || r_type
== R_PARISC_DIR14F
)
3506 value
= hppa_field_adjust (value
, addend
, e_fsel
);
3508 value
= hppa_field_adjust (value
, addend
, e_rrsel
);
3510 if (r_type
== R_PARISC_DIR17R
|| r_type
== R_PARISC_DIR17F
)
3511 /* All branches are implicitly shifted by 2 places. */
3514 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3518 case R_PARISC_PLTOFF21L
:
3519 case R_PARISC_PLTOFF14R
:
3520 case R_PARISC_PLTOFF14F
:
3521 case R_PARISC_PLTOFF14WR
:
3522 case R_PARISC_PLTOFF14DR
:
3523 case R_PARISC_PLTOFF16F
:
3524 case R_PARISC_PLTOFF16WF
:
3525 case R_PARISC_PLTOFF16DF
:
3527 /* We want the value of the PLT offset for this symbol, not
3528 the symbol's actual address. Note that __gp may not point
3529 to the start of the DLT, so we have to compute the absolute
3530 address, then subtract out the value of __gp. */
3531 value
= (hh
->plt_offset
3532 + hppa_info
->plt_sec
->output_offset
3533 + hppa_info
->plt_sec
->output_section
->vma
);
3534 value
-= _bfd_get_gp_value (output_bfd
);
3536 /* All PLTOFF relocations are basically the same at this point,
3537 except that we need different field selectors for the 21bit
3538 version vs the 14bit versions. */
3539 if (r_type
== R_PARISC_PLTOFF21L
)
3540 value
= hppa_field_adjust (value
, addend
, e_lrsel
);
3541 else if (r_type
== R_PARISC_PLTOFF14F
3542 || r_type
== R_PARISC_PLTOFF16F
3543 || r_type
== R_PARISC_PLTOFF16WF
3544 || r_type
== R_PARISC_PLTOFF16DF
)
3545 value
= hppa_field_adjust (value
, addend
, e_fsel
);
3547 value
= hppa_field_adjust (value
, addend
, e_rrsel
);
3549 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3553 case R_PARISC_LTOFF_FPTR32
:
3555 /* FIXME: There used to be code here to create the FPTR itself if
3556 the relocation was against a local symbol. But the code could
3557 never have worked. If the assert below is ever triggered then
3558 the code will need to be reinstated and fixed so that it does
3560 BFD_ASSERT (hh
!= NULL
);
3562 /* We want the value of the DLT offset for this symbol, not
3563 the symbol's actual address. Note that __gp may not point
3564 to the start of the DLT, so we have to compute the absolute
3565 address, then subtract out the value of __gp. */
3566 value
= (hh
->dlt_offset
3567 + hppa_info
->dlt_sec
->output_offset
3568 + hppa_info
->dlt_sec
->output_section
->vma
);
3569 value
-= _bfd_get_gp_value (output_bfd
);
3570 bfd_put_32 (input_bfd
, value
, hit_data
);
3571 return bfd_reloc_ok
;
3574 case R_PARISC_LTOFF_FPTR64
:
3575 case R_PARISC_LTOFF_TP64
:
3577 /* We may still need to create the FPTR itself if it was for
3579 if (eh
== NULL
&& r_type
== R_PARISC_LTOFF_FPTR64
)
3581 /* The first two words of an .opd entry are zero. */
3582 memset (hppa_info
->opd_sec
->contents
+ hh
->opd_offset
, 0, 16);
3584 /* The next word is the address of the function. */
3585 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
+ addend
,
3586 (hppa_info
->opd_sec
->contents
3587 + hh
->opd_offset
+ 16));
3589 /* The last word is our local __gp value. */
3590 value
= _bfd_get_gp_value (info
->output_bfd
);
3591 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
,
3592 hppa_info
->opd_sec
->contents
+ hh
->opd_offset
+ 24);
3594 /* The DLT value is the address of the .opd entry. */
3595 value
= (hh
->opd_offset
3596 + hppa_info
->opd_sec
->output_offset
3597 + hppa_info
->opd_sec
->output_section
->vma
);
3599 bfd_put_64 (hppa_info
->dlt_sec
->owner
,
3601 hppa_info
->dlt_sec
->contents
+ hh
->dlt_offset
);
3604 /* We want the value of the DLT offset for this symbol, not
3605 the symbol's actual address. Note that __gp may not point
3606 to the start of the DLT, so we have to compute the absolute
3607 address, then subtract out the value of __gp. */
3608 value
= (hh
->dlt_offset
3609 + hppa_info
->dlt_sec
->output_offset
3610 + hppa_info
->dlt_sec
->output_section
->vma
);
3611 value
-= _bfd_get_gp_value (output_bfd
);
3612 bfd_put_64 (input_bfd
, value
, hit_data
);
3613 return bfd_reloc_ok
;
3616 case R_PARISC_DIR32
:
3617 bfd_put_32 (input_bfd
, value
+ addend
, hit_data
);
3618 return bfd_reloc_ok
;
3620 case R_PARISC_DIR64
:
3621 bfd_put_64 (input_bfd
, value
+ addend
, hit_data
);
3622 return bfd_reloc_ok
;
3624 case R_PARISC_GPREL64
:
3625 /* Subtract out the global pointer value to make value a DLT
3626 relative address. */
3627 value
-= _bfd_get_gp_value (output_bfd
);
3629 bfd_put_64 (input_bfd
, value
+ addend
, hit_data
);
3630 return bfd_reloc_ok
;
3632 case R_PARISC_LTOFF64
:
3633 /* We want the value of the DLT offset for this symbol, not
3634 the symbol's actual address. Note that __gp may not point
3635 to the start of the DLT, so we have to compute the absolute
3636 address, then subtract out the value of __gp. */
3637 value
= (hh
->dlt_offset
3638 + hppa_info
->dlt_sec
->output_offset
3639 + hppa_info
->dlt_sec
->output_section
->vma
);
3640 value
-= _bfd_get_gp_value (output_bfd
);
3642 bfd_put_64 (input_bfd
, value
+ addend
, hit_data
);
3643 return bfd_reloc_ok
;
3645 case R_PARISC_PCREL32
:
3647 /* If this is a call to a function defined in another dynamic
3648 library, then redirect the call to the local stub for this
3650 if (sym_sec
== NULL
|| sym_sec
->output_section
== NULL
)
3651 value
= (hh
->stub_offset
+ hppa_info
->stub_sec
->output_offset
3652 + hppa_info
->stub_sec
->output_section
->vma
);
3654 /* Turn VALUE into a proper PC relative address. */
3655 value
-= (offset
+ input_section
->output_offset
3656 + input_section
->output_section
->vma
);
3660 bfd_put_32 (input_bfd
, value
, hit_data
);
3661 return bfd_reloc_ok
;
3664 case R_PARISC_PCREL64
:
3666 /* If this is a call to a function defined in another dynamic
3667 library, then redirect the call to the local stub for this
3669 if (sym_sec
== NULL
|| sym_sec
->output_section
== NULL
)
3670 value
= (hh
->stub_offset
+ hppa_info
->stub_sec
->output_offset
3671 + hppa_info
->stub_sec
->output_section
->vma
);
3673 /* Turn VALUE into a proper PC relative address. */
3674 value
-= (offset
+ input_section
->output_offset
3675 + input_section
->output_section
->vma
);
3679 bfd_put_64 (input_bfd
, value
, hit_data
);
3680 return bfd_reloc_ok
;
3683 case R_PARISC_FPTR64
:
3687 /* We may still need to create the FPTR itself if it was for
3691 bfd_vma
*local_opd_offsets
;
3693 if (local_offsets
== NULL
)
3696 local_opd_offsets
= local_offsets
+ 2 * symtab_hdr
->sh_info
;
3697 off
= local_opd_offsets
[r_symndx
];
3699 /* The last bit records whether we've already initialised
3700 this local .opd entry. */
3703 BFD_ASSERT (off
!= (bfd_vma
) -1);
3708 /* The first two words of an .opd entry are zero. */
3709 memset (hppa_info
->opd_sec
->contents
+ off
, 0, 16);
3711 /* The next word is the address of the function. */
3712 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
+ addend
,
3713 (hppa_info
->opd_sec
->contents
+ off
+ 16));
3715 /* The last word is our local __gp value. */
3716 value
= _bfd_get_gp_value (info
->output_bfd
);
3717 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
,
3718 hppa_info
->opd_sec
->contents
+ off
+ 24);
3722 off
= hh
->opd_offset
;
3724 if (hh
== NULL
|| hh
->want_opd
)
3725 /* We want the value of the OPD offset for this symbol. */
3727 + hppa_info
->opd_sec
->output_offset
3728 + hppa_info
->opd_sec
->output_section
->vma
);
3730 /* We want the address of the symbol. */
3733 bfd_put_64 (input_bfd
, value
, hit_data
);
3734 return bfd_reloc_ok
;
3737 case R_PARISC_SECREL32
:
3739 value
-= sym_sec
->output_section
->vma
;
3740 bfd_put_32 (input_bfd
, value
+ addend
, hit_data
);
3741 return bfd_reloc_ok
;
3743 case R_PARISC_SEGREL32
:
3744 case R_PARISC_SEGREL64
:
3746 /* If this is the first SEGREL relocation, then initialize
3747 the segment base values. */
3748 if (hppa_info
->text_segment_base
== (bfd_vma
) -1)
3749 bfd_map_over_sections (output_bfd
, elf_hppa_record_segment_addrs
,
3752 /* VALUE holds the absolute address. We want to include the
3753 addend, then turn it into a segment relative address.
3755 The segment is derived from SYM_SEC. We assume that there are
3756 only two segments of note in the resulting executable/shlib.
3757 A readonly segment (.text) and a readwrite segment (.data). */
3760 if (sym_sec
->flags
& SEC_CODE
)
3761 value
-= hppa_info
->text_segment_base
;
3763 value
-= hppa_info
->data_segment_base
;
3765 if (r_type
== R_PARISC_SEGREL32
)
3766 bfd_put_32 (input_bfd
, value
, hit_data
);
3768 bfd_put_64 (input_bfd
, value
, hit_data
);
3769 return bfd_reloc_ok
;
3772 /* Something we don't know how to handle. */
3774 return bfd_reloc_notsupported
;
3777 /* Update the instruction word. */
3778 bfd_put_32 (input_bfd
, (bfd_vma
) insn
, hit_data
);
3779 return bfd_reloc_ok
;
3782 /* Relocate an HPPA ELF section. */
3785 elf64_hppa_relocate_section (bfd
*output_bfd
,
3786 struct bfd_link_info
*info
,
3788 asection
*input_section
,
3790 Elf_Internal_Rela
*relocs
,
3791 Elf_Internal_Sym
*local_syms
,
3792 asection
**local_sections
)
3794 Elf_Internal_Shdr
*symtab_hdr
;
3795 Elf_Internal_Rela
*rel
;
3796 Elf_Internal_Rela
*relend
;
3797 struct elf64_hppa_link_hash_table
*hppa_info
;
3799 hppa_info
= hppa_link_hash_table (info
);
3800 if (hppa_info
== NULL
)
3803 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3806 relend
= relocs
+ input_section
->reloc_count
;
3807 for (; rel
< relend
; rel
++)
3810 reloc_howto_type
*howto
= elf_hppa_howto_table
+ ELF_R_TYPE (rel
->r_info
);
3811 unsigned long r_symndx
;
3812 struct elf_link_hash_entry
*eh
;
3813 Elf_Internal_Sym
*sym
;
3816 bfd_reloc_status_type r
;
3818 r_type
= ELF_R_TYPE (rel
->r_info
);
3819 if (r_type
< 0 || r_type
>= (int) R_PARISC_UNIMPLEMENTED
)
3821 bfd_set_error (bfd_error_bad_value
);
3824 if (r_type
== (unsigned int) R_PARISC_GNU_VTENTRY
3825 || r_type
== (unsigned int) R_PARISC_GNU_VTINHERIT
)
3828 /* This is a final link. */
3829 r_symndx
= ELF_R_SYM (rel
->r_info
);
3833 if (r_symndx
< symtab_hdr
->sh_info
)
3835 /* This is a local symbol, hh defaults to NULL. */
3836 sym
= local_syms
+ r_symndx
;
3837 sym_sec
= local_sections
[r_symndx
];
3838 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sym_sec
, rel
);
3842 /* This is not a local symbol. */
3843 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (input_bfd
);
3845 /* It seems this can happen with erroneous or unsupported
3846 input (mixing a.out and elf in an archive, for example.) */
3847 if (sym_hashes
== NULL
)
3850 eh
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3852 if (info
->wrap_hash
!= NULL
3853 && (input_section
->flags
& SEC_DEBUGGING
) != 0)
3854 eh
= ((struct elf_link_hash_entry
*)
3855 unwrap_hash_lookup (info
, input_bfd
, &eh
->root
));
3857 while (eh
->root
.type
== bfd_link_hash_indirect
3858 || eh
->root
.type
== bfd_link_hash_warning
)
3859 eh
= (struct elf_link_hash_entry
*) eh
->root
.u
.i
.link
;
3862 if (eh
->root
.type
== bfd_link_hash_defined
3863 || eh
->root
.type
== bfd_link_hash_defweak
)
3865 sym_sec
= eh
->root
.u
.def
.section
;
3867 && sym_sec
->output_section
!= NULL
)
3868 relocation
= (eh
->root
.u
.def
.value
3869 + sym_sec
->output_section
->vma
3870 + sym_sec
->output_offset
);
3872 else if (eh
->root
.type
== bfd_link_hash_undefweak
)
3874 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
3875 && ELF_ST_VISIBILITY (eh
->other
) == STV_DEFAULT
)
3877 else if (!bfd_link_relocatable (info
)
3878 && elf_hppa_is_dynamic_loader_symbol (eh
->root
.root
.string
))
3880 else if (!bfd_link_relocatable (info
))
3883 err
= (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
3884 || ELF_ST_VISIBILITY (eh
->other
) != STV_DEFAULT
);
3885 (*info
->callbacks
->undefined_symbol
) (info
,
3886 eh
->root
.root
.string
,
3889 rel
->r_offset
, err
);
3892 if (!bfd_link_relocatable (info
)
3894 && eh
->root
.type
!= bfd_link_hash_defined
3895 && eh
->root
.type
!= bfd_link_hash_defweak
3896 && eh
->root
.type
!= bfd_link_hash_undefweak
)
3898 if (info
->unresolved_syms_in_objects
== RM_IGNORE
3899 && ELF_ST_VISIBILITY (eh
->other
) == STV_DEFAULT
3900 && eh
->type
== STT_PARISC_MILLI
)
3901 (*info
->callbacks
->undefined_symbol
)
3902 (info
, eh_name (eh
), input_bfd
,
3903 input_section
, rel
->r_offset
, FALSE
);
3907 if (sym_sec
!= NULL
&& discarded_section (sym_sec
))
3908 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
3909 rel
, 1, relend
, howto
, 0, contents
);
3911 if (bfd_link_relocatable (info
))
3914 r
= elf_hppa_final_link_relocate (rel
, input_bfd
, output_bfd
,
3915 input_section
, contents
,
3916 relocation
, info
, sym_sec
,
3919 if (r
!= bfd_reloc_ok
)
3925 case bfd_reloc_overflow
:
3927 const char *sym_name
;
3933 sym_name
= bfd_elf_string_from_elf_section (input_bfd
,
3934 symtab_hdr
->sh_link
,
3936 if (sym_name
== NULL
)
3938 if (*sym_name
== '\0')
3939 sym_name
= bfd_section_name (sym_sec
);
3942 (*info
->callbacks
->reloc_overflow
)
3943 (info
, (eh
? &eh
->root
: NULL
), sym_name
, howto
->name
,
3944 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
3953 static const struct bfd_elf_special_section elf64_hppa_special_sections
[] =
3955 { STRING_COMMA_LEN (".tbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_HP_TLS
},
3956 { STRING_COMMA_LEN (".fini"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
3957 { STRING_COMMA_LEN (".init"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
3958 { STRING_COMMA_LEN (".plt"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
3959 { STRING_COMMA_LEN (".dlt"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
3960 { STRING_COMMA_LEN (".sdata"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
3961 { STRING_COMMA_LEN (".sbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
3962 { NULL
, 0, 0, 0, 0 }
3965 /* The hash bucket size is the standard one, namely 4. */
3967 const struct elf_size_info hppa64_elf_size_info
=
3969 sizeof (Elf64_External_Ehdr
),
3970 sizeof (Elf64_External_Phdr
),
3971 sizeof (Elf64_External_Shdr
),
3972 sizeof (Elf64_External_Rel
),
3973 sizeof (Elf64_External_Rela
),
3974 sizeof (Elf64_External_Sym
),
3975 sizeof (Elf64_External_Dyn
),
3976 sizeof (Elf_External_Note
),
3980 ELFCLASS64
, EV_CURRENT
,
3981 bfd_elf64_write_out_phdrs
,
3982 bfd_elf64_write_shdrs_and_ehdr
,
3983 bfd_elf64_checksum_contents
,
3984 bfd_elf64_write_relocs
,
3985 bfd_elf64_swap_symbol_in
,
3986 bfd_elf64_swap_symbol_out
,
3987 bfd_elf64_slurp_reloc_table
,
3988 bfd_elf64_slurp_symbol_table
,
3989 bfd_elf64_swap_dyn_in
,
3990 bfd_elf64_swap_dyn_out
,
3991 bfd_elf64_swap_reloc_in
,
3992 bfd_elf64_swap_reloc_out
,
3993 bfd_elf64_swap_reloca_in
,
3994 bfd_elf64_swap_reloca_out
3997 #define TARGET_BIG_SYM hppa_elf64_vec
3998 #define TARGET_BIG_NAME "elf64-hppa"
3999 #define ELF_ARCH bfd_arch_hppa
4000 #define ELF_TARGET_ID HPPA64_ELF_DATA
4001 #define ELF_MACHINE_CODE EM_PARISC
4002 /* This is not strictly correct. The maximum page size for PA2.0 is
4003 64M. But everything still uses 4k. */
4004 #define ELF_MAXPAGESIZE 0x1000
4005 #define ELF_OSABI ELFOSABI_HPUX
4007 #define bfd_elf64_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
4008 #define bfd_elf64_bfd_reloc_name_lookup elf_hppa_reloc_name_lookup
4009 #define bfd_elf64_bfd_is_local_label_name elf_hppa_is_local_label_name
4010 #define elf_info_to_howto elf_hppa_info_to_howto
4011 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
4013 #define elf_backend_section_from_shdr elf64_hppa_section_from_shdr
4014 #define elf_backend_object_p elf64_hppa_object_p
4015 #define elf_backend_final_write_processing \
4016 elf_hppa_final_write_processing
4017 #define elf_backend_fake_sections elf_hppa_fake_sections
4018 #define elf_backend_add_symbol_hook elf_hppa_add_symbol_hook
4020 #define elf_backend_relocate_section elf_hppa_relocate_section
4022 #define bfd_elf64_bfd_final_link elf_hppa_final_link
4024 #define elf_backend_create_dynamic_sections \
4025 elf64_hppa_create_dynamic_sections
4026 #define elf_backend_init_file_header elf64_hppa_init_file_header
4028 #define elf_backend_omit_section_dynsym _bfd_elf_omit_section_dynsym_all
4030 #define elf_backend_adjust_dynamic_symbol \
4031 elf64_hppa_adjust_dynamic_symbol
4033 #define elf_backend_size_dynamic_sections \
4034 elf64_hppa_size_dynamic_sections
4036 #define elf_backend_finish_dynamic_symbol \
4037 elf64_hppa_finish_dynamic_symbol
4038 #define elf_backend_finish_dynamic_sections \
4039 elf64_hppa_finish_dynamic_sections
4040 #define elf_backend_grok_prstatus elf64_hppa_grok_prstatus
4041 #define elf_backend_grok_psinfo elf64_hppa_grok_psinfo
4043 /* Stuff for the BFD linker: */
4044 #define bfd_elf64_bfd_link_hash_table_create \
4045 elf64_hppa_hash_table_create
4047 #define elf_backend_check_relocs \
4048 elf64_hppa_check_relocs
4050 #define elf_backend_size_info \
4051 hppa64_elf_size_info
4053 #define elf_backend_additional_program_headers \
4054 elf64_hppa_additional_program_headers
4056 #define elf_backend_modify_segment_map \
4057 elf64_hppa_modify_segment_map
4059 #define elf_backend_allow_non_load_phdr \
4060 elf64_hppa_allow_non_load_phdr
4062 #define elf_backend_link_output_symbol_hook \
4063 elf64_hppa_link_output_symbol_hook
4065 #define elf_backend_want_got_plt 0
4066 #define elf_backend_plt_readonly 0
4067 #define elf_backend_want_plt_sym 0
4068 #define elf_backend_got_header_size 0
4069 #define elf_backend_type_change_ok TRUE
4070 #define elf_backend_get_symbol_type elf64_hppa_elf_get_symbol_type
4071 #define elf_backend_reloc_type_class elf64_hppa_reloc_type_class
4072 #define elf_backend_rela_normal 1
4073 #define elf_backend_special_sections elf64_hppa_special_sections
4074 #define elf_backend_action_discarded elf_hppa_action_discarded
4075 #define elf_backend_section_from_phdr elf64_hppa_section_from_phdr
4077 #define elf64_bed elf64_hppa_hpux_bed
4079 #include "elf64-target.h"
4081 #undef TARGET_BIG_SYM
4082 #define TARGET_BIG_SYM hppa_elf64_linux_vec
4083 #undef TARGET_BIG_NAME
4084 #define TARGET_BIG_NAME "elf64-hppa-linux"
4086 #define ELF_OSABI ELFOSABI_GNU
4088 #define elf64_bed elf64_hppa_linux_bed
4089 #undef elf_backend_special_sections
4090 #define elf_backend_special_sections (elf64_hppa_special_sections + 1)
4092 #include "elf64-target.h"