1 /* BFD back-end for HP PA-RISC ELF files.
2 Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000
3 Free Software Foundation, Inc.
6 Center for Software Science
7 Department of Computer Science
9 Largely rewritten by Alan Modra <alan@linuxcare.com.au>
11 This file is part of BFD, the Binary File Descriptor library.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
33 #include "elf32-hppa.h"
36 #include "elf32-hppa.h"
39 /* In order to gain some understanding of code in this file without
40 knowing all the intricate details of the linker, note the
43 Functions named elf32_hppa_* are called by external routines, other
44 functions are only called locally. elf32_hppa_* functions appear
45 in this file more or less in the order in which they are called
46 from external routines. eg. elf32_hppa_check_relocs is called
47 early in the link process, elf32_hppa_finish_dynamic_sections is
48 one of the last functions. */
51 /* We use two hash tables to hold information for linking PA ELF objects.
53 The first is the elf32_hppa_link_hash_table which is derived
54 from the standard ELF linker hash table. We use this as a place to
55 attach other hash tables and static information.
57 The second is the stub hash table which is derived from the
58 base BFD hash table. The stub hash table holds the information
59 necessary to build the linker stubs during a link.
61 There are a number of different stubs generated by the linker.
69 : addil L'X - ($PIC_pcrel$0 - 4),%r1
70 : be,n R'X - ($PIC_pcrel$0 - 8)(%sr4,%r1)
72 Import stub to call shared library routine from normal object file
73 (single sub-space version)
74 : addil L'lt_ptr+ltoff,%dp ; get procedure entry point
75 : ldw R'lt_ptr+ltoff(%r1),%r21
77 : ldw R'lt_ptr+ltoff+4(%r1),%r19 ; get new dlt value.
79 Import stub to call shared library routine from shared library
80 (single sub-space version)
81 : addil L'ltoff,%r19 ; get procedure entry point
82 : ldw R'ltoff(%r1),%r21
84 : ldw R'ltoff+4(%r1),%r19 ; get new dlt value.
86 Import stub to call shared library routine from normal object file
87 (multiple sub-space support)
88 : addil L'lt_ptr+ltoff,%dp ; get procedure entry point
89 : ldw R'lt_ptr+ltoff(%r1),%r21
90 : ldw R'lt_ptr+ltoff+4(%r1),%r19 ; get new dlt value.
93 : be 0(%sr0,%r21) ; branch to target
94 : stw %rp,-24(%sp) ; save rp
96 Import stub to call shared library routine from shared library
97 (multiple sub-space support)
98 : addil L'ltoff,%r19 ; get procedure entry point
99 : ldw R'ltoff(%r1),%r21
100 : ldw R'ltoff+4(%r1),%r19 ; get new dlt value.
103 : be 0(%sr0,%r21) ; branch to target
104 : stw %rp,-24(%sp) ; save rp
106 Export stub to return from shared lib routine (multiple sub-space support)
107 One of these is created for each exported procedure in a shared
108 library (and stored in the shared lib). Shared lib routines are
109 called via the first instruction in the export stub so that we can
110 do an inter-space return. Not required for single sub-space.
111 : bl,n X,%rp ; trap the return
113 : ldw -24(%sp),%rp ; restore the original rp
116 : be,n 0(%sr0,%rp) ; inter-space return */
118 #define PLT_ENTRY_SIZE 8
119 #define PLABEL_PLT_ENTRY_SIZE PLT_ENTRY_SIZE
120 #define GOT_ENTRY_SIZE 4
121 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
123 /* Section name for stubs is the associated section name plus this
125 #define STUB_SUFFIX ".stub"
127 /* Setting the following non-zero makes all long branch stubs
128 generated during a shared link of the PIC variety. This saves on
129 relocs, but costs one extra instruction per stub. */
130 #ifndef LONG_BRANCH_PIC_IN_SHLIB
131 #define LONG_BRANCH_PIC_IN_SHLIB 1
134 /* Set this non-zero to use import stubs instead of long branch stubs
135 where a .plt entry exists for the symbol. This is a fairly useless
136 option as import stubs are bigger than PIC long branch stubs. */
137 #ifndef LONG_BRANCH_VIA_PLT
138 #define LONG_BRANCH_VIA_PLT 0
141 /* We don't need to copy any PC- or GP-relative dynamic relocs into a
142 shared object's dynamic section. */
143 #ifndef RELATIVE_DYNAMIC_RELOCS
144 #define RELATIVE_DYNAMIC_RELOCS 0
148 enum elf32_hppa_stub_type
{
149 hppa_stub_long_branch
,
150 hppa_stub_long_branch_shared
,
152 hppa_stub_import_shared
,
158 struct elf32_hppa_stub_hash_entry
{
160 /* Base hash table entry structure. */
161 struct bfd_hash_entry root
;
163 /* The stub section. */
166 #if ! LONG_BRANCH_PIC_IN_SHLIB
167 /* It's associated reloc section. */
171 /* Offset within stub_sec of the beginning of this stub. */
174 /* Given the symbol's value and its section we can determine its final
175 value when building the stubs (so the stub knows where to jump. */
176 bfd_vma target_value
;
177 asection
*target_section
;
179 enum elf32_hppa_stub_type stub_type
;
181 /* The symbol table entry, if any, that this was derived from. */
182 struct elf32_hppa_link_hash_entry
*h
;
184 /* Where this stub is being called from. */
185 asection
*input_section
;
189 struct elf32_hppa_link_hash_entry
{
191 struct elf_link_hash_entry elf
;
193 /* A pointer to the most recently used stub hash entry against this
195 struct elf32_hppa_stub_hash_entry
*stub_cache
;
197 #if ! LONG_BRANCH_PIC_IN_SHLIB
198 /* Used to track whether we have allocated space for a long branch
199 stub relocation for this symbol in the given section. */
200 asection
*stub_reloc_sec
;
203 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
204 /* Used to count relocations for delayed sizing of relocation
206 struct elf32_hppa_dyn_reloc_entry
{
208 /* Next relocation in the chain. */
209 struct elf32_hppa_dyn_reloc_entry
*next
;
211 /* The section in dynobj. */
214 /* Number of relocs copied in this section. */
219 /* Set during a static link if we detect a function is PIC. */
220 unsigned int pic_call
:1;
222 /* Set if this symbol is used by a plabel reloc. */
223 unsigned int plabel
:1;
225 /* Set if this symbol is an init or fini function and thus should
226 use an absolute reloc. */
227 unsigned int plt_abs
:1;
231 struct elf32_hppa_link_hash_table
{
233 /* The main hash table. */
234 struct elf_link_hash_table root
;
236 /* The stub hash table. */
237 struct bfd_hash_table stub_hash_table
;
239 /* Linker stub bfd. */
242 /* Whether we support multiple sub-spaces for shared libs. */
243 boolean multi_subspace
;
245 /* Linker call-backs. */
246 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
247 void (*layout_sections_again
) PARAMS ((void));
249 /* Arrays to keep track of which stub sections have been created. */
250 asection
**stub_section_created
;
251 #if ! LONG_BRANCH_PIC_IN_SHLIB
252 asection
**reloc_section_created
;
257 /* Short-cuts to get to dynamic linker sections. */
267 /* Various hash macros and functions. */
268 #define hppa_link_hash_table(p) \
269 ((struct elf32_hppa_link_hash_table *) ((p)->hash))
271 #define hppa_stub_hash_lookup(table, string, create, copy) \
272 ((struct elf32_hppa_stub_hash_entry *) \
273 bfd_hash_lookup ((table), (string), (create), (copy)))
275 static struct bfd_hash_entry
*stub_hash_newfunc
276 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
278 static struct bfd_hash_entry
*hppa_link_hash_newfunc
279 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
281 static struct bfd_link_hash_table
*elf32_hppa_link_hash_table_create
285 /* Stub handling functions. */
286 static char *hppa_stub_name
287 PARAMS ((const asection
*, const asection
*,
288 const struct elf32_hppa_link_hash_entry
*,
289 const Elf_Internal_Rela
*));
291 static struct elf32_hppa_stub_hash_entry
*hppa_get_stub_entry
292 PARAMS ((const asection
*, const asection
*,
293 struct elf32_hppa_link_hash_entry
*,
294 const Elf_Internal_Rela
*, struct bfd_link_info
*));
296 static struct elf32_hppa_stub_hash_entry
*hppa_add_stub
297 PARAMS ((const char *, asection
*, unsigned int,
298 struct bfd_link_info
*));
300 static enum elf32_hppa_stub_type hppa_type_of_stub
301 PARAMS ((asection
*, const Elf_Internal_Rela
*,
302 struct elf32_hppa_link_hash_entry
*, bfd_vma
));
304 static boolean hppa_build_one_stub
305 PARAMS ((struct bfd_hash_entry
*, PTR
));
307 static boolean hppa_size_one_stub
308 PARAMS ((struct bfd_hash_entry
*, PTR
));
311 /* BFD and elf backend functions. */
312 static boolean elf32_hppa_object_p
PARAMS ((bfd
*));
314 static boolean elf32_hppa_add_symbol_hook
315 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
316 const char **, flagword
*, asection
**, bfd_vma
*));
318 static boolean elf32_hppa_create_dynamic_sections
319 PARAMS ((bfd
*, struct bfd_link_info
*));
321 static boolean elf32_hppa_check_relocs
322 PARAMS ((bfd
*, struct bfd_link_info
*,
323 asection
*, const Elf_Internal_Rela
*));
325 static asection
*elf32_hppa_gc_mark_hook
326 PARAMS ((bfd
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
327 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
329 static boolean elf32_hppa_gc_sweep_hook
330 PARAMS ((bfd
*, struct bfd_link_info
*,
331 asection
*, const Elf_Internal_Rela
*));
333 static void elf32_hppa_hide_symbol
334 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
336 static boolean elf32_hppa_adjust_dynamic_symbol
337 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
339 static boolean hppa_handle_PIC_calls
340 PARAMS ((struct elf_link_hash_entry
*, PTR
));
342 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
343 || RELATIVE_DYNAMIC_RELOCS)
344 static boolean hppa_discard_copies
345 PARAMS ((struct elf_link_hash_entry
*, PTR
));
348 static boolean clobber_millicode_symbols
349 PARAMS ((struct elf_link_hash_entry
*, struct bfd_link_info
*));
351 static boolean elf32_hppa_size_dynamic_sections
352 PARAMS ((bfd
*, struct bfd_link_info
*));
354 static bfd_reloc_status_type final_link_relocate
355 PARAMS ((asection
*, bfd_byte
*, const Elf_Internal_Rela
*,
356 bfd_vma
, struct bfd_link_info
*, asection
*,
357 struct elf32_hppa_link_hash_entry
*));
359 static boolean elf32_hppa_relocate_section
360 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*,
361 bfd_byte
*, Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
363 static boolean elf32_hppa_finish_dynamic_symbol
364 PARAMS ((bfd
*, struct bfd_link_info
*,
365 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
367 static boolean elf32_hppa_finish_dynamic_sections
368 PARAMS ((bfd
*, struct bfd_link_info
*));
370 static int elf32_hppa_elf_get_symbol_type
371 PARAMS ((Elf_Internal_Sym
*, int));
374 /* Assorted hash table functions. */
376 /* Initialize an entry in the stub hash table. */
378 static struct bfd_hash_entry
*
379 stub_hash_newfunc (entry
, table
, string
)
380 struct bfd_hash_entry
*entry
;
381 struct bfd_hash_table
*table
;
384 struct elf32_hppa_stub_hash_entry
*ret
;
386 ret
= (struct elf32_hppa_stub_hash_entry
*) entry
;
388 /* Allocate the structure if it has not already been allocated by a
392 ret
= ((struct elf32_hppa_stub_hash_entry
*)
393 bfd_hash_allocate (table
,
394 sizeof (struct elf32_hppa_stub_hash_entry
)));
399 /* Call the allocation method of the superclass. */
400 ret
= ((struct elf32_hppa_stub_hash_entry
*)
401 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
405 /* Initialize the local fields. */
406 ret
->stub_sec
= NULL
;
407 #if ! LONG_BRANCH_PIC_IN_SHLIB
408 ret
->reloc_sec
= NULL
;
410 ret
->stub_offset
= 0;
411 ret
->target_value
= 0;
412 ret
->target_section
= NULL
;
413 ret
->stub_type
= hppa_stub_long_branch
;
415 ret
->input_section
= NULL
;
418 return (struct bfd_hash_entry
*) ret
;
422 /* Initialize an entry in the link hash table. */
424 static struct bfd_hash_entry
*
425 hppa_link_hash_newfunc (entry
, table
, string
)
426 struct bfd_hash_entry
*entry
;
427 struct bfd_hash_table
*table
;
430 struct elf32_hppa_link_hash_entry
*ret
;
432 ret
= (struct elf32_hppa_link_hash_entry
*) entry
;
434 /* Allocate the structure if it has not already been allocated by a
438 ret
= ((struct elf32_hppa_link_hash_entry
*)
439 bfd_hash_allocate (table
,
440 sizeof (struct elf32_hppa_link_hash_entry
)));
445 /* Call the allocation method of the superclass. */
446 ret
= ((struct elf32_hppa_link_hash_entry
*)
447 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
452 /* Initialize the local fields. */
453 #if ! LONG_BRANCH_PIC_IN_SHLIB
454 ret
->stub_reloc_sec
= NULL
;
456 ret
->stub_cache
= NULL
;
457 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
458 ret
->reloc_entries
= NULL
;
465 return (struct bfd_hash_entry
*) ret
;
469 /* Create the derived linker hash table. The PA ELF port uses the derived
470 hash table to keep information specific to the PA ELF linker (without
471 using static variables). */
473 static struct bfd_link_hash_table
*
474 elf32_hppa_link_hash_table_create (abfd
)
477 struct elf32_hppa_link_hash_table
*ret
;
479 ret
= ((struct elf32_hppa_link_hash_table
*) bfd_alloc (abfd
, sizeof (*ret
)));
483 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
, hppa_link_hash_newfunc
))
485 bfd_release (abfd
, ret
);
489 /* Init the stub hash table too. */
490 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
))
493 ret
->stub_bfd
= NULL
;
494 ret
->multi_subspace
= 0;
495 ret
->add_stub_section
= NULL
;
496 ret
->layout_sections_again
= NULL
;
497 ret
->stub_section_created
= NULL
;
498 #if ! LONG_BRANCH_PIC_IN_SHLIB
499 ret
->reloc_section_created
= NULL
;
501 ret
->first_init_sec
= 0;
502 ret
->first_fini_sec
= 0;
510 return &ret
->root
.root
;
514 /* Build a name for an entry in the stub hash table. */
517 hppa_stub_name (input_section
, sym_sec
, hash
, rel
)
518 const asection
*input_section
;
519 const asection
*sym_sec
;
520 const struct elf32_hppa_link_hash_entry
*hash
;
521 const Elf_Internal_Rela
*rel
;
528 len
= 8 + 1 + strlen (hash
->elf
.root
.root
.string
) + 1 + 8 + 1;
529 stub_name
= bfd_malloc (len
);
530 if (stub_name
!= NULL
)
532 sprintf (stub_name
, "%08x_%s+%x",
533 input_section
->id
& 0xffffffff,
534 hash
->elf
.root
.root
.string
,
535 (int) rel
->r_addend
& 0xffffffff);
540 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
541 stub_name
= bfd_malloc (len
);
542 if (stub_name
!= NULL
)
544 sprintf (stub_name
, "%08x_%x:%x+%x",
545 input_section
->id
& 0xffffffff,
546 sym_sec
->id
& 0xffffffff,
547 (int) ELF32_R_SYM (rel
->r_info
) & 0xffffffff,
548 (int) rel
->r_addend
& 0xffffffff);
555 /* Look up an entry in the stub hash. Stub entries are cached because
556 creating the stub name takes a bit of time. */
558 static struct elf32_hppa_stub_hash_entry
*
559 hppa_get_stub_entry (input_section
, sym_sec
, hash
, rel
, info
)
560 const asection
*input_section
;
561 const asection
*sym_sec
;
562 struct elf32_hppa_link_hash_entry
*hash
;
563 const Elf_Internal_Rela
*rel
;
564 struct bfd_link_info
*info
;
566 struct elf32_hppa_stub_hash_entry
*stub_entry
;
568 if (hash
!= NULL
&& hash
->stub_cache
!= NULL
569 && hash
->stub_cache
->h
== hash
570 && hash
->stub_cache
->input_section
== input_section
)
572 stub_entry
= hash
->stub_cache
;
576 struct bfd_hash_table
*stub_hash_table
;
579 stub_name
= hppa_stub_name (input_section
, sym_sec
, hash
, rel
);
580 if (stub_name
== NULL
)
583 stub_hash_table
= &hppa_link_hash_table (info
)->stub_hash_table
;
585 stub_entry
= hppa_stub_hash_lookup (stub_hash_table
, stub_name
,
587 if (stub_entry
== NULL
)
589 if (hash
== NULL
|| hash
->elf
.root
.type
!= bfd_link_hash_undefweak
)
590 (*_bfd_error_handler
) (_("%s(%s+0x%lx): cannot find stub entry %s"),
591 bfd_get_filename (input_section
->owner
),
593 (long) rel
->r_offset
,
599 hash
->stub_cache
= stub_entry
;
609 /* Add a new stub entry to the stub hash. Not all fields of the new
610 stub entry are initialised. */
612 static struct elf32_hppa_stub_hash_entry
*
613 hppa_add_stub (stub_name
, section
, sec_count
, info
)
614 const char *stub_name
;
616 unsigned int sec_count
;
617 struct bfd_link_info
*info
;
620 struct elf32_hppa_stub_hash_entry
*stub_entry
;
621 struct elf32_hppa_link_hash_table
*hplink
;
623 hplink
= hppa_link_hash_table (info
);
624 stub_sec
= hplink
->stub_section_created
[sec_count
];
625 if (stub_sec
== NULL
)
627 if (strncmp (section
->name
, ".init", 5) == 0)
628 stub_sec
= hplink
->stub_section_created
[hplink
->first_init_sec
- 1];
629 else if (strncmp (section
->name
, ".fini", 5) == 0)
630 stub_sec
= hplink
->stub_section_created
[hplink
->first_fini_sec
- 1];
632 if (stub_sec
== NULL
)
637 len
= strlen (section
->name
) + sizeof (STUB_SUFFIX
);
638 s_name
= bfd_alloc (hplink
->stub_bfd
, len
);
642 strcpy (s_name
, section
->name
);
643 strcpy (s_name
+ len
- sizeof (STUB_SUFFIX
), STUB_SUFFIX
);
644 stub_sec
= (*hplink
->add_stub_section
) (s_name
, section
);
645 if (stub_sec
== NULL
)
648 hplink
->stub_section_created
[sec_count
] = stub_sec
;
651 /* Enter this entry into the linker stub hash table. */
652 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
, stub_name
,
654 if (stub_entry
== NULL
)
656 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
657 bfd_get_filename (section
->owner
),
662 stub_entry
->stub_sec
= stub_sec
;
663 #if ! LONG_BRANCH_PIC_IN_SHLIB
664 stub_entry
->reloc_sec
= hplink
->reloc_section_created
[sec_count
];
666 stub_entry
->stub_offset
= 0;
667 stub_entry
->input_section
= section
;
672 /* Determine the type of stub needed, if any, for a call. */
674 static enum elf32_hppa_stub_type
675 hppa_type_of_stub (input_sec
, rel
, hash
, destination
)
677 const Elf_Internal_Rela
*rel
;
678 struct elf32_hppa_link_hash_entry
*hash
;
682 bfd_vma branch_offset
;
683 bfd_vma max_branch_offset
;
687 && (((hash
->elf
.root
.type
== bfd_link_hash_defined
688 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
689 && hash
->elf
.root
.u
.def
.section
->output_section
== NULL
)
690 || (hash
->elf
.root
.type
== bfd_link_hash_defweak
691 && hash
->elf
.dynindx
!= -1
692 && hash
->elf
.plt
.offset
!= (bfd_vma
) -1)
693 || hash
->elf
.root
.type
== bfd_link_hash_undefweak
694 || hash
->elf
.root
.type
== bfd_link_hash_undefined
697 /* If output_section is NULL, then it's a symbol defined in a
698 shared library. We will need an import stub. Decide between
699 hppa_stub_import and hppa_stub_import_shared later. For
700 shared links we need stubs for undefined or weak syms too;
701 They will presumably be resolved by the dynamic linker. */
702 return hppa_stub_import
;
705 /* Determine where the call point is. */
706 location
= (input_sec
->output_offset
707 + input_sec
->output_section
->vma
710 branch_offset
= destination
- location
- 8;
711 r_type
= ELF32_R_TYPE (rel
->r_info
);
713 /* Determine if a long branch stub is needed. parisc branch offsets
714 are relative to the second instruction past the branch, ie. +8
715 bytes on from the branch instruction location. The offset is
716 signed and counts in units of 4 bytes. */
717 if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
719 max_branch_offset
= (1 << (17-1)) << 2;
721 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
723 max_branch_offset
= (1 << (12-1)) << 2;
725 else /* R_PARISC_PCREL22F */
727 max_branch_offset
= (1 << (22-1)) << 2;
730 if (branch_offset
+ max_branch_offset
>= 2*max_branch_offset
)
732 #if LONG_BRANCH_VIA_PLT
734 && hash
->elf
.dynindx
!= -1
735 && hash
->elf
.plt
.offset
!= (bfd_vma
) -1)
737 /* If we are doing a shared link and find we need a long
738 branch stub, then go via the .plt if possible. */
739 return hppa_stub_import
;
743 return hppa_stub_long_branch
;
745 return hppa_stub_none
;
749 /* Build one linker stub as defined by the stub hash table entry GEN_ENTRY.
750 IN_ARG contains the link info pointer. */
752 #define LDIL_R1 0x20200000 /* ldil LR'XXX,%r1 */
753 #define BE_SR4_R1 0xe0202002 /* be,n RR'XXX(%sr4,%r1) */
755 #define BL_R1 0xe8200000 /* b,l .+8,%r1 */
756 #define ADDIL_R1 0x28200000 /* addil L'XXX,%r1,%r1 */
757 #define DEPI_R1 0xd4201c1e /* depi 0,31,2,%r1 */
759 #define ADDIL_DP 0x2b600000 /* addil L'XXX,%dp,%r1 */
760 #define LDW_R1_R21 0x48350000 /* ldw R'XXX(%sr0,%r1),%r21 */
761 #define BV_R0_R21 0xeaa0c000 /* bv %r0(%r21) */
762 #define LDW_R1_R19 0x48330000 /* ldw R'XXX(%sr0,%r1),%r19 */
764 #define ADDIL_R19 0x2a600000 /* addil L'XXX,%r19,%r1 */
765 #define LDW_R1_DP 0x483b0000 /* ldw R'XXX(%sr0,%r1),%dp */
767 #define LDSID_R21_R1 0x02a010a1 /* ldsid (%sr0,%r21),%r1 */
768 #define MTSP_R1 0x00011820 /* mtsp %r1,%sr0 */
769 #define BE_SR0_R21 0xe2a00000 /* be 0(%sr0,%r21) */
770 #define STW_RP 0x6bc23fd1 /* stw %rp,-24(%sr0,%sp) */
772 #define BL_RP 0xe8400002 /* b,l,n XXX,%rp */
773 #define NOP 0x08000240 /* nop */
774 #define LDW_RP 0x4bc23fd1 /* ldw -24(%sr0,%sp),%rp */
775 #define LDSID_RP_R1 0x004010a1 /* ldsid (%sr0,%rp),%r1 */
776 #define BE_SR0_RP 0xe0400002 /* be,n 0(%sr0,%rp) */
783 #define LDW_R1_DLT LDW_R1_R19
785 #define LDW_R1_DLT LDW_R1_DP
789 hppa_build_one_stub (gen_entry
, in_arg
)
790 struct bfd_hash_entry
*gen_entry
;
793 struct elf32_hppa_stub_hash_entry
*stub_entry
;
794 struct bfd_link_info
*info
;
795 struct elf32_hppa_link_hash_table
*hplink
;
804 /* Massage our args to the form they really have. */
805 stub_entry
= (struct elf32_hppa_stub_hash_entry
*) gen_entry
;
806 info
= (struct bfd_link_info
*) in_arg
;
808 hplink
= hppa_link_hash_table (info
);
809 stub_sec
= stub_entry
->stub_sec
;
811 /* Make a note of the offset within the stubs for this entry. */
812 stub_entry
->stub_offset
= stub_sec
->_raw_size
;
813 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
815 stub_bfd
= stub_sec
->owner
;
817 switch (stub_entry
->stub_type
)
819 case hppa_stub_long_branch
:
820 /* Create the long branch. A long branch is formed with "ldil"
821 loading the upper bits of the target address into a register,
822 then branching with "be" which adds in the lower bits.
823 The "be" has its delay slot nullified. */
824 sym_value
= (stub_entry
->target_value
825 + stub_entry
->target_section
->output_offset
826 + stub_entry
->target_section
->output_section
->vma
);
828 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_lrsel
);
829 insn
= hppa_rebuild_insn ((int) LDIL_R1
, val
, 21);
830 bfd_put_32 (stub_bfd
, insn
, loc
);
832 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_rrsel
) >> 2;
833 insn
= hppa_rebuild_insn ((int) BE_SR4_R1
, val
, 17);
834 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
836 #if ! LONG_BRANCH_PIC_IN_SHLIB
839 /* Output a dynamic relocation for this stub. We only
840 output one PCREL21L reloc per stub, trusting that the
841 dynamic linker will also fix the implied PCREL17R for the
842 second instruction. PCREL21L dynamic relocs had better
843 never be emitted for some other purpose... */
845 Elf_Internal_Rela outrel
;
847 if (stub_entry
->h
== NULL
)
849 (*_bfd_error_handler
)
850 (_("%s(%s+0x%lx): cannot relocate %s, recompile with -ffunction-sections"),
851 bfd_get_filename (stub_entry
->target_section
->owner
),
853 (long) stub_entry
->stub_offset
,
854 stub_entry
->root
.string
);
855 bfd_set_error (bfd_error_bad_value
);
859 srel
= stub_entry
->reloc_sec
;
862 (*_bfd_error_handler
)
863 (_("Could not find relocation section for %s"),
865 bfd_set_error (bfd_error_bad_value
);
869 outrel
.r_offset
= (stub_entry
->stub_offset
870 + stub_sec
->output_offset
871 + stub_sec
->output_section
->vma
);
872 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_PCREL21L
);
873 outrel
.r_addend
= sym_value
;
874 bfd_elf32_swap_reloca_out (stub_sec
->output_section
->owner
,
876 ((Elf32_External_Rela
*)
877 srel
->contents
+ srel
->reloc_count
));
884 case hppa_stub_long_branch_shared
:
885 /* Branches are relative. This is where we are going to. */
886 sym_value
= (stub_entry
->target_value
887 + stub_entry
->target_section
->output_offset
888 + stub_entry
->target_section
->output_section
->vma
);
890 /* And this is where we are coming from, more or less. */
891 sym_value
-= (stub_entry
->stub_offset
892 + stub_sec
->output_offset
893 + stub_sec
->output_section
->vma
);
895 bfd_put_32 (stub_bfd
, (bfd_vma
) BL_R1
, loc
);
896 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_lsel
);
897 insn
= hppa_rebuild_insn ((int) ADDIL_R1
, val
, 21);
898 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
900 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_rsel
) >> 2;
901 insn
= hppa_rebuild_insn ((int) BE_SR4_R1
, val
, 17);
902 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
906 case hppa_stub_import
:
907 case hppa_stub_import_shared
:
908 sym_value
= (stub_entry
->h
->elf
.plt
.offset
909 + hplink
->splt
->output_offset
910 + hplink
->splt
->output_section
->vma
911 - elf_gp (hplink
->splt
->output_section
->owner
));
915 if (stub_entry
->stub_type
== hppa_stub_import_shared
)
918 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_lsel
),
919 insn
= hppa_rebuild_insn ((int) insn
, val
, 21);
920 bfd_put_32 (stub_bfd
, insn
, loc
);
922 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_rsel
);
923 insn
= hppa_rebuild_insn ((int) LDW_R1_R21
, val
, 14);
924 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
926 if (hplink
->multi_subspace
)
928 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 4, e_rsel
);
929 insn
= hppa_rebuild_insn ((int) LDW_R1_DLT
, val
, 14);
930 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
932 bfd_put_32 (stub_bfd
, (bfd_vma
) LDSID_R21_R1
, loc
+ 12);
933 bfd_put_32 (stub_bfd
, (bfd_vma
) MTSP_R1
, loc
+ 16);
934 bfd_put_32 (stub_bfd
, (bfd_vma
) BE_SR0_R21
, loc
+ 20);
935 bfd_put_32 (stub_bfd
, (bfd_vma
) STW_RP
, loc
+ 24);
941 bfd_put_32 (stub_bfd
, (bfd_vma
) BV_R0_R21
, loc
+ 8);
942 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 4, e_rsel
);
943 insn
= hppa_rebuild_insn ((int) LDW_R1_DLT
, val
, 14);
944 bfd_put_32 (stub_bfd
, insn
, loc
+ 12);
950 && stub_entry
->h
!= NULL
951 && stub_entry
->h
->pic_call
)
953 /* Build the .plt entry needed to call a PIC function from
954 statically linked code. We don't need any relocs. */
956 struct elf32_hppa_link_hash_entry
*eh
;
959 dynobj
= hplink
->root
.dynobj
;
960 eh
= (struct elf32_hppa_link_hash_entry
*) stub_entry
->h
;
962 BFD_ASSERT (eh
->elf
.root
.type
== bfd_link_hash_defined
963 || eh
->elf
.root
.type
== bfd_link_hash_defweak
);
965 value
= (eh
->elf
.root
.u
.def
.value
966 + eh
->elf
.root
.u
.def
.section
->output_offset
967 + eh
->elf
.root
.u
.def
.section
->output_section
->vma
);
969 /* Fill in the entry in the procedure linkage table.
971 The format of a plt entry is
975 bfd_put_32 (hplink
->splt
->owner
, value
,
976 hplink
->splt
->contents
+ eh
->elf
.plt
.offset
);
977 value
= elf_gp (hplink
->splt
->output_section
->owner
);
978 bfd_put_32 (hplink
->splt
->owner
, value
,
979 hplink
->splt
->contents
+ eh
->elf
.plt
.offset
+ 4);
983 case hppa_stub_export
:
984 /* Branches are relative. This is where we are going to. */
985 sym_value
= (stub_entry
->target_value
986 + stub_entry
->target_section
->output_offset
987 + stub_entry
->target_section
->output_section
->vma
);
989 /* And this is where we are coming from. */
990 sym_value
-= (stub_entry
->stub_offset
991 + stub_sec
->output_offset
992 + stub_sec
->output_section
->vma
);
994 if (sym_value
- 8 + 0x40000 >= 0x80000)
996 (*_bfd_error_handler
)
997 (_("%s(%s+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
998 bfd_get_filename (stub_entry
->target_section
->owner
),
1000 (long) stub_entry
->stub_offset
,
1001 stub_entry
->root
.string
);
1002 bfd_set_error (bfd_error_bad_value
);
1006 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_fsel
) >> 2;
1007 insn
= hppa_rebuild_insn ((int) BL_RP
, val
, 17);
1008 bfd_put_32 (stub_bfd
, insn
, loc
);
1010 bfd_put_32 (stub_bfd
, (bfd_vma
) NOP
, loc
+ 4);
1011 bfd_put_32 (stub_bfd
, (bfd_vma
) LDW_RP
, loc
+ 8);
1012 bfd_put_32 (stub_bfd
, (bfd_vma
) LDSID_RP_R1
, loc
+ 12);
1013 bfd_put_32 (stub_bfd
, (bfd_vma
) MTSP_R1
, loc
+ 16);
1014 bfd_put_32 (stub_bfd
, (bfd_vma
) BE_SR0_RP
, loc
+ 20);
1016 /* Point the function symbol at the stub. */
1017 stub_entry
->h
->elf
.root
.u
.def
.section
= stub_sec
;
1018 stub_entry
->h
->elf
.root
.u
.def
.value
= stub_sec
->_raw_size
;
1028 stub_sec
->_raw_size
+= size
;
1055 /* As above, but don't actually build the stub. Just bump offset so
1056 we know stub section sizes. */
1059 hppa_size_one_stub (gen_entry
, in_arg
)
1060 struct bfd_hash_entry
*gen_entry
;
1063 struct elf32_hppa_stub_hash_entry
*stub_entry
;
1064 struct elf32_hppa_link_hash_table
*hplink
;
1067 /* Massage our args to the form they really have. */
1068 stub_entry
= (struct elf32_hppa_stub_hash_entry
*) gen_entry
;
1069 hplink
= (struct elf32_hppa_link_hash_table
*) in_arg
;
1071 if (stub_entry
->stub_type
== hppa_stub_long_branch
)
1073 #if ! LONG_BRANCH_PIC_IN_SHLIB
1074 if (stub_entry
->reloc_sec
!= NULL
)
1075 stub_entry
->reloc_sec
->_raw_size
+= sizeof (Elf32_External_Rela
);
1079 else if (stub_entry
->stub_type
== hppa_stub_long_branch_shared
)
1081 else if (stub_entry
->stub_type
== hppa_stub_export
)
1083 else /* hppa_stub_import or hppa_stub_import_shared. */
1085 if (hplink
->multi_subspace
)
1091 stub_entry
->stub_sec
->_raw_size
+= size
;
1096 /* Return nonzero if ABFD represents an HPPA ELF32 file.
1097 Additionally we set the default architecture and machine. */
1100 elf32_hppa_object_p (abfd
)
1103 unsigned int flags
= elf_elfheader (abfd
)->e_flags
;
1105 switch (flags
& (EF_PARISC_ARCH
| EF_PARISC_WIDE
))
1107 case EFA_PARISC_1_0
:
1108 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 10);
1109 case EFA_PARISC_1_1
:
1110 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 11);
1111 case EFA_PARISC_2_0
:
1112 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 20);
1113 case EFA_PARISC_2_0
| EF_PARISC_WIDE
:
1114 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 25);
1120 /* Undo the generic ELF code's subtraction of section->vma from the
1121 value of each external symbol. */
1124 elf32_hppa_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
1125 bfd
*abfd ATTRIBUTE_UNUSED
;
1126 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1127 const Elf_Internal_Sym
*sym ATTRIBUTE_UNUSED
;
1128 const char **namep ATTRIBUTE_UNUSED
;
1129 flagword
*flagsp ATTRIBUTE_UNUSED
;
1133 *valp
+= (*secp
)->vma
;
1138 /* Create the .plt and .got sections, and set up our hash table
1139 short-cuts to various dynamic sections. */
1142 elf32_hppa_create_dynamic_sections (abfd
, info
)
1144 struct bfd_link_info
*info
;
1148 struct elf32_hppa_link_hash_table
*hplink
;
1150 /* Don't try to create the .plt and .got twice. */
1151 hplink
= hppa_link_hash_table (info
);
1152 if (hplink
->splt
!= NULL
)
1155 /* Call the generic code to do most of the work. */
1156 if (! _bfd_elf_create_dynamic_sections (abfd
, info
))
1159 /* Our .plt just contains pointers. I suppose we should be using
1160 .plt.got but .plt.got doesn't make too much sense without a .plt
1161 section. Set the flags to say the .plt isn't executable. */
1162 s
= bfd_get_section_by_name (abfd
, ".plt");
1163 flags
= bfd_get_section_flags (abfd
, s
);
1164 if (! bfd_set_section_flags (abfd
, s
, flags
& ~SEC_CODE
))
1167 hplink
->srelplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
1169 hplink
->sgot
= bfd_get_section_by_name (abfd
, ".got");
1170 hplink
->srelgot
= bfd_make_section (abfd
, ".rela.got");
1171 if (hplink
->srelgot
== NULL
1172 || ! bfd_set_section_flags (abfd
, hplink
->srelgot
,
1177 | SEC_LINKER_CREATED
1179 || ! bfd_set_section_alignment (abfd
, hplink
->srelgot
, 2))
1182 hplink
->sdynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
1183 hplink
->srelbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
1189 /* Look through the relocs for a section during the first phase, and
1190 allocate space in the global offset table or procedure linkage
1191 table. At this point we haven't necessarily read all the input
1195 elf32_hppa_check_relocs (abfd
, info
, sec
, relocs
)
1197 struct bfd_link_info
*info
;
1199 const Elf_Internal_Rela
*relocs
;
1202 Elf_Internal_Shdr
*symtab_hdr
;
1203 struct elf_link_hash_entry
**sym_hashes
;
1204 bfd_signed_vma
*local_got_refcounts
;
1205 const Elf_Internal_Rela
*rel
;
1206 const Elf_Internal_Rela
*rel_end
;
1207 struct elf32_hppa_link_hash_table
*hplink
;
1209 asection
*stubreloc
;
1211 if (info
->relocateable
)
1214 hplink
= hppa_link_hash_table (info
);
1215 dynobj
= hplink
->root
.dynobj
;
1216 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1217 sym_hashes
= elf_sym_hashes (abfd
);
1218 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1222 rel_end
= relocs
+ sec
->reloc_count
;
1223 for (rel
= relocs
; rel
< rel_end
; rel
++)
1229 #if LONG_BRANCH_PIC_IN_SHLIB
1230 NEED_STUBREL
= 0, /* We won't be needing them in this case. */
1237 unsigned int r_symndx
, r_type
;
1238 struct elf32_hppa_link_hash_entry
*h
;
1241 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1243 if (r_symndx
< symtab_hdr
->sh_info
)
1246 h
= ((struct elf32_hppa_link_hash_entry
*)
1247 sym_hashes
[r_symndx
- symtab_hdr
->sh_info
]);
1249 r_type
= ELF32_R_TYPE (rel
->r_info
);
1253 case R_PARISC_DLTIND14F
:
1254 case R_PARISC_DLTIND14R
:
1255 case R_PARISC_DLTIND21L
:
1256 /* This symbol requires a global offset table entry. */
1257 need_entry
= NEED_GOT
;
1259 /* Mark this section as containing PIC code. */
1260 sec
->flags
|= SEC_HAS_GOT_REF
;
1263 case R_PARISC_PLABEL14R
: /* "Official" procedure labels. */
1264 case R_PARISC_PLABEL21L
:
1265 case R_PARISC_PLABEL32
:
1266 /* If the addend is non-zero, we break badly. */
1267 BFD_ASSERT (rel
->r_addend
== 0);
1269 /* If we are creating a shared library, then we need to
1270 create a PLT entry for all PLABELs, because PLABELs with
1271 local symbols may be passed via a pointer to another
1272 object. Additionally, output a dynamic relocation
1273 pointing to the PLT entry. */
1274 need_entry
= PLT_PLABEL
| NEED_PLT
| NEED_DYNREL
;
1277 case R_PARISC_PCREL12F
:
1278 case R_PARISC_PCREL17C
:
1279 case R_PARISC_PCREL17F
:
1280 case R_PARISC_PCREL22F
:
1281 /* Handle calls, and function pointers as they might need to
1282 go through the .plt, and might require long branch stubs. */
1285 /* We know local syms won't need a .plt entry, and if
1286 they need a long branch stub we can't guarantee that
1287 we can reach the stub. So just flag an error later
1288 if we're doing a shared link and find we need a long
1294 /* Global symbols will need a .plt entry if they remain
1295 global, and in most cases won't need a long branch
1296 stub. Unfortunately, we have to cater for the case
1297 where a symbol is forced local by versioning, or due
1298 to symbolic linking, and we lose the .plt entry. */
1299 need_entry
= NEED_PLT
| NEED_STUBREL
;
1303 case R_PARISC_SEGBASE
: /* Used to set segment base. */
1304 case R_PARISC_SEGREL32
: /* Relative reloc. */
1305 case R_PARISC_PCREL14F
: /* PC relative load/store. */
1306 case R_PARISC_PCREL14R
:
1307 case R_PARISC_PCREL17R
: /* External branches. */
1308 case R_PARISC_PCREL21L
: /* As above, and for load/store too. */
1309 /* We don't need to propagate the relocation if linking a
1310 shared object since these are section relative. */
1313 case R_PARISC_DPREL14F
: /* Used for gp rel data load/store. */
1314 case R_PARISC_DPREL14R
:
1315 case R_PARISC_DPREL21L
:
1318 (*_bfd_error_handler
)
1319 (_("%s: relocation %s can not be used when making a shared object; recompile with -fPIC"),
1320 bfd_get_filename (abfd
),
1321 elf_hppa_howto_table
[r_type
].name
);
1322 bfd_set_error (bfd_error_bad_value
);
1327 case R_PARISC_DIR17F
: /* Used for external branches. */
1328 case R_PARISC_DIR17R
:
1329 case R_PARISC_DIR14R
: /* Used for load/store from absolute locn. */
1330 case R_PARISC_DIR21L
: /* As above, and for ext branches too. */
1332 /* Help debug shared library creation. Any of the above
1333 relocs can be used in shared libs, but they may cause
1334 pages to become unshared. */
1337 (*_bfd_error_handler
)
1338 (_("%s: relocation %s should not be used when making a shared object; recompile with -fPIC"),
1339 bfd_get_filename (abfd
),
1340 elf_hppa_howto_table
[r_type
].name
);
1345 case R_PARISC_DIR32
: /* .word, PARISC.unwind relocs. */
1346 /* We may want to output a dynamic relocation later. */
1347 need_entry
= NEED_DYNREL
;
1350 /* This relocation describes the C++ object vtable hierarchy.
1351 Reconstruct it for later use during GC. */
1352 case R_PARISC_GNU_VTINHERIT
:
1353 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
,
1354 &h
->elf
, rel
->r_offset
))
1358 /* This relocation describes which C++ vtable entries are actually
1359 used. Record for later use during GC. */
1360 case R_PARISC_GNU_VTENTRY
:
1361 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
,
1362 &h
->elf
, rel
->r_offset
))
1370 /* Now carry out our orders. */
1371 if (need_entry
& NEED_GOT
)
1373 /* Allocate space for a GOT entry, as well as a dynamic
1374 relocation for this entry. */
1376 hplink
->root
.dynobj
= dynobj
= abfd
;
1378 if (hplink
->sgot
== NULL
)
1380 if (! elf32_hppa_create_dynamic_sections (dynobj
, info
))
1386 if (h
->elf
.got
.refcount
== -1)
1388 h
->elf
.got
.refcount
= 1;
1390 /* Make sure this symbol is output as a dynamic symbol. */
1391 if (h
->elf
.dynindx
== -1)
1393 if (! bfd_elf32_link_record_dynamic_symbol (info
,
1398 hplink
->sgot
->_raw_size
+= GOT_ENTRY_SIZE
;
1399 hplink
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
1402 h
->elf
.got
.refcount
+= 1;
1406 /* This is a global offset table entry for a local symbol. */
1407 if (local_got_refcounts
== NULL
)
1411 /* Allocate space for local got offsets and local
1412 plt offsets. Done this way to save polluting
1413 elf_obj_tdata with another target specific
1415 size
= symtab_hdr
->sh_info
* 2 * sizeof (bfd_signed_vma
);
1416 local_got_refcounts
= ((bfd_signed_vma
*)
1417 bfd_alloc (abfd
, size
));
1418 if (local_got_refcounts
== NULL
)
1420 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1421 memset (local_got_refcounts
, -1, size
);
1423 if (local_got_refcounts
[r_symndx
] == -1)
1425 local_got_refcounts
[r_symndx
] = 1;
1427 hplink
->sgot
->_raw_size
+= GOT_ENTRY_SIZE
;
1430 /* If we are generating a shared object, we need to
1431 output a reloc so that the dynamic linker can
1432 adjust this GOT entry (because the address
1433 the shared library is loaded at is not fixed). */
1434 hplink
->srelgot
->_raw_size
+=
1435 sizeof (Elf32_External_Rela
);
1439 local_got_refcounts
[r_symndx
] += 1;
1443 if (need_entry
& NEED_PLT
)
1445 /* If we are creating a shared library, and this is a reloc
1446 against a weak symbol or a global symbol in a dynamic
1447 object, then we will be creating an import stub and a
1448 .plt entry for the symbol. Similarly, on a normal link
1449 to symbols defined in a dynamic object we'll need the
1450 import stub and a .plt entry. We don't know yet whether
1451 the symbol is defined or not, so make an entry anyway and
1452 clean up later in adjust_dynamic_symbol. */
1453 if ((sec
->flags
& SEC_ALLOC
) != 0)
1457 if (h
->elf
.plt
.refcount
== -1)
1459 h
->elf
.plt
.refcount
= 1;
1460 h
->elf
.elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1463 h
->elf
.plt
.refcount
+= 1;
1465 /* If this .plt entry is for a plabel, we need an
1466 extra word for ld.so. adjust_dynamic_symbol will
1467 also keep the entry even if it appears to be
1469 if (need_entry
& PLT_PLABEL
)
1472 else if (need_entry
& PLT_PLABEL
)
1476 if (local_got_refcounts
== NULL
)
1480 /* Allocate space for local got offsets and local
1482 size
= symtab_hdr
->sh_info
* 2 * sizeof (bfd_signed_vma
);
1483 local_got_refcounts
= ((bfd_signed_vma
*)
1484 bfd_alloc (abfd
, size
));
1485 if (local_got_refcounts
== NULL
)
1487 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1488 memset (local_got_refcounts
, -1, size
);
1490 indx
= r_symndx
+ symtab_hdr
->sh_info
;
1491 if (local_got_refcounts
[indx
] == -1)
1492 local_got_refcounts
[indx
] = 1;
1494 local_got_refcounts
[indx
] += 1;
1499 if (need_entry
& (NEED_DYNREL
| NEED_STUBREL
))
1501 /* Flag this symbol as having a non-got, non-plt reference
1502 so that we generate copy relocs if it turns out to be
1505 h
->elf
.elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
1507 /* If we are creating a shared library then we need to copy
1508 the reloc into the shared library. However, if we are
1509 linking with -Bsymbolic, we need only copy absolute
1510 relocs or relocs against symbols that are not defined in
1511 an object we are including in the link. PC- or DP- or
1512 DLT-relative relocs against any local sym or global sym
1513 with DEF_REGULAR set, can be discarded. At this point we
1514 have not seen all the input files, so it is possible that
1515 DEF_REGULAR is not set now but will be set later (it is
1516 never cleared). We account for that possibility below by
1517 storing information in the reloc_entries field of the
1520 A similar situation to the -Bsymbolic case occurs when
1521 creating shared libraries and symbol visibility changes
1522 render the symbol local.
1524 As it turns out, all the relocs we will be creating here
1525 are absolute, so we cannot remove them on -Bsymbolic
1526 links or visibility changes anyway. A STUB_REL reloc
1527 is absolute too, as in that case it is the reloc in the
1528 stub we will be creating, rather than copying the PCREL
1529 reloc in the branch. */
1530 if ((sec
->flags
& SEC_ALLOC
) != 0
1532 #if RELATIVE_DYNAMIC_RELOCS
1534 || is_absolute_reloc (r_type
)
1536 && ((h
->elf
.elf_link_hash_flags
1537 & ELF_LINK_HASH_DEF_REGULAR
) == 0
1538 || h
->elf
.root
.type
== bfd_link_hash_defweak
)))
1546 if ((need_entry
& NEED_STUBREL
))
1549 /* Create a reloc section in dynobj and make room for
1556 hplink
->root
.dynobj
= dynobj
= abfd
;
1558 name
= bfd_elf_string_from_elf_section
1560 elf_elfheader (abfd
)->e_shstrndx
,
1561 elf_section_data (sec
)->rel_hdr
.sh_name
);
1564 (*_bfd_error_handler
)
1565 (_("Could not find relocation section for %s"),
1567 bfd_set_error (bfd_error_bad_value
);
1571 if ((need_entry
& NEED_STUBREL
))
1573 size_t len
= strlen (name
) + sizeof (STUB_SUFFIX
);
1574 char *newname
= bfd_malloc (len
);
1576 if (newname
== NULL
)
1578 strcpy (newname
, name
);
1579 strcpy (newname
+ len
- sizeof (STUB_SUFFIX
),
1584 srel
= bfd_get_section_by_name (dynobj
, name
);
1589 srel
= bfd_make_section (dynobj
, name
);
1590 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
1591 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1592 if ((sec
->flags
& SEC_ALLOC
) != 0)
1593 flags
|= SEC_ALLOC
| SEC_LOAD
;
1595 || !bfd_set_section_flags (dynobj
, srel
, flags
)
1596 || !bfd_set_section_alignment (dynobj
, srel
, 2))
1599 else if ((need_entry
& NEED_STUBREL
))
1602 if ((need_entry
& NEED_STUBREL
))
1608 #if ! LONG_BRANCH_PIC_IN_SHLIB
1609 /* If this is a function call, we only need one dynamic
1610 reloc for the stub as all calls to a particular
1611 function will go through the same stub. Actually, a
1612 long branch stub needs two relocations, but we count
1613 on some intelligence on the part of the dynamic
1615 if ((need_entry
& NEED_STUBREL
))
1617 doit
= h
->stub_reloc_sec
!= stubreloc
;
1618 h
->stub_reloc_sec
= stubreloc
;
1626 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
1628 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
1629 /* Keep track of relocations we have entered for
1630 this global symbol, so that we can discard them
1631 later if necessary. */
1634 #if RELATIVE_DYNAMIC_RELOCS
1635 || ! is_absolute_reloc (rtype
)
1637 || (need_entry
& NEED_STUBREL
)))
1639 struct elf32_hppa_dyn_reloc_entry
*p
;
1641 for (p
= h
->reloc_entries
; p
!= NULL
; p
= p
->next
)
1642 if (p
->section
== srel
)
1647 p
= ((struct elf32_hppa_dyn_reloc_entry
*)
1648 bfd_alloc (dynobj
, sizeof *p
));
1651 p
->next
= h
->reloc_entries
;
1652 h
->reloc_entries
= p
;
1657 /* NEED_STUBREL and NEED_DYNREL are never both
1658 set. Leave the count at zero for the
1659 NEED_STUBREL case as we only ever have one
1660 stub reloc per section per symbol, and this
1661 simplifies code in hppa_discard_copies. */
1662 if (! (need_entry
& NEED_STUBREL
))
1675 /* Return the section that should be marked against garbage collection
1676 for a given relocation. */
1679 elf32_hppa_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
1681 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1682 Elf_Internal_Rela
*rel
;
1683 struct elf_link_hash_entry
*h
;
1684 Elf_Internal_Sym
*sym
;
1688 switch ((unsigned int) ELF32_R_TYPE (rel
->r_info
))
1690 case R_PARISC_GNU_VTINHERIT
:
1691 case R_PARISC_GNU_VTENTRY
:
1695 switch (h
->root
.type
)
1697 case bfd_link_hash_defined
:
1698 case bfd_link_hash_defweak
:
1699 return h
->root
.u
.def
.section
;
1701 case bfd_link_hash_common
:
1702 return h
->root
.u
.c
.p
->section
;
1711 if (!(elf_bad_symtab (abfd
)
1712 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
1713 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
1714 && sym
->st_shndx
!= SHN_COMMON
))
1716 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
1724 /* Update the got and plt entry reference counts for the section being
1728 elf32_hppa_gc_sweep_hook (abfd
, info
, sec
, relocs
)
1730 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1732 const Elf_Internal_Rela
*relocs
;
1734 Elf_Internal_Shdr
*symtab_hdr
;
1735 struct elf_link_hash_entry
**sym_hashes
;
1736 bfd_signed_vma
*local_got_refcounts
;
1737 bfd_signed_vma
*local_plt_refcounts
;
1738 const Elf_Internal_Rela
*rel
, *relend
;
1739 unsigned long r_symndx
;
1740 struct elf_link_hash_entry
*h
;
1741 struct elf32_hppa_link_hash_table
*hplink
;
1746 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1747 sym_hashes
= elf_sym_hashes (abfd
);
1748 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1749 local_plt_refcounts
= local_got_refcounts
;
1750 if (local_plt_refcounts
!= NULL
)
1751 local_plt_refcounts
+= symtab_hdr
->sh_info
;
1752 hplink
= hppa_link_hash_table (info
);
1753 dynobj
= hplink
->root
.dynobj
;
1757 sgot
= hplink
->sgot
;
1758 srelgot
= hplink
->srelgot
;
1760 relend
= relocs
+ sec
->reloc_count
;
1761 for (rel
= relocs
; rel
< relend
; rel
++)
1762 switch ((unsigned int) ELF32_R_TYPE (rel
->r_info
))
1764 case R_PARISC_DLTIND14F
:
1765 case R_PARISC_DLTIND14R
:
1766 case R_PARISC_DLTIND21L
:
1767 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1768 if (r_symndx
>= symtab_hdr
->sh_info
)
1770 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1771 if (h
->got
.refcount
> 0)
1773 h
->got
.refcount
-= 1;
1774 if (h
->got
.refcount
== 0)
1776 sgot
->_raw_size
-= GOT_ENTRY_SIZE
;
1777 srelgot
->_raw_size
-= sizeof (Elf32_External_Rela
);
1781 else if (local_got_refcounts
!= NULL
)
1783 if (local_got_refcounts
[r_symndx
] > 0)
1785 local_got_refcounts
[r_symndx
] -= 1;
1786 if (local_got_refcounts
[r_symndx
] == 0)
1788 sgot
->_raw_size
-= GOT_ENTRY_SIZE
;
1790 srelgot
->_raw_size
-= sizeof (Elf32_External_Rela
);
1796 case R_PARISC_PCREL12F
:
1797 case R_PARISC_PCREL17C
:
1798 case R_PARISC_PCREL17F
:
1799 case R_PARISC_PCREL22F
:
1800 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1801 if (r_symndx
>= symtab_hdr
->sh_info
)
1803 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1804 if (h
->plt
.refcount
> 0)
1805 h
->plt
.refcount
-= 1;
1809 case R_PARISC_PLABEL14R
:
1810 case R_PARISC_PLABEL21L
:
1811 case R_PARISC_PLABEL32
:
1812 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1813 if (r_symndx
>= symtab_hdr
->sh_info
)
1815 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1816 if (h
->plt
.refcount
> 0)
1817 h
->plt
.refcount
-= 1;
1819 else if (local_plt_refcounts
!= NULL
)
1821 if (local_plt_refcounts
[r_symndx
] > 0)
1822 local_plt_refcounts
[r_symndx
] -= 1;
1834 /* Our own version of hide_symbol, so that we can keep plt entries for
1838 elf32_hppa_hide_symbol (info
, h
)
1839 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1840 struct elf_link_hash_entry
*h
;
1843 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
)
1845 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1846 h
->plt
.offset
= (bfd_vma
) -1;
1851 /* Adjust a symbol defined by a dynamic object and referenced by a
1852 regular object. The current definition is in some section of the
1853 dynamic object, but we're not including those sections. We have to
1854 change the definition to something the rest of the link can
1858 elf32_hppa_adjust_dynamic_symbol (info
, h
)
1859 struct bfd_link_info
*info
;
1860 struct elf_link_hash_entry
*h
;
1863 struct elf32_hppa_link_hash_table
*hplink
;
1866 hplink
= hppa_link_hash_table (info
);
1867 dynobj
= hplink
->root
.dynobj
;
1869 /* If this is a function, put it in the procedure linkage table. We
1870 will fill in the contents of the procedure linkage table later,
1871 when we know the address of the .got section. */
1872 if (h
->type
== STT_FUNC
1873 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1875 if (h
->plt
.refcount
<= 0
1876 || ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
1877 && h
->root
.type
!= bfd_link_hash_defweak
1878 && ! ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
1879 && (!info
->shared
|| info
->symbolic
)))
1881 /* The .plt entry is not needed when:
1882 a) Garbage collection has removed all references to the
1884 b) We know for certain the symbol is defined in this
1885 object, and it's not a weak definition, nor is the symbol
1886 used by a plabel relocation. Either this object is the
1887 application or we are doing a shared symbolic link. */
1889 /* As a special sop to the hppa ABI, we keep a .plt entry
1890 for functions in sections containing PIC code. */
1892 && h
->plt
.refcount
> 0
1893 && (h
->root
.type
== bfd_link_hash_defined
1894 || h
->root
.type
== bfd_link_hash_defweak
)
1895 && (h
->root
.u
.def
.section
->flags
& SEC_HAS_GOT_REF
) != 0)
1897 ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
= 1;
1901 h
->plt
.offset
= (bfd_vma
) -1;
1902 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1907 /* Make an entry in the .plt section. */
1909 h
->plt
.offset
= s
->_raw_size
;
1910 if (PLABEL_PLT_ENTRY_SIZE
!= PLT_ENTRY_SIZE
1911 && ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
1912 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1914 /* Add some extra space for the dynamic linker to use. */
1915 s
->_raw_size
+= PLABEL_PLT_ENTRY_SIZE
;
1918 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1920 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
)
1922 /* Make sure this symbol is output as a dynamic symbol. */
1923 if (h
->dynindx
== -1
1924 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1926 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1930 /* We also need to make an entry in the .rela.plt section. */
1931 s
= hplink
->srelplt
;
1932 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
1937 /* If this is a weak symbol, and there is a real definition, the
1938 processor independent code will have arranged for us to see the
1939 real definition first, and we can just use the same value. */
1940 if (h
->weakdef
!= NULL
)
1942 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
1943 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
1944 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1945 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1949 /* This is a reference to a symbol defined by a dynamic object which
1950 is not a function. */
1952 /* If we are creating a shared library, we must presume that the
1953 only references to the symbol are via the global offset table.
1954 For such cases we need not do anything here; the relocations will
1955 be handled correctly by relocate_section. */
1959 /* If there are no references to this symbol that do not use the
1960 GOT, we don't need to generate a copy reloc. */
1961 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
1964 /* We must allocate the symbol in our .dynbss section, which will
1965 become part of the .bss section of the executable. There will be
1966 an entry for this symbol in the .dynsym section. The dynamic
1967 object will contain position independent code, so all references
1968 from the dynamic object to this symbol will go through the global
1969 offset table. The dynamic linker will use the .dynsym entry to
1970 determine the address it must put in the global offset table, so
1971 both the dynamic object and the regular object will refer to the
1972 same memory location for the variable. */
1974 s
= hplink
->sdynbss
;
1976 /* We must generate a COPY reloc to tell the dynamic linker to
1977 copy the initial value out of the dynamic object and into the
1978 runtime process image. We need to remember the offset into the
1979 .rela.bss section we are going to use. */
1980 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1984 srel
= hplink
->srelbss
;
1985 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
1986 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
1990 /* We need to figure out the alignment required for this symbol. I
1991 have no idea how other ELF linkers handle this. */
1992 unsigned int power_of_two
;
1994 power_of_two
= bfd_log2 (h
->size
);
1995 if (power_of_two
> 3)
1998 /* Apply the required alignment. */
1999 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
2000 (bfd_size_type
) (1 << power_of_two
));
2001 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
2003 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
2007 /* Define the symbol as being at this point in the section. */
2008 h
->root
.u
.def
.section
= s
;
2009 h
->root
.u
.def
.value
= s
->_raw_size
;
2011 /* Increment the section size to make room for the symbol. */
2012 s
->_raw_size
+= h
->size
;
2018 /* Called via elf_link_hash_traverse to create .plt entries for an
2019 application that uses statically linked PIC functions. Similar to
2020 the first part of elf32_hppa_adjust_dynamic_symbol. */
2023 hppa_handle_PIC_calls (h
, inf
)
2024 struct elf_link_hash_entry
*h
;
2027 struct bfd_link_info
*info
;
2029 struct elf32_hppa_link_hash_table
*hplink
;
2032 if (! (h
->plt
.refcount
> 0
2033 && (h
->root
.type
== bfd_link_hash_defined
2034 || h
->root
.type
== bfd_link_hash_defweak
)
2035 && (h
->root
.u
.def
.section
->flags
& SEC_HAS_GOT_REF
) != 0))
2037 h
->plt
.offset
= (bfd_vma
) -1;
2038 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2042 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2043 ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
= 1;
2045 info
= (struct bfd_link_info
*) inf
;
2046 hplink
= hppa_link_hash_table (info
);
2047 dynobj
= hplink
->root
.dynobj
;
2049 /* Make an entry in the .plt section. */
2051 h
->plt
.offset
= s
->_raw_size
;
2052 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2058 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
2059 || RELATIVE_DYNAMIC_RELOCS)
2060 /* This function is called via elf_link_hash_traverse to discard space
2061 we allocated for relocs that it turned out we didn't need. */
2064 hppa_discard_copies (h
, inf
)
2065 struct elf_link_hash_entry
*h
;
2068 struct elf32_hppa_dyn_reloc_entry
*s
;
2069 struct elf32_hppa_link_hash_entry
*eh
;
2070 struct bfd_link_info
*info
;
2072 eh
= (struct elf32_hppa_link_hash_entry
*) h
;
2073 info
= (struct bfd_link_info
*) inf
;
2075 #if ! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT
2076 /* Handle the stub reloc case. If we have a plt entry for the
2077 function, we won't be needing long branch stubs. s->count will
2078 only be zero for stub relocs, which provides a handy way of
2079 flagging these relocs, and means we need do nothing special for
2080 the forced local and symbolic link case. */
2081 if (eh
->stub_reloc_sec
!= NULL
2082 && eh
->elf
.plt
.offset
!= (bfd_vma
) -1)
2084 for (s
= eh
->reloc_entries
; s
!= NULL
; s
= s
->next
)
2086 s
->section
->_raw_size
-= sizeof (Elf32_External_Rela
);
2090 #if RELATIVE_DYNAMIC_RELOCS
2091 /* If a symbol has been forced local or we have found a regular
2092 definition for the symbolic link case, then we won't be needing
2094 if (eh
->elf
.dynindx
== -1
2095 || ((eh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
2096 && eh
->elf
.root
.type
!= bfd_link_hash_defweak
2099 for (s
= eh
->reloc_entries
; s
!= NULL
; s
= s
->next
)
2100 s
->section
->_raw_size
-= s
->count
* sizeof (Elf32_External_Rela
);
2109 /* This function is called via elf_link_hash_traverse to force
2110 millicode symbols local so they do not end up as globals in the
2111 dynamic symbol table. We ought to be able to do this in
2112 adjust_dynamic_symbol, but our adjust_dynamic_symbol is not called
2113 for all dynamic symbols. Arguably, this is a bug in
2114 elf_adjust_dynamic_symbol. */
2117 clobber_millicode_symbols (h
, info
)
2118 struct elf_link_hash_entry
*h
;
2119 struct bfd_link_info
*info
;
2121 if (h
->type
== STT_PARISC_MILLI
)
2123 h
->elf_link_hash_flags
|= ELF_LINK_FORCED_LOCAL
;
2124 elf32_hppa_hide_symbol(info
, h
);
2130 /* Set the sizes of the dynamic sections. */
2133 elf32_hppa_size_dynamic_sections (output_bfd
, info
)
2135 struct bfd_link_info
*info
;
2137 struct elf32_hppa_link_hash_table
*hplink
;
2143 hplink
= hppa_link_hash_table (info
);
2144 dynobj
= hplink
->root
.dynobj
;
2145 BFD_ASSERT (dynobj
!= NULL
);
2147 if (hplink
->root
.dynamic_sections_created
)
2149 const char *funcname
;
2152 /* Set the contents of the .interp section to the interpreter. */
2155 s
= bfd_get_section_by_name (dynobj
, ".interp");
2156 BFD_ASSERT (s
!= NULL
);
2157 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2158 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2161 /* Force millicode symbols local. */
2162 elf_link_hash_traverse (&hplink
->root
,
2163 clobber_millicode_symbols
,
2166 /* DT_INIT and DT_FINI need a .plt entry. Make sure they have
2168 funcname
= info
->init_function
;
2171 if (funcname
!= NULL
)
2173 struct elf_link_hash_entry
*h
;
2175 h
= elf_link_hash_lookup (&hplink
->root
,
2177 false, false, false);
2179 && (h
->elf_link_hash_flags
& (ELF_LINK_HASH_REF_REGULAR
2180 | ELF_LINK_HASH_DEF_REGULAR
)))
2182 if (h
->plt
.refcount
<= 0)
2184 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2186 /* Make an entry in the .plt section. We know
2187 the function doesn't have a plabel by the
2190 h
->plt
.offset
= s
->_raw_size
;
2191 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2193 /* Make sure this symbol is output as a dynamic
2195 if (h
->dynindx
== -1)
2197 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
2201 /* Make an entry for the reloc too. */
2202 s
= hplink
->srelplt
;
2203 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
2206 ((struct elf32_hppa_link_hash_entry
*) h
)->plt_abs
= 1;
2209 if (funcname
== info
->fini_function
)
2211 funcname
= info
->fini_function
;
2214 /* Set up .plt offsets for local plabels. */
2215 for (i
= info
->input_bfds
; i
; i
= i
->link_next
)
2217 bfd_signed_vma
*local_plt
;
2218 bfd_signed_vma
*end_local_plt
;
2219 bfd_size_type locsymcount
;
2220 Elf_Internal_Shdr
*symtab_hdr
;
2222 local_plt
= elf_local_got_refcounts (i
);
2226 symtab_hdr
= &elf_tdata (i
)->symtab_hdr
;
2227 locsymcount
= symtab_hdr
->sh_info
;
2228 local_plt
+= locsymcount
;
2229 end_local_plt
= local_plt
+ locsymcount
;
2231 for (; local_plt
< end_local_plt
; ++local_plt
)
2236 *local_plt
= s
->_raw_size
;
2237 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2239 hplink
->srelplt
->_raw_size
+= sizeof (Elf32_External_Rela
);
2242 *local_plt
= (bfd_vma
) -1;
2248 /* Run through the function symbols, looking for any that are
2249 PIC, and allocate space for the necessary .plt entries so
2250 that %r19 will be set up. */
2252 elf_link_hash_traverse (&hplink
->root
,
2253 hppa_handle_PIC_calls
,
2256 /* We may have created entries in the .rela.got section.
2257 However, if we are not creating the dynamic sections, we will
2258 not actually use these entries. Reset the size of .rela.got,
2259 which will cause it to get stripped from the output file
2261 hplink
->srelgot
->_raw_size
= 0;
2264 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
2265 || RELATIVE_DYNAMIC_RELOCS)
2266 /* If this is a -Bsymbolic shared link, then we need to discard all
2267 relocs against symbols defined in a regular object. We also need
2268 to lose relocs we've allocated for long branch stubs if we know
2269 we won't be generating a stub. */
2271 elf_link_hash_traverse (&hplink
->root
,
2272 hppa_discard_copies
,
2276 /* The check_relocs and adjust_dynamic_symbol entry points have
2277 determined the sizes of the various dynamic sections. Allocate
2281 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2285 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2288 /* It's OK to base decisions on the section name, because none
2289 of the dynobj section names depend upon the input files. */
2290 name
= bfd_get_section_name (dynobj
, s
);
2292 if (strncmp (name
, ".rela", 5) == 0)
2294 if (s
->_raw_size
!= 0)
2298 /* Remember whether there are any reloc sections other
2300 if (strcmp (name
+5, ".plt") != 0)
2302 const char *outname
;
2306 /* If this relocation section applies to a read only
2307 section, then we probably need a DT_TEXTREL
2308 entry. The entries in the .rela.plt section
2309 really apply to the .got section, which we
2310 created ourselves and so know is not readonly. */
2311 outname
= bfd_get_section_name (output_bfd
,
2313 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
2315 && (target
->flags
& SEC_READONLY
) != 0
2316 && (target
->flags
& SEC_ALLOC
) != 0)
2320 /* We use the reloc_count field as a counter if we need
2321 to copy relocs into the output file. */
2325 else if (strcmp (name
, ".plt") == 0)
2327 else if (strcmp (name
, ".got") == 0)
2331 /* It's not one of our sections, so don't allocate space. */
2335 if (s
->_raw_size
== 0)
2337 /* If we don't need this section, strip it from the
2338 output file. This is mostly to handle .rela.bss and
2339 .rela.plt. We must create both sections in
2340 create_dynamic_sections, because they must be created
2341 before the linker maps input sections to output
2342 sections. The linker does that before
2343 adjust_dynamic_symbol is called, and it is that
2344 function which decides whether anything needs to go
2345 into these sections. */
2346 _bfd_strip_section_from_output (info
, s
);
2350 /* Allocate memory for the section contents. Zero it, because
2351 we may not fill in all the reloc sections. */
2352 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
2353 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
2357 if (hplink
->root
.dynamic_sections_created
)
2359 /* Like IA-64 and HPPA64, always create a DT_PLTGOT. It
2360 actually has nothing to do with the PLT, it is how we
2361 communicate the LTP value of a load module to the dynamic
2363 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
2366 /* Add some entries to the .dynamic section. We fill in the
2367 values later, in elf32_hppa_finish_dynamic_sections, but we
2368 must add the entries now so that we get the correct size for
2369 the .dynamic section. The DT_DEBUG entry is filled in by the
2370 dynamic linker and used by the debugger. */
2373 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
2377 if (hplink
->srelplt
->_raw_size
!= 0)
2379 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
2380 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
2381 || ! bfd_elf32_add_dynamic_entry (info
, DT_JMPREL
, 0))
2387 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELA
, 0)
2388 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELASZ
, 0)
2389 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELAENT
,
2390 sizeof (Elf32_External_Rela
)))
2396 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
2398 info
->flags
|= DF_TEXTREL
;
2406 /* External entry points for sizing and building linker stubs. */
2408 /* Determine and set the size of the stub section for a final link.
2410 The basic idea here is to examine all the relocations looking for
2411 PC-relative calls to a target that is unreachable with a "bl"
2415 elf32_hppa_size_stubs (stub_bfd
, multi_subspace
, info
,
2416 add_stub_section
, layout_sections_again
)
2418 boolean multi_subspace
;
2419 struct bfd_link_info
*info
;
2420 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
2421 void (*layout_sections_again
) PARAMS ((void));
2425 Elf_Internal_Sym
*local_syms
, **all_local_syms
;
2426 unsigned int i
, indx
, bfd_count
, sec_count
;
2427 struct elf32_hppa_link_hash_table
*hplink
;
2428 boolean stub_changed
= 0;
2430 hplink
= hppa_link_hash_table (info
);
2432 /* Stash our params away. */
2433 hplink
->stub_bfd
= stub_bfd
;
2434 hplink
->multi_subspace
= multi_subspace
;
2435 hplink
->add_stub_section
= add_stub_section
;
2436 hplink
->layout_sections_again
= layout_sections_again
;
2438 /* Count the number of input BFDs and the total number of input sections. */
2439 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, sec_count
= 0;
2441 input_bfd
= input_bfd
->link_next
)
2444 sec_count
+= input_bfd
->section_count
;
2447 hplink
->stub_section_created
2448 = (asection
**) bfd_zmalloc (sizeof (asection
*) * sec_count
);
2449 if (hplink
->stub_section_created
== NULL
)
2452 #if ! LONG_BRANCH_PIC_IN_SHLIB
2453 hplink
->reloc_section_created
2454 = (asection
**) bfd_zmalloc (sizeof (asection
*) * sec_count
);
2455 if (hplink
->reloc_section_created
== NULL
)
2456 goto error_ret_free_stub
;
2459 /* We want to read in symbol extension records only once. To do this
2460 we need to read in the local symbols in parallel and save them for
2461 later use; so hold pointers to the local symbols in an array. */
2463 = (Elf_Internal_Sym
**) bfd_zmalloc (sizeof (Elf_Internal_Sym
*)
2465 if (all_local_syms
== NULL
)
2466 goto error_ret_free_reloc
;
2468 /* Walk over all the input BFDs, swapping in local symbols.
2469 If we are creating a shared library, create hash entries for the
2471 for (input_bfd
= info
->input_bfds
, indx
= 0, sec_count
= 0;
2473 input_bfd
= input_bfd
->link_next
, indx
++)
2475 Elf_Internal_Shdr
*symtab_hdr
;
2476 Elf_Internal_Sym
*isym
;
2477 Elf32_External_Sym
*ext_syms
, *esym
;
2479 /* We'll need the symbol table in a second. */
2480 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2481 if (symtab_hdr
->sh_info
== 0)
2484 /* We need an array of the local symbols attached to the input bfd.
2485 Unfortunately, we're going to have to read & swap them in. */
2486 local_syms
= (Elf_Internal_Sym
*)
2487 bfd_malloc (symtab_hdr
->sh_info
* sizeof (Elf_Internal_Sym
));
2488 if (local_syms
== NULL
)
2490 goto error_ret_free_local
;
2492 all_local_syms
[indx
] = local_syms
;
2493 ext_syms
= (Elf32_External_Sym
*)
2494 bfd_malloc (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
));
2495 if (ext_syms
== NULL
)
2497 goto error_ret_free_local
;
2500 if (bfd_seek (input_bfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
2501 || (bfd_read (ext_syms
, 1,
2502 (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
)),
2504 != (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
))))
2507 goto error_ret_free_local
;
2510 /* Swap the local symbols in. */
2513 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++, esym
++, isym
++)
2514 bfd_elf32_swap_symbol_in (input_bfd
, esym
, isym
);
2516 /* Now we can free the external symbols. */
2519 /* Go looking for .init and .fini sections. We only want one
2520 stub section for each of .init* and .fini* because glibc
2521 splits the _init and _fini functions into multiple parts, and
2522 putting a stub in the middle of a function is not a good idea.
2523 It would be better to merge all the stub sections for an
2524 output section if the output section + stubs is small enough.
2525 This would fix the .init and .fini case and also allow stubs
2526 to be merged. It's more linker work though. */
2527 for (section
= input_bfd
->sections
;
2529 section
= section
->next
, sec_count
++)
2531 if (hplink
->first_init_sec
== 0)
2533 if (strncmp (section
->name
, ".init", 5) == 0)
2534 hplink
->first_init_sec
= sec_count
+ 1;
2536 if (hplink
->first_fini_sec
== 0)
2538 if (strncmp (section
->name
, ".fini", 5) == 0)
2539 hplink
->first_fini_sec
= sec_count
+ 1;
2542 #if ! LONG_BRANCH_PIC_IN_SHLIB
2543 /* If this is a shared link, find all the stub reloc
2548 asection
*reloc_sec
;
2550 name
= bfd_malloc (strlen (section
->name
)
2551 + sizeof STUB_SUFFIX
2555 sprintf (name
, ".rela%s%s", section
->name
, STUB_SUFFIX
);
2556 reloc_sec
= bfd_get_section_by_name (hplink
->root
.dynobj
, name
);
2557 hplink
->reloc_section_created
[sec_count
] = reloc_sec
;
2563 if (info
->shared
&& hplink
->multi_subspace
)
2565 unsigned int symndx
;
2566 unsigned int symcount
;
2568 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
2569 - symtab_hdr
->sh_info
);
2571 /* Look through the global syms for functions; We need to
2572 build export stubs for all globally visible functions. */
2573 for (symndx
= 0; symndx
< symcount
; symndx
++)
2575 struct elf32_hppa_link_hash_entry
*hash
;
2577 hash
= ((struct elf32_hppa_link_hash_entry
*)
2578 elf_sym_hashes (input_bfd
)[symndx
]);
2580 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
2581 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
2582 hash
= ((struct elf32_hppa_link_hash_entry
*)
2583 hash
->elf
.root
.u
.i
.link
);
2585 /* At this point in the link, undefined syms have been
2586 resolved, so we need to check that the symbol was
2587 defined in this BFD. */
2588 if ((hash
->elf
.root
.type
== bfd_link_hash_defined
2589 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
2590 && hash
->elf
.type
== STT_FUNC
2591 && hash
->elf
.root
.u
.def
.section
->output_section
!= NULL
2592 && hash
->elf
.root
.u
.def
.section
->owner
== input_bfd
2593 && (hash
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
2594 && !(hash
->elf
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
2595 && ELF_ST_VISIBILITY (hash
->elf
.other
) == STV_DEFAULT
)
2598 const char *stub_name
;
2599 struct elf32_hppa_stub_hash_entry
*stub_entry
;
2601 sec
= hash
->elf
.root
.u
.def
.section
;
2602 stub_name
= hash
->elf
.root
.root
.string
;
2603 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
,
2606 if (stub_entry
== NULL
)
2608 stub_entry
= hppa_add_stub (stub_name
,
2610 (sec_count
+ sec
->index
2611 - input_bfd
->section_count
),
2614 goto error_ret_free_local
;
2616 stub_entry
->target_value
= hash
->elf
.root
.u
.def
.value
;
2617 stub_entry
->target_section
= hash
->elf
.root
.u
.def
.section
;
2618 stub_entry
->stub_type
= hppa_stub_export
;
2619 stub_entry
->h
= hash
;
2624 (*_bfd_error_handler
) (_("%s: duplicate export stub %s"),
2625 bfd_get_filename (input_bfd
),
2637 for (input_bfd
= info
->input_bfds
, indx
= 0, sec_count
= 0;
2639 input_bfd
= input_bfd
->link_next
, indx
++)
2641 Elf_Internal_Shdr
*symtab_hdr
;
2643 /* We'll need the symbol table in a second. */
2644 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2645 if (symtab_hdr
->sh_info
== 0)
2648 local_syms
= all_local_syms
[indx
];
2650 /* Walk over each section attached to the input bfd. */
2651 for (section
= input_bfd
->sections
;
2653 section
= section
->next
, sec_count
++)
2655 Elf_Internal_Shdr
*input_rel_hdr
;
2656 Elf32_External_Rela
*external_relocs
, *erelaend
, *erela
;
2657 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
2659 /* If there aren't any relocs, then there's nothing more
2661 if ((section
->flags
& SEC_RELOC
) == 0
2662 || section
->reloc_count
== 0)
2665 /* Allocate space for the external relocations. */
2667 = ((Elf32_External_Rela
*)
2668 bfd_malloc (section
->reloc_count
2669 * sizeof (Elf32_External_Rela
)));
2670 if (external_relocs
== NULL
)
2672 goto error_ret_free_local
;
2675 /* Likewise for the internal relocations. */
2676 internal_relocs
= ((Elf_Internal_Rela
*)
2677 bfd_malloc (section
->reloc_count
2678 * sizeof (Elf_Internal_Rela
)));
2679 if (internal_relocs
== NULL
)
2681 free (external_relocs
);
2682 goto error_ret_free_local
;
2685 /* Read in the external relocs. */
2686 input_rel_hdr
= &elf_section_data (section
)->rel_hdr
;
2687 if (bfd_seek (input_bfd
, input_rel_hdr
->sh_offset
, SEEK_SET
) != 0
2688 || bfd_read (external_relocs
, 1,
2689 input_rel_hdr
->sh_size
,
2690 input_bfd
) != input_rel_hdr
->sh_size
)
2692 free (external_relocs
);
2693 error_ret_free_internal
:
2694 free (internal_relocs
);
2695 goto error_ret_free_local
;
2698 /* Swap in the relocs. */
2699 erela
= external_relocs
;
2700 erelaend
= erela
+ section
->reloc_count
;
2701 irela
= internal_relocs
;
2702 for (; erela
< erelaend
; erela
++, irela
++)
2703 bfd_elf32_swap_reloca_in (input_bfd
, erela
, irela
);
2705 /* We're done with the external relocs, free them. */
2706 free (external_relocs
);
2708 /* Now examine each relocation. */
2709 irela
= internal_relocs
;
2710 irelaend
= irela
+ section
->reloc_count
;
2711 for (; irela
< irelaend
; irela
++)
2713 unsigned int r_type
, r_indx
;
2714 enum elf32_hppa_stub_type stub_type
;
2715 struct elf32_hppa_stub_hash_entry
*stub_entry
;
2718 bfd_vma destination
;
2719 struct elf32_hppa_link_hash_entry
*hash
;
2722 r_type
= ELF32_R_TYPE (irela
->r_info
);
2723 r_indx
= ELF32_R_SYM (irela
->r_info
);
2725 if (r_type
>= (unsigned int) R_PARISC_UNIMPLEMENTED
)
2727 bfd_set_error (bfd_error_bad_value
);
2728 goto error_ret_free_internal
;
2731 /* Only look for stubs on call instructions. */
2732 if (r_type
!= (unsigned int) R_PARISC_PCREL12F
2733 && r_type
!= (unsigned int) R_PARISC_PCREL17F
2734 && r_type
!= (unsigned int) R_PARISC_PCREL22F
)
2737 /* Now determine the call target, its name, value,
2743 if (r_indx
< symtab_hdr
->sh_info
)
2745 /* It's a local symbol. */
2746 Elf_Internal_Sym
*sym
;
2747 Elf_Internal_Shdr
*hdr
;
2749 sym
= local_syms
+ r_indx
;
2750 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
2751 sym_sec
= hdr
->bfd_section
;
2752 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
2753 sym_value
= sym
->st_value
;
2754 destination
= (sym_value
+ irela
->r_addend
2755 + sym_sec
->output_offset
2756 + sym_sec
->output_section
->vma
);
2760 /* It's an external symbol. */
2763 e_indx
= r_indx
- symtab_hdr
->sh_info
;
2764 hash
= ((struct elf32_hppa_link_hash_entry
*)
2765 elf_sym_hashes (input_bfd
)[e_indx
]);
2767 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
2768 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
2769 hash
= ((struct elf32_hppa_link_hash_entry
*)
2770 hash
->elf
.root
.u
.i
.link
);
2772 if (hash
->elf
.root
.type
== bfd_link_hash_defined
2773 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
2775 sym_sec
= hash
->elf
.root
.u
.def
.section
;
2776 sym_value
= hash
->elf
.root
.u
.def
.value
;
2777 if (sym_sec
->output_section
!= NULL
)
2778 destination
= (sym_value
+ irela
->r_addend
2779 + sym_sec
->output_offset
2780 + sym_sec
->output_section
->vma
);
2782 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
)
2787 else if (hash
->elf
.root
.type
== bfd_link_hash_undefined
)
2790 && !info
->no_undefined
2791 && (ELF_ST_VISIBILITY (hash
->elf
.other
)
2797 bfd_set_error (bfd_error_bad_value
);
2798 goto error_ret_free_internal
;
2802 /* Determine what (if any) linker stub is needed. */
2803 stub_type
= hppa_type_of_stub (section
, irela
, hash
,
2805 if (stub_type
== hppa_stub_none
)
2808 /* Get the name of this stub. */
2809 stub_name
= hppa_stub_name (section
, sym_sec
, hash
, irela
);
2811 goto error_ret_free_internal
;
2813 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
,
2816 if (stub_entry
!= NULL
)
2818 /* The proper stub has already been created. */
2823 stub_entry
= hppa_add_stub (stub_name
, section
,
2825 if (stub_entry
== NULL
)
2828 goto error_ret_free_local
;
2831 stub_entry
->target_value
= sym_value
;
2832 stub_entry
->target_section
= sym_sec
;
2833 stub_entry
->stub_type
= stub_type
;
2836 if (stub_type
== hppa_stub_import
)
2837 stub_entry
->stub_type
= hppa_stub_import_shared
;
2838 else if (stub_type
== hppa_stub_long_branch
2839 && (LONG_BRANCH_PIC_IN_SHLIB
|| hash
== NULL
))
2840 stub_entry
->stub_type
= hppa_stub_long_branch_shared
;
2842 stub_entry
->h
= hash
;
2846 /* We're done with the internal relocs, free them. */
2847 free (internal_relocs
);
2854 /* OK, we've added some stubs. Find out the new size of the
2856 for (stub_sec
= hplink
->stub_bfd
->sections
;
2858 stub_sec
= stub_sec
->next
)
2860 stub_sec
->_raw_size
= 0;
2861 stub_sec
->_cooked_size
= 0;
2863 #if ! LONG_BRANCH_PIC_IN_SHLIB
2864 for (i
= 0; i
< sec_count
; i
++)
2866 stub_sec
= hplink
->reloc_section_created
[i
];
2867 if (stub_sec
!= NULL
)
2869 stub_sec
->_raw_size
= 0;
2870 stub_sec
->_cooked_size
= 0;
2875 bfd_hash_traverse (&hplink
->stub_hash_table
,
2879 /* Ask the linker to do its stuff. */
2880 (*hplink
->layout_sections_again
) ();
2884 /* We're done with the local symbols, free them. */
2885 for (i
= 0; i
< bfd_count
; i
++)
2886 if (all_local_syms
[i
])
2887 free (all_local_syms
[i
]);
2888 free (all_local_syms
);
2889 #if ! LONG_BRANCH_PIC_IN_SHLIB
2890 free (hplink
->reloc_section_created
);
2892 free (hplink
->stub_section_created
);
2895 error_ret_free_local
:
2896 for (i
= 0; i
< bfd_count
; i
++)
2897 if (all_local_syms
[i
])
2898 free (all_local_syms
[i
]);
2899 free (all_local_syms
);
2901 error_ret_free_reloc
:
2902 #if ! LONG_BRANCH_PIC_IN_SHLIB
2903 free (hplink
->reloc_section_created
);
2904 error_ret_free_stub
:
2906 free (hplink
->stub_section_created
);
2911 /* For a final link, this function is called after we have sized the
2912 stubs to provide a value for __gp. */
2915 elf32_hppa_set_gp (abfd
, info
)
2917 struct bfd_link_info
*info
;
2919 struct elf32_hppa_link_hash_table
*hplink
;
2920 struct elf_link_hash_entry
*h
;
2924 hplink
= hppa_link_hash_table (info
);
2925 h
= elf_link_hash_lookup (&hplink
->root
, "$global$",
2926 false, false, false);
2928 if (h
!= NULL
&& h
->root
.type
== bfd_link_hash_defined
)
2930 gp_val
= h
->root
.u
.def
.value
;
2931 sec
= h
->root
.u
.def
.section
;
2935 /* Choose to point our LTP at, in this order, one of .plt, .got,
2936 or .data, if these sections exist. In the case of choosing
2937 .plt try to make the LTP ideal for addressing anywhere in the
2938 .plt or .got with a 14 bit signed offset. Typically, the end
2939 of the .plt is the start of the .got, so choose .plt + 0x2000
2940 if either the .plt or .got is larger than 0x2000. If both
2941 the .plt and .got are smaller than 0x2000, choose the end of
2942 the .plt section. */
2947 gp_val
= sec
->_raw_size
;
2949 || (hplink
->sgot
&& hplink
->sgot
->_raw_size
> 0x2000))
2960 /* We know we don't have a .plt. If .got is large,
2962 if (sec
->_raw_size
> 0x2000)
2967 /* No .plt or .got. Who cares what the LTP is? */
2968 sec
= bfd_get_section_by_name (abfd
, ".data");
2974 gp_val
+= sec
->output_section
->vma
+ sec
->output_offset
;
2976 elf_gp (abfd
) = gp_val
;
2981 /* Build all the stubs associated with the current output file. The
2982 stubs are kept in a hash table attached to the main linker hash
2983 table. We also set up the .plt entries for statically linked PIC
2984 functions here. This function is called via hppaelf_finish in the
2988 elf32_hppa_build_stubs (info
)
2989 struct bfd_link_info
*info
;
2992 struct bfd_hash_table
*table
;
2993 struct elf32_hppa_link_hash_table
*hplink
;
2995 hplink
= hppa_link_hash_table (info
);
2997 for (stub_sec
= hplink
->stub_bfd
->sections
;
2999 stub_sec
= stub_sec
->next
)
3003 /* Allocate memory to hold the linker stubs. */
3004 size
= stub_sec
->_raw_size
;
3005 stub_sec
->contents
= (unsigned char *) bfd_zalloc (hplink
->stub_bfd
,
3007 if (stub_sec
->contents
== NULL
&& size
!= 0)
3009 stub_sec
->_raw_size
= 0;
3012 /* Build the stubs as directed by the stub hash table. */
3013 table
= &hplink
->stub_hash_table
;
3014 bfd_hash_traverse (table
, hppa_build_one_stub
, info
);
3020 /* Perform a relocation as part of a final link. */
3022 static bfd_reloc_status_type
3023 final_link_relocate (input_section
, contents
, rel
, value
, info
, sym_sec
, h
)
3024 asection
*input_section
;
3026 const Elf_Internal_Rela
*rel
;
3028 struct bfd_link_info
*info
;
3030 struct elf32_hppa_link_hash_entry
*h
;
3033 unsigned int r_type
= ELF32_R_TYPE (rel
->r_info
);
3034 reloc_howto_type
*howto
= elf_hppa_howto_table
+ r_type
;
3035 int r_format
= howto
->bitsize
;
3036 enum hppa_reloc_field_selector_type_alt r_field
;
3037 bfd
*input_bfd
= input_section
->owner
;
3038 bfd_vma offset
= rel
->r_offset
;
3039 bfd_vma max_branch_offset
= 0;
3040 bfd_byte
*hit_data
= contents
+ offset
;
3041 bfd_signed_vma addend
= rel
->r_addend
;
3043 struct elf32_hppa_stub_hash_entry
*stub_entry
= NULL
;
3046 if (r_type
== R_PARISC_NONE
)
3047 return bfd_reloc_ok
;
3049 insn
= bfd_get_32 (input_bfd
, hit_data
);
3051 /* Find out where we are and where we're going. */
3052 location
= (offset
+
3053 input_section
->output_offset
+
3054 input_section
->output_section
->vma
);
3058 case R_PARISC_PCREL12F
:
3059 case R_PARISC_PCREL17F
:
3060 case R_PARISC_PCREL22F
:
3061 /* If this is a call to a function defined in another dynamic
3062 library, or if it is a call to a PIC function in the same
3063 object, or if this is a shared link and it is a call to a
3064 weak symbol which may or may not be in the same object, then
3065 find the import stub in the stub hash. */
3067 || sym_sec
->output_section
== NULL
3070 || (h
->elf
.root
.type
== bfd_link_hash_defweak
3071 && h
->elf
.dynindx
!= -1
3072 && h
->elf
.plt
.offset
!= (bfd_vma
) -1))))
3074 stub_entry
= hppa_get_stub_entry (input_section
, sym_sec
,
3076 if (stub_entry
!= NULL
)
3078 value
= (stub_entry
->stub_offset
3079 + stub_entry
->stub_sec
->output_offset
3080 + stub_entry
->stub_sec
->output_section
->vma
);
3083 else if (sym_sec
== NULL
&& h
!= NULL
3084 && h
->elf
.root
.type
== bfd_link_hash_undefweak
)
3086 /* It's OK if undefined weak. Make undefined weak
3087 branches go nowhere. */
3092 return bfd_reloc_notsupported
;
3096 case R_PARISC_PCREL21L
:
3097 case R_PARISC_PCREL17C
:
3098 case R_PARISC_PCREL17R
:
3099 case R_PARISC_PCREL14R
:
3100 case R_PARISC_PCREL14F
:
3101 /* Make it a pc relative offset. */
3106 case R_PARISC_DPREL21L
:
3107 case R_PARISC_DPREL14R
:
3108 case R_PARISC_DPREL14F
:
3109 /* For all the DP relative relocations, we need to examine the symbol's
3110 section. If it's a code section, then "data pointer relative" makes
3111 no sense. In that case we don't adjust the "value", and for 21 bit
3112 addil instructions, we change the source addend register from %dp to
3113 %r0. This situation commonly arises when a variable's "constness"
3114 is declared differently from the way the variable is defined. For
3115 instance: "extern int foo" with foo defined as "const int foo". */
3116 if (sym_sec
== NULL
)
3118 if ((sym_sec
->flags
& SEC_CODE
) != 0)
3120 if ((insn
& ((0x3f << 26) | (0x1f << 21)))
3121 == (((int) OP_ADDIL
<< 26) | (27 << 21)))
3123 insn
&= ~ (0x1f << 21);
3124 #if 1 /* debug them. */
3125 (*_bfd_error_handler
)
3126 (_("%s(%s+0x%lx): fixing %s"),
3127 bfd_get_filename (input_bfd
),
3128 input_section
->name
,
3129 (long) rel
->r_offset
,
3133 /* Now try to make things easy for the dynamic linker. */
3139 case R_PARISC_DLTIND21L
:
3140 case R_PARISC_DLTIND14R
:
3141 case R_PARISC_DLTIND14F
:
3142 value
-= elf_gp (input_section
->output_section
->owner
);
3151 case R_PARISC_DIR32
:
3152 case R_PARISC_DIR17F
:
3153 case R_PARISC_PCREL17C
:
3154 case R_PARISC_PCREL14F
:
3155 case R_PARISC_DPREL14F
:
3156 case R_PARISC_PLABEL32
:
3157 case R_PARISC_DLTIND14F
:
3158 case R_PARISC_SEGBASE
:
3159 case R_PARISC_SEGREL32
:
3163 case R_PARISC_DIR21L
:
3164 case R_PARISC_PCREL21L
:
3165 case R_PARISC_DPREL21L
:
3166 case R_PARISC_PLABEL21L
:
3167 case R_PARISC_DLTIND21L
:
3171 case R_PARISC_DIR17R
:
3172 case R_PARISC_PCREL17R
:
3173 case R_PARISC_DIR14R
:
3174 case R_PARISC_PCREL14R
:
3175 case R_PARISC_DPREL14R
:
3176 case R_PARISC_PLABEL14R
:
3177 case R_PARISC_DLTIND14R
:
3181 case R_PARISC_PCREL12F
:
3182 case R_PARISC_PCREL17F
:
3183 case R_PARISC_PCREL22F
:
3186 if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
3188 max_branch_offset
= (1 << (17-1)) << 2;
3190 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
3192 max_branch_offset
= (1 << (12-1)) << 2;
3196 max_branch_offset
= (1 << (22-1)) << 2;
3199 /* sym_sec is NULL on undefined weak syms or when shared on
3200 undefined syms. We've already checked for a stub for the
3201 shared undefined case. */
3202 if (sym_sec
== NULL
)
3205 /* If the branch is out of reach, then redirect the
3206 call to the local stub for this function. */
3207 if (value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3209 stub_entry
= hppa_get_stub_entry (input_section
, sym_sec
,
3211 if (stub_entry
== NULL
)
3212 return bfd_reloc_notsupported
;
3214 /* Munge up the value and addend so that we call the stub
3215 rather than the procedure directly. */
3216 value
= (stub_entry
->stub_offset
3217 + stub_entry
->stub_sec
->output_offset
3218 + stub_entry
->stub_sec
->output_section
->vma
3224 /* Something we don't know how to handle. */
3226 return bfd_reloc_notsupported
;
3229 /* Make sure we can reach the stub. */
3230 if (max_branch_offset
!= 0
3231 && value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3233 (*_bfd_error_handler
)
3234 (_("%s(%s+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
3235 bfd_get_filename (input_bfd
),
3236 input_section
->name
,
3237 (long) rel
->r_offset
,
3238 stub_entry
->root
.string
);
3239 return bfd_reloc_notsupported
;
3242 val
= hppa_field_adjust (value
, addend
, r_field
);
3246 case R_PARISC_PCREL12F
:
3247 case R_PARISC_PCREL17C
:
3248 case R_PARISC_PCREL17F
:
3249 case R_PARISC_PCREL17R
:
3250 case R_PARISC_PCREL22F
:
3251 case R_PARISC_DIR17F
:
3252 case R_PARISC_DIR17R
:
3253 /* This is a branch. Divide the offset by four.
3254 Note that we need to decide whether it's a branch or
3255 otherwise by inspecting the reloc. Inspecting insn won't
3256 work as insn might be from a .word directive. */
3264 insn
= hppa_rebuild_insn (insn
, val
, r_format
);
3266 /* Update the instruction word. */
3267 bfd_put_32 (input_bfd
, (bfd_vma
) insn
, hit_data
);
3268 return bfd_reloc_ok
;
3272 /* Relocate an HPPA ELF section. */
3275 elf32_hppa_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
3276 contents
, relocs
, local_syms
, local_sections
)
3278 struct bfd_link_info
*info
;
3280 asection
*input_section
;
3282 Elf_Internal_Rela
*relocs
;
3283 Elf_Internal_Sym
*local_syms
;
3284 asection
**local_sections
;
3287 bfd_vma
*local_got_offsets
;
3288 struct elf32_hppa_link_hash_table
*hplink
;
3289 Elf_Internal_Shdr
*symtab_hdr
;
3290 Elf_Internal_Rela
*rel
;
3291 Elf_Internal_Rela
*relend
;
3294 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3296 hplink
= hppa_link_hash_table (info
);
3297 dynobj
= hplink
->root
.dynobj
;
3298 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3302 relend
= relocs
+ input_section
->reloc_count
;
3303 for (; rel
< relend
; rel
++)
3305 unsigned int r_type
;
3306 reloc_howto_type
*howto
;
3307 unsigned int r_symndx
;
3308 struct elf32_hppa_link_hash_entry
*h
;
3309 Elf_Internal_Sym
*sym
;
3312 bfd_reloc_status_type r
;
3313 const char *sym_name
;
3316 r_type
= ELF32_R_TYPE (rel
->r_info
);
3317 if (r_type
>= (unsigned int) R_PARISC_UNIMPLEMENTED
)
3319 bfd_set_error (bfd_error_bad_value
);
3322 if (r_type
== (unsigned int) R_PARISC_GNU_VTENTRY
3323 || r_type
== (unsigned int) R_PARISC_GNU_VTINHERIT
)
3326 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3328 if (info
->relocateable
)
3330 /* This is a relocateable link. We don't have to change
3331 anything, unless the reloc is against a section symbol,
3332 in which case we have to adjust according to where the
3333 section symbol winds up in the output section. */
3334 if (r_symndx
< symtab_hdr
->sh_info
)
3336 sym
= local_syms
+ r_symndx
;
3337 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
3339 sym_sec
= local_sections
[r_symndx
];
3340 rel
->r_addend
+= sym_sec
->output_offset
;
3346 /* This is a final link. */
3350 if (r_symndx
< symtab_hdr
->sh_info
)
3352 /* This is a local symbol, h defaults to NULL. */
3353 sym
= local_syms
+ r_symndx
;
3354 sym_sec
= local_sections
[r_symndx
];
3355 relocation
= ((ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
3356 ? 0 : sym
->st_value
)
3357 + sym_sec
->output_offset
3358 + sym_sec
->output_section
->vma
);
3364 /* It's a global; Find its entry in the link hash. */
3365 indx
= r_symndx
- symtab_hdr
->sh_info
;
3366 h
= ((struct elf32_hppa_link_hash_entry
*)
3367 elf_sym_hashes (input_bfd
)[indx
]);
3368 while (h
->elf
.root
.type
== bfd_link_hash_indirect
3369 || h
->elf
.root
.type
== bfd_link_hash_warning
)
3370 h
= (struct elf32_hppa_link_hash_entry
*) h
->elf
.root
.u
.i
.link
;
3373 if (h
->elf
.root
.type
== bfd_link_hash_defined
3374 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
3376 sym_sec
= h
->elf
.root
.u
.def
.section
;
3377 /* If sym_sec->output_section is NULL, then it's a
3378 symbol defined in a shared library. */
3379 if (sym_sec
->output_section
!= NULL
)
3380 relocation
= (h
->elf
.root
.u
.def
.value
3381 + sym_sec
->output_offset
3382 + sym_sec
->output_section
->vma
);
3384 else if (h
->elf
.root
.type
== bfd_link_hash_undefweak
)
3386 else if (info
->shared
&& !info
->no_undefined
3387 && ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
)
3390 if (!((*info
->callbacks
->undefined_symbol
)
3391 (info
, h
->elf
.root
.root
.string
, input_bfd
,
3392 input_section
, rel
->r_offset
, false)))
3397 if (!((*info
->callbacks
->undefined_symbol
)
3398 (info
, h
->elf
.root
.root
.string
, input_bfd
,
3399 input_section
, rel
->r_offset
, true)))
3404 /* Do any required modifications to the relocation value, and
3405 determine what types of dynamic info we need to output, if
3410 case R_PARISC_DLTIND14F
:
3411 case R_PARISC_DLTIND14R
:
3412 case R_PARISC_DLTIND21L
:
3413 /* Relocation is to the entry for this symbol in the global
3419 off
= h
->elf
.got
.offset
;
3420 BFD_ASSERT (off
!= (bfd_vma
) -1);
3422 if (! hplink
->root
.dynamic_sections_created
3424 && (info
->symbolic
|| h
->elf
.dynindx
== -1)
3425 && (h
->elf
.elf_link_hash_flags
3426 & ELF_LINK_HASH_DEF_REGULAR
) != 0))
3428 /* This is actually a static link, or it is a
3429 -Bsymbolic link and the symbol is defined
3430 locally, or the symbol was forced to be local
3431 because of a version file. We must initialize
3432 this entry in the global offset table. Since the
3433 offset must always be a multiple of 4, we use the
3434 least significant bit to record whether we have
3435 initialized it already.
3437 When doing a dynamic link, we create a .rela.got
3438 relocation entry to initialize the value. This
3439 is done in the finish_dynamic_symbol routine. */
3444 bfd_put_32 (output_bfd
, relocation
,
3445 hplink
->sgot
->contents
+ off
);
3446 h
->elf
.got
.offset
|= 1;
3454 /* Local symbol case. */
3457 BFD_ASSERT (local_got_offsets
!= NULL
3458 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
3460 off
= local_got_offsets
[r_symndx
];
3462 /* The offset must always be a multiple of 4. We use
3463 the least significant bit to record whether we have
3464 already generated the necessary reloc. */
3469 bfd_put_32 (output_bfd
, relocation
,
3470 hplink
->sgot
->contents
+ off
);
3474 /* Output a dynamic *ABS* relocation for this
3475 GOT entry. In this case it is relative to
3476 the base of the object because the symbol
3478 Elf_Internal_Rela outrel
;
3479 asection
*srelgot
= hplink
->srelgot
;
3481 outrel
.r_offset
= (off
3482 + hplink
->sgot
->output_offset
3483 + hplink
->sgot
->output_section
->vma
);
3484 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_DIR32
);
3485 outrel
.r_addend
= relocation
;
3486 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3487 ((Elf32_External_Rela
*)
3489 + srelgot
->reloc_count
));
3490 ++srelgot
->reloc_count
;
3493 local_got_offsets
[r_symndx
] |= 1;
3499 /* Add the base of the GOT to the relocation value. */
3500 relocation
+= (hplink
->sgot
->output_offset
3501 + hplink
->sgot
->output_section
->vma
);
3504 case R_PARISC_PLABEL14R
:
3505 case R_PARISC_PLABEL21L
:
3506 case R_PARISC_PLABEL32
:
3507 if (hplink
->root
.dynamic_sections_created
)
3511 /* If we have a global symbol with a PLT slot, then
3512 redirect this relocation to it. */
3515 off
= h
->elf
.plt
.offset
;
3521 indx
= r_symndx
+ symtab_hdr
->sh_info
;
3522 off
= local_got_offsets
[indx
];
3524 /* As for the local .got entry case, we use the last
3525 bit to record whether we've already initialised
3526 this local .plt entry. */
3531 bfd_put_32 (output_bfd
,
3533 hplink
->splt
->contents
+ off
);
3534 bfd_put_32 (output_bfd
,
3535 elf_gp (hplink
->splt
->output_section
->owner
),
3536 hplink
->splt
->contents
+ off
+ 4);
3540 /* Output a dynamic IPLT relocation for this
3542 Elf_Internal_Rela outrel
;
3543 asection
*srelplt
= hplink
->srelplt
;
3545 outrel
.r_offset
= (off
3546 + hplink
->splt
->output_offset
3547 + hplink
->splt
->output_section
->vma
);
3548 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_IPLT
);
3549 outrel
.r_addend
= relocation
;
3550 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3551 ((Elf32_External_Rela
*)
3553 + srelplt
->reloc_count
));
3554 ++srelplt
->reloc_count
;
3557 local_got_offsets
[indx
] |= 1;
3561 BFD_ASSERT (off
< (bfd_vma
) -2);
3563 /* PLABELs contain function pointers. Relocation is to
3564 the entry for the function in the .plt. The magic +2
3565 offset signals to $$dyncall that the function pointer
3566 is in the .plt and thus has a gp pointer too.
3567 Exception: Undefined PLABELs should have a value of
3570 || (h
->elf
.root
.type
!= bfd_link_hash_undefweak
3571 && h
->elf
.root
.type
!= bfd_link_hash_undefined
))
3574 + hplink
->splt
->output_offset
3575 + hplink
->splt
->output_section
->vma
3580 /* Fall through and possibly emit a dynamic relocation. */
3582 case R_PARISC_DIR17F
:
3583 case R_PARISC_DIR17R
:
3584 case R_PARISC_DIR14R
:
3585 case R_PARISC_DIR21L
:
3586 case R_PARISC_DPREL14F
:
3587 case R_PARISC_DPREL14R
:
3588 case R_PARISC_DPREL21L
:
3589 case R_PARISC_DIR32
:
3590 /* The reloc types handled here and this conditional
3591 expression must match the code in check_relocs and
3592 hppa_discard_copies. ie. We need exactly the same
3593 condition as in check_relocs, with some extra conditions
3594 (dynindx test in this case) to cater for relocs removed
3595 by hppa_discard_copies. */
3596 if ((input_section
->flags
& SEC_ALLOC
) != 0
3598 #if RELATIVE_DYNAMIC_RELOCS
3599 && (is_absolute_reloc (r_type
)
3600 || ((!info
->symbolic
3602 && ((h
->elf
.elf_link_hash_flags
3603 & ELF_LINK_HASH_DEF_REGULAR
) == 0
3604 || h
->elf
.root
.type
== bfd_link_hash_defweak
)))
3605 && (h
== NULL
|| h
->elf
.dynindx
!= -1)))
3609 Elf_Internal_Rela outrel
;
3612 /* When generating a shared object, these relocations
3613 are copied into the output file to be resolved at run
3620 name
= (bfd_elf_string_from_elf_section
3622 elf_elfheader (input_bfd
)->e_shstrndx
,
3623 elf_section_data (input_section
)->rel_hdr
.sh_name
));
3626 sreloc
= bfd_get_section_by_name (dynobj
, name
);
3627 BFD_ASSERT (sreloc
!= NULL
);
3630 outrel
.r_offset
= rel
->r_offset
;
3631 outrel
.r_addend
= rel
->r_addend
;
3633 if (elf_section_data (input_section
)->stab_info
!= NULL
)
3637 off
= (_bfd_stab_section_offset
3638 (output_bfd
, &hplink
->root
.stab_info
,
3640 &elf_section_data (input_section
)->stab_info
,
3642 if (off
== (bfd_vma
) -1)
3644 outrel
.r_offset
= off
;
3647 outrel
.r_offset
+= (input_section
->output_offset
3648 + input_section
->output_section
->vma
);
3652 memset (&outrel
, 0, sizeof (outrel
));
3655 && h
->elf
.dynindx
!= -1
3658 || (h
->elf
.elf_link_hash_flags
3659 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
3661 outrel
.r_info
= ELF32_R_INFO (h
->elf
.dynindx
, r_type
);
3663 else /* It's a local symbol, or one marked to become local. */
3667 /* Add the absolute offset of the symbol. */
3668 outrel
.r_addend
+= relocation
;
3670 /* Global plabels need to be processed by the
3671 dynamic linker so that functions have at most one
3672 fptr. For this reason, we need to differentiate
3673 between global and local plabels, which we do by
3674 providing the function symbol for a global plabel
3675 reloc, and no symbol for local plabels. */
3678 && sym_sec
->output_section
!= NULL
3679 && ! bfd_is_abs_section (sym_sec
))
3681 indx
= elf_section_data (sym_sec
->output_section
)->dynindx
;
3682 /* We are turning this relocation into one
3683 against a section symbol, so subtract out the
3684 output section's address but not the offset
3685 of the input section in the output section. */
3686 outrel
.r_addend
-= sym_sec
->output_section
->vma
;
3689 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
3692 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3693 ((Elf32_External_Rela
*)
3695 + sreloc
->reloc_count
));
3696 ++sreloc
->reloc_count
;
3704 r
= final_link_relocate (input_section
, contents
, rel
, relocation
,
3707 if (r
== bfd_reloc_ok
)
3711 sym_name
= h
->elf
.root
.root
.string
;
3714 sym_name
= bfd_elf_string_from_elf_section (input_bfd
,
3715 symtab_hdr
->sh_link
,
3717 if (sym_name
== NULL
)
3719 if (*sym_name
== '\0')
3720 sym_name
= bfd_section_name (input_bfd
, sym_sec
);
3723 howto
= elf_hppa_howto_table
+ r_type
;
3725 if (r
== bfd_reloc_undefined
|| r
== bfd_reloc_notsupported
)
3727 (*_bfd_error_handler
)
3728 (_("%s(%s+0x%lx): cannot handle %s for %s"),
3729 bfd_get_filename (input_bfd
),
3730 input_section
->name
,
3731 (long) rel
->r_offset
,
3737 if (!((*info
->callbacks
->reloc_overflow
)
3738 (info
, sym_name
, howto
->name
, (bfd_vma
) 0,
3739 input_bfd
, input_section
, rel
->r_offset
)))
3748 /* Finish up dynamic symbol handling. We set the contents of various
3749 dynamic sections here. */
3752 elf32_hppa_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
3754 struct bfd_link_info
*info
;
3755 struct elf_link_hash_entry
*h
;
3756 Elf_Internal_Sym
*sym
;
3758 struct elf32_hppa_link_hash_table
*hplink
;
3761 hplink
= hppa_link_hash_table (info
);
3762 dynobj
= hplink
->root
.dynobj
;
3764 if (h
->plt
.offset
!= (bfd_vma
) -1)
3767 Elf_Internal_Rela rel
;
3769 /* This symbol has an entry in the procedure linkage table. Set
3772 The format of a plt entry is
3777 The last field is present only for plt entries that are used
3778 by global plabels. */
3780 /* We do not actually care about the value in the PLT entry if
3781 we are creating a shared library and the symbol is still
3782 undefined; We create a dynamic relocation to fill in the
3785 if (h
->root
.type
== bfd_link_hash_defined
3786 || h
->root
.type
== bfd_link_hash_defweak
)
3788 value
= h
->root
.u
.def
.value
;
3789 if (h
->root
.u
.def
.section
->output_section
!= NULL
)
3790 value
+= (h
->root
.u
.def
.section
->output_offset
3791 + h
->root
.u
.def
.section
->output_section
->vma
);
3794 bfd_put_32 (hplink
->splt
->owner
,
3796 hplink
->splt
->contents
+ h
->plt
.offset
);
3797 bfd_put_32 (hplink
->splt
->owner
,
3798 elf_gp (hplink
->splt
->output_section
->owner
),
3799 hplink
->splt
->contents
+ h
->plt
.offset
+ 4);
3800 if (PLABEL_PLT_ENTRY_SIZE
!= PLT_ENTRY_SIZE
3801 && ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
3802 && h
->dynindx
!= -1)
3804 memset (hplink
->splt
->contents
+ h
->plt
.offset
+ 8,
3805 0, PLABEL_PLT_ENTRY_SIZE
- PLT_ENTRY_SIZE
);
3808 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
)
3810 /* Create a dynamic IPLT relocation for this entry. */
3811 rel
.r_offset
= (h
->plt
.offset
3812 + hplink
->splt
->output_offset
3813 + hplink
->splt
->output_section
->vma
);
3814 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->plt_abs
3815 && h
->dynindx
!= -1)
3817 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_IPLT
);
3822 /* This symbol has been marked to become local, and is
3823 used by a plabel so must be kept in the .plt. */
3824 rel
.r_info
= ELF32_R_INFO (0, R_PARISC_IPLT
);
3825 rel
.r_addend
= value
;
3828 bfd_elf32_swap_reloca_out (hplink
->splt
->output_section
->owner
,
3830 ((Elf32_External_Rela
*)
3831 hplink
->srelplt
->contents
3832 + hplink
->srelplt
->reloc_count
));
3833 hplink
->srelplt
->reloc_count
++;
3836 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3838 /* Mark the symbol as undefined, rather than as defined in
3839 the .plt section. Leave the value alone. */
3840 sym
->st_shndx
= SHN_UNDEF
;
3844 if (h
->got
.offset
!= (bfd_vma
) -1)
3846 Elf_Internal_Rela rel
;
3848 /* This symbol has an entry in the global offset table. Set it
3851 rel
.r_offset
= ((h
->got
.offset
&~ (bfd_vma
) 1)
3852 + hplink
->sgot
->output_offset
3853 + hplink
->sgot
->output_section
->vma
);
3855 /* If this is a static link, or it is a -Bsymbolic link and the
3856 symbol is defined locally or was forced to be local because
3857 of a version file, we just want to emit a RELATIVE reloc.
3858 The entry in the global offset table will already have been
3859 initialized in the relocate_section function. */
3860 if (! hplink
->root
.dynamic_sections_created
3862 && (info
->symbolic
|| h
->dynindx
== -1)
3863 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
3865 rel
.r_info
= ELF32_R_INFO (0, R_PARISC_DIR32
);
3866 rel
.r_addend
= (h
->root
.u
.def
.value
3867 + h
->root
.u
.def
.section
->output_offset
3868 + h
->root
.u
.def
.section
->output_section
->vma
);
3872 BFD_ASSERT((h
->got
.offset
& 1) == 0);
3873 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
3874 hplink
->sgot
->contents
+ h
->got
.offset
);
3875 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_DIR32
);
3879 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
3880 ((Elf32_External_Rela
*)
3881 hplink
->srelgot
->contents
3882 + hplink
->srelgot
->reloc_count
));
3883 ++hplink
->srelgot
->reloc_count
;
3886 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
3889 Elf_Internal_Rela rel
;
3891 /* This symbol needs a copy reloc. Set it up. */
3893 BFD_ASSERT (h
->dynindx
!= -1
3894 && (h
->root
.type
== bfd_link_hash_defined
3895 || h
->root
.type
== bfd_link_hash_defweak
));
3897 s
= hplink
->srelbss
;
3899 rel
.r_offset
= (h
->root
.u
.def
.value
3900 + h
->root
.u
.def
.section
->output_offset
3901 + h
->root
.u
.def
.section
->output_section
->vma
);
3903 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_COPY
);
3904 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
3905 ((Elf32_External_Rela
*) s
->contents
3910 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
3911 if (h
->root
.root
.string
[0] == '_'
3912 && (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3913 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0))
3915 sym
->st_shndx
= SHN_ABS
;
3922 /* Finish up the dynamic sections. */
3925 elf32_hppa_finish_dynamic_sections (output_bfd
, info
)
3927 struct bfd_link_info
*info
;
3930 struct elf32_hppa_link_hash_table
*hplink
;
3933 hplink
= hppa_link_hash_table (info
);
3934 dynobj
= hplink
->root
.dynobj
;
3936 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3938 if (hplink
->root
.dynamic_sections_created
)
3940 Elf32_External_Dyn
*dyncon
, *dynconend
;
3942 BFD_ASSERT (sdyn
!= NULL
);
3944 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
3945 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
3946 for (; dyncon
< dynconend
; dyncon
++)
3948 Elf_Internal_Dyn dyn
;
3951 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3959 /* Use PLTGOT to set the GOT register. */
3960 dyn
.d_un
.d_ptr
= elf_gp (output_bfd
);
3961 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3965 s
= hplink
->srelplt
;
3966 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3967 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3971 s
= hplink
->srelplt
;
3972 if (s
->_cooked_size
!= 0)
3973 dyn
.d_un
.d_val
= s
->_cooked_size
;
3975 dyn
.d_un
.d_val
= s
->_raw_size
;
3976 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3982 struct elf_link_hash_entry
*h
;
3983 const char *funcname
;
3985 if (dyn
.d_tag
== DT_INIT
)
3986 funcname
= info
->init_function
;
3988 funcname
= info
->fini_function
;
3990 h
= elf_link_hash_lookup (&hplink
->root
, funcname
,
3991 false, false, false);
3993 /* This is a function pointer. The magic +2 offset
3994 signals to $$dyncall that the function pointer
3995 is in the .plt and thus has a gp pointer too. */
3996 dyn
.d_un
.d_ptr
= (h
->plt
.offset
3997 + hplink
->splt
->output_offset
3998 + hplink
->splt
->output_section
->vma
4000 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4007 if (hplink
->sgot
->_raw_size
!= 0)
4009 /* Fill in the first entry in the global offset table.
4010 We use it to point to our dynamic section, if we have one. */
4011 bfd_put_32 (output_bfd
,
4013 ? sdyn
->output_section
->vma
+ sdyn
->output_offset
4015 hplink
->sgot
->contents
);
4017 /* The second entry is reserved for use by the dynamic linker. */
4018 bfd_put_32 (output_bfd
, (bfd_vma
) 0, hplink
->sgot
->contents
+ 4);
4020 /* Set .got entry size. */
4021 elf_section_data (hplink
->sgot
->output_section
)
4022 ->this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
4025 /* Set plt entry size. */
4026 if (hplink
->splt
->_raw_size
!= 0)
4027 elf_section_data (hplink
->splt
->output_section
)
4028 ->this_hdr
.sh_entsize
= PLT_ENTRY_SIZE
;
4034 /* Called when writing out an object file to decide the type of a
4037 elf32_hppa_elf_get_symbol_type (elf_sym
, type
)
4038 Elf_Internal_Sym
*elf_sym
;
4041 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_PARISC_MILLI
)
4042 return STT_PARISC_MILLI
;
4048 /* Misc BFD support code. */
4049 #define bfd_elf32_bfd_is_local_label_name elf_hppa_is_local_label_name
4050 #define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
4051 #define elf_info_to_howto elf_hppa_info_to_howto
4052 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
4054 /* Stuff for the BFD linker. */
4055 #define bfd_elf32_bfd_final_link _bfd_elf32_gc_common_final_link
4056 #define bfd_elf32_bfd_link_hash_table_create elf32_hppa_link_hash_table_create
4057 #define elf_backend_add_symbol_hook elf32_hppa_add_symbol_hook
4058 #define elf_backend_adjust_dynamic_symbol elf32_hppa_adjust_dynamic_symbol
4059 #define elf_backend_check_relocs elf32_hppa_check_relocs
4060 #define elf_backend_create_dynamic_sections elf32_hppa_create_dynamic_sections
4061 #define elf_backend_fake_sections elf_hppa_fake_sections
4062 #define elf_backend_relocate_section elf32_hppa_relocate_section
4063 #define elf_backend_hide_symbol elf32_hppa_hide_symbol
4064 #define elf_backend_finish_dynamic_symbol elf32_hppa_finish_dynamic_symbol
4065 #define elf_backend_finish_dynamic_sections elf32_hppa_finish_dynamic_sections
4066 #define elf_backend_size_dynamic_sections elf32_hppa_size_dynamic_sections
4067 #define elf_backend_gc_mark_hook elf32_hppa_gc_mark_hook
4068 #define elf_backend_gc_sweep_hook elf32_hppa_gc_sweep_hook
4069 #define elf_backend_object_p elf32_hppa_object_p
4070 #define elf_backend_final_write_processing elf_hppa_final_write_processing
4071 #define elf_backend_get_symbol_type elf32_hppa_elf_get_symbol_type
4073 #define elf_backend_can_gc_sections 1
4074 #define elf_backend_plt_alignment 2
4075 #define elf_backend_want_got_plt 0
4076 #define elf_backend_plt_readonly 0
4077 #define elf_backend_want_plt_sym 0
4078 #define elf_backend_got_header_size 8
4080 #define TARGET_BIG_SYM bfd_elf32_hppa_vec
4081 #define TARGET_BIG_NAME "elf32-hppa"
4082 #define ELF_ARCH bfd_arch_hppa
4083 #define ELF_MACHINE_CODE EM_PARISC
4084 #define ELF_MAXPAGESIZE 0x1000
4086 #include "elf32-target.h"