PR gas/5712
[binutils.git] / bfd / elf64-hppa.c
blobb2032050496a90d5f2582fa381e426bf42fb0657
1 /* Support for HPPA 64-bit ELF
2 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
3 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
22 #include "sysdep.h"
23 #include "bfd.h"
24 #include "libbfd.h"
25 #include "elf-bfd.h"
26 #include "elf/hppa.h"
27 #include "libhppa.h"
28 #include "elf64-hppa.h"
30 /* This is the code recommended in the autoconf documentation, almost
31 verbatim. */
32 #ifndef __GNUC__
33 # if HAVE_ALLOCA_H
34 # include <alloca.h>
35 # else
36 # ifdef _AIX
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
39 thing in the file. */
40 #pragma alloca
41 # else
42 # ifndef alloca /* predefined by HP cc +Olibcalls */
43 # if !defined (__STDC__) && !defined (__hpux)
44 extern char *alloca ();
45 # else
46 extern void *alloca ();
47 # endif /* __STDC__, __hpux */
48 # endif /* alloca */
49 # endif /* _AIX */
50 # endif /* HAVE_ALLOCA_H */
51 #else
52 extern void *alloca (size_t);
53 #endif /* __GNUC__ */
56 #define ARCH_SIZE 64
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
66 address.
68 LDD PLTOFF(%r27),%r1
69 BVE (%r1)
70 LDD PLTOFF+8(%r27),%r27
72 Note that we must use the LDD with a 14 bit displacement, not the one
73 with a 5 bit displacement. */
74 static char plt_stub[] = {0x53, 0x61, 0x00, 0x00, 0xe8, 0x20, 0xd0, 0x00,
75 0x53, 0x7b, 0x00, 0x00 };
77 struct elf64_hppa_dyn_hash_entry
79 struct bfd_hash_entry root;
81 /* Offsets for this symbol in various linker sections. */
82 bfd_vma dlt_offset;
83 bfd_vma plt_offset;
84 bfd_vma opd_offset;
85 bfd_vma stub_offset;
87 /* The symbol table entry, if any, that this was derived from. */
88 struct elf_link_hash_entry *h;
90 /* The index of the (possibly local) symbol in the input bfd and its
91 associated BFD. Needed so that we can have relocs against local
92 symbols in shared libraries. */
93 long sym_indx;
94 bfd *owner;
96 /* Dynamic symbols may need to have two different values. One for
97 the dynamic symbol table, one for the normal symbol table.
99 In such cases we store the symbol's real value and section
100 index here so we can restore the real value before we write
101 the normal symbol table. */
102 bfd_vma st_value;
103 int st_shndx;
105 /* Used to count non-got, non-plt relocations for delayed sizing
106 of relocation sections. */
107 struct elf64_hppa_dyn_reloc_entry
109 /* Next relocation in the chain. */
110 struct elf64_hppa_dyn_reloc_entry *next;
112 /* The type of the relocation. */
113 int type;
115 /* The input section of the relocation. */
116 asection *sec;
118 /* The index of the section symbol for the input section of
119 the relocation. Only needed when building shared libraries. */
120 int sec_symndx;
122 /* The offset within the input section of the relocation. */
123 bfd_vma offset;
125 /* The addend for the relocation. */
126 bfd_vma addend;
128 } *reloc_entries;
130 /* Nonzero if this symbol needs an entry in one of the linker
131 sections. */
132 unsigned want_dlt;
133 unsigned want_plt;
134 unsigned want_opd;
135 unsigned want_stub;
138 struct elf64_hppa_dyn_hash_table
140 struct bfd_hash_table root;
143 struct elf64_hppa_link_hash_table
145 struct elf_link_hash_table root;
147 /* Shortcuts to get to the various linker defined sections. */
148 asection *dlt_sec;
149 asection *dlt_rel_sec;
150 asection *plt_sec;
151 asection *plt_rel_sec;
152 asection *opd_sec;
153 asection *opd_rel_sec;
154 asection *other_rel_sec;
156 /* Offset of __gp within .plt section. When the PLT gets large we want
157 to slide __gp into the PLT section so that we can continue to use
158 single DP relative instructions to load values out of the PLT. */
159 bfd_vma gp_offset;
161 /* Note this is not strictly correct. We should create a stub section for
162 each input section with calls. The stub section should be placed before
163 the section with the call. */
164 asection *stub_sec;
166 bfd_vma text_segment_base;
167 bfd_vma data_segment_base;
169 struct elf64_hppa_dyn_hash_table dyn_hash_table;
171 /* We build tables to map from an input section back to its
172 symbol index. This is the BFD for which we currently have
173 a map. */
174 bfd *section_syms_bfd;
176 /* Array of symbol numbers for each input section attached to the
177 current BFD. */
178 int *section_syms;
181 #define elf64_hppa_hash_table(p) \
182 ((struct elf64_hppa_link_hash_table *) ((p)->hash))
184 typedef struct bfd_hash_entry *(*new_hash_entry_func)
185 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
187 static struct bfd_hash_entry *elf64_hppa_new_dyn_hash_entry
188 PARAMS ((struct bfd_hash_entry *entry, struct bfd_hash_table *table,
189 const char *string));
190 static struct bfd_link_hash_table *elf64_hppa_hash_table_create
191 PARAMS ((bfd *abfd));
192 static struct elf64_hppa_dyn_hash_entry *elf64_hppa_dyn_hash_lookup
193 PARAMS ((struct elf64_hppa_dyn_hash_table *table, const char *string,
194 bfd_boolean create, bfd_boolean copy));
195 static void elf64_hppa_dyn_hash_traverse
196 PARAMS ((struct elf64_hppa_dyn_hash_table *table,
197 bfd_boolean (*func) (struct elf64_hppa_dyn_hash_entry *, PTR),
198 PTR info));
200 static const char *get_dyn_name
201 PARAMS ((bfd *, struct elf_link_hash_entry *,
202 const Elf_Internal_Rela *, char **, size_t *));
204 /* This must follow the definitions of the various derived linker
205 hash tables and shared functions. */
206 #include "elf-hppa.h"
208 static bfd_boolean elf64_hppa_object_p
209 PARAMS ((bfd *));
211 static void elf64_hppa_post_process_headers
212 PARAMS ((bfd *, struct bfd_link_info *));
214 static bfd_boolean elf64_hppa_create_dynamic_sections
215 PARAMS ((bfd *, struct bfd_link_info *));
217 static bfd_boolean elf64_hppa_adjust_dynamic_symbol
218 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
220 static bfd_boolean elf64_hppa_mark_milli_and_exported_functions
221 PARAMS ((struct elf_link_hash_entry *, PTR));
223 static bfd_boolean elf64_hppa_size_dynamic_sections
224 PARAMS ((bfd *, struct bfd_link_info *));
226 static bfd_boolean elf64_hppa_link_output_symbol_hook
227 PARAMS ((struct bfd_link_info *, const char *, Elf_Internal_Sym *,
228 asection *, struct elf_link_hash_entry *));
230 static bfd_boolean elf64_hppa_finish_dynamic_symbol
231 PARAMS ((bfd *, struct bfd_link_info *,
232 struct elf_link_hash_entry *, Elf_Internal_Sym *));
234 static enum elf_reloc_type_class elf64_hppa_reloc_type_class
235 PARAMS ((const Elf_Internal_Rela *));
237 static bfd_boolean elf64_hppa_finish_dynamic_sections
238 PARAMS ((bfd *, struct bfd_link_info *));
240 static bfd_boolean elf64_hppa_check_relocs
241 PARAMS ((bfd *, struct bfd_link_info *,
242 asection *, const Elf_Internal_Rela *));
244 static bfd_boolean elf64_hppa_dynamic_symbol_p
245 PARAMS ((struct elf_link_hash_entry *, struct bfd_link_info *));
247 static bfd_boolean elf64_hppa_mark_exported_functions
248 PARAMS ((struct elf_link_hash_entry *, PTR));
250 static bfd_boolean elf64_hppa_finalize_opd
251 PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
253 static bfd_boolean elf64_hppa_finalize_dlt
254 PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
256 static bfd_boolean allocate_global_data_dlt
257 PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
259 static bfd_boolean allocate_global_data_plt
260 PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
262 static bfd_boolean allocate_global_data_stub
263 PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
265 static bfd_boolean allocate_global_data_opd
266 PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
268 static bfd_boolean get_reloc_section
269 PARAMS ((bfd *, struct elf64_hppa_link_hash_table *, asection *));
271 static bfd_boolean count_dyn_reloc
272 PARAMS ((bfd *, struct elf64_hppa_dyn_hash_entry *,
273 int, asection *, int, bfd_vma, bfd_vma));
275 static bfd_boolean allocate_dynrel_entries
276 PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
278 static bfd_boolean elf64_hppa_finalize_dynreloc
279 PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
281 static bfd_boolean get_opd
282 PARAMS ((bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *));
284 static bfd_boolean get_plt
285 PARAMS ((bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *));
287 static bfd_boolean get_dlt
288 PARAMS ((bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *));
290 static bfd_boolean get_stub
291 PARAMS ((bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *));
293 static int elf64_hppa_elf_get_symbol_type
294 PARAMS ((Elf_Internal_Sym *, int));
296 static bfd_boolean
297 elf64_hppa_dyn_hash_table_init (struct elf64_hppa_dyn_hash_table *ht,
298 bfd *abfd ATTRIBUTE_UNUSED,
299 new_hash_entry_func new,
300 unsigned int entsize)
302 memset (ht, 0, sizeof (*ht));
303 return bfd_hash_table_init (&ht->root, new, entsize);
306 static struct bfd_hash_entry*
307 elf64_hppa_new_dyn_hash_entry (entry, table, string)
308 struct bfd_hash_entry *entry;
309 struct bfd_hash_table *table;
310 const char *string;
312 struct elf64_hppa_dyn_hash_entry *ret;
313 ret = (struct elf64_hppa_dyn_hash_entry *) entry;
315 /* Allocate the structure if it has not already been allocated by a
316 subclass. */
317 if (!ret)
318 ret = bfd_hash_allocate (table, sizeof (*ret));
320 if (!ret)
321 return 0;
323 /* Call the allocation method of the superclass. */
324 ret = ((struct elf64_hppa_dyn_hash_entry *)
325 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
327 /* Initialize our local data. All zeros. */
328 memset (&ret->dlt_offset, 0,
329 (sizeof (struct elf64_hppa_dyn_hash_entry)
330 - offsetof (struct elf64_hppa_dyn_hash_entry, dlt_offset)));
332 return &ret->root;
335 /* Create the derived linker hash table. The PA64 ELF port uses this
336 derived hash table to keep information specific to the PA ElF
337 linker (without using static variables). */
339 static struct bfd_link_hash_table*
340 elf64_hppa_hash_table_create (abfd)
341 bfd *abfd;
343 struct elf64_hppa_link_hash_table *ret;
345 ret = bfd_zalloc (abfd, (bfd_size_type) sizeof (*ret));
346 if (!ret)
347 return 0;
348 if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
349 _bfd_elf_link_hash_newfunc,
350 sizeof (struct elf_link_hash_entry)))
352 bfd_release (abfd, ret);
353 return 0;
356 if (!elf64_hppa_dyn_hash_table_init (&ret->dyn_hash_table, abfd,
357 elf64_hppa_new_dyn_hash_entry,
358 sizeof (struct elf64_hppa_dyn_hash_entry)))
359 return 0;
360 return &ret->root.root;
363 /* Look up an entry in a PA64 ELF linker hash table. */
365 static struct elf64_hppa_dyn_hash_entry *
366 elf64_hppa_dyn_hash_lookup(table, string, create, copy)
367 struct elf64_hppa_dyn_hash_table *table;
368 const char *string;
369 bfd_boolean create, copy;
371 return ((struct elf64_hppa_dyn_hash_entry *)
372 bfd_hash_lookup (&table->root, string, create, copy));
375 /* Traverse a PA64 ELF linker hash table. */
377 static void
378 elf64_hppa_dyn_hash_traverse (table, func, info)
379 struct elf64_hppa_dyn_hash_table *table;
380 bfd_boolean (*func) PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
381 PTR info;
383 (bfd_hash_traverse
384 (&table->root,
385 (bfd_boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) func,
386 info));
389 /* Return nonzero if ABFD represents a PA2.0 ELF64 file.
391 Additionally we set the default architecture and machine. */
392 static bfd_boolean
393 elf64_hppa_object_p (abfd)
394 bfd *abfd;
396 Elf_Internal_Ehdr * i_ehdrp;
397 unsigned int flags;
399 i_ehdrp = elf_elfheader (abfd);
400 if (strcmp (bfd_get_target (abfd), "elf64-hppa-linux") == 0)
402 /* GCC on hppa-linux produces binaries with OSABI=Linux,
403 but the kernel produces corefiles with OSABI=SysV. */
404 if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_LINUX
405 && i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_NONE) /* aka SYSV */
406 return FALSE;
408 else
410 /* HPUX produces binaries with OSABI=HPUX,
411 but the kernel produces corefiles with OSABI=SysV. */
412 if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_HPUX
413 && i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_NONE) /* aka SYSV */
414 return FALSE;
417 flags = i_ehdrp->e_flags;
418 switch (flags & (EF_PARISC_ARCH | EF_PARISC_WIDE))
420 case EFA_PARISC_1_0:
421 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 10);
422 case EFA_PARISC_1_1:
423 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 11);
424 case EFA_PARISC_2_0:
425 if (i_ehdrp->e_ident[EI_CLASS] == ELFCLASS64)
426 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 25);
427 else
428 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 20);
429 case EFA_PARISC_2_0 | EF_PARISC_WIDE:
430 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 25);
432 /* Don't be fussy. */
433 return TRUE;
436 /* Given section type (hdr->sh_type), return a boolean indicating
437 whether or not the section is an elf64-hppa specific section. */
438 static bfd_boolean
439 elf64_hppa_section_from_shdr (bfd *abfd,
440 Elf_Internal_Shdr *hdr,
441 const char *name,
442 int shindex)
444 asection *newsect;
446 switch (hdr->sh_type)
448 case SHT_PARISC_EXT:
449 if (strcmp (name, ".PARISC.archext") != 0)
450 return FALSE;
451 break;
452 case SHT_PARISC_UNWIND:
453 if (strcmp (name, ".PARISC.unwind") != 0)
454 return FALSE;
455 break;
456 case SHT_PARISC_DOC:
457 case SHT_PARISC_ANNOT:
458 default:
459 return FALSE;
462 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
463 return FALSE;
464 newsect = hdr->bfd_section;
466 return TRUE;
469 /* Construct a string for use in the elf64_hppa_dyn_hash_table. The
470 name describes what was once potentially anonymous memory. We
471 allocate memory as necessary, possibly reusing PBUF/PLEN. */
473 static const char *
474 get_dyn_name (abfd, h, rel, pbuf, plen)
475 bfd *abfd;
476 struct elf_link_hash_entry *h;
477 const Elf_Internal_Rela *rel;
478 char **pbuf;
479 size_t *plen;
481 asection *sec = abfd->sections;
482 size_t nlen, tlen;
483 char *buf;
484 size_t len;
486 if (h && rel->r_addend == 0)
487 return h->root.root.string;
489 if (h)
490 nlen = strlen (h->root.root.string);
491 else
492 nlen = 8 + 1 + sizeof (rel->r_info) * 2 - 8;
493 tlen = nlen + 1 + sizeof (rel->r_addend) * 2 + 1;
495 len = *plen;
496 buf = *pbuf;
497 if (len < tlen)
499 if (buf)
500 free (buf);
501 *pbuf = buf = malloc (tlen);
502 *plen = len = tlen;
503 if (!buf)
504 return NULL;
507 if (h)
509 memcpy (buf, h->root.root.string, nlen);
510 buf[nlen++] = '+';
511 sprintf_vma (buf + nlen, rel->r_addend);
513 else
515 nlen = sprintf (buf, "%x:%lx",
516 sec->id & 0xffffffff,
517 (long) ELF64_R_SYM (rel->r_info));
518 if (rel->r_addend)
520 buf[nlen++] = '+';
521 sprintf_vma (buf + nlen, rel->r_addend);
525 return buf;
528 /* SEC is a section containing relocs for an input BFD when linking; return
529 a suitable section for holding relocs in the output BFD for a link. */
531 static bfd_boolean
532 get_reloc_section (abfd, hppa_info, sec)
533 bfd *abfd;
534 struct elf64_hppa_link_hash_table *hppa_info;
535 asection *sec;
537 const char *srel_name;
538 asection *srel;
539 bfd *dynobj;
541 srel_name = (bfd_elf_string_from_elf_section
542 (abfd, elf_elfheader(abfd)->e_shstrndx,
543 elf_section_data(sec)->rel_hdr.sh_name));
544 if (srel_name == NULL)
545 return FALSE;
547 BFD_ASSERT ((CONST_STRNEQ (srel_name, ".rela")
548 && strcmp (bfd_get_section_name (abfd, sec),
549 srel_name + 5) == 0)
550 || (CONST_STRNEQ (srel_name, ".rel")
551 && strcmp (bfd_get_section_name (abfd, sec),
552 srel_name + 4) == 0));
554 dynobj = hppa_info->root.dynobj;
555 if (!dynobj)
556 hppa_info->root.dynobj = dynobj = abfd;
558 srel = bfd_get_section_by_name (dynobj, srel_name);
559 if (srel == NULL)
561 srel = bfd_make_section_with_flags (dynobj, srel_name,
562 (SEC_ALLOC
563 | SEC_LOAD
564 | SEC_HAS_CONTENTS
565 | SEC_IN_MEMORY
566 | SEC_LINKER_CREATED
567 | SEC_READONLY));
568 if (srel == NULL
569 || !bfd_set_section_alignment (dynobj, srel, 3))
570 return FALSE;
573 hppa_info->other_rel_sec = srel;
574 return TRUE;
577 /* Add a new entry to the list of dynamic relocations against DYN_H.
579 We use this to keep a record of all the FPTR relocations against a
580 particular symbol so that we can create FPTR relocations in the
581 output file. */
583 static bfd_boolean
584 count_dyn_reloc (abfd, dyn_h, type, sec, sec_symndx, offset, addend)
585 bfd *abfd;
586 struct elf64_hppa_dyn_hash_entry *dyn_h;
587 int type;
588 asection *sec;
589 int sec_symndx;
590 bfd_vma offset;
591 bfd_vma addend;
593 struct elf64_hppa_dyn_reloc_entry *rent;
595 rent = (struct elf64_hppa_dyn_reloc_entry *)
596 bfd_alloc (abfd, (bfd_size_type) sizeof (*rent));
597 if (!rent)
598 return FALSE;
600 rent->next = dyn_h->reloc_entries;
601 rent->type = type;
602 rent->sec = sec;
603 rent->sec_symndx = sec_symndx;
604 rent->offset = offset;
605 rent->addend = addend;
606 dyn_h->reloc_entries = rent;
608 return TRUE;
611 /* Scan the RELOCS and record the type of dynamic entries that each
612 referenced symbol needs. */
614 static bfd_boolean
615 elf64_hppa_check_relocs (abfd, info, sec, relocs)
616 bfd *abfd;
617 struct bfd_link_info *info;
618 asection *sec;
619 const Elf_Internal_Rela *relocs;
621 struct elf64_hppa_link_hash_table *hppa_info;
622 const Elf_Internal_Rela *relend;
623 Elf_Internal_Shdr *symtab_hdr;
624 const Elf_Internal_Rela *rel;
625 asection *dlt, *plt, *stubs;
626 char *buf;
627 size_t buf_len;
628 int sec_symndx;
630 if (info->relocatable)
631 return TRUE;
633 /* If this is the first dynamic object found in the link, create
634 the special sections required for dynamic linking. */
635 if (! elf_hash_table (info)->dynamic_sections_created)
637 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
638 return FALSE;
641 hppa_info = elf64_hppa_hash_table (info);
642 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
644 /* If necessary, build a new table holding section symbols indices
645 for this BFD. */
647 if (info->shared && hppa_info->section_syms_bfd != abfd)
649 unsigned long i;
650 unsigned int highest_shndx;
651 Elf_Internal_Sym *local_syms = NULL;
652 Elf_Internal_Sym *isym, *isymend;
653 bfd_size_type amt;
655 /* We're done with the old cache of section index to section symbol
656 index information. Free it.
658 ?!? Note we leak the last section_syms array. Presumably we
659 could free it in one of the later routines in this file. */
660 if (hppa_info->section_syms)
661 free (hppa_info->section_syms);
663 /* Read this BFD's local symbols. */
664 if (symtab_hdr->sh_info != 0)
666 local_syms = (Elf_Internal_Sym *) symtab_hdr->contents;
667 if (local_syms == NULL)
668 local_syms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
669 symtab_hdr->sh_info, 0,
670 NULL, NULL, NULL);
671 if (local_syms == NULL)
672 return FALSE;
675 /* Record the highest section index referenced by the local symbols. */
676 highest_shndx = 0;
677 isymend = local_syms + symtab_hdr->sh_info;
678 for (isym = local_syms; isym < isymend; isym++)
680 if (isym->st_shndx > highest_shndx)
681 highest_shndx = isym->st_shndx;
684 /* Allocate an array to hold the section index to section symbol index
685 mapping. Bump by one since we start counting at zero. */
686 highest_shndx++;
687 amt = highest_shndx;
688 amt *= sizeof (int);
689 hppa_info->section_syms = (int *) bfd_malloc (amt);
691 /* Now walk the local symbols again. If we find a section symbol,
692 record the index of the symbol into the section_syms array. */
693 for (i = 0, isym = local_syms; isym < isymend; i++, isym++)
695 if (ELF_ST_TYPE (isym->st_info) == STT_SECTION)
696 hppa_info->section_syms[isym->st_shndx] = i;
699 /* We are finished with the local symbols. */
700 if (local_syms != NULL
701 && symtab_hdr->contents != (unsigned char *) local_syms)
703 if (! info->keep_memory)
704 free (local_syms);
705 else
707 /* Cache the symbols for elf_link_input_bfd. */
708 symtab_hdr->contents = (unsigned char *) local_syms;
712 /* Record which BFD we built the section_syms mapping for. */
713 hppa_info->section_syms_bfd = abfd;
716 /* Record the symbol index for this input section. We may need it for
717 relocations when building shared libraries. When not building shared
718 libraries this value is never really used, but assign it to zero to
719 prevent out of bounds memory accesses in other routines. */
720 if (info->shared)
722 sec_symndx = _bfd_elf_section_from_bfd_section (abfd, sec);
724 /* If we did not find a section symbol for this section, then
725 something went terribly wrong above. */
726 if (sec_symndx == -1)
727 return FALSE;
729 sec_symndx = hppa_info->section_syms[sec_symndx];
731 else
732 sec_symndx = 0;
734 dlt = plt = stubs = NULL;
735 buf = NULL;
736 buf_len = 0;
738 relend = relocs + sec->reloc_count;
739 for (rel = relocs; rel < relend; ++rel)
741 enum
743 NEED_DLT = 1,
744 NEED_PLT = 2,
745 NEED_STUB = 4,
746 NEED_OPD = 8,
747 NEED_DYNREL = 16,
750 struct elf_link_hash_entry *h = NULL;
751 unsigned long r_symndx = ELF64_R_SYM (rel->r_info);
752 struct elf64_hppa_dyn_hash_entry *dyn_h;
753 int need_entry;
754 const char *addr_name;
755 bfd_boolean maybe_dynamic;
756 int dynrel_type = R_PARISC_NONE;
757 static reloc_howto_type *howto;
759 if (r_symndx >= symtab_hdr->sh_info)
761 /* We're dealing with a global symbol -- find its hash entry
762 and mark it as being referenced. */
763 long indx = r_symndx - symtab_hdr->sh_info;
764 h = elf_sym_hashes (abfd)[indx];
765 while (h->root.type == bfd_link_hash_indirect
766 || h->root.type == bfd_link_hash_warning)
767 h = (struct elf_link_hash_entry *) h->root.u.i.link;
769 h->ref_regular = 1;
772 /* We can only get preliminary data on whether a symbol is
773 locally or externally defined, as not all of the input files
774 have yet been processed. Do something with what we know, as
775 this may help reduce memory usage and processing time later. */
776 maybe_dynamic = FALSE;
777 if (h && ((info->shared
778 && (!info->symbolic
779 || info->unresolved_syms_in_shared_libs == RM_IGNORE))
780 || !h->def_regular
781 || h->root.type == bfd_link_hash_defweak))
782 maybe_dynamic = TRUE;
784 howto = elf_hppa_howto_table + ELF64_R_TYPE (rel->r_info);
785 need_entry = 0;
786 switch (howto->type)
788 /* These are simple indirect references to symbols through the
789 DLT. We need to create a DLT entry for any symbols which
790 appears in a DLTIND relocation. */
791 case R_PARISC_DLTIND21L:
792 case R_PARISC_DLTIND14R:
793 case R_PARISC_DLTIND14F:
794 case R_PARISC_DLTIND14WR:
795 case R_PARISC_DLTIND14DR:
796 need_entry = NEED_DLT;
797 break;
799 /* ?!? These need a DLT entry. But I have no idea what to do with
800 the "link time TP value. */
801 case R_PARISC_LTOFF_TP21L:
802 case R_PARISC_LTOFF_TP14R:
803 case R_PARISC_LTOFF_TP14F:
804 case R_PARISC_LTOFF_TP64:
805 case R_PARISC_LTOFF_TP14WR:
806 case R_PARISC_LTOFF_TP14DR:
807 case R_PARISC_LTOFF_TP16F:
808 case R_PARISC_LTOFF_TP16WF:
809 case R_PARISC_LTOFF_TP16DF:
810 need_entry = NEED_DLT;
811 break;
813 /* These are function calls. Depending on their precise target we
814 may need to make a stub for them. The stub uses the PLT, so we
815 need to create PLT entries for these symbols too. */
816 case R_PARISC_PCREL12F:
817 case R_PARISC_PCREL17F:
818 case R_PARISC_PCREL22F:
819 case R_PARISC_PCREL32:
820 case R_PARISC_PCREL64:
821 case R_PARISC_PCREL21L:
822 case R_PARISC_PCREL17R:
823 case R_PARISC_PCREL17C:
824 case R_PARISC_PCREL14R:
825 case R_PARISC_PCREL14F:
826 case R_PARISC_PCREL22C:
827 case R_PARISC_PCREL14WR:
828 case R_PARISC_PCREL14DR:
829 case R_PARISC_PCREL16F:
830 case R_PARISC_PCREL16WF:
831 case R_PARISC_PCREL16DF:
832 need_entry = (NEED_PLT | NEED_STUB);
833 break;
835 case R_PARISC_PLTOFF21L:
836 case R_PARISC_PLTOFF14R:
837 case R_PARISC_PLTOFF14F:
838 case R_PARISC_PLTOFF14WR:
839 case R_PARISC_PLTOFF14DR:
840 case R_PARISC_PLTOFF16F:
841 case R_PARISC_PLTOFF16WF:
842 case R_PARISC_PLTOFF16DF:
843 need_entry = (NEED_PLT);
844 break;
846 case R_PARISC_DIR64:
847 if (info->shared || maybe_dynamic)
848 need_entry = (NEED_DYNREL);
849 dynrel_type = R_PARISC_DIR64;
850 break;
852 /* This is an indirect reference through the DLT to get the address
853 of a OPD descriptor. Thus we need to make a DLT entry that points
854 to an OPD entry. */
855 case R_PARISC_LTOFF_FPTR21L:
856 case R_PARISC_LTOFF_FPTR14R:
857 case R_PARISC_LTOFF_FPTR14WR:
858 case R_PARISC_LTOFF_FPTR14DR:
859 case R_PARISC_LTOFF_FPTR32:
860 case R_PARISC_LTOFF_FPTR64:
861 case R_PARISC_LTOFF_FPTR16F:
862 case R_PARISC_LTOFF_FPTR16WF:
863 case R_PARISC_LTOFF_FPTR16DF:
864 if (info->shared || maybe_dynamic)
865 need_entry = (NEED_DLT | NEED_OPD);
866 else
867 need_entry = (NEED_DLT | NEED_OPD);
868 dynrel_type = R_PARISC_FPTR64;
869 break;
871 /* This is a simple OPD entry. */
872 case R_PARISC_FPTR64:
873 if (info->shared || maybe_dynamic)
874 need_entry = (NEED_OPD | NEED_DYNREL);
875 else
876 need_entry = (NEED_OPD);
877 dynrel_type = R_PARISC_FPTR64;
878 break;
880 /* Add more cases as needed. */
883 if (!need_entry)
884 continue;
886 /* Collect a canonical name for this address. */
887 addr_name = get_dyn_name (abfd, h, rel, &buf, &buf_len);
889 /* Collect the canonical entry data for this address. */
890 dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table,
891 addr_name, TRUE, TRUE);
892 BFD_ASSERT (dyn_h);
894 /* Stash away enough information to be able to find this symbol
895 regardless of whether or not it is local or global. */
896 dyn_h->h = h;
897 dyn_h->owner = abfd;
898 dyn_h->sym_indx = r_symndx;
900 /* ?!? We may need to do some error checking in here. */
901 /* Create what's needed. */
902 if (need_entry & NEED_DLT)
904 if (! hppa_info->dlt_sec
905 && ! get_dlt (abfd, info, hppa_info))
906 goto err_out;
907 dyn_h->want_dlt = 1;
910 if (need_entry & NEED_PLT)
912 if (! hppa_info->plt_sec
913 && ! get_plt (abfd, info, hppa_info))
914 goto err_out;
915 dyn_h->want_plt = 1;
918 if (need_entry & NEED_STUB)
920 if (! hppa_info->stub_sec
921 && ! get_stub (abfd, info, hppa_info))
922 goto err_out;
923 dyn_h->want_stub = 1;
926 if (need_entry & NEED_OPD)
928 if (! hppa_info->opd_sec
929 && ! get_opd (abfd, info, hppa_info))
930 goto err_out;
932 dyn_h->want_opd = 1;
934 /* FPTRs are not allocated by the dynamic linker for PA64, though
935 it is possible that will change in the future. */
937 /* This could be a local function that had its address taken, in
938 which case H will be NULL. */
939 if (h)
940 h->needs_plt = 1;
943 /* Add a new dynamic relocation to the chain of dynamic
944 relocations for this symbol. */
945 if ((need_entry & NEED_DYNREL) && (sec->flags & SEC_ALLOC))
947 if (! hppa_info->other_rel_sec
948 && ! get_reloc_section (abfd, hppa_info, sec))
949 goto err_out;
951 if (!count_dyn_reloc (abfd, dyn_h, dynrel_type, sec,
952 sec_symndx, rel->r_offset, rel->r_addend))
953 goto err_out;
955 /* If we are building a shared library and we just recorded
956 a dynamic R_PARISC_FPTR64 relocation, then make sure the
957 section symbol for this section ends up in the dynamic
958 symbol table. */
959 if (info->shared && dynrel_type == R_PARISC_FPTR64
960 && ! (bfd_elf_link_record_local_dynamic_symbol
961 (info, abfd, sec_symndx)))
962 return FALSE;
966 if (buf)
967 free (buf);
968 return TRUE;
970 err_out:
971 if (buf)
972 free (buf);
973 return FALSE;
976 struct elf64_hppa_allocate_data
978 struct bfd_link_info *info;
979 bfd_size_type ofs;
982 /* Should we do dynamic things to this symbol? */
984 static bfd_boolean
985 elf64_hppa_dynamic_symbol_p (h, info)
986 struct elf_link_hash_entry *h;
987 struct bfd_link_info *info;
989 /* ??? What, if anything, needs to happen wrt STV_PROTECTED symbols
990 and relocations that retrieve a function descriptor? Assume the
991 worst for now. */
992 if (_bfd_elf_dynamic_symbol_p (h, info, 1))
994 /* ??? Why is this here and not elsewhere is_local_label_name. */
995 if (h->root.root.string[0] == '$' && h->root.root.string[1] == '$')
996 return FALSE;
998 return TRUE;
1000 else
1001 return FALSE;
1004 /* Mark all functions exported by this file so that we can later allocate
1005 entries in .opd for them. */
1007 static bfd_boolean
1008 elf64_hppa_mark_exported_functions (h, data)
1009 struct elf_link_hash_entry *h;
1010 PTR data;
1012 struct bfd_link_info *info = (struct bfd_link_info *)data;
1013 struct elf64_hppa_link_hash_table *hppa_info;
1015 hppa_info = elf64_hppa_hash_table (info);
1017 if (h->root.type == bfd_link_hash_warning)
1018 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1020 if (h
1021 && (h->root.type == bfd_link_hash_defined
1022 || h->root.type == bfd_link_hash_defweak)
1023 && h->root.u.def.section->output_section != NULL
1024 && h->type == STT_FUNC)
1026 struct elf64_hppa_dyn_hash_entry *dyn_h;
1028 /* Add this symbol to the PA64 linker hash table. */
1029 dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table,
1030 h->root.root.string, TRUE, TRUE);
1031 BFD_ASSERT (dyn_h);
1032 dyn_h->h = h;
1034 if (! hppa_info->opd_sec
1035 && ! get_opd (hppa_info->root.dynobj, info, hppa_info))
1036 return FALSE;
1038 dyn_h->want_opd = 1;
1039 /* Put a flag here for output_symbol_hook. */
1040 dyn_h->st_shndx = -1;
1041 h->needs_plt = 1;
1044 return TRUE;
1047 /* Allocate space for a DLT entry. */
1049 static bfd_boolean
1050 allocate_global_data_dlt (dyn_h, data)
1051 struct elf64_hppa_dyn_hash_entry *dyn_h;
1052 PTR data;
1054 struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data;
1056 if (dyn_h->want_dlt)
1058 struct elf_link_hash_entry *h = dyn_h->h;
1060 if (x->info->shared)
1062 /* Possibly add the symbol to the local dynamic symbol
1063 table since we might need to create a dynamic relocation
1064 against it. */
1065 if (! h
1066 || (h->dynindx == -1 && h->type != STT_PARISC_MILLI))
1068 bfd *owner;
1069 owner = (h ? h->root.u.def.section->owner : dyn_h->owner);
1071 if (! (bfd_elf_link_record_local_dynamic_symbol
1072 (x->info, owner, dyn_h->sym_indx)))
1073 return FALSE;
1077 dyn_h->dlt_offset = x->ofs;
1078 x->ofs += DLT_ENTRY_SIZE;
1080 return TRUE;
1083 /* Allocate space for a DLT.PLT entry. */
1085 static bfd_boolean
1086 allocate_global_data_plt (dyn_h, data)
1087 struct elf64_hppa_dyn_hash_entry *dyn_h;
1088 PTR data;
1090 struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data;
1092 if (dyn_h->want_plt
1093 && elf64_hppa_dynamic_symbol_p (dyn_h->h, x->info)
1094 && !((dyn_h->h->root.type == bfd_link_hash_defined
1095 || dyn_h->h->root.type == bfd_link_hash_defweak)
1096 && dyn_h->h->root.u.def.section->output_section != NULL))
1098 dyn_h->plt_offset = x->ofs;
1099 x->ofs += PLT_ENTRY_SIZE;
1100 if (dyn_h->plt_offset < 0x2000)
1101 elf64_hppa_hash_table (x->info)->gp_offset = dyn_h->plt_offset;
1103 else
1104 dyn_h->want_plt = 0;
1106 return TRUE;
1109 /* Allocate space for a STUB entry. */
1111 static bfd_boolean
1112 allocate_global_data_stub (dyn_h, data)
1113 struct elf64_hppa_dyn_hash_entry *dyn_h;
1114 PTR data;
1116 struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data;
1118 if (dyn_h->want_stub
1119 && elf64_hppa_dynamic_symbol_p (dyn_h->h, x->info)
1120 && !((dyn_h->h->root.type == bfd_link_hash_defined
1121 || dyn_h->h->root.type == bfd_link_hash_defweak)
1122 && dyn_h->h->root.u.def.section->output_section != NULL))
1124 dyn_h->stub_offset = x->ofs;
1125 x->ofs += sizeof (plt_stub);
1127 else
1128 dyn_h->want_stub = 0;
1129 return TRUE;
1132 /* Allocate space for a FPTR entry. */
1134 static bfd_boolean
1135 allocate_global_data_opd (dyn_h, data)
1136 struct elf64_hppa_dyn_hash_entry *dyn_h;
1137 PTR data;
1139 struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data;
1141 if (dyn_h->want_opd)
1143 struct elf_link_hash_entry *h = dyn_h->h;
1145 if (h)
1146 while (h->root.type == bfd_link_hash_indirect
1147 || h->root.type == bfd_link_hash_warning)
1148 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1150 /* We never need an opd entry for a symbol which is not
1151 defined by this output file. */
1152 if (h && (h->root.type == bfd_link_hash_undefined
1153 || h->root.type == bfd_link_hash_undefweak
1154 || h->root.u.def.section->output_section == NULL))
1155 dyn_h->want_opd = 0;
1157 /* If we are creating a shared library, took the address of a local
1158 function or might export this function from this object file, then
1159 we have to create an opd descriptor. */
1160 else if (x->info->shared
1161 || h == NULL
1162 || (h->dynindx == -1 && h->type != STT_PARISC_MILLI)
1163 || (h->root.type == bfd_link_hash_defined
1164 || h->root.type == bfd_link_hash_defweak))
1166 /* If we are creating a shared library, then we will have to
1167 create a runtime relocation for the symbol to properly
1168 initialize the .opd entry. Make sure the symbol gets
1169 added to the dynamic symbol table. */
1170 if (x->info->shared
1171 && (h == NULL || (h->dynindx == -1)))
1173 bfd *owner;
1174 owner = (h ? h->root.u.def.section->owner : dyn_h->owner);
1176 if (!bfd_elf_link_record_local_dynamic_symbol
1177 (x->info, owner, dyn_h->sym_indx))
1178 return FALSE;
1181 /* This may not be necessary or desirable anymore now that
1182 we have some support for dealing with section symbols
1183 in dynamic relocs. But name munging does make the result
1184 much easier to debug. ie, the EPLT reloc will reference
1185 a symbol like .foobar, instead of .text + offset. */
1186 if (x->info->shared && h)
1188 char *new_name;
1189 struct elf_link_hash_entry *nh;
1191 new_name = alloca (strlen (h->root.root.string) + 2);
1192 new_name[0] = '.';
1193 strcpy (new_name + 1, h->root.root.string);
1195 nh = elf_link_hash_lookup (elf_hash_table (x->info),
1196 new_name, TRUE, TRUE, TRUE);
1198 nh->root.type = h->root.type;
1199 nh->root.u.def.value = h->root.u.def.value;
1200 nh->root.u.def.section = h->root.u.def.section;
1202 if (! bfd_elf_link_record_dynamic_symbol (x->info, nh))
1203 return FALSE;
1206 dyn_h->opd_offset = x->ofs;
1207 x->ofs += OPD_ENTRY_SIZE;
1210 /* Otherwise we do not need an opd entry. */
1211 else
1212 dyn_h->want_opd = 0;
1214 return TRUE;
1217 /* HP requires the EI_OSABI field to be filled in. The assignment to
1218 EI_ABIVERSION may not be strictly necessary. */
1220 static void
1221 elf64_hppa_post_process_headers (abfd, link_info)
1222 bfd * abfd;
1223 struct bfd_link_info * link_info ATTRIBUTE_UNUSED;
1225 Elf_Internal_Ehdr * i_ehdrp;
1227 i_ehdrp = elf_elfheader (abfd);
1229 i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi;
1230 i_ehdrp->e_ident[EI_ABIVERSION] = 1;
1233 /* Create function descriptor section (.opd). This section is called .opd
1234 because it contains "official procedure descriptors". The "official"
1235 refers to the fact that these descriptors are used when taking the address
1236 of a procedure, thus ensuring a unique address for each procedure. */
1238 static bfd_boolean
1239 get_opd (abfd, info, hppa_info)
1240 bfd *abfd;
1241 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1242 struct elf64_hppa_link_hash_table *hppa_info;
1244 asection *opd;
1245 bfd *dynobj;
1247 opd = hppa_info->opd_sec;
1248 if (!opd)
1250 dynobj = hppa_info->root.dynobj;
1251 if (!dynobj)
1252 hppa_info->root.dynobj = dynobj = abfd;
1254 opd = bfd_make_section_with_flags (dynobj, ".opd",
1255 (SEC_ALLOC
1256 | SEC_LOAD
1257 | SEC_HAS_CONTENTS
1258 | SEC_IN_MEMORY
1259 | SEC_LINKER_CREATED));
1260 if (!opd
1261 || !bfd_set_section_alignment (abfd, opd, 3))
1263 BFD_ASSERT (0);
1264 return FALSE;
1267 hppa_info->opd_sec = opd;
1270 return TRUE;
1273 /* Create the PLT section. */
1275 static bfd_boolean
1276 get_plt (abfd, info, hppa_info)
1277 bfd *abfd;
1278 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1279 struct elf64_hppa_link_hash_table *hppa_info;
1281 asection *plt;
1282 bfd *dynobj;
1284 plt = hppa_info->plt_sec;
1285 if (!plt)
1287 dynobj = hppa_info->root.dynobj;
1288 if (!dynobj)
1289 hppa_info->root.dynobj = dynobj = abfd;
1291 plt = bfd_make_section_with_flags (dynobj, ".plt",
1292 (SEC_ALLOC
1293 | SEC_LOAD
1294 | SEC_HAS_CONTENTS
1295 | SEC_IN_MEMORY
1296 | SEC_LINKER_CREATED));
1297 if (!plt
1298 || !bfd_set_section_alignment (abfd, plt, 3))
1300 BFD_ASSERT (0);
1301 return FALSE;
1304 hppa_info->plt_sec = plt;
1307 return TRUE;
1310 /* Create the DLT section. */
1312 static bfd_boolean
1313 get_dlt (abfd, info, hppa_info)
1314 bfd *abfd;
1315 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1316 struct elf64_hppa_link_hash_table *hppa_info;
1318 asection *dlt;
1319 bfd *dynobj;
1321 dlt = hppa_info->dlt_sec;
1322 if (!dlt)
1324 dynobj = hppa_info->root.dynobj;
1325 if (!dynobj)
1326 hppa_info->root.dynobj = dynobj = abfd;
1328 dlt = bfd_make_section_with_flags (dynobj, ".dlt",
1329 (SEC_ALLOC
1330 | SEC_LOAD
1331 | SEC_HAS_CONTENTS
1332 | SEC_IN_MEMORY
1333 | SEC_LINKER_CREATED));
1334 if (!dlt
1335 || !bfd_set_section_alignment (abfd, dlt, 3))
1337 BFD_ASSERT (0);
1338 return FALSE;
1341 hppa_info->dlt_sec = dlt;
1344 return TRUE;
1347 /* Create the stubs section. */
1349 static bfd_boolean
1350 get_stub (abfd, info, hppa_info)
1351 bfd *abfd;
1352 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1353 struct elf64_hppa_link_hash_table *hppa_info;
1355 asection *stub;
1356 bfd *dynobj;
1358 stub = hppa_info->stub_sec;
1359 if (!stub)
1361 dynobj = hppa_info->root.dynobj;
1362 if (!dynobj)
1363 hppa_info->root.dynobj = dynobj = abfd;
1365 stub = bfd_make_section_with_flags (dynobj, ".stub",
1366 (SEC_ALLOC | SEC_LOAD
1367 | SEC_HAS_CONTENTS
1368 | SEC_IN_MEMORY
1369 | SEC_READONLY
1370 | SEC_LINKER_CREATED));
1371 if (!stub
1372 || !bfd_set_section_alignment (abfd, stub, 3))
1374 BFD_ASSERT (0);
1375 return FALSE;
1378 hppa_info->stub_sec = stub;
1381 return TRUE;
1384 /* Create sections necessary for dynamic linking. This is only a rough
1385 cut and will likely change as we learn more about the somewhat
1386 unusual dynamic linking scheme HP uses.
1388 .stub:
1389 Contains code to implement cross-space calls. The first time one
1390 of the stubs is used it will call into the dynamic linker, later
1391 calls will go straight to the target.
1393 The only stub we support right now looks like
1395 ldd OFFSET(%dp),%r1
1396 bve %r0(%r1)
1397 ldd OFFSET+8(%dp),%dp
1399 Other stubs may be needed in the future. We may want the remove
1400 the break/nop instruction. It is only used right now to keep the
1401 offset of a .plt entry and a .stub entry in sync.
1403 .dlt:
1404 This is what most people call the .got. HP used a different name.
1405 Losers.
1407 .rela.dlt:
1408 Relocations for the DLT.
1410 .plt:
1411 Function pointers as address,gp pairs.
1413 .rela.plt:
1414 Should contain dynamic IPLT (and EPLT?) relocations.
1416 .opd:
1417 FPTRS
1419 .rela.opd:
1420 EPLT relocations for symbols exported from shared libraries. */
1422 static bfd_boolean
1423 elf64_hppa_create_dynamic_sections (abfd, info)
1424 bfd *abfd;
1425 struct bfd_link_info *info;
1427 asection *s;
1429 if (! get_stub (abfd, info, elf64_hppa_hash_table (info)))
1430 return FALSE;
1432 if (! get_dlt (abfd, info, elf64_hppa_hash_table (info)))
1433 return FALSE;
1435 if (! get_plt (abfd, info, elf64_hppa_hash_table (info)))
1436 return FALSE;
1438 if (! get_opd (abfd, info, elf64_hppa_hash_table (info)))
1439 return FALSE;
1441 s = bfd_make_section_with_flags (abfd, ".rela.dlt",
1442 (SEC_ALLOC | SEC_LOAD
1443 | SEC_HAS_CONTENTS
1444 | SEC_IN_MEMORY
1445 | SEC_READONLY
1446 | SEC_LINKER_CREATED));
1447 if (s == NULL
1448 || !bfd_set_section_alignment (abfd, s, 3))
1449 return FALSE;
1450 elf64_hppa_hash_table (info)->dlt_rel_sec = s;
1452 s = bfd_make_section_with_flags (abfd, ".rela.plt",
1453 (SEC_ALLOC | SEC_LOAD
1454 | SEC_HAS_CONTENTS
1455 | SEC_IN_MEMORY
1456 | SEC_READONLY
1457 | SEC_LINKER_CREATED));
1458 if (s == NULL
1459 || !bfd_set_section_alignment (abfd, s, 3))
1460 return FALSE;
1461 elf64_hppa_hash_table (info)->plt_rel_sec = s;
1463 s = bfd_make_section_with_flags (abfd, ".rela.data",
1464 (SEC_ALLOC | SEC_LOAD
1465 | SEC_HAS_CONTENTS
1466 | SEC_IN_MEMORY
1467 | SEC_READONLY
1468 | SEC_LINKER_CREATED));
1469 if (s == NULL
1470 || !bfd_set_section_alignment (abfd, s, 3))
1471 return FALSE;
1472 elf64_hppa_hash_table (info)->other_rel_sec = s;
1474 s = bfd_make_section_with_flags (abfd, ".rela.opd",
1475 (SEC_ALLOC | SEC_LOAD
1476 | SEC_HAS_CONTENTS
1477 | SEC_IN_MEMORY
1478 | SEC_READONLY
1479 | SEC_LINKER_CREATED));
1480 if (s == NULL
1481 || !bfd_set_section_alignment (abfd, s, 3))
1482 return FALSE;
1483 elf64_hppa_hash_table (info)->opd_rel_sec = s;
1485 return TRUE;
1488 /* Allocate dynamic relocations for those symbols that turned out
1489 to be dynamic. */
1491 static bfd_boolean
1492 allocate_dynrel_entries (dyn_h, data)
1493 struct elf64_hppa_dyn_hash_entry *dyn_h;
1494 PTR data;
1496 struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data;
1497 struct elf64_hppa_link_hash_table *hppa_info;
1498 struct elf64_hppa_dyn_reloc_entry *rent;
1499 bfd_boolean dynamic_symbol, shared;
1501 hppa_info = elf64_hppa_hash_table (x->info);
1502 dynamic_symbol = elf64_hppa_dynamic_symbol_p (dyn_h->h, x->info);
1503 shared = x->info->shared;
1505 /* We may need to allocate relocations for a non-dynamic symbol
1506 when creating a shared library. */
1507 if (!dynamic_symbol && !shared)
1508 return TRUE;
1510 /* Take care of the normal data relocations. */
1512 for (rent = dyn_h->reloc_entries; rent; rent = rent->next)
1514 /* Allocate one iff we are building a shared library, the relocation
1515 isn't a R_PARISC_FPTR64, or we don't want an opd entry. */
1516 if (!shared && rent->type == R_PARISC_FPTR64 && dyn_h->want_opd)
1517 continue;
1519 hppa_info->other_rel_sec->size += sizeof (Elf64_External_Rela);
1521 /* Make sure this symbol gets into the dynamic symbol table if it is
1522 not already recorded. ?!? This should not be in the loop since
1523 the symbol need only be added once. */
1524 if (dyn_h->h == 0
1525 || (dyn_h->h->dynindx == -1 && dyn_h->h->type != STT_PARISC_MILLI))
1526 if (!bfd_elf_link_record_local_dynamic_symbol
1527 (x->info, rent->sec->owner, dyn_h->sym_indx))
1528 return FALSE;
1531 /* Take care of the GOT and PLT relocations. */
1533 if ((dynamic_symbol || shared) && dyn_h->want_dlt)
1534 hppa_info->dlt_rel_sec->size += sizeof (Elf64_External_Rela);
1536 /* If we are building a shared library, then every symbol that has an
1537 opd entry will need an EPLT relocation to relocate the symbol's address
1538 and __gp value based on the runtime load address. */
1539 if (shared && dyn_h->want_opd)
1540 hppa_info->opd_rel_sec->size += sizeof (Elf64_External_Rela);
1542 if (dyn_h->want_plt && dynamic_symbol)
1544 bfd_size_type t = 0;
1546 /* Dynamic symbols get one IPLT relocation. Local symbols in
1547 shared libraries get two REL relocations. Local symbols in
1548 main applications get nothing. */
1549 if (dynamic_symbol)
1550 t = sizeof (Elf64_External_Rela);
1551 else if (shared)
1552 t = 2 * sizeof (Elf64_External_Rela);
1554 hppa_info->plt_rel_sec->size += t;
1557 return TRUE;
1560 /* Adjust a symbol defined by a dynamic object and referenced by a
1561 regular object. */
1563 static bfd_boolean
1564 elf64_hppa_adjust_dynamic_symbol (info, h)
1565 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1566 struct elf_link_hash_entry *h;
1568 /* ??? Undefined symbols with PLT entries should be re-defined
1569 to be the PLT entry. */
1571 /* If this is a weak symbol, and there is a real definition, the
1572 processor independent code will have arranged for us to see the
1573 real definition first, and we can just use the same value. */
1574 if (h->u.weakdef != NULL)
1576 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
1577 || h->u.weakdef->root.type == bfd_link_hash_defweak);
1578 h->root.u.def.section = h->u.weakdef->root.u.def.section;
1579 h->root.u.def.value = h->u.weakdef->root.u.def.value;
1580 return TRUE;
1583 /* If this is a reference to a symbol defined by a dynamic object which
1584 is not a function, we might allocate the symbol in our .dynbss section
1585 and allocate a COPY dynamic relocation.
1587 But PA64 code is canonically PIC, so as a rule we can avoid this sort
1588 of hackery. */
1590 return TRUE;
1593 /* This function is called via elf_link_hash_traverse to mark millicode
1594 symbols with a dynindx of -1 and to remove the string table reference
1595 from the dynamic symbol table. If the symbol is not a millicode symbol,
1596 elf64_hppa_mark_exported_functions is called. */
1598 static bfd_boolean
1599 elf64_hppa_mark_milli_and_exported_functions (h, data)
1600 struct elf_link_hash_entry *h;
1601 PTR data;
1603 struct bfd_link_info *info = (struct bfd_link_info *)data;
1604 struct elf_link_hash_entry *elf = h;
1606 if (elf->root.type == bfd_link_hash_warning)
1607 elf = (struct elf_link_hash_entry *) elf->root.u.i.link;
1609 if (elf->type == STT_PARISC_MILLI)
1611 if (elf->dynindx != -1)
1613 elf->dynindx = -1;
1614 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
1615 elf->dynstr_index);
1617 return TRUE;
1620 return elf64_hppa_mark_exported_functions (h, data);
1623 /* Set the final sizes of the dynamic sections and allocate memory for
1624 the contents of our special sections. */
1626 static bfd_boolean
1627 elf64_hppa_size_dynamic_sections (output_bfd, info)
1628 bfd *output_bfd;
1629 struct bfd_link_info *info;
1631 bfd *dynobj;
1632 asection *s;
1633 bfd_boolean plt;
1634 bfd_boolean relocs;
1635 bfd_boolean reltext;
1636 struct elf64_hppa_allocate_data data;
1637 struct elf64_hppa_link_hash_table *hppa_info;
1639 hppa_info = elf64_hppa_hash_table (info);
1641 dynobj = elf_hash_table (info)->dynobj;
1642 BFD_ASSERT (dynobj != NULL);
1644 /* Mark each function this program exports so that we will allocate
1645 space in the .opd section for each function's FPTR. If we are
1646 creating dynamic sections, change the dynamic index of millicode
1647 symbols to -1 and remove them from the string table for .dynstr.
1649 We have to traverse the main linker hash table since we have to
1650 find functions which may not have been mentioned in any relocs. */
1651 elf_link_hash_traverse (elf_hash_table (info),
1652 (elf_hash_table (info)->dynamic_sections_created
1653 ? elf64_hppa_mark_milli_and_exported_functions
1654 : elf64_hppa_mark_exported_functions),
1655 info);
1657 if (elf_hash_table (info)->dynamic_sections_created)
1659 /* Set the contents of the .interp section to the interpreter. */
1660 if (info->executable)
1662 s = bfd_get_section_by_name (dynobj, ".interp");
1663 BFD_ASSERT (s != NULL);
1664 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
1665 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
1668 else
1670 /* We may have created entries in the .rela.got section.
1671 However, if we are not creating the dynamic sections, we will
1672 not actually use these entries. Reset the size of .rela.dlt,
1673 which will cause it to get stripped from the output file
1674 below. */
1675 s = bfd_get_section_by_name (dynobj, ".rela.dlt");
1676 if (s != NULL)
1677 s->size = 0;
1680 /* Allocate the GOT entries. */
1682 data.info = info;
1683 if (elf64_hppa_hash_table (info)->dlt_sec)
1685 data.ofs = 0x0;
1686 elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table,
1687 allocate_global_data_dlt, &data);
1688 hppa_info->dlt_sec->size = data.ofs;
1690 data.ofs = 0x0;
1691 elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table,
1692 allocate_global_data_plt, &data);
1693 hppa_info->plt_sec->size = data.ofs;
1695 data.ofs = 0x0;
1696 elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table,
1697 allocate_global_data_stub, &data);
1698 hppa_info->stub_sec->size = data.ofs;
1701 /* Allocate space for entries in the .opd section. */
1702 if (elf64_hppa_hash_table (info)->opd_sec)
1704 data.ofs = 0;
1705 elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table,
1706 allocate_global_data_opd, &data);
1707 hppa_info->opd_sec->size = data.ofs;
1710 /* Now allocate space for dynamic relocations, if necessary. */
1711 if (hppa_info->root.dynamic_sections_created)
1712 elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table,
1713 allocate_dynrel_entries, &data);
1715 /* The sizes of all the sections are set. Allocate memory for them. */
1716 plt = FALSE;
1717 relocs = FALSE;
1718 reltext = FALSE;
1719 for (s = dynobj->sections; s != NULL; s = s->next)
1721 const char *name;
1723 if ((s->flags & SEC_LINKER_CREATED) == 0)
1724 continue;
1726 /* It's OK to base decisions on the section name, because none
1727 of the dynobj section names depend upon the input files. */
1728 name = bfd_get_section_name (dynobj, s);
1730 if (strcmp (name, ".plt") == 0)
1732 /* Remember whether there is a PLT. */
1733 plt = s->size != 0;
1735 else if (strcmp (name, ".opd") == 0
1736 || CONST_STRNEQ (name, ".dlt")
1737 || strcmp (name, ".stub") == 0
1738 || strcmp (name, ".got") == 0)
1740 /* Strip this section if we don't need it; see the comment below. */
1742 else if (CONST_STRNEQ (name, ".rela"))
1744 if (s->size != 0)
1746 asection *target;
1748 /* Remember whether there are any reloc sections other
1749 than .rela.plt. */
1750 if (strcmp (name, ".rela.plt") != 0)
1752 const char *outname;
1754 relocs = TRUE;
1756 /* If this relocation section applies to a read only
1757 section, then we probably need a DT_TEXTREL
1758 entry. The entries in the .rela.plt section
1759 really apply to the .got section, which we
1760 created ourselves and so know is not readonly. */
1761 outname = bfd_get_section_name (output_bfd,
1762 s->output_section);
1763 target = bfd_get_section_by_name (output_bfd, outname + 4);
1764 if (target != NULL
1765 && (target->flags & SEC_READONLY) != 0
1766 && (target->flags & SEC_ALLOC) != 0)
1767 reltext = TRUE;
1770 /* We use the reloc_count field as a counter if we need
1771 to copy relocs into the output file. */
1772 s->reloc_count = 0;
1775 else
1777 /* It's not one of our sections, so don't allocate space. */
1778 continue;
1781 if (s->size == 0)
1783 /* If we don't need this section, strip it from the
1784 output file. This is mostly to handle .rela.bss and
1785 .rela.plt. We must create both sections in
1786 create_dynamic_sections, because they must be created
1787 before the linker maps input sections to output
1788 sections. The linker does that before
1789 adjust_dynamic_symbol is called, and it is that
1790 function which decides whether anything needs to go
1791 into these sections. */
1792 s->flags |= SEC_EXCLUDE;
1793 continue;
1796 if ((s->flags & SEC_HAS_CONTENTS) == 0)
1797 continue;
1799 /* Allocate memory for the section contents if it has not
1800 been allocated already. We use bfd_zalloc here in case
1801 unused entries are not reclaimed before the section's
1802 contents are written out. This should not happen, but this
1803 way if it does, we get a R_PARISC_NONE reloc instead of
1804 garbage. */
1805 if (s->contents == NULL)
1807 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
1808 if (s->contents == NULL)
1809 return FALSE;
1813 if (elf_hash_table (info)->dynamic_sections_created)
1815 /* Always create a DT_PLTGOT. It actually has nothing to do with
1816 the PLT, it is how we communicate the __gp value of a load
1817 module to the dynamic linker. */
1818 #define add_dynamic_entry(TAG, VAL) \
1819 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
1821 if (!add_dynamic_entry (DT_HP_DLD_FLAGS, 0)
1822 || !add_dynamic_entry (DT_PLTGOT, 0))
1823 return FALSE;
1825 /* Add some entries to the .dynamic section. We fill in the
1826 values later, in elf64_hppa_finish_dynamic_sections, but we
1827 must add the entries now so that we get the correct size for
1828 the .dynamic section. The DT_DEBUG entry is filled in by the
1829 dynamic linker and used by the debugger. */
1830 if (! info->shared)
1832 if (!add_dynamic_entry (DT_DEBUG, 0)
1833 || !add_dynamic_entry (DT_HP_DLD_HOOK, 0)
1834 || !add_dynamic_entry (DT_HP_LOAD_MAP, 0))
1835 return FALSE;
1838 /* Force DT_FLAGS to always be set.
1839 Required by HPUX 11.00 patch PHSS_26559. */
1840 if (!add_dynamic_entry (DT_FLAGS, (info)->flags))
1841 return FALSE;
1843 if (plt)
1845 if (!add_dynamic_entry (DT_PLTRELSZ, 0)
1846 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
1847 || !add_dynamic_entry (DT_JMPREL, 0))
1848 return FALSE;
1851 if (relocs)
1853 if (!add_dynamic_entry (DT_RELA, 0)
1854 || !add_dynamic_entry (DT_RELASZ, 0)
1855 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
1856 return FALSE;
1859 if (reltext)
1861 if (!add_dynamic_entry (DT_TEXTREL, 0))
1862 return FALSE;
1863 info->flags |= DF_TEXTREL;
1866 #undef add_dynamic_entry
1868 return TRUE;
1871 /* Called after we have output the symbol into the dynamic symbol
1872 table, but before we output the symbol into the normal symbol
1873 table.
1875 For some symbols we had to change their address when outputting
1876 the dynamic symbol table. We undo that change here so that
1877 the symbols have their expected value in the normal symbol
1878 table. Ick. */
1880 static bfd_boolean
1881 elf64_hppa_link_output_symbol_hook (info, name, sym, input_sec, h)
1882 struct bfd_link_info *info;
1883 const char *name;
1884 Elf_Internal_Sym *sym;
1885 asection *input_sec ATTRIBUTE_UNUSED;
1886 struct elf_link_hash_entry *h;
1888 struct elf64_hppa_link_hash_table *hppa_info;
1889 struct elf64_hppa_dyn_hash_entry *dyn_h;
1891 /* We may be called with the file symbol or section symbols.
1892 They never need munging, so it is safe to ignore them. */
1893 if (!name)
1894 return TRUE;
1896 /* Get the PA dyn_symbol (if any) associated with NAME. */
1897 hppa_info = elf64_hppa_hash_table (info);
1898 dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table,
1899 name, FALSE, FALSE);
1900 if (!dyn_h || dyn_h->h != h)
1901 return TRUE;
1903 /* Function symbols for which we created .opd entries *may* have been
1904 munged by finish_dynamic_symbol and have to be un-munged here.
1906 Note that finish_dynamic_symbol sometimes turns dynamic symbols
1907 into non-dynamic ones, so we initialize st_shndx to -1 in
1908 mark_exported_functions and check to see if it was overwritten
1909 here instead of just checking dyn_h->h->dynindx. */
1910 if (dyn_h->want_opd && dyn_h->st_shndx != -1)
1912 /* Restore the saved value and section index. */
1913 sym->st_value = dyn_h->st_value;
1914 sym->st_shndx = dyn_h->st_shndx;
1917 return TRUE;
1920 /* Finish up dynamic symbol handling. We set the contents of various
1921 dynamic sections here. */
1923 static bfd_boolean
1924 elf64_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
1925 bfd *output_bfd;
1926 struct bfd_link_info *info;
1927 struct elf_link_hash_entry *h;
1928 Elf_Internal_Sym *sym;
1930 asection *stub, *splt, *sdlt, *sopd, *spltrel, *sdltrel;
1931 struct elf64_hppa_link_hash_table *hppa_info;
1932 struct elf64_hppa_dyn_hash_entry *dyn_h;
1934 hppa_info = elf64_hppa_hash_table (info);
1935 dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table,
1936 h->root.root.string, FALSE, FALSE);
1938 stub = hppa_info->stub_sec;
1939 splt = hppa_info->plt_sec;
1940 sdlt = hppa_info->dlt_sec;
1941 sopd = hppa_info->opd_sec;
1942 spltrel = hppa_info->plt_rel_sec;
1943 sdltrel = hppa_info->dlt_rel_sec;
1945 /* Incredible. It is actually necessary to NOT use the symbol's real
1946 value when building the dynamic symbol table for a shared library.
1947 At least for symbols that refer to functions.
1949 We will store a new value and section index into the symbol long
1950 enough to output it into the dynamic symbol table, then we restore
1951 the original values (in elf64_hppa_link_output_symbol_hook). */
1952 if (dyn_h && dyn_h->want_opd)
1954 BFD_ASSERT (sopd != NULL);
1956 /* Save away the original value and section index so that we
1957 can restore them later. */
1958 dyn_h->st_value = sym->st_value;
1959 dyn_h->st_shndx = sym->st_shndx;
1961 /* For the dynamic symbol table entry, we want the value to be
1962 address of this symbol's entry within the .opd section. */
1963 sym->st_value = (dyn_h->opd_offset
1964 + sopd->output_offset
1965 + sopd->output_section->vma);
1966 sym->st_shndx = _bfd_elf_section_from_bfd_section (output_bfd,
1967 sopd->output_section);
1970 /* Initialize a .plt entry if requested. */
1971 if (dyn_h && dyn_h->want_plt
1972 && elf64_hppa_dynamic_symbol_p (dyn_h->h, info))
1974 bfd_vma value;
1975 Elf_Internal_Rela rel;
1976 bfd_byte *loc;
1978 BFD_ASSERT (splt != NULL && spltrel != NULL);
1980 /* We do not actually care about the value in the PLT entry
1981 if we are creating a shared library and the symbol is
1982 still undefined, we create a dynamic relocation to fill
1983 in the correct value. */
1984 if (info->shared && h->root.type == bfd_link_hash_undefined)
1985 value = 0;
1986 else
1987 value = (h->root.u.def.value + h->root.u.def.section->vma);
1989 /* Fill in the entry in the procedure linkage table.
1991 The format of a plt entry is
1992 <funcaddr> <__gp>.
1994 plt_offset is the offset within the PLT section at which to
1995 install the PLT entry.
1997 We are modifying the in-memory PLT contents here, so we do not add
1998 in the output_offset of the PLT section. */
2000 bfd_put_64 (splt->owner, value, splt->contents + dyn_h->plt_offset);
2001 value = _bfd_get_gp_value (splt->output_section->owner);
2002 bfd_put_64 (splt->owner, value, splt->contents + dyn_h->plt_offset + 0x8);
2004 /* Create a dynamic IPLT relocation for this entry.
2006 We are creating a relocation in the output file's PLT section,
2007 which is included within the DLT secton. So we do need to include
2008 the PLT's output_offset in the computation of the relocation's
2009 address. */
2010 rel.r_offset = (dyn_h->plt_offset + splt->output_offset
2011 + splt->output_section->vma);
2012 rel.r_info = ELF64_R_INFO (h->dynindx, R_PARISC_IPLT);
2013 rel.r_addend = 0;
2015 loc = spltrel->contents;
2016 loc += spltrel->reloc_count++ * sizeof (Elf64_External_Rela);
2017 bfd_elf64_swap_reloca_out (splt->output_section->owner, &rel, loc);
2020 /* Initialize an external call stub entry if requested. */
2021 if (dyn_h && dyn_h->want_stub
2022 && elf64_hppa_dynamic_symbol_p (dyn_h->h, info))
2024 bfd_vma value;
2025 int insn;
2026 unsigned int max_offset;
2028 BFD_ASSERT (stub != NULL);
2030 /* Install the generic stub template.
2032 We are modifying the contents of the stub section, so we do not
2033 need to include the stub section's output_offset here. */
2034 memcpy (stub->contents + dyn_h->stub_offset, plt_stub, sizeof (plt_stub));
2036 /* Fix up the first ldd instruction.
2038 We are modifying the contents of the STUB section in memory,
2039 so we do not need to include its output offset in this computation.
2041 Note the plt_offset value is the value of the PLT entry relative to
2042 the start of the PLT section. These instructions will reference
2043 data relative to the value of __gp, which may not necessarily have
2044 the same address as the start of the PLT section.
2046 gp_offset contains the offset of __gp within the PLT section. */
2047 value = dyn_h->plt_offset - hppa_info->gp_offset;
2049 insn = bfd_get_32 (stub->owner, stub->contents + dyn_h->stub_offset);
2050 if (output_bfd->arch_info->mach >= 25)
2052 /* Wide mode allows 16 bit offsets. */
2053 max_offset = 32768;
2054 insn &= ~ 0xfff1;
2055 insn |= re_assemble_16 ((int) value);
2057 else
2059 max_offset = 8192;
2060 insn &= ~ 0x3ff1;
2061 insn |= re_assemble_14 ((int) value);
2064 if ((value & 7) || value + max_offset >= 2*max_offset - 8)
2066 (*_bfd_error_handler) (_("stub entry for %s cannot load .plt, dp offset = %ld"),
2067 dyn_h->root.string,
2068 (long) value);
2069 return FALSE;
2072 bfd_put_32 (stub->owner, (bfd_vma) insn,
2073 stub->contents + dyn_h->stub_offset);
2075 /* Fix up the second ldd instruction. */
2076 value += 8;
2077 insn = bfd_get_32 (stub->owner, stub->contents + dyn_h->stub_offset + 8);
2078 if (output_bfd->arch_info->mach >= 25)
2080 insn &= ~ 0xfff1;
2081 insn |= re_assemble_16 ((int) value);
2083 else
2085 insn &= ~ 0x3ff1;
2086 insn |= re_assemble_14 ((int) value);
2088 bfd_put_32 (stub->owner, (bfd_vma) insn,
2089 stub->contents + dyn_h->stub_offset + 8);
2092 return TRUE;
2095 /* The .opd section contains FPTRs for each function this file
2096 exports. Initialize the FPTR entries. */
2098 static bfd_boolean
2099 elf64_hppa_finalize_opd (dyn_h, data)
2100 struct elf64_hppa_dyn_hash_entry *dyn_h;
2101 PTR data;
2103 struct bfd_link_info *info = (struct bfd_link_info *)data;
2104 struct elf64_hppa_link_hash_table *hppa_info;
2105 struct elf_link_hash_entry *h = dyn_h ? dyn_h->h : NULL;
2106 asection *sopd;
2107 asection *sopdrel;
2109 hppa_info = elf64_hppa_hash_table (info);
2110 sopd = hppa_info->opd_sec;
2111 sopdrel = hppa_info->opd_rel_sec;
2113 if (h && dyn_h->want_opd)
2115 bfd_vma value;
2117 /* The first two words of an .opd entry are zero.
2119 We are modifying the contents of the OPD section in memory, so we
2120 do not need to include its output offset in this computation. */
2121 memset (sopd->contents + dyn_h->opd_offset, 0, 16);
2123 value = (h->root.u.def.value
2124 + h->root.u.def.section->output_section->vma
2125 + h->root.u.def.section->output_offset);
2127 /* The next word is the address of the function. */
2128 bfd_put_64 (sopd->owner, value, sopd->contents + dyn_h->opd_offset + 16);
2130 /* The last word is our local __gp value. */
2131 value = _bfd_get_gp_value (sopd->output_section->owner);
2132 bfd_put_64 (sopd->owner, value, sopd->contents + dyn_h->opd_offset + 24);
2135 /* If we are generating a shared library, we must generate EPLT relocations
2136 for each entry in the .opd, even for static functions (they may have
2137 had their address taken). */
2138 if (info->shared && dyn_h && dyn_h->want_opd)
2140 Elf_Internal_Rela rel;
2141 bfd_byte *loc;
2142 int dynindx;
2144 /* We may need to do a relocation against a local symbol, in
2145 which case we have to look up it's dynamic symbol index off
2146 the local symbol hash table. */
2147 if (h && h->dynindx != -1)
2148 dynindx = h->dynindx;
2149 else
2150 dynindx
2151 = _bfd_elf_link_lookup_local_dynindx (info, dyn_h->owner,
2152 dyn_h->sym_indx);
2154 /* The offset of this relocation is the absolute address of the
2155 .opd entry for this symbol. */
2156 rel.r_offset = (dyn_h->opd_offset + sopd->output_offset
2157 + sopd->output_section->vma);
2159 /* If H is non-null, then we have an external symbol.
2161 It is imperative that we use a different dynamic symbol for the
2162 EPLT relocation if the symbol has global scope.
2164 In the dynamic symbol table, the function symbol will have a value
2165 which is address of the function's .opd entry.
2167 Thus, we can not use that dynamic symbol for the EPLT relocation
2168 (if we did, the data in the .opd would reference itself rather
2169 than the actual address of the function). Instead we have to use
2170 a new dynamic symbol which has the same value as the original global
2171 function symbol.
2173 We prefix the original symbol with a "." and use the new symbol in
2174 the EPLT relocation. This new symbol has already been recorded in
2175 the symbol table, we just have to look it up and use it.
2177 We do not have such problems with static functions because we do
2178 not make their addresses in the dynamic symbol table point to
2179 the .opd entry. Ultimately this should be safe since a static
2180 function can not be directly referenced outside of its shared
2181 library.
2183 We do have to play similar games for FPTR relocations in shared
2184 libraries, including those for static symbols. See the FPTR
2185 handling in elf64_hppa_finalize_dynreloc. */
2186 if (h)
2188 char *new_name;
2189 struct elf_link_hash_entry *nh;
2191 new_name = alloca (strlen (h->root.root.string) + 2);
2192 new_name[0] = '.';
2193 strcpy (new_name + 1, h->root.root.string);
2195 nh = elf_link_hash_lookup (elf_hash_table (info),
2196 new_name, FALSE, FALSE, FALSE);
2198 /* All we really want from the new symbol is its dynamic
2199 symbol index. */
2200 dynindx = nh->dynindx;
2203 rel.r_addend = 0;
2204 rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_EPLT);
2206 loc = sopdrel->contents;
2207 loc += sopdrel->reloc_count++ * sizeof (Elf64_External_Rela);
2208 bfd_elf64_swap_reloca_out (sopd->output_section->owner, &rel, loc);
2210 return TRUE;
2213 /* The .dlt section contains addresses for items referenced through the
2214 dlt. Note that we can have a DLTIND relocation for a local symbol, thus
2215 we can not depend on finish_dynamic_symbol to initialize the .dlt. */
2217 static bfd_boolean
2218 elf64_hppa_finalize_dlt (dyn_h, data)
2219 struct elf64_hppa_dyn_hash_entry *dyn_h;
2220 PTR data;
2222 struct bfd_link_info *info = (struct bfd_link_info *)data;
2223 struct elf64_hppa_link_hash_table *hppa_info;
2224 asection *sdlt, *sdltrel;
2225 struct elf_link_hash_entry *h = dyn_h ? dyn_h->h : NULL;
2227 hppa_info = elf64_hppa_hash_table (info);
2229 sdlt = hppa_info->dlt_sec;
2230 sdltrel = hppa_info->dlt_rel_sec;
2232 /* H/DYN_H may refer to a local variable and we know it's
2233 address, so there is no need to create a relocation. Just install
2234 the proper value into the DLT, note this shortcut can not be
2235 skipped when building a shared library. */
2236 if (! info->shared && h && dyn_h->want_dlt)
2238 bfd_vma value;
2240 /* If we had an LTOFF_FPTR style relocation we want the DLT entry
2241 to point to the FPTR entry in the .opd section.
2243 We include the OPD's output offset in this computation as
2244 we are referring to an absolute address in the resulting
2245 object file. */
2246 if (dyn_h->want_opd)
2248 value = (dyn_h->opd_offset
2249 + hppa_info->opd_sec->output_offset
2250 + hppa_info->opd_sec->output_section->vma);
2252 else if ((h->root.type == bfd_link_hash_defined
2253 || h->root.type == bfd_link_hash_defweak)
2254 && h->root.u.def.section)
2256 value = h->root.u.def.value + h->root.u.def.section->output_offset;
2257 if (h->root.u.def.section->output_section)
2258 value += h->root.u.def.section->output_section->vma;
2259 else
2260 value += h->root.u.def.section->vma;
2262 else
2263 /* We have an undefined function reference. */
2264 value = 0;
2266 /* We do not need to include the output offset of the DLT section
2267 here because we are modifying the in-memory contents. */
2268 bfd_put_64 (sdlt->owner, value, sdlt->contents + dyn_h->dlt_offset);
2271 /* Create a relocation for the DLT entry associated with this symbol.
2272 When building a shared library the symbol does not have to be dynamic. */
2273 if (dyn_h->want_dlt
2274 && (elf64_hppa_dynamic_symbol_p (dyn_h->h, info) || info->shared))
2276 Elf_Internal_Rela rel;
2277 bfd_byte *loc;
2278 int dynindx;
2280 /* We may need to do a relocation against a local symbol, in
2281 which case we have to look up it's dynamic symbol index off
2282 the local symbol hash table. */
2283 if (h && h->dynindx != -1)
2284 dynindx = h->dynindx;
2285 else
2286 dynindx
2287 = _bfd_elf_link_lookup_local_dynindx (info, dyn_h->owner,
2288 dyn_h->sym_indx);
2290 /* Create a dynamic relocation for this entry. Do include the output
2291 offset of the DLT entry since we need an absolute address in the
2292 resulting object file. */
2293 rel.r_offset = (dyn_h->dlt_offset + sdlt->output_offset
2294 + sdlt->output_section->vma);
2295 if (h && h->type == STT_FUNC)
2296 rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_FPTR64);
2297 else
2298 rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_DIR64);
2299 rel.r_addend = 0;
2301 loc = sdltrel->contents;
2302 loc += sdltrel->reloc_count++ * sizeof (Elf64_External_Rela);
2303 bfd_elf64_swap_reloca_out (sdlt->output_section->owner, &rel, loc);
2305 return TRUE;
2308 /* Finalize the dynamic relocations. Specifically the FPTR relocations
2309 for dynamic functions used to initialize static data. */
2311 static bfd_boolean
2312 elf64_hppa_finalize_dynreloc (dyn_h, data)
2313 struct elf64_hppa_dyn_hash_entry *dyn_h;
2314 PTR data;
2316 struct bfd_link_info *info = (struct bfd_link_info *)data;
2317 struct elf64_hppa_link_hash_table *hppa_info;
2318 struct elf_link_hash_entry *h;
2319 int dynamic_symbol;
2321 dynamic_symbol = elf64_hppa_dynamic_symbol_p (dyn_h->h, info);
2323 if (!dynamic_symbol && !info->shared)
2324 return TRUE;
2326 if (dyn_h->reloc_entries)
2328 struct elf64_hppa_dyn_reloc_entry *rent;
2329 int dynindx;
2331 hppa_info = elf64_hppa_hash_table (info);
2332 h = dyn_h->h;
2334 /* We may need to do a relocation against a local symbol, in
2335 which case we have to look up it's dynamic symbol index off
2336 the local symbol hash table. */
2337 if (h && h->dynindx != -1)
2338 dynindx = h->dynindx;
2339 else
2340 dynindx
2341 = _bfd_elf_link_lookup_local_dynindx (info, dyn_h->owner,
2342 dyn_h->sym_indx);
2344 for (rent = dyn_h->reloc_entries; rent; rent = rent->next)
2346 Elf_Internal_Rela rel;
2347 bfd_byte *loc;
2349 /* Allocate one iff we are building a shared library, the relocation
2350 isn't a R_PARISC_FPTR64, or we don't want an opd entry. */
2351 if (!info->shared && rent->type == R_PARISC_FPTR64 && dyn_h->want_opd)
2352 continue;
2354 /* Create a dynamic relocation for this entry.
2356 We need the output offset for the reloc's section because
2357 we are creating an absolute address in the resulting object
2358 file. */
2359 rel.r_offset = (rent->offset + rent->sec->output_offset
2360 + rent->sec->output_section->vma);
2362 /* An FPTR64 relocation implies that we took the address of
2363 a function and that the function has an entry in the .opd
2364 section. We want the FPTR64 relocation to reference the
2365 entry in .opd.
2367 We could munge the symbol value in the dynamic symbol table
2368 (in fact we already do for functions with global scope) to point
2369 to the .opd entry. Then we could use that dynamic symbol in
2370 this relocation.
2372 Or we could do something sensible, not munge the symbol's
2373 address and instead just use a different symbol to reference
2374 the .opd entry. At least that seems sensible until you
2375 realize there's no local dynamic symbols we can use for that
2376 purpose. Thus the hair in the check_relocs routine.
2378 We use a section symbol recorded by check_relocs as the
2379 base symbol for the relocation. The addend is the difference
2380 between the section symbol and the address of the .opd entry. */
2381 if (info->shared && rent->type == R_PARISC_FPTR64 && dyn_h->want_opd)
2383 bfd_vma value, value2;
2385 /* First compute the address of the opd entry for this symbol. */
2386 value = (dyn_h->opd_offset
2387 + hppa_info->opd_sec->output_section->vma
2388 + hppa_info->opd_sec->output_offset);
2390 /* Compute the value of the start of the section with
2391 the relocation. */
2392 value2 = (rent->sec->output_section->vma
2393 + rent->sec->output_offset);
2395 /* Compute the difference between the start of the section
2396 with the relocation and the opd entry. */
2397 value -= value2;
2399 /* The result becomes the addend of the relocation. */
2400 rel.r_addend = value;
2402 /* The section symbol becomes the symbol for the dynamic
2403 relocation. */
2404 dynindx
2405 = _bfd_elf_link_lookup_local_dynindx (info,
2406 rent->sec->owner,
2407 rent->sec_symndx);
2409 else
2410 rel.r_addend = rent->addend;
2412 rel.r_info = ELF64_R_INFO (dynindx, rent->type);
2414 loc = hppa_info->other_rel_sec->contents;
2415 loc += (hppa_info->other_rel_sec->reloc_count++
2416 * sizeof (Elf64_External_Rela));
2417 bfd_elf64_swap_reloca_out (hppa_info->other_rel_sec->output_section->owner,
2418 &rel, loc);
2422 return TRUE;
2425 /* Used to decide how to sort relocs in an optimal manner for the
2426 dynamic linker, before writing them out. */
2428 static enum elf_reloc_type_class
2429 elf64_hppa_reloc_type_class (rela)
2430 const Elf_Internal_Rela *rela;
2432 if (ELF64_R_SYM (rela->r_info) == 0)
2433 return reloc_class_relative;
2435 switch ((int) ELF64_R_TYPE (rela->r_info))
2437 case R_PARISC_IPLT:
2438 return reloc_class_plt;
2439 case R_PARISC_COPY:
2440 return reloc_class_copy;
2441 default:
2442 return reloc_class_normal;
2446 /* Finish up the dynamic sections. */
2448 static bfd_boolean
2449 elf64_hppa_finish_dynamic_sections (output_bfd, info)
2450 bfd *output_bfd;
2451 struct bfd_link_info *info;
2453 bfd *dynobj;
2454 asection *sdyn;
2455 struct elf64_hppa_link_hash_table *hppa_info;
2457 hppa_info = elf64_hppa_hash_table (info);
2459 /* Finalize the contents of the .opd section. */
2460 elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table,
2461 elf64_hppa_finalize_opd,
2462 info);
2464 elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table,
2465 elf64_hppa_finalize_dynreloc,
2466 info);
2468 /* Finalize the contents of the .dlt section. */
2469 dynobj = elf_hash_table (info)->dynobj;
2470 /* Finalize the contents of the .dlt section. */
2471 elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table,
2472 elf64_hppa_finalize_dlt,
2473 info);
2475 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
2477 if (elf_hash_table (info)->dynamic_sections_created)
2479 Elf64_External_Dyn *dyncon, *dynconend;
2481 BFD_ASSERT (sdyn != NULL);
2483 dyncon = (Elf64_External_Dyn *) sdyn->contents;
2484 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
2485 for (; dyncon < dynconend; dyncon++)
2487 Elf_Internal_Dyn dyn;
2488 asection *s;
2490 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
2492 switch (dyn.d_tag)
2494 default:
2495 break;
2497 case DT_HP_LOAD_MAP:
2498 /* Compute the absolute address of 16byte scratchpad area
2499 for the dynamic linker.
2501 By convention the linker script will allocate the scratchpad
2502 area at the start of the .data section. So all we have to
2503 to is find the start of the .data section. */
2504 s = bfd_get_section_by_name (output_bfd, ".data");
2505 dyn.d_un.d_ptr = s->vma;
2506 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2507 break;
2509 case DT_PLTGOT:
2510 /* HP's use PLTGOT to set the GOT register. */
2511 dyn.d_un.d_ptr = _bfd_get_gp_value (output_bfd);
2512 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2513 break;
2515 case DT_JMPREL:
2516 s = hppa_info->plt_rel_sec;
2517 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
2518 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2519 break;
2521 case DT_PLTRELSZ:
2522 s = hppa_info->plt_rel_sec;
2523 dyn.d_un.d_val = s->size;
2524 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2525 break;
2527 case DT_RELA:
2528 s = hppa_info->other_rel_sec;
2529 if (! s || ! s->size)
2530 s = hppa_info->dlt_rel_sec;
2531 if (! s || ! s->size)
2532 s = hppa_info->opd_rel_sec;
2533 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
2534 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2535 break;
2537 case DT_RELASZ:
2538 s = hppa_info->other_rel_sec;
2539 dyn.d_un.d_val = s->size;
2540 s = hppa_info->dlt_rel_sec;
2541 dyn.d_un.d_val += s->size;
2542 s = hppa_info->opd_rel_sec;
2543 dyn.d_un.d_val += s->size;
2544 /* There is some question about whether or not the size of
2545 the PLT relocs should be included here. HP's tools do
2546 it, so we'll emulate them. */
2547 s = hppa_info->plt_rel_sec;
2548 dyn.d_un.d_val += s->size;
2549 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2550 break;
2556 return TRUE;
2559 /* Support for core dump NOTE sections. */
2561 static bfd_boolean
2562 elf64_hppa_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
2564 int offset;
2565 size_t size;
2567 switch (note->descsz)
2569 default:
2570 return FALSE;
2572 case 760: /* Linux/hppa */
2573 /* pr_cursig */
2574 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
2576 /* pr_pid */
2577 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 32);
2579 /* pr_reg */
2580 offset = 112;
2581 size = 640;
2583 break;
2586 /* Make a ".reg/999" section. */
2587 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
2588 size, note->descpos + offset);
2591 static bfd_boolean
2592 elf64_hppa_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
2594 char * command;
2595 int n;
2597 switch (note->descsz)
2599 default:
2600 return FALSE;
2602 case 136: /* Linux/hppa elf_prpsinfo. */
2603 elf_tdata (abfd)->core_program
2604 = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
2605 elf_tdata (abfd)->core_command
2606 = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
2609 /* Note that for some reason, a spurious space is tacked
2610 onto the end of the args in some (at least one anyway)
2611 implementations, so strip it off if it exists. */
2612 command = elf_tdata (abfd)->core_command;
2613 n = strlen (command);
2615 if (0 < n && command[n - 1] == ' ')
2616 command[n - 1] = '\0';
2618 return TRUE;
2621 /* Return the number of additional phdrs we will need.
2623 The generic ELF code only creates PT_PHDRs for executables. The HP
2624 dynamic linker requires PT_PHDRs for dynamic libraries too.
2626 This routine indicates that the backend needs one additional program
2627 header for that case.
2629 Note we do not have access to the link info structure here, so we have
2630 to guess whether or not we are building a shared library based on the
2631 existence of a .interp section. */
2633 static int
2634 elf64_hppa_additional_program_headers (bfd *abfd,
2635 struct bfd_link_info *info ATTRIBUTE_UNUSED)
2637 asection *s;
2639 /* If we are creating a shared library, then we have to create a
2640 PT_PHDR segment. HP's dynamic linker chokes without it. */
2641 s = bfd_get_section_by_name (abfd, ".interp");
2642 if (! s)
2643 return 1;
2644 return 0;
2647 /* Allocate and initialize any program headers required by this
2648 specific backend.
2650 The generic ELF code only creates PT_PHDRs for executables. The HP
2651 dynamic linker requires PT_PHDRs for dynamic libraries too.
2653 This allocates the PT_PHDR and initializes it in a manner suitable
2654 for the HP linker.
2656 Note we do not have access to the link info structure here, so we have
2657 to guess whether or not we are building a shared library based on the
2658 existence of a .interp section. */
2660 static bfd_boolean
2661 elf64_hppa_modify_segment_map (bfd *abfd,
2662 struct bfd_link_info *info ATTRIBUTE_UNUSED)
2664 struct elf_segment_map *m;
2665 asection *s;
2667 s = bfd_get_section_by_name (abfd, ".interp");
2668 if (! s)
2670 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
2671 if (m->p_type == PT_PHDR)
2672 break;
2673 if (m == NULL)
2675 m = ((struct elf_segment_map *)
2676 bfd_zalloc (abfd, (bfd_size_type) sizeof *m));
2677 if (m == NULL)
2678 return FALSE;
2680 m->p_type = PT_PHDR;
2681 m->p_flags = PF_R | PF_X;
2682 m->p_flags_valid = 1;
2683 m->p_paddr_valid = 1;
2684 m->includes_phdrs = 1;
2686 m->next = elf_tdata (abfd)->segment_map;
2687 elf_tdata (abfd)->segment_map = m;
2691 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
2692 if (m->p_type == PT_LOAD)
2694 unsigned int i;
2696 for (i = 0; i < m->count; i++)
2698 /* The code "hint" is not really a hint. It is a requirement
2699 for certain versions of the HP dynamic linker. Worse yet,
2700 it must be set even if the shared library does not have
2701 any code in its "text" segment (thus the check for .hash
2702 to catch this situation). */
2703 if (m->sections[i]->flags & SEC_CODE
2704 || (strcmp (m->sections[i]->name, ".hash") == 0))
2705 m->p_flags |= (PF_X | PF_HP_CODE);
2709 return TRUE;
2712 /* Called when writing out an object file to decide the type of a
2713 symbol. */
2714 static int
2715 elf64_hppa_elf_get_symbol_type (elf_sym, type)
2716 Elf_Internal_Sym *elf_sym;
2717 int type;
2719 if (ELF_ST_TYPE (elf_sym->st_info) == STT_PARISC_MILLI)
2720 return STT_PARISC_MILLI;
2721 else
2722 return type;
2725 /* Support HP specific sections for core files. */
2726 static bfd_boolean
2727 elf64_hppa_section_from_phdr (bfd *abfd, Elf_Internal_Phdr *hdr, int index,
2728 const char *typename)
2730 if (hdr->p_type == PT_HP_CORE_KERNEL)
2732 asection *sect;
2734 if (!_bfd_elf_make_section_from_phdr (abfd, hdr, index, typename))
2735 return FALSE;
2737 sect = bfd_make_section_anyway (abfd, ".kernel");
2738 if (sect == NULL)
2739 return FALSE;
2740 sect->size = hdr->p_filesz;
2741 sect->filepos = hdr->p_offset;
2742 sect->flags = SEC_HAS_CONTENTS | SEC_READONLY;
2743 return TRUE;
2746 if (hdr->p_type == PT_HP_CORE_PROC)
2748 int sig;
2750 if (bfd_seek (abfd, hdr->p_offset, SEEK_SET) != 0)
2751 return FALSE;
2752 if (bfd_bread (&sig, 4, abfd) != 4)
2753 return FALSE;
2755 elf_tdata (abfd)->core_signal = sig;
2757 if (!_bfd_elf_make_section_from_phdr (abfd, hdr, index, typename))
2758 return FALSE;
2760 /* GDB uses the ".reg" section to read register contents. */
2761 return _bfd_elfcore_make_pseudosection (abfd, ".reg", hdr->p_filesz,
2762 hdr->p_offset);
2765 if (hdr->p_type == PT_HP_CORE_LOADABLE
2766 || hdr->p_type == PT_HP_CORE_STACK
2767 || hdr->p_type == PT_HP_CORE_MMF)
2768 hdr->p_type = PT_LOAD;
2770 return _bfd_elf_make_section_from_phdr (abfd, hdr, index, typename);
2773 static const struct bfd_elf_special_section elf64_hppa_special_sections[] =
2775 { STRING_COMMA_LEN (".fini"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
2776 { STRING_COMMA_LEN (".init"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
2777 { STRING_COMMA_LEN (".plt"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT },
2778 { STRING_COMMA_LEN (".dlt"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT },
2779 { STRING_COMMA_LEN (".sdata"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT },
2780 { STRING_COMMA_LEN (".sbss"), 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT },
2781 { STRING_COMMA_LEN (".tbss"), 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_HP_TLS },
2782 { NULL, 0, 0, 0, 0 }
2785 /* The hash bucket size is the standard one, namely 4. */
2787 const struct elf_size_info hppa64_elf_size_info =
2789 sizeof (Elf64_External_Ehdr),
2790 sizeof (Elf64_External_Phdr),
2791 sizeof (Elf64_External_Shdr),
2792 sizeof (Elf64_External_Rel),
2793 sizeof (Elf64_External_Rela),
2794 sizeof (Elf64_External_Sym),
2795 sizeof (Elf64_External_Dyn),
2796 sizeof (Elf_External_Note),
2799 64, 3,
2800 ELFCLASS64, EV_CURRENT,
2801 bfd_elf64_write_out_phdrs,
2802 bfd_elf64_write_shdrs_and_ehdr,
2803 bfd_elf64_checksum_contents,
2804 bfd_elf64_write_relocs,
2805 bfd_elf64_swap_symbol_in,
2806 bfd_elf64_swap_symbol_out,
2807 bfd_elf64_slurp_reloc_table,
2808 bfd_elf64_slurp_symbol_table,
2809 bfd_elf64_swap_dyn_in,
2810 bfd_elf64_swap_dyn_out,
2811 bfd_elf64_swap_reloc_in,
2812 bfd_elf64_swap_reloc_out,
2813 bfd_elf64_swap_reloca_in,
2814 bfd_elf64_swap_reloca_out
2817 #define TARGET_BIG_SYM bfd_elf64_hppa_vec
2818 #define TARGET_BIG_NAME "elf64-hppa"
2819 #define ELF_ARCH bfd_arch_hppa
2820 #define ELF_MACHINE_CODE EM_PARISC
2821 /* This is not strictly correct. The maximum page size for PA2.0 is
2822 64M. But everything still uses 4k. */
2823 #define ELF_MAXPAGESIZE 0x1000
2824 #define ELF_OSABI ELFOSABI_HPUX
2826 #define bfd_elf64_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
2827 #define bfd_elf64_bfd_reloc_name_lookup elf_hppa_reloc_name_lookup
2828 #define bfd_elf64_bfd_is_local_label_name elf_hppa_is_local_label_name
2829 #define elf_info_to_howto elf_hppa_info_to_howto
2830 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
2832 #define elf_backend_section_from_shdr elf64_hppa_section_from_shdr
2833 #define elf_backend_object_p elf64_hppa_object_p
2834 #define elf_backend_final_write_processing \
2835 elf_hppa_final_write_processing
2836 #define elf_backend_fake_sections elf_hppa_fake_sections
2837 #define elf_backend_add_symbol_hook elf_hppa_add_symbol_hook
2839 #define elf_backend_relocate_section elf_hppa_relocate_section
2841 #define bfd_elf64_bfd_final_link elf_hppa_final_link
2843 #define elf_backend_create_dynamic_sections \
2844 elf64_hppa_create_dynamic_sections
2845 #define elf_backend_post_process_headers elf64_hppa_post_process_headers
2847 #define elf_backend_omit_section_dynsym \
2848 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
2849 #define elf_backend_adjust_dynamic_symbol \
2850 elf64_hppa_adjust_dynamic_symbol
2852 #define elf_backend_size_dynamic_sections \
2853 elf64_hppa_size_dynamic_sections
2855 #define elf_backend_finish_dynamic_symbol \
2856 elf64_hppa_finish_dynamic_symbol
2857 #define elf_backend_finish_dynamic_sections \
2858 elf64_hppa_finish_dynamic_sections
2859 #define elf_backend_grok_prstatus elf64_hppa_grok_prstatus
2860 #define elf_backend_grok_psinfo elf64_hppa_grok_psinfo
2862 /* Stuff for the BFD linker: */
2863 #define bfd_elf64_bfd_link_hash_table_create \
2864 elf64_hppa_hash_table_create
2866 #define elf_backend_check_relocs \
2867 elf64_hppa_check_relocs
2869 #define elf_backend_size_info \
2870 hppa64_elf_size_info
2872 #define elf_backend_additional_program_headers \
2873 elf64_hppa_additional_program_headers
2875 #define elf_backend_modify_segment_map \
2876 elf64_hppa_modify_segment_map
2878 #define elf_backend_link_output_symbol_hook \
2879 elf64_hppa_link_output_symbol_hook
2881 #define elf_backend_want_got_plt 0
2882 #define elf_backend_plt_readonly 0
2883 #define elf_backend_want_plt_sym 0
2884 #define elf_backend_got_header_size 0
2885 #define elf_backend_type_change_ok TRUE
2886 #define elf_backend_get_symbol_type elf64_hppa_elf_get_symbol_type
2887 #define elf_backend_reloc_type_class elf64_hppa_reloc_type_class
2888 #define elf_backend_rela_normal 1
2889 #define elf_backend_special_sections elf64_hppa_special_sections
2890 #define elf_backend_action_discarded elf_hppa_action_discarded
2891 #define elf_backend_section_from_phdr elf64_hppa_section_from_phdr
2893 #define elf64_bed elf64_hppa_hpux_bed
2895 #include "elf64-target.h"
2897 #undef TARGET_BIG_SYM
2898 #define TARGET_BIG_SYM bfd_elf64_hppa_linux_vec
2899 #undef TARGET_BIG_NAME
2900 #define TARGET_BIG_NAME "elf64-hppa-linux"
2901 #undef ELF_OSABI
2902 #define ELF_OSABI ELFOSABI_LINUX
2903 #undef elf_backend_post_process_headers
2904 #define elf_backend_post_process_headers _bfd_elf_set_osabi
2905 #undef elf64_bed
2906 #define elf64_bed elf64_hppa_linux_bed
2908 #include "elf64-target.h"