1 /* Support for HPPA 64-bit ELF
2 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
3 2010 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
22 #include "alloca-conf.h"
29 #include "elf64-hppa.h"
34 #define PLT_ENTRY_SIZE 0x10
35 #define DLT_ENTRY_SIZE 0x8
36 #define OPD_ENTRY_SIZE 0x20
38 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/pa20_64/dld.sl"
40 /* The stub is supposed to load the target address and target's DP
41 value out of the PLT, then do an external branch to the target
46 LDD PLTOFF+8(%r27),%r27
48 Note that we must use the LDD with a 14 bit displacement, not the one
49 with a 5 bit displacement. */
50 static char plt_stub
[] = {0x53, 0x61, 0x00, 0x00, 0xe8, 0x20, 0xd0, 0x00,
51 0x53, 0x7b, 0x00, 0x00 };
53 struct elf64_hppa_link_hash_entry
55 struct elf_link_hash_entry eh
;
57 /* Offsets for this symbol in various linker sections. */
63 /* The index of the (possibly local) symbol in the input bfd and its
64 associated BFD. Needed so that we can have relocs against local
65 symbols in shared libraries. */
69 /* Dynamic symbols may need to have two different values. One for
70 the dynamic symbol table, one for the normal symbol table.
72 In such cases we store the symbol's real value and section
73 index here so we can restore the real value before we write
74 the normal symbol table. */
78 /* Used to count non-got, non-plt relocations for delayed sizing
79 of relocation sections. */
80 struct elf64_hppa_dyn_reloc_entry
82 /* Next relocation in the chain. */
83 struct elf64_hppa_dyn_reloc_entry
*next
;
85 /* The type of the relocation. */
88 /* The input section of the relocation. */
91 /* Number of relocs copied in this section. */
94 /* The index of the section symbol for the input section of
95 the relocation. Only needed when building shared libraries. */
98 /* The offset within the input section of the relocation. */
101 /* The addend for the relocation. */
106 /* Nonzero if this symbol needs an entry in one of the linker
114 struct elf64_hppa_link_hash_table
116 struct elf_link_hash_table root
;
118 /* Shortcuts to get to the various linker defined sections. */
120 asection
*dlt_rel_sec
;
122 asection
*plt_rel_sec
;
124 asection
*opd_rel_sec
;
125 asection
*other_rel_sec
;
127 /* Offset of __gp within .plt section. When the PLT gets large we want
128 to slide __gp into the PLT section so that we can continue to use
129 single DP relative instructions to load values out of the PLT. */
132 /* Note this is not strictly correct. We should create a stub section for
133 each input section with calls. The stub section should be placed before
134 the section with the call. */
137 bfd_vma text_segment_base
;
138 bfd_vma data_segment_base
;
140 /* We build tables to map from an input section back to its
141 symbol index. This is the BFD for which we currently have
143 bfd
*section_syms_bfd
;
145 /* Array of symbol numbers for each input section attached to the
150 #define hppa_link_hash_table(p) \
151 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
152 == HPPA64_ELF_DATA ? ((struct elf64_hppa_link_hash_table *) ((p)->hash)) : NULL)
154 #define hppa_elf_hash_entry(ent) \
155 ((struct elf64_hppa_link_hash_entry *)(ent))
157 #define eh_name(eh) \
158 (eh ? eh->root.root.string : "<undef>")
160 typedef struct bfd_hash_entry
*(*new_hash_entry_func
)
161 (struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *);
163 static struct bfd_link_hash_table
*elf64_hppa_hash_table_create
166 /* This must follow the definitions of the various derived linker
167 hash tables and shared functions. */
168 #include "elf-hppa.h"
170 static bfd_boolean elf64_hppa_object_p
173 static void elf64_hppa_post_process_headers
174 (bfd
*, struct bfd_link_info
*);
176 static bfd_boolean elf64_hppa_create_dynamic_sections
177 (bfd
*, struct bfd_link_info
*);
179 static bfd_boolean elf64_hppa_adjust_dynamic_symbol
180 (struct bfd_link_info
*, struct elf_link_hash_entry
*);
182 static bfd_boolean elf64_hppa_mark_milli_and_exported_functions
183 (struct elf_link_hash_entry
*, void *);
185 static bfd_boolean elf64_hppa_size_dynamic_sections
186 (bfd
*, struct bfd_link_info
*);
188 static int elf64_hppa_link_output_symbol_hook
189 (struct bfd_link_info
*, const char *, Elf_Internal_Sym
*,
190 asection
*, struct elf_link_hash_entry
*);
192 static bfd_boolean elf64_hppa_finish_dynamic_symbol
193 (bfd
*, struct bfd_link_info
*,
194 struct elf_link_hash_entry
*, Elf_Internal_Sym
*);
196 static enum elf_reloc_type_class elf64_hppa_reloc_type_class
197 (const Elf_Internal_Rela
*);
199 static bfd_boolean elf64_hppa_finish_dynamic_sections
200 (bfd
*, struct bfd_link_info
*);
202 static bfd_boolean elf64_hppa_check_relocs
203 (bfd
*, struct bfd_link_info
*,
204 asection
*, const Elf_Internal_Rela
*);
206 static bfd_boolean elf64_hppa_dynamic_symbol_p
207 (struct elf_link_hash_entry
*, struct bfd_link_info
*);
209 static bfd_boolean elf64_hppa_mark_exported_functions
210 (struct elf_link_hash_entry
*, void *);
212 static bfd_boolean elf64_hppa_finalize_opd
213 (struct elf_link_hash_entry
*, void *);
215 static bfd_boolean elf64_hppa_finalize_dlt
216 (struct elf_link_hash_entry
*, void *);
218 static bfd_boolean allocate_global_data_dlt
219 (struct elf_link_hash_entry
*, void *);
221 static bfd_boolean allocate_global_data_plt
222 (struct elf_link_hash_entry
*, void *);
224 static bfd_boolean allocate_global_data_stub
225 (struct elf_link_hash_entry
*, void *);
227 static bfd_boolean allocate_global_data_opd
228 (struct elf_link_hash_entry
*, void *);
230 static bfd_boolean get_reloc_section
231 (bfd
*, struct elf64_hppa_link_hash_table
*, asection
*);
233 static bfd_boolean count_dyn_reloc
234 (bfd
*, struct elf64_hppa_link_hash_entry
*,
235 int, asection
*, int, bfd_vma
, bfd_vma
);
237 static bfd_boolean allocate_dynrel_entries
238 (struct elf_link_hash_entry
*, void *);
240 static bfd_boolean elf64_hppa_finalize_dynreloc
241 (struct elf_link_hash_entry
*, void *);
243 static bfd_boolean get_opd
244 (bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*);
246 static bfd_boolean get_plt
247 (bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*);
249 static bfd_boolean get_dlt
250 (bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*);
252 static bfd_boolean get_stub
253 (bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*);
255 static int elf64_hppa_elf_get_symbol_type
256 (Elf_Internal_Sym
*, int);
258 /* Initialize an entry in the link hash table. */
260 static struct bfd_hash_entry
*
261 hppa64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
262 struct bfd_hash_table
*table
,
265 /* Allocate the structure if it has not already been allocated by a
269 entry
= bfd_hash_allocate (table
,
270 sizeof (struct elf64_hppa_link_hash_entry
));
275 /* Call the allocation method of the superclass. */
276 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
279 struct elf64_hppa_link_hash_entry
*hh
;
281 /* Initialize our local data. All zeros. */
282 hh
= hppa_elf_hash_entry (entry
);
283 memset (&hh
->dlt_offset
, 0,
284 (sizeof (struct elf64_hppa_link_hash_entry
)
285 - offsetof (struct elf64_hppa_link_hash_entry
, dlt_offset
)));
291 /* Create the derived linker hash table. The PA64 ELF port uses this
292 derived hash table to keep information specific to the PA ElF
293 linker (without using static variables). */
295 static struct bfd_link_hash_table
*
296 elf64_hppa_hash_table_create (bfd
*abfd
)
298 struct elf64_hppa_link_hash_table
*htab
;
299 bfd_size_type amt
= sizeof (*htab
);
301 htab
= bfd_zalloc (abfd
, amt
);
305 if (!_bfd_elf_link_hash_table_init (&htab
->root
, abfd
,
306 hppa64_link_hash_newfunc
,
307 sizeof (struct elf64_hppa_link_hash_entry
),
310 bfd_release (abfd
, htab
);
314 htab
->text_segment_base
= (bfd_vma
) -1;
315 htab
->data_segment_base
= (bfd_vma
) -1;
317 return &htab
->root
.root
;
320 /* Return nonzero if ABFD represents a PA2.0 ELF64 file.
322 Additionally we set the default architecture and machine. */
324 elf64_hppa_object_p (bfd
*abfd
)
326 Elf_Internal_Ehdr
* i_ehdrp
;
329 i_ehdrp
= elf_elfheader (abfd
);
330 if (strcmp (bfd_get_target (abfd
), "elf64-hppa-linux") == 0)
332 /* GCC on hppa-linux produces binaries with OSABI=Linux,
333 but the kernel produces corefiles with OSABI=SysV. */
334 if (i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_LINUX
335 && i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_NONE
) /* aka SYSV */
340 /* HPUX produces binaries with OSABI=HPUX,
341 but the kernel produces corefiles with OSABI=SysV. */
342 if (i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_HPUX
343 && i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_NONE
) /* aka SYSV */
347 flags
= i_ehdrp
->e_flags
;
348 switch (flags
& (EF_PARISC_ARCH
| EF_PARISC_WIDE
))
351 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 10);
353 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 11);
355 if (i_ehdrp
->e_ident
[EI_CLASS
] == ELFCLASS64
)
356 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 25);
358 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 20);
359 case EFA_PARISC_2_0
| EF_PARISC_WIDE
:
360 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 25);
362 /* Don't be fussy. */
366 /* Given section type (hdr->sh_type), return a boolean indicating
367 whether or not the section is an elf64-hppa specific section. */
369 elf64_hppa_section_from_shdr (bfd
*abfd
,
370 Elf_Internal_Shdr
*hdr
,
374 switch (hdr
->sh_type
)
377 if (strcmp (name
, ".PARISC.archext") != 0)
380 case SHT_PARISC_UNWIND
:
381 if (strcmp (name
, ".PARISC.unwind") != 0)
385 case SHT_PARISC_ANNOT
:
390 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
396 /* SEC is a section containing relocs for an input BFD when linking; return
397 a suitable section for holding relocs in the output BFD for a link. */
400 get_reloc_section (bfd
*abfd
,
401 struct elf64_hppa_link_hash_table
*hppa_info
,
404 const char *srel_name
;
408 srel_name
= (bfd_elf_string_from_elf_section
409 (abfd
, elf_elfheader(abfd
)->e_shstrndx
,
410 _bfd_elf_single_rel_hdr(sec
)->sh_name
));
411 if (srel_name
== NULL
)
414 BFD_ASSERT ((CONST_STRNEQ (srel_name
, ".rela")
415 && strcmp (bfd_get_section_name (abfd
, sec
),
417 || (CONST_STRNEQ (srel_name
, ".rel")
418 && strcmp (bfd_get_section_name (abfd
, sec
),
419 srel_name
+ 4) == 0));
421 dynobj
= hppa_info
->root
.dynobj
;
423 hppa_info
->root
.dynobj
= dynobj
= abfd
;
425 srel
= bfd_get_section_by_name (dynobj
, srel_name
);
428 srel
= bfd_make_section_with_flags (dynobj
, srel_name
,
436 || !bfd_set_section_alignment (dynobj
, srel
, 3))
440 hppa_info
->other_rel_sec
= srel
;
444 /* Add a new entry to the list of dynamic relocations against DYN_H.
446 We use this to keep a record of all the FPTR relocations against a
447 particular symbol so that we can create FPTR relocations in the
451 count_dyn_reloc (bfd
*abfd
,
452 struct elf64_hppa_link_hash_entry
*hh
,
459 struct elf64_hppa_dyn_reloc_entry
*rent
;
461 rent
= (struct elf64_hppa_dyn_reloc_entry
*)
462 bfd_alloc (abfd
, (bfd_size_type
) sizeof (*rent
));
466 rent
->next
= hh
->reloc_entries
;
469 rent
->sec_symndx
= sec_symndx
;
470 rent
->offset
= offset
;
471 rent
->addend
= addend
;
472 hh
->reloc_entries
= rent
;
477 /* Return a pointer to the local DLT, PLT and OPD reference counts
478 for ABFD. Returns NULL if the storage allocation fails. */
480 static bfd_signed_vma
*
481 hppa64_elf_local_refcounts (bfd
*abfd
)
483 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
484 bfd_signed_vma
*local_refcounts
;
486 local_refcounts
= elf_local_got_refcounts (abfd
);
487 if (local_refcounts
== NULL
)
491 /* Allocate space for local DLT, PLT and OPD reference
492 counts. Done this way to save polluting elf_obj_tdata
493 with another target specific pointer. */
494 size
= symtab_hdr
->sh_info
;
495 size
*= 3 * sizeof (bfd_signed_vma
);
496 local_refcounts
= bfd_zalloc (abfd
, size
);
497 elf_local_got_refcounts (abfd
) = local_refcounts
;
499 return local_refcounts
;
502 /* Scan the RELOCS and record the type of dynamic entries that each
503 referenced symbol needs. */
506 elf64_hppa_check_relocs (bfd
*abfd
,
507 struct bfd_link_info
*info
,
509 const Elf_Internal_Rela
*relocs
)
511 struct elf64_hppa_link_hash_table
*hppa_info
;
512 const Elf_Internal_Rela
*relend
;
513 Elf_Internal_Shdr
*symtab_hdr
;
514 const Elf_Internal_Rela
*rel
;
515 unsigned int sec_symndx
;
517 if (info
->relocatable
)
520 /* If this is the first dynamic object found in the link, create
521 the special sections required for dynamic linking. */
522 if (! elf_hash_table (info
)->dynamic_sections_created
)
524 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
528 hppa_info
= hppa_link_hash_table (info
);
529 if (hppa_info
== NULL
)
531 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
533 /* If necessary, build a new table holding section symbols indices
536 if (info
->shared
&& hppa_info
->section_syms_bfd
!= abfd
)
539 unsigned int highest_shndx
;
540 Elf_Internal_Sym
*local_syms
= NULL
;
541 Elf_Internal_Sym
*isym
, *isymend
;
544 /* We're done with the old cache of section index to section symbol
545 index information. Free it.
547 ?!? Note we leak the last section_syms array. Presumably we
548 could free it in one of the later routines in this file. */
549 if (hppa_info
->section_syms
)
550 free (hppa_info
->section_syms
);
552 /* Read this BFD's local symbols. */
553 if (symtab_hdr
->sh_info
!= 0)
555 local_syms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
556 if (local_syms
== NULL
)
557 local_syms
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
558 symtab_hdr
->sh_info
, 0,
560 if (local_syms
== NULL
)
564 /* Record the highest section index referenced by the local symbols. */
566 isymend
= local_syms
+ symtab_hdr
->sh_info
;
567 for (isym
= local_syms
; isym
< isymend
; isym
++)
569 if (isym
->st_shndx
> highest_shndx
570 && isym
->st_shndx
< SHN_LORESERVE
)
571 highest_shndx
= isym
->st_shndx
;
574 /* Allocate an array to hold the section index to section symbol index
575 mapping. Bump by one since we start counting at zero. */
579 hppa_info
->section_syms
= (int *) bfd_malloc (amt
);
581 /* Now walk the local symbols again. If we find a section symbol,
582 record the index of the symbol into the section_syms array. */
583 for (i
= 0, isym
= local_syms
; isym
< isymend
; i
++, isym
++)
585 if (ELF_ST_TYPE (isym
->st_info
) == STT_SECTION
)
586 hppa_info
->section_syms
[isym
->st_shndx
] = i
;
589 /* We are finished with the local symbols. */
590 if (local_syms
!= NULL
591 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
593 if (! info
->keep_memory
)
597 /* Cache the symbols for elf_link_input_bfd. */
598 symtab_hdr
->contents
= (unsigned char *) local_syms
;
602 /* Record which BFD we built the section_syms mapping for. */
603 hppa_info
->section_syms_bfd
= abfd
;
606 /* Record the symbol index for this input section. We may need it for
607 relocations when building shared libraries. When not building shared
608 libraries this value is never really used, but assign it to zero to
609 prevent out of bounds memory accesses in other routines. */
612 sec_symndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
614 /* If we did not find a section symbol for this section, then
615 something went terribly wrong above. */
616 if (sec_symndx
== SHN_BAD
)
619 if (sec_symndx
< SHN_LORESERVE
)
620 sec_symndx
= hppa_info
->section_syms
[sec_symndx
];
627 relend
= relocs
+ sec
->reloc_count
;
628 for (rel
= relocs
; rel
< relend
; ++rel
)
639 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
640 struct elf64_hppa_link_hash_entry
*hh
;
642 bfd_boolean maybe_dynamic
;
643 int dynrel_type
= R_PARISC_NONE
;
644 static reloc_howto_type
*howto
;
646 if (r_symndx
>= symtab_hdr
->sh_info
)
648 /* We're dealing with a global symbol -- find its hash entry
649 and mark it as being referenced. */
650 long indx
= r_symndx
- symtab_hdr
->sh_info
;
651 hh
= hppa_elf_hash_entry (elf_sym_hashes (abfd
)[indx
]);
652 while (hh
->eh
.root
.type
== bfd_link_hash_indirect
653 || hh
->eh
.root
.type
== bfd_link_hash_warning
)
654 hh
= hppa_elf_hash_entry (hh
->eh
.root
.u
.i
.link
);
656 hh
->eh
.ref_regular
= 1;
661 /* We can only get preliminary data on whether a symbol is
662 locally or externally defined, as not all of the input files
663 have yet been processed. Do something with what we know, as
664 this may help reduce memory usage and processing time later. */
665 maybe_dynamic
= FALSE
;
666 if (hh
&& ((info
->shared
668 || info
->unresolved_syms_in_shared_libs
== RM_IGNORE
))
669 || !hh
->eh
.def_regular
670 || hh
->eh
.root
.type
== bfd_link_hash_defweak
))
671 maybe_dynamic
= TRUE
;
673 howto
= elf_hppa_howto_table
+ ELF64_R_TYPE (rel
->r_info
);
677 /* These are simple indirect references to symbols through the
678 DLT. We need to create a DLT entry for any symbols which
679 appears in a DLTIND relocation. */
680 case R_PARISC_DLTIND21L
:
681 case R_PARISC_DLTIND14R
:
682 case R_PARISC_DLTIND14F
:
683 case R_PARISC_DLTIND14WR
:
684 case R_PARISC_DLTIND14DR
:
685 need_entry
= NEED_DLT
;
688 /* ?!? These need a DLT entry. But I have no idea what to do with
689 the "link time TP value. */
690 case R_PARISC_LTOFF_TP21L
:
691 case R_PARISC_LTOFF_TP14R
:
692 case R_PARISC_LTOFF_TP14F
:
693 case R_PARISC_LTOFF_TP64
:
694 case R_PARISC_LTOFF_TP14WR
:
695 case R_PARISC_LTOFF_TP14DR
:
696 case R_PARISC_LTOFF_TP16F
:
697 case R_PARISC_LTOFF_TP16WF
:
698 case R_PARISC_LTOFF_TP16DF
:
699 need_entry
= NEED_DLT
;
702 /* These are function calls. Depending on their precise target we
703 may need to make a stub for them. The stub uses the PLT, so we
704 need to create PLT entries for these symbols too. */
705 case R_PARISC_PCREL12F
:
706 case R_PARISC_PCREL17F
:
707 case R_PARISC_PCREL22F
:
708 case R_PARISC_PCREL32
:
709 case R_PARISC_PCREL64
:
710 case R_PARISC_PCREL21L
:
711 case R_PARISC_PCREL17R
:
712 case R_PARISC_PCREL17C
:
713 case R_PARISC_PCREL14R
:
714 case R_PARISC_PCREL14F
:
715 case R_PARISC_PCREL22C
:
716 case R_PARISC_PCREL14WR
:
717 case R_PARISC_PCREL14DR
:
718 case R_PARISC_PCREL16F
:
719 case R_PARISC_PCREL16WF
:
720 case R_PARISC_PCREL16DF
:
721 /* Function calls might need to go through the .plt, and
722 might need a long branch stub. */
723 if (hh
!= NULL
&& hh
->eh
.type
!= STT_PARISC_MILLI
)
724 need_entry
= (NEED_PLT
| NEED_STUB
);
729 case R_PARISC_PLTOFF21L
:
730 case R_PARISC_PLTOFF14R
:
731 case R_PARISC_PLTOFF14F
:
732 case R_PARISC_PLTOFF14WR
:
733 case R_PARISC_PLTOFF14DR
:
734 case R_PARISC_PLTOFF16F
:
735 case R_PARISC_PLTOFF16WF
:
736 case R_PARISC_PLTOFF16DF
:
737 need_entry
= (NEED_PLT
);
741 if (info
->shared
|| maybe_dynamic
)
742 need_entry
= (NEED_DYNREL
);
743 dynrel_type
= R_PARISC_DIR64
;
746 /* This is an indirect reference through the DLT to get the address
747 of a OPD descriptor. Thus we need to make a DLT entry that points
749 case R_PARISC_LTOFF_FPTR21L
:
750 case R_PARISC_LTOFF_FPTR14R
:
751 case R_PARISC_LTOFF_FPTR14WR
:
752 case R_PARISC_LTOFF_FPTR14DR
:
753 case R_PARISC_LTOFF_FPTR32
:
754 case R_PARISC_LTOFF_FPTR64
:
755 case R_PARISC_LTOFF_FPTR16F
:
756 case R_PARISC_LTOFF_FPTR16WF
:
757 case R_PARISC_LTOFF_FPTR16DF
:
758 if (info
->shared
|| maybe_dynamic
)
759 need_entry
= (NEED_DLT
| NEED_OPD
| NEED_PLT
);
761 need_entry
= (NEED_DLT
| NEED_OPD
| NEED_PLT
);
762 dynrel_type
= R_PARISC_FPTR64
;
765 /* This is a simple OPD entry. */
766 case R_PARISC_FPTR64
:
767 if (info
->shared
|| maybe_dynamic
)
768 need_entry
= (NEED_OPD
| NEED_PLT
| NEED_DYNREL
);
770 need_entry
= (NEED_OPD
| NEED_PLT
);
771 dynrel_type
= R_PARISC_FPTR64
;
774 /* Add more cases as needed. */
782 /* Stash away enough information to be able to find this symbol
783 regardless of whether or not it is local or global. */
785 hh
->sym_indx
= r_symndx
;
788 /* Create what's needed. */
789 if (need_entry
& NEED_DLT
)
791 /* Allocate space for a DLT entry, as well as a dynamic
792 relocation for this entry. */
793 if (! hppa_info
->dlt_sec
794 && ! get_dlt (abfd
, info
, hppa_info
))
800 hh
->eh
.got
.refcount
+= 1;
804 bfd_signed_vma
*local_dlt_refcounts
;
806 /* This is a DLT entry for a local symbol. */
807 local_dlt_refcounts
= hppa64_elf_local_refcounts (abfd
);
808 if (local_dlt_refcounts
== NULL
)
810 local_dlt_refcounts
[r_symndx
] += 1;
814 if (need_entry
& NEED_PLT
)
816 if (! hppa_info
->plt_sec
817 && ! get_plt (abfd
, info
, hppa_info
))
823 hh
->eh
.needs_plt
= 1;
824 hh
->eh
.plt
.refcount
+= 1;
828 bfd_signed_vma
*local_dlt_refcounts
;
829 bfd_signed_vma
*local_plt_refcounts
;
831 /* This is a PLT entry for a local symbol. */
832 local_dlt_refcounts
= hppa64_elf_local_refcounts (abfd
);
833 if (local_dlt_refcounts
== NULL
)
835 local_plt_refcounts
= local_dlt_refcounts
+ symtab_hdr
->sh_info
;
836 local_plt_refcounts
[r_symndx
] += 1;
840 if (need_entry
& NEED_STUB
)
842 if (! hppa_info
->stub_sec
843 && ! get_stub (abfd
, info
, hppa_info
))
849 if (need_entry
& NEED_OPD
)
851 if (! hppa_info
->opd_sec
852 && ! get_opd (abfd
, info
, hppa_info
))
855 /* FPTRs are not allocated by the dynamic linker for PA64,
856 though it is possible that will change in the future. */
862 bfd_signed_vma
*local_dlt_refcounts
;
863 bfd_signed_vma
*local_opd_refcounts
;
865 /* This is a OPD for a local symbol. */
866 local_dlt_refcounts
= hppa64_elf_local_refcounts (abfd
);
867 if (local_dlt_refcounts
== NULL
)
869 local_opd_refcounts
= (local_dlt_refcounts
870 + 2 * symtab_hdr
->sh_info
);
871 local_opd_refcounts
[r_symndx
] += 1;
875 /* Add a new dynamic relocation to the chain of dynamic
876 relocations for this symbol. */
877 if ((need_entry
& NEED_DYNREL
) && (sec
->flags
& SEC_ALLOC
))
879 if (! hppa_info
->other_rel_sec
880 && ! get_reloc_section (abfd
, hppa_info
, sec
))
883 /* Count dynamic relocations against global symbols. */
885 && !count_dyn_reloc (abfd
, hh
, dynrel_type
, sec
,
886 sec_symndx
, rel
->r_offset
, rel
->r_addend
))
889 /* If we are building a shared library and we just recorded
890 a dynamic R_PARISC_FPTR64 relocation, then make sure the
891 section symbol for this section ends up in the dynamic
893 if (info
->shared
&& dynrel_type
== R_PARISC_FPTR64
894 && ! (bfd_elf_link_record_local_dynamic_symbol
895 (info
, abfd
, sec_symndx
)))
906 struct elf64_hppa_allocate_data
908 struct bfd_link_info
*info
;
912 /* Should we do dynamic things to this symbol? */
915 elf64_hppa_dynamic_symbol_p (struct elf_link_hash_entry
*eh
,
916 struct bfd_link_info
*info
)
918 /* ??? What, if anything, needs to happen wrt STV_PROTECTED symbols
919 and relocations that retrieve a function descriptor? Assume the
921 if (_bfd_elf_dynamic_symbol_p (eh
, info
, 1))
923 /* ??? Why is this here and not elsewhere is_local_label_name. */
924 if (eh
->root
.root
.string
[0] == '$' && eh
->root
.root
.string
[1] == '$')
933 /* Mark all functions exported by this file so that we can later allocate
934 entries in .opd for them. */
937 elf64_hppa_mark_exported_functions (struct elf_link_hash_entry
*eh
, void *data
)
939 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
940 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
941 struct elf64_hppa_link_hash_table
*hppa_info
;
943 hppa_info
= hppa_link_hash_table (info
);
944 if (hppa_info
== NULL
)
947 if (eh
->root
.type
== bfd_link_hash_warning
)
948 eh
= (struct elf_link_hash_entry
*) eh
->root
.u
.i
.link
;
951 && (eh
->root
.type
== bfd_link_hash_defined
952 || eh
->root
.type
== bfd_link_hash_defweak
)
953 && eh
->root
.u
.def
.section
->output_section
!= NULL
954 && eh
->type
== STT_FUNC
)
956 if (! hppa_info
->opd_sec
957 && ! get_opd (hppa_info
->root
.dynobj
, info
, hppa_info
))
962 /* Put a flag here for output_symbol_hook. */
970 /* Allocate space for a DLT entry. */
973 allocate_global_data_dlt (struct elf_link_hash_entry
*eh
, void *data
)
975 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
976 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
982 /* Possibly add the symbol to the local dynamic symbol
983 table since we might need to create a dynamic relocation
985 if (eh
->dynindx
== -1 && eh
->type
!= STT_PARISC_MILLI
)
987 bfd
*owner
= eh
->root
.u
.def
.section
->owner
;
989 if (! (bfd_elf_link_record_local_dynamic_symbol
990 (x
->info
, owner
, hh
->sym_indx
)))
995 hh
->dlt_offset
= x
->ofs
;
996 x
->ofs
+= DLT_ENTRY_SIZE
;
1001 /* Allocate space for a DLT.PLT entry. */
1004 allocate_global_data_plt (struct elf_link_hash_entry
*eh
, void *data
)
1006 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
1007 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*) data
;
1010 && elf64_hppa_dynamic_symbol_p (eh
, x
->info
)
1011 && !((eh
->root
.type
== bfd_link_hash_defined
1012 || eh
->root
.type
== bfd_link_hash_defweak
)
1013 && eh
->root
.u
.def
.section
->output_section
!= NULL
))
1015 hh
->plt_offset
= x
->ofs
;
1016 x
->ofs
+= PLT_ENTRY_SIZE
;
1017 if (hh
->plt_offset
< 0x2000)
1019 struct elf64_hppa_link_hash_table
*hppa_info
;
1021 hppa_info
= hppa_link_hash_table (x
->info
);
1022 if (hppa_info
== NULL
)
1025 hppa_info
->gp_offset
= hh
->plt_offset
;
1034 /* Allocate space for a STUB entry. */
1037 allocate_global_data_stub (struct elf_link_hash_entry
*eh
, void *data
)
1039 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
1040 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1043 && elf64_hppa_dynamic_symbol_p (eh
, x
->info
)
1044 && !((eh
->root
.type
== bfd_link_hash_defined
1045 || eh
->root
.type
== bfd_link_hash_defweak
)
1046 && eh
->root
.u
.def
.section
->output_section
!= NULL
))
1048 hh
->stub_offset
= x
->ofs
;
1049 x
->ofs
+= sizeof (plt_stub
);
1056 /* Allocate space for a FPTR entry. */
1059 allocate_global_data_opd (struct elf_link_hash_entry
*eh
, void *data
)
1061 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
1062 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1064 if (hh
&& hh
->want_opd
)
1066 while (hh
->eh
.root
.type
== bfd_link_hash_indirect
1067 || hh
->eh
.root
.type
== bfd_link_hash_warning
)
1068 hh
= hppa_elf_hash_entry (hh
->eh
.root
.u
.i
.link
);
1070 /* We never need an opd entry for a symbol which is not
1071 defined by this output file. */
1072 if (hh
&& (hh
->eh
.root
.type
== bfd_link_hash_undefined
1073 || hh
->eh
.root
.type
== bfd_link_hash_undefweak
1074 || hh
->eh
.root
.u
.def
.section
->output_section
== NULL
))
1077 /* If we are creating a shared library, took the address of a local
1078 function or might export this function from this object file, then
1079 we have to create an opd descriptor. */
1080 else if (x
->info
->shared
1082 || (hh
->eh
.dynindx
== -1 && hh
->eh
.type
!= STT_PARISC_MILLI
)
1083 || (hh
->eh
.root
.type
== bfd_link_hash_defined
1084 || hh
->eh
.root
.type
== bfd_link_hash_defweak
))
1086 /* If we are creating a shared library, then we will have to
1087 create a runtime relocation for the symbol to properly
1088 initialize the .opd entry. Make sure the symbol gets
1089 added to the dynamic symbol table. */
1091 && (hh
== NULL
|| (hh
->eh
.dynindx
== -1)))
1094 /* PR 6511: Default to using the dynamic symbol table. */
1095 owner
= (hh
->owner
? hh
->owner
: eh
->root
.u
.def
.section
->owner
);
1097 if (!bfd_elf_link_record_local_dynamic_symbol
1098 (x
->info
, owner
, hh
->sym_indx
))
1102 /* This may not be necessary or desirable anymore now that
1103 we have some support for dealing with section symbols
1104 in dynamic relocs. But name munging does make the result
1105 much easier to debug. ie, the EPLT reloc will reference
1106 a symbol like .foobar, instead of .text + offset. */
1107 if (x
->info
->shared
&& eh
)
1110 struct elf_link_hash_entry
*nh
;
1112 new_name
= alloca (strlen (eh
->root
.root
.string
) + 2);
1114 strcpy (new_name
+ 1, eh
->root
.root
.string
);
1116 nh
= elf_link_hash_lookup (elf_hash_table (x
->info
),
1117 new_name
, TRUE
, TRUE
, TRUE
);
1119 nh
->root
.type
= eh
->root
.type
;
1120 nh
->root
.u
.def
.value
= eh
->root
.u
.def
.value
;
1121 nh
->root
.u
.def
.section
= eh
->root
.u
.def
.section
;
1123 if (! bfd_elf_link_record_dynamic_symbol (x
->info
, nh
))
1127 hh
->opd_offset
= x
->ofs
;
1128 x
->ofs
+= OPD_ENTRY_SIZE
;
1131 /* Otherwise we do not need an opd entry. */
1138 /* HP requires the EI_OSABI field to be filled in. The assignment to
1139 EI_ABIVERSION may not be strictly necessary. */
1142 elf64_hppa_post_process_headers (bfd
*abfd
,
1143 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
)
1145 Elf_Internal_Ehdr
* i_ehdrp
;
1147 i_ehdrp
= elf_elfheader (abfd
);
1149 i_ehdrp
->e_ident
[EI_OSABI
] = get_elf_backend_data (abfd
)->elf_osabi
;
1150 i_ehdrp
->e_ident
[EI_ABIVERSION
] = 1;
1153 /* Create function descriptor section (.opd). This section is called .opd
1154 because it contains "official procedure descriptors". The "official"
1155 refers to the fact that these descriptors are used when taking the address
1156 of a procedure, thus ensuring a unique address for each procedure. */
1160 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1161 struct elf64_hppa_link_hash_table
*hppa_info
)
1166 opd
= hppa_info
->opd_sec
;
1169 dynobj
= hppa_info
->root
.dynobj
;
1171 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1173 opd
= bfd_make_section_with_flags (dynobj
, ".opd",
1178 | SEC_LINKER_CREATED
));
1180 || !bfd_set_section_alignment (abfd
, opd
, 3))
1186 hppa_info
->opd_sec
= opd
;
1192 /* Create the PLT section. */
1196 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1197 struct elf64_hppa_link_hash_table
*hppa_info
)
1202 plt
= hppa_info
->plt_sec
;
1205 dynobj
= hppa_info
->root
.dynobj
;
1207 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1209 plt
= bfd_make_section_with_flags (dynobj
, ".plt",
1214 | SEC_LINKER_CREATED
));
1216 || !bfd_set_section_alignment (abfd
, plt
, 3))
1222 hppa_info
->plt_sec
= plt
;
1228 /* Create the DLT section. */
1232 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1233 struct elf64_hppa_link_hash_table
*hppa_info
)
1238 dlt
= hppa_info
->dlt_sec
;
1241 dynobj
= hppa_info
->root
.dynobj
;
1243 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1245 dlt
= bfd_make_section_with_flags (dynobj
, ".dlt",
1250 | SEC_LINKER_CREATED
));
1252 || !bfd_set_section_alignment (abfd
, dlt
, 3))
1258 hppa_info
->dlt_sec
= dlt
;
1264 /* Create the stubs section. */
1267 get_stub (bfd
*abfd
,
1268 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1269 struct elf64_hppa_link_hash_table
*hppa_info
)
1274 stub
= hppa_info
->stub_sec
;
1277 dynobj
= hppa_info
->root
.dynobj
;
1279 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1281 stub
= bfd_make_section_with_flags (dynobj
, ".stub",
1282 (SEC_ALLOC
| SEC_LOAD
1286 | SEC_LINKER_CREATED
));
1288 || !bfd_set_section_alignment (abfd
, stub
, 3))
1294 hppa_info
->stub_sec
= stub
;
1300 /* Create sections necessary for dynamic linking. This is only a rough
1301 cut and will likely change as we learn more about the somewhat
1302 unusual dynamic linking scheme HP uses.
1305 Contains code to implement cross-space calls. The first time one
1306 of the stubs is used it will call into the dynamic linker, later
1307 calls will go straight to the target.
1309 The only stub we support right now looks like
1313 ldd OFFSET+8(%dp),%dp
1315 Other stubs may be needed in the future. We may want the remove
1316 the break/nop instruction. It is only used right now to keep the
1317 offset of a .plt entry and a .stub entry in sync.
1320 This is what most people call the .got. HP used a different name.
1324 Relocations for the DLT.
1327 Function pointers as address,gp pairs.
1330 Should contain dynamic IPLT (and EPLT?) relocations.
1336 EPLT relocations for symbols exported from shared libraries. */
1339 elf64_hppa_create_dynamic_sections (bfd
*abfd
,
1340 struct bfd_link_info
*info
)
1343 struct elf64_hppa_link_hash_table
*hppa_info
;
1345 hppa_info
= hppa_link_hash_table (info
);
1346 if (hppa_info
== NULL
)
1349 if (! get_stub (abfd
, info
, hppa_info
))
1352 if (! get_dlt (abfd
, info
, hppa_info
))
1355 if (! get_plt (abfd
, info
, hppa_info
))
1358 if (! get_opd (abfd
, info
, hppa_info
))
1361 s
= bfd_make_section_with_flags (abfd
, ".rela.dlt",
1362 (SEC_ALLOC
| SEC_LOAD
1366 | SEC_LINKER_CREATED
));
1368 || !bfd_set_section_alignment (abfd
, s
, 3))
1370 hppa_info
->dlt_rel_sec
= s
;
1372 s
= bfd_make_section_with_flags (abfd
, ".rela.plt",
1373 (SEC_ALLOC
| SEC_LOAD
1377 | SEC_LINKER_CREATED
));
1379 || !bfd_set_section_alignment (abfd
, s
, 3))
1381 hppa_info
->plt_rel_sec
= s
;
1383 s
= bfd_make_section_with_flags (abfd
, ".rela.data",
1384 (SEC_ALLOC
| SEC_LOAD
1388 | SEC_LINKER_CREATED
));
1390 || !bfd_set_section_alignment (abfd
, s
, 3))
1392 hppa_info
->other_rel_sec
= s
;
1394 s
= bfd_make_section_with_flags (abfd
, ".rela.opd",
1395 (SEC_ALLOC
| SEC_LOAD
1399 | SEC_LINKER_CREATED
));
1401 || !bfd_set_section_alignment (abfd
, s
, 3))
1403 hppa_info
->opd_rel_sec
= s
;
1408 /* Allocate dynamic relocations for those symbols that turned out
1412 allocate_dynrel_entries (struct elf_link_hash_entry
*eh
, void *data
)
1414 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
1415 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1416 struct elf64_hppa_link_hash_table
*hppa_info
;
1417 struct elf64_hppa_dyn_reloc_entry
*rent
;
1418 bfd_boolean dynamic_symbol
, shared
;
1420 hppa_info
= hppa_link_hash_table (x
->info
);
1421 if (hppa_info
== NULL
)
1424 dynamic_symbol
= elf64_hppa_dynamic_symbol_p (eh
, x
->info
);
1425 shared
= x
->info
->shared
;
1427 /* We may need to allocate relocations for a non-dynamic symbol
1428 when creating a shared library. */
1429 if (!dynamic_symbol
&& !shared
)
1432 /* Take care of the normal data relocations. */
1434 for (rent
= hh
->reloc_entries
; rent
; rent
= rent
->next
)
1436 /* Allocate one iff we are building a shared library, the relocation
1437 isn't a R_PARISC_FPTR64, or we don't want an opd entry. */
1438 if (!shared
&& rent
->type
== R_PARISC_FPTR64
&& hh
->want_opd
)
1441 hppa_info
->other_rel_sec
->size
+= sizeof (Elf64_External_Rela
);
1443 /* Make sure this symbol gets into the dynamic symbol table if it is
1444 not already recorded. ?!? This should not be in the loop since
1445 the symbol need only be added once. */
1446 if (eh
->dynindx
== -1 && eh
->type
!= STT_PARISC_MILLI
)
1447 if (!bfd_elf_link_record_local_dynamic_symbol
1448 (x
->info
, rent
->sec
->owner
, hh
->sym_indx
))
1452 /* Take care of the GOT and PLT relocations. */
1454 if ((dynamic_symbol
|| shared
) && hh
->want_dlt
)
1455 hppa_info
->dlt_rel_sec
->size
+= sizeof (Elf64_External_Rela
);
1457 /* If we are building a shared library, then every symbol that has an
1458 opd entry will need an EPLT relocation to relocate the symbol's address
1459 and __gp value based on the runtime load address. */
1460 if (shared
&& hh
->want_opd
)
1461 hppa_info
->opd_rel_sec
->size
+= sizeof (Elf64_External_Rela
);
1463 if (hh
->want_plt
&& dynamic_symbol
)
1465 bfd_size_type t
= 0;
1467 /* Dynamic symbols get one IPLT relocation. Local symbols in
1468 shared libraries get two REL relocations. Local symbols in
1469 main applications get nothing. */
1471 t
= sizeof (Elf64_External_Rela
);
1473 t
= 2 * sizeof (Elf64_External_Rela
);
1475 hppa_info
->plt_rel_sec
->size
+= t
;
1481 /* Adjust a symbol defined by a dynamic object and referenced by a
1485 elf64_hppa_adjust_dynamic_symbol (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1486 struct elf_link_hash_entry
*eh
)
1488 /* ??? Undefined symbols with PLT entries should be re-defined
1489 to be the PLT entry. */
1491 /* If this is a weak symbol, and there is a real definition, the
1492 processor independent code will have arranged for us to see the
1493 real definition first, and we can just use the same value. */
1494 if (eh
->u
.weakdef
!= NULL
)
1496 BFD_ASSERT (eh
->u
.weakdef
->root
.type
== bfd_link_hash_defined
1497 || eh
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
1498 eh
->root
.u
.def
.section
= eh
->u
.weakdef
->root
.u
.def
.section
;
1499 eh
->root
.u
.def
.value
= eh
->u
.weakdef
->root
.u
.def
.value
;
1503 /* If this is a reference to a symbol defined by a dynamic object which
1504 is not a function, we might allocate the symbol in our .dynbss section
1505 and allocate a COPY dynamic relocation.
1507 But PA64 code is canonically PIC, so as a rule we can avoid this sort
1513 /* This function is called via elf_link_hash_traverse to mark millicode
1514 symbols with a dynindx of -1 and to remove the string table reference
1515 from the dynamic symbol table. If the symbol is not a millicode symbol,
1516 elf64_hppa_mark_exported_functions is called. */
1519 elf64_hppa_mark_milli_and_exported_functions (struct elf_link_hash_entry
*eh
,
1522 struct elf_link_hash_entry
*elf
= eh
;
1523 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
1525 if (elf
->root
.type
== bfd_link_hash_warning
)
1526 elf
= (struct elf_link_hash_entry
*) elf
->root
.u
.i
.link
;
1528 if (elf
->type
== STT_PARISC_MILLI
)
1530 if (elf
->dynindx
!= -1)
1533 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
1539 return elf64_hppa_mark_exported_functions (eh
, data
);
1542 /* Set the final sizes of the dynamic sections and allocate memory for
1543 the contents of our special sections. */
1546 elf64_hppa_size_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
1548 struct elf64_hppa_link_hash_table
*hppa_info
;
1549 struct elf64_hppa_allocate_data data
;
1555 bfd_boolean reltext
;
1557 hppa_info
= hppa_link_hash_table (info
);
1558 if (hppa_info
== NULL
)
1561 dynobj
= elf_hash_table (info
)->dynobj
;
1562 BFD_ASSERT (dynobj
!= NULL
);
1564 /* Mark each function this program exports so that we will allocate
1565 space in the .opd section for each function's FPTR. If we are
1566 creating dynamic sections, change the dynamic index of millicode
1567 symbols to -1 and remove them from the string table for .dynstr.
1569 We have to traverse the main linker hash table since we have to
1570 find functions which may not have been mentioned in any relocs. */
1571 elf_link_hash_traverse (elf_hash_table (info
),
1572 (elf_hash_table (info
)->dynamic_sections_created
1573 ? elf64_hppa_mark_milli_and_exported_functions
1574 : elf64_hppa_mark_exported_functions
),
1577 if (elf_hash_table (info
)->dynamic_sections_created
)
1579 /* Set the contents of the .interp section to the interpreter. */
1580 if (info
->executable
)
1582 sec
= bfd_get_section_by_name (dynobj
, ".interp");
1583 BFD_ASSERT (sec
!= NULL
);
1584 sec
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1585 sec
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1590 /* We may have created entries in the .rela.got section.
1591 However, if we are not creating the dynamic sections, we will
1592 not actually use these entries. Reset the size of .rela.dlt,
1593 which will cause it to get stripped from the output file
1595 sec
= bfd_get_section_by_name (dynobj
, ".rela.dlt");
1600 /* Set up DLT, PLT and OPD offsets for local syms, and space for local
1602 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
1604 bfd_signed_vma
*local_dlt
;
1605 bfd_signed_vma
*end_local_dlt
;
1606 bfd_signed_vma
*local_plt
;
1607 bfd_signed_vma
*end_local_plt
;
1608 bfd_signed_vma
*local_opd
;
1609 bfd_signed_vma
*end_local_opd
;
1610 bfd_size_type locsymcount
;
1611 Elf_Internal_Shdr
*symtab_hdr
;
1614 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
1617 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1619 struct elf64_hppa_dyn_reloc_entry
*hdh_p
;
1621 for (hdh_p
= ((struct elf64_hppa_dyn_reloc_entry
*)
1622 elf_section_data (sec
)->local_dynrel
);
1624 hdh_p
= hdh_p
->next
)
1626 if (!bfd_is_abs_section (hdh_p
->sec
)
1627 && bfd_is_abs_section (hdh_p
->sec
->output_section
))
1629 /* Input section has been discarded, either because
1630 it is a copy of a linkonce section or due to
1631 linker script /DISCARD/, so we'll be discarding
1634 else if (hdh_p
->count
!= 0)
1636 srel
= elf_section_data (hdh_p
->sec
)->sreloc
;
1637 srel
->size
+= hdh_p
->count
* sizeof (Elf64_External_Rela
);
1638 if ((hdh_p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
1639 info
->flags
|= DF_TEXTREL
;
1644 local_dlt
= elf_local_got_refcounts (ibfd
);
1648 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
1649 locsymcount
= symtab_hdr
->sh_info
;
1650 end_local_dlt
= local_dlt
+ locsymcount
;
1651 sec
= hppa_info
->dlt_sec
;
1652 srel
= hppa_info
->dlt_rel_sec
;
1653 for (; local_dlt
< end_local_dlt
; ++local_dlt
)
1657 *local_dlt
= sec
->size
;
1658 sec
->size
+= DLT_ENTRY_SIZE
;
1661 srel
->size
+= sizeof (Elf64_External_Rela
);
1665 *local_dlt
= (bfd_vma
) -1;
1668 local_plt
= end_local_dlt
;
1669 end_local_plt
= local_plt
+ locsymcount
;
1670 if (! hppa_info
->root
.dynamic_sections_created
)
1672 /* Won't be used, but be safe. */
1673 for (; local_plt
< end_local_plt
; ++local_plt
)
1674 *local_plt
= (bfd_vma
) -1;
1678 sec
= hppa_info
->plt_sec
;
1679 srel
= hppa_info
->plt_rel_sec
;
1680 for (; local_plt
< end_local_plt
; ++local_plt
)
1684 *local_plt
= sec
->size
;
1685 sec
->size
+= PLT_ENTRY_SIZE
;
1687 srel
->size
+= sizeof (Elf64_External_Rela
);
1690 *local_plt
= (bfd_vma
) -1;
1694 local_opd
= end_local_plt
;
1695 end_local_opd
= local_opd
+ locsymcount
;
1696 if (! hppa_info
->root
.dynamic_sections_created
)
1698 /* Won't be used, but be safe. */
1699 for (; local_opd
< end_local_opd
; ++local_opd
)
1700 *local_opd
= (bfd_vma
) -1;
1704 sec
= hppa_info
->opd_sec
;
1705 srel
= hppa_info
->opd_rel_sec
;
1706 for (; local_opd
< end_local_opd
; ++local_opd
)
1710 *local_opd
= sec
->size
;
1711 sec
->size
+= OPD_ENTRY_SIZE
;
1713 srel
->size
+= sizeof (Elf64_External_Rela
);
1716 *local_opd
= (bfd_vma
) -1;
1721 /* Allocate the GOT entries. */
1724 if (hppa_info
->dlt_sec
)
1726 data
.ofs
= hppa_info
->dlt_sec
->size
;
1727 elf_link_hash_traverse (elf_hash_table (info
),
1728 allocate_global_data_dlt
, &data
);
1729 hppa_info
->dlt_sec
->size
= data
.ofs
;
1732 if (hppa_info
->plt_sec
)
1734 data
.ofs
= hppa_info
->plt_sec
->size
;
1735 elf_link_hash_traverse (elf_hash_table (info
),
1736 allocate_global_data_plt
, &data
);
1737 hppa_info
->plt_sec
->size
= data
.ofs
;
1740 if (hppa_info
->stub_sec
)
1743 elf_link_hash_traverse (elf_hash_table (info
),
1744 allocate_global_data_stub
, &data
);
1745 hppa_info
->stub_sec
->size
= data
.ofs
;
1748 /* Allocate space for entries in the .opd section. */
1749 if (hppa_info
->opd_sec
)
1751 data
.ofs
= hppa_info
->opd_sec
->size
;
1752 elf_link_hash_traverse (elf_hash_table (info
),
1753 allocate_global_data_opd
, &data
);
1754 hppa_info
->opd_sec
->size
= data
.ofs
;
1757 /* Now allocate space for dynamic relocations, if necessary. */
1758 if (hppa_info
->root
.dynamic_sections_created
)
1759 elf_link_hash_traverse (elf_hash_table (info
),
1760 allocate_dynrel_entries
, &data
);
1762 /* The sizes of all the sections are set. Allocate memory for them. */
1766 for (sec
= dynobj
->sections
; sec
!= NULL
; sec
= sec
->next
)
1770 if ((sec
->flags
& SEC_LINKER_CREATED
) == 0)
1773 /* It's OK to base decisions on the section name, because none
1774 of the dynobj section names depend upon the input files. */
1775 name
= bfd_get_section_name (dynobj
, sec
);
1777 if (strcmp (name
, ".plt") == 0)
1779 /* Remember whether there is a PLT. */
1780 plt
= sec
->size
!= 0;
1782 else if (strcmp (name
, ".opd") == 0
1783 || CONST_STRNEQ (name
, ".dlt")
1784 || strcmp (name
, ".stub") == 0
1785 || strcmp (name
, ".got") == 0)
1787 /* Strip this section if we don't need it; see the comment below. */
1789 else if (CONST_STRNEQ (name
, ".rela"))
1795 /* Remember whether there are any reloc sections other
1797 if (strcmp (name
, ".rela.plt") != 0)
1799 const char *outname
;
1803 /* If this relocation section applies to a read only
1804 section, then we probably need a DT_TEXTREL
1805 entry. The entries in the .rela.plt section
1806 really apply to the .got section, which we
1807 created ourselves and so know is not readonly. */
1808 outname
= bfd_get_section_name (output_bfd
,
1809 sec
->output_section
);
1810 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
1812 && (target
->flags
& SEC_READONLY
) != 0
1813 && (target
->flags
& SEC_ALLOC
) != 0)
1817 /* We use the reloc_count field as a counter if we need
1818 to copy relocs into the output file. */
1819 sec
->reloc_count
= 0;
1824 /* It's not one of our sections, so don't allocate space. */
1830 /* If we don't need this section, strip it from the
1831 output file. This is mostly to handle .rela.bss and
1832 .rela.plt. We must create both sections in
1833 create_dynamic_sections, because they must be created
1834 before the linker maps input sections to output
1835 sections. The linker does that before
1836 adjust_dynamic_symbol is called, and it is that
1837 function which decides whether anything needs to go
1838 into these sections. */
1839 sec
->flags
|= SEC_EXCLUDE
;
1843 if ((sec
->flags
& SEC_HAS_CONTENTS
) == 0)
1846 /* Allocate memory for the section contents if it has not
1847 been allocated already. We use bfd_zalloc here in case
1848 unused entries are not reclaimed before the section's
1849 contents are written out. This should not happen, but this
1850 way if it does, we get a R_PARISC_NONE reloc instead of
1852 if (sec
->contents
== NULL
)
1854 sec
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, sec
->size
);
1855 if (sec
->contents
== NULL
)
1860 if (elf_hash_table (info
)->dynamic_sections_created
)
1862 /* Always create a DT_PLTGOT. It actually has nothing to do with
1863 the PLT, it is how we communicate the __gp value of a load
1864 module to the dynamic linker. */
1865 #define add_dynamic_entry(TAG, VAL) \
1866 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
1868 if (!add_dynamic_entry (DT_HP_DLD_FLAGS
, 0)
1869 || !add_dynamic_entry (DT_PLTGOT
, 0))
1872 /* Add some entries to the .dynamic section. We fill in the
1873 values later, in elf64_hppa_finish_dynamic_sections, but we
1874 must add the entries now so that we get the correct size for
1875 the .dynamic section. The DT_DEBUG entry is filled in by the
1876 dynamic linker and used by the debugger. */
1879 if (!add_dynamic_entry (DT_DEBUG
, 0)
1880 || !add_dynamic_entry (DT_HP_DLD_HOOK
, 0)
1881 || !add_dynamic_entry (DT_HP_LOAD_MAP
, 0))
1885 /* Force DT_FLAGS to always be set.
1886 Required by HPUX 11.00 patch PHSS_26559. */
1887 if (!add_dynamic_entry (DT_FLAGS
, (info
)->flags
))
1892 if (!add_dynamic_entry (DT_PLTRELSZ
, 0)
1893 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
1894 || !add_dynamic_entry (DT_JMPREL
, 0))
1900 if (!add_dynamic_entry (DT_RELA
, 0)
1901 || !add_dynamic_entry (DT_RELASZ
, 0)
1902 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
1908 if (!add_dynamic_entry (DT_TEXTREL
, 0))
1910 info
->flags
|= DF_TEXTREL
;
1913 #undef add_dynamic_entry
1918 /* Called after we have output the symbol into the dynamic symbol
1919 table, but before we output the symbol into the normal symbol
1922 For some symbols we had to change their address when outputting
1923 the dynamic symbol table. We undo that change here so that
1924 the symbols have their expected value in the normal symbol
1928 elf64_hppa_link_output_symbol_hook (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1930 Elf_Internal_Sym
*sym
,
1931 asection
*input_sec ATTRIBUTE_UNUSED
,
1932 struct elf_link_hash_entry
*eh
)
1934 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
1936 /* We may be called with the file symbol or section symbols.
1937 They never need munging, so it is safe to ignore them. */
1941 /* Function symbols for which we created .opd entries *may* have been
1942 munged by finish_dynamic_symbol and have to be un-munged here.
1944 Note that finish_dynamic_symbol sometimes turns dynamic symbols
1945 into non-dynamic ones, so we initialize st_shndx to -1 in
1946 mark_exported_functions and check to see if it was overwritten
1947 here instead of just checking eh->dynindx. */
1948 if (hh
->want_opd
&& hh
->st_shndx
!= -1)
1950 /* Restore the saved value and section index. */
1951 sym
->st_value
= hh
->st_value
;
1952 sym
->st_shndx
= hh
->st_shndx
;
1958 /* Finish up dynamic symbol handling. We set the contents of various
1959 dynamic sections here. */
1962 elf64_hppa_finish_dynamic_symbol (bfd
*output_bfd
,
1963 struct bfd_link_info
*info
,
1964 struct elf_link_hash_entry
*eh
,
1965 Elf_Internal_Sym
*sym
)
1967 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
1968 asection
*stub
, *splt
, *sopd
, *spltrel
;
1969 struct elf64_hppa_link_hash_table
*hppa_info
;
1971 hppa_info
= hppa_link_hash_table (info
);
1972 if (hppa_info
== NULL
)
1975 stub
= hppa_info
->stub_sec
;
1976 splt
= hppa_info
->plt_sec
;
1977 sopd
= hppa_info
->opd_sec
;
1978 spltrel
= hppa_info
->plt_rel_sec
;
1980 /* Incredible. It is actually necessary to NOT use the symbol's real
1981 value when building the dynamic symbol table for a shared library.
1982 At least for symbols that refer to functions.
1984 We will store a new value and section index into the symbol long
1985 enough to output it into the dynamic symbol table, then we restore
1986 the original values (in elf64_hppa_link_output_symbol_hook). */
1989 BFD_ASSERT (sopd
!= NULL
);
1991 /* Save away the original value and section index so that we
1992 can restore them later. */
1993 hh
->st_value
= sym
->st_value
;
1994 hh
->st_shndx
= sym
->st_shndx
;
1996 /* For the dynamic symbol table entry, we want the value to be
1997 address of this symbol's entry within the .opd section. */
1998 sym
->st_value
= (hh
->opd_offset
1999 + sopd
->output_offset
2000 + sopd
->output_section
->vma
);
2001 sym
->st_shndx
= _bfd_elf_section_from_bfd_section (output_bfd
,
2002 sopd
->output_section
);
2005 /* Initialize a .plt entry if requested. */
2007 && elf64_hppa_dynamic_symbol_p (eh
, info
))
2010 Elf_Internal_Rela rel
;
2013 BFD_ASSERT (splt
!= NULL
&& spltrel
!= NULL
);
2015 /* We do not actually care about the value in the PLT entry
2016 if we are creating a shared library and the symbol is
2017 still undefined, we create a dynamic relocation to fill
2018 in the correct value. */
2019 if (info
->shared
&& eh
->root
.type
== bfd_link_hash_undefined
)
2022 value
= (eh
->root
.u
.def
.value
+ eh
->root
.u
.def
.section
->vma
);
2024 /* Fill in the entry in the procedure linkage table.
2026 The format of a plt entry is
2029 plt_offset is the offset within the PLT section at which to
2030 install the PLT entry.
2032 We are modifying the in-memory PLT contents here, so we do not add
2033 in the output_offset of the PLT section. */
2035 bfd_put_64 (splt
->owner
, value
, splt
->contents
+ hh
->plt_offset
);
2036 value
= _bfd_get_gp_value (splt
->output_section
->owner
);
2037 bfd_put_64 (splt
->owner
, value
, splt
->contents
+ hh
->plt_offset
+ 0x8);
2039 /* Create a dynamic IPLT relocation for this entry.
2041 We are creating a relocation in the output file's PLT section,
2042 which is included within the DLT secton. So we do need to include
2043 the PLT's output_offset in the computation of the relocation's
2045 rel
.r_offset
= (hh
->plt_offset
+ splt
->output_offset
2046 + splt
->output_section
->vma
);
2047 rel
.r_info
= ELF64_R_INFO (hh
->eh
.dynindx
, R_PARISC_IPLT
);
2050 loc
= spltrel
->contents
;
2051 loc
+= spltrel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2052 bfd_elf64_swap_reloca_out (splt
->output_section
->owner
, &rel
, loc
);
2055 /* Initialize an external call stub entry if requested. */
2057 && elf64_hppa_dynamic_symbol_p (eh
, info
))
2061 unsigned int max_offset
;
2063 BFD_ASSERT (stub
!= NULL
);
2065 /* Install the generic stub template.
2067 We are modifying the contents of the stub section, so we do not
2068 need to include the stub section's output_offset here. */
2069 memcpy (stub
->contents
+ hh
->stub_offset
, plt_stub
, sizeof (plt_stub
));
2071 /* Fix up the first ldd instruction.
2073 We are modifying the contents of the STUB section in memory,
2074 so we do not need to include its output offset in this computation.
2076 Note the plt_offset value is the value of the PLT entry relative to
2077 the start of the PLT section. These instructions will reference
2078 data relative to the value of __gp, which may not necessarily have
2079 the same address as the start of the PLT section.
2081 gp_offset contains the offset of __gp within the PLT section. */
2082 value
= hh
->plt_offset
- hppa_info
->gp_offset
;
2084 insn
= bfd_get_32 (stub
->owner
, stub
->contents
+ hh
->stub_offset
);
2085 if (output_bfd
->arch_info
->mach
>= 25)
2087 /* Wide mode allows 16 bit offsets. */
2090 insn
|= re_assemble_16 ((int) value
);
2096 insn
|= re_assemble_14 ((int) value
);
2099 if ((value
& 7) || value
+ max_offset
>= 2*max_offset
- 8)
2101 (*_bfd_error_handler
) (_("stub entry for %s cannot load .plt, dp offset = %ld"),
2102 hh
->eh
.root
.root
.string
,
2107 bfd_put_32 (stub
->owner
, (bfd_vma
) insn
,
2108 stub
->contents
+ hh
->stub_offset
);
2110 /* Fix up the second ldd instruction. */
2112 insn
= bfd_get_32 (stub
->owner
, stub
->contents
+ hh
->stub_offset
+ 8);
2113 if (output_bfd
->arch_info
->mach
>= 25)
2116 insn
|= re_assemble_16 ((int) value
);
2121 insn
|= re_assemble_14 ((int) value
);
2123 bfd_put_32 (stub
->owner
, (bfd_vma
) insn
,
2124 stub
->contents
+ hh
->stub_offset
+ 8);
2130 /* The .opd section contains FPTRs for each function this file
2131 exports. Initialize the FPTR entries. */
2134 elf64_hppa_finalize_opd (struct elf_link_hash_entry
*eh
, void *data
)
2136 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
2137 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
2138 struct elf64_hppa_link_hash_table
*hppa_info
;
2142 hppa_info
= hppa_link_hash_table (info
);
2143 if (hppa_info
== NULL
)
2146 sopd
= hppa_info
->opd_sec
;
2147 sopdrel
= hppa_info
->opd_rel_sec
;
2153 /* The first two words of an .opd entry are zero.
2155 We are modifying the contents of the OPD section in memory, so we
2156 do not need to include its output offset in this computation. */
2157 memset (sopd
->contents
+ hh
->opd_offset
, 0, 16);
2159 value
= (eh
->root
.u
.def
.value
2160 + eh
->root
.u
.def
.section
->output_section
->vma
2161 + eh
->root
.u
.def
.section
->output_offset
);
2163 /* The next word is the address of the function. */
2164 bfd_put_64 (sopd
->owner
, value
, sopd
->contents
+ hh
->opd_offset
+ 16);
2166 /* The last word is our local __gp value. */
2167 value
= _bfd_get_gp_value (sopd
->output_section
->owner
);
2168 bfd_put_64 (sopd
->owner
, value
, sopd
->contents
+ hh
->opd_offset
+ 24);
2171 /* If we are generating a shared library, we must generate EPLT relocations
2172 for each entry in the .opd, even for static functions (they may have
2173 had their address taken). */
2174 if (info
->shared
&& hh
->want_opd
)
2176 Elf_Internal_Rela rel
;
2180 /* We may need to do a relocation against a local symbol, in
2181 which case we have to look up it's dynamic symbol index off
2182 the local symbol hash table. */
2183 if (eh
->dynindx
!= -1)
2184 dynindx
= eh
->dynindx
;
2187 = _bfd_elf_link_lookup_local_dynindx (info
, hh
->owner
,
2190 /* The offset of this relocation is the absolute address of the
2191 .opd entry for this symbol. */
2192 rel
.r_offset
= (hh
->opd_offset
+ sopd
->output_offset
2193 + sopd
->output_section
->vma
);
2195 /* If H is non-null, then we have an external symbol.
2197 It is imperative that we use a different dynamic symbol for the
2198 EPLT relocation if the symbol has global scope.
2200 In the dynamic symbol table, the function symbol will have a value
2201 which is address of the function's .opd entry.
2203 Thus, we can not use that dynamic symbol for the EPLT relocation
2204 (if we did, the data in the .opd would reference itself rather
2205 than the actual address of the function). Instead we have to use
2206 a new dynamic symbol which has the same value as the original global
2209 We prefix the original symbol with a "." and use the new symbol in
2210 the EPLT relocation. This new symbol has already been recorded in
2211 the symbol table, we just have to look it up and use it.
2213 We do not have such problems with static functions because we do
2214 not make their addresses in the dynamic symbol table point to
2215 the .opd entry. Ultimately this should be safe since a static
2216 function can not be directly referenced outside of its shared
2219 We do have to play similar games for FPTR relocations in shared
2220 libraries, including those for static symbols. See the FPTR
2221 handling in elf64_hppa_finalize_dynreloc. */
2225 struct elf_link_hash_entry
*nh
;
2227 new_name
= alloca (strlen (eh
->root
.root
.string
) + 2);
2229 strcpy (new_name
+ 1, eh
->root
.root
.string
);
2231 nh
= elf_link_hash_lookup (elf_hash_table (info
),
2232 new_name
, TRUE
, TRUE
, FALSE
);
2234 /* All we really want from the new symbol is its dynamic
2237 dynindx
= nh
->dynindx
;
2241 rel
.r_info
= ELF64_R_INFO (dynindx
, R_PARISC_EPLT
);
2243 loc
= sopdrel
->contents
;
2244 loc
+= sopdrel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2245 bfd_elf64_swap_reloca_out (sopd
->output_section
->owner
, &rel
, loc
);
2250 /* The .dlt section contains addresses for items referenced through the
2251 dlt. Note that we can have a DLTIND relocation for a local symbol, thus
2252 we can not depend on finish_dynamic_symbol to initialize the .dlt. */
2255 elf64_hppa_finalize_dlt (struct elf_link_hash_entry
*eh
, void *data
)
2257 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
2258 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
2259 struct elf64_hppa_link_hash_table
*hppa_info
;
2260 asection
*sdlt
, *sdltrel
;
2262 hppa_info
= hppa_link_hash_table (info
);
2263 if (hppa_info
== NULL
)
2266 sdlt
= hppa_info
->dlt_sec
;
2267 sdltrel
= hppa_info
->dlt_rel_sec
;
2269 /* H/DYN_H may refer to a local variable and we know it's
2270 address, so there is no need to create a relocation. Just install
2271 the proper value into the DLT, note this shortcut can not be
2272 skipped when building a shared library. */
2273 if (! info
->shared
&& hh
&& hh
->want_dlt
)
2277 /* If we had an LTOFF_FPTR style relocation we want the DLT entry
2278 to point to the FPTR entry in the .opd section.
2280 We include the OPD's output offset in this computation as
2281 we are referring to an absolute address in the resulting
2285 value
= (hh
->opd_offset
2286 + hppa_info
->opd_sec
->output_offset
2287 + hppa_info
->opd_sec
->output_section
->vma
);
2289 else if ((eh
->root
.type
== bfd_link_hash_defined
2290 || eh
->root
.type
== bfd_link_hash_defweak
)
2291 && eh
->root
.u
.def
.section
)
2293 value
= eh
->root
.u
.def
.value
+ eh
->root
.u
.def
.section
->output_offset
;
2294 if (eh
->root
.u
.def
.section
->output_section
)
2295 value
+= eh
->root
.u
.def
.section
->output_section
->vma
;
2297 value
+= eh
->root
.u
.def
.section
->vma
;
2300 /* We have an undefined function reference. */
2303 /* We do not need to include the output offset of the DLT section
2304 here because we are modifying the in-memory contents. */
2305 bfd_put_64 (sdlt
->owner
, value
, sdlt
->contents
+ hh
->dlt_offset
);
2308 /* Create a relocation for the DLT entry associated with this symbol.
2309 When building a shared library the symbol does not have to be dynamic. */
2311 && (elf64_hppa_dynamic_symbol_p (eh
, info
) || info
->shared
))
2313 Elf_Internal_Rela rel
;
2317 /* We may need to do a relocation against a local symbol, in
2318 which case we have to look up it's dynamic symbol index off
2319 the local symbol hash table. */
2320 if (eh
&& eh
->dynindx
!= -1)
2321 dynindx
= eh
->dynindx
;
2324 = _bfd_elf_link_lookup_local_dynindx (info
, hh
->owner
,
2327 /* Create a dynamic relocation for this entry. Do include the output
2328 offset of the DLT entry since we need an absolute address in the
2329 resulting object file. */
2330 rel
.r_offset
= (hh
->dlt_offset
+ sdlt
->output_offset
2331 + sdlt
->output_section
->vma
);
2332 if (eh
&& eh
->type
== STT_FUNC
)
2333 rel
.r_info
= ELF64_R_INFO (dynindx
, R_PARISC_FPTR64
);
2335 rel
.r_info
= ELF64_R_INFO (dynindx
, R_PARISC_DIR64
);
2338 loc
= sdltrel
->contents
;
2339 loc
+= sdltrel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2340 bfd_elf64_swap_reloca_out (sdlt
->output_section
->owner
, &rel
, loc
);
2345 /* Finalize the dynamic relocations. Specifically the FPTR relocations
2346 for dynamic functions used to initialize static data. */
2349 elf64_hppa_finalize_dynreloc (struct elf_link_hash_entry
*eh
,
2352 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
2353 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
2354 struct elf64_hppa_link_hash_table
*hppa_info
;
2357 dynamic_symbol
= elf64_hppa_dynamic_symbol_p (eh
, info
);
2359 if (!dynamic_symbol
&& !info
->shared
)
2362 if (hh
->reloc_entries
)
2364 struct elf64_hppa_dyn_reloc_entry
*rent
;
2367 hppa_info
= hppa_link_hash_table (info
);
2368 if (hppa_info
== NULL
)
2371 /* We may need to do a relocation against a local symbol, in
2372 which case we have to look up it's dynamic symbol index off
2373 the local symbol hash table. */
2374 if (eh
->dynindx
!= -1)
2375 dynindx
= eh
->dynindx
;
2378 = _bfd_elf_link_lookup_local_dynindx (info
, hh
->owner
,
2381 for (rent
= hh
->reloc_entries
; rent
; rent
= rent
->next
)
2383 Elf_Internal_Rela rel
;
2386 /* Allocate one iff we are building a shared library, the relocation
2387 isn't a R_PARISC_FPTR64, or we don't want an opd entry. */
2388 if (!info
->shared
&& rent
->type
== R_PARISC_FPTR64
&& hh
->want_opd
)
2391 /* Create a dynamic relocation for this entry.
2393 We need the output offset for the reloc's section because
2394 we are creating an absolute address in the resulting object
2396 rel
.r_offset
= (rent
->offset
+ rent
->sec
->output_offset
2397 + rent
->sec
->output_section
->vma
);
2399 /* An FPTR64 relocation implies that we took the address of
2400 a function and that the function has an entry in the .opd
2401 section. We want the FPTR64 relocation to reference the
2404 We could munge the symbol value in the dynamic symbol table
2405 (in fact we already do for functions with global scope) to point
2406 to the .opd entry. Then we could use that dynamic symbol in
2409 Or we could do something sensible, not munge the symbol's
2410 address and instead just use a different symbol to reference
2411 the .opd entry. At least that seems sensible until you
2412 realize there's no local dynamic symbols we can use for that
2413 purpose. Thus the hair in the check_relocs routine.
2415 We use a section symbol recorded by check_relocs as the
2416 base symbol for the relocation. The addend is the difference
2417 between the section symbol and the address of the .opd entry. */
2418 if (info
->shared
&& rent
->type
== R_PARISC_FPTR64
&& hh
->want_opd
)
2420 bfd_vma value
, value2
;
2422 /* First compute the address of the opd entry for this symbol. */
2423 value
= (hh
->opd_offset
2424 + hppa_info
->opd_sec
->output_section
->vma
2425 + hppa_info
->opd_sec
->output_offset
);
2427 /* Compute the value of the start of the section with
2429 value2
= (rent
->sec
->output_section
->vma
2430 + rent
->sec
->output_offset
);
2432 /* Compute the difference between the start of the section
2433 with the relocation and the opd entry. */
2436 /* The result becomes the addend of the relocation. */
2437 rel
.r_addend
= value
;
2439 /* The section symbol becomes the symbol for the dynamic
2442 = _bfd_elf_link_lookup_local_dynindx (info
,
2447 rel
.r_addend
= rent
->addend
;
2449 rel
.r_info
= ELF64_R_INFO (dynindx
, rent
->type
);
2451 loc
= hppa_info
->other_rel_sec
->contents
;
2452 loc
+= (hppa_info
->other_rel_sec
->reloc_count
++
2453 * sizeof (Elf64_External_Rela
));
2454 bfd_elf64_swap_reloca_out (hppa_info
->other_rel_sec
->output_section
->owner
,
2462 /* Used to decide how to sort relocs in an optimal manner for the
2463 dynamic linker, before writing them out. */
2465 static enum elf_reloc_type_class
2466 elf64_hppa_reloc_type_class (const Elf_Internal_Rela
*rela
)
2468 if (ELF64_R_SYM (rela
->r_info
) == STN_UNDEF
)
2469 return reloc_class_relative
;
2471 switch ((int) ELF64_R_TYPE (rela
->r_info
))
2474 return reloc_class_plt
;
2476 return reloc_class_copy
;
2478 return reloc_class_normal
;
2482 /* Finish up the dynamic sections. */
2485 elf64_hppa_finish_dynamic_sections (bfd
*output_bfd
,
2486 struct bfd_link_info
*info
)
2490 struct elf64_hppa_link_hash_table
*hppa_info
;
2492 hppa_info
= hppa_link_hash_table (info
);
2493 if (hppa_info
== NULL
)
2496 /* Finalize the contents of the .opd section. */
2497 elf_link_hash_traverse (elf_hash_table (info
),
2498 elf64_hppa_finalize_opd
,
2501 elf_link_hash_traverse (elf_hash_table (info
),
2502 elf64_hppa_finalize_dynreloc
,
2505 /* Finalize the contents of the .dlt section. */
2506 dynobj
= elf_hash_table (info
)->dynobj
;
2507 /* Finalize the contents of the .dlt section. */
2508 elf_link_hash_traverse (elf_hash_table (info
),
2509 elf64_hppa_finalize_dlt
,
2512 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2514 if (elf_hash_table (info
)->dynamic_sections_created
)
2516 Elf64_External_Dyn
*dyncon
, *dynconend
;
2518 BFD_ASSERT (sdyn
!= NULL
);
2520 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
2521 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
2522 for (; dyncon
< dynconend
; dyncon
++)
2524 Elf_Internal_Dyn dyn
;
2527 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2534 case DT_HP_LOAD_MAP
:
2535 /* Compute the absolute address of 16byte scratchpad area
2536 for the dynamic linker.
2538 By convention the linker script will allocate the scratchpad
2539 area at the start of the .data section. So all we have to
2540 to is find the start of the .data section. */
2541 s
= bfd_get_section_by_name (output_bfd
, ".data");
2542 dyn
.d_un
.d_ptr
= s
->vma
;
2543 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2547 /* HP's use PLTGOT to set the GOT register. */
2548 dyn
.d_un
.d_ptr
= _bfd_get_gp_value (output_bfd
);
2549 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2553 s
= hppa_info
->plt_rel_sec
;
2554 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
2555 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2559 s
= hppa_info
->plt_rel_sec
;
2560 dyn
.d_un
.d_val
= s
->size
;
2561 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2565 s
= hppa_info
->other_rel_sec
;
2566 if (! s
|| ! s
->size
)
2567 s
= hppa_info
->dlt_rel_sec
;
2568 if (! s
|| ! s
->size
)
2569 s
= hppa_info
->opd_rel_sec
;
2570 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
2571 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2575 s
= hppa_info
->other_rel_sec
;
2576 dyn
.d_un
.d_val
= s
->size
;
2577 s
= hppa_info
->dlt_rel_sec
;
2578 dyn
.d_un
.d_val
+= s
->size
;
2579 s
= hppa_info
->opd_rel_sec
;
2580 dyn
.d_un
.d_val
+= s
->size
;
2581 /* There is some question about whether or not the size of
2582 the PLT relocs should be included here. HP's tools do
2583 it, so we'll emulate them. */
2584 s
= hppa_info
->plt_rel_sec
;
2585 dyn
.d_un
.d_val
+= s
->size
;
2586 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2596 /* Support for core dump NOTE sections. */
2599 elf64_hppa_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
2604 switch (note
->descsz
)
2609 case 760: /* Linux/hppa */
2611 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
2614 elf_tdata (abfd
)->core_lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
2623 /* Make a ".reg/999" section. */
2624 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
2625 size
, note
->descpos
+ offset
);
2629 elf64_hppa_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
2634 switch (note
->descsz
)
2639 case 136: /* Linux/hppa elf_prpsinfo. */
2640 elf_tdata (abfd
)->core_program
2641 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
2642 elf_tdata (abfd
)->core_command
2643 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
2646 /* Note that for some reason, a spurious space is tacked
2647 onto the end of the args in some (at least one anyway)
2648 implementations, so strip it off if it exists. */
2649 command
= elf_tdata (abfd
)->core_command
;
2650 n
= strlen (command
);
2652 if (0 < n
&& command
[n
- 1] == ' ')
2653 command
[n
- 1] = '\0';
2658 /* Return the number of additional phdrs we will need.
2660 The generic ELF code only creates PT_PHDRs for executables. The HP
2661 dynamic linker requires PT_PHDRs for dynamic libraries too.
2663 This routine indicates that the backend needs one additional program
2664 header for that case.
2666 Note we do not have access to the link info structure here, so we have
2667 to guess whether or not we are building a shared library based on the
2668 existence of a .interp section. */
2671 elf64_hppa_additional_program_headers (bfd
*abfd
,
2672 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2676 /* If we are creating a shared library, then we have to create a
2677 PT_PHDR segment. HP's dynamic linker chokes without it. */
2678 s
= bfd_get_section_by_name (abfd
, ".interp");
2684 /* Allocate and initialize any program headers required by this
2687 The generic ELF code only creates PT_PHDRs for executables. The HP
2688 dynamic linker requires PT_PHDRs for dynamic libraries too.
2690 This allocates the PT_PHDR and initializes it in a manner suitable
2693 Note we do not have access to the link info structure here, so we have
2694 to guess whether or not we are building a shared library based on the
2695 existence of a .interp section. */
2698 elf64_hppa_modify_segment_map (bfd
*abfd
,
2699 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2701 struct elf_segment_map
*m
;
2704 s
= bfd_get_section_by_name (abfd
, ".interp");
2707 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2708 if (m
->p_type
== PT_PHDR
)
2712 m
= ((struct elf_segment_map
*)
2713 bfd_zalloc (abfd
, (bfd_size_type
) sizeof *m
));
2717 m
->p_type
= PT_PHDR
;
2718 m
->p_flags
= PF_R
| PF_X
;
2719 m
->p_flags_valid
= 1;
2720 m
->p_paddr_valid
= 1;
2721 m
->includes_phdrs
= 1;
2723 m
->next
= elf_tdata (abfd
)->segment_map
;
2724 elf_tdata (abfd
)->segment_map
= m
;
2728 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2729 if (m
->p_type
== PT_LOAD
)
2733 for (i
= 0; i
< m
->count
; i
++)
2735 /* The code "hint" is not really a hint. It is a requirement
2736 for certain versions of the HP dynamic linker. Worse yet,
2737 it must be set even if the shared library does not have
2738 any code in its "text" segment (thus the check for .hash
2739 to catch this situation). */
2740 if (m
->sections
[i
]->flags
& SEC_CODE
2741 || (strcmp (m
->sections
[i
]->name
, ".hash") == 0))
2742 m
->p_flags
|= (PF_X
| PF_HP_CODE
);
2749 /* Called when writing out an object file to decide the type of a
2752 elf64_hppa_elf_get_symbol_type (Elf_Internal_Sym
*elf_sym
,
2755 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_PARISC_MILLI
)
2756 return STT_PARISC_MILLI
;
2761 /* Support HP specific sections for core files. */
2764 elf64_hppa_section_from_phdr (bfd
*abfd
, Elf_Internal_Phdr
*hdr
, int sec_index
,
2765 const char *typename
)
2767 if (hdr
->p_type
== PT_HP_CORE_KERNEL
)
2771 if (!_bfd_elf_make_section_from_phdr (abfd
, hdr
, sec_index
, typename
))
2774 sect
= bfd_make_section_anyway (abfd
, ".kernel");
2777 sect
->size
= hdr
->p_filesz
;
2778 sect
->filepos
= hdr
->p_offset
;
2779 sect
->flags
= SEC_HAS_CONTENTS
| SEC_READONLY
;
2783 if (hdr
->p_type
== PT_HP_CORE_PROC
)
2787 if (bfd_seek (abfd
, hdr
->p_offset
, SEEK_SET
) != 0)
2789 if (bfd_bread (&sig
, 4, abfd
) != 4)
2792 elf_tdata (abfd
)->core_signal
= sig
;
2794 if (!_bfd_elf_make_section_from_phdr (abfd
, hdr
, sec_index
, typename
))
2797 /* GDB uses the ".reg" section to read register contents. */
2798 return _bfd_elfcore_make_pseudosection (abfd
, ".reg", hdr
->p_filesz
,
2802 if (hdr
->p_type
== PT_HP_CORE_LOADABLE
2803 || hdr
->p_type
== PT_HP_CORE_STACK
2804 || hdr
->p_type
== PT_HP_CORE_MMF
)
2805 hdr
->p_type
= PT_LOAD
;
2807 return _bfd_elf_make_section_from_phdr (abfd
, hdr
, sec_index
, typename
);
2810 /* Hook called by the linker routine which adds symbols from an object
2811 file. HP's libraries define symbols with HP specific section
2812 indices, which we have to handle. */
2815 elf_hppa_add_symbol_hook (bfd
*abfd
,
2816 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2817 Elf_Internal_Sym
*sym
,
2818 const char **namep ATTRIBUTE_UNUSED
,
2819 flagword
*flagsp ATTRIBUTE_UNUSED
,
2823 unsigned int sec_index
= sym
->st_shndx
;
2827 case SHN_PARISC_ANSI_COMMON
:
2828 *secp
= bfd_make_section_old_way (abfd
, ".PARISC.ansi.common");
2829 (*secp
)->flags
|= SEC_IS_COMMON
;
2830 *valp
= sym
->st_size
;
2833 case SHN_PARISC_HUGE_COMMON
:
2834 *secp
= bfd_make_section_old_way (abfd
, ".PARISC.huge.common");
2835 (*secp
)->flags
|= SEC_IS_COMMON
;
2836 *valp
= sym
->st_size
;
2844 elf_hppa_unmark_useless_dynamic_symbols (struct elf_link_hash_entry
*h
,
2847 struct bfd_link_info
*info
= data
;
2849 if (h
->root
.type
== bfd_link_hash_warning
)
2850 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2852 /* If we are not creating a shared library, and this symbol is
2853 referenced by a shared library but is not defined anywhere, then
2854 the generic code will warn that it is undefined.
2856 This behavior is undesirable on HPs since the standard shared
2857 libraries contain references to undefined symbols.
2859 So we twiddle the flags associated with such symbols so that they
2860 will not trigger the warning. ?!? FIXME. This is horribly fragile.
2862 Ultimately we should have better controls over the generic ELF BFD
2864 if (! info
->relocatable
2865 && info
->unresolved_syms_in_shared_libs
!= RM_IGNORE
2866 && h
->root
.type
== bfd_link_hash_undefined
2871 h
->pointer_equality_needed
= 1;
2878 elf_hppa_remark_useless_dynamic_symbols (struct elf_link_hash_entry
*h
,
2881 struct bfd_link_info
*info
= data
;
2883 if (h
->root
.type
== bfd_link_hash_warning
)
2884 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2886 /* If we are not creating a shared library, and this symbol is
2887 referenced by a shared library but is not defined anywhere, then
2888 the generic code will warn that it is undefined.
2890 This behavior is undesirable on HPs since the standard shared
2891 libraries contain references to undefined symbols.
2893 So we twiddle the flags associated with such symbols so that they
2894 will not trigger the warning. ?!? FIXME. This is horribly fragile.
2896 Ultimately we should have better controls over the generic ELF BFD
2898 if (! info
->relocatable
2899 && info
->unresolved_syms_in_shared_libs
!= RM_IGNORE
2900 && h
->root
.type
== bfd_link_hash_undefined
2903 && h
->pointer_equality_needed
)
2906 h
->pointer_equality_needed
= 0;
2913 elf_hppa_is_dynamic_loader_symbol (const char *name
)
2915 return (! strcmp (name
, "__CPU_REVISION")
2916 || ! strcmp (name
, "__CPU_KEYBITS_1")
2917 || ! strcmp (name
, "__SYSTEM_ID_D")
2918 || ! strcmp (name
, "__FPU_MODEL")
2919 || ! strcmp (name
, "__FPU_REVISION")
2920 || ! strcmp (name
, "__ARGC")
2921 || ! strcmp (name
, "__ARGV")
2922 || ! strcmp (name
, "__ENVP")
2923 || ! strcmp (name
, "__TLS_SIZE_D")
2924 || ! strcmp (name
, "__LOAD_INFO")
2925 || ! strcmp (name
, "__systab"));
2928 /* Record the lowest address for the data and text segments. */
2930 elf_hppa_record_segment_addrs (bfd
*abfd
,
2934 struct elf64_hppa_link_hash_table
*hppa_info
= data
;
2936 if ((section
->flags
& (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
2939 Elf_Internal_Phdr
*p
;
2941 p
= _bfd_elf_find_segment_containing_section (abfd
, section
->output_section
);
2942 BFD_ASSERT (p
!= NULL
);
2945 if (section
->flags
& SEC_READONLY
)
2947 if (value
< hppa_info
->text_segment_base
)
2948 hppa_info
->text_segment_base
= value
;
2952 if (value
< hppa_info
->data_segment_base
)
2953 hppa_info
->data_segment_base
= value
;
2958 /* Called after we have seen all the input files/sections, but before
2959 final symbol resolution and section placement has been determined.
2961 We use this hook to (possibly) provide a value for __gp, then we
2962 fall back to the generic ELF final link routine. */
2965 elf_hppa_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
2968 struct elf64_hppa_link_hash_table
*hppa_info
= hppa_link_hash_table (info
);
2970 if (hppa_info
== NULL
)
2973 if (! info
->relocatable
)
2975 struct elf_link_hash_entry
*gp
;
2978 /* The linker script defines a value for __gp iff it was referenced
2979 by one of the objects being linked. First try to find the symbol
2980 in the hash table. If that fails, just compute the value __gp
2982 gp
= elf_link_hash_lookup (elf_hash_table (info
), "__gp", FALSE
,
2988 /* Adjust the value of __gp as we may want to slide it into the
2989 .plt section so that the stubs can access PLT entries without
2990 using an addil sequence. */
2991 gp
->root
.u
.def
.value
+= hppa_info
->gp_offset
;
2993 gp_val
= (gp
->root
.u
.def
.section
->output_section
->vma
2994 + gp
->root
.u
.def
.section
->output_offset
2995 + gp
->root
.u
.def
.value
);
3001 /* First look for a .plt section. If found, then __gp is the
3002 address of the .plt + gp_offset.
3004 If no .plt is found, then look for .dlt, .opd and .data (in
3005 that order) and set __gp to the base address of whichever
3006 section is found first. */
3008 sec
= hppa_info
->plt_sec
;
3009 if (sec
&& ! (sec
->flags
& SEC_EXCLUDE
))
3010 gp_val
= (sec
->output_offset
3011 + sec
->output_section
->vma
3012 + hppa_info
->gp_offset
);
3015 sec
= hppa_info
->dlt_sec
;
3016 if (!sec
|| (sec
->flags
& SEC_EXCLUDE
))
3017 sec
= hppa_info
->opd_sec
;
3018 if (!sec
|| (sec
->flags
& SEC_EXCLUDE
))
3019 sec
= bfd_get_section_by_name (abfd
, ".data");
3020 if (!sec
|| (sec
->flags
& SEC_EXCLUDE
))
3023 gp_val
= sec
->output_offset
+ sec
->output_section
->vma
;
3027 /* Install whatever value we found/computed for __gp. */
3028 _bfd_set_gp_value (abfd
, gp_val
);
3031 /* We need to know the base of the text and data segments so that we
3032 can perform SEGREL relocations. We will record the base addresses
3033 when we encounter the first SEGREL relocation. */
3034 hppa_info
->text_segment_base
= (bfd_vma
)-1;
3035 hppa_info
->data_segment_base
= (bfd_vma
)-1;
3037 /* HP's shared libraries have references to symbols that are not
3038 defined anywhere. The generic ELF BFD linker code will complain
3041 So we detect the losing case and arrange for the flags on the symbol
3042 to indicate that it was never referenced. This keeps the generic
3043 ELF BFD link code happy and appears to not create any secondary
3044 problems. Ultimately we need a way to control the behavior of the
3045 generic ELF BFD link code better. */
3046 elf_link_hash_traverse (elf_hash_table (info
),
3047 elf_hppa_unmark_useless_dynamic_symbols
,
3050 /* Invoke the regular ELF backend linker to do all the work. */
3051 retval
= bfd_elf_final_link (abfd
, info
);
3053 elf_link_hash_traverse (elf_hash_table (info
),
3054 elf_hppa_remark_useless_dynamic_symbols
,
3057 /* If we're producing a final executable, sort the contents of the
3059 if (retval
&& !info
->relocatable
)
3060 retval
= elf_hppa_sort_unwind (abfd
);
3065 /* Relocate the given INSN. VALUE should be the actual value we want
3066 to insert into the instruction, ie by this point we should not be
3067 concerned with computing an offset relative to the DLT, PC, etc.
3068 Instead this routine is meant to handle the bit manipulations needed
3069 to insert the relocation into the given instruction. */
3072 elf_hppa_relocate_insn (int insn
, int sym_value
, unsigned int r_type
)
3076 /* This is any 22 bit branch. In PA2.0 syntax it corresponds to
3077 the "B" instruction. */
3078 case R_PARISC_PCREL22F
:
3079 case R_PARISC_PCREL22C
:
3080 return (insn
& ~0x3ff1ffd) | re_assemble_22 (sym_value
);
3082 /* This is any 12 bit branch. */
3083 case R_PARISC_PCREL12F
:
3084 return (insn
& ~0x1ffd) | re_assemble_12 (sym_value
);
3086 /* This is any 17 bit branch. In PA2.0 syntax it also corresponds
3087 to the "B" instruction as well as BE. */
3088 case R_PARISC_PCREL17F
:
3089 case R_PARISC_DIR17F
:
3090 case R_PARISC_DIR17R
:
3091 case R_PARISC_PCREL17C
:
3092 case R_PARISC_PCREL17R
:
3093 return (insn
& ~0x1f1ffd) | re_assemble_17 (sym_value
);
3095 /* ADDIL or LDIL instructions. */
3096 case R_PARISC_DLTREL21L
:
3097 case R_PARISC_DLTIND21L
:
3098 case R_PARISC_LTOFF_FPTR21L
:
3099 case R_PARISC_PCREL21L
:
3100 case R_PARISC_LTOFF_TP21L
:
3101 case R_PARISC_DPREL21L
:
3102 case R_PARISC_PLTOFF21L
:
3103 case R_PARISC_DIR21L
:
3104 return (insn
& ~0x1fffff) | re_assemble_21 (sym_value
);
3106 /* LDO and integer loads/stores with 14 bit displacements. */
3107 case R_PARISC_DLTREL14R
:
3108 case R_PARISC_DLTREL14F
:
3109 case R_PARISC_DLTIND14R
:
3110 case R_PARISC_DLTIND14F
:
3111 case R_PARISC_LTOFF_FPTR14R
:
3112 case R_PARISC_PCREL14R
:
3113 case R_PARISC_PCREL14F
:
3114 case R_PARISC_LTOFF_TP14R
:
3115 case R_PARISC_LTOFF_TP14F
:
3116 case R_PARISC_DPREL14R
:
3117 case R_PARISC_DPREL14F
:
3118 case R_PARISC_PLTOFF14R
:
3119 case R_PARISC_PLTOFF14F
:
3120 case R_PARISC_DIR14R
:
3121 case R_PARISC_DIR14F
:
3122 return (insn
& ~0x3fff) | low_sign_unext (sym_value
, 14);
3124 /* PA2.0W LDO and integer loads/stores with 16 bit displacements. */
3125 case R_PARISC_LTOFF_FPTR16F
:
3126 case R_PARISC_PCREL16F
:
3127 case R_PARISC_LTOFF_TP16F
:
3128 case R_PARISC_GPREL16F
:
3129 case R_PARISC_PLTOFF16F
:
3130 case R_PARISC_DIR16F
:
3131 case R_PARISC_LTOFF16F
:
3132 return (insn
& ~0xffff) | re_assemble_16 (sym_value
);
3134 /* Doubleword loads and stores with a 14 bit displacement. */
3135 case R_PARISC_DLTREL14DR
:
3136 case R_PARISC_DLTIND14DR
:
3137 case R_PARISC_LTOFF_FPTR14DR
:
3138 case R_PARISC_LTOFF_FPTR16DF
:
3139 case R_PARISC_PCREL14DR
:
3140 case R_PARISC_PCREL16DF
:
3141 case R_PARISC_LTOFF_TP14DR
:
3142 case R_PARISC_LTOFF_TP16DF
:
3143 case R_PARISC_DPREL14DR
:
3144 case R_PARISC_GPREL16DF
:
3145 case R_PARISC_PLTOFF14DR
:
3146 case R_PARISC_PLTOFF16DF
:
3147 case R_PARISC_DIR14DR
:
3148 case R_PARISC_DIR16DF
:
3149 case R_PARISC_LTOFF16DF
:
3150 return (insn
& ~0x3ff1) | (((sym_value
& 0x2000) >> 13)
3151 | ((sym_value
& 0x1ff8) << 1));
3153 /* Floating point single word load/store instructions. */
3154 case R_PARISC_DLTREL14WR
:
3155 case R_PARISC_DLTIND14WR
:
3156 case R_PARISC_LTOFF_FPTR14WR
:
3157 case R_PARISC_LTOFF_FPTR16WF
:
3158 case R_PARISC_PCREL14WR
:
3159 case R_PARISC_PCREL16WF
:
3160 case R_PARISC_LTOFF_TP14WR
:
3161 case R_PARISC_LTOFF_TP16WF
:
3162 case R_PARISC_DPREL14WR
:
3163 case R_PARISC_GPREL16WF
:
3164 case R_PARISC_PLTOFF14WR
:
3165 case R_PARISC_PLTOFF16WF
:
3166 case R_PARISC_DIR16WF
:
3167 case R_PARISC_DIR14WR
:
3168 case R_PARISC_LTOFF16WF
:
3169 return (insn
& ~0x3ff9) | (((sym_value
& 0x2000) >> 13)
3170 | ((sym_value
& 0x1ffc) << 1));
3177 /* Compute the value for a relocation (REL) during a final link stage,
3178 then insert the value into the proper location in CONTENTS.
3180 VALUE is a tentative value for the relocation and may be overridden
3181 and modified here based on the specific relocation to be performed.
3183 For example we do conversions for PC-relative branches in this routine
3184 or redirection of calls to external routines to stubs.
3186 The work of actually applying the relocation is left to a helper
3187 routine in an attempt to reduce the complexity and size of this
3190 static bfd_reloc_status_type
3191 elf_hppa_final_link_relocate (Elf_Internal_Rela
*rel
,
3194 asection
*input_section
,
3197 struct bfd_link_info
*info
,
3199 struct elf_link_hash_entry
*eh
)
3201 struct elf64_hppa_link_hash_table
*hppa_info
= hppa_link_hash_table (info
);
3202 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
3203 bfd_vma
*local_offsets
;
3204 Elf_Internal_Shdr
*symtab_hdr
;
3206 bfd_vma max_branch_offset
= 0;
3207 bfd_vma offset
= rel
->r_offset
;
3208 bfd_signed_vma addend
= rel
->r_addend
;
3209 reloc_howto_type
*howto
= elf_hppa_howto_table
+ ELF_R_TYPE (rel
->r_info
);
3210 unsigned int r_symndx
= ELF_R_SYM (rel
->r_info
);
3211 unsigned int r_type
= howto
->type
;
3212 bfd_byte
*hit_data
= contents
+ offset
;
3214 if (hppa_info
== NULL
)
3215 return bfd_reloc_notsupported
;
3217 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3218 local_offsets
= elf_local_got_offsets (input_bfd
);
3219 insn
= bfd_get_32 (input_bfd
, hit_data
);
3226 /* Basic function call support.
3228 Note for a call to a function defined in another dynamic library
3229 we want to redirect the call to a stub. */
3231 /* PC relative relocs without an implicit offset. */
3232 case R_PARISC_PCREL21L
:
3233 case R_PARISC_PCREL14R
:
3234 case R_PARISC_PCREL14F
:
3235 case R_PARISC_PCREL14WR
:
3236 case R_PARISC_PCREL14DR
:
3237 case R_PARISC_PCREL16F
:
3238 case R_PARISC_PCREL16WF
:
3239 case R_PARISC_PCREL16DF
:
3241 /* If this is a call to a function defined in another dynamic
3242 library, then redirect the call to the local stub for this
3244 if (sym_sec
== NULL
|| sym_sec
->output_section
== NULL
)
3245 value
= (hh
->stub_offset
+ hppa_info
->stub_sec
->output_offset
3246 + hppa_info
->stub_sec
->output_section
->vma
);
3248 /* Turn VALUE into a proper PC relative address. */
3249 value
-= (offset
+ input_section
->output_offset
3250 + input_section
->output_section
->vma
);
3252 /* Adjust for any field selectors. */
3253 if (r_type
== R_PARISC_PCREL21L
)
3254 value
= hppa_field_adjust (value
, -8 + addend
, e_lsel
);
3255 else if (r_type
== R_PARISC_PCREL14F
3256 || r_type
== R_PARISC_PCREL16F
3257 || r_type
== R_PARISC_PCREL16WF
3258 || r_type
== R_PARISC_PCREL16DF
)
3259 value
= hppa_field_adjust (value
, -8 + addend
, e_fsel
);
3261 value
= hppa_field_adjust (value
, -8 + addend
, e_rsel
);
3263 /* Apply the relocation to the given instruction. */
3264 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3268 case R_PARISC_PCREL12F
:
3269 case R_PARISC_PCREL22F
:
3270 case R_PARISC_PCREL17F
:
3271 case R_PARISC_PCREL22C
:
3272 case R_PARISC_PCREL17C
:
3273 case R_PARISC_PCREL17R
:
3275 /* If this is a call to a function defined in another dynamic
3276 library, then redirect the call to the local stub for this
3278 if (sym_sec
== NULL
|| sym_sec
->output_section
== NULL
)
3279 value
= (hh
->stub_offset
+ hppa_info
->stub_sec
->output_offset
3280 + hppa_info
->stub_sec
->output_section
->vma
);
3282 /* Turn VALUE into a proper PC relative address. */
3283 value
-= (offset
+ input_section
->output_offset
3284 + input_section
->output_section
->vma
);
3287 if (r_type
== (unsigned int) R_PARISC_PCREL22F
)
3288 max_branch_offset
= (1 << (22-1)) << 2;
3289 else if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
3290 max_branch_offset
= (1 << (17-1)) << 2;
3291 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
3292 max_branch_offset
= (1 << (12-1)) << 2;
3294 /* Make sure we can reach the branch target. */
3295 if (max_branch_offset
!= 0
3296 && value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3298 (*_bfd_error_handler
)
3299 (_("%B(%A+0x%lx): cannot reach %s"),
3303 eh
->root
.root
.string
);
3304 bfd_set_error (bfd_error_bad_value
);
3305 return bfd_reloc_notsupported
;
3308 /* Adjust for any field selectors. */
3309 if (r_type
== R_PARISC_PCREL17R
)
3310 value
= hppa_field_adjust (value
, addend
, e_rsel
);
3312 value
= hppa_field_adjust (value
, addend
, e_fsel
);
3314 /* All branches are implicitly shifted by 2 places. */
3317 /* Apply the relocation to the given instruction. */
3318 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3322 /* Indirect references to data through the DLT. */
3323 case R_PARISC_DLTIND14R
:
3324 case R_PARISC_DLTIND14F
:
3325 case R_PARISC_DLTIND14DR
:
3326 case R_PARISC_DLTIND14WR
:
3327 case R_PARISC_DLTIND21L
:
3328 case R_PARISC_LTOFF_FPTR14R
:
3329 case R_PARISC_LTOFF_FPTR14DR
:
3330 case R_PARISC_LTOFF_FPTR14WR
:
3331 case R_PARISC_LTOFF_FPTR21L
:
3332 case R_PARISC_LTOFF_FPTR16F
:
3333 case R_PARISC_LTOFF_FPTR16WF
:
3334 case R_PARISC_LTOFF_FPTR16DF
:
3335 case R_PARISC_LTOFF_TP21L
:
3336 case R_PARISC_LTOFF_TP14R
:
3337 case R_PARISC_LTOFF_TP14F
:
3338 case R_PARISC_LTOFF_TP14WR
:
3339 case R_PARISC_LTOFF_TP14DR
:
3340 case R_PARISC_LTOFF_TP16F
:
3341 case R_PARISC_LTOFF_TP16WF
:
3342 case R_PARISC_LTOFF_TP16DF
:
3343 case R_PARISC_LTOFF16F
:
3344 case R_PARISC_LTOFF16WF
:
3345 case R_PARISC_LTOFF16DF
:
3349 /* If this relocation was against a local symbol, then we still
3350 have not set up the DLT entry (it's not convenient to do so
3351 in the "finalize_dlt" routine because it is difficult to get
3352 to the local symbol's value).
3354 So, if this is a local symbol (h == NULL), then we need to
3355 fill in its DLT entry.
3357 Similarly we may still need to set up an entry in .opd for
3358 a local function which had its address taken. */
3361 bfd_vma
*local_opd_offsets
, *local_dlt_offsets
;
3363 if (local_offsets
== NULL
)
3366 /* Now do .opd creation if needed. */
3367 if (r_type
== R_PARISC_LTOFF_FPTR14R
3368 || r_type
== R_PARISC_LTOFF_FPTR14DR
3369 || r_type
== R_PARISC_LTOFF_FPTR14WR
3370 || r_type
== R_PARISC_LTOFF_FPTR21L
3371 || r_type
== R_PARISC_LTOFF_FPTR16F
3372 || r_type
== R_PARISC_LTOFF_FPTR16WF
3373 || r_type
== R_PARISC_LTOFF_FPTR16DF
)
3375 local_opd_offsets
= local_offsets
+ 2 * symtab_hdr
->sh_info
;
3376 off
= local_opd_offsets
[r_symndx
];
3378 /* The last bit records whether we've already initialised
3379 this local .opd entry. */
3382 BFD_ASSERT (off
!= (bfd_vma
) -1);
3387 local_opd_offsets
[r_symndx
] |= 1;
3389 /* The first two words of an .opd entry are zero. */
3390 memset (hppa_info
->opd_sec
->contents
+ off
, 0, 16);
3392 /* The next word is the address of the function. */
3393 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
+ addend
,
3394 (hppa_info
->opd_sec
->contents
+ off
+ 16));
3396 /* The last word is our local __gp value. */
3397 value
= _bfd_get_gp_value
3398 (hppa_info
->opd_sec
->output_section
->owner
);
3399 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
,
3400 (hppa_info
->opd_sec
->contents
+ off
+ 24));
3403 /* The DLT value is the address of the .opd entry. */
3405 + hppa_info
->opd_sec
->output_offset
3406 + hppa_info
->opd_sec
->output_section
->vma
);
3410 local_dlt_offsets
= local_offsets
;
3411 off
= local_dlt_offsets
[r_symndx
];
3415 BFD_ASSERT (off
!= (bfd_vma
) -1);
3420 local_dlt_offsets
[r_symndx
] |= 1;
3421 bfd_put_64 (hppa_info
->dlt_sec
->owner
,
3423 hppa_info
->dlt_sec
->contents
+ off
);
3427 off
= hh
->dlt_offset
;
3429 /* We want the value of the DLT offset for this symbol, not
3430 the symbol's actual address. Note that __gp may not point
3431 to the start of the DLT, so we have to compute the absolute
3432 address, then subtract out the value of __gp. */
3434 + hppa_info
->dlt_sec
->output_offset
3435 + hppa_info
->dlt_sec
->output_section
->vma
);
3436 value
-= _bfd_get_gp_value (output_bfd
);
3438 /* All DLTIND relocations are basically the same at this point,
3439 except that we need different field selectors for the 21bit
3440 version vs the 14bit versions. */
3441 if (r_type
== R_PARISC_DLTIND21L
3442 || r_type
== R_PARISC_LTOFF_FPTR21L
3443 || r_type
== R_PARISC_LTOFF_TP21L
)
3444 value
= hppa_field_adjust (value
, 0, e_lsel
);
3445 else if (r_type
== R_PARISC_DLTIND14F
3446 || r_type
== R_PARISC_LTOFF_FPTR16F
3447 || r_type
== R_PARISC_LTOFF_FPTR16WF
3448 || r_type
== R_PARISC_LTOFF_FPTR16DF
3449 || r_type
== R_PARISC_LTOFF16F
3450 || r_type
== R_PARISC_LTOFF16DF
3451 || r_type
== R_PARISC_LTOFF16WF
3452 || r_type
== R_PARISC_LTOFF_TP16F
3453 || r_type
== R_PARISC_LTOFF_TP16WF
3454 || r_type
== R_PARISC_LTOFF_TP16DF
)
3455 value
= hppa_field_adjust (value
, 0, e_fsel
);
3457 value
= hppa_field_adjust (value
, 0, e_rsel
);
3459 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3463 case R_PARISC_DLTREL14R
:
3464 case R_PARISC_DLTREL14F
:
3465 case R_PARISC_DLTREL14DR
:
3466 case R_PARISC_DLTREL14WR
:
3467 case R_PARISC_DLTREL21L
:
3468 case R_PARISC_DPREL21L
:
3469 case R_PARISC_DPREL14WR
:
3470 case R_PARISC_DPREL14DR
:
3471 case R_PARISC_DPREL14R
:
3472 case R_PARISC_DPREL14F
:
3473 case R_PARISC_GPREL16F
:
3474 case R_PARISC_GPREL16WF
:
3475 case R_PARISC_GPREL16DF
:
3477 /* Subtract out the global pointer value to make value a DLT
3478 relative address. */
3479 value
-= _bfd_get_gp_value (output_bfd
);
3481 /* All DLTREL relocations are basically the same at this point,
3482 except that we need different field selectors for the 21bit
3483 version vs the 14bit versions. */
3484 if (r_type
== R_PARISC_DLTREL21L
3485 || r_type
== R_PARISC_DPREL21L
)
3486 value
= hppa_field_adjust (value
, addend
, e_lrsel
);
3487 else if (r_type
== R_PARISC_DLTREL14F
3488 || r_type
== R_PARISC_DPREL14F
3489 || r_type
== R_PARISC_GPREL16F
3490 || r_type
== R_PARISC_GPREL16WF
3491 || r_type
== R_PARISC_GPREL16DF
)
3492 value
= hppa_field_adjust (value
, addend
, e_fsel
);
3494 value
= hppa_field_adjust (value
, addend
, e_rrsel
);
3496 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3500 case R_PARISC_DIR21L
:
3501 case R_PARISC_DIR17R
:
3502 case R_PARISC_DIR17F
:
3503 case R_PARISC_DIR14R
:
3504 case R_PARISC_DIR14F
:
3505 case R_PARISC_DIR14WR
:
3506 case R_PARISC_DIR14DR
:
3507 case R_PARISC_DIR16F
:
3508 case R_PARISC_DIR16WF
:
3509 case R_PARISC_DIR16DF
:
3511 /* All DIR relocations are basically the same at this point,
3512 except that branch offsets need to be divided by four, and
3513 we need different field selectors. Note that we don't
3514 redirect absolute calls to local stubs. */
3516 if (r_type
== R_PARISC_DIR21L
)
3517 value
= hppa_field_adjust (value
, addend
, e_lrsel
);
3518 else if (r_type
== R_PARISC_DIR17F
3519 || r_type
== R_PARISC_DIR16F
3520 || r_type
== R_PARISC_DIR16WF
3521 || r_type
== R_PARISC_DIR16DF
3522 || r_type
== R_PARISC_DIR14F
)
3523 value
= hppa_field_adjust (value
, addend
, e_fsel
);
3525 value
= hppa_field_adjust (value
, addend
, e_rrsel
);
3527 if (r_type
== R_PARISC_DIR17R
|| r_type
== R_PARISC_DIR17F
)
3528 /* All branches are implicitly shifted by 2 places. */
3531 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3535 case R_PARISC_PLTOFF21L
:
3536 case R_PARISC_PLTOFF14R
:
3537 case R_PARISC_PLTOFF14F
:
3538 case R_PARISC_PLTOFF14WR
:
3539 case R_PARISC_PLTOFF14DR
:
3540 case R_PARISC_PLTOFF16F
:
3541 case R_PARISC_PLTOFF16WF
:
3542 case R_PARISC_PLTOFF16DF
:
3544 /* We want the value of the PLT offset for this symbol, not
3545 the symbol's actual address. Note that __gp may not point
3546 to the start of the DLT, so we have to compute the absolute
3547 address, then subtract out the value of __gp. */
3548 value
= (hh
->plt_offset
3549 + hppa_info
->plt_sec
->output_offset
3550 + hppa_info
->plt_sec
->output_section
->vma
);
3551 value
-= _bfd_get_gp_value (output_bfd
);
3553 /* All PLTOFF relocations are basically the same at this point,
3554 except that we need different field selectors for the 21bit
3555 version vs the 14bit versions. */
3556 if (r_type
== R_PARISC_PLTOFF21L
)
3557 value
= hppa_field_adjust (value
, addend
, e_lrsel
);
3558 else if (r_type
== R_PARISC_PLTOFF14F
3559 || r_type
== R_PARISC_PLTOFF16F
3560 || r_type
== R_PARISC_PLTOFF16WF
3561 || r_type
== R_PARISC_PLTOFF16DF
)
3562 value
= hppa_field_adjust (value
, addend
, e_fsel
);
3564 value
= hppa_field_adjust (value
, addend
, e_rrsel
);
3566 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3570 case R_PARISC_LTOFF_FPTR32
:
3572 /* We may still need to create the FPTR itself if it was for
3576 /* The first two words of an .opd entry are zero. */
3577 memset (hppa_info
->opd_sec
->contents
+ hh
->opd_offset
, 0, 16);
3579 /* The next word is the address of the function. */
3580 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
+ addend
,
3581 (hppa_info
->opd_sec
->contents
3582 + hh
->opd_offset
+ 16));
3584 /* The last word is our local __gp value. */
3585 value
= _bfd_get_gp_value
3586 (hppa_info
->opd_sec
->output_section
->owner
);
3587 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
,
3588 hppa_info
->opd_sec
->contents
+ hh
->opd_offset
+ 24);
3590 /* The DLT value is the address of the .opd entry. */
3591 value
= (hh
->opd_offset
3592 + hppa_info
->opd_sec
->output_offset
3593 + hppa_info
->opd_sec
->output_section
->vma
);
3595 bfd_put_64 (hppa_info
->dlt_sec
->owner
,
3597 hppa_info
->dlt_sec
->contents
+ hh
->dlt_offset
);
3600 /* We want the value of the DLT offset for this symbol, not
3601 the symbol's actual address. Note that __gp may not point
3602 to the start of the DLT, so we have to compute the absolute
3603 address, then subtract out the value of __gp. */
3604 value
= (hh
->dlt_offset
3605 + hppa_info
->dlt_sec
->output_offset
3606 + hppa_info
->dlt_sec
->output_section
->vma
);
3607 value
-= _bfd_get_gp_value (output_bfd
);
3608 bfd_put_32 (input_bfd
, value
, hit_data
);
3609 return bfd_reloc_ok
;
3612 case R_PARISC_LTOFF_FPTR64
:
3613 case R_PARISC_LTOFF_TP64
:
3615 /* We may still need to create the FPTR itself if it was for
3617 if (eh
== NULL
&& r_type
== R_PARISC_LTOFF_FPTR64
)
3619 /* The first two words of an .opd entry are zero. */
3620 memset (hppa_info
->opd_sec
->contents
+ hh
->opd_offset
, 0, 16);
3622 /* The next word is the address of the function. */
3623 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
+ addend
,
3624 (hppa_info
->opd_sec
->contents
3625 + hh
->opd_offset
+ 16));
3627 /* The last word is our local __gp value. */
3628 value
= _bfd_get_gp_value
3629 (hppa_info
->opd_sec
->output_section
->owner
);
3630 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
,
3631 hppa_info
->opd_sec
->contents
+ hh
->opd_offset
+ 24);
3633 /* The DLT value is the address of the .opd entry. */
3634 value
= (hh
->opd_offset
3635 + hppa_info
->opd_sec
->output_offset
3636 + hppa_info
->opd_sec
->output_section
->vma
);
3638 bfd_put_64 (hppa_info
->dlt_sec
->owner
,
3640 hppa_info
->dlt_sec
->contents
+ hh
->dlt_offset
);
3643 /* We want the value of the DLT offset for this symbol, not
3644 the symbol's actual address. Note that __gp may not point
3645 to the start of the DLT, so we have to compute the absolute
3646 address, then subtract out the value of __gp. */
3647 value
= (hh
->dlt_offset
3648 + hppa_info
->dlt_sec
->output_offset
3649 + hppa_info
->dlt_sec
->output_section
->vma
);
3650 value
-= _bfd_get_gp_value (output_bfd
);
3651 bfd_put_64 (input_bfd
, value
, hit_data
);
3652 return bfd_reloc_ok
;
3655 case R_PARISC_DIR32
:
3656 bfd_put_32 (input_bfd
, value
+ addend
, hit_data
);
3657 return bfd_reloc_ok
;
3659 case R_PARISC_DIR64
:
3660 bfd_put_64 (input_bfd
, value
+ addend
, hit_data
);
3661 return bfd_reloc_ok
;
3663 case R_PARISC_GPREL64
:
3664 /* Subtract out the global pointer value to make value a DLT
3665 relative address. */
3666 value
-= _bfd_get_gp_value (output_bfd
);
3668 bfd_put_64 (input_bfd
, value
+ addend
, hit_data
);
3669 return bfd_reloc_ok
;
3671 case R_PARISC_LTOFF64
:
3672 /* We want the value of the DLT offset for this symbol, not
3673 the symbol's actual address. Note that __gp may not point
3674 to the start of the DLT, so we have to compute the absolute
3675 address, then subtract out the value of __gp. */
3676 value
= (hh
->dlt_offset
3677 + hppa_info
->dlt_sec
->output_offset
3678 + hppa_info
->dlt_sec
->output_section
->vma
);
3679 value
-= _bfd_get_gp_value (output_bfd
);
3681 bfd_put_64 (input_bfd
, value
+ addend
, hit_data
);
3682 return bfd_reloc_ok
;
3684 case R_PARISC_PCREL32
:
3686 /* If this is a call to a function defined in another dynamic
3687 library, then redirect the call to the local stub for this
3689 if (sym_sec
== NULL
|| sym_sec
->output_section
== NULL
)
3690 value
= (hh
->stub_offset
+ hppa_info
->stub_sec
->output_offset
3691 + hppa_info
->stub_sec
->output_section
->vma
);
3693 /* Turn VALUE into a proper PC relative address. */
3694 value
-= (offset
+ input_section
->output_offset
3695 + input_section
->output_section
->vma
);
3699 bfd_put_32 (input_bfd
, value
, hit_data
);
3700 return bfd_reloc_ok
;
3703 case R_PARISC_PCREL64
:
3705 /* If this is a call to a function defined in another dynamic
3706 library, then redirect the call to the local stub for this
3708 if (sym_sec
== NULL
|| sym_sec
->output_section
== NULL
)
3709 value
= (hh
->stub_offset
+ hppa_info
->stub_sec
->output_offset
3710 + hppa_info
->stub_sec
->output_section
->vma
);
3712 /* Turn VALUE into a proper PC relative address. */
3713 value
-= (offset
+ input_section
->output_offset
3714 + input_section
->output_section
->vma
);
3718 bfd_put_64 (input_bfd
, value
, hit_data
);
3719 return bfd_reloc_ok
;
3722 case R_PARISC_FPTR64
:
3726 /* We may still need to create the FPTR itself if it was for
3730 bfd_vma
*local_opd_offsets
;
3732 if (local_offsets
== NULL
)
3735 local_opd_offsets
= local_offsets
+ 2 * symtab_hdr
->sh_info
;
3736 off
= local_opd_offsets
[r_symndx
];
3738 /* The last bit records whether we've already initialised
3739 this local .opd entry. */
3742 BFD_ASSERT (off
!= (bfd_vma
) -1);
3747 /* The first two words of an .opd entry are zero. */
3748 memset (hppa_info
->opd_sec
->contents
+ off
, 0, 16);
3750 /* The next word is the address of the function. */
3751 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
+ addend
,
3752 (hppa_info
->opd_sec
->contents
+ off
+ 16));
3754 /* The last word is our local __gp value. */
3755 value
= _bfd_get_gp_value
3756 (hppa_info
->opd_sec
->output_section
->owner
);
3757 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
,
3758 hppa_info
->opd_sec
->contents
+ off
+ 24);
3762 off
= hh
->opd_offset
;
3764 if (hh
== NULL
|| hh
->want_opd
)
3765 /* We want the value of the OPD offset for this symbol. */
3767 + hppa_info
->opd_sec
->output_offset
3768 + hppa_info
->opd_sec
->output_section
->vma
);
3770 /* We want the address of the symbol. */
3773 bfd_put_64 (input_bfd
, value
, hit_data
);
3774 return bfd_reloc_ok
;
3777 case R_PARISC_SECREL32
:
3779 value
-= sym_sec
->output_section
->vma
;
3780 bfd_put_32 (input_bfd
, value
+ addend
, hit_data
);
3781 return bfd_reloc_ok
;
3783 case R_PARISC_SEGREL32
:
3784 case R_PARISC_SEGREL64
:
3786 /* If this is the first SEGREL relocation, then initialize
3787 the segment base values. */
3788 if (hppa_info
->text_segment_base
== (bfd_vma
) -1)
3789 bfd_map_over_sections (output_bfd
, elf_hppa_record_segment_addrs
,
3792 /* VALUE holds the absolute address. We want to include the
3793 addend, then turn it into a segment relative address.
3795 The segment is derived from SYM_SEC. We assume that there are
3796 only two segments of note in the resulting executable/shlib.
3797 A readonly segment (.text) and a readwrite segment (.data). */
3800 if (sym_sec
->flags
& SEC_CODE
)
3801 value
-= hppa_info
->text_segment_base
;
3803 value
-= hppa_info
->data_segment_base
;
3805 if (r_type
== R_PARISC_SEGREL32
)
3806 bfd_put_32 (input_bfd
, value
, hit_data
);
3808 bfd_put_64 (input_bfd
, value
, hit_data
);
3809 return bfd_reloc_ok
;
3812 /* Something we don't know how to handle. */
3814 return bfd_reloc_notsupported
;
3817 /* Update the instruction word. */
3818 bfd_put_32 (input_bfd
, (bfd_vma
) insn
, hit_data
);
3819 return bfd_reloc_ok
;
3822 /* Relocate an HPPA ELF section. */
3825 elf64_hppa_relocate_section (bfd
*output_bfd
,
3826 struct bfd_link_info
*info
,
3828 asection
*input_section
,
3830 Elf_Internal_Rela
*relocs
,
3831 Elf_Internal_Sym
*local_syms
,
3832 asection
**local_sections
)
3834 Elf_Internal_Shdr
*symtab_hdr
;
3835 Elf_Internal_Rela
*rel
;
3836 Elf_Internal_Rela
*relend
;
3837 struct elf64_hppa_link_hash_table
*hppa_info
;
3839 hppa_info
= hppa_link_hash_table (info
);
3840 if (hppa_info
== NULL
)
3843 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3846 relend
= relocs
+ input_section
->reloc_count
;
3847 for (; rel
< relend
; rel
++)
3850 reloc_howto_type
*howto
= elf_hppa_howto_table
+ ELF_R_TYPE (rel
->r_info
);
3851 unsigned long r_symndx
;
3852 struct elf_link_hash_entry
*eh
;
3853 Elf_Internal_Sym
*sym
;
3856 bfd_reloc_status_type r
;
3858 r_type
= ELF_R_TYPE (rel
->r_info
);
3859 if (r_type
< 0 || r_type
>= (int) R_PARISC_UNIMPLEMENTED
)
3861 bfd_set_error (bfd_error_bad_value
);
3864 if (r_type
== (unsigned int) R_PARISC_GNU_VTENTRY
3865 || r_type
== (unsigned int) R_PARISC_GNU_VTINHERIT
)
3868 /* This is a final link. */
3869 r_symndx
= ELF_R_SYM (rel
->r_info
);
3873 if (r_symndx
< symtab_hdr
->sh_info
)
3875 /* This is a local symbol, hh defaults to NULL. */
3876 sym
= local_syms
+ r_symndx
;
3877 sym_sec
= local_sections
[r_symndx
];
3878 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sym_sec
, rel
);
3882 /* This is not a local symbol. */
3883 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (input_bfd
);
3885 /* It seems this can happen with erroneous or unsupported
3886 input (mixing a.out and elf in an archive, for example.) */
3887 if (sym_hashes
== NULL
)
3890 eh
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3892 while (eh
->root
.type
== bfd_link_hash_indirect
3893 || eh
->root
.type
== bfd_link_hash_warning
)
3894 eh
= (struct elf_link_hash_entry
*) eh
->root
.u
.i
.link
;
3897 if (eh
->root
.type
== bfd_link_hash_defined
3898 || eh
->root
.type
== bfd_link_hash_defweak
)
3900 sym_sec
= eh
->root
.u
.def
.section
;
3902 && sym_sec
->output_section
!= NULL
)
3903 relocation
= (eh
->root
.u
.def
.value
3904 + sym_sec
->output_section
->vma
3905 + sym_sec
->output_offset
);
3907 else if (eh
->root
.type
== bfd_link_hash_undefweak
)
3909 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
3910 && ELF_ST_VISIBILITY (eh
->other
) == STV_DEFAULT
)
3912 else if (!info
->relocatable
3913 && elf_hppa_is_dynamic_loader_symbol (eh
->root
.root
.string
))
3915 else if (!info
->relocatable
)
3918 err
= (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
3919 || ELF_ST_VISIBILITY (eh
->other
) != STV_DEFAULT
);
3920 if (!info
->callbacks
->undefined_symbol (info
,
3921 eh
->root
.root
.string
,
3924 rel
->r_offset
, err
))
3928 if (!info
->relocatable
3930 && eh
->root
.type
!= bfd_link_hash_defined
3931 && eh
->root
.type
!= bfd_link_hash_defweak
3932 && eh
->root
.type
!= bfd_link_hash_undefweak
)
3934 if (info
->unresolved_syms_in_objects
== RM_IGNORE
3935 && ELF_ST_VISIBILITY (eh
->other
) == STV_DEFAULT
3936 && eh
->type
== STT_PARISC_MILLI
)
3938 if (! info
->callbacks
->undefined_symbol
3939 (info
, eh_name (eh
), input_bfd
,
3940 input_section
, rel
->r_offset
, FALSE
))
3946 if (sym_sec
!= NULL
&& elf_discarded_section (sym_sec
))
3947 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
3948 rel
, relend
, howto
, contents
);
3950 if (info
->relocatable
)
3953 r
= elf_hppa_final_link_relocate (rel
, input_bfd
, output_bfd
,
3954 input_section
, contents
,
3955 relocation
, info
, sym_sec
,
3958 if (r
!= bfd_reloc_ok
)
3964 case bfd_reloc_overflow
:
3966 const char *sym_name
;
3972 sym_name
= bfd_elf_string_from_elf_section (input_bfd
,
3973 symtab_hdr
->sh_link
,
3975 if (sym_name
== NULL
)
3977 if (*sym_name
== '\0')
3978 sym_name
= bfd_section_name (input_bfd
, sym_sec
);
3981 if (!((*info
->callbacks
->reloc_overflow
)
3982 (info
, (eh
? &eh
->root
: NULL
), sym_name
,
3983 howto
->name
, (bfd_vma
) 0, input_bfd
,
3984 input_section
, rel
->r_offset
)))
3994 static const struct bfd_elf_special_section elf64_hppa_special_sections
[] =
3996 { STRING_COMMA_LEN (".fini"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
3997 { STRING_COMMA_LEN (".init"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
3998 { STRING_COMMA_LEN (".plt"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
3999 { STRING_COMMA_LEN (".dlt"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
4000 { STRING_COMMA_LEN (".sdata"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
4001 { STRING_COMMA_LEN (".sbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
4002 { STRING_COMMA_LEN (".tbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_HP_TLS
},
4003 { NULL
, 0, 0, 0, 0 }
4006 /* The hash bucket size is the standard one, namely 4. */
4008 const struct elf_size_info hppa64_elf_size_info
=
4010 sizeof (Elf64_External_Ehdr
),
4011 sizeof (Elf64_External_Phdr
),
4012 sizeof (Elf64_External_Shdr
),
4013 sizeof (Elf64_External_Rel
),
4014 sizeof (Elf64_External_Rela
),
4015 sizeof (Elf64_External_Sym
),
4016 sizeof (Elf64_External_Dyn
),
4017 sizeof (Elf_External_Note
),
4021 ELFCLASS64
, EV_CURRENT
,
4022 bfd_elf64_write_out_phdrs
,
4023 bfd_elf64_write_shdrs_and_ehdr
,
4024 bfd_elf64_checksum_contents
,
4025 bfd_elf64_write_relocs
,
4026 bfd_elf64_swap_symbol_in
,
4027 bfd_elf64_swap_symbol_out
,
4028 bfd_elf64_slurp_reloc_table
,
4029 bfd_elf64_slurp_symbol_table
,
4030 bfd_elf64_swap_dyn_in
,
4031 bfd_elf64_swap_dyn_out
,
4032 bfd_elf64_swap_reloc_in
,
4033 bfd_elf64_swap_reloc_out
,
4034 bfd_elf64_swap_reloca_in
,
4035 bfd_elf64_swap_reloca_out
4038 #define TARGET_BIG_SYM bfd_elf64_hppa_vec
4039 #define TARGET_BIG_NAME "elf64-hppa"
4040 #define ELF_ARCH bfd_arch_hppa
4041 #define ELF_TARGET_ID HPPA64_ELF_DATA
4042 #define ELF_MACHINE_CODE EM_PARISC
4043 /* This is not strictly correct. The maximum page size for PA2.0 is
4044 64M. But everything still uses 4k. */
4045 #define ELF_MAXPAGESIZE 0x1000
4046 #define ELF_OSABI ELFOSABI_HPUX
4048 #define bfd_elf64_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
4049 #define bfd_elf64_bfd_reloc_name_lookup elf_hppa_reloc_name_lookup
4050 #define bfd_elf64_bfd_is_local_label_name elf_hppa_is_local_label_name
4051 #define elf_info_to_howto elf_hppa_info_to_howto
4052 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
4054 #define elf_backend_section_from_shdr elf64_hppa_section_from_shdr
4055 #define elf_backend_object_p elf64_hppa_object_p
4056 #define elf_backend_final_write_processing \
4057 elf_hppa_final_write_processing
4058 #define elf_backend_fake_sections elf_hppa_fake_sections
4059 #define elf_backend_add_symbol_hook elf_hppa_add_symbol_hook
4061 #define elf_backend_relocate_section elf_hppa_relocate_section
4063 #define bfd_elf64_bfd_final_link elf_hppa_final_link
4065 #define elf_backend_create_dynamic_sections \
4066 elf64_hppa_create_dynamic_sections
4067 #define elf_backend_post_process_headers elf64_hppa_post_process_headers
4069 #define elf_backend_omit_section_dynsym \
4070 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
4071 #define elf_backend_adjust_dynamic_symbol \
4072 elf64_hppa_adjust_dynamic_symbol
4074 #define elf_backend_size_dynamic_sections \
4075 elf64_hppa_size_dynamic_sections
4077 #define elf_backend_finish_dynamic_symbol \
4078 elf64_hppa_finish_dynamic_symbol
4079 #define elf_backend_finish_dynamic_sections \
4080 elf64_hppa_finish_dynamic_sections
4081 #define elf_backend_grok_prstatus elf64_hppa_grok_prstatus
4082 #define elf_backend_grok_psinfo elf64_hppa_grok_psinfo
4084 /* Stuff for the BFD linker: */
4085 #define bfd_elf64_bfd_link_hash_table_create \
4086 elf64_hppa_hash_table_create
4088 #define elf_backend_check_relocs \
4089 elf64_hppa_check_relocs
4091 #define elf_backend_size_info \
4092 hppa64_elf_size_info
4094 #define elf_backend_additional_program_headers \
4095 elf64_hppa_additional_program_headers
4097 #define elf_backend_modify_segment_map \
4098 elf64_hppa_modify_segment_map
4100 #define elf_backend_link_output_symbol_hook \
4101 elf64_hppa_link_output_symbol_hook
4103 #define elf_backend_want_got_plt 0
4104 #define elf_backend_plt_readonly 0
4105 #define elf_backend_want_plt_sym 0
4106 #define elf_backend_got_header_size 0
4107 #define elf_backend_type_change_ok TRUE
4108 #define elf_backend_get_symbol_type elf64_hppa_elf_get_symbol_type
4109 #define elf_backend_reloc_type_class elf64_hppa_reloc_type_class
4110 #define elf_backend_rela_normal 1
4111 #define elf_backend_special_sections elf64_hppa_special_sections
4112 #define elf_backend_action_discarded elf_hppa_action_discarded
4113 #define elf_backend_section_from_phdr elf64_hppa_section_from_phdr
4115 #define elf64_bed elf64_hppa_hpux_bed
4117 #include "elf64-target.h"
4119 #undef TARGET_BIG_SYM
4120 #define TARGET_BIG_SYM bfd_elf64_hppa_linux_vec
4121 #undef TARGET_BIG_NAME
4122 #define TARGET_BIG_NAME "elf64-hppa-linux"
4124 #define ELF_OSABI ELFOSABI_LINUX
4125 #undef elf_backend_post_process_headers
4126 #define elf_backend_post_process_headers _bfd_elf_set_osabi
4128 #define elf64_bed elf64_hppa_linux_bed
4130 #include "elf64-target.h"