1 /* BFD back-end for HP PA-RISC ELF files.
2 Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000
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"
39 /* In order to gain some understanding of code in this file without
40 knowing all the intricate details of the linker, note the
43 Functions named elf32_hppa_* are called by external routines, other
44 functions are only called locally. elf32_hppa_* functions appear
45 in this file more or less in the order in which they are called
46 from external routines. eg. elf32_hppa_check_relocs is called
47 early in the link process, elf32_hppa_finish_dynamic_sections is
48 one of the last functions. */
51 /* We use two hash tables to hold information for linking PA ELF objects.
53 The first is the elf32_hppa_link_hash_table which is derived
54 from the standard ELF linker hash table. We use this as a place to
55 attach other hash tables and static information.
57 The second is the stub hash table which is derived from the
58 base BFD hash table. The stub hash table holds the information
59 necessary to build the linker stubs during a link.
61 There are a number of different stubs generated by the linker.
69 : addil L'X - ($PIC_pcrel$0 - 4),%r1
70 : be,n R'X - ($PIC_pcrel$0 - 8)(%sr4,%r1)
72 Import stub to call shared library routine from normal object file
73 (single sub-space version)
74 : addil L'lt_ptr+ltoff,%dp ; get procedure entry point
75 : ldw R'lt_ptr+ltoff(%r1),%r21
77 : ldw R'lt_ptr+ltoff+4(%r1),%r19 ; get new dlt value.
79 Import stub to call shared library routine from shared library
80 (single sub-space version)
81 : addil L'ltoff,%r19 ; get procedure entry point
82 : ldw R'ltoff(%r1),%r21
84 : ldw R'ltoff+4(%r1),%r19 ; get new dlt value.
86 Import stub to call shared library routine from normal object file
87 (multiple sub-space support)
88 : addil L'lt_ptr+ltoff,%dp ; get procedure entry point
89 : ldw R'lt_ptr+ltoff(%r1),%r21
90 : ldw R'lt_ptr+ltoff+4(%r1),%r19 ; get new dlt value.
93 : be 0(%sr0,%r21) ; branch to target
94 : stw %rp,-24(%sp) ; save rp
96 Import stub to call shared library routine from shared library
97 (multiple sub-space support)
98 : addil L'ltoff,%r19 ; get procedure entry point
99 : ldw R'ltoff(%r1),%r21
100 : ldw R'ltoff+4(%r1),%r19 ; get new dlt value.
103 : be 0(%sr0,%r21) ; branch to target
104 : stw %rp,-24(%sp) ; save rp
106 Export stub to return from shared lib routine (multiple sub-space support)
107 One of these is created for each exported procedure in a shared
108 library (and stored in the shared lib). Shared lib routines are
109 called via the first instruction in the export stub so that we can
110 do an inter-space return. Not required for single sub-space.
111 : bl,n X,%rp ; trap the return
113 : ldw -24(%sp),%rp ; restore the original rp
116 : be,n 0(%sr0,%rp) ; inter-space return */
118 #define PLT_ENTRY_SIZE 8
119 #define PLABEL_PLT_ENTRY_SIZE PLT_ENTRY_SIZE
120 #define GOT_ENTRY_SIZE 4
121 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
123 static const bfd_byte plt_stub
[] =
125 0x0e, 0x80, 0x10, 0x96, /* 1: ldw 0(%r20),%r22 */
126 0xea, 0xc0, 0xc0, 0x00, /* bv %r0(%r22) */
127 0x0e, 0x88, 0x10, 0x95, /* ldw 4(%r20),%r21 */
128 #define PLT_STUB_ENTRY (3*4)
129 0xea, 0x9f, 0x1f, 0xdd, /* b,l 1b,%r20 */
130 0xd6, 0x80, 0x1c, 0x1e, /* depi 0,31,2,%r20 */
131 0x00, 0xc0, 0xff, 0xee, /* 9: .word fixup_func */
132 0xde, 0xad, 0xbe, 0xef /* .word fixup_ltp */
135 /* Section name for stubs is the associated section name plus this
137 #define STUB_SUFFIX ".stub"
139 /* Setting the following non-zero makes all long branch stubs
140 generated during a shared link of the PIC variety. This saves on
141 relocs, but costs one extra instruction per stub. */
142 #ifndef LONG_BRANCH_PIC_IN_SHLIB
143 #define LONG_BRANCH_PIC_IN_SHLIB 1
146 /* Set this non-zero to use import stubs instead of long branch stubs
147 where a .plt entry exists for the symbol. This is a fairly useless
148 option as import stubs are bigger than PIC long branch stubs. */
149 #ifndef LONG_BRANCH_VIA_PLT
150 #define LONG_BRANCH_VIA_PLT 0
153 /* We don't need to copy any PC- or GP-relative dynamic relocs into a
154 shared object's dynamic section. */
155 #ifndef RELATIVE_DYNAMIC_RELOCS
156 #define RELATIVE_DYNAMIC_RELOCS 0
160 enum elf32_hppa_stub_type
{
161 hppa_stub_long_branch
,
162 hppa_stub_long_branch_shared
,
164 hppa_stub_import_shared
,
170 struct elf32_hppa_stub_hash_entry
{
172 /* Base hash table entry structure. */
173 struct bfd_hash_entry root
;
175 /* The stub section. */
178 #if ! LONG_BRANCH_PIC_IN_SHLIB
179 /* It's associated reloc section. */
183 /* Offset within stub_sec of the beginning of this stub. */
186 /* Given the symbol's value and its section we can determine its final
187 value when building the stubs (so the stub knows where to jump. */
188 bfd_vma target_value
;
189 asection
*target_section
;
191 enum elf32_hppa_stub_type stub_type
;
193 /* The symbol table entry, if any, that this was derived from. */
194 struct elf32_hppa_link_hash_entry
*h
;
196 /* Where this stub is being called from, or, in the case of combined
197 stub sections, the first input section in the group. */
202 struct elf32_hppa_link_hash_entry
{
204 struct elf_link_hash_entry elf
;
206 /* A pointer to the most recently used stub hash entry against this
208 struct elf32_hppa_stub_hash_entry
*stub_cache
;
210 #if ! LONG_BRANCH_PIC_IN_SHLIB
211 /* Used to track whether we have allocated space for a long branch
212 stub relocation for this symbol in the given section. */
213 asection
*stub_reloc_sec
;
216 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
217 /* Used to count relocations for delayed sizing of relocation
219 struct elf32_hppa_dyn_reloc_entry
{
221 /* Next relocation in the chain. */
222 struct elf32_hppa_dyn_reloc_entry
*next
;
224 /* The section in dynobj. */
227 /* Number of relocs copied in this section. */
232 /* Set during a static link if we detect a function is PIC. */
233 unsigned int pic_call
:1;
235 /* Set if this symbol is used by a plabel reloc. */
236 unsigned int plabel
:1;
238 /* Set if this symbol is an init or fini function and thus should
239 use an absolute reloc. */
240 unsigned int plt_abs
:1;
244 struct elf32_hppa_link_hash_table
{
246 /* The main hash table. */
247 struct elf_link_hash_table root
;
249 /* The stub hash table. */
250 struct bfd_hash_table stub_hash_table
;
252 /* Linker stub bfd. */
255 /* Linker call-backs. */
256 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
257 void (*layout_sections_again
) PARAMS ((void));
259 /* Array to keep track of which stub sections have been created, and
260 information on stub grouping. */
262 /* This is the section to which stubs in the group will be
265 /* The stub section. */
267 #if ! LONG_BRANCH_PIC_IN_SHLIB
268 /* The stub section's reloc section. */
273 /* Short-cuts to get to dynamic linker sections. */
281 /* Whether we support multiple sub-spaces for shared libs. */
282 unsigned int multi_subspace
:1;
284 /* Flags set when PCREL12F and PCREL17F branches detected. Used to
285 select suitable defaults for the stub group size. */
286 unsigned int has_12bit_branch
:1;
287 unsigned int has_17bit_branch
:1;
289 /* Set if we need a .plt stub to support lazy dynamic linking. */
290 unsigned int need_plt_stub
:1;
294 /* Various hash macros and functions. */
295 #define hppa_link_hash_table(p) \
296 ((struct elf32_hppa_link_hash_table *) ((p)->hash))
298 #define hppa_stub_hash_lookup(table, string, create, copy) \
299 ((struct elf32_hppa_stub_hash_entry *) \
300 bfd_hash_lookup ((table), (string), (create), (copy)))
302 static struct bfd_hash_entry
*stub_hash_newfunc
303 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
305 static struct bfd_hash_entry
*hppa_link_hash_newfunc
306 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
308 static struct bfd_link_hash_table
*elf32_hppa_link_hash_table_create
312 /* Stub handling functions. */
313 static char *hppa_stub_name
314 PARAMS ((const asection
*, const asection
*,
315 const struct elf32_hppa_link_hash_entry
*,
316 const Elf_Internal_Rela
*));
318 static struct elf32_hppa_stub_hash_entry
*hppa_get_stub_entry
319 PARAMS ((const asection
*, const asection
*,
320 struct elf32_hppa_link_hash_entry
*,
321 const Elf_Internal_Rela
*,
322 struct elf32_hppa_link_hash_table
*));
324 static struct elf32_hppa_stub_hash_entry
*hppa_add_stub
325 PARAMS ((const char *, asection
*, struct elf32_hppa_link_hash_table
*));
327 static enum elf32_hppa_stub_type hppa_type_of_stub
328 PARAMS ((asection
*, const Elf_Internal_Rela
*,
329 struct elf32_hppa_link_hash_entry
*, bfd_vma
));
331 static boolean hppa_build_one_stub
332 PARAMS ((struct bfd_hash_entry
*, PTR
));
334 static boolean hppa_size_one_stub
335 PARAMS ((struct bfd_hash_entry
*, PTR
));
338 /* BFD and elf backend functions. */
339 static boolean elf32_hppa_object_p
PARAMS ((bfd
*));
341 static boolean elf32_hppa_add_symbol_hook
342 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
343 const char **, flagword
*, asection
**, bfd_vma
*));
345 static boolean elf32_hppa_create_dynamic_sections
346 PARAMS ((bfd
*, struct bfd_link_info
*));
348 static boolean elf32_hppa_check_relocs
349 PARAMS ((bfd
*, struct bfd_link_info
*,
350 asection
*, const Elf_Internal_Rela
*));
352 static asection
*elf32_hppa_gc_mark_hook
353 PARAMS ((bfd
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
354 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
356 static boolean elf32_hppa_gc_sweep_hook
357 PARAMS ((bfd
*, struct bfd_link_info
*,
358 asection
*, const Elf_Internal_Rela
*));
360 static void elf32_hppa_hide_symbol
361 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
363 static boolean elf32_hppa_adjust_dynamic_symbol
364 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
366 static boolean hppa_handle_PIC_calls
367 PARAMS ((struct elf_link_hash_entry
*, PTR
));
369 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
370 || RELATIVE_DYNAMIC_RELOCS)
371 static boolean hppa_discard_copies
372 PARAMS ((struct elf_link_hash_entry
*, PTR
));
375 static boolean clobber_millicode_symbols
376 PARAMS ((struct elf_link_hash_entry
*, struct bfd_link_info
*));
378 static boolean elf32_hppa_size_dynamic_sections
379 PARAMS ((bfd
*, struct bfd_link_info
*));
381 static bfd_reloc_status_type final_link_relocate
382 PARAMS ((asection
*, bfd_byte
*, const Elf_Internal_Rela
*,
383 bfd_vma
, struct elf32_hppa_link_hash_table
*, asection
*,
384 struct elf32_hppa_link_hash_entry
*));
386 static boolean elf32_hppa_relocate_section
387 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*,
388 bfd_byte
*, Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
390 static boolean elf32_hppa_finish_dynamic_symbol
391 PARAMS ((bfd
*, struct bfd_link_info
*,
392 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
394 static boolean elf32_hppa_finish_dynamic_sections
395 PARAMS ((bfd
*, struct bfd_link_info
*));
397 static int elf32_hppa_elf_get_symbol_type
398 PARAMS ((Elf_Internal_Sym
*, int));
401 /* Assorted hash table functions. */
403 /* Initialize an entry in the stub hash table. */
405 static struct bfd_hash_entry
*
406 stub_hash_newfunc (entry
, table
, string
)
407 struct bfd_hash_entry
*entry
;
408 struct bfd_hash_table
*table
;
411 struct elf32_hppa_stub_hash_entry
*ret
;
413 ret
= (struct elf32_hppa_stub_hash_entry
*) entry
;
415 /* Allocate the structure if it has not already been allocated by a
419 ret
= ((struct elf32_hppa_stub_hash_entry
*)
420 bfd_hash_allocate (table
,
421 sizeof (struct elf32_hppa_stub_hash_entry
)));
426 /* Call the allocation method of the superclass. */
427 ret
= ((struct elf32_hppa_stub_hash_entry
*)
428 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
432 /* Initialize the local fields. */
433 ret
->stub_sec
= NULL
;
434 #if ! LONG_BRANCH_PIC_IN_SHLIB
435 ret
->reloc_sec
= NULL
;
437 ret
->stub_offset
= 0;
438 ret
->target_value
= 0;
439 ret
->target_section
= NULL
;
440 ret
->stub_type
= hppa_stub_long_branch
;
445 return (struct bfd_hash_entry
*) ret
;
449 /* Initialize an entry in the link hash table. */
451 static struct bfd_hash_entry
*
452 hppa_link_hash_newfunc (entry
, table
, string
)
453 struct bfd_hash_entry
*entry
;
454 struct bfd_hash_table
*table
;
457 struct elf32_hppa_link_hash_entry
*ret
;
459 ret
= (struct elf32_hppa_link_hash_entry
*) entry
;
461 /* Allocate the structure if it has not already been allocated by a
465 ret
= ((struct elf32_hppa_link_hash_entry
*)
466 bfd_hash_allocate (table
,
467 sizeof (struct elf32_hppa_link_hash_entry
)));
472 /* Call the allocation method of the superclass. */
473 ret
= ((struct elf32_hppa_link_hash_entry
*)
474 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
479 /* Initialize the local fields. */
480 #if ! LONG_BRANCH_PIC_IN_SHLIB
481 ret
->stub_reloc_sec
= NULL
;
483 ret
->stub_cache
= NULL
;
484 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
485 ret
->reloc_entries
= NULL
;
492 return (struct bfd_hash_entry
*) ret
;
496 /* Create the derived linker hash table. The PA ELF port uses the derived
497 hash table to keep information specific to the PA ELF linker (without
498 using static variables). */
500 static struct bfd_link_hash_table
*
501 elf32_hppa_link_hash_table_create (abfd
)
504 struct elf32_hppa_link_hash_table
*ret
;
506 ret
= ((struct elf32_hppa_link_hash_table
*) bfd_alloc (abfd
, sizeof (*ret
)));
510 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
, hppa_link_hash_newfunc
))
512 bfd_release (abfd
, ret
);
516 /* Init the stub hash table too. */
517 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
))
520 ret
->stub_bfd
= NULL
;
521 ret
->add_stub_section
= NULL
;
522 ret
->layout_sections_again
= NULL
;
523 ret
->stub_group
= NULL
;
530 ret
->multi_subspace
= 0;
531 ret
->has_12bit_branch
= 0;
532 ret
->has_17bit_branch
= 0;
533 ret
->need_plt_stub
= 0;
535 return &ret
->root
.root
;
539 /* Build a name for an entry in the stub hash table. */
542 hppa_stub_name (input_section
, sym_sec
, hash
, rel
)
543 const asection
*input_section
;
544 const asection
*sym_sec
;
545 const struct elf32_hppa_link_hash_entry
*hash
;
546 const Elf_Internal_Rela
*rel
;
553 len
= 8 + 1 + strlen (hash
->elf
.root
.root
.string
) + 1 + 8 + 1;
554 stub_name
= bfd_malloc (len
);
555 if (stub_name
!= NULL
)
557 sprintf (stub_name
, "%08x_%s+%x",
558 input_section
->id
& 0xffffffff,
559 hash
->elf
.root
.root
.string
,
560 (int) rel
->r_addend
& 0xffffffff);
565 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
566 stub_name
= bfd_malloc (len
);
567 if (stub_name
!= NULL
)
569 sprintf (stub_name
, "%08x_%x:%x+%x",
570 input_section
->id
& 0xffffffff,
571 sym_sec
->id
& 0xffffffff,
572 (int) ELF32_R_SYM (rel
->r_info
) & 0xffffffff,
573 (int) rel
->r_addend
& 0xffffffff);
580 /* Look up an entry in the stub hash. Stub entries are cached because
581 creating the stub name takes a bit of time. */
583 static struct elf32_hppa_stub_hash_entry
*
584 hppa_get_stub_entry (input_section
, sym_sec
, hash
, rel
, hplink
)
585 const asection
*input_section
;
586 const asection
*sym_sec
;
587 struct elf32_hppa_link_hash_entry
*hash
;
588 const Elf_Internal_Rela
*rel
;
589 struct elf32_hppa_link_hash_table
*hplink
;
591 struct elf32_hppa_stub_hash_entry
*stub_entry
;
592 const asection
*id_sec
;
594 /* If this input section is part of a group of sections sharing one
595 stub section, then use the id of the first section in the group.
596 Stub names need to include a section id, as there may well be
597 more than one stub used to reach say, printf, and we need to
598 distinguish between them. */
599 id_sec
= hplink
->stub_group
[input_section
->id
].link_sec
;
601 if (hash
!= NULL
&& hash
->stub_cache
!= NULL
602 && hash
->stub_cache
->h
== hash
603 && hash
->stub_cache
->id_sec
== id_sec
)
605 stub_entry
= hash
->stub_cache
;
611 stub_name
= hppa_stub_name (id_sec
, sym_sec
, hash
, rel
);
612 if (stub_name
== NULL
)
615 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
,
616 stub_name
, false, false);
617 if (stub_entry
== NULL
)
619 if (hash
== NULL
|| hash
->elf
.root
.type
!= bfd_link_hash_undefweak
)
620 (*_bfd_error_handler
) (_("%s(%s+0x%lx): cannot find stub entry %s"),
621 bfd_get_filename (input_section
->owner
),
623 (long) rel
->r_offset
,
629 hash
->stub_cache
= stub_entry
;
639 /* Add a new stub entry to the stub hash. Not all fields of the new
640 stub entry are initialised. */
642 static struct elf32_hppa_stub_hash_entry
*
643 hppa_add_stub (stub_name
, section
, hplink
)
644 const char *stub_name
;
646 struct elf32_hppa_link_hash_table
*hplink
;
650 struct elf32_hppa_stub_hash_entry
*stub_entry
;
652 link_sec
= hplink
->stub_group
[section
->id
].link_sec
;
653 stub_sec
= hplink
->stub_group
[section
->id
].stub_sec
;
654 if (stub_sec
== NULL
)
656 stub_sec
= hplink
->stub_group
[link_sec
->id
].stub_sec
;
657 if (stub_sec
== NULL
)
662 len
= strlen (link_sec
->name
) + sizeof (STUB_SUFFIX
);
663 s_name
= bfd_alloc (hplink
->stub_bfd
, len
);
667 strcpy (s_name
, link_sec
->name
);
668 strcpy (s_name
+ len
- sizeof (STUB_SUFFIX
), STUB_SUFFIX
);
669 stub_sec
= (*hplink
->add_stub_section
) (s_name
, link_sec
);
670 if (stub_sec
== NULL
)
672 hplink
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
674 hplink
->stub_group
[section
->id
].stub_sec
= stub_sec
;
677 /* Enter this entry into the linker stub hash table. */
678 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
, stub_name
,
680 if (stub_entry
== NULL
)
682 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
683 bfd_get_filename (section
->owner
),
688 stub_entry
->stub_sec
= stub_sec
;
689 #if ! LONG_BRANCH_PIC_IN_SHLIB
690 stub_entry
->reloc_sec
= hplink
->stub_group
[section
->id
].reloc_sec
;
692 stub_entry
->stub_offset
= 0;
693 stub_entry
->id_sec
= link_sec
;
698 /* Determine the type of stub needed, if any, for a call. */
700 static enum elf32_hppa_stub_type
701 hppa_type_of_stub (input_sec
, rel
, hash
, destination
)
703 const Elf_Internal_Rela
*rel
;
704 struct elf32_hppa_link_hash_entry
*hash
;
708 bfd_vma branch_offset
;
709 bfd_vma max_branch_offset
;
713 && (((hash
->elf
.root
.type
== bfd_link_hash_defined
714 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
715 && hash
->elf
.root
.u
.def
.section
->output_section
== NULL
)
716 || (hash
->elf
.root
.type
== bfd_link_hash_defweak
717 && hash
->elf
.dynindx
!= -1
718 && hash
->elf
.plt
.offset
!= (bfd_vma
) -1)
719 || hash
->elf
.root
.type
== bfd_link_hash_undefweak
720 || hash
->elf
.root
.type
== bfd_link_hash_undefined
723 /* If output_section is NULL, then it's a symbol defined in a
724 shared library. We will need an import stub. Decide between
725 hppa_stub_import and hppa_stub_import_shared later. For
726 shared links we need stubs for undefined or weak syms too;
727 They will presumably be resolved by the dynamic linker. */
728 return hppa_stub_import
;
731 /* Determine where the call point is. */
732 location
= (input_sec
->output_offset
733 + input_sec
->output_section
->vma
736 branch_offset
= destination
- location
- 8;
737 r_type
= ELF32_R_TYPE (rel
->r_info
);
739 /* Determine if a long branch stub is needed. parisc branch offsets
740 are relative to the second instruction past the branch, ie. +8
741 bytes on from the branch instruction location. The offset is
742 signed and counts in units of 4 bytes. */
743 if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
745 max_branch_offset
= (1 << (17-1)) << 2;
747 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
749 max_branch_offset
= (1 << (12-1)) << 2;
751 else /* R_PARISC_PCREL22F. */
753 max_branch_offset
= (1 << (22-1)) << 2;
756 if (branch_offset
+ max_branch_offset
>= 2*max_branch_offset
)
758 #if LONG_BRANCH_VIA_PLT
760 && hash
->elf
.dynindx
!= -1
761 && hash
->elf
.plt
.offset
!= (bfd_vma
) -1)
763 /* If we are doing a shared link and find we need a long
764 branch stub, then go via the .plt if possible. */
765 return hppa_stub_import
;
769 return hppa_stub_long_branch
;
771 return hppa_stub_none
;
775 /* Build one linker stub as defined by the stub hash table entry GEN_ENTRY.
776 IN_ARG contains the link info pointer. */
778 #define LDIL_R1 0x20200000 /* ldil LR'XXX,%r1 */
779 #define BE_SR4_R1 0xe0202002 /* be,n RR'XXX(%sr4,%r1) */
781 #define BL_R1 0xe8200000 /* b,l .+8,%r1 */
782 #define ADDIL_R1 0x28200000 /* addil L'XXX,%r1,%r1 */
783 #define DEPI_R1 0xd4201c1e /* depi 0,31,2,%r1 */
785 #define ADDIL_DP 0x2b600000 /* addil L'XXX,%dp,%r1 */
786 #define LDW_R1_R21 0x48350000 /* ldw R'XXX(%sr0,%r1),%r21 */
787 #define BV_R0_R21 0xeaa0c000 /* bv %r0(%r21) */
788 #define LDW_R1_R19 0x48330000 /* ldw R'XXX(%sr0,%r1),%r19 */
790 #define ADDIL_R19 0x2a600000 /* addil L'XXX,%r19,%r1 */
791 #define LDW_R1_DP 0x483b0000 /* ldw R'XXX(%sr0,%r1),%dp */
793 #define LDSID_R21_R1 0x02a010a1 /* ldsid (%sr0,%r21),%r1 */
794 #define MTSP_R1 0x00011820 /* mtsp %r1,%sr0 */
795 #define BE_SR0_R21 0xe2a00000 /* be 0(%sr0,%r21) */
796 #define STW_RP 0x6bc23fd1 /* stw %rp,-24(%sr0,%sp) */
798 #define BL_RP 0xe8400002 /* b,l,n XXX,%rp */
799 #define NOP 0x08000240 /* nop */
800 #define LDW_RP 0x4bc23fd1 /* ldw -24(%sr0,%sp),%rp */
801 #define LDSID_RP_R1 0x004010a1 /* ldsid (%sr0,%rp),%r1 */
802 #define BE_SR0_RP 0xe0400002 /* be,n 0(%sr0,%rp) */
809 #define LDW_R1_DLT LDW_R1_R19
811 #define LDW_R1_DLT LDW_R1_DP
815 hppa_build_one_stub (gen_entry
, in_arg
)
816 struct bfd_hash_entry
*gen_entry
;
819 struct elf32_hppa_stub_hash_entry
*stub_entry
;
820 struct bfd_link_info
*info
;
821 struct elf32_hppa_link_hash_table
*hplink
;
830 /* Massage our args to the form they really have. */
831 stub_entry
= (struct elf32_hppa_stub_hash_entry
*) gen_entry
;
832 info
= (struct bfd_link_info
*) in_arg
;
834 hplink
= hppa_link_hash_table (info
);
835 stub_sec
= stub_entry
->stub_sec
;
837 /* Make a note of the offset within the stubs for this entry. */
838 stub_entry
->stub_offset
= stub_sec
->_raw_size
;
839 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
841 stub_bfd
= stub_sec
->owner
;
843 switch (stub_entry
->stub_type
)
845 case hppa_stub_long_branch
:
846 /* Create the long branch. A long branch is formed with "ldil"
847 loading the upper bits of the target address into a register,
848 then branching with "be" which adds in the lower bits.
849 The "be" has its delay slot nullified. */
850 sym_value
= (stub_entry
->target_value
851 + stub_entry
->target_section
->output_offset
852 + stub_entry
->target_section
->output_section
->vma
);
854 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_lrsel
);
855 insn
= hppa_rebuild_insn ((int) LDIL_R1
, val
, 21);
856 bfd_put_32 (stub_bfd
, insn
, loc
);
858 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_rrsel
) >> 2;
859 insn
= hppa_rebuild_insn ((int) BE_SR4_R1
, val
, 17);
860 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
862 #if ! LONG_BRANCH_PIC_IN_SHLIB
865 /* Output a dynamic relocation for this stub. We only
866 output one PCREL21L reloc per stub, trusting that the
867 dynamic linker will also fix the implied PCREL17R for the
868 second instruction. PCREL21L dynamic relocs had better
869 never be emitted for some other purpose... */
871 Elf_Internal_Rela outrel
;
873 if (stub_entry
->h
== NULL
)
875 (*_bfd_error_handler
)
876 (_("%s(%s+0x%lx): cannot relocate %s, recompile with -ffunction-sections"),
877 bfd_get_filename (stub_entry
->target_section
->owner
),
879 (long) stub_entry
->stub_offset
,
880 stub_entry
->root
.string
);
881 bfd_set_error (bfd_error_bad_value
);
885 srel
= stub_entry
->reloc_sec
;
888 (*_bfd_error_handler
)
889 (_("Could not find relocation section for %s"),
891 bfd_set_error (bfd_error_bad_value
);
895 outrel
.r_offset
= (stub_entry
->stub_offset
896 + stub_sec
->output_offset
897 + stub_sec
->output_section
->vma
);
898 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_PCREL21L
);
899 outrel
.r_addend
= sym_value
;
900 bfd_elf32_swap_reloca_out (stub_sec
->output_section
->owner
,
902 ((Elf32_External_Rela
*)
903 srel
->contents
+ srel
->reloc_count
));
910 case hppa_stub_long_branch_shared
:
911 /* Branches are relative. This is where we are going to. */
912 sym_value
= (stub_entry
->target_value
913 + stub_entry
->target_section
->output_offset
914 + stub_entry
->target_section
->output_section
->vma
);
916 /* And this is where we are coming from, more or less. */
917 sym_value
-= (stub_entry
->stub_offset
918 + stub_sec
->output_offset
919 + stub_sec
->output_section
->vma
);
921 bfd_put_32 (stub_bfd
, (bfd_vma
) BL_R1
, loc
);
922 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_lrsel
);
923 insn
= hppa_rebuild_insn ((int) ADDIL_R1
, val
, 21);
924 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
926 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_rrsel
) >> 2;
927 insn
= hppa_rebuild_insn ((int) BE_SR4_R1
, val
, 17);
928 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
932 case hppa_stub_import
:
933 case hppa_stub_import_shared
:
934 sym_value
= (stub_entry
->h
->elf
.plt
.offset
935 + hplink
->splt
->output_offset
936 + hplink
->splt
->output_section
->vma
937 - elf_gp (hplink
->splt
->output_section
->owner
));
941 if (stub_entry
->stub_type
== hppa_stub_import_shared
)
944 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_lrsel
),
945 insn
= hppa_rebuild_insn ((int) insn
, val
, 21);
946 bfd_put_32 (stub_bfd
, insn
, loc
);
948 /* It is critical to use lrsel/rrsel here because we are using
949 two different offsets (+0 and +4) from sym_value. If we use
950 lsel/rsel then with unfortunate sym_values we will round
951 sym_value+4 up to the next 2k block leading to a mis-match
952 between the lsel and rsel value. */
953 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_rrsel
);
954 insn
= hppa_rebuild_insn ((int) LDW_R1_R21
, val
, 14);
955 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
957 if (hplink
->multi_subspace
)
959 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 4, e_rrsel
);
960 insn
= hppa_rebuild_insn ((int) LDW_R1_DLT
, val
, 14);
961 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
963 bfd_put_32 (stub_bfd
, (bfd_vma
) LDSID_R21_R1
, loc
+ 12);
964 bfd_put_32 (stub_bfd
, (bfd_vma
) MTSP_R1
, loc
+ 16);
965 bfd_put_32 (stub_bfd
, (bfd_vma
) BE_SR0_R21
, loc
+ 20);
966 bfd_put_32 (stub_bfd
, (bfd_vma
) STW_RP
, loc
+ 24);
972 bfd_put_32 (stub_bfd
, (bfd_vma
) BV_R0_R21
, loc
+ 8);
973 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 4, e_rrsel
);
974 insn
= hppa_rebuild_insn ((int) LDW_R1_DLT
, val
, 14);
975 bfd_put_32 (stub_bfd
, insn
, loc
+ 12);
981 && stub_entry
->h
!= NULL
982 && stub_entry
->h
->pic_call
)
984 /* Build the .plt entry needed to call a PIC function from
985 statically linked code. We don't need any relocs. */
987 struct elf32_hppa_link_hash_entry
*eh
;
990 dynobj
= hplink
->root
.dynobj
;
991 eh
= (struct elf32_hppa_link_hash_entry
*) stub_entry
->h
;
993 BFD_ASSERT (eh
->elf
.root
.type
== bfd_link_hash_defined
994 || eh
->elf
.root
.type
== bfd_link_hash_defweak
);
996 value
= (eh
->elf
.root
.u
.def
.value
997 + eh
->elf
.root
.u
.def
.section
->output_offset
998 + eh
->elf
.root
.u
.def
.section
->output_section
->vma
);
1000 /* Fill in the entry in the procedure linkage table.
1002 The format of a plt entry is
1006 bfd_put_32 (hplink
->splt
->owner
, value
,
1007 hplink
->splt
->contents
+ eh
->elf
.plt
.offset
);
1008 value
= elf_gp (hplink
->splt
->output_section
->owner
);
1009 bfd_put_32 (hplink
->splt
->owner
, value
,
1010 hplink
->splt
->contents
+ eh
->elf
.plt
.offset
+ 4);
1014 case hppa_stub_export
:
1015 /* Branches are relative. This is where we are going to. */
1016 sym_value
= (stub_entry
->target_value
1017 + stub_entry
->target_section
->output_offset
1018 + stub_entry
->target_section
->output_section
->vma
);
1020 /* And this is where we are coming from. */
1021 sym_value
-= (stub_entry
->stub_offset
1022 + stub_sec
->output_offset
1023 + stub_sec
->output_section
->vma
);
1025 if (sym_value
- 8 + 0x40000 >= 0x80000)
1027 (*_bfd_error_handler
)
1028 (_("%s(%s+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
1029 bfd_get_filename (stub_entry
->target_section
->owner
),
1031 (long) stub_entry
->stub_offset
,
1032 stub_entry
->root
.string
);
1033 bfd_set_error (bfd_error_bad_value
);
1037 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_fsel
) >> 2;
1038 insn
= hppa_rebuild_insn ((int) BL_RP
, val
, 17);
1039 bfd_put_32 (stub_bfd
, insn
, loc
);
1041 bfd_put_32 (stub_bfd
, (bfd_vma
) NOP
, loc
+ 4);
1042 bfd_put_32 (stub_bfd
, (bfd_vma
) LDW_RP
, loc
+ 8);
1043 bfd_put_32 (stub_bfd
, (bfd_vma
) LDSID_RP_R1
, loc
+ 12);
1044 bfd_put_32 (stub_bfd
, (bfd_vma
) MTSP_R1
, loc
+ 16);
1045 bfd_put_32 (stub_bfd
, (bfd_vma
) BE_SR0_RP
, loc
+ 20);
1047 /* Point the function symbol at the stub. */
1048 stub_entry
->h
->elf
.root
.u
.def
.section
= stub_sec
;
1049 stub_entry
->h
->elf
.root
.u
.def
.value
= stub_sec
->_raw_size
;
1059 stub_sec
->_raw_size
+= size
;
1086 /* As above, but don't actually build the stub. Just bump offset so
1087 we know stub section sizes. */
1090 hppa_size_one_stub (gen_entry
, in_arg
)
1091 struct bfd_hash_entry
*gen_entry
;
1094 struct elf32_hppa_stub_hash_entry
*stub_entry
;
1095 struct elf32_hppa_link_hash_table
*hplink
;
1098 /* Massage our args to the form they really have. */
1099 stub_entry
= (struct elf32_hppa_stub_hash_entry
*) gen_entry
;
1100 hplink
= (struct elf32_hppa_link_hash_table
*) in_arg
;
1102 if (stub_entry
->stub_type
== hppa_stub_long_branch
)
1104 #if ! LONG_BRANCH_PIC_IN_SHLIB
1105 if (stub_entry
->reloc_sec
!= NULL
)
1106 stub_entry
->reloc_sec
->_raw_size
+= sizeof (Elf32_External_Rela
);
1110 else if (stub_entry
->stub_type
== hppa_stub_long_branch_shared
)
1112 else if (stub_entry
->stub_type
== hppa_stub_export
)
1114 else /* hppa_stub_import or hppa_stub_import_shared. */
1116 if (hplink
->multi_subspace
)
1122 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);
1151 /* Undo the generic ELF code's subtraction of section->vma from the
1152 value of each external symbol. */
1155 elf32_hppa_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
1156 bfd
*abfd ATTRIBUTE_UNUSED
;
1157 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1158 const Elf_Internal_Sym
*sym ATTRIBUTE_UNUSED
;
1159 const char **namep ATTRIBUTE_UNUSED
;
1160 flagword
*flagsp ATTRIBUTE_UNUSED
;
1164 *valp
+= (*secp
)->vma
;
1169 /* Create the .plt and .got sections, and set up our hash table
1170 short-cuts to various dynamic sections. */
1173 elf32_hppa_create_dynamic_sections (abfd
, info
)
1175 struct bfd_link_info
*info
;
1177 struct elf32_hppa_link_hash_table
*hplink
;
1179 /* Don't try to create the .plt and .got twice. */
1180 hplink
= hppa_link_hash_table (info
);
1181 if (hplink
->splt
!= NULL
)
1184 /* Call the generic code to do most of the work. */
1185 if (! _bfd_elf_create_dynamic_sections (abfd
, info
))
1188 hplink
->splt
= bfd_get_section_by_name (abfd
, ".plt");
1189 hplink
->srelplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
1191 hplink
->sgot
= bfd_get_section_by_name (abfd
, ".got");
1192 hplink
->srelgot
= bfd_make_section (abfd
, ".rela.got");
1193 if (hplink
->srelgot
== NULL
1194 || ! bfd_set_section_flags (abfd
, hplink
->srelgot
,
1199 | SEC_LINKER_CREATED
1201 || ! bfd_set_section_alignment (abfd
, hplink
->srelgot
, 2))
1204 hplink
->sdynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
1205 hplink
->srelbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
1211 /* Look through the relocs for a section during the first phase, and
1212 allocate space in the global offset table or procedure linkage
1213 table. At this point we haven't necessarily read all the input
1217 elf32_hppa_check_relocs (abfd
, info
, sec
, relocs
)
1219 struct bfd_link_info
*info
;
1221 const Elf_Internal_Rela
*relocs
;
1224 Elf_Internal_Shdr
*symtab_hdr
;
1225 struct elf_link_hash_entry
**sym_hashes
;
1226 bfd_signed_vma
*local_got_refcounts
;
1227 const Elf_Internal_Rela
*rel
;
1228 const Elf_Internal_Rela
*rel_end
;
1229 struct elf32_hppa_link_hash_table
*hplink
;
1231 asection
*stubreloc
;
1233 if (info
->relocateable
)
1236 hplink
= hppa_link_hash_table (info
);
1237 dynobj
= hplink
->root
.dynobj
;
1238 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1239 sym_hashes
= elf_sym_hashes (abfd
);
1240 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1244 rel_end
= relocs
+ sec
->reloc_count
;
1245 for (rel
= relocs
; rel
< rel_end
; rel
++)
1251 #if LONG_BRANCH_PIC_IN_SHLIB
1252 NEED_STUBREL
= 0, /* We won't be needing them in this case. */
1259 unsigned int r_symndx
, r_type
;
1260 struct elf32_hppa_link_hash_entry
*h
;
1263 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1265 if (r_symndx
< symtab_hdr
->sh_info
)
1268 h
= ((struct elf32_hppa_link_hash_entry
*)
1269 sym_hashes
[r_symndx
- symtab_hdr
->sh_info
]);
1271 r_type
= ELF32_R_TYPE (rel
->r_info
);
1275 case R_PARISC_DLTIND14F
:
1276 case R_PARISC_DLTIND14R
:
1277 case R_PARISC_DLTIND21L
:
1278 /* This symbol requires a global offset table entry. */
1279 need_entry
= NEED_GOT
;
1281 /* Mark this section as containing PIC code. */
1282 sec
->flags
|= SEC_HAS_GOT_REF
;
1285 case R_PARISC_PLABEL14R
: /* "Official" procedure labels. */
1286 case R_PARISC_PLABEL21L
:
1287 case R_PARISC_PLABEL32
:
1288 /* If the addend is non-zero, we break badly. */
1289 BFD_ASSERT (rel
->r_addend
== 0);
1291 /* If we are creating a shared library, then we need to
1292 create a PLT entry for all PLABELs, because PLABELs with
1293 local symbols may be passed via a pointer to another
1294 object. Additionally, output a dynamic relocation
1295 pointing to the PLT entry. */
1296 need_entry
= PLT_PLABEL
| NEED_PLT
| NEED_DYNREL
;
1299 case R_PARISC_PCREL12F
:
1300 hplink
->has_12bit_branch
= 1;
1302 case R_PARISC_PCREL17C
:
1303 case R_PARISC_PCREL17F
:
1304 hplink
->has_17bit_branch
= 1;
1306 case R_PARISC_PCREL22F
:
1307 /* Function calls might need to go through the .plt, and
1308 might require long branch stubs. */
1311 /* We know local syms won't need a .plt entry, and if
1312 they need a long branch stub we can't guarantee that
1313 we can reach the stub. So just flag an error later
1314 if we're doing a shared link and find we need a long
1320 /* Global symbols will need a .plt entry if they remain
1321 global, and in most cases won't need a long branch
1322 stub. Unfortunately, we have to cater for the case
1323 where a symbol is forced local by versioning, or due
1324 to symbolic linking, and we lose the .plt entry. */
1325 need_entry
= NEED_PLT
| NEED_STUBREL
;
1329 case R_PARISC_SEGBASE
: /* Used to set segment base. */
1330 case R_PARISC_SEGREL32
: /* Relative reloc. */
1331 case R_PARISC_PCREL14F
: /* PC relative load/store. */
1332 case R_PARISC_PCREL14R
:
1333 case R_PARISC_PCREL17R
: /* External branches. */
1334 case R_PARISC_PCREL21L
: /* As above, and for load/store too. */
1335 /* We don't need to propagate the relocation if linking a
1336 shared object since these are section relative. */
1339 case R_PARISC_DPREL14F
: /* Used for gp rel data load/store. */
1340 case R_PARISC_DPREL14R
:
1341 case R_PARISC_DPREL21L
:
1344 (*_bfd_error_handler
)
1345 (_("%s: relocation %s can not be used when making a shared object; recompile with -fPIC"),
1346 bfd_get_filename (abfd
),
1347 elf_hppa_howto_table
[r_type
].name
);
1348 bfd_set_error (bfd_error_bad_value
);
1353 case R_PARISC_DIR17F
: /* Used for external branches. */
1354 case R_PARISC_DIR17R
:
1355 case R_PARISC_DIR14F
: /* Used for load/store from absolute locn. */
1356 case R_PARISC_DIR14R
:
1357 case R_PARISC_DIR21L
: /* As above, and for ext branches too. */
1359 /* Help debug shared library creation. Any of the above
1360 relocs can be used in shared libs, but they may cause
1361 pages to become unshared. */
1364 (*_bfd_error_handler
)
1365 (_("%s: relocation %s should not be used when making a shared object; recompile with -fPIC"),
1366 bfd_get_filename (abfd
),
1367 elf_hppa_howto_table
[r_type
].name
);
1372 case R_PARISC_DIR32
: /* .word, PARISC.unwind relocs. */
1373 /* We may want to output a dynamic relocation later. */
1374 need_entry
= NEED_DYNREL
;
1377 /* This relocation describes the C++ object vtable hierarchy.
1378 Reconstruct it for later use during GC. */
1379 case R_PARISC_GNU_VTINHERIT
:
1380 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
,
1381 &h
->elf
, rel
->r_offset
))
1385 /* This relocation describes which C++ vtable entries are actually
1386 used. Record for later use during GC. */
1387 case R_PARISC_GNU_VTENTRY
:
1388 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
,
1389 &h
->elf
, rel
->r_addend
))
1397 /* Now carry out our orders. */
1398 if (need_entry
& NEED_GOT
)
1400 /* Allocate space for a GOT entry, as well as a dynamic
1401 relocation for this entry. */
1403 hplink
->root
.dynobj
= dynobj
= abfd
;
1405 if (hplink
->sgot
== NULL
)
1407 if (! elf32_hppa_create_dynamic_sections (dynobj
, info
))
1413 if (h
->elf
.got
.refcount
== -1)
1415 h
->elf
.got
.refcount
= 1;
1417 /* Make sure this symbol is output as a dynamic symbol. */
1418 if (h
->elf
.dynindx
== -1)
1420 if (! bfd_elf32_link_record_dynamic_symbol (info
,
1425 hplink
->sgot
->_raw_size
+= GOT_ENTRY_SIZE
;
1426 hplink
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
1429 h
->elf
.got
.refcount
+= 1;
1433 /* This is a global offset table entry for a local symbol. */
1434 if (local_got_refcounts
== NULL
)
1438 /* Allocate space for local got offsets and local
1439 plt offsets. Done this way to save polluting
1440 elf_obj_tdata with another target specific
1442 size
= symtab_hdr
->sh_info
* 2 * sizeof (bfd_signed_vma
);
1443 local_got_refcounts
= ((bfd_signed_vma
*)
1444 bfd_alloc (abfd
, size
));
1445 if (local_got_refcounts
== NULL
)
1447 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1448 memset (local_got_refcounts
, -1, size
);
1450 if (local_got_refcounts
[r_symndx
] == -1)
1452 local_got_refcounts
[r_symndx
] = 1;
1454 hplink
->sgot
->_raw_size
+= GOT_ENTRY_SIZE
;
1457 /* If we are generating a shared object, we need to
1458 output a reloc so that the dynamic linker can
1459 adjust this GOT entry (because the address
1460 the shared library is loaded at is not fixed). */
1461 hplink
->srelgot
->_raw_size
+=
1462 sizeof (Elf32_External_Rela
);
1466 local_got_refcounts
[r_symndx
] += 1;
1470 if (need_entry
& NEED_PLT
)
1472 /* If we are creating a shared library, and this is a reloc
1473 against a weak symbol or a global symbol in a dynamic
1474 object, then we will be creating an import stub and a
1475 .plt entry for the symbol. Similarly, on a normal link
1476 to symbols defined in a dynamic object we'll need the
1477 import stub and a .plt entry. We don't know yet whether
1478 the symbol is defined or not, so make an entry anyway and
1479 clean up later in adjust_dynamic_symbol. */
1480 if ((sec
->flags
& SEC_ALLOC
) != 0)
1484 if (h
->elf
.plt
.refcount
== -1)
1486 h
->elf
.plt
.refcount
= 1;
1487 h
->elf
.elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1490 h
->elf
.plt
.refcount
+= 1;
1492 /* If this .plt entry is for a plabel, mark it so
1493 that adjust_dynamic_symbol will keep the entry
1494 even if it appears to be local. */
1495 if (need_entry
& PLT_PLABEL
)
1498 else if (need_entry
& PLT_PLABEL
)
1502 if (local_got_refcounts
== NULL
)
1506 /* Allocate space for local got offsets and local
1508 size
= symtab_hdr
->sh_info
* 2 * sizeof (bfd_signed_vma
);
1509 local_got_refcounts
= ((bfd_signed_vma
*)
1510 bfd_alloc (abfd
, size
));
1511 if (local_got_refcounts
== NULL
)
1513 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1514 memset (local_got_refcounts
, -1, size
);
1516 indx
= r_symndx
+ symtab_hdr
->sh_info
;
1517 if (local_got_refcounts
[indx
] == -1)
1518 local_got_refcounts
[indx
] = 1;
1520 local_got_refcounts
[indx
] += 1;
1525 if (need_entry
& (NEED_DYNREL
| NEED_STUBREL
))
1527 /* Flag this symbol as having a non-got, non-plt reference
1528 so that we generate copy relocs if it turns out to be
1531 h
->elf
.elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
1533 /* If we are creating a shared library then we need to copy
1534 the reloc into the shared library. However, if we are
1535 linking with -Bsymbolic, we need only copy absolute
1536 relocs or relocs against symbols that are not defined in
1537 an object we are including in the link. PC- or DP- or
1538 DLT-relative relocs against any local sym or global sym
1539 with DEF_REGULAR set, can be discarded. At this point we
1540 have not seen all the input files, so it is possible that
1541 DEF_REGULAR is not set now but will be set later (it is
1542 never cleared). We account for that possibility below by
1543 storing information in the reloc_entries field of the
1546 A similar situation to the -Bsymbolic case occurs when
1547 creating shared libraries and symbol visibility changes
1548 render the symbol local.
1550 As it turns out, all the relocs we will be creating here
1551 are absolute, so we cannot remove them on -Bsymbolic
1552 links or visibility changes anyway. A STUB_REL reloc
1553 is absolute too, as in that case it is the reloc in the
1554 stub we will be creating, rather than copying the PCREL
1555 reloc in the branch. */
1556 if ((sec
->flags
& SEC_ALLOC
) != 0
1558 #if RELATIVE_DYNAMIC_RELOCS
1560 || is_absolute_reloc (r_type
)
1562 && ((h
->elf
.elf_link_hash_flags
1563 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
1571 if ((need_entry
& NEED_STUBREL
))
1574 /* Create a reloc section in dynobj and make room for
1581 hplink
->root
.dynobj
= dynobj
= abfd
;
1583 name
= bfd_elf_string_from_elf_section
1585 elf_elfheader (abfd
)->e_shstrndx
,
1586 elf_section_data (sec
)->rel_hdr
.sh_name
);
1589 (*_bfd_error_handler
)
1590 (_("Could not find relocation section for %s"),
1592 bfd_set_error (bfd_error_bad_value
);
1596 if ((need_entry
& NEED_STUBREL
))
1598 size_t len
= strlen (name
) + sizeof (STUB_SUFFIX
);
1599 char *newname
= bfd_malloc (len
);
1601 if (newname
== NULL
)
1603 strcpy (newname
, name
);
1604 strcpy (newname
+ len
- sizeof (STUB_SUFFIX
),
1609 srel
= bfd_get_section_by_name (dynobj
, name
);
1614 srel
= bfd_make_section (dynobj
, name
);
1615 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
1616 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1617 if ((sec
->flags
& SEC_ALLOC
) != 0)
1618 flags
|= SEC_ALLOC
| SEC_LOAD
;
1620 || !bfd_set_section_flags (dynobj
, srel
, flags
)
1621 || !bfd_set_section_alignment (dynobj
, srel
, 2))
1624 else if ((need_entry
& NEED_STUBREL
))
1627 if ((need_entry
& NEED_STUBREL
))
1633 #if ! LONG_BRANCH_PIC_IN_SHLIB
1634 /* If this is a function call, we only need one dynamic
1635 reloc for the stub as all calls to a particular
1636 function will go through the same stub. Actually, a
1637 long branch stub needs two relocations, but we count
1638 on some intelligence on the part of the dynamic
1640 if ((need_entry
& NEED_STUBREL
))
1642 doit
= h
->stub_reloc_sec
!= stubreloc
;
1643 h
->stub_reloc_sec
= stubreloc
;
1651 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
1653 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
1654 /* Keep track of relocations we have entered for
1655 this global symbol, so that we can discard them
1656 later if necessary. */
1659 #if RELATIVE_DYNAMIC_RELOCS
1660 || ! is_absolute_reloc (rtype
)
1662 || (need_entry
& NEED_STUBREL
)))
1664 struct elf32_hppa_dyn_reloc_entry
*p
;
1666 for (p
= h
->reloc_entries
; p
!= NULL
; p
= p
->next
)
1667 if (p
->section
== srel
)
1672 p
= ((struct elf32_hppa_dyn_reloc_entry
*)
1673 bfd_alloc (dynobj
, sizeof *p
));
1676 p
->next
= h
->reloc_entries
;
1677 h
->reloc_entries
= p
;
1682 /* NEED_STUBREL and NEED_DYNREL are never both
1683 set. Leave the count at zero for the
1684 NEED_STUBREL case as we only ever have one
1685 stub reloc per section per symbol, and this
1686 simplifies code in hppa_discard_copies. */
1687 if (! (need_entry
& NEED_STUBREL
))
1700 /* Return the section that should be marked against garbage collection
1701 for a given relocation. */
1704 elf32_hppa_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
1706 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1707 Elf_Internal_Rela
*rel
;
1708 struct elf_link_hash_entry
*h
;
1709 Elf_Internal_Sym
*sym
;
1713 switch ((unsigned int) ELF32_R_TYPE (rel
->r_info
))
1715 case R_PARISC_GNU_VTINHERIT
:
1716 case R_PARISC_GNU_VTENTRY
:
1720 switch (h
->root
.type
)
1722 case bfd_link_hash_defined
:
1723 case bfd_link_hash_defweak
:
1724 return h
->root
.u
.def
.section
;
1726 case bfd_link_hash_common
:
1727 return h
->root
.u
.c
.p
->section
;
1736 if (!(elf_bad_symtab (abfd
)
1737 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
1738 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
1739 && sym
->st_shndx
!= SHN_COMMON
))
1741 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
1749 /* Update the got and plt entry reference counts for the section being
1753 elf32_hppa_gc_sweep_hook (abfd
, info
, sec
, relocs
)
1755 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1757 const Elf_Internal_Rela
*relocs
;
1759 Elf_Internal_Shdr
*symtab_hdr
;
1760 struct elf_link_hash_entry
**sym_hashes
;
1761 bfd_signed_vma
*local_got_refcounts
;
1762 bfd_signed_vma
*local_plt_refcounts
;
1763 const Elf_Internal_Rela
*rel
, *relend
;
1764 unsigned long r_symndx
;
1765 struct elf_link_hash_entry
*h
;
1766 struct elf32_hppa_link_hash_table
*hplink
;
1771 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1772 sym_hashes
= elf_sym_hashes (abfd
);
1773 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1774 local_plt_refcounts
= local_got_refcounts
;
1775 if (local_plt_refcounts
!= NULL
)
1776 local_plt_refcounts
+= symtab_hdr
->sh_info
;
1777 hplink
= hppa_link_hash_table (info
);
1778 dynobj
= hplink
->root
.dynobj
;
1782 sgot
= hplink
->sgot
;
1783 srelgot
= hplink
->srelgot
;
1785 relend
= relocs
+ sec
->reloc_count
;
1786 for (rel
= relocs
; rel
< relend
; rel
++)
1787 switch ((unsigned int) ELF32_R_TYPE (rel
->r_info
))
1789 case R_PARISC_DLTIND14F
:
1790 case R_PARISC_DLTIND14R
:
1791 case R_PARISC_DLTIND21L
:
1792 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1793 if (r_symndx
>= symtab_hdr
->sh_info
)
1795 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1796 if (h
->got
.refcount
> 0)
1798 h
->got
.refcount
-= 1;
1799 if (h
->got
.refcount
== 0)
1801 sgot
->_raw_size
-= GOT_ENTRY_SIZE
;
1802 srelgot
->_raw_size
-= sizeof (Elf32_External_Rela
);
1806 else if (local_got_refcounts
!= NULL
)
1808 if (local_got_refcounts
[r_symndx
] > 0)
1810 local_got_refcounts
[r_symndx
] -= 1;
1811 if (local_got_refcounts
[r_symndx
] == 0)
1813 sgot
->_raw_size
-= GOT_ENTRY_SIZE
;
1815 srelgot
->_raw_size
-= sizeof (Elf32_External_Rela
);
1821 case R_PARISC_PCREL12F
:
1822 case R_PARISC_PCREL17C
:
1823 case R_PARISC_PCREL17F
:
1824 case R_PARISC_PCREL22F
:
1825 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1826 if (r_symndx
>= symtab_hdr
->sh_info
)
1828 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1829 if (h
->plt
.refcount
> 0)
1830 h
->plt
.refcount
-= 1;
1834 case R_PARISC_PLABEL14R
:
1835 case R_PARISC_PLABEL21L
:
1836 case R_PARISC_PLABEL32
:
1837 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1838 if (r_symndx
>= symtab_hdr
->sh_info
)
1840 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1841 if (h
->plt
.refcount
> 0)
1842 h
->plt
.refcount
-= 1;
1844 else if (local_plt_refcounts
!= NULL
)
1846 if (local_plt_refcounts
[r_symndx
] > 0)
1847 local_plt_refcounts
[r_symndx
] -= 1;
1859 /* Our own version of hide_symbol, so that we can keep plt entries for
1863 elf32_hppa_hide_symbol (info
, h
)
1864 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1865 struct elf_link_hash_entry
*h
;
1868 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
)
1870 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1871 h
->plt
.offset
= (bfd_vma
) -1;
1876 /* Adjust a symbol defined by a dynamic object and referenced by a
1877 regular object. The current definition is in some section of the
1878 dynamic object, but we're not including those sections. We have to
1879 change the definition to something the rest of the link can
1883 elf32_hppa_adjust_dynamic_symbol (info
, h
)
1884 struct bfd_link_info
*info
;
1885 struct elf_link_hash_entry
*h
;
1888 struct elf32_hppa_link_hash_table
*hplink
;
1891 hplink
= hppa_link_hash_table (info
);
1892 dynobj
= hplink
->root
.dynobj
;
1894 /* If this is a function, put it in the procedure linkage table. We
1895 will fill in the contents of the procedure linkage table later,
1896 when we know the address of the .got section. */
1897 if (h
->type
== STT_FUNC
1898 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1900 if (h
->plt
.refcount
<= 0
1901 || ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
1902 && h
->root
.type
!= bfd_link_hash_defweak
1903 && ! ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
1904 && (!info
->shared
|| info
->symbolic
)))
1906 /* The .plt entry is not needed when:
1907 a) Garbage collection has removed all references to the
1909 b) We know for certain the symbol is defined in this
1910 object, and it's not a weak definition, nor is the symbol
1911 used by a plabel relocation. Either this object is the
1912 application or we are doing a shared symbolic link. */
1914 /* As a special sop to the hppa ABI, we keep a .plt entry
1915 for functions in sections containing PIC code. */
1917 && h
->plt
.refcount
> 0
1918 && (h
->root
.type
== bfd_link_hash_defined
1919 || h
->root
.type
== bfd_link_hash_defweak
)
1920 && (h
->root
.u
.def
.section
->flags
& SEC_HAS_GOT_REF
) != 0)
1922 ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
= 1;
1926 h
->plt
.offset
= (bfd_vma
) -1;
1927 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1932 /* Make an entry in the .plt section. */
1934 h
->plt
.offset
= s
->_raw_size
;
1935 if (PLABEL_PLT_ENTRY_SIZE
!= PLT_ENTRY_SIZE
1936 && ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
1937 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1939 /* Add some extra space for the dynamic linker to use. */
1940 s
->_raw_size
+= PLABEL_PLT_ENTRY_SIZE
;
1943 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1945 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
)
1947 /* Make sure this symbol is output as a dynamic symbol. */
1948 if (h
->dynindx
== -1
1949 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1951 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1955 /* We also need to make an entry in the .rela.plt section. */
1956 s
= hplink
->srelplt
;
1957 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
1959 hplink
->need_plt_stub
= 1;
1964 /* If this is a weak symbol, and there is a real definition, the
1965 processor independent code will have arranged for us to see the
1966 real definition first, and we can just use the same value. */
1967 if (h
->weakdef
!= NULL
)
1969 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
1970 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
1971 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1972 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1976 /* This is a reference to a symbol defined by a dynamic object which
1977 is not a function. */
1979 /* If we are creating a shared library, we must presume that the
1980 only references to the symbol are via the global offset table.
1981 For such cases we need not do anything here; the relocations will
1982 be handled correctly by relocate_section. */
1986 /* If there are no references to this symbol that do not use the
1987 GOT, we don't need to generate a copy reloc. */
1988 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
1991 /* We must allocate the symbol in our .dynbss section, which will
1992 become part of the .bss section of the executable. There will be
1993 an entry for this symbol in the .dynsym section. The dynamic
1994 object will contain position independent code, so all references
1995 from the dynamic object to this symbol will go through the global
1996 offset table. The dynamic linker will use the .dynsym entry to
1997 determine the address it must put in the global offset table, so
1998 both the dynamic object and the regular object will refer to the
1999 same memory location for the variable. */
2001 s
= hplink
->sdynbss
;
2003 /* We must generate a COPY reloc to tell the dynamic linker to
2004 copy the initial value out of the dynamic object and into the
2005 runtime process image. We need to remember the offset into the
2006 .rela.bss section we are going to use. */
2007 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2011 srel
= hplink
->srelbss
;
2012 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
2013 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
2017 /* We need to figure out the alignment required for this symbol. I
2018 have no idea how other ELF linkers handle this. */
2019 unsigned int power_of_two
;
2021 power_of_two
= bfd_log2 (h
->size
);
2022 if (power_of_two
> 3)
2025 /* Apply the required alignment. */
2026 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
2027 (bfd_size_type
) (1 << power_of_two
));
2028 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
2030 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
2034 /* Define the symbol as being at this point in the section. */
2035 h
->root
.u
.def
.section
= s
;
2036 h
->root
.u
.def
.value
= s
->_raw_size
;
2038 /* Increment the section size to make room for the symbol. */
2039 s
->_raw_size
+= h
->size
;
2045 /* Called via elf_link_hash_traverse to create .plt entries for an
2046 application that uses statically linked PIC functions. Similar to
2047 the first part of elf32_hppa_adjust_dynamic_symbol. */
2050 hppa_handle_PIC_calls (h
, inf
)
2051 struct elf_link_hash_entry
*h
;
2054 struct bfd_link_info
*info
;
2056 struct elf32_hppa_link_hash_table
*hplink
;
2059 if (! (h
->plt
.refcount
> 0
2060 && (h
->root
.type
== bfd_link_hash_defined
2061 || h
->root
.type
== bfd_link_hash_defweak
)
2062 && (h
->root
.u
.def
.section
->flags
& SEC_HAS_GOT_REF
) != 0))
2064 h
->plt
.offset
= (bfd_vma
) -1;
2065 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2069 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2070 ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
= 1;
2072 info
= (struct bfd_link_info
*) inf
;
2073 hplink
= hppa_link_hash_table (info
);
2074 dynobj
= hplink
->root
.dynobj
;
2076 /* Make an entry in the .plt section. */
2078 h
->plt
.offset
= s
->_raw_size
;
2079 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2085 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
2086 || RELATIVE_DYNAMIC_RELOCS)
2087 /* This function is called via elf_link_hash_traverse to discard space
2088 we allocated for relocs that it turned out we didn't need. */
2091 hppa_discard_copies (h
, inf
)
2092 struct elf_link_hash_entry
*h
;
2095 struct elf32_hppa_dyn_reloc_entry
*s
;
2096 struct elf32_hppa_link_hash_entry
*eh
;
2097 struct bfd_link_info
*info
;
2099 eh
= (struct elf32_hppa_link_hash_entry
*) h
;
2100 info
= (struct bfd_link_info
*) inf
;
2102 #if ! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT
2103 /* Handle the stub reloc case. If we have a plt entry for the
2104 function, we won't be needing long branch stubs. s->count will
2105 only be zero for stub relocs, which provides a handy way of
2106 flagging these relocs, and means we need do nothing special for
2107 the forced local and symbolic link case. */
2108 if (eh
->stub_reloc_sec
!= NULL
2109 && eh
->elf
.plt
.offset
!= (bfd_vma
) -1)
2111 for (s
= eh
->reloc_entries
; s
!= NULL
; s
= s
->next
)
2113 s
->section
->_raw_size
-= sizeof (Elf32_External_Rela
);
2117 #if RELATIVE_DYNAMIC_RELOCS
2118 /* If a symbol has been forced local or we have found a regular
2119 definition for the symbolic link case, then we won't be needing
2121 if (eh
->elf
.dynindx
== -1
2122 || ((eh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
2123 && !is_absolute_reloc (r_type
)
2126 for (s
= eh
->reloc_entries
; s
!= NULL
; s
= s
->next
)
2127 s
->section
->_raw_size
-= s
->count
* sizeof (Elf32_External_Rela
);
2136 /* This function is called via elf_link_hash_traverse to force
2137 millicode symbols local so they do not end up as globals in the
2138 dynamic symbol table. We ought to be able to do this in
2139 adjust_dynamic_symbol, but our adjust_dynamic_symbol is not called
2140 for all dynamic symbols. Arguably, this is a bug in
2141 elf_adjust_dynamic_symbol. */
2144 clobber_millicode_symbols (h
, info
)
2145 struct elf_link_hash_entry
*h
;
2146 struct bfd_link_info
*info
;
2148 /* Note! We only want to remove these from the dynamic symbol
2149 table. Therefore we do not set ELF_LINK_FORCED_LOCAL. */
2150 if (h
->type
== STT_PARISC_MILLI
)
2151 elf32_hppa_hide_symbol(info
, h
);
2156 /* Set the sizes of the dynamic sections. */
2159 elf32_hppa_size_dynamic_sections (output_bfd
, info
)
2161 struct bfd_link_info
*info
;
2163 struct elf32_hppa_link_hash_table
*hplink
;
2169 hplink
= hppa_link_hash_table (info
);
2170 dynobj
= hplink
->root
.dynobj
;
2171 BFD_ASSERT (dynobj
!= NULL
);
2173 if (hplink
->root
.dynamic_sections_created
)
2175 const char *funcname
;
2178 /* Set the contents of the .interp section to the interpreter. */
2181 s
= bfd_get_section_by_name (dynobj
, ".interp");
2182 BFD_ASSERT (s
!= NULL
);
2183 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2184 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2187 /* Force millicode symbols local. */
2188 elf_link_hash_traverse (&hplink
->root
,
2189 clobber_millicode_symbols
,
2192 /* DT_INIT and DT_FINI need a .plt entry. Make sure they have
2194 funcname
= info
->init_function
;
2197 if (funcname
!= NULL
)
2199 struct elf_link_hash_entry
*h
;
2201 h
= elf_link_hash_lookup (&hplink
->root
,
2203 false, false, false);
2205 && (h
->elf_link_hash_flags
& (ELF_LINK_HASH_REF_REGULAR
2206 | ELF_LINK_HASH_DEF_REGULAR
)))
2208 if (h
->plt
.refcount
<= 0)
2210 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2212 /* Make an entry in the .plt section. We know
2213 the function doesn't have a plabel by the
2216 h
->plt
.offset
= s
->_raw_size
;
2217 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2219 /* Make sure this symbol is output as a dynamic
2221 if (h
->dynindx
== -1)
2223 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
2227 /* Make an entry for the reloc too. */
2228 s
= hplink
->srelplt
;
2229 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
2232 ((struct elf32_hppa_link_hash_entry
*) h
)->plt_abs
= 1;
2235 if (funcname
== info
->fini_function
)
2237 funcname
= info
->fini_function
;
2240 /* Set up .plt offsets for local plabels. */
2241 for (i
= info
->input_bfds
; i
; i
= i
->link_next
)
2243 bfd_signed_vma
*local_plt
;
2244 bfd_signed_vma
*end_local_plt
;
2245 bfd_size_type locsymcount
;
2246 Elf_Internal_Shdr
*symtab_hdr
;
2248 local_plt
= elf_local_got_refcounts (i
);
2252 symtab_hdr
= &elf_tdata (i
)->symtab_hdr
;
2253 locsymcount
= symtab_hdr
->sh_info
;
2254 local_plt
+= locsymcount
;
2255 end_local_plt
= local_plt
+ locsymcount
;
2257 for (; local_plt
< end_local_plt
; ++local_plt
)
2262 *local_plt
= s
->_raw_size
;
2263 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2265 hplink
->srelplt
->_raw_size
+= sizeof (Elf32_External_Rela
);
2268 *local_plt
= (bfd_vma
) -1;
2274 /* Run through the function symbols, looking for any that are
2275 PIC, and allocate space for the necessary .plt entries so
2276 that %r19 will be set up. */
2278 elf_link_hash_traverse (&hplink
->root
,
2279 hppa_handle_PIC_calls
,
2282 /* We may have created entries in the .rela.got section.
2283 However, if we are not creating the dynamic sections, we will
2284 not actually use these entries. Reset the size of .rela.got,
2285 which will cause it to get stripped from the output file
2287 hplink
->srelgot
->_raw_size
= 0;
2290 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
2291 || RELATIVE_DYNAMIC_RELOCS)
2292 /* If this is a -Bsymbolic shared link, then we need to discard all
2293 relocs against symbols defined in a regular object. We also need
2294 to lose relocs we've allocated for long branch stubs if we know
2295 we won't be generating a stub. */
2297 elf_link_hash_traverse (&hplink
->root
,
2298 hppa_discard_copies
,
2302 /* The check_relocs and adjust_dynamic_symbol entry points have
2303 determined the sizes of the various dynamic sections. Allocate
2307 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2311 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2314 /* It's OK to base decisions on the section name, because none
2315 of the dynobj section names depend upon the input files. */
2316 name
= bfd_get_section_name (dynobj
, s
);
2318 if (strncmp (name
, ".rela", 5) == 0)
2320 if (s
->_raw_size
!= 0)
2323 const char *outname
;
2325 /* Remember whether there are any reloc sections other
2327 if (strcmp (name
+5, ".plt") != 0)
2330 /* If this relocation section applies to a read only
2331 section, then we probably need a DT_TEXTREL entry. */
2332 outname
= bfd_get_section_name (output_bfd
,
2334 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
2336 && (target
->flags
& SEC_READONLY
) != 0
2337 && (target
->flags
& SEC_ALLOC
) != 0)
2340 /* We use the reloc_count field as a counter if we need
2341 to copy relocs into the output file. */
2345 else if (strcmp (name
, ".plt") == 0)
2347 if (hplink
->need_plt_stub
)
2349 /* Make space for the plt stub at the end of the .plt
2350 section. We want this stub right at the end, up
2351 against the .got section. */
2352 int gotalign
= bfd_section_alignment (dynobj
, hplink
->sgot
);
2353 int pltalign
= bfd_section_alignment (dynobj
, s
);
2356 if (gotalign
> pltalign
)
2357 bfd_set_section_alignment (dynobj
, s
, gotalign
);
2358 mask
= ((bfd_size_type
) 1 << gotalign
) - 1;
2359 s
->_raw_size
= (s
->_raw_size
+ sizeof (plt_stub
) + mask
) & ~mask
;
2362 else if (strcmp (name
, ".got") == 0)
2366 /* It's not one of our sections, so don't allocate space. */
2370 if (s
->_raw_size
== 0)
2372 /* If we don't need this section, strip it from the
2373 output file. This is mostly to handle .rela.bss and
2374 .rela.plt. We must create both sections in
2375 create_dynamic_sections, because they must be created
2376 before the linker maps input sections to output
2377 sections. The linker does that before
2378 adjust_dynamic_symbol is called, and it is that
2379 function which decides whether anything needs to go
2380 into these sections. */
2381 _bfd_strip_section_from_output (info
, s
);
2385 /* Allocate memory for the section contents. Zero it, because
2386 we may not fill in all the reloc sections. */
2387 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
2388 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
2392 if (hplink
->root
.dynamic_sections_created
)
2394 /* Like IA-64 and HPPA64, always create a DT_PLTGOT. It
2395 actually has nothing to do with the PLT, it is how we
2396 communicate the LTP value of a load module to the dynamic
2398 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
2401 /* Add some entries to the .dynamic section. We fill in the
2402 values later, in elf32_hppa_finish_dynamic_sections, but we
2403 must add the entries now so that we get the correct size for
2404 the .dynamic section. The DT_DEBUG entry is filled in by the
2405 dynamic linker and used by the debugger. */
2408 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
2412 if (hplink
->srelplt
->_raw_size
!= 0)
2414 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
2415 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
2416 || ! bfd_elf32_add_dynamic_entry (info
, DT_JMPREL
, 0))
2422 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELA
, 0)
2423 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELASZ
, 0)
2424 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELAENT
,
2425 sizeof (Elf32_External_Rela
)))
2431 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
2433 info
->flags
|= DF_TEXTREL
;
2441 /* External entry points for sizing and building linker stubs. */
2443 /* Determine and set the size of the stub section for a final link.
2445 The basic idea here is to examine all the relocations looking for
2446 PC-relative calls to a target that is unreachable with a "bl"
2450 elf32_hppa_size_stubs (output_bfd
, stub_bfd
, info
, multi_subspace
, group_size
,
2451 add_stub_section
, layout_sections_again
)
2454 struct bfd_link_info
*info
;
2455 boolean multi_subspace
;
2456 bfd_signed_vma group_size
;
2457 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
2458 void (*layout_sections_again
) PARAMS ((void));
2462 asection
**input_list
, **list
;
2463 Elf_Internal_Sym
*local_syms
, **all_local_syms
;
2464 unsigned int bfd_indx
, bfd_count
;
2465 int top_id
, top_index
;
2466 struct elf32_hppa_link_hash_table
*hplink
;
2467 bfd_size_type stub_group_size
;
2468 boolean stubs_always_before_branch
;
2469 boolean stub_changed
= 0;
2472 hplink
= hppa_link_hash_table (info
);
2474 /* Stash our params away. */
2475 hplink
->stub_bfd
= stub_bfd
;
2476 hplink
->multi_subspace
= multi_subspace
;
2477 hplink
->add_stub_section
= add_stub_section
;
2478 hplink
->layout_sections_again
= layout_sections_again
;
2479 stubs_always_before_branch
= group_size
< 0;
2481 stub_group_size
= -group_size
;
2483 stub_group_size
= group_size
;
2484 if (stub_group_size
== 1)
2486 /* Default values. */
2487 stub_group_size
= 8000000;
2488 if (hplink
->has_17bit_branch
|| hplink
->multi_subspace
)
2489 stub_group_size
= 250000;
2490 if (hplink
->has_12bit_branch
)
2491 stub_group_size
= 7812;
2494 /* Count the number of input BFDs and find the top input section id. */
2495 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
2497 input_bfd
= input_bfd
->link_next
)
2500 for (section
= input_bfd
->sections
;
2502 section
= section
->next
)
2504 if (top_id
< section
->id
)
2505 top_id
= section
->id
;
2510 = (struct map_stub
*) bfd_zmalloc (sizeof (struct map_stub
) * (top_id
+ 1));
2511 if (hplink
->stub_group
== NULL
)
2514 /* Make a list of input sections for each output section included in
2517 We can't use output_bfd->section_count here to find the top output
2518 section index as some sections may have been removed, and
2519 _bfd_strip_section_from_output doesn't renumber the indices. */
2520 for (section
= output_bfd
->sections
, top_index
= 0;
2522 section
= section
->next
)
2524 if (top_index
< section
->index
)
2525 top_index
= section
->index
;
2529 = (asection
**) bfd_malloc (sizeof (asection
*) * (top_index
+ 1));
2530 if (input_list
== NULL
)
2533 /* For sections we aren't interested in, mark their entries with a
2534 value we can check later. */
2535 list
= input_list
+ top_index
;
2537 *list
= bfd_abs_section_ptr
;
2538 while (list
-- != input_list
);
2540 for (section
= output_bfd
->sections
;
2542 section
= section
->next
)
2544 if ((section
->flags
& SEC_CODE
) != 0)
2545 input_list
[section
->index
] = NULL
;
2548 /* Now actually build the lists. */
2549 for (input_bfd
= info
->input_bfds
;
2551 input_bfd
= input_bfd
->link_next
)
2553 for (section
= input_bfd
->sections
;
2555 section
= section
->next
)
2557 if (section
->output_section
!= NULL
2558 && section
->output_section
->owner
== output_bfd
2559 && section
->output_section
->index
<= top_index
)
2561 list
= input_list
+ section
->output_section
->index
;
2562 if (*list
!= bfd_abs_section_ptr
)
2564 /* Steal the link_sec pointer for our list. */
2565 #define PREV_SEC(sec) (hplink->stub_group[(sec)->id].link_sec)
2566 /* This happens to make the list in reverse order,
2567 which is what we want. */
2568 PREV_SEC (section
) = *list
;
2575 /* See whether we can group stub sections together. Grouping stub
2576 sections may result in fewer stubs. More importantly, we need to
2577 put all .init* and .fini* stubs at the beginning of the .init or
2578 .fini output sections respectively, because glibc splits the
2579 _init and _fini functions into multiple parts. Putting a stub in
2580 the middle of a function is not a good idea. */
2581 list
= input_list
+ top_index
;
2584 asection
*tail
= *list
;
2585 if (tail
== bfd_abs_section_ptr
)
2587 while (tail
!= NULL
)
2591 bfd_size_type total
;
2594 if (tail
->_cooked_size
)
2595 total
= tail
->_cooked_size
;
2597 total
= tail
->_raw_size
;
2598 while ((prev
= PREV_SEC (curr
)) != NULL
2599 && ((total
+= curr
->output_offset
- prev
->output_offset
)
2603 /* OK, the size from the start of CURR to the end is less
2604 than 250000 bytes and thus can be handled by one stub
2605 section. (or the tail section is itself larger than
2606 250000 bytes, in which case we may be toast.)
2607 We should really be keeping track of the total size of
2608 stubs added here, as stubs contribute to the final output
2609 section size. That's a little tricky, and this way will
2610 only break if stubs added total more than 12144 bytes, or
2611 1518 long branch stubs. It seems unlikely for more than
2612 1518 different functions to be called, especially from
2613 code only 250000 bytes long. */
2616 prev
= PREV_SEC (tail
);
2617 /* Set up this stub group. */
2618 hplink
->stub_group
[tail
->id
].link_sec
= curr
;
2620 while (tail
!= curr
&& (tail
= prev
) != NULL
);
2622 /* But wait, there's more! Input sections up to 250000
2623 bytes before the stub section can be handled by it too. */
2624 if (!stubs_always_before_branch
)
2628 && ((total
+= tail
->output_offset
- prev
->output_offset
)
2632 prev
= PREV_SEC (tail
);
2633 hplink
->stub_group
[tail
->id
].link_sec
= curr
;
2639 while (list
-- != input_list
);
2643 /* We want to read in symbol extension records only once. To do this
2644 we need to read in the local symbols in parallel and save them for
2645 later use; so hold pointers to the local symbols in an array. */
2647 = (Elf_Internal_Sym
**) bfd_zmalloc (sizeof (Elf_Internal_Sym
*)
2649 if (all_local_syms
== NULL
)
2652 /* Walk over all the input BFDs, swapping in local symbols.
2653 If we are creating a shared library, create hash entries for the
2655 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
2657 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
2659 Elf_Internal_Shdr
*symtab_hdr
;
2660 Elf_Internal_Sym
*isym
;
2661 Elf32_External_Sym
*ext_syms
, *esym
, *end_sy
;
2663 /* We'll need the symbol table in a second. */
2664 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2665 if (symtab_hdr
->sh_info
== 0)
2668 /* We need an array of the local symbols attached to the input bfd.
2669 Unfortunately, we're going to have to read & swap them in. */
2670 local_syms
= (Elf_Internal_Sym
*)
2671 bfd_malloc (symtab_hdr
->sh_info
* sizeof (Elf_Internal_Sym
));
2672 if (local_syms
== NULL
)
2674 goto error_ret_free_local
;
2676 all_local_syms
[bfd_indx
] = local_syms
;
2677 ext_syms
= (Elf32_External_Sym
*)
2678 bfd_malloc (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
));
2679 if (ext_syms
== NULL
)
2681 goto error_ret_free_local
;
2684 if (bfd_seek (input_bfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
2685 || (bfd_read (ext_syms
, 1,
2686 (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
)),
2688 != (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
))))
2691 goto error_ret_free_local
;
2694 /* Swap the local symbols in. */
2697 for (end_sy
= esym
+ symtab_hdr
->sh_info
; esym
< end_sy
; esym
++, isym
++)
2698 bfd_elf32_swap_symbol_in (input_bfd
, esym
, isym
);
2700 /* Now we can free the external symbols. */
2703 #if ! LONG_BRANCH_PIC_IN_SHLIB
2704 /* If this is a shared link, find all the stub reloc sections. */
2706 for (section
= input_bfd
->sections
;
2708 section
= section
->next
)
2711 asection
*reloc_sec
;
2713 name
= bfd_malloc (strlen (section
->name
)
2714 + sizeof STUB_SUFFIX
2718 sprintf (name
, ".rela%s%s", section
->name
, STUB_SUFFIX
);
2719 reloc_sec
= bfd_get_section_by_name (hplink
->root
.dynobj
, name
);
2720 hplink
->stub_group
[section
->id
].reloc_sec
= reloc_sec
;
2725 if (info
->shared
&& hplink
->multi_subspace
)
2727 struct elf_link_hash_entry
**sym_hashes
;
2728 struct elf_link_hash_entry
**end_hashes
;
2729 unsigned int symcount
;
2731 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
2732 - symtab_hdr
->sh_info
);
2733 sym_hashes
= elf_sym_hashes (input_bfd
);
2734 end_hashes
= sym_hashes
+ symcount
;
2736 /* Look through the global syms for functions; We need to
2737 build export stubs for all globally visible functions. */
2738 for (; sym_hashes
< end_hashes
; sym_hashes
++)
2740 struct elf32_hppa_link_hash_entry
*hash
;
2742 hash
= (struct elf32_hppa_link_hash_entry
*) *sym_hashes
;
2744 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
2745 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
2746 hash
= ((struct elf32_hppa_link_hash_entry
*)
2747 hash
->elf
.root
.u
.i
.link
);
2749 /* At this point in the link, undefined syms have been
2750 resolved, so we need to check that the symbol was
2751 defined in this BFD. */
2752 if ((hash
->elf
.root
.type
== bfd_link_hash_defined
2753 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
2754 && hash
->elf
.type
== STT_FUNC
2755 && hash
->elf
.root
.u
.def
.section
->output_section
!= NULL
2756 && (hash
->elf
.root
.u
.def
.section
->output_section
->owner
2758 && hash
->elf
.root
.u
.def
.section
->owner
== input_bfd
2759 && (hash
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
2760 && !(hash
->elf
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
2761 && ELF_ST_VISIBILITY (hash
->elf
.other
) == STV_DEFAULT
)
2764 const char *stub_name
;
2765 struct elf32_hppa_stub_hash_entry
*stub_entry
;
2767 sec
= hash
->elf
.root
.u
.def
.section
;
2768 stub_name
= hash
->elf
.root
.root
.string
;
2769 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
,
2772 if (stub_entry
== NULL
)
2774 stub_entry
= hppa_add_stub (stub_name
, sec
, hplink
);
2776 goto error_ret_free_local
;
2778 stub_entry
->target_value
= hash
->elf
.root
.u
.def
.value
;
2779 stub_entry
->target_section
= hash
->elf
.root
.u
.def
.section
;
2780 stub_entry
->stub_type
= hppa_stub_export
;
2781 stub_entry
->h
= hash
;
2786 (*_bfd_error_handler
) (_("%s: duplicate export stub %s"),
2787 bfd_get_filename (input_bfd
),
2799 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
2801 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
2803 Elf_Internal_Shdr
*symtab_hdr
;
2805 /* We'll need the symbol table in a second. */
2806 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2807 if (symtab_hdr
->sh_info
== 0)
2810 local_syms
= all_local_syms
[bfd_indx
];
2812 /* Walk over each section attached to the input bfd. */
2813 for (section
= input_bfd
->sections
;
2815 section
= section
->next
)
2817 Elf_Internal_Shdr
*input_rel_hdr
;
2818 Elf32_External_Rela
*external_relocs
, *erelaend
, *erela
;
2819 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
2821 /* If there aren't any relocs, then there's nothing more
2823 if ((section
->flags
& SEC_RELOC
) == 0
2824 || section
->reloc_count
== 0)
2827 /* If this section is a link-once section that will be
2828 discarded, then don't create any stubs. */
2829 if (section
->output_section
== NULL
2830 || section
->output_section
->owner
!= output_bfd
)
2833 /* Allocate space for the external relocations. */
2835 = ((Elf32_External_Rela
*)
2836 bfd_malloc (section
->reloc_count
2837 * sizeof (Elf32_External_Rela
)));
2838 if (external_relocs
== NULL
)
2840 goto error_ret_free_local
;
2843 /* Likewise for the internal relocations. */
2844 internal_relocs
= ((Elf_Internal_Rela
*)
2845 bfd_malloc (section
->reloc_count
2846 * sizeof (Elf_Internal_Rela
)));
2847 if (internal_relocs
== NULL
)
2849 free (external_relocs
);
2850 goto error_ret_free_local
;
2853 /* Read in the external relocs. */
2854 input_rel_hdr
= &elf_section_data (section
)->rel_hdr
;
2855 if (bfd_seek (input_bfd
, input_rel_hdr
->sh_offset
, SEEK_SET
) != 0
2856 || bfd_read (external_relocs
, 1,
2857 input_rel_hdr
->sh_size
,
2858 input_bfd
) != input_rel_hdr
->sh_size
)
2860 free (external_relocs
);
2861 error_ret_free_internal
:
2862 free (internal_relocs
);
2863 goto error_ret_free_local
;
2866 /* Swap in the relocs. */
2867 erela
= external_relocs
;
2868 erelaend
= erela
+ section
->reloc_count
;
2869 irela
= internal_relocs
;
2870 for (; erela
< erelaend
; erela
++, irela
++)
2871 bfd_elf32_swap_reloca_in (input_bfd
, erela
, irela
);
2873 /* We're done with the external relocs, free them. */
2874 free (external_relocs
);
2876 /* Now examine each relocation. */
2877 irela
= internal_relocs
;
2878 irelaend
= irela
+ section
->reloc_count
;
2879 for (; irela
< irelaend
; irela
++)
2881 unsigned int r_type
, r_indx
;
2882 enum elf32_hppa_stub_type stub_type
;
2883 struct elf32_hppa_stub_hash_entry
*stub_entry
;
2886 bfd_vma destination
;
2887 struct elf32_hppa_link_hash_entry
*hash
;
2889 const asection
*id_sec
;
2891 r_type
= ELF32_R_TYPE (irela
->r_info
);
2892 r_indx
= ELF32_R_SYM (irela
->r_info
);
2894 if (r_type
>= (unsigned int) R_PARISC_UNIMPLEMENTED
)
2896 bfd_set_error (bfd_error_bad_value
);
2897 goto error_ret_free_internal
;
2900 /* Only look for stubs on call instructions. */
2901 if (r_type
!= (unsigned int) R_PARISC_PCREL12F
2902 && r_type
!= (unsigned int) R_PARISC_PCREL17F
2903 && r_type
!= (unsigned int) R_PARISC_PCREL22F
)
2906 /* Now determine the call target, its name, value,
2912 if (r_indx
< symtab_hdr
->sh_info
)
2914 /* It's a local symbol. */
2915 Elf_Internal_Sym
*sym
;
2916 Elf_Internal_Shdr
*hdr
;
2918 sym
= local_syms
+ r_indx
;
2919 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
2920 sym_sec
= hdr
->bfd_section
;
2921 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
2922 sym_value
= sym
->st_value
;
2923 destination
= (sym_value
+ irela
->r_addend
2924 + sym_sec
->output_offset
2925 + sym_sec
->output_section
->vma
);
2929 /* It's an external symbol. */
2932 e_indx
= r_indx
- symtab_hdr
->sh_info
;
2933 hash
= ((struct elf32_hppa_link_hash_entry
*)
2934 elf_sym_hashes (input_bfd
)[e_indx
]);
2936 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
2937 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
2938 hash
= ((struct elf32_hppa_link_hash_entry
*)
2939 hash
->elf
.root
.u
.i
.link
);
2941 if (hash
->elf
.root
.type
== bfd_link_hash_defined
2942 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
2944 sym_sec
= hash
->elf
.root
.u
.def
.section
;
2945 sym_value
= hash
->elf
.root
.u
.def
.value
;
2946 if (sym_sec
->output_section
!= NULL
)
2947 destination
= (sym_value
+ irela
->r_addend
2948 + sym_sec
->output_offset
2949 + sym_sec
->output_section
->vma
);
2951 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
)
2956 else if (hash
->elf
.root
.type
== bfd_link_hash_undefined
)
2959 && !info
->no_undefined
2960 && (ELF_ST_VISIBILITY (hash
->elf
.other
)
2966 bfd_set_error (bfd_error_bad_value
);
2967 goto error_ret_free_internal
;
2971 /* Determine what (if any) linker stub is needed. */
2972 stub_type
= hppa_type_of_stub (section
, irela
, hash
,
2974 if (stub_type
== hppa_stub_none
)
2977 /* Support for grouping stub sections. */
2978 id_sec
= hplink
->stub_group
[section
->id
].link_sec
;
2980 /* Get the name of this stub. */
2981 stub_name
= hppa_stub_name (id_sec
, sym_sec
, hash
, irela
);
2983 goto error_ret_free_internal
;
2985 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
,
2988 if (stub_entry
!= NULL
)
2990 /* The proper stub has already been created. */
2995 stub_entry
= hppa_add_stub (stub_name
, section
, hplink
);
2996 if (stub_entry
== NULL
)
2999 goto error_ret_free_local
;
3002 stub_entry
->target_value
= sym_value
;
3003 stub_entry
->target_section
= sym_sec
;
3004 stub_entry
->stub_type
= stub_type
;
3007 if (stub_type
== hppa_stub_import
)
3008 stub_entry
->stub_type
= hppa_stub_import_shared
;
3009 else if (stub_type
== hppa_stub_long_branch
3010 && (LONG_BRANCH_PIC_IN_SHLIB
|| hash
== NULL
))
3011 stub_entry
->stub_type
= hppa_stub_long_branch_shared
;
3013 stub_entry
->h
= hash
;
3017 /* We're done with the internal relocs, free them. */
3018 free (internal_relocs
);
3025 /* OK, we've added some stubs. Find out the new size of the
3027 for (stub_sec
= hplink
->stub_bfd
->sections
;
3029 stub_sec
= stub_sec
->next
)
3031 stub_sec
->_raw_size
= 0;
3032 stub_sec
->_cooked_size
= 0;
3034 #if ! LONG_BRANCH_PIC_IN_SHLIB
3038 for (i
= top_id
; i
>= 0; --i
)
3040 /* This will probably hit the same section many times.. */
3041 stub_sec
= hplink
->stub_group
[i
].reloc_sec
;
3042 if (stub_sec
!= NULL
)
3044 stub_sec
->_raw_size
= 0;
3045 stub_sec
->_cooked_size
= 0;
3051 bfd_hash_traverse (&hplink
->stub_hash_table
,
3055 /* Ask the linker to do its stuff. */
3056 (*hplink
->layout_sections_again
) ();
3062 error_ret_free_local
:
3063 while (bfd_count
-- > 0)
3064 if (all_local_syms
[bfd_count
])
3065 free (all_local_syms
[bfd_count
]);
3066 free (all_local_syms
);
3072 /* For a final link, this function is called after we have sized the
3073 stubs to provide a value for __gp. */
3076 elf32_hppa_set_gp (abfd
, info
)
3078 struct bfd_link_info
*info
;
3080 struct elf32_hppa_link_hash_table
*hplink
;
3081 struct elf_link_hash_entry
*h
;
3085 hplink
= hppa_link_hash_table (info
);
3086 h
= elf_link_hash_lookup (&hplink
->root
, "$global$",
3087 false, false, false);
3089 if (h
!= NULL
&& h
->root
.type
== bfd_link_hash_defined
)
3091 gp_val
= h
->root
.u
.def
.value
;
3092 sec
= h
->root
.u
.def
.section
;
3096 /* Choose to point our LTP at, in this order, one of .plt, .got,
3097 or .data, if these sections exist. In the case of choosing
3098 .plt try to make the LTP ideal for addressing anywhere in the
3099 .plt or .got with a 14 bit signed offset. Typically, the end
3100 of the .plt is the start of the .got, so choose .plt + 0x2000
3101 if either the .plt or .got is larger than 0x2000. If both
3102 the .plt and .got are smaller than 0x2000, choose the end of
3103 the .plt section. */
3108 gp_val
= sec
->_raw_size
;
3110 || (hplink
->sgot
&& hplink
->sgot
->_raw_size
> 0x2000))
3121 /* We know we don't have a .plt. If .got is large,
3123 if (sec
->_raw_size
> 0x2000)
3128 /* No .plt or .got. Who cares what the LTP is? */
3129 sec
= bfd_get_section_by_name (abfd
, ".data");
3135 gp_val
+= sec
->output_section
->vma
+ sec
->output_offset
;
3137 elf_gp (abfd
) = gp_val
;
3142 /* Build all the stubs associated with the current output file. The
3143 stubs are kept in a hash table attached to the main linker hash
3144 table. We also set up the .plt entries for statically linked PIC
3145 functions here. This function is called via hppaelf_finish in the
3149 elf32_hppa_build_stubs (info
)
3150 struct bfd_link_info
*info
;
3153 struct bfd_hash_table
*table
;
3154 struct elf32_hppa_link_hash_table
*hplink
;
3156 hplink
= hppa_link_hash_table (info
);
3158 for (stub_sec
= hplink
->stub_bfd
->sections
;
3160 stub_sec
= stub_sec
->next
)
3164 /* Allocate memory to hold the linker stubs. */
3165 size
= stub_sec
->_raw_size
;
3166 stub_sec
->contents
= (unsigned char *) bfd_zalloc (hplink
->stub_bfd
,
3168 if (stub_sec
->contents
== NULL
&& size
!= 0)
3170 stub_sec
->_raw_size
= 0;
3173 /* Build the stubs as directed by the stub hash table. */
3174 table
= &hplink
->stub_hash_table
;
3175 bfd_hash_traverse (table
, hppa_build_one_stub
, info
);
3181 /* Perform a relocation as part of a final link. */
3183 static bfd_reloc_status_type
3184 final_link_relocate (input_section
, contents
, rel
, value
, hplink
, sym_sec
, h
)
3185 asection
*input_section
;
3187 const Elf_Internal_Rela
*rel
;
3189 struct elf32_hppa_link_hash_table
*hplink
;
3191 struct elf32_hppa_link_hash_entry
*h
;
3194 unsigned int r_type
= ELF32_R_TYPE (rel
->r_info
);
3195 reloc_howto_type
*howto
= elf_hppa_howto_table
+ r_type
;
3196 int r_format
= howto
->bitsize
;
3197 enum hppa_reloc_field_selector_type_alt r_field
;
3198 bfd
*input_bfd
= input_section
->owner
;
3199 bfd_vma offset
= rel
->r_offset
;
3200 bfd_vma max_branch_offset
= 0;
3201 bfd_byte
*hit_data
= contents
+ offset
;
3202 bfd_signed_vma addend
= rel
->r_addend
;
3204 struct elf32_hppa_stub_hash_entry
*stub_entry
= NULL
;
3207 if (r_type
== R_PARISC_NONE
)
3208 return bfd_reloc_ok
;
3210 insn
= bfd_get_32 (input_bfd
, hit_data
);
3212 /* Find out where we are and where we're going. */
3213 location
= (offset
+
3214 input_section
->output_offset
+
3215 input_section
->output_section
->vma
);
3219 case R_PARISC_PCREL12F
:
3220 case R_PARISC_PCREL17F
:
3221 case R_PARISC_PCREL22F
:
3222 /* If this is a call to a function defined in another dynamic
3223 library, or if it is a call to a PIC function in the same
3224 object, or if this is a shared link and it is a call to a
3225 weak symbol which may or may not be in the same object, then
3226 find the import stub in the stub hash. */
3228 || sym_sec
->output_section
== NULL
3231 || (h
->elf
.root
.type
== bfd_link_hash_defweak
3232 && h
->elf
.dynindx
!= -1
3233 && h
->elf
.plt
.offset
!= (bfd_vma
) -1))))
3235 stub_entry
= hppa_get_stub_entry (input_section
, sym_sec
,
3237 if (stub_entry
!= NULL
)
3239 value
= (stub_entry
->stub_offset
3240 + stub_entry
->stub_sec
->output_offset
3241 + stub_entry
->stub_sec
->output_section
->vma
);
3244 else if (sym_sec
== NULL
&& h
!= NULL
3245 && h
->elf
.root
.type
== bfd_link_hash_undefweak
)
3247 /* It's OK if undefined weak. Make undefined weak
3248 branches go nowhere. */
3253 return bfd_reloc_notsupported
;
3257 case R_PARISC_PCREL21L
:
3258 case R_PARISC_PCREL17C
:
3259 case R_PARISC_PCREL17R
:
3260 case R_PARISC_PCREL14R
:
3261 case R_PARISC_PCREL14F
:
3262 /* Make it a pc relative offset. */
3267 case R_PARISC_DPREL21L
:
3268 case R_PARISC_DPREL14R
:
3269 case R_PARISC_DPREL14F
:
3270 /* For all the DP relative relocations, we need to examine the symbol's
3271 section. If it's a code section, then "data pointer relative" makes
3272 no sense. In that case we don't adjust the "value", and for 21 bit
3273 addil instructions, we change the source addend register from %dp to
3274 %r0. This situation commonly arises when a variable's "constness"
3275 is declared differently from the way the variable is defined. For
3276 instance: "extern int foo" with foo defined as "const int foo". */
3277 if (sym_sec
== NULL
)
3279 if ((sym_sec
->flags
& SEC_CODE
) != 0)
3281 if ((insn
& ((0x3f << 26) | (0x1f << 21)))
3282 == (((int) OP_ADDIL
<< 26) | (27 << 21)))
3284 insn
&= ~ (0x1f << 21);
3285 #if 1 /* debug them. */
3286 (*_bfd_error_handler
)
3287 (_("%s(%s+0x%lx): fixing %s"),
3288 bfd_get_filename (input_bfd
),
3289 input_section
->name
,
3290 (long) rel
->r_offset
,
3294 /* Now try to make things easy for the dynamic linker. */
3300 case R_PARISC_DLTIND21L
:
3301 case R_PARISC_DLTIND14R
:
3302 case R_PARISC_DLTIND14F
:
3303 value
-= elf_gp (input_section
->output_section
->owner
);
3312 case R_PARISC_DIR32
:
3313 case R_PARISC_DIR14F
:
3314 case R_PARISC_DIR17F
:
3315 case R_PARISC_PCREL17C
:
3316 case R_PARISC_PCREL14F
:
3317 case R_PARISC_DPREL14F
:
3318 case R_PARISC_PLABEL32
:
3319 case R_PARISC_DLTIND14F
:
3320 case R_PARISC_SEGBASE
:
3321 case R_PARISC_SEGREL32
:
3325 case R_PARISC_DIR21L
:
3326 case R_PARISC_PCREL21L
:
3327 case R_PARISC_DPREL21L
:
3328 case R_PARISC_PLABEL21L
:
3329 case R_PARISC_DLTIND21L
:
3333 case R_PARISC_DIR17R
:
3334 case R_PARISC_PCREL17R
:
3335 case R_PARISC_DIR14R
:
3336 case R_PARISC_PCREL14R
:
3337 case R_PARISC_DPREL14R
:
3338 case R_PARISC_PLABEL14R
:
3339 case R_PARISC_DLTIND14R
:
3343 case R_PARISC_PCREL12F
:
3344 case R_PARISC_PCREL17F
:
3345 case R_PARISC_PCREL22F
:
3348 if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
3350 max_branch_offset
= (1 << (17-1)) << 2;
3352 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
3354 max_branch_offset
= (1 << (12-1)) << 2;
3358 max_branch_offset
= (1 << (22-1)) << 2;
3361 /* sym_sec is NULL on undefined weak syms or when shared on
3362 undefined syms. We've already checked for a stub for the
3363 shared undefined case. */
3364 if (sym_sec
== NULL
)
3367 /* If the branch is out of reach, then redirect the
3368 call to the local stub for this function. */
3369 if (value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3371 stub_entry
= hppa_get_stub_entry (input_section
, sym_sec
,
3373 if (stub_entry
== NULL
)
3374 return bfd_reloc_notsupported
;
3376 /* Munge up the value and addend so that we call the stub
3377 rather than the procedure directly. */
3378 value
= (stub_entry
->stub_offset
3379 + stub_entry
->stub_sec
->output_offset
3380 + stub_entry
->stub_sec
->output_section
->vma
3386 /* Something we don't know how to handle. */
3388 return bfd_reloc_notsupported
;
3391 /* Make sure we can reach the stub. */
3392 if (max_branch_offset
!= 0
3393 && value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3395 (*_bfd_error_handler
)
3396 (_("%s(%s+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
3397 bfd_get_filename (input_bfd
),
3398 input_section
->name
,
3399 (long) rel
->r_offset
,
3400 stub_entry
->root
.string
);
3401 return bfd_reloc_notsupported
;
3404 val
= hppa_field_adjust (value
, addend
, r_field
);
3408 case R_PARISC_PCREL12F
:
3409 case R_PARISC_PCREL17C
:
3410 case R_PARISC_PCREL17F
:
3411 case R_PARISC_PCREL17R
:
3412 case R_PARISC_PCREL22F
:
3413 case R_PARISC_DIR17F
:
3414 case R_PARISC_DIR17R
:
3415 /* This is a branch. Divide the offset by four.
3416 Note that we need to decide whether it's a branch or
3417 otherwise by inspecting the reloc. Inspecting insn won't
3418 work as insn might be from a .word directive. */
3426 insn
= hppa_rebuild_insn (insn
, val
, r_format
);
3428 /* Update the instruction word. */
3429 bfd_put_32 (input_bfd
, (bfd_vma
) insn
, hit_data
);
3430 return bfd_reloc_ok
;
3434 /* Relocate an HPPA ELF section. */
3437 elf32_hppa_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
3438 contents
, relocs
, local_syms
, local_sections
)
3440 struct bfd_link_info
*info
;
3442 asection
*input_section
;
3444 Elf_Internal_Rela
*relocs
;
3445 Elf_Internal_Sym
*local_syms
;
3446 asection
**local_sections
;
3449 bfd_vma
*local_got_offsets
;
3450 struct elf32_hppa_link_hash_table
*hplink
;
3451 Elf_Internal_Shdr
*symtab_hdr
;
3452 Elf_Internal_Rela
*rel
;
3453 Elf_Internal_Rela
*relend
;
3456 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3458 hplink
= hppa_link_hash_table (info
);
3459 dynobj
= hplink
->root
.dynobj
;
3460 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3464 relend
= relocs
+ input_section
->reloc_count
;
3465 for (; rel
< relend
; rel
++)
3467 unsigned int r_type
;
3468 reloc_howto_type
*howto
;
3469 unsigned int r_symndx
;
3470 struct elf32_hppa_link_hash_entry
*h
;
3471 Elf_Internal_Sym
*sym
;
3474 bfd_reloc_status_type r
;
3475 const char *sym_name
;
3478 r_type
= ELF32_R_TYPE (rel
->r_info
);
3479 if (r_type
>= (unsigned int) R_PARISC_UNIMPLEMENTED
)
3481 bfd_set_error (bfd_error_bad_value
);
3484 if (r_type
== (unsigned int) R_PARISC_GNU_VTENTRY
3485 || r_type
== (unsigned int) R_PARISC_GNU_VTINHERIT
)
3488 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3490 if (info
->relocateable
)
3492 /* This is a relocateable link. We don't have to change
3493 anything, unless the reloc is against a section symbol,
3494 in which case we have to adjust according to where the
3495 section symbol winds up in the output section. */
3496 if (r_symndx
< symtab_hdr
->sh_info
)
3498 sym
= local_syms
+ r_symndx
;
3499 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
3501 sym_sec
= local_sections
[r_symndx
];
3502 rel
->r_addend
+= sym_sec
->output_offset
;
3508 /* This is a final link. */
3512 if (r_symndx
< symtab_hdr
->sh_info
)
3514 /* This is a local symbol, h defaults to NULL. */
3515 sym
= local_syms
+ r_symndx
;
3516 sym_sec
= local_sections
[r_symndx
];
3517 relocation
= ((ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
3518 ? 0 : sym
->st_value
)
3519 + sym_sec
->output_offset
3520 + sym_sec
->output_section
->vma
);
3526 /* It's a global; Find its entry in the link hash. */
3527 indx
= r_symndx
- symtab_hdr
->sh_info
;
3528 h
= ((struct elf32_hppa_link_hash_entry
*)
3529 elf_sym_hashes (input_bfd
)[indx
]);
3530 while (h
->elf
.root
.type
== bfd_link_hash_indirect
3531 || h
->elf
.root
.type
== bfd_link_hash_warning
)
3532 h
= (struct elf32_hppa_link_hash_entry
*) h
->elf
.root
.u
.i
.link
;
3535 if (h
->elf
.root
.type
== bfd_link_hash_defined
3536 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
3538 sym_sec
= h
->elf
.root
.u
.def
.section
;
3539 /* If sym_sec->output_section is NULL, then it's a
3540 symbol defined in a shared library. */
3541 if (sym_sec
->output_section
!= NULL
)
3542 relocation
= (h
->elf
.root
.u
.def
.value
3543 + sym_sec
->output_offset
3544 + sym_sec
->output_section
->vma
);
3546 else if (h
->elf
.root
.type
== bfd_link_hash_undefweak
)
3548 else if (info
->shared
&& !info
->no_undefined
3549 && ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
)
3552 if (!((*info
->callbacks
->undefined_symbol
)
3553 (info
, h
->elf
.root
.root
.string
, input_bfd
,
3554 input_section
, rel
->r_offset
, false)))
3559 if (!((*info
->callbacks
->undefined_symbol
)
3560 (info
, h
->elf
.root
.root
.string
, input_bfd
,
3561 input_section
, rel
->r_offset
, true)))
3566 /* Do any required modifications to the relocation value, and
3567 determine what types of dynamic info we need to output, if
3572 case R_PARISC_DLTIND14F
:
3573 case R_PARISC_DLTIND14R
:
3574 case R_PARISC_DLTIND21L
:
3575 /* Relocation is to the entry for this symbol in the global
3581 off
= h
->elf
.got
.offset
;
3582 BFD_ASSERT (off
!= (bfd_vma
) -1);
3584 if (! hplink
->root
.dynamic_sections_created
3586 && (info
->symbolic
|| h
->elf
.dynindx
== -1)
3587 && (h
->elf
.elf_link_hash_flags
3588 & ELF_LINK_HASH_DEF_REGULAR
) != 0))
3590 /* This is actually a static link, or it is a
3591 -Bsymbolic link and the symbol is defined
3592 locally, or the symbol was forced to be local
3593 because of a version file. We must initialize
3594 this entry in the global offset table. Since the
3595 offset must always be a multiple of 4, we use the
3596 least significant bit to record whether we have
3597 initialized it already.
3599 When doing a dynamic link, we create a .rela.got
3600 relocation entry to initialize the value. This
3601 is done in the finish_dynamic_symbol routine. */
3606 bfd_put_32 (output_bfd
, relocation
,
3607 hplink
->sgot
->contents
+ off
);
3608 h
->elf
.got
.offset
|= 1;
3616 /* Local symbol case. */
3619 BFD_ASSERT (local_got_offsets
!= NULL
3620 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
3622 off
= local_got_offsets
[r_symndx
];
3624 /* The offset must always be a multiple of 4. We use
3625 the least significant bit to record whether we have
3626 already generated the necessary reloc. */
3631 bfd_put_32 (output_bfd
, relocation
,
3632 hplink
->sgot
->contents
+ off
);
3636 /* Output a dynamic *ABS* relocation for this
3637 GOT entry. In this case it is relative to
3638 the base of the object because the symbol
3640 Elf_Internal_Rela outrel
;
3641 asection
*srelgot
= hplink
->srelgot
;
3643 outrel
.r_offset
= (off
3644 + hplink
->sgot
->output_offset
3645 + hplink
->sgot
->output_section
->vma
);
3646 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_DIR32
);
3647 outrel
.r_addend
= relocation
;
3648 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3649 ((Elf32_External_Rela
*)
3651 + srelgot
->reloc_count
));
3652 ++srelgot
->reloc_count
;
3655 local_got_offsets
[r_symndx
] |= 1;
3661 /* Add the base of the GOT to the relocation value. */
3662 relocation
+= (hplink
->sgot
->output_offset
3663 + hplink
->sgot
->output_section
->vma
);
3666 case R_PARISC_PLABEL14R
:
3667 case R_PARISC_PLABEL21L
:
3668 case R_PARISC_PLABEL32
:
3669 if (hplink
->root
.dynamic_sections_created
)
3673 /* If we have a global symbol with a PLT slot, then
3674 redirect this relocation to it. */
3677 off
= h
->elf
.plt
.offset
;
3683 indx
= r_symndx
+ symtab_hdr
->sh_info
;
3684 off
= local_got_offsets
[indx
];
3686 /* As for the local .got entry case, we use the last
3687 bit to record whether we've already initialised
3688 this local .plt entry. */
3693 bfd_put_32 (output_bfd
,
3695 hplink
->splt
->contents
+ off
);
3696 bfd_put_32 (output_bfd
,
3697 elf_gp (hplink
->splt
->output_section
->owner
),
3698 hplink
->splt
->contents
+ off
+ 4);
3702 /* Output a dynamic IPLT relocation for this
3704 Elf_Internal_Rela outrel
;
3705 asection
*srelplt
= hplink
->srelplt
;
3707 outrel
.r_offset
= (off
3708 + hplink
->splt
->output_offset
3709 + hplink
->splt
->output_section
->vma
);
3710 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_IPLT
);
3711 outrel
.r_addend
= relocation
;
3712 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3713 ((Elf32_External_Rela
*)
3715 + srelplt
->reloc_count
));
3716 ++srelplt
->reloc_count
;
3719 local_got_offsets
[indx
] |= 1;
3723 BFD_ASSERT (off
< (bfd_vma
) -2);
3725 /* PLABELs contain function pointers. Relocation is to
3726 the entry for the function in the .plt. The magic +2
3727 offset signals to $$dyncall that the function pointer
3728 is in the .plt and thus has a gp pointer too.
3729 Exception: Undefined PLABELs should have a value of
3732 || (h
->elf
.root
.type
!= bfd_link_hash_undefweak
3733 && h
->elf
.root
.type
!= bfd_link_hash_undefined
))
3736 + hplink
->splt
->output_offset
3737 + hplink
->splt
->output_section
->vma
3742 /* Fall through and possibly emit a dynamic relocation. */
3744 case R_PARISC_DIR17F
:
3745 case R_PARISC_DIR17R
:
3746 case R_PARISC_DIR14F
:
3747 case R_PARISC_DIR14R
:
3748 case R_PARISC_DIR21L
:
3749 case R_PARISC_DPREL14F
:
3750 case R_PARISC_DPREL14R
:
3751 case R_PARISC_DPREL21L
:
3752 case R_PARISC_DIR32
:
3753 /* The reloc types handled here and this conditional
3754 expression must match the code in check_relocs and
3755 hppa_discard_copies. ie. We need exactly the same
3756 condition as in check_relocs, with some extra conditions
3757 (dynindx test in this case) to cater for relocs removed
3758 by hppa_discard_copies. */
3759 if ((input_section
->flags
& SEC_ALLOC
) != 0
3761 #if RELATIVE_DYNAMIC_RELOCS
3762 && (is_absolute_reloc (r_type
)
3763 || ((!info
->symbolic
3765 && ((h
->elf
.elf_link_hash_flags
3766 & ELF_LINK_HASH_DEF_REGULAR
) == 0
3767 || h
->elf
.root
.type
== bfd_link_hash_defweak
)))
3768 && (h
== NULL
|| h
->elf
.dynindx
!= -1)))
3772 Elf_Internal_Rela outrel
;
3775 /* When generating a shared object, these relocations
3776 are copied into the output file to be resolved at run
3783 name
= (bfd_elf_string_from_elf_section
3785 elf_elfheader (input_bfd
)->e_shstrndx
,
3786 elf_section_data (input_section
)->rel_hdr
.sh_name
));
3789 sreloc
= bfd_get_section_by_name (dynobj
, name
);
3790 BFD_ASSERT (sreloc
!= NULL
);
3793 outrel
.r_offset
= rel
->r_offset
;
3794 outrel
.r_addend
= rel
->r_addend
;
3796 if (elf_section_data (input_section
)->stab_info
!= NULL
)
3800 off
= (_bfd_stab_section_offset
3801 (output_bfd
, &hplink
->root
.stab_info
,
3803 &elf_section_data (input_section
)->stab_info
,
3805 if (off
== (bfd_vma
) -1)
3807 outrel
.r_offset
= off
;
3810 outrel
.r_offset
+= (input_section
->output_offset
3811 + input_section
->output_section
->vma
);
3815 memset (&outrel
, 0, sizeof (outrel
));
3818 && h
->elf
.dynindx
!= -1
3821 || (h
->elf
.elf_link_hash_flags
3822 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
3824 outrel
.r_info
= ELF32_R_INFO (h
->elf
.dynindx
, r_type
);
3826 else /* It's a local symbol, or one marked to become local. */
3830 /* Add the absolute offset of the symbol. */
3831 outrel
.r_addend
+= relocation
;
3833 /* Global plabels need to be processed by the
3834 dynamic linker so that functions have at most one
3835 fptr. For this reason, we need to differentiate
3836 between global and local plabels, which we do by
3837 providing the function symbol for a global plabel
3838 reloc, and no symbol for local plabels. */
3841 && sym_sec
->output_section
!= NULL
3842 && ! bfd_is_abs_section (sym_sec
))
3844 indx
= elf_section_data (sym_sec
->output_section
)->dynindx
;
3845 /* We are turning this relocation into one
3846 against a section symbol, so subtract out the
3847 output section's address but not the offset
3848 of the input section in the output section. */
3849 outrel
.r_addend
-= sym_sec
->output_section
->vma
;
3852 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
3855 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3856 ((Elf32_External_Rela
*)
3858 + sreloc
->reloc_count
));
3859 ++sreloc
->reloc_count
;
3867 r
= final_link_relocate (input_section
, contents
, rel
, relocation
,
3868 hplink
, sym_sec
, h
);
3870 if (r
== bfd_reloc_ok
)
3874 sym_name
= h
->elf
.root
.root
.string
;
3877 sym_name
= bfd_elf_string_from_elf_section (input_bfd
,
3878 symtab_hdr
->sh_link
,
3880 if (sym_name
== NULL
)
3882 if (*sym_name
== '\0')
3883 sym_name
= bfd_section_name (input_bfd
, sym_sec
);
3886 howto
= elf_hppa_howto_table
+ r_type
;
3888 if (r
== bfd_reloc_undefined
|| r
== bfd_reloc_notsupported
)
3890 (*_bfd_error_handler
)
3891 (_("%s(%s+0x%lx): cannot handle %s for %s"),
3892 bfd_get_filename (input_bfd
),
3893 input_section
->name
,
3894 (long) rel
->r_offset
,
3900 if (!((*info
->callbacks
->reloc_overflow
)
3901 (info
, sym_name
, howto
->name
, (bfd_vma
) 0,
3902 input_bfd
, input_section
, rel
->r_offset
)))
3911 /* Finish up dynamic symbol handling. We set the contents of various
3912 dynamic sections here. */
3915 elf32_hppa_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
3917 struct bfd_link_info
*info
;
3918 struct elf_link_hash_entry
*h
;
3919 Elf_Internal_Sym
*sym
;
3921 struct elf32_hppa_link_hash_table
*hplink
;
3924 hplink
= hppa_link_hash_table (info
);
3925 dynobj
= hplink
->root
.dynobj
;
3927 if (h
->plt
.offset
!= (bfd_vma
) -1)
3931 /* This symbol has an entry in the procedure linkage table. Set
3934 The format of a plt entry is
3939 if (h
->root
.type
== bfd_link_hash_defined
3940 || h
->root
.type
== bfd_link_hash_defweak
)
3942 value
= h
->root
.u
.def
.value
;
3943 if (h
->root
.u
.def
.section
->output_section
!= NULL
)
3944 value
+= (h
->root
.u
.def
.section
->output_offset
3945 + h
->root
.u
.def
.section
->output_section
->vma
);
3948 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
)
3950 Elf_Internal_Rela rel
;
3952 /* Create a dynamic IPLT relocation for this entry. */
3953 rel
.r_offset
= (h
->plt
.offset
3954 + hplink
->splt
->output_offset
3955 + hplink
->splt
->output_section
->vma
);
3956 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->plt_abs
3957 && h
->dynindx
!= -1)
3959 /* To support lazy linking, the function pointer is
3960 initialised to point to a special stub stored at the
3961 end of the .plt. This is only done for plt entries
3962 with a non-*ABS* dynamic relocation. */
3963 value
= (hplink
->splt
->output_offset
3964 + hplink
->splt
->output_section
->vma
3965 + hplink
->splt
->_raw_size
3968 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_IPLT
);
3973 /* This symbol has been marked to become local, and is
3974 used by a plabel so must be kept in the .plt. */
3975 rel
.r_info
= ELF32_R_INFO (0, R_PARISC_IPLT
);
3976 rel
.r_addend
= value
;
3979 bfd_elf32_swap_reloca_out (hplink
->splt
->output_section
->owner
,
3981 ((Elf32_External_Rela
*)
3982 hplink
->srelplt
->contents
3983 + hplink
->srelplt
->reloc_count
));
3984 hplink
->srelplt
->reloc_count
++;
3987 bfd_put_32 (hplink
->splt
->owner
,
3989 hplink
->splt
->contents
+ h
->plt
.offset
);
3990 bfd_put_32 (hplink
->splt
->owner
,
3991 elf_gp (hplink
->splt
->output_section
->owner
),
3992 hplink
->splt
->contents
+ h
->plt
.offset
+ 4);
3993 if (PLABEL_PLT_ENTRY_SIZE
!= PLT_ENTRY_SIZE
3994 && ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
3995 && h
->dynindx
!= -1)
3997 memset (hplink
->splt
->contents
+ h
->plt
.offset
+ 8,
3998 0, PLABEL_PLT_ENTRY_SIZE
- PLT_ENTRY_SIZE
);
4001 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4003 /* Mark the symbol as undefined, rather than as defined in
4004 the .plt section. Leave the value alone. */
4005 sym
->st_shndx
= SHN_UNDEF
;
4009 if (h
->got
.offset
!= (bfd_vma
) -1)
4011 Elf_Internal_Rela rel
;
4013 /* This symbol has an entry in the global offset table. Set it
4016 rel
.r_offset
= ((h
->got
.offset
&~ (bfd_vma
) 1)
4017 + hplink
->sgot
->output_offset
4018 + hplink
->sgot
->output_section
->vma
);
4020 /* If this is a static link, or it is a -Bsymbolic link and the
4021 symbol is defined locally or was forced to be local because
4022 of a version file, we just want to emit a RELATIVE reloc.
4023 The entry in the global offset table will already have been
4024 initialized in the relocate_section function. */
4025 if (! hplink
->root
.dynamic_sections_created
4027 && (info
->symbolic
|| h
->dynindx
== -1)
4028 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
4030 rel
.r_info
= ELF32_R_INFO (0, R_PARISC_DIR32
);
4031 rel
.r_addend
= (h
->root
.u
.def
.value
4032 + h
->root
.u
.def
.section
->output_offset
4033 + h
->root
.u
.def
.section
->output_section
->vma
);
4037 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4038 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
4039 hplink
->sgot
->contents
+ h
->got
.offset
);
4040 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_DIR32
);
4044 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
4045 ((Elf32_External_Rela
*)
4046 hplink
->srelgot
->contents
4047 + hplink
->srelgot
->reloc_count
));
4048 ++hplink
->srelgot
->reloc_count
;
4051 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
4054 Elf_Internal_Rela rel
;
4056 /* This symbol needs a copy reloc. Set it up. */
4058 BFD_ASSERT (h
->dynindx
!= -1
4059 && (h
->root
.type
== bfd_link_hash_defined
4060 || h
->root
.type
== bfd_link_hash_defweak
));
4062 s
= hplink
->srelbss
;
4064 rel
.r_offset
= (h
->root
.u
.def
.value
4065 + h
->root
.u
.def
.section
->output_offset
4066 + h
->root
.u
.def
.section
->output_section
->vma
);
4068 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_COPY
);
4069 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
4070 ((Elf32_External_Rela
*) s
->contents
4075 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
4076 if (h
->root
.root
.string
[0] == '_'
4077 && (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4078 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0))
4080 sym
->st_shndx
= SHN_ABS
;
4087 /* Finish up the dynamic sections. */
4090 elf32_hppa_finish_dynamic_sections (output_bfd
, info
)
4092 struct bfd_link_info
*info
;
4095 struct elf32_hppa_link_hash_table
*hplink
;
4098 hplink
= hppa_link_hash_table (info
);
4099 dynobj
= hplink
->root
.dynobj
;
4101 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4103 if (hplink
->root
.dynamic_sections_created
)
4105 Elf32_External_Dyn
*dyncon
, *dynconend
;
4107 BFD_ASSERT (sdyn
!= NULL
);
4109 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4110 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
4111 for (; dyncon
< dynconend
; dyncon
++)
4113 Elf_Internal_Dyn dyn
;
4116 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4124 /* Use PLTGOT to set the GOT register. */
4125 dyn
.d_un
.d_ptr
= elf_gp (output_bfd
);
4126 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4130 s
= hplink
->srelplt
;
4131 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4132 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4136 s
= hplink
->srelplt
;
4137 if (s
->_cooked_size
!= 0)
4138 dyn
.d_un
.d_val
= s
->_cooked_size
;
4140 dyn
.d_un
.d_val
= s
->_raw_size
;
4141 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4147 struct elf_link_hash_entry
*h
;
4148 const char *funcname
;
4150 if (dyn
.d_tag
== DT_INIT
)
4151 funcname
= info
->init_function
;
4153 funcname
= info
->fini_function
;
4155 h
= elf_link_hash_lookup (&hplink
->root
, funcname
,
4156 false, false, false);
4158 /* This is a function pointer. The magic +2 offset
4159 signals to $$dyncall that the function pointer
4160 is in the .plt and thus has a gp pointer too. */
4161 dyn
.d_un
.d_ptr
= (h
->plt
.offset
4162 + hplink
->splt
->output_offset
4163 + hplink
->splt
->output_section
->vma
4165 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4172 if (hplink
->sgot
->_raw_size
!= 0)
4174 /* Fill in the first entry in the global offset table.
4175 We use it to point to our dynamic section, if we have one. */
4176 bfd_put_32 (output_bfd
,
4178 ? sdyn
->output_section
->vma
+ sdyn
->output_offset
4180 hplink
->sgot
->contents
);
4182 /* The second entry is reserved for use by the dynamic linker. */
4183 memset (hplink
->sgot
->contents
+ GOT_ENTRY_SIZE
, 0, GOT_ENTRY_SIZE
);
4185 /* Set .got entry size. */
4186 elf_section_data (hplink
->sgot
->output_section
)
4187 ->this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
4190 if (hplink
->splt
->_raw_size
!= 0)
4192 /* Set plt entry size. */
4193 elf_section_data (hplink
->splt
->output_section
)
4194 ->this_hdr
.sh_entsize
= PLT_ENTRY_SIZE
;
4196 if (hplink
->need_plt_stub
)
4198 /* Set up the .plt stub. */
4199 memcpy (hplink
->splt
->contents
4200 + hplink
->splt
->_raw_size
- sizeof (plt_stub
),
4201 plt_stub
, sizeof (plt_stub
));
4203 if ((hplink
->splt
->output_offset
4204 + hplink
->splt
->output_section
->vma
4205 + hplink
->splt
->_raw_size
)
4206 != (hplink
->sgot
->output_offset
4207 + hplink
->sgot
->output_section
->vma
))
4209 (*_bfd_error_handler
)
4210 (_(".got section not immediately after .plt section"));
4220 /* Called when writing out an object file to decide the type of a
4223 elf32_hppa_elf_get_symbol_type (elf_sym
, type
)
4224 Elf_Internal_Sym
*elf_sym
;
4227 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_PARISC_MILLI
)
4228 return STT_PARISC_MILLI
;
4234 /* Misc BFD support code. */
4235 #define bfd_elf32_bfd_is_local_label_name elf_hppa_is_local_label_name
4236 #define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
4237 #define elf_info_to_howto elf_hppa_info_to_howto
4238 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
4240 /* Stuff for the BFD linker. */
4241 #define bfd_elf32_bfd_final_link _bfd_elf32_gc_common_final_link
4242 #define bfd_elf32_bfd_link_hash_table_create elf32_hppa_link_hash_table_create
4243 #define elf_backend_add_symbol_hook elf32_hppa_add_symbol_hook
4244 #define elf_backend_adjust_dynamic_symbol elf32_hppa_adjust_dynamic_symbol
4245 #define elf_backend_check_relocs elf32_hppa_check_relocs
4246 #define elf_backend_create_dynamic_sections elf32_hppa_create_dynamic_sections
4247 #define elf_backend_fake_sections elf_hppa_fake_sections
4248 #define elf_backend_relocate_section elf32_hppa_relocate_section
4249 #define elf_backend_hide_symbol elf32_hppa_hide_symbol
4250 #define elf_backend_finish_dynamic_symbol elf32_hppa_finish_dynamic_symbol
4251 #define elf_backend_finish_dynamic_sections elf32_hppa_finish_dynamic_sections
4252 #define elf_backend_size_dynamic_sections elf32_hppa_size_dynamic_sections
4253 #define elf_backend_gc_mark_hook elf32_hppa_gc_mark_hook
4254 #define elf_backend_gc_sweep_hook elf32_hppa_gc_sweep_hook
4255 #define elf_backend_object_p elf32_hppa_object_p
4256 #define elf_backend_final_write_processing elf_hppa_final_write_processing
4257 #define elf_backend_get_symbol_type elf32_hppa_elf_get_symbol_type
4259 #define elf_backend_can_gc_sections 1
4260 #define elf_backend_plt_alignment 2
4261 #define elf_backend_want_got_plt 0
4262 #define elf_backend_plt_readonly 0
4263 #define elf_backend_want_plt_sym 0
4264 #define elf_backend_got_header_size 8
4266 #define TARGET_BIG_SYM bfd_elf32_hppa_vec
4267 #define TARGET_BIG_NAME "elf32-hppa"
4268 #define ELF_ARCH bfd_arch_hppa
4269 #define ELF_MACHINE_CODE EM_PARISC
4270 #define ELF_MAXPAGESIZE 0x1000
4272 #include "elf32-target.h"