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 /* Section name for stubs is the associated section name plus this
125 #define STUB_SUFFIX ".stub"
127 /* Setting the following non-zero makes all long branch stubs
128 generated during a shared link of the PIC variety. This saves on
129 relocs, but costs one extra instruction per stub. */
130 #ifndef LONG_BRANCH_PIC_IN_SHLIB
131 #define LONG_BRANCH_PIC_IN_SHLIB 1
134 /* Set this non-zero to use import stubs instead of long branch stubs
135 where a .plt entry exists for the symbol. This is a fairly useless
136 option as import stubs are bigger than PIC long branch stubs. */
137 #ifndef LONG_BRANCH_VIA_PLT
138 #define LONG_BRANCH_VIA_PLT 0
141 /* We don't need to copy any PC- or GP-relative dynamic relocs into a
142 shared object's dynamic section. */
143 #ifndef RELATIVE_DYNAMIC_RELOCS
144 #define RELATIVE_DYNAMIC_RELOCS 0
148 enum elf32_hppa_stub_type
{
149 hppa_stub_long_branch
,
150 hppa_stub_long_branch_shared
,
152 hppa_stub_import_shared
,
158 struct elf32_hppa_stub_hash_entry
{
160 /* Base hash table entry structure. */
161 struct bfd_hash_entry root
;
163 /* The stub section. */
166 #if ! LONG_BRANCH_PIC_IN_SHLIB
167 /* It's associated reloc section. */
171 /* Offset within stub_sec of the beginning of this stub. */
174 /* Given the symbol's value and its section we can determine its final
175 value when building the stubs (so the stub knows where to jump. */
176 bfd_vma target_value
;
177 asection
*target_section
;
179 enum elf32_hppa_stub_type stub_type
;
181 /* The symbol table entry, if any, that this was derived from. */
182 struct elf32_hppa_link_hash_entry
*h
;
184 /* Where this stub is being called from, or, in the case of combined
185 stub sections, the first input section in the group. */
190 struct elf32_hppa_link_hash_entry
{
192 struct elf_link_hash_entry elf
;
194 /* A pointer to the most recently used stub hash entry against this
196 struct elf32_hppa_stub_hash_entry
*stub_cache
;
198 #if ! LONG_BRANCH_PIC_IN_SHLIB
199 /* Used to track whether we have allocated space for a long branch
200 stub relocation for this symbol in the given section. */
201 asection
*stub_reloc_sec
;
204 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
205 /* Used to count relocations for delayed sizing of relocation
207 struct elf32_hppa_dyn_reloc_entry
{
209 /* Next relocation in the chain. */
210 struct elf32_hppa_dyn_reloc_entry
*next
;
212 /* The section in dynobj. */
215 /* Number of relocs copied in this section. */
220 /* Set during a static link if we detect a function is PIC. */
221 unsigned int pic_call
:1;
223 /* Set if this symbol is used by a plabel reloc. */
224 unsigned int plabel
:1;
226 /* Set if this symbol is an init or fini function and thus should
227 use an absolute reloc. */
228 unsigned int plt_abs
:1;
232 struct elf32_hppa_link_hash_table
{
234 /* The main hash table. */
235 struct elf_link_hash_table root
;
237 /* The stub hash table. */
238 struct bfd_hash_table stub_hash_table
;
240 /* Linker stub bfd. */
243 /* Whether we support multiple sub-spaces for shared libs. */
244 boolean multi_subspace
;
246 /* Linker call-backs. */
247 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
248 void (*layout_sections_again
) PARAMS ((void));
250 /* Array to keep track of which stub sections have been created, and
251 information on stub grouping. */
253 /* This is the section to which stubs in the group will be
256 /* The stub section. */
258 #if ! LONG_BRANCH_PIC_IN_SHLIB
259 /* The stub section's reloc section. */
264 /* Short-cuts to get to dynamic linker sections. */
274 /* Various hash macros and functions. */
275 #define hppa_link_hash_table(p) \
276 ((struct elf32_hppa_link_hash_table *) ((p)->hash))
278 #define hppa_stub_hash_lookup(table, string, create, copy) \
279 ((struct elf32_hppa_stub_hash_entry *) \
280 bfd_hash_lookup ((table), (string), (create), (copy)))
282 static struct bfd_hash_entry
*stub_hash_newfunc
283 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
285 static struct bfd_hash_entry
*hppa_link_hash_newfunc
286 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
288 static struct bfd_link_hash_table
*elf32_hppa_link_hash_table_create
292 /* Stub handling functions. */
293 static char *hppa_stub_name
294 PARAMS ((const asection
*, const asection
*,
295 const struct elf32_hppa_link_hash_entry
*,
296 const Elf_Internal_Rela
*));
298 static struct elf32_hppa_stub_hash_entry
*hppa_get_stub_entry
299 PARAMS ((const asection
*, const asection
*,
300 struct elf32_hppa_link_hash_entry
*,
301 const Elf_Internal_Rela
*,
302 struct elf32_hppa_link_hash_table
*));
304 static struct elf32_hppa_stub_hash_entry
*hppa_add_stub
305 PARAMS ((const char *, asection
*, struct elf32_hppa_link_hash_table
*));
307 static enum elf32_hppa_stub_type hppa_type_of_stub
308 PARAMS ((asection
*, const Elf_Internal_Rela
*,
309 struct elf32_hppa_link_hash_entry
*, bfd_vma
));
311 static boolean hppa_build_one_stub
312 PARAMS ((struct bfd_hash_entry
*, PTR
));
314 static boolean hppa_size_one_stub
315 PARAMS ((struct bfd_hash_entry
*, PTR
));
318 /* BFD and elf backend functions. */
319 static boolean elf32_hppa_object_p
PARAMS ((bfd
*));
321 static boolean elf32_hppa_add_symbol_hook
322 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
323 const char **, flagword
*, asection
**, bfd_vma
*));
325 static boolean elf32_hppa_create_dynamic_sections
326 PARAMS ((bfd
*, struct bfd_link_info
*));
328 static boolean elf32_hppa_check_relocs
329 PARAMS ((bfd
*, struct bfd_link_info
*,
330 asection
*, const Elf_Internal_Rela
*));
332 static asection
*elf32_hppa_gc_mark_hook
333 PARAMS ((bfd
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
334 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
336 static boolean elf32_hppa_gc_sweep_hook
337 PARAMS ((bfd
*, struct bfd_link_info
*,
338 asection
*, const Elf_Internal_Rela
*));
340 static void elf32_hppa_hide_symbol
341 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
343 static boolean elf32_hppa_adjust_dynamic_symbol
344 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
346 static boolean hppa_handle_PIC_calls
347 PARAMS ((struct elf_link_hash_entry
*, PTR
));
349 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
350 || RELATIVE_DYNAMIC_RELOCS)
351 static boolean hppa_discard_copies
352 PARAMS ((struct elf_link_hash_entry
*, PTR
));
355 static boolean clobber_millicode_symbols
356 PARAMS ((struct elf_link_hash_entry
*, struct bfd_link_info
*));
358 static boolean elf32_hppa_size_dynamic_sections
359 PARAMS ((bfd
*, struct bfd_link_info
*));
361 static bfd_reloc_status_type final_link_relocate
362 PARAMS ((asection
*, bfd_byte
*, const Elf_Internal_Rela
*,
363 bfd_vma
, struct elf32_hppa_link_hash_table
*, asection
*,
364 struct elf32_hppa_link_hash_entry
*));
366 static boolean elf32_hppa_relocate_section
367 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*,
368 bfd_byte
*, Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
370 static boolean elf32_hppa_finish_dynamic_symbol
371 PARAMS ((bfd
*, struct bfd_link_info
*,
372 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
374 static boolean elf32_hppa_finish_dynamic_sections
375 PARAMS ((bfd
*, struct bfd_link_info
*));
377 static int elf32_hppa_elf_get_symbol_type
378 PARAMS ((Elf_Internal_Sym
*, int));
381 /* Assorted hash table functions. */
383 /* Initialize an entry in the stub hash table. */
385 static struct bfd_hash_entry
*
386 stub_hash_newfunc (entry
, table
, string
)
387 struct bfd_hash_entry
*entry
;
388 struct bfd_hash_table
*table
;
391 struct elf32_hppa_stub_hash_entry
*ret
;
393 ret
= (struct elf32_hppa_stub_hash_entry
*) entry
;
395 /* Allocate the structure if it has not already been allocated by a
399 ret
= ((struct elf32_hppa_stub_hash_entry
*)
400 bfd_hash_allocate (table
,
401 sizeof (struct elf32_hppa_stub_hash_entry
)));
406 /* Call the allocation method of the superclass. */
407 ret
= ((struct elf32_hppa_stub_hash_entry
*)
408 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
412 /* Initialize the local fields. */
413 ret
->stub_sec
= NULL
;
414 #if ! LONG_BRANCH_PIC_IN_SHLIB
415 ret
->reloc_sec
= NULL
;
417 ret
->stub_offset
= 0;
418 ret
->target_value
= 0;
419 ret
->target_section
= NULL
;
420 ret
->stub_type
= hppa_stub_long_branch
;
425 return (struct bfd_hash_entry
*) ret
;
429 /* Initialize an entry in the link hash table. */
431 static struct bfd_hash_entry
*
432 hppa_link_hash_newfunc (entry
, table
, string
)
433 struct bfd_hash_entry
*entry
;
434 struct bfd_hash_table
*table
;
437 struct elf32_hppa_link_hash_entry
*ret
;
439 ret
= (struct elf32_hppa_link_hash_entry
*) entry
;
441 /* Allocate the structure if it has not already been allocated by a
445 ret
= ((struct elf32_hppa_link_hash_entry
*)
446 bfd_hash_allocate (table
,
447 sizeof (struct elf32_hppa_link_hash_entry
)));
452 /* Call the allocation method of the superclass. */
453 ret
= ((struct elf32_hppa_link_hash_entry
*)
454 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
459 /* Initialize the local fields. */
460 #if ! LONG_BRANCH_PIC_IN_SHLIB
461 ret
->stub_reloc_sec
= NULL
;
463 ret
->stub_cache
= NULL
;
464 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
465 ret
->reloc_entries
= NULL
;
472 return (struct bfd_hash_entry
*) ret
;
476 /* Create the derived linker hash table. The PA ELF port uses the derived
477 hash table to keep information specific to the PA ELF linker (without
478 using static variables). */
480 static struct bfd_link_hash_table
*
481 elf32_hppa_link_hash_table_create (abfd
)
484 struct elf32_hppa_link_hash_table
*ret
;
486 ret
= ((struct elf32_hppa_link_hash_table
*) bfd_alloc (abfd
, sizeof (*ret
)));
490 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
, hppa_link_hash_newfunc
))
492 bfd_release (abfd
, ret
);
496 /* Init the stub hash table too. */
497 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
))
500 ret
->stub_bfd
= NULL
;
501 ret
->multi_subspace
= 0;
502 ret
->add_stub_section
= NULL
;
503 ret
->layout_sections_again
= NULL
;
504 ret
->stub_group
= NULL
;
512 return &ret
->root
.root
;
516 /* Build a name for an entry in the stub hash table. */
519 hppa_stub_name (input_section
, sym_sec
, hash
, rel
)
520 const asection
*input_section
;
521 const asection
*sym_sec
;
522 const struct elf32_hppa_link_hash_entry
*hash
;
523 const Elf_Internal_Rela
*rel
;
530 len
= 8 + 1 + strlen (hash
->elf
.root
.root
.string
) + 1 + 8 + 1;
531 stub_name
= bfd_malloc (len
);
532 if (stub_name
!= NULL
)
534 sprintf (stub_name
, "%08x_%s+%x",
535 input_section
->id
& 0xffffffff,
536 hash
->elf
.root
.root
.string
,
537 (int) rel
->r_addend
& 0xffffffff);
542 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
543 stub_name
= bfd_malloc (len
);
544 if (stub_name
!= NULL
)
546 sprintf (stub_name
, "%08x_%x:%x+%x",
547 input_section
->id
& 0xffffffff,
548 sym_sec
->id
& 0xffffffff,
549 (int) ELF32_R_SYM (rel
->r_info
) & 0xffffffff,
550 (int) rel
->r_addend
& 0xffffffff);
557 /* Look up an entry in the stub hash. Stub entries are cached because
558 creating the stub name takes a bit of time. */
560 static struct elf32_hppa_stub_hash_entry
*
561 hppa_get_stub_entry (input_section
, sym_sec
, hash
, rel
, hplink
)
562 const asection
*input_section
;
563 const asection
*sym_sec
;
564 struct elf32_hppa_link_hash_entry
*hash
;
565 const Elf_Internal_Rela
*rel
;
566 struct elf32_hppa_link_hash_table
*hplink
;
568 struct elf32_hppa_stub_hash_entry
*stub_entry
;
569 const asection
*id_sec
;
571 /* If this input section is part of a group of sections sharing one
572 stub section, then use the id of the first section in the group.
573 Stub names need to include a section id, as there may well be
574 more than one stub used to reach say, printf, and we need to
575 distinguish between them. */
576 id_sec
= hplink
->stub_group
[input_section
->id
].link_sec
;
578 if (hash
!= NULL
&& hash
->stub_cache
!= NULL
579 && hash
->stub_cache
->h
== hash
580 && hash
->stub_cache
->id_sec
== id_sec
)
582 stub_entry
= hash
->stub_cache
;
588 stub_name
= hppa_stub_name (id_sec
, sym_sec
, hash
, rel
);
589 if (stub_name
== NULL
)
592 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
,
593 stub_name
, false, false);
594 if (stub_entry
== NULL
)
596 if (hash
== NULL
|| hash
->elf
.root
.type
!= bfd_link_hash_undefweak
)
597 (*_bfd_error_handler
) (_("%s(%s+0x%lx): cannot find stub entry %s"),
598 bfd_get_filename (input_section
->owner
),
600 (long) rel
->r_offset
,
606 hash
->stub_cache
= stub_entry
;
616 /* Add a new stub entry to the stub hash. Not all fields of the new
617 stub entry are initialised. */
619 static struct elf32_hppa_stub_hash_entry
*
620 hppa_add_stub (stub_name
, section
, hplink
)
621 const char *stub_name
;
623 struct elf32_hppa_link_hash_table
*hplink
;
627 struct elf32_hppa_stub_hash_entry
*stub_entry
;
629 link_sec
= hplink
->stub_group
[section
->id
].link_sec
;
630 stub_sec
= hplink
->stub_group
[section
->id
].stub_sec
;
631 if (stub_sec
== NULL
)
633 stub_sec
= hplink
->stub_group
[link_sec
->id
].stub_sec
;
634 if (stub_sec
== NULL
)
639 len
= strlen (link_sec
->name
) + sizeof (STUB_SUFFIX
);
640 s_name
= bfd_alloc (hplink
->stub_bfd
, len
);
644 strcpy (s_name
, link_sec
->name
);
645 strcpy (s_name
+ len
- sizeof (STUB_SUFFIX
), STUB_SUFFIX
);
646 stub_sec
= (*hplink
->add_stub_section
) (s_name
, link_sec
);
647 if (stub_sec
== NULL
)
649 hplink
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
651 hplink
->stub_group
[section
->id
].stub_sec
= stub_sec
;
654 /* Enter this entry into the linker stub hash table. */
655 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
, stub_name
,
657 if (stub_entry
== NULL
)
659 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
660 bfd_get_filename (section
->owner
),
665 stub_entry
->stub_sec
= stub_sec
;
666 #if ! LONG_BRANCH_PIC_IN_SHLIB
667 stub_entry
->reloc_sec
= hplink
->stub_group
[section
->id
].reloc_sec
;
669 stub_entry
->stub_offset
= 0;
670 stub_entry
->id_sec
= link_sec
;
675 /* Determine the type of stub needed, if any, for a call. */
677 static enum elf32_hppa_stub_type
678 hppa_type_of_stub (input_sec
, rel
, hash
, destination
)
680 const Elf_Internal_Rela
*rel
;
681 struct elf32_hppa_link_hash_entry
*hash
;
685 bfd_vma branch_offset
;
686 bfd_vma max_branch_offset
;
690 && (((hash
->elf
.root
.type
== bfd_link_hash_defined
691 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
692 && hash
->elf
.root
.u
.def
.section
->output_section
== NULL
)
693 || (hash
->elf
.root
.type
== bfd_link_hash_defweak
694 && hash
->elf
.dynindx
!= -1
695 && hash
->elf
.plt
.offset
!= (bfd_vma
) -1)
696 || hash
->elf
.root
.type
== bfd_link_hash_undefweak
697 || hash
->elf
.root
.type
== bfd_link_hash_undefined
700 /* If output_section is NULL, then it's a symbol defined in a
701 shared library. We will need an import stub. Decide between
702 hppa_stub_import and hppa_stub_import_shared later. For
703 shared links we need stubs for undefined or weak syms too;
704 They will presumably be resolved by the dynamic linker. */
705 return hppa_stub_import
;
708 /* Determine where the call point is. */
709 location
= (input_sec
->output_offset
710 + input_sec
->output_section
->vma
713 branch_offset
= destination
- location
- 8;
714 r_type
= ELF32_R_TYPE (rel
->r_info
);
716 /* Determine if a long branch stub is needed. parisc branch offsets
717 are relative to the second instruction past the branch, ie. +8
718 bytes on from the branch instruction location. The offset is
719 signed and counts in units of 4 bytes. */
720 if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
722 max_branch_offset
= (1 << (17-1)) << 2;
724 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
726 max_branch_offset
= (1 << (12-1)) << 2;
728 else /* R_PARISC_PCREL22F. */
730 max_branch_offset
= (1 << (22-1)) << 2;
733 if (branch_offset
+ max_branch_offset
>= 2*max_branch_offset
)
735 #if LONG_BRANCH_VIA_PLT
737 && hash
->elf
.dynindx
!= -1
738 && hash
->elf
.plt
.offset
!= (bfd_vma
) -1)
740 /* If we are doing a shared link and find we need a long
741 branch stub, then go via the .plt if possible. */
742 return hppa_stub_import
;
746 return hppa_stub_long_branch
;
748 return hppa_stub_none
;
752 /* Build one linker stub as defined by the stub hash table entry GEN_ENTRY.
753 IN_ARG contains the link info pointer. */
755 #define LDIL_R1 0x20200000 /* ldil LR'XXX,%r1 */
756 #define BE_SR4_R1 0xe0202002 /* be,n RR'XXX(%sr4,%r1) */
758 #define BL_R1 0xe8200000 /* b,l .+8,%r1 */
759 #define ADDIL_R1 0x28200000 /* addil L'XXX,%r1,%r1 */
760 #define DEPI_R1 0xd4201c1e /* depi 0,31,2,%r1 */
762 #define ADDIL_DP 0x2b600000 /* addil L'XXX,%dp,%r1 */
763 #define LDW_R1_R21 0x48350000 /* ldw R'XXX(%sr0,%r1),%r21 */
764 #define BV_R0_R21 0xeaa0c000 /* bv %r0(%r21) */
765 #define LDW_R1_R19 0x48330000 /* ldw R'XXX(%sr0,%r1),%r19 */
767 #define ADDIL_R19 0x2a600000 /* addil L'XXX,%r19,%r1 */
768 #define LDW_R1_DP 0x483b0000 /* ldw R'XXX(%sr0,%r1),%dp */
770 #define LDSID_R21_R1 0x02a010a1 /* ldsid (%sr0,%r21),%r1 */
771 #define MTSP_R1 0x00011820 /* mtsp %r1,%sr0 */
772 #define BE_SR0_R21 0xe2a00000 /* be 0(%sr0,%r21) */
773 #define STW_RP 0x6bc23fd1 /* stw %rp,-24(%sr0,%sp) */
775 #define BL_RP 0xe8400002 /* b,l,n XXX,%rp */
776 #define NOP 0x08000240 /* nop */
777 #define LDW_RP 0x4bc23fd1 /* ldw -24(%sr0,%sp),%rp */
778 #define LDSID_RP_R1 0x004010a1 /* ldsid (%sr0,%rp),%r1 */
779 #define BE_SR0_RP 0xe0400002 /* be,n 0(%sr0,%rp) */
786 #define LDW_R1_DLT LDW_R1_R19
788 #define LDW_R1_DLT LDW_R1_DP
792 hppa_build_one_stub (gen_entry
, in_arg
)
793 struct bfd_hash_entry
*gen_entry
;
796 struct elf32_hppa_stub_hash_entry
*stub_entry
;
797 struct bfd_link_info
*info
;
798 struct elf32_hppa_link_hash_table
*hplink
;
807 /* Massage our args to the form they really have. */
808 stub_entry
= (struct elf32_hppa_stub_hash_entry
*) gen_entry
;
809 info
= (struct bfd_link_info
*) in_arg
;
811 hplink
= hppa_link_hash_table (info
);
812 stub_sec
= stub_entry
->stub_sec
;
814 /* Make a note of the offset within the stubs for this entry. */
815 stub_entry
->stub_offset
= stub_sec
->_raw_size
;
816 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
818 stub_bfd
= stub_sec
->owner
;
820 switch (stub_entry
->stub_type
)
822 case hppa_stub_long_branch
:
823 /* Create the long branch. A long branch is formed with "ldil"
824 loading the upper bits of the target address into a register,
825 then branching with "be" which adds in the lower bits.
826 The "be" has its delay slot nullified. */
827 sym_value
= (stub_entry
->target_value
828 + stub_entry
->target_section
->output_offset
829 + stub_entry
->target_section
->output_section
->vma
);
831 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_lrsel
);
832 insn
= hppa_rebuild_insn ((int) LDIL_R1
, val
, 21);
833 bfd_put_32 (stub_bfd
, insn
, loc
);
835 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_rrsel
) >> 2;
836 insn
= hppa_rebuild_insn ((int) BE_SR4_R1
, val
, 17);
837 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
839 #if ! LONG_BRANCH_PIC_IN_SHLIB
842 /* Output a dynamic relocation for this stub. We only
843 output one PCREL21L reloc per stub, trusting that the
844 dynamic linker will also fix the implied PCREL17R for the
845 second instruction. PCREL21L dynamic relocs had better
846 never be emitted for some other purpose... */
848 Elf_Internal_Rela outrel
;
850 if (stub_entry
->h
== NULL
)
852 (*_bfd_error_handler
)
853 (_("%s(%s+0x%lx): cannot relocate %s, recompile with -ffunction-sections"),
854 bfd_get_filename (stub_entry
->target_section
->owner
),
856 (long) stub_entry
->stub_offset
,
857 stub_entry
->root
.string
);
858 bfd_set_error (bfd_error_bad_value
);
862 srel
= stub_entry
->reloc_sec
;
865 (*_bfd_error_handler
)
866 (_("Could not find relocation section for %s"),
868 bfd_set_error (bfd_error_bad_value
);
872 outrel
.r_offset
= (stub_entry
->stub_offset
873 + stub_sec
->output_offset
874 + stub_sec
->output_section
->vma
);
875 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_PCREL21L
);
876 outrel
.r_addend
= sym_value
;
877 bfd_elf32_swap_reloca_out (stub_sec
->output_section
->owner
,
879 ((Elf32_External_Rela
*)
880 srel
->contents
+ srel
->reloc_count
));
887 case hppa_stub_long_branch_shared
:
888 /* Branches are relative. This is where we are going to. */
889 sym_value
= (stub_entry
->target_value
890 + stub_entry
->target_section
->output_offset
891 + stub_entry
->target_section
->output_section
->vma
);
893 /* And this is where we are coming from, more or less. */
894 sym_value
-= (stub_entry
->stub_offset
895 + stub_sec
->output_offset
896 + stub_sec
->output_section
->vma
);
898 bfd_put_32 (stub_bfd
, (bfd_vma
) BL_R1
, loc
);
899 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_lsel
);
900 insn
= hppa_rebuild_insn ((int) ADDIL_R1
, val
, 21);
901 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
903 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_rsel
) >> 2;
904 insn
= hppa_rebuild_insn ((int) BE_SR4_R1
, val
, 17);
905 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
909 case hppa_stub_import
:
910 case hppa_stub_import_shared
:
911 sym_value
= (stub_entry
->h
->elf
.plt
.offset
912 + hplink
->splt
->output_offset
913 + hplink
->splt
->output_section
->vma
914 - elf_gp (hplink
->splt
->output_section
->owner
));
918 if (stub_entry
->stub_type
== hppa_stub_import_shared
)
921 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_lsel
),
922 insn
= hppa_rebuild_insn ((int) insn
, val
, 21);
923 bfd_put_32 (stub_bfd
, insn
, loc
);
925 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_rsel
);
926 insn
= hppa_rebuild_insn ((int) LDW_R1_R21
, val
, 14);
927 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
929 if (hplink
->multi_subspace
)
931 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 4, e_rsel
);
932 insn
= hppa_rebuild_insn ((int) LDW_R1_DLT
, val
, 14);
933 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
935 bfd_put_32 (stub_bfd
, (bfd_vma
) LDSID_R21_R1
, loc
+ 12);
936 bfd_put_32 (stub_bfd
, (bfd_vma
) MTSP_R1
, loc
+ 16);
937 bfd_put_32 (stub_bfd
, (bfd_vma
) BE_SR0_R21
, loc
+ 20);
938 bfd_put_32 (stub_bfd
, (bfd_vma
) STW_RP
, loc
+ 24);
944 bfd_put_32 (stub_bfd
, (bfd_vma
) BV_R0_R21
, loc
+ 8);
945 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 4, e_rsel
);
946 insn
= hppa_rebuild_insn ((int) LDW_R1_DLT
, val
, 14);
947 bfd_put_32 (stub_bfd
, insn
, loc
+ 12);
953 && stub_entry
->h
!= NULL
954 && stub_entry
->h
->pic_call
)
956 /* Build the .plt entry needed to call a PIC function from
957 statically linked code. We don't need any relocs. */
959 struct elf32_hppa_link_hash_entry
*eh
;
962 dynobj
= hplink
->root
.dynobj
;
963 eh
= (struct elf32_hppa_link_hash_entry
*) stub_entry
->h
;
965 BFD_ASSERT (eh
->elf
.root
.type
== bfd_link_hash_defined
966 || eh
->elf
.root
.type
== bfd_link_hash_defweak
);
968 value
= (eh
->elf
.root
.u
.def
.value
969 + eh
->elf
.root
.u
.def
.section
->output_offset
970 + eh
->elf
.root
.u
.def
.section
->output_section
->vma
);
972 /* Fill in the entry in the procedure linkage table.
974 The format of a plt entry is
978 bfd_put_32 (hplink
->splt
->owner
, value
,
979 hplink
->splt
->contents
+ eh
->elf
.plt
.offset
);
980 value
= elf_gp (hplink
->splt
->output_section
->owner
);
981 bfd_put_32 (hplink
->splt
->owner
, value
,
982 hplink
->splt
->contents
+ eh
->elf
.plt
.offset
+ 4);
986 case hppa_stub_export
:
987 /* Branches are relative. This is where we are going to. */
988 sym_value
= (stub_entry
->target_value
989 + stub_entry
->target_section
->output_offset
990 + stub_entry
->target_section
->output_section
->vma
);
992 /* And this is where we are coming from. */
993 sym_value
-= (stub_entry
->stub_offset
994 + stub_sec
->output_offset
995 + stub_sec
->output_section
->vma
);
997 if (sym_value
- 8 + 0x40000 >= 0x80000)
999 (*_bfd_error_handler
)
1000 (_("%s(%s+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
1001 bfd_get_filename (stub_entry
->target_section
->owner
),
1003 (long) stub_entry
->stub_offset
,
1004 stub_entry
->root
.string
);
1005 bfd_set_error (bfd_error_bad_value
);
1009 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_fsel
) >> 2;
1010 insn
= hppa_rebuild_insn ((int) BL_RP
, val
, 17);
1011 bfd_put_32 (stub_bfd
, insn
, loc
);
1013 bfd_put_32 (stub_bfd
, (bfd_vma
) NOP
, loc
+ 4);
1014 bfd_put_32 (stub_bfd
, (bfd_vma
) LDW_RP
, loc
+ 8);
1015 bfd_put_32 (stub_bfd
, (bfd_vma
) LDSID_RP_R1
, loc
+ 12);
1016 bfd_put_32 (stub_bfd
, (bfd_vma
) MTSP_R1
, loc
+ 16);
1017 bfd_put_32 (stub_bfd
, (bfd_vma
) BE_SR0_RP
, loc
+ 20);
1019 /* Point the function symbol at the stub. */
1020 stub_entry
->h
->elf
.root
.u
.def
.section
= stub_sec
;
1021 stub_entry
->h
->elf
.root
.u
.def
.value
= stub_sec
->_raw_size
;
1031 stub_sec
->_raw_size
+= size
;
1058 /* As above, but don't actually build the stub. Just bump offset so
1059 we know stub section sizes. */
1062 hppa_size_one_stub (gen_entry
, in_arg
)
1063 struct bfd_hash_entry
*gen_entry
;
1066 struct elf32_hppa_stub_hash_entry
*stub_entry
;
1067 struct elf32_hppa_link_hash_table
*hplink
;
1070 /* Massage our args to the form they really have. */
1071 stub_entry
= (struct elf32_hppa_stub_hash_entry
*) gen_entry
;
1072 hplink
= (struct elf32_hppa_link_hash_table
*) in_arg
;
1074 if (stub_entry
->stub_type
== hppa_stub_long_branch
)
1076 #if ! LONG_BRANCH_PIC_IN_SHLIB
1077 if (stub_entry
->reloc_sec
!= NULL
)
1078 stub_entry
->reloc_sec
->_raw_size
+= sizeof (Elf32_External_Rela
);
1082 else if (stub_entry
->stub_type
== hppa_stub_long_branch_shared
)
1084 else if (stub_entry
->stub_type
== hppa_stub_export
)
1086 else /* hppa_stub_import or hppa_stub_import_shared. */
1088 if (hplink
->multi_subspace
)
1094 stub_entry
->stub_sec
->_raw_size
+= size
;
1099 /* Return nonzero if ABFD represents an HPPA ELF32 file.
1100 Additionally we set the default architecture and machine. */
1103 elf32_hppa_object_p (abfd
)
1106 unsigned int flags
= elf_elfheader (abfd
)->e_flags
;
1108 switch (flags
& (EF_PARISC_ARCH
| EF_PARISC_WIDE
))
1110 case EFA_PARISC_1_0
:
1111 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 10);
1112 case EFA_PARISC_1_1
:
1113 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 11);
1114 case EFA_PARISC_2_0
:
1115 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 20);
1116 case EFA_PARISC_2_0
| EF_PARISC_WIDE
:
1117 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 25);
1123 /* Undo the generic ELF code's subtraction of section->vma from the
1124 value of each external symbol. */
1127 elf32_hppa_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
1128 bfd
*abfd ATTRIBUTE_UNUSED
;
1129 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1130 const Elf_Internal_Sym
*sym ATTRIBUTE_UNUSED
;
1131 const char **namep ATTRIBUTE_UNUSED
;
1132 flagword
*flagsp ATTRIBUTE_UNUSED
;
1136 *valp
+= (*secp
)->vma
;
1141 /* Create the .plt and .got sections, and set up our hash table
1142 short-cuts to various dynamic sections. */
1145 elf32_hppa_create_dynamic_sections (abfd
, info
)
1147 struct bfd_link_info
*info
;
1151 struct elf32_hppa_link_hash_table
*hplink
;
1153 /* Don't try to create the .plt and .got twice. */
1154 hplink
= hppa_link_hash_table (info
);
1155 if (hplink
->splt
!= NULL
)
1158 /* Call the generic code to do most of the work. */
1159 if (! _bfd_elf_create_dynamic_sections (abfd
, info
))
1162 /* Our .plt just contains pointers. I suppose we should be using
1163 .plt.got but .plt.got doesn't make too much sense without a .plt
1164 section. Set the flags to say the .plt isn't executable. */
1165 s
= bfd_get_section_by_name (abfd
, ".plt");
1166 flags
= bfd_get_section_flags (abfd
, s
);
1167 if (! bfd_set_section_flags (abfd
, s
, flags
& ~SEC_CODE
))
1170 hplink
->srelplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
1172 hplink
->sgot
= bfd_get_section_by_name (abfd
, ".got");
1173 hplink
->srelgot
= bfd_make_section (abfd
, ".rela.got");
1174 if (hplink
->srelgot
== NULL
1175 || ! bfd_set_section_flags (abfd
, hplink
->srelgot
,
1180 | SEC_LINKER_CREATED
1182 || ! bfd_set_section_alignment (abfd
, hplink
->srelgot
, 2))
1185 hplink
->sdynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
1186 hplink
->srelbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
1192 /* Look through the relocs for a section during the first phase, and
1193 allocate space in the global offset table or procedure linkage
1194 table. At this point we haven't necessarily read all the input
1198 elf32_hppa_check_relocs (abfd
, info
, sec
, relocs
)
1200 struct bfd_link_info
*info
;
1202 const Elf_Internal_Rela
*relocs
;
1205 Elf_Internal_Shdr
*symtab_hdr
;
1206 struct elf_link_hash_entry
**sym_hashes
;
1207 bfd_signed_vma
*local_got_refcounts
;
1208 const Elf_Internal_Rela
*rel
;
1209 const Elf_Internal_Rela
*rel_end
;
1210 struct elf32_hppa_link_hash_table
*hplink
;
1212 asection
*stubreloc
;
1214 if (info
->relocateable
)
1217 hplink
= hppa_link_hash_table (info
);
1218 dynobj
= hplink
->root
.dynobj
;
1219 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1220 sym_hashes
= elf_sym_hashes (abfd
);
1221 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1225 rel_end
= relocs
+ sec
->reloc_count
;
1226 for (rel
= relocs
; rel
< rel_end
; rel
++)
1232 #if LONG_BRANCH_PIC_IN_SHLIB
1233 NEED_STUBREL
= 0, /* We won't be needing them in this case. */
1240 unsigned int r_symndx
, r_type
;
1241 struct elf32_hppa_link_hash_entry
*h
;
1244 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1246 if (r_symndx
< symtab_hdr
->sh_info
)
1249 h
= ((struct elf32_hppa_link_hash_entry
*)
1250 sym_hashes
[r_symndx
- symtab_hdr
->sh_info
]);
1252 r_type
= ELF32_R_TYPE (rel
->r_info
);
1256 case R_PARISC_DLTIND14F
:
1257 case R_PARISC_DLTIND14R
:
1258 case R_PARISC_DLTIND21L
:
1259 /* This symbol requires a global offset table entry. */
1260 need_entry
= NEED_GOT
;
1262 /* Mark this section as containing PIC code. */
1263 sec
->flags
|= SEC_HAS_GOT_REF
;
1266 case R_PARISC_PLABEL14R
: /* "Official" procedure labels. */
1267 case R_PARISC_PLABEL21L
:
1268 case R_PARISC_PLABEL32
:
1269 /* If the addend is non-zero, we break badly. */
1270 BFD_ASSERT (rel
->r_addend
== 0);
1272 /* If we are creating a shared library, then we need to
1273 create a PLT entry for all PLABELs, because PLABELs with
1274 local symbols may be passed via a pointer to another
1275 object. Additionally, output a dynamic relocation
1276 pointing to the PLT entry. */
1277 need_entry
= PLT_PLABEL
| NEED_PLT
| NEED_DYNREL
;
1280 case R_PARISC_PCREL12F
:
1281 case R_PARISC_PCREL17C
:
1282 case R_PARISC_PCREL17F
:
1283 case R_PARISC_PCREL22F
:
1284 /* Handle calls, and function pointers as they might need to
1285 go through the .plt, and might require long branch stubs. */
1288 /* We know local syms won't need a .plt entry, and if
1289 they need a long branch stub we can't guarantee that
1290 we can reach the stub. So just flag an error later
1291 if we're doing a shared link and find we need a long
1297 /* Global symbols will need a .plt entry if they remain
1298 global, and in most cases won't need a long branch
1299 stub. Unfortunately, we have to cater for the case
1300 where a symbol is forced local by versioning, or due
1301 to symbolic linking, and we lose the .plt entry. */
1302 need_entry
= NEED_PLT
| NEED_STUBREL
;
1306 case R_PARISC_SEGBASE
: /* Used to set segment base. */
1307 case R_PARISC_SEGREL32
: /* Relative reloc. */
1308 case R_PARISC_PCREL14F
: /* PC relative load/store. */
1309 case R_PARISC_PCREL14R
:
1310 case R_PARISC_PCREL17R
: /* External branches. */
1311 case R_PARISC_PCREL21L
: /* As above, and for load/store too. */
1312 /* We don't need to propagate the relocation if linking a
1313 shared object since these are section relative. */
1316 case R_PARISC_DPREL14F
: /* Used for gp rel data load/store. */
1317 case R_PARISC_DPREL14R
:
1318 case R_PARISC_DPREL21L
:
1321 (*_bfd_error_handler
)
1322 (_("%s: relocation %s can not be used when making a shared object; recompile with -fPIC"),
1323 bfd_get_filename (abfd
),
1324 elf_hppa_howto_table
[r_type
].name
);
1325 bfd_set_error (bfd_error_bad_value
);
1330 case R_PARISC_DIR17F
: /* Used for external branches. */
1331 case R_PARISC_DIR17R
:
1332 case R_PARISC_DIR14R
: /* Used for load/store from absolute locn. */
1333 case R_PARISC_DIR21L
: /* As above, and for ext branches too. */
1335 /* Help debug shared library creation. Any of the above
1336 relocs can be used in shared libs, but they may cause
1337 pages to become unshared. */
1340 (*_bfd_error_handler
)
1341 (_("%s: relocation %s should not be used when making a shared object; recompile with -fPIC"),
1342 bfd_get_filename (abfd
),
1343 elf_hppa_howto_table
[r_type
].name
);
1348 case R_PARISC_DIR32
: /* .word, PARISC.unwind relocs. */
1349 /* We may want to output a dynamic relocation later. */
1350 need_entry
= NEED_DYNREL
;
1353 /* This relocation describes the C++ object vtable hierarchy.
1354 Reconstruct it for later use during GC. */
1355 case R_PARISC_GNU_VTINHERIT
:
1356 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
,
1357 &h
->elf
, rel
->r_offset
))
1361 /* This relocation describes which C++ vtable entries are actually
1362 used. Record for later use during GC. */
1363 case R_PARISC_GNU_VTENTRY
:
1364 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
,
1365 &h
->elf
, rel
->r_offset
))
1373 /* Now carry out our orders. */
1374 if (need_entry
& NEED_GOT
)
1376 /* Allocate space for a GOT entry, as well as a dynamic
1377 relocation for this entry. */
1379 hplink
->root
.dynobj
= dynobj
= abfd
;
1381 if (hplink
->sgot
== NULL
)
1383 if (! elf32_hppa_create_dynamic_sections (dynobj
, info
))
1389 if (h
->elf
.got
.refcount
== -1)
1391 h
->elf
.got
.refcount
= 1;
1393 /* Make sure this symbol is output as a dynamic symbol. */
1394 if (h
->elf
.dynindx
== -1)
1396 if (! bfd_elf32_link_record_dynamic_symbol (info
,
1401 hplink
->sgot
->_raw_size
+= GOT_ENTRY_SIZE
;
1402 hplink
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
1405 h
->elf
.got
.refcount
+= 1;
1409 /* This is a global offset table entry for a local symbol. */
1410 if (local_got_refcounts
== NULL
)
1414 /* Allocate space for local got offsets and local
1415 plt offsets. Done this way to save polluting
1416 elf_obj_tdata with another target specific
1418 size
= symtab_hdr
->sh_info
* 2 * sizeof (bfd_signed_vma
);
1419 local_got_refcounts
= ((bfd_signed_vma
*)
1420 bfd_alloc (abfd
, size
));
1421 if (local_got_refcounts
== NULL
)
1423 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1424 memset (local_got_refcounts
, -1, size
);
1426 if (local_got_refcounts
[r_symndx
] == -1)
1428 local_got_refcounts
[r_symndx
] = 1;
1430 hplink
->sgot
->_raw_size
+= GOT_ENTRY_SIZE
;
1433 /* If we are generating a shared object, we need to
1434 output a reloc so that the dynamic linker can
1435 adjust this GOT entry (because the address
1436 the shared library is loaded at is not fixed). */
1437 hplink
->srelgot
->_raw_size
+=
1438 sizeof (Elf32_External_Rela
);
1442 local_got_refcounts
[r_symndx
] += 1;
1446 if (need_entry
& NEED_PLT
)
1448 /* If we are creating a shared library, and this is a reloc
1449 against a weak symbol or a global symbol in a dynamic
1450 object, then we will be creating an import stub and a
1451 .plt entry for the symbol. Similarly, on a normal link
1452 to symbols defined in a dynamic object we'll need the
1453 import stub and a .plt entry. We don't know yet whether
1454 the symbol is defined or not, so make an entry anyway and
1455 clean up later in adjust_dynamic_symbol. */
1456 if ((sec
->flags
& SEC_ALLOC
) != 0)
1460 if (h
->elf
.plt
.refcount
== -1)
1462 h
->elf
.plt
.refcount
= 1;
1463 h
->elf
.elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1466 h
->elf
.plt
.refcount
+= 1;
1468 /* If this .plt entry is for a plabel, we need an
1469 extra word for ld.so. adjust_dynamic_symbol will
1470 also keep the entry even if it appears to be
1472 if (need_entry
& PLT_PLABEL
)
1475 else if (need_entry
& PLT_PLABEL
)
1479 if (local_got_refcounts
== NULL
)
1483 /* Allocate space for local got offsets and local
1485 size
= symtab_hdr
->sh_info
* 2 * sizeof (bfd_signed_vma
);
1486 local_got_refcounts
= ((bfd_signed_vma
*)
1487 bfd_alloc (abfd
, size
));
1488 if (local_got_refcounts
== NULL
)
1490 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1491 memset (local_got_refcounts
, -1, size
);
1493 indx
= r_symndx
+ symtab_hdr
->sh_info
;
1494 if (local_got_refcounts
[indx
] == -1)
1495 local_got_refcounts
[indx
] = 1;
1497 local_got_refcounts
[indx
] += 1;
1502 if (need_entry
& (NEED_DYNREL
| NEED_STUBREL
))
1504 /* Flag this symbol as having a non-got, non-plt reference
1505 so that we generate copy relocs if it turns out to be
1508 h
->elf
.elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
1510 /* If we are creating a shared library then we need to copy
1511 the reloc into the shared library. However, if we are
1512 linking with -Bsymbolic, we need only copy absolute
1513 relocs or relocs against symbols that are not defined in
1514 an object we are including in the link. PC- or DP- or
1515 DLT-relative relocs against any local sym or global sym
1516 with DEF_REGULAR set, can be discarded. At this point we
1517 have not seen all the input files, so it is possible that
1518 DEF_REGULAR is not set now but will be set later (it is
1519 never cleared). We account for that possibility below by
1520 storing information in the reloc_entries field of the
1523 A similar situation to the -Bsymbolic case occurs when
1524 creating shared libraries and symbol visibility changes
1525 render the symbol local.
1527 As it turns out, all the relocs we will be creating here
1528 are absolute, so we cannot remove them on -Bsymbolic
1529 links or visibility changes anyway. A STUB_REL reloc
1530 is absolute too, as in that case it is the reloc in the
1531 stub we will be creating, rather than copying the PCREL
1532 reloc in the branch. */
1533 if ((sec
->flags
& SEC_ALLOC
) != 0
1535 #if RELATIVE_DYNAMIC_RELOCS
1537 || is_absolute_reloc (r_type
)
1539 && ((h
->elf
.elf_link_hash_flags
1540 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
1548 if ((need_entry
& NEED_STUBREL
))
1551 /* Create a reloc section in dynobj and make room for
1558 hplink
->root
.dynobj
= dynobj
= abfd
;
1560 name
= bfd_elf_string_from_elf_section
1562 elf_elfheader (abfd
)->e_shstrndx
,
1563 elf_section_data (sec
)->rel_hdr
.sh_name
);
1566 (*_bfd_error_handler
)
1567 (_("Could not find relocation section for %s"),
1569 bfd_set_error (bfd_error_bad_value
);
1573 if ((need_entry
& NEED_STUBREL
))
1575 size_t len
= strlen (name
) + sizeof (STUB_SUFFIX
);
1576 char *newname
= bfd_malloc (len
);
1578 if (newname
== NULL
)
1580 strcpy (newname
, name
);
1581 strcpy (newname
+ len
- sizeof (STUB_SUFFIX
),
1586 srel
= bfd_get_section_by_name (dynobj
, name
);
1591 srel
= bfd_make_section (dynobj
, name
);
1592 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
1593 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1594 if ((sec
->flags
& SEC_ALLOC
) != 0)
1595 flags
|= SEC_ALLOC
| SEC_LOAD
;
1597 || !bfd_set_section_flags (dynobj
, srel
, flags
)
1598 || !bfd_set_section_alignment (dynobj
, srel
, 2))
1601 else if ((need_entry
& NEED_STUBREL
))
1604 if ((need_entry
& NEED_STUBREL
))
1610 #if ! LONG_BRANCH_PIC_IN_SHLIB
1611 /* If this is a function call, we only need one dynamic
1612 reloc for the stub as all calls to a particular
1613 function will go through the same stub. Actually, a
1614 long branch stub needs two relocations, but we count
1615 on some intelligence on the part of the dynamic
1617 if ((need_entry
& NEED_STUBREL
))
1619 doit
= h
->stub_reloc_sec
!= stubreloc
;
1620 h
->stub_reloc_sec
= stubreloc
;
1628 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
1630 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
1631 /* Keep track of relocations we have entered for
1632 this global symbol, so that we can discard them
1633 later if necessary. */
1636 #if RELATIVE_DYNAMIC_RELOCS
1637 || ! is_absolute_reloc (rtype
)
1639 || (need_entry
& NEED_STUBREL
)))
1641 struct elf32_hppa_dyn_reloc_entry
*p
;
1643 for (p
= h
->reloc_entries
; p
!= NULL
; p
= p
->next
)
1644 if (p
->section
== srel
)
1649 p
= ((struct elf32_hppa_dyn_reloc_entry
*)
1650 bfd_alloc (dynobj
, sizeof *p
));
1653 p
->next
= h
->reloc_entries
;
1654 h
->reloc_entries
= p
;
1659 /* NEED_STUBREL and NEED_DYNREL are never both
1660 set. Leave the count at zero for the
1661 NEED_STUBREL case as we only ever have one
1662 stub reloc per section per symbol, and this
1663 simplifies code in hppa_discard_copies. */
1664 if (! (need_entry
& NEED_STUBREL
))
1677 /* Return the section that should be marked against garbage collection
1678 for a given relocation. */
1681 elf32_hppa_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
1683 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1684 Elf_Internal_Rela
*rel
;
1685 struct elf_link_hash_entry
*h
;
1686 Elf_Internal_Sym
*sym
;
1690 switch ((unsigned int) ELF32_R_TYPE (rel
->r_info
))
1692 case R_PARISC_GNU_VTINHERIT
:
1693 case R_PARISC_GNU_VTENTRY
:
1697 switch (h
->root
.type
)
1699 case bfd_link_hash_defined
:
1700 case bfd_link_hash_defweak
:
1701 return h
->root
.u
.def
.section
;
1703 case bfd_link_hash_common
:
1704 return h
->root
.u
.c
.p
->section
;
1713 if (!(elf_bad_symtab (abfd
)
1714 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
1715 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
1716 && sym
->st_shndx
!= SHN_COMMON
))
1718 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
1726 /* Update the got and plt entry reference counts for the section being
1730 elf32_hppa_gc_sweep_hook (abfd
, info
, sec
, relocs
)
1732 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1734 const Elf_Internal_Rela
*relocs
;
1736 Elf_Internal_Shdr
*symtab_hdr
;
1737 struct elf_link_hash_entry
**sym_hashes
;
1738 bfd_signed_vma
*local_got_refcounts
;
1739 bfd_signed_vma
*local_plt_refcounts
;
1740 const Elf_Internal_Rela
*rel
, *relend
;
1741 unsigned long r_symndx
;
1742 struct elf_link_hash_entry
*h
;
1743 struct elf32_hppa_link_hash_table
*hplink
;
1748 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1749 sym_hashes
= elf_sym_hashes (abfd
);
1750 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1751 local_plt_refcounts
= local_got_refcounts
;
1752 if (local_plt_refcounts
!= NULL
)
1753 local_plt_refcounts
+= symtab_hdr
->sh_info
;
1754 hplink
= hppa_link_hash_table (info
);
1755 dynobj
= hplink
->root
.dynobj
;
1759 sgot
= hplink
->sgot
;
1760 srelgot
= hplink
->srelgot
;
1762 relend
= relocs
+ sec
->reloc_count
;
1763 for (rel
= relocs
; rel
< relend
; rel
++)
1764 switch ((unsigned int) ELF32_R_TYPE (rel
->r_info
))
1766 case R_PARISC_DLTIND14F
:
1767 case R_PARISC_DLTIND14R
:
1768 case R_PARISC_DLTIND21L
:
1769 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1770 if (r_symndx
>= symtab_hdr
->sh_info
)
1772 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1773 if (h
->got
.refcount
> 0)
1775 h
->got
.refcount
-= 1;
1776 if (h
->got
.refcount
== 0)
1778 sgot
->_raw_size
-= GOT_ENTRY_SIZE
;
1779 srelgot
->_raw_size
-= sizeof (Elf32_External_Rela
);
1783 else if (local_got_refcounts
!= NULL
)
1785 if (local_got_refcounts
[r_symndx
] > 0)
1787 local_got_refcounts
[r_symndx
] -= 1;
1788 if (local_got_refcounts
[r_symndx
] == 0)
1790 sgot
->_raw_size
-= GOT_ENTRY_SIZE
;
1792 srelgot
->_raw_size
-= sizeof (Elf32_External_Rela
);
1798 case R_PARISC_PCREL12F
:
1799 case R_PARISC_PCREL17C
:
1800 case R_PARISC_PCREL17F
:
1801 case R_PARISC_PCREL22F
:
1802 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1803 if (r_symndx
>= symtab_hdr
->sh_info
)
1805 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1806 if (h
->plt
.refcount
> 0)
1807 h
->plt
.refcount
-= 1;
1811 case R_PARISC_PLABEL14R
:
1812 case R_PARISC_PLABEL21L
:
1813 case R_PARISC_PLABEL32
:
1814 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1815 if (r_symndx
>= symtab_hdr
->sh_info
)
1817 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1818 if (h
->plt
.refcount
> 0)
1819 h
->plt
.refcount
-= 1;
1821 else if (local_plt_refcounts
!= NULL
)
1823 if (local_plt_refcounts
[r_symndx
] > 0)
1824 local_plt_refcounts
[r_symndx
] -= 1;
1836 /* Our own version of hide_symbol, so that we can keep plt entries for
1840 elf32_hppa_hide_symbol (info
, h
)
1841 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1842 struct elf_link_hash_entry
*h
;
1845 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
)
1847 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1848 h
->plt
.offset
= (bfd_vma
) -1;
1853 /* Adjust a symbol defined by a dynamic object and referenced by a
1854 regular object. The current definition is in some section of the
1855 dynamic object, but we're not including those sections. We have to
1856 change the definition to something the rest of the link can
1860 elf32_hppa_adjust_dynamic_symbol (info
, h
)
1861 struct bfd_link_info
*info
;
1862 struct elf_link_hash_entry
*h
;
1865 struct elf32_hppa_link_hash_table
*hplink
;
1868 hplink
= hppa_link_hash_table (info
);
1869 dynobj
= hplink
->root
.dynobj
;
1871 /* If this is a function, put it in the procedure linkage table. We
1872 will fill in the contents of the procedure linkage table later,
1873 when we know the address of the .got section. */
1874 if (h
->type
== STT_FUNC
1875 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1877 if (h
->plt
.refcount
<= 0
1878 || ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
1879 && h
->root
.type
!= bfd_link_hash_defweak
1880 && ! ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
1881 && (!info
->shared
|| info
->symbolic
)))
1883 /* The .plt entry is not needed when:
1884 a) Garbage collection has removed all references to the
1886 b) We know for certain the symbol is defined in this
1887 object, and it's not a weak definition, nor is the symbol
1888 used by a plabel relocation. Either this object is the
1889 application or we are doing a shared symbolic link. */
1891 /* As a special sop to the hppa ABI, we keep a .plt entry
1892 for functions in sections containing PIC code. */
1894 && h
->plt
.refcount
> 0
1895 && (h
->root
.type
== bfd_link_hash_defined
1896 || h
->root
.type
== bfd_link_hash_defweak
)
1897 && (h
->root
.u
.def
.section
->flags
& SEC_HAS_GOT_REF
) != 0)
1899 ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
= 1;
1903 h
->plt
.offset
= (bfd_vma
) -1;
1904 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1909 /* Make an entry in the .plt section. */
1911 h
->plt
.offset
= s
->_raw_size
;
1912 if (PLABEL_PLT_ENTRY_SIZE
!= PLT_ENTRY_SIZE
1913 && ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
1914 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1916 /* Add some extra space for the dynamic linker to use. */
1917 s
->_raw_size
+= PLABEL_PLT_ENTRY_SIZE
;
1920 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1922 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
)
1924 /* Make sure this symbol is output as a dynamic symbol. */
1925 if (h
->dynindx
== -1
1926 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1928 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1932 /* We also need to make an entry in the .rela.plt section. */
1933 s
= hplink
->srelplt
;
1934 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
1939 /* If this is a weak symbol, and there is a real definition, the
1940 processor independent code will have arranged for us to see the
1941 real definition first, and we can just use the same value. */
1942 if (h
->weakdef
!= NULL
)
1944 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
1945 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
1946 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1947 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1951 /* This is a reference to a symbol defined by a dynamic object which
1952 is not a function. */
1954 /* If we are creating a shared library, we must presume that the
1955 only references to the symbol are via the global offset table.
1956 For such cases we need not do anything here; the relocations will
1957 be handled correctly by relocate_section. */
1961 /* If there are no references to this symbol that do not use the
1962 GOT, we don't need to generate a copy reloc. */
1963 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
1966 /* We must allocate the symbol in our .dynbss section, which will
1967 become part of the .bss section of the executable. There will be
1968 an entry for this symbol in the .dynsym section. The dynamic
1969 object will contain position independent code, so all references
1970 from the dynamic object to this symbol will go through the global
1971 offset table. The dynamic linker will use the .dynsym entry to
1972 determine the address it must put in the global offset table, so
1973 both the dynamic object and the regular object will refer to the
1974 same memory location for the variable. */
1976 s
= hplink
->sdynbss
;
1978 /* We must generate a COPY reloc to tell the dynamic linker to
1979 copy the initial value out of the dynamic object and into the
1980 runtime process image. We need to remember the offset into the
1981 .rela.bss section we are going to use. */
1982 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1986 srel
= hplink
->srelbss
;
1987 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
1988 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
1992 /* We need to figure out the alignment required for this symbol. I
1993 have no idea how other ELF linkers handle this. */
1994 unsigned int power_of_two
;
1996 power_of_two
= bfd_log2 (h
->size
);
1997 if (power_of_two
> 3)
2000 /* Apply the required alignment. */
2001 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
2002 (bfd_size_type
) (1 << power_of_two
));
2003 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
2005 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
2009 /* Define the symbol as being at this point in the section. */
2010 h
->root
.u
.def
.section
= s
;
2011 h
->root
.u
.def
.value
= s
->_raw_size
;
2013 /* Increment the section size to make room for the symbol. */
2014 s
->_raw_size
+= h
->size
;
2020 /* Called via elf_link_hash_traverse to create .plt entries for an
2021 application that uses statically linked PIC functions. Similar to
2022 the first part of elf32_hppa_adjust_dynamic_symbol. */
2025 hppa_handle_PIC_calls (h
, inf
)
2026 struct elf_link_hash_entry
*h
;
2029 struct bfd_link_info
*info
;
2031 struct elf32_hppa_link_hash_table
*hplink
;
2034 if (! (h
->plt
.refcount
> 0
2035 && (h
->root
.type
== bfd_link_hash_defined
2036 || h
->root
.type
== bfd_link_hash_defweak
)
2037 && (h
->root
.u
.def
.section
->flags
& SEC_HAS_GOT_REF
) != 0))
2039 h
->plt
.offset
= (bfd_vma
) -1;
2040 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2044 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2045 ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
= 1;
2047 info
= (struct bfd_link_info
*) inf
;
2048 hplink
= hppa_link_hash_table (info
);
2049 dynobj
= hplink
->root
.dynobj
;
2051 /* Make an entry in the .plt section. */
2053 h
->plt
.offset
= s
->_raw_size
;
2054 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2060 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
2061 || RELATIVE_DYNAMIC_RELOCS)
2062 /* This function is called via elf_link_hash_traverse to discard space
2063 we allocated for relocs that it turned out we didn't need. */
2066 hppa_discard_copies (h
, inf
)
2067 struct elf_link_hash_entry
*h
;
2070 struct elf32_hppa_dyn_reloc_entry
*s
;
2071 struct elf32_hppa_link_hash_entry
*eh
;
2072 struct bfd_link_info
*info
;
2074 eh
= (struct elf32_hppa_link_hash_entry
*) h
;
2075 info
= (struct bfd_link_info
*) inf
;
2077 #if ! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT
2078 /* Handle the stub reloc case. If we have a plt entry for the
2079 function, we won't be needing long branch stubs. s->count will
2080 only be zero for stub relocs, which provides a handy way of
2081 flagging these relocs, and means we need do nothing special for
2082 the forced local and symbolic link case. */
2083 if (eh
->stub_reloc_sec
!= NULL
2084 && eh
->elf
.plt
.offset
!= (bfd_vma
) -1)
2086 for (s
= eh
->reloc_entries
; s
!= NULL
; s
= s
->next
)
2088 s
->section
->_raw_size
-= sizeof (Elf32_External_Rela
);
2092 #if RELATIVE_DYNAMIC_RELOCS
2093 /* If a symbol has been forced local or we have found a regular
2094 definition for the symbolic link case, then we won't be needing
2096 if (eh
->elf
.dynindx
== -1
2097 || ((eh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
2098 && !is_absolute_reloc (r_type
)
2101 for (s
= eh
->reloc_entries
; s
!= NULL
; s
= s
->next
)
2102 s
->section
->_raw_size
-= s
->count
* sizeof (Elf32_External_Rela
);
2111 /* This function is called via elf_link_hash_traverse to force
2112 millicode symbols local so they do not end up as globals in the
2113 dynamic symbol table. We ought to be able to do this in
2114 adjust_dynamic_symbol, but our adjust_dynamic_symbol is not called
2115 for all dynamic symbols. Arguably, this is a bug in
2116 elf_adjust_dynamic_symbol. */
2119 clobber_millicode_symbols (h
, info
)
2120 struct elf_link_hash_entry
*h
;
2121 struct bfd_link_info
*info
;
2123 /* Note! We only want to remove these from the dynamic symbol
2124 table. Therefore we do not set ELF_LINK_FORCED_LOCAL. */
2125 if (h
->type
== STT_PARISC_MILLI
)
2126 elf32_hppa_hide_symbol(info
, h
);
2131 /* Set the sizes of the dynamic sections. */
2134 elf32_hppa_size_dynamic_sections (output_bfd
, info
)
2136 struct bfd_link_info
*info
;
2138 struct elf32_hppa_link_hash_table
*hplink
;
2144 hplink
= hppa_link_hash_table (info
);
2145 dynobj
= hplink
->root
.dynobj
;
2146 BFD_ASSERT (dynobj
!= NULL
);
2148 if (hplink
->root
.dynamic_sections_created
)
2150 const char *funcname
;
2153 /* Set the contents of the .interp section to the interpreter. */
2156 s
= bfd_get_section_by_name (dynobj
, ".interp");
2157 BFD_ASSERT (s
!= NULL
);
2158 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2159 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2162 /* Force millicode symbols local. */
2163 elf_link_hash_traverse (&hplink
->root
,
2164 clobber_millicode_symbols
,
2167 /* DT_INIT and DT_FINI need a .plt entry. Make sure they have
2169 funcname
= info
->init_function
;
2172 if (funcname
!= NULL
)
2174 struct elf_link_hash_entry
*h
;
2176 h
= elf_link_hash_lookup (&hplink
->root
,
2178 false, false, false);
2180 && (h
->elf_link_hash_flags
& (ELF_LINK_HASH_REF_REGULAR
2181 | ELF_LINK_HASH_DEF_REGULAR
)))
2183 if (h
->plt
.refcount
<= 0)
2185 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2187 /* Make an entry in the .plt section. We know
2188 the function doesn't have a plabel by the
2191 h
->plt
.offset
= s
->_raw_size
;
2192 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2194 /* Make sure this symbol is output as a dynamic
2196 if (h
->dynindx
== -1)
2198 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
2202 /* Make an entry for the reloc too. */
2203 s
= hplink
->srelplt
;
2204 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
2207 ((struct elf32_hppa_link_hash_entry
*) h
)->plt_abs
= 1;
2210 if (funcname
== info
->fini_function
)
2212 funcname
= info
->fini_function
;
2215 /* Set up .plt offsets for local plabels. */
2216 for (i
= info
->input_bfds
; i
; i
= i
->link_next
)
2218 bfd_signed_vma
*local_plt
;
2219 bfd_signed_vma
*end_local_plt
;
2220 bfd_size_type locsymcount
;
2221 Elf_Internal_Shdr
*symtab_hdr
;
2223 local_plt
= elf_local_got_refcounts (i
);
2227 symtab_hdr
= &elf_tdata (i
)->symtab_hdr
;
2228 locsymcount
= symtab_hdr
->sh_info
;
2229 local_plt
+= locsymcount
;
2230 end_local_plt
= local_plt
+ locsymcount
;
2232 for (; local_plt
< end_local_plt
; ++local_plt
)
2237 *local_plt
= s
->_raw_size
;
2238 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2240 hplink
->srelplt
->_raw_size
+= sizeof (Elf32_External_Rela
);
2243 *local_plt
= (bfd_vma
) -1;
2249 /* Run through the function symbols, looking for any that are
2250 PIC, and allocate space for the necessary .plt entries so
2251 that %r19 will be set up. */
2253 elf_link_hash_traverse (&hplink
->root
,
2254 hppa_handle_PIC_calls
,
2257 /* We may have created entries in the .rela.got section.
2258 However, if we are not creating the dynamic sections, we will
2259 not actually use these entries. Reset the size of .rela.got,
2260 which will cause it to get stripped from the output file
2262 hplink
->srelgot
->_raw_size
= 0;
2265 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
2266 || RELATIVE_DYNAMIC_RELOCS)
2267 /* If this is a -Bsymbolic shared link, then we need to discard all
2268 relocs against symbols defined in a regular object. We also need
2269 to lose relocs we've allocated for long branch stubs if we know
2270 we won't be generating a stub. */
2272 elf_link_hash_traverse (&hplink
->root
,
2273 hppa_discard_copies
,
2277 /* The check_relocs and adjust_dynamic_symbol entry points have
2278 determined the sizes of the various dynamic sections. Allocate
2282 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2286 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2289 /* It's OK to base decisions on the section name, because none
2290 of the dynobj section names depend upon the input files. */
2291 name
= bfd_get_section_name (dynobj
, s
);
2293 if (strncmp (name
, ".rela", 5) == 0)
2295 if (s
->_raw_size
!= 0)
2299 /* Remember whether there are any reloc sections other
2301 if (strcmp (name
+5, ".plt") != 0)
2303 const char *outname
;
2307 /* If this relocation section applies to a read only
2308 section, then we probably need a DT_TEXTREL
2309 entry. The entries in the .rela.plt section
2310 really apply to the .got section, which we
2311 created ourselves and so know is not readonly. */
2312 outname
= bfd_get_section_name (output_bfd
,
2314 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
2316 && (target
->flags
& SEC_READONLY
) != 0
2317 && (target
->flags
& SEC_ALLOC
) != 0)
2321 /* We use the reloc_count field as a counter if we need
2322 to copy relocs into the output file. */
2326 else if (strcmp (name
, ".plt") == 0)
2328 else if (strcmp (name
, ".got") == 0)
2332 /* It's not one of our sections, so don't allocate space. */
2336 if (s
->_raw_size
== 0)
2338 /* If we don't need this section, strip it from the
2339 output file. This is mostly to handle .rela.bss and
2340 .rela.plt. We must create both sections in
2341 create_dynamic_sections, because they must be created
2342 before the linker maps input sections to output
2343 sections. The linker does that before
2344 adjust_dynamic_symbol is called, and it is that
2345 function which decides whether anything needs to go
2346 into these sections. */
2347 _bfd_strip_section_from_output (info
, s
);
2351 /* Allocate memory for the section contents. Zero it, because
2352 we may not fill in all the reloc sections. */
2353 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
2354 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
2358 if (hplink
->root
.dynamic_sections_created
)
2360 /* Like IA-64 and HPPA64, always create a DT_PLTGOT. It
2361 actually has nothing to do with the PLT, it is how we
2362 communicate the LTP value of a load module to the dynamic
2364 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
2367 /* Add some entries to the .dynamic section. We fill in the
2368 values later, in elf32_hppa_finish_dynamic_sections, but we
2369 must add the entries now so that we get the correct size for
2370 the .dynamic section. The DT_DEBUG entry is filled in by the
2371 dynamic linker and used by the debugger. */
2374 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
2378 if (hplink
->srelplt
->_raw_size
!= 0)
2380 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
2381 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
2382 || ! bfd_elf32_add_dynamic_entry (info
, DT_JMPREL
, 0))
2388 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELA
, 0)
2389 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELASZ
, 0)
2390 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELAENT
,
2391 sizeof (Elf32_External_Rela
)))
2397 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
2399 info
->flags
|= DF_TEXTREL
;
2407 /* External entry points for sizing and building linker stubs. */
2409 /* Determine and set the size of the stub section for a final link.
2411 The basic idea here is to examine all the relocations looking for
2412 PC-relative calls to a target that is unreachable with a "bl"
2416 elf32_hppa_size_stubs (output_bfd
, stub_bfd
, info
, multi_subspace
,
2417 add_stub_section
, layout_sections_again
)
2420 struct bfd_link_info
*info
;
2421 boolean multi_subspace
;
2422 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
2423 void (*layout_sections_again
) PARAMS ((void));
2427 asection
**input_list
, **list
;
2428 Elf_Internal_Sym
*local_syms
, **all_local_syms
;
2429 unsigned int bfd_indx
, bfd_count
;
2430 int top_id
, top_index
;
2431 struct elf32_hppa_link_hash_table
*hplink
;
2432 boolean stub_changed
= 0;
2435 hplink
= hppa_link_hash_table (info
);
2437 /* Stash our params away. */
2438 hplink
->stub_bfd
= stub_bfd
;
2439 hplink
->multi_subspace
= multi_subspace
;
2440 hplink
->add_stub_section
= add_stub_section
;
2441 hplink
->layout_sections_again
= layout_sections_again
;
2443 /* Count the number of input BFDs and find the top input section id. */
2444 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
2446 input_bfd
= input_bfd
->link_next
)
2449 for (section
= input_bfd
->sections
;
2451 section
= section
->next
)
2453 if (top_id
< section
->id
)
2454 top_id
= section
->id
;
2459 = (struct map_stub
*) bfd_zmalloc (sizeof (struct map_stub
) * (top_id
+ 1));
2460 if (hplink
->stub_group
== NULL
)
2463 /* Make a list of input sections for each output section included in
2466 We can't use output_bfd->section_count here to find the top output
2467 section index as some sections may have been removed, and
2468 _bfd_strip_section_from_output doesn't renumber the indices. */
2469 for (section
= output_bfd
->sections
, top_index
= 0;
2471 section
= section
->next
)
2473 if (top_index
< section
->index
)
2474 top_index
= section
->index
;
2478 = (asection
**) bfd_malloc (sizeof (asection
*) * (top_index
+ 1));
2479 if (input_list
== NULL
)
2482 /* For sections we aren't interested in, mark their entries with a
2483 value we can check later. */
2484 list
= input_list
+ top_index
;
2486 *list
= bfd_abs_section_ptr
;
2487 while (list
-- != input_list
);
2489 for (section
= output_bfd
->sections
;
2491 section
= section
->next
)
2493 if ((section
->flags
& SEC_CODE
) != 0 && section
->index
<= top_index
)
2494 input_list
[section
->index
] = NULL
;
2497 /* Now actually build the lists. */
2498 for (input_bfd
= info
->input_bfds
;
2500 input_bfd
= input_bfd
->link_next
)
2502 for (section
= input_bfd
->sections
;
2504 section
= section
->next
)
2506 if (section
->output_section
!= NULL
2507 && section
->output_section
->owner
== output_bfd
2508 && section
->output_section
->index
<= top_index
)
2510 list
= input_list
+ section
->output_section
->index
;
2511 if (*list
!= bfd_abs_section_ptr
)
2513 /* Steal the link_sec pointer for our list. */
2514 #define PREV_SEC(sec) (hplink->stub_group[(sec)->id].link_sec)
2515 /* This happens to make the list in reverse order,
2516 which is what we want. */
2517 PREV_SEC (section
) = *list
;
2524 /* See whether we can group stub sections together. Grouping stub
2525 sections may result in fewer stubs. More importantly, we need to
2526 put all .init* and .fini* stubs at the beginning of the .init or
2527 .fini output sections respectively, because glibc splits the
2528 _init and _fini functions into multiple parts. Putting a stub in
2529 the middle of a function is not a good idea. */
2530 list
= input_list
+ top_index
;
2533 asection
*tail
= *list
;
2534 if (tail
== bfd_abs_section_ptr
)
2536 while (tail
!= NULL
)
2540 bfd_size_type total
;
2543 if (tail
->_cooked_size
)
2544 total
= tail
->_cooked_size
;
2546 total
= tail
->_raw_size
;
2547 while ((prev
= PREV_SEC (curr
)) != NULL
2548 && ((total
+= curr
->output_offset
- prev
->output_offset
)
2552 /* OK, the size from the start of CURR to the end is less
2553 than 250000 bytes and thus can be handled by one stub
2554 section. (or the tail section is itself larger than
2555 250000 bytes, in which case we may be toast.)
2556 We should really be keeping track of the total size of
2557 stubs added here, as stubs contribute to the final output
2558 section size. That's a little tricky, and this way will
2559 only break if stubs added total more than 12144 bytes, or
2560 1518 long branch stubs. It seems unlikely for more than
2561 1518 different functions to be called, especially from
2562 code only 250000 bytes long. */
2565 prev
= PREV_SEC (tail
);
2566 /* Set up this stub group. */
2567 hplink
->stub_group
[tail
->id
].link_sec
= curr
;
2569 while (tail
!= curr
&& (tail
= prev
) != NULL
);
2571 /* But wait, there's more! Input sections up to 250000
2572 bytes before the stub section can be handled by it too. */
2575 && ((total
+= tail
->output_offset
- prev
->output_offset
)
2579 prev
= PREV_SEC (tail
);
2580 hplink
->stub_group
[tail
->id
].link_sec
= curr
;
2585 while (list
-- != input_list
);
2589 /* We want to read in symbol extension records only once. To do this
2590 we need to read in the local symbols in parallel and save them for
2591 later use; so hold pointers to the local symbols in an array. */
2593 = (Elf_Internal_Sym
**) bfd_zmalloc (sizeof (Elf_Internal_Sym
*)
2595 if (all_local_syms
== NULL
)
2598 /* Walk over all the input BFDs, swapping in local symbols.
2599 If we are creating a shared library, create hash entries for the
2601 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
2603 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
2605 Elf_Internal_Shdr
*symtab_hdr
;
2606 Elf_Internal_Sym
*isym
;
2607 Elf32_External_Sym
*ext_syms
, *esym
, *end_sy
;
2609 /* We'll need the symbol table in a second. */
2610 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2611 if (symtab_hdr
->sh_info
== 0)
2614 /* We need an array of the local symbols attached to the input bfd.
2615 Unfortunately, we're going to have to read & swap them in. */
2616 local_syms
= (Elf_Internal_Sym
*)
2617 bfd_malloc (symtab_hdr
->sh_info
* sizeof (Elf_Internal_Sym
));
2618 if (local_syms
== NULL
)
2620 goto error_ret_free_local
;
2622 all_local_syms
[bfd_indx
] = local_syms
;
2623 ext_syms
= (Elf32_External_Sym
*)
2624 bfd_malloc (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
));
2625 if (ext_syms
== NULL
)
2627 goto error_ret_free_local
;
2630 if (bfd_seek (input_bfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
2631 || (bfd_read (ext_syms
, 1,
2632 (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
)),
2634 != (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
))))
2637 goto error_ret_free_local
;
2640 /* Swap the local symbols in. */
2643 for (end_sy
= esym
+ symtab_hdr
->sh_info
; esym
< end_sy
; esym
++, isym
++)
2644 bfd_elf32_swap_symbol_in (input_bfd
, esym
, isym
);
2646 /* Now we can free the external symbols. */
2649 #if ! LONG_BRANCH_PIC_IN_SHLIB
2650 /* If this is a shared link, find all the stub reloc sections. */
2652 for (section
= input_bfd
->sections
;
2654 section
= section
->next
)
2657 asection
*reloc_sec
;
2659 name
= bfd_malloc (strlen (section
->name
)
2660 + sizeof STUB_SUFFIX
2664 sprintf (name
, ".rela%s%s", section
->name
, STUB_SUFFIX
);
2665 reloc_sec
= bfd_get_section_by_name (hplink
->root
.dynobj
, name
);
2666 hplink
->stub_group
[section
->id
].reloc_sec
= reloc_sec
;
2671 if (info
->shared
&& hplink
->multi_subspace
)
2673 struct elf_link_hash_entry
**sym_hashes
;
2674 struct elf_link_hash_entry
**end_hashes
;
2675 unsigned int symcount
;
2677 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
2678 - symtab_hdr
->sh_info
);
2679 sym_hashes
= elf_sym_hashes (input_bfd
);
2680 end_hashes
= sym_hashes
+ symcount
;
2682 /* Look through the global syms for functions; We need to
2683 build export stubs for all globally visible functions. */
2684 for (; sym_hashes
< end_hashes
; sym_hashes
++)
2686 struct elf32_hppa_link_hash_entry
*hash
;
2688 hash
= (struct elf32_hppa_link_hash_entry
*) *sym_hashes
;
2690 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
2691 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
2692 hash
= ((struct elf32_hppa_link_hash_entry
*)
2693 hash
->elf
.root
.u
.i
.link
);
2695 /* At this point in the link, undefined syms have been
2696 resolved, so we need to check that the symbol was
2697 defined in this BFD. */
2698 if ((hash
->elf
.root
.type
== bfd_link_hash_defined
2699 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
2700 && hash
->elf
.type
== STT_FUNC
2701 && hash
->elf
.root
.u
.def
.section
->output_section
!= NULL
2702 && (hash
->elf
.root
.u
.def
.section
->output_section
->owner
2704 && hash
->elf
.root
.u
.def
.section
->owner
== input_bfd
2705 && (hash
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
2706 && !(hash
->elf
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
2707 && ELF_ST_VISIBILITY (hash
->elf
.other
) == STV_DEFAULT
)
2710 const char *stub_name
;
2711 struct elf32_hppa_stub_hash_entry
*stub_entry
;
2713 sec
= hash
->elf
.root
.u
.def
.section
;
2714 stub_name
= hash
->elf
.root
.root
.string
;
2715 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
,
2718 if (stub_entry
== NULL
)
2720 stub_entry
= hppa_add_stub (stub_name
, sec
, hplink
);
2722 goto error_ret_free_local
;
2724 stub_entry
->target_value
= hash
->elf
.root
.u
.def
.value
;
2725 stub_entry
->target_section
= hash
->elf
.root
.u
.def
.section
;
2726 stub_entry
->stub_type
= hppa_stub_export
;
2727 stub_entry
->h
= hash
;
2732 (*_bfd_error_handler
) (_("%s: duplicate export stub %s"),
2733 bfd_get_filename (input_bfd
),
2745 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
2747 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
2749 Elf_Internal_Shdr
*symtab_hdr
;
2751 /* We'll need the symbol table in a second. */
2752 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2753 if (symtab_hdr
->sh_info
== 0)
2756 local_syms
= all_local_syms
[bfd_indx
];
2758 /* Walk over each section attached to the input bfd. */
2759 for (section
= input_bfd
->sections
;
2761 section
= section
->next
)
2763 Elf_Internal_Shdr
*input_rel_hdr
;
2764 Elf32_External_Rela
*external_relocs
, *erelaend
, *erela
;
2765 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
2767 /* If there aren't any relocs, then there's nothing more
2769 if ((section
->flags
& SEC_RELOC
) == 0
2770 || section
->reloc_count
== 0)
2773 /* If this section is a link-once section that will be
2774 discarded, then don't create any stubs. */
2775 if (section
->output_section
== NULL
2776 || section
->output_section
->owner
!= output_bfd
)
2779 /* Allocate space for the external relocations. */
2781 = ((Elf32_External_Rela
*)
2782 bfd_malloc (section
->reloc_count
2783 * sizeof (Elf32_External_Rela
)));
2784 if (external_relocs
== NULL
)
2786 goto error_ret_free_local
;
2789 /* Likewise for the internal relocations. */
2790 internal_relocs
= ((Elf_Internal_Rela
*)
2791 bfd_malloc (section
->reloc_count
2792 * sizeof (Elf_Internal_Rela
)));
2793 if (internal_relocs
== NULL
)
2795 free (external_relocs
);
2796 goto error_ret_free_local
;
2799 /* Read in the external relocs. */
2800 input_rel_hdr
= &elf_section_data (section
)->rel_hdr
;
2801 if (bfd_seek (input_bfd
, input_rel_hdr
->sh_offset
, SEEK_SET
) != 0
2802 || bfd_read (external_relocs
, 1,
2803 input_rel_hdr
->sh_size
,
2804 input_bfd
) != input_rel_hdr
->sh_size
)
2806 free (external_relocs
);
2807 error_ret_free_internal
:
2808 free (internal_relocs
);
2809 goto error_ret_free_local
;
2812 /* Swap in the relocs. */
2813 erela
= external_relocs
;
2814 erelaend
= erela
+ section
->reloc_count
;
2815 irela
= internal_relocs
;
2816 for (; erela
< erelaend
; erela
++, irela
++)
2817 bfd_elf32_swap_reloca_in (input_bfd
, erela
, irela
);
2819 /* We're done with the external relocs, free them. */
2820 free (external_relocs
);
2822 /* Now examine each relocation. */
2823 irela
= internal_relocs
;
2824 irelaend
= irela
+ section
->reloc_count
;
2825 for (; irela
< irelaend
; irela
++)
2827 unsigned int r_type
, r_indx
;
2828 enum elf32_hppa_stub_type stub_type
;
2829 struct elf32_hppa_stub_hash_entry
*stub_entry
;
2832 bfd_vma destination
;
2833 struct elf32_hppa_link_hash_entry
*hash
;
2835 const asection
*id_sec
;
2837 r_type
= ELF32_R_TYPE (irela
->r_info
);
2838 r_indx
= ELF32_R_SYM (irela
->r_info
);
2840 if (r_type
>= (unsigned int) R_PARISC_UNIMPLEMENTED
)
2842 bfd_set_error (bfd_error_bad_value
);
2843 goto error_ret_free_internal
;
2846 /* Only look for stubs on call instructions. */
2847 if (r_type
!= (unsigned int) R_PARISC_PCREL12F
2848 && r_type
!= (unsigned int) R_PARISC_PCREL17F
2849 && r_type
!= (unsigned int) R_PARISC_PCREL22F
)
2852 /* Now determine the call target, its name, value,
2858 if (r_indx
< symtab_hdr
->sh_info
)
2860 /* It's a local symbol. */
2861 Elf_Internal_Sym
*sym
;
2862 Elf_Internal_Shdr
*hdr
;
2864 sym
= local_syms
+ r_indx
;
2865 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
2866 sym_sec
= hdr
->bfd_section
;
2867 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
2868 sym_value
= sym
->st_value
;
2869 destination
= (sym_value
+ irela
->r_addend
2870 + sym_sec
->output_offset
2871 + sym_sec
->output_section
->vma
);
2875 /* It's an external symbol. */
2878 e_indx
= r_indx
- symtab_hdr
->sh_info
;
2879 hash
= ((struct elf32_hppa_link_hash_entry
*)
2880 elf_sym_hashes (input_bfd
)[e_indx
]);
2882 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
2883 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
2884 hash
= ((struct elf32_hppa_link_hash_entry
*)
2885 hash
->elf
.root
.u
.i
.link
);
2887 if (hash
->elf
.root
.type
== bfd_link_hash_defined
2888 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
2890 sym_sec
= hash
->elf
.root
.u
.def
.section
;
2891 sym_value
= hash
->elf
.root
.u
.def
.value
;
2892 if (sym_sec
->output_section
!= NULL
)
2893 destination
= (sym_value
+ irela
->r_addend
2894 + sym_sec
->output_offset
2895 + sym_sec
->output_section
->vma
);
2897 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
)
2902 else if (hash
->elf
.root
.type
== bfd_link_hash_undefined
)
2905 && !info
->no_undefined
2906 && (ELF_ST_VISIBILITY (hash
->elf
.other
)
2912 bfd_set_error (bfd_error_bad_value
);
2913 goto error_ret_free_internal
;
2917 /* Determine what (if any) linker stub is needed. */
2918 stub_type
= hppa_type_of_stub (section
, irela
, hash
,
2920 if (stub_type
== hppa_stub_none
)
2923 /* Support for grouping stub sections. */
2924 id_sec
= hplink
->stub_group
[section
->id
].link_sec
;
2926 /* Get the name of this stub. */
2927 stub_name
= hppa_stub_name (id_sec
, sym_sec
, hash
, irela
);
2929 goto error_ret_free_internal
;
2931 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
,
2934 if (stub_entry
!= NULL
)
2936 /* The proper stub has already been created. */
2941 stub_entry
= hppa_add_stub (stub_name
, section
, hplink
);
2942 if (stub_entry
== NULL
)
2945 goto error_ret_free_local
;
2948 stub_entry
->target_value
= sym_value
;
2949 stub_entry
->target_section
= sym_sec
;
2950 stub_entry
->stub_type
= stub_type
;
2953 if (stub_type
== hppa_stub_import
)
2954 stub_entry
->stub_type
= hppa_stub_import_shared
;
2955 else if (stub_type
== hppa_stub_long_branch
2956 && (LONG_BRANCH_PIC_IN_SHLIB
|| hash
== NULL
))
2957 stub_entry
->stub_type
= hppa_stub_long_branch_shared
;
2959 stub_entry
->h
= hash
;
2963 /* We're done with the internal relocs, free them. */
2964 free (internal_relocs
);
2971 /* OK, we've added some stubs. Find out the new size of the
2973 for (stub_sec
= hplink
->stub_bfd
->sections
;
2975 stub_sec
= stub_sec
->next
)
2977 stub_sec
->_raw_size
= 0;
2978 stub_sec
->_cooked_size
= 0;
2980 #if ! LONG_BRANCH_PIC_IN_SHLIB
2984 for (i
= top_id
; i
>= 0; --i
)
2986 /* This will probably hit the same section many times.. */
2987 stub_sec
= hplink
->stub_group
[i
].reloc_sec
;
2988 if (stub_sec
!= NULL
)
2990 stub_sec
->_raw_size
= 0;
2991 stub_sec
->_cooked_size
= 0;
2997 bfd_hash_traverse (&hplink
->stub_hash_table
,
3001 /* Ask the linker to do its stuff. */
3002 (*hplink
->layout_sections_again
) ();
3008 error_ret_free_local
:
3009 while (bfd_count
-- > 0)
3010 if (all_local_syms
[bfd_count
])
3011 free (all_local_syms
[bfd_count
]);
3012 free (all_local_syms
);
3018 /* For a final link, this function is called after we have sized the
3019 stubs to provide a value for __gp. */
3022 elf32_hppa_set_gp (abfd
, info
)
3024 struct bfd_link_info
*info
;
3026 struct elf32_hppa_link_hash_table
*hplink
;
3027 struct elf_link_hash_entry
*h
;
3031 hplink
= hppa_link_hash_table (info
);
3032 h
= elf_link_hash_lookup (&hplink
->root
, "$global$",
3033 false, false, false);
3035 if (h
!= NULL
&& h
->root
.type
== bfd_link_hash_defined
)
3037 gp_val
= h
->root
.u
.def
.value
;
3038 sec
= h
->root
.u
.def
.section
;
3042 /* Choose to point our LTP at, in this order, one of .plt, .got,
3043 or .data, if these sections exist. In the case of choosing
3044 .plt try to make the LTP ideal for addressing anywhere in the
3045 .plt or .got with a 14 bit signed offset. Typically, the end
3046 of the .plt is the start of the .got, so choose .plt + 0x2000
3047 if either the .plt or .got is larger than 0x2000. If both
3048 the .plt and .got are smaller than 0x2000, choose the end of
3049 the .plt section. */
3054 gp_val
= sec
->_raw_size
;
3056 || (hplink
->sgot
&& hplink
->sgot
->_raw_size
> 0x2000))
3067 /* We know we don't have a .plt. If .got is large,
3069 if (sec
->_raw_size
> 0x2000)
3074 /* No .plt or .got. Who cares what the LTP is? */
3075 sec
= bfd_get_section_by_name (abfd
, ".data");
3081 gp_val
+= sec
->output_section
->vma
+ sec
->output_offset
;
3083 elf_gp (abfd
) = gp_val
;
3088 /* Build all the stubs associated with the current output file. The
3089 stubs are kept in a hash table attached to the main linker hash
3090 table. We also set up the .plt entries for statically linked PIC
3091 functions here. This function is called via hppaelf_finish in the
3095 elf32_hppa_build_stubs (info
)
3096 struct bfd_link_info
*info
;
3099 struct bfd_hash_table
*table
;
3100 struct elf32_hppa_link_hash_table
*hplink
;
3102 hplink
= hppa_link_hash_table (info
);
3104 for (stub_sec
= hplink
->stub_bfd
->sections
;
3106 stub_sec
= stub_sec
->next
)
3110 /* Allocate memory to hold the linker stubs. */
3111 size
= stub_sec
->_raw_size
;
3112 stub_sec
->contents
= (unsigned char *) bfd_zalloc (hplink
->stub_bfd
,
3114 if (stub_sec
->contents
== NULL
&& size
!= 0)
3116 stub_sec
->_raw_size
= 0;
3119 /* Build the stubs as directed by the stub hash table. */
3120 table
= &hplink
->stub_hash_table
;
3121 bfd_hash_traverse (table
, hppa_build_one_stub
, info
);
3127 /* Perform a relocation as part of a final link. */
3129 static bfd_reloc_status_type
3130 final_link_relocate (input_section
, contents
, rel
, value
, hplink
, sym_sec
, h
)
3131 asection
*input_section
;
3133 const Elf_Internal_Rela
*rel
;
3135 struct elf32_hppa_link_hash_table
*hplink
;
3137 struct elf32_hppa_link_hash_entry
*h
;
3140 unsigned int r_type
= ELF32_R_TYPE (rel
->r_info
);
3141 reloc_howto_type
*howto
= elf_hppa_howto_table
+ r_type
;
3142 int r_format
= howto
->bitsize
;
3143 enum hppa_reloc_field_selector_type_alt r_field
;
3144 bfd
*input_bfd
= input_section
->owner
;
3145 bfd_vma offset
= rel
->r_offset
;
3146 bfd_vma max_branch_offset
= 0;
3147 bfd_byte
*hit_data
= contents
+ offset
;
3148 bfd_signed_vma addend
= rel
->r_addend
;
3150 struct elf32_hppa_stub_hash_entry
*stub_entry
= NULL
;
3153 if (r_type
== R_PARISC_NONE
)
3154 return bfd_reloc_ok
;
3156 insn
= bfd_get_32 (input_bfd
, hit_data
);
3158 /* Find out where we are and where we're going. */
3159 location
= (offset
+
3160 input_section
->output_offset
+
3161 input_section
->output_section
->vma
);
3165 case R_PARISC_PCREL12F
:
3166 case R_PARISC_PCREL17F
:
3167 case R_PARISC_PCREL22F
:
3168 /* If this is a call to a function defined in another dynamic
3169 library, or if it is a call to a PIC function in the same
3170 object, or if this is a shared link and it is a call to a
3171 weak symbol which may or may not be in the same object, then
3172 find the import stub in the stub hash. */
3174 || sym_sec
->output_section
== NULL
3177 || (h
->elf
.root
.type
== bfd_link_hash_defweak
3178 && h
->elf
.dynindx
!= -1
3179 && h
->elf
.plt
.offset
!= (bfd_vma
) -1))))
3181 stub_entry
= hppa_get_stub_entry (input_section
, sym_sec
,
3183 if (stub_entry
!= NULL
)
3185 value
= (stub_entry
->stub_offset
3186 + stub_entry
->stub_sec
->output_offset
3187 + stub_entry
->stub_sec
->output_section
->vma
);
3190 else if (sym_sec
== NULL
&& h
!= NULL
3191 && h
->elf
.root
.type
== bfd_link_hash_undefweak
)
3193 /* It's OK if undefined weak. Make undefined weak
3194 branches go nowhere. */
3199 return bfd_reloc_notsupported
;
3203 case R_PARISC_PCREL21L
:
3204 case R_PARISC_PCREL17C
:
3205 case R_PARISC_PCREL17R
:
3206 case R_PARISC_PCREL14R
:
3207 case R_PARISC_PCREL14F
:
3208 /* Make it a pc relative offset. */
3213 case R_PARISC_DPREL21L
:
3214 case R_PARISC_DPREL14R
:
3215 case R_PARISC_DPREL14F
:
3216 /* For all the DP relative relocations, we need to examine the symbol's
3217 section. If it's a code section, then "data pointer relative" makes
3218 no sense. In that case we don't adjust the "value", and for 21 bit
3219 addil instructions, we change the source addend register from %dp to
3220 %r0. This situation commonly arises when a variable's "constness"
3221 is declared differently from the way the variable is defined. For
3222 instance: "extern int foo" with foo defined as "const int foo". */
3223 if (sym_sec
== NULL
)
3225 if ((sym_sec
->flags
& SEC_CODE
) != 0)
3227 if ((insn
& ((0x3f << 26) | (0x1f << 21)))
3228 == (((int) OP_ADDIL
<< 26) | (27 << 21)))
3230 insn
&= ~ (0x1f << 21);
3231 #if 1 /* debug them. */
3232 (*_bfd_error_handler
)
3233 (_("%s(%s+0x%lx): fixing %s"),
3234 bfd_get_filename (input_bfd
),
3235 input_section
->name
,
3236 (long) rel
->r_offset
,
3240 /* Now try to make things easy for the dynamic linker. */
3246 case R_PARISC_DLTIND21L
:
3247 case R_PARISC_DLTIND14R
:
3248 case R_PARISC_DLTIND14F
:
3249 value
-= elf_gp (input_section
->output_section
->owner
);
3258 case R_PARISC_DIR32
:
3259 case R_PARISC_DIR17F
:
3260 case R_PARISC_PCREL17C
:
3261 case R_PARISC_PCREL14F
:
3262 case R_PARISC_DPREL14F
:
3263 case R_PARISC_PLABEL32
:
3264 case R_PARISC_DLTIND14F
:
3265 case R_PARISC_SEGBASE
:
3266 case R_PARISC_SEGREL32
:
3270 case R_PARISC_DIR21L
:
3271 case R_PARISC_PCREL21L
:
3272 case R_PARISC_DPREL21L
:
3273 case R_PARISC_PLABEL21L
:
3274 case R_PARISC_DLTIND21L
:
3278 case R_PARISC_DIR17R
:
3279 case R_PARISC_PCREL17R
:
3280 case R_PARISC_DIR14R
:
3281 case R_PARISC_PCREL14R
:
3282 case R_PARISC_DPREL14R
:
3283 case R_PARISC_PLABEL14R
:
3284 case R_PARISC_DLTIND14R
:
3288 case R_PARISC_PCREL12F
:
3289 case R_PARISC_PCREL17F
:
3290 case R_PARISC_PCREL22F
:
3293 if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
3295 max_branch_offset
= (1 << (17-1)) << 2;
3297 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
3299 max_branch_offset
= (1 << (12-1)) << 2;
3303 max_branch_offset
= (1 << (22-1)) << 2;
3306 /* sym_sec is NULL on undefined weak syms or when shared on
3307 undefined syms. We've already checked for a stub for the
3308 shared undefined case. */
3309 if (sym_sec
== NULL
)
3312 /* If the branch is out of reach, then redirect the
3313 call to the local stub for this function. */
3314 if (value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3316 stub_entry
= hppa_get_stub_entry (input_section
, sym_sec
,
3318 if (stub_entry
== NULL
)
3319 return bfd_reloc_notsupported
;
3321 /* Munge up the value and addend so that we call the stub
3322 rather than the procedure directly. */
3323 value
= (stub_entry
->stub_offset
3324 + stub_entry
->stub_sec
->output_offset
3325 + stub_entry
->stub_sec
->output_section
->vma
3331 /* Something we don't know how to handle. */
3333 return bfd_reloc_notsupported
;
3336 /* Make sure we can reach the stub. */
3337 if (max_branch_offset
!= 0
3338 && value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3340 (*_bfd_error_handler
)
3341 (_("%s(%s+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
3342 bfd_get_filename (input_bfd
),
3343 input_section
->name
,
3344 (long) rel
->r_offset
,
3345 stub_entry
->root
.string
);
3346 return bfd_reloc_notsupported
;
3349 val
= hppa_field_adjust (value
, addend
, r_field
);
3353 case R_PARISC_PCREL12F
:
3354 case R_PARISC_PCREL17C
:
3355 case R_PARISC_PCREL17F
:
3356 case R_PARISC_PCREL17R
:
3357 case R_PARISC_PCREL22F
:
3358 case R_PARISC_DIR17F
:
3359 case R_PARISC_DIR17R
:
3360 /* This is a branch. Divide the offset by four.
3361 Note that we need to decide whether it's a branch or
3362 otherwise by inspecting the reloc. Inspecting insn won't
3363 work as insn might be from a .word directive. */
3371 insn
= hppa_rebuild_insn (insn
, val
, r_format
);
3373 /* Update the instruction word. */
3374 bfd_put_32 (input_bfd
, (bfd_vma
) insn
, hit_data
);
3375 return bfd_reloc_ok
;
3379 /* Relocate an HPPA ELF section. */
3382 elf32_hppa_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
3383 contents
, relocs
, local_syms
, local_sections
)
3385 struct bfd_link_info
*info
;
3387 asection
*input_section
;
3389 Elf_Internal_Rela
*relocs
;
3390 Elf_Internal_Sym
*local_syms
;
3391 asection
**local_sections
;
3394 bfd_vma
*local_got_offsets
;
3395 struct elf32_hppa_link_hash_table
*hplink
;
3396 Elf_Internal_Shdr
*symtab_hdr
;
3397 Elf_Internal_Rela
*rel
;
3398 Elf_Internal_Rela
*relend
;
3401 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3403 hplink
= hppa_link_hash_table (info
);
3404 dynobj
= hplink
->root
.dynobj
;
3405 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3409 relend
= relocs
+ input_section
->reloc_count
;
3410 for (; rel
< relend
; rel
++)
3412 unsigned int r_type
;
3413 reloc_howto_type
*howto
;
3414 unsigned int r_symndx
;
3415 struct elf32_hppa_link_hash_entry
*h
;
3416 Elf_Internal_Sym
*sym
;
3419 bfd_reloc_status_type r
;
3420 const char *sym_name
;
3423 r_type
= ELF32_R_TYPE (rel
->r_info
);
3424 if (r_type
>= (unsigned int) R_PARISC_UNIMPLEMENTED
)
3426 bfd_set_error (bfd_error_bad_value
);
3429 if (r_type
== (unsigned int) R_PARISC_GNU_VTENTRY
3430 || r_type
== (unsigned int) R_PARISC_GNU_VTINHERIT
)
3433 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3435 if (info
->relocateable
)
3437 /* This is a relocateable link. We don't have to change
3438 anything, unless the reloc is against a section symbol,
3439 in which case we have to adjust according to where the
3440 section symbol winds up in the output section. */
3441 if (r_symndx
< symtab_hdr
->sh_info
)
3443 sym
= local_syms
+ r_symndx
;
3444 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
3446 sym_sec
= local_sections
[r_symndx
];
3447 rel
->r_addend
+= sym_sec
->output_offset
;
3453 /* This is a final link. */
3457 if (r_symndx
< symtab_hdr
->sh_info
)
3459 /* This is a local symbol, h defaults to NULL. */
3460 sym
= local_syms
+ r_symndx
;
3461 sym_sec
= local_sections
[r_symndx
];
3462 relocation
= ((ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
3463 ? 0 : sym
->st_value
)
3464 + sym_sec
->output_offset
3465 + sym_sec
->output_section
->vma
);
3471 /* It's a global; Find its entry in the link hash. */
3472 indx
= r_symndx
- symtab_hdr
->sh_info
;
3473 h
= ((struct elf32_hppa_link_hash_entry
*)
3474 elf_sym_hashes (input_bfd
)[indx
]);
3475 while (h
->elf
.root
.type
== bfd_link_hash_indirect
3476 || h
->elf
.root
.type
== bfd_link_hash_warning
)
3477 h
= (struct elf32_hppa_link_hash_entry
*) h
->elf
.root
.u
.i
.link
;
3480 if (h
->elf
.root
.type
== bfd_link_hash_defined
3481 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
3483 sym_sec
= h
->elf
.root
.u
.def
.section
;
3484 /* If sym_sec->output_section is NULL, then it's a
3485 symbol defined in a shared library. */
3486 if (sym_sec
->output_section
!= NULL
)
3487 relocation
= (h
->elf
.root
.u
.def
.value
3488 + sym_sec
->output_offset
3489 + sym_sec
->output_section
->vma
);
3491 else if (h
->elf
.root
.type
== bfd_link_hash_undefweak
)
3493 else if (info
->shared
&& !info
->no_undefined
3494 && ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
)
3497 if (!((*info
->callbacks
->undefined_symbol
)
3498 (info
, h
->elf
.root
.root
.string
, input_bfd
,
3499 input_section
, rel
->r_offset
, false)))
3504 if (!((*info
->callbacks
->undefined_symbol
)
3505 (info
, h
->elf
.root
.root
.string
, input_bfd
,
3506 input_section
, rel
->r_offset
, true)))
3511 /* Do any required modifications to the relocation value, and
3512 determine what types of dynamic info we need to output, if
3517 case R_PARISC_DLTIND14F
:
3518 case R_PARISC_DLTIND14R
:
3519 case R_PARISC_DLTIND21L
:
3520 /* Relocation is to the entry for this symbol in the global
3526 off
= h
->elf
.got
.offset
;
3527 BFD_ASSERT (off
!= (bfd_vma
) -1);
3529 if (! hplink
->root
.dynamic_sections_created
3531 && (info
->symbolic
|| h
->elf
.dynindx
== -1)
3532 && (h
->elf
.elf_link_hash_flags
3533 & ELF_LINK_HASH_DEF_REGULAR
) != 0))
3535 /* This is actually a static link, or it is a
3536 -Bsymbolic link and the symbol is defined
3537 locally, or the symbol was forced to be local
3538 because of a version file. We must initialize
3539 this entry in the global offset table. Since the
3540 offset must always be a multiple of 4, we use the
3541 least significant bit to record whether we have
3542 initialized it already.
3544 When doing a dynamic link, we create a .rela.got
3545 relocation entry to initialize the value. This
3546 is done in the finish_dynamic_symbol routine. */
3551 bfd_put_32 (output_bfd
, relocation
,
3552 hplink
->sgot
->contents
+ off
);
3553 h
->elf
.got
.offset
|= 1;
3561 /* Local symbol case. */
3564 BFD_ASSERT (local_got_offsets
!= NULL
3565 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
3567 off
= local_got_offsets
[r_symndx
];
3569 /* The offset must always be a multiple of 4. We use
3570 the least significant bit to record whether we have
3571 already generated the necessary reloc. */
3576 bfd_put_32 (output_bfd
, relocation
,
3577 hplink
->sgot
->contents
+ off
);
3581 /* Output a dynamic *ABS* relocation for this
3582 GOT entry. In this case it is relative to
3583 the base of the object because the symbol
3585 Elf_Internal_Rela outrel
;
3586 asection
*srelgot
= hplink
->srelgot
;
3588 outrel
.r_offset
= (off
3589 + hplink
->sgot
->output_offset
3590 + hplink
->sgot
->output_section
->vma
);
3591 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_DIR32
);
3592 outrel
.r_addend
= relocation
;
3593 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3594 ((Elf32_External_Rela
*)
3596 + srelgot
->reloc_count
));
3597 ++srelgot
->reloc_count
;
3600 local_got_offsets
[r_symndx
] |= 1;
3606 /* Add the base of the GOT to the relocation value. */
3607 relocation
+= (hplink
->sgot
->output_offset
3608 + hplink
->sgot
->output_section
->vma
);
3611 case R_PARISC_PLABEL14R
:
3612 case R_PARISC_PLABEL21L
:
3613 case R_PARISC_PLABEL32
:
3614 if (hplink
->root
.dynamic_sections_created
)
3618 /* If we have a global symbol with a PLT slot, then
3619 redirect this relocation to it. */
3622 off
= h
->elf
.plt
.offset
;
3628 indx
= r_symndx
+ symtab_hdr
->sh_info
;
3629 off
= local_got_offsets
[indx
];
3631 /* As for the local .got entry case, we use the last
3632 bit to record whether we've already initialised
3633 this local .plt entry. */
3638 bfd_put_32 (output_bfd
,
3640 hplink
->splt
->contents
+ off
);
3641 bfd_put_32 (output_bfd
,
3642 elf_gp (hplink
->splt
->output_section
->owner
),
3643 hplink
->splt
->contents
+ off
+ 4);
3647 /* Output a dynamic IPLT relocation for this
3649 Elf_Internal_Rela outrel
;
3650 asection
*srelplt
= hplink
->srelplt
;
3652 outrel
.r_offset
= (off
3653 + hplink
->splt
->output_offset
3654 + hplink
->splt
->output_section
->vma
);
3655 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_IPLT
);
3656 outrel
.r_addend
= relocation
;
3657 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3658 ((Elf32_External_Rela
*)
3660 + srelplt
->reloc_count
));
3661 ++srelplt
->reloc_count
;
3664 local_got_offsets
[indx
] |= 1;
3668 BFD_ASSERT (off
< (bfd_vma
) -2);
3670 /* PLABELs contain function pointers. Relocation is to
3671 the entry for the function in the .plt. The magic +2
3672 offset signals to $$dyncall that the function pointer
3673 is in the .plt and thus has a gp pointer too.
3674 Exception: Undefined PLABELs should have a value of
3677 || (h
->elf
.root
.type
!= bfd_link_hash_undefweak
3678 && h
->elf
.root
.type
!= bfd_link_hash_undefined
))
3681 + hplink
->splt
->output_offset
3682 + hplink
->splt
->output_section
->vma
3687 /* Fall through and possibly emit a dynamic relocation. */
3689 case R_PARISC_DIR17F
:
3690 case R_PARISC_DIR17R
:
3691 case R_PARISC_DIR14R
:
3692 case R_PARISC_DIR21L
:
3693 case R_PARISC_DPREL14F
:
3694 case R_PARISC_DPREL14R
:
3695 case R_PARISC_DPREL21L
:
3696 case R_PARISC_DIR32
:
3697 /* The reloc types handled here and this conditional
3698 expression must match the code in check_relocs and
3699 hppa_discard_copies. ie. We need exactly the same
3700 condition as in check_relocs, with some extra conditions
3701 (dynindx test in this case) to cater for relocs removed
3702 by hppa_discard_copies. */
3703 if ((input_section
->flags
& SEC_ALLOC
) != 0
3705 #if RELATIVE_DYNAMIC_RELOCS
3706 && (is_absolute_reloc (r_type
)
3707 || ((!info
->symbolic
3709 && ((h
->elf
.elf_link_hash_flags
3710 & ELF_LINK_HASH_DEF_REGULAR
) == 0
3711 || h
->elf
.root
.type
== bfd_link_hash_defweak
)))
3712 && (h
== NULL
|| h
->elf
.dynindx
!= -1)))
3716 Elf_Internal_Rela outrel
;
3719 /* When generating a shared object, these relocations
3720 are copied into the output file to be resolved at run
3727 name
= (bfd_elf_string_from_elf_section
3729 elf_elfheader (input_bfd
)->e_shstrndx
,
3730 elf_section_data (input_section
)->rel_hdr
.sh_name
));
3733 sreloc
= bfd_get_section_by_name (dynobj
, name
);
3734 BFD_ASSERT (sreloc
!= NULL
);
3737 outrel
.r_offset
= rel
->r_offset
;
3738 outrel
.r_addend
= rel
->r_addend
;
3740 if (elf_section_data (input_section
)->stab_info
!= NULL
)
3744 off
= (_bfd_stab_section_offset
3745 (output_bfd
, &hplink
->root
.stab_info
,
3747 &elf_section_data (input_section
)->stab_info
,
3749 if (off
== (bfd_vma
) -1)
3751 outrel
.r_offset
= off
;
3754 outrel
.r_offset
+= (input_section
->output_offset
3755 + input_section
->output_section
->vma
);
3759 memset (&outrel
, 0, sizeof (outrel
));
3762 && h
->elf
.dynindx
!= -1
3765 || (h
->elf
.elf_link_hash_flags
3766 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
3768 outrel
.r_info
= ELF32_R_INFO (h
->elf
.dynindx
, r_type
);
3770 else /* It's a local symbol, or one marked to become local. */
3774 /* Add the absolute offset of the symbol. */
3775 outrel
.r_addend
+= relocation
;
3777 /* Global plabels need to be processed by the
3778 dynamic linker so that functions have at most one
3779 fptr. For this reason, we need to differentiate
3780 between global and local plabels, which we do by
3781 providing the function symbol for a global plabel
3782 reloc, and no symbol for local plabels. */
3785 && sym_sec
->output_section
!= NULL
3786 && ! bfd_is_abs_section (sym_sec
))
3788 indx
= elf_section_data (sym_sec
->output_section
)->dynindx
;
3789 /* We are turning this relocation into one
3790 against a section symbol, so subtract out the
3791 output section's address but not the offset
3792 of the input section in the output section. */
3793 outrel
.r_addend
-= sym_sec
->output_section
->vma
;
3796 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
3799 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3800 ((Elf32_External_Rela
*)
3802 + sreloc
->reloc_count
));
3803 ++sreloc
->reloc_count
;
3811 r
= final_link_relocate (input_section
, contents
, rel
, relocation
,
3812 hplink
, sym_sec
, h
);
3814 if (r
== bfd_reloc_ok
)
3818 sym_name
= h
->elf
.root
.root
.string
;
3821 sym_name
= bfd_elf_string_from_elf_section (input_bfd
,
3822 symtab_hdr
->sh_link
,
3824 if (sym_name
== NULL
)
3826 if (*sym_name
== '\0')
3827 sym_name
= bfd_section_name (input_bfd
, sym_sec
);
3830 howto
= elf_hppa_howto_table
+ r_type
;
3832 if (r
== bfd_reloc_undefined
|| r
== bfd_reloc_notsupported
)
3834 (*_bfd_error_handler
)
3835 (_("%s(%s+0x%lx): cannot handle %s for %s"),
3836 bfd_get_filename (input_bfd
),
3837 input_section
->name
,
3838 (long) rel
->r_offset
,
3844 if (!((*info
->callbacks
->reloc_overflow
)
3845 (info
, sym_name
, howto
->name
, (bfd_vma
) 0,
3846 input_bfd
, input_section
, rel
->r_offset
)))
3855 /* Finish up dynamic symbol handling. We set the contents of various
3856 dynamic sections here. */
3859 elf32_hppa_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
3861 struct bfd_link_info
*info
;
3862 struct elf_link_hash_entry
*h
;
3863 Elf_Internal_Sym
*sym
;
3865 struct elf32_hppa_link_hash_table
*hplink
;
3868 hplink
= hppa_link_hash_table (info
);
3869 dynobj
= hplink
->root
.dynobj
;
3871 if (h
->plt
.offset
!= (bfd_vma
) -1)
3874 Elf_Internal_Rela rel
;
3876 /* This symbol has an entry in the procedure linkage table. Set
3879 The format of a plt entry is
3884 The last field is present only for plt entries that are used
3885 by global plabels. */
3887 /* We do not actually care about the value in the PLT entry if
3888 we are creating a shared library and the symbol is still
3889 undefined; We create a dynamic relocation to fill in the
3892 if (h
->root
.type
== bfd_link_hash_defined
3893 || h
->root
.type
== bfd_link_hash_defweak
)
3895 value
= h
->root
.u
.def
.value
;
3896 if (h
->root
.u
.def
.section
->output_section
!= NULL
)
3897 value
+= (h
->root
.u
.def
.section
->output_offset
3898 + h
->root
.u
.def
.section
->output_section
->vma
);
3901 bfd_put_32 (hplink
->splt
->owner
,
3903 hplink
->splt
->contents
+ h
->plt
.offset
);
3904 bfd_put_32 (hplink
->splt
->owner
,
3905 elf_gp (hplink
->splt
->output_section
->owner
),
3906 hplink
->splt
->contents
+ h
->plt
.offset
+ 4);
3907 if (PLABEL_PLT_ENTRY_SIZE
!= PLT_ENTRY_SIZE
3908 && ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
3909 && h
->dynindx
!= -1)
3911 memset (hplink
->splt
->contents
+ h
->plt
.offset
+ 8,
3912 0, PLABEL_PLT_ENTRY_SIZE
- PLT_ENTRY_SIZE
);
3915 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
)
3917 /* Create a dynamic IPLT relocation for this entry. */
3918 rel
.r_offset
= (h
->plt
.offset
3919 + hplink
->splt
->output_offset
3920 + hplink
->splt
->output_section
->vma
);
3921 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->plt_abs
3922 && h
->dynindx
!= -1)
3924 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_IPLT
);
3929 /* This symbol has been marked to become local, and is
3930 used by a plabel so must be kept in the .plt. */
3931 rel
.r_info
= ELF32_R_INFO (0, R_PARISC_IPLT
);
3932 rel
.r_addend
= value
;
3935 bfd_elf32_swap_reloca_out (hplink
->splt
->output_section
->owner
,
3937 ((Elf32_External_Rela
*)
3938 hplink
->srelplt
->contents
3939 + hplink
->srelplt
->reloc_count
));
3940 hplink
->srelplt
->reloc_count
++;
3943 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3945 /* Mark the symbol as undefined, rather than as defined in
3946 the .plt section. Leave the value alone. */
3947 sym
->st_shndx
= SHN_UNDEF
;
3951 if (h
->got
.offset
!= (bfd_vma
) -1)
3953 Elf_Internal_Rela rel
;
3955 /* This symbol has an entry in the global offset table. Set it
3958 rel
.r_offset
= ((h
->got
.offset
&~ (bfd_vma
) 1)
3959 + hplink
->sgot
->output_offset
3960 + hplink
->sgot
->output_section
->vma
);
3962 /* If this is a static link, or it is a -Bsymbolic link and the
3963 symbol is defined locally or was forced to be local because
3964 of a version file, we just want to emit a RELATIVE reloc.
3965 The entry in the global offset table will already have been
3966 initialized in the relocate_section function. */
3967 if (! hplink
->root
.dynamic_sections_created
3969 && (info
->symbolic
|| h
->dynindx
== -1)
3970 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
3972 rel
.r_info
= ELF32_R_INFO (0, R_PARISC_DIR32
);
3973 rel
.r_addend
= (h
->root
.u
.def
.value
3974 + h
->root
.u
.def
.section
->output_offset
3975 + h
->root
.u
.def
.section
->output_section
->vma
);
3979 BFD_ASSERT((h
->got
.offset
& 1) == 0);
3980 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
3981 hplink
->sgot
->contents
+ h
->got
.offset
);
3982 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_DIR32
);
3986 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
3987 ((Elf32_External_Rela
*)
3988 hplink
->srelgot
->contents
3989 + hplink
->srelgot
->reloc_count
));
3990 ++hplink
->srelgot
->reloc_count
;
3993 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
3996 Elf_Internal_Rela rel
;
3998 /* This symbol needs a copy reloc. Set it up. */
4000 BFD_ASSERT (h
->dynindx
!= -1
4001 && (h
->root
.type
== bfd_link_hash_defined
4002 || h
->root
.type
== bfd_link_hash_defweak
));
4004 s
= hplink
->srelbss
;
4006 rel
.r_offset
= (h
->root
.u
.def
.value
4007 + h
->root
.u
.def
.section
->output_offset
4008 + h
->root
.u
.def
.section
->output_section
->vma
);
4010 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_COPY
);
4011 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
4012 ((Elf32_External_Rela
*) s
->contents
4017 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
4018 if (h
->root
.root
.string
[0] == '_'
4019 && (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4020 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0))
4022 sym
->st_shndx
= SHN_ABS
;
4029 /* Finish up the dynamic sections. */
4032 elf32_hppa_finish_dynamic_sections (output_bfd
, info
)
4034 struct bfd_link_info
*info
;
4037 struct elf32_hppa_link_hash_table
*hplink
;
4040 hplink
= hppa_link_hash_table (info
);
4041 dynobj
= hplink
->root
.dynobj
;
4043 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4045 if (hplink
->root
.dynamic_sections_created
)
4047 Elf32_External_Dyn
*dyncon
, *dynconend
;
4049 BFD_ASSERT (sdyn
!= NULL
);
4051 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4052 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
4053 for (; dyncon
< dynconend
; dyncon
++)
4055 Elf_Internal_Dyn dyn
;
4058 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4066 /* Use PLTGOT to set the GOT register. */
4067 dyn
.d_un
.d_ptr
= elf_gp (output_bfd
);
4068 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4072 s
= hplink
->srelplt
;
4073 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4074 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4078 s
= hplink
->srelplt
;
4079 if (s
->_cooked_size
!= 0)
4080 dyn
.d_un
.d_val
= s
->_cooked_size
;
4082 dyn
.d_un
.d_val
= s
->_raw_size
;
4083 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4089 struct elf_link_hash_entry
*h
;
4090 const char *funcname
;
4092 if (dyn
.d_tag
== DT_INIT
)
4093 funcname
= info
->init_function
;
4095 funcname
= info
->fini_function
;
4097 h
= elf_link_hash_lookup (&hplink
->root
, funcname
,
4098 false, false, false);
4100 /* This is a function pointer. The magic +2 offset
4101 signals to $$dyncall that the function pointer
4102 is in the .plt and thus has a gp pointer too. */
4103 dyn
.d_un
.d_ptr
= (h
->plt
.offset
4104 + hplink
->splt
->output_offset
4105 + hplink
->splt
->output_section
->vma
4107 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4114 if (hplink
->sgot
->_raw_size
!= 0)
4116 /* Fill in the first entry in the global offset table.
4117 We use it to point to our dynamic section, if we have one. */
4118 bfd_put_32 (output_bfd
,
4120 ? sdyn
->output_section
->vma
+ sdyn
->output_offset
4122 hplink
->sgot
->contents
);
4124 /* The second entry is reserved for use by the dynamic linker. */
4125 bfd_put_32 (output_bfd
, (bfd_vma
) 0, hplink
->sgot
->contents
+ 4);
4127 /* Set .got entry size. */
4128 elf_section_data (hplink
->sgot
->output_section
)
4129 ->this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
4132 /* Set plt entry size. */
4133 if (hplink
->splt
->_raw_size
!= 0)
4134 elf_section_data (hplink
->splt
->output_section
)
4135 ->this_hdr
.sh_entsize
= PLT_ENTRY_SIZE
;
4141 /* Called when writing out an object file to decide the type of a
4144 elf32_hppa_elf_get_symbol_type (elf_sym
, type
)
4145 Elf_Internal_Sym
*elf_sym
;
4148 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_PARISC_MILLI
)
4149 return STT_PARISC_MILLI
;
4155 /* Misc BFD support code. */
4156 #define bfd_elf32_bfd_is_local_label_name elf_hppa_is_local_label_name
4157 #define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
4158 #define elf_info_to_howto elf_hppa_info_to_howto
4159 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
4161 /* Stuff for the BFD linker. */
4162 #define bfd_elf32_bfd_final_link _bfd_elf32_gc_common_final_link
4163 #define bfd_elf32_bfd_link_hash_table_create elf32_hppa_link_hash_table_create
4164 #define elf_backend_add_symbol_hook elf32_hppa_add_symbol_hook
4165 #define elf_backend_adjust_dynamic_symbol elf32_hppa_adjust_dynamic_symbol
4166 #define elf_backend_check_relocs elf32_hppa_check_relocs
4167 #define elf_backend_create_dynamic_sections elf32_hppa_create_dynamic_sections
4168 #define elf_backend_fake_sections elf_hppa_fake_sections
4169 #define elf_backend_relocate_section elf32_hppa_relocate_section
4170 #define elf_backend_hide_symbol elf32_hppa_hide_symbol
4171 #define elf_backend_finish_dynamic_symbol elf32_hppa_finish_dynamic_symbol
4172 #define elf_backend_finish_dynamic_sections elf32_hppa_finish_dynamic_sections
4173 #define elf_backend_size_dynamic_sections elf32_hppa_size_dynamic_sections
4174 #define elf_backend_gc_mark_hook elf32_hppa_gc_mark_hook
4175 #define elf_backend_gc_sweep_hook elf32_hppa_gc_sweep_hook
4176 #define elf_backend_object_p elf32_hppa_object_p
4177 #define elf_backend_final_write_processing elf_hppa_final_write_processing
4178 #define elf_backend_get_symbol_type elf32_hppa_elf_get_symbol_type
4180 #define elf_backend_can_gc_sections 1
4181 #define elf_backend_plt_alignment 2
4182 #define elf_backend_want_got_plt 0
4183 #define elf_backend_plt_readonly 0
4184 #define elf_backend_want_plt_sym 0
4185 #define elf_backend_got_header_size 8
4187 #define TARGET_BIG_SYM bfd_elf32_hppa_vec
4188 #define TARGET_BIG_NAME "elf32-hppa"
4189 #define ELF_ARCH bfd_arch_hppa
4190 #define ELF_MACHINE_CODE EM_PARISC
4191 #define ELF_MAXPAGESIZE 0x1000
4193 #include "elf32-target.h"