1 /* Support for HPPA 64-bit ELF
2 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
3 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 ((struct elf64_hppa_link_hash_table *) ((p)->hash))
153 #define hppa_elf_hash_entry(ent) \
154 ((struct elf64_hppa_link_hash_entry *)(ent))
156 #define eh_name(eh) \
157 (eh ? eh->root.root.string : "<undef>")
159 typedef struct bfd_hash_entry
*(*new_hash_entry_func
)
160 (struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *);
162 static struct bfd_link_hash_table
*elf64_hppa_hash_table_create
165 /* This must follow the definitions of the various derived linker
166 hash tables and shared functions. */
167 #include "elf-hppa.h"
169 static bfd_boolean elf64_hppa_object_p
172 static void elf64_hppa_post_process_headers
173 (bfd
*, struct bfd_link_info
*);
175 static bfd_boolean elf64_hppa_create_dynamic_sections
176 (bfd
*, struct bfd_link_info
*);
178 static bfd_boolean elf64_hppa_adjust_dynamic_symbol
179 (struct bfd_link_info
*, struct elf_link_hash_entry
*);
181 static bfd_boolean elf64_hppa_mark_milli_and_exported_functions
182 (struct elf_link_hash_entry
*, void *);
184 static bfd_boolean elf64_hppa_size_dynamic_sections
185 (bfd
*, struct bfd_link_info
*);
187 static int elf64_hppa_link_output_symbol_hook
188 (struct bfd_link_info
*, const char *, Elf_Internal_Sym
*,
189 asection
*, struct elf_link_hash_entry
*);
191 static bfd_boolean elf64_hppa_finish_dynamic_symbol
192 (bfd
*, struct bfd_link_info
*,
193 struct elf_link_hash_entry
*, Elf_Internal_Sym
*);
195 static enum elf_reloc_type_class elf64_hppa_reloc_type_class
196 (const Elf_Internal_Rela
*);
198 static bfd_boolean elf64_hppa_finish_dynamic_sections
199 (bfd
*, struct bfd_link_info
*);
201 static bfd_boolean elf64_hppa_check_relocs
202 (bfd
*, struct bfd_link_info
*,
203 asection
*, const Elf_Internal_Rela
*);
205 static bfd_boolean elf64_hppa_dynamic_symbol_p
206 (struct elf_link_hash_entry
*, struct bfd_link_info
*);
208 static bfd_boolean elf64_hppa_mark_exported_functions
209 (struct elf_link_hash_entry
*, void *);
211 static bfd_boolean elf64_hppa_finalize_opd
212 (struct elf_link_hash_entry
*, void *);
214 static bfd_boolean elf64_hppa_finalize_dlt
215 (struct elf_link_hash_entry
*, void *);
217 static bfd_boolean allocate_global_data_dlt
218 (struct elf_link_hash_entry
*, void *);
220 static bfd_boolean allocate_global_data_plt
221 (struct elf_link_hash_entry
*, void *);
223 static bfd_boolean allocate_global_data_stub
224 (struct elf_link_hash_entry
*, void *);
226 static bfd_boolean allocate_global_data_opd
227 (struct elf_link_hash_entry
*, void *);
229 static bfd_boolean get_reloc_section
230 (bfd
*, struct elf64_hppa_link_hash_table
*, asection
*);
232 static bfd_boolean count_dyn_reloc
233 (bfd
*, struct elf64_hppa_link_hash_entry
*,
234 int, asection
*, int, bfd_vma
, bfd_vma
);
236 static bfd_boolean allocate_dynrel_entries
237 (struct elf_link_hash_entry
*, void *);
239 static bfd_boolean elf64_hppa_finalize_dynreloc
240 (struct elf_link_hash_entry
*, void *);
242 static bfd_boolean get_opd
243 (bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*);
245 static bfd_boolean get_plt
246 (bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*);
248 static bfd_boolean get_dlt
249 (bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*);
251 static bfd_boolean get_stub
252 (bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*);
254 static int elf64_hppa_elf_get_symbol_type
255 (Elf_Internal_Sym
*, int);
257 /* Initialize an entry in the link hash table. */
259 static struct bfd_hash_entry
*
260 hppa64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
261 struct bfd_hash_table
*table
,
264 /* Allocate the structure if it has not already been allocated by a
268 entry
= bfd_hash_allocate (table
,
269 sizeof (struct elf64_hppa_link_hash_entry
));
274 /* Call the allocation method of the superclass. */
275 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
278 struct elf64_hppa_link_hash_entry
*hh
;
280 /* Initialize our local data. All zeros. */
281 hh
= hppa_elf_hash_entry (entry
);
282 memset (&hh
->dlt_offset
, 0,
283 (sizeof (struct elf64_hppa_link_hash_entry
)
284 - offsetof (struct elf64_hppa_link_hash_entry
, dlt_offset
)));
290 /* Create the derived linker hash table. The PA64 ELF port uses this
291 derived hash table to keep information specific to the PA ElF
292 linker (without using static variables). */
294 static struct bfd_link_hash_table
*
295 elf64_hppa_hash_table_create (bfd
*abfd
)
297 struct elf64_hppa_link_hash_table
*htab
;
298 bfd_size_type amt
= sizeof (*htab
);
300 htab
= bfd_zalloc (abfd
, amt
);
304 if (!_bfd_elf_link_hash_table_init (&htab
->root
, abfd
,
305 hppa64_link_hash_newfunc
,
306 sizeof (struct elf64_hppa_link_hash_entry
)))
308 bfd_release (abfd
, htab
);
312 htab
->text_segment_base
= (bfd_vma
) -1;
313 htab
->data_segment_base
= (bfd_vma
) -1;
315 return &htab
->root
.root
;
318 /* Return nonzero if ABFD represents a PA2.0 ELF64 file.
320 Additionally we set the default architecture and machine. */
322 elf64_hppa_object_p (bfd
*abfd
)
324 Elf_Internal_Ehdr
* i_ehdrp
;
327 i_ehdrp
= elf_elfheader (abfd
);
328 if (strcmp (bfd_get_target (abfd
), "elf64-hppa-linux") == 0)
330 /* GCC on hppa-linux produces binaries with OSABI=Linux,
331 but the kernel produces corefiles with OSABI=SysV. */
332 if (i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_LINUX
333 && i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_NONE
) /* aka SYSV */
338 /* HPUX produces binaries with OSABI=HPUX,
339 but the kernel produces corefiles with OSABI=SysV. */
340 if (i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_HPUX
341 && i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_NONE
) /* aka SYSV */
345 flags
= i_ehdrp
->e_flags
;
346 switch (flags
& (EF_PARISC_ARCH
| EF_PARISC_WIDE
))
349 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 10);
351 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 11);
353 if (i_ehdrp
->e_ident
[EI_CLASS
] == ELFCLASS64
)
354 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 25);
356 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 20);
357 case EFA_PARISC_2_0
| EF_PARISC_WIDE
:
358 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 25);
360 /* Don't be fussy. */
364 /* Given section type (hdr->sh_type), return a boolean indicating
365 whether or not the section is an elf64-hppa specific section. */
367 elf64_hppa_section_from_shdr (bfd
*abfd
,
368 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
))
392 newsect
= hdr
->bfd_section
;
397 /* SEC is a section containing relocs for an input BFD when linking; return
398 a suitable section for holding relocs in the output BFD for a link. */
401 get_reloc_section (bfd
*abfd
,
402 struct elf64_hppa_link_hash_table
*hppa_info
,
405 const char *srel_name
;
409 srel_name
= (bfd_elf_string_from_elf_section
410 (abfd
, elf_elfheader(abfd
)->e_shstrndx
,
411 elf_section_data(sec
)->rel_hdr
.sh_name
));
412 if (srel_name
== NULL
)
415 BFD_ASSERT ((CONST_STRNEQ (srel_name
, ".rela")
416 && strcmp (bfd_get_section_name (abfd
, sec
),
418 || (CONST_STRNEQ (srel_name
, ".rel")
419 && strcmp (bfd_get_section_name (abfd
, sec
),
420 srel_name
+ 4) == 0));
422 dynobj
= hppa_info
->root
.dynobj
;
424 hppa_info
->root
.dynobj
= dynobj
= abfd
;
426 srel
= bfd_get_section_by_name (dynobj
, srel_name
);
429 srel
= bfd_make_section_with_flags (dynobj
, srel_name
,
437 || !bfd_set_section_alignment (dynobj
, srel
, 3))
441 hppa_info
->other_rel_sec
= srel
;
445 /* Add a new entry to the list of dynamic relocations against DYN_H.
447 We use this to keep a record of all the FPTR relocations against a
448 particular symbol so that we can create FPTR relocations in the
452 count_dyn_reloc (bfd
*abfd
,
453 struct elf64_hppa_link_hash_entry
*hh
,
460 struct elf64_hppa_dyn_reloc_entry
*rent
;
462 rent
= (struct elf64_hppa_dyn_reloc_entry
*)
463 bfd_alloc (abfd
, (bfd_size_type
) sizeof (*rent
));
467 rent
->next
= hh
->reloc_entries
;
470 rent
->sec_symndx
= sec_symndx
;
471 rent
->offset
= offset
;
472 rent
->addend
= addend
;
473 hh
->reloc_entries
= rent
;
478 /* Return a pointer to the local DLT, PLT and OPD reference counts
479 for ABFD. Returns NULL if the storage allocation fails. */
481 static bfd_signed_vma
*
482 hppa64_elf_local_refcounts (bfd
*abfd
)
484 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
485 bfd_signed_vma
*local_refcounts
;
487 local_refcounts
= elf_local_got_refcounts (abfd
);
488 if (local_refcounts
== NULL
)
492 /* Allocate space for local DLT, PLT and OPD reference
493 counts. Done this way to save polluting elf_obj_tdata
494 with another target specific pointer. */
495 size
= symtab_hdr
->sh_info
;
496 size
*= 3 * sizeof (bfd_signed_vma
);
497 local_refcounts
= bfd_zalloc (abfd
, size
);
498 elf_local_got_refcounts (abfd
) = local_refcounts
;
500 return local_refcounts
;
503 /* Scan the RELOCS and record the type of dynamic entries that each
504 referenced symbol needs. */
507 elf64_hppa_check_relocs (bfd
*abfd
,
508 struct bfd_link_info
*info
,
510 const Elf_Internal_Rela
*relocs
)
512 struct elf64_hppa_link_hash_table
*hppa_info
;
513 const Elf_Internal_Rela
*relend
;
514 Elf_Internal_Shdr
*symtab_hdr
;
515 const Elf_Internal_Rela
*rel
;
516 asection
*dlt
, *plt
, *stubs
;
519 unsigned int sec_symndx
;
521 if (info
->relocatable
)
524 /* If this is the first dynamic object found in the link, create
525 the special sections required for dynamic linking. */
526 if (! elf_hash_table (info
)->dynamic_sections_created
)
528 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
532 hppa_info
= hppa_link_hash_table (info
);
533 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
535 /* If necessary, build a new table holding section symbols indices
538 if (info
->shared
&& hppa_info
->section_syms_bfd
!= abfd
)
541 unsigned int highest_shndx
;
542 Elf_Internal_Sym
*local_syms
= NULL
;
543 Elf_Internal_Sym
*isym
, *isymend
;
546 /* We're done with the old cache of section index to section symbol
547 index information. Free it.
549 ?!? Note we leak the last section_syms array. Presumably we
550 could free it in one of the later routines in this file. */
551 if (hppa_info
->section_syms
)
552 free (hppa_info
->section_syms
);
554 /* Read this BFD's local symbols. */
555 if (symtab_hdr
->sh_info
!= 0)
557 local_syms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
558 if (local_syms
== NULL
)
559 local_syms
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
560 symtab_hdr
->sh_info
, 0,
562 if (local_syms
== NULL
)
566 /* Record the highest section index referenced by the local symbols. */
568 isymend
= local_syms
+ symtab_hdr
->sh_info
;
569 for (isym
= local_syms
; isym
< isymend
; isym
++)
571 if (isym
->st_shndx
> highest_shndx
572 && isym
->st_shndx
< SHN_LORESERVE
)
573 highest_shndx
= isym
->st_shndx
;
576 /* Allocate an array to hold the section index to section symbol index
577 mapping. Bump by one since we start counting at zero. */
581 hppa_info
->section_syms
= (int *) bfd_malloc (amt
);
583 /* Now walk the local symbols again. If we find a section symbol,
584 record the index of the symbol into the section_syms array. */
585 for (i
= 0, isym
= local_syms
; isym
< isymend
; i
++, isym
++)
587 if (ELF_ST_TYPE (isym
->st_info
) == STT_SECTION
)
588 hppa_info
->section_syms
[isym
->st_shndx
] = i
;
591 /* We are finished with the local symbols. */
592 if (local_syms
!= NULL
593 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
595 if (! info
->keep_memory
)
599 /* Cache the symbols for elf_link_input_bfd. */
600 symtab_hdr
->contents
= (unsigned char *) local_syms
;
604 /* Record which BFD we built the section_syms mapping for. */
605 hppa_info
->section_syms_bfd
= abfd
;
608 /* Record the symbol index for this input section. We may need it for
609 relocations when building shared libraries. When not building shared
610 libraries this value is never really used, but assign it to zero to
611 prevent out of bounds memory accesses in other routines. */
614 sec_symndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
616 /* If we did not find a section symbol for this section, then
617 something went terribly wrong above. */
618 if (sec_symndx
== SHN_BAD
)
621 if (sec_symndx
< SHN_LORESERVE
)
622 sec_symndx
= hppa_info
->section_syms
[sec_symndx
];
629 dlt
= plt
= stubs
= NULL
;
633 relend
= relocs
+ sec
->reloc_count
;
634 for (rel
= relocs
; rel
< relend
; ++rel
)
645 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
646 struct elf64_hppa_link_hash_entry
*hh
;
648 bfd_boolean maybe_dynamic
;
649 int dynrel_type
= R_PARISC_NONE
;
650 static reloc_howto_type
*howto
;
652 if (r_symndx
>= symtab_hdr
->sh_info
)
654 /* We're dealing with a global symbol -- find its hash entry
655 and mark it as being referenced. */
656 long indx
= r_symndx
- symtab_hdr
->sh_info
;
657 hh
= hppa_elf_hash_entry (elf_sym_hashes (abfd
)[indx
]);
658 while (hh
->eh
.root
.type
== bfd_link_hash_indirect
659 || hh
->eh
.root
.type
== bfd_link_hash_warning
)
660 hh
= hppa_elf_hash_entry (hh
->eh
.root
.u
.i
.link
);
662 hh
->eh
.ref_regular
= 1;
667 /* We can only get preliminary data on whether a symbol is
668 locally or externally defined, as not all of the input files
669 have yet been processed. Do something with what we know, as
670 this may help reduce memory usage and processing time later. */
671 maybe_dynamic
= FALSE
;
672 if (hh
&& ((info
->shared
674 || info
->unresolved_syms_in_shared_libs
== RM_IGNORE
))
675 || !hh
->eh
.def_regular
676 || hh
->eh
.root
.type
== bfd_link_hash_defweak
))
677 maybe_dynamic
= TRUE
;
679 howto
= elf_hppa_howto_table
+ ELF64_R_TYPE (rel
->r_info
);
683 /* These are simple indirect references to symbols through the
684 DLT. We need to create a DLT entry for any symbols which
685 appears in a DLTIND relocation. */
686 case R_PARISC_DLTIND21L
:
687 case R_PARISC_DLTIND14R
:
688 case R_PARISC_DLTIND14F
:
689 case R_PARISC_DLTIND14WR
:
690 case R_PARISC_DLTIND14DR
:
691 need_entry
= NEED_DLT
;
694 /* ?!? These need a DLT entry. But I have no idea what to do with
695 the "link time TP value. */
696 case R_PARISC_LTOFF_TP21L
:
697 case R_PARISC_LTOFF_TP14R
:
698 case R_PARISC_LTOFF_TP14F
:
699 case R_PARISC_LTOFF_TP64
:
700 case R_PARISC_LTOFF_TP14WR
:
701 case R_PARISC_LTOFF_TP14DR
:
702 case R_PARISC_LTOFF_TP16F
:
703 case R_PARISC_LTOFF_TP16WF
:
704 case R_PARISC_LTOFF_TP16DF
:
705 need_entry
= NEED_DLT
;
708 /* These are function calls. Depending on their precise target we
709 may need to make a stub for them. The stub uses the PLT, so we
710 need to create PLT entries for these symbols too. */
711 case R_PARISC_PCREL12F
:
712 case R_PARISC_PCREL17F
:
713 case R_PARISC_PCREL22F
:
714 case R_PARISC_PCREL32
:
715 case R_PARISC_PCREL64
:
716 case R_PARISC_PCREL21L
:
717 case R_PARISC_PCREL17R
:
718 case R_PARISC_PCREL17C
:
719 case R_PARISC_PCREL14R
:
720 case R_PARISC_PCREL14F
:
721 case R_PARISC_PCREL22C
:
722 case R_PARISC_PCREL14WR
:
723 case R_PARISC_PCREL14DR
:
724 case R_PARISC_PCREL16F
:
725 case R_PARISC_PCREL16WF
:
726 case R_PARISC_PCREL16DF
:
727 /* Function calls might need to go through the .plt, and
728 might need a long branch stub. */
729 if (hh
!= NULL
&& hh
->eh
.type
!= STT_PARISC_MILLI
)
730 need_entry
= (NEED_PLT
| NEED_STUB
);
735 case R_PARISC_PLTOFF21L
:
736 case R_PARISC_PLTOFF14R
:
737 case R_PARISC_PLTOFF14F
:
738 case R_PARISC_PLTOFF14WR
:
739 case R_PARISC_PLTOFF14DR
:
740 case R_PARISC_PLTOFF16F
:
741 case R_PARISC_PLTOFF16WF
:
742 case R_PARISC_PLTOFF16DF
:
743 need_entry
= (NEED_PLT
);
747 if (info
->shared
|| maybe_dynamic
)
748 need_entry
= (NEED_DYNREL
);
749 dynrel_type
= R_PARISC_DIR64
;
752 /* This is an indirect reference through the DLT to get the address
753 of a OPD descriptor. Thus we need to make a DLT entry that points
755 case R_PARISC_LTOFF_FPTR21L
:
756 case R_PARISC_LTOFF_FPTR14R
:
757 case R_PARISC_LTOFF_FPTR14WR
:
758 case R_PARISC_LTOFF_FPTR14DR
:
759 case R_PARISC_LTOFF_FPTR32
:
760 case R_PARISC_LTOFF_FPTR64
:
761 case R_PARISC_LTOFF_FPTR16F
:
762 case R_PARISC_LTOFF_FPTR16WF
:
763 case R_PARISC_LTOFF_FPTR16DF
:
764 if (info
->shared
|| maybe_dynamic
)
765 need_entry
= (NEED_DLT
| NEED_OPD
| NEED_PLT
);
767 need_entry
= (NEED_DLT
| NEED_OPD
| NEED_PLT
);
768 dynrel_type
= R_PARISC_FPTR64
;
771 /* This is a simple OPD entry. */
772 case R_PARISC_FPTR64
:
773 if (info
->shared
|| maybe_dynamic
)
774 need_entry
= (NEED_OPD
| NEED_PLT
| NEED_DYNREL
);
776 need_entry
= (NEED_OPD
| NEED_PLT
);
777 dynrel_type
= R_PARISC_FPTR64
;
780 /* Add more cases as needed. */
788 /* Stash away enough information to be able to find this symbol
789 regardless of whether or not it is local or global. */
791 hh
->sym_indx
= r_symndx
;
794 /* Create what's needed. */
795 if (need_entry
& NEED_DLT
)
797 /* Allocate space for a DLT entry, as well as a dynamic
798 relocation for this entry. */
799 if (! hppa_info
->dlt_sec
800 && ! get_dlt (abfd
, info
, hppa_info
))
806 hh
->eh
.got
.refcount
+= 1;
810 bfd_signed_vma
*local_dlt_refcounts
;
812 /* This is a DLT entry for a local symbol. */
813 local_dlt_refcounts
= hppa64_elf_local_refcounts (abfd
);
814 if (local_dlt_refcounts
== NULL
)
816 local_dlt_refcounts
[r_symndx
] += 1;
820 if (need_entry
& NEED_PLT
)
822 if (! hppa_info
->plt_sec
823 && ! get_plt (abfd
, info
, hppa_info
))
829 hh
->eh
.needs_plt
= 1;
830 hh
->eh
.plt
.refcount
+= 1;
834 bfd_signed_vma
*local_dlt_refcounts
;
835 bfd_signed_vma
*local_plt_refcounts
;
837 /* This is a PLT entry for a local symbol. */
838 local_dlt_refcounts
= hppa64_elf_local_refcounts (abfd
);
839 if (local_dlt_refcounts
== NULL
)
841 local_plt_refcounts
= local_dlt_refcounts
+ symtab_hdr
->sh_info
;
842 local_plt_refcounts
[r_symndx
] += 1;
846 if (need_entry
& NEED_STUB
)
848 if (! hppa_info
->stub_sec
849 && ! get_stub (abfd
, info
, hppa_info
))
855 if (need_entry
& NEED_OPD
)
857 if (! hppa_info
->opd_sec
858 && ! get_opd (abfd
, info
, hppa_info
))
861 /* FPTRs are not allocated by the dynamic linker for PA64,
862 though it is possible that will change in the future. */
868 bfd_signed_vma
*local_dlt_refcounts
;
869 bfd_signed_vma
*local_opd_refcounts
;
871 /* This is a OPD for a local symbol. */
872 local_dlt_refcounts
= hppa64_elf_local_refcounts (abfd
);
873 if (local_dlt_refcounts
== NULL
)
875 local_opd_refcounts
= (local_dlt_refcounts
876 + 2 * symtab_hdr
->sh_info
);
877 local_opd_refcounts
[r_symndx
] += 1;
881 /* Add a new dynamic relocation to the chain of dynamic
882 relocations for this symbol. */
883 if ((need_entry
& NEED_DYNREL
) && (sec
->flags
& SEC_ALLOC
))
885 if (! hppa_info
->other_rel_sec
886 && ! get_reloc_section (abfd
, hppa_info
, sec
))
889 /* Count dynamic relocations against global symbols. */
891 && !count_dyn_reloc (abfd
, hh
, dynrel_type
, sec
,
892 sec_symndx
, rel
->r_offset
, rel
->r_addend
))
895 /* If we are building a shared library and we just recorded
896 a dynamic R_PARISC_FPTR64 relocation, then make sure the
897 section symbol for this section ends up in the dynamic
899 if (info
->shared
&& dynrel_type
== R_PARISC_FPTR64
900 && ! (bfd_elf_link_record_local_dynamic_symbol
901 (info
, abfd
, sec_symndx
)))
916 struct elf64_hppa_allocate_data
918 struct bfd_link_info
*info
;
922 /* Should we do dynamic things to this symbol? */
925 elf64_hppa_dynamic_symbol_p (struct elf_link_hash_entry
*eh
,
926 struct bfd_link_info
*info
)
928 /* ??? What, if anything, needs to happen wrt STV_PROTECTED symbols
929 and relocations that retrieve a function descriptor? Assume the
931 if (_bfd_elf_dynamic_symbol_p (eh
, info
, 1))
933 /* ??? Why is this here and not elsewhere is_local_label_name. */
934 if (eh
->root
.root
.string
[0] == '$' && eh
->root
.root
.string
[1] == '$')
943 /* Mark all functions exported by this file so that we can later allocate
944 entries in .opd for them. */
947 elf64_hppa_mark_exported_functions (struct elf_link_hash_entry
*eh
, void *data
)
949 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
950 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
951 struct elf64_hppa_link_hash_table
*hppa_info
;
953 hppa_info
= hppa_link_hash_table (info
);
955 if (eh
->root
.type
== bfd_link_hash_warning
)
956 eh
= (struct elf_link_hash_entry
*) eh
->root
.u
.i
.link
;
959 && (eh
->root
.type
== bfd_link_hash_defined
960 || eh
->root
.type
== bfd_link_hash_defweak
)
961 && eh
->root
.u
.def
.section
->output_section
!= NULL
962 && eh
->type
== STT_FUNC
)
964 if (! hppa_info
->opd_sec
965 && ! get_opd (hppa_info
->root
.dynobj
, info
, hppa_info
))
970 /* Put a flag here for output_symbol_hook. */
978 /* Allocate space for a DLT entry. */
981 allocate_global_data_dlt (struct elf_link_hash_entry
*eh
, void *data
)
983 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
984 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
990 /* Possibly add the symbol to the local dynamic symbol
991 table since we might need to create a dynamic relocation
993 if (eh
->dynindx
== -1 && eh
->type
!= STT_PARISC_MILLI
)
995 bfd
*owner
= eh
->root
.u
.def
.section
->owner
;
997 if (! (bfd_elf_link_record_local_dynamic_symbol
998 (x
->info
, owner
, hh
->sym_indx
)))
1003 hh
->dlt_offset
= x
->ofs
;
1004 x
->ofs
+= DLT_ENTRY_SIZE
;
1009 /* Allocate space for a DLT.PLT entry. */
1012 allocate_global_data_plt (struct elf_link_hash_entry
*eh
, void *data
)
1014 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
1015 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1018 && elf64_hppa_dynamic_symbol_p (eh
, x
->info
)
1019 && !((eh
->root
.type
== bfd_link_hash_defined
1020 || eh
->root
.type
== bfd_link_hash_defweak
)
1021 && eh
->root
.u
.def
.section
->output_section
!= NULL
))
1023 hh
->plt_offset
= x
->ofs
;
1024 x
->ofs
+= PLT_ENTRY_SIZE
;
1025 if (hh
->plt_offset
< 0x2000)
1026 hppa_link_hash_table (x
->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
)
1344 if (! get_stub (abfd
, info
, hppa_link_hash_table (info
)))
1347 if (! get_dlt (abfd
, info
, hppa_link_hash_table (info
)))
1350 if (! get_plt (abfd
, info
, hppa_link_hash_table (info
)))
1353 if (! get_opd (abfd
, info
, hppa_link_hash_table (info
)))
1356 s
= bfd_make_section_with_flags (abfd
, ".rela.dlt",
1357 (SEC_ALLOC
| SEC_LOAD
1361 | SEC_LINKER_CREATED
));
1363 || !bfd_set_section_alignment (abfd
, s
, 3))
1365 hppa_link_hash_table (info
)->dlt_rel_sec
= s
;
1367 s
= bfd_make_section_with_flags (abfd
, ".rela.plt",
1368 (SEC_ALLOC
| SEC_LOAD
1372 | SEC_LINKER_CREATED
));
1374 || !bfd_set_section_alignment (abfd
, s
, 3))
1376 hppa_link_hash_table (info
)->plt_rel_sec
= s
;
1378 s
= bfd_make_section_with_flags (abfd
, ".rela.data",
1379 (SEC_ALLOC
| SEC_LOAD
1383 | SEC_LINKER_CREATED
));
1385 || !bfd_set_section_alignment (abfd
, s
, 3))
1387 hppa_link_hash_table (info
)->other_rel_sec
= s
;
1389 s
= bfd_make_section_with_flags (abfd
, ".rela.opd",
1390 (SEC_ALLOC
| SEC_LOAD
1394 | SEC_LINKER_CREATED
));
1396 || !bfd_set_section_alignment (abfd
, s
, 3))
1398 hppa_link_hash_table (info
)->opd_rel_sec
= s
;
1403 /* Allocate dynamic relocations for those symbols that turned out
1407 allocate_dynrel_entries (struct elf_link_hash_entry
*eh
, void *data
)
1409 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
1410 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1411 struct elf64_hppa_link_hash_table
*hppa_info
;
1412 struct elf64_hppa_dyn_reloc_entry
*rent
;
1413 bfd_boolean dynamic_symbol
, shared
;
1415 hppa_info
= hppa_link_hash_table (x
->info
);
1416 dynamic_symbol
= elf64_hppa_dynamic_symbol_p (eh
, x
->info
);
1417 shared
= x
->info
->shared
;
1419 /* We may need to allocate relocations for a non-dynamic symbol
1420 when creating a shared library. */
1421 if (!dynamic_symbol
&& !shared
)
1424 /* Take care of the normal data relocations. */
1426 for (rent
= hh
->reloc_entries
; rent
; rent
= rent
->next
)
1428 /* Allocate one iff we are building a shared library, the relocation
1429 isn't a R_PARISC_FPTR64, or we don't want an opd entry. */
1430 if (!shared
&& rent
->type
== R_PARISC_FPTR64
&& hh
->want_opd
)
1433 hppa_info
->other_rel_sec
->size
+= sizeof (Elf64_External_Rela
);
1435 /* Make sure this symbol gets into the dynamic symbol table if it is
1436 not already recorded. ?!? This should not be in the loop since
1437 the symbol need only be added once. */
1438 if (eh
->dynindx
== -1 && eh
->type
!= STT_PARISC_MILLI
)
1439 if (!bfd_elf_link_record_local_dynamic_symbol
1440 (x
->info
, rent
->sec
->owner
, hh
->sym_indx
))
1444 /* Take care of the GOT and PLT relocations. */
1446 if ((dynamic_symbol
|| shared
) && hh
->want_dlt
)
1447 hppa_info
->dlt_rel_sec
->size
+= sizeof (Elf64_External_Rela
);
1449 /* If we are building a shared library, then every symbol that has an
1450 opd entry will need an EPLT relocation to relocate the symbol's address
1451 and __gp value based on the runtime load address. */
1452 if (shared
&& hh
->want_opd
)
1453 hppa_info
->opd_rel_sec
->size
+= sizeof (Elf64_External_Rela
);
1455 if (hh
->want_plt
&& dynamic_symbol
)
1457 bfd_size_type t
= 0;
1459 /* Dynamic symbols get one IPLT relocation. Local symbols in
1460 shared libraries get two REL relocations. Local symbols in
1461 main applications get nothing. */
1463 t
= sizeof (Elf64_External_Rela
);
1465 t
= 2 * sizeof (Elf64_External_Rela
);
1467 hppa_info
->plt_rel_sec
->size
+= t
;
1473 /* Adjust a symbol defined by a dynamic object and referenced by a
1477 elf64_hppa_adjust_dynamic_symbol (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1478 struct elf_link_hash_entry
*eh
)
1480 /* ??? Undefined symbols with PLT entries should be re-defined
1481 to be the PLT entry. */
1483 /* If this is a weak symbol, and there is a real definition, the
1484 processor independent code will have arranged for us to see the
1485 real definition first, and we can just use the same value. */
1486 if (eh
->u
.weakdef
!= NULL
)
1488 BFD_ASSERT (eh
->u
.weakdef
->root
.type
== bfd_link_hash_defined
1489 || eh
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
1490 eh
->root
.u
.def
.section
= eh
->u
.weakdef
->root
.u
.def
.section
;
1491 eh
->root
.u
.def
.value
= eh
->u
.weakdef
->root
.u
.def
.value
;
1495 /* If this is a reference to a symbol defined by a dynamic object which
1496 is not a function, we might allocate the symbol in our .dynbss section
1497 and allocate a COPY dynamic relocation.
1499 But PA64 code is canonically PIC, so as a rule we can avoid this sort
1505 /* This function is called via elf_link_hash_traverse to mark millicode
1506 symbols with a dynindx of -1 and to remove the string table reference
1507 from the dynamic symbol table. If the symbol is not a millicode symbol,
1508 elf64_hppa_mark_exported_functions is called. */
1511 elf64_hppa_mark_milli_and_exported_functions (struct elf_link_hash_entry
*eh
,
1514 struct elf_link_hash_entry
*elf
= eh
;
1515 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
1517 if (elf
->root
.type
== bfd_link_hash_warning
)
1518 elf
= (struct elf_link_hash_entry
*) elf
->root
.u
.i
.link
;
1520 if (elf
->type
== STT_PARISC_MILLI
)
1522 if (elf
->dynindx
!= -1)
1525 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
1531 return elf64_hppa_mark_exported_functions (eh
, data
);
1534 /* Set the final sizes of the dynamic sections and allocate memory for
1535 the contents of our special sections. */
1538 elf64_hppa_size_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
1540 struct elf64_hppa_link_hash_table
*hppa_info
;
1541 struct elf64_hppa_allocate_data data
;
1547 bfd_boolean reltext
;
1549 hppa_info
= hppa_link_hash_table (info
);
1551 dynobj
= elf_hash_table (info
)->dynobj
;
1552 BFD_ASSERT (dynobj
!= NULL
);
1554 /* Mark each function this program exports so that we will allocate
1555 space in the .opd section for each function's FPTR. If we are
1556 creating dynamic sections, change the dynamic index of millicode
1557 symbols to -1 and remove them from the string table for .dynstr.
1559 We have to traverse the main linker hash table since we have to
1560 find functions which may not have been mentioned in any relocs. */
1561 elf_link_hash_traverse (elf_hash_table (info
),
1562 (elf_hash_table (info
)->dynamic_sections_created
1563 ? elf64_hppa_mark_milli_and_exported_functions
1564 : elf64_hppa_mark_exported_functions
),
1567 if (elf_hash_table (info
)->dynamic_sections_created
)
1569 /* Set the contents of the .interp section to the interpreter. */
1570 if (info
->executable
)
1572 sec
= bfd_get_section_by_name (dynobj
, ".interp");
1573 BFD_ASSERT (sec
!= NULL
);
1574 sec
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1575 sec
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1580 /* We may have created entries in the .rela.got section.
1581 However, if we are not creating the dynamic sections, we will
1582 not actually use these entries. Reset the size of .rela.dlt,
1583 which will cause it to get stripped from the output file
1585 sec
= bfd_get_section_by_name (dynobj
, ".rela.dlt");
1590 /* Set up DLT, PLT and OPD offsets for local syms, and space for local
1592 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
1594 bfd_signed_vma
*local_dlt
;
1595 bfd_signed_vma
*end_local_dlt
;
1596 bfd_signed_vma
*local_plt
;
1597 bfd_signed_vma
*end_local_plt
;
1598 bfd_signed_vma
*local_opd
;
1599 bfd_signed_vma
*end_local_opd
;
1600 bfd_size_type locsymcount
;
1601 Elf_Internal_Shdr
*symtab_hdr
;
1604 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
1607 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1609 struct elf64_hppa_dyn_reloc_entry
*hdh_p
;
1611 for (hdh_p
= ((struct elf64_hppa_dyn_reloc_entry
*)
1612 elf_section_data (sec
)->local_dynrel
);
1614 hdh_p
= hdh_p
->next
)
1616 if (!bfd_is_abs_section (hdh_p
->sec
)
1617 && bfd_is_abs_section (hdh_p
->sec
->output_section
))
1619 /* Input section has been discarded, either because
1620 it is a copy of a linkonce section or due to
1621 linker script /DISCARD/, so we'll be discarding
1624 else if (hdh_p
->count
!= 0)
1626 srel
= elf_section_data (hdh_p
->sec
)->sreloc
;
1627 srel
->size
+= hdh_p
->count
* sizeof (Elf64_External_Rela
);
1628 if ((hdh_p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
1629 info
->flags
|= DF_TEXTREL
;
1634 local_dlt
= elf_local_got_refcounts (ibfd
);
1638 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
1639 locsymcount
= symtab_hdr
->sh_info
;
1640 end_local_dlt
= local_dlt
+ locsymcount
;
1641 sec
= hppa_info
->dlt_sec
;
1642 srel
= hppa_info
->dlt_rel_sec
;
1643 for (; local_dlt
< end_local_dlt
; ++local_dlt
)
1647 *local_dlt
= sec
->size
;
1648 sec
->size
+= DLT_ENTRY_SIZE
;
1651 srel
->size
+= sizeof (Elf64_External_Rela
);
1655 *local_dlt
= (bfd_vma
) -1;
1658 local_plt
= end_local_dlt
;
1659 end_local_plt
= local_plt
+ locsymcount
;
1660 if (! hppa_info
->root
.dynamic_sections_created
)
1662 /* Won't be used, but be safe. */
1663 for (; local_plt
< end_local_plt
; ++local_plt
)
1664 *local_plt
= (bfd_vma
) -1;
1668 sec
= hppa_info
->plt_sec
;
1669 srel
= hppa_info
->plt_rel_sec
;
1670 for (; local_plt
< end_local_plt
; ++local_plt
)
1674 *local_plt
= sec
->size
;
1675 sec
->size
+= PLT_ENTRY_SIZE
;
1677 srel
->size
+= sizeof (Elf64_External_Rela
);
1680 *local_plt
= (bfd_vma
) -1;
1684 local_opd
= end_local_plt
;
1685 end_local_opd
= local_opd
+ locsymcount
;
1686 if (! hppa_info
->root
.dynamic_sections_created
)
1688 /* Won't be used, but be safe. */
1689 for (; local_opd
< end_local_opd
; ++local_opd
)
1690 *local_opd
= (bfd_vma
) -1;
1694 sec
= hppa_info
->opd_sec
;
1695 srel
= hppa_info
->opd_rel_sec
;
1696 for (; local_opd
< end_local_opd
; ++local_opd
)
1700 *local_opd
= sec
->size
;
1701 sec
->size
+= OPD_ENTRY_SIZE
;
1703 srel
->size
+= sizeof (Elf64_External_Rela
);
1706 *local_opd
= (bfd_vma
) -1;
1711 /* Allocate the GOT entries. */
1714 if (hppa_info
->dlt_sec
)
1716 data
.ofs
= hppa_info
->dlt_sec
->size
;
1717 elf_link_hash_traverse (elf_hash_table (info
),
1718 allocate_global_data_dlt
, &data
);
1719 hppa_info
->dlt_sec
->size
= data
.ofs
;
1722 if (hppa_info
->plt_sec
)
1724 data
.ofs
= hppa_info
->plt_sec
->size
;
1725 elf_link_hash_traverse (elf_hash_table (info
),
1726 allocate_global_data_plt
, &data
);
1727 hppa_info
->plt_sec
->size
= data
.ofs
;
1730 if (hppa_info
->stub_sec
)
1733 elf_link_hash_traverse (elf_hash_table (info
),
1734 allocate_global_data_stub
, &data
);
1735 hppa_info
->stub_sec
->size
= data
.ofs
;
1738 /* Allocate space for entries in the .opd section. */
1739 if (hppa_info
->opd_sec
)
1741 data
.ofs
= hppa_info
->opd_sec
->size
;
1742 elf_link_hash_traverse (elf_hash_table (info
),
1743 allocate_global_data_opd
, &data
);
1744 hppa_info
->opd_sec
->size
= data
.ofs
;
1747 /* Now allocate space for dynamic relocations, if necessary. */
1748 if (hppa_info
->root
.dynamic_sections_created
)
1749 elf_link_hash_traverse (elf_hash_table (info
),
1750 allocate_dynrel_entries
, &data
);
1752 /* The sizes of all the sections are set. Allocate memory for them. */
1756 for (sec
= dynobj
->sections
; sec
!= NULL
; sec
= sec
->next
)
1760 if ((sec
->flags
& SEC_LINKER_CREATED
) == 0)
1763 /* It's OK to base decisions on the section name, because none
1764 of the dynobj section names depend upon the input files. */
1765 name
= bfd_get_section_name (dynobj
, sec
);
1767 if (strcmp (name
, ".plt") == 0)
1769 /* Remember whether there is a PLT. */
1770 plt
= sec
->size
!= 0;
1772 else if (strcmp (name
, ".opd") == 0
1773 || CONST_STRNEQ (name
, ".dlt")
1774 || strcmp (name
, ".stub") == 0
1775 || strcmp (name
, ".got") == 0)
1777 /* Strip this section if we don't need it; see the comment below. */
1779 else if (CONST_STRNEQ (name
, ".rela"))
1785 /* Remember whether there are any reloc sections other
1787 if (strcmp (name
, ".rela.plt") != 0)
1789 const char *outname
;
1793 /* If this relocation section applies to a read only
1794 section, then we probably need a DT_TEXTREL
1795 entry. The entries in the .rela.plt section
1796 really apply to the .got section, which we
1797 created ourselves and so know is not readonly. */
1798 outname
= bfd_get_section_name (output_bfd
,
1799 sec
->output_section
);
1800 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
1802 && (target
->flags
& SEC_READONLY
) != 0
1803 && (target
->flags
& SEC_ALLOC
) != 0)
1807 /* We use the reloc_count field as a counter if we need
1808 to copy relocs into the output file. */
1809 sec
->reloc_count
= 0;
1814 /* It's not one of our sections, so don't allocate space. */
1820 /* If we don't need this section, strip it from the
1821 output file. This is mostly to handle .rela.bss and
1822 .rela.plt. We must create both sections in
1823 create_dynamic_sections, because they must be created
1824 before the linker maps input sections to output
1825 sections. The linker does that before
1826 adjust_dynamic_symbol is called, and it is that
1827 function which decides whether anything needs to go
1828 into these sections. */
1829 sec
->flags
|= SEC_EXCLUDE
;
1833 if ((sec
->flags
& SEC_HAS_CONTENTS
) == 0)
1836 /* Allocate memory for the section contents if it has not
1837 been allocated already. We use bfd_zalloc here in case
1838 unused entries are not reclaimed before the section's
1839 contents are written out. This should not happen, but this
1840 way if it does, we get a R_PARISC_NONE reloc instead of
1842 if (sec
->contents
== NULL
)
1844 sec
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, sec
->size
);
1845 if (sec
->contents
== NULL
)
1850 if (elf_hash_table (info
)->dynamic_sections_created
)
1852 /* Always create a DT_PLTGOT. It actually has nothing to do with
1853 the PLT, it is how we communicate the __gp value of a load
1854 module to the dynamic linker. */
1855 #define add_dynamic_entry(TAG, VAL) \
1856 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
1858 if (!add_dynamic_entry (DT_HP_DLD_FLAGS
, 0)
1859 || !add_dynamic_entry (DT_PLTGOT
, 0))
1862 /* Add some entries to the .dynamic section. We fill in the
1863 values later, in elf64_hppa_finish_dynamic_sections, but we
1864 must add the entries now so that we get the correct size for
1865 the .dynamic section. The DT_DEBUG entry is filled in by the
1866 dynamic linker and used by the debugger. */
1869 if (!add_dynamic_entry (DT_DEBUG
, 0)
1870 || !add_dynamic_entry (DT_HP_DLD_HOOK
, 0)
1871 || !add_dynamic_entry (DT_HP_LOAD_MAP
, 0))
1875 /* Force DT_FLAGS to always be set.
1876 Required by HPUX 11.00 patch PHSS_26559. */
1877 if (!add_dynamic_entry (DT_FLAGS
, (info
)->flags
))
1882 if (!add_dynamic_entry (DT_PLTRELSZ
, 0)
1883 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
1884 || !add_dynamic_entry (DT_JMPREL
, 0))
1890 if (!add_dynamic_entry (DT_RELA
, 0)
1891 || !add_dynamic_entry (DT_RELASZ
, 0)
1892 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
1898 if (!add_dynamic_entry (DT_TEXTREL
, 0))
1900 info
->flags
|= DF_TEXTREL
;
1903 #undef add_dynamic_entry
1908 /* Called after we have output the symbol into the dynamic symbol
1909 table, but before we output the symbol into the normal symbol
1912 For some symbols we had to change their address when outputting
1913 the dynamic symbol table. We undo that change here so that
1914 the symbols have their expected value in the normal symbol
1918 elf64_hppa_link_output_symbol_hook (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1920 Elf_Internal_Sym
*sym
,
1921 asection
*input_sec ATTRIBUTE_UNUSED
,
1922 struct elf_link_hash_entry
*eh
)
1924 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
1926 /* We may be called with the file symbol or section symbols.
1927 They never need munging, so it is safe to ignore them. */
1931 /* Function symbols for which we created .opd entries *may* have been
1932 munged by finish_dynamic_symbol and have to be un-munged here.
1934 Note that finish_dynamic_symbol sometimes turns dynamic symbols
1935 into non-dynamic ones, so we initialize st_shndx to -1 in
1936 mark_exported_functions and check to see if it was overwritten
1937 here instead of just checking eh->dynindx. */
1938 if (hh
->want_opd
&& hh
->st_shndx
!= -1)
1940 /* Restore the saved value and section index. */
1941 sym
->st_value
= hh
->st_value
;
1942 sym
->st_shndx
= hh
->st_shndx
;
1948 /* Finish up dynamic symbol handling. We set the contents of various
1949 dynamic sections here. */
1952 elf64_hppa_finish_dynamic_symbol (bfd
*output_bfd
,
1953 struct bfd_link_info
*info
,
1954 struct elf_link_hash_entry
*eh
,
1955 Elf_Internal_Sym
*sym
)
1957 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
1958 asection
*stub
, *splt
, *sdlt
, *sopd
, *spltrel
, *sdltrel
;
1959 struct elf64_hppa_link_hash_table
*hppa_info
;
1961 hppa_info
= hppa_link_hash_table (info
);
1963 stub
= hppa_info
->stub_sec
;
1964 splt
= hppa_info
->plt_sec
;
1965 sdlt
= hppa_info
->dlt_sec
;
1966 sopd
= hppa_info
->opd_sec
;
1967 spltrel
= hppa_info
->plt_rel_sec
;
1968 sdltrel
= hppa_info
->dlt_rel_sec
;
1970 /* Incredible. It is actually necessary to NOT use the symbol's real
1971 value when building the dynamic symbol table for a shared library.
1972 At least for symbols that refer to functions.
1974 We will store a new value and section index into the symbol long
1975 enough to output it into the dynamic symbol table, then we restore
1976 the original values (in elf64_hppa_link_output_symbol_hook). */
1979 BFD_ASSERT (sopd
!= NULL
);
1981 /* Save away the original value and section index so that we
1982 can restore them later. */
1983 hh
->st_value
= sym
->st_value
;
1984 hh
->st_shndx
= sym
->st_shndx
;
1986 /* For the dynamic symbol table entry, we want the value to be
1987 address of this symbol's entry within the .opd section. */
1988 sym
->st_value
= (hh
->opd_offset
1989 + sopd
->output_offset
1990 + sopd
->output_section
->vma
);
1991 sym
->st_shndx
= _bfd_elf_section_from_bfd_section (output_bfd
,
1992 sopd
->output_section
);
1995 /* Initialize a .plt entry if requested. */
1997 && elf64_hppa_dynamic_symbol_p (eh
, info
))
2000 Elf_Internal_Rela rel
;
2003 BFD_ASSERT (splt
!= NULL
&& spltrel
!= NULL
);
2005 /* We do not actually care about the value in the PLT entry
2006 if we are creating a shared library and the symbol is
2007 still undefined, we create a dynamic relocation to fill
2008 in the correct value. */
2009 if (info
->shared
&& eh
->root
.type
== bfd_link_hash_undefined
)
2012 value
= (eh
->root
.u
.def
.value
+ eh
->root
.u
.def
.section
->vma
);
2014 /* Fill in the entry in the procedure linkage table.
2016 The format of a plt entry is
2019 plt_offset is the offset within the PLT section at which to
2020 install the PLT entry.
2022 We are modifying the in-memory PLT contents here, so we do not add
2023 in the output_offset of the PLT section. */
2025 bfd_put_64 (splt
->owner
, value
, splt
->contents
+ hh
->plt_offset
);
2026 value
= _bfd_get_gp_value (splt
->output_section
->owner
);
2027 bfd_put_64 (splt
->owner
, value
, splt
->contents
+ hh
->plt_offset
+ 0x8);
2029 /* Create a dynamic IPLT relocation for this entry.
2031 We are creating a relocation in the output file's PLT section,
2032 which is included within the DLT secton. So we do need to include
2033 the PLT's output_offset in the computation of the relocation's
2035 rel
.r_offset
= (hh
->plt_offset
+ splt
->output_offset
2036 + splt
->output_section
->vma
);
2037 rel
.r_info
= ELF64_R_INFO (hh
->eh
.dynindx
, R_PARISC_IPLT
);
2040 loc
= spltrel
->contents
;
2041 loc
+= spltrel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2042 bfd_elf64_swap_reloca_out (splt
->output_section
->owner
, &rel
, loc
);
2045 /* Initialize an external call stub entry if requested. */
2047 && elf64_hppa_dynamic_symbol_p (eh
, info
))
2051 unsigned int max_offset
;
2053 BFD_ASSERT (stub
!= NULL
);
2055 /* Install the generic stub template.
2057 We are modifying the contents of the stub section, so we do not
2058 need to include the stub section's output_offset here. */
2059 memcpy (stub
->contents
+ hh
->stub_offset
, plt_stub
, sizeof (plt_stub
));
2061 /* Fix up the first ldd instruction.
2063 We are modifying the contents of the STUB section in memory,
2064 so we do not need to include its output offset in this computation.
2066 Note the plt_offset value is the value of the PLT entry relative to
2067 the start of the PLT section. These instructions will reference
2068 data relative to the value of __gp, which may not necessarily have
2069 the same address as the start of the PLT section.
2071 gp_offset contains the offset of __gp within the PLT section. */
2072 value
= hh
->plt_offset
- hppa_info
->gp_offset
;
2074 insn
= bfd_get_32 (stub
->owner
, stub
->contents
+ hh
->stub_offset
);
2075 if (output_bfd
->arch_info
->mach
>= 25)
2077 /* Wide mode allows 16 bit offsets. */
2080 insn
|= re_assemble_16 ((int) value
);
2086 insn
|= re_assemble_14 ((int) value
);
2089 if ((value
& 7) || value
+ max_offset
>= 2*max_offset
- 8)
2091 (*_bfd_error_handler
) (_("stub entry for %s cannot load .plt, dp offset = %ld"),
2092 hh
->eh
.root
.root
.string
,
2097 bfd_put_32 (stub
->owner
, (bfd_vma
) insn
,
2098 stub
->contents
+ hh
->stub_offset
);
2100 /* Fix up the second ldd instruction. */
2102 insn
= bfd_get_32 (stub
->owner
, stub
->contents
+ hh
->stub_offset
+ 8);
2103 if (output_bfd
->arch_info
->mach
>= 25)
2106 insn
|= re_assemble_16 ((int) value
);
2111 insn
|= re_assemble_14 ((int) value
);
2113 bfd_put_32 (stub
->owner
, (bfd_vma
) insn
,
2114 stub
->contents
+ hh
->stub_offset
+ 8);
2120 /* The .opd section contains FPTRs for each function this file
2121 exports. Initialize the FPTR entries. */
2124 elf64_hppa_finalize_opd (struct elf_link_hash_entry
*eh
, void *data
)
2126 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
2127 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
2128 struct elf64_hppa_link_hash_table
*hppa_info
;
2132 hppa_info
= hppa_link_hash_table (info
);
2133 sopd
= hppa_info
->opd_sec
;
2134 sopdrel
= hppa_info
->opd_rel_sec
;
2140 /* The first two words of an .opd entry are zero.
2142 We are modifying the contents of the OPD section in memory, so we
2143 do not need to include its output offset in this computation. */
2144 memset (sopd
->contents
+ hh
->opd_offset
, 0, 16);
2146 value
= (eh
->root
.u
.def
.value
2147 + eh
->root
.u
.def
.section
->output_section
->vma
2148 + eh
->root
.u
.def
.section
->output_offset
);
2150 /* The next word is the address of the function. */
2151 bfd_put_64 (sopd
->owner
, value
, sopd
->contents
+ hh
->opd_offset
+ 16);
2153 /* The last word is our local __gp value. */
2154 value
= _bfd_get_gp_value (sopd
->output_section
->owner
);
2155 bfd_put_64 (sopd
->owner
, value
, sopd
->contents
+ hh
->opd_offset
+ 24);
2158 /* If we are generating a shared library, we must generate EPLT relocations
2159 for each entry in the .opd, even for static functions (they may have
2160 had their address taken). */
2161 if (info
->shared
&& hh
->want_opd
)
2163 Elf_Internal_Rela rel
;
2167 /* We may need to do a relocation against a local symbol, in
2168 which case we have to look up it's dynamic symbol index off
2169 the local symbol hash table. */
2170 if (eh
->dynindx
!= -1)
2171 dynindx
= eh
->dynindx
;
2174 = _bfd_elf_link_lookup_local_dynindx (info
, hh
->owner
,
2177 /* The offset of this relocation is the absolute address of the
2178 .opd entry for this symbol. */
2179 rel
.r_offset
= (hh
->opd_offset
+ sopd
->output_offset
2180 + sopd
->output_section
->vma
);
2182 /* If H is non-null, then we have an external symbol.
2184 It is imperative that we use a different dynamic symbol for the
2185 EPLT relocation if the symbol has global scope.
2187 In the dynamic symbol table, the function symbol will have a value
2188 which is address of the function's .opd entry.
2190 Thus, we can not use that dynamic symbol for the EPLT relocation
2191 (if we did, the data in the .opd would reference itself rather
2192 than the actual address of the function). Instead we have to use
2193 a new dynamic symbol which has the same value as the original global
2196 We prefix the original symbol with a "." and use the new symbol in
2197 the EPLT relocation. This new symbol has already been recorded in
2198 the symbol table, we just have to look it up and use it.
2200 We do not have such problems with static functions because we do
2201 not make their addresses in the dynamic symbol table point to
2202 the .opd entry. Ultimately this should be safe since a static
2203 function can not be directly referenced outside of its shared
2206 We do have to play similar games for FPTR relocations in shared
2207 libraries, including those for static symbols. See the FPTR
2208 handling in elf64_hppa_finalize_dynreloc. */
2212 struct elf_link_hash_entry
*nh
;
2214 new_name
= alloca (strlen (eh
->root
.root
.string
) + 2);
2216 strcpy (new_name
+ 1, eh
->root
.root
.string
);
2218 nh
= elf_link_hash_lookup (elf_hash_table (info
),
2219 new_name
, TRUE
, TRUE
, FALSE
);
2221 /* All we really want from the new symbol is its dynamic
2224 dynindx
= nh
->dynindx
;
2228 rel
.r_info
= ELF64_R_INFO (dynindx
, R_PARISC_EPLT
);
2230 loc
= sopdrel
->contents
;
2231 loc
+= sopdrel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2232 bfd_elf64_swap_reloca_out (sopd
->output_section
->owner
, &rel
, loc
);
2237 /* The .dlt section contains addresses for items referenced through the
2238 dlt. Note that we can have a DLTIND relocation for a local symbol, thus
2239 we can not depend on finish_dynamic_symbol to initialize the .dlt. */
2242 elf64_hppa_finalize_dlt (struct elf_link_hash_entry
*eh
, void *data
)
2244 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
2245 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
2246 struct elf64_hppa_link_hash_table
*hppa_info
;
2247 asection
*sdlt
, *sdltrel
;
2249 hppa_info
= hppa_link_hash_table (info
);
2251 sdlt
= hppa_info
->dlt_sec
;
2252 sdltrel
= hppa_info
->dlt_rel_sec
;
2254 /* H/DYN_H may refer to a local variable and we know it's
2255 address, so there is no need to create a relocation. Just install
2256 the proper value into the DLT, note this shortcut can not be
2257 skipped when building a shared library. */
2258 if (! info
->shared
&& hh
&& hh
->want_dlt
)
2262 /* If we had an LTOFF_FPTR style relocation we want the DLT entry
2263 to point to the FPTR entry in the .opd section.
2265 We include the OPD's output offset in this computation as
2266 we are referring to an absolute address in the resulting
2270 value
= (hh
->opd_offset
2271 + hppa_info
->opd_sec
->output_offset
2272 + hppa_info
->opd_sec
->output_section
->vma
);
2274 else if ((eh
->root
.type
== bfd_link_hash_defined
2275 || eh
->root
.type
== bfd_link_hash_defweak
)
2276 && eh
->root
.u
.def
.section
)
2278 value
= eh
->root
.u
.def
.value
+ eh
->root
.u
.def
.section
->output_offset
;
2279 if (eh
->root
.u
.def
.section
->output_section
)
2280 value
+= eh
->root
.u
.def
.section
->output_section
->vma
;
2282 value
+= eh
->root
.u
.def
.section
->vma
;
2285 /* We have an undefined function reference. */
2288 /* We do not need to include the output offset of the DLT section
2289 here because we are modifying the in-memory contents. */
2290 bfd_put_64 (sdlt
->owner
, value
, sdlt
->contents
+ hh
->dlt_offset
);
2293 /* Create a relocation for the DLT entry associated with this symbol.
2294 When building a shared library the symbol does not have to be dynamic. */
2296 && (elf64_hppa_dynamic_symbol_p (eh
, info
) || info
->shared
))
2298 Elf_Internal_Rela rel
;
2302 /* We may need to do a relocation against a local symbol, in
2303 which case we have to look up it's dynamic symbol index off
2304 the local symbol hash table. */
2305 if (eh
&& eh
->dynindx
!= -1)
2306 dynindx
= eh
->dynindx
;
2309 = _bfd_elf_link_lookup_local_dynindx (info
, hh
->owner
,
2312 /* Create a dynamic relocation for this entry. Do include the output
2313 offset of the DLT entry since we need an absolute address in the
2314 resulting object file. */
2315 rel
.r_offset
= (hh
->dlt_offset
+ sdlt
->output_offset
2316 + sdlt
->output_section
->vma
);
2317 if (eh
&& eh
->type
== STT_FUNC
)
2318 rel
.r_info
= ELF64_R_INFO (dynindx
, R_PARISC_FPTR64
);
2320 rel
.r_info
= ELF64_R_INFO (dynindx
, R_PARISC_DIR64
);
2323 loc
= sdltrel
->contents
;
2324 loc
+= sdltrel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2325 bfd_elf64_swap_reloca_out (sdlt
->output_section
->owner
, &rel
, loc
);
2330 /* Finalize the dynamic relocations. Specifically the FPTR relocations
2331 for dynamic functions used to initialize static data. */
2334 elf64_hppa_finalize_dynreloc (struct elf_link_hash_entry
*eh
,
2337 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
2338 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
2339 struct elf64_hppa_link_hash_table
*hppa_info
;
2342 dynamic_symbol
= elf64_hppa_dynamic_symbol_p (eh
, info
);
2344 if (!dynamic_symbol
&& !info
->shared
)
2347 if (hh
->reloc_entries
)
2349 struct elf64_hppa_dyn_reloc_entry
*rent
;
2352 hppa_info
= hppa_link_hash_table (info
);
2354 /* We may need to do a relocation against a local symbol, in
2355 which case we have to look up it's dynamic symbol index off
2356 the local symbol hash table. */
2357 if (eh
->dynindx
!= -1)
2358 dynindx
= eh
->dynindx
;
2361 = _bfd_elf_link_lookup_local_dynindx (info
, hh
->owner
,
2364 for (rent
= hh
->reloc_entries
; rent
; rent
= rent
->next
)
2366 Elf_Internal_Rela rel
;
2369 /* Allocate one iff we are building a shared library, the relocation
2370 isn't a R_PARISC_FPTR64, or we don't want an opd entry. */
2371 if (!info
->shared
&& rent
->type
== R_PARISC_FPTR64
&& hh
->want_opd
)
2374 /* Create a dynamic relocation for this entry.
2376 We need the output offset for the reloc's section because
2377 we are creating an absolute address in the resulting object
2379 rel
.r_offset
= (rent
->offset
+ rent
->sec
->output_offset
2380 + rent
->sec
->output_section
->vma
);
2382 /* An FPTR64 relocation implies that we took the address of
2383 a function and that the function has an entry in the .opd
2384 section. We want the FPTR64 relocation to reference the
2387 We could munge the symbol value in the dynamic symbol table
2388 (in fact we already do for functions with global scope) to point
2389 to the .opd entry. Then we could use that dynamic symbol in
2392 Or we could do something sensible, not munge the symbol's
2393 address and instead just use a different symbol to reference
2394 the .opd entry. At least that seems sensible until you
2395 realize there's no local dynamic symbols we can use for that
2396 purpose. Thus the hair in the check_relocs routine.
2398 We use a section symbol recorded by check_relocs as the
2399 base symbol for the relocation. The addend is the difference
2400 between the section symbol and the address of the .opd entry. */
2401 if (info
->shared
&& rent
->type
== R_PARISC_FPTR64
&& hh
->want_opd
)
2403 bfd_vma value
, value2
;
2405 /* First compute the address of the opd entry for this symbol. */
2406 value
= (hh
->opd_offset
2407 + hppa_info
->opd_sec
->output_section
->vma
2408 + hppa_info
->opd_sec
->output_offset
);
2410 /* Compute the value of the start of the section with
2412 value2
= (rent
->sec
->output_section
->vma
2413 + rent
->sec
->output_offset
);
2415 /* Compute the difference between the start of the section
2416 with the relocation and the opd entry. */
2419 /* The result becomes the addend of the relocation. */
2420 rel
.r_addend
= value
;
2422 /* The section symbol becomes the symbol for the dynamic
2425 = _bfd_elf_link_lookup_local_dynindx (info
,
2430 rel
.r_addend
= rent
->addend
;
2432 rel
.r_info
= ELF64_R_INFO (dynindx
, rent
->type
);
2434 loc
= hppa_info
->other_rel_sec
->contents
;
2435 loc
+= (hppa_info
->other_rel_sec
->reloc_count
++
2436 * sizeof (Elf64_External_Rela
));
2437 bfd_elf64_swap_reloca_out (hppa_info
->other_rel_sec
->output_section
->owner
,
2445 /* Used to decide how to sort relocs in an optimal manner for the
2446 dynamic linker, before writing them out. */
2448 static enum elf_reloc_type_class
2449 elf64_hppa_reloc_type_class (const Elf_Internal_Rela
*rela
)
2451 if (ELF64_R_SYM (rela
->r_info
) == 0)
2452 return reloc_class_relative
;
2454 switch ((int) ELF64_R_TYPE (rela
->r_info
))
2457 return reloc_class_plt
;
2459 return reloc_class_copy
;
2461 return reloc_class_normal
;
2465 /* Finish up the dynamic sections. */
2468 elf64_hppa_finish_dynamic_sections (bfd
*output_bfd
,
2469 struct bfd_link_info
*info
)
2473 struct elf64_hppa_link_hash_table
*hppa_info
;
2475 hppa_info
= hppa_link_hash_table (info
);
2477 /* Finalize the contents of the .opd section. */
2478 elf_link_hash_traverse (elf_hash_table (info
),
2479 elf64_hppa_finalize_opd
,
2482 elf_link_hash_traverse (elf_hash_table (info
),
2483 elf64_hppa_finalize_dynreloc
,
2486 /* Finalize the contents of the .dlt section. */
2487 dynobj
= elf_hash_table (info
)->dynobj
;
2488 /* Finalize the contents of the .dlt section. */
2489 elf_link_hash_traverse (elf_hash_table (info
),
2490 elf64_hppa_finalize_dlt
,
2493 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2495 if (elf_hash_table (info
)->dynamic_sections_created
)
2497 Elf64_External_Dyn
*dyncon
, *dynconend
;
2499 BFD_ASSERT (sdyn
!= NULL
);
2501 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
2502 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
2503 for (; dyncon
< dynconend
; dyncon
++)
2505 Elf_Internal_Dyn dyn
;
2508 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2515 case DT_HP_LOAD_MAP
:
2516 /* Compute the absolute address of 16byte scratchpad area
2517 for the dynamic linker.
2519 By convention the linker script will allocate the scratchpad
2520 area at the start of the .data section. So all we have to
2521 to is find the start of the .data section. */
2522 s
= bfd_get_section_by_name (output_bfd
, ".data");
2523 dyn
.d_un
.d_ptr
= s
->vma
;
2524 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2528 /* HP's use PLTGOT to set the GOT register. */
2529 dyn
.d_un
.d_ptr
= _bfd_get_gp_value (output_bfd
);
2530 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2534 s
= hppa_info
->plt_rel_sec
;
2535 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
2536 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2540 s
= hppa_info
->plt_rel_sec
;
2541 dyn
.d_un
.d_val
= s
->size
;
2542 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2546 s
= hppa_info
->other_rel_sec
;
2547 if (! s
|| ! s
->size
)
2548 s
= hppa_info
->dlt_rel_sec
;
2549 if (! s
|| ! s
->size
)
2550 s
= hppa_info
->opd_rel_sec
;
2551 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
2552 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2556 s
= hppa_info
->other_rel_sec
;
2557 dyn
.d_un
.d_val
= s
->size
;
2558 s
= hppa_info
->dlt_rel_sec
;
2559 dyn
.d_un
.d_val
+= s
->size
;
2560 s
= hppa_info
->opd_rel_sec
;
2561 dyn
.d_un
.d_val
+= s
->size
;
2562 /* There is some question about whether or not the size of
2563 the PLT relocs should be included here. HP's tools do
2564 it, so we'll emulate them. */
2565 s
= hppa_info
->plt_rel_sec
;
2566 dyn
.d_un
.d_val
+= s
->size
;
2567 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2577 /* Support for core dump NOTE sections. */
2580 elf64_hppa_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
2585 switch (note
->descsz
)
2590 case 760: /* Linux/hppa */
2592 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
2595 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
2604 /* Make a ".reg/999" section. */
2605 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
2606 size
, note
->descpos
+ offset
);
2610 elf64_hppa_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
2615 switch (note
->descsz
)
2620 case 136: /* Linux/hppa elf_prpsinfo. */
2621 elf_tdata (abfd
)->core_program
2622 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
2623 elf_tdata (abfd
)->core_command
2624 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
2627 /* Note that for some reason, a spurious space is tacked
2628 onto the end of the args in some (at least one anyway)
2629 implementations, so strip it off if it exists. */
2630 command
= elf_tdata (abfd
)->core_command
;
2631 n
= strlen (command
);
2633 if (0 < n
&& command
[n
- 1] == ' ')
2634 command
[n
- 1] = '\0';
2639 /* Return the number of additional phdrs we will need.
2641 The generic ELF code only creates PT_PHDRs for executables. The HP
2642 dynamic linker requires PT_PHDRs for dynamic libraries too.
2644 This routine indicates that the backend needs one additional program
2645 header for that case.
2647 Note we do not have access to the link info structure here, so we have
2648 to guess whether or not we are building a shared library based on the
2649 existence of a .interp section. */
2652 elf64_hppa_additional_program_headers (bfd
*abfd
,
2653 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2657 /* If we are creating a shared library, then we have to create a
2658 PT_PHDR segment. HP's dynamic linker chokes without it. */
2659 s
= bfd_get_section_by_name (abfd
, ".interp");
2665 /* Allocate and initialize any program headers required by this
2668 The generic ELF code only creates PT_PHDRs for executables. The HP
2669 dynamic linker requires PT_PHDRs for dynamic libraries too.
2671 This allocates the PT_PHDR and initializes it in a manner suitable
2674 Note we do not have access to the link info structure here, so we have
2675 to guess whether or not we are building a shared library based on the
2676 existence of a .interp section. */
2679 elf64_hppa_modify_segment_map (bfd
*abfd
,
2680 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2682 struct elf_segment_map
*m
;
2685 s
= bfd_get_section_by_name (abfd
, ".interp");
2688 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2689 if (m
->p_type
== PT_PHDR
)
2693 m
= ((struct elf_segment_map
*)
2694 bfd_zalloc (abfd
, (bfd_size_type
) sizeof *m
));
2698 m
->p_type
= PT_PHDR
;
2699 m
->p_flags
= PF_R
| PF_X
;
2700 m
->p_flags_valid
= 1;
2701 m
->p_paddr_valid
= 1;
2702 m
->includes_phdrs
= 1;
2704 m
->next
= elf_tdata (abfd
)->segment_map
;
2705 elf_tdata (abfd
)->segment_map
= m
;
2709 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2710 if (m
->p_type
== PT_LOAD
)
2714 for (i
= 0; i
< m
->count
; i
++)
2716 /* The code "hint" is not really a hint. It is a requirement
2717 for certain versions of the HP dynamic linker. Worse yet,
2718 it must be set even if the shared library does not have
2719 any code in its "text" segment (thus the check for .hash
2720 to catch this situation). */
2721 if (m
->sections
[i
]->flags
& SEC_CODE
2722 || (strcmp (m
->sections
[i
]->name
, ".hash") == 0))
2723 m
->p_flags
|= (PF_X
| PF_HP_CODE
);
2730 /* Called when writing out an object file to decide the type of a
2733 elf64_hppa_elf_get_symbol_type (Elf_Internal_Sym
*elf_sym
,
2736 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_PARISC_MILLI
)
2737 return STT_PARISC_MILLI
;
2742 /* Support HP specific sections for core files. */
2744 elf64_hppa_section_from_phdr (bfd
*abfd
, Elf_Internal_Phdr
*hdr
, int index
,
2745 const char *typename
)
2747 if (hdr
->p_type
== PT_HP_CORE_KERNEL
)
2751 if (!_bfd_elf_make_section_from_phdr (abfd
, hdr
, index
, typename
))
2754 sect
= bfd_make_section_anyway (abfd
, ".kernel");
2757 sect
->size
= hdr
->p_filesz
;
2758 sect
->filepos
= hdr
->p_offset
;
2759 sect
->flags
= SEC_HAS_CONTENTS
| SEC_READONLY
;
2763 if (hdr
->p_type
== PT_HP_CORE_PROC
)
2767 if (bfd_seek (abfd
, hdr
->p_offset
, SEEK_SET
) != 0)
2769 if (bfd_bread (&sig
, 4, abfd
) != 4)
2772 elf_tdata (abfd
)->core_signal
= sig
;
2774 if (!_bfd_elf_make_section_from_phdr (abfd
, hdr
, index
, typename
))
2777 /* GDB uses the ".reg" section to read register contents. */
2778 return _bfd_elfcore_make_pseudosection (abfd
, ".reg", hdr
->p_filesz
,
2782 if (hdr
->p_type
== PT_HP_CORE_LOADABLE
2783 || hdr
->p_type
== PT_HP_CORE_STACK
2784 || hdr
->p_type
== PT_HP_CORE_MMF
)
2785 hdr
->p_type
= PT_LOAD
;
2787 return _bfd_elf_make_section_from_phdr (abfd
, hdr
, index
, typename
);
2790 /* Hook called by the linker routine which adds symbols from an object
2791 file. HP's libraries define symbols with HP specific section
2792 indices, which we have to handle. */
2795 elf_hppa_add_symbol_hook (bfd
*abfd
,
2796 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2797 Elf_Internal_Sym
*sym
,
2798 const char **namep ATTRIBUTE_UNUSED
,
2799 flagword
*flagsp ATTRIBUTE_UNUSED
,
2803 unsigned int index
= sym
->st_shndx
;
2807 case SHN_PARISC_ANSI_COMMON
:
2808 *secp
= bfd_make_section_old_way (abfd
, ".PARISC.ansi.common");
2809 (*secp
)->flags
|= SEC_IS_COMMON
;
2810 *valp
= sym
->st_size
;
2813 case SHN_PARISC_HUGE_COMMON
:
2814 *secp
= bfd_make_section_old_way (abfd
, ".PARISC.huge.common");
2815 (*secp
)->flags
|= SEC_IS_COMMON
;
2816 *valp
= sym
->st_size
;
2824 elf_hppa_unmark_useless_dynamic_symbols (struct elf_link_hash_entry
*h
,
2827 struct bfd_link_info
*info
= data
;
2829 if (h
->root
.type
== bfd_link_hash_warning
)
2830 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2832 /* If we are not creating a shared library, and this symbol is
2833 referenced by a shared library but is not defined anywhere, then
2834 the generic code will warn that it is undefined.
2836 This behavior is undesirable on HPs since the standard shared
2837 libraries contain references to undefined symbols.
2839 So we twiddle the flags associated with such symbols so that they
2840 will not trigger the warning. ?!? FIXME. This is horribly fragile.
2842 Ultimately we should have better controls over the generic ELF BFD
2844 if (! info
->relocatable
2845 && info
->unresolved_syms_in_shared_libs
!= RM_IGNORE
2846 && h
->root
.type
== bfd_link_hash_undefined
2851 h
->pointer_equality_needed
= 1;
2858 elf_hppa_remark_useless_dynamic_symbols (struct elf_link_hash_entry
*h
,
2861 struct bfd_link_info
*info
= data
;
2863 if (h
->root
.type
== bfd_link_hash_warning
)
2864 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2866 /* If we are not creating a shared library, and this symbol is
2867 referenced by a shared library but is not defined anywhere, then
2868 the generic code will warn that it is undefined.
2870 This behavior is undesirable on HPs since the standard shared
2871 libraries contain references to undefined symbols.
2873 So we twiddle the flags associated with such symbols so that they
2874 will not trigger the warning. ?!? FIXME. This is horribly fragile.
2876 Ultimately we should have better controls over the generic ELF BFD
2878 if (! info
->relocatable
2879 && info
->unresolved_syms_in_shared_libs
!= RM_IGNORE
2880 && h
->root
.type
== bfd_link_hash_undefined
2883 && h
->pointer_equality_needed
)
2886 h
->pointer_equality_needed
= 0;
2893 elf_hppa_is_dynamic_loader_symbol (const char *name
)
2895 return (! strcmp (name
, "__CPU_REVISION")
2896 || ! strcmp (name
, "__CPU_KEYBITS_1")
2897 || ! strcmp (name
, "__SYSTEM_ID_D")
2898 || ! strcmp (name
, "__FPU_MODEL")
2899 || ! strcmp (name
, "__FPU_REVISION")
2900 || ! strcmp (name
, "__ARGC")
2901 || ! strcmp (name
, "__ARGV")
2902 || ! strcmp (name
, "__ENVP")
2903 || ! strcmp (name
, "__TLS_SIZE_D")
2904 || ! strcmp (name
, "__LOAD_INFO")
2905 || ! strcmp (name
, "__systab"));
2908 /* Record the lowest address for the data and text segments. */
2910 elf_hppa_record_segment_addrs (bfd
*abfd
,
2914 struct elf64_hppa_link_hash_table
*hppa_info
= data
;
2916 if ((section
->flags
& (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
2919 Elf_Internal_Phdr
*p
;
2921 p
= _bfd_elf_find_segment_containing_section (abfd
, section
->output_section
);
2922 BFD_ASSERT (p
!= NULL
);
2925 if (section
->flags
& SEC_READONLY
)
2927 if (value
< hppa_info
->text_segment_base
)
2928 hppa_info
->text_segment_base
= value
;
2932 if (value
< hppa_info
->data_segment_base
)
2933 hppa_info
->data_segment_base
= value
;
2938 /* Called after we have seen all the input files/sections, but before
2939 final symbol resolution and section placement has been determined.
2941 We use this hook to (possibly) provide a value for __gp, then we
2942 fall back to the generic ELF final link routine. */
2945 elf_hppa_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
2948 struct elf64_hppa_link_hash_table
*hppa_info
= hppa_link_hash_table (info
);
2950 if (! info
->relocatable
)
2952 struct elf_link_hash_entry
*gp
;
2955 /* The linker script defines a value for __gp iff it was referenced
2956 by one of the objects being linked. First try to find the symbol
2957 in the hash table. If that fails, just compute the value __gp
2959 gp
= elf_link_hash_lookup (elf_hash_table (info
), "__gp", FALSE
,
2965 /* Adjust the value of __gp as we may want to slide it into the
2966 .plt section so that the stubs can access PLT entries without
2967 using an addil sequence. */
2968 gp
->root
.u
.def
.value
+= hppa_info
->gp_offset
;
2970 gp_val
= (gp
->root
.u
.def
.section
->output_section
->vma
2971 + gp
->root
.u
.def
.section
->output_offset
2972 + gp
->root
.u
.def
.value
);
2978 /* First look for a .plt section. If found, then __gp is the
2979 address of the .plt + gp_offset.
2981 If no .plt is found, then look for .dlt, .opd and .data (in
2982 that order) and set __gp to the base address of whichever
2983 section is found first. */
2985 sec
= hppa_info
->plt_sec
;
2986 if (sec
&& ! (sec
->flags
& SEC_EXCLUDE
))
2987 gp_val
= (sec
->output_offset
2988 + sec
->output_section
->vma
2989 + hppa_info
->gp_offset
);
2992 sec
= hppa_info
->dlt_sec
;
2993 if (!sec
|| (sec
->flags
& SEC_EXCLUDE
))
2994 sec
= hppa_info
->opd_sec
;
2995 if (!sec
|| (sec
->flags
& SEC_EXCLUDE
))
2996 sec
= bfd_get_section_by_name (abfd
, ".data");
2997 if (!sec
|| (sec
->flags
& SEC_EXCLUDE
))
3000 gp_val
= sec
->output_offset
+ sec
->output_section
->vma
;
3004 /* Install whatever value we found/computed for __gp. */
3005 _bfd_set_gp_value (abfd
, gp_val
);
3008 /* We need to know the base of the text and data segments so that we
3009 can perform SEGREL relocations. We will record the base addresses
3010 when we encounter the first SEGREL relocation. */
3011 hppa_info
->text_segment_base
= (bfd_vma
)-1;
3012 hppa_info
->data_segment_base
= (bfd_vma
)-1;
3014 /* HP's shared libraries have references to symbols that are not
3015 defined anywhere. The generic ELF BFD linker code will complain
3018 So we detect the losing case and arrange for the flags on the symbol
3019 to indicate that it was never referenced. This keeps the generic
3020 ELF BFD link code happy and appears to not create any secondary
3021 problems. Ultimately we need a way to control the behavior of the
3022 generic ELF BFD link code better. */
3023 elf_link_hash_traverse (elf_hash_table (info
),
3024 elf_hppa_unmark_useless_dynamic_symbols
,
3027 /* Invoke the regular ELF backend linker to do all the work. */
3028 retval
= bfd_elf_final_link (abfd
, info
);
3030 elf_link_hash_traverse (elf_hash_table (info
),
3031 elf_hppa_remark_useless_dynamic_symbols
,
3034 /* If we're producing a final executable, sort the contents of the
3036 if (retval
&& !info
->relocatable
)
3037 retval
= elf_hppa_sort_unwind (abfd
);
3042 /* Relocate the given INSN. VALUE should be the actual value we want
3043 to insert into the instruction, ie by this point we should not be
3044 concerned with computing an offset relative to the DLT, PC, etc.
3045 Instead this routine is meant to handle the bit manipulations needed
3046 to insert the relocation into the given instruction. */
3049 elf_hppa_relocate_insn (int insn
, int sym_value
, unsigned int r_type
)
3053 /* This is any 22 bit branch. In PA2.0 syntax it corresponds to
3054 the "B" instruction. */
3055 case R_PARISC_PCREL22F
:
3056 case R_PARISC_PCREL22C
:
3057 return (insn
& ~0x3ff1ffd) | re_assemble_22 (sym_value
);
3059 /* This is any 12 bit branch. */
3060 case R_PARISC_PCREL12F
:
3061 return (insn
& ~0x1ffd) | re_assemble_12 (sym_value
);
3063 /* This is any 17 bit branch. In PA2.0 syntax it also corresponds
3064 to the "B" instruction as well as BE. */
3065 case R_PARISC_PCREL17F
:
3066 case R_PARISC_DIR17F
:
3067 case R_PARISC_DIR17R
:
3068 case R_PARISC_PCREL17C
:
3069 case R_PARISC_PCREL17R
:
3070 return (insn
& ~0x1f1ffd) | re_assemble_17 (sym_value
);
3072 /* ADDIL or LDIL instructions. */
3073 case R_PARISC_DLTREL21L
:
3074 case R_PARISC_DLTIND21L
:
3075 case R_PARISC_LTOFF_FPTR21L
:
3076 case R_PARISC_PCREL21L
:
3077 case R_PARISC_LTOFF_TP21L
:
3078 case R_PARISC_DPREL21L
:
3079 case R_PARISC_PLTOFF21L
:
3080 case R_PARISC_DIR21L
:
3081 return (insn
& ~0x1fffff) | re_assemble_21 (sym_value
);
3083 /* LDO and integer loads/stores with 14 bit displacements. */
3084 case R_PARISC_DLTREL14R
:
3085 case R_PARISC_DLTREL14F
:
3086 case R_PARISC_DLTIND14R
:
3087 case R_PARISC_DLTIND14F
:
3088 case R_PARISC_LTOFF_FPTR14R
:
3089 case R_PARISC_PCREL14R
:
3090 case R_PARISC_PCREL14F
:
3091 case R_PARISC_LTOFF_TP14R
:
3092 case R_PARISC_LTOFF_TP14F
:
3093 case R_PARISC_DPREL14R
:
3094 case R_PARISC_DPREL14F
:
3095 case R_PARISC_PLTOFF14R
:
3096 case R_PARISC_PLTOFF14F
:
3097 case R_PARISC_DIR14R
:
3098 case R_PARISC_DIR14F
:
3099 return (insn
& ~0x3fff) | low_sign_unext (sym_value
, 14);
3101 /* PA2.0W LDO and integer loads/stores with 16 bit displacements. */
3102 case R_PARISC_LTOFF_FPTR16F
:
3103 case R_PARISC_PCREL16F
:
3104 case R_PARISC_LTOFF_TP16F
:
3105 case R_PARISC_GPREL16F
:
3106 case R_PARISC_PLTOFF16F
:
3107 case R_PARISC_DIR16F
:
3108 case R_PARISC_LTOFF16F
:
3109 return (insn
& ~0xffff) | re_assemble_16 (sym_value
);
3111 /* Doubleword loads and stores with a 14 bit displacement. */
3112 case R_PARISC_DLTREL14DR
:
3113 case R_PARISC_DLTIND14DR
:
3114 case R_PARISC_LTOFF_FPTR14DR
:
3115 case R_PARISC_LTOFF_FPTR16DF
:
3116 case R_PARISC_PCREL14DR
:
3117 case R_PARISC_PCREL16DF
:
3118 case R_PARISC_LTOFF_TP14DR
:
3119 case R_PARISC_LTOFF_TP16DF
:
3120 case R_PARISC_DPREL14DR
:
3121 case R_PARISC_GPREL16DF
:
3122 case R_PARISC_PLTOFF14DR
:
3123 case R_PARISC_PLTOFF16DF
:
3124 case R_PARISC_DIR14DR
:
3125 case R_PARISC_DIR16DF
:
3126 case R_PARISC_LTOFF16DF
:
3127 return (insn
& ~0x3ff1) | (((sym_value
& 0x2000) >> 13)
3128 | ((sym_value
& 0x1ff8) << 1));
3130 /* Floating point single word load/store instructions. */
3131 case R_PARISC_DLTREL14WR
:
3132 case R_PARISC_DLTIND14WR
:
3133 case R_PARISC_LTOFF_FPTR14WR
:
3134 case R_PARISC_LTOFF_FPTR16WF
:
3135 case R_PARISC_PCREL14WR
:
3136 case R_PARISC_PCREL16WF
:
3137 case R_PARISC_LTOFF_TP14WR
:
3138 case R_PARISC_LTOFF_TP16WF
:
3139 case R_PARISC_DPREL14WR
:
3140 case R_PARISC_GPREL16WF
:
3141 case R_PARISC_PLTOFF14WR
:
3142 case R_PARISC_PLTOFF16WF
:
3143 case R_PARISC_DIR16WF
:
3144 case R_PARISC_DIR14WR
:
3145 case R_PARISC_LTOFF16WF
:
3146 return (insn
& ~0x3ff9) | (((sym_value
& 0x2000) >> 13)
3147 | ((sym_value
& 0x1ffc) << 1));
3154 /* Compute the value for a relocation (REL) during a final link stage,
3155 then insert the value into the proper location in CONTENTS.
3157 VALUE is a tentative value for the relocation and may be overridden
3158 and modified here based on the specific relocation to be performed.
3160 For example we do conversions for PC-relative branches in this routine
3161 or redirection of calls to external routines to stubs.
3163 The work of actually applying the relocation is left to a helper
3164 routine in an attempt to reduce the complexity and size of this
3167 static bfd_reloc_status_type
3168 elf_hppa_final_link_relocate (Elf_Internal_Rela
*rel
,
3171 asection
*input_section
,
3174 struct bfd_link_info
*info
,
3176 struct elf_link_hash_entry
*eh
)
3178 struct elf64_hppa_link_hash_table
*hppa_info
= hppa_link_hash_table (info
);
3179 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
3180 bfd_vma
*local_offsets
;
3181 Elf_Internal_Shdr
*symtab_hdr
;
3183 bfd_vma max_branch_offset
= 0;
3184 bfd_vma offset
= rel
->r_offset
;
3185 bfd_signed_vma addend
= rel
->r_addend
;
3186 reloc_howto_type
*howto
= elf_hppa_howto_table
+ ELF_R_TYPE (rel
->r_info
);
3187 unsigned int r_symndx
= ELF_R_SYM (rel
->r_info
);
3188 unsigned int r_type
= howto
->type
;
3189 bfd_byte
*hit_data
= contents
+ offset
;
3191 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3192 local_offsets
= elf_local_got_offsets (input_bfd
);
3193 insn
= bfd_get_32 (input_bfd
, hit_data
);
3200 /* Basic function call support.
3202 Note for a call to a function defined in another dynamic library
3203 we want to redirect the call to a stub. */
3205 /* PC relative relocs without an implicit offset. */
3206 case R_PARISC_PCREL21L
:
3207 case R_PARISC_PCREL14R
:
3208 case R_PARISC_PCREL14F
:
3209 case R_PARISC_PCREL14WR
:
3210 case R_PARISC_PCREL14DR
:
3211 case R_PARISC_PCREL16F
:
3212 case R_PARISC_PCREL16WF
:
3213 case R_PARISC_PCREL16DF
:
3215 /* If this is a call to a function defined in another dynamic
3216 library, then redirect the call to the local stub for this
3218 if (sym_sec
== NULL
|| sym_sec
->output_section
== NULL
)
3219 value
= (hh
->stub_offset
+ hppa_info
->stub_sec
->output_offset
3220 + hppa_info
->stub_sec
->output_section
->vma
);
3222 /* Turn VALUE into a proper PC relative address. */
3223 value
-= (offset
+ input_section
->output_offset
3224 + input_section
->output_section
->vma
);
3226 /* Adjust for any field selectors. */
3227 if (r_type
== R_PARISC_PCREL21L
)
3228 value
= hppa_field_adjust (value
, -8 + addend
, e_lsel
);
3229 else if (r_type
== R_PARISC_PCREL14F
3230 || r_type
== R_PARISC_PCREL16F
3231 || r_type
== R_PARISC_PCREL16WF
3232 || r_type
== R_PARISC_PCREL16DF
)
3233 value
= hppa_field_adjust (value
, -8 + addend
, e_fsel
);
3235 value
= hppa_field_adjust (value
, -8 + addend
, e_rsel
);
3237 /* Apply the relocation to the given instruction. */
3238 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3242 case R_PARISC_PCREL12F
:
3243 case R_PARISC_PCREL22F
:
3244 case R_PARISC_PCREL17F
:
3245 case R_PARISC_PCREL22C
:
3246 case R_PARISC_PCREL17C
:
3247 case R_PARISC_PCREL17R
:
3249 /* If this is a call to a function defined in another dynamic
3250 library, then redirect the call to the local stub for this
3252 if (sym_sec
== NULL
|| sym_sec
->output_section
== NULL
)
3253 value
= (hh
->stub_offset
+ hppa_info
->stub_sec
->output_offset
3254 + hppa_info
->stub_sec
->output_section
->vma
);
3256 /* Turn VALUE into a proper PC relative address. */
3257 value
-= (offset
+ input_section
->output_offset
3258 + input_section
->output_section
->vma
);
3261 if (r_type
== (unsigned int) R_PARISC_PCREL22F
)
3262 max_branch_offset
= (1 << (22-1)) << 2;
3263 else if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
3264 max_branch_offset
= (1 << (17-1)) << 2;
3265 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
3266 max_branch_offset
= (1 << (12-1)) << 2;
3268 /* Make sure we can reach the branch target. */
3269 if (max_branch_offset
!= 0
3270 && value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3272 (*_bfd_error_handler
)
3273 (_("%B(%A+0x%lx): cannot reach %s"),
3277 eh
->root
.root
.string
);
3278 bfd_set_error (bfd_error_bad_value
);
3279 return bfd_reloc_notsupported
;
3282 /* Adjust for any field selectors. */
3283 if (r_type
== R_PARISC_PCREL17R
)
3284 value
= hppa_field_adjust (value
, addend
, e_rsel
);
3286 value
= hppa_field_adjust (value
, addend
, e_fsel
);
3288 /* All branches are implicitly shifted by 2 places. */
3291 /* Apply the relocation to the given instruction. */
3292 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3296 /* Indirect references to data through the DLT. */
3297 case R_PARISC_DLTIND14R
:
3298 case R_PARISC_DLTIND14F
:
3299 case R_PARISC_DLTIND14DR
:
3300 case R_PARISC_DLTIND14WR
:
3301 case R_PARISC_DLTIND21L
:
3302 case R_PARISC_LTOFF_FPTR14R
:
3303 case R_PARISC_LTOFF_FPTR14DR
:
3304 case R_PARISC_LTOFF_FPTR14WR
:
3305 case R_PARISC_LTOFF_FPTR21L
:
3306 case R_PARISC_LTOFF_FPTR16F
:
3307 case R_PARISC_LTOFF_FPTR16WF
:
3308 case R_PARISC_LTOFF_FPTR16DF
:
3309 case R_PARISC_LTOFF_TP21L
:
3310 case R_PARISC_LTOFF_TP14R
:
3311 case R_PARISC_LTOFF_TP14F
:
3312 case R_PARISC_LTOFF_TP14WR
:
3313 case R_PARISC_LTOFF_TP14DR
:
3314 case R_PARISC_LTOFF_TP16F
:
3315 case R_PARISC_LTOFF_TP16WF
:
3316 case R_PARISC_LTOFF_TP16DF
:
3317 case R_PARISC_LTOFF16F
:
3318 case R_PARISC_LTOFF16WF
:
3319 case R_PARISC_LTOFF16DF
:
3323 /* If this relocation was against a local symbol, then we still
3324 have not set up the DLT entry (it's not convenient to do so
3325 in the "finalize_dlt" routine because it is difficult to get
3326 to the local symbol's value).
3328 So, if this is a local symbol (h == NULL), then we need to
3329 fill in its DLT entry.
3331 Similarly we may still need to set up an entry in .opd for
3332 a local function which had its address taken. */
3335 bfd_vma
*local_opd_offsets
, *local_dlt_offsets
;
3337 if (local_offsets
== NULL
)
3340 /* Now do .opd creation if needed. */
3341 if (r_type
== R_PARISC_LTOFF_FPTR14R
3342 || r_type
== R_PARISC_LTOFF_FPTR14DR
3343 || r_type
== R_PARISC_LTOFF_FPTR14WR
3344 || r_type
== R_PARISC_LTOFF_FPTR21L
3345 || r_type
== R_PARISC_LTOFF_FPTR16F
3346 || r_type
== R_PARISC_LTOFF_FPTR16WF
3347 || r_type
== R_PARISC_LTOFF_FPTR16DF
)
3349 local_opd_offsets
= local_offsets
+ 2 * symtab_hdr
->sh_info
;
3350 off
= local_opd_offsets
[r_symndx
];
3352 /* The last bit records whether we've already initialised
3353 this local .opd entry. */
3356 BFD_ASSERT (off
!= (bfd_vma
) -1);
3361 local_opd_offsets
[r_symndx
] |= 1;
3363 /* The first two words of an .opd entry are zero. */
3364 memset (hppa_info
->opd_sec
->contents
+ off
, 0, 16);
3366 /* The next word is the address of the function. */
3367 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
+ addend
,
3368 (hppa_info
->opd_sec
->contents
+ off
+ 16));
3370 /* The last word is our local __gp value. */
3371 value
= _bfd_get_gp_value
3372 (hppa_info
->opd_sec
->output_section
->owner
);
3373 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
,
3374 (hppa_info
->opd_sec
->contents
+ off
+ 24));
3377 /* The DLT value is the address of the .opd entry. */
3379 + hppa_info
->opd_sec
->output_offset
3380 + hppa_info
->opd_sec
->output_section
->vma
);
3384 local_dlt_offsets
= local_offsets
;
3385 off
= local_dlt_offsets
[r_symndx
];
3389 BFD_ASSERT (off
!= (bfd_vma
) -1);
3394 local_dlt_offsets
[r_symndx
] |= 1;
3395 bfd_put_64 (hppa_info
->dlt_sec
->owner
,
3397 hppa_info
->dlt_sec
->contents
+ off
);
3401 off
= hh
->dlt_offset
;
3403 /* We want the value of the DLT offset for this symbol, not
3404 the symbol's actual address. Note that __gp may not point
3405 to the start of the DLT, so we have to compute the absolute
3406 address, then subtract out the value of __gp. */
3408 + hppa_info
->dlt_sec
->output_offset
3409 + hppa_info
->dlt_sec
->output_section
->vma
);
3410 value
-= _bfd_get_gp_value (output_bfd
);
3412 /* All DLTIND relocations are basically the same at this point,
3413 except that we need different field selectors for the 21bit
3414 version vs the 14bit versions. */
3415 if (r_type
== R_PARISC_DLTIND21L
3416 || r_type
== R_PARISC_LTOFF_FPTR21L
3417 || r_type
== R_PARISC_LTOFF_TP21L
)
3418 value
= hppa_field_adjust (value
, 0, e_lsel
);
3419 else if (r_type
== R_PARISC_DLTIND14F
3420 || r_type
== R_PARISC_LTOFF_FPTR16F
3421 || r_type
== R_PARISC_LTOFF_FPTR16WF
3422 || r_type
== R_PARISC_LTOFF_FPTR16DF
3423 || r_type
== R_PARISC_LTOFF16F
3424 || r_type
== R_PARISC_LTOFF16DF
3425 || r_type
== R_PARISC_LTOFF16WF
3426 || r_type
== R_PARISC_LTOFF_TP16F
3427 || r_type
== R_PARISC_LTOFF_TP16WF
3428 || r_type
== R_PARISC_LTOFF_TP16DF
)
3429 value
= hppa_field_adjust (value
, 0, e_fsel
);
3431 value
= hppa_field_adjust (value
, 0, e_rsel
);
3433 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3437 case R_PARISC_DLTREL14R
:
3438 case R_PARISC_DLTREL14F
:
3439 case R_PARISC_DLTREL14DR
:
3440 case R_PARISC_DLTREL14WR
:
3441 case R_PARISC_DLTREL21L
:
3442 case R_PARISC_DPREL21L
:
3443 case R_PARISC_DPREL14WR
:
3444 case R_PARISC_DPREL14DR
:
3445 case R_PARISC_DPREL14R
:
3446 case R_PARISC_DPREL14F
:
3447 case R_PARISC_GPREL16F
:
3448 case R_PARISC_GPREL16WF
:
3449 case R_PARISC_GPREL16DF
:
3451 /* Subtract out the global pointer value to make value a DLT
3452 relative address. */
3453 value
-= _bfd_get_gp_value (output_bfd
);
3455 /* All DLTREL relocations are basically the same at this point,
3456 except that we need different field selectors for the 21bit
3457 version vs the 14bit versions. */
3458 if (r_type
== R_PARISC_DLTREL21L
3459 || r_type
== R_PARISC_DPREL21L
)
3460 value
= hppa_field_adjust (value
, addend
, e_lrsel
);
3461 else if (r_type
== R_PARISC_DLTREL14F
3462 || r_type
== R_PARISC_DPREL14F
3463 || r_type
== R_PARISC_GPREL16F
3464 || r_type
== R_PARISC_GPREL16WF
3465 || r_type
== R_PARISC_GPREL16DF
)
3466 value
= hppa_field_adjust (value
, addend
, e_fsel
);
3468 value
= hppa_field_adjust (value
, addend
, e_rrsel
);
3470 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3474 case R_PARISC_DIR21L
:
3475 case R_PARISC_DIR17R
:
3476 case R_PARISC_DIR17F
:
3477 case R_PARISC_DIR14R
:
3478 case R_PARISC_DIR14F
:
3479 case R_PARISC_DIR14WR
:
3480 case R_PARISC_DIR14DR
:
3481 case R_PARISC_DIR16F
:
3482 case R_PARISC_DIR16WF
:
3483 case R_PARISC_DIR16DF
:
3485 /* All DIR relocations are basically the same at this point,
3486 except that branch offsets need to be divided by four, and
3487 we need different field selectors. Note that we don't
3488 redirect absolute calls to local stubs. */
3490 if (r_type
== R_PARISC_DIR21L
)
3491 value
= hppa_field_adjust (value
, addend
, e_lrsel
);
3492 else if (r_type
== R_PARISC_DIR17F
3493 || r_type
== R_PARISC_DIR16F
3494 || r_type
== R_PARISC_DIR16WF
3495 || r_type
== R_PARISC_DIR16DF
3496 || r_type
== R_PARISC_DIR14F
)
3497 value
= hppa_field_adjust (value
, addend
, e_fsel
);
3499 value
= hppa_field_adjust (value
, addend
, e_rrsel
);
3501 if (r_type
== R_PARISC_DIR17R
|| r_type
== R_PARISC_DIR17F
)
3502 /* All branches are implicitly shifted by 2 places. */
3505 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3509 case R_PARISC_PLTOFF21L
:
3510 case R_PARISC_PLTOFF14R
:
3511 case R_PARISC_PLTOFF14F
:
3512 case R_PARISC_PLTOFF14WR
:
3513 case R_PARISC_PLTOFF14DR
:
3514 case R_PARISC_PLTOFF16F
:
3515 case R_PARISC_PLTOFF16WF
:
3516 case R_PARISC_PLTOFF16DF
:
3518 /* We want the value of the PLT offset for this symbol, not
3519 the symbol's actual address. Note that __gp may not point
3520 to the start of the DLT, so we have to compute the absolute
3521 address, then subtract out the value of __gp. */
3522 value
= (hh
->plt_offset
3523 + hppa_info
->plt_sec
->output_offset
3524 + hppa_info
->plt_sec
->output_section
->vma
);
3525 value
-= _bfd_get_gp_value (output_bfd
);
3527 /* All PLTOFF relocations are basically the same at this point,
3528 except that we need different field selectors for the 21bit
3529 version vs the 14bit versions. */
3530 if (r_type
== R_PARISC_PLTOFF21L
)
3531 value
= hppa_field_adjust (value
, addend
, e_lrsel
);
3532 else if (r_type
== R_PARISC_PLTOFF14F
3533 || r_type
== R_PARISC_PLTOFF16F
3534 || r_type
== R_PARISC_PLTOFF16WF
3535 || r_type
== R_PARISC_PLTOFF16DF
)
3536 value
= hppa_field_adjust (value
, addend
, e_fsel
);
3538 value
= hppa_field_adjust (value
, addend
, e_rrsel
);
3540 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3544 case R_PARISC_LTOFF_FPTR32
:
3546 /* We may still need to create the FPTR itself if it was for
3550 /* The first two words of an .opd entry are zero. */
3551 memset (hppa_info
->opd_sec
->contents
+ hh
->opd_offset
, 0, 16);
3553 /* The next word is the address of the function. */
3554 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
+ addend
,
3555 (hppa_info
->opd_sec
->contents
3556 + hh
->opd_offset
+ 16));
3558 /* The last word is our local __gp value. */
3559 value
= _bfd_get_gp_value
3560 (hppa_info
->opd_sec
->output_section
->owner
);
3561 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
,
3562 hppa_info
->opd_sec
->contents
+ hh
->opd_offset
+ 24);
3564 /* The DLT value is the address of the .opd entry. */
3565 value
= (hh
->opd_offset
3566 + hppa_info
->opd_sec
->output_offset
3567 + hppa_info
->opd_sec
->output_section
->vma
);
3569 bfd_put_64 (hppa_info
->dlt_sec
->owner
,
3571 hppa_info
->dlt_sec
->contents
+ hh
->dlt_offset
);
3574 /* We want the value of the DLT offset for this symbol, not
3575 the symbol's actual address. Note that __gp may not point
3576 to the start of the DLT, so we have to compute the absolute
3577 address, then subtract out the value of __gp. */
3578 value
= (hh
->dlt_offset
3579 + hppa_info
->dlt_sec
->output_offset
3580 + hppa_info
->dlt_sec
->output_section
->vma
);
3581 value
-= _bfd_get_gp_value (output_bfd
);
3582 bfd_put_32 (input_bfd
, value
, hit_data
);
3583 return bfd_reloc_ok
;
3586 case R_PARISC_LTOFF_FPTR64
:
3587 case R_PARISC_LTOFF_TP64
:
3589 /* We may still need to create the FPTR itself if it was for
3591 if (eh
== NULL
&& r_type
== R_PARISC_LTOFF_FPTR64
)
3593 /* The first two words of an .opd entry are zero. */
3594 memset (hppa_info
->opd_sec
->contents
+ hh
->opd_offset
, 0, 16);
3596 /* The next word is the address of the function. */
3597 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
+ addend
,
3598 (hppa_info
->opd_sec
->contents
3599 + hh
->opd_offset
+ 16));
3601 /* The last word is our local __gp value. */
3602 value
= _bfd_get_gp_value
3603 (hppa_info
->opd_sec
->output_section
->owner
);
3604 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
,
3605 hppa_info
->opd_sec
->contents
+ hh
->opd_offset
+ 24);
3607 /* The DLT value is the address of the .opd entry. */
3608 value
= (hh
->opd_offset
3609 + hppa_info
->opd_sec
->output_offset
3610 + hppa_info
->opd_sec
->output_section
->vma
);
3612 bfd_put_64 (hppa_info
->dlt_sec
->owner
,
3614 hppa_info
->dlt_sec
->contents
+ hh
->dlt_offset
);
3617 /* We want the value of the DLT offset for this symbol, not
3618 the symbol's actual address. Note that __gp may not point
3619 to the start of the DLT, so we have to compute the absolute
3620 address, then subtract out the value of __gp. */
3621 value
= (hh
->dlt_offset
3622 + hppa_info
->dlt_sec
->output_offset
3623 + hppa_info
->dlt_sec
->output_section
->vma
);
3624 value
-= _bfd_get_gp_value (output_bfd
);
3625 bfd_put_64 (input_bfd
, value
, hit_data
);
3626 return bfd_reloc_ok
;
3629 case R_PARISC_DIR32
:
3630 bfd_put_32 (input_bfd
, value
+ addend
, hit_data
);
3631 return bfd_reloc_ok
;
3633 case R_PARISC_DIR64
:
3634 bfd_put_64 (input_bfd
, value
+ addend
, hit_data
);
3635 return bfd_reloc_ok
;
3637 case R_PARISC_GPREL64
:
3638 /* Subtract out the global pointer value to make value a DLT
3639 relative address. */
3640 value
-= _bfd_get_gp_value (output_bfd
);
3642 bfd_put_64 (input_bfd
, value
+ addend
, hit_data
);
3643 return bfd_reloc_ok
;
3645 case R_PARISC_LTOFF64
:
3646 /* We want the value of the DLT offset for this symbol, not
3647 the symbol's actual address. Note that __gp may not point
3648 to the start of the DLT, so we have to compute the absolute
3649 address, then subtract out the value of __gp. */
3650 value
= (hh
->dlt_offset
3651 + hppa_info
->dlt_sec
->output_offset
3652 + hppa_info
->dlt_sec
->output_section
->vma
);
3653 value
-= _bfd_get_gp_value (output_bfd
);
3655 bfd_put_64 (input_bfd
, value
+ addend
, hit_data
);
3656 return bfd_reloc_ok
;
3658 case R_PARISC_PCREL32
:
3660 /* If this is a call to a function defined in another dynamic
3661 library, then redirect the call to the local stub for this
3663 if (sym_sec
== NULL
|| sym_sec
->output_section
== NULL
)
3664 value
= (hh
->stub_offset
+ hppa_info
->stub_sec
->output_offset
3665 + hppa_info
->stub_sec
->output_section
->vma
);
3667 /* Turn VALUE into a proper PC relative address. */
3668 value
-= (offset
+ input_section
->output_offset
3669 + input_section
->output_section
->vma
);
3673 bfd_put_32 (input_bfd
, value
, hit_data
);
3674 return bfd_reloc_ok
;
3677 case R_PARISC_PCREL64
:
3679 /* If this is a call to a function defined in another dynamic
3680 library, then redirect the call to the local stub for this
3682 if (sym_sec
== NULL
|| sym_sec
->output_section
== NULL
)
3683 value
= (hh
->stub_offset
+ hppa_info
->stub_sec
->output_offset
3684 + hppa_info
->stub_sec
->output_section
->vma
);
3686 /* Turn VALUE into a proper PC relative address. */
3687 value
-= (offset
+ input_section
->output_offset
3688 + input_section
->output_section
->vma
);
3692 bfd_put_64 (input_bfd
, value
, hit_data
);
3693 return bfd_reloc_ok
;
3696 case R_PARISC_FPTR64
:
3700 /* We may still need to create the FPTR itself if it was for
3704 bfd_vma
*local_opd_offsets
;
3706 if (local_offsets
== NULL
)
3709 local_opd_offsets
= local_offsets
+ 2 * symtab_hdr
->sh_info
;
3710 off
= local_opd_offsets
[r_symndx
];
3712 /* The last bit records whether we've already initialised
3713 this local .opd entry. */
3716 BFD_ASSERT (off
!= (bfd_vma
) -1);
3721 /* The first two words of an .opd entry are zero. */
3722 memset (hppa_info
->opd_sec
->contents
+ off
, 0, 16);
3724 /* The next word is the address of the function. */
3725 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
+ addend
,
3726 (hppa_info
->opd_sec
->contents
+ off
+ 16));
3728 /* The last word is our local __gp value. */
3729 value
= _bfd_get_gp_value
3730 (hppa_info
->opd_sec
->output_section
->owner
);
3731 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
,
3732 hppa_info
->opd_sec
->contents
+ off
+ 24);
3736 off
= hh
->opd_offset
;
3738 if (hh
== NULL
|| hh
->want_opd
)
3739 /* We want the value of the OPD offset for this symbol. */
3741 + hppa_info
->opd_sec
->output_offset
3742 + hppa_info
->opd_sec
->output_section
->vma
);
3744 /* We want the address of the symbol. */
3747 bfd_put_64 (input_bfd
, value
, hit_data
);
3748 return bfd_reloc_ok
;
3751 case R_PARISC_SECREL32
:
3753 value
-= sym_sec
->output_section
->vma
;
3754 bfd_put_32 (input_bfd
, value
+ addend
, hit_data
);
3755 return bfd_reloc_ok
;
3757 case R_PARISC_SEGREL32
:
3758 case R_PARISC_SEGREL64
:
3760 /* If this is the first SEGREL relocation, then initialize
3761 the segment base values. */
3762 if (hppa_info
->text_segment_base
== (bfd_vma
) -1)
3763 bfd_map_over_sections (output_bfd
, elf_hppa_record_segment_addrs
,
3766 /* VALUE holds the absolute address. We want to include the
3767 addend, then turn it into a segment relative address.
3769 The segment is derived from SYM_SEC. We assume that there are
3770 only two segments of note in the resulting executable/shlib.
3771 A readonly segment (.text) and a readwrite segment (.data). */
3774 if (sym_sec
->flags
& SEC_CODE
)
3775 value
-= hppa_info
->text_segment_base
;
3777 value
-= hppa_info
->data_segment_base
;
3779 if (r_type
== R_PARISC_SEGREL32
)
3780 bfd_put_32 (input_bfd
, value
, hit_data
);
3782 bfd_put_64 (input_bfd
, value
, hit_data
);
3783 return bfd_reloc_ok
;
3786 /* Something we don't know how to handle. */
3788 return bfd_reloc_notsupported
;
3791 /* Update the instruction word. */
3792 bfd_put_32 (input_bfd
, (bfd_vma
) insn
, hit_data
);
3793 return bfd_reloc_ok
;
3796 /* Relocate an HPPA ELF section. */
3799 elf64_hppa_relocate_section (bfd
*output_bfd
,
3800 struct bfd_link_info
*info
,
3802 asection
*input_section
,
3804 Elf_Internal_Rela
*relocs
,
3805 Elf_Internal_Sym
*local_syms
,
3806 asection
**local_sections
)
3808 Elf_Internal_Shdr
*symtab_hdr
;
3809 Elf_Internal_Rela
*rel
;
3810 Elf_Internal_Rela
*relend
;
3811 struct elf64_hppa_link_hash_table
*hppa_info
;
3813 hppa_info
= hppa_link_hash_table (info
);
3814 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3817 relend
= relocs
+ input_section
->reloc_count
;
3818 for (; rel
< relend
; rel
++)
3821 reloc_howto_type
*howto
= elf_hppa_howto_table
+ ELF_R_TYPE (rel
->r_info
);
3822 unsigned long r_symndx
;
3823 struct elf_link_hash_entry
*eh
;
3824 Elf_Internal_Sym
*sym
;
3827 bfd_reloc_status_type r
;
3828 bfd_boolean warned_undef
;
3830 r_type
= ELF_R_TYPE (rel
->r_info
);
3831 if (r_type
< 0 || r_type
>= (int) R_PARISC_UNIMPLEMENTED
)
3833 bfd_set_error (bfd_error_bad_value
);
3836 if (r_type
== (unsigned int) R_PARISC_GNU_VTENTRY
3837 || r_type
== (unsigned int) R_PARISC_GNU_VTINHERIT
)
3840 /* This is a final link. */
3841 r_symndx
= ELF_R_SYM (rel
->r_info
);
3845 warned_undef
= FALSE
;
3846 if (r_symndx
< symtab_hdr
->sh_info
)
3848 /* This is a local symbol, hh defaults to NULL. */
3849 sym
= local_syms
+ r_symndx
;
3850 sym_sec
= local_sections
[r_symndx
];
3851 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sym_sec
, rel
);
3855 /* This is not a local symbol. */
3856 bfd_boolean unresolved_reloc
;
3857 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (input_bfd
);
3859 /* It seems this can happen with erroneous or unsupported
3860 input (mixing a.out and elf in an archive, for example.) */
3861 if (sym_hashes
== NULL
)
3864 eh
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3866 while (eh
->root
.type
== bfd_link_hash_indirect
3867 || eh
->root
.type
== bfd_link_hash_warning
)
3868 eh
= (struct elf_link_hash_entry
*) eh
->root
.u
.i
.link
;
3870 warned_undef
= FALSE
;
3871 unresolved_reloc
= FALSE
;
3873 if (eh
->root
.type
== bfd_link_hash_defined
3874 || eh
->root
.type
== bfd_link_hash_defweak
)
3876 sym_sec
= eh
->root
.u
.def
.section
;
3878 || sym_sec
->output_section
== NULL
)
3879 /* Set a flag that will be cleared later if we find a
3880 relocation value for this symbol. output_section
3881 is typically NULL for symbols satisfied by a shared
3883 unresolved_reloc
= TRUE
;
3885 relocation
= (eh
->root
.u
.def
.value
3886 + sym_sec
->output_section
->vma
3887 + sym_sec
->output_offset
);
3889 else if (eh
->root
.type
== bfd_link_hash_undefweak
)
3891 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
3892 && ELF_ST_VISIBILITY (eh
->other
) == STV_DEFAULT
)
3894 else if (!info
->relocatable
3895 && elf_hppa_is_dynamic_loader_symbol (eh
->root
.root
.string
))
3897 else if (!info
->relocatable
)
3900 err
= (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
3901 || ELF_ST_VISIBILITY (eh
->other
) != STV_DEFAULT
);
3902 if (!info
->callbacks
->undefined_symbol (info
,
3903 eh
->root
.root
.string
,
3906 rel
->r_offset
, err
))
3908 warned_undef
= TRUE
;
3911 if (!info
->relocatable
3913 && eh
->root
.type
!= bfd_link_hash_defined
3914 && eh
->root
.type
!= bfd_link_hash_defweak
3915 && eh
->root
.type
!= bfd_link_hash_undefweak
)
3917 if (info
->unresolved_syms_in_objects
== RM_IGNORE
3918 && ELF_ST_VISIBILITY (eh
->other
) == STV_DEFAULT
3919 && eh
->type
== STT_PARISC_MILLI
)
3921 if (! info
->callbacks
->undefined_symbol
3922 (info
, eh_name (eh
), input_bfd
,
3923 input_section
, rel
->r_offset
, FALSE
))
3925 warned_undef
= TRUE
;
3930 if (sym_sec
!= NULL
&& elf_discarded_section (sym_sec
))
3932 /* For relocs against symbols from removed linkonce sections,
3933 or sections discarded by a linker script, we just want the
3934 section contents zeroed. Avoid any special processing. */
3935 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
3941 if (info
->relocatable
)
3944 r
= elf_hppa_final_link_relocate (rel
, input_bfd
, output_bfd
,
3945 input_section
, contents
,
3946 relocation
, info
, sym_sec
,
3949 if (r
!= bfd_reloc_ok
)
3955 case bfd_reloc_overflow
:
3957 const char *sym_name
;
3963 sym_name
= bfd_elf_string_from_elf_section (input_bfd
,
3964 symtab_hdr
->sh_link
,
3966 if (sym_name
== NULL
)
3968 if (*sym_name
== '\0')
3969 sym_name
= bfd_section_name (input_bfd
, sym_sec
);
3972 if (!((*info
->callbacks
->reloc_overflow
)
3973 (info
, (eh
? &eh
->root
: NULL
), sym_name
,
3974 howto
->name
, (bfd_vma
) 0, input_bfd
,
3975 input_section
, rel
->r_offset
)))
3985 static const struct bfd_elf_special_section elf64_hppa_special_sections
[] =
3987 { STRING_COMMA_LEN (".fini"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
3988 { STRING_COMMA_LEN (".init"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
3989 { STRING_COMMA_LEN (".plt"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
3990 { STRING_COMMA_LEN (".dlt"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
3991 { STRING_COMMA_LEN (".sdata"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
3992 { STRING_COMMA_LEN (".sbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
3993 { STRING_COMMA_LEN (".tbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_HP_TLS
},
3994 { NULL
, 0, 0, 0, 0 }
3997 /* The hash bucket size is the standard one, namely 4. */
3999 const struct elf_size_info hppa64_elf_size_info
=
4001 sizeof (Elf64_External_Ehdr
),
4002 sizeof (Elf64_External_Phdr
),
4003 sizeof (Elf64_External_Shdr
),
4004 sizeof (Elf64_External_Rel
),
4005 sizeof (Elf64_External_Rela
),
4006 sizeof (Elf64_External_Sym
),
4007 sizeof (Elf64_External_Dyn
),
4008 sizeof (Elf_External_Note
),
4012 ELFCLASS64
, EV_CURRENT
,
4013 bfd_elf64_write_out_phdrs
,
4014 bfd_elf64_write_shdrs_and_ehdr
,
4015 bfd_elf64_checksum_contents
,
4016 bfd_elf64_write_relocs
,
4017 bfd_elf64_swap_symbol_in
,
4018 bfd_elf64_swap_symbol_out
,
4019 bfd_elf64_slurp_reloc_table
,
4020 bfd_elf64_slurp_symbol_table
,
4021 bfd_elf64_swap_dyn_in
,
4022 bfd_elf64_swap_dyn_out
,
4023 bfd_elf64_swap_reloc_in
,
4024 bfd_elf64_swap_reloc_out
,
4025 bfd_elf64_swap_reloca_in
,
4026 bfd_elf64_swap_reloca_out
4029 #define TARGET_BIG_SYM bfd_elf64_hppa_vec
4030 #define TARGET_BIG_NAME "elf64-hppa"
4031 #define ELF_ARCH bfd_arch_hppa
4032 #define ELF_MACHINE_CODE EM_PARISC
4033 /* This is not strictly correct. The maximum page size for PA2.0 is
4034 64M. But everything still uses 4k. */
4035 #define ELF_MAXPAGESIZE 0x1000
4036 #define ELF_OSABI ELFOSABI_HPUX
4038 #define bfd_elf64_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
4039 #define bfd_elf64_bfd_reloc_name_lookup elf_hppa_reloc_name_lookup
4040 #define bfd_elf64_bfd_is_local_label_name elf_hppa_is_local_label_name
4041 #define elf_info_to_howto elf_hppa_info_to_howto
4042 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
4044 #define elf_backend_section_from_shdr elf64_hppa_section_from_shdr
4045 #define elf_backend_object_p elf64_hppa_object_p
4046 #define elf_backend_final_write_processing \
4047 elf_hppa_final_write_processing
4048 #define elf_backend_fake_sections elf_hppa_fake_sections
4049 #define elf_backend_add_symbol_hook elf_hppa_add_symbol_hook
4051 #define elf_backend_relocate_section elf_hppa_relocate_section
4053 #define bfd_elf64_bfd_final_link elf_hppa_final_link
4055 #define elf_backend_create_dynamic_sections \
4056 elf64_hppa_create_dynamic_sections
4057 #define elf_backend_post_process_headers elf64_hppa_post_process_headers
4059 #define elf_backend_omit_section_dynsym \
4060 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
4061 #define elf_backend_adjust_dynamic_symbol \
4062 elf64_hppa_adjust_dynamic_symbol
4064 #define elf_backend_size_dynamic_sections \
4065 elf64_hppa_size_dynamic_sections
4067 #define elf_backend_finish_dynamic_symbol \
4068 elf64_hppa_finish_dynamic_symbol
4069 #define elf_backend_finish_dynamic_sections \
4070 elf64_hppa_finish_dynamic_sections
4071 #define elf_backend_grok_prstatus elf64_hppa_grok_prstatus
4072 #define elf_backend_grok_psinfo elf64_hppa_grok_psinfo
4074 /* Stuff for the BFD linker: */
4075 #define bfd_elf64_bfd_link_hash_table_create \
4076 elf64_hppa_hash_table_create
4078 #define elf_backend_check_relocs \
4079 elf64_hppa_check_relocs
4081 #define elf_backend_size_info \
4082 hppa64_elf_size_info
4084 #define elf_backend_additional_program_headers \
4085 elf64_hppa_additional_program_headers
4087 #define elf_backend_modify_segment_map \
4088 elf64_hppa_modify_segment_map
4090 #define elf_backend_link_output_symbol_hook \
4091 elf64_hppa_link_output_symbol_hook
4093 #define elf_backend_want_got_plt 0
4094 #define elf_backend_plt_readonly 0
4095 #define elf_backend_want_plt_sym 0
4096 #define elf_backend_got_header_size 0
4097 #define elf_backend_type_change_ok TRUE
4098 #define elf_backend_get_symbol_type elf64_hppa_elf_get_symbol_type
4099 #define elf_backend_reloc_type_class elf64_hppa_reloc_type_class
4100 #define elf_backend_rela_normal 1
4101 #define elf_backend_special_sections elf64_hppa_special_sections
4102 #define elf_backend_action_discarded elf_hppa_action_discarded
4103 #define elf_backend_section_from_phdr elf64_hppa_section_from_phdr
4105 #define elf64_bed elf64_hppa_hpux_bed
4107 #include "elf64-target.h"
4109 #undef TARGET_BIG_SYM
4110 #define TARGET_BIG_SYM bfd_elf64_hppa_linux_vec
4111 #undef TARGET_BIG_NAME
4112 #define TARGET_BIG_NAME "elf64-hppa-linux"
4114 #define ELF_OSABI ELFOSABI_LINUX
4115 #undef elf_backend_post_process_headers
4116 #define elf_backend_post_process_headers _bfd_elf_set_osabi
4118 #define elf64_bed elf64_hppa_linux_bed
4120 #include "elf64-target.h"