1 /* BFD back-end for HP PA-RISC ELF files.
2 Copyright (C) 1990-2016 Free Software Foundation, Inc.
5 Center for Software Science
6 Department of Computer Science
8 Largely rewritten by Alan Modra <alan@linuxcare.com.au>
9 Naming cleanup by Carlos O'Donell <carlos@systemhalted.org>
10 TLS support written by Randolph Chung <tausq@debian.org>
12 This file is part of BFD, the Binary File Descriptor library.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
27 MA 02110-1301, USA. */
35 #include "elf32-hppa.h"
37 #include "elf32-hppa.h"
40 /* In order to gain some understanding of code in this file without
41 knowing all the intricate details of the linker, note the
44 Functions named elf32_hppa_* are called by external routines, other
45 functions are only called locally. elf32_hppa_* functions appear
46 in this file more or less in the order in which they are called
47 from external routines. eg. elf32_hppa_check_relocs is called
48 early in the link process, elf32_hppa_finish_dynamic_sections is
49 one of the last functions. */
51 /* We use two hash tables to hold information for linking PA ELF objects.
53 The first is the elf32_hppa_link_hash_table which is derived
54 from the standard ELF linker hash table. We use this as a place to
55 attach other hash tables and static information.
57 The second is the stub hash table which is derived from the
58 base BFD hash table. The stub hash table holds the information
59 necessary to build the linker stubs during a link.
61 There are a number of different stubs generated by the linker.
69 : addil LR'X - ($PIC_pcrel$0 - 4),%r1
70 : be,n RR'X - ($PIC_pcrel$0 - 8)(%sr4,%r1)
72 Import stub to call shared library routine from normal object file
73 (single sub-space version)
74 : addil LR'lt_ptr+ltoff,%dp ; get procedure entry point
75 : ldw RR'lt_ptr+ltoff(%r1),%r21
77 : ldw RR'lt_ptr+ltoff+4(%r1),%r19 ; get new dlt value.
79 Import stub to call shared library routine from shared library
80 (single sub-space version)
81 : addil LR'ltoff,%r19 ; get procedure entry point
82 : ldw RR'ltoff(%r1),%r21
84 : ldw RR'ltoff+4(%r1),%r19 ; get new dlt value.
86 Import stub to call shared library routine from normal object file
87 (multiple sub-space support)
88 : addil LR'lt_ptr+ltoff,%dp ; get procedure entry point
89 : ldw RR'lt_ptr+ltoff(%r1),%r21
90 : ldw RR'lt_ptr+ltoff+4(%r1),%r19 ; get new dlt value.
93 : be 0(%sr0,%r21) ; branch to target
94 : stw %rp,-24(%sp) ; save rp
96 Import stub to call shared library routine from shared library
97 (multiple sub-space support)
98 : addil LR'ltoff,%r19 ; get procedure entry point
99 : ldw RR'ltoff(%r1),%r21
100 : ldw RR'ltoff+4(%r1),%r19 ; get new dlt value.
103 : be 0(%sr0,%r21) ; branch to target
104 : stw %rp,-24(%sp) ; save rp
106 Export stub to return from shared lib routine (multiple sub-space support)
107 One of these is created for each exported procedure in a shared
108 library (and stored in the shared lib). Shared lib routines are
109 called via the first instruction in the export stub so that we can
110 do an inter-space return. Not required for single sub-space.
111 : bl,n X,%rp ; trap the return
113 : ldw -24(%sp),%rp ; restore the original rp
116 : be,n 0(%sr0,%rp) ; inter-space return. */
119 /* Variable names follow a coding style.
120 Please follow this (Apps Hungarian) style:
122 Structure/Variable Prefix
123 elf_link_hash_table "etab"
124 elf_link_hash_entry "eh"
126 elf32_hppa_link_hash_table "htab"
127 elf32_hppa_link_hash_entry "hh"
129 bfd_hash_table "btab"
132 bfd_hash_table containing stubs "bstab"
133 elf32_hppa_stub_hash_entry "hsh"
135 elf32_hppa_dyn_reloc_entry "hdh"
137 Always remember to use GNU Coding Style. */
139 #define PLT_ENTRY_SIZE 8
140 #define GOT_ENTRY_SIZE 4
141 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
143 static const bfd_byte plt_stub[] =
145 0x0e, 0x80, 0x10, 0x96, /* 1: ldw 0(%r20),%r22 */
146 0xea, 0xc0, 0xc0, 0x00, /* bv %r0(%r22) */
147 0x0e, 0x88, 0x10, 0x95, /* ldw 4(%r20),%r21 */
148 #define PLT_STUB_ENTRY (3*4)
149 0xea, 0x9f, 0x1f, 0xdd, /* b,l 1b,%r20 */
150 0xd6, 0x80, 0x1c, 0x1e, /* depi 0,31,2,%r20 */
151 0x00, 0xc0, 0xff, 0xee, /* 9: .word fixup_func */
152 0xde, 0xad, 0xbe, 0xef /* .word fixup_ltp */
155 /* Section name for stubs is the associated section name plus this
157 #define STUB_SUFFIX ".stub"
159 /* We don't need to copy certain PC- or GP-relative dynamic relocs
160 into a shared object's dynamic section. All the relocs of the
161 limited class we are interested in, are absolute. */
162 #ifndef RELATIVE_DYNRELOCS
163 #define RELATIVE_DYNRELOCS 0
164 #define IS_ABSOLUTE_RELOC(r_type) 1
167 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
168 copying dynamic variables from a shared lib into an app's dynbss
169 section, and instead use a dynamic relocation to point into the
171 #define ELIMINATE_COPY_RELOCS 1
173 enum elf32_hppa_stub_type
175 hppa_stub_long_branch,
176 hppa_stub_long_branch_shared,
178 hppa_stub_import_shared,
183 struct elf32_hppa_stub_hash_entry
185 /* Base hash table entry structure. */
186 struct bfd_hash_entry bh_root;
188 /* The stub section. */
191 /* Offset within stub_sec of the beginning of this stub. */
194 /* Given the symbol's value and its section we can determine its final
195 value when building the stubs (so the stub knows where to jump. */
196 bfd_vma target_value;
197 asection *target_section;
199 enum elf32_hppa_stub_type stub_type;
201 /* The symbol table entry, if any, that this was derived from. */
202 struct elf32_hppa_link_hash_entry *hh;
204 /* Where this stub is being called from, or, in the case of combined
205 stub sections, the first input section in the group. */
209 struct elf32_hppa_link_hash_entry
211 struct elf_link_hash_entry eh;
213 /* A pointer to the most recently used stub hash entry against this
215 struct elf32_hppa_stub_hash_entry *hsh_cache;
217 /* Used to count relocations for delayed sizing of relocation
219 struct elf32_hppa_dyn_reloc_entry
221 /* Next relocation in the chain. */
222 struct elf32_hppa_dyn_reloc_entry *hdh_next;
224 /* The input section of the reloc. */
227 /* Number of relocs copied in this section. */
230 #if RELATIVE_DYNRELOCS
231 /* Number of relative relocs copied for the input section. */
232 bfd_size_type relative_count;
238 GOT_UNKNOWN = 0, GOT_NORMAL = 1, GOT_TLS_GD = 2, GOT_TLS_LDM = 4, GOT_TLS_IE = 8
241 /* Set if this symbol is used by a plabel reloc. */
242 unsigned int plabel:1;
245 struct elf32_hppa_link_hash_table
247 /* The main hash table. */
248 struct elf_link_hash_table etab;
250 /* The stub hash table. */
251 struct bfd_hash_table bstab;
253 /* Linker stub bfd. */
256 /* Linker call-backs. */
257 asection * (*add_stub_section) (const char *, asection *);
258 void (*layout_sections_again) (void);
260 /* Array to keep track of which stub sections have been created, and
261 information on stub grouping. */
264 /* This is the section to which stubs in the group will be
267 /* The stub section. */
271 /* Assorted information used by elf32_hppa_size_stubs. */
272 unsigned int bfd_count;
273 unsigned int top_index;
274 asection **input_list;
275 Elf_Internal_Sym **all_local_syms;
277 /* Short-cuts to get to dynamic linker sections. */
281 /* Used during a final link to store the base of the text and data
282 segments so that we can perform SEGREL relocations. */
283 bfd_vma text_segment_base;
284 bfd_vma data_segment_base;
286 /* Whether we support multiple sub-spaces for shared libs. */
287 unsigned int multi_subspace:1;
289 /* Flags set when various size branches are detected. Used to
290 select suitable defaults for the stub group size. */
291 unsigned int has_12bit_branch:1;
292 unsigned int has_17bit_branch:1;
293 unsigned int has_22bit_branch:1;
295 /* Set if we need a .plt stub to support lazy dynamic linking. */
296 unsigned int need_plt_stub:1;
298 /* Small local sym cache. */
299 struct sym_cache sym_cache;
301 /* Data for LDM relocations. */
304 bfd_signed_vma refcount;
309 /* Various hash macros and functions. */
310 #define hppa_link_hash_table(p) \
311 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
312 == HPPA32_ELF_DATA ? ((struct elf32_hppa_link_hash_table *) ((p)->hash)) : NULL)
314 #define hppa_elf_hash_entry(ent) \
315 ((struct elf32_hppa_link_hash_entry *)(ent))
317 #define hppa_stub_hash_entry(ent) \
318 ((struct elf32_hppa_stub_hash_entry *)(ent))
320 #define hppa_stub_hash_lookup(table, string, create, copy) \
321 ((struct elf32_hppa_stub_hash_entry *) \
322 bfd_hash_lookup ((table), (string), (create), (copy)))
324 #define hppa_elf_local_got_tls_type(abfd) \
325 ((char *)(elf_local_got_offsets (abfd) + (elf_tdata (abfd)->symtab_hdr.sh_info * 2)))
327 #define hh_name(hh) \
328 (hh ? hh->eh.root.root.string : "<undef>")
330 #define eh_name(eh) \
331 (eh ? eh->root.root.string : "<undef>")
333 /* Assorted hash table functions. */
335 /* Initialize an entry in the stub hash table. */
337 static struct bfd_hash_entry *
338 stub_hash_newfunc (struct bfd_hash_entry *entry,
339 struct bfd_hash_table *table,
342 /* Allocate the structure if it has not already been allocated by a
346 entry = bfd_hash_allocate (table,
347 sizeof (struct elf32_hppa_stub_hash_entry));
352 /* Call the allocation method of the superclass. */
353 entry = bfd_hash_newfunc (entry, table, string);
356 struct elf32_hppa_stub_hash_entry *hsh;
358 /* Initialize the local fields. */
359 hsh = hppa_stub_hash_entry (entry);
360 hsh->stub_sec = NULL;
361 hsh->stub_offset = 0;
362 hsh->target_value = 0;
363 hsh->target_section = NULL;
364 hsh->stub_type = hppa_stub_long_branch;
372 /* Initialize an entry in the link hash table. */
374 static struct bfd_hash_entry *
375 hppa_link_hash_newfunc (struct bfd_hash_entry *entry,
376 struct bfd_hash_table *table,
379 /* Allocate the structure if it has not already been allocated by a
383 entry = bfd_hash_allocate (table,
384 sizeof (struct elf32_hppa_link_hash_entry));
389 /* Call the allocation method of the superclass. */
390 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
393 struct elf32_hppa_link_hash_entry *hh;
395 /* Initialize the local fields. */
396 hh = hppa_elf_hash_entry (entry);
397 hh->hsh_cache = NULL;
398 hh->dyn_relocs = NULL;
400 hh->tls_type = GOT_UNKNOWN;
406 /* Free the derived linker hash table. */
409 elf32_hppa_link_hash_table_free (bfd *obfd)
411 struct elf32_hppa_link_hash_table *htab
412 = (struct elf32_hppa_link_hash_table *) obfd->link.hash;
414 bfd_hash_table_free (&htab->bstab);
415 _bfd_elf_link_hash_table_free (obfd);
418 /* Create the derived linker hash table. The PA ELF port uses the derived
419 hash table to keep information specific to the PA ELF linker (without
420 using static variables). */
422 static struct bfd_link_hash_table *
423 elf32_hppa_link_hash_table_create (bfd *abfd)
425 struct elf32_hppa_link_hash_table *htab;
426 bfd_size_type amt = sizeof (*htab);
428 htab = bfd_zmalloc (amt);
432 if (!_bfd_elf_link_hash_table_init (&htab->etab, abfd, hppa_link_hash_newfunc,
433 sizeof (struct elf32_hppa_link_hash_entry),
440 /* Init the stub hash table too. */
441 if (!bfd_hash_table_init (&htab->bstab, stub_hash_newfunc,
442 sizeof (struct elf32_hppa_stub_hash_entry)))
444 _bfd_elf_link_hash_table_free (abfd);
447 htab->etab.root.hash_table_free = elf32_hppa_link_hash_table_free;
449 htab->text_segment_base = (bfd_vma) -1;
450 htab->data_segment_base = (bfd_vma) -1;
451 return &htab->etab.root;
454 /* Initialize the linker stubs BFD so that we can use it for linker
455 created dynamic sections. */
458 elf32_hppa_init_stub_bfd (bfd *abfd, struct bfd_link_info *info)
460 struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info);
462 elf_elfheader (abfd)->e_ident[EI_CLASS] = ELFCLASS32;
463 htab->etab.dynobj = abfd;
466 /* Build a name for an entry in the stub hash table. */
469 hppa_stub_name (const asection *input_section,
470 const asection *sym_sec,
471 const struct elf32_hppa_link_hash_entry *hh,
472 const Elf_Internal_Rela *rela)
479 len = 8 + 1 + strlen (hh_name (hh)) + 1 + 8 + 1;
480 stub_name = bfd_malloc (len);
481 if (stub_name != NULL)
482 sprintf (stub_name, "%08x_%s+%x",
483 input_section->id & 0xffffffff,
485 (int) rela->r_addend & 0xffffffff);
489 len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
490 stub_name = bfd_malloc (len);
491 if (stub_name != NULL)
492 sprintf (stub_name, "%08x_%x:%x+%x",
493 input_section->id & 0xffffffff,
494 sym_sec->id & 0xffffffff,
495 (int) ELF32_R_SYM (rela->r_info) & 0xffffffff,
496 (int) rela->r_addend & 0xffffffff);
501 /* Look up an entry in the stub hash. Stub entries are cached because
502 creating the stub name takes a bit of time. */
504 static struct elf32_hppa_stub_hash_entry *
505 hppa_get_stub_entry (const asection *input_section,
506 const asection *sym_sec,
507 struct elf32_hppa_link_hash_entry *hh,
508 const Elf_Internal_Rela *rela,
509 struct elf32_hppa_link_hash_table *htab)
511 struct elf32_hppa_stub_hash_entry *hsh_entry;
512 const asection *id_sec;
514 /* If this input section is part of a group of sections sharing one
515 stub section, then use the id of the first section in the group.
516 Stub names need to include a section id, as there may well be
517 more than one stub used to reach say, printf, and we need to
518 distinguish between them. */
519 id_sec = htab->stub_group[input_section->id].link_sec;
521 if (hh != NULL && hh->hsh_cache != NULL
522 && hh->hsh_cache->hh == hh
523 && hh->hsh_cache->id_sec == id_sec)
525 hsh_entry = hh->hsh_cache;
531 stub_name = hppa_stub_name (id_sec, sym_sec, hh, rela);
532 if (stub_name == NULL)
535 hsh_entry = hppa_stub_hash_lookup (&htab->bstab,
536 stub_name, FALSE, FALSE);
538 hh->hsh_cache = hsh_entry;
546 /* Add a new stub entry to the stub hash. Not all fields of the new
547 stub entry are initialised. */
549 static struct elf32_hppa_stub_hash_entry *
550 hppa_add_stub (const char *stub_name,
552 struct elf32_hppa_link_hash_table *htab)
556 struct elf32_hppa_stub_hash_entry *hsh;
558 link_sec = htab->stub_group[section->id].link_sec;
559 stub_sec = htab->stub_group[section->id].stub_sec;
560 if (stub_sec == NULL)
562 stub_sec = htab->stub_group[link_sec->id].stub_sec;
563 if (stub_sec == NULL)
569 namelen = strlen (link_sec->name);
570 len = namelen + sizeof (STUB_SUFFIX);
571 s_name = bfd_alloc (htab->stub_bfd, len);
575 memcpy (s_name, link_sec->name, namelen);
576 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
577 stub_sec = (*htab->add_stub_section) (s_name, link_sec);
578 if (stub_sec == NULL)
580 htab->stub_group[link_sec->id].stub_sec = stub_sec;
582 htab->stub_group[section->id].stub_sec = stub_sec;
585 /* Enter this entry into the linker stub hash table. */
586 hsh = hppa_stub_hash_lookup (&htab->bstab, stub_name,
590 /* xgettext:c-format */
591 _bfd_error_handler (_("%B: cannot create stub entry %s"),
592 section->owner, stub_name);
596 hsh->stub_sec = stub_sec;
597 hsh->stub_offset = 0;
598 hsh->id_sec = link_sec;
602 /* Determine the type of stub needed, if any, for a call. */
604 static enum elf32_hppa_stub_type
605 hppa_type_of_stub (asection *input_sec,
606 const Elf_Internal_Rela *rela,
607 struct elf32_hppa_link_hash_entry *hh,
609 struct bfd_link_info *info)
612 bfd_vma branch_offset;
613 bfd_vma max_branch_offset;
617 && hh->eh.plt.offset != (bfd_vma) -1
618 && hh->eh.dynindx != -1
620 && (bfd_link_pic (info)
621 || !hh->eh.def_regular
622 || hh->eh.root.type == bfd_link_hash_defweak))
624 /* We need an import stub. Decide between hppa_stub_import
625 and hppa_stub_import_shared later. */
626 return hppa_stub_import;
629 /* Determine where the call point is. */
630 location = (input_sec->output_offset
631 + input_sec->output_section->vma
634 branch_offset = destination - location - 8;
635 r_type = ELF32_R_TYPE (rela->r_info);
637 /* Determine if a long branch stub is needed. parisc branch offsets
638 are relative to the second instruction past the branch, ie. +8
639 bytes on from the branch instruction location. The offset is
640 signed and counts in units of 4 bytes. */
641 if (r_type == (unsigned int) R_PARISC_PCREL17F)
642 max_branch_offset = (1 << (17 - 1)) << 2;
644 else if (r_type == (unsigned int) R_PARISC_PCREL12F)
645 max_branch_offset = (1 << (12 - 1)) << 2;
647 else /* R_PARISC_PCREL22F. */
648 max_branch_offset = (1 << (22 - 1)) << 2;
650 if (branch_offset + max_branch_offset >= 2*max_branch_offset)
651 return hppa_stub_long_branch;
653 return hppa_stub_none;
656 /* Build one linker stub as defined by the stub hash table entry GEN_ENTRY.
657 IN_ARG contains the link info pointer. */
659 #define LDIL_R1 0x20200000 /* ldil LR'XXX,%r1 */
660 #define BE_SR4_R1 0xe0202002 /* be,n RR'XXX(%sr4,%r1) */
662 #define BL_R1 0xe8200000 /* b,l .+8,%r1 */
663 #define ADDIL_R1 0x28200000 /* addil LR'XXX,%r1,%r1 */
664 #define DEPI_R1 0xd4201c1e /* depi 0,31,2,%r1 */
666 #define ADDIL_DP 0x2b600000 /* addil LR'XXX,%dp,%r1 */
667 #define LDW_R1_R21 0x48350000 /* ldw RR'XXX(%sr0,%r1),%r21 */
668 #define BV_R0_R21 0xeaa0c000 /* bv %r0(%r21) */
669 #define LDW_R1_R19 0x48330000 /* ldw RR'XXX(%sr0,%r1),%r19 */
671 #define ADDIL_R19 0x2a600000 /* addil LR'XXX,%r19,%r1 */
672 #define LDW_R1_DP 0x483b0000 /* ldw RR'XXX(%sr0,%r1),%dp */
674 #define LDSID_R21_R1 0x02a010a1 /* ldsid (%sr0,%r21),%r1 */
675 #define MTSP_R1 0x00011820 /* mtsp %r1,%sr0 */
676 #define BE_SR0_R21 0xe2a00000 /* be 0(%sr0,%r21) */
677 #define STW_RP 0x6bc23fd1 /* stw %rp,-24(%sr0,%sp) */
679 #define BL22_RP 0xe800a002 /* b,l,n XXX,%rp */
680 #define BL_RP 0xe8400002 /* b,l,n XXX,%rp */
681 #define NOP 0x08000240 /* nop */
682 #define LDW_RP 0x4bc23fd1 /* ldw -24(%sr0,%sp),%rp */
683 #define LDSID_RP_R1 0x004010a1 /* ldsid (%sr0,%rp),%r1 */
684 #define BE_SR0_RP 0xe0400002 /* be,n 0(%sr0,%rp) */
691 #define LDW_R1_DLT LDW_R1_R19
693 #define LDW_R1_DLT LDW_R1_DP
697 hppa_build_one_stub (struct bfd_hash_entry *bh, void *in_arg)
699 struct elf32_hppa_stub_hash_entry *hsh;
700 struct bfd_link_info *info;
701 struct elf32_hppa_link_hash_table *htab;
711 /* Massage our args to the form they really have. */
712 hsh = hppa_stub_hash_entry (bh);
713 info = (struct bfd_link_info *)in_arg;
715 htab = hppa_link_hash_table (info);
719 stub_sec = hsh->stub_sec;
721 /* Make a note of the offset within the stubs for this entry. */
722 hsh->stub_offset = stub_sec->size;
723 loc = stub_sec->contents + hsh->stub_offset;
725 stub_bfd = stub_sec->owner;
727 switch (hsh->stub_type)
729 case hppa_stub_long_branch:
730 /* Create the long branch. A long branch is formed with "ldil"
731 loading the upper bits of the target address into a register,
732 then branching with "be" which adds in the lower bits.
733 The "be" has its delay slot nullified. */
734 sym_value = (hsh->target_value
735 + hsh->target_section->output_offset
736 + hsh->target_section->output_section->vma);
738 val = hppa_field_adjust (sym_value, 0, e_lrsel);
739 insn = hppa_rebuild_insn ((int) LDIL_R1, val, 21);
740 bfd_put_32 (stub_bfd, insn, loc);
742 val = hppa_field_adjust (sym_value, 0, e_rrsel) >> 2;
743 insn = hppa_rebuild_insn ((int) BE_SR4_R1, val, 17);
744 bfd_put_32 (stub_bfd, insn, loc + 4);
749 case hppa_stub_long_branch_shared:
750 /* Branches are relative. This is where we are going to. */
751 sym_value = (hsh->target_value
752 + hsh->target_section->output_offset
753 + hsh->target_section->output_section->vma);
755 /* And this is where we are coming from, more or less. */
756 sym_value -= (hsh->stub_offset
757 + stub_sec->output_offset
758 + stub_sec->output_section->vma);
760 bfd_put_32 (stub_bfd, (bfd_vma) BL_R1, loc);
761 val = hppa_field_adjust (sym_value, (bfd_signed_vma) -8, e_lrsel);
762 insn = hppa_rebuild_insn ((int) ADDIL_R1, val, 21);
763 bfd_put_32 (stub_bfd, insn, loc + 4);
765 val = hppa_field_adjust (sym_value, (bfd_signed_vma) -8, e_rrsel) >> 2;
766 insn = hppa_rebuild_insn ((int) BE_SR4_R1, val, 17);
767 bfd_put_32 (stub_bfd, insn, loc + 8);
771 case hppa_stub_import:
772 case hppa_stub_import_shared:
773 off = hsh->hh->eh.plt.offset;
774 if (off >= (bfd_vma) -2)
777 off &= ~ (bfd_vma) 1;
779 + htab->etab.splt->output_offset
780 + htab->etab.splt->output_section->vma
781 - elf_gp (htab->etab.splt->output_section->owner));
785 if (hsh->stub_type == hppa_stub_import_shared)
788 val = hppa_field_adjust (sym_value, 0, e_lrsel),
789 insn = hppa_rebuild_insn ((int) insn, val, 21);
790 bfd_put_32 (stub_bfd, insn, loc);
792 /* It is critical to use lrsel/rrsel here because we are using
793 two different offsets (+0 and +4) from sym_value. If we use
794 lsel/rsel then with unfortunate sym_values we will round
795 sym_value+4 up to the next 2k block leading to a mis-match
796 between the lsel and rsel value. */
797 val = hppa_field_adjust (sym_value, 0, e_rrsel);
798 insn = hppa_rebuild_insn ((int) LDW_R1_R21, val, 14);
799 bfd_put_32 (stub_bfd, insn, loc + 4);
801 if (htab->multi_subspace)
803 val = hppa_field_adjust (sym_value, (bfd_signed_vma) 4, e_rrsel);
804 insn = hppa_rebuild_insn ((int) LDW_R1_DLT, val, 14);
805 bfd_put_32 (stub_bfd, insn, loc + 8);
807 bfd_put_32 (stub_bfd, (bfd_vma) LDSID_R21_R1, loc + 12);
808 bfd_put_32 (stub_bfd, (bfd_vma) MTSP_R1, loc + 16);
809 bfd_put_32 (stub_bfd, (bfd_vma) BE_SR0_R21, loc + 20);
810 bfd_put_32 (stub_bfd, (bfd_vma) STW_RP, loc + 24);
816 bfd_put_32 (stub_bfd, (bfd_vma) BV_R0_R21, loc + 8);
817 val = hppa_field_adjust (sym_value, (bfd_signed_vma) 4, e_rrsel);
818 insn = hppa_rebuild_insn ((int) LDW_R1_DLT, val, 14);
819 bfd_put_32 (stub_bfd, insn, loc + 12);
826 case hppa_stub_export:
827 /* Branches are relative. This is where we are going to. */
828 sym_value = (hsh->target_value
829 + hsh->target_section->output_offset
830 + hsh->target_section->output_section->vma);
832 /* And this is where we are coming from. */
833 sym_value -= (hsh->stub_offset
834 + stub_sec->output_offset
835 + stub_sec->output_section->vma);
837 if (sym_value - 8 + (1 << (17 + 1)) >= (1 << (17 + 2))
838 && (!htab->has_22bit_branch
839 || sym_value - 8 + (1 << (22 + 1)) >= (1 << (22 + 2))))
842 /* xgettext:c-format */
843 (_("%B(%A+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
844 hsh->target_section->owner,
846 (long) hsh->stub_offset,
847 hsh->bh_root.string);
848 bfd_set_error (bfd_error_bad_value);
852 val = hppa_field_adjust (sym_value, (bfd_signed_vma) -8, e_fsel) >> 2;
853 if (!htab->has_22bit_branch)
854 insn = hppa_rebuild_insn ((int) BL_RP, val, 17);
856 insn = hppa_rebuild_insn ((int) BL22_RP, val, 22);
857 bfd_put_32 (stub_bfd, insn, loc);
859 bfd_put_32 (stub_bfd, (bfd_vma) NOP, loc + 4);
860 bfd_put_32 (stub_bfd, (bfd_vma) LDW_RP, loc + 8);
861 bfd_put_32 (stub_bfd, (bfd_vma) LDSID_RP_R1, loc + 12);
862 bfd_put_32 (stub_bfd, (bfd_vma) MTSP_R1, loc + 16);
863 bfd_put_32 (stub_bfd, (bfd_vma) BE_SR0_RP, loc + 20);
865 /* Point the function symbol at the stub. */
866 hsh->hh->eh.root.u.def.section = stub_sec;
867 hsh->hh->eh.root.u.def.value = stub_sec->size;
877 stub_sec->size += size;
902 /* As above, but don't actually build the stub. Just bump offset so
903 we know stub section sizes. */
906 hppa_size_one_stub (struct bfd_hash_entry *bh, void *in_arg)
908 struct elf32_hppa_stub_hash_entry *hsh;
909 struct elf32_hppa_link_hash_table *htab;
912 /* Massage our args to the form they really have. */
913 hsh = hppa_stub_hash_entry (bh);
916 if (hsh->stub_type == hppa_stub_long_branch)
918 else if (hsh->stub_type == hppa_stub_long_branch_shared)
920 else if (hsh->stub_type == hppa_stub_export)
922 else /* hppa_stub_import or hppa_stub_import_shared. */
924 if (htab->multi_subspace)
930 hsh->stub_sec->size += size;
934 /* Return nonzero if ABFD represents an HPPA ELF32 file.
935 Additionally we set the default architecture and machine. */
938 elf32_hppa_object_p (bfd *abfd)
940 Elf_Internal_Ehdr * i_ehdrp;
943 i_ehdrp = elf_elfheader (abfd);
944 if (strcmp (bfd_get_target (abfd), "elf32-hppa-linux") == 0)
946 /* GCC on hppa-linux produces binaries with OSABI=GNU,
947 but the kernel produces corefiles with OSABI=SysV. */
948 if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_GNU &&
949 i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_NONE) /* aka SYSV */
952 else if (strcmp (bfd_get_target (abfd), "elf32-hppa-netbsd") == 0)
954 /* GCC on hppa-netbsd produces binaries with OSABI=NetBSD,
955 but the kernel produces corefiles with OSABI=SysV. */
956 if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_NETBSD &&
957 i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_NONE) /* aka SYSV */
962 if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_HPUX)
966 flags = i_ehdrp->e_flags;
967 switch (flags & (EF_PARISC_ARCH | EF_PARISC_WIDE))
970 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 10);
972 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 11);
974 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 20);
975 case EFA_PARISC_2_0 | EF_PARISC_WIDE:
976 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 25);
981 /* Create the .plt and .got sections, and set up our hash table
982 short-cuts to various dynamic sections. */
985 elf32_hppa_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
987 struct elf32_hppa_link_hash_table *htab;
988 struct elf_link_hash_entry *eh;
990 /* Don't try to create the .plt and .got twice. */
991 htab = hppa_link_hash_table (info);
994 if (htab->etab.splt != NULL)
997 /* Call the generic code to do most of the work. */
998 if (! _bfd_elf_create_dynamic_sections (abfd, info))
1001 htab->sdynbss = bfd_get_linker_section (abfd, ".dynbss");
1002 htab->srelbss = bfd_get_linker_section (abfd, ".rela.bss");
1004 /* hppa-linux needs _GLOBAL_OFFSET_TABLE_ to be visible from the main
1005 application, because __canonicalize_funcptr_for_compare needs it. */
1006 eh = elf_hash_table (info)->hgot;
1007 eh->forced_local = 0;
1008 eh->other = STV_DEFAULT;
1009 return bfd_elf_link_record_dynamic_symbol (info, eh);
1012 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1015 elf32_hppa_copy_indirect_symbol (struct bfd_link_info *info,
1016 struct elf_link_hash_entry *eh_dir,
1017 struct elf_link_hash_entry *eh_ind)
1019 struct elf32_hppa_link_hash_entry *hh_dir, *hh_ind;
1021 hh_dir = hppa_elf_hash_entry (eh_dir);
1022 hh_ind = hppa_elf_hash_entry (eh_ind);
1024 if (hh_ind->dyn_relocs != NULL)
1026 if (hh_dir->dyn_relocs != NULL)
1028 struct elf32_hppa_dyn_reloc_entry **hdh_pp;
1029 struct elf32_hppa_dyn_reloc_entry *hdh_p;
1031 /* Add reloc counts against the indirect sym to the direct sym
1032 list. Merge any entries against the same section. */
1033 for (hdh_pp = &hh_ind->dyn_relocs; (hdh_p = *hdh_pp) != NULL; )
1035 struct elf32_hppa_dyn_reloc_entry *hdh_q;
1037 for (hdh_q = hh_dir->dyn_relocs;
1039 hdh_q = hdh_q->hdh_next)
1040 if (hdh_q->sec == hdh_p->sec)
1042 #if RELATIVE_DYNRELOCS
1043 hdh_q->relative_count += hdh_p->relative_count;
1045 hdh_q->count += hdh_p->count;
1046 *hdh_pp = hdh_p->hdh_next;
1050 hdh_pp = &hdh_p->hdh_next;
1052 *hdh_pp = hh_dir->dyn_relocs;
1055 hh_dir->dyn_relocs = hh_ind->dyn_relocs;
1056 hh_ind->dyn_relocs = NULL;
1059 if (ELIMINATE_COPY_RELOCS
1060 && eh_ind->root.type != bfd_link_hash_indirect
1061 && eh_dir->dynamic_adjusted)
1063 /* If called to transfer flags for a weakdef during processing
1064 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1065 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1066 eh_dir->ref_dynamic |= eh_ind->ref_dynamic;
1067 eh_dir->ref_regular |= eh_ind->ref_regular;
1068 eh_dir->ref_regular_nonweak |= eh_ind->ref_regular_nonweak;
1069 eh_dir->needs_plt |= eh_ind->needs_plt;
1073 if (eh_ind->root.type == bfd_link_hash_indirect
1074 && eh_dir->got.refcount <= 0)
1076 hh_dir->tls_type = hh_ind->tls_type;
1077 hh_ind->tls_type = GOT_UNKNOWN;
1080 _bfd_elf_link_hash_copy_indirect (info, eh_dir, eh_ind);
1085 elf32_hppa_optimized_tls_reloc (struct bfd_link_info *info ATTRIBUTE_UNUSED,
1086 int r_type, int is_local ATTRIBUTE_UNUSED)
1088 /* For now we don't support linker optimizations. */
1092 /* Return a pointer to the local GOT, PLT and TLS reference counts
1093 for ABFD. Returns NULL if the storage allocation fails. */
1095 static bfd_signed_vma *
1096 hppa32_elf_local_refcounts (bfd *abfd)
1098 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1099 bfd_signed_vma *local_refcounts;
1101 local_refcounts = elf_local_got_refcounts (abfd);
1102 if (local_refcounts == NULL)
1106 /* Allocate space for local GOT and PLT reference
1107 counts. Done this way to save polluting elf_obj_tdata
1108 with another target specific pointer. */
1109 size = symtab_hdr->sh_info;
1110 size *= 2 * sizeof (bfd_signed_vma);
1111 /* Add in space to store the local GOT TLS types. */
1112 size += symtab_hdr->sh_info;
1113 local_refcounts = bfd_zalloc (abfd, size);
1114 if (local_refcounts == NULL)
1116 elf_local_got_refcounts (abfd) = local_refcounts;
1117 memset (hppa_elf_local_got_tls_type (abfd), GOT_UNKNOWN,
1118 symtab_hdr->sh_info);
1120 return local_refcounts;
1124 /* Look through the relocs for a section during the first phase, and
1125 calculate needed space in the global offset table, procedure linkage
1126 table, and dynamic reloc sections. At this point we haven't
1127 necessarily read all the input files. */
1130 elf32_hppa_check_relocs (bfd *abfd,
1131 struct bfd_link_info *info,
1133 const Elf_Internal_Rela *relocs)
1135 Elf_Internal_Shdr *symtab_hdr;
1136 struct elf_link_hash_entry **eh_syms;
1137 const Elf_Internal_Rela *rela;
1138 const Elf_Internal_Rela *rela_end;
1139 struct elf32_hppa_link_hash_table *htab;
1141 int tls_type = GOT_UNKNOWN, old_tls_type = GOT_UNKNOWN;
1143 if (bfd_link_relocatable (info))
1146 htab = hppa_link_hash_table (info);
1149 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1150 eh_syms = elf_sym_hashes (abfd);
1153 rela_end = relocs + sec->reloc_count;
1154 for (rela = relocs; rela < rela_end; rela++)
1163 unsigned int r_symndx, r_type;
1164 struct elf32_hppa_link_hash_entry *hh;
1167 r_symndx = ELF32_R_SYM (rela->r_info);
1169 if (r_symndx < symtab_hdr->sh_info)
1173 hh = hppa_elf_hash_entry (eh_syms[r_symndx - symtab_hdr->sh_info]);
1174 while (hh->eh.root.type == bfd_link_hash_indirect
1175 || hh->eh.root.type == bfd_link_hash_warning)
1176 hh = hppa_elf_hash_entry (hh->eh.root.u.i.link);
1178 /* PR15323, ref flags aren't set for references in the same
1180 hh->eh.root.non_ir_ref = 1;
1183 r_type = ELF32_R_TYPE (rela->r_info);
1184 r_type = elf32_hppa_optimized_tls_reloc (info, r_type, hh == NULL);
1188 case R_PARISC_DLTIND14F:
1189 case R_PARISC_DLTIND14R:
1190 case R_PARISC_DLTIND21L:
1191 /* This symbol requires a global offset table entry. */
1192 need_entry = NEED_GOT;
1195 case R_PARISC_PLABEL14R: /* "Official" procedure labels. */
1196 case R_PARISC_PLABEL21L:
1197 case R_PARISC_PLABEL32:
1198 /* If the addend is non-zero, we break badly. */
1199 if (rela->r_addend != 0)
1202 /* If we are creating a shared library, then we need to
1203 create a PLT entry for all PLABELs, because PLABELs with
1204 local symbols may be passed via a pointer to another
1205 object. Additionally, output a dynamic relocation
1206 pointing to the PLT entry.
1208 For executables, the original 32-bit ABI allowed two
1209 different styles of PLABELs (function pointers): For
1210 global functions, the PLABEL word points into the .plt
1211 two bytes past a (function address, gp) pair, and for
1212 local functions the PLABEL points directly at the
1213 function. The magic +2 for the first type allows us to
1214 differentiate between the two. As you can imagine, this
1215 is a real pain when it comes to generating code to call
1216 functions indirectly or to compare function pointers.
1217 We avoid the mess by always pointing a PLABEL into the
1218 .plt, even for local functions. */
1219 need_entry = PLT_PLABEL | NEED_PLT | NEED_DYNREL;
1222 case R_PARISC_PCREL12F:
1223 htab->has_12bit_branch = 1;
1226 case R_PARISC_PCREL17C:
1227 case R_PARISC_PCREL17F:
1228 htab->has_17bit_branch = 1;
1231 case R_PARISC_PCREL22F:
1232 htab->has_22bit_branch = 1;
1234 /* Function calls might need to go through the .plt, and
1235 might require long branch stubs. */
1238 /* We know local syms won't need a .plt entry, and if
1239 they need a long branch stub we can't guarantee that
1240 we can reach the stub. So just flag an error later
1241 if we're doing a shared link and find we need a long
1247 /* Global symbols will need a .plt entry if they remain
1248 global, and in most cases won't need a long branch
1249 stub. Unfortunately, we have to cater for the case
1250 where a symbol is forced local by versioning, or due
1251 to symbolic linking, and we lose the .plt entry. */
1252 need_entry = NEED_PLT;
1253 if (hh->eh.type == STT_PARISC_MILLI)
1258 case R_PARISC_SEGBASE: /* Used to set segment base. */
1259 case R_PARISC_SEGREL32: /* Relative reloc, used for unwind. */
1260 case R_PARISC_PCREL14F: /* PC relative load/store. */
1261 case R_PARISC_PCREL14R:
1262 case R_PARISC_PCREL17R: /* External branches. */
1263 case R_PARISC_PCREL21L: /* As above, and for load/store too. */
1264 case R_PARISC_PCREL32:
1265 /* We don't need to propagate the relocation if linking a
1266 shared object since these are section relative. */
1269 case R_PARISC_DPREL14F: /* Used for gp rel data load/store. */
1270 case R_PARISC_DPREL14R:
1271 case R_PARISC_DPREL21L:
1272 if (bfd_link_pic (info))
1275 /* xgettext:c-format */
1276 (_("%B: relocation %s can not be used when making a shared object; recompile with -fPIC"),
1278 elf_hppa_howto_table[r_type].name);
1279 bfd_set_error (bfd_error_bad_value);
1284 case R_PARISC_DIR17F: /* Used for external branches. */
1285 case R_PARISC_DIR17R:
1286 case R_PARISC_DIR14F: /* Used for load/store from absolute locn. */
1287 case R_PARISC_DIR14R:
1288 case R_PARISC_DIR21L: /* As above, and for ext branches too. */
1289 case R_PARISC_DIR32: /* .word relocs. */
1290 /* We may want to output a dynamic relocation later. */
1291 need_entry = NEED_DYNREL;
1294 /* This relocation describes the C++ object vtable hierarchy.
1295 Reconstruct it for later use during GC. */
1296 case R_PARISC_GNU_VTINHERIT:
1297 if (!bfd_elf_gc_record_vtinherit (abfd, sec, &hh->eh, rela->r_offset))
1301 /* This relocation describes which C++ vtable entries are actually
1302 used. Record for later use during GC. */
1303 case R_PARISC_GNU_VTENTRY:
1304 BFD_ASSERT (hh != NULL);
1306 && !bfd_elf_gc_record_vtentry (abfd, sec, &hh->eh, rela->r_addend))
1310 case R_PARISC_TLS_GD21L:
1311 case R_PARISC_TLS_GD14R:
1312 case R_PARISC_TLS_LDM21L:
1313 case R_PARISC_TLS_LDM14R:
1314 need_entry = NEED_GOT;
1317 case R_PARISC_TLS_IE21L:
1318 case R_PARISC_TLS_IE14R:
1319 if (bfd_link_pic (info))
1320 info->flags |= DF_STATIC_TLS;
1321 need_entry = NEED_GOT;
1328 /* Now carry out our orders. */
1329 if (need_entry & NEED_GOT)
1334 tls_type = GOT_NORMAL;
1336 case R_PARISC_TLS_GD21L:
1337 case R_PARISC_TLS_GD14R:
1338 tls_type |= GOT_TLS_GD;
1340 case R_PARISC_TLS_LDM21L:
1341 case R_PARISC_TLS_LDM14R:
1342 tls_type |= GOT_TLS_LDM;
1344 case R_PARISC_TLS_IE21L:
1345 case R_PARISC_TLS_IE14R:
1346 tls_type |= GOT_TLS_IE;
1350 /* Allocate space for a GOT entry, as well as a dynamic
1351 relocation for this entry. */
1352 if (htab->etab.sgot == NULL)
1354 if (!elf32_hppa_create_dynamic_sections (htab->etab.dynobj, info))
1358 if (r_type == R_PARISC_TLS_LDM21L
1359 || r_type == R_PARISC_TLS_LDM14R)
1360 htab->tls_ldm_got.refcount += 1;
1365 hh->eh.got.refcount += 1;
1366 old_tls_type = hh->tls_type;
1370 bfd_signed_vma *local_got_refcounts;
1372 /* This is a global offset table entry for a local symbol. */
1373 local_got_refcounts = hppa32_elf_local_refcounts (abfd);
1374 if (local_got_refcounts == NULL)
1376 local_got_refcounts[r_symndx] += 1;
1378 old_tls_type = hppa_elf_local_got_tls_type (abfd) [r_symndx];
1381 tls_type |= old_tls_type;
1383 if (old_tls_type != tls_type)
1386 hh->tls_type = tls_type;
1388 hppa_elf_local_got_tls_type (abfd) [r_symndx] = tls_type;
1394 if (need_entry & NEED_PLT)
1396 /* If we are creating a shared library, and this is a reloc
1397 against a weak symbol or a global symbol in a dynamic
1398 object, then we will be creating an import stub and a
1399 .plt entry for the symbol. Similarly, on a normal link
1400 to symbols defined in a dynamic object we'll need the
1401 import stub and a .plt entry. We don't know yet whether
1402 the symbol is defined or not, so make an entry anyway and
1403 clean up later in adjust_dynamic_symbol. */
1404 if ((sec->flags & SEC_ALLOC) != 0)
1408 hh->eh.needs_plt = 1;
1409 hh->eh.plt.refcount += 1;
1411 /* If this .plt entry is for a plabel, mark it so
1412 that adjust_dynamic_symbol will keep the entry
1413 even if it appears to be local. */
1414 if (need_entry & PLT_PLABEL)
1417 else if (need_entry & PLT_PLABEL)
1419 bfd_signed_vma *local_got_refcounts;
1420 bfd_signed_vma *local_plt_refcounts;
1422 local_got_refcounts = hppa32_elf_local_refcounts (abfd);
1423 if (local_got_refcounts == NULL)
1425 local_plt_refcounts = (local_got_refcounts
1426 + symtab_hdr->sh_info);
1427 local_plt_refcounts[r_symndx] += 1;
1432 if (need_entry & NEED_DYNREL)
1434 /* Flag this symbol as having a non-got, non-plt reference
1435 so that we generate copy relocs if it turns out to be
1437 if (hh != NULL && !bfd_link_pic (info))
1438 hh->eh.non_got_ref = 1;
1440 /* If we are creating a shared library then we need to copy
1441 the reloc into the shared library. However, if we are
1442 linking with -Bsymbolic, we need only copy absolute
1443 relocs or relocs against symbols that are not defined in
1444 an object we are including in the link. PC- or DP- or
1445 DLT-relative relocs against any local sym or global sym
1446 with DEF_REGULAR set, can be discarded. At this point we
1447 have not seen all the input files, so it is possible that
1448 DEF_REGULAR is not set now but will be set later (it is
1449 never cleared). We account for that possibility below by
1450 storing information in the dyn_relocs field of the
1453 A similar situation to the -Bsymbolic case occurs when
1454 creating shared libraries and symbol visibility changes
1455 render the symbol local.
1457 As it turns out, all the relocs we will be creating here
1458 are absolute, so we cannot remove them on -Bsymbolic
1459 links or visibility changes anyway. A STUB_REL reloc
1460 is absolute too, as in that case it is the reloc in the
1461 stub we will be creating, rather than copying the PCREL
1462 reloc in the branch.
1464 If on the other hand, we are creating an executable, we
1465 may need to keep relocations for symbols satisfied by a
1466 dynamic library if we manage to avoid copy relocs for the
1468 if ((bfd_link_pic (info)
1469 && (sec->flags & SEC_ALLOC) != 0
1470 && (IS_ABSOLUTE_RELOC (r_type)
1472 && (!SYMBOLIC_BIND (info, &hh->eh)
1473 || hh->eh.root.type == bfd_link_hash_defweak
1474 || !hh->eh.def_regular))))
1475 || (ELIMINATE_COPY_RELOCS
1476 && !bfd_link_pic (info)
1477 && (sec->flags & SEC_ALLOC) != 0
1479 && (hh->eh.root.type == bfd_link_hash_defweak
1480 || !hh->eh.def_regular)))
1482 struct elf32_hppa_dyn_reloc_entry *hdh_p;
1483 struct elf32_hppa_dyn_reloc_entry **hdh_head;
1485 /* Create a reloc section in dynobj and make room for
1489 sreloc = _bfd_elf_make_dynamic_reloc_section
1490 (sec, htab->etab.dynobj, 2, abfd, /*rela?*/ TRUE);
1494 bfd_set_error (bfd_error_bad_value);
1499 /* If this is a global symbol, we count the number of
1500 relocations we need for this symbol. */
1503 hdh_head = &hh->dyn_relocs;
1507 /* Track dynamic relocs needed for local syms too.
1508 We really need local syms available to do this
1512 Elf_Internal_Sym *isym;
1514 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1519 sr = bfd_section_from_elf_index (abfd, isym->st_shndx);
1523 vpp = &elf_section_data (sr)->local_dynrel;
1524 hdh_head = (struct elf32_hppa_dyn_reloc_entry **) vpp;
1528 if (hdh_p == NULL || hdh_p->sec != sec)
1530 hdh_p = bfd_alloc (htab->etab.dynobj, sizeof *hdh_p);
1533 hdh_p->hdh_next = *hdh_head;
1537 #if RELATIVE_DYNRELOCS
1538 hdh_p->relative_count = 0;
1543 #if RELATIVE_DYNRELOCS
1544 if (!IS_ABSOLUTE_RELOC (rtype))
1545 hdh_p->relative_count += 1;
1554 /* Return the section that should be marked against garbage collection
1555 for a given relocation. */
1558 elf32_hppa_gc_mark_hook (asection *sec,
1559 struct bfd_link_info *info,
1560 Elf_Internal_Rela *rela,
1561 struct elf_link_hash_entry *hh,
1562 Elf_Internal_Sym *sym)
1565 switch ((unsigned int) ELF32_R_TYPE (rela->r_info))
1567 case R_PARISC_GNU_VTINHERIT:
1568 case R_PARISC_GNU_VTENTRY:
1572 return _bfd_elf_gc_mark_hook (sec, info, rela, hh, sym);
1575 /* Update the got and plt entry reference counts for the section being
1579 elf32_hppa_gc_sweep_hook (bfd *abfd,
1580 struct bfd_link_info *info ATTRIBUTE_UNUSED,
1582 const Elf_Internal_Rela *relocs)
1584 Elf_Internal_Shdr *symtab_hdr;
1585 struct elf_link_hash_entry **eh_syms;
1586 bfd_signed_vma *local_got_refcounts;
1587 bfd_signed_vma *local_plt_refcounts;
1588 const Elf_Internal_Rela *rela, *relend;
1589 struct elf32_hppa_link_hash_table *htab;
1591 if (bfd_link_relocatable (info))
1594 htab = hppa_link_hash_table (info);
1598 elf_section_data (sec)->local_dynrel = NULL;
1600 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1601 eh_syms = elf_sym_hashes (abfd);
1602 local_got_refcounts = elf_local_got_refcounts (abfd);
1603 local_plt_refcounts = local_got_refcounts;
1604 if (local_plt_refcounts != NULL)
1605 local_plt_refcounts += symtab_hdr->sh_info;
1607 relend = relocs + sec->reloc_count;
1608 for (rela = relocs; rela < relend; rela++)
1610 unsigned long r_symndx;
1611 unsigned int r_type;
1612 struct elf_link_hash_entry *eh = NULL;
1614 r_symndx = ELF32_R_SYM (rela->r_info);
1615 if (r_symndx >= symtab_hdr->sh_info)
1617 struct elf32_hppa_link_hash_entry *hh;
1618 struct elf32_hppa_dyn_reloc_entry **hdh_pp;
1619 struct elf32_hppa_dyn_reloc_entry *hdh_p;
1621 eh = eh_syms[r_symndx - symtab_hdr->sh_info];
1622 while (eh->root.type == bfd_link_hash_indirect
1623 || eh->root.type == bfd_link_hash_warning)
1624 eh = (struct elf_link_hash_entry *) eh->root.u.i.link;
1625 hh = hppa_elf_hash_entry (eh);
1627 for (hdh_pp = &hh->dyn_relocs; (hdh_p = *hdh_pp) != NULL; hdh_pp = &hdh_p->hdh_next)
1628 if (hdh_p->sec == sec)
1630 /* Everything must go for SEC. */
1631 *hdh_pp = hdh_p->hdh_next;
1636 r_type = ELF32_R_TYPE (rela->r_info);
1637 r_type = elf32_hppa_optimized_tls_reloc (info, r_type, eh != NULL);
1641 case R_PARISC_DLTIND14F:
1642 case R_PARISC_DLTIND14R:
1643 case R_PARISC_DLTIND21L:
1644 case R_PARISC_TLS_GD21L:
1645 case R_PARISC_TLS_GD14R:
1646 case R_PARISC_TLS_IE21L:
1647 case R_PARISC_TLS_IE14R:
1650 if (eh->got.refcount > 0)
1651 eh->got.refcount -= 1;
1653 else if (local_got_refcounts != NULL)
1655 if (local_got_refcounts[r_symndx] > 0)
1656 local_got_refcounts[r_symndx] -= 1;
1660 case R_PARISC_TLS_LDM21L:
1661 case R_PARISC_TLS_LDM14R:
1662 htab->tls_ldm_got.refcount -= 1;
1665 case R_PARISC_PCREL12F:
1666 case R_PARISC_PCREL17C:
1667 case R_PARISC_PCREL17F:
1668 case R_PARISC_PCREL22F:
1671 if (eh->plt.refcount > 0)
1672 eh->plt.refcount -= 1;
1676 case R_PARISC_PLABEL14R:
1677 case R_PARISC_PLABEL21L:
1678 case R_PARISC_PLABEL32:
1681 if (eh->plt.refcount > 0)
1682 eh->plt.refcount -= 1;
1684 else if (local_plt_refcounts != NULL)
1686 if (local_plt_refcounts[r_symndx] > 0)
1687 local_plt_refcounts[r_symndx] -= 1;
1699 /* Support for core dump NOTE sections. */
1702 elf32_hppa_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
1707 switch (note->descsz)
1712 case 396: /* Linux/hppa */
1714 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
1717 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
1726 /* Make a ".reg/999" section. */
1727 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
1728 size, note->descpos + offset);
1732 elf32_hppa_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
1734 switch (note->descsz)
1739 case 124: /* Linux/hppa elf_prpsinfo. */
1740 elf_tdata (abfd)->core->program
1741 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
1742 elf_tdata (abfd)->core->command
1743 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
1746 /* Note that for some reason, a spurious space is tacked
1747 onto the end of the args in some (at least one anyway)
1748 implementations, so strip it off if it exists. */
1750 char *command = elf_tdata (abfd)->core->command;
1751 int n = strlen (command);
1753 if (0 < n && command[n - 1] == ' ')
1754 command[n - 1] = '\0';
1760 /* Our own version of hide_symbol, so that we can keep plt entries for
1764 elf32_hppa_hide_symbol (struct bfd_link_info *info,
1765 struct elf_link_hash_entry *eh,
1766 bfd_boolean force_local)
1770 eh->forced_local = 1;
1771 if (eh->dynindx != -1)
1774 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
1778 /* PR 16082: Remove version information from hidden symbol. */
1779 eh->verinfo.verdef = NULL;
1780 eh->verinfo.vertree = NULL;
1783 /* STT_GNU_IFUNC symbol must go through PLT. */
1784 if (! hppa_elf_hash_entry (eh)->plabel
1785 && eh->type != STT_GNU_IFUNC)
1788 eh->plt = elf_hash_table (info)->init_plt_offset;
1792 /* Adjust a symbol defined by a dynamic object and referenced by a
1793 regular object. The current definition is in some section of the
1794 dynamic object, but we're not including those sections. We have to
1795 change the definition to something the rest of the link can
1799 elf32_hppa_adjust_dynamic_symbol (struct bfd_link_info *info,
1800 struct elf_link_hash_entry *eh)
1802 struct elf32_hppa_link_hash_table *htab;
1805 /* If this is a function, put it in the procedure linkage table. We
1806 will fill in the contents of the procedure linkage table later. */
1807 if (eh->type == STT_FUNC
1810 /* If the symbol is used by a plabel, we must allocate a PLT slot.
1811 The refcounts are not reliable when it has been hidden since
1812 hide_symbol can be called before the plabel flag is set. */
1813 if (hppa_elf_hash_entry (eh)->plabel
1814 && eh->plt.refcount <= 0)
1815 eh->plt.refcount = 1;
1817 if (eh->plt.refcount <= 0
1819 && eh->root.type != bfd_link_hash_defweak
1820 && ! hppa_elf_hash_entry (eh)->plabel
1821 && (!bfd_link_pic (info) || SYMBOLIC_BIND (info, eh))))
1823 /* The .plt entry is not needed when:
1824 a) Garbage collection has removed all references to the
1826 b) We know for certain the symbol is defined in this
1827 object, and it's not a weak definition, nor is the symbol
1828 used by a plabel relocation. Either this object is the
1829 application or we are doing a shared symbolic link. */
1831 eh->plt.offset = (bfd_vma) -1;
1838 eh->plt.offset = (bfd_vma) -1;
1840 /* If this is a weak symbol, and there is a real definition, the
1841 processor independent code will have arranged for us to see the
1842 real definition first, and we can just use the same value. */
1843 if (eh->u.weakdef != NULL)
1845 if (eh->u.weakdef->root.type != bfd_link_hash_defined
1846 && eh->u.weakdef->root.type != bfd_link_hash_defweak)
1848 eh->root.u.def.section = eh->u.weakdef->root.u.def.section;
1849 eh->root.u.def.value = eh->u.weakdef->root.u.def.value;
1850 if (ELIMINATE_COPY_RELOCS)
1851 eh->non_got_ref = eh->u.weakdef->non_got_ref;
1855 /* This is a reference to a symbol defined by a dynamic object which
1856 is not a function. */
1858 /* If we are creating a shared library, we must presume that the
1859 only references to the symbol are via the global offset table.
1860 For such cases we need not do anything here; the relocations will
1861 be handled correctly by relocate_section. */
1862 if (bfd_link_pic (info))
1865 /* If there are no references to this symbol that do not use the
1866 GOT, we don't need to generate a copy reloc. */
1867 if (!eh->non_got_ref)
1870 if (ELIMINATE_COPY_RELOCS)
1872 struct elf32_hppa_link_hash_entry *hh;
1873 struct elf32_hppa_dyn_reloc_entry *hdh_p;
1875 hh = hppa_elf_hash_entry (eh);
1876 for (hdh_p = hh->dyn_relocs; hdh_p != NULL; hdh_p = hdh_p->hdh_next)
1878 sec = hdh_p->sec->output_section;
1879 if (sec != NULL && (sec->flags & SEC_READONLY) != 0)
1883 /* If we didn't find any dynamic relocs in read-only sections, then
1884 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
1887 eh->non_got_ref = 0;
1892 /* We must allocate the symbol in our .dynbss section, which will
1893 become part of the .bss section of the executable. There will be
1894 an entry for this symbol in the .dynsym section. The dynamic
1895 object will contain position independent code, so all references
1896 from the dynamic object to this symbol will go through the global
1897 offset table. The dynamic linker will use the .dynsym entry to
1898 determine the address it must put in the global offset table, so
1899 both the dynamic object and the regular object will refer to the
1900 same memory location for the variable. */
1902 htab = hppa_link_hash_table (info);
1906 /* We must generate a COPY reloc to tell the dynamic linker to
1907 copy the initial value out of the dynamic object and into the
1908 runtime process image. */
1909 if ((eh->root.u.def.section->flags & SEC_ALLOC) != 0 && eh->size != 0)
1911 htab->srelbss->size += sizeof (Elf32_External_Rela);
1915 sec = htab->sdynbss;
1917 return _bfd_elf_adjust_dynamic_copy (info, eh, sec);
1920 /* Allocate space in the .plt for entries that won't have relocations.
1921 ie. plabel entries. */
1924 allocate_plt_static (struct elf_link_hash_entry *eh, void *inf)
1926 struct bfd_link_info *info;
1927 struct elf32_hppa_link_hash_table *htab;
1928 struct elf32_hppa_link_hash_entry *hh;
1931 if (eh->root.type == bfd_link_hash_indirect)
1934 info = (struct bfd_link_info *) inf;
1935 hh = hppa_elf_hash_entry (eh);
1936 htab = hppa_link_hash_table (info);
1940 if (htab->etab.dynamic_sections_created
1941 && eh->plt.refcount > 0)
1943 /* Make sure this symbol is output as a dynamic symbol.
1944 Undefined weak syms won't yet be marked as dynamic. */
1945 if (eh->dynindx == -1
1946 && !eh->forced_local
1947 && eh->type != STT_PARISC_MILLI)
1949 if (! bfd_elf_link_record_dynamic_symbol (info, eh))
1953 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), eh))
1955 /* Allocate these later. From this point on, h->plabel
1956 means that the plt entry is only used by a plabel.
1957 We'll be using a normal plt entry for this symbol, so
1958 clear the plabel indicator. */
1962 else if (hh->plabel)
1964 /* Make an entry in the .plt section for plabel references
1965 that won't have a .plt entry for other reasons. */
1966 sec = htab->etab.splt;
1967 eh->plt.offset = sec->size;
1968 sec->size += PLT_ENTRY_SIZE;
1972 /* No .plt entry needed. */
1973 eh->plt.offset = (bfd_vma) -1;
1979 eh->plt.offset = (bfd_vma) -1;
1986 /* Allocate space in .plt, .got and associated reloc sections for
1990 allocate_dynrelocs (struct elf_link_hash_entry *eh, void *inf)
1992 struct bfd_link_info *info;
1993 struct elf32_hppa_link_hash_table *htab;
1995 struct elf32_hppa_link_hash_entry *hh;
1996 struct elf32_hppa_dyn_reloc_entry *hdh_p;
1998 if (eh->root.type == bfd_link_hash_indirect)
2002 htab = hppa_link_hash_table (info);
2006 hh = hppa_elf_hash_entry (eh);
2008 if (htab->etab.dynamic_sections_created
2009 && eh->plt.offset != (bfd_vma) -1
2011 && eh->plt.refcount > 0)
2013 /* Make an entry in the .plt section. */
2014 sec = htab->etab.splt;
2015 eh->plt.offset = sec->size;
2016 sec->size += PLT_ENTRY_SIZE;
2018 /* We also need to make an entry in the .rela.plt section. */
2019 htab->etab.srelplt->size += sizeof (Elf32_External_Rela);
2020 htab->need_plt_stub = 1;
2023 if (eh->got.refcount > 0)
2025 /* Make sure this symbol is output as a dynamic symbol.
2026 Undefined weak syms won't yet be marked as dynamic. */
2027 if (eh->dynindx == -1
2028 && !eh->forced_local
2029 && eh->type != STT_PARISC_MILLI)
2031 if (! bfd_elf_link_record_dynamic_symbol (info, eh))
2035 sec = htab->etab.sgot;
2036 eh->got.offset = sec->size;
2037 sec->size += GOT_ENTRY_SIZE;
2038 /* R_PARISC_TLS_GD* needs two GOT entries */
2039 if ((hh->tls_type & (GOT_TLS_GD | GOT_TLS_IE)) == (GOT_TLS_GD | GOT_TLS_IE))
2040 sec->size += GOT_ENTRY_SIZE * 2;
2041 else if ((hh->tls_type & GOT_TLS_GD) == GOT_TLS_GD)
2042 sec->size += GOT_ENTRY_SIZE;
2043 if (htab->etab.dynamic_sections_created
2044 && (bfd_link_pic (info)
2045 || (eh->dynindx != -1
2046 && !eh->forced_local)))
2048 htab->etab.srelgot->size += sizeof (Elf32_External_Rela);
2049 if ((hh->tls_type & (GOT_TLS_GD | GOT_TLS_IE)) == (GOT_TLS_GD | GOT_TLS_IE))
2050 htab->etab.srelgot->size += 2 * sizeof (Elf32_External_Rela);
2051 else if ((hh->tls_type & GOT_TLS_GD) == GOT_TLS_GD)
2052 htab->etab.srelgot->size += sizeof (Elf32_External_Rela);
2056 eh->got.offset = (bfd_vma) -1;
2058 if (hh->dyn_relocs == NULL)
2061 /* If this is a -Bsymbolic shared link, then we need to discard all
2062 space allocated for dynamic pc-relative relocs against symbols
2063 defined in a regular object. For the normal shared case, discard
2064 space for relocs that have become local due to symbol visibility
2066 if (bfd_link_pic (info))
2068 #if RELATIVE_DYNRELOCS
2069 if (SYMBOL_CALLS_LOCAL (info, eh))
2071 struct elf32_hppa_dyn_reloc_entry **hdh_pp;
2073 for (hdh_pp = &hh->dyn_relocs; (hdh_p = *hdh_pp) != NULL; )
2075 hdh_p->count -= hdh_p->relative_count;
2076 hdh_p->relative_count = 0;
2077 if (hdh_p->count == 0)
2078 *hdh_pp = hdh_p->hdh_next;
2080 hdh_pp = &hdh_p->hdh_next;
2085 /* Also discard relocs on undefined weak syms with non-default
2087 if (hh->dyn_relocs != NULL
2088 && eh->root.type == bfd_link_hash_undefweak)
2090 if (ELF_ST_VISIBILITY (eh->other) != STV_DEFAULT)
2091 hh->dyn_relocs = NULL;
2093 /* Make sure undefined weak symbols are output as a dynamic
2095 else if (eh->dynindx == -1
2096 && !eh->forced_local)
2098 if (! bfd_elf_link_record_dynamic_symbol (info, eh))
2105 /* For the non-shared case, discard space for relocs against
2106 symbols which turn out to need copy relocs or are not
2109 if (!eh->non_got_ref
2110 && ((ELIMINATE_COPY_RELOCS
2112 && !eh->def_regular)
2113 || (htab->etab.dynamic_sections_created
2114 && (eh->root.type == bfd_link_hash_undefweak
2115 || eh->root.type == bfd_link_hash_undefined))))
2117 /* Make sure this symbol is output as a dynamic symbol.
2118 Undefined weak syms won't yet be marked as dynamic. */
2119 if (eh->dynindx == -1
2120 && !eh->forced_local
2121 && eh->type != STT_PARISC_MILLI)
2123 if (! bfd_elf_link_record_dynamic_symbol (info, eh))
2127 /* If that succeeded, we know we'll be keeping all the
2129 if (eh->dynindx != -1)
2133 hh->dyn_relocs = NULL;
2139 /* Finally, allocate space. */
2140 for (hdh_p = hh->dyn_relocs; hdh_p != NULL; hdh_p = hdh_p->hdh_next)
2142 asection *sreloc = elf_section_data (hdh_p->sec)->sreloc;
2143 sreloc->size += hdh_p->count * sizeof (Elf32_External_Rela);
2149 /* This function is called via elf_link_hash_traverse to force
2150 millicode symbols local so they do not end up as globals in the
2151 dynamic symbol table. We ought to be able to do this in
2152 adjust_dynamic_symbol, but our adjust_dynamic_symbol is not called
2153 for all dynamic symbols. Arguably, this is a bug in
2154 elf_adjust_dynamic_symbol. */
2157 clobber_millicode_symbols (struct elf_link_hash_entry *eh,
2158 struct bfd_link_info *info)
2160 if (eh->type == STT_PARISC_MILLI
2161 && !eh->forced_local)
2163 elf32_hppa_hide_symbol (info, eh, TRUE);
2168 /* Find any dynamic relocs that apply to read-only sections. */
2171 readonly_dynrelocs (struct elf_link_hash_entry *eh, void *inf)
2173 struct elf32_hppa_link_hash_entry *hh;
2174 struct elf32_hppa_dyn_reloc_entry *hdh_p;
2176 hh = hppa_elf_hash_entry (eh);
2177 for (hdh_p = hh->dyn_relocs; hdh_p != NULL; hdh_p = hdh_p->hdh_next)
2179 asection *sec = hdh_p->sec->output_section;
2181 if (sec != NULL && (sec->flags & SEC_READONLY) != 0)
2183 struct bfd_link_info *info = inf;
2185 info->flags |= DF_TEXTREL;
2187 /* Not an error, just cut short the traversal. */
2194 /* Set the sizes of the dynamic sections. */
2197 elf32_hppa_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
2198 struct bfd_link_info *info)
2200 struct elf32_hppa_link_hash_table *htab;
2206 htab = hppa_link_hash_table (info);
2210 dynobj = htab->etab.dynobj;
2214 if (htab->etab.dynamic_sections_created)
2216 /* Set the contents of the .interp section to the interpreter. */
2217 if (bfd_link_executable (info) && !info->nointerp)
2219 sec = bfd_get_linker_section (dynobj, ".interp");
2222 sec->size = sizeof ELF_DYNAMIC_INTERPRETER;
2223 sec->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
2226 /* Force millicode symbols local. */
2227 elf_link_hash_traverse (&htab->etab,
2228 clobber_millicode_symbols,
2232 /* Set up .got and .plt offsets for local syms, and space for local
2234 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
2236 bfd_signed_vma *local_got;
2237 bfd_signed_vma *end_local_got;
2238 bfd_signed_vma *local_plt;
2239 bfd_signed_vma *end_local_plt;
2240 bfd_size_type locsymcount;
2241 Elf_Internal_Shdr *symtab_hdr;
2243 char *local_tls_type;
2245 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
2248 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
2250 struct elf32_hppa_dyn_reloc_entry *hdh_p;
2252 for (hdh_p = ((struct elf32_hppa_dyn_reloc_entry *)
2253 elf_section_data (sec)->local_dynrel);
2255 hdh_p = hdh_p->hdh_next)
2257 if (!bfd_is_abs_section (hdh_p->sec)
2258 && bfd_is_abs_section (hdh_p->sec->output_section))
2260 /* Input section has been discarded, either because
2261 it is a copy of a linkonce section or due to
2262 linker script /DISCARD/, so we'll be discarding
2265 else if (hdh_p->count != 0)
2267 srel = elf_section_data (hdh_p->sec)->sreloc;
2268 srel->size += hdh_p->count * sizeof (Elf32_External_Rela);
2269 if ((hdh_p->sec->output_section->flags & SEC_READONLY) != 0)
2270 info->flags |= DF_TEXTREL;
2275 local_got = elf_local_got_refcounts (ibfd);
2279 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
2280 locsymcount = symtab_hdr->sh_info;
2281 end_local_got = local_got + locsymcount;
2282 local_tls_type = hppa_elf_local_got_tls_type (ibfd);
2283 sec = htab->etab.sgot;
2284 srel = htab->etab.srelgot;
2285 for (; local_got < end_local_got; ++local_got)
2289 *local_got = sec->size;
2290 sec->size += GOT_ENTRY_SIZE;
2291 if ((*local_tls_type & (GOT_TLS_GD | GOT_TLS_IE)) == (GOT_TLS_GD | GOT_TLS_IE))
2292 sec->size += 2 * GOT_ENTRY_SIZE;
2293 else if ((*local_tls_type & GOT_TLS_GD) == GOT_TLS_GD)
2294 sec->size += GOT_ENTRY_SIZE;
2295 if (bfd_link_pic (info))
2297 srel->size += sizeof (Elf32_External_Rela);
2298 if ((*local_tls_type & (GOT_TLS_GD | GOT_TLS_IE)) == (GOT_TLS_GD | GOT_TLS_IE))
2299 srel->size += 2 * sizeof (Elf32_External_Rela);
2300 else if ((*local_tls_type & GOT_TLS_GD) == GOT_TLS_GD)
2301 srel->size += sizeof (Elf32_External_Rela);
2305 *local_got = (bfd_vma) -1;
2310 local_plt = end_local_got;
2311 end_local_plt = local_plt + locsymcount;
2312 if (! htab->etab.dynamic_sections_created)
2314 /* Won't be used, but be safe. */
2315 for (; local_plt < end_local_plt; ++local_plt)
2316 *local_plt = (bfd_vma) -1;
2320 sec = htab->etab.splt;
2321 srel = htab->etab.srelplt;
2322 for (; local_plt < end_local_plt; ++local_plt)
2326 *local_plt = sec->size;
2327 sec->size += PLT_ENTRY_SIZE;
2328 if (bfd_link_pic (info))
2329 srel->size += sizeof (Elf32_External_Rela);
2332 *local_plt = (bfd_vma) -1;
2337 if (htab->tls_ldm_got.refcount > 0)
2339 /* Allocate 2 got entries and 1 dynamic reloc for
2340 R_PARISC_TLS_DTPMOD32 relocs. */
2341 htab->tls_ldm_got.offset = htab->etab.sgot->size;
2342 htab->etab.sgot->size += (GOT_ENTRY_SIZE * 2);
2343 htab->etab.srelgot->size += sizeof (Elf32_External_Rela);
2346 htab->tls_ldm_got.offset = -1;
2348 /* Do all the .plt entries without relocs first. The dynamic linker
2349 uses the last .plt reloc to find the end of the .plt (and hence
2350 the start of the .got) for lazy linking. */
2351 elf_link_hash_traverse (&htab->etab, allocate_plt_static, info);
2353 /* Allocate global sym .plt and .got entries, and space for global
2354 sym dynamic relocs. */
2355 elf_link_hash_traverse (&htab->etab, allocate_dynrelocs, info);
2357 /* The check_relocs and adjust_dynamic_symbol entry points have
2358 determined the sizes of the various dynamic sections. Allocate
2361 for (sec = dynobj->sections; sec != NULL; sec = sec->next)
2363 if ((sec->flags & SEC_LINKER_CREATED) == 0)
2366 if (sec == htab->etab.splt)
2368 if (htab->need_plt_stub)
2370 /* Make space for the plt stub at the end of the .plt
2371 section. We want this stub right at the end, up
2372 against the .got section. */
2373 int gotalign = bfd_section_alignment (dynobj, htab->etab.sgot);
2374 int pltalign = bfd_section_alignment (dynobj, sec);
2377 if (gotalign > pltalign)
2378 (void) bfd_set_section_alignment (dynobj, sec, gotalign);
2379 mask = ((bfd_size_type) 1 << gotalign) - 1;
2380 sec->size = (sec->size + sizeof (plt_stub) + mask) & ~mask;
2383 else if (sec == htab->etab.sgot
2384 || sec == htab->sdynbss)
2386 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, sec), ".rela"))
2390 /* Remember whether there are any reloc sections other
2392 if (sec != htab->etab.srelplt)
2395 /* We use the reloc_count field as a counter if we need
2396 to copy relocs into the output file. */
2397 sec->reloc_count = 0;
2402 /* It's not one of our sections, so don't allocate space. */
2408 /* If we don't need this section, strip it from the
2409 output file. This is mostly to handle .rela.bss and
2410 .rela.plt. We must create both sections in
2411 create_dynamic_sections, because they must be created
2412 before the linker maps input sections to output
2413 sections. The linker does that before
2414 adjust_dynamic_symbol is called, and it is that
2415 function which decides whether anything needs to go
2416 into these sections. */
2417 sec->flags |= SEC_EXCLUDE;
2421 if ((sec->flags & SEC_HAS_CONTENTS) == 0)
2424 /* Allocate memory for the section contents. Zero it, because
2425 we may not fill in all the reloc sections. */
2426 sec->contents = bfd_zalloc (dynobj, sec->size);
2427 if (sec->contents == NULL)
2431 if (htab->etab.dynamic_sections_created)
2433 /* Like IA-64 and HPPA64, always create a DT_PLTGOT. It
2434 actually has nothing to do with the PLT, it is how we
2435 communicate the LTP value of a load module to the dynamic
2437 #define add_dynamic_entry(TAG, VAL) \
2438 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2440 if (!add_dynamic_entry (DT_PLTGOT, 0))
2443 /* Add some entries to the .dynamic section. We fill in the
2444 values later, in elf32_hppa_finish_dynamic_sections, but we
2445 must add the entries now so that we get the correct size for
2446 the .dynamic section. The DT_DEBUG entry is filled in by the
2447 dynamic linker and used by the debugger. */
2448 if (bfd_link_executable (info))
2450 if (!add_dynamic_entry (DT_DEBUG, 0))
2454 if (htab->etab.srelplt->size != 0)
2456 if (!add_dynamic_entry (DT_PLTRELSZ, 0)
2457 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
2458 || !add_dynamic_entry (DT_JMPREL, 0))
2464 if (!add_dynamic_entry (DT_RELA, 0)
2465 || !add_dynamic_entry (DT_RELASZ, 0)
2466 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
2469 /* If any dynamic relocs apply to a read-only section,
2470 then we need a DT_TEXTREL entry. */
2471 if ((info->flags & DF_TEXTREL) == 0)
2472 elf_link_hash_traverse (&htab->etab, readonly_dynrelocs, info);
2474 if ((info->flags & DF_TEXTREL) != 0)
2476 if (!add_dynamic_entry (DT_TEXTREL, 0))
2481 #undef add_dynamic_entry
2486 /* External entry points for sizing and building linker stubs. */
2488 /* Set up various things so that we can make a list of input sections
2489 for each output section included in the link. Returns -1 on error,
2490 0 when no stubs will be needed, and 1 on success. */
2493 elf32_hppa_setup_section_lists (bfd *output_bfd, struct bfd_link_info *info)
2496 unsigned int bfd_count;
2497 unsigned int top_id, top_index;
2499 asection **input_list, **list;
2501 struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info);
2506 /* Count the number of input BFDs and find the top input section id. */
2507 for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
2509 input_bfd = input_bfd->link.next)
2512 for (section = input_bfd->sections;
2514 section = section->next)
2516 if (top_id < section->id)
2517 top_id = section->id;
2520 htab->bfd_count = bfd_count;
2522 amt = sizeof (struct map_stub) * (top_id + 1);
2523 htab->stub_group = bfd_zmalloc (amt);
2524 if (htab->stub_group == NULL)
2527 /* We can't use output_bfd->section_count here to find the top output
2528 section index as some sections may have been removed, and
2529 strip_excluded_output_sections doesn't renumber the indices. */
2530 for (section = output_bfd->sections, top_index = 0;
2532 section = section->next)
2534 if (top_index < section->index)
2535 top_index = section->index;
2538 htab->top_index = top_index;
2539 amt = sizeof (asection *) * (top_index + 1);
2540 input_list = bfd_malloc (amt);
2541 htab->input_list = input_list;
2542 if (input_list == NULL)
2545 /* For sections we aren't interested in, mark their entries with a
2546 value we can check later. */
2547 list = input_list + top_index;
2549 *list = bfd_abs_section_ptr;
2550 while (list-- != input_list);
2552 for (section = output_bfd->sections;
2554 section = section->next)
2556 if ((section->flags & SEC_CODE) != 0)
2557 input_list[section->index] = NULL;
2563 /* The linker repeatedly calls this function for each input section,
2564 in the order that input sections are linked into output sections.
2565 Build lists of input sections to determine groupings between which
2566 we may insert linker stubs. */
2569 elf32_hppa_next_input_section (struct bfd_link_info *info, asection *isec)
2571 struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info);
2576 if (isec->output_section->index <= htab->top_index)
2578 asection **list = htab->input_list + isec->output_section->index;
2579 if (*list != bfd_abs_section_ptr)
2581 /* Steal the link_sec pointer for our list. */
2582 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
2583 /* This happens to make the list in reverse order,
2584 which is what we want. */
2585 PREV_SEC (isec) = *list;
2591 /* See whether we can group stub sections together. Grouping stub
2592 sections may result in fewer stubs. More importantly, we need to
2593 put all .init* and .fini* stubs at the beginning of the .init or
2594 .fini output sections respectively, because glibc splits the
2595 _init and _fini functions into multiple parts. Putting a stub in
2596 the middle of a function is not a good idea. */
2599 group_sections (struct elf32_hppa_link_hash_table *htab,
2600 bfd_size_type stub_group_size,
2601 bfd_boolean stubs_always_before_branch)
2603 asection **list = htab->input_list + htab->top_index;
2606 asection *tail = *list;
2607 if (tail == bfd_abs_section_ptr)
2609 while (tail != NULL)
2613 bfd_size_type total;
2614 bfd_boolean big_sec;
2618 big_sec = total >= stub_group_size;
2620 while ((prev = PREV_SEC (curr)) != NULL
2621 && ((total += curr->output_offset - prev->output_offset)
2625 /* OK, the size from the start of CURR to the end is less
2626 than 240000 bytes and thus can be handled by one stub
2627 section. (or the tail section is itself larger than
2628 240000 bytes, in which case we may be toast.)
2629 We should really be keeping track of the total size of
2630 stubs added here, as stubs contribute to the final output
2631 section size. That's a little tricky, and this way will
2632 only break if stubs added total more than 22144 bytes, or
2633 2768 long branch stubs. It seems unlikely for more than
2634 2768 different functions to be called, especially from
2635 code only 240000 bytes long. This limit used to be
2636 250000, but c++ code tends to generate lots of little
2637 functions, and sometimes violated the assumption. */
2640 prev = PREV_SEC (tail);
2641 /* Set up this stub group. */
2642 htab->stub_group[tail->id].link_sec = curr;
2644 while (tail != curr && (tail = prev) != NULL);
2646 /* But wait, there's more! Input sections up to 240000
2647 bytes before the stub section can be handled by it too.
2648 Don't do this if we have a really large section after the
2649 stubs, as adding more stubs increases the chance that
2650 branches may not reach into the stub section. */
2651 if (!stubs_always_before_branch && !big_sec)
2655 && ((total += tail->output_offset - prev->output_offset)
2659 prev = PREV_SEC (tail);
2660 htab->stub_group[tail->id].link_sec = curr;
2666 while (list-- != htab->input_list);
2667 free (htab->input_list);
2671 /* Read in all local syms for all input bfds, and create hash entries
2672 for export stubs if we are building a multi-subspace shared lib.
2673 Returns -1 on error, 1 if export stubs created, 0 otherwise. */
2676 get_local_syms (bfd *output_bfd, bfd *input_bfd, struct bfd_link_info *info)
2678 unsigned int bfd_indx;
2679 Elf_Internal_Sym *local_syms, **all_local_syms;
2680 int stub_changed = 0;
2681 struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info);
2686 /* We want to read in symbol extension records only once. To do this
2687 we need to read in the local symbols in parallel and save them for
2688 later use; so hold pointers to the local symbols in an array. */
2689 bfd_size_type amt = sizeof (Elf_Internal_Sym *) * htab->bfd_count;
2690 all_local_syms = bfd_zmalloc (amt);
2691 htab->all_local_syms = all_local_syms;
2692 if (all_local_syms == NULL)
2695 /* Walk over all the input BFDs, swapping in local symbols.
2696 If we are creating a shared library, create hash entries for the
2700 input_bfd = input_bfd->link.next, bfd_indx++)
2702 Elf_Internal_Shdr *symtab_hdr;
2704 /* We'll need the symbol table in a second. */
2705 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2706 if (symtab_hdr->sh_info == 0)
2709 /* We need an array of the local symbols attached to the input bfd. */
2710 local_syms = (Elf_Internal_Sym *) symtab_hdr->contents;
2711 if (local_syms == NULL)
2713 local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
2714 symtab_hdr->sh_info, 0,
2716 /* Cache them for elf_link_input_bfd. */
2717 symtab_hdr->contents = (unsigned char *) local_syms;
2719 if (local_syms == NULL)
2722 all_local_syms[bfd_indx] = local_syms;
2724 if (bfd_link_pic (info) && htab->multi_subspace)
2726 struct elf_link_hash_entry **eh_syms;
2727 struct elf_link_hash_entry **eh_symend;
2728 unsigned int symcount;
2730 symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
2731 - symtab_hdr->sh_info);
2732 eh_syms = (struct elf_link_hash_entry **) elf_sym_hashes (input_bfd);
2733 eh_symend = (struct elf_link_hash_entry **) (eh_syms + symcount);
2735 /* Look through the global syms for functions; We need to
2736 build export stubs for all globally visible functions. */
2737 for (; eh_syms < eh_symend; eh_syms++)
2739 struct elf32_hppa_link_hash_entry *hh;
2741 hh = hppa_elf_hash_entry (*eh_syms);
2743 while (hh->eh.root.type == bfd_link_hash_indirect
2744 || hh->eh.root.type == bfd_link_hash_warning)
2745 hh = hppa_elf_hash_entry (hh->eh.root.u.i.link);
2747 /* At this point in the link, undefined syms have been
2748 resolved, so we need to check that the symbol was
2749 defined in this BFD. */
2750 if ((hh->eh.root.type == bfd_link_hash_defined
2751 || hh->eh.root.type == bfd_link_hash_defweak)
2752 && hh->eh.type == STT_FUNC
2753 && hh->eh.root.u.def.section->output_section != NULL
2754 && (hh->eh.root.u.def.section->output_section->owner
2756 && hh->eh.root.u.def.section->owner == input_bfd
2757 && hh->eh.def_regular
2758 && !hh->eh.forced_local
2759 && ELF_ST_VISIBILITY (hh->eh.other) == STV_DEFAULT)
2762 const char *stub_name;
2763 struct elf32_hppa_stub_hash_entry *hsh;
2765 sec = hh->eh.root.u.def.section;
2766 stub_name = hh_name (hh);
2767 hsh = hppa_stub_hash_lookup (&htab->bstab,
2772 hsh = hppa_add_stub (stub_name, sec, htab);
2776 hsh->target_value = hh->eh.root.u.def.value;
2777 hsh->target_section = hh->eh.root.u.def.section;
2778 hsh->stub_type = hppa_stub_export;
2784 /* xgettext:c-format */
2785 _bfd_error_handler (_("%B: duplicate export stub %s"),
2786 input_bfd, stub_name);
2793 return stub_changed;
2796 /* Determine and set the size of the stub section for a final link.
2798 The basic idea here is to examine all the relocations looking for
2799 PC-relative calls to a target that is unreachable with a "bl"
2803 elf32_hppa_size_stubs
2804 (bfd *output_bfd, bfd *stub_bfd, struct bfd_link_info *info,
2805 bfd_boolean multi_subspace, bfd_signed_vma group_size,
2806 asection * (*add_stub_section) (const char *, asection *),
2807 void (*layout_sections_again) (void))
2809 bfd_size_type stub_group_size;
2810 bfd_boolean stubs_always_before_branch;
2811 bfd_boolean stub_changed;
2812 struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info);
2817 /* Stash our params away. */
2818 htab->stub_bfd = stub_bfd;
2819 htab->multi_subspace = multi_subspace;
2820 htab->add_stub_section = add_stub_section;
2821 htab->layout_sections_again = layout_sections_again;
2822 stubs_always_before_branch = group_size < 0;
2824 stub_group_size = -group_size;
2826 stub_group_size = group_size;
2827 if (stub_group_size == 1)
2829 /* Default values. */
2830 if (stubs_always_before_branch)
2832 stub_group_size = 7680000;
2833 if (htab->has_17bit_branch || htab->multi_subspace)
2834 stub_group_size = 240000;
2835 if (htab->has_12bit_branch)
2836 stub_group_size = 7500;
2840 stub_group_size = 6971392;
2841 if (htab->has_17bit_branch || htab->multi_subspace)
2842 stub_group_size = 217856;
2843 if (htab->has_12bit_branch)
2844 stub_group_size = 6808;
2848 group_sections (htab, stub_group_size, stubs_always_before_branch);
2850 switch (get_local_syms (output_bfd, info->input_bfds, info))
2853 if (htab->all_local_syms)
2854 goto error_ret_free_local;
2858 stub_changed = FALSE;
2862 stub_changed = TRUE;
2869 unsigned int bfd_indx;
2872 for (input_bfd = info->input_bfds, bfd_indx = 0;
2874 input_bfd = input_bfd->link.next, bfd_indx++)
2876 Elf_Internal_Shdr *symtab_hdr;
2878 Elf_Internal_Sym *local_syms;
2880 /* We'll need the symbol table in a second. */
2881 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2882 if (symtab_hdr->sh_info == 0)
2885 local_syms = htab->all_local_syms[bfd_indx];
2887 /* Walk over each section attached to the input bfd. */
2888 for (section = input_bfd->sections;
2890 section = section->next)
2892 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
2894 /* If there aren't any relocs, then there's nothing more
2896 if ((section->flags & SEC_RELOC) == 0
2897 || section->reloc_count == 0)
2900 /* If this section is a link-once section that will be
2901 discarded, then don't create any stubs. */
2902 if (section->output_section == NULL
2903 || section->output_section->owner != output_bfd)
2906 /* Get the relocs. */
2908 = _bfd_elf_link_read_relocs (input_bfd, section, NULL, NULL,
2910 if (internal_relocs == NULL)
2911 goto error_ret_free_local;
2913 /* Now examine each relocation. */
2914 irela = internal_relocs;
2915 irelaend = irela + section->reloc_count;
2916 for (; irela < irelaend; irela++)
2918 unsigned int r_type, r_indx;
2919 enum elf32_hppa_stub_type stub_type;
2920 struct elf32_hppa_stub_hash_entry *hsh;
2923 bfd_vma destination;
2924 struct elf32_hppa_link_hash_entry *hh;
2926 const asection *id_sec;
2928 r_type = ELF32_R_TYPE (irela->r_info);
2929 r_indx = ELF32_R_SYM (irela->r_info);
2931 if (r_type >= (unsigned int) R_PARISC_UNIMPLEMENTED)
2933 bfd_set_error (bfd_error_bad_value);
2934 error_ret_free_internal:
2935 if (elf_section_data (section)->relocs == NULL)
2936 free (internal_relocs);
2937 goto error_ret_free_local;
2940 /* Only look for stubs on call instructions. */
2941 if (r_type != (unsigned int) R_PARISC_PCREL12F
2942 && r_type != (unsigned int) R_PARISC_PCREL17F
2943 && r_type != (unsigned int) R_PARISC_PCREL22F)
2946 /* Now determine the call target, its name, value,
2952 if (r_indx < symtab_hdr->sh_info)
2954 /* It's a local symbol. */
2955 Elf_Internal_Sym *sym;
2956 Elf_Internal_Shdr *hdr;
2959 sym = local_syms + r_indx;
2960 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
2961 sym_value = sym->st_value;
2962 shndx = sym->st_shndx;
2963 if (shndx < elf_numsections (input_bfd))
2965 hdr = elf_elfsections (input_bfd)[shndx];
2966 sym_sec = hdr->bfd_section;
2967 destination = (sym_value + irela->r_addend
2968 + sym_sec->output_offset
2969 + sym_sec->output_section->vma);
2974 /* It's an external symbol. */
2977 e_indx = r_indx - symtab_hdr->sh_info;
2978 hh = hppa_elf_hash_entry (elf_sym_hashes (input_bfd)[e_indx]);
2980 while (hh->eh.root.type == bfd_link_hash_indirect
2981 || hh->eh.root.type == bfd_link_hash_warning)
2982 hh = hppa_elf_hash_entry (hh->eh.root.u.i.link);
2984 if (hh->eh.root.type == bfd_link_hash_defined
2985 || hh->eh.root.type == bfd_link_hash_defweak)
2987 sym_sec = hh->eh.root.u.def.section;
2988 sym_value = hh->eh.root.u.def.value;
2989 if (sym_sec->output_section != NULL)
2990 destination = (sym_value + irela->r_addend
2991 + sym_sec->output_offset
2992 + sym_sec->output_section->vma);
2994 else if (hh->eh.root.type == bfd_link_hash_undefweak)
2996 if (! bfd_link_pic (info))
2999 else if (hh->eh.root.type == bfd_link_hash_undefined)
3001 if (! (info->unresolved_syms_in_objects == RM_IGNORE
3002 && (ELF_ST_VISIBILITY (hh->eh.other)
3004 && hh->eh.type != STT_PARISC_MILLI))
3009 bfd_set_error (bfd_error_bad_value);
3010 goto error_ret_free_internal;
3014 /* Determine what (if any) linker stub is needed. */
3015 stub_type = hppa_type_of_stub (section, irela, hh,
3017 if (stub_type == hppa_stub_none)
3020 /* Support for grouping stub sections. */
3021 id_sec = htab->stub_group[section->id].link_sec;
3023 /* Get the name of this stub. */
3024 stub_name = hppa_stub_name (id_sec, sym_sec, hh, irela);
3026 goto error_ret_free_internal;
3028 hsh = hppa_stub_hash_lookup (&htab->bstab,
3033 /* The proper stub has already been created. */
3038 hsh = hppa_add_stub (stub_name, section, htab);
3042 goto error_ret_free_internal;
3045 hsh->target_value = sym_value;
3046 hsh->target_section = sym_sec;
3047 hsh->stub_type = stub_type;
3048 if (bfd_link_pic (info))
3050 if (stub_type == hppa_stub_import)
3051 hsh->stub_type = hppa_stub_import_shared;
3052 else if (stub_type == hppa_stub_long_branch)
3053 hsh->stub_type = hppa_stub_long_branch_shared;
3056 stub_changed = TRUE;
3059 /* We're done with the internal relocs, free them. */
3060 if (elf_section_data (section)->relocs == NULL)
3061 free (internal_relocs);
3068 /* OK, we've added some stubs. Find out the new size of the
3070 for (stub_sec = htab->stub_bfd->sections;
3072 stub_sec = stub_sec->next)
3073 if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
3076 bfd_hash_traverse (&htab->bstab, hppa_size_one_stub, htab);
3078 /* Ask the linker to do its stuff. */
3079 (*htab->layout_sections_again) ();
3080 stub_changed = FALSE;
3083 free (htab->all_local_syms);
3086 error_ret_free_local:
3087 free (htab->all_local_syms);
3091 /* For a final link, this function is called after we have sized the
3092 stubs to provide a value for __gp. */
3095 elf32_hppa_set_gp (bfd *abfd, struct bfd_link_info *info)
3097 struct bfd_link_hash_entry *h;
3098 asection *sec = NULL;
3100 struct elf32_hppa_link_hash_table *htab;
3102 htab = hppa_link_hash_table (info);
3106 h = bfd_link_hash_lookup (&htab->etab.root, "$global$", FALSE, FALSE, FALSE);
3109 && (h->type == bfd_link_hash_defined
3110 || h->type == bfd_link_hash_defweak))
3112 gp_val = h->u.def.value;
3113 sec = h->u.def.section;
3117 asection *splt = bfd_get_section_by_name (abfd, ".plt");
3118 asection *sgot = bfd_get_section_by_name (abfd, ".got");
3120 /* Choose to point our LTP at, in this order, one of .plt, .got,
3121 or .data, if these sections exist. In the case of choosing
3122 .plt try to make the LTP ideal for addressing anywhere in the
3123 .plt or .got with a 14 bit signed offset. Typically, the end
3124 of the .plt is the start of the .got, so choose .plt + 0x2000
3125 if either the .plt or .got is larger than 0x2000. If both
3126 the .plt and .got are smaller than 0x2000, choose the end of
3127 the .plt section. */
3128 sec = strcmp (bfd_get_target (abfd), "elf32-hppa-netbsd") == 0
3133 if (gp_val > 0x2000 || (sgot && sgot->size > 0x2000))
3143 if (strcmp (bfd_get_target (abfd), "elf32-hppa-netbsd") != 0)
3145 /* We know we don't have a .plt. If .got is large,
3147 if (sec->size > 0x2000)
3153 /* No .plt or .got. Who cares what the LTP is? */
3154 sec = bfd_get_section_by_name (abfd, ".data");
3160 h->type = bfd_link_hash_defined;
3161 h->u.def.value = gp_val;
3163 h->u.def.section = sec;
3165 h->u.def.section = bfd_abs_section_ptr;
3169 if (sec != NULL && sec->output_section != NULL)
3170 gp_val += sec->output_section->vma + sec->output_offset;
3172 elf_gp (abfd) = gp_val;
3176 /* Build all the stubs associated with the current output file. The
3177 stubs are kept in a hash table attached to the main linker hash
3178 table. We also set up the .plt entries for statically linked PIC
3179 functions here. This function is called via hppaelf_finish in the
3183 elf32_hppa_build_stubs (struct bfd_link_info *info)
3186 struct bfd_hash_table *table;
3187 struct elf32_hppa_link_hash_table *htab;
3189 htab = hppa_link_hash_table (info);
3193 for (stub_sec = htab->stub_bfd->sections;
3195 stub_sec = stub_sec->next)
3196 if ((stub_sec->flags & SEC_LINKER_CREATED) == 0
3197 && stub_sec->size != 0)
3199 /* Allocate memory to hold the linker stubs. */
3200 stub_sec->contents = bfd_zalloc (htab->stub_bfd, stub_sec->size);
3201 if (stub_sec->contents == NULL)
3206 /* Build the stubs as directed by the stub hash table. */
3207 table = &htab->bstab;
3208 bfd_hash_traverse (table, hppa_build_one_stub, info);
3213 /* Return the base vma address which should be subtracted from the real
3214 address when resolving a dtpoff relocation.
3215 This is PT_TLS segment p_vaddr. */
3218 dtpoff_base (struct bfd_link_info *info)
3220 /* If tls_sec is NULL, we should have signalled an error already. */
3221 if (elf_hash_table (info)->tls_sec == NULL)
3223 return elf_hash_table (info)->tls_sec->vma;
3226 /* Return the relocation value for R_PARISC_TLS_TPOFF*.. */
3229 tpoff (struct bfd_link_info *info, bfd_vma address)
3231 struct elf_link_hash_table *htab = elf_hash_table (info);
3233 /* If tls_sec is NULL, we should have signalled an error already. */
3234 if (htab->tls_sec == NULL)
3236 /* hppa TLS ABI is variant I and static TLS block start just after
3237 tcbhead structure which has 2 pointer fields. */
3238 return (address - htab->tls_sec->vma
3239 + align_power ((bfd_vma) 8, htab->tls_sec->alignment_power));
3242 /* Perform a final link. */
3245 elf32_hppa_final_link (bfd *abfd, struct bfd_link_info *info)
3249 /* Invoke the regular ELF linker to do all the work. */
3250 if (!bfd_elf_final_link (abfd, info))
3253 /* If we're producing a final executable, sort the contents of the
3255 if (bfd_link_relocatable (info))
3258 /* Do not attempt to sort non-regular files. This is here
3259 especially for configure scripts and kernel builds which run
3260 tests with "ld [...] -o /dev/null". */
3261 if (stat (abfd->filename, &buf) != 0
3262 || !S_ISREG(buf.st_mode))
3265 return elf_hppa_sort_unwind (abfd);
3268 /* Record the lowest address for the data and text segments. */
3271 hppa_record_segment_addr (bfd *abfd, asection *section, void *data)
3273 struct elf32_hppa_link_hash_table *htab;
3275 htab = (struct elf32_hppa_link_hash_table*) data;
3279 if ((section->flags & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
3282 Elf_Internal_Phdr *p;
3284 p = _bfd_elf_find_segment_containing_section (abfd, section->output_section);
3285 BFD_ASSERT (p != NULL);
3288 if ((section->flags & SEC_READONLY) != 0)
3290 if (value < htab->text_segment_base)
3291 htab->text_segment_base = value;
3295 if (value < htab->data_segment_base)
3296 htab->data_segment_base = value;
3301 /* Perform a relocation as part of a final link. */
3303 static bfd_reloc_status_type
3304 final_link_relocate (asection *input_section,
3306 const Elf_Internal_Rela *rela,
3308 struct elf32_hppa_link_hash_table *htab,
3310 struct elf32_hppa_link_hash_entry *hh,
3311 struct bfd_link_info *info)
3314 unsigned int r_type = ELF32_R_TYPE (rela->r_info);
3315 unsigned int orig_r_type = r_type;
3316 reloc_howto_type *howto = elf_hppa_howto_table + r_type;
3317 int r_format = howto->bitsize;
3318 enum hppa_reloc_field_selector_type_alt r_field;
3319 bfd *input_bfd = input_section->owner;
3320 bfd_vma offset = rela->r_offset;
3321 bfd_vma max_branch_offset = 0;
3322 bfd_byte *hit_data = contents + offset;
3323 bfd_signed_vma addend = rela->r_addend;
3325 struct elf32_hppa_stub_hash_entry *hsh = NULL;
3328 if (r_type == R_PARISC_NONE)
3329 return bfd_reloc_ok;
3331 insn = bfd_get_32 (input_bfd, hit_data);
3333 /* Find out where we are and where we're going. */
3334 location = (offset +
3335 input_section->output_offset +
3336 input_section->output_section->vma);
3338 /* If we are not building a shared library, convert DLTIND relocs to
3340 if (!bfd_link_pic (info))
3344 case R_PARISC_DLTIND21L:
3345 case R_PARISC_TLS_GD21L:
3346 case R_PARISC_TLS_LDM21L:
3347 case R_PARISC_TLS_IE21L:
3348 r_type = R_PARISC_DPREL21L;
3351 case R_PARISC_DLTIND14R:
3352 case R_PARISC_TLS_GD14R:
3353 case R_PARISC_TLS_LDM14R:
3354 case R_PARISC_TLS_IE14R:
3355 r_type = R_PARISC_DPREL14R;
3358 case R_PARISC_DLTIND14F:
3359 r_type = R_PARISC_DPREL14F;
3366 case R_PARISC_PCREL12F:
3367 case R_PARISC_PCREL17F:
3368 case R_PARISC_PCREL22F:
3369 /* If this call should go via the plt, find the import stub in
3372 || sym_sec->output_section == NULL
3374 && hh->eh.plt.offset != (bfd_vma) -1
3375 && hh->eh.dynindx != -1
3377 && (bfd_link_pic (info)
3378 || !hh->eh.def_regular
3379 || hh->eh.root.type == bfd_link_hash_defweak)))
3381 hsh = hppa_get_stub_entry (input_section, sym_sec,
3385 value = (hsh->stub_offset
3386 + hsh->stub_sec->output_offset
3387 + hsh->stub_sec->output_section->vma);
3390 else if (sym_sec == NULL && hh != NULL
3391 && hh->eh.root.type == bfd_link_hash_undefweak)
3393 /* It's OK if undefined weak. Calls to undefined weak
3394 symbols behave as if the "called" function
3395 immediately returns. We can thus call to a weak
3396 function without first checking whether the function
3402 return bfd_reloc_undefined;
3406 case R_PARISC_PCREL21L:
3407 case R_PARISC_PCREL17C:
3408 case R_PARISC_PCREL17R:
3409 case R_PARISC_PCREL14R:
3410 case R_PARISC_PCREL14F:
3411 case R_PARISC_PCREL32:
3412 /* Make it a pc relative offset. */
3417 case R_PARISC_DPREL21L:
3418 case R_PARISC_DPREL14R:
3419 case R_PARISC_DPREL14F:
3420 /* Convert instructions that use the linkage table pointer (r19) to
3421 instructions that use the global data pointer (dp). This is the
3422 most efficient way of using PIC code in an incomplete executable,
3423 but the user must follow the standard runtime conventions for
3424 accessing data for this to work. */
3425 if (orig_r_type != r_type)
3427 if (r_type == R_PARISC_DPREL21L)
3429 /* GCC sometimes uses a register other than r19 for the
3430 operation, so we must convert any addil instruction
3431 that uses this relocation. */
3432 if ((insn & 0xfc000000) == ((int) OP_ADDIL << 26))
3435 /* We must have a ldil instruction. It's too hard to find
3436 and convert the associated add instruction, so issue an
3439 /* xgettext:c-format */
3440 (_("%B(%A+0x%lx): %s fixup for insn 0x%x is not supported in a non-shared link"),
3447 else if (r_type == R_PARISC_DPREL14F)
3449 /* This must be a format 1 load/store. Change the base
3451 insn = (insn & 0xfc1ffff) | (27 << 21);
3455 /* For all the DP relative relocations, we need to examine the symbol's
3456 section. If it has no section or if it's a code section, then
3457 "data pointer relative" makes no sense. In that case we don't
3458 adjust the "value", and for 21 bit addil instructions, we change the
3459 source addend register from %dp to %r0. This situation commonly
3460 arises for undefined weak symbols and when a variable's "constness"
3461 is declared differently from the way the variable is defined. For
3462 instance: "extern int foo" with foo defined as "const int foo". */
3463 if (sym_sec == NULL || (sym_sec->flags & SEC_CODE) != 0)
3465 if ((insn & ((0x3f << 26) | (0x1f << 21)))
3466 == (((int) OP_ADDIL << 26) | (27 << 21)))
3468 insn &= ~ (0x1f << 21);
3470 /* Now try to make things easy for the dynamic linker. */
3476 case R_PARISC_DLTIND21L:
3477 case R_PARISC_DLTIND14R:
3478 case R_PARISC_DLTIND14F:
3479 case R_PARISC_TLS_GD21L:
3480 case R_PARISC_TLS_LDM21L:
3481 case R_PARISC_TLS_IE21L:
3482 case R_PARISC_TLS_GD14R:
3483 case R_PARISC_TLS_LDM14R:
3484 case R_PARISC_TLS_IE14R:
3485 value -= elf_gp (input_section->output_section->owner);
3488 case R_PARISC_SEGREL32:
3489 if ((sym_sec->flags & SEC_CODE) != 0)
3490 value -= htab->text_segment_base;
3492 value -= htab->data_segment_base;
3501 case R_PARISC_DIR32:
3502 case R_PARISC_DIR14F:
3503 case R_PARISC_DIR17F:
3504 case R_PARISC_PCREL17C:
3505 case R_PARISC_PCREL14F:
3506 case R_PARISC_PCREL32:
3507 case R_PARISC_DPREL14F:
3508 case R_PARISC_PLABEL32:
3509 case R_PARISC_DLTIND14F:
3510 case R_PARISC_SEGBASE:
3511 case R_PARISC_SEGREL32:
3512 case R_PARISC_TLS_DTPMOD32:
3513 case R_PARISC_TLS_DTPOFF32:
3514 case R_PARISC_TLS_TPREL32:
3518 case R_PARISC_DLTIND21L:
3519 case R_PARISC_PCREL21L:
3520 case R_PARISC_PLABEL21L:
3524 case R_PARISC_DIR21L:
3525 case R_PARISC_DPREL21L:
3526 case R_PARISC_TLS_GD21L:
3527 case R_PARISC_TLS_LDM21L:
3528 case R_PARISC_TLS_LDO21L:
3529 case R_PARISC_TLS_IE21L:
3530 case R_PARISC_TLS_LE21L:
3534 case R_PARISC_PCREL17R:
3535 case R_PARISC_PCREL14R:
3536 case R_PARISC_PLABEL14R:
3537 case R_PARISC_DLTIND14R:
3541 case R_PARISC_DIR17R:
3542 case R_PARISC_DIR14R:
3543 case R_PARISC_DPREL14R:
3544 case R_PARISC_TLS_GD14R:
3545 case R_PARISC_TLS_LDM14R:
3546 case R_PARISC_TLS_LDO14R:
3547 case R_PARISC_TLS_IE14R:
3548 case R_PARISC_TLS_LE14R:
3552 case R_PARISC_PCREL12F:
3553 case R_PARISC_PCREL17F:
3554 case R_PARISC_PCREL22F:
3557 if (r_type == (unsigned int) R_PARISC_PCREL17F)
3559 max_branch_offset = (1 << (17-1)) << 2;
3561 else if (r_type == (unsigned int) R_PARISC_PCREL12F)
3563 max_branch_offset = (1 << (12-1)) << 2;
3567 max_branch_offset = (1 << (22-1)) << 2;
3570 /* sym_sec is NULL on undefined weak syms or when shared on
3571 undefined syms. We've already checked for a stub for the
3572 shared undefined case. */
3573 if (sym_sec == NULL)
3576 /* If the branch is out of reach, then redirect the
3577 call to the local stub for this function. */
3578 if (value + addend + max_branch_offset >= 2*max_branch_offset)
3580 hsh = hppa_get_stub_entry (input_section, sym_sec,
3583 return bfd_reloc_undefined;
3585 /* Munge up the value and addend so that we call the stub
3586 rather than the procedure directly. */
3587 value = (hsh->stub_offset
3588 + hsh->stub_sec->output_offset
3589 + hsh->stub_sec->output_section->vma
3595 /* Something we don't know how to handle. */
3597 return bfd_reloc_notsupported;
3600 /* Make sure we can reach the stub. */
3601 if (max_branch_offset != 0
3602 && value + addend + max_branch_offset >= 2*max_branch_offset)
3605 /* xgettext:c-format */
3606 (_("%B(%A+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
3610 hsh->bh_root.string);
3611 bfd_set_error (bfd_error_bad_value);
3612 return bfd_reloc_notsupported;
3615 val = hppa_field_adjust (value, addend, r_field);
3619 case R_PARISC_PCREL12F:
3620 case R_PARISC_PCREL17C:
3621 case R_PARISC_PCREL17F:
3622 case R_PARISC_PCREL17R:
3623 case R_PARISC_PCREL22F:
3624 case R_PARISC_DIR17F:
3625 case R_PARISC_DIR17R:
3626 /* This is a branch. Divide the offset by four.
3627 Note that we need to decide whether it's a branch or
3628 otherwise by inspecting the reloc. Inspecting insn won't
3629 work as insn might be from a .word directive. */
3637 insn = hppa_rebuild_insn (insn, val, r_format);
3639 /* Update the instruction word. */
3640 bfd_put_32 (input_bfd, (bfd_vma) insn, hit_data);
3641 return bfd_reloc_ok;
3644 /* Relocate an HPPA ELF section. */
3647 elf32_hppa_relocate_section (bfd *output_bfd,
3648 struct bfd_link_info *info,
3650 asection *input_section,
3652 Elf_Internal_Rela *relocs,
3653 Elf_Internal_Sym *local_syms,
3654 asection **local_sections)
3656 bfd_vma *local_got_offsets;
3657 struct elf32_hppa_link_hash_table *htab;
3658 Elf_Internal_Shdr *symtab_hdr;
3659 Elf_Internal_Rela *rela;
3660 Elf_Internal_Rela *relend;
3662 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3664 htab = hppa_link_hash_table (info);
3668 local_got_offsets = elf_local_got_offsets (input_bfd);
3671 relend = relocs + input_section->reloc_count;
3672 for (; rela < relend; rela++)
3674 unsigned int r_type;
3675 reloc_howto_type *howto;
3676 unsigned int r_symndx;
3677 struct elf32_hppa_link_hash_entry *hh;
3678 Elf_Internal_Sym *sym;
3681 bfd_reloc_status_type rstatus;
3682 const char *sym_name;
3684 bfd_boolean warned_undef;
3686 r_type = ELF32_R_TYPE (rela->r_info);
3687 if (r_type >= (unsigned int) R_PARISC_UNIMPLEMENTED)
3689 bfd_set_error (bfd_error_bad_value);
3692 if (r_type == (unsigned int) R_PARISC_GNU_VTENTRY
3693 || r_type == (unsigned int) R_PARISC_GNU_VTINHERIT)
3696 r_symndx = ELF32_R_SYM (rela->r_info);
3700 warned_undef = FALSE;
3701 if (r_symndx < symtab_hdr->sh_info)
3703 /* This is a local symbol, h defaults to NULL. */
3704 sym = local_syms + r_symndx;
3705 sym_sec = local_sections[r_symndx];
3706 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sym_sec, rela);
3710 struct elf_link_hash_entry *eh;
3711 bfd_boolean unresolved_reloc, ignored;
3712 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
3714 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rela,
3715 r_symndx, symtab_hdr, sym_hashes,
3716 eh, sym_sec, relocation,
3717 unresolved_reloc, warned_undef,
3720 if (!bfd_link_relocatable (info)
3722 && eh->root.type != bfd_link_hash_defined
3723 && eh->root.type != bfd_link_hash_defweak
3724 && eh->root.type != bfd_link_hash_undefweak)
3726 if (info->unresolved_syms_in_objects == RM_IGNORE
3727 && ELF_ST_VISIBILITY (eh->other) == STV_DEFAULT
3728 && eh->type == STT_PARISC_MILLI)
3730 (*info->callbacks->undefined_symbol)
3731 (info, eh_name (eh), input_bfd,
3732 input_section, rela->r_offset, FALSE);
3733 warned_undef = TRUE;
3736 hh = hppa_elf_hash_entry (eh);
3739 if (sym_sec != NULL && discarded_section (sym_sec))
3740 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
3742 elf_hppa_howto_table + r_type, 0,
3745 if (bfd_link_relocatable (info))
3748 /* Do any required modifications to the relocation value, and
3749 determine what types of dynamic info we need to output, if
3754 case R_PARISC_DLTIND14F:
3755 case R_PARISC_DLTIND14R:
3756 case R_PARISC_DLTIND21L:
3759 bfd_boolean do_got = 0;
3761 /* Relocation is to the entry for this symbol in the
3762 global offset table. */
3767 off = hh->eh.got.offset;
3768 dyn = htab->etab.dynamic_sections_created;
3769 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
3770 bfd_link_pic (info),
3773 /* If we aren't going to call finish_dynamic_symbol,
3774 then we need to handle initialisation of the .got
3775 entry and create needed relocs here. Since the
3776 offset must always be a multiple of 4, we use the
3777 least significant bit to record whether we have
3778 initialised it already. */
3783 hh->eh.got.offset |= 1;
3790 /* Local symbol case. */
3791 if (local_got_offsets == NULL)
3794 off = local_got_offsets[r_symndx];
3796 /* The offset must always be a multiple of 4. We use
3797 the least significant bit to record whether we have
3798 already generated the necessary reloc. */
3803 local_got_offsets[r_symndx] |= 1;
3810 if (bfd_link_pic (info))
3812 /* Output a dynamic relocation for this GOT entry.
3813 In this case it is relative to the base of the
3814 object because the symbol index is zero. */
3815 Elf_Internal_Rela outrel;
3817 asection *sec = htab->etab.srelgot;
3819 outrel.r_offset = (off
3820 + htab->etab.sgot->output_offset
3821 + htab->etab.sgot->output_section->vma);
3822 outrel.r_info = ELF32_R_INFO (0, R_PARISC_DIR32);
3823 outrel.r_addend = relocation;
3824 loc = sec->contents;
3825 loc += sec->reloc_count++ * sizeof (Elf32_External_Rela);
3826 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
3829 bfd_put_32 (output_bfd, relocation,
3830 htab->etab.sgot->contents + off);
3833 if (off >= (bfd_vma) -2)
3836 /* Add the base of the GOT to the relocation value. */
3838 + htab->etab.sgot->output_offset
3839 + htab->etab.sgot->output_section->vma);
3843 case R_PARISC_SEGREL32:
3844 /* If this is the first SEGREL relocation, then initialize
3845 the segment base values. */
3846 if (htab->text_segment_base == (bfd_vma) -1)
3847 bfd_map_over_sections (output_bfd, hppa_record_segment_addr, htab);
3850 case R_PARISC_PLABEL14R:
3851 case R_PARISC_PLABEL21L:
3852 case R_PARISC_PLABEL32:
3853 if (htab->etab.dynamic_sections_created)
3856 bfd_boolean do_plt = 0;
3857 /* If we have a global symbol with a PLT slot, then
3858 redirect this relocation to it. */
3861 off = hh->eh.plt.offset;
3862 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (1,
3863 bfd_link_pic (info),
3866 /* In a non-shared link, adjust_dynamic_symbols
3867 isn't called for symbols forced local. We
3868 need to write out the plt entry here. */
3873 hh->eh.plt.offset |= 1;
3880 bfd_vma *local_plt_offsets;
3882 if (local_got_offsets == NULL)
3885 local_plt_offsets = local_got_offsets + symtab_hdr->sh_info;
3886 off = local_plt_offsets[r_symndx];
3888 /* As for the local .got entry case, we use the last
3889 bit to record whether we've already initialised
3890 this local .plt entry. */
3895 local_plt_offsets[r_symndx] |= 1;
3902 if (bfd_link_pic (info))
3904 /* Output a dynamic IPLT relocation for this
3906 Elf_Internal_Rela outrel;
3908 asection *s = htab->etab.srelplt;
3910 outrel.r_offset = (off
3911 + htab->etab.splt->output_offset
3912 + htab->etab.splt->output_section->vma);
3913 outrel.r_info = ELF32_R_INFO (0, R_PARISC_IPLT);
3914 outrel.r_addend = relocation;
3916 loc += s->reloc_count++ * sizeof (Elf32_External_Rela);
3917 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
3921 bfd_put_32 (output_bfd,
3923 htab->etab.splt->contents + off);
3924 bfd_put_32 (output_bfd,
3925 elf_gp (htab->etab.splt->output_section->owner),
3926 htab->etab.splt->contents + off + 4);
3930 if (off >= (bfd_vma) -2)
3933 /* PLABELs contain function pointers. Relocation is to
3934 the entry for the function in the .plt. The magic +2
3935 offset signals to $$dyncall that the function pointer
3936 is in the .plt and thus has a gp pointer too.
3937 Exception: Undefined PLABELs should have a value of
3940 || (hh->eh.root.type != bfd_link_hash_undefweak
3941 && hh->eh.root.type != bfd_link_hash_undefined))
3944 + htab->etab.splt->output_offset
3945 + htab->etab.splt->output_section->vma
3952 case R_PARISC_DIR17F:
3953 case R_PARISC_DIR17R:
3954 case R_PARISC_DIR14F:
3955 case R_PARISC_DIR14R:
3956 case R_PARISC_DIR21L:
3957 case R_PARISC_DPREL14F:
3958 case R_PARISC_DPREL14R:
3959 case R_PARISC_DPREL21L:
3960 case R_PARISC_DIR32:
3961 if ((input_section->flags & SEC_ALLOC) == 0)
3964 /* The reloc types handled here and this conditional
3965 expression must match the code in ..check_relocs and
3966 allocate_dynrelocs. ie. We need exactly the same condition
3967 as in ..check_relocs, with some extra conditions (dynindx
3968 test in this case) to cater for relocs removed by
3969 allocate_dynrelocs. If you squint, the non-shared test
3970 here does indeed match the one in ..check_relocs, the
3971 difference being that here we test DEF_DYNAMIC as well as
3972 !DEF_REGULAR. All common syms end up with !DEF_REGULAR,
3973 which is why we can't use just that test here.
3974 Conversely, DEF_DYNAMIC can't be used in check_relocs as
3975 there all files have not been loaded. */
3976 if ((bfd_link_pic (info)
3978 || ELF_ST_VISIBILITY (hh->eh.other) == STV_DEFAULT
3979 || hh->eh.root.type != bfd_link_hash_undefweak)
3980 && (IS_ABSOLUTE_RELOC (r_type)
3981 || !SYMBOL_CALLS_LOCAL (info, &hh->eh)))
3982 || (!bfd_link_pic (info)
3984 && hh->eh.dynindx != -1
3985 && !hh->eh.non_got_ref
3986 && ((ELIMINATE_COPY_RELOCS
3987 && hh->eh.def_dynamic
3988 && !hh->eh.def_regular)
3989 || hh->eh.root.type == bfd_link_hash_undefweak
3990 || hh->eh.root.type == bfd_link_hash_undefined)))
3992 Elf_Internal_Rela outrel;
3997 /* When generating a shared object, these relocations
3998 are copied into the output file to be resolved at run
4001 outrel.r_addend = rela->r_addend;
4003 _bfd_elf_section_offset (output_bfd, info, input_section,
4005 skip = (outrel.r_offset == (bfd_vma) -1
4006 || outrel.r_offset == (bfd_vma) -2);
4007 outrel.r_offset += (input_section->output_offset
4008 + input_section->output_section->vma);
4012 memset (&outrel, 0, sizeof (outrel));
4015 && hh->eh.dynindx != -1
4017 || !IS_ABSOLUTE_RELOC (r_type)
4018 || !bfd_link_pic (info)
4019 || !SYMBOLIC_BIND (info, &hh->eh)
4020 || !hh->eh.def_regular))
4022 outrel.r_info = ELF32_R_INFO (hh->eh.dynindx, r_type);
4024 else /* It's a local symbol, or one marked to become local. */
4028 /* Add the absolute offset of the symbol. */
4029 outrel.r_addend += relocation;
4031 /* Global plabels need to be processed by the
4032 dynamic linker so that functions have at most one
4033 fptr. For this reason, we need to differentiate
4034 between global and local plabels, which we do by
4035 providing the function symbol for a global plabel
4036 reloc, and no symbol for local plabels. */
4039 && sym_sec->output_section != NULL
4040 && ! bfd_is_abs_section (sym_sec))
4044 osec = sym_sec->output_section;
4045 indx = elf_section_data (osec)->dynindx;
4048 osec = htab->etab.text_index_section;
4049 indx = elf_section_data (osec)->dynindx;
4051 BFD_ASSERT (indx != 0);
4053 /* We are turning this relocation into one
4054 against a section symbol, so subtract out the
4055 output section's address but not the offset
4056 of the input section in the output section. */
4057 outrel.r_addend -= osec->vma;
4060 outrel.r_info = ELF32_R_INFO (indx, r_type);
4062 sreloc = elf_section_data (input_section)->sreloc;
4066 loc = sreloc->contents;
4067 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
4068 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
4072 case R_PARISC_TLS_LDM21L:
4073 case R_PARISC_TLS_LDM14R:
4077 off = htab->tls_ldm_got.offset;
4082 Elf_Internal_Rela outrel;
4085 outrel.r_offset = (off
4086 + htab->etab.sgot->output_section->vma
4087 + htab->etab.sgot->output_offset);
4088 outrel.r_addend = 0;
4089 outrel.r_info = ELF32_R_INFO (0, R_PARISC_TLS_DTPMOD32);
4090 loc = htab->etab.srelgot->contents;
4091 loc += htab->etab.srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
4093 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
4094 htab->tls_ldm_got.offset |= 1;
4097 /* Add the base of the GOT to the relocation value. */
4099 + htab->etab.sgot->output_offset
4100 + htab->etab.sgot->output_section->vma);
4105 case R_PARISC_TLS_LDO21L:
4106 case R_PARISC_TLS_LDO14R:
4107 relocation -= dtpoff_base (info);
4110 case R_PARISC_TLS_GD21L:
4111 case R_PARISC_TLS_GD14R:
4112 case R_PARISC_TLS_IE21L:
4113 case R_PARISC_TLS_IE14R:
4123 dyn = htab->etab.dynamic_sections_created;
4125 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
4126 bfd_link_pic (info),
4128 && (!bfd_link_pic (info)
4129 || !SYMBOL_REFERENCES_LOCAL (info, &hh->eh)))
4131 indx = hh->eh.dynindx;
4133 off = hh->eh.got.offset;
4134 tls_type = hh->tls_type;
4138 off = local_got_offsets[r_symndx];
4139 tls_type = hppa_elf_local_got_tls_type (input_bfd)[r_symndx];
4142 if (tls_type == GOT_UNKNOWN)
4149 bfd_boolean need_relocs = FALSE;
4150 Elf_Internal_Rela outrel;
4151 bfd_byte *loc = NULL;
4154 /* The GOT entries have not been initialized yet. Do it
4155 now, and emit any relocations. If both an IE GOT and a
4156 GD GOT are necessary, we emit the GD first. */
4158 if ((bfd_link_pic (info) || indx != 0)
4160 || ELF_ST_VISIBILITY (hh->eh.other) == STV_DEFAULT
4161 || hh->eh.root.type != bfd_link_hash_undefweak))
4164 loc = htab->etab.srelgot->contents;
4165 /* FIXME (CAO): Should this be reloc_count++ ? */
4166 loc += htab->etab.srelgot->reloc_count * sizeof (Elf32_External_Rela);
4169 if (tls_type & GOT_TLS_GD)
4173 outrel.r_offset = (cur_off
4174 + htab->etab.sgot->output_section->vma
4175 + htab->etab.sgot->output_offset);
4176 outrel.r_info = ELF32_R_INFO (indx,R_PARISC_TLS_DTPMOD32);
4177 outrel.r_addend = 0;
4178 bfd_put_32 (output_bfd, 0, htab->etab.sgot->contents + cur_off);
4179 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
4180 htab->etab.srelgot->reloc_count++;
4181 loc += sizeof (Elf32_External_Rela);
4184 bfd_put_32 (output_bfd, relocation - dtpoff_base (info),
4185 htab->etab.sgot->contents + cur_off + 4);
4188 bfd_put_32 (output_bfd, 0,
4189 htab->etab.sgot->contents + cur_off + 4);
4190 outrel.r_info = ELF32_R_INFO (indx, R_PARISC_TLS_DTPOFF32);
4191 outrel.r_offset += 4;
4192 bfd_elf32_swap_reloca_out (output_bfd, &outrel,loc);
4193 htab->etab.srelgot->reloc_count++;
4194 loc += sizeof (Elf32_External_Rela);
4199 /* If we are not emitting relocations for a
4200 general dynamic reference, then we must be in a
4201 static link or an executable link with the
4202 symbol binding locally. Mark it as belonging
4203 to module 1, the executable. */
4204 bfd_put_32 (output_bfd, 1,
4205 htab->etab.sgot->contents + cur_off);
4206 bfd_put_32 (output_bfd, relocation - dtpoff_base (info),
4207 htab->etab.sgot->contents + cur_off + 4);
4214 if (tls_type & GOT_TLS_IE)
4218 outrel.r_offset = (cur_off
4219 + htab->etab.sgot->output_section->vma
4220 + htab->etab.sgot->output_offset);
4221 outrel.r_info = ELF32_R_INFO (indx, R_PARISC_TLS_TPREL32);
4224 outrel.r_addend = relocation - dtpoff_base (info);
4226 outrel.r_addend = 0;
4228 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
4229 htab->etab.srelgot->reloc_count++;
4230 loc += sizeof (Elf32_External_Rela);
4233 bfd_put_32 (output_bfd, tpoff (info, relocation),
4234 htab->etab.sgot->contents + cur_off);
4240 hh->eh.got.offset |= 1;
4242 local_got_offsets[r_symndx] |= 1;
4245 if ((tls_type & GOT_TLS_GD)
4246 && r_type != R_PARISC_TLS_GD21L
4247 && r_type != R_PARISC_TLS_GD14R)
4248 off += 2 * GOT_ENTRY_SIZE;
4250 /* Add the base of the GOT to the relocation value. */
4252 + htab->etab.sgot->output_offset
4253 + htab->etab.sgot->output_section->vma);
4258 case R_PARISC_TLS_LE21L:
4259 case R_PARISC_TLS_LE14R:
4261 relocation = tpoff (info, relocation);
4270 rstatus = final_link_relocate (input_section, contents, rela, relocation,
4271 htab, sym_sec, hh, info);
4273 if (rstatus == bfd_reloc_ok)
4277 sym_name = hh_name (hh);
4280 sym_name = bfd_elf_string_from_elf_section (input_bfd,
4281 symtab_hdr->sh_link,
4283 if (sym_name == NULL)
4285 if (*sym_name == '\0')
4286 sym_name = bfd_section_name (input_bfd, sym_sec);
4289 howto = elf_hppa_howto_table + r_type;
4291 if (rstatus == bfd_reloc_undefined || rstatus == bfd_reloc_notsupported)
4293 if (rstatus == bfd_reloc_notsupported || !warned_undef)
4296 /* xgettext:c-format */
4297 (_("%B(%A+0x%lx): cannot handle %s for %s"),
4300 (long) rela->r_offset,
4303 bfd_set_error (bfd_error_bad_value);
4308 (*info->callbacks->reloc_overflow)
4309 (info, (hh ? &hh->eh.root : NULL), sym_name, howto->name,
4310 (bfd_vma) 0, input_bfd, input_section, rela->r_offset);
4316 /* Finish up dynamic symbol handling. We set the contents of various
4317 dynamic sections here. */
4320 elf32_hppa_finish_dynamic_symbol (bfd *output_bfd,
4321 struct bfd_link_info *info,
4322 struct elf_link_hash_entry *eh,
4323 Elf_Internal_Sym *sym)
4325 struct elf32_hppa_link_hash_table *htab;
4326 Elf_Internal_Rela rela;
4329 htab = hppa_link_hash_table (info);
4333 if (eh->plt.offset != (bfd_vma) -1)
4337 if (eh->plt.offset & 1)
4340 /* This symbol has an entry in the procedure linkage table. Set
4343 The format of a plt entry is
4348 if (eh->root.type == bfd_link_hash_defined
4349 || eh->root.type == bfd_link_hash_defweak)
4351 value = eh->root.u.def.value;
4352 if (eh->root.u.def.section->output_section != NULL)
4353 value += (eh->root.u.def.section->output_offset
4354 + eh->root.u.def.section->output_section->vma);
4357 /* Create a dynamic IPLT relocation for this entry. */
4358 rela.r_offset = (eh->plt.offset
4359 + htab->etab.splt->output_offset
4360 + htab->etab.splt->output_section->vma);
4361 if (eh->dynindx != -1)
4363 rela.r_info = ELF32_R_INFO (eh->dynindx, R_PARISC_IPLT);
4368 /* This symbol has been marked to become local, and is
4369 used by a plabel so must be kept in the .plt. */
4370 rela.r_info = ELF32_R_INFO (0, R_PARISC_IPLT);
4371 rela.r_addend = value;
4374 loc = htab->etab.srelplt->contents;
4375 loc += htab->etab.srelplt->reloc_count++ * sizeof (Elf32_External_Rela);
4376 bfd_elf32_swap_reloca_out (htab->etab.splt->output_section->owner, &rela, loc);
4378 if (!eh->def_regular)
4380 /* Mark the symbol as undefined, rather than as defined in
4381 the .plt section. Leave the value alone. */
4382 sym->st_shndx = SHN_UNDEF;
4386 if (eh->got.offset != (bfd_vma) -1
4387 && (hppa_elf_hash_entry (eh)->tls_type & GOT_TLS_GD) == 0
4388 && (hppa_elf_hash_entry (eh)->tls_type & GOT_TLS_IE) == 0)
4390 /* This symbol has an entry in the global offset table. Set it
4393 rela.r_offset = ((eh->got.offset &~ (bfd_vma) 1)
4394 + htab->etab.sgot->output_offset
4395 + htab->etab.sgot->output_section->vma);
4397 /* If this is a -Bsymbolic link and the symbol is defined
4398 locally or was forced to be local because of a version file,
4399 we just want to emit a RELATIVE reloc. The entry in the
4400 global offset table will already have been initialized in the
4401 relocate_section function. */
4402 if (bfd_link_pic (info)
4403 && (SYMBOLIC_BIND (info, eh) || eh->dynindx == -1)
4406 rela.r_info = ELF32_R_INFO (0, R_PARISC_DIR32);
4407 rela.r_addend = (eh->root.u.def.value
4408 + eh->root.u.def.section->output_offset
4409 + eh->root.u.def.section->output_section->vma);
4413 if ((eh->got.offset & 1) != 0)
4416 bfd_put_32 (output_bfd, 0, htab->etab.sgot->contents + (eh->got.offset & ~1));
4417 rela.r_info = ELF32_R_INFO (eh->dynindx, R_PARISC_DIR32);
4421 loc = htab->etab.srelgot->contents;
4422 loc += htab->etab.srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
4423 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4430 /* This symbol needs a copy reloc. Set it up. */
4432 if (! (eh->dynindx != -1
4433 && (eh->root.type == bfd_link_hash_defined
4434 || eh->root.type == bfd_link_hash_defweak)))
4437 sec = htab->srelbss;
4439 rela.r_offset = (eh->root.u.def.value
4440 + eh->root.u.def.section->output_offset
4441 + eh->root.u.def.section->output_section->vma);
4443 rela.r_info = ELF32_R_INFO (eh->dynindx, R_PARISC_COPY);
4444 loc = sec->contents + sec->reloc_count++ * sizeof (Elf32_External_Rela);
4445 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4448 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
4449 if (eh == htab->etab.hdynamic || eh == htab->etab.hgot)
4451 sym->st_shndx = SHN_ABS;
4457 /* Used to decide how to sort relocs in an optimal manner for the
4458 dynamic linker, before writing them out. */
4460 static enum elf_reloc_type_class
4461 elf32_hppa_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
4462 const asection *rel_sec ATTRIBUTE_UNUSED,
4463 const Elf_Internal_Rela *rela)
4465 /* Handle TLS relocs first; we don't want them to be marked
4466 relative by the "if (ELF32_R_SYM (rela->r_info) == STN_UNDEF)"
4468 switch ((int) ELF32_R_TYPE (rela->r_info))
4470 case R_PARISC_TLS_DTPMOD32:
4471 case R_PARISC_TLS_DTPOFF32:
4472 case R_PARISC_TLS_TPREL32:
4473 return reloc_class_normal;
4476 if (ELF32_R_SYM (rela->r_info) == STN_UNDEF)
4477 return reloc_class_relative;
4479 switch ((int) ELF32_R_TYPE (rela->r_info))
4482 return reloc_class_plt;
4484 return reloc_class_copy;
4486 return reloc_class_normal;
4490 /* Finish up the dynamic sections. */
4493 elf32_hppa_finish_dynamic_sections (bfd *output_bfd,
4494 struct bfd_link_info *info)
4497 struct elf32_hppa_link_hash_table *htab;
4501 htab = hppa_link_hash_table (info);
4505 dynobj = htab->etab.dynobj;
4507 sgot = htab->etab.sgot;
4508 /* A broken linker script might have discarded the dynamic sections.
4509 Catch this here so that we do not seg-fault later on. */
4510 if (sgot != NULL && bfd_is_abs_section (sgot->output_section))
4513 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
4515 if (htab->etab.dynamic_sections_created)
4517 Elf32_External_Dyn *dyncon, *dynconend;
4522 dyncon = (Elf32_External_Dyn *) sdyn->contents;
4523 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
4524 for (; dyncon < dynconend; dyncon++)
4526 Elf_Internal_Dyn dyn;
4529 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
4537 /* Use PLTGOT to set the GOT register. */
4538 dyn.d_un.d_ptr = elf_gp (output_bfd);
4542 s = htab->etab.srelplt;
4543 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
4547 s = htab->etab.srelplt;
4548 dyn.d_un.d_val = s->size;
4552 /* Don't count procedure linkage table relocs in the
4553 overall reloc count. */
4554 s = htab->etab.srelplt;
4557 dyn.d_un.d_val -= s->size;
4561 /* We may not be using the standard ELF linker script.
4562 If .rela.plt is the first .rela section, we adjust
4563 DT_RELA to not include it. */
4564 s = htab->etab.srelplt;
4567 if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset)
4569 dyn.d_un.d_ptr += s->size;
4573 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4577 if (sgot != NULL && sgot->size != 0)
4579 /* Fill in the first entry in the global offset table.
4580 We use it to point to our dynamic section, if we have one. */
4581 bfd_put_32 (output_bfd,
4582 sdyn ? sdyn->output_section->vma + sdyn->output_offset : 0,
4585 /* The second entry is reserved for use by the dynamic linker. */
4586 memset (sgot->contents + GOT_ENTRY_SIZE, 0, GOT_ENTRY_SIZE);
4588 /* Set .got entry size. */
4589 elf_section_data (sgot->output_section)
4590 ->this_hdr.sh_entsize = GOT_ENTRY_SIZE;
4593 if (htab->etab.splt != NULL && htab->etab.splt->size != 0)
4595 /* Set plt entry size to 0 instead of PLT_ENTRY_SIZE, since we add the
4596 plt stubs and as such the section does not hold a table of fixed-size
4598 elf_section_data (htab->etab.splt->output_section)->this_hdr.sh_entsize = 0;
4600 if (htab->need_plt_stub)
4602 /* Set up the .plt stub. */
4603 memcpy (htab->etab.splt->contents
4604 + htab->etab.splt->size - sizeof (plt_stub),
4605 plt_stub, sizeof (plt_stub));
4607 if ((htab->etab.splt->output_offset
4608 + htab->etab.splt->output_section->vma
4609 + htab->etab.splt->size)
4610 != (sgot->output_offset
4611 + sgot->output_section->vma))
4614 (_(".got section not immediately after .plt section"));
4623 /* Called when writing out an object file to decide the type of a
4626 elf32_hppa_elf_get_symbol_type (Elf_Internal_Sym *elf_sym, int type)
4628 if (ELF_ST_TYPE (elf_sym->st_info) == STT_PARISC_MILLI)
4629 return STT_PARISC_MILLI;
4634 /* Misc BFD support code. */
4635 #define bfd_elf32_bfd_is_local_label_name elf_hppa_is_local_label_name
4636 #define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
4637 #define bfd_elf32_bfd_reloc_name_lookup elf_hppa_reloc_name_lookup
4638 #define elf_info_to_howto elf_hppa_info_to_howto
4639 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
4641 /* Stuff for the BFD linker. */
4642 #define bfd_elf32_bfd_final_link elf32_hppa_final_link
4643 #define bfd_elf32_bfd_link_hash_table_create elf32_hppa_link_hash_table_create
4644 #define elf_backend_adjust_dynamic_symbol elf32_hppa_adjust_dynamic_symbol
4645 #define elf_backend_copy_indirect_symbol elf32_hppa_copy_indirect_symbol
4646 #define elf_backend_check_relocs elf32_hppa_check_relocs
4647 #define elf_backend_create_dynamic_sections elf32_hppa_create_dynamic_sections
4648 #define elf_backend_fake_sections elf_hppa_fake_sections
4649 #define elf_backend_relocate_section elf32_hppa_relocate_section
4650 #define elf_backend_hide_symbol elf32_hppa_hide_symbol
4651 #define elf_backend_finish_dynamic_symbol elf32_hppa_finish_dynamic_symbol
4652 #define elf_backend_finish_dynamic_sections elf32_hppa_finish_dynamic_sections
4653 #define elf_backend_size_dynamic_sections elf32_hppa_size_dynamic_sections
4654 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
4655 #define elf_backend_gc_mark_hook elf32_hppa_gc_mark_hook
4656 #define elf_backend_gc_sweep_hook elf32_hppa_gc_sweep_hook
4657 #define elf_backend_grok_prstatus elf32_hppa_grok_prstatus
4658 #define elf_backend_grok_psinfo elf32_hppa_grok_psinfo
4659 #define elf_backend_object_p elf32_hppa_object_p
4660 #define elf_backend_final_write_processing elf_hppa_final_write_processing
4661 #define elf_backend_get_symbol_type elf32_hppa_elf_get_symbol_type
4662 #define elf_backend_reloc_type_class elf32_hppa_reloc_type_class
4663 #define elf_backend_action_discarded elf_hppa_action_discarded
4665 #define elf_backend_can_gc_sections 1
4666 #define elf_backend_can_refcount 1
4667 #define elf_backend_plt_alignment 2
4668 #define elf_backend_want_got_plt 0
4669 #define elf_backend_plt_readonly 0
4670 #define elf_backend_want_plt_sym 0
4671 #define elf_backend_got_header_size 8
4672 #define elf_backend_rela_normal 1
4674 #define TARGET_BIG_SYM hppa_elf32_vec
4675 #define TARGET_BIG_NAME "elf32-hppa"
4676 #define ELF_ARCH bfd_arch_hppa
4677 #define ELF_TARGET_ID HPPA32_ELF_DATA
4678 #define ELF_MACHINE_CODE EM_PARISC
4679 #define ELF_MAXPAGESIZE 0x1000
4680 #define ELF_OSABI ELFOSABI_HPUX
4681 #define elf32_bed elf32_hppa_hpux_bed
4683 #include "elf32-target.h"
4685 #undef TARGET_BIG_SYM
4686 #define TARGET_BIG_SYM hppa_elf32_linux_vec
4687 #undef TARGET_BIG_NAME
4688 #define TARGET_BIG_NAME "elf32-hppa-linux"
4690 #define ELF_OSABI ELFOSABI_GNU
4692 #define elf32_bed elf32_hppa_linux_bed
4694 #include "elf32-target.h"
4696 #undef TARGET_BIG_SYM
4697 #define TARGET_BIG_SYM hppa_elf32_nbsd_vec
4698 #undef TARGET_BIG_NAME
4699 #define TARGET_BIG_NAME "elf32-hppa-netbsd"
4701 #define ELF_OSABI ELFOSABI_NETBSD
4703 #define elf32_bed elf32_hppa_netbsd_bed
4705 #include "elf32-target.h"