1 /* Support for HPPA 64-bit ELF
2 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
3 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
22 #include "alloca-conf.h"
29 #include "elf64-hppa.h"
32 #define PLT_ENTRY_SIZE 0x10
33 #define DLT_ENTRY_SIZE 0x8
34 #define OPD_ENTRY_SIZE 0x20
36 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/pa20_64/dld.sl"
38 /* The stub is supposed to load the target address and target's DP
39 value out of the PLT, then do an external branch to the target
44 LDD PLTOFF+8(%r27),%r27
46 Note that we must use the LDD with a 14 bit displacement, not the one
47 with a 5 bit displacement. */
48 static char plt_stub
[] = {0x53, 0x61, 0x00, 0x00, 0xe8, 0x20, 0xd0, 0x00,
49 0x53, 0x7b, 0x00, 0x00 };
51 struct elf64_hppa_dyn_hash_entry
53 struct bfd_hash_entry root
;
55 /* Offsets for this symbol in various linker sections. */
61 /* The symbol table entry, if any, that this was derived from. */
62 struct elf_link_hash_entry
*h
;
64 /* The index of the (possibly local) symbol in the input bfd and its
65 associated BFD. Needed so that we can have relocs against local
66 symbols in shared libraries. */
70 /* Dynamic symbols may need to have two different values. One for
71 the dynamic symbol table, one for the normal symbol table.
73 In such cases we store the symbol's real value and section
74 index here so we can restore the real value before we write
75 the normal symbol table. */
79 /* Used to count non-got, non-plt relocations for delayed sizing
80 of relocation sections. */
81 struct elf64_hppa_dyn_reloc_entry
83 /* Next relocation in the chain. */
84 struct elf64_hppa_dyn_reloc_entry
*next
;
86 /* The type of the relocation. */
89 /* The input section of the relocation. */
92 /* The index of the section symbol for the input section of
93 the relocation. Only needed when building shared libraries. */
96 /* The offset within the input section of the relocation. */
99 /* The addend for the relocation. */
104 /* Nonzero if this symbol needs an entry in one of the linker
112 struct elf64_hppa_dyn_hash_table
114 struct bfd_hash_table root
;
117 struct elf64_hppa_link_hash_table
119 struct elf_link_hash_table root
;
121 /* Shortcuts to get to the various linker defined sections. */
123 asection
*dlt_rel_sec
;
125 asection
*plt_rel_sec
;
127 asection
*opd_rel_sec
;
128 asection
*other_rel_sec
;
130 /* Offset of __gp within .plt section. When the PLT gets large we want
131 to slide __gp into the PLT section so that we can continue to use
132 single DP relative instructions to load values out of the PLT. */
135 /* Note this is not strictly correct. We should create a stub section for
136 each input section with calls. The stub section should be placed before
137 the section with the call. */
140 bfd_vma text_segment_base
;
141 bfd_vma data_segment_base
;
143 struct elf64_hppa_dyn_hash_table dyn_hash_table
;
145 /* We build tables to map from an input section back to its
146 symbol index. This is the BFD for which we currently have
148 bfd
*section_syms_bfd
;
150 /* Array of symbol numbers for each input section attached to the
155 #define elf64_hppa_hash_table(p) \
156 ((struct elf64_hppa_link_hash_table *) ((p)->hash))
158 typedef struct bfd_hash_entry
*(*new_hash_entry_func
)
159 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
161 static struct bfd_hash_entry
*elf64_hppa_new_dyn_hash_entry
162 PARAMS ((struct bfd_hash_entry
*entry
, struct bfd_hash_table
*table
,
163 const char *string
));
164 static struct bfd_link_hash_table
*elf64_hppa_hash_table_create
165 PARAMS ((bfd
*abfd
));
166 static struct elf64_hppa_dyn_hash_entry
*elf64_hppa_dyn_hash_lookup
167 PARAMS ((struct elf64_hppa_dyn_hash_table
*table
, const char *string
,
168 bfd_boolean create
, bfd_boolean copy
));
169 static void elf64_hppa_dyn_hash_traverse
170 PARAMS ((struct elf64_hppa_dyn_hash_table
*table
,
171 bfd_boolean (*func
) (struct elf64_hppa_dyn_hash_entry
*, PTR
),
174 static const char *get_dyn_name
175 PARAMS ((bfd
*, struct elf_link_hash_entry
*,
176 const Elf_Internal_Rela
*, char **, size_t *));
178 /* This must follow the definitions of the various derived linker
179 hash tables and shared functions. */
180 #include "elf-hppa.h"
182 static bfd_boolean elf64_hppa_object_p
185 static void elf64_hppa_post_process_headers
186 PARAMS ((bfd
*, struct bfd_link_info
*));
188 static bfd_boolean elf64_hppa_create_dynamic_sections
189 PARAMS ((bfd
*, struct bfd_link_info
*));
191 static bfd_boolean elf64_hppa_adjust_dynamic_symbol
192 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
194 static bfd_boolean elf64_hppa_mark_milli_and_exported_functions
195 PARAMS ((struct elf_link_hash_entry
*, PTR
));
197 static bfd_boolean elf64_hppa_size_dynamic_sections
198 PARAMS ((bfd
*, struct bfd_link_info
*));
200 static bfd_boolean elf64_hppa_link_output_symbol_hook
201 PARAMS ((struct bfd_link_info
*, const char *, Elf_Internal_Sym
*,
202 asection
*, struct elf_link_hash_entry
*));
204 static bfd_boolean elf64_hppa_finish_dynamic_symbol
205 PARAMS ((bfd
*, struct bfd_link_info
*,
206 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
208 static enum elf_reloc_type_class elf64_hppa_reloc_type_class
209 PARAMS ((const Elf_Internal_Rela
*));
211 static bfd_boolean elf64_hppa_finish_dynamic_sections
212 PARAMS ((bfd
*, struct bfd_link_info
*));
214 static bfd_boolean elf64_hppa_check_relocs
215 PARAMS ((bfd
*, struct bfd_link_info
*,
216 asection
*, const Elf_Internal_Rela
*));
218 static bfd_boolean elf64_hppa_dynamic_symbol_p
219 PARAMS ((struct elf_link_hash_entry
*, struct bfd_link_info
*));
221 static bfd_boolean elf64_hppa_mark_exported_functions
222 PARAMS ((struct elf_link_hash_entry
*, PTR
));
224 static bfd_boolean elf64_hppa_finalize_opd
225 PARAMS ((struct elf64_hppa_dyn_hash_entry
*, PTR
));
227 static bfd_boolean elf64_hppa_finalize_dlt
228 PARAMS ((struct elf64_hppa_dyn_hash_entry
*, PTR
));
230 static bfd_boolean allocate_global_data_dlt
231 PARAMS ((struct elf64_hppa_dyn_hash_entry
*, PTR
));
233 static bfd_boolean allocate_global_data_plt
234 PARAMS ((struct elf64_hppa_dyn_hash_entry
*, PTR
));
236 static bfd_boolean allocate_global_data_stub
237 PARAMS ((struct elf64_hppa_dyn_hash_entry
*, PTR
));
239 static bfd_boolean allocate_global_data_opd
240 PARAMS ((struct elf64_hppa_dyn_hash_entry
*, PTR
));
242 static bfd_boolean get_reloc_section
243 PARAMS ((bfd
*, struct elf64_hppa_link_hash_table
*, asection
*));
245 static bfd_boolean count_dyn_reloc
246 PARAMS ((bfd
*, struct elf64_hppa_dyn_hash_entry
*,
247 int, asection
*, int, bfd_vma
, bfd_vma
));
249 static bfd_boolean allocate_dynrel_entries
250 PARAMS ((struct elf64_hppa_dyn_hash_entry
*, PTR
));
252 static bfd_boolean elf64_hppa_finalize_dynreloc
253 PARAMS ((struct elf64_hppa_dyn_hash_entry
*, PTR
));
255 static bfd_boolean get_opd
256 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*));
258 static bfd_boolean get_plt
259 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*));
261 static bfd_boolean get_dlt
262 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*));
264 static bfd_boolean get_stub
265 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*));
267 static int elf64_hppa_elf_get_symbol_type
268 PARAMS ((Elf_Internal_Sym
*, int));
271 elf64_hppa_dyn_hash_table_init (struct elf64_hppa_dyn_hash_table
*ht
,
272 bfd
*abfd ATTRIBUTE_UNUSED
,
273 new_hash_entry_func
new,
274 unsigned int entsize
)
276 memset (ht
, 0, sizeof (*ht
));
277 return bfd_hash_table_init (&ht
->root
, new, entsize
);
280 static struct bfd_hash_entry
*
281 elf64_hppa_new_dyn_hash_entry (entry
, table
, string
)
282 struct bfd_hash_entry
*entry
;
283 struct bfd_hash_table
*table
;
286 struct elf64_hppa_dyn_hash_entry
*ret
;
287 ret
= (struct elf64_hppa_dyn_hash_entry
*) entry
;
289 /* Allocate the structure if it has not already been allocated by a
292 ret
= bfd_hash_allocate (table
, sizeof (*ret
));
297 /* Call the allocation method of the superclass. */
298 ret
= ((struct elf64_hppa_dyn_hash_entry
*)
299 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
301 /* Initialize our local data. All zeros. */
302 memset (&ret
->dlt_offset
, 0,
303 (sizeof (struct elf64_hppa_dyn_hash_entry
)
304 - offsetof (struct elf64_hppa_dyn_hash_entry
, dlt_offset
)));
309 /* Create the derived linker hash table. The PA64 ELF port uses this
310 derived hash table to keep information specific to the PA ElF
311 linker (without using static variables). */
313 static struct bfd_link_hash_table
*
314 elf64_hppa_hash_table_create (abfd
)
317 struct elf64_hppa_link_hash_table
*ret
;
319 ret
= bfd_zalloc (abfd
, (bfd_size_type
) sizeof (*ret
));
322 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
323 _bfd_elf_link_hash_newfunc
,
324 sizeof (struct elf_link_hash_entry
)))
326 bfd_release (abfd
, ret
);
330 if (!elf64_hppa_dyn_hash_table_init (&ret
->dyn_hash_table
, abfd
,
331 elf64_hppa_new_dyn_hash_entry
,
332 sizeof (struct elf64_hppa_dyn_hash_entry
)))
334 return &ret
->root
.root
;
337 /* Look up an entry in a PA64 ELF linker hash table. */
339 static struct elf64_hppa_dyn_hash_entry
*
340 elf64_hppa_dyn_hash_lookup(table
, string
, create
, copy
)
341 struct elf64_hppa_dyn_hash_table
*table
;
343 bfd_boolean create
, copy
;
345 return ((struct elf64_hppa_dyn_hash_entry
*)
346 bfd_hash_lookup (&table
->root
, string
, create
, copy
));
349 /* Traverse a PA64 ELF linker hash table. */
352 elf64_hppa_dyn_hash_traverse (table
, func
, info
)
353 struct elf64_hppa_dyn_hash_table
*table
;
354 bfd_boolean (*func
) PARAMS ((struct elf64_hppa_dyn_hash_entry
*, PTR
));
359 (bfd_boolean (*) PARAMS ((struct bfd_hash_entry
*, PTR
))) func
,
363 /* Return nonzero if ABFD represents a PA2.0 ELF64 file.
365 Additionally we set the default architecture and machine. */
367 elf64_hppa_object_p (abfd
)
370 Elf_Internal_Ehdr
* i_ehdrp
;
373 i_ehdrp
= elf_elfheader (abfd
);
374 if (strcmp (bfd_get_target (abfd
), "elf64-hppa-linux") == 0)
376 /* GCC on hppa-linux produces binaries with OSABI=Linux,
377 but the kernel produces corefiles with OSABI=SysV. */
378 if (i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_LINUX
379 && i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_NONE
) /* aka SYSV */
384 /* HPUX produces binaries with OSABI=HPUX,
385 but the kernel produces corefiles with OSABI=SysV. */
386 if (i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_HPUX
387 && i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_NONE
) /* aka SYSV */
391 flags
= i_ehdrp
->e_flags
;
392 switch (flags
& (EF_PARISC_ARCH
| EF_PARISC_WIDE
))
395 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 10);
397 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 11);
399 if (i_ehdrp
->e_ident
[EI_CLASS
] == ELFCLASS64
)
400 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 25);
402 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 20);
403 case EFA_PARISC_2_0
| EF_PARISC_WIDE
:
404 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 25);
406 /* Don't be fussy. */
410 /* Given section type (hdr->sh_type), return a boolean indicating
411 whether or not the section is an elf64-hppa specific section. */
413 elf64_hppa_section_from_shdr (bfd
*abfd
,
414 Elf_Internal_Shdr
*hdr
,
420 switch (hdr
->sh_type
)
423 if (strcmp (name
, ".PARISC.archext") != 0)
426 case SHT_PARISC_UNWIND
:
427 if (strcmp (name
, ".PARISC.unwind") != 0)
431 case SHT_PARISC_ANNOT
:
436 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
438 newsect
= hdr
->bfd_section
;
443 /* Construct a string for use in the elf64_hppa_dyn_hash_table. The
444 name describes what was once potentially anonymous memory. We
445 allocate memory as necessary, possibly reusing PBUF/PLEN. */
448 get_dyn_name (abfd
, h
, rel
, pbuf
, plen
)
450 struct elf_link_hash_entry
*h
;
451 const Elf_Internal_Rela
*rel
;
455 asection
*sec
= abfd
->sections
;
460 if (h
&& rel
->r_addend
== 0)
461 return h
->root
.root
.string
;
464 nlen
= strlen (h
->root
.root
.string
);
466 nlen
= 8 + 1 + sizeof (rel
->r_info
) * 2 - 8;
467 tlen
= nlen
+ 1 + sizeof (rel
->r_addend
) * 2 + 1;
475 *pbuf
= buf
= malloc (tlen
);
483 memcpy (buf
, h
->root
.root
.string
, nlen
);
485 sprintf_vma (buf
+ nlen
, rel
->r_addend
);
489 nlen
= sprintf (buf
, "%x:%lx",
490 sec
->id
& 0xffffffff,
491 (long) ELF64_R_SYM (rel
->r_info
));
495 sprintf_vma (buf
+ nlen
, rel
->r_addend
);
502 /* SEC is a section containing relocs for an input BFD when linking; return
503 a suitable section for holding relocs in the output BFD for a link. */
506 get_reloc_section (abfd
, hppa_info
, sec
)
508 struct elf64_hppa_link_hash_table
*hppa_info
;
511 const char *srel_name
;
515 srel_name
= (bfd_elf_string_from_elf_section
516 (abfd
, elf_elfheader(abfd
)->e_shstrndx
,
517 elf_section_data(sec
)->rel_hdr
.sh_name
));
518 if (srel_name
== NULL
)
521 BFD_ASSERT ((CONST_STRNEQ (srel_name
, ".rela")
522 && strcmp (bfd_get_section_name (abfd
, sec
),
524 || (CONST_STRNEQ (srel_name
, ".rel")
525 && strcmp (bfd_get_section_name (abfd
, sec
),
526 srel_name
+ 4) == 0));
528 dynobj
= hppa_info
->root
.dynobj
;
530 hppa_info
->root
.dynobj
= dynobj
= abfd
;
532 srel
= bfd_get_section_by_name (dynobj
, srel_name
);
535 srel
= bfd_make_section_with_flags (dynobj
, srel_name
,
543 || !bfd_set_section_alignment (dynobj
, srel
, 3))
547 hppa_info
->other_rel_sec
= srel
;
551 /* Add a new entry to the list of dynamic relocations against DYN_H.
553 We use this to keep a record of all the FPTR relocations against a
554 particular symbol so that we can create FPTR relocations in the
558 count_dyn_reloc (abfd
, dyn_h
, type
, sec
, sec_symndx
, offset
, addend
)
560 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
567 struct elf64_hppa_dyn_reloc_entry
*rent
;
569 rent
= (struct elf64_hppa_dyn_reloc_entry
*)
570 bfd_alloc (abfd
, (bfd_size_type
) sizeof (*rent
));
574 rent
->next
= dyn_h
->reloc_entries
;
577 rent
->sec_symndx
= sec_symndx
;
578 rent
->offset
= offset
;
579 rent
->addend
= addend
;
580 dyn_h
->reloc_entries
= rent
;
585 /* Scan the RELOCS and record the type of dynamic entries that each
586 referenced symbol needs. */
589 elf64_hppa_check_relocs (abfd
, info
, sec
, relocs
)
591 struct bfd_link_info
*info
;
593 const Elf_Internal_Rela
*relocs
;
595 struct elf64_hppa_link_hash_table
*hppa_info
;
596 const Elf_Internal_Rela
*relend
;
597 Elf_Internal_Shdr
*symtab_hdr
;
598 const Elf_Internal_Rela
*rel
;
599 asection
*dlt
, *plt
, *stubs
;
604 if (info
->relocatable
)
607 /* If this is the first dynamic object found in the link, create
608 the special sections required for dynamic linking. */
609 if (! elf_hash_table (info
)->dynamic_sections_created
)
611 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
615 hppa_info
= elf64_hppa_hash_table (info
);
616 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
618 /* If necessary, build a new table holding section symbols indices
621 if (info
->shared
&& hppa_info
->section_syms_bfd
!= abfd
)
624 unsigned int highest_shndx
;
625 Elf_Internal_Sym
*local_syms
= NULL
;
626 Elf_Internal_Sym
*isym
, *isymend
;
629 /* We're done with the old cache of section index to section symbol
630 index information. Free it.
632 ?!? Note we leak the last section_syms array. Presumably we
633 could free it in one of the later routines in this file. */
634 if (hppa_info
->section_syms
)
635 free (hppa_info
->section_syms
);
637 /* Read this BFD's local symbols. */
638 if (symtab_hdr
->sh_info
!= 0)
640 local_syms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
641 if (local_syms
== NULL
)
642 local_syms
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
643 symtab_hdr
->sh_info
, 0,
645 if (local_syms
== NULL
)
649 /* Record the highest section index referenced by the local symbols. */
651 isymend
= local_syms
+ symtab_hdr
->sh_info
;
652 for (isym
= local_syms
; isym
< isymend
; isym
++)
654 if (isym
->st_shndx
> highest_shndx
)
655 highest_shndx
= isym
->st_shndx
;
658 /* Allocate an array to hold the section index to section symbol index
659 mapping. Bump by one since we start counting at zero. */
663 hppa_info
->section_syms
= (int *) bfd_malloc (amt
);
665 /* Now walk the local symbols again. If we find a section symbol,
666 record the index of the symbol into the section_syms array. */
667 for (i
= 0, isym
= local_syms
; isym
< isymend
; i
++, isym
++)
669 if (ELF_ST_TYPE (isym
->st_info
) == STT_SECTION
)
670 hppa_info
->section_syms
[isym
->st_shndx
] = i
;
673 /* We are finished with the local symbols. */
674 if (local_syms
!= NULL
675 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
677 if (! info
->keep_memory
)
681 /* Cache the symbols for elf_link_input_bfd. */
682 symtab_hdr
->contents
= (unsigned char *) local_syms
;
686 /* Record which BFD we built the section_syms mapping for. */
687 hppa_info
->section_syms_bfd
= abfd
;
690 /* Record the symbol index for this input section. We may need it for
691 relocations when building shared libraries. When not building shared
692 libraries this value is never really used, but assign it to zero to
693 prevent out of bounds memory accesses in other routines. */
696 sec_symndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
698 /* If we did not find a section symbol for this section, then
699 something went terribly wrong above. */
700 if (sec_symndx
== -1)
703 sec_symndx
= hppa_info
->section_syms
[sec_symndx
];
708 dlt
= plt
= stubs
= NULL
;
712 relend
= relocs
+ sec
->reloc_count
;
713 for (rel
= relocs
; rel
< relend
; ++rel
)
724 struct elf_link_hash_entry
*h
= NULL
;
725 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
726 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
728 const char *addr_name
;
729 bfd_boolean maybe_dynamic
;
730 int dynrel_type
= R_PARISC_NONE
;
731 static reloc_howto_type
*howto
;
733 if (r_symndx
>= symtab_hdr
->sh_info
)
735 /* We're dealing with a global symbol -- find its hash entry
736 and mark it as being referenced. */
737 long indx
= r_symndx
- symtab_hdr
->sh_info
;
738 h
= elf_sym_hashes (abfd
)[indx
];
739 while (h
->root
.type
== bfd_link_hash_indirect
740 || h
->root
.type
== bfd_link_hash_warning
)
741 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
746 /* We can only get preliminary data on whether a symbol is
747 locally or externally defined, as not all of the input files
748 have yet been processed. Do something with what we know, as
749 this may help reduce memory usage and processing time later. */
750 maybe_dynamic
= FALSE
;
751 if (h
&& ((info
->shared
753 || info
->unresolved_syms_in_shared_libs
== RM_IGNORE
))
755 || h
->root
.type
== bfd_link_hash_defweak
))
756 maybe_dynamic
= TRUE
;
758 howto
= elf_hppa_howto_table
+ ELF64_R_TYPE (rel
->r_info
);
762 /* These are simple indirect references to symbols through the
763 DLT. We need to create a DLT entry for any symbols which
764 appears in a DLTIND relocation. */
765 case R_PARISC_DLTIND21L
:
766 case R_PARISC_DLTIND14R
:
767 case R_PARISC_DLTIND14F
:
768 case R_PARISC_DLTIND14WR
:
769 case R_PARISC_DLTIND14DR
:
770 need_entry
= NEED_DLT
;
773 /* ?!? These need a DLT entry. But I have no idea what to do with
774 the "link time TP value. */
775 case R_PARISC_LTOFF_TP21L
:
776 case R_PARISC_LTOFF_TP14R
:
777 case R_PARISC_LTOFF_TP14F
:
778 case R_PARISC_LTOFF_TP64
:
779 case R_PARISC_LTOFF_TP14WR
:
780 case R_PARISC_LTOFF_TP14DR
:
781 case R_PARISC_LTOFF_TP16F
:
782 case R_PARISC_LTOFF_TP16WF
:
783 case R_PARISC_LTOFF_TP16DF
:
784 need_entry
= NEED_DLT
;
787 /* These are function calls. Depending on their precise target we
788 may need to make a stub for them. The stub uses the PLT, so we
789 need to create PLT entries for these symbols too. */
790 case R_PARISC_PCREL12F
:
791 case R_PARISC_PCREL17F
:
792 case R_PARISC_PCREL22F
:
793 case R_PARISC_PCREL32
:
794 case R_PARISC_PCREL64
:
795 case R_PARISC_PCREL21L
:
796 case R_PARISC_PCREL17R
:
797 case R_PARISC_PCREL17C
:
798 case R_PARISC_PCREL14R
:
799 case R_PARISC_PCREL14F
:
800 case R_PARISC_PCREL22C
:
801 case R_PARISC_PCREL14WR
:
802 case R_PARISC_PCREL14DR
:
803 case R_PARISC_PCREL16F
:
804 case R_PARISC_PCREL16WF
:
805 case R_PARISC_PCREL16DF
:
806 need_entry
= (NEED_PLT
| NEED_STUB
);
809 case R_PARISC_PLTOFF21L
:
810 case R_PARISC_PLTOFF14R
:
811 case R_PARISC_PLTOFF14F
:
812 case R_PARISC_PLTOFF14WR
:
813 case R_PARISC_PLTOFF14DR
:
814 case R_PARISC_PLTOFF16F
:
815 case R_PARISC_PLTOFF16WF
:
816 case R_PARISC_PLTOFF16DF
:
817 need_entry
= (NEED_PLT
);
821 if (info
->shared
|| maybe_dynamic
)
822 need_entry
= (NEED_DYNREL
);
823 dynrel_type
= R_PARISC_DIR64
;
826 /* This is an indirect reference through the DLT to get the address
827 of a OPD descriptor. Thus we need to make a DLT entry that points
829 case R_PARISC_LTOFF_FPTR21L
:
830 case R_PARISC_LTOFF_FPTR14R
:
831 case R_PARISC_LTOFF_FPTR14WR
:
832 case R_PARISC_LTOFF_FPTR14DR
:
833 case R_PARISC_LTOFF_FPTR32
:
834 case R_PARISC_LTOFF_FPTR64
:
835 case R_PARISC_LTOFF_FPTR16F
:
836 case R_PARISC_LTOFF_FPTR16WF
:
837 case R_PARISC_LTOFF_FPTR16DF
:
838 if (info
->shared
|| maybe_dynamic
)
839 need_entry
= (NEED_DLT
| NEED_OPD
);
841 need_entry
= (NEED_DLT
| NEED_OPD
);
842 dynrel_type
= R_PARISC_FPTR64
;
845 /* This is a simple OPD entry. */
846 case R_PARISC_FPTR64
:
847 if (info
->shared
|| maybe_dynamic
)
848 need_entry
= (NEED_OPD
| NEED_DYNREL
);
850 need_entry
= (NEED_OPD
);
851 dynrel_type
= R_PARISC_FPTR64
;
854 /* Add more cases as needed. */
860 /* Collect a canonical name for this address. */
861 addr_name
= get_dyn_name (abfd
, h
, rel
, &buf
, &buf_len
);
863 /* Collect the canonical entry data for this address. */
864 dyn_h
= elf64_hppa_dyn_hash_lookup (&hppa_info
->dyn_hash_table
,
865 addr_name
, TRUE
, TRUE
);
868 /* Stash away enough information to be able to find this symbol
869 regardless of whether or not it is local or global. */
872 dyn_h
->sym_indx
= r_symndx
;
874 /* ?!? We may need to do some error checking in here. */
875 /* Create what's needed. */
876 if (need_entry
& NEED_DLT
)
878 if (! hppa_info
->dlt_sec
879 && ! get_dlt (abfd
, info
, hppa_info
))
884 if (need_entry
& NEED_PLT
)
886 if (! hppa_info
->plt_sec
887 && ! get_plt (abfd
, info
, hppa_info
))
892 if (need_entry
& NEED_STUB
)
894 if (! hppa_info
->stub_sec
895 && ! get_stub (abfd
, info
, hppa_info
))
897 dyn_h
->want_stub
= 1;
900 if (need_entry
& NEED_OPD
)
902 if (! hppa_info
->opd_sec
903 && ! get_opd (abfd
, info
, hppa_info
))
908 /* FPTRs are not allocated by the dynamic linker for PA64, though
909 it is possible that will change in the future. */
911 /* This could be a local function that had its address taken, in
912 which case H will be NULL. */
917 /* Add a new dynamic relocation to the chain of dynamic
918 relocations for this symbol. */
919 if ((need_entry
& NEED_DYNREL
) && (sec
->flags
& SEC_ALLOC
))
921 if (! hppa_info
->other_rel_sec
922 && ! get_reloc_section (abfd
, hppa_info
, sec
))
925 if (!count_dyn_reloc (abfd
, dyn_h
, dynrel_type
, sec
,
926 sec_symndx
, rel
->r_offset
, rel
->r_addend
))
929 /* If we are building a shared library and we just recorded
930 a dynamic R_PARISC_FPTR64 relocation, then make sure the
931 section symbol for this section ends up in the dynamic
933 if (info
->shared
&& dynrel_type
== R_PARISC_FPTR64
934 && ! (bfd_elf_link_record_local_dynamic_symbol
935 (info
, abfd
, sec_symndx
)))
950 struct elf64_hppa_allocate_data
952 struct bfd_link_info
*info
;
956 /* Should we do dynamic things to this symbol? */
959 elf64_hppa_dynamic_symbol_p (h
, info
)
960 struct elf_link_hash_entry
*h
;
961 struct bfd_link_info
*info
;
963 /* ??? What, if anything, needs to happen wrt STV_PROTECTED symbols
964 and relocations that retrieve a function descriptor? Assume the
966 if (_bfd_elf_dynamic_symbol_p (h
, info
, 1))
968 /* ??? Why is this here and not elsewhere is_local_label_name. */
969 if (h
->root
.root
.string
[0] == '$' && h
->root
.root
.string
[1] == '$')
978 /* Mark all functions exported by this file so that we can later allocate
979 entries in .opd for them. */
982 elf64_hppa_mark_exported_functions (h
, data
)
983 struct elf_link_hash_entry
*h
;
986 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
987 struct elf64_hppa_link_hash_table
*hppa_info
;
989 hppa_info
= elf64_hppa_hash_table (info
);
991 if (h
->root
.type
== bfd_link_hash_warning
)
992 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
995 && (h
->root
.type
== bfd_link_hash_defined
996 || h
->root
.type
== bfd_link_hash_defweak
)
997 && h
->root
.u
.def
.section
->output_section
!= NULL
998 && h
->type
== STT_FUNC
)
1000 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
1002 /* Add this symbol to the PA64 linker hash table. */
1003 dyn_h
= elf64_hppa_dyn_hash_lookup (&hppa_info
->dyn_hash_table
,
1004 h
->root
.root
.string
, TRUE
, TRUE
);
1008 if (! hppa_info
->opd_sec
1009 && ! get_opd (hppa_info
->root
.dynobj
, info
, hppa_info
))
1012 dyn_h
->want_opd
= 1;
1013 /* Put a flag here for output_symbol_hook. */
1014 dyn_h
->st_shndx
= -1;
1021 /* Allocate space for a DLT entry. */
1024 allocate_global_data_dlt (dyn_h
, data
)
1025 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
1028 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1030 if (dyn_h
->want_dlt
)
1032 struct elf_link_hash_entry
*h
= dyn_h
->h
;
1034 if (x
->info
->shared
)
1036 /* Possibly add the symbol to the local dynamic symbol
1037 table since we might need to create a dynamic relocation
1040 || (h
->dynindx
== -1 && h
->type
!= STT_PARISC_MILLI
))
1043 owner
= (h
? h
->root
.u
.def
.section
->owner
: dyn_h
->owner
);
1045 if (! (bfd_elf_link_record_local_dynamic_symbol
1046 (x
->info
, owner
, dyn_h
->sym_indx
)))
1051 dyn_h
->dlt_offset
= x
->ofs
;
1052 x
->ofs
+= DLT_ENTRY_SIZE
;
1057 /* Allocate space for a DLT.PLT entry. */
1060 allocate_global_data_plt (dyn_h
, data
)
1061 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
1064 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1067 && elf64_hppa_dynamic_symbol_p (dyn_h
->h
, x
->info
)
1068 && !((dyn_h
->h
->root
.type
== bfd_link_hash_defined
1069 || dyn_h
->h
->root
.type
== bfd_link_hash_defweak
)
1070 && dyn_h
->h
->root
.u
.def
.section
->output_section
!= NULL
))
1072 dyn_h
->plt_offset
= x
->ofs
;
1073 x
->ofs
+= PLT_ENTRY_SIZE
;
1074 if (dyn_h
->plt_offset
< 0x2000)
1075 elf64_hppa_hash_table (x
->info
)->gp_offset
= dyn_h
->plt_offset
;
1078 dyn_h
->want_plt
= 0;
1083 /* Allocate space for a STUB entry. */
1086 allocate_global_data_stub (dyn_h
, data
)
1087 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
1090 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1092 if (dyn_h
->want_stub
1093 && elf64_hppa_dynamic_symbol_p (dyn_h
->h
, x
->info
)
1094 && !((dyn_h
->h
->root
.type
== bfd_link_hash_defined
1095 || dyn_h
->h
->root
.type
== bfd_link_hash_defweak
)
1096 && dyn_h
->h
->root
.u
.def
.section
->output_section
!= NULL
))
1098 dyn_h
->stub_offset
= x
->ofs
;
1099 x
->ofs
+= sizeof (plt_stub
);
1102 dyn_h
->want_stub
= 0;
1106 /* Allocate space for a FPTR entry. */
1109 allocate_global_data_opd (dyn_h
, data
)
1110 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
1113 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1115 if (dyn_h
->want_opd
)
1117 struct elf_link_hash_entry
*h
= dyn_h
->h
;
1120 while (h
->root
.type
== bfd_link_hash_indirect
1121 || h
->root
.type
== bfd_link_hash_warning
)
1122 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1124 /* We never need an opd entry for a symbol which is not
1125 defined by this output file. */
1126 if (h
&& (h
->root
.type
== bfd_link_hash_undefined
1127 || h
->root
.type
== bfd_link_hash_undefweak
1128 || h
->root
.u
.def
.section
->output_section
== NULL
))
1129 dyn_h
->want_opd
= 0;
1131 /* If we are creating a shared library, took the address of a local
1132 function or might export this function from this object file, then
1133 we have to create an opd descriptor. */
1134 else if (x
->info
->shared
1136 || (h
->dynindx
== -1 && h
->type
!= STT_PARISC_MILLI
)
1137 || (h
->root
.type
== bfd_link_hash_defined
1138 || h
->root
.type
== bfd_link_hash_defweak
))
1140 /* If we are creating a shared library, then we will have to
1141 create a runtime relocation for the symbol to properly
1142 initialize the .opd entry. Make sure the symbol gets
1143 added to the dynamic symbol table. */
1145 && (h
== NULL
|| (h
->dynindx
== -1)))
1148 owner
= (h
? h
->root
.u
.def
.section
->owner
: dyn_h
->owner
);
1150 if (!bfd_elf_link_record_local_dynamic_symbol
1151 (x
->info
, owner
, dyn_h
->sym_indx
))
1155 /* This may not be necessary or desirable anymore now that
1156 we have some support for dealing with section symbols
1157 in dynamic relocs. But name munging does make the result
1158 much easier to debug. ie, the EPLT reloc will reference
1159 a symbol like .foobar, instead of .text + offset. */
1160 if (x
->info
->shared
&& h
)
1163 struct elf_link_hash_entry
*nh
;
1165 new_name
= alloca (strlen (h
->root
.root
.string
) + 2);
1167 strcpy (new_name
+ 1, h
->root
.root
.string
);
1169 nh
= elf_link_hash_lookup (elf_hash_table (x
->info
),
1170 new_name
, TRUE
, TRUE
, TRUE
);
1172 nh
->root
.type
= h
->root
.type
;
1173 nh
->root
.u
.def
.value
= h
->root
.u
.def
.value
;
1174 nh
->root
.u
.def
.section
= h
->root
.u
.def
.section
;
1176 if (! bfd_elf_link_record_dynamic_symbol (x
->info
, nh
))
1180 dyn_h
->opd_offset
= x
->ofs
;
1181 x
->ofs
+= OPD_ENTRY_SIZE
;
1184 /* Otherwise we do not need an opd entry. */
1186 dyn_h
->want_opd
= 0;
1191 /* HP requires the EI_OSABI field to be filled in. The assignment to
1192 EI_ABIVERSION may not be strictly necessary. */
1195 elf64_hppa_post_process_headers (abfd
, link_info
)
1197 struct bfd_link_info
* link_info ATTRIBUTE_UNUSED
;
1199 Elf_Internal_Ehdr
* i_ehdrp
;
1201 i_ehdrp
= elf_elfheader (abfd
);
1203 i_ehdrp
->e_ident
[EI_OSABI
] = get_elf_backend_data (abfd
)->elf_osabi
;
1204 i_ehdrp
->e_ident
[EI_ABIVERSION
] = 1;
1207 /* Create function descriptor section (.opd). This section is called .opd
1208 because it contains "official procedure descriptors". The "official"
1209 refers to the fact that these descriptors are used when taking the address
1210 of a procedure, thus ensuring a unique address for each procedure. */
1213 get_opd (abfd
, info
, hppa_info
)
1215 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1216 struct elf64_hppa_link_hash_table
*hppa_info
;
1221 opd
= hppa_info
->opd_sec
;
1224 dynobj
= hppa_info
->root
.dynobj
;
1226 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1228 opd
= bfd_make_section_with_flags (dynobj
, ".opd",
1233 | SEC_LINKER_CREATED
));
1235 || !bfd_set_section_alignment (abfd
, opd
, 3))
1241 hppa_info
->opd_sec
= opd
;
1247 /* Create the PLT section. */
1250 get_plt (abfd
, info
, hppa_info
)
1252 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1253 struct elf64_hppa_link_hash_table
*hppa_info
;
1258 plt
= hppa_info
->plt_sec
;
1261 dynobj
= hppa_info
->root
.dynobj
;
1263 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1265 plt
= bfd_make_section_with_flags (dynobj
, ".plt",
1270 | SEC_LINKER_CREATED
));
1272 || !bfd_set_section_alignment (abfd
, plt
, 3))
1278 hppa_info
->plt_sec
= plt
;
1284 /* Create the DLT section. */
1287 get_dlt (abfd
, info
, hppa_info
)
1289 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1290 struct elf64_hppa_link_hash_table
*hppa_info
;
1295 dlt
= hppa_info
->dlt_sec
;
1298 dynobj
= hppa_info
->root
.dynobj
;
1300 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1302 dlt
= bfd_make_section_with_flags (dynobj
, ".dlt",
1307 | SEC_LINKER_CREATED
));
1309 || !bfd_set_section_alignment (abfd
, dlt
, 3))
1315 hppa_info
->dlt_sec
= dlt
;
1321 /* Create the stubs section. */
1324 get_stub (abfd
, info
, hppa_info
)
1326 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1327 struct elf64_hppa_link_hash_table
*hppa_info
;
1332 stub
= hppa_info
->stub_sec
;
1335 dynobj
= hppa_info
->root
.dynobj
;
1337 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1339 stub
= bfd_make_section_with_flags (dynobj
, ".stub",
1340 (SEC_ALLOC
| SEC_LOAD
1344 | SEC_LINKER_CREATED
));
1346 || !bfd_set_section_alignment (abfd
, stub
, 3))
1352 hppa_info
->stub_sec
= stub
;
1358 /* Create sections necessary for dynamic linking. This is only a rough
1359 cut and will likely change as we learn more about the somewhat
1360 unusual dynamic linking scheme HP uses.
1363 Contains code to implement cross-space calls. The first time one
1364 of the stubs is used it will call into the dynamic linker, later
1365 calls will go straight to the target.
1367 The only stub we support right now looks like
1371 ldd OFFSET+8(%dp),%dp
1373 Other stubs may be needed in the future. We may want the remove
1374 the break/nop instruction. It is only used right now to keep the
1375 offset of a .plt entry and a .stub entry in sync.
1378 This is what most people call the .got. HP used a different name.
1382 Relocations for the DLT.
1385 Function pointers as address,gp pairs.
1388 Should contain dynamic IPLT (and EPLT?) relocations.
1394 EPLT relocations for symbols exported from shared libraries. */
1397 elf64_hppa_create_dynamic_sections (abfd
, info
)
1399 struct bfd_link_info
*info
;
1403 if (! get_stub (abfd
, info
, elf64_hppa_hash_table (info
)))
1406 if (! get_dlt (abfd
, info
, elf64_hppa_hash_table (info
)))
1409 if (! get_plt (abfd
, info
, elf64_hppa_hash_table (info
)))
1412 if (! get_opd (abfd
, info
, elf64_hppa_hash_table (info
)))
1415 s
= bfd_make_section_with_flags (abfd
, ".rela.dlt",
1416 (SEC_ALLOC
| SEC_LOAD
1420 | SEC_LINKER_CREATED
));
1422 || !bfd_set_section_alignment (abfd
, s
, 3))
1424 elf64_hppa_hash_table (info
)->dlt_rel_sec
= s
;
1426 s
= bfd_make_section_with_flags (abfd
, ".rela.plt",
1427 (SEC_ALLOC
| SEC_LOAD
1431 | SEC_LINKER_CREATED
));
1433 || !bfd_set_section_alignment (abfd
, s
, 3))
1435 elf64_hppa_hash_table (info
)->plt_rel_sec
= s
;
1437 s
= bfd_make_section_with_flags (abfd
, ".rela.data",
1438 (SEC_ALLOC
| SEC_LOAD
1442 | SEC_LINKER_CREATED
));
1444 || !bfd_set_section_alignment (abfd
, s
, 3))
1446 elf64_hppa_hash_table (info
)->other_rel_sec
= s
;
1448 s
= bfd_make_section_with_flags (abfd
, ".rela.opd",
1449 (SEC_ALLOC
| SEC_LOAD
1453 | SEC_LINKER_CREATED
));
1455 || !bfd_set_section_alignment (abfd
, s
, 3))
1457 elf64_hppa_hash_table (info
)->opd_rel_sec
= s
;
1462 /* Allocate dynamic relocations for those symbols that turned out
1466 allocate_dynrel_entries (dyn_h
, data
)
1467 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
1470 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1471 struct elf64_hppa_link_hash_table
*hppa_info
;
1472 struct elf64_hppa_dyn_reloc_entry
*rent
;
1473 bfd_boolean dynamic_symbol
, shared
;
1475 hppa_info
= elf64_hppa_hash_table (x
->info
);
1476 dynamic_symbol
= elf64_hppa_dynamic_symbol_p (dyn_h
->h
, x
->info
);
1477 shared
= x
->info
->shared
;
1479 /* We may need to allocate relocations for a non-dynamic symbol
1480 when creating a shared library. */
1481 if (!dynamic_symbol
&& !shared
)
1484 /* Take care of the normal data relocations. */
1486 for (rent
= dyn_h
->reloc_entries
; rent
; rent
= rent
->next
)
1488 /* Allocate one iff we are building a shared library, the relocation
1489 isn't a R_PARISC_FPTR64, or we don't want an opd entry. */
1490 if (!shared
&& rent
->type
== R_PARISC_FPTR64
&& dyn_h
->want_opd
)
1493 hppa_info
->other_rel_sec
->size
+= sizeof (Elf64_External_Rela
);
1495 /* Make sure this symbol gets into the dynamic symbol table if it is
1496 not already recorded. ?!? This should not be in the loop since
1497 the symbol need only be added once. */
1499 || (dyn_h
->h
->dynindx
== -1 && dyn_h
->h
->type
!= STT_PARISC_MILLI
))
1500 if (!bfd_elf_link_record_local_dynamic_symbol
1501 (x
->info
, rent
->sec
->owner
, dyn_h
->sym_indx
))
1505 /* Take care of the GOT and PLT relocations. */
1507 if ((dynamic_symbol
|| shared
) && dyn_h
->want_dlt
)
1508 hppa_info
->dlt_rel_sec
->size
+= sizeof (Elf64_External_Rela
);
1510 /* If we are building a shared library, then every symbol that has an
1511 opd entry will need an EPLT relocation to relocate the symbol's address
1512 and __gp value based on the runtime load address. */
1513 if (shared
&& dyn_h
->want_opd
)
1514 hppa_info
->opd_rel_sec
->size
+= sizeof (Elf64_External_Rela
);
1516 if (dyn_h
->want_plt
&& dynamic_symbol
)
1518 bfd_size_type t
= 0;
1520 /* Dynamic symbols get one IPLT relocation. Local symbols in
1521 shared libraries get two REL relocations. Local symbols in
1522 main applications get nothing. */
1524 t
= sizeof (Elf64_External_Rela
);
1526 t
= 2 * sizeof (Elf64_External_Rela
);
1528 hppa_info
->plt_rel_sec
->size
+= t
;
1534 /* Adjust a symbol defined by a dynamic object and referenced by a
1538 elf64_hppa_adjust_dynamic_symbol (info
, h
)
1539 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1540 struct elf_link_hash_entry
*h
;
1542 /* ??? Undefined symbols with PLT entries should be re-defined
1543 to be the PLT entry. */
1545 /* If this is a weak symbol, and there is a real definition, the
1546 processor independent code will have arranged for us to see the
1547 real definition first, and we can just use the same value. */
1548 if (h
->u
.weakdef
!= NULL
)
1550 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
1551 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
1552 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
1553 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
1557 /* If this is a reference to a symbol defined by a dynamic object which
1558 is not a function, we might allocate the symbol in our .dynbss section
1559 and allocate a COPY dynamic relocation.
1561 But PA64 code is canonically PIC, so as a rule we can avoid this sort
1567 /* This function is called via elf_link_hash_traverse to mark millicode
1568 symbols with a dynindx of -1 and to remove the string table reference
1569 from the dynamic symbol table. If the symbol is not a millicode symbol,
1570 elf64_hppa_mark_exported_functions is called. */
1573 elf64_hppa_mark_milli_and_exported_functions (h
, data
)
1574 struct elf_link_hash_entry
*h
;
1577 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
1578 struct elf_link_hash_entry
*elf
= h
;
1580 if (elf
->root
.type
== bfd_link_hash_warning
)
1581 elf
= (struct elf_link_hash_entry
*) elf
->root
.u
.i
.link
;
1583 if (elf
->type
== STT_PARISC_MILLI
)
1585 if (elf
->dynindx
!= -1)
1588 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
1594 return elf64_hppa_mark_exported_functions (h
, data
);
1597 /* Set the final sizes of the dynamic sections and allocate memory for
1598 the contents of our special sections. */
1601 elf64_hppa_size_dynamic_sections (output_bfd
, info
)
1603 struct bfd_link_info
*info
;
1609 bfd_boolean reltext
;
1610 struct elf64_hppa_allocate_data data
;
1611 struct elf64_hppa_link_hash_table
*hppa_info
;
1613 hppa_info
= elf64_hppa_hash_table (info
);
1615 dynobj
= elf_hash_table (info
)->dynobj
;
1616 BFD_ASSERT (dynobj
!= NULL
);
1618 /* Mark each function this program exports so that we will allocate
1619 space in the .opd section for each function's FPTR. If we are
1620 creating dynamic sections, change the dynamic index of millicode
1621 symbols to -1 and remove them from the string table for .dynstr.
1623 We have to traverse the main linker hash table since we have to
1624 find functions which may not have been mentioned in any relocs. */
1625 elf_link_hash_traverse (elf_hash_table (info
),
1626 (elf_hash_table (info
)->dynamic_sections_created
1627 ? elf64_hppa_mark_milli_and_exported_functions
1628 : elf64_hppa_mark_exported_functions
),
1631 if (elf_hash_table (info
)->dynamic_sections_created
)
1633 /* Set the contents of the .interp section to the interpreter. */
1634 if (info
->executable
)
1636 s
= bfd_get_section_by_name (dynobj
, ".interp");
1637 BFD_ASSERT (s
!= NULL
);
1638 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1639 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1644 /* We may have created entries in the .rela.got section.
1645 However, if we are not creating the dynamic sections, we will
1646 not actually use these entries. Reset the size of .rela.dlt,
1647 which will cause it to get stripped from the output file
1649 s
= bfd_get_section_by_name (dynobj
, ".rela.dlt");
1654 /* Allocate the GOT entries. */
1657 if (elf64_hppa_hash_table (info
)->dlt_sec
)
1660 elf64_hppa_dyn_hash_traverse (&hppa_info
->dyn_hash_table
,
1661 allocate_global_data_dlt
, &data
);
1662 hppa_info
->dlt_sec
->size
= data
.ofs
;
1665 elf64_hppa_dyn_hash_traverse (&hppa_info
->dyn_hash_table
,
1666 allocate_global_data_plt
, &data
);
1667 hppa_info
->plt_sec
->size
= data
.ofs
;
1670 elf64_hppa_dyn_hash_traverse (&hppa_info
->dyn_hash_table
,
1671 allocate_global_data_stub
, &data
);
1672 hppa_info
->stub_sec
->size
= data
.ofs
;
1675 /* Allocate space for entries in the .opd section. */
1676 if (elf64_hppa_hash_table (info
)->opd_sec
)
1679 elf64_hppa_dyn_hash_traverse (&hppa_info
->dyn_hash_table
,
1680 allocate_global_data_opd
, &data
);
1681 hppa_info
->opd_sec
->size
= data
.ofs
;
1684 /* Now allocate space for dynamic relocations, if necessary. */
1685 if (hppa_info
->root
.dynamic_sections_created
)
1686 elf64_hppa_dyn_hash_traverse (&hppa_info
->dyn_hash_table
,
1687 allocate_dynrel_entries
, &data
);
1689 /* The sizes of all the sections are set. Allocate memory for them. */
1693 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1697 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
1700 /* It's OK to base decisions on the section name, because none
1701 of the dynobj section names depend upon the input files. */
1702 name
= bfd_get_section_name (dynobj
, s
);
1704 if (strcmp (name
, ".plt") == 0)
1706 /* Remember whether there is a PLT. */
1709 else if (strcmp (name
, ".opd") == 0
1710 || CONST_STRNEQ (name
, ".dlt")
1711 || strcmp (name
, ".stub") == 0
1712 || strcmp (name
, ".got") == 0)
1714 /* Strip this section if we don't need it; see the comment below. */
1716 else if (CONST_STRNEQ (name
, ".rela"))
1722 /* Remember whether there are any reloc sections other
1724 if (strcmp (name
, ".rela.plt") != 0)
1726 const char *outname
;
1730 /* If this relocation section applies to a read only
1731 section, then we probably need a DT_TEXTREL
1732 entry. The entries in the .rela.plt section
1733 really apply to the .got section, which we
1734 created ourselves and so know is not readonly. */
1735 outname
= bfd_get_section_name (output_bfd
,
1737 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
1739 && (target
->flags
& SEC_READONLY
) != 0
1740 && (target
->flags
& SEC_ALLOC
) != 0)
1744 /* We use the reloc_count field as a counter if we need
1745 to copy relocs into the output file. */
1751 /* It's not one of our sections, so don't allocate space. */
1757 /* If we don't need this section, strip it from the
1758 output file. This is mostly to handle .rela.bss and
1759 .rela.plt. We must create both sections in
1760 create_dynamic_sections, because they must be created
1761 before the linker maps input sections to output
1762 sections. The linker does that before
1763 adjust_dynamic_symbol is called, and it is that
1764 function which decides whether anything needs to go
1765 into these sections. */
1766 s
->flags
|= SEC_EXCLUDE
;
1770 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
1773 /* Allocate memory for the section contents if it has not
1774 been allocated already. We use bfd_zalloc here in case
1775 unused entries are not reclaimed before the section's
1776 contents are written out. This should not happen, but this
1777 way if it does, we get a R_PARISC_NONE reloc instead of
1779 if (s
->contents
== NULL
)
1781 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
1782 if (s
->contents
== NULL
)
1787 if (elf_hash_table (info
)->dynamic_sections_created
)
1789 /* Always create a DT_PLTGOT. It actually has nothing to do with
1790 the PLT, it is how we communicate the __gp value of a load
1791 module to the dynamic linker. */
1792 #define add_dynamic_entry(TAG, VAL) \
1793 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
1795 if (!add_dynamic_entry (DT_HP_DLD_FLAGS
, 0)
1796 || !add_dynamic_entry (DT_PLTGOT
, 0))
1799 /* Add some entries to the .dynamic section. We fill in the
1800 values later, in elf64_hppa_finish_dynamic_sections, but we
1801 must add the entries now so that we get the correct size for
1802 the .dynamic section. The DT_DEBUG entry is filled in by the
1803 dynamic linker and used by the debugger. */
1806 if (!add_dynamic_entry (DT_DEBUG
, 0)
1807 || !add_dynamic_entry (DT_HP_DLD_HOOK
, 0)
1808 || !add_dynamic_entry (DT_HP_LOAD_MAP
, 0))
1812 /* Force DT_FLAGS to always be set.
1813 Required by HPUX 11.00 patch PHSS_26559. */
1814 if (!add_dynamic_entry (DT_FLAGS
, (info
)->flags
))
1819 if (!add_dynamic_entry (DT_PLTRELSZ
, 0)
1820 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
1821 || !add_dynamic_entry (DT_JMPREL
, 0))
1827 if (!add_dynamic_entry (DT_RELA
, 0)
1828 || !add_dynamic_entry (DT_RELASZ
, 0)
1829 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
1835 if (!add_dynamic_entry (DT_TEXTREL
, 0))
1837 info
->flags
|= DF_TEXTREL
;
1840 #undef add_dynamic_entry
1845 /* Called after we have output the symbol into the dynamic symbol
1846 table, but before we output the symbol into the normal symbol
1849 For some symbols we had to change their address when outputting
1850 the dynamic symbol table. We undo that change here so that
1851 the symbols have their expected value in the normal symbol
1855 elf64_hppa_link_output_symbol_hook (info
, name
, sym
, input_sec
, h
)
1856 struct bfd_link_info
*info
;
1858 Elf_Internal_Sym
*sym
;
1859 asection
*input_sec ATTRIBUTE_UNUSED
;
1860 struct elf_link_hash_entry
*h
;
1862 struct elf64_hppa_link_hash_table
*hppa_info
;
1863 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
1865 /* We may be called with the file symbol or section symbols.
1866 They never need munging, so it is safe to ignore them. */
1870 /* Get the PA dyn_symbol (if any) associated with NAME. */
1871 hppa_info
= elf64_hppa_hash_table (info
);
1872 dyn_h
= elf64_hppa_dyn_hash_lookup (&hppa_info
->dyn_hash_table
,
1873 name
, FALSE
, FALSE
);
1874 if (!dyn_h
|| dyn_h
->h
!= h
)
1877 /* Function symbols for which we created .opd entries *may* have been
1878 munged by finish_dynamic_symbol and have to be un-munged here.
1880 Note that finish_dynamic_symbol sometimes turns dynamic symbols
1881 into non-dynamic ones, so we initialize st_shndx to -1 in
1882 mark_exported_functions and check to see if it was overwritten
1883 here instead of just checking dyn_h->h->dynindx. */
1884 if (dyn_h
->want_opd
&& dyn_h
->st_shndx
!= -1)
1886 /* Restore the saved value and section index. */
1887 sym
->st_value
= dyn_h
->st_value
;
1888 sym
->st_shndx
= dyn_h
->st_shndx
;
1894 /* Finish up dynamic symbol handling. We set the contents of various
1895 dynamic sections here. */
1898 elf64_hppa_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
1900 struct bfd_link_info
*info
;
1901 struct elf_link_hash_entry
*h
;
1902 Elf_Internal_Sym
*sym
;
1904 asection
*stub
, *splt
, *sdlt
, *sopd
, *spltrel
, *sdltrel
;
1905 struct elf64_hppa_link_hash_table
*hppa_info
;
1906 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
1908 hppa_info
= elf64_hppa_hash_table (info
);
1909 dyn_h
= elf64_hppa_dyn_hash_lookup (&hppa_info
->dyn_hash_table
,
1910 h
->root
.root
.string
, FALSE
, FALSE
);
1912 stub
= hppa_info
->stub_sec
;
1913 splt
= hppa_info
->plt_sec
;
1914 sdlt
= hppa_info
->dlt_sec
;
1915 sopd
= hppa_info
->opd_sec
;
1916 spltrel
= hppa_info
->plt_rel_sec
;
1917 sdltrel
= hppa_info
->dlt_rel_sec
;
1919 /* Incredible. It is actually necessary to NOT use the symbol's real
1920 value when building the dynamic symbol table for a shared library.
1921 At least for symbols that refer to functions.
1923 We will store a new value and section index into the symbol long
1924 enough to output it into the dynamic symbol table, then we restore
1925 the original values (in elf64_hppa_link_output_symbol_hook). */
1926 if (dyn_h
&& dyn_h
->want_opd
)
1928 BFD_ASSERT (sopd
!= NULL
);
1930 /* Save away the original value and section index so that we
1931 can restore them later. */
1932 dyn_h
->st_value
= sym
->st_value
;
1933 dyn_h
->st_shndx
= sym
->st_shndx
;
1935 /* For the dynamic symbol table entry, we want the value to be
1936 address of this symbol's entry within the .opd section. */
1937 sym
->st_value
= (dyn_h
->opd_offset
1938 + sopd
->output_offset
1939 + sopd
->output_section
->vma
);
1940 sym
->st_shndx
= _bfd_elf_section_from_bfd_section (output_bfd
,
1941 sopd
->output_section
);
1944 /* Initialize a .plt entry if requested. */
1945 if (dyn_h
&& dyn_h
->want_plt
1946 && elf64_hppa_dynamic_symbol_p (dyn_h
->h
, info
))
1949 Elf_Internal_Rela rel
;
1952 BFD_ASSERT (splt
!= NULL
&& spltrel
!= NULL
);
1954 /* We do not actually care about the value in the PLT entry
1955 if we are creating a shared library and the symbol is
1956 still undefined, we create a dynamic relocation to fill
1957 in the correct value. */
1958 if (info
->shared
&& h
->root
.type
== bfd_link_hash_undefined
)
1961 value
= (h
->root
.u
.def
.value
+ h
->root
.u
.def
.section
->vma
);
1963 /* Fill in the entry in the procedure linkage table.
1965 The format of a plt entry is
1968 plt_offset is the offset within the PLT section at which to
1969 install the PLT entry.
1971 We are modifying the in-memory PLT contents here, so we do not add
1972 in the output_offset of the PLT section. */
1974 bfd_put_64 (splt
->owner
, value
, splt
->contents
+ dyn_h
->plt_offset
);
1975 value
= _bfd_get_gp_value (splt
->output_section
->owner
);
1976 bfd_put_64 (splt
->owner
, value
, splt
->contents
+ dyn_h
->plt_offset
+ 0x8);
1978 /* Create a dynamic IPLT relocation for this entry.
1980 We are creating a relocation in the output file's PLT section,
1981 which is included within the DLT secton. So we do need to include
1982 the PLT's output_offset in the computation of the relocation's
1984 rel
.r_offset
= (dyn_h
->plt_offset
+ splt
->output_offset
1985 + splt
->output_section
->vma
);
1986 rel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PARISC_IPLT
);
1989 loc
= spltrel
->contents
;
1990 loc
+= spltrel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
1991 bfd_elf64_swap_reloca_out (splt
->output_section
->owner
, &rel
, loc
);
1994 /* Initialize an external call stub entry if requested. */
1995 if (dyn_h
&& dyn_h
->want_stub
1996 && elf64_hppa_dynamic_symbol_p (dyn_h
->h
, info
))
2000 unsigned int max_offset
;
2002 BFD_ASSERT (stub
!= NULL
);
2004 /* Install the generic stub template.
2006 We are modifying the contents of the stub section, so we do not
2007 need to include the stub section's output_offset here. */
2008 memcpy (stub
->contents
+ dyn_h
->stub_offset
, plt_stub
, sizeof (plt_stub
));
2010 /* Fix up the first ldd instruction.
2012 We are modifying the contents of the STUB section in memory,
2013 so we do not need to include its output offset in this computation.
2015 Note the plt_offset value is the value of the PLT entry relative to
2016 the start of the PLT section. These instructions will reference
2017 data relative to the value of __gp, which may not necessarily have
2018 the same address as the start of the PLT section.
2020 gp_offset contains the offset of __gp within the PLT section. */
2021 value
= dyn_h
->plt_offset
- hppa_info
->gp_offset
;
2023 insn
= bfd_get_32 (stub
->owner
, stub
->contents
+ dyn_h
->stub_offset
);
2024 if (output_bfd
->arch_info
->mach
>= 25)
2026 /* Wide mode allows 16 bit offsets. */
2029 insn
|= re_assemble_16 ((int) value
);
2035 insn
|= re_assemble_14 ((int) value
);
2038 if ((value
& 7) || value
+ max_offset
>= 2*max_offset
- 8)
2040 (*_bfd_error_handler
) (_("stub entry for %s cannot load .plt, dp offset = %ld"),
2046 bfd_put_32 (stub
->owner
, (bfd_vma
) insn
,
2047 stub
->contents
+ dyn_h
->stub_offset
);
2049 /* Fix up the second ldd instruction. */
2051 insn
= bfd_get_32 (stub
->owner
, stub
->contents
+ dyn_h
->stub_offset
+ 8);
2052 if (output_bfd
->arch_info
->mach
>= 25)
2055 insn
|= re_assemble_16 ((int) value
);
2060 insn
|= re_assemble_14 ((int) value
);
2062 bfd_put_32 (stub
->owner
, (bfd_vma
) insn
,
2063 stub
->contents
+ dyn_h
->stub_offset
+ 8);
2069 /* The .opd section contains FPTRs for each function this file
2070 exports. Initialize the FPTR entries. */
2073 elf64_hppa_finalize_opd (dyn_h
, data
)
2074 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
2077 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
2078 struct elf64_hppa_link_hash_table
*hppa_info
;
2079 struct elf_link_hash_entry
*h
= dyn_h
? dyn_h
->h
: NULL
;
2083 hppa_info
= elf64_hppa_hash_table (info
);
2084 sopd
= hppa_info
->opd_sec
;
2085 sopdrel
= hppa_info
->opd_rel_sec
;
2087 if (h
&& dyn_h
->want_opd
)
2091 /* The first two words of an .opd entry are zero.
2093 We are modifying the contents of the OPD section in memory, so we
2094 do not need to include its output offset in this computation. */
2095 memset (sopd
->contents
+ dyn_h
->opd_offset
, 0, 16);
2097 value
= (h
->root
.u
.def
.value
2098 + h
->root
.u
.def
.section
->output_section
->vma
2099 + h
->root
.u
.def
.section
->output_offset
);
2101 /* The next word is the address of the function. */
2102 bfd_put_64 (sopd
->owner
, value
, sopd
->contents
+ dyn_h
->opd_offset
+ 16);
2104 /* The last word is our local __gp value. */
2105 value
= _bfd_get_gp_value (sopd
->output_section
->owner
);
2106 bfd_put_64 (sopd
->owner
, value
, sopd
->contents
+ dyn_h
->opd_offset
+ 24);
2109 /* If we are generating a shared library, we must generate EPLT relocations
2110 for each entry in the .opd, even for static functions (they may have
2111 had their address taken). */
2112 if (info
->shared
&& dyn_h
&& dyn_h
->want_opd
)
2114 Elf_Internal_Rela rel
;
2118 /* We may need to do a relocation against a local symbol, in
2119 which case we have to look up it's dynamic symbol index off
2120 the local symbol hash table. */
2121 if (h
&& h
->dynindx
!= -1)
2122 dynindx
= h
->dynindx
;
2125 = _bfd_elf_link_lookup_local_dynindx (info
, dyn_h
->owner
,
2128 /* The offset of this relocation is the absolute address of the
2129 .opd entry for this symbol. */
2130 rel
.r_offset
= (dyn_h
->opd_offset
+ sopd
->output_offset
2131 + sopd
->output_section
->vma
);
2133 /* If H is non-null, then we have an external symbol.
2135 It is imperative that we use a different dynamic symbol for the
2136 EPLT relocation if the symbol has global scope.
2138 In the dynamic symbol table, the function symbol will have a value
2139 which is address of the function's .opd entry.
2141 Thus, we can not use that dynamic symbol for the EPLT relocation
2142 (if we did, the data in the .opd would reference itself rather
2143 than the actual address of the function). Instead we have to use
2144 a new dynamic symbol which has the same value as the original global
2147 We prefix the original symbol with a "." and use the new symbol in
2148 the EPLT relocation. This new symbol has already been recorded in
2149 the symbol table, we just have to look it up and use it.
2151 We do not have such problems with static functions because we do
2152 not make their addresses in the dynamic symbol table point to
2153 the .opd entry. Ultimately this should be safe since a static
2154 function can not be directly referenced outside of its shared
2157 We do have to play similar games for FPTR relocations in shared
2158 libraries, including those for static symbols. See the FPTR
2159 handling in elf64_hppa_finalize_dynreloc. */
2163 struct elf_link_hash_entry
*nh
;
2165 new_name
= alloca (strlen (h
->root
.root
.string
) + 2);
2167 strcpy (new_name
+ 1, h
->root
.root
.string
);
2169 nh
= elf_link_hash_lookup (elf_hash_table (info
),
2170 new_name
, FALSE
, FALSE
, FALSE
);
2172 /* All we really want from the new symbol is its dynamic
2174 dynindx
= nh
->dynindx
;
2178 rel
.r_info
= ELF64_R_INFO (dynindx
, R_PARISC_EPLT
);
2180 loc
= sopdrel
->contents
;
2181 loc
+= sopdrel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2182 bfd_elf64_swap_reloca_out (sopd
->output_section
->owner
, &rel
, loc
);
2187 /* The .dlt section contains addresses for items referenced through the
2188 dlt. Note that we can have a DLTIND relocation for a local symbol, thus
2189 we can not depend on finish_dynamic_symbol to initialize the .dlt. */
2192 elf64_hppa_finalize_dlt (dyn_h
, data
)
2193 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
2196 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
2197 struct elf64_hppa_link_hash_table
*hppa_info
;
2198 asection
*sdlt
, *sdltrel
;
2199 struct elf_link_hash_entry
*h
= dyn_h
? dyn_h
->h
: NULL
;
2201 hppa_info
= elf64_hppa_hash_table (info
);
2203 sdlt
= hppa_info
->dlt_sec
;
2204 sdltrel
= hppa_info
->dlt_rel_sec
;
2206 /* H/DYN_H may refer to a local variable and we know it's
2207 address, so there is no need to create a relocation. Just install
2208 the proper value into the DLT, note this shortcut can not be
2209 skipped when building a shared library. */
2210 if (! info
->shared
&& h
&& dyn_h
->want_dlt
)
2214 /* If we had an LTOFF_FPTR style relocation we want the DLT entry
2215 to point to the FPTR entry in the .opd section.
2217 We include the OPD's output offset in this computation as
2218 we are referring to an absolute address in the resulting
2220 if (dyn_h
->want_opd
)
2222 value
= (dyn_h
->opd_offset
2223 + hppa_info
->opd_sec
->output_offset
2224 + hppa_info
->opd_sec
->output_section
->vma
);
2226 else if ((h
->root
.type
== bfd_link_hash_defined
2227 || h
->root
.type
== bfd_link_hash_defweak
)
2228 && h
->root
.u
.def
.section
)
2230 value
= h
->root
.u
.def
.value
+ h
->root
.u
.def
.section
->output_offset
;
2231 if (h
->root
.u
.def
.section
->output_section
)
2232 value
+= h
->root
.u
.def
.section
->output_section
->vma
;
2234 value
+= h
->root
.u
.def
.section
->vma
;
2237 /* We have an undefined function reference. */
2240 /* We do not need to include the output offset of the DLT section
2241 here because we are modifying the in-memory contents. */
2242 bfd_put_64 (sdlt
->owner
, value
, sdlt
->contents
+ dyn_h
->dlt_offset
);
2245 /* Create a relocation for the DLT entry associated with this symbol.
2246 When building a shared library the symbol does not have to be dynamic. */
2248 && (elf64_hppa_dynamic_symbol_p (dyn_h
->h
, info
) || info
->shared
))
2250 Elf_Internal_Rela rel
;
2254 /* We may need to do a relocation against a local symbol, in
2255 which case we have to look up it's dynamic symbol index off
2256 the local symbol hash table. */
2257 if (h
&& h
->dynindx
!= -1)
2258 dynindx
= h
->dynindx
;
2261 = _bfd_elf_link_lookup_local_dynindx (info
, dyn_h
->owner
,
2264 /* Create a dynamic relocation for this entry. Do include the output
2265 offset of the DLT entry since we need an absolute address in the
2266 resulting object file. */
2267 rel
.r_offset
= (dyn_h
->dlt_offset
+ sdlt
->output_offset
2268 + sdlt
->output_section
->vma
);
2269 if (h
&& h
->type
== STT_FUNC
)
2270 rel
.r_info
= ELF64_R_INFO (dynindx
, R_PARISC_FPTR64
);
2272 rel
.r_info
= ELF64_R_INFO (dynindx
, R_PARISC_DIR64
);
2275 loc
= sdltrel
->contents
;
2276 loc
+= sdltrel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2277 bfd_elf64_swap_reloca_out (sdlt
->output_section
->owner
, &rel
, loc
);
2282 /* Finalize the dynamic relocations. Specifically the FPTR relocations
2283 for dynamic functions used to initialize static data. */
2286 elf64_hppa_finalize_dynreloc (dyn_h
, data
)
2287 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
2290 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
2291 struct elf64_hppa_link_hash_table
*hppa_info
;
2292 struct elf_link_hash_entry
*h
;
2295 dynamic_symbol
= elf64_hppa_dynamic_symbol_p (dyn_h
->h
, info
);
2297 if (!dynamic_symbol
&& !info
->shared
)
2300 if (dyn_h
->reloc_entries
)
2302 struct elf64_hppa_dyn_reloc_entry
*rent
;
2305 hppa_info
= elf64_hppa_hash_table (info
);
2308 /* We may need to do a relocation against a local symbol, in
2309 which case we have to look up it's dynamic symbol index off
2310 the local symbol hash table. */
2311 if (h
&& h
->dynindx
!= -1)
2312 dynindx
= h
->dynindx
;
2315 = _bfd_elf_link_lookup_local_dynindx (info
, dyn_h
->owner
,
2318 for (rent
= dyn_h
->reloc_entries
; rent
; rent
= rent
->next
)
2320 Elf_Internal_Rela rel
;
2323 /* Allocate one iff we are building a shared library, the relocation
2324 isn't a R_PARISC_FPTR64, or we don't want an opd entry. */
2325 if (!info
->shared
&& rent
->type
== R_PARISC_FPTR64
&& dyn_h
->want_opd
)
2328 /* Create a dynamic relocation for this entry.
2330 We need the output offset for the reloc's section because
2331 we are creating an absolute address in the resulting object
2333 rel
.r_offset
= (rent
->offset
+ rent
->sec
->output_offset
2334 + rent
->sec
->output_section
->vma
);
2336 /* An FPTR64 relocation implies that we took the address of
2337 a function and that the function has an entry in the .opd
2338 section. We want the FPTR64 relocation to reference the
2341 We could munge the symbol value in the dynamic symbol table
2342 (in fact we already do for functions with global scope) to point
2343 to the .opd entry. Then we could use that dynamic symbol in
2346 Or we could do something sensible, not munge the symbol's
2347 address and instead just use a different symbol to reference
2348 the .opd entry. At least that seems sensible until you
2349 realize there's no local dynamic symbols we can use for that
2350 purpose. Thus the hair in the check_relocs routine.
2352 We use a section symbol recorded by check_relocs as the
2353 base symbol for the relocation. The addend is the difference
2354 between the section symbol and the address of the .opd entry. */
2355 if (info
->shared
&& rent
->type
== R_PARISC_FPTR64
&& dyn_h
->want_opd
)
2357 bfd_vma value
, value2
;
2359 /* First compute the address of the opd entry for this symbol. */
2360 value
= (dyn_h
->opd_offset
2361 + hppa_info
->opd_sec
->output_section
->vma
2362 + hppa_info
->opd_sec
->output_offset
);
2364 /* Compute the value of the start of the section with
2366 value2
= (rent
->sec
->output_section
->vma
2367 + rent
->sec
->output_offset
);
2369 /* Compute the difference between the start of the section
2370 with the relocation and the opd entry. */
2373 /* The result becomes the addend of the relocation. */
2374 rel
.r_addend
= value
;
2376 /* The section symbol becomes the symbol for the dynamic
2379 = _bfd_elf_link_lookup_local_dynindx (info
,
2384 rel
.r_addend
= rent
->addend
;
2386 rel
.r_info
= ELF64_R_INFO (dynindx
, rent
->type
);
2388 loc
= hppa_info
->other_rel_sec
->contents
;
2389 loc
+= (hppa_info
->other_rel_sec
->reloc_count
++
2390 * sizeof (Elf64_External_Rela
));
2391 bfd_elf64_swap_reloca_out (hppa_info
->other_rel_sec
->output_section
->owner
,
2399 /* Used to decide how to sort relocs in an optimal manner for the
2400 dynamic linker, before writing them out. */
2402 static enum elf_reloc_type_class
2403 elf64_hppa_reloc_type_class (rela
)
2404 const Elf_Internal_Rela
*rela
;
2406 if (ELF64_R_SYM (rela
->r_info
) == 0)
2407 return reloc_class_relative
;
2409 switch ((int) ELF64_R_TYPE (rela
->r_info
))
2412 return reloc_class_plt
;
2414 return reloc_class_copy
;
2416 return reloc_class_normal
;
2420 /* Finish up the dynamic sections. */
2423 elf64_hppa_finish_dynamic_sections (output_bfd
, info
)
2425 struct bfd_link_info
*info
;
2429 struct elf64_hppa_link_hash_table
*hppa_info
;
2431 hppa_info
= elf64_hppa_hash_table (info
);
2433 /* Finalize the contents of the .opd section. */
2434 elf64_hppa_dyn_hash_traverse (&hppa_info
->dyn_hash_table
,
2435 elf64_hppa_finalize_opd
,
2438 elf64_hppa_dyn_hash_traverse (&hppa_info
->dyn_hash_table
,
2439 elf64_hppa_finalize_dynreloc
,
2442 /* Finalize the contents of the .dlt section. */
2443 dynobj
= elf_hash_table (info
)->dynobj
;
2444 /* Finalize the contents of the .dlt section. */
2445 elf64_hppa_dyn_hash_traverse (&hppa_info
->dyn_hash_table
,
2446 elf64_hppa_finalize_dlt
,
2449 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2451 if (elf_hash_table (info
)->dynamic_sections_created
)
2453 Elf64_External_Dyn
*dyncon
, *dynconend
;
2455 BFD_ASSERT (sdyn
!= NULL
);
2457 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
2458 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
2459 for (; dyncon
< dynconend
; dyncon
++)
2461 Elf_Internal_Dyn dyn
;
2464 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2471 case DT_HP_LOAD_MAP
:
2472 /* Compute the absolute address of 16byte scratchpad area
2473 for the dynamic linker.
2475 By convention the linker script will allocate the scratchpad
2476 area at the start of the .data section. So all we have to
2477 to is find the start of the .data section. */
2478 s
= bfd_get_section_by_name (output_bfd
, ".data");
2479 dyn
.d_un
.d_ptr
= s
->vma
;
2480 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2484 /* HP's use PLTGOT to set the GOT register. */
2485 dyn
.d_un
.d_ptr
= _bfd_get_gp_value (output_bfd
);
2486 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2490 s
= hppa_info
->plt_rel_sec
;
2491 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
2492 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2496 s
= hppa_info
->plt_rel_sec
;
2497 dyn
.d_un
.d_val
= s
->size
;
2498 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2502 s
= hppa_info
->other_rel_sec
;
2503 if (! s
|| ! s
->size
)
2504 s
= hppa_info
->dlt_rel_sec
;
2505 if (! s
|| ! s
->size
)
2506 s
= hppa_info
->opd_rel_sec
;
2507 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
2508 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2512 s
= hppa_info
->other_rel_sec
;
2513 dyn
.d_un
.d_val
= s
->size
;
2514 s
= hppa_info
->dlt_rel_sec
;
2515 dyn
.d_un
.d_val
+= s
->size
;
2516 s
= hppa_info
->opd_rel_sec
;
2517 dyn
.d_un
.d_val
+= s
->size
;
2518 /* There is some question about whether or not the size of
2519 the PLT relocs should be included here. HP's tools do
2520 it, so we'll emulate them. */
2521 s
= hppa_info
->plt_rel_sec
;
2522 dyn
.d_un
.d_val
+= s
->size
;
2523 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2533 /* Support for core dump NOTE sections. */
2536 elf64_hppa_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
2541 switch (note
->descsz
)
2546 case 760: /* Linux/hppa */
2548 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
2551 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
2560 /* Make a ".reg/999" section. */
2561 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
2562 size
, note
->descpos
+ offset
);
2566 elf64_hppa_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
2571 switch (note
->descsz
)
2576 case 136: /* Linux/hppa elf_prpsinfo. */
2577 elf_tdata (abfd
)->core_program
2578 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
2579 elf_tdata (abfd
)->core_command
2580 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
2583 /* Note that for some reason, a spurious space is tacked
2584 onto the end of the args in some (at least one anyway)
2585 implementations, so strip it off if it exists. */
2586 command
= elf_tdata (abfd
)->core_command
;
2587 n
= strlen (command
);
2589 if (0 < n
&& command
[n
- 1] == ' ')
2590 command
[n
- 1] = '\0';
2595 /* Return the number of additional phdrs we will need.
2597 The generic ELF code only creates PT_PHDRs for executables. The HP
2598 dynamic linker requires PT_PHDRs for dynamic libraries too.
2600 This routine indicates that the backend needs one additional program
2601 header for that case.
2603 Note we do not have access to the link info structure here, so we have
2604 to guess whether or not we are building a shared library based on the
2605 existence of a .interp section. */
2608 elf64_hppa_additional_program_headers (bfd
*abfd
,
2609 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2613 /* If we are creating a shared library, then we have to create a
2614 PT_PHDR segment. HP's dynamic linker chokes without it. */
2615 s
= bfd_get_section_by_name (abfd
, ".interp");
2621 /* Allocate and initialize any program headers required by this
2624 The generic ELF code only creates PT_PHDRs for executables. The HP
2625 dynamic linker requires PT_PHDRs for dynamic libraries too.
2627 This allocates the PT_PHDR and initializes it in a manner suitable
2630 Note we do not have access to the link info structure here, so we have
2631 to guess whether or not we are building a shared library based on the
2632 existence of a .interp section. */
2635 elf64_hppa_modify_segment_map (bfd
*abfd
,
2636 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2638 struct elf_segment_map
*m
;
2641 s
= bfd_get_section_by_name (abfd
, ".interp");
2644 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2645 if (m
->p_type
== PT_PHDR
)
2649 m
= ((struct elf_segment_map
*)
2650 bfd_zalloc (abfd
, (bfd_size_type
) sizeof *m
));
2654 m
->p_type
= PT_PHDR
;
2655 m
->p_flags
= PF_R
| PF_X
;
2656 m
->p_flags_valid
= 1;
2657 m
->p_paddr_valid
= 1;
2658 m
->includes_phdrs
= 1;
2660 m
->next
= elf_tdata (abfd
)->segment_map
;
2661 elf_tdata (abfd
)->segment_map
= m
;
2665 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2666 if (m
->p_type
== PT_LOAD
)
2670 for (i
= 0; i
< m
->count
; i
++)
2672 /* The code "hint" is not really a hint. It is a requirement
2673 for certain versions of the HP dynamic linker. Worse yet,
2674 it must be set even if the shared library does not have
2675 any code in its "text" segment (thus the check for .hash
2676 to catch this situation). */
2677 if (m
->sections
[i
]->flags
& SEC_CODE
2678 || (strcmp (m
->sections
[i
]->name
, ".hash") == 0))
2679 m
->p_flags
|= (PF_X
| PF_HP_CODE
);
2686 /* Called when writing out an object file to decide the type of a
2689 elf64_hppa_elf_get_symbol_type (elf_sym
, type
)
2690 Elf_Internal_Sym
*elf_sym
;
2693 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_PARISC_MILLI
)
2694 return STT_PARISC_MILLI
;
2699 /* Support HP specific sections for core files. */
2701 elf64_hppa_section_from_phdr (bfd
*abfd
, Elf_Internal_Phdr
*hdr
, int index
,
2702 const char *typename
)
2704 if (hdr
->p_type
== PT_HP_CORE_KERNEL
)
2708 if (!_bfd_elf_make_section_from_phdr (abfd
, hdr
, index
, typename
))
2711 sect
= bfd_make_section_anyway (abfd
, ".kernel");
2714 sect
->size
= hdr
->p_filesz
;
2715 sect
->filepos
= hdr
->p_offset
;
2716 sect
->flags
= SEC_HAS_CONTENTS
| SEC_READONLY
;
2720 if (hdr
->p_type
== PT_HP_CORE_PROC
)
2724 if (bfd_seek (abfd
, hdr
->p_offset
, SEEK_SET
) != 0)
2726 if (bfd_bread (&sig
, 4, abfd
) != 4)
2729 elf_tdata (abfd
)->core_signal
= sig
;
2731 if (!_bfd_elf_make_section_from_phdr (abfd
, hdr
, index
, typename
))
2734 /* GDB uses the ".reg" section to read register contents. */
2735 return _bfd_elfcore_make_pseudosection (abfd
, ".reg", hdr
->p_filesz
,
2739 if (hdr
->p_type
== PT_HP_CORE_LOADABLE
2740 || hdr
->p_type
== PT_HP_CORE_STACK
2741 || hdr
->p_type
== PT_HP_CORE_MMF
)
2742 hdr
->p_type
= PT_LOAD
;
2744 return _bfd_elf_make_section_from_phdr (abfd
, hdr
, index
, typename
);
2747 static const struct bfd_elf_special_section elf64_hppa_special_sections
[] =
2749 { STRING_COMMA_LEN (".fini"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2750 { STRING_COMMA_LEN (".init"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2751 { STRING_COMMA_LEN (".plt"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
2752 { STRING_COMMA_LEN (".dlt"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
2753 { STRING_COMMA_LEN (".sdata"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
2754 { STRING_COMMA_LEN (".sbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
2755 { STRING_COMMA_LEN (".tbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_HP_TLS
},
2756 { NULL
, 0, 0, 0, 0 }
2759 /* The hash bucket size is the standard one, namely 4. */
2761 const struct elf_size_info hppa64_elf_size_info
=
2763 sizeof (Elf64_External_Ehdr
),
2764 sizeof (Elf64_External_Phdr
),
2765 sizeof (Elf64_External_Shdr
),
2766 sizeof (Elf64_External_Rel
),
2767 sizeof (Elf64_External_Rela
),
2768 sizeof (Elf64_External_Sym
),
2769 sizeof (Elf64_External_Dyn
),
2770 sizeof (Elf_External_Note
),
2774 ELFCLASS64
, EV_CURRENT
,
2775 bfd_elf64_write_out_phdrs
,
2776 bfd_elf64_write_shdrs_and_ehdr
,
2777 bfd_elf64_checksum_contents
,
2778 bfd_elf64_write_relocs
,
2779 bfd_elf64_swap_symbol_in
,
2780 bfd_elf64_swap_symbol_out
,
2781 bfd_elf64_slurp_reloc_table
,
2782 bfd_elf64_slurp_symbol_table
,
2783 bfd_elf64_swap_dyn_in
,
2784 bfd_elf64_swap_dyn_out
,
2785 bfd_elf64_swap_reloc_in
,
2786 bfd_elf64_swap_reloc_out
,
2787 bfd_elf64_swap_reloca_in
,
2788 bfd_elf64_swap_reloca_out
2791 #define TARGET_BIG_SYM bfd_elf64_hppa_vec
2792 #define TARGET_BIG_NAME "elf64-hppa"
2793 #define ELF_ARCH bfd_arch_hppa
2794 #define ELF_MACHINE_CODE EM_PARISC
2795 /* This is not strictly correct. The maximum page size for PA2.0 is
2796 64M. But everything still uses 4k. */
2797 #define ELF_MAXPAGESIZE 0x1000
2798 #define ELF_OSABI ELFOSABI_HPUX
2800 #define bfd_elf64_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
2801 #define bfd_elf64_bfd_reloc_name_lookup elf_hppa_reloc_name_lookup
2802 #define bfd_elf64_bfd_is_local_label_name elf_hppa_is_local_label_name
2803 #define elf_info_to_howto elf_hppa_info_to_howto
2804 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
2806 #define elf_backend_section_from_shdr elf64_hppa_section_from_shdr
2807 #define elf_backend_object_p elf64_hppa_object_p
2808 #define elf_backend_final_write_processing \
2809 elf_hppa_final_write_processing
2810 #define elf_backend_fake_sections elf_hppa_fake_sections
2811 #define elf_backend_add_symbol_hook elf_hppa_add_symbol_hook
2813 #define elf_backend_relocate_section elf_hppa_relocate_section
2815 #define bfd_elf64_bfd_final_link elf_hppa_final_link
2817 #define elf_backend_create_dynamic_sections \
2818 elf64_hppa_create_dynamic_sections
2819 #define elf_backend_post_process_headers elf64_hppa_post_process_headers
2821 #define elf_backend_omit_section_dynsym \
2822 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
2823 #define elf_backend_adjust_dynamic_symbol \
2824 elf64_hppa_adjust_dynamic_symbol
2826 #define elf_backend_size_dynamic_sections \
2827 elf64_hppa_size_dynamic_sections
2829 #define elf_backend_finish_dynamic_symbol \
2830 elf64_hppa_finish_dynamic_symbol
2831 #define elf_backend_finish_dynamic_sections \
2832 elf64_hppa_finish_dynamic_sections
2833 #define elf_backend_grok_prstatus elf64_hppa_grok_prstatus
2834 #define elf_backend_grok_psinfo elf64_hppa_grok_psinfo
2836 /* Stuff for the BFD linker: */
2837 #define bfd_elf64_bfd_link_hash_table_create \
2838 elf64_hppa_hash_table_create
2840 #define elf_backend_check_relocs \
2841 elf64_hppa_check_relocs
2843 #define elf_backend_size_info \
2844 hppa64_elf_size_info
2846 #define elf_backend_additional_program_headers \
2847 elf64_hppa_additional_program_headers
2849 #define elf_backend_modify_segment_map \
2850 elf64_hppa_modify_segment_map
2852 #define elf_backend_link_output_symbol_hook \
2853 elf64_hppa_link_output_symbol_hook
2855 #define elf_backend_want_got_plt 0
2856 #define elf_backend_plt_readonly 0
2857 #define elf_backend_want_plt_sym 0
2858 #define elf_backend_got_header_size 0
2859 #define elf_backend_type_change_ok TRUE
2860 #define elf_backend_get_symbol_type elf64_hppa_elf_get_symbol_type
2861 #define elf_backend_reloc_type_class elf64_hppa_reloc_type_class
2862 #define elf_backend_rela_normal 1
2863 #define elf_backend_special_sections elf64_hppa_special_sections
2864 #define elf_backend_action_discarded elf_hppa_action_discarded
2865 #define elf_backend_section_from_phdr elf64_hppa_section_from_phdr
2867 #define elf64_bed elf64_hppa_hpux_bed
2869 #include "elf64-target.h"
2871 #undef TARGET_BIG_SYM
2872 #define TARGET_BIG_SYM bfd_elf64_hppa_linux_vec
2873 #undef TARGET_BIG_NAME
2874 #define TARGET_BIG_NAME "elf64-hppa-linux"
2876 #define ELF_OSABI ELFOSABI_LINUX
2877 #undef elf_backend_post_process_headers
2878 #define elf_backend_post_process_headers _bfd_elf_set_osabi
2880 #define elf64_bed elf64_hppa_linux_bed
2882 #include "elf64-target.h"