1 /* Support for HPPA 64-bit ELF
2 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
3 2010 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
22 #include "alloca-conf.h"
29 #include "elf64-hppa.h"
34 #define PLT_ENTRY_SIZE 0x10
35 #define DLT_ENTRY_SIZE 0x8
36 #define OPD_ENTRY_SIZE 0x20
38 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/pa20_64/dld.sl"
40 /* The stub is supposed to load the target address and target's DP
41 value out of the PLT, then do an external branch to the target
46 LDD PLTOFF+8(%r27),%r27
48 Note that we must use the LDD with a 14 bit displacement, not the one
49 with a 5 bit displacement. */
50 static char plt_stub
[] = {0x53, 0x61, 0x00, 0x00, 0xe8, 0x20, 0xd0, 0x00,
51 0x53, 0x7b, 0x00, 0x00 };
53 struct elf64_hppa_link_hash_entry
55 struct elf_link_hash_entry eh
;
57 /* Offsets for this symbol in various linker sections. */
63 /* The index of the (possibly local) symbol in the input bfd and its
64 associated BFD. Needed so that we can have relocs against local
65 symbols in shared libraries. */
69 /* Dynamic symbols may need to have two different values. One for
70 the dynamic symbol table, one for the normal symbol table.
72 In such cases we store the symbol's real value and section
73 index here so we can restore the real value before we write
74 the normal symbol table. */
78 /* Used to count non-got, non-plt relocations for delayed sizing
79 of relocation sections. */
80 struct elf64_hppa_dyn_reloc_entry
82 /* Next relocation in the chain. */
83 struct elf64_hppa_dyn_reloc_entry
*next
;
85 /* The type of the relocation. */
88 /* The input section of the relocation. */
91 /* Number of relocs copied in this section. */
94 /* The index of the section symbol for the input section of
95 the relocation. Only needed when building shared libraries. */
98 /* The offset within the input section of the relocation. */
101 /* The addend for the relocation. */
106 /* Nonzero if this symbol needs an entry in one of the linker
114 struct elf64_hppa_link_hash_table
116 struct elf_link_hash_table root
;
118 /* Shortcuts to get to the various linker defined sections. */
120 asection
*dlt_rel_sec
;
122 asection
*plt_rel_sec
;
124 asection
*opd_rel_sec
;
125 asection
*other_rel_sec
;
127 /* Offset of __gp within .plt section. When the PLT gets large we want
128 to slide __gp into the PLT section so that we can continue to use
129 single DP relative instructions to load values out of the PLT. */
132 /* Note this is not strictly correct. We should create a stub section for
133 each input section with calls. The stub section should be placed before
134 the section with the call. */
137 bfd_vma text_segment_base
;
138 bfd_vma data_segment_base
;
140 /* We build tables to map from an input section back to its
141 symbol index. This is the BFD for which we currently have
143 bfd
*section_syms_bfd
;
145 /* Array of symbol numbers for each input section attached to the
150 #define hppa_link_hash_table(p) \
151 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
152 == HPPA64_ELF_DATA ? ((struct elf64_hppa_link_hash_table *) ((p)->hash)) : NULL)
154 #define hppa_elf_hash_entry(ent) \
155 ((struct elf64_hppa_link_hash_entry *)(ent))
157 #define eh_name(eh) \
158 (eh ? eh->root.root.string : "<undef>")
160 typedef struct bfd_hash_entry
*(*new_hash_entry_func
)
161 (struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *);
163 static struct bfd_link_hash_table
*elf64_hppa_hash_table_create
166 /* This must follow the definitions of the various derived linker
167 hash tables and shared functions. */
168 #include "elf-hppa.h"
170 static bfd_boolean elf64_hppa_object_p
173 static void elf64_hppa_post_process_headers
174 (bfd
*, struct bfd_link_info
*);
176 static bfd_boolean elf64_hppa_create_dynamic_sections
177 (bfd
*, struct bfd_link_info
*);
179 static bfd_boolean elf64_hppa_adjust_dynamic_symbol
180 (struct bfd_link_info
*, struct elf_link_hash_entry
*);
182 static bfd_boolean elf64_hppa_mark_milli_and_exported_functions
183 (struct elf_link_hash_entry
*, void *);
185 static bfd_boolean elf64_hppa_size_dynamic_sections
186 (bfd
*, struct bfd_link_info
*);
188 static int elf64_hppa_link_output_symbol_hook
189 (struct bfd_link_info
*, const char *, Elf_Internal_Sym
*,
190 asection
*, struct elf_link_hash_entry
*);
192 static bfd_boolean elf64_hppa_finish_dynamic_symbol
193 (bfd
*, struct bfd_link_info
*,
194 struct elf_link_hash_entry
*, Elf_Internal_Sym
*);
196 static enum elf_reloc_type_class elf64_hppa_reloc_type_class
197 (const Elf_Internal_Rela
*);
199 static bfd_boolean elf64_hppa_finish_dynamic_sections
200 (bfd
*, struct bfd_link_info
*);
202 static bfd_boolean elf64_hppa_check_relocs
203 (bfd
*, struct bfd_link_info
*,
204 asection
*, const Elf_Internal_Rela
*);
206 static bfd_boolean elf64_hppa_dynamic_symbol_p
207 (struct elf_link_hash_entry
*, struct bfd_link_info
*);
209 static bfd_boolean elf64_hppa_mark_exported_functions
210 (struct elf_link_hash_entry
*, void *);
212 static bfd_boolean elf64_hppa_finalize_opd
213 (struct elf_link_hash_entry
*, void *);
215 static bfd_boolean elf64_hppa_finalize_dlt
216 (struct elf_link_hash_entry
*, void *);
218 static bfd_boolean allocate_global_data_dlt
219 (struct elf_link_hash_entry
*, void *);
221 static bfd_boolean allocate_global_data_plt
222 (struct elf_link_hash_entry
*, void *);
224 static bfd_boolean allocate_global_data_stub
225 (struct elf_link_hash_entry
*, void *);
227 static bfd_boolean allocate_global_data_opd
228 (struct elf_link_hash_entry
*, void *);
230 static bfd_boolean get_reloc_section
231 (bfd
*, struct elf64_hppa_link_hash_table
*, asection
*);
233 static bfd_boolean count_dyn_reloc
234 (bfd
*, struct elf64_hppa_link_hash_entry
*,
235 int, asection
*, int, bfd_vma
, bfd_vma
);
237 static bfd_boolean allocate_dynrel_entries
238 (struct elf_link_hash_entry
*, void *);
240 static bfd_boolean elf64_hppa_finalize_dynreloc
241 (struct elf_link_hash_entry
*, void *);
243 static bfd_boolean get_opd
244 (bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*);
246 static bfd_boolean get_plt
247 (bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*);
249 static bfd_boolean get_dlt
250 (bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*);
252 static bfd_boolean get_stub
253 (bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*);
255 static int elf64_hppa_elf_get_symbol_type
256 (Elf_Internal_Sym
*, int);
258 /* Initialize an entry in the link hash table. */
260 static struct bfd_hash_entry
*
261 hppa64_link_hash_newfunc (struct bfd_hash_entry
*entry
,
262 struct bfd_hash_table
*table
,
265 /* Allocate the structure if it has not already been allocated by a
269 entry
= bfd_hash_allocate (table
,
270 sizeof (struct elf64_hppa_link_hash_entry
));
275 /* Call the allocation method of the superclass. */
276 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
279 struct elf64_hppa_link_hash_entry
*hh
;
281 /* Initialize our local data. All zeros. */
282 hh
= hppa_elf_hash_entry (entry
);
283 memset (&hh
->dlt_offset
, 0,
284 (sizeof (struct elf64_hppa_link_hash_entry
)
285 - offsetof (struct elf64_hppa_link_hash_entry
, dlt_offset
)));
291 /* Create the derived linker hash table. The PA64 ELF port uses this
292 derived hash table to keep information specific to the PA ElF
293 linker (without using static variables). */
295 static struct bfd_link_hash_table
*
296 elf64_hppa_hash_table_create (bfd
*abfd
)
298 struct elf64_hppa_link_hash_table
*htab
;
299 bfd_size_type amt
= sizeof (*htab
);
301 htab
= bfd_zalloc (abfd
, amt
);
305 if (!_bfd_elf_link_hash_table_init (&htab
->root
, abfd
,
306 hppa64_link_hash_newfunc
,
307 sizeof (struct elf64_hppa_link_hash_entry
),
310 bfd_release (abfd
, htab
);
314 htab
->text_segment_base
= (bfd_vma
) -1;
315 htab
->data_segment_base
= (bfd_vma
) -1;
317 return &htab
->root
.root
;
320 /* Return nonzero if ABFD represents a PA2.0 ELF64 file.
322 Additionally we set the default architecture and machine. */
324 elf64_hppa_object_p (bfd
*abfd
)
326 Elf_Internal_Ehdr
* i_ehdrp
;
329 i_ehdrp
= elf_elfheader (abfd
);
330 if (strcmp (bfd_get_target (abfd
), "elf64-hppa-linux") == 0)
332 /* GCC on hppa-linux produces binaries with OSABI=Linux,
333 but the kernel produces corefiles with OSABI=SysV. */
334 if (i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_LINUX
335 && i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_NONE
) /* aka SYSV */
340 /* HPUX produces binaries with OSABI=HPUX,
341 but the kernel produces corefiles with OSABI=SysV. */
342 if (i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_HPUX
343 && i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_NONE
) /* aka SYSV */
347 flags
= i_ehdrp
->e_flags
;
348 switch (flags
& (EF_PARISC_ARCH
| EF_PARISC_WIDE
))
351 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 10);
353 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 11);
355 if (i_ehdrp
->e_ident
[EI_CLASS
] == ELFCLASS64
)
356 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 25);
358 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 20);
359 case EFA_PARISC_2_0
| EF_PARISC_WIDE
:
360 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 25);
362 /* Don't be fussy. */
366 /* Given section type (hdr->sh_type), return a boolean indicating
367 whether or not the section is an elf64-hppa specific section. */
369 elf64_hppa_section_from_shdr (bfd
*abfd
,
370 Elf_Internal_Shdr
*hdr
,
374 switch (hdr
->sh_type
)
377 if (strcmp (name
, ".PARISC.archext") != 0)
380 case SHT_PARISC_UNWIND
:
381 if (strcmp (name
, ".PARISC.unwind") != 0)
385 case SHT_PARISC_ANNOT
:
390 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
396 /* SEC is a section containing relocs for an input BFD when linking; return
397 a suitable section for holding relocs in the output BFD for a link. */
400 get_reloc_section (bfd
*abfd
,
401 struct elf64_hppa_link_hash_table
*hppa_info
,
404 const char *srel_name
;
408 srel_name
= (bfd_elf_string_from_elf_section
409 (abfd
, elf_elfheader(abfd
)->e_shstrndx
,
410 _bfd_elf_single_rel_hdr(sec
)->sh_name
));
411 if (srel_name
== NULL
)
414 dynobj
= hppa_info
->root
.dynobj
;
416 hppa_info
->root
.dynobj
= dynobj
= abfd
;
418 srel
= bfd_get_section_by_name (dynobj
, srel_name
);
421 srel
= bfd_make_section_with_flags (dynobj
, srel_name
,
429 || !bfd_set_section_alignment (dynobj
, srel
, 3))
433 hppa_info
->other_rel_sec
= srel
;
437 /* Add a new entry to the list of dynamic relocations against DYN_H.
439 We use this to keep a record of all the FPTR relocations against a
440 particular symbol so that we can create FPTR relocations in the
444 count_dyn_reloc (bfd
*abfd
,
445 struct elf64_hppa_link_hash_entry
*hh
,
452 struct elf64_hppa_dyn_reloc_entry
*rent
;
454 rent
= (struct elf64_hppa_dyn_reloc_entry
*)
455 bfd_alloc (abfd
, (bfd_size_type
) sizeof (*rent
));
459 rent
->next
= hh
->reloc_entries
;
462 rent
->sec_symndx
= sec_symndx
;
463 rent
->offset
= offset
;
464 rent
->addend
= addend
;
465 hh
->reloc_entries
= rent
;
470 /* Return a pointer to the local DLT, PLT and OPD reference counts
471 for ABFD. Returns NULL if the storage allocation fails. */
473 static bfd_signed_vma
*
474 hppa64_elf_local_refcounts (bfd
*abfd
)
476 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
477 bfd_signed_vma
*local_refcounts
;
479 local_refcounts
= elf_local_got_refcounts (abfd
);
480 if (local_refcounts
== NULL
)
484 /* Allocate space for local DLT, PLT and OPD reference
485 counts. Done this way to save polluting elf_obj_tdata
486 with another target specific pointer. */
487 size
= symtab_hdr
->sh_info
;
488 size
*= 3 * sizeof (bfd_signed_vma
);
489 local_refcounts
= bfd_zalloc (abfd
, size
);
490 elf_local_got_refcounts (abfd
) = local_refcounts
;
492 return local_refcounts
;
495 /* Scan the RELOCS and record the type of dynamic entries that each
496 referenced symbol needs. */
499 elf64_hppa_check_relocs (bfd
*abfd
,
500 struct bfd_link_info
*info
,
502 const Elf_Internal_Rela
*relocs
)
504 struct elf64_hppa_link_hash_table
*hppa_info
;
505 const Elf_Internal_Rela
*relend
;
506 Elf_Internal_Shdr
*symtab_hdr
;
507 const Elf_Internal_Rela
*rel
;
508 unsigned int sec_symndx
;
510 if (info
->relocatable
)
513 /* If this is the first dynamic object found in the link, create
514 the special sections required for dynamic linking. */
515 if (! elf_hash_table (info
)->dynamic_sections_created
)
517 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
521 hppa_info
= hppa_link_hash_table (info
);
522 if (hppa_info
== NULL
)
524 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
526 /* If necessary, build a new table holding section symbols indices
529 if (info
->shared
&& hppa_info
->section_syms_bfd
!= abfd
)
532 unsigned int highest_shndx
;
533 Elf_Internal_Sym
*local_syms
= NULL
;
534 Elf_Internal_Sym
*isym
, *isymend
;
537 /* We're done with the old cache of section index to section symbol
538 index information. Free it.
540 ?!? Note we leak the last section_syms array. Presumably we
541 could free it in one of the later routines in this file. */
542 if (hppa_info
->section_syms
)
543 free (hppa_info
->section_syms
);
545 /* Read this BFD's local symbols. */
546 if (symtab_hdr
->sh_info
!= 0)
548 local_syms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
549 if (local_syms
== NULL
)
550 local_syms
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
551 symtab_hdr
->sh_info
, 0,
553 if (local_syms
== NULL
)
557 /* Record the highest section index referenced by the local symbols. */
559 isymend
= local_syms
+ symtab_hdr
->sh_info
;
560 for (isym
= local_syms
; isym
< isymend
; isym
++)
562 if (isym
->st_shndx
> highest_shndx
563 && isym
->st_shndx
< SHN_LORESERVE
)
564 highest_shndx
= isym
->st_shndx
;
567 /* Allocate an array to hold the section index to section symbol index
568 mapping. Bump by one since we start counting at zero. */
572 hppa_info
->section_syms
= (int *) bfd_malloc (amt
);
574 /* Now walk the local symbols again. If we find a section symbol,
575 record the index of the symbol into the section_syms array. */
576 for (i
= 0, isym
= local_syms
; isym
< isymend
; i
++, isym
++)
578 if (ELF_ST_TYPE (isym
->st_info
) == STT_SECTION
)
579 hppa_info
->section_syms
[isym
->st_shndx
] = i
;
582 /* We are finished with the local symbols. */
583 if (local_syms
!= NULL
584 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
586 if (! info
->keep_memory
)
590 /* Cache the symbols for elf_link_input_bfd. */
591 symtab_hdr
->contents
= (unsigned char *) local_syms
;
595 /* Record which BFD we built the section_syms mapping for. */
596 hppa_info
->section_syms_bfd
= abfd
;
599 /* Record the symbol index for this input section. We may need it for
600 relocations when building shared libraries. When not building shared
601 libraries this value is never really used, but assign it to zero to
602 prevent out of bounds memory accesses in other routines. */
605 sec_symndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
607 /* If we did not find a section symbol for this section, then
608 something went terribly wrong above. */
609 if (sec_symndx
== SHN_BAD
)
612 if (sec_symndx
< SHN_LORESERVE
)
613 sec_symndx
= hppa_info
->section_syms
[sec_symndx
];
620 relend
= relocs
+ sec
->reloc_count
;
621 for (rel
= relocs
; rel
< relend
; ++rel
)
632 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
633 struct elf64_hppa_link_hash_entry
*hh
;
635 bfd_boolean maybe_dynamic
;
636 int dynrel_type
= R_PARISC_NONE
;
637 static reloc_howto_type
*howto
;
639 if (r_symndx
>= symtab_hdr
->sh_info
)
641 /* We're dealing with a global symbol -- find its hash entry
642 and mark it as being referenced. */
643 long indx
= r_symndx
- symtab_hdr
->sh_info
;
644 hh
= hppa_elf_hash_entry (elf_sym_hashes (abfd
)[indx
]);
645 while (hh
->eh
.root
.type
== bfd_link_hash_indirect
646 || hh
->eh
.root
.type
== bfd_link_hash_warning
)
647 hh
= hppa_elf_hash_entry (hh
->eh
.root
.u
.i
.link
);
649 hh
->eh
.ref_regular
= 1;
654 /* We can only get preliminary data on whether a symbol is
655 locally or externally defined, as not all of the input files
656 have yet been processed. Do something with what we know, as
657 this may help reduce memory usage and processing time later. */
658 maybe_dynamic
= FALSE
;
659 if (hh
&& ((info
->shared
661 || info
->unresolved_syms_in_shared_libs
== RM_IGNORE
))
662 || !hh
->eh
.def_regular
663 || hh
->eh
.root
.type
== bfd_link_hash_defweak
))
664 maybe_dynamic
= TRUE
;
666 howto
= elf_hppa_howto_table
+ ELF64_R_TYPE (rel
->r_info
);
670 /* These are simple indirect references to symbols through the
671 DLT. We need to create a DLT entry for any symbols which
672 appears in a DLTIND relocation. */
673 case R_PARISC_DLTIND21L
:
674 case R_PARISC_DLTIND14R
:
675 case R_PARISC_DLTIND14F
:
676 case R_PARISC_DLTIND14WR
:
677 case R_PARISC_DLTIND14DR
:
678 need_entry
= NEED_DLT
;
681 /* ?!? These need a DLT entry. But I have no idea what to do with
682 the "link time TP value. */
683 case R_PARISC_LTOFF_TP21L
:
684 case R_PARISC_LTOFF_TP14R
:
685 case R_PARISC_LTOFF_TP14F
:
686 case R_PARISC_LTOFF_TP64
:
687 case R_PARISC_LTOFF_TP14WR
:
688 case R_PARISC_LTOFF_TP14DR
:
689 case R_PARISC_LTOFF_TP16F
:
690 case R_PARISC_LTOFF_TP16WF
:
691 case R_PARISC_LTOFF_TP16DF
:
692 need_entry
= NEED_DLT
;
695 /* These are function calls. Depending on their precise target we
696 may need to make a stub for them. The stub uses the PLT, so we
697 need to create PLT entries for these symbols too. */
698 case R_PARISC_PCREL12F
:
699 case R_PARISC_PCREL17F
:
700 case R_PARISC_PCREL22F
:
701 case R_PARISC_PCREL32
:
702 case R_PARISC_PCREL64
:
703 case R_PARISC_PCREL21L
:
704 case R_PARISC_PCREL17R
:
705 case R_PARISC_PCREL17C
:
706 case R_PARISC_PCREL14R
:
707 case R_PARISC_PCREL14F
:
708 case R_PARISC_PCREL22C
:
709 case R_PARISC_PCREL14WR
:
710 case R_PARISC_PCREL14DR
:
711 case R_PARISC_PCREL16F
:
712 case R_PARISC_PCREL16WF
:
713 case R_PARISC_PCREL16DF
:
714 /* Function calls might need to go through the .plt, and
715 might need a long branch stub. */
716 if (hh
!= NULL
&& hh
->eh
.type
!= STT_PARISC_MILLI
)
717 need_entry
= (NEED_PLT
| NEED_STUB
);
722 case R_PARISC_PLTOFF21L
:
723 case R_PARISC_PLTOFF14R
:
724 case R_PARISC_PLTOFF14F
:
725 case R_PARISC_PLTOFF14WR
:
726 case R_PARISC_PLTOFF14DR
:
727 case R_PARISC_PLTOFF16F
:
728 case R_PARISC_PLTOFF16WF
:
729 case R_PARISC_PLTOFF16DF
:
730 need_entry
= (NEED_PLT
);
734 if (info
->shared
|| maybe_dynamic
)
735 need_entry
= (NEED_DYNREL
);
736 dynrel_type
= R_PARISC_DIR64
;
739 /* This is an indirect reference through the DLT to get the address
740 of a OPD descriptor. Thus we need to make a DLT entry that points
742 case R_PARISC_LTOFF_FPTR21L
:
743 case R_PARISC_LTOFF_FPTR14R
:
744 case R_PARISC_LTOFF_FPTR14WR
:
745 case R_PARISC_LTOFF_FPTR14DR
:
746 case R_PARISC_LTOFF_FPTR32
:
747 case R_PARISC_LTOFF_FPTR64
:
748 case R_PARISC_LTOFF_FPTR16F
:
749 case R_PARISC_LTOFF_FPTR16WF
:
750 case R_PARISC_LTOFF_FPTR16DF
:
751 if (info
->shared
|| maybe_dynamic
)
752 need_entry
= (NEED_DLT
| NEED_OPD
| NEED_PLT
);
754 need_entry
= (NEED_DLT
| NEED_OPD
| NEED_PLT
);
755 dynrel_type
= R_PARISC_FPTR64
;
758 /* This is a simple OPD entry. */
759 case R_PARISC_FPTR64
:
760 if (info
->shared
|| maybe_dynamic
)
761 need_entry
= (NEED_OPD
| NEED_PLT
| NEED_DYNREL
);
763 need_entry
= (NEED_OPD
| NEED_PLT
);
764 dynrel_type
= R_PARISC_FPTR64
;
767 /* Add more cases as needed. */
775 /* Stash away enough information to be able to find this symbol
776 regardless of whether or not it is local or global. */
778 hh
->sym_indx
= r_symndx
;
781 /* Create what's needed. */
782 if (need_entry
& NEED_DLT
)
784 /* Allocate space for a DLT entry, as well as a dynamic
785 relocation for this entry. */
786 if (! hppa_info
->dlt_sec
787 && ! get_dlt (abfd
, info
, hppa_info
))
793 hh
->eh
.got
.refcount
+= 1;
797 bfd_signed_vma
*local_dlt_refcounts
;
799 /* This is a DLT entry for a local symbol. */
800 local_dlt_refcounts
= hppa64_elf_local_refcounts (abfd
);
801 if (local_dlt_refcounts
== NULL
)
803 local_dlt_refcounts
[r_symndx
] += 1;
807 if (need_entry
& NEED_PLT
)
809 if (! hppa_info
->plt_sec
810 && ! get_plt (abfd
, info
, hppa_info
))
816 hh
->eh
.needs_plt
= 1;
817 hh
->eh
.plt
.refcount
+= 1;
821 bfd_signed_vma
*local_dlt_refcounts
;
822 bfd_signed_vma
*local_plt_refcounts
;
824 /* This is a PLT entry for a local symbol. */
825 local_dlt_refcounts
= hppa64_elf_local_refcounts (abfd
);
826 if (local_dlt_refcounts
== NULL
)
828 local_plt_refcounts
= local_dlt_refcounts
+ symtab_hdr
->sh_info
;
829 local_plt_refcounts
[r_symndx
] += 1;
833 if (need_entry
& NEED_STUB
)
835 if (! hppa_info
->stub_sec
836 && ! get_stub (abfd
, info
, hppa_info
))
842 if (need_entry
& NEED_OPD
)
844 if (! hppa_info
->opd_sec
845 && ! get_opd (abfd
, info
, hppa_info
))
848 /* FPTRs are not allocated by the dynamic linker for PA64,
849 though it is possible that will change in the future. */
855 bfd_signed_vma
*local_dlt_refcounts
;
856 bfd_signed_vma
*local_opd_refcounts
;
858 /* This is a OPD for a local symbol. */
859 local_dlt_refcounts
= hppa64_elf_local_refcounts (abfd
);
860 if (local_dlt_refcounts
== NULL
)
862 local_opd_refcounts
= (local_dlt_refcounts
863 + 2 * symtab_hdr
->sh_info
);
864 local_opd_refcounts
[r_symndx
] += 1;
868 /* Add a new dynamic relocation to the chain of dynamic
869 relocations for this symbol. */
870 if ((need_entry
& NEED_DYNREL
) && (sec
->flags
& SEC_ALLOC
))
872 if (! hppa_info
->other_rel_sec
873 && ! get_reloc_section (abfd
, hppa_info
, sec
))
876 /* Count dynamic relocations against global symbols. */
878 && !count_dyn_reloc (abfd
, hh
, dynrel_type
, sec
,
879 sec_symndx
, rel
->r_offset
, rel
->r_addend
))
882 /* If we are building a shared library and we just recorded
883 a dynamic R_PARISC_FPTR64 relocation, then make sure the
884 section symbol for this section ends up in the dynamic
886 if (info
->shared
&& dynrel_type
== R_PARISC_FPTR64
887 && ! (bfd_elf_link_record_local_dynamic_symbol
888 (info
, abfd
, sec_symndx
)))
899 struct elf64_hppa_allocate_data
901 struct bfd_link_info
*info
;
905 /* Should we do dynamic things to this symbol? */
908 elf64_hppa_dynamic_symbol_p (struct elf_link_hash_entry
*eh
,
909 struct bfd_link_info
*info
)
911 /* ??? What, if anything, needs to happen wrt STV_PROTECTED symbols
912 and relocations that retrieve a function descriptor? Assume the
914 if (_bfd_elf_dynamic_symbol_p (eh
, info
, 1))
916 /* ??? Why is this here and not elsewhere is_local_label_name. */
917 if (eh
->root
.root
.string
[0] == '$' && eh
->root
.root
.string
[1] == '$')
926 /* Mark all functions exported by this file so that we can later allocate
927 entries in .opd for them. */
930 elf64_hppa_mark_exported_functions (struct elf_link_hash_entry
*eh
, void *data
)
932 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
933 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
934 struct elf64_hppa_link_hash_table
*hppa_info
;
936 hppa_info
= hppa_link_hash_table (info
);
937 if (hppa_info
== NULL
)
940 if (eh
->root
.type
== bfd_link_hash_warning
)
941 eh
= (struct elf_link_hash_entry
*) eh
->root
.u
.i
.link
;
944 && (eh
->root
.type
== bfd_link_hash_defined
945 || eh
->root
.type
== bfd_link_hash_defweak
)
946 && eh
->root
.u
.def
.section
->output_section
!= NULL
947 && eh
->type
== STT_FUNC
)
949 if (! hppa_info
->opd_sec
950 && ! get_opd (hppa_info
->root
.dynobj
, info
, hppa_info
))
955 /* Put a flag here for output_symbol_hook. */
963 /* Allocate space for a DLT entry. */
966 allocate_global_data_dlt (struct elf_link_hash_entry
*eh
, void *data
)
968 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
969 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
975 /* Possibly add the symbol to the local dynamic symbol
976 table since we might need to create a dynamic relocation
978 if (eh
->dynindx
== -1 && eh
->type
!= STT_PARISC_MILLI
)
980 bfd
*owner
= eh
->root
.u
.def
.section
->owner
;
982 if (! (bfd_elf_link_record_local_dynamic_symbol
983 (x
->info
, owner
, hh
->sym_indx
)))
988 hh
->dlt_offset
= x
->ofs
;
989 x
->ofs
+= DLT_ENTRY_SIZE
;
994 /* Allocate space for a DLT.PLT entry. */
997 allocate_global_data_plt (struct elf_link_hash_entry
*eh
, void *data
)
999 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
1000 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*) data
;
1003 && elf64_hppa_dynamic_symbol_p (eh
, x
->info
)
1004 && !((eh
->root
.type
== bfd_link_hash_defined
1005 || eh
->root
.type
== bfd_link_hash_defweak
)
1006 && eh
->root
.u
.def
.section
->output_section
!= NULL
))
1008 hh
->plt_offset
= x
->ofs
;
1009 x
->ofs
+= PLT_ENTRY_SIZE
;
1010 if (hh
->plt_offset
< 0x2000)
1012 struct elf64_hppa_link_hash_table
*hppa_info
;
1014 hppa_info
= hppa_link_hash_table (x
->info
);
1015 if (hppa_info
== NULL
)
1018 hppa_info
->gp_offset
= hh
->plt_offset
;
1027 /* Allocate space for a STUB entry. */
1030 allocate_global_data_stub (struct elf_link_hash_entry
*eh
, void *data
)
1032 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
1033 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1036 && elf64_hppa_dynamic_symbol_p (eh
, x
->info
)
1037 && !((eh
->root
.type
== bfd_link_hash_defined
1038 || eh
->root
.type
== bfd_link_hash_defweak
)
1039 && eh
->root
.u
.def
.section
->output_section
!= NULL
))
1041 hh
->stub_offset
= x
->ofs
;
1042 x
->ofs
+= sizeof (plt_stub
);
1049 /* Allocate space for a FPTR entry. */
1052 allocate_global_data_opd (struct elf_link_hash_entry
*eh
, void *data
)
1054 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
1055 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1057 if (hh
&& hh
->want_opd
)
1059 while (hh
->eh
.root
.type
== bfd_link_hash_indirect
1060 || hh
->eh
.root
.type
== bfd_link_hash_warning
)
1061 hh
= hppa_elf_hash_entry (hh
->eh
.root
.u
.i
.link
);
1063 /* We never need an opd entry for a symbol which is not
1064 defined by this output file. */
1065 if (hh
&& (hh
->eh
.root
.type
== bfd_link_hash_undefined
1066 || hh
->eh
.root
.type
== bfd_link_hash_undefweak
1067 || hh
->eh
.root
.u
.def
.section
->output_section
== NULL
))
1070 /* If we are creating a shared library, took the address of a local
1071 function or might export this function from this object file, then
1072 we have to create an opd descriptor. */
1073 else if (x
->info
->shared
1075 || (hh
->eh
.dynindx
== -1 && hh
->eh
.type
!= STT_PARISC_MILLI
)
1076 || (hh
->eh
.root
.type
== bfd_link_hash_defined
1077 || hh
->eh
.root
.type
== bfd_link_hash_defweak
))
1079 /* If we are creating a shared library, then we will have to
1080 create a runtime relocation for the symbol to properly
1081 initialize the .opd entry. Make sure the symbol gets
1082 added to the dynamic symbol table. */
1084 && (hh
== NULL
|| (hh
->eh
.dynindx
== -1)))
1087 /* PR 6511: Default to using the dynamic symbol table. */
1088 owner
= (hh
->owner
? hh
->owner
: eh
->root
.u
.def
.section
->owner
);
1090 if (!bfd_elf_link_record_local_dynamic_symbol
1091 (x
->info
, owner
, hh
->sym_indx
))
1095 /* This may not be necessary or desirable anymore now that
1096 we have some support for dealing with section symbols
1097 in dynamic relocs. But name munging does make the result
1098 much easier to debug. ie, the EPLT reloc will reference
1099 a symbol like .foobar, instead of .text + offset. */
1100 if (x
->info
->shared
&& eh
)
1103 struct elf_link_hash_entry
*nh
;
1105 new_name
= alloca (strlen (eh
->root
.root
.string
) + 2);
1107 strcpy (new_name
+ 1, eh
->root
.root
.string
);
1109 nh
= elf_link_hash_lookup (elf_hash_table (x
->info
),
1110 new_name
, TRUE
, TRUE
, TRUE
);
1112 nh
->root
.type
= eh
->root
.type
;
1113 nh
->root
.u
.def
.value
= eh
->root
.u
.def
.value
;
1114 nh
->root
.u
.def
.section
= eh
->root
.u
.def
.section
;
1116 if (! bfd_elf_link_record_dynamic_symbol (x
->info
, nh
))
1120 hh
->opd_offset
= x
->ofs
;
1121 x
->ofs
+= OPD_ENTRY_SIZE
;
1124 /* Otherwise we do not need an opd entry. */
1131 /* HP requires the EI_OSABI field to be filled in. The assignment to
1132 EI_ABIVERSION may not be strictly necessary. */
1135 elf64_hppa_post_process_headers (bfd
*abfd
,
1136 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
)
1138 Elf_Internal_Ehdr
* i_ehdrp
;
1140 i_ehdrp
= elf_elfheader (abfd
);
1142 i_ehdrp
->e_ident
[EI_OSABI
] = get_elf_backend_data (abfd
)->elf_osabi
;
1143 i_ehdrp
->e_ident
[EI_ABIVERSION
] = 1;
1146 /* Create function descriptor section (.opd). This section is called .opd
1147 because it contains "official procedure descriptors". The "official"
1148 refers to the fact that these descriptors are used when taking the address
1149 of a procedure, thus ensuring a unique address for each procedure. */
1153 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1154 struct elf64_hppa_link_hash_table
*hppa_info
)
1159 opd
= hppa_info
->opd_sec
;
1162 dynobj
= hppa_info
->root
.dynobj
;
1164 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1166 opd
= bfd_make_section_with_flags (dynobj
, ".opd",
1171 | SEC_LINKER_CREATED
));
1173 || !bfd_set_section_alignment (abfd
, opd
, 3))
1179 hppa_info
->opd_sec
= opd
;
1185 /* Create the PLT section. */
1189 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1190 struct elf64_hppa_link_hash_table
*hppa_info
)
1195 plt
= hppa_info
->plt_sec
;
1198 dynobj
= hppa_info
->root
.dynobj
;
1200 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1202 plt
= bfd_make_section_with_flags (dynobj
, ".plt",
1207 | SEC_LINKER_CREATED
));
1209 || !bfd_set_section_alignment (abfd
, plt
, 3))
1215 hppa_info
->plt_sec
= plt
;
1221 /* Create the DLT section. */
1225 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1226 struct elf64_hppa_link_hash_table
*hppa_info
)
1231 dlt
= hppa_info
->dlt_sec
;
1234 dynobj
= hppa_info
->root
.dynobj
;
1236 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1238 dlt
= bfd_make_section_with_flags (dynobj
, ".dlt",
1243 | SEC_LINKER_CREATED
));
1245 || !bfd_set_section_alignment (abfd
, dlt
, 3))
1251 hppa_info
->dlt_sec
= dlt
;
1257 /* Create the stubs section. */
1260 get_stub (bfd
*abfd
,
1261 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1262 struct elf64_hppa_link_hash_table
*hppa_info
)
1267 stub
= hppa_info
->stub_sec
;
1270 dynobj
= hppa_info
->root
.dynobj
;
1272 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1274 stub
= bfd_make_section_with_flags (dynobj
, ".stub",
1275 (SEC_ALLOC
| SEC_LOAD
1279 | SEC_LINKER_CREATED
));
1281 || !bfd_set_section_alignment (abfd
, stub
, 3))
1287 hppa_info
->stub_sec
= stub
;
1293 /* Create sections necessary for dynamic linking. This is only a rough
1294 cut and will likely change as we learn more about the somewhat
1295 unusual dynamic linking scheme HP uses.
1298 Contains code to implement cross-space calls. The first time one
1299 of the stubs is used it will call into the dynamic linker, later
1300 calls will go straight to the target.
1302 The only stub we support right now looks like
1306 ldd OFFSET+8(%dp),%dp
1308 Other stubs may be needed in the future. We may want the remove
1309 the break/nop instruction. It is only used right now to keep the
1310 offset of a .plt entry and a .stub entry in sync.
1313 This is what most people call the .got. HP used a different name.
1317 Relocations for the DLT.
1320 Function pointers as address,gp pairs.
1323 Should contain dynamic IPLT (and EPLT?) relocations.
1329 EPLT relocations for symbols exported from shared libraries. */
1332 elf64_hppa_create_dynamic_sections (bfd
*abfd
,
1333 struct bfd_link_info
*info
)
1336 struct elf64_hppa_link_hash_table
*hppa_info
;
1338 hppa_info
= hppa_link_hash_table (info
);
1339 if (hppa_info
== NULL
)
1342 if (! get_stub (abfd
, info
, hppa_info
))
1345 if (! get_dlt (abfd
, info
, hppa_info
))
1348 if (! get_plt (abfd
, info
, hppa_info
))
1351 if (! get_opd (abfd
, info
, hppa_info
))
1354 s
= bfd_make_section_with_flags (abfd
, ".rela.dlt",
1355 (SEC_ALLOC
| SEC_LOAD
1359 | SEC_LINKER_CREATED
));
1361 || !bfd_set_section_alignment (abfd
, s
, 3))
1363 hppa_info
->dlt_rel_sec
= s
;
1365 s
= bfd_make_section_with_flags (abfd
, ".rela.plt",
1366 (SEC_ALLOC
| SEC_LOAD
1370 | SEC_LINKER_CREATED
));
1372 || !bfd_set_section_alignment (abfd
, s
, 3))
1374 hppa_info
->plt_rel_sec
= s
;
1376 s
= bfd_make_section_with_flags (abfd
, ".rela.data",
1377 (SEC_ALLOC
| SEC_LOAD
1381 | SEC_LINKER_CREATED
));
1383 || !bfd_set_section_alignment (abfd
, s
, 3))
1385 hppa_info
->other_rel_sec
= s
;
1387 s
= bfd_make_section_with_flags (abfd
, ".rela.opd",
1388 (SEC_ALLOC
| SEC_LOAD
1392 | SEC_LINKER_CREATED
));
1394 || !bfd_set_section_alignment (abfd
, s
, 3))
1396 hppa_info
->opd_rel_sec
= s
;
1401 /* Allocate dynamic relocations for those symbols that turned out
1405 allocate_dynrel_entries (struct elf_link_hash_entry
*eh
, void *data
)
1407 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
1408 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1409 struct elf64_hppa_link_hash_table
*hppa_info
;
1410 struct elf64_hppa_dyn_reloc_entry
*rent
;
1411 bfd_boolean dynamic_symbol
, shared
;
1413 hppa_info
= hppa_link_hash_table (x
->info
);
1414 if (hppa_info
== NULL
)
1417 dynamic_symbol
= elf64_hppa_dynamic_symbol_p (eh
, x
->info
);
1418 shared
= x
->info
->shared
;
1420 /* We may need to allocate relocations for a non-dynamic symbol
1421 when creating a shared library. */
1422 if (!dynamic_symbol
&& !shared
)
1425 /* Take care of the normal data relocations. */
1427 for (rent
= hh
->reloc_entries
; rent
; rent
= rent
->next
)
1429 /* Allocate one iff we are building a shared library, the relocation
1430 isn't a R_PARISC_FPTR64, or we don't want an opd entry. */
1431 if (!shared
&& rent
->type
== R_PARISC_FPTR64
&& hh
->want_opd
)
1434 hppa_info
->other_rel_sec
->size
+= sizeof (Elf64_External_Rela
);
1436 /* Make sure this symbol gets into the dynamic symbol table if it is
1437 not already recorded. ?!? This should not be in the loop since
1438 the symbol need only be added once. */
1439 if (eh
->dynindx
== -1 && eh
->type
!= STT_PARISC_MILLI
)
1440 if (!bfd_elf_link_record_local_dynamic_symbol
1441 (x
->info
, rent
->sec
->owner
, hh
->sym_indx
))
1445 /* Take care of the GOT and PLT relocations. */
1447 if ((dynamic_symbol
|| shared
) && hh
->want_dlt
)
1448 hppa_info
->dlt_rel_sec
->size
+= sizeof (Elf64_External_Rela
);
1450 /* If we are building a shared library, then every symbol that has an
1451 opd entry will need an EPLT relocation to relocate the symbol's address
1452 and __gp value based on the runtime load address. */
1453 if (shared
&& hh
->want_opd
)
1454 hppa_info
->opd_rel_sec
->size
+= sizeof (Elf64_External_Rela
);
1456 if (hh
->want_plt
&& dynamic_symbol
)
1458 bfd_size_type t
= 0;
1460 /* Dynamic symbols get one IPLT relocation. Local symbols in
1461 shared libraries get two REL relocations. Local symbols in
1462 main applications get nothing. */
1464 t
= sizeof (Elf64_External_Rela
);
1466 t
= 2 * sizeof (Elf64_External_Rela
);
1468 hppa_info
->plt_rel_sec
->size
+= t
;
1474 /* Adjust a symbol defined by a dynamic object and referenced by a
1478 elf64_hppa_adjust_dynamic_symbol (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1479 struct elf_link_hash_entry
*eh
)
1481 /* ??? Undefined symbols with PLT entries should be re-defined
1482 to be the PLT entry. */
1484 /* If this is a weak symbol, and there is a real definition, the
1485 processor independent code will have arranged for us to see the
1486 real definition first, and we can just use the same value. */
1487 if (eh
->u
.weakdef
!= NULL
)
1489 BFD_ASSERT (eh
->u
.weakdef
->root
.type
== bfd_link_hash_defined
1490 || eh
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
1491 eh
->root
.u
.def
.section
= eh
->u
.weakdef
->root
.u
.def
.section
;
1492 eh
->root
.u
.def
.value
= eh
->u
.weakdef
->root
.u
.def
.value
;
1496 /* If this is a reference to a symbol defined by a dynamic object which
1497 is not a function, we might allocate the symbol in our .dynbss section
1498 and allocate a COPY dynamic relocation.
1500 But PA64 code is canonically PIC, so as a rule we can avoid this sort
1506 /* This function is called via elf_link_hash_traverse to mark millicode
1507 symbols with a dynindx of -1 and to remove the string table reference
1508 from the dynamic symbol table. If the symbol is not a millicode symbol,
1509 elf64_hppa_mark_exported_functions is called. */
1512 elf64_hppa_mark_milli_and_exported_functions (struct elf_link_hash_entry
*eh
,
1515 struct elf_link_hash_entry
*elf
= eh
;
1516 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
1518 if (elf
->root
.type
== bfd_link_hash_warning
)
1519 elf
= (struct elf_link_hash_entry
*) elf
->root
.u
.i
.link
;
1521 if (elf
->type
== STT_PARISC_MILLI
)
1523 if (elf
->dynindx
!= -1)
1526 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
1532 return elf64_hppa_mark_exported_functions (eh
, data
);
1535 /* Set the final sizes of the dynamic sections and allocate memory for
1536 the contents of our special sections. */
1539 elf64_hppa_size_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
1541 struct elf64_hppa_link_hash_table
*hppa_info
;
1542 struct elf64_hppa_allocate_data data
;
1548 bfd_boolean reltext
;
1550 hppa_info
= hppa_link_hash_table (info
);
1551 if (hppa_info
== NULL
)
1554 dynobj
= elf_hash_table (info
)->dynobj
;
1555 BFD_ASSERT (dynobj
!= NULL
);
1557 /* Mark each function this program exports so that we will allocate
1558 space in the .opd section for each function's FPTR. If we are
1559 creating dynamic sections, change the dynamic index of millicode
1560 symbols to -1 and remove them from the string table for .dynstr.
1562 We have to traverse the main linker hash table since we have to
1563 find functions which may not have been mentioned in any relocs. */
1564 elf_link_hash_traverse (elf_hash_table (info
),
1565 (elf_hash_table (info
)->dynamic_sections_created
1566 ? elf64_hppa_mark_milli_and_exported_functions
1567 : elf64_hppa_mark_exported_functions
),
1570 if (elf_hash_table (info
)->dynamic_sections_created
)
1572 /* Set the contents of the .interp section to the interpreter. */
1573 if (info
->executable
)
1575 sec
= bfd_get_section_by_name (dynobj
, ".interp");
1576 BFD_ASSERT (sec
!= NULL
);
1577 sec
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1578 sec
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1583 /* We may have created entries in the .rela.got section.
1584 However, if we are not creating the dynamic sections, we will
1585 not actually use these entries. Reset the size of .rela.dlt,
1586 which will cause it to get stripped from the output file
1588 sec
= bfd_get_section_by_name (dynobj
, ".rela.dlt");
1593 /* Set up DLT, PLT and OPD offsets for local syms, and space for local
1595 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
1597 bfd_signed_vma
*local_dlt
;
1598 bfd_signed_vma
*end_local_dlt
;
1599 bfd_signed_vma
*local_plt
;
1600 bfd_signed_vma
*end_local_plt
;
1601 bfd_signed_vma
*local_opd
;
1602 bfd_signed_vma
*end_local_opd
;
1603 bfd_size_type locsymcount
;
1604 Elf_Internal_Shdr
*symtab_hdr
;
1607 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
1610 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1612 struct elf64_hppa_dyn_reloc_entry
*hdh_p
;
1614 for (hdh_p
= ((struct elf64_hppa_dyn_reloc_entry
*)
1615 elf_section_data (sec
)->local_dynrel
);
1617 hdh_p
= hdh_p
->next
)
1619 if (!bfd_is_abs_section (hdh_p
->sec
)
1620 && bfd_is_abs_section (hdh_p
->sec
->output_section
))
1622 /* Input section has been discarded, either because
1623 it is a copy of a linkonce section or due to
1624 linker script /DISCARD/, so we'll be discarding
1627 else if (hdh_p
->count
!= 0)
1629 srel
= elf_section_data (hdh_p
->sec
)->sreloc
;
1630 srel
->size
+= hdh_p
->count
* sizeof (Elf64_External_Rela
);
1631 if ((hdh_p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
1632 info
->flags
|= DF_TEXTREL
;
1637 local_dlt
= elf_local_got_refcounts (ibfd
);
1641 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
1642 locsymcount
= symtab_hdr
->sh_info
;
1643 end_local_dlt
= local_dlt
+ locsymcount
;
1644 sec
= hppa_info
->dlt_sec
;
1645 srel
= hppa_info
->dlt_rel_sec
;
1646 for (; local_dlt
< end_local_dlt
; ++local_dlt
)
1650 *local_dlt
= sec
->size
;
1651 sec
->size
+= DLT_ENTRY_SIZE
;
1654 srel
->size
+= sizeof (Elf64_External_Rela
);
1658 *local_dlt
= (bfd_vma
) -1;
1661 local_plt
= end_local_dlt
;
1662 end_local_plt
= local_plt
+ locsymcount
;
1663 if (! hppa_info
->root
.dynamic_sections_created
)
1665 /* Won't be used, but be safe. */
1666 for (; local_plt
< end_local_plt
; ++local_plt
)
1667 *local_plt
= (bfd_vma
) -1;
1671 sec
= hppa_info
->plt_sec
;
1672 srel
= hppa_info
->plt_rel_sec
;
1673 for (; local_plt
< end_local_plt
; ++local_plt
)
1677 *local_plt
= sec
->size
;
1678 sec
->size
+= PLT_ENTRY_SIZE
;
1680 srel
->size
+= sizeof (Elf64_External_Rela
);
1683 *local_plt
= (bfd_vma
) -1;
1687 local_opd
= end_local_plt
;
1688 end_local_opd
= local_opd
+ locsymcount
;
1689 if (! hppa_info
->root
.dynamic_sections_created
)
1691 /* Won't be used, but be safe. */
1692 for (; local_opd
< end_local_opd
; ++local_opd
)
1693 *local_opd
= (bfd_vma
) -1;
1697 sec
= hppa_info
->opd_sec
;
1698 srel
= hppa_info
->opd_rel_sec
;
1699 for (; local_opd
< end_local_opd
; ++local_opd
)
1703 *local_opd
= sec
->size
;
1704 sec
->size
+= OPD_ENTRY_SIZE
;
1706 srel
->size
+= sizeof (Elf64_External_Rela
);
1709 *local_opd
= (bfd_vma
) -1;
1714 /* Allocate the GOT entries. */
1717 if (hppa_info
->dlt_sec
)
1719 data
.ofs
= hppa_info
->dlt_sec
->size
;
1720 elf_link_hash_traverse (elf_hash_table (info
),
1721 allocate_global_data_dlt
, &data
);
1722 hppa_info
->dlt_sec
->size
= data
.ofs
;
1725 if (hppa_info
->plt_sec
)
1727 data
.ofs
= hppa_info
->plt_sec
->size
;
1728 elf_link_hash_traverse (elf_hash_table (info
),
1729 allocate_global_data_plt
, &data
);
1730 hppa_info
->plt_sec
->size
= data
.ofs
;
1733 if (hppa_info
->stub_sec
)
1736 elf_link_hash_traverse (elf_hash_table (info
),
1737 allocate_global_data_stub
, &data
);
1738 hppa_info
->stub_sec
->size
= data
.ofs
;
1741 /* Allocate space for entries in the .opd section. */
1742 if (hppa_info
->opd_sec
)
1744 data
.ofs
= hppa_info
->opd_sec
->size
;
1745 elf_link_hash_traverse (elf_hash_table (info
),
1746 allocate_global_data_opd
, &data
);
1747 hppa_info
->opd_sec
->size
= data
.ofs
;
1750 /* Now allocate space for dynamic relocations, if necessary. */
1751 if (hppa_info
->root
.dynamic_sections_created
)
1752 elf_link_hash_traverse (elf_hash_table (info
),
1753 allocate_dynrel_entries
, &data
);
1755 /* The sizes of all the sections are set. Allocate memory for them. */
1759 for (sec
= dynobj
->sections
; sec
!= NULL
; sec
= sec
->next
)
1763 if ((sec
->flags
& SEC_LINKER_CREATED
) == 0)
1766 /* It's OK to base decisions on the section name, because none
1767 of the dynobj section names depend upon the input files. */
1768 name
= bfd_get_section_name (dynobj
, sec
);
1770 if (strcmp (name
, ".plt") == 0)
1772 /* Remember whether there is a PLT. */
1773 plt
= sec
->size
!= 0;
1775 else if (strcmp (name
, ".opd") == 0
1776 || CONST_STRNEQ (name
, ".dlt")
1777 || strcmp (name
, ".stub") == 0
1778 || strcmp (name
, ".got") == 0)
1780 /* Strip this section if we don't need it; see the comment below. */
1782 else if (CONST_STRNEQ (name
, ".rela"))
1788 /* Remember whether there are any reloc sections other
1790 if (strcmp (name
, ".rela.plt") != 0)
1792 const char *outname
;
1796 /* If this relocation section applies to a read only
1797 section, then we probably need a DT_TEXTREL
1798 entry. The entries in the .rela.plt section
1799 really apply to the .got section, which we
1800 created ourselves and so know is not readonly. */
1801 outname
= bfd_get_section_name (output_bfd
,
1802 sec
->output_section
);
1803 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
1805 && (target
->flags
& SEC_READONLY
) != 0
1806 && (target
->flags
& SEC_ALLOC
) != 0)
1810 /* We use the reloc_count field as a counter if we need
1811 to copy relocs into the output file. */
1812 sec
->reloc_count
= 0;
1817 /* It's not one of our sections, so don't allocate space. */
1823 /* If we don't need this section, strip it from the
1824 output file. This is mostly to handle .rela.bss and
1825 .rela.plt. We must create both sections in
1826 create_dynamic_sections, because they must be created
1827 before the linker maps input sections to output
1828 sections. The linker does that before
1829 adjust_dynamic_symbol is called, and it is that
1830 function which decides whether anything needs to go
1831 into these sections. */
1832 sec
->flags
|= SEC_EXCLUDE
;
1836 if ((sec
->flags
& SEC_HAS_CONTENTS
) == 0)
1839 /* Allocate memory for the section contents if it has not
1840 been allocated already. We use bfd_zalloc here in case
1841 unused entries are not reclaimed before the section's
1842 contents are written out. This should not happen, but this
1843 way if it does, we get a R_PARISC_NONE reloc instead of
1845 if (sec
->contents
== NULL
)
1847 sec
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, sec
->size
);
1848 if (sec
->contents
== NULL
)
1853 if (elf_hash_table (info
)->dynamic_sections_created
)
1855 /* Always create a DT_PLTGOT. It actually has nothing to do with
1856 the PLT, it is how we communicate the __gp value of a load
1857 module to the dynamic linker. */
1858 #define add_dynamic_entry(TAG, VAL) \
1859 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
1861 if (!add_dynamic_entry (DT_HP_DLD_FLAGS
, 0)
1862 || !add_dynamic_entry (DT_PLTGOT
, 0))
1865 /* Add some entries to the .dynamic section. We fill in the
1866 values later, in elf64_hppa_finish_dynamic_sections, but we
1867 must add the entries now so that we get the correct size for
1868 the .dynamic section. The DT_DEBUG entry is filled in by the
1869 dynamic linker and used by the debugger. */
1872 if (!add_dynamic_entry (DT_DEBUG
, 0)
1873 || !add_dynamic_entry (DT_HP_DLD_HOOK
, 0)
1874 || !add_dynamic_entry (DT_HP_LOAD_MAP
, 0))
1878 /* Force DT_FLAGS to always be set.
1879 Required by HPUX 11.00 patch PHSS_26559. */
1880 if (!add_dynamic_entry (DT_FLAGS
, (info
)->flags
))
1885 if (!add_dynamic_entry (DT_PLTRELSZ
, 0)
1886 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
1887 || !add_dynamic_entry (DT_JMPREL
, 0))
1893 if (!add_dynamic_entry (DT_RELA
, 0)
1894 || !add_dynamic_entry (DT_RELASZ
, 0)
1895 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
1901 if (!add_dynamic_entry (DT_TEXTREL
, 0))
1903 info
->flags
|= DF_TEXTREL
;
1906 #undef add_dynamic_entry
1911 /* Called after we have output the symbol into the dynamic symbol
1912 table, but before we output the symbol into the normal symbol
1915 For some symbols we had to change their address when outputting
1916 the dynamic symbol table. We undo that change here so that
1917 the symbols have their expected value in the normal symbol
1921 elf64_hppa_link_output_symbol_hook (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1923 Elf_Internal_Sym
*sym
,
1924 asection
*input_sec ATTRIBUTE_UNUSED
,
1925 struct elf_link_hash_entry
*eh
)
1927 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
1929 /* We may be called with the file symbol or section symbols.
1930 They never need munging, so it is safe to ignore them. */
1934 /* Function symbols for which we created .opd entries *may* have been
1935 munged by finish_dynamic_symbol and have to be un-munged here.
1937 Note that finish_dynamic_symbol sometimes turns dynamic symbols
1938 into non-dynamic ones, so we initialize st_shndx to -1 in
1939 mark_exported_functions and check to see if it was overwritten
1940 here instead of just checking eh->dynindx. */
1941 if (hh
->want_opd
&& hh
->st_shndx
!= -1)
1943 /* Restore the saved value and section index. */
1944 sym
->st_value
= hh
->st_value
;
1945 sym
->st_shndx
= hh
->st_shndx
;
1951 /* Finish up dynamic symbol handling. We set the contents of various
1952 dynamic sections here. */
1955 elf64_hppa_finish_dynamic_symbol (bfd
*output_bfd
,
1956 struct bfd_link_info
*info
,
1957 struct elf_link_hash_entry
*eh
,
1958 Elf_Internal_Sym
*sym
)
1960 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
1961 asection
*stub
, *splt
, *sopd
, *spltrel
;
1962 struct elf64_hppa_link_hash_table
*hppa_info
;
1964 hppa_info
= hppa_link_hash_table (info
);
1965 if (hppa_info
== NULL
)
1968 stub
= hppa_info
->stub_sec
;
1969 splt
= hppa_info
->plt_sec
;
1970 sopd
= hppa_info
->opd_sec
;
1971 spltrel
= hppa_info
->plt_rel_sec
;
1973 /* Incredible. It is actually necessary to NOT use the symbol's real
1974 value when building the dynamic symbol table for a shared library.
1975 At least for symbols that refer to functions.
1977 We will store a new value and section index into the symbol long
1978 enough to output it into the dynamic symbol table, then we restore
1979 the original values (in elf64_hppa_link_output_symbol_hook). */
1982 BFD_ASSERT (sopd
!= NULL
);
1984 /* Save away the original value and section index so that we
1985 can restore them later. */
1986 hh
->st_value
= sym
->st_value
;
1987 hh
->st_shndx
= sym
->st_shndx
;
1989 /* For the dynamic symbol table entry, we want the value to be
1990 address of this symbol's entry within the .opd section. */
1991 sym
->st_value
= (hh
->opd_offset
1992 + sopd
->output_offset
1993 + sopd
->output_section
->vma
);
1994 sym
->st_shndx
= _bfd_elf_section_from_bfd_section (output_bfd
,
1995 sopd
->output_section
);
1998 /* Initialize a .plt entry if requested. */
2000 && elf64_hppa_dynamic_symbol_p (eh
, info
))
2003 Elf_Internal_Rela rel
;
2006 BFD_ASSERT (splt
!= NULL
&& spltrel
!= NULL
);
2008 /* We do not actually care about the value in the PLT entry
2009 if we are creating a shared library and the symbol is
2010 still undefined, we create a dynamic relocation to fill
2011 in the correct value. */
2012 if (info
->shared
&& eh
->root
.type
== bfd_link_hash_undefined
)
2015 value
= (eh
->root
.u
.def
.value
+ eh
->root
.u
.def
.section
->vma
);
2017 /* Fill in the entry in the procedure linkage table.
2019 The format of a plt entry is
2022 plt_offset is the offset within the PLT section at which to
2023 install the PLT entry.
2025 We are modifying the in-memory PLT contents here, so we do not add
2026 in the output_offset of the PLT section. */
2028 bfd_put_64 (splt
->owner
, value
, splt
->contents
+ hh
->plt_offset
);
2029 value
= _bfd_get_gp_value (splt
->output_section
->owner
);
2030 bfd_put_64 (splt
->owner
, value
, splt
->contents
+ hh
->plt_offset
+ 0x8);
2032 /* Create a dynamic IPLT relocation for this entry.
2034 We are creating a relocation in the output file's PLT section,
2035 which is included within the DLT secton. So we do need to include
2036 the PLT's output_offset in the computation of the relocation's
2038 rel
.r_offset
= (hh
->plt_offset
+ splt
->output_offset
2039 + splt
->output_section
->vma
);
2040 rel
.r_info
= ELF64_R_INFO (hh
->eh
.dynindx
, R_PARISC_IPLT
);
2043 loc
= spltrel
->contents
;
2044 loc
+= spltrel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2045 bfd_elf64_swap_reloca_out (splt
->output_section
->owner
, &rel
, loc
);
2048 /* Initialize an external call stub entry if requested. */
2050 && elf64_hppa_dynamic_symbol_p (eh
, info
))
2054 unsigned int max_offset
;
2056 BFD_ASSERT (stub
!= NULL
);
2058 /* Install the generic stub template.
2060 We are modifying the contents of the stub section, so we do not
2061 need to include the stub section's output_offset here. */
2062 memcpy (stub
->contents
+ hh
->stub_offset
, plt_stub
, sizeof (plt_stub
));
2064 /* Fix up the first ldd instruction.
2066 We are modifying the contents of the STUB section in memory,
2067 so we do not need to include its output offset in this computation.
2069 Note the plt_offset value is the value of the PLT entry relative to
2070 the start of the PLT section. These instructions will reference
2071 data relative to the value of __gp, which may not necessarily have
2072 the same address as the start of the PLT section.
2074 gp_offset contains the offset of __gp within the PLT section. */
2075 value
= hh
->plt_offset
- hppa_info
->gp_offset
;
2077 insn
= bfd_get_32 (stub
->owner
, stub
->contents
+ hh
->stub_offset
);
2078 if (output_bfd
->arch_info
->mach
>= 25)
2080 /* Wide mode allows 16 bit offsets. */
2083 insn
|= re_assemble_16 ((int) value
);
2089 insn
|= re_assemble_14 ((int) value
);
2092 if ((value
& 7) || value
+ max_offset
>= 2*max_offset
- 8)
2094 (*_bfd_error_handler
) (_("stub entry for %s cannot load .plt, dp offset = %ld"),
2095 hh
->eh
.root
.root
.string
,
2100 bfd_put_32 (stub
->owner
, (bfd_vma
) insn
,
2101 stub
->contents
+ hh
->stub_offset
);
2103 /* Fix up the second ldd instruction. */
2105 insn
= bfd_get_32 (stub
->owner
, stub
->contents
+ hh
->stub_offset
+ 8);
2106 if (output_bfd
->arch_info
->mach
>= 25)
2109 insn
|= re_assemble_16 ((int) value
);
2114 insn
|= re_assemble_14 ((int) value
);
2116 bfd_put_32 (stub
->owner
, (bfd_vma
) insn
,
2117 stub
->contents
+ hh
->stub_offset
+ 8);
2123 /* The .opd section contains FPTRs for each function this file
2124 exports. Initialize the FPTR entries. */
2127 elf64_hppa_finalize_opd (struct elf_link_hash_entry
*eh
, void *data
)
2129 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
2130 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
2131 struct elf64_hppa_link_hash_table
*hppa_info
;
2135 hppa_info
= hppa_link_hash_table (info
);
2136 if (hppa_info
== NULL
)
2139 sopd
= hppa_info
->opd_sec
;
2140 sopdrel
= hppa_info
->opd_rel_sec
;
2146 /* The first two words of an .opd entry are zero.
2148 We are modifying the contents of the OPD section in memory, so we
2149 do not need to include its output offset in this computation. */
2150 memset (sopd
->contents
+ hh
->opd_offset
, 0, 16);
2152 value
= (eh
->root
.u
.def
.value
2153 + eh
->root
.u
.def
.section
->output_section
->vma
2154 + eh
->root
.u
.def
.section
->output_offset
);
2156 /* The next word is the address of the function. */
2157 bfd_put_64 (sopd
->owner
, value
, sopd
->contents
+ hh
->opd_offset
+ 16);
2159 /* The last word is our local __gp value. */
2160 value
= _bfd_get_gp_value (sopd
->output_section
->owner
);
2161 bfd_put_64 (sopd
->owner
, value
, sopd
->contents
+ hh
->opd_offset
+ 24);
2164 /* If we are generating a shared library, we must generate EPLT relocations
2165 for each entry in the .opd, even for static functions (they may have
2166 had their address taken). */
2167 if (info
->shared
&& hh
->want_opd
)
2169 Elf_Internal_Rela rel
;
2173 /* We may need to do a relocation against a local symbol, in
2174 which case we have to look up it's dynamic symbol index off
2175 the local symbol hash table. */
2176 if (eh
->dynindx
!= -1)
2177 dynindx
= eh
->dynindx
;
2180 = _bfd_elf_link_lookup_local_dynindx (info
, hh
->owner
,
2183 /* The offset of this relocation is the absolute address of the
2184 .opd entry for this symbol. */
2185 rel
.r_offset
= (hh
->opd_offset
+ sopd
->output_offset
2186 + sopd
->output_section
->vma
);
2188 /* If H is non-null, then we have an external symbol.
2190 It is imperative that we use a different dynamic symbol for the
2191 EPLT relocation if the symbol has global scope.
2193 In the dynamic symbol table, the function symbol will have a value
2194 which is address of the function's .opd entry.
2196 Thus, we can not use that dynamic symbol for the EPLT relocation
2197 (if we did, the data in the .opd would reference itself rather
2198 than the actual address of the function). Instead we have to use
2199 a new dynamic symbol which has the same value as the original global
2202 We prefix the original symbol with a "." and use the new symbol in
2203 the EPLT relocation. This new symbol has already been recorded in
2204 the symbol table, we just have to look it up and use it.
2206 We do not have such problems with static functions because we do
2207 not make their addresses in the dynamic symbol table point to
2208 the .opd entry. Ultimately this should be safe since a static
2209 function can not be directly referenced outside of its shared
2212 We do have to play similar games for FPTR relocations in shared
2213 libraries, including those for static symbols. See the FPTR
2214 handling in elf64_hppa_finalize_dynreloc. */
2218 struct elf_link_hash_entry
*nh
;
2220 new_name
= alloca (strlen (eh
->root
.root
.string
) + 2);
2222 strcpy (new_name
+ 1, eh
->root
.root
.string
);
2224 nh
= elf_link_hash_lookup (elf_hash_table (info
),
2225 new_name
, TRUE
, TRUE
, FALSE
);
2227 /* All we really want from the new symbol is its dynamic
2230 dynindx
= nh
->dynindx
;
2234 rel
.r_info
= ELF64_R_INFO (dynindx
, R_PARISC_EPLT
);
2236 loc
= sopdrel
->contents
;
2237 loc
+= sopdrel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2238 bfd_elf64_swap_reloca_out (sopd
->output_section
->owner
, &rel
, loc
);
2243 /* The .dlt section contains addresses for items referenced through the
2244 dlt. Note that we can have a DLTIND relocation for a local symbol, thus
2245 we can not depend on finish_dynamic_symbol to initialize the .dlt. */
2248 elf64_hppa_finalize_dlt (struct elf_link_hash_entry
*eh
, void *data
)
2250 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
2251 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
2252 struct elf64_hppa_link_hash_table
*hppa_info
;
2253 asection
*sdlt
, *sdltrel
;
2255 hppa_info
= hppa_link_hash_table (info
);
2256 if (hppa_info
== NULL
)
2259 sdlt
= hppa_info
->dlt_sec
;
2260 sdltrel
= hppa_info
->dlt_rel_sec
;
2262 /* H/DYN_H may refer to a local variable and we know it's
2263 address, so there is no need to create a relocation. Just install
2264 the proper value into the DLT, note this shortcut can not be
2265 skipped when building a shared library. */
2266 if (! info
->shared
&& hh
&& hh
->want_dlt
)
2270 /* If we had an LTOFF_FPTR style relocation we want the DLT entry
2271 to point to the FPTR entry in the .opd section.
2273 We include the OPD's output offset in this computation as
2274 we are referring to an absolute address in the resulting
2278 value
= (hh
->opd_offset
2279 + hppa_info
->opd_sec
->output_offset
2280 + hppa_info
->opd_sec
->output_section
->vma
);
2282 else if ((eh
->root
.type
== bfd_link_hash_defined
2283 || eh
->root
.type
== bfd_link_hash_defweak
)
2284 && eh
->root
.u
.def
.section
)
2286 value
= eh
->root
.u
.def
.value
+ eh
->root
.u
.def
.section
->output_offset
;
2287 if (eh
->root
.u
.def
.section
->output_section
)
2288 value
+= eh
->root
.u
.def
.section
->output_section
->vma
;
2290 value
+= eh
->root
.u
.def
.section
->vma
;
2293 /* We have an undefined function reference. */
2296 /* We do not need to include the output offset of the DLT section
2297 here because we are modifying the in-memory contents. */
2298 bfd_put_64 (sdlt
->owner
, value
, sdlt
->contents
+ hh
->dlt_offset
);
2301 /* Create a relocation for the DLT entry associated with this symbol.
2302 When building a shared library the symbol does not have to be dynamic. */
2304 && (elf64_hppa_dynamic_symbol_p (eh
, info
) || info
->shared
))
2306 Elf_Internal_Rela rel
;
2310 /* We may need to do a relocation against a local symbol, in
2311 which case we have to look up it's dynamic symbol index off
2312 the local symbol hash table. */
2313 if (eh
&& eh
->dynindx
!= -1)
2314 dynindx
= eh
->dynindx
;
2317 = _bfd_elf_link_lookup_local_dynindx (info
, hh
->owner
,
2320 /* Create a dynamic relocation for this entry. Do include the output
2321 offset of the DLT entry since we need an absolute address in the
2322 resulting object file. */
2323 rel
.r_offset
= (hh
->dlt_offset
+ sdlt
->output_offset
2324 + sdlt
->output_section
->vma
);
2325 if (eh
&& eh
->type
== STT_FUNC
)
2326 rel
.r_info
= ELF64_R_INFO (dynindx
, R_PARISC_FPTR64
);
2328 rel
.r_info
= ELF64_R_INFO (dynindx
, R_PARISC_DIR64
);
2331 loc
= sdltrel
->contents
;
2332 loc
+= sdltrel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2333 bfd_elf64_swap_reloca_out (sdlt
->output_section
->owner
, &rel
, loc
);
2338 /* Finalize the dynamic relocations. Specifically the FPTR relocations
2339 for dynamic functions used to initialize static data. */
2342 elf64_hppa_finalize_dynreloc (struct elf_link_hash_entry
*eh
,
2345 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
2346 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
2347 struct elf64_hppa_link_hash_table
*hppa_info
;
2350 dynamic_symbol
= elf64_hppa_dynamic_symbol_p (eh
, info
);
2352 if (!dynamic_symbol
&& !info
->shared
)
2355 if (hh
->reloc_entries
)
2357 struct elf64_hppa_dyn_reloc_entry
*rent
;
2360 hppa_info
= hppa_link_hash_table (info
);
2361 if (hppa_info
== NULL
)
2364 /* We may need to do a relocation against a local symbol, in
2365 which case we have to look up it's dynamic symbol index off
2366 the local symbol hash table. */
2367 if (eh
->dynindx
!= -1)
2368 dynindx
= eh
->dynindx
;
2371 = _bfd_elf_link_lookup_local_dynindx (info
, hh
->owner
,
2374 for (rent
= hh
->reloc_entries
; rent
; rent
= rent
->next
)
2376 Elf_Internal_Rela rel
;
2379 /* Allocate one iff we are building a shared library, the relocation
2380 isn't a R_PARISC_FPTR64, or we don't want an opd entry. */
2381 if (!info
->shared
&& rent
->type
== R_PARISC_FPTR64
&& hh
->want_opd
)
2384 /* Create a dynamic relocation for this entry.
2386 We need the output offset for the reloc's section because
2387 we are creating an absolute address in the resulting object
2389 rel
.r_offset
= (rent
->offset
+ rent
->sec
->output_offset
2390 + rent
->sec
->output_section
->vma
);
2392 /* An FPTR64 relocation implies that we took the address of
2393 a function and that the function has an entry in the .opd
2394 section. We want the FPTR64 relocation to reference the
2397 We could munge the symbol value in the dynamic symbol table
2398 (in fact we already do for functions with global scope) to point
2399 to the .opd entry. Then we could use that dynamic symbol in
2402 Or we could do something sensible, not munge the symbol's
2403 address and instead just use a different symbol to reference
2404 the .opd entry. At least that seems sensible until you
2405 realize there's no local dynamic symbols we can use for that
2406 purpose. Thus the hair in the check_relocs routine.
2408 We use a section symbol recorded by check_relocs as the
2409 base symbol for the relocation. The addend is the difference
2410 between the section symbol and the address of the .opd entry. */
2411 if (info
->shared
&& rent
->type
== R_PARISC_FPTR64
&& hh
->want_opd
)
2413 bfd_vma value
, value2
;
2415 /* First compute the address of the opd entry for this symbol. */
2416 value
= (hh
->opd_offset
2417 + hppa_info
->opd_sec
->output_section
->vma
2418 + hppa_info
->opd_sec
->output_offset
);
2420 /* Compute the value of the start of the section with
2422 value2
= (rent
->sec
->output_section
->vma
2423 + rent
->sec
->output_offset
);
2425 /* Compute the difference between the start of the section
2426 with the relocation and the opd entry. */
2429 /* The result becomes the addend of the relocation. */
2430 rel
.r_addend
= value
;
2432 /* The section symbol becomes the symbol for the dynamic
2435 = _bfd_elf_link_lookup_local_dynindx (info
,
2440 rel
.r_addend
= rent
->addend
;
2442 rel
.r_info
= ELF64_R_INFO (dynindx
, rent
->type
);
2444 loc
= hppa_info
->other_rel_sec
->contents
;
2445 loc
+= (hppa_info
->other_rel_sec
->reloc_count
++
2446 * sizeof (Elf64_External_Rela
));
2447 bfd_elf64_swap_reloca_out (hppa_info
->other_rel_sec
->output_section
->owner
,
2455 /* Used to decide how to sort relocs in an optimal manner for the
2456 dynamic linker, before writing them out. */
2458 static enum elf_reloc_type_class
2459 elf64_hppa_reloc_type_class (const Elf_Internal_Rela
*rela
)
2461 if (ELF64_R_SYM (rela
->r_info
) == STN_UNDEF
)
2462 return reloc_class_relative
;
2464 switch ((int) ELF64_R_TYPE (rela
->r_info
))
2467 return reloc_class_plt
;
2469 return reloc_class_copy
;
2471 return reloc_class_normal
;
2475 /* Finish up the dynamic sections. */
2478 elf64_hppa_finish_dynamic_sections (bfd
*output_bfd
,
2479 struct bfd_link_info
*info
)
2483 struct elf64_hppa_link_hash_table
*hppa_info
;
2485 hppa_info
= hppa_link_hash_table (info
);
2486 if (hppa_info
== NULL
)
2489 /* Finalize the contents of the .opd section. */
2490 elf_link_hash_traverse (elf_hash_table (info
),
2491 elf64_hppa_finalize_opd
,
2494 elf_link_hash_traverse (elf_hash_table (info
),
2495 elf64_hppa_finalize_dynreloc
,
2498 /* Finalize the contents of the .dlt section. */
2499 dynobj
= elf_hash_table (info
)->dynobj
;
2500 /* Finalize the contents of the .dlt section. */
2501 elf_link_hash_traverse (elf_hash_table (info
),
2502 elf64_hppa_finalize_dlt
,
2505 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2507 if (elf_hash_table (info
)->dynamic_sections_created
)
2509 Elf64_External_Dyn
*dyncon
, *dynconend
;
2511 BFD_ASSERT (sdyn
!= NULL
);
2513 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
2514 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
2515 for (; dyncon
< dynconend
; dyncon
++)
2517 Elf_Internal_Dyn dyn
;
2520 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2527 case DT_HP_LOAD_MAP
:
2528 /* Compute the absolute address of 16byte scratchpad area
2529 for the dynamic linker.
2531 By convention the linker script will allocate the scratchpad
2532 area at the start of the .data section. So all we have to
2533 to is find the start of the .data section. */
2534 s
= bfd_get_section_by_name (output_bfd
, ".data");
2535 dyn
.d_un
.d_ptr
= s
->vma
;
2536 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2540 /* HP's use PLTGOT to set the GOT register. */
2541 dyn
.d_un
.d_ptr
= _bfd_get_gp_value (output_bfd
);
2542 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2546 s
= hppa_info
->plt_rel_sec
;
2547 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
2548 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2552 s
= hppa_info
->plt_rel_sec
;
2553 dyn
.d_un
.d_val
= s
->size
;
2554 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2558 s
= hppa_info
->other_rel_sec
;
2559 if (! s
|| ! s
->size
)
2560 s
= hppa_info
->dlt_rel_sec
;
2561 if (! s
|| ! s
->size
)
2562 s
= hppa_info
->opd_rel_sec
;
2563 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
2564 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2568 s
= hppa_info
->other_rel_sec
;
2569 dyn
.d_un
.d_val
= s
->size
;
2570 s
= hppa_info
->dlt_rel_sec
;
2571 dyn
.d_un
.d_val
+= s
->size
;
2572 s
= hppa_info
->opd_rel_sec
;
2573 dyn
.d_un
.d_val
+= s
->size
;
2574 /* There is some question about whether or not the size of
2575 the PLT relocs should be included here. HP's tools do
2576 it, so we'll emulate them. */
2577 s
= hppa_info
->plt_rel_sec
;
2578 dyn
.d_un
.d_val
+= s
->size
;
2579 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2589 /* Support for core dump NOTE sections. */
2592 elf64_hppa_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
2597 switch (note
->descsz
)
2602 case 760: /* Linux/hppa */
2604 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
2607 elf_tdata (abfd
)->core_lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
2616 /* Make a ".reg/999" section. */
2617 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
2618 size
, note
->descpos
+ offset
);
2622 elf64_hppa_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
2627 switch (note
->descsz
)
2632 case 136: /* Linux/hppa elf_prpsinfo. */
2633 elf_tdata (abfd
)->core_program
2634 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
2635 elf_tdata (abfd
)->core_command
2636 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
2639 /* Note that for some reason, a spurious space is tacked
2640 onto the end of the args in some (at least one anyway)
2641 implementations, so strip it off if it exists. */
2642 command
= elf_tdata (abfd
)->core_command
;
2643 n
= strlen (command
);
2645 if (0 < n
&& command
[n
- 1] == ' ')
2646 command
[n
- 1] = '\0';
2651 /* Return the number of additional phdrs we will need.
2653 The generic ELF code only creates PT_PHDRs for executables. The HP
2654 dynamic linker requires PT_PHDRs for dynamic libraries too.
2656 This routine indicates that the backend needs one additional program
2657 header for that case.
2659 Note we do not have access to the link info structure here, so we have
2660 to guess whether or not we are building a shared library based on the
2661 existence of a .interp section. */
2664 elf64_hppa_additional_program_headers (bfd
*abfd
,
2665 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2669 /* If we are creating a shared library, then we have to create a
2670 PT_PHDR segment. HP's dynamic linker chokes without it. */
2671 s
= bfd_get_section_by_name (abfd
, ".interp");
2677 /* Allocate and initialize any program headers required by this
2680 The generic ELF code only creates PT_PHDRs for executables. The HP
2681 dynamic linker requires PT_PHDRs for dynamic libraries too.
2683 This allocates the PT_PHDR and initializes it in a manner suitable
2686 Note we do not have access to the link info structure here, so we have
2687 to guess whether or not we are building a shared library based on the
2688 existence of a .interp section. */
2691 elf64_hppa_modify_segment_map (bfd
*abfd
,
2692 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2694 struct elf_segment_map
*m
;
2697 s
= bfd_get_section_by_name (abfd
, ".interp");
2700 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2701 if (m
->p_type
== PT_PHDR
)
2705 m
= ((struct elf_segment_map
*)
2706 bfd_zalloc (abfd
, (bfd_size_type
) sizeof *m
));
2710 m
->p_type
= PT_PHDR
;
2711 m
->p_flags
= PF_R
| PF_X
;
2712 m
->p_flags_valid
= 1;
2713 m
->p_paddr_valid
= 1;
2714 m
->includes_phdrs
= 1;
2716 m
->next
= elf_tdata (abfd
)->segment_map
;
2717 elf_tdata (abfd
)->segment_map
= m
;
2721 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2722 if (m
->p_type
== PT_LOAD
)
2726 for (i
= 0; i
< m
->count
; i
++)
2728 /* The code "hint" is not really a hint. It is a requirement
2729 for certain versions of the HP dynamic linker. Worse yet,
2730 it must be set even if the shared library does not have
2731 any code in its "text" segment (thus the check for .hash
2732 to catch this situation). */
2733 if (m
->sections
[i
]->flags
& SEC_CODE
2734 || (strcmp (m
->sections
[i
]->name
, ".hash") == 0))
2735 m
->p_flags
|= (PF_X
| PF_HP_CODE
);
2742 /* Called when writing out an object file to decide the type of a
2745 elf64_hppa_elf_get_symbol_type (Elf_Internal_Sym
*elf_sym
,
2748 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_PARISC_MILLI
)
2749 return STT_PARISC_MILLI
;
2754 /* Support HP specific sections for core files. */
2757 elf64_hppa_section_from_phdr (bfd
*abfd
, Elf_Internal_Phdr
*hdr
, int sec_index
,
2758 const char *typename
)
2760 if (hdr
->p_type
== PT_HP_CORE_KERNEL
)
2764 if (!_bfd_elf_make_section_from_phdr (abfd
, hdr
, sec_index
, typename
))
2767 sect
= bfd_make_section_anyway (abfd
, ".kernel");
2770 sect
->size
= hdr
->p_filesz
;
2771 sect
->filepos
= hdr
->p_offset
;
2772 sect
->flags
= SEC_HAS_CONTENTS
| SEC_READONLY
;
2776 if (hdr
->p_type
== PT_HP_CORE_PROC
)
2780 if (bfd_seek (abfd
, hdr
->p_offset
, SEEK_SET
) != 0)
2782 if (bfd_bread (&sig
, 4, abfd
) != 4)
2785 elf_tdata (abfd
)->core_signal
= sig
;
2787 if (!_bfd_elf_make_section_from_phdr (abfd
, hdr
, sec_index
, typename
))
2790 /* GDB uses the ".reg" section to read register contents. */
2791 return _bfd_elfcore_make_pseudosection (abfd
, ".reg", hdr
->p_filesz
,
2795 if (hdr
->p_type
== PT_HP_CORE_LOADABLE
2796 || hdr
->p_type
== PT_HP_CORE_STACK
2797 || hdr
->p_type
== PT_HP_CORE_MMF
)
2798 hdr
->p_type
= PT_LOAD
;
2800 return _bfd_elf_make_section_from_phdr (abfd
, hdr
, sec_index
, typename
);
2803 /* Hook called by the linker routine which adds symbols from an object
2804 file. HP's libraries define symbols with HP specific section
2805 indices, which we have to handle. */
2808 elf_hppa_add_symbol_hook (bfd
*abfd
,
2809 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2810 Elf_Internal_Sym
*sym
,
2811 const char **namep ATTRIBUTE_UNUSED
,
2812 flagword
*flagsp ATTRIBUTE_UNUSED
,
2816 unsigned int sec_index
= sym
->st_shndx
;
2820 case SHN_PARISC_ANSI_COMMON
:
2821 *secp
= bfd_make_section_old_way (abfd
, ".PARISC.ansi.common");
2822 (*secp
)->flags
|= SEC_IS_COMMON
;
2823 *valp
= sym
->st_size
;
2826 case SHN_PARISC_HUGE_COMMON
:
2827 *secp
= bfd_make_section_old_way (abfd
, ".PARISC.huge.common");
2828 (*secp
)->flags
|= SEC_IS_COMMON
;
2829 *valp
= sym
->st_size
;
2837 elf_hppa_unmark_useless_dynamic_symbols (struct elf_link_hash_entry
*h
,
2840 struct bfd_link_info
*info
= data
;
2842 if (h
->root
.type
== bfd_link_hash_warning
)
2843 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2845 /* If we are not creating a shared library, and this symbol is
2846 referenced by a shared library but is not defined anywhere, then
2847 the generic code will warn that it is undefined.
2849 This behavior is undesirable on HPs since the standard shared
2850 libraries contain references to undefined symbols.
2852 So we twiddle the flags associated with such symbols so that they
2853 will not trigger the warning. ?!? FIXME. This is horribly fragile.
2855 Ultimately we should have better controls over the generic ELF BFD
2857 if (! info
->relocatable
2858 && info
->unresolved_syms_in_shared_libs
!= RM_IGNORE
2859 && h
->root
.type
== bfd_link_hash_undefined
2864 h
->pointer_equality_needed
= 1;
2871 elf_hppa_remark_useless_dynamic_symbols (struct elf_link_hash_entry
*h
,
2874 struct bfd_link_info
*info
= data
;
2876 if (h
->root
.type
== bfd_link_hash_warning
)
2877 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2879 /* If we are not creating a shared library, and this symbol is
2880 referenced by a shared library but is not defined anywhere, then
2881 the generic code will warn that it is undefined.
2883 This behavior is undesirable on HPs since the standard shared
2884 libraries contain references to undefined symbols.
2886 So we twiddle the flags associated with such symbols so that they
2887 will not trigger the warning. ?!? FIXME. This is horribly fragile.
2889 Ultimately we should have better controls over the generic ELF BFD
2891 if (! info
->relocatable
2892 && info
->unresolved_syms_in_shared_libs
!= RM_IGNORE
2893 && h
->root
.type
== bfd_link_hash_undefined
2896 && h
->pointer_equality_needed
)
2899 h
->pointer_equality_needed
= 0;
2906 elf_hppa_is_dynamic_loader_symbol (const char *name
)
2908 return (! strcmp (name
, "__CPU_REVISION")
2909 || ! strcmp (name
, "__CPU_KEYBITS_1")
2910 || ! strcmp (name
, "__SYSTEM_ID_D")
2911 || ! strcmp (name
, "__FPU_MODEL")
2912 || ! strcmp (name
, "__FPU_REVISION")
2913 || ! strcmp (name
, "__ARGC")
2914 || ! strcmp (name
, "__ARGV")
2915 || ! strcmp (name
, "__ENVP")
2916 || ! strcmp (name
, "__TLS_SIZE_D")
2917 || ! strcmp (name
, "__LOAD_INFO")
2918 || ! strcmp (name
, "__systab"));
2921 /* Record the lowest address for the data and text segments. */
2923 elf_hppa_record_segment_addrs (bfd
*abfd
,
2927 struct elf64_hppa_link_hash_table
*hppa_info
= data
;
2929 if ((section
->flags
& (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
2932 Elf_Internal_Phdr
*p
;
2934 p
= _bfd_elf_find_segment_containing_section (abfd
, section
->output_section
);
2935 BFD_ASSERT (p
!= NULL
);
2938 if (section
->flags
& SEC_READONLY
)
2940 if (value
< hppa_info
->text_segment_base
)
2941 hppa_info
->text_segment_base
= value
;
2945 if (value
< hppa_info
->data_segment_base
)
2946 hppa_info
->data_segment_base
= value
;
2951 /* Called after we have seen all the input files/sections, but before
2952 final symbol resolution and section placement has been determined.
2954 We use this hook to (possibly) provide a value for __gp, then we
2955 fall back to the generic ELF final link routine. */
2958 elf_hppa_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
2961 struct elf64_hppa_link_hash_table
*hppa_info
= hppa_link_hash_table (info
);
2963 if (hppa_info
== NULL
)
2966 if (! info
->relocatable
)
2968 struct elf_link_hash_entry
*gp
;
2971 /* The linker script defines a value for __gp iff it was referenced
2972 by one of the objects being linked. First try to find the symbol
2973 in the hash table. If that fails, just compute the value __gp
2975 gp
= elf_link_hash_lookup (elf_hash_table (info
), "__gp", FALSE
,
2981 /* Adjust the value of __gp as we may want to slide it into the
2982 .plt section so that the stubs can access PLT entries without
2983 using an addil sequence. */
2984 gp
->root
.u
.def
.value
+= hppa_info
->gp_offset
;
2986 gp_val
= (gp
->root
.u
.def
.section
->output_section
->vma
2987 + gp
->root
.u
.def
.section
->output_offset
2988 + gp
->root
.u
.def
.value
);
2994 /* First look for a .plt section. If found, then __gp is the
2995 address of the .plt + gp_offset.
2997 If no .plt is found, then look for .dlt, .opd and .data (in
2998 that order) and set __gp to the base address of whichever
2999 section is found first. */
3001 sec
= hppa_info
->plt_sec
;
3002 if (sec
&& ! (sec
->flags
& SEC_EXCLUDE
))
3003 gp_val
= (sec
->output_offset
3004 + sec
->output_section
->vma
3005 + hppa_info
->gp_offset
);
3008 sec
= hppa_info
->dlt_sec
;
3009 if (!sec
|| (sec
->flags
& SEC_EXCLUDE
))
3010 sec
= hppa_info
->opd_sec
;
3011 if (!sec
|| (sec
->flags
& SEC_EXCLUDE
))
3012 sec
= bfd_get_section_by_name (abfd
, ".data");
3013 if (!sec
|| (sec
->flags
& SEC_EXCLUDE
))
3016 gp_val
= sec
->output_offset
+ sec
->output_section
->vma
;
3020 /* Install whatever value we found/computed for __gp. */
3021 _bfd_set_gp_value (abfd
, gp_val
);
3024 /* We need to know the base of the text and data segments so that we
3025 can perform SEGREL relocations. We will record the base addresses
3026 when we encounter the first SEGREL relocation. */
3027 hppa_info
->text_segment_base
= (bfd_vma
)-1;
3028 hppa_info
->data_segment_base
= (bfd_vma
)-1;
3030 /* HP's shared libraries have references to symbols that are not
3031 defined anywhere. The generic ELF BFD linker code will complain
3034 So we detect the losing case and arrange for the flags on the symbol
3035 to indicate that it was never referenced. This keeps the generic
3036 ELF BFD link code happy and appears to not create any secondary
3037 problems. Ultimately we need a way to control the behavior of the
3038 generic ELF BFD link code better. */
3039 elf_link_hash_traverse (elf_hash_table (info
),
3040 elf_hppa_unmark_useless_dynamic_symbols
,
3043 /* Invoke the regular ELF backend linker to do all the work. */
3044 retval
= bfd_elf_final_link (abfd
, info
);
3046 elf_link_hash_traverse (elf_hash_table (info
),
3047 elf_hppa_remark_useless_dynamic_symbols
,
3050 /* If we're producing a final executable, sort the contents of the
3052 if (retval
&& !info
->relocatable
)
3053 retval
= elf_hppa_sort_unwind (abfd
);
3058 /* Relocate the given INSN. VALUE should be the actual value we want
3059 to insert into the instruction, ie by this point we should not be
3060 concerned with computing an offset relative to the DLT, PC, etc.
3061 Instead this routine is meant to handle the bit manipulations needed
3062 to insert the relocation into the given instruction. */
3065 elf_hppa_relocate_insn (int insn
, int sym_value
, unsigned int r_type
)
3069 /* This is any 22 bit branch. In PA2.0 syntax it corresponds to
3070 the "B" instruction. */
3071 case R_PARISC_PCREL22F
:
3072 case R_PARISC_PCREL22C
:
3073 return (insn
& ~0x3ff1ffd) | re_assemble_22 (sym_value
);
3075 /* This is any 12 bit branch. */
3076 case R_PARISC_PCREL12F
:
3077 return (insn
& ~0x1ffd) | re_assemble_12 (sym_value
);
3079 /* This is any 17 bit branch. In PA2.0 syntax it also corresponds
3080 to the "B" instruction as well as BE. */
3081 case R_PARISC_PCREL17F
:
3082 case R_PARISC_DIR17F
:
3083 case R_PARISC_DIR17R
:
3084 case R_PARISC_PCREL17C
:
3085 case R_PARISC_PCREL17R
:
3086 return (insn
& ~0x1f1ffd) | re_assemble_17 (sym_value
);
3088 /* ADDIL or LDIL instructions. */
3089 case R_PARISC_DLTREL21L
:
3090 case R_PARISC_DLTIND21L
:
3091 case R_PARISC_LTOFF_FPTR21L
:
3092 case R_PARISC_PCREL21L
:
3093 case R_PARISC_LTOFF_TP21L
:
3094 case R_PARISC_DPREL21L
:
3095 case R_PARISC_PLTOFF21L
:
3096 case R_PARISC_DIR21L
:
3097 return (insn
& ~0x1fffff) | re_assemble_21 (sym_value
);
3099 /* LDO and integer loads/stores with 14 bit displacements. */
3100 case R_PARISC_DLTREL14R
:
3101 case R_PARISC_DLTREL14F
:
3102 case R_PARISC_DLTIND14R
:
3103 case R_PARISC_DLTIND14F
:
3104 case R_PARISC_LTOFF_FPTR14R
:
3105 case R_PARISC_PCREL14R
:
3106 case R_PARISC_PCREL14F
:
3107 case R_PARISC_LTOFF_TP14R
:
3108 case R_PARISC_LTOFF_TP14F
:
3109 case R_PARISC_DPREL14R
:
3110 case R_PARISC_DPREL14F
:
3111 case R_PARISC_PLTOFF14R
:
3112 case R_PARISC_PLTOFF14F
:
3113 case R_PARISC_DIR14R
:
3114 case R_PARISC_DIR14F
:
3115 return (insn
& ~0x3fff) | low_sign_unext (sym_value
, 14);
3117 /* PA2.0W LDO and integer loads/stores with 16 bit displacements. */
3118 case R_PARISC_LTOFF_FPTR16F
:
3119 case R_PARISC_PCREL16F
:
3120 case R_PARISC_LTOFF_TP16F
:
3121 case R_PARISC_GPREL16F
:
3122 case R_PARISC_PLTOFF16F
:
3123 case R_PARISC_DIR16F
:
3124 case R_PARISC_LTOFF16F
:
3125 return (insn
& ~0xffff) | re_assemble_16 (sym_value
);
3127 /* Doubleword loads and stores with a 14 bit displacement. */
3128 case R_PARISC_DLTREL14DR
:
3129 case R_PARISC_DLTIND14DR
:
3130 case R_PARISC_LTOFF_FPTR14DR
:
3131 case R_PARISC_LTOFF_FPTR16DF
:
3132 case R_PARISC_PCREL14DR
:
3133 case R_PARISC_PCREL16DF
:
3134 case R_PARISC_LTOFF_TP14DR
:
3135 case R_PARISC_LTOFF_TP16DF
:
3136 case R_PARISC_DPREL14DR
:
3137 case R_PARISC_GPREL16DF
:
3138 case R_PARISC_PLTOFF14DR
:
3139 case R_PARISC_PLTOFF16DF
:
3140 case R_PARISC_DIR14DR
:
3141 case R_PARISC_DIR16DF
:
3142 case R_PARISC_LTOFF16DF
:
3143 return (insn
& ~0x3ff1) | (((sym_value
& 0x2000) >> 13)
3144 | ((sym_value
& 0x1ff8) << 1));
3146 /* Floating point single word load/store instructions. */
3147 case R_PARISC_DLTREL14WR
:
3148 case R_PARISC_DLTIND14WR
:
3149 case R_PARISC_LTOFF_FPTR14WR
:
3150 case R_PARISC_LTOFF_FPTR16WF
:
3151 case R_PARISC_PCREL14WR
:
3152 case R_PARISC_PCREL16WF
:
3153 case R_PARISC_LTOFF_TP14WR
:
3154 case R_PARISC_LTOFF_TP16WF
:
3155 case R_PARISC_DPREL14WR
:
3156 case R_PARISC_GPREL16WF
:
3157 case R_PARISC_PLTOFF14WR
:
3158 case R_PARISC_PLTOFF16WF
:
3159 case R_PARISC_DIR16WF
:
3160 case R_PARISC_DIR14WR
:
3161 case R_PARISC_LTOFF16WF
:
3162 return (insn
& ~0x3ff9) | (((sym_value
& 0x2000) >> 13)
3163 | ((sym_value
& 0x1ffc) << 1));
3170 /* Compute the value for a relocation (REL) during a final link stage,
3171 then insert the value into the proper location in CONTENTS.
3173 VALUE is a tentative value for the relocation and may be overridden
3174 and modified here based on the specific relocation to be performed.
3176 For example we do conversions for PC-relative branches in this routine
3177 or redirection of calls to external routines to stubs.
3179 The work of actually applying the relocation is left to a helper
3180 routine in an attempt to reduce the complexity and size of this
3183 static bfd_reloc_status_type
3184 elf_hppa_final_link_relocate (Elf_Internal_Rela
*rel
,
3187 asection
*input_section
,
3190 struct bfd_link_info
*info
,
3192 struct elf_link_hash_entry
*eh
)
3194 struct elf64_hppa_link_hash_table
*hppa_info
= hppa_link_hash_table (info
);
3195 struct elf64_hppa_link_hash_entry
*hh
= hppa_elf_hash_entry (eh
);
3196 bfd_vma
*local_offsets
;
3197 Elf_Internal_Shdr
*symtab_hdr
;
3199 bfd_vma max_branch_offset
= 0;
3200 bfd_vma offset
= rel
->r_offset
;
3201 bfd_signed_vma addend
= rel
->r_addend
;
3202 reloc_howto_type
*howto
= elf_hppa_howto_table
+ ELF_R_TYPE (rel
->r_info
);
3203 unsigned int r_symndx
= ELF_R_SYM (rel
->r_info
);
3204 unsigned int r_type
= howto
->type
;
3205 bfd_byte
*hit_data
= contents
+ offset
;
3207 if (hppa_info
== NULL
)
3208 return bfd_reloc_notsupported
;
3210 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3211 local_offsets
= elf_local_got_offsets (input_bfd
);
3212 insn
= bfd_get_32 (input_bfd
, hit_data
);
3219 /* Basic function call support.
3221 Note for a call to a function defined in another dynamic library
3222 we want to redirect the call to a stub. */
3224 /* PC relative relocs without an implicit offset. */
3225 case R_PARISC_PCREL21L
:
3226 case R_PARISC_PCREL14R
:
3227 case R_PARISC_PCREL14F
:
3228 case R_PARISC_PCREL14WR
:
3229 case R_PARISC_PCREL14DR
:
3230 case R_PARISC_PCREL16F
:
3231 case R_PARISC_PCREL16WF
:
3232 case R_PARISC_PCREL16DF
:
3234 /* If this is a call to a function defined in another dynamic
3235 library, then redirect the call to the local stub for this
3237 if (sym_sec
== NULL
|| sym_sec
->output_section
== NULL
)
3238 value
= (hh
->stub_offset
+ hppa_info
->stub_sec
->output_offset
3239 + hppa_info
->stub_sec
->output_section
->vma
);
3241 /* Turn VALUE into a proper PC relative address. */
3242 value
-= (offset
+ input_section
->output_offset
3243 + input_section
->output_section
->vma
);
3245 /* Adjust for any field selectors. */
3246 if (r_type
== R_PARISC_PCREL21L
)
3247 value
= hppa_field_adjust (value
, -8 + addend
, e_lsel
);
3248 else if (r_type
== R_PARISC_PCREL14F
3249 || r_type
== R_PARISC_PCREL16F
3250 || r_type
== R_PARISC_PCREL16WF
3251 || r_type
== R_PARISC_PCREL16DF
)
3252 value
= hppa_field_adjust (value
, -8 + addend
, e_fsel
);
3254 value
= hppa_field_adjust (value
, -8 + addend
, e_rsel
);
3256 /* Apply the relocation to the given instruction. */
3257 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3261 case R_PARISC_PCREL12F
:
3262 case R_PARISC_PCREL22F
:
3263 case R_PARISC_PCREL17F
:
3264 case R_PARISC_PCREL22C
:
3265 case R_PARISC_PCREL17C
:
3266 case R_PARISC_PCREL17R
:
3268 /* If this is a call to a function defined in another dynamic
3269 library, then redirect the call to the local stub for this
3271 if (sym_sec
== NULL
|| sym_sec
->output_section
== NULL
)
3272 value
= (hh
->stub_offset
+ hppa_info
->stub_sec
->output_offset
3273 + hppa_info
->stub_sec
->output_section
->vma
);
3275 /* Turn VALUE into a proper PC relative address. */
3276 value
-= (offset
+ input_section
->output_offset
3277 + input_section
->output_section
->vma
);
3280 if (r_type
== (unsigned int) R_PARISC_PCREL22F
)
3281 max_branch_offset
= (1 << (22-1)) << 2;
3282 else if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
3283 max_branch_offset
= (1 << (17-1)) << 2;
3284 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
3285 max_branch_offset
= (1 << (12-1)) << 2;
3287 /* Make sure we can reach the branch target. */
3288 if (max_branch_offset
!= 0
3289 && value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3291 (*_bfd_error_handler
)
3292 (_("%B(%A+0x%lx): cannot reach %s"),
3296 eh
->root
.root
.string
);
3297 bfd_set_error (bfd_error_bad_value
);
3298 return bfd_reloc_notsupported
;
3301 /* Adjust for any field selectors. */
3302 if (r_type
== R_PARISC_PCREL17R
)
3303 value
= hppa_field_adjust (value
, addend
, e_rsel
);
3305 value
= hppa_field_adjust (value
, addend
, e_fsel
);
3307 /* All branches are implicitly shifted by 2 places. */
3310 /* Apply the relocation to the given instruction. */
3311 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3315 /* Indirect references to data through the DLT. */
3316 case R_PARISC_DLTIND14R
:
3317 case R_PARISC_DLTIND14F
:
3318 case R_PARISC_DLTIND14DR
:
3319 case R_PARISC_DLTIND14WR
:
3320 case R_PARISC_DLTIND21L
:
3321 case R_PARISC_LTOFF_FPTR14R
:
3322 case R_PARISC_LTOFF_FPTR14DR
:
3323 case R_PARISC_LTOFF_FPTR14WR
:
3324 case R_PARISC_LTOFF_FPTR21L
:
3325 case R_PARISC_LTOFF_FPTR16F
:
3326 case R_PARISC_LTOFF_FPTR16WF
:
3327 case R_PARISC_LTOFF_FPTR16DF
:
3328 case R_PARISC_LTOFF_TP21L
:
3329 case R_PARISC_LTOFF_TP14R
:
3330 case R_PARISC_LTOFF_TP14F
:
3331 case R_PARISC_LTOFF_TP14WR
:
3332 case R_PARISC_LTOFF_TP14DR
:
3333 case R_PARISC_LTOFF_TP16F
:
3334 case R_PARISC_LTOFF_TP16WF
:
3335 case R_PARISC_LTOFF_TP16DF
:
3336 case R_PARISC_LTOFF16F
:
3337 case R_PARISC_LTOFF16WF
:
3338 case R_PARISC_LTOFF16DF
:
3342 /* If this relocation was against a local symbol, then we still
3343 have not set up the DLT entry (it's not convenient to do so
3344 in the "finalize_dlt" routine because it is difficult to get
3345 to the local symbol's value).
3347 So, if this is a local symbol (h == NULL), then we need to
3348 fill in its DLT entry.
3350 Similarly we may still need to set up an entry in .opd for
3351 a local function which had its address taken. */
3354 bfd_vma
*local_opd_offsets
, *local_dlt_offsets
;
3356 if (local_offsets
== NULL
)
3359 /* Now do .opd creation if needed. */
3360 if (r_type
== R_PARISC_LTOFF_FPTR14R
3361 || r_type
== R_PARISC_LTOFF_FPTR14DR
3362 || r_type
== R_PARISC_LTOFF_FPTR14WR
3363 || r_type
== R_PARISC_LTOFF_FPTR21L
3364 || r_type
== R_PARISC_LTOFF_FPTR16F
3365 || r_type
== R_PARISC_LTOFF_FPTR16WF
3366 || r_type
== R_PARISC_LTOFF_FPTR16DF
)
3368 local_opd_offsets
= local_offsets
+ 2 * symtab_hdr
->sh_info
;
3369 off
= local_opd_offsets
[r_symndx
];
3371 /* The last bit records whether we've already initialised
3372 this local .opd entry. */
3375 BFD_ASSERT (off
!= (bfd_vma
) -1);
3380 local_opd_offsets
[r_symndx
] |= 1;
3382 /* The first two words of an .opd entry are zero. */
3383 memset (hppa_info
->opd_sec
->contents
+ off
, 0, 16);
3385 /* The next word is the address of the function. */
3386 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
+ addend
,
3387 (hppa_info
->opd_sec
->contents
+ off
+ 16));
3389 /* The last word is our local __gp value. */
3390 value
= _bfd_get_gp_value
3391 (hppa_info
->opd_sec
->output_section
->owner
);
3392 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
,
3393 (hppa_info
->opd_sec
->contents
+ off
+ 24));
3396 /* The DLT value is the address of the .opd entry. */
3398 + hppa_info
->opd_sec
->output_offset
3399 + hppa_info
->opd_sec
->output_section
->vma
);
3403 local_dlt_offsets
= local_offsets
;
3404 off
= local_dlt_offsets
[r_symndx
];
3408 BFD_ASSERT (off
!= (bfd_vma
) -1);
3413 local_dlt_offsets
[r_symndx
] |= 1;
3414 bfd_put_64 (hppa_info
->dlt_sec
->owner
,
3416 hppa_info
->dlt_sec
->contents
+ off
);
3420 off
= hh
->dlt_offset
;
3422 /* We want the value of the DLT offset for this symbol, not
3423 the symbol's actual address. Note that __gp may not point
3424 to the start of the DLT, so we have to compute the absolute
3425 address, then subtract out the value of __gp. */
3427 + hppa_info
->dlt_sec
->output_offset
3428 + hppa_info
->dlt_sec
->output_section
->vma
);
3429 value
-= _bfd_get_gp_value (output_bfd
);
3431 /* All DLTIND relocations are basically the same at this point,
3432 except that we need different field selectors for the 21bit
3433 version vs the 14bit versions. */
3434 if (r_type
== R_PARISC_DLTIND21L
3435 || r_type
== R_PARISC_LTOFF_FPTR21L
3436 || r_type
== R_PARISC_LTOFF_TP21L
)
3437 value
= hppa_field_adjust (value
, 0, e_lsel
);
3438 else if (r_type
== R_PARISC_DLTIND14F
3439 || r_type
== R_PARISC_LTOFF_FPTR16F
3440 || r_type
== R_PARISC_LTOFF_FPTR16WF
3441 || r_type
== R_PARISC_LTOFF_FPTR16DF
3442 || r_type
== R_PARISC_LTOFF16F
3443 || r_type
== R_PARISC_LTOFF16DF
3444 || r_type
== R_PARISC_LTOFF16WF
3445 || r_type
== R_PARISC_LTOFF_TP16F
3446 || r_type
== R_PARISC_LTOFF_TP16WF
3447 || r_type
== R_PARISC_LTOFF_TP16DF
)
3448 value
= hppa_field_adjust (value
, 0, e_fsel
);
3450 value
= hppa_field_adjust (value
, 0, e_rsel
);
3452 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3456 case R_PARISC_DLTREL14R
:
3457 case R_PARISC_DLTREL14F
:
3458 case R_PARISC_DLTREL14DR
:
3459 case R_PARISC_DLTREL14WR
:
3460 case R_PARISC_DLTREL21L
:
3461 case R_PARISC_DPREL21L
:
3462 case R_PARISC_DPREL14WR
:
3463 case R_PARISC_DPREL14DR
:
3464 case R_PARISC_DPREL14R
:
3465 case R_PARISC_DPREL14F
:
3466 case R_PARISC_GPREL16F
:
3467 case R_PARISC_GPREL16WF
:
3468 case R_PARISC_GPREL16DF
:
3470 /* Subtract out the global pointer value to make value a DLT
3471 relative address. */
3472 value
-= _bfd_get_gp_value (output_bfd
);
3474 /* All DLTREL relocations are basically the same at this point,
3475 except that we need different field selectors for the 21bit
3476 version vs the 14bit versions. */
3477 if (r_type
== R_PARISC_DLTREL21L
3478 || r_type
== R_PARISC_DPREL21L
)
3479 value
= hppa_field_adjust (value
, addend
, e_lrsel
);
3480 else if (r_type
== R_PARISC_DLTREL14F
3481 || r_type
== R_PARISC_DPREL14F
3482 || r_type
== R_PARISC_GPREL16F
3483 || r_type
== R_PARISC_GPREL16WF
3484 || r_type
== R_PARISC_GPREL16DF
)
3485 value
= hppa_field_adjust (value
, addend
, e_fsel
);
3487 value
= hppa_field_adjust (value
, addend
, e_rrsel
);
3489 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3493 case R_PARISC_DIR21L
:
3494 case R_PARISC_DIR17R
:
3495 case R_PARISC_DIR17F
:
3496 case R_PARISC_DIR14R
:
3497 case R_PARISC_DIR14F
:
3498 case R_PARISC_DIR14WR
:
3499 case R_PARISC_DIR14DR
:
3500 case R_PARISC_DIR16F
:
3501 case R_PARISC_DIR16WF
:
3502 case R_PARISC_DIR16DF
:
3504 /* All DIR relocations are basically the same at this point,
3505 except that branch offsets need to be divided by four, and
3506 we need different field selectors. Note that we don't
3507 redirect absolute calls to local stubs. */
3509 if (r_type
== R_PARISC_DIR21L
)
3510 value
= hppa_field_adjust (value
, addend
, e_lrsel
);
3511 else if (r_type
== R_PARISC_DIR17F
3512 || r_type
== R_PARISC_DIR16F
3513 || r_type
== R_PARISC_DIR16WF
3514 || r_type
== R_PARISC_DIR16DF
3515 || r_type
== R_PARISC_DIR14F
)
3516 value
= hppa_field_adjust (value
, addend
, e_fsel
);
3518 value
= hppa_field_adjust (value
, addend
, e_rrsel
);
3520 if (r_type
== R_PARISC_DIR17R
|| r_type
== R_PARISC_DIR17F
)
3521 /* All branches are implicitly shifted by 2 places. */
3524 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3528 case R_PARISC_PLTOFF21L
:
3529 case R_PARISC_PLTOFF14R
:
3530 case R_PARISC_PLTOFF14F
:
3531 case R_PARISC_PLTOFF14WR
:
3532 case R_PARISC_PLTOFF14DR
:
3533 case R_PARISC_PLTOFF16F
:
3534 case R_PARISC_PLTOFF16WF
:
3535 case R_PARISC_PLTOFF16DF
:
3537 /* We want the value of the PLT offset for this symbol, not
3538 the symbol's actual address. Note that __gp may not point
3539 to the start of the DLT, so we have to compute the absolute
3540 address, then subtract out the value of __gp. */
3541 value
= (hh
->plt_offset
3542 + hppa_info
->plt_sec
->output_offset
3543 + hppa_info
->plt_sec
->output_section
->vma
);
3544 value
-= _bfd_get_gp_value (output_bfd
);
3546 /* All PLTOFF relocations are basically the same at this point,
3547 except that we need different field selectors for the 21bit
3548 version vs the 14bit versions. */
3549 if (r_type
== R_PARISC_PLTOFF21L
)
3550 value
= hppa_field_adjust (value
, addend
, e_lrsel
);
3551 else if (r_type
== R_PARISC_PLTOFF14F
3552 || r_type
== R_PARISC_PLTOFF16F
3553 || r_type
== R_PARISC_PLTOFF16WF
3554 || r_type
== R_PARISC_PLTOFF16DF
)
3555 value
= hppa_field_adjust (value
, addend
, e_fsel
);
3557 value
= hppa_field_adjust (value
, addend
, e_rrsel
);
3559 insn
= elf_hppa_relocate_insn (insn
, (int) value
, r_type
);
3563 case R_PARISC_LTOFF_FPTR32
:
3565 /* We may still need to create the FPTR itself if it was for
3569 /* The first two words of an .opd entry are zero. */
3570 memset (hppa_info
->opd_sec
->contents
+ hh
->opd_offset
, 0, 16);
3572 /* The next word is the address of the function. */
3573 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
+ addend
,
3574 (hppa_info
->opd_sec
->contents
3575 + hh
->opd_offset
+ 16));
3577 /* The last word is our local __gp value. */
3578 value
= _bfd_get_gp_value
3579 (hppa_info
->opd_sec
->output_section
->owner
);
3580 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
,
3581 hppa_info
->opd_sec
->contents
+ hh
->opd_offset
+ 24);
3583 /* The DLT value is the address of the .opd entry. */
3584 value
= (hh
->opd_offset
3585 + hppa_info
->opd_sec
->output_offset
3586 + hppa_info
->opd_sec
->output_section
->vma
);
3588 bfd_put_64 (hppa_info
->dlt_sec
->owner
,
3590 hppa_info
->dlt_sec
->contents
+ hh
->dlt_offset
);
3593 /* We want the value of the DLT offset for this symbol, not
3594 the symbol's actual address. Note that __gp may not point
3595 to the start of the DLT, so we have to compute the absolute
3596 address, then subtract out the value of __gp. */
3597 value
= (hh
->dlt_offset
3598 + hppa_info
->dlt_sec
->output_offset
3599 + hppa_info
->dlt_sec
->output_section
->vma
);
3600 value
-= _bfd_get_gp_value (output_bfd
);
3601 bfd_put_32 (input_bfd
, value
, hit_data
);
3602 return bfd_reloc_ok
;
3605 case R_PARISC_LTOFF_FPTR64
:
3606 case R_PARISC_LTOFF_TP64
:
3608 /* We may still need to create the FPTR itself if it was for
3610 if (eh
== NULL
&& r_type
== R_PARISC_LTOFF_FPTR64
)
3612 /* The first two words of an .opd entry are zero. */
3613 memset (hppa_info
->opd_sec
->contents
+ hh
->opd_offset
, 0, 16);
3615 /* The next word is the address of the function. */
3616 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
+ addend
,
3617 (hppa_info
->opd_sec
->contents
3618 + hh
->opd_offset
+ 16));
3620 /* The last word is our local __gp value. */
3621 value
= _bfd_get_gp_value
3622 (hppa_info
->opd_sec
->output_section
->owner
);
3623 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
,
3624 hppa_info
->opd_sec
->contents
+ hh
->opd_offset
+ 24);
3626 /* The DLT value is the address of the .opd entry. */
3627 value
= (hh
->opd_offset
3628 + hppa_info
->opd_sec
->output_offset
3629 + hppa_info
->opd_sec
->output_section
->vma
);
3631 bfd_put_64 (hppa_info
->dlt_sec
->owner
,
3633 hppa_info
->dlt_sec
->contents
+ hh
->dlt_offset
);
3636 /* We want the value of the DLT offset for this symbol, not
3637 the symbol's actual address. Note that __gp may not point
3638 to the start of the DLT, so we have to compute the absolute
3639 address, then subtract out the value of __gp. */
3640 value
= (hh
->dlt_offset
3641 + hppa_info
->dlt_sec
->output_offset
3642 + hppa_info
->dlt_sec
->output_section
->vma
);
3643 value
-= _bfd_get_gp_value (output_bfd
);
3644 bfd_put_64 (input_bfd
, value
, hit_data
);
3645 return bfd_reloc_ok
;
3648 case R_PARISC_DIR32
:
3649 bfd_put_32 (input_bfd
, value
+ addend
, hit_data
);
3650 return bfd_reloc_ok
;
3652 case R_PARISC_DIR64
:
3653 bfd_put_64 (input_bfd
, value
+ addend
, hit_data
);
3654 return bfd_reloc_ok
;
3656 case R_PARISC_GPREL64
:
3657 /* Subtract out the global pointer value to make value a DLT
3658 relative address. */
3659 value
-= _bfd_get_gp_value (output_bfd
);
3661 bfd_put_64 (input_bfd
, value
+ addend
, hit_data
);
3662 return bfd_reloc_ok
;
3664 case R_PARISC_LTOFF64
:
3665 /* We want the value of the DLT offset for this symbol, not
3666 the symbol's actual address. Note that __gp may not point
3667 to the start of the DLT, so we have to compute the absolute
3668 address, then subtract out the value of __gp. */
3669 value
= (hh
->dlt_offset
3670 + hppa_info
->dlt_sec
->output_offset
3671 + hppa_info
->dlt_sec
->output_section
->vma
);
3672 value
-= _bfd_get_gp_value (output_bfd
);
3674 bfd_put_64 (input_bfd
, value
+ addend
, hit_data
);
3675 return bfd_reloc_ok
;
3677 case R_PARISC_PCREL32
:
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_32 (input_bfd
, value
, hit_data
);
3693 return bfd_reloc_ok
;
3696 case R_PARISC_PCREL64
:
3698 /* If this is a call to a function defined in another dynamic
3699 library, then redirect the call to the local stub for this
3701 if (sym_sec
== NULL
|| sym_sec
->output_section
== NULL
)
3702 value
= (hh
->stub_offset
+ hppa_info
->stub_sec
->output_offset
3703 + hppa_info
->stub_sec
->output_section
->vma
);
3705 /* Turn VALUE into a proper PC relative address. */
3706 value
-= (offset
+ input_section
->output_offset
3707 + input_section
->output_section
->vma
);
3711 bfd_put_64 (input_bfd
, value
, hit_data
);
3712 return bfd_reloc_ok
;
3715 case R_PARISC_FPTR64
:
3719 /* We may still need to create the FPTR itself if it was for
3723 bfd_vma
*local_opd_offsets
;
3725 if (local_offsets
== NULL
)
3728 local_opd_offsets
= local_offsets
+ 2 * symtab_hdr
->sh_info
;
3729 off
= local_opd_offsets
[r_symndx
];
3731 /* The last bit records whether we've already initialised
3732 this local .opd entry. */
3735 BFD_ASSERT (off
!= (bfd_vma
) -1);
3740 /* The first two words of an .opd entry are zero. */
3741 memset (hppa_info
->opd_sec
->contents
+ off
, 0, 16);
3743 /* The next word is the address of the function. */
3744 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
+ addend
,
3745 (hppa_info
->opd_sec
->contents
+ off
+ 16));
3747 /* The last word is our local __gp value. */
3748 value
= _bfd_get_gp_value
3749 (hppa_info
->opd_sec
->output_section
->owner
);
3750 bfd_put_64 (hppa_info
->opd_sec
->owner
, value
,
3751 hppa_info
->opd_sec
->contents
+ off
+ 24);
3755 off
= hh
->opd_offset
;
3757 if (hh
== NULL
|| hh
->want_opd
)
3758 /* We want the value of the OPD offset for this symbol. */
3760 + hppa_info
->opd_sec
->output_offset
3761 + hppa_info
->opd_sec
->output_section
->vma
);
3763 /* We want the address of the symbol. */
3766 bfd_put_64 (input_bfd
, value
, hit_data
);
3767 return bfd_reloc_ok
;
3770 case R_PARISC_SECREL32
:
3772 value
-= sym_sec
->output_section
->vma
;
3773 bfd_put_32 (input_bfd
, value
+ addend
, hit_data
);
3774 return bfd_reloc_ok
;
3776 case R_PARISC_SEGREL32
:
3777 case R_PARISC_SEGREL64
:
3779 /* If this is the first SEGREL relocation, then initialize
3780 the segment base values. */
3781 if (hppa_info
->text_segment_base
== (bfd_vma
) -1)
3782 bfd_map_over_sections (output_bfd
, elf_hppa_record_segment_addrs
,
3785 /* VALUE holds the absolute address. We want to include the
3786 addend, then turn it into a segment relative address.
3788 The segment is derived from SYM_SEC. We assume that there are
3789 only two segments of note in the resulting executable/shlib.
3790 A readonly segment (.text) and a readwrite segment (.data). */
3793 if (sym_sec
->flags
& SEC_CODE
)
3794 value
-= hppa_info
->text_segment_base
;
3796 value
-= hppa_info
->data_segment_base
;
3798 if (r_type
== R_PARISC_SEGREL32
)
3799 bfd_put_32 (input_bfd
, value
, hit_data
);
3801 bfd_put_64 (input_bfd
, value
, hit_data
);
3802 return bfd_reloc_ok
;
3805 /* Something we don't know how to handle. */
3807 return bfd_reloc_notsupported
;
3810 /* Update the instruction word. */
3811 bfd_put_32 (input_bfd
, (bfd_vma
) insn
, hit_data
);
3812 return bfd_reloc_ok
;
3815 /* Relocate an HPPA ELF section. */
3818 elf64_hppa_relocate_section (bfd
*output_bfd
,
3819 struct bfd_link_info
*info
,
3821 asection
*input_section
,
3823 Elf_Internal_Rela
*relocs
,
3824 Elf_Internal_Sym
*local_syms
,
3825 asection
**local_sections
)
3827 Elf_Internal_Shdr
*symtab_hdr
;
3828 Elf_Internal_Rela
*rel
;
3829 Elf_Internal_Rela
*relend
;
3830 struct elf64_hppa_link_hash_table
*hppa_info
;
3832 hppa_info
= hppa_link_hash_table (info
);
3833 if (hppa_info
== NULL
)
3836 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3839 relend
= relocs
+ input_section
->reloc_count
;
3840 for (; rel
< relend
; rel
++)
3843 reloc_howto_type
*howto
= elf_hppa_howto_table
+ ELF_R_TYPE (rel
->r_info
);
3844 unsigned long r_symndx
;
3845 struct elf_link_hash_entry
*eh
;
3846 Elf_Internal_Sym
*sym
;
3849 bfd_reloc_status_type r
;
3851 r_type
= ELF_R_TYPE (rel
->r_info
);
3852 if (r_type
< 0 || r_type
>= (int) R_PARISC_UNIMPLEMENTED
)
3854 bfd_set_error (bfd_error_bad_value
);
3857 if (r_type
== (unsigned int) R_PARISC_GNU_VTENTRY
3858 || r_type
== (unsigned int) R_PARISC_GNU_VTINHERIT
)
3861 /* This is a final link. */
3862 r_symndx
= ELF_R_SYM (rel
->r_info
);
3866 if (r_symndx
< symtab_hdr
->sh_info
)
3868 /* This is a local symbol, hh defaults to NULL. */
3869 sym
= local_syms
+ r_symndx
;
3870 sym_sec
= local_sections
[r_symndx
];
3871 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sym_sec
, rel
);
3875 /* This is not a local symbol. */
3876 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (input_bfd
);
3878 /* It seems this can happen with erroneous or unsupported
3879 input (mixing a.out and elf in an archive, for example.) */
3880 if (sym_hashes
== NULL
)
3883 eh
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3885 while (eh
->root
.type
== bfd_link_hash_indirect
3886 || eh
->root
.type
== bfd_link_hash_warning
)
3887 eh
= (struct elf_link_hash_entry
*) eh
->root
.u
.i
.link
;
3890 if (eh
->root
.type
== bfd_link_hash_defined
3891 || eh
->root
.type
== bfd_link_hash_defweak
)
3893 sym_sec
= eh
->root
.u
.def
.section
;
3895 && sym_sec
->output_section
!= NULL
)
3896 relocation
= (eh
->root
.u
.def
.value
3897 + sym_sec
->output_section
->vma
3898 + sym_sec
->output_offset
);
3900 else if (eh
->root
.type
== bfd_link_hash_undefweak
)
3902 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
3903 && ELF_ST_VISIBILITY (eh
->other
) == STV_DEFAULT
)
3905 else if (!info
->relocatable
3906 && elf_hppa_is_dynamic_loader_symbol (eh
->root
.root
.string
))
3908 else if (!info
->relocatable
)
3911 err
= (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
3912 || ELF_ST_VISIBILITY (eh
->other
) != STV_DEFAULT
);
3913 if (!info
->callbacks
->undefined_symbol (info
,
3914 eh
->root
.root
.string
,
3917 rel
->r_offset
, err
))
3921 if (!info
->relocatable
3923 && eh
->root
.type
!= bfd_link_hash_defined
3924 && eh
->root
.type
!= bfd_link_hash_defweak
3925 && eh
->root
.type
!= bfd_link_hash_undefweak
)
3927 if (info
->unresolved_syms_in_objects
== RM_IGNORE
3928 && ELF_ST_VISIBILITY (eh
->other
) == STV_DEFAULT
3929 && eh
->type
== STT_PARISC_MILLI
)
3931 if (! info
->callbacks
->undefined_symbol
3932 (info
, eh_name (eh
), input_bfd
,
3933 input_section
, rel
->r_offset
, FALSE
))
3939 if (sym_sec
!= NULL
&& elf_discarded_section (sym_sec
))
3940 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
3941 rel
, relend
, howto
, contents
);
3943 if (info
->relocatable
)
3946 r
= elf_hppa_final_link_relocate (rel
, input_bfd
, output_bfd
,
3947 input_section
, contents
,
3948 relocation
, info
, sym_sec
,
3951 if (r
!= bfd_reloc_ok
)
3957 case bfd_reloc_overflow
:
3959 const char *sym_name
;
3965 sym_name
= bfd_elf_string_from_elf_section (input_bfd
,
3966 symtab_hdr
->sh_link
,
3968 if (sym_name
== NULL
)
3970 if (*sym_name
== '\0')
3971 sym_name
= bfd_section_name (input_bfd
, sym_sec
);
3974 if (!((*info
->callbacks
->reloc_overflow
)
3975 (info
, (eh
? &eh
->root
: NULL
), sym_name
,
3976 howto
->name
, (bfd_vma
) 0, input_bfd
,
3977 input_section
, rel
->r_offset
)))
3987 static const struct bfd_elf_special_section elf64_hppa_special_sections
[] =
3989 { STRING_COMMA_LEN (".fini"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
3990 { STRING_COMMA_LEN (".init"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
3991 { STRING_COMMA_LEN (".plt"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
3992 { STRING_COMMA_LEN (".dlt"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
3993 { STRING_COMMA_LEN (".sdata"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
3994 { STRING_COMMA_LEN (".sbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
3995 { STRING_COMMA_LEN (".tbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_HP_TLS
},
3996 { NULL
, 0, 0, 0, 0 }
3999 /* The hash bucket size is the standard one, namely 4. */
4001 const struct elf_size_info hppa64_elf_size_info
=
4003 sizeof (Elf64_External_Ehdr
),
4004 sizeof (Elf64_External_Phdr
),
4005 sizeof (Elf64_External_Shdr
),
4006 sizeof (Elf64_External_Rel
),
4007 sizeof (Elf64_External_Rela
),
4008 sizeof (Elf64_External_Sym
),
4009 sizeof (Elf64_External_Dyn
),
4010 sizeof (Elf_External_Note
),
4014 ELFCLASS64
, EV_CURRENT
,
4015 bfd_elf64_write_out_phdrs
,
4016 bfd_elf64_write_shdrs_and_ehdr
,
4017 bfd_elf64_checksum_contents
,
4018 bfd_elf64_write_relocs
,
4019 bfd_elf64_swap_symbol_in
,
4020 bfd_elf64_swap_symbol_out
,
4021 bfd_elf64_slurp_reloc_table
,
4022 bfd_elf64_slurp_symbol_table
,
4023 bfd_elf64_swap_dyn_in
,
4024 bfd_elf64_swap_dyn_out
,
4025 bfd_elf64_swap_reloc_in
,
4026 bfd_elf64_swap_reloc_out
,
4027 bfd_elf64_swap_reloca_in
,
4028 bfd_elf64_swap_reloca_out
4031 #define TARGET_BIG_SYM bfd_elf64_hppa_vec
4032 #define TARGET_BIG_NAME "elf64-hppa"
4033 #define ELF_ARCH bfd_arch_hppa
4034 #define ELF_TARGET_ID HPPA64_ELF_DATA
4035 #define ELF_MACHINE_CODE EM_PARISC
4036 /* This is not strictly correct. The maximum page size for PA2.0 is
4037 64M. But everything still uses 4k. */
4038 #define ELF_MAXPAGESIZE 0x1000
4039 #define ELF_OSABI ELFOSABI_HPUX
4041 #define bfd_elf64_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
4042 #define bfd_elf64_bfd_reloc_name_lookup elf_hppa_reloc_name_lookup
4043 #define bfd_elf64_bfd_is_local_label_name elf_hppa_is_local_label_name
4044 #define elf_info_to_howto elf_hppa_info_to_howto
4045 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
4047 #define elf_backend_section_from_shdr elf64_hppa_section_from_shdr
4048 #define elf_backend_object_p elf64_hppa_object_p
4049 #define elf_backend_final_write_processing \
4050 elf_hppa_final_write_processing
4051 #define elf_backend_fake_sections elf_hppa_fake_sections
4052 #define elf_backend_add_symbol_hook elf_hppa_add_symbol_hook
4054 #define elf_backend_relocate_section elf_hppa_relocate_section
4056 #define bfd_elf64_bfd_final_link elf_hppa_final_link
4058 #define elf_backend_create_dynamic_sections \
4059 elf64_hppa_create_dynamic_sections
4060 #define elf_backend_post_process_headers elf64_hppa_post_process_headers
4062 #define elf_backend_omit_section_dynsym \
4063 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
4064 #define elf_backend_adjust_dynamic_symbol \
4065 elf64_hppa_adjust_dynamic_symbol
4067 #define elf_backend_size_dynamic_sections \
4068 elf64_hppa_size_dynamic_sections
4070 #define elf_backend_finish_dynamic_symbol \
4071 elf64_hppa_finish_dynamic_symbol
4072 #define elf_backend_finish_dynamic_sections \
4073 elf64_hppa_finish_dynamic_sections
4074 #define elf_backend_grok_prstatus elf64_hppa_grok_prstatus
4075 #define elf_backend_grok_psinfo elf64_hppa_grok_psinfo
4077 /* Stuff for the BFD linker: */
4078 #define bfd_elf64_bfd_link_hash_table_create \
4079 elf64_hppa_hash_table_create
4081 #define elf_backend_check_relocs \
4082 elf64_hppa_check_relocs
4084 #define elf_backend_size_info \
4085 hppa64_elf_size_info
4087 #define elf_backend_additional_program_headers \
4088 elf64_hppa_additional_program_headers
4090 #define elf_backend_modify_segment_map \
4091 elf64_hppa_modify_segment_map
4093 #define elf_backend_link_output_symbol_hook \
4094 elf64_hppa_link_output_symbol_hook
4096 #define elf_backend_want_got_plt 0
4097 #define elf_backend_plt_readonly 0
4098 #define elf_backend_want_plt_sym 0
4099 #define elf_backend_got_header_size 0
4100 #define elf_backend_type_change_ok TRUE
4101 #define elf_backend_get_symbol_type elf64_hppa_elf_get_symbol_type
4102 #define elf_backend_reloc_type_class elf64_hppa_reloc_type_class
4103 #define elf_backend_rela_normal 1
4104 #define elf_backend_special_sections elf64_hppa_special_sections
4105 #define elf_backend_action_discarded elf_hppa_action_discarded
4106 #define elf_backend_section_from_phdr elf64_hppa_section_from_phdr
4108 #define elf64_bed elf64_hppa_hpux_bed
4110 #include "elf64-target.h"
4112 #undef TARGET_BIG_SYM
4113 #define TARGET_BIG_SYM bfd_elf64_hppa_linux_vec
4114 #undef TARGET_BIG_NAME
4115 #define TARGET_BIG_NAME "elf64-hppa-linux"
4117 #define ELF_OSABI ELFOSABI_LINUX
4118 #undef elf_backend_post_process_headers
4119 #define elf_backend_post_process_headers _bfd_elf_set_osabi
4121 #define elf64_bed elf64_hppa_linux_bed
4123 #include "elf64-target.h"