1 /* BFD back-end for HP PA-RISC ELF files.
2 Copyright 1990, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001
3 Free Software Foundation, Inc.
6 Center for Software Science
7 Department of Computer Science
9 Largely rewritten by Alan Modra <alan@linuxcare.com.au>
11 This file is part of BFD, the Binary File Descriptor library.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
33 #include "elf32-hppa.h"
36 #include "elf32-hppa.h"
38 /* In order to gain some understanding of code in this file without
39 knowing all the intricate details of the linker, note the
42 Functions named elf32_hppa_* are called by external routines, other
43 functions are only called locally. elf32_hppa_* functions appear
44 in this file more or less in the order in which they are called
45 from external routines. eg. elf32_hppa_check_relocs is called
46 early in the link process, elf32_hppa_finish_dynamic_sections is
47 one of the last functions. */
49 /* We use two hash tables to hold information for linking PA ELF objects.
51 The first is the elf32_hppa_link_hash_table which is derived
52 from the standard ELF linker hash table. We use this as a place to
53 attach other hash tables and static information.
55 The second is the stub hash table which is derived from the
56 base BFD hash table. The stub hash table holds the information
57 necessary to build the linker stubs during a link.
59 There are a number of different stubs generated by the linker.
67 : addil L'X - ($PIC_pcrel$0 - 4),%r1
68 : be,n R'X - ($PIC_pcrel$0 - 8)(%sr4,%r1)
70 Import stub to call shared library routine from normal object file
71 (single sub-space version)
72 : addil L'lt_ptr+ltoff,%dp ; get procedure entry point
73 : ldw R'lt_ptr+ltoff(%r1),%r21
75 : ldw R'lt_ptr+ltoff+4(%r1),%r19 ; get new dlt value.
77 Import stub to call shared library routine from shared library
78 (single sub-space version)
79 : addil L'ltoff,%r19 ; get procedure entry point
80 : ldw R'ltoff(%r1),%r21
82 : ldw R'ltoff+4(%r1),%r19 ; get new dlt value.
84 Import stub to call shared library routine from normal object file
85 (multiple sub-space support)
86 : addil L'lt_ptr+ltoff,%dp ; get procedure entry point
87 : ldw R'lt_ptr+ltoff(%r1),%r21
88 : ldw R'lt_ptr+ltoff+4(%r1),%r19 ; get new dlt value.
91 : be 0(%sr0,%r21) ; branch to target
92 : stw %rp,-24(%sp) ; save rp
94 Import stub to call shared library routine from shared library
95 (multiple sub-space support)
96 : addil L'ltoff,%r19 ; get procedure entry point
97 : ldw R'ltoff(%r1),%r21
98 : ldw R'ltoff+4(%r1),%r19 ; get new dlt value.
101 : be 0(%sr0,%r21) ; branch to target
102 : stw %rp,-24(%sp) ; save rp
104 Export stub to return from shared lib routine (multiple sub-space support)
105 One of these is created for each exported procedure in a shared
106 library (and stored in the shared lib). Shared lib routines are
107 called via the first instruction in the export stub so that we can
108 do an inter-space return. Not required for single sub-space.
109 : bl,n X,%rp ; trap the return
111 : ldw -24(%sp),%rp ; restore the original rp
114 : be,n 0(%sr0,%rp) ; inter-space return */
116 #define PLT_ENTRY_SIZE 8
117 #define PLABEL_PLT_ENTRY_SIZE PLT_ENTRY_SIZE
118 #define GOT_ENTRY_SIZE 4
119 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
121 static const bfd_byte plt_stub
[] =
123 0x0e, 0x80, 0x10, 0x96, /* 1: ldw 0(%r20),%r22 */
124 0xea, 0xc0, 0xc0, 0x00, /* bv %r0(%r22) */
125 0x0e, 0x88, 0x10, 0x95, /* ldw 4(%r20),%r21 */
126 #define PLT_STUB_ENTRY (3*4)
127 0xea, 0x9f, 0x1f, 0xdd, /* b,l 1b,%r20 */
128 0xd6, 0x80, 0x1c, 0x1e, /* depi 0,31,2,%r20 */
129 0x00, 0xc0, 0xff, 0xee, /* 9: .word fixup_func */
130 0xde, 0xad, 0xbe, 0xef /* .word fixup_ltp */
133 /* Section name for stubs is the associated section name plus this
135 #define STUB_SUFFIX ".stub"
137 /* Setting the following non-zero makes all long branch stubs
138 generated during a shared link of the PIC variety. This saves on
139 relocs, but costs one extra instruction per stub. */
140 #ifndef LONG_BRANCH_PIC_IN_SHLIB
141 #define LONG_BRANCH_PIC_IN_SHLIB 1
144 /* Set this non-zero to use import stubs instead of long branch stubs
145 where a .plt entry exists for the symbol. This is a fairly useless
146 option as import stubs are bigger than PIC long branch stubs. */
147 #ifndef LONG_BRANCH_VIA_PLT
148 #define LONG_BRANCH_VIA_PLT 0
151 /* We don't need to copy any PC- or GP-relative dynamic relocs into a
152 shared object's dynamic section. */
153 #ifndef RELATIVE_DYNAMIC_RELOCS
154 #define RELATIVE_DYNAMIC_RELOCS 0
157 enum elf32_hppa_stub_type
{
158 hppa_stub_long_branch
,
159 hppa_stub_long_branch_shared
,
161 hppa_stub_import_shared
,
166 struct elf32_hppa_stub_hash_entry
{
168 /* Base hash table entry structure. */
169 struct bfd_hash_entry root
;
171 /* The stub section. */
174 #if ! LONG_BRANCH_PIC_IN_SHLIB
175 /* It's associated reloc section. */
179 /* Offset within stub_sec of the beginning of this stub. */
182 /* Given the symbol's value and its section we can determine its final
183 value when building the stubs (so the stub knows where to jump. */
184 bfd_vma target_value
;
185 asection
*target_section
;
187 enum elf32_hppa_stub_type stub_type
;
189 /* The symbol table entry, if any, that this was derived from. */
190 struct elf32_hppa_link_hash_entry
*h
;
192 /* Where this stub is being called from, or, in the case of combined
193 stub sections, the first input section in the group. */
197 struct elf32_hppa_link_hash_entry
{
199 struct elf_link_hash_entry elf
;
201 /* A pointer to the most recently used stub hash entry against this
203 struct elf32_hppa_stub_hash_entry
*stub_cache
;
205 #if ! LONG_BRANCH_PIC_IN_SHLIB
206 /* Used to track whether we have allocated space for a long branch
207 stub relocation for this symbol in the given section. */
208 asection
*stub_reloc_sec
;
211 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
212 /* Used to count relocations for delayed sizing of relocation
214 struct elf32_hppa_dyn_reloc_entry
{
216 /* Next relocation in the chain. */
217 struct elf32_hppa_dyn_reloc_entry
*next
;
219 /* The section in dynobj. */
222 /* Number of relocs copied in this section. */
227 /* Set during a static link if we detect a function is PIC. */
228 unsigned int pic_call
:1;
230 /* Set if this symbol is used by a plabel reloc. */
231 unsigned int plabel
:1;
233 /* Set if this symbol is an init or fini function and thus should
234 use an absolute reloc. */
235 unsigned int plt_abs
:1;
238 struct elf32_hppa_link_hash_table
{
240 /* The main hash table. */
241 struct elf_link_hash_table root
;
243 /* The stub hash table. */
244 struct bfd_hash_table stub_hash_table
;
246 /* Linker stub bfd. */
249 /* Linker call-backs. */
250 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
251 void (*layout_sections_again
) PARAMS ((void));
253 /* Array to keep track of which stub sections have been created, and
254 information on stub grouping. */
256 /* This is the section to which stubs in the group will be
259 /* The stub section. */
261 #if ! LONG_BRANCH_PIC_IN_SHLIB
262 /* The stub section's reloc section. */
267 /* Short-cuts to get to dynamic linker sections. */
275 /* 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 L'XXX,%r1,%r1 */
785 #define DEPI_R1 0xd4201c1e /* depi 0,31,2,%r1 */
787 #define ADDIL_DP 0x2b600000 /* addil L'XXX,%dp,%r1 */
788 #define LDW_R1_R21 0x48350000 /* ldw R'XXX(%sr0,%r1),%r21 */
789 #define BV_R0_R21 0xeaa0c000 /* bv %r0(%r21) */
790 #define LDW_R1_R19 0x48330000 /* ldw R'XXX(%sr0,%r1),%r19 */
792 #define ADDIL_R19 0x2a600000 /* addil L'XXX,%r19,%r1 */
793 #define LDW_R1_DP 0x483b0000 /* ldw R'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);
3027 if (h
!= NULL
&& h
->root
.type
== bfd_link_hash_defined
)
3029 gp_val
= h
->root
.u
.def
.value
;
3030 sec
= h
->root
.u
.def
.section
;
3034 /* Choose to point our LTP at, in this order, one of .plt, .got,
3035 or .data, if these sections exist. In the case of choosing
3036 .plt try to make the LTP ideal for addressing anywhere in the
3037 .plt or .got with a 14 bit signed offset. Typically, the end
3038 of the .plt is the start of the .got, so choose .plt + 0x2000
3039 if either the .plt or .got is larger than 0x2000. If both
3040 the .plt and .got are smaller than 0x2000, choose the end of
3041 the .plt section. */
3046 gp_val
= sec
->_raw_size
;
3048 || (hplink
->sgot
&& hplink
->sgot
->_raw_size
> 0x2000))
3059 /* We know we don't have a .plt. If .got is large,
3061 if (sec
->_raw_size
> 0x2000)
3066 /* No .plt or .got. Who cares what the LTP is? */
3067 sec
= bfd_get_section_by_name (abfd
, ".data");
3073 gp_val
+= sec
->output_section
->vma
+ sec
->output_offset
;
3075 elf_gp (abfd
) = gp_val
;
3079 /* Build all the stubs associated with the current output file. The
3080 stubs are kept in a hash table attached to the main linker hash
3081 table. We also set up the .plt entries for statically linked PIC
3082 functions here. This function is called via hppaelf_finish in the
3086 elf32_hppa_build_stubs (info
)
3087 struct bfd_link_info
*info
;
3090 struct bfd_hash_table
*table
;
3091 struct elf32_hppa_link_hash_table
*hplink
;
3093 hplink
= hppa_link_hash_table (info
);
3095 for (stub_sec
= hplink
->stub_bfd
->sections
;
3097 stub_sec
= stub_sec
->next
)
3101 /* Allocate memory to hold the linker stubs. */
3102 size
= stub_sec
->_raw_size
;
3103 stub_sec
->contents
= (unsigned char *) bfd_zalloc (hplink
->stub_bfd
,
3105 if (stub_sec
->contents
== NULL
&& size
!= 0)
3107 stub_sec
->_raw_size
= 0;
3110 /* Build the stubs as directed by the stub hash table. */
3111 table
= &hplink
->stub_hash_table
;
3112 bfd_hash_traverse (table
, hppa_build_one_stub
, info
);
3117 /* Perform a final link. */
3120 elf32_hppa_final_link (abfd
, info
)
3122 struct bfd_link_info
*info
;
3126 /* Invoke the regular ELF garbage collecting linker to do all the
3128 if (!_bfd_elf32_gc_common_final_link (abfd
, info
))
3131 /* If we're producing a final executable, sort the contents of the
3132 unwind section. Magic section names, but this is much safer than
3133 having elf32_hppa_relocate_section remember where SEGREL32 relocs
3134 occurred. Consider what happens if someone inept creates a
3135 linker script that puts unwind information in .text. */
3136 s
= bfd_get_section_by_name (abfd
, ".PARISC.unwind");
3142 size
= s
->_raw_size
;
3143 contents
= bfd_malloc (size
);
3144 if (contents
== NULL
)
3147 if (! bfd_get_section_contents (abfd
, s
, contents
, (file_ptr
) 0, size
))
3150 qsort (contents
, size
/ 16, 16, hppa_unwind_entry_compare
);
3152 if (! bfd_set_section_contents (abfd
, s
, contents
, (file_ptr
) 0, size
))
3158 /* Record the lowest address for the data and text segments. */
3161 hppa_record_segment_addr (abfd
, section
, data
)
3162 bfd
*abfd ATTRIBUTE_UNUSED
;
3166 struct elf32_hppa_link_hash_table
*hplink
;
3168 hplink
= (struct elf32_hppa_link_hash_table
*) data
;
3170 if ((section
->flags
& (SEC_ALLOC
| SEC_LOAD
)) == (SEC_ALLOC
| SEC_LOAD
))
3172 bfd_vma value
= section
->vma
- section
->filepos
;
3174 if ((section
->flags
& SEC_READONLY
) != 0)
3176 if (value
< hplink
->text_segment_base
)
3177 hplink
->text_segment_base
= value
;
3181 if (value
< hplink
->data_segment_base
)
3182 hplink
->data_segment_base
= value
;
3187 /* Perform a relocation as part of a final link. */
3189 static bfd_reloc_status_type
3190 final_link_relocate (input_section
, contents
, rel
, value
, hplink
, sym_sec
, h
)
3191 asection
*input_section
;
3193 const Elf_Internal_Rela
*rel
;
3195 struct elf32_hppa_link_hash_table
*hplink
;
3197 struct elf32_hppa_link_hash_entry
*h
;
3200 unsigned int r_type
= ELF32_R_TYPE (rel
->r_info
);
3201 reloc_howto_type
*howto
= elf_hppa_howto_table
+ r_type
;
3202 int r_format
= howto
->bitsize
;
3203 enum hppa_reloc_field_selector_type_alt r_field
;
3204 bfd
*input_bfd
= input_section
->owner
;
3205 bfd_vma offset
= rel
->r_offset
;
3206 bfd_vma max_branch_offset
= 0;
3207 bfd_byte
*hit_data
= contents
+ offset
;
3208 bfd_signed_vma addend
= rel
->r_addend
;
3210 struct elf32_hppa_stub_hash_entry
*stub_entry
= NULL
;
3213 if (r_type
== R_PARISC_NONE
)
3214 return bfd_reloc_ok
;
3216 insn
= bfd_get_32 (input_bfd
, hit_data
);
3218 /* Find out where we are and where we're going. */
3219 location
= (offset
+
3220 input_section
->output_offset
+
3221 input_section
->output_section
->vma
);
3225 case R_PARISC_PCREL12F
:
3226 case R_PARISC_PCREL17F
:
3227 case R_PARISC_PCREL22F
:
3228 /* If this is a call to a function defined in another dynamic
3229 library, or if it is a call to a PIC function in the same
3230 object, or if this is a shared link and it is a call to a
3231 weak symbol which may or may not be in the same object, then
3232 find the import stub in the stub hash. */
3234 || sym_sec
->output_section
== NULL
3237 || (h
->elf
.root
.type
== bfd_link_hash_defweak
3238 && h
->elf
.dynindx
!= -1
3239 && h
->elf
.plt
.offset
!= (bfd_vma
) -1))))
3241 stub_entry
= hppa_get_stub_entry (input_section
, sym_sec
,
3243 if (stub_entry
!= NULL
)
3245 value
= (stub_entry
->stub_offset
3246 + stub_entry
->stub_sec
->output_offset
3247 + stub_entry
->stub_sec
->output_section
->vma
);
3250 else if (sym_sec
== NULL
&& h
!= NULL
3251 && h
->elf
.root
.type
== bfd_link_hash_undefweak
)
3253 /* It's OK if undefined weak. Make undefined weak
3254 branches go nowhere. */
3259 return bfd_reloc_notsupported
;
3263 case R_PARISC_PCREL21L
:
3264 case R_PARISC_PCREL17C
:
3265 case R_PARISC_PCREL17R
:
3266 case R_PARISC_PCREL14R
:
3267 case R_PARISC_PCREL14F
:
3268 /* Make it a pc relative offset. */
3273 case R_PARISC_DPREL21L
:
3274 case R_PARISC_DPREL14R
:
3275 case R_PARISC_DPREL14F
:
3276 /* For all the DP relative relocations, we need to examine the symbol's
3277 section. If it's a code section, then "data pointer relative" makes
3278 no sense. In that case we don't adjust the "value", and for 21 bit
3279 addil instructions, we change the source addend register from %dp to
3280 %r0. This situation commonly arises when a variable's "constness"
3281 is declared differently from the way the variable is defined. For
3282 instance: "extern int foo" with foo defined as "const int foo". */
3283 if (sym_sec
== NULL
)
3285 if ((sym_sec
->flags
& SEC_CODE
) != 0)
3287 if ((insn
& ((0x3f << 26) | (0x1f << 21)))
3288 == (((int) OP_ADDIL
<< 26) | (27 << 21)))
3290 insn
&= ~ (0x1f << 21);
3291 #if 1 /* debug them. */
3292 (*_bfd_error_handler
)
3293 (_("%s(%s+0x%lx): fixing %s"),
3294 bfd_get_filename (input_bfd
),
3295 input_section
->name
,
3296 (long) rel
->r_offset
,
3300 /* Now try to make things easy for the dynamic linker. */
3306 case R_PARISC_DLTIND21L
:
3307 case R_PARISC_DLTIND14R
:
3308 case R_PARISC_DLTIND14F
:
3309 value
-= elf_gp (input_section
->output_section
->owner
);
3312 case R_PARISC_SEGREL32
:
3313 if ((sym_sec
->flags
& SEC_CODE
) != 0)
3314 value
-= hplink
->text_segment_base
;
3316 value
-= hplink
->data_segment_base
;
3325 case R_PARISC_DIR32
:
3326 case R_PARISC_DIR14F
:
3327 case R_PARISC_DIR17F
:
3328 case R_PARISC_PCREL17C
:
3329 case R_PARISC_PCREL14F
:
3330 case R_PARISC_DPREL14F
:
3331 case R_PARISC_PLABEL32
:
3332 case R_PARISC_DLTIND14F
:
3333 case R_PARISC_SEGBASE
:
3334 case R_PARISC_SEGREL32
:
3338 case R_PARISC_DIR21L
:
3339 case R_PARISC_PCREL21L
:
3340 case R_PARISC_DPREL21L
:
3341 case R_PARISC_PLABEL21L
:
3342 case R_PARISC_DLTIND21L
:
3346 case R_PARISC_DIR17R
:
3347 case R_PARISC_PCREL17R
:
3348 case R_PARISC_DIR14R
:
3349 case R_PARISC_PCREL14R
:
3350 case R_PARISC_DPREL14R
:
3351 case R_PARISC_PLABEL14R
:
3352 case R_PARISC_DLTIND14R
:
3356 case R_PARISC_PCREL12F
:
3357 case R_PARISC_PCREL17F
:
3358 case R_PARISC_PCREL22F
:
3361 if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
3363 max_branch_offset
= (1 << (17-1)) << 2;
3365 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
3367 max_branch_offset
= (1 << (12-1)) << 2;
3371 max_branch_offset
= (1 << (22-1)) << 2;
3374 /* sym_sec is NULL on undefined weak syms or when shared on
3375 undefined syms. We've already checked for a stub for the
3376 shared undefined case. */
3377 if (sym_sec
== NULL
)
3380 /* If the branch is out of reach, then redirect the
3381 call to the local stub for this function. */
3382 if (value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3384 stub_entry
= hppa_get_stub_entry (input_section
, sym_sec
,
3386 if (stub_entry
== NULL
)
3387 return bfd_reloc_notsupported
;
3389 /* Munge up the value and addend so that we call the stub
3390 rather than the procedure directly. */
3391 value
= (stub_entry
->stub_offset
3392 + stub_entry
->stub_sec
->output_offset
3393 + stub_entry
->stub_sec
->output_section
->vma
3399 /* Something we don't know how to handle. */
3401 return bfd_reloc_notsupported
;
3404 /* Make sure we can reach the stub. */
3405 if (max_branch_offset
!= 0
3406 && value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3408 (*_bfd_error_handler
)
3409 (_("%s(%s+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
3410 bfd_get_filename (input_bfd
),
3411 input_section
->name
,
3412 (long) rel
->r_offset
,
3413 stub_entry
->root
.string
);
3414 return bfd_reloc_notsupported
;
3417 val
= hppa_field_adjust (value
, addend
, r_field
);
3421 case R_PARISC_PCREL12F
:
3422 case R_PARISC_PCREL17C
:
3423 case R_PARISC_PCREL17F
:
3424 case R_PARISC_PCREL17R
:
3425 case R_PARISC_PCREL22F
:
3426 case R_PARISC_DIR17F
:
3427 case R_PARISC_DIR17R
:
3428 /* This is a branch. Divide the offset by four.
3429 Note that we need to decide whether it's a branch or
3430 otherwise by inspecting the reloc. Inspecting insn won't
3431 work as insn might be from a .word directive. */
3439 insn
= hppa_rebuild_insn (insn
, val
, r_format
);
3441 /* Update the instruction word. */
3442 bfd_put_32 (input_bfd
, (bfd_vma
) insn
, hit_data
);
3443 return bfd_reloc_ok
;
3446 /* Relocate an HPPA ELF section. */
3449 elf32_hppa_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
3450 contents
, relocs
, local_syms
, local_sections
)
3452 struct bfd_link_info
*info
;
3454 asection
*input_section
;
3456 Elf_Internal_Rela
*relocs
;
3457 Elf_Internal_Sym
*local_syms
;
3458 asection
**local_sections
;
3461 bfd_vma
*local_got_offsets
;
3462 struct elf32_hppa_link_hash_table
*hplink
;
3463 Elf_Internal_Shdr
*symtab_hdr
;
3464 Elf_Internal_Rela
*rel
;
3465 Elf_Internal_Rela
*relend
;
3468 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3470 hplink
= hppa_link_hash_table (info
);
3471 dynobj
= hplink
->root
.dynobj
;
3472 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3476 relend
= relocs
+ input_section
->reloc_count
;
3477 for (; rel
< relend
; rel
++)
3479 unsigned int r_type
;
3480 reloc_howto_type
*howto
;
3481 unsigned int r_symndx
;
3482 struct elf32_hppa_link_hash_entry
*h
;
3483 Elf_Internal_Sym
*sym
;
3486 bfd_reloc_status_type r
;
3487 const char *sym_name
;
3490 r_type
= ELF32_R_TYPE (rel
->r_info
);
3491 if (r_type
>= (unsigned int) R_PARISC_UNIMPLEMENTED
)
3493 bfd_set_error (bfd_error_bad_value
);
3496 if (r_type
== (unsigned int) R_PARISC_GNU_VTENTRY
3497 || r_type
== (unsigned int) R_PARISC_GNU_VTINHERIT
)
3500 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3502 if (info
->relocateable
)
3504 /* This is a relocateable link. We don't have to change
3505 anything, unless the reloc is against a section symbol,
3506 in which case we have to adjust according to where the
3507 section symbol winds up in the output section. */
3508 if (r_symndx
< symtab_hdr
->sh_info
)
3510 sym
= local_syms
+ r_symndx
;
3511 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
3513 sym_sec
= local_sections
[r_symndx
];
3514 rel
->r_addend
+= sym_sec
->output_offset
;
3520 /* This is a final link. */
3524 if (r_symndx
< symtab_hdr
->sh_info
)
3526 /* This is a local symbol, h defaults to NULL. */
3527 sym
= local_syms
+ r_symndx
;
3528 sym_sec
= local_sections
[r_symndx
];
3529 relocation
= ((ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
3530 ? 0 : sym
->st_value
)
3531 + sym_sec
->output_offset
3532 + sym_sec
->output_section
->vma
);
3538 /* It's a global; Find its entry in the link hash. */
3539 indx
= r_symndx
- symtab_hdr
->sh_info
;
3540 h
= ((struct elf32_hppa_link_hash_entry
*)
3541 elf_sym_hashes (input_bfd
)[indx
]);
3542 while (h
->elf
.root
.type
== bfd_link_hash_indirect
3543 || h
->elf
.root
.type
== bfd_link_hash_warning
)
3544 h
= (struct elf32_hppa_link_hash_entry
*) h
->elf
.root
.u
.i
.link
;
3547 if (h
->elf
.root
.type
== bfd_link_hash_defined
3548 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
3550 sym_sec
= h
->elf
.root
.u
.def
.section
;
3551 /* If sym_sec->output_section is NULL, then it's a
3552 symbol defined in a shared library. */
3553 if (sym_sec
->output_section
!= NULL
)
3554 relocation
= (h
->elf
.root
.u
.def
.value
3555 + sym_sec
->output_offset
3556 + sym_sec
->output_section
->vma
);
3558 else if (h
->elf
.root
.type
== bfd_link_hash_undefweak
)
3560 else if (info
->shared
&& !info
->no_undefined
3561 && ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
)
3564 if (!((*info
->callbacks
->undefined_symbol
)
3565 (info
, h
->elf
.root
.root
.string
, input_bfd
,
3566 input_section
, rel
->r_offset
, false)))
3571 if (!((*info
->callbacks
->undefined_symbol
)
3572 (info
, h
->elf
.root
.root
.string
, input_bfd
,
3573 input_section
, rel
->r_offset
, true)))
3578 /* Do any required modifications to the relocation value, and
3579 determine what types of dynamic info we need to output, if
3584 case R_PARISC_DLTIND14F
:
3585 case R_PARISC_DLTIND14R
:
3586 case R_PARISC_DLTIND21L
:
3587 /* Relocation is to the entry for this symbol in the global
3593 off
= h
->elf
.got
.offset
;
3594 BFD_ASSERT (off
!= (bfd_vma
) -1);
3596 if (! hplink
->root
.dynamic_sections_created
3598 && (info
->symbolic
|| h
->elf
.dynindx
== -1)
3599 && (h
->elf
.elf_link_hash_flags
3600 & ELF_LINK_HASH_DEF_REGULAR
) != 0))
3602 /* This is actually a static link, or it is a
3603 -Bsymbolic link and the symbol is defined
3604 locally, or the symbol was forced to be local
3605 because of a version file. We must initialize
3606 this entry in the global offset table. Since the
3607 offset must always be a multiple of 4, we use the
3608 least significant bit to record whether we have
3609 initialized it already.
3611 When doing a dynamic link, we create a .rela.got
3612 relocation entry to initialize the value. This
3613 is done in the finish_dynamic_symbol routine. */
3618 bfd_put_32 (output_bfd
, relocation
,
3619 hplink
->sgot
->contents
+ off
);
3620 h
->elf
.got
.offset
|= 1;
3628 /* Local symbol case. */
3631 BFD_ASSERT (local_got_offsets
!= NULL
3632 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
3634 off
= local_got_offsets
[r_symndx
];
3636 /* The offset must always be a multiple of 4. We use
3637 the least significant bit to record whether we have
3638 already generated the necessary reloc. */
3643 bfd_put_32 (output_bfd
, relocation
,
3644 hplink
->sgot
->contents
+ off
);
3648 /* Output a dynamic *ABS* relocation for this
3649 GOT entry. In this case it is relative to
3650 the base of the object because the symbol
3652 Elf_Internal_Rela outrel
;
3653 asection
*srelgot
= hplink
->srelgot
;
3655 outrel
.r_offset
= (off
3656 + hplink
->sgot
->output_offset
3657 + hplink
->sgot
->output_section
->vma
);
3658 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_DIR32
);
3659 outrel
.r_addend
= relocation
;
3660 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3661 ((Elf32_External_Rela
*)
3663 + srelgot
->reloc_count
));
3664 ++srelgot
->reloc_count
;
3667 local_got_offsets
[r_symndx
] |= 1;
3673 /* Add the base of the GOT to the relocation value. */
3674 relocation
+= (hplink
->sgot
->output_offset
3675 + hplink
->sgot
->output_section
->vma
);
3678 case R_PARISC_SEGREL32
:
3679 /* If this is the first SEGREL relocation, then initialize
3680 the segment base values. */
3681 if (hplink
->text_segment_base
== (bfd_vma
) -1)
3682 bfd_map_over_sections (output_bfd
,
3683 hppa_record_segment_addr
,
3687 case R_PARISC_PLABEL14R
:
3688 case R_PARISC_PLABEL21L
:
3689 case R_PARISC_PLABEL32
:
3690 if (hplink
->root
.dynamic_sections_created
)
3694 /* If we have a global symbol with a PLT slot, then
3695 redirect this relocation to it. */
3698 off
= h
->elf
.plt
.offset
;
3704 indx
= r_symndx
+ symtab_hdr
->sh_info
;
3705 off
= local_got_offsets
[indx
];
3707 /* As for the local .got entry case, we use the last
3708 bit to record whether we've already initialised
3709 this local .plt entry. */
3714 bfd_put_32 (output_bfd
,
3716 hplink
->splt
->contents
+ off
);
3717 bfd_put_32 (output_bfd
,
3718 elf_gp (hplink
->splt
->output_section
->owner
),
3719 hplink
->splt
->contents
+ off
+ 4);
3723 /* Output a dynamic IPLT relocation for this
3725 Elf_Internal_Rela outrel
;
3726 asection
*srelplt
= hplink
->srelplt
;
3728 outrel
.r_offset
= (off
3729 + hplink
->splt
->output_offset
3730 + hplink
->splt
->output_section
->vma
);
3731 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_IPLT
);
3732 outrel
.r_addend
= relocation
;
3733 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3734 ((Elf32_External_Rela
*)
3736 + srelplt
->reloc_count
));
3737 ++srelplt
->reloc_count
;
3740 local_got_offsets
[indx
] |= 1;
3744 BFD_ASSERT (off
< (bfd_vma
) -2);
3746 /* PLABELs contain function pointers. Relocation is to
3747 the entry for the function in the .plt. The magic +2
3748 offset signals to $$dyncall that the function pointer
3749 is in the .plt and thus has a gp pointer too.
3750 Exception: Undefined PLABELs should have a value of
3753 || (h
->elf
.root
.type
!= bfd_link_hash_undefweak
3754 && h
->elf
.root
.type
!= bfd_link_hash_undefined
))
3757 + hplink
->splt
->output_offset
3758 + hplink
->splt
->output_section
->vma
3763 /* Fall through and possibly emit a dynamic relocation. */
3765 case R_PARISC_DIR17F
:
3766 case R_PARISC_DIR17R
:
3767 case R_PARISC_DIR14F
:
3768 case R_PARISC_DIR14R
:
3769 case R_PARISC_DIR21L
:
3770 case R_PARISC_DPREL14F
:
3771 case R_PARISC_DPREL14R
:
3772 case R_PARISC_DPREL21L
:
3773 case R_PARISC_DIR32
:
3774 /* The reloc types handled here and this conditional
3775 expression must match the code in check_relocs and
3776 hppa_discard_copies. ie. We need exactly the same
3777 condition as in check_relocs, with some extra conditions
3778 (dynindx test in this case) to cater for relocs removed
3779 by hppa_discard_copies. */
3780 if ((input_section
->flags
& SEC_ALLOC
) != 0
3782 #if RELATIVE_DYNAMIC_RELOCS
3783 && (is_absolute_reloc (r_type
)
3784 || ((!info
->symbolic
3786 && ((h
->elf
.elf_link_hash_flags
3787 & ELF_LINK_HASH_DEF_REGULAR
) == 0
3788 || h
->elf
.root
.type
== bfd_link_hash_defweak
)))
3789 && (h
== NULL
|| h
->elf
.dynindx
!= -1)))
3793 Elf_Internal_Rela outrel
;
3796 /* When generating a shared object, these relocations
3797 are copied into the output file to be resolved at run
3804 name
= (bfd_elf_string_from_elf_section
3806 elf_elfheader (input_bfd
)->e_shstrndx
,
3807 elf_section_data (input_section
)->rel_hdr
.sh_name
));
3810 sreloc
= bfd_get_section_by_name (dynobj
, name
);
3811 BFD_ASSERT (sreloc
!= NULL
);
3814 outrel
.r_offset
= rel
->r_offset
;
3815 outrel
.r_addend
= rel
->r_addend
;
3817 if (elf_section_data (input_section
)->stab_info
!= NULL
)
3821 off
= (_bfd_stab_section_offset
3822 (output_bfd
, &hplink
->root
.stab_info
,
3824 &elf_section_data (input_section
)->stab_info
,
3826 if (off
== (bfd_vma
) -1)
3828 outrel
.r_offset
= off
;
3831 outrel
.r_offset
+= (input_section
->output_offset
3832 + input_section
->output_section
->vma
);
3836 memset (&outrel
, 0, sizeof (outrel
));
3839 && h
->elf
.dynindx
!= -1
3842 || (h
->elf
.elf_link_hash_flags
3843 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
3845 outrel
.r_info
= ELF32_R_INFO (h
->elf
.dynindx
, r_type
);
3847 else /* It's a local symbol, or one marked to become local. */
3851 /* Add the absolute offset of the symbol. */
3852 outrel
.r_addend
+= relocation
;
3854 /* Global plabels need to be processed by the
3855 dynamic linker so that functions have at most one
3856 fptr. For this reason, we need to differentiate
3857 between global and local plabels, which we do by
3858 providing the function symbol for a global plabel
3859 reloc, and no symbol for local plabels. */
3862 && sym_sec
->output_section
!= NULL
3863 && ! bfd_is_abs_section (sym_sec
))
3865 indx
= elf_section_data (sym_sec
->output_section
)->dynindx
;
3866 /* We are turning this relocation into one
3867 against a section symbol, so subtract out the
3868 output section's address but not the offset
3869 of the input section in the output section. */
3870 outrel
.r_addend
-= sym_sec
->output_section
->vma
;
3873 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
3876 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3877 ((Elf32_External_Rela
*)
3879 + sreloc
->reloc_count
));
3880 ++sreloc
->reloc_count
;
3888 r
= final_link_relocate (input_section
, contents
, rel
, relocation
,
3889 hplink
, sym_sec
, h
);
3891 if (r
== bfd_reloc_ok
)
3895 sym_name
= h
->elf
.root
.root
.string
;
3898 sym_name
= bfd_elf_string_from_elf_section (input_bfd
,
3899 symtab_hdr
->sh_link
,
3901 if (sym_name
== NULL
)
3903 if (*sym_name
== '\0')
3904 sym_name
= bfd_section_name (input_bfd
, sym_sec
);
3907 howto
= elf_hppa_howto_table
+ r_type
;
3909 if (r
== bfd_reloc_undefined
|| r
== bfd_reloc_notsupported
)
3911 (*_bfd_error_handler
)
3912 (_("%s(%s+0x%lx): cannot handle %s for %s"),
3913 bfd_get_filename (input_bfd
),
3914 input_section
->name
,
3915 (long) rel
->r_offset
,
3921 if (!((*info
->callbacks
->reloc_overflow
)
3922 (info
, sym_name
, howto
->name
, (bfd_vma
) 0,
3923 input_bfd
, input_section
, rel
->r_offset
)))
3931 /* Comparison function for qsort to sort unwind section during a
3935 hppa_unwind_entry_compare (a
, b
)
3939 const bfd_byte
*ap
, *bp
;
3940 unsigned long av
, bv
;
3942 ap
= (const bfd_byte
*) a
;
3943 av
= (unsigned long) ap
[0] << 24;
3944 av
|= (unsigned long) ap
[1] << 16;
3945 av
|= (unsigned long) ap
[2] << 8;
3946 av
|= (unsigned long) ap
[3];
3948 bp
= (const bfd_byte
*) b
;
3949 bv
= (unsigned long) bp
[0] << 24;
3950 bv
|= (unsigned long) bp
[1] << 16;
3951 bv
|= (unsigned long) bp
[2] << 8;
3952 bv
|= (unsigned long) bp
[3];
3954 return av
< bv
? -1 : av
> bv
? 1 : 0;
3957 /* Finish up dynamic symbol handling. We set the contents of various
3958 dynamic sections here. */
3961 elf32_hppa_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
3963 struct bfd_link_info
*info
;
3964 struct elf_link_hash_entry
*h
;
3965 Elf_Internal_Sym
*sym
;
3967 struct elf32_hppa_link_hash_table
*hplink
;
3970 hplink
= hppa_link_hash_table (info
);
3971 dynobj
= hplink
->root
.dynobj
;
3973 if (h
->plt
.offset
!= (bfd_vma
) -1)
3977 /* This symbol has an entry in the procedure linkage table. Set
3980 The format of a plt entry is
3985 if (h
->root
.type
== bfd_link_hash_defined
3986 || h
->root
.type
== bfd_link_hash_defweak
)
3988 value
= h
->root
.u
.def
.value
;
3989 if (h
->root
.u
.def
.section
->output_section
!= NULL
)
3990 value
+= (h
->root
.u
.def
.section
->output_offset
3991 + h
->root
.u
.def
.section
->output_section
->vma
);
3994 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
)
3996 Elf_Internal_Rela rel
;
3998 /* Create a dynamic IPLT relocation for this entry. */
3999 rel
.r_offset
= (h
->plt
.offset
4000 + hplink
->splt
->output_offset
4001 + hplink
->splt
->output_section
->vma
);
4002 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->plt_abs
4003 && h
->dynindx
!= -1)
4005 /* To support lazy linking, the function pointer is
4006 initialised to point to a special stub stored at the
4007 end of the .plt. This is only done for plt entries
4008 with a non-*ABS* dynamic relocation. */
4009 value
= (hplink
->splt
->output_offset
4010 + hplink
->splt
->output_section
->vma
4011 + hplink
->splt
->_raw_size
4014 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_IPLT
);
4019 /* This symbol has been marked to become local, and is
4020 used by a plabel so must be kept in the .plt. */
4021 rel
.r_info
= ELF32_R_INFO (0, R_PARISC_IPLT
);
4022 rel
.r_addend
= value
;
4025 bfd_elf32_swap_reloca_out (hplink
->splt
->output_section
->owner
,
4027 ((Elf32_External_Rela
*)
4028 hplink
->srelplt
->contents
4029 + hplink
->srelplt
->reloc_count
));
4030 hplink
->srelplt
->reloc_count
++;
4033 bfd_put_32 (hplink
->splt
->owner
,
4035 hplink
->splt
->contents
+ h
->plt
.offset
);
4036 bfd_put_32 (hplink
->splt
->owner
,
4037 elf_gp (hplink
->splt
->output_section
->owner
),
4038 hplink
->splt
->contents
+ h
->plt
.offset
+ 4);
4039 if (PLABEL_PLT_ENTRY_SIZE
!= PLT_ENTRY_SIZE
4040 && ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
4041 && h
->dynindx
!= -1)
4043 memset (hplink
->splt
->contents
+ h
->plt
.offset
+ 8,
4044 0, PLABEL_PLT_ENTRY_SIZE
- PLT_ENTRY_SIZE
);
4047 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4049 /* Mark the symbol as undefined, rather than as defined in
4050 the .plt section. Leave the value alone. */
4051 sym
->st_shndx
= SHN_UNDEF
;
4055 if (h
->got
.offset
!= (bfd_vma
) -1)
4057 Elf_Internal_Rela rel
;
4059 /* This symbol has an entry in the global offset table. Set it
4062 rel
.r_offset
= ((h
->got
.offset
&~ (bfd_vma
) 1)
4063 + hplink
->sgot
->output_offset
4064 + hplink
->sgot
->output_section
->vma
);
4066 /* If this is a static link, or it is a -Bsymbolic link and the
4067 symbol is defined locally or was forced to be local because
4068 of a version file, we just want to emit a RELATIVE reloc.
4069 The entry in the global offset table will already have been
4070 initialized in the relocate_section function. */
4071 if (! hplink
->root
.dynamic_sections_created
4073 && (info
->symbolic
|| h
->dynindx
== -1)
4074 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
4076 rel
.r_info
= ELF32_R_INFO (0, R_PARISC_DIR32
);
4077 rel
.r_addend
= (h
->root
.u
.def
.value
4078 + h
->root
.u
.def
.section
->output_offset
4079 + h
->root
.u
.def
.section
->output_section
->vma
);
4083 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4084 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
4085 hplink
->sgot
->contents
+ h
->got
.offset
);
4086 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_DIR32
);
4090 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
4091 ((Elf32_External_Rela
*)
4092 hplink
->srelgot
->contents
4093 + hplink
->srelgot
->reloc_count
));
4094 ++hplink
->srelgot
->reloc_count
;
4097 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
4100 Elf_Internal_Rela rel
;
4102 /* This symbol needs a copy reloc. Set it up. */
4104 BFD_ASSERT (h
->dynindx
!= -1
4105 && (h
->root
.type
== bfd_link_hash_defined
4106 || h
->root
.type
== bfd_link_hash_defweak
));
4108 s
= hplink
->srelbss
;
4110 rel
.r_offset
= (h
->root
.u
.def
.value
4111 + h
->root
.u
.def
.section
->output_offset
4112 + h
->root
.u
.def
.section
->output_section
->vma
);
4114 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_COPY
);
4115 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
4116 ((Elf32_External_Rela
*) s
->contents
4121 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
4122 if (h
->root
.root
.string
[0] == '_'
4123 && (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4124 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0))
4126 sym
->st_shndx
= SHN_ABS
;
4132 /* Finish up the dynamic sections. */
4135 elf32_hppa_finish_dynamic_sections (output_bfd
, info
)
4137 struct bfd_link_info
*info
;
4140 struct elf32_hppa_link_hash_table
*hplink
;
4143 hplink
= hppa_link_hash_table (info
);
4144 dynobj
= hplink
->root
.dynobj
;
4146 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4148 if (hplink
->root
.dynamic_sections_created
)
4150 Elf32_External_Dyn
*dyncon
, *dynconend
;
4152 BFD_ASSERT (sdyn
!= NULL
);
4154 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4155 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
4156 for (; dyncon
< dynconend
; dyncon
++)
4158 Elf_Internal_Dyn dyn
;
4161 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4169 /* Use PLTGOT to set the GOT register. */
4170 dyn
.d_un
.d_ptr
= elf_gp (output_bfd
);
4171 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4175 s
= hplink
->srelplt
;
4176 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4177 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4181 s
= hplink
->srelplt
;
4182 if (s
->_cooked_size
!= 0)
4183 dyn
.d_un
.d_val
= s
->_cooked_size
;
4185 dyn
.d_un
.d_val
= s
->_raw_size
;
4186 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4192 if (hplink
->sgot
->_raw_size
!= 0)
4194 /* Fill in the first entry in the global offset table.
4195 We use it to point to our dynamic section, if we have one. */
4196 bfd_put_32 (output_bfd
,
4198 ? sdyn
->output_section
->vma
+ sdyn
->output_offset
4200 hplink
->sgot
->contents
);
4202 /* The second entry is reserved for use by the dynamic linker. */
4203 memset (hplink
->sgot
->contents
+ GOT_ENTRY_SIZE
, 0, GOT_ENTRY_SIZE
);
4205 /* Set .got entry size. */
4206 elf_section_data (hplink
->sgot
->output_section
)
4207 ->this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
4210 if (hplink
->splt
->_raw_size
!= 0)
4212 /* Set plt entry size. */
4213 elf_section_data (hplink
->splt
->output_section
)
4214 ->this_hdr
.sh_entsize
= PLT_ENTRY_SIZE
;
4216 if (hplink
->need_plt_stub
)
4218 /* Set up the .plt stub. */
4219 memcpy (hplink
->splt
->contents
4220 + hplink
->splt
->_raw_size
- sizeof (plt_stub
),
4221 plt_stub
, sizeof (plt_stub
));
4223 if ((hplink
->splt
->output_offset
4224 + hplink
->splt
->output_section
->vma
4225 + hplink
->splt
->_raw_size
)
4226 != (hplink
->sgot
->output_offset
4227 + hplink
->sgot
->output_section
->vma
))
4229 (*_bfd_error_handler
)
4230 (_(".got section not immediately after .plt section"));
4239 /* Tweak the OSABI field of the elf header. */
4242 elf32_hppa_post_process_headers (abfd
, link_info
)
4244 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
;
4246 Elf_Internal_Ehdr
* i_ehdrp
;
4248 i_ehdrp
= elf_elfheader (abfd
);
4250 if (strcmp (bfd_get_target (abfd
), "elf32-hppa-linux") == 0)
4252 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_LINUX
;
4256 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_HPUX
;
4260 /* Called when writing out an object file to decide the type of a
4263 elf32_hppa_elf_get_symbol_type (elf_sym
, type
)
4264 Elf_Internal_Sym
*elf_sym
;
4267 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_PARISC_MILLI
)
4268 return STT_PARISC_MILLI
;
4273 /* Misc BFD support code. */
4274 #define bfd_elf32_bfd_is_local_label_name elf_hppa_is_local_label_name
4275 #define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
4276 #define elf_info_to_howto elf_hppa_info_to_howto
4277 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
4279 /* Stuff for the BFD linker. */
4280 #define bfd_elf32_bfd_final_link elf32_hppa_final_link
4281 #define bfd_elf32_bfd_link_hash_table_create elf32_hppa_link_hash_table_create
4282 #define elf_backend_add_symbol_hook elf32_hppa_add_symbol_hook
4283 #define elf_backend_adjust_dynamic_symbol elf32_hppa_adjust_dynamic_symbol
4284 #define elf_backend_check_relocs elf32_hppa_check_relocs
4285 #define elf_backend_create_dynamic_sections elf32_hppa_create_dynamic_sections
4286 #define elf_backend_fake_sections elf_hppa_fake_sections
4287 #define elf_backend_relocate_section elf32_hppa_relocate_section
4288 #define elf_backend_hide_symbol elf32_hppa_hide_symbol
4289 #define elf_backend_finish_dynamic_symbol elf32_hppa_finish_dynamic_symbol
4290 #define elf_backend_finish_dynamic_sections elf32_hppa_finish_dynamic_sections
4291 #define elf_backend_size_dynamic_sections elf32_hppa_size_dynamic_sections
4292 #define elf_backend_gc_mark_hook elf32_hppa_gc_mark_hook
4293 #define elf_backend_gc_sweep_hook elf32_hppa_gc_sweep_hook
4294 #define elf_backend_object_p elf32_hppa_object_p
4295 #define elf_backend_final_write_processing elf_hppa_final_write_processing
4296 #define elf_backend_post_process_headers elf32_hppa_post_process_headers
4297 #define elf_backend_get_symbol_type elf32_hppa_elf_get_symbol_type
4299 #define elf_backend_can_gc_sections 1
4300 #define elf_backend_plt_alignment 2
4301 #define elf_backend_want_got_plt 0
4302 #define elf_backend_plt_readonly 0
4303 #define elf_backend_want_plt_sym 0
4304 #define elf_backend_got_header_size 8
4306 #define TARGET_BIG_SYM bfd_elf32_hppa_vec
4307 #define TARGET_BIG_NAME "elf32-hppa"
4308 #define ELF_ARCH bfd_arch_hppa
4309 #define ELF_MACHINE_CODE EM_PARISC
4310 #define ELF_MAXPAGESIZE 0x1000
4312 #include "elf32-target.h"
4314 #undef TARGET_BIG_SYM
4315 #define TARGET_BIG_SYM bfd_elf32_hppa_linux_vec
4316 #undef TARGET_BIG_NAME
4317 #define TARGET_BIG_NAME "elf32-hppa-linux"
4319 #define INCLUDED_TARGET_FILE 1
4320 #include "elf32-target.h"