1 /* Support for HPPA 64-bit ELF
2 Copyright (C) 1999-2024 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. */
27 #include "elf64-hppa.h"
28 #include "libiberty.h"
32 #define PLT_ENTRY_SIZE 0x10
33 #define DLT_ENTRY_SIZE 0x8
34 #define OPD_ENTRY_SIZE 0x20
36 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/pa20_64/dld.sl"
38 /* The stub is supposed to load the target address and target's DP
39 value out of the PLT, then do an external branch to the target
44 LDD PLTOFF+8(%r27),%r27
46 Note that we must use the LDD with a 14 bit displacement, not the one
47 with a 5 bit displacement. */
48 static char plt_stub
[] = {0x53, 0x61, 0x00, 0x00, 0xe8, 0x20, 0xd0, 0x00,
49 0x53, 0x7b, 0x00, 0x00 };
51 struct elf64_hppa_link_hash_entry
53 struct elf_link_hash_entry eh
;
55 /* Offsets for this symbol in various linker sections. */
61 /* The index of the (possibly local) symbol in the input bfd and its
62 associated BFD. Needed so that we can have relocs against local
63 symbols in shared libraries. */
67 /* Dynamic symbols may need to have two different values. One for
68 the dynamic symbol table, one for the normal symbol table.
70 In such cases we store the symbol's real value and section
71 index here so we can restore the real value before we write
72 the normal symbol table. */
76 /* Used to count non-got, non-plt relocations for delayed sizing
77 of relocation sections. */
78 struct elf64_hppa_dyn_reloc_entry
80 /* Next relocation in the chain. */
81 struct elf64_hppa_dyn_reloc_entry
*next
;
83 /* The type of the relocation. */
86 /* The input section of the relocation. */
89 /* Number of relocs copied in this section. */
92 /* The index of the section symbol for the input section of
93 the relocation. Only needed when building shared libraries. */
96 /* The offset within the input section of the relocation. */
99 /* The addend for the relocation. */
104 /* Nonzero if this symbol needs an entry in one of the linker
112 struct elf64_hppa_link_hash_table
114 struct elf_link_hash_table root
;
116 /* Shortcuts to get to the various linker defined sections. */
118 asection
*dlt_rel_sec
;
120 asection
*opd_rel_sec
;
121 asection
*other_rel_sec
;
123 /* Offset of __gp within .plt section. When the PLT gets large we want
124 to slide __gp into the PLT section so that we can continue to use
125 single DP relative instructions to load values out of the PLT. */
128 /* Note this is not strictly correct. We should create a stub section for
129 each input section with calls. The stub section should be placed before
130 the section with the call. */
133 bfd_vma text_segment_base
;
134 bfd_vma data_segment_base
;
136 /* We build tables to map from an input section back to its
137 symbol index. This is the BFD for which we currently have
139 bfd
*section_syms_bfd
;
141 /* Array of symbol numbers for each input section attached to the
146 #define hppa_link_hash_table(p) \
147 ((is_elf_hash_table ((p)->hash) \
148 && elf_hash_table_id (elf_hash_table (p)) == HPPA64_ELF_DATA) \
149 ? (struct elf64_hppa_link_hash_table *) (p)->hash : NULL)
151 #define hppa_elf_hash_entry(ent) \
152 ((struct elf64_hppa_link_hash_entry *)(ent))
154 #define eh_name(eh) \
155 (eh ? eh->root.root.string : "<undef>")
157 typedef struct bfd_hash_entry
*(*new_hash_entry_func
)
158 (struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *);
160 static struct bfd_link_hash_table
*elf64_hppa_hash_table_create
163 /* This must follow the definitions of the various derived linker
164 hash tables and shared functions. */
165 #include "elf-hppa.h"
167 static bool elf64_hppa_object_p
170 static bool elf64_hppa_create_dynamic_sections
171 (bfd
*, struct bfd_link_info
*);
173 static bool elf64_hppa_adjust_dynamic_symbol
174 (struct bfd_link_info
*, struct elf_link_hash_entry
*);
176 static bool elf64_hppa_mark_milli_and_exported_functions
177 (struct elf_link_hash_entry
*, void *);
179 static int elf64_hppa_link_output_symbol_hook
180 (struct bfd_link_info
*, const char *, Elf_Internal_Sym
*,
181 asection
*, struct elf_link_hash_entry
*);
183 static bool elf64_hppa_finish_dynamic_symbol
184 (bfd
*, struct bfd_link_info
*,
185 struct elf_link_hash_entry
*, Elf_Internal_Sym
*);
187 static bool elf64_hppa_finish_dynamic_sections
188 (bfd
*, struct bfd_link_info
*);
190 static bool elf64_hppa_check_relocs
191 (bfd
*, struct bfd_link_info
*,
192 asection
*, const Elf_Internal_Rela
*);
194 static bool elf64_hppa_dynamic_symbol_p
195 (struct elf_link_hash_entry
*, struct bfd_link_info
*);
197 static bool elf64_hppa_mark_exported_functions
198 (struct elf_link_hash_entry
*, void *);
200 static bool elf64_hppa_finalize_opd
201 (struct elf_link_hash_entry
*, void *);
203 static bool elf64_hppa_finalize_dlt
204 (struct elf_link_hash_entry
*, void *);
206 static bool allocate_global_data_dlt
207 (struct elf_link_hash_entry
*, void *);
209 static bool allocate_global_data_plt
210 (struct elf_link_hash_entry
*, void *);
212 static bool allocate_global_data_stub
213 (struct elf_link_hash_entry
*, void *);
215 static bool allocate_global_data_opd
216 (struct elf_link_hash_entry
*, void *);
218 static bool get_reloc_section
219 (bfd
*, struct elf64_hppa_link_hash_table
*, asection
*);
221 static bool count_dyn_reloc
222 (bfd
*, struct elf64_hppa_link_hash_entry
*,
223 int, asection
*, int, bfd_vma
, bfd_vma
);
225 static bool allocate_dynrel_entries
226 (struct elf_link_hash_entry
*, void *);
228 static bool elf64_hppa_finalize_dynreloc
229 (struct elf_link_hash_entry
*, void *);
232 (bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*);
235 (bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*);
238 (bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*);
241 (bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*);
243 static int elf64_hppa_elf_get_symbol_type
244 (Elf_Internal_Sym
*, int);
246 /* Initialize an entry in the link hash table. */
248 static struct bfd_hash_entry
*
249 hppa64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
250 struct bfd_hash_table
*table
,
253 /* Allocate the structure if it has not already been allocated by a
257 entry
= bfd_hash_allocate (table
,
258 sizeof (struct elf64_hppa_link_hash_entry
));
263 /* Call the allocation method of the superclass. */
264 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
267 struct elf64_hppa_link_hash_entry
*hh
;
269 /* Initialize our local data. All zeros. */
270 hh
= hppa_elf_hash_entry (entry
);
271 memset (&hh
->dlt_offset
, 0,
272 (sizeof (struct elf64_hppa_link_hash_entry
)
273 - offsetof (struct elf64_hppa_link_hash_entry
, dlt_offset
)));
279 /* Create the derived linker hash table. The PA64 ELF port uses this
280 derived hash table to keep information specific to the PA ElF
281 linker (without using static variables). */
283 static struct bfd_link_hash_table
*
284 elf64_hppa_hash_table_create (bfd
*abfd
)
286 struct elf64_hppa_link_hash_table
*htab
;
287 size_t amt
= sizeof (*htab
);
289 htab
= bfd_zmalloc (amt
);
293 if (!_bfd_elf_link_hash_table_init (&htab
->root
, abfd
,
294 hppa64_link_hash_newfunc
,
295 sizeof (struct elf64_hppa_link_hash_entry
),
302 htab
->root
.dt_pltgot_required
= true;
303 htab
->text_segment_base
= (bfd_vma
) -1;
304 htab
->data_segment_base
= (bfd_vma
) -1;
306 return &htab
->root
.root
;
309 /* Return nonzero if ABFD represents a PA2.0 ELF64 file.
311 Additionally we set the default architecture and machine. */
313 elf64_hppa_object_p (bfd
*abfd
)
315 Elf_Internal_Ehdr
* i_ehdrp
;
318 i_ehdrp
= elf_elfheader (abfd
);
319 if (strcmp (bfd_get_target (abfd
), "elf64-hppa-linux") == 0)
321 /* GCC on hppa-linux produces binaries with OSABI=GNU,
322 but the kernel produces corefiles with OSABI=SysV. */
323 if (i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_GNU
324 && i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_NONE
) /* aka SYSV */
329 /* HPUX produces binaries with OSABI=HPUX,
330 but the kernel produces corefiles with OSABI=SysV. */
331 if (i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_HPUX
332 && i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_NONE
) /* aka SYSV */
336 flags
= i_ehdrp
->e_flags
;
337 switch (flags
& (EF_PARISC_ARCH
| EF_PARISC_WIDE
))
340 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 10);
342 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 11);
344 if (i_ehdrp
->e_ident
[EI_CLASS
] == ELFCLASS64
)
345 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 25);
347 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 20);
348 case EFA_PARISC_2_0
| EF_PARISC_WIDE
:
349 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 25);
351 /* Don't be fussy. */
355 /* Given section type (hdr->sh_type), return a boolean indicating
356 whether or not the section is an elf64-hppa specific section. */
358 elf64_hppa_section_from_shdr (bfd
*abfd
,
359 Elf_Internal_Shdr
*hdr
,
363 switch (hdr
->sh_type
)
366 if (strcmp (name
, ".PARISC.archext") != 0)
369 case SHT_PARISC_UNWIND
:
370 if (strcmp (name
, ".PARISC.unwind") != 0)
374 case SHT_PARISC_ANNOT
:
379 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
382 return ((hdr
->sh_flags
& SHF_PARISC_SHORT
) == 0
383 || bfd_set_section_flags (hdr
->bfd_section
,
384 hdr
->bfd_section
->flags
| SEC_SMALL_DATA
));
387 /* SEC is a section containing relocs for an input BFD when linking; return
388 a suitable section for holding relocs in the output BFD for a link. */
391 get_reloc_section (bfd
*abfd
,
392 struct elf64_hppa_link_hash_table
*hppa_info
,
395 const char *srel_name
;
399 srel_name
= (bfd_elf_string_from_elf_section
400 (abfd
, elf_elfheader(abfd
)->e_shstrndx
,
401 _bfd_elf_single_rel_hdr(sec
)->sh_name
));
402 if (srel_name
== NULL
)
405 dynobj
= hppa_info
->root
.dynobj
;
407 hppa_info
->root
.dynobj
= dynobj
= abfd
;
409 srel
= bfd_get_linker_section (dynobj
, srel_name
);
412 srel
= bfd_make_section_anyway_with_flags (dynobj
, srel_name
,
420 || !bfd_set_section_alignment (srel
, 3))
424 hppa_info
->other_rel_sec
= srel
;
428 /* Add a new entry to the list of dynamic relocations against DYN_H.
430 We use this to keep a record of all the FPTR relocations against a
431 particular symbol so that we can create FPTR relocations in the
435 count_dyn_reloc (bfd
*abfd
,
436 struct elf64_hppa_link_hash_entry
*hh
,
443 struct elf64_hppa_dyn_reloc_entry
*rent
;
445 rent
= (struct elf64_hppa_dyn_reloc_entry
*)
446 bfd_alloc (abfd
, (bfd_size_type
) sizeof (*rent
));
450 rent
->next
= hh
->reloc_entries
;
453 rent
->sec_symndx
= sec_symndx
;
454 rent
->offset
= offset
;
455 rent
->addend
= addend
;
456 hh
->reloc_entries
= rent
;
461 /* Return a pointer to the local DLT, PLT and OPD reference counts
462 for ABFD. Returns NULL if the storage allocation fails. */
464 static bfd_signed_vma
*
465 hppa64_elf_local_refcounts (bfd
*abfd
)
467 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
468 bfd_signed_vma
*local_refcounts
;
470 local_refcounts
= elf_local_got_refcounts (abfd
);
471 if (local_refcounts
== NULL
)
475 /* Allocate space for local DLT, PLT and OPD reference
476 counts. Done this way to save polluting elf_obj_tdata
477 with another target specific pointer. */
478 size
= symtab_hdr
->sh_info
;
479 size
*= 3 * sizeof (bfd_signed_vma
);
480 local_refcounts
= bfd_zalloc (abfd
, size
);
481 elf_local_got_refcounts (abfd
) = local_refcounts
;
483 return local_refcounts
;
486 /* Scan the RELOCS and record the type of dynamic entries that each
487 referenced symbol needs. */
490 elf64_hppa_check_relocs (bfd
*abfd
,
491 struct bfd_link_info
*info
,
493 const Elf_Internal_Rela
*relocs
)
495 struct elf64_hppa_link_hash_table
*hppa_info
;
496 const Elf_Internal_Rela
*relend
;
497 Elf_Internal_Shdr
*symtab_hdr
;
498 const Elf_Internal_Rela
*rel
;
499 unsigned int sec_symndx
;
501 if (bfd_link_relocatable (info
))
504 /* If this is the first dynamic object found in the link, create
505 the special sections required for dynamic linking. */
506 if (! elf_hash_table (info
)->dynamic_sections_created
)
508 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
512 hppa_info
= hppa_link_hash_table (info
);
513 if (hppa_info
== NULL
)
515 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
517 /* If necessary, build a new table holding section symbols indices
520 if (bfd_link_pic (info
) && hppa_info
->section_syms_bfd
!= abfd
)
523 unsigned int highest_shndx
;
524 Elf_Internal_Sym
*local_syms
= NULL
;
525 Elf_Internal_Sym
*isym
, *isymend
;
528 /* We're done with the old cache of section index to section symbol
529 index information. Free it.
531 ?!? Note we leak the last section_syms array. Presumably we
532 could free it in one of the later routines in this file. */
533 free (hppa_info
->section_syms
);
535 /* Read this BFD's local symbols. */
536 if (symtab_hdr
->sh_info
!= 0)
538 local_syms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
539 if (local_syms
== NULL
)
540 local_syms
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
541 symtab_hdr
->sh_info
, 0,
543 if (local_syms
== NULL
)
547 /* Record the highest section index referenced by the local symbols. */
549 isymend
= local_syms
+ symtab_hdr
->sh_info
;
550 for (isym
= local_syms
; isym
< isymend
; isym
++)
552 if (isym
->st_shndx
> highest_shndx
553 && isym
->st_shndx
< SHN_LORESERVE
)
554 highest_shndx
= isym
->st_shndx
;
557 /* Allocate an array to hold the section index to section symbol index
558 mapping. Bump by one since we start counting at zero. */
562 hppa_info
->section_syms
= (int *) bfd_malloc (amt
);
564 /* Now walk the local symbols again. If we find a section symbol,
565 record the index of the symbol into the section_syms array. */
566 for (i
= 0, isym
= local_syms
; isym
< isymend
; i
++, isym
++)
568 if (ELF_ST_TYPE (isym
->st_info
) == STT_SECTION
)
569 hppa_info
->section_syms
[isym
->st_shndx
] = i
;
572 /* We are finished with the local symbols. */
573 if (local_syms
!= NULL
574 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
576 if (! info
->keep_memory
)
580 /* Cache the symbols for elf_link_input_bfd. */
581 symtab_hdr
->contents
= (unsigned char *) local_syms
;
585 /* Record which BFD we built the section_syms mapping for. */
586 hppa_info
->section_syms_bfd
= abfd
;
589 /* Record the symbol index for this input section. We may need it for
590 relocations when building shared libraries. When not building shared
591 libraries this value is never really used, but assign it to zero to
592 prevent out of bounds memory accesses in other routines. */
593 if (bfd_link_pic (info
))
595 sec_symndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
597 /* If we did not find a section symbol for this section, then
598 something went terribly wrong above. */
599 if (sec_symndx
== SHN_BAD
)
602 if (sec_symndx
< SHN_LORESERVE
)
603 sec_symndx
= hppa_info
->section_syms
[sec_symndx
];
610 relend
= relocs
+ sec
->reloc_count
;
611 for (rel
= relocs
; rel
< relend
; ++rel
)
622 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
623 struct elf64_hppa_link_hash_entry
*hh
;
626 int dynrel_type
= R_PARISC_NONE
;
627 static reloc_howto_type
*howto
;
629 if (r_symndx
>= symtab_hdr
->sh_info
)
631 /* We're dealing with a global symbol -- find its hash entry
632 and mark it as being referenced. */
633 long indx
= r_symndx
- symtab_hdr
->sh_info
;
634 hh
= hppa_elf_hash_entry (elf_sym_hashes (abfd
)[indx
]);
635 while (hh
->eh
.root
.type
== bfd_link_hash_indirect
636 || hh
->eh
.root
.type
== bfd_link_hash_warning
)
637 hh
= hppa_elf_hash_entry (hh
->eh
.root
.u
.i
.link
);
639 /* PR15323, ref flags aren't set for references in the same
641 hh
->eh
.ref_regular
= 1;
646 /* We can only get preliminary data on whether a symbol is
647 locally or externally defined, as not all of the input files
648 have yet been processed. Do something with what we know, as
649 this may help reduce memory usage and processing time later. */
650 maybe_dynamic
= false;
651 if (hh
&& ((bfd_link_pic (info
)
653 || info
->unresolved_syms_in_shared_libs
== RM_IGNORE
))
654 || !hh
->eh
.def_regular
655 || hh
->eh
.root
.type
== bfd_link_hash_defweak
))
656 maybe_dynamic
= true;
658 howto
= elf_hppa_howto_table
+ ELF64_R_TYPE (rel
->r_info
);
662 /* These are simple indirect references to symbols through the
663 DLT. We need to create a DLT entry for any symbols which
664 appears in a DLTIND relocation. */
665 case R_PARISC_DLTIND21L
:
666 case R_PARISC_DLTIND14R
:
667 case R_PARISC_DLTIND14F
:
668 case R_PARISC_DLTIND14WR
:
669 case R_PARISC_DLTIND14DR
:
670 need_entry
= NEED_DLT
;
673 /* ?!? These need a DLT entry. But I have no idea what to do with
674 the "link time TP value. */
675 case R_PARISC_LTOFF_TP21L
:
676 case R_PARISC_LTOFF_TP14R
:
677 case R_PARISC_LTOFF_TP14F
:
678 case R_PARISC_LTOFF_TP64
:
679 case R_PARISC_LTOFF_TP14WR
:
680 case R_PARISC_LTOFF_TP14DR
:
681 case R_PARISC_LTOFF_TP16F
:
682 case R_PARISC_LTOFF_TP16WF
:
683 case R_PARISC_LTOFF_TP16DF
:
684 need_entry
= NEED_DLT
;
687 /* These are function calls. Depending on their precise target we
688 may need to make a stub for them. The stub uses the PLT, so we
689 need to create PLT entries for these symbols too. */
690 case R_PARISC_PCREL12F
:
691 case R_PARISC_PCREL17F
:
692 case R_PARISC_PCREL22F
:
693 case R_PARISC_PCREL32
:
694 case R_PARISC_PCREL64
:
695 case R_PARISC_PCREL21L
:
696 case R_PARISC_PCREL17R
:
697 case R_PARISC_PCREL17C
:
698 case R_PARISC_PCREL14R
:
699 case R_PARISC_PCREL14F
:
700 case R_PARISC_PCREL22C
:
701 case R_PARISC_PCREL14WR
:
702 case R_PARISC_PCREL14DR
:
703 case R_PARISC_PCREL16F
:
704 case R_PARISC_PCREL16WF
:
705 case R_PARISC_PCREL16DF
:
706 /* Function calls might need to go through the .plt, and
707 might need a long branch stub. */
708 if (hh
!= NULL
&& hh
->eh
.type
!= STT_PARISC_MILLI
)
709 need_entry
= (NEED_PLT
| NEED_STUB
);
714 case R_PARISC_PLTOFF21L
:
715 case R_PARISC_PLTOFF14R
:
716 case R_PARISC_PLTOFF14F
:
717 case R_PARISC_PLTOFF14WR
:
718 case R_PARISC_PLTOFF14DR
:
719 case R_PARISC_PLTOFF16F
:
720 case R_PARISC_PLTOFF16WF
:
721 case R_PARISC_PLTOFF16DF
:
722 need_entry
= (NEED_PLT
);
726 if (bfd_link_pic (info
) || maybe_dynamic
)
727 need_entry
= (NEED_DYNREL
);
728 dynrel_type
= R_PARISC_DIR64
;
731 /* This is an indirect reference through the DLT to get the address
732 of a OPD descriptor. Thus we need to make a DLT entry that points
734 case R_PARISC_LTOFF_FPTR21L
:
735 case R_PARISC_LTOFF_FPTR14R
:
736 case R_PARISC_LTOFF_FPTR14WR
:
737 case R_PARISC_LTOFF_FPTR14DR
:
738 case R_PARISC_LTOFF_FPTR32
:
739 case R_PARISC_LTOFF_FPTR64
:
740 case R_PARISC_LTOFF_FPTR16F
:
741 case R_PARISC_LTOFF_FPTR16WF
:
742 case R_PARISC_LTOFF_FPTR16DF
:
743 if (bfd_link_pic (info
) || maybe_dynamic
)
744 need_entry
= (NEED_DLT
| NEED_OPD
| NEED_PLT
);
746 need_entry
= (NEED_DLT
| NEED_OPD
| NEED_PLT
);
747 dynrel_type
= R_PARISC_FPTR64
;
750 /* This is a simple OPD entry. */
751 case R_PARISC_FPTR64
:
752 if (bfd_link_pic (info
) || maybe_dynamic
)
753 need_entry
= (NEED_OPD
| NEED_PLT
| NEED_DYNREL
);
755 need_entry
= (NEED_OPD
| NEED_PLT
);
756 dynrel_type
= R_PARISC_FPTR64
;
759 /* Add more cases as needed. */
767 /* Stash away enough information to be able to find this symbol
768 regardless of whether or not it is local or global. */
770 hh
->sym_indx
= r_symndx
;
773 /* Create what's needed. */
774 if (need_entry
& NEED_DLT
)
776 /* Allocate space for a DLT entry, as well as a dynamic
777 relocation for this entry. */
778 if (! hppa_info
->dlt_sec
779 && ! get_dlt (abfd
, info
, hppa_info
))
785 hh
->eh
.got
.refcount
+= 1;
789 bfd_signed_vma
*local_dlt_refcounts
;
791 /* This is a DLT entry for a local symbol. */
792 local_dlt_refcounts
= hppa64_elf_local_refcounts (abfd
);
793 if (local_dlt_refcounts
== NULL
)
795 local_dlt_refcounts
[r_symndx
] += 1;
799 if (need_entry
& NEED_PLT
)
801 if (! hppa_info
->root
.splt
802 && ! get_plt (abfd
, info
, hppa_info
))
808 hh
->eh
.needs_plt
= 1;
809 hh
->eh
.plt
.refcount
+= 1;
813 bfd_signed_vma
*local_dlt_refcounts
;
814 bfd_signed_vma
*local_plt_refcounts
;
816 /* This is a PLT entry for a local symbol. */
817 local_dlt_refcounts
= hppa64_elf_local_refcounts (abfd
);
818 if (local_dlt_refcounts
== NULL
)
820 local_plt_refcounts
= local_dlt_refcounts
+ symtab_hdr
->sh_info
;
821 local_plt_refcounts
[r_symndx
] += 1;
825 if (need_entry
& NEED_STUB
)
827 if (! hppa_info
->stub_sec
828 && ! get_stub (abfd
, info
, hppa_info
))
834 if (need_entry
& NEED_OPD
)
836 if (! hppa_info
->opd_sec
837 && ! get_opd (abfd
, info
, hppa_info
))
840 /* FPTRs are not allocated by the dynamic linker for PA64,
841 though it is possible that will change in the future. */
847 bfd_signed_vma
*local_dlt_refcounts
;
848 bfd_signed_vma
*local_opd_refcounts
;
850 /* This is a OPD for a local symbol. */
851 local_dlt_refcounts
= hppa64_elf_local_refcounts (abfd
);
852 if (local_dlt_refcounts
== NULL
)
854 local_opd_refcounts
= (local_dlt_refcounts
855 + 2 * symtab_hdr
->sh_info
);
856 local_opd_refcounts
[r_symndx
] += 1;
860 /* Add a new dynamic relocation to the chain of dynamic
861 relocations for this symbol. */
862 if ((need_entry
& NEED_DYNREL
) && (sec
->flags
& SEC_ALLOC
))
864 if (! hppa_info
->other_rel_sec
865 && ! get_reloc_section (abfd
, hppa_info
, sec
))
868 /* Count dynamic relocations against global symbols. */
870 && !count_dyn_reloc (abfd
, hh
, dynrel_type
, sec
,
871 sec_symndx
, rel
->r_offset
, rel
->r_addend
))
874 /* If we are building a shared library and we just recorded
875 a dynamic R_PARISC_FPTR64 relocation, then make sure the
876 section symbol for this section ends up in the dynamic
878 if (bfd_link_pic (info
) && dynrel_type
== R_PARISC_FPTR64
879 && ! (bfd_elf_link_record_local_dynamic_symbol
880 (info
, abfd
, sec_symndx
)))
891 struct elf64_hppa_allocate_data
893 struct bfd_link_info
*info
;
897 /* Should we do dynamic things to this symbol? */
900 elf64_hppa_dynamic_symbol_p (struct elf_link_hash_entry
*eh
,
901 struct bfd_link_info
*info
)
903 /* ??? What, if anything, needs to happen wrt STV_PROTECTED symbols
904 and relocations that retrieve a function descriptor? Assume the
906 if (_bfd_elf_dynamic_symbol_p (eh
, info
, 1))
908 /* ??? Why is this here and not elsewhere is_local_label_name. */
909 if (eh
->root
.root
.string
[0] == '$' && eh
->root
.root
.string
[1] == '$')
918 /* Mark all functions exported by this file so that we can later allocate
919 entries in .opd for them. */
922 elf64_hppa_mark_exported_functions (struct elf_link_hash_entry
*eh
, void *data
)
924 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
925 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
926 struct elf64_hppa_link_hash_table
*hppa_info
;
928 hppa_info
= hppa_link_hash_table (info
);
929 if (hppa_info
== NULL
)
933 && (eh
->root
.type
== bfd_link_hash_defined
934 || eh
->root
.type
== bfd_link_hash_defweak
)
935 && eh
->root
.u
.def
.section
->output_section
!= NULL
936 && eh
->type
== STT_FUNC
)
938 if (! hppa_info
->opd_sec
939 && ! get_opd (hppa_info
->root
.dynobj
, info
, hppa_info
))
944 /* Put a flag here for output_symbol_hook. */
952 /* Allocate space for a DLT entry. */
955 allocate_global_data_dlt (struct elf_link_hash_entry
*eh
, void *data
)
957 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
958 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
962 if (bfd_link_pic (x
->info
))
964 /* Possibly add the symbol to the local dynamic symbol
965 table since we might need to create a dynamic relocation
967 if (eh
->dynindx
== -1 && eh
->type
!= STT_PARISC_MILLI
)
969 bfd
*owner
= eh
->root
.u
.def
.section
->owner
;
971 if (! (bfd_elf_link_record_local_dynamic_symbol
972 (x
->info
, owner
, hh
->sym_indx
)))
977 hh
->dlt_offset
= x
->ofs
;
978 x
->ofs
+= DLT_ENTRY_SIZE
;
983 /* Allocate space for a DLT.PLT entry. */
986 allocate_global_data_plt (struct elf_link_hash_entry
*eh
, void *data
)
988 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
989 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*) data
;
992 && elf64_hppa_dynamic_symbol_p (eh
, x
->info
)
993 && !((eh
->root
.type
== bfd_link_hash_defined
994 || eh
->root
.type
== bfd_link_hash_defweak
)
995 && eh
->root
.u
.def
.section
->output_section
!= NULL
))
997 hh
->plt_offset
= x
->ofs
;
998 x
->ofs
+= PLT_ENTRY_SIZE
;
999 if (hh
->plt_offset
< 0x2000)
1001 struct elf64_hppa_link_hash_table
*hppa_info
;
1003 hppa_info
= hppa_link_hash_table (x
->info
);
1004 if (hppa_info
== NULL
)
1007 hppa_info
->gp_offset
= hh
->plt_offset
;
1016 /* Allocate space for a STUB entry. */
1019 allocate_global_data_stub (struct elf_link_hash_entry
*eh
, void *data
)
1021 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
1022 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1025 && elf64_hppa_dynamic_symbol_p (eh
, x
->info
)
1026 && !((eh
->root
.type
== bfd_link_hash_defined
1027 || eh
->root
.type
== bfd_link_hash_defweak
)
1028 && eh
->root
.u
.def
.section
->output_section
!= NULL
))
1030 hh
->stub_offset
= x
->ofs
;
1031 x
->ofs
+= sizeof (plt_stub
);
1038 /* Allocate space for a FPTR entry. */
1041 allocate_global_data_opd (struct elf_link_hash_entry
*eh
, void *data
)
1043 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
1044 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1046 if (hh
&& hh
->want_opd
)
1048 /* We never need an opd entry for a symbol which is not
1049 defined by this output file. */
1050 if (hh
&& (hh
->eh
.root
.type
== bfd_link_hash_undefined
1051 || hh
->eh
.root
.type
== bfd_link_hash_undefweak
1052 || hh
->eh
.root
.u
.def
.section
->output_section
== NULL
))
1055 /* If we are creating a shared library, took the address of a local
1056 function or might export this function from this object file, then
1057 we have to create an opd descriptor. */
1058 else if (bfd_link_pic (x
->info
)
1060 || (hh
->eh
.dynindx
== -1 && hh
->eh
.type
!= STT_PARISC_MILLI
)
1061 || (hh
->eh
.root
.type
== bfd_link_hash_defined
1062 || hh
->eh
.root
.type
== bfd_link_hash_defweak
))
1064 /* If we are creating a shared library, then we will have to
1065 create a runtime relocation for the symbol to properly
1066 initialize the .opd entry. Make sure the symbol gets
1067 added to the dynamic symbol table. */
1068 if (bfd_link_pic (x
->info
)
1069 && (hh
== NULL
|| (hh
->eh
.dynindx
== -1)))
1072 /* PR 6511: Default to using the dynamic symbol table. */
1073 owner
= (hh
->owner
? hh
->owner
: eh
->root
.u
.def
.section
->owner
);
1075 if (!bfd_elf_link_record_local_dynamic_symbol
1076 (x
->info
, owner
, hh
->sym_indx
))
1080 /* This may not be necessary or desirable anymore now that
1081 we have some support for dealing with section symbols
1082 in dynamic relocs. But name munging does make the result
1083 much easier to debug. ie, the EPLT reloc will reference
1084 a symbol like .foobar, instead of .text + offset. */
1085 if (bfd_link_pic (x
->info
) && eh
)
1088 struct elf_link_hash_entry
*nh
;
1090 new_name
= concat (".", eh
->root
.root
.string
, NULL
);
1092 nh
= elf_link_hash_lookup (elf_hash_table (x
->info
),
1093 new_name
, true, true, true);
1096 nh
->root
.type
= eh
->root
.type
;
1097 nh
->root
.u
.def
.value
= eh
->root
.u
.def
.value
;
1098 nh
->root
.u
.def
.section
= eh
->root
.u
.def
.section
;
1100 if (! bfd_elf_link_record_dynamic_symbol (x
->info
, nh
))
1103 hh
->opd_offset
= x
->ofs
;
1104 x
->ofs
+= OPD_ENTRY_SIZE
;
1107 /* Otherwise we do not need an opd entry. */
1114 /* HP requires the EI_OSABI field to be filled in. The assignment to
1115 EI_ABIVERSION may not be strictly necessary. */
1118 elf64_hppa_init_file_header (bfd
*abfd
, struct bfd_link_info
*info
)
1120 Elf_Internal_Ehdr
*i_ehdrp
;
1122 if (!_bfd_elf_init_file_header (abfd
, info
))
1125 i_ehdrp
= elf_elfheader (abfd
);
1126 i_ehdrp
->e_ident
[EI_OSABI
] = get_elf_backend_data (abfd
)->elf_osabi
;
1127 i_ehdrp
->e_ident
[EI_ABIVERSION
] = 1;
1131 /* Create function descriptor section (.opd). This section is called .opd
1132 because it contains "official procedure descriptors". The "official"
1133 refers to the fact that these descriptors are used when taking the address
1134 of a procedure, thus ensuring a unique address for each procedure. */
1138 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1139 struct elf64_hppa_link_hash_table
*hppa_info
)
1144 opd
= hppa_info
->opd_sec
;
1147 dynobj
= hppa_info
->root
.dynobj
;
1149 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1151 opd
= bfd_make_section_anyway_with_flags (dynobj
, ".opd",
1156 | SEC_LINKER_CREATED
));
1158 || !bfd_set_section_alignment (opd
, 3))
1164 hppa_info
->opd_sec
= opd
;
1170 /* Create the PLT section. */
1174 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1175 struct elf64_hppa_link_hash_table
*hppa_info
)
1180 plt
= hppa_info
->root
.splt
;
1183 dynobj
= hppa_info
->root
.dynobj
;
1185 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1187 plt
= bfd_make_section_anyway_with_flags (dynobj
, ".plt",
1192 | SEC_LINKER_CREATED
));
1194 || !bfd_set_section_alignment (plt
, 3))
1200 hppa_info
->root
.splt
= plt
;
1206 /* Create the DLT section. */
1210 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1211 struct elf64_hppa_link_hash_table
*hppa_info
)
1216 dlt
= hppa_info
->dlt_sec
;
1219 dynobj
= hppa_info
->root
.dynobj
;
1221 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1223 dlt
= bfd_make_section_anyway_with_flags (dynobj
, ".dlt",
1228 | SEC_LINKER_CREATED
));
1230 || !bfd_set_section_alignment (dlt
, 3))
1236 hppa_info
->dlt_sec
= dlt
;
1242 /* Create the stubs section. */
1245 get_stub (bfd
*abfd
,
1246 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1247 struct elf64_hppa_link_hash_table
*hppa_info
)
1252 stub
= hppa_info
->stub_sec
;
1255 dynobj
= hppa_info
->root
.dynobj
;
1257 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1259 stub
= bfd_make_section_anyway_with_flags (dynobj
, ".stub",
1260 (SEC_ALLOC
| SEC_LOAD
1264 | SEC_LINKER_CREATED
));
1266 || !bfd_set_section_alignment (stub
, 3))
1272 hppa_info
->stub_sec
= stub
;
1278 /* Create sections necessary for dynamic linking. This is only a rough
1279 cut and will likely change as we learn more about the somewhat
1280 unusual dynamic linking scheme HP uses.
1283 Contains code to implement cross-space calls. The first time one
1284 of the stubs is used it will call into the dynamic linker, later
1285 calls will go straight to the target.
1287 The only stub we support right now looks like
1291 ldd OFFSET+8(%dp),%dp
1293 Other stubs may be needed in the future. We may want the remove
1294 the break/nop instruction. It is only used right now to keep the
1295 offset of a .plt entry and a .stub entry in sync.
1298 This is what most people call the .got. HP used a different name.
1302 Relocations for the DLT.
1305 Function pointers as address,gp pairs.
1308 Should contain dynamic IPLT (and EPLT?) relocations.
1314 EPLT relocations for symbols exported from shared libraries. */
1317 elf64_hppa_create_dynamic_sections (bfd
*abfd
,
1318 struct bfd_link_info
*info
)
1321 struct elf64_hppa_link_hash_table
*hppa_info
;
1323 hppa_info
= hppa_link_hash_table (info
);
1324 if (hppa_info
== NULL
)
1327 if (! get_stub (abfd
, info
, hppa_info
))
1330 if (! get_dlt (abfd
, info
, hppa_info
))
1333 if (! get_plt (abfd
, info
, hppa_info
))
1336 if (! get_opd (abfd
, info
, hppa_info
))
1339 s
= bfd_make_section_anyway_with_flags (abfd
, ".rela.dlt",
1340 (SEC_ALLOC
| SEC_LOAD
1344 | SEC_LINKER_CREATED
));
1346 || !bfd_set_section_alignment (s
, 3))
1348 hppa_info
->dlt_rel_sec
= s
;
1350 s
= bfd_make_section_anyway_with_flags (abfd
, ".rela.plt",
1351 (SEC_ALLOC
| SEC_LOAD
1355 | SEC_LINKER_CREATED
));
1357 || !bfd_set_section_alignment (s
, 3))
1359 hppa_info
->root
.srelplt
= s
;
1361 s
= bfd_make_section_anyway_with_flags (abfd
, ".rela.data",
1362 (SEC_ALLOC
| SEC_LOAD
1366 | SEC_LINKER_CREATED
));
1368 || !bfd_set_section_alignment (s
, 3))
1370 hppa_info
->other_rel_sec
= s
;
1372 s
= bfd_make_section_anyway_with_flags (abfd
, ".rela.opd",
1373 (SEC_ALLOC
| SEC_LOAD
1377 | SEC_LINKER_CREATED
));
1379 || !bfd_set_section_alignment (s
, 3))
1381 hppa_info
->opd_rel_sec
= s
;
1386 /* Allocate dynamic relocations for those symbols that turned out
1390 allocate_dynrel_entries (struct elf_link_hash_entry
*eh
, void *data
)
1392 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
1393 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1394 struct elf64_hppa_link_hash_table
*hppa_info
;
1395 struct elf64_hppa_dyn_reloc_entry
*rent
;
1396 bool dynamic_symbol
, shared
;
1398 hppa_info
= hppa_link_hash_table (x
->info
);
1399 if (hppa_info
== NULL
)
1402 dynamic_symbol
= elf64_hppa_dynamic_symbol_p (eh
, x
->info
);
1403 shared
= bfd_link_pic (x
->info
);
1405 /* We may need to allocate relocations for a non-dynamic symbol
1406 when creating a shared library. */
1407 if (!dynamic_symbol
&& !shared
)
1410 /* Take care of the normal data relocations. */
1412 for (rent
= hh
->reloc_entries
; rent
; rent
= rent
->next
)
1414 /* Allocate one iff we are building a shared library, the relocation
1415 isn't a R_PARISC_FPTR64, or we don't want an opd entry. */
1416 if (!shared
&& rent
->type
== R_PARISC_FPTR64
&& hh
->want_opd
)
1419 hppa_info
->other_rel_sec
->size
+= sizeof (Elf64_External_Rela
);
1421 /* Make sure this symbol gets into the dynamic symbol table if it is
1422 not already recorded. ?!? This should not be in the loop since
1423 the symbol need only be added once. */
1424 if (eh
->dynindx
== -1 && eh
->type
!= STT_PARISC_MILLI
)
1425 if (!bfd_elf_link_record_local_dynamic_symbol
1426 (x
->info
, rent
->sec
->owner
, hh
->sym_indx
))
1430 /* Take care of the GOT and PLT relocations. */
1432 if ((dynamic_symbol
|| shared
) && hh
->want_dlt
)
1433 hppa_info
->dlt_rel_sec
->size
+= sizeof (Elf64_External_Rela
);
1435 /* If we are building a shared library, then every symbol that has an
1436 opd entry will need an EPLT relocation to relocate the symbol's address
1437 and __gp value based on the runtime load address. */
1438 if (shared
&& hh
->want_opd
)
1439 hppa_info
->opd_rel_sec
->size
+= sizeof (Elf64_External_Rela
);
1441 if (hh
->want_plt
&& dynamic_symbol
)
1443 bfd_size_type t
= 0;
1445 /* Dynamic symbols get one IPLT relocation. Local symbols in
1446 shared libraries get two REL relocations. Local symbols in
1447 main applications get nothing. */
1449 t
= sizeof (Elf64_External_Rela
);
1451 t
= 2 * sizeof (Elf64_External_Rela
);
1453 hppa_info
->root
.srelplt
->size
+= t
;
1459 /* Adjust a symbol defined by a dynamic object and referenced by a
1463 elf64_hppa_adjust_dynamic_symbol (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1464 struct elf_link_hash_entry
*eh
)
1466 /* ??? Undefined symbols with PLT entries should be re-defined
1467 to be the PLT entry. */
1469 /* If this is a weak symbol, and there is a real definition, the
1470 processor independent code will have arranged for us to see the
1471 real definition first, and we can just use the same value. */
1472 if (eh
->is_weakalias
)
1474 struct elf_link_hash_entry
*def
= weakdef (eh
);
1475 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
1476 eh
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
1477 eh
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
1481 /* If this is a reference to a symbol defined by a dynamic object which
1482 is not a function, we might allocate the symbol in our .dynbss section
1483 and allocate a COPY dynamic relocation.
1485 But PA64 code is canonically PIC, so as a rule we can avoid this sort
1491 /* This function is called via elf_link_hash_traverse to mark millicode
1492 symbols with a dynindx of -1 and to remove the string table reference
1493 from the dynamic symbol table. If the symbol is not a millicode symbol,
1494 elf64_hppa_mark_exported_functions is called. */
1497 elf64_hppa_mark_milli_and_exported_functions (struct elf_link_hash_entry
*eh
,
1500 struct bfd_link_info
*info
= (struct bfd_link_info
*) data
;
1502 if (eh
->type
== STT_PARISC_MILLI
)
1504 if (eh
->dynindx
!= -1)
1507 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
1513 return elf64_hppa_mark_exported_functions (eh
, data
);
1516 /* Set the final sizes of the dynamic sections and allocate memory for
1517 the contents of our special sections. */
1520 elf64_hppa_late_size_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
1522 struct elf64_hppa_link_hash_table
*hppa_info
;
1523 struct elf64_hppa_allocate_data data
;
1529 hppa_info
= hppa_link_hash_table (info
);
1530 if (hppa_info
== NULL
)
1533 dynobj
= hppa_info
->root
.dynobj
;
1537 /* Mark each function this program exports so that we will allocate
1538 space in the .opd section for each function's FPTR. If we are
1539 creating dynamic sections, change the dynamic index of millicode
1540 symbols to -1 and remove them from the string table for .dynstr.
1542 We have to traverse the main linker hash table since we have to
1543 find functions which may not have been mentioned in any relocs. */
1544 elf_link_hash_traverse (&hppa_info
->root
,
1545 (hppa_info
->root
.dynamic_sections_created
1546 ? elf64_hppa_mark_milli_and_exported_functions
1547 : elf64_hppa_mark_exported_functions
),
1550 if (hppa_info
->root
.dynamic_sections_created
)
1552 /* Set the contents of the .interp section to the interpreter. */
1553 if (bfd_link_executable (info
) && !info
->nointerp
)
1555 sec
= bfd_get_linker_section (dynobj
, ".interp");
1556 BFD_ASSERT (sec
!= NULL
);
1557 sec
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1558 sec
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1563 /* We may have created entries in the .rela.got section.
1564 However, if we are not creating the dynamic sections, we will
1565 not actually use these entries. Reset the size of .rela.dlt,
1566 which will cause it to get stripped from the output file
1568 sec
= hppa_info
->dlt_rel_sec
;
1573 /* Set up DLT, PLT and OPD offsets for local syms, and space for local
1575 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
1577 bfd_signed_vma
*local_dlt
;
1578 bfd_signed_vma
*end_local_dlt
;
1579 bfd_signed_vma
*local_plt
;
1580 bfd_signed_vma
*end_local_plt
;
1581 bfd_signed_vma
*local_opd
;
1582 bfd_signed_vma
*end_local_opd
;
1583 bfd_size_type locsymcount
;
1584 Elf_Internal_Shdr
*symtab_hdr
;
1587 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
1590 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1592 struct elf64_hppa_dyn_reloc_entry
*hdh_p
;
1594 for (hdh_p
= ((struct elf64_hppa_dyn_reloc_entry
*)
1595 elf_section_data (sec
)->local_dynrel
);
1597 hdh_p
= hdh_p
->next
)
1599 if (!bfd_is_abs_section (hdh_p
->sec
)
1600 && bfd_is_abs_section (hdh_p
->sec
->output_section
))
1602 /* Input section has been discarded, either because
1603 it is a copy of a linkonce section or due to
1604 linker script /DISCARD/, so we'll be discarding
1607 else if (hdh_p
->count
!= 0)
1609 srel
= elf_section_data (hdh_p
->sec
)->sreloc
;
1610 srel
->size
+= hdh_p
->count
* sizeof (Elf64_External_Rela
);
1611 if ((hdh_p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
1612 info
->flags
|= DF_TEXTREL
;
1617 local_dlt
= elf_local_got_refcounts (ibfd
);
1621 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
1622 locsymcount
= symtab_hdr
->sh_info
;
1623 end_local_dlt
= local_dlt
+ locsymcount
;
1624 sec
= hppa_info
->dlt_sec
;
1625 srel
= hppa_info
->dlt_rel_sec
;
1626 for (; local_dlt
< end_local_dlt
; ++local_dlt
)
1630 *local_dlt
= sec
->size
;
1631 sec
->size
+= DLT_ENTRY_SIZE
;
1632 if (bfd_link_pic (info
))
1634 srel
->size
+= sizeof (Elf64_External_Rela
);
1638 *local_dlt
= (bfd_vma
) -1;
1641 local_plt
= end_local_dlt
;
1642 end_local_plt
= local_plt
+ locsymcount
;
1643 if (! hppa_info
->root
.dynamic_sections_created
)
1645 /* Won't be used, but be safe. */
1646 for (; local_plt
< end_local_plt
; ++local_plt
)
1647 *local_plt
= (bfd_vma
) -1;
1651 sec
= hppa_info
->root
.splt
;
1652 srel
= hppa_info
->root
.srelplt
;
1653 for (; local_plt
< end_local_plt
; ++local_plt
)
1657 *local_plt
= sec
->size
;
1658 sec
->size
+= PLT_ENTRY_SIZE
;
1659 if (bfd_link_pic (info
))
1660 srel
->size
+= sizeof (Elf64_External_Rela
);
1663 *local_plt
= (bfd_vma
) -1;
1667 local_opd
= end_local_plt
;
1668 end_local_opd
= local_opd
+ locsymcount
;
1669 if (! hppa_info
->root
.dynamic_sections_created
)
1671 /* Won't be used, but be safe. */
1672 for (; local_opd
< end_local_opd
; ++local_opd
)
1673 *local_opd
= (bfd_vma
) -1;
1677 sec
= hppa_info
->opd_sec
;
1678 srel
= hppa_info
->opd_rel_sec
;
1679 for (; local_opd
< end_local_opd
; ++local_opd
)
1683 *local_opd
= sec
->size
;
1684 sec
->size
+= OPD_ENTRY_SIZE
;
1685 if (bfd_link_pic (info
))
1686 srel
->size
+= sizeof (Elf64_External_Rela
);
1689 *local_opd
= (bfd_vma
) -1;
1694 /* Allocate the GOT entries. */
1697 if (hppa_info
->dlt_sec
)
1699 data
.ofs
= hppa_info
->dlt_sec
->size
;
1700 elf_link_hash_traverse (&hppa_info
->root
,
1701 allocate_global_data_dlt
, &data
);
1702 hppa_info
->dlt_sec
->size
= data
.ofs
;
1705 if (hppa_info
->root
.splt
)
1707 data
.ofs
= hppa_info
->root
.splt
->size
;
1708 elf_link_hash_traverse (&hppa_info
->root
,
1709 allocate_global_data_plt
, &data
);
1710 hppa_info
->root
.splt
->size
= data
.ofs
;
1713 if (hppa_info
->stub_sec
)
1716 elf_link_hash_traverse (&hppa_info
->root
,
1717 allocate_global_data_stub
, &data
);
1718 hppa_info
->stub_sec
->size
= data
.ofs
;
1721 /* Allocate space for entries in the .opd section. */
1722 if (hppa_info
->opd_sec
)
1724 data
.ofs
= hppa_info
->opd_sec
->size
;
1725 elf_link_hash_traverse (&hppa_info
->root
,
1726 allocate_global_data_opd
, &data
);
1727 hppa_info
->opd_sec
->size
= data
.ofs
;
1730 /* Now allocate space for dynamic relocations, if necessary. */
1731 if (hppa_info
->root
.dynamic_sections_created
)
1732 elf_link_hash_traverse (&hppa_info
->root
,
1733 allocate_dynrel_entries
, &data
);
1735 /* The sizes of all the sections are set. Allocate memory for them. */
1737 for (sec
= dynobj
->sections
; sec
!= NULL
; sec
= sec
->next
)
1741 if ((sec
->flags
& SEC_LINKER_CREATED
) == 0)
1744 /* It's OK to base decisions on the section name, because none
1745 of the dynobj section names depend upon the input files. */
1746 name
= bfd_section_name (sec
);
1748 if (strcmp (name
, ".plt") == 0)
1750 /* Remember whether there is a PLT. */
1753 else if (strcmp (name
, ".opd") == 0
1754 || startswith (name
, ".dlt")
1755 || strcmp (name
, ".stub") == 0
1756 || strcmp (name
, ".got") == 0)
1758 /* Strip this section if we don't need it; see the comment below. */
1760 else if (startswith (name
, ".rela"))
1764 /* Remember whether there are any reloc sections other
1766 if (strcmp (name
, ".rela.plt") != 0)
1769 /* We use the reloc_count field as a counter if we need
1770 to copy relocs into the output file. */
1771 sec
->reloc_count
= 0;
1776 /* It's not one of our sections, so don't allocate space. */
1782 /* If we don't need this section, strip it from the
1783 output file. This is mostly to handle .rela.bss and
1784 .rela.plt. We must create both sections in
1785 create_dynamic_sections, because they must be created
1786 before the linker maps input sections to output
1787 sections. The linker does that before
1788 adjust_dynamic_symbol is called, and it is that
1789 function which decides whether anything needs to go
1790 into these sections. */
1791 sec
->flags
|= SEC_EXCLUDE
;
1795 if ((sec
->flags
& SEC_HAS_CONTENTS
) == 0)
1798 /* Allocate memory for the section contents if it has not
1799 been allocated already. We use bfd_zalloc here in case
1800 unused entries are not reclaimed before the section's
1801 contents are written out. This should not happen, but this
1802 way if it does, we get a R_PARISC_NONE reloc instead of
1804 if (sec
->contents
== NULL
)
1806 sec
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, sec
->size
);
1807 if (sec
->contents
== NULL
)
1812 if (hppa_info
->root
.dynamic_sections_created
)
1814 /* Always create a DT_PLTGOT. It actually has nothing to do with
1815 the PLT, it is how we communicate the __gp value of a load
1816 module to the dynamic linker. */
1817 #define add_dynamic_entry(TAG, VAL) \
1818 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
1820 if (!add_dynamic_entry (DT_HP_DLD_FLAGS
, 0))
1823 /* Add some entries to the .dynamic section. We fill in the
1824 values later, in elf64_hppa_finish_dynamic_sections, but we
1825 must add the entries now so that we get the correct size for
1826 the .dynamic section. The DT_DEBUG entry is filled in by the
1827 dynamic linker and used by the debugger. */
1828 if (! bfd_link_pic (info
))
1830 if (!add_dynamic_entry (DT_HP_DLD_HOOK
, 0)
1831 || !add_dynamic_entry (DT_HP_LOAD_MAP
, 0))
1835 /* Force DT_FLAGS to always be set.
1836 Required by HPUX 11.00 patch PHSS_26559. */
1837 if (!add_dynamic_entry (DT_FLAGS
, (info
)->flags
))
1840 #undef add_dynamic_entry
1842 return _bfd_elf_add_dynamic_tags (output_bfd
, info
, relocs
);
1845 /* Called after we have output the symbol into the dynamic symbol
1846 table, but before we output the symbol into the normal symbol
1849 For some symbols we had to change their address when outputting
1850 the dynamic symbol table. We undo that change here so that
1851 the symbols have their expected value in the normal symbol
1855 elf64_hppa_link_output_symbol_hook (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1857 Elf_Internal_Sym
*sym
,
1858 asection
*input_sec ATTRIBUTE_UNUSED
,
1859 struct elf_link_hash_entry
*eh
)
1861 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
1863 /* We may be called with the file symbol or section symbols.
1864 They never need munging, so it is safe to ignore them. */
1868 /* Function symbols for which we created .opd entries *may* have been
1869 munged by finish_dynamic_symbol and have to be un-munged here.
1871 Note that finish_dynamic_symbol sometimes turns dynamic symbols
1872 into non-dynamic ones, so we initialize st_shndx to -1 in
1873 mark_exported_functions and check to see if it was overwritten
1874 here instead of just checking eh->dynindx. */
1875 if (hh
->want_opd
&& hh
->st_shndx
!= -1)
1877 /* Restore the saved value and section index. */
1878 sym
->st_value
= hh
->st_value
;
1879 sym
->st_shndx
= hh
->st_shndx
;
1885 /* Finish up dynamic symbol handling. We set the contents of various
1886 dynamic sections here. */
1889 elf64_hppa_finish_dynamic_symbol (bfd
*output_bfd
,
1890 struct bfd_link_info
*info
,
1891 struct elf_link_hash_entry
*eh
,
1892 Elf_Internal_Sym
*sym
)
1894 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
1895 asection
*stub
, *splt
, *sopd
, *spltrel
;
1896 struct elf64_hppa_link_hash_table
*hppa_info
;
1898 hppa_info
= hppa_link_hash_table (info
);
1900 stub
= hppa_info
->stub_sec
;
1901 splt
= hppa_info
->root
.splt
;
1902 sopd
= hppa_info
->opd_sec
;
1903 spltrel
= hppa_info
->root
.srelplt
;
1905 /* Incredible. It is actually necessary to NOT use the symbol's real
1906 value when building the dynamic symbol table for a shared library.
1907 At least for symbols that refer to functions.
1909 We will store a new value and section index into the symbol long
1910 enough to output it into the dynamic symbol table, then we restore
1911 the original values (in elf64_hppa_link_output_symbol_hook). */
1914 BFD_ASSERT (sopd
!= NULL
);
1916 /* Save away the original value and section index so that we
1917 can restore them later. */
1918 hh
->st_value
= sym
->st_value
;
1919 hh
->st_shndx
= sym
->st_shndx
;
1921 /* For the dynamic symbol table entry, we want the value to be
1922 address of this symbol's entry within the .opd section. */
1923 sym
->st_value
= (hh
->opd_offset
1924 + sopd
->output_offset
1925 + sopd
->output_section
->vma
);
1926 sym
->st_shndx
= _bfd_elf_section_from_bfd_section (output_bfd
,
1927 sopd
->output_section
);
1930 /* Initialize a .plt entry if requested. */
1932 && elf64_hppa_dynamic_symbol_p (eh
, info
))
1935 Elf_Internal_Rela rel
;
1938 BFD_ASSERT (splt
!= NULL
&& spltrel
!= NULL
);
1940 /* We do not actually care about the value in the PLT entry
1941 if we are creating a shared library and the symbol is
1942 still undefined, we create a dynamic relocation to fill
1943 in the correct value. */
1944 if (bfd_link_pic (info
) && eh
->root
.type
== bfd_link_hash_undefined
)
1947 value
= (eh
->root
.u
.def
.value
+ eh
->root
.u
.def
.section
->vma
);
1949 /* Fill in the entry in the procedure linkage table.
1951 The format of a plt entry is
1954 plt_offset is the offset within the PLT section at which to
1955 install the PLT entry.
1957 We are modifying the in-memory PLT contents here, so we do not add
1958 in the output_offset of the PLT section. */
1960 bfd_put_64 (splt
->owner
, value
, splt
->contents
+ hh
->plt_offset
);
1961 value
= _bfd_get_gp_value (info
->output_bfd
);
1962 bfd_put_64 (splt
->owner
, value
, splt
->contents
+ hh
->plt_offset
+ 0x8);
1964 /* Create a dynamic IPLT relocation for this entry.
1966 We are creating a relocation in the output file's PLT section,
1967 which is included within the DLT secton. So we do need to include
1968 the PLT's output_offset in the computation of the relocation's
1970 rel
.r_offset
= (hh
->plt_offset
+ splt
->output_offset
1971 + splt
->output_section
->vma
);
1972 rel
.r_info
= ELF64_R_INFO (hh
->eh
.dynindx
, R_PARISC_IPLT
);
1975 loc
= spltrel
->contents
;
1976 loc
+= spltrel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
1977 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rel
, loc
);
1980 /* Initialize an external call stub entry if requested. */
1982 && elf64_hppa_dynamic_symbol_p (eh
, info
))
1986 unsigned int max_offset
;
1988 BFD_ASSERT (stub
!= NULL
);
1990 /* Install the generic stub template.
1992 We are modifying the contents of the stub section, so we do not
1993 need to include the stub section's output_offset here. */
1994 memcpy (stub
->contents
+ hh
->stub_offset
, plt_stub
, sizeof (plt_stub
));
1996 /* Fix up the first ldd instruction.
1998 We are modifying the contents of the STUB section in memory,
1999 so we do not need to include its output offset in this computation.
2001 Note the plt_offset value is the value of the PLT entry relative to
2002 the start of the PLT section. These instructions will reference
2003 data relative to the value of __gp, which may not necessarily have
2004 the same address as the start of the PLT section.
2006 gp_offset contains the offset of __gp within the PLT section. */
2007 value
= hh
->plt_offset
- hppa_info
->gp_offset
;
2009 insn
= bfd_get_32 (stub
->owner
, stub
->contents
+ hh
->stub_offset
);
2010 if (output_bfd
->arch_info
->mach
>= 25)
2012 /* Wide mode allows 16 bit offsets. */
2015 insn
|= re_assemble_16 ((int) value
);
2021 insn
|= re_assemble_14 ((int) value
);
2024 if ((value
& 7) || value
+ max_offset
>= 2*max_offset
- 8)
2027 /* xgettext:c-format */
2028 (_("stub entry for %s cannot load .plt, dp offset = %" PRId64
),
2029 hh
->eh
.root
.root
.string
, (int64_t) value
);
2033 bfd_put_32 (stub
->owner
, (bfd_vma
) insn
,
2034 stub
->contents
+ hh
->stub_offset
);
2036 /* Fix up the second ldd instruction. */
2038 insn
= bfd_get_32 (stub
->owner
, stub
->contents
+ hh
->stub_offset
+ 8);
2039 if (output_bfd
->arch_info
->mach
>= 25)
2042 insn
|= re_assemble_16 ((int) value
);
2047 insn
|= re_assemble_14 ((int) value
);
2049 bfd_put_32 (stub
->owner
, (bfd_vma
) insn
,
2050 stub
->contents
+ hh
->stub_offset
+ 8);
2056 /* The .opd section contains FPTRs for each function this file
2057 exports. Initialize the FPTR entries. */
2060 elf64_hppa_finalize_opd (struct elf_link_hash_entry
*eh
, void *data
)
2062 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
2063 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
2064 struct elf64_hppa_link_hash_table
*hppa_info
;
2068 hppa_info
= hppa_link_hash_table (info
);
2069 if (hppa_info
== NULL
)
2072 sopd
= hppa_info
->opd_sec
;
2073 sopdrel
= hppa_info
->opd_rel_sec
;
2079 /* The first two words of an .opd entry are zero.
2081 We are modifying the contents of the OPD section in memory, so we
2082 do not need to include its output offset in this computation. */
2083 memset (sopd
->contents
+ hh
->opd_offset
, 0, 16);
2085 value
= (eh
->root
.u
.def
.value
2086 + eh
->root
.u
.def
.section
->output_section
->vma
2087 + eh
->root
.u
.def
.section
->output_offset
);
2089 /* The next word is the address of the function. */
2090 bfd_put_64 (sopd
->owner
, value
, sopd
->contents
+ hh
->opd_offset
+ 16);
2092 /* The last word is our local __gp value. */
2093 value
= _bfd_get_gp_value (info
->output_bfd
);
2094 bfd_put_64 (sopd
->owner
, value
, sopd
->contents
+ hh
->opd_offset
+ 24);
2097 /* If we are generating a shared library, we must generate EPLT relocations
2098 for each entry in the .opd, even for static functions (they may have
2099 had their address taken). */
2100 if (bfd_link_pic (info
) && hh
->want_opd
)
2102 Elf_Internal_Rela rel
;
2106 /* We may need to do a relocation against a local symbol, in
2107 which case we have to look up it's dynamic symbol index off
2108 the local symbol hash table. */
2109 if (eh
->dynindx
!= -1)
2110 dynindx
= eh
->dynindx
;
2113 = _bfd_elf_link_lookup_local_dynindx (info
, hh
->owner
,
2116 /* The offset of this relocation is the absolute address of the
2117 .opd entry for this symbol. */
2118 rel
.r_offset
= (hh
->opd_offset
+ sopd
->output_offset
2119 + sopd
->output_section
->vma
);
2121 /* If H is non-null, then we have an external symbol.
2123 It is imperative that we use a different dynamic symbol for the
2124 EPLT relocation if the symbol has global scope.
2126 In the dynamic symbol table, the function symbol will have a value
2127 which is address of the function's .opd entry.
2129 Thus, we can not use that dynamic symbol for the EPLT relocation
2130 (if we did, the data in the .opd would reference itself rather
2131 than the actual address of the function). Instead we have to use
2132 a new dynamic symbol which has the same value as the original global
2135 We prefix the original symbol with a "." and use the new symbol in
2136 the EPLT relocation. This new symbol has already been recorded in
2137 the symbol table, we just have to look it up and use it.
2139 We do not have such problems with static functions because we do
2140 not make their addresses in the dynamic symbol table point to
2141 the .opd entry. Ultimately this should be safe since a static
2142 function can not be directly referenced outside of its shared
2145 We do have to play similar games for FPTR relocations in shared
2146 libraries, including those for static symbols. See the FPTR
2147 handling in elf64_hppa_finalize_dynreloc. */
2151 struct elf_link_hash_entry
*nh
;
2153 new_name
= concat (".", eh
->root
.root
.string
, NULL
);
2155 nh
= elf_link_hash_lookup (elf_hash_table (info
),
2156 new_name
, true, true, false);
2158 /* All we really want from the new symbol is its dynamic
2161 dynindx
= nh
->dynindx
;
2166 rel
.r_info
= ELF64_R_INFO (dynindx
, R_PARISC_EPLT
);
2168 loc
= sopdrel
->contents
;
2169 loc
+= sopdrel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2170 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rel
, loc
);
2175 /* The .dlt section contains addresses for items referenced through the
2176 dlt. Note that we can have a DLTIND relocation for a local symbol, thus
2177 we can not depend on finish_dynamic_symbol to initialize the .dlt. */
2180 elf64_hppa_finalize_dlt (struct elf_link_hash_entry
*eh
, void *data
)
2182 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
2183 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
2184 struct elf64_hppa_link_hash_table
*hppa_info
;
2185 asection
*sdlt
, *sdltrel
;
2187 hppa_info
= hppa_link_hash_table (info
);
2188 if (hppa_info
== NULL
)
2191 sdlt
= hppa_info
->dlt_sec
;
2192 sdltrel
= hppa_info
->dlt_rel_sec
;
2194 /* H/DYN_H may refer to a local variable and we know it's
2195 address, so there is no need to create a relocation. Just install
2196 the proper value into the DLT, note this shortcut can not be
2197 skipped when building a shared library. */
2198 if (! bfd_link_pic (info
) && hh
&& hh
->want_dlt
)
2202 /* If we had an LTOFF_FPTR style relocation we want the DLT entry
2203 to point to the FPTR entry in the .opd section.
2205 We include the OPD's output offset in this computation as
2206 we are referring to an absolute address in the resulting
2210 value
= (hh
->opd_offset
2211 + hppa_info
->opd_sec
->output_offset
2212 + hppa_info
->opd_sec
->output_section
->vma
);
2214 else if ((eh
->root
.type
== bfd_link_hash_defined
2215 || eh
->root
.type
== bfd_link_hash_defweak
)
2216 && eh
->root
.u
.def
.section
)
2218 value
= eh
->root
.u
.def
.value
+ eh
->root
.u
.def
.section
->output_offset
;
2219 if (eh
->root
.u
.def
.section
->output_section
)
2220 value
+= eh
->root
.u
.def
.section
->output_section
->vma
;
2222 value
+= eh
->root
.u
.def
.section
->vma
;
2225 /* We have an undefined function reference. */
2228 /* We do not need to include the output offset of the DLT section
2229 here because we are modifying the in-memory contents. */
2230 bfd_put_64 (sdlt
->owner
, value
, sdlt
->contents
+ hh
->dlt_offset
);
2233 /* Create a relocation for the DLT entry associated with this symbol.
2234 When building a shared library the symbol does not have to be dynamic. */
2236 && (elf64_hppa_dynamic_symbol_p (eh
, info
) || bfd_link_pic (info
)))
2238 Elf_Internal_Rela rel
;
2242 /* We may need to do a relocation against a local symbol, in
2243 which case we have to look up it's dynamic symbol index off
2244 the local symbol hash table. */
2245 if (eh
&& eh
->dynindx
!= -1)
2246 dynindx
= eh
->dynindx
;
2249 = _bfd_elf_link_lookup_local_dynindx (info
, hh
->owner
,
2252 /* Create a dynamic relocation for this entry. Do include the output
2253 offset of the DLT entry since we need an absolute address in the
2254 resulting object file. */
2255 rel
.r_offset
= (hh
->dlt_offset
+ sdlt
->output_offset
2256 + sdlt
->output_section
->vma
);
2257 if (eh
&& eh
->type
== STT_FUNC
)
2258 rel
.r_info
= ELF64_R_INFO (dynindx
, R_PARISC_FPTR64
);
2260 rel
.r_info
= ELF64_R_INFO (dynindx
, R_PARISC_DIR64
);
2263 loc
= sdltrel
->contents
;
2264 loc
+= sdltrel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2265 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rel
, loc
);
2270 /* Finalize the dynamic relocations. Specifically the FPTR relocations
2271 for dynamic functions used to initialize static data. */
2274 elf64_hppa_finalize_dynreloc (struct elf_link_hash_entry
*eh
,
2277 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
2278 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
2279 struct elf64_hppa_link_hash_table
*hppa_info
;
2282 dynamic_symbol
= elf64_hppa_dynamic_symbol_p (eh
, info
);
2284 if (!dynamic_symbol
&& !bfd_link_pic (info
))
2287 if (hh
->reloc_entries
)
2289 struct elf64_hppa_dyn_reloc_entry
*rent
;
2292 hppa_info
= hppa_link_hash_table (info
);
2293 if (hppa_info
== NULL
)
2296 /* We may need to do a relocation against a local symbol, in
2297 which case we have to look up it's dynamic symbol index off
2298 the local symbol hash table. */
2299 if (eh
->dynindx
!= -1)
2300 dynindx
= eh
->dynindx
;
2303 = _bfd_elf_link_lookup_local_dynindx (info
, hh
->owner
,
2306 for (rent
= hh
->reloc_entries
; rent
; rent
= rent
->next
)
2308 Elf_Internal_Rela rel
;
2311 /* Allocate one iff we are building a shared library, the relocation
2312 isn't a R_PARISC_FPTR64, or we don't want an opd entry. */
2313 if (!bfd_link_pic (info
)
2314 && rent
->type
== R_PARISC_FPTR64
&& hh
->want_opd
)
2317 /* Create a dynamic relocation for this entry.
2319 We need the output offset for the reloc's section because
2320 we are creating an absolute address in the resulting object
2322 rel
.r_offset
= (rent
->offset
+ rent
->sec
->output_offset
2323 + rent
->sec
->output_section
->vma
);
2325 /* An FPTR64 relocation implies that we took the address of
2326 a function and that the function has an entry in the .opd
2327 section. We want the FPTR64 relocation to reference the
2330 We could munge the symbol value in the dynamic symbol table
2331 (in fact we already do for functions with global scope) to point
2332 to the .opd entry. Then we could use that dynamic symbol in
2335 Or we could do something sensible, not munge the symbol's
2336 address and instead just use a different symbol to reference
2337 the .opd entry. At least that seems sensible until you
2338 realize there's no local dynamic symbols we can use for that
2339 purpose. Thus the hair in the check_relocs routine.
2341 We use a section symbol recorded by check_relocs as the
2342 base symbol for the relocation. The addend is the difference
2343 between the section symbol and the address of the .opd entry. */
2344 if (bfd_link_pic (info
)
2345 && rent
->type
== R_PARISC_FPTR64
&& hh
->want_opd
)
2347 bfd_vma value
, value2
;
2349 /* First compute the address of the opd entry for this symbol. */
2350 value
= (hh
->opd_offset
2351 + hppa_info
->opd_sec
->output_section
->vma
2352 + hppa_info
->opd_sec
->output_offset
);
2354 /* Compute the value of the start of the section with
2356 value2
= (rent
->sec
->output_section
->vma
2357 + rent
->sec
->output_offset
);
2359 /* Compute the difference between the start of the section
2360 with the relocation and the opd entry. */
2363 /* The result becomes the addend of the relocation. */
2364 rel
.r_addend
= value
;
2366 /* The section symbol becomes the symbol for the dynamic
2369 = _bfd_elf_link_lookup_local_dynindx (info
,
2374 rel
.r_addend
= rent
->addend
;
2376 rel
.r_info
= ELF64_R_INFO (dynindx
, rent
->type
);
2378 loc
= hppa_info
->other_rel_sec
->contents
;
2379 loc
+= (hppa_info
->other_rel_sec
->reloc_count
++
2380 * sizeof (Elf64_External_Rela
));
2381 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rel
, loc
);
2388 /* Used to decide how to sort relocs in an optimal manner for the
2389 dynamic linker, before writing them out. */
2391 static enum elf_reloc_type_class
2392 elf64_hppa_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2393 const asection
*rel_sec ATTRIBUTE_UNUSED
,
2394 const Elf_Internal_Rela
*rela
)
2396 if (ELF64_R_SYM (rela
->r_info
) == STN_UNDEF
)
2397 return reloc_class_relative
;
2399 switch ((int) ELF64_R_TYPE (rela
->r_info
))
2402 return reloc_class_plt
;
2404 return reloc_class_copy
;
2406 return reloc_class_normal
;
2410 /* Finish up the dynamic sections. */
2413 elf64_hppa_finish_dynamic_sections (bfd
*output_bfd
,
2414 struct bfd_link_info
*info
)
2418 struct elf64_hppa_link_hash_table
*hppa_info
;
2420 hppa_info
= hppa_link_hash_table (info
);
2421 if (hppa_info
== NULL
)
2424 /* Finalize the contents of the .opd section. */
2425 elf_link_hash_traverse (elf_hash_table (info
),
2426 elf64_hppa_finalize_opd
,
2429 elf_link_hash_traverse (elf_hash_table (info
),
2430 elf64_hppa_finalize_dynreloc
,
2433 /* Finalize the contents of the .dlt section. */
2434 dynobj
= elf_hash_table (info
)->dynobj
;
2435 /* Finalize the contents of the .dlt section. */
2436 elf_link_hash_traverse (elf_hash_table (info
),
2437 elf64_hppa_finalize_dlt
,
2440 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
2442 if (elf_hash_table (info
)->dynamic_sections_created
)
2444 Elf64_External_Dyn
*dyncon
, *dynconend
;
2446 BFD_ASSERT (sdyn
!= NULL
);
2448 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
2449 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
2450 for (; dyncon
< dynconend
; dyncon
++)
2452 Elf_Internal_Dyn dyn
;
2455 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2462 case DT_HP_LOAD_MAP
:
2463 /* Compute the absolute address of 16byte scratchpad area
2464 for the dynamic linker.
2466 By convention the linker script will allocate the scratchpad
2467 area at the start of the .data section. So all we have to
2468 to is find the start of the .data section. */
2469 s
= bfd_get_section_by_name (output_bfd
, ".data");
2472 dyn
.d_un
.d_ptr
= s
->vma
;
2473 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2477 /* HP's use PLTGOT to set the GOT register. */
2478 dyn
.d_un
.d_ptr
= _bfd_get_gp_value (output_bfd
);
2479 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2483 s
= hppa_info
->root
.srelplt
;
2484 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
2485 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2489 s
= hppa_info
->root
.srelplt
;
2490 dyn
.d_un
.d_val
= s
->size
;
2491 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2495 s
= hppa_info
->other_rel_sec
;
2496 if (! s
|| ! s
->size
)
2497 s
= hppa_info
->dlt_rel_sec
;
2498 if (! s
|| ! s
->size
)
2499 s
= hppa_info
->opd_rel_sec
;
2500 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
2501 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2505 s
= hppa_info
->other_rel_sec
;
2506 dyn
.d_un
.d_val
= s
->size
;
2507 s
= hppa_info
->dlt_rel_sec
;
2508 dyn
.d_un
.d_val
+= s
->size
;
2509 s
= hppa_info
->opd_rel_sec
;
2510 dyn
.d_un
.d_val
+= s
->size
;
2511 /* There is some question about whether or not the size of
2512 the PLT relocs should be included here. HP's tools do
2513 it, so we'll emulate them. */
2514 s
= hppa_info
->root
.srelplt
;
2515 dyn
.d_un
.d_val
+= s
->size
;
2516 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2526 /* Support for core dump NOTE sections. */
2529 elf64_hppa_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
2534 switch (note
->descsz
)
2539 case 760: /* Linux/hppa */
2541 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
2544 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
2553 /* Make a ".reg/999" section. */
2554 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
2555 size
, note
->descpos
+ offset
);
2559 elf64_hppa_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
2564 switch (note
->descsz
)
2569 case 136: /* Linux/hppa elf_prpsinfo. */
2570 elf_tdata (abfd
)->core
->program
2571 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
2572 elf_tdata (abfd
)->core
->command
2573 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
2576 /* Note that for some reason, a spurious space is tacked
2577 onto the end of the args in some (at least one anyway)
2578 implementations, so strip it off if it exists. */
2579 command
= elf_tdata (abfd
)->core
->command
;
2580 n
= strlen (command
);
2582 if (0 < n
&& command
[n
- 1] == ' ')
2583 command
[n
- 1] = '\0';
2588 /* Return the number of additional phdrs we will need.
2590 The generic ELF code only creates PT_PHDRs for executables. The HP
2591 dynamic linker requires PT_PHDRs for dynamic libraries too.
2593 This routine indicates that the backend needs one additional program
2594 header for that case.
2596 Note we do not have access to the link info structure here, so we have
2597 to guess whether or not we are building a shared library based on the
2598 existence of a .interp section. */
2601 elf64_hppa_additional_program_headers (bfd
*abfd
,
2602 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2606 /* If we are creating a shared library, then we have to create a
2607 PT_PHDR segment. HP's dynamic linker chokes without it. */
2608 s
= bfd_get_section_by_name (abfd
, ".interp");
2615 elf64_hppa_allow_non_load_phdr (bfd
*abfd ATTRIBUTE_UNUSED
,
2616 const Elf_Internal_Phdr
*phdr ATTRIBUTE_UNUSED
,
2617 unsigned int count ATTRIBUTE_UNUSED
)
2622 /* Allocate and initialize any program headers required by this
2625 The generic ELF code only creates PT_PHDRs for executables. The HP
2626 dynamic linker requires PT_PHDRs for dynamic libraries too.
2628 This allocates the PT_PHDR and initializes it in a manner suitable
2631 Note we do not have access to the link info structure here, so we have
2632 to guess whether or not we are building a shared library based on the
2633 existence of a .interp section. */
2636 elf64_hppa_modify_segment_map (bfd
*abfd
, struct bfd_link_info
*info
)
2638 struct elf_segment_map
*m
;
2640 m
= elf_seg_map (abfd
);
2641 if (info
!= NULL
&& !info
->user_phdrs
&& m
!= NULL
&& m
->p_type
!= PT_PHDR
)
2643 m
= ((struct elf_segment_map
*)
2644 bfd_zalloc (abfd
, (bfd_size_type
) sizeof *m
));
2648 m
->p_type
= PT_PHDR
;
2649 m
->p_flags
= PF_R
| PF_X
;
2650 m
->p_flags_valid
= 1;
2651 m
->p_paddr_valid
= 1;
2652 m
->includes_phdrs
= 1;
2654 m
->next
= elf_seg_map (abfd
);
2655 elf_seg_map (abfd
) = m
;
2658 for (m
= elf_seg_map (abfd
) ; m
!= NULL
; m
= m
->next
)
2659 if (m
->p_type
== PT_LOAD
)
2663 for (i
= 0; i
< m
->count
; i
++)
2665 /* The code "hint" is not really a hint. It is a requirement
2666 for certain versions of the HP dynamic linker. Worse yet,
2667 it must be set even if the shared library does not have
2668 any code in its "text" segment (thus the check for .hash
2669 to catch this situation). */
2670 if (m
->sections
[i
]->flags
& SEC_CODE
2671 || (strcmp (m
->sections
[i
]->name
, ".hash") == 0))
2672 m
->p_flags
|= (PF_X
| PF_HP_CODE
);
2679 /* Called when writing out an object file to decide the type of a
2682 elf64_hppa_elf_get_symbol_type (Elf_Internal_Sym
*elf_sym
,
2685 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_PARISC_MILLI
)
2686 return STT_PARISC_MILLI
;
2691 /* Support HP specific sections for core files. */
2694 elf64_hppa_section_from_phdr (bfd
*abfd
, Elf_Internal_Phdr
*hdr
, int sec_index
,
2695 const char *typename
)
2697 if (hdr
->p_type
== PT_HP_CORE_KERNEL
)
2701 if (!_bfd_elf_make_section_from_phdr (abfd
, hdr
, sec_index
, typename
))
2704 sect
= bfd_make_section_anyway (abfd
, ".kernel");
2707 sect
->size
= hdr
->p_filesz
;
2708 sect
->filepos
= hdr
->p_offset
;
2709 sect
->flags
= SEC_HAS_CONTENTS
| SEC_READONLY
;
2713 if (hdr
->p_type
== PT_HP_CORE_PROC
)
2717 if (bfd_seek (abfd
, hdr
->p_offset
, SEEK_SET
) != 0)
2719 if (bfd_read (&sig
, 4, abfd
) != 4)
2722 elf_tdata (abfd
)->core
->signal
= sig
;
2724 if (!_bfd_elf_make_section_from_phdr (abfd
, hdr
, sec_index
, typename
))
2727 /* GDB uses the ".reg" section to read register contents. */
2728 return _bfd_elfcore_make_pseudosection (abfd
, ".reg", hdr
->p_filesz
,
2732 if (hdr
->p_type
== PT_HP_CORE_LOADABLE
2733 || hdr
->p_type
== PT_HP_CORE_STACK
2734 || hdr
->p_type
== PT_HP_CORE_MMF
)
2735 hdr
->p_type
= PT_LOAD
;
2737 return _bfd_elf_make_section_from_phdr (abfd
, hdr
, sec_index
, typename
);
2740 /* Hook called by the linker routine which adds symbols from an object
2741 file. HP's libraries define symbols with HP specific section
2742 indices, which we have to handle. */
2745 elf_hppa_add_symbol_hook (bfd
*abfd
,
2746 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2747 Elf_Internal_Sym
*sym
,
2748 const char **namep ATTRIBUTE_UNUSED
,
2749 flagword
*flagsp ATTRIBUTE_UNUSED
,
2753 unsigned int sec_index
= sym
->st_shndx
;
2757 case SHN_PARISC_ANSI_COMMON
:
2758 *secp
= bfd_make_section_old_way (abfd
, ".PARISC.ansi.common");
2759 (*secp
)->flags
|= SEC_IS_COMMON
;
2760 *valp
= sym
->st_size
;
2763 case SHN_PARISC_HUGE_COMMON
:
2764 *secp
= bfd_make_section_old_way (abfd
, ".PARISC.huge.common");
2765 (*secp
)->flags
|= SEC_IS_COMMON
;
2766 *valp
= sym
->st_size
;
2774 elf_hppa_unmark_useless_dynamic_symbols (struct elf_link_hash_entry
*h
,
2777 struct bfd_link_info
*info
= data
;
2779 /* If we are not creating a shared library, and this symbol is
2780 referenced by a shared library but is not defined anywhere, then
2781 the generic code will warn that it is undefined.
2783 This behavior is undesirable on HPs since the standard shared
2784 libraries contain references to undefined symbols.
2786 So we twiddle the flags associated with such symbols so that they
2787 will not trigger the warning. ?!? FIXME. This is horribly fragile.
2789 Ultimately we should have better controls over the generic ELF BFD
2791 if (! bfd_link_relocatable (info
)
2792 && info
->unresolved_syms_in_shared_libs
!= RM_IGNORE
2793 && h
->root
.type
== bfd_link_hash_undefined
2798 h
->pointer_equality_needed
= 1;
2805 elf_hppa_remark_useless_dynamic_symbols (struct elf_link_hash_entry
*h
,
2808 struct bfd_link_info
*info
= data
;
2810 /* If we are not creating a shared library, and this symbol is
2811 referenced by a shared library but is not defined anywhere, then
2812 the generic code will warn that it is undefined.
2814 This behavior is undesirable on HPs since the standard shared
2815 libraries contain references to undefined symbols.
2817 So we twiddle the flags associated with such symbols so that they
2818 will not trigger the warning. ?!? FIXME. This is horribly fragile.
2820 Ultimately we should have better controls over the generic ELF BFD
2822 if (! bfd_link_relocatable (info
)
2823 && info
->unresolved_syms_in_shared_libs
!= RM_IGNORE
2824 && h
->root
.type
== bfd_link_hash_undefined
2827 && h
->pointer_equality_needed
)
2830 h
->pointer_equality_needed
= 0;
2837 elf_hppa_is_dynamic_loader_symbol (const char *name
)
2839 return (! strcmp (name
, "__CPU_REVISION")
2840 || ! strcmp (name
, "__CPU_KEYBITS_1")
2841 || ! strcmp (name
, "__SYSTEM_ID_D")
2842 || ! strcmp (name
, "__FPU_MODEL")
2843 || ! strcmp (name
, "__FPU_REVISION")
2844 || ! strcmp (name
, "__ARGC")
2845 || ! strcmp (name
, "__ARGV")
2846 || ! strcmp (name
, "__ENVP")
2847 || ! strcmp (name
, "__TLS_SIZE_D")
2848 || ! strcmp (name
, "__LOAD_INFO")
2849 || ! strcmp (name
, "__systab"));
2852 /* Record the lowest address for the data and text segments. */
2854 elf_hppa_record_segment_addrs (bfd
*abfd
,
2858 struct elf64_hppa_link_hash_table
*hppa_info
= data
;
2860 if ((section
->flags
& (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
2863 Elf_Internal_Phdr
*p
;
2865 p
= _bfd_elf_find_segment_containing_section (abfd
, section
->output_section
);
2866 BFD_ASSERT (p
!= NULL
);
2869 if (section
->flags
& SEC_READONLY
)
2871 if (value
< hppa_info
->text_segment_base
)
2872 hppa_info
->text_segment_base
= value
;
2876 if (value
< hppa_info
->data_segment_base
)
2877 hppa_info
->data_segment_base
= value
;
2882 /* Called after we have seen all the input files/sections, but before
2883 final symbol resolution and section placement has been determined.
2885 We use this hook to (possibly) provide a value for __gp, then we
2886 fall back to the generic ELF final link routine. */
2889 elf_hppa_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
2892 struct elf64_hppa_link_hash_table
*hppa_info
= hppa_link_hash_table (info
);
2894 if (hppa_info
== NULL
)
2897 if (! bfd_link_relocatable (info
))
2899 struct elf_link_hash_entry
*gp
;
2902 /* The linker script defines a value for __gp iff it was referenced
2903 by one of the objects being linked. First try to find the symbol
2904 in the hash table. If that fails, just compute the value __gp
2906 gp
= elf_link_hash_lookup (elf_hash_table (info
), "__gp", false,
2912 /* Adjust the value of __gp as we may want to slide it into the
2913 .plt section so that the stubs can access PLT entries without
2914 using an addil sequence. */
2915 gp
->root
.u
.def
.value
+= hppa_info
->gp_offset
;
2917 gp_val
= (gp
->root
.u
.def
.section
->output_section
->vma
2918 + gp
->root
.u
.def
.section
->output_offset
2919 + gp
->root
.u
.def
.value
);
2925 /* First look for a .plt section. If found, then __gp is the
2926 address of the .plt + gp_offset.
2928 If no .plt is found, then look for .dlt, .opd and .data (in
2929 that order) and set __gp to the base address of whichever
2930 section is found first. */
2932 sec
= hppa_info
->root
.splt
;
2933 if (sec
&& ! (sec
->flags
& SEC_EXCLUDE
))
2934 gp_val
= (sec
->output_offset
2935 + sec
->output_section
->vma
2936 + hppa_info
->gp_offset
);
2939 sec
= hppa_info
->dlt_sec
;
2940 if (!sec
|| (sec
->flags
& SEC_EXCLUDE
))
2941 sec
= hppa_info
->opd_sec
;
2942 if (!sec
|| (sec
->flags
& SEC_EXCLUDE
))
2943 sec
= bfd_get_section_by_name (abfd
, ".data");
2944 if (!sec
|| (sec
->flags
& SEC_EXCLUDE
))
2947 gp_val
= sec
->output_offset
+ sec
->output_section
->vma
;
2951 /* Install whatever value we found/computed for __gp. */
2952 _bfd_set_gp_value (abfd
, gp_val
);
2955 /* We need to know the base of the text and data segments so that we
2956 can perform SEGREL relocations. We will record the base addresses
2957 when we encounter the first SEGREL relocation. */
2958 hppa_info
->text_segment_base
= (bfd_vma
)-1;
2959 hppa_info
->data_segment_base
= (bfd_vma
)-1;
2961 /* HP's shared libraries have references to symbols that are not
2962 defined anywhere. The generic ELF BFD linker code will complain
2965 So we detect the losing case and arrange for the flags on the symbol
2966 to indicate that it was never referenced. This keeps the generic
2967 ELF BFD link code happy and appears to not create any secondary
2968 problems. Ultimately we need a way to control the behavior of the
2969 generic ELF BFD link code better. */
2970 elf_link_hash_traverse (elf_hash_table (info
),
2971 elf_hppa_unmark_useless_dynamic_symbols
,
2974 /* Invoke the regular ELF backend linker to do all the work. */
2975 if (!bfd_elf_final_link (abfd
, info
))
2978 elf_link_hash_traverse (elf_hash_table (info
),
2979 elf_hppa_remark_useless_dynamic_symbols
,
2982 /* If we're producing a final executable, sort the contents of the
2984 if (bfd_link_relocatable (info
))
2987 /* Do not attempt to sort non-regular files. This is here
2988 especially for configure scripts and kernel builds which run
2989 tests with "ld [...] -o /dev/null". */
2990 if (stat (bfd_get_filename (abfd
), &buf
) != 0
2991 || !S_ISREG(buf
.st_mode
))
2994 return elf_hppa_sort_unwind (abfd
);
2997 /* Relocate the given INSN. VALUE should be the actual value we want
2998 to insert into the instruction, ie by this point we should not be
2999 concerned with computing an offset relative to the DLT, PC, etc.
3000 Instead this routine is meant to handle the bit manipulations needed
3001 to insert the relocation into the given instruction. */
3004 elf_hppa_relocate_insn (int insn
, int sym_value
, unsigned int r_type
)
3008 /* This is any 22 bit branch. In PA2.0 syntax it corresponds to
3009 the "B" instruction. */
3010 case R_PARISC_PCREL22F
:
3011 case R_PARISC_PCREL22C
:
3012 return (insn
& ~0x3ff1ffd) | re_assemble_22 (sym_value
);
3014 /* This is any 12 bit branch. */
3015 case R_PARISC_PCREL12F
:
3016 return (insn
& ~0x1ffd) | re_assemble_12 (sym_value
);
3018 /* This is any 17 bit branch. In PA2.0 syntax it also corresponds
3019 to the "B" instruction as well as BE. */
3020 case R_PARISC_PCREL17F
:
3021 case R_PARISC_DIR17F
:
3022 case R_PARISC_DIR17R
:
3023 case R_PARISC_PCREL17C
:
3024 case R_PARISC_PCREL17R
:
3025 return (insn
& ~0x1f1ffd) | re_assemble_17 (sym_value
);
3027 /* ADDIL or LDIL instructions. */
3028 case R_PARISC_DLTREL21L
:
3029 case R_PARISC_DLTIND21L
:
3030 case R_PARISC_LTOFF_FPTR21L
:
3031 case R_PARISC_PCREL21L
:
3032 case R_PARISC_LTOFF_TP21L
:
3033 case R_PARISC_DPREL21L
:
3034 case R_PARISC_PLTOFF21L
:
3035 case R_PARISC_DIR21L
:
3036 return (insn
& ~0x1fffff) | re_assemble_21 (sym_value
);
3038 /* LDO and integer loads/stores with 14 bit displacements. */
3039 case R_PARISC_DLTREL14R
:
3040 case R_PARISC_DLTREL14F
:
3041 case R_PARISC_DLTIND14R
:
3042 case R_PARISC_DLTIND14F
:
3043 case R_PARISC_LTOFF_FPTR14R
:
3044 case R_PARISC_PCREL14R
:
3045 case R_PARISC_PCREL14F
:
3046 case R_PARISC_LTOFF_TP14R
:
3047 case R_PARISC_LTOFF_TP14F
:
3048 case R_PARISC_DPREL14R
:
3049 case R_PARISC_DPREL14F
:
3050 case R_PARISC_PLTOFF14R
:
3051 case R_PARISC_PLTOFF14F
:
3052 case R_PARISC_DIR14R
:
3053 case R_PARISC_DIR14F
:
3054 return (insn
& ~0x3fff) | low_sign_unext (sym_value
, 14);
3056 /* PA2.0W LDO and integer loads/stores with 16 bit displacements. */
3057 case R_PARISC_LTOFF_FPTR16F
:
3058 case R_PARISC_PCREL16F
:
3059 case R_PARISC_LTOFF_TP16F
:
3060 case R_PARISC_GPREL16F
:
3061 case R_PARISC_PLTOFF16F
:
3062 case R_PARISC_DIR16F
:
3063 case R_PARISC_LTOFF16F
:
3064 return (insn
& ~0xffff) | re_assemble_16 (sym_value
);
3066 /* Doubleword loads and stores with a 14 bit displacement. */
3067 case R_PARISC_DLTREL14DR
:
3068 case R_PARISC_DLTIND14DR
:
3069 case R_PARISC_LTOFF_FPTR14DR
:
3070 case R_PARISC_LTOFF_FPTR16DF
:
3071 case R_PARISC_PCREL14DR
:
3072 case R_PARISC_PCREL16DF
:
3073 case R_PARISC_LTOFF_TP14DR
:
3074 case R_PARISC_LTOFF_TP16DF
:
3075 case R_PARISC_DPREL14DR
:
3076 case R_PARISC_GPREL16DF
:
3077 case R_PARISC_PLTOFF14DR
:
3078 case R_PARISC_PLTOFF16DF
:
3079 case R_PARISC_DIR14DR
:
3080 case R_PARISC_DIR16DF
:
3081 case R_PARISC_LTOFF16DF
:
3082 return (insn
& ~0x3ff1) | (((sym_value
& 0x2000) >> 13)
3083 | ((sym_value
& 0x1ff8) << 1));
3085 /* Floating point single word load/store instructions. */
3086 case R_PARISC_DLTREL14WR
:
3087 case R_PARISC_DLTIND14WR
:
3088 case R_PARISC_LTOFF_FPTR14WR
:
3089 case R_PARISC_LTOFF_FPTR16WF
:
3090 case R_PARISC_PCREL14WR
:
3091 case R_PARISC_PCREL16WF
:
3092 case R_PARISC_LTOFF_TP14WR
:
3093 case R_PARISC_LTOFF_TP16WF
:
3094 case R_PARISC_DPREL14WR
:
3095 case R_PARISC_GPREL16WF
:
3096 case R_PARISC_PLTOFF14WR
:
3097 case R_PARISC_PLTOFF16WF
:
3098 case R_PARISC_DIR16WF
:
3099 case R_PARISC_DIR14WR
:
3100 case R_PARISC_LTOFF16WF
:
3101 return (insn
& ~0x3ff9) | (((sym_value
& 0x2000) >> 13)
3102 | ((sym_value
& 0x1ffc) << 1));
3109 /* Compute the value for a relocation (REL) during a final link stage,
3110 then insert the value into the proper location in CONTENTS.
3112 VALUE is a tentative value for the relocation and may be overridden
3113 and modified here based on the specific relocation to be performed.
3115 For example we do conversions for PC-relative branches in this routine
3116 or redirection of calls to external routines to stubs.
3118 The work of actually applying the relocation is left to a helper
3119 routine in an attempt to reduce the complexity and size of this
3122 static bfd_reloc_status_type
3123 elf_hppa_final_link_relocate (Elf_Internal_Rela
*rel
,
3126 asection
*input_section
,
3129 struct bfd_link_info
*info
,
3131 struct elf_link_hash_entry
*eh
)
3133 struct elf64_hppa_link_hash_table
*hppa_info
= hppa_link_hash_table (info
);
3134 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
3135 bfd_vma
*local_offsets
;
3136 Elf_Internal_Shdr
*symtab_hdr
;
3138 bfd_vma max_branch_offset
= 0;
3139 bfd_vma offset
= rel
->r_offset
;
3140 bfd_signed_vma addend
= rel
->r_addend
;
3141 reloc_howto_type
*howto
= elf_hppa_howto_table
+ ELF_R_TYPE (rel
->r_info
);
3142 unsigned int r_symndx
= ELF_R_SYM (rel
->r_info
);
3143 unsigned int r_type
= howto
->type
;
3144 bfd_byte
*hit_data
= contents
+ offset
;
3146 if (hppa_info
== NULL
)
3147 return bfd_reloc_notsupported
;
3149 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3150 local_offsets
= elf_local_got_offsets (input_bfd
);
3151 insn
= bfd_get_32 (input_bfd
, hit_data
);
3158 /* Basic function call support.
3160 Note for a call to a function defined in another dynamic library
3161 we want to redirect the call to a stub. */
3163 /* PC relative relocs without an implicit offset. */
3164 case R_PARISC_PCREL21L
:
3165 case R_PARISC_PCREL14R
:
3166 case R_PARISC_PCREL14F
:
3167 case R_PARISC_PCREL14WR
:
3168 case R_PARISC_PCREL14DR
:
3169 case R_PARISC_PCREL16F
:
3170 case R_PARISC_PCREL16WF
:
3171 case R_PARISC_PCREL16DF
:
3173 /* If this is a call to a function defined in another dynamic
3174 library, then redirect the call to the local stub for this
3176 if (sym_sec
== NULL
|| sym_sec
->output_section
== NULL
)
3177 value
= (hh
->stub_offset
+ hppa_info
->stub_sec
->output_offset
3178 + hppa_info
->stub_sec
->output_section
->vma
);
3180 /* Turn VALUE into a proper PC relative address. */
3181 value
-= (offset
+ input_section
->output_offset
3182 + input_section
->output_section
->vma
);
3184 /* Adjust for any field selectors. */
3185 if (r_type
== R_PARISC_PCREL21L
)
3186 value
= hppa_field_adjust (value
, -8 + addend
, e_lsel
);
3187 else if (r_type
== R_PARISC_PCREL14F
3188 || r_type
== R_PARISC_PCREL16F
3189 || r_type
== R_PARISC_PCREL16WF
3190 || r_type
== R_PARISC_PCREL16DF
)
3191 value
= hppa_field_adjust (value
, -8 + addend
, e_fsel
);
3193 value
= hppa_field_adjust (value
, -8 + addend
, e_rsel
);
3195 /* Apply the relocation to the given instruction. */
3196 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3200 case R_PARISC_PCREL12F
:
3201 case R_PARISC_PCREL22F
:
3202 case R_PARISC_PCREL17F
:
3203 case R_PARISC_PCREL22C
:
3204 case R_PARISC_PCREL17C
:
3205 case R_PARISC_PCREL17R
:
3207 /* If this is a call to a function defined in another dynamic
3208 library, then redirect the call to the local stub for this
3210 if (sym_sec
== NULL
|| sym_sec
->output_section
== NULL
)
3211 value
= (hh
->stub_offset
+ hppa_info
->stub_sec
->output_offset
3212 + hppa_info
->stub_sec
->output_section
->vma
);
3214 /* Turn VALUE into a proper PC relative address. */
3215 value
-= (offset
+ input_section
->output_offset
3216 + input_section
->output_section
->vma
);
3219 if (r_type
== (unsigned int) R_PARISC_PCREL22F
)
3220 max_branch_offset
= (1 << (22-1)) << 2;
3221 else if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
3222 max_branch_offset
= (1 << (17-1)) << 2;
3223 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
3224 max_branch_offset
= (1 << (12-1)) << 2;
3226 /* Make sure we can reach the branch target. */
3227 if (max_branch_offset
!= 0
3228 && value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3231 /* xgettext:c-format */
3232 (_("%pB(%pA+%#" PRIx64
"): cannot reach %s"),
3236 eh
? eh
->root
.root
.string
: "unknown");
3237 bfd_set_error (bfd_error_bad_value
);
3238 return bfd_reloc_overflow
;
3241 /* Adjust for any field selectors. */
3242 if (r_type
== R_PARISC_PCREL17R
)
3243 value
= hppa_field_adjust (value
, addend
, e_rsel
);
3245 value
= hppa_field_adjust (value
, addend
, e_fsel
);
3247 /* All branches are implicitly shifted by 2 places. */
3250 /* Apply the relocation to the given instruction. */
3251 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3255 /* Indirect references to data through the DLT. */
3256 case R_PARISC_DLTIND14R
:
3257 case R_PARISC_DLTIND14F
:
3258 case R_PARISC_DLTIND14DR
:
3259 case R_PARISC_DLTIND14WR
:
3260 case R_PARISC_DLTIND21L
:
3261 case R_PARISC_LTOFF_FPTR14R
:
3262 case R_PARISC_LTOFF_FPTR14DR
:
3263 case R_PARISC_LTOFF_FPTR14WR
:
3264 case R_PARISC_LTOFF_FPTR21L
:
3265 case R_PARISC_LTOFF_FPTR16F
:
3266 case R_PARISC_LTOFF_FPTR16WF
:
3267 case R_PARISC_LTOFF_FPTR16DF
:
3268 case R_PARISC_LTOFF_TP21L
:
3269 case R_PARISC_LTOFF_TP14R
:
3270 case R_PARISC_LTOFF_TP14F
:
3271 case R_PARISC_LTOFF_TP14WR
:
3272 case R_PARISC_LTOFF_TP14DR
:
3273 case R_PARISC_LTOFF_TP16F
:
3274 case R_PARISC_LTOFF_TP16WF
:
3275 case R_PARISC_LTOFF_TP16DF
:
3276 case R_PARISC_LTOFF16F
:
3277 case R_PARISC_LTOFF16WF
:
3278 case R_PARISC_LTOFF16DF
:
3282 /* If this relocation was against a local symbol, then we still
3283 have not set up the DLT entry (it's not convenient to do so
3284 in the "finalize_dlt" routine because it is difficult to get
3285 to the local symbol's value).
3287 So, if this is a local symbol (h == NULL), then we need to
3288 fill in its DLT entry.
3290 Similarly we may still need to set up an entry in .opd for
3291 a local function which had its address taken. */
3294 bfd_vma
*local_opd_offsets
, *local_dlt_offsets
;
3296 if (local_offsets
== NULL
)
3299 /* Now do .opd creation if needed. */
3300 if (r_type
== R_PARISC_LTOFF_FPTR14R
3301 || r_type
== R_PARISC_LTOFF_FPTR14DR
3302 || r_type
== R_PARISC_LTOFF_FPTR14WR
3303 || r_type
== R_PARISC_LTOFF_FPTR21L
3304 || r_type
== R_PARISC_LTOFF_FPTR16F
3305 || r_type
== R_PARISC_LTOFF_FPTR16WF
3306 || r_type
== R_PARISC_LTOFF_FPTR16DF
)
3308 local_opd_offsets
= local_offsets
+ 2 * symtab_hdr
->sh_info
;
3309 off
= local_opd_offsets
[r_symndx
];
3311 /* The last bit records whether we've already initialised
3312 this local .opd entry. */
3315 BFD_ASSERT (off
!= (bfd_vma
) -1);
3320 local_opd_offsets
[r_symndx
] |= 1;
3322 /* The first two words of an .opd entry are zero. */
3323 memset (hppa_info
->opd_sec
->contents
+ off
, 0, 16);
3325 /* The next word is the address of the function. */
3326 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
+ addend
,
3327 (hppa_info
->opd_sec
->contents
+ off
+ 16));
3329 /* The last word is our local __gp value. */
3330 value
= _bfd_get_gp_value (info
->output_bfd
);
3331 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
,
3332 (hppa_info
->opd_sec
->contents
+ off
+ 24));
3335 /* The DLT value is the address of the .opd entry. */
3337 + hppa_info
->opd_sec
->output_offset
3338 + hppa_info
->opd_sec
->output_section
->vma
);
3342 local_dlt_offsets
= local_offsets
;
3343 off
= local_dlt_offsets
[r_symndx
];
3347 BFD_ASSERT (off
!= (bfd_vma
) -1);
3352 local_dlt_offsets
[r_symndx
] |= 1;
3353 bfd_put_64 (hppa_info
->dlt_sec
->owner
,
3355 hppa_info
->dlt_sec
->contents
+ off
);
3359 off
= hh
->dlt_offset
;
3361 /* We want the value of the DLT offset for this symbol, not
3362 the symbol's actual address. Note that __gp may not point
3363 to the start of the DLT, so we have to compute the absolute
3364 address, then subtract out the value of __gp. */
3366 + hppa_info
->dlt_sec
->output_offset
3367 + hppa_info
->dlt_sec
->output_section
->vma
);
3368 value
-= _bfd_get_gp_value (output_bfd
);
3370 /* All DLTIND relocations are basically the same at this point,
3371 except that we need different field selectors for the 21bit
3372 version vs the 14bit versions. */
3373 if (r_type
== R_PARISC_DLTIND21L
3374 || r_type
== R_PARISC_LTOFF_FPTR21L
3375 || r_type
== R_PARISC_LTOFF_TP21L
)
3376 value
= hppa_field_adjust (value
, 0, e_lsel
);
3377 else if (r_type
== R_PARISC_DLTIND14F
3378 || r_type
== R_PARISC_LTOFF_FPTR16F
3379 || r_type
== R_PARISC_LTOFF_FPTR16WF
3380 || r_type
== R_PARISC_LTOFF_FPTR16DF
3381 || r_type
== R_PARISC_LTOFF16F
3382 || r_type
== R_PARISC_LTOFF16DF
3383 || r_type
== R_PARISC_LTOFF16WF
3384 || r_type
== R_PARISC_LTOFF_TP16F
3385 || r_type
== R_PARISC_LTOFF_TP16WF
3386 || r_type
== R_PARISC_LTOFF_TP16DF
)
3387 value
= hppa_field_adjust (value
, 0, e_fsel
);
3389 value
= hppa_field_adjust (value
, 0, e_rsel
);
3391 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3395 case R_PARISC_DLTREL14R
:
3396 case R_PARISC_DLTREL14F
:
3397 case R_PARISC_DLTREL14DR
:
3398 case R_PARISC_DLTREL14WR
:
3399 case R_PARISC_DLTREL21L
:
3400 case R_PARISC_DPREL21L
:
3401 case R_PARISC_DPREL14WR
:
3402 case R_PARISC_DPREL14DR
:
3403 case R_PARISC_DPREL14R
:
3404 case R_PARISC_DPREL14F
:
3405 case R_PARISC_GPREL16F
:
3406 case R_PARISC_GPREL16WF
:
3407 case R_PARISC_GPREL16DF
:
3409 /* Subtract out the global pointer value to make value a DLT
3410 relative address. */
3411 value
-= _bfd_get_gp_value (output_bfd
);
3413 /* All DLTREL relocations are basically the same at this point,
3414 except that we need different field selectors for the 21bit
3415 version vs the 14bit versions. */
3416 if (r_type
== R_PARISC_DLTREL21L
3417 || r_type
== R_PARISC_DPREL21L
)
3418 value
= hppa_field_adjust (value
, addend
, e_lrsel
);
3419 else if (r_type
== R_PARISC_DLTREL14F
3420 || r_type
== R_PARISC_DPREL14F
3421 || r_type
== R_PARISC_GPREL16F
3422 || r_type
== R_PARISC_GPREL16WF
3423 || r_type
== R_PARISC_GPREL16DF
)
3424 value
= hppa_field_adjust (value
, addend
, e_fsel
);
3426 value
= hppa_field_adjust (value
, addend
, e_rrsel
);
3428 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3432 case R_PARISC_DIR21L
:
3433 case R_PARISC_DIR17R
:
3434 case R_PARISC_DIR17F
:
3435 case R_PARISC_DIR14R
:
3436 case R_PARISC_DIR14F
:
3437 case R_PARISC_DIR14WR
:
3438 case R_PARISC_DIR14DR
:
3439 case R_PARISC_DIR16F
:
3440 case R_PARISC_DIR16WF
:
3441 case R_PARISC_DIR16DF
:
3443 /* All DIR relocations are basically the same at this point,
3444 except that branch offsets need to be divided by four, and
3445 we need different field selectors. Note that we don't
3446 redirect absolute calls to local stubs. */
3448 if (r_type
== R_PARISC_DIR21L
)
3449 value
= hppa_field_adjust (value
, addend
, e_lrsel
);
3450 else if (r_type
== R_PARISC_DIR17F
3451 || r_type
== R_PARISC_DIR16F
3452 || r_type
== R_PARISC_DIR16WF
3453 || r_type
== R_PARISC_DIR16DF
3454 || r_type
== R_PARISC_DIR14F
)
3455 value
= hppa_field_adjust (value
, addend
, e_fsel
);
3457 value
= hppa_field_adjust (value
, addend
, e_rrsel
);
3459 if (r_type
== R_PARISC_DIR17R
|| r_type
== R_PARISC_DIR17F
)
3460 /* All branches are implicitly shifted by 2 places. */
3463 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3467 case R_PARISC_PLTOFF21L
:
3468 case R_PARISC_PLTOFF14R
:
3469 case R_PARISC_PLTOFF14F
:
3470 case R_PARISC_PLTOFF14WR
:
3471 case R_PARISC_PLTOFF14DR
:
3472 case R_PARISC_PLTOFF16F
:
3473 case R_PARISC_PLTOFF16WF
:
3474 case R_PARISC_PLTOFF16DF
:
3476 /* We want the value of the PLT offset for this symbol, not
3477 the symbol's actual address. Note that __gp may not point
3478 to the start of the DLT, so we have to compute the absolute
3479 address, then subtract out the value of __gp. */
3480 value
= (hh
->plt_offset
3481 + hppa_info
->root
.splt
->output_offset
3482 + hppa_info
->root
.splt
->output_section
->vma
);
3483 value
-= _bfd_get_gp_value (output_bfd
);
3485 /* All PLTOFF relocations are basically the same at this point,
3486 except that we need different field selectors for the 21bit
3487 version vs the 14bit versions. */
3488 if (r_type
== R_PARISC_PLTOFF21L
)
3489 value
= hppa_field_adjust (value
, addend
, e_lrsel
);
3490 else if (r_type
== R_PARISC_PLTOFF14F
3491 || r_type
== R_PARISC_PLTOFF16F
3492 || r_type
== R_PARISC_PLTOFF16WF
3493 || r_type
== R_PARISC_PLTOFF16DF
)
3494 value
= hppa_field_adjust (value
, addend
, e_fsel
);
3496 value
= hppa_field_adjust (value
, addend
, e_rrsel
);
3498 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3502 case R_PARISC_LTOFF_FPTR32
:
3504 /* FIXME: There used to be code here to create the FPTR itself if
3505 the relocation was against a local symbol. But the code could
3506 never have worked. If the assert below is ever triggered then
3507 the code will need to be reinstated and fixed so that it does
3509 BFD_ASSERT (hh
!= NULL
);
3511 /* We want the value of the DLT offset for this symbol, not
3512 the symbol's actual address. Note that __gp may not point
3513 to the start of the DLT, so we have to compute the absolute
3514 address, then subtract out the value of __gp. */
3515 value
= (hh
->dlt_offset
3516 + hppa_info
->dlt_sec
->output_offset
3517 + hppa_info
->dlt_sec
->output_section
->vma
);
3518 value
-= _bfd_get_gp_value (output_bfd
);
3519 bfd_put_32 (input_bfd
, value
, hit_data
);
3520 return bfd_reloc_ok
;
3523 case R_PARISC_LTOFF_FPTR64
:
3524 case R_PARISC_LTOFF_TP64
:
3526 /* We may still need to create the FPTR itself if it was for
3528 if (eh
== NULL
&& r_type
== R_PARISC_LTOFF_FPTR64
)
3530 /* The first two words of an .opd entry are zero. */
3531 memset (hppa_info
->opd_sec
->contents
+ hh
->opd_offset
, 0, 16);
3533 /* The next word is the address of the function. */
3534 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
+ addend
,
3535 (hppa_info
->opd_sec
->contents
3536 + hh
->opd_offset
+ 16));
3538 /* The last word is our local __gp value. */
3539 value
= _bfd_get_gp_value (info
->output_bfd
);
3540 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
,
3541 hppa_info
->opd_sec
->contents
+ hh
->opd_offset
+ 24);
3543 /* The DLT value is the address of the .opd entry. */
3544 value
= (hh
->opd_offset
3545 + hppa_info
->opd_sec
->output_offset
3546 + hppa_info
->opd_sec
->output_section
->vma
);
3548 bfd_put_64 (hppa_info
->dlt_sec
->owner
,
3550 hppa_info
->dlt_sec
->contents
+ hh
->dlt_offset
);
3553 /* We want the value of the DLT offset for this symbol, not
3554 the symbol's actual address. Note that __gp may not point
3555 to the start of the DLT, so we have to compute the absolute
3556 address, then subtract out the value of __gp. */
3557 value
= (hh
->dlt_offset
3558 + hppa_info
->dlt_sec
->output_offset
3559 + hppa_info
->dlt_sec
->output_section
->vma
);
3560 value
-= _bfd_get_gp_value (output_bfd
);
3561 bfd_put_64 (input_bfd
, value
, hit_data
);
3562 return bfd_reloc_ok
;
3565 case R_PARISC_DIR32
:
3566 bfd_put_32 (input_bfd
, value
+ addend
, hit_data
);
3567 return bfd_reloc_ok
;
3569 case R_PARISC_DIR64
:
3570 bfd_put_64 (input_bfd
, value
+ addend
, hit_data
);
3571 return bfd_reloc_ok
;
3573 case R_PARISC_GPREL64
:
3574 /* Subtract out the global pointer value to make value a DLT
3575 relative address. */
3576 value
-= _bfd_get_gp_value (output_bfd
);
3578 bfd_put_64 (input_bfd
, value
+ addend
, hit_data
);
3579 return bfd_reloc_ok
;
3581 case R_PARISC_LTOFF64
:
3582 /* We want the value of the DLT offset for this symbol, not
3583 the symbol's actual address. Note that __gp may not point
3584 to the start of the DLT, so we have to compute the absolute
3585 address, then subtract out the value of __gp. */
3586 value
= (hh
->dlt_offset
3587 + hppa_info
->dlt_sec
->output_offset
3588 + hppa_info
->dlt_sec
->output_section
->vma
);
3589 value
-= _bfd_get_gp_value (output_bfd
);
3591 bfd_put_64 (input_bfd
, value
+ addend
, hit_data
);
3592 return bfd_reloc_ok
;
3594 case R_PARISC_PCREL32
:
3596 /* If this is a call to a function defined in another dynamic
3597 library, then redirect the call to the local stub for this
3599 if (sym_sec
== NULL
|| sym_sec
->output_section
== NULL
)
3600 value
= (hh
->stub_offset
+ hppa_info
->stub_sec
->output_offset
3601 + hppa_info
->stub_sec
->output_section
->vma
);
3603 /* Turn VALUE into a proper PC relative address. */
3604 value
-= (offset
+ input_section
->output_offset
3605 + input_section
->output_section
->vma
);
3609 bfd_put_32 (input_bfd
, value
, hit_data
);
3610 return bfd_reloc_ok
;
3613 case R_PARISC_PCREL64
:
3615 /* If this is a call to a function defined in another dynamic
3616 library, then redirect the call to the local stub for this
3618 if (sym_sec
== NULL
|| sym_sec
->output_section
== NULL
)
3619 value
= (hh
->stub_offset
+ hppa_info
->stub_sec
->output_offset
3620 + hppa_info
->stub_sec
->output_section
->vma
);
3622 /* Turn VALUE into a proper PC relative address. */
3623 value
-= (offset
+ input_section
->output_offset
3624 + input_section
->output_section
->vma
);
3628 bfd_put_64 (input_bfd
, value
, hit_data
);
3629 return bfd_reloc_ok
;
3632 case R_PARISC_FPTR64
:
3636 /* We may still need to create the FPTR itself if it was for
3640 bfd_vma
*local_opd_offsets
;
3642 if (local_offsets
== NULL
)
3645 local_opd_offsets
= local_offsets
+ 2 * symtab_hdr
->sh_info
;
3646 off
= local_opd_offsets
[r_symndx
];
3648 /* The last bit records whether we've already initialised
3649 this local .opd entry. */
3652 BFD_ASSERT (off
!= (bfd_vma
) -1);
3657 /* The first two words of an .opd entry are zero. */
3658 memset (hppa_info
->opd_sec
->contents
+ off
, 0, 16);
3660 /* The next word is the address of the function. */
3661 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
+ addend
,
3662 (hppa_info
->opd_sec
->contents
+ off
+ 16));
3664 /* The last word is our local __gp value. */
3665 value
= _bfd_get_gp_value (info
->output_bfd
);
3666 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
,
3667 hppa_info
->opd_sec
->contents
+ off
+ 24);
3671 off
= hh
->opd_offset
;
3673 if (hh
== NULL
|| hh
->want_opd
)
3674 /* We want the value of the OPD offset for this symbol. */
3676 + hppa_info
->opd_sec
->output_offset
3677 + hppa_info
->opd_sec
->output_section
->vma
);
3679 /* We want the address of the symbol. */
3682 bfd_put_64 (input_bfd
, value
, hit_data
);
3683 return bfd_reloc_ok
;
3686 case R_PARISC_SECREL32
:
3687 if (sym_sec
&& sym_sec
->output_section
)
3688 value
-= sym_sec
->output_section
->vma
;
3689 bfd_put_32 (input_bfd
, value
+ addend
, hit_data
);
3690 return bfd_reloc_ok
;
3692 case R_PARISC_SEGREL32
:
3693 case R_PARISC_SEGREL64
:
3695 /* If this is the first SEGREL relocation, then initialize
3696 the segment base values. */
3697 if (hppa_info
->text_segment_base
== (bfd_vma
) -1)
3698 bfd_map_over_sections (output_bfd
, elf_hppa_record_segment_addrs
,
3701 /* VALUE holds the absolute address. We want to include the
3702 addend, then turn it into a segment relative address.
3704 The segment is derived from SYM_SEC. We assume that there are
3705 only two segments of note in the resulting executable/shlib.
3706 A readonly segment (.text) and a readwrite segment (.data). */
3709 if (sym_sec
->flags
& SEC_CODE
)
3710 value
-= hppa_info
->text_segment_base
;
3712 value
-= hppa_info
->data_segment_base
;
3714 if (r_type
== R_PARISC_SEGREL32
)
3715 bfd_put_32 (input_bfd
, value
, hit_data
);
3717 bfd_put_64 (input_bfd
, value
, hit_data
);
3718 return bfd_reloc_ok
;
3721 /* Something we don't know how to handle. */
3723 return bfd_reloc_notsupported
;
3726 /* Update the instruction word. */
3727 bfd_put_32 (input_bfd
, (bfd_vma
) insn
, hit_data
);
3728 return bfd_reloc_ok
;
3731 /* Relocate an HPPA ELF section. */
3734 elf64_hppa_relocate_section (bfd
*output_bfd
,
3735 struct bfd_link_info
*info
,
3737 asection
*input_section
,
3739 Elf_Internal_Rela
*relocs
,
3740 Elf_Internal_Sym
*local_syms
,
3741 asection
**local_sections
)
3743 Elf_Internal_Shdr
*symtab_hdr
;
3744 Elf_Internal_Rela
*rel
;
3745 Elf_Internal_Rela
*relend
;
3746 struct elf64_hppa_link_hash_table
*hppa_info
;
3748 hppa_info
= hppa_link_hash_table (info
);
3749 if (hppa_info
== NULL
)
3752 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3755 relend
= relocs
+ input_section
->reloc_count
;
3756 for (; rel
< relend
; rel
++)
3759 reloc_howto_type
*howto
= elf_hppa_howto_table
+ ELF_R_TYPE (rel
->r_info
);
3760 unsigned long r_symndx
;
3761 struct elf_link_hash_entry
*eh
;
3762 Elf_Internal_Sym
*sym
;
3765 bfd_reloc_status_type r
;
3767 r_type
= ELF_R_TYPE (rel
->r_info
);
3768 if (r_type
< 0 || r_type
>= (int) R_PARISC_UNIMPLEMENTED
)
3770 bfd_set_error (bfd_error_bad_value
);
3773 if (r_type
== (unsigned int) R_PARISC_GNU_VTENTRY
3774 || r_type
== (unsigned int) R_PARISC_GNU_VTINHERIT
)
3777 /* This is a final link. */
3778 r_symndx
= ELF_R_SYM (rel
->r_info
);
3782 if (r_symndx
< symtab_hdr
->sh_info
)
3784 /* This is a local symbol, hh defaults to NULL. */
3785 sym
= local_syms
+ r_symndx
;
3786 sym_sec
= local_sections
[r_symndx
];
3787 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sym_sec
, rel
);
3791 /* This is not a local symbol. */
3792 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (input_bfd
);
3794 /* It seems this can happen with erroneous or unsupported
3795 input (mixing a.out and elf in an archive, for example.) */
3796 if (sym_hashes
== NULL
)
3799 eh
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3801 if (info
->wrap_hash
!= NULL
3802 && (input_section
->flags
& SEC_DEBUGGING
) != 0)
3803 eh
= ((struct elf_link_hash_entry
*)
3804 unwrap_hash_lookup (info
, input_bfd
, &eh
->root
));
3806 while (eh
->root
.type
== bfd_link_hash_indirect
3807 || eh
->root
.type
== bfd_link_hash_warning
)
3808 eh
= (struct elf_link_hash_entry
*) eh
->root
.u
.i
.link
;
3811 if (eh
->root
.type
== bfd_link_hash_defined
3812 || eh
->root
.type
== bfd_link_hash_defweak
)
3814 sym_sec
= eh
->root
.u
.def
.section
;
3816 && sym_sec
->output_section
!= NULL
)
3817 relocation
= (eh
->root
.u
.def
.value
3818 + sym_sec
->output_section
->vma
3819 + sym_sec
->output_offset
);
3821 else if (eh
->root
.type
== bfd_link_hash_undefweak
)
3823 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
3824 && ELF_ST_VISIBILITY (eh
->other
) == STV_DEFAULT
)
3826 else if (!bfd_link_relocatable (info
)
3827 && elf_hppa_is_dynamic_loader_symbol (eh
->root
.root
.string
))
3829 else if (!bfd_link_relocatable (info
))
3833 err
= (info
->unresolved_syms_in_objects
== RM_DIAGNOSE
3834 && !info
->warn_unresolved_syms
)
3835 || ELF_ST_VISIBILITY (eh
->other
) != STV_DEFAULT
;
3837 info
->callbacks
->undefined_symbol
3838 (info
, eh
->root
.root
.string
, input_bfd
,
3839 input_section
, rel
->r_offset
, err
);
3842 if (!bfd_link_relocatable (info
)
3844 && eh
->root
.type
!= bfd_link_hash_defined
3845 && eh
->root
.type
!= bfd_link_hash_defweak
3846 && eh
->root
.type
!= bfd_link_hash_undefweak
)
3848 if (info
->unresolved_syms_in_objects
== RM_IGNORE
3849 && ELF_ST_VISIBILITY (eh
->other
) == STV_DEFAULT
3850 && eh
->type
== STT_PARISC_MILLI
)
3851 info
->callbacks
->undefined_symbol
3852 (info
, eh_name (eh
), input_bfd
,
3853 input_section
, rel
->r_offset
, false);
3857 if (sym_sec
!= NULL
&& discarded_section (sym_sec
))
3858 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
3859 rel
, 1, relend
, howto
, 0, contents
);
3861 if (bfd_link_relocatable (info
))
3864 r
= elf_hppa_final_link_relocate (rel
, input_bfd
, output_bfd
,
3865 input_section
, contents
,
3866 relocation
, info
, sym_sec
,
3869 if (r
!= bfd_reloc_ok
)
3875 case bfd_reloc_overflow
:
3877 const char *sym_name
;
3883 sym_name
= bfd_elf_string_from_elf_section (input_bfd
,
3884 symtab_hdr
->sh_link
,
3886 if (sym_name
== NULL
)
3888 if (*sym_name
== '\0')
3889 sym_name
= bfd_section_name (sym_sec
);
3892 (*info
->callbacks
->reloc_overflow
)
3893 (info
, (eh
? &eh
->root
: NULL
), sym_name
, howto
->name
,
3894 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
3903 static const struct bfd_elf_special_section elf64_hppa_special_sections
[] =
3905 { STRING_COMMA_LEN (".tbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_HP_TLS
},
3906 { STRING_COMMA_LEN (".fini"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
3907 { STRING_COMMA_LEN (".init"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
3908 { STRING_COMMA_LEN (".plt"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
3909 { STRING_COMMA_LEN (".dlt"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
3910 { STRING_COMMA_LEN (".sdata"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
3911 { STRING_COMMA_LEN (".sbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
3912 { NULL
, 0, 0, 0, 0 }
3915 /* The hash bucket size is the standard one, namely 4. */
3917 const struct elf_size_info hppa64_elf_size_info
=
3919 sizeof (Elf64_External_Ehdr
),
3920 sizeof (Elf64_External_Phdr
),
3921 sizeof (Elf64_External_Shdr
),
3922 sizeof (Elf64_External_Rel
),
3923 sizeof (Elf64_External_Rela
),
3924 sizeof (Elf64_External_Sym
),
3925 sizeof (Elf64_External_Dyn
),
3926 sizeof (Elf_External_Note
),
3930 ELFCLASS64
, EV_CURRENT
,
3931 bfd_elf64_write_out_phdrs
,
3932 bfd_elf64_write_shdrs_and_ehdr
,
3933 bfd_elf64_checksum_contents
,
3934 bfd_elf64_write_relocs
,
3935 bfd_elf64_swap_symbol_in
,
3936 bfd_elf64_swap_symbol_out
,
3937 bfd_elf64_slurp_reloc_table
,
3938 bfd_elf64_slurp_symbol_table
,
3939 bfd_elf64_swap_dyn_in
,
3940 bfd_elf64_swap_dyn_out
,
3941 bfd_elf64_swap_reloc_in
,
3942 bfd_elf64_swap_reloc_out
,
3943 bfd_elf64_swap_reloca_in
,
3944 bfd_elf64_swap_reloca_out
3947 #define TARGET_BIG_SYM hppa_elf64_vec
3948 #define TARGET_BIG_NAME "elf64-hppa"
3949 #define ELF_ARCH bfd_arch_hppa
3950 #define ELF_TARGET_ID HPPA64_ELF_DATA
3951 #define ELF_MACHINE_CODE EM_PARISC
3952 /* This is not strictly correct. The maximum page size for PA2.0 is
3953 64M. But everything still uses 4k. */
3954 #define ELF_MAXPAGESIZE 0x1000
3955 #define ELF_OSABI ELFOSABI_HPUX
3957 #define bfd_elf64_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
3958 #define bfd_elf64_bfd_reloc_name_lookup elf_hppa_reloc_name_lookup
3959 #define bfd_elf64_bfd_is_local_label_name elf_hppa_is_local_label_name
3960 #define elf_info_to_howto elf_hppa_info_to_howto
3961 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
3963 #define elf_backend_section_from_shdr elf64_hppa_section_from_shdr
3964 #define elf_backend_object_p elf64_hppa_object_p
3965 #define elf_backend_final_write_processing \
3966 elf_hppa_final_write_processing
3967 #define elf_backend_fake_sections elf_hppa_fake_sections
3968 #define elf_backend_add_symbol_hook elf_hppa_add_symbol_hook
3970 #define elf_backend_relocate_section elf_hppa_relocate_section
3972 #define bfd_elf64_bfd_final_link elf_hppa_final_link
3974 #define elf_backend_create_dynamic_sections \
3975 elf64_hppa_create_dynamic_sections
3976 #define elf_backend_init_file_header elf64_hppa_init_file_header
3978 #define elf_backend_omit_section_dynsym _bfd_elf_omit_section_dynsym_all
3980 #define elf_backend_adjust_dynamic_symbol \
3981 elf64_hppa_adjust_dynamic_symbol
3983 #define elf_backend_late_size_sections elf64_hppa_late_size_sections
3985 #define elf_backend_finish_dynamic_symbol \
3986 elf64_hppa_finish_dynamic_symbol
3987 #define elf_backend_finish_dynamic_sections \
3988 elf64_hppa_finish_dynamic_sections
3989 #define elf_backend_grok_prstatus elf64_hppa_grok_prstatus
3990 #define elf_backend_grok_psinfo elf64_hppa_grok_psinfo
3992 /* Stuff for the BFD linker: */
3993 #define bfd_elf64_bfd_link_hash_table_create \
3994 elf64_hppa_hash_table_create
3996 #define elf_backend_check_relocs \
3997 elf64_hppa_check_relocs
3999 #define elf_backend_size_info \
4000 hppa64_elf_size_info
4002 #define elf_backend_additional_program_headers \
4003 elf64_hppa_additional_program_headers
4005 #define elf_backend_modify_segment_map \
4006 elf64_hppa_modify_segment_map
4008 #define elf_backend_allow_non_load_phdr \
4009 elf64_hppa_allow_non_load_phdr
4011 #define elf_backend_link_output_symbol_hook \
4012 elf64_hppa_link_output_symbol_hook
4014 #define elf_backend_want_got_plt 0
4015 #define elf_backend_plt_readonly 0
4016 #define elf_backend_want_plt_sym 0
4017 #define elf_backend_got_header_size 0
4018 #define elf_backend_type_change_ok true
4019 #define elf_backend_get_symbol_type elf64_hppa_elf_get_symbol_type
4020 #define elf_backend_reloc_type_class elf64_hppa_reloc_type_class
4021 #define elf_backend_rela_normal 1
4022 #define elf_backend_special_sections elf64_hppa_special_sections
4023 #define elf_backend_action_discarded elf_hppa_action_discarded
4024 #define elf_backend_section_from_phdr elf64_hppa_section_from_phdr
4026 #define elf64_bed elf64_hppa_hpux_bed
4028 #include "elf64-target.h"
4030 #undef TARGET_BIG_SYM
4031 #define TARGET_BIG_SYM hppa_elf64_linux_vec
4032 #undef TARGET_BIG_NAME
4033 #define TARGET_BIG_NAME "elf64-hppa-linux"
4035 #define ELF_OSABI ELFOSABI_GNU
4037 #define elf64_bed elf64_hppa_linux_bed
4038 #undef elf_backend_special_sections
4039 #define elf_backend_special_sections (elf64_hppa_special_sections + 1)
4041 #include "elf64-target.h"