1 /* BFD back-end for HP PA-RISC ELF files.
2 Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000
3 Free Software Foundation, Inc.
6 Center for Software Science
7 Department of Computer Science
9 Largely rewritten by Alan Modra <alan@linuxcare.com.au>
11 This file is part of BFD, the Binary File Descriptor library.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
33 #include "elf32-hppa.h"
36 #include "elf32-hppa.h"
39 /* In order to gain some understanding of code in this file without
40 knowing all the intricate details of the linker, note the
43 Functions named elf32_hppa_* are called by external routines, other
44 functions are only called locally. elf32_hppa_* functions appear
45 in this file more or less in the order in which they are called
46 from external routines. eg. elf32_hppa_check_relocs is called
47 early in the link process, elf32_hppa_finish_dynamic_sections is
48 one of the last functions. */
51 /* We use two hash tables to hold information for linking PA ELF objects.
53 The first is the elf32_hppa_link_hash_table which is derived
54 from the standard ELF linker hash table. We use this as a place to
55 attach other hash tables and static information.
57 The second is the stub hash table which is derived from the
58 base BFD hash table. The stub hash table holds the information
59 necessary to build the linker stubs during a link.
61 There are a number of different stubs generated by the linker.
69 : addil L'X - ($PIC_pcrel$0 - 4),%r1
70 : be,n R'X - ($PIC_pcrel$0 - 8)(%sr4,%r1)
72 Import stub to call shared library routine from normal object file
73 (single sub-space version)
74 : addil L'lt_ptr+ltoff,%dp ; get procedure entry point
75 : ldw R'lt_ptr+ltoff(%r1),%r21
77 : ldw R'lt_ptr+ltoff+4(%r1),%r19 ; get new dlt value.
79 Import stub to call shared library routine from shared library
80 (single sub-space version)
81 : addil L'ltoff,%r19 ; get procedure entry point
82 : ldw R'ltoff(%r1),%r21
84 : ldw R'ltoff+4(%r1),%r19 ; get new dlt value.
86 Import stub to call shared library routine from normal object file
87 (multiple sub-space support)
88 : addil L'lt_ptr+ltoff,%dp ; get procedure entry point
89 : ldw R'lt_ptr+ltoff(%r1),%r21
90 : ldw R'lt_ptr+ltoff+4(%r1),%r19 ; get new dlt value.
93 : be 0(%sr0,%r21) ; branch to target
94 : stw %rp,-24(%sp) ; save rp
96 Import stub to call shared library routine from shared library
97 (multiple sub-space support)
98 : addil L'ltoff,%r19 ; get procedure entry point
99 : ldw R'ltoff(%r1),%r21
100 : ldw R'ltoff+4(%r1),%r19 ; get new dlt value.
103 : be 0(%sr0,%r21) ; branch to target
104 : stw %rp,-24(%sp) ; save rp
106 Export stub to return from shared lib routine (multiple sub-space support)
107 One of these is created for each exported procedure in a shared
108 library (and stored in the shared lib). Shared lib routines are
109 called via the first instruction in the export stub so that we can
110 do an inter-space return. Not required for single sub-space.
111 : bl,n X,%rp ; trap the return
113 : ldw -24(%sp),%rp ; restore the original rp
116 : be,n 0(%sr0,%rp) ; inter-space return */
118 #define PLT_ENTRY_SIZE 8
119 #define PLABEL_PLT_ENTRY_SIZE PLT_ENTRY_SIZE
120 #define GOT_ENTRY_SIZE 4
121 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
123 static const bfd_byte plt_stub
[] =
125 0x0e, 0x80, 0x10, 0x96, /* 1: ldw 0(%r20),%r22 */
126 0xea, 0xc0, 0xc0, 0x00, /* bv %r0(%r22) */
127 0x0e, 0x88, 0x10, 0x95, /* ldw 4(%r20),%r21 */
128 #define PLT_STUB_ENTRY (3*4)
129 0xea, 0x9f, 0x1f, 0xdd, /* b,l 1b,%r20 */
130 0xd6, 0x80, 0x1c, 0x1e, /* depi 0,31,2,%r20 */
131 0x00, 0xc0, 0xff, 0xee, /* 9: .word fixup_func */
132 0xde, 0xad, 0xbe, 0xef /* .word fixup_ltp */
135 /* Section name for stubs is the associated section name plus this
137 #define STUB_SUFFIX ".stub"
139 /* Setting the following non-zero makes all long branch stubs
140 generated during a shared link of the PIC variety. This saves on
141 relocs, but costs one extra instruction per stub. */
142 #ifndef LONG_BRANCH_PIC_IN_SHLIB
143 #define LONG_BRANCH_PIC_IN_SHLIB 1
146 /* Set this non-zero to use import stubs instead of long branch stubs
147 where a .plt entry exists for the symbol. This is a fairly useless
148 option as import stubs are bigger than PIC long branch stubs. */
149 #ifndef LONG_BRANCH_VIA_PLT
150 #define LONG_BRANCH_VIA_PLT 0
153 /* We don't need to copy any PC- or GP-relative dynamic relocs into a
154 shared object's dynamic section. */
155 #ifndef RELATIVE_DYNAMIC_RELOCS
156 #define RELATIVE_DYNAMIC_RELOCS 0
160 enum elf32_hppa_stub_type
{
161 hppa_stub_long_branch
,
162 hppa_stub_long_branch_shared
,
164 hppa_stub_import_shared
,
170 struct elf32_hppa_stub_hash_entry
{
172 /* Base hash table entry structure. */
173 struct bfd_hash_entry root
;
175 /* The stub section. */
178 #if ! LONG_BRANCH_PIC_IN_SHLIB
179 /* It's associated reloc section. */
183 /* Offset within stub_sec of the beginning of this stub. */
186 /* Given the symbol's value and its section we can determine its final
187 value when building the stubs (so the stub knows where to jump. */
188 bfd_vma target_value
;
189 asection
*target_section
;
191 enum elf32_hppa_stub_type stub_type
;
193 /* The symbol table entry, if any, that this was derived from. */
194 struct elf32_hppa_link_hash_entry
*h
;
196 /* Where this stub is being called from, or, in the case of combined
197 stub sections, the first input section in the group. */
202 struct elf32_hppa_link_hash_entry
{
204 struct elf_link_hash_entry elf
;
206 /* A pointer to the most recently used stub hash entry against this
208 struct elf32_hppa_stub_hash_entry
*stub_cache
;
210 #if ! LONG_BRANCH_PIC_IN_SHLIB
211 /* Used to track whether we have allocated space for a long branch
212 stub relocation for this symbol in the given section. */
213 asection
*stub_reloc_sec
;
216 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
217 /* Used to count relocations for delayed sizing of relocation
219 struct elf32_hppa_dyn_reloc_entry
{
221 /* Next relocation in the chain. */
222 struct elf32_hppa_dyn_reloc_entry
*next
;
224 /* The section in dynobj. */
227 /* Number of relocs copied in this section. */
232 /* Set during a static link if we detect a function is PIC. */
233 unsigned int pic_call
:1;
235 /* Set if this symbol is used by a plabel reloc. */
236 unsigned int plabel
:1;
238 /* Set if this symbol is an init or fini function and thus should
239 use an absolute reloc. */
240 unsigned int plt_abs
:1;
244 struct elf32_hppa_link_hash_table
{
246 /* The main hash table. */
247 struct elf_link_hash_table root
;
249 /* The stub hash table. */
250 struct bfd_hash_table stub_hash_table
;
252 /* Linker stub bfd. */
255 /* Linker call-backs. */
256 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
257 void (*layout_sections_again
) PARAMS ((void));
259 /* Array to keep track of which stub sections have been created, and
260 information on stub grouping. */
262 /* This is the section to which stubs in the group will be
265 /* The stub section. */
267 #if ! LONG_BRANCH_PIC_IN_SHLIB
268 /* The stub section's reloc section. */
273 /* Short-cuts to get to dynamic linker sections. */
281 /* Whether we support multiple sub-spaces for shared libs. */
282 unsigned int multi_subspace
:1;
284 /* Flags set when PCREL12F and PCREL17F branches detected. Used to
285 select suitable defaults for the stub group size. */
286 unsigned int has_12bit_branch
:1;
287 unsigned int has_17bit_branch
:1;
289 /* Set if we need a .plt stub to support lazy dynamic linking. */
290 unsigned int need_plt_stub
:1;
294 /* Various hash macros and functions. */
295 #define hppa_link_hash_table(p) \
296 ((struct elf32_hppa_link_hash_table *) ((p)->hash))
298 #define hppa_stub_hash_lookup(table, string, create, copy) \
299 ((struct elf32_hppa_stub_hash_entry *) \
300 bfd_hash_lookup ((table), (string), (create), (copy)))
302 static struct bfd_hash_entry
*stub_hash_newfunc
303 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
305 static struct bfd_hash_entry
*hppa_link_hash_newfunc
306 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
308 static struct bfd_link_hash_table
*elf32_hppa_link_hash_table_create
312 /* Stub handling functions. */
313 static char *hppa_stub_name
314 PARAMS ((const asection
*, const asection
*,
315 const struct elf32_hppa_link_hash_entry
*,
316 const Elf_Internal_Rela
*));
318 static struct elf32_hppa_stub_hash_entry
*hppa_get_stub_entry
319 PARAMS ((const asection
*, const asection
*,
320 struct elf32_hppa_link_hash_entry
*,
321 const Elf_Internal_Rela
*,
322 struct elf32_hppa_link_hash_table
*));
324 static struct elf32_hppa_stub_hash_entry
*hppa_add_stub
325 PARAMS ((const char *, asection
*, struct elf32_hppa_link_hash_table
*));
327 static enum elf32_hppa_stub_type hppa_type_of_stub
328 PARAMS ((asection
*, const Elf_Internal_Rela
*,
329 struct elf32_hppa_link_hash_entry
*, bfd_vma
));
331 static boolean hppa_build_one_stub
332 PARAMS ((struct bfd_hash_entry
*, PTR
));
334 static boolean hppa_size_one_stub
335 PARAMS ((struct bfd_hash_entry
*, PTR
));
338 /* BFD and elf backend functions. */
339 static boolean elf32_hppa_object_p
PARAMS ((bfd
*));
341 static boolean elf32_hppa_add_symbol_hook
342 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
343 const char **, flagword
*, asection
**, bfd_vma
*));
345 static boolean elf32_hppa_create_dynamic_sections
346 PARAMS ((bfd
*, struct bfd_link_info
*));
348 static boolean elf32_hppa_check_relocs
349 PARAMS ((bfd
*, struct bfd_link_info
*,
350 asection
*, const Elf_Internal_Rela
*));
352 static asection
*elf32_hppa_gc_mark_hook
353 PARAMS ((bfd
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
354 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
356 static boolean elf32_hppa_gc_sweep_hook
357 PARAMS ((bfd
*, struct bfd_link_info
*,
358 asection
*, const Elf_Internal_Rela
*));
360 static void elf32_hppa_hide_symbol
361 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
363 static boolean elf32_hppa_adjust_dynamic_symbol
364 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
366 static boolean hppa_handle_PIC_calls
367 PARAMS ((struct elf_link_hash_entry
*, PTR
));
369 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
370 || RELATIVE_DYNAMIC_RELOCS)
371 static boolean hppa_discard_copies
372 PARAMS ((struct elf_link_hash_entry
*, PTR
));
375 static boolean clobber_millicode_symbols
376 PARAMS ((struct elf_link_hash_entry
*, struct bfd_link_info
*));
378 static boolean elf32_hppa_size_dynamic_sections
379 PARAMS ((bfd
*, struct bfd_link_info
*));
381 static bfd_reloc_status_type final_link_relocate
382 PARAMS ((asection
*, bfd_byte
*, const Elf_Internal_Rela
*,
383 bfd_vma
, struct elf32_hppa_link_hash_table
*, asection
*,
384 struct elf32_hppa_link_hash_entry
*));
386 static boolean elf32_hppa_relocate_section
387 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*,
388 bfd_byte
*, Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
390 static boolean elf32_hppa_finish_dynamic_symbol
391 PARAMS ((bfd
*, struct bfd_link_info
*,
392 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
394 static boolean elf32_hppa_finish_dynamic_sections
395 PARAMS ((bfd
*, struct bfd_link_info
*));
397 static int elf32_hppa_elf_get_symbol_type
398 PARAMS ((Elf_Internal_Sym
*, int));
401 /* Assorted hash table functions. */
403 /* Initialize an entry in the stub hash table. */
405 static struct bfd_hash_entry
*
406 stub_hash_newfunc (entry
, table
, string
)
407 struct bfd_hash_entry
*entry
;
408 struct bfd_hash_table
*table
;
411 struct elf32_hppa_stub_hash_entry
*ret
;
413 ret
= (struct elf32_hppa_stub_hash_entry
*) entry
;
415 /* Allocate the structure if it has not already been allocated by a
419 ret
= ((struct elf32_hppa_stub_hash_entry
*)
420 bfd_hash_allocate (table
,
421 sizeof (struct elf32_hppa_stub_hash_entry
)));
426 /* Call the allocation method of the superclass. */
427 ret
= ((struct elf32_hppa_stub_hash_entry
*)
428 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
432 /* Initialize the local fields. */
433 ret
->stub_sec
= NULL
;
434 #if ! LONG_BRANCH_PIC_IN_SHLIB
435 ret
->reloc_sec
= NULL
;
437 ret
->stub_offset
= 0;
438 ret
->target_value
= 0;
439 ret
->target_section
= NULL
;
440 ret
->stub_type
= hppa_stub_long_branch
;
445 return (struct bfd_hash_entry
*) ret
;
449 /* Initialize an entry in the link hash table. */
451 static struct bfd_hash_entry
*
452 hppa_link_hash_newfunc (entry
, table
, string
)
453 struct bfd_hash_entry
*entry
;
454 struct bfd_hash_table
*table
;
457 struct elf32_hppa_link_hash_entry
*ret
;
459 ret
= (struct elf32_hppa_link_hash_entry
*) entry
;
461 /* Allocate the structure if it has not already been allocated by a
465 ret
= ((struct elf32_hppa_link_hash_entry
*)
466 bfd_hash_allocate (table
,
467 sizeof (struct elf32_hppa_link_hash_entry
)));
472 /* Call the allocation method of the superclass. */
473 ret
= ((struct elf32_hppa_link_hash_entry
*)
474 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
479 /* Initialize the local fields. */
480 #if ! LONG_BRANCH_PIC_IN_SHLIB
481 ret
->stub_reloc_sec
= NULL
;
483 ret
->stub_cache
= NULL
;
484 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
485 ret
->reloc_entries
= NULL
;
492 return (struct bfd_hash_entry
*) ret
;
496 /* Create the derived linker hash table. The PA ELF port uses the derived
497 hash table to keep information specific to the PA ELF linker (without
498 using static variables). */
500 static struct bfd_link_hash_table
*
501 elf32_hppa_link_hash_table_create (abfd
)
504 struct elf32_hppa_link_hash_table
*ret
;
506 ret
= ((struct elf32_hppa_link_hash_table
*) bfd_alloc (abfd
, sizeof (*ret
)));
510 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
, hppa_link_hash_newfunc
))
512 bfd_release (abfd
, ret
);
516 /* Init the stub hash table too. */
517 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
))
520 ret
->stub_bfd
= NULL
;
521 ret
->add_stub_section
= NULL
;
522 ret
->layout_sections_again
= NULL
;
523 ret
->stub_group
= NULL
;
530 ret
->multi_subspace
= 0;
531 ret
->has_12bit_branch
= 0;
532 ret
->has_17bit_branch
= 0;
533 ret
->need_plt_stub
= 0;
535 return &ret
->root
.root
;
539 /* Build a name for an entry in the stub hash table. */
542 hppa_stub_name (input_section
, sym_sec
, hash
, rel
)
543 const asection
*input_section
;
544 const asection
*sym_sec
;
545 const struct elf32_hppa_link_hash_entry
*hash
;
546 const Elf_Internal_Rela
*rel
;
553 len
= 8 + 1 + strlen (hash
->elf
.root
.root
.string
) + 1 + 8 + 1;
554 stub_name
= bfd_malloc (len
);
555 if (stub_name
!= NULL
)
557 sprintf (stub_name
, "%08x_%s+%x",
558 input_section
->id
& 0xffffffff,
559 hash
->elf
.root
.root
.string
,
560 (int) rel
->r_addend
& 0xffffffff);
565 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
566 stub_name
= bfd_malloc (len
);
567 if (stub_name
!= NULL
)
569 sprintf (stub_name
, "%08x_%x:%x+%x",
570 input_section
->id
& 0xffffffff,
571 sym_sec
->id
& 0xffffffff,
572 (int) ELF32_R_SYM (rel
->r_info
) & 0xffffffff,
573 (int) rel
->r_addend
& 0xffffffff);
580 /* Look up an entry in the stub hash. Stub entries are cached because
581 creating the stub name takes a bit of time. */
583 static struct elf32_hppa_stub_hash_entry
*
584 hppa_get_stub_entry (input_section
, sym_sec
, hash
, rel
, hplink
)
585 const asection
*input_section
;
586 const asection
*sym_sec
;
587 struct elf32_hppa_link_hash_entry
*hash
;
588 const Elf_Internal_Rela
*rel
;
589 struct elf32_hppa_link_hash_table
*hplink
;
591 struct elf32_hppa_stub_hash_entry
*stub_entry
;
592 const asection
*id_sec
;
594 /* If this input section is part of a group of sections sharing one
595 stub section, then use the id of the first section in the group.
596 Stub names need to include a section id, as there may well be
597 more than one stub used to reach say, printf, and we need to
598 distinguish between them. */
599 id_sec
= hplink
->stub_group
[input_section
->id
].link_sec
;
601 if (hash
!= NULL
&& hash
->stub_cache
!= NULL
602 && hash
->stub_cache
->h
== hash
603 && hash
->stub_cache
->id_sec
== id_sec
)
605 stub_entry
= hash
->stub_cache
;
611 stub_name
= hppa_stub_name (id_sec
, sym_sec
, hash
, rel
);
612 if (stub_name
== NULL
)
615 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
,
616 stub_name
, false, false);
617 if (stub_entry
== NULL
)
619 if (hash
== NULL
|| hash
->elf
.root
.type
!= bfd_link_hash_undefweak
)
620 (*_bfd_error_handler
) (_("%s(%s+0x%lx): cannot find stub entry %s"),
621 bfd_get_filename (input_section
->owner
),
623 (long) rel
->r_offset
,
629 hash
->stub_cache
= stub_entry
;
639 /* Add a new stub entry to the stub hash. Not all fields of the new
640 stub entry are initialised. */
642 static struct elf32_hppa_stub_hash_entry
*
643 hppa_add_stub (stub_name
, section
, hplink
)
644 const char *stub_name
;
646 struct elf32_hppa_link_hash_table
*hplink
;
650 struct elf32_hppa_stub_hash_entry
*stub_entry
;
652 link_sec
= hplink
->stub_group
[section
->id
].link_sec
;
653 stub_sec
= hplink
->stub_group
[section
->id
].stub_sec
;
654 if (stub_sec
== NULL
)
656 stub_sec
= hplink
->stub_group
[link_sec
->id
].stub_sec
;
657 if (stub_sec
== NULL
)
662 len
= strlen (link_sec
->name
) + sizeof (STUB_SUFFIX
);
663 s_name
= bfd_alloc (hplink
->stub_bfd
, len
);
667 strcpy (s_name
, link_sec
->name
);
668 strcpy (s_name
+ len
- sizeof (STUB_SUFFIX
), STUB_SUFFIX
);
669 stub_sec
= (*hplink
->add_stub_section
) (s_name
, link_sec
);
670 if (stub_sec
== NULL
)
672 hplink
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
674 hplink
->stub_group
[section
->id
].stub_sec
= stub_sec
;
677 /* Enter this entry into the linker stub hash table. */
678 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
, stub_name
,
680 if (stub_entry
== NULL
)
682 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
683 bfd_get_filename (section
->owner
),
688 stub_entry
->stub_sec
= stub_sec
;
689 #if ! LONG_BRANCH_PIC_IN_SHLIB
690 stub_entry
->reloc_sec
= hplink
->stub_group
[section
->id
].reloc_sec
;
692 stub_entry
->stub_offset
= 0;
693 stub_entry
->id_sec
= link_sec
;
698 /* Determine the type of stub needed, if any, for a call. */
700 static enum elf32_hppa_stub_type
701 hppa_type_of_stub (input_sec
, rel
, hash
, destination
)
703 const Elf_Internal_Rela
*rel
;
704 struct elf32_hppa_link_hash_entry
*hash
;
708 bfd_vma branch_offset
;
709 bfd_vma max_branch_offset
;
713 && (((hash
->elf
.root
.type
== bfd_link_hash_defined
714 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
715 && hash
->elf
.root
.u
.def
.section
->output_section
== NULL
)
716 || (hash
->elf
.root
.type
== bfd_link_hash_defweak
717 && hash
->elf
.dynindx
!= -1
718 && hash
->elf
.plt
.offset
!= (bfd_vma
) -1)
719 || hash
->elf
.root
.type
== bfd_link_hash_undefweak
720 || hash
->elf
.root
.type
== bfd_link_hash_undefined
723 /* If output_section is NULL, then it's a symbol defined in a
724 shared library. We will need an import stub. Decide between
725 hppa_stub_import and hppa_stub_import_shared later. For
726 shared links we need stubs for undefined or weak syms too;
727 They will presumably be resolved by the dynamic linker. */
728 return hppa_stub_import
;
731 /* Determine where the call point is. */
732 location
= (input_sec
->output_offset
733 + input_sec
->output_section
->vma
736 branch_offset
= destination
- location
- 8;
737 r_type
= ELF32_R_TYPE (rel
->r_info
);
739 /* Determine if a long branch stub is needed. parisc branch offsets
740 are relative to the second instruction past the branch, ie. +8
741 bytes on from the branch instruction location. The offset is
742 signed and counts in units of 4 bytes. */
743 if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
745 max_branch_offset
= (1 << (17-1)) << 2;
747 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
749 max_branch_offset
= (1 << (12-1)) << 2;
751 else /* R_PARISC_PCREL22F. */
753 max_branch_offset
= (1 << (22-1)) << 2;
756 if (branch_offset
+ max_branch_offset
>= 2*max_branch_offset
)
758 #if LONG_BRANCH_VIA_PLT
760 && hash
->elf
.dynindx
!= -1
761 && hash
->elf
.plt
.offset
!= (bfd_vma
) -1)
763 /* If we are doing a shared link and find we need a long
764 branch stub, then go via the .plt if possible. */
765 return hppa_stub_import
;
769 return hppa_stub_long_branch
;
771 return hppa_stub_none
;
775 /* Build one linker stub as defined by the stub hash table entry GEN_ENTRY.
776 IN_ARG contains the link info pointer. */
778 #define LDIL_R1 0x20200000 /* ldil LR'XXX,%r1 */
779 #define BE_SR4_R1 0xe0202002 /* be,n RR'XXX(%sr4,%r1) */
781 #define BL_R1 0xe8200000 /* b,l .+8,%r1 */
782 #define ADDIL_R1 0x28200000 /* addil L'XXX,%r1,%r1 */
783 #define DEPI_R1 0xd4201c1e /* depi 0,31,2,%r1 */
785 #define ADDIL_DP 0x2b600000 /* addil L'XXX,%dp,%r1 */
786 #define LDW_R1_R21 0x48350000 /* ldw R'XXX(%sr0,%r1),%r21 */
787 #define BV_R0_R21 0xeaa0c000 /* bv %r0(%r21) */
788 #define LDW_R1_R19 0x48330000 /* ldw R'XXX(%sr0,%r1),%r19 */
790 #define ADDIL_R19 0x2a600000 /* addil L'XXX,%r19,%r1 */
791 #define LDW_R1_DP 0x483b0000 /* ldw R'XXX(%sr0,%r1),%dp */
793 #define LDSID_R21_R1 0x02a010a1 /* ldsid (%sr0,%r21),%r1 */
794 #define MTSP_R1 0x00011820 /* mtsp %r1,%sr0 */
795 #define BE_SR0_R21 0xe2a00000 /* be 0(%sr0,%r21) */
796 #define STW_RP 0x6bc23fd1 /* stw %rp,-24(%sr0,%sp) */
798 #define BL_RP 0xe8400002 /* b,l,n XXX,%rp */
799 #define NOP 0x08000240 /* nop */
800 #define LDW_RP 0x4bc23fd1 /* ldw -24(%sr0,%sp),%rp */
801 #define LDSID_RP_R1 0x004010a1 /* ldsid (%sr0,%rp),%r1 */
802 #define BE_SR0_RP 0xe0400002 /* be,n 0(%sr0,%rp) */
809 #define LDW_R1_DLT LDW_R1_R19
811 #define LDW_R1_DLT LDW_R1_DP
815 hppa_build_one_stub (gen_entry
, in_arg
)
816 struct bfd_hash_entry
*gen_entry
;
819 struct elf32_hppa_stub_hash_entry
*stub_entry
;
820 struct bfd_link_info
*info
;
821 struct elf32_hppa_link_hash_table
*hplink
;
830 /* Massage our args to the form they really have. */
831 stub_entry
= (struct elf32_hppa_stub_hash_entry
*) gen_entry
;
832 info
= (struct bfd_link_info
*) in_arg
;
834 hplink
= hppa_link_hash_table (info
);
835 stub_sec
= stub_entry
->stub_sec
;
837 /* Make a note of the offset within the stubs for this entry. */
838 stub_entry
->stub_offset
= stub_sec
->_raw_size
;
839 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
841 stub_bfd
= stub_sec
->owner
;
843 switch (stub_entry
->stub_type
)
845 case hppa_stub_long_branch
:
846 /* Create the long branch. A long branch is formed with "ldil"
847 loading the upper bits of the target address into a register,
848 then branching with "be" which adds in the lower bits.
849 The "be" has its delay slot nullified. */
850 sym_value
= (stub_entry
->target_value
851 + stub_entry
->target_section
->output_offset
852 + stub_entry
->target_section
->output_section
->vma
);
854 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_lrsel
);
855 insn
= hppa_rebuild_insn ((int) LDIL_R1
, val
, 21);
856 bfd_put_32 (stub_bfd
, insn
, loc
);
858 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_rrsel
) >> 2;
859 insn
= hppa_rebuild_insn ((int) BE_SR4_R1
, val
, 17);
860 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
862 #if ! LONG_BRANCH_PIC_IN_SHLIB
865 /* Output a dynamic relocation for this stub. We only
866 output one PCREL21L reloc per stub, trusting that the
867 dynamic linker will also fix the implied PCREL17R for the
868 second instruction. PCREL21L dynamic relocs had better
869 never be emitted for some other purpose... */
871 Elf_Internal_Rela outrel
;
873 if (stub_entry
->h
== NULL
)
875 (*_bfd_error_handler
)
876 (_("%s(%s+0x%lx): cannot relocate %s, recompile with -ffunction-sections"),
877 bfd_get_filename (stub_entry
->target_section
->owner
),
879 (long) stub_entry
->stub_offset
,
880 stub_entry
->root
.string
);
881 bfd_set_error (bfd_error_bad_value
);
885 srel
= stub_entry
->reloc_sec
;
888 (*_bfd_error_handler
)
889 (_("Could not find relocation section for %s"),
891 bfd_set_error (bfd_error_bad_value
);
895 outrel
.r_offset
= (stub_entry
->stub_offset
896 + stub_sec
->output_offset
897 + stub_sec
->output_section
->vma
);
898 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_PCREL21L
);
899 outrel
.r_addend
= sym_value
;
900 bfd_elf32_swap_reloca_out (stub_sec
->output_section
->owner
,
902 ((Elf32_External_Rela
*)
903 srel
->contents
+ srel
->reloc_count
));
910 case hppa_stub_long_branch_shared
:
911 /* Branches are relative. This is where we are going to. */
912 sym_value
= (stub_entry
->target_value
913 + stub_entry
->target_section
->output_offset
914 + stub_entry
->target_section
->output_section
->vma
);
916 /* And this is where we are coming from, more or less. */
917 sym_value
-= (stub_entry
->stub_offset
918 + stub_sec
->output_offset
919 + stub_sec
->output_section
->vma
);
921 bfd_put_32 (stub_bfd
, (bfd_vma
) BL_R1
, loc
);
922 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_lrsel
);
923 insn
= hppa_rebuild_insn ((int) ADDIL_R1
, val
, 21);
924 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
926 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_rrsel
) >> 2;
927 insn
= hppa_rebuild_insn ((int) BE_SR4_R1
, val
, 17);
928 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
932 case hppa_stub_import
:
933 case hppa_stub_import_shared
:
934 sym_value
= (stub_entry
->h
->elf
.plt
.offset
935 + hplink
->splt
->output_offset
936 + hplink
->splt
->output_section
->vma
937 - elf_gp (hplink
->splt
->output_section
->owner
));
941 if (stub_entry
->stub_type
== hppa_stub_import_shared
)
944 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_lrsel
),
945 insn
= hppa_rebuild_insn ((int) insn
, val
, 21);
946 bfd_put_32 (stub_bfd
, insn
, loc
);
948 /* It is critical to use lrsel/rrsel here because we are using
949 two different offsets (+0 and +4) from sym_value. If we use
950 lsel/rsel then with unfortunate sym_values we will round
951 sym_value+4 up to the next 2k block leading to a mis-match
952 between the lsel and rsel value. */
953 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_rrsel
);
954 insn
= hppa_rebuild_insn ((int) LDW_R1_R21
, val
, 14);
955 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
957 if (hplink
->multi_subspace
)
959 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 4, e_rrsel
);
960 insn
= hppa_rebuild_insn ((int) LDW_R1_DLT
, val
, 14);
961 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
963 bfd_put_32 (stub_bfd
, (bfd_vma
) LDSID_R21_R1
, loc
+ 12);
964 bfd_put_32 (stub_bfd
, (bfd_vma
) MTSP_R1
, loc
+ 16);
965 bfd_put_32 (stub_bfd
, (bfd_vma
) BE_SR0_R21
, loc
+ 20);
966 bfd_put_32 (stub_bfd
, (bfd_vma
) STW_RP
, loc
+ 24);
972 bfd_put_32 (stub_bfd
, (bfd_vma
) BV_R0_R21
, loc
+ 8);
973 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 4, e_rrsel
);
974 insn
= hppa_rebuild_insn ((int) LDW_R1_DLT
, val
, 14);
975 bfd_put_32 (stub_bfd
, insn
, loc
+ 12);
981 && stub_entry
->h
!= NULL
982 && stub_entry
->h
->pic_call
)
984 /* Build the .plt entry needed to call a PIC function from
985 statically linked code. We don't need any relocs. */
987 struct elf32_hppa_link_hash_entry
*eh
;
990 dynobj
= hplink
->root
.dynobj
;
991 eh
= (struct elf32_hppa_link_hash_entry
*) stub_entry
->h
;
993 BFD_ASSERT (eh
->elf
.root
.type
== bfd_link_hash_defined
994 || eh
->elf
.root
.type
== bfd_link_hash_defweak
);
996 value
= (eh
->elf
.root
.u
.def
.value
997 + eh
->elf
.root
.u
.def
.section
->output_offset
998 + eh
->elf
.root
.u
.def
.section
->output_section
->vma
);
1000 /* Fill in the entry in the procedure linkage table.
1002 The format of a plt entry is
1006 bfd_put_32 (hplink
->splt
->owner
, value
,
1007 hplink
->splt
->contents
+ eh
->elf
.plt
.offset
);
1008 value
= elf_gp (hplink
->splt
->output_section
->owner
);
1009 bfd_put_32 (hplink
->splt
->owner
, value
,
1010 hplink
->splt
->contents
+ eh
->elf
.plt
.offset
+ 4);
1014 case hppa_stub_export
:
1015 /* Branches are relative. This is where we are going to. */
1016 sym_value
= (stub_entry
->target_value
1017 + stub_entry
->target_section
->output_offset
1018 + stub_entry
->target_section
->output_section
->vma
);
1020 /* And this is where we are coming from. */
1021 sym_value
-= (stub_entry
->stub_offset
1022 + stub_sec
->output_offset
1023 + stub_sec
->output_section
->vma
);
1025 if (sym_value
- 8 + 0x40000 >= 0x80000)
1027 (*_bfd_error_handler
)
1028 (_("%s(%s+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
1029 bfd_get_filename (stub_entry
->target_section
->owner
),
1031 (long) stub_entry
->stub_offset
,
1032 stub_entry
->root
.string
);
1033 bfd_set_error (bfd_error_bad_value
);
1037 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_fsel
) >> 2;
1038 insn
= hppa_rebuild_insn ((int) BL_RP
, val
, 17);
1039 bfd_put_32 (stub_bfd
, insn
, loc
);
1041 bfd_put_32 (stub_bfd
, (bfd_vma
) NOP
, loc
+ 4);
1042 bfd_put_32 (stub_bfd
, (bfd_vma
) LDW_RP
, loc
+ 8);
1043 bfd_put_32 (stub_bfd
, (bfd_vma
) LDSID_RP_R1
, loc
+ 12);
1044 bfd_put_32 (stub_bfd
, (bfd_vma
) MTSP_R1
, loc
+ 16);
1045 bfd_put_32 (stub_bfd
, (bfd_vma
) BE_SR0_RP
, loc
+ 20);
1047 /* Point the function symbol at the stub. */
1048 stub_entry
->h
->elf
.root
.u
.def
.section
= stub_sec
;
1049 stub_entry
->h
->elf
.root
.u
.def
.value
= stub_sec
->_raw_size
;
1059 stub_sec
->_raw_size
+= size
;
1086 /* As above, but don't actually build the stub. Just bump offset so
1087 we know stub section sizes. */
1090 hppa_size_one_stub (gen_entry
, in_arg
)
1091 struct bfd_hash_entry
*gen_entry
;
1094 struct elf32_hppa_stub_hash_entry
*stub_entry
;
1095 struct elf32_hppa_link_hash_table
*hplink
;
1098 /* Massage our args to the form they really have. */
1099 stub_entry
= (struct elf32_hppa_stub_hash_entry
*) gen_entry
;
1100 hplink
= (struct elf32_hppa_link_hash_table
*) in_arg
;
1102 if (stub_entry
->stub_type
== hppa_stub_long_branch
)
1104 #if ! LONG_BRANCH_PIC_IN_SHLIB
1105 if (stub_entry
->reloc_sec
!= NULL
)
1106 stub_entry
->reloc_sec
->_raw_size
+= sizeof (Elf32_External_Rela
);
1110 else if (stub_entry
->stub_type
== hppa_stub_long_branch_shared
)
1112 else if (stub_entry
->stub_type
== hppa_stub_export
)
1114 else /* hppa_stub_import or hppa_stub_import_shared. */
1116 if (hplink
->multi_subspace
)
1122 stub_entry
->stub_sec
->_raw_size
+= size
;
1127 /* Return nonzero if ABFD represents an HPPA ELF32 file.
1128 Additionally we set the default architecture and machine. */
1131 elf32_hppa_object_p (abfd
)
1134 unsigned int flags
= elf_elfheader (abfd
)->e_flags
;
1136 switch (flags
& (EF_PARISC_ARCH
| EF_PARISC_WIDE
))
1138 case EFA_PARISC_1_0
:
1139 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 10);
1140 case EFA_PARISC_1_1
:
1141 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 11);
1142 case EFA_PARISC_2_0
:
1143 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 20);
1144 case EFA_PARISC_2_0
| EF_PARISC_WIDE
:
1145 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 25);
1151 /* Undo the generic ELF code's subtraction of section->vma from the
1152 value of each external symbol. */
1155 elf32_hppa_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
1156 bfd
*abfd ATTRIBUTE_UNUSED
;
1157 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1158 const Elf_Internal_Sym
*sym ATTRIBUTE_UNUSED
;
1159 const char **namep ATTRIBUTE_UNUSED
;
1160 flagword
*flagsp ATTRIBUTE_UNUSED
;
1164 *valp
+= (*secp
)->vma
;
1169 /* Create the .plt and .got sections, and set up our hash table
1170 short-cuts to various dynamic sections. */
1173 elf32_hppa_create_dynamic_sections (abfd
, info
)
1175 struct bfd_link_info
*info
;
1177 struct elf32_hppa_link_hash_table
*hplink
;
1179 /* Don't try to create the .plt and .got twice. */
1180 hplink
= hppa_link_hash_table (info
);
1181 if (hplink
->splt
!= NULL
)
1184 /* Call the generic code to do most of the work. */
1185 if (! _bfd_elf_create_dynamic_sections (abfd
, info
))
1188 hplink
->splt
= bfd_get_section_by_name (abfd
, ".plt");
1189 hplink
->srelplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
1191 hplink
->sgot
= bfd_get_section_by_name (abfd
, ".got");
1192 hplink
->srelgot
= bfd_make_section (abfd
, ".rela.got");
1193 if (hplink
->srelgot
== NULL
1194 || ! bfd_set_section_flags (abfd
, hplink
->srelgot
,
1199 | SEC_LINKER_CREATED
1201 || ! bfd_set_section_alignment (abfd
, hplink
->srelgot
, 2))
1204 hplink
->sdynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
1205 hplink
->srelbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
1211 /* Look through the relocs for a section during the first phase, and
1212 allocate space in the global offset table or procedure linkage
1213 table. At this point we haven't necessarily read all the input
1217 elf32_hppa_check_relocs (abfd
, info
, sec
, relocs
)
1219 struct bfd_link_info
*info
;
1221 const Elf_Internal_Rela
*relocs
;
1224 Elf_Internal_Shdr
*symtab_hdr
;
1225 struct elf_link_hash_entry
**sym_hashes
;
1226 bfd_signed_vma
*local_got_refcounts
;
1227 const Elf_Internal_Rela
*rel
;
1228 const Elf_Internal_Rela
*rel_end
;
1229 struct elf32_hppa_link_hash_table
*hplink
;
1231 asection
*stubreloc
;
1233 if (info
->relocateable
)
1236 hplink
= hppa_link_hash_table (info
);
1237 dynobj
= hplink
->root
.dynobj
;
1238 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1239 sym_hashes
= elf_sym_hashes (abfd
);
1240 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1244 rel_end
= relocs
+ sec
->reloc_count
;
1245 for (rel
= relocs
; rel
< rel_end
; rel
++)
1251 #if LONG_BRANCH_PIC_IN_SHLIB
1252 NEED_STUBREL
= 0, /* We won't be needing them in this case. */
1259 unsigned int r_symndx
, r_type
;
1260 struct elf32_hppa_link_hash_entry
*h
;
1263 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1265 if (r_symndx
< symtab_hdr
->sh_info
)
1268 h
= ((struct elf32_hppa_link_hash_entry
*)
1269 sym_hashes
[r_symndx
- symtab_hdr
->sh_info
]);
1271 r_type
= ELF32_R_TYPE (rel
->r_info
);
1275 case R_PARISC_DLTIND14F
:
1276 case R_PARISC_DLTIND14R
:
1277 case R_PARISC_DLTIND21L
:
1278 /* This symbol requires a global offset table entry. */
1279 need_entry
= NEED_GOT
;
1281 /* Mark this section as containing PIC code. */
1282 sec
->flags
|= SEC_HAS_GOT_REF
;
1285 case R_PARISC_PLABEL14R
: /* "Official" procedure labels. */
1286 case R_PARISC_PLABEL21L
:
1287 case R_PARISC_PLABEL32
:
1288 /* If the addend is non-zero, we break badly. */
1289 BFD_ASSERT (rel
->r_addend
== 0);
1291 /* If we are creating a shared library, then we need to
1292 create a PLT entry for all PLABELs, because PLABELs with
1293 local symbols may be passed via a pointer to another
1294 object. Additionally, output a dynamic relocation
1295 pointing to the PLT entry. */
1296 need_entry
= PLT_PLABEL
| NEED_PLT
| NEED_DYNREL
;
1299 case R_PARISC_PCREL12F
:
1300 hplink
->has_12bit_branch
= 1;
1302 case R_PARISC_PCREL17C
:
1303 case R_PARISC_PCREL17F
:
1304 hplink
->has_17bit_branch
= 1;
1306 case R_PARISC_PCREL22F
:
1307 /* Function calls might need to go through the .plt, and
1308 might require long branch stubs. */
1311 /* We know local syms won't need a .plt entry, and if
1312 they need a long branch stub we can't guarantee that
1313 we can reach the stub. So just flag an error later
1314 if we're doing a shared link and find we need a long
1320 /* Global symbols will need a .plt entry if they remain
1321 global, and in most cases won't need a long branch
1322 stub. Unfortunately, we have to cater for the case
1323 where a symbol is forced local by versioning, or due
1324 to symbolic linking, and we lose the .plt entry. */
1325 need_entry
= NEED_PLT
| NEED_STUBREL
;
1329 case R_PARISC_SEGBASE
: /* Used to set segment base. */
1330 case R_PARISC_SEGREL32
: /* Relative reloc. */
1331 case R_PARISC_PCREL14F
: /* PC relative load/store. */
1332 case R_PARISC_PCREL14R
:
1333 case R_PARISC_PCREL17R
: /* External branches. */
1334 case R_PARISC_PCREL21L
: /* As above, and for load/store too. */
1335 /* We don't need to propagate the relocation if linking a
1336 shared object since these are section relative. */
1339 case R_PARISC_DPREL14F
: /* Used for gp rel data load/store. */
1340 case R_PARISC_DPREL14R
:
1341 case R_PARISC_DPREL21L
:
1344 (*_bfd_error_handler
)
1345 (_("%s: relocation %s can not be used when making a shared object; recompile with -fPIC"),
1346 bfd_get_filename (abfd
),
1347 elf_hppa_howto_table
[r_type
].name
);
1348 bfd_set_error (bfd_error_bad_value
);
1353 case R_PARISC_DIR17F
: /* Used for external branches. */
1354 case R_PARISC_DIR17R
:
1355 case R_PARISC_DIR14F
: /* Used for load/store from absolute locn. */
1356 case R_PARISC_DIR14R
:
1357 case R_PARISC_DIR21L
: /* As above, and for ext branches too. */
1359 /* Help debug shared library creation. Any of the above
1360 relocs can be used in shared libs, but they may cause
1361 pages to become unshared. */
1364 (*_bfd_error_handler
)
1365 (_("%s: relocation %s should not be used when making a shared object; recompile with -fPIC"),
1366 bfd_get_filename (abfd
),
1367 elf_hppa_howto_table
[r_type
].name
);
1372 case R_PARISC_DIR32
: /* .word, PARISC.unwind relocs. */
1373 /* We may want to output a dynamic relocation later. */
1374 need_entry
= NEED_DYNREL
;
1377 /* This relocation describes the C++ object vtable hierarchy.
1378 Reconstruct it for later use during GC. */
1379 case R_PARISC_GNU_VTINHERIT
:
1380 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
,
1381 &h
->elf
, rel
->r_offset
))
1385 /* This relocation describes which C++ vtable entries are actually
1386 used. Record for later use during GC. */
1387 case R_PARISC_GNU_VTENTRY
:
1388 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
,
1389 &h
->elf
, rel
->r_offset
))
1397 /* Now carry out our orders. */
1398 if (need_entry
& NEED_GOT
)
1400 /* Allocate space for a GOT entry, as well as a dynamic
1401 relocation for this entry. */
1403 hplink
->root
.dynobj
= dynobj
= abfd
;
1405 if (hplink
->sgot
== NULL
)
1407 if (! elf32_hppa_create_dynamic_sections (dynobj
, info
))
1413 if (h
->elf
.got
.refcount
== -1)
1415 h
->elf
.got
.refcount
= 1;
1417 /* Make sure this symbol is output as a dynamic symbol. */
1418 if (h
->elf
.dynindx
== -1)
1420 if (! bfd_elf32_link_record_dynamic_symbol (info
,
1425 hplink
->sgot
->_raw_size
+= GOT_ENTRY_SIZE
;
1426 hplink
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
1429 h
->elf
.got
.refcount
+= 1;
1433 /* This is a global offset table entry for a local symbol. */
1434 if (local_got_refcounts
== NULL
)
1438 /* Allocate space for local got offsets and local
1439 plt offsets. Done this way to save polluting
1440 elf_obj_tdata with another target specific
1442 size
= symtab_hdr
->sh_info
* 2 * sizeof (bfd_signed_vma
);
1443 local_got_refcounts
= ((bfd_signed_vma
*)
1444 bfd_alloc (abfd
, size
));
1445 if (local_got_refcounts
== NULL
)
1447 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1448 memset (local_got_refcounts
, -1, size
);
1450 if (local_got_refcounts
[r_symndx
] == -1)
1452 local_got_refcounts
[r_symndx
] = 1;
1454 hplink
->sgot
->_raw_size
+= GOT_ENTRY_SIZE
;
1457 /* If we are generating a shared object, we need to
1458 output a reloc so that the dynamic linker can
1459 adjust this GOT entry (because the address
1460 the shared library is loaded at is not fixed). */
1461 hplink
->srelgot
->_raw_size
+=
1462 sizeof (Elf32_External_Rela
);
1466 local_got_refcounts
[r_symndx
] += 1;
1470 if (need_entry
& NEED_PLT
)
1472 /* If we are creating a shared library, and this is a reloc
1473 against a weak symbol or a global symbol in a dynamic
1474 object, then we will be creating an import stub and a
1475 .plt entry for the symbol. Similarly, on a normal link
1476 to symbols defined in a dynamic object we'll need the
1477 import stub and a .plt entry. We don't know yet whether
1478 the symbol is defined or not, so make an entry anyway and
1479 clean up later in adjust_dynamic_symbol. */
1480 if ((sec
->flags
& SEC_ALLOC
) != 0)
1484 if (h
->elf
.plt
.refcount
== -1)
1486 h
->elf
.plt
.refcount
= 1;
1487 h
->elf
.elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1490 h
->elf
.plt
.refcount
+= 1;
1492 /* If this .plt entry is for a plabel, we need an
1493 extra word for ld.so. adjust_dynamic_symbol will
1494 also keep the entry even if it appears to be
1496 if (need_entry
& PLT_PLABEL
)
1499 else if (need_entry
& PLT_PLABEL
)
1503 if (local_got_refcounts
== NULL
)
1507 /* Allocate space for local got offsets and local
1509 size
= symtab_hdr
->sh_info
* 2 * sizeof (bfd_signed_vma
);
1510 local_got_refcounts
= ((bfd_signed_vma
*)
1511 bfd_alloc (abfd
, size
));
1512 if (local_got_refcounts
== NULL
)
1514 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1515 memset (local_got_refcounts
, -1, size
);
1517 indx
= r_symndx
+ symtab_hdr
->sh_info
;
1518 if (local_got_refcounts
[indx
] == -1)
1519 local_got_refcounts
[indx
] = 1;
1521 local_got_refcounts
[indx
] += 1;
1526 if (need_entry
& (NEED_DYNREL
| NEED_STUBREL
))
1528 /* Flag this symbol as having a non-got, non-plt reference
1529 so that we generate copy relocs if it turns out to be
1532 h
->elf
.elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
1534 /* If we are creating a shared library then we need to copy
1535 the reloc into the shared library. However, if we are
1536 linking with -Bsymbolic, we need only copy absolute
1537 relocs or relocs against symbols that are not defined in
1538 an object we are including in the link. PC- or DP- or
1539 DLT-relative relocs against any local sym or global sym
1540 with DEF_REGULAR set, can be discarded. At this point we
1541 have not seen all the input files, so it is possible that
1542 DEF_REGULAR is not set now but will be set later (it is
1543 never cleared). We account for that possibility below by
1544 storing information in the reloc_entries field of the
1547 A similar situation to the -Bsymbolic case occurs when
1548 creating shared libraries and symbol visibility changes
1549 render the symbol local.
1551 As it turns out, all the relocs we will be creating here
1552 are absolute, so we cannot remove them on -Bsymbolic
1553 links or visibility changes anyway. A STUB_REL reloc
1554 is absolute too, as in that case it is the reloc in the
1555 stub we will be creating, rather than copying the PCREL
1556 reloc in the branch. */
1557 if ((sec
->flags
& SEC_ALLOC
) != 0
1559 #if RELATIVE_DYNAMIC_RELOCS
1561 || is_absolute_reloc (r_type
)
1563 && ((h
->elf
.elf_link_hash_flags
1564 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
1572 if ((need_entry
& NEED_STUBREL
))
1575 /* Create a reloc section in dynobj and make room for
1582 hplink
->root
.dynobj
= dynobj
= abfd
;
1584 name
= bfd_elf_string_from_elf_section
1586 elf_elfheader (abfd
)->e_shstrndx
,
1587 elf_section_data (sec
)->rel_hdr
.sh_name
);
1590 (*_bfd_error_handler
)
1591 (_("Could not find relocation section for %s"),
1593 bfd_set_error (bfd_error_bad_value
);
1597 if ((need_entry
& NEED_STUBREL
))
1599 size_t len
= strlen (name
) + sizeof (STUB_SUFFIX
);
1600 char *newname
= bfd_malloc (len
);
1602 if (newname
== NULL
)
1604 strcpy (newname
, name
);
1605 strcpy (newname
+ len
- sizeof (STUB_SUFFIX
),
1610 srel
= bfd_get_section_by_name (dynobj
, name
);
1615 srel
= bfd_make_section (dynobj
, name
);
1616 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
1617 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1618 if ((sec
->flags
& SEC_ALLOC
) != 0)
1619 flags
|= SEC_ALLOC
| SEC_LOAD
;
1621 || !bfd_set_section_flags (dynobj
, srel
, flags
)
1622 || !bfd_set_section_alignment (dynobj
, srel
, 2))
1625 else if ((need_entry
& NEED_STUBREL
))
1628 if ((need_entry
& NEED_STUBREL
))
1634 #if ! LONG_BRANCH_PIC_IN_SHLIB
1635 /* If this is a function call, we only need one dynamic
1636 reloc for the stub as all calls to a particular
1637 function will go through the same stub. Actually, a
1638 long branch stub needs two relocations, but we count
1639 on some intelligence on the part of the dynamic
1641 if ((need_entry
& NEED_STUBREL
))
1643 doit
= h
->stub_reloc_sec
!= stubreloc
;
1644 h
->stub_reloc_sec
= stubreloc
;
1652 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
1654 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
1655 /* Keep track of relocations we have entered for
1656 this global symbol, so that we can discard them
1657 later if necessary. */
1660 #if RELATIVE_DYNAMIC_RELOCS
1661 || ! is_absolute_reloc (rtype
)
1663 || (need_entry
& NEED_STUBREL
)))
1665 struct elf32_hppa_dyn_reloc_entry
*p
;
1667 for (p
= h
->reloc_entries
; p
!= NULL
; p
= p
->next
)
1668 if (p
->section
== srel
)
1673 p
= ((struct elf32_hppa_dyn_reloc_entry
*)
1674 bfd_alloc (dynobj
, sizeof *p
));
1677 p
->next
= h
->reloc_entries
;
1678 h
->reloc_entries
= p
;
1683 /* NEED_STUBREL and NEED_DYNREL are never both
1684 set. Leave the count at zero for the
1685 NEED_STUBREL case as we only ever have one
1686 stub reloc per section per symbol, and this
1687 simplifies code in hppa_discard_copies. */
1688 if (! (need_entry
& NEED_STUBREL
))
1701 /* Return the section that should be marked against garbage collection
1702 for a given relocation. */
1705 elf32_hppa_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
1707 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1708 Elf_Internal_Rela
*rel
;
1709 struct elf_link_hash_entry
*h
;
1710 Elf_Internal_Sym
*sym
;
1714 switch ((unsigned int) ELF32_R_TYPE (rel
->r_info
))
1716 case R_PARISC_GNU_VTINHERIT
:
1717 case R_PARISC_GNU_VTENTRY
:
1721 switch (h
->root
.type
)
1723 case bfd_link_hash_defined
:
1724 case bfd_link_hash_defweak
:
1725 return h
->root
.u
.def
.section
;
1727 case bfd_link_hash_common
:
1728 return h
->root
.u
.c
.p
->section
;
1737 if (!(elf_bad_symtab (abfd
)
1738 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
1739 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
1740 && sym
->st_shndx
!= SHN_COMMON
))
1742 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
1750 /* Update the got and plt entry reference counts for the section being
1754 elf32_hppa_gc_sweep_hook (abfd
, info
, sec
, relocs
)
1756 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1758 const Elf_Internal_Rela
*relocs
;
1760 Elf_Internal_Shdr
*symtab_hdr
;
1761 struct elf_link_hash_entry
**sym_hashes
;
1762 bfd_signed_vma
*local_got_refcounts
;
1763 bfd_signed_vma
*local_plt_refcounts
;
1764 const Elf_Internal_Rela
*rel
, *relend
;
1765 unsigned long r_symndx
;
1766 struct elf_link_hash_entry
*h
;
1767 struct elf32_hppa_link_hash_table
*hplink
;
1772 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1773 sym_hashes
= elf_sym_hashes (abfd
);
1774 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1775 local_plt_refcounts
= local_got_refcounts
;
1776 if (local_plt_refcounts
!= NULL
)
1777 local_plt_refcounts
+= symtab_hdr
->sh_info
;
1778 hplink
= hppa_link_hash_table (info
);
1779 dynobj
= hplink
->root
.dynobj
;
1783 sgot
= hplink
->sgot
;
1784 srelgot
= hplink
->srelgot
;
1786 relend
= relocs
+ sec
->reloc_count
;
1787 for (rel
= relocs
; rel
< relend
; rel
++)
1788 switch ((unsigned int) ELF32_R_TYPE (rel
->r_info
))
1790 case R_PARISC_DLTIND14F
:
1791 case R_PARISC_DLTIND14R
:
1792 case R_PARISC_DLTIND21L
:
1793 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1794 if (r_symndx
>= symtab_hdr
->sh_info
)
1796 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1797 if (h
->got
.refcount
> 0)
1799 h
->got
.refcount
-= 1;
1800 if (h
->got
.refcount
== 0)
1802 sgot
->_raw_size
-= GOT_ENTRY_SIZE
;
1803 srelgot
->_raw_size
-= sizeof (Elf32_External_Rela
);
1807 else if (local_got_refcounts
!= NULL
)
1809 if (local_got_refcounts
[r_symndx
] > 0)
1811 local_got_refcounts
[r_symndx
] -= 1;
1812 if (local_got_refcounts
[r_symndx
] == 0)
1814 sgot
->_raw_size
-= GOT_ENTRY_SIZE
;
1816 srelgot
->_raw_size
-= sizeof (Elf32_External_Rela
);
1822 case R_PARISC_PCREL12F
:
1823 case R_PARISC_PCREL17C
:
1824 case R_PARISC_PCREL17F
:
1825 case R_PARISC_PCREL22F
:
1826 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1827 if (r_symndx
>= symtab_hdr
->sh_info
)
1829 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1830 if (h
->plt
.refcount
> 0)
1831 h
->plt
.refcount
-= 1;
1835 case R_PARISC_PLABEL14R
:
1836 case R_PARISC_PLABEL21L
:
1837 case R_PARISC_PLABEL32
:
1838 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1839 if (r_symndx
>= symtab_hdr
->sh_info
)
1841 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1842 if (h
->plt
.refcount
> 0)
1843 h
->plt
.refcount
-= 1;
1845 else if (local_plt_refcounts
!= NULL
)
1847 if (local_plt_refcounts
[r_symndx
] > 0)
1848 local_plt_refcounts
[r_symndx
] -= 1;
1860 /* Our own version of hide_symbol, so that we can keep plt entries for
1864 elf32_hppa_hide_symbol (info
, h
)
1865 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1866 struct elf_link_hash_entry
*h
;
1869 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
)
1871 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1872 h
->plt
.offset
= (bfd_vma
) -1;
1877 /* Adjust a symbol defined by a dynamic object and referenced by a
1878 regular object. The current definition is in some section of the
1879 dynamic object, but we're not including those sections. We have to
1880 change the definition to something the rest of the link can
1884 elf32_hppa_adjust_dynamic_symbol (info
, h
)
1885 struct bfd_link_info
*info
;
1886 struct elf_link_hash_entry
*h
;
1889 struct elf32_hppa_link_hash_table
*hplink
;
1892 hplink
= hppa_link_hash_table (info
);
1893 dynobj
= hplink
->root
.dynobj
;
1895 /* If this is a function, put it in the procedure linkage table. We
1896 will fill in the contents of the procedure linkage table later,
1897 when we know the address of the .got section. */
1898 if (h
->type
== STT_FUNC
1899 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1901 if (h
->plt
.refcount
<= 0
1902 || ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
1903 && h
->root
.type
!= bfd_link_hash_defweak
1904 && ! ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
1905 && (!info
->shared
|| info
->symbolic
)))
1907 /* The .plt entry is not needed when:
1908 a) Garbage collection has removed all references to the
1910 b) We know for certain the symbol is defined in this
1911 object, and it's not a weak definition, nor is the symbol
1912 used by a plabel relocation. Either this object is the
1913 application or we are doing a shared symbolic link. */
1915 /* As a special sop to the hppa ABI, we keep a .plt entry
1916 for functions in sections containing PIC code. */
1918 && h
->plt
.refcount
> 0
1919 && (h
->root
.type
== bfd_link_hash_defined
1920 || h
->root
.type
== bfd_link_hash_defweak
)
1921 && (h
->root
.u
.def
.section
->flags
& SEC_HAS_GOT_REF
) != 0)
1923 ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
= 1;
1927 h
->plt
.offset
= (bfd_vma
) -1;
1928 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1933 /* Make an entry in the .plt section. */
1935 h
->plt
.offset
= s
->_raw_size
;
1936 if (PLABEL_PLT_ENTRY_SIZE
!= PLT_ENTRY_SIZE
1937 && ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
1938 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1940 /* Add some extra space for the dynamic linker to use. */
1941 s
->_raw_size
+= PLABEL_PLT_ENTRY_SIZE
;
1944 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1946 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
)
1948 /* Make sure this symbol is output as a dynamic symbol. */
1949 if (h
->dynindx
== -1
1950 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1952 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1956 /* We also need to make an entry in the .rela.plt section. */
1957 s
= hplink
->srelplt
;
1958 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
1960 hplink
->need_plt_stub
= 1;
1965 /* If this is a weak symbol, and there is a real definition, the
1966 processor independent code will have arranged for us to see the
1967 real definition first, and we can just use the same value. */
1968 if (h
->weakdef
!= NULL
)
1970 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
1971 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
1972 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1973 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1977 /* This is a reference to a symbol defined by a dynamic object which
1978 is not a function. */
1980 /* If we are creating a shared library, we must presume that the
1981 only references to the symbol are via the global offset table.
1982 For such cases we need not do anything here; the relocations will
1983 be handled correctly by relocate_section. */
1987 /* If there are no references to this symbol that do not use the
1988 GOT, we don't need to generate a copy reloc. */
1989 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
1992 /* We must allocate the symbol in our .dynbss section, which will
1993 become part of the .bss section of the executable. There will be
1994 an entry for this symbol in the .dynsym section. The dynamic
1995 object will contain position independent code, so all references
1996 from the dynamic object to this symbol will go through the global
1997 offset table. The dynamic linker will use the .dynsym entry to
1998 determine the address it must put in the global offset table, so
1999 both the dynamic object and the regular object will refer to the
2000 same memory location for the variable. */
2002 s
= hplink
->sdynbss
;
2004 /* We must generate a COPY reloc to tell the dynamic linker to
2005 copy the initial value out of the dynamic object and into the
2006 runtime process image. We need to remember the offset into the
2007 .rela.bss section we are going to use. */
2008 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2012 srel
= hplink
->srelbss
;
2013 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
2014 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
2018 /* We need to figure out the alignment required for this symbol. I
2019 have no idea how other ELF linkers handle this. */
2020 unsigned int power_of_two
;
2022 power_of_two
= bfd_log2 (h
->size
);
2023 if (power_of_two
> 3)
2026 /* Apply the required alignment. */
2027 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
2028 (bfd_size_type
) (1 << power_of_two
));
2029 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
2031 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
2035 /* Define the symbol as being at this point in the section. */
2036 h
->root
.u
.def
.section
= s
;
2037 h
->root
.u
.def
.value
= s
->_raw_size
;
2039 /* Increment the section size to make room for the symbol. */
2040 s
->_raw_size
+= h
->size
;
2046 /* Called via elf_link_hash_traverse to create .plt entries for an
2047 application that uses statically linked PIC functions. Similar to
2048 the first part of elf32_hppa_adjust_dynamic_symbol. */
2051 hppa_handle_PIC_calls (h
, inf
)
2052 struct elf_link_hash_entry
*h
;
2055 struct bfd_link_info
*info
;
2057 struct elf32_hppa_link_hash_table
*hplink
;
2060 if (! (h
->plt
.refcount
> 0
2061 && (h
->root
.type
== bfd_link_hash_defined
2062 || h
->root
.type
== bfd_link_hash_defweak
)
2063 && (h
->root
.u
.def
.section
->flags
& SEC_HAS_GOT_REF
) != 0))
2065 h
->plt
.offset
= (bfd_vma
) -1;
2066 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2070 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2071 ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
= 1;
2073 info
= (struct bfd_link_info
*) inf
;
2074 hplink
= hppa_link_hash_table (info
);
2075 dynobj
= hplink
->root
.dynobj
;
2077 /* Make an entry in the .plt section. */
2079 h
->plt
.offset
= s
->_raw_size
;
2080 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2086 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
2087 || RELATIVE_DYNAMIC_RELOCS)
2088 /* This function is called via elf_link_hash_traverse to discard space
2089 we allocated for relocs that it turned out we didn't need. */
2092 hppa_discard_copies (h
, inf
)
2093 struct elf_link_hash_entry
*h
;
2096 struct elf32_hppa_dyn_reloc_entry
*s
;
2097 struct elf32_hppa_link_hash_entry
*eh
;
2098 struct bfd_link_info
*info
;
2100 eh
= (struct elf32_hppa_link_hash_entry
*) h
;
2101 info
= (struct bfd_link_info
*) inf
;
2103 #if ! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT
2104 /* Handle the stub reloc case. If we have a plt entry for the
2105 function, we won't be needing long branch stubs. s->count will
2106 only be zero for stub relocs, which provides a handy way of
2107 flagging these relocs, and means we need do nothing special for
2108 the forced local and symbolic link case. */
2109 if (eh
->stub_reloc_sec
!= NULL
2110 && eh
->elf
.plt
.offset
!= (bfd_vma
) -1)
2112 for (s
= eh
->reloc_entries
; s
!= NULL
; s
= s
->next
)
2114 s
->section
->_raw_size
-= sizeof (Elf32_External_Rela
);
2118 #if RELATIVE_DYNAMIC_RELOCS
2119 /* If a symbol has been forced local or we have found a regular
2120 definition for the symbolic link case, then we won't be needing
2122 if (eh
->elf
.dynindx
== -1
2123 || ((eh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
2124 && !is_absolute_reloc (r_type
)
2127 for (s
= eh
->reloc_entries
; s
!= NULL
; s
= s
->next
)
2128 s
->section
->_raw_size
-= s
->count
* sizeof (Elf32_External_Rela
);
2137 /* This function is called via elf_link_hash_traverse to force
2138 millicode symbols local so they do not end up as globals in the
2139 dynamic symbol table. We ought to be able to do this in
2140 adjust_dynamic_symbol, but our adjust_dynamic_symbol is not called
2141 for all dynamic symbols. Arguably, this is a bug in
2142 elf_adjust_dynamic_symbol. */
2145 clobber_millicode_symbols (h
, info
)
2146 struct elf_link_hash_entry
*h
;
2147 struct bfd_link_info
*info
;
2149 /* Note! We only want to remove these from the dynamic symbol
2150 table. Therefore we do not set ELF_LINK_FORCED_LOCAL. */
2151 if (h
->type
== STT_PARISC_MILLI
)
2152 elf32_hppa_hide_symbol(info
, h
);
2157 /* Set the sizes of the dynamic sections. */
2160 elf32_hppa_size_dynamic_sections (output_bfd
, info
)
2162 struct bfd_link_info
*info
;
2164 struct elf32_hppa_link_hash_table
*hplink
;
2170 hplink
= hppa_link_hash_table (info
);
2171 dynobj
= hplink
->root
.dynobj
;
2172 BFD_ASSERT (dynobj
!= NULL
);
2174 if (hplink
->root
.dynamic_sections_created
)
2176 const char *funcname
;
2179 /* Set the contents of the .interp section to the interpreter. */
2182 s
= bfd_get_section_by_name (dynobj
, ".interp");
2183 BFD_ASSERT (s
!= NULL
);
2184 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2185 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2188 /* Force millicode symbols local. */
2189 elf_link_hash_traverse (&hplink
->root
,
2190 clobber_millicode_symbols
,
2193 /* DT_INIT and DT_FINI need a .plt entry. Make sure they have
2195 funcname
= info
->init_function
;
2198 if (funcname
!= NULL
)
2200 struct elf_link_hash_entry
*h
;
2202 h
= elf_link_hash_lookup (&hplink
->root
,
2204 false, false, false);
2206 && (h
->elf_link_hash_flags
& (ELF_LINK_HASH_REF_REGULAR
2207 | ELF_LINK_HASH_DEF_REGULAR
)))
2209 if (h
->plt
.refcount
<= 0)
2211 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2213 /* Make an entry in the .plt section. We know
2214 the function doesn't have a plabel by the
2217 h
->plt
.offset
= s
->_raw_size
;
2218 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2220 /* Make sure this symbol is output as a dynamic
2222 if (h
->dynindx
== -1)
2224 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
2228 /* Make an entry for the reloc too. */
2229 s
= hplink
->srelplt
;
2230 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
2233 ((struct elf32_hppa_link_hash_entry
*) h
)->plt_abs
= 1;
2236 if (funcname
== info
->fini_function
)
2238 funcname
= info
->fini_function
;
2241 /* Set up .plt offsets for local plabels. */
2242 for (i
= info
->input_bfds
; i
; i
= i
->link_next
)
2244 bfd_signed_vma
*local_plt
;
2245 bfd_signed_vma
*end_local_plt
;
2246 bfd_size_type locsymcount
;
2247 Elf_Internal_Shdr
*symtab_hdr
;
2249 local_plt
= elf_local_got_refcounts (i
);
2253 symtab_hdr
= &elf_tdata (i
)->symtab_hdr
;
2254 locsymcount
= symtab_hdr
->sh_info
;
2255 local_plt
+= locsymcount
;
2256 end_local_plt
= local_plt
+ locsymcount
;
2258 for (; local_plt
< end_local_plt
; ++local_plt
)
2263 *local_plt
= s
->_raw_size
;
2264 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2266 hplink
->srelplt
->_raw_size
+= sizeof (Elf32_External_Rela
);
2269 *local_plt
= (bfd_vma
) -1;
2275 /* Run through the function symbols, looking for any that are
2276 PIC, and allocate space for the necessary .plt entries so
2277 that %r19 will be set up. */
2279 elf_link_hash_traverse (&hplink
->root
,
2280 hppa_handle_PIC_calls
,
2283 /* We may have created entries in the .rela.got section.
2284 However, if we are not creating the dynamic sections, we will
2285 not actually use these entries. Reset the size of .rela.got,
2286 which will cause it to get stripped from the output file
2288 hplink
->srelgot
->_raw_size
= 0;
2291 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
2292 || RELATIVE_DYNAMIC_RELOCS)
2293 /* If this is a -Bsymbolic shared link, then we need to discard all
2294 relocs against symbols defined in a regular object. We also need
2295 to lose relocs we've allocated for long branch stubs if we know
2296 we won't be generating a stub. */
2298 elf_link_hash_traverse (&hplink
->root
,
2299 hppa_discard_copies
,
2303 /* The check_relocs and adjust_dynamic_symbol entry points have
2304 determined the sizes of the various dynamic sections. Allocate
2308 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2312 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2315 /* It's OK to base decisions on the section name, because none
2316 of the dynobj section names depend upon the input files. */
2317 name
= bfd_get_section_name (dynobj
, s
);
2319 if (strncmp (name
, ".rela", 5) == 0)
2321 if (s
->_raw_size
!= 0)
2324 const char *outname
;
2326 /* Remember whether there are any reloc sections other
2328 if (strcmp (name
+5, ".plt") != 0)
2331 /* If this relocation section applies to a read only
2332 section, then we probably need a DT_TEXTREL entry. */
2333 outname
= bfd_get_section_name (output_bfd
,
2335 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
2337 && (target
->flags
& SEC_READONLY
) != 0
2338 && (target
->flags
& SEC_ALLOC
) != 0)
2341 /* We use the reloc_count field as a counter if we need
2342 to copy relocs into the output file. */
2346 else if (strcmp (name
, ".plt") == 0)
2348 if (hplink
->need_plt_stub
)
2350 /* Make space for the plt stub at the end of the .plt
2351 section. We want this stub right at the end, up
2352 against the .got section. */
2353 int gotalign
= bfd_section_alignment (dynobj
, hplink
->sgot
);
2354 int pltalign
= bfd_section_alignment (dynobj
, s
);
2357 if (gotalign
> pltalign
)
2358 bfd_set_section_alignment (dynobj
, s
, gotalign
);
2359 mask
= ((bfd_size_type
) 1 << gotalign
) - 1;
2360 s
->_raw_size
= (s
->_raw_size
+ sizeof (plt_stub
) + mask
) & ~mask
;
2363 else if (strcmp (name
, ".got") == 0)
2367 /* It's not one of our sections, so don't allocate space. */
2371 if (s
->_raw_size
== 0)
2373 /* If we don't need this section, strip it from the
2374 output file. This is mostly to handle .rela.bss and
2375 .rela.plt. We must create both sections in
2376 create_dynamic_sections, because they must be created
2377 before the linker maps input sections to output
2378 sections. The linker does that before
2379 adjust_dynamic_symbol is called, and it is that
2380 function which decides whether anything needs to go
2381 into these sections. */
2382 _bfd_strip_section_from_output (info
, s
);
2386 /* Allocate memory for the section contents. Zero it, because
2387 we may not fill in all the reloc sections. */
2388 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
2389 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
2393 if (hplink
->root
.dynamic_sections_created
)
2395 /* Like IA-64 and HPPA64, always create a DT_PLTGOT. It
2396 actually has nothing to do with the PLT, it is how we
2397 communicate the LTP value of a load module to the dynamic
2399 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
2402 /* Add some entries to the .dynamic section. We fill in the
2403 values later, in elf32_hppa_finish_dynamic_sections, but we
2404 must add the entries now so that we get the correct size for
2405 the .dynamic section. The DT_DEBUG entry is filled in by the
2406 dynamic linker and used by the debugger. */
2409 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
2413 if (hplink
->srelplt
->_raw_size
!= 0)
2415 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
2416 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
2417 || ! bfd_elf32_add_dynamic_entry (info
, DT_JMPREL
, 0))
2423 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELA
, 0)
2424 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELASZ
, 0)
2425 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELAENT
,
2426 sizeof (Elf32_External_Rela
)))
2432 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
2434 info
->flags
|= DF_TEXTREL
;
2442 /* External entry points for sizing and building linker stubs. */
2444 /* Determine and set the size of the stub section for a final link.
2446 The basic idea here is to examine all the relocations looking for
2447 PC-relative calls to a target that is unreachable with a "bl"
2451 elf32_hppa_size_stubs (output_bfd
, stub_bfd
, info
, multi_subspace
, group_size
,
2452 add_stub_section
, layout_sections_again
)
2455 struct bfd_link_info
*info
;
2456 boolean multi_subspace
;
2457 bfd_signed_vma group_size
;
2458 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
2459 void (*layout_sections_again
) PARAMS ((void));
2463 asection
**input_list
, **list
;
2464 Elf_Internal_Sym
*local_syms
, **all_local_syms
;
2465 unsigned int bfd_indx
, bfd_count
;
2466 int top_id
, top_index
;
2467 struct elf32_hppa_link_hash_table
*hplink
;
2468 bfd_size_type stub_group_size
;
2469 boolean stubs_always_before_branch
;
2470 boolean stub_changed
= 0;
2473 hplink
= hppa_link_hash_table (info
);
2475 /* Stash our params away. */
2476 hplink
->stub_bfd
= stub_bfd
;
2477 hplink
->multi_subspace
= multi_subspace
;
2478 hplink
->add_stub_section
= add_stub_section
;
2479 hplink
->layout_sections_again
= layout_sections_again
;
2480 stubs_always_before_branch
= group_size
< 0;
2482 stub_group_size
= -group_size
;
2484 stub_group_size
= group_size
;
2485 if (stub_group_size
== 1)
2487 /* Default values. */
2488 stub_group_size
= 8000000;
2489 if (hplink
->has_17bit_branch
|| hplink
->multi_subspace
)
2490 stub_group_size
= 250000;
2491 if (hplink
->has_12bit_branch
)
2492 stub_group_size
= 7812;
2495 /* Count the number of input BFDs and find the top input section id. */
2496 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
2498 input_bfd
= input_bfd
->link_next
)
2501 for (section
= input_bfd
->sections
;
2503 section
= section
->next
)
2505 if (top_id
< section
->id
)
2506 top_id
= section
->id
;
2511 = (struct map_stub
*) bfd_zmalloc (sizeof (struct map_stub
) * (top_id
+ 1));
2512 if (hplink
->stub_group
== NULL
)
2515 /* Make a list of input sections for each output section included in
2518 We can't use output_bfd->section_count here to find the top output
2519 section index as some sections may have been removed, and
2520 _bfd_strip_section_from_output doesn't renumber the indices. */
2521 for (section
= output_bfd
->sections
, top_index
= 0;
2523 section
= section
->next
)
2525 if (top_index
< section
->index
)
2526 top_index
= section
->index
;
2530 = (asection
**) bfd_malloc (sizeof (asection
*) * (top_index
+ 1));
2531 if (input_list
== NULL
)
2534 /* For sections we aren't interested in, mark their entries with a
2535 value we can check later. */
2536 list
= input_list
+ top_index
;
2538 *list
= bfd_abs_section_ptr
;
2539 while (list
-- != input_list
);
2541 for (section
= output_bfd
->sections
;
2543 section
= section
->next
)
2545 if ((section
->flags
& SEC_CODE
) != 0)
2546 input_list
[section
->index
] = NULL
;
2549 /* Now actually build the lists. */
2550 for (input_bfd
= info
->input_bfds
;
2552 input_bfd
= input_bfd
->link_next
)
2554 for (section
= input_bfd
->sections
;
2556 section
= section
->next
)
2558 if (section
->output_section
!= NULL
2559 && section
->output_section
->owner
== output_bfd
2560 && section
->output_section
->index
<= top_index
)
2562 list
= input_list
+ section
->output_section
->index
;
2563 if (*list
!= bfd_abs_section_ptr
)
2565 /* Steal the link_sec pointer for our list. */
2566 #define PREV_SEC(sec) (hplink->stub_group[(sec)->id].link_sec)
2567 /* This happens to make the list in reverse order,
2568 which is what we want. */
2569 PREV_SEC (section
) = *list
;
2576 /* See whether we can group stub sections together. Grouping stub
2577 sections may result in fewer stubs. More importantly, we need to
2578 put all .init* and .fini* stubs at the beginning of the .init or
2579 .fini output sections respectively, because glibc splits the
2580 _init and _fini functions into multiple parts. Putting a stub in
2581 the middle of a function is not a good idea. */
2582 list
= input_list
+ top_index
;
2585 asection
*tail
= *list
;
2586 if (tail
== bfd_abs_section_ptr
)
2588 while (tail
!= NULL
)
2592 bfd_size_type total
;
2595 if (tail
->_cooked_size
)
2596 total
= tail
->_cooked_size
;
2598 total
= tail
->_raw_size
;
2599 while ((prev
= PREV_SEC (curr
)) != NULL
2600 && ((total
+= curr
->output_offset
- prev
->output_offset
)
2604 /* OK, the size from the start of CURR to the end is less
2605 than 250000 bytes and thus can be handled by one stub
2606 section. (or the tail section is itself larger than
2607 250000 bytes, in which case we may be toast.)
2608 We should really be keeping track of the total size of
2609 stubs added here, as stubs contribute to the final output
2610 section size. That's a little tricky, and this way will
2611 only break if stubs added total more than 12144 bytes, or
2612 1518 long branch stubs. It seems unlikely for more than
2613 1518 different functions to be called, especially from
2614 code only 250000 bytes long. */
2617 prev
= PREV_SEC (tail
);
2618 /* Set up this stub group. */
2619 hplink
->stub_group
[tail
->id
].link_sec
= curr
;
2621 while (tail
!= curr
&& (tail
= prev
) != NULL
);
2623 /* But wait, there's more! Input sections up to 250000
2624 bytes before the stub section can be handled by it too. */
2625 if (!stubs_always_before_branch
)
2629 && ((total
+= tail
->output_offset
- prev
->output_offset
)
2633 prev
= PREV_SEC (tail
);
2634 hplink
->stub_group
[tail
->id
].link_sec
= curr
;
2640 while (list
-- != input_list
);
2644 /* We want to read in symbol extension records only once. To do this
2645 we need to read in the local symbols in parallel and save them for
2646 later use; so hold pointers to the local symbols in an array. */
2648 = (Elf_Internal_Sym
**) bfd_zmalloc (sizeof (Elf_Internal_Sym
*)
2650 if (all_local_syms
== NULL
)
2653 /* Walk over all the input BFDs, swapping in local symbols.
2654 If we are creating a shared library, create hash entries for the
2656 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
2658 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
2660 Elf_Internal_Shdr
*symtab_hdr
;
2661 Elf_Internal_Sym
*isym
;
2662 Elf32_External_Sym
*ext_syms
, *esym
, *end_sy
;
2664 /* We'll need the symbol table in a second. */
2665 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2666 if (symtab_hdr
->sh_info
== 0)
2669 /* We need an array of the local symbols attached to the input bfd.
2670 Unfortunately, we're going to have to read & swap them in. */
2671 local_syms
= (Elf_Internal_Sym
*)
2672 bfd_malloc (symtab_hdr
->sh_info
* sizeof (Elf_Internal_Sym
));
2673 if (local_syms
== NULL
)
2675 goto error_ret_free_local
;
2677 all_local_syms
[bfd_indx
] = local_syms
;
2678 ext_syms
= (Elf32_External_Sym
*)
2679 bfd_malloc (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
));
2680 if (ext_syms
== NULL
)
2682 goto error_ret_free_local
;
2685 if (bfd_seek (input_bfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
2686 || (bfd_read (ext_syms
, 1,
2687 (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
)),
2689 != (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
))))
2692 goto error_ret_free_local
;
2695 /* Swap the local symbols in. */
2698 for (end_sy
= esym
+ symtab_hdr
->sh_info
; esym
< end_sy
; esym
++, isym
++)
2699 bfd_elf32_swap_symbol_in (input_bfd
, esym
, isym
);
2701 /* Now we can free the external symbols. */
2704 #if ! LONG_BRANCH_PIC_IN_SHLIB
2705 /* If this is a shared link, find all the stub reloc sections. */
2707 for (section
= input_bfd
->sections
;
2709 section
= section
->next
)
2712 asection
*reloc_sec
;
2714 name
= bfd_malloc (strlen (section
->name
)
2715 + sizeof STUB_SUFFIX
2719 sprintf (name
, ".rela%s%s", section
->name
, STUB_SUFFIX
);
2720 reloc_sec
= bfd_get_section_by_name (hplink
->root
.dynobj
, name
);
2721 hplink
->stub_group
[section
->id
].reloc_sec
= reloc_sec
;
2726 if (info
->shared
&& hplink
->multi_subspace
)
2728 struct elf_link_hash_entry
**sym_hashes
;
2729 struct elf_link_hash_entry
**end_hashes
;
2730 unsigned int symcount
;
2732 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
2733 - symtab_hdr
->sh_info
);
2734 sym_hashes
= elf_sym_hashes (input_bfd
);
2735 end_hashes
= sym_hashes
+ symcount
;
2737 /* Look through the global syms for functions; We need to
2738 build export stubs for all globally visible functions. */
2739 for (; sym_hashes
< end_hashes
; sym_hashes
++)
2741 struct elf32_hppa_link_hash_entry
*hash
;
2743 hash
= (struct elf32_hppa_link_hash_entry
*) *sym_hashes
;
2745 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
2746 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
2747 hash
= ((struct elf32_hppa_link_hash_entry
*)
2748 hash
->elf
.root
.u
.i
.link
);
2750 /* At this point in the link, undefined syms have been
2751 resolved, so we need to check that the symbol was
2752 defined in this BFD. */
2753 if ((hash
->elf
.root
.type
== bfd_link_hash_defined
2754 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
2755 && hash
->elf
.type
== STT_FUNC
2756 && hash
->elf
.root
.u
.def
.section
->output_section
!= NULL
2757 && (hash
->elf
.root
.u
.def
.section
->output_section
->owner
2759 && hash
->elf
.root
.u
.def
.section
->owner
== input_bfd
2760 && (hash
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
2761 && !(hash
->elf
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
2762 && ELF_ST_VISIBILITY (hash
->elf
.other
) == STV_DEFAULT
)
2765 const char *stub_name
;
2766 struct elf32_hppa_stub_hash_entry
*stub_entry
;
2768 sec
= hash
->elf
.root
.u
.def
.section
;
2769 stub_name
= hash
->elf
.root
.root
.string
;
2770 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
,
2773 if (stub_entry
== NULL
)
2775 stub_entry
= hppa_add_stub (stub_name
, sec
, hplink
);
2777 goto error_ret_free_local
;
2779 stub_entry
->target_value
= hash
->elf
.root
.u
.def
.value
;
2780 stub_entry
->target_section
= hash
->elf
.root
.u
.def
.section
;
2781 stub_entry
->stub_type
= hppa_stub_export
;
2782 stub_entry
->h
= hash
;
2787 (*_bfd_error_handler
) (_("%s: duplicate export stub %s"),
2788 bfd_get_filename (input_bfd
),
2800 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
2802 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
2804 Elf_Internal_Shdr
*symtab_hdr
;
2806 /* We'll need the symbol table in a second. */
2807 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2808 if (symtab_hdr
->sh_info
== 0)
2811 local_syms
= all_local_syms
[bfd_indx
];
2813 /* Walk over each section attached to the input bfd. */
2814 for (section
= input_bfd
->sections
;
2816 section
= section
->next
)
2818 Elf_Internal_Shdr
*input_rel_hdr
;
2819 Elf32_External_Rela
*external_relocs
, *erelaend
, *erela
;
2820 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
2822 /* If there aren't any relocs, then there's nothing more
2824 if ((section
->flags
& SEC_RELOC
) == 0
2825 || section
->reloc_count
== 0)
2828 /* If this section is a link-once section that will be
2829 discarded, then don't create any stubs. */
2830 if (section
->output_section
== NULL
2831 || section
->output_section
->owner
!= output_bfd
)
2834 /* Allocate space for the external relocations. */
2836 = ((Elf32_External_Rela
*)
2837 bfd_malloc (section
->reloc_count
2838 * sizeof (Elf32_External_Rela
)));
2839 if (external_relocs
== NULL
)
2841 goto error_ret_free_local
;
2844 /* Likewise for the internal relocations. */
2845 internal_relocs
= ((Elf_Internal_Rela
*)
2846 bfd_malloc (section
->reloc_count
2847 * sizeof (Elf_Internal_Rela
)));
2848 if (internal_relocs
== NULL
)
2850 free (external_relocs
);
2851 goto error_ret_free_local
;
2854 /* Read in the external relocs. */
2855 input_rel_hdr
= &elf_section_data (section
)->rel_hdr
;
2856 if (bfd_seek (input_bfd
, input_rel_hdr
->sh_offset
, SEEK_SET
) != 0
2857 || bfd_read (external_relocs
, 1,
2858 input_rel_hdr
->sh_size
,
2859 input_bfd
) != input_rel_hdr
->sh_size
)
2861 free (external_relocs
);
2862 error_ret_free_internal
:
2863 free (internal_relocs
);
2864 goto error_ret_free_local
;
2867 /* Swap in the relocs. */
2868 erela
= external_relocs
;
2869 erelaend
= erela
+ section
->reloc_count
;
2870 irela
= internal_relocs
;
2871 for (; erela
< erelaend
; erela
++, irela
++)
2872 bfd_elf32_swap_reloca_in (input_bfd
, erela
, irela
);
2874 /* We're done with the external relocs, free them. */
2875 free (external_relocs
);
2877 /* Now examine each relocation. */
2878 irela
= internal_relocs
;
2879 irelaend
= irela
+ section
->reloc_count
;
2880 for (; irela
< irelaend
; irela
++)
2882 unsigned int r_type
, r_indx
;
2883 enum elf32_hppa_stub_type stub_type
;
2884 struct elf32_hppa_stub_hash_entry
*stub_entry
;
2887 bfd_vma destination
;
2888 struct elf32_hppa_link_hash_entry
*hash
;
2890 const asection
*id_sec
;
2892 r_type
= ELF32_R_TYPE (irela
->r_info
);
2893 r_indx
= ELF32_R_SYM (irela
->r_info
);
2895 if (r_type
>= (unsigned int) R_PARISC_UNIMPLEMENTED
)
2897 bfd_set_error (bfd_error_bad_value
);
2898 goto error_ret_free_internal
;
2901 /* Only look for stubs on call instructions. */
2902 if (r_type
!= (unsigned int) R_PARISC_PCREL12F
2903 && r_type
!= (unsigned int) R_PARISC_PCREL17F
2904 && r_type
!= (unsigned int) R_PARISC_PCREL22F
)
2907 /* Now determine the call target, its name, value,
2913 if (r_indx
< symtab_hdr
->sh_info
)
2915 /* It's a local symbol. */
2916 Elf_Internal_Sym
*sym
;
2917 Elf_Internal_Shdr
*hdr
;
2919 sym
= local_syms
+ r_indx
;
2920 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
2921 sym_sec
= hdr
->bfd_section
;
2922 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
2923 sym_value
= sym
->st_value
;
2924 destination
= (sym_value
+ irela
->r_addend
2925 + sym_sec
->output_offset
2926 + sym_sec
->output_section
->vma
);
2930 /* It's an external symbol. */
2933 e_indx
= r_indx
- symtab_hdr
->sh_info
;
2934 hash
= ((struct elf32_hppa_link_hash_entry
*)
2935 elf_sym_hashes (input_bfd
)[e_indx
]);
2937 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
2938 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
2939 hash
= ((struct elf32_hppa_link_hash_entry
*)
2940 hash
->elf
.root
.u
.i
.link
);
2942 if (hash
->elf
.root
.type
== bfd_link_hash_defined
2943 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
2945 sym_sec
= hash
->elf
.root
.u
.def
.section
;
2946 sym_value
= hash
->elf
.root
.u
.def
.value
;
2947 if (sym_sec
->output_section
!= NULL
)
2948 destination
= (sym_value
+ irela
->r_addend
2949 + sym_sec
->output_offset
2950 + sym_sec
->output_section
->vma
);
2952 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
)
2957 else if (hash
->elf
.root
.type
== bfd_link_hash_undefined
)
2960 && !info
->no_undefined
2961 && (ELF_ST_VISIBILITY (hash
->elf
.other
)
2967 bfd_set_error (bfd_error_bad_value
);
2968 goto error_ret_free_internal
;
2972 /* Determine what (if any) linker stub is needed. */
2973 stub_type
= hppa_type_of_stub (section
, irela
, hash
,
2975 if (stub_type
== hppa_stub_none
)
2978 /* Support for grouping stub sections. */
2979 id_sec
= hplink
->stub_group
[section
->id
].link_sec
;
2981 /* Get the name of this stub. */
2982 stub_name
= hppa_stub_name (id_sec
, sym_sec
, hash
, irela
);
2984 goto error_ret_free_internal
;
2986 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
,
2989 if (stub_entry
!= NULL
)
2991 /* The proper stub has already been created. */
2996 stub_entry
= hppa_add_stub (stub_name
, section
, hplink
);
2997 if (stub_entry
== NULL
)
3000 goto error_ret_free_local
;
3003 stub_entry
->target_value
= sym_value
;
3004 stub_entry
->target_section
= sym_sec
;
3005 stub_entry
->stub_type
= stub_type
;
3008 if (stub_type
== hppa_stub_import
)
3009 stub_entry
->stub_type
= hppa_stub_import_shared
;
3010 else if (stub_type
== hppa_stub_long_branch
3011 && (LONG_BRANCH_PIC_IN_SHLIB
|| hash
== NULL
))
3012 stub_entry
->stub_type
= hppa_stub_long_branch_shared
;
3014 stub_entry
->h
= hash
;
3018 /* We're done with the internal relocs, free them. */
3019 free (internal_relocs
);
3026 /* OK, we've added some stubs. Find out the new size of the
3028 for (stub_sec
= hplink
->stub_bfd
->sections
;
3030 stub_sec
= stub_sec
->next
)
3032 stub_sec
->_raw_size
= 0;
3033 stub_sec
->_cooked_size
= 0;
3035 #if ! LONG_BRANCH_PIC_IN_SHLIB
3039 for (i
= top_id
; i
>= 0; --i
)
3041 /* This will probably hit the same section many times.. */
3042 stub_sec
= hplink
->stub_group
[i
].reloc_sec
;
3043 if (stub_sec
!= NULL
)
3045 stub_sec
->_raw_size
= 0;
3046 stub_sec
->_cooked_size
= 0;
3052 bfd_hash_traverse (&hplink
->stub_hash_table
,
3056 /* Ask the linker to do its stuff. */
3057 (*hplink
->layout_sections_again
) ();
3063 error_ret_free_local
:
3064 while (bfd_count
-- > 0)
3065 if (all_local_syms
[bfd_count
])
3066 free (all_local_syms
[bfd_count
]);
3067 free (all_local_syms
);
3073 /* For a final link, this function is called after we have sized the
3074 stubs to provide a value for __gp. */
3077 elf32_hppa_set_gp (abfd
, info
)
3079 struct bfd_link_info
*info
;
3081 struct elf32_hppa_link_hash_table
*hplink
;
3082 struct elf_link_hash_entry
*h
;
3086 hplink
= hppa_link_hash_table (info
);
3087 h
= elf_link_hash_lookup (&hplink
->root
, "$global$",
3088 false, false, false);
3090 if (h
!= NULL
&& h
->root
.type
== bfd_link_hash_defined
)
3092 gp_val
= h
->root
.u
.def
.value
;
3093 sec
= h
->root
.u
.def
.section
;
3097 /* Choose to point our LTP at, in this order, one of .plt, .got,
3098 or .data, if these sections exist. In the case of choosing
3099 .plt try to make the LTP ideal for addressing anywhere in the
3100 .plt or .got with a 14 bit signed offset. Typically, the end
3101 of the .plt is the start of the .got, so choose .plt + 0x2000
3102 if either the .plt or .got is larger than 0x2000. If both
3103 the .plt and .got are smaller than 0x2000, choose the end of
3104 the .plt section. */
3109 gp_val
= sec
->_raw_size
;
3111 || (hplink
->sgot
&& hplink
->sgot
->_raw_size
> 0x2000))
3122 /* We know we don't have a .plt. If .got is large,
3124 if (sec
->_raw_size
> 0x2000)
3129 /* No .plt or .got. Who cares what the LTP is? */
3130 sec
= bfd_get_section_by_name (abfd
, ".data");
3136 gp_val
+= sec
->output_section
->vma
+ sec
->output_offset
;
3138 elf_gp (abfd
) = gp_val
;
3143 /* Build all the stubs associated with the current output file. The
3144 stubs are kept in a hash table attached to the main linker hash
3145 table. We also set up the .plt entries for statically linked PIC
3146 functions here. This function is called via hppaelf_finish in the
3150 elf32_hppa_build_stubs (info
)
3151 struct bfd_link_info
*info
;
3154 struct bfd_hash_table
*table
;
3155 struct elf32_hppa_link_hash_table
*hplink
;
3157 hplink
= hppa_link_hash_table (info
);
3159 for (stub_sec
= hplink
->stub_bfd
->sections
;
3161 stub_sec
= stub_sec
->next
)
3165 /* Allocate memory to hold the linker stubs. */
3166 size
= stub_sec
->_raw_size
;
3167 stub_sec
->contents
= (unsigned char *) bfd_zalloc (hplink
->stub_bfd
,
3169 if (stub_sec
->contents
== NULL
&& size
!= 0)
3171 stub_sec
->_raw_size
= 0;
3174 /* Build the stubs as directed by the stub hash table. */
3175 table
= &hplink
->stub_hash_table
;
3176 bfd_hash_traverse (table
, hppa_build_one_stub
, info
);
3182 /* Perform a relocation as part of a final link. */
3184 static bfd_reloc_status_type
3185 final_link_relocate (input_section
, contents
, rel
, value
, hplink
, sym_sec
, h
)
3186 asection
*input_section
;
3188 const Elf_Internal_Rela
*rel
;
3190 struct elf32_hppa_link_hash_table
*hplink
;
3192 struct elf32_hppa_link_hash_entry
*h
;
3195 unsigned int r_type
= ELF32_R_TYPE (rel
->r_info
);
3196 reloc_howto_type
*howto
= elf_hppa_howto_table
+ r_type
;
3197 int r_format
= howto
->bitsize
;
3198 enum hppa_reloc_field_selector_type_alt r_field
;
3199 bfd
*input_bfd
= input_section
->owner
;
3200 bfd_vma offset
= rel
->r_offset
;
3201 bfd_vma max_branch_offset
= 0;
3202 bfd_byte
*hit_data
= contents
+ offset
;
3203 bfd_signed_vma addend
= rel
->r_addend
;
3205 struct elf32_hppa_stub_hash_entry
*stub_entry
= NULL
;
3208 if (r_type
== R_PARISC_NONE
)
3209 return bfd_reloc_ok
;
3211 insn
= bfd_get_32 (input_bfd
, hit_data
);
3213 /* Find out where we are and where we're going. */
3214 location
= (offset
+
3215 input_section
->output_offset
+
3216 input_section
->output_section
->vma
);
3220 case R_PARISC_PCREL12F
:
3221 case R_PARISC_PCREL17F
:
3222 case R_PARISC_PCREL22F
:
3223 /* If this is a call to a function defined in another dynamic
3224 library, or if it is a call to a PIC function in the same
3225 object, or if this is a shared link and it is a call to a
3226 weak symbol which may or may not be in the same object, then
3227 find the import stub in the stub hash. */
3229 || sym_sec
->output_section
== NULL
3232 || (h
->elf
.root
.type
== bfd_link_hash_defweak
3233 && h
->elf
.dynindx
!= -1
3234 && h
->elf
.plt
.offset
!= (bfd_vma
) -1))))
3236 stub_entry
= hppa_get_stub_entry (input_section
, sym_sec
,
3238 if (stub_entry
!= NULL
)
3240 value
= (stub_entry
->stub_offset
3241 + stub_entry
->stub_sec
->output_offset
3242 + stub_entry
->stub_sec
->output_section
->vma
);
3245 else if (sym_sec
== NULL
&& h
!= NULL
3246 && h
->elf
.root
.type
== bfd_link_hash_undefweak
)
3248 /* It's OK if undefined weak. Make undefined weak
3249 branches go nowhere. */
3254 return bfd_reloc_notsupported
;
3258 case R_PARISC_PCREL21L
:
3259 case R_PARISC_PCREL17C
:
3260 case R_PARISC_PCREL17R
:
3261 case R_PARISC_PCREL14R
:
3262 case R_PARISC_PCREL14F
:
3263 /* Make it a pc relative offset. */
3268 case R_PARISC_DPREL21L
:
3269 case R_PARISC_DPREL14R
:
3270 case R_PARISC_DPREL14F
:
3271 /* For all the DP relative relocations, we need to examine the symbol's
3272 section. If it's a code section, then "data pointer relative" makes
3273 no sense. In that case we don't adjust the "value", and for 21 bit
3274 addil instructions, we change the source addend register from %dp to
3275 %r0. This situation commonly arises when a variable's "constness"
3276 is declared differently from the way the variable is defined. For
3277 instance: "extern int foo" with foo defined as "const int foo". */
3278 if (sym_sec
== NULL
)
3280 if ((sym_sec
->flags
& SEC_CODE
) != 0)
3282 if ((insn
& ((0x3f << 26) | (0x1f << 21)))
3283 == (((int) OP_ADDIL
<< 26) | (27 << 21)))
3285 insn
&= ~ (0x1f << 21);
3286 #if 1 /* debug them. */
3287 (*_bfd_error_handler
)
3288 (_("%s(%s+0x%lx): fixing %s"),
3289 bfd_get_filename (input_bfd
),
3290 input_section
->name
,
3291 (long) rel
->r_offset
,
3295 /* Now try to make things easy for the dynamic linker. */
3301 case R_PARISC_DLTIND21L
:
3302 case R_PARISC_DLTIND14R
:
3303 case R_PARISC_DLTIND14F
:
3304 value
-= elf_gp (input_section
->output_section
->owner
);
3313 case R_PARISC_DIR32
:
3314 case R_PARISC_DIR14F
:
3315 case R_PARISC_DIR17F
:
3316 case R_PARISC_PCREL17C
:
3317 case R_PARISC_PCREL14F
:
3318 case R_PARISC_DPREL14F
:
3319 case R_PARISC_PLABEL32
:
3320 case R_PARISC_DLTIND14F
:
3321 case R_PARISC_SEGBASE
:
3322 case R_PARISC_SEGREL32
:
3326 case R_PARISC_DIR21L
:
3327 case R_PARISC_PCREL21L
:
3328 case R_PARISC_DPREL21L
:
3329 case R_PARISC_PLABEL21L
:
3330 case R_PARISC_DLTIND21L
:
3334 case R_PARISC_DIR17R
:
3335 case R_PARISC_PCREL17R
:
3336 case R_PARISC_DIR14R
:
3337 case R_PARISC_PCREL14R
:
3338 case R_PARISC_DPREL14R
:
3339 case R_PARISC_PLABEL14R
:
3340 case R_PARISC_DLTIND14R
:
3344 case R_PARISC_PCREL12F
:
3345 case R_PARISC_PCREL17F
:
3346 case R_PARISC_PCREL22F
:
3349 if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
3351 max_branch_offset
= (1 << (17-1)) << 2;
3353 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
3355 max_branch_offset
= (1 << (12-1)) << 2;
3359 max_branch_offset
= (1 << (22-1)) << 2;
3362 /* sym_sec is NULL on undefined weak syms or when shared on
3363 undefined syms. We've already checked for a stub for the
3364 shared undefined case. */
3365 if (sym_sec
== NULL
)
3368 /* If the branch is out of reach, then redirect the
3369 call to the local stub for this function. */
3370 if (value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3372 stub_entry
= hppa_get_stub_entry (input_section
, sym_sec
,
3374 if (stub_entry
== NULL
)
3375 return bfd_reloc_notsupported
;
3377 /* Munge up the value and addend so that we call the stub
3378 rather than the procedure directly. */
3379 value
= (stub_entry
->stub_offset
3380 + stub_entry
->stub_sec
->output_offset
3381 + stub_entry
->stub_sec
->output_section
->vma
3387 /* Something we don't know how to handle. */
3389 return bfd_reloc_notsupported
;
3392 /* Make sure we can reach the stub. */
3393 if (max_branch_offset
!= 0
3394 && value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3396 (*_bfd_error_handler
)
3397 (_("%s(%s+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
3398 bfd_get_filename (input_bfd
),
3399 input_section
->name
,
3400 (long) rel
->r_offset
,
3401 stub_entry
->root
.string
);
3402 return bfd_reloc_notsupported
;
3405 val
= hppa_field_adjust (value
, addend
, r_field
);
3409 case R_PARISC_PCREL12F
:
3410 case R_PARISC_PCREL17C
:
3411 case R_PARISC_PCREL17F
:
3412 case R_PARISC_PCREL17R
:
3413 case R_PARISC_PCREL22F
:
3414 case R_PARISC_DIR17F
:
3415 case R_PARISC_DIR17R
:
3416 /* This is a branch. Divide the offset by four.
3417 Note that we need to decide whether it's a branch or
3418 otherwise by inspecting the reloc. Inspecting insn won't
3419 work as insn might be from a .word directive. */
3427 insn
= hppa_rebuild_insn (insn
, val
, r_format
);
3429 /* Update the instruction word. */
3430 bfd_put_32 (input_bfd
, (bfd_vma
) insn
, hit_data
);
3431 return bfd_reloc_ok
;
3435 /* Relocate an HPPA ELF section. */
3438 elf32_hppa_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
3439 contents
, relocs
, local_syms
, local_sections
)
3441 struct bfd_link_info
*info
;
3443 asection
*input_section
;
3445 Elf_Internal_Rela
*relocs
;
3446 Elf_Internal_Sym
*local_syms
;
3447 asection
**local_sections
;
3450 bfd_vma
*local_got_offsets
;
3451 struct elf32_hppa_link_hash_table
*hplink
;
3452 Elf_Internal_Shdr
*symtab_hdr
;
3453 Elf_Internal_Rela
*rel
;
3454 Elf_Internal_Rela
*relend
;
3457 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3459 hplink
= hppa_link_hash_table (info
);
3460 dynobj
= hplink
->root
.dynobj
;
3461 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3465 relend
= relocs
+ input_section
->reloc_count
;
3466 for (; rel
< relend
; rel
++)
3468 unsigned int r_type
;
3469 reloc_howto_type
*howto
;
3470 unsigned int r_symndx
;
3471 struct elf32_hppa_link_hash_entry
*h
;
3472 Elf_Internal_Sym
*sym
;
3475 bfd_reloc_status_type r
;
3476 const char *sym_name
;
3479 r_type
= ELF32_R_TYPE (rel
->r_info
);
3480 if (r_type
>= (unsigned int) R_PARISC_UNIMPLEMENTED
)
3482 bfd_set_error (bfd_error_bad_value
);
3485 if (r_type
== (unsigned int) R_PARISC_GNU_VTENTRY
3486 || r_type
== (unsigned int) R_PARISC_GNU_VTINHERIT
)
3489 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3491 if (info
->relocateable
)
3493 /* This is a relocateable link. We don't have to change
3494 anything, unless the reloc is against a section symbol,
3495 in which case we have to adjust according to where the
3496 section symbol winds up in the output section. */
3497 if (r_symndx
< symtab_hdr
->sh_info
)
3499 sym
= local_syms
+ r_symndx
;
3500 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
3502 sym_sec
= local_sections
[r_symndx
];
3503 rel
->r_addend
+= sym_sec
->output_offset
;
3509 /* This is a final link. */
3513 if (r_symndx
< symtab_hdr
->sh_info
)
3515 /* This is a local symbol, h defaults to NULL. */
3516 sym
= local_syms
+ r_symndx
;
3517 sym_sec
= local_sections
[r_symndx
];
3518 relocation
= ((ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
3519 ? 0 : sym
->st_value
)
3520 + sym_sec
->output_offset
3521 + sym_sec
->output_section
->vma
);
3527 /* It's a global; Find its entry in the link hash. */
3528 indx
= r_symndx
- symtab_hdr
->sh_info
;
3529 h
= ((struct elf32_hppa_link_hash_entry
*)
3530 elf_sym_hashes (input_bfd
)[indx
]);
3531 while (h
->elf
.root
.type
== bfd_link_hash_indirect
3532 || h
->elf
.root
.type
== bfd_link_hash_warning
)
3533 h
= (struct elf32_hppa_link_hash_entry
*) h
->elf
.root
.u
.i
.link
;
3536 if (h
->elf
.root
.type
== bfd_link_hash_defined
3537 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
3539 sym_sec
= h
->elf
.root
.u
.def
.section
;
3540 /* If sym_sec->output_section is NULL, then it's a
3541 symbol defined in a shared library. */
3542 if (sym_sec
->output_section
!= NULL
)
3543 relocation
= (h
->elf
.root
.u
.def
.value
3544 + sym_sec
->output_offset
3545 + sym_sec
->output_section
->vma
);
3547 else if (h
->elf
.root
.type
== bfd_link_hash_undefweak
)
3549 else if (info
->shared
&& !info
->no_undefined
3550 && ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
)
3553 if (!((*info
->callbacks
->undefined_symbol
)
3554 (info
, h
->elf
.root
.root
.string
, input_bfd
,
3555 input_section
, rel
->r_offset
, false)))
3560 if (!((*info
->callbacks
->undefined_symbol
)
3561 (info
, h
->elf
.root
.root
.string
, input_bfd
,
3562 input_section
, rel
->r_offset
, true)))
3567 /* Do any required modifications to the relocation value, and
3568 determine what types of dynamic info we need to output, if
3573 case R_PARISC_DLTIND14F
:
3574 case R_PARISC_DLTIND14R
:
3575 case R_PARISC_DLTIND21L
:
3576 /* Relocation is to the entry for this symbol in the global
3582 off
= h
->elf
.got
.offset
;
3583 BFD_ASSERT (off
!= (bfd_vma
) -1);
3585 if (! hplink
->root
.dynamic_sections_created
3587 && (info
->symbolic
|| h
->elf
.dynindx
== -1)
3588 && (h
->elf
.elf_link_hash_flags
3589 & ELF_LINK_HASH_DEF_REGULAR
) != 0))
3591 /* This is actually a static link, or it is a
3592 -Bsymbolic link and the symbol is defined
3593 locally, or the symbol was forced to be local
3594 because of a version file. We must initialize
3595 this entry in the global offset table. Since the
3596 offset must always be a multiple of 4, we use the
3597 least significant bit to record whether we have
3598 initialized it already.
3600 When doing a dynamic link, we create a .rela.got
3601 relocation entry to initialize the value. This
3602 is done in the finish_dynamic_symbol routine. */
3607 bfd_put_32 (output_bfd
, relocation
,
3608 hplink
->sgot
->contents
+ off
);
3609 h
->elf
.got
.offset
|= 1;
3617 /* Local symbol case. */
3620 BFD_ASSERT (local_got_offsets
!= NULL
3621 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
3623 off
= local_got_offsets
[r_symndx
];
3625 /* The offset must always be a multiple of 4. We use
3626 the least significant bit to record whether we have
3627 already generated the necessary reloc. */
3632 bfd_put_32 (output_bfd
, relocation
,
3633 hplink
->sgot
->contents
+ off
);
3637 /* Output a dynamic *ABS* relocation for this
3638 GOT entry. In this case it is relative to
3639 the base of the object because the symbol
3641 Elf_Internal_Rela outrel
;
3642 asection
*srelgot
= hplink
->srelgot
;
3644 outrel
.r_offset
= (off
3645 + hplink
->sgot
->output_offset
3646 + hplink
->sgot
->output_section
->vma
);
3647 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_DIR32
);
3648 outrel
.r_addend
= relocation
;
3649 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3650 ((Elf32_External_Rela
*)
3652 + srelgot
->reloc_count
));
3653 ++srelgot
->reloc_count
;
3656 local_got_offsets
[r_symndx
] |= 1;
3662 /* Add the base of the GOT to the relocation value. */
3663 relocation
+= (hplink
->sgot
->output_offset
3664 + hplink
->sgot
->output_section
->vma
);
3667 case R_PARISC_PLABEL14R
:
3668 case R_PARISC_PLABEL21L
:
3669 case R_PARISC_PLABEL32
:
3670 if (hplink
->root
.dynamic_sections_created
)
3674 /* If we have a global symbol with a PLT slot, then
3675 redirect this relocation to it. */
3678 off
= h
->elf
.plt
.offset
;
3684 indx
= r_symndx
+ symtab_hdr
->sh_info
;
3685 off
= local_got_offsets
[indx
];
3687 /* As for the local .got entry case, we use the last
3688 bit to record whether we've already initialised
3689 this local .plt entry. */
3694 bfd_put_32 (output_bfd
,
3696 hplink
->splt
->contents
+ off
);
3697 bfd_put_32 (output_bfd
,
3698 elf_gp (hplink
->splt
->output_section
->owner
),
3699 hplink
->splt
->contents
+ off
+ 4);
3703 /* Output a dynamic IPLT relocation for this
3705 Elf_Internal_Rela outrel
;
3706 asection
*srelplt
= hplink
->srelplt
;
3708 outrel
.r_offset
= (off
3709 + hplink
->splt
->output_offset
3710 + hplink
->splt
->output_section
->vma
);
3711 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_IPLT
);
3712 outrel
.r_addend
= relocation
;
3713 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3714 ((Elf32_External_Rela
*)
3716 + srelplt
->reloc_count
));
3717 ++srelplt
->reloc_count
;
3720 local_got_offsets
[indx
] |= 1;
3724 BFD_ASSERT (off
< (bfd_vma
) -2);
3726 /* PLABELs contain function pointers. Relocation is to
3727 the entry for the function in the .plt. The magic +2
3728 offset signals to $$dyncall that the function pointer
3729 is in the .plt and thus has a gp pointer too.
3730 Exception: Undefined PLABELs should have a value of
3733 || (h
->elf
.root
.type
!= bfd_link_hash_undefweak
3734 && h
->elf
.root
.type
!= bfd_link_hash_undefined
))
3737 + hplink
->splt
->output_offset
3738 + hplink
->splt
->output_section
->vma
3743 /* Fall through and possibly emit a dynamic relocation. */
3745 case R_PARISC_DIR17F
:
3746 case R_PARISC_DIR17R
:
3747 case R_PARISC_DIR14F
:
3748 case R_PARISC_DIR14R
:
3749 case R_PARISC_DIR21L
:
3750 case R_PARISC_DPREL14F
:
3751 case R_PARISC_DPREL14R
:
3752 case R_PARISC_DPREL21L
:
3753 case R_PARISC_DIR32
:
3754 /* The reloc types handled here and this conditional
3755 expression must match the code in check_relocs and
3756 hppa_discard_copies. ie. We need exactly the same
3757 condition as in check_relocs, with some extra conditions
3758 (dynindx test in this case) to cater for relocs removed
3759 by hppa_discard_copies. */
3760 if ((input_section
->flags
& SEC_ALLOC
) != 0
3762 #if RELATIVE_DYNAMIC_RELOCS
3763 && (is_absolute_reloc (r_type
)
3764 || ((!info
->symbolic
3766 && ((h
->elf
.elf_link_hash_flags
3767 & ELF_LINK_HASH_DEF_REGULAR
) == 0
3768 || h
->elf
.root
.type
== bfd_link_hash_defweak
)))
3769 && (h
== NULL
|| h
->elf
.dynindx
!= -1)))
3773 Elf_Internal_Rela outrel
;
3776 /* When generating a shared object, these relocations
3777 are copied into the output file to be resolved at run
3784 name
= (bfd_elf_string_from_elf_section
3786 elf_elfheader (input_bfd
)->e_shstrndx
,
3787 elf_section_data (input_section
)->rel_hdr
.sh_name
));
3790 sreloc
= bfd_get_section_by_name (dynobj
, name
);
3791 BFD_ASSERT (sreloc
!= NULL
);
3794 outrel
.r_offset
= rel
->r_offset
;
3795 outrel
.r_addend
= rel
->r_addend
;
3797 if (elf_section_data (input_section
)->stab_info
!= NULL
)
3801 off
= (_bfd_stab_section_offset
3802 (output_bfd
, &hplink
->root
.stab_info
,
3804 &elf_section_data (input_section
)->stab_info
,
3806 if (off
== (bfd_vma
) -1)
3808 outrel
.r_offset
= off
;
3811 outrel
.r_offset
+= (input_section
->output_offset
3812 + input_section
->output_section
->vma
);
3816 memset (&outrel
, 0, sizeof (outrel
));
3819 && h
->elf
.dynindx
!= -1
3822 || (h
->elf
.elf_link_hash_flags
3823 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
3825 outrel
.r_info
= ELF32_R_INFO (h
->elf
.dynindx
, r_type
);
3827 else /* It's a local symbol, or one marked to become local. */
3831 /* Add the absolute offset of the symbol. */
3832 outrel
.r_addend
+= relocation
;
3834 /* Global plabels need to be processed by the
3835 dynamic linker so that functions have at most one
3836 fptr. For this reason, we need to differentiate
3837 between global and local plabels, which we do by
3838 providing the function symbol for a global plabel
3839 reloc, and no symbol for local plabels. */
3842 && sym_sec
->output_section
!= NULL
3843 && ! bfd_is_abs_section (sym_sec
))
3845 indx
= elf_section_data (sym_sec
->output_section
)->dynindx
;
3846 /* We are turning this relocation into one
3847 against a section symbol, so subtract out the
3848 output section's address but not the offset
3849 of the input section in the output section. */
3850 outrel
.r_addend
-= sym_sec
->output_section
->vma
;
3853 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
3856 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3857 ((Elf32_External_Rela
*)
3859 + sreloc
->reloc_count
));
3860 ++sreloc
->reloc_count
;
3868 r
= final_link_relocate (input_section
, contents
, rel
, relocation
,
3869 hplink
, sym_sec
, h
);
3871 if (r
== bfd_reloc_ok
)
3875 sym_name
= h
->elf
.root
.root
.string
;
3878 sym_name
= bfd_elf_string_from_elf_section (input_bfd
,
3879 symtab_hdr
->sh_link
,
3881 if (sym_name
== NULL
)
3883 if (*sym_name
== '\0')
3884 sym_name
= bfd_section_name (input_bfd
, sym_sec
);
3887 howto
= elf_hppa_howto_table
+ r_type
;
3889 if (r
== bfd_reloc_undefined
|| r
== bfd_reloc_notsupported
)
3891 (*_bfd_error_handler
)
3892 (_("%s(%s+0x%lx): cannot handle %s for %s"),
3893 bfd_get_filename (input_bfd
),
3894 input_section
->name
,
3895 (long) rel
->r_offset
,
3901 if (!((*info
->callbacks
->reloc_overflow
)
3902 (info
, sym_name
, howto
->name
, (bfd_vma
) 0,
3903 input_bfd
, input_section
, rel
->r_offset
)))
3912 /* Finish up dynamic symbol handling. We set the contents of various
3913 dynamic sections here. */
3916 elf32_hppa_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
3918 struct bfd_link_info
*info
;
3919 struct elf_link_hash_entry
*h
;
3920 Elf_Internal_Sym
*sym
;
3922 struct elf32_hppa_link_hash_table
*hplink
;
3925 hplink
= hppa_link_hash_table (info
);
3926 dynobj
= hplink
->root
.dynobj
;
3928 if (h
->plt
.offset
!= (bfd_vma
) -1)
3932 /* This symbol has an entry in the procedure linkage table. Set
3935 The format of a plt entry is
3940 if (h
->root
.type
== bfd_link_hash_defined
3941 || h
->root
.type
== bfd_link_hash_defweak
)
3943 value
= h
->root
.u
.def
.value
;
3944 if (h
->root
.u
.def
.section
->output_section
!= NULL
)
3945 value
+= (h
->root
.u
.def
.section
->output_offset
3946 + h
->root
.u
.def
.section
->output_section
->vma
);
3949 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
)
3951 Elf_Internal_Rela rel
;
3953 /* Create a dynamic IPLT relocation for this entry. */
3954 rel
.r_offset
= (h
->plt
.offset
3955 + hplink
->splt
->output_offset
3956 + hplink
->splt
->output_section
->vma
);
3957 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->plt_abs
3958 && h
->dynindx
!= -1)
3960 /* To support lazy linking, the function pointer is
3961 initialised to point to a special stub stored at the
3962 end of the .plt. This is only done for plt entries
3963 with a non-*ABS* dynamic relocation. */
3964 value
= (hplink
->splt
->output_offset
3965 + hplink
->splt
->output_section
->vma
3966 + hplink
->splt
->_raw_size
3969 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_IPLT
);
3974 /* This symbol has been marked to become local, and is
3975 used by a plabel so must be kept in the .plt. */
3976 rel
.r_info
= ELF32_R_INFO (0, R_PARISC_IPLT
);
3977 rel
.r_addend
= value
;
3980 bfd_elf32_swap_reloca_out (hplink
->splt
->output_section
->owner
,
3982 ((Elf32_External_Rela
*)
3983 hplink
->srelplt
->contents
3984 + hplink
->srelplt
->reloc_count
));
3985 hplink
->srelplt
->reloc_count
++;
3988 bfd_put_32 (hplink
->splt
->owner
,
3990 hplink
->splt
->contents
+ h
->plt
.offset
);
3991 bfd_put_32 (hplink
->splt
->owner
,
3992 elf_gp (hplink
->splt
->output_section
->owner
),
3993 hplink
->splt
->contents
+ h
->plt
.offset
+ 4);
3994 if (PLABEL_PLT_ENTRY_SIZE
!= PLT_ENTRY_SIZE
3995 && ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
3996 && h
->dynindx
!= -1)
3998 memset (hplink
->splt
->contents
+ h
->plt
.offset
+ 8,
3999 0, PLABEL_PLT_ENTRY_SIZE
- PLT_ENTRY_SIZE
);
4002 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4004 /* Mark the symbol as undefined, rather than as defined in
4005 the .plt section. Leave the value alone. */
4006 sym
->st_shndx
= SHN_UNDEF
;
4010 if (h
->got
.offset
!= (bfd_vma
) -1)
4012 Elf_Internal_Rela rel
;
4014 /* This symbol has an entry in the global offset table. Set it
4017 rel
.r_offset
= ((h
->got
.offset
&~ (bfd_vma
) 1)
4018 + hplink
->sgot
->output_offset
4019 + hplink
->sgot
->output_section
->vma
);
4021 /* If this is a static link, or it is a -Bsymbolic link and the
4022 symbol is defined locally or was forced to be local because
4023 of a version file, we just want to emit a RELATIVE reloc.
4024 The entry in the global offset table will already have been
4025 initialized in the relocate_section function. */
4026 if (! hplink
->root
.dynamic_sections_created
4028 && (info
->symbolic
|| h
->dynindx
== -1)
4029 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
4031 rel
.r_info
= ELF32_R_INFO (0, R_PARISC_DIR32
);
4032 rel
.r_addend
= (h
->root
.u
.def
.value
4033 + h
->root
.u
.def
.section
->output_offset
4034 + h
->root
.u
.def
.section
->output_section
->vma
);
4038 BFD_ASSERT((h
->got
.offset
& 1) == 0);
4039 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
4040 hplink
->sgot
->contents
+ h
->got
.offset
);
4041 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_DIR32
);
4045 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
4046 ((Elf32_External_Rela
*)
4047 hplink
->srelgot
->contents
4048 + hplink
->srelgot
->reloc_count
));
4049 ++hplink
->srelgot
->reloc_count
;
4052 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
4055 Elf_Internal_Rela rel
;
4057 /* This symbol needs a copy reloc. Set it up. */
4059 BFD_ASSERT (h
->dynindx
!= -1
4060 && (h
->root
.type
== bfd_link_hash_defined
4061 || h
->root
.type
== bfd_link_hash_defweak
));
4063 s
= hplink
->srelbss
;
4065 rel
.r_offset
= (h
->root
.u
.def
.value
4066 + h
->root
.u
.def
.section
->output_offset
4067 + h
->root
.u
.def
.section
->output_section
->vma
);
4069 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_COPY
);
4070 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
4071 ((Elf32_External_Rela
*) s
->contents
4076 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
4077 if (h
->root
.root
.string
[0] == '_'
4078 && (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4079 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0))
4081 sym
->st_shndx
= SHN_ABS
;
4088 /* Finish up the dynamic sections. */
4091 elf32_hppa_finish_dynamic_sections (output_bfd
, info
)
4093 struct bfd_link_info
*info
;
4096 struct elf32_hppa_link_hash_table
*hplink
;
4099 hplink
= hppa_link_hash_table (info
);
4100 dynobj
= hplink
->root
.dynobj
;
4102 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4104 if (hplink
->root
.dynamic_sections_created
)
4106 Elf32_External_Dyn
*dyncon
, *dynconend
;
4108 BFD_ASSERT (sdyn
!= NULL
);
4110 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4111 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
4112 for (; dyncon
< dynconend
; dyncon
++)
4114 Elf_Internal_Dyn dyn
;
4117 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4125 /* Use PLTGOT to set the GOT register. */
4126 dyn
.d_un
.d_ptr
= elf_gp (output_bfd
);
4127 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4131 s
= hplink
->srelplt
;
4132 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4133 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4137 s
= hplink
->srelplt
;
4138 if (s
->_cooked_size
!= 0)
4139 dyn
.d_un
.d_val
= s
->_cooked_size
;
4141 dyn
.d_un
.d_val
= s
->_raw_size
;
4142 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4148 struct elf_link_hash_entry
*h
;
4149 const char *funcname
;
4151 if (dyn
.d_tag
== DT_INIT
)
4152 funcname
= info
->init_function
;
4154 funcname
= info
->fini_function
;
4156 h
= elf_link_hash_lookup (&hplink
->root
, funcname
,
4157 false, false, false);
4159 /* This is a function pointer. The magic +2 offset
4160 signals to $$dyncall that the function pointer
4161 is in the .plt and thus has a gp pointer too. */
4162 dyn
.d_un
.d_ptr
= (h
->plt
.offset
4163 + hplink
->splt
->output_offset
4164 + hplink
->splt
->output_section
->vma
4166 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4173 if (hplink
->sgot
->_raw_size
!= 0)
4175 /* Fill in the first entry in the global offset table.
4176 We use it to point to our dynamic section, if we have one. */
4177 bfd_put_32 (output_bfd
,
4179 ? sdyn
->output_section
->vma
+ sdyn
->output_offset
4181 hplink
->sgot
->contents
);
4183 /* The second entry is reserved for use by the dynamic linker. */
4184 memset (hplink
->sgot
->contents
+ GOT_ENTRY_SIZE
, 0, GOT_ENTRY_SIZE
);
4186 /* Set .got entry size. */
4187 elf_section_data (hplink
->sgot
->output_section
)
4188 ->this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
4191 if (hplink
->splt
->_raw_size
!= 0)
4193 /* Set plt entry size. */
4194 elf_section_data (hplink
->splt
->output_section
)
4195 ->this_hdr
.sh_entsize
= PLT_ENTRY_SIZE
;
4197 if (hplink
->need_plt_stub
)
4199 /* Set up the .plt stub. */
4200 memcpy (hplink
->splt
->contents
4201 + hplink
->splt
->_raw_size
- sizeof (plt_stub
),
4202 plt_stub
, sizeof (plt_stub
));
4204 if ((hplink
->splt
->output_offset
4205 + hplink
->splt
->output_section
->vma
4206 + hplink
->splt
->_raw_size
)
4207 != (hplink
->sgot
->output_offset
4208 + hplink
->sgot
->output_section
->vma
))
4210 (*_bfd_error_handler
)
4211 (_(".got section not immediately after .plt section"));
4221 /* Called when writing out an object file to decide the type of a
4224 elf32_hppa_elf_get_symbol_type (elf_sym
, type
)
4225 Elf_Internal_Sym
*elf_sym
;
4228 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_PARISC_MILLI
)
4229 return STT_PARISC_MILLI
;
4235 /* Misc BFD support code. */
4236 #define bfd_elf32_bfd_is_local_label_name elf_hppa_is_local_label_name
4237 #define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
4238 #define elf_info_to_howto elf_hppa_info_to_howto
4239 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
4241 /* Stuff for the BFD linker. */
4242 #define bfd_elf32_bfd_final_link _bfd_elf32_gc_common_final_link
4243 #define bfd_elf32_bfd_link_hash_table_create elf32_hppa_link_hash_table_create
4244 #define elf_backend_add_symbol_hook elf32_hppa_add_symbol_hook
4245 #define elf_backend_adjust_dynamic_symbol elf32_hppa_adjust_dynamic_symbol
4246 #define elf_backend_check_relocs elf32_hppa_check_relocs
4247 #define elf_backend_create_dynamic_sections elf32_hppa_create_dynamic_sections
4248 #define elf_backend_fake_sections elf_hppa_fake_sections
4249 #define elf_backend_relocate_section elf32_hppa_relocate_section
4250 #define elf_backend_hide_symbol elf32_hppa_hide_symbol
4251 #define elf_backend_finish_dynamic_symbol elf32_hppa_finish_dynamic_symbol
4252 #define elf_backend_finish_dynamic_sections elf32_hppa_finish_dynamic_sections
4253 #define elf_backend_size_dynamic_sections elf32_hppa_size_dynamic_sections
4254 #define elf_backend_gc_mark_hook elf32_hppa_gc_mark_hook
4255 #define elf_backend_gc_sweep_hook elf32_hppa_gc_sweep_hook
4256 #define elf_backend_object_p elf32_hppa_object_p
4257 #define elf_backend_final_write_processing elf_hppa_final_write_processing
4258 #define elf_backend_get_symbol_type elf32_hppa_elf_get_symbol_type
4260 #define elf_backend_can_gc_sections 1
4261 #define elf_backend_plt_alignment 2
4262 #define elf_backend_want_got_plt 0
4263 #define elf_backend_plt_readonly 0
4264 #define elf_backend_want_plt_sym 0
4265 #define elf_backend_got_header_size 8
4267 #define TARGET_BIG_SYM bfd_elf32_hppa_vec
4268 #define TARGET_BIG_NAME "elf32-hppa"
4269 #define ELF_ARCH bfd_arch_hppa
4270 #define ELF_MACHINE_CODE EM_PARISC
4271 #define ELF_MAXPAGESIZE 0x1000
4273 #include "elf32-target.h"