1 /* BFD back-end for HP PA-RISC ELF files.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2001,
3 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
6 Center for Software Science
7 Department of Computer Science
9 Largely rewritten by Alan Modra <alan@linuxcare.com.au>
11 This file is part of BFD, the Binary File Descriptor library.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
33 #include "elf32-hppa.h"
35 #include "elf32-hppa.h"
38 /* In order to gain some understanding of code in this file without
39 knowing all the intricate details of the linker, note the
42 Functions named elf32_hppa_* are called by external routines, other
43 functions are only called locally. elf32_hppa_* functions appear
44 in this file more or less in the order in which they are called
45 from external routines. eg. elf32_hppa_check_relocs is called
46 early in the link process, elf32_hppa_finish_dynamic_sections is
47 one of the last functions. */
49 /* We use two hash tables to hold information for linking PA ELF objects.
51 The first is the elf32_hppa_link_hash_table which is derived
52 from the standard ELF linker hash table. We use this as a place to
53 attach other hash tables and static information.
55 The second is the stub hash table which is derived from the
56 base BFD hash table. The stub hash table holds the information
57 necessary to build the linker stubs during a link.
59 There are a number of different stubs generated by the linker.
67 : addil LR'X - ($PIC_pcrel$0 - 4),%r1
68 : be,n RR'X - ($PIC_pcrel$0 - 8)(%sr4,%r1)
70 Import stub to call shared library routine from normal object file
71 (single sub-space version)
72 : addil LR'lt_ptr+ltoff,%dp ; get procedure entry point
73 : ldw RR'lt_ptr+ltoff(%r1),%r21
75 : ldw RR'lt_ptr+ltoff+4(%r1),%r19 ; get new dlt value.
77 Import stub to call shared library routine from shared library
78 (single sub-space version)
79 : addil LR'ltoff,%r19 ; get procedure entry point
80 : ldw RR'ltoff(%r1),%r21
82 : ldw RR'ltoff+4(%r1),%r19 ; get new dlt value.
84 Import stub to call shared library routine from normal object file
85 (multiple sub-space support)
86 : addil LR'lt_ptr+ltoff,%dp ; get procedure entry point
87 : ldw RR'lt_ptr+ltoff(%r1),%r21
88 : ldw RR'lt_ptr+ltoff+4(%r1),%r19 ; get new dlt value.
91 : be 0(%sr0,%r21) ; branch to target
92 : stw %rp,-24(%sp) ; save rp
94 Import stub to call shared library routine from shared library
95 (multiple sub-space support)
96 : addil LR'ltoff,%r19 ; get procedure entry point
97 : ldw RR'ltoff(%r1),%r21
98 : ldw RR'ltoff+4(%r1),%r19 ; get new dlt value.
101 : be 0(%sr0,%r21) ; branch to target
102 : stw %rp,-24(%sp) ; save rp
104 Export stub to return from shared lib routine (multiple sub-space support)
105 One of these is created for each exported procedure in a shared
106 library (and stored in the shared lib). Shared lib routines are
107 called via the first instruction in the export stub so that we can
108 do an inter-space return. Not required for single sub-space.
109 : bl,n X,%rp ; trap the return
111 : ldw -24(%sp),%rp ; restore the original rp
114 : be,n 0(%sr0,%rp) ; inter-space return. */
117 /* Variable names follow a coding style.
118 Please follow this (Apps Hungarian) style:
120 Structure/Variable Prefix
121 elf_link_hash_table "etab"
122 elf_link_hash_entry "eh"
124 elf32_hppa_link_hash_table "htab"
125 elf32_hppa_link_hash_entry "hh"
127 bfd_hash_table "btab"
130 bfd_hash_table containing stubs "bstab"
131 elf32_hppa_stub_hash_entry "hsh"
133 elf32_hppa_dyn_reloc_entry "hdh"
135 Always remember to use GNU Coding Style. */
137 #define PLT_ENTRY_SIZE 8
138 #define GOT_ENTRY_SIZE 4
139 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
141 static const bfd_byte plt_stub
[] =
143 0x0e, 0x80, 0x10, 0x96, /* 1: ldw 0(%r20),%r22 */
144 0xea, 0xc0, 0xc0, 0x00, /* bv %r0(%r22) */
145 0x0e, 0x88, 0x10, 0x95, /* ldw 4(%r20),%r21 */
146 #define PLT_STUB_ENTRY (3*4)
147 0xea, 0x9f, 0x1f, 0xdd, /* b,l 1b,%r20 */
148 0xd6, 0x80, 0x1c, 0x1e, /* depi 0,31,2,%r20 */
149 0x00, 0xc0, 0xff, 0xee, /* 9: .word fixup_func */
150 0xde, 0xad, 0xbe, 0xef /* .word fixup_ltp */
153 /* Section name for stubs is the associated section name plus this
155 #define STUB_SUFFIX ".stub"
157 /* We don't need to copy certain PC- or GP-relative dynamic relocs
158 into a shared object's dynamic section. All the relocs of the
159 limited class we are interested in, are absolute. */
160 #ifndef RELATIVE_DYNRELOCS
161 #define RELATIVE_DYNRELOCS 0
162 #define IS_ABSOLUTE_RELOC(r_type) 1
165 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
166 copying dynamic variables from a shared lib into an app's dynbss
167 section, and instead use a dynamic relocation to point into the
169 #define ELIMINATE_COPY_RELOCS 1
171 enum elf32_hppa_stub_type
{
172 hppa_stub_long_branch
,
173 hppa_stub_long_branch_shared
,
175 hppa_stub_import_shared
,
180 struct elf32_hppa_stub_hash_entry
{
182 /* Base hash table entry structure. */
183 struct bfd_hash_entry bh_root
;
185 /* The stub section. */
188 /* Offset within stub_sec of the beginning of this stub. */
191 /* Given the symbol's value and its section we can determine its final
192 value when building the stubs (so the stub knows where to jump. */
193 bfd_vma target_value
;
194 asection
*target_section
;
196 enum elf32_hppa_stub_type stub_type
;
198 /* The symbol table entry, if any, that this was derived from. */
199 struct elf32_hppa_link_hash_entry
*hh
;
201 /* Where this stub is being called from, or, in the case of combined
202 stub sections, the first input section in the group. */
206 struct elf32_hppa_link_hash_entry
{
208 struct elf_link_hash_entry eh
;
210 /* A pointer to the most recently used stub hash entry against this
212 struct elf32_hppa_stub_hash_entry
*hsh_cache
;
214 /* Used to count relocations for delayed sizing of relocation
216 struct elf32_hppa_dyn_reloc_entry
{
218 /* Next relocation in the chain. */
219 struct elf32_hppa_dyn_reloc_entry
*hdh_next
;
221 /* The input section of the reloc. */
224 /* Number of relocs copied in this section. */
227 #if RELATIVE_DYNRELOCS
228 /* Number of relative relocs copied for the input section. */
229 bfd_size_type relative_count
;
233 /* Set if this symbol is used by a plabel reloc. */
234 unsigned int plabel
:1;
237 struct elf32_hppa_link_hash_table
{
239 /* The main hash table. */
240 struct elf_link_hash_table etab
;
242 /* The stub hash table. */
243 struct bfd_hash_table bstab
;
245 /* Linker stub bfd. */
248 /* Linker call-backs. */
249 asection
* (*add_stub_section
) (const char *, asection
*);
250 void (*layout_sections_again
) (void);
252 /* Array to keep track of which stub sections have been created, and
253 information on stub grouping. */
255 /* This is the section to which stubs in the group will be
258 /* The stub section. */
262 /* Assorted information used by elf32_hppa_size_stubs. */
263 unsigned int bfd_count
;
265 asection
**input_list
;
266 Elf_Internal_Sym
**all_local_syms
;
268 /* Short-cuts to get to dynamic linker sections. */
276 /* Used during a final link to store the base of the text and data
277 segments so that we can perform SEGREL relocations. */
278 bfd_vma text_segment_base
;
279 bfd_vma data_segment_base
;
281 /* Whether we support multiple sub-spaces for shared libs. */
282 unsigned int multi_subspace
:1;
284 /* Flags set when various size branches are detected. Used to
285 select suitable defaults for the stub group size. */
286 unsigned int has_12bit_branch
:1;
287 unsigned int has_17bit_branch
:1;
288 unsigned int has_22bit_branch
:1;
290 /* Set if we need a .plt stub to support lazy dynamic linking. */
291 unsigned int need_plt_stub
:1;
293 /* Small local sym to section mapping cache. */
294 struct sym_sec_cache sym_sec
;
297 /* Various hash macros and functions. */
298 #define hppa_link_hash_table(p) \
299 ((struct elf32_hppa_link_hash_table *) ((p)->hash))
301 #define hppa_elf_hash_entry(ent) \
302 ((struct elf32_hppa_link_hash_entry *)(ent))
304 #define hppa_stub_hash_entry(ent) \
305 ((struct elf32_hppa_stub_hash_entry *)(ent))
307 #define hppa_stub_hash_lookup(table, string, create, copy) \
308 ((struct elf32_hppa_stub_hash_entry *) \
309 bfd_hash_lookup ((table), (string), (create), (copy)))
311 /* Assorted hash table functions. */
313 /* Initialize an entry in the stub hash table. */
315 static struct bfd_hash_entry
*
316 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
317 struct bfd_hash_table
*table
,
320 /* Allocate the structure if it has not already been allocated by a
324 entry
= bfd_hash_allocate (table
,
325 sizeof (struct elf32_hppa_stub_hash_entry
));
330 /* Call the allocation method of the superclass. */
331 entry
= bfd_hash_newfunc (entry
, table
, string
);
334 struct elf32_hppa_stub_hash_entry
*hsh
;
336 /* Initialize the local fields. */
337 hsh
= hppa_stub_hash_entry (entry
);
338 hsh
->stub_sec
= NULL
;
339 hsh
->stub_offset
= 0;
340 hsh
->target_value
= 0;
341 hsh
->target_section
= NULL
;
342 hsh
->stub_type
= hppa_stub_long_branch
;
350 /* Initialize an entry in the link hash table. */
352 static struct bfd_hash_entry
*
353 hppa_link_hash_newfunc (struct bfd_hash_entry
*entry
,
354 struct bfd_hash_table
*table
,
357 /* Allocate the structure if it has not already been allocated by a
361 entry
= bfd_hash_allocate (table
,
362 sizeof (struct elf32_hppa_link_hash_entry
));
367 /* Call the allocation method of the superclass. */
368 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
371 struct elf32_hppa_link_hash_entry
*hh
;
373 /* Initialize the local fields. */
374 hh
= hppa_elf_hash_entry (entry
);
375 hh
->hsh_cache
= NULL
;
376 hh
->dyn_relocs
= NULL
;
383 /* Create the derived linker hash table. The PA ELF port uses the derived
384 hash table to keep information specific to the PA ELF linker (without
385 using static variables). */
387 static struct bfd_link_hash_table
*
388 elf32_hppa_link_hash_table_create (bfd
*abfd
)
390 struct elf32_hppa_link_hash_table
*htab
;
391 bfd_size_type amt
= sizeof (*htab
);
393 htab
= (struct elf32_hppa_link_hash_table
*) bfd_malloc (amt
);
397 if (!_bfd_elf_link_hash_table_init (&htab
->etab
, abfd
, hppa_link_hash_newfunc
))
403 /* Init the stub hash table too. */
404 if (!bfd_hash_table_init (&htab
->bstab
, stub_hash_newfunc
))
407 htab
->stub_bfd
= NULL
;
408 htab
->add_stub_section
= NULL
;
409 htab
->layout_sections_again
= NULL
;
410 htab
->stub_group
= NULL
;
412 htab
->srelgot
= NULL
;
414 htab
->srelplt
= NULL
;
415 htab
->sdynbss
= NULL
;
416 htab
->srelbss
= NULL
;
417 htab
->text_segment_base
= (bfd_vma
) -1;
418 htab
->data_segment_base
= (bfd_vma
) -1;
419 htab
->multi_subspace
= 0;
420 htab
->has_12bit_branch
= 0;
421 htab
->has_17bit_branch
= 0;
422 htab
->has_22bit_branch
= 0;
423 htab
->need_plt_stub
= 0;
424 htab
->sym_sec
.abfd
= NULL
;
426 return &htab
->etab
.root
;
429 /* Free the derived linker hash table. */
432 elf32_hppa_link_hash_table_free (struct bfd_link_hash_table
*btab
)
434 struct elf32_hppa_link_hash_table
*htab
435 = (struct elf32_hppa_link_hash_table
*) btab
;
437 bfd_hash_table_free (&htab
->bstab
);
438 _bfd_generic_link_hash_table_free (btab
);
441 /* Build a name for an entry in the stub hash table. */
444 hppa_stub_name (const asection
*input_section
,
445 const asection
*sym_sec
,
446 const struct elf32_hppa_link_hash_entry
*hh
,
447 const Elf_Internal_Rela
*rela
)
454 len
= 8 + 1 + strlen (hh
->eh
.root
.root
.string
) + 1 + 8 + 1;
455 stub_name
= bfd_malloc (len
);
456 if (stub_name
!= NULL
)
458 sprintf (stub_name
, "%08x_%s+%x",
459 input_section
->id
& 0xffffffff,
460 hh
->eh
.root
.root
.string
,
461 (int) rela
->r_addend
& 0xffffffff);
466 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
467 stub_name
= bfd_malloc (len
);
468 if (stub_name
!= NULL
)
470 sprintf (stub_name
, "%08x_%x:%x+%x",
471 input_section
->id
& 0xffffffff,
472 sym_sec
->id
& 0xffffffff,
473 (int) ELF32_R_SYM (rela
->r_info
) & 0xffffffff,
474 (int) rela
->r_addend
& 0xffffffff);
480 /* Look up an entry in the stub hash. Stub entries are cached because
481 creating the stub name takes a bit of time. */
483 static struct elf32_hppa_stub_hash_entry
*
484 hppa_get_stub_entry (const asection
*input_section
,
485 const asection
*sym_sec
,
486 struct elf32_hppa_link_hash_entry
*hh
,
487 const Elf_Internal_Rela
*rela
,
488 struct elf32_hppa_link_hash_table
*htab
)
490 struct elf32_hppa_stub_hash_entry
*hsh_entry
;
491 const asection
*id_sec
;
493 /* If this input section is part of a group of sections sharing one
494 stub section, then use the id of the first section in the group.
495 Stub names need to include a section id, as there may well be
496 more than one stub used to reach say, printf, and we need to
497 distinguish between them. */
498 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
500 if (hh
!= NULL
&& hh
->hsh_cache
!= NULL
501 && hh
->hsh_cache
->hh
== hh
502 && hh
->hsh_cache
->id_sec
== id_sec
)
504 hsh_entry
= hh
->hsh_cache
;
510 stub_name
= hppa_stub_name (id_sec
, sym_sec
, hh
, rela
);
511 if (stub_name
== NULL
)
514 hsh_entry
= hppa_stub_hash_lookup (&htab
->bstab
,
515 stub_name
, FALSE
, FALSE
);
517 hh
->hsh_cache
= hsh_entry
;
525 /* Add a new stub entry to the stub hash. Not all fields of the new
526 stub entry are initialised. */
528 static struct elf32_hppa_stub_hash_entry
*
529 hppa_add_stub (const char *stub_name
,
531 struct elf32_hppa_link_hash_table
*htab
)
535 struct elf32_hppa_stub_hash_entry
*hsh
;
537 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
538 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
539 if (stub_sec
== NULL
)
541 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
542 if (stub_sec
== NULL
)
548 namelen
= strlen (link_sec
->name
);
549 len
= namelen
+ sizeof (STUB_SUFFIX
);
550 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
554 memcpy (s_name
, link_sec
->name
, namelen
);
555 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
556 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
557 if (stub_sec
== NULL
)
559 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
561 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
564 /* Enter this entry into the linker stub hash table. */
565 hsh
= hppa_stub_hash_lookup (&htab
->bstab
, stub_name
,
569 (*_bfd_error_handler
) (_("%B: cannot create stub entry %s"),
575 hsh
->stub_sec
= stub_sec
;
576 hsh
->stub_offset
= 0;
577 hsh
->id_sec
= link_sec
;
581 /* Determine the type of stub needed, if any, for a call. */
583 static enum elf32_hppa_stub_type
584 hppa_type_of_stub (asection
*input_sec
,
585 const Elf_Internal_Rela
*rela
,
586 struct elf32_hppa_link_hash_entry
*hh
,
588 struct bfd_link_info
*info
)
591 bfd_vma branch_offset
;
592 bfd_vma max_branch_offset
;
596 && hh
->eh
.plt
.offset
!= (bfd_vma
) -1
597 && hh
->eh
.dynindx
!= -1
600 || !hh
->eh
.def_regular
601 || hh
->eh
.root
.type
== bfd_link_hash_defweak
))
603 /* We need an import stub. Decide between hppa_stub_import
604 and hppa_stub_import_shared later. */
605 return hppa_stub_import
;
608 /* Determine where the call point is. */
609 location
= (input_sec
->output_offset
610 + input_sec
->output_section
->vma
613 branch_offset
= destination
- location
- 8;
614 r_type
= ELF32_R_TYPE (rela
->r_info
);
616 /* Determine if a long branch stub is needed. parisc branch offsets
617 are relative to the second instruction past the branch, ie. +8
618 bytes on from the branch instruction location. The offset is
619 signed and counts in units of 4 bytes. */
620 if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
622 max_branch_offset
= (1 << (17-1)) << 2;
624 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
626 max_branch_offset
= (1 << (12-1)) << 2;
628 else /* R_PARISC_PCREL22F. */
630 max_branch_offset
= (1 << (22-1)) << 2;
633 if (branch_offset
+ max_branch_offset
>= 2*max_branch_offset
)
634 return hppa_stub_long_branch
;
636 return hppa_stub_none
;
639 /* Build one linker stub as defined by the stub hash table entry GEN_ENTRY.
640 IN_ARG contains the link info pointer. */
642 #define LDIL_R1 0x20200000 /* ldil LR'XXX,%r1 */
643 #define BE_SR4_R1 0xe0202002 /* be,n RR'XXX(%sr4,%r1) */
645 #define BL_R1 0xe8200000 /* b,l .+8,%r1 */
646 #define ADDIL_R1 0x28200000 /* addil LR'XXX,%r1,%r1 */
647 #define DEPI_R1 0xd4201c1e /* depi 0,31,2,%r1 */
649 #define ADDIL_DP 0x2b600000 /* addil LR'XXX,%dp,%r1 */
650 #define LDW_R1_R21 0x48350000 /* ldw RR'XXX(%sr0,%r1),%r21 */
651 #define BV_R0_R21 0xeaa0c000 /* bv %r0(%r21) */
652 #define LDW_R1_R19 0x48330000 /* ldw RR'XXX(%sr0,%r1),%r19 */
654 #define ADDIL_R19 0x2a600000 /* addil LR'XXX,%r19,%r1 */
655 #define LDW_R1_DP 0x483b0000 /* ldw RR'XXX(%sr0,%r1),%dp */
657 #define LDSID_R21_R1 0x02a010a1 /* ldsid (%sr0,%r21),%r1 */
658 #define MTSP_R1 0x00011820 /* mtsp %r1,%sr0 */
659 #define BE_SR0_R21 0xe2a00000 /* be 0(%sr0,%r21) */
660 #define STW_RP 0x6bc23fd1 /* stw %rp,-24(%sr0,%sp) */
662 #define BL22_RP 0xe800a002 /* b,l,n XXX,%rp */
663 #define BL_RP 0xe8400002 /* b,l,n XXX,%rp */
664 #define NOP 0x08000240 /* nop */
665 #define LDW_RP 0x4bc23fd1 /* ldw -24(%sr0,%sp),%rp */
666 #define LDSID_RP_R1 0x004010a1 /* ldsid (%sr0,%rp),%r1 */
667 #define BE_SR0_RP 0xe0400002 /* be,n 0(%sr0,%rp) */
674 #define LDW_R1_DLT LDW_R1_R19
676 #define LDW_R1_DLT LDW_R1_DP
680 hppa_build_one_stub (struct bfd_hash_entry
*bh
, void *in_arg
)
682 struct elf32_hppa_stub_hash_entry
*hsh
;
683 struct bfd_link_info
*info
;
684 struct elf32_hppa_link_hash_table
*htab
;
694 /* Massage our args to the form they really have. */
695 hsh
= hppa_stub_hash_entry (bh
);
696 info
= (struct bfd_link_info
*)in_arg
;
698 htab
= hppa_link_hash_table (info
);
699 stub_sec
= hsh
->stub_sec
;
701 /* Make a note of the offset within the stubs for this entry. */
702 hsh
->stub_offset
= stub_sec
->size
;
703 loc
= stub_sec
->contents
+ hsh
->stub_offset
;
705 stub_bfd
= stub_sec
->owner
;
707 switch (hsh
->stub_type
)
709 case hppa_stub_long_branch
:
710 /* Create the long branch. A long branch is formed with "ldil"
711 loading the upper bits of the target address into a register,
712 then branching with "be" which adds in the lower bits.
713 The "be" has its delay slot nullified. */
714 sym_value
= (hsh
->target_value
715 + hsh
->target_section
->output_offset
716 + hsh
->target_section
->output_section
->vma
);
718 val
= hppa_field_adjust (sym_value
, 0, e_lrsel
);
719 insn
= hppa_rebuild_insn ((int) LDIL_R1
, val
, 21);
720 bfd_put_32 (stub_bfd
, insn
, loc
);
722 val
= hppa_field_adjust (sym_value
, 0, e_rrsel
) >> 2;
723 insn
= hppa_rebuild_insn ((int) BE_SR4_R1
, val
, 17);
724 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
729 case hppa_stub_long_branch_shared
:
730 /* Branches are relative. This is where we are going to. */
731 sym_value
= (hsh
->target_value
732 + hsh
->target_section
->output_offset
733 + hsh
->target_section
->output_section
->vma
);
735 /* And this is where we are coming from, more or less. */
736 sym_value
-= (hsh
->stub_offset
737 + stub_sec
->output_offset
738 + stub_sec
->output_section
->vma
);
740 bfd_put_32 (stub_bfd
, (bfd_vma
) BL_R1
, loc
);
741 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_lrsel
);
742 insn
= hppa_rebuild_insn ((int) ADDIL_R1
, val
, 21);
743 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
745 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_rrsel
) >> 2;
746 insn
= hppa_rebuild_insn ((int) BE_SR4_R1
, val
, 17);
747 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
751 case hppa_stub_import
:
752 case hppa_stub_import_shared
:
753 off
= hsh
->hh
->eh
.plt
.offset
;
754 if (off
>= (bfd_vma
) -2)
757 off
&= ~ (bfd_vma
) 1;
759 + htab
->splt
->output_offset
760 + htab
->splt
->output_section
->vma
761 - elf_gp (htab
->splt
->output_section
->owner
));
765 if (hsh
->stub_type
== hppa_stub_import_shared
)
768 val
= hppa_field_adjust (sym_value
, 0, e_lrsel
),
769 insn
= hppa_rebuild_insn ((int) insn
, val
, 21);
770 bfd_put_32 (stub_bfd
, insn
, loc
);
772 /* It is critical to use lrsel/rrsel here because we are using
773 two different offsets (+0 and +4) from sym_value. If we use
774 lsel/rsel then with unfortunate sym_values we will round
775 sym_value+4 up to the next 2k block leading to a mis-match
776 between the lsel and rsel value. */
777 val
= hppa_field_adjust (sym_value
, 0, e_rrsel
);
778 insn
= hppa_rebuild_insn ((int) LDW_R1_R21
, val
, 14);
779 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
781 if (htab
->multi_subspace
)
783 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 4, e_rrsel
);
784 insn
= hppa_rebuild_insn ((int) LDW_R1_DLT
, val
, 14);
785 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
787 bfd_put_32 (stub_bfd
, (bfd_vma
) LDSID_R21_R1
, loc
+ 12);
788 bfd_put_32 (stub_bfd
, (bfd_vma
) MTSP_R1
, loc
+ 16);
789 bfd_put_32 (stub_bfd
, (bfd_vma
) BE_SR0_R21
, loc
+ 20);
790 bfd_put_32 (stub_bfd
, (bfd_vma
) STW_RP
, loc
+ 24);
796 bfd_put_32 (stub_bfd
, (bfd_vma
) BV_R0_R21
, loc
+ 8);
797 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 4, e_rrsel
);
798 insn
= hppa_rebuild_insn ((int) LDW_R1_DLT
, val
, 14);
799 bfd_put_32 (stub_bfd
, insn
, loc
+ 12);
806 case hppa_stub_export
:
807 /* Branches are relative. This is where we are going to. */
808 sym_value
= (hsh
->target_value
809 + hsh
->target_section
->output_offset
810 + hsh
->target_section
->output_section
->vma
);
812 /* And this is where we are coming from. */
813 sym_value
-= (hsh
->stub_offset
814 + stub_sec
->output_offset
815 + stub_sec
->output_section
->vma
);
817 if (sym_value
- 8 + (1 << (17 + 1)) >= (1 << (17 + 2))
818 && (!htab
->has_22bit_branch
819 || sym_value
- 8 + (1 << (22 + 1)) >= (1 << (22 + 2))))
821 (*_bfd_error_handler
)
822 (_("%B(%A+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
823 hsh
->target_section
->owner
,
825 (long) hsh
->stub_offset
,
826 hsh
->bh_root
.string
);
827 bfd_set_error (bfd_error_bad_value
);
831 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_fsel
) >> 2;
832 if (!htab
->has_22bit_branch
)
833 insn
= hppa_rebuild_insn ((int) BL_RP
, val
, 17);
835 insn
= hppa_rebuild_insn ((int) BL22_RP
, val
, 22);
836 bfd_put_32 (stub_bfd
, insn
, loc
);
838 bfd_put_32 (stub_bfd
, (bfd_vma
) NOP
, loc
+ 4);
839 bfd_put_32 (stub_bfd
, (bfd_vma
) LDW_RP
, loc
+ 8);
840 bfd_put_32 (stub_bfd
, (bfd_vma
) LDSID_RP_R1
, loc
+ 12);
841 bfd_put_32 (stub_bfd
, (bfd_vma
) MTSP_R1
, loc
+ 16);
842 bfd_put_32 (stub_bfd
, (bfd_vma
) BE_SR0_RP
, loc
+ 20);
844 /* Point the function symbol at the stub. */
845 hsh
->hh
->eh
.root
.u
.def
.section
= stub_sec
;
846 hsh
->hh
->eh
.root
.u
.def
.value
= stub_sec
->size
;
856 stub_sec
->size
+= size
;
881 /* As above, but don't actually build the stub. Just bump offset so
882 we know stub section sizes. */
885 hppa_size_one_stub (struct bfd_hash_entry
*bh
, void *in_arg
)
887 struct elf32_hppa_stub_hash_entry
*hsh
;
888 struct elf32_hppa_link_hash_table
*htab
;
891 /* Massage our args to the form they really have. */
892 hsh
= hppa_stub_hash_entry (bh
);
895 if (hsh
->stub_type
== hppa_stub_long_branch
)
897 else if (hsh
->stub_type
== hppa_stub_long_branch_shared
)
899 else if (hsh
->stub_type
== hppa_stub_export
)
901 else /* hppa_stub_import or hppa_stub_import_shared. */
903 if (htab
->multi_subspace
)
909 hsh
->stub_sec
->size
+= size
;
913 /* Return nonzero if ABFD represents an HPPA ELF32 file.
914 Additionally we set the default architecture and machine. */
917 elf32_hppa_object_p (bfd
*abfd
)
919 Elf_Internal_Ehdr
* i_ehdrp
;
922 i_ehdrp
= elf_elfheader (abfd
);
923 if (strcmp (bfd_get_target (abfd
), "elf32-hppa-linux") == 0)
925 /* GCC on hppa-linux produces binaries with OSABI=Linux,
926 but the kernel produces corefiles with OSABI=SysV. */
927 if (i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_LINUX
&&
928 i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_NONE
) /* aka SYSV */
931 else if (strcmp (bfd_get_target (abfd
), "elf32-hppa-netbsd") == 0)
933 /* GCC on hppa-netbsd produces binaries with OSABI=NetBSD,
934 but the kernel produces corefiles with OSABI=SysV. */
935 if (i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_NETBSD
&&
936 i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_NONE
) /* aka SYSV */
941 if (i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_HPUX
)
945 flags
= i_ehdrp
->e_flags
;
946 switch (flags
& (EF_PARISC_ARCH
| EF_PARISC_WIDE
))
949 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 10);
951 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 11);
953 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 20);
954 case EFA_PARISC_2_0
| EF_PARISC_WIDE
:
955 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 25);
960 /* Create the .plt and .got sections, and set up our hash table
961 short-cuts to various dynamic sections. */
964 elf32_hppa_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
966 struct elf32_hppa_link_hash_table
*htab
;
967 struct elf_link_hash_entry
*eh
;
969 /* Don't try to create the .plt and .got twice. */
970 htab
= hppa_link_hash_table (info
);
971 if (htab
->splt
!= NULL
)
974 /* Call the generic code to do most of the work. */
975 if (! _bfd_elf_create_dynamic_sections (abfd
, info
))
978 htab
->splt
= bfd_get_section_by_name (abfd
, ".plt");
979 htab
->srelplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
981 htab
->sgot
= bfd_get_section_by_name (abfd
, ".got");
982 htab
->srelgot
= bfd_make_section_with_flags (abfd
, ".rela.got",
989 if (htab
->srelgot
== NULL
990 || ! bfd_set_section_alignment (abfd
, htab
->srelgot
, 2))
993 htab
->sdynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
994 htab
->srelbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
996 /* hppa-linux needs _GLOBAL_OFFSET_TABLE_ to be visible from the main
997 application, because __canonicalize_funcptr_for_compare needs it. */
998 eh
= elf_hash_table (info
)->hgot
;
999 eh
->forced_local
= 0;
1000 eh
->other
= STV_DEFAULT
;
1001 return bfd_elf_link_record_dynamic_symbol (info
, eh
);
1004 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1007 elf32_hppa_copy_indirect_symbol (const struct elf_backend_data
*bed
,
1008 struct elf_link_hash_entry
*eh_dir
,
1009 struct elf_link_hash_entry
*eh_ind
)
1011 struct elf32_hppa_link_hash_entry
*hh_dir
, *hh_ind
;
1013 hh_dir
= hppa_elf_hash_entry (eh_dir
);
1014 hh_ind
= hppa_elf_hash_entry (eh_ind
);
1016 if (hh_ind
->dyn_relocs
!= NULL
)
1018 if (hh_dir
->dyn_relocs
!= NULL
)
1020 struct elf32_hppa_dyn_reloc_entry
**hdh_pp
;
1021 struct elf32_hppa_dyn_reloc_entry
*hdh_p
;
1023 if (eh_ind
->root
.type
== bfd_link_hash_indirect
)
1026 /* Add reloc counts against the weak sym to the strong sym
1027 list. Merge any entries against the same section. */
1028 for (hdh_pp
= &hh_ind
->dyn_relocs
; (hdh_p
= *hdh_pp
) != NULL
; )
1030 struct elf32_hppa_dyn_reloc_entry
*hdh_q
;
1032 for (hdh_q
= hh_dir
->dyn_relocs
; hdh_q
!= NULL
; hdh_q
= hdh_q
->hdh_next
)
1033 if (hdh_q
->sec
== hdh_p
->sec
)
1035 #if RELATIVE_DYNRELOCS
1036 hdh_q
->relative_count
+= hdh_p
->relative_count
;
1038 hdh_q
->count
+= hdh_p
->count
;
1039 *hdh_pp
= hdh_p
->hdh_next
;
1043 hdh_pp
= &hdh_p
->hdh_next
;
1045 *hdh_pp
= hh_dir
->dyn_relocs
;
1048 hh_dir
->dyn_relocs
= hh_ind
->dyn_relocs
;
1049 hh_ind
->dyn_relocs
= NULL
;
1052 if (ELIMINATE_COPY_RELOCS
1053 && eh_ind
->root
.type
!= bfd_link_hash_indirect
1054 && eh_dir
->dynamic_adjusted
)
1056 /* If called to transfer flags for a weakdef during processing
1057 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1058 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1059 eh_dir
->ref_dynamic
|= eh_ind
->ref_dynamic
;
1060 eh_dir
->ref_regular
|= eh_ind
->ref_regular
;
1061 eh_dir
->ref_regular_nonweak
|= eh_ind
->ref_regular_nonweak
;
1062 eh_dir
->needs_plt
|= eh_ind
->needs_plt
;
1065 _bfd_elf_link_hash_copy_indirect (bed
, eh_dir
, eh_ind
);
1068 /* Look through the relocs for a section during the first phase, and
1069 calculate needed space in the global offset table, procedure linkage
1070 table, and dynamic reloc sections. At this point we haven't
1071 necessarily read all the input files. */
1074 elf32_hppa_check_relocs (bfd
*abfd
,
1075 struct bfd_link_info
*info
,
1077 const Elf_Internal_Rela
*relocs
)
1079 Elf_Internal_Shdr
*symtab_hdr
;
1080 struct elf_link_hash_entry
**eh_syms
;
1081 const Elf_Internal_Rela
*rela
;
1082 const Elf_Internal_Rela
*rela_end
;
1083 struct elf32_hppa_link_hash_table
*htab
;
1085 asection
*stubreloc
;
1087 if (info
->relocatable
)
1090 htab
= hppa_link_hash_table (info
);
1091 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1092 eh_syms
= elf_sym_hashes (abfd
);
1096 rela_end
= relocs
+ sec
->reloc_count
;
1097 for (rela
= relocs
; rela
< rela_end
; rela
++)
1106 unsigned int r_symndx
, r_type
;
1107 struct elf32_hppa_link_hash_entry
*hh
;
1110 r_symndx
= ELF32_R_SYM (rela
->r_info
);
1112 if (r_symndx
< symtab_hdr
->sh_info
)
1116 hh
= hppa_elf_hash_entry (eh_syms
[r_symndx
- symtab_hdr
->sh_info
]);
1117 while (hh
->eh
.root
.type
== bfd_link_hash_indirect
1118 || hh
->eh
.root
.type
== bfd_link_hash_warning
)
1119 hh
= hppa_elf_hash_entry (hh
->eh
.root
.u
.i
.link
);
1122 r_type
= ELF32_R_TYPE (rela
->r_info
);
1126 case R_PARISC_DLTIND14F
:
1127 case R_PARISC_DLTIND14R
:
1128 case R_PARISC_DLTIND21L
:
1129 /* This symbol requires a global offset table entry. */
1130 need_entry
= NEED_GOT
;
1133 case R_PARISC_PLABEL14R
: /* "Official" procedure labels. */
1134 case R_PARISC_PLABEL21L
:
1135 case R_PARISC_PLABEL32
:
1136 /* If the addend is non-zero, we break badly. */
1137 if (rela
->r_addend
!= 0)
1140 /* If we are creating a shared library, then we need to
1141 create a PLT entry for all PLABELs, because PLABELs with
1142 local symbols may be passed via a pointer to another
1143 object. Additionally, output a dynamic relocation
1144 pointing to the PLT entry.
1146 For executables, the original 32-bit ABI allowed two
1147 different styles of PLABELs (function pointers): For
1148 global functions, the PLABEL word points into the .plt
1149 two bytes past a (function address, gp) pair, and for
1150 local functions the PLABEL points directly at the
1151 function. The magic +2 for the first type allows us to
1152 differentiate between the two. As you can imagine, this
1153 is a real pain when it comes to generating code to call
1154 functions indirectly or to compare function pointers.
1155 We avoid the mess by always pointing a PLABEL into the
1156 .plt, even for local functions. */
1157 need_entry
= PLT_PLABEL
| NEED_PLT
| NEED_DYNREL
;
1160 case R_PARISC_PCREL12F
:
1161 htab
->has_12bit_branch
= 1;
1164 case R_PARISC_PCREL17C
:
1165 case R_PARISC_PCREL17F
:
1166 htab
->has_17bit_branch
= 1;
1169 case R_PARISC_PCREL22F
:
1170 htab
->has_22bit_branch
= 1;
1172 /* Function calls might need to go through the .plt, and
1173 might require long branch stubs. */
1176 /* We know local syms won't need a .plt entry, and if
1177 they need a long branch stub we can't guarantee that
1178 we can reach the stub. So just flag an error later
1179 if we're doing a shared link and find we need a long
1185 /* Global symbols will need a .plt entry if they remain
1186 global, and in most cases won't need a long branch
1187 stub. Unfortunately, we have to cater for the case
1188 where a symbol is forced local by versioning, or due
1189 to symbolic linking, and we lose the .plt entry. */
1190 need_entry
= NEED_PLT
;
1191 if (hh
->eh
.type
== STT_PARISC_MILLI
)
1196 case R_PARISC_SEGBASE
: /* Used to set segment base. */
1197 case R_PARISC_SEGREL32
: /* Relative reloc, used for unwind. */
1198 case R_PARISC_PCREL14F
: /* PC relative load/store. */
1199 case R_PARISC_PCREL14R
:
1200 case R_PARISC_PCREL17R
: /* External branches. */
1201 case R_PARISC_PCREL21L
: /* As above, and for load/store too. */
1202 case R_PARISC_PCREL32
:
1203 /* We don't need to propagate the relocation if linking a
1204 shared object since these are section relative. */
1207 case R_PARISC_DPREL14F
: /* Used for gp rel data load/store. */
1208 case R_PARISC_DPREL14R
:
1209 case R_PARISC_DPREL21L
:
1212 (*_bfd_error_handler
)
1213 (_("%B: relocation %s can not be used when making a shared object; recompile with -fPIC"),
1215 elf_hppa_howto_table
[r_type
].name
);
1216 bfd_set_error (bfd_error_bad_value
);
1221 case R_PARISC_DIR17F
: /* Used for external branches. */
1222 case R_PARISC_DIR17R
:
1223 case R_PARISC_DIR14F
: /* Used for load/store from absolute locn. */
1224 case R_PARISC_DIR14R
:
1225 case R_PARISC_DIR21L
: /* As above, and for ext branches too. */
1226 case R_PARISC_DIR32
: /* .word relocs. */
1227 /* We may want to output a dynamic relocation later. */
1228 need_entry
= NEED_DYNREL
;
1231 /* This relocation describes the C++ object vtable hierarchy.
1232 Reconstruct it for later use during GC. */
1233 case R_PARISC_GNU_VTINHERIT
:
1234 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, &hh
->eh
, rela
->r_offset
))
1238 /* This relocation describes which C++ vtable entries are actually
1239 used. Record for later use during GC. */
1240 case R_PARISC_GNU_VTENTRY
:
1241 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, &hh
->eh
, rela
->r_addend
))
1249 /* Now carry out our orders. */
1250 if (need_entry
& NEED_GOT
)
1252 /* Allocate space for a GOT entry, as well as a dynamic
1253 relocation for this entry. */
1254 if (htab
->sgot
== NULL
)
1256 if (htab
->etab
.dynobj
== NULL
)
1257 htab
->etab
.dynobj
= abfd
;
1258 if (!elf32_hppa_create_dynamic_sections (htab
->etab
.dynobj
, info
))
1264 hh
->eh
.got
.refcount
+= 1;
1268 bfd_signed_vma
*local_got_refcounts
;
1269 /* This is a global offset table entry for a local symbol. */
1270 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1271 if (local_got_refcounts
== NULL
)
1275 /* Allocate space for local got offsets and local
1276 plt offsets. Done this way to save polluting
1277 elf_obj_tdata with another target specific
1279 size
= symtab_hdr
->sh_info
;
1280 size
*= 2 * sizeof (bfd_signed_vma
);
1281 local_got_refcounts
= bfd_zalloc (abfd
, size
);
1282 if (local_got_refcounts
== NULL
)
1284 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1286 local_got_refcounts
[r_symndx
] += 1;
1290 if (need_entry
& NEED_PLT
)
1292 /* If we are creating a shared library, and this is a reloc
1293 against a weak symbol or a global symbol in a dynamic
1294 object, then we will be creating an import stub and a
1295 .plt entry for the symbol. Similarly, on a normal link
1296 to symbols defined in a dynamic object we'll need the
1297 import stub and a .plt entry. We don't know yet whether
1298 the symbol is defined or not, so make an entry anyway and
1299 clean up later in adjust_dynamic_symbol. */
1300 if ((sec
->flags
& SEC_ALLOC
) != 0)
1304 hh
->eh
.needs_plt
= 1;
1305 hh
->eh
.plt
.refcount
+= 1;
1307 /* If this .plt entry is for a plabel, mark it so
1308 that adjust_dynamic_symbol will keep the entry
1309 even if it appears to be local. */
1310 if (need_entry
& PLT_PLABEL
)
1313 else if (need_entry
& PLT_PLABEL
)
1315 bfd_signed_vma
*local_got_refcounts
;
1316 bfd_signed_vma
*local_plt_refcounts
;
1318 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1319 if (local_got_refcounts
== NULL
)
1323 /* Allocate space for local got offsets and local
1325 size
= symtab_hdr
->sh_info
;
1326 size
*= 2 * sizeof (bfd_signed_vma
);
1327 local_got_refcounts
= bfd_zalloc (abfd
, size
);
1328 if (local_got_refcounts
== NULL
)
1330 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1332 local_plt_refcounts
= (local_got_refcounts
1333 + symtab_hdr
->sh_info
);
1334 local_plt_refcounts
[r_symndx
] += 1;
1339 if (need_entry
& NEED_DYNREL
)
1341 /* Flag this symbol as having a non-got, non-plt reference
1342 so that we generate copy relocs if it turns out to be
1344 if (hh
!= NULL
&& !info
->shared
)
1345 hh
->eh
.non_got_ref
= 1;
1347 /* If we are creating a shared library then we need to copy
1348 the reloc into the shared library. However, if we are
1349 linking with -Bsymbolic, we need only copy absolute
1350 relocs or relocs against symbols that are not defined in
1351 an object we are including in the link. PC- or DP- or
1352 DLT-relative relocs against any local sym or global sym
1353 with DEF_REGULAR set, can be discarded. At this point we
1354 have not seen all the input files, so it is possible that
1355 DEF_REGULAR is not set now but will be set later (it is
1356 never cleared). We account for that possibility below by
1357 storing information in the dyn_relocs field of the
1360 A similar situation to the -Bsymbolic case occurs when
1361 creating shared libraries and symbol visibility changes
1362 render the symbol local.
1364 As it turns out, all the relocs we will be creating here
1365 are absolute, so we cannot remove them on -Bsymbolic
1366 links or visibility changes anyway. A STUB_REL reloc
1367 is absolute too, as in that case it is the reloc in the
1368 stub we will be creating, rather than copying the PCREL
1369 reloc in the branch.
1371 If on the other hand, we are creating an executable, we
1372 may need to keep relocations for symbols satisfied by a
1373 dynamic library if we manage to avoid copy relocs for the
1376 && (sec
->flags
& SEC_ALLOC
) != 0
1377 && (IS_ABSOLUTE_RELOC (r_type
)
1380 || hh
->eh
.root
.type
== bfd_link_hash_defweak
1381 || !hh
->eh
.def_regular
))))
1382 || (ELIMINATE_COPY_RELOCS
1384 && (sec
->flags
& SEC_ALLOC
) != 0
1386 && (hh
->eh
.root
.type
== bfd_link_hash_defweak
1387 || !hh
->eh
.def_regular
)))
1389 struct elf32_hppa_dyn_reloc_entry
*hdh_p
;
1390 struct elf32_hppa_dyn_reloc_entry
**hdh_head
;
1392 /* Create a reloc section in dynobj and make room for
1399 name
= (bfd_elf_string_from_elf_section
1401 elf_elfheader (abfd
)->e_shstrndx
,
1402 elf_section_data (sec
)->rel_hdr
.sh_name
));
1405 (*_bfd_error_handler
)
1406 (_("Could not find relocation section for %s"),
1408 bfd_set_error (bfd_error_bad_value
);
1412 if (htab
->etab
.dynobj
== NULL
)
1413 htab
->etab
.dynobj
= abfd
;
1415 dynobj
= htab
->etab
.dynobj
;
1416 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1421 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
1422 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1423 if ((sec
->flags
& SEC_ALLOC
) != 0)
1424 flags
|= SEC_ALLOC
| SEC_LOAD
;
1425 sreloc
= bfd_make_section_with_flags (dynobj
,
1429 || !bfd_set_section_alignment (dynobj
, sreloc
, 2))
1433 elf_section_data (sec
)->sreloc
= sreloc
;
1436 /* If this is a global symbol, we count the number of
1437 relocations we need for this symbol. */
1440 hdh_head
= &hh
->dyn_relocs
;
1444 /* Track dynamic relocs needed for local syms too.
1445 We really need local syms available to do this
1449 sr
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
1454 hdh_head
= ((struct elf32_hppa_dyn_reloc_entry
**)
1455 &elf_section_data (sr
)->local_dynrel
);
1459 if (hdh_p
== NULL
|| hdh_p
->sec
!= sec
)
1461 hdh_p
= bfd_alloc (htab
->etab
.dynobj
, sizeof *hdh_p
);
1464 hdh_p
->hdh_next
= *hdh_head
;
1468 #if RELATIVE_DYNRELOCS
1469 hdh_p
->relative_count
= 0;
1474 #if RELATIVE_DYNRELOCS
1475 if (!IS_ABSOLUTE_RELOC (rtype
))
1476 hdh_p
->relative_count
+= 1;
1485 /* Return the section that should be marked against garbage collection
1486 for a given relocation. */
1489 elf32_hppa_gc_mark_hook (asection
*sec
,
1490 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1491 Elf_Internal_Rela
*rela
,
1492 struct elf_link_hash_entry
*hh
,
1493 Elf_Internal_Sym
*sym
)
1497 switch ((unsigned int) ELF32_R_TYPE (rela
->r_info
))
1499 case R_PARISC_GNU_VTINHERIT
:
1500 case R_PARISC_GNU_VTENTRY
:
1504 switch (hh
->root
.type
)
1506 case bfd_link_hash_defined
:
1507 case bfd_link_hash_defweak
:
1508 return hh
->root
.u
.def
.section
;
1510 case bfd_link_hash_common
:
1511 return hh
->root
.u
.c
.p
->section
;
1519 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
1524 /* Update the got and plt entry reference counts for the section being
1528 elf32_hppa_gc_sweep_hook (bfd
*abfd
,
1529 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1531 const Elf_Internal_Rela
*relocs
)
1533 Elf_Internal_Shdr
*symtab_hdr
;
1534 struct elf_link_hash_entry
**eh_syms
;
1535 bfd_signed_vma
*local_got_refcounts
;
1536 bfd_signed_vma
*local_plt_refcounts
;
1537 const Elf_Internal_Rela
*rela
, *relend
;
1539 elf_section_data (sec
)->local_dynrel
= NULL
;
1541 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1542 eh_syms
= elf_sym_hashes (abfd
);
1543 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1544 local_plt_refcounts
= local_got_refcounts
;
1545 if (local_plt_refcounts
!= NULL
)
1546 local_plt_refcounts
+= symtab_hdr
->sh_info
;
1548 relend
= relocs
+ sec
->reloc_count
;
1549 for (rela
= relocs
; rela
< relend
; rela
++)
1551 unsigned long r_symndx
;
1552 unsigned int r_type
;
1553 struct elf_link_hash_entry
*eh
= NULL
;
1555 r_symndx
= ELF32_R_SYM (rela
->r_info
);
1556 if (r_symndx
>= symtab_hdr
->sh_info
)
1558 struct elf32_hppa_link_hash_entry
*hh
;
1559 struct elf32_hppa_dyn_reloc_entry
**hdh_pp
;
1560 struct elf32_hppa_dyn_reloc_entry
*hdh_p
;
1562 eh
= eh_syms
[r_symndx
- symtab_hdr
->sh_info
];
1563 while (eh
->root
.type
== bfd_link_hash_indirect
1564 || eh
->root
.type
== bfd_link_hash_warning
)
1565 eh
= (struct elf_link_hash_entry
*) eh
->root
.u
.i
.link
;
1566 hh
= hppa_elf_hash_entry (eh
);
1568 for (hdh_pp
= &hh
->dyn_relocs
; (hdh_p
= *hdh_pp
) != NULL
; hdh_pp
= &hdh_p
->hdh_next
)
1569 if (hdh_p
->sec
== sec
)
1571 /* Everything must go for SEC. */
1572 *hdh_pp
= hdh_p
->hdh_next
;
1577 r_type
= ELF32_R_TYPE (rela
->r_info
);
1580 case R_PARISC_DLTIND14F
:
1581 case R_PARISC_DLTIND14R
:
1582 case R_PARISC_DLTIND21L
:
1585 if (eh
->got
.refcount
> 0)
1586 eh
->got
.refcount
-= 1;
1588 else if (local_got_refcounts
!= NULL
)
1590 if (local_got_refcounts
[r_symndx
] > 0)
1591 local_got_refcounts
[r_symndx
] -= 1;
1595 case R_PARISC_PCREL12F
:
1596 case R_PARISC_PCREL17C
:
1597 case R_PARISC_PCREL17F
:
1598 case R_PARISC_PCREL22F
:
1601 if (eh
->plt
.refcount
> 0)
1602 eh
->plt
.refcount
-= 1;
1606 case R_PARISC_PLABEL14R
:
1607 case R_PARISC_PLABEL21L
:
1608 case R_PARISC_PLABEL32
:
1611 if (eh
->plt
.refcount
> 0)
1612 eh
->plt
.refcount
-= 1;
1614 else if (local_plt_refcounts
!= NULL
)
1616 if (local_plt_refcounts
[r_symndx
] > 0)
1617 local_plt_refcounts
[r_symndx
] -= 1;
1629 /* Support for core dump NOTE sections. */
1632 elf32_hppa_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
1637 switch (note
->descsz
)
1642 case 396: /* Linux/hppa */
1644 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
1647 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
1656 /* Make a ".reg/999" section. */
1657 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
1658 size
, note
->descpos
+ offset
);
1662 elf32_hppa_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
1664 switch (note
->descsz
)
1669 case 124: /* Linux/hppa elf_prpsinfo. */
1670 elf_tdata (abfd
)->core_program
1671 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
1672 elf_tdata (abfd
)->core_command
1673 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
1676 /* Note that for some reason, a spurious space is tacked
1677 onto the end of the args in some (at least one anyway)
1678 implementations, so strip it off if it exists. */
1680 char *command
= elf_tdata (abfd
)->core_command
;
1681 int n
= strlen (command
);
1683 if (0 < n
&& command
[n
- 1] == ' ')
1684 command
[n
- 1] = '\0';
1690 /* Our own version of hide_symbol, so that we can keep plt entries for
1694 elf32_hppa_hide_symbol (struct bfd_link_info
*info
,
1695 struct elf_link_hash_entry
*eh
,
1696 bfd_boolean force_local
)
1700 eh
->forced_local
= 1;
1701 if (eh
->dynindx
!= -1)
1704 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
1709 if (! hppa_elf_hash_entry(eh
)->plabel
)
1712 eh
->plt
= elf_hash_table (info
)->init_plt_refcount
;
1716 /* Adjust a symbol defined by a dynamic object and referenced by a
1717 regular object. The current definition is in some section of the
1718 dynamic object, but we're not including those sections. We have to
1719 change the definition to something the rest of the link can
1723 elf32_hppa_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1724 struct elf_link_hash_entry
*eh
)
1726 struct elf32_hppa_link_hash_table
*htab
;
1728 unsigned int power_of_two
;
1730 /* If this is a function, put it in the procedure linkage table. We
1731 will fill in the contents of the procedure linkage table later. */
1732 if (eh
->type
== STT_FUNC
1735 if (eh
->plt
.refcount
<= 0
1737 && eh
->root
.type
!= bfd_link_hash_defweak
1738 && ! hppa_elf_hash_entry (eh
)->plabel
1739 && (!info
->shared
|| info
->symbolic
)))
1741 /* The .plt entry is not needed when:
1742 a) Garbage collection has removed all references to the
1744 b) We know for certain the symbol is defined in this
1745 object, and it's not a weak definition, nor is the symbol
1746 used by a plabel relocation. Either this object is the
1747 application or we are doing a shared symbolic link. */
1749 eh
->plt
.offset
= (bfd_vma
) -1;
1756 eh
->plt
.offset
= (bfd_vma
) -1;
1758 /* If this is a weak symbol, and there is a real definition, the
1759 processor independent code will have arranged for us to see the
1760 real definition first, and we can just use the same value. */
1761 if (eh
->u
.weakdef
!= NULL
)
1763 if (eh
->u
.weakdef
->root
.type
!= bfd_link_hash_defined
1764 && eh
->u
.weakdef
->root
.type
!= bfd_link_hash_defweak
)
1766 eh
->root
.u
.def
.section
= eh
->u
.weakdef
->root
.u
.def
.section
;
1767 eh
->root
.u
.def
.value
= eh
->u
.weakdef
->root
.u
.def
.value
;
1768 if (ELIMINATE_COPY_RELOCS
)
1769 eh
->non_got_ref
= eh
->u
.weakdef
->non_got_ref
;
1773 /* This is a reference to a symbol defined by a dynamic object which
1774 is not a function. */
1776 /* If we are creating a shared library, we must presume that the
1777 only references to the symbol are via the global offset table.
1778 For such cases we need not do anything here; the relocations will
1779 be handled correctly by relocate_section. */
1783 /* If there are no references to this symbol that do not use the
1784 GOT, we don't need to generate a copy reloc. */
1785 if (!eh
->non_got_ref
)
1788 if (ELIMINATE_COPY_RELOCS
)
1790 struct elf32_hppa_link_hash_entry
*hh
;
1791 struct elf32_hppa_dyn_reloc_entry
*hdh_p
;
1793 hh
= hppa_elf_hash_entry (eh
);
1794 for (hdh_p
= hh
->dyn_relocs
; hdh_p
!= NULL
; hdh_p
= hdh_p
->hdh_next
)
1796 sec
= hdh_p
->sec
->output_section
;
1797 if (sec
!= NULL
&& (sec
->flags
& SEC_READONLY
) != 0)
1801 /* If we didn't find any dynamic relocs in read-only sections, then
1802 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
1805 eh
->non_got_ref
= 0;
1810 /* We must allocate the symbol in our .dynbss section, which will
1811 become part of the .bss section of the executable. There will be
1812 an entry for this symbol in the .dynsym section. The dynamic
1813 object will contain position independent code, so all references
1814 from the dynamic object to this symbol will go through the global
1815 offset table. The dynamic linker will use the .dynsym entry to
1816 determine the address it must put in the global offset table, so
1817 both the dynamic object and the regular object will refer to the
1818 same memory location for the variable. */
1820 htab
= hppa_link_hash_table (info
);
1822 /* We must generate a COPY reloc to tell the dynamic linker to
1823 copy the initial value out of the dynamic object and into the
1824 runtime process image. */
1825 if ((eh
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1827 htab
->srelbss
->size
+= sizeof (Elf32_External_Rela
);
1831 /* We need to figure out the alignment required for this symbol. I
1832 have no idea how other ELF linkers handle this. */
1834 power_of_two
= bfd_log2 (eh
->size
);
1835 if (power_of_two
> 3)
1838 /* Apply the required alignment. */
1839 sec
= htab
->sdynbss
;
1840 sec
->size
= BFD_ALIGN (sec
->size
, (bfd_size_type
) (1 << power_of_two
));
1841 if (power_of_two
> bfd_get_section_alignment (htab
->etab
.dynobj
, sec
))
1843 if (! bfd_set_section_alignment (htab
->etab
.dynobj
, sec
, power_of_two
))
1847 /* Define the symbol as being at this point in the section. */
1848 eh
->root
.u
.def
.section
= sec
;
1849 eh
->root
.u
.def
.value
= sec
->size
;
1851 /* Increment the section size to make room for the symbol. */
1852 sec
->size
+= eh
->size
;
1857 /* Allocate space in the .plt for entries that won't have relocations.
1858 ie. plabel entries. */
1861 allocate_plt_static (struct elf_link_hash_entry
*eh
, void *inf
)
1863 struct bfd_link_info
*info
;
1864 struct elf32_hppa_link_hash_table
*htab
;
1865 struct elf32_hppa_link_hash_entry
*hh
;
1868 if (eh
->root
.type
== bfd_link_hash_indirect
)
1871 if (eh
->root
.type
== bfd_link_hash_warning
)
1872 eh
= (struct elf_link_hash_entry
*) eh
->root
.u
.i
.link
;
1874 info
= (struct bfd_link_info
*) inf
;
1875 hh
= hppa_elf_hash_entry(eh
);
1876 htab
= hppa_link_hash_table (info
);
1877 if (htab
->etab
.dynamic_sections_created
1878 && eh
->plt
.refcount
> 0)
1880 /* Make sure this symbol is output as a dynamic symbol.
1881 Undefined weak syms won't yet be marked as dynamic. */
1882 if (eh
->dynindx
== -1
1883 && !eh
->forced_local
1884 && eh
->type
!= STT_PARISC_MILLI
)
1886 if (! bfd_elf_link_record_dynamic_symbol (info
, eh
))
1890 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
->shared
, eh
))
1892 /* Allocate these later. From this point on, h->plabel
1893 means that the plt entry is only used by a plabel.
1894 We'll be using a normal plt entry for this symbol, so
1895 clear the plabel indicator. */
1899 else if (hh
->plabel
)
1901 /* Make an entry in the .plt section for plabel references
1902 that won't have a .plt entry for other reasons. */
1904 eh
->plt
.offset
= sec
->size
;
1905 sec
->size
+= PLT_ENTRY_SIZE
;
1909 /* No .plt entry needed. */
1910 eh
->plt
.offset
= (bfd_vma
) -1;
1916 eh
->plt
.offset
= (bfd_vma
) -1;
1923 /* Allocate space in .plt, .got and associated reloc sections for
1927 allocate_dynrelocs (struct elf_link_hash_entry
*eh
, void *inf
)
1929 struct bfd_link_info
*info
;
1930 struct elf32_hppa_link_hash_table
*htab
;
1932 struct elf32_hppa_link_hash_entry
*hh
;
1933 struct elf32_hppa_dyn_reloc_entry
*hdh_p
;
1935 if (eh
->root
.type
== bfd_link_hash_indirect
)
1938 if (eh
->root
.type
== bfd_link_hash_warning
)
1939 eh
= (struct elf_link_hash_entry
*) eh
->root
.u
.i
.link
;
1942 htab
= hppa_link_hash_table (info
);
1943 hh
= hppa_elf_hash_entry (eh
);
1945 if (htab
->etab
.dynamic_sections_created
1946 && eh
->plt
.offset
!= (bfd_vma
) -1
1948 && eh
->plt
.refcount
> 0)
1950 /* Make an entry in the .plt section. */
1952 eh
->plt
.offset
= sec
->size
;
1953 sec
->size
+= PLT_ENTRY_SIZE
;
1955 /* We also need to make an entry in the .rela.plt section. */
1956 htab
->srelplt
->size
+= sizeof (Elf32_External_Rela
);
1957 htab
->need_plt_stub
= 1;
1960 if (eh
->got
.refcount
> 0)
1962 /* Make sure this symbol is output as a dynamic symbol.
1963 Undefined weak syms won't yet be marked as dynamic. */
1964 if (eh
->dynindx
== -1
1965 && !eh
->forced_local
1966 && eh
->type
!= STT_PARISC_MILLI
)
1968 if (! bfd_elf_link_record_dynamic_symbol (info
, eh
))
1973 eh
->got
.offset
= sec
->size
;
1974 sec
->size
+= GOT_ENTRY_SIZE
;
1975 if (htab
->etab
.dynamic_sections_created
1977 || (eh
->dynindx
!= -1
1978 && !eh
->forced_local
)))
1980 htab
->srelgot
->size
+= sizeof (Elf32_External_Rela
);
1984 eh
->got
.offset
= (bfd_vma
) -1;
1986 if (hh
->dyn_relocs
== NULL
)
1989 /* If this is a -Bsymbolic shared link, then we need to discard all
1990 space allocated for dynamic pc-relative relocs against symbols
1991 defined in a regular object. For the normal shared case, discard
1992 space for relocs that have become local due to symbol visibility
1996 #if RELATIVE_DYNRELOCS
1997 if (SYMBOL_CALLS_LOCAL (info
, eh
))
1999 struct elf32_hppa_dyn_reloc_entry
**hdh_pp
;
2001 for (hdh_pp
= &hh
->dyn_relocs
; (hdh_p
= *hdh_pp
) != NULL
; )
2003 hdh_p
->count
-= hdh_p
->relative_count
;
2004 hdh_p
->relative_count
= 0;
2005 if (hdh_p
->count
== 0)
2006 *hdh_pp
= hdh_p
->hdh_next
;
2008 hdh_pp
= &hdh_p
->hdh_next
;
2013 /* Also discard relocs on undefined weak syms with non-default
2015 if (ELF_ST_VISIBILITY (eh
->other
) != STV_DEFAULT
2016 && eh
->root
.type
== bfd_link_hash_undefweak
)
2017 hh
->dyn_relocs
= NULL
;
2021 /* For the non-shared case, discard space for relocs against
2022 symbols which turn out to need copy relocs or are not
2025 if (!eh
->non_got_ref
2026 && ((ELIMINATE_COPY_RELOCS
2028 && !eh
->def_regular
)
2029 || (htab
->etab
.dynamic_sections_created
2030 && (eh
->root
.type
== bfd_link_hash_undefweak
2031 || eh
->root
.type
== bfd_link_hash_undefined
))))
2033 /* Make sure this symbol is output as a dynamic symbol.
2034 Undefined weak syms won't yet be marked as dynamic. */
2035 if (eh
->dynindx
== -1
2036 && !eh
->forced_local
2037 && eh
->type
!= STT_PARISC_MILLI
)
2039 if (! bfd_elf_link_record_dynamic_symbol (info
, eh
))
2043 /* If that succeeded, we know we'll be keeping all the
2045 if (eh
->dynindx
!= -1)
2049 hh
->dyn_relocs
= NULL
;
2055 /* Finally, allocate space. */
2056 for (hdh_p
= hh
->dyn_relocs
; hdh_p
!= NULL
; hdh_p
= hdh_p
->hdh_next
)
2058 asection
*sreloc
= elf_section_data (hdh_p
->sec
)->sreloc
;
2059 sreloc
->size
+= hdh_p
->count
* sizeof (Elf32_External_Rela
);
2065 /* This function is called via elf_link_hash_traverse to force
2066 millicode symbols local so they do not end up as globals in the
2067 dynamic symbol table. We ought to be able to do this in
2068 adjust_dynamic_symbol, but our adjust_dynamic_symbol is not called
2069 for all dynamic symbols. Arguably, this is a bug in
2070 elf_adjust_dynamic_symbol. */
2073 clobber_millicode_symbols (struct elf_link_hash_entry
*eh
,
2074 struct bfd_link_info
*info
)
2076 if (eh
->root
.type
== bfd_link_hash_warning
)
2077 eh
= (struct elf_link_hash_entry
*) eh
->root
.u
.i
.link
;
2079 if (eh
->type
== STT_PARISC_MILLI
2080 && !eh
->forced_local
)
2082 elf32_hppa_hide_symbol (info
, eh
, TRUE
);
2087 /* Find any dynamic relocs that apply to read-only sections. */
2090 readonly_dynrelocs (struct elf_link_hash_entry
*eh
, void *inf
)
2092 struct elf32_hppa_link_hash_entry
*hh
;
2093 struct elf32_hppa_dyn_reloc_entry
*hdh_p
;
2095 if (eh
->root
.type
== bfd_link_hash_warning
)
2096 eh
= (struct elf_link_hash_entry
*) eh
->root
.u
.i
.link
;
2098 hh
= hppa_elf_hash_entry (eh
);
2099 for (hdh_p
= hh
->dyn_relocs
; hdh_p
!= NULL
; hdh_p
= hdh_p
->hdh_next
)
2101 asection
*sec
= hdh_p
->sec
->output_section
;
2103 if (sec
!= NULL
&& (sec
->flags
& SEC_READONLY
) != 0)
2105 struct bfd_link_info
*info
= inf
;
2107 info
->flags
|= DF_TEXTREL
;
2109 /* Not an error, just cut short the traversal. */
2116 /* Set the sizes of the dynamic sections. */
2119 elf32_hppa_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2120 struct bfd_link_info
*info
)
2122 struct elf32_hppa_link_hash_table
*htab
;
2128 htab
= hppa_link_hash_table (info
);
2129 dynobj
= htab
->etab
.dynobj
;
2133 if (htab
->etab
.dynamic_sections_created
)
2135 /* Set the contents of the .interp section to the interpreter. */
2136 if (info
->executable
)
2138 sec
= bfd_get_section_by_name (dynobj
, ".interp");
2141 sec
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2142 sec
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2145 /* Force millicode symbols local. */
2146 elf_link_hash_traverse (&htab
->etab
,
2147 clobber_millicode_symbols
,
2151 /* Set up .got and .plt offsets for local syms, and space for local
2153 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2155 bfd_signed_vma
*local_got
;
2156 bfd_signed_vma
*end_local_got
;
2157 bfd_signed_vma
*local_plt
;
2158 bfd_signed_vma
*end_local_plt
;
2159 bfd_size_type locsymcount
;
2160 Elf_Internal_Shdr
*symtab_hdr
;
2163 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
2166 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2168 struct elf32_hppa_dyn_reloc_entry
*hdh_p
;
2170 for (hdh_p
= ((struct elf32_hppa_dyn_reloc_entry
*)
2171 elf_section_data (sec
)->local_dynrel
);
2173 hdh_p
= hdh_p
->hdh_next
)
2175 if (!bfd_is_abs_section (hdh_p
->sec
)
2176 && bfd_is_abs_section (hdh_p
->sec
->output_section
))
2178 /* Input section has been discarded, either because
2179 it is a copy of a linkonce section or due to
2180 linker script /DISCARD/, so we'll be discarding
2183 else if (hdh_p
->count
!= 0)
2185 srel
= elf_section_data (hdh_p
->sec
)->sreloc
;
2186 srel
->size
+= hdh_p
->count
* sizeof (Elf32_External_Rela
);
2187 if ((hdh_p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
2188 info
->flags
|= DF_TEXTREL
;
2193 local_got
= elf_local_got_refcounts (ibfd
);
2197 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
2198 locsymcount
= symtab_hdr
->sh_info
;
2199 end_local_got
= local_got
+ locsymcount
;
2201 srel
= htab
->srelgot
;
2202 for (; local_got
< end_local_got
; ++local_got
)
2206 *local_got
= sec
->size
;
2207 sec
->size
+= GOT_ENTRY_SIZE
;
2209 srel
->size
+= sizeof (Elf32_External_Rela
);
2212 *local_got
= (bfd_vma
) -1;
2215 local_plt
= end_local_got
;
2216 end_local_plt
= local_plt
+ locsymcount
;
2217 if (! htab
->etab
.dynamic_sections_created
)
2219 /* Won't be used, but be safe. */
2220 for (; local_plt
< end_local_plt
; ++local_plt
)
2221 *local_plt
= (bfd_vma
) -1;
2226 srel
= htab
->srelplt
;
2227 for (; local_plt
< end_local_plt
; ++local_plt
)
2231 *local_plt
= sec
->size
;
2232 sec
->size
+= PLT_ENTRY_SIZE
;
2234 srel
->size
+= sizeof (Elf32_External_Rela
);
2237 *local_plt
= (bfd_vma
) -1;
2242 /* Do all the .plt entries without relocs first. The dynamic linker
2243 uses the last .plt reloc to find the end of the .plt (and hence
2244 the start of the .got) for lazy linking. */
2245 elf_link_hash_traverse (&htab
->etab
, allocate_plt_static
, info
);
2247 /* Allocate global sym .plt and .got entries, and space for global
2248 sym dynamic relocs. */
2249 elf_link_hash_traverse (&htab
->etab
, allocate_dynrelocs
, info
);
2251 /* The check_relocs and adjust_dynamic_symbol entry points have
2252 determined the sizes of the various dynamic sections. Allocate
2255 for (sec
= dynobj
->sections
; sec
!= NULL
; sec
= sec
->next
)
2257 if ((sec
->flags
& SEC_LINKER_CREATED
) == 0)
2260 if (sec
== htab
->splt
)
2262 if (htab
->need_plt_stub
)
2264 /* Make space for the plt stub at the end of the .plt
2265 section. We want this stub right at the end, up
2266 against the .got section. */
2267 int gotalign
= bfd_section_alignment (dynobj
, htab
->sgot
);
2268 int pltalign
= bfd_section_alignment (dynobj
, sec
);
2271 if (gotalign
> pltalign
)
2272 bfd_set_section_alignment (dynobj
, sec
, gotalign
);
2273 mask
= ((bfd_size_type
) 1 << gotalign
) - 1;
2274 sec
->size
= (sec
->size
+ sizeof (plt_stub
) + mask
) & ~mask
;
2277 else if (sec
== htab
->sgot
)
2279 else if (strncmp (bfd_get_section_name (dynobj
, sec
), ".rela", 5) == 0)
2283 /* Remember whether there are any reloc sections other
2285 if (sec
!= htab
->srelplt
)
2288 /* We use the reloc_count field as a counter if we need
2289 to copy relocs into the output file. */
2290 sec
->reloc_count
= 0;
2295 /* It's not one of our sections, so don't allocate space. */
2301 /* If we don't need this section, strip it from the
2302 output file. This is mostly to handle .rela.bss and
2303 .rela.plt. We must create both sections in
2304 create_dynamic_sections, because they must be created
2305 before the linker maps input sections to output
2306 sections. The linker does that before
2307 adjust_dynamic_symbol is called, and it is that
2308 function which decides whether anything needs to go
2309 into these sections. */
2310 sec
->flags
|= SEC_EXCLUDE
;
2314 /* Allocate memory for the section contents. Zero it, because
2315 we may not fill in all the reloc sections. */
2316 sec
->contents
= bfd_zalloc (dynobj
, sec
->size
);
2317 if (sec
->contents
== NULL
&& sec
->size
!= 0)
2321 if (htab
->etab
.dynamic_sections_created
)
2323 /* Like IA-64 and HPPA64, always create a DT_PLTGOT. It
2324 actually has nothing to do with the PLT, it is how we
2325 communicate the LTP value of a load module to the dynamic
2327 #define add_dynamic_entry(TAG, VAL) \
2328 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2330 if (!add_dynamic_entry (DT_PLTGOT
, 0))
2333 /* Add some entries to the .dynamic section. We fill in the
2334 values later, in elf32_hppa_finish_dynamic_sections, but we
2335 must add the entries now so that we get the correct size for
2336 the .dynamic section. The DT_DEBUG entry is filled in by the
2337 dynamic linker and used by the debugger. */
2340 if (!add_dynamic_entry (DT_DEBUG
, 0))
2344 if (htab
->srelplt
->size
!= 0)
2346 if (!add_dynamic_entry (DT_PLTRELSZ
, 0)
2347 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
2348 || !add_dynamic_entry (DT_JMPREL
, 0))
2354 if (!add_dynamic_entry (DT_RELA
, 0)
2355 || !add_dynamic_entry (DT_RELASZ
, 0)
2356 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
2359 /* If any dynamic relocs apply to a read-only section,
2360 then we need a DT_TEXTREL entry. */
2361 if ((info
->flags
& DF_TEXTREL
) == 0)
2362 elf_link_hash_traverse (&htab
->etab
, readonly_dynrelocs
, info
);
2364 if ((info
->flags
& DF_TEXTREL
) != 0)
2366 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2371 #undef add_dynamic_entry
2376 /* External entry points for sizing and building linker stubs. */
2378 /* Set up various things so that we can make a list of input sections
2379 for each output section included in the link. Returns -1 on error,
2380 0 when no stubs will be needed, and 1 on success. */
2383 elf32_hppa_setup_section_lists (bfd
*output_bfd
, struct bfd_link_info
*info
)
2386 unsigned int bfd_count
;
2387 int top_id
, top_index
;
2389 asection
**input_list
, **list
;
2391 struct elf32_hppa_link_hash_table
*htab
= hppa_link_hash_table (info
);
2393 /* Count the number of input BFDs and find the top input section id. */
2394 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
2396 input_bfd
= input_bfd
->link_next
)
2399 for (section
= input_bfd
->sections
;
2401 section
= section
->next
)
2403 if (top_id
< section
->id
)
2404 top_id
= section
->id
;
2407 htab
->bfd_count
= bfd_count
;
2409 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
2410 htab
->stub_group
= bfd_zmalloc (amt
);
2411 if (htab
->stub_group
== NULL
)
2414 /* We can't use output_bfd->section_count here to find the top output
2415 section index as some sections may have been removed, and
2416 strip_excluded_output_sections doesn't renumber the indices. */
2417 for (section
= output_bfd
->sections
, top_index
= 0;
2419 section
= section
->next
)
2421 if (top_index
< section
->index
)
2422 top_index
= section
->index
;
2425 htab
->top_index
= top_index
;
2426 amt
= sizeof (asection
*) * (top_index
+ 1);
2427 input_list
= bfd_malloc (amt
);
2428 htab
->input_list
= input_list
;
2429 if (input_list
== NULL
)
2432 /* For sections we aren't interested in, mark their entries with a
2433 value we can check later. */
2434 list
= input_list
+ top_index
;
2436 *list
= bfd_abs_section_ptr
;
2437 while (list
-- != input_list
);
2439 for (section
= output_bfd
->sections
;
2441 section
= section
->next
)
2443 if ((section
->flags
& SEC_CODE
) != 0)
2444 input_list
[section
->index
] = NULL
;
2450 /* The linker repeatedly calls this function for each input section,
2451 in the order that input sections are linked into output sections.
2452 Build lists of input sections to determine groupings between which
2453 we may insert linker stubs. */
2456 elf32_hppa_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
2458 struct elf32_hppa_link_hash_table
*htab
= hppa_link_hash_table (info
);
2460 if (isec
->output_section
->index
<= htab
->top_index
)
2462 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
2463 if (*list
!= bfd_abs_section_ptr
)
2465 /* Steal the link_sec pointer for our list. */
2466 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
2467 /* This happens to make the list in reverse order,
2468 which is what we want. */
2469 PREV_SEC (isec
) = *list
;
2475 /* See whether we can group stub sections together. Grouping stub
2476 sections may result in fewer stubs. More importantly, we need to
2477 put all .init* and .fini* stubs at the beginning of the .init or
2478 .fini output sections respectively, because glibc splits the
2479 _init and _fini functions into multiple parts. Putting a stub in
2480 the middle of a function is not a good idea. */
2483 group_sections (struct elf32_hppa_link_hash_table
*htab
,
2484 bfd_size_type stub_group_size
,
2485 bfd_boolean stubs_always_before_branch
)
2487 asection
**list
= htab
->input_list
+ htab
->top_index
;
2490 asection
*tail
= *list
;
2491 if (tail
== bfd_abs_section_ptr
)
2493 while (tail
!= NULL
)
2497 bfd_size_type total
;
2498 bfd_boolean big_sec
;
2502 big_sec
= total
>= stub_group_size
;
2504 while ((prev
= PREV_SEC (curr
)) != NULL
2505 && ((total
+= curr
->output_offset
- prev
->output_offset
)
2509 /* OK, the size from the start of CURR to the end is less
2510 than 240000 bytes and thus can be handled by one stub
2511 section. (or the tail section is itself larger than
2512 240000 bytes, in which case we may be toast.)
2513 We should really be keeping track of the total size of
2514 stubs added here, as stubs contribute to the final output
2515 section size. That's a little tricky, and this way will
2516 only break if stubs added total more than 22144 bytes, or
2517 2768 long branch stubs. It seems unlikely for more than
2518 2768 different functions to be called, especially from
2519 code only 240000 bytes long. This limit used to be
2520 250000, but c++ code tends to generate lots of little
2521 functions, and sometimes violated the assumption. */
2524 prev
= PREV_SEC (tail
);
2525 /* Set up this stub group. */
2526 htab
->stub_group
[tail
->id
].link_sec
= curr
;
2528 while (tail
!= curr
&& (tail
= prev
) != NULL
);
2530 /* But wait, there's more! Input sections up to 240000
2531 bytes before the stub section can be handled by it too.
2532 Don't do this if we have a really large section after the
2533 stubs, as adding more stubs increases the chance that
2534 branches may not reach into the stub section. */
2535 if (!stubs_always_before_branch
&& !big_sec
)
2539 && ((total
+= tail
->output_offset
- prev
->output_offset
)
2543 prev
= PREV_SEC (tail
);
2544 htab
->stub_group
[tail
->id
].link_sec
= curr
;
2550 while (list
-- != htab
->input_list
);
2551 free (htab
->input_list
);
2555 /* Read in all local syms for all input bfds, and create hash entries
2556 for export stubs if we are building a multi-subspace shared lib.
2557 Returns -1 on error, 1 if export stubs created, 0 otherwise. */
2560 get_local_syms (bfd
*output_bfd
, bfd
*input_bfd
, struct bfd_link_info
*info
)
2562 unsigned int bfd_indx
;
2563 Elf_Internal_Sym
*local_syms
, **all_local_syms
;
2564 int stub_changed
= 0;
2565 struct elf32_hppa_link_hash_table
*htab
= hppa_link_hash_table (info
);
2567 /* We want to read in symbol extension records only once. To do this
2568 we need to read in the local symbols in parallel and save them for
2569 later use; so hold pointers to the local symbols in an array. */
2570 bfd_size_type amt
= sizeof (Elf_Internal_Sym
*) * htab
->bfd_count
;
2571 all_local_syms
= bfd_zmalloc (amt
);
2572 htab
->all_local_syms
= all_local_syms
;
2573 if (all_local_syms
== NULL
)
2576 /* Walk over all the input BFDs, swapping in local symbols.
2577 If we are creating a shared library, create hash entries for the
2581 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
2583 Elf_Internal_Shdr
*symtab_hdr
;
2585 /* We'll need the symbol table in a second. */
2586 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2587 if (symtab_hdr
->sh_info
== 0)
2590 /* We need an array of the local symbols attached to the input bfd. */
2591 local_syms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2592 if (local_syms
== NULL
)
2594 local_syms
= bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
2595 symtab_hdr
->sh_info
, 0,
2597 /* Cache them for elf_link_input_bfd. */
2598 symtab_hdr
->contents
= (unsigned char *) local_syms
;
2600 if (local_syms
== NULL
)
2603 all_local_syms
[bfd_indx
] = local_syms
;
2605 if (info
->shared
&& htab
->multi_subspace
)
2607 struct elf_link_hash_entry
**eh_syms
;
2608 struct elf_link_hash_entry
**eh_symend
;
2609 unsigned int symcount
;
2611 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
2612 - symtab_hdr
->sh_info
);
2613 eh_syms
= (struct elf_link_hash_entry
**) elf_sym_hashes (input_bfd
);
2614 eh_symend
= (struct elf_link_hash_entry
**) (eh_syms
+ symcount
);
2616 /* Look through the global syms for functions; We need to
2617 build export stubs for all globally visible functions. */
2618 for (; eh_syms
< eh_symend
; eh_syms
++)
2620 struct elf32_hppa_link_hash_entry
*hh
;
2622 hh
= hppa_elf_hash_entry (*eh_syms
);
2624 while (hh
->eh
.root
.type
== bfd_link_hash_indirect
2625 || hh
->eh
.root
.type
== bfd_link_hash_warning
)
2626 hh
= hppa_elf_hash_entry (hh
->eh
.root
.u
.i
.link
);
2628 /* At this point in the link, undefined syms have been
2629 resolved, so we need to check that the symbol was
2630 defined in this BFD. */
2631 if ((hh
->eh
.root
.type
== bfd_link_hash_defined
2632 || hh
->eh
.root
.type
== bfd_link_hash_defweak
)
2633 && hh
->eh
.type
== STT_FUNC
2634 && hh
->eh
.root
.u
.def
.section
->output_section
!= NULL
2635 && (hh
->eh
.root
.u
.def
.section
->output_section
->owner
2637 && hh
->eh
.root
.u
.def
.section
->owner
== input_bfd
2638 && hh
->eh
.def_regular
2639 && !hh
->eh
.forced_local
2640 && ELF_ST_VISIBILITY (hh
->eh
.other
) == STV_DEFAULT
)
2643 const char *stub_name
;
2644 struct elf32_hppa_stub_hash_entry
*hsh
;
2646 sec
= hh
->eh
.root
.u
.def
.section
;
2647 stub_name
= hh
->eh
.root
.root
.string
;
2648 hsh
= hppa_stub_hash_lookup (&htab
->bstab
,
2653 hsh
= hppa_add_stub (stub_name
, sec
, htab
);
2657 hsh
->target_value
= hh
->eh
.root
.u
.def
.value
;
2658 hsh
->target_section
= hh
->eh
.root
.u
.def
.section
;
2659 hsh
->stub_type
= hppa_stub_export
;
2665 (*_bfd_error_handler
) (_("%B: duplicate export stub %s"),
2674 return stub_changed
;
2677 /* Determine and set the size of the stub section for a final link.
2679 The basic idea here is to examine all the relocations looking for
2680 PC-relative calls to a target that is unreachable with a "bl"
2684 elf32_hppa_size_stubs
2685 (bfd
*output_bfd
, bfd
*stub_bfd
, struct bfd_link_info
*info
,
2686 bfd_boolean multi_subspace
, bfd_signed_vma group_size
,
2687 asection
* (*add_stub_section
) (const char *, asection
*),
2688 void (*layout_sections_again
) (void))
2690 bfd_size_type stub_group_size
;
2691 bfd_boolean stubs_always_before_branch
;
2692 bfd_boolean stub_changed
;
2693 struct elf32_hppa_link_hash_table
*htab
= hppa_link_hash_table (info
);
2695 /* Stash our params away. */
2696 htab
->stub_bfd
= stub_bfd
;
2697 htab
->multi_subspace
= multi_subspace
;
2698 htab
->add_stub_section
= add_stub_section
;
2699 htab
->layout_sections_again
= layout_sections_again
;
2700 stubs_always_before_branch
= group_size
< 0;
2702 stub_group_size
= -group_size
;
2704 stub_group_size
= group_size
;
2705 if (stub_group_size
== 1)
2707 /* Default values. */
2708 if (stubs_always_before_branch
)
2710 stub_group_size
= 7680000;
2711 if (htab
->has_17bit_branch
|| htab
->multi_subspace
)
2712 stub_group_size
= 240000;
2713 if (htab
->has_12bit_branch
)
2714 stub_group_size
= 7500;
2718 stub_group_size
= 6971392;
2719 if (htab
->has_17bit_branch
|| htab
->multi_subspace
)
2720 stub_group_size
= 217856;
2721 if (htab
->has_12bit_branch
)
2722 stub_group_size
= 6808;
2726 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
2728 switch (get_local_syms (output_bfd
, info
->input_bfds
, info
))
2731 if (htab
->all_local_syms
)
2732 goto error_ret_free_local
;
2736 stub_changed
= FALSE
;
2740 stub_changed
= TRUE
;
2747 unsigned int bfd_indx
;
2750 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
2752 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
2754 Elf_Internal_Shdr
*symtab_hdr
;
2756 Elf_Internal_Sym
*local_syms
;
2758 /* We'll need the symbol table in a second. */
2759 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2760 if (symtab_hdr
->sh_info
== 0)
2763 local_syms
= htab
->all_local_syms
[bfd_indx
];
2765 /* Walk over each section attached to the input bfd. */
2766 for (section
= input_bfd
->sections
;
2768 section
= section
->next
)
2770 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
2772 /* If there aren't any relocs, then there's nothing more
2774 if ((section
->flags
& SEC_RELOC
) == 0
2775 || section
->reloc_count
== 0)
2778 /* If this section is a link-once section that will be
2779 discarded, then don't create any stubs. */
2780 if (section
->output_section
== NULL
2781 || section
->output_section
->owner
!= output_bfd
)
2784 /* Get the relocs. */
2786 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
, NULL
,
2788 if (internal_relocs
== NULL
)
2789 goto error_ret_free_local
;
2791 /* Now examine each relocation. */
2792 irela
= internal_relocs
;
2793 irelaend
= irela
+ section
->reloc_count
;
2794 for (; irela
< irelaend
; irela
++)
2796 unsigned int r_type
, r_indx
;
2797 enum elf32_hppa_stub_type stub_type
;
2798 struct elf32_hppa_stub_hash_entry
*hsh
;
2801 bfd_vma destination
;
2802 struct elf32_hppa_link_hash_entry
*hh
;
2804 const asection
*id_sec
;
2806 r_type
= ELF32_R_TYPE (irela
->r_info
);
2807 r_indx
= ELF32_R_SYM (irela
->r_info
);
2809 if (r_type
>= (unsigned int) R_PARISC_UNIMPLEMENTED
)
2811 bfd_set_error (bfd_error_bad_value
);
2812 error_ret_free_internal
:
2813 if (elf_section_data (section
)->relocs
== NULL
)
2814 free (internal_relocs
);
2815 goto error_ret_free_local
;
2818 /* Only look for stubs on call instructions. */
2819 if (r_type
!= (unsigned int) R_PARISC_PCREL12F
2820 && r_type
!= (unsigned int) R_PARISC_PCREL17F
2821 && r_type
!= (unsigned int) R_PARISC_PCREL22F
)
2824 /* Now determine the call target, its name, value,
2830 if (r_indx
< symtab_hdr
->sh_info
)
2832 /* It's a local symbol. */
2833 Elf_Internal_Sym
*sym
;
2834 Elf_Internal_Shdr
*hdr
;
2836 sym
= local_syms
+ r_indx
;
2837 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
2838 sym_sec
= hdr
->bfd_section
;
2839 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
2840 sym_value
= sym
->st_value
;
2841 destination
= (sym_value
+ irela
->r_addend
2842 + sym_sec
->output_offset
2843 + sym_sec
->output_section
->vma
);
2847 /* It's an external symbol. */
2850 e_indx
= r_indx
- symtab_hdr
->sh_info
;
2851 hh
= hppa_elf_hash_entry (elf_sym_hashes (input_bfd
)[e_indx
]);
2853 while (hh
->eh
.root
.type
== bfd_link_hash_indirect
2854 || hh
->eh
.root
.type
== bfd_link_hash_warning
)
2855 hh
= hppa_elf_hash_entry (hh
->eh
.root
.u
.i
.link
);
2857 if (hh
->eh
.root
.type
== bfd_link_hash_defined
2858 || hh
->eh
.root
.type
== bfd_link_hash_defweak
)
2860 sym_sec
= hh
->eh
.root
.u
.def
.section
;
2861 sym_value
= hh
->eh
.root
.u
.def
.value
;
2862 if (sym_sec
->output_section
!= NULL
)
2863 destination
= (sym_value
+ irela
->r_addend
2864 + sym_sec
->output_offset
2865 + sym_sec
->output_section
->vma
);
2867 else if (hh
->eh
.root
.type
== bfd_link_hash_undefweak
)
2872 else if (hh
->eh
.root
.type
== bfd_link_hash_undefined
)
2874 if (! (info
->unresolved_syms_in_objects
== RM_IGNORE
2875 && (ELF_ST_VISIBILITY (hh
->eh
.other
)
2877 && hh
->eh
.type
!= STT_PARISC_MILLI
))
2882 bfd_set_error (bfd_error_bad_value
);
2883 goto error_ret_free_internal
;
2887 /* Determine what (if any) linker stub is needed. */
2888 stub_type
= hppa_type_of_stub (section
, irela
, hh
,
2890 if (stub_type
== hppa_stub_none
)
2893 /* Support for grouping stub sections. */
2894 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
2896 /* Get the name of this stub. */
2897 stub_name
= hppa_stub_name (id_sec
, sym_sec
, hh
, irela
);
2899 goto error_ret_free_internal
;
2901 hsh
= hppa_stub_hash_lookup (&htab
->bstab
,
2906 /* The proper stub has already been created. */
2911 hsh
= hppa_add_stub (stub_name
, section
, htab
);
2915 goto error_ret_free_internal
;
2918 hsh
->target_value
= sym_value
;
2919 hsh
->target_section
= sym_sec
;
2920 hsh
->stub_type
= stub_type
;
2923 if (stub_type
== hppa_stub_import
)
2924 hsh
->stub_type
= hppa_stub_import_shared
;
2925 else if (stub_type
== hppa_stub_long_branch
)
2926 hsh
->stub_type
= hppa_stub_long_branch_shared
;
2929 stub_changed
= TRUE
;
2932 /* We're done with the internal relocs, free them. */
2933 if (elf_section_data (section
)->relocs
== NULL
)
2934 free (internal_relocs
);
2941 /* OK, we've added some stubs. Find out the new size of the
2943 for (stub_sec
= htab
->stub_bfd
->sections
;
2945 stub_sec
= stub_sec
->next
)
2948 bfd_hash_traverse (&htab
->bstab
, hppa_size_one_stub
, htab
);
2950 /* Ask the linker to do its stuff. */
2951 (*htab
->layout_sections_again
) ();
2952 stub_changed
= FALSE
;
2955 free (htab
->all_local_syms
);
2958 error_ret_free_local
:
2959 free (htab
->all_local_syms
);
2963 /* For a final link, this function is called after we have sized the
2964 stubs to provide a value for __gp. */
2967 elf32_hppa_set_gp (bfd
*abfd
, struct bfd_link_info
*info
)
2969 struct bfd_link_hash_entry
*h
;
2970 asection
*sec
= NULL
;
2972 struct elf32_hppa_link_hash_table
*htab
;
2974 htab
= hppa_link_hash_table (info
);
2975 h
= bfd_link_hash_lookup (&htab
->etab
.root
, "$global$", FALSE
, FALSE
, FALSE
);
2978 && (h
->type
== bfd_link_hash_defined
2979 || h
->type
== bfd_link_hash_defweak
))
2981 gp_val
= h
->u
.def
.value
;
2982 sec
= h
->u
.def
.section
;
2986 asection
*splt
= bfd_get_section_by_name (abfd
, ".plt");
2987 asection
*sgot
= bfd_get_section_by_name (abfd
, ".got");
2989 /* Choose to point our LTP at, in this order, one of .plt, .got,
2990 or .data, if these sections exist. In the case of choosing
2991 .plt try to make the LTP ideal for addressing anywhere in the
2992 .plt or .got with a 14 bit signed offset. Typically, the end
2993 of the .plt is the start of the .got, so choose .plt + 0x2000
2994 if either the .plt or .got is larger than 0x2000. If both
2995 the .plt and .got are smaller than 0x2000, choose the end of
2996 the .plt section. */
2997 sec
= strcmp (bfd_get_target (abfd
), "elf32-hppa-netbsd") == 0
3002 if (gp_val
> 0x2000 || (sgot
&& sgot
->size
> 0x2000))
3012 if (strcmp (bfd_get_target (abfd
), "elf32-hppa-netbsd") != 0)
3014 /* We know we don't have a .plt. If .got is large,
3016 if (sec
->size
> 0x2000)
3022 /* No .plt or .got. Who cares what the LTP is? */
3023 sec
= bfd_get_section_by_name (abfd
, ".data");
3029 h
->type
= bfd_link_hash_defined
;
3030 h
->u
.def
.value
= gp_val
;
3032 h
->u
.def
.section
= sec
;
3034 h
->u
.def
.section
= bfd_abs_section_ptr
;
3038 if (sec
!= NULL
&& sec
->output_section
!= NULL
)
3039 gp_val
+= sec
->output_section
->vma
+ sec
->output_offset
;
3041 elf_gp (abfd
) = gp_val
;
3045 /* Build all the stubs associated with the current output file. The
3046 stubs are kept in a hash table attached to the main linker hash
3047 table. We also set up the .plt entries for statically linked PIC
3048 functions here. This function is called via hppaelf_finish in the
3052 elf32_hppa_build_stubs (struct bfd_link_info
*info
)
3055 struct bfd_hash_table
*table
;
3056 struct elf32_hppa_link_hash_table
*htab
;
3058 htab
= hppa_link_hash_table (info
);
3060 for (stub_sec
= htab
->stub_bfd
->sections
;
3062 stub_sec
= stub_sec
->next
)
3066 /* Allocate memory to hold the linker stubs. */
3067 size
= stub_sec
->size
;
3068 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, size
);
3069 if (stub_sec
->contents
== NULL
&& size
!= 0)
3074 /* Build the stubs as directed by the stub hash table. */
3075 table
= &htab
->bstab
;
3076 bfd_hash_traverse (table
, hppa_build_one_stub
, info
);
3081 /* Perform a final link. */
3084 elf32_hppa_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
3086 /* Invoke the regular ELF linker to do all the work. */
3087 if (!bfd_elf_final_link (abfd
, info
))
3090 /* If we're producing a final executable, sort the contents of the
3092 return elf_hppa_sort_unwind (abfd
);
3095 /* Record the lowest address for the data and text segments. */
3098 hppa_record_segment_addr (bfd
*abfd ATTRIBUTE_UNUSED
,
3102 struct elf32_hppa_link_hash_table
*htab
;
3104 htab
= (struct elf32_hppa_link_hash_table
*) data
;
3106 if ((section
->flags
& (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3108 bfd_vma value
= section
->vma
- section
->filepos
;
3110 if ((section
->flags
& SEC_READONLY
) != 0)
3112 if (value
< htab
->text_segment_base
)
3113 htab
->text_segment_base
= value
;
3117 if (value
< htab
->data_segment_base
)
3118 htab
->data_segment_base
= value
;
3123 /* Perform a relocation as part of a final link. */
3125 static bfd_reloc_status_type
3126 final_link_relocate (asection
*input_section
,
3128 const Elf_Internal_Rela
*rela
,
3130 struct elf32_hppa_link_hash_table
*htab
,
3132 struct elf32_hppa_link_hash_entry
*hh
,
3133 struct bfd_link_info
*info
)
3136 unsigned int r_type
= ELF32_R_TYPE (rela
->r_info
);
3137 unsigned int orig_r_type
= r_type
;
3138 reloc_howto_type
*howto
= elf_hppa_howto_table
+ r_type
;
3139 int r_format
= howto
->bitsize
;
3140 enum hppa_reloc_field_selector_type_alt r_field
;
3141 bfd
*input_bfd
= input_section
->owner
;
3142 bfd_vma offset
= rela
->r_offset
;
3143 bfd_vma max_branch_offset
= 0;
3144 bfd_byte
*hit_data
= contents
+ offset
;
3145 bfd_signed_vma addend
= rela
->r_addend
;
3147 struct elf32_hppa_stub_hash_entry
*hsh
= NULL
;
3150 if (r_type
== R_PARISC_NONE
)
3151 return bfd_reloc_ok
;
3153 insn
= bfd_get_32 (input_bfd
, hit_data
);
3155 /* Find out where we are and where we're going. */
3156 location
= (offset
+
3157 input_section
->output_offset
+
3158 input_section
->output_section
->vma
);
3160 /* If we are not building a shared library, convert DLTIND relocs to
3166 case R_PARISC_DLTIND21L
:
3167 r_type
= R_PARISC_DPREL21L
;
3170 case R_PARISC_DLTIND14R
:
3171 r_type
= R_PARISC_DPREL14R
;
3174 case R_PARISC_DLTIND14F
:
3175 r_type
= R_PARISC_DPREL14F
;
3182 case R_PARISC_PCREL12F
:
3183 case R_PARISC_PCREL17F
:
3184 case R_PARISC_PCREL22F
:
3185 /* If this call should go via the plt, find the import stub in
3188 || sym_sec
->output_section
== NULL
3190 && hh
->eh
.plt
.offset
!= (bfd_vma
) -1
3191 && hh
->eh
.dynindx
!= -1
3194 || !hh
->eh
.def_regular
3195 || hh
->eh
.root
.type
== bfd_link_hash_defweak
)))
3197 hsh
= hppa_get_stub_entry (input_section
, sym_sec
,
3201 value
= (hsh
->stub_offset
3202 + hsh
->stub_sec
->output_offset
3203 + hsh
->stub_sec
->output_section
->vma
);
3206 else if (sym_sec
== NULL
&& hh
!= NULL
3207 && hh
->eh
.root
.type
== bfd_link_hash_undefweak
)
3209 /* It's OK if undefined weak. Calls to undefined weak
3210 symbols behave as if the "called" function
3211 immediately returns. We can thus call to a weak
3212 function without first checking whether the function
3218 return bfd_reloc_undefined
;
3222 case R_PARISC_PCREL21L
:
3223 case R_PARISC_PCREL17C
:
3224 case R_PARISC_PCREL17R
:
3225 case R_PARISC_PCREL14R
:
3226 case R_PARISC_PCREL14F
:
3227 case R_PARISC_PCREL32
:
3228 /* Make it a pc relative offset. */
3233 case R_PARISC_DPREL21L
:
3234 case R_PARISC_DPREL14R
:
3235 case R_PARISC_DPREL14F
:
3236 /* Convert instructions that use the linkage table pointer (r19) to
3237 instructions that use the global data pointer (dp). This is the
3238 most efficient way of using PIC code in an incomplete executable,
3239 but the user must follow the standard runtime conventions for
3240 accessing data for this to work. */
3241 if (orig_r_type
== R_PARISC_DLTIND21L
)
3243 /* Convert addil instructions if the original reloc was a
3244 DLTIND21L. GCC sometimes uses a register other than r19 for
3245 the operation, so we must convert any addil instruction
3246 that uses this relocation. */
3247 if ((insn
& 0xfc000000) == ((int) OP_ADDIL
<< 26))
3250 /* We must have a ldil instruction. It's too hard to find
3251 and convert the associated add instruction, so issue an
3253 (*_bfd_error_handler
)
3254 (_("%B(%A+0x%lx): %s fixup for insn 0x%x is not supported in a non-shared link"),
3261 else if (orig_r_type
== R_PARISC_DLTIND14F
)
3263 /* This must be a format 1 load/store. Change the base
3265 insn
= (insn
& 0xfc1ffff) | (27 << 21);
3268 /* For all the DP relative relocations, we need to examine the symbol's
3269 section. If it has no section or if it's a code section, then
3270 "data pointer relative" makes no sense. In that case we don't
3271 adjust the "value", and for 21 bit addil instructions, we change the
3272 source addend register from %dp to %r0. This situation commonly
3273 arises for undefined weak symbols and when a variable's "constness"
3274 is declared differently from the way the variable is defined. For
3275 instance: "extern int foo" with foo defined as "const int foo". */
3276 if (sym_sec
== NULL
|| (sym_sec
->flags
& SEC_CODE
) != 0)
3278 if ((insn
& ((0x3f << 26) | (0x1f << 21)))
3279 == (((int) OP_ADDIL
<< 26) | (27 << 21)))
3281 insn
&= ~ (0x1f << 21);
3283 /* Now try to make things easy for the dynamic linker. */
3289 case R_PARISC_DLTIND21L
:
3290 case R_PARISC_DLTIND14R
:
3291 case R_PARISC_DLTIND14F
:
3292 value
-= elf_gp (input_section
->output_section
->owner
);
3295 case R_PARISC_SEGREL32
:
3296 if ((sym_sec
->flags
& SEC_CODE
) != 0)
3297 value
-= htab
->text_segment_base
;
3299 value
-= htab
->data_segment_base
;
3308 case R_PARISC_DIR32
:
3309 case R_PARISC_DIR14F
:
3310 case R_PARISC_DIR17F
:
3311 case R_PARISC_PCREL17C
:
3312 case R_PARISC_PCREL14F
:
3313 case R_PARISC_PCREL32
:
3314 case R_PARISC_DPREL14F
:
3315 case R_PARISC_PLABEL32
:
3316 case R_PARISC_DLTIND14F
:
3317 case R_PARISC_SEGBASE
:
3318 case R_PARISC_SEGREL32
:
3322 case R_PARISC_DLTIND21L
:
3323 case R_PARISC_PCREL21L
:
3324 case R_PARISC_PLABEL21L
:
3328 case R_PARISC_DIR21L
:
3329 case R_PARISC_DPREL21L
:
3333 case R_PARISC_PCREL17R
:
3334 case R_PARISC_PCREL14R
:
3335 case R_PARISC_PLABEL14R
:
3336 case R_PARISC_DLTIND14R
:
3340 case R_PARISC_DIR17R
:
3341 case R_PARISC_DIR14R
:
3342 case R_PARISC_DPREL14R
:
3346 case R_PARISC_PCREL12F
:
3347 case R_PARISC_PCREL17F
:
3348 case R_PARISC_PCREL22F
:
3351 if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
3353 max_branch_offset
= (1 << (17-1)) << 2;
3355 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
3357 max_branch_offset
= (1 << (12-1)) << 2;
3361 max_branch_offset
= (1 << (22-1)) << 2;
3364 /* sym_sec is NULL on undefined weak syms or when shared on
3365 undefined syms. We've already checked for a stub for the
3366 shared undefined case. */
3367 if (sym_sec
== NULL
)
3370 /* If the branch is out of reach, then redirect the
3371 call to the local stub for this function. */
3372 if (value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3374 hsh
= hppa_get_stub_entry (input_section
, sym_sec
,
3377 return bfd_reloc_undefined
;
3379 /* Munge up the value and addend so that we call the stub
3380 rather than the procedure directly. */
3381 value
= (hsh
->stub_offset
3382 + hsh
->stub_sec
->output_offset
3383 + hsh
->stub_sec
->output_section
->vma
3389 /* Something we don't know how to handle. */
3391 return bfd_reloc_notsupported
;
3394 /* Make sure we can reach the stub. */
3395 if (max_branch_offset
!= 0
3396 && value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3398 (*_bfd_error_handler
)
3399 (_("%B(%A+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
3403 hsh
->bh_root
.string
);
3404 bfd_set_error (bfd_error_bad_value
);
3405 return bfd_reloc_notsupported
;
3408 val
= hppa_field_adjust (value
, addend
, r_field
);
3412 case R_PARISC_PCREL12F
:
3413 case R_PARISC_PCREL17C
:
3414 case R_PARISC_PCREL17F
:
3415 case R_PARISC_PCREL17R
:
3416 case R_PARISC_PCREL22F
:
3417 case R_PARISC_DIR17F
:
3418 case R_PARISC_DIR17R
:
3419 /* This is a branch. Divide the offset by four.
3420 Note that we need to decide whether it's a branch or
3421 otherwise by inspecting the reloc. Inspecting insn won't
3422 work as insn might be from a .word directive. */
3430 insn
= hppa_rebuild_insn (insn
, val
, r_format
);
3432 /* Update the instruction word. */
3433 bfd_put_32 (input_bfd
, (bfd_vma
) insn
, hit_data
);
3434 return bfd_reloc_ok
;
3437 /* Relocate an HPPA ELF section. */
3440 elf32_hppa_relocate_section (bfd
*output_bfd
,
3441 struct bfd_link_info
*info
,
3443 asection
*input_section
,
3445 Elf_Internal_Rela
*relocs
,
3446 Elf_Internal_Sym
*local_syms
,
3447 asection
**local_sections
)
3449 bfd_vma
*local_got_offsets
;
3450 struct elf32_hppa_link_hash_table
*htab
;
3451 Elf_Internal_Shdr
*symtab_hdr
;
3452 Elf_Internal_Rela
*rela
;
3453 Elf_Internal_Rela
*relend
;
3455 if (info
->relocatable
)
3458 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3460 htab
= hppa_link_hash_table (info
);
3461 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3464 relend
= relocs
+ input_section
->reloc_count
;
3465 for (; rela
< relend
; rela
++)
3467 unsigned int r_type
;
3468 reloc_howto_type
*howto
;
3469 unsigned int r_symndx
;
3470 struct elf32_hppa_link_hash_entry
*hh
;
3471 Elf_Internal_Sym
*sym
;
3474 bfd_reloc_status_type rstatus
;
3475 const char *sym_name
;
3477 bfd_boolean warned_undef
;
3479 r_type
= ELF32_R_TYPE (rela
->r_info
);
3480 if (r_type
>= (unsigned int) R_PARISC_UNIMPLEMENTED
)
3482 bfd_set_error (bfd_error_bad_value
);
3485 if (r_type
== (unsigned int) R_PARISC_GNU_VTENTRY
3486 || r_type
== (unsigned int) R_PARISC_GNU_VTINHERIT
)
3489 /* This is a final link. */
3490 r_symndx
= ELF32_R_SYM (rela
->r_info
);
3494 warned_undef
= FALSE
;
3495 if (r_symndx
< symtab_hdr
->sh_info
)
3497 /* This is a local symbol, h defaults to NULL. */
3498 sym
= local_syms
+ r_symndx
;
3499 sym_sec
= local_sections
[r_symndx
];
3500 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sym_sec
, rela
);
3504 struct elf_link_hash_entry
*eh
;
3505 bfd_boolean unresolved_reloc
;
3506 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (input_bfd
);
3508 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rela
,
3509 r_symndx
, symtab_hdr
, sym_hashes
,
3510 eh
, sym_sec
, relocation
,
3511 unresolved_reloc
, warned_undef
);
3514 && eh
->root
.type
!= bfd_link_hash_defined
3515 && eh
->root
.type
!= bfd_link_hash_defweak
3516 && eh
->root
.type
!= bfd_link_hash_undefweak
)
3518 if (info
->unresolved_syms_in_objects
== RM_IGNORE
3519 && ELF_ST_VISIBILITY (eh
->other
) == STV_DEFAULT
3520 && eh
->type
== STT_PARISC_MILLI
)
3522 if (! info
->callbacks
->undefined_symbol
3523 (info
, eh
->root
.root
.string
, input_bfd
,
3524 input_section
, rela
->r_offset
, FALSE
))
3526 warned_undef
= TRUE
;
3529 hh
= hppa_elf_hash_entry (eh
);
3532 /* Do any required modifications to the relocation value, and
3533 determine what types of dynamic info we need to output, if
3538 case R_PARISC_DLTIND14F
:
3539 case R_PARISC_DLTIND14R
:
3540 case R_PARISC_DLTIND21L
:
3543 bfd_boolean do_got
= 0;
3545 /* Relocation is to the entry for this symbol in the
3546 global offset table. */
3551 off
= hh
->eh
.got
.offset
;
3552 dyn
= htab
->etab
.dynamic_sections_created
;
3553 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
,
3556 /* If we aren't going to call finish_dynamic_symbol,
3557 then we need to handle initialisation of the .got
3558 entry and create needed relocs here. Since the
3559 offset must always be a multiple of 4, we use the
3560 least significant bit to record whether we have
3561 initialised it already. */
3566 hh
->eh
.got
.offset
|= 1;
3573 /* Local symbol case. */
3574 if (local_got_offsets
== NULL
)
3577 off
= local_got_offsets
[r_symndx
];
3579 /* The offset must always be a multiple of 4. We use
3580 the least significant bit to record whether we have
3581 already generated the necessary reloc. */
3586 local_got_offsets
[r_symndx
] |= 1;
3595 /* Output a dynamic relocation for this GOT entry.
3596 In this case it is relative to the base of the
3597 object because the symbol index is zero. */
3598 Elf_Internal_Rela outrel
;
3600 asection
*sec
= htab
->srelgot
;
3602 outrel
.r_offset
= (off
3603 + htab
->sgot
->output_offset
3604 + htab
->sgot
->output_section
->vma
);
3605 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_DIR32
);
3606 outrel
.r_addend
= relocation
;
3607 loc
= sec
->contents
;
3608 loc
+= sec
->reloc_count
++ * sizeof (Elf32_External_Rela
);
3609 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
3612 bfd_put_32 (output_bfd
, relocation
,
3613 htab
->sgot
->contents
+ off
);
3616 if (off
>= (bfd_vma
) -2)
3619 /* Add the base of the GOT to the relocation value. */
3621 + htab
->sgot
->output_offset
3622 + htab
->sgot
->output_section
->vma
);
3626 case R_PARISC_SEGREL32
:
3627 /* If this is the first SEGREL relocation, then initialize
3628 the segment base values. */
3629 if (htab
->text_segment_base
== (bfd_vma
) -1)
3630 bfd_map_over_sections (output_bfd
, hppa_record_segment_addr
, htab
);
3633 case R_PARISC_PLABEL14R
:
3634 case R_PARISC_PLABEL21L
:
3635 case R_PARISC_PLABEL32
:
3636 if (htab
->etab
.dynamic_sections_created
)
3639 bfd_boolean do_plt
= 0;
3640 /* If we have a global symbol with a PLT slot, then
3641 redirect this relocation to it. */
3644 off
= hh
->eh
.plt
.offset
;
3645 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
->shared
,
3648 /* In a non-shared link, adjust_dynamic_symbols
3649 isn't called for symbols forced local. We
3650 need to write out the plt entry here. */
3655 hh
->eh
.plt
.offset
|= 1;
3662 bfd_vma
*local_plt_offsets
;
3664 if (local_got_offsets
== NULL
)
3667 local_plt_offsets
= local_got_offsets
+ symtab_hdr
->sh_info
;
3668 off
= local_plt_offsets
[r_symndx
];
3670 /* As for the local .got entry case, we use the last
3671 bit to record whether we've already initialised
3672 this local .plt entry. */
3677 local_plt_offsets
[r_symndx
] |= 1;
3686 /* Output a dynamic IPLT relocation for this
3688 Elf_Internal_Rela outrel
;
3690 asection
*s
= htab
->srelplt
;
3692 outrel
.r_offset
= (off
3693 + htab
->splt
->output_offset
3694 + htab
->splt
->output_section
->vma
);
3695 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_IPLT
);
3696 outrel
.r_addend
= relocation
;
3698 loc
+= s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
3699 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
3703 bfd_put_32 (output_bfd
,
3705 htab
->splt
->contents
+ off
);
3706 bfd_put_32 (output_bfd
,
3707 elf_gp (htab
->splt
->output_section
->owner
),
3708 htab
->splt
->contents
+ off
+ 4);
3712 if (off
>= (bfd_vma
) -2)
3715 /* PLABELs contain function pointers. Relocation is to
3716 the entry for the function in the .plt. The magic +2
3717 offset signals to $$dyncall that the function pointer
3718 is in the .plt and thus has a gp pointer too.
3719 Exception: Undefined PLABELs should have a value of
3722 || (hh
->eh
.root
.type
!= bfd_link_hash_undefweak
3723 && hh
->eh
.root
.type
!= bfd_link_hash_undefined
))
3726 + htab
->splt
->output_offset
3727 + htab
->splt
->output_section
->vma
3732 /* Fall through and possibly emit a dynamic relocation. */
3734 case R_PARISC_DIR17F
:
3735 case R_PARISC_DIR17R
:
3736 case R_PARISC_DIR14F
:
3737 case R_PARISC_DIR14R
:
3738 case R_PARISC_DIR21L
:
3739 case R_PARISC_DPREL14F
:
3740 case R_PARISC_DPREL14R
:
3741 case R_PARISC_DPREL21L
:
3742 case R_PARISC_DIR32
:
3743 /* r_symndx will be zero only for relocs against symbols
3744 from removed linkonce sections, or sections discarded by
3747 || (input_section
->flags
& SEC_ALLOC
) == 0)
3750 /* The reloc types handled here and this conditional
3751 expression must match the code in ..check_relocs and
3752 allocate_dynrelocs. ie. We need exactly the same condition
3753 as in ..check_relocs, with some extra conditions (dynindx
3754 test in this case) to cater for relocs removed by
3755 allocate_dynrelocs. If you squint, the non-shared test
3756 here does indeed match the one in ..check_relocs, the
3757 difference being that here we test DEF_DYNAMIC as well as
3758 !DEF_REGULAR. All common syms end up with !DEF_REGULAR,
3759 which is why we can't use just that test here.
3760 Conversely, DEF_DYNAMIC can't be used in check_relocs as
3761 there all files have not been loaded. */
3764 || ELF_ST_VISIBILITY (hh
->eh
.other
) == STV_DEFAULT
3765 || hh
->eh
.root
.type
!= bfd_link_hash_undefweak
)
3766 && (IS_ABSOLUTE_RELOC (r_type
)
3767 || !SYMBOL_CALLS_LOCAL (info
, &hh
->eh
)))
3770 && hh
->eh
.dynindx
!= -1
3771 && !hh
->eh
.non_got_ref
3772 && ((ELIMINATE_COPY_RELOCS
3773 && hh
->eh
.def_dynamic
3774 && !hh
->eh
.def_regular
)
3775 || hh
->eh
.root
.type
== bfd_link_hash_undefweak
3776 || hh
->eh
.root
.type
== bfd_link_hash_undefined
)))
3778 Elf_Internal_Rela outrel
;
3783 /* When generating a shared object, these relocations
3784 are copied into the output file to be resolved at run
3787 outrel
.r_addend
= rela
->r_addend
;
3789 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3791 skip
= (outrel
.r_offset
== (bfd_vma
) -1
3792 || outrel
.r_offset
== (bfd_vma
) -2);
3793 outrel
.r_offset
+= (input_section
->output_offset
3794 + input_section
->output_section
->vma
);
3798 memset (&outrel
, 0, sizeof (outrel
));
3801 && hh
->eh
.dynindx
!= -1
3803 || !IS_ABSOLUTE_RELOC (r_type
)
3806 || !hh
->eh
.def_regular
))
3808 outrel
.r_info
= ELF32_R_INFO (hh
->eh
.dynindx
, r_type
);
3810 else /* It's a local symbol, or one marked to become local. */
3814 /* Add the absolute offset of the symbol. */
3815 outrel
.r_addend
+= relocation
;
3817 /* Global plabels need to be processed by the
3818 dynamic linker so that functions have at most one
3819 fptr. For this reason, we need to differentiate
3820 between global and local plabels, which we do by
3821 providing the function symbol for a global plabel
3822 reloc, and no symbol for local plabels. */
3825 && sym_sec
->output_section
!= NULL
3826 && ! bfd_is_abs_section (sym_sec
))
3828 /* Skip this relocation if the output section has
3830 if (bfd_is_abs_section (sym_sec
->output_section
))
3833 indx
= elf_section_data (sym_sec
->output_section
)->dynindx
;
3834 /* We are turning this relocation into one
3835 against a section symbol, so subtract out the
3836 output section's address but not the offset
3837 of the input section in the output section. */
3838 outrel
.r_addend
-= sym_sec
->output_section
->vma
;
3841 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
3843 sreloc
= elf_section_data (input_section
)->sreloc
;
3847 loc
= sreloc
->contents
;
3848 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
3849 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
3857 rstatus
= final_link_relocate (input_section
, contents
, rela
, relocation
,
3858 htab
, sym_sec
, hh
, info
);
3860 if (rstatus
== bfd_reloc_ok
)
3864 sym_name
= hh
->eh
.root
.root
.string
;
3867 sym_name
= bfd_elf_string_from_elf_section (input_bfd
,
3868 symtab_hdr
->sh_link
,
3870 if (sym_name
== NULL
)
3872 if (*sym_name
== '\0')
3873 sym_name
= bfd_section_name (input_bfd
, sym_sec
);
3876 howto
= elf_hppa_howto_table
+ r_type
;
3878 if (rstatus
== bfd_reloc_undefined
|| rstatus
== bfd_reloc_notsupported
)
3880 if (rstatus
== bfd_reloc_notsupported
|| !warned_undef
)
3882 (*_bfd_error_handler
)
3883 (_("%B(%A+0x%lx): cannot handle %s for %s"),
3886 (long) rela
->r_offset
,
3889 bfd_set_error (bfd_error_bad_value
);
3895 if (!((*info
->callbacks
->reloc_overflow
)
3896 (info
, (hh
? &hh
->eh
.root
: NULL
), sym_name
, howto
->name
,
3897 (bfd_vma
) 0, input_bfd
, input_section
, rela
->r_offset
)))
3905 /* Finish up dynamic symbol handling. We set the contents of various
3906 dynamic sections here. */
3909 elf32_hppa_finish_dynamic_symbol (bfd
*output_bfd
,
3910 struct bfd_link_info
*info
,
3911 struct elf_link_hash_entry
*eh
,
3912 Elf_Internal_Sym
*sym
)
3914 struct elf32_hppa_link_hash_table
*htab
;
3915 Elf_Internal_Rela rela
;
3918 htab
= hppa_link_hash_table (info
);
3920 if (eh
->plt
.offset
!= (bfd_vma
) -1)
3924 if (eh
->plt
.offset
& 1)
3927 /* This symbol has an entry in the procedure linkage table. Set
3930 The format of a plt entry is
3935 if (eh
->root
.type
== bfd_link_hash_defined
3936 || eh
->root
.type
== bfd_link_hash_defweak
)
3938 value
= eh
->root
.u
.def
.value
;
3939 if (eh
->root
.u
.def
.section
->output_section
!= NULL
)
3940 value
+= (eh
->root
.u
.def
.section
->output_offset
3941 + eh
->root
.u
.def
.section
->output_section
->vma
);
3944 /* Create a dynamic IPLT relocation for this entry. */
3945 rela
.r_offset
= (eh
->plt
.offset
3946 + htab
->splt
->output_offset
3947 + htab
->splt
->output_section
->vma
);
3948 if (eh
->dynindx
!= -1)
3950 rela
.r_info
= ELF32_R_INFO (eh
->dynindx
, R_PARISC_IPLT
);
3955 /* This symbol has been marked to become local, and is
3956 used by a plabel so must be kept in the .plt. */
3957 rela
.r_info
= ELF32_R_INFO (0, R_PARISC_IPLT
);
3958 rela
.r_addend
= value
;
3961 loc
= htab
->srelplt
->contents
;
3962 loc
+= htab
->srelplt
->reloc_count
++ * sizeof (Elf32_External_Rela
);
3963 bfd_elf32_swap_reloca_out (htab
->splt
->output_section
->owner
, &rela
, loc
);
3965 if (!eh
->def_regular
)
3967 /* Mark the symbol as undefined, rather than as defined in
3968 the .plt section. Leave the value alone. */
3969 sym
->st_shndx
= SHN_UNDEF
;
3973 if (eh
->got
.offset
!= (bfd_vma
) -1)
3975 /* This symbol has an entry in the global offset table. Set it
3978 rela
.r_offset
= ((eh
->got
.offset
&~ (bfd_vma
) 1)
3979 + htab
->sgot
->output_offset
3980 + htab
->sgot
->output_section
->vma
);
3982 /* If this is a -Bsymbolic link and the symbol is defined
3983 locally or was forced to be local because of a version file,
3984 we just want to emit a RELATIVE reloc. The entry in the
3985 global offset table will already have been initialized in the
3986 relocate_section function. */
3988 && (info
->symbolic
|| eh
->dynindx
== -1)
3991 rela
.r_info
= ELF32_R_INFO (0, R_PARISC_DIR32
);
3992 rela
.r_addend
= (eh
->root
.u
.def
.value
3993 + eh
->root
.u
.def
.section
->output_offset
3994 + eh
->root
.u
.def
.section
->output_section
->vma
);
3998 if ((eh
->got
.offset
& 1) != 0)
4001 bfd_put_32 (output_bfd
, 0, htab
->sgot
->contents
+ (eh
->got
.offset
& ~1));
4002 rela
.r_info
= ELF32_R_INFO (eh
->dynindx
, R_PARISC_DIR32
);
4006 loc
= htab
->srelgot
->contents
;
4007 loc
+= htab
->srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4008 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4015 /* This symbol needs a copy reloc. Set it up. */
4017 if (! (eh
->dynindx
!= -1
4018 && (eh
->root
.type
== bfd_link_hash_defined
4019 || eh
->root
.type
== bfd_link_hash_defweak
)))
4022 sec
= htab
->srelbss
;
4024 rela
.r_offset
= (eh
->root
.u
.def
.value
4025 + eh
->root
.u
.def
.section
->output_offset
4026 + eh
->root
.u
.def
.section
->output_section
->vma
);
4028 rela
.r_info
= ELF32_R_INFO (eh
->dynindx
, R_PARISC_COPY
);
4029 loc
= sec
->contents
+ sec
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4030 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4033 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
4034 if (eh
->root
.root
.string
[0] == '_'
4035 && (strcmp (eh
->root
.root
.string
, "_DYNAMIC") == 0
4036 || strcmp (eh
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0))
4038 sym
->st_shndx
= SHN_ABS
;
4044 /* Used to decide how to sort relocs in an optimal manner for the
4045 dynamic linker, before writing them out. */
4047 static enum elf_reloc_type_class
4048 elf32_hppa_reloc_type_class (const Elf_Internal_Rela
*rela
)
4050 if (ELF32_R_SYM (rela
->r_info
) == 0)
4051 return reloc_class_relative
;
4053 switch ((int) ELF32_R_TYPE (rela
->r_info
))
4056 return reloc_class_plt
;
4058 return reloc_class_copy
;
4060 return reloc_class_normal
;
4064 /* Finish up the dynamic sections. */
4067 elf32_hppa_finish_dynamic_sections (bfd
*output_bfd
,
4068 struct bfd_link_info
*info
)
4071 struct elf32_hppa_link_hash_table
*htab
;
4074 htab
= hppa_link_hash_table (info
);
4075 dynobj
= htab
->etab
.dynobj
;
4077 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4079 if (htab
->etab
.dynamic_sections_created
)
4081 Elf32_External_Dyn
*dyncon
, *dynconend
;
4086 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4087 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4088 for (; dyncon
< dynconend
; dyncon
++)
4090 Elf_Internal_Dyn dyn
;
4093 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4101 /* Use PLTGOT to set the GOT register. */
4102 dyn
.d_un
.d_ptr
= elf_gp (output_bfd
);
4107 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4112 dyn
.d_un
.d_val
= s
->size
;
4116 /* Don't count procedure linkage table relocs in the
4117 overall reloc count. */
4121 dyn
.d_un
.d_val
-= s
->size
;
4125 /* We may not be using the standard ELF linker script.
4126 If .rela.plt is the first .rela section, we adjust
4127 DT_RELA to not include it. */
4131 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
4133 dyn
.d_un
.d_ptr
+= s
->size
;
4137 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4141 if (htab
->sgot
!= NULL
&& htab
->sgot
->size
!= 0)
4143 /* Fill in the first entry in the global offset table.
4144 We use it to point to our dynamic section, if we have one. */
4145 bfd_put_32 (output_bfd
,
4146 sdyn
? sdyn
->output_section
->vma
+ sdyn
->output_offset
: 0,
4147 htab
->sgot
->contents
);
4149 /* The second entry is reserved for use by the dynamic linker. */
4150 memset (htab
->sgot
->contents
+ GOT_ENTRY_SIZE
, 0, GOT_ENTRY_SIZE
);
4152 /* Set .got entry size. */
4153 elf_section_data (htab
->sgot
->output_section
)
4154 ->this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
4157 if (htab
->splt
!= NULL
&& htab
->splt
->size
!= 0)
4159 /* Set plt entry size. */
4160 elf_section_data (htab
->splt
->output_section
)
4161 ->this_hdr
.sh_entsize
= PLT_ENTRY_SIZE
;
4163 if (htab
->need_plt_stub
)
4165 /* Set up the .plt stub. */
4166 memcpy (htab
->splt
->contents
4167 + htab
->splt
->size
- sizeof (plt_stub
),
4168 plt_stub
, sizeof (plt_stub
));
4170 if ((htab
->splt
->output_offset
4171 + htab
->splt
->output_section
->vma
4173 != (htab
->sgot
->output_offset
4174 + htab
->sgot
->output_section
->vma
))
4176 (*_bfd_error_handler
)
4177 (_(".got section not immediately after .plt section"));
4186 /* Tweak the OSABI field of the elf header. */
4189 elf32_hppa_post_process_headers (bfd
*abfd
,
4190 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
4192 Elf_Internal_Ehdr
* i_ehdrp
;
4194 i_ehdrp
= elf_elfheader (abfd
);
4196 if (strcmp (bfd_get_target (abfd
), "elf32-hppa-linux") == 0)
4198 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_LINUX
;
4200 else if (strcmp (bfd_get_target (abfd
), "elf32-hppa-netbsd") == 0)
4202 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_NETBSD
;
4206 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_HPUX
;
4210 /* Called when writing out an object file to decide the type of a
4213 elf32_hppa_elf_get_symbol_type (Elf_Internal_Sym
*elf_sym
, int type
)
4215 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_PARISC_MILLI
)
4216 return STT_PARISC_MILLI
;
4221 /* Misc BFD support code. */
4222 #define bfd_elf32_bfd_is_local_label_name elf_hppa_is_local_label_name
4223 #define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
4224 #define elf_info_to_howto elf_hppa_info_to_howto
4225 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
4227 /* Stuff for the BFD linker. */
4228 #define bfd_elf32_bfd_final_link elf32_hppa_final_link
4229 #define bfd_elf32_bfd_link_hash_table_create elf32_hppa_link_hash_table_create
4230 #define bfd_elf32_bfd_link_hash_table_free elf32_hppa_link_hash_table_free
4231 #define elf_backend_adjust_dynamic_symbol elf32_hppa_adjust_dynamic_symbol
4232 #define elf_backend_copy_indirect_symbol elf32_hppa_copy_indirect_symbol
4233 #define elf_backend_check_relocs elf32_hppa_check_relocs
4234 #define elf_backend_create_dynamic_sections elf32_hppa_create_dynamic_sections
4235 #define elf_backend_fake_sections elf_hppa_fake_sections
4236 #define elf_backend_relocate_section elf32_hppa_relocate_section
4237 #define elf_backend_hide_symbol elf32_hppa_hide_symbol
4238 #define elf_backend_finish_dynamic_symbol elf32_hppa_finish_dynamic_symbol
4239 #define elf_backend_finish_dynamic_sections elf32_hppa_finish_dynamic_sections
4240 #define elf_backend_size_dynamic_sections elf32_hppa_size_dynamic_sections
4241 #define elf_backend_gc_mark_hook elf32_hppa_gc_mark_hook
4242 #define elf_backend_gc_sweep_hook elf32_hppa_gc_sweep_hook
4243 #define elf_backend_grok_prstatus elf32_hppa_grok_prstatus
4244 #define elf_backend_grok_psinfo elf32_hppa_grok_psinfo
4245 #define elf_backend_object_p elf32_hppa_object_p
4246 #define elf_backend_final_write_processing elf_hppa_final_write_processing
4247 #define elf_backend_post_process_headers elf32_hppa_post_process_headers
4248 #define elf_backend_get_symbol_type elf32_hppa_elf_get_symbol_type
4249 #define elf_backend_reloc_type_class elf32_hppa_reloc_type_class
4251 #define elf_backend_can_gc_sections 1
4252 #define elf_backend_can_refcount 1
4253 #define elf_backend_plt_alignment 2
4254 #define elf_backend_want_got_plt 0
4255 #define elf_backend_plt_readonly 0
4256 #define elf_backend_want_plt_sym 0
4257 #define elf_backend_got_header_size 8
4258 #define elf_backend_rela_normal 1
4260 #define TARGET_BIG_SYM bfd_elf32_hppa_vec
4261 #define TARGET_BIG_NAME "elf32-hppa"
4262 #define ELF_ARCH bfd_arch_hppa
4263 #define ELF_MACHINE_CODE EM_PARISC
4264 #define ELF_MAXPAGESIZE 0x1000
4266 #include "elf32-target.h"
4268 #undef TARGET_BIG_SYM
4269 #define TARGET_BIG_SYM bfd_elf32_hppa_linux_vec
4270 #undef TARGET_BIG_NAME
4271 #define TARGET_BIG_NAME "elf32-hppa-linux"
4273 #define INCLUDED_TARGET_FILE 1
4274 #include "elf32-target.h"
4276 #undef TARGET_BIG_SYM
4277 #define TARGET_BIG_SYM bfd_elf32_hppa_nbsd_vec
4278 #undef TARGET_BIG_NAME
4279 #define TARGET_BIG_NAME "elf32-hppa-netbsd"
4281 #include "elf32-target.h"