1 /* Support for HPPA 64-bit ELF
2 Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 #include "alloca-conf.h"
27 #include "elf64-hppa.h"
30 #define PLT_ENTRY_SIZE 0x10
31 #define DLT_ENTRY_SIZE 0x8
32 #define OPD_ENTRY_SIZE 0x20
34 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/pa20_64/dld.sl"
36 /* The stub is supposed to load the target address and target's DP
37 value out of the PLT, then do an external branch to the target
42 LDD PLTOFF+8(%r27),%r27
44 Note that we must use the LDD with a 14 bit displacement, not the one
45 with a 5 bit displacement. */
46 static char plt_stub
[] = {0x53, 0x61, 0x00, 0x00, 0xe8, 0x20, 0xd0, 0x00,
47 0x53, 0x7b, 0x00, 0x00 };
49 struct elf64_hppa_dyn_hash_entry
51 struct bfd_hash_entry root
;
53 /* Offsets for this symbol in various linker sections. */
59 /* The symbol table entry, if any, that this was derived from. */
60 struct elf_link_hash_entry
*h
;
62 /* The index of the (possibly local) symbol in the input bfd and its
63 associated BFD. Needed so that we can have relocs against local
64 symbols in shared libraries. */
68 /* Dynamic symbols may need to have two different values. One for
69 the dynamic symbol table, one for the normal symbol table.
71 In such cases we store the symbol's real value and section
72 index here so we can restore the real value before we write
73 the normal symbol table. */
77 /* Used to count non-got, non-plt relocations for delayed sizing
78 of relocation sections. */
79 struct elf64_hppa_dyn_reloc_entry
81 /* Next relocation in the chain. */
82 struct elf64_hppa_dyn_reloc_entry
*next
;
84 /* The type of the relocation. */
87 /* The input section of the relocation. */
90 /* The index of the section symbol for the input section of
91 the relocation. Only needed when building shared libraries. */
94 /* The offset within the input section of the relocation. */
97 /* The addend for the relocation. */
102 /* Nonzero if this symbol needs an entry in one of the linker
110 struct elf64_hppa_dyn_hash_table
112 struct bfd_hash_table root
;
115 struct elf64_hppa_link_hash_table
117 struct elf_link_hash_table root
;
119 /* Shortcuts to get to the various linker defined sections. */
121 asection
*dlt_rel_sec
;
123 asection
*plt_rel_sec
;
125 asection
*opd_rel_sec
;
126 asection
*other_rel_sec
;
128 /* Offset of __gp within .plt section. When the PLT gets large we want
129 to slide __gp into the PLT section so that we can continue to use
130 single DP relative instructions to load values out of the PLT. */
133 /* Note this is not strictly correct. We should create a stub section for
134 each input section with calls. The stub section should be placed before
135 the section with the call. */
138 bfd_vma text_segment_base
;
139 bfd_vma data_segment_base
;
141 struct elf64_hppa_dyn_hash_table dyn_hash_table
;
143 /* We build tables to map from an input section back to its
144 symbol index. This is the BFD for which we currently have
146 bfd
*section_syms_bfd
;
148 /* Array of symbol numbers for each input section attached to the
153 #define elf64_hppa_hash_table(p) \
154 ((struct elf64_hppa_link_hash_table *) ((p)->hash))
156 typedef struct bfd_hash_entry
*(*new_hash_entry_func
)
157 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
159 static boolean elf64_hppa_dyn_hash_table_init
160 PARAMS ((struct elf64_hppa_dyn_hash_table
*ht
, bfd
*abfd
,
161 new_hash_entry_func
new));
162 static struct bfd_hash_entry
*elf64_hppa_new_dyn_hash_entry
163 PARAMS ((struct bfd_hash_entry
*entry
, struct bfd_hash_table
*table
,
164 const char *string
));
165 static struct bfd_link_hash_table
*elf64_hppa_hash_table_create
166 PARAMS ((bfd
*abfd
));
167 static struct elf64_hppa_dyn_hash_entry
*elf64_hppa_dyn_hash_lookup
168 PARAMS ((struct elf64_hppa_dyn_hash_table
*table
, const char *string
,
169 boolean create
, boolean copy
));
170 static void elf64_hppa_dyn_hash_traverse
171 PARAMS ((struct elf64_hppa_dyn_hash_table
*table
,
172 boolean (*func
) (struct elf64_hppa_dyn_hash_entry
*, PTR
),
175 static const char *get_dyn_name
176 PARAMS ((asection
*, struct elf_link_hash_entry
*,
177 const Elf_Internal_Rela
*, char **, size_t *));
179 /* This must follow the definitions of the various derived linker
180 hash tables and shared functions. */
181 #include "elf-hppa.h"
183 static boolean elf64_hppa_object_p
186 static boolean elf64_hppa_section_from_shdr
187 PARAMS ((bfd
*, Elf64_Internal_Shdr
*, const char *));
189 static void elf64_hppa_post_process_headers
190 PARAMS ((bfd
*, struct bfd_link_info
*));
192 static boolean elf64_hppa_create_dynamic_sections
193 PARAMS ((bfd
*, struct bfd_link_info
*));
195 static boolean elf64_hppa_adjust_dynamic_symbol
196 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
198 static boolean elf64_hppa_mark_milli_and_exported_functions
199 PARAMS ((struct elf_link_hash_entry
*, PTR
));
201 static boolean elf64_hppa_size_dynamic_sections
202 PARAMS ((bfd
*, struct bfd_link_info
*));
204 static boolean elf64_hppa_link_output_symbol_hook
205 PARAMS ((bfd
*abfd
, struct bfd_link_info
*, const char *,
206 Elf_Internal_Sym
*, asection
*input_sec
));
208 static boolean elf64_hppa_finish_dynamic_symbol
209 PARAMS ((bfd
*, struct bfd_link_info
*,
210 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
212 static int elf64_hppa_additional_program_headers
PARAMS ((bfd
*));
214 static boolean elf64_hppa_modify_segment_map
PARAMS ((bfd
*));
216 static enum elf_reloc_type_class elf64_hppa_reloc_type_class
217 PARAMS ((const Elf_Internal_Rela
*));
219 static boolean elf64_hppa_finish_dynamic_sections
220 PARAMS ((bfd
*, struct bfd_link_info
*));
222 static boolean elf64_hppa_check_relocs
223 PARAMS ((bfd
*, struct bfd_link_info
*,
224 asection
*, const Elf_Internal_Rela
*));
226 static boolean elf64_hppa_dynamic_symbol_p
227 PARAMS ((struct elf_link_hash_entry
*, struct bfd_link_info
*));
229 static boolean elf64_hppa_mark_exported_functions
230 PARAMS ((struct elf_link_hash_entry
*, PTR
));
232 static boolean elf64_hppa_finalize_opd
233 PARAMS ((struct elf64_hppa_dyn_hash_entry
*, PTR
));
235 static boolean elf64_hppa_finalize_dlt
236 PARAMS ((struct elf64_hppa_dyn_hash_entry
*, PTR
));
238 static boolean allocate_global_data_dlt
239 PARAMS ((struct elf64_hppa_dyn_hash_entry
*, PTR
));
241 static boolean allocate_global_data_plt
242 PARAMS ((struct elf64_hppa_dyn_hash_entry
*, PTR
));
244 static boolean allocate_global_data_stub
245 PARAMS ((struct elf64_hppa_dyn_hash_entry
*, PTR
));
247 static boolean allocate_global_data_opd
248 PARAMS ((struct elf64_hppa_dyn_hash_entry
*, PTR
));
250 static boolean get_reloc_section
251 PARAMS ((bfd
*, struct elf64_hppa_link_hash_table
*, asection
*));
253 static boolean count_dyn_reloc
254 PARAMS ((bfd
*, struct elf64_hppa_dyn_hash_entry
*,
255 int, asection
*, int, bfd_vma
, bfd_vma
));
257 static boolean allocate_dynrel_entries
258 PARAMS ((struct elf64_hppa_dyn_hash_entry
*, PTR
));
260 static boolean elf64_hppa_finalize_dynreloc
261 PARAMS ((struct elf64_hppa_dyn_hash_entry
*, PTR
));
263 static boolean get_opd
264 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*));
266 static boolean get_plt
267 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*));
269 static boolean get_dlt
270 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*));
272 static boolean get_stub
273 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*));
275 static int elf64_hppa_elf_get_symbol_type
276 PARAMS ((Elf_Internal_Sym
*, int));
279 elf64_hppa_dyn_hash_table_init (ht
, abfd
, new)
280 struct elf64_hppa_dyn_hash_table
*ht
;
281 bfd
*abfd ATTRIBUTE_UNUSED
;
282 new_hash_entry_func
new;
284 memset (ht
, 0, sizeof (*ht
));
285 return bfd_hash_table_init (&ht
->root
, new);
288 static struct bfd_hash_entry
*
289 elf64_hppa_new_dyn_hash_entry (entry
, table
, string
)
290 struct bfd_hash_entry
*entry
;
291 struct bfd_hash_table
*table
;
294 struct elf64_hppa_dyn_hash_entry
*ret
;
295 ret
= (struct elf64_hppa_dyn_hash_entry
*) entry
;
297 /* Allocate the structure if it has not already been allocated by a
300 ret
= bfd_hash_allocate (table
, sizeof (*ret
));
305 /* Initialize our local data. All zeros, and definitely easier
306 than setting 8 bit fields. */
307 memset (ret
, 0, sizeof (*ret
));
309 /* Call the allocation method of the superclass. */
310 ret
= ((struct elf64_hppa_dyn_hash_entry
*)
311 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
316 /* Create the derived linker hash table. The PA64 ELF port uses this
317 derived hash table to keep information specific to the PA ElF
318 linker (without using static variables). */
320 static struct bfd_link_hash_table
*
321 elf64_hppa_hash_table_create (abfd
)
324 struct elf64_hppa_link_hash_table
*ret
;
326 ret
= bfd_zalloc (abfd
, (bfd_size_type
) sizeof (*ret
));
329 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
330 _bfd_elf_link_hash_newfunc
))
332 bfd_release (abfd
, ret
);
336 if (!elf64_hppa_dyn_hash_table_init (&ret
->dyn_hash_table
, abfd
,
337 elf64_hppa_new_dyn_hash_entry
))
339 return &ret
->root
.root
;
342 /* Look up an entry in a PA64 ELF linker hash table. */
344 static struct elf64_hppa_dyn_hash_entry
*
345 elf64_hppa_dyn_hash_lookup(table
, string
, create
, copy
)
346 struct elf64_hppa_dyn_hash_table
*table
;
348 boolean create
, copy
;
350 return ((struct elf64_hppa_dyn_hash_entry
*)
351 bfd_hash_lookup (&table
->root
, string
, create
, copy
));
354 /* Traverse a PA64 ELF linker hash table. */
357 elf64_hppa_dyn_hash_traverse (table
, func
, info
)
358 struct elf64_hppa_dyn_hash_table
*table
;
359 boolean (*func
) PARAMS ((struct elf64_hppa_dyn_hash_entry
*, PTR
));
364 (boolean (*) PARAMS ((struct bfd_hash_entry
*, PTR
))) func
,
368 /* Return nonzero if ABFD represents a PA2.0 ELF64 file.
370 Additionally we set the default architecture and machine. */
372 elf64_hppa_object_p (abfd
)
375 Elf_Internal_Ehdr
* i_ehdrp
;
378 i_ehdrp
= elf_elfheader (abfd
);
379 if (strcmp (bfd_get_target (abfd
), "elf64-hppa-linux") == 0)
381 if (i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_LINUX
)
386 if (i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_HPUX
)
390 flags
= i_ehdrp
->e_flags
;
391 switch (flags
& (EF_PARISC_ARCH
| EF_PARISC_WIDE
))
394 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 10);
396 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 11);
398 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 20);
399 case EFA_PARISC_2_0
| EF_PARISC_WIDE
:
400 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 25);
402 /* Don't be fussy. */
406 /* Given section type (hdr->sh_type), return a boolean indicating
407 whether or not the section is an elf64-hppa specific section. */
409 elf64_hppa_section_from_shdr (abfd
, hdr
, name
)
411 Elf64_Internal_Shdr
*hdr
;
416 switch (hdr
->sh_type
)
419 if (strcmp (name
, ".PARISC.archext") != 0)
422 case SHT_PARISC_UNWIND
:
423 if (strcmp (name
, ".PARISC.unwind") != 0)
427 case SHT_PARISC_ANNOT
:
432 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
434 newsect
= hdr
->bfd_section
;
439 /* Construct a string for use in the elf64_hppa_dyn_hash_table. The
440 name describes what was once potentially anonymous memory. We
441 allocate memory as necessary, possibly reusing PBUF/PLEN. */
444 get_dyn_name (sec
, h
, rel
, pbuf
, plen
)
446 struct elf_link_hash_entry
*h
;
447 const Elf_Internal_Rela
*rel
;
455 if (h
&& rel
->r_addend
== 0)
456 return h
->root
.root
.string
;
459 nlen
= strlen (h
->root
.root
.string
);
461 nlen
= 8 + 1 + sizeof (rel
->r_info
) * 2 - 8;
462 tlen
= nlen
+ 1 + sizeof (rel
->r_addend
) * 2 + 1;
470 *pbuf
= buf
= malloc (tlen
);
478 memcpy (buf
, h
->root
.root
.string
, nlen
);
480 sprintf_vma (buf
+ nlen
, rel
->r_addend
);
484 nlen
= sprintf (buf
, "%x:%lx",
485 sec
->id
& 0xffffffff,
486 (long) ELF64_R_SYM (rel
->r_info
));
490 sprintf_vma (buf
+ nlen
, rel
->r_addend
);
497 /* SEC is a section containing relocs for an input BFD when linking; return
498 a suitable section for holding relocs in the output BFD for a link. */
501 get_reloc_section (abfd
, hppa_info
, sec
)
503 struct elf64_hppa_link_hash_table
*hppa_info
;
506 const char *srel_name
;
510 srel_name
= (bfd_elf_string_from_elf_section
511 (abfd
, elf_elfheader(abfd
)->e_shstrndx
,
512 elf_section_data(sec
)->rel_hdr
.sh_name
));
513 if (srel_name
== NULL
)
516 BFD_ASSERT ((strncmp (srel_name
, ".rela", 5) == 0
517 && strcmp (bfd_get_section_name (abfd
, sec
),
519 || (strncmp (srel_name
, ".rel", 4) == 0
520 && strcmp (bfd_get_section_name (abfd
, sec
),
523 dynobj
= hppa_info
->root
.dynobj
;
525 hppa_info
->root
.dynobj
= dynobj
= abfd
;
527 srel
= bfd_get_section_by_name (dynobj
, srel_name
);
530 srel
= bfd_make_section (dynobj
, srel_name
);
532 || !bfd_set_section_flags (dynobj
, srel
,
539 || !bfd_set_section_alignment (dynobj
, srel
, 3))
543 hppa_info
->other_rel_sec
= srel
;
547 /* Add a new entry to the list of dynamic relocations against DYN_H.
549 We use this to keep a record of all the FPTR relocations against a
550 particular symbol so that we can create FPTR relocations in the
554 count_dyn_reloc (abfd
, dyn_h
, type
, sec
, sec_symndx
, offset
, addend
)
556 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
563 struct elf64_hppa_dyn_reloc_entry
*rent
;
565 rent
= (struct elf64_hppa_dyn_reloc_entry
*)
566 bfd_alloc (abfd
, (bfd_size_type
) sizeof (*rent
));
570 rent
->next
= dyn_h
->reloc_entries
;
573 rent
->sec_symndx
= sec_symndx
;
574 rent
->offset
= offset
;
575 rent
->addend
= addend
;
576 dyn_h
->reloc_entries
= rent
;
581 /* Scan the RELOCS and record the type of dynamic entries that each
582 referenced symbol needs. */
585 elf64_hppa_check_relocs (abfd
, info
, sec
, relocs
)
587 struct bfd_link_info
*info
;
589 const Elf_Internal_Rela
*relocs
;
591 struct elf64_hppa_link_hash_table
*hppa_info
;
592 const Elf_Internal_Rela
*relend
;
593 Elf_Internal_Shdr
*symtab_hdr
;
594 Elf_Internal_Shdr
*shndx_hdr
;
595 const Elf_Internal_Rela
*rel
;
596 asection
*dlt
, *plt
, *stubs
;
601 if (info
->relocateable
)
604 /* If this is the first dynamic object found in the link, create
605 the special sections required for dynamic linking. */
606 if (! elf_hash_table (info
)->dynamic_sections_created
)
608 if (! bfd_elf64_link_create_dynamic_sections (abfd
, info
))
612 hppa_info
= elf64_hppa_hash_table (info
);
613 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
615 /* If necessary, build a new table holding section symbols indices
616 for this BFD. This is disgusting. */
618 if (info
->shared
&& hppa_info
->section_syms_bfd
!= abfd
)
621 unsigned int highest_shndx
;
622 Elf_Internal_Sym
*local_syms
, *isym
;
623 Elf64_External_Sym
*ext_syms
, *esym
;
624 Elf_External_Sym_Shndx
*shndx_buf
, *shndx
;
627 /* We're done with the old cache of section index to section symbol
628 index information. Free it.
630 ?!? Note we leak the last section_syms array. Presumably we
631 could free it in one of the later routines in this file. */
632 if (hppa_info
->section_syms
)
633 free (hppa_info
->section_syms
);
635 /* Allocate memory for the internal and external symbols. */
636 amt
= symtab_hdr
->sh_info
;
637 amt
*= sizeof (Elf_Internal_Sym
);
638 local_syms
= (Elf_Internal_Sym
*) bfd_malloc (amt
);
639 if (local_syms
== NULL
)
642 amt
= symtab_hdr
->sh_info
;
643 amt
*= sizeof (Elf64_External_Sym
);
644 ext_syms
= (Elf64_External_Sym
*) bfd_malloc (amt
);
645 if (ext_syms
== NULL
)
651 /* Read in the local symbols. */
652 if (bfd_seek (abfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
653 || bfd_bread (ext_syms
, amt
, abfd
) != amt
)
661 shndx_hdr
= &elf_tdata (abfd
)->symtab_shndx_hdr
;
662 if (shndx_hdr
->sh_size
!= 0)
664 amt
= symtab_hdr
->sh_info
;
665 amt
*= sizeof (Elf_External_Sym_Shndx
);
666 shndx_buf
= (Elf_External_Sym_Shndx
*) bfd_malloc (amt
);
667 if (shndx_buf
== NULL
)
674 if (bfd_seek (abfd
, shndx_hdr
->sh_offset
, SEEK_SET
) != 0
675 || bfd_bread (shndx_buf
, amt
, abfd
) != amt
)
684 /* Swap in the local symbols, also record the highest section index
685 referenced by the local symbols. */
687 for (i
= 0, isym
= local_syms
, esym
= ext_syms
, shndx
= shndx_buf
;
688 i
< symtab_hdr
->sh_info
;
689 i
++, esym
++, isym
++, shndx
= (shndx
!= NULL
? shndx
+ 1 : NULL
))
691 bfd_elf64_swap_symbol_in (abfd
, (const PTR
) esym
, (const PTR
) shndx
,
693 if (isym
->st_shndx
> highest_shndx
)
694 highest_shndx
= isym
->st_shndx
;
697 /* Now we can free the external symbols. */
701 /* Allocate an array to hold the section index to section symbol index
702 mapping. Bump by one since we start counting at zero. */
706 hppa_info
->section_syms
= (int *) bfd_malloc (amt
);
708 /* Now walk the local symbols again. If we find a section symbol,
709 record the index of the symbol into the section_syms array. */
710 for (isym
= local_syms
, i
= 0; i
< symtab_hdr
->sh_info
; i
++, isym
++)
712 if (ELF_ST_TYPE (isym
->st_info
) == STT_SECTION
)
713 hppa_info
->section_syms
[isym
->st_shndx
] = i
;
716 /* We are finished with the local symbols. Get rid of them. */
719 /* Record which BFD we built the section_syms mapping for. */
720 hppa_info
->section_syms_bfd
= abfd
;
723 /* Record the symbol index for this input section. We may need it for
724 relocations when building shared libraries. When not building shared
725 libraries this value is never really used, but assign it to zero to
726 prevent out of bounds memory accesses in other routines. */
729 sec_symndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
731 /* If we did not find a section symbol for this section, then
732 something went terribly wrong above. */
733 if (sec_symndx
== -1)
736 sec_symndx
= hppa_info
->section_syms
[sec_symndx
];
741 dlt
= plt
= stubs
= NULL
;
745 relend
= relocs
+ sec
->reloc_count
;
746 for (rel
= relocs
; rel
< relend
; ++rel
)
756 struct elf_link_hash_entry
*h
= NULL
;
757 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
758 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
760 const char *addr_name
;
761 boolean maybe_dynamic
;
762 int dynrel_type
= R_PARISC_NONE
;
763 static reloc_howto_type
*howto
;
765 if (r_symndx
>= symtab_hdr
->sh_info
)
767 /* We're dealing with a global symbol -- find its hash entry
768 and mark it as being referenced. */
769 long indx
= r_symndx
- symtab_hdr
->sh_info
;
770 h
= elf_sym_hashes (abfd
)[indx
];
771 while (h
->root
.type
== bfd_link_hash_indirect
772 || h
->root
.type
== bfd_link_hash_warning
)
773 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
775 h
->elf_link_hash_flags
|= ELF_LINK_HASH_REF_REGULAR
;
778 /* We can only get preliminary data on whether a symbol is
779 locally or externally defined, as not all of the input files
780 have yet been processed. Do something with what we know, as
781 this may help reduce memory usage and processing time later. */
782 maybe_dynamic
= false;
783 if (h
&& ((info
->shared
784 && (!info
->symbolic
|| info
->allow_shlib_undefined
) )
785 || ! (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
786 || h
->root
.type
== bfd_link_hash_defweak
))
787 maybe_dynamic
= true;
789 howto
= elf_hppa_howto_table
+ ELF64_R_TYPE (rel
->r_info
);
793 /* These are simple indirect references to symbols through the
794 DLT. We need to create a DLT entry for any symbols which
795 appears in a DLTIND relocation. */
796 case R_PARISC_DLTIND21L
:
797 case R_PARISC_DLTIND14R
:
798 case R_PARISC_DLTIND14F
:
799 case R_PARISC_DLTIND14WR
:
800 case R_PARISC_DLTIND14DR
:
801 need_entry
= NEED_DLT
;
804 /* ?!? These need a DLT entry. But I have no idea what to do with
805 the "link time TP value. */
806 case R_PARISC_LTOFF_TP21L
:
807 case R_PARISC_LTOFF_TP14R
:
808 case R_PARISC_LTOFF_TP14F
:
809 case R_PARISC_LTOFF_TP64
:
810 case R_PARISC_LTOFF_TP14WR
:
811 case R_PARISC_LTOFF_TP14DR
:
812 case R_PARISC_LTOFF_TP16F
:
813 case R_PARISC_LTOFF_TP16WF
:
814 case R_PARISC_LTOFF_TP16DF
:
815 need_entry
= NEED_DLT
;
818 /* These are function calls. Depending on their precise target we
819 may need to make a stub for them. The stub uses the PLT, so we
820 need to create PLT entries for these symbols too. */
821 case R_PARISC_PCREL12F
:
822 case R_PARISC_PCREL17F
:
823 case R_PARISC_PCREL22F
:
824 case R_PARISC_PCREL32
:
825 case R_PARISC_PCREL64
:
826 case R_PARISC_PCREL21L
:
827 case R_PARISC_PCREL17R
:
828 case R_PARISC_PCREL17C
:
829 case R_PARISC_PCREL14R
:
830 case R_PARISC_PCREL14F
:
831 case R_PARISC_PCREL22C
:
832 case R_PARISC_PCREL14WR
:
833 case R_PARISC_PCREL14DR
:
834 case R_PARISC_PCREL16F
:
835 case R_PARISC_PCREL16WF
:
836 case R_PARISC_PCREL16DF
:
837 need_entry
= (NEED_PLT
| NEED_STUB
);
840 case R_PARISC_PLTOFF21L
:
841 case R_PARISC_PLTOFF14R
:
842 case R_PARISC_PLTOFF14F
:
843 case R_PARISC_PLTOFF14WR
:
844 case R_PARISC_PLTOFF14DR
:
845 case R_PARISC_PLTOFF16F
:
846 case R_PARISC_PLTOFF16WF
:
847 case R_PARISC_PLTOFF16DF
:
848 need_entry
= (NEED_PLT
);
852 if (info
->shared
|| maybe_dynamic
)
853 need_entry
= (NEED_DYNREL
);
854 dynrel_type
= R_PARISC_DIR64
;
857 /* This is an indirect reference through the DLT to get the address
858 of a OPD descriptor. Thus we need to make a DLT entry that points
860 case R_PARISC_LTOFF_FPTR21L
:
861 case R_PARISC_LTOFF_FPTR14R
:
862 case R_PARISC_LTOFF_FPTR14WR
:
863 case R_PARISC_LTOFF_FPTR14DR
:
864 case R_PARISC_LTOFF_FPTR32
:
865 case R_PARISC_LTOFF_FPTR64
:
866 case R_PARISC_LTOFF_FPTR16F
:
867 case R_PARISC_LTOFF_FPTR16WF
:
868 case R_PARISC_LTOFF_FPTR16DF
:
869 if (info
->shared
|| maybe_dynamic
)
870 need_entry
= (NEED_DLT
| NEED_OPD
);
872 need_entry
= (NEED_DLT
| NEED_OPD
);
873 dynrel_type
= R_PARISC_FPTR64
;
876 /* This is a simple OPD entry. */
877 case R_PARISC_FPTR64
:
878 if (info
->shared
|| maybe_dynamic
)
879 need_entry
= (NEED_OPD
| NEED_DYNREL
);
881 need_entry
= (NEED_OPD
);
882 dynrel_type
= R_PARISC_FPTR64
;
885 /* Add more cases as needed. */
891 /* Collect a canonical name for this address. */
892 addr_name
= get_dyn_name (sec
, h
, rel
, &buf
, &buf_len
);
894 /* Collect the canonical entry data for this address. */
895 dyn_h
= elf64_hppa_dyn_hash_lookup (&hppa_info
->dyn_hash_table
,
896 addr_name
, true, true);
899 /* Stash away enough information to be able to find this symbol
900 regardless of whether or not it is local or global. */
903 dyn_h
->sym_indx
= r_symndx
;
905 /* ?!? We may need to do some error checking in here. */
906 /* Create what's needed. */
907 if (need_entry
& NEED_DLT
)
909 if (! hppa_info
->dlt_sec
910 && ! get_dlt (abfd
, info
, hppa_info
))
915 if (need_entry
& NEED_PLT
)
917 if (! hppa_info
->plt_sec
918 && ! get_plt (abfd
, info
, hppa_info
))
923 if (need_entry
& NEED_STUB
)
925 if (! hppa_info
->stub_sec
926 && ! get_stub (abfd
, info
, hppa_info
))
928 dyn_h
->want_stub
= 1;
931 if (need_entry
& NEED_OPD
)
933 if (! hppa_info
->opd_sec
934 && ! get_opd (abfd
, info
, hppa_info
))
939 /* FPTRs are not allocated by the dynamic linker for PA64, though
940 it is possible that will change in the future. */
942 /* This could be a local function that had its address taken, in
943 which case H will be NULL. */
945 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
948 /* Add a new dynamic relocation to the chain of dynamic
949 relocations for this symbol. */
950 if ((need_entry
& NEED_DYNREL
) && (sec
->flags
& SEC_ALLOC
))
952 if (! hppa_info
->other_rel_sec
953 && ! get_reloc_section (abfd
, hppa_info
, sec
))
956 if (!count_dyn_reloc (abfd
, dyn_h
, dynrel_type
, sec
,
957 sec_symndx
, rel
->r_offset
, rel
->r_addend
))
960 /* If we are building a shared library and we just recorded
961 a dynamic R_PARISC_FPTR64 relocation, then make sure the
962 section symbol for this section ends up in the dynamic
964 if (info
->shared
&& dynrel_type
== R_PARISC_FPTR64
965 && ! (_bfd_elf64_link_record_local_dynamic_symbol
966 (info
, abfd
, sec_symndx
)))
981 struct elf64_hppa_allocate_data
983 struct bfd_link_info
*info
;
987 /* Should we do dynamic things to this symbol? */
990 elf64_hppa_dynamic_symbol_p (h
, info
)
991 struct elf_link_hash_entry
*h
;
992 struct bfd_link_info
*info
;
997 while (h
->root
.type
== bfd_link_hash_indirect
998 || h
->root
.type
== bfd_link_hash_warning
)
999 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1001 if (h
->dynindx
== -1)
1004 if (h
->root
.type
== bfd_link_hash_undefweak
1005 || h
->root
.type
== bfd_link_hash_defweak
)
1008 if (h
->root
.root
.string
[0] == '$' && h
->root
.root
.string
[1] == '$')
1011 if ((info
->shared
&& (!info
->symbolic
|| info
->allow_shlib_undefined
))
1012 || ((h
->elf_link_hash_flags
1013 & (ELF_LINK_HASH_DEF_DYNAMIC
| ELF_LINK_HASH_REF_REGULAR
))
1014 == (ELF_LINK_HASH_DEF_DYNAMIC
| ELF_LINK_HASH_REF_REGULAR
)))
1020 /* Mark all funtions exported by this file so that we can later allocate
1021 entries in .opd for them. */
1024 elf64_hppa_mark_exported_functions (h
, data
)
1025 struct elf_link_hash_entry
*h
;
1028 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
1029 struct elf64_hppa_link_hash_table
*hppa_info
;
1031 hppa_info
= elf64_hppa_hash_table (info
);
1033 if (h
->root
.type
== bfd_link_hash_warning
)
1034 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1037 && (h
->root
.type
== bfd_link_hash_defined
1038 || h
->root
.type
== bfd_link_hash_defweak
)
1039 && h
->root
.u
.def
.section
->output_section
!= NULL
1040 && h
->type
== STT_FUNC
)
1042 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
1044 /* Add this symbol to the PA64 linker hash table. */
1045 dyn_h
= elf64_hppa_dyn_hash_lookup (&hppa_info
->dyn_hash_table
,
1046 h
->root
.root
.string
, true, true);
1050 if (! hppa_info
->opd_sec
1051 && ! get_opd (hppa_info
->root
.dynobj
, info
, hppa_info
))
1054 dyn_h
->want_opd
= 1;
1055 /* Put a flag here for output_symbol_hook. */
1056 dyn_h
->st_shndx
= -1;
1057 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1063 /* Allocate space for a DLT entry. */
1066 allocate_global_data_dlt (dyn_h
, data
)
1067 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
1070 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1072 if (dyn_h
->want_dlt
)
1074 struct elf_link_hash_entry
*h
= dyn_h
->h
;
1076 if (x
->info
->shared
)
1078 /* Possibly add the symbol to the local dynamic symbol
1079 table since we might need to create a dynamic relocation
1082 || (h
->dynindx
== -1 && h
->type
!= STT_PARISC_MILLI
))
1085 owner
= (h
? h
->root
.u
.def
.section
->owner
: dyn_h
->owner
);
1087 if (! (_bfd_elf64_link_record_local_dynamic_symbol
1088 (x
->info
, owner
, dyn_h
->sym_indx
)))
1093 dyn_h
->dlt_offset
= x
->ofs
;
1094 x
->ofs
+= DLT_ENTRY_SIZE
;
1099 /* Allocate space for a DLT.PLT entry. */
1102 allocate_global_data_plt (dyn_h
, data
)
1103 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
1106 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1109 && elf64_hppa_dynamic_symbol_p (dyn_h
->h
, x
->info
)
1110 && !((dyn_h
->h
->root
.type
== bfd_link_hash_defined
1111 || dyn_h
->h
->root
.type
== bfd_link_hash_defweak
)
1112 && dyn_h
->h
->root
.u
.def
.section
->output_section
!= NULL
))
1114 dyn_h
->plt_offset
= x
->ofs
;
1115 x
->ofs
+= PLT_ENTRY_SIZE
;
1116 if (dyn_h
->plt_offset
< 0x2000)
1117 elf64_hppa_hash_table (x
->info
)->gp_offset
= dyn_h
->plt_offset
;
1120 dyn_h
->want_plt
= 0;
1125 /* Allocate space for a STUB entry. */
1128 allocate_global_data_stub (dyn_h
, data
)
1129 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
1132 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1134 if (dyn_h
->want_stub
1135 && elf64_hppa_dynamic_symbol_p (dyn_h
->h
, x
->info
)
1136 && !((dyn_h
->h
->root
.type
== bfd_link_hash_defined
1137 || dyn_h
->h
->root
.type
== bfd_link_hash_defweak
)
1138 && dyn_h
->h
->root
.u
.def
.section
->output_section
!= NULL
))
1140 dyn_h
->stub_offset
= x
->ofs
;
1141 x
->ofs
+= sizeof (plt_stub
);
1144 dyn_h
->want_stub
= 0;
1148 /* Allocate space for a FPTR entry. */
1151 allocate_global_data_opd (dyn_h
, data
)
1152 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
1155 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1157 if (dyn_h
->want_opd
)
1159 struct elf_link_hash_entry
*h
= dyn_h
->h
;
1162 while (h
->root
.type
== bfd_link_hash_indirect
1163 || h
->root
.type
== bfd_link_hash_warning
)
1164 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1166 /* We never need an opd entry for a symbol which is not
1167 defined by this output file. */
1168 if (h
&& (h
->root
.type
== bfd_link_hash_undefined
1169 || h
->root
.u
.def
.section
->output_section
== NULL
))
1170 dyn_h
->want_opd
= 0;
1172 /* If we are creating a shared library, took the address of a local
1173 function or might export this function from this object file, then
1174 we have to create an opd descriptor. */
1175 else if (x
->info
->shared
1177 || (h
->dynindx
== -1 && h
->type
!= STT_PARISC_MILLI
)
1178 || (h
->root
.type
== bfd_link_hash_defined
1179 || h
->root
.type
== bfd_link_hash_defweak
))
1181 /* If we are creating a shared library, then we will have to
1182 create a runtime relocation for the symbol to properly
1183 initialize the .opd entry. Make sure the symbol gets
1184 added to the dynamic symbol table. */
1186 && (h
== NULL
|| (h
->dynindx
== -1)))
1189 owner
= (h
? h
->root
.u
.def
.section
->owner
: dyn_h
->owner
);
1191 if (!_bfd_elf64_link_record_local_dynamic_symbol
1192 (x
->info
, owner
, dyn_h
->sym_indx
))
1196 /* This may not be necessary or desirable anymore now that
1197 we have some support for dealing with section symbols
1198 in dynamic relocs. But name munging does make the result
1199 much easier to debug. ie, the EPLT reloc will reference
1200 a symbol like .foobar, instead of .text + offset. */
1201 if (x
->info
->shared
&& h
)
1204 struct elf_link_hash_entry
*nh
;
1206 new_name
= alloca (strlen (h
->root
.root
.string
) + 2);
1208 strcpy (new_name
+ 1, h
->root
.root
.string
);
1210 nh
= elf_link_hash_lookup (elf_hash_table (x
->info
),
1211 new_name
, true, true, true);
1213 nh
->root
.type
= h
->root
.type
;
1214 nh
->root
.u
.def
.value
= h
->root
.u
.def
.value
;
1215 nh
->root
.u
.def
.section
= h
->root
.u
.def
.section
;
1217 if (! bfd_elf64_link_record_dynamic_symbol (x
->info
, nh
))
1221 dyn_h
->opd_offset
= x
->ofs
;
1222 x
->ofs
+= OPD_ENTRY_SIZE
;
1225 /* Otherwise we do not need an opd entry. */
1227 dyn_h
->want_opd
= 0;
1232 /* HP requires the EI_OSABI field to be filled in. The assignment to
1233 EI_ABIVERSION may not be strictly necessary. */
1236 elf64_hppa_post_process_headers (abfd
, link_info
)
1238 struct bfd_link_info
* link_info ATTRIBUTE_UNUSED
;
1240 Elf_Internal_Ehdr
* i_ehdrp
;
1242 i_ehdrp
= elf_elfheader (abfd
);
1244 if (strcmp (bfd_get_target (abfd
), "elf64-hppa-linux") == 0)
1246 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_LINUX
;
1250 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_HPUX
;
1251 i_ehdrp
->e_ident
[EI_ABIVERSION
] = 1;
1255 /* Create function descriptor section (.opd). This section is called .opd
1256 because it contains "official prodecure descriptors". The "official"
1257 refers to the fact that these descriptors are used when taking the address
1258 of a procedure, thus ensuring a unique address for each procedure. */
1261 get_opd (abfd
, info
, hppa_info
)
1263 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1264 struct elf64_hppa_link_hash_table
*hppa_info
;
1269 opd
= hppa_info
->opd_sec
;
1272 dynobj
= hppa_info
->root
.dynobj
;
1274 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1276 opd
= bfd_make_section (dynobj
, ".opd");
1278 || !bfd_set_section_flags (dynobj
, opd
,
1283 | SEC_LINKER_CREATED
))
1284 || !bfd_set_section_alignment (abfd
, opd
, 3))
1290 hppa_info
->opd_sec
= opd
;
1296 /* Create the PLT section. */
1299 get_plt (abfd
, info
, hppa_info
)
1301 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1302 struct elf64_hppa_link_hash_table
*hppa_info
;
1307 plt
= hppa_info
->plt_sec
;
1310 dynobj
= hppa_info
->root
.dynobj
;
1312 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1314 plt
= bfd_make_section (dynobj
, ".plt");
1316 || !bfd_set_section_flags (dynobj
, plt
,
1321 | SEC_LINKER_CREATED
))
1322 || !bfd_set_section_alignment (abfd
, plt
, 3))
1328 hppa_info
->plt_sec
= plt
;
1334 /* Create the DLT section. */
1337 get_dlt (abfd
, info
, hppa_info
)
1339 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1340 struct elf64_hppa_link_hash_table
*hppa_info
;
1345 dlt
= hppa_info
->dlt_sec
;
1348 dynobj
= hppa_info
->root
.dynobj
;
1350 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1352 dlt
= bfd_make_section (dynobj
, ".dlt");
1354 || !bfd_set_section_flags (dynobj
, dlt
,
1359 | SEC_LINKER_CREATED
))
1360 || !bfd_set_section_alignment (abfd
, dlt
, 3))
1366 hppa_info
->dlt_sec
= dlt
;
1372 /* Create the stubs section. */
1375 get_stub (abfd
, info
, hppa_info
)
1377 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1378 struct elf64_hppa_link_hash_table
*hppa_info
;
1383 stub
= hppa_info
->stub_sec
;
1386 dynobj
= hppa_info
->root
.dynobj
;
1388 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1390 stub
= bfd_make_section (dynobj
, ".stub");
1392 || !bfd_set_section_flags (dynobj
, stub
,
1398 | SEC_LINKER_CREATED
))
1399 || !bfd_set_section_alignment (abfd
, stub
, 3))
1405 hppa_info
->stub_sec
= stub
;
1411 /* Create sections necessary for dynamic linking. This is only a rough
1412 cut and will likely change as we learn more about the somewhat
1413 unusual dynamic linking scheme HP uses.
1416 Contains code to implement cross-space calls. The first time one
1417 of the stubs is used it will call into the dynamic linker, later
1418 calls will go straight to the target.
1420 The only stub we support right now looks like
1424 ldd OFFSET+8(%dp),%dp
1426 Other stubs may be needed in the future. We may want the remove
1427 the break/nop instruction. It is only used right now to keep the
1428 offset of a .plt entry and a .stub entry in sync.
1431 This is what most people call the .got. HP used a different name.
1435 Relocations for the DLT.
1438 Function pointers as address,gp pairs.
1441 Should contain dynamic IPLT (and EPLT?) relocations.
1447 EPLT relocations for symbols exported from shared libraries. */
1450 elf64_hppa_create_dynamic_sections (abfd
, info
)
1452 struct bfd_link_info
*info
;
1456 if (! get_stub (abfd
, info
, elf64_hppa_hash_table (info
)))
1459 if (! get_dlt (abfd
, info
, elf64_hppa_hash_table (info
)))
1462 if (! get_plt (abfd
, info
, elf64_hppa_hash_table (info
)))
1465 if (! get_opd (abfd
, info
, elf64_hppa_hash_table (info
)))
1468 s
= bfd_make_section(abfd
, ".rela.dlt");
1470 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
1474 | SEC_LINKER_CREATED
))
1475 || !bfd_set_section_alignment (abfd
, s
, 3))
1477 elf64_hppa_hash_table (info
)->dlt_rel_sec
= s
;
1479 s
= bfd_make_section(abfd
, ".rela.plt");
1481 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
1485 | SEC_LINKER_CREATED
))
1486 || !bfd_set_section_alignment (abfd
, s
, 3))
1488 elf64_hppa_hash_table (info
)->plt_rel_sec
= s
;
1490 s
= bfd_make_section(abfd
, ".rela.data");
1492 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
1496 | SEC_LINKER_CREATED
))
1497 || !bfd_set_section_alignment (abfd
, s
, 3))
1499 elf64_hppa_hash_table (info
)->other_rel_sec
= s
;
1501 s
= bfd_make_section(abfd
, ".rela.opd");
1503 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
1507 | SEC_LINKER_CREATED
))
1508 || !bfd_set_section_alignment (abfd
, s
, 3))
1510 elf64_hppa_hash_table (info
)->opd_rel_sec
= s
;
1515 /* Allocate dynamic relocations for those symbols that turned out
1519 allocate_dynrel_entries (dyn_h
, data
)
1520 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
1523 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1524 struct elf64_hppa_link_hash_table
*hppa_info
;
1525 struct elf64_hppa_dyn_reloc_entry
*rent
;
1526 boolean dynamic_symbol
, shared
;
1528 hppa_info
= elf64_hppa_hash_table (x
->info
);
1529 dynamic_symbol
= elf64_hppa_dynamic_symbol_p (dyn_h
->h
, x
->info
);
1530 shared
= x
->info
->shared
;
1532 /* We may need to allocate relocations for a non-dynamic symbol
1533 when creating a shared library. */
1534 if (!dynamic_symbol
&& !shared
)
1537 /* Take care of the normal data relocations. */
1539 for (rent
= dyn_h
->reloc_entries
; rent
; rent
= rent
->next
)
1541 /* Allocate one iff we are building a shared library, the relocation
1542 isn't a R_PARISC_FPTR64, or we don't want an opd entry. */
1543 if (!shared
&& rent
->type
== R_PARISC_FPTR64
&& dyn_h
->want_opd
)
1546 hppa_info
->other_rel_sec
->_raw_size
+= sizeof (Elf64_External_Rela
);
1548 /* Make sure this symbol gets into the dynamic symbol table if it is
1549 not already recorded. ?!? This should not be in the loop since
1550 the symbol need only be added once. */
1552 || (dyn_h
->h
->dynindx
== -1 && dyn_h
->h
->type
!= STT_PARISC_MILLI
))
1553 if (!_bfd_elf64_link_record_local_dynamic_symbol
1554 (x
->info
, rent
->sec
->owner
, dyn_h
->sym_indx
))
1558 /* Take care of the GOT and PLT relocations. */
1560 if ((dynamic_symbol
|| shared
) && dyn_h
->want_dlt
)
1561 hppa_info
->dlt_rel_sec
->_raw_size
+= sizeof (Elf64_External_Rela
);
1563 /* If we are building a shared library, then every symbol that has an
1564 opd entry will need an EPLT relocation to relocate the symbol's address
1565 and __gp value based on the runtime load address. */
1566 if (shared
&& dyn_h
->want_opd
)
1567 hppa_info
->opd_rel_sec
->_raw_size
+= sizeof (Elf64_External_Rela
);
1569 if (dyn_h
->want_plt
&& dynamic_symbol
)
1571 bfd_size_type t
= 0;
1573 /* Dynamic symbols get one IPLT relocation. Local symbols in
1574 shared libraries get two REL relocations. Local symbols in
1575 main applications get nothing. */
1577 t
= sizeof (Elf64_External_Rela
);
1579 t
= 2 * sizeof (Elf64_External_Rela
);
1581 hppa_info
->plt_rel_sec
->_raw_size
+= t
;
1587 /* Adjust a symbol defined by a dynamic object and referenced by a
1591 elf64_hppa_adjust_dynamic_symbol (info
, h
)
1592 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1593 struct elf_link_hash_entry
*h
;
1595 /* ??? Undefined symbols with PLT entries should be re-defined
1596 to be the PLT entry. */
1598 /* If this is a weak symbol, and there is a real definition, the
1599 processor independent code will have arranged for us to see the
1600 real definition first, and we can just use the same value. */
1601 if (h
->weakdef
!= NULL
)
1603 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
1604 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
1605 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1606 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1610 /* If this is a reference to a symbol defined by a dynamic object which
1611 is not a function, we might allocate the symbol in our .dynbss section
1612 and allocate a COPY dynamic relocation.
1614 But PA64 code is canonically PIC, so as a rule we can avoid this sort
1620 /* This function is called via elf_link_hash_traverse to mark millicode
1621 symbols with a dynindx of -1 and to remove the string table reference
1622 from the dynamic symbol table. If the symbol is not a millicode symbol,
1623 elf64_hppa_mark_exported_functions is called. */
1626 elf64_hppa_mark_milli_and_exported_functions (h
, data
)
1627 struct elf_link_hash_entry
*h
;
1630 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
1631 struct elf_link_hash_entry
*elf
= h
;
1633 if (elf
->root
.type
== bfd_link_hash_warning
)
1634 elf
= (struct elf_link_hash_entry
*) elf
->root
.u
.i
.link
;
1636 if (elf
->type
== STT_PARISC_MILLI
)
1638 if (elf
->dynindx
!= -1)
1641 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
1647 return elf64_hppa_mark_exported_functions (h
, data
);
1650 /* Set the final sizes of the dynamic sections and allocate memory for
1651 the contents of our special sections. */
1654 elf64_hppa_size_dynamic_sections (output_bfd
, info
)
1656 struct bfd_link_info
*info
;
1663 struct elf64_hppa_allocate_data data
;
1664 struct elf64_hppa_link_hash_table
*hppa_info
;
1666 hppa_info
= elf64_hppa_hash_table (info
);
1668 dynobj
= elf_hash_table (info
)->dynobj
;
1669 BFD_ASSERT (dynobj
!= NULL
);
1671 /* Mark each function this program exports so that we will allocate
1672 space in the .opd section for each function's FPTR. If we are
1673 creating dynamic sections, change the dynamic index of millicode
1674 symbols to -1 and remove them from the string table for .dynstr.
1676 We have to traverse the main linker hash table since we have to
1677 find functions which may not have been mentioned in any relocs. */
1678 elf_link_hash_traverse (elf_hash_table (info
),
1679 (elf_hash_table (info
)->dynamic_sections_created
1680 ? elf64_hppa_mark_milli_and_exported_functions
1681 : elf64_hppa_mark_exported_functions
),
1684 if (elf_hash_table (info
)->dynamic_sections_created
)
1686 /* Set the contents of the .interp section to the interpreter. */
1689 s
= bfd_get_section_by_name (dynobj
, ".interp");
1690 BFD_ASSERT (s
!= NULL
);
1691 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1692 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1697 /* We may have created entries in the .rela.got section.
1698 However, if we are not creating the dynamic sections, we will
1699 not actually use these entries. Reset the size of .rela.dlt,
1700 which will cause it to get stripped from the output file
1702 s
= bfd_get_section_by_name (dynobj
, ".rela.dlt");
1707 /* Allocate the GOT entries. */
1710 if (elf64_hppa_hash_table (info
)->dlt_sec
)
1713 elf64_hppa_dyn_hash_traverse (&hppa_info
->dyn_hash_table
,
1714 allocate_global_data_dlt
, &data
);
1715 hppa_info
->dlt_sec
->_raw_size
= data
.ofs
;
1718 elf64_hppa_dyn_hash_traverse (&hppa_info
->dyn_hash_table
,
1719 allocate_global_data_plt
, &data
);
1720 hppa_info
->plt_sec
->_raw_size
= data
.ofs
;
1723 elf64_hppa_dyn_hash_traverse (&hppa_info
->dyn_hash_table
,
1724 allocate_global_data_stub
, &data
);
1725 hppa_info
->stub_sec
->_raw_size
= data
.ofs
;
1728 /* Allocate space for entries in the .opd section. */
1729 if (elf64_hppa_hash_table (info
)->opd_sec
)
1732 elf64_hppa_dyn_hash_traverse (&hppa_info
->dyn_hash_table
,
1733 allocate_global_data_opd
, &data
);
1734 hppa_info
->opd_sec
->_raw_size
= data
.ofs
;
1737 /* Now allocate space for dynamic relocations, if necessary. */
1738 if (hppa_info
->root
.dynamic_sections_created
)
1739 elf64_hppa_dyn_hash_traverse (&hppa_info
->dyn_hash_table
,
1740 allocate_dynrel_entries
, &data
);
1742 /* The sizes of all the sections are set. Allocate memory for them. */
1746 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1751 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
1754 /* It's OK to base decisions on the section name, because none
1755 of the dynobj section names depend upon the input files. */
1756 name
= bfd_get_section_name (dynobj
, s
);
1760 if (strcmp (name
, ".plt") == 0)
1762 /* Strip this section if we don't need it; see the comment below. */
1763 if (s
->_raw_size
== 0)
1769 /* Remember whether there is a PLT. */
1773 else if (strcmp (name
, ".dlt") == 0)
1775 /* Strip this section if we don't need it; see the comment below. */
1776 if (s
->_raw_size
== 0)
1781 else if (strcmp (name
, ".opd") == 0)
1783 /* Strip this section if we don't need it; see the comment below. */
1784 if (s
->_raw_size
== 0)
1789 else if (strncmp (name
, ".rela", 5) == 0)
1791 /* If we don't need this section, strip it from the output file.
1792 This is mostly to handle .rela.bss and .rela.plt. We must
1793 create both sections in create_dynamic_sections, because they
1794 must be created before the linker maps input sections to output
1795 sections. The linker does that before adjust_dynamic_symbol
1796 is called, and it is that function which decides whether
1797 anything needs to go into these sections. */
1798 if (s
->_raw_size
== 0)
1800 /* If we don't need this section, strip it from the
1801 output file. This is mostly to handle .rela.bss and
1802 .rela.plt. We must create both sections in
1803 create_dynamic_sections, because they must be created
1804 before the linker maps input sections to output
1805 sections. The linker does that before
1806 adjust_dynamic_symbol is called, and it is that
1807 function which decides whether anything needs to go
1808 into these sections. */
1815 /* Remember whether there are any reloc sections other
1817 if (strcmp (name
, ".rela.plt") != 0)
1819 const char *outname
;
1823 /* If this relocation section applies to a read only
1824 section, then we probably need a DT_TEXTREL
1825 entry. The entries in the .rela.plt section
1826 really apply to the .got section, which we
1827 created ourselves and so know is not readonly. */
1828 outname
= bfd_get_section_name (output_bfd
,
1830 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
1832 && (target
->flags
& SEC_READONLY
) != 0
1833 && (target
->flags
& SEC_ALLOC
) != 0)
1837 /* We use the reloc_count field as a counter if we need
1838 to copy relocs into the output file. */
1842 else if (strncmp (name
, ".dlt", 4) != 0
1843 && strcmp (name
, ".stub") != 0
1844 && strcmp (name
, ".got") != 0)
1846 /* It's not one of our sections, so don't allocate space. */
1852 _bfd_strip_section_from_output (info
, s
);
1856 /* Allocate memory for the section contents if it has not
1857 been allocated already. We use bfd_zalloc here in case
1858 unused entries are not reclaimed before the section's
1859 contents are written out. This should not happen, but this
1860 way if it does, we get a R_PARISC_NONE reloc instead of
1862 if (s
->contents
== NULL
)
1864 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
1865 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
1870 if (elf_hash_table (info
)->dynamic_sections_created
)
1872 /* Always create a DT_PLTGOT. It actually has nothing to do with
1873 the PLT, it is how we communicate the __gp value of a load
1874 module to the dynamic linker. */
1875 #define add_dynamic_entry(TAG, VAL) \
1876 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
1878 if (!add_dynamic_entry (DT_HP_DLD_FLAGS
, 0)
1879 || !add_dynamic_entry (DT_PLTGOT
, 0))
1882 /* Add some entries to the .dynamic section. We fill in the
1883 values later, in elf64_hppa_finish_dynamic_sections, but we
1884 must add the entries now so that we get the correct size for
1885 the .dynamic section. The DT_DEBUG entry is filled in by the
1886 dynamic linker and used by the debugger. */
1889 if (!add_dynamic_entry (DT_DEBUG
, 0)
1890 || !add_dynamic_entry (DT_HP_DLD_HOOK
, 0)
1891 || !add_dynamic_entry (DT_HP_LOAD_MAP
, 0))
1897 if (!add_dynamic_entry (DT_PLTRELSZ
, 0)
1898 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
1899 || !add_dynamic_entry (DT_JMPREL
, 0))
1905 if (!add_dynamic_entry (DT_RELA
, 0)
1906 || !add_dynamic_entry (DT_RELASZ
, 0)
1907 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
1913 if (!add_dynamic_entry (DT_TEXTREL
, 0))
1915 info
->flags
|= DF_TEXTREL
;
1918 #undef add_dynamic_entry
1923 /* Called after we have output the symbol into the dynamic symbol
1924 table, but before we output the symbol into the normal symbol
1927 For some symbols we had to change their address when outputting
1928 the dynamic symbol table. We undo that change here so that
1929 the symbols have their expected value in the normal symbol
1933 elf64_hppa_link_output_symbol_hook (abfd
, info
, name
, sym
, input_sec
)
1934 bfd
*abfd ATTRIBUTE_UNUSED
;
1935 struct bfd_link_info
*info
;
1937 Elf_Internal_Sym
*sym
;
1938 asection
*input_sec ATTRIBUTE_UNUSED
;
1940 struct elf64_hppa_link_hash_table
*hppa_info
;
1941 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
1943 /* We may be called with the file symbol or section symbols.
1944 They never need munging, so it is safe to ignore them. */
1948 /* Get the PA dyn_symbol (if any) associated with NAME. */
1949 hppa_info
= elf64_hppa_hash_table (info
);
1950 dyn_h
= elf64_hppa_dyn_hash_lookup (&hppa_info
->dyn_hash_table
,
1951 name
, false, false);
1953 /* Function symbols for which we created .opd entries *may* have been
1954 munged by finish_dynamic_symbol and have to be un-munged here.
1956 Note that finish_dynamic_symbol sometimes turns dynamic symbols
1957 into non-dynamic ones, so we initialize st_shndx to -1 in
1958 mark_exported_functions and check to see if it was overwritten
1959 here instead of just checking dyn_h->h->dynindx. */
1960 if (dyn_h
&& dyn_h
->want_opd
&& dyn_h
->st_shndx
!= -1)
1962 /* Restore the saved value and section index. */
1963 sym
->st_value
= dyn_h
->st_value
;
1964 sym
->st_shndx
= dyn_h
->st_shndx
;
1970 /* Finish up dynamic symbol handling. We set the contents of various
1971 dynamic sections here. */
1974 elf64_hppa_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
1976 struct bfd_link_info
*info
;
1977 struct elf_link_hash_entry
*h
;
1978 Elf_Internal_Sym
*sym
;
1980 asection
*stub
, *splt
, *sdlt
, *sopd
, *spltrel
, *sdltrel
;
1981 struct elf64_hppa_link_hash_table
*hppa_info
;
1982 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
1984 hppa_info
= elf64_hppa_hash_table (info
);
1985 dyn_h
= elf64_hppa_dyn_hash_lookup (&hppa_info
->dyn_hash_table
,
1986 h
->root
.root
.string
, false, false);
1988 stub
= hppa_info
->stub_sec
;
1989 splt
= hppa_info
->plt_sec
;
1990 sdlt
= hppa_info
->dlt_sec
;
1991 sopd
= hppa_info
->opd_sec
;
1992 spltrel
= hppa_info
->plt_rel_sec
;
1993 sdltrel
= hppa_info
->dlt_rel_sec
;
1995 /* Incredible. It is actually necessary to NOT use the symbol's real
1996 value when building the dynamic symbol table for a shared library.
1997 At least for symbols that refer to functions.
1999 We will store a new value and section index into the symbol long
2000 enough to output it into the dynamic symbol table, then we restore
2001 the original values (in elf64_hppa_link_output_symbol_hook). */
2002 if (dyn_h
&& dyn_h
->want_opd
)
2004 BFD_ASSERT (sopd
!= NULL
)
2006 /* Save away the original value and section index so that we
2007 can restore them later. */
2008 dyn_h
->st_value
= sym
->st_value
;
2009 dyn_h
->st_shndx
= sym
->st_shndx
;
2011 /* For the dynamic symbol table entry, we want the value to be
2012 address of this symbol's entry within the .opd section. */
2013 sym
->st_value
= (dyn_h
->opd_offset
2014 + sopd
->output_offset
2015 + sopd
->output_section
->vma
);
2016 sym
->st_shndx
= _bfd_elf_section_from_bfd_section (output_bfd
,
2017 sopd
->output_section
);
2020 /* Initialize a .plt entry if requested. */
2021 if (dyn_h
&& dyn_h
->want_plt
2022 && elf64_hppa_dynamic_symbol_p (dyn_h
->h
, info
))
2025 Elf_Internal_Rela rel
;
2027 BFD_ASSERT (splt
!= NULL
&& spltrel
!= NULL
)
2029 /* We do not actually care about the value in the PLT entry
2030 if we are creating a shared library and the symbol is
2031 still undefined, we create a dynamic relocation to fill
2032 in the correct value. */
2033 if (info
->shared
&& h
->root
.type
== bfd_link_hash_undefined
)
2036 value
= (h
->root
.u
.def
.value
+ h
->root
.u
.def
.section
->vma
);
2038 /* Fill in the entry in the procedure linkage table.
2040 The format of a plt entry is
2043 plt_offset is the offset within the PLT section at which to
2044 install the PLT entry.
2046 We are modifying the in-memory PLT contents here, so we do not add
2047 in the output_offset of the PLT section. */
2049 bfd_put_64 (splt
->owner
, value
, splt
->contents
+ dyn_h
->plt_offset
);
2050 value
= _bfd_get_gp_value (splt
->output_section
->owner
);
2051 bfd_put_64 (splt
->owner
, value
, splt
->contents
+ dyn_h
->plt_offset
+ 0x8);
2053 /* Create a dynamic IPLT relocation for this entry.
2055 We are creating a relocation in the output file's PLT section,
2056 which is included within the DLT secton. So we do need to include
2057 the PLT's output_offset in the computation of the relocation's
2059 rel
.r_offset
= (dyn_h
->plt_offset
+ splt
->output_offset
2060 + splt
->output_section
->vma
);
2061 rel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PARISC_IPLT
);
2064 bfd_elf64_swap_reloca_out (splt
->output_section
->owner
, &rel
,
2065 (((Elf64_External_Rela
*)
2067 + spltrel
->reloc_count
));
2068 spltrel
->reloc_count
++;
2071 /* Initialize an external call stub entry if requested. */
2072 if (dyn_h
&& dyn_h
->want_stub
2073 && elf64_hppa_dynamic_symbol_p (dyn_h
->h
, info
))
2077 unsigned int max_offset
;
2079 BFD_ASSERT (stub
!= NULL
)
2081 /* Install the generic stub template.
2083 We are modifying the contents of the stub section, so we do not
2084 need to include the stub section's output_offset here. */
2085 memcpy (stub
->contents
+ dyn_h
->stub_offset
, plt_stub
, sizeof (plt_stub
));
2087 /* Fix up the first ldd instruction.
2089 We are modifying the contents of the STUB section in memory,
2090 so we do not need to include its output offset in this computation.
2092 Note the plt_offset value is the value of the PLT entry relative to
2093 the start of the PLT section. These instructions will reference
2094 data relative to the value of __gp, which may not necessarily have
2095 the same address as the start of the PLT section.
2097 gp_offset contains the offset of __gp within the PLT section. */
2098 value
= dyn_h
->plt_offset
- hppa_info
->gp_offset
;
2100 insn
= bfd_get_32 (stub
->owner
, stub
->contents
+ dyn_h
->stub_offset
);
2101 if (output_bfd
->arch_info
->mach
>= 25)
2103 /* Wide mode allows 16 bit offsets. */
2106 insn
|= re_assemble_16 ((int) value
);
2112 insn
|= re_assemble_14 ((int) value
);
2115 if ((value
& 7) || value
+ max_offset
>= 2*max_offset
- 8)
2117 (*_bfd_error_handler
) (_("stub entry for %s cannot load .plt, dp offset = %ld"),
2123 bfd_put_32 (stub
->owner
, (bfd_vma
) insn
,
2124 stub
->contents
+ dyn_h
->stub_offset
);
2126 /* Fix up the second ldd instruction. */
2128 insn
= bfd_get_32 (stub
->owner
, stub
->contents
+ dyn_h
->stub_offset
+ 8);
2129 if (output_bfd
->arch_info
->mach
>= 25)
2132 insn
|= re_assemble_16 ((int) value
);
2137 insn
|= re_assemble_14 ((int) value
);
2139 bfd_put_32 (stub
->owner
, (bfd_vma
) insn
,
2140 stub
->contents
+ dyn_h
->stub_offset
+ 8);
2146 /* The .opd section contains FPTRs for each function this file
2147 exports. Initialize the FPTR entries. */
2150 elf64_hppa_finalize_opd (dyn_h
, data
)
2151 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
2154 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
2155 struct elf64_hppa_link_hash_table
*hppa_info
;
2156 struct elf_link_hash_entry
*h
= dyn_h
? dyn_h
->h
: NULL
;
2160 hppa_info
= elf64_hppa_hash_table (info
);
2161 sopd
= hppa_info
->opd_sec
;
2162 sopdrel
= hppa_info
->opd_rel_sec
;
2164 if (h
&& dyn_h
->want_opd
)
2168 /* The first two words of an .opd entry are zero.
2170 We are modifying the contents of the OPD section in memory, so we
2171 do not need to include its output offset in this computation. */
2172 memset (sopd
->contents
+ dyn_h
->opd_offset
, 0, 16);
2174 value
= (h
->root
.u
.def
.value
2175 + h
->root
.u
.def
.section
->output_section
->vma
2176 + h
->root
.u
.def
.section
->output_offset
);
2178 /* The next word is the address of the function. */
2179 bfd_put_64 (sopd
->owner
, value
, sopd
->contents
+ dyn_h
->opd_offset
+ 16);
2181 /* The last word is our local __gp value. */
2182 value
= _bfd_get_gp_value (sopd
->output_section
->owner
);
2183 bfd_put_64 (sopd
->owner
, value
, sopd
->contents
+ dyn_h
->opd_offset
+ 24);
2186 /* If we are generating a shared library, we must generate EPLT relocations
2187 for each entry in the .opd, even for static functions (they may have
2188 had their address taken). */
2189 if (info
->shared
&& dyn_h
&& dyn_h
->want_opd
)
2191 Elf64_Internal_Rela rel
;
2194 /* We may need to do a relocation against a local symbol, in
2195 which case we have to look up it's dynamic symbol index off
2196 the local symbol hash table. */
2197 if (h
&& h
->dynindx
!= -1)
2198 dynindx
= h
->dynindx
;
2201 = _bfd_elf_link_lookup_local_dynindx (info
, dyn_h
->owner
,
2204 /* The offset of this relocation is the absolute address of the
2205 .opd entry for this symbol. */
2206 rel
.r_offset
= (dyn_h
->opd_offset
+ sopd
->output_offset
2207 + sopd
->output_section
->vma
);
2209 /* If H is non-null, then we have an external symbol.
2211 It is imperative that we use a different dynamic symbol for the
2212 EPLT relocation if the symbol has global scope.
2214 In the dynamic symbol table, the function symbol will have a value
2215 which is address of the function's .opd entry.
2217 Thus, we can not use that dynamic symbol for the EPLT relocation
2218 (if we did, the data in the .opd would reference itself rather
2219 than the actual address of the function). Instead we have to use
2220 a new dynamic symbol which has the same value as the original global
2223 We prefix the original symbol with a "." and use the new symbol in
2224 the EPLT relocation. This new symbol has already been recorded in
2225 the symbol table, we just have to look it up and use it.
2227 We do not have such problems with static functions because we do
2228 not make their addresses in the dynamic symbol table point to
2229 the .opd entry. Ultimately this should be safe since a static
2230 function can not be directly referenced outside of its shared
2233 We do have to play similar games for FPTR relocations in shared
2234 libraries, including those for static symbols. See the FPTR
2235 handling in elf64_hppa_finalize_dynreloc. */
2239 struct elf_link_hash_entry
*nh
;
2241 new_name
= alloca (strlen (h
->root
.root
.string
) + 2);
2243 strcpy (new_name
+ 1, h
->root
.root
.string
);
2245 nh
= elf_link_hash_lookup (elf_hash_table (info
),
2246 new_name
, false, false, false);
2248 /* All we really want from the new symbol is its dynamic
2250 dynindx
= nh
->dynindx
;
2254 rel
.r_info
= ELF64_R_INFO (dynindx
, R_PARISC_EPLT
);
2256 bfd_elf64_swap_reloca_out (sopd
->output_section
->owner
, &rel
,
2257 (((Elf64_External_Rela
*)
2259 + sopdrel
->reloc_count
));
2260 sopdrel
->reloc_count
++;
2265 /* The .dlt section contains addresses for items referenced through the
2266 dlt. Note that we can have a DLTIND relocation for a local symbol, thus
2267 we can not depend on finish_dynamic_symbol to initialize the .dlt. */
2270 elf64_hppa_finalize_dlt (dyn_h
, data
)
2271 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
2274 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
2275 struct elf64_hppa_link_hash_table
*hppa_info
;
2276 asection
*sdlt
, *sdltrel
;
2277 struct elf_link_hash_entry
*h
= dyn_h
? dyn_h
->h
: NULL
;
2279 hppa_info
= elf64_hppa_hash_table (info
);
2281 sdlt
= hppa_info
->dlt_sec
;
2282 sdltrel
= hppa_info
->dlt_rel_sec
;
2284 /* H/DYN_H may refer to a local variable and we know it's
2285 address, so there is no need to create a relocation. Just install
2286 the proper value into the DLT, note this shortcut can not be
2287 skipped when building a shared library. */
2288 if (! info
->shared
&& h
&& dyn_h
->want_dlt
)
2292 /* If we had an LTOFF_FPTR style relocation we want the DLT entry
2293 to point to the FPTR entry in the .opd section.
2295 We include the OPD's output offset in this computation as
2296 we are referring to an absolute address in the resulting
2298 if (dyn_h
->want_opd
)
2300 value
= (dyn_h
->opd_offset
2301 + hppa_info
->opd_sec
->output_offset
2302 + hppa_info
->opd_sec
->output_section
->vma
);
2304 else if (h
->root
.u
.def
.section
)
2306 value
= h
->root
.u
.def
.value
+ h
->root
.u
.def
.section
->output_offset
;
2307 if (h
->root
.u
.def
.section
->output_section
)
2308 value
+= h
->root
.u
.def
.section
->output_section
->vma
;
2310 value
+= h
->root
.u
.def
.section
->vma
;
2313 /* We have an undefined function reference. */
2316 /* We do not need to include the output offset of the DLT section
2317 here because we are modifying the in-memory contents. */
2318 bfd_put_64 (sdlt
->owner
, value
, sdlt
->contents
+ dyn_h
->dlt_offset
);
2321 /* Create a relocation for the DLT entry assocated with this symbol.
2322 When building a shared library the symbol does not have to be dynamic. */
2324 && (elf64_hppa_dynamic_symbol_p (dyn_h
->h
, info
) || info
->shared
))
2326 Elf64_Internal_Rela rel
;
2329 /* We may need to do a relocation against a local symbol, in
2330 which case we have to look up it's dynamic symbol index off
2331 the local symbol hash table. */
2332 if (h
&& h
->dynindx
!= -1)
2333 dynindx
= h
->dynindx
;
2336 = _bfd_elf_link_lookup_local_dynindx (info
, dyn_h
->owner
,
2339 /* Create a dynamic relocation for this entry. Do include the output
2340 offset of the DLT entry since we need an absolute address in the
2341 resulting object file. */
2342 rel
.r_offset
= (dyn_h
->dlt_offset
+ sdlt
->output_offset
2343 + sdlt
->output_section
->vma
);
2344 if (h
&& h
->type
== STT_FUNC
)
2345 rel
.r_info
= ELF64_R_INFO (dynindx
, R_PARISC_FPTR64
);
2347 rel
.r_info
= ELF64_R_INFO (dynindx
, R_PARISC_DIR64
);
2350 bfd_elf64_swap_reloca_out (sdlt
->output_section
->owner
, &rel
,
2351 (((Elf64_External_Rela
*)
2353 + sdltrel
->reloc_count
));
2354 sdltrel
->reloc_count
++;
2359 /* Finalize the dynamic relocations. Specifically the FPTR relocations
2360 for dynamic functions used to initialize static data. */
2363 elf64_hppa_finalize_dynreloc (dyn_h
, data
)
2364 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
2367 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
2368 struct elf64_hppa_link_hash_table
*hppa_info
;
2369 struct elf_link_hash_entry
*h
;
2372 dynamic_symbol
= elf64_hppa_dynamic_symbol_p (dyn_h
->h
, info
);
2374 if (!dynamic_symbol
&& !info
->shared
)
2377 if (dyn_h
->reloc_entries
)
2379 struct elf64_hppa_dyn_reloc_entry
*rent
;
2382 hppa_info
= elf64_hppa_hash_table (info
);
2385 /* We may need to do a relocation against a local symbol, in
2386 which case we have to look up it's dynamic symbol index off
2387 the local symbol hash table. */
2388 if (h
&& h
->dynindx
!= -1)
2389 dynindx
= h
->dynindx
;
2392 = _bfd_elf_link_lookup_local_dynindx (info
, dyn_h
->owner
,
2395 for (rent
= dyn_h
->reloc_entries
; rent
; rent
= rent
->next
)
2397 Elf64_Internal_Rela rel
;
2399 /* Allocate one iff we are building a shared library, the relocation
2400 isn't a R_PARISC_FPTR64, or we don't want an opd entry. */
2401 if (!info
->shared
&& rent
->type
== R_PARISC_FPTR64
&& dyn_h
->want_opd
)
2404 /* Create a dynamic relocation for this entry.
2406 We need the output offset for the reloc's section because
2407 we are creating an absolute address in the resulting object
2409 rel
.r_offset
= (rent
->offset
+ rent
->sec
->output_offset
2410 + rent
->sec
->output_section
->vma
);
2412 /* An FPTR64 relocation implies that we took the address of
2413 a function and that the function has an entry in the .opd
2414 section. We want the FPTR64 relocation to reference the
2417 We could munge the symbol value in the dynamic symbol table
2418 (in fact we already do for functions with global scope) to point
2419 to the .opd entry. Then we could use that dynamic symbol in
2422 Or we could do something sensible, not munge the symbol's
2423 address and instead just use a different symbol to reference
2424 the .opd entry. At least that seems sensible until you
2425 realize there's no local dynamic symbols we can use for that
2426 purpose. Thus the hair in the check_relocs routine.
2428 We use a section symbol recorded by check_relocs as the
2429 base symbol for the relocation. The addend is the difference
2430 between the section symbol and the address of the .opd entry. */
2431 if (info
->shared
&& rent
->type
== R_PARISC_FPTR64
&& dyn_h
->want_opd
)
2433 bfd_vma value
, value2
;
2435 /* First compute the address of the opd entry for this symbol. */
2436 value
= (dyn_h
->opd_offset
2437 + hppa_info
->opd_sec
->output_section
->vma
2438 + hppa_info
->opd_sec
->output_offset
);
2440 /* Compute the value of the start of the section with
2442 value2
= (rent
->sec
->output_section
->vma
2443 + rent
->sec
->output_offset
);
2445 /* Compute the difference between the start of the section
2446 with the relocation and the opd entry. */
2449 /* The result becomes the addend of the relocation. */
2450 rel
.r_addend
= value
;
2452 /* The section symbol becomes the symbol for the dynamic
2455 = _bfd_elf_link_lookup_local_dynindx (info
,
2460 rel
.r_addend
= rent
->addend
;
2462 rel
.r_info
= ELF64_R_INFO (dynindx
, rent
->type
);
2464 bfd_elf64_swap_reloca_out (hppa_info
->other_rel_sec
->output_section
->owner
,
2466 (((Elf64_External_Rela
*)
2467 hppa_info
->other_rel_sec
->contents
)
2468 + hppa_info
->other_rel_sec
->reloc_count
));
2469 hppa_info
->other_rel_sec
->reloc_count
++;
2476 /* Used to decide how to sort relocs in an optimal manner for the
2477 dynamic linker, before writing them out. */
2479 static enum elf_reloc_type_class
2480 elf64_hppa_reloc_type_class (rela
)
2481 const Elf_Internal_Rela
*rela
;
2483 if (ELF64_R_SYM (rela
->r_info
) == 0)
2484 return reloc_class_relative
;
2486 switch ((int) ELF64_R_TYPE (rela
->r_info
))
2489 return reloc_class_plt
;
2491 return reloc_class_copy
;
2493 return reloc_class_normal
;
2497 /* Finish up the dynamic sections. */
2500 elf64_hppa_finish_dynamic_sections (output_bfd
, info
)
2502 struct bfd_link_info
*info
;
2506 struct elf64_hppa_link_hash_table
*hppa_info
;
2508 hppa_info
= elf64_hppa_hash_table (info
);
2510 /* Finalize the contents of the .opd section. */
2511 elf64_hppa_dyn_hash_traverse (&hppa_info
->dyn_hash_table
,
2512 elf64_hppa_finalize_opd
,
2515 elf64_hppa_dyn_hash_traverse (&hppa_info
->dyn_hash_table
,
2516 elf64_hppa_finalize_dynreloc
,
2519 /* Finalize the contents of the .dlt section. */
2520 dynobj
= elf_hash_table (info
)->dynobj
;
2521 /* Finalize the contents of the .dlt section. */
2522 elf64_hppa_dyn_hash_traverse (&hppa_info
->dyn_hash_table
,
2523 elf64_hppa_finalize_dlt
,
2526 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2528 if (elf_hash_table (info
)->dynamic_sections_created
)
2530 Elf64_External_Dyn
*dyncon
, *dynconend
;
2532 BFD_ASSERT (sdyn
!= NULL
);
2534 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
2535 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
2536 for (; dyncon
< dynconend
; dyncon
++)
2538 Elf_Internal_Dyn dyn
;
2541 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2548 case DT_HP_LOAD_MAP
:
2549 /* Compute the absolute address of 16byte scratchpad area
2550 for the dynamic linker.
2552 By convention the linker script will allocate the scratchpad
2553 area at the start of the .data section. So all we have to
2554 to is find the start of the .data section. */
2555 s
= bfd_get_section_by_name (output_bfd
, ".data");
2556 dyn
.d_un
.d_ptr
= s
->vma
;
2557 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2561 /* HP's use PLTGOT to set the GOT register. */
2562 dyn
.d_un
.d_ptr
= _bfd_get_gp_value (output_bfd
);
2563 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2567 s
= hppa_info
->plt_rel_sec
;
2568 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
2569 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2573 s
= hppa_info
->plt_rel_sec
;
2574 dyn
.d_un
.d_val
= s
->_raw_size
;
2575 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2579 s
= hppa_info
->other_rel_sec
;
2580 if (! s
|| ! s
->_raw_size
)
2581 s
= hppa_info
->dlt_rel_sec
;
2582 if (! s
|| ! s
->_raw_size
)
2583 s
= hppa_info
->opd_rel_sec
;
2584 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
2585 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2589 s
= hppa_info
->other_rel_sec
;
2590 dyn
.d_un
.d_val
= s
->_raw_size
;
2591 s
= hppa_info
->dlt_rel_sec
;
2592 dyn
.d_un
.d_val
+= s
->_raw_size
;
2593 s
= hppa_info
->opd_rel_sec
;
2594 dyn
.d_un
.d_val
+= s
->_raw_size
;
2595 /* There is some question about whether or not the size of
2596 the PLT relocs should be included here. HP's tools do
2597 it, so we'll emulate them. */
2598 s
= hppa_info
->plt_rel_sec
;
2599 dyn
.d_un
.d_val
+= s
->_raw_size
;
2600 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2610 /* Return the number of additional phdrs we will need.
2612 The generic ELF code only creates PT_PHDRs for executables. The HP
2613 dynamic linker requires PT_PHDRs for dynamic libraries too.
2615 This routine indicates that the backend needs one additional program
2616 header for that case.
2618 Note we do not have access to the link info structure here, so we have
2619 to guess whether or not we are building a shared library based on the
2620 existence of a .interp section. */
2623 elf64_hppa_additional_program_headers (abfd
)
2628 /* If we are creating a shared library, then we have to create a
2629 PT_PHDR segment. HP's dynamic linker chokes without it. */
2630 s
= bfd_get_section_by_name (abfd
, ".interp");
2636 /* Allocate and initialize any program headers required by this
2639 The generic ELF code only creates PT_PHDRs for executables. The HP
2640 dynamic linker requires PT_PHDRs for dynamic libraries too.
2642 This allocates the PT_PHDR and initializes it in a manner suitable
2645 Note we do not have access to the link info structure here, so we have
2646 to guess whether or not we are building a shared library based on the
2647 existence of a .interp section. */
2650 elf64_hppa_modify_segment_map (abfd
)
2653 struct elf_segment_map
*m
;
2656 s
= bfd_get_section_by_name (abfd
, ".interp");
2659 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2660 if (m
->p_type
== PT_PHDR
)
2664 m
= ((struct elf_segment_map
*)
2665 bfd_zalloc (abfd
, (bfd_size_type
) sizeof *m
));
2669 m
->p_type
= PT_PHDR
;
2670 m
->p_flags
= PF_R
| PF_X
;
2671 m
->p_flags_valid
= 1;
2672 m
->p_paddr_valid
= 1;
2673 m
->includes_phdrs
= 1;
2675 m
->next
= elf_tdata (abfd
)->segment_map
;
2676 elf_tdata (abfd
)->segment_map
= m
;
2680 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2681 if (m
->p_type
== PT_LOAD
)
2685 for (i
= 0; i
< m
->count
; i
++)
2687 /* The code "hint" is not really a hint. It is a requirement
2688 for certain versions of the HP dynamic linker. Worse yet,
2689 it must be set even if the shared library does not have
2690 any code in its "text" segment (thus the check for .hash
2691 to catch this situation). */
2692 if (m
->sections
[i
]->flags
& SEC_CODE
2693 || (strcmp (m
->sections
[i
]->name
, ".hash") == 0))
2694 m
->p_flags
|= (PF_X
| PF_HP_CODE
);
2701 /* Called when writing out an object file to decide the type of a
2704 elf64_hppa_elf_get_symbol_type (elf_sym
, type
)
2705 Elf_Internal_Sym
*elf_sym
;
2708 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_PARISC_MILLI
)
2709 return STT_PARISC_MILLI
;
2714 /* The hash bucket size is the standard one, namely 4. */
2716 const struct elf_size_info hppa64_elf_size_info
=
2718 sizeof (Elf64_External_Ehdr
),
2719 sizeof (Elf64_External_Phdr
),
2720 sizeof (Elf64_External_Shdr
),
2721 sizeof (Elf64_External_Rel
),
2722 sizeof (Elf64_External_Rela
),
2723 sizeof (Elf64_External_Sym
),
2724 sizeof (Elf64_External_Dyn
),
2725 sizeof (Elf_External_Note
),
2729 ELFCLASS64
, EV_CURRENT
,
2730 bfd_elf64_write_out_phdrs
,
2731 bfd_elf64_write_shdrs_and_ehdr
,
2732 bfd_elf64_write_relocs
,
2733 bfd_elf64_swap_symbol_in
,
2734 bfd_elf64_swap_symbol_out
,
2735 bfd_elf64_slurp_reloc_table
,
2736 bfd_elf64_slurp_symbol_table
,
2737 bfd_elf64_swap_dyn_in
,
2738 bfd_elf64_swap_dyn_out
,
2745 #define TARGET_BIG_SYM bfd_elf64_hppa_vec
2746 #define TARGET_BIG_NAME "elf64-hppa"
2747 #define ELF_ARCH bfd_arch_hppa
2748 #define ELF_MACHINE_CODE EM_PARISC
2749 /* This is not strictly correct. The maximum page size for PA2.0 is
2750 64M. But everything still uses 4k. */
2751 #define ELF_MAXPAGESIZE 0x1000
2752 #define bfd_elf64_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
2753 #define bfd_elf64_bfd_is_local_label_name elf_hppa_is_local_label_name
2754 #define elf_info_to_howto elf_hppa_info_to_howto
2755 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
2757 #define elf_backend_section_from_shdr elf64_hppa_section_from_shdr
2758 #define elf_backend_object_p elf64_hppa_object_p
2759 #define elf_backend_final_write_processing \
2760 elf_hppa_final_write_processing
2761 #define elf_backend_fake_sections elf_hppa_fake_sections
2762 #define elf_backend_add_symbol_hook elf_hppa_add_symbol_hook
2764 #define elf_backend_relocate_section elf_hppa_relocate_section
2766 #define bfd_elf64_bfd_final_link elf_hppa_final_link
2768 #define elf_backend_create_dynamic_sections \
2769 elf64_hppa_create_dynamic_sections
2770 #define elf_backend_post_process_headers elf64_hppa_post_process_headers
2772 #define elf_backend_adjust_dynamic_symbol \
2773 elf64_hppa_adjust_dynamic_symbol
2775 #define elf_backend_size_dynamic_sections \
2776 elf64_hppa_size_dynamic_sections
2778 #define elf_backend_finish_dynamic_symbol \
2779 elf64_hppa_finish_dynamic_symbol
2780 #define elf_backend_finish_dynamic_sections \
2781 elf64_hppa_finish_dynamic_sections
2783 /* Stuff for the BFD linker: */
2784 #define bfd_elf64_bfd_link_hash_table_create \
2785 elf64_hppa_hash_table_create
2787 #define elf_backend_check_relocs \
2788 elf64_hppa_check_relocs
2790 #define elf_backend_size_info \
2791 hppa64_elf_size_info
2793 #define elf_backend_additional_program_headers \
2794 elf64_hppa_additional_program_headers
2796 #define elf_backend_modify_segment_map \
2797 elf64_hppa_modify_segment_map
2799 #define elf_backend_link_output_symbol_hook \
2800 elf64_hppa_link_output_symbol_hook
2802 #define elf_backend_want_got_plt 0
2803 #define elf_backend_plt_readonly 0
2804 #define elf_backend_want_plt_sym 0
2805 #define elf_backend_got_header_size 0
2806 #define elf_backend_plt_header_size 0
2807 #define elf_backend_type_change_ok true
2808 #define elf_backend_get_symbol_type elf64_hppa_elf_get_symbol_type
2809 #define elf_backend_reloc_type_class elf64_hppa_reloc_type_class
2811 #include "elf64-target.h"
2813 #undef TARGET_BIG_SYM
2814 #define TARGET_BIG_SYM bfd_elf64_hppa_linux_vec
2815 #undef TARGET_BIG_NAME
2816 #define TARGET_BIG_NAME "elf64-hppa-linux"
2818 #define INCLUDED_TARGET_FILE 1
2819 #include "elf64-target.h"