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 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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. */
116 #define PLT_ENTRY_SIZE 8
117 #define GOT_ENTRY_SIZE 4
118 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
120 static const bfd_byte plt_stub
[] =
122 0x0e, 0x80, 0x10, 0x96, /* 1: ldw 0(%r20),%r22 */
123 0xea, 0xc0, 0xc0, 0x00, /* bv %r0(%r22) */
124 0x0e, 0x88, 0x10, 0x95, /* ldw 4(%r20),%r21 */
125 #define PLT_STUB_ENTRY (3*4)
126 0xea, 0x9f, 0x1f, 0xdd, /* b,l 1b,%r20 */
127 0xd6, 0x80, 0x1c, 0x1e, /* depi 0,31,2,%r20 */
128 0x00, 0xc0, 0xff, 0xee, /* 9: .word fixup_func */
129 0xde, 0xad, 0xbe, 0xef /* .word fixup_ltp */
132 /* Section name for stubs is the associated section name plus this
134 #define STUB_SUFFIX ".stub"
136 /* We don't need to copy certain PC- or GP-relative dynamic relocs
137 into a shared object's dynamic section. All the relocs of the
138 limited class we are interested in, are absolute. */
139 #ifndef RELATIVE_DYNRELOCS
140 #define RELATIVE_DYNRELOCS 0
141 #define IS_ABSOLUTE_RELOC(r_type) 1
144 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
145 copying dynamic variables from a shared lib into an app's dynbss
146 section, and instead use a dynamic relocation to point into the
148 #define ELIMINATE_COPY_RELOCS 1
150 enum elf32_hppa_stub_type
{
151 hppa_stub_long_branch
,
152 hppa_stub_long_branch_shared
,
154 hppa_stub_import_shared
,
159 struct elf32_hppa_stub_hash_entry
{
161 /* Base hash table entry structure. */
162 struct bfd_hash_entry root
;
164 /* The stub section. */
167 /* Offset within stub_sec of the beginning of this stub. */
170 /* Given the symbol's value and its section we can determine its final
171 value when building the stubs (so the stub knows where to jump. */
172 bfd_vma target_value
;
173 asection
*target_section
;
175 enum elf32_hppa_stub_type stub_type
;
177 /* The symbol table entry, if any, that this was derived from. */
178 struct elf32_hppa_link_hash_entry
*h
;
180 /* Where this stub is being called from, or, in the case of combined
181 stub sections, the first input section in the group. */
185 struct elf32_hppa_link_hash_entry
{
187 struct elf_link_hash_entry elf
;
189 /* A pointer to the most recently used stub hash entry against this
191 struct elf32_hppa_stub_hash_entry
*stub_cache
;
193 /* Used to count relocations for delayed sizing of relocation
195 struct elf32_hppa_dyn_reloc_entry
{
197 /* Next relocation in the chain. */
198 struct elf32_hppa_dyn_reloc_entry
*next
;
200 /* The input section of the reloc. */
203 /* Number of relocs copied in this section. */
206 #if RELATIVE_DYNRELOCS
207 /* Number of relative relocs copied for the input section. */
208 bfd_size_type relative_count
;
212 /* Set if this symbol is used by a plabel reloc. */
213 unsigned int plabel
:1;
216 struct elf32_hppa_link_hash_table
{
218 /* The main hash table. */
219 struct elf_link_hash_table elf
;
221 /* The stub hash table. */
222 struct bfd_hash_table stub_hash_table
;
224 /* Linker stub bfd. */
227 /* Linker call-backs. */
228 asection
* (*add_stub_section
) (const char *, asection
*);
229 void (*layout_sections_again
) (void);
231 /* Array to keep track of which stub sections have been created, and
232 information on stub grouping. */
234 /* This is the section to which stubs in the group will be
237 /* The stub section. */
241 /* Assorted information used by elf32_hppa_size_stubs. */
242 unsigned int bfd_count
;
244 asection
**input_list
;
245 Elf_Internal_Sym
**all_local_syms
;
247 /* Short-cuts to get to dynamic linker sections. */
255 /* Used during a final link to store the base of the text and data
256 segments so that we can perform SEGREL relocations. */
257 bfd_vma text_segment_base
;
258 bfd_vma data_segment_base
;
260 /* Whether we support multiple sub-spaces for shared libs. */
261 unsigned int multi_subspace
:1;
263 /* Flags set when various size branches are detected. Used to
264 select suitable defaults for the stub group size. */
265 unsigned int has_12bit_branch
:1;
266 unsigned int has_17bit_branch
:1;
267 unsigned int has_22bit_branch
:1;
269 /* Set if we need a .plt stub to support lazy dynamic linking. */
270 unsigned int need_plt_stub
:1;
272 /* Small local sym to section mapping cache. */
273 struct sym_sec_cache sym_sec
;
276 /* Various hash macros and functions. */
277 #define hppa_link_hash_table(p) \
278 ((struct elf32_hppa_link_hash_table *) ((p)->hash))
280 #define hppa_stub_hash_lookup(table, string, create, copy) \
281 ((struct elf32_hppa_stub_hash_entry *) \
282 bfd_hash_lookup ((table), (string), (create), (copy)))
284 /* Assorted hash table functions. */
286 /* Initialize an entry in the stub hash table. */
288 static struct bfd_hash_entry
*
289 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
290 struct bfd_hash_table
*table
,
293 /* Allocate the structure if it has not already been allocated by a
297 entry
= bfd_hash_allocate (table
,
298 sizeof (struct elf32_hppa_stub_hash_entry
));
303 /* Call the allocation method of the superclass. */
304 entry
= bfd_hash_newfunc (entry
, table
, string
);
307 struct elf32_hppa_stub_hash_entry
*eh
;
309 /* Initialize the local fields. */
310 eh
= (struct elf32_hppa_stub_hash_entry
*) entry
;
313 eh
->target_value
= 0;
314 eh
->target_section
= NULL
;
315 eh
->stub_type
= hppa_stub_long_branch
;
323 /* Initialize an entry in the link hash table. */
325 static struct bfd_hash_entry
*
326 hppa_link_hash_newfunc (struct bfd_hash_entry
*entry
,
327 struct bfd_hash_table
*table
,
330 /* Allocate the structure if it has not already been allocated by a
334 entry
= bfd_hash_allocate (table
,
335 sizeof (struct elf32_hppa_link_hash_entry
));
340 /* Call the allocation method of the superclass. */
341 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
344 struct elf32_hppa_link_hash_entry
*eh
;
346 /* Initialize the local fields. */
347 eh
= (struct elf32_hppa_link_hash_entry
*) entry
;
348 eh
->stub_cache
= NULL
;
349 eh
->dyn_relocs
= NULL
;
356 /* Create the derived linker hash table. The PA ELF port uses the derived
357 hash table to keep information specific to the PA ELF linker (without
358 using static variables). */
360 static struct bfd_link_hash_table
*
361 elf32_hppa_link_hash_table_create (bfd
*abfd
)
363 struct elf32_hppa_link_hash_table
*ret
;
364 bfd_size_type amt
= sizeof (*ret
);
366 ret
= bfd_malloc (amt
);
370 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
, hppa_link_hash_newfunc
))
376 /* Init the stub hash table too. */
377 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
))
380 ret
->stub_bfd
= NULL
;
381 ret
->add_stub_section
= NULL
;
382 ret
->layout_sections_again
= NULL
;
383 ret
->stub_group
= NULL
;
390 ret
->text_segment_base
= (bfd_vma
) -1;
391 ret
->data_segment_base
= (bfd_vma
) -1;
392 ret
->multi_subspace
= 0;
393 ret
->has_12bit_branch
= 0;
394 ret
->has_17bit_branch
= 0;
395 ret
->has_22bit_branch
= 0;
396 ret
->need_plt_stub
= 0;
397 ret
->sym_sec
.abfd
= NULL
;
399 return &ret
->elf
.root
;
402 /* Free the derived linker hash table. */
405 elf32_hppa_link_hash_table_free (struct bfd_link_hash_table
*hash
)
407 struct elf32_hppa_link_hash_table
*ret
408 = (struct elf32_hppa_link_hash_table
*) hash
;
410 bfd_hash_table_free (&ret
->stub_hash_table
);
411 _bfd_generic_link_hash_table_free (hash
);
414 /* Build a name for an entry in the stub hash table. */
417 hppa_stub_name (const asection
*input_section
,
418 const asection
*sym_sec
,
419 const struct elf32_hppa_link_hash_entry
*hash
,
420 const Elf_Internal_Rela
*rel
)
427 len
= 8 + 1 + strlen (hash
->elf
.root
.root
.string
) + 1 + 8 + 1;
428 stub_name
= bfd_malloc (len
);
429 if (stub_name
!= NULL
)
431 sprintf (stub_name
, "%08x_%s+%x",
432 input_section
->id
& 0xffffffff,
433 hash
->elf
.root
.root
.string
,
434 (int) rel
->r_addend
& 0xffffffff);
439 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
440 stub_name
= bfd_malloc (len
);
441 if (stub_name
!= NULL
)
443 sprintf (stub_name
, "%08x_%x:%x+%x",
444 input_section
->id
& 0xffffffff,
445 sym_sec
->id
& 0xffffffff,
446 (int) ELF32_R_SYM (rel
->r_info
) & 0xffffffff,
447 (int) rel
->r_addend
& 0xffffffff);
453 /* Look up an entry in the stub hash. Stub entries are cached because
454 creating the stub name takes a bit of time. */
456 static struct elf32_hppa_stub_hash_entry
*
457 hppa_get_stub_entry (const asection
*input_section
,
458 const asection
*sym_sec
,
459 struct elf32_hppa_link_hash_entry
*hash
,
460 const Elf_Internal_Rela
*rel
,
461 struct elf32_hppa_link_hash_table
*htab
)
463 struct elf32_hppa_stub_hash_entry
*stub_entry
;
464 const asection
*id_sec
;
466 /* If this input section is part of a group of sections sharing one
467 stub section, then use the id of the first section in the group.
468 Stub names need to include a section id, as there may well be
469 more than one stub used to reach say, printf, and we need to
470 distinguish between them. */
471 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
473 if (hash
!= NULL
&& hash
->stub_cache
!= NULL
474 && hash
->stub_cache
->h
== hash
475 && hash
->stub_cache
->id_sec
== id_sec
)
477 stub_entry
= hash
->stub_cache
;
483 stub_name
= hppa_stub_name (id_sec
, sym_sec
, hash
, rel
);
484 if (stub_name
== NULL
)
487 stub_entry
= hppa_stub_hash_lookup (&htab
->stub_hash_table
,
488 stub_name
, FALSE
, FALSE
);
490 hash
->stub_cache
= stub_entry
;
498 /* Add a new stub entry to the stub hash. Not all fields of the new
499 stub entry are initialised. */
501 static struct elf32_hppa_stub_hash_entry
*
502 hppa_add_stub (const char *stub_name
,
504 struct elf32_hppa_link_hash_table
*htab
)
508 struct elf32_hppa_stub_hash_entry
*stub_entry
;
510 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
511 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
512 if (stub_sec
== NULL
)
514 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
515 if (stub_sec
== NULL
)
521 namelen
= strlen (link_sec
->name
);
522 len
= namelen
+ sizeof (STUB_SUFFIX
);
523 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
527 memcpy (s_name
, link_sec
->name
, namelen
);
528 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
529 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
530 if (stub_sec
== NULL
)
532 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
534 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
537 /* Enter this entry into the linker stub hash table. */
538 stub_entry
= hppa_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
540 if (stub_entry
== NULL
)
542 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
543 bfd_archive_filename (section
->owner
),
548 stub_entry
->stub_sec
= stub_sec
;
549 stub_entry
->stub_offset
= 0;
550 stub_entry
->id_sec
= link_sec
;
554 /* Determine the type of stub needed, if any, for a call. */
556 static enum elf32_hppa_stub_type
557 hppa_type_of_stub (asection
*input_sec
,
558 const Elf_Internal_Rela
*rel
,
559 struct elf32_hppa_link_hash_entry
*hash
,
561 struct bfd_link_info
*info
)
564 bfd_vma branch_offset
;
565 bfd_vma max_branch_offset
;
569 && hash
->elf
.plt
.offset
!= (bfd_vma
) -1
570 && hash
->elf
.dynindx
!= -1
573 || !(hash
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
574 || hash
->elf
.root
.type
== bfd_link_hash_defweak
))
576 /* We need an import stub. Decide between hppa_stub_import
577 and hppa_stub_import_shared later. */
578 return hppa_stub_import
;
581 /* Determine where the call point is. */
582 location
= (input_sec
->output_offset
583 + input_sec
->output_section
->vma
586 branch_offset
= destination
- location
- 8;
587 r_type
= ELF32_R_TYPE (rel
->r_info
);
589 /* Determine if a long branch stub is needed. parisc branch offsets
590 are relative to the second instruction past the branch, ie. +8
591 bytes on from the branch instruction location. The offset is
592 signed and counts in units of 4 bytes. */
593 if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
595 max_branch_offset
= (1 << (17-1)) << 2;
597 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
599 max_branch_offset
= (1 << (12-1)) << 2;
601 else /* R_PARISC_PCREL22F. */
603 max_branch_offset
= (1 << (22-1)) << 2;
606 if (branch_offset
+ max_branch_offset
>= 2*max_branch_offset
)
607 return hppa_stub_long_branch
;
609 return hppa_stub_none
;
612 /* Build one linker stub as defined by the stub hash table entry GEN_ENTRY.
613 IN_ARG contains the link info pointer. */
615 #define LDIL_R1 0x20200000 /* ldil LR'XXX,%r1 */
616 #define BE_SR4_R1 0xe0202002 /* be,n RR'XXX(%sr4,%r1) */
618 #define BL_R1 0xe8200000 /* b,l .+8,%r1 */
619 #define ADDIL_R1 0x28200000 /* addil LR'XXX,%r1,%r1 */
620 #define DEPI_R1 0xd4201c1e /* depi 0,31,2,%r1 */
622 #define ADDIL_DP 0x2b600000 /* addil LR'XXX,%dp,%r1 */
623 #define LDW_R1_R21 0x48350000 /* ldw RR'XXX(%sr0,%r1),%r21 */
624 #define BV_R0_R21 0xeaa0c000 /* bv %r0(%r21) */
625 #define LDW_R1_R19 0x48330000 /* ldw RR'XXX(%sr0,%r1),%r19 */
627 #define ADDIL_R19 0x2a600000 /* addil LR'XXX,%r19,%r1 */
628 #define LDW_R1_DP 0x483b0000 /* ldw RR'XXX(%sr0,%r1),%dp */
630 #define LDSID_R21_R1 0x02a010a1 /* ldsid (%sr0,%r21),%r1 */
631 #define MTSP_R1 0x00011820 /* mtsp %r1,%sr0 */
632 #define BE_SR0_R21 0xe2a00000 /* be 0(%sr0,%r21) */
633 #define STW_RP 0x6bc23fd1 /* stw %rp,-24(%sr0,%sp) */
635 #define BL22_RP 0xe800a002 /* b,l,n XXX,%rp */
636 #define BL_RP 0xe8400002 /* b,l,n XXX,%rp */
637 #define NOP 0x08000240 /* nop */
638 #define LDW_RP 0x4bc23fd1 /* ldw -24(%sr0,%sp),%rp */
639 #define LDSID_RP_R1 0x004010a1 /* ldsid (%sr0,%rp),%r1 */
640 #define BE_SR0_RP 0xe0400002 /* be,n 0(%sr0,%rp) */
647 #define LDW_R1_DLT LDW_R1_R19
649 #define LDW_R1_DLT LDW_R1_DP
653 hppa_build_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
655 struct elf32_hppa_stub_hash_entry
*stub_entry
;
656 struct bfd_link_info
*info
;
657 struct elf32_hppa_link_hash_table
*htab
;
667 /* Massage our args to the form they really have. */
668 stub_entry
= (struct elf32_hppa_stub_hash_entry
*) gen_entry
;
671 htab
= hppa_link_hash_table (info
);
672 stub_sec
= stub_entry
->stub_sec
;
674 /* Make a note of the offset within the stubs for this entry. */
675 stub_entry
->stub_offset
= stub_sec
->_raw_size
;
676 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
678 stub_bfd
= stub_sec
->owner
;
680 switch (stub_entry
->stub_type
)
682 case hppa_stub_long_branch
:
683 /* Create the long branch. A long branch is formed with "ldil"
684 loading the upper bits of the target address into a register,
685 then branching with "be" which adds in the lower bits.
686 The "be" has its delay slot nullified. */
687 sym_value
= (stub_entry
->target_value
688 + stub_entry
->target_section
->output_offset
689 + stub_entry
->target_section
->output_section
->vma
);
691 val
= hppa_field_adjust (sym_value
, 0, e_lrsel
);
692 insn
= hppa_rebuild_insn ((int) LDIL_R1
, val
, 21);
693 bfd_put_32 (stub_bfd
, insn
, loc
);
695 val
= hppa_field_adjust (sym_value
, 0, e_rrsel
) >> 2;
696 insn
= hppa_rebuild_insn ((int) BE_SR4_R1
, val
, 17);
697 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
702 case hppa_stub_long_branch_shared
:
703 /* Branches are relative. This is where we are going to. */
704 sym_value
= (stub_entry
->target_value
705 + stub_entry
->target_section
->output_offset
706 + stub_entry
->target_section
->output_section
->vma
);
708 /* And this is where we are coming from, more or less. */
709 sym_value
-= (stub_entry
->stub_offset
710 + stub_sec
->output_offset
711 + stub_sec
->output_section
->vma
);
713 bfd_put_32 (stub_bfd
, (bfd_vma
) BL_R1
, loc
);
714 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_lrsel
);
715 insn
= hppa_rebuild_insn ((int) ADDIL_R1
, val
, 21);
716 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
718 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_rrsel
) >> 2;
719 insn
= hppa_rebuild_insn ((int) BE_SR4_R1
, val
, 17);
720 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
724 case hppa_stub_import
:
725 case hppa_stub_import_shared
:
726 off
= stub_entry
->h
->elf
.plt
.offset
;
727 if (off
>= (bfd_vma
) -2)
730 off
&= ~ (bfd_vma
) 1;
732 + htab
->splt
->output_offset
733 + htab
->splt
->output_section
->vma
734 - elf_gp (htab
->splt
->output_section
->owner
));
738 if (stub_entry
->stub_type
== hppa_stub_import_shared
)
741 val
= hppa_field_adjust (sym_value
, 0, e_lrsel
),
742 insn
= hppa_rebuild_insn ((int) insn
, val
, 21);
743 bfd_put_32 (stub_bfd
, insn
, loc
);
745 /* It is critical to use lrsel/rrsel here because we are using
746 two different offsets (+0 and +4) from sym_value. If we use
747 lsel/rsel then with unfortunate sym_values we will round
748 sym_value+4 up to the next 2k block leading to a mis-match
749 between the lsel and rsel value. */
750 val
= hppa_field_adjust (sym_value
, 0, e_rrsel
);
751 insn
= hppa_rebuild_insn ((int) LDW_R1_R21
, val
, 14);
752 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
754 if (htab
->multi_subspace
)
756 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 4, e_rrsel
);
757 insn
= hppa_rebuild_insn ((int) LDW_R1_DLT
, val
, 14);
758 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
760 bfd_put_32 (stub_bfd
, (bfd_vma
) LDSID_R21_R1
, loc
+ 12);
761 bfd_put_32 (stub_bfd
, (bfd_vma
) MTSP_R1
, loc
+ 16);
762 bfd_put_32 (stub_bfd
, (bfd_vma
) BE_SR0_R21
, loc
+ 20);
763 bfd_put_32 (stub_bfd
, (bfd_vma
) STW_RP
, loc
+ 24);
769 bfd_put_32 (stub_bfd
, (bfd_vma
) BV_R0_R21
, loc
+ 8);
770 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 4, e_rrsel
);
771 insn
= hppa_rebuild_insn ((int) LDW_R1_DLT
, val
, 14);
772 bfd_put_32 (stub_bfd
, insn
, loc
+ 12);
779 case hppa_stub_export
:
780 /* Branches are relative. This is where we are going to. */
781 sym_value
= (stub_entry
->target_value
782 + stub_entry
->target_section
->output_offset
783 + stub_entry
->target_section
->output_section
->vma
);
785 /* And this is where we are coming from. */
786 sym_value
-= (stub_entry
->stub_offset
787 + stub_sec
->output_offset
788 + stub_sec
->output_section
->vma
);
790 if (sym_value
- 8 + (1 << (17 + 1)) >= (1 << (17 + 2))
791 && (!htab
->has_22bit_branch
792 || sym_value
- 8 + (1 << (22 + 1)) >= (1 << (22 + 2))))
794 (*_bfd_error_handler
)
795 (_("%s(%s+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
796 bfd_archive_filename (stub_entry
->target_section
->owner
),
798 (long) stub_entry
->stub_offset
,
799 stub_entry
->root
.string
);
800 bfd_set_error (bfd_error_bad_value
);
804 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_fsel
) >> 2;
805 if (!htab
->has_22bit_branch
)
806 insn
= hppa_rebuild_insn ((int) BL_RP
, val
, 17);
808 insn
= hppa_rebuild_insn ((int) BL22_RP
, val
, 22);
809 bfd_put_32 (stub_bfd
, insn
, loc
);
811 bfd_put_32 (stub_bfd
, (bfd_vma
) NOP
, loc
+ 4);
812 bfd_put_32 (stub_bfd
, (bfd_vma
) LDW_RP
, loc
+ 8);
813 bfd_put_32 (stub_bfd
, (bfd_vma
) LDSID_RP_R1
, loc
+ 12);
814 bfd_put_32 (stub_bfd
, (bfd_vma
) MTSP_R1
, loc
+ 16);
815 bfd_put_32 (stub_bfd
, (bfd_vma
) BE_SR0_RP
, loc
+ 20);
817 /* Point the function symbol at the stub. */
818 stub_entry
->h
->elf
.root
.u
.def
.section
= stub_sec
;
819 stub_entry
->h
->elf
.root
.u
.def
.value
= stub_sec
->_raw_size
;
829 stub_sec
->_raw_size
+= size
;
854 /* As above, but don't actually build the stub. Just bump offset so
855 we know stub section sizes. */
858 hppa_size_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
860 struct elf32_hppa_stub_hash_entry
*stub_entry
;
861 struct elf32_hppa_link_hash_table
*htab
;
864 /* Massage our args to the form they really have. */
865 stub_entry
= (struct elf32_hppa_stub_hash_entry
*) gen_entry
;
868 if (stub_entry
->stub_type
== hppa_stub_long_branch
)
870 else if (stub_entry
->stub_type
== hppa_stub_long_branch_shared
)
872 else if (stub_entry
->stub_type
== hppa_stub_export
)
874 else /* hppa_stub_import or hppa_stub_import_shared. */
876 if (htab
->multi_subspace
)
882 stub_entry
->stub_sec
->_raw_size
+= size
;
886 /* Return nonzero if ABFD represents an HPPA ELF32 file.
887 Additionally we set the default architecture and machine. */
890 elf32_hppa_object_p (bfd
*abfd
)
892 Elf_Internal_Ehdr
* i_ehdrp
;
895 i_ehdrp
= elf_elfheader (abfd
);
896 if (strcmp (bfd_get_target (abfd
), "elf32-hppa-linux") == 0)
898 /* GCC on hppa-linux produces binaries with OSABI=Linux,
899 but the kernel produces corefiles with OSABI=SysV. */
900 if (i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_LINUX
&&
901 i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_NONE
) /* aka SYSV */
906 if (i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_HPUX
)
910 flags
= i_ehdrp
->e_flags
;
911 switch (flags
& (EF_PARISC_ARCH
| EF_PARISC_WIDE
))
914 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 10);
916 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 11);
918 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 20);
919 case EFA_PARISC_2_0
| EF_PARISC_WIDE
:
920 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 25);
925 /* Create the .plt and .got sections, and set up our hash table
926 short-cuts to various dynamic sections. */
929 elf32_hppa_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
931 struct elf32_hppa_link_hash_table
*htab
;
933 /* Don't try to create the .plt and .got twice. */
934 htab
= hppa_link_hash_table (info
);
935 if (htab
->splt
!= NULL
)
938 /* Call the generic code to do most of the work. */
939 if (! _bfd_elf_create_dynamic_sections (abfd
, info
))
942 htab
->splt
= bfd_get_section_by_name (abfd
, ".plt");
943 htab
->srelplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
945 htab
->sgot
= bfd_get_section_by_name (abfd
, ".got");
946 htab
->srelgot
= bfd_make_section (abfd
, ".rela.got");
947 if (htab
->srelgot
== NULL
948 || ! bfd_set_section_flags (abfd
, htab
->srelgot
,
955 || ! bfd_set_section_alignment (abfd
, htab
->srelgot
, 2))
958 htab
->sdynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
959 htab
->srelbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
964 /* Copy the extra info we tack onto an elf_link_hash_entry. */
967 elf32_hppa_copy_indirect_symbol (const struct elf_backend_data
*bed
,
968 struct elf_link_hash_entry
*dir
,
969 struct elf_link_hash_entry
*ind
)
971 struct elf32_hppa_link_hash_entry
*edir
, *eind
;
973 edir
= (struct elf32_hppa_link_hash_entry
*) dir
;
974 eind
= (struct elf32_hppa_link_hash_entry
*) ind
;
976 if (eind
->dyn_relocs
!= NULL
)
978 if (edir
->dyn_relocs
!= NULL
)
980 struct elf32_hppa_dyn_reloc_entry
**pp
;
981 struct elf32_hppa_dyn_reloc_entry
*p
;
983 if (ind
->root
.type
== bfd_link_hash_indirect
)
986 /* Add reloc counts against the weak sym to the strong sym
987 list. Merge any entries against the same section. */
988 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
990 struct elf32_hppa_dyn_reloc_entry
*q
;
992 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
993 if (q
->sec
== p
->sec
)
995 #if RELATIVE_DYNRELOCS
996 q
->relative_count
+= p
->relative_count
;
998 q
->count
+= p
->count
;
1005 *pp
= edir
->dyn_relocs
;
1008 edir
->dyn_relocs
= eind
->dyn_relocs
;
1009 eind
->dyn_relocs
= NULL
;
1012 if (ELIMINATE_COPY_RELOCS
1013 && ind
->root
.type
!= bfd_link_hash_indirect
1014 && (dir
->elf_link_hash_flags
& ELF_LINK_HASH_DYNAMIC_ADJUSTED
) != 0)
1015 /* If called to transfer flags for a weakdef during processing
1016 of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
1017 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1018 dir
->elf_link_hash_flags
|=
1019 (ind
->elf_link_hash_flags
& (ELF_LINK_HASH_REF_DYNAMIC
1020 | ELF_LINK_HASH_REF_REGULAR
1021 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
));
1023 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
1026 /* Look through the relocs for a section during the first phase, and
1027 calculate needed space in the global offset table, procedure linkage
1028 table, and dynamic reloc sections. At this point we haven't
1029 necessarily read all the input files. */
1032 elf32_hppa_check_relocs (bfd
*abfd
,
1033 struct bfd_link_info
*info
,
1035 const Elf_Internal_Rela
*relocs
)
1037 Elf_Internal_Shdr
*symtab_hdr
;
1038 struct elf_link_hash_entry
**sym_hashes
;
1039 const Elf_Internal_Rela
*rel
;
1040 const Elf_Internal_Rela
*rel_end
;
1041 struct elf32_hppa_link_hash_table
*htab
;
1043 asection
*stubreloc
;
1045 if (info
->relocatable
)
1048 htab
= hppa_link_hash_table (info
);
1049 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1050 sym_hashes
= elf_sym_hashes (abfd
);
1054 rel_end
= relocs
+ sec
->reloc_count
;
1055 for (rel
= relocs
; rel
< rel_end
; rel
++)
1064 unsigned int r_symndx
, r_type
;
1065 struct elf32_hppa_link_hash_entry
*h
;
1068 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1070 if (r_symndx
< symtab_hdr
->sh_info
)
1073 h
= ((struct elf32_hppa_link_hash_entry
*)
1074 sym_hashes
[r_symndx
- symtab_hdr
->sh_info
]);
1076 r_type
= ELF32_R_TYPE (rel
->r_info
);
1080 case R_PARISC_DLTIND14F
:
1081 case R_PARISC_DLTIND14R
:
1082 case R_PARISC_DLTIND21L
:
1083 /* This symbol requires a global offset table entry. */
1084 need_entry
= NEED_GOT
;
1087 case R_PARISC_PLABEL14R
: /* "Official" procedure labels. */
1088 case R_PARISC_PLABEL21L
:
1089 case R_PARISC_PLABEL32
:
1090 /* If the addend is non-zero, we break badly. */
1091 if (rel
->r_addend
!= 0)
1094 /* If we are creating a shared library, then we need to
1095 create a PLT entry for all PLABELs, because PLABELs with
1096 local symbols may be passed via a pointer to another
1097 object. Additionally, output a dynamic relocation
1098 pointing to the PLT entry.
1099 For executables, the original 32-bit ABI allowed two
1100 different styles of PLABELs (function pointers): For
1101 global functions, the PLABEL word points into the .plt
1102 two bytes past a (function address, gp) pair, and for
1103 local functions the PLABEL points directly at the
1104 function. The magic +2 for the first type allows us to
1105 differentiate between the two. As you can imagine, this
1106 is a real pain when it comes to generating code to call
1107 functions indirectly or to compare function pointers.
1108 We avoid the mess by always pointing a PLABEL into the
1109 .plt, even for local functions. */
1110 need_entry
= PLT_PLABEL
| NEED_PLT
| NEED_DYNREL
;
1113 case R_PARISC_PCREL12F
:
1114 htab
->has_12bit_branch
= 1;
1117 case R_PARISC_PCREL17C
:
1118 case R_PARISC_PCREL17F
:
1119 htab
->has_17bit_branch
= 1;
1122 case R_PARISC_PCREL22F
:
1123 htab
->has_22bit_branch
= 1;
1125 /* Function calls might need to go through the .plt, and
1126 might require long branch stubs. */
1129 /* We know local syms won't need a .plt entry, and if
1130 they need a long branch stub we can't guarantee that
1131 we can reach the stub. So just flag an error later
1132 if we're doing a shared link and find we need a long
1138 /* Global symbols will need a .plt entry if they remain
1139 global, and in most cases won't need a long branch
1140 stub. Unfortunately, we have to cater for the case
1141 where a symbol is forced local by versioning, or due
1142 to symbolic linking, and we lose the .plt entry. */
1143 need_entry
= NEED_PLT
;
1144 if (h
->elf
.type
== STT_PARISC_MILLI
)
1149 case R_PARISC_SEGBASE
: /* Used to set segment base. */
1150 case R_PARISC_SEGREL32
: /* Relative reloc, used for unwind. */
1151 case R_PARISC_PCREL14F
: /* PC relative load/store. */
1152 case R_PARISC_PCREL14R
:
1153 case R_PARISC_PCREL17R
: /* External branches. */
1154 case R_PARISC_PCREL21L
: /* As above, and for load/store too. */
1155 /* We don't need to propagate the relocation if linking a
1156 shared object since these are section relative. */
1159 case R_PARISC_DPREL14F
: /* Used for gp rel data load/store. */
1160 case R_PARISC_DPREL14R
:
1161 case R_PARISC_DPREL21L
:
1164 (*_bfd_error_handler
)
1165 (_("%s: relocation %s can not be used when making a shared object; recompile with -fPIC"),
1166 bfd_archive_filename (abfd
),
1167 elf_hppa_howto_table
[r_type
].name
);
1168 bfd_set_error (bfd_error_bad_value
);
1173 case R_PARISC_DIR17F
: /* Used for external branches. */
1174 case R_PARISC_DIR17R
:
1175 case R_PARISC_DIR14F
: /* Used for load/store from absolute locn. */
1176 case R_PARISC_DIR14R
:
1177 case R_PARISC_DIR21L
: /* As above, and for ext branches too. */
1179 /* Help debug shared library creation. Any of the above
1180 relocs can be used in shared libs, but they may cause
1181 pages to become unshared. */
1184 (*_bfd_error_handler
)
1185 (_("%s: relocation %s should not be used when making a shared object; recompile with -fPIC"),
1186 bfd_archive_filename (abfd
),
1187 elf_hppa_howto_table
[r_type
].name
);
1192 case R_PARISC_DIR32
: /* .word relocs. */
1193 /* We may want to output a dynamic relocation later. */
1194 need_entry
= NEED_DYNREL
;
1197 /* This relocation describes the C++ object vtable hierarchy.
1198 Reconstruct it for later use during GC. */
1199 case R_PARISC_GNU_VTINHERIT
:
1200 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
,
1201 &h
->elf
, rel
->r_offset
))
1205 /* This relocation describes which C++ vtable entries are actually
1206 used. Record for later use during GC. */
1207 case R_PARISC_GNU_VTENTRY
:
1208 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
,
1209 &h
->elf
, rel
->r_addend
))
1217 /* Now carry out our orders. */
1218 if (need_entry
& NEED_GOT
)
1220 /* Allocate space for a GOT entry, as well as a dynamic
1221 relocation for this entry. */
1222 if (htab
->sgot
== NULL
)
1224 if (htab
->elf
.dynobj
== NULL
)
1225 htab
->elf
.dynobj
= abfd
;
1226 if (!elf32_hppa_create_dynamic_sections (htab
->elf
.dynobj
, info
))
1232 h
->elf
.got
.refcount
+= 1;
1236 bfd_signed_vma
*local_got_refcounts
;
1238 /* This is a global offset table entry for a local symbol. */
1239 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1240 if (local_got_refcounts
== NULL
)
1244 /* Allocate space for local got offsets and local
1245 plt offsets. Done this way to save polluting
1246 elf_obj_tdata with another target specific
1248 size
= symtab_hdr
->sh_info
;
1249 size
*= 2 * sizeof (bfd_signed_vma
);
1250 local_got_refcounts
= bfd_zalloc (abfd
, size
);
1251 if (local_got_refcounts
== NULL
)
1253 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1255 local_got_refcounts
[r_symndx
] += 1;
1259 if (need_entry
& NEED_PLT
)
1261 /* If we are creating a shared library, and this is a reloc
1262 against a weak symbol or a global symbol in a dynamic
1263 object, then we will be creating an import stub and a
1264 .plt entry for the symbol. Similarly, on a normal link
1265 to symbols defined in a dynamic object we'll need the
1266 import stub and a .plt entry. We don't know yet whether
1267 the symbol is defined or not, so make an entry anyway and
1268 clean up later in adjust_dynamic_symbol. */
1269 if ((sec
->flags
& SEC_ALLOC
) != 0)
1273 h
->elf
.elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1274 h
->elf
.plt
.refcount
+= 1;
1276 /* If this .plt entry is for a plabel, mark it so
1277 that adjust_dynamic_symbol will keep the entry
1278 even if it appears to be local. */
1279 if (need_entry
& PLT_PLABEL
)
1282 else if (need_entry
& PLT_PLABEL
)
1284 bfd_signed_vma
*local_got_refcounts
;
1285 bfd_signed_vma
*local_plt_refcounts
;
1287 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1288 if (local_got_refcounts
== NULL
)
1292 /* Allocate space for local got offsets and local
1294 size
= symtab_hdr
->sh_info
;
1295 size
*= 2 * sizeof (bfd_signed_vma
);
1296 local_got_refcounts
= bfd_zalloc (abfd
, size
);
1297 if (local_got_refcounts
== NULL
)
1299 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1301 local_plt_refcounts
= (local_got_refcounts
1302 + symtab_hdr
->sh_info
);
1303 local_plt_refcounts
[r_symndx
] += 1;
1308 if (need_entry
& NEED_DYNREL
)
1310 /* Flag this symbol as having a non-got, non-plt reference
1311 so that we generate copy relocs if it turns out to be
1313 if (h
!= NULL
&& !info
->shared
)
1314 h
->elf
.elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
1316 /* If we are creating a shared library then we need to copy
1317 the reloc into the shared library. However, if we are
1318 linking with -Bsymbolic, we need only copy absolute
1319 relocs or relocs against symbols that are not defined in
1320 an object we are including in the link. PC- or DP- or
1321 DLT-relative relocs against any local sym or global sym
1322 with DEF_REGULAR set, can be discarded. At this point we
1323 have not seen all the input files, so it is possible that
1324 DEF_REGULAR is not set now but will be set later (it is
1325 never cleared). We account for that possibility below by
1326 storing information in the dyn_relocs field of the
1329 A similar situation to the -Bsymbolic case occurs when
1330 creating shared libraries and symbol visibility changes
1331 render the symbol local.
1333 As it turns out, all the relocs we will be creating here
1334 are absolute, so we cannot remove them on -Bsymbolic
1335 links or visibility changes anyway. A STUB_REL reloc
1336 is absolute too, as in that case it is the reloc in the
1337 stub we will be creating, rather than copying the PCREL
1338 reloc in the branch.
1340 If on the other hand, we are creating an executable, we
1341 may need to keep relocations for symbols satisfied by a
1342 dynamic library if we manage to avoid copy relocs for the
1345 && (sec
->flags
& SEC_ALLOC
) != 0
1346 && (IS_ABSOLUTE_RELOC (r_type
)
1349 || h
->elf
.root
.type
== bfd_link_hash_defweak
1350 || (h
->elf
.elf_link_hash_flags
1351 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
1352 || (ELIMINATE_COPY_RELOCS
1354 && (sec
->flags
& SEC_ALLOC
) != 0
1356 && (h
->elf
.root
.type
== bfd_link_hash_defweak
1357 || (h
->elf
.elf_link_hash_flags
1358 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
1360 struct elf32_hppa_dyn_reloc_entry
*p
;
1361 struct elf32_hppa_dyn_reloc_entry
**head
;
1363 /* Create a reloc section in dynobj and make room for
1370 name
= (bfd_elf_string_from_elf_section
1372 elf_elfheader (abfd
)->e_shstrndx
,
1373 elf_section_data (sec
)->rel_hdr
.sh_name
));
1376 (*_bfd_error_handler
)
1377 (_("Could not find relocation section for %s"),
1379 bfd_set_error (bfd_error_bad_value
);
1383 if (htab
->elf
.dynobj
== NULL
)
1384 htab
->elf
.dynobj
= abfd
;
1386 dynobj
= htab
->elf
.dynobj
;
1387 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1392 sreloc
= bfd_make_section (dynobj
, name
);
1393 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
1394 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1395 if ((sec
->flags
& SEC_ALLOC
) != 0)
1396 flags
|= SEC_ALLOC
| SEC_LOAD
;
1398 || !bfd_set_section_flags (dynobj
, sreloc
, flags
)
1399 || !bfd_set_section_alignment (dynobj
, sreloc
, 2))
1403 elf_section_data (sec
)->sreloc
= sreloc
;
1406 /* If this is a global symbol, we count the number of
1407 relocations we need for this symbol. */
1410 head
= &h
->dyn_relocs
;
1414 /* Track dynamic relocs needed for local syms too.
1415 We really need local syms available to do this
1419 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
1424 head
= ((struct elf32_hppa_dyn_reloc_entry
**)
1425 &elf_section_data (s
)->local_dynrel
);
1429 if (p
== NULL
|| p
->sec
!= sec
)
1431 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
1438 #if RELATIVE_DYNRELOCS
1439 p
->relative_count
= 0;
1444 #if RELATIVE_DYNRELOCS
1445 if (!IS_ABSOLUTE_RELOC (rtype
))
1446 p
->relative_count
+= 1;
1455 /* Return the section that should be marked against garbage collection
1456 for a given relocation. */
1459 elf32_hppa_gc_mark_hook (asection
*sec
,
1460 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1461 Elf_Internal_Rela
*rel
,
1462 struct elf_link_hash_entry
*h
,
1463 Elf_Internal_Sym
*sym
)
1467 switch ((unsigned int) ELF32_R_TYPE (rel
->r_info
))
1469 case R_PARISC_GNU_VTINHERIT
:
1470 case R_PARISC_GNU_VTENTRY
:
1474 switch (h
->root
.type
)
1476 case bfd_link_hash_defined
:
1477 case bfd_link_hash_defweak
:
1478 return h
->root
.u
.def
.section
;
1480 case bfd_link_hash_common
:
1481 return h
->root
.u
.c
.p
->section
;
1489 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
1494 /* Update the got and plt entry reference counts for the section being
1498 elf32_hppa_gc_sweep_hook (bfd
*abfd
,
1499 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1501 const Elf_Internal_Rela
*relocs
)
1503 Elf_Internal_Shdr
*symtab_hdr
;
1504 struct elf_link_hash_entry
**sym_hashes
;
1505 bfd_signed_vma
*local_got_refcounts
;
1506 bfd_signed_vma
*local_plt_refcounts
;
1507 const Elf_Internal_Rela
*rel
, *relend
;
1509 elf_section_data (sec
)->local_dynrel
= NULL
;
1511 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1512 sym_hashes
= elf_sym_hashes (abfd
);
1513 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1514 local_plt_refcounts
= local_got_refcounts
;
1515 if (local_plt_refcounts
!= NULL
)
1516 local_plt_refcounts
+= symtab_hdr
->sh_info
;
1518 relend
= relocs
+ sec
->reloc_count
;
1519 for (rel
= relocs
; rel
< relend
; rel
++)
1521 unsigned long r_symndx
;
1522 unsigned int r_type
;
1523 struct elf_link_hash_entry
*h
= NULL
;
1525 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1526 if (r_symndx
>= symtab_hdr
->sh_info
)
1528 struct elf32_hppa_link_hash_entry
*eh
;
1529 struct elf32_hppa_dyn_reloc_entry
**pp
;
1530 struct elf32_hppa_dyn_reloc_entry
*p
;
1532 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1533 eh
= (struct elf32_hppa_link_hash_entry
*) h
;
1535 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
1538 /* Everything must go for SEC. */
1544 r_type
= ELF32_R_TYPE (rel
->r_info
);
1547 case R_PARISC_DLTIND14F
:
1548 case R_PARISC_DLTIND14R
:
1549 case R_PARISC_DLTIND21L
:
1552 if (h
->got
.refcount
> 0)
1553 h
->got
.refcount
-= 1;
1555 else if (local_got_refcounts
!= NULL
)
1557 if (local_got_refcounts
[r_symndx
] > 0)
1558 local_got_refcounts
[r_symndx
] -= 1;
1562 case R_PARISC_PCREL12F
:
1563 case R_PARISC_PCREL17C
:
1564 case R_PARISC_PCREL17F
:
1565 case R_PARISC_PCREL22F
:
1568 if (h
->plt
.refcount
> 0)
1569 h
->plt
.refcount
-= 1;
1573 case R_PARISC_PLABEL14R
:
1574 case R_PARISC_PLABEL21L
:
1575 case R_PARISC_PLABEL32
:
1578 if (h
->plt
.refcount
> 0)
1579 h
->plt
.refcount
-= 1;
1581 else if (local_plt_refcounts
!= NULL
)
1583 if (local_plt_refcounts
[r_symndx
] > 0)
1584 local_plt_refcounts
[r_symndx
] -= 1;
1596 /* Our own version of hide_symbol, so that we can keep plt entries for
1600 elf32_hppa_hide_symbol (struct bfd_link_info
*info
,
1601 struct elf_link_hash_entry
*h
,
1602 bfd_boolean force_local
)
1606 h
->elf_link_hash_flags
|= ELF_LINK_FORCED_LOCAL
;
1607 if (h
->dynindx
!= -1)
1610 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
1615 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
)
1617 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1618 h
->plt
.offset
= (bfd_vma
) -1;
1622 /* This is the condition under which elf32_hppa_finish_dynamic_symbol
1623 will be called from elflink.h. If elflink.h doesn't call our
1624 finish_dynamic_symbol routine, we'll need to do something about
1625 initializing any .plt and .got entries in elf32_hppa_relocate_section. */
1626 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
1628 && ((INFO)->shared \
1629 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
1630 && ((H)->dynindx != -1 \
1631 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
1633 /* Adjust a symbol defined by a dynamic object and referenced by a
1634 regular object. The current definition is in some section of the
1635 dynamic object, but we're not including those sections. We have to
1636 change the definition to something the rest of the link can
1640 elf32_hppa_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1641 struct elf_link_hash_entry
*h
)
1643 struct elf32_hppa_link_hash_table
*htab
;
1645 unsigned int power_of_two
;
1647 /* If this is a function, put it in the procedure linkage table. We
1648 will fill in the contents of the procedure linkage table later. */
1649 if (h
->type
== STT_FUNC
1650 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1652 if (h
->plt
.refcount
<= 0
1653 || ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
1654 && h
->root
.type
!= bfd_link_hash_defweak
1655 && ! ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
1656 && (!info
->shared
|| info
->symbolic
)))
1658 /* The .plt entry is not needed when:
1659 a) Garbage collection has removed all references to the
1661 b) We know for certain the symbol is defined in this
1662 object, and it's not a weak definition, nor is the symbol
1663 used by a plabel relocation. Either this object is the
1664 application or we are doing a shared symbolic link. */
1666 h
->plt
.offset
= (bfd_vma
) -1;
1667 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1673 h
->plt
.offset
= (bfd_vma
) -1;
1675 /* If this is a weak symbol, and there is a real definition, the
1676 processor independent code will have arranged for us to see the
1677 real definition first, and we can just use the same value. */
1678 if (h
->weakdef
!= NULL
)
1680 if (h
->weakdef
->root
.type
!= bfd_link_hash_defined
1681 && h
->weakdef
->root
.type
!= bfd_link_hash_defweak
)
1683 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1684 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1685 if (ELIMINATE_COPY_RELOCS
)
1686 h
->elf_link_hash_flags
1687 = ((h
->elf_link_hash_flags
& ~ELF_LINK_NON_GOT_REF
)
1688 | (h
->weakdef
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
));
1692 /* This is a reference to a symbol defined by a dynamic object which
1693 is not a function. */
1695 /* If we are creating a shared library, we must presume that the
1696 only references to the symbol are via the global offset table.
1697 For such cases we need not do anything here; the relocations will
1698 be handled correctly by relocate_section. */
1702 /* If there are no references to this symbol that do not use the
1703 GOT, we don't need to generate a copy reloc. */
1704 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
1707 if (ELIMINATE_COPY_RELOCS
)
1709 struct elf32_hppa_link_hash_entry
*eh
;
1710 struct elf32_hppa_dyn_reloc_entry
*p
;
1712 eh
= (struct elf32_hppa_link_hash_entry
*) h
;
1713 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1715 s
= p
->sec
->output_section
;
1716 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
1720 /* If we didn't find any dynamic relocs in read-only sections, then
1721 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
1724 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
1729 /* We must allocate the symbol in our .dynbss section, which will
1730 become part of the .bss section of the executable. There will be
1731 an entry for this symbol in the .dynsym section. The dynamic
1732 object will contain position independent code, so all references
1733 from the dynamic object to this symbol will go through the global
1734 offset table. The dynamic linker will use the .dynsym entry to
1735 determine the address it must put in the global offset table, so
1736 both the dynamic object and the regular object will refer to the
1737 same memory location for the variable. */
1739 htab
= hppa_link_hash_table (info
);
1741 /* We must generate a COPY reloc to tell the dynamic linker to
1742 copy the initial value out of the dynamic object and into the
1743 runtime process image. */
1744 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1746 htab
->srelbss
->_raw_size
+= sizeof (Elf32_External_Rela
);
1747 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
1750 /* We need to figure out the alignment required for this symbol. I
1751 have no idea how other ELF linkers handle this. */
1753 power_of_two
= bfd_log2 (h
->size
);
1754 if (power_of_two
> 3)
1757 /* Apply the required alignment. */
1759 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
1760 (bfd_size_type
) (1 << power_of_two
));
1761 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
1763 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
1767 /* Define the symbol as being at this point in the section. */
1768 h
->root
.u
.def
.section
= s
;
1769 h
->root
.u
.def
.value
= s
->_raw_size
;
1771 /* Increment the section size to make room for the symbol. */
1772 s
->_raw_size
+= h
->size
;
1777 /* Allocate space in the .plt for entries that won't have relocations.
1778 ie. plabel entries. */
1781 allocate_plt_static (struct elf_link_hash_entry
*h
, void *inf
)
1783 struct bfd_link_info
*info
;
1784 struct elf32_hppa_link_hash_table
*htab
;
1787 if (h
->root
.type
== bfd_link_hash_indirect
)
1790 if (h
->root
.type
== bfd_link_hash_warning
)
1791 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1794 htab
= hppa_link_hash_table (info
);
1795 if (htab
->elf
.dynamic_sections_created
1796 && h
->plt
.refcount
> 0)
1798 /* Make sure this symbol is output as a dynamic symbol.
1799 Undefined weak syms won't yet be marked as dynamic. */
1800 if (h
->dynindx
== -1
1801 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0
1802 && h
->type
!= STT_PARISC_MILLI
)
1804 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1808 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
, h
))
1810 /* Allocate these later. From this point on, h->plabel
1811 means that the plt entry is only used by a plabel.
1812 We'll be using a normal plt entry for this symbol, so
1813 clear the plabel indicator. */
1814 ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
= 0;
1816 else if (((struct elf32_hppa_link_hash_entry
*) h
)->plabel
)
1818 /* Make an entry in the .plt section for plabel references
1819 that won't have a .plt entry for other reasons. */
1821 h
->plt
.offset
= s
->_raw_size
;
1822 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1826 /* No .plt entry needed. */
1827 h
->plt
.offset
= (bfd_vma
) -1;
1828 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1833 h
->plt
.offset
= (bfd_vma
) -1;
1834 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1840 /* Allocate space in .plt, .got and associated reloc sections for
1844 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
1846 struct bfd_link_info
*info
;
1847 struct elf32_hppa_link_hash_table
*htab
;
1849 struct elf32_hppa_link_hash_entry
*eh
;
1850 struct elf32_hppa_dyn_reloc_entry
*p
;
1852 if (h
->root
.type
== bfd_link_hash_indirect
)
1855 if (h
->root
.type
== bfd_link_hash_warning
)
1856 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1859 htab
= hppa_link_hash_table (info
);
1860 if (htab
->elf
.dynamic_sections_created
1861 && h
->plt
.offset
!= (bfd_vma
) -1
1862 && !((struct elf32_hppa_link_hash_entry
*) h
)->plabel
)
1864 /* Make an entry in the .plt section. */
1866 h
->plt
.offset
= s
->_raw_size
;
1867 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1869 /* We also need to make an entry in the .rela.plt section. */
1870 htab
->srelplt
->_raw_size
+= sizeof (Elf32_External_Rela
);
1871 htab
->need_plt_stub
= 1;
1874 if (h
->got
.refcount
> 0)
1876 /* Make sure this symbol is output as a dynamic symbol.
1877 Undefined weak syms won't yet be marked as dynamic. */
1878 if (h
->dynindx
== -1
1879 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0
1880 && h
->type
!= STT_PARISC_MILLI
)
1882 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1887 h
->got
.offset
= s
->_raw_size
;
1888 s
->_raw_size
+= GOT_ENTRY_SIZE
;
1889 if (htab
->elf
.dynamic_sections_created
1891 || (h
->dynindx
!= -1
1892 && h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0))
1894 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
1898 h
->got
.offset
= (bfd_vma
) -1;
1900 eh
= (struct elf32_hppa_link_hash_entry
*) h
;
1901 if (eh
->dyn_relocs
== NULL
)
1904 /* If this is a -Bsymbolic shared link, then we need to discard all
1905 space allocated for dynamic pc-relative relocs against symbols
1906 defined in a regular object. For the normal shared case, discard
1907 space for relocs that have become local due to symbol visibility
1911 #if RELATIVE_DYNRELOCS
1912 if (SYMBOL_CALLS_LOCAL (info
, h
))
1914 struct elf32_hppa_dyn_reloc_entry
**pp
;
1916 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
1918 p
->count
-= p
->relative_count
;
1919 p
->relative_count
= 0;
1928 /* Also discard relocs on undefined weak syms with non-default
1930 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1931 && h
->root
.type
== bfd_link_hash_undefweak
)
1932 eh
->dyn_relocs
= NULL
;
1936 /* For the non-shared case, discard space for relocs against
1937 symbols which turn out to need copy relocs or are not
1939 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
1940 && ((ELIMINATE_COPY_RELOCS
1941 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
1942 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1943 || (htab
->elf
.dynamic_sections_created
1944 && (h
->root
.type
== bfd_link_hash_undefweak
1945 || h
->root
.type
== bfd_link_hash_undefined
))))
1947 /* Make sure this symbol is output as a dynamic symbol.
1948 Undefined weak syms won't yet be marked as dynamic. */
1949 if (h
->dynindx
== -1
1950 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0
1951 && h
->type
!= STT_PARISC_MILLI
)
1953 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1957 /* If that succeeded, we know we'll be keeping all the
1959 if (h
->dynindx
!= -1)
1963 eh
->dyn_relocs
= NULL
;
1969 /* Finally, allocate space. */
1970 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1972 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
1973 sreloc
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rela
);
1979 /* This function is called via elf_link_hash_traverse to force
1980 millicode symbols local so they do not end up as globals in the
1981 dynamic symbol table. We ought to be able to do this in
1982 adjust_dynamic_symbol, but our adjust_dynamic_symbol is not called
1983 for all dynamic symbols. Arguably, this is a bug in
1984 elf_adjust_dynamic_symbol. */
1987 clobber_millicode_symbols (struct elf_link_hash_entry
*h
,
1988 struct bfd_link_info
*info
)
1990 if (h
->root
.type
== bfd_link_hash_warning
)
1991 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1993 if (h
->type
== STT_PARISC_MILLI
1994 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1996 elf32_hppa_hide_symbol (info
, h
, TRUE
);
2001 /* Find any dynamic relocs that apply to read-only sections. */
2004 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2006 struct elf32_hppa_link_hash_entry
*eh
;
2007 struct elf32_hppa_dyn_reloc_entry
*p
;
2009 if (h
->root
.type
== bfd_link_hash_warning
)
2010 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2012 eh
= (struct elf32_hppa_link_hash_entry
*) h
;
2013 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2015 asection
*s
= p
->sec
->output_section
;
2017 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2019 struct bfd_link_info
*info
= inf
;
2021 info
->flags
|= DF_TEXTREL
;
2023 /* Not an error, just cut short the traversal. */
2030 /* Set the sizes of the dynamic sections. */
2033 elf32_hppa_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2034 struct bfd_link_info
*info
)
2036 struct elf32_hppa_link_hash_table
*htab
;
2042 htab
= hppa_link_hash_table (info
);
2043 dynobj
= htab
->elf
.dynobj
;
2047 if (htab
->elf
.dynamic_sections_created
)
2049 /* Set the contents of the .interp section to the interpreter. */
2050 if (info
->executable
)
2052 s
= bfd_get_section_by_name (dynobj
, ".interp");
2055 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2056 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2059 /* Force millicode symbols local. */
2060 elf_link_hash_traverse (&htab
->elf
,
2061 clobber_millicode_symbols
,
2065 /* Set up .got and .plt offsets for local syms, and space for local
2067 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2069 bfd_signed_vma
*local_got
;
2070 bfd_signed_vma
*end_local_got
;
2071 bfd_signed_vma
*local_plt
;
2072 bfd_signed_vma
*end_local_plt
;
2073 bfd_size_type locsymcount
;
2074 Elf_Internal_Shdr
*symtab_hdr
;
2077 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
2080 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2082 struct elf32_hppa_dyn_reloc_entry
*p
;
2084 for (p
= ((struct elf32_hppa_dyn_reloc_entry
*)
2085 elf_section_data (s
)->local_dynrel
);
2089 if (!bfd_is_abs_section (p
->sec
)
2090 && bfd_is_abs_section (p
->sec
->output_section
))
2092 /* Input section has been discarded, either because
2093 it is a copy of a linkonce section or due to
2094 linker script /DISCARD/, so we'll be discarding
2097 else if (p
->count
!= 0)
2099 srel
= elf_section_data (p
->sec
)->sreloc
;
2100 srel
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rela
);
2101 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
2102 info
->flags
|= DF_TEXTREL
;
2107 local_got
= elf_local_got_refcounts (ibfd
);
2111 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
2112 locsymcount
= symtab_hdr
->sh_info
;
2113 end_local_got
= local_got
+ locsymcount
;
2115 srel
= htab
->srelgot
;
2116 for (; local_got
< end_local_got
; ++local_got
)
2120 *local_got
= s
->_raw_size
;
2121 s
->_raw_size
+= GOT_ENTRY_SIZE
;
2123 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
2126 *local_got
= (bfd_vma
) -1;
2129 local_plt
= end_local_got
;
2130 end_local_plt
= local_plt
+ locsymcount
;
2131 if (! htab
->elf
.dynamic_sections_created
)
2133 /* Won't be used, but be safe. */
2134 for (; local_plt
< end_local_plt
; ++local_plt
)
2135 *local_plt
= (bfd_vma
) -1;
2140 srel
= htab
->srelplt
;
2141 for (; local_plt
< end_local_plt
; ++local_plt
)
2145 *local_plt
= s
->_raw_size
;
2146 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2148 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
2151 *local_plt
= (bfd_vma
) -1;
2156 /* Do all the .plt entries without relocs first. The dynamic linker
2157 uses the last .plt reloc to find the end of the .plt (and hence
2158 the start of the .got) for lazy linking. */
2159 elf_link_hash_traverse (&htab
->elf
, allocate_plt_static
, info
);
2161 /* Allocate global sym .plt and .got entries, and space for global
2162 sym dynamic relocs. */
2163 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, info
);
2165 /* The check_relocs and adjust_dynamic_symbol entry points have
2166 determined the sizes of the various dynamic sections. Allocate
2169 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2171 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2174 if (s
== htab
->splt
)
2176 if (htab
->need_plt_stub
)
2178 /* Make space for the plt stub at the end of the .plt
2179 section. We want this stub right at the end, up
2180 against the .got section. */
2181 int gotalign
= bfd_section_alignment (dynobj
, htab
->sgot
);
2182 int pltalign
= bfd_section_alignment (dynobj
, s
);
2185 if (gotalign
> pltalign
)
2186 bfd_set_section_alignment (dynobj
, s
, gotalign
);
2187 mask
= ((bfd_size_type
) 1 << gotalign
) - 1;
2188 s
->_raw_size
= (s
->_raw_size
+ sizeof (plt_stub
) + mask
) & ~mask
;
2191 else if (s
== htab
->sgot
)
2193 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
2195 if (s
->_raw_size
!= 0)
2197 /* Remember whether there are any reloc sections other
2199 if (s
!= htab
->srelplt
)
2202 /* We use the reloc_count field as a counter if we need
2203 to copy relocs into the output file. */
2209 /* It's not one of our sections, so don't allocate space. */
2213 if (s
->_raw_size
== 0)
2215 /* If we don't need this section, strip it from the
2216 output file. This is mostly to handle .rela.bss and
2217 .rela.plt. We must create both sections in
2218 create_dynamic_sections, because they must be created
2219 before the linker maps input sections to output
2220 sections. The linker does that before
2221 adjust_dynamic_symbol is called, and it is that
2222 function which decides whether anything needs to go
2223 into these sections. */
2224 _bfd_strip_section_from_output (info
, s
);
2228 /* Allocate memory for the section contents. Zero it, because
2229 we may not fill in all the reloc sections. */
2230 s
->contents
= bfd_zalloc (dynobj
, s
->_raw_size
);
2231 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
2235 if (htab
->elf
.dynamic_sections_created
)
2237 /* Like IA-64 and HPPA64, always create a DT_PLTGOT. It
2238 actually has nothing to do with the PLT, it is how we
2239 communicate the LTP value of a load module to the dynamic
2241 #define add_dynamic_entry(TAG, VAL) \
2242 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
2244 if (!add_dynamic_entry (DT_PLTGOT
, 0))
2247 /* Add some entries to the .dynamic section. We fill in the
2248 values later, in elf32_hppa_finish_dynamic_sections, but we
2249 must add the entries now so that we get the correct size for
2250 the .dynamic section. The DT_DEBUG entry is filled in by the
2251 dynamic linker and used by the debugger. */
2254 if (!add_dynamic_entry (DT_DEBUG
, 0))
2258 if (htab
->srelplt
->_raw_size
!= 0)
2260 if (!add_dynamic_entry (DT_PLTRELSZ
, 0)
2261 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
2262 || !add_dynamic_entry (DT_JMPREL
, 0))
2268 if (!add_dynamic_entry (DT_RELA
, 0)
2269 || !add_dynamic_entry (DT_RELASZ
, 0)
2270 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
2273 /* If any dynamic relocs apply to a read-only section,
2274 then we need a DT_TEXTREL entry. */
2275 if ((info
->flags
& DF_TEXTREL
) == 0)
2276 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
, info
);
2278 if ((info
->flags
& DF_TEXTREL
) != 0)
2280 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2285 #undef add_dynamic_entry
2290 /* External entry points for sizing and building linker stubs. */
2292 /* Set up various things so that we can make a list of input sections
2293 for each output section included in the link. Returns -1 on error,
2294 0 when no stubs will be needed, and 1 on success. */
2297 elf32_hppa_setup_section_lists (bfd
*output_bfd
, struct bfd_link_info
*info
)
2300 unsigned int bfd_count
;
2301 int top_id
, top_index
;
2303 asection
**input_list
, **list
;
2305 struct elf32_hppa_link_hash_table
*htab
= hppa_link_hash_table (info
);
2307 if (htab
->elf
.root
.creator
->flavour
!= bfd_target_elf_flavour
)
2310 /* Count the number of input BFDs and find the top input section id. */
2311 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
2313 input_bfd
= input_bfd
->link_next
)
2316 for (section
= input_bfd
->sections
;
2318 section
= section
->next
)
2320 if (top_id
< section
->id
)
2321 top_id
= section
->id
;
2324 htab
->bfd_count
= bfd_count
;
2326 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
2327 htab
->stub_group
= bfd_zmalloc (amt
);
2328 if (htab
->stub_group
== NULL
)
2331 /* We can't use output_bfd->section_count here to find the top output
2332 section index as some sections may have been removed, and
2333 _bfd_strip_section_from_output doesn't renumber the indices. */
2334 for (section
= output_bfd
->sections
, top_index
= 0;
2336 section
= section
->next
)
2338 if (top_index
< section
->index
)
2339 top_index
= section
->index
;
2342 htab
->top_index
= top_index
;
2343 amt
= sizeof (asection
*) * (top_index
+ 1);
2344 input_list
= bfd_malloc (amt
);
2345 htab
->input_list
= input_list
;
2346 if (input_list
== NULL
)
2349 /* For sections we aren't interested in, mark their entries with a
2350 value we can check later. */
2351 list
= input_list
+ top_index
;
2353 *list
= bfd_abs_section_ptr
;
2354 while (list
-- != input_list
);
2356 for (section
= output_bfd
->sections
;
2358 section
= section
->next
)
2360 if ((section
->flags
& SEC_CODE
) != 0)
2361 input_list
[section
->index
] = NULL
;
2367 /* The linker repeatedly calls this function for each input section,
2368 in the order that input sections are linked into output sections.
2369 Build lists of input sections to determine groupings between which
2370 we may insert linker stubs. */
2373 elf32_hppa_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
2375 struct elf32_hppa_link_hash_table
*htab
= hppa_link_hash_table (info
);
2377 if (isec
->output_section
->index
<= htab
->top_index
)
2379 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
2380 if (*list
!= bfd_abs_section_ptr
)
2382 /* Steal the link_sec pointer for our list. */
2383 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
2384 /* This happens to make the list in reverse order,
2385 which is what we want. */
2386 PREV_SEC (isec
) = *list
;
2392 /* See whether we can group stub sections together. Grouping stub
2393 sections may result in fewer stubs. More importantly, we need to
2394 put all .init* and .fini* stubs at the beginning of the .init or
2395 .fini output sections respectively, because glibc splits the
2396 _init and _fini functions into multiple parts. Putting a stub in
2397 the middle of a function is not a good idea. */
2400 group_sections (struct elf32_hppa_link_hash_table
*htab
,
2401 bfd_size_type stub_group_size
,
2402 bfd_boolean stubs_always_before_branch
)
2404 asection
**list
= htab
->input_list
+ htab
->top_index
;
2407 asection
*tail
= *list
;
2408 if (tail
== bfd_abs_section_ptr
)
2410 while (tail
!= NULL
)
2414 bfd_size_type total
;
2415 bfd_boolean big_sec
;
2418 if (tail
->_cooked_size
)
2419 total
= tail
->_cooked_size
;
2421 total
= tail
->_raw_size
;
2422 big_sec
= total
>= stub_group_size
;
2424 while ((prev
= PREV_SEC (curr
)) != NULL
2425 && ((total
+= curr
->output_offset
- prev
->output_offset
)
2429 /* OK, the size from the start of CURR to the end is less
2430 than 240000 bytes and thus can be handled by one stub
2431 section. (or the tail section is itself larger than
2432 240000 bytes, in which case we may be toast.)
2433 We should really be keeping track of the total size of
2434 stubs added here, as stubs contribute to the final output
2435 section size. That's a little tricky, and this way will
2436 only break if stubs added total more than 22144 bytes, or
2437 2768 long branch stubs. It seems unlikely for more than
2438 2768 different functions to be called, especially from
2439 code only 240000 bytes long. This limit used to be
2440 250000, but c++ code tends to generate lots of little
2441 functions, and sometimes violated the assumption. */
2444 prev
= PREV_SEC (tail
);
2445 /* Set up this stub group. */
2446 htab
->stub_group
[tail
->id
].link_sec
= curr
;
2448 while (tail
!= curr
&& (tail
= prev
) != NULL
);
2450 /* But wait, there's more! Input sections up to 240000
2451 bytes before the stub section can be handled by it too.
2452 Don't do this if we have a really large section after the
2453 stubs, as adding more stubs increases the chance that
2454 branches may not reach into the stub section. */
2455 if (!stubs_always_before_branch
&& !big_sec
)
2459 && ((total
+= tail
->output_offset
- prev
->output_offset
)
2463 prev
= PREV_SEC (tail
);
2464 htab
->stub_group
[tail
->id
].link_sec
= curr
;
2470 while (list
-- != htab
->input_list
);
2471 free (htab
->input_list
);
2475 /* Read in all local syms for all input bfds, and create hash entries
2476 for export stubs if we are building a multi-subspace shared lib.
2477 Returns -1 on error, 1 if export stubs created, 0 otherwise. */
2480 get_local_syms (bfd
*output_bfd
, bfd
*input_bfd
, struct bfd_link_info
*info
)
2482 unsigned int bfd_indx
;
2483 Elf_Internal_Sym
*local_syms
, **all_local_syms
;
2484 int stub_changed
= 0;
2485 struct elf32_hppa_link_hash_table
*htab
= hppa_link_hash_table (info
);
2487 /* We want to read in symbol extension records only once. To do this
2488 we need to read in the local symbols in parallel and save them for
2489 later use; so hold pointers to the local symbols in an array. */
2490 bfd_size_type amt
= sizeof (Elf_Internal_Sym
*) * htab
->bfd_count
;
2491 all_local_syms
= bfd_zmalloc (amt
);
2492 htab
->all_local_syms
= all_local_syms
;
2493 if (all_local_syms
== NULL
)
2496 /* Walk over all the input BFDs, swapping in local symbols.
2497 If we are creating a shared library, create hash entries for the
2501 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
2503 Elf_Internal_Shdr
*symtab_hdr
;
2505 /* We'll need the symbol table in a second. */
2506 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2507 if (symtab_hdr
->sh_info
== 0)
2510 /* We need an array of the local symbols attached to the input bfd. */
2511 local_syms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2512 if (local_syms
== NULL
)
2514 local_syms
= bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
2515 symtab_hdr
->sh_info
, 0,
2517 /* Cache them for elf_link_input_bfd. */
2518 symtab_hdr
->contents
= (unsigned char *) local_syms
;
2520 if (local_syms
== NULL
)
2523 all_local_syms
[bfd_indx
] = local_syms
;
2525 if (info
->shared
&& htab
->multi_subspace
)
2527 struct elf_link_hash_entry
**sym_hashes
;
2528 struct elf_link_hash_entry
**end_hashes
;
2529 unsigned int symcount
;
2531 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
2532 - symtab_hdr
->sh_info
);
2533 sym_hashes
= elf_sym_hashes (input_bfd
);
2534 end_hashes
= sym_hashes
+ symcount
;
2536 /* Look through the global syms for functions; We need to
2537 build export stubs for all globally visible functions. */
2538 for (; sym_hashes
< end_hashes
; sym_hashes
++)
2540 struct elf32_hppa_link_hash_entry
*hash
;
2542 hash
= (struct elf32_hppa_link_hash_entry
*) *sym_hashes
;
2544 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
2545 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
2546 hash
= ((struct elf32_hppa_link_hash_entry
*)
2547 hash
->elf
.root
.u
.i
.link
);
2549 /* At this point in the link, undefined syms have been
2550 resolved, so we need to check that the symbol was
2551 defined in this BFD. */
2552 if ((hash
->elf
.root
.type
== bfd_link_hash_defined
2553 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
2554 && hash
->elf
.type
== STT_FUNC
2555 && hash
->elf
.root
.u
.def
.section
->output_section
!= NULL
2556 && (hash
->elf
.root
.u
.def
.section
->output_section
->owner
2558 && hash
->elf
.root
.u
.def
.section
->owner
== input_bfd
2559 && (hash
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
2560 && !(hash
->elf
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
2561 && ELF_ST_VISIBILITY (hash
->elf
.other
) == STV_DEFAULT
)
2564 const char *stub_name
;
2565 struct elf32_hppa_stub_hash_entry
*stub_entry
;
2567 sec
= hash
->elf
.root
.u
.def
.section
;
2568 stub_name
= hash
->elf
.root
.root
.string
;
2569 stub_entry
= hppa_stub_hash_lookup (&htab
->stub_hash_table
,
2572 if (stub_entry
== NULL
)
2574 stub_entry
= hppa_add_stub (stub_name
, sec
, htab
);
2578 stub_entry
->target_value
= hash
->elf
.root
.u
.def
.value
;
2579 stub_entry
->target_section
= hash
->elf
.root
.u
.def
.section
;
2580 stub_entry
->stub_type
= hppa_stub_export
;
2581 stub_entry
->h
= hash
;
2586 (*_bfd_error_handler
) (_("%s: duplicate export stub %s"),
2587 bfd_archive_filename (input_bfd
),
2595 return stub_changed
;
2598 /* Determine and set the size of the stub section for a final link.
2600 The basic idea here is to examine all the relocations looking for
2601 PC-relative calls to a target that is unreachable with a "bl"
2605 elf32_hppa_size_stubs
2606 (bfd
*output_bfd
, bfd
*stub_bfd
, struct bfd_link_info
*info
,
2607 bfd_boolean multi_subspace
, bfd_signed_vma group_size
,
2608 asection
* (*add_stub_section
) (const char *, asection
*),
2609 void (*layout_sections_again
) (void))
2611 bfd_size_type stub_group_size
;
2612 bfd_boolean stubs_always_before_branch
;
2613 bfd_boolean stub_changed
;
2614 struct elf32_hppa_link_hash_table
*htab
= hppa_link_hash_table (info
);
2616 /* Stash our params away. */
2617 htab
->stub_bfd
= stub_bfd
;
2618 htab
->multi_subspace
= multi_subspace
;
2619 htab
->add_stub_section
= add_stub_section
;
2620 htab
->layout_sections_again
= layout_sections_again
;
2621 stubs_always_before_branch
= group_size
< 0;
2623 stub_group_size
= -group_size
;
2625 stub_group_size
= group_size
;
2626 if (stub_group_size
== 1)
2628 /* Default values. */
2629 if (stubs_always_before_branch
)
2631 stub_group_size
= 7680000;
2632 if (htab
->has_17bit_branch
|| htab
->multi_subspace
)
2633 stub_group_size
= 240000;
2634 if (htab
->has_12bit_branch
)
2635 stub_group_size
= 7500;
2639 stub_group_size
= 6971392;
2640 if (htab
->has_17bit_branch
|| htab
->multi_subspace
)
2641 stub_group_size
= 217856;
2642 if (htab
->has_12bit_branch
)
2643 stub_group_size
= 6808;
2647 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
2649 switch (get_local_syms (output_bfd
, info
->input_bfds
, info
))
2652 if (htab
->all_local_syms
)
2653 goto error_ret_free_local
;
2657 stub_changed
= FALSE
;
2661 stub_changed
= TRUE
;
2668 unsigned int bfd_indx
;
2671 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
2673 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
2675 Elf_Internal_Shdr
*symtab_hdr
;
2677 Elf_Internal_Sym
*local_syms
;
2679 /* We'll need the symbol table in a second. */
2680 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2681 if (symtab_hdr
->sh_info
== 0)
2684 local_syms
= htab
->all_local_syms
[bfd_indx
];
2686 /* Walk over each section attached to the input bfd. */
2687 for (section
= input_bfd
->sections
;
2689 section
= section
->next
)
2691 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
2693 /* If there aren't any relocs, then there's nothing more
2695 if ((section
->flags
& SEC_RELOC
) == 0
2696 || section
->reloc_count
== 0)
2699 /* If this section is a link-once section that will be
2700 discarded, then don't create any stubs. */
2701 if (section
->output_section
== NULL
2702 || section
->output_section
->owner
!= output_bfd
)
2705 /* Get the relocs. */
2707 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
, NULL
,
2709 if (internal_relocs
== NULL
)
2710 goto error_ret_free_local
;
2712 /* Now examine each relocation. */
2713 irela
= internal_relocs
;
2714 irelaend
= irela
+ section
->reloc_count
;
2715 for (; irela
< irelaend
; irela
++)
2717 unsigned int r_type
, r_indx
;
2718 enum elf32_hppa_stub_type stub_type
;
2719 struct elf32_hppa_stub_hash_entry
*stub_entry
;
2722 bfd_vma destination
;
2723 struct elf32_hppa_link_hash_entry
*hash
;
2725 const asection
*id_sec
;
2727 r_type
= ELF32_R_TYPE (irela
->r_info
);
2728 r_indx
= ELF32_R_SYM (irela
->r_info
);
2730 if (r_type
>= (unsigned int) R_PARISC_UNIMPLEMENTED
)
2732 bfd_set_error (bfd_error_bad_value
);
2733 error_ret_free_internal
:
2734 if (elf_section_data (section
)->relocs
== NULL
)
2735 free (internal_relocs
);
2736 goto error_ret_free_local
;
2739 /* Only look for stubs on call instructions. */
2740 if (r_type
!= (unsigned int) R_PARISC_PCREL12F
2741 && r_type
!= (unsigned int) R_PARISC_PCREL17F
2742 && r_type
!= (unsigned int) R_PARISC_PCREL22F
)
2745 /* Now determine the call target, its name, value,
2751 if (r_indx
< symtab_hdr
->sh_info
)
2753 /* It's a local symbol. */
2754 Elf_Internal_Sym
*sym
;
2755 Elf_Internal_Shdr
*hdr
;
2757 sym
= local_syms
+ r_indx
;
2758 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
2759 sym_sec
= hdr
->bfd_section
;
2760 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
2761 sym_value
= sym
->st_value
;
2762 destination
= (sym_value
+ irela
->r_addend
2763 + sym_sec
->output_offset
2764 + sym_sec
->output_section
->vma
);
2768 /* It's an external symbol. */
2771 e_indx
= r_indx
- symtab_hdr
->sh_info
;
2772 hash
= ((struct elf32_hppa_link_hash_entry
*)
2773 elf_sym_hashes (input_bfd
)[e_indx
]);
2775 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
2776 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
2777 hash
= ((struct elf32_hppa_link_hash_entry
*)
2778 hash
->elf
.root
.u
.i
.link
);
2780 if (hash
->elf
.root
.type
== bfd_link_hash_defined
2781 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
2783 sym_sec
= hash
->elf
.root
.u
.def
.section
;
2784 sym_value
= hash
->elf
.root
.u
.def
.value
;
2785 if (sym_sec
->output_section
!= NULL
)
2786 destination
= (sym_value
+ irela
->r_addend
2787 + sym_sec
->output_offset
2788 + sym_sec
->output_section
->vma
);
2790 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
)
2795 else if (hash
->elf
.root
.type
== bfd_link_hash_undefined
)
2798 && info
->unresolved_syms_in_objects
== RM_IGNORE
2799 && (ELF_ST_VISIBILITY (hash
->elf
.other
)
2801 && hash
->elf
.type
!= STT_PARISC_MILLI
))
2806 bfd_set_error (bfd_error_bad_value
);
2807 goto error_ret_free_internal
;
2811 /* Determine what (if any) linker stub is needed. */
2812 stub_type
= hppa_type_of_stub (section
, irela
, hash
,
2814 if (stub_type
== hppa_stub_none
)
2817 /* Support for grouping stub sections. */
2818 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
2820 /* Get the name of this stub. */
2821 stub_name
= hppa_stub_name (id_sec
, sym_sec
, hash
, irela
);
2823 goto error_ret_free_internal
;
2825 stub_entry
= hppa_stub_hash_lookup (&htab
->stub_hash_table
,
2828 if (stub_entry
!= NULL
)
2830 /* The proper stub has already been created. */
2835 stub_entry
= hppa_add_stub (stub_name
, section
, htab
);
2836 if (stub_entry
== NULL
)
2839 goto error_ret_free_internal
;
2842 stub_entry
->target_value
= sym_value
;
2843 stub_entry
->target_section
= sym_sec
;
2844 stub_entry
->stub_type
= stub_type
;
2847 if (stub_type
== hppa_stub_import
)
2848 stub_entry
->stub_type
= hppa_stub_import_shared
;
2849 else if (stub_type
== hppa_stub_long_branch
)
2850 stub_entry
->stub_type
= hppa_stub_long_branch_shared
;
2852 stub_entry
->h
= hash
;
2853 stub_changed
= TRUE
;
2856 /* We're done with the internal relocs, free them. */
2857 if (elf_section_data (section
)->relocs
== NULL
)
2858 free (internal_relocs
);
2865 /* OK, we've added some stubs. Find out the new size of the
2867 for (stub_sec
= htab
->stub_bfd
->sections
;
2869 stub_sec
= stub_sec
->next
)
2871 stub_sec
->_raw_size
= 0;
2872 stub_sec
->_cooked_size
= 0;
2875 bfd_hash_traverse (&htab
->stub_hash_table
, hppa_size_one_stub
, htab
);
2877 /* Ask the linker to do its stuff. */
2878 (*htab
->layout_sections_again
) ();
2879 stub_changed
= FALSE
;
2882 free (htab
->all_local_syms
);
2885 error_ret_free_local
:
2886 free (htab
->all_local_syms
);
2890 /* For a final link, this function is called after we have sized the
2891 stubs to provide a value for __gp. */
2894 elf32_hppa_set_gp (bfd
*abfd
, struct bfd_link_info
*info
)
2896 struct bfd_link_hash_entry
*h
;
2897 asection
*sec
= NULL
;
2899 struct elf32_hppa_link_hash_table
*htab
;
2901 htab
= hppa_link_hash_table (info
);
2902 h
= bfd_link_hash_lookup (&htab
->elf
.root
, "$global$", FALSE
, FALSE
, FALSE
);
2905 && (h
->type
== bfd_link_hash_defined
2906 || h
->type
== bfd_link_hash_defweak
))
2908 gp_val
= h
->u
.def
.value
;
2909 sec
= h
->u
.def
.section
;
2916 if (htab
->elf
.root
.creator
->flavour
== bfd_target_elf_flavour
)
2923 /* If we're not elf, look up the output sections in the
2924 hope we may actually find them. */
2925 splt
= bfd_get_section_by_name (abfd
, ".plt");
2926 sgot
= bfd_get_section_by_name (abfd
, ".got");
2929 /* Choose to point our LTP at, in this order, one of .plt, .got,
2930 or .data, if these sections exist. In the case of choosing
2931 .plt try to make the LTP ideal for addressing anywhere in the
2932 .plt or .got with a 14 bit signed offset. Typically, the end
2933 of the .plt is the start of the .got, so choose .plt + 0x2000
2934 if either the .plt or .got is larger than 0x2000. If both
2935 the .plt and .got are smaller than 0x2000, choose the end of
2936 the .plt section. */
2940 gp_val
= sec
->_raw_size
;
2941 if (gp_val
> 0x2000 || (sgot
&& sgot
->_raw_size
> 0x2000))
2951 /* We know we don't have a .plt. If .got is large,
2953 if (sec
->_raw_size
> 0x2000)
2958 /* No .plt or .got. Who cares what the LTP is? */
2959 sec
= bfd_get_section_by_name (abfd
, ".data");
2965 h
->type
= bfd_link_hash_defined
;
2966 h
->u
.def
.value
= gp_val
;
2968 h
->u
.def
.section
= sec
;
2970 h
->u
.def
.section
= bfd_abs_section_ptr
;
2974 if (sec
!= NULL
&& sec
->output_section
!= NULL
)
2975 gp_val
+= sec
->output_section
->vma
+ sec
->output_offset
;
2977 elf_gp (abfd
) = gp_val
;
2981 /* Build all the stubs associated with the current output file. The
2982 stubs are kept in a hash table attached to the main linker hash
2983 table. We also set up the .plt entries for statically linked PIC
2984 functions here. This function is called via hppaelf_finish in the
2988 elf32_hppa_build_stubs (struct bfd_link_info
*info
)
2991 struct bfd_hash_table
*table
;
2992 struct elf32_hppa_link_hash_table
*htab
;
2994 htab
= hppa_link_hash_table (info
);
2996 for (stub_sec
= htab
->stub_bfd
->sections
;
2998 stub_sec
= stub_sec
->next
)
3002 /* Allocate memory to hold the linker stubs. */
3003 size
= stub_sec
->_raw_size
;
3004 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, size
);
3005 if (stub_sec
->contents
== NULL
&& size
!= 0)
3007 stub_sec
->_raw_size
= 0;
3010 /* Build the stubs as directed by the stub hash table. */
3011 table
= &htab
->stub_hash_table
;
3012 bfd_hash_traverse (table
, hppa_build_one_stub
, info
);
3017 /* Perform a final link. */
3020 elf32_hppa_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
3022 /* Invoke the regular ELF linker to do all the work. */
3023 if (!bfd_elf32_bfd_final_link (abfd
, info
))
3026 /* If we're producing a final executable, sort the contents of the
3028 return elf_hppa_sort_unwind (abfd
);
3031 /* Record the lowest address for the data and text segments. */
3034 hppa_record_segment_addr (bfd
*abfd ATTRIBUTE_UNUSED
,
3038 struct elf32_hppa_link_hash_table
*htab
;
3040 htab
= (struct elf32_hppa_link_hash_table
*) data
;
3042 if ((section
->flags
& (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3044 bfd_vma value
= section
->vma
- section
->filepos
;
3046 if ((section
->flags
& SEC_READONLY
) != 0)
3048 if (value
< htab
->text_segment_base
)
3049 htab
->text_segment_base
= value
;
3053 if (value
< htab
->data_segment_base
)
3054 htab
->data_segment_base
= value
;
3059 /* Perform a relocation as part of a final link. */
3061 static bfd_reloc_status_type
3062 final_link_relocate (asection
*input_section
,
3064 const Elf_Internal_Rela
*rel
,
3066 struct elf32_hppa_link_hash_table
*htab
,
3068 struct elf32_hppa_link_hash_entry
*h
,
3069 struct bfd_link_info
*info
)
3072 unsigned int r_type
= ELF32_R_TYPE (rel
->r_info
);
3073 unsigned int orig_r_type
= r_type
;
3074 reloc_howto_type
*howto
= elf_hppa_howto_table
+ r_type
;
3075 int r_format
= howto
->bitsize
;
3076 enum hppa_reloc_field_selector_type_alt r_field
;
3077 bfd
*input_bfd
= input_section
->owner
;
3078 bfd_vma offset
= rel
->r_offset
;
3079 bfd_vma max_branch_offset
= 0;
3080 bfd_byte
*hit_data
= contents
+ offset
;
3081 bfd_signed_vma addend
= rel
->r_addend
;
3083 struct elf32_hppa_stub_hash_entry
*stub_entry
= NULL
;
3086 if (r_type
== R_PARISC_NONE
)
3087 return bfd_reloc_ok
;
3089 insn
= bfd_get_32 (input_bfd
, hit_data
);
3091 /* Find out where we are and where we're going. */
3092 location
= (offset
+
3093 input_section
->output_offset
+
3094 input_section
->output_section
->vma
);
3096 /* If we are not building a shared library, convert DLTIND relocs to
3102 case R_PARISC_DLTIND21L
:
3103 r_type
= R_PARISC_DPREL21L
;
3106 case R_PARISC_DLTIND14R
:
3107 r_type
= R_PARISC_DPREL14R
;
3110 case R_PARISC_DLTIND14F
:
3111 r_type
= R_PARISC_DPREL14F
;
3118 case R_PARISC_PCREL12F
:
3119 case R_PARISC_PCREL17F
:
3120 case R_PARISC_PCREL22F
:
3121 /* If this call should go via the plt, find the import stub in
3124 || sym_sec
->output_section
== NULL
3126 && h
->elf
.plt
.offset
!= (bfd_vma
) -1
3127 && h
->elf
.dynindx
!= -1
3130 || !(h
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
3131 || h
->elf
.root
.type
== bfd_link_hash_defweak
)))
3133 stub_entry
= hppa_get_stub_entry (input_section
, sym_sec
,
3135 if (stub_entry
!= NULL
)
3137 value
= (stub_entry
->stub_offset
3138 + stub_entry
->stub_sec
->output_offset
3139 + stub_entry
->stub_sec
->output_section
->vma
);
3142 else if (sym_sec
== NULL
&& h
!= NULL
3143 && h
->elf
.root
.type
== bfd_link_hash_undefweak
)
3145 /* It's OK if undefined weak. Calls to undefined weak
3146 symbols behave as if the "called" function
3147 immediately returns. We can thus call to a weak
3148 function without first checking whether the function
3154 return bfd_reloc_undefined
;
3158 case R_PARISC_PCREL21L
:
3159 case R_PARISC_PCREL17C
:
3160 case R_PARISC_PCREL17R
:
3161 case R_PARISC_PCREL14R
:
3162 case R_PARISC_PCREL14F
:
3163 /* Make it a pc relative offset. */
3168 case R_PARISC_DPREL21L
:
3169 case R_PARISC_DPREL14R
:
3170 case R_PARISC_DPREL14F
:
3171 /* Convert instructions that use the linkage table pointer (r19) to
3172 instructions that use the global data pointer (dp). This is the
3173 most efficient way of using PIC code in an incomplete executable,
3174 but the user must follow the standard runtime conventions for
3175 accessing data for this to work. */
3176 if (orig_r_type
== R_PARISC_DLTIND21L
)
3178 /* Convert addil instructions if the original reloc was a
3179 DLTIND21L. GCC sometimes uses a register other than r19 for
3180 the operation, so we must convert any addil instruction
3181 that uses this relocation. */
3182 if ((insn
& 0xfc000000) == ((int) OP_ADDIL
<< 26))
3185 /* We must have a ldil instruction. It's too hard to find
3186 and convert the associated add instruction, so issue an
3188 (*_bfd_error_handler
)
3189 (_("%s(%s+0x%lx): %s fixup for insn 0x%x is not supported in a non-shared link"),
3190 bfd_archive_filename (input_bfd
),
3191 input_section
->name
,
3192 (long) rel
->r_offset
,
3196 else if (orig_r_type
== R_PARISC_DLTIND14F
)
3198 /* This must be a format 1 load/store. Change the base
3200 insn
= (insn
& 0xfc1ffff) | (27 << 21);
3203 /* For all the DP relative relocations, we need to examine the symbol's
3204 section. If it has no section or if it's a code section, then
3205 "data pointer relative" makes no sense. In that case we don't
3206 adjust the "value", and for 21 bit addil instructions, we change the
3207 source addend register from %dp to %r0. This situation commonly
3208 arises for undefined weak symbols and when a variable's "constness"
3209 is declared differently from the way the variable is defined. For
3210 instance: "extern int foo" with foo defined as "const int foo". */
3211 if (sym_sec
== NULL
|| (sym_sec
->flags
& SEC_CODE
) != 0)
3213 if ((insn
& ((0x3f << 26) | (0x1f << 21)))
3214 == (((int) OP_ADDIL
<< 26) | (27 << 21)))
3216 insn
&= ~ (0x1f << 21);
3217 #if 0 /* debug them. */
3218 (*_bfd_error_handler
)
3219 (_("%s(%s+0x%lx): fixing %s"),
3220 bfd_archive_filename (input_bfd
),
3221 input_section
->name
,
3222 (long) rel
->r_offset
,
3226 /* Now try to make things easy for the dynamic linker. */
3232 case R_PARISC_DLTIND21L
:
3233 case R_PARISC_DLTIND14R
:
3234 case R_PARISC_DLTIND14F
:
3235 value
-= elf_gp (input_section
->output_section
->owner
);
3238 case R_PARISC_SEGREL32
:
3239 if ((sym_sec
->flags
& SEC_CODE
) != 0)
3240 value
-= htab
->text_segment_base
;
3242 value
-= htab
->data_segment_base
;
3251 case R_PARISC_DIR32
:
3252 case R_PARISC_DIR14F
:
3253 case R_PARISC_DIR17F
:
3254 case R_PARISC_PCREL17C
:
3255 case R_PARISC_PCREL14F
:
3256 case R_PARISC_DPREL14F
:
3257 case R_PARISC_PLABEL32
:
3258 case R_PARISC_DLTIND14F
:
3259 case R_PARISC_SEGBASE
:
3260 case R_PARISC_SEGREL32
:
3264 case R_PARISC_DLTIND21L
:
3265 case R_PARISC_PCREL21L
:
3266 case R_PARISC_PLABEL21L
:
3270 case R_PARISC_DIR21L
:
3271 case R_PARISC_DPREL21L
:
3275 case R_PARISC_PCREL17R
:
3276 case R_PARISC_PCREL14R
:
3277 case R_PARISC_PLABEL14R
:
3278 case R_PARISC_DLTIND14R
:
3282 case R_PARISC_DIR17R
:
3283 case R_PARISC_DIR14R
:
3284 case R_PARISC_DPREL14R
:
3288 case R_PARISC_PCREL12F
:
3289 case R_PARISC_PCREL17F
:
3290 case R_PARISC_PCREL22F
:
3293 if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
3295 max_branch_offset
= (1 << (17-1)) << 2;
3297 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
3299 max_branch_offset
= (1 << (12-1)) << 2;
3303 max_branch_offset
= (1 << (22-1)) << 2;
3306 /* sym_sec is NULL on undefined weak syms or when shared on
3307 undefined syms. We've already checked for a stub for the
3308 shared undefined case. */
3309 if (sym_sec
== NULL
)
3312 /* If the branch is out of reach, then redirect the
3313 call to the local stub for this function. */
3314 if (value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3316 stub_entry
= hppa_get_stub_entry (input_section
, sym_sec
,
3318 if (stub_entry
== NULL
)
3319 return bfd_reloc_undefined
;
3321 /* Munge up the value and addend so that we call the stub
3322 rather than the procedure directly. */
3323 value
= (stub_entry
->stub_offset
3324 + stub_entry
->stub_sec
->output_offset
3325 + stub_entry
->stub_sec
->output_section
->vma
3331 /* Something we don't know how to handle. */
3333 return bfd_reloc_notsupported
;
3336 /* Make sure we can reach the stub. */
3337 if (max_branch_offset
!= 0
3338 && value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3340 (*_bfd_error_handler
)
3341 (_("%s(%s+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
3342 bfd_archive_filename (input_bfd
),
3343 input_section
->name
,
3344 (long) rel
->r_offset
,
3345 stub_entry
->root
.string
);
3346 bfd_set_error (bfd_error_bad_value
);
3347 return bfd_reloc_notsupported
;
3350 val
= hppa_field_adjust (value
, addend
, r_field
);
3354 case R_PARISC_PCREL12F
:
3355 case R_PARISC_PCREL17C
:
3356 case R_PARISC_PCREL17F
:
3357 case R_PARISC_PCREL17R
:
3358 case R_PARISC_PCREL22F
:
3359 case R_PARISC_DIR17F
:
3360 case R_PARISC_DIR17R
:
3361 /* This is a branch. Divide the offset by four.
3362 Note that we need to decide whether it's a branch or
3363 otherwise by inspecting the reloc. Inspecting insn won't
3364 work as insn might be from a .word directive. */
3372 insn
= hppa_rebuild_insn (insn
, val
, r_format
);
3374 /* Update the instruction word. */
3375 bfd_put_32 (input_bfd
, (bfd_vma
) insn
, hit_data
);
3376 return bfd_reloc_ok
;
3379 /* Relocate an HPPA ELF section. */
3382 elf32_hppa_relocate_section (bfd
*output_bfd
,
3383 struct bfd_link_info
*info
,
3385 asection
*input_section
,
3387 Elf_Internal_Rela
*relocs
,
3388 Elf_Internal_Sym
*local_syms
,
3389 asection
**local_sections
)
3391 bfd_vma
*local_got_offsets
;
3392 struct elf32_hppa_link_hash_table
*htab
;
3393 Elf_Internal_Shdr
*symtab_hdr
;
3394 Elf_Internal_Rela
*rel
;
3395 Elf_Internal_Rela
*relend
;
3397 if (info
->relocatable
)
3400 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3402 htab
= hppa_link_hash_table (info
);
3403 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3406 relend
= relocs
+ input_section
->reloc_count
;
3407 for (; rel
< relend
; rel
++)
3409 unsigned int r_type
;
3410 reloc_howto_type
*howto
;
3411 unsigned int r_symndx
;
3412 struct elf32_hppa_link_hash_entry
*h
;
3413 Elf_Internal_Sym
*sym
;
3416 bfd_reloc_status_type r
;
3417 const char *sym_name
;
3419 bfd_boolean warned_undef
;
3421 r_type
= ELF32_R_TYPE (rel
->r_info
);
3422 if (r_type
>= (unsigned int) R_PARISC_UNIMPLEMENTED
)
3424 bfd_set_error (bfd_error_bad_value
);
3427 if (r_type
== (unsigned int) R_PARISC_GNU_VTENTRY
3428 || r_type
== (unsigned int) R_PARISC_GNU_VTINHERIT
)
3431 /* This is a final link. */
3432 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3436 warned_undef
= FALSE
;
3437 if (r_symndx
< symtab_hdr
->sh_info
)
3439 /* This is a local symbol, h defaults to NULL. */
3440 sym
= local_syms
+ r_symndx
;
3441 sym_sec
= local_sections
[r_symndx
];
3442 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sym_sec
, rel
);
3446 struct elf_link_hash_entry
*hh
;
3447 bfd_boolean unresolved_reloc
;
3449 RELOC_FOR_GLOBAL_SYMBOL (hh
, elf_sym_hashes (input_bfd
), r_symndx
, symtab_hdr
,
3450 relocation
, sym_sec
, unresolved_reloc
, info
,
3454 && hh
->root
.type
!= bfd_link_hash_defined
3455 && hh
->root
.type
!= bfd_link_hash_defweak
3456 && hh
->root
.type
!= bfd_link_hash_undefweak
)
3458 if (!info
->executable
3459 && info
->unresolved_syms_in_objects
== RM_IGNORE
3460 && ELF_ST_VISIBILITY (hh
->other
) == STV_DEFAULT
3461 && hh
->type
== STT_PARISC_MILLI
)
3463 if (! info
->callbacks
->undefined_symbol
3464 (info
, hh
->root
.root
.string
, input_bfd
,
3465 input_section
, rel
->r_offset
,
3466 ((info
->shared
&& info
->unresolved_syms_in_shared_libs
== RM_GENERATE_ERROR
)
3467 || (!info
->shared
&& info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
))))
3469 warned_undef
= TRUE
;
3472 h
= (struct elf32_hppa_link_hash_entry
*) hh
;
3475 /* Do any required modifications to the relocation value, and
3476 determine what types of dynamic info we need to output, if
3481 case R_PARISC_DLTIND14F
:
3482 case R_PARISC_DLTIND14R
:
3483 case R_PARISC_DLTIND21L
:
3486 bfd_boolean do_got
= 0;
3488 /* Relocation is to the entry for this symbol in the
3489 global offset table. */
3494 off
= h
->elf
.got
.offset
;
3495 dyn
= htab
->elf
.dynamic_sections_created
;
3496 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, &h
->elf
))
3498 /* If we aren't going to call finish_dynamic_symbol,
3499 then we need to handle initialisation of the .got
3500 entry and create needed relocs here. Since the
3501 offset must always be a multiple of 4, we use the
3502 least significant bit to record whether we have
3503 initialised it already. */
3508 h
->elf
.got
.offset
|= 1;
3515 /* Local symbol case. */
3516 if (local_got_offsets
== NULL
)
3519 off
= local_got_offsets
[r_symndx
];
3521 /* The offset must always be a multiple of 4. We use
3522 the least significant bit to record whether we have
3523 already generated the necessary reloc. */
3528 local_got_offsets
[r_symndx
] |= 1;
3537 /* Output a dynamic relocation for this GOT entry.
3538 In this case it is relative to the base of the
3539 object because the symbol index is zero. */
3540 Elf_Internal_Rela outrel
;
3542 asection
*s
= htab
->srelgot
;
3544 outrel
.r_offset
= (off
3545 + htab
->sgot
->output_offset
3546 + htab
->sgot
->output_section
->vma
);
3547 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_DIR32
);
3548 outrel
.r_addend
= relocation
;
3550 loc
+= s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
3551 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
3554 bfd_put_32 (output_bfd
, relocation
,
3555 htab
->sgot
->contents
+ off
);
3558 if (off
>= (bfd_vma
) -2)
3561 /* Add the base of the GOT to the relocation value. */
3563 + htab
->sgot
->output_offset
3564 + htab
->sgot
->output_section
->vma
);
3568 case R_PARISC_SEGREL32
:
3569 /* If this is the first SEGREL relocation, then initialize
3570 the segment base values. */
3571 if (htab
->text_segment_base
== (bfd_vma
) -1)
3572 bfd_map_over_sections (output_bfd
, hppa_record_segment_addr
, htab
);
3575 case R_PARISC_PLABEL14R
:
3576 case R_PARISC_PLABEL21L
:
3577 case R_PARISC_PLABEL32
:
3578 if (htab
->elf
.dynamic_sections_created
)
3581 bfd_boolean do_plt
= 0;
3583 /* If we have a global symbol with a PLT slot, then
3584 redirect this relocation to it. */
3587 off
= h
->elf
.plt
.offset
;
3588 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
, &h
->elf
))
3590 /* In a non-shared link, adjust_dynamic_symbols
3591 isn't called for symbols forced local. We
3592 need to write out the plt entry here. */
3597 h
->elf
.plt
.offset
|= 1;
3604 bfd_vma
*local_plt_offsets
;
3606 if (local_got_offsets
== NULL
)
3609 local_plt_offsets
= local_got_offsets
+ symtab_hdr
->sh_info
;
3610 off
= local_plt_offsets
[r_symndx
];
3612 /* As for the local .got entry case, we use the last
3613 bit to record whether we've already initialised
3614 this local .plt entry. */
3619 local_plt_offsets
[r_symndx
] |= 1;
3628 /* Output a dynamic IPLT relocation for this
3630 Elf_Internal_Rela outrel
;
3632 asection
*s
= htab
->srelplt
;
3634 outrel
.r_offset
= (off
3635 + htab
->splt
->output_offset
3636 + htab
->splt
->output_section
->vma
);
3637 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_IPLT
);
3638 outrel
.r_addend
= relocation
;
3640 loc
+= s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
3641 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
3645 bfd_put_32 (output_bfd
,
3647 htab
->splt
->contents
+ off
);
3648 bfd_put_32 (output_bfd
,
3649 elf_gp (htab
->splt
->output_section
->owner
),
3650 htab
->splt
->contents
+ off
+ 4);
3654 if (off
>= (bfd_vma
) -2)
3657 /* PLABELs contain function pointers. Relocation is to
3658 the entry for the function in the .plt. The magic +2
3659 offset signals to $$dyncall that the function pointer
3660 is in the .plt and thus has a gp pointer too.
3661 Exception: Undefined PLABELs should have a value of
3664 || (h
->elf
.root
.type
!= bfd_link_hash_undefweak
3665 && h
->elf
.root
.type
!= bfd_link_hash_undefined
))
3668 + htab
->splt
->output_offset
3669 + htab
->splt
->output_section
->vma
3674 /* Fall through and possibly emit a dynamic relocation. */
3676 case R_PARISC_DIR17F
:
3677 case R_PARISC_DIR17R
:
3678 case R_PARISC_DIR14F
:
3679 case R_PARISC_DIR14R
:
3680 case R_PARISC_DIR21L
:
3681 case R_PARISC_DPREL14F
:
3682 case R_PARISC_DPREL14R
:
3683 case R_PARISC_DPREL21L
:
3684 case R_PARISC_DIR32
:
3685 /* r_symndx will be zero only for relocs against symbols
3686 from removed linkonce sections, or sections discarded by
3689 || (input_section
->flags
& SEC_ALLOC
) == 0)
3692 /* The reloc types handled here and this conditional
3693 expression must match the code in ..check_relocs and
3694 allocate_dynrelocs. ie. We need exactly the same condition
3695 as in ..check_relocs, with some extra conditions (dynindx
3696 test in this case) to cater for relocs removed by
3697 allocate_dynrelocs. If you squint, the non-shared test
3698 here does indeed match the one in ..check_relocs, the
3699 difference being that here we test DEF_DYNAMIC as well as
3700 !DEF_REGULAR. All common syms end up with !DEF_REGULAR,
3701 which is why we can't use just that test here.
3702 Conversely, DEF_DYNAMIC can't be used in check_relocs as
3703 there all files have not been loaded. */
3706 || ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
3707 || h
->elf
.root
.type
!= bfd_link_hash_undefweak
)
3708 && (IS_ABSOLUTE_RELOC (r_type
)
3709 || !SYMBOL_CALLS_LOCAL (info
, &h
->elf
)))
3712 && h
->elf
.dynindx
!= -1
3713 && (h
->elf
.elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
3714 && ((ELIMINATE_COPY_RELOCS
3715 && (h
->elf
.elf_link_hash_flags
3716 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3717 && (h
->elf
.elf_link_hash_flags
3718 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
3719 || h
->elf
.root
.type
== bfd_link_hash_undefweak
3720 || h
->elf
.root
.type
== bfd_link_hash_undefined
)))
3722 Elf_Internal_Rela outrel
;
3727 /* When generating a shared object, these relocations
3728 are copied into the output file to be resolved at run
3731 outrel
.r_addend
= rel
->r_addend
;
3733 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3735 skip
= (outrel
.r_offset
== (bfd_vma
) -1
3736 || outrel
.r_offset
== (bfd_vma
) -2);
3737 outrel
.r_offset
+= (input_section
->output_offset
3738 + input_section
->output_section
->vma
);
3742 memset (&outrel
, 0, sizeof (outrel
));
3745 && h
->elf
.dynindx
!= -1
3747 || !IS_ABSOLUTE_RELOC (r_type
)
3750 || (h
->elf
.elf_link_hash_flags
3751 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
3753 outrel
.r_info
= ELF32_R_INFO (h
->elf
.dynindx
, r_type
);
3755 else /* It's a local symbol, or one marked to become local. */
3759 /* Add the absolute offset of the symbol. */
3760 outrel
.r_addend
+= relocation
;
3762 /* Global plabels need to be processed by the
3763 dynamic linker so that functions have at most one
3764 fptr. For this reason, we need to differentiate
3765 between global and local plabels, which we do by
3766 providing the function symbol for a global plabel
3767 reloc, and no symbol for local plabels. */
3770 && sym_sec
->output_section
!= NULL
3771 && ! bfd_is_abs_section (sym_sec
))
3773 /* Skip this relocation if the output section has
3775 if (bfd_is_abs_section (sym_sec
->output_section
))
3778 indx
= elf_section_data (sym_sec
->output_section
)->dynindx
;
3779 /* We are turning this relocation into one
3780 against a section symbol, so subtract out the
3781 output section's address but not the offset
3782 of the input section in the output section. */
3783 outrel
.r_addend
-= sym_sec
->output_section
->vma
;
3786 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
3789 /* EH info can cause unaligned DIR32 relocs.
3790 Tweak the reloc type for the dynamic linker. */
3791 if (r_type
== R_PARISC_DIR32
&& (outrel
.r_offset
& 3) != 0)
3792 outrel
.r_info
= ELF32_R_INFO (ELF32_R_SYM (outrel
.r_info
),
3795 sreloc
= elf_section_data (input_section
)->sreloc
;
3799 loc
= sreloc
->contents
;
3800 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
3801 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
3809 r
= final_link_relocate (input_section
, contents
, rel
, relocation
,
3810 htab
, sym_sec
, h
, info
);
3812 if (r
== bfd_reloc_ok
)
3816 sym_name
= h
->elf
.root
.root
.string
;
3819 sym_name
= bfd_elf_string_from_elf_section (input_bfd
,
3820 symtab_hdr
->sh_link
,
3822 if (sym_name
== NULL
)
3824 if (*sym_name
== '\0')
3825 sym_name
= bfd_section_name (input_bfd
, sym_sec
);
3828 howto
= elf_hppa_howto_table
+ r_type
;
3830 if (r
== bfd_reloc_undefined
|| r
== bfd_reloc_notsupported
)
3832 if (r
== bfd_reloc_notsupported
|| !warned_undef
)
3834 (*_bfd_error_handler
)
3835 (_("%s(%s+0x%lx): cannot handle %s for %s"),
3836 bfd_archive_filename (input_bfd
),
3837 input_section
->name
,
3838 (long) rel
->r_offset
,
3841 bfd_set_error (bfd_error_bad_value
);
3847 if (!((*info
->callbacks
->reloc_overflow
)
3848 (info
, sym_name
, howto
->name
, 0, input_bfd
, input_section
,
3857 /* Finish up dynamic symbol handling. We set the contents of various
3858 dynamic sections here. */
3861 elf32_hppa_finish_dynamic_symbol (bfd
*output_bfd
,
3862 struct bfd_link_info
*info
,
3863 struct elf_link_hash_entry
*h
,
3864 Elf_Internal_Sym
*sym
)
3866 struct elf32_hppa_link_hash_table
*htab
;
3867 Elf_Internal_Rela rel
;
3870 htab
= hppa_link_hash_table (info
);
3872 if (h
->plt
.offset
!= (bfd_vma
) -1)
3876 if (h
->plt
.offset
& 1)
3879 /* This symbol has an entry in the procedure linkage table. Set
3882 The format of a plt entry is
3887 if (h
->root
.type
== bfd_link_hash_defined
3888 || h
->root
.type
== bfd_link_hash_defweak
)
3890 value
= h
->root
.u
.def
.value
;
3891 if (h
->root
.u
.def
.section
->output_section
!= NULL
)
3892 value
+= (h
->root
.u
.def
.section
->output_offset
3893 + h
->root
.u
.def
.section
->output_section
->vma
);
3896 /* Create a dynamic IPLT relocation for this entry. */
3897 rel
.r_offset
= (h
->plt
.offset
3898 + htab
->splt
->output_offset
3899 + htab
->splt
->output_section
->vma
);
3900 if (h
->dynindx
!= -1)
3902 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_IPLT
);
3907 /* This symbol has been marked to become local, and is
3908 used by a plabel so must be kept in the .plt. */
3909 rel
.r_info
= ELF32_R_INFO (0, R_PARISC_IPLT
);
3910 rel
.r_addend
= value
;
3913 loc
= htab
->srelplt
->contents
;
3914 loc
+= htab
->srelplt
->reloc_count
++ * sizeof (Elf32_External_Rela
);
3915 bfd_elf32_swap_reloca_out (htab
->splt
->output_section
->owner
, &rel
, loc
);
3917 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3919 /* Mark the symbol as undefined, rather than as defined in
3920 the .plt section. Leave the value alone. */
3921 sym
->st_shndx
= SHN_UNDEF
;
3925 if (h
->got
.offset
!= (bfd_vma
) -1)
3927 /* This symbol has an entry in the global offset table. Set it
3930 rel
.r_offset
= ((h
->got
.offset
&~ (bfd_vma
) 1)
3931 + htab
->sgot
->output_offset
3932 + htab
->sgot
->output_section
->vma
);
3934 /* If this is a -Bsymbolic link and the symbol is defined
3935 locally or was forced to be local because of a version file,
3936 we just want to emit a RELATIVE reloc. The entry in the
3937 global offset table will already have been initialized in the
3938 relocate_section function. */
3940 && (info
->symbolic
|| h
->dynindx
== -1)
3941 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
3943 rel
.r_info
= ELF32_R_INFO (0, R_PARISC_DIR32
);
3944 rel
.r_addend
= (h
->root
.u
.def
.value
3945 + h
->root
.u
.def
.section
->output_offset
3946 + h
->root
.u
.def
.section
->output_section
->vma
);
3950 if ((h
->got
.offset
& 1) != 0)
3952 bfd_put_32 (output_bfd
, 0, htab
->sgot
->contents
+ h
->got
.offset
);
3953 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_DIR32
);
3957 loc
= htab
->srelgot
->contents
;
3958 loc
+= htab
->srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
3959 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
3962 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
3966 /* This symbol needs a copy reloc. Set it up. */
3968 if (! (h
->dynindx
!= -1
3969 && (h
->root
.type
== bfd_link_hash_defined
3970 || h
->root
.type
== bfd_link_hash_defweak
)))
3975 rel
.r_offset
= (h
->root
.u
.def
.value
3976 + h
->root
.u
.def
.section
->output_offset
3977 + h
->root
.u
.def
.section
->output_section
->vma
);
3979 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_COPY
);
3980 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
3981 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
3984 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
3985 if (h
->root
.root
.string
[0] == '_'
3986 && (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3987 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0))
3989 sym
->st_shndx
= SHN_ABS
;
3995 /* Used to decide how to sort relocs in an optimal manner for the
3996 dynamic linker, before writing them out. */
3998 static enum elf_reloc_type_class
3999 elf32_hppa_reloc_type_class (const Elf_Internal_Rela
*rela
)
4001 if (ELF32_R_SYM (rela
->r_info
) == 0)
4002 return reloc_class_relative
;
4004 switch ((int) ELF32_R_TYPE (rela
->r_info
))
4007 return reloc_class_plt
;
4009 return reloc_class_copy
;
4011 return reloc_class_normal
;
4015 /* Finish up the dynamic sections. */
4018 elf32_hppa_finish_dynamic_sections (bfd
*output_bfd
,
4019 struct bfd_link_info
*info
)
4022 struct elf32_hppa_link_hash_table
*htab
;
4025 htab
= hppa_link_hash_table (info
);
4026 dynobj
= htab
->elf
.dynobj
;
4028 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4030 if (htab
->elf
.dynamic_sections_created
)
4032 Elf32_External_Dyn
*dyncon
, *dynconend
;
4037 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4038 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
4039 for (; dyncon
< dynconend
; dyncon
++)
4041 Elf_Internal_Dyn dyn
;
4044 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4052 /* Use PLTGOT to set the GOT register. */
4053 dyn
.d_un
.d_ptr
= elf_gp (output_bfd
);
4058 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4063 dyn
.d_un
.d_val
= s
->_raw_size
;
4067 /* Don't count procedure linkage table relocs in the
4068 overall reloc count. */
4072 dyn
.d_un
.d_val
-= s
->_raw_size
;
4076 /* We may not be using the standard ELF linker script.
4077 If .rela.plt is the first .rela section, we adjust
4078 DT_RELA to not include it. */
4082 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
4084 dyn
.d_un
.d_ptr
+= s
->_raw_size
;
4088 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4092 if (htab
->sgot
!= NULL
&& htab
->sgot
->_raw_size
!= 0)
4094 /* Fill in the first entry in the global offset table.
4095 We use it to point to our dynamic section, if we have one. */
4096 bfd_put_32 (output_bfd
,
4097 sdyn
? sdyn
->output_section
->vma
+ sdyn
->output_offset
: 0,
4098 htab
->sgot
->contents
);
4100 /* The second entry is reserved for use by the dynamic linker. */
4101 memset (htab
->sgot
->contents
+ GOT_ENTRY_SIZE
, 0, GOT_ENTRY_SIZE
);
4103 /* Set .got entry size. */
4104 elf_section_data (htab
->sgot
->output_section
)
4105 ->this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
4108 if (htab
->splt
!= NULL
&& htab
->splt
->_raw_size
!= 0)
4110 /* Set plt entry size. */
4111 elf_section_data (htab
->splt
->output_section
)
4112 ->this_hdr
.sh_entsize
= PLT_ENTRY_SIZE
;
4114 if (htab
->need_plt_stub
)
4116 /* Set up the .plt stub. */
4117 memcpy (htab
->splt
->contents
4118 + htab
->splt
->_raw_size
- sizeof (plt_stub
),
4119 plt_stub
, sizeof (plt_stub
));
4121 if ((htab
->splt
->output_offset
4122 + htab
->splt
->output_section
->vma
4123 + htab
->splt
->_raw_size
)
4124 != (htab
->sgot
->output_offset
4125 + htab
->sgot
->output_section
->vma
))
4127 (*_bfd_error_handler
)
4128 (_(".got section not immediately after .plt section"));
4137 /* Tweak the OSABI field of the elf header. */
4140 elf32_hppa_post_process_headers (bfd
*abfd
,
4141 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
4143 Elf_Internal_Ehdr
* i_ehdrp
;
4145 i_ehdrp
= elf_elfheader (abfd
);
4147 if (strcmp (bfd_get_target (abfd
), "elf32-hppa-linux") == 0)
4149 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_LINUX
;
4153 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_HPUX
;
4157 /* Called when writing out an object file to decide the type of a
4160 elf32_hppa_elf_get_symbol_type (Elf_Internal_Sym
*elf_sym
, int type
)
4162 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_PARISC_MILLI
)
4163 return STT_PARISC_MILLI
;
4168 /* Misc BFD support code. */
4169 #define bfd_elf32_bfd_is_local_label_name elf_hppa_is_local_label_name
4170 #define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
4171 #define elf_info_to_howto elf_hppa_info_to_howto
4172 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
4174 /* Stuff for the BFD linker. */
4175 #define bfd_elf32_bfd_final_link elf32_hppa_final_link
4176 #define bfd_elf32_bfd_link_hash_table_create elf32_hppa_link_hash_table_create
4177 #define bfd_elf32_bfd_link_hash_table_free elf32_hppa_link_hash_table_free
4178 #define elf_backend_adjust_dynamic_symbol elf32_hppa_adjust_dynamic_symbol
4179 #define elf_backend_copy_indirect_symbol elf32_hppa_copy_indirect_symbol
4180 #define elf_backend_check_relocs elf32_hppa_check_relocs
4181 #define elf_backend_create_dynamic_sections elf32_hppa_create_dynamic_sections
4182 #define elf_backend_fake_sections elf_hppa_fake_sections
4183 #define elf_backend_relocate_section elf32_hppa_relocate_section
4184 #define elf_backend_hide_symbol elf32_hppa_hide_symbol
4185 #define elf_backend_finish_dynamic_symbol elf32_hppa_finish_dynamic_symbol
4186 #define elf_backend_finish_dynamic_sections elf32_hppa_finish_dynamic_sections
4187 #define elf_backend_size_dynamic_sections elf32_hppa_size_dynamic_sections
4188 #define elf_backend_gc_mark_hook elf32_hppa_gc_mark_hook
4189 #define elf_backend_gc_sweep_hook elf32_hppa_gc_sweep_hook
4190 #define elf_backend_object_p elf32_hppa_object_p
4191 #define elf_backend_final_write_processing elf_hppa_final_write_processing
4192 #define elf_backend_post_process_headers elf32_hppa_post_process_headers
4193 #define elf_backend_get_symbol_type elf32_hppa_elf_get_symbol_type
4194 #define elf_backend_reloc_type_class elf32_hppa_reloc_type_class
4196 #define elf_backend_can_gc_sections 1
4197 #define elf_backend_can_refcount 1
4198 #define elf_backend_plt_alignment 2
4199 #define elf_backend_want_got_plt 0
4200 #define elf_backend_plt_readonly 0
4201 #define elf_backend_want_plt_sym 0
4202 #define elf_backend_got_header_size 8
4203 #define elf_backend_rela_normal 1
4205 #define TARGET_BIG_SYM bfd_elf32_hppa_vec
4206 #define TARGET_BIG_NAME "elf32-hppa"
4207 #define ELF_ARCH bfd_arch_hppa
4208 #define ELF_MACHINE_CODE EM_PARISC
4209 #define ELF_MAXPAGESIZE 0x1000
4211 #include "elf32-target.h"
4213 #undef TARGET_BIG_SYM
4214 #define TARGET_BIG_SYM bfd_elf32_hppa_linux_vec
4215 #undef TARGET_BIG_NAME
4216 #define TARGET_BIG_NAME "elf32-hppa-linux"
4218 #define INCLUDED_TARGET_FILE 1
4219 #include "elf32-target.h"