1 /* BFD back-end for HP PA-RISC ELF files.
2 Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97, 98, 99, 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 L'X - ($PIC_pcrel$0 - 4),%r1
68 : be,n R'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 L'lt_ptr+ltoff,%dp ; get procedure entry point
73 : ldw R'lt_ptr+ltoff(%r1),%r21
75 : ldw R'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 L'ltoff,%r19 ; get procedure entry point
80 : ldw R'ltoff(%r1),%r21
82 : ldw R'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 L'lt_ptr+ltoff,%dp ; get procedure entry point
87 : ldw R'lt_ptr+ltoff(%r1),%r21
88 : ldw R'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 L'ltoff,%r19 ; get procedure entry point
97 : ldw R'ltoff(%r1),%r21
98 : ldw R'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 pic_call
:1;
230 /* Set if this symbol is used by a plabel reloc. */
231 unsigned int plabel
:1;
233 /* Set if this symbol is an init or fini function and thus should
234 use an absolute reloc. */
235 unsigned int plt_abs
:1;
238 struct elf32_hppa_link_hash_table
{
240 /* The main hash table. */
241 struct elf_link_hash_table root
;
243 /* The stub hash table. */
244 struct bfd_hash_table stub_hash_table
;
246 /* Linker stub bfd. */
249 /* Linker call-backs. */
250 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
251 void (*layout_sections_again
) PARAMS ((void));
253 /* Array to keep track of which stub sections have been created, and
254 information on stub grouping. */
256 /* This is the section to which stubs in the group will be
259 /* The stub section. */
261 #if ! LONG_BRANCH_PIC_IN_SHLIB
262 /* The stub section's reloc section. */
267 /* Short-cuts to get to dynamic linker sections. */
275 /* Whether we support multiple sub-spaces for shared libs. */
276 unsigned int multi_subspace
:1;
278 /* Flags set when PCREL12F and PCREL17F branches detected. Used to
279 select suitable defaults for the stub group size. */
280 unsigned int has_12bit_branch
:1;
281 unsigned int has_17bit_branch
:1;
283 /* Set if we need a .plt stub to support lazy dynamic linking. */
284 unsigned int need_plt_stub
:1;
287 /* Various hash macros and functions. */
288 #define hppa_link_hash_table(p) \
289 ((struct elf32_hppa_link_hash_table *) ((p)->hash))
291 #define hppa_stub_hash_lookup(table, string, create, copy) \
292 ((struct elf32_hppa_stub_hash_entry *) \
293 bfd_hash_lookup ((table), (string), (create), (copy)))
295 static struct bfd_hash_entry
*stub_hash_newfunc
296 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
298 static struct bfd_hash_entry
*hppa_link_hash_newfunc
299 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
301 static struct bfd_link_hash_table
*elf32_hppa_link_hash_table_create
304 /* Stub handling functions. */
305 static char *hppa_stub_name
306 PARAMS ((const asection
*, const asection
*,
307 const struct elf32_hppa_link_hash_entry
*,
308 const Elf_Internal_Rela
*));
310 static struct elf32_hppa_stub_hash_entry
*hppa_get_stub_entry
311 PARAMS ((const asection
*, const asection
*,
312 struct elf32_hppa_link_hash_entry
*,
313 const Elf_Internal_Rela
*,
314 struct elf32_hppa_link_hash_table
*));
316 static struct elf32_hppa_stub_hash_entry
*hppa_add_stub
317 PARAMS ((const char *, asection
*, struct elf32_hppa_link_hash_table
*));
319 static enum elf32_hppa_stub_type hppa_type_of_stub
320 PARAMS ((asection
*, const Elf_Internal_Rela
*,
321 struct elf32_hppa_link_hash_entry
*, bfd_vma
));
323 static boolean hppa_build_one_stub
324 PARAMS ((struct bfd_hash_entry
*, PTR
));
326 static boolean hppa_size_one_stub
327 PARAMS ((struct bfd_hash_entry
*, PTR
));
329 /* BFD and elf backend functions. */
330 static boolean elf32_hppa_object_p
PARAMS ((bfd
*));
332 static boolean elf32_hppa_add_symbol_hook
333 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
334 const char **, flagword
*, asection
**, bfd_vma
*));
336 static boolean elf32_hppa_create_dynamic_sections
337 PARAMS ((bfd
*, struct bfd_link_info
*));
339 static boolean elf32_hppa_check_relocs
340 PARAMS ((bfd
*, struct bfd_link_info
*,
341 asection
*, const Elf_Internal_Rela
*));
343 static asection
*elf32_hppa_gc_mark_hook
344 PARAMS ((bfd
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
345 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
347 static boolean elf32_hppa_gc_sweep_hook
348 PARAMS ((bfd
*, struct bfd_link_info
*,
349 asection
*, const Elf_Internal_Rela
*));
351 static void elf32_hppa_hide_symbol
352 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
354 static boolean elf32_hppa_adjust_dynamic_symbol
355 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
357 static boolean hppa_handle_PIC_calls
358 PARAMS ((struct elf_link_hash_entry
*, PTR
));
360 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
361 || RELATIVE_DYNAMIC_RELOCS)
362 static boolean hppa_discard_copies
363 PARAMS ((struct elf_link_hash_entry
*, PTR
));
366 static boolean clobber_millicode_symbols
367 PARAMS ((struct elf_link_hash_entry
*, struct bfd_link_info
*));
369 static boolean elf32_hppa_size_dynamic_sections
370 PARAMS ((bfd
*, struct bfd_link_info
*));
372 static bfd_reloc_status_type final_link_relocate
373 PARAMS ((asection
*, bfd_byte
*, const Elf_Internal_Rela
*,
374 bfd_vma
, struct elf32_hppa_link_hash_table
*, asection
*,
375 struct elf32_hppa_link_hash_entry
*));
377 static boolean elf32_hppa_relocate_section
378 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*,
379 bfd_byte
*, Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
381 static boolean elf32_hppa_finish_dynamic_symbol
382 PARAMS ((bfd
*, struct bfd_link_info
*,
383 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
385 static boolean elf32_hppa_finish_dynamic_sections
386 PARAMS ((bfd
*, struct bfd_link_info
*));
388 static int elf32_hppa_elf_get_symbol_type
389 PARAMS ((Elf_Internal_Sym
*, int));
391 /* Assorted hash table functions. */
393 /* Initialize an entry in the stub hash table. */
395 static struct bfd_hash_entry
*
396 stub_hash_newfunc (entry
, table
, string
)
397 struct bfd_hash_entry
*entry
;
398 struct bfd_hash_table
*table
;
401 struct elf32_hppa_stub_hash_entry
*ret
;
403 ret
= (struct elf32_hppa_stub_hash_entry
*) entry
;
405 /* Allocate the structure if it has not already been allocated by a
409 ret
= ((struct elf32_hppa_stub_hash_entry
*)
410 bfd_hash_allocate (table
,
411 sizeof (struct elf32_hppa_stub_hash_entry
)));
416 /* Call the allocation method of the superclass. */
417 ret
= ((struct elf32_hppa_stub_hash_entry
*)
418 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
422 /* Initialize the local fields. */
423 ret
->stub_sec
= NULL
;
424 #if ! LONG_BRANCH_PIC_IN_SHLIB
425 ret
->reloc_sec
= NULL
;
427 ret
->stub_offset
= 0;
428 ret
->target_value
= 0;
429 ret
->target_section
= NULL
;
430 ret
->stub_type
= hppa_stub_long_branch
;
435 return (struct bfd_hash_entry
*) ret
;
438 /* Initialize an entry in the link hash table. */
440 static struct bfd_hash_entry
*
441 hppa_link_hash_newfunc (entry
, table
, string
)
442 struct bfd_hash_entry
*entry
;
443 struct bfd_hash_table
*table
;
446 struct elf32_hppa_link_hash_entry
*ret
;
448 ret
= (struct elf32_hppa_link_hash_entry
*) entry
;
450 /* Allocate the structure if it has not already been allocated by a
454 ret
= ((struct elf32_hppa_link_hash_entry
*)
455 bfd_hash_allocate (table
,
456 sizeof (struct elf32_hppa_link_hash_entry
)));
461 /* Call the allocation method of the superclass. */
462 ret
= ((struct elf32_hppa_link_hash_entry
*)
463 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
468 /* Initialize the local fields. */
469 #if ! LONG_BRANCH_PIC_IN_SHLIB
470 ret
->stub_reloc_sec
= NULL
;
472 ret
->stub_cache
= NULL
;
473 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
474 ret
->reloc_entries
= NULL
;
481 return (struct bfd_hash_entry
*) ret
;
484 /* Create the derived linker hash table. The PA ELF port uses the derived
485 hash table to keep information specific to the PA ELF linker (without
486 using static variables). */
488 static struct bfd_link_hash_table
*
489 elf32_hppa_link_hash_table_create (abfd
)
492 struct elf32_hppa_link_hash_table
*ret
;
494 ret
= ((struct elf32_hppa_link_hash_table
*) bfd_alloc (abfd
, sizeof (*ret
)));
498 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
, hppa_link_hash_newfunc
))
500 bfd_release (abfd
, ret
);
504 /* Init the stub hash table too. */
505 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
))
508 ret
->stub_bfd
= NULL
;
509 ret
->add_stub_section
= NULL
;
510 ret
->layout_sections_again
= NULL
;
511 ret
->stub_group
= NULL
;
518 ret
->multi_subspace
= 0;
519 ret
->has_12bit_branch
= 0;
520 ret
->has_17bit_branch
= 0;
521 ret
->need_plt_stub
= 0;
523 return &ret
->root
.root
;
526 /* Build a name for an entry in the stub hash table. */
529 hppa_stub_name (input_section
, sym_sec
, hash
, rel
)
530 const asection
*input_section
;
531 const asection
*sym_sec
;
532 const struct elf32_hppa_link_hash_entry
*hash
;
533 const Elf_Internal_Rela
*rel
;
540 len
= 8 + 1 + strlen (hash
->elf
.root
.root
.string
) + 1 + 8 + 1;
541 stub_name
= bfd_malloc (len
);
542 if (stub_name
!= NULL
)
544 sprintf (stub_name
, "%08x_%s+%x",
545 input_section
->id
& 0xffffffff,
546 hash
->elf
.root
.root
.string
,
547 (int) rel
->r_addend
& 0xffffffff);
552 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
553 stub_name
= bfd_malloc (len
);
554 if (stub_name
!= NULL
)
556 sprintf (stub_name
, "%08x_%x:%x+%x",
557 input_section
->id
& 0xffffffff,
558 sym_sec
->id
& 0xffffffff,
559 (int) ELF32_R_SYM (rel
->r_info
) & 0xffffffff,
560 (int) rel
->r_addend
& 0xffffffff);
566 /* Look up an entry in the stub hash. Stub entries are cached because
567 creating the stub name takes a bit of time. */
569 static struct elf32_hppa_stub_hash_entry
*
570 hppa_get_stub_entry (input_section
, sym_sec
, hash
, rel
, hplink
)
571 const asection
*input_section
;
572 const asection
*sym_sec
;
573 struct elf32_hppa_link_hash_entry
*hash
;
574 const Elf_Internal_Rela
*rel
;
575 struct elf32_hppa_link_hash_table
*hplink
;
577 struct elf32_hppa_stub_hash_entry
*stub_entry
;
578 const asection
*id_sec
;
580 /* If this input section is part of a group of sections sharing one
581 stub section, then use the id of the first section in the group.
582 Stub names need to include a section id, as there may well be
583 more than one stub used to reach say, printf, and we need to
584 distinguish between them. */
585 id_sec
= hplink
->stub_group
[input_section
->id
].link_sec
;
587 if (hash
!= NULL
&& hash
->stub_cache
!= NULL
588 && hash
->stub_cache
->h
== hash
589 && hash
->stub_cache
->id_sec
== id_sec
)
591 stub_entry
= hash
->stub_cache
;
597 stub_name
= hppa_stub_name (id_sec
, sym_sec
, hash
, rel
);
598 if (stub_name
== NULL
)
601 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
,
602 stub_name
, false, false);
603 if (stub_entry
== NULL
)
605 if (hash
== NULL
|| hash
->elf
.root
.type
!= bfd_link_hash_undefweak
)
606 (*_bfd_error_handler
) (_("%s(%s+0x%lx): cannot find stub entry %s"),
607 bfd_get_filename (input_section
->owner
),
609 (long) rel
->r_offset
,
615 hash
->stub_cache
= stub_entry
;
624 /* Add a new stub entry to the stub hash. Not all fields of the new
625 stub entry are initialised. */
627 static struct elf32_hppa_stub_hash_entry
*
628 hppa_add_stub (stub_name
, section
, hplink
)
629 const char *stub_name
;
631 struct elf32_hppa_link_hash_table
*hplink
;
635 struct elf32_hppa_stub_hash_entry
*stub_entry
;
637 link_sec
= hplink
->stub_group
[section
->id
].link_sec
;
638 stub_sec
= hplink
->stub_group
[section
->id
].stub_sec
;
639 if (stub_sec
== NULL
)
641 stub_sec
= hplink
->stub_group
[link_sec
->id
].stub_sec
;
642 if (stub_sec
== NULL
)
647 len
= strlen (link_sec
->name
) + sizeof (STUB_SUFFIX
);
648 s_name
= bfd_alloc (hplink
->stub_bfd
, len
);
652 strcpy (s_name
, link_sec
->name
);
653 strcpy (s_name
+ len
- sizeof (STUB_SUFFIX
), STUB_SUFFIX
);
654 stub_sec
= (*hplink
->add_stub_section
) (s_name
, link_sec
);
655 if (stub_sec
== NULL
)
657 hplink
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
659 hplink
->stub_group
[section
->id
].stub_sec
= stub_sec
;
662 /* Enter this entry into the linker stub hash table. */
663 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
, stub_name
,
665 if (stub_entry
== NULL
)
667 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
668 bfd_get_filename (section
->owner
),
673 stub_entry
->stub_sec
= stub_sec
;
674 #if ! LONG_BRANCH_PIC_IN_SHLIB
675 stub_entry
->reloc_sec
= hplink
->stub_group
[section
->id
].reloc_sec
;
677 stub_entry
->stub_offset
= 0;
678 stub_entry
->id_sec
= link_sec
;
682 /* Determine the type of stub needed, if any, for a call. */
684 static enum elf32_hppa_stub_type
685 hppa_type_of_stub (input_sec
, rel
, hash
, destination
)
687 const Elf_Internal_Rela
*rel
;
688 struct elf32_hppa_link_hash_entry
*hash
;
692 bfd_vma branch_offset
;
693 bfd_vma max_branch_offset
;
697 && (((hash
->elf
.root
.type
== bfd_link_hash_defined
698 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
699 && hash
->elf
.root
.u
.def
.section
->output_section
== NULL
)
700 || (hash
->elf
.root
.type
== bfd_link_hash_defweak
701 && hash
->elf
.dynindx
!= -1
702 && hash
->elf
.plt
.offset
!= (bfd_vma
) -1)
703 || hash
->elf
.root
.type
== bfd_link_hash_undefweak
704 || hash
->elf
.root
.type
== bfd_link_hash_undefined
707 /* If output_section is NULL, then it's a symbol defined in a
708 shared library. We will need an import stub. Decide between
709 hppa_stub_import and hppa_stub_import_shared later. For
710 shared links we need stubs for undefined or weak syms too;
711 They will presumably be resolved by the dynamic linker. */
712 return hppa_stub_import
;
715 /* Determine where the call point is. */
716 location
= (input_sec
->output_offset
717 + input_sec
->output_section
->vma
720 branch_offset
= destination
- location
- 8;
721 r_type
= ELF32_R_TYPE (rel
->r_info
);
723 /* Determine if a long branch stub is needed. parisc branch offsets
724 are relative to the second instruction past the branch, ie. +8
725 bytes on from the branch instruction location. The offset is
726 signed and counts in units of 4 bytes. */
727 if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
729 max_branch_offset
= (1 << (17-1)) << 2;
731 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
733 max_branch_offset
= (1 << (12-1)) << 2;
735 else /* R_PARISC_PCREL22F. */
737 max_branch_offset
= (1 << (22-1)) << 2;
740 if (branch_offset
+ max_branch_offset
>= 2*max_branch_offset
)
742 #if LONG_BRANCH_VIA_PLT
744 && hash
->elf
.dynindx
!= -1
745 && hash
->elf
.plt
.offset
!= (bfd_vma
) -1)
747 /* If we are doing a shared link and find we need a long
748 branch stub, then go via the .plt if possible. */
749 return hppa_stub_import
;
753 return hppa_stub_long_branch
;
755 return hppa_stub_none
;
758 /* Build one linker stub as defined by the stub hash table entry GEN_ENTRY.
759 IN_ARG contains the link info pointer. */
761 #define LDIL_R1 0x20200000 /* ldil LR'XXX,%r1 */
762 #define BE_SR4_R1 0xe0202002 /* be,n RR'XXX(%sr4,%r1) */
764 #define BL_R1 0xe8200000 /* b,l .+8,%r1 */
765 #define ADDIL_R1 0x28200000 /* addil L'XXX,%r1,%r1 */
766 #define DEPI_R1 0xd4201c1e /* depi 0,31,2,%r1 */
768 #define ADDIL_DP 0x2b600000 /* addil L'XXX,%dp,%r1 */
769 #define LDW_R1_R21 0x48350000 /* ldw R'XXX(%sr0,%r1),%r21 */
770 #define BV_R0_R21 0xeaa0c000 /* bv %r0(%r21) */
771 #define LDW_R1_R19 0x48330000 /* ldw R'XXX(%sr0,%r1),%r19 */
773 #define ADDIL_R19 0x2a600000 /* addil L'XXX,%r19,%r1 */
774 #define LDW_R1_DP 0x483b0000 /* ldw R'XXX(%sr0,%r1),%dp */
776 #define LDSID_R21_R1 0x02a010a1 /* ldsid (%sr0,%r21),%r1 */
777 #define MTSP_R1 0x00011820 /* mtsp %r1,%sr0 */
778 #define BE_SR0_R21 0xe2a00000 /* be 0(%sr0,%r21) */
779 #define STW_RP 0x6bc23fd1 /* stw %rp,-24(%sr0,%sp) */
781 #define BL_RP 0xe8400002 /* b,l,n XXX,%rp */
782 #define NOP 0x08000240 /* nop */
783 #define LDW_RP 0x4bc23fd1 /* ldw -24(%sr0,%sp),%rp */
784 #define LDSID_RP_R1 0x004010a1 /* ldsid (%sr0,%rp),%r1 */
785 #define BE_SR0_RP 0xe0400002 /* be,n 0(%sr0,%rp) */
792 #define LDW_R1_DLT LDW_R1_R19
794 #define LDW_R1_DLT LDW_R1_DP
798 hppa_build_one_stub (gen_entry
, in_arg
)
799 struct bfd_hash_entry
*gen_entry
;
802 struct elf32_hppa_stub_hash_entry
*stub_entry
;
803 struct bfd_link_info
*info
;
804 struct elf32_hppa_link_hash_table
*hplink
;
813 /* Massage our args to the form they really have. */
814 stub_entry
= (struct elf32_hppa_stub_hash_entry
*) gen_entry
;
815 info
= (struct bfd_link_info
*) in_arg
;
817 hplink
= hppa_link_hash_table (info
);
818 stub_sec
= stub_entry
->stub_sec
;
820 /* Make a note of the offset within the stubs for this entry. */
821 stub_entry
->stub_offset
= stub_sec
->_raw_size
;
822 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
824 stub_bfd
= stub_sec
->owner
;
826 switch (stub_entry
->stub_type
)
828 case hppa_stub_long_branch
:
829 /* Create the long branch. A long branch is formed with "ldil"
830 loading the upper bits of the target address into a register,
831 then branching with "be" which adds in the lower bits.
832 The "be" has its delay slot nullified. */
833 sym_value
= (stub_entry
->target_value
834 + stub_entry
->target_section
->output_offset
835 + stub_entry
->target_section
->output_section
->vma
);
837 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_lrsel
);
838 insn
= hppa_rebuild_insn ((int) LDIL_R1
, val
, 21);
839 bfd_put_32 (stub_bfd
, insn
, loc
);
841 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_rrsel
) >> 2;
842 insn
= hppa_rebuild_insn ((int) BE_SR4_R1
, val
, 17);
843 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
845 #if ! LONG_BRANCH_PIC_IN_SHLIB
848 /* Output a dynamic relocation for this stub. We only
849 output one PCREL21L reloc per stub, trusting that the
850 dynamic linker will also fix the implied PCREL17R for the
851 second instruction. PCREL21L dynamic relocs had better
852 never be emitted for some other purpose... */
854 Elf_Internal_Rela outrel
;
856 if (stub_entry
->h
== NULL
)
858 (*_bfd_error_handler
)
859 (_("%s(%s+0x%lx): cannot relocate %s, recompile with -ffunction-sections"),
860 bfd_get_filename (stub_entry
->target_section
->owner
),
862 (long) stub_entry
->stub_offset
,
863 stub_entry
->root
.string
);
864 bfd_set_error (bfd_error_bad_value
);
868 srel
= stub_entry
->reloc_sec
;
871 (*_bfd_error_handler
)
872 (_("Could not find relocation section for %s"),
874 bfd_set_error (bfd_error_bad_value
);
878 outrel
.r_offset
= (stub_entry
->stub_offset
879 + stub_sec
->output_offset
880 + stub_sec
->output_section
->vma
);
881 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_PCREL21L
);
882 outrel
.r_addend
= sym_value
;
883 bfd_elf32_swap_reloca_out (stub_sec
->output_section
->owner
,
885 ((Elf32_External_Rela
*)
886 srel
->contents
+ srel
->reloc_count
));
893 case hppa_stub_long_branch_shared
:
894 /* Branches are relative. This is where we are going to. */
895 sym_value
= (stub_entry
->target_value
896 + stub_entry
->target_section
->output_offset
897 + stub_entry
->target_section
->output_section
->vma
);
899 /* And this is where we are coming from, more or less. */
900 sym_value
-= (stub_entry
->stub_offset
901 + stub_sec
->output_offset
902 + stub_sec
->output_section
->vma
);
904 bfd_put_32 (stub_bfd
, (bfd_vma
) BL_R1
, loc
);
905 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_lrsel
);
906 insn
= hppa_rebuild_insn ((int) ADDIL_R1
, val
, 21);
907 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
909 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_rrsel
) >> 2;
910 insn
= hppa_rebuild_insn ((int) BE_SR4_R1
, val
, 17);
911 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
915 case hppa_stub_import
:
916 case hppa_stub_import_shared
:
917 sym_value
= (stub_entry
->h
->elf
.plt
.offset
918 + hplink
->splt
->output_offset
919 + hplink
->splt
->output_section
->vma
920 - elf_gp (hplink
->splt
->output_section
->owner
));
924 if (stub_entry
->stub_type
== hppa_stub_import_shared
)
927 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_lrsel
),
928 insn
= hppa_rebuild_insn ((int) insn
, val
, 21);
929 bfd_put_32 (stub_bfd
, insn
, loc
);
931 /* It is critical to use lrsel/rrsel here because we are using
932 two different offsets (+0 and +4) from sym_value. If we use
933 lsel/rsel then with unfortunate sym_values we will round
934 sym_value+4 up to the next 2k block leading to a mis-match
935 between the lsel and rsel value. */
936 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_rrsel
);
937 insn
= hppa_rebuild_insn ((int) LDW_R1_R21
, val
, 14);
938 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
940 if (hplink
->multi_subspace
)
942 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 4, e_rrsel
);
943 insn
= hppa_rebuild_insn ((int) LDW_R1_DLT
, val
, 14);
944 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
946 bfd_put_32 (stub_bfd
, (bfd_vma
) LDSID_R21_R1
, loc
+ 12);
947 bfd_put_32 (stub_bfd
, (bfd_vma
) MTSP_R1
, loc
+ 16);
948 bfd_put_32 (stub_bfd
, (bfd_vma
) BE_SR0_R21
, loc
+ 20);
949 bfd_put_32 (stub_bfd
, (bfd_vma
) STW_RP
, loc
+ 24);
955 bfd_put_32 (stub_bfd
, (bfd_vma
) BV_R0_R21
, loc
+ 8);
956 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 4, e_rrsel
);
957 insn
= hppa_rebuild_insn ((int) LDW_R1_DLT
, val
, 14);
958 bfd_put_32 (stub_bfd
, insn
, loc
+ 12);
964 && stub_entry
->h
!= NULL
965 && stub_entry
->h
->pic_call
)
967 /* Build the .plt entry needed to call a PIC function from
968 statically linked code. We don't need any relocs. */
970 struct elf32_hppa_link_hash_entry
*eh
;
973 dynobj
= hplink
->root
.dynobj
;
974 eh
= (struct elf32_hppa_link_hash_entry
*) stub_entry
->h
;
976 BFD_ASSERT (eh
->elf
.root
.type
== bfd_link_hash_defined
977 || eh
->elf
.root
.type
== bfd_link_hash_defweak
);
979 value
= (eh
->elf
.root
.u
.def
.value
980 + eh
->elf
.root
.u
.def
.section
->output_offset
981 + eh
->elf
.root
.u
.def
.section
->output_section
->vma
);
983 /* Fill in the entry in the procedure linkage table.
985 The format of a plt entry is
989 bfd_put_32 (hplink
->splt
->owner
, value
,
990 hplink
->splt
->contents
+ eh
->elf
.plt
.offset
);
991 value
= elf_gp (hplink
->splt
->output_section
->owner
);
992 bfd_put_32 (hplink
->splt
->owner
, value
,
993 hplink
->splt
->contents
+ eh
->elf
.plt
.offset
+ 4);
997 case hppa_stub_export
:
998 /* Branches are relative. This is where we are going to. */
999 sym_value
= (stub_entry
->target_value
1000 + stub_entry
->target_section
->output_offset
1001 + stub_entry
->target_section
->output_section
->vma
);
1003 /* And this is where we are coming from. */
1004 sym_value
-= (stub_entry
->stub_offset
1005 + stub_sec
->output_offset
1006 + stub_sec
->output_section
->vma
);
1008 if (sym_value
- 8 + 0x40000 >= 0x80000)
1010 (*_bfd_error_handler
)
1011 (_("%s(%s+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
1012 bfd_get_filename (stub_entry
->target_section
->owner
),
1014 (long) stub_entry
->stub_offset
,
1015 stub_entry
->root
.string
);
1016 bfd_set_error (bfd_error_bad_value
);
1020 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_fsel
) >> 2;
1021 insn
= hppa_rebuild_insn ((int) BL_RP
, val
, 17);
1022 bfd_put_32 (stub_bfd
, insn
, loc
);
1024 bfd_put_32 (stub_bfd
, (bfd_vma
) NOP
, loc
+ 4);
1025 bfd_put_32 (stub_bfd
, (bfd_vma
) LDW_RP
, loc
+ 8);
1026 bfd_put_32 (stub_bfd
, (bfd_vma
) LDSID_RP_R1
, loc
+ 12);
1027 bfd_put_32 (stub_bfd
, (bfd_vma
) MTSP_R1
, loc
+ 16);
1028 bfd_put_32 (stub_bfd
, (bfd_vma
) BE_SR0_RP
, loc
+ 20);
1030 /* Point the function symbol at the stub. */
1031 stub_entry
->h
->elf
.root
.u
.def
.section
= stub_sec
;
1032 stub_entry
->h
->elf
.root
.u
.def
.value
= stub_sec
->_raw_size
;
1042 stub_sec
->_raw_size
+= size
;
1068 /* As above, but don't actually build the stub. Just bump offset so
1069 we know stub section sizes. */
1072 hppa_size_one_stub (gen_entry
, in_arg
)
1073 struct bfd_hash_entry
*gen_entry
;
1076 struct elf32_hppa_stub_hash_entry
*stub_entry
;
1077 struct elf32_hppa_link_hash_table
*hplink
;
1080 /* Massage our args to the form they really have. */
1081 stub_entry
= (struct elf32_hppa_stub_hash_entry
*) gen_entry
;
1082 hplink
= (struct elf32_hppa_link_hash_table
*) in_arg
;
1084 if (stub_entry
->stub_type
== hppa_stub_long_branch
)
1086 #if ! LONG_BRANCH_PIC_IN_SHLIB
1087 if (stub_entry
->reloc_sec
!= NULL
)
1088 stub_entry
->reloc_sec
->_raw_size
+= sizeof (Elf32_External_Rela
);
1092 else if (stub_entry
->stub_type
== hppa_stub_long_branch_shared
)
1094 else if (stub_entry
->stub_type
== hppa_stub_export
)
1096 else /* hppa_stub_import or hppa_stub_import_shared. */
1098 if (hplink
->multi_subspace
)
1104 stub_entry
->stub_sec
->_raw_size
+= size
;
1108 /* Return nonzero if ABFD represents an HPPA ELF32 file.
1109 Additionally we set the default architecture and machine. */
1112 elf32_hppa_object_p (abfd
)
1115 unsigned int flags
= elf_elfheader (abfd
)->e_flags
;
1117 switch (flags
& (EF_PARISC_ARCH
| EF_PARISC_WIDE
))
1119 case EFA_PARISC_1_0
:
1120 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 10);
1121 case EFA_PARISC_1_1
:
1122 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 11);
1123 case EFA_PARISC_2_0
:
1124 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 20);
1125 case EFA_PARISC_2_0
| EF_PARISC_WIDE
:
1126 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 25);
1131 /* Undo the generic ELF code's subtraction of section->vma from the
1132 value of each external symbol. */
1135 elf32_hppa_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
1136 bfd
*abfd ATTRIBUTE_UNUSED
;
1137 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1138 const Elf_Internal_Sym
*sym ATTRIBUTE_UNUSED
;
1139 const char **namep ATTRIBUTE_UNUSED
;
1140 flagword
*flagsp ATTRIBUTE_UNUSED
;
1144 *valp
+= (*secp
)->vma
;
1148 /* Create the .plt and .got sections, and set up our hash table
1149 short-cuts to various dynamic sections. */
1152 elf32_hppa_create_dynamic_sections (abfd
, info
)
1154 struct bfd_link_info
*info
;
1156 struct elf32_hppa_link_hash_table
*hplink
;
1158 /* Don't try to create the .plt and .got twice. */
1159 hplink
= hppa_link_hash_table (info
);
1160 if (hplink
->splt
!= NULL
)
1163 /* Call the generic code to do most of the work. */
1164 if (! _bfd_elf_create_dynamic_sections (abfd
, info
))
1167 hplink
->splt
= bfd_get_section_by_name (abfd
, ".plt");
1168 hplink
->srelplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
1170 hplink
->sgot
= bfd_get_section_by_name (abfd
, ".got");
1171 hplink
->srelgot
= bfd_make_section (abfd
, ".rela.got");
1172 if (hplink
->srelgot
== NULL
1173 || ! bfd_set_section_flags (abfd
, hplink
->srelgot
,
1178 | SEC_LINKER_CREATED
1180 || ! bfd_set_section_alignment (abfd
, hplink
->srelgot
, 2))
1183 hplink
->sdynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
1184 hplink
->srelbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
1189 /* Look through the relocs for a section during the first phase, and
1190 allocate space in the global offset table or procedure linkage
1191 table. At this point we haven't necessarily read all the input
1195 elf32_hppa_check_relocs (abfd
, info
, sec
, relocs
)
1197 struct bfd_link_info
*info
;
1199 const Elf_Internal_Rela
*relocs
;
1202 Elf_Internal_Shdr
*symtab_hdr
;
1203 struct elf_link_hash_entry
**sym_hashes
;
1204 bfd_signed_vma
*local_got_refcounts
;
1205 const Elf_Internal_Rela
*rel
;
1206 const Elf_Internal_Rela
*rel_end
;
1207 struct elf32_hppa_link_hash_table
*hplink
;
1209 asection
*stubreloc
;
1211 if (info
->relocateable
)
1214 hplink
= hppa_link_hash_table (info
);
1215 dynobj
= hplink
->root
.dynobj
;
1216 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1217 sym_hashes
= elf_sym_hashes (abfd
);
1218 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1222 rel_end
= relocs
+ sec
->reloc_count
;
1223 for (rel
= relocs
; rel
< rel_end
; rel
++)
1229 #if LONG_BRANCH_PIC_IN_SHLIB
1230 NEED_STUBREL
= 0, /* We won't be needing them in this case. */
1237 unsigned int r_symndx
, r_type
;
1238 struct elf32_hppa_link_hash_entry
*h
;
1241 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1243 if (r_symndx
< symtab_hdr
->sh_info
)
1246 h
= ((struct elf32_hppa_link_hash_entry
*)
1247 sym_hashes
[r_symndx
- symtab_hdr
->sh_info
]);
1249 r_type
= ELF32_R_TYPE (rel
->r_info
);
1253 case R_PARISC_DLTIND14F
:
1254 case R_PARISC_DLTIND14R
:
1255 case R_PARISC_DLTIND21L
:
1256 /* This symbol requires a global offset table entry. */
1257 need_entry
= NEED_GOT
;
1259 /* Mark this section as containing PIC code. */
1260 sec
->flags
|= SEC_HAS_GOT_REF
;
1263 case R_PARISC_PLABEL14R
: /* "Official" procedure labels. */
1264 case R_PARISC_PLABEL21L
:
1265 case R_PARISC_PLABEL32
:
1266 /* If the addend is non-zero, we break badly. */
1267 BFD_ASSERT (rel
->r_addend
== 0);
1269 /* If we are creating a shared library, then we need to
1270 create a PLT entry for all PLABELs, because PLABELs with
1271 local symbols may be passed via a pointer to another
1272 object. Additionally, output a dynamic relocation
1273 pointing to the PLT entry. */
1274 need_entry
= PLT_PLABEL
| NEED_PLT
| NEED_DYNREL
;
1277 case R_PARISC_PCREL12F
:
1278 hplink
->has_12bit_branch
= 1;
1280 case R_PARISC_PCREL17C
:
1281 case R_PARISC_PCREL17F
:
1282 hplink
->has_17bit_branch
= 1;
1284 case R_PARISC_PCREL22F
:
1285 /* Function calls might need to go through the .plt, and
1286 might require long branch stubs. */
1289 /* We know local syms won't need a .plt entry, and if
1290 they need a long branch stub we can't guarantee that
1291 we can reach the stub. So just flag an error later
1292 if we're doing a shared link and find we need a long
1298 /* Global symbols will need a .plt entry if they remain
1299 global, and in most cases won't need a long branch
1300 stub. Unfortunately, we have to cater for the case
1301 where a symbol is forced local by versioning, or due
1302 to symbolic linking, and we lose the .plt entry. */
1303 need_entry
= NEED_PLT
| NEED_STUBREL
;
1307 case R_PARISC_SEGBASE
: /* Used to set segment base. */
1308 case R_PARISC_SEGREL32
: /* Relative reloc. */
1309 case R_PARISC_PCREL14F
: /* PC relative load/store. */
1310 case R_PARISC_PCREL14R
:
1311 case R_PARISC_PCREL17R
: /* External branches. */
1312 case R_PARISC_PCREL21L
: /* As above, and for load/store too. */
1313 /* We don't need to propagate the relocation if linking a
1314 shared object since these are section relative. */
1317 case R_PARISC_DPREL14F
: /* Used for gp rel data load/store. */
1318 case R_PARISC_DPREL14R
:
1319 case R_PARISC_DPREL21L
:
1322 (*_bfd_error_handler
)
1323 (_("%s: relocation %s can not be used when making a shared object; recompile with -fPIC"),
1324 bfd_get_filename (abfd
),
1325 elf_hppa_howto_table
[r_type
].name
);
1326 bfd_set_error (bfd_error_bad_value
);
1331 case R_PARISC_DIR17F
: /* Used for external branches. */
1332 case R_PARISC_DIR17R
:
1333 case R_PARISC_DIR14F
: /* Used for load/store from absolute locn. */
1334 case R_PARISC_DIR14R
:
1335 case R_PARISC_DIR21L
: /* As above, and for ext branches too. */
1337 /* Help debug shared library creation. Any of the above
1338 relocs can be used in shared libs, but they may cause
1339 pages to become unshared. */
1342 (*_bfd_error_handler
)
1343 (_("%s: relocation %s should not be used when making a shared object; recompile with -fPIC"),
1344 bfd_get_filename (abfd
),
1345 elf_hppa_howto_table
[r_type
].name
);
1350 case R_PARISC_DIR32
: /* .word, PARISC.unwind relocs. */
1351 /* We may want to output a dynamic relocation later. */
1352 need_entry
= NEED_DYNREL
;
1355 /* This relocation describes the C++ object vtable hierarchy.
1356 Reconstruct it for later use during GC. */
1357 case R_PARISC_GNU_VTINHERIT
:
1358 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
,
1359 &h
->elf
, rel
->r_offset
))
1363 /* This relocation describes which C++ vtable entries are actually
1364 used. Record for later use during GC. */
1365 case R_PARISC_GNU_VTENTRY
:
1366 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
,
1367 &h
->elf
, rel
->r_addend
))
1375 /* Now carry out our orders. */
1376 if (need_entry
& NEED_GOT
)
1378 /* Allocate space for a GOT entry, as well as a dynamic
1379 relocation for this entry. */
1381 hplink
->root
.dynobj
= dynobj
= abfd
;
1383 if (hplink
->sgot
== NULL
)
1385 if (! elf32_hppa_create_dynamic_sections (dynobj
, info
))
1391 if (h
->elf
.got
.refcount
== -1)
1393 h
->elf
.got
.refcount
= 1;
1395 /* Make sure this symbol is output as a dynamic symbol. */
1396 if (h
->elf
.dynindx
== -1)
1398 if (! bfd_elf32_link_record_dynamic_symbol (info
,
1403 hplink
->sgot
->_raw_size
+= GOT_ENTRY_SIZE
;
1404 hplink
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
1407 h
->elf
.got
.refcount
+= 1;
1411 /* This is a global offset table entry for a local symbol. */
1412 if (local_got_refcounts
== NULL
)
1416 /* Allocate space for local got offsets and local
1417 plt offsets. Done this way to save polluting
1418 elf_obj_tdata with another target specific
1420 size
= symtab_hdr
->sh_info
* 2 * sizeof (bfd_signed_vma
);
1421 local_got_refcounts
= ((bfd_signed_vma
*)
1422 bfd_alloc (abfd
, size
));
1423 if (local_got_refcounts
== NULL
)
1425 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1426 memset (local_got_refcounts
, -1, size
);
1428 if (local_got_refcounts
[r_symndx
] == -1)
1430 local_got_refcounts
[r_symndx
] = 1;
1432 hplink
->sgot
->_raw_size
+= GOT_ENTRY_SIZE
;
1435 /* If we are generating a shared object, we need to
1436 output a reloc so that the dynamic linker can
1437 adjust this GOT entry (because the address
1438 the shared library is loaded at is not fixed). */
1439 hplink
->srelgot
->_raw_size
+=
1440 sizeof (Elf32_External_Rela
);
1444 local_got_refcounts
[r_symndx
] += 1;
1448 if (need_entry
& NEED_PLT
)
1450 /* If we are creating a shared library, and this is a reloc
1451 against a weak symbol or a global symbol in a dynamic
1452 object, then we will be creating an import stub and a
1453 .plt entry for the symbol. Similarly, on a normal link
1454 to symbols defined in a dynamic object we'll need the
1455 import stub and a .plt entry. We don't know yet whether
1456 the symbol is defined or not, so make an entry anyway and
1457 clean up later in adjust_dynamic_symbol. */
1458 if ((sec
->flags
& SEC_ALLOC
) != 0)
1462 if (h
->elf
.plt
.refcount
== -1)
1464 h
->elf
.plt
.refcount
= 1;
1465 h
->elf
.elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1468 h
->elf
.plt
.refcount
+= 1;
1470 /* If this .plt entry is for a plabel, mark it so
1471 that adjust_dynamic_symbol will keep the entry
1472 even if it appears to be local. */
1473 if (need_entry
& PLT_PLABEL
)
1476 else if (need_entry
& PLT_PLABEL
)
1480 if (local_got_refcounts
== NULL
)
1484 /* Allocate space for local got offsets and local
1486 size
= symtab_hdr
->sh_info
* 2 * sizeof (bfd_signed_vma
);
1487 local_got_refcounts
= ((bfd_signed_vma
*)
1488 bfd_alloc (abfd
, size
));
1489 if (local_got_refcounts
== NULL
)
1491 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1492 memset (local_got_refcounts
, -1, size
);
1494 indx
= r_symndx
+ symtab_hdr
->sh_info
;
1495 if (local_got_refcounts
[indx
] == -1)
1496 local_got_refcounts
[indx
] = 1;
1498 local_got_refcounts
[indx
] += 1;
1503 if (need_entry
& (NEED_DYNREL
| NEED_STUBREL
))
1505 /* Flag this symbol as having a non-got, non-plt reference
1506 so that we generate copy relocs if it turns out to be
1509 h
->elf
.elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
1511 /* If we are creating a shared library then we need to copy
1512 the reloc into the shared library. However, if we are
1513 linking with -Bsymbolic, we need only copy absolute
1514 relocs or relocs against symbols that are not defined in
1515 an object we are including in the link. PC- or DP- or
1516 DLT-relative relocs against any local sym or global sym
1517 with DEF_REGULAR set, can be discarded. At this point we
1518 have not seen all the input files, so it is possible that
1519 DEF_REGULAR is not set now but will be set later (it is
1520 never cleared). We account for that possibility below by
1521 storing information in the reloc_entries field of the
1524 A similar situation to the -Bsymbolic case occurs when
1525 creating shared libraries and symbol visibility changes
1526 render the symbol local.
1528 As it turns out, all the relocs we will be creating here
1529 are absolute, so we cannot remove them on -Bsymbolic
1530 links or visibility changes anyway. A STUB_REL reloc
1531 is absolute too, as in that case it is the reloc in the
1532 stub we will be creating, rather than copying the PCREL
1533 reloc in the branch. */
1534 if ((sec
->flags
& SEC_ALLOC
) != 0
1536 #if RELATIVE_DYNAMIC_RELOCS
1538 || is_absolute_reloc (r_type
)
1540 && ((h
->elf
.elf_link_hash_flags
1541 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
1549 if ((need_entry
& NEED_STUBREL
))
1552 /* Create a reloc section in dynobj and make room for
1559 hplink
->root
.dynobj
= dynobj
= abfd
;
1561 name
= bfd_elf_string_from_elf_section
1563 elf_elfheader (abfd
)->e_shstrndx
,
1564 elf_section_data (sec
)->rel_hdr
.sh_name
);
1567 (*_bfd_error_handler
)
1568 (_("Could not find relocation section for %s"),
1570 bfd_set_error (bfd_error_bad_value
);
1574 if ((need_entry
& NEED_STUBREL
))
1576 size_t len
= strlen (name
) + sizeof (STUB_SUFFIX
);
1577 char *newname
= bfd_malloc (len
);
1579 if (newname
== NULL
)
1581 strcpy (newname
, name
);
1582 strcpy (newname
+ len
- sizeof (STUB_SUFFIX
),
1587 srel
= bfd_get_section_by_name (dynobj
, name
);
1592 srel
= bfd_make_section (dynobj
, name
);
1593 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
1594 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1595 if ((sec
->flags
& SEC_ALLOC
) != 0)
1596 flags
|= SEC_ALLOC
| SEC_LOAD
;
1598 || !bfd_set_section_flags (dynobj
, srel
, flags
)
1599 || !bfd_set_section_alignment (dynobj
, srel
, 2))
1602 else if ((need_entry
& NEED_STUBREL
))
1605 if ((need_entry
& NEED_STUBREL
))
1611 #if ! LONG_BRANCH_PIC_IN_SHLIB
1612 /* If this is a function call, we only need one dynamic
1613 reloc for the stub as all calls to a particular
1614 function will go through the same stub. Actually, a
1615 long branch stub needs two relocations, but we count
1616 on some intelligence on the part of the dynamic
1618 if ((need_entry
& NEED_STUBREL
))
1620 doit
= h
->stub_reloc_sec
!= stubreloc
;
1621 h
->stub_reloc_sec
= stubreloc
;
1629 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
1631 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
1632 /* Keep track of relocations we have entered for
1633 this global symbol, so that we can discard them
1634 later if necessary. */
1637 #if RELATIVE_DYNAMIC_RELOCS
1638 || ! is_absolute_reloc (rtype
)
1640 || (need_entry
& NEED_STUBREL
)))
1642 struct elf32_hppa_dyn_reloc_entry
*p
;
1644 for (p
= h
->reloc_entries
; p
!= NULL
; p
= p
->next
)
1645 if (p
->section
== srel
)
1650 p
= ((struct elf32_hppa_dyn_reloc_entry
*)
1651 bfd_alloc (dynobj
, sizeof *p
));
1654 p
->next
= h
->reloc_entries
;
1655 h
->reloc_entries
= p
;
1660 /* NEED_STUBREL and NEED_DYNREL are never both
1661 set. Leave the count at zero for the
1662 NEED_STUBREL case as we only ever have one
1663 stub reloc per section per symbol, and this
1664 simplifies code in hppa_discard_copies. */
1665 if (! (need_entry
& NEED_STUBREL
))
1677 /* Return the section that should be marked against garbage collection
1678 for a given relocation. */
1681 elf32_hppa_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
1683 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1684 Elf_Internal_Rela
*rel
;
1685 struct elf_link_hash_entry
*h
;
1686 Elf_Internal_Sym
*sym
;
1690 switch ((unsigned int) ELF32_R_TYPE (rel
->r_info
))
1692 case R_PARISC_GNU_VTINHERIT
:
1693 case R_PARISC_GNU_VTENTRY
:
1697 switch (h
->root
.type
)
1699 case bfd_link_hash_defined
:
1700 case bfd_link_hash_defweak
:
1701 return h
->root
.u
.def
.section
;
1703 case bfd_link_hash_common
:
1704 return h
->root
.u
.c
.p
->section
;
1713 if (!(elf_bad_symtab (abfd
)
1714 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
1715 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
1716 && sym
->st_shndx
!= SHN_COMMON
))
1718 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
1725 /* Update the got and plt entry reference counts for the section being
1729 elf32_hppa_gc_sweep_hook (abfd
, info
, sec
, relocs
)
1731 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1733 const Elf_Internal_Rela
*relocs
;
1735 Elf_Internal_Shdr
*symtab_hdr
;
1736 struct elf_link_hash_entry
**sym_hashes
;
1737 bfd_signed_vma
*local_got_refcounts
;
1738 bfd_signed_vma
*local_plt_refcounts
;
1739 const Elf_Internal_Rela
*rel
, *relend
;
1740 unsigned long r_symndx
;
1741 struct elf_link_hash_entry
*h
;
1742 struct elf32_hppa_link_hash_table
*hplink
;
1747 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1748 sym_hashes
= elf_sym_hashes (abfd
);
1749 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1750 local_plt_refcounts
= local_got_refcounts
;
1751 if (local_plt_refcounts
!= NULL
)
1752 local_plt_refcounts
+= symtab_hdr
->sh_info
;
1753 hplink
= hppa_link_hash_table (info
);
1754 dynobj
= hplink
->root
.dynobj
;
1758 sgot
= hplink
->sgot
;
1759 srelgot
= hplink
->srelgot
;
1761 relend
= relocs
+ sec
->reloc_count
;
1762 for (rel
= relocs
; rel
< relend
; rel
++)
1763 switch ((unsigned int) ELF32_R_TYPE (rel
->r_info
))
1765 case R_PARISC_DLTIND14F
:
1766 case R_PARISC_DLTIND14R
:
1767 case R_PARISC_DLTIND21L
:
1768 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1769 if (r_symndx
>= symtab_hdr
->sh_info
)
1771 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1772 if (h
->got
.refcount
> 0)
1774 h
->got
.refcount
-= 1;
1775 if (h
->got
.refcount
== 0)
1777 sgot
->_raw_size
-= GOT_ENTRY_SIZE
;
1778 srelgot
->_raw_size
-= sizeof (Elf32_External_Rela
);
1782 else if (local_got_refcounts
!= NULL
)
1784 if (local_got_refcounts
[r_symndx
] > 0)
1786 local_got_refcounts
[r_symndx
] -= 1;
1787 if (local_got_refcounts
[r_symndx
] == 0)
1789 sgot
->_raw_size
-= GOT_ENTRY_SIZE
;
1791 srelgot
->_raw_size
-= sizeof (Elf32_External_Rela
);
1797 case R_PARISC_PCREL12F
:
1798 case R_PARISC_PCREL17C
:
1799 case R_PARISC_PCREL17F
:
1800 case R_PARISC_PCREL22F
:
1801 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1802 if (r_symndx
>= symtab_hdr
->sh_info
)
1804 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1805 if (h
->plt
.refcount
> 0)
1806 h
->plt
.refcount
-= 1;
1810 case R_PARISC_PLABEL14R
:
1811 case R_PARISC_PLABEL21L
:
1812 case R_PARISC_PLABEL32
:
1813 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1814 if (r_symndx
>= symtab_hdr
->sh_info
)
1816 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1817 if (h
->plt
.refcount
> 0)
1818 h
->plt
.refcount
-= 1;
1820 else if (local_plt_refcounts
!= NULL
)
1822 if (local_plt_refcounts
[r_symndx
] > 0)
1823 local_plt_refcounts
[r_symndx
] -= 1;
1834 /* Our own version of hide_symbol, so that we can keep plt entries for
1838 elf32_hppa_hide_symbol (info
, h
)
1839 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1840 struct elf_link_hash_entry
*h
;
1843 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
)
1845 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1846 h
->plt
.offset
= (bfd_vma
) -1;
1850 /* Adjust a symbol defined by a dynamic object and referenced by a
1851 regular object. The current definition is in some section of the
1852 dynamic object, but we're not including those sections. We have to
1853 change the definition to something the rest of the link can
1857 elf32_hppa_adjust_dynamic_symbol (info
, h
)
1858 struct bfd_link_info
*info
;
1859 struct elf_link_hash_entry
*h
;
1862 struct elf32_hppa_link_hash_table
*hplink
;
1865 hplink
= hppa_link_hash_table (info
);
1866 dynobj
= hplink
->root
.dynobj
;
1868 /* If this is a function, put it in the procedure linkage table. We
1869 will fill in the contents of the procedure linkage table later,
1870 when we know the address of the .got section. */
1871 if (h
->type
== STT_FUNC
1872 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1874 if (h
->plt
.refcount
<= 0
1875 || ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
1876 && h
->root
.type
!= bfd_link_hash_defweak
1877 && ! ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
1878 && (!info
->shared
|| info
->symbolic
)))
1880 /* The .plt entry is not needed when:
1881 a) Garbage collection has removed all references to the
1883 b) We know for certain the symbol is defined in this
1884 object, and it's not a weak definition, nor is the symbol
1885 used by a plabel relocation. Either this object is the
1886 application or we are doing a shared symbolic link. */
1888 /* As a special sop to the hppa ABI, we keep a .plt entry
1889 for functions in sections containing PIC code. */
1891 && h
->plt
.refcount
> 0
1892 && (h
->root
.type
== bfd_link_hash_defined
1893 || h
->root
.type
== bfd_link_hash_defweak
)
1894 && (h
->root
.u
.def
.section
->flags
& SEC_HAS_GOT_REF
) != 0)
1896 ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
= 1;
1900 h
->plt
.offset
= (bfd_vma
) -1;
1901 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1906 /* Make an entry in the .plt section. */
1908 h
->plt
.offset
= s
->_raw_size
;
1909 if (PLABEL_PLT_ENTRY_SIZE
!= PLT_ENTRY_SIZE
1910 && ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
1911 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1913 /* Add some extra space for the dynamic linker to use. */
1914 s
->_raw_size
+= PLABEL_PLT_ENTRY_SIZE
;
1917 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1919 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
)
1921 /* Make sure this symbol is output as a dynamic symbol. */
1922 if (h
->dynindx
== -1
1923 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1925 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1929 /* We also need to make an entry in the .rela.plt section. */
1930 s
= hplink
->srelplt
;
1931 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
1933 hplink
->need_plt_stub
= 1;
1938 /* If this is a weak symbol, and there is a real definition, the
1939 processor independent code will have arranged for us to see the
1940 real definition first, and we can just use the same value. */
1941 if (h
->weakdef
!= NULL
)
1943 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
1944 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
1945 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1946 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1950 /* This is a reference to a symbol defined by a dynamic object which
1951 is not a function. */
1953 /* If we are creating a shared library, we must presume that the
1954 only references to the symbol are via the global offset table.
1955 For such cases we need not do anything here; the relocations will
1956 be handled correctly by relocate_section. */
1960 /* If there are no references to this symbol that do not use the
1961 GOT, we don't need to generate a copy reloc. */
1962 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
1965 /* We must allocate the symbol in our .dynbss section, which will
1966 become part of the .bss section of the executable. There will be
1967 an entry for this symbol in the .dynsym section. The dynamic
1968 object will contain position independent code, so all references
1969 from the dynamic object to this symbol will go through the global
1970 offset table. The dynamic linker will use the .dynsym entry to
1971 determine the address it must put in the global offset table, so
1972 both the dynamic object and the regular object will refer to the
1973 same memory location for the variable. */
1975 s
= hplink
->sdynbss
;
1977 /* We must generate a COPY reloc to tell the dynamic linker to
1978 copy the initial value out of the dynamic object and into the
1979 runtime process image. We need to remember the offset into the
1980 .rela.bss section we are going to use. */
1981 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1985 srel
= hplink
->srelbss
;
1986 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
1987 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
1991 /* We need to figure out the alignment required for this symbol. I
1992 have no idea how other ELF linkers handle this. */
1993 unsigned int power_of_two
;
1995 power_of_two
= bfd_log2 (h
->size
);
1996 if (power_of_two
> 3)
1999 /* Apply the required alignment. */
2000 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
2001 (bfd_size_type
) (1 << power_of_two
));
2002 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
2004 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
2008 /* Define the symbol as being at this point in the section. */
2009 h
->root
.u
.def
.section
= s
;
2010 h
->root
.u
.def
.value
= s
->_raw_size
;
2012 /* Increment the section size to make room for the symbol. */
2013 s
->_raw_size
+= h
->size
;
2018 /* Called via elf_link_hash_traverse to create .plt entries for an
2019 application that uses statically linked PIC functions. Similar to
2020 the first part of elf32_hppa_adjust_dynamic_symbol. */
2023 hppa_handle_PIC_calls (h
, inf
)
2024 struct elf_link_hash_entry
*h
;
2027 struct bfd_link_info
*info
;
2029 struct elf32_hppa_link_hash_table
*hplink
;
2032 if (! (h
->plt
.refcount
> 0
2033 && (h
->root
.type
== bfd_link_hash_defined
2034 || h
->root
.type
== bfd_link_hash_defweak
)
2035 && (h
->root
.u
.def
.section
->flags
& SEC_HAS_GOT_REF
) != 0))
2037 h
->plt
.offset
= (bfd_vma
) -1;
2038 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2042 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2043 ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
= 1;
2045 info
= (struct bfd_link_info
*) inf
;
2046 hplink
= hppa_link_hash_table (info
);
2047 dynobj
= hplink
->root
.dynobj
;
2049 /* Make an entry in the .plt section. */
2051 h
->plt
.offset
= s
->_raw_size
;
2052 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2057 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
2058 || RELATIVE_DYNAMIC_RELOCS)
2059 /* This function is called via elf_link_hash_traverse to discard space
2060 we allocated for relocs that it turned out we didn't need. */
2063 hppa_discard_copies (h
, inf
)
2064 struct elf_link_hash_entry
*h
;
2067 struct elf32_hppa_dyn_reloc_entry
*s
;
2068 struct elf32_hppa_link_hash_entry
*eh
;
2069 struct bfd_link_info
*info
;
2071 eh
= (struct elf32_hppa_link_hash_entry
*) h
;
2072 info
= (struct bfd_link_info
*) inf
;
2074 #if ! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT
2075 /* Handle the stub reloc case. If we have a plt entry for the
2076 function, we won't be needing long branch stubs. s->count will
2077 only be zero for stub relocs, which provides a handy way of
2078 flagging these relocs, and means we need do nothing special for
2079 the forced local and symbolic link case. */
2080 if (eh
->stub_reloc_sec
!= NULL
2081 && eh
->elf
.plt
.offset
!= (bfd_vma
) -1)
2083 for (s
= eh
->reloc_entries
; s
!= NULL
; s
= s
->next
)
2085 s
->section
->_raw_size
-= sizeof (Elf32_External_Rela
);
2089 #if RELATIVE_DYNAMIC_RELOCS
2090 /* If a symbol has been forced local or we have found a regular
2091 definition for the symbolic link case, then we won't be needing
2093 if (eh
->elf
.dynindx
== -1
2094 || ((eh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
2095 && !is_absolute_reloc (r_type
)
2098 for (s
= eh
->reloc_entries
; s
!= NULL
; s
= s
->next
)
2099 s
->section
->_raw_size
-= s
->count
* sizeof (Elf32_External_Rela
);
2107 /* This function is called via elf_link_hash_traverse to force
2108 millicode symbols local so they do not end up as globals in the
2109 dynamic symbol table. We ought to be able to do this in
2110 adjust_dynamic_symbol, but our adjust_dynamic_symbol is not called
2111 for all dynamic symbols. Arguably, this is a bug in
2112 elf_adjust_dynamic_symbol. */
2115 clobber_millicode_symbols (h
, info
)
2116 struct elf_link_hash_entry
*h
;
2117 struct bfd_link_info
*info
;
2119 /* Note! We only want to remove these from the dynamic symbol
2120 table. Therefore we do not set ELF_LINK_FORCED_LOCAL. */
2121 if (h
->type
== STT_PARISC_MILLI
)
2122 elf32_hppa_hide_symbol(info
, h
);
2126 /* Set the sizes of the dynamic sections. */
2129 elf32_hppa_size_dynamic_sections (output_bfd
, info
)
2131 struct bfd_link_info
*info
;
2133 struct elf32_hppa_link_hash_table
*hplink
;
2139 hplink
= hppa_link_hash_table (info
);
2140 dynobj
= hplink
->root
.dynobj
;
2141 BFD_ASSERT (dynobj
!= NULL
);
2143 if (hplink
->root
.dynamic_sections_created
)
2147 /* Set the contents of the .interp section to the interpreter. */
2150 s
= bfd_get_section_by_name (dynobj
, ".interp");
2151 BFD_ASSERT (s
!= NULL
);
2152 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2153 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2156 /* Force millicode symbols local. */
2157 elf_link_hash_traverse (&hplink
->root
,
2158 clobber_millicode_symbols
,
2161 /* Set up .plt offsets for local plabels. */
2162 for (i
= info
->input_bfds
; i
; i
= i
->link_next
)
2164 bfd_signed_vma
*local_plt
;
2165 bfd_signed_vma
*end_local_plt
;
2166 bfd_size_type locsymcount
;
2167 Elf_Internal_Shdr
*symtab_hdr
;
2169 local_plt
= elf_local_got_refcounts (i
);
2173 symtab_hdr
= &elf_tdata (i
)->symtab_hdr
;
2174 locsymcount
= symtab_hdr
->sh_info
;
2175 local_plt
+= locsymcount
;
2176 end_local_plt
= local_plt
+ locsymcount
;
2178 for (; local_plt
< end_local_plt
; ++local_plt
)
2183 *local_plt
= s
->_raw_size
;
2184 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2186 hplink
->srelplt
->_raw_size
+= sizeof (Elf32_External_Rela
);
2189 *local_plt
= (bfd_vma
) -1;
2195 /* Run through the function symbols, looking for any that are
2196 PIC, and allocate space for the necessary .plt entries so
2197 that %r19 will be set up. */
2199 elf_link_hash_traverse (&hplink
->root
,
2200 hppa_handle_PIC_calls
,
2203 /* We may have created entries in the .rela.got section.
2204 However, if we are not creating the dynamic sections, we will
2205 not actually use these entries. Reset the size of .rela.got,
2206 which will cause it to get stripped from the output file
2208 hplink
->srelgot
->_raw_size
= 0;
2211 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
2212 || RELATIVE_DYNAMIC_RELOCS)
2213 /* If this is a -Bsymbolic shared link, then we need to discard all
2214 relocs against symbols defined in a regular object. We also need
2215 to lose relocs we've allocated for long branch stubs if we know
2216 we won't be generating a stub. */
2218 elf_link_hash_traverse (&hplink
->root
,
2219 hppa_discard_copies
,
2223 /* The check_relocs and adjust_dynamic_symbol entry points have
2224 determined the sizes of the various dynamic sections. Allocate
2228 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2232 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2235 /* It's OK to base decisions on the section name, because none
2236 of the dynobj section names depend upon the input files. */
2237 name
= bfd_get_section_name (dynobj
, s
);
2239 if (strncmp (name
, ".rela", 5) == 0)
2241 if (s
->_raw_size
!= 0)
2244 const char *outname
;
2246 /* Remember whether there are any reloc sections other
2248 if (strcmp (name
+5, ".plt") != 0)
2251 /* If this relocation section applies to a read only
2252 section, then we probably need a DT_TEXTREL entry. */
2253 outname
= bfd_get_section_name (output_bfd
,
2255 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
2257 && (target
->flags
& SEC_READONLY
) != 0
2258 && (target
->flags
& SEC_ALLOC
) != 0)
2261 /* We use the reloc_count field as a counter if we need
2262 to copy relocs into the output file. */
2266 else if (strcmp (name
, ".plt") == 0)
2268 if (hplink
->need_plt_stub
)
2270 /* Make space for the plt stub at the end of the .plt
2271 section. We want this stub right at the end, up
2272 against the .got section. */
2273 int gotalign
= bfd_section_alignment (dynobj
, hplink
->sgot
);
2274 int pltalign
= bfd_section_alignment (dynobj
, s
);
2277 if (gotalign
> pltalign
)
2278 bfd_set_section_alignment (dynobj
, s
, gotalign
);
2279 mask
= ((bfd_size_type
) 1 << gotalign
) - 1;
2280 s
->_raw_size
= (s
->_raw_size
+ sizeof (plt_stub
) + mask
) & ~mask
;
2283 else if (strcmp (name
, ".got") == 0)
2287 /* It's not one of our sections, so don't allocate space. */
2291 if (s
->_raw_size
== 0)
2293 /* If we don't need this section, strip it from the
2294 output file. This is mostly to handle .rela.bss and
2295 .rela.plt. We must create both sections in
2296 create_dynamic_sections, because they must be created
2297 before the linker maps input sections to output
2298 sections. The linker does that before
2299 adjust_dynamic_symbol is called, and it is that
2300 function which decides whether anything needs to go
2301 into these sections. */
2302 _bfd_strip_section_from_output (info
, s
);
2306 /* Allocate memory for the section contents. Zero it, because
2307 we may not fill in all the reloc sections. */
2308 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
2309 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
2313 if (hplink
->root
.dynamic_sections_created
)
2315 /* Like IA-64 and HPPA64, always create a DT_PLTGOT. It
2316 actually has nothing to do with the PLT, it is how we
2317 communicate the LTP value of a load module to the dynamic
2319 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
2322 /* Add some entries to the .dynamic section. We fill in the
2323 values later, in elf32_hppa_finish_dynamic_sections, but we
2324 must add the entries now so that we get the correct size for
2325 the .dynamic section. The DT_DEBUG entry is filled in by the
2326 dynamic linker and used by the debugger. */
2329 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
2333 if (hplink
->srelplt
->_raw_size
!= 0)
2335 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
2336 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
2337 || ! bfd_elf32_add_dynamic_entry (info
, DT_JMPREL
, 0))
2343 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELA
, 0)
2344 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELASZ
, 0)
2345 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELAENT
,
2346 sizeof (Elf32_External_Rela
)))
2352 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
2354 info
->flags
|= DF_TEXTREL
;
2361 /* External entry points for sizing and building linker stubs. */
2363 /* Determine and set the size of the stub section for a final link.
2365 The basic idea here is to examine all the relocations looking for
2366 PC-relative calls to a target that is unreachable with a "bl"
2370 elf32_hppa_size_stubs (output_bfd
, stub_bfd
, info
, multi_subspace
, group_size
,
2371 add_stub_section
, layout_sections_again
)
2374 struct bfd_link_info
*info
;
2375 boolean multi_subspace
;
2376 bfd_signed_vma group_size
;
2377 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
2378 void (*layout_sections_again
) PARAMS ((void));
2382 asection
**input_list
, **list
;
2383 Elf_Internal_Sym
*local_syms
, **all_local_syms
;
2384 unsigned int bfd_indx
, bfd_count
;
2385 int top_id
, top_index
;
2386 struct elf32_hppa_link_hash_table
*hplink
;
2387 bfd_size_type stub_group_size
;
2388 boolean stubs_always_before_branch
;
2389 boolean stub_changed
= 0;
2392 hplink
= hppa_link_hash_table (info
);
2394 /* Stash our params away. */
2395 hplink
->stub_bfd
= stub_bfd
;
2396 hplink
->multi_subspace
= multi_subspace
;
2397 hplink
->add_stub_section
= add_stub_section
;
2398 hplink
->layout_sections_again
= layout_sections_again
;
2399 stubs_always_before_branch
= group_size
< 0;
2401 stub_group_size
= -group_size
;
2403 stub_group_size
= group_size
;
2404 if (stub_group_size
== 1)
2406 /* Default values. */
2407 stub_group_size
= 8000000;
2408 if (hplink
->has_17bit_branch
|| hplink
->multi_subspace
)
2409 stub_group_size
= 250000;
2410 if (hplink
->has_12bit_branch
)
2411 stub_group_size
= 7812;
2414 /* Count the number of input BFDs and find the top input section id. */
2415 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
2417 input_bfd
= input_bfd
->link_next
)
2420 for (section
= input_bfd
->sections
;
2422 section
= section
->next
)
2424 if (top_id
< section
->id
)
2425 top_id
= section
->id
;
2430 = (struct map_stub
*) bfd_zmalloc (sizeof (struct map_stub
) * (top_id
+ 1));
2431 if (hplink
->stub_group
== NULL
)
2434 /* Make a list of input sections for each output section included in
2437 We can't use output_bfd->section_count here to find the top output
2438 section index as some sections may have been removed, and
2439 _bfd_strip_section_from_output doesn't renumber the indices. */
2440 for (section
= output_bfd
->sections
, top_index
= 0;
2442 section
= section
->next
)
2444 if (top_index
< section
->index
)
2445 top_index
= section
->index
;
2449 = (asection
**) bfd_malloc (sizeof (asection
*) * (top_index
+ 1));
2450 if (input_list
== NULL
)
2453 /* For sections we aren't interested in, mark their entries with a
2454 value we can check later. */
2455 list
= input_list
+ top_index
;
2457 *list
= bfd_abs_section_ptr
;
2458 while (list
-- != input_list
);
2460 for (section
= output_bfd
->sections
;
2462 section
= section
->next
)
2464 if ((section
->flags
& SEC_CODE
) != 0)
2465 input_list
[section
->index
] = NULL
;
2468 /* Now actually build the lists. */
2469 for (input_bfd
= info
->input_bfds
;
2471 input_bfd
= input_bfd
->link_next
)
2473 for (section
= input_bfd
->sections
;
2475 section
= section
->next
)
2477 if (section
->output_section
!= NULL
2478 && section
->output_section
->owner
== output_bfd
2479 && section
->output_section
->index
<= top_index
)
2481 list
= input_list
+ section
->output_section
->index
;
2482 if (*list
!= bfd_abs_section_ptr
)
2484 /* Steal the link_sec pointer for our list. */
2485 #define PREV_SEC(sec) (hplink->stub_group[(sec)->id].link_sec)
2486 /* This happens to make the list in reverse order,
2487 which is what we want. */
2488 PREV_SEC (section
) = *list
;
2495 /* See whether we can group stub sections together. Grouping stub
2496 sections may result in fewer stubs. More importantly, we need to
2497 put all .init* and .fini* stubs at the beginning of the .init or
2498 .fini output sections respectively, because glibc splits the
2499 _init and _fini functions into multiple parts. Putting a stub in
2500 the middle of a function is not a good idea. */
2501 list
= input_list
+ top_index
;
2504 asection
*tail
= *list
;
2505 if (tail
== bfd_abs_section_ptr
)
2507 while (tail
!= NULL
)
2511 bfd_size_type total
;
2514 if (tail
->_cooked_size
)
2515 total
= tail
->_cooked_size
;
2517 total
= tail
->_raw_size
;
2518 while ((prev
= PREV_SEC (curr
)) != NULL
2519 && ((total
+= curr
->output_offset
- prev
->output_offset
)
2523 /* OK, the size from the start of CURR to the end is less
2524 than 250000 bytes and thus can be handled by one stub
2525 section. (or the tail section is itself larger than
2526 250000 bytes, in which case we may be toast.)
2527 We should really be keeping track of the total size of
2528 stubs added here, as stubs contribute to the final output
2529 section size. That's a little tricky, and this way will
2530 only break if stubs added total more than 12144 bytes, or
2531 1518 long branch stubs. It seems unlikely for more than
2532 1518 different functions to be called, especially from
2533 code only 250000 bytes long. */
2536 prev
= PREV_SEC (tail
);
2537 /* Set up this stub group. */
2538 hplink
->stub_group
[tail
->id
].link_sec
= curr
;
2540 while (tail
!= curr
&& (tail
= prev
) != NULL
);
2542 /* But wait, there's more! Input sections up to 250000
2543 bytes before the stub section can be handled by it too. */
2544 if (!stubs_always_before_branch
)
2548 && ((total
+= tail
->output_offset
- prev
->output_offset
)
2552 prev
= PREV_SEC (tail
);
2553 hplink
->stub_group
[tail
->id
].link_sec
= curr
;
2559 while (list
-- != input_list
);
2563 /* We want to read in symbol extension records only once. To do this
2564 we need to read in the local symbols in parallel and save them for
2565 later use; so hold pointers to the local symbols in an array. */
2567 = (Elf_Internal_Sym
**) bfd_zmalloc (sizeof (Elf_Internal_Sym
*)
2569 if (all_local_syms
== NULL
)
2572 /* Walk over all the input BFDs, swapping in local symbols.
2573 If we are creating a shared library, create hash entries for the
2575 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
2577 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
2579 Elf_Internal_Shdr
*symtab_hdr
;
2580 Elf_Internal_Sym
*isym
;
2581 Elf32_External_Sym
*ext_syms
, *esym
, *end_sy
;
2583 /* We'll need the symbol table in a second. */
2584 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2585 if (symtab_hdr
->sh_info
== 0)
2588 /* We need an array of the local symbols attached to the input bfd.
2589 Unfortunately, we're going to have to read & swap them in. */
2590 local_syms
= (Elf_Internal_Sym
*)
2591 bfd_malloc (symtab_hdr
->sh_info
* sizeof (Elf_Internal_Sym
));
2592 if (local_syms
== NULL
)
2594 goto error_ret_free_local
;
2596 all_local_syms
[bfd_indx
] = local_syms
;
2597 ext_syms
= (Elf32_External_Sym
*)
2598 bfd_malloc (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
));
2599 if (ext_syms
== NULL
)
2601 goto error_ret_free_local
;
2604 if (bfd_seek (input_bfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
2605 || (bfd_read (ext_syms
, 1,
2606 (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
)),
2608 != (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
))))
2611 goto error_ret_free_local
;
2614 /* Swap the local symbols in. */
2617 for (end_sy
= esym
+ symtab_hdr
->sh_info
; esym
< end_sy
; esym
++, isym
++)
2618 bfd_elf32_swap_symbol_in (input_bfd
, esym
, isym
);
2620 /* Now we can free the external symbols. */
2623 #if ! LONG_BRANCH_PIC_IN_SHLIB
2624 /* If this is a shared link, find all the stub reloc sections. */
2626 for (section
= input_bfd
->sections
;
2628 section
= section
->next
)
2631 asection
*reloc_sec
;
2633 name
= bfd_malloc (strlen (section
->name
)
2634 + sizeof STUB_SUFFIX
2638 sprintf (name
, ".rela%s%s", section
->name
, STUB_SUFFIX
);
2639 reloc_sec
= bfd_get_section_by_name (hplink
->root
.dynobj
, name
);
2640 hplink
->stub_group
[section
->id
].reloc_sec
= reloc_sec
;
2645 if (info
->shared
&& hplink
->multi_subspace
)
2647 struct elf_link_hash_entry
**sym_hashes
;
2648 struct elf_link_hash_entry
**end_hashes
;
2649 unsigned int symcount
;
2651 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
2652 - symtab_hdr
->sh_info
);
2653 sym_hashes
= elf_sym_hashes (input_bfd
);
2654 end_hashes
= sym_hashes
+ symcount
;
2656 /* Look through the global syms for functions; We need to
2657 build export stubs for all globally visible functions. */
2658 for (; sym_hashes
< end_hashes
; sym_hashes
++)
2660 struct elf32_hppa_link_hash_entry
*hash
;
2662 hash
= (struct elf32_hppa_link_hash_entry
*) *sym_hashes
;
2664 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
2665 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
2666 hash
= ((struct elf32_hppa_link_hash_entry
*)
2667 hash
->elf
.root
.u
.i
.link
);
2669 /* At this point in the link, undefined syms have been
2670 resolved, so we need to check that the symbol was
2671 defined in this BFD. */
2672 if ((hash
->elf
.root
.type
== bfd_link_hash_defined
2673 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
2674 && hash
->elf
.type
== STT_FUNC
2675 && hash
->elf
.root
.u
.def
.section
->output_section
!= NULL
2676 && (hash
->elf
.root
.u
.def
.section
->output_section
->owner
2678 && hash
->elf
.root
.u
.def
.section
->owner
== input_bfd
2679 && (hash
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
2680 && !(hash
->elf
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
2681 && ELF_ST_VISIBILITY (hash
->elf
.other
) == STV_DEFAULT
)
2684 const char *stub_name
;
2685 struct elf32_hppa_stub_hash_entry
*stub_entry
;
2687 sec
= hash
->elf
.root
.u
.def
.section
;
2688 stub_name
= hash
->elf
.root
.root
.string
;
2689 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
,
2692 if (stub_entry
== NULL
)
2694 stub_entry
= hppa_add_stub (stub_name
, sec
, hplink
);
2696 goto error_ret_free_local
;
2698 stub_entry
->target_value
= hash
->elf
.root
.u
.def
.value
;
2699 stub_entry
->target_section
= hash
->elf
.root
.u
.def
.section
;
2700 stub_entry
->stub_type
= hppa_stub_export
;
2701 stub_entry
->h
= hash
;
2706 (*_bfd_error_handler
) (_("%s: duplicate export stub %s"),
2707 bfd_get_filename (input_bfd
),
2719 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
2721 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
2723 Elf_Internal_Shdr
*symtab_hdr
;
2725 /* We'll need the symbol table in a second. */
2726 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2727 if (symtab_hdr
->sh_info
== 0)
2730 local_syms
= all_local_syms
[bfd_indx
];
2732 /* Walk over each section attached to the input bfd. */
2733 for (section
= input_bfd
->sections
;
2735 section
= section
->next
)
2737 Elf_Internal_Shdr
*input_rel_hdr
;
2738 Elf32_External_Rela
*external_relocs
, *erelaend
, *erela
;
2739 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
2741 /* If there aren't any relocs, then there's nothing more
2743 if ((section
->flags
& SEC_RELOC
) == 0
2744 || section
->reloc_count
== 0)
2747 /* If this section is a link-once section that will be
2748 discarded, then don't create any stubs. */
2749 if (section
->output_section
== NULL
2750 || section
->output_section
->owner
!= output_bfd
)
2753 /* Allocate space for the external relocations. */
2755 = ((Elf32_External_Rela
*)
2756 bfd_malloc (section
->reloc_count
2757 * sizeof (Elf32_External_Rela
)));
2758 if (external_relocs
== NULL
)
2760 goto error_ret_free_local
;
2763 /* Likewise for the internal relocations. */
2764 internal_relocs
= ((Elf_Internal_Rela
*)
2765 bfd_malloc (section
->reloc_count
2766 * sizeof (Elf_Internal_Rela
)));
2767 if (internal_relocs
== NULL
)
2769 free (external_relocs
);
2770 goto error_ret_free_local
;
2773 /* Read in the external relocs. */
2774 input_rel_hdr
= &elf_section_data (section
)->rel_hdr
;
2775 if (bfd_seek (input_bfd
, input_rel_hdr
->sh_offset
, SEEK_SET
) != 0
2776 || bfd_read (external_relocs
, 1,
2777 input_rel_hdr
->sh_size
,
2778 input_bfd
) != input_rel_hdr
->sh_size
)
2780 free (external_relocs
);
2781 error_ret_free_internal
:
2782 free (internal_relocs
);
2783 goto error_ret_free_local
;
2786 /* Swap in the relocs. */
2787 erela
= external_relocs
;
2788 erelaend
= erela
+ section
->reloc_count
;
2789 irela
= internal_relocs
;
2790 for (; erela
< erelaend
; erela
++, irela
++)
2791 bfd_elf32_swap_reloca_in (input_bfd
, erela
, irela
);
2793 /* We're done with the external relocs, free them. */
2794 free (external_relocs
);
2796 /* Now examine each relocation. */
2797 irela
= internal_relocs
;
2798 irelaend
= irela
+ section
->reloc_count
;
2799 for (; irela
< irelaend
; irela
++)
2801 unsigned int r_type
, r_indx
;
2802 enum elf32_hppa_stub_type stub_type
;
2803 struct elf32_hppa_stub_hash_entry
*stub_entry
;
2806 bfd_vma destination
;
2807 struct elf32_hppa_link_hash_entry
*hash
;
2809 const asection
*id_sec
;
2811 r_type
= ELF32_R_TYPE (irela
->r_info
);
2812 r_indx
= ELF32_R_SYM (irela
->r_info
);
2814 if (r_type
>= (unsigned int) R_PARISC_UNIMPLEMENTED
)
2816 bfd_set_error (bfd_error_bad_value
);
2817 goto error_ret_free_internal
;
2820 /* Only look for stubs on call instructions. */
2821 if (r_type
!= (unsigned int) R_PARISC_PCREL12F
2822 && r_type
!= (unsigned int) R_PARISC_PCREL17F
2823 && r_type
!= (unsigned int) R_PARISC_PCREL22F
)
2826 /* Now determine the call target, its name, value,
2832 if (r_indx
< symtab_hdr
->sh_info
)
2834 /* It's a local symbol. */
2835 Elf_Internal_Sym
*sym
;
2836 Elf_Internal_Shdr
*hdr
;
2838 sym
= local_syms
+ r_indx
;
2839 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
2840 sym_sec
= hdr
->bfd_section
;
2841 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
2842 sym_value
= sym
->st_value
;
2843 destination
= (sym_value
+ irela
->r_addend
2844 + sym_sec
->output_offset
2845 + sym_sec
->output_section
->vma
);
2849 /* It's an external symbol. */
2852 e_indx
= r_indx
- symtab_hdr
->sh_info
;
2853 hash
= ((struct elf32_hppa_link_hash_entry
*)
2854 elf_sym_hashes (input_bfd
)[e_indx
]);
2856 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
2857 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
2858 hash
= ((struct elf32_hppa_link_hash_entry
*)
2859 hash
->elf
.root
.u
.i
.link
);
2861 if (hash
->elf
.root
.type
== bfd_link_hash_defined
2862 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
2864 sym_sec
= hash
->elf
.root
.u
.def
.section
;
2865 sym_value
= hash
->elf
.root
.u
.def
.value
;
2866 if (sym_sec
->output_section
!= NULL
)
2867 destination
= (sym_value
+ irela
->r_addend
2868 + sym_sec
->output_offset
2869 + sym_sec
->output_section
->vma
);
2871 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
)
2876 else if (hash
->elf
.root
.type
== bfd_link_hash_undefined
)
2879 && !info
->no_undefined
2880 && (ELF_ST_VISIBILITY (hash
->elf
.other
)
2886 bfd_set_error (bfd_error_bad_value
);
2887 goto error_ret_free_internal
;
2891 /* Determine what (if any) linker stub is needed. */
2892 stub_type
= hppa_type_of_stub (section
, irela
, hash
,
2894 if (stub_type
== hppa_stub_none
)
2897 /* Support for grouping stub sections. */
2898 id_sec
= hplink
->stub_group
[section
->id
].link_sec
;
2900 /* Get the name of this stub. */
2901 stub_name
= hppa_stub_name (id_sec
, sym_sec
, hash
, irela
);
2903 goto error_ret_free_internal
;
2905 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
,
2908 if (stub_entry
!= NULL
)
2910 /* The proper stub has already been created. */
2915 stub_entry
= hppa_add_stub (stub_name
, section
, hplink
);
2916 if (stub_entry
== NULL
)
2919 goto error_ret_free_local
;
2922 stub_entry
->target_value
= sym_value
;
2923 stub_entry
->target_section
= sym_sec
;
2924 stub_entry
->stub_type
= stub_type
;
2927 if (stub_type
== hppa_stub_import
)
2928 stub_entry
->stub_type
= hppa_stub_import_shared
;
2929 else if (stub_type
== hppa_stub_long_branch
2930 && (LONG_BRANCH_PIC_IN_SHLIB
|| hash
== NULL
))
2931 stub_entry
->stub_type
= hppa_stub_long_branch_shared
;
2933 stub_entry
->h
= hash
;
2937 /* We're done with the internal relocs, free them. */
2938 free (internal_relocs
);
2945 /* OK, we've added some stubs. Find out the new size of the
2947 for (stub_sec
= hplink
->stub_bfd
->sections
;
2949 stub_sec
= stub_sec
->next
)
2951 stub_sec
->_raw_size
= 0;
2952 stub_sec
->_cooked_size
= 0;
2954 #if ! LONG_BRANCH_PIC_IN_SHLIB
2958 for (i
= top_id
; i
>= 0; --i
)
2960 /* This will probably hit the same section many times.. */
2961 stub_sec
= hplink
->stub_group
[i
].reloc_sec
;
2962 if (stub_sec
!= NULL
)
2964 stub_sec
->_raw_size
= 0;
2965 stub_sec
->_cooked_size
= 0;
2971 bfd_hash_traverse (&hplink
->stub_hash_table
,
2975 /* Ask the linker to do its stuff. */
2976 (*hplink
->layout_sections_again
) ();
2982 error_ret_free_local
:
2983 while (bfd_count
-- > 0)
2984 if (all_local_syms
[bfd_count
])
2985 free (all_local_syms
[bfd_count
]);
2986 free (all_local_syms
);
2991 /* For a final link, this function is called after we have sized the
2992 stubs to provide a value for __gp. */
2995 elf32_hppa_set_gp (abfd
, info
)
2997 struct bfd_link_info
*info
;
2999 struct elf32_hppa_link_hash_table
*hplink
;
3000 struct elf_link_hash_entry
*h
;
3004 hplink
= hppa_link_hash_table (info
);
3005 h
= elf_link_hash_lookup (&hplink
->root
, "$global$",
3006 false, false, false);
3008 if (h
!= NULL
&& h
->root
.type
== bfd_link_hash_defined
)
3010 gp_val
= h
->root
.u
.def
.value
;
3011 sec
= h
->root
.u
.def
.section
;
3015 /* Choose to point our LTP at, in this order, one of .plt, .got,
3016 or .data, if these sections exist. In the case of choosing
3017 .plt try to make the LTP ideal for addressing anywhere in the
3018 .plt or .got with a 14 bit signed offset. Typically, the end
3019 of the .plt is the start of the .got, so choose .plt + 0x2000
3020 if either the .plt or .got is larger than 0x2000. If both
3021 the .plt and .got are smaller than 0x2000, choose the end of
3022 the .plt section. */
3027 gp_val
= sec
->_raw_size
;
3029 || (hplink
->sgot
&& hplink
->sgot
->_raw_size
> 0x2000))
3040 /* We know we don't have a .plt. If .got is large,
3042 if (sec
->_raw_size
> 0x2000)
3047 /* No .plt or .got. Who cares what the LTP is? */
3048 sec
= bfd_get_section_by_name (abfd
, ".data");
3054 gp_val
+= sec
->output_section
->vma
+ sec
->output_offset
;
3056 elf_gp (abfd
) = gp_val
;
3060 /* Build all the stubs associated with the current output file. The
3061 stubs are kept in a hash table attached to the main linker hash
3062 table. We also set up the .plt entries for statically linked PIC
3063 functions here. This function is called via hppaelf_finish in the
3067 elf32_hppa_build_stubs (info
)
3068 struct bfd_link_info
*info
;
3071 struct bfd_hash_table
*table
;
3072 struct elf32_hppa_link_hash_table
*hplink
;
3074 hplink
= hppa_link_hash_table (info
);
3076 for (stub_sec
= hplink
->stub_bfd
->sections
;
3078 stub_sec
= stub_sec
->next
)
3082 /* Allocate memory to hold the linker stubs. */
3083 size
= stub_sec
->_raw_size
;
3084 stub_sec
->contents
= (unsigned char *) bfd_zalloc (hplink
->stub_bfd
,
3086 if (stub_sec
->contents
== NULL
&& size
!= 0)
3088 stub_sec
->_raw_size
= 0;
3091 /* Build the stubs as directed by the stub hash table. */
3092 table
= &hplink
->stub_hash_table
;
3093 bfd_hash_traverse (table
, hppa_build_one_stub
, info
);
3098 /* Perform a relocation as part of a final link. */
3100 static bfd_reloc_status_type
3101 final_link_relocate (input_section
, contents
, rel
, value
, hplink
, sym_sec
, h
)
3102 asection
*input_section
;
3104 const Elf_Internal_Rela
*rel
;
3106 struct elf32_hppa_link_hash_table
*hplink
;
3108 struct elf32_hppa_link_hash_entry
*h
;
3111 unsigned int r_type
= ELF32_R_TYPE (rel
->r_info
);
3112 reloc_howto_type
*howto
= elf_hppa_howto_table
+ r_type
;
3113 int r_format
= howto
->bitsize
;
3114 enum hppa_reloc_field_selector_type_alt r_field
;
3115 bfd
*input_bfd
= input_section
->owner
;
3116 bfd_vma offset
= rel
->r_offset
;
3117 bfd_vma max_branch_offset
= 0;
3118 bfd_byte
*hit_data
= contents
+ offset
;
3119 bfd_signed_vma addend
= rel
->r_addend
;
3121 struct elf32_hppa_stub_hash_entry
*stub_entry
= NULL
;
3124 if (r_type
== R_PARISC_NONE
)
3125 return bfd_reloc_ok
;
3127 insn
= bfd_get_32 (input_bfd
, hit_data
);
3129 /* Find out where we are and where we're going. */
3130 location
= (offset
+
3131 input_section
->output_offset
+
3132 input_section
->output_section
->vma
);
3136 case R_PARISC_PCREL12F
:
3137 case R_PARISC_PCREL17F
:
3138 case R_PARISC_PCREL22F
:
3139 /* If this is a call to a function defined in another dynamic
3140 library, or if it is a call to a PIC function in the same
3141 object, or if this is a shared link and it is a call to a
3142 weak symbol which may or may not be in the same object, then
3143 find the import stub in the stub hash. */
3145 || sym_sec
->output_section
== NULL
3148 || (h
->elf
.root
.type
== bfd_link_hash_defweak
3149 && h
->elf
.dynindx
!= -1
3150 && h
->elf
.plt
.offset
!= (bfd_vma
) -1))))
3152 stub_entry
= hppa_get_stub_entry (input_section
, sym_sec
,
3154 if (stub_entry
!= NULL
)
3156 value
= (stub_entry
->stub_offset
3157 + stub_entry
->stub_sec
->output_offset
3158 + stub_entry
->stub_sec
->output_section
->vma
);
3161 else if (sym_sec
== NULL
&& h
!= NULL
3162 && h
->elf
.root
.type
== bfd_link_hash_undefweak
)
3164 /* It's OK if undefined weak. Make undefined weak
3165 branches go nowhere. */
3170 return bfd_reloc_notsupported
;
3174 case R_PARISC_PCREL21L
:
3175 case R_PARISC_PCREL17C
:
3176 case R_PARISC_PCREL17R
:
3177 case R_PARISC_PCREL14R
:
3178 case R_PARISC_PCREL14F
:
3179 /* Make it a pc relative offset. */
3184 case R_PARISC_DPREL21L
:
3185 case R_PARISC_DPREL14R
:
3186 case R_PARISC_DPREL14F
:
3187 /* For all the DP relative relocations, we need to examine the symbol's
3188 section. If it's a code section, then "data pointer relative" makes
3189 no sense. In that case we don't adjust the "value", and for 21 bit
3190 addil instructions, we change the source addend register from %dp to
3191 %r0. This situation commonly arises when a variable's "constness"
3192 is declared differently from the way the variable is defined. For
3193 instance: "extern int foo" with foo defined as "const int foo". */
3194 if (sym_sec
== NULL
)
3196 if ((sym_sec
->flags
& SEC_CODE
) != 0)
3198 if ((insn
& ((0x3f << 26) | (0x1f << 21)))
3199 == (((int) OP_ADDIL
<< 26) | (27 << 21)))
3201 insn
&= ~ (0x1f << 21);
3202 #if 1 /* debug them. */
3203 (*_bfd_error_handler
)
3204 (_("%s(%s+0x%lx): fixing %s"),
3205 bfd_get_filename (input_bfd
),
3206 input_section
->name
,
3207 (long) rel
->r_offset
,
3211 /* Now try to make things easy for the dynamic linker. */
3217 case R_PARISC_DLTIND21L
:
3218 case R_PARISC_DLTIND14R
:
3219 case R_PARISC_DLTIND14F
:
3220 value
-= elf_gp (input_section
->output_section
->owner
);
3229 case R_PARISC_DIR32
:
3230 case R_PARISC_DIR14F
:
3231 case R_PARISC_DIR17F
:
3232 case R_PARISC_PCREL17C
:
3233 case R_PARISC_PCREL14F
:
3234 case R_PARISC_DPREL14F
:
3235 case R_PARISC_PLABEL32
:
3236 case R_PARISC_DLTIND14F
:
3237 case R_PARISC_SEGBASE
:
3238 case R_PARISC_SEGREL32
:
3242 case R_PARISC_DIR21L
:
3243 case R_PARISC_PCREL21L
:
3244 case R_PARISC_DPREL21L
:
3245 case R_PARISC_PLABEL21L
:
3246 case R_PARISC_DLTIND21L
:
3250 case R_PARISC_DIR17R
:
3251 case R_PARISC_PCREL17R
:
3252 case R_PARISC_DIR14R
:
3253 case R_PARISC_PCREL14R
:
3254 case R_PARISC_DPREL14R
:
3255 case R_PARISC_PLABEL14R
:
3256 case R_PARISC_DLTIND14R
:
3260 case R_PARISC_PCREL12F
:
3261 case R_PARISC_PCREL17F
:
3262 case R_PARISC_PCREL22F
:
3265 if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
3267 max_branch_offset
= (1 << (17-1)) << 2;
3269 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
3271 max_branch_offset
= (1 << (12-1)) << 2;
3275 max_branch_offset
= (1 << (22-1)) << 2;
3278 /* sym_sec is NULL on undefined weak syms or when shared on
3279 undefined syms. We've already checked for a stub for the
3280 shared undefined case. */
3281 if (sym_sec
== NULL
)
3284 /* If the branch is out of reach, then redirect the
3285 call to the local stub for this function. */
3286 if (value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3288 stub_entry
= hppa_get_stub_entry (input_section
, sym_sec
,
3290 if (stub_entry
== NULL
)
3291 return bfd_reloc_notsupported
;
3293 /* Munge up the value and addend so that we call the stub
3294 rather than the procedure directly. */
3295 value
= (stub_entry
->stub_offset
3296 + stub_entry
->stub_sec
->output_offset
3297 + stub_entry
->stub_sec
->output_section
->vma
3303 /* Something we don't know how to handle. */
3305 return bfd_reloc_notsupported
;
3308 /* Make sure we can reach the stub. */
3309 if (max_branch_offset
!= 0
3310 && value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3312 (*_bfd_error_handler
)
3313 (_("%s(%s+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
3314 bfd_get_filename (input_bfd
),
3315 input_section
->name
,
3316 (long) rel
->r_offset
,
3317 stub_entry
->root
.string
);
3318 return bfd_reloc_notsupported
;
3321 val
= hppa_field_adjust (value
, addend
, r_field
);
3325 case R_PARISC_PCREL12F
:
3326 case R_PARISC_PCREL17C
:
3327 case R_PARISC_PCREL17F
:
3328 case R_PARISC_PCREL17R
:
3329 case R_PARISC_PCREL22F
:
3330 case R_PARISC_DIR17F
:
3331 case R_PARISC_DIR17R
:
3332 /* This is a branch. Divide the offset by four.
3333 Note that we need to decide whether it's a branch or
3334 otherwise by inspecting the reloc. Inspecting insn won't
3335 work as insn might be from a .word directive. */
3343 insn
= hppa_rebuild_insn (insn
, val
, r_format
);
3345 /* Update the instruction word. */
3346 bfd_put_32 (input_bfd
, (bfd_vma
) insn
, hit_data
);
3347 return bfd_reloc_ok
;
3350 /* Relocate an HPPA ELF section. */
3353 elf32_hppa_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
3354 contents
, relocs
, local_syms
, local_sections
)
3356 struct bfd_link_info
*info
;
3358 asection
*input_section
;
3360 Elf_Internal_Rela
*relocs
;
3361 Elf_Internal_Sym
*local_syms
;
3362 asection
**local_sections
;
3365 bfd_vma
*local_got_offsets
;
3366 struct elf32_hppa_link_hash_table
*hplink
;
3367 Elf_Internal_Shdr
*symtab_hdr
;
3368 Elf_Internal_Rela
*rel
;
3369 Elf_Internal_Rela
*relend
;
3372 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3374 hplink
= hppa_link_hash_table (info
);
3375 dynobj
= hplink
->root
.dynobj
;
3376 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3380 relend
= relocs
+ input_section
->reloc_count
;
3381 for (; rel
< relend
; rel
++)
3383 unsigned int r_type
;
3384 reloc_howto_type
*howto
;
3385 unsigned int r_symndx
;
3386 struct elf32_hppa_link_hash_entry
*h
;
3387 Elf_Internal_Sym
*sym
;
3390 bfd_reloc_status_type r
;
3391 const char *sym_name
;
3394 r_type
= ELF32_R_TYPE (rel
->r_info
);
3395 if (r_type
>= (unsigned int) R_PARISC_UNIMPLEMENTED
)
3397 bfd_set_error (bfd_error_bad_value
);
3400 if (r_type
== (unsigned int) R_PARISC_GNU_VTENTRY
3401 || r_type
== (unsigned int) R_PARISC_GNU_VTINHERIT
)
3404 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3406 if (info
->relocateable
)
3408 /* This is a relocateable link. We don't have to change
3409 anything, unless the reloc is against a section symbol,
3410 in which case we have to adjust according to where the
3411 section symbol winds up in the output section. */
3412 if (r_symndx
< symtab_hdr
->sh_info
)
3414 sym
= local_syms
+ r_symndx
;
3415 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
3417 sym_sec
= local_sections
[r_symndx
];
3418 rel
->r_addend
+= sym_sec
->output_offset
;
3424 /* This is a final link. */
3428 if (r_symndx
< symtab_hdr
->sh_info
)
3430 /* This is a local symbol, h defaults to NULL. */
3431 sym
= local_syms
+ r_symndx
;
3432 sym_sec
= local_sections
[r_symndx
];
3433 relocation
= ((ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
3434 ? 0 : sym
->st_value
)
3435 + sym_sec
->output_offset
3436 + sym_sec
->output_section
->vma
);
3442 /* It's a global; Find its entry in the link hash. */
3443 indx
= r_symndx
- symtab_hdr
->sh_info
;
3444 h
= ((struct elf32_hppa_link_hash_entry
*)
3445 elf_sym_hashes (input_bfd
)[indx
]);
3446 while (h
->elf
.root
.type
== bfd_link_hash_indirect
3447 || h
->elf
.root
.type
== bfd_link_hash_warning
)
3448 h
= (struct elf32_hppa_link_hash_entry
*) h
->elf
.root
.u
.i
.link
;
3451 if (h
->elf
.root
.type
== bfd_link_hash_defined
3452 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
3454 sym_sec
= h
->elf
.root
.u
.def
.section
;
3455 /* If sym_sec->output_section is NULL, then it's a
3456 symbol defined in a shared library. */
3457 if (sym_sec
->output_section
!= NULL
)
3458 relocation
= (h
->elf
.root
.u
.def
.value
3459 + sym_sec
->output_offset
3460 + sym_sec
->output_section
->vma
);
3462 else if (h
->elf
.root
.type
== bfd_link_hash_undefweak
)
3464 else if (info
->shared
&& !info
->no_undefined
3465 && ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
)
3468 if (!((*info
->callbacks
->undefined_symbol
)
3469 (info
, h
->elf
.root
.root
.string
, input_bfd
,
3470 input_section
, rel
->r_offset
, false)))
3475 if (!((*info
->callbacks
->undefined_symbol
)
3476 (info
, h
->elf
.root
.root
.string
, input_bfd
,
3477 input_section
, rel
->r_offset
, true)))
3482 /* Do any required modifications to the relocation value, and
3483 determine what types of dynamic info we need to output, if
3488 case R_PARISC_DLTIND14F
:
3489 case R_PARISC_DLTIND14R
:
3490 case R_PARISC_DLTIND21L
:
3491 /* Relocation is to the entry for this symbol in the global
3497 off
= h
->elf
.got
.offset
;
3498 BFD_ASSERT (off
!= (bfd_vma
) -1);
3500 if (! hplink
->root
.dynamic_sections_created
3502 && (info
->symbolic
|| h
->elf
.dynindx
== -1)
3503 && (h
->elf
.elf_link_hash_flags
3504 & ELF_LINK_HASH_DEF_REGULAR
) != 0))
3506 /* This is actually a static link, or it is a
3507 -Bsymbolic link and the symbol is defined
3508 locally, or the symbol was forced to be local
3509 because of a version file. We must initialize
3510 this entry in the global offset table. Since the
3511 offset must always be a multiple of 4, we use the
3512 least significant bit to record whether we have
3513 initialized it already.
3515 When doing a dynamic link, we create a .rela.got
3516 relocation entry to initialize the value. This
3517 is done in the finish_dynamic_symbol routine. */
3522 bfd_put_32 (output_bfd
, relocation
,
3523 hplink
->sgot
->contents
+ off
);
3524 h
->elf
.got
.offset
|= 1;
3532 /* Local symbol case. */
3535 BFD_ASSERT (local_got_offsets
!= NULL
3536 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
3538 off
= local_got_offsets
[r_symndx
];
3540 /* The offset must always be a multiple of 4. We use
3541 the least significant bit to record whether we have
3542 already generated the necessary reloc. */
3547 bfd_put_32 (output_bfd
, relocation
,
3548 hplink
->sgot
->contents
+ off
);
3552 /* Output a dynamic *ABS* relocation for this
3553 GOT entry. In this case it is relative to
3554 the base of the object because the symbol
3556 Elf_Internal_Rela outrel
;
3557 asection
*srelgot
= hplink
->srelgot
;
3559 outrel
.r_offset
= (off
3560 + hplink
->sgot
->output_offset
3561 + hplink
->sgot
->output_section
->vma
);
3562 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_DIR32
);
3563 outrel
.r_addend
= relocation
;
3564 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3565 ((Elf32_External_Rela
*)
3567 + srelgot
->reloc_count
));
3568 ++srelgot
->reloc_count
;
3571 local_got_offsets
[r_symndx
] |= 1;
3577 /* Add the base of the GOT to the relocation value. */
3578 relocation
+= (hplink
->sgot
->output_offset
3579 + hplink
->sgot
->output_section
->vma
);
3582 case R_PARISC_PLABEL14R
:
3583 case R_PARISC_PLABEL21L
:
3584 case R_PARISC_PLABEL32
:
3585 if (hplink
->root
.dynamic_sections_created
)
3589 /* If we have a global symbol with a PLT slot, then
3590 redirect this relocation to it. */
3593 off
= h
->elf
.plt
.offset
;
3599 indx
= r_symndx
+ symtab_hdr
->sh_info
;
3600 off
= local_got_offsets
[indx
];
3602 /* As for the local .got entry case, we use the last
3603 bit to record whether we've already initialised
3604 this local .plt entry. */
3609 bfd_put_32 (output_bfd
,
3611 hplink
->splt
->contents
+ off
);
3612 bfd_put_32 (output_bfd
,
3613 elf_gp (hplink
->splt
->output_section
->owner
),
3614 hplink
->splt
->contents
+ off
+ 4);
3618 /* Output a dynamic IPLT relocation for this
3620 Elf_Internal_Rela outrel
;
3621 asection
*srelplt
= hplink
->srelplt
;
3623 outrel
.r_offset
= (off
3624 + hplink
->splt
->output_offset
3625 + hplink
->splt
->output_section
->vma
);
3626 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_IPLT
);
3627 outrel
.r_addend
= relocation
;
3628 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3629 ((Elf32_External_Rela
*)
3631 + srelplt
->reloc_count
));
3632 ++srelplt
->reloc_count
;
3635 local_got_offsets
[indx
] |= 1;
3639 BFD_ASSERT (off
< (bfd_vma
) -2);
3641 /* PLABELs contain function pointers. Relocation is to
3642 the entry for the function in the .plt. The magic +2
3643 offset signals to $$dyncall that the function pointer
3644 is in the .plt and thus has a gp pointer too.
3645 Exception: Undefined PLABELs should have a value of
3648 || (h
->elf
.root
.type
!= bfd_link_hash_undefweak
3649 && h
->elf
.root
.type
!= bfd_link_hash_undefined
))
3652 + hplink
->splt
->output_offset
3653 + hplink
->splt
->output_section
->vma
3658 /* Fall through and possibly emit a dynamic relocation. */
3660 case R_PARISC_DIR17F
:
3661 case R_PARISC_DIR17R
:
3662 case R_PARISC_DIR14F
:
3663 case R_PARISC_DIR14R
:
3664 case R_PARISC_DIR21L
:
3665 case R_PARISC_DPREL14F
:
3666 case R_PARISC_DPREL14R
:
3667 case R_PARISC_DPREL21L
:
3668 case R_PARISC_DIR32
:
3669 /* The reloc types handled here and this conditional
3670 expression must match the code in check_relocs and
3671 hppa_discard_copies. ie. We need exactly the same
3672 condition as in check_relocs, with some extra conditions
3673 (dynindx test in this case) to cater for relocs removed
3674 by hppa_discard_copies. */
3675 if ((input_section
->flags
& SEC_ALLOC
) != 0
3677 #if RELATIVE_DYNAMIC_RELOCS
3678 && (is_absolute_reloc (r_type
)
3679 || ((!info
->symbolic
3681 && ((h
->elf
.elf_link_hash_flags
3682 & ELF_LINK_HASH_DEF_REGULAR
) == 0
3683 || h
->elf
.root
.type
== bfd_link_hash_defweak
)))
3684 && (h
== NULL
|| h
->elf
.dynindx
!= -1)))
3688 Elf_Internal_Rela outrel
;
3691 /* When generating a shared object, these relocations
3692 are copied into the output file to be resolved at run
3699 name
= (bfd_elf_string_from_elf_section
3701 elf_elfheader (input_bfd
)->e_shstrndx
,
3702 elf_section_data (input_section
)->rel_hdr
.sh_name
));
3705 sreloc
= bfd_get_section_by_name (dynobj
, name
);
3706 BFD_ASSERT (sreloc
!= NULL
);
3709 outrel
.r_offset
= rel
->r_offset
;
3710 outrel
.r_addend
= rel
->r_addend
;
3712 if (elf_section_data (input_section
)->stab_info
!= NULL
)
3716 off
= (_bfd_stab_section_offset
3717 (output_bfd
, &hplink
->root
.stab_info
,
3719 &elf_section_data (input_section
)->stab_info
,
3721 if (off
== (bfd_vma
) -1)
3723 outrel
.r_offset
= off
;
3726 outrel
.r_offset
+= (input_section
->output_offset
3727 + input_section
->output_section
->vma
);
3731 memset (&outrel
, 0, sizeof (outrel
));
3734 && h
->elf
.dynindx
!= -1
3737 || (h
->elf
.elf_link_hash_flags
3738 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
3740 outrel
.r_info
= ELF32_R_INFO (h
->elf
.dynindx
, r_type
);
3742 else /* It's a local symbol, or one marked to become local. */
3746 /* Add the absolute offset of the symbol. */
3747 outrel
.r_addend
+= relocation
;
3749 /* Global plabels need to be processed by the
3750 dynamic linker so that functions have at most one
3751 fptr. For this reason, we need to differentiate
3752 between global and local plabels, which we do by
3753 providing the function symbol for a global plabel
3754 reloc, and no symbol for local plabels. */
3757 && sym_sec
->output_section
!= NULL
3758 && ! bfd_is_abs_section (sym_sec
))
3760 indx
= elf_section_data (sym_sec
->output_section
)->dynindx
;
3761 /* We are turning this relocation into one
3762 against a section symbol, so subtract out the
3763 output section's address but not the offset
3764 of the input section in the output section. */
3765 outrel
.r_addend
-= sym_sec
->output_section
->vma
;
3768 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
3771 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3772 ((Elf32_External_Rela
*)
3774 + sreloc
->reloc_count
));
3775 ++sreloc
->reloc_count
;
3783 r
= final_link_relocate (input_section
, contents
, rel
, relocation
,
3784 hplink
, sym_sec
, h
);
3786 if (r
== bfd_reloc_ok
)
3790 sym_name
= h
->elf
.root
.root
.string
;
3793 sym_name
= bfd_elf_string_from_elf_section (input_bfd
,
3794 symtab_hdr
->sh_link
,
3796 if (sym_name
== NULL
)
3798 if (*sym_name
== '\0')
3799 sym_name
= bfd_section_name (input_bfd
, sym_sec
);
3802 howto
= elf_hppa_howto_table
+ r_type
;
3804 if (r
== bfd_reloc_undefined
|| r
== bfd_reloc_notsupported
)
3806 (*_bfd_error_handler
)
3807 (_("%s(%s+0x%lx): cannot handle %s for %s"),
3808 bfd_get_filename (input_bfd
),
3809 input_section
->name
,
3810 (long) rel
->r_offset
,
3816 if (!((*info
->callbacks
->reloc_overflow
)
3817 (info
, sym_name
, howto
->name
, (bfd_vma
) 0,
3818 input_bfd
, input_section
, rel
->r_offset
)))
3826 /* Finish up dynamic symbol handling. We set the contents of various
3827 dynamic sections here. */
3830 elf32_hppa_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
3832 struct bfd_link_info
*info
;
3833 struct elf_link_hash_entry
*h
;
3834 Elf_Internal_Sym
*sym
;
3836 struct elf32_hppa_link_hash_table
*hplink
;
3839 hplink
= hppa_link_hash_table (info
);
3840 dynobj
= hplink
->root
.dynobj
;
3842 if (h
->plt
.offset
!= (bfd_vma
) -1)
3846 /* This symbol has an entry in the procedure linkage table. Set
3849 The format of a plt entry is
3854 if (h
->root
.type
== bfd_link_hash_defined
3855 || h
->root
.type
== bfd_link_hash_defweak
)
3857 value
= h
->root
.u
.def
.value
;
3858 if (h
->root
.u
.def
.section
->output_section
!= NULL
)
3859 value
+= (h
->root
.u
.def
.section
->output_offset
3860 + h
->root
.u
.def
.section
->output_section
->vma
);
3863 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
)
3865 Elf_Internal_Rela rel
;
3867 /* Create a dynamic IPLT relocation for this entry. */
3868 rel
.r_offset
= (h
->plt
.offset
3869 + hplink
->splt
->output_offset
3870 + hplink
->splt
->output_section
->vma
);
3871 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->plt_abs
3872 && h
->dynindx
!= -1)
3874 /* To support lazy linking, the function pointer is
3875 initialised to point to a special stub stored at the
3876 end of the .plt. This is only done for plt entries
3877 with a non-*ABS* dynamic relocation. */
3878 value
= (hplink
->splt
->output_offset
3879 + hplink
->splt
->output_section
->vma
3880 + hplink
->splt
->_raw_size
3883 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_IPLT
);
3888 /* This symbol has been marked to become local, and is
3889 used by a plabel so must be kept in the .plt. */
3890 rel
.r_info
= ELF32_R_INFO (0, R_PARISC_IPLT
);
3891 rel
.r_addend
= value
;
3894 bfd_elf32_swap_reloca_out (hplink
->splt
->output_section
->owner
,
3896 ((Elf32_External_Rela
*)
3897 hplink
->srelplt
->contents
3898 + hplink
->srelplt
->reloc_count
));
3899 hplink
->srelplt
->reloc_count
++;
3902 bfd_put_32 (hplink
->splt
->owner
,
3904 hplink
->splt
->contents
+ h
->plt
.offset
);
3905 bfd_put_32 (hplink
->splt
->owner
,
3906 elf_gp (hplink
->splt
->output_section
->owner
),
3907 hplink
->splt
->contents
+ h
->plt
.offset
+ 4);
3908 if (PLABEL_PLT_ENTRY_SIZE
!= PLT_ENTRY_SIZE
3909 && ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
3910 && h
->dynindx
!= -1)
3912 memset (hplink
->splt
->contents
+ h
->plt
.offset
+ 8,
3913 0, PLABEL_PLT_ENTRY_SIZE
- PLT_ENTRY_SIZE
);
3916 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3918 /* Mark the symbol as undefined, rather than as defined in
3919 the .plt section. Leave the value alone. */
3920 sym
->st_shndx
= SHN_UNDEF
;
3924 if (h
->got
.offset
!= (bfd_vma
) -1)
3926 Elf_Internal_Rela rel
;
3928 /* This symbol has an entry in the global offset table. Set it
3931 rel
.r_offset
= ((h
->got
.offset
&~ (bfd_vma
) 1)
3932 + hplink
->sgot
->output_offset
3933 + hplink
->sgot
->output_section
->vma
);
3935 /* If this is a static link, or it is a -Bsymbolic link and the
3936 symbol is defined locally or was forced to be local because
3937 of a version file, we just want to emit a RELATIVE reloc.
3938 The entry in the global offset table will already have been
3939 initialized in the relocate_section function. */
3940 if (! hplink
->root
.dynamic_sections_created
3942 && (info
->symbolic
|| h
->dynindx
== -1)
3943 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
3945 rel
.r_info
= ELF32_R_INFO (0, R_PARISC_DIR32
);
3946 rel
.r_addend
= (h
->root
.u
.def
.value
3947 + h
->root
.u
.def
.section
->output_offset
3948 + h
->root
.u
.def
.section
->output_section
->vma
);
3952 BFD_ASSERT((h
->got
.offset
& 1) == 0);
3953 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
3954 hplink
->sgot
->contents
+ h
->got
.offset
);
3955 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_DIR32
);
3959 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
3960 ((Elf32_External_Rela
*)
3961 hplink
->srelgot
->contents
3962 + hplink
->srelgot
->reloc_count
));
3963 ++hplink
->srelgot
->reloc_count
;
3966 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
3969 Elf_Internal_Rela rel
;
3971 /* This symbol needs a copy reloc. Set it up. */
3973 BFD_ASSERT (h
->dynindx
!= -1
3974 && (h
->root
.type
== bfd_link_hash_defined
3975 || h
->root
.type
== bfd_link_hash_defweak
));
3977 s
= hplink
->srelbss
;
3979 rel
.r_offset
= (h
->root
.u
.def
.value
3980 + h
->root
.u
.def
.section
->output_offset
3981 + h
->root
.u
.def
.section
->output_section
->vma
);
3983 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_COPY
);
3984 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
3985 ((Elf32_External_Rela
*) s
->contents
3990 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
3991 if (h
->root
.root
.string
[0] == '_'
3992 && (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3993 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0))
3995 sym
->st_shndx
= SHN_ABS
;
4001 /* Finish up the dynamic sections. */
4004 elf32_hppa_finish_dynamic_sections (output_bfd
, info
)
4006 struct bfd_link_info
*info
;
4009 struct elf32_hppa_link_hash_table
*hplink
;
4012 hplink
= hppa_link_hash_table (info
);
4013 dynobj
= hplink
->root
.dynobj
;
4015 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4017 if (hplink
->root
.dynamic_sections_created
)
4019 Elf32_External_Dyn
*dyncon
, *dynconend
;
4021 BFD_ASSERT (sdyn
!= NULL
);
4023 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4024 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
4025 for (; dyncon
< dynconend
; dyncon
++)
4027 Elf_Internal_Dyn dyn
;
4030 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4038 /* Use PLTGOT to set the GOT register. */
4039 dyn
.d_un
.d_ptr
= elf_gp (output_bfd
);
4040 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4044 s
= hplink
->srelplt
;
4045 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4046 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4050 s
= hplink
->srelplt
;
4051 if (s
->_cooked_size
!= 0)
4052 dyn
.d_un
.d_val
= s
->_cooked_size
;
4054 dyn
.d_un
.d_val
= s
->_raw_size
;
4055 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4061 if (hplink
->sgot
->_raw_size
!= 0)
4063 /* Fill in the first entry in the global offset table.
4064 We use it to point to our dynamic section, if we have one. */
4065 bfd_put_32 (output_bfd
,
4067 ? sdyn
->output_section
->vma
+ sdyn
->output_offset
4069 hplink
->sgot
->contents
);
4071 /* The second entry is reserved for use by the dynamic linker. */
4072 memset (hplink
->sgot
->contents
+ GOT_ENTRY_SIZE
, 0, GOT_ENTRY_SIZE
);
4074 /* Set .got entry size. */
4075 elf_section_data (hplink
->sgot
->output_section
)
4076 ->this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
4079 if (hplink
->splt
->_raw_size
!= 0)
4081 /* Set plt entry size. */
4082 elf_section_data (hplink
->splt
->output_section
)
4083 ->this_hdr
.sh_entsize
= PLT_ENTRY_SIZE
;
4085 if (hplink
->need_plt_stub
)
4087 /* Set up the .plt stub. */
4088 memcpy (hplink
->splt
->contents
4089 + hplink
->splt
->_raw_size
- sizeof (plt_stub
),
4090 plt_stub
, sizeof (plt_stub
));
4092 if ((hplink
->splt
->output_offset
4093 + hplink
->splt
->output_section
->vma
4094 + hplink
->splt
->_raw_size
)
4095 != (hplink
->sgot
->output_offset
4096 + hplink
->sgot
->output_section
->vma
))
4098 (*_bfd_error_handler
)
4099 (_(".got section not immediately after .plt section"));
4108 /* Called when writing out an object file to decide the type of a
4111 elf32_hppa_elf_get_symbol_type (elf_sym
, type
)
4112 Elf_Internal_Sym
*elf_sym
;
4115 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_PARISC_MILLI
)
4116 return STT_PARISC_MILLI
;
4121 /* Misc BFD support code. */
4122 #define bfd_elf32_bfd_is_local_label_name elf_hppa_is_local_label_name
4123 #define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
4124 #define elf_info_to_howto elf_hppa_info_to_howto
4125 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
4127 /* Stuff for the BFD linker. */
4128 #define bfd_elf32_bfd_final_link _bfd_elf32_gc_common_final_link
4129 #define bfd_elf32_bfd_link_hash_table_create elf32_hppa_link_hash_table_create
4130 #define elf_backend_add_symbol_hook elf32_hppa_add_symbol_hook
4131 #define elf_backend_adjust_dynamic_symbol elf32_hppa_adjust_dynamic_symbol
4132 #define elf_backend_check_relocs elf32_hppa_check_relocs
4133 #define elf_backend_create_dynamic_sections elf32_hppa_create_dynamic_sections
4134 #define elf_backend_fake_sections elf_hppa_fake_sections
4135 #define elf_backend_relocate_section elf32_hppa_relocate_section
4136 #define elf_backend_hide_symbol elf32_hppa_hide_symbol
4137 #define elf_backend_finish_dynamic_symbol elf32_hppa_finish_dynamic_symbol
4138 #define elf_backend_finish_dynamic_sections elf32_hppa_finish_dynamic_sections
4139 #define elf_backend_size_dynamic_sections elf32_hppa_size_dynamic_sections
4140 #define elf_backend_gc_mark_hook elf32_hppa_gc_mark_hook
4141 #define elf_backend_gc_sweep_hook elf32_hppa_gc_sweep_hook
4142 #define elf_backend_object_p elf32_hppa_object_p
4143 #define elf_backend_final_write_processing elf_hppa_final_write_processing
4144 #define elf_backend_get_symbol_type elf32_hppa_elf_get_symbol_type
4146 #define elf_backend_can_gc_sections 1
4147 #define elf_backend_plt_alignment 2
4148 #define elf_backend_want_got_plt 0
4149 #define elf_backend_plt_readonly 0
4150 #define elf_backend_want_plt_sym 0
4151 #define elf_backend_got_header_size 8
4153 #define TARGET_BIG_SYM bfd_elf32_hppa_vec
4154 #define TARGET_BIG_NAME "elf32-hppa"
4155 #define ELF_ARCH bfd_arch_hppa
4156 #define ELF_MACHINE_CODE EM_PARISC
4157 #define ELF_MAXPAGESIZE 0x1000
4159 #include "elf32-target.h"