1 /* Support for HPPA 64-bit ELF
2 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_link_hash_entry
79 struct elf_link_hash_entry eh;
81 /* Offsets for this symbol in various linker sections. */
87 /* The index of the (possibly local) symbol in the input bfd and its
88 associated BFD. Needed so that we can have relocs against local
89 symbols in shared libraries. */
93 /* Dynamic symbols may need to have two different values. One for
94 the dynamic symbol table, one for the normal symbol table.
96 In such cases we store the symbol's real value and section
97 index here so we can restore the real value before we write
98 the normal symbol table. */
102 /* Used to count non-got, non-plt relocations for delayed sizing
103 of relocation sections. */
104 struct elf64_hppa_dyn_reloc_entry
106 /* Next relocation in the chain. */
107 struct elf64_hppa_dyn_reloc_entry *next;
109 /* The type of the relocation. */
112 /* The input section of the relocation. */
115 /* Number of relocs copied in this section. */
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_link_hash_table
140 struct elf_link_hash_table root;
142 /* Shortcuts to get to the various linker defined sections. */
144 asection *dlt_rel_sec;
146 asection *plt_rel_sec;
148 asection *opd_rel_sec;
149 asection *other_rel_sec;
151 /* Offset of __gp within .plt section. When the PLT gets large we want
152 to slide __gp into the PLT section so that we can continue to use
153 single DP relative instructions to load values out of the PLT. */
156 /* Note this is not strictly correct. We should create a stub section for
157 each input section with calls. The stub section should be placed before
158 the section with the call. */
161 bfd_vma text_segment_base;
162 bfd_vma data_segment_base;
164 /* We build tables to map from an input section back to its
165 symbol index. This is the BFD for which we currently have
167 bfd *section_syms_bfd;
169 /* Array of symbol numbers for each input section attached to the
174 #define hppa_link_hash_table(p) \
175 ((struct elf64_hppa_link_hash_table *) ((p)->hash))
177 #define hppa_elf_hash_entry(ent) \
178 ((struct elf64_hppa_link_hash_entry *)(ent))
180 #define eh_name(eh) \
181 (eh ? eh->root.root.string : "<undef>")
183 typedef struct bfd_hash_entry *(*new_hash_entry_func)
184 (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
186 static struct bfd_link_hash_table *elf64_hppa_hash_table_create
189 /* This must follow the definitions of the various derived linker
190 hash tables and shared functions. */
191 #include "elf-hppa.h"
193 static bfd_boolean elf64_hppa_object_p
196 static void elf64_hppa_post_process_headers
197 (bfd *, struct bfd_link_info *);
199 static bfd_boolean elf64_hppa_create_dynamic_sections
200 (bfd *, struct bfd_link_info *);
202 static bfd_boolean elf64_hppa_adjust_dynamic_symbol
203 (struct bfd_link_info *, struct elf_link_hash_entry *);
205 static bfd_boolean elf64_hppa_mark_milli_and_exported_functions
206 (struct elf_link_hash_entry *, void *);
208 static bfd_boolean elf64_hppa_size_dynamic_sections
209 (bfd *, struct bfd_link_info *);
211 static bfd_boolean elf64_hppa_link_output_symbol_hook
212 (struct bfd_link_info *, const char *, Elf_Internal_Sym *,
213 asection *, struct elf_link_hash_entry *);
215 static bfd_boolean elf64_hppa_finish_dynamic_symbol
216 (bfd *, struct bfd_link_info *,
217 struct elf_link_hash_entry *, Elf_Internal_Sym *);
219 static enum elf_reloc_type_class elf64_hppa_reloc_type_class
220 (const Elf_Internal_Rela *);
222 static bfd_boolean elf64_hppa_finish_dynamic_sections
223 (bfd *, struct bfd_link_info *);
225 static bfd_boolean elf64_hppa_check_relocs
226 (bfd *, struct bfd_link_info *,
227 asection *, const Elf_Internal_Rela *);
229 static bfd_boolean elf64_hppa_dynamic_symbol_p
230 (struct elf_link_hash_entry *, struct bfd_link_info *);
232 static bfd_boolean elf64_hppa_mark_exported_functions
233 (struct elf_link_hash_entry *, void *);
235 static bfd_boolean elf64_hppa_finalize_opd
236 (struct elf_link_hash_entry *, void *);
238 static bfd_boolean elf64_hppa_finalize_dlt
239 (struct elf_link_hash_entry *, void *);
241 static bfd_boolean allocate_global_data_dlt
242 (struct elf_link_hash_entry *, void *);
244 static bfd_boolean allocate_global_data_plt
245 (struct elf_link_hash_entry *, void *);
247 static bfd_boolean allocate_global_data_stub
248 (struct elf_link_hash_entry *, void *);
250 static bfd_boolean allocate_global_data_opd
251 (struct elf_link_hash_entry *, void *);
253 static bfd_boolean get_reloc_section
254 (bfd *, struct elf64_hppa_link_hash_table *, asection *);
256 static bfd_boolean count_dyn_reloc
257 (bfd *, struct elf64_hppa_link_hash_entry *,
258 int, asection *, int, bfd_vma, bfd_vma);
260 static bfd_boolean allocate_dynrel_entries
261 (struct elf_link_hash_entry *, void *);
263 static bfd_boolean elf64_hppa_finalize_dynreloc
264 (struct elf_link_hash_entry *, void *);
266 static bfd_boolean get_opd
267 (bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *);
269 static bfd_boolean get_plt
270 (bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *);
272 static bfd_boolean get_dlt
273 (bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *);
275 static bfd_boolean get_stub
276 (bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *);
278 static int elf64_hppa_elf_get_symbol_type
279 (Elf_Internal_Sym *, int);
281 /* Initialize an entry in the link hash table. */
283 static struct bfd_hash_entry *
284 hppa64_link_hash_newfunc (struct bfd_hash_entry *entry,
285 struct bfd_hash_table *table,
288 /* Allocate the structure if it has not already been allocated by a
292 entry = bfd_hash_allocate (table,
293 sizeof (struct elf64_hppa_link_hash_entry));
298 /* Call the allocation method of the superclass. */
299 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
302 struct elf64_hppa_link_hash_entry *hh;
304 /* Initialize our local data. All zeros. */
305 hh = hppa_elf_hash_entry (entry);
306 memset (&hh->dlt_offset, 0,
307 (sizeof (struct elf64_hppa_link_hash_entry)
308 - offsetof (struct elf64_hppa_link_hash_entry, dlt_offset)));
314 /* Create the derived linker hash table. The PA64 ELF port uses this
315 derived hash table to keep information specific to the PA ElF
316 linker (without using static variables). */
318 static struct bfd_link_hash_table*
319 elf64_hppa_hash_table_create (bfd *abfd)
321 struct elf64_hppa_link_hash_table *htab;
322 bfd_size_type amt = sizeof (*htab);
324 htab = bfd_zalloc (abfd, amt);
328 if (!_bfd_elf_link_hash_table_init (&htab->root, abfd,
329 hppa64_link_hash_newfunc,
330 sizeof (struct elf64_hppa_link_hash_entry)))
332 bfd_release (abfd, htab);
336 htab->text_segment_base = (bfd_vma) -1;
337 htab->data_segment_base = (bfd_vma) -1;
339 return &htab->root.root;
342 /* Return nonzero if ABFD represents a PA2.0 ELF64 file.
344 Additionally we set the default architecture and machine. */
346 elf64_hppa_object_p (bfd *abfd)
348 Elf_Internal_Ehdr * i_ehdrp;
351 i_ehdrp = elf_elfheader (abfd);
352 if (strcmp (bfd_get_target (abfd), "elf64-hppa-linux") == 0)
354 /* GCC on hppa-linux produces binaries with OSABI=Linux,
355 but the kernel produces corefiles with OSABI=SysV. */
356 if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_LINUX
357 && i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_NONE) /* aka SYSV */
362 /* HPUX produces binaries with OSABI=HPUX,
363 but the kernel produces corefiles with OSABI=SysV. */
364 if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_HPUX
365 && i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_NONE) /* aka SYSV */
369 flags = i_ehdrp->e_flags;
370 switch (flags & (EF_PARISC_ARCH | EF_PARISC_WIDE))
373 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 10);
375 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 11);
377 if (i_ehdrp->e_ident[EI_CLASS] == ELFCLASS64)
378 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 25);
380 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 20);
381 case EFA_PARISC_2_0 | EF_PARISC_WIDE:
382 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 25);
384 /* Don't be fussy. */
388 /* Given section type (hdr->sh_type), return a boolean indicating
389 whether or not the section is an elf64-hppa specific section. */
391 elf64_hppa_section_from_shdr (bfd *abfd,
392 Elf_Internal_Shdr *hdr,
398 switch (hdr->sh_type)
401 if (strcmp (name, ".PARISC.archext") != 0)
404 case SHT_PARISC_UNWIND:
405 if (strcmp (name, ".PARISC.unwind") != 0)
409 case SHT_PARISC_ANNOT:
414 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
416 newsect = hdr->bfd_section;
421 /* SEC is a section containing relocs for an input BFD when linking; return
422 a suitable section for holding relocs in the output BFD for a link. */
425 get_reloc_section (bfd *abfd,
426 struct elf64_hppa_link_hash_table *hppa_info,
429 const char *srel_name;
433 srel_name = (bfd_elf_string_from_elf_section
434 (abfd, elf_elfheader(abfd)->e_shstrndx,
435 elf_section_data(sec)->rel_hdr.sh_name));
436 if (srel_name == NULL)
439 BFD_ASSERT ((CONST_STRNEQ (srel_name, ".rela")
440 && strcmp (bfd_get_section_name (abfd, sec),
442 || (CONST_STRNEQ (srel_name, ".rel")
443 && strcmp (bfd_get_section_name (abfd, sec),
444 srel_name + 4) == 0));
446 dynobj = hppa_info->root.dynobj;
448 hppa_info->root.dynobj = dynobj = abfd;
450 srel = bfd_get_section_by_name (dynobj, srel_name);
453 srel = bfd_make_section_with_flags (dynobj, srel_name,
461 || !bfd_set_section_alignment (dynobj, srel, 3))
465 hppa_info->other_rel_sec = srel;
469 /* Add a new entry to the list of dynamic relocations against DYN_H.
471 We use this to keep a record of all the FPTR relocations against a
472 particular symbol so that we can create FPTR relocations in the
476 count_dyn_reloc (bfd *abfd,
477 struct elf64_hppa_link_hash_entry *hh,
484 struct elf64_hppa_dyn_reloc_entry *rent;
486 rent = (struct elf64_hppa_dyn_reloc_entry *)
487 bfd_alloc (abfd, (bfd_size_type) sizeof (*rent));
491 rent->next = hh->reloc_entries;
494 rent->sec_symndx = sec_symndx;
495 rent->offset = offset;
496 rent->addend = addend;
497 hh->reloc_entries = rent;
502 /* Return a pointer to the local DLT, PLT and OPD reference counts
503 for ABFD. Returns NULL if the storage allocation fails. */
505 static bfd_signed_vma *
506 hppa64_elf_local_refcounts (bfd *abfd)
508 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
509 bfd_signed_vma *local_refcounts;
511 local_refcounts = elf_local_got_refcounts (abfd);
512 if (local_refcounts == NULL)
516 /* Allocate space for local DLT, PLT and OPD reference
517 counts. Done this way to save polluting elf_obj_tdata
518 with another target specific pointer. */
519 size = symtab_hdr->sh_info;
520 size *= 3 * sizeof (bfd_signed_vma);
521 local_refcounts = bfd_zalloc (abfd, size);
522 elf_local_got_refcounts (abfd) = local_refcounts;
524 return local_refcounts;
527 /* Scan the RELOCS and record the type of dynamic entries that each
528 referenced symbol needs. */
531 elf64_hppa_check_relocs (bfd *abfd,
532 struct bfd_link_info *info,
534 const Elf_Internal_Rela *relocs)
536 struct elf64_hppa_link_hash_table *hppa_info;
537 const Elf_Internal_Rela *relend;
538 Elf_Internal_Shdr *symtab_hdr;
539 const Elf_Internal_Rela *rel;
540 asection *dlt, *plt, *stubs;
543 unsigned int sec_symndx;
545 if (info->relocatable)
548 /* If this is the first dynamic object found in the link, create
549 the special sections required for dynamic linking. */
550 if (! elf_hash_table (info)->dynamic_sections_created)
552 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
556 hppa_info = hppa_link_hash_table (info);
557 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
559 /* If necessary, build a new table holding section symbols indices
562 if (info->shared && hppa_info->section_syms_bfd != abfd)
565 unsigned int highest_shndx;
566 Elf_Internal_Sym *local_syms = NULL;
567 Elf_Internal_Sym *isym, *isymend;
570 /* We're done with the old cache of section index to section symbol
571 index information. Free it.
573 ?!? Note we leak the last section_syms array. Presumably we
574 could free it in one of the later routines in this file. */
575 if (hppa_info->section_syms)
576 free (hppa_info->section_syms);
578 /* Read this BFD's local symbols. */
579 if (symtab_hdr->sh_info != 0)
581 local_syms = (Elf_Internal_Sym *) symtab_hdr->contents;
582 if (local_syms == NULL)
583 local_syms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
584 symtab_hdr->sh_info, 0,
586 if (local_syms == NULL)
590 /* Record the highest section index referenced by the local symbols. */
592 isymend = local_syms + symtab_hdr->sh_info;
593 for (isym = local_syms; isym < isymend; isym++)
595 if (isym->st_shndx > highest_shndx
596 && isym->st_shndx < SHN_LORESERVE)
597 highest_shndx = isym->st_shndx;
600 /* Allocate an array to hold the section index to section symbol index
601 mapping. Bump by one since we start counting at zero. */
605 hppa_info->section_syms = (int *) bfd_malloc (amt);
607 /* Now walk the local symbols again. If we find a section symbol,
608 record the index of the symbol into the section_syms array. */
609 for (i = 0, isym = local_syms; isym < isymend; i++, isym++)
611 if (ELF_ST_TYPE (isym->st_info) == STT_SECTION)
612 hppa_info->section_syms[isym->st_shndx] = i;
615 /* We are finished with the local symbols. */
616 if (local_syms != NULL
617 && symtab_hdr->contents != (unsigned char *) local_syms)
619 if (! info->keep_memory)
623 /* Cache the symbols for elf_link_input_bfd. */
624 symtab_hdr->contents = (unsigned char *) local_syms;
628 /* Record which BFD we built the section_syms mapping for. */
629 hppa_info->section_syms_bfd = abfd;
632 /* Record the symbol index for this input section. We may need it for
633 relocations when building shared libraries. When not building shared
634 libraries this value is never really used, but assign it to zero to
635 prevent out of bounds memory accesses in other routines. */
638 sec_symndx = _bfd_elf_section_from_bfd_section (abfd, sec);
640 /* If we did not find a section symbol for this section, then
641 something went terribly wrong above. */
642 if (sec_symndx == SHN_BAD)
645 if (sec_symndx < SHN_LORESERVE)
646 sec_symndx = hppa_info->section_syms[sec_symndx];
653 dlt = plt = stubs = NULL;
657 relend = relocs + sec->reloc_count;
658 for (rel = relocs; rel < relend; ++rel)
669 unsigned long r_symndx = ELF64_R_SYM (rel->r_info);
670 struct elf64_hppa_link_hash_entry *hh;
672 bfd_boolean maybe_dynamic;
673 int dynrel_type = R_PARISC_NONE;
674 static reloc_howto_type *howto;
676 if (r_symndx >= symtab_hdr->sh_info)
678 /* We're dealing with a global symbol -- find its hash entry
679 and mark it as being referenced. */
680 long indx = r_symndx - symtab_hdr->sh_info;
681 hh = hppa_elf_hash_entry (elf_sym_hashes (abfd)[indx]);
682 while (hh->eh.root.type == bfd_link_hash_indirect
683 || hh->eh.root.type == bfd_link_hash_warning)
684 hh = hppa_elf_hash_entry (hh->eh.root.u.i.link);
686 hh->eh.ref_regular = 1;
691 /* We can only get preliminary data on whether a symbol is
692 locally or externally defined, as not all of the input files
693 have yet been processed. Do something with what we know, as
694 this may help reduce memory usage and processing time later. */
695 maybe_dynamic = FALSE;
696 if (hh && ((info->shared
698 || info->unresolved_syms_in_shared_libs == RM_IGNORE))
699 || !hh->eh.def_regular
700 || hh->eh.root.type == bfd_link_hash_defweak))
701 maybe_dynamic = TRUE;
703 howto = elf_hppa_howto_table + ELF64_R_TYPE (rel->r_info);
707 /* These are simple indirect references to symbols through the
708 DLT. We need to create a DLT entry for any symbols which
709 appears in a DLTIND relocation. */
710 case R_PARISC_DLTIND21L:
711 case R_PARISC_DLTIND14R:
712 case R_PARISC_DLTIND14F:
713 case R_PARISC_DLTIND14WR:
714 case R_PARISC_DLTIND14DR:
715 need_entry = NEED_DLT;
718 /* ?!? These need a DLT entry. But I have no idea what to do with
719 the "link time TP value. */
720 case R_PARISC_LTOFF_TP21L:
721 case R_PARISC_LTOFF_TP14R:
722 case R_PARISC_LTOFF_TP14F:
723 case R_PARISC_LTOFF_TP64:
724 case R_PARISC_LTOFF_TP14WR:
725 case R_PARISC_LTOFF_TP14DR:
726 case R_PARISC_LTOFF_TP16F:
727 case R_PARISC_LTOFF_TP16WF:
728 case R_PARISC_LTOFF_TP16DF:
729 need_entry = NEED_DLT;
732 /* These are function calls. Depending on their precise target we
733 may need to make a stub for them. The stub uses the PLT, so we
734 need to create PLT entries for these symbols too. */
735 case R_PARISC_PCREL12F:
736 case R_PARISC_PCREL17F:
737 case R_PARISC_PCREL22F:
738 case R_PARISC_PCREL32:
739 case R_PARISC_PCREL64:
740 case R_PARISC_PCREL21L:
741 case R_PARISC_PCREL17R:
742 case R_PARISC_PCREL17C:
743 case R_PARISC_PCREL14R:
744 case R_PARISC_PCREL14F:
745 case R_PARISC_PCREL22C:
746 case R_PARISC_PCREL14WR:
747 case R_PARISC_PCREL14DR:
748 case R_PARISC_PCREL16F:
749 case R_PARISC_PCREL16WF:
750 case R_PARISC_PCREL16DF:
751 /* Function calls might need to go through the .plt, and
752 might need a long branch stub. */
753 if (hh != NULL && hh->eh.type != STT_PARISC_MILLI)
754 need_entry = (NEED_PLT | NEED_STUB);
759 case R_PARISC_PLTOFF21L:
760 case R_PARISC_PLTOFF14R:
761 case R_PARISC_PLTOFF14F:
762 case R_PARISC_PLTOFF14WR:
763 case R_PARISC_PLTOFF14DR:
764 case R_PARISC_PLTOFF16F:
765 case R_PARISC_PLTOFF16WF:
766 case R_PARISC_PLTOFF16DF:
767 need_entry = (NEED_PLT);
771 if (info->shared || maybe_dynamic)
772 need_entry = (NEED_DYNREL);
773 dynrel_type = R_PARISC_DIR64;
776 /* This is an indirect reference through the DLT to get the address
777 of a OPD descriptor. Thus we need to make a DLT entry that points
779 case R_PARISC_LTOFF_FPTR21L:
780 case R_PARISC_LTOFF_FPTR14R:
781 case R_PARISC_LTOFF_FPTR14WR:
782 case R_PARISC_LTOFF_FPTR14DR:
783 case R_PARISC_LTOFF_FPTR32:
784 case R_PARISC_LTOFF_FPTR64:
785 case R_PARISC_LTOFF_FPTR16F:
786 case R_PARISC_LTOFF_FPTR16WF:
787 case R_PARISC_LTOFF_FPTR16DF:
788 if (info->shared || maybe_dynamic)
789 need_entry = (NEED_DLT | NEED_OPD | NEED_PLT);
791 need_entry = (NEED_DLT | NEED_OPD | NEED_PLT);
792 dynrel_type = R_PARISC_FPTR64;
795 /* This is a simple OPD entry. */
796 case R_PARISC_FPTR64:
797 if (info->shared || maybe_dynamic)
798 need_entry = (NEED_OPD | NEED_PLT | NEED_DYNREL);
800 need_entry = (NEED_OPD | NEED_PLT);
801 dynrel_type = R_PARISC_FPTR64;
804 /* Add more cases as needed. */
812 /* Stash away enough information to be able to find this symbol
813 regardless of whether or not it is local or global. */
815 hh->sym_indx = r_symndx;
818 /* Create what's needed. */
819 if (need_entry & NEED_DLT)
821 /* Allocate space for a DLT entry, as well as a dynamic
822 relocation for this entry. */
823 if (! hppa_info->dlt_sec
824 && ! get_dlt (abfd, info, hppa_info))
830 hh->eh.got.refcount += 1;
834 bfd_signed_vma *local_dlt_refcounts;
836 /* This is a DLT entry for a local symbol. */
837 local_dlt_refcounts = hppa64_elf_local_refcounts (abfd);
838 if (local_dlt_refcounts == NULL)
840 local_dlt_refcounts[r_symndx] += 1;
844 if (need_entry & NEED_PLT)
846 if (! hppa_info->plt_sec
847 && ! get_plt (abfd, info, hppa_info))
853 hh->eh.needs_plt = 1;
854 hh->eh.plt.refcount += 1;
858 bfd_signed_vma *local_dlt_refcounts;
859 bfd_signed_vma *local_plt_refcounts;
861 /* This is a PLT entry for a local symbol. */
862 local_dlt_refcounts = hppa64_elf_local_refcounts (abfd);
863 if (local_dlt_refcounts == NULL)
865 local_plt_refcounts = local_dlt_refcounts + symtab_hdr->sh_info;
866 local_plt_refcounts[r_symndx] += 1;
870 if (need_entry & NEED_STUB)
872 if (! hppa_info->stub_sec
873 && ! get_stub (abfd, info, hppa_info))
879 if (need_entry & NEED_OPD)
881 if (! hppa_info->opd_sec
882 && ! get_opd (abfd, info, hppa_info))
885 /* FPTRs are not allocated by the dynamic linker for PA64,
886 though it is possible that will change in the future. */
892 bfd_signed_vma *local_dlt_refcounts;
893 bfd_signed_vma *local_opd_refcounts;
895 /* This is a OPD for a local symbol. */
896 local_dlt_refcounts = hppa64_elf_local_refcounts (abfd);
897 if (local_dlt_refcounts == NULL)
899 local_opd_refcounts = (local_dlt_refcounts
900 + 2 * symtab_hdr->sh_info);
901 local_opd_refcounts[r_symndx] += 1;
905 /* Add a new dynamic relocation to the chain of dynamic
906 relocations for this symbol. */
907 if ((need_entry & NEED_DYNREL) && (sec->flags & SEC_ALLOC))
909 if (! hppa_info->other_rel_sec
910 && ! get_reloc_section (abfd, hppa_info, sec))
913 /* Count dynamic relocations against global symbols. */
915 && !count_dyn_reloc (abfd, hh, dynrel_type, sec,
916 sec_symndx, rel->r_offset, rel->r_addend))
919 /* If we are building a shared library and we just recorded
920 a dynamic R_PARISC_FPTR64 relocation, then make sure the
921 section symbol for this section ends up in the dynamic
923 if (info->shared && dynrel_type == R_PARISC_FPTR64
924 && ! (bfd_elf_link_record_local_dynamic_symbol
925 (info, abfd, sec_symndx)))
940 struct elf64_hppa_allocate_data
942 struct bfd_link_info *info;
946 /* Should we do dynamic things to this symbol? */
949 elf64_hppa_dynamic_symbol_p (struct elf_link_hash_entry *eh,
950 struct bfd_link_info *info)
952 /* ??? What, if anything, needs to happen wrt STV_PROTECTED symbols
953 and relocations that retrieve a function descriptor? Assume the
955 if (_bfd_elf_dynamic_symbol_p (eh, info, 1))
957 /* ??? Why is this here and not elsewhere is_local_label_name. */
958 if (eh->root.root.string[0] == '$' && eh->root.root.string[1] == '$')
967 /* Mark all functions exported by this file so that we can later allocate
968 entries in .opd for them. */
971 elf64_hppa_mark_exported_functions (struct elf_link_hash_entry *eh, void *data)
973 struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
974 struct bfd_link_info *info = (struct bfd_link_info *)data;
975 struct elf64_hppa_link_hash_table *hppa_info;
977 hppa_info = hppa_link_hash_table (info);
979 if (eh->root.type == bfd_link_hash_warning)
980 eh = (struct elf_link_hash_entry *) eh->root.u.i.link;
983 && (eh->root.type == bfd_link_hash_defined
984 || eh->root.type == bfd_link_hash_defweak)
985 && eh->root.u.def.section->output_section != NULL
986 && eh->type == STT_FUNC)
988 if (! hppa_info->opd_sec
989 && ! get_opd (hppa_info->root.dynobj, info, hppa_info))
994 /* Put a flag here for output_symbol_hook. */
1002 /* Allocate space for a DLT entry. */
1005 allocate_global_data_dlt (struct elf_link_hash_entry *eh, void *data)
1007 struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
1008 struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data;
1012 if (x->info->shared)
1014 /* Possibly add the symbol to the local dynamic symbol
1015 table since we might need to create a dynamic relocation
1017 if (eh->dynindx == -1 && eh->type != STT_PARISC_MILLI)
1019 bfd *owner = eh->root.u.def.section->owner;
1021 if (! (bfd_elf_link_record_local_dynamic_symbol
1022 (x->info, owner, hh->sym_indx)))
1027 hh->dlt_offset = x->ofs;
1028 x->ofs += DLT_ENTRY_SIZE;
1033 /* Allocate space for a DLT.PLT entry. */
1036 allocate_global_data_plt (struct elf_link_hash_entry *eh, void *data)
1038 struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
1039 struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data;
1042 && elf64_hppa_dynamic_symbol_p (eh, x->info)
1043 && !((eh->root.type == bfd_link_hash_defined
1044 || eh->root.type == bfd_link_hash_defweak)
1045 && eh->root.u.def.section->output_section != NULL))
1047 hh->plt_offset = x->ofs;
1048 x->ofs += PLT_ENTRY_SIZE;
1049 if (hh->plt_offset < 0x2000)
1050 hppa_link_hash_table (x->info)->gp_offset = hh->plt_offset;
1058 /* Allocate space for a STUB entry. */
1061 allocate_global_data_stub (struct elf_link_hash_entry *eh, void *data)
1063 struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
1064 struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data;
1067 && elf64_hppa_dynamic_symbol_p (eh, x->info)
1068 && !((eh->root.type == bfd_link_hash_defined
1069 || eh->root.type == bfd_link_hash_defweak)
1070 && eh->root.u.def.section->output_section != NULL))
1072 hh->stub_offset = x->ofs;
1073 x->ofs += sizeof (plt_stub);
1080 /* Allocate space for a FPTR entry. */
1083 allocate_global_data_opd (struct elf_link_hash_entry *eh, void *data)
1085 struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
1086 struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data;
1088 if (hh && hh->want_opd)
1090 while (hh->eh.root.type == bfd_link_hash_indirect
1091 || hh->eh.root.type == bfd_link_hash_warning)
1092 hh = hppa_elf_hash_entry (hh->eh.root.u.i.link);
1094 /* We never need an opd entry for a symbol which is not
1095 defined by this output file. */
1096 if (hh && (hh->eh.root.type == bfd_link_hash_undefined
1097 || hh->eh.root.type == bfd_link_hash_undefweak
1098 || hh->eh.root.u.def.section->output_section == NULL))
1101 /* If we are creating a shared library, took the address of a local
1102 function or might export this function from this object file, then
1103 we have to create an opd descriptor. */
1104 else if (x->info->shared
1106 || (hh->eh.dynindx == -1 && hh->eh.type != STT_PARISC_MILLI)
1107 || (hh->eh.root.type == bfd_link_hash_defined
1108 || hh->eh.root.type == bfd_link_hash_defweak))
1110 /* If we are creating a shared library, then we will have to
1111 create a runtime relocation for the symbol to properly
1112 initialize the .opd entry. Make sure the symbol gets
1113 added to the dynamic symbol table. */
1115 && (hh == NULL || (hh->eh.dynindx == -1)))
1118 /* PR 6511: Default to using the dynamic symbol table. */
1119 owner = (hh->owner ? hh->owner: eh->root.u.def.section->owner);
1121 if (!bfd_elf_link_record_local_dynamic_symbol
1122 (x->info, owner, hh->sym_indx))
1126 /* This may not be necessary or desirable anymore now that
1127 we have some support for dealing with section symbols
1128 in dynamic relocs. But name munging does make the result
1129 much easier to debug. ie, the EPLT reloc will reference
1130 a symbol like .foobar, instead of .text + offset. */
1131 if (x->info->shared && eh)
1134 struct elf_link_hash_entry *nh;
1136 new_name = alloca (strlen (eh->root.root.string) + 2);
1138 strcpy (new_name + 1, eh->root.root.string);
1140 nh = elf_link_hash_lookup (elf_hash_table (x->info),
1141 new_name, TRUE, TRUE, TRUE);
1143 nh->root.type = eh->root.type;
1144 nh->root.u.def.value = eh->root.u.def.value;
1145 nh->root.u.def.section = eh->root.u.def.section;
1147 if (! bfd_elf_link_record_dynamic_symbol (x->info, nh))
1151 hh->opd_offset = x->ofs;
1152 x->ofs += OPD_ENTRY_SIZE;
1155 /* Otherwise we do not need an opd entry. */
1162 /* HP requires the EI_OSABI field to be filled in. The assignment to
1163 EI_ABIVERSION may not be strictly necessary. */
1166 elf64_hppa_post_process_headers (bfd *abfd,
1167 struct bfd_link_info *link_info ATTRIBUTE_UNUSED)
1169 Elf_Internal_Ehdr * i_ehdrp;
1171 i_ehdrp = elf_elfheader (abfd);
1173 i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi;
1174 i_ehdrp->e_ident[EI_ABIVERSION] = 1;
1177 /* Create function descriptor section (.opd). This section is called .opd
1178 because it contains "official procedure descriptors". The "official"
1179 refers to the fact that these descriptors are used when taking the address
1180 of a procedure, thus ensuring a unique address for each procedure. */
1184 struct bfd_link_info *info ATTRIBUTE_UNUSED,
1185 struct elf64_hppa_link_hash_table *hppa_info)
1190 opd = hppa_info->opd_sec;
1193 dynobj = hppa_info->root.dynobj;
1195 hppa_info->root.dynobj = dynobj = abfd;
1197 opd = bfd_make_section_with_flags (dynobj, ".opd",
1202 | SEC_LINKER_CREATED));
1204 || !bfd_set_section_alignment (abfd, opd, 3))
1210 hppa_info->opd_sec = opd;
1216 /* Create the PLT section. */
1220 struct bfd_link_info *info ATTRIBUTE_UNUSED,
1221 struct elf64_hppa_link_hash_table *hppa_info)
1226 plt = hppa_info->plt_sec;
1229 dynobj = hppa_info->root.dynobj;
1231 hppa_info->root.dynobj = dynobj = abfd;
1233 plt = bfd_make_section_with_flags (dynobj, ".plt",
1238 | SEC_LINKER_CREATED));
1240 || !bfd_set_section_alignment (abfd, plt, 3))
1246 hppa_info->plt_sec = plt;
1252 /* Create the DLT section. */
1256 struct bfd_link_info *info ATTRIBUTE_UNUSED,
1257 struct elf64_hppa_link_hash_table *hppa_info)
1262 dlt = hppa_info->dlt_sec;
1265 dynobj = hppa_info->root.dynobj;
1267 hppa_info->root.dynobj = dynobj = abfd;
1269 dlt = bfd_make_section_with_flags (dynobj, ".dlt",
1274 | SEC_LINKER_CREATED));
1276 || !bfd_set_section_alignment (abfd, dlt, 3))
1282 hppa_info->dlt_sec = dlt;
1288 /* Create the stubs section. */
1291 get_stub (bfd *abfd,
1292 struct bfd_link_info *info ATTRIBUTE_UNUSED,
1293 struct elf64_hppa_link_hash_table *hppa_info)
1298 stub = hppa_info->stub_sec;
1301 dynobj = hppa_info->root.dynobj;
1303 hppa_info->root.dynobj = dynobj = abfd;
1305 stub = bfd_make_section_with_flags (dynobj, ".stub",
1306 (SEC_ALLOC | SEC_LOAD
1310 | SEC_LINKER_CREATED));
1312 || !bfd_set_section_alignment (abfd, stub, 3))
1318 hppa_info->stub_sec = stub;
1324 /* Create sections necessary for dynamic linking. This is only a rough
1325 cut and will likely change as we learn more about the somewhat
1326 unusual dynamic linking scheme HP uses.
1329 Contains code to implement cross-space calls. The first time one
1330 of the stubs is used it will call into the dynamic linker, later
1331 calls will go straight to the target.
1333 The only stub we support right now looks like
1337 ldd OFFSET+8(%dp),%dp
1339 Other stubs may be needed in the future. We may want the remove
1340 the break/nop instruction. It is only used right now to keep the
1341 offset of a .plt entry and a .stub entry in sync.
1344 This is what most people call the .got. HP used a different name.
1348 Relocations for the DLT.
1351 Function pointers as address,gp pairs.
1354 Should contain dynamic IPLT (and EPLT?) relocations.
1360 EPLT relocations for symbols exported from shared libraries. */
1363 elf64_hppa_create_dynamic_sections (bfd *abfd,
1364 struct bfd_link_info *info)
1368 if (! get_stub (abfd, info, hppa_link_hash_table (info)))
1371 if (! get_dlt (abfd, info, hppa_link_hash_table (info)))
1374 if (! get_plt (abfd, info, hppa_link_hash_table (info)))
1377 if (! get_opd (abfd, info, hppa_link_hash_table (info)))
1380 s = bfd_make_section_with_flags (abfd, ".rela.dlt",
1381 (SEC_ALLOC | SEC_LOAD
1385 | SEC_LINKER_CREATED));
1387 || !bfd_set_section_alignment (abfd, s, 3))
1389 hppa_link_hash_table (info)->dlt_rel_sec = s;
1391 s = bfd_make_section_with_flags (abfd, ".rela.plt",
1392 (SEC_ALLOC | SEC_LOAD
1396 | SEC_LINKER_CREATED));
1398 || !bfd_set_section_alignment (abfd, s, 3))
1400 hppa_link_hash_table (info)->plt_rel_sec = s;
1402 s = bfd_make_section_with_flags (abfd, ".rela.data",
1403 (SEC_ALLOC | SEC_LOAD
1407 | SEC_LINKER_CREATED));
1409 || !bfd_set_section_alignment (abfd, s, 3))
1411 hppa_link_hash_table (info)->other_rel_sec = s;
1413 s = bfd_make_section_with_flags (abfd, ".rela.opd",
1414 (SEC_ALLOC | SEC_LOAD
1418 | SEC_LINKER_CREATED));
1420 || !bfd_set_section_alignment (abfd, s, 3))
1422 hppa_link_hash_table (info)->opd_rel_sec = s;
1427 /* Allocate dynamic relocations for those symbols that turned out
1431 allocate_dynrel_entries (struct elf_link_hash_entry *eh, void *data)
1433 struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
1434 struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data;
1435 struct elf64_hppa_link_hash_table *hppa_info;
1436 struct elf64_hppa_dyn_reloc_entry *rent;
1437 bfd_boolean dynamic_symbol, shared;
1439 hppa_info = hppa_link_hash_table (x->info);
1440 dynamic_symbol = elf64_hppa_dynamic_symbol_p (eh, x->info);
1441 shared = x->info->shared;
1443 /* We may need to allocate relocations for a non-dynamic symbol
1444 when creating a shared library. */
1445 if (!dynamic_symbol && !shared)
1448 /* Take care of the normal data relocations. */
1450 for (rent = hh->reloc_entries; rent; rent = rent->next)
1452 /* Allocate one iff we are building a shared library, the relocation
1453 isn't a R_PARISC_FPTR64, or we don't want an opd entry. */
1454 if (!shared && rent->type == R_PARISC_FPTR64 && hh->want_opd)
1457 hppa_info->other_rel_sec->size += sizeof (Elf64_External_Rela);
1459 /* Make sure this symbol gets into the dynamic symbol table if it is
1460 not already recorded. ?!? This should not be in the loop since
1461 the symbol need only be added once. */
1462 if (eh->dynindx == -1 && eh->type != STT_PARISC_MILLI)
1463 if (!bfd_elf_link_record_local_dynamic_symbol
1464 (x->info, rent->sec->owner, hh->sym_indx))
1468 /* Take care of the GOT and PLT relocations. */
1470 if ((dynamic_symbol || shared) && hh->want_dlt)
1471 hppa_info->dlt_rel_sec->size += sizeof (Elf64_External_Rela);
1473 /* If we are building a shared library, then every symbol that has an
1474 opd entry will need an EPLT relocation to relocate the symbol's address
1475 and __gp value based on the runtime load address. */
1476 if (shared && hh->want_opd)
1477 hppa_info->opd_rel_sec->size += sizeof (Elf64_External_Rela);
1479 if (hh->want_plt && dynamic_symbol)
1481 bfd_size_type t = 0;
1483 /* Dynamic symbols get one IPLT relocation. Local symbols in
1484 shared libraries get two REL relocations. Local symbols in
1485 main applications get nothing. */
1487 t = sizeof (Elf64_External_Rela);
1489 t = 2 * sizeof (Elf64_External_Rela);
1491 hppa_info->plt_rel_sec->size += t;
1497 /* Adjust a symbol defined by a dynamic object and referenced by a
1501 elf64_hppa_adjust_dynamic_symbol (struct bfd_link_info *info ATTRIBUTE_UNUSED,
1502 struct elf_link_hash_entry *eh)
1504 /* ??? Undefined symbols with PLT entries should be re-defined
1505 to be the PLT entry. */
1507 /* If this is a weak symbol, and there is a real definition, the
1508 processor independent code will have arranged for us to see the
1509 real definition first, and we can just use the same value. */
1510 if (eh->u.weakdef != NULL)
1512 BFD_ASSERT (eh->u.weakdef->root.type == bfd_link_hash_defined
1513 || eh->u.weakdef->root.type == bfd_link_hash_defweak);
1514 eh->root.u.def.section = eh->u.weakdef->root.u.def.section;
1515 eh->root.u.def.value = eh->u.weakdef->root.u.def.value;
1519 /* If this is a reference to a symbol defined by a dynamic object which
1520 is not a function, we might allocate the symbol in our .dynbss section
1521 and allocate a COPY dynamic relocation.
1523 But PA64 code is canonically PIC, so as a rule we can avoid this sort
1529 /* This function is called via elf_link_hash_traverse to mark millicode
1530 symbols with a dynindx of -1 and to remove the string table reference
1531 from the dynamic symbol table. If the symbol is not a millicode symbol,
1532 elf64_hppa_mark_exported_functions is called. */
1535 elf64_hppa_mark_milli_and_exported_functions (struct elf_link_hash_entry *eh,
1538 struct elf_link_hash_entry *elf = eh;
1539 struct bfd_link_info *info = (struct bfd_link_info *)data;
1541 if (elf->root.type == bfd_link_hash_warning)
1542 elf = (struct elf_link_hash_entry *) elf->root.u.i.link;
1544 if (elf->type == STT_PARISC_MILLI)
1546 if (elf->dynindx != -1)
1549 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
1555 return elf64_hppa_mark_exported_functions (eh, data);
1558 /* Set the final sizes of the dynamic sections and allocate memory for
1559 the contents of our special sections. */
1562 elf64_hppa_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
1564 struct elf64_hppa_link_hash_table *hppa_info;
1565 struct elf64_hppa_allocate_data data;
1571 bfd_boolean reltext;
1573 hppa_info = hppa_link_hash_table (info);
1575 dynobj = elf_hash_table (info)->dynobj;
1576 BFD_ASSERT (dynobj != NULL);
1578 /* Mark each function this program exports so that we will allocate
1579 space in the .opd section for each function's FPTR. If we are
1580 creating dynamic sections, change the dynamic index of millicode
1581 symbols to -1 and remove them from the string table for .dynstr.
1583 We have to traverse the main linker hash table since we have to
1584 find functions which may not have been mentioned in any relocs. */
1585 elf_link_hash_traverse (elf_hash_table (info),
1586 (elf_hash_table (info)->dynamic_sections_created
1587 ? elf64_hppa_mark_milli_and_exported_functions
1588 : elf64_hppa_mark_exported_functions),
1591 if (elf_hash_table (info)->dynamic_sections_created)
1593 /* Set the contents of the .interp section to the interpreter. */
1594 if (info->executable)
1596 sec = bfd_get_section_by_name (dynobj, ".interp");
1597 BFD_ASSERT (sec != NULL);
1598 sec->size = sizeof ELF_DYNAMIC_INTERPRETER;
1599 sec->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
1604 /* We may have created entries in the .rela.got section.
1605 However, if we are not creating the dynamic sections, we will
1606 not actually use these entries. Reset the size of .rela.dlt,
1607 which will cause it to get stripped from the output file
1609 sec = bfd_get_section_by_name (dynobj, ".rela.dlt");
1614 /* Set up DLT, PLT and OPD offsets for local syms, and space for local
1616 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
1618 bfd_signed_vma *local_dlt;
1619 bfd_signed_vma *end_local_dlt;
1620 bfd_signed_vma *local_plt;
1621 bfd_signed_vma *end_local_plt;
1622 bfd_signed_vma *local_opd;
1623 bfd_signed_vma *end_local_opd;
1624 bfd_size_type locsymcount;
1625 Elf_Internal_Shdr *symtab_hdr;
1628 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
1631 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
1633 struct elf64_hppa_dyn_reloc_entry *hdh_p;
1635 for (hdh_p = ((struct elf64_hppa_dyn_reloc_entry *)
1636 elf_section_data (sec)->local_dynrel);
1638 hdh_p = hdh_p->next)
1640 if (!bfd_is_abs_section (hdh_p->sec)
1641 && bfd_is_abs_section (hdh_p->sec->output_section))
1643 /* Input section has been discarded, either because
1644 it is a copy of a linkonce section or due to
1645 linker script /DISCARD/, so we'll be discarding
1648 else if (hdh_p->count != 0)
1650 srel = elf_section_data (hdh_p->sec)->sreloc;
1651 srel->size += hdh_p->count * sizeof (Elf64_External_Rela);
1652 if ((hdh_p->sec->output_section->flags & SEC_READONLY) != 0)
1653 info->flags |= DF_TEXTREL;
1658 local_dlt = elf_local_got_refcounts (ibfd);
1662 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
1663 locsymcount = symtab_hdr->sh_info;
1664 end_local_dlt = local_dlt + locsymcount;
1665 sec = hppa_info->dlt_sec;
1666 srel = hppa_info->dlt_rel_sec;
1667 for (; local_dlt < end_local_dlt; ++local_dlt)
1671 *local_dlt = sec->size;
1672 sec->size += DLT_ENTRY_SIZE;
1675 srel->size += sizeof (Elf64_External_Rela);
1679 *local_dlt = (bfd_vma) -1;
1682 local_plt = end_local_dlt;
1683 end_local_plt = local_plt + locsymcount;
1684 if (! hppa_info->root.dynamic_sections_created)
1686 /* Won't be used, but be safe. */
1687 for (; local_plt < end_local_plt; ++local_plt)
1688 *local_plt = (bfd_vma) -1;
1692 sec = hppa_info->plt_sec;
1693 srel = hppa_info->plt_rel_sec;
1694 for (; local_plt < end_local_plt; ++local_plt)
1698 *local_plt = sec->size;
1699 sec->size += PLT_ENTRY_SIZE;
1701 srel->size += sizeof (Elf64_External_Rela);
1704 *local_plt = (bfd_vma) -1;
1708 local_opd = end_local_plt;
1709 end_local_opd = local_opd + locsymcount;
1710 if (! hppa_info->root.dynamic_sections_created)
1712 /* Won't be used, but be safe. */
1713 for (; local_opd < end_local_opd; ++local_opd)
1714 *local_opd = (bfd_vma) -1;
1718 sec = hppa_info->opd_sec;
1719 srel = hppa_info->opd_rel_sec;
1720 for (; local_opd < end_local_opd; ++local_opd)
1724 *local_opd = sec->size;
1725 sec->size += OPD_ENTRY_SIZE;
1727 srel->size += sizeof (Elf64_External_Rela);
1730 *local_opd = (bfd_vma) -1;
1735 /* Allocate the GOT entries. */
1738 if (hppa_info->dlt_sec)
1740 data.ofs = hppa_info->dlt_sec->size;
1741 elf_link_hash_traverse (elf_hash_table (info),
1742 allocate_global_data_dlt, &data);
1743 hppa_info->dlt_sec->size = data.ofs;
1746 if (hppa_info->plt_sec)
1748 data.ofs = hppa_info->plt_sec->size;
1749 elf_link_hash_traverse (elf_hash_table (info),
1750 allocate_global_data_plt, &data);
1751 hppa_info->plt_sec->size = data.ofs;
1754 if (hppa_info->stub_sec)
1757 elf_link_hash_traverse (elf_hash_table (info),
1758 allocate_global_data_stub, &data);
1759 hppa_info->stub_sec->size = data.ofs;
1762 /* Allocate space for entries in the .opd section. */
1763 if (hppa_info->opd_sec)
1765 data.ofs = hppa_info->opd_sec->size;
1766 elf_link_hash_traverse (elf_hash_table (info),
1767 allocate_global_data_opd, &data);
1768 hppa_info->opd_sec->size = data.ofs;
1771 /* Now allocate space for dynamic relocations, if necessary. */
1772 if (hppa_info->root.dynamic_sections_created)
1773 elf_link_hash_traverse (elf_hash_table (info),
1774 allocate_dynrel_entries, &data);
1776 /* The sizes of all the sections are set. Allocate memory for them. */
1780 for (sec = dynobj->sections; sec != NULL; sec = sec->next)
1784 if ((sec->flags & SEC_LINKER_CREATED) == 0)
1787 /* It's OK to base decisions on the section name, because none
1788 of the dynobj section names depend upon the input files. */
1789 name = bfd_get_section_name (dynobj, sec);
1791 if (strcmp (name, ".plt") == 0)
1793 /* Remember whether there is a PLT. */
1794 plt = sec->size != 0;
1796 else if (strcmp (name, ".opd") == 0
1797 || CONST_STRNEQ (name, ".dlt")
1798 || strcmp (name, ".stub") == 0
1799 || strcmp (name, ".got") == 0)
1801 /* Strip this section if we don't need it; see the comment below. */
1803 else if (CONST_STRNEQ (name, ".rela"))
1809 /* Remember whether there are any reloc sections other
1811 if (strcmp (name, ".rela.plt") != 0)
1813 const char *outname;
1817 /* If this relocation section applies to a read only
1818 section, then we probably need a DT_TEXTREL
1819 entry. The entries in the .rela.plt section
1820 really apply to the .got section, which we
1821 created ourselves and so know is not readonly. */
1822 outname = bfd_get_section_name (output_bfd,
1823 sec->output_section);
1824 target = bfd_get_section_by_name (output_bfd, outname + 4);
1826 && (target->flags & SEC_READONLY) != 0
1827 && (target->flags & SEC_ALLOC) != 0)
1831 /* We use the reloc_count field as a counter if we need
1832 to copy relocs into the output file. */
1833 sec->reloc_count = 0;
1838 /* It's not one of our sections, so don't allocate space. */
1844 /* If we don't need this section, strip it from the
1845 output file. This is mostly to handle .rela.bss and
1846 .rela.plt. We must create both sections in
1847 create_dynamic_sections, because they must be created
1848 before the linker maps input sections to output
1849 sections. The linker does that before
1850 adjust_dynamic_symbol is called, and it is that
1851 function which decides whether anything needs to go
1852 into these sections. */
1853 sec->flags |= SEC_EXCLUDE;
1857 if ((sec->flags & SEC_HAS_CONTENTS) == 0)
1860 /* Allocate memory for the section contents if it has not
1861 been allocated already. We use bfd_zalloc here in case
1862 unused entries are not reclaimed before the section's
1863 contents are written out. This should not happen, but this
1864 way if it does, we get a R_PARISC_NONE reloc instead of
1866 if (sec->contents == NULL)
1868 sec->contents = (bfd_byte *) bfd_zalloc (dynobj, sec->size);
1869 if (sec->contents == NULL)
1874 if (elf_hash_table (info)->dynamic_sections_created)
1876 /* Always create a DT_PLTGOT. It actually has nothing to do with
1877 the PLT, it is how we communicate the __gp value of a load
1878 module to the dynamic linker. */
1879 #define add_dynamic_entry(TAG, VAL) \
1880 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
1882 if (!add_dynamic_entry (DT_HP_DLD_FLAGS, 0)
1883 || !add_dynamic_entry (DT_PLTGOT, 0))
1886 /* Add some entries to the .dynamic section. We fill in the
1887 values later, in elf64_hppa_finish_dynamic_sections, but we
1888 must add the entries now so that we get the correct size for
1889 the .dynamic section. The DT_DEBUG entry is filled in by the
1890 dynamic linker and used by the debugger. */
1893 if (!add_dynamic_entry (DT_DEBUG, 0)
1894 || !add_dynamic_entry (DT_HP_DLD_HOOK, 0)
1895 || !add_dynamic_entry (DT_HP_LOAD_MAP, 0))
1899 /* Force DT_FLAGS to always be set.
1900 Required by HPUX 11.00 patch PHSS_26559. */
1901 if (!add_dynamic_entry (DT_FLAGS, (info)->flags))
1906 if (!add_dynamic_entry (DT_PLTRELSZ, 0)
1907 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
1908 || !add_dynamic_entry (DT_JMPREL, 0))
1914 if (!add_dynamic_entry (DT_RELA, 0)
1915 || !add_dynamic_entry (DT_RELASZ, 0)
1916 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
1922 if (!add_dynamic_entry (DT_TEXTREL, 0))
1924 info->flags |= DF_TEXTREL;
1927 #undef add_dynamic_entry
1932 /* Called after we have output the symbol into the dynamic symbol
1933 table, but before we output the symbol into the normal symbol
1936 For some symbols we had to change their address when outputting
1937 the dynamic symbol table. We undo that change here so that
1938 the symbols have their expected value in the normal symbol
1942 elf64_hppa_link_output_symbol_hook (struct bfd_link_info *info ATTRIBUTE_UNUSED,
1944 Elf_Internal_Sym *sym,
1945 asection *input_sec ATTRIBUTE_UNUSED,
1946 struct elf_link_hash_entry *eh)
1948 struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
1950 /* We may be called with the file symbol or section symbols.
1951 They never need munging, so it is safe to ignore them. */
1955 /* Function symbols for which we created .opd entries *may* have been
1956 munged by finish_dynamic_symbol and have to be un-munged here.
1958 Note that finish_dynamic_symbol sometimes turns dynamic symbols
1959 into non-dynamic ones, so we initialize st_shndx to -1 in
1960 mark_exported_functions and check to see if it was overwritten
1961 here instead of just checking eh->dynindx. */
1962 if (hh->want_opd && hh->st_shndx != -1)
1964 /* Restore the saved value and section index. */
1965 sym->st_value = hh->st_value;
1966 sym->st_shndx = hh->st_shndx;
1972 /* Finish up dynamic symbol handling. We set the contents of various
1973 dynamic sections here. */
1976 elf64_hppa_finish_dynamic_symbol (bfd *output_bfd,
1977 struct bfd_link_info *info,
1978 struct elf_link_hash_entry *eh,
1979 Elf_Internal_Sym *sym)
1981 struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
1982 asection *stub, *splt, *sdlt, *sopd, *spltrel, *sdltrel;
1983 struct elf64_hppa_link_hash_table *hppa_info;
1985 hppa_info = hppa_link_hash_table (info);
1987 stub = hppa_info->stub_sec;
1988 splt = hppa_info->plt_sec;
1989 sdlt = hppa_info->dlt_sec;
1990 sopd = hppa_info->opd_sec;
1991 spltrel = hppa_info->plt_rel_sec;
1992 sdltrel = hppa_info->dlt_rel_sec;
1994 /* Incredible. It is actually necessary to NOT use the symbol's real
1995 value when building the dynamic symbol table for a shared library.
1996 At least for symbols that refer to functions.
1998 We will store a new value and section index into the symbol long
1999 enough to output it into the dynamic symbol table, then we restore
2000 the original values (in elf64_hppa_link_output_symbol_hook). */
2003 BFD_ASSERT (sopd != NULL);
2005 /* Save away the original value and section index so that we
2006 can restore them later. */
2007 hh->st_value = sym->st_value;
2008 hh->st_shndx = sym->st_shndx;
2010 /* For the dynamic symbol table entry, we want the value to be
2011 address of this symbol's entry within the .opd section. */
2012 sym->st_value = (hh->opd_offset
2013 + sopd->output_offset
2014 + sopd->output_section->vma);
2015 sym->st_shndx = _bfd_elf_section_from_bfd_section (output_bfd,
2016 sopd->output_section);
2019 /* Initialize a .plt entry if requested. */
2021 && elf64_hppa_dynamic_symbol_p (eh, info))
2024 Elf_Internal_Rela rel;
2027 BFD_ASSERT (splt != NULL && spltrel != NULL);
2029 /* We do not actually care about the value in the PLT entry
2030 if we are creating a shared library and the symbol is
2031 still undefined, we create a dynamic relocation to fill
2032 in the correct value. */
2033 if (info->shared && eh->root.type == bfd_link_hash_undefined)
2036 value = (eh->root.u.def.value + eh->root.u.def.section->vma);
2038 /* Fill in the entry in the procedure linkage table.
2040 The format of a plt entry is
2043 plt_offset is the offset within the PLT section at which to
2044 install the PLT entry.
2046 We are modifying the in-memory PLT contents here, so we do not add
2047 in the output_offset of the PLT section. */
2049 bfd_put_64 (splt->owner, value, splt->contents + hh->plt_offset);
2050 value = _bfd_get_gp_value (splt->output_section->owner);
2051 bfd_put_64 (splt->owner, value, splt->contents + hh->plt_offset + 0x8);
2053 /* Create a dynamic IPLT relocation for this entry.
2055 We are creating a relocation in the output file's PLT section,
2056 which is included within the DLT secton. So we do need to include
2057 the PLT's output_offset in the computation of the relocation's
2059 rel.r_offset = (hh->plt_offset + splt->output_offset
2060 + splt->output_section->vma);
2061 rel.r_info = ELF64_R_INFO (hh->eh.dynindx, R_PARISC_IPLT);
2064 loc = spltrel->contents;
2065 loc += spltrel->reloc_count++ * sizeof (Elf64_External_Rela);
2066 bfd_elf64_swap_reloca_out (splt->output_section->owner, &rel, loc);
2069 /* Initialize an external call stub entry if requested. */
2071 && elf64_hppa_dynamic_symbol_p (eh, info))
2075 unsigned int max_offset;
2077 BFD_ASSERT (stub != NULL);
2079 /* Install the generic stub template.
2081 We are modifying the contents of the stub section, so we do not
2082 need to include the stub section's output_offset here. */
2083 memcpy (stub->contents + hh->stub_offset, plt_stub, sizeof (plt_stub));
2085 /* Fix up the first ldd instruction.
2087 We are modifying the contents of the STUB section in memory,
2088 so we do not need to include its output offset in this computation.
2090 Note the plt_offset value is the value of the PLT entry relative to
2091 the start of the PLT section. These instructions will reference
2092 data relative to the value of __gp, which may not necessarily have
2093 the same address as the start of the PLT section.
2095 gp_offset contains the offset of __gp within the PLT section. */
2096 value = hh->plt_offset - hppa_info->gp_offset;
2098 insn = bfd_get_32 (stub->owner, stub->contents + hh->stub_offset);
2099 if (output_bfd->arch_info->mach >= 25)
2101 /* Wide mode allows 16 bit offsets. */
2104 insn |= re_assemble_16 ((int) value);
2110 insn |= re_assemble_14 ((int) value);
2113 if ((value & 7) || value + max_offset >= 2*max_offset - 8)
2115 (*_bfd_error_handler) (_("stub entry for %s cannot load .plt, dp offset = %ld"),
2116 hh->eh.root.root.string,
2121 bfd_put_32 (stub->owner, (bfd_vma) insn,
2122 stub->contents + hh->stub_offset);
2124 /* Fix up the second ldd instruction. */
2126 insn = bfd_get_32 (stub->owner, stub->contents + hh->stub_offset + 8);
2127 if (output_bfd->arch_info->mach >= 25)
2130 insn |= re_assemble_16 ((int) value);
2135 insn |= re_assemble_14 ((int) value);
2137 bfd_put_32 (stub->owner, (bfd_vma) insn,
2138 stub->contents + hh->stub_offset + 8);
2144 /* The .opd section contains FPTRs for each function this file
2145 exports. Initialize the FPTR entries. */
2148 elf64_hppa_finalize_opd (struct elf_link_hash_entry *eh, void *data)
2150 struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
2151 struct bfd_link_info *info = (struct bfd_link_info *)data;
2152 struct elf64_hppa_link_hash_table *hppa_info;
2156 hppa_info = hppa_link_hash_table (info);
2157 sopd = hppa_info->opd_sec;
2158 sopdrel = hppa_info->opd_rel_sec;
2164 /* The first two words of an .opd entry are zero.
2166 We are modifying the contents of the OPD section in memory, so we
2167 do not need to include its output offset in this computation. */
2168 memset (sopd->contents + hh->opd_offset, 0, 16);
2170 value = (eh->root.u.def.value
2171 + eh->root.u.def.section->output_section->vma
2172 + eh->root.u.def.section->output_offset);
2174 /* The next word is the address of the function. */
2175 bfd_put_64 (sopd->owner, value, sopd->contents + hh->opd_offset + 16);
2177 /* The last word is our local __gp value. */
2178 value = _bfd_get_gp_value (sopd->output_section->owner);
2179 bfd_put_64 (sopd->owner, value, sopd->contents + hh->opd_offset + 24);
2182 /* If we are generating a shared library, we must generate EPLT relocations
2183 for each entry in the .opd, even for static functions (they may have
2184 had their address taken). */
2185 if (info->shared && hh->want_opd)
2187 Elf_Internal_Rela rel;
2191 /* We may need to do a relocation against a local symbol, in
2192 which case we have to look up it's dynamic symbol index off
2193 the local symbol hash table. */
2194 if (eh->dynindx != -1)
2195 dynindx = eh->dynindx;
2198 = _bfd_elf_link_lookup_local_dynindx (info, hh->owner,
2201 /* The offset of this relocation is the absolute address of the
2202 .opd entry for this symbol. */
2203 rel.r_offset = (hh->opd_offset + sopd->output_offset
2204 + sopd->output_section->vma);
2206 /* If H is non-null, then we have an external symbol.
2208 It is imperative that we use a different dynamic symbol for the
2209 EPLT relocation if the symbol has global scope.
2211 In the dynamic symbol table, the function symbol will have a value
2212 which is address of the function's .opd entry.
2214 Thus, we can not use that dynamic symbol for the EPLT relocation
2215 (if we did, the data in the .opd would reference itself rather
2216 than the actual address of the function). Instead we have to use
2217 a new dynamic symbol which has the same value as the original global
2220 We prefix the original symbol with a "." and use the new symbol in
2221 the EPLT relocation. This new symbol has already been recorded in
2222 the symbol table, we just have to look it up and use it.
2224 We do not have such problems with static functions because we do
2225 not make their addresses in the dynamic symbol table point to
2226 the .opd entry. Ultimately this should be safe since a static
2227 function can not be directly referenced outside of its shared
2230 We do have to play similar games for FPTR relocations in shared
2231 libraries, including those for static symbols. See the FPTR
2232 handling in elf64_hppa_finalize_dynreloc. */
2236 struct elf_link_hash_entry *nh;
2238 new_name = alloca (strlen (eh->root.root.string) + 2);
2240 strcpy (new_name + 1, eh->root.root.string);
2242 nh = elf_link_hash_lookup (elf_hash_table (info),
2243 new_name, TRUE, TRUE, FALSE);
2245 /* All we really want from the new symbol is its dynamic
2248 dynindx = nh->dynindx;
2252 rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_EPLT);
2254 loc = sopdrel->contents;
2255 loc += sopdrel->reloc_count++ * sizeof (Elf64_External_Rela);
2256 bfd_elf64_swap_reloca_out (sopd->output_section->owner, &rel, loc);
2261 /* The .dlt section contains addresses for items referenced through the
2262 dlt. Note that we can have a DLTIND relocation for a local symbol, thus
2263 we can not depend on finish_dynamic_symbol to initialize the .dlt. */
2266 elf64_hppa_finalize_dlt (struct elf_link_hash_entry *eh, void *data)
2268 struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
2269 struct bfd_link_info *info = (struct bfd_link_info *)data;
2270 struct elf64_hppa_link_hash_table *hppa_info;
2271 asection *sdlt, *sdltrel;
2273 hppa_info = hppa_link_hash_table (info);
2275 sdlt = hppa_info->dlt_sec;
2276 sdltrel = hppa_info->dlt_rel_sec;
2278 /* H/DYN_H may refer to a local variable and we know it's
2279 address, so there is no need to create a relocation. Just install
2280 the proper value into the DLT, note this shortcut can not be
2281 skipped when building a shared library. */
2282 if (! info->shared && hh && hh->want_dlt)
2286 /* If we had an LTOFF_FPTR style relocation we want the DLT entry
2287 to point to the FPTR entry in the .opd section.
2289 We include the OPD's output offset in this computation as
2290 we are referring to an absolute address in the resulting
2294 value = (hh->opd_offset
2295 + hppa_info->opd_sec->output_offset
2296 + hppa_info->opd_sec->output_section->vma);
2298 else if ((eh->root.type == bfd_link_hash_defined
2299 || eh->root.type == bfd_link_hash_defweak)
2300 && eh->root.u.def.section)
2302 value = eh->root.u.def.value + eh->root.u.def.section->output_offset;
2303 if (eh->root.u.def.section->output_section)
2304 value += eh->root.u.def.section->output_section->vma;
2306 value += eh->root.u.def.section->vma;
2309 /* We have an undefined function reference. */
2312 /* We do not need to include the output offset of the DLT section
2313 here because we are modifying the in-memory contents. */
2314 bfd_put_64 (sdlt->owner, value, sdlt->contents + hh->dlt_offset);
2317 /* Create a relocation for the DLT entry associated with this symbol.
2318 When building a shared library the symbol does not have to be dynamic. */
2320 && (elf64_hppa_dynamic_symbol_p (eh, info) || info->shared))
2322 Elf_Internal_Rela rel;
2326 /* We may need to do a relocation against a local symbol, in
2327 which case we have to look up it's dynamic symbol index off
2328 the local symbol hash table. */
2329 if (eh && eh->dynindx != -1)
2330 dynindx = eh->dynindx;
2333 = _bfd_elf_link_lookup_local_dynindx (info, hh->owner,
2336 /* Create a dynamic relocation for this entry. Do include the output
2337 offset of the DLT entry since we need an absolute address in the
2338 resulting object file. */
2339 rel.r_offset = (hh->dlt_offset + sdlt->output_offset
2340 + sdlt->output_section->vma);
2341 if (eh && eh->type == STT_FUNC)
2342 rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_FPTR64);
2344 rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_DIR64);
2347 loc = sdltrel->contents;
2348 loc += sdltrel->reloc_count++ * sizeof (Elf64_External_Rela);
2349 bfd_elf64_swap_reloca_out (sdlt->output_section->owner, &rel, loc);
2354 /* Finalize the dynamic relocations. Specifically the FPTR relocations
2355 for dynamic functions used to initialize static data. */
2358 elf64_hppa_finalize_dynreloc (struct elf_link_hash_entry *eh,
2361 struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
2362 struct bfd_link_info *info = (struct bfd_link_info *)data;
2363 struct elf64_hppa_link_hash_table *hppa_info;
2366 dynamic_symbol = elf64_hppa_dynamic_symbol_p (eh, info);
2368 if (!dynamic_symbol && !info->shared)
2371 if (hh->reloc_entries)
2373 struct elf64_hppa_dyn_reloc_entry *rent;
2376 hppa_info = hppa_link_hash_table (info);
2378 /* We may need to do a relocation against a local symbol, in
2379 which case we have to look up it's dynamic symbol index off
2380 the local symbol hash table. */
2381 if (eh->dynindx != -1)
2382 dynindx = eh->dynindx;
2385 = _bfd_elf_link_lookup_local_dynindx (info, hh->owner,
2388 for (rent = hh->reloc_entries; rent; rent = rent->next)
2390 Elf_Internal_Rela rel;
2393 /* Allocate one iff we are building a shared library, the relocation
2394 isn't a R_PARISC_FPTR64, or we don't want an opd entry. */
2395 if (!info->shared && rent->type == R_PARISC_FPTR64 && hh->want_opd)
2398 /* Create a dynamic relocation for this entry.
2400 We need the output offset for the reloc's section because
2401 we are creating an absolute address in the resulting object
2403 rel.r_offset = (rent->offset + rent->sec->output_offset
2404 + rent->sec->output_section->vma);
2406 /* An FPTR64 relocation implies that we took the address of
2407 a function and that the function has an entry in the .opd
2408 section. We want the FPTR64 relocation to reference the
2411 We could munge the symbol value in the dynamic symbol table
2412 (in fact we already do for functions with global scope) to point
2413 to the .opd entry. Then we could use that dynamic symbol in
2416 Or we could do something sensible, not munge the symbol's
2417 address and instead just use a different symbol to reference
2418 the .opd entry. At least that seems sensible until you
2419 realize there's no local dynamic symbols we can use for that
2420 purpose. Thus the hair in the check_relocs routine.
2422 We use a section symbol recorded by check_relocs as the
2423 base symbol for the relocation. The addend is the difference
2424 between the section symbol and the address of the .opd entry. */
2425 if (info->shared && rent->type == R_PARISC_FPTR64 && hh->want_opd)
2427 bfd_vma value, value2;
2429 /* First compute the address of the opd entry for this symbol. */
2430 value = (hh->opd_offset
2431 + hppa_info->opd_sec->output_section->vma
2432 + hppa_info->opd_sec->output_offset);
2434 /* Compute the value of the start of the section with
2436 value2 = (rent->sec->output_section->vma
2437 + rent->sec->output_offset);
2439 /* Compute the difference between the start of the section
2440 with the relocation and the opd entry. */
2443 /* The result becomes the addend of the relocation. */
2444 rel.r_addend = value;
2446 /* The section symbol becomes the symbol for the dynamic
2449 = _bfd_elf_link_lookup_local_dynindx (info,
2454 rel.r_addend = rent->addend;
2456 rel.r_info = ELF64_R_INFO (dynindx, rent->type);
2458 loc = hppa_info->other_rel_sec->contents;
2459 loc += (hppa_info->other_rel_sec->reloc_count++
2460 * sizeof (Elf64_External_Rela));
2461 bfd_elf64_swap_reloca_out (hppa_info->other_rel_sec->output_section->owner,
2469 /* Used to decide how to sort relocs in an optimal manner for the
2470 dynamic linker, before writing them out. */
2472 static enum elf_reloc_type_class
2473 elf64_hppa_reloc_type_class (const Elf_Internal_Rela *rela)
2475 if (ELF64_R_SYM (rela->r_info) == 0)
2476 return reloc_class_relative;
2478 switch ((int) ELF64_R_TYPE (rela->r_info))
2481 return reloc_class_plt;
2483 return reloc_class_copy;
2485 return reloc_class_normal;
2489 /* Finish up the dynamic sections. */
2492 elf64_hppa_finish_dynamic_sections (bfd *output_bfd,
2493 struct bfd_link_info *info)
2497 struct elf64_hppa_link_hash_table *hppa_info;
2499 hppa_info = hppa_link_hash_table (info);
2501 /* Finalize the contents of the .opd section. */
2502 elf_link_hash_traverse (elf_hash_table (info),
2503 elf64_hppa_finalize_opd,
2506 elf_link_hash_traverse (elf_hash_table (info),
2507 elf64_hppa_finalize_dynreloc,
2510 /* Finalize the contents of the .dlt section. */
2511 dynobj = elf_hash_table (info)->dynobj;
2512 /* Finalize the contents of the .dlt section. */
2513 elf_link_hash_traverse (elf_hash_table (info),
2514 elf64_hppa_finalize_dlt,
2517 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
2519 if (elf_hash_table (info)->dynamic_sections_created)
2521 Elf64_External_Dyn *dyncon, *dynconend;
2523 BFD_ASSERT (sdyn != NULL);
2525 dyncon = (Elf64_External_Dyn *) sdyn->contents;
2526 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
2527 for (; dyncon < dynconend; dyncon++)
2529 Elf_Internal_Dyn dyn;
2532 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
2539 case DT_HP_LOAD_MAP:
2540 /* Compute the absolute address of 16byte scratchpad area
2541 for the dynamic linker.
2543 By convention the linker script will allocate the scratchpad
2544 area at the start of the .data section. So all we have to
2545 to is find the start of the .data section. */
2546 s = bfd_get_section_by_name (output_bfd, ".data");
2547 dyn.d_un.d_ptr = s->vma;
2548 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2552 /* HP's use PLTGOT to set the GOT register. */
2553 dyn.d_un.d_ptr = _bfd_get_gp_value (output_bfd);
2554 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2558 s = hppa_info->plt_rel_sec;
2559 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
2560 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2564 s = hppa_info->plt_rel_sec;
2565 dyn.d_un.d_val = s->size;
2566 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2570 s = hppa_info->other_rel_sec;
2571 if (! s || ! s->size)
2572 s = hppa_info->dlt_rel_sec;
2573 if (! s || ! s->size)
2574 s = hppa_info->opd_rel_sec;
2575 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
2576 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2580 s = hppa_info->other_rel_sec;
2581 dyn.d_un.d_val = s->size;
2582 s = hppa_info->dlt_rel_sec;
2583 dyn.d_un.d_val += s->size;
2584 s = hppa_info->opd_rel_sec;
2585 dyn.d_un.d_val += s->size;
2586 /* There is some question about whether or not the size of
2587 the PLT relocs should be included here. HP's tools do
2588 it, so we'll emulate them. */
2589 s = hppa_info->plt_rel_sec;
2590 dyn.d_un.d_val += s->size;
2591 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2601 /* Support for core dump NOTE sections. */
2604 elf64_hppa_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
2609 switch (note->descsz)
2614 case 760: /* Linux/hppa */
2616 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
2619 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 32);
2628 /* Make a ".reg/999" section. */
2629 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
2630 size, note->descpos + offset);
2634 elf64_hppa_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
2639 switch (note->descsz)
2644 case 136: /* Linux/hppa elf_prpsinfo. */
2645 elf_tdata (abfd)->core_program
2646 = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
2647 elf_tdata (abfd)->core_command
2648 = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
2651 /* Note that for some reason, a spurious space is tacked
2652 onto the end of the args in some (at least one anyway)
2653 implementations, so strip it off if it exists. */
2654 command = elf_tdata (abfd)->core_command;
2655 n = strlen (command);
2657 if (0 < n && command[n - 1] == ' ')
2658 command[n - 1] = '\0';
2663 /* Return the number of additional phdrs we will need.
2665 The generic ELF code only creates PT_PHDRs for executables. The HP
2666 dynamic linker requires PT_PHDRs for dynamic libraries too.
2668 This routine indicates that the backend needs one additional program
2669 header for that case.
2671 Note we do not have access to the link info structure here, so we have
2672 to guess whether or not we are building a shared library based on the
2673 existence of a .interp section. */
2676 elf64_hppa_additional_program_headers (bfd *abfd,
2677 struct bfd_link_info *info ATTRIBUTE_UNUSED)
2681 /* If we are creating a shared library, then we have to create a
2682 PT_PHDR segment. HP's dynamic linker chokes without it. */
2683 s = bfd_get_section_by_name (abfd, ".interp");
2689 /* Allocate and initialize any program headers required by this
2692 The generic ELF code only creates PT_PHDRs for executables. The HP
2693 dynamic linker requires PT_PHDRs for dynamic libraries too.
2695 This allocates the PT_PHDR and initializes it in a manner suitable
2698 Note we do not have access to the link info structure here, so we have
2699 to guess whether or not we are building a shared library based on the
2700 existence of a .interp section. */
2703 elf64_hppa_modify_segment_map (bfd *abfd,
2704 struct bfd_link_info *info ATTRIBUTE_UNUSED)
2706 struct elf_segment_map *m;
2709 s = bfd_get_section_by_name (abfd, ".interp");
2712 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
2713 if (m->p_type == PT_PHDR)
2717 m = ((struct elf_segment_map *)
2718 bfd_zalloc (abfd, (bfd_size_type) sizeof *m));
2722 m->p_type = PT_PHDR;
2723 m->p_flags = PF_R | PF_X;
2724 m->p_flags_valid = 1;
2725 m->p_paddr_valid = 1;
2726 m->includes_phdrs = 1;
2728 m->next = elf_tdata (abfd)->segment_map;
2729 elf_tdata (abfd)->segment_map = m;
2733 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
2734 if (m->p_type == PT_LOAD)
2738 for (i = 0; i < m->count; i++)
2740 /* The code "hint" is not really a hint. It is a requirement
2741 for certain versions of the HP dynamic linker. Worse yet,
2742 it must be set even if the shared library does not have
2743 any code in its "text" segment (thus the check for .hash
2744 to catch this situation). */
2745 if (m->sections[i]->flags & SEC_CODE
2746 || (strcmp (m->sections[i]->name, ".hash") == 0))
2747 m->p_flags |= (PF_X | PF_HP_CODE);
2754 /* Called when writing out an object file to decide the type of a
2757 elf64_hppa_elf_get_symbol_type (Elf_Internal_Sym *elf_sym,
2760 if (ELF_ST_TYPE (elf_sym->st_info) == STT_PARISC_MILLI)
2761 return STT_PARISC_MILLI;
2766 /* Support HP specific sections for core files. */
2768 elf64_hppa_section_from_phdr (bfd *abfd, Elf_Internal_Phdr *hdr, int index,
2769 const char *typename)
2771 if (hdr->p_type == PT_HP_CORE_KERNEL)
2775 if (!_bfd_elf_make_section_from_phdr (abfd, hdr, index, typename))
2778 sect = bfd_make_section_anyway (abfd, ".kernel");
2781 sect->size = hdr->p_filesz;
2782 sect->filepos = hdr->p_offset;
2783 sect->flags = SEC_HAS_CONTENTS | SEC_READONLY;
2787 if (hdr->p_type == PT_HP_CORE_PROC)
2791 if (bfd_seek (abfd, hdr->p_offset, SEEK_SET) != 0)
2793 if (bfd_bread (&sig, 4, abfd) != 4)
2796 elf_tdata (abfd)->core_signal = sig;
2798 if (!_bfd_elf_make_section_from_phdr (abfd, hdr, index, typename))
2801 /* GDB uses the ".reg" section to read register contents. */
2802 return _bfd_elfcore_make_pseudosection (abfd, ".reg", hdr->p_filesz,
2806 if (hdr->p_type == PT_HP_CORE_LOADABLE
2807 || hdr->p_type == PT_HP_CORE_STACK
2808 || hdr->p_type == PT_HP_CORE_MMF)
2809 hdr->p_type = PT_LOAD;
2811 return _bfd_elf_make_section_from_phdr (abfd, hdr, index, typename);
2814 /* Hook called by the linker routine which adds symbols from an object
2815 file. HP's libraries define symbols with HP specific section
2816 indices, which we have to handle. */
2819 elf_hppa_add_symbol_hook (bfd *abfd,
2820 struct bfd_link_info *info ATTRIBUTE_UNUSED,
2821 Elf_Internal_Sym *sym,
2822 const char **namep ATTRIBUTE_UNUSED,
2823 flagword *flagsp ATTRIBUTE_UNUSED,
2827 unsigned int index = sym->st_shndx;
2831 case SHN_PARISC_ANSI_COMMON:
2832 *secp = bfd_make_section_old_way (abfd, ".PARISC.ansi.common");
2833 (*secp)->flags |= SEC_IS_COMMON;
2834 *valp = sym->st_size;
2837 case SHN_PARISC_HUGE_COMMON:
2838 *secp = bfd_make_section_old_way (abfd, ".PARISC.huge.common");
2839 (*secp)->flags |= SEC_IS_COMMON;
2840 *valp = sym->st_size;
2848 elf_hppa_unmark_useless_dynamic_symbols (struct elf_link_hash_entry *h,
2851 struct bfd_link_info *info = data;
2853 if (h->root.type == bfd_link_hash_warning)
2854 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2856 /* If we are not creating a shared library, and this symbol is
2857 referenced by a shared library but is not defined anywhere, then
2858 the generic code will warn that it is undefined.
2860 This behavior is undesirable on HPs since the standard shared
2861 libraries contain references to undefined symbols.
2863 So we twiddle the flags associated with such symbols so that they
2864 will not trigger the warning. ?!? FIXME. This is horribly fragile.
2866 Ultimately we should have better controls over the generic ELF BFD
2868 if (! info->relocatable
2869 && info->unresolved_syms_in_shared_libs != RM_IGNORE
2870 && h->root.type == bfd_link_hash_undefined
2875 h->pointer_equality_needed = 1;
2882 elf_hppa_remark_useless_dynamic_symbols (struct elf_link_hash_entry *h,
2885 struct bfd_link_info *info = data;
2887 if (h->root.type == bfd_link_hash_warning)
2888 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2890 /* If we are not creating a shared library, and this symbol is
2891 referenced by a shared library but is not defined anywhere, then
2892 the generic code will warn that it is undefined.
2894 This behavior is undesirable on HPs since the standard shared
2895 libraries contain references to undefined symbols.
2897 So we twiddle the flags associated with such symbols so that they
2898 will not trigger the warning. ?!? FIXME. This is horribly fragile.
2900 Ultimately we should have better controls over the generic ELF BFD
2902 if (! info->relocatable
2903 && info->unresolved_syms_in_shared_libs != RM_IGNORE
2904 && h->root.type == bfd_link_hash_undefined
2907 && h->pointer_equality_needed)
2910 h->pointer_equality_needed = 0;
2917 elf_hppa_is_dynamic_loader_symbol (const char *name)
2919 return (! strcmp (name, "__CPU_REVISION")
2920 || ! strcmp (name, "__CPU_KEYBITS_1")
2921 || ! strcmp (name, "__SYSTEM_ID_D")
2922 || ! strcmp (name, "__FPU_MODEL")
2923 || ! strcmp (name, "__FPU_REVISION")
2924 || ! strcmp (name, "__ARGC")
2925 || ! strcmp (name, "__ARGV")
2926 || ! strcmp (name, "__ENVP")
2927 || ! strcmp (name, "__TLS_SIZE_D")
2928 || ! strcmp (name, "__LOAD_INFO")
2929 || ! strcmp (name, "__systab"));
2932 /* Record the lowest address for the data and text segments. */
2934 elf_hppa_record_segment_addrs (bfd *abfd,
2938 struct elf64_hppa_link_hash_table *hppa_info = data;
2940 if ((section->flags & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
2943 Elf_Internal_Phdr *p;
2945 p = _bfd_elf_find_segment_containing_section (abfd, section->output_section);
2946 BFD_ASSERT (p != NULL);
2949 if (section->flags & SEC_READONLY)
2951 if (value < hppa_info->text_segment_base)
2952 hppa_info->text_segment_base = value;
2956 if (value < hppa_info->data_segment_base)
2957 hppa_info->data_segment_base = value;
2962 /* Called after we have seen all the input files/sections, but before
2963 final symbol resolution and section placement has been determined.
2965 We use this hook to (possibly) provide a value for __gp, then we
2966 fall back to the generic ELF final link routine. */
2969 elf_hppa_final_link (bfd *abfd, struct bfd_link_info *info)
2972 struct elf64_hppa_link_hash_table *hppa_info = hppa_link_hash_table (info);
2974 if (! info->relocatable)
2976 struct elf_link_hash_entry *gp;
2979 /* The linker script defines a value for __gp iff it was referenced
2980 by one of the objects being linked. First try to find the symbol
2981 in the hash table. If that fails, just compute the value __gp
2983 gp = elf_link_hash_lookup (elf_hash_table (info), "__gp", FALSE,
2989 /* Adjust the value of __gp as we may want to slide it into the
2990 .plt section so that the stubs can access PLT entries without
2991 using an addil sequence. */
2992 gp->root.u.def.value += hppa_info->gp_offset;
2994 gp_val = (gp->root.u.def.section->output_section->vma
2995 + gp->root.u.def.section->output_offset
2996 + gp->root.u.def.value);
3002 /* First look for a .plt section. If found, then __gp is the
3003 address of the .plt + gp_offset.
3005 If no .plt is found, then look for .dlt, .opd and .data (in
3006 that order) and set __gp to the base address of whichever
3007 section is found first. */
3009 sec = hppa_info->plt_sec;
3010 if (sec && ! (sec->flags & SEC_EXCLUDE))
3011 gp_val = (sec->output_offset
3012 + sec->output_section->vma
3013 + hppa_info->gp_offset);
3016 sec = hppa_info->dlt_sec;
3017 if (!sec || (sec->flags & SEC_EXCLUDE))
3018 sec = hppa_info->opd_sec;
3019 if (!sec || (sec->flags & SEC_EXCLUDE))
3020 sec = bfd_get_section_by_name (abfd, ".data");
3021 if (!sec || (sec->flags & SEC_EXCLUDE))
3024 gp_val = sec->output_offset + sec->output_section->vma;
3028 /* Install whatever value we found/computed for __gp. */
3029 _bfd_set_gp_value (abfd, gp_val);
3032 /* We need to know the base of the text and data segments so that we
3033 can perform SEGREL relocations. We will record the base addresses
3034 when we encounter the first SEGREL relocation. */
3035 hppa_info->text_segment_base = (bfd_vma)-1;
3036 hppa_info->data_segment_base = (bfd_vma)-1;
3038 /* HP's shared libraries have references to symbols that are not
3039 defined anywhere. The generic ELF BFD linker code will complain
3042 So we detect the losing case and arrange for the flags on the symbol
3043 to indicate that it was never referenced. This keeps the generic
3044 ELF BFD link code happy and appears to not create any secondary
3045 problems. Ultimately we need a way to control the behavior of the
3046 generic ELF BFD link code better. */
3047 elf_link_hash_traverse (elf_hash_table (info),
3048 elf_hppa_unmark_useless_dynamic_symbols,
3051 /* Invoke the regular ELF backend linker to do all the work. */
3052 retval = bfd_elf_final_link (abfd, info);
3054 elf_link_hash_traverse (elf_hash_table (info),
3055 elf_hppa_remark_useless_dynamic_symbols,
3058 /* If we're producing a final executable, sort the contents of the
3061 retval = elf_hppa_sort_unwind (abfd);
3066 /* Relocate the given INSN. VALUE should be the actual value we want
3067 to insert into the instruction, ie by this point we should not be
3068 concerned with computing an offset relative to the DLT, PC, etc.
3069 Instead this routine is meant to handle the bit manipulations needed
3070 to insert the relocation into the given instruction. */
3073 elf_hppa_relocate_insn (int insn, int sym_value, unsigned int r_type)
3077 /* This is any 22 bit branch. In PA2.0 syntax it corresponds to
3078 the "B" instruction. */
3079 case R_PARISC_PCREL22F:
3080 case R_PARISC_PCREL22C:
3081 return (insn & ~0x3ff1ffd) | re_assemble_22 (sym_value);
3083 /* This is any 12 bit branch. */
3084 case R_PARISC_PCREL12F:
3085 return (insn & ~0x1ffd) | re_assemble_12 (sym_value);
3087 /* This is any 17 bit branch. In PA2.0 syntax it also corresponds
3088 to the "B" instruction as well as BE. */
3089 case R_PARISC_PCREL17F:
3090 case R_PARISC_DIR17F:
3091 case R_PARISC_DIR17R:
3092 case R_PARISC_PCREL17C:
3093 case R_PARISC_PCREL17R:
3094 return (insn & ~0x1f1ffd) | re_assemble_17 (sym_value);
3096 /* ADDIL or LDIL instructions. */
3097 case R_PARISC_DLTREL21L:
3098 case R_PARISC_DLTIND21L:
3099 case R_PARISC_LTOFF_FPTR21L:
3100 case R_PARISC_PCREL21L:
3101 case R_PARISC_LTOFF_TP21L:
3102 case R_PARISC_DPREL21L:
3103 case R_PARISC_PLTOFF21L:
3104 case R_PARISC_DIR21L:
3105 return (insn & ~0x1fffff) | re_assemble_21 (sym_value);
3107 /* LDO and integer loads/stores with 14 bit displacements. */
3108 case R_PARISC_DLTREL14R:
3109 case R_PARISC_DLTREL14F:
3110 case R_PARISC_DLTIND14R:
3111 case R_PARISC_DLTIND14F:
3112 case R_PARISC_LTOFF_FPTR14R:
3113 case R_PARISC_PCREL14R:
3114 case R_PARISC_PCREL14F:
3115 case R_PARISC_LTOFF_TP14R:
3116 case R_PARISC_LTOFF_TP14F:
3117 case R_PARISC_DPREL14R:
3118 case R_PARISC_DPREL14F:
3119 case R_PARISC_PLTOFF14R:
3120 case R_PARISC_PLTOFF14F:
3121 case R_PARISC_DIR14R:
3122 case R_PARISC_DIR14F:
3123 return (insn & ~0x3fff) | low_sign_unext (sym_value, 14);
3125 /* PA2.0W LDO and integer loads/stores with 16 bit displacements. */
3126 case R_PARISC_LTOFF_FPTR16F:
3127 case R_PARISC_PCREL16F:
3128 case R_PARISC_LTOFF_TP16F:
3129 case R_PARISC_GPREL16F:
3130 case R_PARISC_PLTOFF16F:
3131 case R_PARISC_DIR16F:
3132 case R_PARISC_LTOFF16F:
3133 return (insn & ~0xffff) | re_assemble_16 (sym_value);
3135 /* Doubleword loads and stores with a 14 bit displacement. */
3136 case R_PARISC_DLTREL14DR:
3137 case R_PARISC_DLTIND14DR:
3138 case R_PARISC_LTOFF_FPTR14DR:
3139 case R_PARISC_LTOFF_FPTR16DF:
3140 case R_PARISC_PCREL14DR:
3141 case R_PARISC_PCREL16DF:
3142 case R_PARISC_LTOFF_TP14DR:
3143 case R_PARISC_LTOFF_TP16DF:
3144 case R_PARISC_DPREL14DR:
3145 case R_PARISC_GPREL16DF:
3146 case R_PARISC_PLTOFF14DR:
3147 case R_PARISC_PLTOFF16DF:
3148 case R_PARISC_DIR14DR:
3149 case R_PARISC_DIR16DF:
3150 case R_PARISC_LTOFF16DF:
3151 return (insn & ~0x3ff1) | (((sym_value & 0x2000) >> 13)
3152 | ((sym_value & 0x1ff8) << 1));
3154 /* Floating point single word load/store instructions. */
3155 case R_PARISC_DLTREL14WR:
3156 case R_PARISC_DLTIND14WR:
3157 case R_PARISC_LTOFF_FPTR14WR:
3158 case R_PARISC_LTOFF_FPTR16WF:
3159 case R_PARISC_PCREL14WR:
3160 case R_PARISC_PCREL16WF:
3161 case R_PARISC_LTOFF_TP14WR:
3162 case R_PARISC_LTOFF_TP16WF:
3163 case R_PARISC_DPREL14WR:
3164 case R_PARISC_GPREL16WF:
3165 case R_PARISC_PLTOFF14WR:
3166 case R_PARISC_PLTOFF16WF:
3167 case R_PARISC_DIR16WF:
3168 case R_PARISC_DIR14WR:
3169 case R_PARISC_LTOFF16WF:
3170 return (insn & ~0x3ff9) | (((sym_value & 0x2000) >> 13)
3171 | ((sym_value & 0x1ffc) << 1));
3178 /* Compute the value for a relocation (REL) during a final link stage,
3179 then insert the value into the proper location in CONTENTS.
3181 VALUE is a tentative value for the relocation and may be overridden
3182 and modified here based on the specific relocation to be performed.
3184 For example we do conversions for PC-relative branches in this routine
3185 or redirection of calls to external routines to stubs.
3187 The work of actually applying the relocation is left to a helper
3188 routine in an attempt to reduce the complexity and size of this
3191 static bfd_reloc_status_type
3192 elf_hppa_final_link_relocate (Elf_Internal_Rela *rel,
3195 asection *input_section,
3198 struct bfd_link_info *info,
3200 struct elf_link_hash_entry *eh)
3202 struct elf64_hppa_link_hash_table *hppa_info = hppa_link_hash_table (info);
3203 struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
3204 bfd_vma *local_offsets;
3205 Elf_Internal_Shdr *symtab_hdr;
3207 bfd_vma max_branch_offset = 0;
3208 bfd_vma offset = rel->r_offset;
3209 bfd_signed_vma addend = rel->r_addend;
3210 reloc_howto_type *howto = elf_hppa_howto_table + ELF_R_TYPE (rel->r_info);
3211 unsigned int r_symndx = ELF_R_SYM (rel->r_info);
3212 unsigned int r_type = howto->type;
3213 bfd_byte *hit_data = contents + offset;
3215 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3216 local_offsets = elf_local_got_offsets (input_bfd);
3217 insn = bfd_get_32 (input_bfd, hit_data);
3224 /* Basic function call support.
3226 Note for a call to a function defined in another dynamic library
3227 we want to redirect the call to a stub. */
3229 /* PC relative relocs without an implicit offset. */
3230 case R_PARISC_PCREL21L:
3231 case R_PARISC_PCREL14R:
3232 case R_PARISC_PCREL14F:
3233 case R_PARISC_PCREL14WR:
3234 case R_PARISC_PCREL14DR:
3235 case R_PARISC_PCREL16F:
3236 case R_PARISC_PCREL16WF:
3237 case R_PARISC_PCREL16DF:
3239 /* If this is a call to a function defined in another dynamic
3240 library, then redirect the call to the local stub for this
3242 if (sym_sec == NULL || sym_sec->output_section == NULL)
3243 value = (hh->stub_offset + hppa_info->stub_sec->output_offset
3244 + hppa_info->stub_sec->output_section->vma);
3246 /* Turn VALUE into a proper PC relative address. */
3247 value -= (offset + input_section->output_offset
3248 + input_section->output_section->vma);
3250 /* Adjust for any field selectors. */
3251 if (r_type == R_PARISC_PCREL21L)
3252 value = hppa_field_adjust (value, -8 + addend, e_lsel);
3253 else if (r_type == R_PARISC_PCREL14F
3254 || r_type == R_PARISC_PCREL16F
3255 || r_type == R_PARISC_PCREL16WF
3256 || r_type == R_PARISC_PCREL16DF)
3257 value = hppa_field_adjust (value, -8 + addend, e_fsel);
3259 value = hppa_field_adjust (value, -8 + addend, e_rsel);
3261 /* Apply the relocation to the given instruction. */
3262 insn = elf_hppa_relocate_insn (insn, (int) value, r_type);
3266 case R_PARISC_PCREL12F:
3267 case R_PARISC_PCREL22F:
3268 case R_PARISC_PCREL17F:
3269 case R_PARISC_PCREL22C:
3270 case R_PARISC_PCREL17C:
3271 case R_PARISC_PCREL17R:
3273 /* If this is a call to a function defined in another dynamic
3274 library, then redirect the call to the local stub for this
3276 if (sym_sec == NULL || sym_sec->output_section == NULL)
3277 value = (hh->stub_offset + hppa_info->stub_sec->output_offset
3278 + hppa_info->stub_sec->output_section->vma);
3280 /* Turn VALUE into a proper PC relative address. */
3281 value -= (offset + input_section->output_offset
3282 + input_section->output_section->vma);
3285 if (r_type == (unsigned int) R_PARISC_PCREL22F)
3286 max_branch_offset = (1 << (22-1)) << 2;
3287 else if (r_type == (unsigned int) R_PARISC_PCREL17F)
3288 max_branch_offset = (1 << (17-1)) << 2;
3289 else if (r_type == (unsigned int) R_PARISC_PCREL12F)
3290 max_branch_offset = (1 << (12-1)) << 2;
3292 /* Make sure we can reach the branch target. */
3293 if (max_branch_offset != 0
3294 && value + addend + max_branch_offset >= 2*max_branch_offset)
3296 (*_bfd_error_handler)
3297 (_("%B(%A+0x%lx): cannot reach %s"),
3301 eh->root.root.string);
3302 bfd_set_error (bfd_error_bad_value);
3303 return bfd_reloc_notsupported;
3306 /* Adjust for any field selectors. */
3307 if (r_type == R_PARISC_PCREL17R)
3308 value = hppa_field_adjust (value, addend, e_rsel);
3310 value = hppa_field_adjust (value, addend, e_fsel);
3312 /* All branches are implicitly shifted by 2 places. */
3315 /* Apply the relocation to the given instruction. */
3316 insn = elf_hppa_relocate_insn (insn, (int) value, r_type);
3320 /* Indirect references to data through the DLT. */
3321 case R_PARISC_DLTIND14R:
3322 case R_PARISC_DLTIND14F:
3323 case R_PARISC_DLTIND14DR:
3324 case R_PARISC_DLTIND14WR:
3325 case R_PARISC_DLTIND21L:
3326 case R_PARISC_LTOFF_FPTR14R:
3327 case R_PARISC_LTOFF_FPTR14DR:
3328 case R_PARISC_LTOFF_FPTR14WR:
3329 case R_PARISC_LTOFF_FPTR21L:
3330 case R_PARISC_LTOFF_FPTR16F:
3331 case R_PARISC_LTOFF_FPTR16WF:
3332 case R_PARISC_LTOFF_FPTR16DF:
3333 case R_PARISC_LTOFF_TP21L:
3334 case R_PARISC_LTOFF_TP14R:
3335 case R_PARISC_LTOFF_TP14F:
3336 case R_PARISC_LTOFF_TP14WR:
3337 case R_PARISC_LTOFF_TP14DR:
3338 case R_PARISC_LTOFF_TP16F:
3339 case R_PARISC_LTOFF_TP16WF:
3340 case R_PARISC_LTOFF_TP16DF:
3341 case R_PARISC_LTOFF16F:
3342 case R_PARISC_LTOFF16WF:
3343 case R_PARISC_LTOFF16DF:
3347 /* If this relocation was against a local symbol, then we still
3348 have not set up the DLT entry (it's not convenient to do so
3349 in the "finalize_dlt" routine because it is difficult to get
3350 to the local symbol's value).
3352 So, if this is a local symbol (h == NULL), then we need to
3353 fill in its DLT entry.
3355 Similarly we may still need to set up an entry in .opd for
3356 a local function which had its address taken. */
3359 bfd_vma *local_opd_offsets, *local_dlt_offsets;
3361 if (local_offsets == NULL)
3364 /* Now do .opd creation if needed. */
3365 if (r_type == R_PARISC_LTOFF_FPTR14R
3366 || r_type == R_PARISC_LTOFF_FPTR14DR
3367 || r_type == R_PARISC_LTOFF_FPTR14WR
3368 || r_type == R_PARISC_LTOFF_FPTR21L
3369 || r_type == R_PARISC_LTOFF_FPTR16F
3370 || r_type == R_PARISC_LTOFF_FPTR16WF
3371 || r_type == R_PARISC_LTOFF_FPTR16DF)
3373 local_opd_offsets = local_offsets + 2 * symtab_hdr->sh_info;
3374 off = local_opd_offsets[r_symndx];
3376 /* The last bit records whether we've already initialised
3377 this local .opd entry. */
3380 BFD_ASSERT (off != (bfd_vma) -1);
3385 local_opd_offsets[r_symndx] |= 1;
3387 /* The first two words of an .opd entry are zero. */
3388 memset (hppa_info->opd_sec->contents + off, 0, 16);
3390 /* The next word is the address of the function. */
3391 bfd_put_64 (hppa_info->opd_sec->owner, value + addend,
3392 (hppa_info->opd_sec->contents + off + 16));
3394 /* The last word is our local __gp value. */
3395 value = _bfd_get_gp_value
3396 (hppa_info->opd_sec->output_section->owner);
3397 bfd_put_64 (hppa_info->opd_sec->owner, value,
3398 (hppa_info->opd_sec->contents + off + 24));
3401 /* The DLT value is the address of the .opd entry. */
3403 + hppa_info->opd_sec->output_offset
3404 + hppa_info->opd_sec->output_section->vma);
3408 local_dlt_offsets = local_offsets;
3409 off = local_dlt_offsets[r_symndx];
3413 BFD_ASSERT (off != (bfd_vma) -1);
3418 local_dlt_offsets[r_symndx] |= 1;
3419 bfd_put_64 (hppa_info->dlt_sec->owner,
3421 hppa_info->dlt_sec->contents + off);
3425 off = hh->dlt_offset;
3427 /* We want the value of the DLT offset for this symbol, not
3428 the symbol's actual address. Note that __gp may not point
3429 to the start of the DLT, so we have to compute the absolute
3430 address, then subtract out the value of __gp. */
3432 + hppa_info->dlt_sec->output_offset
3433 + hppa_info->dlt_sec->output_section->vma);
3434 value -= _bfd_get_gp_value (output_bfd);
3436 /* All DLTIND relocations are basically the same at this point,
3437 except that we need different field selectors for the 21bit
3438 version vs the 14bit versions. */
3439 if (r_type == R_PARISC_DLTIND21L
3440 || r_type == R_PARISC_LTOFF_FPTR21L
3441 || r_type == R_PARISC_LTOFF_TP21L)
3442 value = hppa_field_adjust (value, 0, e_lsel);
3443 else if (r_type == R_PARISC_DLTIND14F
3444 || r_type == R_PARISC_LTOFF_FPTR16F
3445 || r_type == R_PARISC_LTOFF_FPTR16WF
3446 || r_type == R_PARISC_LTOFF_FPTR16DF
3447 || r_type == R_PARISC_LTOFF16F
3448 || r_type == R_PARISC_LTOFF16DF
3449 || r_type == R_PARISC_LTOFF16WF
3450 || r_type == R_PARISC_LTOFF_TP16F
3451 || r_type == R_PARISC_LTOFF_TP16WF
3452 || r_type == R_PARISC_LTOFF_TP16DF)
3453 value = hppa_field_adjust (value, 0, e_fsel);
3455 value = hppa_field_adjust (value, 0, e_rsel);
3457 insn = elf_hppa_relocate_insn (insn, (int) value, r_type);
3461 case R_PARISC_DLTREL14R:
3462 case R_PARISC_DLTREL14F:
3463 case R_PARISC_DLTREL14DR:
3464 case R_PARISC_DLTREL14WR:
3465 case R_PARISC_DLTREL21L:
3466 case R_PARISC_DPREL21L:
3467 case R_PARISC_DPREL14WR:
3468 case R_PARISC_DPREL14DR:
3469 case R_PARISC_DPREL14R:
3470 case R_PARISC_DPREL14F:
3471 case R_PARISC_GPREL16F:
3472 case R_PARISC_GPREL16WF:
3473 case R_PARISC_GPREL16DF:
3475 /* Subtract out the global pointer value to make value a DLT
3476 relative address. */
3477 value -= _bfd_get_gp_value (output_bfd);
3479 /* All DLTREL relocations are basically the same at this point,
3480 except that we need different field selectors for the 21bit
3481 version vs the 14bit versions. */
3482 if (r_type == R_PARISC_DLTREL21L
3483 || r_type == R_PARISC_DPREL21L)
3484 value = hppa_field_adjust (value, addend, e_lrsel);
3485 else if (r_type == R_PARISC_DLTREL14F
3486 || r_type == R_PARISC_DPREL14F
3487 || r_type == R_PARISC_GPREL16F
3488 || r_type == R_PARISC_GPREL16WF
3489 || r_type == R_PARISC_GPREL16DF)
3490 value = hppa_field_adjust (value, addend, e_fsel);
3492 value = hppa_field_adjust (value, addend, e_rrsel);
3494 insn = elf_hppa_relocate_insn (insn, (int) value, r_type);
3498 case R_PARISC_DIR21L:
3499 case R_PARISC_DIR17R:
3500 case R_PARISC_DIR17F:
3501 case R_PARISC_DIR14R:
3502 case R_PARISC_DIR14F:
3503 case R_PARISC_DIR14WR:
3504 case R_PARISC_DIR14DR:
3505 case R_PARISC_DIR16F:
3506 case R_PARISC_DIR16WF:
3507 case R_PARISC_DIR16DF:
3509 /* All DIR relocations are basically the same at this point,
3510 except that branch offsets need to be divided by four, and
3511 we need different field selectors. Note that we don't
3512 redirect absolute calls to local stubs. */
3514 if (r_type == R_PARISC_DIR21L)
3515 value = hppa_field_adjust (value, addend, e_lrsel);
3516 else if (r_type == R_PARISC_DIR17F
3517 || r_type == R_PARISC_DIR16F
3518 || r_type == R_PARISC_DIR16WF
3519 || r_type == R_PARISC_DIR16DF
3520 || r_type == R_PARISC_DIR14F)
3521 value = hppa_field_adjust (value, addend, e_fsel);
3523 value = hppa_field_adjust (value, addend, e_rrsel);
3525 if (r_type == R_PARISC_DIR17R || r_type == R_PARISC_DIR17F)
3526 /* All branches are implicitly shifted by 2 places. */
3529 insn = elf_hppa_relocate_insn (insn, (int) value, r_type);
3533 case R_PARISC_PLTOFF21L:
3534 case R_PARISC_PLTOFF14R:
3535 case R_PARISC_PLTOFF14F:
3536 case R_PARISC_PLTOFF14WR:
3537 case R_PARISC_PLTOFF14DR:
3538 case R_PARISC_PLTOFF16F:
3539 case R_PARISC_PLTOFF16WF:
3540 case R_PARISC_PLTOFF16DF:
3542 /* We want the value of the PLT offset for this symbol, not
3543 the symbol's actual address. Note that __gp may not point
3544 to the start of the DLT, so we have to compute the absolute
3545 address, then subtract out the value of __gp. */
3546 value = (hh->plt_offset
3547 + hppa_info->plt_sec->output_offset
3548 + hppa_info->plt_sec->output_section->vma);
3549 value -= _bfd_get_gp_value (output_bfd);
3551 /* All PLTOFF relocations are basically the same at this point,
3552 except that we need different field selectors for the 21bit
3553 version vs the 14bit versions. */
3554 if (r_type == R_PARISC_PLTOFF21L)
3555 value = hppa_field_adjust (value, addend, e_lrsel);
3556 else if (r_type == R_PARISC_PLTOFF14F
3557 || r_type == R_PARISC_PLTOFF16F
3558 || r_type == R_PARISC_PLTOFF16WF
3559 || r_type == R_PARISC_PLTOFF16DF)
3560 value = hppa_field_adjust (value, addend, e_fsel);
3562 value = hppa_field_adjust (value, addend, e_rrsel);
3564 insn = elf_hppa_relocate_insn (insn, (int) value, r_type);
3568 case R_PARISC_LTOFF_FPTR32:
3570 /* We may still need to create the FPTR itself if it was for
3574 /* The first two words of an .opd entry are zero. */
3575 memset (hppa_info->opd_sec->contents + hh->opd_offset, 0, 16);
3577 /* The next word is the address of the function. */
3578 bfd_put_64 (hppa_info->opd_sec->owner, value + addend,
3579 (hppa_info->opd_sec->contents
3580 + hh->opd_offset + 16));
3582 /* The last word is our local __gp value. */
3583 value = _bfd_get_gp_value
3584 (hppa_info->opd_sec->output_section->owner);
3585 bfd_put_64 (hppa_info->opd_sec->owner, value,
3586 hppa_info->opd_sec->contents + hh->opd_offset + 24);
3588 /* The DLT value is the address of the .opd entry. */
3589 value = (hh->opd_offset
3590 + hppa_info->opd_sec->output_offset
3591 + hppa_info->opd_sec->output_section->vma);
3593 bfd_put_64 (hppa_info->dlt_sec->owner,
3595 hppa_info->dlt_sec->contents + hh->dlt_offset);
3598 /* We want the value of the DLT offset for this symbol, not
3599 the symbol's actual address. Note that __gp may not point
3600 to the start of the DLT, so we have to compute the absolute
3601 address, then subtract out the value of __gp. */
3602 value = (hh->dlt_offset
3603 + hppa_info->dlt_sec->output_offset
3604 + hppa_info->dlt_sec->output_section->vma);
3605 value -= _bfd_get_gp_value (output_bfd);
3606 bfd_put_32 (input_bfd, value, hit_data);
3607 return bfd_reloc_ok;
3610 case R_PARISC_LTOFF_FPTR64:
3611 case R_PARISC_LTOFF_TP64:
3613 /* We may still need to create the FPTR itself if it was for
3615 if (eh == NULL && r_type == R_PARISC_LTOFF_FPTR64)
3617 /* The first two words of an .opd entry are zero. */
3618 memset (hppa_info->opd_sec->contents + hh->opd_offset, 0, 16);
3620 /* The next word is the address of the function. */
3621 bfd_put_64 (hppa_info->opd_sec->owner, value + addend,
3622 (hppa_info->opd_sec->contents
3623 + hh->opd_offset + 16));
3625 /* The last word is our local __gp value. */
3626 value = _bfd_get_gp_value
3627 (hppa_info->opd_sec->output_section->owner);
3628 bfd_put_64 (hppa_info->opd_sec->owner, value,
3629 hppa_info->opd_sec->contents + hh->opd_offset + 24);
3631 /* The DLT value is the address of the .opd entry. */
3632 value = (hh->opd_offset
3633 + hppa_info->opd_sec->output_offset
3634 + hppa_info->opd_sec->output_section->vma);
3636 bfd_put_64 (hppa_info->dlt_sec->owner,
3638 hppa_info->dlt_sec->contents + hh->dlt_offset);
3641 /* We want the value of the DLT offset for this symbol, not
3642 the symbol's actual address. Note that __gp may not point
3643 to the start of the DLT, so we have to compute the absolute
3644 address, then subtract out the value of __gp. */
3645 value = (hh->dlt_offset
3646 + hppa_info->dlt_sec->output_offset
3647 + hppa_info->dlt_sec->output_section->vma);
3648 value -= _bfd_get_gp_value (output_bfd);
3649 bfd_put_64 (input_bfd, value, hit_data);
3650 return bfd_reloc_ok;
3653 case R_PARISC_DIR32:
3654 bfd_put_32 (input_bfd, value + addend, hit_data);
3655 return bfd_reloc_ok;
3657 case R_PARISC_DIR64:
3658 bfd_put_64 (input_bfd, value + addend, hit_data);
3659 return bfd_reloc_ok;
3661 case R_PARISC_GPREL64:
3662 /* Subtract out the global pointer value to make value a DLT
3663 relative address. */
3664 value -= _bfd_get_gp_value (output_bfd);
3666 bfd_put_64 (input_bfd, value + addend, hit_data);
3667 return bfd_reloc_ok;
3669 case R_PARISC_LTOFF64:
3670 /* We want the value of the DLT offset for this symbol, not
3671 the symbol's actual address. Note that __gp may not point
3672 to the start of the DLT, so we have to compute the absolute
3673 address, then subtract out the value of __gp. */
3674 value = (hh->dlt_offset
3675 + hppa_info->dlt_sec->output_offset
3676 + hppa_info->dlt_sec->output_section->vma);
3677 value -= _bfd_get_gp_value (output_bfd);
3679 bfd_put_64 (input_bfd, value + addend, hit_data);
3680 return bfd_reloc_ok;
3682 case R_PARISC_PCREL32:
3684 /* If this is a call to a function defined in another dynamic
3685 library, then redirect the call to the local stub for this
3687 if (sym_sec == NULL || sym_sec->output_section == NULL)
3688 value = (hh->stub_offset + hppa_info->stub_sec->output_offset
3689 + hppa_info->stub_sec->output_section->vma);
3691 /* Turn VALUE into a proper PC relative address. */
3692 value -= (offset + input_section->output_offset
3693 + input_section->output_section->vma);
3697 bfd_put_32 (input_bfd, value, hit_data);
3698 return bfd_reloc_ok;
3701 case R_PARISC_PCREL64:
3703 /* If this is a call to a function defined in another dynamic
3704 library, then redirect the call to the local stub for this
3706 if (sym_sec == NULL || sym_sec->output_section == NULL)
3707 value = (hh->stub_offset + hppa_info->stub_sec->output_offset
3708 + hppa_info->stub_sec->output_section->vma);
3710 /* Turn VALUE into a proper PC relative address. */
3711 value -= (offset + input_section->output_offset
3712 + input_section->output_section->vma);
3716 bfd_put_64 (input_bfd, value, hit_data);
3717 return bfd_reloc_ok;
3720 case R_PARISC_FPTR64:
3724 /* We may still need to create the FPTR itself if it was for
3728 bfd_vma *local_opd_offsets;
3730 if (local_offsets == NULL)
3733 local_opd_offsets = local_offsets + 2 * symtab_hdr->sh_info;
3734 off = local_opd_offsets[r_symndx];
3736 /* The last bit records whether we've already initialised
3737 this local .opd entry. */
3740 BFD_ASSERT (off != (bfd_vma) -1);
3745 /* The first two words of an .opd entry are zero. */
3746 memset (hppa_info->opd_sec->contents + off, 0, 16);
3748 /* The next word is the address of the function. */
3749 bfd_put_64 (hppa_info->opd_sec->owner, value + addend,
3750 (hppa_info->opd_sec->contents + off + 16));
3752 /* The last word is our local __gp value. */
3753 value = _bfd_get_gp_value
3754 (hppa_info->opd_sec->output_section->owner);
3755 bfd_put_64 (hppa_info->opd_sec->owner, value,
3756 hppa_info->opd_sec->contents + off + 24);
3760 off = hh->opd_offset;
3762 if (hh == NULL || hh->want_opd)
3763 /* We want the value of the OPD offset for this symbol. */
3765 + hppa_info->opd_sec->output_offset
3766 + hppa_info->opd_sec->output_section->vma);
3768 /* We want the address of the symbol. */
3771 bfd_put_64 (input_bfd, value, hit_data);
3772 return bfd_reloc_ok;
3775 case R_PARISC_SECREL32:
3777 value -= sym_sec->output_section->vma;
3778 bfd_put_32 (input_bfd, value + addend, hit_data);
3779 return bfd_reloc_ok;
3781 case R_PARISC_SEGREL32:
3782 case R_PARISC_SEGREL64:
3784 /* If this is the first SEGREL relocation, then initialize
3785 the segment base values. */
3786 if (hppa_info->text_segment_base == (bfd_vma) -1)
3787 bfd_map_over_sections (output_bfd, elf_hppa_record_segment_addrs,
3790 /* VALUE holds the absolute address. We want to include the
3791 addend, then turn it into a segment relative address.
3793 The segment is derived from SYM_SEC. We assume that there are
3794 only two segments of note in the resulting executable/shlib.
3795 A readonly segment (.text) and a readwrite segment (.data). */
3798 if (sym_sec->flags & SEC_CODE)
3799 value -= hppa_info->text_segment_base;
3801 value -= hppa_info->data_segment_base;
3803 if (r_type == R_PARISC_SEGREL32)
3804 bfd_put_32 (input_bfd, value, hit_data);
3806 bfd_put_64 (input_bfd, value, hit_data);
3807 return bfd_reloc_ok;
3810 /* Something we don't know how to handle. */
3812 return bfd_reloc_notsupported;
3815 /* Update the instruction word. */
3816 bfd_put_32 (input_bfd, (bfd_vma) insn, hit_data);
3817 return bfd_reloc_ok;
3820 /* Relocate an HPPA ELF section. */
3823 elf64_hppa_relocate_section (bfd *output_bfd,
3824 struct bfd_link_info *info,
3826 asection *input_section,
3828 Elf_Internal_Rela *relocs,
3829 Elf_Internal_Sym *local_syms,
3830 asection **local_sections)
3832 Elf_Internal_Shdr *symtab_hdr;
3833 Elf_Internal_Rela *rel;
3834 Elf_Internal_Rela *relend;
3835 struct elf64_hppa_link_hash_table *hppa_info;
3837 hppa_info = hppa_link_hash_table (info);
3838 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3841 relend = relocs + input_section->reloc_count;
3842 for (; rel < relend; rel++)
3845 reloc_howto_type *howto = elf_hppa_howto_table + ELF_R_TYPE (rel->r_info);
3846 unsigned long r_symndx;
3847 struct elf_link_hash_entry *eh;
3848 Elf_Internal_Sym *sym;
3851 bfd_reloc_status_type r;
3852 bfd_boolean warned_undef;
3854 r_type = ELF_R_TYPE (rel->r_info);
3855 if (r_type < 0 || r_type >= (int) R_PARISC_UNIMPLEMENTED)
3857 bfd_set_error (bfd_error_bad_value);
3860 if (r_type == (unsigned int) R_PARISC_GNU_VTENTRY
3861 || r_type == (unsigned int) R_PARISC_GNU_VTINHERIT)
3864 /* This is a final link. */
3865 r_symndx = ELF_R_SYM (rel->r_info);
3869 warned_undef = FALSE;
3870 if (r_symndx < symtab_hdr->sh_info)
3872 /* This is a local symbol, hh defaults to NULL. */
3873 sym = local_syms + r_symndx;
3874 sym_sec = local_sections[r_symndx];
3875 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sym_sec, rel);
3879 /* This is not a local symbol. */
3880 bfd_boolean unresolved_reloc;
3881 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
3883 /* It seems this can happen with erroneous or unsupported
3884 input (mixing a.out and elf in an archive, for example.) */
3885 if (sym_hashes == NULL)
3888 eh = sym_hashes[r_symndx - symtab_hdr->sh_info];
3890 while (eh->root.type == bfd_link_hash_indirect
3891 || eh->root.type == bfd_link_hash_warning)
3892 eh = (struct elf_link_hash_entry *) eh->root.u.i.link;
3894 warned_undef = FALSE;
3895 unresolved_reloc = FALSE;
3897 if (eh->root.type == bfd_link_hash_defined
3898 || eh->root.type == bfd_link_hash_defweak)
3900 sym_sec = eh->root.u.def.section;
3902 || sym_sec->output_section == NULL)
3903 /* Set a flag that will be cleared later if we find a
3904 relocation value for this symbol. output_section
3905 is typically NULL for symbols satisfied by a shared
3907 unresolved_reloc = TRUE;
3909 relocation = (eh->root.u.def.value
3910 + sym_sec->output_section->vma
3911 + sym_sec->output_offset);
3913 else if (eh->root.type == bfd_link_hash_undefweak)
3915 else if (info->unresolved_syms_in_objects == RM_IGNORE
3916 && ELF_ST_VISIBILITY (eh->other) == STV_DEFAULT)
3918 else if (!info->relocatable
3919 && elf_hppa_is_dynamic_loader_symbol (eh->root.root.string))
3921 else if (!info->relocatable)
3924 err = (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
3925 || ELF_ST_VISIBILITY (eh->other) != STV_DEFAULT);
3926 if (!info->callbacks->undefined_symbol (info,
3927 eh->root.root.string,
3930 rel->r_offset, err))
3932 warned_undef = TRUE;
3935 if (!info->relocatable
3937 && eh->root.type != bfd_link_hash_defined
3938 && eh->root.type != bfd_link_hash_defweak
3939 && eh->root.type != bfd_link_hash_undefweak)
3941 if (info->unresolved_syms_in_objects == RM_IGNORE
3942 && ELF_ST_VISIBILITY (eh->other) == STV_DEFAULT
3943 && eh->type == STT_PARISC_MILLI)
3945 if (! info->callbacks->undefined_symbol
3946 (info, eh_name (eh), input_bfd,
3947 input_section, rel->r_offset, FALSE))
3949 warned_undef = TRUE;
3954 if (sym_sec != NULL && elf_discarded_section (sym_sec))
3956 /* For relocs against symbols from removed linkonce sections,
3957 or sections discarded by a linker script, we just want the
3958 section contents zeroed. Avoid any special processing. */
3959 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
3965 if (info->relocatable)
3968 r = elf_hppa_final_link_relocate (rel, input_bfd, output_bfd,
3969 input_section, contents,
3970 relocation, info, sym_sec,
3973 if (r != bfd_reloc_ok)
3979 case bfd_reloc_overflow:
3981 const char *sym_name;
3987 sym_name = bfd_elf_string_from_elf_section (input_bfd,
3988 symtab_hdr->sh_link,
3990 if (sym_name == NULL)
3992 if (*sym_name == '\0')
3993 sym_name = bfd_section_name (input_bfd, sym_sec);
3996 if (!((*info->callbacks->reloc_overflow)
3997 (info, (eh ? &eh->root : NULL), sym_name,
3998 howto->name, (bfd_vma) 0, input_bfd,
3999 input_section, rel->r_offset)))
4009 static const struct bfd_elf_special_section elf64_hppa_special_sections[] =
4011 { STRING_COMMA_LEN (".fini"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
4012 { STRING_COMMA_LEN (".init"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
4013 { STRING_COMMA_LEN (".plt"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT },
4014 { STRING_COMMA_LEN (".dlt"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT },
4015 { STRING_COMMA_LEN (".sdata"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT },
4016 { STRING_COMMA_LEN (".sbss"), 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT },
4017 { STRING_COMMA_LEN (".tbss"), 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_HP_TLS },
4018 { NULL, 0, 0, 0, 0 }
4021 /* The hash bucket size is the standard one, namely 4. */
4023 const struct elf_size_info hppa64_elf_size_info =
4025 sizeof (Elf64_External_Ehdr),
4026 sizeof (Elf64_External_Phdr),
4027 sizeof (Elf64_External_Shdr),
4028 sizeof (Elf64_External_Rel),
4029 sizeof (Elf64_External_Rela),
4030 sizeof (Elf64_External_Sym),
4031 sizeof (Elf64_External_Dyn),
4032 sizeof (Elf_External_Note),
4036 ELFCLASS64, EV_CURRENT,
4037 bfd_elf64_write_out_phdrs,
4038 bfd_elf64_write_shdrs_and_ehdr,
4039 bfd_elf64_checksum_contents,
4040 bfd_elf64_write_relocs,
4041 bfd_elf64_swap_symbol_in,
4042 bfd_elf64_swap_symbol_out,
4043 bfd_elf64_slurp_reloc_table,
4044 bfd_elf64_slurp_symbol_table,
4045 bfd_elf64_swap_dyn_in,
4046 bfd_elf64_swap_dyn_out,
4047 bfd_elf64_swap_reloc_in,
4048 bfd_elf64_swap_reloc_out,
4049 bfd_elf64_swap_reloca_in,
4050 bfd_elf64_swap_reloca_out
4053 #define TARGET_BIG_SYM bfd_elf64_hppa_vec
4054 #define TARGET_BIG_NAME "elf64-hppa"
4055 #define ELF_ARCH bfd_arch_hppa
4056 #define ELF_MACHINE_CODE EM_PARISC
4057 /* This is not strictly correct. The maximum page size for PA2.0 is
4058 64M. But everything still uses 4k. */
4059 #define ELF_MAXPAGESIZE 0x1000
4060 #define ELF_OSABI ELFOSABI_HPUX
4062 #define bfd_elf64_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
4063 #define bfd_elf64_bfd_reloc_name_lookup elf_hppa_reloc_name_lookup
4064 #define bfd_elf64_bfd_is_local_label_name elf_hppa_is_local_label_name
4065 #define elf_info_to_howto elf_hppa_info_to_howto
4066 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
4068 #define elf_backend_section_from_shdr elf64_hppa_section_from_shdr
4069 #define elf_backend_object_p elf64_hppa_object_p
4070 #define elf_backend_final_write_processing \
4071 elf_hppa_final_write_processing
4072 #define elf_backend_fake_sections elf_hppa_fake_sections
4073 #define elf_backend_add_symbol_hook elf_hppa_add_symbol_hook
4075 #define elf_backend_relocate_section elf_hppa_relocate_section
4077 #define bfd_elf64_bfd_final_link elf_hppa_final_link
4079 #define elf_backend_create_dynamic_sections \
4080 elf64_hppa_create_dynamic_sections
4081 #define elf_backend_post_process_headers elf64_hppa_post_process_headers
4083 #define elf_backend_omit_section_dynsym \
4084 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
4085 #define elf_backend_adjust_dynamic_symbol \
4086 elf64_hppa_adjust_dynamic_symbol
4088 #define elf_backend_size_dynamic_sections \
4089 elf64_hppa_size_dynamic_sections
4091 #define elf_backend_finish_dynamic_symbol \
4092 elf64_hppa_finish_dynamic_symbol
4093 #define elf_backend_finish_dynamic_sections \
4094 elf64_hppa_finish_dynamic_sections
4095 #define elf_backend_grok_prstatus elf64_hppa_grok_prstatus
4096 #define elf_backend_grok_psinfo elf64_hppa_grok_psinfo
4098 /* Stuff for the BFD linker: */
4099 #define bfd_elf64_bfd_link_hash_table_create \
4100 elf64_hppa_hash_table_create
4102 #define elf_backend_check_relocs \
4103 elf64_hppa_check_relocs
4105 #define elf_backend_size_info \
4106 hppa64_elf_size_info
4108 #define elf_backend_additional_program_headers \
4109 elf64_hppa_additional_program_headers
4111 #define elf_backend_modify_segment_map \
4112 elf64_hppa_modify_segment_map
4114 #define elf_backend_link_output_symbol_hook \
4115 elf64_hppa_link_output_symbol_hook
4117 #define elf_backend_want_got_plt 0
4118 #define elf_backend_plt_readonly 0
4119 #define elf_backend_want_plt_sym 0
4120 #define elf_backend_got_header_size 0
4121 #define elf_backend_type_change_ok TRUE
4122 #define elf_backend_get_symbol_type elf64_hppa_elf_get_symbol_type
4123 #define elf_backend_reloc_type_class elf64_hppa_reloc_type_class
4124 #define elf_backend_rela_normal 1
4125 #define elf_backend_special_sections elf64_hppa_special_sections
4126 #define elf_backend_action_discarded elf_hppa_action_discarded
4127 #define elf_backend_section_from_phdr elf64_hppa_section_from_phdr
4129 #define elf64_bed elf64_hppa_hpux_bed
4131 #include "elf64-target.h"
4133 #undef TARGET_BIG_SYM
4134 #define TARGET_BIG_SYM bfd_elf64_hppa_linux_vec
4135 #undef TARGET_BIG_NAME
4136 #define TARGET_BIG_NAME "elf64-hppa-linux"
4138 #define ELF_OSABI ELFOSABI_LINUX
4139 #undef elf_backend_post_process_headers
4140 #define elf_backend_post_process_headers _bfd_elf_set_osabi
4142 #define elf64_bed elf64_hppa_linux_bed
4144 #include "elf64-target.h"