1 /* BFD back-end for HP PA-RISC ELF files.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2001
3 Free Software Foundation, Inc.
6 Center for Software Science
7 Department of Computer Science
9 Largely rewritten by Alan Modra <alan@linuxcare.com.au>
11 This file is part of BFD, the Binary File Descriptor library.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
33 #include "elf32-hppa.h"
36 #include "elf32-hppa.h"
38 /* In order to gain some understanding of code in this file without
39 knowing all the intricate details of the linker, note the
42 Functions named elf32_hppa_* are called by external routines, other
43 functions are only called locally. elf32_hppa_* functions appear
44 in this file more or less in the order in which they are called
45 from external routines. eg. elf32_hppa_check_relocs is called
46 early in the link process, elf32_hppa_finish_dynamic_sections is
47 one of the last functions. */
49 /* We use two hash tables to hold information for linking PA ELF objects.
51 The first is the elf32_hppa_link_hash_table which is derived
52 from the standard ELF linker hash table. We use this as a place to
53 attach other hash tables and static information.
55 The second is the stub hash table which is derived from the
56 base BFD hash table. The stub hash table holds the information
57 necessary to build the linker stubs during a link.
59 There are a number of different stubs generated by the linker.
67 : addil LR'X - ($PIC_pcrel$0 - 4),%r1
68 : be,n RR'X - ($PIC_pcrel$0 - 8)(%sr4,%r1)
70 Import stub to call shared library routine from normal object file
71 (single sub-space version)
72 : addil LR'lt_ptr+ltoff,%dp ; get procedure entry point
73 : ldw RR'lt_ptr+ltoff(%r1),%r21
75 : ldw RR'lt_ptr+ltoff+4(%r1),%r19 ; get new dlt value.
77 Import stub to call shared library routine from shared library
78 (single sub-space version)
79 : addil LR'ltoff,%r19 ; get procedure entry point
80 : ldw RR'ltoff(%r1),%r21
82 : ldw RR'ltoff+4(%r1),%r19 ; get new dlt value.
84 Import stub to call shared library routine from normal object file
85 (multiple sub-space support)
86 : addil LR'lt_ptr+ltoff,%dp ; get procedure entry point
87 : ldw RR'lt_ptr+ltoff(%r1),%r21
88 : ldw RR'lt_ptr+ltoff+4(%r1),%r19 ; get new dlt value.
91 : be 0(%sr0,%r21) ; branch to target
92 : stw %rp,-24(%sp) ; save rp
94 Import stub to call shared library routine from shared library
95 (multiple sub-space support)
96 : addil LR'ltoff,%r19 ; get procedure entry point
97 : ldw RR'ltoff(%r1),%r21
98 : ldw RR'ltoff+4(%r1),%r19 ; get new dlt value.
101 : be 0(%sr0,%r21) ; branch to target
102 : stw %rp,-24(%sp) ; save rp
104 Export stub to return from shared lib routine (multiple sub-space support)
105 One of these is created for each exported procedure in a shared
106 library (and stored in the shared lib). Shared lib routines are
107 called via the first instruction in the export stub so that we can
108 do an inter-space return. Not required for single sub-space.
109 : bl,n X,%rp ; trap the return
111 : ldw -24(%sp),%rp ; restore the original rp
114 : be,n 0(%sr0,%rp) ; inter-space return */
116 #define PLT_ENTRY_SIZE 8
117 #define PLABEL_PLT_ENTRY_SIZE PLT_ENTRY_SIZE
118 #define GOT_ENTRY_SIZE 4
119 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
121 static const bfd_byte plt_stub
[] =
123 0x0e, 0x80, 0x10, 0x96, /* 1: ldw 0(%r20),%r22 */
124 0xea, 0xc0, 0xc0, 0x00, /* bv %r0(%r22) */
125 0x0e, 0x88, 0x10, 0x95, /* ldw 4(%r20),%r21 */
126 #define PLT_STUB_ENTRY (3*4)
127 0xea, 0x9f, 0x1f, 0xdd, /* b,l 1b,%r20 */
128 0xd6, 0x80, 0x1c, 0x1e, /* depi 0,31,2,%r20 */
129 0x00, 0xc0, 0xff, 0xee, /* 9: .word fixup_func */
130 0xde, 0xad, 0xbe, 0xef /* .word fixup_ltp */
133 /* Section name for stubs is the associated section name plus this
135 #define STUB_SUFFIX ".stub"
137 /* Setting the following non-zero makes all long branch stubs
138 generated during a shared link of the PIC variety. This saves on
139 relocs, but costs one extra instruction per stub. */
140 #ifndef LONG_BRANCH_PIC_IN_SHLIB
141 #define LONG_BRANCH_PIC_IN_SHLIB 1
144 /* Set this non-zero to use import stubs instead of long branch stubs
145 where a .plt entry exists for the symbol. This is a fairly useless
146 option as import stubs are bigger than PIC long branch stubs. */
147 #ifndef LONG_BRANCH_VIA_PLT
148 #define LONG_BRANCH_VIA_PLT 0
151 /* We don't need to copy any PC- or GP-relative dynamic relocs into a
152 shared object's dynamic section. */
153 #ifndef RELATIVE_DYNAMIC_RELOCS
154 #define RELATIVE_DYNAMIC_RELOCS 0
157 enum elf32_hppa_stub_type
{
158 hppa_stub_long_branch
,
159 hppa_stub_long_branch_shared
,
161 hppa_stub_import_shared
,
166 struct elf32_hppa_stub_hash_entry
{
168 /* Base hash table entry structure. */
169 struct bfd_hash_entry root
;
171 /* The stub section. */
174 #if ! LONG_BRANCH_PIC_IN_SHLIB
175 /* It's associated reloc section. */
179 /* Offset within stub_sec of the beginning of this stub. */
182 /* Given the symbol's value and its section we can determine its final
183 value when building the stubs (so the stub knows where to jump. */
184 bfd_vma target_value
;
185 asection
*target_section
;
187 enum elf32_hppa_stub_type stub_type
;
189 /* The symbol table entry, if any, that this was derived from. */
190 struct elf32_hppa_link_hash_entry
*h
;
192 /* Where this stub is being called from, or, in the case of combined
193 stub sections, the first input section in the group. */
197 struct elf32_hppa_link_hash_entry
{
199 struct elf_link_hash_entry elf
;
201 /* A pointer to the most recently used stub hash entry against this
203 struct elf32_hppa_stub_hash_entry
*stub_cache
;
205 #if ! LONG_BRANCH_PIC_IN_SHLIB
206 /* Used to track whether we have allocated space for a long branch
207 stub relocation for this symbol in the given section. */
208 asection
*stub_reloc_sec
;
211 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
212 /* Used to count relocations for delayed sizing of relocation
214 struct elf32_hppa_dyn_reloc_entry
{
216 /* Next relocation in the chain. */
217 struct elf32_hppa_dyn_reloc_entry
*next
;
219 /* The section in dynobj. */
222 /* Number of relocs copied in this section. */
227 /* Set during a static link if we detect a function is PIC. */
228 unsigned int 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 /* Used during a final link to store the base of the text and data
276 segments so that we can perform SEGREL relocations. */
277 bfd_vma text_segment_base
;
278 bfd_vma data_segment_base
;
280 /* Whether we support multiple sub-spaces for shared libs. */
281 unsigned int multi_subspace
:1;
283 /* Flags set when PCREL12F and PCREL17F branches detected. Used to
284 select suitable defaults for the stub group size. */
285 unsigned int has_12bit_branch
:1;
286 unsigned int has_17bit_branch
:1;
288 /* Set if we need a .plt stub to support lazy dynamic linking. */
289 unsigned int need_plt_stub
:1;
292 /* Various hash macros and functions. */
293 #define hppa_link_hash_table(p) \
294 ((struct elf32_hppa_link_hash_table *) ((p)->hash))
296 #define hppa_stub_hash_lookup(table, string, create, copy) \
297 ((struct elf32_hppa_stub_hash_entry *) \
298 bfd_hash_lookup ((table), (string), (create), (copy)))
300 static struct bfd_hash_entry
*stub_hash_newfunc
301 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
303 static struct bfd_hash_entry
*hppa_link_hash_newfunc
304 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
306 static struct bfd_link_hash_table
*elf32_hppa_link_hash_table_create
309 /* Stub handling functions. */
310 static char *hppa_stub_name
311 PARAMS ((const asection
*, const asection
*,
312 const struct elf32_hppa_link_hash_entry
*,
313 const Elf_Internal_Rela
*));
315 static struct elf32_hppa_stub_hash_entry
*hppa_get_stub_entry
316 PARAMS ((const asection
*, const asection
*,
317 struct elf32_hppa_link_hash_entry
*,
318 const Elf_Internal_Rela
*,
319 struct elf32_hppa_link_hash_table
*));
321 static struct elf32_hppa_stub_hash_entry
*hppa_add_stub
322 PARAMS ((const char *, asection
*, struct elf32_hppa_link_hash_table
*));
324 static enum elf32_hppa_stub_type hppa_type_of_stub
325 PARAMS ((asection
*, const Elf_Internal_Rela
*,
326 struct elf32_hppa_link_hash_entry
*, bfd_vma
));
328 static boolean hppa_build_one_stub
329 PARAMS ((struct bfd_hash_entry
*, PTR
));
331 static boolean hppa_size_one_stub
332 PARAMS ((struct bfd_hash_entry
*, PTR
));
334 /* BFD and elf backend functions. */
335 static boolean elf32_hppa_object_p
PARAMS ((bfd
*));
337 static boolean elf32_hppa_add_symbol_hook
338 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
339 const char **, flagword
*, asection
**, bfd_vma
*));
341 static boolean elf32_hppa_create_dynamic_sections
342 PARAMS ((bfd
*, struct bfd_link_info
*));
344 static boolean elf32_hppa_check_relocs
345 PARAMS ((bfd
*, struct bfd_link_info
*,
346 asection
*, const Elf_Internal_Rela
*));
348 static asection
*elf32_hppa_gc_mark_hook
349 PARAMS ((bfd
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
350 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
352 static boolean elf32_hppa_gc_sweep_hook
353 PARAMS ((bfd
*, struct bfd_link_info
*,
354 asection
*, const Elf_Internal_Rela
*));
356 static void elf32_hppa_hide_symbol
357 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
359 static boolean elf32_hppa_adjust_dynamic_symbol
360 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
362 static boolean hppa_handle_PIC_calls
363 PARAMS ((struct elf_link_hash_entry
*, PTR
));
365 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
366 || RELATIVE_DYNAMIC_RELOCS)
367 static boolean hppa_discard_copies
368 PARAMS ((struct elf_link_hash_entry
*, PTR
));
371 static boolean clobber_millicode_symbols
372 PARAMS ((struct elf_link_hash_entry
*, struct bfd_link_info
*));
374 static boolean elf32_hppa_size_dynamic_sections
375 PARAMS ((bfd
*, struct bfd_link_info
*));
377 static boolean elf32_hppa_final_link
378 PARAMS ((bfd
*, struct bfd_link_info
*));
380 static void hppa_record_segment_addr
381 PARAMS ((bfd
*, asection
*, PTR
));
383 static bfd_reloc_status_type final_link_relocate
384 PARAMS ((asection
*, bfd_byte
*, const Elf_Internal_Rela
*,
385 bfd_vma
, struct elf32_hppa_link_hash_table
*, asection
*,
386 struct elf32_hppa_link_hash_entry
*));
388 static boolean elf32_hppa_relocate_section
389 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*,
390 bfd_byte
*, Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
392 static int hppa_unwind_entry_compare
393 PARAMS ((const PTR
, const PTR
));
395 static boolean elf32_hppa_finish_dynamic_symbol
396 PARAMS ((bfd
*, struct bfd_link_info
*,
397 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
399 static boolean elf32_hppa_finish_dynamic_sections
400 PARAMS ((bfd
*, struct bfd_link_info
*));
402 static void elf32_hppa_post_process_headers
403 PARAMS ((bfd
*, struct bfd_link_info
*));
405 static int elf32_hppa_elf_get_symbol_type
406 PARAMS ((Elf_Internal_Sym
*, int));
408 /* Assorted hash table functions. */
410 /* Initialize an entry in the stub hash table. */
412 static struct bfd_hash_entry
*
413 stub_hash_newfunc (entry
, table
, string
)
414 struct bfd_hash_entry
*entry
;
415 struct bfd_hash_table
*table
;
418 struct elf32_hppa_stub_hash_entry
*ret
;
420 ret
= (struct elf32_hppa_stub_hash_entry
*) entry
;
422 /* Allocate the structure if it has not already been allocated by a
426 ret
= ((struct elf32_hppa_stub_hash_entry
*)
427 bfd_hash_allocate (table
,
428 sizeof (struct elf32_hppa_stub_hash_entry
)));
433 /* Call the allocation method of the superclass. */
434 ret
= ((struct elf32_hppa_stub_hash_entry
*)
435 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
439 /* Initialize the local fields. */
440 ret
->stub_sec
= NULL
;
441 #if ! LONG_BRANCH_PIC_IN_SHLIB
442 ret
->reloc_sec
= NULL
;
444 ret
->stub_offset
= 0;
445 ret
->target_value
= 0;
446 ret
->target_section
= NULL
;
447 ret
->stub_type
= hppa_stub_long_branch
;
452 return (struct bfd_hash_entry
*) ret
;
455 /* Initialize an entry in the link hash table. */
457 static struct bfd_hash_entry
*
458 hppa_link_hash_newfunc (entry
, table
, string
)
459 struct bfd_hash_entry
*entry
;
460 struct bfd_hash_table
*table
;
463 struct elf32_hppa_link_hash_entry
*ret
;
465 ret
= (struct elf32_hppa_link_hash_entry
*) entry
;
467 /* Allocate the structure if it has not already been allocated by a
471 ret
= ((struct elf32_hppa_link_hash_entry
*)
472 bfd_hash_allocate (table
,
473 sizeof (struct elf32_hppa_link_hash_entry
)));
478 /* Call the allocation method of the superclass. */
479 ret
= ((struct elf32_hppa_link_hash_entry
*)
480 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
485 /* Initialize the local fields. */
486 #if ! LONG_BRANCH_PIC_IN_SHLIB
487 ret
->stub_reloc_sec
= NULL
;
489 ret
->stub_cache
= NULL
;
490 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
491 ret
->reloc_entries
= NULL
;
498 return (struct bfd_hash_entry
*) ret
;
501 /* Create the derived linker hash table. The PA ELF port uses the derived
502 hash table to keep information specific to the PA ELF linker (without
503 using static variables). */
505 static struct bfd_link_hash_table
*
506 elf32_hppa_link_hash_table_create (abfd
)
509 struct elf32_hppa_link_hash_table
*ret
;
511 ret
= ((struct elf32_hppa_link_hash_table
*) bfd_alloc (abfd
, sizeof (*ret
)));
515 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
, hppa_link_hash_newfunc
))
517 bfd_release (abfd
, ret
);
521 /* Init the stub hash table too. */
522 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
))
525 ret
->stub_bfd
= NULL
;
526 ret
->add_stub_section
= NULL
;
527 ret
->layout_sections_again
= NULL
;
528 ret
->stub_group
= NULL
;
535 ret
->text_segment_base
= (bfd_vma
) -1;
536 ret
->data_segment_base
= (bfd_vma
) -1;
537 ret
->multi_subspace
= 0;
538 ret
->has_12bit_branch
= 0;
539 ret
->has_17bit_branch
= 0;
540 ret
->need_plt_stub
= 0;
542 return &ret
->root
.root
;
545 /* Build a name for an entry in the stub hash table. */
548 hppa_stub_name (input_section
, sym_sec
, hash
, rel
)
549 const asection
*input_section
;
550 const asection
*sym_sec
;
551 const struct elf32_hppa_link_hash_entry
*hash
;
552 const Elf_Internal_Rela
*rel
;
559 len
= 8 + 1 + strlen (hash
->elf
.root
.root
.string
) + 1 + 8 + 1;
560 stub_name
= bfd_malloc (len
);
561 if (stub_name
!= NULL
)
563 sprintf (stub_name
, "%08x_%s+%x",
564 input_section
->id
& 0xffffffff,
565 hash
->elf
.root
.root
.string
,
566 (int) rel
->r_addend
& 0xffffffff);
571 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
572 stub_name
= bfd_malloc (len
);
573 if (stub_name
!= NULL
)
575 sprintf (stub_name
, "%08x_%x:%x+%x",
576 input_section
->id
& 0xffffffff,
577 sym_sec
->id
& 0xffffffff,
578 (int) ELF32_R_SYM (rel
->r_info
) & 0xffffffff,
579 (int) rel
->r_addend
& 0xffffffff);
585 /* Look up an entry in the stub hash. Stub entries are cached because
586 creating the stub name takes a bit of time. */
588 static struct elf32_hppa_stub_hash_entry
*
589 hppa_get_stub_entry (input_section
, sym_sec
, hash
, rel
, hplink
)
590 const asection
*input_section
;
591 const asection
*sym_sec
;
592 struct elf32_hppa_link_hash_entry
*hash
;
593 const Elf_Internal_Rela
*rel
;
594 struct elf32_hppa_link_hash_table
*hplink
;
596 struct elf32_hppa_stub_hash_entry
*stub_entry
;
597 const asection
*id_sec
;
599 /* If this input section is part of a group of sections sharing one
600 stub section, then use the id of the first section in the group.
601 Stub names need to include a section id, as there may well be
602 more than one stub used to reach say, printf, and we need to
603 distinguish between them. */
604 id_sec
= hplink
->stub_group
[input_section
->id
].link_sec
;
606 if (hash
!= NULL
&& hash
->stub_cache
!= NULL
607 && hash
->stub_cache
->h
== hash
608 && hash
->stub_cache
->id_sec
== id_sec
)
610 stub_entry
= hash
->stub_cache
;
616 stub_name
= hppa_stub_name (id_sec
, sym_sec
, hash
, rel
);
617 if (stub_name
== NULL
)
620 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
,
621 stub_name
, false, false);
622 if (stub_entry
== NULL
)
624 if (hash
== NULL
|| hash
->elf
.root
.type
!= bfd_link_hash_undefweak
)
625 (*_bfd_error_handler
) (_("%s(%s+0x%lx): cannot find stub entry %s"),
626 bfd_get_filename (input_section
->owner
),
628 (long) rel
->r_offset
,
634 hash
->stub_cache
= stub_entry
;
643 /* Add a new stub entry to the stub hash. Not all fields of the new
644 stub entry are initialised. */
646 static struct elf32_hppa_stub_hash_entry
*
647 hppa_add_stub (stub_name
, section
, hplink
)
648 const char *stub_name
;
650 struct elf32_hppa_link_hash_table
*hplink
;
654 struct elf32_hppa_stub_hash_entry
*stub_entry
;
656 link_sec
= hplink
->stub_group
[section
->id
].link_sec
;
657 stub_sec
= hplink
->stub_group
[section
->id
].stub_sec
;
658 if (stub_sec
== NULL
)
660 stub_sec
= hplink
->stub_group
[link_sec
->id
].stub_sec
;
661 if (stub_sec
== NULL
)
666 len
= strlen (link_sec
->name
) + sizeof (STUB_SUFFIX
);
667 s_name
= bfd_alloc (hplink
->stub_bfd
, len
);
671 strcpy (s_name
, link_sec
->name
);
672 strcpy (s_name
+ len
- sizeof (STUB_SUFFIX
), STUB_SUFFIX
);
673 stub_sec
= (*hplink
->add_stub_section
) (s_name
, link_sec
);
674 if (stub_sec
== NULL
)
676 hplink
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
678 hplink
->stub_group
[section
->id
].stub_sec
= stub_sec
;
681 /* Enter this entry into the linker stub hash table. */
682 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
, stub_name
,
684 if (stub_entry
== NULL
)
686 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
687 bfd_get_filename (section
->owner
),
692 stub_entry
->stub_sec
= stub_sec
;
693 #if ! LONG_BRANCH_PIC_IN_SHLIB
694 stub_entry
->reloc_sec
= hplink
->stub_group
[section
->id
].reloc_sec
;
696 stub_entry
->stub_offset
= 0;
697 stub_entry
->id_sec
= link_sec
;
701 /* Determine the type of stub needed, if any, for a call. */
703 static enum elf32_hppa_stub_type
704 hppa_type_of_stub (input_sec
, rel
, hash
, destination
)
706 const Elf_Internal_Rela
*rel
;
707 struct elf32_hppa_link_hash_entry
*hash
;
711 bfd_vma branch_offset
;
712 bfd_vma max_branch_offset
;
716 && (((hash
->elf
.root
.type
== bfd_link_hash_defined
717 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
718 && hash
->elf
.root
.u
.def
.section
->output_section
== NULL
)
719 || (hash
->elf
.root
.type
== bfd_link_hash_defweak
720 && hash
->elf
.dynindx
!= -1
721 && hash
->elf
.plt
.offset
!= (bfd_vma
) -1)
722 || hash
->elf
.root
.type
== bfd_link_hash_undefweak
723 || hash
->elf
.root
.type
== bfd_link_hash_undefined
726 /* If output_section is NULL, then it's a symbol defined in a
727 shared library. We will need an import stub. Decide between
728 hppa_stub_import and hppa_stub_import_shared later. For
729 shared links we need stubs for undefined or weak syms too;
730 They will presumably be resolved by the dynamic linker. */
731 return hppa_stub_import
;
734 /* Determine where the call point is. */
735 location
= (input_sec
->output_offset
736 + input_sec
->output_section
->vma
739 branch_offset
= destination
- location
- 8;
740 r_type
= ELF32_R_TYPE (rel
->r_info
);
742 /* Determine if a long branch stub is needed. parisc branch offsets
743 are relative to the second instruction past the branch, ie. +8
744 bytes on from the branch instruction location. The offset is
745 signed and counts in units of 4 bytes. */
746 if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
748 max_branch_offset
= (1 << (17-1)) << 2;
750 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
752 max_branch_offset
= (1 << (12-1)) << 2;
754 else /* R_PARISC_PCREL22F. */
756 max_branch_offset
= (1 << (22-1)) << 2;
759 if (branch_offset
+ max_branch_offset
>= 2*max_branch_offset
)
761 #if LONG_BRANCH_VIA_PLT
763 && hash
->elf
.dynindx
!= -1
764 && hash
->elf
.plt
.offset
!= (bfd_vma
) -1)
766 /* If we are doing a shared link and find we need a long
767 branch stub, then go via the .plt if possible. */
768 return hppa_stub_import
;
772 return hppa_stub_long_branch
;
774 return hppa_stub_none
;
777 /* Build one linker stub as defined by the stub hash table entry GEN_ENTRY.
778 IN_ARG contains the link info pointer. */
780 #define LDIL_R1 0x20200000 /* ldil LR'XXX,%r1 */
781 #define BE_SR4_R1 0xe0202002 /* be,n RR'XXX(%sr4,%r1) */
783 #define BL_R1 0xe8200000 /* b,l .+8,%r1 */
784 #define ADDIL_R1 0x28200000 /* addil LR'XXX,%r1,%r1 */
785 #define DEPI_R1 0xd4201c1e /* depi 0,31,2,%r1 */
787 #define ADDIL_DP 0x2b600000 /* addil LR'XXX,%dp,%r1 */
788 #define LDW_R1_R21 0x48350000 /* ldw RR'XXX(%sr0,%r1),%r21 */
789 #define BV_R0_R21 0xeaa0c000 /* bv %r0(%r21) */
790 #define LDW_R1_R19 0x48330000 /* ldw RR'XXX(%sr0,%r1),%r19 */
792 #define ADDIL_R19 0x2a600000 /* addil LR'XXX,%r19,%r1 */
793 #define LDW_R1_DP 0x483b0000 /* ldw RR'XXX(%sr0,%r1),%dp */
795 #define LDSID_R21_R1 0x02a010a1 /* ldsid (%sr0,%r21),%r1 */
796 #define MTSP_R1 0x00011820 /* mtsp %r1,%sr0 */
797 #define BE_SR0_R21 0xe2a00000 /* be 0(%sr0,%r21) */
798 #define STW_RP 0x6bc23fd1 /* stw %rp,-24(%sr0,%sp) */
800 #define BL_RP 0xe8400002 /* b,l,n XXX,%rp */
801 #define NOP 0x08000240 /* nop */
802 #define LDW_RP 0x4bc23fd1 /* ldw -24(%sr0,%sp),%rp */
803 #define LDSID_RP_R1 0x004010a1 /* ldsid (%sr0,%rp),%r1 */
804 #define BE_SR0_RP 0xe0400002 /* be,n 0(%sr0,%rp) */
811 #define LDW_R1_DLT LDW_R1_R19
813 #define LDW_R1_DLT LDW_R1_DP
817 hppa_build_one_stub (gen_entry
, in_arg
)
818 struct bfd_hash_entry
*gen_entry
;
821 struct elf32_hppa_stub_hash_entry
*stub_entry
;
822 struct bfd_link_info
*info
;
823 struct elf32_hppa_link_hash_table
*hplink
;
832 /* Massage our args to the form they really have. */
833 stub_entry
= (struct elf32_hppa_stub_hash_entry
*) gen_entry
;
834 info
= (struct bfd_link_info
*) in_arg
;
836 hplink
= hppa_link_hash_table (info
);
837 stub_sec
= stub_entry
->stub_sec
;
839 /* Make a note of the offset within the stubs for this entry. */
840 stub_entry
->stub_offset
= stub_sec
->_raw_size
;
841 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
843 stub_bfd
= stub_sec
->owner
;
845 switch (stub_entry
->stub_type
)
847 case hppa_stub_long_branch
:
848 /* Create the long branch. A long branch is formed with "ldil"
849 loading the upper bits of the target address into a register,
850 then branching with "be" which adds in the lower bits.
851 The "be" has its delay slot nullified. */
852 sym_value
= (stub_entry
->target_value
853 + stub_entry
->target_section
->output_offset
854 + stub_entry
->target_section
->output_section
->vma
);
856 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_lrsel
);
857 insn
= hppa_rebuild_insn ((int) LDIL_R1
, val
, 21);
858 bfd_put_32 (stub_bfd
, insn
, loc
);
860 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_rrsel
) >> 2;
861 insn
= hppa_rebuild_insn ((int) BE_SR4_R1
, val
, 17);
862 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
864 #if ! LONG_BRANCH_PIC_IN_SHLIB
867 /* Output a dynamic relocation for this stub. We only
868 output one PCREL21L reloc per stub, trusting that the
869 dynamic linker will also fix the implied PCREL17R for the
870 second instruction. PCREL21L dynamic relocs had better
871 never be emitted for some other purpose... */
873 Elf_Internal_Rela outrel
;
875 if (stub_entry
->h
== NULL
)
877 (*_bfd_error_handler
)
878 (_("%s(%s+0x%lx): cannot relocate %s, recompile with -ffunction-sections"),
879 bfd_get_filename (stub_entry
->target_section
->owner
),
881 (long) stub_entry
->stub_offset
,
882 stub_entry
->root
.string
);
883 bfd_set_error (bfd_error_bad_value
);
887 srel
= stub_entry
->reloc_sec
;
890 (*_bfd_error_handler
)
891 (_("Could not find relocation section for %s"),
893 bfd_set_error (bfd_error_bad_value
);
897 outrel
.r_offset
= (stub_entry
->stub_offset
898 + stub_sec
->output_offset
899 + stub_sec
->output_section
->vma
);
900 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_PCREL21L
);
901 outrel
.r_addend
= sym_value
;
902 bfd_elf32_swap_reloca_out (stub_sec
->output_section
->owner
,
904 ((Elf32_External_Rela
*)
905 srel
->contents
+ srel
->reloc_count
));
912 case hppa_stub_long_branch_shared
:
913 /* Branches are relative. This is where we are going to. */
914 sym_value
= (stub_entry
->target_value
915 + stub_entry
->target_section
->output_offset
916 + stub_entry
->target_section
->output_section
->vma
);
918 /* And this is where we are coming from, more or less. */
919 sym_value
-= (stub_entry
->stub_offset
920 + stub_sec
->output_offset
921 + stub_sec
->output_section
->vma
);
923 bfd_put_32 (stub_bfd
, (bfd_vma
) BL_R1
, loc
);
924 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_lrsel
);
925 insn
= hppa_rebuild_insn ((int) ADDIL_R1
, val
, 21);
926 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
928 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_rrsel
) >> 2;
929 insn
= hppa_rebuild_insn ((int) BE_SR4_R1
, val
, 17);
930 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
934 case hppa_stub_import
:
935 case hppa_stub_import_shared
:
936 sym_value
= (stub_entry
->h
->elf
.plt
.offset
937 + hplink
->splt
->output_offset
938 + hplink
->splt
->output_section
->vma
939 - elf_gp (hplink
->splt
->output_section
->owner
));
943 if (stub_entry
->stub_type
== hppa_stub_import_shared
)
946 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_lrsel
),
947 insn
= hppa_rebuild_insn ((int) insn
, val
, 21);
948 bfd_put_32 (stub_bfd
, insn
, loc
);
950 /* It is critical to use lrsel/rrsel here because we are using
951 two different offsets (+0 and +4) from sym_value. If we use
952 lsel/rsel then with unfortunate sym_values we will round
953 sym_value+4 up to the next 2k block leading to a mis-match
954 between the lsel and rsel value. */
955 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_rrsel
);
956 insn
= hppa_rebuild_insn ((int) LDW_R1_R21
, val
, 14);
957 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
959 if (hplink
->multi_subspace
)
961 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 4, e_rrsel
);
962 insn
= hppa_rebuild_insn ((int) LDW_R1_DLT
, val
, 14);
963 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
965 bfd_put_32 (stub_bfd
, (bfd_vma
) LDSID_R21_R1
, loc
+ 12);
966 bfd_put_32 (stub_bfd
, (bfd_vma
) MTSP_R1
, loc
+ 16);
967 bfd_put_32 (stub_bfd
, (bfd_vma
) BE_SR0_R21
, loc
+ 20);
968 bfd_put_32 (stub_bfd
, (bfd_vma
) STW_RP
, loc
+ 24);
974 bfd_put_32 (stub_bfd
, (bfd_vma
) BV_R0_R21
, loc
+ 8);
975 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 4, e_rrsel
);
976 insn
= hppa_rebuild_insn ((int) LDW_R1_DLT
, val
, 14);
977 bfd_put_32 (stub_bfd
, insn
, loc
+ 12);
983 && stub_entry
->h
!= NULL
984 && stub_entry
->h
->pic_call
)
986 /* Build the .plt entry needed to call a PIC function from
987 statically linked code. We don't need any relocs. */
989 struct elf32_hppa_link_hash_entry
*eh
;
992 dynobj
= hplink
->root
.dynobj
;
993 eh
= (struct elf32_hppa_link_hash_entry
*) stub_entry
->h
;
995 BFD_ASSERT (eh
->elf
.root
.type
== bfd_link_hash_defined
996 || eh
->elf
.root
.type
== bfd_link_hash_defweak
);
998 value
= (eh
->elf
.root
.u
.def
.value
999 + eh
->elf
.root
.u
.def
.section
->output_offset
1000 + eh
->elf
.root
.u
.def
.section
->output_section
->vma
);
1002 /* Fill in the entry in the procedure linkage table.
1004 The format of a plt entry is
1008 bfd_put_32 (hplink
->splt
->owner
, value
,
1009 hplink
->splt
->contents
+ eh
->elf
.plt
.offset
);
1010 value
= elf_gp (hplink
->splt
->output_section
->owner
);
1011 bfd_put_32 (hplink
->splt
->owner
, value
,
1012 hplink
->splt
->contents
+ eh
->elf
.plt
.offset
+ 4);
1016 case hppa_stub_export
:
1017 /* Branches are relative. This is where we are going to. */
1018 sym_value
= (stub_entry
->target_value
1019 + stub_entry
->target_section
->output_offset
1020 + stub_entry
->target_section
->output_section
->vma
);
1022 /* And this is where we are coming from. */
1023 sym_value
-= (stub_entry
->stub_offset
1024 + stub_sec
->output_offset
1025 + stub_sec
->output_section
->vma
);
1027 if (sym_value
- 8 + 0x40000 >= 0x80000)
1029 (*_bfd_error_handler
)
1030 (_("%s(%s+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
1031 bfd_get_filename (stub_entry
->target_section
->owner
),
1033 (long) stub_entry
->stub_offset
,
1034 stub_entry
->root
.string
);
1035 bfd_set_error (bfd_error_bad_value
);
1039 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_fsel
) >> 2;
1040 insn
= hppa_rebuild_insn ((int) BL_RP
, val
, 17);
1041 bfd_put_32 (stub_bfd
, insn
, loc
);
1043 bfd_put_32 (stub_bfd
, (bfd_vma
) NOP
, loc
+ 4);
1044 bfd_put_32 (stub_bfd
, (bfd_vma
) LDW_RP
, loc
+ 8);
1045 bfd_put_32 (stub_bfd
, (bfd_vma
) LDSID_RP_R1
, loc
+ 12);
1046 bfd_put_32 (stub_bfd
, (bfd_vma
) MTSP_R1
, loc
+ 16);
1047 bfd_put_32 (stub_bfd
, (bfd_vma
) BE_SR0_RP
, loc
+ 20);
1049 /* Point the function symbol at the stub. */
1050 stub_entry
->h
->elf
.root
.u
.def
.section
= stub_sec
;
1051 stub_entry
->h
->elf
.root
.u
.def
.value
= stub_sec
->_raw_size
;
1061 stub_sec
->_raw_size
+= size
;
1087 /* As above, but don't actually build the stub. Just bump offset so
1088 we know stub section sizes. */
1091 hppa_size_one_stub (gen_entry
, in_arg
)
1092 struct bfd_hash_entry
*gen_entry
;
1095 struct elf32_hppa_stub_hash_entry
*stub_entry
;
1096 struct elf32_hppa_link_hash_table
*hplink
;
1099 /* Massage our args to the form they really have. */
1100 stub_entry
= (struct elf32_hppa_stub_hash_entry
*) gen_entry
;
1101 hplink
= (struct elf32_hppa_link_hash_table
*) in_arg
;
1103 if (stub_entry
->stub_type
== hppa_stub_long_branch
)
1105 #if ! LONG_BRANCH_PIC_IN_SHLIB
1106 if (stub_entry
->reloc_sec
!= NULL
)
1107 stub_entry
->reloc_sec
->_raw_size
+= sizeof (Elf32_External_Rela
);
1111 else if (stub_entry
->stub_type
== hppa_stub_long_branch_shared
)
1113 else if (stub_entry
->stub_type
== hppa_stub_export
)
1115 else /* hppa_stub_import or hppa_stub_import_shared. */
1117 if (hplink
->multi_subspace
)
1123 stub_entry
->stub_sec
->_raw_size
+= size
;
1127 /* Return nonzero if ABFD represents an HPPA ELF32 file.
1128 Additionally we set the default architecture and machine. */
1131 elf32_hppa_object_p (abfd
)
1134 unsigned int flags
= elf_elfheader (abfd
)->e_flags
;
1136 switch (flags
& (EF_PARISC_ARCH
| EF_PARISC_WIDE
))
1138 case EFA_PARISC_1_0
:
1139 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 10);
1140 case EFA_PARISC_1_1
:
1141 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 11);
1142 case EFA_PARISC_2_0
:
1143 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 20);
1144 case EFA_PARISC_2_0
| EF_PARISC_WIDE
:
1145 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 25);
1150 /* Undo the generic ELF code's subtraction of section->vma from the
1151 value of each external symbol. */
1154 elf32_hppa_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
1155 bfd
*abfd ATTRIBUTE_UNUSED
;
1156 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1157 const Elf_Internal_Sym
*sym ATTRIBUTE_UNUSED
;
1158 const char **namep ATTRIBUTE_UNUSED
;
1159 flagword
*flagsp ATTRIBUTE_UNUSED
;
1163 *valp
+= (*secp
)->vma
;
1167 /* Create the .plt and .got sections, and set up our hash table
1168 short-cuts to various dynamic sections. */
1171 elf32_hppa_create_dynamic_sections (abfd
, info
)
1173 struct bfd_link_info
*info
;
1175 struct elf32_hppa_link_hash_table
*hplink
;
1177 /* Don't try to create the .plt and .got twice. */
1178 hplink
= hppa_link_hash_table (info
);
1179 if (hplink
->splt
!= NULL
)
1182 /* Call the generic code to do most of the work. */
1183 if (! _bfd_elf_create_dynamic_sections (abfd
, info
))
1186 hplink
->splt
= bfd_get_section_by_name (abfd
, ".plt");
1187 hplink
->srelplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
1189 hplink
->sgot
= bfd_get_section_by_name (abfd
, ".got");
1190 hplink
->srelgot
= bfd_make_section (abfd
, ".rela.got");
1191 if (hplink
->srelgot
== NULL
1192 || ! bfd_set_section_flags (abfd
, hplink
->srelgot
,
1197 | SEC_LINKER_CREATED
1199 || ! bfd_set_section_alignment (abfd
, hplink
->srelgot
, 2))
1202 hplink
->sdynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
1203 hplink
->srelbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
1208 /* Look through the relocs for a section during the first phase, and
1209 allocate space in the global offset table or procedure linkage
1210 table. At this point we haven't necessarily read all the input
1214 elf32_hppa_check_relocs (abfd
, info
, sec
, relocs
)
1216 struct bfd_link_info
*info
;
1218 const Elf_Internal_Rela
*relocs
;
1221 Elf_Internal_Shdr
*symtab_hdr
;
1222 struct elf_link_hash_entry
**sym_hashes
;
1223 bfd_signed_vma
*local_got_refcounts
;
1224 const Elf_Internal_Rela
*rel
;
1225 const Elf_Internal_Rela
*rel_end
;
1226 struct elf32_hppa_link_hash_table
*hplink
;
1228 asection
*stubreloc
;
1230 if (info
->relocateable
)
1233 hplink
= hppa_link_hash_table (info
);
1234 dynobj
= hplink
->root
.dynobj
;
1235 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1236 sym_hashes
= elf_sym_hashes (abfd
);
1237 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1241 rel_end
= relocs
+ sec
->reloc_count
;
1242 for (rel
= relocs
; rel
< rel_end
; rel
++)
1248 #if LONG_BRANCH_PIC_IN_SHLIB
1249 NEED_STUBREL
= 0, /* We won't be needing them in this case. */
1256 unsigned int r_symndx
, r_type
;
1257 struct elf32_hppa_link_hash_entry
*h
;
1260 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1262 if (r_symndx
< symtab_hdr
->sh_info
)
1265 h
= ((struct elf32_hppa_link_hash_entry
*)
1266 sym_hashes
[r_symndx
- symtab_hdr
->sh_info
]);
1268 r_type
= ELF32_R_TYPE (rel
->r_info
);
1272 case R_PARISC_DLTIND14F
:
1273 case R_PARISC_DLTIND14R
:
1274 case R_PARISC_DLTIND21L
:
1275 /* This symbol requires a global offset table entry. */
1276 need_entry
= NEED_GOT
;
1278 /* Mark this section as containing PIC code. */
1279 sec
->flags
|= SEC_HAS_GOT_REF
;
1282 case R_PARISC_PLABEL14R
: /* "Official" procedure labels. */
1283 case R_PARISC_PLABEL21L
:
1284 case R_PARISC_PLABEL32
:
1285 /* If the addend is non-zero, we break badly. */
1286 BFD_ASSERT (rel
->r_addend
== 0);
1288 /* If we are creating a shared library, then we need to
1289 create a PLT entry for all PLABELs, because PLABELs with
1290 local symbols may be passed via a pointer to another
1291 object. Additionally, output a dynamic relocation
1292 pointing to the PLT entry. */
1293 need_entry
= PLT_PLABEL
| NEED_PLT
| NEED_DYNREL
;
1296 case R_PARISC_PCREL12F
:
1297 hplink
->has_12bit_branch
= 1;
1299 case R_PARISC_PCREL17C
:
1300 case R_PARISC_PCREL17F
:
1301 hplink
->has_17bit_branch
= 1;
1303 case R_PARISC_PCREL22F
:
1304 /* Function calls might need to go through the .plt, and
1305 might require long branch stubs. */
1308 /* We know local syms won't need a .plt entry, and if
1309 they need a long branch stub we can't guarantee that
1310 we can reach the stub. So just flag an error later
1311 if we're doing a shared link and find we need a long
1317 /* Global symbols will need a .plt entry if they remain
1318 global, and in most cases won't need a long branch
1319 stub. Unfortunately, we have to cater for the case
1320 where a symbol is forced local by versioning, or due
1321 to symbolic linking, and we lose the .plt entry. */
1322 need_entry
= NEED_PLT
| NEED_STUBREL
;
1326 case R_PARISC_SEGBASE
: /* Used to set segment base. */
1327 case R_PARISC_SEGREL32
: /* Relative reloc, used for unwind. */
1328 case R_PARISC_PCREL14F
: /* PC relative load/store. */
1329 case R_PARISC_PCREL14R
:
1330 case R_PARISC_PCREL17R
: /* External branches. */
1331 case R_PARISC_PCREL21L
: /* As above, and for load/store too. */
1332 /* We don't need to propagate the relocation if linking a
1333 shared object since these are section relative. */
1336 case R_PARISC_DPREL14F
: /* Used for gp rel data load/store. */
1337 case R_PARISC_DPREL14R
:
1338 case R_PARISC_DPREL21L
:
1341 (*_bfd_error_handler
)
1342 (_("%s: relocation %s can not be used when making a shared object; recompile with -fPIC"),
1343 bfd_get_filename (abfd
),
1344 elf_hppa_howto_table
[r_type
].name
);
1345 bfd_set_error (bfd_error_bad_value
);
1350 case R_PARISC_DIR17F
: /* Used for external branches. */
1351 case R_PARISC_DIR17R
:
1352 case R_PARISC_DIR14F
: /* Used for load/store from absolute locn. */
1353 case R_PARISC_DIR14R
:
1354 case R_PARISC_DIR21L
: /* As above, and for ext branches too. */
1356 /* Help debug shared library creation. Any of the above
1357 relocs can be used in shared libs, but they may cause
1358 pages to become unshared. */
1361 (*_bfd_error_handler
)
1362 (_("%s: relocation %s should not be used when making a shared object; recompile with -fPIC"),
1363 bfd_get_filename (abfd
),
1364 elf_hppa_howto_table
[r_type
].name
);
1369 case R_PARISC_DIR32
: /* .word relocs. */
1370 /* We may want to output a dynamic relocation later. */
1371 need_entry
= NEED_DYNREL
;
1374 /* This relocation describes the C++ object vtable hierarchy.
1375 Reconstruct it for later use during GC. */
1376 case R_PARISC_GNU_VTINHERIT
:
1377 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
,
1378 &h
->elf
, rel
->r_offset
))
1382 /* This relocation describes which C++ vtable entries are actually
1383 used. Record for later use during GC. */
1384 case R_PARISC_GNU_VTENTRY
:
1385 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
,
1386 &h
->elf
, rel
->r_addend
))
1394 /* Now carry out our orders. */
1395 if (need_entry
& NEED_GOT
)
1397 /* Allocate space for a GOT entry, as well as a dynamic
1398 relocation for this entry. */
1400 hplink
->root
.dynobj
= dynobj
= abfd
;
1402 if (hplink
->sgot
== NULL
)
1404 if (! elf32_hppa_create_dynamic_sections (dynobj
, info
))
1410 if (h
->elf
.got
.refcount
== -1)
1412 h
->elf
.got
.refcount
= 1;
1414 /* Make sure this symbol is output as a dynamic symbol. */
1415 if (h
->elf
.dynindx
== -1)
1417 if (! bfd_elf32_link_record_dynamic_symbol (info
,
1422 hplink
->sgot
->_raw_size
+= GOT_ENTRY_SIZE
;
1423 hplink
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
1426 h
->elf
.got
.refcount
+= 1;
1430 /* This is a global offset table entry for a local symbol. */
1431 if (local_got_refcounts
== NULL
)
1435 /* Allocate space for local got offsets and local
1436 plt offsets. Done this way to save polluting
1437 elf_obj_tdata with another target specific
1439 size
= symtab_hdr
->sh_info
* 2 * sizeof (bfd_signed_vma
);
1440 local_got_refcounts
= ((bfd_signed_vma
*)
1441 bfd_alloc (abfd
, size
));
1442 if (local_got_refcounts
== NULL
)
1444 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1445 memset (local_got_refcounts
, -1, size
);
1447 if (local_got_refcounts
[r_symndx
] == -1)
1449 local_got_refcounts
[r_symndx
] = 1;
1451 hplink
->sgot
->_raw_size
+= GOT_ENTRY_SIZE
;
1454 /* If we are generating a shared object, we need to
1455 output a reloc so that the dynamic linker can
1456 adjust this GOT entry (because the address
1457 the shared library is loaded at is not fixed). */
1458 hplink
->srelgot
->_raw_size
+=
1459 sizeof (Elf32_External_Rela
);
1463 local_got_refcounts
[r_symndx
] += 1;
1467 if (need_entry
& NEED_PLT
)
1469 /* If we are creating a shared library, and this is a reloc
1470 against a weak symbol or a global symbol in a dynamic
1471 object, then we will be creating an import stub and a
1472 .plt entry for the symbol. Similarly, on a normal link
1473 to symbols defined in a dynamic object we'll need the
1474 import stub and a .plt entry. We don't know yet whether
1475 the symbol is defined or not, so make an entry anyway and
1476 clean up later in adjust_dynamic_symbol. */
1477 if ((sec
->flags
& SEC_ALLOC
) != 0)
1481 if (h
->elf
.plt
.refcount
== -1)
1483 h
->elf
.plt
.refcount
= 1;
1484 h
->elf
.elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1487 h
->elf
.plt
.refcount
+= 1;
1489 /* If this .plt entry is for a plabel, mark it so
1490 that adjust_dynamic_symbol will keep the entry
1491 even if it appears to be local. */
1492 if (need_entry
& PLT_PLABEL
)
1495 else if (need_entry
& PLT_PLABEL
)
1499 if (local_got_refcounts
== NULL
)
1503 /* Allocate space for local got offsets and local
1505 size
= symtab_hdr
->sh_info
* 2 * sizeof (bfd_signed_vma
);
1506 local_got_refcounts
= ((bfd_signed_vma
*)
1507 bfd_alloc (abfd
, size
));
1508 if (local_got_refcounts
== NULL
)
1510 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1511 memset (local_got_refcounts
, -1, size
);
1513 indx
= r_symndx
+ symtab_hdr
->sh_info
;
1514 if (local_got_refcounts
[indx
] == -1)
1515 local_got_refcounts
[indx
] = 1;
1517 local_got_refcounts
[indx
] += 1;
1522 if (need_entry
& (NEED_DYNREL
| NEED_STUBREL
))
1524 /* Flag this symbol as having a non-got, non-plt reference
1525 so that we generate copy relocs if it turns out to be
1528 h
->elf
.elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
1530 /* If we are creating a shared library then we need to copy
1531 the reloc into the shared library. However, if we are
1532 linking with -Bsymbolic, we need only copy absolute
1533 relocs or relocs against symbols that are not defined in
1534 an object we are including in the link. PC- or DP- or
1535 DLT-relative relocs against any local sym or global sym
1536 with DEF_REGULAR set, can be discarded. At this point we
1537 have not seen all the input files, so it is possible that
1538 DEF_REGULAR is not set now but will be set later (it is
1539 never cleared). We account for that possibility below by
1540 storing information in the reloc_entries field of the
1543 A similar situation to the -Bsymbolic case occurs when
1544 creating shared libraries and symbol visibility changes
1545 render the symbol local.
1547 As it turns out, all the relocs we will be creating here
1548 are absolute, so we cannot remove them on -Bsymbolic
1549 links or visibility changes anyway. A STUB_REL reloc
1550 is absolute too, as in that case it is the reloc in the
1551 stub we will be creating, rather than copying the PCREL
1552 reloc in the branch. */
1553 if ((sec
->flags
& SEC_ALLOC
) != 0
1555 #if RELATIVE_DYNAMIC_RELOCS
1557 || is_absolute_reloc (r_type
)
1559 && ((h
->elf
.elf_link_hash_flags
1560 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
1568 if ((need_entry
& NEED_STUBREL
))
1571 /* Create a reloc section in dynobj and make room for
1578 hplink
->root
.dynobj
= dynobj
= abfd
;
1580 name
= bfd_elf_string_from_elf_section
1582 elf_elfheader (abfd
)->e_shstrndx
,
1583 elf_section_data (sec
)->rel_hdr
.sh_name
);
1586 (*_bfd_error_handler
)
1587 (_("Could not find relocation section for %s"),
1589 bfd_set_error (bfd_error_bad_value
);
1593 if ((need_entry
& NEED_STUBREL
))
1595 size_t len
= strlen (name
) + sizeof (STUB_SUFFIX
);
1596 char *newname
= bfd_malloc (len
);
1598 if (newname
== NULL
)
1600 strcpy (newname
, name
);
1601 strcpy (newname
+ len
- sizeof (STUB_SUFFIX
),
1606 srel
= bfd_get_section_by_name (dynobj
, name
);
1611 srel
= bfd_make_section (dynobj
, name
);
1612 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
1613 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1614 if ((sec
->flags
& SEC_ALLOC
) != 0)
1615 flags
|= SEC_ALLOC
| SEC_LOAD
;
1617 || !bfd_set_section_flags (dynobj
, srel
, flags
)
1618 || !bfd_set_section_alignment (dynobj
, srel
, 2))
1621 else if ((need_entry
& NEED_STUBREL
))
1624 if ((need_entry
& NEED_STUBREL
))
1630 #if ! LONG_BRANCH_PIC_IN_SHLIB
1631 /* If this is a function call, we only need one dynamic
1632 reloc for the stub as all calls to a particular
1633 function will go through the same stub. Actually, a
1634 long branch stub needs two relocations, but we count
1635 on some intelligence on the part of the dynamic
1637 if ((need_entry
& NEED_STUBREL
))
1639 doit
= h
->stub_reloc_sec
!= stubreloc
;
1640 h
->stub_reloc_sec
= stubreloc
;
1648 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
1650 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
1651 /* Keep track of relocations we have entered for
1652 this global symbol, so that we can discard them
1653 later if necessary. */
1656 #if RELATIVE_DYNAMIC_RELOCS
1657 || ! is_absolute_reloc (rtype
)
1659 || (need_entry
& NEED_STUBREL
)))
1661 struct elf32_hppa_dyn_reloc_entry
*p
;
1663 for (p
= h
->reloc_entries
; p
!= NULL
; p
= p
->next
)
1664 if (p
->section
== srel
)
1669 p
= ((struct elf32_hppa_dyn_reloc_entry
*)
1670 bfd_alloc (dynobj
, sizeof *p
));
1673 p
->next
= h
->reloc_entries
;
1674 h
->reloc_entries
= p
;
1679 /* NEED_STUBREL and NEED_DYNREL are never both
1680 set. Leave the count at zero for the
1681 NEED_STUBREL case as we only ever have one
1682 stub reloc per section per symbol, and this
1683 simplifies code in hppa_discard_copies. */
1684 if (! (need_entry
& NEED_STUBREL
))
1696 /* Return the section that should be marked against garbage collection
1697 for a given relocation. */
1700 elf32_hppa_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
1702 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1703 Elf_Internal_Rela
*rel
;
1704 struct elf_link_hash_entry
*h
;
1705 Elf_Internal_Sym
*sym
;
1709 switch ((unsigned int) ELF32_R_TYPE (rel
->r_info
))
1711 case R_PARISC_GNU_VTINHERIT
:
1712 case R_PARISC_GNU_VTENTRY
:
1716 switch (h
->root
.type
)
1718 case bfd_link_hash_defined
:
1719 case bfd_link_hash_defweak
:
1720 return h
->root
.u
.def
.section
;
1722 case bfd_link_hash_common
:
1723 return h
->root
.u
.c
.p
->section
;
1732 if (!(elf_bad_symtab (abfd
)
1733 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
1734 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
1735 && sym
->st_shndx
!= SHN_COMMON
))
1737 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
1744 /* Update the got and plt entry reference counts for the section being
1748 elf32_hppa_gc_sweep_hook (abfd
, info
, sec
, relocs
)
1750 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1752 const Elf_Internal_Rela
*relocs
;
1754 Elf_Internal_Shdr
*symtab_hdr
;
1755 struct elf_link_hash_entry
**sym_hashes
;
1756 bfd_signed_vma
*local_got_refcounts
;
1757 bfd_signed_vma
*local_plt_refcounts
;
1758 const Elf_Internal_Rela
*rel
, *relend
;
1759 unsigned long r_symndx
;
1760 struct elf_link_hash_entry
*h
;
1761 struct elf32_hppa_link_hash_table
*hplink
;
1766 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1767 sym_hashes
= elf_sym_hashes (abfd
);
1768 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1769 local_plt_refcounts
= local_got_refcounts
;
1770 if (local_plt_refcounts
!= NULL
)
1771 local_plt_refcounts
+= symtab_hdr
->sh_info
;
1772 hplink
= hppa_link_hash_table (info
);
1773 dynobj
= hplink
->root
.dynobj
;
1777 sgot
= hplink
->sgot
;
1778 srelgot
= hplink
->srelgot
;
1780 relend
= relocs
+ sec
->reloc_count
;
1781 for (rel
= relocs
; rel
< relend
; rel
++)
1782 switch ((unsigned int) ELF32_R_TYPE (rel
->r_info
))
1784 case R_PARISC_DLTIND14F
:
1785 case R_PARISC_DLTIND14R
:
1786 case R_PARISC_DLTIND21L
:
1787 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1788 if (r_symndx
>= symtab_hdr
->sh_info
)
1790 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1791 if (h
->got
.refcount
> 0)
1793 h
->got
.refcount
-= 1;
1794 if (h
->got
.refcount
== 0)
1796 sgot
->_raw_size
-= GOT_ENTRY_SIZE
;
1797 srelgot
->_raw_size
-= sizeof (Elf32_External_Rela
);
1801 else if (local_got_refcounts
!= NULL
)
1803 if (local_got_refcounts
[r_symndx
] > 0)
1805 local_got_refcounts
[r_symndx
] -= 1;
1806 if (local_got_refcounts
[r_symndx
] == 0)
1808 sgot
->_raw_size
-= GOT_ENTRY_SIZE
;
1810 srelgot
->_raw_size
-= sizeof (Elf32_External_Rela
);
1816 case R_PARISC_PCREL12F
:
1817 case R_PARISC_PCREL17C
:
1818 case R_PARISC_PCREL17F
:
1819 case R_PARISC_PCREL22F
:
1820 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1821 if (r_symndx
>= symtab_hdr
->sh_info
)
1823 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1824 if (h
->plt
.refcount
> 0)
1825 h
->plt
.refcount
-= 1;
1829 case R_PARISC_PLABEL14R
:
1830 case R_PARISC_PLABEL21L
:
1831 case R_PARISC_PLABEL32
:
1832 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1833 if (r_symndx
>= symtab_hdr
->sh_info
)
1835 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1836 if (h
->plt
.refcount
> 0)
1837 h
->plt
.refcount
-= 1;
1839 else if (local_plt_refcounts
!= NULL
)
1841 if (local_plt_refcounts
[r_symndx
] > 0)
1842 local_plt_refcounts
[r_symndx
] -= 1;
1853 /* Our own version of hide_symbol, so that we can keep plt entries for
1857 elf32_hppa_hide_symbol (info
, h
)
1858 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1859 struct elf_link_hash_entry
*h
;
1862 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
)
1864 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1865 h
->plt
.offset
= (bfd_vma
) -1;
1869 /* Adjust a symbol defined by a dynamic object and referenced by a
1870 regular object. The current definition is in some section of the
1871 dynamic object, but we're not including those sections. We have to
1872 change the definition to something the rest of the link can
1876 elf32_hppa_adjust_dynamic_symbol (info
, h
)
1877 struct bfd_link_info
*info
;
1878 struct elf_link_hash_entry
*h
;
1881 struct elf32_hppa_link_hash_table
*hplink
;
1884 hplink
= hppa_link_hash_table (info
);
1885 dynobj
= hplink
->root
.dynobj
;
1887 /* If this is a function, put it in the procedure linkage table. We
1888 will fill in the contents of the procedure linkage table later,
1889 when we know the address of the .got section. */
1890 if (h
->type
== STT_FUNC
1891 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1893 if (h
->plt
.refcount
<= 0
1894 || ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
1895 && h
->root
.type
!= bfd_link_hash_defweak
1896 && ! ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
1897 && (!info
->shared
|| info
->symbolic
)))
1899 /* The .plt entry is not needed when:
1900 a) Garbage collection has removed all references to the
1902 b) We know for certain the symbol is defined in this
1903 object, and it's not a weak definition, nor is the symbol
1904 used by a plabel relocation. Either this object is the
1905 application or we are doing a shared symbolic link. */
1907 /* As a special sop to the hppa ABI, we keep a .plt entry
1908 for functions in sections containing PIC code. */
1910 && h
->plt
.refcount
> 0
1911 && (h
->root
.type
== bfd_link_hash_defined
1912 || h
->root
.type
== bfd_link_hash_defweak
)
1913 && (h
->root
.u
.def
.section
->flags
& SEC_HAS_GOT_REF
) != 0)
1915 ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
= 1;
1919 h
->plt
.offset
= (bfd_vma
) -1;
1920 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1925 /* Make an entry in the .plt section. */
1927 h
->plt
.offset
= s
->_raw_size
;
1928 if (PLABEL_PLT_ENTRY_SIZE
!= PLT_ENTRY_SIZE
1929 && ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
1930 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1932 /* Add some extra space for the dynamic linker to use. */
1933 s
->_raw_size
+= PLABEL_PLT_ENTRY_SIZE
;
1936 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1938 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
)
1940 /* Make sure this symbol is output as a dynamic symbol. */
1941 if (h
->dynindx
== -1
1942 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1944 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1948 /* We also need to make an entry in the .rela.plt section. */
1949 s
= hplink
->srelplt
;
1950 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
1952 hplink
->need_plt_stub
= 1;
1957 /* If this is a weak symbol, and there is a real definition, the
1958 processor independent code will have arranged for us to see the
1959 real definition first, and we can just use the same value. */
1960 if (h
->weakdef
!= NULL
)
1962 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
1963 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
1964 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1965 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1969 /* This is a reference to a symbol defined by a dynamic object which
1970 is not a function. */
1972 /* If we are creating a shared library, we must presume that the
1973 only references to the symbol are via the global offset table.
1974 For such cases we need not do anything here; the relocations will
1975 be handled correctly by relocate_section. */
1979 /* If there are no references to this symbol that do not use the
1980 GOT, we don't need to generate a copy reloc. */
1981 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
1984 /* We must allocate the symbol in our .dynbss section, which will
1985 become part of the .bss section of the executable. There will be
1986 an entry for this symbol in the .dynsym section. The dynamic
1987 object will contain position independent code, so all references
1988 from the dynamic object to this symbol will go through the global
1989 offset table. The dynamic linker will use the .dynsym entry to
1990 determine the address it must put in the global offset table, so
1991 both the dynamic object and the regular object will refer to the
1992 same memory location for the variable. */
1994 s
= hplink
->sdynbss
;
1996 /* We must generate a COPY reloc to tell the dynamic linker to
1997 copy the initial value out of the dynamic object and into the
1998 runtime process image. We need to remember the offset into the
1999 .rela.bss section we are going to use. */
2000 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2004 srel
= hplink
->srelbss
;
2005 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
2006 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
2010 /* We need to figure out the alignment required for this symbol. I
2011 have no idea how other ELF linkers handle this. */
2012 unsigned int power_of_two
;
2014 power_of_two
= bfd_log2 (h
->size
);
2015 if (power_of_two
> 3)
2018 /* Apply the required alignment. */
2019 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
2020 (bfd_size_type
) (1 << power_of_two
));
2021 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
2023 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
2027 /* Define the symbol as being at this point in the section. */
2028 h
->root
.u
.def
.section
= s
;
2029 h
->root
.u
.def
.value
= s
->_raw_size
;
2031 /* Increment the section size to make room for the symbol. */
2032 s
->_raw_size
+= h
->size
;
2037 /* Called via elf_link_hash_traverse to create .plt entries for an
2038 application that uses statically linked PIC functions. Similar to
2039 the first part of elf32_hppa_adjust_dynamic_symbol. */
2042 hppa_handle_PIC_calls (h
, inf
)
2043 struct elf_link_hash_entry
*h
;
2046 struct bfd_link_info
*info
;
2048 struct elf32_hppa_link_hash_table
*hplink
;
2051 if (! (h
->plt
.refcount
> 0
2052 && (h
->root
.type
== bfd_link_hash_defined
2053 || h
->root
.type
== bfd_link_hash_defweak
)
2054 && (h
->root
.u
.def
.section
->flags
& SEC_HAS_GOT_REF
) != 0))
2056 h
->plt
.offset
= (bfd_vma
) -1;
2057 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2061 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2062 ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
= 1;
2064 info
= (struct bfd_link_info
*) inf
;
2065 hplink
= hppa_link_hash_table (info
);
2066 dynobj
= hplink
->root
.dynobj
;
2068 /* Make an entry in the .plt section. */
2070 h
->plt
.offset
= s
->_raw_size
;
2071 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2076 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
2077 || RELATIVE_DYNAMIC_RELOCS)
2078 /* This function is called via elf_link_hash_traverse to discard space
2079 we allocated for relocs that it turned out we didn't need. */
2082 hppa_discard_copies (h
, inf
)
2083 struct elf_link_hash_entry
*h
;
2086 struct elf32_hppa_dyn_reloc_entry
*s
;
2087 struct elf32_hppa_link_hash_entry
*eh
;
2088 struct bfd_link_info
*info
;
2090 eh
= (struct elf32_hppa_link_hash_entry
*) h
;
2091 info
= (struct bfd_link_info
*) inf
;
2093 #if ! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT
2094 /* Handle the stub reloc case. If we have a plt entry for the
2095 function, we won't be needing long branch stubs. s->count will
2096 only be zero for stub relocs, which provides a handy way of
2097 flagging these relocs, and means we need do nothing special for
2098 the forced local and symbolic link case. */
2099 if (eh
->stub_reloc_sec
!= NULL
2100 && eh
->elf
.plt
.offset
!= (bfd_vma
) -1)
2102 for (s
= eh
->reloc_entries
; s
!= NULL
; s
= s
->next
)
2104 s
->section
->_raw_size
-= sizeof (Elf32_External_Rela
);
2108 #if RELATIVE_DYNAMIC_RELOCS
2109 /* If a symbol has been forced local or we have found a regular
2110 definition for the symbolic link case, then we won't be needing
2112 if (eh
->elf
.dynindx
== -1
2113 || ((eh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
2114 && !is_absolute_reloc (r_type
)
2117 for (s
= eh
->reloc_entries
; s
!= NULL
; s
= s
->next
)
2118 s
->section
->_raw_size
-= s
->count
* sizeof (Elf32_External_Rela
);
2126 /* This function is called via elf_link_hash_traverse to force
2127 millicode symbols local so they do not end up as globals in the
2128 dynamic symbol table. We ought to be able to do this in
2129 adjust_dynamic_symbol, but our adjust_dynamic_symbol is not called
2130 for all dynamic symbols. Arguably, this is a bug in
2131 elf_adjust_dynamic_symbol. */
2134 clobber_millicode_symbols (h
, info
)
2135 struct elf_link_hash_entry
*h
;
2136 struct bfd_link_info
*info
;
2138 /* Note! We only want to remove these from the dynamic symbol
2139 table. Therefore we do not set ELF_LINK_FORCED_LOCAL. */
2140 if (h
->type
== STT_PARISC_MILLI
)
2141 elf32_hppa_hide_symbol (info
, h
);
2145 /* Set the sizes of the dynamic sections. */
2148 elf32_hppa_size_dynamic_sections (output_bfd
, info
)
2150 struct bfd_link_info
*info
;
2152 struct elf32_hppa_link_hash_table
*hplink
;
2158 hplink
= hppa_link_hash_table (info
);
2159 dynobj
= hplink
->root
.dynobj
;
2160 BFD_ASSERT (dynobj
!= NULL
);
2162 if (hplink
->root
.dynamic_sections_created
)
2166 /* Set the contents of the .interp section to the interpreter. */
2169 s
= bfd_get_section_by_name (dynobj
, ".interp");
2170 BFD_ASSERT (s
!= NULL
);
2171 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2172 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2175 /* Force millicode symbols local. */
2176 elf_link_hash_traverse (&hplink
->root
,
2177 clobber_millicode_symbols
,
2180 /* Set up .plt offsets for local plabels. */
2181 for (i
= info
->input_bfds
; i
; i
= i
->link_next
)
2183 bfd_signed_vma
*local_plt
;
2184 bfd_signed_vma
*end_local_plt
;
2185 bfd_size_type locsymcount
;
2186 Elf_Internal_Shdr
*symtab_hdr
;
2188 local_plt
= elf_local_got_refcounts (i
);
2192 symtab_hdr
= &elf_tdata (i
)->symtab_hdr
;
2193 locsymcount
= symtab_hdr
->sh_info
;
2194 local_plt
+= locsymcount
;
2195 end_local_plt
= local_plt
+ locsymcount
;
2197 for (; local_plt
< end_local_plt
; ++local_plt
)
2202 *local_plt
= s
->_raw_size
;
2203 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2205 hplink
->srelplt
->_raw_size
+= sizeof (Elf32_External_Rela
);
2208 *local_plt
= (bfd_vma
) -1;
2214 /* Run through the function symbols, looking for any that are
2215 PIC, and allocate space for the necessary .plt entries so
2216 that %r19 will be set up. */
2218 elf_link_hash_traverse (&hplink
->root
,
2219 hppa_handle_PIC_calls
,
2222 /* We may have created entries in the .rela.got section.
2223 However, if we are not creating the dynamic sections, we will
2224 not actually use these entries. Reset the size of .rela.got,
2225 which will cause it to get stripped from the output file
2227 hplink
->srelgot
->_raw_size
= 0;
2230 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
2231 || RELATIVE_DYNAMIC_RELOCS)
2232 /* If this is a -Bsymbolic shared link, then we need to discard all
2233 relocs against symbols defined in a regular object. We also need
2234 to lose relocs we've allocated for long branch stubs if we know
2235 we won't be generating a stub. */
2237 elf_link_hash_traverse (&hplink
->root
,
2238 hppa_discard_copies
,
2242 /* The check_relocs and adjust_dynamic_symbol entry points have
2243 determined the sizes of the various dynamic sections. Allocate
2247 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2251 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2254 /* It's OK to base decisions on the section name, because none
2255 of the dynobj section names depend upon the input files. */
2256 name
= bfd_get_section_name (dynobj
, s
);
2258 if (strncmp (name
, ".rela", 5) == 0)
2260 if (s
->_raw_size
!= 0)
2263 const char *outname
;
2265 /* Remember whether there are any reloc sections other
2267 if (strcmp (name
+5, ".plt") != 0)
2270 /* If this relocation section applies to a read only
2271 section, then we probably need a DT_TEXTREL entry. */
2272 outname
= bfd_get_section_name (output_bfd
,
2274 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
2276 && (target
->flags
& SEC_READONLY
) != 0
2277 && (target
->flags
& SEC_ALLOC
) != 0)
2280 /* We use the reloc_count field as a counter if we need
2281 to copy relocs into the output file. */
2285 else if (strcmp (name
, ".plt") == 0)
2287 if (hplink
->need_plt_stub
)
2289 /* Make space for the plt stub at the end of the .plt
2290 section. We want this stub right at the end, up
2291 against the .got section. */
2292 int gotalign
= bfd_section_alignment (dynobj
, hplink
->sgot
);
2293 int pltalign
= bfd_section_alignment (dynobj
, s
);
2296 if (gotalign
> pltalign
)
2297 bfd_set_section_alignment (dynobj
, s
, gotalign
);
2298 mask
= ((bfd_size_type
) 1 << gotalign
) - 1;
2299 s
->_raw_size
= (s
->_raw_size
+ sizeof (plt_stub
) + mask
) & ~mask
;
2302 else if (strcmp (name
, ".got") == 0)
2306 /* It's not one of our sections, so don't allocate space. */
2310 if (s
->_raw_size
== 0)
2312 /* If we don't need this section, strip it from the
2313 output file. This is mostly to handle .rela.bss and
2314 .rela.plt. We must create both sections in
2315 create_dynamic_sections, because they must be created
2316 before the linker maps input sections to output
2317 sections. The linker does that before
2318 adjust_dynamic_symbol is called, and it is that
2319 function which decides whether anything needs to go
2320 into these sections. */
2321 _bfd_strip_section_from_output (info
, s
);
2325 /* Allocate memory for the section contents. Zero it, because
2326 we may not fill in all the reloc sections. */
2327 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
2328 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
2332 if (hplink
->root
.dynamic_sections_created
)
2334 /* Like IA-64 and HPPA64, always create a DT_PLTGOT. It
2335 actually has nothing to do with the PLT, it is how we
2336 communicate the LTP value of a load module to the dynamic
2338 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
2341 /* Add some entries to the .dynamic section. We fill in the
2342 values later, in elf32_hppa_finish_dynamic_sections, but we
2343 must add the entries now so that we get the correct size for
2344 the .dynamic section. The DT_DEBUG entry is filled in by the
2345 dynamic linker and used by the debugger. */
2348 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
2352 if (hplink
->srelplt
->_raw_size
!= 0)
2354 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
2355 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
2356 || ! bfd_elf32_add_dynamic_entry (info
, DT_JMPREL
, 0))
2362 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELA
, 0)
2363 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELASZ
, 0)
2364 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELAENT
,
2365 sizeof (Elf32_External_Rela
)))
2371 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
2373 info
->flags
|= DF_TEXTREL
;
2380 /* External entry points for sizing and building linker stubs. */
2382 /* Determine and set the size of the stub section for a final link.
2384 The basic idea here is to examine all the relocations looking for
2385 PC-relative calls to a target that is unreachable with a "bl"
2389 elf32_hppa_size_stubs (output_bfd
, stub_bfd
, info
, multi_subspace
, group_size
,
2390 add_stub_section
, layout_sections_again
)
2393 struct bfd_link_info
*info
;
2394 boolean multi_subspace
;
2395 bfd_signed_vma group_size
;
2396 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
2397 void (*layout_sections_again
) PARAMS ((void));
2401 asection
**input_list
, **list
;
2402 Elf_Internal_Sym
*local_syms
, **all_local_syms
;
2403 unsigned int bfd_indx
, bfd_count
;
2404 int top_id
, top_index
;
2405 struct elf32_hppa_link_hash_table
*hplink
;
2406 bfd_size_type stub_group_size
;
2407 boolean stubs_always_before_branch
;
2408 boolean stub_changed
= 0;
2411 hplink
= hppa_link_hash_table (info
);
2413 /* Stash our params away. */
2414 hplink
->stub_bfd
= stub_bfd
;
2415 hplink
->multi_subspace
= multi_subspace
;
2416 hplink
->add_stub_section
= add_stub_section
;
2417 hplink
->layout_sections_again
= layout_sections_again
;
2418 stubs_always_before_branch
= group_size
< 0;
2420 stub_group_size
= -group_size
;
2422 stub_group_size
= group_size
;
2423 if (stub_group_size
== 1)
2425 /* Default values. */
2426 stub_group_size
= 8000000;
2427 if (hplink
->has_17bit_branch
|| hplink
->multi_subspace
)
2428 stub_group_size
= 250000;
2429 if (hplink
->has_12bit_branch
)
2430 stub_group_size
= 7812;
2433 /* Count the number of input BFDs and find the top input section id. */
2434 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
2436 input_bfd
= input_bfd
->link_next
)
2439 for (section
= input_bfd
->sections
;
2441 section
= section
->next
)
2443 if (top_id
< section
->id
)
2444 top_id
= section
->id
;
2449 = (struct map_stub
*) bfd_zmalloc (sizeof (struct map_stub
) * (top_id
+ 1));
2450 if (hplink
->stub_group
== NULL
)
2453 /* Make a list of input sections for each output section included in
2456 We can't use output_bfd->section_count here to find the top output
2457 section index as some sections may have been removed, and
2458 _bfd_strip_section_from_output doesn't renumber the indices. */
2459 for (section
= output_bfd
->sections
, top_index
= 0;
2461 section
= section
->next
)
2463 if (top_index
< section
->index
)
2464 top_index
= section
->index
;
2468 = (asection
**) bfd_malloc (sizeof (asection
*) * (top_index
+ 1));
2469 if (input_list
== NULL
)
2472 /* For sections we aren't interested in, mark their entries with a
2473 value we can check later. */
2474 list
= input_list
+ top_index
;
2476 *list
= bfd_abs_section_ptr
;
2477 while (list
-- != input_list
);
2479 for (section
= output_bfd
->sections
;
2481 section
= section
->next
)
2483 if ((section
->flags
& SEC_CODE
) != 0)
2484 input_list
[section
->index
] = NULL
;
2487 /* Now actually build the lists. */
2488 for (input_bfd
= info
->input_bfds
;
2490 input_bfd
= input_bfd
->link_next
)
2492 for (section
= input_bfd
->sections
;
2494 section
= section
->next
)
2496 if (section
->output_section
!= NULL
2497 && section
->output_section
->owner
== output_bfd
2498 && section
->output_section
->index
<= top_index
)
2500 list
= input_list
+ section
->output_section
->index
;
2501 if (*list
!= bfd_abs_section_ptr
)
2503 /* Steal the link_sec pointer for our list. */
2504 #define PREV_SEC(sec) (hplink->stub_group[(sec)->id].link_sec)
2505 /* This happens to make the list in reverse order,
2506 which is what we want. */
2507 PREV_SEC (section
) = *list
;
2514 /* See whether we can group stub sections together. Grouping stub
2515 sections may result in fewer stubs. More importantly, we need to
2516 put all .init* and .fini* stubs at the beginning of the .init or
2517 .fini output sections respectively, because glibc splits the
2518 _init and _fini functions into multiple parts. Putting a stub in
2519 the middle of a function is not a good idea. */
2520 list
= input_list
+ top_index
;
2523 asection
*tail
= *list
;
2524 if (tail
== bfd_abs_section_ptr
)
2526 while (tail
!= NULL
)
2530 bfd_size_type total
;
2533 if (tail
->_cooked_size
)
2534 total
= tail
->_cooked_size
;
2536 total
= tail
->_raw_size
;
2537 while ((prev
= PREV_SEC (curr
)) != NULL
2538 && ((total
+= curr
->output_offset
- prev
->output_offset
)
2542 /* OK, the size from the start of CURR to the end is less
2543 than 250000 bytes and thus can be handled by one stub
2544 section. (or the tail section is itself larger than
2545 250000 bytes, in which case we may be toast.)
2546 We should really be keeping track of the total size of
2547 stubs added here, as stubs contribute to the final output
2548 section size. That's a little tricky, and this way will
2549 only break if stubs added total more than 12144 bytes, or
2550 1518 long branch stubs. It seems unlikely for more than
2551 1518 different functions to be called, especially from
2552 code only 250000 bytes long. */
2555 prev
= PREV_SEC (tail
);
2556 /* Set up this stub group. */
2557 hplink
->stub_group
[tail
->id
].link_sec
= curr
;
2559 while (tail
!= curr
&& (tail
= prev
) != NULL
);
2561 /* But wait, there's more! Input sections up to 250000
2562 bytes before the stub section can be handled by it too. */
2563 if (!stubs_always_before_branch
)
2567 && ((total
+= tail
->output_offset
- prev
->output_offset
)
2571 prev
= PREV_SEC (tail
);
2572 hplink
->stub_group
[tail
->id
].link_sec
= curr
;
2578 while (list
-- != input_list
);
2582 /* We want to read in symbol extension records only once. To do this
2583 we need to read in the local symbols in parallel and save them for
2584 later use; so hold pointers to the local symbols in an array. */
2586 = (Elf_Internal_Sym
**) bfd_zmalloc (sizeof (Elf_Internal_Sym
*)
2588 if (all_local_syms
== NULL
)
2591 /* Walk over all the input BFDs, swapping in local symbols.
2592 If we are creating a shared library, create hash entries for the
2594 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
2596 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
2598 Elf_Internal_Shdr
*symtab_hdr
;
2599 Elf_Internal_Sym
*isym
;
2600 Elf32_External_Sym
*ext_syms
, *esym
, *end_sy
;
2602 /* We'll need the symbol table in a second. */
2603 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2604 if (symtab_hdr
->sh_info
== 0)
2607 /* We need an array of the local symbols attached to the input bfd.
2608 Unfortunately, we're going to have to read & swap them in. */
2609 local_syms
= (Elf_Internal_Sym
*)
2610 bfd_malloc (symtab_hdr
->sh_info
* sizeof (Elf_Internal_Sym
));
2611 if (local_syms
== NULL
)
2613 goto error_ret_free_local
;
2615 all_local_syms
[bfd_indx
] = local_syms
;
2616 ext_syms
= (Elf32_External_Sym
*)
2617 bfd_malloc (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
));
2618 if (ext_syms
== NULL
)
2620 goto error_ret_free_local
;
2623 if (bfd_seek (input_bfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
2624 || (bfd_read (ext_syms
, 1,
2625 (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
)),
2627 != (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
))))
2630 goto error_ret_free_local
;
2633 /* Swap the local symbols in. */
2636 for (end_sy
= esym
+ symtab_hdr
->sh_info
; esym
< end_sy
; esym
++, isym
++)
2637 bfd_elf32_swap_symbol_in (input_bfd
, esym
, isym
);
2639 /* Now we can free the external symbols. */
2642 #if ! LONG_BRANCH_PIC_IN_SHLIB
2643 /* If this is a shared link, find all the stub reloc sections. */
2645 for (section
= input_bfd
->sections
;
2647 section
= section
->next
)
2650 asection
*reloc_sec
;
2652 name
= bfd_malloc (strlen (section
->name
)
2653 + sizeof STUB_SUFFIX
2657 sprintf (name
, ".rela%s%s", section
->name
, STUB_SUFFIX
);
2658 reloc_sec
= bfd_get_section_by_name (hplink
->root
.dynobj
, name
);
2659 hplink
->stub_group
[section
->id
].reloc_sec
= reloc_sec
;
2664 if (info
->shared
&& hplink
->multi_subspace
)
2666 struct elf_link_hash_entry
**sym_hashes
;
2667 struct elf_link_hash_entry
**end_hashes
;
2668 unsigned int symcount
;
2670 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
2671 - symtab_hdr
->sh_info
);
2672 sym_hashes
= elf_sym_hashes (input_bfd
);
2673 end_hashes
= sym_hashes
+ symcount
;
2675 /* Look through the global syms for functions; We need to
2676 build export stubs for all globally visible functions. */
2677 for (; sym_hashes
< end_hashes
; sym_hashes
++)
2679 struct elf32_hppa_link_hash_entry
*hash
;
2681 hash
= (struct elf32_hppa_link_hash_entry
*) *sym_hashes
;
2683 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
2684 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
2685 hash
= ((struct elf32_hppa_link_hash_entry
*)
2686 hash
->elf
.root
.u
.i
.link
);
2688 /* At this point in the link, undefined syms have been
2689 resolved, so we need to check that the symbol was
2690 defined in this BFD. */
2691 if ((hash
->elf
.root
.type
== bfd_link_hash_defined
2692 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
2693 && hash
->elf
.type
== STT_FUNC
2694 && hash
->elf
.root
.u
.def
.section
->output_section
!= NULL
2695 && (hash
->elf
.root
.u
.def
.section
->output_section
->owner
2697 && hash
->elf
.root
.u
.def
.section
->owner
== input_bfd
2698 && (hash
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
2699 && !(hash
->elf
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
2700 && ELF_ST_VISIBILITY (hash
->elf
.other
) == STV_DEFAULT
)
2703 const char *stub_name
;
2704 struct elf32_hppa_stub_hash_entry
*stub_entry
;
2706 sec
= hash
->elf
.root
.u
.def
.section
;
2707 stub_name
= hash
->elf
.root
.root
.string
;
2708 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
,
2711 if (stub_entry
== NULL
)
2713 stub_entry
= hppa_add_stub (stub_name
, sec
, hplink
);
2715 goto error_ret_free_local
;
2717 stub_entry
->target_value
= hash
->elf
.root
.u
.def
.value
;
2718 stub_entry
->target_section
= hash
->elf
.root
.u
.def
.section
;
2719 stub_entry
->stub_type
= hppa_stub_export
;
2720 stub_entry
->h
= hash
;
2725 (*_bfd_error_handler
) (_("%s: duplicate export stub %s"),
2726 bfd_get_filename (input_bfd
),
2738 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
2740 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
2742 Elf_Internal_Shdr
*symtab_hdr
;
2744 /* We'll need the symbol table in a second. */
2745 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2746 if (symtab_hdr
->sh_info
== 0)
2749 local_syms
= all_local_syms
[bfd_indx
];
2751 /* Walk over each section attached to the input bfd. */
2752 for (section
= input_bfd
->sections
;
2754 section
= section
->next
)
2756 Elf_Internal_Shdr
*input_rel_hdr
;
2757 Elf32_External_Rela
*external_relocs
, *erelaend
, *erela
;
2758 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
2760 /* If there aren't any relocs, then there's nothing more
2762 if ((section
->flags
& SEC_RELOC
) == 0
2763 || section
->reloc_count
== 0)
2766 /* If this section is a link-once section that will be
2767 discarded, then don't create any stubs. */
2768 if (section
->output_section
== NULL
2769 || section
->output_section
->owner
!= output_bfd
)
2772 /* Allocate space for the external relocations. */
2774 = ((Elf32_External_Rela
*)
2775 bfd_malloc (section
->reloc_count
2776 * sizeof (Elf32_External_Rela
)));
2777 if (external_relocs
== NULL
)
2779 goto error_ret_free_local
;
2782 /* Likewise for the internal relocations. */
2783 internal_relocs
= ((Elf_Internal_Rela
*)
2784 bfd_malloc (section
->reloc_count
2785 * sizeof (Elf_Internal_Rela
)));
2786 if (internal_relocs
== NULL
)
2788 free (external_relocs
);
2789 goto error_ret_free_local
;
2792 /* Read in the external relocs. */
2793 input_rel_hdr
= &elf_section_data (section
)->rel_hdr
;
2794 if (bfd_seek (input_bfd
, input_rel_hdr
->sh_offset
, SEEK_SET
) != 0
2795 || bfd_read (external_relocs
, 1,
2796 input_rel_hdr
->sh_size
,
2797 input_bfd
) != input_rel_hdr
->sh_size
)
2799 free (external_relocs
);
2800 error_ret_free_internal
:
2801 free (internal_relocs
);
2802 goto error_ret_free_local
;
2805 /* Swap in the relocs. */
2806 erela
= external_relocs
;
2807 erelaend
= erela
+ section
->reloc_count
;
2808 irela
= internal_relocs
;
2809 for (; erela
< erelaend
; erela
++, irela
++)
2810 bfd_elf32_swap_reloca_in (input_bfd
, erela
, irela
);
2812 /* We're done with the external relocs, free them. */
2813 free (external_relocs
);
2815 /* Now examine each relocation. */
2816 irela
= internal_relocs
;
2817 irelaend
= irela
+ section
->reloc_count
;
2818 for (; irela
< irelaend
; irela
++)
2820 unsigned int r_type
, r_indx
;
2821 enum elf32_hppa_stub_type stub_type
;
2822 struct elf32_hppa_stub_hash_entry
*stub_entry
;
2825 bfd_vma destination
;
2826 struct elf32_hppa_link_hash_entry
*hash
;
2828 const asection
*id_sec
;
2830 r_type
= ELF32_R_TYPE (irela
->r_info
);
2831 r_indx
= ELF32_R_SYM (irela
->r_info
);
2833 if (r_type
>= (unsigned int) R_PARISC_UNIMPLEMENTED
)
2835 bfd_set_error (bfd_error_bad_value
);
2836 goto error_ret_free_internal
;
2839 /* Only look for stubs on call instructions. */
2840 if (r_type
!= (unsigned int) R_PARISC_PCREL12F
2841 && r_type
!= (unsigned int) R_PARISC_PCREL17F
2842 && r_type
!= (unsigned int) R_PARISC_PCREL22F
)
2845 /* Now determine the call target, its name, value,
2851 if (r_indx
< symtab_hdr
->sh_info
)
2853 /* It's a local symbol. */
2854 Elf_Internal_Sym
*sym
;
2855 Elf_Internal_Shdr
*hdr
;
2857 sym
= local_syms
+ r_indx
;
2858 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
2859 sym_sec
= hdr
->bfd_section
;
2860 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
2861 sym_value
= sym
->st_value
;
2862 destination
= (sym_value
+ irela
->r_addend
2863 + sym_sec
->output_offset
2864 + sym_sec
->output_section
->vma
);
2868 /* It's an external symbol. */
2871 e_indx
= r_indx
- symtab_hdr
->sh_info
;
2872 hash
= ((struct elf32_hppa_link_hash_entry
*)
2873 elf_sym_hashes (input_bfd
)[e_indx
]);
2875 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
2876 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
2877 hash
= ((struct elf32_hppa_link_hash_entry
*)
2878 hash
->elf
.root
.u
.i
.link
);
2880 if (hash
->elf
.root
.type
== bfd_link_hash_defined
2881 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
2883 sym_sec
= hash
->elf
.root
.u
.def
.section
;
2884 sym_value
= hash
->elf
.root
.u
.def
.value
;
2885 if (sym_sec
->output_section
!= NULL
)
2886 destination
= (sym_value
+ irela
->r_addend
2887 + sym_sec
->output_offset
2888 + sym_sec
->output_section
->vma
);
2890 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
)
2895 else if (hash
->elf
.root
.type
== bfd_link_hash_undefined
)
2898 && !info
->no_undefined
2899 && (ELF_ST_VISIBILITY (hash
->elf
.other
)
2905 bfd_set_error (bfd_error_bad_value
);
2906 goto error_ret_free_internal
;
2910 /* Determine what (if any) linker stub is needed. */
2911 stub_type
= hppa_type_of_stub (section
, irela
, hash
,
2913 if (stub_type
== hppa_stub_none
)
2916 /* Support for grouping stub sections. */
2917 id_sec
= hplink
->stub_group
[section
->id
].link_sec
;
2919 /* Get the name of this stub. */
2920 stub_name
= hppa_stub_name (id_sec
, sym_sec
, hash
, irela
);
2922 goto error_ret_free_internal
;
2924 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
,
2927 if (stub_entry
!= NULL
)
2929 /* The proper stub has already been created. */
2934 stub_entry
= hppa_add_stub (stub_name
, section
, hplink
);
2935 if (stub_entry
== NULL
)
2938 goto error_ret_free_local
;
2941 stub_entry
->target_value
= sym_value
;
2942 stub_entry
->target_section
= sym_sec
;
2943 stub_entry
->stub_type
= stub_type
;
2946 if (stub_type
== hppa_stub_import
)
2947 stub_entry
->stub_type
= hppa_stub_import_shared
;
2948 else if (stub_type
== hppa_stub_long_branch
2949 && (LONG_BRANCH_PIC_IN_SHLIB
|| hash
== NULL
))
2950 stub_entry
->stub_type
= hppa_stub_long_branch_shared
;
2952 stub_entry
->h
= hash
;
2956 /* We're done with the internal relocs, free them. */
2957 free (internal_relocs
);
2964 /* OK, we've added some stubs. Find out the new size of the
2966 for (stub_sec
= hplink
->stub_bfd
->sections
;
2968 stub_sec
= stub_sec
->next
)
2970 stub_sec
->_raw_size
= 0;
2971 stub_sec
->_cooked_size
= 0;
2973 #if ! LONG_BRANCH_PIC_IN_SHLIB
2977 for (i
= top_id
; i
>= 0; --i
)
2979 /* This will probably hit the same section many times.. */
2980 stub_sec
= hplink
->stub_group
[i
].reloc_sec
;
2981 if (stub_sec
!= NULL
)
2983 stub_sec
->_raw_size
= 0;
2984 stub_sec
->_cooked_size
= 0;
2990 bfd_hash_traverse (&hplink
->stub_hash_table
,
2994 /* Ask the linker to do its stuff. */
2995 (*hplink
->layout_sections_again
) ();
3001 error_ret_free_local
:
3002 while (bfd_count
-- > 0)
3003 if (all_local_syms
[bfd_count
])
3004 free (all_local_syms
[bfd_count
]);
3005 free (all_local_syms
);
3010 /* For a final link, this function is called after we have sized the
3011 stubs to provide a value for __gp. */
3014 elf32_hppa_set_gp (abfd
, info
)
3016 struct bfd_link_info
*info
;
3018 struct elf32_hppa_link_hash_table
*hplink
;
3019 struct elf_link_hash_entry
*h
;
3023 hplink
= hppa_link_hash_table (info
);
3024 h
= elf_link_hash_lookup (&hplink
->root
, "$global$",
3025 false, false, false);
3028 && (h
->root
.type
== bfd_link_hash_defined
3029 || h
->root
.type
== bfd_link_hash_defweak
))
3031 gp_val
= h
->root
.u
.def
.value
;
3032 sec
= h
->root
.u
.def
.section
;
3036 /* Choose to point our LTP at, in this order, one of .plt, .got,
3037 or .data, if these sections exist. In the case of choosing
3038 .plt try to make the LTP ideal for addressing anywhere in the
3039 .plt or .got with a 14 bit signed offset. Typically, the end
3040 of the .plt is the start of the .got, so choose .plt + 0x2000
3041 if either the .plt or .got is larger than 0x2000. If both
3042 the .plt and .got are smaller than 0x2000, choose the end of
3043 the .plt section. */
3048 gp_val
= sec
->_raw_size
;
3050 || (hplink
->sgot
&& hplink
->sgot
->_raw_size
> 0x2000))
3061 /* We know we don't have a .plt. If .got is large,
3063 if (sec
->_raw_size
> 0x2000)
3068 /* No .plt or .got. Who cares what the LTP is? */
3069 sec
= bfd_get_section_by_name (abfd
, ".data");
3075 h
->root
.type
= bfd_link_hash_defined
;
3076 h
->root
.u
.def
.value
= gp_val
;
3078 h
->root
.u
.def
.section
= sec
;
3080 h
->root
.u
.def
.section
= bfd_abs_section_ptr
;
3085 gp_val
+= sec
->output_section
->vma
+ sec
->output_offset
;
3087 elf_gp (abfd
) = gp_val
;
3091 /* Build all the stubs associated with the current output file. The
3092 stubs are kept in a hash table attached to the main linker hash
3093 table. We also set up the .plt entries for statically linked PIC
3094 functions here. This function is called via hppaelf_finish in the
3098 elf32_hppa_build_stubs (info
)
3099 struct bfd_link_info
*info
;
3102 struct bfd_hash_table
*table
;
3103 struct elf32_hppa_link_hash_table
*hplink
;
3105 hplink
= hppa_link_hash_table (info
);
3107 for (stub_sec
= hplink
->stub_bfd
->sections
;
3109 stub_sec
= stub_sec
->next
)
3113 /* Allocate memory to hold the linker stubs. */
3114 size
= stub_sec
->_raw_size
;
3115 stub_sec
->contents
= (unsigned char *) bfd_zalloc (hplink
->stub_bfd
,
3117 if (stub_sec
->contents
== NULL
&& size
!= 0)
3119 stub_sec
->_raw_size
= 0;
3122 /* Build the stubs as directed by the stub hash table. */
3123 table
= &hplink
->stub_hash_table
;
3124 bfd_hash_traverse (table
, hppa_build_one_stub
, info
);
3129 /* Perform a final link. */
3132 elf32_hppa_final_link (abfd
, info
)
3134 struct bfd_link_info
*info
;
3138 /* Invoke the regular ELF garbage collecting linker to do all the
3140 if (!_bfd_elf32_gc_common_final_link (abfd
, info
))
3143 /* If we're producing a final executable, sort the contents of the
3144 unwind section. Magic section names, but this is much safer than
3145 having elf32_hppa_relocate_section remember where SEGREL32 relocs
3146 occurred. Consider what happens if someone inept creates a
3147 linker script that puts unwind information in .text. */
3148 s
= bfd_get_section_by_name (abfd
, ".PARISC.unwind");
3154 size
= s
->_raw_size
;
3155 contents
= bfd_malloc (size
);
3156 if (contents
== NULL
)
3159 if (! bfd_get_section_contents (abfd
, s
, contents
, (file_ptr
) 0, size
))
3162 qsort (contents
, size
/ 16, 16, hppa_unwind_entry_compare
);
3164 if (! bfd_set_section_contents (abfd
, s
, contents
, (file_ptr
) 0, size
))
3170 /* Record the lowest address for the data and text segments. */
3173 hppa_record_segment_addr (abfd
, section
, data
)
3174 bfd
*abfd ATTRIBUTE_UNUSED
;
3178 struct elf32_hppa_link_hash_table
*hplink
;
3180 hplink
= (struct elf32_hppa_link_hash_table
*) data
;
3182 if ((section
->flags
& (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3184 bfd_vma value
= section
->vma
- section
->filepos
;
3186 if ((section
->flags
& SEC_READONLY
) != 0)
3188 if (value
< hplink
->text_segment_base
)
3189 hplink
->text_segment_base
= value
;
3193 if (value
< hplink
->data_segment_base
)
3194 hplink
->data_segment_base
= value
;
3199 /* Perform a relocation as part of a final link. */
3201 static bfd_reloc_status_type
3202 final_link_relocate (input_section
, contents
, rel
, value
, hplink
, sym_sec
, h
)
3203 asection
*input_section
;
3205 const Elf_Internal_Rela
*rel
;
3207 struct elf32_hppa_link_hash_table
*hplink
;
3209 struct elf32_hppa_link_hash_entry
*h
;
3212 unsigned int r_type
= ELF32_R_TYPE (rel
->r_info
);
3213 reloc_howto_type
*howto
= elf_hppa_howto_table
+ r_type
;
3214 int r_format
= howto
->bitsize
;
3215 enum hppa_reloc_field_selector_type_alt r_field
;
3216 bfd
*input_bfd
= input_section
->owner
;
3217 bfd_vma offset
= rel
->r_offset
;
3218 bfd_vma max_branch_offset
= 0;
3219 bfd_byte
*hit_data
= contents
+ offset
;
3220 bfd_signed_vma addend
= rel
->r_addend
;
3222 struct elf32_hppa_stub_hash_entry
*stub_entry
= NULL
;
3225 if (r_type
== R_PARISC_NONE
)
3226 return bfd_reloc_ok
;
3228 insn
= bfd_get_32 (input_bfd
, hit_data
);
3230 /* Find out where we are and where we're going. */
3231 location
= (offset
+
3232 input_section
->output_offset
+
3233 input_section
->output_section
->vma
);
3237 case R_PARISC_PCREL12F
:
3238 case R_PARISC_PCREL17F
:
3239 case R_PARISC_PCREL22F
:
3240 /* If this is a call to a function defined in another dynamic
3241 library, or if it is a call to a PIC function in the same
3242 object, or if this is a shared link and it is a call to a
3243 weak symbol which may or may not be in the same object, then
3244 find the import stub in the stub hash. */
3246 || sym_sec
->output_section
== NULL
3249 || (h
->elf
.root
.type
== bfd_link_hash_defweak
3250 && h
->elf
.dynindx
!= -1
3251 && h
->elf
.plt
.offset
!= (bfd_vma
) -1))))
3253 stub_entry
= hppa_get_stub_entry (input_section
, sym_sec
,
3255 if (stub_entry
!= NULL
)
3257 value
= (stub_entry
->stub_offset
3258 + stub_entry
->stub_sec
->output_offset
3259 + stub_entry
->stub_sec
->output_section
->vma
);
3262 else if (sym_sec
== NULL
&& h
!= NULL
3263 && h
->elf
.root
.type
== bfd_link_hash_undefweak
)
3265 /* It's OK if undefined weak. Make undefined weak
3266 branches go nowhere. */
3271 return bfd_reloc_notsupported
;
3275 case R_PARISC_PCREL21L
:
3276 case R_PARISC_PCREL17C
:
3277 case R_PARISC_PCREL17R
:
3278 case R_PARISC_PCREL14R
:
3279 case R_PARISC_PCREL14F
:
3280 /* Make it a pc relative offset. */
3285 case R_PARISC_DPREL21L
:
3286 case R_PARISC_DPREL14R
:
3287 case R_PARISC_DPREL14F
:
3288 /* For all the DP relative relocations, we need to examine the symbol's
3289 section. If it's a code section, then "data pointer relative" makes
3290 no sense. In that case we don't adjust the "value", and for 21 bit
3291 addil instructions, we change the source addend register from %dp to
3292 %r0. This situation commonly arises when a variable's "constness"
3293 is declared differently from the way the variable is defined. For
3294 instance: "extern int foo" with foo defined as "const int foo". */
3295 if (sym_sec
== NULL
)
3297 if ((sym_sec
->flags
& SEC_CODE
) != 0)
3299 if ((insn
& ((0x3f << 26) | (0x1f << 21)))
3300 == (((int) OP_ADDIL
<< 26) | (27 << 21)))
3302 insn
&= ~ (0x1f << 21);
3303 #if 1 /* debug them. */
3304 (*_bfd_error_handler
)
3305 (_("%s(%s+0x%lx): fixing %s"),
3306 bfd_get_filename (input_bfd
),
3307 input_section
->name
,
3308 (long) rel
->r_offset
,
3312 /* Now try to make things easy for the dynamic linker. */
3318 case R_PARISC_DLTIND21L
:
3319 case R_PARISC_DLTIND14R
:
3320 case R_PARISC_DLTIND14F
:
3321 value
-= elf_gp (input_section
->output_section
->owner
);
3324 case R_PARISC_SEGREL32
:
3325 if ((sym_sec
->flags
& SEC_CODE
) != 0)
3326 value
-= hplink
->text_segment_base
;
3328 value
-= hplink
->data_segment_base
;
3337 case R_PARISC_DIR32
:
3338 case R_PARISC_DIR14F
:
3339 case R_PARISC_DIR17F
:
3340 case R_PARISC_PCREL17C
:
3341 case R_PARISC_PCREL14F
:
3342 case R_PARISC_DPREL14F
:
3343 case R_PARISC_PLABEL32
:
3344 case R_PARISC_DLTIND14F
:
3345 case R_PARISC_SEGBASE
:
3346 case R_PARISC_SEGREL32
:
3350 case R_PARISC_DIR21L
:
3351 case R_PARISC_PCREL21L
:
3352 case R_PARISC_DPREL21L
:
3353 case R_PARISC_PLABEL21L
:
3354 case R_PARISC_DLTIND21L
:
3358 case R_PARISC_DIR17R
:
3359 case R_PARISC_PCREL17R
:
3360 case R_PARISC_DIR14R
:
3361 case R_PARISC_PCREL14R
:
3362 case R_PARISC_DPREL14R
:
3363 case R_PARISC_PLABEL14R
:
3364 case R_PARISC_DLTIND14R
:
3368 case R_PARISC_PCREL12F
:
3369 case R_PARISC_PCREL17F
:
3370 case R_PARISC_PCREL22F
:
3373 if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
3375 max_branch_offset
= (1 << (17-1)) << 2;
3377 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
3379 max_branch_offset
= (1 << (12-1)) << 2;
3383 max_branch_offset
= (1 << (22-1)) << 2;
3386 /* sym_sec is NULL on undefined weak syms or when shared on
3387 undefined syms. We've already checked for a stub for the
3388 shared undefined case. */
3389 if (sym_sec
== NULL
)
3392 /* If the branch is out of reach, then redirect the
3393 call to the local stub for this function. */
3394 if (value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3396 stub_entry
= hppa_get_stub_entry (input_section
, sym_sec
,
3398 if (stub_entry
== NULL
)
3399 return bfd_reloc_notsupported
;
3401 /* Munge up the value and addend so that we call the stub
3402 rather than the procedure directly. */
3403 value
= (stub_entry
->stub_offset
3404 + stub_entry
->stub_sec
->output_offset
3405 + stub_entry
->stub_sec
->output_section
->vma
3411 /* Something we don't know how to handle. */
3413 return bfd_reloc_notsupported
;
3416 /* Make sure we can reach the stub. */
3417 if (max_branch_offset
!= 0
3418 && value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3420 (*_bfd_error_handler
)
3421 (_("%s(%s+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
3422 bfd_get_filename (input_bfd
),
3423 input_section
->name
,
3424 (long) rel
->r_offset
,
3425 stub_entry
->root
.string
);
3426 return bfd_reloc_notsupported
;
3429 val
= hppa_field_adjust (value
, addend
, r_field
);
3433 case R_PARISC_PCREL12F
:
3434 case R_PARISC_PCREL17C
:
3435 case R_PARISC_PCREL17F
:
3436 case R_PARISC_PCREL17R
:
3437 case R_PARISC_PCREL22F
:
3438 case R_PARISC_DIR17F
:
3439 case R_PARISC_DIR17R
:
3440 /* This is a branch. Divide the offset by four.
3441 Note that we need to decide whether it's a branch or
3442 otherwise by inspecting the reloc. Inspecting insn won't
3443 work as insn might be from a .word directive. */
3451 insn
= hppa_rebuild_insn (insn
, val
, r_format
);
3453 /* Update the instruction word. */
3454 bfd_put_32 (input_bfd
, (bfd_vma
) insn
, hit_data
);
3455 return bfd_reloc_ok
;
3458 /* Relocate an HPPA ELF section. */
3461 elf32_hppa_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
3462 contents
, relocs
, local_syms
, local_sections
)
3464 struct bfd_link_info
*info
;
3466 asection
*input_section
;
3468 Elf_Internal_Rela
*relocs
;
3469 Elf_Internal_Sym
*local_syms
;
3470 asection
**local_sections
;
3473 bfd_vma
*local_got_offsets
;
3474 struct elf32_hppa_link_hash_table
*hplink
;
3475 Elf_Internal_Shdr
*symtab_hdr
;
3476 Elf_Internal_Rela
*rel
;
3477 Elf_Internal_Rela
*relend
;
3480 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3482 hplink
= hppa_link_hash_table (info
);
3483 dynobj
= hplink
->root
.dynobj
;
3484 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3488 relend
= relocs
+ input_section
->reloc_count
;
3489 for (; rel
< relend
; rel
++)
3491 unsigned int r_type
;
3492 reloc_howto_type
*howto
;
3493 unsigned int r_symndx
;
3494 struct elf32_hppa_link_hash_entry
*h
;
3495 Elf_Internal_Sym
*sym
;
3498 bfd_reloc_status_type r
;
3499 const char *sym_name
;
3502 r_type
= ELF32_R_TYPE (rel
->r_info
);
3503 if (r_type
>= (unsigned int) R_PARISC_UNIMPLEMENTED
)
3505 bfd_set_error (bfd_error_bad_value
);
3508 if (r_type
== (unsigned int) R_PARISC_GNU_VTENTRY
3509 || r_type
== (unsigned int) R_PARISC_GNU_VTINHERIT
)
3512 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3514 if (info
->relocateable
)
3516 /* This is a relocateable link. We don't have to change
3517 anything, unless the reloc is against a section symbol,
3518 in which case we have to adjust according to where the
3519 section symbol winds up in the output section. */
3520 if (r_symndx
< symtab_hdr
->sh_info
)
3522 sym
= local_syms
+ r_symndx
;
3523 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
3525 sym_sec
= local_sections
[r_symndx
];
3526 rel
->r_addend
+= sym_sec
->output_offset
;
3532 /* This is a final link. */
3536 if (r_symndx
< symtab_hdr
->sh_info
)
3538 /* This is a local symbol, h defaults to NULL. */
3539 sym
= local_syms
+ r_symndx
;
3540 sym_sec
= local_sections
[r_symndx
];
3541 relocation
= ((ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
3542 ? 0 : sym
->st_value
)
3543 + sym_sec
->output_offset
3544 + sym_sec
->output_section
->vma
);
3550 /* It's a global; Find its entry in the link hash. */
3551 indx
= r_symndx
- symtab_hdr
->sh_info
;
3552 h
= ((struct elf32_hppa_link_hash_entry
*)
3553 elf_sym_hashes (input_bfd
)[indx
]);
3554 while (h
->elf
.root
.type
== bfd_link_hash_indirect
3555 || h
->elf
.root
.type
== bfd_link_hash_warning
)
3556 h
= (struct elf32_hppa_link_hash_entry
*) h
->elf
.root
.u
.i
.link
;
3559 if (h
->elf
.root
.type
== bfd_link_hash_defined
3560 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
3562 sym_sec
= h
->elf
.root
.u
.def
.section
;
3563 /* If sym_sec->output_section is NULL, then it's a
3564 symbol defined in a shared library. */
3565 if (sym_sec
->output_section
!= NULL
)
3566 relocation
= (h
->elf
.root
.u
.def
.value
3567 + sym_sec
->output_offset
3568 + sym_sec
->output_section
->vma
);
3570 else if (h
->elf
.root
.type
== bfd_link_hash_undefweak
)
3572 else if (info
->shared
&& !info
->no_undefined
3573 && ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
)
3576 if (!((*info
->callbacks
->undefined_symbol
)
3577 (info
, h
->elf
.root
.root
.string
, input_bfd
,
3578 input_section
, rel
->r_offset
, false)))
3583 if (!((*info
->callbacks
->undefined_symbol
)
3584 (info
, h
->elf
.root
.root
.string
, input_bfd
,
3585 input_section
, rel
->r_offset
, true)))
3590 /* Do any required modifications to the relocation value, and
3591 determine what types of dynamic info we need to output, if
3596 case R_PARISC_DLTIND14F
:
3597 case R_PARISC_DLTIND14R
:
3598 case R_PARISC_DLTIND21L
:
3599 /* Relocation is to the entry for this symbol in the global
3605 off
= h
->elf
.got
.offset
;
3606 BFD_ASSERT (off
!= (bfd_vma
) -1);
3608 if (! hplink
->root
.dynamic_sections_created
3610 && (info
->symbolic
|| h
->elf
.dynindx
== -1)
3611 && (h
->elf
.elf_link_hash_flags
3612 & ELF_LINK_HASH_DEF_REGULAR
) != 0))
3614 /* This is actually a static link, or it is a
3615 -Bsymbolic link and the symbol is defined
3616 locally, or the symbol was forced to be local
3617 because of a version file. We must initialize
3618 this entry in the global offset table. Since the
3619 offset must always be a multiple of 4, we use the
3620 least significant bit to record whether we have
3621 initialized it already.
3623 When doing a dynamic link, we create a .rela.got
3624 relocation entry to initialize the value. This
3625 is done in the finish_dynamic_symbol routine. */
3630 bfd_put_32 (output_bfd
, relocation
,
3631 hplink
->sgot
->contents
+ off
);
3632 h
->elf
.got
.offset
|= 1;
3640 /* Local symbol case. */
3643 BFD_ASSERT (local_got_offsets
!= NULL
3644 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
3646 off
= local_got_offsets
[r_symndx
];
3648 /* The offset must always be a multiple of 4. We use
3649 the least significant bit to record whether we have
3650 already generated the necessary reloc. */
3655 bfd_put_32 (output_bfd
, relocation
,
3656 hplink
->sgot
->contents
+ off
);
3660 /* Output a dynamic *ABS* relocation for this
3661 GOT entry. In this case it is relative to
3662 the base of the object because the symbol
3664 Elf_Internal_Rela outrel
;
3665 asection
*srelgot
= hplink
->srelgot
;
3667 outrel
.r_offset
= (off
3668 + hplink
->sgot
->output_offset
3669 + hplink
->sgot
->output_section
->vma
);
3670 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_DIR32
);
3671 outrel
.r_addend
= relocation
;
3672 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3673 ((Elf32_External_Rela
*)
3675 + srelgot
->reloc_count
));
3676 ++srelgot
->reloc_count
;
3679 local_got_offsets
[r_symndx
] |= 1;
3685 /* Add the base of the GOT to the relocation value. */
3686 relocation
+= (hplink
->sgot
->output_offset
3687 + hplink
->sgot
->output_section
->vma
);
3690 case R_PARISC_SEGREL32
:
3691 /* If this is the first SEGREL relocation, then initialize
3692 the segment base values. */
3693 if (hplink
->text_segment_base
== (bfd_vma
) -1)
3694 bfd_map_over_sections (output_bfd
,
3695 hppa_record_segment_addr
,
3699 case R_PARISC_PLABEL14R
:
3700 case R_PARISC_PLABEL21L
:
3701 case R_PARISC_PLABEL32
:
3702 if (hplink
->root
.dynamic_sections_created
)
3706 /* If we have a global symbol with a PLT slot, then
3707 redirect this relocation to it. */
3710 off
= h
->elf
.plt
.offset
;
3716 indx
= r_symndx
+ symtab_hdr
->sh_info
;
3717 off
= local_got_offsets
[indx
];
3719 /* As for the local .got entry case, we use the last
3720 bit to record whether we've already initialised
3721 this local .plt entry. */
3726 bfd_put_32 (output_bfd
,
3728 hplink
->splt
->contents
+ off
);
3729 bfd_put_32 (output_bfd
,
3730 elf_gp (hplink
->splt
->output_section
->owner
),
3731 hplink
->splt
->contents
+ off
+ 4);
3735 /* Output a dynamic IPLT relocation for this
3737 Elf_Internal_Rela outrel
;
3738 asection
*srelplt
= hplink
->srelplt
;
3740 outrel
.r_offset
= (off
3741 + hplink
->splt
->output_offset
3742 + hplink
->splt
->output_section
->vma
);
3743 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_IPLT
);
3744 outrel
.r_addend
= relocation
;
3745 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3746 ((Elf32_External_Rela
*)
3748 + srelplt
->reloc_count
));
3749 ++srelplt
->reloc_count
;
3752 local_got_offsets
[indx
] |= 1;
3756 BFD_ASSERT (off
< (bfd_vma
) -2);
3758 /* PLABELs contain function pointers. Relocation is to
3759 the entry for the function in the .plt. The magic +2
3760 offset signals to $$dyncall that the function pointer
3761 is in the .plt and thus has a gp pointer too.
3762 Exception: Undefined PLABELs should have a value of
3765 || (h
->elf
.root
.type
!= bfd_link_hash_undefweak
3766 && h
->elf
.root
.type
!= bfd_link_hash_undefined
))
3769 + hplink
->splt
->output_offset
3770 + hplink
->splt
->output_section
->vma
3775 /* Fall through and possibly emit a dynamic relocation. */
3777 case R_PARISC_DIR17F
:
3778 case R_PARISC_DIR17R
:
3779 case R_PARISC_DIR14F
:
3780 case R_PARISC_DIR14R
:
3781 case R_PARISC_DIR21L
:
3782 case R_PARISC_DPREL14F
:
3783 case R_PARISC_DPREL14R
:
3784 case R_PARISC_DPREL21L
:
3785 case R_PARISC_DIR32
:
3786 /* The reloc types handled here and this conditional
3787 expression must match the code in check_relocs and
3788 hppa_discard_copies. ie. We need exactly the same
3789 condition as in check_relocs, with some extra conditions
3790 (dynindx test in this case) to cater for relocs removed
3791 by hppa_discard_copies. */
3792 if ((input_section
->flags
& SEC_ALLOC
) != 0
3794 #if RELATIVE_DYNAMIC_RELOCS
3795 && (is_absolute_reloc (r_type
)
3796 || ((!info
->symbolic
3798 && ((h
->elf
.elf_link_hash_flags
3799 & ELF_LINK_HASH_DEF_REGULAR
) == 0
3800 || h
->elf
.root
.type
== bfd_link_hash_defweak
)))
3801 && (h
== NULL
|| h
->elf
.dynindx
!= -1)))
3805 Elf_Internal_Rela outrel
;
3808 /* When generating a shared object, these relocations
3809 are copied into the output file to be resolved at run
3816 name
= (bfd_elf_string_from_elf_section
3818 elf_elfheader (input_bfd
)->e_shstrndx
,
3819 elf_section_data (input_section
)->rel_hdr
.sh_name
));
3822 sreloc
= bfd_get_section_by_name (dynobj
, name
);
3823 BFD_ASSERT (sreloc
!= NULL
);
3826 outrel
.r_offset
= rel
->r_offset
;
3827 outrel
.r_addend
= rel
->r_addend
;
3829 if (elf_section_data (input_section
)->stab_info
!= NULL
)
3833 off
= (_bfd_stab_section_offset
3834 (output_bfd
, &hplink
->root
.stab_info
,
3836 &elf_section_data (input_section
)->stab_info
,
3838 if (off
== (bfd_vma
) -1)
3840 outrel
.r_offset
= off
;
3843 outrel
.r_offset
+= (input_section
->output_offset
3844 + input_section
->output_section
->vma
);
3848 memset (&outrel
, 0, sizeof (outrel
));
3851 && h
->elf
.dynindx
!= -1
3854 || (h
->elf
.elf_link_hash_flags
3855 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
3857 outrel
.r_info
= ELF32_R_INFO (h
->elf
.dynindx
, r_type
);
3859 else /* It's a local symbol, or one marked to become local. */
3863 /* Add the absolute offset of the symbol. */
3864 outrel
.r_addend
+= relocation
;
3866 /* Global plabels need to be processed by the
3867 dynamic linker so that functions have at most one
3868 fptr. For this reason, we need to differentiate
3869 between global and local plabels, which we do by
3870 providing the function symbol for a global plabel
3871 reloc, and no symbol for local plabels. */
3874 && sym_sec
->output_section
!= NULL
3875 && ! bfd_is_abs_section (sym_sec
))
3877 indx
= elf_section_data (sym_sec
->output_section
)->dynindx
;
3878 /* We are turning this relocation into one
3879 against a section symbol, so subtract out the
3880 output section's address but not the offset
3881 of the input section in the output section. */
3882 outrel
.r_addend
-= sym_sec
->output_section
->vma
;
3885 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
3888 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3889 ((Elf32_External_Rela
*)
3891 + sreloc
->reloc_count
));
3892 ++sreloc
->reloc_count
;
3900 r
= final_link_relocate (input_section
, contents
, rel
, relocation
,
3901 hplink
, sym_sec
, h
);
3903 if (r
== bfd_reloc_ok
)
3907 sym_name
= h
->elf
.root
.root
.string
;
3910 sym_name
= bfd_elf_string_from_elf_section (input_bfd
,
3911 symtab_hdr
->sh_link
,
3913 if (sym_name
== NULL
)
3915 if (*sym_name
== '\0')
3916 sym_name
= bfd_section_name (input_bfd
, sym_sec
);
3919 howto
= elf_hppa_howto_table
+ r_type
;
3921 if (r
== bfd_reloc_undefined
|| r
== bfd_reloc_notsupported
)
3923 (*_bfd_error_handler
)
3924 (_("%s(%s+0x%lx): cannot handle %s for %s"),
3925 bfd_get_filename (input_bfd
),
3926 input_section
->name
,
3927 (long) rel
->r_offset
,
3933 if (!((*info
->callbacks
->reloc_overflow
)
3934 (info
, sym_name
, howto
->name
, (bfd_vma
) 0,
3935 input_bfd
, input_section
, rel
->r_offset
)))
3943 /* Comparison function for qsort to sort unwind section during a
3947 hppa_unwind_entry_compare (a
, b
)
3951 const bfd_byte
*ap
, *bp
;
3952 unsigned long av
, bv
;
3954 ap
= (const bfd_byte
*) a
;
3955 av
= (unsigned long) ap
[0] << 24;
3956 av
|= (unsigned long) ap
[1] << 16;
3957 av
|= (unsigned long) ap
[2] << 8;
3958 av
|= (unsigned long) ap
[3];
3960 bp
= (const bfd_byte
*) b
;
3961 bv
= (unsigned long) bp
[0] << 24;
3962 bv
|= (unsigned long) bp
[1] << 16;
3963 bv
|= (unsigned long) bp
[2] << 8;
3964 bv
|= (unsigned long) bp
[3];
3966 return av
< bv
? -1 : av
> bv
? 1 : 0;
3969 /* Finish up dynamic symbol handling. We set the contents of various
3970 dynamic sections here. */
3973 elf32_hppa_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
3975 struct bfd_link_info
*info
;
3976 struct elf_link_hash_entry
*h
;
3977 Elf_Internal_Sym
*sym
;
3979 struct elf32_hppa_link_hash_table
*hplink
;
3982 hplink
= hppa_link_hash_table (info
);
3983 dynobj
= hplink
->root
.dynobj
;
3985 if (h
->plt
.offset
!= (bfd_vma
) -1)
3989 /* This symbol has an entry in the procedure linkage table. Set
3992 The format of a plt entry is
3997 if (h
->root
.type
== bfd_link_hash_defined
3998 || h
->root
.type
== bfd_link_hash_defweak
)
4000 value
= h
->root
.u
.def
.value
;
4001 if (h
->root
.u
.def
.section
->output_section
!= NULL
)
4002 value
+= (h
->root
.u
.def
.section
->output_offset
4003 + h
->root
.u
.def
.section
->output_section
->vma
);
4006 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
)
4008 Elf_Internal_Rela rel
;
4010 /* Create a dynamic IPLT relocation for this entry. */
4011 rel
.r_offset
= (h
->plt
.offset
4012 + hplink
->splt
->output_offset
4013 + hplink
->splt
->output_section
->vma
);
4014 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->plt_abs
4015 && h
->dynindx
!= -1)
4017 /* To support lazy linking, the function pointer is
4018 initialised to point to a special stub stored at the
4019 end of the .plt. This is only done for plt entries
4020 with a non-*ABS* dynamic relocation. */
4021 value
= (hplink
->splt
->output_offset
4022 + hplink
->splt
->output_section
->vma
4023 + hplink
->splt
->_raw_size
4026 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_IPLT
);
4031 /* This symbol has been marked to become local, and is
4032 used by a plabel so must be kept in the .plt. */
4033 rel
.r_info
= ELF32_R_INFO (0, R_PARISC_IPLT
);
4034 rel
.r_addend
= value
;
4037 bfd_elf32_swap_reloca_out (hplink
->splt
->output_section
->owner
,
4039 ((Elf32_External_Rela
*)
4040 hplink
->srelplt
->contents
4041 + hplink
->srelplt
->reloc_count
));
4042 hplink
->srelplt
->reloc_count
++;
4045 bfd_put_32 (hplink
->splt
->owner
,
4047 hplink
->splt
->contents
+ h
->plt
.offset
);
4048 bfd_put_32 (hplink
->splt
->owner
,
4049 elf_gp (hplink
->splt
->output_section
->owner
),
4050 hplink
->splt
->contents
+ h
->plt
.offset
+ 4);
4051 if (PLABEL_PLT_ENTRY_SIZE
!= PLT_ENTRY_SIZE
4052 && ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
4053 && h
->dynindx
!= -1)
4055 memset (hplink
->splt
->contents
+ h
->plt
.offset
+ 8,
4056 0, PLABEL_PLT_ENTRY_SIZE
- PLT_ENTRY_SIZE
);
4059 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4061 /* Mark the symbol as undefined, rather than as defined in
4062 the .plt section. Leave the value alone. */
4063 sym
->st_shndx
= SHN_UNDEF
;
4067 if (h
->got
.offset
!= (bfd_vma
) -1)
4069 Elf_Internal_Rela rel
;
4071 /* This symbol has an entry in the global offset table. Set it
4074 rel
.r_offset
= ((h
->got
.offset
&~ (bfd_vma
) 1)
4075 + hplink
->sgot
->output_offset
4076 + hplink
->sgot
->output_section
->vma
);
4078 /* If this is a static link, or it is a -Bsymbolic link and the
4079 symbol is defined locally or was forced to be local because
4080 of a version file, we just want to emit a RELATIVE reloc.
4081 The entry in the global offset table will already have been
4082 initialized in the relocate_section function. */
4083 if (! hplink
->root
.dynamic_sections_created
4085 && (info
->symbolic
|| h
->dynindx
== -1)
4086 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
4088 rel
.r_info
= ELF32_R_INFO (0, R_PARISC_DIR32
);
4089 rel
.r_addend
= (h
->root
.u
.def
.value
4090 + h
->root
.u
.def
.section
->output_offset
4091 + h
->root
.u
.def
.section
->output_section
->vma
);
4095 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4096 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
4097 hplink
->sgot
->contents
+ h
->got
.offset
);
4098 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_DIR32
);
4102 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
4103 ((Elf32_External_Rela
*)
4104 hplink
->srelgot
->contents
4105 + hplink
->srelgot
->reloc_count
));
4106 ++hplink
->srelgot
->reloc_count
;
4109 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
4112 Elf_Internal_Rela rel
;
4114 /* This symbol needs a copy reloc. Set it up. */
4116 BFD_ASSERT (h
->dynindx
!= -1
4117 && (h
->root
.type
== bfd_link_hash_defined
4118 || h
->root
.type
== bfd_link_hash_defweak
));
4120 s
= hplink
->srelbss
;
4122 rel
.r_offset
= (h
->root
.u
.def
.value
4123 + h
->root
.u
.def
.section
->output_offset
4124 + h
->root
.u
.def
.section
->output_section
->vma
);
4126 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_COPY
);
4127 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
4128 ((Elf32_External_Rela
*) s
->contents
4133 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
4134 if (h
->root
.root
.string
[0] == '_'
4135 && (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4136 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0))
4138 sym
->st_shndx
= SHN_ABS
;
4144 /* Finish up the dynamic sections. */
4147 elf32_hppa_finish_dynamic_sections (output_bfd
, info
)
4149 struct bfd_link_info
*info
;
4152 struct elf32_hppa_link_hash_table
*hplink
;
4155 hplink
= hppa_link_hash_table (info
);
4156 dynobj
= hplink
->root
.dynobj
;
4158 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4160 if (hplink
->root
.dynamic_sections_created
)
4162 Elf32_External_Dyn
*dyncon
, *dynconend
;
4164 BFD_ASSERT (sdyn
!= NULL
);
4166 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4167 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
4168 for (; dyncon
< dynconend
; dyncon
++)
4170 Elf_Internal_Dyn dyn
;
4173 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4181 /* Use PLTGOT to set the GOT register. */
4182 dyn
.d_un
.d_ptr
= elf_gp (output_bfd
);
4183 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4187 s
= hplink
->srelplt
;
4188 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4189 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4193 s
= hplink
->srelplt
;
4194 if (s
->_cooked_size
!= 0)
4195 dyn
.d_un
.d_val
= s
->_cooked_size
;
4197 dyn
.d_un
.d_val
= s
->_raw_size
;
4198 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4204 if (hplink
->sgot
->_raw_size
!= 0)
4206 /* Fill in the first entry in the global offset table.
4207 We use it to point to our dynamic section, if we have one. */
4208 bfd_put_32 (output_bfd
,
4210 ? sdyn
->output_section
->vma
+ sdyn
->output_offset
4212 hplink
->sgot
->contents
);
4214 /* The second entry is reserved for use by the dynamic linker. */
4215 memset (hplink
->sgot
->contents
+ GOT_ENTRY_SIZE
, 0, GOT_ENTRY_SIZE
);
4217 /* Set .got entry size. */
4218 elf_section_data (hplink
->sgot
->output_section
)
4219 ->this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
4222 if (hplink
->splt
->_raw_size
!= 0)
4224 /* Set plt entry size. */
4225 elf_section_data (hplink
->splt
->output_section
)
4226 ->this_hdr
.sh_entsize
= PLT_ENTRY_SIZE
;
4228 if (hplink
->need_plt_stub
)
4230 /* Set up the .plt stub. */
4231 memcpy (hplink
->splt
->contents
4232 + hplink
->splt
->_raw_size
- sizeof (plt_stub
),
4233 plt_stub
, sizeof (plt_stub
));
4235 if ((hplink
->splt
->output_offset
4236 + hplink
->splt
->output_section
->vma
4237 + hplink
->splt
->_raw_size
)
4238 != (hplink
->sgot
->output_offset
4239 + hplink
->sgot
->output_section
->vma
))
4241 (*_bfd_error_handler
)
4242 (_(".got section not immediately after .plt section"));
4251 /* Tweak the OSABI field of the elf header. */
4254 elf32_hppa_post_process_headers (abfd
, link_info
)
4256 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
;
4258 Elf_Internal_Ehdr
* i_ehdrp
;
4260 i_ehdrp
= elf_elfheader (abfd
);
4262 if (strcmp (bfd_get_target (abfd
), "elf32-hppa-linux") == 0)
4264 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_LINUX
;
4268 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_HPUX
;
4272 /* Called when writing out an object file to decide the type of a
4275 elf32_hppa_elf_get_symbol_type (elf_sym
, type
)
4276 Elf_Internal_Sym
*elf_sym
;
4279 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_PARISC_MILLI
)
4280 return STT_PARISC_MILLI
;
4285 /* Misc BFD support code. */
4286 #define bfd_elf32_bfd_is_local_label_name elf_hppa_is_local_label_name
4287 #define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
4288 #define elf_info_to_howto elf_hppa_info_to_howto
4289 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
4291 /* Stuff for the BFD linker. */
4292 #define bfd_elf32_bfd_final_link elf32_hppa_final_link
4293 #define bfd_elf32_bfd_link_hash_table_create elf32_hppa_link_hash_table_create
4294 #define elf_backend_add_symbol_hook elf32_hppa_add_symbol_hook
4295 #define elf_backend_adjust_dynamic_symbol elf32_hppa_adjust_dynamic_symbol
4296 #define elf_backend_check_relocs elf32_hppa_check_relocs
4297 #define elf_backend_create_dynamic_sections elf32_hppa_create_dynamic_sections
4298 #define elf_backend_fake_sections elf_hppa_fake_sections
4299 #define elf_backend_relocate_section elf32_hppa_relocate_section
4300 #define elf_backend_hide_symbol elf32_hppa_hide_symbol
4301 #define elf_backend_finish_dynamic_symbol elf32_hppa_finish_dynamic_symbol
4302 #define elf_backend_finish_dynamic_sections elf32_hppa_finish_dynamic_sections
4303 #define elf_backend_size_dynamic_sections elf32_hppa_size_dynamic_sections
4304 #define elf_backend_gc_mark_hook elf32_hppa_gc_mark_hook
4305 #define elf_backend_gc_sweep_hook elf32_hppa_gc_sweep_hook
4306 #define elf_backend_object_p elf32_hppa_object_p
4307 #define elf_backend_final_write_processing elf_hppa_final_write_processing
4308 #define elf_backend_post_process_headers elf32_hppa_post_process_headers
4309 #define elf_backend_get_symbol_type elf32_hppa_elf_get_symbol_type
4311 #define elf_backend_can_gc_sections 1
4312 #define elf_backend_plt_alignment 2
4313 #define elf_backend_want_got_plt 0
4314 #define elf_backend_plt_readonly 0
4315 #define elf_backend_want_plt_sym 0
4316 #define elf_backend_got_header_size 8
4318 #define TARGET_BIG_SYM bfd_elf32_hppa_vec
4319 #define TARGET_BIG_NAME "elf32-hppa"
4320 #define ELF_ARCH bfd_arch_hppa
4321 #define ELF_MACHINE_CODE EM_PARISC
4322 #define ELF_MAXPAGESIZE 0x1000
4324 #include "elf32-target.h"
4326 #undef TARGET_BIG_SYM
4327 #define TARGET_BIG_SYM bfd_elf32_hppa_linux_vec
4328 #undef TARGET_BIG_NAME
4329 #define TARGET_BIG_NAME "elf32-hppa-linux"
4331 #define INCLUDED_TARGET_FILE 1
4332 #include "elf32-target.h"