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 elf32_hppa_size_dynamic_sections
349 PARAMS ((bfd
*, struct bfd_link_info
*));
351 static bfd_reloc_status_type final_link_relocate
352 PARAMS ((asection
*, bfd_byte
*, const Elf_Internal_Rela
*,
353 bfd_vma
, struct bfd_link_info
*, asection
*,
354 struct elf32_hppa_link_hash_entry
*));
356 static boolean elf32_hppa_relocate_section
357 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*,
358 bfd_byte
*, Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
360 static boolean elf32_hppa_finish_dynamic_symbol
361 PARAMS ((bfd
*, struct bfd_link_info
*,
362 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
364 static boolean elf32_hppa_finish_dynamic_sections
365 PARAMS ((bfd
*, struct bfd_link_info
*));
367 static int elf32_hppa_elf_get_symbol_type
368 PARAMS ((Elf_Internal_Sym
*, int));
371 /* Assorted hash table functions. */
373 /* Initialize an entry in the stub hash table. */
375 static struct bfd_hash_entry
*
376 stub_hash_newfunc (entry
, table
, string
)
377 struct bfd_hash_entry
*entry
;
378 struct bfd_hash_table
*table
;
381 struct elf32_hppa_stub_hash_entry
*ret
;
383 ret
= (struct elf32_hppa_stub_hash_entry
*) entry
;
385 /* Allocate the structure if it has not already been allocated by a
389 ret
= ((struct elf32_hppa_stub_hash_entry
*)
390 bfd_hash_allocate (table
,
391 sizeof (struct elf32_hppa_stub_hash_entry
)));
396 /* Call the allocation method of the superclass. */
397 ret
= ((struct elf32_hppa_stub_hash_entry
*)
398 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
402 /* Initialize the local fields. */
403 ret
->stub_sec
= NULL
;
404 #if ! LONG_BRANCH_PIC_IN_SHLIB
405 ret
->reloc_sec
= NULL
;
407 ret
->stub_offset
= 0;
408 ret
->target_value
= 0;
409 ret
->target_section
= NULL
;
410 ret
->stub_type
= hppa_stub_long_branch
;
412 ret
->input_section
= NULL
;
415 return (struct bfd_hash_entry
*) ret
;
419 /* Initialize an entry in the link hash table. */
421 static struct bfd_hash_entry
*
422 hppa_link_hash_newfunc (entry
, table
, string
)
423 struct bfd_hash_entry
*entry
;
424 struct bfd_hash_table
*table
;
427 struct elf32_hppa_link_hash_entry
*ret
;
429 ret
= (struct elf32_hppa_link_hash_entry
*) entry
;
431 /* Allocate the structure if it has not already been allocated by a
435 ret
= ((struct elf32_hppa_link_hash_entry
*)
436 bfd_hash_allocate (table
,
437 sizeof (struct elf32_hppa_link_hash_entry
)));
442 /* Call the allocation method of the superclass. */
443 ret
= ((struct elf32_hppa_link_hash_entry
*)
444 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
449 /* Initialize the local fields. */
450 #if ! LONG_BRANCH_PIC_IN_SHLIB
451 ret
->stub_reloc_sec
= NULL
;
453 ret
->stub_cache
= NULL
;
454 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
455 ret
->reloc_entries
= NULL
;
462 return (struct bfd_hash_entry
*) ret
;
466 /* Create the derived linker hash table. The PA ELF port uses the derived
467 hash table to keep information specific to the PA ELF linker (without
468 using static variables). */
470 static struct bfd_link_hash_table
*
471 elf32_hppa_link_hash_table_create (abfd
)
474 struct elf32_hppa_link_hash_table
*ret
;
476 ret
= ((struct elf32_hppa_link_hash_table
*) bfd_alloc (abfd
, sizeof (*ret
)));
480 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
, hppa_link_hash_newfunc
))
482 bfd_release (abfd
, ret
);
486 /* Init the stub hash table too. */
487 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
))
490 ret
->stub_bfd
= NULL
;
491 ret
->multi_subspace
= 0;
492 ret
->add_stub_section
= NULL
;
493 ret
->layout_sections_again
= NULL
;
494 ret
->stub_section_created
= NULL
;
495 #if ! LONG_BRANCH_PIC_IN_SHLIB
496 ret
->reloc_section_created
= NULL
;
498 ret
->first_init_sec
= 0;
499 ret
->first_fini_sec
= 0;
507 return &ret
->root
.root
;
511 /* Build a name for an entry in the stub hash table. */
514 hppa_stub_name (input_section
, sym_sec
, hash
, rel
)
515 const asection
*input_section
;
516 const asection
*sym_sec
;
517 const struct elf32_hppa_link_hash_entry
*hash
;
518 const Elf_Internal_Rela
*rel
;
525 len
= 8 + 1 + strlen (hash
->elf
.root
.root
.string
) + 1 + 8 + 1;
526 stub_name
= bfd_malloc (len
);
527 if (stub_name
!= NULL
)
529 sprintf (stub_name
, "%08x_%s+%x",
530 input_section
->id
& 0xffffffff,
531 hash
->elf
.root
.root
.string
,
532 (int) rel
->r_addend
& 0xffffffff);
537 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
538 stub_name
= bfd_malloc (len
);
539 if (stub_name
!= NULL
)
541 sprintf (stub_name
, "%08x_%x:%x+%x",
542 input_section
->id
& 0xffffffff,
543 sym_sec
->id
& 0xffffffff,
544 (int) ELF32_R_SYM (rel
->r_info
) & 0xffffffff,
545 (int) rel
->r_addend
& 0xffffffff);
552 /* Look up an entry in the stub hash. Stub entries are cached because
553 creating the stub name takes a bit of time. */
555 static struct elf32_hppa_stub_hash_entry
*
556 hppa_get_stub_entry (input_section
, sym_sec
, hash
, rel
, info
)
557 const asection
*input_section
;
558 const asection
*sym_sec
;
559 struct elf32_hppa_link_hash_entry
*hash
;
560 const Elf_Internal_Rela
*rel
;
561 struct bfd_link_info
*info
;
563 struct elf32_hppa_stub_hash_entry
*stub_entry
;
565 if (hash
!= NULL
&& hash
->stub_cache
!= NULL
566 && hash
->stub_cache
->h
== hash
567 && hash
->stub_cache
->input_section
== input_section
)
569 stub_entry
= hash
->stub_cache
;
573 struct bfd_hash_table
*stub_hash_table
;
576 stub_name
= hppa_stub_name (input_section
, sym_sec
, hash
, rel
);
577 if (stub_name
== NULL
)
580 stub_hash_table
= &hppa_link_hash_table (info
)->stub_hash_table
;
582 stub_entry
= hppa_stub_hash_lookup (stub_hash_table
, stub_name
,
584 if (stub_entry
== NULL
)
586 if (hash
== NULL
|| hash
->elf
.root
.type
!= bfd_link_hash_undefweak
)
587 (*_bfd_error_handler
) (_("%s(%s+0x%lx): cannot find stub entry %s"),
588 bfd_get_filename (input_section
->owner
),
590 (long) rel
->r_offset
,
596 hash
->stub_cache
= stub_entry
;
606 /* Add a new stub entry to the stub hash. Not all fields of the new
607 stub entry are initialised. */
609 static struct elf32_hppa_stub_hash_entry
*
610 hppa_add_stub (stub_name
, section
, sec_count
, info
)
611 const char *stub_name
;
613 unsigned int sec_count
;
614 struct bfd_link_info
*info
;
617 struct elf32_hppa_stub_hash_entry
*stub_entry
;
618 struct elf32_hppa_link_hash_table
*hplink
;
620 hplink
= hppa_link_hash_table (info
);
621 stub_sec
= hplink
->stub_section_created
[sec_count
];
622 if (stub_sec
== NULL
)
626 /* We only want one stub for .init and .fini because glibc
627 splits the _init and _fini functions into two parts. We
628 don't want to put a stub in the middle of a function.
629 It would be better to merge all the stub sections for an
630 output section if the output section + stubs is small enough.
631 This would fix the .init and .fini case and also allow stubs
632 to be merged. It's more linker work though. */
633 if (strncmp (section
->name
, ".init", 5) == 0)
635 if (hplink
->first_init_sec
!= 0)
636 stub_sec
= hplink
->stub_section_created
[hplink
->first_init_sec
-1];
639 else if (strncmp (section
->name
, ".fini", 5) == 0)
641 if (hplink
->first_fini_sec
!= 0)
642 stub_sec
= hplink
->stub_section_created
[hplink
->first_fini_sec
-1];
645 if (stub_sec
== NULL
)
650 len
= strlen (section
->name
) + sizeof (STUB_SUFFIX
);
651 s_name
= bfd_alloc (hplink
->stub_bfd
, len
);
655 strcpy (s_name
, section
->name
);
656 strcpy (s_name
+ len
- sizeof (STUB_SUFFIX
), STUB_SUFFIX
);
657 stub_sec
= (*hplink
->add_stub_section
) (s_name
, section
);
658 if (stub_sec
== NULL
)
661 if (special_sec
!= 0)
663 if (special_sec
== 1)
664 hplink
->first_init_sec
= sec_count
+ 1;
666 hplink
->first_fini_sec
= sec_count
+ 1;
669 hplink
->stub_section_created
[sec_count
] = stub_sec
;
672 /* Enter this entry into the linker stub hash table. */
673 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
, stub_name
,
675 if (stub_entry
== NULL
)
677 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
678 bfd_get_filename (section
->owner
),
683 stub_entry
->stub_sec
= stub_sec
;
684 #if ! LONG_BRANCH_PIC_IN_SHLIB
685 stub_entry
->reloc_sec
= hplink
->reloc_section_created
[sec_count
];
687 stub_entry
->stub_offset
= 0;
688 stub_entry
->input_section
= section
;
693 /* Determine the type of stub needed, if any, for a call. */
695 static enum elf32_hppa_stub_type
696 hppa_type_of_stub (input_sec
, rel
, hash
, destination
)
698 const Elf_Internal_Rela
*rel
;
699 struct elf32_hppa_link_hash_entry
*hash
;
703 bfd_vma branch_offset
;
704 bfd_vma max_branch_offset
;
708 && (((hash
->elf
.root
.type
== bfd_link_hash_defined
709 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
710 && hash
->elf
.root
.u
.def
.section
->output_section
== NULL
)
711 || (hash
->elf
.root
.type
== bfd_link_hash_defweak
712 && hash
->elf
.dynindx
!= -1
713 && hash
->elf
.plt
.offset
!= (bfd_vma
) -1)
714 || hash
->elf
.root
.type
== bfd_link_hash_undefweak
715 || hash
->elf
.root
.type
== bfd_link_hash_undefined
718 /* If output_section is NULL, then it's a symbol defined in a
719 shared library. We will need an import stub. Decide between
720 hppa_stub_import and hppa_stub_import_shared later. For
721 shared links we need stubs for undefined or weak syms too;
722 They will presumably be resolved by the dynamic linker. */
723 return hppa_stub_import
;
726 /* Determine where the call point is. */
727 location
= (input_sec
->output_offset
728 + input_sec
->output_section
->vma
731 branch_offset
= destination
- location
- 8;
732 r_type
= ELF32_R_TYPE (rel
->r_info
);
734 /* Determine if a long branch stub is needed. parisc branch offsets
735 are relative to the second instruction past the branch, ie. +8
736 bytes on from the branch instruction location. The offset is
737 signed and counts in units of 4 bytes. */
738 if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
740 max_branch_offset
= (1 << (17-1)) << 2;
742 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
744 max_branch_offset
= (1 << (12-1)) << 2;
746 else /* R_PARISC_PCREL22F */
748 max_branch_offset
= (1 << (22-1)) << 2;
751 if (branch_offset
+ max_branch_offset
>= 2*max_branch_offset
)
753 #if LONG_BRANCH_VIA_PLT
755 && hash
->elf
.dynindx
!= -1
756 && hash
->elf
.plt
.offset
!= (bfd_vma
) -1)
758 /* If we are doing a shared link and find we need a long
759 branch stub, then go via the .plt if possible. */
760 return hppa_stub_import
;
764 return hppa_stub_long_branch
;
766 return hppa_stub_none
;
770 /* Build one linker stub as defined by the stub hash table entry GEN_ENTRY.
771 IN_ARG contains the link info pointer. */
773 #define LDIL_R1 0x20200000 /* ldil LR'XXX,%r1 */
774 #define BE_SR4_R1 0xe0202002 /* be,n RR'XXX(%sr4,%r1) */
776 #define BL_R1 0xe8200000 /* b,l .+8,%r1 */
777 #define ADDIL_R1 0x28200000 /* addil L'XXX,%r1,%r1 */
778 #define DEPI_R1 0xd4201c1e /* depi 0,31,2,%r1 */
780 #define ADDIL_DP 0x2b600000 /* addil L'XXX,%dp,%r1 */
781 #define LDW_R1_R21 0x48350000 /* ldw R'XXX(%sr0,%r1),%r21 */
782 #define BV_R0_R21 0xeaa0c000 /* bv %r0(%r21) */
783 #define LDW_R1_R19 0x48330000 /* ldw R'XXX(%sr0,%r1),%r19 */
785 #define ADDIL_R19 0x2a600000 /* addil L'XXX,%r19,%r1 */
786 #define LDW_R1_DP 0x483b0000 /* ldw R'XXX(%sr0,%r1),%dp */
788 #define LDSID_R21_R1 0x02a010a1 /* ldsid (%sr0,%r21),%r1 */
789 #define MTSP_R1 0x00011820 /* mtsp %r1,%sr0 */
790 #define BE_SR0_R21 0xe2a00000 /* be 0(%sr0,%r21) */
791 #define STW_RP 0x6bc23fd1 /* stw %rp,-24(%sr0,%sp) */
793 #define BL_RP 0xe8400002 /* b,l,n XXX,%rp */
794 #define NOP 0x08000240 /* nop */
795 #define LDW_RP 0x4bc23fd1 /* ldw -24(%sr0,%sp),%rp */
796 #define LDSID_RP_R1 0x004010a1 /* ldsid (%sr0,%rp),%r1 */
797 #define BE_SR0_RP 0xe0400002 /* be,n 0(%sr0,%rp) */
804 #define LDW_R1_DLT LDW_R1_R19
806 #define LDW_R1_DLT LDW_R1_DP
810 hppa_build_one_stub (gen_entry
, in_arg
)
811 struct bfd_hash_entry
*gen_entry
;
814 struct elf32_hppa_stub_hash_entry
*stub_entry
;
815 struct bfd_link_info
*info
;
816 struct elf32_hppa_link_hash_table
*hplink
;
825 /* Massage our args to the form they really have. */
826 stub_entry
= (struct elf32_hppa_stub_hash_entry
*) gen_entry
;
827 info
= (struct bfd_link_info
*) in_arg
;
829 hplink
= hppa_link_hash_table (info
);
830 stub_sec
= stub_entry
->stub_sec
;
832 /* Make a note of the offset within the stubs for this entry. */
833 stub_entry
->stub_offset
= stub_sec
->_raw_size
;
834 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
836 stub_bfd
= stub_sec
->owner
;
838 switch (stub_entry
->stub_type
)
840 case hppa_stub_long_branch
:
841 /* Create the long branch. A long branch is formed with "ldil"
842 loading the upper bits of the target address into a register,
843 then branching with "be" which adds in the lower bits.
844 The "be" has its delay slot nullified. */
845 sym_value
= (stub_entry
->target_value
846 + stub_entry
->target_section
->output_offset
847 + stub_entry
->target_section
->output_section
->vma
);
849 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_lrsel
);
850 insn
= hppa_rebuild_insn ((int) LDIL_R1
, val
, 21);
851 bfd_put_32 (stub_bfd
, insn
, loc
);
853 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_rrsel
) >> 2;
854 insn
= hppa_rebuild_insn ((int) BE_SR4_R1
, val
, 17);
855 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
857 #if ! LONG_BRANCH_PIC_IN_SHLIB
860 /* Output a dynamic relocation for this stub. We only
861 output one PCREL21L reloc per stub, trusting that the
862 dynamic linker will also fix the implied PCREL17R for the
863 second instruction. PCREL21L dynamic relocs had better
864 never be emitted for some other purpose... */
866 Elf_Internal_Rela outrel
;
868 if (stub_entry
->h
== NULL
)
870 (*_bfd_error_handler
)
871 (_("%s(%s+0x%lx): cannot relocate %s, recompile with -ffunction-sections"),
872 bfd_get_filename (stub_entry
->target_section
->owner
),
874 (long) stub_entry
->stub_offset
,
875 stub_entry
->root
.string
);
876 bfd_set_error (bfd_error_bad_value
);
880 srel
= stub_entry
->reloc_sec
;
883 (*_bfd_error_handler
)
884 (_("Could not find relocation section for %s"),
886 bfd_set_error (bfd_error_bad_value
);
890 outrel
.r_offset
= (stub_entry
->stub_offset
891 + stub_sec
->output_offset
892 + stub_sec
->output_section
->vma
);
893 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_PCREL21L
);
894 outrel
.r_addend
= sym_value
;
895 bfd_elf32_swap_reloca_out (stub_sec
->output_section
->owner
,
897 ((Elf32_External_Rela
*)
898 srel
->contents
+ srel
->reloc_count
));
905 case hppa_stub_long_branch_shared
:
906 /* Branches are relative. This is where we are going to. */
907 sym_value
= (stub_entry
->target_value
908 + stub_entry
->target_section
->output_offset
909 + stub_entry
->target_section
->output_section
->vma
);
911 /* And this is where we are coming from, more or less. */
912 sym_value
-= (stub_entry
->stub_offset
913 + stub_sec
->output_offset
914 + stub_sec
->output_section
->vma
);
916 bfd_put_32 (stub_bfd
, (bfd_vma
) BL_R1
, loc
);
917 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_lsel
);
918 insn
= hppa_rebuild_insn ((int) ADDIL_R1
, val
, 21);
919 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
921 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_rsel
) >> 2;
922 insn
= hppa_rebuild_insn ((int) BE_SR4_R1
, val
, 17);
923 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
927 case hppa_stub_import
:
928 case hppa_stub_import_shared
:
929 sym_value
= (stub_entry
->h
->elf
.plt
.offset
930 + hplink
->splt
->output_offset
931 + hplink
->splt
->output_section
->vma
932 - elf_gp (hplink
->splt
->output_section
->owner
));
936 if (stub_entry
->stub_type
== hppa_stub_import_shared
)
939 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_lsel
),
940 insn
= hppa_rebuild_insn ((int) insn
, val
, 21);
941 bfd_put_32 (stub_bfd
, insn
, loc
);
943 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 0, e_rsel
);
944 insn
= hppa_rebuild_insn ((int) LDW_R1_R21
, val
, 14);
945 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
947 if (hplink
->multi_subspace
)
949 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 4, e_rsel
);
950 insn
= hppa_rebuild_insn ((int) LDW_R1_DLT
, val
, 14);
951 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
953 bfd_put_32 (stub_bfd
, (bfd_vma
) LDSID_R21_R1
, loc
+ 12);
954 bfd_put_32 (stub_bfd
, (bfd_vma
) MTSP_R1
, loc
+ 16);
955 bfd_put_32 (stub_bfd
, (bfd_vma
) BE_SR0_R21
, loc
+ 20);
956 bfd_put_32 (stub_bfd
, (bfd_vma
) STW_RP
, loc
+ 24);
962 bfd_put_32 (stub_bfd
, (bfd_vma
) BV_R0_R21
, loc
+ 8);
963 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) 4, e_rsel
);
964 insn
= hppa_rebuild_insn ((int) LDW_R1_DLT
, val
, 14);
965 bfd_put_32 (stub_bfd
, insn
, loc
+ 12);
971 && stub_entry
->h
!= NULL
972 && stub_entry
->h
->pic_call
)
974 /* Build the .plt entry needed to call a PIC function from
975 statically linked code. We don't need any relocs. */
977 struct elf32_hppa_link_hash_entry
*eh
;
980 dynobj
= hplink
->root
.dynobj
;
981 eh
= (struct elf32_hppa_link_hash_entry
*) stub_entry
->h
;
983 BFD_ASSERT (eh
->elf
.root
.type
== bfd_link_hash_defined
984 || eh
->elf
.root
.type
== bfd_link_hash_defweak
);
986 value
= (eh
->elf
.root
.u
.def
.value
987 + eh
->elf
.root
.u
.def
.section
->output_offset
988 + eh
->elf
.root
.u
.def
.section
->output_section
->vma
);
990 /* Fill in the entry in the procedure linkage table.
992 The format of a plt entry is
996 bfd_put_32 (hplink
->splt
->owner
, value
,
997 hplink
->splt
->contents
+ eh
->elf
.plt
.offset
);
998 value
= elf_gp (hplink
->splt
->output_section
->owner
);
999 bfd_put_32 (hplink
->splt
->owner
, value
,
1000 hplink
->splt
->contents
+ eh
->elf
.plt
.offset
+ 4);
1004 case hppa_stub_export
:
1005 /* Branches are relative. This is where we are going to. */
1006 sym_value
= (stub_entry
->target_value
1007 + stub_entry
->target_section
->output_offset
1008 + stub_entry
->target_section
->output_section
->vma
);
1010 /* And this is where we are coming from. */
1011 sym_value
-= (stub_entry
->stub_offset
1012 + stub_sec
->output_offset
1013 + stub_sec
->output_section
->vma
);
1015 if (sym_value
- 8 + 0x40000 >= 0x80000)
1017 (*_bfd_error_handler
)
1018 (_("%s(%s+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
1019 bfd_get_filename (stub_entry
->target_section
->owner
),
1021 (long) stub_entry
->stub_offset
,
1022 stub_entry
->root
.string
);
1023 bfd_set_error (bfd_error_bad_value
);
1027 val
= hppa_field_adjust (sym_value
, (bfd_signed_vma
) -8, e_fsel
) >> 2;
1028 insn
= hppa_rebuild_insn ((int) BL_RP
, val
, 17);
1029 bfd_put_32 (stub_bfd
, insn
, loc
);
1031 bfd_put_32 (stub_bfd
, (bfd_vma
) NOP
, loc
+ 4);
1032 bfd_put_32 (stub_bfd
, (bfd_vma
) LDW_RP
, loc
+ 8);
1033 bfd_put_32 (stub_bfd
, (bfd_vma
) LDSID_RP_R1
, loc
+ 12);
1034 bfd_put_32 (stub_bfd
, (bfd_vma
) MTSP_R1
, loc
+ 16);
1035 bfd_put_32 (stub_bfd
, (bfd_vma
) BE_SR0_RP
, loc
+ 20);
1037 /* Point the function symbol at the stub. */
1038 stub_entry
->h
->elf
.root
.u
.def
.section
= stub_sec
;
1039 stub_entry
->h
->elf
.root
.u
.def
.value
= stub_sec
->_raw_size
;
1049 stub_sec
->_raw_size
+= size
;
1076 /* As above, but don't actually build the stub. Just bump offset so
1077 we know stub section sizes. */
1080 hppa_size_one_stub (gen_entry
, in_arg
)
1081 struct bfd_hash_entry
*gen_entry
;
1084 struct elf32_hppa_stub_hash_entry
*stub_entry
;
1085 struct elf32_hppa_link_hash_table
*hplink
;
1088 /* Massage our args to the form they really have. */
1089 stub_entry
= (struct elf32_hppa_stub_hash_entry
*) gen_entry
;
1090 hplink
= (struct elf32_hppa_link_hash_table
*) in_arg
;
1092 if (stub_entry
->stub_type
== hppa_stub_long_branch
)
1094 #if ! LONG_BRANCH_PIC_IN_SHLIB
1095 if (stub_entry
->reloc_sec
!= NULL
)
1096 stub_entry
->reloc_sec
->_raw_size
+= sizeof (Elf32_External_Rela
);
1100 else if (stub_entry
->stub_type
== hppa_stub_long_branch_shared
)
1102 else if (stub_entry
->stub_type
== hppa_stub_export
)
1104 else /* hppa_stub_import or hppa_stub_import_shared. */
1106 if (hplink
->multi_subspace
)
1112 stub_entry
->stub_sec
->_raw_size
+= size
;
1117 /* Return nonzero if ABFD represents an HPPA ELF32 file.
1118 Additionally we set the default architecture and machine. */
1121 elf32_hppa_object_p (abfd
)
1124 unsigned int flags
= elf_elfheader (abfd
)->e_flags
;
1126 switch (flags
& (EF_PARISC_ARCH
| EF_PARISC_WIDE
))
1128 case EFA_PARISC_1_0
:
1129 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 10);
1130 case EFA_PARISC_1_1
:
1131 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 11);
1132 case EFA_PARISC_2_0
:
1133 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 20);
1134 case EFA_PARISC_2_0
| EF_PARISC_WIDE
:
1135 return bfd_default_set_arch_mach (abfd
, bfd_arch_hppa
, 25);
1141 /* Undo the generic ELF code's subtraction of section->vma from the
1142 value of each external symbol. */
1145 elf32_hppa_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
1146 bfd
*abfd ATTRIBUTE_UNUSED
;
1147 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1148 const Elf_Internal_Sym
*sym ATTRIBUTE_UNUSED
;
1149 const char **namep ATTRIBUTE_UNUSED
;
1150 flagword
*flagsp ATTRIBUTE_UNUSED
;
1154 *valp
+= (*secp
)->vma
;
1159 /* Create the .plt and .got sections, and set up our hash table
1160 short-cuts to various dynamic sections. */
1163 elf32_hppa_create_dynamic_sections (abfd
, info
)
1165 struct bfd_link_info
*info
;
1169 struct elf32_hppa_link_hash_table
*hplink
;
1171 /* Don't try to create the .plt and .got twice. */
1172 hplink
= hppa_link_hash_table (info
);
1173 if (hplink
->splt
!= NULL
)
1176 /* Call the generic code to do most of the work. */
1177 if (! _bfd_elf_create_dynamic_sections (abfd
, info
))
1180 /* Our .plt just contains pointers. I suppose we should be using
1181 .plt.got but .plt.got doesn't make too much sense without a .plt
1182 section. Set the flags to say the .plt isn't executable. */
1183 s
= bfd_get_section_by_name (abfd
, ".plt");
1184 flags
= bfd_get_section_flags (abfd
, s
);
1185 if (! bfd_set_section_flags (abfd
, s
, flags
& ~SEC_CODE
))
1188 hplink
->srelplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
1190 hplink
->sgot
= bfd_get_section_by_name (abfd
, ".got");
1191 hplink
->srelgot
= bfd_make_section (abfd
, ".rela.got");
1192 if (hplink
->srelgot
== NULL
1193 || ! bfd_set_section_flags (abfd
, hplink
->srelgot
,
1198 | SEC_LINKER_CREATED
1200 || ! bfd_set_section_alignment (abfd
, hplink
->srelgot
, 2))
1203 hplink
->sdynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
1204 hplink
->srelbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
1210 /* Look through the relocs for a section during the first phase, and
1211 allocate space in the global offset table or procedure linkage
1212 table. At this point we haven't necessarily read all the input
1216 elf32_hppa_check_relocs (abfd
, info
, sec
, relocs
)
1218 struct bfd_link_info
*info
;
1220 const Elf_Internal_Rela
*relocs
;
1223 Elf_Internal_Shdr
*symtab_hdr
;
1224 struct elf_link_hash_entry
**sym_hashes
;
1225 bfd_signed_vma
*local_got_refcounts
;
1226 const Elf_Internal_Rela
*rel
;
1227 const Elf_Internal_Rela
*rel_end
;
1228 struct elf32_hppa_link_hash_table
*hplink
;
1230 asection
*stubreloc
;
1232 if (info
->relocateable
)
1235 hplink
= hppa_link_hash_table (info
);
1236 dynobj
= hplink
->root
.dynobj
;
1237 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1238 sym_hashes
= elf_sym_hashes (abfd
);
1239 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1243 rel_end
= relocs
+ sec
->reloc_count
;
1244 for (rel
= relocs
; rel
< rel_end
; rel
++)
1250 #if LONG_BRANCH_PIC_IN_SHLIB
1251 NEED_STUBREL
= 0, /* We won't be needing them in this case. */
1258 unsigned int r_symndx
, r_type
;
1259 struct elf32_hppa_link_hash_entry
*h
;
1262 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1264 if (r_symndx
< symtab_hdr
->sh_info
)
1267 h
= ((struct elf32_hppa_link_hash_entry
*)
1268 sym_hashes
[r_symndx
- symtab_hdr
->sh_info
]);
1270 r_type
= ELF32_R_TYPE (rel
->r_info
);
1274 case R_PARISC_DLTIND14F
:
1275 case R_PARISC_DLTIND14R
:
1276 case R_PARISC_DLTIND21L
:
1277 /* This symbol requires a global offset table entry. */
1278 need_entry
= NEED_GOT
;
1280 /* Mark this section as containing PIC code. */
1281 sec
->flags
|= SEC_HAS_GOT_REF
;
1284 case R_PARISC_PLABEL14R
: /* "Official" procedure labels. */
1285 case R_PARISC_PLABEL21L
:
1286 case R_PARISC_PLABEL32
:
1287 /* If the addend is non-zero, we break badly. */
1288 BFD_ASSERT (rel
->r_addend
== 0);
1290 /* If we are creating a shared library, then we need to
1291 create a PLT entry for all PLABELs, because PLABELs with
1292 local symbols may be passed via a pointer to another
1293 object. Additionally, output a dynamic relocation
1294 pointing to the PLT entry. */
1295 need_entry
= PLT_PLABEL
| NEED_PLT
| NEED_DYNREL
;
1298 case R_PARISC_PCREL12F
:
1299 case R_PARISC_PCREL17C
:
1300 case R_PARISC_PCREL17F
:
1301 case R_PARISC_PCREL22F
:
1302 /* Handle calls, and function pointers as they might need to
1303 go through the .plt, and might require long branch stubs. */
1306 /* We know local syms won't need a .plt entry, and if
1307 they need a long branch stub we can't guarantee that
1308 we can reach the stub. So just flag an error later
1309 if we're doing a shared link and find we need a long
1315 /* Global symbols will need a .plt entry if they remain
1316 global, and in most cases won't need a long branch
1317 stub. Unfortunately, we have to cater for the case
1318 where a symbol is forced local by versioning, or due
1319 to symbolic linking, and we lose the .plt entry. */
1320 need_entry
= NEED_PLT
| NEED_STUBREL
;
1324 case R_PARISC_SEGBASE
: /* Used to set segment base. */
1325 case R_PARISC_SEGREL32
: /* Relative reloc. */
1326 case R_PARISC_PCREL14F
: /* PC relative load/store. */
1327 case R_PARISC_PCREL14R
:
1328 case R_PARISC_PCREL17R
: /* External branches. */
1329 case R_PARISC_PCREL21L
: /* As above, and for load/store too. */
1330 /* We don't need to propagate the relocation if linking a
1331 shared object since these are section relative. */
1334 case R_PARISC_DPREL14F
: /* Used for gp rel data load/store. */
1335 case R_PARISC_DPREL14R
:
1336 case R_PARISC_DPREL21L
:
1339 (*_bfd_error_handler
)
1340 (_("%s: relocation %s can not be used when making a shared object; recompile with -fPIC"),
1341 bfd_get_filename (abfd
),
1342 elf_hppa_howto_table
[r_type
].name
);
1343 bfd_set_error (bfd_error_bad_value
);
1348 case R_PARISC_DIR17F
: /* Used for external branches. */
1349 case R_PARISC_DIR17R
:
1350 case R_PARISC_DIR14R
: /* Used for load/store from absolute locn. */
1351 case R_PARISC_DIR21L
: /* As above, and for ext branches too. */
1353 /* Help debug shared library creation. Any of the above
1354 relocs can be used in shared libs, but they may cause
1355 pages to become unshared. */
1358 (*_bfd_error_handler
)
1359 (_("%s: relocation %s should not be used when making a shared object; recompile with -fPIC"),
1360 bfd_get_filename (abfd
),
1361 elf_hppa_howto_table
[r_type
].name
);
1366 case R_PARISC_DIR32
: /* .word, PARISC.unwind relocs. */
1367 /* We may want to output a dynamic relocation later. */
1368 need_entry
= NEED_DYNREL
;
1371 /* This relocation describes the C++ object vtable hierarchy.
1372 Reconstruct it for later use during GC. */
1373 case R_PARISC_GNU_VTINHERIT
:
1374 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
,
1375 &h
->elf
, rel
->r_offset
))
1379 /* This relocation describes which C++ vtable entries are actually
1380 used. Record for later use during GC. */
1381 case R_PARISC_GNU_VTENTRY
:
1382 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
,
1383 &h
->elf
, rel
->r_offset
))
1391 /* Now carry out our orders. */
1392 if (need_entry
& NEED_GOT
)
1394 /* Allocate space for a GOT entry, as well as a dynamic
1395 relocation for this entry. */
1397 hplink
->root
.dynobj
= dynobj
= abfd
;
1399 if (hplink
->sgot
== NULL
)
1401 if (! elf32_hppa_create_dynamic_sections (dynobj
, info
))
1407 if (h
->elf
.got
.refcount
== -1)
1409 h
->elf
.got
.refcount
= 1;
1411 /* Make sure this symbol is output as a dynamic symbol. */
1412 if (h
->elf
.dynindx
== -1)
1414 if (! bfd_elf32_link_record_dynamic_symbol (info
,
1419 hplink
->sgot
->_raw_size
+= GOT_ENTRY_SIZE
;
1420 hplink
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
1423 h
->elf
.got
.refcount
+= 1;
1427 /* This is a global offset table entry for a local symbol. */
1428 if (local_got_refcounts
== NULL
)
1432 /* Allocate space for local got offsets and local
1433 plt offsets. Done this way to save polluting
1434 elf_obj_tdata with another target specific
1436 size
= symtab_hdr
->sh_info
* 2 * sizeof (bfd_signed_vma
);
1437 local_got_refcounts
= ((bfd_signed_vma
*)
1438 bfd_alloc (abfd
, size
));
1439 if (local_got_refcounts
== NULL
)
1441 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1442 memset (local_got_refcounts
, -1, size
);
1444 if (local_got_refcounts
[r_symndx
] == -1)
1446 local_got_refcounts
[r_symndx
] = 1;
1448 hplink
->sgot
->_raw_size
+= GOT_ENTRY_SIZE
;
1451 /* If we are generating a shared object, we need to
1452 output a reloc so that the dynamic linker can
1453 adjust this GOT entry (because the address
1454 the shared library is loaded at is not fixed). */
1455 hplink
->srelgot
->_raw_size
+=
1456 sizeof (Elf32_External_Rela
);
1460 local_got_refcounts
[r_symndx
] += 1;
1464 if (need_entry
& NEED_PLT
)
1466 /* If we are creating a shared library, and this is a reloc
1467 against a weak symbol or a global symbol in a dynamic
1468 object, then we will be creating an import stub and a
1469 .plt entry for the symbol. Similarly, on a normal link
1470 to symbols defined in a dynamic object we'll need the
1471 import stub and a .plt entry. We don't know yet whether
1472 the symbol is defined or not, so make an entry anyway and
1473 clean up later in adjust_dynamic_symbol. */
1474 if ((sec
->flags
& SEC_ALLOC
) != 0)
1478 if (h
->elf
.plt
.refcount
== -1)
1480 h
->elf
.plt
.refcount
= 1;
1481 h
->elf
.elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1484 h
->elf
.plt
.refcount
+= 1;
1486 /* If this .plt entry is for a plabel, we need an
1487 extra word for ld.so. adjust_dynamic_symbol will
1488 also keep the entry even if it appears to be
1490 if (need_entry
& PLT_PLABEL
)
1493 else if (need_entry
& PLT_PLABEL
)
1497 if (local_got_refcounts
== NULL
)
1501 /* Allocate space for local got offsets and local
1503 size
= symtab_hdr
->sh_info
* 2 * sizeof (bfd_signed_vma
);
1504 local_got_refcounts
= ((bfd_signed_vma
*)
1505 bfd_alloc (abfd
, size
));
1506 if (local_got_refcounts
== NULL
)
1508 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1509 memset (local_got_refcounts
, -1, size
);
1511 indx
= r_symndx
+ symtab_hdr
->sh_info
;
1512 if (local_got_refcounts
[indx
] == -1)
1513 local_got_refcounts
[indx
] = 1;
1515 local_got_refcounts
[indx
] += 1;
1520 if (need_entry
& (NEED_DYNREL
| NEED_STUBREL
))
1522 /* Flag this symbol as having a non-got, non-plt reference
1523 so that we generate copy relocs if it turns out to be
1526 h
->elf
.elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
1528 /* If we are creating a shared library then we need to copy
1529 the reloc into the shared library. However, if we are
1530 linking with -Bsymbolic, we need only copy absolute
1531 relocs or relocs against symbols that are not defined in
1532 an object we are including in the link. PC- or DP- or
1533 DLT-relative relocs against any local sym or global sym
1534 with DEF_REGULAR set, can be discarded. At this point we
1535 have not seen all the input files, so it is possible that
1536 DEF_REGULAR is not set now but will be set later (it is
1537 never cleared). We account for that possibility below by
1538 storing information in the reloc_entries field of the
1541 A similar situation to the -Bsymbolic case occurs when
1542 creating shared libraries and symbol visibility changes
1543 render the symbol local.
1545 As it turns out, all the relocs we will be creating here
1546 are absolute, so we cannot remove them on -Bsymbolic
1547 links or visibility changes anyway. A STUB_REL reloc
1548 is absolute too, as in that case it is the reloc in the
1549 stub we will be creating, rather than copying the PCREL
1550 reloc in the branch. */
1551 if ((sec
->flags
& SEC_ALLOC
) != 0
1553 #if RELATIVE_DYNAMIC_RELOCS
1555 || is_absolute_reloc (r_type
)
1557 && ((h
->elf
.elf_link_hash_flags
1558 & ELF_LINK_HASH_DEF_REGULAR
) == 0
1559 || h
->elf
.root
.type
== bfd_link_hash_defweak
)))
1567 if ((need_entry
& NEED_STUBREL
))
1570 /* Create a reloc section in dynobj and make room for
1577 hplink
->root
.dynobj
= dynobj
= abfd
;
1579 name
= bfd_elf_string_from_elf_section
1581 elf_elfheader (abfd
)->e_shstrndx
,
1582 elf_section_data (sec
)->rel_hdr
.sh_name
);
1585 (*_bfd_error_handler
)
1586 (_("Could not find relocation section for %s"),
1588 bfd_set_error (bfd_error_bad_value
);
1592 if ((need_entry
& NEED_STUBREL
))
1594 size_t len
= strlen (name
) + sizeof (STUB_SUFFIX
);
1595 char *newname
= bfd_malloc (len
);
1597 if (newname
== NULL
)
1599 strcpy (newname
, name
);
1600 strcpy (newname
+ len
- sizeof (STUB_SUFFIX
),
1605 srel
= bfd_get_section_by_name (dynobj
, name
);
1610 srel
= bfd_make_section (dynobj
, name
);
1611 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
1612 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1613 if ((sec
->flags
& SEC_ALLOC
) != 0)
1614 flags
|= SEC_ALLOC
| SEC_LOAD
;
1616 || !bfd_set_section_flags (dynobj
, srel
, flags
)
1617 || !bfd_set_section_alignment (dynobj
, srel
, 2))
1620 else if ((need_entry
& NEED_STUBREL
))
1623 if ((need_entry
& NEED_STUBREL
))
1629 #if ! LONG_BRANCH_PIC_IN_SHLIB
1630 /* If this is a function call, we only need one dynamic
1631 reloc for the stub as all calls to a particular
1632 function will go through the same stub. Actually, a
1633 long branch stub needs two relocations, but we count
1634 on some intelligence on the part of the dynamic
1636 if ((need_entry
& NEED_STUBREL
))
1638 doit
= h
->stub_reloc_sec
!= stubreloc
;
1639 h
->stub_reloc_sec
= stubreloc
;
1647 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
1649 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
1650 /* Keep track of relocations we have entered for
1651 this global symbol, so that we can discard them
1652 later if necessary. */
1655 #if RELATIVE_DYNAMIC_RELOCS
1656 || ! is_absolute_reloc (rtype
)
1658 || (need_entry
& NEED_STUBREL
)))
1660 struct elf32_hppa_dyn_reloc_entry
*p
;
1662 for (p
= h
->reloc_entries
; p
!= NULL
; p
= p
->next
)
1663 if (p
->section
== srel
)
1668 p
= ((struct elf32_hppa_dyn_reloc_entry
*)
1669 bfd_alloc (dynobj
, sizeof *p
));
1672 p
->next
= h
->reloc_entries
;
1673 h
->reloc_entries
= p
;
1678 /* NEED_STUBREL and NEED_DYNREL are never both
1679 set. Leave the count at zero for the
1680 NEED_STUBREL case as we only ever have one
1681 stub reloc per section per symbol, and this
1682 simplifies code in hppa_discard_copies. */
1683 if (! (need_entry
& NEED_STUBREL
))
1696 /* Return the section that should be marked against garbage collection
1697 for a given relocation. */
1700 elf32_hppa_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
1702 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1703 Elf_Internal_Rela
*rel
;
1704 struct elf_link_hash_entry
*h
;
1705 Elf_Internal_Sym
*sym
;
1709 switch ((unsigned int) ELF32_R_TYPE (rel
->r_info
))
1711 case R_PARISC_GNU_VTINHERIT
:
1712 case R_PARISC_GNU_VTENTRY
:
1716 switch (h
->root
.type
)
1718 case bfd_link_hash_defined
:
1719 case bfd_link_hash_defweak
:
1720 return h
->root
.u
.def
.section
;
1722 case bfd_link_hash_common
:
1723 return h
->root
.u
.c
.p
->section
;
1732 if (!(elf_bad_symtab (abfd
)
1733 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
1734 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
1735 && sym
->st_shndx
!= SHN_COMMON
))
1737 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
1745 /* Update the got and plt entry reference counts for the section being
1749 elf32_hppa_gc_sweep_hook (abfd
, info
, sec
, relocs
)
1751 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1753 const Elf_Internal_Rela
*relocs
;
1755 Elf_Internal_Shdr
*symtab_hdr
;
1756 struct elf_link_hash_entry
**sym_hashes
;
1757 bfd_signed_vma
*local_got_refcounts
;
1758 bfd_signed_vma
*local_plt_refcounts
;
1759 const Elf_Internal_Rela
*rel
, *relend
;
1760 unsigned long r_symndx
;
1761 struct elf_link_hash_entry
*h
;
1762 struct elf32_hppa_link_hash_table
*hplink
;
1767 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1768 sym_hashes
= elf_sym_hashes (abfd
);
1769 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1770 local_plt_refcounts
= local_got_refcounts
;
1771 if (local_plt_refcounts
!= NULL
)
1772 local_plt_refcounts
+= symtab_hdr
->sh_info
;
1773 hplink
= hppa_link_hash_table (info
);
1774 dynobj
= hplink
->root
.dynobj
;
1778 sgot
= hplink
->sgot
;
1779 srelgot
= hplink
->srelgot
;
1781 relend
= relocs
+ sec
->reloc_count
;
1782 for (rel
= relocs
; rel
< relend
; rel
++)
1783 switch ((unsigned int) ELF32_R_TYPE (rel
->r_info
))
1785 case R_PARISC_DLTIND14F
:
1786 case R_PARISC_DLTIND14R
:
1787 case R_PARISC_DLTIND21L
:
1788 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1789 if (r_symndx
>= symtab_hdr
->sh_info
)
1791 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1792 if (h
->got
.refcount
> 0)
1794 h
->got
.refcount
-= 1;
1795 if (h
->got
.refcount
== 0)
1797 sgot
->_raw_size
-= GOT_ENTRY_SIZE
;
1798 srelgot
->_raw_size
-= sizeof (Elf32_External_Rela
);
1802 else if (local_got_refcounts
!= NULL
)
1804 if (local_got_refcounts
[r_symndx
] > 0)
1806 local_got_refcounts
[r_symndx
] -= 1;
1807 if (local_got_refcounts
[r_symndx
] == 0)
1809 sgot
->_raw_size
-= GOT_ENTRY_SIZE
;
1811 srelgot
->_raw_size
-= sizeof (Elf32_External_Rela
);
1817 case R_PARISC_PCREL12F
:
1818 case R_PARISC_PCREL17C
:
1819 case R_PARISC_PCREL17F
:
1820 case R_PARISC_PCREL22F
:
1821 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1822 if (r_symndx
>= symtab_hdr
->sh_info
)
1824 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1825 if (h
->plt
.refcount
> 0)
1826 h
->plt
.refcount
-= 1;
1830 case R_PARISC_PLABEL14R
:
1831 case R_PARISC_PLABEL21L
:
1832 case R_PARISC_PLABEL32
:
1833 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1834 if (r_symndx
>= symtab_hdr
->sh_info
)
1836 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1837 if (h
->plt
.refcount
> 0)
1838 h
->plt
.refcount
-= 1;
1840 else if (local_plt_refcounts
!= NULL
)
1842 if (local_plt_refcounts
[r_symndx
] > 0)
1843 local_plt_refcounts
[r_symndx
] -= 1;
1855 /* Our own version of hide_symbol, so that we can keep plt entries for
1859 elf32_hppa_hide_symbol (info
, h
)
1860 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1861 struct elf_link_hash_entry
*h
;
1864 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
)
1866 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1867 h
->plt
.offset
= (bfd_vma
) -1;
1872 /* Adjust a symbol defined by a dynamic object and referenced by a
1873 regular object. The current definition is in some section of the
1874 dynamic object, but we're not including those sections. We have to
1875 change the definition to something the rest of the link can
1879 elf32_hppa_adjust_dynamic_symbol (info
, h
)
1880 struct bfd_link_info
*info
;
1881 struct elf_link_hash_entry
*h
;
1884 struct elf32_hppa_link_hash_table
*hplink
;
1887 hplink
= hppa_link_hash_table (info
);
1888 dynobj
= hplink
->root
.dynobj
;
1890 /* If this is a function, put it in the procedure linkage table. We
1891 will fill in the contents of the procedure linkage table later,
1892 when we know the address of the .got section. */
1893 if (h
->type
== STT_FUNC
1894 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1896 if (h
->plt
.refcount
<= 0
1897 || ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
1898 && h
->root
.type
!= bfd_link_hash_defweak
1899 && ! ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
1900 && (!info
->shared
|| info
->symbolic
)))
1902 /* The .plt entry is not needed when:
1903 a) Garbage collection has removed all references to the
1905 b) We know for certain the symbol is defined in this
1906 object, and it's not a weak definition, nor is the symbol
1907 used by a plabel relocation. Either this object is the
1908 application or we are doing a shared symbolic link. */
1910 /* As a special sop to the hppa ABI, we keep a .plt entry
1911 for functions in sections containing PIC code. */
1913 && h
->plt
.refcount
> 0
1914 && (h
->root
.type
== bfd_link_hash_defined
1915 || h
->root
.type
== bfd_link_hash_defweak
)
1916 && (h
->root
.u
.def
.section
->flags
& SEC_HAS_GOT_REF
) != 0)
1918 ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
= 1;
1922 h
->plt
.offset
= (bfd_vma
) -1;
1923 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1928 /* Make an entry in the .plt section. */
1930 h
->plt
.offset
= s
->_raw_size
;
1931 if (PLABEL_PLT_ENTRY_SIZE
!= PLT_ENTRY_SIZE
1932 && ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
1933 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1935 /* Add some extra space for the dynamic linker to use. */
1936 s
->_raw_size
+= PLABEL_PLT_ENTRY_SIZE
;
1939 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1941 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
)
1943 /* Make sure this symbol is output as a dynamic symbol. */
1944 if (h
->dynindx
== -1
1945 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
1947 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1951 /* We also need to make an entry in the .rela.plt section. */
1952 s
= hplink
->srelplt
;
1953 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
1958 /* If this is a weak symbol, and there is a real definition, the
1959 processor independent code will have arranged for us to see the
1960 real definition first, and we can just use the same value. */
1961 if (h
->weakdef
!= NULL
)
1963 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
1964 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
1965 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1966 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1970 /* This is a reference to a symbol defined by a dynamic object which
1971 is not a function. */
1973 /* If we are creating a shared library, we must presume that the
1974 only references to the symbol are via the global offset table.
1975 For such cases we need not do anything here; the relocations will
1976 be handled correctly by relocate_section. */
1980 /* If there are no references to this symbol that do not use the
1981 GOT, we don't need to generate a copy reloc. */
1982 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
1985 /* We must allocate the symbol in our .dynbss section, which will
1986 become part of the .bss section of the executable. There will be
1987 an entry for this symbol in the .dynsym section. The dynamic
1988 object will contain position independent code, so all references
1989 from the dynamic object to this symbol will go through the global
1990 offset table. The dynamic linker will use the .dynsym entry to
1991 determine the address it must put in the global offset table, so
1992 both the dynamic object and the regular object will refer to the
1993 same memory location for the variable. */
1995 s
= hplink
->sdynbss
;
1997 /* We must generate a COPY reloc to tell the dynamic linker to
1998 copy the initial value out of the dynamic object and into the
1999 runtime process image. We need to remember the offset into the
2000 .rela.bss section we are going to use. */
2001 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2005 srel
= hplink
->srelbss
;
2006 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
2007 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
2011 /* We need to figure out the alignment required for this symbol. I
2012 have no idea how other ELF linkers handle this. */
2013 unsigned int power_of_two
;
2015 power_of_two
= bfd_log2 (h
->size
);
2016 if (power_of_two
> 3)
2019 /* Apply the required alignment. */
2020 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
2021 (bfd_size_type
) (1 << power_of_two
));
2022 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
2024 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
2028 /* Define the symbol as being at this point in the section. */
2029 h
->root
.u
.def
.section
= s
;
2030 h
->root
.u
.def
.value
= s
->_raw_size
;
2032 /* Increment the section size to make room for the symbol. */
2033 s
->_raw_size
+= h
->size
;
2039 /* Called via elf_link_hash_traverse to create .plt entries for an
2040 application that uses statically linked PIC functions. Similar to
2041 the first part of elf32_hppa_adjust_dynamic_symbol. */
2044 hppa_handle_PIC_calls (h
, inf
)
2045 struct elf_link_hash_entry
*h
;
2048 struct bfd_link_info
*info
;
2050 struct elf32_hppa_link_hash_table
*hplink
;
2053 if (! (h
->plt
.refcount
> 0
2054 && (h
->root
.type
== bfd_link_hash_defined
2055 || h
->root
.type
== bfd_link_hash_defweak
)
2056 && (h
->root
.u
.def
.section
->flags
& SEC_HAS_GOT_REF
) != 0))
2058 h
->plt
.offset
= (bfd_vma
) -1;
2059 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2063 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2064 ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
= 1;
2066 info
= (struct bfd_link_info
*) inf
;
2067 hplink
= hppa_link_hash_table (info
);
2068 dynobj
= hplink
->root
.dynobj
;
2070 /* Make an entry in the .plt section. */
2072 h
->plt
.offset
= s
->_raw_size
;
2073 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2079 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
2080 || RELATIVE_DYNAMIC_RELOCS)
2081 /* This function is called via elf_link_hash_traverse to discard space
2082 we allocated for relocs that it turned out we didn't need. */
2085 hppa_discard_copies (h
, inf
)
2086 struct elf_link_hash_entry
*h
;
2089 struct elf32_hppa_dyn_reloc_entry
*s
;
2090 struct elf32_hppa_link_hash_entry
*eh
;
2091 struct bfd_link_info
*info
;
2093 eh
= (struct elf32_hppa_link_hash_entry
*) h
;
2094 info
= (struct bfd_link_info
*) inf
;
2096 #if ! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT
2097 /* Handle the stub reloc case. If we have a plt entry for the
2098 function, we won't be needing long branch stubs. s->count will
2099 only be zero for stub relocs, which provides a handy way of
2100 flagging these relocs, and means we need do nothing special for
2101 the forced local and symbolic link case. */
2102 if (eh
->stub_reloc_sec
!= NULL
2103 && eh
->elf
.plt
.offset
!= (bfd_vma
) -1)
2105 for (s
= eh
->reloc_entries
; s
!= NULL
; s
= s
->next
)
2107 s
->section
->_raw_size
-= sizeof (Elf32_External_Rela
);
2111 #if RELATIVE_DYNAMIC_RELOCS
2112 /* If a symbol has been forced local or we have found a regular
2113 definition for the symbolic link case, then we won't be needing
2115 if (eh
->elf
.dynindx
== -1
2116 || ((eh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
2117 && eh
->elf
.root
.type
!= bfd_link_hash_defweak
2120 for (s
= eh
->reloc_entries
; s
!= NULL
; s
= s
->next
)
2121 s
->section
->_raw_size
-= s
->count
* sizeof (Elf32_External_Rela
);
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 /* DT_INIT and DT_FINI need a .plt entry. Make sure they have
2163 funcname
= info
->init_function
;
2166 if (funcname
!= NULL
)
2168 struct elf_link_hash_entry
*h
;
2170 h
= elf_link_hash_lookup (&hplink
->root
,
2172 false, false, false);
2174 && (h
->elf_link_hash_flags
& (ELF_LINK_HASH_REF_REGULAR
2175 | ELF_LINK_HASH_DEF_REGULAR
)))
2177 if (h
->plt
.refcount
<= 0)
2179 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2181 /* Make an entry in the .plt section. We know
2182 the function doesn't have a plabel by the
2185 h
->plt
.offset
= s
->_raw_size
;
2186 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2188 /* Make sure this symbol is output as a dynamic
2190 if (h
->dynindx
== -1)
2192 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
2196 /* Make an entry for the reloc too. */
2197 s
= hplink
->srelplt
;
2198 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
2201 ((struct elf32_hppa_link_hash_entry
*) h
)->plt_abs
= 1;
2204 if (funcname
== info
->fini_function
)
2206 funcname
= info
->fini_function
;
2209 /* Set up .plt offsets for local plabels. */
2210 for (i
= info
->input_bfds
; i
; i
= i
->link_next
)
2212 bfd_signed_vma
*local_plt
;
2213 bfd_signed_vma
*end_local_plt
;
2214 bfd_size_type locsymcount
;
2215 Elf_Internal_Shdr
*symtab_hdr
;
2217 local_plt
= elf_local_got_refcounts (i
);
2221 symtab_hdr
= &elf_tdata (i
)->symtab_hdr
;
2222 locsymcount
= symtab_hdr
->sh_info
;
2223 local_plt
+= locsymcount
;
2224 end_local_plt
= local_plt
+ locsymcount
;
2226 for (; local_plt
< end_local_plt
; ++local_plt
)
2231 *local_plt
= s
->_raw_size
;
2232 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2234 hplink
->srelplt
->_raw_size
+= sizeof (Elf32_External_Rela
);
2237 *local_plt
= (bfd_vma
) -1;
2243 /* Run through the function symbols, looking for any that are
2244 PIC, and allocate space for the necessary .plt entries so
2245 that %r19 will be set up. */
2247 elf_link_hash_traverse (&hplink
->root
,
2248 hppa_handle_PIC_calls
,
2251 /* We may have created entries in the .rela.got section.
2252 However, if we are not creating the dynamic sections, we will
2253 not actually use these entries. Reset the size of .rela.got,
2254 which will cause it to get stripped from the output file
2256 hplink
->srelgot
->_raw_size
= 0;
2259 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
2260 || RELATIVE_DYNAMIC_RELOCS)
2261 /* If this is a -Bsymbolic shared link, then we need to discard all
2262 relocs against symbols defined in a regular object. We also need
2263 to lose relocs we've allocated for long branch stubs if we know
2264 we won't be generating a stub. */
2266 elf_link_hash_traverse (&hplink
->root
,
2267 hppa_discard_copies
,
2271 /* The check_relocs and adjust_dynamic_symbol entry points have
2272 determined the sizes of the various dynamic sections. Allocate
2276 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2280 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2283 /* It's OK to base decisions on the section name, because none
2284 of the dynobj section names depend upon the input files. */
2285 name
= bfd_get_section_name (dynobj
, s
);
2287 if (strncmp (name
, ".rela", 5) == 0)
2289 if (s
->_raw_size
!= 0)
2293 /* Remember whether there are any reloc sections other
2295 if (strcmp (name
+5, ".plt") != 0)
2297 const char *outname
;
2301 /* If this relocation section applies to a read only
2302 section, then we probably need a DT_TEXTREL
2303 entry. The entries in the .rela.plt section
2304 really apply to the .got section, which we
2305 created ourselves and so know is not readonly. */
2306 outname
= bfd_get_section_name (output_bfd
,
2308 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
2310 && (target
->flags
& SEC_READONLY
) != 0
2311 && (target
->flags
& SEC_ALLOC
) != 0)
2315 /* We use the reloc_count field as a counter if we need
2316 to copy relocs into the output file. */
2320 else if (strcmp (name
, ".plt") == 0)
2322 else if (strcmp (name
, ".got") == 0)
2326 /* It's not one of our sections, so don't allocate space. */
2330 if (s
->_raw_size
== 0)
2332 /* If we don't need this section, strip it from the
2333 output file. This is mostly to handle .rela.bss and
2334 .rela.plt. We must create both sections in
2335 create_dynamic_sections, because they must be created
2336 before the linker maps input sections to output
2337 sections. The linker does that before
2338 adjust_dynamic_symbol is called, and it is that
2339 function which decides whether anything needs to go
2340 into these sections. */
2341 _bfd_strip_section_from_output (info
, s
);
2345 /* Allocate memory for the section contents. Zero it, because
2346 we may not fill in all the reloc sections. */
2347 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
2348 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
2352 if (hplink
->root
.dynamic_sections_created
)
2354 /* Like IA-64 and HPPA64, always create a DT_PLTGOT. It
2355 actually has nothing to do with the PLT, it is how we
2356 communicate the LTP value of a load module to the dynamic
2358 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
2361 /* Add some entries to the .dynamic section. We fill in the
2362 values later, in elf32_hppa_finish_dynamic_sections, but we
2363 must add the entries now so that we get the correct size for
2364 the .dynamic section. The DT_DEBUG entry is filled in by the
2365 dynamic linker and used by the debugger. */
2368 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
2372 if (hplink
->srelplt
->_raw_size
!= 0)
2374 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
2375 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
2376 || ! bfd_elf32_add_dynamic_entry (info
, DT_JMPREL
, 0))
2382 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELA
, 0)
2383 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELASZ
, 0)
2384 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELAENT
,
2385 sizeof (Elf32_External_Rela
)))
2391 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
2393 info
->flags
|= DF_TEXTREL
;
2401 /* External entry points for sizing and building linker stubs. */
2403 /* Determine and set the size of the stub section for a final link.
2405 The basic idea here is to examine all the relocations looking for
2406 PC-relative calls to a target that is unreachable with a "bl"
2410 elf32_hppa_size_stubs (stub_bfd
, multi_subspace
, info
,
2411 add_stub_section
, layout_sections_again
)
2413 boolean multi_subspace
;
2414 struct bfd_link_info
*info
;
2415 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
2416 void (*layout_sections_again
) PARAMS ((void));
2420 Elf_Internal_Sym
*local_syms
, **all_local_syms
;
2421 unsigned int i
, indx
, bfd_count
, sec_count
;
2422 struct elf32_hppa_link_hash_table
*hplink
;
2423 boolean stub_changed
= 0;
2425 hplink
= hppa_link_hash_table (info
);
2427 /* Stash our params away. */
2428 hplink
->stub_bfd
= stub_bfd
;
2429 hplink
->multi_subspace
= multi_subspace
;
2430 hplink
->add_stub_section
= add_stub_section
;
2431 hplink
->layout_sections_again
= layout_sections_again
;
2433 /* Count the number of input BFDs and the total number of input sections. */
2434 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, sec_count
= 0;
2436 input_bfd
= input_bfd
->link_next
)
2439 sec_count
+= input_bfd
->section_count
;
2442 hplink
->stub_section_created
2443 = (asection
**) bfd_zmalloc (sizeof (asection
*) * sec_count
);
2444 if (hplink
->stub_section_created
== NULL
)
2447 #if ! LONG_BRANCH_PIC_IN_SHLIB
2448 hplink
->reloc_section_created
2449 = (asection
**) bfd_zmalloc (sizeof (asection
*) * sec_count
);
2450 if (hplink
->reloc_section_created
== NULL
)
2451 goto error_ret_free_stub
;
2454 /* We want to read in symbol extension records only once. To do this
2455 we need to read in the local symbols in parallel and save them for
2456 later use; so hold pointers to the local symbols in an array. */
2458 = (Elf_Internal_Sym
**) bfd_zmalloc (sizeof (Elf_Internal_Sym
*)
2460 if (all_local_syms
== NULL
)
2461 goto error_ret_free_reloc
;
2463 /* Walk over all the input BFDs, swapping in local symbols.
2464 If we are creating a shared library, create hash entries for the
2466 for (input_bfd
= info
->input_bfds
, indx
= 0, sec_count
= 0;
2468 input_bfd
= input_bfd
->link_next
, indx
++)
2470 Elf_Internal_Shdr
*symtab_hdr
;
2471 Elf_Internal_Sym
*isym
;
2472 Elf32_External_Sym
*ext_syms
, *esym
;
2474 /* We'll need the symbol table in a second. */
2475 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2476 if (symtab_hdr
->sh_info
== 0)
2479 /* We need an array of the local symbols attached to the input bfd.
2480 Unfortunately, we're going to have to read & swap them in. */
2481 local_syms
= (Elf_Internal_Sym
*)
2482 bfd_malloc (symtab_hdr
->sh_info
* sizeof (Elf_Internal_Sym
));
2483 if (local_syms
== NULL
)
2485 goto error_ret_free_local
;
2487 all_local_syms
[indx
] = local_syms
;
2488 ext_syms
= (Elf32_External_Sym
*)
2489 bfd_malloc (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
));
2490 if (ext_syms
== NULL
)
2492 goto error_ret_free_local
;
2495 if (bfd_seek (input_bfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
2496 || (bfd_read (ext_syms
, 1,
2497 (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
)),
2499 != (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
))))
2502 goto error_ret_free_local
;
2505 /* Swap the local symbols in. */
2508 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++, esym
++, isym
++)
2509 bfd_elf32_swap_symbol_in (input_bfd
, esym
, isym
);
2511 /* Now we can free the external symbols. */
2514 if (info
->shared
&& hplink
->multi_subspace
)
2516 unsigned int symndx
;
2517 unsigned int symcount
;
2519 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
2520 - symtab_hdr
->sh_info
);
2522 /* Look through the global syms for functions; We need to
2523 build export stubs for all globally visible functions. */
2524 for (symndx
= 0; symndx
< symcount
; symndx
++)
2526 struct elf32_hppa_link_hash_entry
*hash
;
2528 hash
= ((struct elf32_hppa_link_hash_entry
*)
2529 elf_sym_hashes (input_bfd
)[symndx
]);
2531 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
2532 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
2533 hash
= ((struct elf32_hppa_link_hash_entry
*)
2534 hash
->elf
.root
.u
.i
.link
);
2536 /* At this point in the link, undefined syms have been
2537 resolved, so we need to check that the symbol was
2538 defined in this BFD. */
2539 if ((hash
->elf
.root
.type
== bfd_link_hash_defined
2540 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
2541 && hash
->elf
.type
== STT_FUNC
2542 && hash
->elf
.root
.u
.def
.section
->output_section
!= NULL
2543 && hash
->elf
.root
.u
.def
.section
->owner
== input_bfd
2544 && (hash
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
2545 && !(hash
->elf
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
2546 && ELF_ST_VISIBILITY (hash
->elf
.other
) == STV_DEFAULT
)
2549 const char *stub_name
;
2550 struct elf32_hppa_stub_hash_entry
*stub_entry
;
2552 sec
= hash
->elf
.root
.u
.def
.section
;
2553 stub_name
= hash
->elf
.root
.root
.string
;
2554 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
,
2557 if (stub_entry
== NULL
)
2559 stub_entry
= hppa_add_stub (stub_name
,
2561 sec_count
+ sec
->index
,
2564 goto error_ret_free_local
;
2566 stub_entry
->target_value
= hash
->elf
.root
.u
.def
.value
;
2567 stub_entry
->target_section
= hash
->elf
.root
.u
.def
.section
;
2568 stub_entry
->stub_type
= hppa_stub_export
;
2569 stub_entry
->h
= hash
;
2574 (*_bfd_error_handler
) (_("%s: duplicate export stub %s"),
2575 bfd_get_filename (input_bfd
),
2581 #if LONG_BRANCH_PIC_IN_SHLIB
2582 sec_count
+= input_bfd
->section_count
;
2585 sec_count
+= input_bfd
->section_count
;
2587 for (section
= input_bfd
->sections
;
2589 section
= section
->next
, sec_count
++)
2592 asection
*reloc_sec
;
2594 name
= bfd_malloc (strlen (section
->name
)
2595 + sizeof STUB_SUFFIX
2599 sprintf (name
, ".rela%s%s", section
->name
, STUB_SUFFIX
);
2600 reloc_sec
= bfd_get_section_by_name (hplink
->root
.dynobj
, name
);
2601 hplink
->reloc_section_created
[sec_count
] = reloc_sec
;
2611 for (input_bfd
= info
->input_bfds
, indx
= 0, sec_count
= 0;
2613 input_bfd
= input_bfd
->link_next
, indx
++)
2615 Elf_Internal_Shdr
*symtab_hdr
;
2617 /* We'll need the symbol table in a second. */
2618 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2619 if (symtab_hdr
->sh_info
== 0)
2622 local_syms
= all_local_syms
[indx
];
2624 /* Walk over each section attached to the input bfd. */
2625 for (section
= input_bfd
->sections
;
2627 section
= section
->next
, sec_count
++)
2629 Elf_Internal_Shdr
*input_rel_hdr
;
2630 Elf32_External_Rela
*external_relocs
, *erelaend
, *erela
;
2631 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
2633 /* If there aren't any relocs, then there's nothing more
2635 if ((section
->flags
& SEC_RELOC
) == 0
2636 || section
->reloc_count
== 0)
2639 /* Allocate space for the external relocations. */
2641 = ((Elf32_External_Rela
*)
2642 bfd_malloc (section
->reloc_count
2643 * sizeof (Elf32_External_Rela
)));
2644 if (external_relocs
== NULL
)
2646 goto error_ret_free_local
;
2649 /* Likewise for the internal relocations. */
2650 internal_relocs
= ((Elf_Internal_Rela
*)
2651 bfd_malloc (section
->reloc_count
2652 * sizeof (Elf_Internal_Rela
)));
2653 if (internal_relocs
== NULL
)
2655 free (external_relocs
);
2656 goto error_ret_free_local
;
2659 /* Read in the external relocs. */
2660 input_rel_hdr
= &elf_section_data (section
)->rel_hdr
;
2661 if (bfd_seek (input_bfd
, input_rel_hdr
->sh_offset
, SEEK_SET
) != 0
2662 || bfd_read (external_relocs
, 1,
2663 input_rel_hdr
->sh_size
,
2664 input_bfd
) != input_rel_hdr
->sh_size
)
2666 free (external_relocs
);
2667 error_ret_free_internal
:
2668 free (internal_relocs
);
2669 goto error_ret_free_local
;
2672 /* Swap in the relocs. */
2673 erela
= external_relocs
;
2674 erelaend
= erela
+ section
->reloc_count
;
2675 irela
= internal_relocs
;
2676 for (; erela
< erelaend
; erela
++, irela
++)
2677 bfd_elf32_swap_reloca_in (input_bfd
, erela
, irela
);
2679 /* We're done with the external relocs, free them. */
2680 free (external_relocs
);
2682 /* Now examine each relocation. */
2683 irela
= internal_relocs
;
2684 irelaend
= irela
+ section
->reloc_count
;
2685 for (; irela
< irelaend
; irela
++)
2687 unsigned int r_type
, r_indx
;
2688 enum elf32_hppa_stub_type stub_type
;
2689 struct elf32_hppa_stub_hash_entry
*stub_entry
;
2692 bfd_vma destination
;
2693 struct elf32_hppa_link_hash_entry
*hash
;
2696 r_type
= ELF32_R_TYPE (irela
->r_info
);
2697 r_indx
= ELF32_R_SYM (irela
->r_info
);
2699 if (r_type
>= (unsigned int) R_PARISC_UNIMPLEMENTED
)
2701 bfd_set_error (bfd_error_bad_value
);
2702 goto error_ret_free_internal
;
2705 /* Only look for stubs on call instructions. */
2706 if (r_type
!= (unsigned int) R_PARISC_PCREL12F
2707 && r_type
!= (unsigned int) R_PARISC_PCREL17F
2708 && r_type
!= (unsigned int) R_PARISC_PCREL22F
)
2711 /* Now determine the call target, its name, value,
2717 if (r_indx
< symtab_hdr
->sh_info
)
2719 /* It's a local symbol. */
2720 Elf_Internal_Sym
*sym
;
2721 Elf_Internal_Shdr
*hdr
;
2723 sym
= local_syms
+ r_indx
;
2724 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
2725 sym_sec
= hdr
->bfd_section
;
2726 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
2727 sym_value
= sym
->st_value
;
2728 destination
= (sym_value
+ irela
->r_addend
2729 + sym_sec
->output_offset
2730 + sym_sec
->output_section
->vma
);
2734 /* It's an external symbol. */
2737 e_indx
= r_indx
- symtab_hdr
->sh_info
;
2738 hash
= ((struct elf32_hppa_link_hash_entry
*)
2739 elf_sym_hashes (input_bfd
)[e_indx
]);
2741 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
2742 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
2743 hash
= ((struct elf32_hppa_link_hash_entry
*)
2744 hash
->elf
.root
.u
.i
.link
);
2746 if (hash
->elf
.root
.type
== bfd_link_hash_defined
2747 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
2749 sym_sec
= hash
->elf
.root
.u
.def
.section
;
2750 sym_value
= hash
->elf
.root
.u
.def
.value
;
2751 if (sym_sec
->output_section
!= NULL
)
2752 destination
= (sym_value
+ irela
->r_addend
2753 + sym_sec
->output_offset
2754 + sym_sec
->output_section
->vma
);
2756 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
)
2761 else if (hash
->elf
.root
.type
== bfd_link_hash_undefined
)
2764 && !info
->no_undefined
2765 && (ELF_ST_VISIBILITY (hash
->elf
.other
)
2771 bfd_set_error (bfd_error_bad_value
);
2772 goto error_ret_free_internal
;
2776 /* Determine what (if any) linker stub is needed. */
2777 stub_type
= hppa_type_of_stub (section
, irela
, hash
,
2779 if (stub_type
== hppa_stub_none
)
2782 /* Get the name of this stub. */
2783 stub_name
= hppa_stub_name (section
, sym_sec
, hash
, irela
);
2785 goto error_ret_free_internal
;
2787 stub_entry
= hppa_stub_hash_lookup (&hplink
->stub_hash_table
,
2790 if (stub_entry
!= NULL
)
2792 /* The proper stub has already been created. */
2797 stub_entry
= hppa_add_stub (stub_name
, section
,
2799 if (stub_entry
== NULL
)
2802 goto error_ret_free_local
;
2805 stub_entry
->target_value
= sym_value
;
2806 stub_entry
->target_section
= sym_sec
;
2807 stub_entry
->stub_type
= stub_type
;
2810 if (stub_type
== hppa_stub_import
)
2811 stub_entry
->stub_type
= hppa_stub_import_shared
;
2812 else if (stub_type
== hppa_stub_long_branch
2813 && (LONG_BRANCH_PIC_IN_SHLIB
|| hash
== NULL
))
2814 stub_entry
->stub_type
= hppa_stub_long_branch_shared
;
2816 stub_entry
->h
= hash
;
2820 /* We're done with the internal relocs, free them. */
2821 free (internal_relocs
);
2828 /* OK, we've added some stubs. Find out the new size of the
2830 for (stub_sec
= hplink
->stub_bfd
->sections
;
2832 stub_sec
= stub_sec
->next
)
2834 stub_sec
->_raw_size
= 0;
2835 stub_sec
->_cooked_size
= 0;
2837 #if ! LONG_BRANCH_PIC_IN_SHLIB
2838 for (i
= 0; i
< sec_count
; i
++)
2840 stub_sec
= hplink
->reloc_section_created
[i
];
2841 if (stub_sec
!= NULL
)
2843 stub_sec
->_raw_size
= 0;
2844 stub_sec
->_cooked_size
= 0;
2849 bfd_hash_traverse (&hplink
->stub_hash_table
,
2853 /* Ask the linker to do its stuff. */
2854 (*hplink
->layout_sections_again
) ();
2858 /* We're done with the local symbols, free them. */
2859 for (i
= 0; i
< bfd_count
; i
++)
2860 if (all_local_syms
[i
])
2861 free (all_local_syms
[i
]);
2862 free (all_local_syms
);
2863 #if ! LONG_BRANCH_PIC_IN_SHLIB
2864 free (hplink
->reloc_section_created
);
2866 free (hplink
->stub_section_created
);
2869 error_ret_free_local
:
2870 for (i
= 0; i
< bfd_count
; i
++)
2871 if (all_local_syms
[i
])
2872 free (all_local_syms
[i
]);
2873 free (all_local_syms
);
2875 error_ret_free_reloc
:
2876 #if ! LONG_BRANCH_PIC_IN_SHLIB
2877 free (hplink
->reloc_section_created
);
2878 error_ret_free_stub
:
2880 free (hplink
->stub_section_created
);
2885 /* For a final link, this function is called after we have sized the
2886 stubs to provide a value for __gp. */
2889 elf32_hppa_set_gp (abfd
, info
)
2891 struct bfd_link_info
*info
;
2893 struct elf32_hppa_link_hash_table
*hplink
;
2894 struct elf_link_hash_entry
*h
;
2898 hplink
= hppa_link_hash_table (info
);
2899 h
= elf_link_hash_lookup (&hplink
->root
, "$global$",
2900 false, false, false);
2902 if (h
!= NULL
&& h
->root
.type
== bfd_link_hash_defined
)
2904 gp_val
= h
->root
.u
.def
.value
;
2905 sec
= h
->root
.u
.def
.section
;
2909 /* Choose to point our LTP at, in this order, one of .plt, .got,
2910 or .data, if these sections exist. In the case of choosing
2911 .plt try to make the LTP ideal for addressing anywhere in the
2912 .plt or .got with a 14 bit signed offset. Typically, the end
2913 of the .plt is the start of the .got, so choose .plt + 0x2000
2914 if either the .plt or .got is larger than 0x2000. If both
2915 the .plt and .got are smaller than 0x2000, choose the end of
2916 the .plt section. */
2921 gp_val
= sec
->_raw_size
;
2923 || (hplink
->sgot
&& hplink
->sgot
->_raw_size
> 0x2000))
2934 /* We know we don't have a .plt. If .got is large,
2936 if (sec
->_raw_size
> 0x2000)
2941 /* No .plt or .got. Who cares what the LTP is? */
2942 sec
= bfd_get_section_by_name (abfd
, ".data");
2948 gp_val
+= sec
->output_section
->vma
+ sec
->output_offset
;
2950 elf_gp (abfd
) = gp_val
;
2955 /* Build all the stubs associated with the current output file. The
2956 stubs are kept in a hash table attached to the main linker hash
2957 table. We also set up the .plt entries for statically linked PIC
2958 functions here. This function is called via hppaelf_finish in the
2962 elf32_hppa_build_stubs (info
)
2963 struct bfd_link_info
*info
;
2966 struct bfd_hash_table
*table
;
2967 struct elf32_hppa_link_hash_table
*hplink
;
2969 hplink
= hppa_link_hash_table (info
);
2971 for (stub_sec
= hplink
->stub_bfd
->sections
;
2973 stub_sec
= stub_sec
->next
)
2977 /* Allocate memory to hold the linker stubs. */
2978 size
= stub_sec
->_raw_size
;
2979 stub_sec
->contents
= (unsigned char *) bfd_zalloc (hplink
->stub_bfd
,
2981 if (stub_sec
->contents
== NULL
&& size
!= 0)
2983 stub_sec
->_raw_size
= 0;
2986 /* Build the stubs as directed by the stub hash table. */
2987 table
= &hplink
->stub_hash_table
;
2988 bfd_hash_traverse (table
, hppa_build_one_stub
, info
);
2994 /* Perform a relocation as part of a final link. */
2996 static bfd_reloc_status_type
2997 final_link_relocate (input_section
, contents
, rel
, value
, info
, sym_sec
, h
)
2998 asection
*input_section
;
3000 const Elf_Internal_Rela
*rel
;
3002 struct bfd_link_info
*info
;
3004 struct elf32_hppa_link_hash_entry
*h
;
3007 unsigned int r_type
= ELF32_R_TYPE (rel
->r_info
);
3008 reloc_howto_type
*howto
= elf_hppa_howto_table
+ r_type
;
3009 int r_format
= howto
->bitsize
;
3010 enum hppa_reloc_field_selector_type_alt r_field
;
3011 bfd
*input_bfd
= input_section
->owner
;
3012 bfd_vma offset
= rel
->r_offset
;
3013 bfd_vma max_branch_offset
= 0;
3014 bfd_byte
*hit_data
= contents
+ offset
;
3015 bfd_signed_vma addend
= rel
->r_addend
;
3017 struct elf32_hppa_stub_hash_entry
*stub_entry
= NULL
;
3020 if (r_type
== R_PARISC_NONE
)
3021 return bfd_reloc_ok
;
3023 insn
= bfd_get_32 (input_bfd
, hit_data
);
3025 /* Find out where we are and where we're going. */
3026 location
= (offset
+
3027 input_section
->output_offset
+
3028 input_section
->output_section
->vma
);
3032 case R_PARISC_PCREL12F
:
3033 case R_PARISC_PCREL17F
:
3034 case R_PARISC_PCREL22F
:
3035 /* If this is a call to a function defined in another dynamic
3036 library, or if it is a call to a PIC function in the same
3037 object, or if this is a shared link and it is a call to a
3038 weak symbol which may or may not be in the same object, then
3039 find the import stub in the stub hash. */
3041 || sym_sec
->output_section
== NULL
3044 || (h
->elf
.root
.type
== bfd_link_hash_defweak
3045 && h
->elf
.dynindx
!= -1
3046 && h
->elf
.plt
.offset
!= (bfd_vma
) -1))))
3048 stub_entry
= hppa_get_stub_entry (input_section
, sym_sec
,
3050 if (stub_entry
!= NULL
)
3052 value
= (stub_entry
->stub_offset
3053 + stub_entry
->stub_sec
->output_offset
3054 + stub_entry
->stub_sec
->output_section
->vma
);
3057 else if (sym_sec
== NULL
&& h
!= NULL
3058 && h
->elf
.root
.type
== bfd_link_hash_undefweak
)
3060 /* It's OK if undefined weak. Make undefined weak
3061 branches go nowhere. */
3066 return bfd_reloc_notsupported
;
3070 case R_PARISC_PCREL21L
:
3071 case R_PARISC_PCREL17C
:
3072 case R_PARISC_PCREL17R
:
3073 case R_PARISC_PCREL14R
:
3074 case R_PARISC_PCREL14F
:
3075 /* Make it a pc relative offset. */
3080 case R_PARISC_DPREL21L
:
3081 case R_PARISC_DPREL14R
:
3082 case R_PARISC_DPREL14F
:
3083 /* For all the DP relative relocations, we need to examine the symbol's
3084 section. If it's a code section, then "data pointer relative" makes
3085 no sense. In that case we don't adjust the "value", and for 21 bit
3086 addil instructions, we change the source addend register from %dp to
3087 %r0. This situation commonly arises when a variable's "constness"
3088 is declared differently from the way the variable is defined. For
3089 instance: "extern int foo" with foo defined as "const int foo". */
3090 if (sym_sec
== NULL
)
3092 if ((sym_sec
->flags
& SEC_CODE
) != 0)
3094 if ((insn
& ((0x3f << 26) | (0x1f << 21)))
3095 == (((int) OP_ADDIL
<< 26) | (27 << 21)))
3097 insn
&= ~ (0x1f << 21);
3098 #if 1 /* debug them. */
3099 (*_bfd_error_handler
)
3100 (_("%s(%s+0x%lx): fixing %s"),
3101 bfd_get_filename (input_bfd
),
3102 input_section
->name
,
3103 (long) rel
->r_offset
,
3107 /* Now try to make things easy for the dynamic linker. */
3113 case R_PARISC_DLTIND21L
:
3114 case R_PARISC_DLTIND14R
:
3115 case R_PARISC_DLTIND14F
:
3116 value
-= elf_gp (input_section
->output_section
->owner
);
3125 case R_PARISC_DIR32
:
3126 case R_PARISC_DIR17F
:
3127 case R_PARISC_PCREL17C
:
3128 case R_PARISC_PCREL14F
:
3129 case R_PARISC_DPREL14F
:
3130 case R_PARISC_PLABEL32
:
3131 case R_PARISC_DLTIND14F
:
3132 case R_PARISC_SEGBASE
:
3133 case R_PARISC_SEGREL32
:
3137 case R_PARISC_DIR21L
:
3138 case R_PARISC_PCREL21L
:
3139 case R_PARISC_DPREL21L
:
3140 case R_PARISC_PLABEL21L
:
3141 case R_PARISC_DLTIND21L
:
3145 case R_PARISC_DIR17R
:
3146 case R_PARISC_PCREL17R
:
3147 case R_PARISC_DIR14R
:
3148 case R_PARISC_PCREL14R
:
3149 case R_PARISC_DPREL14R
:
3150 case R_PARISC_PLABEL14R
:
3151 case R_PARISC_DLTIND14R
:
3155 case R_PARISC_PCREL12F
:
3156 case R_PARISC_PCREL17F
:
3157 case R_PARISC_PCREL22F
:
3160 if (r_type
== (unsigned int) R_PARISC_PCREL17F
)
3162 max_branch_offset
= (1 << (17-1)) << 2;
3164 else if (r_type
== (unsigned int) R_PARISC_PCREL12F
)
3166 max_branch_offset
= (1 << (12-1)) << 2;
3170 max_branch_offset
= (1 << (22-1)) << 2;
3173 /* sym_sec is NULL on undefined weak syms or when shared on
3174 undefined syms. We've already checked for a stub for the
3175 shared undefined case. */
3176 if (sym_sec
== NULL
)
3179 /* If the branch is out of reach, then redirect the
3180 call to the local stub for this function. */
3181 if (value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3183 stub_entry
= hppa_get_stub_entry (input_section
, sym_sec
,
3185 if (stub_entry
== NULL
)
3186 return bfd_reloc_notsupported
;
3188 /* Munge up the value and addend so that we call the stub
3189 rather than the procedure directly. */
3190 value
= (stub_entry
->stub_offset
3191 + stub_entry
->stub_sec
->output_offset
3192 + stub_entry
->stub_sec
->output_section
->vma
3198 /* Something we don't know how to handle. */
3200 return bfd_reloc_notsupported
;
3203 /* Make sure we can reach the stub. */
3204 if (max_branch_offset
!= 0
3205 && value
+ addend
+ max_branch_offset
>= 2*max_branch_offset
)
3207 (*_bfd_error_handler
)
3208 (_("%s(%s+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
3209 bfd_get_filename (input_bfd
),
3210 input_section
->name
,
3211 (long) rel
->r_offset
,
3212 stub_entry
->root
.string
);
3213 return bfd_reloc_notsupported
;
3216 val
= hppa_field_adjust (value
, addend
, r_field
);
3220 case R_PARISC_PCREL12F
:
3221 case R_PARISC_PCREL17C
:
3222 case R_PARISC_PCREL17F
:
3223 case R_PARISC_PCREL17R
:
3224 case R_PARISC_PCREL22F
:
3225 case R_PARISC_DIR17F
:
3226 case R_PARISC_DIR17R
:
3227 /* This is a branch. Divide the offset by four.
3228 Note that we need to decide whether it's a branch or
3229 otherwise by inspecting the reloc. Inspecting insn won't
3230 work as insn might be from a .word directive. */
3238 insn
= hppa_rebuild_insn (insn
, val
, r_format
);
3240 /* Update the instruction word. */
3241 bfd_put_32 (input_bfd
, (bfd_vma
) insn
, hit_data
);
3242 return bfd_reloc_ok
;
3246 /* Relocate an HPPA ELF section. */
3249 elf32_hppa_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
3250 contents
, relocs
, local_syms
, local_sections
)
3252 struct bfd_link_info
*info
;
3254 asection
*input_section
;
3256 Elf_Internal_Rela
*relocs
;
3257 Elf_Internal_Sym
*local_syms
;
3258 asection
**local_sections
;
3261 bfd_vma
*local_got_offsets
;
3262 struct elf32_hppa_link_hash_table
*hplink
;
3263 Elf_Internal_Shdr
*symtab_hdr
;
3264 Elf_Internal_Rela
*rel
;
3265 Elf_Internal_Rela
*relend
;
3268 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3270 hplink
= hppa_link_hash_table (info
);
3271 dynobj
= hplink
->root
.dynobj
;
3272 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3276 relend
= relocs
+ input_section
->reloc_count
;
3277 for (; rel
< relend
; rel
++)
3279 unsigned int r_type
;
3280 reloc_howto_type
*howto
;
3281 unsigned int r_symndx
;
3282 struct elf32_hppa_link_hash_entry
*h
;
3283 Elf_Internal_Sym
*sym
;
3286 bfd_reloc_status_type r
;
3287 const char *sym_name
;
3290 r_type
= ELF32_R_TYPE (rel
->r_info
);
3291 if (r_type
>= (unsigned int) R_PARISC_UNIMPLEMENTED
)
3293 bfd_set_error (bfd_error_bad_value
);
3296 if (r_type
== (unsigned int) R_PARISC_GNU_VTENTRY
3297 || r_type
== (unsigned int) R_PARISC_GNU_VTINHERIT
)
3300 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3302 if (info
->relocateable
)
3304 /* This is a relocateable link. We don't have to change
3305 anything, unless the reloc is against a section symbol,
3306 in which case we have to adjust according to where the
3307 section symbol winds up in the output section. */
3308 if (r_symndx
< symtab_hdr
->sh_info
)
3310 sym
= local_syms
+ r_symndx
;
3311 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
3313 sym_sec
= local_sections
[r_symndx
];
3314 rel
->r_addend
+= sym_sec
->output_offset
;
3320 /* This is a final link. */
3324 if (r_symndx
< symtab_hdr
->sh_info
)
3326 /* This is a local symbol, h defaults to NULL. */
3327 sym
= local_syms
+ r_symndx
;
3328 sym_sec
= local_sections
[r_symndx
];
3329 relocation
= ((ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
3330 ? 0 : sym
->st_value
)
3331 + sym_sec
->output_offset
3332 + sym_sec
->output_section
->vma
);
3338 /* It's a global; Find its entry in the link hash. */
3339 indx
= r_symndx
- symtab_hdr
->sh_info
;
3340 h
= ((struct elf32_hppa_link_hash_entry
*)
3341 elf_sym_hashes (input_bfd
)[indx
]);
3342 while (h
->elf
.root
.type
== bfd_link_hash_indirect
3343 || h
->elf
.root
.type
== bfd_link_hash_warning
)
3344 h
= (struct elf32_hppa_link_hash_entry
*) h
->elf
.root
.u
.i
.link
;
3347 if (h
->elf
.root
.type
== bfd_link_hash_defined
3348 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
3350 sym_sec
= h
->elf
.root
.u
.def
.section
;
3351 /* If sym_sec->output_section is NULL, then it's a
3352 symbol defined in a shared library. */
3353 if (sym_sec
->output_section
!= NULL
)
3354 relocation
= (h
->elf
.root
.u
.def
.value
3355 + sym_sec
->output_offset
3356 + sym_sec
->output_section
->vma
);
3358 else if (h
->elf
.root
.type
== bfd_link_hash_undefweak
)
3360 else if (info
->shared
&& !info
->no_undefined
3361 && ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
)
3364 if (!((*info
->callbacks
->undefined_symbol
)
3365 (info
, h
->elf
.root
.root
.string
, input_bfd
,
3366 input_section
, rel
->r_offset
, false)))
3371 if (!((*info
->callbacks
->undefined_symbol
)
3372 (info
, h
->elf
.root
.root
.string
, input_bfd
,
3373 input_section
, rel
->r_offset
, true)))
3378 /* Do any required modifications to the relocation value, and
3379 determine what types of dynamic info we need to output, if
3384 case R_PARISC_DLTIND14F
:
3385 case R_PARISC_DLTIND14R
:
3386 case R_PARISC_DLTIND21L
:
3387 /* Relocation is to the entry for this symbol in the global
3393 off
= h
->elf
.got
.offset
;
3394 BFD_ASSERT (off
!= (bfd_vma
) -1);
3396 if (! hplink
->root
.dynamic_sections_created
3398 && (info
->symbolic
|| h
->elf
.dynindx
== -1)
3399 && (h
->elf
.elf_link_hash_flags
3400 & ELF_LINK_HASH_DEF_REGULAR
) != 0))
3402 /* This is actually a static link, or it is a
3403 -Bsymbolic link and the symbol is defined
3404 locally, or the symbol was forced to be local
3405 because of a version file. We must initialize
3406 this entry in the global offset table. Since the
3407 offset must always be a multiple of 4, we use the
3408 least significant bit to record whether we have
3409 initialized it already.
3411 When doing a dynamic link, we create a .rela.got
3412 relocation entry to initialize the value. This
3413 is done in the finish_dynamic_symbol routine. */
3418 bfd_put_32 (output_bfd
, relocation
,
3419 hplink
->sgot
->contents
+ off
);
3420 h
->elf
.got
.offset
|= 1;
3428 /* Local symbol case. */
3431 BFD_ASSERT (local_got_offsets
!= NULL
3432 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
3434 off
= local_got_offsets
[r_symndx
];
3436 /* The offset must always be a multiple of 4. We use
3437 the least significant bit to record whether we have
3438 already generated the necessary reloc. */
3443 bfd_put_32 (output_bfd
, relocation
,
3444 hplink
->sgot
->contents
+ off
);
3448 /* Output a dynamic *ABS* relocation for this
3449 GOT entry. In this case it is relative to
3450 the base of the object because the symbol
3452 Elf_Internal_Rela outrel
;
3453 asection
*srelgot
= hplink
->srelgot
;
3455 outrel
.r_offset
= (off
3456 + hplink
->sgot
->output_offset
3457 + hplink
->sgot
->output_section
->vma
);
3458 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_DIR32
);
3459 outrel
.r_addend
= relocation
;
3460 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3461 ((Elf32_External_Rela
*)
3463 + srelgot
->reloc_count
));
3464 ++srelgot
->reloc_count
;
3467 local_got_offsets
[r_symndx
] |= 1;
3473 /* Add the base of the GOT to the relocation value. */
3474 relocation
+= (hplink
->sgot
->output_offset
3475 + hplink
->sgot
->output_section
->vma
);
3478 case R_PARISC_PLABEL14R
:
3479 case R_PARISC_PLABEL21L
:
3480 case R_PARISC_PLABEL32
:
3481 if (hplink
->root
.dynamic_sections_created
)
3485 /* If we have a global symbol with a PLT slot, then
3486 redirect this relocation to it. */
3489 off
= h
->elf
.plt
.offset
;
3495 indx
= r_symndx
+ symtab_hdr
->sh_info
;
3496 off
= local_got_offsets
[indx
];
3498 /* As for the local .got entry case, we use the last
3499 bit to record whether we've already initialised
3500 this local .plt entry. */
3505 bfd_put_32 (output_bfd
,
3507 hplink
->splt
->contents
+ off
);
3508 bfd_put_32 (output_bfd
,
3509 elf_gp (hplink
->splt
->output_section
->owner
),
3510 hplink
->splt
->contents
+ off
+ 4);
3514 /* Output a dynamic IPLT relocation for this
3516 Elf_Internal_Rela outrel
;
3517 asection
*srelplt
= hplink
->srelplt
;
3519 outrel
.r_offset
= (off
3520 + hplink
->splt
->output_offset
3521 + hplink
->splt
->output_section
->vma
);
3522 outrel
.r_info
= ELF32_R_INFO (0, R_PARISC_IPLT
);
3523 outrel
.r_addend
= relocation
;
3524 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3525 ((Elf32_External_Rela
*)
3527 + srelplt
->reloc_count
));
3528 ++srelplt
->reloc_count
;
3531 local_got_offsets
[indx
] |= 1;
3535 BFD_ASSERT (off
< (bfd_vma
) -2);
3537 /* PLABELs contain function pointers. Relocation is to
3538 the entry for the function in the .plt. The magic +2
3539 offset signals to $$dyncall that the function pointer
3540 is in the .plt and thus has a gp pointer too.
3541 Exception: Undefined PLABELs should have a value of
3544 || (h
->elf
.root
.type
!= bfd_link_hash_undefweak
3545 && h
->elf
.root
.type
!= bfd_link_hash_undefined
))
3548 + hplink
->splt
->output_offset
3549 + hplink
->splt
->output_section
->vma
3554 /* Fall through and possibly emit a dynamic relocation. */
3556 case R_PARISC_DIR17F
:
3557 case R_PARISC_DIR17R
:
3558 case R_PARISC_DIR14R
:
3559 case R_PARISC_DIR21L
:
3560 case R_PARISC_DPREL14F
:
3561 case R_PARISC_DPREL14R
:
3562 case R_PARISC_DPREL21L
:
3563 case R_PARISC_DIR32
:
3564 /* The reloc types handled here and this conditional
3565 expression must match the code in check_relocs and
3566 hppa_discard_copies. ie. We need exactly the same
3567 condition as in check_relocs, with some extra conditions
3568 (dynindx test in this case) to cater for relocs removed
3569 by hppa_discard_copies. */
3570 if ((input_section
->flags
& SEC_ALLOC
) != 0
3572 #if RELATIVE_DYNAMIC_RELOCS
3573 && (is_absolute_reloc (r_type
)
3574 || ((!info
->symbolic
3576 && ((h
->elf
.elf_link_hash_flags
3577 & ELF_LINK_HASH_DEF_REGULAR
) == 0
3578 || h
->elf
.root
.type
== bfd_link_hash_defweak
)))
3579 && (h
== NULL
|| h
->elf
.dynindx
!= -1)))
3583 Elf_Internal_Rela outrel
;
3586 /* When generating a shared object, these relocations
3587 are copied into the output file to be resolved at run
3594 name
= (bfd_elf_string_from_elf_section
3596 elf_elfheader (input_bfd
)->e_shstrndx
,
3597 elf_section_data (input_section
)->rel_hdr
.sh_name
));
3600 sreloc
= bfd_get_section_by_name (dynobj
, name
);
3601 BFD_ASSERT (sreloc
!= NULL
);
3604 outrel
.r_offset
= rel
->r_offset
;
3605 outrel
.r_addend
= rel
->r_addend
;
3607 if (elf_section_data (input_section
)->stab_info
!= NULL
)
3611 off
= (_bfd_stab_section_offset
3612 (output_bfd
, &hplink
->root
.stab_info
,
3614 &elf_section_data (input_section
)->stab_info
,
3616 if (off
== (bfd_vma
) -1)
3618 outrel
.r_offset
= off
;
3621 outrel
.r_offset
+= (input_section
->output_offset
3622 + input_section
->output_section
->vma
);
3626 memset (&outrel
, 0, sizeof (outrel
));
3629 && h
->elf
.dynindx
!= -1
3632 || (h
->elf
.elf_link_hash_flags
3633 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
3635 outrel
.r_info
= ELF32_R_INFO (h
->elf
.dynindx
, r_type
);
3637 else /* It's a local symbol, or one marked to become local. */
3641 /* Add the absolute offset of the symbol. */
3642 outrel
.r_addend
+= relocation
;
3644 /* Global plabels need to be processed by the
3645 dynamic linker so that functions have at most one
3646 fptr. For this reason, we need to differentiate
3647 between global and local plabels, which we do by
3648 providing the function symbol for a global plabel
3649 reloc, and no symbol for local plabels. */
3652 && sym_sec
->output_section
!= NULL
3653 && ! bfd_is_abs_section (sym_sec
))
3655 indx
= elf_section_data (sym_sec
->output_section
)->dynindx
;
3656 /* We are turning this relocation into one
3657 against a section symbol, so subtract out the
3658 output section's address but not the offset
3659 of the input section in the output section. */
3660 outrel
.r_addend
-= sym_sec
->output_section
->vma
;
3663 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
3666 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3667 ((Elf32_External_Rela
*)
3669 + sreloc
->reloc_count
));
3670 ++sreloc
->reloc_count
;
3678 r
= final_link_relocate (input_section
, contents
, rel
, relocation
,
3681 if (r
== bfd_reloc_ok
)
3685 sym_name
= h
->elf
.root
.root
.string
;
3688 sym_name
= bfd_elf_string_from_elf_section (input_bfd
,
3689 symtab_hdr
->sh_link
,
3691 if (sym_name
== NULL
)
3693 if (*sym_name
== '\0')
3694 sym_name
= bfd_section_name (input_bfd
, sym_sec
);
3697 howto
= elf_hppa_howto_table
+ r_type
;
3699 if (r
== bfd_reloc_undefined
|| r
== bfd_reloc_notsupported
)
3701 (*_bfd_error_handler
)
3702 (_("%s(%s+0x%lx): cannot handle %s for %s"),
3703 bfd_get_filename (input_bfd
),
3704 input_section
->name
,
3705 (long) rel
->r_offset
,
3711 if (!((*info
->callbacks
->reloc_overflow
)
3712 (info
, sym_name
, howto
->name
, (bfd_vma
) 0,
3713 input_bfd
, input_section
, rel
->r_offset
)))
3722 /* Finish up dynamic symbol handling. We set the contents of various
3723 dynamic sections here. */
3726 elf32_hppa_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
3728 struct bfd_link_info
*info
;
3729 struct elf_link_hash_entry
*h
;
3730 Elf_Internal_Sym
*sym
;
3732 struct elf32_hppa_link_hash_table
*hplink
;
3735 hplink
= hppa_link_hash_table (info
);
3736 dynobj
= hplink
->root
.dynobj
;
3738 /* Millicode symbols should not be put in the dynamic
3739 symbol table under any circumstances. */
3740 if (ELF_ST_TYPE (sym
->st_info
) == STT_PARISC_MILLI
)
3743 if (h
->plt
.offset
!= (bfd_vma
) -1)
3746 Elf_Internal_Rela rel
;
3748 /* This symbol has an entry in the procedure linkage table. Set
3751 The format of a plt entry is
3756 The last field is present only for plt entries that are used
3757 by global plabels. */
3759 /* We do not actually care about the value in the PLT entry if
3760 we are creating a shared library and the symbol is still
3761 undefined; We create a dynamic relocation to fill in the
3764 if (h
->root
.type
== bfd_link_hash_defined
3765 || h
->root
.type
== bfd_link_hash_defweak
)
3767 value
= h
->root
.u
.def
.value
;
3768 if (h
->root
.u
.def
.section
->output_section
!= NULL
)
3769 value
+= (h
->root
.u
.def
.section
->output_offset
3770 + h
->root
.u
.def
.section
->output_section
->vma
);
3773 bfd_put_32 (hplink
->splt
->owner
,
3775 hplink
->splt
->contents
+ h
->plt
.offset
);
3776 bfd_put_32 (hplink
->splt
->owner
,
3777 elf_gp (hplink
->splt
->output_section
->owner
),
3778 hplink
->splt
->contents
+ h
->plt
.offset
+ 4);
3779 if (PLABEL_PLT_ENTRY_SIZE
!= PLT_ENTRY_SIZE
3780 && ((struct elf32_hppa_link_hash_entry
*) h
)->plabel
3781 && h
->dynindx
!= -1)
3783 memset (hplink
->splt
->contents
+ h
->plt
.offset
+ 8,
3784 0, PLABEL_PLT_ENTRY_SIZE
- PLT_ENTRY_SIZE
);
3787 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->pic_call
)
3789 /* Create a dynamic IPLT relocation for this entry. */
3790 rel
.r_offset
= (h
->plt
.offset
3791 + hplink
->splt
->output_offset
3792 + hplink
->splt
->output_section
->vma
);
3793 if (! ((struct elf32_hppa_link_hash_entry
*) h
)->plt_abs
3794 && h
->dynindx
!= -1)
3796 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_IPLT
);
3801 /* This symbol has been marked to become local, and is
3802 used by a plabel so must be kept in the .plt. */
3803 rel
.r_info
= ELF32_R_INFO (0, R_PARISC_IPLT
);
3804 rel
.r_addend
= value
;
3807 bfd_elf32_swap_reloca_out (hplink
->splt
->output_section
->owner
,
3809 ((Elf32_External_Rela
*)
3810 hplink
->srelplt
->contents
3811 + hplink
->srelplt
->reloc_count
));
3812 hplink
->srelplt
->reloc_count
++;
3815 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3817 /* Mark the symbol as undefined, rather than as defined in
3818 the .plt section. Leave the value alone. */
3819 sym
->st_shndx
= SHN_UNDEF
;
3823 if (h
->got
.offset
!= (bfd_vma
) -1)
3825 Elf_Internal_Rela rel
;
3827 /* This symbol has an entry in the global offset table. Set it
3830 rel
.r_offset
= ((h
->got
.offset
&~ (bfd_vma
) 1)
3831 + hplink
->sgot
->output_offset
3832 + hplink
->sgot
->output_section
->vma
);
3834 /* If this is a static link, or it is a -Bsymbolic link and the
3835 symbol is defined locally or was forced to be local because
3836 of a version file, we just want to emit a RELATIVE reloc.
3837 The entry in the global offset table will already have been
3838 initialized in the relocate_section function. */
3839 if (! hplink
->root
.dynamic_sections_created
3841 && (info
->symbolic
|| h
->dynindx
== -1)
3842 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
3844 rel
.r_info
= ELF32_R_INFO (0, R_PARISC_DIR32
);
3845 rel
.r_addend
= (h
->root
.u
.def
.value
3846 + h
->root
.u
.def
.section
->output_offset
3847 + h
->root
.u
.def
.section
->output_section
->vma
);
3851 BFD_ASSERT((h
->got
.offset
& 1) == 0);
3852 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
3853 hplink
->sgot
->contents
+ h
->got
.offset
);
3854 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_DIR32
);
3858 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
3859 ((Elf32_External_Rela
*)
3860 hplink
->srelgot
->contents
3861 + hplink
->srelgot
->reloc_count
));
3862 ++hplink
->srelgot
->reloc_count
;
3865 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
3868 Elf_Internal_Rela rel
;
3870 /* This symbol needs a copy reloc. Set it up. */
3872 BFD_ASSERT (h
->dynindx
!= -1
3873 && (h
->root
.type
== bfd_link_hash_defined
3874 || h
->root
.type
== bfd_link_hash_defweak
));
3876 s
= hplink
->srelbss
;
3878 rel
.r_offset
= (h
->root
.u
.def
.value
3879 + h
->root
.u
.def
.section
->output_offset
3880 + h
->root
.u
.def
.section
->output_section
->vma
);
3882 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PARISC_COPY
);
3883 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
3884 ((Elf32_External_Rela
*) s
->contents
3889 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
3890 if (h
->root
.root
.string
[0] == '_'
3891 && (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3892 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0))
3894 sym
->st_shndx
= SHN_ABS
;
3901 /* Finish up the dynamic sections. */
3904 elf32_hppa_finish_dynamic_sections (output_bfd
, info
)
3906 struct bfd_link_info
*info
;
3909 struct elf32_hppa_link_hash_table
*hplink
;
3912 hplink
= hppa_link_hash_table (info
);
3913 dynobj
= hplink
->root
.dynobj
;
3915 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3917 if (hplink
->root
.dynamic_sections_created
)
3919 Elf32_External_Dyn
*dyncon
, *dynconend
;
3921 BFD_ASSERT (sdyn
!= NULL
);
3923 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
3924 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
3925 for (; dyncon
< dynconend
; dyncon
++)
3927 Elf_Internal_Dyn dyn
;
3930 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3938 /* Use PLTGOT to set the GOT register. */
3939 dyn
.d_un
.d_ptr
= elf_gp (output_bfd
);
3940 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3944 s
= hplink
->srelplt
;
3945 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
3946 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3950 s
= hplink
->srelplt
;
3951 if (s
->_cooked_size
!= 0)
3952 dyn
.d_un
.d_val
= s
->_cooked_size
;
3954 dyn
.d_un
.d_val
= s
->_raw_size
;
3955 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3961 struct elf_link_hash_entry
*h
;
3962 const char *funcname
;
3964 if (dyn
.d_tag
== DT_INIT
)
3965 funcname
= info
->init_function
;
3967 funcname
= info
->fini_function
;
3969 h
= elf_link_hash_lookup (&hplink
->root
, funcname
,
3970 false, false, false);
3972 /* This is a function pointer. The magic +2 offset
3973 signals to $$dyncall that the function pointer
3974 is in the .plt and thus has a gp pointer too. */
3975 dyn
.d_un
.d_ptr
= (h
->plt
.offset
3976 + hplink
->splt
->output_offset
3977 + hplink
->splt
->output_section
->vma
3979 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3986 if (hplink
->sgot
->_raw_size
!= 0)
3988 /* Fill in the first entry in the global offset table.
3989 We use it to point to our dynamic section, if we have one. */
3990 bfd_put_32 (output_bfd
,
3992 ? sdyn
->output_section
->vma
+ sdyn
->output_offset
3994 hplink
->sgot
->contents
);
3996 /* The second entry is reserved for use by the dynamic linker. */
3997 bfd_put_32 (output_bfd
, (bfd_vma
) 0, hplink
->sgot
->contents
+ 4);
3999 /* Set .got entry size. */
4000 elf_section_data (hplink
->sgot
->output_section
)
4001 ->this_hdr
.sh_entsize
= GOT_ENTRY_SIZE
;
4004 /* Set plt entry size. */
4005 if (hplink
->splt
->_raw_size
!= 0)
4006 elf_section_data (hplink
->splt
->output_section
)
4007 ->this_hdr
.sh_entsize
= PLT_ENTRY_SIZE
;
4013 /* Called when writing out an object file to decide the type of a
4016 elf32_hppa_elf_get_symbol_type (elf_sym
, type
)
4017 Elf_Internal_Sym
*elf_sym
;
4020 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_PARISC_MILLI
)
4021 return STT_PARISC_MILLI
;
4027 /* Misc BFD support code. */
4028 #define bfd_elf32_bfd_is_local_label_name elf_hppa_is_local_label_name
4029 #define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
4030 #define elf_info_to_howto elf_hppa_info_to_howto
4031 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
4033 /* Stuff for the BFD linker. */
4034 #define bfd_elf32_bfd_final_link _bfd_elf32_gc_common_final_link
4035 #define bfd_elf32_bfd_link_hash_table_create elf32_hppa_link_hash_table_create
4036 #define elf_backend_add_symbol_hook elf32_hppa_add_symbol_hook
4037 #define elf_backend_adjust_dynamic_symbol elf32_hppa_adjust_dynamic_symbol
4038 #define elf_backend_check_relocs elf32_hppa_check_relocs
4039 #define elf_backend_create_dynamic_sections elf32_hppa_create_dynamic_sections
4040 #define elf_backend_fake_sections elf_hppa_fake_sections
4041 #define elf_backend_relocate_section elf32_hppa_relocate_section
4042 #define elf_backend_hide_symbol elf32_hppa_hide_symbol
4043 #define elf_backend_finish_dynamic_symbol elf32_hppa_finish_dynamic_symbol
4044 #define elf_backend_finish_dynamic_sections elf32_hppa_finish_dynamic_sections
4045 #define elf_backend_size_dynamic_sections elf32_hppa_size_dynamic_sections
4046 #define elf_backend_gc_mark_hook elf32_hppa_gc_mark_hook
4047 #define elf_backend_gc_sweep_hook elf32_hppa_gc_sweep_hook
4048 #define elf_backend_object_p elf32_hppa_object_p
4049 #define elf_backend_final_write_processing elf_hppa_final_write_processing
4050 #define elf_backend_get_symbol_type elf32_hppa_elf_get_symbol_type
4052 #define elf_backend_can_gc_sections 1
4053 #define elf_backend_plt_alignment 2
4054 #define elf_backend_want_got_plt 0
4055 #define elf_backend_plt_readonly 0
4056 #define elf_backend_want_plt_sym 0
4057 #define elf_backend_got_header_size 8
4059 #define TARGET_BIG_SYM bfd_elf32_hppa_vec
4060 #define TARGET_BIG_NAME "elf32-hppa"
4061 #define ELF_ARCH bfd_arch_hppa
4062 #define ELF_MACHINE_CODE EM_PARISC
4063 #define ELF_MAXPAGESIZE 0x1000
4065 #include "elf32-target.h"