1 /* BFD back-end for HP PA-RISC ELF files.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2001
3 Free Software Foundation, Inc.
6 Center for Software Science
7 Department of Computer Science
9 Largely rewritten by Alan Modra <alan@linuxcare.com.au>
11 This file is part of BFD, the Binary File Descriptor library.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
33 #include "elf32-hppa.h"
36 #include "elf32-hppa.h"
38 /* In order to gain some understanding of code in this file without
39 knowing all the intricate details of the linker, note the
42 Functions named elf32_hppa_* are called by external routines, other
43 functions are only called locally. elf32_hppa_* functions appear
44 in this file more or less in the order in which they are called
45 from external routines. eg. elf32_hppa_check_relocs is called
46 early in the link process, elf32_hppa_finish_dynamic_sections is
47 one of the last functions. */
49 /* We use two hash tables to hold information for linking PA ELF objects.
51 The first is the elf32_hppa_link_hash_table which is derived
52 from the standard ELF linker hash table. We use this as a place to
53 attach other hash tables and static information.
55 The second is the stub hash table which is derived from the
56 base BFD hash table. The stub hash table holds the information
57 necessary to build the linker stubs during a link.
59 There are a number of different stubs generated by the linker.
67 : addil LR'X - ($PIC_pcrel$0 - 4),%r1
68 : be,n RR'X - ($PIC_pcrel$0 - 8)(%sr4,%r1)
70 Import stub to call shared library routine from normal object file
71 (single sub-space version)
72 : addil LR'lt_ptr+ltoff,%dp ; get procedure entry point
73 : ldw RR'lt_ptr+ltoff(%r1),%r21
75 : ldw RR'lt_ptr+ltoff+4(%r1),%r19 ; get new dlt value.
77 Import stub to call shared library routine from shared library
78 (single sub-space version)
79 : addil LR'ltoff,%r19 ; get procedure entry point
80 : ldw RR'ltoff(%r1),%r21
82 : ldw RR'ltoff+4(%r1),%r19 ; get new dlt value.
84 Import stub to call shared library routine from normal object file
85 (multiple sub-space support)
86 : addil LR'lt_ptr+ltoff,%dp ; get procedure entry point
87 : ldw RR'lt_ptr+ltoff(%r1),%r21
88 : ldw RR'lt_ptr+ltoff+4(%r1),%r19 ; get new dlt value.
91 : be 0(%sr0,%r21) ; branch to target
92 : stw %rp,-24(%sp) ; save rp
94 Import stub to call shared library routine from shared library
95 (multiple sub-space support)
96 : addil LR'ltoff,%r19 ; get procedure entry point
97 : ldw RR'ltoff(%r1),%r21
98 : ldw RR'ltoff+4(%r1),%r19 ; get new dlt value.
101 : be 0(%sr0,%r21) ; branch to target
102 : stw %rp,-24(%sp) ; save rp
104 Export stub to return from shared lib routine (multiple sub-space support)
105 One of these is created for each exported procedure in a shared
106 library (and stored in the shared lib). Shared lib routines are
107 called via the first instruction in the export stub so that we can
108 do an inter-space return. Not required for single sub-space.
109 : bl,n X,%rp ; trap the return
111 : ldw -24(%sp),%rp ; restore the original rp
114 : be,n 0(%sr0,%rp) ; inter-space return */
116 #define PLT_ENTRY_SIZE 8
117 #define PLABEL_PLT_ENTRY_SIZE PLT_ENTRY_SIZE
118 #define GOT_ENTRY_SIZE 4
119 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
121 static const bfd_byte plt_stub
[] =
123 0x0e, 0x80, 0x10, 0x96, /* 1: ldw 0(%r20),%r22 */
124 0xea, 0xc0, 0xc0, 0x00, /* bv %r0(%r22) */
125 0x0e, 0x88, 0x10, 0x95, /* ldw 4(%r20),%r21 */
126 #define PLT_STUB_ENTRY (3*4)
127 0xea, 0x9f, 0x1f, 0xdd, /* b,l 1b,%r20 */
128 0xd6, 0x80, 0x1c, 0x1e, /* depi 0,31,2,%r20 */
129 0x00, 0xc0, 0xff, 0xee, /* 9: .word fixup_func */
130 0xde, 0xad, 0xbe, 0xef /* .word fixup_ltp */
133 /* Section name for stubs is the associated section name plus this
135 #define STUB_SUFFIX ".stub"
137 /* Setting the following non-zero makes all long branch stubs
138 generated during a shared link of the PIC variety. This saves on
139 relocs, but costs one extra instruction per stub. */
140 #ifndef LONG_BRANCH_PIC_IN_SHLIB
141 #define LONG_BRANCH_PIC_IN_SHLIB 1
144 /* Set this non-zero to use import stubs instead of long branch stubs
145 where a .plt entry exists for the symbol. This is a fairly useless
146 option as import stubs are bigger than PIC long branch stubs. */
147 #ifndef LONG_BRANCH_VIA_PLT
148 #define LONG_BRANCH_VIA_PLT 0
151 /* We don't need to copy any PC- or GP-relative dynamic relocs into a
152 shared object's dynamic section. */
153 #ifndef RELATIVE_DYNAMIC_RELOCS
154 #define RELATIVE_DYNAMIC_RELOCS 0
157 enum elf32_hppa_stub_type
{
158 hppa_stub_long_branch
,
159 hppa_stub_long_branch_shared
,
161 hppa_stub_import_shared
,
166 struct elf32_hppa_stub_hash_entry
{
168 /* Base hash table entry structure. */
169 struct bfd_hash_entry root
;
171 /* The stub section. */
174 #if ! LONG_BRANCH_PIC_IN_SHLIB
175 /* It's associated reloc section. */
179 /* Offset within stub_sec of the beginning of this stub. */
182 /* Given the symbol's value and its section we can determine its final
183 value when building the stubs (so the stub knows where to jump. */
184 bfd_vma target_value
;
185 asection
*target_section
;
187 enum elf32_hppa_stub_type stub_type
;
189 /* The symbol table entry, if any, that this was derived from. */
190 struct elf32_hppa_link_hash_entry
*h
;
192 /* Where this stub is being called from, or, in the case of combined
193 stub sections, the first input section in the group. */
197 struct elf32_hppa_link_hash_entry
{
199 struct elf_link_hash_entry elf
;
201 /* A pointer to the most recently used stub hash entry against this
203 struct elf32_hppa_stub_hash_entry
*stub_cache
;
205 #if ! LONG_BRANCH_PIC_IN_SHLIB
206 /* Used to track whether we have allocated space for a long branch
207 stub relocation for this symbol in the given section. */
208 asection
*stub_reloc_sec
;
211 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
212 /* Used to count relocations for delayed sizing of relocation
214 struct elf32_hppa_dyn_reloc_entry
{
216 /* Next relocation in the chain. */
217 struct elf32_hppa_dyn_reloc_entry
*next
;
219 /* The section in dynobj. */
222 /* Number of relocs copied in this section. */
227 /* Set during a static link if we detect a function is PIC. */
228 unsigned int maybe_pic_call
:1;
230 /* Set if the only reason we need a .plt entry is for a non-PIC to
231 PIC function call. */
232 unsigned int pic_call
:1;
234 /* Set if this symbol is used by a plabel reloc. */
235 unsigned int plabel
:1;
237 /* Set if this symbol is an init or fini function and thus should
238 use an absolute reloc. */
239 unsigned int plt_abs
:1;
242 struct elf32_hppa_link_hash_table
{
244 /* The main hash table. */
245 struct elf_link_hash_table root
;
247 /* The stub hash table. */
248 struct bfd_hash_table stub_hash_table
;
250 /* Linker stub bfd. */
253 /* Linker call-backs. */
254 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
255 void (*layout_sections_again
) PARAMS ((void));
257 /* Array to keep track of which stub sections have been created, and
258 information on stub grouping. */
260 /* This is the section to which stubs in the group will be
263 /* The stub section. */
265 #if ! LONG_BRANCH_PIC_IN_SHLIB
266 /* The stub section's reloc section. */
271 /* Short-cuts to get to dynamic linker sections. */
279 /* Used during a final link to store the base of the text and data
280 segments so that we can perform SEGREL relocations. */
281 bfd_vma text_segment_base
;
282 bfd_vma data_segment_base
;
284 /* Whether we support multiple sub-spaces for shared libs. */
285 unsigned int multi_subspace
:1;
287 /* Flags set when PCREL12F and PCREL17F branches detected. Used to
288 select suitable defaults for the stub group size. */
289 unsigned int has_12bit_branch
:1;
290 unsigned int has_17bit_branch
:1;
292 /* Set if we need a .plt stub to support lazy dynamic linking. */
293 unsigned int need_plt_stub
:1;
296 /* Various hash macros and functions. */
297 #define hppa_link_hash_table(p) \
298 ((struct elf32_hppa_link_hash_table *) ((p)->hash))
300 #define hppa_stub_hash_lookup(table, string, create, copy) \
301 ((struct elf32_hppa_stub_hash_entry *) \
302 bfd_hash_lookup ((table), (string), (create), (copy)))
304 static struct bfd_hash_entry
*stub_hash_newfunc
305 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
307 static struct bfd_hash_entry
*hppa_link_hash_newfunc
308 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
310 static struct bfd_link_hash_table
*elf32_hppa_link_hash_table_create
313 /* Stub handling functions. */
314 static char *hppa_stub_name
315 PARAMS ((const asection
*, const asection
*,
316 const struct elf32_hppa_link_hash_entry
*,
317 const Elf_Internal_Rela
*));
319 static struct elf32_hppa_stub_hash_entry
*hppa_get_stub_entry
320 PARAMS ((const asection
*, const asection
*,
321 struct elf32_hppa_link_hash_entry
*,
322 const Elf_Internal_Rela
*,
323 struct elf32_hppa_link_hash_table
*));
325 static struct elf32_hppa_stub_hash_entry
*hppa_add_stub
326 PARAMS ((const char *, asection
*, struct elf32_hppa_link_hash_table
*));
328 static enum elf32_hppa_stub_type hppa_type_of_stub
329 PARAMS ((asection
*, const Elf_Internal_Rela
*,
330 struct elf32_hppa_link_hash_entry
*, bfd_vma
));
332 static boolean hppa_build_one_stub
333 PARAMS ((struct bfd_hash_entry
*, PTR
));
335 static boolean hppa_size_one_stub
336 PARAMS ((struct bfd_hash_entry
*, PTR
));
338 /* BFD and elf backend functions. */
339 static boolean elf32_hppa_object_p
PARAMS ((bfd
*));
341 static boolean elf32_hppa_add_symbol_hook
342 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
343 const char **, flagword
*, asection
**, bfd_vma
*));
345 static boolean elf32_hppa_create_dynamic_sections
346 PARAMS ((bfd
*, struct bfd_link_info
*));
348 static boolean elf32_hppa_check_relocs
349 PARAMS ((bfd
*, struct bfd_link_info
*,
350 asection
*, const Elf_Internal_Rela
*));
352 static asection
*elf32_hppa_gc_mark_hook
353 PARAMS ((bfd
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
354 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
356 static boolean elf32_hppa_gc_sweep_hook
357 PARAMS ((bfd
*, struct bfd_link_info
*,
358 asection
*, const Elf_Internal_Rela
*));
360 static void elf32_hppa_hide_symbol
361 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
363 static boolean elf32_hppa_adjust_dynamic_symbol
364 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
366 static boolean hppa_handle_PIC_calls
367 PARAMS ((struct elf_link_hash_entry
*, PTR
));
369 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
370 || RELATIVE_DYNAMIC_RELOCS)
371 static boolean hppa_discard_copies
372 PARAMS ((struct elf_link_hash_entry
*, PTR
));
375 static boolean clobber_millicode_symbols
376 PARAMS ((struct elf_link_hash_entry
*, struct bfd_link_info
*));
378 static boolean elf32_hppa_size_dynamic_sections
379 PARAMS ((bfd
*, struct bfd_link_info
*));
381 static boolean elf32_hppa_final_link
382 PARAMS ((bfd
*, struct bfd_link_info
*));
384 static void hppa_record_segment_addr
385 PARAMS ((bfd
*, asection
*, PTR
));
387 static bfd_reloc_status_type final_link_relocate
388 PARAMS ((asection
*, bfd_byte
*, const Elf_Internal_Rela
*,
389 bfd_vma
, struct elf32_hppa_link_hash_table
*, asection
*,
390 struct elf32_hppa_link_hash_entry
*));
392 static boolean elf32_hppa_relocate_section
393 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*,
394 bfd_byte
*, Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
396 static int hppa_unwind_entry_compare
397 PARAMS ((const PTR
, const PTR
));
399 static boolean elf32_hppa_finish_dynamic_symbol
400 PARAMS ((bfd
*, struct bfd_link_info
*,
401 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
403 static boolean elf32_hppa_finish_dynamic_sections
404 PARAMS ((bfd
*, struct bfd_link_info
*));
406 static void elf32_hppa_post_process_headers
407 PARAMS ((bfd
*, struct bfd_link_info
*));
409 static int elf32_hppa_elf_get_symbol_type
410 PARAMS ((Elf_Internal_Sym
*, int));
412 /* Assorted hash table functions. */
414 /* Initialize an entry in the stub hash table. */
416 static struct bfd_hash_entry
*
417 stub_hash_newfunc (entry
, table
, string
)
418 struct bfd_hash_entry
*entry
;
419 struct bfd_hash_table
*table
;
422 struct elf32_hppa_stub_hash_entry
*ret
;
424 ret
= (struct elf32_hppa_stub_hash_entry
*) entry
;
426 /* Allocate the structure if it has not already been allocated by a
430 ret
= ((struct elf32_hppa_stub_hash_entry
*)
431 bfd_hash_allocate (table
,
432 sizeof (struct elf32_hppa_stub_hash_entry
)));
437 /* Call the allocation method of the superclass. */
438 ret
= ((struct elf32_hppa_stub_hash_entry
*)
439 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
443 /* Initialize the local fields. */
444 ret
->stub_sec
= NULL
;
445 #if ! LONG_BRANCH_PIC_IN_SHLIB
446 ret
->reloc_sec
= NULL
;
448 ret
->stub_offset
= 0;
449 ret
->target_value
= 0;
450 ret
->target_section
= NULL
;
451 ret
->stub_type
= hppa_stub_long_branch
;
456 return (struct bfd_hash_entry
*) ret
;
459 /* Initialize an entry in the link hash table. */
461 static struct bfd_hash_entry
*
462 hppa_link_hash_newfunc (entry
, table
, string
)
463 struct bfd_hash_entry
*entry
;
464 struct bfd_hash_table
*table
;
467 struct elf32_hppa_link_hash_entry
*ret
;
469 ret
= (struct elf32_hppa_link_hash_entry
*) entry
;
471 /* Allocate the structure if it has not already been allocated by a
475 ret
= ((struct elf32_hppa_link_hash_entry
*)
476 bfd_hash_allocate (table
,
477 sizeof (struct elf32_hppa_link_hash_entry
)));
482 /* Call the allocation method of the superclass. */
483 ret
= ((struct elf32_hppa_link_hash_entry
*)
484 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
489 /* Initialize the local fields. */
490 #if ! LONG_BRANCH_PIC_IN_SHLIB
491 ret
->stub_reloc_sec
= NULL
;
493 ret
->stub_cache
= NULL
;
494 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
495 ret
->reloc_entries
= NULL
;
497 ret
->maybe_pic_call
= 0;
503 return (struct bfd_hash_entry
*) ret
;
506 /* Create the derived linker hash table. The PA ELF port uses the derived
507 hash table to keep information specific to the PA ELF linker (without
508 using static variables). */
510 static struct bfd_link_hash_table
*
511 elf32_hppa_link_hash_table_create (abfd
)
514 struct elf32_hppa_link_hash_table
*ret
;
516 ret
= ((struct elf32_hppa_link_hash_table
*) bfd_alloc (abfd
, sizeof (*ret
)));
520 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
, hppa_link_hash_newfunc
))
522 bfd_release (abfd
, ret
);
526 /* Init the stub hash table too. */
527 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
))
530 ret
->stub_bfd
= NULL
;
531 ret
->add_stub_section
= NULL
;
532 ret
->layout_sections_again
= NULL
;
533 ret
->stub_group
= NULL
;
540 ret
->text_segment_base
= (bfd_vma
) -1;
541 ret
->data_segment_base
= (bfd_vma
) -1;
542 ret
->multi_subspace
= 0;
543 ret
->has_12bit_branch
= 0;
544 ret
->has_17bit_branch
= 0;
545 ret
->need_plt_stub
= 0;
547 return &ret
->root
.root
;
550 /* Build a name for an entry in the stub hash table. */
553 hppa_stub_name (input_section
, sym_sec
, hash
, rel
)
554 const asection
*input_section
;
555 const asection
*sym_sec
;
556 const struct elf32_hppa_link_hash_entry
*hash
;
557 const Elf_Internal_Rela
*rel
;
564 len
= 8 + 1 + strlen (hash
->elf
.root
.root
.string
) + 1 + 8 + 1;
565 stub_name
= bfd_malloc (len
);
566 if (stub_name
!= NULL
)
568 sprintf (stub_name
, "%08x_%s+%x",
569 input_section
->id
& 0xffffffff,
570 hash
->elf
.root
.root
.string
,
571 (int) rel
->r_addend
& 0xffffffff);
576 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
577 stub_name
= bfd_malloc (len
);
578 if (stub_name
!= NULL
)
580 sprintf (stub_name
, "%08x_%x:%x+%x",
581 input_section
->id
& 0xffffffff,
582 sym_sec
->id
& 0xffffffff,
583 (int) ELF32_R_SYM (rel
->r_info
) & 0xffffffff,
584 (int) rel
->r_addend
& 0xffffffff);
590 /* Look up an entry in the stub hash. Stub entries are cached because
591 creating the stub name takes a bit of time. */
593 static struct elf32_hppa_stub_hash_entry
*
594 hppa_get_stub_entry (input_section
, sym_sec
, hash
, rel
, hplink
)
595 const asection
*input_section
;
596 const asection
*sym_sec
;
597 struct elf32_hppa_link_hash_entry
*hash
;
598 const Elf_Internal_Rela
*rel
;
599 struct elf32_hppa_link_hash_table
*hplink
;
601 struct elf32_hppa_stub_hash_entry
*stub_entry
;
602 const asection
*id_sec
;
604 /* If this input section is part of a group of sections sharing one
605 stub section, then use the id of the first section in the group.
606 Stub names need to include a section id, as there may well be
607 more than one stub used to reach say, printf, and we need to
608 distinguish between them. */
609 id_sec
= hplink
->stub_group
[input_section
->id
].link_sec
;
611 if (hash
!= NULL
&& hash
->stub_cache
!= NULL
612 && hash
->stub_cache
->h
== hash
613 && hash
->stub_cache
->id_sec
== id_sec
)
615 stub_entry
= hash
->stub_cache
;
621 stub_name
= hppa_stub_name (id_sec
, sym_sec
, hash
, rel
);
622 if (stub_name
== NULL
)
625 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
,
626 stub_name
, false, false);
627 if (stub_entry
== NULL
)
629 if (hash
== NULL
|| hash
->elf
.root
.type
!= bfd_link_hash_undefweak
)
630 (*_bfd_error_handler
) (_("%s(%s+0x%lx): cannot find stub entry %s"),
631 bfd_get_filename (input_section
->owner
),
633 (long) rel
->r_offset
,
639 hash
->stub_cache
= stub_entry
;
648 /* Add a new stub entry to the stub hash. Not all fields of the new
649 stub entry are initialised. */
651 static struct elf32_hppa_stub_hash_entry
*
652 hppa_add_stub (stub_name
, section
, hplink
)
653 const char *stub_name
;
655 struct elf32_hppa_link_hash_table
*hplink
;
659 struct elf32_hppa_stub_hash_entry
*stub_entry
;
661 link_sec
= hplink
->stub_group
[section
->id
].link_sec
;
662 stub_sec
= hplink
->stub_group
[section
->id
].stub_sec
;
663 if (stub_sec
== NULL
)
665 stub_sec
= hplink
->stub_group
[link_sec
->id
].stub_sec
;
666 if (stub_sec
== NULL
)
671 len
= strlen (link_sec
->name
) + sizeof (STUB_SUFFIX
);
672 s_name
= bfd_alloc (hplink
->stub_bfd
, len
);
676 strcpy (s_name
, link_sec
->name
);
677 strcpy (s_name
+ len
- sizeof (STUB_SUFFIX
), STUB_SUFFIX
);
678 stub_sec
= (*hplink
->add_stub_section
) (s_name
, link_sec
);
679 if (stub_sec
== NULL
)
681 hplink
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
683 hplink
->stub_group
[section
->id
].stub_sec
= stub_sec
;
686 /* Enter this entry into the linker stub hash table. */
687 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
, stub_name
,
689 if (stub_entry
== NULL
)
691 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
692 bfd_get_filename (section
->owner
),
697 stub_entry
->stub_sec
= stub_sec
;
698 #if ! LONG_BRANCH_PIC_IN_SHLIB
699 stub_entry
->reloc_sec
= hplink
->stub_group
[section
->id
].reloc_sec
;
701 stub_entry
->stub_offset
= 0;
702 stub_entry
->id_sec
= link_sec
;
706 /* Determine the type of stub needed, if any, for a call. */
708 static enum elf32_hppa_stub_type
709 hppa_type_of_stub (input_sec
, rel
, hash
, destination
)
711 const Elf_Internal_Rela
*rel
;
712 struct elf32_hppa_link_hash_entry
*hash
;
716 bfd_vma branch_offset
;
717 bfd_vma max_branch_offset
;
721 && (((hash
->elf
.root
.type
== bfd_link_hash_defined
722 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
723 && hash
->elf
.root
.u
.def
.section
->output_section
== NULL
)
724 || (hash
->elf
.root
.type
== bfd_link_hash_defweak
725 && hash
->elf
.dynindx
!= -1
726 && hash
->elf
.plt
.offset
!= (bfd_vma
) -1)
727 || hash
->elf
.root
.type
== bfd_link_hash_undefweak
728 || hash
->elf
.root
.type
== bfd_link_hash_undefined
729 || (hash
->maybe_pic_call
&& !(input_sec
->flags
& SEC_HAS_GOT_REF
))))
731 /* If output_section is NULL, then it's a symbol defined in a
732 shared library. We will need an import stub. Decide between
733 hppa_stub_import and hppa_stub_import_shared later. For
734 shared links we need stubs for undefined or weak syms too;
735 They will presumably be resolved by the dynamic linker. */
736 return hppa_stub_import
;
739 /* Determine where the call point is. */
740 location
= (input_sec
->output_offset
741 + input_sec
->output_section
->vma
744 branch_offset
= destination
- location
- 8;
745 r_type
= ELF32_R_TYPE (rel
->r_info
);
747 /* Determine if a long branch stub is needed. parisc branch offsets
748 are relative to the second instruction past the branch, ie. +8
749 bytes on from the branch instruction location. The offset is
750 signed and counts in units of 4 bytes. */
751 if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
753 max_branch_offset
= (1 << (17-1)) << 2;
755 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
757 max_branch_offset
= (1 << (12-1)) << 2;
759 else /* R_PARISC_PCREL22F. */
761 max_branch_offset
= (1 << (22-1)) << 2;
764 if (branch_offset
+ max_branch_offset
>= 2*max_branch_offset
)
766 #if LONG_BRANCH_VIA_PLT
768 && hash
->elf
.dynindx
!= -1
769 && hash
->elf
.plt
.offset
!= (bfd_vma
) -1)
771 /* If we are doing a shared link and find we need a long
772 branch stub, then go via the .plt if possible. */
773 return hppa_stub_import
;
777 return hppa_stub_long_branch
;
779 return hppa_stub_none
;
782 /* Build one linker stub as defined by the stub hash table entry GEN_ENTRY.
783 IN_ARG contains the link info pointer. */
785 #define LDIL_R1 0x20200000 /* ldil LR'XXX,%r1 */
786 #define BE_SR4_R1 0xe0202002 /* be,n RR'XXX(%sr4,%r1) */
788 #define BL_R1 0xe8200000 /* b,l .+8,%r1 */
789 #define ADDIL_R1 0x28200000 /* addil LR'XXX,%r1,%r1 */
790 #define DEPI_R1 0xd4201c1e /* depi 0,31,2,%r1 */
792 #define ADDIL_DP 0x2b600000 /* addil LR'XXX,%dp,%r1 */
793 #define LDW_R1_R21 0x48350000 /* ldw RR'XXX(%sr0,%r1),%r21 */
794 #define BV_R0_R21 0xeaa0c000 /* bv %r0(%r21) */
795 #define LDW_R1_R19 0x48330000 /* ldw RR'XXX(%sr0,%r1),%r19 */
797 #define ADDIL_R19 0x2a600000 /* addil LR'XXX,%r19,%r1 */
798 #define LDW_R1_DP 0x483b0000 /* ldw RR'XXX(%sr0,%r1),%dp */
800 #define LDSID_R21_R1 0x02a010a1 /* ldsid (%sr0,%r21),%r1 */
801 #define MTSP_R1 0x00011820 /* mtsp %r1,%sr0 */
802 #define BE_SR0_R21 0xe2a00000 /* be 0(%sr0,%r21) */
803 #define STW_RP 0x6bc23fd1 /* stw %rp,-24(%sr0,%sp) */
805 #define BL_RP 0xe8400002 /* b,l,n XXX,%rp */
806 #define NOP 0x08000240 /* nop */
807 #define LDW_RP 0x4bc23fd1 /* ldw -24(%sr0,%sp),%rp */
808 #define LDSID_RP_R1 0x004010a1 /* ldsid (%sr0,%rp),%r1 */
809 #define BE_SR0_RP 0xe0400002 /* be,n 0(%sr0,%rp) */
816 #define LDW_R1_DLT LDW_R1_R19
818 #define LDW_R1_DLT LDW_R1_DP
822 hppa_build_one_stub (gen_entry
, in_arg
)
823 struct bfd_hash_entry
*gen_entry
;
826 struct elf32_hppa_stub_hash_entry
*stub_entry
;
827 struct bfd_link_info
*info
;
828 struct elf32_hppa_link_hash_table
*hplink
;
838 /* Massage our args to the form they really have. */
839 stub_entry
= (struct elf32_hppa_stub_hash_entry
*) gen_entry
;
840 info
= (struct bfd_link_info
*) in_arg
;
842 hplink
= hppa_link_hash_table (info
);
843 stub_sec
= stub_entry
->stub_sec
;
845 /* Make a note of the offset within the stubs for this entry. */
846 stub_entry
->stub_offset
= stub_sec
->_raw_size
;
847 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
849 stub_bfd
= stub_sec
->owner
;
851 switch (stub_entry
->stub_type
)
853 case hppa_stub_long_branch
:
854 /* Create the long branch. A long branch is formed with "ldil"
855 loading the upper bits of the target address into a register,
856 then branching with "be" which adds in the lower bits.
857 The "be" has its delay slot nullified. */
858 sym_value
= (stub_entry
->target_value
859 + stub_entry
->target_section
->output_offset
860 + stub_entry
->target_section
->output_section
->vma
);
862 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_lrsel
);
863 insn
= hppa_rebuild_insn ((int) LDIL_R1
, val
, 21);
864 bfd_put_32 (stub_bfd
, insn
, loc
);
866 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_rrsel
) >> 2;
867 insn
= hppa_rebuild_insn ((int) BE_SR4_R1
, val
, 17);
868 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
870 #if ! LONG_BRANCH_PIC_IN_SHLIB
873 /* Output a dynamic relocation for this stub. We only
874 output one PCREL21L reloc per stub, trusting that the
875 dynamic linker will also fix the implied PCREL17R for the
876 second instruction. PCREL21L dynamic relocs had better
877 never be emitted for some other purpose... */
879 Elf_Internal_Rela outrel
;
881 if (stub_entry
->h
== NULL
)
883 (*_bfd_error_handler
)
884 (_("%s(%s+0x%lx): cannot relocate %s, recompile with -ffunction-sections"),
885 bfd_get_filename (stub_entry
->target_section
->owner
),
887 (long) stub_entry
->stub_offset
,
888 stub_entry
->root
.string
);
889 bfd_set_error (bfd_error_bad_value
);
893 srel
= stub_entry
->reloc_sec
;
896 (*_bfd_error_handler
)
897 (_("Could not find relocation section for %s"),
899 bfd_set_error (bfd_error_bad_value
);
903 outrel
.r_offset
= (stub_entry
->stub_offset
904 + stub_sec
->output_offset
905 + stub_sec
->output_section
->vma
);
906 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_PCREL21L
);
907 outrel
.r_addend
= sym_value
;
908 bfd_elf32_swap_reloca_out (stub_sec
->output_section
->owner
,
910 ((Elf32_External_Rela
*)
911 srel
->contents
+ srel
->reloc_count
));
918 case hppa_stub_long_branch_shared
:
919 /* Branches are relative. This is where we are going to. */
920 sym_value
= (stub_entry
->target_value
921 + stub_entry
->target_section
->output_offset
922 + stub_entry
->target_section
->output_section
->vma
);
924 /* And this is where we are coming from, more or less. */
925 sym_value
-= (stub_entry
->stub_offset
926 + stub_sec
->output_offset
927 + stub_sec
->output_section
->vma
);
929 bfd_put_32 (stub_bfd
, (bfd_vma
) BL_R1
, loc
);
930 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_lrsel
);
931 insn
= hppa_rebuild_insn ((int) ADDIL_R1
, val
, 21);
932 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
934 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_rrsel
) >> 2;
935 insn
= hppa_rebuild_insn ((int) BE_SR4_R1
, val
, 17);
936 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
940 case hppa_stub_import
:
941 case hppa_stub_import_shared
:
942 off
= stub_entry
->h
->elf
.plt
.offset
;
943 if (off
>= (bfd_vma
) -2)
946 off
&= ~ (bfd_vma
) 1;
948 + hplink
->splt
->output_offset
949 + hplink
->splt
->output_section
->vma
950 - elf_gp (hplink
->splt
->output_section
->owner
));
954 if (stub_entry
->stub_type
== hppa_stub_import_shared
)
957 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_lrsel
),
958 insn
= hppa_rebuild_insn ((int) insn
, val
, 21);
959 bfd_put_32 (stub_bfd
, insn
, loc
);
961 /* It is critical to use lrsel/rrsel here because we are using
962 two different offsets (+0 and +4) from sym_value. If we use
963 lsel/rsel then with unfortunate sym_values we will round
964 sym_value+4 up to the next 2k block leading to a mis-match
965 between the lsel and rsel value. */
966 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_rrsel
);
967 insn
= hppa_rebuild_insn ((int) LDW_R1_R21
, val
, 14);
968 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
970 if (hplink
->multi_subspace
)
972 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 4, e_rrsel
);
973 insn
= hppa_rebuild_insn ((int) LDW_R1_DLT
, val
, 14);
974 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
976 bfd_put_32 (stub_bfd
, (bfd_vma
) LDSID_R21_R1
, loc
+ 12);
977 bfd_put_32 (stub_bfd
, (bfd_vma
) MTSP_R1
, loc
+ 16);
978 bfd_put_32 (stub_bfd
, (bfd_vma
) BE_SR0_R21
, loc
+ 20);
979 bfd_put_32 (stub_bfd
, (bfd_vma
) STW_RP
, loc
+ 24);
985 bfd_put_32 (stub_bfd
, (bfd_vma
) BV_R0_R21
, loc
+ 8);
986 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 4, e_rrsel
);
987 insn
= hppa_rebuild_insn ((int) LDW_R1_DLT
, val
, 14);
988 bfd_put_32 (stub_bfd
, insn
, loc
+ 12);
994 && stub_entry
->h
!= NULL
995 && stub_entry
->h
->pic_call
)
997 /* Build the .plt entry needed to call a PIC function from
998 statically linked code. We don't need any relocs. */
1000 struct elf32_hppa_link_hash_entry
*eh
;
1003 dynobj
= hplink
->root
.dynobj
;
1004 eh
= (struct elf32_hppa_link_hash_entry
*) stub_entry
->h
;
1006 if (eh
->elf
.root
.type
!= bfd_link_hash_defined
1007 && eh
->elf
.root
.type
!= bfd_link_hash_defweak
)
1010 value
= (eh
->elf
.root
.u
.def
.value
1011 + eh
->elf
.root
.u
.def
.section
->output_offset
1012 + eh
->elf
.root
.u
.def
.section
->output_section
->vma
);
1014 /* Fill in the entry in the procedure linkage table.
1016 The format of a plt entry is
1020 bfd_put_32 (hplink
->splt
->owner
, value
,
1021 hplink
->splt
->contents
+ off
);
1022 value
= elf_gp (hplink
->splt
->output_section
->owner
);
1023 bfd_put_32 (hplink
->splt
->owner
, value
,
1024 hplink
->splt
->contents
+ off
+ 4);
1028 case hppa_stub_export
:
1029 /* Branches are relative. This is where we are going to. */
1030 sym_value
= (stub_entry
->target_value
1031 + stub_entry
->target_section
->output_offset
1032 + stub_entry
->target_section
->output_section
->vma
);
1034 /* And this is where we are coming from. */
1035 sym_value
-= (stub_entry
->stub_offset
1036 + stub_sec
->output_offset
1037 + stub_sec
->output_section
->vma
);
1039 if (sym_value
- 8 + 0x40000 >= 0x80000)
1041 (*_bfd_error_handler
)
1042 (_("%s(%s+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
1043 bfd_get_filename (stub_entry
->target_section
->owner
),
1045 (long) stub_entry
->stub_offset
,
1046 stub_entry
->root
.string
);
1047 bfd_set_error (bfd_error_bad_value
);
1051 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_fsel
) >> 2;
1052 insn
= hppa_rebuild_insn ((int) BL_RP
, val
, 17);
1053 bfd_put_32 (stub_bfd
, insn
, loc
);
1055 bfd_put_32 (stub_bfd
, (bfd_vma
) NOP
, loc
+ 4);
1056 bfd_put_32 (stub_bfd
, (bfd_vma
) LDW_RP
, loc
+ 8);
1057 bfd_put_32 (stub_bfd
, (bfd_vma
) LDSID_RP_R1
, loc
+ 12);
1058 bfd_put_32 (stub_bfd
, (bfd_vma
) MTSP_R1
, loc
+ 16);
1059 bfd_put_32 (stub_bfd
, (bfd_vma
) BE_SR0_RP
, loc
+ 20);
1061 /* Point the function symbol at the stub. */
1062 stub_entry
->h
->elf
.root
.u
.def
.section
= stub_sec
;
1063 stub_entry
->h
->elf
.root
.u
.def
.value
= stub_sec
->_raw_size
;
1073 stub_sec
->_raw_size
+= size
;
1099 /* As above, but don't actually build the stub. Just bump offset so
1100 we know stub section sizes. */
1103 hppa_size_one_stub (gen_entry
, in_arg
)
1104 struct bfd_hash_entry
*gen_entry
;
1107 struct elf32_hppa_stub_hash_entry
*stub_entry
;
1108 struct elf32_hppa_link_hash_table
*hplink
;
1111 /* Massage our args to the form they really have. */
1112 stub_entry
= (struct elf32_hppa_stub_hash_entry
*) gen_entry
;
1113 hplink
= (struct elf32_hppa_link_hash_table
*) in_arg
;
1115 if (stub_entry
->stub_type
== hppa_stub_long_branch
)
1117 #if ! LONG_BRANCH_PIC_IN_SHLIB
1118 if (stub_entry
->reloc_sec
!= NULL
)
1119 stub_entry
->reloc_sec
->_raw_size
+= sizeof (Elf32_External_Rela
);
1123 else if (stub_entry
->stub_type
== hppa_stub_long_branch_shared
)
1125 else if (stub_entry
->stub_type
== hppa_stub_export
)
1127 else /* hppa_stub_import or hppa_stub_import_shared. */
1129 if (hplink
->multi_subspace
)
1135 stub_entry
->stub_sec
->_raw_size
+= size
;
1139 /* Return nonzero if ABFD represents an HPPA ELF32 file.
1140 Additionally we set the default architecture and machine. */
1143 elf32_hppa_object_p (abfd
)
1146 unsigned int flags
= elf_elfheader (abfd
)->e_flags
;
1148 switch (flags
& (EF_PARISC_ARCH
| EF_PARISC_WIDE
))
1150 case EFA_PARISC_1_0
:
1151 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 10);
1152 case EFA_PARISC_1_1
:
1153 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 11);
1154 case EFA_PARISC_2_0
:
1155 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 20);
1156 case EFA_PARISC_2_0
| EF_PARISC_WIDE
:
1157 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 25);
1162 /* Undo the generic ELF code's subtraction of section->vma from the
1163 value of each external symbol. */
1166 elf32_hppa_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
1167 bfd
*abfd ATTRIBUTE_UNUSED
;
1168 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1169 const Elf_Internal_Sym
*sym ATTRIBUTE_UNUSED
;
1170 const char **namep ATTRIBUTE_UNUSED
;
1171 flagword
*flagsp ATTRIBUTE_UNUSED
;
1175 *valp
+= (*secp
)->vma
;
1179 /* Create the .plt and .got sections, and set up our hash table
1180 short-cuts to various dynamic sections. */
1183 elf32_hppa_create_dynamic_sections (abfd
, info
)
1185 struct bfd_link_info
*info
;
1187 struct elf32_hppa_link_hash_table
*hplink
;
1189 /* Don't try to create the .plt and .got twice. */
1190 hplink
= hppa_link_hash_table (info
);
1191 if (hplink
->splt
!= NULL
)
1194 /* Call the generic code to do most of the work. */
1195 if (! _bfd_elf_create_dynamic_sections (abfd
, info
))
1198 hplink
->splt
= bfd_get_section_by_name (abfd
, ".plt");
1199 hplink
->srelplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
1201 hplink
->sgot
= bfd_get_section_by_name (abfd
, ".got");
1202 hplink
->srelgot
= bfd_make_section (abfd
, ".rela.got");
1203 if (hplink
->srelgot
== NULL
1204 || ! bfd_set_section_flags (abfd
, hplink
->srelgot
,
1209 | SEC_LINKER_CREATED
1211 || ! bfd_set_section_alignment (abfd
, hplink
->srelgot
, 2))
1214 hplink
->sdynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
1215 hplink
->srelbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
1220 /* Look through the relocs for a section during the first phase, and
1221 allocate space in the global offset table or procedure linkage
1222 table. At this point we haven't necessarily read all the input
1226 elf32_hppa_check_relocs (abfd
, info
, sec
, relocs
)
1228 struct bfd_link_info
*info
;
1230 const Elf_Internal_Rela
*relocs
;
1233 Elf_Internal_Shdr
*symtab_hdr
;
1234 struct elf_link_hash_entry
**sym_hashes
;
1235 bfd_signed_vma
*local_got_refcounts
;
1236 const Elf_Internal_Rela
*rel
;
1237 const Elf_Internal_Rela
*rel_end
;
1238 struct elf32_hppa_link_hash_table
*hplink
;
1240 asection
*stubreloc
;
1242 if (info
->relocateable
)
1245 hplink
= hppa_link_hash_table (info
);
1246 dynobj
= hplink
->root
.dynobj
;
1247 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1248 sym_hashes
= elf_sym_hashes (abfd
);
1249 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1253 rel_end
= relocs
+ sec
->reloc_count
;
1254 for (rel
= relocs
; rel
< rel_end
; rel
++)
1260 #if LONG_BRANCH_PIC_IN_SHLIB
1261 NEED_STUBREL
= 0, /* We won't be needing them in this case. */
1268 unsigned int r_symndx
, r_type
;
1269 struct elf32_hppa_link_hash_entry
*h
;
1272 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1274 if (r_symndx
< symtab_hdr
->sh_info
)
1277 h
= ((struct elf32_hppa_link_hash_entry
*)
1278 sym_hashes
[r_symndx
- symtab_hdr
->sh_info
]);
1280 r_type
= ELF32_R_TYPE (rel
->r_info
);
1284 case R_PARISC_DLTIND14F
:
1285 case R_PARISC_DLTIND14R
:
1286 case R_PARISC_DLTIND21L
:
1287 /* This symbol requires a global offset table entry. */
1288 need_entry
= NEED_GOT
;
1290 /* Mark this section as containing PIC code. */
1291 sec
->flags
|= SEC_HAS_GOT_REF
;
1294 case R_PARISC_PLABEL14R
: /* "Official" procedure labels. */
1295 case R_PARISC_PLABEL21L
:
1296 case R_PARISC_PLABEL32
:
1297 /* If the addend is non-zero, we break badly. */
1298 if (rel
->r_addend
!= 0)
1301 /* If we are creating a shared library, then we need to
1302 create a PLT entry for all PLABELs, because PLABELs with
1303 local symbols may be passed via a pointer to another
1304 object. Additionally, output a dynamic relocation
1305 pointing to the PLT entry. */
1306 need_entry
= PLT_PLABEL
| NEED_PLT
| NEED_DYNREL
;
1309 case R_PARISC_PCREL12F
:
1310 hplink
->has_12bit_branch
= 1;
1312 case R_PARISC_PCREL17C
:
1313 case R_PARISC_PCREL17F
:
1314 hplink
->has_17bit_branch
= 1;
1316 case R_PARISC_PCREL22F
:
1317 /* Function calls might need to go through the .plt, and
1318 might require long branch stubs. */
1321 /* We know local syms won't need a .plt entry, and if
1322 they need a long branch stub we can't guarantee that
1323 we can reach the stub. So just flag an error later
1324 if we're doing a shared link and find we need a long
1330 /* Global symbols will need a .plt entry if they remain
1331 global, and in most cases won't need a long branch
1332 stub. Unfortunately, we have to cater for the case
1333 where a symbol is forced local by versioning, or due
1334 to symbolic linking, and we lose the .plt entry. */
1335 need_entry
= NEED_PLT
| NEED_STUBREL
;
1339 case R_PARISC_SEGBASE
: /* Used to set segment base. */
1340 case R_PARISC_SEGREL32
: /* Relative reloc, used for unwind. */
1341 case R_PARISC_PCREL14F
: /* PC relative load/store. */
1342 case R_PARISC_PCREL14R
:
1343 case R_PARISC_PCREL17R
: /* External branches. */
1344 case R_PARISC_PCREL21L
: /* As above, and for load/store too. */
1345 /* We don't need to propagate the relocation if linking a
1346 shared object since these are section relative. */
1349 case R_PARISC_DPREL14F
: /* Used for gp rel data load/store. */
1350 case R_PARISC_DPREL14R
:
1351 case R_PARISC_DPREL21L
:
1354 (*_bfd_error_handler
)
1355 (_("%s: relocation %s can not be used when making a shared object; recompile with -fPIC"),
1356 bfd_get_filename (abfd
),
1357 elf_hppa_howto_table
[r_type
].name
);
1358 bfd_set_error (bfd_error_bad_value
);
1363 case R_PARISC_DIR17F
: /* Used for external branches. */
1364 case R_PARISC_DIR17R
:
1365 case R_PARISC_DIR14F
: /* Used for load/store from absolute locn. */
1366 case R_PARISC_DIR14R
:
1367 case R_PARISC_DIR21L
: /* As above, and for ext branches too. */
1369 /* Help debug shared library creation. Any of the above
1370 relocs can be used in shared libs, but they may cause
1371 pages to become unshared. */
1374 (*_bfd_error_handler
)
1375 (_("%s: relocation %s should not be used when making a shared object; recompile with -fPIC"),
1376 bfd_get_filename (abfd
),
1377 elf_hppa_howto_table
[r_type
].name
);
1382 case R_PARISC_DIR32
: /* .word relocs. */
1383 /* We may want to output a dynamic relocation later. */
1384 need_entry
= NEED_DYNREL
;
1387 /* This relocation describes the C++ object vtable hierarchy.
1388 Reconstruct it for later use during GC. */
1389 case R_PARISC_GNU_VTINHERIT
:
1390 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
,
1391 &h
->elf
, rel
->r_offset
))
1395 /* This relocation describes which C++ vtable entries are actually
1396 used. Record for later use during GC. */
1397 case R_PARISC_GNU_VTENTRY
:
1398 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
,
1399 &h
->elf
, rel
->r_addend
))
1407 /* Now carry out our orders. */
1408 if (need_entry
& NEED_GOT
)
1410 /* Allocate space for a GOT entry, as well as a dynamic
1411 relocation for this entry. */
1413 hplink
->root
.dynobj
= dynobj
= abfd
;
1415 if (hplink
->sgot
== NULL
)
1417 if (! elf32_hppa_create_dynamic_sections (dynobj
, info
))
1423 if (h
->elf
.got
.refcount
== -1)
1425 h
->elf
.got
.refcount
= 1;
1427 /* Make sure this symbol is output as a dynamic symbol. */
1428 if (h
->elf
.dynindx
== -1)
1430 if (! bfd_elf32_link_record_dynamic_symbol (info
,
1435 hplink
->sgot
->_raw_size
+= GOT_ENTRY_SIZE
;
1436 hplink
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
1439 h
->elf
.got
.refcount
+= 1;
1443 /* This is a global offset table entry for a local symbol. */
1444 if (local_got_refcounts
== NULL
)
1448 /* Allocate space for local got offsets and local
1449 plt offsets. Done this way to save polluting
1450 elf_obj_tdata with another target specific
1452 size
= symtab_hdr
->sh_info
* 2 * sizeof (bfd_signed_vma
);
1453 local_got_refcounts
= ((bfd_signed_vma
*)
1454 bfd_alloc (abfd
, size
));
1455 if (local_got_refcounts
== NULL
)
1457 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1458 memset (local_got_refcounts
, -1, size
);
1460 if (local_got_refcounts
[r_symndx
] == -1)
1462 local_got_refcounts
[r_symndx
] = 1;
1464 hplink
->sgot
->_raw_size
+= GOT_ENTRY_SIZE
;
1467 /* If we are generating a shared object, we need to
1468 output a reloc so that the dynamic linker can
1469 adjust this GOT entry (because the address
1470 the shared library is loaded at is not fixed). */
1471 hplink
->srelgot
->_raw_size
+=
1472 sizeof (Elf32_External_Rela
);
1476 local_got_refcounts
[r_symndx
] += 1;
1480 if (need_entry
& NEED_PLT
)
1482 /* If we are creating a shared library, and this is a reloc
1483 against a weak symbol or a global symbol in a dynamic
1484 object, then we will be creating an import stub and a
1485 .plt entry for the symbol. Similarly, on a normal link
1486 to symbols defined in a dynamic object we'll need the
1487 import stub and a .plt entry. We don't know yet whether
1488 the symbol is defined or not, so make an entry anyway and
1489 clean up later in adjust_dynamic_symbol. */
1490 if ((sec
->flags
& SEC_ALLOC
) != 0)
1494 if (h
->elf
.plt
.refcount
== -1)
1496 h
->elf
.plt
.refcount
= 1;
1497 h
->elf
.elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1500 h
->elf
.plt
.refcount
+= 1;
1502 /* If this .plt entry is for a plabel, mark it so
1503 that adjust_dynamic_symbol will keep the entry
1504 even if it appears to be local. */
1505 if (need_entry
& PLT_PLABEL
)
1508 else if (need_entry
& PLT_PLABEL
)
1512 if (local_got_refcounts
== NULL
)
1516 /* Allocate space for local got offsets and local
1518 size
= symtab_hdr
->sh_info
* 2 * sizeof (bfd_signed_vma
);
1519 local_got_refcounts
= ((bfd_signed_vma
*)
1520 bfd_alloc (abfd
, size
));
1521 if (local_got_refcounts
== NULL
)
1523 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1524 memset (local_got_refcounts
, -1, size
);
1526 indx
= r_symndx
+ symtab_hdr
->sh_info
;
1527 if (local_got_refcounts
[indx
] == -1)
1528 local_got_refcounts
[indx
] = 1;
1530 local_got_refcounts
[indx
] += 1;
1535 if (need_entry
& (NEED_DYNREL
| NEED_STUBREL
))
1537 /* Flag this symbol as having a non-got, non-plt reference
1538 so that we generate copy relocs if it turns out to be
1541 h
->elf
.elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
1543 /* If we are creating a shared library then we need to copy
1544 the reloc into the shared library. However, if we are
1545 linking with -Bsymbolic, we need only copy absolute
1546 relocs or relocs against symbols that are not defined in
1547 an object we are including in the link. PC- or DP- or
1548 DLT-relative relocs against any local sym or global sym
1549 with DEF_REGULAR set, can be discarded. At this point we
1550 have not seen all the input files, so it is possible that
1551 DEF_REGULAR is not set now but will be set later (it is
1552 never cleared). We account for that possibility below by
1553 storing information in the reloc_entries field of the
1556 A similar situation to the -Bsymbolic case occurs when
1557 creating shared libraries and symbol visibility changes
1558 render the symbol local.
1560 As it turns out, all the relocs we will be creating here
1561 are absolute, so we cannot remove them on -Bsymbolic
1562 links or visibility changes anyway. A STUB_REL reloc
1563 is absolute too, as in that case it is the reloc in the
1564 stub we will be creating, rather than copying the PCREL
1565 reloc in the branch. */
1566 if ((sec
->flags
& SEC_ALLOC
) != 0
1568 #if RELATIVE_DYNAMIC_RELOCS
1570 || is_absolute_reloc (r_type
)
1572 && ((h
->elf
.elf_link_hash_flags
1573 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
1581 if ((need_entry
& NEED_STUBREL
))
1584 /* Create a reloc section in dynobj and make room for
1591 hplink
->root
.dynobj
= dynobj
= abfd
;
1593 name
= bfd_elf_string_from_elf_section
1595 elf_elfheader (abfd
)->e_shstrndx
,
1596 elf_section_data (sec
)->rel_hdr
.sh_name
);
1599 (*_bfd_error_handler
)
1600 (_("Could not find relocation section for %s"),
1602 bfd_set_error (bfd_error_bad_value
);
1606 if ((need_entry
& NEED_STUBREL
))
1608 size_t len
= strlen (name
) + sizeof (STUB_SUFFIX
);
1609 char *newname
= bfd_malloc (len
);
1611 if (newname
== NULL
)
1613 strcpy (newname
, name
);
1614 strcpy (newname
+ len
- sizeof (STUB_SUFFIX
),
1619 srel
= bfd_get_section_by_name (dynobj
, name
);
1624 srel
= bfd_make_section (dynobj
, name
);
1625 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
1626 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1627 if ((sec
->flags
& SEC_ALLOC
) != 0)
1628 flags
|= SEC_ALLOC
| SEC_LOAD
;
1630 || !bfd_set_section_flags (dynobj
, srel
, flags
)
1631 || !bfd_set_section_alignment (dynobj
, srel
, 2))
1634 else if ((need_entry
& NEED_STUBREL
))
1637 if ((need_entry
& NEED_STUBREL
))
1643 #if ! LONG_BRANCH_PIC_IN_SHLIB
1644 /* If this is a function call, we only need one dynamic
1645 reloc for the stub as all calls to a particular
1646 function will go through the same stub. Actually, a
1647 long branch stub needs two relocations, but we count
1648 on some intelligence on the part of the dynamic
1650 if ((need_entry
& NEED_STUBREL
))
1652 doit
= h
->stub_reloc_sec
!= stubreloc
;
1653 h
->stub_reloc_sec
= stubreloc
;
1661 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
1663 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
1664 /* Keep track of relocations we have entered for
1665 this global symbol, so that we can discard them
1666 later if necessary. */
1669 #if RELATIVE_DYNAMIC_RELOCS
1670 || ! is_absolute_reloc (rtype
)
1672 || (need_entry
& NEED_STUBREL
)))
1674 struct elf32_hppa_dyn_reloc_entry
*p
;
1676 for (p
= h
->reloc_entries
; p
!= NULL
; p
= p
->next
)
1677 if (p
->section
== srel
)
1682 p
= ((struct elf32_hppa_dyn_reloc_entry
*)
1683 bfd_alloc (dynobj
, sizeof *p
));
1686 p
->next
= h
->reloc_entries
;
1687 h
->reloc_entries
= p
;
1692 /* NEED_STUBREL and NEED_DYNREL are never both
1693 set. Leave the count at zero for the
1694 NEED_STUBREL case as we only ever have one
1695 stub reloc per section per symbol, and this
1696 simplifies code in hppa_discard_copies. */
1697 if (! (need_entry
& NEED_STUBREL
))
1709 /* Return the section that should be marked against garbage collection
1710 for a given relocation. */
1713 elf32_hppa_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
1715 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1716 Elf_Internal_Rela
*rel
;
1717 struct elf_link_hash_entry
*h
;
1718 Elf_Internal_Sym
*sym
;
1722 switch ((unsigned int) ELF32_R_TYPE (rel
->r_info
))
1724 case R_PARISC_GNU_VTINHERIT
:
1725 case R_PARISC_GNU_VTENTRY
:
1729 switch (h
->root
.type
)
1731 case bfd_link_hash_defined
:
1732 case bfd_link_hash_defweak
:
1733 return h
->root
.u
.def
.section
;
1735 case bfd_link_hash_common
:
1736 return h
->root
.u
.c
.p
->section
;
1745 if (!(elf_bad_symtab (abfd
)
1746 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
1747 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
1748 && sym
->st_shndx
!= SHN_COMMON
))
1750 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
1757 /* Update the got and plt entry reference counts for the section being
1761 elf32_hppa_gc_sweep_hook (abfd
, info
, sec
, relocs
)
1763 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1765 const Elf_Internal_Rela
*relocs
;
1767 Elf_Internal_Shdr
*symtab_hdr
;
1768 struct elf_link_hash_entry
**sym_hashes
;
1769 bfd_signed_vma
*local_got_refcounts
;
1770 bfd_signed_vma
*local_plt_refcounts
;
1771 const Elf_Internal_Rela
*rel
, *relend
;
1772 unsigned long r_symndx
;
1773 struct elf_link_hash_entry
*h
;
1774 struct elf32_hppa_link_hash_table
*hplink
;
1779 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1780 sym_hashes
= elf_sym_hashes (abfd
);
1781 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1782 local_plt_refcounts
= local_got_refcounts
;
1783 if (local_plt_refcounts
!= NULL
)
1784 local_plt_refcounts
+= symtab_hdr
->sh_info
;
1785 hplink
= hppa_link_hash_table (info
);
1786 dynobj
= hplink
->root
.dynobj
;
1790 sgot
= hplink
->sgot
;
1791 srelgot
= hplink
->srelgot
;
1793 relend
= relocs
+ sec
->reloc_count
;
1794 for (rel
= relocs
; rel
< relend
; rel
++)
1795 switch ((unsigned int) ELF32_R_TYPE (rel
->r_info
))
1797 case R_PARISC_DLTIND14F
:
1798 case R_PARISC_DLTIND14R
:
1799 case R_PARISC_DLTIND21L
:
1800 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1801 if (r_symndx
>= symtab_hdr
->sh_info
)
1803 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1804 if (h
->got
.refcount
> 0)
1806 h
->got
.refcount
-= 1;
1807 if (h
->got
.refcount
== 0)
1809 sgot
->_raw_size
-= GOT_ENTRY_SIZE
;
1810 srelgot
->_raw_size
-= sizeof (Elf32_External_Rela
);
1814 else if (local_got_refcounts
!= NULL
)
1816 if (local_got_refcounts
[r_symndx
] > 0)
1818 local_got_refcounts
[r_symndx
] -= 1;
1819 if (local_got_refcounts
[r_symndx
] == 0)
1821 sgot
->_raw_size
-= GOT_ENTRY_SIZE
;
1823 srelgot
->_raw_size
-= sizeof (Elf32_External_Rela
);
1829 case R_PARISC_PCREL12F
:
1830 case R_PARISC_PCREL17C
:
1831 case R_PARISC_PCREL17F
:
1832 case R_PARISC_PCREL22F
:
1833 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1834 if (r_symndx
>= symtab_hdr
->sh_info
)
1836 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1837 if (h
->plt
.refcount
> 0)
1838 h
->plt
.refcount
-= 1;
1842 case R_PARISC_PLABEL14R
:
1843 case R_PARISC_PLABEL21L
:
1844 case R_PARISC_PLABEL32
:
1845 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1846 if (r_symndx
>= symtab_hdr
->sh_info
)
1848 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1849 if (h
->plt
.refcount
> 0)
1850 h
->plt
.refcount
-= 1;
1852 else if (local_plt_refcounts
!= NULL
)
1854 if (local_plt_refcounts
[r_symndx
] > 0)
1855 local_plt_refcounts
[r_symndx
] -= 1;
1866 /* Our own version of hide_symbol, so that we can keep plt entries for
1870 elf32_hppa_hide_symbol (info
, h
)
1871 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1872 struct elf_link_hash_entry
*h
;
1874 if ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0)
1876 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
)
1878 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1879 h
->plt
.offset
= (bfd_vma
) -1;
1883 /* Adjust a symbol defined by a dynamic object and referenced by a
1884 regular object. The current definition is in some section of the
1885 dynamic object, but we're not including those sections. We have to
1886 change the definition to something the rest of the link can
1890 elf32_hppa_adjust_dynamic_symbol (info
, h
)
1891 struct bfd_link_info
*info
;
1892 struct elf_link_hash_entry
*h
;
1895 struct elf32_hppa_link_hash_table
*hplink
;
1898 hplink
= hppa_link_hash_table (info
);
1899 dynobj
= hplink
->root
.dynobj
;
1901 /* If this is a function, put it in the procedure linkage table. We
1902 will fill in the contents of the procedure linkage table later,
1903 when we know the address of the .got section. */
1904 if (h
->type
== STT_FUNC
1905 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1908 && h
->plt
.refcount
> 0
1909 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
1910 && (h
->root
.u
.def
.section
->flags
& SEC_HAS_GOT_REF
) != 0)
1912 ((struct elf32_hppa_link_hash_entry
*) h
)->maybe_pic_call
= 1;
1915 if (h
->plt
.refcount
<= 0
1916 || ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
1917 && h
->root
.type
!= bfd_link_hash_defweak
1918 && ! ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
1919 && (!info
->shared
|| info
->symbolic
)))
1921 /* The .plt entry is not needed when:
1922 a) Garbage collection has removed all references to the
1924 b) We know for certain the symbol is defined in this
1925 object, and it's not a weak definition, nor is the symbol
1926 used by a plabel relocation. Either this object is the
1927 application or we are doing a shared symbolic link. */
1929 /* As a special sop to the hppa ABI, we keep a .plt entry
1930 for functions in sections containing PIC code. */
1931 if (((struct elf32_hppa_link_hash_entry
*) h
)->maybe_pic_call
)
1932 ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
= 1;
1935 h
->plt
.offset
= (bfd_vma
) -1;
1936 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1941 /* Make an entry in the .plt section. */
1943 h
->plt
.offset
= s
->_raw_size
;
1944 if (PLABEL_PLT_ENTRY_SIZE
!= PLT_ENTRY_SIZE
1945 && ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
1946 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1948 /* Add some extra space for the dynamic linker to use. */
1949 s
->_raw_size
+= PLABEL_PLT_ENTRY_SIZE
;
1952 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1954 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
)
1956 /* Make sure this symbol is output as a dynamic symbol. */
1957 if (h
->dynindx
== -1
1958 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1960 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1964 if (h
->dynindx
!= -1 || info
->shared
)
1966 /* We also need to make an entry in the .rela.plt section. */
1967 s
= hplink
->srelplt
;
1968 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
1970 hplink
->need_plt_stub
= 1;
1976 /* If this is a weak symbol, and there is a real definition, the
1977 processor independent code will have arranged for us to see the
1978 real definition first, and we can just use the same value. */
1979 if (h
->weakdef
!= NULL
)
1981 if (h
->weakdef
->root
.type
!= bfd_link_hash_defined
1982 && h
->weakdef
->root
.type
!= bfd_link_hash_defweak
)
1984 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1985 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1989 /* This is a reference to a symbol defined by a dynamic object which
1990 is not a function. */
1992 /* If we are creating a shared library, we must presume that the
1993 only references to the symbol are via the global offset table.
1994 For such cases we need not do anything here; the relocations will
1995 be handled correctly by relocate_section. */
1999 /* If there are no references to this symbol that do not use the
2000 GOT, we don't need to generate a copy reloc. */
2001 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
2004 /* We must allocate the symbol in our .dynbss section, which will
2005 become part of the .bss section of the executable. There will be
2006 an entry for this symbol in the .dynsym section. The dynamic
2007 object will contain position independent code, so all references
2008 from the dynamic object to this symbol will go through the global
2009 offset table. The dynamic linker will use the .dynsym entry to
2010 determine the address it must put in the global offset table, so
2011 both the dynamic object and the regular object will refer to the
2012 same memory location for the variable. */
2014 s
= hplink
->sdynbss
;
2016 /* We must generate a COPY reloc to tell the dynamic linker to
2017 copy the initial value out of the dynamic object and into the
2018 runtime process image. We need to remember the offset into the
2019 .rela.bss section we are going to use. */
2020 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2024 srel
= hplink
->srelbss
;
2025 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
2026 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
2030 /* We need to figure out the alignment required for this symbol. I
2031 have no idea how other ELF linkers handle this. */
2032 unsigned int power_of_two
;
2034 power_of_two
= bfd_log2 (h
->size
);
2035 if (power_of_two
> 3)
2038 /* Apply the required alignment. */
2039 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
2040 (bfd_size_type
) (1 << power_of_two
));
2041 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
2043 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
2047 /* Define the symbol as being at this point in the section. */
2048 h
->root
.u
.def
.section
= s
;
2049 h
->root
.u
.def
.value
= s
->_raw_size
;
2051 /* Increment the section size to make room for the symbol. */
2052 s
->_raw_size
+= h
->size
;
2057 /* Called via elf_link_hash_traverse to create .plt entries for an
2058 application that uses statically linked PIC functions. Similar to
2059 the first part of elf32_hppa_adjust_dynamic_symbol. */
2062 hppa_handle_PIC_calls (h
, inf
)
2063 struct elf_link_hash_entry
*h
;
2066 struct bfd_link_info
*info
;
2068 struct elf32_hppa_link_hash_table
*hplink
;
2071 if (! (h
->plt
.refcount
> 0
2072 && (h
->root
.type
== bfd_link_hash_defined
2073 || h
->root
.type
== bfd_link_hash_defweak
)
2074 && (h
->root
.u
.def
.section
->flags
& SEC_HAS_GOT_REF
) != 0))
2076 h
->plt
.offset
= (bfd_vma
) -1;
2077 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2081 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2082 ((struct elf32_hppa_link_hash_entry
*) h
)->maybe_pic_call
= 1;
2083 ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
= 1;
2085 info
= (struct bfd_link_info
*) inf
;
2086 hplink
= hppa_link_hash_table (info
);
2087 dynobj
= hplink
->root
.dynobj
;
2089 /* Make an entry in the .plt section. */
2091 h
->plt
.offset
= s
->_raw_size
;
2092 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2097 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
2098 || RELATIVE_DYNAMIC_RELOCS)
2099 /* This function is called via elf_link_hash_traverse to discard space
2100 we allocated for relocs that it turned out we didn't need. */
2103 hppa_discard_copies (h
, inf
)
2104 struct elf_link_hash_entry
*h
;
2107 struct elf32_hppa_dyn_reloc_entry
*s
;
2108 struct elf32_hppa_link_hash_entry
*eh
;
2109 struct bfd_link_info
*info
;
2111 eh
= (struct elf32_hppa_link_hash_entry
*) h
;
2112 info
= (struct bfd_link_info
*) inf
;
2114 #if ! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT
2115 /* Handle the stub reloc case. If we have a plt entry for the
2116 function, we won't be needing long branch stubs. s->count will
2117 only be zero for stub relocs, which provides a handy way of
2118 flagging these relocs, and means we need do nothing special for
2119 the forced local and symbolic link case. */
2120 if (eh
->stub_reloc_sec
!= NULL
2121 && eh
->elf
.plt
.offset
!= (bfd_vma
) -1)
2123 for (s
= eh
->reloc_entries
; s
!= NULL
; s
= s
->next
)
2125 s
->section
->_raw_size
-= sizeof (Elf32_External_Rela
);
2129 #if RELATIVE_DYNAMIC_RELOCS
2130 /* If a symbol has been forced local or we have found a regular
2131 definition for the symbolic link case, then we won't be needing
2133 if (eh
->elf
.dynindx
== -1
2134 || ((eh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
2135 && !is_absolute_reloc (r_type
)
2138 for (s
= eh
->reloc_entries
; s
!= NULL
; s
= s
->next
)
2139 s
->section
->_raw_size
-= s
->count
* sizeof (Elf32_External_Rela
);
2147 /* This function is called via elf_link_hash_traverse to force
2148 millicode symbols local so they do not end up as globals in the
2149 dynamic symbol table. We ought to be able to do this in
2150 adjust_dynamic_symbol, but our adjust_dynamic_symbol is not called
2151 for all dynamic symbols. Arguably, this is a bug in
2152 elf_adjust_dynamic_symbol. */
2155 clobber_millicode_symbols (h
, info
)
2156 struct elf_link_hash_entry
*h
;
2157 struct bfd_link_info
*info
;
2159 /* We only want to remove these from the dynamic symbol table.
2160 Therefore we do not leave ELF_LINK_FORCED_LOCAL set. */
2161 if (h
->type
== STT_PARISC_MILLI
)
2163 unsigned short oldflags
= h
->elf_link_hash_flags
;
2164 h
->elf_link_hash_flags
|= ELF_LINK_FORCED_LOCAL
;
2165 elf32_hppa_hide_symbol (info
, h
);
2166 h
->elf_link_hash_flags
&= ~ELF_LINK_FORCED_LOCAL
;
2167 h
->elf_link_hash_flags
|= oldflags
& ELF_LINK_FORCED_LOCAL
;
2172 /* Set the sizes of the dynamic sections. */
2175 elf32_hppa_size_dynamic_sections (output_bfd
, info
)
2177 struct bfd_link_info
*info
;
2179 struct elf32_hppa_link_hash_table
*hplink
;
2185 hplink
= hppa_link_hash_table (info
);
2186 dynobj
= hplink
->root
.dynobj
;
2190 if (hplink
->root
.dynamic_sections_created
)
2194 /* Set the contents of the .interp section to the interpreter. */
2197 s
= bfd_get_section_by_name (dynobj
, ".interp");
2200 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2201 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2204 /* Force millicode symbols local. */
2205 elf_link_hash_traverse (&hplink
->root
,
2206 clobber_millicode_symbols
,
2209 /* Set up .plt offsets for local plabels. */
2210 for (i
= info
->input_bfds
; i
; i
= i
->link_next
)
2212 bfd_signed_vma
*local_plt
;
2213 bfd_signed_vma
*end_local_plt
;
2214 bfd_size_type locsymcount
;
2215 Elf_Internal_Shdr
*symtab_hdr
;
2217 local_plt
= elf_local_got_refcounts (i
);
2221 symtab_hdr
= &elf_tdata (i
)->symtab_hdr
;
2222 locsymcount
= symtab_hdr
->sh_info
;
2223 local_plt
+= locsymcount
;
2224 end_local_plt
= local_plt
+ locsymcount
;
2226 for (; local_plt
< end_local_plt
; ++local_plt
)
2231 *local_plt
= s
->_raw_size
;
2232 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2234 hplink
->srelplt
->_raw_size
+= sizeof (Elf32_External_Rela
);
2237 *local_plt
= (bfd_vma
) -1;
2243 /* Run through the function symbols, looking for any that are
2244 PIC, and allocate space for the necessary .plt entries so
2245 that %r19 will be set up. */
2247 elf_link_hash_traverse (&hplink
->root
,
2248 hppa_handle_PIC_calls
,
2251 /* We may have created entries in the .rela.got section.
2252 However, if we are not creating the dynamic sections, we will
2253 not actually use these entries. Reset the size of .rela.got,
2254 which will cause it to get stripped from the output file
2256 hplink
->srelgot
->_raw_size
= 0;
2259 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
2260 || RELATIVE_DYNAMIC_RELOCS)
2261 /* If this is a -Bsymbolic shared link, then we need to discard all
2262 relocs against symbols defined in a regular object. We also need
2263 to lose relocs we've allocated for long branch stubs if we know
2264 we won't be generating a stub. */
2266 elf_link_hash_traverse (&hplink
->root
,
2267 hppa_discard_copies
,
2271 /* The check_relocs and adjust_dynamic_symbol entry points have
2272 determined the sizes of the various dynamic sections. Allocate
2276 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2280 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2283 /* It's OK to base decisions on the section name, because none
2284 of the dynobj section names depend upon the input files. */
2285 name
= bfd_get_section_name (dynobj
, s
);
2287 if (strncmp (name
, ".rela", 5) == 0)
2289 if (s
->_raw_size
!= 0)
2292 const char *outname
;
2294 /* Remember whether there are any reloc sections other
2296 if (strcmp (name
+5, ".plt") != 0)
2299 /* If this relocation section applies to a read only
2300 section, then we probably need a DT_TEXTREL entry. */
2301 outname
= bfd_get_section_name (output_bfd
,
2303 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
2305 && (target
->flags
& SEC_READONLY
) != 0
2306 && (target
->flags
& SEC_ALLOC
) != 0)
2309 /* We use the reloc_count field as a counter if we need
2310 to copy relocs into the output file. */
2314 else if (strcmp (name
, ".plt") == 0)
2316 if (hplink
->need_plt_stub
)
2318 /* Make space for the plt stub at the end of the .plt
2319 section. We want this stub right at the end, up
2320 against the .got section. */
2321 int gotalign
= bfd_section_alignment (dynobj
, hplink
->sgot
);
2322 int pltalign
= bfd_section_alignment (dynobj
, s
);
2325 if (gotalign
> pltalign
)
2326 bfd_set_section_alignment (dynobj
, s
, gotalign
);
2327 mask
= ((bfd_size_type
) 1 << gotalign
) - 1;
2328 s
->_raw_size
= (s
->_raw_size
+ sizeof (plt_stub
) + mask
) & ~mask
;
2331 else if (strcmp (name
, ".got") == 0)
2335 /* It's not one of our sections, so don't allocate space. */
2339 if (s
->_raw_size
== 0)
2341 /* If we don't need this section, strip it from the
2342 output file. This is mostly to handle .rela.bss and
2343 .rela.plt. We must create both sections in
2344 create_dynamic_sections, because they must be created
2345 before the linker maps input sections to output
2346 sections. The linker does that before
2347 adjust_dynamic_symbol is called, and it is that
2348 function which decides whether anything needs to go
2349 into these sections. */
2350 _bfd_strip_section_from_output (info
, s
);
2354 /* Allocate memory for the section contents. Zero it, because
2355 we may not fill in all the reloc sections. */
2356 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
2357 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
2361 if (hplink
->root
.dynamic_sections_created
)
2363 /* Like IA-64 and HPPA64, always create a DT_PLTGOT. It
2364 actually has nothing to do with the PLT, it is how we
2365 communicate the LTP value of a load module to the dynamic
2367 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
2370 /* Add some entries to the .dynamic section. We fill in the
2371 values later, in elf32_hppa_finish_dynamic_sections, but we
2372 must add the entries now so that we get the correct size for
2373 the .dynamic section. The DT_DEBUG entry is filled in by the
2374 dynamic linker and used by the debugger. */
2377 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
2381 if (hplink
->srelplt
->_raw_size
!= 0)
2383 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
2384 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
2385 || ! bfd_elf32_add_dynamic_entry (info
, DT_JMPREL
, 0))
2391 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELA
, 0)
2392 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELASZ
, 0)
2393 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELAENT
,
2394 sizeof (Elf32_External_Rela
)))
2400 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
2402 info
->flags
|= DF_TEXTREL
;
2409 /* External entry points for sizing and building linker stubs. */
2411 /* Determine and set the size of the stub section for a final link.
2413 The basic idea here is to examine all the relocations looking for
2414 PC-relative calls to a target that is unreachable with a "bl"
2418 elf32_hppa_size_stubs (output_bfd
, stub_bfd
, info
, multi_subspace
, group_size
,
2419 add_stub_section
, layout_sections_again
)
2422 struct bfd_link_info
*info
;
2423 boolean multi_subspace
;
2424 bfd_signed_vma group_size
;
2425 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
2426 void (*layout_sections_again
) PARAMS ((void));
2430 asection
**input_list
, **list
;
2431 Elf_Internal_Sym
*local_syms
, **all_local_syms
;
2432 unsigned int bfd_indx
, bfd_count
;
2433 int top_id
, top_index
;
2434 struct elf32_hppa_link_hash_table
*hplink
;
2435 bfd_size_type stub_group_size
;
2436 boolean stubs_always_before_branch
;
2437 boolean stub_changed
= 0;
2440 hplink
= hppa_link_hash_table (info
);
2442 /* Stash our params away. */
2443 hplink
->stub_bfd
= stub_bfd
;
2444 hplink
->multi_subspace
= multi_subspace
;
2445 hplink
->add_stub_section
= add_stub_section
;
2446 hplink
->layout_sections_again
= layout_sections_again
;
2447 stubs_always_before_branch
= group_size
< 0;
2449 stub_group_size
= -group_size
;
2451 stub_group_size
= group_size
;
2452 if (stub_group_size
== 1)
2454 /* Default values. */
2455 stub_group_size
= 8000000;
2456 if (hplink
->has_17bit_branch
|| hplink
->multi_subspace
)
2457 stub_group_size
= 250000;
2458 if (hplink
->has_12bit_branch
)
2459 stub_group_size
= 7812;
2462 /* Count the number of input BFDs and find the top input section id. */
2463 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
2465 input_bfd
= input_bfd
->link_next
)
2468 for (section
= input_bfd
->sections
;
2470 section
= section
->next
)
2472 if (top_id
< section
->id
)
2473 top_id
= section
->id
;
2478 = (struct map_stub
*) bfd_zmalloc (sizeof (struct map_stub
) * (top_id
+ 1));
2479 if (hplink
->stub_group
== NULL
)
2482 /* Make a list of input sections for each output section included in
2485 We can't use output_bfd->section_count here to find the top output
2486 section index as some sections may have been removed, and
2487 _bfd_strip_section_from_output doesn't renumber the indices. */
2488 for (section
= output_bfd
->sections
, top_index
= 0;
2490 section
= section
->next
)
2492 if (top_index
< section
->index
)
2493 top_index
= section
->index
;
2497 = (asection
**) bfd_malloc (sizeof (asection
*) * (top_index
+ 1));
2498 if (input_list
== NULL
)
2501 /* For sections we aren't interested in, mark their entries with a
2502 value we can check later. */
2503 list
= input_list
+ top_index
;
2505 *list
= bfd_abs_section_ptr
;
2506 while (list
-- != input_list
);
2508 for (section
= output_bfd
->sections
;
2510 section
= section
->next
)
2512 if ((section
->flags
& SEC_CODE
) != 0)
2513 input_list
[section
->index
] = NULL
;
2516 /* Now actually build the lists. */
2517 for (input_bfd
= info
->input_bfds
;
2519 input_bfd
= input_bfd
->link_next
)
2521 for (section
= input_bfd
->sections
;
2523 section
= section
->next
)
2525 if (section
->output_section
!= NULL
2526 && section
->output_section
->owner
== output_bfd
2527 && section
->output_section
->index
<= top_index
)
2529 list
= input_list
+ section
->output_section
->index
;
2530 if (*list
!= bfd_abs_section_ptr
)
2532 /* Steal the link_sec pointer for our list. */
2533 #define PREV_SEC(sec) (hplink->stub_group[(sec)->id].link_sec)
2534 /* This happens to make the list in reverse order,
2535 which is what we want. */
2536 PREV_SEC (section
) = *list
;
2543 /* See whether we can group stub sections together. Grouping stub
2544 sections may result in fewer stubs. More importantly, we need to
2545 put all .init* and .fini* stubs at the beginning of the .init or
2546 .fini output sections respectively, because glibc splits the
2547 _init and _fini functions into multiple parts. Putting a stub in
2548 the middle of a function is not a good idea. */
2549 list
= input_list
+ top_index
;
2552 asection
*tail
= *list
;
2553 if (tail
== bfd_abs_section_ptr
)
2555 while (tail
!= NULL
)
2559 bfd_size_type total
;
2562 if (tail
->_cooked_size
)
2563 total
= tail
->_cooked_size
;
2565 total
= tail
->_raw_size
;
2566 while ((prev
= PREV_SEC (curr
)) != NULL
2567 && ((total
+= curr
->output_offset
- prev
->output_offset
)
2571 /* OK, the size from the start of CURR to the end is less
2572 than 250000 bytes and thus can be handled by one stub
2573 section. (or the tail section is itself larger than
2574 250000 bytes, in which case we may be toast.)
2575 We should really be keeping track of the total size of
2576 stubs added here, as stubs contribute to the final output
2577 section size. That's a little tricky, and this way will
2578 only break if stubs added total more than 12144 bytes, or
2579 1518 long branch stubs. It seems unlikely for more than
2580 1518 different functions to be called, especially from
2581 code only 250000 bytes long. */
2584 prev
= PREV_SEC (tail
);
2585 /* Set up this stub group. */
2586 hplink
->stub_group
[tail
->id
].link_sec
= curr
;
2588 while (tail
!= curr
&& (tail
= prev
) != NULL
);
2590 /* But wait, there's more! Input sections up to 250000
2591 bytes before the stub section can be handled by it too. */
2592 if (!stubs_always_before_branch
)
2596 && ((total
+= tail
->output_offset
- prev
->output_offset
)
2600 prev
= PREV_SEC (tail
);
2601 hplink
->stub_group
[tail
->id
].link_sec
= curr
;
2607 while (list
-- != input_list
);
2611 /* We want to read in symbol extension records only once. To do this
2612 we need to read in the local symbols in parallel and save them for
2613 later use; so hold pointers to the local symbols in an array. */
2615 = (Elf_Internal_Sym
**) bfd_zmalloc (sizeof (Elf_Internal_Sym
*)
2617 if (all_local_syms
== NULL
)
2620 /* Walk over all the input BFDs, swapping in local symbols.
2621 If we are creating a shared library, create hash entries for the
2623 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
2625 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
2627 Elf_Internal_Shdr
*symtab_hdr
;
2628 Elf_Internal_Sym
*isym
;
2629 Elf32_External_Sym
*ext_syms
, *esym
, *end_sy
;
2631 /* We'll need the symbol table in a second. */
2632 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2633 if (symtab_hdr
->sh_info
== 0)
2636 /* We need an array of the local symbols attached to the input bfd.
2637 Unfortunately, we're going to have to read & swap them in. */
2638 local_syms
= (Elf_Internal_Sym
*)
2639 bfd_malloc (symtab_hdr
->sh_info
* sizeof (Elf_Internal_Sym
));
2640 if (local_syms
== NULL
)
2642 goto error_ret_free_local
;
2644 all_local_syms
[bfd_indx
] = local_syms
;
2645 ext_syms
= (Elf32_External_Sym
*)
2646 bfd_malloc (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
));
2647 if (ext_syms
== NULL
)
2649 goto error_ret_free_local
;
2652 if (bfd_seek (input_bfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
2653 || (bfd_read (ext_syms
, 1,
2654 (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
)),
2656 != (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
))))
2659 goto error_ret_free_local
;
2662 /* Swap the local symbols in. */
2665 for (end_sy
= esym
+ symtab_hdr
->sh_info
; esym
< end_sy
; esym
++, isym
++)
2666 bfd_elf32_swap_symbol_in (input_bfd
, esym
, isym
);
2668 /* Now we can free the external symbols. */
2671 #if ! LONG_BRANCH_PIC_IN_SHLIB
2672 /* If this is a shared link, find all the stub reloc sections. */
2674 for (section
= input_bfd
->sections
;
2676 section
= section
->next
)
2679 asection
*reloc_sec
;
2681 name
= bfd_malloc (strlen (section
->name
)
2682 + sizeof STUB_SUFFIX
2686 sprintf (name
, ".rela%s%s", section
->name
, STUB_SUFFIX
);
2687 reloc_sec
= bfd_get_section_by_name (hplink
->root
.dynobj
, name
);
2688 hplink
->stub_group
[section
->id
].reloc_sec
= reloc_sec
;
2693 if (info
->shared
&& hplink
->multi_subspace
)
2695 struct elf_link_hash_entry
**sym_hashes
;
2696 struct elf_link_hash_entry
**end_hashes
;
2697 unsigned int symcount
;
2699 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
2700 - symtab_hdr
->sh_info
);
2701 sym_hashes
= elf_sym_hashes (input_bfd
);
2702 end_hashes
= sym_hashes
+ symcount
;
2704 /* Look through the global syms for functions; We need to
2705 build export stubs for all globally visible functions. */
2706 for (; sym_hashes
< end_hashes
; sym_hashes
++)
2708 struct elf32_hppa_link_hash_entry
*hash
;
2710 hash
= (struct elf32_hppa_link_hash_entry
*) *sym_hashes
;
2712 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
2713 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
2714 hash
= ((struct elf32_hppa_link_hash_entry
*)
2715 hash
->elf
.root
.u
.i
.link
);
2717 /* At this point in the link, undefined syms have been
2718 resolved, so we need to check that the symbol was
2719 defined in this BFD. */
2720 if ((hash
->elf
.root
.type
== bfd_link_hash_defined
2721 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
2722 && hash
->elf
.type
== STT_FUNC
2723 && hash
->elf
.root
.u
.def
.section
->output_section
!= NULL
2724 && (hash
->elf
.root
.u
.def
.section
->output_section
->owner
2726 && hash
->elf
.root
.u
.def
.section
->owner
== input_bfd
2727 && (hash
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
2728 && !(hash
->elf
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
2729 && ELF_ST_VISIBILITY (hash
->elf
.other
) == STV_DEFAULT
)
2732 const char *stub_name
;
2733 struct elf32_hppa_stub_hash_entry
*stub_entry
;
2735 sec
= hash
->elf
.root
.u
.def
.section
;
2736 stub_name
= hash
->elf
.root
.root
.string
;
2737 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
,
2740 if (stub_entry
== NULL
)
2742 stub_entry
= hppa_add_stub (stub_name
, sec
, hplink
);
2744 goto error_ret_free_local
;
2746 stub_entry
->target_value
= hash
->elf
.root
.u
.def
.value
;
2747 stub_entry
->target_section
= hash
->elf
.root
.u
.def
.section
;
2748 stub_entry
->stub_type
= hppa_stub_export
;
2749 stub_entry
->h
= hash
;
2754 (*_bfd_error_handler
) (_("%s: duplicate export stub %s"),
2755 bfd_get_filename (input_bfd
),
2767 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
2769 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
2771 Elf_Internal_Shdr
*symtab_hdr
;
2773 /* We'll need the symbol table in a second. */
2774 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2775 if (symtab_hdr
->sh_info
== 0)
2778 local_syms
= all_local_syms
[bfd_indx
];
2780 /* Walk over each section attached to the input bfd. */
2781 for (section
= input_bfd
->sections
;
2783 section
= section
->next
)
2785 Elf_Internal_Shdr
*input_rel_hdr
;
2786 Elf32_External_Rela
*external_relocs
, *erelaend
, *erela
;
2787 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
2789 /* If there aren't any relocs, then there's nothing more
2791 if ((section
->flags
& SEC_RELOC
) == 0
2792 || section
->reloc_count
== 0)
2795 /* If this section is a link-once section that will be
2796 discarded, then don't create any stubs. */
2797 if (section
->output_section
== NULL
2798 || section
->output_section
->owner
!= output_bfd
)
2801 /* Allocate space for the external relocations. */
2803 = ((Elf32_External_Rela
*)
2804 bfd_malloc (section
->reloc_count
2805 * sizeof (Elf32_External_Rela
)));
2806 if (external_relocs
== NULL
)
2808 goto error_ret_free_local
;
2811 /* Likewise for the internal relocations. */
2812 internal_relocs
= ((Elf_Internal_Rela
*)
2813 bfd_malloc (section
->reloc_count
2814 * sizeof (Elf_Internal_Rela
)));
2815 if (internal_relocs
== NULL
)
2817 free (external_relocs
);
2818 goto error_ret_free_local
;
2821 /* Read in the external relocs. */
2822 input_rel_hdr
= &elf_section_data (section
)->rel_hdr
;
2823 if (bfd_seek (input_bfd
, input_rel_hdr
->sh_offset
, SEEK_SET
) != 0
2824 || bfd_read (external_relocs
, 1,
2825 input_rel_hdr
->sh_size
,
2826 input_bfd
) != input_rel_hdr
->sh_size
)
2828 free (external_relocs
);
2829 error_ret_free_internal
:
2830 free (internal_relocs
);
2831 goto error_ret_free_local
;
2834 /* Swap in the relocs. */
2835 erela
= external_relocs
;
2836 erelaend
= erela
+ section
->reloc_count
;
2837 irela
= internal_relocs
;
2838 for (; erela
< erelaend
; erela
++, irela
++)
2839 bfd_elf32_swap_reloca_in (input_bfd
, erela
, irela
);
2841 /* We're done with the external relocs, free them. */
2842 free (external_relocs
);
2844 /* Now examine each relocation. */
2845 irela
= internal_relocs
;
2846 irelaend
= irela
+ section
->reloc_count
;
2847 for (; irela
< irelaend
; irela
++)
2849 unsigned int r_type
, r_indx
;
2850 enum elf32_hppa_stub_type stub_type
;
2851 struct elf32_hppa_stub_hash_entry
*stub_entry
;
2854 bfd_vma destination
;
2855 struct elf32_hppa_link_hash_entry
*hash
;
2857 const asection
*id_sec
;
2859 r_type
= ELF32_R_TYPE (irela
->r_info
);
2860 r_indx
= ELF32_R_SYM (irela
->r_info
);
2862 if (r_type
>= (unsigned int) R_PARISC_UNIMPLEMENTED
)
2864 bfd_set_error (bfd_error_bad_value
);
2865 goto error_ret_free_internal
;
2868 /* Only look for stubs on call instructions. */
2869 if (r_type
!= (unsigned int) R_PARISC_PCREL12F
2870 && r_type
!= (unsigned int) R_PARISC_PCREL17F
2871 && r_type
!= (unsigned int) R_PARISC_PCREL22F
)
2874 /* Now determine the call target, its name, value,
2880 if (r_indx
< symtab_hdr
->sh_info
)
2882 /* It's a local symbol. */
2883 Elf_Internal_Sym
*sym
;
2884 Elf_Internal_Shdr
*hdr
;
2886 sym
= local_syms
+ r_indx
;
2887 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
2888 sym_sec
= hdr
->bfd_section
;
2889 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
2890 sym_value
= sym
->st_value
;
2891 destination
= (sym_value
+ irela
->r_addend
2892 + sym_sec
->output_offset
2893 + sym_sec
->output_section
->vma
);
2897 /* It's an external symbol. */
2900 e_indx
= r_indx
- symtab_hdr
->sh_info
;
2901 hash
= ((struct elf32_hppa_link_hash_entry
*)
2902 elf_sym_hashes (input_bfd
)[e_indx
]);
2904 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
2905 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
2906 hash
= ((struct elf32_hppa_link_hash_entry
*)
2907 hash
->elf
.root
.u
.i
.link
);
2909 if (hash
->elf
.root
.type
== bfd_link_hash_defined
2910 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
2912 sym_sec
= hash
->elf
.root
.u
.def
.section
;
2913 sym_value
= hash
->elf
.root
.u
.def
.value
;
2914 if (sym_sec
->output_section
!= NULL
)
2915 destination
= (sym_value
+ irela
->r_addend
2916 + sym_sec
->output_offset
2917 + sym_sec
->output_section
->vma
);
2919 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
)
2924 else if (hash
->elf
.root
.type
== bfd_link_hash_undefined
)
2927 && !info
->no_undefined
2928 && (ELF_ST_VISIBILITY (hash
->elf
.other
)
2934 bfd_set_error (bfd_error_bad_value
);
2935 goto error_ret_free_internal
;
2939 /* Determine what (if any) linker stub is needed. */
2940 stub_type
= hppa_type_of_stub (section
, irela
, hash
,
2942 if (stub_type
== hppa_stub_none
)
2945 /* Support for grouping stub sections. */
2946 id_sec
= hplink
->stub_group
[section
->id
].link_sec
;
2948 /* Get the name of this stub. */
2949 stub_name
= hppa_stub_name (id_sec
, sym_sec
, hash
, irela
);
2951 goto error_ret_free_internal
;
2953 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
,
2956 if (stub_entry
!= NULL
)
2958 /* The proper stub has already been created. */
2963 stub_entry
= hppa_add_stub (stub_name
, section
, hplink
);
2964 if (stub_entry
== NULL
)
2967 goto error_ret_free_local
;
2970 stub_entry
->target_value
= sym_value
;
2971 stub_entry
->target_section
= sym_sec
;
2972 stub_entry
->stub_type
= stub_type
;
2975 if (stub_type
== hppa_stub_import
)
2976 stub_entry
->stub_type
= hppa_stub_import_shared
;
2977 else if (stub_type
== hppa_stub_long_branch
2978 && (LONG_BRANCH_PIC_IN_SHLIB
|| hash
== NULL
))
2979 stub_entry
->stub_type
= hppa_stub_long_branch_shared
;
2981 stub_entry
->h
= hash
;
2985 /* We're done with the internal relocs, free them. */
2986 free (internal_relocs
);
2993 /* OK, we've added some stubs. Find out the new size of the
2995 for (stub_sec
= hplink
->stub_bfd
->sections
;
2997 stub_sec
= stub_sec
->next
)
2999 stub_sec
->_raw_size
= 0;
3000 stub_sec
->_cooked_size
= 0;
3002 #if ! LONG_BRANCH_PIC_IN_SHLIB
3006 for (i
= top_id
; i
>= 0; --i
)
3008 /* This will probably hit the same section many times.. */
3009 stub_sec
= hplink
->stub_group
[i
].reloc_sec
;
3010 if (stub_sec
!= NULL
)
3012 stub_sec
->_raw_size
= 0;
3013 stub_sec
->_cooked_size
= 0;
3019 bfd_hash_traverse (&hplink
->stub_hash_table
,
3023 /* Ask the linker to do its stuff. */
3024 (*hplink
->layout_sections_again
) ();
3030 error_ret_free_local
:
3031 while (bfd_count
-- > 0)
3032 if (all_local_syms
[bfd_count
])
3033 free (all_local_syms
[bfd_count
]);
3034 free (all_local_syms
);
3039 /* For a final link, this function is called after we have sized the
3040 stubs to provide a value for __gp. */
3043 elf32_hppa_set_gp (abfd
, info
)
3045 struct bfd_link_info
*info
;
3047 struct elf32_hppa_link_hash_table
*hplink
;
3048 struct elf_link_hash_entry
*h
;
3052 hplink
= hppa_link_hash_table (info
);
3053 h
= elf_link_hash_lookup (&hplink
->root
, "$global$",
3054 false, false, false);
3057 && (h
->root
.type
== bfd_link_hash_defined
3058 || h
->root
.type
== bfd_link_hash_defweak
))
3060 gp_val
= h
->root
.u
.def
.value
;
3061 sec
= h
->root
.u
.def
.section
;
3065 /* Choose to point our LTP at, in this order, one of .plt, .got,
3066 or .data, if these sections exist. In the case of choosing
3067 .plt try to make the LTP ideal for addressing anywhere in the
3068 .plt or .got with a 14 bit signed offset. Typically, the end
3069 of the .plt is the start of the .got, so choose .plt + 0x2000
3070 if either the .plt or .got is larger than 0x2000. If both
3071 the .plt and .got are smaller than 0x2000, choose the end of
3072 the .plt section. */
3077 gp_val
= sec
->_raw_size
;
3079 || (hplink
->sgot
&& hplink
->sgot
->_raw_size
> 0x2000))
3090 /* We know we don't have a .plt. If .got is large,
3092 if (sec
->_raw_size
> 0x2000)
3097 /* No .plt or .got. Who cares what the LTP is? */
3098 sec
= bfd_get_section_by_name (abfd
, ".data");
3104 h
->root
.type
= bfd_link_hash_defined
;
3105 h
->root
.u
.def
.value
= gp_val
;
3107 h
->root
.u
.def
.section
= sec
;
3109 h
->root
.u
.def
.section
= bfd_abs_section_ptr
;
3113 if (sec
!= NULL
&& sec
->output_section
!= NULL
)
3114 gp_val
+= sec
->output_section
->vma
+ sec
->output_offset
;
3116 elf_gp (abfd
) = gp_val
;
3120 /* Build all the stubs associated with the current output file. The
3121 stubs are kept in a hash table attached to the main linker hash
3122 table. We also set up the .plt entries for statically linked PIC
3123 functions here. This function is called via hppaelf_finish in the
3127 elf32_hppa_build_stubs (info
)
3128 struct bfd_link_info
*info
;
3131 struct bfd_hash_table
*table
;
3132 struct elf32_hppa_link_hash_table
*hplink
;
3134 hplink
= hppa_link_hash_table (info
);
3136 for (stub_sec
= hplink
->stub_bfd
->sections
;
3138 stub_sec
= stub_sec
->next
)
3142 /* Allocate memory to hold the linker stubs. */
3143 size
= stub_sec
->_raw_size
;
3144 stub_sec
->contents
= (unsigned char *) bfd_zalloc (hplink
->stub_bfd
,
3146 if (stub_sec
->contents
== NULL
&& size
!= 0)
3148 stub_sec
->_raw_size
= 0;
3151 /* Build the stubs as directed by the stub hash table. */
3152 table
= &hplink
->stub_hash_table
;
3153 bfd_hash_traverse (table
, hppa_build_one_stub
, info
);
3158 /* Perform a final link. */
3161 elf32_hppa_final_link (abfd
, info
)
3163 struct bfd_link_info
*info
;
3167 /* Invoke the regular ELF garbage collecting linker to do all the
3169 if (!_bfd_elf32_gc_common_final_link (abfd
, info
))
3172 /* If we're producing a final executable, sort the contents of the
3173 unwind section. Magic section names, but this is much safer than
3174 having elf32_hppa_relocate_section remember where SEGREL32 relocs
3175 occurred. Consider what happens if someone inept creates a
3176 linker script that puts unwind information in .text. */
3177 s
= bfd_get_section_by_name (abfd
, ".PARISC.unwind");
3183 size
= s
->_raw_size
;
3184 contents
= bfd_malloc (size
);
3185 if (contents
== NULL
)
3188 if (! bfd_get_section_contents (abfd
, s
, contents
, (file_ptr
) 0, size
))
3191 qsort (contents
, size
/ 16, 16, hppa_unwind_entry_compare
);
3193 if (! bfd_set_section_contents (abfd
, s
, contents
, (file_ptr
) 0, size
))
3199 /* Record the lowest address for the data and text segments. */
3202 hppa_record_segment_addr (abfd
, section
, data
)
3203 bfd
*abfd ATTRIBUTE_UNUSED
;
3207 struct elf32_hppa_link_hash_table
*hplink
;
3209 hplink
= (struct elf32_hppa_link_hash_table
*) data
;
3211 if ((section
->flags
& (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3213 bfd_vma value
= section
->vma
- section
->filepos
;
3215 if ((section
->flags
& SEC_READONLY
) != 0)
3217 if (value
< hplink
->text_segment_base
)
3218 hplink
->text_segment_base
= value
;
3222 if (value
< hplink
->data_segment_base
)
3223 hplink
->data_segment_base
= value
;
3228 /* Perform a relocation as part of a final link. */
3230 static bfd_reloc_status_type
3231 final_link_relocate (input_section
, contents
, rel
, value
, hplink
, sym_sec
, h
)
3232 asection
*input_section
;
3234 const Elf_Internal_Rela
*rel
;
3236 struct elf32_hppa_link_hash_table
*hplink
;
3238 struct elf32_hppa_link_hash_entry
*h
;
3241 unsigned int r_type
= ELF32_R_TYPE (rel
->r_info
);
3242 reloc_howto_type
*howto
= elf_hppa_howto_table
+ r_type
;
3243 int r_format
= howto
->bitsize
;
3244 enum hppa_reloc_field_selector_type_alt r_field
;
3245 bfd
*input_bfd
= input_section
->owner
;
3246 bfd_vma offset
= rel
->r_offset
;
3247 bfd_vma max_branch_offset
= 0;
3248 bfd_byte
*hit_data
= contents
+ offset
;
3249 bfd_signed_vma addend
= rel
->r_addend
;
3251 struct elf32_hppa_stub_hash_entry
*stub_entry
= NULL
;
3254 if (r_type
== R_PARISC_NONE
)
3255 return bfd_reloc_ok
;
3257 insn
= bfd_get_32 (input_bfd
, hit_data
);
3259 /* Find out where we are and where we're going. */
3260 location
= (offset
+
3261 input_section
->output_offset
+
3262 input_section
->output_section
->vma
);
3266 case R_PARISC_PCREL12F
:
3267 case R_PARISC_PCREL17F
:
3268 case R_PARISC_PCREL22F
:
3269 /* If this is a call to a function defined in another dynamic
3270 library, or if it is a call to a PIC function in the same
3271 object, or if this is a shared link and it is a call to a
3272 weak symbol which may or may not be in the same object, then
3273 find the import stub in the stub hash. */
3275 || sym_sec
->output_section
== NULL
3277 && ((h
->maybe_pic_call
3278 && !(input_section
->flags
& SEC_HAS_GOT_REF
))
3279 || (h
->elf
.root
.type
== bfd_link_hash_defweak
3280 && h
->elf
.dynindx
!= -1
3281 && h
->elf
.plt
.offset
!= (bfd_vma
) -1))))
3283 stub_entry
= hppa_get_stub_entry (input_section
, sym_sec
,
3285 if (stub_entry
!= NULL
)
3287 value
= (stub_entry
->stub_offset
3288 + stub_entry
->stub_sec
->output_offset
3289 + stub_entry
->stub_sec
->output_section
->vma
);
3292 else if (sym_sec
== NULL
&& h
!= NULL
3293 && h
->elf
.root
.type
== bfd_link_hash_undefweak
)
3295 /* It's OK if undefined weak. Calls to undefined weak
3296 symbols behave as if the "called" function
3297 immediately returns. We can thus call to a weak
3298 function without first checking whether the function
3304 return bfd_reloc_notsupported
;
3308 case R_PARISC_PCREL21L
:
3309 case R_PARISC_PCREL17C
:
3310 case R_PARISC_PCREL17R
:
3311 case R_PARISC_PCREL14R
:
3312 case R_PARISC_PCREL14F
:
3313 /* Make it a pc relative offset. */
3318 case R_PARISC_DPREL21L
:
3319 case R_PARISC_DPREL14R
:
3320 case R_PARISC_DPREL14F
:
3321 /* For all the DP relative relocations, we need to examine the symbol's
3322 section. If it's a code section, then "data pointer relative" makes
3323 no sense. In that case we don't adjust the "value", and for 21 bit
3324 addil instructions, we change the source addend register from %dp to
3325 %r0. This situation commonly arises when a variable's "constness"
3326 is declared differently from the way the variable is defined. For
3327 instance: "extern int foo" with foo defined as "const int foo". */
3328 if (sym_sec
== NULL
)
3330 if ((sym_sec
->flags
& SEC_CODE
) != 0)
3332 if ((insn
& ((0x3f << 26) | (0x1f << 21)))
3333 == (((int) OP_ADDIL
<< 26) | (27 << 21)))
3335 insn
&= ~ (0x1f << 21);
3336 #if 1 /* debug them. */
3337 (*_bfd_error_handler
)
3338 (_("%s(%s+0x%lx): fixing %s"),
3339 bfd_get_filename (input_bfd
),
3340 input_section
->name
,
3341 (long) rel
->r_offset
,
3345 /* Now try to make things easy for the dynamic linker. */
3351 case R_PARISC_DLTIND21L
:
3352 case R_PARISC_DLTIND14R
:
3353 case R_PARISC_DLTIND14F
:
3354 value
-= elf_gp (input_section
->output_section
->owner
);
3357 case R_PARISC_SEGREL32
:
3358 if ((sym_sec
->flags
& SEC_CODE
) != 0)
3359 value
-= hplink
->text_segment_base
;
3361 value
-= hplink
->data_segment_base
;
3370 case R_PARISC_DIR32
:
3371 case R_PARISC_DIR14F
:
3372 case R_PARISC_DIR17F
:
3373 case R_PARISC_PCREL17C
:
3374 case R_PARISC_PCREL14F
:
3375 case R_PARISC_DPREL14F
:
3376 case R_PARISC_PLABEL32
:
3377 case R_PARISC_DLTIND14F
:
3378 case R_PARISC_SEGBASE
:
3379 case R_PARISC_SEGREL32
:
3383 case R_PARISC_DIR21L
:
3384 case R_PARISC_PCREL21L
:
3385 case R_PARISC_DPREL21L
:
3386 case R_PARISC_PLABEL21L
:
3387 case R_PARISC_DLTIND21L
:
3391 case R_PARISC_DIR17R
:
3392 case R_PARISC_PCREL17R
:
3393 case R_PARISC_DIR14R
:
3394 case R_PARISC_PCREL14R
:
3395 case R_PARISC_DPREL14R
:
3396 case R_PARISC_PLABEL14R
:
3397 case R_PARISC_DLTIND14R
:
3401 case R_PARISC_PCREL12F
:
3402 case R_PARISC_PCREL17F
:
3403 case R_PARISC_PCREL22F
:
3406 if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
3408 max_branch_offset
= (1 << (17-1)) << 2;
3410 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
3412 max_branch_offset
= (1 << (12-1)) << 2;
3416 max_branch_offset
= (1 << (22-1)) << 2;
3419 /* sym_sec is NULL on undefined weak syms or when shared on
3420 undefined syms. We've already checked for a stub for the
3421 shared undefined case. */
3422 if (sym_sec
== NULL
)
3425 /* If the branch is out of reach, then redirect the
3426 call to the local stub for this function. */
3427 if (value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3429 stub_entry
= hppa_get_stub_entry (input_section
, sym_sec
,
3431 if (stub_entry
== NULL
)
3432 return bfd_reloc_notsupported
;
3434 /* Munge up the value and addend so that we call the stub
3435 rather than the procedure directly. */
3436 value
= (stub_entry
->stub_offset
3437 + stub_entry
->stub_sec
->output_offset
3438 + stub_entry
->stub_sec
->output_section
->vma
3444 /* Something we don't know how to handle. */
3446 return bfd_reloc_notsupported
;
3449 /* Make sure we can reach the stub. */
3450 if (max_branch_offset
!= 0
3451 && value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3453 (*_bfd_error_handler
)
3454 (_("%s(%s+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
3455 bfd_get_filename (input_bfd
),
3456 input_section
->name
,
3457 (long) rel
->r_offset
,
3458 stub_entry
->root
.string
);
3459 return bfd_reloc_notsupported
;
3462 val
= hppa_field_adjust (value
, addend
, r_field
);
3466 case R_PARISC_PCREL12F
:
3467 case R_PARISC_PCREL17C
:
3468 case R_PARISC_PCREL17F
:
3469 case R_PARISC_PCREL17R
:
3470 case R_PARISC_PCREL22F
:
3471 case R_PARISC_DIR17F
:
3472 case R_PARISC_DIR17R
:
3473 /* This is a branch. Divide the offset by four.
3474 Note that we need to decide whether it's a branch or
3475 otherwise by inspecting the reloc. Inspecting insn won't
3476 work as insn might be from a .word directive. */
3484 insn
= hppa_rebuild_insn (insn
, val
, r_format
);
3486 /* Update the instruction word. */
3487 bfd_put_32 (input_bfd
, (bfd_vma
) insn
, hit_data
);
3488 return bfd_reloc_ok
;
3491 /* Relocate an HPPA ELF section. */
3494 elf32_hppa_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
3495 contents
, relocs
, local_syms
, local_sections
)
3497 struct bfd_link_info
*info
;
3499 asection
*input_section
;
3501 Elf_Internal_Rela
*relocs
;
3502 Elf_Internal_Sym
*local_syms
;
3503 asection
**local_sections
;
3506 bfd_vma
*local_got_offsets
;
3507 struct elf32_hppa_link_hash_table
*hplink
;
3508 Elf_Internal_Shdr
*symtab_hdr
;
3509 Elf_Internal_Rela
*rel
;
3510 Elf_Internal_Rela
*relend
;
3513 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3515 hplink
= hppa_link_hash_table (info
);
3516 dynobj
= hplink
->root
.dynobj
;
3517 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3521 relend
= relocs
+ input_section
->reloc_count
;
3522 for (; rel
< relend
; rel
++)
3524 unsigned int r_type
;
3525 reloc_howto_type
*howto
;
3526 unsigned int r_symndx
;
3527 struct elf32_hppa_link_hash_entry
*h
;
3528 Elf_Internal_Sym
*sym
;
3531 bfd_reloc_status_type r
;
3532 const char *sym_name
;
3535 r_type
= ELF32_R_TYPE (rel
->r_info
);
3536 if (r_type
>= (unsigned int) R_PARISC_UNIMPLEMENTED
)
3538 bfd_set_error (bfd_error_bad_value
);
3541 if (r_type
== (unsigned int) R_PARISC_GNU_VTENTRY
3542 || r_type
== (unsigned int) R_PARISC_GNU_VTINHERIT
)
3545 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3547 if (info
->relocateable
)
3549 /* This is a relocateable link. We don't have to change
3550 anything, unless the reloc is against a section symbol,
3551 in which case we have to adjust according to where the
3552 section symbol winds up in the output section. */
3553 if (r_symndx
< symtab_hdr
->sh_info
)
3555 sym
= local_syms
+ r_symndx
;
3556 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
3558 sym_sec
= local_sections
[r_symndx
];
3559 rel
->r_addend
+= sym_sec
->output_offset
;
3565 /* This is a final link. */
3569 if (r_symndx
< symtab_hdr
->sh_info
)
3571 /* This is a local symbol, h defaults to NULL. */
3572 sym
= local_syms
+ r_symndx
;
3573 sym_sec
= local_sections
[r_symndx
];
3574 relocation
= ((ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
3575 ? 0 : sym
->st_value
)
3576 + sym_sec
->output_offset
3577 + sym_sec
->output_section
->vma
);
3583 /* It's a global; Find its entry in the link hash. */
3584 indx
= r_symndx
- symtab_hdr
->sh_info
;
3585 h
= ((struct elf32_hppa_link_hash_entry
*)
3586 elf_sym_hashes (input_bfd
)[indx
]);
3587 while (h
->elf
.root
.type
== bfd_link_hash_indirect
3588 || h
->elf
.root
.type
== bfd_link_hash_warning
)
3589 h
= (struct elf32_hppa_link_hash_entry
*) h
->elf
.root
.u
.i
.link
;
3592 if (h
->elf
.root
.type
== bfd_link_hash_defined
3593 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
3595 sym_sec
= h
->elf
.root
.u
.def
.section
;
3596 /* If sym_sec->output_section is NULL, then it's a
3597 symbol defined in a shared library. */
3598 if (sym_sec
->output_section
!= NULL
)
3599 relocation
= (h
->elf
.root
.u
.def
.value
3600 + sym_sec
->output_offset
3601 + sym_sec
->output_section
->vma
);
3603 else if (h
->elf
.root
.type
== bfd_link_hash_undefweak
)
3605 else if (info
->shared
&& !info
->no_undefined
3606 && ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
3607 && h
->elf
.type
!= STT_PARISC_MILLI
)
3610 if (!((*info
->callbacks
->undefined_symbol
)
3611 (info
, h
->elf
.root
.root
.string
, input_bfd
,
3612 input_section
, rel
->r_offset
, false)))
3617 if (!((*info
->callbacks
->undefined_symbol
)
3618 (info
, h
->elf
.root
.root
.string
, input_bfd
,
3619 input_section
, rel
->r_offset
, true)))
3624 /* Do any required modifications to the relocation value, and
3625 determine what types of dynamic info we need to output, if
3630 case R_PARISC_DLTIND14F
:
3631 case R_PARISC_DLTIND14R
:
3632 case R_PARISC_DLTIND21L
:
3633 /* Relocation is to the entry for this symbol in the global
3639 off
= h
->elf
.got
.offset
;
3640 if (off
== (bfd_vma
) -1)
3643 if (! hplink
->root
.dynamic_sections_created
3645 && (info
->symbolic
|| h
->elf
.dynindx
== -1)
3646 && (h
->elf
.elf_link_hash_flags
3647 & ELF_LINK_HASH_DEF_REGULAR
) != 0))
3649 /* This is actually a static link, or it is a
3650 -Bsymbolic link and the symbol is defined
3651 locally, or the symbol was forced to be local
3652 because of a version file. We must initialize
3653 this entry in the global offset table. Since the
3654 offset must always be a multiple of 4, we use the
3655 least significant bit to record whether we have
3656 initialized it already.
3658 When doing a dynamic link, we create a .rela.got
3659 relocation entry to initialize the value. This
3660 is done in the finish_dynamic_symbol routine. */
3665 bfd_put_32 (output_bfd
, relocation
,
3666 hplink
->sgot
->contents
+ off
);
3667 h
->elf
.got
.offset
|= 1;
3675 /* Local symbol case. */
3678 if (local_got_offsets
== NULL
3679 || (off
= local_got_offsets
[r_symndx
]) == (bfd_vma
) -1)
3682 /* The offset must always be a multiple of 4. We use
3683 the least significant bit to record whether we have
3684 already generated the necessary reloc. */
3689 bfd_put_32 (output_bfd
, relocation
,
3690 hplink
->sgot
->contents
+ off
);
3694 /* Output a dynamic relocation for this GOT
3695 entry. In this case it is relative to the
3696 base of the object because the symbol index
3698 Elf_Internal_Rela outrel
;
3699 asection
*srelgot
= hplink
->srelgot
;
3701 outrel
.r_offset
= (off
3702 + hplink
->sgot
->output_offset
3703 + hplink
->sgot
->output_section
->vma
);
3704 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_DIR32
);
3705 outrel
.r_addend
= relocation
;
3706 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3707 ((Elf32_External_Rela
*)
3709 + srelgot
->reloc_count
));
3710 ++srelgot
->reloc_count
;
3713 local_got_offsets
[r_symndx
] |= 1;
3719 /* Add the base of the GOT to the relocation value. */
3720 relocation
+= (hplink
->sgot
->output_offset
3721 + hplink
->sgot
->output_section
->vma
);
3724 case R_PARISC_SEGREL32
:
3725 /* If this is the first SEGREL relocation, then initialize
3726 the segment base values. */
3727 if (hplink
->text_segment_base
== (bfd_vma
) -1)
3728 bfd_map_over_sections (output_bfd
,
3729 hppa_record_segment_addr
,
3733 case R_PARISC_PLABEL14R
:
3734 case R_PARISC_PLABEL21L
:
3735 case R_PARISC_PLABEL32
:
3736 if (hplink
->root
.dynamic_sections_created
)
3740 /* If we have a global symbol with a PLT slot, then
3741 redirect this relocation to it. */
3744 off
= h
->elf
.plt
.offset
;
3746 && (h
->elf
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
3748 /* In a non-shared link, adjust_dynamic_symbols
3749 isn't called for symbols forced local. We
3750 need to write out the plt entry here. */
3755 bfd_put_32 (output_bfd
,
3757 hplink
->splt
->contents
+ off
);
3758 bfd_put_32 (output_bfd
,
3759 elf_gp (hplink
->splt
->output_section
->owner
),
3760 hplink
->splt
->contents
+ off
+ 4);
3761 h
->elf
.plt
.offset
|= 1;
3769 indx
= r_symndx
+ symtab_hdr
->sh_info
;
3770 off
= local_got_offsets
[indx
];
3772 /* As for the local .got entry case, we use the last
3773 bit to record whether we've already initialised
3774 this local .plt entry. */
3779 bfd_put_32 (output_bfd
,
3781 hplink
->splt
->contents
+ off
);
3782 bfd_put_32 (output_bfd
,
3783 elf_gp (hplink
->splt
->output_section
->owner
),
3784 hplink
->splt
->contents
+ off
+ 4);
3788 /* Output a dynamic IPLT relocation for this
3790 Elf_Internal_Rela outrel
;
3791 asection
*srelplt
= hplink
->srelplt
;
3793 outrel
.r_offset
= (off
3794 + hplink
->splt
->output_offset
3795 + hplink
->splt
->output_section
->vma
);
3796 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_IPLT
);
3797 outrel
.r_addend
= relocation
;
3798 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3799 ((Elf32_External_Rela
*)
3801 + srelplt
->reloc_count
));
3802 ++srelplt
->reloc_count
;
3805 local_got_offsets
[indx
] |= 1;
3809 if (off
>= (bfd_vma
) -2 || (off
& 1) != 0)
3812 /* PLABELs contain function pointers. Relocation is to
3813 the entry for the function in the .plt. The magic +2
3814 offset signals to $$dyncall that the function pointer
3815 is in the .plt and thus has a gp pointer too.
3816 Exception: Undefined PLABELs should have a value of
3819 || (h
->elf
.root
.type
!= bfd_link_hash_undefweak
3820 && h
->elf
.root
.type
!= bfd_link_hash_undefined
))
3823 + hplink
->splt
->output_offset
3824 + hplink
->splt
->output_section
->vma
3829 /* Fall through and possibly emit a dynamic relocation. */
3831 case R_PARISC_DIR17F
:
3832 case R_PARISC_DIR17R
:
3833 case R_PARISC_DIR14F
:
3834 case R_PARISC_DIR14R
:
3835 case R_PARISC_DIR21L
:
3836 case R_PARISC_DPREL14F
:
3837 case R_PARISC_DPREL14R
:
3838 case R_PARISC_DPREL21L
:
3839 case R_PARISC_DIR32
:
3840 /* The reloc types handled here and this conditional
3841 expression must match the code in check_relocs and
3842 hppa_discard_copies. ie. We need exactly the same
3843 condition as in check_relocs, with some extra conditions
3844 (dynindx test in this case) to cater for relocs removed
3845 by hppa_discard_copies. */
3846 if ((input_section
->flags
& SEC_ALLOC
) != 0
3848 #if RELATIVE_DYNAMIC_RELOCS
3849 && (is_absolute_reloc (r_type
)
3850 || ((!info
->symbolic
3852 && ((h
->elf
.elf_link_hash_flags
3853 & ELF_LINK_HASH_DEF_REGULAR
) == 0
3854 || h
->elf
.root
.type
== bfd_link_hash_defweak
)))
3855 && (h
== NULL
|| h
->elf
.dynindx
!= -1)))
3859 Elf_Internal_Rela outrel
;
3862 /* When generating a shared object, these relocations
3863 are copied into the output file to be resolved at run
3870 name
= (bfd_elf_string_from_elf_section
3872 elf_elfheader (input_bfd
)->e_shstrndx
,
3873 elf_section_data (input_section
)->rel_hdr
.sh_name
));
3876 sreloc
= bfd_get_section_by_name (dynobj
, name
);
3881 outrel
.r_offset
= rel
->r_offset
;
3882 outrel
.r_addend
= rel
->r_addend
;
3884 if (elf_section_data (input_section
)->stab_info
!= NULL
)
3888 off
= (_bfd_stab_section_offset
3889 (output_bfd
, &hplink
->root
.stab_info
,
3891 &elf_section_data (input_section
)->stab_info
,
3893 if (off
== (bfd_vma
) -1)
3895 outrel
.r_offset
= off
;
3898 outrel
.r_offset
+= (input_section
->output_offset
3899 + input_section
->output_section
->vma
);
3903 memset (&outrel
, 0, sizeof (outrel
));
3906 && h
->elf
.dynindx
!= -1
3909 || (h
->elf
.elf_link_hash_flags
3910 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
3912 outrel
.r_info
= ELF32_R_INFO (h
->elf
.dynindx
, r_type
);
3914 else /* It's a local symbol, or one marked to become local. */
3918 /* Add the absolute offset of the symbol. */
3919 outrel
.r_addend
+= relocation
;
3921 /* Global plabels need to be processed by the
3922 dynamic linker so that functions have at most one
3923 fptr. For this reason, we need to differentiate
3924 between global and local plabels, which we do by
3925 providing the function symbol for a global plabel
3926 reloc, and no symbol for local plabels. */
3929 && sym_sec
->output_section
!= NULL
3930 && ! bfd_is_abs_section (sym_sec
))
3932 indx
= elf_section_data (sym_sec
->output_section
)->dynindx
;
3933 /* We are turning this relocation into one
3934 against a section symbol, so subtract out the
3935 output section's address but not the offset
3936 of the input section in the output section. */
3937 outrel
.r_addend
-= sym_sec
->output_section
->vma
;
3940 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
3943 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3944 ((Elf32_External_Rela
*)
3946 + sreloc
->reloc_count
));
3947 ++sreloc
->reloc_count
;
3955 r
= final_link_relocate (input_section
, contents
, rel
, relocation
,
3956 hplink
, sym_sec
, h
);
3958 if (r
== bfd_reloc_ok
)
3962 sym_name
= h
->elf
.root
.root
.string
;
3965 sym_name
= bfd_elf_string_from_elf_section (input_bfd
,
3966 symtab_hdr
->sh_link
,
3968 if (sym_name
== NULL
)
3970 if (*sym_name
== '\0')
3971 sym_name
= bfd_section_name (input_bfd
, sym_sec
);
3974 howto
= elf_hppa_howto_table
+ r_type
;
3976 if (r
== bfd_reloc_undefined
|| r
== bfd_reloc_notsupported
)
3978 (*_bfd_error_handler
)
3979 (_("%s(%s+0x%lx): cannot handle %s for %s"),
3980 bfd_get_filename (input_bfd
),
3981 input_section
->name
,
3982 (long) rel
->r_offset
,
3988 if (!((*info
->callbacks
->reloc_overflow
)
3989 (info
, sym_name
, howto
->name
, (bfd_vma
) 0,
3990 input_bfd
, input_section
, rel
->r_offset
)))
3998 /* Comparison function for qsort to sort unwind section during a
4002 hppa_unwind_entry_compare (a
, b
)
4006 const bfd_byte
*ap
, *bp
;
4007 unsigned long av
, bv
;
4009 ap
= (const bfd_byte
*) a
;
4010 av
= (unsigned long) ap
[0] << 24;
4011 av
|= (unsigned long) ap
[1] << 16;
4012 av
|= (unsigned long) ap
[2] << 8;
4013 av
|= (unsigned long) ap
[3];
4015 bp
= (const bfd_byte
*) b
;
4016 bv
= (unsigned long) bp
[0] << 24;
4017 bv
|= (unsigned long) bp
[1] << 16;
4018 bv
|= (unsigned long) bp
[2] << 8;
4019 bv
|= (unsigned long) bp
[3];
4021 return av
< bv
? -1 : av
> bv
? 1 : 0;
4024 /* Finish up dynamic symbol handling. We set the contents of various
4025 dynamic sections here. */
4028 elf32_hppa_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
4030 struct bfd_link_info
*info
;
4031 struct elf_link_hash_entry
*h
;
4032 Elf_Internal_Sym
*sym
;
4034 struct elf32_hppa_link_hash_table
*hplink
;
4037 hplink
= hppa_link_hash_table (info
);
4038 dynobj
= hplink
->root
.dynobj
;
4040 if (h
->plt
.offset
!= (bfd_vma
) -1)
4044 if (h
->plt
.offset
& 1)
4047 /* This symbol has an entry in the procedure linkage table. Set
4050 The format of a plt entry is
4055 if (h
->root
.type
== bfd_link_hash_defined
4056 || h
->root
.type
== bfd_link_hash_defweak
)
4058 value
= h
->root
.u
.def
.value
;
4059 if (h
->root
.u
.def
.section
->output_section
!= NULL
)
4060 value
+= (h
->root
.u
.def
.section
->output_offset
4061 + h
->root
.u
.def
.section
->output_section
->vma
);
4064 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
)
4066 Elf_Internal_Rela rel
;
4068 /* Create a dynamic IPLT relocation for this entry. */
4069 rel
.r_offset
= (h
->plt
.offset
4070 + hplink
->splt
->output_offset
4071 + hplink
->splt
->output_section
->vma
);
4072 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->plt_abs
4073 && h
->dynindx
!= -1)
4075 /* To support lazy linking, the function pointer is
4076 initialised to point to a special stub stored at the
4077 end of the .plt. This is not done for plt entries
4078 with a base-relative dynamic relocation. */
4079 value
= (hplink
->splt
->output_offset
4080 + hplink
->splt
->output_section
->vma
4081 + hplink
->splt
->_raw_size
4084 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_IPLT
);
4089 /* This symbol has been marked to become local, and is
4090 used by a plabel so must be kept in the .plt. */
4091 rel
.r_info
= ELF32_R_INFO (0, R_PARISC_IPLT
);
4092 rel
.r_addend
= value
;
4095 bfd_elf32_swap_reloca_out (hplink
->splt
->output_section
->owner
,
4097 ((Elf32_External_Rela
*)
4098 hplink
->srelplt
->contents
4099 + hplink
->srelplt
->reloc_count
));
4100 hplink
->srelplt
->reloc_count
++;
4103 bfd_put_32 (hplink
->splt
->owner
,
4105 hplink
->splt
->contents
+ h
->plt
.offset
);
4106 bfd_put_32 (hplink
->splt
->owner
,
4107 elf_gp (hplink
->splt
->output_section
->owner
),
4108 hplink
->splt
->contents
+ h
->plt
.offset
+ 4);
4109 if (PLABEL_PLT_ENTRY_SIZE
!= PLT_ENTRY_SIZE
4110 && ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
4111 && h
->dynindx
!= -1)
4113 memset (hplink
->splt
->contents
+ h
->plt
.offset
+ 8,
4114 0, PLABEL_PLT_ENTRY_SIZE
- PLT_ENTRY_SIZE
);
4117 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4119 /* Mark the symbol as undefined, rather than as defined in
4120 the .plt section. Leave the value alone. */
4121 sym
->st_shndx
= SHN_UNDEF
;
4125 if (h
->got
.offset
!= (bfd_vma
) -1)
4127 Elf_Internal_Rela rel
;
4129 /* This symbol has an entry in the global offset table. Set it
4132 rel
.r_offset
= ((h
->got
.offset
&~ (bfd_vma
) 1)
4133 + hplink
->sgot
->output_offset
4134 + hplink
->sgot
->output_section
->vma
);
4136 /* If this is a static link, or it is a -Bsymbolic link and the
4137 symbol is defined locally or was forced to be local because
4138 of a version file, we just want to emit a RELATIVE reloc.
4139 The entry in the global offset table will already have been
4140 initialized in the relocate_section function. */
4141 if (! hplink
->root
.dynamic_sections_created
4143 && (info
->symbolic
|| h
->dynindx
== -1)
4144 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
4146 rel
.r_info
= ELF32_R_INFO (0, R_PARISC_DIR32
);
4147 rel
.r_addend
= (h
->root
.u
.def
.value
4148 + h
->root
.u
.def
.section
->output_offset
4149 + h
->root
.u
.def
.section
->output_section
->vma
);
4153 if ((h
->got
.offset
& 1) != 0)
4155 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
4156 hplink
->sgot
->contents
+ h
->got
.offset
);
4157 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_DIR32
);
4161 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
4162 ((Elf32_External_Rela
*)
4163 hplink
->srelgot
->contents
4164 + hplink
->srelgot
->reloc_count
));
4165 ++hplink
->srelgot
->reloc_count
;
4168 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
4171 Elf_Internal_Rela rel
;
4173 /* This symbol needs a copy reloc. Set it up. */
4175 if (! (h
->dynindx
!= -1
4176 && (h
->root
.type
== bfd_link_hash_defined
4177 || h
->root
.type
== bfd_link_hash_defweak
)))
4180 s
= hplink
->srelbss
;
4182 rel
.r_offset
= (h
->root
.u
.def
.value
4183 + h
->root
.u
.def
.section
->output_offset
4184 + h
->root
.u
.def
.section
->output_section
->vma
);
4186 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_COPY
);
4187 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
4188 ((Elf32_External_Rela
*) s
->contents
4193 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
4194 if (h
->root
.root
.string
[0] == '_'
4195 && (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4196 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0))
4198 sym
->st_shndx
= SHN_ABS
;
4204 /* Finish up the dynamic sections. */
4207 elf32_hppa_finish_dynamic_sections (output_bfd
, info
)
4209 struct bfd_link_info
*info
;
4212 struct elf32_hppa_link_hash_table
*hplink
;
4215 hplink
= hppa_link_hash_table (info
);
4216 dynobj
= hplink
->root
.dynobj
;
4218 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4220 if (hplink
->root
.dynamic_sections_created
)
4222 Elf32_External_Dyn
*dyncon
, *dynconend
;
4227 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4228 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
4229 for (; dyncon
< dynconend
; dyncon
++)
4231 Elf_Internal_Dyn dyn
;
4234 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4242 /* Use PLTGOT to set the GOT register. */
4243 dyn
.d_un
.d_ptr
= elf_gp (output_bfd
);
4244 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4248 s
= hplink
->srelplt
;
4249 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4250 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4254 s
= hplink
->srelplt
;
4255 if (s
->_cooked_size
!= 0)
4256 dyn
.d_un
.d_val
= s
->_cooked_size
;
4258 dyn
.d_un
.d_val
= s
->_raw_size
;
4259 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4265 if (hplink
->sgot
->_raw_size
!= 0)
4267 /* Fill in the first entry in the global offset table.
4268 We use it to point to our dynamic section, if we have one. */
4269 bfd_put_32 (output_bfd
,
4271 ? sdyn
->output_section
->vma
+ sdyn
->output_offset
4273 hplink
->sgot
->contents
);
4275 /* The second entry is reserved for use by the dynamic linker. */
4276 memset (hplink
->sgot
->contents
+ GOT_ENTRY_SIZE
, 0, GOT_ENTRY_SIZE
);
4278 /* Set .got entry size. */
4279 elf_section_data (hplink
->sgot
->output_section
)
4280 ->this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
4283 if (hplink
->splt
->_raw_size
!= 0)
4285 /* Set plt entry size. */
4286 elf_section_data (hplink
->splt
->output_section
)
4287 ->this_hdr
.sh_entsize
= PLT_ENTRY_SIZE
;
4289 if (hplink
->need_plt_stub
)
4291 /* Set up the .plt stub. */
4292 memcpy (hplink
->splt
->contents
4293 + hplink
->splt
->_raw_size
- sizeof (plt_stub
),
4294 plt_stub
, sizeof (plt_stub
));
4296 if ((hplink
->splt
->output_offset
4297 + hplink
->splt
->output_section
->vma
4298 + hplink
->splt
->_raw_size
)
4299 != (hplink
->sgot
->output_offset
4300 + hplink
->sgot
->output_section
->vma
))
4302 (*_bfd_error_handler
)
4303 (_(".got section not immediately after .plt section"));
4312 /* Tweak the OSABI field of the elf header. */
4315 elf32_hppa_post_process_headers (abfd
, link_info
)
4317 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
;
4319 Elf_Internal_Ehdr
* i_ehdrp
;
4321 i_ehdrp
= elf_elfheader (abfd
);
4323 if (strcmp (bfd_get_target (abfd
), "elf32-hppa-linux") == 0)
4325 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_LINUX
;
4329 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_HPUX
;
4333 /* Called when writing out an object file to decide the type of a
4336 elf32_hppa_elf_get_symbol_type (elf_sym
, type
)
4337 Elf_Internal_Sym
*elf_sym
;
4340 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_PARISC_MILLI
)
4341 return STT_PARISC_MILLI
;
4346 /* Misc BFD support code. */
4347 #define bfd_elf32_bfd_is_local_label_name elf_hppa_is_local_label_name
4348 #define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
4349 #define elf_info_to_howto elf_hppa_info_to_howto
4350 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
4352 /* Stuff for the BFD linker. */
4353 #define bfd_elf32_bfd_final_link elf32_hppa_final_link
4354 #define bfd_elf32_bfd_link_hash_table_create elf32_hppa_link_hash_table_create
4355 #define elf_backend_add_symbol_hook elf32_hppa_add_symbol_hook
4356 #define elf_backend_adjust_dynamic_symbol elf32_hppa_adjust_dynamic_symbol
4357 #define elf_backend_check_relocs elf32_hppa_check_relocs
4358 #define elf_backend_create_dynamic_sections elf32_hppa_create_dynamic_sections
4359 #define elf_backend_fake_sections elf_hppa_fake_sections
4360 #define elf_backend_relocate_section elf32_hppa_relocate_section
4361 #define elf_backend_hide_symbol elf32_hppa_hide_symbol
4362 #define elf_backend_finish_dynamic_symbol elf32_hppa_finish_dynamic_symbol
4363 #define elf_backend_finish_dynamic_sections elf32_hppa_finish_dynamic_sections
4364 #define elf_backend_size_dynamic_sections elf32_hppa_size_dynamic_sections
4365 #define elf_backend_gc_mark_hook elf32_hppa_gc_mark_hook
4366 #define elf_backend_gc_sweep_hook elf32_hppa_gc_sweep_hook
4367 #define elf_backend_object_p elf32_hppa_object_p
4368 #define elf_backend_final_write_processing elf_hppa_final_write_processing
4369 #define elf_backend_post_process_headers elf32_hppa_post_process_headers
4370 #define elf_backend_get_symbol_type elf32_hppa_elf_get_symbol_type
4372 #define elf_backend_can_gc_sections 1
4373 #define elf_backend_plt_alignment 2
4374 #define elf_backend_want_got_plt 0
4375 #define elf_backend_plt_readonly 0
4376 #define elf_backend_want_plt_sym 0
4377 #define elf_backend_got_header_size 8
4379 #define TARGET_BIG_SYM bfd_elf32_hppa_vec
4380 #define TARGET_BIG_NAME "elf32-hppa"
4381 #define ELF_ARCH bfd_arch_hppa
4382 #define ELF_MACHINE_CODE EM_PARISC
4383 #define ELF_MAXPAGESIZE 0x1000
4385 #include "elf32-target.h"
4387 #undef TARGET_BIG_SYM
4388 #define TARGET_BIG_SYM bfd_elf32_hppa_linux_vec
4389 #undef TARGET_BIG_NAME
4390 #define TARGET_BIG_NAME "elf32-hppa-linux"
4392 #define INCLUDED_TARGET_FILE 1
4393 #include "elf32-target.h"