1 /* BFD back-end for HP PA-RISC ELF files.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2001,
3 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
6 Center for Software Science
7 Department of Computer Science
9 Largely rewritten by Alan Modra <alan@linuxcare.com.au>
10 Naming cleanup by Carlos O'Donell <carlos@systemhalted.org>
11 TLS support written by Randolph Chung <tausq@debian.org>
13 This file is part of BFD, the Binary File Descriptor library.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 3 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
28 MA 02110-1301, USA. */
36 #include "elf32-hppa.h"
38 #include "elf32-hppa.h"
41 /* In order to gain some understanding of code in this file without
42 knowing all the intricate details of the linker, note the
45 Functions named elf32_hppa_* are called by external routines, other
46 functions are only called locally. elf32_hppa_* functions appear
47 in this file more or less in the order in which they are called
48 from external routines. eg. elf32_hppa_check_relocs is called
49 early in the link process, elf32_hppa_finish_dynamic_sections is
50 one of the last functions. */
52 /* We use two hash tables to hold information for linking PA ELF objects.
54 The first is the elf32_hppa_link_hash_table which is derived
55 from the standard ELF linker hash table. We use this as a place to
56 attach other hash tables and static information.
58 The second is the stub hash table which is derived from the
59 base BFD hash table. The stub hash table holds the information
60 necessary to build the linker stubs during a link.
62 There are a number of different stubs generated by the linker.
70 : addil LR'X - ($PIC_pcrel$0 - 4),%r1
71 : be,n RR'X - ($PIC_pcrel$0 - 8)(%sr4,%r1)
73 Import stub to call shared library routine from normal object file
74 (single sub-space version)
75 : addil LR'lt_ptr+ltoff,%dp ; get procedure entry point
76 : ldw RR'lt_ptr+ltoff(%r1),%r21
78 : ldw RR'lt_ptr+ltoff+4(%r1),%r19 ; get new dlt value.
80 Import stub to call shared library routine from shared library
81 (single sub-space version)
82 : addil LR'ltoff,%r19 ; get procedure entry point
83 : ldw RR'ltoff(%r1),%r21
85 : ldw RR'ltoff+4(%r1),%r19 ; get new dlt value.
87 Import stub to call shared library routine from normal object file
88 (multiple sub-space support)
89 : addil LR'lt_ptr+ltoff,%dp ; get procedure entry point
90 : ldw RR'lt_ptr+ltoff(%r1),%r21
91 : ldw RR'lt_ptr+ltoff+4(%r1),%r19 ; get new dlt value.
94 : be 0(%sr0,%r21) ; branch to target
95 : stw %rp,-24(%sp) ; save rp
97 Import stub to call shared library routine from shared library
98 (multiple sub-space support)
99 : addil LR'ltoff,%r19 ; get procedure entry point
100 : ldw RR'ltoff(%r1),%r21
101 : ldw RR'ltoff+4(%r1),%r19 ; get new dlt value.
104 : be 0(%sr0,%r21) ; branch to target
105 : stw %rp,-24(%sp) ; save rp
107 Export stub to return from shared lib routine (multiple sub-space support)
108 One of these is created for each exported procedure in a shared
109 library (and stored in the shared lib). Shared lib routines are
110 called via the first instruction in the export stub so that we can
111 do an inter-space return. Not required for single sub-space.
112 : bl,n X,%rp ; trap the return
114 : ldw -24(%sp),%rp ; restore the original rp
117 : be,n 0(%sr0,%rp) ; inter-space return. */
120 /* Variable names follow a coding style.
121 Please follow this (Apps Hungarian) style:
123 Structure/Variable Prefix
124 elf_link_hash_table "etab"
125 elf_link_hash_entry "eh"
127 elf32_hppa_link_hash_table "htab"
128 elf32_hppa_link_hash_entry "hh"
130 bfd_hash_table "btab"
133 bfd_hash_table containing stubs "bstab"
134 elf32_hppa_stub_hash_entry "hsh"
136 elf32_hppa_dyn_reloc_entry "hdh"
138 Always remember to use GNU Coding Style. */
140 #define PLT_ENTRY_SIZE 8
141 #define GOT_ENTRY_SIZE 4
142 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
144 static const bfd_byte plt_stub
[] =
146 0x0e, 0x80, 0x10, 0x96, /* 1: ldw 0(%r20),%r22 */
147 0xea, 0xc0, 0xc0, 0x00, /* bv %r0(%r22) */
148 0x0e, 0x88, 0x10, 0x95, /* ldw 4(%r20),%r21 */
149 #define PLT_STUB_ENTRY (3*4)
150 0xea, 0x9f, 0x1f, 0xdd, /* b,l 1b,%r20 */
151 0xd6, 0x80, 0x1c, 0x1e, /* depi 0,31,2,%r20 */
152 0x00, 0xc0, 0xff, 0xee, /* 9: .word fixup_func */
153 0xde, 0xad, 0xbe, 0xef /* .word fixup_ltp */
156 /* Section name for stubs is the associated section name plus this
158 #define STUB_SUFFIX ".stub"
160 /* We don't need to copy certain PC- or GP-relative dynamic relocs
161 into a shared object's dynamic section. All the relocs of the
162 limited class we are interested in, are absolute. */
163 #ifndef RELATIVE_DYNRELOCS
164 #define RELATIVE_DYNRELOCS 0
165 #define IS_ABSOLUTE_RELOC(r_type) 1
168 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
169 copying dynamic variables from a shared lib into an app's dynbss
170 section, and instead use a dynamic relocation to point into the
172 #define ELIMINATE_COPY_RELOCS 1
174 enum elf32_hppa_stub_type
176 hppa_stub_long_branch
,
177 hppa_stub_long_branch_shared
,
179 hppa_stub_import_shared
,
184 struct elf32_hppa_stub_hash_entry
186 /* Base hash table entry structure. */
187 struct bfd_hash_entry bh_root
;
189 /* The stub section. */
192 /* Offset within stub_sec of the beginning of this stub. */
195 /* Given the symbol's value and its section we can determine its final
196 value when building the stubs (so the stub knows where to jump. */
197 bfd_vma target_value
;
198 asection
*target_section
;
200 enum elf32_hppa_stub_type stub_type
;
202 /* The symbol table entry, if any, that this was derived from. */
203 struct elf32_hppa_link_hash_entry
*hh
;
205 /* Where this stub is being called from, or, in the case of combined
206 stub sections, the first input section in the group. */
210 struct elf32_hppa_link_hash_entry
212 struct elf_link_hash_entry eh
;
214 /* A pointer to the most recently used stub hash entry against this
216 struct elf32_hppa_stub_hash_entry
*hsh_cache
;
218 /* Used to count relocations for delayed sizing of relocation
220 struct elf32_hppa_dyn_reloc_entry
222 /* Next relocation in the chain. */
223 struct elf32_hppa_dyn_reloc_entry
*hdh_next
;
225 /* The input section of the reloc. */
228 /* Number of relocs copied in this section. */
231 #if RELATIVE_DYNRELOCS
232 /* Number of relative relocs copied for the input section. */
233 bfd_size_type relative_count
;
239 GOT_UNKNOWN
= 0, GOT_NORMAL
= 1, GOT_TLS_GD
= 2, GOT_TLS_LDM
= 4, GOT_TLS_IE
= 8
242 /* Set if this symbol is used by a plabel reloc. */
243 unsigned int plabel
:1;
246 struct elf32_hppa_link_hash_table
248 /* The main hash table. */
249 struct elf_link_hash_table etab
;
251 /* The stub hash table. */
252 struct bfd_hash_table bstab
;
254 /* Linker stub bfd. */
257 /* Linker call-backs. */
258 asection
* (*add_stub_section
) (const char *, asection
*);
259 void (*layout_sections_again
) (void);
261 /* Array to keep track of which stub sections have been created, and
262 information on stub grouping. */
265 /* This is the section to which stubs in the group will be
268 /* The stub section. */
272 /* Assorted information used by elf32_hppa_size_stubs. */
273 unsigned int bfd_count
;
275 asection
**input_list
;
276 Elf_Internal_Sym
**all_local_syms
;
278 /* Short-cuts to get to dynamic linker sections. */
286 /* Used during a final link to store the base of the text and data
287 segments so that we can perform SEGREL relocations. */
288 bfd_vma text_segment_base
;
289 bfd_vma data_segment_base
;
291 /* Whether we support multiple sub-spaces for shared libs. */
292 unsigned int multi_subspace
:1;
294 /* Flags set when various size branches are detected. Used to
295 select suitable defaults for the stub group size. */
296 unsigned int has_12bit_branch
:1;
297 unsigned int has_17bit_branch
:1;
298 unsigned int has_22bit_branch
:1;
300 /* Set if we need a .plt stub to support lazy dynamic linking. */
301 unsigned int need_plt_stub
:1;
303 /* Small local sym to section mapping cache. */
304 struct sym_sec_cache sym_sec
;
306 /* Data for LDM relocations. */
309 bfd_signed_vma refcount
;
314 /* Various hash macros and functions. */
315 #define hppa_link_hash_table(p) \
316 ((struct elf32_hppa_link_hash_table *) ((p)->hash))
318 #define hppa_elf_hash_entry(ent) \
319 ((struct elf32_hppa_link_hash_entry *)(ent))
321 #define hppa_stub_hash_entry(ent) \
322 ((struct elf32_hppa_stub_hash_entry *)(ent))
324 #define hppa_stub_hash_lookup(table, string, create, copy) \
325 ((struct elf32_hppa_stub_hash_entry *) \
326 bfd_hash_lookup ((table), (string), (create), (copy)))
328 #define hppa_elf_local_got_tls_type(abfd) \
329 ((char *)(elf_local_got_offsets (abfd) + (elf_tdata (abfd)->symtab_hdr.sh_info * 2)))
331 #define hh_name(hh) \
332 (hh ? hh->eh.root.root.string : "<undef>")
334 #define eh_name(eh) \
335 (eh ? eh->root.root.string : "<undef>")
337 /* Override the generic function because we want to mark our BFDs. */
340 elf32_hppa_mkobject (bfd
*abfd
)
342 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_obj_tdata
),
346 /* Assorted hash table functions. */
348 /* Initialize an entry in the stub hash table. */
350 static struct bfd_hash_entry
*
351 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
352 struct bfd_hash_table
*table
,
355 /* Allocate the structure if it has not already been allocated by a
359 entry
= bfd_hash_allocate (table
,
360 sizeof (struct elf32_hppa_stub_hash_entry
));
365 /* Call the allocation method of the superclass. */
366 entry
= bfd_hash_newfunc (entry
, table
, string
);
369 struct elf32_hppa_stub_hash_entry
*hsh
;
371 /* Initialize the local fields. */
372 hsh
= hppa_stub_hash_entry (entry
);
373 hsh
->stub_sec
= NULL
;
374 hsh
->stub_offset
= 0;
375 hsh
->target_value
= 0;
376 hsh
->target_section
= NULL
;
377 hsh
->stub_type
= hppa_stub_long_branch
;
385 /* Initialize an entry in the link hash table. */
387 static struct bfd_hash_entry
*
388 hppa_link_hash_newfunc (struct bfd_hash_entry
*entry
,
389 struct bfd_hash_table
*table
,
392 /* Allocate the structure if it has not already been allocated by a
396 entry
= bfd_hash_allocate (table
,
397 sizeof (struct elf32_hppa_link_hash_entry
));
402 /* Call the allocation method of the superclass. */
403 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
406 struct elf32_hppa_link_hash_entry
*hh
;
408 /* Initialize the local fields. */
409 hh
= hppa_elf_hash_entry (entry
);
410 hh
->hsh_cache
= NULL
;
411 hh
->dyn_relocs
= NULL
;
413 hh
->tls_type
= GOT_UNKNOWN
;
419 /* Create the derived linker hash table. The PA ELF port uses the derived
420 hash table to keep information specific to the PA ELF linker (without
421 using static variables). */
423 static struct bfd_link_hash_table
*
424 elf32_hppa_link_hash_table_create (bfd
*abfd
)
426 struct elf32_hppa_link_hash_table
*htab
;
427 bfd_size_type amt
= sizeof (*htab
);
429 htab
= bfd_malloc (amt
);
433 if (!_bfd_elf_link_hash_table_init (&htab
->etab
, abfd
, hppa_link_hash_newfunc
,
434 sizeof (struct elf32_hppa_link_hash_entry
)))
440 /* Init the stub hash table too. */
441 if (!bfd_hash_table_init (&htab
->bstab
, stub_hash_newfunc
,
442 sizeof (struct elf32_hppa_stub_hash_entry
)))
445 htab
->stub_bfd
= NULL
;
446 htab
->add_stub_section
= NULL
;
447 htab
->layout_sections_again
= NULL
;
448 htab
->stub_group
= NULL
;
450 htab
->srelgot
= NULL
;
452 htab
->srelplt
= NULL
;
453 htab
->sdynbss
= NULL
;
454 htab
->srelbss
= NULL
;
455 htab
->text_segment_base
= (bfd_vma
) -1;
456 htab
->data_segment_base
= (bfd_vma
) -1;
457 htab
->multi_subspace
= 0;
458 htab
->has_12bit_branch
= 0;
459 htab
->has_17bit_branch
= 0;
460 htab
->has_22bit_branch
= 0;
461 htab
->need_plt_stub
= 0;
462 htab
->sym_sec
.abfd
= NULL
;
463 htab
->tls_ldm_got
.refcount
= 0;
465 return &htab
->etab
.root
;
468 /* Free the derived linker hash table. */
471 elf32_hppa_link_hash_table_free (struct bfd_link_hash_table
*btab
)
473 struct elf32_hppa_link_hash_table
*htab
474 = (struct elf32_hppa_link_hash_table
*) btab
;
476 bfd_hash_table_free (&htab
->bstab
);
477 _bfd_generic_link_hash_table_free (btab
);
480 /* Build a name for an entry in the stub hash table. */
483 hppa_stub_name (const asection
*input_section
,
484 const asection
*sym_sec
,
485 const struct elf32_hppa_link_hash_entry
*hh
,
486 const Elf_Internal_Rela
*rela
)
493 len
= 8 + 1 + strlen (hh_name (hh
)) + 1 + 8 + 1;
494 stub_name
= bfd_malloc (len
);
495 if (stub_name
!= NULL
)
496 sprintf (stub_name
, "%08x_%s+%x",
497 input_section
->id
& 0xffffffff,
499 (int) rela
->r_addend
& 0xffffffff);
503 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
504 stub_name
= bfd_malloc (len
);
505 if (stub_name
!= NULL
)
506 sprintf (stub_name
, "%08x_%x:%x+%x",
507 input_section
->id
& 0xffffffff,
508 sym_sec
->id
& 0xffffffff,
509 (int) ELF32_R_SYM (rela
->r_info
) & 0xffffffff,
510 (int) rela
->r_addend
& 0xffffffff);
515 /* Look up an entry in the stub hash. Stub entries are cached because
516 creating the stub name takes a bit of time. */
518 static struct elf32_hppa_stub_hash_entry
*
519 hppa_get_stub_entry (const asection
*input_section
,
520 const asection
*sym_sec
,
521 struct elf32_hppa_link_hash_entry
*hh
,
522 const Elf_Internal_Rela
*rela
,
523 struct elf32_hppa_link_hash_table
*htab
)
525 struct elf32_hppa_stub_hash_entry
*hsh_entry
;
526 const asection
*id_sec
;
528 /* If this input section is part of a group of sections sharing one
529 stub section, then use the id of the first section in the group.
530 Stub names need to include a section id, as there may well be
531 more than one stub used to reach say, printf, and we need to
532 distinguish between them. */
533 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
535 if (hh
!= NULL
&& hh
->hsh_cache
!= NULL
536 && hh
->hsh_cache
->hh
== hh
537 && hh
->hsh_cache
->id_sec
== id_sec
)
539 hsh_entry
= hh
->hsh_cache
;
545 stub_name
= hppa_stub_name (id_sec
, sym_sec
, hh
, rela
);
546 if (stub_name
== NULL
)
549 hsh_entry
= hppa_stub_hash_lookup (&htab
->bstab
,
550 stub_name
, FALSE
, FALSE
);
552 hh
->hsh_cache
= hsh_entry
;
560 /* Add a new stub entry to the stub hash. Not all fields of the new
561 stub entry are initialised. */
563 static struct elf32_hppa_stub_hash_entry
*
564 hppa_add_stub (const char *stub_name
,
566 struct elf32_hppa_link_hash_table
*htab
)
570 struct elf32_hppa_stub_hash_entry
*hsh
;
572 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
573 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
574 if (stub_sec
== NULL
)
576 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
577 if (stub_sec
== NULL
)
583 namelen
= strlen (link_sec
->name
);
584 len
= namelen
+ sizeof (STUB_SUFFIX
);
585 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
589 memcpy (s_name
, link_sec
->name
, namelen
);
590 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
591 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
592 if (stub_sec
== NULL
)
594 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
596 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
599 /* Enter this entry into the linker stub hash table. */
600 hsh
= hppa_stub_hash_lookup (&htab
->bstab
, stub_name
,
604 (*_bfd_error_handler
) (_("%B: cannot create stub entry %s"),
610 hsh
->stub_sec
= stub_sec
;
611 hsh
->stub_offset
= 0;
612 hsh
->id_sec
= link_sec
;
616 /* Determine the type of stub needed, if any, for a call. */
618 static enum elf32_hppa_stub_type
619 hppa_type_of_stub (asection
*input_sec
,
620 const Elf_Internal_Rela
*rela
,
621 struct elf32_hppa_link_hash_entry
*hh
,
623 struct bfd_link_info
*info
)
626 bfd_vma branch_offset
;
627 bfd_vma max_branch_offset
;
631 && hh
->eh
.plt
.offset
!= (bfd_vma
) -1
632 && hh
->eh
.dynindx
!= -1
635 || !hh
->eh
.def_regular
636 || hh
->eh
.root
.type
== bfd_link_hash_defweak
))
638 /* We need an import stub. Decide between hppa_stub_import
639 and hppa_stub_import_shared later. */
640 return hppa_stub_import
;
643 /* Determine where the call point is. */
644 location
= (input_sec
->output_offset
645 + input_sec
->output_section
->vma
648 branch_offset
= destination
- location
- 8;
649 r_type
= ELF32_R_TYPE (rela
->r_info
);
651 /* Determine if a long branch stub is needed. parisc branch offsets
652 are relative to the second instruction past the branch, ie. +8
653 bytes on from the branch instruction location. The offset is
654 signed and counts in units of 4 bytes. */
655 if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
656 max_branch_offset
= (1 << (17 - 1)) << 2;
658 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
659 max_branch_offset
= (1 << (12 - 1)) << 2;
661 else /* R_PARISC_PCREL22F. */
662 max_branch_offset
= (1 << (22 - 1)) << 2;
664 if (branch_offset
+ max_branch_offset
>= 2*max_branch_offset
)
665 return hppa_stub_long_branch
;
667 return hppa_stub_none
;
670 /* Build one linker stub as defined by the stub hash table entry GEN_ENTRY.
671 IN_ARG contains the link info pointer. */
673 #define LDIL_R1 0x20200000 /* ldil LR'XXX,%r1 */
674 #define BE_SR4_R1 0xe0202002 /* be,n RR'XXX(%sr4,%r1) */
676 #define BL_R1 0xe8200000 /* b,l .+8,%r1 */
677 #define ADDIL_R1 0x28200000 /* addil LR'XXX,%r1,%r1 */
678 #define DEPI_R1 0xd4201c1e /* depi 0,31,2,%r1 */
680 #define ADDIL_DP 0x2b600000 /* addil LR'XXX,%dp,%r1 */
681 #define LDW_R1_R21 0x48350000 /* ldw RR'XXX(%sr0,%r1),%r21 */
682 #define BV_R0_R21 0xeaa0c000 /* bv %r0(%r21) */
683 #define LDW_R1_R19 0x48330000 /* ldw RR'XXX(%sr0,%r1),%r19 */
685 #define ADDIL_R19 0x2a600000 /* addil LR'XXX,%r19,%r1 */
686 #define LDW_R1_DP 0x483b0000 /* ldw RR'XXX(%sr0,%r1),%dp */
688 #define LDSID_R21_R1 0x02a010a1 /* ldsid (%sr0,%r21),%r1 */
689 #define MTSP_R1 0x00011820 /* mtsp %r1,%sr0 */
690 #define BE_SR0_R21 0xe2a00000 /* be 0(%sr0,%r21) */
691 #define STW_RP 0x6bc23fd1 /* stw %rp,-24(%sr0,%sp) */
693 #define BL22_RP 0xe800a002 /* b,l,n XXX,%rp */
694 #define BL_RP 0xe8400002 /* b,l,n XXX,%rp */
695 #define NOP 0x08000240 /* nop */
696 #define LDW_RP 0x4bc23fd1 /* ldw -24(%sr0,%sp),%rp */
697 #define LDSID_RP_R1 0x004010a1 /* ldsid (%sr0,%rp),%r1 */
698 #define BE_SR0_RP 0xe0400002 /* be,n 0(%sr0,%rp) */
705 #define LDW_R1_DLT LDW_R1_R19
707 #define LDW_R1_DLT LDW_R1_DP
711 hppa_build_one_stub (struct bfd_hash_entry
*bh
, void *in_arg
)
713 struct elf32_hppa_stub_hash_entry
*hsh
;
714 struct bfd_link_info
*info
;
715 struct elf32_hppa_link_hash_table
*htab
;
725 /* Massage our args to the form they really have. */
726 hsh
= hppa_stub_hash_entry (bh
);
727 info
= (struct bfd_link_info
*)in_arg
;
729 htab
= hppa_link_hash_table (info
);
730 stub_sec
= hsh
->stub_sec
;
732 /* Make a note of the offset within the stubs for this entry. */
733 hsh
->stub_offset
= stub_sec
->size
;
734 loc
= stub_sec
->contents
+ hsh
->stub_offset
;
736 stub_bfd
= stub_sec
->owner
;
738 switch (hsh
->stub_type
)
740 case hppa_stub_long_branch
:
741 /* Create the long branch. A long branch is formed with "ldil"
742 loading the upper bits of the target address into a register,
743 then branching with "be" which adds in the lower bits.
744 The "be" has its delay slot nullified. */
745 sym_value
= (hsh
->target_value
746 + hsh
->target_section
->output_offset
747 + hsh
->target_section
->output_section
->vma
);
749 val
= hppa_field_adjust (sym_value
, 0, e_lrsel
);
750 insn
= hppa_rebuild_insn ((int) LDIL_R1
, val
, 21);
751 bfd_put_32 (stub_bfd
, insn
, loc
);
753 val
= hppa_field_adjust (sym_value
, 0, e_rrsel
) >> 2;
754 insn
= hppa_rebuild_insn ((int) BE_SR4_R1
, val
, 17);
755 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
760 case hppa_stub_long_branch_shared
:
761 /* Branches are relative. This is where we are going to. */
762 sym_value
= (hsh
->target_value
763 + hsh
->target_section
->output_offset
764 + hsh
->target_section
->output_section
->vma
);
766 /* And this is where we are coming from, more or less. */
767 sym_value
-= (hsh
->stub_offset
768 + stub_sec
->output_offset
769 + stub_sec
->output_section
->vma
);
771 bfd_put_32 (stub_bfd
, (bfd_vma
) BL_R1
, loc
);
772 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_lrsel
);
773 insn
= hppa_rebuild_insn ((int) ADDIL_R1
, val
, 21);
774 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
776 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_rrsel
) >> 2;
777 insn
= hppa_rebuild_insn ((int) BE_SR4_R1
, val
, 17);
778 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
782 case hppa_stub_import
:
783 case hppa_stub_import_shared
:
784 off
= hsh
->hh
->eh
.plt
.offset
;
785 if (off
>= (bfd_vma
) -2)
788 off
&= ~ (bfd_vma
) 1;
790 + htab
->splt
->output_offset
791 + htab
->splt
->output_section
->vma
792 - elf_gp (htab
->splt
->output_section
->owner
));
796 if (hsh
->stub_type
== hppa_stub_import_shared
)
799 val
= hppa_field_adjust (sym_value
, 0, e_lrsel
),
800 insn
= hppa_rebuild_insn ((int) insn
, val
, 21);
801 bfd_put_32 (stub_bfd
, insn
, loc
);
803 /* It is critical to use lrsel/rrsel here because we are using
804 two different offsets (+0 and +4) from sym_value. If we use
805 lsel/rsel then with unfortunate sym_values we will round
806 sym_value+4 up to the next 2k block leading to a mis-match
807 between the lsel and rsel value. */
808 val
= hppa_field_adjust (sym_value
, 0, e_rrsel
);
809 insn
= hppa_rebuild_insn ((int) LDW_R1_R21
, val
, 14);
810 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
812 if (htab
->multi_subspace
)
814 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 4, e_rrsel
);
815 insn
= hppa_rebuild_insn ((int) LDW_R1_DLT
, val
, 14);
816 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
818 bfd_put_32 (stub_bfd
, (bfd_vma
) LDSID_R21_R1
, loc
+ 12);
819 bfd_put_32 (stub_bfd
, (bfd_vma
) MTSP_R1
, loc
+ 16);
820 bfd_put_32 (stub_bfd
, (bfd_vma
) BE_SR0_R21
, loc
+ 20);
821 bfd_put_32 (stub_bfd
, (bfd_vma
) STW_RP
, loc
+ 24);
827 bfd_put_32 (stub_bfd
, (bfd_vma
) BV_R0_R21
, loc
+ 8);
828 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 4, e_rrsel
);
829 insn
= hppa_rebuild_insn ((int) LDW_R1_DLT
, val
, 14);
830 bfd_put_32 (stub_bfd
, insn
, loc
+ 12);
837 case hppa_stub_export
:
838 /* Branches are relative. This is where we are going to. */
839 sym_value
= (hsh
->target_value
840 + hsh
->target_section
->output_offset
841 + hsh
->target_section
->output_section
->vma
);
843 /* And this is where we are coming from. */
844 sym_value
-= (hsh
->stub_offset
845 + stub_sec
->output_offset
846 + stub_sec
->output_section
->vma
);
848 if (sym_value
- 8 + (1 << (17 + 1)) >= (1 << (17 + 2))
849 && (!htab
->has_22bit_branch
850 || sym_value
- 8 + (1 << (22 + 1)) >= (1 << (22 + 2))))
852 (*_bfd_error_handler
)
853 (_("%B(%A+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
854 hsh
->target_section
->owner
,
856 (long) hsh
->stub_offset
,
857 hsh
->bh_root
.string
);
858 bfd_set_error (bfd_error_bad_value
);
862 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_fsel
) >> 2;
863 if (!htab
->has_22bit_branch
)
864 insn
= hppa_rebuild_insn ((int) BL_RP
, val
, 17);
866 insn
= hppa_rebuild_insn ((int) BL22_RP
, val
, 22);
867 bfd_put_32 (stub_bfd
, insn
, loc
);
869 bfd_put_32 (stub_bfd
, (bfd_vma
) NOP
, loc
+ 4);
870 bfd_put_32 (stub_bfd
, (bfd_vma
) LDW_RP
, loc
+ 8);
871 bfd_put_32 (stub_bfd
, (bfd_vma
) LDSID_RP_R1
, loc
+ 12);
872 bfd_put_32 (stub_bfd
, (bfd_vma
) MTSP_R1
, loc
+ 16);
873 bfd_put_32 (stub_bfd
, (bfd_vma
) BE_SR0_RP
, loc
+ 20);
875 /* Point the function symbol at the stub. */
876 hsh
->hh
->eh
.root
.u
.def
.section
= stub_sec
;
877 hsh
->hh
->eh
.root
.u
.def
.value
= stub_sec
->size
;
887 stub_sec
->size
+= size
;
912 /* As above, but don't actually build the stub. Just bump offset so
913 we know stub section sizes. */
916 hppa_size_one_stub (struct bfd_hash_entry
*bh
, void *in_arg
)
918 struct elf32_hppa_stub_hash_entry
*hsh
;
919 struct elf32_hppa_link_hash_table
*htab
;
922 /* Massage our args to the form they really have. */
923 hsh
= hppa_stub_hash_entry (bh
);
926 if (hsh
->stub_type
== hppa_stub_long_branch
)
928 else if (hsh
->stub_type
== hppa_stub_long_branch_shared
)
930 else if (hsh
->stub_type
== hppa_stub_export
)
932 else /* hppa_stub_import or hppa_stub_import_shared. */
934 if (htab
->multi_subspace
)
940 hsh
->stub_sec
->size
+= size
;
944 /* Return nonzero if ABFD represents an HPPA ELF32 file.
945 Additionally we set the default architecture and machine. */
948 elf32_hppa_object_p (bfd
*abfd
)
950 Elf_Internal_Ehdr
* i_ehdrp
;
953 i_ehdrp
= elf_elfheader (abfd
);
954 if (strcmp (bfd_get_target (abfd
), "elf32-hppa-linux") == 0)
956 /* GCC on hppa-linux produces binaries with OSABI=Linux,
957 but the kernel produces corefiles with OSABI=SysV. */
958 if (i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_LINUX
&&
959 i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_NONE
) /* aka SYSV */
962 else if (strcmp (bfd_get_target (abfd
), "elf32-hppa-netbsd") == 0)
964 /* GCC on hppa-netbsd produces binaries with OSABI=NetBSD,
965 but the kernel produces corefiles with OSABI=SysV. */
966 if (i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_NETBSD
&&
967 i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_NONE
) /* aka SYSV */
972 if (i_ehdrp
->e_ident
[EI_OSABI
] != ELFOSABI_HPUX
)
976 flags
= i_ehdrp
->e_flags
;
977 switch (flags
& (EF_PARISC_ARCH
| EF_PARISC_WIDE
))
980 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 10);
982 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 11);
984 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 20);
985 case EFA_PARISC_2_0
| EF_PARISC_WIDE
:
986 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 25);
991 /* Create the .plt and .got sections, and set up our hash table
992 short-cuts to various dynamic sections. */
995 elf32_hppa_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
997 struct elf32_hppa_link_hash_table
*htab
;
998 struct elf_link_hash_entry
*eh
;
1000 /* Don't try to create the .plt and .got twice. */
1001 htab
= hppa_link_hash_table (info
);
1002 if (htab
->splt
!= NULL
)
1005 /* Call the generic code to do most of the work. */
1006 if (! _bfd_elf_create_dynamic_sections (abfd
, info
))
1009 htab
->splt
= bfd_get_section_by_name (abfd
, ".plt");
1010 htab
->srelplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
1012 htab
->sgot
= bfd_get_section_by_name (abfd
, ".got");
1013 htab
->srelgot
= bfd_make_section_with_flags (abfd
, ".rela.got",
1018 | SEC_LINKER_CREATED
1020 if (htab
->srelgot
== NULL
1021 || ! bfd_set_section_alignment (abfd
, htab
->srelgot
, 2))
1024 htab
->sdynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
1025 htab
->srelbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
1027 /* hppa-linux needs _GLOBAL_OFFSET_TABLE_ to be visible from the main
1028 application, because __canonicalize_funcptr_for_compare needs it. */
1029 eh
= elf_hash_table (info
)->hgot
;
1030 eh
->forced_local
= 0;
1031 eh
->other
= STV_DEFAULT
;
1032 return bfd_elf_link_record_dynamic_symbol (info
, eh
);
1035 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1038 elf32_hppa_copy_indirect_symbol (struct bfd_link_info
*info
,
1039 struct elf_link_hash_entry
*eh_dir
,
1040 struct elf_link_hash_entry
*eh_ind
)
1042 struct elf32_hppa_link_hash_entry
*hh_dir
, *hh_ind
;
1044 hh_dir
= hppa_elf_hash_entry (eh_dir
);
1045 hh_ind
= hppa_elf_hash_entry (eh_ind
);
1047 if (hh_ind
->dyn_relocs
!= NULL
)
1049 if (hh_dir
->dyn_relocs
!= NULL
)
1051 struct elf32_hppa_dyn_reloc_entry
**hdh_pp
;
1052 struct elf32_hppa_dyn_reloc_entry
*hdh_p
;
1054 /* Add reloc counts against the indirect sym to the direct sym
1055 list. Merge any entries against the same section. */
1056 for (hdh_pp
= &hh_ind
->dyn_relocs
; (hdh_p
= *hdh_pp
) != NULL
; )
1058 struct elf32_hppa_dyn_reloc_entry
*hdh_q
;
1060 for (hdh_q
= hh_dir
->dyn_relocs
;
1062 hdh_q
= hdh_q
->hdh_next
)
1063 if (hdh_q
->sec
== hdh_p
->sec
)
1065 #if RELATIVE_DYNRELOCS
1066 hdh_q
->relative_count
+= hdh_p
->relative_count
;
1068 hdh_q
->count
+= hdh_p
->count
;
1069 *hdh_pp
= hdh_p
->hdh_next
;
1073 hdh_pp
= &hdh_p
->hdh_next
;
1075 *hdh_pp
= hh_dir
->dyn_relocs
;
1078 hh_dir
->dyn_relocs
= hh_ind
->dyn_relocs
;
1079 hh_ind
->dyn_relocs
= NULL
;
1082 if (ELIMINATE_COPY_RELOCS
1083 && eh_ind
->root
.type
!= bfd_link_hash_indirect
1084 && eh_dir
->dynamic_adjusted
)
1086 /* If called to transfer flags for a weakdef during processing
1087 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1088 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1089 eh_dir
->ref_dynamic
|= eh_ind
->ref_dynamic
;
1090 eh_dir
->ref_regular
|= eh_ind
->ref_regular
;
1091 eh_dir
->ref_regular_nonweak
|= eh_ind
->ref_regular_nonweak
;
1092 eh_dir
->needs_plt
|= eh_ind
->needs_plt
;
1096 if (eh_ind
->root
.type
== bfd_link_hash_indirect
1097 && eh_dir
->got
.refcount
<= 0)
1099 hh_dir
->tls_type
= hh_ind
->tls_type
;
1100 hh_ind
->tls_type
= GOT_UNKNOWN
;
1103 _bfd_elf_link_hash_copy_indirect (info
, eh_dir
, eh_ind
);
1108 elf32_hppa_optimized_tls_reloc (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1109 int r_type
, int is_local ATTRIBUTE_UNUSED
)
1111 /* For now we don't support linker optimizations. */
1115 /* Look through the relocs for a section during the first phase, and
1116 calculate needed space in the global offset table, procedure linkage
1117 table, and dynamic reloc sections. At this point we haven't
1118 necessarily read all the input files. */
1121 elf32_hppa_check_relocs (bfd
*abfd
,
1122 struct bfd_link_info
*info
,
1124 const Elf_Internal_Rela
*relocs
)
1126 Elf_Internal_Shdr
*symtab_hdr
;
1127 struct elf_link_hash_entry
**eh_syms
;
1128 const Elf_Internal_Rela
*rela
;
1129 const Elf_Internal_Rela
*rela_end
;
1130 struct elf32_hppa_link_hash_table
*htab
;
1132 asection
*stubreloc
;
1133 int tls_type
= GOT_UNKNOWN
, old_tls_type
= GOT_UNKNOWN
;
1135 if (info
->relocatable
)
1138 htab
= hppa_link_hash_table (info
);
1139 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1140 eh_syms
= elf_sym_hashes (abfd
);
1144 rela_end
= relocs
+ sec
->reloc_count
;
1145 for (rela
= relocs
; rela
< rela_end
; rela
++)
1154 unsigned int r_symndx
, r_type
;
1155 struct elf32_hppa_link_hash_entry
*hh
;
1158 r_symndx
= ELF32_R_SYM (rela
->r_info
);
1160 if (r_symndx
< symtab_hdr
->sh_info
)
1164 hh
= hppa_elf_hash_entry (eh_syms
[r_symndx
- symtab_hdr
->sh_info
]);
1165 while (hh
->eh
.root
.type
== bfd_link_hash_indirect
1166 || hh
->eh
.root
.type
== bfd_link_hash_warning
)
1167 hh
= hppa_elf_hash_entry (hh
->eh
.root
.u
.i
.link
);
1170 r_type
= ELF32_R_TYPE (rela
->r_info
);
1171 r_type
= elf32_hppa_optimized_tls_reloc (info
, r_type
, hh
== NULL
);
1175 case R_PARISC_DLTIND14F
:
1176 case R_PARISC_DLTIND14R
:
1177 case R_PARISC_DLTIND21L
:
1178 /* This symbol requires a global offset table entry. */
1179 need_entry
= NEED_GOT
;
1182 case R_PARISC_PLABEL14R
: /* "Official" procedure labels. */
1183 case R_PARISC_PLABEL21L
:
1184 case R_PARISC_PLABEL32
:
1185 /* If the addend is non-zero, we break badly. */
1186 if (rela
->r_addend
!= 0)
1189 /* If we are creating a shared library, then we need to
1190 create a PLT entry for all PLABELs, because PLABELs with
1191 local symbols may be passed via a pointer to another
1192 object. Additionally, output a dynamic relocation
1193 pointing to the PLT entry.
1195 For executables, the original 32-bit ABI allowed two
1196 different styles of PLABELs (function pointers): For
1197 global functions, the PLABEL word points into the .plt
1198 two bytes past a (function address, gp) pair, and for
1199 local functions the PLABEL points directly at the
1200 function. The magic +2 for the first type allows us to
1201 differentiate between the two. As you can imagine, this
1202 is a real pain when it comes to generating code to call
1203 functions indirectly or to compare function pointers.
1204 We avoid the mess by always pointing a PLABEL into the
1205 .plt, even for local functions. */
1206 need_entry
= PLT_PLABEL
| NEED_PLT
| NEED_DYNREL
;
1209 case R_PARISC_PCREL12F
:
1210 htab
->has_12bit_branch
= 1;
1213 case R_PARISC_PCREL17C
:
1214 case R_PARISC_PCREL17F
:
1215 htab
->has_17bit_branch
= 1;
1218 case R_PARISC_PCREL22F
:
1219 htab
->has_22bit_branch
= 1;
1221 /* Function calls might need to go through the .plt, and
1222 might require long branch stubs. */
1225 /* We know local syms won't need a .plt entry, and if
1226 they need a long branch stub we can't guarantee that
1227 we can reach the stub. So just flag an error later
1228 if we're doing a shared link and find we need a long
1234 /* Global symbols will need a .plt entry if they remain
1235 global, and in most cases won't need a long branch
1236 stub. Unfortunately, we have to cater for the case
1237 where a symbol is forced local by versioning, or due
1238 to symbolic linking, and we lose the .plt entry. */
1239 need_entry
= NEED_PLT
;
1240 if (hh
->eh
.type
== STT_PARISC_MILLI
)
1245 case R_PARISC_SEGBASE
: /* Used to set segment base. */
1246 case R_PARISC_SEGREL32
: /* Relative reloc, used for unwind. */
1247 case R_PARISC_PCREL14F
: /* PC relative load/store. */
1248 case R_PARISC_PCREL14R
:
1249 case R_PARISC_PCREL17R
: /* External branches. */
1250 case R_PARISC_PCREL21L
: /* As above, and for load/store too. */
1251 case R_PARISC_PCREL32
:
1252 /* We don't need to propagate the relocation if linking a
1253 shared object since these are section relative. */
1256 case R_PARISC_DPREL14F
: /* Used for gp rel data load/store. */
1257 case R_PARISC_DPREL14R
:
1258 case R_PARISC_DPREL21L
:
1261 (*_bfd_error_handler
)
1262 (_("%B: relocation %s can not be used when making a shared object; recompile with -fPIC"),
1264 elf_hppa_howto_table
[r_type
].name
);
1265 bfd_set_error (bfd_error_bad_value
);
1270 case R_PARISC_DIR17F
: /* Used for external branches. */
1271 case R_PARISC_DIR17R
:
1272 case R_PARISC_DIR14F
: /* Used for load/store from absolute locn. */
1273 case R_PARISC_DIR14R
:
1274 case R_PARISC_DIR21L
: /* As above, and for ext branches too. */
1275 case R_PARISC_DIR32
: /* .word relocs. */
1276 /* We may want to output a dynamic relocation later. */
1277 need_entry
= NEED_DYNREL
;
1280 /* This relocation describes the C++ object vtable hierarchy.
1281 Reconstruct it for later use during GC. */
1282 case R_PARISC_GNU_VTINHERIT
:
1283 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, &hh
->eh
, rela
->r_offset
))
1287 /* This relocation describes which C++ vtable entries are actually
1288 used. Record for later use during GC. */
1289 case R_PARISC_GNU_VTENTRY
:
1290 BFD_ASSERT (hh
!= NULL
);
1292 && !bfd_elf_gc_record_vtentry (abfd
, sec
, &hh
->eh
, rela
->r_addend
))
1296 case R_PARISC_TLS_GD21L
:
1297 case R_PARISC_TLS_GD14R
:
1298 case R_PARISC_TLS_LDM21L
:
1299 case R_PARISC_TLS_LDM14R
:
1300 need_entry
= NEED_GOT
;
1303 case R_PARISC_TLS_IE21L
:
1304 case R_PARISC_TLS_IE14R
:
1306 info
->flags
|= DF_STATIC_TLS
;
1307 need_entry
= NEED_GOT
;
1314 /* Now carry out our orders. */
1315 if (need_entry
& NEED_GOT
)
1320 tls_type
= GOT_NORMAL
;
1322 case R_PARISC_TLS_GD21L
:
1323 case R_PARISC_TLS_GD14R
:
1324 tls_type
|= GOT_TLS_GD
;
1326 case R_PARISC_TLS_LDM21L
:
1327 case R_PARISC_TLS_LDM14R
:
1328 tls_type
|= GOT_TLS_LDM
;
1330 case R_PARISC_TLS_IE21L
:
1331 case R_PARISC_TLS_IE14R
:
1332 tls_type
|= GOT_TLS_IE
;
1336 /* Allocate space for a GOT entry, as well as a dynamic
1337 relocation for this entry. */
1338 if (htab
->sgot
== NULL
)
1340 if (htab
->etab
.dynobj
== NULL
)
1341 htab
->etab
.dynobj
= abfd
;
1342 if (!elf32_hppa_create_dynamic_sections (htab
->etab
.dynobj
, info
))
1346 if (r_type
== R_PARISC_TLS_LDM21L
1347 || r_type
== R_PARISC_TLS_LDM14R
)
1348 hppa_link_hash_table (info
)->tls_ldm_got
.refcount
+= 1;
1353 hh
->eh
.got
.refcount
+= 1;
1354 old_tls_type
= hh
->tls_type
;
1358 bfd_signed_vma
*local_got_refcounts
;
1360 /* This is a global offset table entry for a local symbol. */
1361 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1362 if (local_got_refcounts
== NULL
)
1366 /* Allocate space for local got offsets and local
1367 plt offsets. Done this way to save polluting
1368 elf_obj_tdata with another target specific
1370 size
= symtab_hdr
->sh_info
;
1371 size
*= 2 * sizeof (bfd_signed_vma
);
1372 /* Add in space to store the local GOT TLS types. */
1373 size
+= symtab_hdr
->sh_info
;
1374 local_got_refcounts
= bfd_zalloc (abfd
, size
);
1375 if (local_got_refcounts
== NULL
)
1377 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1378 memset (hppa_elf_local_got_tls_type (abfd
),
1379 GOT_UNKNOWN
, symtab_hdr
->sh_info
);
1381 local_got_refcounts
[r_symndx
] += 1;
1383 old_tls_type
= hppa_elf_local_got_tls_type (abfd
) [r_symndx
];
1386 tls_type
|= old_tls_type
;
1388 if (old_tls_type
!= tls_type
)
1391 hh
->tls_type
= tls_type
;
1393 hppa_elf_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
1399 if (need_entry
& NEED_PLT
)
1401 /* If we are creating a shared library, and this is a reloc
1402 against a weak symbol or a global symbol in a dynamic
1403 object, then we will be creating an import stub and a
1404 .plt entry for the symbol. Similarly, on a normal link
1405 to symbols defined in a dynamic object we'll need the
1406 import stub and a .plt entry. We don't know yet whether
1407 the symbol is defined or not, so make an entry anyway and
1408 clean up later in adjust_dynamic_symbol. */
1409 if ((sec
->flags
& SEC_ALLOC
) != 0)
1413 hh
->eh
.needs_plt
= 1;
1414 hh
->eh
.plt
.refcount
+= 1;
1416 /* If this .plt entry is for a plabel, mark it so
1417 that adjust_dynamic_symbol will keep the entry
1418 even if it appears to be local. */
1419 if (need_entry
& PLT_PLABEL
)
1422 else if (need_entry
& PLT_PLABEL
)
1424 bfd_signed_vma
*local_got_refcounts
;
1425 bfd_signed_vma
*local_plt_refcounts
;
1427 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1428 if (local_got_refcounts
== NULL
)
1432 /* Allocate space for local got offsets and local
1434 size
= symtab_hdr
->sh_info
;
1435 size
*= 2 * sizeof (bfd_signed_vma
);
1436 /* Add in space to store the local GOT TLS types. */
1437 size
+= symtab_hdr
->sh_info
;
1438 local_got_refcounts
= bfd_zalloc (abfd
, size
);
1439 if (local_got_refcounts
== NULL
)
1441 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1443 local_plt_refcounts
= (local_got_refcounts
1444 + symtab_hdr
->sh_info
);
1445 local_plt_refcounts
[r_symndx
] += 1;
1450 if (need_entry
& NEED_DYNREL
)
1452 /* Flag this symbol as having a non-got, non-plt reference
1453 so that we generate copy relocs if it turns out to be
1455 if (hh
!= NULL
&& !info
->shared
)
1456 hh
->eh
.non_got_ref
= 1;
1458 /* If we are creating a shared library then we need to copy
1459 the reloc into the shared library. However, if we are
1460 linking with -Bsymbolic, we need only copy absolute
1461 relocs or relocs against symbols that are not defined in
1462 an object we are including in the link. PC- or DP- or
1463 DLT-relative relocs against any local sym or global sym
1464 with DEF_REGULAR set, can be discarded. At this point we
1465 have not seen all the input files, so it is possible that
1466 DEF_REGULAR is not set now but will be set later (it is
1467 never cleared). We account for that possibility below by
1468 storing information in the dyn_relocs field of the
1471 A similar situation to the -Bsymbolic case occurs when
1472 creating shared libraries and symbol visibility changes
1473 render the symbol local.
1475 As it turns out, all the relocs we will be creating here
1476 are absolute, so we cannot remove them on -Bsymbolic
1477 links or visibility changes anyway. A STUB_REL reloc
1478 is absolute too, as in that case it is the reloc in the
1479 stub we will be creating, rather than copying the PCREL
1480 reloc in the branch.
1482 If on the other hand, we are creating an executable, we
1483 may need to keep relocations for symbols satisfied by a
1484 dynamic library if we manage to avoid copy relocs for the
1487 && (sec
->flags
& SEC_ALLOC
) != 0
1488 && (IS_ABSOLUTE_RELOC (r_type
)
1491 || hh
->eh
.root
.type
== bfd_link_hash_defweak
1492 || !hh
->eh
.def_regular
))))
1493 || (ELIMINATE_COPY_RELOCS
1495 && (sec
->flags
& SEC_ALLOC
) != 0
1497 && (hh
->eh
.root
.type
== bfd_link_hash_defweak
1498 || !hh
->eh
.def_regular
)))
1500 struct elf32_hppa_dyn_reloc_entry
*hdh_p
;
1501 struct elf32_hppa_dyn_reloc_entry
**hdh_head
;
1503 /* Create a reloc section in dynobj and make room for
1510 name
= (bfd_elf_string_from_elf_section
1512 elf_elfheader (abfd
)->e_shstrndx
,
1513 elf_section_data (sec
)->rel_hdr
.sh_name
));
1516 (*_bfd_error_handler
)
1517 (_("Could not find relocation section for %s"),
1519 bfd_set_error (bfd_error_bad_value
);
1523 if (htab
->etab
.dynobj
== NULL
)
1524 htab
->etab
.dynobj
= abfd
;
1526 dynobj
= htab
->etab
.dynobj
;
1527 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1532 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
1533 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1534 if ((sec
->flags
& SEC_ALLOC
) != 0)
1535 flags
|= SEC_ALLOC
| SEC_LOAD
;
1536 sreloc
= bfd_make_section_with_flags (dynobj
,
1540 || !bfd_set_section_alignment (dynobj
, sreloc
, 2))
1544 elf_section_data (sec
)->sreloc
= sreloc
;
1547 /* If this is a global symbol, we count the number of
1548 relocations we need for this symbol. */
1551 hdh_head
= &hh
->dyn_relocs
;
1555 /* Track dynamic relocs needed for local syms too.
1556 We really need local syms available to do this
1562 sr
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
1567 vpp
= &elf_section_data (sr
)->local_dynrel
;
1568 hdh_head
= (struct elf32_hppa_dyn_reloc_entry
**) vpp
;
1572 if (hdh_p
== NULL
|| hdh_p
->sec
!= sec
)
1574 hdh_p
= bfd_alloc (htab
->etab
.dynobj
, sizeof *hdh_p
);
1577 hdh_p
->hdh_next
= *hdh_head
;
1581 #if RELATIVE_DYNRELOCS
1582 hdh_p
->relative_count
= 0;
1587 #if RELATIVE_DYNRELOCS
1588 if (!IS_ABSOLUTE_RELOC (rtype
))
1589 hdh_p
->relative_count
+= 1;
1598 /* Return the section that should be marked against garbage collection
1599 for a given relocation. */
1602 elf32_hppa_gc_mark_hook (asection
*sec
,
1603 struct bfd_link_info
*info
,
1604 Elf_Internal_Rela
*rela
,
1605 struct elf_link_hash_entry
*hh
,
1606 Elf_Internal_Sym
*sym
)
1609 switch ((unsigned int) ELF32_R_TYPE (rela
->r_info
))
1611 case R_PARISC_GNU_VTINHERIT
:
1612 case R_PARISC_GNU_VTENTRY
:
1616 return _bfd_elf_gc_mark_hook (sec
, info
, rela
, hh
, sym
);
1619 /* Update the got and plt entry reference counts for the section being
1623 elf32_hppa_gc_sweep_hook (bfd
*abfd
,
1624 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
1626 const Elf_Internal_Rela
*relocs
)
1628 Elf_Internal_Shdr
*symtab_hdr
;
1629 struct elf_link_hash_entry
**eh_syms
;
1630 bfd_signed_vma
*local_got_refcounts
;
1631 bfd_signed_vma
*local_plt_refcounts
;
1632 const Elf_Internal_Rela
*rela
, *relend
;
1634 if (info
->relocatable
)
1637 elf_section_data (sec
)->local_dynrel
= NULL
;
1639 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1640 eh_syms
= elf_sym_hashes (abfd
);
1641 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1642 local_plt_refcounts
= local_got_refcounts
;
1643 if (local_plt_refcounts
!= NULL
)
1644 local_plt_refcounts
+= symtab_hdr
->sh_info
;
1646 relend
= relocs
+ sec
->reloc_count
;
1647 for (rela
= relocs
; rela
< relend
; rela
++)
1649 unsigned long r_symndx
;
1650 unsigned int r_type
;
1651 struct elf_link_hash_entry
*eh
= NULL
;
1653 r_symndx
= ELF32_R_SYM (rela
->r_info
);
1654 if (r_symndx
>= symtab_hdr
->sh_info
)
1656 struct elf32_hppa_link_hash_entry
*hh
;
1657 struct elf32_hppa_dyn_reloc_entry
**hdh_pp
;
1658 struct elf32_hppa_dyn_reloc_entry
*hdh_p
;
1660 eh
= eh_syms
[r_symndx
- symtab_hdr
->sh_info
];
1661 while (eh
->root
.type
== bfd_link_hash_indirect
1662 || eh
->root
.type
== bfd_link_hash_warning
)
1663 eh
= (struct elf_link_hash_entry
*) eh
->root
.u
.i
.link
;
1664 hh
= hppa_elf_hash_entry (eh
);
1666 for (hdh_pp
= &hh
->dyn_relocs
; (hdh_p
= *hdh_pp
) != NULL
; hdh_pp
= &hdh_p
->hdh_next
)
1667 if (hdh_p
->sec
== sec
)
1669 /* Everything must go for SEC. */
1670 *hdh_pp
= hdh_p
->hdh_next
;
1675 r_type
= ELF32_R_TYPE (rela
->r_info
);
1676 r_type
= elf32_hppa_optimized_tls_reloc (info
, r_type
, eh
!= NULL
);
1680 case R_PARISC_DLTIND14F
:
1681 case R_PARISC_DLTIND14R
:
1682 case R_PARISC_DLTIND21L
:
1683 case R_PARISC_TLS_GD21L
:
1684 case R_PARISC_TLS_GD14R
:
1685 case R_PARISC_TLS_IE21L
:
1686 case R_PARISC_TLS_IE14R
:
1689 if (eh
->got
.refcount
> 0)
1690 eh
->got
.refcount
-= 1;
1692 else if (local_got_refcounts
!= NULL
)
1694 if (local_got_refcounts
[r_symndx
] > 0)
1695 local_got_refcounts
[r_symndx
] -= 1;
1699 case R_PARISC_TLS_LDM21L
:
1700 case R_PARISC_TLS_LDM14R
:
1701 hppa_link_hash_table (info
)->tls_ldm_got
.refcount
-= 1;
1704 case R_PARISC_PCREL12F
:
1705 case R_PARISC_PCREL17C
:
1706 case R_PARISC_PCREL17F
:
1707 case R_PARISC_PCREL22F
:
1710 if (eh
->plt
.refcount
> 0)
1711 eh
->plt
.refcount
-= 1;
1715 case R_PARISC_PLABEL14R
:
1716 case R_PARISC_PLABEL21L
:
1717 case R_PARISC_PLABEL32
:
1720 if (eh
->plt
.refcount
> 0)
1721 eh
->plt
.refcount
-= 1;
1723 else if (local_plt_refcounts
!= NULL
)
1725 if (local_plt_refcounts
[r_symndx
] > 0)
1726 local_plt_refcounts
[r_symndx
] -= 1;
1738 /* Support for core dump NOTE sections. */
1741 elf32_hppa_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
1746 switch (note
->descsz
)
1751 case 396: /* Linux/hppa */
1753 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
1756 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
1765 /* Make a ".reg/999" section. */
1766 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
1767 size
, note
->descpos
+ offset
);
1771 elf32_hppa_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
1773 switch (note
->descsz
)
1778 case 124: /* Linux/hppa elf_prpsinfo. */
1779 elf_tdata (abfd
)->core_program
1780 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
1781 elf_tdata (abfd
)->core_command
1782 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
1785 /* Note that for some reason, a spurious space is tacked
1786 onto the end of the args in some (at least one anyway)
1787 implementations, so strip it off if it exists. */
1789 char *command
= elf_tdata (abfd
)->core_command
;
1790 int n
= strlen (command
);
1792 if (0 < n
&& command
[n
- 1] == ' ')
1793 command
[n
- 1] = '\0';
1799 /* Our own version of hide_symbol, so that we can keep plt entries for
1803 elf32_hppa_hide_symbol (struct bfd_link_info
*info
,
1804 struct elf_link_hash_entry
*eh
,
1805 bfd_boolean force_local
)
1809 eh
->forced_local
= 1;
1810 if (eh
->dynindx
!= -1)
1813 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
1818 if (! hppa_elf_hash_entry (eh
)->plabel
)
1821 eh
->plt
= elf_hash_table (info
)->init_plt_refcount
;
1825 /* Adjust a symbol defined by a dynamic object and referenced by a
1826 regular object. The current definition is in some section of the
1827 dynamic object, but we're not including those sections. We have to
1828 change the definition to something the rest of the link can
1832 elf32_hppa_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1833 struct elf_link_hash_entry
*eh
)
1835 struct elf32_hppa_link_hash_table
*htab
;
1838 /* If this is a function, put it in the procedure linkage table. We
1839 will fill in the contents of the procedure linkage table later. */
1840 if (eh
->type
== STT_FUNC
1843 if (eh
->plt
.refcount
<= 0
1845 && eh
->root
.type
!= bfd_link_hash_defweak
1846 && ! hppa_elf_hash_entry (eh
)->plabel
1847 && (!info
->shared
|| info
->symbolic
)))
1849 /* The .plt entry is not needed when:
1850 a) Garbage collection has removed all references to the
1852 b) We know for certain the symbol is defined in this
1853 object, and it's not a weak definition, nor is the symbol
1854 used by a plabel relocation. Either this object is the
1855 application or we are doing a shared symbolic link. */
1857 eh
->plt
.offset
= (bfd_vma
) -1;
1864 eh
->plt
.offset
= (bfd_vma
) -1;
1866 /* If this is a weak symbol, and there is a real definition, the
1867 processor independent code will have arranged for us to see the
1868 real definition first, and we can just use the same value. */
1869 if (eh
->u
.weakdef
!= NULL
)
1871 if (eh
->u
.weakdef
->root
.type
!= bfd_link_hash_defined
1872 && eh
->u
.weakdef
->root
.type
!= bfd_link_hash_defweak
)
1874 eh
->root
.u
.def
.section
= eh
->u
.weakdef
->root
.u
.def
.section
;
1875 eh
->root
.u
.def
.value
= eh
->u
.weakdef
->root
.u
.def
.value
;
1876 if (ELIMINATE_COPY_RELOCS
)
1877 eh
->non_got_ref
= eh
->u
.weakdef
->non_got_ref
;
1881 /* This is a reference to a symbol defined by a dynamic object which
1882 is not a function. */
1884 /* If we are creating a shared library, we must presume that the
1885 only references to the symbol are via the global offset table.
1886 For such cases we need not do anything here; the relocations will
1887 be handled correctly by relocate_section. */
1891 /* If there are no references to this symbol that do not use the
1892 GOT, we don't need to generate a copy reloc. */
1893 if (!eh
->non_got_ref
)
1896 if (ELIMINATE_COPY_RELOCS
)
1898 struct elf32_hppa_link_hash_entry
*hh
;
1899 struct elf32_hppa_dyn_reloc_entry
*hdh_p
;
1901 hh
= hppa_elf_hash_entry (eh
);
1902 for (hdh_p
= hh
->dyn_relocs
; hdh_p
!= NULL
; hdh_p
= hdh_p
->hdh_next
)
1904 sec
= hdh_p
->sec
->output_section
;
1905 if (sec
!= NULL
&& (sec
->flags
& SEC_READONLY
) != 0)
1909 /* If we didn't find any dynamic relocs in read-only sections, then
1910 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
1913 eh
->non_got_ref
= 0;
1920 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
1921 eh
->root
.root
.string
);
1925 /* We must allocate the symbol in our .dynbss section, which will
1926 become part of the .bss section of the executable. There will be
1927 an entry for this symbol in the .dynsym section. The dynamic
1928 object will contain position independent code, so all references
1929 from the dynamic object to this symbol will go through the global
1930 offset table. The dynamic linker will use the .dynsym entry to
1931 determine the address it must put in the global offset table, so
1932 both the dynamic object and the regular object will refer to the
1933 same memory location for the variable. */
1935 htab
= hppa_link_hash_table (info
);
1937 /* We must generate a COPY reloc to tell the dynamic linker to
1938 copy the initial value out of the dynamic object and into the
1939 runtime process image. */
1940 if ((eh
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1942 htab
->srelbss
->size
+= sizeof (Elf32_External_Rela
);
1946 sec
= htab
->sdynbss
;
1948 return _bfd_elf_adjust_dynamic_copy (eh
, sec
);
1951 /* Allocate space in the .plt for entries that won't have relocations.
1952 ie. plabel entries. */
1955 allocate_plt_static (struct elf_link_hash_entry
*eh
, void *inf
)
1957 struct bfd_link_info
*info
;
1958 struct elf32_hppa_link_hash_table
*htab
;
1959 struct elf32_hppa_link_hash_entry
*hh
;
1962 if (eh
->root
.type
== bfd_link_hash_indirect
)
1965 if (eh
->root
.type
== bfd_link_hash_warning
)
1966 eh
= (struct elf_link_hash_entry
*) eh
->root
.u
.i
.link
;
1968 info
= (struct bfd_link_info
*) inf
;
1969 hh
= hppa_elf_hash_entry (eh
);
1970 htab
= hppa_link_hash_table (info
);
1971 if (htab
->etab
.dynamic_sections_created
1972 && eh
->plt
.refcount
> 0)
1974 /* Make sure this symbol is output as a dynamic symbol.
1975 Undefined weak syms won't yet be marked as dynamic. */
1976 if (eh
->dynindx
== -1
1977 && !eh
->forced_local
1978 && eh
->type
!= STT_PARISC_MILLI
)
1980 if (! bfd_elf_link_record_dynamic_symbol (info
, eh
))
1984 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
->shared
, eh
))
1986 /* Allocate these later. From this point on, h->plabel
1987 means that the plt entry is only used by a plabel.
1988 We'll be using a normal plt entry for this symbol, so
1989 clear the plabel indicator. */
1993 else if (hh
->plabel
)
1995 /* Make an entry in the .plt section for plabel references
1996 that won't have a .plt entry for other reasons. */
1998 eh
->plt
.offset
= sec
->size
;
1999 sec
->size
+= PLT_ENTRY_SIZE
;
2003 /* No .plt entry needed. */
2004 eh
->plt
.offset
= (bfd_vma
) -1;
2010 eh
->plt
.offset
= (bfd_vma
) -1;
2017 /* Allocate space in .plt, .got and associated reloc sections for
2021 allocate_dynrelocs (struct elf_link_hash_entry
*eh
, void *inf
)
2023 struct bfd_link_info
*info
;
2024 struct elf32_hppa_link_hash_table
*htab
;
2026 struct elf32_hppa_link_hash_entry
*hh
;
2027 struct elf32_hppa_dyn_reloc_entry
*hdh_p
;
2029 if (eh
->root
.type
== bfd_link_hash_indirect
)
2032 if (eh
->root
.type
== bfd_link_hash_warning
)
2033 eh
= (struct elf_link_hash_entry
*) eh
->root
.u
.i
.link
;
2036 htab
= hppa_link_hash_table (info
);
2037 hh
= hppa_elf_hash_entry (eh
);
2039 if (htab
->etab
.dynamic_sections_created
2040 && eh
->plt
.offset
!= (bfd_vma
) -1
2042 && eh
->plt
.refcount
> 0)
2044 /* Make an entry in the .plt section. */
2046 eh
->plt
.offset
= sec
->size
;
2047 sec
->size
+= PLT_ENTRY_SIZE
;
2049 /* We also need to make an entry in the .rela.plt section. */
2050 htab
->srelplt
->size
+= sizeof (Elf32_External_Rela
);
2051 htab
->need_plt_stub
= 1;
2054 if (eh
->got
.refcount
> 0)
2056 /* Make sure this symbol is output as a dynamic symbol.
2057 Undefined weak syms won't yet be marked as dynamic. */
2058 if (eh
->dynindx
== -1
2059 && !eh
->forced_local
2060 && eh
->type
!= STT_PARISC_MILLI
)
2062 if (! bfd_elf_link_record_dynamic_symbol (info
, eh
))
2067 eh
->got
.offset
= sec
->size
;
2068 sec
->size
+= GOT_ENTRY_SIZE
;
2069 /* R_PARISC_TLS_GD* needs two GOT entries */
2070 if ((hh
->tls_type
& (GOT_TLS_GD
| GOT_TLS_IE
)) == (GOT_TLS_GD
| GOT_TLS_IE
))
2071 sec
->size
+= GOT_ENTRY_SIZE
* 2;
2072 else if ((hh
->tls_type
& GOT_TLS_GD
) == GOT_TLS_GD
)
2073 sec
->size
+= GOT_ENTRY_SIZE
;
2074 if (htab
->etab
.dynamic_sections_created
2076 || (eh
->dynindx
!= -1
2077 && !eh
->forced_local
)))
2079 htab
->srelgot
->size
+= sizeof (Elf32_External_Rela
);
2080 if ((hh
->tls_type
& (GOT_TLS_GD
| GOT_TLS_IE
)) == (GOT_TLS_GD
| GOT_TLS_IE
))
2081 htab
->srelgot
->size
+= 2 * sizeof (Elf32_External_Rela
);
2082 else if ((hh
->tls_type
& GOT_TLS_GD
) == GOT_TLS_GD
)
2083 htab
->srelgot
->size
+= sizeof (Elf32_External_Rela
);
2087 eh
->got
.offset
= (bfd_vma
) -1;
2089 if (hh
->dyn_relocs
== NULL
)
2092 /* If this is a -Bsymbolic shared link, then we need to discard all
2093 space allocated for dynamic pc-relative relocs against symbols
2094 defined in a regular object. For the normal shared case, discard
2095 space for relocs that have become local due to symbol visibility
2099 #if RELATIVE_DYNRELOCS
2100 if (SYMBOL_CALLS_LOCAL (info
, eh
))
2102 struct elf32_hppa_dyn_reloc_entry
**hdh_pp
;
2104 for (hdh_pp
= &hh
->dyn_relocs
; (hdh_p
= *hdh_pp
) != NULL
; )
2106 hdh_p
->count
-= hdh_p
->relative_count
;
2107 hdh_p
->relative_count
= 0;
2108 if (hdh_p
->count
== 0)
2109 *hdh_pp
= hdh_p
->hdh_next
;
2111 hdh_pp
= &hdh_p
->hdh_next
;
2116 /* Also discard relocs on undefined weak syms with non-default
2118 if (hh
->dyn_relocs
!= NULL
2119 && eh
->root
.type
== bfd_link_hash_undefweak
)
2121 if (ELF_ST_VISIBILITY (eh
->other
) != STV_DEFAULT
)
2122 hh
->dyn_relocs
= NULL
;
2124 /* Make sure undefined weak symbols are output as a dynamic
2126 else if (eh
->dynindx
== -1
2127 && !eh
->forced_local
)
2129 if (! bfd_elf_link_record_dynamic_symbol (info
, eh
))
2136 /* For the non-shared case, discard space for relocs against
2137 symbols which turn out to need copy relocs or are not
2140 if (!eh
->non_got_ref
2141 && ((ELIMINATE_COPY_RELOCS
2143 && !eh
->def_regular
)
2144 || (htab
->etab
.dynamic_sections_created
2145 && (eh
->root
.type
== bfd_link_hash_undefweak
2146 || eh
->root
.type
== bfd_link_hash_undefined
))))
2148 /* Make sure this symbol is output as a dynamic symbol.
2149 Undefined weak syms won't yet be marked as dynamic. */
2150 if (eh
->dynindx
== -1
2151 && !eh
->forced_local
2152 && eh
->type
!= STT_PARISC_MILLI
)
2154 if (! bfd_elf_link_record_dynamic_symbol (info
, eh
))
2158 /* If that succeeded, we know we'll be keeping all the
2160 if (eh
->dynindx
!= -1)
2164 hh
->dyn_relocs
= NULL
;
2170 /* Finally, allocate space. */
2171 for (hdh_p
= hh
->dyn_relocs
; hdh_p
!= NULL
; hdh_p
= hdh_p
->hdh_next
)
2173 asection
*sreloc
= elf_section_data (hdh_p
->sec
)->sreloc
;
2174 sreloc
->size
+= hdh_p
->count
* sizeof (Elf32_External_Rela
);
2180 /* This function is called via elf_link_hash_traverse to force
2181 millicode symbols local so they do not end up as globals in the
2182 dynamic symbol table. We ought to be able to do this in
2183 adjust_dynamic_symbol, but our adjust_dynamic_symbol is not called
2184 for all dynamic symbols. Arguably, this is a bug in
2185 elf_adjust_dynamic_symbol. */
2188 clobber_millicode_symbols (struct elf_link_hash_entry
*eh
,
2189 struct bfd_link_info
*info
)
2191 if (eh
->root
.type
== bfd_link_hash_warning
)
2192 eh
= (struct elf_link_hash_entry
*) eh
->root
.u
.i
.link
;
2194 if (eh
->type
== STT_PARISC_MILLI
2195 && !eh
->forced_local
)
2197 elf32_hppa_hide_symbol (info
, eh
, TRUE
);
2202 /* Find any dynamic relocs that apply to read-only sections. */
2205 readonly_dynrelocs (struct elf_link_hash_entry
*eh
, void *inf
)
2207 struct elf32_hppa_link_hash_entry
*hh
;
2208 struct elf32_hppa_dyn_reloc_entry
*hdh_p
;
2210 if (eh
->root
.type
== bfd_link_hash_warning
)
2211 eh
= (struct elf_link_hash_entry
*) eh
->root
.u
.i
.link
;
2213 hh
= hppa_elf_hash_entry (eh
);
2214 for (hdh_p
= hh
->dyn_relocs
; hdh_p
!= NULL
; hdh_p
= hdh_p
->hdh_next
)
2216 asection
*sec
= hdh_p
->sec
->output_section
;
2218 if (sec
!= NULL
&& (sec
->flags
& SEC_READONLY
) != 0)
2220 struct bfd_link_info
*info
= inf
;
2222 info
->flags
|= DF_TEXTREL
;
2224 /* Not an error, just cut short the traversal. */
2231 /* Set the sizes of the dynamic sections. */
2234 elf32_hppa_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2235 struct bfd_link_info
*info
)
2237 struct elf32_hppa_link_hash_table
*htab
;
2243 htab
= hppa_link_hash_table (info
);
2244 dynobj
= htab
->etab
.dynobj
;
2248 if (htab
->etab
.dynamic_sections_created
)
2250 /* Set the contents of the .interp section to the interpreter. */
2251 if (info
->executable
)
2253 sec
= bfd_get_section_by_name (dynobj
, ".interp");
2256 sec
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2257 sec
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2260 /* Force millicode symbols local. */
2261 elf_link_hash_traverse (&htab
->etab
,
2262 clobber_millicode_symbols
,
2266 /* Set up .got and .plt offsets for local syms, and space for local
2268 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2270 bfd_signed_vma
*local_got
;
2271 bfd_signed_vma
*end_local_got
;
2272 bfd_signed_vma
*local_plt
;
2273 bfd_signed_vma
*end_local_plt
;
2274 bfd_size_type locsymcount
;
2275 Elf_Internal_Shdr
*symtab_hdr
;
2277 char *local_tls_type
;
2279 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
2282 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2284 struct elf32_hppa_dyn_reloc_entry
*hdh_p
;
2286 for (hdh_p
= ((struct elf32_hppa_dyn_reloc_entry
*)
2287 elf_section_data (sec
)->local_dynrel
);
2289 hdh_p
= hdh_p
->hdh_next
)
2291 if (!bfd_is_abs_section (hdh_p
->sec
)
2292 && bfd_is_abs_section (hdh_p
->sec
->output_section
))
2294 /* Input section has been discarded, either because
2295 it is a copy of a linkonce section or due to
2296 linker script /DISCARD/, so we'll be discarding
2299 else if (hdh_p
->count
!= 0)
2301 srel
= elf_section_data (hdh_p
->sec
)->sreloc
;
2302 srel
->size
+= hdh_p
->count
* sizeof (Elf32_External_Rela
);
2303 if ((hdh_p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
2304 info
->flags
|= DF_TEXTREL
;
2309 local_got
= elf_local_got_refcounts (ibfd
);
2313 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
2314 locsymcount
= symtab_hdr
->sh_info
;
2315 end_local_got
= local_got
+ locsymcount
;
2316 local_tls_type
= hppa_elf_local_got_tls_type (ibfd
);
2318 srel
= htab
->srelgot
;
2319 for (; local_got
< end_local_got
; ++local_got
)
2323 *local_got
= sec
->size
;
2324 sec
->size
+= GOT_ENTRY_SIZE
;
2325 if ((*local_tls_type
& (GOT_TLS_GD
| GOT_TLS_IE
)) == (GOT_TLS_GD
| GOT_TLS_IE
))
2326 sec
->size
+= 2 * GOT_ENTRY_SIZE
;
2327 else if ((*local_tls_type
& GOT_TLS_GD
) == GOT_TLS_GD
)
2328 sec
->size
+= GOT_ENTRY_SIZE
;
2331 srel
->size
+= sizeof (Elf32_External_Rela
);
2332 if ((*local_tls_type
& (GOT_TLS_GD
| GOT_TLS_IE
)) == (GOT_TLS_GD
| GOT_TLS_IE
))
2333 srel
->size
+= 2 * sizeof (Elf32_External_Rela
);
2334 else if ((*local_tls_type
& GOT_TLS_GD
) == GOT_TLS_GD
)
2335 srel
->size
+= sizeof (Elf32_External_Rela
);
2339 *local_got
= (bfd_vma
) -1;
2344 local_plt
= end_local_got
;
2345 end_local_plt
= local_plt
+ locsymcount
;
2346 if (! htab
->etab
.dynamic_sections_created
)
2348 /* Won't be used, but be safe. */
2349 for (; local_plt
< end_local_plt
; ++local_plt
)
2350 *local_plt
= (bfd_vma
) -1;
2355 srel
= htab
->srelplt
;
2356 for (; local_plt
< end_local_plt
; ++local_plt
)
2360 *local_plt
= sec
->size
;
2361 sec
->size
+= PLT_ENTRY_SIZE
;
2363 srel
->size
+= sizeof (Elf32_External_Rela
);
2366 *local_plt
= (bfd_vma
) -1;
2371 if (htab
->tls_ldm_got
.refcount
> 0)
2373 /* Allocate 2 got entries and 1 dynamic reloc for
2374 R_PARISC_TLS_DTPMOD32 relocs. */
2375 htab
->tls_ldm_got
.offset
= htab
->sgot
->size
;
2376 htab
->sgot
->size
+= (GOT_ENTRY_SIZE
* 2);
2377 htab
->srelgot
->size
+= sizeof (Elf32_External_Rela
);
2380 htab
->tls_ldm_got
.offset
= -1;
2382 /* Do all the .plt entries without relocs first. The dynamic linker
2383 uses the last .plt reloc to find the end of the .plt (and hence
2384 the start of the .got) for lazy linking. */
2385 elf_link_hash_traverse (&htab
->etab
, allocate_plt_static
, info
);
2387 /* Allocate global sym .plt and .got entries, and space for global
2388 sym dynamic relocs. */
2389 elf_link_hash_traverse (&htab
->etab
, allocate_dynrelocs
, info
);
2391 /* The check_relocs and adjust_dynamic_symbol entry points have
2392 determined the sizes of the various dynamic sections. Allocate
2395 for (sec
= dynobj
->sections
; sec
!= NULL
; sec
= sec
->next
)
2397 if ((sec
->flags
& SEC_LINKER_CREATED
) == 0)
2400 if (sec
== htab
->splt
)
2402 if (htab
->need_plt_stub
)
2404 /* Make space for the plt stub at the end of the .plt
2405 section. We want this stub right at the end, up
2406 against the .got section. */
2407 int gotalign
= bfd_section_alignment (dynobj
, htab
->sgot
);
2408 int pltalign
= bfd_section_alignment (dynobj
, sec
);
2411 if (gotalign
> pltalign
)
2412 bfd_set_section_alignment (dynobj
, sec
, gotalign
);
2413 mask
= ((bfd_size_type
) 1 << gotalign
) - 1;
2414 sec
->size
= (sec
->size
+ sizeof (plt_stub
) + mask
) & ~mask
;
2417 else if (sec
== htab
->sgot
2418 || sec
== htab
->sdynbss
)
2420 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, sec
), ".rela"))
2424 /* Remember whether there are any reloc sections other
2426 if (sec
!= htab
->srelplt
)
2429 /* We use the reloc_count field as a counter if we need
2430 to copy relocs into the output file. */
2431 sec
->reloc_count
= 0;
2436 /* It's not one of our sections, so don't allocate space. */
2442 /* If we don't need this section, strip it from the
2443 output file. This is mostly to handle .rela.bss and
2444 .rela.plt. We must create both sections in
2445 create_dynamic_sections, because they must be created
2446 before the linker maps input sections to output
2447 sections. The linker does that before
2448 adjust_dynamic_symbol is called, and it is that
2449 function which decides whether anything needs to go
2450 into these sections. */
2451 sec
->flags
|= SEC_EXCLUDE
;
2455 if ((sec
->flags
& SEC_HAS_CONTENTS
) == 0)
2458 /* Allocate memory for the section contents. Zero it, because
2459 we may not fill in all the reloc sections. */
2460 sec
->contents
= bfd_zalloc (dynobj
, sec
->size
);
2461 if (sec
->contents
== NULL
)
2465 if (htab
->etab
.dynamic_sections_created
)
2467 /* Like IA-64 and HPPA64, always create a DT_PLTGOT. It
2468 actually has nothing to do with the PLT, it is how we
2469 communicate the LTP value of a load module to the dynamic
2471 #define add_dynamic_entry(TAG, VAL) \
2472 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2474 if (!add_dynamic_entry (DT_PLTGOT
, 0))
2477 /* Add some entries to the .dynamic section. We fill in the
2478 values later, in elf32_hppa_finish_dynamic_sections, but we
2479 must add the entries now so that we get the correct size for
2480 the .dynamic section. The DT_DEBUG entry is filled in by the
2481 dynamic linker and used by the debugger. */
2482 if (info
->executable
)
2484 if (!add_dynamic_entry (DT_DEBUG
, 0))
2488 if (htab
->srelplt
->size
!= 0)
2490 if (!add_dynamic_entry (DT_PLTRELSZ
, 0)
2491 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
2492 || !add_dynamic_entry (DT_JMPREL
, 0))
2498 if (!add_dynamic_entry (DT_RELA
, 0)
2499 || !add_dynamic_entry (DT_RELASZ
, 0)
2500 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
2503 /* If any dynamic relocs apply to a read-only section,
2504 then we need a DT_TEXTREL entry. */
2505 if ((info
->flags
& DF_TEXTREL
) == 0)
2506 elf_link_hash_traverse (&htab
->etab
, readonly_dynrelocs
, info
);
2508 if ((info
->flags
& DF_TEXTREL
) != 0)
2510 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2515 #undef add_dynamic_entry
2520 /* External entry points for sizing and building linker stubs. */
2522 /* Set up various things so that we can make a list of input sections
2523 for each output section included in the link. Returns -1 on error,
2524 0 when no stubs will be needed, and 1 on success. */
2527 elf32_hppa_setup_section_lists (bfd
*output_bfd
, struct bfd_link_info
*info
)
2530 unsigned int bfd_count
;
2531 int top_id
, top_index
;
2533 asection
**input_list
, **list
;
2535 struct elf32_hppa_link_hash_table
*htab
= hppa_link_hash_table (info
);
2537 /* Count the number of input BFDs and find the top input section id. */
2538 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
2540 input_bfd
= input_bfd
->link_next
)
2543 for (section
= input_bfd
->sections
;
2545 section
= section
->next
)
2547 if (top_id
< section
->id
)
2548 top_id
= section
->id
;
2551 htab
->bfd_count
= bfd_count
;
2553 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
2554 htab
->stub_group
= bfd_zmalloc (amt
);
2555 if (htab
->stub_group
== NULL
)
2558 /* We can't use output_bfd->section_count here to find the top output
2559 section index as some sections may have been removed, and
2560 strip_excluded_output_sections doesn't renumber the indices. */
2561 for (section
= output_bfd
->sections
, top_index
= 0;
2563 section
= section
->next
)
2565 if (top_index
< section
->index
)
2566 top_index
= section
->index
;
2569 htab
->top_index
= top_index
;
2570 amt
= sizeof (asection
*) * (top_index
+ 1);
2571 input_list
= bfd_malloc (amt
);
2572 htab
->input_list
= input_list
;
2573 if (input_list
== NULL
)
2576 /* For sections we aren't interested in, mark their entries with a
2577 value we can check later. */
2578 list
= input_list
+ top_index
;
2580 *list
= bfd_abs_section_ptr
;
2581 while (list
-- != input_list
);
2583 for (section
= output_bfd
->sections
;
2585 section
= section
->next
)
2587 if ((section
->flags
& SEC_CODE
) != 0)
2588 input_list
[section
->index
] = NULL
;
2594 /* The linker repeatedly calls this function for each input section,
2595 in the order that input sections are linked into output sections.
2596 Build lists of input sections to determine groupings between which
2597 we may insert linker stubs. */
2600 elf32_hppa_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
2602 struct elf32_hppa_link_hash_table
*htab
= hppa_link_hash_table (info
);
2604 if (isec
->output_section
->index
<= htab
->top_index
)
2606 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
2607 if (*list
!= bfd_abs_section_ptr
)
2609 /* Steal the link_sec pointer for our list. */
2610 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
2611 /* This happens to make the list in reverse order,
2612 which is what we want. */
2613 PREV_SEC (isec
) = *list
;
2619 /* See whether we can group stub sections together. Grouping stub
2620 sections may result in fewer stubs. More importantly, we need to
2621 put all .init* and .fini* stubs at the beginning of the .init or
2622 .fini output sections respectively, because glibc splits the
2623 _init and _fini functions into multiple parts. Putting a stub in
2624 the middle of a function is not a good idea. */
2627 group_sections (struct elf32_hppa_link_hash_table
*htab
,
2628 bfd_size_type stub_group_size
,
2629 bfd_boolean stubs_always_before_branch
)
2631 asection
**list
= htab
->input_list
+ htab
->top_index
;
2634 asection
*tail
= *list
;
2635 if (tail
== bfd_abs_section_ptr
)
2637 while (tail
!= NULL
)
2641 bfd_size_type total
;
2642 bfd_boolean big_sec
;
2646 big_sec
= total
>= stub_group_size
;
2648 while ((prev
= PREV_SEC (curr
)) != NULL
2649 && ((total
+= curr
->output_offset
- prev
->output_offset
)
2653 /* OK, the size from the start of CURR to the end is less
2654 than 240000 bytes and thus can be handled by one stub
2655 section. (or the tail section is itself larger than
2656 240000 bytes, in which case we may be toast.)
2657 We should really be keeping track of the total size of
2658 stubs added here, as stubs contribute to the final output
2659 section size. That's a little tricky, and this way will
2660 only break if stubs added total more than 22144 bytes, or
2661 2768 long branch stubs. It seems unlikely for more than
2662 2768 different functions to be called, especially from
2663 code only 240000 bytes long. This limit used to be
2664 250000, but c++ code tends to generate lots of little
2665 functions, and sometimes violated the assumption. */
2668 prev
= PREV_SEC (tail
);
2669 /* Set up this stub group. */
2670 htab
->stub_group
[tail
->id
].link_sec
= curr
;
2672 while (tail
!= curr
&& (tail
= prev
) != NULL
);
2674 /* But wait, there's more! Input sections up to 240000
2675 bytes before the stub section can be handled by it too.
2676 Don't do this if we have a really large section after the
2677 stubs, as adding more stubs increases the chance that
2678 branches may not reach into the stub section. */
2679 if (!stubs_always_before_branch
&& !big_sec
)
2683 && ((total
+= tail
->output_offset
- prev
->output_offset
)
2687 prev
= PREV_SEC (tail
);
2688 htab
->stub_group
[tail
->id
].link_sec
= curr
;
2694 while (list
-- != htab
->input_list
);
2695 free (htab
->input_list
);
2699 /* Read in all local syms for all input bfds, and create hash entries
2700 for export stubs if we are building a multi-subspace shared lib.
2701 Returns -1 on error, 1 if export stubs created, 0 otherwise. */
2704 get_local_syms (bfd
*output_bfd
, bfd
*input_bfd
, struct bfd_link_info
*info
)
2706 unsigned int bfd_indx
;
2707 Elf_Internal_Sym
*local_syms
, **all_local_syms
;
2708 int stub_changed
= 0;
2709 struct elf32_hppa_link_hash_table
*htab
= hppa_link_hash_table (info
);
2711 /* We want to read in symbol extension records only once. To do this
2712 we need to read in the local symbols in parallel and save them for
2713 later use; so hold pointers to the local symbols in an array. */
2714 bfd_size_type amt
= sizeof (Elf_Internal_Sym
*) * htab
->bfd_count
;
2715 all_local_syms
= bfd_zmalloc (amt
);
2716 htab
->all_local_syms
= all_local_syms
;
2717 if (all_local_syms
== NULL
)
2720 /* Walk over all the input BFDs, swapping in local symbols.
2721 If we are creating a shared library, create hash entries for the
2725 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
2727 Elf_Internal_Shdr
*symtab_hdr
;
2729 /* We'll need the symbol table in a second. */
2730 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2731 if (symtab_hdr
->sh_info
== 0)
2734 /* We need an array of the local symbols attached to the input bfd. */
2735 local_syms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2736 if (local_syms
== NULL
)
2738 local_syms
= bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
2739 symtab_hdr
->sh_info
, 0,
2741 /* Cache them for elf_link_input_bfd. */
2742 symtab_hdr
->contents
= (unsigned char *) local_syms
;
2744 if (local_syms
== NULL
)
2747 all_local_syms
[bfd_indx
] = local_syms
;
2749 if (info
->shared
&& htab
->multi_subspace
)
2751 struct elf_link_hash_entry
**eh_syms
;
2752 struct elf_link_hash_entry
**eh_symend
;
2753 unsigned int symcount
;
2755 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
2756 - symtab_hdr
->sh_info
);
2757 eh_syms
= (struct elf_link_hash_entry
**) elf_sym_hashes (input_bfd
);
2758 eh_symend
= (struct elf_link_hash_entry
**) (eh_syms
+ symcount
);
2760 /* Look through the global syms for functions; We need to
2761 build export stubs for all globally visible functions. */
2762 for (; eh_syms
< eh_symend
; eh_syms
++)
2764 struct elf32_hppa_link_hash_entry
*hh
;
2766 hh
= hppa_elf_hash_entry (*eh_syms
);
2768 while (hh
->eh
.root
.type
== bfd_link_hash_indirect
2769 || hh
->eh
.root
.type
== bfd_link_hash_warning
)
2770 hh
= hppa_elf_hash_entry (hh
->eh
.root
.u
.i
.link
);
2772 /* At this point in the link, undefined syms have been
2773 resolved, so we need to check that the symbol was
2774 defined in this BFD. */
2775 if ((hh
->eh
.root
.type
== bfd_link_hash_defined
2776 || hh
->eh
.root
.type
== bfd_link_hash_defweak
)
2777 && hh
->eh
.type
== STT_FUNC
2778 && hh
->eh
.root
.u
.def
.section
->output_section
!= NULL
2779 && (hh
->eh
.root
.u
.def
.section
->output_section
->owner
2781 && hh
->eh
.root
.u
.def
.section
->owner
== input_bfd
2782 && hh
->eh
.def_regular
2783 && !hh
->eh
.forced_local
2784 && ELF_ST_VISIBILITY (hh
->eh
.other
) == STV_DEFAULT
)
2787 const char *stub_name
;
2788 struct elf32_hppa_stub_hash_entry
*hsh
;
2790 sec
= hh
->eh
.root
.u
.def
.section
;
2791 stub_name
= hh_name (hh
);
2792 hsh
= hppa_stub_hash_lookup (&htab
->bstab
,
2797 hsh
= hppa_add_stub (stub_name
, sec
, htab
);
2801 hsh
->target_value
= hh
->eh
.root
.u
.def
.value
;
2802 hsh
->target_section
= hh
->eh
.root
.u
.def
.section
;
2803 hsh
->stub_type
= hppa_stub_export
;
2809 (*_bfd_error_handler
) (_("%B: duplicate export stub %s"),
2818 return stub_changed
;
2821 /* Determine and set the size of the stub section for a final link.
2823 The basic idea here is to examine all the relocations looking for
2824 PC-relative calls to a target that is unreachable with a "bl"
2828 elf32_hppa_size_stubs
2829 (bfd
*output_bfd
, bfd
*stub_bfd
, struct bfd_link_info
*info
,
2830 bfd_boolean multi_subspace
, bfd_signed_vma group_size
,
2831 asection
* (*add_stub_section
) (const char *, asection
*),
2832 void (*layout_sections_again
) (void))
2834 bfd_size_type stub_group_size
;
2835 bfd_boolean stubs_always_before_branch
;
2836 bfd_boolean stub_changed
;
2837 struct elf32_hppa_link_hash_table
*htab
= hppa_link_hash_table (info
);
2839 /* Stash our params away. */
2840 htab
->stub_bfd
= stub_bfd
;
2841 htab
->multi_subspace
= multi_subspace
;
2842 htab
->add_stub_section
= add_stub_section
;
2843 htab
->layout_sections_again
= layout_sections_again
;
2844 stubs_always_before_branch
= group_size
< 0;
2846 stub_group_size
= -group_size
;
2848 stub_group_size
= group_size
;
2849 if (stub_group_size
== 1)
2851 /* Default values. */
2852 if (stubs_always_before_branch
)
2854 stub_group_size
= 7680000;
2855 if (htab
->has_17bit_branch
|| htab
->multi_subspace
)
2856 stub_group_size
= 240000;
2857 if (htab
->has_12bit_branch
)
2858 stub_group_size
= 7500;
2862 stub_group_size
= 6971392;
2863 if (htab
->has_17bit_branch
|| htab
->multi_subspace
)
2864 stub_group_size
= 217856;
2865 if (htab
->has_12bit_branch
)
2866 stub_group_size
= 6808;
2870 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
2872 switch (get_local_syms (output_bfd
, info
->input_bfds
, info
))
2875 if (htab
->all_local_syms
)
2876 goto error_ret_free_local
;
2880 stub_changed
= FALSE
;
2884 stub_changed
= TRUE
;
2891 unsigned int bfd_indx
;
2894 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
2896 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
2898 Elf_Internal_Shdr
*symtab_hdr
;
2900 Elf_Internal_Sym
*local_syms
;
2902 /* We'll need the symbol table in a second. */
2903 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2904 if (symtab_hdr
->sh_info
== 0)
2907 local_syms
= htab
->all_local_syms
[bfd_indx
];
2909 /* Walk over each section attached to the input bfd. */
2910 for (section
= input_bfd
->sections
;
2912 section
= section
->next
)
2914 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
2916 /* If there aren't any relocs, then there's nothing more
2918 if ((section
->flags
& SEC_RELOC
) == 0
2919 || section
->reloc_count
== 0)
2922 /* If this section is a link-once section that will be
2923 discarded, then don't create any stubs. */
2924 if (section
->output_section
== NULL
2925 || section
->output_section
->owner
!= output_bfd
)
2928 /* Get the relocs. */
2930 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
, NULL
,
2932 if (internal_relocs
== NULL
)
2933 goto error_ret_free_local
;
2935 /* Now examine each relocation. */
2936 irela
= internal_relocs
;
2937 irelaend
= irela
+ section
->reloc_count
;
2938 for (; irela
< irelaend
; irela
++)
2940 unsigned int r_type
, r_indx
;
2941 enum elf32_hppa_stub_type stub_type
;
2942 struct elf32_hppa_stub_hash_entry
*hsh
;
2945 bfd_vma destination
;
2946 struct elf32_hppa_link_hash_entry
*hh
;
2948 const asection
*id_sec
;
2950 r_type
= ELF32_R_TYPE (irela
->r_info
);
2951 r_indx
= ELF32_R_SYM (irela
->r_info
);
2953 if (r_type
>= (unsigned int) R_PARISC_UNIMPLEMENTED
)
2955 bfd_set_error (bfd_error_bad_value
);
2956 error_ret_free_internal
:
2957 if (elf_section_data (section
)->relocs
== NULL
)
2958 free (internal_relocs
);
2959 goto error_ret_free_local
;
2962 /* Only look for stubs on call instructions. */
2963 if (r_type
!= (unsigned int) R_PARISC_PCREL12F
2964 && r_type
!= (unsigned int) R_PARISC_PCREL17F
2965 && r_type
!= (unsigned int) R_PARISC_PCREL22F
)
2968 /* Now determine the call target, its name, value,
2974 if (r_indx
< symtab_hdr
->sh_info
)
2976 /* It's a local symbol. */
2977 Elf_Internal_Sym
*sym
;
2978 Elf_Internal_Shdr
*hdr
;
2980 sym
= local_syms
+ r_indx
;
2981 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
2982 sym_sec
= hdr
->bfd_section
;
2983 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
2984 sym_value
= sym
->st_value
;
2985 destination
= (sym_value
+ irela
->r_addend
2986 + sym_sec
->output_offset
2987 + sym_sec
->output_section
->vma
);
2991 /* It's an external symbol. */
2994 e_indx
= r_indx
- symtab_hdr
->sh_info
;
2995 hh
= hppa_elf_hash_entry (elf_sym_hashes (input_bfd
)[e_indx
]);
2997 while (hh
->eh
.root
.type
== bfd_link_hash_indirect
2998 || hh
->eh
.root
.type
== bfd_link_hash_warning
)
2999 hh
= hppa_elf_hash_entry (hh
->eh
.root
.u
.i
.link
);
3001 if (hh
->eh
.root
.type
== bfd_link_hash_defined
3002 || hh
->eh
.root
.type
== bfd_link_hash_defweak
)
3004 sym_sec
= hh
->eh
.root
.u
.def
.section
;
3005 sym_value
= hh
->eh
.root
.u
.def
.value
;
3006 if (sym_sec
->output_section
!= NULL
)
3007 destination
= (sym_value
+ irela
->r_addend
3008 + sym_sec
->output_offset
3009 + sym_sec
->output_section
->vma
);
3011 else if (hh
->eh
.root
.type
== bfd_link_hash_undefweak
)
3016 else if (hh
->eh
.root
.type
== bfd_link_hash_undefined
)
3018 if (! (info
->unresolved_syms_in_objects
== RM_IGNORE
3019 && (ELF_ST_VISIBILITY (hh
->eh
.other
)
3021 && hh
->eh
.type
!= STT_PARISC_MILLI
))
3026 bfd_set_error (bfd_error_bad_value
);
3027 goto error_ret_free_internal
;
3031 /* Determine what (if any) linker stub is needed. */
3032 stub_type
= hppa_type_of_stub (section
, irela
, hh
,
3034 if (stub_type
== hppa_stub_none
)
3037 /* Support for grouping stub sections. */
3038 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
3040 /* Get the name of this stub. */
3041 stub_name
= hppa_stub_name (id_sec
, sym_sec
, hh
, irela
);
3043 goto error_ret_free_internal
;
3045 hsh
= hppa_stub_hash_lookup (&htab
->bstab
,
3050 /* The proper stub has already been created. */
3055 hsh
= hppa_add_stub (stub_name
, section
, htab
);
3059 goto error_ret_free_internal
;
3062 hsh
->target_value
= sym_value
;
3063 hsh
->target_section
= sym_sec
;
3064 hsh
->stub_type
= stub_type
;
3067 if (stub_type
== hppa_stub_import
)
3068 hsh
->stub_type
= hppa_stub_import_shared
;
3069 else if (stub_type
== hppa_stub_long_branch
)
3070 hsh
->stub_type
= hppa_stub_long_branch_shared
;
3073 stub_changed
= TRUE
;
3076 /* We're done with the internal relocs, free them. */
3077 if (elf_section_data (section
)->relocs
== NULL
)
3078 free (internal_relocs
);
3085 /* OK, we've added some stubs. Find out the new size of the
3087 for (stub_sec
= htab
->stub_bfd
->sections
;
3089 stub_sec
= stub_sec
->next
)
3092 bfd_hash_traverse (&htab
->bstab
, hppa_size_one_stub
, htab
);
3094 /* Ask the linker to do its stuff. */
3095 (*htab
->layout_sections_again
) ();
3096 stub_changed
= FALSE
;
3099 free (htab
->all_local_syms
);
3102 error_ret_free_local
:
3103 free (htab
->all_local_syms
);
3107 /* For a final link, this function is called after we have sized the
3108 stubs to provide a value for __gp. */
3111 elf32_hppa_set_gp (bfd
*abfd
, struct bfd_link_info
*info
)
3113 struct bfd_link_hash_entry
*h
;
3114 asection
*sec
= NULL
;
3116 struct elf32_hppa_link_hash_table
*htab
;
3118 htab
= hppa_link_hash_table (info
);
3119 h
= bfd_link_hash_lookup (&htab
->etab
.root
, "$global$", FALSE
, FALSE
, FALSE
);
3122 && (h
->type
== bfd_link_hash_defined
3123 || h
->type
== bfd_link_hash_defweak
))
3125 gp_val
= h
->u
.def
.value
;
3126 sec
= h
->u
.def
.section
;
3130 asection
*splt
= bfd_get_section_by_name (abfd
, ".plt");
3131 asection
*sgot
= bfd_get_section_by_name (abfd
, ".got");
3133 /* Choose to point our LTP at, in this order, one of .plt, .got,
3134 or .data, if these sections exist. In the case of choosing
3135 .plt try to make the LTP ideal for addressing anywhere in the
3136 .plt or .got with a 14 bit signed offset. Typically, the end
3137 of the .plt is the start of the .got, so choose .plt + 0x2000
3138 if either the .plt or .got is larger than 0x2000. If both
3139 the .plt and .got are smaller than 0x2000, choose the end of
3140 the .plt section. */
3141 sec
= strcmp (bfd_get_target (abfd
), "elf32-hppa-netbsd") == 0
3146 if (gp_val
> 0x2000 || (sgot
&& sgot
->size
> 0x2000))
3156 if (strcmp (bfd_get_target (abfd
), "elf32-hppa-netbsd") != 0)
3158 /* We know we don't have a .plt. If .got is large,
3160 if (sec
->size
> 0x2000)
3166 /* No .plt or .got. Who cares what the LTP is? */
3167 sec
= bfd_get_section_by_name (abfd
, ".data");
3173 h
->type
= bfd_link_hash_defined
;
3174 h
->u
.def
.value
= gp_val
;
3176 h
->u
.def
.section
= sec
;
3178 h
->u
.def
.section
= bfd_abs_section_ptr
;
3182 if (sec
!= NULL
&& sec
->output_section
!= NULL
)
3183 gp_val
+= sec
->output_section
->vma
+ sec
->output_offset
;
3185 elf_gp (abfd
) = gp_val
;
3189 /* Build all the stubs associated with the current output file. The
3190 stubs are kept in a hash table attached to the main linker hash
3191 table. We also set up the .plt entries for statically linked PIC
3192 functions here. This function is called via hppaelf_finish in the
3196 elf32_hppa_build_stubs (struct bfd_link_info
*info
)
3199 struct bfd_hash_table
*table
;
3200 struct elf32_hppa_link_hash_table
*htab
;
3202 htab
= hppa_link_hash_table (info
);
3204 for (stub_sec
= htab
->stub_bfd
->sections
;
3206 stub_sec
= stub_sec
->next
)
3210 /* Allocate memory to hold the linker stubs. */
3211 size
= stub_sec
->size
;
3212 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, size
);
3213 if (stub_sec
->contents
== NULL
&& size
!= 0)
3218 /* Build the stubs as directed by the stub hash table. */
3219 table
= &htab
->bstab
;
3220 bfd_hash_traverse (table
, hppa_build_one_stub
, info
);
3225 /* Return the base vma address which should be subtracted from the real
3226 address when resolving a dtpoff relocation.
3227 This is PT_TLS segment p_vaddr. */
3230 dtpoff_base (struct bfd_link_info
*info
)
3232 /* If tls_sec is NULL, we should have signalled an error already. */
3233 if (elf_hash_table (info
)->tls_sec
== NULL
)
3235 return elf_hash_table (info
)->tls_sec
->vma
;
3238 /* Return the relocation value for R_PARISC_TLS_TPOFF*.. */
3241 tpoff (struct bfd_link_info
*info
, bfd_vma address
)
3243 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
3245 /* If tls_sec is NULL, we should have signalled an error already. */
3246 if (htab
->tls_sec
== NULL
)
3248 /* hppa TLS ABI is variant I and static TLS block start just after
3249 tcbhead structure which has 2 pointer fields. */
3250 return (address
- htab
->tls_sec
->vma
3251 + align_power ((bfd_vma
) 8, htab
->tls_sec
->alignment_power
));
3254 /* Perform a final link. */
3257 elf32_hppa_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
3259 /* Invoke the regular ELF linker to do all the work. */
3260 if (!bfd_elf_final_link (abfd
, info
))
3263 /* If we're producing a final executable, sort the contents of the
3265 return elf_hppa_sort_unwind (abfd
);
3268 /* Record the lowest address for the data and text segments. */
3271 hppa_record_segment_addr (bfd
*abfd
, asection
*section
, void *data
)
3273 struct elf32_hppa_link_hash_table
*htab
;
3275 htab
= (struct elf32_hppa_link_hash_table
*) data
;
3277 if ((section
->flags
& (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3280 Elf_Internal_Phdr
*p
;
3282 p
= _bfd_elf_find_segment_containing_section (abfd
, section
->output_section
);
3283 BFD_ASSERT (p
!= NULL
);
3286 if ((section
->flags
& SEC_READONLY
) != 0)
3288 if (value
< htab
->text_segment_base
)
3289 htab
->text_segment_base
= value
;
3293 if (value
< htab
->data_segment_base
)
3294 htab
->data_segment_base
= value
;
3299 /* Perform a relocation as part of a final link. */
3301 static bfd_reloc_status_type
3302 final_link_relocate (asection
*input_section
,
3304 const Elf_Internal_Rela
*rela
,
3306 struct elf32_hppa_link_hash_table
*htab
,
3308 struct elf32_hppa_link_hash_entry
*hh
,
3309 struct bfd_link_info
*info
)
3312 unsigned int r_type
= ELF32_R_TYPE (rela
->r_info
);
3313 unsigned int orig_r_type
= r_type
;
3314 reloc_howto_type
*howto
= elf_hppa_howto_table
+ r_type
;
3315 int r_format
= howto
->bitsize
;
3316 enum hppa_reloc_field_selector_type_alt r_field
;
3317 bfd
*input_bfd
= input_section
->owner
;
3318 bfd_vma offset
= rela
->r_offset
;
3319 bfd_vma max_branch_offset
= 0;
3320 bfd_byte
*hit_data
= contents
+ offset
;
3321 bfd_signed_vma addend
= rela
->r_addend
;
3323 struct elf32_hppa_stub_hash_entry
*hsh
= NULL
;
3326 if (r_type
== R_PARISC_NONE
)
3327 return bfd_reloc_ok
;
3329 insn
= bfd_get_32 (input_bfd
, hit_data
);
3331 /* Find out where we are and where we're going. */
3332 location
= (offset
+
3333 input_section
->output_offset
+
3334 input_section
->output_section
->vma
);
3336 /* If we are not building a shared library, convert DLTIND relocs to
3342 case R_PARISC_DLTIND21L
:
3343 r_type
= R_PARISC_DPREL21L
;
3346 case R_PARISC_DLTIND14R
:
3347 r_type
= R_PARISC_DPREL14R
;
3350 case R_PARISC_DLTIND14F
:
3351 r_type
= R_PARISC_DPREL14F
;
3358 case R_PARISC_PCREL12F
:
3359 case R_PARISC_PCREL17F
:
3360 case R_PARISC_PCREL22F
:
3361 /* If this call should go via the plt, find the import stub in
3364 || sym_sec
->output_section
== NULL
3366 && hh
->eh
.plt
.offset
!= (bfd_vma
) -1
3367 && hh
->eh
.dynindx
!= -1
3370 || !hh
->eh
.def_regular
3371 || hh
->eh
.root
.type
== bfd_link_hash_defweak
)))
3373 hsh
= hppa_get_stub_entry (input_section
, sym_sec
,
3377 value
= (hsh
->stub_offset
3378 + hsh
->stub_sec
->output_offset
3379 + hsh
->stub_sec
->output_section
->vma
);
3382 else if (sym_sec
== NULL
&& hh
!= NULL
3383 && hh
->eh
.root
.type
== bfd_link_hash_undefweak
)
3385 /* It's OK if undefined weak. Calls to undefined weak
3386 symbols behave as if the "called" function
3387 immediately returns. We can thus call to a weak
3388 function without first checking whether the function
3394 return bfd_reloc_undefined
;
3398 case R_PARISC_PCREL21L
:
3399 case R_PARISC_PCREL17C
:
3400 case R_PARISC_PCREL17R
:
3401 case R_PARISC_PCREL14R
:
3402 case R_PARISC_PCREL14F
:
3403 case R_PARISC_PCREL32
:
3404 /* Make it a pc relative offset. */
3409 case R_PARISC_DPREL21L
:
3410 case R_PARISC_DPREL14R
:
3411 case R_PARISC_DPREL14F
:
3412 /* Convert instructions that use the linkage table pointer (r19) to
3413 instructions that use the global data pointer (dp). This is the
3414 most efficient way of using PIC code in an incomplete executable,
3415 but the user must follow the standard runtime conventions for
3416 accessing data for this to work. */
3417 if (orig_r_type
== R_PARISC_DLTIND21L
)
3419 /* Convert addil instructions if the original reloc was a
3420 DLTIND21L. GCC sometimes uses a register other than r19 for
3421 the operation, so we must convert any addil instruction
3422 that uses this relocation. */
3423 if ((insn
& 0xfc000000) == ((int) OP_ADDIL
<< 26))
3426 /* We must have a ldil instruction. It's too hard to find
3427 and convert the associated add instruction, so issue an
3429 (*_bfd_error_handler
)
3430 (_("%B(%A+0x%lx): %s fixup for insn 0x%x is not supported in a non-shared link"),
3437 else if (orig_r_type
== R_PARISC_DLTIND14F
)
3439 /* This must be a format 1 load/store. Change the base
3441 insn
= (insn
& 0xfc1ffff) | (27 << 21);
3444 /* For all the DP relative relocations, we need to examine the symbol's
3445 section. If it has no section or if it's a code section, then
3446 "data pointer relative" makes no sense. In that case we don't
3447 adjust the "value", and for 21 bit addil instructions, we change the
3448 source addend register from %dp to %r0. This situation commonly
3449 arises for undefined weak symbols and when a variable's "constness"
3450 is declared differently from the way the variable is defined. For
3451 instance: "extern int foo" with foo defined as "const int foo". */
3452 if (sym_sec
== NULL
|| (sym_sec
->flags
& SEC_CODE
) != 0)
3454 if ((insn
& ((0x3f << 26) | (0x1f << 21)))
3455 == (((int) OP_ADDIL
<< 26) | (27 << 21)))
3457 insn
&= ~ (0x1f << 21);
3459 /* Now try to make things easy for the dynamic linker. */
3465 case R_PARISC_DLTIND21L
:
3466 case R_PARISC_DLTIND14R
:
3467 case R_PARISC_DLTIND14F
:
3468 case R_PARISC_TLS_GD21L
:
3469 case R_PARISC_TLS_GD14R
:
3470 case R_PARISC_TLS_LDM21L
:
3471 case R_PARISC_TLS_LDM14R
:
3472 case R_PARISC_TLS_IE21L
:
3473 case R_PARISC_TLS_IE14R
:
3474 value
-= elf_gp (input_section
->output_section
->owner
);
3477 case R_PARISC_SEGREL32
:
3478 if ((sym_sec
->flags
& SEC_CODE
) != 0)
3479 value
-= htab
->text_segment_base
;
3481 value
-= htab
->data_segment_base
;
3490 case R_PARISC_DIR32
:
3491 case R_PARISC_DIR14F
:
3492 case R_PARISC_DIR17F
:
3493 case R_PARISC_PCREL17C
:
3494 case R_PARISC_PCREL14F
:
3495 case R_PARISC_PCREL32
:
3496 case R_PARISC_DPREL14F
:
3497 case R_PARISC_PLABEL32
:
3498 case R_PARISC_DLTIND14F
:
3499 case R_PARISC_SEGBASE
:
3500 case R_PARISC_SEGREL32
:
3501 case R_PARISC_TLS_DTPMOD32
:
3502 case R_PARISC_TLS_DTPOFF32
:
3503 case R_PARISC_TLS_TPREL32
:
3507 case R_PARISC_DLTIND21L
:
3508 case R_PARISC_PCREL21L
:
3509 case R_PARISC_PLABEL21L
:
3513 case R_PARISC_DIR21L
:
3514 case R_PARISC_DPREL21L
:
3515 case R_PARISC_TLS_GD21L
:
3516 case R_PARISC_TLS_LDM21L
:
3517 case R_PARISC_TLS_LDO21L
:
3518 case R_PARISC_TLS_IE21L
:
3519 case R_PARISC_TLS_LE21L
:
3523 case R_PARISC_PCREL17R
:
3524 case R_PARISC_PCREL14R
:
3525 case R_PARISC_PLABEL14R
:
3526 case R_PARISC_DLTIND14R
:
3530 case R_PARISC_DIR17R
:
3531 case R_PARISC_DIR14R
:
3532 case R_PARISC_DPREL14R
:
3533 case R_PARISC_TLS_GD14R
:
3534 case R_PARISC_TLS_LDM14R
:
3535 case R_PARISC_TLS_LDO14R
:
3536 case R_PARISC_TLS_IE14R
:
3537 case R_PARISC_TLS_LE14R
:
3541 case R_PARISC_PCREL12F
:
3542 case R_PARISC_PCREL17F
:
3543 case R_PARISC_PCREL22F
:
3546 if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
3548 max_branch_offset
= (1 << (17-1)) << 2;
3550 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
3552 max_branch_offset
= (1 << (12-1)) << 2;
3556 max_branch_offset
= (1 << (22-1)) << 2;
3559 /* sym_sec is NULL on undefined weak syms or when shared on
3560 undefined syms. We've already checked for a stub for the
3561 shared undefined case. */
3562 if (sym_sec
== NULL
)
3565 /* If the branch is out of reach, then redirect the
3566 call to the local stub for this function. */
3567 if (value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3569 hsh
= hppa_get_stub_entry (input_section
, sym_sec
,
3572 return bfd_reloc_undefined
;
3574 /* Munge up the value and addend so that we call the stub
3575 rather than the procedure directly. */
3576 value
= (hsh
->stub_offset
3577 + hsh
->stub_sec
->output_offset
3578 + hsh
->stub_sec
->output_section
->vma
3584 /* Something we don't know how to handle. */
3586 return bfd_reloc_notsupported
;
3589 /* Make sure we can reach the stub. */
3590 if (max_branch_offset
!= 0
3591 && value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3593 (*_bfd_error_handler
)
3594 (_("%B(%A+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
3598 hsh
->bh_root
.string
);
3599 bfd_set_error (bfd_error_bad_value
);
3600 return bfd_reloc_notsupported
;
3603 val
= hppa_field_adjust (value
, addend
, r_field
);
3607 case R_PARISC_PCREL12F
:
3608 case R_PARISC_PCREL17C
:
3609 case R_PARISC_PCREL17F
:
3610 case R_PARISC_PCREL17R
:
3611 case R_PARISC_PCREL22F
:
3612 case R_PARISC_DIR17F
:
3613 case R_PARISC_DIR17R
:
3614 /* This is a branch. Divide the offset by four.
3615 Note that we need to decide whether it's a branch or
3616 otherwise by inspecting the reloc. Inspecting insn won't
3617 work as insn might be from a .word directive. */
3625 insn
= hppa_rebuild_insn (insn
, val
, r_format
);
3627 /* Update the instruction word. */
3628 bfd_put_32 (input_bfd
, (bfd_vma
) insn
, hit_data
);
3629 return bfd_reloc_ok
;
3632 /* Relocate an HPPA ELF section. */
3635 elf32_hppa_relocate_section (bfd
*output_bfd
,
3636 struct bfd_link_info
*info
,
3638 asection
*input_section
,
3640 Elf_Internal_Rela
*relocs
,
3641 Elf_Internal_Sym
*local_syms
,
3642 asection
**local_sections
)
3644 bfd_vma
*local_got_offsets
;
3645 struct elf32_hppa_link_hash_table
*htab
;
3646 Elf_Internal_Shdr
*symtab_hdr
;
3647 Elf_Internal_Rela
*rela
;
3648 Elf_Internal_Rela
*relend
;
3650 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3652 htab
= hppa_link_hash_table (info
);
3653 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3656 relend
= relocs
+ input_section
->reloc_count
;
3657 for (; rela
< relend
; rela
++)
3659 unsigned int r_type
;
3660 reloc_howto_type
*howto
;
3661 unsigned int r_symndx
;
3662 struct elf32_hppa_link_hash_entry
*hh
;
3663 Elf_Internal_Sym
*sym
;
3666 bfd_reloc_status_type rstatus
;
3667 const char *sym_name
;
3669 bfd_boolean warned_undef
;
3671 r_type
= ELF32_R_TYPE (rela
->r_info
);
3672 if (r_type
>= (unsigned int) R_PARISC_UNIMPLEMENTED
)
3674 bfd_set_error (bfd_error_bad_value
);
3677 if (r_type
== (unsigned int) R_PARISC_GNU_VTENTRY
3678 || r_type
== (unsigned int) R_PARISC_GNU_VTINHERIT
)
3681 r_symndx
= ELF32_R_SYM (rela
->r_info
);
3685 warned_undef
= FALSE
;
3686 if (r_symndx
< symtab_hdr
->sh_info
)
3688 /* This is a local symbol, h defaults to NULL. */
3689 sym
= local_syms
+ r_symndx
;
3690 sym_sec
= local_sections
[r_symndx
];
3691 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sym_sec
, rela
);
3695 struct elf_link_hash_entry
*eh
;
3696 bfd_boolean unresolved_reloc
;
3697 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (input_bfd
);
3699 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rela
,
3700 r_symndx
, symtab_hdr
, sym_hashes
,
3701 eh
, sym_sec
, relocation
,
3702 unresolved_reloc
, warned_undef
);
3704 if (!info
->relocatable
3706 && eh
->root
.type
!= bfd_link_hash_defined
3707 && eh
->root
.type
!= bfd_link_hash_defweak
3708 && eh
->root
.type
!= bfd_link_hash_undefweak
)
3710 if (info
->unresolved_syms_in_objects
== RM_IGNORE
3711 && ELF_ST_VISIBILITY (eh
->other
) == STV_DEFAULT
3712 && eh
->type
== STT_PARISC_MILLI
)
3714 if (! info
->callbacks
->undefined_symbol
3715 (info
, eh_name (eh
), input_bfd
,
3716 input_section
, rela
->r_offset
, FALSE
))
3718 warned_undef
= TRUE
;
3721 hh
= hppa_elf_hash_entry (eh
);
3724 if (sym_sec
!= NULL
&& elf_discarded_section (sym_sec
))
3726 /* For relocs against symbols from removed linkonce
3727 sections, or sections discarded by a linker script,
3728 we just want the section contents zeroed. Avoid any
3729 special processing. */
3730 _bfd_clear_contents (elf_hppa_howto_table
+ r_type
, input_bfd
,
3731 contents
+ rela
->r_offset
);
3737 if (info
->relocatable
)
3740 /* Do any required modifications to the relocation value, and
3741 determine what types of dynamic info we need to output, if
3746 case R_PARISC_DLTIND14F
:
3747 case R_PARISC_DLTIND14R
:
3748 case R_PARISC_DLTIND21L
:
3751 bfd_boolean do_got
= 0;
3753 /* Relocation is to the entry for this symbol in the
3754 global offset table. */
3759 off
= hh
->eh
.got
.offset
;
3760 dyn
= htab
->etab
.dynamic_sections_created
;
3761 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
,
3764 /* If we aren't going to call finish_dynamic_symbol,
3765 then we need to handle initialisation of the .got
3766 entry and create needed relocs here. Since the
3767 offset must always be a multiple of 4, we use the
3768 least significant bit to record whether we have
3769 initialised it already. */
3774 hh
->eh
.got
.offset
|= 1;
3781 /* Local symbol case. */
3782 if (local_got_offsets
== NULL
)
3785 off
= local_got_offsets
[r_symndx
];
3787 /* The offset must always be a multiple of 4. We use
3788 the least significant bit to record whether we have
3789 already generated the necessary reloc. */
3794 local_got_offsets
[r_symndx
] |= 1;
3803 /* Output a dynamic relocation for this GOT entry.
3804 In this case it is relative to the base of the
3805 object because the symbol index is zero. */
3806 Elf_Internal_Rela outrel
;
3808 asection
*sec
= htab
->srelgot
;
3810 outrel
.r_offset
= (off
3811 + htab
->sgot
->output_offset
3812 + htab
->sgot
->output_section
->vma
);
3813 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_DIR32
);
3814 outrel
.r_addend
= relocation
;
3815 loc
= sec
->contents
;
3816 loc
+= sec
->reloc_count
++ * sizeof (Elf32_External_Rela
);
3817 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
3820 bfd_put_32 (output_bfd
, relocation
,
3821 htab
->sgot
->contents
+ off
);
3824 if (off
>= (bfd_vma
) -2)
3827 /* Add the base of the GOT to the relocation value. */
3829 + htab
->sgot
->output_offset
3830 + htab
->sgot
->output_section
->vma
);
3834 case R_PARISC_SEGREL32
:
3835 /* If this is the first SEGREL relocation, then initialize
3836 the segment base values. */
3837 if (htab
->text_segment_base
== (bfd_vma
) -1)
3838 bfd_map_over_sections (output_bfd
, hppa_record_segment_addr
, htab
);
3841 case R_PARISC_PLABEL14R
:
3842 case R_PARISC_PLABEL21L
:
3843 case R_PARISC_PLABEL32
:
3844 if (htab
->etab
.dynamic_sections_created
)
3847 bfd_boolean do_plt
= 0;
3848 /* If we have a global symbol with a PLT slot, then
3849 redirect this relocation to it. */
3852 off
= hh
->eh
.plt
.offset
;
3853 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
->shared
,
3856 /* In a non-shared link, adjust_dynamic_symbols
3857 isn't called for symbols forced local. We
3858 need to write out the plt entry here. */
3863 hh
->eh
.plt
.offset
|= 1;
3870 bfd_vma
*local_plt_offsets
;
3872 if (local_got_offsets
== NULL
)
3875 local_plt_offsets
= local_got_offsets
+ symtab_hdr
->sh_info
;
3876 off
= local_plt_offsets
[r_symndx
];
3878 /* As for the local .got entry case, we use the last
3879 bit to record whether we've already initialised
3880 this local .plt entry. */
3885 local_plt_offsets
[r_symndx
] |= 1;
3894 /* Output a dynamic IPLT relocation for this
3896 Elf_Internal_Rela outrel
;
3898 asection
*s
= htab
->srelplt
;
3900 outrel
.r_offset
= (off
3901 + htab
->splt
->output_offset
3902 + htab
->splt
->output_section
->vma
);
3903 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_IPLT
);
3904 outrel
.r_addend
= relocation
;
3906 loc
+= s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
3907 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
3911 bfd_put_32 (output_bfd
,
3913 htab
->splt
->contents
+ off
);
3914 bfd_put_32 (output_bfd
,
3915 elf_gp (htab
->splt
->output_section
->owner
),
3916 htab
->splt
->contents
+ off
+ 4);
3920 if (off
>= (bfd_vma
) -2)
3923 /* PLABELs contain function pointers. Relocation is to
3924 the entry for the function in the .plt. The magic +2
3925 offset signals to $$dyncall that the function pointer
3926 is in the .plt and thus has a gp pointer too.
3927 Exception: Undefined PLABELs should have a value of
3930 || (hh
->eh
.root
.type
!= bfd_link_hash_undefweak
3931 && hh
->eh
.root
.type
!= bfd_link_hash_undefined
))
3934 + htab
->splt
->output_offset
3935 + htab
->splt
->output_section
->vma
3940 /* Fall through and possibly emit a dynamic relocation. */
3942 case R_PARISC_DIR17F
:
3943 case R_PARISC_DIR17R
:
3944 case R_PARISC_DIR14F
:
3945 case R_PARISC_DIR14R
:
3946 case R_PARISC_DIR21L
:
3947 case R_PARISC_DPREL14F
:
3948 case R_PARISC_DPREL14R
:
3949 case R_PARISC_DPREL21L
:
3950 case R_PARISC_DIR32
:
3951 if ((input_section
->flags
& SEC_ALLOC
) == 0)
3954 /* The reloc types handled here and this conditional
3955 expression must match the code in ..check_relocs and
3956 allocate_dynrelocs. ie. We need exactly the same condition
3957 as in ..check_relocs, with some extra conditions (dynindx
3958 test in this case) to cater for relocs removed by
3959 allocate_dynrelocs. If you squint, the non-shared test
3960 here does indeed match the one in ..check_relocs, the
3961 difference being that here we test DEF_DYNAMIC as well as
3962 !DEF_REGULAR. All common syms end up with !DEF_REGULAR,
3963 which is why we can't use just that test here.
3964 Conversely, DEF_DYNAMIC can't be used in check_relocs as
3965 there all files have not been loaded. */
3968 || ELF_ST_VISIBILITY (hh
->eh
.other
) == STV_DEFAULT
3969 || hh
->eh
.root
.type
!= bfd_link_hash_undefweak
)
3970 && (IS_ABSOLUTE_RELOC (r_type
)
3971 || !SYMBOL_CALLS_LOCAL (info
, &hh
->eh
)))
3974 && hh
->eh
.dynindx
!= -1
3975 && !hh
->eh
.non_got_ref
3976 && ((ELIMINATE_COPY_RELOCS
3977 && hh
->eh
.def_dynamic
3978 && !hh
->eh
.def_regular
)
3979 || hh
->eh
.root
.type
== bfd_link_hash_undefweak
3980 || hh
->eh
.root
.type
== bfd_link_hash_undefined
)))
3982 Elf_Internal_Rela outrel
;
3987 /* When generating a shared object, these relocations
3988 are copied into the output file to be resolved at run
3991 outrel
.r_addend
= rela
->r_addend
;
3993 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3995 skip
= (outrel
.r_offset
== (bfd_vma
) -1
3996 || outrel
.r_offset
== (bfd_vma
) -2);
3997 outrel
.r_offset
+= (input_section
->output_offset
3998 + input_section
->output_section
->vma
);
4002 memset (&outrel
, 0, sizeof (outrel
));
4005 && hh
->eh
.dynindx
!= -1
4007 || !IS_ABSOLUTE_RELOC (r_type
)
4010 || !hh
->eh
.def_regular
))
4012 outrel
.r_info
= ELF32_R_INFO (hh
->eh
.dynindx
, r_type
);
4014 else /* It's a local symbol, or one marked to become local. */
4018 /* Add the absolute offset of the symbol. */
4019 outrel
.r_addend
+= relocation
;
4021 /* Global plabels need to be processed by the
4022 dynamic linker so that functions have at most one
4023 fptr. For this reason, we need to differentiate
4024 between global and local plabels, which we do by
4025 providing the function symbol for a global plabel
4026 reloc, and no symbol for local plabels. */
4029 && sym_sec
->output_section
!= NULL
4030 && ! bfd_is_abs_section (sym_sec
))
4034 osec
= sym_sec
->output_section
;
4035 indx
= elf_section_data (osec
)->dynindx
;
4038 osec
= htab
->etab
.text_index_section
;
4039 indx
= elf_section_data (osec
)->dynindx
;
4041 BFD_ASSERT (indx
!= 0);
4043 /* We are turning this relocation into one
4044 against a section symbol, so subtract out the
4045 output section's address but not the offset
4046 of the input section in the output section. */
4047 outrel
.r_addend
-= osec
->vma
;
4050 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
4052 sreloc
= elf_section_data (input_section
)->sreloc
;
4056 loc
= sreloc
->contents
;
4057 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4058 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4062 case R_PARISC_TLS_LDM21L
:
4063 case R_PARISC_TLS_LDM14R
:
4067 off
= htab
->tls_ldm_got
.offset
;
4072 Elf_Internal_Rela outrel
;
4075 outrel
.r_offset
= (off
4076 + htab
->sgot
->output_section
->vma
4077 + htab
->sgot
->output_offset
);
4078 outrel
.r_addend
= 0;
4079 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_TLS_DTPMOD32
);
4080 loc
= htab
->srelgot
->contents
;
4081 loc
+= htab
->srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4083 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4084 htab
->tls_ldm_got
.offset
|= 1;
4087 /* Add the base of the GOT to the relocation value. */
4089 + htab
->sgot
->output_offset
4090 + htab
->sgot
->output_section
->vma
);
4095 case R_PARISC_TLS_LDO21L
:
4096 case R_PARISC_TLS_LDO14R
:
4097 relocation
-= dtpoff_base (info
);
4100 case R_PARISC_TLS_GD21L
:
4101 case R_PARISC_TLS_GD14R
:
4102 case R_PARISC_TLS_IE21L
:
4103 case R_PARISC_TLS_IE14R
:
4113 dyn
= htab
->etab
.dynamic_sections_created
;
4115 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, &hh
->eh
)
4117 || !SYMBOL_REFERENCES_LOCAL (info
, &hh
->eh
)))
4119 indx
= hh
->eh
.dynindx
;
4121 off
= hh
->eh
.got
.offset
;
4122 tls_type
= hh
->tls_type
;
4126 off
= local_got_offsets
[r_symndx
];
4127 tls_type
= hppa_elf_local_got_tls_type (input_bfd
)[r_symndx
];
4130 if (tls_type
== GOT_UNKNOWN
)
4137 bfd_boolean need_relocs
= FALSE
;
4138 Elf_Internal_Rela outrel
;
4139 bfd_byte
*loc
= NULL
;
4142 /* The GOT entries have not been initialized yet. Do it
4143 now, and emit any relocations. If both an IE GOT and a
4144 GD GOT are necessary, we emit the GD first. */
4146 if ((info
->shared
|| indx
!= 0)
4148 || ELF_ST_VISIBILITY (hh
->eh
.other
) == STV_DEFAULT
4149 || hh
->eh
.root
.type
!= bfd_link_hash_undefweak
))
4152 loc
= htab
->srelgot
->contents
;
4153 /* FIXME (CAO): Should this be reloc_count++ ? */
4154 loc
+= htab
->srelgot
->reloc_count
* sizeof (Elf32_External_Rela
);
4157 if (tls_type
& GOT_TLS_GD
)
4161 outrel
.r_offset
= (cur_off
4162 + htab
->sgot
->output_section
->vma
4163 + htab
->sgot
->output_offset
);
4164 outrel
.r_info
= ELF32_R_INFO (indx
,R_PARISC_TLS_DTPMOD32
);
4165 outrel
.r_addend
= 0;
4166 bfd_put_32 (output_bfd
, 0, htab
->sgot
->contents
+ cur_off
);
4167 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4168 htab
->srelgot
->reloc_count
++;
4169 loc
+= sizeof (Elf32_External_Rela
);
4172 bfd_put_32 (output_bfd
, relocation
- dtpoff_base (info
),
4173 htab
->sgot
->contents
+ cur_off
+ 4);
4176 bfd_put_32 (output_bfd
, 0,
4177 htab
->sgot
->contents
+ cur_off
+ 4);
4178 outrel
.r_info
= ELF32_R_INFO (indx
, R_PARISC_TLS_DTPOFF32
);
4179 outrel
.r_offset
+= 4;
4180 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,loc
);
4181 htab
->srelgot
->reloc_count
++;
4182 loc
+= sizeof (Elf32_External_Rela
);
4187 /* If we are not emitting relocations for a
4188 general dynamic reference, then we must be in a
4189 static link or an executable link with the
4190 symbol binding locally. Mark it as belonging
4191 to module 1, the executable. */
4192 bfd_put_32 (output_bfd
, 1,
4193 htab
->sgot
->contents
+ cur_off
);
4194 bfd_put_32 (output_bfd
, relocation
- dtpoff_base (info
),
4195 htab
->sgot
->contents
+ cur_off
+ 4);
4202 if (tls_type
& GOT_TLS_IE
)
4206 outrel
.r_offset
= (cur_off
4207 + htab
->sgot
->output_section
->vma
4208 + htab
->sgot
->output_offset
);
4209 outrel
.r_info
= ELF32_R_INFO (indx
, R_PARISC_TLS_TPREL32
);
4212 outrel
.r_addend
= relocation
- dtpoff_base (info
);
4214 outrel
.r_addend
= 0;
4216 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4217 htab
->srelgot
->reloc_count
++;
4218 loc
+= sizeof (Elf32_External_Rela
);
4221 bfd_put_32 (output_bfd
, tpoff (info
, relocation
),
4222 htab
->sgot
->contents
+ cur_off
);
4228 hh
->eh
.got
.offset
|= 1;
4230 local_got_offsets
[r_symndx
] |= 1;
4233 if ((tls_type
& GOT_TLS_GD
)
4234 && r_type
!= R_PARISC_TLS_GD21L
4235 && r_type
!= R_PARISC_TLS_GD14R
)
4236 off
+= 2 * GOT_ENTRY_SIZE
;
4238 /* Add the base of the GOT to the relocation value. */
4240 + htab
->sgot
->output_offset
4241 + htab
->sgot
->output_section
->vma
);
4246 case R_PARISC_TLS_LE21L
:
4247 case R_PARISC_TLS_LE14R
:
4249 relocation
= tpoff (info
, relocation
);
4258 rstatus
= final_link_relocate (input_section
, contents
, rela
, relocation
,
4259 htab
, sym_sec
, hh
, info
);
4261 if (rstatus
== bfd_reloc_ok
)
4265 sym_name
= hh_name (hh
);
4268 sym_name
= bfd_elf_string_from_elf_section (input_bfd
,
4269 symtab_hdr
->sh_link
,
4271 if (sym_name
== NULL
)
4273 if (*sym_name
== '\0')
4274 sym_name
= bfd_section_name (input_bfd
, sym_sec
);
4277 howto
= elf_hppa_howto_table
+ r_type
;
4279 if (rstatus
== bfd_reloc_undefined
|| rstatus
== bfd_reloc_notsupported
)
4281 if (rstatus
== bfd_reloc_notsupported
|| !warned_undef
)
4283 (*_bfd_error_handler
)
4284 (_("%B(%A+0x%lx): cannot handle %s for %s"),
4287 (long) rela
->r_offset
,
4290 bfd_set_error (bfd_error_bad_value
);
4296 if (!((*info
->callbacks
->reloc_overflow
)
4297 (info
, (hh
? &hh
->eh
.root
: NULL
), sym_name
, howto
->name
,
4298 (bfd_vma
) 0, input_bfd
, input_section
, rela
->r_offset
)))
4306 /* Finish up dynamic symbol handling. We set the contents of various
4307 dynamic sections here. */
4310 elf32_hppa_finish_dynamic_symbol (bfd
*output_bfd
,
4311 struct bfd_link_info
*info
,
4312 struct elf_link_hash_entry
*eh
,
4313 Elf_Internal_Sym
*sym
)
4315 struct elf32_hppa_link_hash_table
*htab
;
4316 Elf_Internal_Rela rela
;
4319 htab
= hppa_link_hash_table (info
);
4321 if (eh
->plt
.offset
!= (bfd_vma
) -1)
4325 if (eh
->plt
.offset
& 1)
4328 /* This symbol has an entry in the procedure linkage table. Set
4331 The format of a plt entry is
4336 if (eh
->root
.type
== bfd_link_hash_defined
4337 || eh
->root
.type
== bfd_link_hash_defweak
)
4339 value
= eh
->root
.u
.def
.value
;
4340 if (eh
->root
.u
.def
.section
->output_section
!= NULL
)
4341 value
+= (eh
->root
.u
.def
.section
->output_offset
4342 + eh
->root
.u
.def
.section
->output_section
->vma
);
4345 /* Create a dynamic IPLT relocation for this entry. */
4346 rela
.r_offset
= (eh
->plt
.offset
4347 + htab
->splt
->output_offset
4348 + htab
->splt
->output_section
->vma
);
4349 if (eh
->dynindx
!= -1)
4351 rela
.r_info
= ELF32_R_INFO (eh
->dynindx
, R_PARISC_IPLT
);
4356 /* This symbol has been marked to become local, and is
4357 used by a plabel so must be kept in the .plt. */
4358 rela
.r_info
= ELF32_R_INFO (0, R_PARISC_IPLT
);
4359 rela
.r_addend
= value
;
4362 loc
= htab
->srelplt
->contents
;
4363 loc
+= htab
->srelplt
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4364 bfd_elf32_swap_reloca_out (htab
->splt
->output_section
->owner
, &rela
, loc
);
4366 if (!eh
->def_regular
)
4368 /* Mark the symbol as undefined, rather than as defined in
4369 the .plt section. Leave the value alone. */
4370 sym
->st_shndx
= SHN_UNDEF
;
4374 if (eh
->got
.offset
!= (bfd_vma
) -1
4375 && (hppa_elf_hash_entry (eh
)->tls_type
& GOT_TLS_GD
) == 0
4376 && (hppa_elf_hash_entry (eh
)->tls_type
& GOT_TLS_IE
) == 0)
4378 /* This symbol has an entry in the global offset table. Set it
4381 rela
.r_offset
= ((eh
->got
.offset
&~ (bfd_vma
) 1)
4382 + htab
->sgot
->output_offset
4383 + htab
->sgot
->output_section
->vma
);
4385 /* If this is a -Bsymbolic link and the symbol is defined
4386 locally or was forced to be local because of a version file,
4387 we just want to emit a RELATIVE reloc. The entry in the
4388 global offset table will already have been initialized in the
4389 relocate_section function. */
4391 && (info
->symbolic
|| eh
->dynindx
== -1)
4394 rela
.r_info
= ELF32_R_INFO (0, R_PARISC_DIR32
);
4395 rela
.r_addend
= (eh
->root
.u
.def
.value
4396 + eh
->root
.u
.def
.section
->output_offset
4397 + eh
->root
.u
.def
.section
->output_section
->vma
);
4401 if ((eh
->got
.offset
& 1) != 0)
4404 bfd_put_32 (output_bfd
, 0, htab
->sgot
->contents
+ (eh
->got
.offset
& ~1));
4405 rela
.r_info
= ELF32_R_INFO (eh
->dynindx
, R_PARISC_DIR32
);
4409 loc
= htab
->srelgot
->contents
;
4410 loc
+= htab
->srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4411 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4418 /* This symbol needs a copy reloc. Set it up. */
4420 if (! (eh
->dynindx
!= -1
4421 && (eh
->root
.type
== bfd_link_hash_defined
4422 || eh
->root
.type
== bfd_link_hash_defweak
)))
4425 sec
= htab
->srelbss
;
4427 rela
.r_offset
= (eh
->root
.u
.def
.value
4428 + eh
->root
.u
.def
.section
->output_offset
4429 + eh
->root
.u
.def
.section
->output_section
->vma
);
4431 rela
.r_info
= ELF32_R_INFO (eh
->dynindx
, R_PARISC_COPY
);
4432 loc
= sec
->contents
+ sec
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4433 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4436 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
4437 if (eh_name (eh
)[0] == '_'
4438 && (strcmp (eh_name (eh
), "_DYNAMIC") == 0
4439 || eh
== htab
->etab
.hgot
))
4441 sym
->st_shndx
= SHN_ABS
;
4447 /* Used to decide how to sort relocs in an optimal manner for the
4448 dynamic linker, before writing them out. */
4450 static enum elf_reloc_type_class
4451 elf32_hppa_reloc_type_class (const Elf_Internal_Rela
*rela
)
4453 /* Handle TLS relocs first; we don't want them to be marked
4454 relative by the "if (ELF32_R_SYM (rela->r_info) == 0)"
4456 switch ((int) ELF32_R_TYPE (rela
->r_info
))
4458 case R_PARISC_TLS_DTPMOD32
:
4459 case R_PARISC_TLS_DTPOFF32
:
4460 case R_PARISC_TLS_TPREL32
:
4461 return reloc_class_normal
;
4464 if (ELF32_R_SYM (rela
->r_info
) == 0)
4465 return reloc_class_relative
;
4467 switch ((int) ELF32_R_TYPE (rela
->r_info
))
4470 return reloc_class_plt
;
4472 return reloc_class_copy
;
4474 return reloc_class_normal
;
4478 /* Finish up the dynamic sections. */
4481 elf32_hppa_finish_dynamic_sections (bfd
*output_bfd
,
4482 struct bfd_link_info
*info
)
4485 struct elf32_hppa_link_hash_table
*htab
;
4488 htab
= hppa_link_hash_table (info
);
4489 dynobj
= htab
->etab
.dynobj
;
4491 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4493 if (htab
->etab
.dynamic_sections_created
)
4495 Elf32_External_Dyn
*dyncon
, *dynconend
;
4500 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4501 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4502 for (; dyncon
< dynconend
; dyncon
++)
4504 Elf_Internal_Dyn dyn
;
4507 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4515 /* Use PLTGOT to set the GOT register. */
4516 dyn
.d_un
.d_ptr
= elf_gp (output_bfd
);
4521 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4526 dyn
.d_un
.d_val
= s
->size
;
4530 /* Don't count procedure linkage table relocs in the
4531 overall reloc count. */
4535 dyn
.d_un
.d_val
-= s
->size
;
4539 /* We may not be using the standard ELF linker script.
4540 If .rela.plt is the first .rela section, we adjust
4541 DT_RELA to not include it. */
4545 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
4547 dyn
.d_un
.d_ptr
+= s
->size
;
4551 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4555 if (htab
->sgot
!= NULL
&& htab
->sgot
->size
!= 0)
4557 /* Fill in the first entry in the global offset table.
4558 We use it to point to our dynamic section, if we have one. */
4559 bfd_put_32 (output_bfd
,
4560 sdyn
? sdyn
->output_section
->vma
+ sdyn
->output_offset
: 0,
4561 htab
->sgot
->contents
);
4563 /* The second entry is reserved for use by the dynamic linker. */
4564 memset (htab
->sgot
->contents
+ GOT_ENTRY_SIZE
, 0, GOT_ENTRY_SIZE
);
4566 /* Set .got entry size. */
4567 elf_section_data (htab
->sgot
->output_section
)
4568 ->this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
4571 if (htab
->splt
!= NULL
&& htab
->splt
->size
!= 0)
4573 /* Set plt entry size. */
4574 elf_section_data (htab
->splt
->output_section
)
4575 ->this_hdr
.sh_entsize
= PLT_ENTRY_SIZE
;
4577 if (htab
->need_plt_stub
)
4579 /* Set up the .plt stub. */
4580 memcpy (htab
->splt
->contents
4581 + htab
->splt
->size
- sizeof (plt_stub
),
4582 plt_stub
, sizeof (plt_stub
));
4584 if ((htab
->splt
->output_offset
4585 + htab
->splt
->output_section
->vma
4587 != (htab
->sgot
->output_offset
4588 + htab
->sgot
->output_section
->vma
))
4590 (*_bfd_error_handler
)
4591 (_(".got section not immediately after .plt section"));
4600 /* Called when writing out an object file to decide the type of a
4603 elf32_hppa_elf_get_symbol_type (Elf_Internal_Sym
*elf_sym
, int type
)
4605 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_PARISC_MILLI
)
4606 return STT_PARISC_MILLI
;
4611 /* Misc BFD support code. */
4612 #define bfd_elf32_bfd_is_local_label_name elf_hppa_is_local_label_name
4613 #define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
4614 #define bfd_elf32_bfd_reloc_name_lookup elf_hppa_reloc_name_lookup
4615 #define elf_info_to_howto elf_hppa_info_to_howto
4616 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
4618 /* Stuff for the BFD linker. */
4619 #define bfd_elf32_mkobject elf32_hppa_mkobject
4620 #define bfd_elf32_bfd_final_link elf32_hppa_final_link
4621 #define bfd_elf32_bfd_link_hash_table_create elf32_hppa_link_hash_table_create
4622 #define bfd_elf32_bfd_link_hash_table_free elf32_hppa_link_hash_table_free
4623 #define elf_backend_adjust_dynamic_symbol elf32_hppa_adjust_dynamic_symbol
4624 #define elf_backend_copy_indirect_symbol elf32_hppa_copy_indirect_symbol
4625 #define elf_backend_check_relocs elf32_hppa_check_relocs
4626 #define elf_backend_create_dynamic_sections elf32_hppa_create_dynamic_sections
4627 #define elf_backend_fake_sections elf_hppa_fake_sections
4628 #define elf_backend_relocate_section elf32_hppa_relocate_section
4629 #define elf_backend_hide_symbol elf32_hppa_hide_symbol
4630 #define elf_backend_finish_dynamic_symbol elf32_hppa_finish_dynamic_symbol
4631 #define elf_backend_finish_dynamic_sections elf32_hppa_finish_dynamic_sections
4632 #define elf_backend_size_dynamic_sections elf32_hppa_size_dynamic_sections
4633 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
4634 #define elf_backend_gc_mark_hook elf32_hppa_gc_mark_hook
4635 #define elf_backend_gc_sweep_hook elf32_hppa_gc_sweep_hook
4636 #define elf_backend_grok_prstatus elf32_hppa_grok_prstatus
4637 #define elf_backend_grok_psinfo elf32_hppa_grok_psinfo
4638 #define elf_backend_object_p elf32_hppa_object_p
4639 #define elf_backend_final_write_processing elf_hppa_final_write_processing
4640 #define elf_backend_post_process_headers _bfd_elf_set_osabi
4641 #define elf_backend_get_symbol_type elf32_hppa_elf_get_symbol_type
4642 #define elf_backend_reloc_type_class elf32_hppa_reloc_type_class
4643 #define elf_backend_action_discarded elf_hppa_action_discarded
4645 #define elf_backend_can_gc_sections 1
4646 #define elf_backend_can_refcount 1
4647 #define elf_backend_plt_alignment 2
4648 #define elf_backend_want_got_plt 0
4649 #define elf_backend_plt_readonly 0
4650 #define elf_backend_want_plt_sym 0
4651 #define elf_backend_got_header_size 8
4652 #define elf_backend_rela_normal 1
4654 #define TARGET_BIG_SYM bfd_elf32_hppa_vec
4655 #define TARGET_BIG_NAME "elf32-hppa"
4656 #define ELF_ARCH bfd_arch_hppa
4657 #define ELF_MACHINE_CODE EM_PARISC
4658 #define ELF_MAXPAGESIZE 0x1000
4659 #define ELF_OSABI ELFOSABI_HPUX
4660 #define elf32_bed elf32_hppa_hpux_bed
4662 #include "elf32-target.h"
4664 #undef TARGET_BIG_SYM
4665 #define TARGET_BIG_SYM bfd_elf32_hppa_linux_vec
4666 #undef TARGET_BIG_NAME
4667 #define TARGET_BIG_NAME "elf32-hppa-linux"
4669 #define ELF_OSABI ELFOSABI_LINUX
4671 #define elf32_bed elf32_hppa_linux_bed
4673 #include "elf32-target.h"
4675 #undef TARGET_BIG_SYM
4676 #define TARGET_BIG_SYM bfd_elf32_hppa_nbsd_vec
4677 #undef TARGET_BIG_NAME
4678 #define TARGET_BIG_NAME "elf32-hppa-netbsd"
4680 #define ELF_OSABI ELFOSABI_NETBSD
4682 #define elf32_bed elf32_hppa_netbsd_bed
4684 #include "elf32-target.h"