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. */
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 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
187 static struct bfd_hash_entry *elf64_hppa_new_dyn_hash_entry
188 PARAMS ((struct bfd_hash_entry *entry, struct bfd_hash_table *table,
189 const char *string));
190 static struct bfd_link_hash_table *elf64_hppa_hash_table_create
191 PARAMS ((bfd *abfd));
192 static struct elf64_hppa_dyn_hash_entry *elf64_hppa_dyn_hash_lookup
193 PARAMS ((struct elf64_hppa_dyn_hash_table *table, const char *string,
194 bfd_boolean create, bfd_boolean copy));
195 static void elf64_hppa_dyn_hash_traverse
196 PARAMS ((struct elf64_hppa_dyn_hash_table *table,
197 bfd_boolean (*func) (struct elf64_hppa_dyn_hash_entry *, PTR),
200 static const char *get_dyn_name
201 PARAMS ((bfd *, struct elf_link_hash_entry *,
202 const Elf_Internal_Rela *, char **, size_t *));
204 /* This must follow the definitions of the various derived linker
205 hash tables and shared functions. */
206 #include "elf-hppa.h"
208 static bfd_boolean elf64_hppa_object_p
211 static void elf64_hppa_post_process_headers
212 PARAMS ((bfd *, struct bfd_link_info *));
214 static bfd_boolean elf64_hppa_create_dynamic_sections
215 PARAMS ((bfd *, struct bfd_link_info *));
217 static bfd_boolean elf64_hppa_adjust_dynamic_symbol
218 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
220 static bfd_boolean elf64_hppa_mark_milli_and_exported_functions
221 PARAMS ((struct elf_link_hash_entry *, PTR));
223 static bfd_boolean elf64_hppa_size_dynamic_sections
224 PARAMS ((bfd *, struct bfd_link_info *));
226 static bfd_boolean elf64_hppa_link_output_symbol_hook
227 PARAMS ((struct bfd_link_info *, const char *, Elf_Internal_Sym *,
228 asection *, struct elf_link_hash_entry *));
230 static bfd_boolean elf64_hppa_finish_dynamic_symbol
231 PARAMS ((bfd *, struct bfd_link_info *,
232 struct elf_link_hash_entry *, Elf_Internal_Sym *));
234 static enum elf_reloc_type_class elf64_hppa_reloc_type_class
235 PARAMS ((const Elf_Internal_Rela *));
237 static bfd_boolean elf64_hppa_finish_dynamic_sections
238 PARAMS ((bfd *, struct bfd_link_info *));
240 static bfd_boolean elf64_hppa_check_relocs
241 PARAMS ((bfd *, struct bfd_link_info *,
242 asection *, const Elf_Internal_Rela *));
244 static bfd_boolean elf64_hppa_dynamic_symbol_p
245 PARAMS ((struct elf_link_hash_entry *, struct bfd_link_info *));
247 static bfd_boolean elf64_hppa_mark_exported_functions
248 PARAMS ((struct elf_link_hash_entry *, PTR));
250 static bfd_boolean elf64_hppa_finalize_opd
251 PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
253 static bfd_boolean elf64_hppa_finalize_dlt
254 PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
256 static bfd_boolean allocate_global_data_dlt
257 PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
259 static bfd_boolean allocate_global_data_plt
260 PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
262 static bfd_boolean allocate_global_data_stub
263 PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
265 static bfd_boolean allocate_global_data_opd
266 PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
268 static bfd_boolean get_reloc_section
269 PARAMS ((bfd *, struct elf64_hppa_link_hash_table *, asection *));
271 static bfd_boolean count_dyn_reloc
272 PARAMS ((bfd *, struct elf64_hppa_dyn_hash_entry *,
273 int, asection *, int, bfd_vma, bfd_vma));
275 static bfd_boolean allocate_dynrel_entries
276 PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
278 static bfd_boolean elf64_hppa_finalize_dynreloc
279 PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
281 static bfd_boolean get_opd
282 PARAMS ((bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *));
284 static bfd_boolean get_plt
285 PARAMS ((bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *));
287 static bfd_boolean get_dlt
288 PARAMS ((bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *));
290 static bfd_boolean get_stub
291 PARAMS ((bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *));
293 static int elf64_hppa_elf_get_symbol_type
294 PARAMS ((Elf_Internal_Sym *, int));
297 elf64_hppa_dyn_hash_table_init (struct elf64_hppa_dyn_hash_table *ht,
298 bfd *abfd ATTRIBUTE_UNUSED,
299 new_hash_entry_func new,
300 unsigned int entsize)
302 memset (ht, 0, sizeof (*ht));
303 return bfd_hash_table_init (&ht->root, new, entsize);
306 static struct bfd_hash_entry*
307 elf64_hppa_new_dyn_hash_entry (entry, table, string)
308 struct bfd_hash_entry *entry;
309 struct bfd_hash_table *table;
312 struct elf64_hppa_dyn_hash_entry *ret;
313 ret = (struct elf64_hppa_dyn_hash_entry *) entry;
315 /* Allocate the structure if it has not already been allocated by a
318 ret = bfd_hash_allocate (table, sizeof (*ret));
323 /* Call the allocation method of the superclass. */
324 ret = ((struct elf64_hppa_dyn_hash_entry *)
325 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
327 /* Initialize our local data. All zeros. */
328 memset (&ret->dlt_offset, 0,
329 (sizeof (struct elf64_hppa_dyn_hash_entry)
330 - offsetof (struct elf64_hppa_dyn_hash_entry, dlt_offset)));
335 /* Create the derived linker hash table. The PA64 ELF port uses this
336 derived hash table to keep information specific to the PA ElF
337 linker (without using static variables). */
339 static struct bfd_link_hash_table*
340 elf64_hppa_hash_table_create (abfd)
343 struct elf64_hppa_link_hash_table *ret;
345 ret = bfd_zalloc (abfd, (bfd_size_type) sizeof (*ret));
348 if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
349 _bfd_elf_link_hash_newfunc,
350 sizeof (struct elf_link_hash_entry)))
352 bfd_release (abfd, ret);
356 if (!elf64_hppa_dyn_hash_table_init (&ret->dyn_hash_table, abfd,
357 elf64_hppa_new_dyn_hash_entry,
358 sizeof (struct elf64_hppa_dyn_hash_entry)))
360 return &ret->root.root;
363 /* Look up an entry in a PA64 ELF linker hash table. */
365 static struct elf64_hppa_dyn_hash_entry *
366 elf64_hppa_dyn_hash_lookup(table, string, create, copy)
367 struct elf64_hppa_dyn_hash_table *table;
369 bfd_boolean create, copy;
371 return ((struct elf64_hppa_dyn_hash_entry *)
372 bfd_hash_lookup (&table->root, string, create, copy));
375 /* Traverse a PA64 ELF linker hash table. */
378 elf64_hppa_dyn_hash_traverse (table, func, info)
379 struct elf64_hppa_dyn_hash_table *table;
380 bfd_boolean (*func) PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
385 (bfd_boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) func,
389 /* Return nonzero if ABFD represents a PA2.0 ELF64 file.
391 Additionally we set the default architecture and machine. */
393 elf64_hppa_object_p (abfd)
396 Elf_Internal_Ehdr * i_ehdrp;
399 i_ehdrp = elf_elfheader (abfd);
400 if (strcmp (bfd_get_target (abfd), "elf64-hppa-linux") == 0)
402 /* GCC on hppa-linux produces binaries with OSABI=Linux,
403 but the kernel produces corefiles with OSABI=SysV. */
404 if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_LINUX
405 && i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_NONE) /* aka SYSV */
410 /* HPUX produces binaries with OSABI=HPUX,
411 but the kernel produces corefiles with OSABI=SysV. */
412 if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_HPUX
413 && i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_NONE) /* aka SYSV */
417 flags = i_ehdrp->e_flags;
418 switch (flags & (EF_PARISC_ARCH | EF_PARISC_WIDE))
421 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 10);
423 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 11);
425 if (i_ehdrp->e_ident[EI_CLASS] == ELFCLASS64)
426 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 25);
428 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 20);
429 case EFA_PARISC_2_0 | EF_PARISC_WIDE:
430 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 25);
432 /* Don't be fussy. */
436 /* Given section type (hdr->sh_type), return a boolean indicating
437 whether or not the section is an elf64-hppa specific section. */
439 elf64_hppa_section_from_shdr (bfd *abfd,
440 Elf_Internal_Shdr *hdr,
446 switch (hdr->sh_type)
449 if (strcmp (name, ".PARISC.archext") != 0)
452 case SHT_PARISC_UNWIND:
453 if (strcmp (name, ".PARISC.unwind") != 0)
457 case SHT_PARISC_ANNOT:
462 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
464 newsect = hdr->bfd_section;
469 /* Construct a string for use in the elf64_hppa_dyn_hash_table. The
470 name describes what was once potentially anonymous memory. We
471 allocate memory as necessary, possibly reusing PBUF/PLEN. */
474 get_dyn_name (abfd, h, rel, pbuf, plen)
476 struct elf_link_hash_entry *h;
477 const Elf_Internal_Rela *rel;
481 asection *sec = abfd->sections;
486 if (h && rel->r_addend == 0)
487 return h->root.root.string;
490 nlen = strlen (h->root.root.string);
492 nlen = 8 + 1 + sizeof (rel->r_info) * 2 - 8;
493 tlen = nlen + 1 + sizeof (rel->r_addend) * 2 + 1;
501 *pbuf = buf = malloc (tlen);
509 memcpy (buf, h->root.root.string, nlen);
511 sprintf_vma (buf + nlen, rel->r_addend);
515 nlen = sprintf (buf, "%x:%lx",
516 sec->id & 0xffffffff,
517 (long) ELF64_R_SYM (rel->r_info));
521 sprintf_vma (buf + nlen, rel->r_addend);
528 /* SEC is a section containing relocs for an input BFD when linking; return
529 a suitable section for holding relocs in the output BFD for a link. */
532 get_reloc_section (abfd, hppa_info, sec)
534 struct elf64_hppa_link_hash_table *hppa_info;
537 const char *srel_name;
541 srel_name = (bfd_elf_string_from_elf_section
542 (abfd, elf_elfheader(abfd)->e_shstrndx,
543 elf_section_data(sec)->rel_hdr.sh_name));
544 if (srel_name == NULL)
547 BFD_ASSERT ((CONST_STRNEQ (srel_name, ".rela")
548 && strcmp (bfd_get_section_name (abfd, sec),
550 || (CONST_STRNEQ (srel_name, ".rel")
551 && strcmp (bfd_get_section_name (abfd, sec),
552 srel_name + 4) == 0));
554 dynobj = hppa_info->root.dynobj;
556 hppa_info->root.dynobj = dynobj = abfd;
558 srel = bfd_get_section_by_name (dynobj, srel_name);
561 srel = bfd_make_section_with_flags (dynobj, srel_name,
569 || !bfd_set_section_alignment (dynobj, srel, 3))
573 hppa_info->other_rel_sec = srel;
577 /* Add a new entry to the list of dynamic relocations against DYN_H.
579 We use this to keep a record of all the FPTR relocations against a
580 particular symbol so that we can create FPTR relocations in the
584 count_dyn_reloc (abfd, dyn_h, type, sec, sec_symndx, offset, addend)
586 struct elf64_hppa_dyn_hash_entry *dyn_h;
593 struct elf64_hppa_dyn_reloc_entry *rent;
595 rent = (struct elf64_hppa_dyn_reloc_entry *)
596 bfd_alloc (abfd, (bfd_size_type) sizeof (*rent));
600 rent->next = dyn_h->reloc_entries;
603 rent->sec_symndx = sec_symndx;
604 rent->offset = offset;
605 rent->addend = addend;
606 dyn_h->reloc_entries = rent;
611 /* Scan the RELOCS and record the type of dynamic entries that each
612 referenced symbol needs. */
615 elf64_hppa_check_relocs (abfd, info, sec, relocs)
617 struct bfd_link_info *info;
619 const Elf_Internal_Rela *relocs;
621 struct elf64_hppa_link_hash_table *hppa_info;
622 const Elf_Internal_Rela *relend;
623 Elf_Internal_Shdr *symtab_hdr;
624 const Elf_Internal_Rela *rel;
625 asection *dlt, *plt, *stubs;
630 if (info->relocatable)
633 /* If this is the first dynamic object found in the link, create
634 the special sections required for dynamic linking. */
635 if (! elf_hash_table (info)->dynamic_sections_created)
637 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
641 hppa_info = elf64_hppa_hash_table (info);
642 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
644 /* If necessary, build a new table holding section symbols indices
647 if (info->shared && hppa_info->section_syms_bfd != abfd)
650 unsigned int highest_shndx;
651 Elf_Internal_Sym *local_syms = NULL;
652 Elf_Internal_Sym *isym, *isymend;
655 /* We're done with the old cache of section index to section symbol
656 index information. Free it.
658 ?!? Note we leak the last section_syms array. Presumably we
659 could free it in one of the later routines in this file. */
660 if (hppa_info->section_syms)
661 free (hppa_info->section_syms);
663 /* Read this BFD's local symbols. */
664 if (symtab_hdr->sh_info != 0)
666 local_syms = (Elf_Internal_Sym *) symtab_hdr->contents;
667 if (local_syms == NULL)
668 local_syms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
669 symtab_hdr->sh_info, 0,
671 if (local_syms == NULL)
675 /* Record the highest section index referenced by the local symbols. */
677 isymend = local_syms + symtab_hdr->sh_info;
678 for (isym = local_syms; isym < isymend; isym++)
680 if (isym->st_shndx > highest_shndx)
681 highest_shndx = isym->st_shndx;
684 /* Allocate an array to hold the section index to section symbol index
685 mapping. Bump by one since we start counting at zero. */
689 hppa_info->section_syms = (int *) bfd_malloc (amt);
691 /* Now walk the local symbols again. If we find a section symbol,
692 record the index of the symbol into the section_syms array. */
693 for (i = 0, isym = local_syms; isym < isymend; i++, isym++)
695 if (ELF_ST_TYPE (isym->st_info) == STT_SECTION)
696 hppa_info->section_syms[isym->st_shndx] = i;
699 /* We are finished with the local symbols. */
700 if (local_syms != NULL
701 && symtab_hdr->contents != (unsigned char *) local_syms)
703 if (! info->keep_memory)
707 /* Cache the symbols for elf_link_input_bfd. */
708 symtab_hdr->contents = (unsigned char *) local_syms;
712 /* Record which BFD we built the section_syms mapping for. */
713 hppa_info->section_syms_bfd = abfd;
716 /* Record the symbol index for this input section. We may need it for
717 relocations when building shared libraries. When not building shared
718 libraries this value is never really used, but assign it to zero to
719 prevent out of bounds memory accesses in other routines. */
722 sec_symndx = _bfd_elf_section_from_bfd_section (abfd, sec);
724 /* If we did not find a section symbol for this section, then
725 something went terribly wrong above. */
726 if (sec_symndx == -1)
729 sec_symndx = hppa_info->section_syms[sec_symndx];
734 dlt = plt = stubs = NULL;
738 relend = relocs + sec->reloc_count;
739 for (rel = relocs; rel < relend; ++rel)
750 struct elf_link_hash_entry *h = NULL;
751 unsigned long r_symndx = ELF64_R_SYM (rel->r_info);
752 struct elf64_hppa_dyn_hash_entry *dyn_h;
754 const char *addr_name;
755 bfd_boolean maybe_dynamic;
756 int dynrel_type = R_PARISC_NONE;
757 static reloc_howto_type *howto;
759 if (r_symndx >= symtab_hdr->sh_info)
761 /* We're dealing with a global symbol -- find its hash entry
762 and mark it as being referenced. */
763 long indx = r_symndx - symtab_hdr->sh_info;
764 h = elf_sym_hashes (abfd)[indx];
765 while (h->root.type == bfd_link_hash_indirect
766 || h->root.type == bfd_link_hash_warning)
767 h = (struct elf_link_hash_entry *) h->root.u.i.link;
772 /* We can only get preliminary data on whether a symbol is
773 locally or externally defined, as not all of the input files
774 have yet been processed. Do something with what we know, as
775 this may help reduce memory usage and processing time later. */
776 maybe_dynamic = FALSE;
777 if (h && ((info->shared
779 || info->unresolved_syms_in_shared_libs == RM_IGNORE))
781 || h->root.type == bfd_link_hash_defweak))
782 maybe_dynamic = TRUE;
784 howto = elf_hppa_howto_table + ELF64_R_TYPE (rel->r_info);
788 /* These are simple indirect references to symbols through the
789 DLT. We need to create a DLT entry for any symbols which
790 appears in a DLTIND relocation. */
791 case R_PARISC_DLTIND21L:
792 case R_PARISC_DLTIND14R:
793 case R_PARISC_DLTIND14F:
794 case R_PARISC_DLTIND14WR:
795 case R_PARISC_DLTIND14DR:
796 need_entry = NEED_DLT;
799 /* ?!? These need a DLT entry. But I have no idea what to do with
800 the "link time TP value. */
801 case R_PARISC_LTOFF_TP21L:
802 case R_PARISC_LTOFF_TP14R:
803 case R_PARISC_LTOFF_TP14F:
804 case R_PARISC_LTOFF_TP64:
805 case R_PARISC_LTOFF_TP14WR:
806 case R_PARISC_LTOFF_TP14DR:
807 case R_PARISC_LTOFF_TP16F:
808 case R_PARISC_LTOFF_TP16WF:
809 case R_PARISC_LTOFF_TP16DF:
810 need_entry = NEED_DLT;
813 /* These are function calls. Depending on their precise target we
814 may need to make a stub for them. The stub uses the PLT, so we
815 need to create PLT entries for these symbols too. */
816 case R_PARISC_PCREL12F:
817 case R_PARISC_PCREL17F:
818 case R_PARISC_PCREL22F:
819 case R_PARISC_PCREL32:
820 case R_PARISC_PCREL64:
821 case R_PARISC_PCREL21L:
822 case R_PARISC_PCREL17R:
823 case R_PARISC_PCREL17C:
824 case R_PARISC_PCREL14R:
825 case R_PARISC_PCREL14F:
826 case R_PARISC_PCREL22C:
827 case R_PARISC_PCREL14WR:
828 case R_PARISC_PCREL14DR:
829 case R_PARISC_PCREL16F:
830 case R_PARISC_PCREL16WF:
831 case R_PARISC_PCREL16DF:
832 need_entry = (NEED_PLT | NEED_STUB);
835 case R_PARISC_PLTOFF21L:
836 case R_PARISC_PLTOFF14R:
837 case R_PARISC_PLTOFF14F:
838 case R_PARISC_PLTOFF14WR:
839 case R_PARISC_PLTOFF14DR:
840 case R_PARISC_PLTOFF16F:
841 case R_PARISC_PLTOFF16WF:
842 case R_PARISC_PLTOFF16DF:
843 need_entry = (NEED_PLT);
847 if (info->shared || maybe_dynamic)
848 need_entry = (NEED_DYNREL);
849 dynrel_type = R_PARISC_DIR64;
852 /* This is an indirect reference through the DLT to get the address
853 of a OPD descriptor. Thus we need to make a DLT entry that points
855 case R_PARISC_LTOFF_FPTR21L:
856 case R_PARISC_LTOFF_FPTR14R:
857 case R_PARISC_LTOFF_FPTR14WR:
858 case R_PARISC_LTOFF_FPTR14DR:
859 case R_PARISC_LTOFF_FPTR32:
860 case R_PARISC_LTOFF_FPTR64:
861 case R_PARISC_LTOFF_FPTR16F:
862 case R_PARISC_LTOFF_FPTR16WF:
863 case R_PARISC_LTOFF_FPTR16DF:
864 if (info->shared || maybe_dynamic)
865 need_entry = (NEED_DLT | NEED_OPD);
867 need_entry = (NEED_DLT | NEED_OPD);
868 dynrel_type = R_PARISC_FPTR64;
871 /* This is a simple OPD entry. */
872 case R_PARISC_FPTR64:
873 if (info->shared || maybe_dynamic)
874 need_entry = (NEED_OPD | NEED_DYNREL);
876 need_entry = (NEED_OPD);
877 dynrel_type = R_PARISC_FPTR64;
880 /* Add more cases as needed. */
886 /* Collect a canonical name for this address. */
887 addr_name = get_dyn_name (abfd, h, rel, &buf, &buf_len);
889 /* Collect the canonical entry data for this address. */
890 dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table,
891 addr_name, TRUE, TRUE);
894 /* Stash away enough information to be able to find this symbol
895 regardless of whether or not it is local or global. */
898 dyn_h->sym_indx = r_symndx;
900 /* ?!? We may need to do some error checking in here. */
901 /* Create what's needed. */
902 if (need_entry & NEED_DLT)
904 if (! hppa_info->dlt_sec
905 && ! get_dlt (abfd, info, hppa_info))
910 if (need_entry & NEED_PLT)
912 if (! hppa_info->plt_sec
913 && ! get_plt (abfd, info, hppa_info))
918 if (need_entry & NEED_STUB)
920 if (! hppa_info->stub_sec
921 && ! get_stub (abfd, info, hppa_info))
923 dyn_h->want_stub = 1;
926 if (need_entry & NEED_OPD)
928 if (! hppa_info->opd_sec
929 && ! get_opd (abfd, info, hppa_info))
934 /* FPTRs are not allocated by the dynamic linker for PA64, though
935 it is possible that will change in the future. */
937 /* This could be a local function that had its address taken, in
938 which case H will be NULL. */
943 /* Add a new dynamic relocation to the chain of dynamic
944 relocations for this symbol. */
945 if ((need_entry & NEED_DYNREL) && (sec->flags & SEC_ALLOC))
947 if (! hppa_info->other_rel_sec
948 && ! get_reloc_section (abfd, hppa_info, sec))
951 if (!count_dyn_reloc (abfd, dyn_h, dynrel_type, sec,
952 sec_symndx, rel->r_offset, rel->r_addend))
955 /* If we are building a shared library and we just recorded
956 a dynamic R_PARISC_FPTR64 relocation, then make sure the
957 section symbol for this section ends up in the dynamic
959 if (info->shared && dynrel_type == R_PARISC_FPTR64
960 && ! (bfd_elf_link_record_local_dynamic_symbol
961 (info, abfd, sec_symndx)))
976 struct elf64_hppa_allocate_data
978 struct bfd_link_info *info;
982 /* Should we do dynamic things to this symbol? */
985 elf64_hppa_dynamic_symbol_p (h, info)
986 struct elf_link_hash_entry *h;
987 struct bfd_link_info *info;
989 /* ??? What, if anything, needs to happen wrt STV_PROTECTED symbols
990 and relocations that retrieve a function descriptor? Assume the
992 if (_bfd_elf_dynamic_symbol_p (h, info, 1))
994 /* ??? Why is this here and not elsewhere is_local_label_name. */
995 if (h->root.root.string[0] == '$' && h->root.root.string[1] == '$')
1004 /* Mark all functions exported by this file so that we can later allocate
1005 entries in .opd for them. */
1008 elf64_hppa_mark_exported_functions (h, data)
1009 struct elf_link_hash_entry *h;
1012 struct bfd_link_info *info = (struct bfd_link_info *)data;
1013 struct elf64_hppa_link_hash_table *hppa_info;
1015 hppa_info = elf64_hppa_hash_table (info);
1017 if (h->root.type == bfd_link_hash_warning)
1018 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1021 && (h->root.type == bfd_link_hash_defined
1022 || h->root.type == bfd_link_hash_defweak)
1023 && h->root.u.def.section->output_section != NULL
1024 && h->type == STT_FUNC)
1026 struct elf64_hppa_dyn_hash_entry *dyn_h;
1028 /* Add this symbol to the PA64 linker hash table. */
1029 dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table,
1030 h->root.root.string, TRUE, TRUE);
1034 if (! hppa_info->opd_sec
1035 && ! get_opd (hppa_info->root.dynobj, info, hppa_info))
1038 dyn_h->want_opd = 1;
1039 /* Put a flag here for output_symbol_hook. */
1040 dyn_h->st_shndx = -1;
1047 /* Allocate space for a DLT entry. */
1050 allocate_global_data_dlt (dyn_h, data)
1051 struct elf64_hppa_dyn_hash_entry *dyn_h;
1054 struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data;
1056 if (dyn_h->want_dlt)
1058 struct elf_link_hash_entry *h = dyn_h->h;
1060 if (x->info->shared)
1062 /* Possibly add the symbol to the local dynamic symbol
1063 table since we might need to create a dynamic relocation
1066 || (h->dynindx == -1 && h->type != STT_PARISC_MILLI))
1069 owner = (h ? h->root.u.def.section->owner : dyn_h->owner);
1071 if (! (bfd_elf_link_record_local_dynamic_symbol
1072 (x->info, owner, dyn_h->sym_indx)))
1077 dyn_h->dlt_offset = x->ofs;
1078 x->ofs += DLT_ENTRY_SIZE;
1083 /* Allocate space for a DLT.PLT entry. */
1086 allocate_global_data_plt (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;
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->plt_offset = x->ofs;
1099 x->ofs += PLT_ENTRY_SIZE;
1100 if (dyn_h->plt_offset < 0x2000)
1101 elf64_hppa_hash_table (x->info)->gp_offset = dyn_h->plt_offset;
1104 dyn_h->want_plt = 0;
1109 /* Allocate space for a STUB entry. */
1112 allocate_global_data_stub (dyn_h, data)
1113 struct elf64_hppa_dyn_hash_entry *dyn_h;
1116 struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data;
1118 if (dyn_h->want_stub
1119 && elf64_hppa_dynamic_symbol_p (dyn_h->h, x->info)
1120 && !((dyn_h->h->root.type == bfd_link_hash_defined
1121 || dyn_h->h->root.type == bfd_link_hash_defweak)
1122 && dyn_h->h->root.u.def.section->output_section != NULL))
1124 dyn_h->stub_offset = x->ofs;
1125 x->ofs += sizeof (plt_stub);
1128 dyn_h->want_stub = 0;
1132 /* Allocate space for a FPTR entry. */
1135 allocate_global_data_opd (dyn_h, data)
1136 struct elf64_hppa_dyn_hash_entry *dyn_h;
1139 struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data;
1141 if (dyn_h->want_opd)
1143 struct elf_link_hash_entry *h = dyn_h->h;
1146 while (h->root.type == bfd_link_hash_indirect
1147 || h->root.type == bfd_link_hash_warning)
1148 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1150 /* We never need an opd entry for a symbol which is not
1151 defined by this output file. */
1152 if (h && (h->root.type == bfd_link_hash_undefined
1153 || h->root.type == bfd_link_hash_undefweak
1154 || h->root.u.def.section->output_section == NULL))
1155 dyn_h->want_opd = 0;
1157 /* If we are creating a shared library, took the address of a local
1158 function or might export this function from this object file, then
1159 we have to create an opd descriptor. */
1160 else if (x->info->shared
1162 || (h->dynindx == -1 && h->type != STT_PARISC_MILLI)
1163 || (h->root.type == bfd_link_hash_defined
1164 || h->root.type == bfd_link_hash_defweak))
1166 /* If we are creating a shared library, then we will have to
1167 create a runtime relocation for the symbol to properly
1168 initialize the .opd entry. Make sure the symbol gets
1169 added to the dynamic symbol table. */
1171 && (h == NULL || (h->dynindx == -1)))
1174 owner = (h ? h->root.u.def.section->owner : dyn_h->owner);
1176 if (!bfd_elf_link_record_local_dynamic_symbol
1177 (x->info, owner, dyn_h->sym_indx))
1181 /* This may not be necessary or desirable anymore now that
1182 we have some support for dealing with section symbols
1183 in dynamic relocs. But name munging does make the result
1184 much easier to debug. ie, the EPLT reloc will reference
1185 a symbol like .foobar, instead of .text + offset. */
1186 if (x->info->shared && h)
1189 struct elf_link_hash_entry *nh;
1191 new_name = alloca (strlen (h->root.root.string) + 2);
1193 strcpy (new_name + 1, h->root.root.string);
1195 nh = elf_link_hash_lookup (elf_hash_table (x->info),
1196 new_name, TRUE, TRUE, TRUE);
1198 nh->root.type = h->root.type;
1199 nh->root.u.def.value = h->root.u.def.value;
1200 nh->root.u.def.section = h->root.u.def.section;
1202 if (! bfd_elf_link_record_dynamic_symbol (x->info, nh))
1206 dyn_h->opd_offset = x->ofs;
1207 x->ofs += OPD_ENTRY_SIZE;
1210 /* Otherwise we do not need an opd entry. */
1212 dyn_h->want_opd = 0;
1217 /* HP requires the EI_OSABI field to be filled in. The assignment to
1218 EI_ABIVERSION may not be strictly necessary. */
1221 elf64_hppa_post_process_headers (abfd, link_info)
1223 struct bfd_link_info * link_info ATTRIBUTE_UNUSED;
1225 Elf_Internal_Ehdr * i_ehdrp;
1227 i_ehdrp = elf_elfheader (abfd);
1229 i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi;
1230 i_ehdrp->e_ident[EI_ABIVERSION] = 1;
1233 /* Create function descriptor section (.opd). This section is called .opd
1234 because it contains "official procedure descriptors". The "official"
1235 refers to the fact that these descriptors are used when taking the address
1236 of a procedure, thus ensuring a unique address for each procedure. */
1239 get_opd (abfd, info, hppa_info)
1241 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1242 struct elf64_hppa_link_hash_table *hppa_info;
1247 opd = hppa_info->opd_sec;
1250 dynobj = hppa_info->root.dynobj;
1252 hppa_info->root.dynobj = dynobj = abfd;
1254 opd = bfd_make_section_with_flags (dynobj, ".opd",
1259 | SEC_LINKER_CREATED));
1261 || !bfd_set_section_alignment (abfd, opd, 3))
1267 hppa_info->opd_sec = opd;
1273 /* Create the PLT section. */
1276 get_plt (abfd, info, hppa_info)
1278 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1279 struct elf64_hppa_link_hash_table *hppa_info;
1284 plt = hppa_info->plt_sec;
1287 dynobj = hppa_info->root.dynobj;
1289 hppa_info->root.dynobj = dynobj = abfd;
1291 plt = bfd_make_section_with_flags (dynobj, ".plt",
1296 | SEC_LINKER_CREATED));
1298 || !bfd_set_section_alignment (abfd, plt, 3))
1304 hppa_info->plt_sec = plt;
1310 /* Create the DLT section. */
1313 get_dlt (abfd, info, hppa_info)
1315 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1316 struct elf64_hppa_link_hash_table *hppa_info;
1321 dlt = hppa_info->dlt_sec;
1324 dynobj = hppa_info->root.dynobj;
1326 hppa_info->root.dynobj = dynobj = abfd;
1328 dlt = bfd_make_section_with_flags (dynobj, ".dlt",
1333 | SEC_LINKER_CREATED));
1335 || !bfd_set_section_alignment (abfd, dlt, 3))
1341 hppa_info->dlt_sec = dlt;
1347 /* Create the stubs section. */
1350 get_stub (abfd, info, hppa_info)
1352 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1353 struct elf64_hppa_link_hash_table *hppa_info;
1358 stub = hppa_info->stub_sec;
1361 dynobj = hppa_info->root.dynobj;
1363 hppa_info->root.dynobj = dynobj = abfd;
1365 stub = bfd_make_section_with_flags (dynobj, ".stub",
1366 (SEC_ALLOC | SEC_LOAD
1370 | SEC_LINKER_CREATED));
1372 || !bfd_set_section_alignment (abfd, stub, 3))
1378 hppa_info->stub_sec = stub;
1384 /* Create sections necessary for dynamic linking. This is only a rough
1385 cut and will likely change as we learn more about the somewhat
1386 unusual dynamic linking scheme HP uses.
1389 Contains code to implement cross-space calls. The first time one
1390 of the stubs is used it will call into the dynamic linker, later
1391 calls will go straight to the target.
1393 The only stub we support right now looks like
1397 ldd OFFSET+8(%dp),%dp
1399 Other stubs may be needed in the future. We may want the remove
1400 the break/nop instruction. It is only used right now to keep the
1401 offset of a .plt entry and a .stub entry in sync.
1404 This is what most people call the .got. HP used a different name.
1408 Relocations for the DLT.
1411 Function pointers as address,gp pairs.
1414 Should contain dynamic IPLT (and EPLT?) relocations.
1420 EPLT relocations for symbols exported from shared libraries. */
1423 elf64_hppa_create_dynamic_sections (abfd, info)
1425 struct bfd_link_info *info;
1429 if (! get_stub (abfd, info, elf64_hppa_hash_table (info)))
1432 if (! get_dlt (abfd, info, elf64_hppa_hash_table (info)))
1435 if (! get_plt (abfd, info, elf64_hppa_hash_table (info)))
1438 if (! get_opd (abfd, info, elf64_hppa_hash_table (info)))
1441 s = bfd_make_section_with_flags (abfd, ".rela.dlt",
1442 (SEC_ALLOC | SEC_LOAD
1446 | SEC_LINKER_CREATED));
1448 || !bfd_set_section_alignment (abfd, s, 3))
1450 elf64_hppa_hash_table (info)->dlt_rel_sec = s;
1452 s = bfd_make_section_with_flags (abfd, ".rela.plt",
1453 (SEC_ALLOC | SEC_LOAD
1457 | SEC_LINKER_CREATED));
1459 || !bfd_set_section_alignment (abfd, s, 3))
1461 elf64_hppa_hash_table (info)->plt_rel_sec = s;
1463 s = bfd_make_section_with_flags (abfd, ".rela.data",
1464 (SEC_ALLOC | SEC_LOAD
1468 | SEC_LINKER_CREATED));
1470 || !bfd_set_section_alignment (abfd, s, 3))
1472 elf64_hppa_hash_table (info)->other_rel_sec = s;
1474 s = bfd_make_section_with_flags (abfd, ".rela.opd",
1475 (SEC_ALLOC | SEC_LOAD
1479 | SEC_LINKER_CREATED));
1481 || !bfd_set_section_alignment (abfd, s, 3))
1483 elf64_hppa_hash_table (info)->opd_rel_sec = s;
1488 /* Allocate dynamic relocations for those symbols that turned out
1492 allocate_dynrel_entries (dyn_h, data)
1493 struct elf64_hppa_dyn_hash_entry *dyn_h;
1496 struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data;
1497 struct elf64_hppa_link_hash_table *hppa_info;
1498 struct elf64_hppa_dyn_reloc_entry *rent;
1499 bfd_boolean dynamic_symbol, shared;
1501 hppa_info = elf64_hppa_hash_table (x->info);
1502 dynamic_symbol = elf64_hppa_dynamic_symbol_p (dyn_h->h, x->info);
1503 shared = x->info->shared;
1505 /* We may need to allocate relocations for a non-dynamic symbol
1506 when creating a shared library. */
1507 if (!dynamic_symbol && !shared)
1510 /* Take care of the normal data relocations. */
1512 for (rent = dyn_h->reloc_entries; rent; rent = rent->next)
1514 /* Allocate one iff we are building a shared library, the relocation
1515 isn't a R_PARISC_FPTR64, or we don't want an opd entry. */
1516 if (!shared && rent->type == R_PARISC_FPTR64 && dyn_h->want_opd)
1519 hppa_info->other_rel_sec->size += sizeof (Elf64_External_Rela);
1521 /* Make sure this symbol gets into the dynamic symbol table if it is
1522 not already recorded. ?!? This should not be in the loop since
1523 the symbol need only be added once. */
1525 || (dyn_h->h->dynindx == -1 && dyn_h->h->type != STT_PARISC_MILLI))
1526 if (!bfd_elf_link_record_local_dynamic_symbol
1527 (x->info, rent->sec->owner, dyn_h->sym_indx))
1531 /* Take care of the GOT and PLT relocations. */
1533 if ((dynamic_symbol || shared) && dyn_h->want_dlt)
1534 hppa_info->dlt_rel_sec->size += sizeof (Elf64_External_Rela);
1536 /* If we are building a shared library, then every symbol that has an
1537 opd entry will need an EPLT relocation to relocate the symbol's address
1538 and __gp value based on the runtime load address. */
1539 if (shared && dyn_h->want_opd)
1540 hppa_info->opd_rel_sec->size += sizeof (Elf64_External_Rela);
1542 if (dyn_h->want_plt && dynamic_symbol)
1544 bfd_size_type t = 0;
1546 /* Dynamic symbols get one IPLT relocation. Local symbols in
1547 shared libraries get two REL relocations. Local symbols in
1548 main applications get nothing. */
1550 t = sizeof (Elf64_External_Rela);
1552 t = 2 * sizeof (Elf64_External_Rela);
1554 hppa_info->plt_rel_sec->size += t;
1560 /* Adjust a symbol defined by a dynamic object and referenced by a
1564 elf64_hppa_adjust_dynamic_symbol (info, h)
1565 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1566 struct elf_link_hash_entry *h;
1568 /* ??? Undefined symbols with PLT entries should be re-defined
1569 to be the PLT entry. */
1571 /* If this is a weak symbol, and there is a real definition, the
1572 processor independent code will have arranged for us to see the
1573 real definition first, and we can just use the same value. */
1574 if (h->u.weakdef != NULL)
1576 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
1577 || h->u.weakdef->root.type == bfd_link_hash_defweak);
1578 h->root.u.def.section = h->u.weakdef->root.u.def.section;
1579 h->root.u.def.value = h->u.weakdef->root.u.def.value;
1583 /* If this is a reference to a symbol defined by a dynamic object which
1584 is not a function, we might allocate the symbol in our .dynbss section
1585 and allocate a COPY dynamic relocation.
1587 But PA64 code is canonically PIC, so as a rule we can avoid this sort
1593 /* This function is called via elf_link_hash_traverse to mark millicode
1594 symbols with a dynindx of -1 and to remove the string table reference
1595 from the dynamic symbol table. If the symbol is not a millicode symbol,
1596 elf64_hppa_mark_exported_functions is called. */
1599 elf64_hppa_mark_milli_and_exported_functions (h, data)
1600 struct elf_link_hash_entry *h;
1603 struct bfd_link_info *info = (struct bfd_link_info *)data;
1604 struct elf_link_hash_entry *elf = h;
1606 if (elf->root.type == bfd_link_hash_warning)
1607 elf = (struct elf_link_hash_entry *) elf->root.u.i.link;
1609 if (elf->type == STT_PARISC_MILLI)
1611 if (elf->dynindx != -1)
1614 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
1620 return elf64_hppa_mark_exported_functions (h, data);
1623 /* Set the final sizes of the dynamic sections and allocate memory for
1624 the contents of our special sections. */
1627 elf64_hppa_size_dynamic_sections (output_bfd, info)
1629 struct bfd_link_info *info;
1635 bfd_boolean reltext;
1636 struct elf64_hppa_allocate_data data;
1637 struct elf64_hppa_link_hash_table *hppa_info;
1639 hppa_info = elf64_hppa_hash_table (info);
1641 dynobj = elf_hash_table (info)->dynobj;
1642 BFD_ASSERT (dynobj != NULL);
1644 /* Mark each function this program exports so that we will allocate
1645 space in the .opd section for each function's FPTR. If we are
1646 creating dynamic sections, change the dynamic index of millicode
1647 symbols to -1 and remove them from the string table for .dynstr.
1649 We have to traverse the main linker hash table since we have to
1650 find functions which may not have been mentioned in any relocs. */
1651 elf_link_hash_traverse (elf_hash_table (info),
1652 (elf_hash_table (info)->dynamic_sections_created
1653 ? elf64_hppa_mark_milli_and_exported_functions
1654 : elf64_hppa_mark_exported_functions),
1657 if (elf_hash_table (info)->dynamic_sections_created)
1659 /* Set the contents of the .interp section to the interpreter. */
1660 if (info->executable)
1662 s = bfd_get_section_by_name (dynobj, ".interp");
1663 BFD_ASSERT (s != NULL);
1664 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
1665 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
1670 /* We may have created entries in the .rela.got section.
1671 However, if we are not creating the dynamic sections, we will
1672 not actually use these entries. Reset the size of .rela.dlt,
1673 which will cause it to get stripped from the output file
1675 s = bfd_get_section_by_name (dynobj, ".rela.dlt");
1680 /* Allocate the GOT entries. */
1683 if (elf64_hppa_hash_table (info)->dlt_sec)
1686 elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table,
1687 allocate_global_data_dlt, &data);
1688 hppa_info->dlt_sec->size = data.ofs;
1691 elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table,
1692 allocate_global_data_plt, &data);
1693 hppa_info->plt_sec->size = data.ofs;
1696 elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table,
1697 allocate_global_data_stub, &data);
1698 hppa_info->stub_sec->size = data.ofs;
1701 /* Allocate space for entries in the .opd section. */
1702 if (elf64_hppa_hash_table (info)->opd_sec)
1705 elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table,
1706 allocate_global_data_opd, &data);
1707 hppa_info->opd_sec->size = data.ofs;
1710 /* Now allocate space for dynamic relocations, if necessary. */
1711 if (hppa_info->root.dynamic_sections_created)
1712 elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table,
1713 allocate_dynrel_entries, &data);
1715 /* The sizes of all the sections are set. Allocate memory for them. */
1719 for (s = dynobj->sections; s != NULL; s = s->next)
1723 if ((s->flags & SEC_LINKER_CREATED) == 0)
1726 /* It's OK to base decisions on the section name, because none
1727 of the dynobj section names depend upon the input files. */
1728 name = bfd_get_section_name (dynobj, s);
1730 if (strcmp (name, ".plt") == 0)
1732 /* Remember whether there is a PLT. */
1735 else if (strcmp (name, ".opd") == 0
1736 || CONST_STRNEQ (name, ".dlt")
1737 || strcmp (name, ".stub") == 0
1738 || strcmp (name, ".got") == 0)
1740 /* Strip this section if we don't need it; see the comment below. */
1742 else if (CONST_STRNEQ (name, ".rela"))
1748 /* Remember whether there are any reloc sections other
1750 if (strcmp (name, ".rela.plt") != 0)
1752 const char *outname;
1756 /* If this relocation section applies to a read only
1757 section, then we probably need a DT_TEXTREL
1758 entry. The entries in the .rela.plt section
1759 really apply to the .got section, which we
1760 created ourselves and so know is not readonly. */
1761 outname = bfd_get_section_name (output_bfd,
1763 target = bfd_get_section_by_name (output_bfd, outname + 4);
1765 && (target->flags & SEC_READONLY) != 0
1766 && (target->flags & SEC_ALLOC) != 0)
1770 /* We use the reloc_count field as a counter if we need
1771 to copy relocs into the output file. */
1777 /* It's not one of our sections, so don't allocate space. */
1783 /* If we don't need this section, strip it from the
1784 output file. This is mostly to handle .rela.bss and
1785 .rela.plt. We must create both sections in
1786 create_dynamic_sections, because they must be created
1787 before the linker maps input sections to output
1788 sections. The linker does that before
1789 adjust_dynamic_symbol is called, and it is that
1790 function which decides whether anything needs to go
1791 into these sections. */
1792 s->flags |= SEC_EXCLUDE;
1796 if ((s->flags & SEC_HAS_CONTENTS) == 0)
1799 /* Allocate memory for the section contents if it has not
1800 been allocated already. We use bfd_zalloc here in case
1801 unused entries are not reclaimed before the section's
1802 contents are written out. This should not happen, but this
1803 way if it does, we get a R_PARISC_NONE reloc instead of
1805 if (s->contents == NULL)
1807 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
1808 if (s->contents == NULL)
1813 if (elf_hash_table (info)->dynamic_sections_created)
1815 /* Always create a DT_PLTGOT. It actually has nothing to do with
1816 the PLT, it is how we communicate the __gp value of a load
1817 module to the dynamic linker. */
1818 #define add_dynamic_entry(TAG, VAL) \
1819 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
1821 if (!add_dynamic_entry (DT_HP_DLD_FLAGS, 0)
1822 || !add_dynamic_entry (DT_PLTGOT, 0))
1825 /* Add some entries to the .dynamic section. We fill in the
1826 values later, in elf64_hppa_finish_dynamic_sections, but we
1827 must add the entries now so that we get the correct size for
1828 the .dynamic section. The DT_DEBUG entry is filled in by the
1829 dynamic linker and used by the debugger. */
1832 if (!add_dynamic_entry (DT_DEBUG, 0)
1833 || !add_dynamic_entry (DT_HP_DLD_HOOK, 0)
1834 || !add_dynamic_entry (DT_HP_LOAD_MAP, 0))
1838 /* Force DT_FLAGS to always be set.
1839 Required by HPUX 11.00 patch PHSS_26559. */
1840 if (!add_dynamic_entry (DT_FLAGS, (info)->flags))
1845 if (!add_dynamic_entry (DT_PLTRELSZ, 0)
1846 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
1847 || !add_dynamic_entry (DT_JMPREL, 0))
1853 if (!add_dynamic_entry (DT_RELA, 0)
1854 || !add_dynamic_entry (DT_RELASZ, 0)
1855 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
1861 if (!add_dynamic_entry (DT_TEXTREL, 0))
1863 info->flags |= DF_TEXTREL;
1866 #undef add_dynamic_entry
1871 /* Called after we have output the symbol into the dynamic symbol
1872 table, but before we output the symbol into the normal symbol
1875 For some symbols we had to change their address when outputting
1876 the dynamic symbol table. We undo that change here so that
1877 the symbols have their expected value in the normal symbol
1881 elf64_hppa_link_output_symbol_hook (info, name, sym, input_sec, h)
1882 struct bfd_link_info *info;
1884 Elf_Internal_Sym *sym;
1885 asection *input_sec ATTRIBUTE_UNUSED;
1886 struct elf_link_hash_entry *h;
1888 struct elf64_hppa_link_hash_table *hppa_info;
1889 struct elf64_hppa_dyn_hash_entry *dyn_h;
1891 /* We may be called with the file symbol or section symbols.
1892 They never need munging, so it is safe to ignore them. */
1896 /* Get the PA dyn_symbol (if any) associated with NAME. */
1897 hppa_info = elf64_hppa_hash_table (info);
1898 dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table,
1899 name, FALSE, FALSE);
1900 if (!dyn_h || dyn_h->h != h)
1903 /* Function symbols for which we created .opd entries *may* have been
1904 munged by finish_dynamic_symbol and have to be un-munged here.
1906 Note that finish_dynamic_symbol sometimes turns dynamic symbols
1907 into non-dynamic ones, so we initialize st_shndx to -1 in
1908 mark_exported_functions and check to see if it was overwritten
1909 here instead of just checking dyn_h->h->dynindx. */
1910 if (dyn_h->want_opd && dyn_h->st_shndx != -1)
1912 /* Restore the saved value and section index. */
1913 sym->st_value = dyn_h->st_value;
1914 sym->st_shndx = dyn_h->st_shndx;
1920 /* Finish up dynamic symbol handling. We set the contents of various
1921 dynamic sections here. */
1924 elf64_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
1926 struct bfd_link_info *info;
1927 struct elf_link_hash_entry *h;
1928 Elf_Internal_Sym *sym;
1930 asection *stub, *splt, *sdlt, *sopd, *spltrel, *sdltrel;
1931 struct elf64_hppa_link_hash_table *hppa_info;
1932 struct elf64_hppa_dyn_hash_entry *dyn_h;
1934 hppa_info = elf64_hppa_hash_table (info);
1935 dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table,
1936 h->root.root.string, FALSE, FALSE);
1938 stub = hppa_info->stub_sec;
1939 splt = hppa_info->plt_sec;
1940 sdlt = hppa_info->dlt_sec;
1941 sopd = hppa_info->opd_sec;
1942 spltrel = hppa_info->plt_rel_sec;
1943 sdltrel = hppa_info->dlt_rel_sec;
1945 /* Incredible. It is actually necessary to NOT use the symbol's real
1946 value when building the dynamic symbol table for a shared library.
1947 At least for symbols that refer to functions.
1949 We will store a new value and section index into the symbol long
1950 enough to output it into the dynamic symbol table, then we restore
1951 the original values (in elf64_hppa_link_output_symbol_hook). */
1952 if (dyn_h && dyn_h->want_opd)
1954 BFD_ASSERT (sopd != NULL);
1956 /* Save away the original value and section index so that we
1957 can restore them later. */
1958 dyn_h->st_value = sym->st_value;
1959 dyn_h->st_shndx = sym->st_shndx;
1961 /* For the dynamic symbol table entry, we want the value to be
1962 address of this symbol's entry within the .opd section. */
1963 sym->st_value = (dyn_h->opd_offset
1964 + sopd->output_offset
1965 + sopd->output_section->vma);
1966 sym->st_shndx = _bfd_elf_section_from_bfd_section (output_bfd,
1967 sopd->output_section);
1970 /* Initialize a .plt entry if requested. */
1971 if (dyn_h && dyn_h->want_plt
1972 && elf64_hppa_dynamic_symbol_p (dyn_h->h, info))
1975 Elf_Internal_Rela rel;
1978 BFD_ASSERT (splt != NULL && spltrel != NULL);
1980 /* We do not actually care about the value in the PLT entry
1981 if we are creating a shared library and the symbol is
1982 still undefined, we create a dynamic relocation to fill
1983 in the correct value. */
1984 if (info->shared && h->root.type == bfd_link_hash_undefined)
1987 value = (h->root.u.def.value + h->root.u.def.section->vma);
1989 /* Fill in the entry in the procedure linkage table.
1991 The format of a plt entry is
1994 plt_offset is the offset within the PLT section at which to
1995 install the PLT entry.
1997 We are modifying the in-memory PLT contents here, so we do not add
1998 in the output_offset of the PLT section. */
2000 bfd_put_64 (splt->owner, value, splt->contents + dyn_h->plt_offset);
2001 value = _bfd_get_gp_value (splt->output_section->owner);
2002 bfd_put_64 (splt->owner, value, splt->contents + dyn_h->plt_offset + 0x8);
2004 /* Create a dynamic IPLT relocation for this entry.
2006 We are creating a relocation in the output file's PLT section,
2007 which is included within the DLT secton. So we do need to include
2008 the PLT's output_offset in the computation of the relocation's
2010 rel.r_offset = (dyn_h->plt_offset + splt->output_offset
2011 + splt->output_section->vma);
2012 rel.r_info = ELF64_R_INFO (h->dynindx, R_PARISC_IPLT);
2015 loc = spltrel->contents;
2016 loc += spltrel->reloc_count++ * sizeof (Elf64_External_Rela);
2017 bfd_elf64_swap_reloca_out (splt->output_section->owner, &rel, loc);
2020 /* Initialize an external call stub entry if requested. */
2021 if (dyn_h && dyn_h->want_stub
2022 && elf64_hppa_dynamic_symbol_p (dyn_h->h, info))
2026 unsigned int max_offset;
2028 BFD_ASSERT (stub != NULL);
2030 /* Install the generic stub template.
2032 We are modifying the contents of the stub section, so we do not
2033 need to include the stub section's output_offset here. */
2034 memcpy (stub->contents + dyn_h->stub_offset, plt_stub, sizeof (plt_stub));
2036 /* Fix up the first ldd instruction.
2038 We are modifying the contents of the STUB section in memory,
2039 so we do not need to include its output offset in this computation.
2041 Note the plt_offset value is the value of the PLT entry relative to
2042 the start of the PLT section. These instructions will reference
2043 data relative to the value of __gp, which may not necessarily have
2044 the same address as the start of the PLT section.
2046 gp_offset contains the offset of __gp within the PLT section. */
2047 value = dyn_h->plt_offset - hppa_info->gp_offset;
2049 insn = bfd_get_32 (stub->owner, stub->contents + dyn_h->stub_offset);
2050 if (output_bfd->arch_info->mach >= 25)
2052 /* Wide mode allows 16 bit offsets. */
2055 insn |= re_assemble_16 ((int) value);
2061 insn |= re_assemble_14 ((int) value);
2064 if ((value & 7) || value + max_offset >= 2*max_offset - 8)
2066 (*_bfd_error_handler) (_("stub entry for %s cannot load .plt, dp offset = %ld"),
2072 bfd_put_32 (stub->owner, (bfd_vma) insn,
2073 stub->contents + dyn_h->stub_offset);
2075 /* Fix up the second ldd instruction. */
2077 insn = bfd_get_32 (stub->owner, stub->contents + dyn_h->stub_offset + 8);
2078 if (output_bfd->arch_info->mach >= 25)
2081 insn |= re_assemble_16 ((int) value);
2086 insn |= re_assemble_14 ((int) value);
2088 bfd_put_32 (stub->owner, (bfd_vma) insn,
2089 stub->contents + dyn_h->stub_offset + 8);
2095 /* The .opd section contains FPTRs for each function this file
2096 exports. Initialize the FPTR entries. */
2099 elf64_hppa_finalize_opd (dyn_h, data)
2100 struct elf64_hppa_dyn_hash_entry *dyn_h;
2103 struct bfd_link_info *info = (struct bfd_link_info *)data;
2104 struct elf64_hppa_link_hash_table *hppa_info;
2105 struct elf_link_hash_entry *h = dyn_h ? dyn_h->h : NULL;
2109 hppa_info = elf64_hppa_hash_table (info);
2110 sopd = hppa_info->opd_sec;
2111 sopdrel = hppa_info->opd_rel_sec;
2113 if (h && dyn_h->want_opd)
2117 /* The first two words of an .opd entry are zero.
2119 We are modifying the contents of the OPD section in memory, so we
2120 do not need to include its output offset in this computation. */
2121 memset (sopd->contents + dyn_h->opd_offset, 0, 16);
2123 value = (h->root.u.def.value
2124 + h->root.u.def.section->output_section->vma
2125 + h->root.u.def.section->output_offset);
2127 /* The next word is the address of the function. */
2128 bfd_put_64 (sopd->owner, value, sopd->contents + dyn_h->opd_offset + 16);
2130 /* The last word is our local __gp value. */
2131 value = _bfd_get_gp_value (sopd->output_section->owner);
2132 bfd_put_64 (sopd->owner, value, sopd->contents + dyn_h->opd_offset + 24);
2135 /* If we are generating a shared library, we must generate EPLT relocations
2136 for each entry in the .opd, even for static functions (they may have
2137 had their address taken). */
2138 if (info->shared && dyn_h && dyn_h->want_opd)
2140 Elf_Internal_Rela rel;
2144 /* We may need to do a relocation against a local symbol, in
2145 which case we have to look up it's dynamic symbol index off
2146 the local symbol hash table. */
2147 if (h && h->dynindx != -1)
2148 dynindx = h->dynindx;
2151 = _bfd_elf_link_lookup_local_dynindx (info, dyn_h->owner,
2154 /* The offset of this relocation is the absolute address of the
2155 .opd entry for this symbol. */
2156 rel.r_offset = (dyn_h->opd_offset + sopd->output_offset
2157 + sopd->output_section->vma);
2159 /* If H is non-null, then we have an external symbol.
2161 It is imperative that we use a different dynamic symbol for the
2162 EPLT relocation if the symbol has global scope.
2164 In the dynamic symbol table, the function symbol will have a value
2165 which is address of the function's .opd entry.
2167 Thus, we can not use that dynamic symbol for the EPLT relocation
2168 (if we did, the data in the .opd would reference itself rather
2169 than the actual address of the function). Instead we have to use
2170 a new dynamic symbol which has the same value as the original global
2173 We prefix the original symbol with a "." and use the new symbol in
2174 the EPLT relocation. This new symbol has already been recorded in
2175 the symbol table, we just have to look it up and use it.
2177 We do not have such problems with static functions because we do
2178 not make their addresses in the dynamic symbol table point to
2179 the .opd entry. Ultimately this should be safe since a static
2180 function can not be directly referenced outside of its shared
2183 We do have to play similar games for FPTR relocations in shared
2184 libraries, including those for static symbols. See the FPTR
2185 handling in elf64_hppa_finalize_dynreloc. */
2189 struct elf_link_hash_entry *nh;
2191 new_name = alloca (strlen (h->root.root.string) + 2);
2193 strcpy (new_name + 1, h->root.root.string);
2195 nh = elf_link_hash_lookup (elf_hash_table (info),
2196 new_name, FALSE, FALSE, FALSE);
2198 /* All we really want from the new symbol is its dynamic
2200 dynindx = nh->dynindx;
2204 rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_EPLT);
2206 loc = sopdrel->contents;
2207 loc += sopdrel->reloc_count++ * sizeof (Elf64_External_Rela);
2208 bfd_elf64_swap_reloca_out (sopd->output_section->owner, &rel, loc);
2213 /* The .dlt section contains addresses for items referenced through the
2214 dlt. Note that we can have a DLTIND relocation for a local symbol, thus
2215 we can not depend on finish_dynamic_symbol to initialize the .dlt. */
2218 elf64_hppa_finalize_dlt (dyn_h, data)
2219 struct elf64_hppa_dyn_hash_entry *dyn_h;
2222 struct bfd_link_info *info = (struct bfd_link_info *)data;
2223 struct elf64_hppa_link_hash_table *hppa_info;
2224 asection *sdlt, *sdltrel;
2225 struct elf_link_hash_entry *h = dyn_h ? dyn_h->h : NULL;
2227 hppa_info = elf64_hppa_hash_table (info);
2229 sdlt = hppa_info->dlt_sec;
2230 sdltrel = hppa_info->dlt_rel_sec;
2232 /* H/DYN_H may refer to a local variable and we know it's
2233 address, so there is no need to create a relocation. Just install
2234 the proper value into the DLT, note this shortcut can not be
2235 skipped when building a shared library. */
2236 if (! info->shared && h && dyn_h->want_dlt)
2240 /* If we had an LTOFF_FPTR style relocation we want the DLT entry
2241 to point to the FPTR entry in the .opd section.
2243 We include the OPD's output offset in this computation as
2244 we are referring to an absolute address in the resulting
2246 if (dyn_h->want_opd)
2248 value = (dyn_h->opd_offset
2249 + hppa_info->opd_sec->output_offset
2250 + hppa_info->opd_sec->output_section->vma);
2252 else if ((h->root.type == bfd_link_hash_defined
2253 || h->root.type == bfd_link_hash_defweak)
2254 && h->root.u.def.section)
2256 value = h->root.u.def.value + h->root.u.def.section->output_offset;
2257 if (h->root.u.def.section->output_section)
2258 value += h->root.u.def.section->output_section->vma;
2260 value += h->root.u.def.section->vma;
2263 /* We have an undefined function reference. */
2266 /* We do not need to include the output offset of the DLT section
2267 here because we are modifying the in-memory contents. */
2268 bfd_put_64 (sdlt->owner, value, sdlt->contents + dyn_h->dlt_offset);
2271 /* Create a relocation for the DLT entry associated with this symbol.
2272 When building a shared library the symbol does not have to be dynamic. */
2274 && (elf64_hppa_dynamic_symbol_p (dyn_h->h, info) || info->shared))
2276 Elf_Internal_Rela rel;
2280 /* We may need to do a relocation against a local symbol, in
2281 which case we have to look up it's dynamic symbol index off
2282 the local symbol hash table. */
2283 if (h && h->dynindx != -1)
2284 dynindx = h->dynindx;
2287 = _bfd_elf_link_lookup_local_dynindx (info, dyn_h->owner,
2290 /* Create a dynamic relocation for this entry. Do include the output
2291 offset of the DLT entry since we need an absolute address in the
2292 resulting object file. */
2293 rel.r_offset = (dyn_h->dlt_offset + sdlt->output_offset
2294 + sdlt->output_section->vma);
2295 if (h && h->type == STT_FUNC)
2296 rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_FPTR64);
2298 rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_DIR64);
2301 loc = sdltrel->contents;
2302 loc += sdltrel->reloc_count++ * sizeof (Elf64_External_Rela);
2303 bfd_elf64_swap_reloca_out (sdlt->output_section->owner, &rel, loc);
2308 /* Finalize the dynamic relocations. Specifically the FPTR relocations
2309 for dynamic functions used to initialize static data. */
2312 elf64_hppa_finalize_dynreloc (dyn_h, data)
2313 struct elf64_hppa_dyn_hash_entry *dyn_h;
2316 struct bfd_link_info *info = (struct bfd_link_info *)data;
2317 struct elf64_hppa_link_hash_table *hppa_info;
2318 struct elf_link_hash_entry *h;
2321 dynamic_symbol = elf64_hppa_dynamic_symbol_p (dyn_h->h, info);
2323 if (!dynamic_symbol && !info->shared)
2326 if (dyn_h->reloc_entries)
2328 struct elf64_hppa_dyn_reloc_entry *rent;
2331 hppa_info = elf64_hppa_hash_table (info);
2334 /* We may need to do a relocation against a local symbol, in
2335 which case we have to look up it's dynamic symbol index off
2336 the local symbol hash table. */
2337 if (h && h->dynindx != -1)
2338 dynindx = h->dynindx;
2341 = _bfd_elf_link_lookup_local_dynindx (info, dyn_h->owner,
2344 for (rent = dyn_h->reloc_entries; rent; rent = rent->next)
2346 Elf_Internal_Rela rel;
2349 /* Allocate one iff we are building a shared library, the relocation
2350 isn't a R_PARISC_FPTR64, or we don't want an opd entry. */
2351 if (!info->shared && rent->type == R_PARISC_FPTR64 && dyn_h->want_opd)
2354 /* Create a dynamic relocation for this entry.
2356 We need the output offset for the reloc's section because
2357 we are creating an absolute address in the resulting object
2359 rel.r_offset = (rent->offset + rent->sec->output_offset
2360 + rent->sec->output_section->vma);
2362 /* An FPTR64 relocation implies that we took the address of
2363 a function and that the function has an entry in the .opd
2364 section. We want the FPTR64 relocation to reference the
2367 We could munge the symbol value in the dynamic symbol table
2368 (in fact we already do for functions with global scope) to point
2369 to the .opd entry. Then we could use that dynamic symbol in
2372 Or we could do something sensible, not munge the symbol's
2373 address and instead just use a different symbol to reference
2374 the .opd entry. At least that seems sensible until you
2375 realize there's no local dynamic symbols we can use for that
2376 purpose. Thus the hair in the check_relocs routine.
2378 We use a section symbol recorded by check_relocs as the
2379 base symbol for the relocation. The addend is the difference
2380 between the section symbol and the address of the .opd entry. */
2381 if (info->shared && rent->type == R_PARISC_FPTR64 && dyn_h->want_opd)
2383 bfd_vma value, value2;
2385 /* First compute the address of the opd entry for this symbol. */
2386 value = (dyn_h->opd_offset
2387 + hppa_info->opd_sec->output_section->vma
2388 + hppa_info->opd_sec->output_offset);
2390 /* Compute the value of the start of the section with
2392 value2 = (rent->sec->output_section->vma
2393 + rent->sec->output_offset);
2395 /* Compute the difference between the start of the section
2396 with the relocation and the opd entry. */
2399 /* The result becomes the addend of the relocation. */
2400 rel.r_addend = value;
2402 /* The section symbol becomes the symbol for the dynamic
2405 = _bfd_elf_link_lookup_local_dynindx (info,
2410 rel.r_addend = rent->addend;
2412 rel.r_info = ELF64_R_INFO (dynindx, rent->type);
2414 loc = hppa_info->other_rel_sec->contents;
2415 loc += (hppa_info->other_rel_sec->reloc_count++
2416 * sizeof (Elf64_External_Rela));
2417 bfd_elf64_swap_reloca_out (hppa_info->other_rel_sec->output_section->owner,
2425 /* Used to decide how to sort relocs in an optimal manner for the
2426 dynamic linker, before writing them out. */
2428 static enum elf_reloc_type_class
2429 elf64_hppa_reloc_type_class (rela)
2430 const Elf_Internal_Rela *rela;
2432 if (ELF64_R_SYM (rela->r_info) == 0)
2433 return reloc_class_relative;
2435 switch ((int) ELF64_R_TYPE (rela->r_info))
2438 return reloc_class_plt;
2440 return reloc_class_copy;
2442 return reloc_class_normal;
2446 /* Finish up the dynamic sections. */
2449 elf64_hppa_finish_dynamic_sections (output_bfd, info)
2451 struct bfd_link_info *info;
2455 struct elf64_hppa_link_hash_table *hppa_info;
2457 hppa_info = elf64_hppa_hash_table (info);
2459 /* Finalize the contents of the .opd section. */
2460 elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table,
2461 elf64_hppa_finalize_opd,
2464 elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table,
2465 elf64_hppa_finalize_dynreloc,
2468 /* Finalize the contents of the .dlt section. */
2469 dynobj = elf_hash_table (info)->dynobj;
2470 /* Finalize the contents of the .dlt section. */
2471 elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table,
2472 elf64_hppa_finalize_dlt,
2475 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
2477 if (elf_hash_table (info)->dynamic_sections_created)
2479 Elf64_External_Dyn *dyncon, *dynconend;
2481 BFD_ASSERT (sdyn != NULL);
2483 dyncon = (Elf64_External_Dyn *) sdyn->contents;
2484 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
2485 for (; dyncon < dynconend; dyncon++)
2487 Elf_Internal_Dyn dyn;
2490 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
2497 case DT_HP_LOAD_MAP:
2498 /* Compute the absolute address of 16byte scratchpad area
2499 for the dynamic linker.
2501 By convention the linker script will allocate the scratchpad
2502 area at the start of the .data section. So all we have to
2503 to is find the start of the .data section. */
2504 s = bfd_get_section_by_name (output_bfd, ".data");
2505 dyn.d_un.d_ptr = s->vma;
2506 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2510 /* HP's use PLTGOT to set the GOT register. */
2511 dyn.d_un.d_ptr = _bfd_get_gp_value (output_bfd);
2512 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2516 s = hppa_info->plt_rel_sec;
2517 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
2518 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2522 s = hppa_info->plt_rel_sec;
2523 dyn.d_un.d_val = s->size;
2524 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2528 s = hppa_info->other_rel_sec;
2529 if (! s || ! s->size)
2530 s = hppa_info->dlt_rel_sec;
2531 if (! s || ! s->size)
2532 s = hppa_info->opd_rel_sec;
2533 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
2534 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2538 s = hppa_info->other_rel_sec;
2539 dyn.d_un.d_val = s->size;
2540 s = hppa_info->dlt_rel_sec;
2541 dyn.d_un.d_val += s->size;
2542 s = hppa_info->opd_rel_sec;
2543 dyn.d_un.d_val += s->size;
2544 /* There is some question about whether or not the size of
2545 the PLT relocs should be included here. HP's tools do
2546 it, so we'll emulate them. */
2547 s = hppa_info->plt_rel_sec;
2548 dyn.d_un.d_val += s->size;
2549 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2559 /* Support for core dump NOTE sections. */
2562 elf64_hppa_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
2567 switch (note->descsz)
2572 case 760: /* Linux/hppa */
2574 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
2577 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 32);
2586 /* Make a ".reg/999" section. */
2587 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
2588 size, note->descpos + offset);
2592 elf64_hppa_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
2597 switch (note->descsz)
2602 case 136: /* Linux/hppa elf_prpsinfo. */
2603 elf_tdata (abfd)->core_program
2604 = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
2605 elf_tdata (abfd)->core_command
2606 = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
2609 /* Note that for some reason, a spurious space is tacked
2610 onto the end of the args in some (at least one anyway)
2611 implementations, so strip it off if it exists. */
2612 command = elf_tdata (abfd)->core_command;
2613 n = strlen (command);
2615 if (0 < n && command[n - 1] == ' ')
2616 command[n - 1] = '\0';
2621 /* Return the number of additional phdrs we will need.
2623 The generic ELF code only creates PT_PHDRs for executables. The HP
2624 dynamic linker requires PT_PHDRs for dynamic libraries too.
2626 This routine indicates that the backend needs one additional program
2627 header for that case.
2629 Note we do not have access to the link info structure here, so we have
2630 to guess whether or not we are building a shared library based on the
2631 existence of a .interp section. */
2634 elf64_hppa_additional_program_headers (bfd *abfd,
2635 struct bfd_link_info *info ATTRIBUTE_UNUSED)
2639 /* If we are creating a shared library, then we have to create a
2640 PT_PHDR segment. HP's dynamic linker chokes without it. */
2641 s = bfd_get_section_by_name (abfd, ".interp");
2647 /* Allocate and initialize any program headers required by this
2650 The generic ELF code only creates PT_PHDRs for executables. The HP
2651 dynamic linker requires PT_PHDRs for dynamic libraries too.
2653 This allocates the PT_PHDR and initializes it in a manner suitable
2656 Note we do not have access to the link info structure here, so we have
2657 to guess whether or not we are building a shared library based on the
2658 existence of a .interp section. */
2661 elf64_hppa_modify_segment_map (bfd *abfd,
2662 struct bfd_link_info *info ATTRIBUTE_UNUSED)
2664 struct elf_segment_map *m;
2667 s = bfd_get_section_by_name (abfd, ".interp");
2670 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
2671 if (m->p_type == PT_PHDR)
2675 m = ((struct elf_segment_map *)
2676 bfd_zalloc (abfd, (bfd_size_type) sizeof *m));
2680 m->p_type = PT_PHDR;
2681 m->p_flags = PF_R | PF_X;
2682 m->p_flags_valid = 1;
2683 m->p_paddr_valid = 1;
2684 m->includes_phdrs = 1;
2686 m->next = elf_tdata (abfd)->segment_map;
2687 elf_tdata (abfd)->segment_map = m;
2691 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
2692 if (m->p_type == PT_LOAD)
2696 for (i = 0; i < m->count; i++)
2698 /* The code "hint" is not really a hint. It is a requirement
2699 for certain versions of the HP dynamic linker. Worse yet,
2700 it must be set even if the shared library does not have
2701 any code in its "text" segment (thus the check for .hash
2702 to catch this situation). */
2703 if (m->sections[i]->flags & SEC_CODE
2704 || (strcmp (m->sections[i]->name, ".hash") == 0))
2705 m->p_flags |= (PF_X | PF_HP_CODE);
2712 /* Called when writing out an object file to decide the type of a
2715 elf64_hppa_elf_get_symbol_type (elf_sym, type)
2716 Elf_Internal_Sym *elf_sym;
2719 if (ELF_ST_TYPE (elf_sym->st_info) == STT_PARISC_MILLI)
2720 return STT_PARISC_MILLI;
2725 /* Support HP specific sections for core files. */
2727 elf64_hppa_section_from_phdr (bfd *abfd, Elf_Internal_Phdr *hdr, int index,
2728 const char *typename)
2730 if (hdr->p_type == PT_HP_CORE_KERNEL)
2734 if (!_bfd_elf_make_section_from_phdr (abfd, hdr, index, typename))
2737 sect = bfd_make_section_anyway (abfd, ".kernel");
2740 sect->size = hdr->p_filesz;
2741 sect->filepos = hdr->p_offset;
2742 sect->flags = SEC_HAS_CONTENTS | SEC_READONLY;
2746 if (hdr->p_type == PT_HP_CORE_PROC)
2750 if (bfd_seek (abfd, hdr->p_offset, SEEK_SET) != 0)
2752 if (bfd_bread (&sig, 4, abfd) != 4)
2755 elf_tdata (abfd)->core_signal = sig;
2757 if (!_bfd_elf_make_section_from_phdr (abfd, hdr, index, typename))
2760 /* GDB uses the ".reg" section to read register contents. */
2761 return _bfd_elfcore_make_pseudosection (abfd, ".reg", hdr->p_filesz,
2765 if (hdr->p_type == PT_HP_CORE_LOADABLE
2766 || hdr->p_type == PT_HP_CORE_STACK
2767 || hdr->p_type == PT_HP_CORE_MMF)
2768 hdr->p_type = PT_LOAD;
2770 return _bfd_elf_make_section_from_phdr (abfd, hdr, index, typename);
2773 static const struct bfd_elf_special_section elf64_hppa_special_sections[] =
2775 { STRING_COMMA_LEN (".fini"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
2776 { STRING_COMMA_LEN (".init"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
2777 { STRING_COMMA_LEN (".plt"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT },
2778 { STRING_COMMA_LEN (".dlt"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT },
2779 { STRING_COMMA_LEN (".sdata"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT },
2780 { STRING_COMMA_LEN (".sbss"), 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT },
2781 { STRING_COMMA_LEN (".tbss"), 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_HP_TLS },
2782 { NULL, 0, 0, 0, 0 }
2785 /* The hash bucket size is the standard one, namely 4. */
2787 const struct elf_size_info hppa64_elf_size_info =
2789 sizeof (Elf64_External_Ehdr),
2790 sizeof (Elf64_External_Phdr),
2791 sizeof (Elf64_External_Shdr),
2792 sizeof (Elf64_External_Rel),
2793 sizeof (Elf64_External_Rela),
2794 sizeof (Elf64_External_Sym),
2795 sizeof (Elf64_External_Dyn),
2796 sizeof (Elf_External_Note),
2800 ELFCLASS64, EV_CURRENT,
2801 bfd_elf64_write_out_phdrs,
2802 bfd_elf64_write_shdrs_and_ehdr,
2803 bfd_elf64_checksum_contents,
2804 bfd_elf64_write_relocs,
2805 bfd_elf64_swap_symbol_in,
2806 bfd_elf64_swap_symbol_out,
2807 bfd_elf64_slurp_reloc_table,
2808 bfd_elf64_slurp_symbol_table,
2809 bfd_elf64_swap_dyn_in,
2810 bfd_elf64_swap_dyn_out,
2811 bfd_elf64_swap_reloc_in,
2812 bfd_elf64_swap_reloc_out,
2813 bfd_elf64_swap_reloca_in,
2814 bfd_elf64_swap_reloca_out
2817 #define TARGET_BIG_SYM bfd_elf64_hppa_vec
2818 #define TARGET_BIG_NAME "elf64-hppa"
2819 #define ELF_ARCH bfd_arch_hppa
2820 #define ELF_MACHINE_CODE EM_PARISC
2821 /* This is not strictly correct. The maximum page size for PA2.0 is
2822 64M. But everything still uses 4k. */
2823 #define ELF_MAXPAGESIZE 0x1000
2824 #define ELF_OSABI ELFOSABI_HPUX
2826 #define bfd_elf64_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
2827 #define bfd_elf64_bfd_reloc_name_lookup elf_hppa_reloc_name_lookup
2828 #define bfd_elf64_bfd_is_local_label_name elf_hppa_is_local_label_name
2829 #define elf_info_to_howto elf_hppa_info_to_howto
2830 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
2832 #define elf_backend_section_from_shdr elf64_hppa_section_from_shdr
2833 #define elf_backend_object_p elf64_hppa_object_p
2834 #define elf_backend_final_write_processing \
2835 elf_hppa_final_write_processing
2836 #define elf_backend_fake_sections elf_hppa_fake_sections
2837 #define elf_backend_add_symbol_hook elf_hppa_add_symbol_hook
2839 #define elf_backend_relocate_section elf_hppa_relocate_section
2841 #define bfd_elf64_bfd_final_link elf_hppa_final_link
2843 #define elf_backend_create_dynamic_sections \
2844 elf64_hppa_create_dynamic_sections
2845 #define elf_backend_post_process_headers elf64_hppa_post_process_headers
2847 #define elf_backend_omit_section_dynsym \
2848 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
2849 #define elf_backend_adjust_dynamic_symbol \
2850 elf64_hppa_adjust_dynamic_symbol
2852 #define elf_backend_size_dynamic_sections \
2853 elf64_hppa_size_dynamic_sections
2855 #define elf_backend_finish_dynamic_symbol \
2856 elf64_hppa_finish_dynamic_symbol
2857 #define elf_backend_finish_dynamic_sections \
2858 elf64_hppa_finish_dynamic_sections
2859 #define elf_backend_grok_prstatus elf64_hppa_grok_prstatus
2860 #define elf_backend_grok_psinfo elf64_hppa_grok_psinfo
2862 /* Stuff for the BFD linker: */
2863 #define bfd_elf64_bfd_link_hash_table_create \
2864 elf64_hppa_hash_table_create
2866 #define elf_backend_check_relocs \
2867 elf64_hppa_check_relocs
2869 #define elf_backend_size_info \
2870 hppa64_elf_size_info
2872 #define elf_backend_additional_program_headers \
2873 elf64_hppa_additional_program_headers
2875 #define elf_backend_modify_segment_map \
2876 elf64_hppa_modify_segment_map
2878 #define elf_backend_link_output_symbol_hook \
2879 elf64_hppa_link_output_symbol_hook
2881 #define elf_backend_want_got_plt 0
2882 #define elf_backend_plt_readonly 0
2883 #define elf_backend_want_plt_sym 0
2884 #define elf_backend_got_header_size 0
2885 #define elf_backend_type_change_ok TRUE
2886 #define elf_backend_get_symbol_type elf64_hppa_elf_get_symbol_type
2887 #define elf_backend_reloc_type_class elf64_hppa_reloc_type_class
2888 #define elf_backend_rela_normal 1
2889 #define elf_backend_special_sections elf64_hppa_special_sections
2890 #define elf_backend_action_discarded elf_hppa_action_discarded
2891 #define elf_backend_section_from_phdr elf64_hppa_section_from_phdr
2893 #define elf64_bed elf64_hppa_hpux_bed
2895 #include "elf64-target.h"
2897 #undef TARGET_BIG_SYM
2898 #define TARGET_BIG_SYM bfd_elf64_hppa_linux_vec
2899 #undef TARGET_BIG_NAME
2900 #define TARGET_BIG_NAME "elf64-hppa-linux"
2902 #define ELF_OSABI ELFOSABI_LINUX
2903 #undef elf_backend_post_process_headers
2904 #define elf_backend_post_process_headers _bfd_elf_set_osabi
2906 #define elf64_bed elf64_hppa_linux_bed
2908 #include "elf64-target.h"