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
;
837 /* Massage our args to the form they really have. */
838 stub_entry
= (struct elf32_hppa_stub_hash_entry
*) gen_entry
;
839 info
= (struct bfd_link_info
*) in_arg
;
841 hplink
= hppa_link_hash_table (info
);
842 stub_sec
= stub_entry
->stub_sec
;
844 /* Make a note of the offset within the stubs for this entry. */
845 stub_entry
->stub_offset
= stub_sec
->_raw_size
;
846 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
848 stub_bfd
= stub_sec
->owner
;
850 switch (stub_entry
->stub_type
)
852 case hppa_stub_long_branch
:
853 /* Create the long branch. A long branch is formed with "ldil"
854 loading the upper bits of the target address into a register,
855 then branching with "be" which adds in the lower bits.
856 The "be" has its delay slot nullified. */
857 sym_value
= (stub_entry
->target_value
858 + stub_entry
->target_section
->output_offset
859 + stub_entry
->target_section
->output_section
->vma
);
861 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_lrsel
);
862 insn
= hppa_rebuild_insn ((int) LDIL_R1
, val
, 21);
863 bfd_put_32 (stub_bfd
, insn
, loc
);
865 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_rrsel
) >> 2;
866 insn
= hppa_rebuild_insn ((int) BE_SR4_R1
, val
, 17);
867 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
869 #if ! LONG_BRANCH_PIC_IN_SHLIB
872 /* Output a dynamic relocation for this stub. We only
873 output one PCREL21L reloc per stub, trusting that the
874 dynamic linker will also fix the implied PCREL17R for the
875 second instruction. PCREL21L dynamic relocs had better
876 never be emitted for some other purpose... */
878 Elf_Internal_Rela outrel
;
880 if (stub_entry
->h
== NULL
)
882 (*_bfd_error_handler
)
883 (_("%s(%s+0x%lx): cannot relocate %s, recompile with -ffunction-sections"),
884 bfd_get_filename (stub_entry
->target_section
->owner
),
886 (long) stub_entry
->stub_offset
,
887 stub_entry
->root
.string
);
888 bfd_set_error (bfd_error_bad_value
);
892 srel
= stub_entry
->reloc_sec
;
895 (*_bfd_error_handler
)
896 (_("Could not find relocation section for %s"),
898 bfd_set_error (bfd_error_bad_value
);
902 outrel
.r_offset
= (stub_entry
->stub_offset
903 + stub_sec
->output_offset
904 + stub_sec
->output_section
->vma
);
905 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_PCREL21L
);
906 outrel
.r_addend
= sym_value
;
907 bfd_elf32_swap_reloca_out (stub_sec
->output_section
->owner
,
909 ((Elf32_External_Rela
*)
910 srel
->contents
+ srel
->reloc_count
));
917 case hppa_stub_long_branch_shared
:
918 /* Branches are relative. This is where we are going to. */
919 sym_value
= (stub_entry
->target_value
920 + stub_entry
->target_section
->output_offset
921 + stub_entry
->target_section
->output_section
->vma
);
923 /* And this is where we are coming from, more or less. */
924 sym_value
-= (stub_entry
->stub_offset
925 + stub_sec
->output_offset
926 + stub_sec
->output_section
->vma
);
928 bfd_put_32 (stub_bfd
, (bfd_vma
) BL_R1
, loc
);
929 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_lrsel
);
930 insn
= hppa_rebuild_insn ((int) ADDIL_R1
, val
, 21);
931 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
933 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_rrsel
) >> 2;
934 insn
= hppa_rebuild_insn ((int) BE_SR4_R1
, val
, 17);
935 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
939 case hppa_stub_import
:
940 case hppa_stub_import_shared
:
941 BFD_ASSERT (stub_entry
->h
->elf
.plt
.offset
< (bfd_vma
) -2);
942 sym_value
= (stub_entry
->h
->elf
.plt
.offset
943 + hplink
->splt
->output_offset
944 + hplink
->splt
->output_section
->vma
945 - elf_gp (hplink
->splt
->output_section
->owner
));
949 if (stub_entry
->stub_type
== hppa_stub_import_shared
)
952 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_lrsel
),
953 insn
= hppa_rebuild_insn ((int) insn
, val
, 21);
954 bfd_put_32 (stub_bfd
, insn
, loc
);
956 /* It is critical to use lrsel/rrsel here because we are using
957 two different offsets (+0 and +4) from sym_value. If we use
958 lsel/rsel then with unfortunate sym_values we will round
959 sym_value+4 up to the next 2k block leading to a mis-match
960 between the lsel and rsel value. */
961 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_rrsel
);
962 insn
= hppa_rebuild_insn ((int) LDW_R1_R21
, val
, 14);
963 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
965 if (hplink
->multi_subspace
)
967 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 4, e_rrsel
);
968 insn
= hppa_rebuild_insn ((int) LDW_R1_DLT
, val
, 14);
969 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
971 bfd_put_32 (stub_bfd
, (bfd_vma
) LDSID_R21_R1
, loc
+ 12);
972 bfd_put_32 (stub_bfd
, (bfd_vma
) MTSP_R1
, loc
+ 16);
973 bfd_put_32 (stub_bfd
, (bfd_vma
) BE_SR0_R21
, loc
+ 20);
974 bfd_put_32 (stub_bfd
, (bfd_vma
) STW_RP
, loc
+ 24);
980 bfd_put_32 (stub_bfd
, (bfd_vma
) BV_R0_R21
, loc
+ 8);
981 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 4, e_rrsel
);
982 insn
= hppa_rebuild_insn ((int) LDW_R1_DLT
, val
, 14);
983 bfd_put_32 (stub_bfd
, insn
, loc
+ 12);
989 && stub_entry
->h
!= NULL
990 && stub_entry
->h
->pic_call
)
992 /* Build the .plt entry needed to call a PIC function from
993 statically linked code. We don't need any relocs. */
995 struct elf32_hppa_link_hash_entry
*eh
;
998 dynobj
= hplink
->root
.dynobj
;
999 eh
= (struct elf32_hppa_link_hash_entry
*) stub_entry
->h
;
1001 BFD_ASSERT (eh
->elf
.root
.type
== bfd_link_hash_defined
1002 || eh
->elf
.root
.type
== bfd_link_hash_defweak
);
1004 value
= (eh
->elf
.root
.u
.def
.value
1005 + eh
->elf
.root
.u
.def
.section
->output_offset
1006 + eh
->elf
.root
.u
.def
.section
->output_section
->vma
);
1008 /* Fill in the entry in the procedure linkage table.
1010 The format of a plt entry is
1014 bfd_put_32 (hplink
->splt
->owner
, value
,
1015 hplink
->splt
->contents
+ eh
->elf
.plt
.offset
);
1016 value
= elf_gp (hplink
->splt
->output_section
->owner
);
1017 bfd_put_32 (hplink
->splt
->owner
, value
,
1018 hplink
->splt
->contents
+ eh
->elf
.plt
.offset
+ 4);
1022 case hppa_stub_export
:
1023 /* Branches are relative. This is where we are going to. */
1024 sym_value
= (stub_entry
->target_value
1025 + stub_entry
->target_section
->output_offset
1026 + stub_entry
->target_section
->output_section
->vma
);
1028 /* And this is where we are coming from. */
1029 sym_value
-= (stub_entry
->stub_offset
1030 + stub_sec
->output_offset
1031 + stub_sec
->output_section
->vma
);
1033 if (sym_value
- 8 + 0x40000 >= 0x80000)
1035 (*_bfd_error_handler
)
1036 (_("%s(%s+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
1037 bfd_get_filename (stub_entry
->target_section
->owner
),
1039 (long) stub_entry
->stub_offset
,
1040 stub_entry
->root
.string
);
1041 bfd_set_error (bfd_error_bad_value
);
1045 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_fsel
) >> 2;
1046 insn
= hppa_rebuild_insn ((int) BL_RP
, val
, 17);
1047 bfd_put_32 (stub_bfd
, insn
, loc
);
1049 bfd_put_32 (stub_bfd
, (bfd_vma
) NOP
, loc
+ 4);
1050 bfd_put_32 (stub_bfd
, (bfd_vma
) LDW_RP
, loc
+ 8);
1051 bfd_put_32 (stub_bfd
, (bfd_vma
) LDSID_RP_R1
, loc
+ 12);
1052 bfd_put_32 (stub_bfd
, (bfd_vma
) MTSP_R1
, loc
+ 16);
1053 bfd_put_32 (stub_bfd
, (bfd_vma
) BE_SR0_RP
, loc
+ 20);
1055 /* Point the function symbol at the stub. */
1056 stub_entry
->h
->elf
.root
.u
.def
.section
= stub_sec
;
1057 stub_entry
->h
->elf
.root
.u
.def
.value
= stub_sec
->_raw_size
;
1067 stub_sec
->_raw_size
+= size
;
1093 /* As above, but don't actually build the stub. Just bump offset so
1094 we know stub section sizes. */
1097 hppa_size_one_stub (gen_entry
, in_arg
)
1098 struct bfd_hash_entry
*gen_entry
;
1101 struct elf32_hppa_stub_hash_entry
*stub_entry
;
1102 struct elf32_hppa_link_hash_table
*hplink
;
1105 /* Massage our args to the form they really have. */
1106 stub_entry
= (struct elf32_hppa_stub_hash_entry
*) gen_entry
;
1107 hplink
= (struct elf32_hppa_link_hash_table
*) in_arg
;
1109 if (stub_entry
->stub_type
== hppa_stub_long_branch
)
1111 #if ! LONG_BRANCH_PIC_IN_SHLIB
1112 if (stub_entry
->reloc_sec
!= NULL
)
1113 stub_entry
->reloc_sec
->_raw_size
+= sizeof (Elf32_External_Rela
);
1117 else if (stub_entry
->stub_type
== hppa_stub_long_branch_shared
)
1119 else if (stub_entry
->stub_type
== hppa_stub_export
)
1121 else /* hppa_stub_import or hppa_stub_import_shared. */
1123 if (hplink
->multi_subspace
)
1129 stub_entry
->stub_sec
->_raw_size
+= size
;
1133 /* Return nonzero if ABFD represents an HPPA ELF32 file.
1134 Additionally we set the default architecture and machine. */
1137 elf32_hppa_object_p (abfd
)
1140 unsigned int flags
= elf_elfheader (abfd
)->e_flags
;
1142 switch (flags
& (EF_PARISC_ARCH
| EF_PARISC_WIDE
))
1144 case EFA_PARISC_1_0
:
1145 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 10);
1146 case EFA_PARISC_1_1
:
1147 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 11);
1148 case EFA_PARISC_2_0
:
1149 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 20);
1150 case EFA_PARISC_2_0
| EF_PARISC_WIDE
:
1151 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 25);
1156 /* Undo the generic ELF code's subtraction of section->vma from the
1157 value of each external symbol. */
1160 elf32_hppa_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
1161 bfd
*abfd ATTRIBUTE_UNUSED
;
1162 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1163 const Elf_Internal_Sym
*sym ATTRIBUTE_UNUSED
;
1164 const char **namep ATTRIBUTE_UNUSED
;
1165 flagword
*flagsp ATTRIBUTE_UNUSED
;
1169 *valp
+= (*secp
)->vma
;
1173 /* Create the .plt and .got sections, and set up our hash table
1174 short-cuts to various dynamic sections. */
1177 elf32_hppa_create_dynamic_sections (abfd
, info
)
1179 struct bfd_link_info
*info
;
1181 struct elf32_hppa_link_hash_table
*hplink
;
1183 /* Don't try to create the .plt and .got twice. */
1184 hplink
= hppa_link_hash_table (info
);
1185 if (hplink
->splt
!= NULL
)
1188 /* Call the generic code to do most of the work. */
1189 if (! _bfd_elf_create_dynamic_sections (abfd
, info
))
1192 hplink
->splt
= bfd_get_section_by_name (abfd
, ".plt");
1193 hplink
->srelplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
1195 hplink
->sgot
= bfd_get_section_by_name (abfd
, ".got");
1196 hplink
->srelgot
= bfd_make_section (abfd
, ".rela.got");
1197 if (hplink
->srelgot
== NULL
1198 || ! bfd_set_section_flags (abfd
, hplink
->srelgot
,
1203 | SEC_LINKER_CREATED
1205 || ! bfd_set_section_alignment (abfd
, hplink
->srelgot
, 2))
1208 hplink
->sdynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
1209 hplink
->srelbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
1214 /* Look through the relocs for a section during the first phase, and
1215 allocate space in the global offset table or procedure linkage
1216 table. At this point we haven't necessarily read all the input
1220 elf32_hppa_check_relocs (abfd
, info
, sec
, relocs
)
1222 struct bfd_link_info
*info
;
1224 const Elf_Internal_Rela
*relocs
;
1227 Elf_Internal_Shdr
*symtab_hdr
;
1228 struct elf_link_hash_entry
**sym_hashes
;
1229 bfd_signed_vma
*local_got_refcounts
;
1230 const Elf_Internal_Rela
*rel
;
1231 const Elf_Internal_Rela
*rel_end
;
1232 struct elf32_hppa_link_hash_table
*hplink
;
1234 asection
*stubreloc
;
1236 if (info
->relocateable
)
1239 hplink
= hppa_link_hash_table (info
);
1240 dynobj
= hplink
->root
.dynobj
;
1241 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1242 sym_hashes
= elf_sym_hashes (abfd
);
1243 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1247 rel_end
= relocs
+ sec
->reloc_count
;
1248 for (rel
= relocs
; rel
< rel_end
; rel
++)
1254 #if LONG_BRANCH_PIC_IN_SHLIB
1255 NEED_STUBREL
= 0, /* We won't be needing them in this case. */
1262 unsigned int r_symndx
, r_type
;
1263 struct elf32_hppa_link_hash_entry
*h
;
1266 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1268 if (r_symndx
< symtab_hdr
->sh_info
)
1271 h
= ((struct elf32_hppa_link_hash_entry
*)
1272 sym_hashes
[r_symndx
- symtab_hdr
->sh_info
]);
1274 r_type
= ELF32_R_TYPE (rel
->r_info
);
1278 case R_PARISC_DLTIND14F
:
1279 case R_PARISC_DLTIND14R
:
1280 case R_PARISC_DLTIND21L
:
1281 /* This symbol requires a global offset table entry. */
1282 need_entry
= NEED_GOT
;
1284 /* Mark this section as containing PIC code. */
1285 sec
->flags
|= SEC_HAS_GOT_REF
;
1288 case R_PARISC_PLABEL14R
: /* "Official" procedure labels. */
1289 case R_PARISC_PLABEL21L
:
1290 case R_PARISC_PLABEL32
:
1291 /* If the addend is non-zero, we break badly. */
1292 BFD_ASSERT (rel
->r_addend
== 0);
1294 /* If we are creating a shared library, then we need to
1295 create a PLT entry for all PLABELs, because PLABELs with
1296 local symbols may be passed via a pointer to another
1297 object. Additionally, output a dynamic relocation
1298 pointing to the PLT entry. */
1299 need_entry
= PLT_PLABEL
| NEED_PLT
| NEED_DYNREL
;
1302 case R_PARISC_PCREL12F
:
1303 hplink
->has_12bit_branch
= 1;
1305 case R_PARISC_PCREL17C
:
1306 case R_PARISC_PCREL17F
:
1307 hplink
->has_17bit_branch
= 1;
1309 case R_PARISC_PCREL22F
:
1310 /* Function calls might need to go through the .plt, and
1311 might require long branch stubs. */
1314 /* We know local syms won't need a .plt entry, and if
1315 they need a long branch stub we can't guarantee that
1316 we can reach the stub. So just flag an error later
1317 if we're doing a shared link and find we need a long
1323 /* Global symbols will need a .plt entry if they remain
1324 global, and in most cases won't need a long branch
1325 stub. Unfortunately, we have to cater for the case
1326 where a symbol is forced local by versioning, or due
1327 to symbolic linking, and we lose the .plt entry. */
1328 need_entry
= NEED_PLT
| NEED_STUBREL
;
1332 case R_PARISC_SEGBASE
: /* Used to set segment base. */
1333 case R_PARISC_SEGREL32
: /* Relative reloc, used for unwind. */
1334 case R_PARISC_PCREL14F
: /* PC relative load/store. */
1335 case R_PARISC_PCREL14R
:
1336 case R_PARISC_PCREL17R
: /* External branches. */
1337 case R_PARISC_PCREL21L
: /* As above, and for load/store too. */
1338 /* We don't need to propagate the relocation if linking a
1339 shared object since these are section relative. */
1342 case R_PARISC_DPREL14F
: /* Used for gp rel data load/store. */
1343 case R_PARISC_DPREL14R
:
1344 case R_PARISC_DPREL21L
:
1347 (*_bfd_error_handler
)
1348 (_("%s: relocation %s can not be used when making a shared object; recompile with -fPIC"),
1349 bfd_get_filename (abfd
),
1350 elf_hppa_howto_table
[r_type
].name
);
1351 bfd_set_error (bfd_error_bad_value
);
1356 case R_PARISC_DIR17F
: /* Used for external branches. */
1357 case R_PARISC_DIR17R
:
1358 case R_PARISC_DIR14F
: /* Used for load/store from absolute locn. */
1359 case R_PARISC_DIR14R
:
1360 case R_PARISC_DIR21L
: /* As above, and for ext branches too. */
1362 /* Help debug shared library creation. Any of the above
1363 relocs can be used in shared libs, but they may cause
1364 pages to become unshared. */
1367 (*_bfd_error_handler
)
1368 (_("%s: relocation %s should not be used when making a shared object; recompile with -fPIC"),
1369 bfd_get_filename (abfd
),
1370 elf_hppa_howto_table
[r_type
].name
);
1375 case R_PARISC_DIR32
: /* .word relocs. */
1376 /* We may want to output a dynamic relocation later. */
1377 need_entry
= NEED_DYNREL
;
1380 /* This relocation describes the C++ object vtable hierarchy.
1381 Reconstruct it for later use during GC. */
1382 case R_PARISC_GNU_VTINHERIT
:
1383 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
,
1384 &h
->elf
, rel
->r_offset
))
1388 /* This relocation describes which C++ vtable entries are actually
1389 used. Record for later use during GC. */
1390 case R_PARISC_GNU_VTENTRY
:
1391 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
,
1392 &h
->elf
, rel
->r_addend
))
1400 /* Now carry out our orders. */
1401 if (need_entry
& NEED_GOT
)
1403 /* Allocate space for a GOT entry, as well as a dynamic
1404 relocation for this entry. */
1406 hplink
->root
.dynobj
= dynobj
= abfd
;
1408 if (hplink
->sgot
== NULL
)
1410 if (! elf32_hppa_create_dynamic_sections (dynobj
, info
))
1416 if (h
->elf
.got
.refcount
== -1)
1418 h
->elf
.got
.refcount
= 1;
1420 /* Make sure this symbol is output as a dynamic symbol. */
1421 if (h
->elf
.dynindx
== -1)
1423 if (! bfd_elf32_link_record_dynamic_symbol (info
,
1428 hplink
->sgot
->_raw_size
+= GOT_ENTRY_SIZE
;
1429 hplink
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
1432 h
->elf
.got
.refcount
+= 1;
1436 /* This is a global offset table entry for a local symbol. */
1437 if (local_got_refcounts
== NULL
)
1441 /* Allocate space for local got offsets and local
1442 plt offsets. Done this way to save polluting
1443 elf_obj_tdata with another target specific
1445 size
= symtab_hdr
->sh_info
* 2 * sizeof (bfd_signed_vma
);
1446 local_got_refcounts
= ((bfd_signed_vma
*)
1447 bfd_alloc (abfd
, size
));
1448 if (local_got_refcounts
== NULL
)
1450 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1451 memset (local_got_refcounts
, -1, size
);
1453 if (local_got_refcounts
[r_symndx
] == -1)
1455 local_got_refcounts
[r_symndx
] = 1;
1457 hplink
->sgot
->_raw_size
+= GOT_ENTRY_SIZE
;
1460 /* If we are generating a shared object, we need to
1461 output a reloc so that the dynamic linker can
1462 adjust this GOT entry (because the address
1463 the shared library is loaded at is not fixed). */
1464 hplink
->srelgot
->_raw_size
+=
1465 sizeof (Elf32_External_Rela
);
1469 local_got_refcounts
[r_symndx
] += 1;
1473 if (need_entry
& NEED_PLT
)
1475 /* If we are creating a shared library, and this is a reloc
1476 against a weak symbol or a global symbol in a dynamic
1477 object, then we will be creating an import stub and a
1478 .plt entry for the symbol. Similarly, on a normal link
1479 to symbols defined in a dynamic object we'll need the
1480 import stub and a .plt entry. We don't know yet whether
1481 the symbol is defined or not, so make an entry anyway and
1482 clean up later in adjust_dynamic_symbol. */
1483 if ((sec
->flags
& SEC_ALLOC
) != 0)
1487 if (h
->elf
.plt
.refcount
== -1)
1489 h
->elf
.plt
.refcount
= 1;
1490 h
->elf
.elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1493 h
->elf
.plt
.refcount
+= 1;
1495 /* If this .plt entry is for a plabel, mark it so
1496 that adjust_dynamic_symbol will keep the entry
1497 even if it appears to be local. */
1498 if (need_entry
& PLT_PLABEL
)
1501 else if (need_entry
& PLT_PLABEL
)
1505 if (local_got_refcounts
== NULL
)
1509 /* Allocate space for local got offsets and local
1511 size
= symtab_hdr
->sh_info
* 2 * sizeof (bfd_signed_vma
);
1512 local_got_refcounts
= ((bfd_signed_vma
*)
1513 bfd_alloc (abfd
, size
));
1514 if (local_got_refcounts
== NULL
)
1516 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1517 memset (local_got_refcounts
, -1, size
);
1519 indx
= r_symndx
+ symtab_hdr
->sh_info
;
1520 if (local_got_refcounts
[indx
] == -1)
1521 local_got_refcounts
[indx
] = 1;
1523 local_got_refcounts
[indx
] += 1;
1528 if (need_entry
& (NEED_DYNREL
| NEED_STUBREL
))
1530 /* Flag this symbol as having a non-got, non-plt reference
1531 so that we generate copy relocs if it turns out to be
1534 h
->elf
.elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
1536 /* If we are creating a shared library then we need to copy
1537 the reloc into the shared library. However, if we are
1538 linking with -Bsymbolic, we need only copy absolute
1539 relocs or relocs against symbols that are not defined in
1540 an object we are including in the link. PC- or DP- or
1541 DLT-relative relocs against any local sym or global sym
1542 with DEF_REGULAR set, can be discarded. At this point we
1543 have not seen all the input files, so it is possible that
1544 DEF_REGULAR is not set now but will be set later (it is
1545 never cleared). We account for that possibility below by
1546 storing information in the reloc_entries field of the
1549 A similar situation to the -Bsymbolic case occurs when
1550 creating shared libraries and symbol visibility changes
1551 render the symbol local.
1553 As it turns out, all the relocs we will be creating here
1554 are absolute, so we cannot remove them on -Bsymbolic
1555 links or visibility changes anyway. A STUB_REL reloc
1556 is absolute too, as in that case it is the reloc in the
1557 stub we will be creating, rather than copying the PCREL
1558 reloc in the branch. */
1559 if ((sec
->flags
& SEC_ALLOC
) != 0
1561 #if RELATIVE_DYNAMIC_RELOCS
1563 || is_absolute_reloc (r_type
)
1565 && ((h
->elf
.elf_link_hash_flags
1566 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
1574 if ((need_entry
& NEED_STUBREL
))
1577 /* Create a reloc section in dynobj and make room for
1584 hplink
->root
.dynobj
= dynobj
= abfd
;
1586 name
= bfd_elf_string_from_elf_section
1588 elf_elfheader (abfd
)->e_shstrndx
,
1589 elf_section_data (sec
)->rel_hdr
.sh_name
);
1592 (*_bfd_error_handler
)
1593 (_("Could not find relocation section for %s"),
1595 bfd_set_error (bfd_error_bad_value
);
1599 if ((need_entry
& NEED_STUBREL
))
1601 size_t len
= strlen (name
) + sizeof (STUB_SUFFIX
);
1602 char *newname
= bfd_malloc (len
);
1604 if (newname
== NULL
)
1606 strcpy (newname
, name
);
1607 strcpy (newname
+ len
- sizeof (STUB_SUFFIX
),
1612 srel
= bfd_get_section_by_name (dynobj
, name
);
1617 srel
= bfd_make_section (dynobj
, name
);
1618 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
1619 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1620 if ((sec
->flags
& SEC_ALLOC
) != 0)
1621 flags
|= SEC_ALLOC
| SEC_LOAD
;
1623 || !bfd_set_section_flags (dynobj
, srel
, flags
)
1624 || !bfd_set_section_alignment (dynobj
, srel
, 2))
1627 else if ((need_entry
& NEED_STUBREL
))
1630 if ((need_entry
& NEED_STUBREL
))
1636 #if ! LONG_BRANCH_PIC_IN_SHLIB
1637 /* If this is a function call, we only need one dynamic
1638 reloc for the stub as all calls to a particular
1639 function will go through the same stub. Actually, a
1640 long branch stub needs two relocations, but we count
1641 on some intelligence on the part of the dynamic
1643 if ((need_entry
& NEED_STUBREL
))
1645 doit
= h
->stub_reloc_sec
!= stubreloc
;
1646 h
->stub_reloc_sec
= stubreloc
;
1654 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
1656 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
1657 /* Keep track of relocations we have entered for
1658 this global symbol, so that we can discard them
1659 later if necessary. */
1662 #if RELATIVE_DYNAMIC_RELOCS
1663 || ! is_absolute_reloc (rtype
)
1665 || (need_entry
& NEED_STUBREL
)))
1667 struct elf32_hppa_dyn_reloc_entry
*p
;
1669 for (p
= h
->reloc_entries
; p
!= NULL
; p
= p
->next
)
1670 if (p
->section
== srel
)
1675 p
= ((struct elf32_hppa_dyn_reloc_entry
*)
1676 bfd_alloc (dynobj
, sizeof *p
));
1679 p
->next
= h
->reloc_entries
;
1680 h
->reloc_entries
= p
;
1685 /* NEED_STUBREL and NEED_DYNREL are never both
1686 set. Leave the count at zero for the
1687 NEED_STUBREL case as we only ever have one
1688 stub reloc per section per symbol, and this
1689 simplifies code in hppa_discard_copies. */
1690 if (! (need_entry
& NEED_STUBREL
))
1702 /* Return the section that should be marked against garbage collection
1703 for a given relocation. */
1706 elf32_hppa_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
1708 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1709 Elf_Internal_Rela
*rel
;
1710 struct elf_link_hash_entry
*h
;
1711 Elf_Internal_Sym
*sym
;
1715 switch ((unsigned int) ELF32_R_TYPE (rel
->r_info
))
1717 case R_PARISC_GNU_VTINHERIT
:
1718 case R_PARISC_GNU_VTENTRY
:
1722 switch (h
->root
.type
)
1724 case bfd_link_hash_defined
:
1725 case bfd_link_hash_defweak
:
1726 return h
->root
.u
.def
.section
;
1728 case bfd_link_hash_common
:
1729 return h
->root
.u
.c
.p
->section
;
1738 if (!(elf_bad_symtab (abfd
)
1739 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
1740 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
1741 && sym
->st_shndx
!= SHN_COMMON
))
1743 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
1750 /* Update the got and plt entry reference counts for the section being
1754 elf32_hppa_gc_sweep_hook (abfd
, info
, sec
, relocs
)
1756 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1758 const Elf_Internal_Rela
*relocs
;
1760 Elf_Internal_Shdr
*symtab_hdr
;
1761 struct elf_link_hash_entry
**sym_hashes
;
1762 bfd_signed_vma
*local_got_refcounts
;
1763 bfd_signed_vma
*local_plt_refcounts
;
1764 const Elf_Internal_Rela
*rel
, *relend
;
1765 unsigned long r_symndx
;
1766 struct elf_link_hash_entry
*h
;
1767 struct elf32_hppa_link_hash_table
*hplink
;
1772 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1773 sym_hashes
= elf_sym_hashes (abfd
);
1774 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1775 local_plt_refcounts
= local_got_refcounts
;
1776 if (local_plt_refcounts
!= NULL
)
1777 local_plt_refcounts
+= symtab_hdr
->sh_info
;
1778 hplink
= hppa_link_hash_table (info
);
1779 dynobj
= hplink
->root
.dynobj
;
1783 sgot
= hplink
->sgot
;
1784 srelgot
= hplink
->srelgot
;
1786 relend
= relocs
+ sec
->reloc_count
;
1787 for (rel
= relocs
; rel
< relend
; rel
++)
1788 switch ((unsigned int) ELF32_R_TYPE (rel
->r_info
))
1790 case R_PARISC_DLTIND14F
:
1791 case R_PARISC_DLTIND14R
:
1792 case R_PARISC_DLTIND21L
:
1793 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1794 if (r_symndx
>= symtab_hdr
->sh_info
)
1796 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1797 if (h
->got
.refcount
> 0)
1799 h
->got
.refcount
-= 1;
1800 if (h
->got
.refcount
== 0)
1802 sgot
->_raw_size
-= GOT_ENTRY_SIZE
;
1803 srelgot
->_raw_size
-= sizeof (Elf32_External_Rela
);
1807 else if (local_got_refcounts
!= NULL
)
1809 if (local_got_refcounts
[r_symndx
] > 0)
1811 local_got_refcounts
[r_symndx
] -= 1;
1812 if (local_got_refcounts
[r_symndx
] == 0)
1814 sgot
->_raw_size
-= GOT_ENTRY_SIZE
;
1816 srelgot
->_raw_size
-= sizeof (Elf32_External_Rela
);
1822 case R_PARISC_PCREL12F
:
1823 case R_PARISC_PCREL17C
:
1824 case R_PARISC_PCREL17F
:
1825 case R_PARISC_PCREL22F
:
1826 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1827 if (r_symndx
>= symtab_hdr
->sh_info
)
1829 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1830 if (h
->plt
.refcount
> 0)
1831 h
->plt
.refcount
-= 1;
1835 case R_PARISC_PLABEL14R
:
1836 case R_PARISC_PLABEL21L
:
1837 case R_PARISC_PLABEL32
:
1838 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1839 if (r_symndx
>= symtab_hdr
->sh_info
)
1841 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1842 if (h
->plt
.refcount
> 0)
1843 h
->plt
.refcount
-= 1;
1845 else if (local_plt_refcounts
!= NULL
)
1847 if (local_plt_refcounts
[r_symndx
] > 0)
1848 local_plt_refcounts
[r_symndx
] -= 1;
1859 /* Our own version of hide_symbol, so that we can keep plt entries for
1863 elf32_hppa_hide_symbol (info
, h
)
1864 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1865 struct elf_link_hash_entry
*h
;
1867 if ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0)
1869 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
)
1871 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1872 h
->plt
.offset
= (bfd_vma
) -1;
1876 /* Adjust a symbol defined by a dynamic object and referenced by a
1877 regular object. The current definition is in some section of the
1878 dynamic object, but we're not including those sections. We have to
1879 change the definition to something the rest of the link can
1883 elf32_hppa_adjust_dynamic_symbol (info
, h
)
1884 struct bfd_link_info
*info
;
1885 struct elf_link_hash_entry
*h
;
1888 struct elf32_hppa_link_hash_table
*hplink
;
1891 hplink
= hppa_link_hash_table (info
);
1892 dynobj
= hplink
->root
.dynobj
;
1894 /* If this is a function, put it in the procedure linkage table. We
1895 will fill in the contents of the procedure linkage table later,
1896 when we know the address of the .got section. */
1897 if (h
->type
== STT_FUNC
1898 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1901 && h
->plt
.refcount
> 0
1902 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
1903 && (h
->root
.u
.def
.section
->flags
& SEC_HAS_GOT_REF
) != 0)
1905 ((struct elf32_hppa_link_hash_entry
*) h
)->maybe_pic_call
= 1;
1908 if (h
->plt
.refcount
<= 0
1909 || ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
1910 && h
->root
.type
!= bfd_link_hash_defweak
1911 && ! ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
1912 && (!info
->shared
|| info
->symbolic
)))
1914 /* The .plt entry is not needed when:
1915 a) Garbage collection has removed all references to the
1917 b) We know for certain the symbol is defined in this
1918 object, and it's not a weak definition, nor is the symbol
1919 used by a plabel relocation. Either this object is the
1920 application or we are doing a shared symbolic link. */
1922 /* As a special sop to the hppa ABI, we keep a .plt entry
1923 for functions in sections containing PIC code. */
1924 if (((struct elf32_hppa_link_hash_entry
*) h
)->maybe_pic_call
)
1925 ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
= 1;
1928 h
->plt
.offset
= (bfd_vma
) -1;
1929 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1934 /* Make an entry in the .plt section. */
1936 h
->plt
.offset
= s
->_raw_size
;
1937 if (PLABEL_PLT_ENTRY_SIZE
!= PLT_ENTRY_SIZE
1938 && ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
1939 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1941 /* Add some extra space for the dynamic linker to use. */
1942 s
->_raw_size
+= PLABEL_PLT_ENTRY_SIZE
;
1945 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1947 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
)
1949 /* Make sure this symbol is output as a dynamic symbol. */
1950 if (h
->dynindx
== -1
1951 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1953 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1957 /* We also need to make an entry in the .rela.plt section. */
1958 s
= hplink
->srelplt
;
1959 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
1961 hplink
->need_plt_stub
= 1;
1966 /* If this is a weak symbol, and there is a real definition, the
1967 processor independent code will have arranged for us to see the
1968 real definition first, and we can just use the same value. */
1969 if (h
->weakdef
!= NULL
)
1971 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
1972 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
1973 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1974 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1978 /* This is a reference to a symbol defined by a dynamic object which
1979 is not a function. */
1981 /* If we are creating a shared library, we must presume that the
1982 only references to the symbol are via the global offset table.
1983 For such cases we need not do anything here; the relocations will
1984 be handled correctly by relocate_section. */
1988 /* If there are no references to this symbol that do not use the
1989 GOT, we don't need to generate a copy reloc. */
1990 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
1993 /* We must allocate the symbol in our .dynbss section, which will
1994 become part of the .bss section of the executable. There will be
1995 an entry for this symbol in the .dynsym section. The dynamic
1996 object will contain position independent code, so all references
1997 from the dynamic object to this symbol will go through the global
1998 offset table. The dynamic linker will use the .dynsym entry to
1999 determine the address it must put in the global offset table, so
2000 both the dynamic object and the regular object will refer to the
2001 same memory location for the variable. */
2003 s
= hplink
->sdynbss
;
2005 /* We must generate a COPY reloc to tell the dynamic linker to
2006 copy the initial value out of the dynamic object and into the
2007 runtime process image. We need to remember the offset into the
2008 .rela.bss section we are going to use. */
2009 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2013 srel
= hplink
->srelbss
;
2014 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
2015 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
2019 /* We need to figure out the alignment required for this symbol. I
2020 have no idea how other ELF linkers handle this. */
2021 unsigned int power_of_two
;
2023 power_of_two
= bfd_log2 (h
->size
);
2024 if (power_of_two
> 3)
2027 /* Apply the required alignment. */
2028 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
2029 (bfd_size_type
) (1 << power_of_two
));
2030 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
2032 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
2036 /* Define the symbol as being at this point in the section. */
2037 h
->root
.u
.def
.section
= s
;
2038 h
->root
.u
.def
.value
= s
->_raw_size
;
2040 /* Increment the section size to make room for the symbol. */
2041 s
->_raw_size
+= h
->size
;
2046 /* Called via elf_link_hash_traverse to create .plt entries for an
2047 application that uses statically linked PIC functions. Similar to
2048 the first part of elf32_hppa_adjust_dynamic_symbol. */
2051 hppa_handle_PIC_calls (h
, inf
)
2052 struct elf_link_hash_entry
*h
;
2055 struct bfd_link_info
*info
;
2057 struct elf32_hppa_link_hash_table
*hplink
;
2060 if (! (h
->plt
.refcount
> 0
2061 && (h
->root
.type
== bfd_link_hash_defined
2062 || h
->root
.type
== bfd_link_hash_defweak
)
2063 && (h
->root
.u
.def
.section
->flags
& SEC_HAS_GOT_REF
) != 0))
2065 h
->plt
.offset
= (bfd_vma
) -1;
2066 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2070 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2071 ((struct elf32_hppa_link_hash_entry
*) h
)->maybe_pic_call
= 1;
2072 ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
= 1;
2074 info
= (struct bfd_link_info
*) inf
;
2075 hplink
= hppa_link_hash_table (info
);
2076 dynobj
= hplink
->root
.dynobj
;
2078 /* Make an entry in the .plt section. */
2080 h
->plt
.offset
= s
->_raw_size
;
2081 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2086 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
2087 || RELATIVE_DYNAMIC_RELOCS)
2088 /* This function is called via elf_link_hash_traverse to discard space
2089 we allocated for relocs that it turned out we didn't need. */
2092 hppa_discard_copies (h
, inf
)
2093 struct elf_link_hash_entry
*h
;
2096 struct elf32_hppa_dyn_reloc_entry
*s
;
2097 struct elf32_hppa_link_hash_entry
*eh
;
2098 struct bfd_link_info
*info
;
2100 eh
= (struct elf32_hppa_link_hash_entry
*) h
;
2101 info
= (struct bfd_link_info
*) inf
;
2103 #if ! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT
2104 /* Handle the stub reloc case. If we have a plt entry for the
2105 function, we won't be needing long branch stubs. s->count will
2106 only be zero for stub relocs, which provides a handy way of
2107 flagging these relocs, and means we need do nothing special for
2108 the forced local and symbolic link case. */
2109 if (eh
->stub_reloc_sec
!= NULL
2110 && eh
->elf
.plt
.offset
!= (bfd_vma
) -1)
2112 for (s
= eh
->reloc_entries
; s
!= NULL
; s
= s
->next
)
2114 s
->section
->_raw_size
-= sizeof (Elf32_External_Rela
);
2118 #if RELATIVE_DYNAMIC_RELOCS
2119 /* If a symbol has been forced local or we have found a regular
2120 definition for the symbolic link case, then we won't be needing
2122 if (eh
->elf
.dynindx
== -1
2123 || ((eh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
2124 && !is_absolute_reloc (r_type
)
2127 for (s
= eh
->reloc_entries
; s
!= NULL
; s
= s
->next
)
2128 s
->section
->_raw_size
-= s
->count
* sizeof (Elf32_External_Rela
);
2136 /* This function is called via elf_link_hash_traverse to force
2137 millicode symbols local so they do not end up as globals in the
2138 dynamic symbol table. We ought to be able to do this in
2139 adjust_dynamic_symbol, but our adjust_dynamic_symbol is not called
2140 for all dynamic symbols. Arguably, this is a bug in
2141 elf_adjust_dynamic_symbol. */
2144 clobber_millicode_symbols (h
, info
)
2145 struct elf_link_hash_entry
*h
;
2146 struct bfd_link_info
*info
;
2148 /* Note! We only want to remove these from the dynamic symbol
2149 table. Therefore we do not set ELF_LINK_FORCED_LOCAL. */
2150 if (h
->type
== STT_PARISC_MILLI
)
2152 unsigned short oldflags
= h
->elf_link_hash_flags
;
2153 h
->elf_link_hash_flags
|= ELF_LINK_FORCED_LOCAL
;
2154 elf32_hppa_hide_symbol (info
, h
);
2155 h
->elf_link_hash_flags
&= ~ELF_LINK_FORCED_LOCAL
;
2156 h
->elf_link_hash_flags
|= oldflags
& ELF_LINK_FORCED_LOCAL
;
2161 /* Set the sizes of the dynamic sections. */
2164 elf32_hppa_size_dynamic_sections (output_bfd
, info
)
2166 struct bfd_link_info
*info
;
2168 struct elf32_hppa_link_hash_table
*hplink
;
2174 hplink
= hppa_link_hash_table (info
);
2175 dynobj
= hplink
->root
.dynobj
;
2176 BFD_ASSERT (dynobj
!= NULL
);
2178 if (hplink
->root
.dynamic_sections_created
)
2182 /* Set the contents of the .interp section to the interpreter. */
2185 s
= bfd_get_section_by_name (dynobj
, ".interp");
2186 BFD_ASSERT (s
!= NULL
);
2187 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2188 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2191 /* Force millicode symbols local. */
2192 elf_link_hash_traverse (&hplink
->root
,
2193 clobber_millicode_symbols
,
2196 /* Set up .plt offsets for local plabels. */
2197 for (i
= info
->input_bfds
; i
; i
= i
->link_next
)
2199 bfd_signed_vma
*local_plt
;
2200 bfd_signed_vma
*end_local_plt
;
2201 bfd_size_type locsymcount
;
2202 Elf_Internal_Shdr
*symtab_hdr
;
2204 local_plt
= elf_local_got_refcounts (i
);
2208 symtab_hdr
= &elf_tdata (i
)->symtab_hdr
;
2209 locsymcount
= symtab_hdr
->sh_info
;
2210 local_plt
+= locsymcount
;
2211 end_local_plt
= local_plt
+ locsymcount
;
2213 for (; local_plt
< end_local_plt
; ++local_plt
)
2218 *local_plt
= s
->_raw_size
;
2219 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2221 hplink
->srelplt
->_raw_size
+= sizeof (Elf32_External_Rela
);
2224 *local_plt
= (bfd_vma
) -1;
2230 /* Run through the function symbols, looking for any that are
2231 PIC, and allocate space for the necessary .plt entries so
2232 that %r19 will be set up. */
2234 elf_link_hash_traverse (&hplink
->root
,
2235 hppa_handle_PIC_calls
,
2238 /* We may have created entries in the .rela.got section.
2239 However, if we are not creating the dynamic sections, we will
2240 not actually use these entries. Reset the size of .rela.got,
2241 which will cause it to get stripped from the output file
2243 hplink
->srelgot
->_raw_size
= 0;
2246 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
2247 || RELATIVE_DYNAMIC_RELOCS)
2248 /* If this is a -Bsymbolic shared link, then we need to discard all
2249 relocs against symbols defined in a regular object. We also need
2250 to lose relocs we've allocated for long branch stubs if we know
2251 we won't be generating a stub. */
2253 elf_link_hash_traverse (&hplink
->root
,
2254 hppa_discard_copies
,
2258 /* The check_relocs and adjust_dynamic_symbol entry points have
2259 determined the sizes of the various dynamic sections. Allocate
2263 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2267 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2270 /* It's OK to base decisions on the section name, because none
2271 of the dynobj section names depend upon the input files. */
2272 name
= bfd_get_section_name (dynobj
, s
);
2274 if (strncmp (name
, ".rela", 5) == 0)
2276 if (s
->_raw_size
!= 0)
2279 const char *outname
;
2281 /* Remember whether there are any reloc sections other
2283 if (strcmp (name
+5, ".plt") != 0)
2286 /* If this relocation section applies to a read only
2287 section, then we probably need a DT_TEXTREL entry. */
2288 outname
= bfd_get_section_name (output_bfd
,
2290 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
2292 && (target
->flags
& SEC_READONLY
) != 0
2293 && (target
->flags
& SEC_ALLOC
) != 0)
2296 /* We use the reloc_count field as a counter if we need
2297 to copy relocs into the output file. */
2301 else if (strcmp (name
, ".plt") == 0)
2303 if (hplink
->need_plt_stub
)
2305 /* Make space for the plt stub at the end of the .plt
2306 section. We want this stub right at the end, up
2307 against the .got section. */
2308 int gotalign
= bfd_section_alignment (dynobj
, hplink
->sgot
);
2309 int pltalign
= bfd_section_alignment (dynobj
, s
);
2312 if (gotalign
> pltalign
)
2313 bfd_set_section_alignment (dynobj
, s
, gotalign
);
2314 mask
= ((bfd_size_type
) 1 << gotalign
) - 1;
2315 s
->_raw_size
= (s
->_raw_size
+ sizeof (plt_stub
) + mask
) & ~mask
;
2318 else if (strcmp (name
, ".got") == 0)
2322 /* It's not one of our sections, so don't allocate space. */
2326 if (s
->_raw_size
== 0)
2328 /* If we don't need this section, strip it from the
2329 output file. This is mostly to handle .rela.bss and
2330 .rela.plt. We must create both sections in
2331 create_dynamic_sections, because they must be created
2332 before the linker maps input sections to output
2333 sections. The linker does that before
2334 adjust_dynamic_symbol is called, and it is that
2335 function which decides whether anything needs to go
2336 into these sections. */
2337 _bfd_strip_section_from_output (info
, s
);
2341 /* Allocate memory for the section contents. Zero it, because
2342 we may not fill in all the reloc sections. */
2343 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
2344 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
2348 if (hplink
->root
.dynamic_sections_created
)
2350 /* Like IA-64 and HPPA64, always create a DT_PLTGOT. It
2351 actually has nothing to do with the PLT, it is how we
2352 communicate the LTP value of a load module to the dynamic
2354 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
2357 /* Add some entries to the .dynamic section. We fill in the
2358 values later, in elf32_hppa_finish_dynamic_sections, but we
2359 must add the entries now so that we get the correct size for
2360 the .dynamic section. The DT_DEBUG entry is filled in by the
2361 dynamic linker and used by the debugger. */
2364 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
2368 if (hplink
->srelplt
->_raw_size
!= 0)
2370 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
2371 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
2372 || ! bfd_elf32_add_dynamic_entry (info
, DT_JMPREL
, 0))
2378 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELA
, 0)
2379 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELASZ
, 0)
2380 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELAENT
,
2381 sizeof (Elf32_External_Rela
)))
2387 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
2389 info
->flags
|= DF_TEXTREL
;
2396 /* External entry points for sizing and building linker stubs. */
2398 /* Determine and set the size of the stub section for a final link.
2400 The basic idea here is to examine all the relocations looking for
2401 PC-relative calls to a target that is unreachable with a "bl"
2405 elf32_hppa_size_stubs (output_bfd
, stub_bfd
, info
, multi_subspace
, group_size
,
2406 add_stub_section
, layout_sections_again
)
2409 struct bfd_link_info
*info
;
2410 boolean multi_subspace
;
2411 bfd_signed_vma group_size
;
2412 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
2413 void (*layout_sections_again
) PARAMS ((void));
2417 asection
**input_list
, **list
;
2418 Elf_Internal_Sym
*local_syms
, **all_local_syms
;
2419 unsigned int bfd_indx
, bfd_count
;
2420 int top_id
, top_index
;
2421 struct elf32_hppa_link_hash_table
*hplink
;
2422 bfd_size_type stub_group_size
;
2423 boolean stubs_always_before_branch
;
2424 boolean stub_changed
= 0;
2427 hplink
= hppa_link_hash_table (info
);
2429 /* Stash our params away. */
2430 hplink
->stub_bfd
= stub_bfd
;
2431 hplink
->multi_subspace
= multi_subspace
;
2432 hplink
->add_stub_section
= add_stub_section
;
2433 hplink
->layout_sections_again
= layout_sections_again
;
2434 stubs_always_before_branch
= group_size
< 0;
2436 stub_group_size
= -group_size
;
2438 stub_group_size
= group_size
;
2439 if (stub_group_size
== 1)
2441 /* Default values. */
2442 stub_group_size
= 8000000;
2443 if (hplink
->has_17bit_branch
|| hplink
->multi_subspace
)
2444 stub_group_size
= 250000;
2445 if (hplink
->has_12bit_branch
)
2446 stub_group_size
= 7812;
2449 /* Count the number of input BFDs and find the top input section id. */
2450 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
2452 input_bfd
= input_bfd
->link_next
)
2455 for (section
= input_bfd
->sections
;
2457 section
= section
->next
)
2459 if (top_id
< section
->id
)
2460 top_id
= section
->id
;
2465 = (struct map_stub
*) bfd_zmalloc (sizeof (struct map_stub
) * (top_id
+ 1));
2466 if (hplink
->stub_group
== NULL
)
2469 /* Make a list of input sections for each output section included in
2472 We can't use output_bfd->section_count here to find the top output
2473 section index as some sections may have been removed, and
2474 _bfd_strip_section_from_output doesn't renumber the indices. */
2475 for (section
= output_bfd
->sections
, top_index
= 0;
2477 section
= section
->next
)
2479 if (top_index
< section
->index
)
2480 top_index
= section
->index
;
2484 = (asection
**) bfd_malloc (sizeof (asection
*) * (top_index
+ 1));
2485 if (input_list
== NULL
)
2488 /* For sections we aren't interested in, mark their entries with a
2489 value we can check later. */
2490 list
= input_list
+ top_index
;
2492 *list
= bfd_abs_section_ptr
;
2493 while (list
-- != input_list
);
2495 for (section
= output_bfd
->sections
;
2497 section
= section
->next
)
2499 if ((section
->flags
& SEC_CODE
) != 0)
2500 input_list
[section
->index
] = NULL
;
2503 /* Now actually build the lists. */
2504 for (input_bfd
= info
->input_bfds
;
2506 input_bfd
= input_bfd
->link_next
)
2508 for (section
= input_bfd
->sections
;
2510 section
= section
->next
)
2512 if (section
->output_section
!= NULL
2513 && section
->output_section
->owner
== output_bfd
2514 && section
->output_section
->index
<= top_index
)
2516 list
= input_list
+ section
->output_section
->index
;
2517 if (*list
!= bfd_abs_section_ptr
)
2519 /* Steal the link_sec pointer for our list. */
2520 #define PREV_SEC(sec) (hplink->stub_group[(sec)->id].link_sec)
2521 /* This happens to make the list in reverse order,
2522 which is what we want. */
2523 PREV_SEC (section
) = *list
;
2530 /* See whether we can group stub sections together. Grouping stub
2531 sections may result in fewer stubs. More importantly, we need to
2532 put all .init* and .fini* stubs at the beginning of the .init or
2533 .fini output sections respectively, because glibc splits the
2534 _init and _fini functions into multiple parts. Putting a stub in
2535 the middle of a function is not a good idea. */
2536 list
= input_list
+ top_index
;
2539 asection
*tail
= *list
;
2540 if (tail
== bfd_abs_section_ptr
)
2542 while (tail
!= NULL
)
2546 bfd_size_type total
;
2549 if (tail
->_cooked_size
)
2550 total
= tail
->_cooked_size
;
2552 total
= tail
->_raw_size
;
2553 while ((prev
= PREV_SEC (curr
)) != NULL
2554 && ((total
+= curr
->output_offset
- prev
->output_offset
)
2558 /* OK, the size from the start of CURR to the end is less
2559 than 250000 bytes and thus can be handled by one stub
2560 section. (or the tail section is itself larger than
2561 250000 bytes, in which case we may be toast.)
2562 We should really be keeping track of the total size of
2563 stubs added here, as stubs contribute to the final output
2564 section size. That's a little tricky, and this way will
2565 only break if stubs added total more than 12144 bytes, or
2566 1518 long branch stubs. It seems unlikely for more than
2567 1518 different functions to be called, especially from
2568 code only 250000 bytes long. */
2571 prev
= PREV_SEC (tail
);
2572 /* Set up this stub group. */
2573 hplink
->stub_group
[tail
->id
].link_sec
= curr
;
2575 while (tail
!= curr
&& (tail
= prev
) != NULL
);
2577 /* But wait, there's more! Input sections up to 250000
2578 bytes before the stub section can be handled by it too. */
2579 if (!stubs_always_before_branch
)
2583 && ((total
+= tail
->output_offset
- prev
->output_offset
)
2587 prev
= PREV_SEC (tail
);
2588 hplink
->stub_group
[tail
->id
].link_sec
= curr
;
2594 while (list
-- != input_list
);
2598 /* We want to read in symbol extension records only once. To do this
2599 we need to read in the local symbols in parallel and save them for
2600 later use; so hold pointers to the local symbols in an array. */
2602 = (Elf_Internal_Sym
**) bfd_zmalloc (sizeof (Elf_Internal_Sym
*)
2604 if (all_local_syms
== NULL
)
2607 /* Walk over all the input BFDs, swapping in local symbols.
2608 If we are creating a shared library, create hash entries for the
2610 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
2612 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
2614 Elf_Internal_Shdr
*symtab_hdr
;
2615 Elf_Internal_Sym
*isym
;
2616 Elf32_External_Sym
*ext_syms
, *esym
, *end_sy
;
2618 /* We'll need the symbol table in a second. */
2619 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2620 if (symtab_hdr
->sh_info
== 0)
2623 /* We need an array of the local symbols attached to the input bfd.
2624 Unfortunately, we're going to have to read & swap them in. */
2625 local_syms
= (Elf_Internal_Sym
*)
2626 bfd_malloc (symtab_hdr
->sh_info
* sizeof (Elf_Internal_Sym
));
2627 if (local_syms
== NULL
)
2629 goto error_ret_free_local
;
2631 all_local_syms
[bfd_indx
] = local_syms
;
2632 ext_syms
= (Elf32_External_Sym
*)
2633 bfd_malloc (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
));
2634 if (ext_syms
== NULL
)
2636 goto error_ret_free_local
;
2639 if (bfd_seek (input_bfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
2640 || (bfd_read (ext_syms
, 1,
2641 (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
)),
2643 != (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
))))
2646 goto error_ret_free_local
;
2649 /* Swap the local symbols in. */
2652 for (end_sy
= esym
+ symtab_hdr
->sh_info
; esym
< end_sy
; esym
++, isym
++)
2653 bfd_elf32_swap_symbol_in (input_bfd
, esym
, isym
);
2655 /* Now we can free the external symbols. */
2658 #if ! LONG_BRANCH_PIC_IN_SHLIB
2659 /* If this is a shared link, find all the stub reloc sections. */
2661 for (section
= input_bfd
->sections
;
2663 section
= section
->next
)
2666 asection
*reloc_sec
;
2668 name
= bfd_malloc (strlen (section
->name
)
2669 + sizeof STUB_SUFFIX
2673 sprintf (name
, ".rela%s%s", section
->name
, STUB_SUFFIX
);
2674 reloc_sec
= bfd_get_section_by_name (hplink
->root
.dynobj
, name
);
2675 hplink
->stub_group
[section
->id
].reloc_sec
= reloc_sec
;
2680 if (info
->shared
&& hplink
->multi_subspace
)
2682 struct elf_link_hash_entry
**sym_hashes
;
2683 struct elf_link_hash_entry
**end_hashes
;
2684 unsigned int symcount
;
2686 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
2687 - symtab_hdr
->sh_info
);
2688 sym_hashes
= elf_sym_hashes (input_bfd
);
2689 end_hashes
= sym_hashes
+ symcount
;
2691 /* Look through the global syms for functions; We need to
2692 build export stubs for all globally visible functions. */
2693 for (; sym_hashes
< end_hashes
; sym_hashes
++)
2695 struct elf32_hppa_link_hash_entry
*hash
;
2697 hash
= (struct elf32_hppa_link_hash_entry
*) *sym_hashes
;
2699 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
2700 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
2701 hash
= ((struct elf32_hppa_link_hash_entry
*)
2702 hash
->elf
.root
.u
.i
.link
);
2704 /* At this point in the link, undefined syms have been
2705 resolved, so we need to check that the symbol was
2706 defined in this BFD. */
2707 if ((hash
->elf
.root
.type
== bfd_link_hash_defined
2708 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
2709 && hash
->elf
.type
== STT_FUNC
2710 && hash
->elf
.root
.u
.def
.section
->output_section
!= NULL
2711 && (hash
->elf
.root
.u
.def
.section
->output_section
->owner
2713 && hash
->elf
.root
.u
.def
.section
->owner
== input_bfd
2714 && (hash
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
2715 && !(hash
->elf
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
2716 && ELF_ST_VISIBILITY (hash
->elf
.other
) == STV_DEFAULT
)
2719 const char *stub_name
;
2720 struct elf32_hppa_stub_hash_entry
*stub_entry
;
2722 sec
= hash
->elf
.root
.u
.def
.section
;
2723 stub_name
= hash
->elf
.root
.root
.string
;
2724 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
,
2727 if (stub_entry
== NULL
)
2729 stub_entry
= hppa_add_stub (stub_name
, sec
, hplink
);
2731 goto error_ret_free_local
;
2733 stub_entry
->target_value
= hash
->elf
.root
.u
.def
.value
;
2734 stub_entry
->target_section
= hash
->elf
.root
.u
.def
.section
;
2735 stub_entry
->stub_type
= hppa_stub_export
;
2736 stub_entry
->h
= hash
;
2741 (*_bfd_error_handler
) (_("%s: duplicate export stub %s"),
2742 bfd_get_filename (input_bfd
),
2754 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
2756 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
2758 Elf_Internal_Shdr
*symtab_hdr
;
2760 /* We'll need the symbol table in a second. */
2761 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2762 if (symtab_hdr
->sh_info
== 0)
2765 local_syms
= all_local_syms
[bfd_indx
];
2767 /* Walk over each section attached to the input bfd. */
2768 for (section
= input_bfd
->sections
;
2770 section
= section
->next
)
2772 Elf_Internal_Shdr
*input_rel_hdr
;
2773 Elf32_External_Rela
*external_relocs
, *erelaend
, *erela
;
2774 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
2776 /* If there aren't any relocs, then there's nothing more
2778 if ((section
->flags
& SEC_RELOC
) == 0
2779 || section
->reloc_count
== 0)
2782 /* If this section is a link-once section that will be
2783 discarded, then don't create any stubs. */
2784 if (section
->output_section
== NULL
2785 || section
->output_section
->owner
!= output_bfd
)
2788 /* Allocate space for the external relocations. */
2790 = ((Elf32_External_Rela
*)
2791 bfd_malloc (section
->reloc_count
2792 * sizeof (Elf32_External_Rela
)));
2793 if (external_relocs
== NULL
)
2795 goto error_ret_free_local
;
2798 /* Likewise for the internal relocations. */
2799 internal_relocs
= ((Elf_Internal_Rela
*)
2800 bfd_malloc (section
->reloc_count
2801 * sizeof (Elf_Internal_Rela
)));
2802 if (internal_relocs
== NULL
)
2804 free (external_relocs
);
2805 goto error_ret_free_local
;
2808 /* Read in the external relocs. */
2809 input_rel_hdr
= &elf_section_data (section
)->rel_hdr
;
2810 if (bfd_seek (input_bfd
, input_rel_hdr
->sh_offset
, SEEK_SET
) != 0
2811 || bfd_read (external_relocs
, 1,
2812 input_rel_hdr
->sh_size
,
2813 input_bfd
) != input_rel_hdr
->sh_size
)
2815 free (external_relocs
);
2816 error_ret_free_internal
:
2817 free (internal_relocs
);
2818 goto error_ret_free_local
;
2821 /* Swap in the relocs. */
2822 erela
= external_relocs
;
2823 erelaend
= erela
+ section
->reloc_count
;
2824 irela
= internal_relocs
;
2825 for (; erela
< erelaend
; erela
++, irela
++)
2826 bfd_elf32_swap_reloca_in (input_bfd
, erela
, irela
);
2828 /* We're done with the external relocs, free them. */
2829 free (external_relocs
);
2831 /* Now examine each relocation. */
2832 irela
= internal_relocs
;
2833 irelaend
= irela
+ section
->reloc_count
;
2834 for (; irela
< irelaend
; irela
++)
2836 unsigned int r_type
, r_indx
;
2837 enum elf32_hppa_stub_type stub_type
;
2838 struct elf32_hppa_stub_hash_entry
*stub_entry
;
2841 bfd_vma destination
;
2842 struct elf32_hppa_link_hash_entry
*hash
;
2844 const asection
*id_sec
;
2846 r_type
= ELF32_R_TYPE (irela
->r_info
);
2847 r_indx
= ELF32_R_SYM (irela
->r_info
);
2849 if (r_type
>= (unsigned int) R_PARISC_UNIMPLEMENTED
)
2851 bfd_set_error (bfd_error_bad_value
);
2852 goto error_ret_free_internal
;
2855 /* Only look for stubs on call instructions. */
2856 if (r_type
!= (unsigned int) R_PARISC_PCREL12F
2857 && r_type
!= (unsigned int) R_PARISC_PCREL17F
2858 && r_type
!= (unsigned int) R_PARISC_PCREL22F
)
2861 /* Now determine the call target, its name, value,
2867 if (r_indx
< symtab_hdr
->sh_info
)
2869 /* It's a local symbol. */
2870 Elf_Internal_Sym
*sym
;
2871 Elf_Internal_Shdr
*hdr
;
2873 sym
= local_syms
+ r_indx
;
2874 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
2875 sym_sec
= hdr
->bfd_section
;
2876 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
2877 sym_value
= sym
->st_value
;
2878 destination
= (sym_value
+ irela
->r_addend
2879 + sym_sec
->output_offset
2880 + sym_sec
->output_section
->vma
);
2884 /* It's an external symbol. */
2887 e_indx
= r_indx
- symtab_hdr
->sh_info
;
2888 hash
= ((struct elf32_hppa_link_hash_entry
*)
2889 elf_sym_hashes (input_bfd
)[e_indx
]);
2891 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
2892 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
2893 hash
= ((struct elf32_hppa_link_hash_entry
*)
2894 hash
->elf
.root
.u
.i
.link
);
2896 if (hash
->elf
.root
.type
== bfd_link_hash_defined
2897 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
2899 sym_sec
= hash
->elf
.root
.u
.def
.section
;
2900 sym_value
= hash
->elf
.root
.u
.def
.value
;
2901 if (sym_sec
->output_section
!= NULL
)
2902 destination
= (sym_value
+ irela
->r_addend
2903 + sym_sec
->output_offset
2904 + sym_sec
->output_section
->vma
);
2906 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
)
2911 else if (hash
->elf
.root
.type
== bfd_link_hash_undefined
)
2914 && !info
->no_undefined
2915 && (ELF_ST_VISIBILITY (hash
->elf
.other
)
2921 bfd_set_error (bfd_error_bad_value
);
2922 goto error_ret_free_internal
;
2926 /* Determine what (if any) linker stub is needed. */
2927 stub_type
= hppa_type_of_stub (section
, irela
, hash
,
2929 if (stub_type
== hppa_stub_none
)
2932 /* Support for grouping stub sections. */
2933 id_sec
= hplink
->stub_group
[section
->id
].link_sec
;
2935 /* Get the name of this stub. */
2936 stub_name
= hppa_stub_name (id_sec
, sym_sec
, hash
, irela
);
2938 goto error_ret_free_internal
;
2940 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
,
2943 if (stub_entry
!= NULL
)
2945 /* The proper stub has already been created. */
2950 stub_entry
= hppa_add_stub (stub_name
, section
, hplink
);
2951 if (stub_entry
== NULL
)
2954 goto error_ret_free_local
;
2957 stub_entry
->target_value
= sym_value
;
2958 stub_entry
->target_section
= sym_sec
;
2959 stub_entry
->stub_type
= stub_type
;
2962 if (stub_type
== hppa_stub_import
)
2963 stub_entry
->stub_type
= hppa_stub_import_shared
;
2964 else if (stub_type
== hppa_stub_long_branch
2965 && (LONG_BRANCH_PIC_IN_SHLIB
|| hash
== NULL
))
2966 stub_entry
->stub_type
= hppa_stub_long_branch_shared
;
2968 stub_entry
->h
= hash
;
2972 /* We're done with the internal relocs, free them. */
2973 free (internal_relocs
);
2980 /* OK, we've added some stubs. Find out the new size of the
2982 for (stub_sec
= hplink
->stub_bfd
->sections
;
2984 stub_sec
= stub_sec
->next
)
2986 stub_sec
->_raw_size
= 0;
2987 stub_sec
->_cooked_size
= 0;
2989 #if ! LONG_BRANCH_PIC_IN_SHLIB
2993 for (i
= top_id
; i
>= 0; --i
)
2995 /* This will probably hit the same section many times.. */
2996 stub_sec
= hplink
->stub_group
[i
].reloc_sec
;
2997 if (stub_sec
!= NULL
)
2999 stub_sec
->_raw_size
= 0;
3000 stub_sec
->_cooked_size
= 0;
3006 bfd_hash_traverse (&hplink
->stub_hash_table
,
3010 /* Ask the linker to do its stuff. */
3011 (*hplink
->layout_sections_again
) ();
3017 error_ret_free_local
:
3018 while (bfd_count
-- > 0)
3019 if (all_local_syms
[bfd_count
])
3020 free (all_local_syms
[bfd_count
]);
3021 free (all_local_syms
);
3026 /* For a final link, this function is called after we have sized the
3027 stubs to provide a value for __gp. */
3030 elf32_hppa_set_gp (abfd
, info
)
3032 struct bfd_link_info
*info
;
3034 struct elf32_hppa_link_hash_table
*hplink
;
3035 struct elf_link_hash_entry
*h
;
3039 hplink
= hppa_link_hash_table (info
);
3040 h
= elf_link_hash_lookup (&hplink
->root
, "$global$",
3041 false, false, false);
3044 && (h
->root
.type
== bfd_link_hash_defined
3045 || h
->root
.type
== bfd_link_hash_defweak
))
3047 gp_val
= h
->root
.u
.def
.value
;
3048 sec
= h
->root
.u
.def
.section
;
3052 /* Choose to point our LTP at, in this order, one of .plt, .got,
3053 or .data, if these sections exist. In the case of choosing
3054 .plt try to make the LTP ideal for addressing anywhere in the
3055 .plt or .got with a 14 bit signed offset. Typically, the end
3056 of the .plt is the start of the .got, so choose .plt + 0x2000
3057 if either the .plt or .got is larger than 0x2000. If both
3058 the .plt and .got are smaller than 0x2000, choose the end of
3059 the .plt section. */
3064 gp_val
= sec
->_raw_size
;
3066 || (hplink
->sgot
&& hplink
->sgot
->_raw_size
> 0x2000))
3077 /* We know we don't have a .plt. If .got is large,
3079 if (sec
->_raw_size
> 0x2000)
3084 /* No .plt or .got. Who cares what the LTP is? */
3085 sec
= bfd_get_section_by_name (abfd
, ".data");
3091 h
->root
.type
= bfd_link_hash_defined
;
3092 h
->root
.u
.def
.value
= gp_val
;
3094 h
->root
.u
.def
.section
= sec
;
3096 h
->root
.u
.def
.section
= bfd_abs_section_ptr
;
3100 if (sec
!= NULL
&& sec
->output_section
!= NULL
)
3101 gp_val
+= sec
->output_section
->vma
+ sec
->output_offset
;
3103 elf_gp (abfd
) = gp_val
;
3107 /* Build all the stubs associated with the current output file. The
3108 stubs are kept in a hash table attached to the main linker hash
3109 table. We also set up the .plt entries for statically linked PIC
3110 functions here. This function is called via hppaelf_finish in the
3114 elf32_hppa_build_stubs (info
)
3115 struct bfd_link_info
*info
;
3118 struct bfd_hash_table
*table
;
3119 struct elf32_hppa_link_hash_table
*hplink
;
3121 hplink
= hppa_link_hash_table (info
);
3123 for (stub_sec
= hplink
->stub_bfd
->sections
;
3125 stub_sec
= stub_sec
->next
)
3129 /* Allocate memory to hold the linker stubs. */
3130 size
= stub_sec
->_raw_size
;
3131 stub_sec
->contents
= (unsigned char *) bfd_zalloc (hplink
->stub_bfd
,
3133 if (stub_sec
->contents
== NULL
&& size
!= 0)
3135 stub_sec
->_raw_size
= 0;
3138 /* Build the stubs as directed by the stub hash table. */
3139 table
= &hplink
->stub_hash_table
;
3140 bfd_hash_traverse (table
, hppa_build_one_stub
, info
);
3145 /* Perform a final link. */
3148 elf32_hppa_final_link (abfd
, info
)
3150 struct bfd_link_info
*info
;
3154 /* Invoke the regular ELF garbage collecting linker to do all the
3156 if (!_bfd_elf32_gc_common_final_link (abfd
, info
))
3159 /* If we're producing a final executable, sort the contents of the
3160 unwind section. Magic section names, but this is much safer than
3161 having elf32_hppa_relocate_section remember where SEGREL32 relocs
3162 occurred. Consider what happens if someone inept creates a
3163 linker script that puts unwind information in .text. */
3164 s
= bfd_get_section_by_name (abfd
, ".PARISC.unwind");
3170 size
= s
->_raw_size
;
3171 contents
= bfd_malloc (size
);
3172 if (contents
== NULL
)
3175 if (! bfd_get_section_contents (abfd
, s
, contents
, (file_ptr
) 0, size
))
3178 qsort (contents
, size
/ 16, 16, hppa_unwind_entry_compare
);
3180 if (! bfd_set_section_contents (abfd
, s
, contents
, (file_ptr
) 0, size
))
3186 /* Record the lowest address for the data and text segments. */
3189 hppa_record_segment_addr (abfd
, section
, data
)
3190 bfd
*abfd ATTRIBUTE_UNUSED
;
3194 struct elf32_hppa_link_hash_table
*hplink
;
3196 hplink
= (struct elf32_hppa_link_hash_table
*) data
;
3198 if ((section
->flags
& (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3200 bfd_vma value
= section
->vma
- section
->filepos
;
3202 if ((section
->flags
& SEC_READONLY
) != 0)
3204 if (value
< hplink
->text_segment_base
)
3205 hplink
->text_segment_base
= value
;
3209 if (value
< hplink
->data_segment_base
)
3210 hplink
->data_segment_base
= value
;
3215 /* Perform a relocation as part of a final link. */
3217 static bfd_reloc_status_type
3218 final_link_relocate (input_section
, contents
, rel
, value
, hplink
, sym_sec
, h
)
3219 asection
*input_section
;
3221 const Elf_Internal_Rela
*rel
;
3223 struct elf32_hppa_link_hash_table
*hplink
;
3225 struct elf32_hppa_link_hash_entry
*h
;
3228 unsigned int r_type
= ELF32_R_TYPE (rel
->r_info
);
3229 reloc_howto_type
*howto
= elf_hppa_howto_table
+ r_type
;
3230 int r_format
= howto
->bitsize
;
3231 enum hppa_reloc_field_selector_type_alt r_field
;
3232 bfd
*input_bfd
= input_section
->owner
;
3233 bfd_vma offset
= rel
->r_offset
;
3234 bfd_vma max_branch_offset
= 0;
3235 bfd_byte
*hit_data
= contents
+ offset
;
3236 bfd_signed_vma addend
= rel
->r_addend
;
3238 struct elf32_hppa_stub_hash_entry
*stub_entry
= NULL
;
3241 if (r_type
== R_PARISC_NONE
)
3242 return bfd_reloc_ok
;
3244 insn
= bfd_get_32 (input_bfd
, hit_data
);
3246 /* Find out where we are and where we're going. */
3247 location
= (offset
+
3248 input_section
->output_offset
+
3249 input_section
->output_section
->vma
);
3253 case R_PARISC_PCREL12F
:
3254 case R_PARISC_PCREL17F
:
3255 case R_PARISC_PCREL22F
:
3256 /* If this is a call to a function defined in another dynamic
3257 library, or if it is a call to a PIC function in the same
3258 object, or if this is a shared link and it is a call to a
3259 weak symbol which may or may not be in the same object, then
3260 find the import stub in the stub hash. */
3262 || sym_sec
->output_section
== NULL
3264 && ((h
->maybe_pic_call
3265 && !(input_section
->flags
& SEC_HAS_GOT_REF
))
3266 || (h
->elf
.root
.type
== bfd_link_hash_defweak
3267 && h
->elf
.dynindx
!= -1
3268 && h
->elf
.plt
.offset
!= (bfd_vma
) -1))))
3270 stub_entry
= hppa_get_stub_entry (input_section
, sym_sec
,
3272 if (stub_entry
!= NULL
)
3274 value
= (stub_entry
->stub_offset
3275 + stub_entry
->stub_sec
->output_offset
3276 + stub_entry
->stub_sec
->output_section
->vma
);
3279 else if (sym_sec
== NULL
&& h
!= NULL
3280 && h
->elf
.root
.type
== bfd_link_hash_undefweak
)
3282 /* It's OK if undefined weak. Calls to undefined weak
3283 symbols behave as if the "called" function
3284 immediately returns. We can thus call to a weak
3285 function without first checking whether the function
3291 return bfd_reloc_notsupported
;
3295 case R_PARISC_PCREL21L
:
3296 case R_PARISC_PCREL17C
:
3297 case R_PARISC_PCREL17R
:
3298 case R_PARISC_PCREL14R
:
3299 case R_PARISC_PCREL14F
:
3300 /* Make it a pc relative offset. */
3305 case R_PARISC_DPREL21L
:
3306 case R_PARISC_DPREL14R
:
3307 case R_PARISC_DPREL14F
:
3308 /* For all the DP relative relocations, we need to examine the symbol's
3309 section. If it's a code section, then "data pointer relative" makes
3310 no sense. In that case we don't adjust the "value", and for 21 bit
3311 addil instructions, we change the source addend register from %dp to
3312 %r0. This situation commonly arises when a variable's "constness"
3313 is declared differently from the way the variable is defined. For
3314 instance: "extern int foo" with foo defined as "const int foo". */
3315 if (sym_sec
== NULL
)
3317 if ((sym_sec
->flags
& SEC_CODE
) != 0)
3319 if ((insn
& ((0x3f << 26) | (0x1f << 21)))
3320 == (((int) OP_ADDIL
<< 26) | (27 << 21)))
3322 insn
&= ~ (0x1f << 21);
3323 #if 1 /* debug them. */
3324 (*_bfd_error_handler
)
3325 (_("%s(%s+0x%lx): fixing %s"),
3326 bfd_get_filename (input_bfd
),
3327 input_section
->name
,
3328 (long) rel
->r_offset
,
3332 /* Now try to make things easy for the dynamic linker. */
3338 case R_PARISC_DLTIND21L
:
3339 case R_PARISC_DLTIND14R
:
3340 case R_PARISC_DLTIND14F
:
3341 value
-= elf_gp (input_section
->output_section
->owner
);
3344 case R_PARISC_SEGREL32
:
3345 if ((sym_sec
->flags
& SEC_CODE
) != 0)
3346 value
-= hplink
->text_segment_base
;
3348 value
-= hplink
->data_segment_base
;
3357 case R_PARISC_DIR32
:
3358 case R_PARISC_DIR14F
:
3359 case R_PARISC_DIR17F
:
3360 case R_PARISC_PCREL17C
:
3361 case R_PARISC_PCREL14F
:
3362 case R_PARISC_DPREL14F
:
3363 case R_PARISC_PLABEL32
:
3364 case R_PARISC_DLTIND14F
:
3365 case R_PARISC_SEGBASE
:
3366 case R_PARISC_SEGREL32
:
3370 case R_PARISC_DIR21L
:
3371 case R_PARISC_PCREL21L
:
3372 case R_PARISC_DPREL21L
:
3373 case R_PARISC_PLABEL21L
:
3374 case R_PARISC_DLTIND21L
:
3378 case R_PARISC_DIR17R
:
3379 case R_PARISC_PCREL17R
:
3380 case R_PARISC_DIR14R
:
3381 case R_PARISC_PCREL14R
:
3382 case R_PARISC_DPREL14R
:
3383 case R_PARISC_PLABEL14R
:
3384 case R_PARISC_DLTIND14R
:
3388 case R_PARISC_PCREL12F
:
3389 case R_PARISC_PCREL17F
:
3390 case R_PARISC_PCREL22F
:
3393 if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
3395 max_branch_offset
= (1 << (17-1)) << 2;
3397 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
3399 max_branch_offset
= (1 << (12-1)) << 2;
3403 max_branch_offset
= (1 << (22-1)) << 2;
3406 /* sym_sec is NULL on undefined weak syms or when shared on
3407 undefined syms. We've already checked for a stub for the
3408 shared undefined case. */
3409 if (sym_sec
== NULL
)
3412 /* If the branch is out of reach, then redirect the
3413 call to the local stub for this function. */
3414 if (value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3416 stub_entry
= hppa_get_stub_entry (input_section
, sym_sec
,
3418 if (stub_entry
== NULL
)
3419 return bfd_reloc_notsupported
;
3421 /* Munge up the value and addend so that we call the stub
3422 rather than the procedure directly. */
3423 value
= (stub_entry
->stub_offset
3424 + stub_entry
->stub_sec
->output_offset
3425 + stub_entry
->stub_sec
->output_section
->vma
3431 /* Something we don't know how to handle. */
3433 return bfd_reloc_notsupported
;
3436 /* Make sure we can reach the stub. */
3437 if (max_branch_offset
!= 0
3438 && value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3440 (*_bfd_error_handler
)
3441 (_("%s(%s+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
3442 bfd_get_filename (input_bfd
),
3443 input_section
->name
,
3444 (long) rel
->r_offset
,
3445 stub_entry
->root
.string
);
3446 return bfd_reloc_notsupported
;
3449 val
= hppa_field_adjust (value
, addend
, r_field
);
3453 case R_PARISC_PCREL12F
:
3454 case R_PARISC_PCREL17C
:
3455 case R_PARISC_PCREL17F
:
3456 case R_PARISC_PCREL17R
:
3457 case R_PARISC_PCREL22F
:
3458 case R_PARISC_DIR17F
:
3459 case R_PARISC_DIR17R
:
3460 /* This is a branch. Divide the offset by four.
3461 Note that we need to decide whether it's a branch or
3462 otherwise by inspecting the reloc. Inspecting insn won't
3463 work as insn might be from a .word directive. */
3471 insn
= hppa_rebuild_insn (insn
, val
, r_format
);
3473 /* Update the instruction word. */
3474 bfd_put_32 (input_bfd
, (bfd_vma
) insn
, hit_data
);
3475 return bfd_reloc_ok
;
3478 /* Relocate an HPPA ELF section. */
3481 elf32_hppa_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
3482 contents
, relocs
, local_syms
, local_sections
)
3484 struct bfd_link_info
*info
;
3486 asection
*input_section
;
3488 Elf_Internal_Rela
*relocs
;
3489 Elf_Internal_Sym
*local_syms
;
3490 asection
**local_sections
;
3493 bfd_vma
*local_got_offsets
;
3494 struct elf32_hppa_link_hash_table
*hplink
;
3495 Elf_Internal_Shdr
*symtab_hdr
;
3496 Elf_Internal_Rela
*rel
;
3497 Elf_Internal_Rela
*relend
;
3500 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3502 hplink
= hppa_link_hash_table (info
);
3503 dynobj
= hplink
->root
.dynobj
;
3504 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3508 relend
= relocs
+ input_section
->reloc_count
;
3509 for (; rel
< relend
; rel
++)
3511 unsigned int r_type
;
3512 reloc_howto_type
*howto
;
3513 unsigned int r_symndx
;
3514 struct elf32_hppa_link_hash_entry
*h
;
3515 Elf_Internal_Sym
*sym
;
3518 bfd_reloc_status_type r
;
3519 const char *sym_name
;
3522 r_type
= ELF32_R_TYPE (rel
->r_info
);
3523 if (r_type
>= (unsigned int) R_PARISC_UNIMPLEMENTED
)
3525 bfd_set_error (bfd_error_bad_value
);
3528 if (r_type
== (unsigned int) R_PARISC_GNU_VTENTRY
3529 || r_type
== (unsigned int) R_PARISC_GNU_VTINHERIT
)
3532 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3534 if (info
->relocateable
)
3536 /* This is a relocateable link. We don't have to change
3537 anything, unless the reloc is against a section symbol,
3538 in which case we have to adjust according to where the
3539 section symbol winds up in the output section. */
3540 if (r_symndx
< symtab_hdr
->sh_info
)
3542 sym
= local_syms
+ r_symndx
;
3543 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
3545 sym_sec
= local_sections
[r_symndx
];
3546 rel
->r_addend
+= sym_sec
->output_offset
;
3552 /* This is a final link. */
3556 if (r_symndx
< symtab_hdr
->sh_info
)
3558 /* This is a local symbol, h defaults to NULL. */
3559 sym
= local_syms
+ r_symndx
;
3560 sym_sec
= local_sections
[r_symndx
];
3561 relocation
= ((ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
3562 ? 0 : sym
->st_value
)
3563 + sym_sec
->output_offset
3564 + sym_sec
->output_section
->vma
);
3570 /* It's a global; Find its entry in the link hash. */
3571 indx
= r_symndx
- symtab_hdr
->sh_info
;
3572 h
= ((struct elf32_hppa_link_hash_entry
*)
3573 elf_sym_hashes (input_bfd
)[indx
]);
3574 while (h
->elf
.root
.type
== bfd_link_hash_indirect
3575 || h
->elf
.root
.type
== bfd_link_hash_warning
)
3576 h
= (struct elf32_hppa_link_hash_entry
*) h
->elf
.root
.u
.i
.link
;
3579 if (h
->elf
.root
.type
== bfd_link_hash_defined
3580 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
3582 sym_sec
= h
->elf
.root
.u
.def
.section
;
3583 /* If sym_sec->output_section is NULL, then it's a
3584 symbol defined in a shared library. */
3585 if (sym_sec
->output_section
!= NULL
)
3586 relocation
= (h
->elf
.root
.u
.def
.value
3587 + sym_sec
->output_offset
3588 + sym_sec
->output_section
->vma
);
3590 else if (h
->elf
.root
.type
== bfd_link_hash_undefweak
)
3592 else if (info
->shared
&& !info
->no_undefined
3593 && ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
)
3596 if (!((*info
->callbacks
->undefined_symbol
)
3597 (info
, h
->elf
.root
.root
.string
, input_bfd
,
3598 input_section
, rel
->r_offset
, false)))
3603 if (!((*info
->callbacks
->undefined_symbol
)
3604 (info
, h
->elf
.root
.root
.string
, input_bfd
,
3605 input_section
, rel
->r_offset
, true)))
3610 /* Do any required modifications to the relocation value, and
3611 determine what types of dynamic info we need to output, if
3616 case R_PARISC_DLTIND14F
:
3617 case R_PARISC_DLTIND14R
:
3618 case R_PARISC_DLTIND21L
:
3619 /* Relocation is to the entry for this symbol in the global
3625 off
= h
->elf
.got
.offset
;
3626 BFD_ASSERT (off
!= (bfd_vma
) -1);
3628 if (! hplink
->root
.dynamic_sections_created
3630 && (info
->symbolic
|| h
->elf
.dynindx
== -1)
3631 && (h
->elf
.elf_link_hash_flags
3632 & ELF_LINK_HASH_DEF_REGULAR
) != 0))
3634 /* This is actually a static link, or it is a
3635 -Bsymbolic link and the symbol is defined
3636 locally, or the symbol was forced to be local
3637 because of a version file. We must initialize
3638 this entry in the global offset table. Since the
3639 offset must always be a multiple of 4, we use the
3640 least significant bit to record whether we have
3641 initialized it already.
3643 When doing a dynamic link, we create a .rela.got
3644 relocation entry to initialize the value. This
3645 is done in the finish_dynamic_symbol routine. */
3650 bfd_put_32 (output_bfd
, relocation
,
3651 hplink
->sgot
->contents
+ off
);
3652 h
->elf
.got
.offset
|= 1;
3660 /* Local symbol case. */
3663 BFD_ASSERT (local_got_offsets
!= NULL
3664 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
3666 off
= local_got_offsets
[r_symndx
];
3668 /* The offset must always be a multiple of 4. We use
3669 the least significant bit to record whether we have
3670 already generated the necessary reloc. */
3675 bfd_put_32 (output_bfd
, relocation
,
3676 hplink
->sgot
->contents
+ off
);
3680 /* Output a dynamic *ABS* relocation for this
3681 GOT entry. In this case it is relative to
3682 the base of the object because the symbol
3684 Elf_Internal_Rela outrel
;
3685 asection
*srelgot
= hplink
->srelgot
;
3687 outrel
.r_offset
= (off
3688 + hplink
->sgot
->output_offset
3689 + hplink
->sgot
->output_section
->vma
);
3690 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_DIR32
);
3691 outrel
.r_addend
= relocation
;
3692 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3693 ((Elf32_External_Rela
*)
3695 + srelgot
->reloc_count
));
3696 ++srelgot
->reloc_count
;
3699 local_got_offsets
[r_symndx
] |= 1;
3705 /* Add the base of the GOT to the relocation value. */
3706 relocation
+= (hplink
->sgot
->output_offset
3707 + hplink
->sgot
->output_section
->vma
);
3710 case R_PARISC_SEGREL32
:
3711 /* If this is the first SEGREL relocation, then initialize
3712 the segment base values. */
3713 if (hplink
->text_segment_base
== (bfd_vma
) -1)
3714 bfd_map_over_sections (output_bfd
,
3715 hppa_record_segment_addr
,
3719 case R_PARISC_PLABEL14R
:
3720 case R_PARISC_PLABEL21L
:
3721 case R_PARISC_PLABEL32
:
3722 if (hplink
->root
.dynamic_sections_created
)
3726 /* If we have a global symbol with a PLT slot, then
3727 redirect this relocation to it. */
3730 off
= h
->elf
.plt
.offset
;
3736 indx
= r_symndx
+ symtab_hdr
->sh_info
;
3737 off
= local_got_offsets
[indx
];
3739 /* As for the local .got entry case, we use the last
3740 bit to record whether we've already initialised
3741 this local .plt entry. */
3746 bfd_put_32 (output_bfd
,
3748 hplink
->splt
->contents
+ off
);
3749 bfd_put_32 (output_bfd
,
3750 elf_gp (hplink
->splt
->output_section
->owner
),
3751 hplink
->splt
->contents
+ off
+ 4);
3755 /* Output a dynamic IPLT relocation for this
3757 Elf_Internal_Rela outrel
;
3758 asection
*srelplt
= hplink
->srelplt
;
3760 outrel
.r_offset
= (off
3761 + hplink
->splt
->output_offset
3762 + hplink
->splt
->output_section
->vma
);
3763 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_IPLT
);
3764 outrel
.r_addend
= relocation
;
3765 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3766 ((Elf32_External_Rela
*)
3768 + srelplt
->reloc_count
));
3769 ++srelplt
->reloc_count
;
3772 local_got_offsets
[indx
] |= 1;
3776 BFD_ASSERT (off
< (bfd_vma
) -2);
3778 /* PLABELs contain function pointers. Relocation is to
3779 the entry for the function in the .plt. The magic +2
3780 offset signals to $$dyncall that the function pointer
3781 is in the .plt and thus has a gp pointer too.
3782 Exception: Undefined PLABELs should have a value of
3785 || (h
->elf
.root
.type
!= bfd_link_hash_undefweak
3786 && h
->elf
.root
.type
!= bfd_link_hash_undefined
))
3789 + hplink
->splt
->output_offset
3790 + hplink
->splt
->output_section
->vma
3795 /* Fall through and possibly emit a dynamic relocation. */
3797 case R_PARISC_DIR17F
:
3798 case R_PARISC_DIR17R
:
3799 case R_PARISC_DIR14F
:
3800 case R_PARISC_DIR14R
:
3801 case R_PARISC_DIR21L
:
3802 case R_PARISC_DPREL14F
:
3803 case R_PARISC_DPREL14R
:
3804 case R_PARISC_DPREL21L
:
3805 case R_PARISC_DIR32
:
3806 /* The reloc types handled here and this conditional
3807 expression must match the code in check_relocs and
3808 hppa_discard_copies. ie. We need exactly the same
3809 condition as in check_relocs, with some extra conditions
3810 (dynindx test in this case) to cater for relocs removed
3811 by hppa_discard_copies. */
3812 if ((input_section
->flags
& SEC_ALLOC
) != 0
3814 #if RELATIVE_DYNAMIC_RELOCS
3815 && (is_absolute_reloc (r_type
)
3816 || ((!info
->symbolic
3818 && ((h
->elf
.elf_link_hash_flags
3819 & ELF_LINK_HASH_DEF_REGULAR
) == 0
3820 || h
->elf
.root
.type
== bfd_link_hash_defweak
)))
3821 && (h
== NULL
|| h
->elf
.dynindx
!= -1)))
3825 Elf_Internal_Rela outrel
;
3828 /* When generating a shared object, these relocations
3829 are copied into the output file to be resolved at run
3836 name
= (bfd_elf_string_from_elf_section
3838 elf_elfheader (input_bfd
)->e_shstrndx
,
3839 elf_section_data (input_section
)->rel_hdr
.sh_name
));
3842 sreloc
= bfd_get_section_by_name (dynobj
, name
);
3843 BFD_ASSERT (sreloc
!= NULL
);
3846 outrel
.r_offset
= rel
->r_offset
;
3847 outrel
.r_addend
= rel
->r_addend
;
3849 if (elf_section_data (input_section
)->stab_info
!= NULL
)
3853 off
= (_bfd_stab_section_offset
3854 (output_bfd
, &hplink
->root
.stab_info
,
3856 &elf_section_data (input_section
)->stab_info
,
3858 if (off
== (bfd_vma
) -1)
3860 outrel
.r_offset
= off
;
3863 outrel
.r_offset
+= (input_section
->output_offset
3864 + input_section
->output_section
->vma
);
3868 memset (&outrel
, 0, sizeof (outrel
));
3871 && h
->elf
.dynindx
!= -1
3874 || (h
->elf
.elf_link_hash_flags
3875 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
3877 outrel
.r_info
= ELF32_R_INFO (h
->elf
.dynindx
, r_type
);
3879 else /* It's a local symbol, or one marked to become local. */
3883 /* Add the absolute offset of the symbol. */
3884 outrel
.r_addend
+= relocation
;
3886 /* Global plabels need to be processed by the
3887 dynamic linker so that functions have at most one
3888 fptr. For this reason, we need to differentiate
3889 between global and local plabels, which we do by
3890 providing the function symbol for a global plabel
3891 reloc, and no symbol for local plabels. */
3894 && sym_sec
->output_section
!= NULL
3895 && ! bfd_is_abs_section (sym_sec
))
3897 indx
= elf_section_data (sym_sec
->output_section
)->dynindx
;
3898 /* We are turning this relocation into one
3899 against a section symbol, so subtract out the
3900 output section's address but not the offset
3901 of the input section in the output section. */
3902 outrel
.r_addend
-= sym_sec
->output_section
->vma
;
3905 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
3908 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3909 ((Elf32_External_Rela
*)
3911 + sreloc
->reloc_count
));
3912 ++sreloc
->reloc_count
;
3920 r
= final_link_relocate (input_section
, contents
, rel
, relocation
,
3921 hplink
, sym_sec
, h
);
3923 if (r
== bfd_reloc_ok
)
3927 sym_name
= h
->elf
.root
.root
.string
;
3930 sym_name
= bfd_elf_string_from_elf_section (input_bfd
,
3931 symtab_hdr
->sh_link
,
3933 if (sym_name
== NULL
)
3935 if (*sym_name
== '\0')
3936 sym_name
= bfd_section_name (input_bfd
, sym_sec
);
3939 howto
= elf_hppa_howto_table
+ r_type
;
3941 if (r
== bfd_reloc_undefined
|| r
== bfd_reloc_notsupported
)
3943 (*_bfd_error_handler
)
3944 (_("%s(%s+0x%lx): cannot handle %s for %s"),
3945 bfd_get_filename (input_bfd
),
3946 input_section
->name
,
3947 (long) rel
->r_offset
,
3953 if (!((*info
->callbacks
->reloc_overflow
)
3954 (info
, sym_name
, howto
->name
, (bfd_vma
) 0,
3955 input_bfd
, input_section
, rel
->r_offset
)))
3963 /* Comparison function for qsort to sort unwind section during a
3967 hppa_unwind_entry_compare (a
, b
)
3971 const bfd_byte
*ap
, *bp
;
3972 unsigned long av
, bv
;
3974 ap
= (const bfd_byte
*) a
;
3975 av
= (unsigned long) ap
[0] << 24;
3976 av
|= (unsigned long) ap
[1] << 16;
3977 av
|= (unsigned long) ap
[2] << 8;
3978 av
|= (unsigned long) ap
[3];
3980 bp
= (const bfd_byte
*) b
;
3981 bv
= (unsigned long) bp
[0] << 24;
3982 bv
|= (unsigned long) bp
[1] << 16;
3983 bv
|= (unsigned long) bp
[2] << 8;
3984 bv
|= (unsigned long) bp
[3];
3986 return av
< bv
? -1 : av
> bv
? 1 : 0;
3989 /* Finish up dynamic symbol handling. We set the contents of various
3990 dynamic sections here. */
3993 elf32_hppa_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
3995 struct bfd_link_info
*info
;
3996 struct elf_link_hash_entry
*h
;
3997 Elf_Internal_Sym
*sym
;
3999 struct elf32_hppa_link_hash_table
*hplink
;
4002 hplink
= hppa_link_hash_table (info
);
4003 dynobj
= hplink
->root
.dynobj
;
4005 if (h
->plt
.offset
!= (bfd_vma
) -1)
4009 /* This symbol has an entry in the procedure linkage table. Set
4012 The format of a plt entry is
4017 if (h
->root
.type
== bfd_link_hash_defined
4018 || h
->root
.type
== bfd_link_hash_defweak
)
4020 value
= h
->root
.u
.def
.value
;
4021 if (h
->root
.u
.def
.section
->output_section
!= NULL
)
4022 value
+= (h
->root
.u
.def
.section
->output_offset
4023 + h
->root
.u
.def
.section
->output_section
->vma
);
4026 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
)
4028 Elf_Internal_Rela rel
;
4030 /* Create a dynamic IPLT relocation for this entry. */
4031 rel
.r_offset
= (h
->plt
.offset
4032 + hplink
->splt
->output_offset
4033 + hplink
->splt
->output_section
->vma
);
4034 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->plt_abs
4035 && h
->dynindx
!= -1)
4037 /* To support lazy linking, the function pointer is
4038 initialised to point to a special stub stored at the
4039 end of the .plt. This is only done for plt entries
4040 with a non-*ABS* dynamic relocation. */
4041 value
= (hplink
->splt
->output_offset
4042 + hplink
->splt
->output_section
->vma
4043 + hplink
->splt
->_raw_size
4046 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_IPLT
);
4051 /* This symbol has been marked to become local, and is
4052 used by a plabel so must be kept in the .plt. */
4053 rel
.r_info
= ELF32_R_INFO (0, R_PARISC_IPLT
);
4054 rel
.r_addend
= value
;
4057 bfd_elf32_swap_reloca_out (hplink
->splt
->output_section
->owner
,
4059 ((Elf32_External_Rela
*)
4060 hplink
->srelplt
->contents
4061 + hplink
->srelplt
->reloc_count
));
4062 hplink
->srelplt
->reloc_count
++;
4065 bfd_put_32 (hplink
->splt
->owner
,
4067 hplink
->splt
->contents
+ h
->plt
.offset
);
4068 bfd_put_32 (hplink
->splt
->owner
,
4069 elf_gp (hplink
->splt
->output_section
->owner
),
4070 hplink
->splt
->contents
+ h
->plt
.offset
+ 4);
4071 if (PLABEL_PLT_ENTRY_SIZE
!= PLT_ENTRY_SIZE
4072 && ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
4073 && h
->dynindx
!= -1)
4075 memset (hplink
->splt
->contents
+ h
->plt
.offset
+ 8,
4076 0, PLABEL_PLT_ENTRY_SIZE
- PLT_ENTRY_SIZE
);
4079 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4081 /* Mark the symbol as undefined, rather than as defined in
4082 the .plt section. Leave the value alone. */
4083 sym
->st_shndx
= SHN_UNDEF
;
4087 if (h
->got
.offset
!= (bfd_vma
) -1)
4089 Elf_Internal_Rela rel
;
4091 /* This symbol has an entry in the global offset table. Set it
4094 rel
.r_offset
= ((h
->got
.offset
&~ (bfd_vma
) 1)
4095 + hplink
->sgot
->output_offset
4096 + hplink
->sgot
->output_section
->vma
);
4098 /* If this is a static link, or it is a -Bsymbolic link and the
4099 symbol is defined locally or was forced to be local because
4100 of a version file, we just want to emit a RELATIVE reloc.
4101 The entry in the global offset table will already have been
4102 initialized in the relocate_section function. */
4103 if (! hplink
->root
.dynamic_sections_created
4105 && (info
->symbolic
|| h
->dynindx
== -1)
4106 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
4108 rel
.r_info
= ELF32_R_INFO (0, R_PARISC_DIR32
);
4109 rel
.r_addend
= (h
->root
.u
.def
.value
4110 + h
->root
.u
.def
.section
->output_offset
4111 + h
->root
.u
.def
.section
->output_section
->vma
);
4115 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4116 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
4117 hplink
->sgot
->contents
+ h
->got
.offset
);
4118 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_DIR32
);
4122 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
4123 ((Elf32_External_Rela
*)
4124 hplink
->srelgot
->contents
4125 + hplink
->srelgot
->reloc_count
));
4126 ++hplink
->srelgot
->reloc_count
;
4129 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
4132 Elf_Internal_Rela rel
;
4134 /* This symbol needs a copy reloc. Set it up. */
4136 BFD_ASSERT (h
->dynindx
!= -1
4137 && (h
->root
.type
== bfd_link_hash_defined
4138 || h
->root
.type
== bfd_link_hash_defweak
));
4140 s
= hplink
->srelbss
;
4142 rel
.r_offset
= (h
->root
.u
.def
.value
4143 + h
->root
.u
.def
.section
->output_offset
4144 + h
->root
.u
.def
.section
->output_section
->vma
);
4146 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_COPY
);
4147 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
4148 ((Elf32_External_Rela
*) s
->contents
4153 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
4154 if (h
->root
.root
.string
[0] == '_'
4155 && (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4156 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0))
4158 sym
->st_shndx
= SHN_ABS
;
4164 /* Finish up the dynamic sections. */
4167 elf32_hppa_finish_dynamic_sections (output_bfd
, info
)
4169 struct bfd_link_info
*info
;
4172 struct elf32_hppa_link_hash_table
*hplink
;
4175 hplink
= hppa_link_hash_table (info
);
4176 dynobj
= hplink
->root
.dynobj
;
4178 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4180 if (hplink
->root
.dynamic_sections_created
)
4182 Elf32_External_Dyn
*dyncon
, *dynconend
;
4184 BFD_ASSERT (sdyn
!= NULL
);
4186 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4187 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
4188 for (; dyncon
< dynconend
; dyncon
++)
4190 Elf_Internal_Dyn dyn
;
4193 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4201 /* Use PLTGOT to set the GOT register. */
4202 dyn
.d_un
.d_ptr
= elf_gp (output_bfd
);
4203 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4207 s
= hplink
->srelplt
;
4208 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4209 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4213 s
= hplink
->srelplt
;
4214 if (s
->_cooked_size
!= 0)
4215 dyn
.d_un
.d_val
= s
->_cooked_size
;
4217 dyn
.d_un
.d_val
= s
->_raw_size
;
4218 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4224 if (hplink
->sgot
->_raw_size
!= 0)
4226 /* Fill in the first entry in the global offset table.
4227 We use it to point to our dynamic section, if we have one. */
4228 bfd_put_32 (output_bfd
,
4230 ? sdyn
->output_section
->vma
+ sdyn
->output_offset
4232 hplink
->sgot
->contents
);
4234 /* The second entry is reserved for use by the dynamic linker. */
4235 memset (hplink
->sgot
->contents
+ GOT_ENTRY_SIZE
, 0, GOT_ENTRY_SIZE
);
4237 /* Set .got entry size. */
4238 elf_section_data (hplink
->sgot
->output_section
)
4239 ->this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
4242 if (hplink
->splt
->_raw_size
!= 0)
4244 /* Set plt entry size. */
4245 elf_section_data (hplink
->splt
->output_section
)
4246 ->this_hdr
.sh_entsize
= PLT_ENTRY_SIZE
;
4248 if (hplink
->need_plt_stub
)
4250 /* Set up the .plt stub. */
4251 memcpy (hplink
->splt
->contents
4252 + hplink
->splt
->_raw_size
- sizeof (plt_stub
),
4253 plt_stub
, sizeof (plt_stub
));
4255 if ((hplink
->splt
->output_offset
4256 + hplink
->splt
->output_section
->vma
4257 + hplink
->splt
->_raw_size
)
4258 != (hplink
->sgot
->output_offset
4259 + hplink
->sgot
->output_section
->vma
))
4261 (*_bfd_error_handler
)
4262 (_(".got section not immediately after .plt section"));
4271 /* Tweak the OSABI field of the elf header. */
4274 elf32_hppa_post_process_headers (abfd
, link_info
)
4276 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
;
4278 Elf_Internal_Ehdr
* i_ehdrp
;
4280 i_ehdrp
= elf_elfheader (abfd
);
4282 if (strcmp (bfd_get_target (abfd
), "elf32-hppa-linux") == 0)
4284 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_LINUX
;
4288 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_HPUX
;
4292 /* Called when writing out an object file to decide the type of a
4295 elf32_hppa_elf_get_symbol_type (elf_sym
, type
)
4296 Elf_Internal_Sym
*elf_sym
;
4299 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_PARISC_MILLI
)
4300 return STT_PARISC_MILLI
;
4305 /* Misc BFD support code. */
4306 #define bfd_elf32_bfd_is_local_label_name elf_hppa_is_local_label_name
4307 #define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
4308 #define elf_info_to_howto elf_hppa_info_to_howto
4309 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
4311 /* Stuff for the BFD linker. */
4312 #define bfd_elf32_bfd_final_link elf32_hppa_final_link
4313 #define bfd_elf32_bfd_link_hash_table_create elf32_hppa_link_hash_table_create
4314 #define elf_backend_add_symbol_hook elf32_hppa_add_symbol_hook
4315 #define elf_backend_adjust_dynamic_symbol elf32_hppa_adjust_dynamic_symbol
4316 #define elf_backend_check_relocs elf32_hppa_check_relocs
4317 #define elf_backend_create_dynamic_sections elf32_hppa_create_dynamic_sections
4318 #define elf_backend_fake_sections elf_hppa_fake_sections
4319 #define elf_backend_relocate_section elf32_hppa_relocate_section
4320 #define elf_backend_hide_symbol elf32_hppa_hide_symbol
4321 #define elf_backend_finish_dynamic_symbol elf32_hppa_finish_dynamic_symbol
4322 #define elf_backend_finish_dynamic_sections elf32_hppa_finish_dynamic_sections
4323 #define elf_backend_size_dynamic_sections elf32_hppa_size_dynamic_sections
4324 #define elf_backend_gc_mark_hook elf32_hppa_gc_mark_hook
4325 #define elf_backend_gc_sweep_hook elf32_hppa_gc_sweep_hook
4326 #define elf_backend_object_p elf32_hppa_object_p
4327 #define elf_backend_final_write_processing elf_hppa_final_write_processing
4328 #define elf_backend_post_process_headers elf32_hppa_post_process_headers
4329 #define elf_backend_get_symbol_type elf32_hppa_elf_get_symbol_type
4331 #define elf_backend_can_gc_sections 1
4332 #define elf_backend_plt_alignment 2
4333 #define elf_backend_want_got_plt 0
4334 #define elf_backend_plt_readonly 0
4335 #define elf_backend_want_plt_sym 0
4336 #define elf_backend_got_header_size 8
4338 #define TARGET_BIG_SYM bfd_elf32_hppa_vec
4339 #define TARGET_BIG_NAME "elf32-hppa"
4340 #define ELF_ARCH bfd_arch_hppa
4341 #define ELF_MACHINE_CODE EM_PARISC
4342 #define ELF_MAXPAGESIZE 0x1000
4344 #include "elf32-target.h"
4346 #undef TARGET_BIG_SYM
4347 #define TARGET_BIG_SYM bfd_elf32_hppa_linux_vec
4348 #undef TARGET_BIG_NAME
4349 #define TARGET_BIG_NAME "elf32-hppa-linux"
4351 #define INCLUDED_TARGET_FILE 1
4352 #include "elf32-target.h"