1 /* Support for HPPA 64-bit ELF
2 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
3 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
28 #include "elf64-hppa.h"
30 /* This is the code recommended in the autoconf documentation, almost
37 /* Indented so that pre-ansi C compilers will ignore it, rather than
38 choke on it. Some versions of AIX require this to be the first
42 # ifndef alloca /* predefined by HP cc +Olibcalls */
43 # if !defined (__STDC__) && !defined (__hpux)
44 extern char *alloca ();
46 extern void *alloca ();
47 # endif /* __STDC__, __hpux */
50 # endif /* HAVE_ALLOCA_H */
52 extern void *alloca (size_t);
58 #define PLT_ENTRY_SIZE 0x10
59 #define DLT_ENTRY_SIZE 0x8
60 #define OPD_ENTRY_SIZE 0x20
62 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/pa20_64/dld.sl"
64 /* The stub is supposed to load the target address and target's DP
65 value out of the PLT, then do an external branch to the target
70 LDD PLTOFF+8(%r27),%r27
72 Note that we must use the LDD with a 14 bit displacement, not the one
73 with a 5 bit displacement. */
74 static char plt_stub
[] = {0x53, 0x61, 0x00, 0x00, 0xe8, 0x20, 0xd0, 0x00,
75 0x53, 0x7b, 0x00, 0x00 };
77 struct elf64_hppa_dyn_hash_entry
79 struct bfd_hash_entry root
;
81 /* Offsets for this symbol in various linker sections. */
87 /* The symbol table entry, if any, that this was derived from. */
88 struct elf_link_hash_entry
*h
;
90 /* The index of the (possibly local) symbol in the input bfd and its
91 associated BFD. Needed so that we can have relocs against local
92 symbols in shared libraries. */
96 /* Dynamic symbols may need to have two different values. One for
97 the dynamic symbol table, one for the normal symbol table.
99 In such cases we store the symbol's real value and section
100 index here so we can restore the real value before we write
101 the normal symbol table. */
105 /* Used to count non-got, non-plt relocations for delayed sizing
106 of relocation sections. */
107 struct elf64_hppa_dyn_reloc_entry
109 /* Next relocation in the chain. */
110 struct elf64_hppa_dyn_reloc_entry
*next
;
112 /* The type of the relocation. */
115 /* The input section of the relocation. */
118 /* The index of the section symbol for the input section of
119 the relocation. Only needed when building shared libraries. */
122 /* The offset within the input section of the relocation. */
125 /* The addend for the relocation. */
130 /* Nonzero if this symbol needs an entry in one of the linker
138 struct elf64_hppa_dyn_hash_table
140 struct bfd_hash_table root
;
143 struct elf64_hppa_link_hash_table
145 struct elf_link_hash_table root
;
147 /* Shortcuts to get to the various linker defined sections. */
149 asection
*dlt_rel_sec
;
151 asection
*plt_rel_sec
;
153 asection
*opd_rel_sec
;
154 asection
*other_rel_sec
;
156 /* Offset of __gp within .plt section. When the PLT gets large we want
157 to slide __gp into the PLT section so that we can continue to use
158 single DP relative instructions to load values out of the PLT. */
161 /* Note this is not strictly correct. We should create a stub section for
162 each input section with calls. The stub section should be placed before
163 the section with the call. */
166 bfd_vma text_segment_base
;
167 bfd_vma data_segment_base
;
169 struct elf64_hppa_dyn_hash_table dyn_hash_table
;
171 /* We build tables to map from an input section back to its
172 symbol index. This is the BFD for which we currently have
174 bfd
*section_syms_bfd
;
176 /* Array of symbol numbers for each input section attached to the
181 #define elf64_hppa_hash_table(p) \
182 ((struct elf64_hppa_link_hash_table *) ((p)->hash))
184 typedef struct bfd_hash_entry
*(*new_hash_entry_func
)
185 (struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *);
187 static struct bfd_hash_entry
*elf64_hppa_new_dyn_hash_entry
188 (struct bfd_hash_entry
*entry
, struct bfd_hash_table
*table
,
191 static struct bfd_link_hash_table
*elf64_hppa_hash_table_create
194 static struct elf64_hppa_dyn_hash_entry
*elf64_hppa_dyn_hash_lookup
195 (struct elf64_hppa_dyn_hash_table
*table
, const char *string
,
196 bfd_boolean create
, bfd_boolean copy
);
198 static void elf64_hppa_dyn_hash_traverse
199 (struct elf64_hppa_dyn_hash_table
*table
,
200 bfd_boolean (*func
) (struct elf64_hppa_dyn_hash_entry
*, void *),
203 static const char *get_dyn_name
204 (bfd
*, struct elf_link_hash_entry
*,
205 const Elf_Internal_Rela
*, char **, size_t *);
207 /* This must follow the definitions of the various derived linker
208 hash tables and shared functions. */
209 #include "elf-hppa.h"
211 static bfd_boolean elf64_hppa_object_p
214 static void elf64_hppa_post_process_headers
215 (bfd
*, struct bfd_link_info
*);
217 static bfd_boolean elf64_hppa_create_dynamic_sections
218 (bfd
*, struct bfd_link_info
*);
220 static bfd_boolean elf64_hppa_adjust_dynamic_symbol
221 (struct bfd_link_info
*, struct elf_link_hash_entry
*);
223 static bfd_boolean elf64_hppa_mark_milli_and_exported_functions
224 (struct elf_link_hash_entry
*, void *);
226 static bfd_boolean elf64_hppa_size_dynamic_sections
227 (bfd
*, struct bfd_link_info
*);
229 static bfd_boolean elf64_hppa_link_output_symbol_hook
230 (struct bfd_link_info
*, const char *, Elf_Internal_Sym
*,
231 asection
*, struct elf_link_hash_entry
*);
233 static bfd_boolean elf64_hppa_finish_dynamic_symbol
234 (bfd
*, struct bfd_link_info
*,
235 struct elf_link_hash_entry
*, Elf_Internal_Sym
*);
237 static enum elf_reloc_type_class elf64_hppa_reloc_type_class
238 (const Elf_Internal_Rela
*);
240 static bfd_boolean elf64_hppa_finish_dynamic_sections
241 (bfd
*, struct bfd_link_info
*);
243 static bfd_boolean elf64_hppa_check_relocs
244 (bfd
*, struct bfd_link_info
*,
245 asection
*, const Elf_Internal_Rela
*);
247 static bfd_boolean elf64_hppa_dynamic_symbol_p
248 (struct elf_link_hash_entry
*, struct bfd_link_info
*);
250 static bfd_boolean elf64_hppa_mark_exported_functions
251 (struct elf_link_hash_entry
*, void *);
253 static bfd_boolean elf64_hppa_finalize_opd
254 (struct elf64_hppa_dyn_hash_entry
*, void *);
256 static bfd_boolean elf64_hppa_finalize_dlt
257 (struct elf64_hppa_dyn_hash_entry
*, void *);
259 static bfd_boolean allocate_global_data_dlt
260 (struct elf64_hppa_dyn_hash_entry
*, void *);
262 static bfd_boolean allocate_global_data_plt
263 (struct elf64_hppa_dyn_hash_entry
*, void *);
265 static bfd_boolean allocate_global_data_stub
266 (struct elf64_hppa_dyn_hash_entry
*, void *);
268 static bfd_boolean allocate_global_data_opd
269 (struct elf64_hppa_dyn_hash_entry
*, void *);
271 static bfd_boolean get_reloc_section
272 (bfd
*, struct elf64_hppa_link_hash_table
*, asection
*);
274 static bfd_boolean count_dyn_reloc
275 (bfd
*, struct elf64_hppa_dyn_hash_entry
*,
276 int, asection
*, int, bfd_vma
, bfd_vma
);
278 static bfd_boolean allocate_dynrel_entries
279 (struct elf64_hppa_dyn_hash_entry
*, void *);
281 static bfd_boolean elf64_hppa_finalize_dynreloc
282 (struct elf64_hppa_dyn_hash_entry
*, void *);
284 static bfd_boolean get_opd
285 (bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*);
287 static bfd_boolean get_plt
288 (bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*);
290 static bfd_boolean get_dlt
291 (bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*);
293 static bfd_boolean get_stub
294 (bfd
*, struct bfd_link_info
*, struct elf64_hppa_link_hash_table
*);
296 static int elf64_hppa_elf_get_symbol_type
297 (Elf_Internal_Sym
*, int);
300 elf64_hppa_dyn_hash_table_init (struct elf64_hppa_dyn_hash_table
*ht
,
301 bfd
*abfd ATTRIBUTE_UNUSED
,
302 new_hash_entry_func
new,
303 unsigned int entsize
)
305 memset (ht
, 0, sizeof (*ht
));
306 return bfd_hash_table_init (&ht
->root
, new, entsize
);
309 static struct bfd_hash_entry
*
310 elf64_hppa_new_dyn_hash_entry (struct bfd_hash_entry
*entry
,
311 struct bfd_hash_table
*table
,
314 struct elf64_hppa_dyn_hash_entry
*ret
;
315 ret
= (struct elf64_hppa_dyn_hash_entry
*) entry
;
317 /* Allocate the structure if it has not already been allocated by a
320 ret
= bfd_hash_allocate (table
, sizeof (*ret
));
325 /* Call the allocation method of the superclass. */
326 ret
= ((struct elf64_hppa_dyn_hash_entry
*)
327 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
329 /* Initialize our local data. All zeros. */
330 memset (&ret
->dlt_offset
, 0,
331 (sizeof (struct elf64_hppa_dyn_hash_entry
)
332 - offsetof (struct elf64_hppa_dyn_hash_entry
, dlt_offset
)));
337 /* Create the derived linker hash table. The PA64 ELF port uses this
338 derived hash table to keep information specific to the PA ElF
339 linker (without using static variables). */
341 static struct bfd_link_hash_table
*
342 elf64_hppa_hash_table_create (bfd
*abfd
)
344 struct elf64_hppa_link_hash_table
*ret
;
346 ret
= bfd_zalloc (abfd
, (bfd_size_type
) sizeof (*ret
));
349 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
350 _bfd_elf_link_hash_newfunc
,
351 sizeof (struct elf_link_hash_entry
)))
353 bfd_release (abfd
, ret
);
357 if (!elf64_hppa_dyn_hash_table_init (&ret
->dyn_hash_table
, abfd
,
358 elf64_hppa_new_dyn_hash_entry
,
359 sizeof (struct elf64_hppa_dyn_hash_entry
)))
361 return &ret
->root
.root
;
364 /* Look up an entry in a PA64 ELF linker hash table. */
366 static struct elf64_hppa_dyn_hash_entry
*
367 elf64_hppa_dyn_hash_lookup(struct elf64_hppa_dyn_hash_table
*table
,
372 return ((struct elf64_hppa_dyn_hash_entry
*)
373 bfd_hash_lookup (&table
->root
, string
, create
, copy
));
376 /* Traverse a PA64 ELF linker hash table. */
379 elf64_hppa_dyn_hash_traverse (struct elf64_hppa_dyn_hash_table
*table
,
380 bfd_boolean (*func
) (struct elf64_hppa_dyn_hash_entry
*, void *),
383 bfd_hash_traverse (&table
->root
,
384 (bfd_boolean (*) (struct bfd_hash_entry
*, void *)) func
,
388 /* Return nonzero if ABFD represents a PA2.0 ELF64 file.
390 Additionally we set the default architecture and machine. */
392 elf64_hppa_object_p (bfd
*abfd
)
394 Elf_Internal_Ehdr
* i_ehdrp
;
397 i_ehdrp
= elf_elfheader (abfd
);
398 if (strcmp (bfd_get_target (abfd
), "elf64-hppa-linux") == 0)
400 /* GCC on hppa-linux produces binaries with OSABI=Linux,
401 but the kernel produces corefiles with OSABI=SysV. */
402 if (i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_LINUX
403 && i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_NONE
) /* aka SYSV */
408 /* HPUX produces binaries with OSABI=HPUX,
409 but the kernel produces corefiles with OSABI=SysV. */
410 if (i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_HPUX
411 && i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_NONE
) /* aka SYSV */
415 flags
= i_ehdrp
->e_flags
;
416 switch (flags
& (EF_PARISC_ARCH
| EF_PARISC_WIDE
))
419 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 10);
421 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 11);
423 if (i_ehdrp
->e_ident
[EI_CLASS
] == ELFCLASS64
)
424 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 25);
426 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 20);
427 case EFA_PARISC_2_0
| EF_PARISC_WIDE
:
428 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 25);
430 /* Don't be fussy. */
434 /* Given section type (hdr->sh_type), return a boolean indicating
435 whether or not the section is an elf64-hppa specific section. */
437 elf64_hppa_section_from_shdr (bfd
*abfd
,
438 Elf_Internal_Shdr
*hdr
,
444 switch (hdr
->sh_type
)
447 if (strcmp (name
, ".PARISC.archext") != 0)
450 case SHT_PARISC_UNWIND
:
451 if (strcmp (name
, ".PARISC.unwind") != 0)
455 case SHT_PARISC_ANNOT
:
460 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
462 newsect
= hdr
->bfd_section
;
467 /* Construct a string for use in the elf64_hppa_dyn_hash_table. The
468 name describes what was once potentially anonymous memory. We
469 allocate memory as necessary, possibly reusing PBUF/PLEN. */
472 get_dyn_name (bfd
*abfd
,
473 struct elf_link_hash_entry
*h
,
474 const Elf_Internal_Rela
*rel
,
478 asection
*sec
= abfd
->sections
;
483 if (h
&& rel
->r_addend
== 0)
484 return h
->root
.root
.string
;
487 nlen
= strlen (h
->root
.root
.string
);
489 nlen
= 8 + 1 + sizeof (rel
->r_info
) * 2 - 8;
490 tlen
= nlen
+ 1 + sizeof (rel
->r_addend
) * 2 + 1;
498 *pbuf
= buf
= malloc (tlen
);
506 memcpy (buf
, h
->root
.root
.string
, nlen
);
508 sprintf_vma (buf
+ nlen
, rel
->r_addend
);
512 nlen
= sprintf (buf
, "%x:%lx",
513 sec
->id
& 0xffffffff,
514 (unsigned long) ELF64_R_SYM (rel
->r_info
));
518 sprintf_vma (buf
+ nlen
, rel
->r_addend
);
525 /* SEC is a section containing relocs for an input BFD when linking; return
526 a suitable section for holding relocs in the output BFD for a link. */
529 get_reloc_section (bfd
*abfd
,
530 struct elf64_hppa_link_hash_table
*hppa_info
,
533 const char *srel_name
;
537 srel_name
= (bfd_elf_string_from_elf_section
538 (abfd
, elf_elfheader(abfd
)->e_shstrndx
,
539 elf_section_data(sec
)->rel_hdr
.sh_name
));
540 if (srel_name
== NULL
)
543 BFD_ASSERT ((CONST_STRNEQ (srel_name
, ".rela")
544 && strcmp (bfd_get_section_name (abfd
, sec
),
546 || (CONST_STRNEQ (srel_name
, ".rel")
547 && strcmp (bfd_get_section_name (abfd
, sec
),
548 srel_name
+ 4) == 0));
550 dynobj
= hppa_info
->root
.dynobj
;
552 hppa_info
->root
.dynobj
= dynobj
= abfd
;
554 srel
= bfd_get_section_by_name (dynobj
, srel_name
);
557 srel
= bfd_make_section_with_flags (dynobj
, srel_name
,
565 || !bfd_set_section_alignment (dynobj
, srel
, 3))
569 hppa_info
->other_rel_sec
= srel
;
573 /* Add a new entry to the list of dynamic relocations against DYN_H.
575 We use this to keep a record of all the FPTR relocations against a
576 particular symbol so that we can create FPTR relocations in the
580 count_dyn_reloc (bfd
*abfd
,
581 struct elf64_hppa_dyn_hash_entry
*dyn_h
,
588 struct elf64_hppa_dyn_reloc_entry
*rent
;
590 rent
= (struct elf64_hppa_dyn_reloc_entry
*)
591 bfd_alloc (abfd
, (bfd_size_type
) sizeof (*rent
));
595 rent
->next
= dyn_h
->reloc_entries
;
598 rent
->sec_symndx
= sec_symndx
;
599 rent
->offset
= offset
;
600 rent
->addend
= addend
;
601 dyn_h
->reloc_entries
= rent
;
606 /* Scan the RELOCS and record the type of dynamic entries that each
607 referenced symbol needs. */
610 elf64_hppa_check_relocs (bfd
*abfd
,
611 struct bfd_link_info
*info
,
613 const Elf_Internal_Rela
*relocs
)
615 struct elf64_hppa_link_hash_table
*hppa_info
;
616 const Elf_Internal_Rela
*relend
;
617 Elf_Internal_Shdr
*symtab_hdr
;
618 const Elf_Internal_Rela
*rel
;
619 asection
*dlt
, *plt
, *stubs
;
622 unsigned int sec_symndx
;
624 if (info
->relocatable
)
627 /* If this is the first dynamic object found in the link, create
628 the special sections required for dynamic linking. */
629 if (! elf_hash_table (info
)->dynamic_sections_created
)
631 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
635 hppa_info
= elf64_hppa_hash_table (info
);
636 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
638 /* If necessary, build a new table holding section symbols indices
641 if (info
->shared
&& hppa_info
->section_syms_bfd
!= abfd
)
644 unsigned int highest_shndx
;
645 Elf_Internal_Sym
*local_syms
= NULL
;
646 Elf_Internal_Sym
*isym
, *isymend
;
649 /* We're done with the old cache of section index to section symbol
650 index information. Free it.
652 ?!? Note we leak the last section_syms array. Presumably we
653 could free it in one of the later routines in this file. */
654 if (hppa_info
->section_syms
)
655 free (hppa_info
->section_syms
);
657 /* Read this BFD's local symbols. */
658 if (symtab_hdr
->sh_info
!= 0)
660 local_syms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
661 if (local_syms
== NULL
)
662 local_syms
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
663 symtab_hdr
->sh_info
, 0,
665 if (local_syms
== NULL
)
669 /* Record the highest section index referenced by the local symbols. */
671 isymend
= local_syms
+ symtab_hdr
->sh_info
;
672 for (isym
= local_syms
; isym
< isymend
; isym
++)
674 if (isym
->st_shndx
> highest_shndx
675 && isym
->st_shndx
< SHN_LORESERVE
)
676 highest_shndx
= isym
->st_shndx
;
679 /* Allocate an array to hold the section index to section symbol index
680 mapping. Bump by one since we start counting at zero. */
684 hppa_info
->section_syms
= (int *) bfd_malloc (amt
);
686 /* Now walk the local symbols again. If we find a section symbol,
687 record the index of the symbol into the section_syms array. */
688 for (i
= 0, isym
= local_syms
; isym
< isymend
; i
++, isym
++)
690 if (ELF_ST_TYPE (isym
->st_info
) == STT_SECTION
)
691 hppa_info
->section_syms
[isym
->st_shndx
] = i
;
694 /* We are finished with the local symbols. */
695 if (local_syms
!= NULL
696 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
698 if (! info
->keep_memory
)
702 /* Cache the symbols for elf_link_input_bfd. */
703 symtab_hdr
->contents
= (unsigned char *) local_syms
;
707 /* Record which BFD we built the section_syms mapping for. */
708 hppa_info
->section_syms_bfd
= abfd
;
711 /* Record the symbol index for this input section. We may need it for
712 relocations when building shared libraries. When not building shared
713 libraries this value is never really used, but assign it to zero to
714 prevent out of bounds memory accesses in other routines. */
717 sec_symndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
719 /* If we did not find a section symbol for this section, then
720 something went terribly wrong above. */
721 if (sec_symndx
== SHN_BAD
)
724 if (sec_symndx
< SHN_LORESERVE
)
725 sec_symndx
= hppa_info
->section_syms
[sec_symndx
];
732 dlt
= plt
= stubs
= NULL
;
736 relend
= relocs
+ sec
->reloc_count
;
737 for (rel
= relocs
; rel
< relend
; ++rel
)
748 struct elf_link_hash_entry
*h
= NULL
;
749 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
750 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
752 const char *addr_name
;
753 bfd_boolean maybe_dynamic
;
754 int dynrel_type
= R_PARISC_NONE
;
755 static reloc_howto_type
*howto
;
757 if (r_symndx
>= symtab_hdr
->sh_info
)
759 /* We're dealing with a global symbol -- find its hash entry
760 and mark it as being referenced. */
761 long indx
= r_symndx
- symtab_hdr
->sh_info
;
762 h
= elf_sym_hashes (abfd
)[indx
];
763 while (h
->root
.type
== bfd_link_hash_indirect
764 || h
->root
.type
== bfd_link_hash_warning
)
765 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
770 /* We can only get preliminary data on whether a symbol is
771 locally or externally defined, as not all of the input files
772 have yet been processed. Do something with what we know, as
773 this may help reduce memory usage and processing time later. */
774 maybe_dynamic
= FALSE
;
775 if (h
&& ((info
->shared
777 || info
->unresolved_syms_in_shared_libs
== RM_IGNORE
))
779 || h
->root
.type
== bfd_link_hash_defweak
))
780 maybe_dynamic
= TRUE
;
782 howto
= elf_hppa_howto_table
+ ELF64_R_TYPE (rel
->r_info
);
786 /* These are simple indirect references to symbols through the
787 DLT. We need to create a DLT entry for any symbols which
788 appears in a DLTIND relocation. */
789 case R_PARISC_DLTIND21L
:
790 case R_PARISC_DLTIND14R
:
791 case R_PARISC_DLTIND14F
:
792 case R_PARISC_DLTIND14WR
:
793 case R_PARISC_DLTIND14DR
:
794 need_entry
= NEED_DLT
;
797 /* ?!? These need a DLT entry. But I have no idea what to do with
798 the "link time TP value. */
799 case R_PARISC_LTOFF_TP21L
:
800 case R_PARISC_LTOFF_TP14R
:
801 case R_PARISC_LTOFF_TP14F
:
802 case R_PARISC_LTOFF_TP64
:
803 case R_PARISC_LTOFF_TP14WR
:
804 case R_PARISC_LTOFF_TP14DR
:
805 case R_PARISC_LTOFF_TP16F
:
806 case R_PARISC_LTOFF_TP16WF
:
807 case R_PARISC_LTOFF_TP16DF
:
808 need_entry
= NEED_DLT
;
811 /* These are function calls. Depending on their precise target we
812 may need to make a stub for them. The stub uses the PLT, so we
813 need to create PLT entries for these symbols too. */
814 case R_PARISC_PCREL12F
:
815 case R_PARISC_PCREL17F
:
816 case R_PARISC_PCREL22F
:
817 case R_PARISC_PCREL32
:
818 case R_PARISC_PCREL64
:
819 case R_PARISC_PCREL21L
:
820 case R_PARISC_PCREL17R
:
821 case R_PARISC_PCREL17C
:
822 case R_PARISC_PCREL14R
:
823 case R_PARISC_PCREL14F
:
824 case R_PARISC_PCREL22C
:
825 case R_PARISC_PCREL14WR
:
826 case R_PARISC_PCREL14DR
:
827 case R_PARISC_PCREL16F
:
828 case R_PARISC_PCREL16WF
:
829 case R_PARISC_PCREL16DF
:
830 need_entry
= (NEED_PLT
| NEED_STUB
);
833 case R_PARISC_PLTOFF21L
:
834 case R_PARISC_PLTOFF14R
:
835 case R_PARISC_PLTOFF14F
:
836 case R_PARISC_PLTOFF14WR
:
837 case R_PARISC_PLTOFF14DR
:
838 case R_PARISC_PLTOFF16F
:
839 case R_PARISC_PLTOFF16WF
:
840 case R_PARISC_PLTOFF16DF
:
841 need_entry
= (NEED_PLT
);
845 if (info
->shared
|| maybe_dynamic
)
846 need_entry
= (NEED_DYNREL
);
847 dynrel_type
= R_PARISC_DIR64
;
850 /* This is an indirect reference through the DLT to get the address
851 of a OPD descriptor. Thus we need to make a DLT entry that points
853 case R_PARISC_LTOFF_FPTR21L
:
854 case R_PARISC_LTOFF_FPTR14R
:
855 case R_PARISC_LTOFF_FPTR14WR
:
856 case R_PARISC_LTOFF_FPTR14DR
:
857 case R_PARISC_LTOFF_FPTR32
:
858 case R_PARISC_LTOFF_FPTR64
:
859 case R_PARISC_LTOFF_FPTR16F
:
860 case R_PARISC_LTOFF_FPTR16WF
:
861 case R_PARISC_LTOFF_FPTR16DF
:
862 if (info
->shared
|| maybe_dynamic
)
863 need_entry
= (NEED_DLT
| NEED_OPD
);
865 need_entry
= (NEED_DLT
| NEED_OPD
);
866 dynrel_type
= R_PARISC_FPTR64
;
869 /* This is a simple OPD entry. */
870 case R_PARISC_FPTR64
:
871 if (info
->shared
|| maybe_dynamic
)
872 need_entry
= (NEED_OPD
| NEED_DYNREL
);
874 need_entry
= (NEED_OPD
);
875 dynrel_type
= R_PARISC_FPTR64
;
878 /* Add more cases as needed. */
884 /* Collect a canonical name for this address. */
885 addr_name
= get_dyn_name (abfd
, h
, rel
, &buf
, &buf_len
);
887 /* Collect the canonical entry data for this address. */
888 dyn_h
= elf64_hppa_dyn_hash_lookup (&hppa_info
->dyn_hash_table
,
889 addr_name
, TRUE
, TRUE
);
892 /* Stash away enough information to be able to find this symbol
893 regardless of whether or not it is local or global. */
896 dyn_h
->sym_indx
= r_symndx
;
898 /* ?!? We may need to do some error checking in here. */
899 /* Create what's needed. */
900 if (need_entry
& NEED_DLT
)
902 if (! hppa_info
->dlt_sec
903 && ! get_dlt (abfd
, info
, hppa_info
))
908 if (need_entry
& NEED_PLT
)
910 if (! hppa_info
->plt_sec
911 && ! get_plt (abfd
, info
, hppa_info
))
916 if (need_entry
& NEED_STUB
)
918 if (! hppa_info
->stub_sec
919 && ! get_stub (abfd
, info
, hppa_info
))
921 dyn_h
->want_stub
= 1;
924 if (need_entry
& NEED_OPD
)
926 if (! hppa_info
->opd_sec
927 && ! get_opd (abfd
, info
, hppa_info
))
932 /* FPTRs are not allocated by the dynamic linker for PA64, though
933 it is possible that will change in the future. */
935 /* This could be a local function that had its address taken, in
936 which case H will be NULL. */
941 /* Add a new dynamic relocation to the chain of dynamic
942 relocations for this symbol. */
943 if ((need_entry
& NEED_DYNREL
) && (sec
->flags
& SEC_ALLOC
))
945 if (! hppa_info
->other_rel_sec
946 && ! get_reloc_section (abfd
, hppa_info
, sec
))
949 if (!count_dyn_reloc (abfd
, dyn_h
, dynrel_type
, sec
,
950 sec_symndx
, rel
->r_offset
, rel
->r_addend
))
953 /* If we are building a shared library and we just recorded
954 a dynamic R_PARISC_FPTR64 relocation, then make sure the
955 section symbol for this section ends up in the dynamic
957 if (info
->shared
&& dynrel_type
== R_PARISC_FPTR64
958 && ! (bfd_elf_link_record_local_dynamic_symbol
959 (info
, abfd
, sec_symndx
)))
974 struct elf64_hppa_allocate_data
976 struct bfd_link_info
*info
;
980 /* Should we do dynamic things to this symbol? */
983 elf64_hppa_dynamic_symbol_p (struct elf_link_hash_entry
*h
,
984 struct bfd_link_info
*info
)
986 /* ??? What, if anything, needs to happen wrt STV_PROTECTED symbols
987 and relocations that retrieve a function descriptor? Assume the
989 if (_bfd_elf_dynamic_symbol_p (h
, info
, 1))
991 /* ??? Why is this here and not elsewhere is_local_label_name. */
992 if (h
->root
.root
.string
[0] == '$' && h
->root
.root
.string
[1] == '$')
1001 /* Mark all functions exported by this file so that we can later allocate
1002 entries in .opd for them. */
1005 elf64_hppa_mark_exported_functions (struct elf_link_hash_entry
*h
,
1008 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
1009 struct elf64_hppa_link_hash_table
*hppa_info
;
1011 hppa_info
= elf64_hppa_hash_table (info
);
1013 if (h
->root
.type
== bfd_link_hash_warning
)
1014 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1017 && (h
->root
.type
== bfd_link_hash_defined
1018 || h
->root
.type
== bfd_link_hash_defweak
)
1019 && h
->root
.u
.def
.section
->output_section
!= NULL
1020 && h
->type
== STT_FUNC
)
1022 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
1024 /* Add this symbol to the PA64 linker hash table. */
1025 dyn_h
= elf64_hppa_dyn_hash_lookup (&hppa_info
->dyn_hash_table
,
1026 h
->root
.root
.string
, TRUE
, TRUE
);
1030 if (! hppa_info
->opd_sec
1031 && ! get_opd (hppa_info
->root
.dynobj
, info
, hppa_info
))
1034 dyn_h
->want_opd
= 1;
1035 /* Put a flag here for output_symbol_hook. */
1036 dyn_h
->st_shndx
= -1;
1043 /* Allocate space for a DLT entry. */
1046 allocate_global_data_dlt (struct elf64_hppa_dyn_hash_entry
*dyn_h
,
1049 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1051 if (dyn_h
->want_dlt
)
1053 struct elf_link_hash_entry
*h
= dyn_h
->h
;
1055 if (x
->info
->shared
)
1057 /* Possibly add the symbol to the local dynamic symbol
1058 table since we might need to create a dynamic relocation
1061 || (h
->dynindx
== -1 && h
->type
!= STT_PARISC_MILLI
))
1064 owner
= (h
? h
->root
.u
.def
.section
->owner
: dyn_h
->owner
);
1066 if (! (bfd_elf_link_record_local_dynamic_symbol
1067 (x
->info
, owner
, dyn_h
->sym_indx
)))
1072 dyn_h
->dlt_offset
= x
->ofs
;
1073 x
->ofs
+= DLT_ENTRY_SIZE
;
1078 /* Allocate space for a DLT.PLT entry. */
1081 allocate_global_data_plt (struct elf64_hppa_dyn_hash_entry
*dyn_h
,
1084 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1087 && elf64_hppa_dynamic_symbol_p (dyn_h
->h
, x
->info
)
1088 && !((dyn_h
->h
->root
.type
== bfd_link_hash_defined
1089 || dyn_h
->h
->root
.type
== bfd_link_hash_defweak
)
1090 && dyn_h
->h
->root
.u
.def
.section
->output_section
!= NULL
))
1092 dyn_h
->plt_offset
= x
->ofs
;
1093 x
->ofs
+= PLT_ENTRY_SIZE
;
1094 if (dyn_h
->plt_offset
< 0x2000)
1095 elf64_hppa_hash_table (x
->info
)->gp_offset
= dyn_h
->plt_offset
;
1098 dyn_h
->want_plt
= 0;
1103 /* Allocate space for a STUB entry. */
1106 allocate_global_data_stub (struct elf64_hppa_dyn_hash_entry
*dyn_h
,
1109 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1111 if (dyn_h
->want_stub
1112 && elf64_hppa_dynamic_symbol_p (dyn_h
->h
, x
->info
)
1113 && !((dyn_h
->h
->root
.type
== bfd_link_hash_defined
1114 || dyn_h
->h
->root
.type
== bfd_link_hash_defweak
)
1115 && dyn_h
->h
->root
.u
.def
.section
->output_section
!= NULL
))
1117 dyn_h
->stub_offset
= x
->ofs
;
1118 x
->ofs
+= sizeof (plt_stub
);
1121 dyn_h
->want_stub
= 0;
1125 /* Allocate space for a FPTR entry. */
1128 allocate_global_data_opd (struct elf64_hppa_dyn_hash_entry
*dyn_h
,
1131 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1133 if (dyn_h
->want_opd
)
1135 struct elf_link_hash_entry
*h
= dyn_h
->h
;
1138 while (h
->root
.type
== bfd_link_hash_indirect
1139 || h
->root
.type
== bfd_link_hash_warning
)
1140 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1142 /* We never need an opd entry for a symbol which is not
1143 defined by this output file. */
1144 if (h
&& (h
->root
.type
== bfd_link_hash_undefined
1145 || h
->root
.type
== bfd_link_hash_undefweak
1146 || h
->root
.u
.def
.section
->output_section
== NULL
))
1147 dyn_h
->want_opd
= 0;
1149 /* If we are creating a shared library, took the address of a local
1150 function or might export this function from this object file, then
1151 we have to create an opd descriptor. */
1152 else if (x
->info
->shared
1154 || (h
->dynindx
== -1 && h
->type
!= STT_PARISC_MILLI
)
1155 || (h
->root
.type
== bfd_link_hash_defined
1156 || h
->root
.type
== bfd_link_hash_defweak
))
1158 /* If we are creating a shared library, then we will have to
1159 create a runtime relocation for the symbol to properly
1160 initialize the .opd entry. Make sure the symbol gets
1161 added to the dynamic symbol table. */
1163 && (h
== NULL
|| (h
->dynindx
== -1)))
1166 /* PR 6511: Default to using the dynamic symbol table. */
1167 owner
= (dyn_h
->owner
? dyn_h
->owner
: h
->root
.u
.def
.section
->owner
);
1169 if (!bfd_elf_link_record_local_dynamic_symbol
1170 (x
->info
, owner
, dyn_h
->sym_indx
))
1174 /* This may not be necessary or desirable anymore now that
1175 we have some support for dealing with section symbols
1176 in dynamic relocs. But name munging does make the result
1177 much easier to debug. ie, the EPLT reloc will reference
1178 a symbol like .foobar, instead of .text + offset. */
1179 if (x
->info
->shared
&& h
)
1182 struct elf_link_hash_entry
*nh
;
1184 new_name
= alloca (strlen (h
->root
.root
.string
) + 2);
1186 strcpy (new_name
+ 1, h
->root
.root
.string
);
1188 nh
= elf_link_hash_lookup (elf_hash_table (x
->info
),
1189 new_name
, TRUE
, TRUE
, TRUE
);
1191 nh
->root
.type
= h
->root
.type
;
1192 nh
->root
.u
.def
.value
= h
->root
.u
.def
.value
;
1193 nh
->root
.u
.def
.section
= h
->root
.u
.def
.section
;
1195 if (! bfd_elf_link_record_dynamic_symbol (x
->info
, nh
))
1199 dyn_h
->opd_offset
= x
->ofs
;
1200 x
->ofs
+= OPD_ENTRY_SIZE
;
1203 /* Otherwise we do not need an opd entry. */
1205 dyn_h
->want_opd
= 0;
1210 /* HP requires the EI_OSABI field to be filled in. The assignment to
1211 EI_ABIVERSION may not be strictly necessary. */
1214 elf64_hppa_post_process_headers (bfd
*abfd
,
1215 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
)
1217 Elf_Internal_Ehdr
* i_ehdrp
;
1219 i_ehdrp
= elf_elfheader (abfd
);
1221 i_ehdrp
->e_ident
[EI_OSABI
] = get_elf_backend_data (abfd
)->elf_osabi
;
1222 i_ehdrp
->e_ident
[EI_ABIVERSION
] = 1;
1225 /* Create function descriptor section (.opd). This section is called .opd
1226 because it contains "official procedure descriptors". The "official"
1227 refers to the fact that these descriptors are used when taking the address
1228 of a procedure, thus ensuring a unique address for each procedure. */
1232 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1233 struct elf64_hppa_link_hash_table
*hppa_info
)
1238 opd
= hppa_info
->opd_sec
;
1241 dynobj
= hppa_info
->root
.dynobj
;
1243 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1245 opd
= bfd_make_section_with_flags (dynobj
, ".opd",
1250 | SEC_LINKER_CREATED
));
1252 || !bfd_set_section_alignment (abfd
, opd
, 3))
1258 hppa_info
->opd_sec
= opd
;
1264 /* Create the PLT section. */
1268 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1269 struct elf64_hppa_link_hash_table
*hppa_info
)
1274 plt
= hppa_info
->plt_sec
;
1277 dynobj
= hppa_info
->root
.dynobj
;
1279 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1281 plt
= bfd_make_section_with_flags (dynobj
, ".plt",
1286 | SEC_LINKER_CREATED
));
1288 || !bfd_set_section_alignment (abfd
, plt
, 3))
1294 hppa_info
->plt_sec
= plt
;
1300 /* Create the DLT section. */
1304 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1305 struct elf64_hppa_link_hash_table
*hppa_info
)
1310 dlt
= hppa_info
->dlt_sec
;
1313 dynobj
= hppa_info
->root
.dynobj
;
1315 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1317 dlt
= bfd_make_section_with_flags (dynobj
, ".dlt",
1322 | SEC_LINKER_CREATED
));
1324 || !bfd_set_section_alignment (abfd
, dlt
, 3))
1330 hppa_info
->dlt_sec
= dlt
;
1336 /* Create the stubs section. */
1339 get_stub (bfd
*abfd
,
1340 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1341 struct elf64_hppa_link_hash_table
*hppa_info
)
1346 stub
= hppa_info
->stub_sec
;
1349 dynobj
= hppa_info
->root
.dynobj
;
1351 hppa_info
->root
.dynobj
= dynobj
= abfd
;
1353 stub
= bfd_make_section_with_flags (dynobj
, ".stub",
1354 (SEC_ALLOC
| SEC_LOAD
1358 | SEC_LINKER_CREATED
));
1360 || !bfd_set_section_alignment (abfd
, stub
, 3))
1366 hppa_info
->stub_sec
= stub
;
1372 /* Create sections necessary for dynamic linking. This is only a rough
1373 cut and will likely change as we learn more about the somewhat
1374 unusual dynamic linking scheme HP uses.
1377 Contains code to implement cross-space calls. The first time one
1378 of the stubs is used it will call into the dynamic linker, later
1379 calls will go straight to the target.
1381 The only stub we support right now looks like
1385 ldd OFFSET+8(%dp),%dp
1387 Other stubs may be needed in the future. We may want the remove
1388 the break/nop instruction. It is only used right now to keep the
1389 offset of a .plt entry and a .stub entry in sync.
1392 This is what most people call the .got. HP used a different name.
1396 Relocations for the DLT.
1399 Function pointers as address,gp pairs.
1402 Should contain dynamic IPLT (and EPLT?) relocations.
1408 EPLT relocations for symbols exported from shared libraries. */
1411 elf64_hppa_create_dynamic_sections (bfd
*abfd
,
1412 struct bfd_link_info
*info
)
1416 if (! get_stub (abfd
, info
, elf64_hppa_hash_table (info
)))
1419 if (! get_dlt (abfd
, info
, elf64_hppa_hash_table (info
)))
1422 if (! get_plt (abfd
, info
, elf64_hppa_hash_table (info
)))
1425 if (! get_opd (abfd
, info
, elf64_hppa_hash_table (info
)))
1428 s
= bfd_make_section_with_flags (abfd
, ".rela.dlt",
1429 (SEC_ALLOC
| SEC_LOAD
1433 | SEC_LINKER_CREATED
));
1435 || !bfd_set_section_alignment (abfd
, s
, 3))
1437 elf64_hppa_hash_table (info
)->dlt_rel_sec
= s
;
1439 s
= bfd_make_section_with_flags (abfd
, ".rela.plt",
1440 (SEC_ALLOC
| SEC_LOAD
1444 | SEC_LINKER_CREATED
));
1446 || !bfd_set_section_alignment (abfd
, s
, 3))
1448 elf64_hppa_hash_table (info
)->plt_rel_sec
= s
;
1450 s
= bfd_make_section_with_flags (abfd
, ".rela.data",
1451 (SEC_ALLOC
| SEC_LOAD
1455 | SEC_LINKER_CREATED
));
1457 || !bfd_set_section_alignment (abfd
, s
, 3))
1459 elf64_hppa_hash_table (info
)->other_rel_sec
= s
;
1461 s
= bfd_make_section_with_flags (abfd
, ".rela.opd",
1462 (SEC_ALLOC
| SEC_LOAD
1466 | SEC_LINKER_CREATED
));
1468 || !bfd_set_section_alignment (abfd
, s
, 3))
1470 elf64_hppa_hash_table (info
)->opd_rel_sec
= s
;
1475 /* Allocate dynamic relocations for those symbols that turned out
1479 allocate_dynrel_entries (struct elf64_hppa_dyn_hash_entry
*dyn_h
,
1482 struct elf64_hppa_allocate_data
*x
= (struct elf64_hppa_allocate_data
*)data
;
1483 struct elf64_hppa_link_hash_table
*hppa_info
;
1484 struct elf64_hppa_dyn_reloc_entry
*rent
;
1485 bfd_boolean dynamic_symbol
, shared
;
1487 hppa_info
= elf64_hppa_hash_table (x
->info
);
1488 dynamic_symbol
= elf64_hppa_dynamic_symbol_p (dyn_h
->h
, x
->info
);
1489 shared
= x
->info
->shared
;
1491 /* We may need to allocate relocations for a non-dynamic symbol
1492 when creating a shared library. */
1493 if (!dynamic_symbol
&& !shared
)
1496 /* Take care of the normal data relocations. */
1498 for (rent
= dyn_h
->reloc_entries
; rent
; rent
= rent
->next
)
1500 /* Allocate one iff we are building a shared library, the relocation
1501 isn't a R_PARISC_FPTR64, or we don't want an opd entry. */
1502 if (!shared
&& rent
->type
== R_PARISC_FPTR64
&& dyn_h
->want_opd
)
1505 hppa_info
->other_rel_sec
->size
+= sizeof (Elf64_External_Rela
);
1507 /* Make sure this symbol gets into the dynamic symbol table if it is
1508 not already recorded. ?!? This should not be in the loop since
1509 the symbol need only be added once. */
1511 || (dyn_h
->h
->dynindx
== -1 && dyn_h
->h
->type
!= STT_PARISC_MILLI
))
1512 if (!bfd_elf_link_record_local_dynamic_symbol
1513 (x
->info
, rent
->sec
->owner
, dyn_h
->sym_indx
))
1517 /* Take care of the GOT and PLT relocations. */
1519 if ((dynamic_symbol
|| shared
) && dyn_h
->want_dlt
)
1520 hppa_info
->dlt_rel_sec
->size
+= sizeof (Elf64_External_Rela
);
1522 /* If we are building a shared library, then every symbol that has an
1523 opd entry will need an EPLT relocation to relocate the symbol's address
1524 and __gp value based on the runtime load address. */
1525 if (shared
&& dyn_h
->want_opd
)
1526 hppa_info
->opd_rel_sec
->size
+= sizeof (Elf64_External_Rela
);
1528 if (dyn_h
->want_plt
&& dynamic_symbol
)
1530 bfd_size_type t
= 0;
1532 /* Dynamic symbols get one IPLT relocation. Local symbols in
1533 shared libraries get two REL relocations. Local symbols in
1534 main applications get nothing. */
1536 t
= sizeof (Elf64_External_Rela
);
1538 t
= 2 * sizeof (Elf64_External_Rela
);
1540 hppa_info
->plt_rel_sec
->size
+= t
;
1546 /* Adjust a symbol defined by a dynamic object and referenced by a
1550 elf64_hppa_adjust_dynamic_symbol (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1551 struct elf_link_hash_entry
*h
)
1553 /* ??? Undefined symbols with PLT entries should be re-defined
1554 to be the PLT entry. */
1556 /* If this is a weak symbol, and there is a real definition, the
1557 processor independent code will have arranged for us to see the
1558 real definition first, and we can just use the same value. */
1559 if (h
->u
.weakdef
!= NULL
)
1561 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
1562 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
1563 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
1564 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
1568 /* If this is a reference to a symbol defined by a dynamic object which
1569 is not a function, we might allocate the symbol in our .dynbss section
1570 and allocate a COPY dynamic relocation.
1572 But PA64 code is canonically PIC, so as a rule we can avoid this sort
1578 /* This function is called via elf_link_hash_traverse to mark millicode
1579 symbols with a dynindx of -1 and to remove the string table reference
1580 from the dynamic symbol table. If the symbol is not a millicode symbol,
1581 elf64_hppa_mark_exported_functions is called. */
1584 elf64_hppa_mark_milli_and_exported_functions (struct elf_link_hash_entry
*h
,
1587 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
1588 struct elf_link_hash_entry
*elf
= h
;
1590 if (elf
->root
.type
== bfd_link_hash_warning
)
1591 elf
= (struct elf_link_hash_entry
*) elf
->root
.u
.i
.link
;
1593 if (elf
->type
== STT_PARISC_MILLI
)
1595 if (elf
->dynindx
!= -1)
1598 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
1604 return elf64_hppa_mark_exported_functions (h
, data
);
1607 /* Set the final sizes of the dynamic sections and allocate memory for
1608 the contents of our special sections. */
1611 elf64_hppa_size_dynamic_sections (bfd
*output_bfd
,
1612 struct bfd_link_info
*info
)
1618 bfd_boolean reltext
;
1619 struct elf64_hppa_allocate_data data
;
1620 struct elf64_hppa_link_hash_table
*hppa_info
;
1622 hppa_info
= elf64_hppa_hash_table (info
);
1624 dynobj
= elf_hash_table (info
)->dynobj
;
1625 BFD_ASSERT (dynobj
!= NULL
);
1627 /* Mark each function this program exports so that we will allocate
1628 space in the .opd section for each function's FPTR. If we are
1629 creating dynamic sections, change the dynamic index of millicode
1630 symbols to -1 and remove them from the string table for .dynstr.
1632 We have to traverse the main linker hash table since we have to
1633 find functions which may not have been mentioned in any relocs. */
1634 elf_link_hash_traverse (elf_hash_table (info
),
1635 (elf_hash_table (info
)->dynamic_sections_created
1636 ? elf64_hppa_mark_milli_and_exported_functions
1637 : elf64_hppa_mark_exported_functions
),
1640 if (elf_hash_table (info
)->dynamic_sections_created
)
1642 /* Set the contents of the .interp section to the interpreter. */
1643 if (info
->executable
)
1645 s
= bfd_get_section_by_name (dynobj
, ".interp");
1646 BFD_ASSERT (s
!= NULL
);
1647 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1648 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1653 /* We may have created entries in the .rela.got section.
1654 However, if we are not creating the dynamic sections, we will
1655 not actually use these entries. Reset the size of .rela.dlt,
1656 which will cause it to get stripped from the output file
1658 s
= bfd_get_section_by_name (dynobj
, ".rela.dlt");
1663 /* Allocate the GOT entries. */
1666 if (elf64_hppa_hash_table (info
)->dlt_sec
)
1669 elf64_hppa_dyn_hash_traverse (&hppa_info
->dyn_hash_table
,
1670 allocate_global_data_dlt
, &data
);
1671 hppa_info
->dlt_sec
->size
= data
.ofs
;
1674 elf64_hppa_dyn_hash_traverse (&hppa_info
->dyn_hash_table
,
1675 allocate_global_data_plt
, &data
);
1676 hppa_info
->plt_sec
->size
= data
.ofs
;
1679 elf64_hppa_dyn_hash_traverse (&hppa_info
->dyn_hash_table
,
1680 allocate_global_data_stub
, &data
);
1681 hppa_info
->stub_sec
->size
= data
.ofs
;
1684 /* Allocate space for entries in the .opd section. */
1685 if (elf64_hppa_hash_table (info
)->opd_sec
)
1688 elf64_hppa_dyn_hash_traverse (&hppa_info
->dyn_hash_table
,
1689 allocate_global_data_opd
, &data
);
1690 hppa_info
->opd_sec
->size
= data
.ofs
;
1693 /* Now allocate space for dynamic relocations, if necessary. */
1694 if (hppa_info
->root
.dynamic_sections_created
)
1695 elf64_hppa_dyn_hash_traverse (&hppa_info
->dyn_hash_table
,
1696 allocate_dynrel_entries
, &data
);
1698 /* The sizes of all the sections are set. Allocate memory for them. */
1702 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1706 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
1709 /* It's OK to base decisions on the section name, because none
1710 of the dynobj section names depend upon the input files. */
1711 name
= bfd_get_section_name (dynobj
, s
);
1713 if (strcmp (name
, ".plt") == 0)
1715 /* Remember whether there is a PLT. */
1718 else if (strcmp (name
, ".opd") == 0
1719 || CONST_STRNEQ (name
, ".dlt")
1720 || strcmp (name
, ".stub") == 0
1721 || strcmp (name
, ".got") == 0)
1723 /* Strip this section if we don't need it; see the comment below. */
1725 else if (CONST_STRNEQ (name
, ".rela"))
1731 /* Remember whether there are any reloc sections other
1733 if (strcmp (name
, ".rela.plt") != 0)
1735 const char *outname
;
1739 /* If this relocation section applies to a read only
1740 section, then we probably need a DT_TEXTREL
1741 entry. The entries in the .rela.plt section
1742 really apply to the .got section, which we
1743 created ourselves and so know is not readonly. */
1744 outname
= bfd_get_section_name (output_bfd
,
1746 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
1748 && (target
->flags
& SEC_READONLY
) != 0
1749 && (target
->flags
& SEC_ALLOC
) != 0)
1753 /* We use the reloc_count field as a counter if we need
1754 to copy relocs into the output file. */
1760 /* It's not one of our sections, so don't allocate space. */
1766 /* If we don't need this section, strip it from the
1767 output file. This is mostly to handle .rela.bss and
1768 .rela.plt. We must create both sections in
1769 create_dynamic_sections, because they must be created
1770 before the linker maps input sections to output
1771 sections. The linker does that before
1772 adjust_dynamic_symbol is called, and it is that
1773 function which decides whether anything needs to go
1774 into these sections. */
1775 s
->flags
|= SEC_EXCLUDE
;
1779 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
1782 /* Allocate memory for the section contents if it has not
1783 been allocated already. We use bfd_zalloc here in case
1784 unused entries are not reclaimed before the section's
1785 contents are written out. This should not happen, but this
1786 way if it does, we get a R_PARISC_NONE reloc instead of
1788 if (s
->contents
== NULL
)
1790 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
1791 if (s
->contents
== NULL
)
1796 if (elf_hash_table (info
)->dynamic_sections_created
)
1798 /* Always create a DT_PLTGOT. It actually has nothing to do with
1799 the PLT, it is how we communicate the __gp value of a load
1800 module to the dynamic linker. */
1801 #define add_dynamic_entry(TAG, VAL) \
1802 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
1804 if (!add_dynamic_entry (DT_HP_DLD_FLAGS
, 0)
1805 || !add_dynamic_entry (DT_PLTGOT
, 0))
1808 /* Add some entries to the .dynamic section. We fill in the
1809 values later, in elf64_hppa_finish_dynamic_sections, but we
1810 must add the entries now so that we get the correct size for
1811 the .dynamic section. The DT_DEBUG entry is filled in by the
1812 dynamic linker and used by the debugger. */
1815 if (!add_dynamic_entry (DT_DEBUG
, 0)
1816 || !add_dynamic_entry (DT_HP_DLD_HOOK
, 0)
1817 || !add_dynamic_entry (DT_HP_LOAD_MAP
, 0))
1821 /* Force DT_FLAGS to always be set.
1822 Required by HPUX 11.00 patch PHSS_26559. */
1823 if (!add_dynamic_entry (DT_FLAGS
, (info
)->flags
))
1828 if (!add_dynamic_entry (DT_PLTRELSZ
, 0)
1829 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
1830 || !add_dynamic_entry (DT_JMPREL
, 0))
1836 if (!add_dynamic_entry (DT_RELA
, 0)
1837 || !add_dynamic_entry (DT_RELASZ
, 0)
1838 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
1844 if (!add_dynamic_entry (DT_TEXTREL
, 0))
1846 info
->flags
|= DF_TEXTREL
;
1849 #undef add_dynamic_entry
1854 /* Called after we have output the symbol into the dynamic symbol
1855 table, but before we output the symbol into the normal symbol
1858 For some symbols we had to change their address when outputting
1859 the dynamic symbol table. We undo that change here so that
1860 the symbols have their expected value in the normal symbol
1864 elf64_hppa_link_output_symbol_hook (struct bfd_link_info
*info
,
1866 Elf_Internal_Sym
*sym
,
1867 asection
*input_sec ATTRIBUTE_UNUSED
,
1868 struct elf_link_hash_entry
*h
)
1870 struct elf64_hppa_link_hash_table
*hppa_info
;
1871 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
1873 /* We may be called with the file symbol or section symbols.
1874 They never need munging, so it is safe to ignore them. */
1878 /* Get the PA dyn_symbol (if any) associated with NAME. */
1879 hppa_info
= elf64_hppa_hash_table (info
);
1880 dyn_h
= elf64_hppa_dyn_hash_lookup (&hppa_info
->dyn_hash_table
,
1881 name
, FALSE
, FALSE
);
1882 if (!dyn_h
|| dyn_h
->h
!= h
)
1885 /* Function symbols for which we created .opd entries *may* have been
1886 munged by finish_dynamic_symbol and have to be un-munged here.
1888 Note that finish_dynamic_symbol sometimes turns dynamic symbols
1889 into non-dynamic ones, so we initialize st_shndx to -1 in
1890 mark_exported_functions and check to see if it was overwritten
1891 here instead of just checking dyn_h->h->dynindx. */
1892 if (dyn_h
->want_opd
&& dyn_h
->st_shndx
!= -1)
1894 /* Restore the saved value and section index. */
1895 sym
->st_value
= dyn_h
->st_value
;
1896 sym
->st_shndx
= dyn_h
->st_shndx
;
1902 /* Finish up dynamic symbol handling. We set the contents of various
1903 dynamic sections here. */
1906 elf64_hppa_finish_dynamic_symbol (bfd
*output_bfd
,
1907 struct bfd_link_info
*info
,
1908 struct elf_link_hash_entry
*h
,
1909 Elf_Internal_Sym
*sym
)
1911 asection
*stub
, *splt
, *sdlt
, *sopd
, *spltrel
, *sdltrel
;
1912 struct elf64_hppa_link_hash_table
*hppa_info
;
1913 struct elf64_hppa_dyn_hash_entry
*dyn_h
;
1915 hppa_info
= elf64_hppa_hash_table (info
);
1916 dyn_h
= elf64_hppa_dyn_hash_lookup (&hppa_info
->dyn_hash_table
,
1917 h
->root
.root
.string
, FALSE
, FALSE
);
1919 stub
= hppa_info
->stub_sec
;
1920 splt
= hppa_info
->plt_sec
;
1921 sdlt
= hppa_info
->dlt_sec
;
1922 sopd
= hppa_info
->opd_sec
;
1923 spltrel
= hppa_info
->plt_rel_sec
;
1924 sdltrel
= hppa_info
->dlt_rel_sec
;
1926 /* Incredible. It is actually necessary to NOT use the symbol's real
1927 value when building the dynamic symbol table for a shared library.
1928 At least for symbols that refer to functions.
1930 We will store a new value and section index into the symbol long
1931 enough to output it into the dynamic symbol table, then we restore
1932 the original values (in elf64_hppa_link_output_symbol_hook). */
1933 if (dyn_h
&& dyn_h
->want_opd
)
1935 BFD_ASSERT (sopd
!= NULL
);
1937 /* Save away the original value and section index so that we
1938 can restore them later. */
1939 dyn_h
->st_value
= sym
->st_value
;
1940 dyn_h
->st_shndx
= sym
->st_shndx
;
1942 /* For the dynamic symbol table entry, we want the value to be
1943 address of this symbol's entry within the .opd section. */
1944 sym
->st_value
= (dyn_h
->opd_offset
1945 + sopd
->output_offset
1946 + sopd
->output_section
->vma
);
1947 sym
->st_shndx
= _bfd_elf_section_from_bfd_section (output_bfd
,
1948 sopd
->output_section
);
1951 /* Initialize a .plt entry if requested. */
1952 if (dyn_h
&& dyn_h
->want_plt
1953 && elf64_hppa_dynamic_symbol_p (dyn_h
->h
, info
))
1956 Elf_Internal_Rela rel
;
1959 BFD_ASSERT (splt
!= NULL
&& spltrel
!= NULL
);
1961 /* We do not actually care about the value in the PLT entry
1962 if we are creating a shared library and the symbol is
1963 still undefined, we create a dynamic relocation to fill
1964 in the correct value. */
1965 if (info
->shared
&& h
->root
.type
== bfd_link_hash_undefined
)
1968 value
= (h
->root
.u
.def
.value
+ h
->root
.u
.def
.section
->vma
);
1970 /* Fill in the entry in the procedure linkage table.
1972 The format of a plt entry is
1975 plt_offset is the offset within the PLT section at which to
1976 install the PLT entry.
1978 We are modifying the in-memory PLT contents here, so we do not add
1979 in the output_offset of the PLT section. */
1981 bfd_put_64 (splt
->owner
, value
, splt
->contents
+ dyn_h
->plt_offset
);
1982 value
= _bfd_get_gp_value (splt
->output_section
->owner
);
1983 bfd_put_64 (splt
->owner
, value
, splt
->contents
+ dyn_h
->plt_offset
+ 0x8);
1985 /* Create a dynamic IPLT relocation for this entry.
1987 We are creating a relocation in the output file's PLT section,
1988 which is included within the DLT secton. So we do need to include
1989 the PLT's output_offset in the computation of the relocation's
1991 rel
.r_offset
= (dyn_h
->plt_offset
+ splt
->output_offset
1992 + splt
->output_section
->vma
);
1993 rel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PARISC_IPLT
);
1996 loc
= spltrel
->contents
;
1997 loc
+= spltrel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
1998 bfd_elf64_swap_reloca_out (splt
->output_section
->owner
, &rel
, loc
);
2001 /* Initialize an external call stub entry if requested. */
2002 if (dyn_h
&& dyn_h
->want_stub
2003 && elf64_hppa_dynamic_symbol_p (dyn_h
->h
, info
))
2007 unsigned int max_offset
;
2009 BFD_ASSERT (stub
!= NULL
);
2011 /* Install the generic stub template.
2013 We are modifying the contents of the stub section, so we do not
2014 need to include the stub section's output_offset here. */
2015 memcpy (stub
->contents
+ dyn_h
->stub_offset
, plt_stub
, sizeof (plt_stub
));
2017 /* Fix up the first ldd instruction.
2019 We are modifying the contents of the STUB section in memory,
2020 so we do not need to include its output offset in this computation.
2022 Note the plt_offset value is the value of the PLT entry relative to
2023 the start of the PLT section. These instructions will reference
2024 data relative to the value of __gp, which may not necessarily have
2025 the same address as the start of the PLT section.
2027 gp_offset contains the offset of __gp within the PLT section. */
2028 value
= dyn_h
->plt_offset
- hppa_info
->gp_offset
;
2030 insn
= bfd_get_32 (stub
->owner
, stub
->contents
+ dyn_h
->stub_offset
);
2031 if (output_bfd
->arch_info
->mach
>= 25)
2033 /* Wide mode allows 16 bit offsets. */
2036 insn
|= re_assemble_16 ((int) value
);
2042 insn
|= re_assemble_14 ((int) value
);
2045 if ((value
& 7) || value
+ max_offset
>= 2*max_offset
- 8)
2047 (*_bfd_error_handler
) (_("stub entry for %s cannot load .plt, dp offset = %ld"),
2053 bfd_put_32 (stub
->owner
, (bfd_vma
) insn
,
2054 stub
->contents
+ dyn_h
->stub_offset
);
2056 /* Fix up the second ldd instruction. */
2058 insn
= bfd_get_32 (stub
->owner
, stub
->contents
+ dyn_h
->stub_offset
+ 8);
2059 if (output_bfd
->arch_info
->mach
>= 25)
2062 insn
|= re_assemble_16 ((int) value
);
2067 insn
|= re_assemble_14 ((int) value
);
2069 bfd_put_32 (stub
->owner
, (bfd_vma
) insn
,
2070 stub
->contents
+ dyn_h
->stub_offset
+ 8);
2076 /* The .opd section contains FPTRs for each function this file
2077 exports. Initialize the FPTR entries. */
2080 elf64_hppa_finalize_opd (struct elf64_hppa_dyn_hash_entry
*dyn_h
,
2083 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
2084 struct elf64_hppa_link_hash_table
*hppa_info
;
2085 struct elf_link_hash_entry
*h
= dyn_h
? dyn_h
->h
: NULL
;
2089 hppa_info
= elf64_hppa_hash_table (info
);
2090 sopd
= hppa_info
->opd_sec
;
2091 sopdrel
= hppa_info
->opd_rel_sec
;
2093 if (h
&& dyn_h
->want_opd
)
2097 /* The first two words of an .opd entry are zero.
2099 We are modifying the contents of the OPD section in memory, so we
2100 do not need to include its output offset in this computation. */
2101 memset (sopd
->contents
+ dyn_h
->opd_offset
, 0, 16);
2103 value
= (h
->root
.u
.def
.value
2104 + h
->root
.u
.def
.section
->output_section
->vma
2105 + h
->root
.u
.def
.section
->output_offset
);
2107 /* The next word is the address of the function. */
2108 bfd_put_64 (sopd
->owner
, value
, sopd
->contents
+ dyn_h
->opd_offset
+ 16);
2110 /* The last word is our local __gp value. */
2111 value
= _bfd_get_gp_value (sopd
->output_section
->owner
);
2112 bfd_put_64 (sopd
->owner
, value
, sopd
->contents
+ dyn_h
->opd_offset
+ 24);
2115 /* If we are generating a shared library, we must generate EPLT relocations
2116 for each entry in the .opd, even for static functions (they may have
2117 had their address taken). */
2118 if (info
->shared
&& dyn_h
&& dyn_h
->want_opd
)
2120 Elf_Internal_Rela rel
;
2124 /* We may need to do a relocation against a local symbol, in
2125 which case we have to look up it's dynamic symbol index off
2126 the local symbol hash table. */
2127 if (h
&& h
->dynindx
!= -1)
2128 dynindx
= h
->dynindx
;
2131 = _bfd_elf_link_lookup_local_dynindx (info
, dyn_h
->owner
,
2134 /* The offset of this relocation is the absolute address of the
2135 .opd entry for this symbol. */
2136 rel
.r_offset
= (dyn_h
->opd_offset
+ sopd
->output_offset
2137 + sopd
->output_section
->vma
);
2139 /* If H is non-null, then we have an external symbol.
2141 It is imperative that we use a different dynamic symbol for the
2142 EPLT relocation if the symbol has global scope.
2144 In the dynamic symbol table, the function symbol will have a value
2145 which is address of the function's .opd entry.
2147 Thus, we can not use that dynamic symbol for the EPLT relocation
2148 (if we did, the data in the .opd would reference itself rather
2149 than the actual address of the function). Instead we have to use
2150 a new dynamic symbol which has the same value as the original global
2153 We prefix the original symbol with a "." and use the new symbol in
2154 the EPLT relocation. This new symbol has already been recorded in
2155 the symbol table, we just have to look it up and use it.
2157 We do not have such problems with static functions because we do
2158 not make their addresses in the dynamic symbol table point to
2159 the .opd entry. Ultimately this should be safe since a static
2160 function can not be directly referenced outside of its shared
2163 We do have to play similar games for FPTR relocations in shared
2164 libraries, including those for static symbols. See the FPTR
2165 handling in elf64_hppa_finalize_dynreloc. */
2169 struct elf_link_hash_entry
*nh
;
2171 new_name
= alloca (strlen (h
->root
.root
.string
) + 2);
2173 strcpy (new_name
+ 1, h
->root
.root
.string
);
2175 nh
= elf_link_hash_lookup (elf_hash_table (info
),
2176 new_name
, TRUE
, TRUE
, FALSE
);
2178 /* All we really want from the new symbol is its dynamic
2181 dynindx
= nh
->dynindx
;
2185 rel
.r_info
= ELF64_R_INFO (dynindx
, R_PARISC_EPLT
);
2187 loc
= sopdrel
->contents
;
2188 loc
+= sopdrel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2189 bfd_elf64_swap_reloca_out (sopd
->output_section
->owner
, &rel
, loc
);
2194 /* The .dlt section contains addresses for items referenced through the
2195 dlt. Note that we can have a DLTIND relocation for a local symbol, thus
2196 we can not depend on finish_dynamic_symbol to initialize the .dlt. */
2199 elf64_hppa_finalize_dlt (struct elf64_hppa_dyn_hash_entry
*dyn_h
,
2202 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
2203 struct elf64_hppa_link_hash_table
*hppa_info
;
2204 asection
*sdlt
, *sdltrel
;
2205 struct elf_link_hash_entry
*h
= dyn_h
? dyn_h
->h
: NULL
;
2207 hppa_info
= elf64_hppa_hash_table (info
);
2209 sdlt
= hppa_info
->dlt_sec
;
2210 sdltrel
= hppa_info
->dlt_rel_sec
;
2212 /* H/DYN_H may refer to a local variable and we know it's
2213 address, so there is no need to create a relocation. Just install
2214 the proper value into the DLT, note this shortcut can not be
2215 skipped when building a shared library. */
2216 if (! info
->shared
&& h
&& dyn_h
->want_dlt
)
2220 /* If we had an LTOFF_FPTR style relocation we want the DLT entry
2221 to point to the FPTR entry in the .opd section.
2223 We include the OPD's output offset in this computation as
2224 we are referring to an absolute address in the resulting
2226 if (dyn_h
->want_opd
)
2228 value
= (dyn_h
->opd_offset
2229 + hppa_info
->opd_sec
->output_offset
2230 + hppa_info
->opd_sec
->output_section
->vma
);
2232 else if ((h
->root
.type
== bfd_link_hash_defined
2233 || h
->root
.type
== bfd_link_hash_defweak
)
2234 && h
->root
.u
.def
.section
)
2236 value
= h
->root
.u
.def
.value
+ h
->root
.u
.def
.section
->output_offset
;
2237 if (h
->root
.u
.def
.section
->output_section
)
2238 value
+= h
->root
.u
.def
.section
->output_section
->vma
;
2240 value
+= h
->root
.u
.def
.section
->vma
;
2243 /* We have an undefined function reference. */
2246 /* We do not need to include the output offset of the DLT section
2247 here because we are modifying the in-memory contents. */
2248 bfd_put_64 (sdlt
->owner
, value
, sdlt
->contents
+ dyn_h
->dlt_offset
);
2251 /* Create a relocation for the DLT entry associated with this symbol.
2252 When building a shared library the symbol does not have to be dynamic. */
2254 && (elf64_hppa_dynamic_symbol_p (dyn_h
->h
, info
) || info
->shared
))
2256 Elf_Internal_Rela rel
;
2260 /* We may need to do a relocation against a local symbol, in
2261 which case we have to look up it's dynamic symbol index off
2262 the local symbol hash table. */
2263 if (h
&& h
->dynindx
!= -1)
2264 dynindx
= h
->dynindx
;
2267 = _bfd_elf_link_lookup_local_dynindx (info
, dyn_h
->owner
,
2270 /* Create a dynamic relocation for this entry. Do include the output
2271 offset of the DLT entry since we need an absolute address in the
2272 resulting object file. */
2273 rel
.r_offset
= (dyn_h
->dlt_offset
+ sdlt
->output_offset
2274 + sdlt
->output_section
->vma
);
2275 if (h
&& h
->type
== STT_FUNC
)
2276 rel
.r_info
= ELF64_R_INFO (dynindx
, R_PARISC_FPTR64
);
2278 rel
.r_info
= ELF64_R_INFO (dynindx
, R_PARISC_DIR64
);
2281 loc
= sdltrel
->contents
;
2282 loc
+= sdltrel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
2283 bfd_elf64_swap_reloca_out (sdlt
->output_section
->owner
, &rel
, loc
);
2288 /* Finalize the dynamic relocations. Specifically the FPTR relocations
2289 for dynamic functions used to initialize static data. */
2292 elf64_hppa_finalize_dynreloc (struct elf64_hppa_dyn_hash_entry
*dyn_h
,
2295 struct bfd_link_info
*info
= (struct bfd_link_info
*)data
;
2296 struct elf64_hppa_link_hash_table
*hppa_info
;
2297 struct elf_link_hash_entry
*h
;
2300 dynamic_symbol
= elf64_hppa_dynamic_symbol_p (dyn_h
->h
, info
);
2302 if (!dynamic_symbol
&& !info
->shared
)
2305 if (dyn_h
->reloc_entries
)
2307 struct elf64_hppa_dyn_reloc_entry
*rent
;
2310 hppa_info
= elf64_hppa_hash_table (info
);
2313 /* We may need to do a relocation against a local symbol, in
2314 which case we have to look up it's dynamic symbol index off
2315 the local symbol hash table. */
2316 if (h
&& h
->dynindx
!= -1)
2317 dynindx
= h
->dynindx
;
2320 = _bfd_elf_link_lookup_local_dynindx (info
, dyn_h
->owner
,
2323 for (rent
= dyn_h
->reloc_entries
; rent
; rent
= rent
->next
)
2325 Elf_Internal_Rela rel
;
2328 /* Allocate one iff we are building a shared library, the relocation
2329 isn't a R_PARISC_FPTR64, or we don't want an opd entry. */
2330 if (!info
->shared
&& rent
->type
== R_PARISC_FPTR64
&& dyn_h
->want_opd
)
2333 /* Create a dynamic relocation for this entry.
2335 We need the output offset for the reloc's section because
2336 we are creating an absolute address in the resulting object
2338 rel
.r_offset
= (rent
->offset
+ rent
->sec
->output_offset
2339 + rent
->sec
->output_section
->vma
);
2341 /* An FPTR64 relocation implies that we took the address of
2342 a function and that the function has an entry in the .opd
2343 section. We want the FPTR64 relocation to reference the
2346 We could munge the symbol value in the dynamic symbol table
2347 (in fact we already do for functions with global scope) to point
2348 to the .opd entry. Then we could use that dynamic symbol in
2351 Or we could do something sensible, not munge the symbol's
2352 address and instead just use a different symbol to reference
2353 the .opd entry. At least that seems sensible until you
2354 realize there's no local dynamic symbols we can use for that
2355 purpose. Thus the hair in the check_relocs routine.
2357 We use a section symbol recorded by check_relocs as the
2358 base symbol for the relocation. The addend is the difference
2359 between the section symbol and the address of the .opd entry. */
2360 if (info
->shared
&& rent
->type
== R_PARISC_FPTR64
&& dyn_h
->want_opd
)
2362 bfd_vma value
, value2
;
2364 /* First compute the address of the opd entry for this symbol. */
2365 value
= (dyn_h
->opd_offset
2366 + hppa_info
->opd_sec
->output_section
->vma
2367 + hppa_info
->opd_sec
->output_offset
);
2369 /* Compute the value of the start of the section with
2371 value2
= (rent
->sec
->output_section
->vma
2372 + rent
->sec
->output_offset
);
2374 /* Compute the difference between the start of the section
2375 with the relocation and the opd entry. */
2378 /* The result becomes the addend of the relocation. */
2379 rel
.r_addend
= value
;
2381 /* The section symbol becomes the symbol for the dynamic
2384 = _bfd_elf_link_lookup_local_dynindx (info
,
2389 rel
.r_addend
= rent
->addend
;
2391 rel
.r_info
= ELF64_R_INFO (dynindx
, rent
->type
);
2393 loc
= hppa_info
->other_rel_sec
->contents
;
2394 loc
+= (hppa_info
->other_rel_sec
->reloc_count
++
2395 * sizeof (Elf64_External_Rela
));
2396 bfd_elf64_swap_reloca_out (hppa_info
->other_rel_sec
->output_section
->owner
,
2404 /* Used to decide how to sort relocs in an optimal manner for the
2405 dynamic linker, before writing them out. */
2407 static enum elf_reloc_type_class
2408 elf64_hppa_reloc_type_class (const Elf_Internal_Rela
*rela
)
2410 if (ELF64_R_SYM (rela
->r_info
) == 0)
2411 return reloc_class_relative
;
2413 switch ((int) ELF64_R_TYPE (rela
->r_info
))
2416 return reloc_class_plt
;
2418 return reloc_class_copy
;
2420 return reloc_class_normal
;
2424 /* Finish up the dynamic sections. */
2427 elf64_hppa_finish_dynamic_sections (bfd
*output_bfd
,
2428 struct bfd_link_info
*info
)
2432 struct elf64_hppa_link_hash_table
*hppa_info
;
2434 hppa_info
= elf64_hppa_hash_table (info
);
2436 /* Finalize the contents of the .opd section. */
2437 elf64_hppa_dyn_hash_traverse (&hppa_info
->dyn_hash_table
,
2438 elf64_hppa_finalize_opd
,
2441 elf64_hppa_dyn_hash_traverse (&hppa_info
->dyn_hash_table
,
2442 elf64_hppa_finalize_dynreloc
,
2445 /* Finalize the contents of the .dlt section. */
2446 dynobj
= elf_hash_table (info
)->dynobj
;
2447 /* Finalize the contents of the .dlt section. */
2448 elf64_hppa_dyn_hash_traverse (&hppa_info
->dyn_hash_table
,
2449 elf64_hppa_finalize_dlt
,
2452 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2454 if (elf_hash_table (info
)->dynamic_sections_created
)
2456 Elf64_External_Dyn
*dyncon
, *dynconend
;
2458 BFD_ASSERT (sdyn
!= NULL
);
2460 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
2461 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
2462 for (; dyncon
< dynconend
; dyncon
++)
2464 Elf_Internal_Dyn dyn
;
2467 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2474 case DT_HP_LOAD_MAP
:
2475 /* Compute the absolute address of 16byte scratchpad area
2476 for the dynamic linker.
2478 By convention the linker script will allocate the scratchpad
2479 area at the start of the .data section. So all we have to
2480 to is find the start of the .data section. */
2481 s
= bfd_get_section_by_name (output_bfd
, ".data");
2482 dyn
.d_un
.d_ptr
= s
->vma
;
2483 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2487 /* HP's use PLTGOT to set the GOT register. */
2488 dyn
.d_un
.d_ptr
= _bfd_get_gp_value (output_bfd
);
2489 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2493 s
= hppa_info
->plt_rel_sec
;
2494 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
2495 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2499 s
= hppa_info
->plt_rel_sec
;
2500 dyn
.d_un
.d_val
= s
->size
;
2501 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2505 s
= hppa_info
->other_rel_sec
;
2506 if (! s
|| ! s
->size
)
2507 s
= hppa_info
->dlt_rel_sec
;
2508 if (! s
|| ! s
->size
)
2509 s
= hppa_info
->opd_rel_sec
;
2510 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
2511 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2515 s
= hppa_info
->other_rel_sec
;
2516 dyn
.d_un
.d_val
= s
->size
;
2517 s
= hppa_info
->dlt_rel_sec
;
2518 dyn
.d_un
.d_val
+= s
->size
;
2519 s
= hppa_info
->opd_rel_sec
;
2520 dyn
.d_un
.d_val
+= s
->size
;
2521 /* There is some question about whether or not the size of
2522 the PLT relocs should be included here. HP's tools do
2523 it, so we'll emulate them. */
2524 s
= hppa_info
->plt_rel_sec
;
2525 dyn
.d_un
.d_val
+= s
->size
;
2526 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2536 /* Support for core dump NOTE sections. */
2539 elf64_hppa_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
2544 switch (note
->descsz
)
2549 case 760: /* Linux/hppa */
2551 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
2554 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
2563 /* Make a ".reg/999" section. */
2564 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
2565 size
, note
->descpos
+ offset
);
2569 elf64_hppa_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
2574 switch (note
->descsz
)
2579 case 136: /* Linux/hppa elf_prpsinfo. */
2580 elf_tdata (abfd
)->core_program
2581 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
2582 elf_tdata (abfd
)->core_command
2583 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
2586 /* Note that for some reason, a spurious space is tacked
2587 onto the end of the args in some (at least one anyway)
2588 implementations, so strip it off if it exists. */
2589 command
= elf_tdata (abfd
)->core_command
;
2590 n
= strlen (command
);
2592 if (0 < n
&& command
[n
- 1] == ' ')
2593 command
[n
- 1] = '\0';
2598 /* Return the number of additional phdrs we will need.
2600 The generic ELF code only creates PT_PHDRs for executables. The HP
2601 dynamic linker requires PT_PHDRs for dynamic libraries too.
2603 This routine indicates that the backend needs one additional program
2604 header for that case.
2606 Note we do not have access to the link info structure here, so we have
2607 to guess whether or not we are building a shared library based on the
2608 existence of a .interp section. */
2611 elf64_hppa_additional_program_headers (bfd
*abfd
,
2612 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2616 /* If we are creating a shared library, then we have to create a
2617 PT_PHDR segment. HP's dynamic linker chokes without it. */
2618 s
= bfd_get_section_by_name (abfd
, ".interp");
2624 /* Allocate and initialize any program headers required by this
2627 The generic ELF code only creates PT_PHDRs for executables. The HP
2628 dynamic linker requires PT_PHDRs for dynamic libraries too.
2630 This allocates the PT_PHDR and initializes it in a manner suitable
2633 Note we do not have access to the link info structure here, so we have
2634 to guess whether or not we are building a shared library based on the
2635 existence of a .interp section. */
2638 elf64_hppa_modify_segment_map (bfd
*abfd
,
2639 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2641 struct elf_segment_map
*m
;
2644 s
= bfd_get_section_by_name (abfd
, ".interp");
2647 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2648 if (m
->p_type
== PT_PHDR
)
2652 m
= ((struct elf_segment_map
*)
2653 bfd_zalloc (abfd
, (bfd_size_type
) sizeof *m
));
2657 m
->p_type
= PT_PHDR
;
2658 m
->p_flags
= PF_R
| PF_X
;
2659 m
->p_flags_valid
= 1;
2660 m
->p_paddr_valid
= 1;
2661 m
->includes_phdrs
= 1;
2663 m
->next
= elf_tdata (abfd
)->segment_map
;
2664 elf_tdata (abfd
)->segment_map
= m
;
2668 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
2669 if (m
->p_type
== PT_LOAD
)
2673 for (i
= 0; i
< m
->count
; i
++)
2675 /* The code "hint" is not really a hint. It is a requirement
2676 for certain versions of the HP dynamic linker. Worse yet,
2677 it must be set even if the shared library does not have
2678 any code in its "text" segment (thus the check for .hash
2679 to catch this situation). */
2680 if (m
->sections
[i
]->flags
& SEC_CODE
2681 || (strcmp (m
->sections
[i
]->name
, ".hash") == 0))
2682 m
->p_flags
|= (PF_X
| PF_HP_CODE
);
2689 /* Called when writing out an object file to decide the type of a
2692 elf64_hppa_elf_get_symbol_type (Elf_Internal_Sym
*elf_sym
,
2695 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_PARISC_MILLI
)
2696 return STT_PARISC_MILLI
;
2701 /* Support HP specific sections for core files. */
2703 elf64_hppa_section_from_phdr (bfd
*abfd
, Elf_Internal_Phdr
*hdr
, int index
,
2704 const char *typename
)
2706 if (hdr
->p_type
== PT_HP_CORE_KERNEL
)
2710 if (!_bfd_elf_make_section_from_phdr (abfd
, hdr
, index
, typename
))
2713 sect
= bfd_make_section_anyway (abfd
, ".kernel");
2716 sect
->size
= hdr
->p_filesz
;
2717 sect
->filepos
= hdr
->p_offset
;
2718 sect
->flags
= SEC_HAS_CONTENTS
| SEC_READONLY
;
2722 if (hdr
->p_type
== PT_HP_CORE_PROC
)
2726 if (bfd_seek (abfd
, hdr
->p_offset
, SEEK_SET
) != 0)
2728 if (bfd_bread (&sig
, 4, abfd
) != 4)
2731 elf_tdata (abfd
)->core_signal
= sig
;
2733 if (!_bfd_elf_make_section_from_phdr (abfd
, hdr
, index
, typename
))
2736 /* GDB uses the ".reg" section to read register contents. */
2737 return _bfd_elfcore_make_pseudosection (abfd
, ".reg", hdr
->p_filesz
,
2741 if (hdr
->p_type
== PT_HP_CORE_LOADABLE
2742 || hdr
->p_type
== PT_HP_CORE_STACK
2743 || hdr
->p_type
== PT_HP_CORE_MMF
)
2744 hdr
->p_type
= PT_LOAD
;
2746 return _bfd_elf_make_section_from_phdr (abfd
, hdr
, index
, typename
);
2749 static const struct bfd_elf_special_section elf64_hppa_special_sections
[] =
2751 { STRING_COMMA_LEN (".fini"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2752 { STRING_COMMA_LEN (".init"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2753 { STRING_COMMA_LEN (".plt"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
2754 { STRING_COMMA_LEN (".dlt"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
2755 { STRING_COMMA_LEN (".sdata"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
2756 { STRING_COMMA_LEN (".sbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_PARISC_SHORT
},
2757 { STRING_COMMA_LEN (".tbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_HP_TLS
},
2758 { NULL
, 0, 0, 0, 0 }
2761 /* The hash bucket size is the standard one, namely 4. */
2763 const struct elf_size_info hppa64_elf_size_info
=
2765 sizeof (Elf64_External_Ehdr
),
2766 sizeof (Elf64_External_Phdr
),
2767 sizeof (Elf64_External_Shdr
),
2768 sizeof (Elf64_External_Rel
),
2769 sizeof (Elf64_External_Rela
),
2770 sizeof (Elf64_External_Sym
),
2771 sizeof (Elf64_External_Dyn
),
2772 sizeof (Elf_External_Note
),
2776 ELFCLASS64
, EV_CURRENT
,
2777 bfd_elf64_write_out_phdrs
,
2778 bfd_elf64_write_shdrs_and_ehdr
,
2779 bfd_elf64_checksum_contents
,
2780 bfd_elf64_write_relocs
,
2781 bfd_elf64_swap_symbol_in
,
2782 bfd_elf64_swap_symbol_out
,
2783 bfd_elf64_slurp_reloc_table
,
2784 bfd_elf64_slurp_symbol_table
,
2785 bfd_elf64_swap_dyn_in
,
2786 bfd_elf64_swap_dyn_out
,
2787 bfd_elf64_swap_reloc_in
,
2788 bfd_elf64_swap_reloc_out
,
2789 bfd_elf64_swap_reloca_in
,
2790 bfd_elf64_swap_reloca_out
2793 #define TARGET_BIG_SYM bfd_elf64_hppa_vec
2794 #define TARGET_BIG_NAME "elf64-hppa"
2795 #define ELF_ARCH bfd_arch_hppa
2796 #define ELF_MACHINE_CODE EM_PARISC
2797 /* This is not strictly correct. The maximum page size for PA2.0 is
2798 64M. But everything still uses 4k. */
2799 #define ELF_MAXPAGESIZE 0x1000
2800 #define ELF_OSABI ELFOSABI_HPUX
2802 #define bfd_elf64_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
2803 #define bfd_elf64_bfd_reloc_name_lookup elf_hppa_reloc_name_lookup
2804 #define bfd_elf64_bfd_is_local_label_name elf_hppa_is_local_label_name
2805 #define elf_info_to_howto elf_hppa_info_to_howto
2806 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
2808 #define elf_backend_section_from_shdr elf64_hppa_section_from_shdr
2809 #define elf_backend_object_p elf64_hppa_object_p
2810 #define elf_backend_final_write_processing \
2811 elf_hppa_final_write_processing
2812 #define elf_backend_fake_sections elf_hppa_fake_sections
2813 #define elf_backend_add_symbol_hook elf_hppa_add_symbol_hook
2815 #define elf_backend_relocate_section elf_hppa_relocate_section
2817 #define bfd_elf64_bfd_final_link elf_hppa_final_link
2819 #define elf_backend_create_dynamic_sections \
2820 elf64_hppa_create_dynamic_sections
2821 #define elf_backend_post_process_headers elf64_hppa_post_process_headers
2823 #define elf_backend_omit_section_dynsym \
2824 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
2825 #define elf_backend_adjust_dynamic_symbol \
2826 elf64_hppa_adjust_dynamic_symbol
2828 #define elf_backend_size_dynamic_sections \
2829 elf64_hppa_size_dynamic_sections
2831 #define elf_backend_finish_dynamic_symbol \
2832 elf64_hppa_finish_dynamic_symbol
2833 #define elf_backend_finish_dynamic_sections \
2834 elf64_hppa_finish_dynamic_sections
2835 #define elf_backend_grok_prstatus elf64_hppa_grok_prstatus
2836 #define elf_backend_grok_psinfo elf64_hppa_grok_psinfo
2838 /* Stuff for the BFD linker: */
2839 #define bfd_elf64_bfd_link_hash_table_create \
2840 elf64_hppa_hash_table_create
2842 #define elf_backend_check_relocs \
2843 elf64_hppa_check_relocs
2845 #define elf_backend_size_info \
2846 hppa64_elf_size_info
2848 #define elf_backend_additional_program_headers \
2849 elf64_hppa_additional_program_headers
2851 #define elf_backend_modify_segment_map \
2852 elf64_hppa_modify_segment_map
2854 #define elf_backend_link_output_symbol_hook \
2855 elf64_hppa_link_output_symbol_hook
2857 #define elf_backend_want_got_plt 0
2858 #define elf_backend_plt_readonly 0
2859 #define elf_backend_want_plt_sym 0
2860 #define elf_backend_got_header_size 0
2861 #define elf_backend_type_change_ok TRUE
2862 #define elf_backend_get_symbol_type elf64_hppa_elf_get_symbol_type
2863 #define elf_backend_reloc_type_class elf64_hppa_reloc_type_class
2864 #define elf_backend_rela_normal 1
2865 #define elf_backend_special_sections elf64_hppa_special_sections
2866 #define elf_backend_action_discarded elf_hppa_action_discarded
2867 #define elf_backend_section_from_phdr elf64_hppa_section_from_phdr
2869 #define elf64_bed elf64_hppa_hpux_bed
2871 #include "elf64-target.h"
2873 #undef TARGET_BIG_SYM
2874 #define TARGET_BIG_SYM bfd_elf64_hppa_linux_vec
2875 #undef TARGET_BIG_NAME
2876 #define TARGET_BIG_NAME "elf64-hppa-linux"
2878 #define ELF_OSABI ELFOSABI_LINUX
2879 #undef elf_backend_post_process_headers
2880 #define elf_backend_post_process_headers _bfd_elf_set_osabi
2882 #define elf64_bed elf64_hppa_linux_bed
2884 #include "elf64-target.h"