1 /* BFD back-end for HP PA-RISC ELF files.
2 Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 1997
3 Free Software Foundation, Inc.
7 Center for Software Science
8 Department of Computer Science
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"
38 /* The internal type of a symbol table extension entry. */
39 typedef unsigned long symext_entryS
;
41 /* The external type of a symbol table extension entry. */
42 #define ELF32_PARISC_SX_SIZE (4)
43 #define ELF32_PARISC_SX_GET(bfd, addr) bfd_h_get_32 ((bfd), (addr))
44 #define ELF32_PARISC_SX_PUT(bfd, val, addr) \
45 bfd_h_put_32 ((bfd), (val), (addr))
47 /* HPPA symbol table extension entry types */
48 enum elf32_hppa_symextn_types
55 /* These macros compose and decompose the value of a symextn entry:
57 entry_type = ELF32_PARISC_SX_TYPE(word);
58 entry_value = ELF32_PARISC_SX_VAL(word);
59 word = ELF32_PARISC_SX_WORD(type,val); */
61 #define ELF32_PARISC_SX_TYPE(p) ((p) >> 24)
62 #define ELF32_PARISC_SX_VAL(p) ((p) & 0xFFFFFF)
63 #define ELF32_PARISC_SX_WORD(type,val) (((type) << 24) + (val & 0xFFFFFF))
65 /* The following was added facilitate implementation of the .hppa_symextn
66 section. This section is built after the symbol table is built in the
67 elf_write_object_contents routine (called from bfd_close). It is built
68 so late because it requires information that is not known until
69 the symbol and string table sections have been allocated, and
70 the symbol table has been built. */
72 #define SYMEXTN_SECTION_NAME ".PARISC.symext"
77 struct symext_chain
*next
;
80 typedef struct symext_chain symext_chainS
;
82 /* We use three different hash tables to hold information for
83 linking PA ELF objects.
85 The first is the elf32_hppa_link_hash_table which is derived
86 from the standard ELF linker hash table. We use this as a place to
87 attach other hash tables and static information.
89 The second is the stub hash table which is derived from the
90 base BFD hash table. The stub hash table holds the information
91 necessary to build the linker stubs during a link.
93 The last hash table keeps track of argument location information needed
94 to build hash tables. Each function with nonzero argument location
95 bits will have an entry in this table. */
97 /* Hash table for linker stubs. */
99 struct elf32_hppa_stub_hash_entry
101 /* Base hash table entry structure, we can get the name of the stub
102 (and thus know exactly what actions it performs) from the base
104 struct bfd_hash_entry root
;
106 /* Offset of the beginning of this stub. */
109 /* Given the symbol's value and its section we can determine its final
110 value when building the stubs (so the stub knows where to jump. */
111 symvalue target_value
;
112 asection
*target_section
;
115 struct elf32_hppa_stub_hash_table
117 /* The hash table itself. */
118 struct bfd_hash_table root
;
123 /* Where to place the next stub. */
126 /* Current offset in the stub section. */
131 /* Hash table for argument location information. */
133 struct elf32_hppa_args_hash_entry
135 /* Base hash table entry structure. */
136 struct bfd_hash_entry root
;
138 /* The argument location bits for this entry. */
142 struct elf32_hppa_args_hash_table
144 /* The hash table itself. */
145 struct bfd_hash_table root
;
148 struct elf32_hppa_link_hash_entry
150 struct elf_link_hash_entry root
;
153 struct elf32_hppa_link_hash_table
155 /* The main hash table. */
156 struct elf_link_hash_table root
;
158 /* The stub hash table. */
159 struct elf32_hppa_stub_hash_table
*stub_hash_table
;
161 /* The argument relocation bits hash table. */
162 struct elf32_hppa_args_hash_table
*args_hash_table
;
164 /* A count of the number of output symbols. */
165 unsigned int output_symbol_count
;
167 /* Stuff so we can handle DP relative relocations. */
169 int global_sym_defined
;
174 #define RETURN_VALUE 1
176 /* The various argument relocations that may be performed. */
181 /* Relocate 32 bits from GR to FP register. */
183 /* Relocate 64 bits from a GR pair to FP pair. */
185 /* Relocate 32 bits from FP to GR. */
187 /* Relocate 64 bits from FP pair to GR pair. */
191 /* What is being relocated (eg which argument or the return value). */
194 ARG0
, ARG1
, ARG2
, ARG3
, RET
,
195 } arg_reloc_location
;
198 /* ELF32/HPPA relocation support
200 This file contains ELF32/HPPA relocation support as specified
201 in the Stratus FTX/Golf Object File Format (SED-1762) dated
204 #include "elf32-hppa.h"
205 #include "hppa_stubs.h"
207 static bfd_reloc_status_type hppa_elf_reloc
208 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
210 static unsigned long hppa_elf_relocate_insn
211 PARAMS ((bfd
*, asection
*, unsigned long, unsigned long, long,
212 long, unsigned long, unsigned long, unsigned long));
214 static bfd_reloc_status_type hppa_elf_reloc
215 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
217 static boolean elf32_hppa_set_section_contents
218 PARAMS ((bfd
*, sec_ptr
, PTR
, file_ptr
, bfd_size_type
));
220 static boolean elf32_hppa_backend_symbol_table_processing
221 PARAMS ((bfd
*, elf_symbol_type
*, unsigned int));
223 static void elf32_hppa_backend_begin_write_processing
224 PARAMS ((bfd
*, struct bfd_link_info
*));
226 static void elf32_hppa_backend_final_write_processing
227 PARAMS ((bfd
*, boolean
));
229 static void add_entry_to_symext_chain
230 PARAMS ((bfd
*, unsigned int, unsigned int, symext_chainS
**,
234 elf_hppa_tc_make_sections
PARAMS ((bfd
*, symext_chainS
*));
236 static boolean hppa_elf_is_local_label_name
PARAMS ((bfd
*, const char *));
238 static boolean elf32_hppa_add_symbol_hook
239 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
240 const char **, flagword
*, asection
**, bfd_vma
*));
242 static bfd_reloc_status_type elf32_hppa_bfd_final_link_relocate
243 PARAMS ((reloc_howto_type
*, bfd
*, bfd
*, asection
*,
244 bfd_byte
*, bfd_vma
, bfd_vma
, bfd_vma
, struct bfd_link_info
*,
245 asection
*, const char *, int));
247 static struct bfd_link_hash_table
*elf32_hppa_link_hash_table_create
250 static struct bfd_hash_entry
*
251 elf32_hppa_stub_hash_newfunc
252 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
254 static struct bfd_hash_entry
*
255 elf32_hppa_args_hash_newfunc
256 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
259 elf32_hppa_relocate_section
260 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*,
261 bfd_byte
*, Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
264 elf32_hppa_stub_hash_table_init
265 PARAMS ((struct elf32_hppa_stub_hash_table
*, bfd
*,
266 struct bfd_hash_entry
*(*) PARAMS ((struct bfd_hash_entry
*,
267 struct bfd_hash_table
*,
271 elf32_hppa_build_one_stub
PARAMS ((struct bfd_hash_entry
*, PTR
));
274 elf32_hppa_read_symext_info
275 PARAMS ((bfd
*, Elf_Internal_Shdr
*, struct elf32_hppa_args_hash_table
*,
276 Elf_Internal_Sym
*));
278 static unsigned int elf32_hppa_size_of_stub
279 PARAMS ((unsigned int, unsigned int, bfd_vma
, bfd_vma
, const char *));
281 static boolean elf32_hppa_arg_reloc_needed
282 PARAMS ((unsigned int, unsigned int, arg_reloc_type
[]));
284 static void elf32_hppa_name_of_stub
285 PARAMS ((unsigned int, unsigned int, bfd_vma
, bfd_vma
, char *));
287 static boolean elf32_hppa_size_symext
PARAMS ((struct bfd_hash_entry
*, PTR
));
289 static boolean elf32_hppa_link_output_symbol_hook
290 PARAMS ((bfd
*, struct bfd_link_info
*, const char *,
291 Elf_Internal_Sym
*, asection
*));
293 /* Where (what register type) is an argument comming from? */
304 /* Horizontal represents the callee's argument location information,
305 vertical represents caller's argument location information. Value at a
306 particular X,Y location represents what (if any) argument relocation
307 needs to be performed to make caller and callee agree. */
309 static CONST arg_reloc_type arg_mismatches
[6][6] =
311 {NO
, NO
, NO
, NO
, NO
, NO
},
312 {NO
, NO
, GF
, NO
, GD
, NO
},
313 {NO
, FG
, NO
, NO
, NO
, NO
},
314 {NO
, NO
, NO
, NO
, NO
, NO
},
315 {NO
, DG
, NO
, NO
, NO
, NO
},
316 {NO
, DG
, NO
, NO
, NO
, NO
},
319 /* Likewise, but reversed for the return value. */
320 static CONST arg_reloc_type ret_mismatches
[6][6] =
322 {NO
, NO
, NO
, NO
, NO
, NO
},
323 {NO
, NO
, FG
, NO
, DG
, NO
},
324 {NO
, GF
, NO
, NO
, NO
, NO
},
325 {NO
, NO
, NO
, NO
, NO
, NO
},
326 {NO
, GD
, NO
, NO
, NO
, NO
},
327 {NO
, GD
, NO
, NO
, NO
, NO
},
330 /* Misc static crud for symbol extension records. */
331 static symext_chainS
*symext_rootP
;
332 static symext_chainS
*symext_lastP
;
333 static bfd_size_type symext_chain_size
;
335 /* FIXME: We should be able to try this static variable! */
336 static bfd_byte
*symextn_contents
;
339 /* For linker stub hash tables. */
340 #define elf32_hppa_stub_hash_lookup(table, string, create, copy) \
341 ((struct elf32_hppa_stub_hash_entry *) \
342 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
344 #define elf32_hppa_stub_hash_traverse(table, func, info) \
347 (boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) (func), \
350 /* For linker args hash tables. */
351 #define elf32_hppa_args_hash_lookup(table, string, create, copy) \
352 ((struct elf32_hppa_args_hash_entry *) \
353 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
355 #define elf32_hppa_args_hash_traverse(table, func, info) \
358 (boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) (func), \
361 #define elf32_hppa_args_hash_table_init(table, newfunc) \
362 (bfd_hash_table_init \
364 (struct bfd_hash_entry *(*) PARAMS ((struct bfd_hash_entry *, \
365 struct bfd_hash_table *, \
366 const char *))) (newfunc)))
368 /* For HPPA linker hash table. */
370 #define elf32_hppa_link_hash_lookup(table, string, create, copy, follow)\
371 ((struct elf32_hppa_link_hash_entry *) \
372 elf_link_hash_lookup (&(table)->root, (string), (create), \
375 #define elf32_hppa_link_hash_traverse(table, func, info) \
376 (elf_link_hash_traverse \
378 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
381 /* Get the PA ELF linker hash table from a link_info structure. */
383 #define elf32_hppa_hash_table(p) \
384 ((struct elf32_hppa_link_hash_table *) ((p)->hash))
387 /* Extract specific argument location bits for WHICH from
388 the full argument location in AR. */
389 #define EXTRACT_ARBITS(ar, which) ((ar) >> (8 - ((which) * 2))) & 3
391 /* Assorted hash table functions. */
393 /* Initialize an entry in the stub hash table. */
395 static struct bfd_hash_entry
*
396 elf32_hppa_stub_hash_newfunc (entry
, table
, string
)
397 struct bfd_hash_entry
*entry
;
398 struct bfd_hash_table
*table
;
401 struct elf32_hppa_stub_hash_entry
*ret
;
403 ret
= (struct elf32_hppa_stub_hash_entry
*) entry
;
405 /* Allocate the structure if it has not already been allocated by a
408 ret
= ((struct elf32_hppa_stub_hash_entry
*)
409 bfd_hash_allocate (table
,
410 sizeof (struct elf32_hppa_stub_hash_entry
)));
414 /* Call the allocation method of the superclass. */
415 ret
= ((struct elf32_hppa_stub_hash_entry
*)
416 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
420 /* Initialize the local fields. */
422 ret
->target_value
= 0;
423 ret
->target_section
= NULL
;
426 return (struct bfd_hash_entry
*) ret
;
429 /* Initialize a stub hash table. */
432 elf32_hppa_stub_hash_table_init (table
, stub_bfd
, newfunc
)
433 struct elf32_hppa_stub_hash_table
*table
;
435 struct bfd_hash_entry
*(*newfunc
) PARAMS ((struct bfd_hash_entry
*,
436 struct bfd_hash_table
*,
441 table
->stub_bfd
= stub_bfd
;
442 return (bfd_hash_table_init (&table
->root
, newfunc
));
445 /* Initialize an entry in the argument location hash table. */
447 static struct bfd_hash_entry
*
448 elf32_hppa_args_hash_newfunc (entry
, table
, string
)
449 struct bfd_hash_entry
*entry
;
450 struct bfd_hash_table
*table
;
453 struct elf32_hppa_args_hash_entry
*ret
;
455 ret
= (struct elf32_hppa_args_hash_entry
*) entry
;
457 /* Allocate the structure if it has not already been allocated by a
460 ret
= ((struct elf32_hppa_args_hash_entry
*)
461 bfd_hash_allocate (table
,
462 sizeof (struct elf32_hppa_args_hash_entry
)));
466 /* Call the allocation method of the superclass. */
467 ret
= ((struct elf32_hppa_args_hash_entry
*)
468 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
470 /* Initialize the local fields. */
474 return (struct bfd_hash_entry
*) ret
;
477 /* Create the derived linker hash table. The PA ELF port uses the derived
478 hash table to keep information specific to the PA ELF linker (without
479 using static variables). */
481 static struct bfd_link_hash_table
*
482 elf32_hppa_link_hash_table_create (abfd
)
485 struct elf32_hppa_link_hash_table
*ret
;
487 ret
= ((struct elf32_hppa_link_hash_table
*)
488 bfd_alloc (abfd
, sizeof (struct elf32_hppa_link_hash_table
)));
491 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
492 _bfd_elf_link_hash_newfunc
))
494 bfd_release (abfd
, ret
);
497 ret
->stub_hash_table
= NULL
;
498 ret
->args_hash_table
= NULL
;
499 ret
->output_symbol_count
= 0;
500 ret
->global_value
= 0;
501 ret
->global_sym_defined
= 0;
503 return &ret
->root
.root
;
506 /* Relocate the given INSN given the various input parameters.
508 FIXME: endianness and sizeof (long) issues abound here. */
511 hppa_elf_relocate_insn (abfd
, input_sect
, insn
, address
, sym_value
,
512 r_addend
, r_format
, r_field
, pcrel
)
514 asection
*input_sect
;
516 unsigned long address
;
519 unsigned long r_format
;
520 unsigned long r_field
;
523 unsigned char opcode
= get_opcode (insn
);
543 constant_value
= HPPA_R_CONSTANT (r_addend
);
546 sym_value
-= address
;
548 sym_value
= hppa_field_adjust (sym_value
, constant_value
, r_field
);
549 return hppa_rebuild_insn (abfd
, insn
, sym_value
, r_format
);
554 /* XXX computing constant_value is not needed??? */
555 constant_value
= assemble_17 ((insn
& 0x001f0000) >> 16,
556 (insn
& 0x00001ffc) >> 2,
559 constant_value
= (constant_value
<< 15) >> 15;
563 address
+ input_sect
->output_offset
564 + input_sect
->output_section
->vma
;
565 sym_value
= hppa_field_adjust (sym_value
, -8, r_field
);
568 sym_value
= hppa_field_adjust (sym_value
, constant_value
, r_field
);
570 return hppa_rebuild_insn (abfd
, insn
, sym_value
>> 2, r_format
);
575 constant_value
= HPPA_R_CONSTANT (r_addend
);
578 sym_value
-= address
;
580 return hppa_field_adjust (sym_value
, constant_value
, r_field
);
587 /* Relocate an HPPA ELF section. */
590 elf32_hppa_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
591 contents
, relocs
, local_syms
, local_sections
)
593 struct bfd_link_info
*info
;
595 asection
*input_section
;
597 Elf_Internal_Rela
*relocs
;
598 Elf_Internal_Sym
*local_syms
;
599 asection
**local_sections
;
601 Elf_Internal_Shdr
*symtab_hdr
;
602 Elf_Internal_Rela
*rel
;
603 Elf_Internal_Rela
*relend
;
605 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
608 relend
= relocs
+ input_section
->reloc_count
;
609 for (; rel
< relend
; rel
++)
612 reloc_howto_type
*howto
;
613 unsigned long r_symndx
;
614 struct elf_link_hash_entry
*h
;
615 Elf_Internal_Sym
*sym
;
618 bfd_reloc_status_type r
;
619 const char *sym_name
;
621 r_type
= ELF32_R_TYPE (rel
->r_info
);
622 if (r_type
< 0 || r_type
>= (int) R_PARISC_UNIMPLEMENTED
)
624 bfd_set_error (bfd_error_bad_value
);
627 howto
= elf_hppa_howto_table
+ r_type
;
629 r_symndx
= ELF32_R_SYM (rel
->r_info
);
631 if (info
->relocateable
)
633 /* This is a relocateable link. We don't have to change
634 anything, unless the reloc is against a section symbol,
635 in which case we have to adjust according to where the
636 section symbol winds up in the output section. */
637 if (r_symndx
< symtab_hdr
->sh_info
)
639 sym
= local_syms
+ r_symndx
;
640 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
642 sym_sec
= local_sections
[r_symndx
];
643 rel
->r_addend
+= sym_sec
->output_offset
;
650 /* This is a final link. */
654 if (r_symndx
< symtab_hdr
->sh_info
)
656 sym
= local_syms
+ r_symndx
;
657 sym_sec
= local_sections
[r_symndx
];
658 relocation
= ((ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
660 + sym_sec
->output_offset
661 + sym_sec
->output_section
->vma
);
667 indx
= r_symndx
- symtab_hdr
->sh_info
;
668 h
= elf_sym_hashes (input_bfd
)[indx
];
669 while (h
->root
.type
== bfd_link_hash_indirect
670 || h
->root
.type
== bfd_link_hash_warning
)
671 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
672 if (h
->root
.type
== bfd_link_hash_defined
673 || h
->root
.type
== bfd_link_hash_defweak
)
675 sym_sec
= h
->root
.u
.def
.section
;
676 relocation
= (h
->root
.u
.def
.value
677 + sym_sec
->output_offset
678 + sym_sec
->output_section
->vma
);
680 else if (h
->root
.type
== bfd_link_hash_undefweak
)
684 if (!((*info
->callbacks
->undefined_symbol
)
685 (info
, h
->root
.root
.string
, input_bfd
,
686 input_section
, rel
->r_offset
)))
693 sym_name
= h
->root
.root
.string
;
696 sym_name
= bfd_elf_string_from_elf_section (input_bfd
,
699 if (sym_name
== NULL
)
701 if (*sym_name
== '\0')
702 sym_name
= bfd_section_name (input_bfd
, sym_sec
);
705 /* If args_hash_table is NULL, then we have encountered some
706 kind of link error (ex. undefined symbols). Do not try to
707 apply any relocations, continue the loop so we can notify
708 the user of several errors in a single attempted link. */
709 if (elf32_hppa_hash_table (info
)->args_hash_table
== NULL
)
712 r
= elf32_hppa_bfd_final_link_relocate (howto
, input_bfd
, output_bfd
,
713 input_section
, contents
,
714 rel
->r_offset
, relocation
,
715 rel
->r_addend
, info
, sym_sec
,
716 sym_name
, h
== NULL
);
718 if (r
!= bfd_reloc_ok
)
722 /* This can happen for DP relative relocs if $global$ is
723 undefined. This is a panic situation so we don't try
725 case bfd_reloc_undefined
:
726 case bfd_reloc_notsupported
:
727 if (!((*info
->callbacks
->undefined_symbol
)
728 (info
, "$global$", input_bfd
,
729 input_section
, rel
->r_offset
)))
732 case bfd_reloc_dangerous
:
734 /* We use this return value to indicate that we performed
735 a "dangerous" relocation. This doesn't mean we did
736 the wrong thing, it just means there may be some cleanup
737 that needs to be done here.
739 In particular we had to swap the last call insn and its
740 delay slot. If the delay slot insn needed a relocation,
741 then we'll need to adjust the next relocation entry's
742 offset to account for the fact that the insn moved.
744 This hair wouldn't be necessary if we inserted stubs
745 between procedures and used a "bl" to get to the stub. */
748 Elf_Internal_Rela
*next_rel
= rel
+ 1;
750 if (rel
->r_offset
+ 4 == next_rel
->r_offset
)
751 next_rel
->r_offset
-= 4;
756 case bfd_reloc_outofrange
:
757 case bfd_reloc_overflow
:
759 if (!((*info
->callbacks
->reloc_overflow
)
760 (info
, sym_name
, howto
->name
, (bfd_vma
) 0,
761 input_bfd
, input_section
, rel
->r_offset
)))
772 /* Set the contents of a particular section at a particular location. */
775 elf32_hppa_set_section_contents (abfd
, section
, location
, offset
, count
)
782 /* Ignore write requests for the symbol extension section until we've
783 had the chance to rebuild it ourselves. */
784 if (!strcmp (section
->name
, ".PARISC.symextn") && !symext_chain_size
)
787 return _bfd_elf_set_section_contents (abfd
, section
, location
,
791 /* Actually perform a relocation. NOTE this is (mostly) superceeded
792 by elf32_hppa_bfd_final_link_relocate which is called by the new
795 static bfd_reloc_status_type
796 hppa_elf_reloc (abfd
, reloc_entry
, symbol_in
, data
, input_section
, output_bfd
,
799 arelent
*reloc_entry
;
802 asection
*input_section
;
804 char **error_message
;
806 /* It is no longer valid to call hppa_elf_reloc when creating
807 a final executable. */
810 reloc_entry
->address
+= input_section
->output_offset
;
812 /* Work around lossage in generic elf code to write relocations.
813 (maps different section symbols into the same symbol index). */
814 if ((symbol_in
->flags
& BSF_SECTION_SYM
)
815 && symbol_in
->section
)
816 reloc_entry
->addend
+= symbol_in
->section
->output_offset
;
821 *error_message
= (char *) _("Unsupported call to hppa_elf_reloc");
822 return bfd_reloc_notsupported
;
826 /* Actually perform a relocation as part of a final link. This can get
827 rather hairy when linker stubs are needed. */
829 static bfd_reloc_status_type
830 elf32_hppa_bfd_final_link_relocate (howto
, input_bfd
, output_bfd
,
831 input_section
, contents
, offset
, value
,
832 addend
, info
, sym_sec
, sym_name
, is_local
)
833 reloc_howto_type
*howto
;
836 asection
*input_section
;
841 struct bfd_link_info
*info
;
843 const char *sym_name
;
847 unsigned long r_type
= howto
->type
;
848 unsigned long r_format
= howto
->bitsize
;
849 unsigned long r_field
= e_fsel
;
850 bfd_byte
*hit_data
= contents
+ offset
;
851 boolean r_pcrel
= howto
->pc_relative
;
853 insn
= bfd_get_32 (input_bfd
, hit_data
);
855 /* Make sure we have a value for $global$. FIXME isn't this effectively
856 just like the gp pointer on MIPS? Can we use those routines for this
858 if (!elf32_hppa_hash_table (info
)->global_sym_defined
)
860 struct elf_link_hash_entry
*h
;
863 h
= elf_link_hash_lookup (elf_hash_table (info
), "$global$", false,
866 /* If there isn't a $global$, then we're in deep trouble. */
868 return bfd_reloc_notsupported
;
870 /* If $global$ isn't a defined symbol, then we're still in deep
872 if (h
->root
.type
!= bfd_link_hash_defined
)
873 return bfd_reloc_undefined
;
875 sec
= h
->root
.u
.def
.section
;
876 elf32_hppa_hash_table (info
)->global_value
= (h
->root
.u
.def
.value
877 + sec
->output_section
->vma
878 + sec
->output_offset
);
879 elf32_hppa_hash_table (info
)->global_sym_defined
= 1;
888 case R_PARISC_DIR17F
:
889 case R_PARISC_PCREL17C
:
891 goto do_basic_type_1
;
892 case R_PARISC_DIR21L
:
893 case R_PARISC_PCREL21L
:
895 goto do_basic_type_1
;
896 case R_PARISC_DIR17R
:
897 case R_PARISC_PCREL17R
:
898 case R_PARISC_DIR14R
:
899 case R_PARISC_PCREL14R
:
901 goto do_basic_type_1
;
903 /* For all the DP relative relocations, we need to examine the symbol's
904 section. If it's a code section, then "data pointer relative" makes
905 no sense. In that case we don't adjust the "value", and for 21 bit
906 addil instructions, we change the source addend register from %dp to
908 case R_PARISC_DPREL21L
:
910 if (sym_sec
->flags
& SEC_CODE
)
912 if ((insn
& 0xfc000000) >> 26 == 0xa
913 && (insn
& 0x03e00000) >> 21 == 0x1b)
917 value
-= elf32_hppa_hash_table (info
)->global_value
;
918 goto do_basic_type_1
;
919 case R_PARISC_DPREL14R
:
921 if ((sym_sec
->flags
& SEC_CODE
) == 0)
922 value
-= elf32_hppa_hash_table (info
)->global_value
;
923 goto do_basic_type_1
;
924 case R_PARISC_DPREL14F
:
926 if ((sym_sec
->flags
& SEC_CODE
) == 0)
927 value
-= elf32_hppa_hash_table (info
)->global_value
;
928 goto do_basic_type_1
;
930 /* These cases are separate as they may involve a lot more work
931 to deal with linker stubs. */
932 case R_PARISC_PLABEL32
:
933 case R_PARISC_PLABEL21L
:
934 case R_PARISC_PLABEL14R
:
935 case R_PARISC_PCREL17F
:
938 unsigned int len
, caller_args
, callee_args
;
939 arg_reloc_type arg_reloc_types
[5];
940 struct elf32_hppa_args_hash_table
*args_hash_table
;
941 struct elf32_hppa_args_hash_entry
*args_hash
;
942 char *new_name
, *stub_name
;
944 /* Get the field selector right. We'll need it in a minute. */
945 if (r_type
== R_PARISC_PCREL17F
946 || r_type
== R_PARISC_PLABEL32
)
948 else if (r_type
== R_PARISC_PLABEL21L
)
950 else if (r_type
== R_PARISC_PLABEL14R
)
953 /* Find out where we are and where we're going. */
955 input_section
->output_offset
+
956 input_section
->output_section
->vma
);
958 /* Now look for the argument relocation bits associated with the
960 len
= strlen (sym_name
) + 1;
963 new_name
= bfd_malloc (len
);
965 return bfd_reloc_notsupported
;
966 strcpy (new_name
, sym_name
);
968 /* Local symbols have unique IDs. */
970 sprintf (new_name
+ len
- 10, "_%08x", (int)sym_sec
);
972 args_hash_table
= elf32_hppa_hash_table (info
)->args_hash_table
;
974 args_hash
= elf32_hppa_args_hash_lookup (args_hash_table
,
975 new_name
, false, false);
976 if (args_hash
== NULL
)
979 callee_args
= args_hash
->arg_bits
;
981 /* If this is a CALL relocation, then get the caller's bits
982 from the addend. Else use the magic 0x155 value for PLABELS.
984 Also we don't care about the destination (value) for PLABELS. */
985 if (r_type
== R_PARISC_PCREL17F
)
986 caller_args
= HPPA_R_ARG_RELOC (addend
);
993 /* Any kind of linker stub needed? */
994 if (((int)(value
- location
) > 0x3ffff)
995 || ((int)(value
- location
) < (int)0xfffc0000)
996 || elf32_hppa_arg_reloc_needed (caller_args
, callee_args
,
999 struct elf32_hppa_stub_hash_table
*stub_hash_table
;
1000 struct elf32_hppa_stub_hash_entry
*stub_hash
;
1001 asection
*stub_section
;
1003 /* Build a name for the stub. */
1005 len
= strlen (new_name
);
1007 stub_name
= bfd_malloc (len
);
1009 return bfd_reloc_notsupported
;
1010 elf32_hppa_name_of_stub (caller_args
, callee_args
,
1011 location
, value
, stub_name
);
1012 strcat (stub_name
, new_name
);
1015 stub_hash_table
= elf32_hppa_hash_table (info
)->stub_hash_table
;
1018 = elf32_hppa_stub_hash_lookup (stub_hash_table
, stub_name
,
1021 /* We're done with that name. */
1024 /* The stub BFD only has one section. */
1025 stub_section
= stub_hash_table
->stub_bfd
->sections
;
1027 if (stub_hash
!= NULL
)
1030 if (r_type
== R_PARISC_PCREL17F
)
1032 unsigned long delay_insn
;
1033 unsigned int opcode
, rtn_reg
, ldo_target_reg
, ldo_src_reg
;
1035 /* We'll need to peek at the next insn. */
1036 delay_insn
= bfd_get_32 (input_bfd
, hit_data
+ 4);
1037 opcode
= get_opcode (delay_insn
);
1039 /* We also need to know the return register for this
1041 rtn_reg
= (insn
& 0x03e00000) >> 21;
1043 ldo_src_reg
= (delay_insn
& 0x03e00000) >> 21;
1044 ldo_target_reg
= (delay_insn
& 0x001f0000) >> 16;
1046 /* Munge up the value and other parameters for
1047 hppa_elf_relocate_insn. */
1049 value
= (stub_hash
->offset
1050 + stub_section
->output_offset
1051 + stub_section
->output_section
->vma
);
1058 /* We need to peek at the delay insn and determine if
1059 we'll need to swap the branch and its delay insn. */
1062 && ldo_target_reg
== rtn_reg
)
1063 || (delay_insn
== 0x08000240))
1065 /* No need to swap the branch and its delay slot, but
1066 we do need to make sure to jump past the return
1067 pointer update in the stub. */
1070 /* If the delay insn does a return pointer adjustment,
1071 then we have to make sure it stays valid. */
1073 && ldo_target_reg
== rtn_reg
)
1075 delay_insn
&= 0xfc00ffff;
1076 delay_insn
|= ((31 << 21) | (31 << 16));
1077 bfd_put_32 (input_bfd
, delay_insn
, hit_data
+ 4);
1079 /* Use a BLE to reach the stub. */
1084 /* Wonderful, we have to swap the call insn and its
1086 bfd_put_32 (input_bfd
, delay_insn
, hit_data
);
1087 /* Use a BLE,n to reach the stub. */
1088 insn
= (BLE_SR4_R0
| 0x2);
1089 bfd_put_32 (input_bfd
, insn
, hit_data
+ 4);
1090 insn
= hppa_elf_relocate_insn (input_bfd
,
1096 /* Update the instruction word. */
1097 bfd_put_32 (input_bfd
, insn
, hit_data
+ 4);
1098 return bfd_reloc_dangerous
;
1103 /* PLABEL stuff is easy. */
1105 value
= (stub_hash
->offset
1106 + stub_section
->output_offset
1107 + stub_section
->output_section
->vma
);
1108 /* We don't need the RP adjustment for PLABELs. */
1110 if (r_type
== R_PARISC_PLABEL32
)
1112 else if (r_type
== R_PARISC_PLABEL21L
)
1114 else if (r_type
== R_PARISC_PLABEL14R
)
1122 return bfd_reloc_notsupported
;
1124 goto do_basic_type_1
;
1128 insn
= hppa_elf_relocate_insn (input_bfd
, input_section
, insn
,
1129 offset
, value
, addend
, r_format
,
1133 /* Something we don't know how to handle. */
1135 return bfd_reloc_notsupported
;
1138 /* Update the instruction word. */
1139 bfd_put_32 (input_bfd
, insn
, hit_data
);
1140 return (bfd_reloc_ok
);
1143 /* Return true if SYM represents a local label symbol. */
1146 hppa_elf_is_local_label_name (abfd
, name
)
1150 return (name
[0] == 'L' && name
[1] == '$');
1153 /* Do any backend specific processing when beginning to write an object
1154 file. For PA ELF we need to determine the size of the symbol extension
1155 section *before* any other output processing happens. */
1158 elf32_hppa_backend_begin_write_processing (abfd
, info
)
1160 struct bfd_link_info
*info
;
1163 asection
*symextn_sec
;
1165 /* Size up the symbol extension section. */
1166 if ((abfd
->outsymbols
== NULL
1168 || symext_chain_size
!= 0)
1173 /* We were not called from the BFD ELF linker code, so we need
1174 to examine the output BFD's outsymbols.
1176 Note we can not build the symbol extensions now as the symbol
1177 map hasn't been set up. */
1178 for (i
= 0; i
< abfd
->symcount
; i
++)
1180 elf_symbol_type
*symbol
= (elf_symbol_type
*)abfd
->outsymbols
[i
];
1182 /* Only functions ever need an entry in the symbol extension
1184 if (!(symbol
->symbol
.flags
& BSF_FUNCTION
))
1187 /* And only if they specify the locations of their arguments. */
1188 if (symbol
->tc_data
.hppa_arg_reloc
== 0)
1191 /* Yup. This function symbol needs an entry. */
1192 symext_chain_size
+= 2 * ELF32_PARISC_SX_SIZE
;
1195 else if (info
->relocateable
== true)
1197 struct elf32_hppa_args_hash_table
*table
;
1198 table
= elf32_hppa_hash_table (info
)->args_hash_table
;
1200 /* Determine the size of the symbol extension section. */
1201 elf32_hppa_args_hash_traverse (table
,
1202 elf32_hppa_size_symext
,
1203 &symext_chain_size
);
1206 /* Now create the section and set its size. We'll fill in the
1208 symextn_sec
= bfd_get_section_by_name (abfd
, SYMEXTN_SECTION_NAME
);
1209 if (symextn_sec
== NULL
)
1210 symextn_sec
= bfd_make_section (abfd
, SYMEXTN_SECTION_NAME
);
1212 bfd_set_section_flags (abfd
, symextn_sec
,
1213 SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_DATA
);
1214 symextn_sec
->output_section
= symextn_sec
;
1215 symextn_sec
->output_offset
= 0;
1216 bfd_set_section_alignment (abfd
, symextn_sec
, 2);
1217 bfd_set_section_size (abfd
, symextn_sec
, symext_chain_size
);
1220 /* Called for each entry in the args location hash table. For each
1221 entry we bump the size pointer by 2 records (16 bytes). */
1224 elf32_hppa_size_symext (gen_entry
, in_args
)
1225 struct bfd_hash_entry
*gen_entry
;
1228 bfd_size_type
*sizep
= (bfd_size_type
*)in_args
;
1230 *sizep
+= 2 * ELF32_PARISC_SX_SIZE
;
1234 /* Backend routine called by the linker for each output symbol.
1236 For PA ELF we use this opportunity to add an appropriate entry
1237 to the symbol extension chain for function symbols. */
1240 elf32_hppa_link_output_symbol_hook (abfd
, info
, name
, sym
, section
)
1242 struct bfd_link_info
*info
;
1244 Elf_Internal_Sym
*sym
;
1248 unsigned int len
, index
;
1249 struct elf32_hppa_args_hash_table
*args_hash_table
;
1250 struct elf32_hppa_args_hash_entry
*args_hash
;
1252 /* If the args hash table is NULL, then we've encountered an error
1253 of some sorts (for example, an undefined symbol). In that case
1254 we've got nothing else to do.
1256 NOTE: elf_link_output_symbol will abort if we return false here! */
1257 if (elf32_hppa_hash_table (info
)->args_hash_table
== NULL
)
1260 index
= elf32_hppa_hash_table (info
)->output_symbol_count
++;
1262 /* We need to look up this symbol in the args hash table to see if
1263 it has argument relocation bits. */
1264 if (ELF_ST_TYPE (sym
->st_info
) != STT_FUNC
)
1267 /* We know it's a function symbol of some kind. */
1268 len
= strlen (name
) + 1;
1269 if (ELF_ST_BIND (sym
->st_info
) == STB_LOCAL
)
1272 new_name
= bfd_malloc (len
);
1273 if (new_name
== NULL
)
1276 strcpy (new_name
, name
);
1277 if (ELF_ST_BIND (sym
->st_info
) == STB_LOCAL
)
1278 sprintf (new_name
+ len
- 10, "_%08x", (int)section
);
1280 /* Now that we have the unique name, we can look it up in the
1282 args_hash_table
= elf32_hppa_hash_table (info
)->args_hash_table
;
1283 args_hash
= elf32_hppa_args_hash_lookup (args_hash_table
, new_name
,
1286 if (args_hash
== NULL
)
1289 /* We know this symbol has arg reloc bits. */
1290 add_entry_to_symext_chain (abfd
, args_hash
->arg_bits
,
1291 index
, &symext_rootP
, &symext_lastP
);
1295 /* Perform any processing needed late in the object file writing process.
1296 For PA ELF we build and set the contents of the symbol extension
1300 elf32_hppa_backend_final_write_processing (abfd
, linker
)
1304 asection
*symextn_sec
;
1307 /* Now build the symbol extension section. */
1308 if (symext_chain_size
== 0)
1313 /* We were not called from the backend linker, so we still need
1314 to build the symbol extension chain.
1316 Look at each symbol, adding the appropriate information to the
1317 symbol extension section list as necessary. */
1318 for (i
= 0; i
< abfd
->symcount
; i
++)
1320 elf_symbol_type
*symbol
= (elf_symbol_type
*) abfd
->outsymbols
[i
];
1322 /* Only functions ever need an entry in the symbol extension
1324 if (!(symbol
->symbol
.flags
& BSF_FUNCTION
))
1327 /* And only if they specify the locations of their arguments. */
1328 if (symbol
->tc_data
.hppa_arg_reloc
== 0)
1331 /* Add this symbol's information to the chain. */
1332 add_entry_to_symext_chain (abfd
, symbol
->tc_data
.hppa_arg_reloc
,
1333 symbol
->symbol
.udata
.i
, &symext_rootP
,
1338 /* Now fill in the contents of the symbol extension section. */
1339 elf_hppa_tc_make_sections (abfd
, symext_rootP
);
1341 /* And attach that as the section's contents. */
1342 symextn_sec
= bfd_get_section_by_name (abfd
, SYMEXTN_SECTION_NAME
);
1343 if (symextn_sec
== (asection
*) 0)
1346 symextn_sec
->contents
= (void *)symextn_contents
;
1348 bfd_set_section_contents (abfd
, symextn_sec
, symextn_sec
->contents
,
1349 symextn_sec
->output_offset
, symextn_sec
->_raw_size
);
1352 /* Update the symbol extention chain to include the symbol pointed to
1353 by SYMBOLP if SYMBOLP is a function symbol. Used internally and by GAS. */
1356 add_entry_to_symext_chain (abfd
, arg_reloc
, sym_idx
, symext_root
, symext_last
)
1358 unsigned int arg_reloc
;
1359 unsigned int sym_idx
;
1360 symext_chainS
**symext_root
;
1361 symext_chainS
**symext_last
;
1363 symext_chainS
*symextP
;
1365 /* Allocate memory and initialize this entry. */
1366 symextP
= (symext_chainS
*) bfd_alloc (abfd
, sizeof (symext_chainS
) * 2);
1368 abort(); /* FIXME */
1370 symextP
[0].entry
= ELF32_PARISC_SX_WORD (PARISC_SXT_SYMNDX
, sym_idx
);
1371 symextP
[0].next
= &symextP
[1];
1373 symextP
[1].entry
= ELF32_PARISC_SX_WORD (PARISC_SXT_ARG_RELOC
, arg_reloc
);
1374 symextP
[1].next
= NULL
;
1376 /* Now update the chain itself so it can be walked later to build
1377 the symbol extension section. */
1378 if (*symext_root
== NULL
)
1380 *symext_root
= &symextP
[0];
1381 *symext_last
= &symextP
[1];
1385 (*symext_last
)->next
= &symextP
[0];
1386 *symext_last
= &symextP
[1];
1390 /* Build the symbol extension section. */
1393 elf_hppa_tc_make_sections (abfd
, symext_root
)
1395 symext_chainS
*symext_root
;
1397 symext_chainS
*symextP
;
1399 asection
*symextn_sec
;
1401 symextn_sec
= bfd_get_section_by_name (abfd
, SYMEXTN_SECTION_NAME
);
1403 /* Grab some memory for the contents of the symbol extension section
1405 symextn_contents
= (bfd_byte
*) bfd_zalloc (abfd
,
1406 symextn_sec
->_raw_size
);
1407 if (!symextn_contents
)
1408 abort(); /* FIXME */
1410 /* Fill in the contents of the symbol extension chain. */
1411 for (i
= 0, symextP
= symext_root
; symextP
; symextP
= symextP
->next
, ++i
)
1412 ELF32_PARISC_SX_PUT (abfd
, (bfd_vma
) symextP
->entry
,
1413 symextn_contents
+ i
* ELF32_PARISC_SX_SIZE
);
1418 /* Do some PA ELF specific work after reading in the symbol table.
1419 In particular attach the argument relocation from the
1420 symbol extension section to the appropriate symbols. */
1423 elf32_hppa_backend_symbol_table_processing (abfd
, esyms
,symcnt
)
1425 elf_symbol_type
*esyms
;
1426 unsigned int symcnt
;
1428 Elf32_Internal_Shdr
*symextn_hdr
=
1429 bfd_elf_find_section (abfd
, SYMEXTN_SECTION_NAME
);
1430 unsigned int i
, current_sym_idx
= 0;
1432 /* If no symbol extension existed, then all symbol extension information
1433 is assumed to be zero. */
1434 if (symextn_hdr
== NULL
)
1436 for (i
= 0; i
< symcnt
; i
++)
1437 esyms
[i
].tc_data
.hppa_arg_reloc
= 0;
1441 /* FIXME: Why not use bfd_get_section_contents here? Also should give
1442 memory back when we're done. */
1443 /* Allocate a buffer of the appropriate size for the symextn section. */
1444 symextn_hdr
->contents
= bfd_zalloc(abfd
,symextn_hdr
->sh_size
);
1445 if (!symextn_hdr
->contents
)
1448 /* Read in the symextn section. */
1449 if (bfd_seek (abfd
, symextn_hdr
->sh_offset
, SEEK_SET
) == -1)
1451 if (bfd_read ((PTR
) symextn_hdr
->contents
, 1, symextn_hdr
->sh_size
, abfd
)
1452 != symextn_hdr
->sh_size
)
1455 /* Parse entries in the symbol extension section, updating the symtab
1457 for (i
= 0; i
< symextn_hdr
->sh_size
/ ELF32_PARISC_SX_SIZE
; i
++)
1460 ELF32_PARISC_SX_GET (abfd
,
1461 ((unsigned char *)symextn_hdr
->contents
1462 + i
* ELF32_PARISC_SX_SIZE
));
1463 unsigned int se_value
= ELF32_PARISC_SX_VAL (se
);
1464 unsigned int se_type
= ELF32_PARISC_SX_TYPE (se
);
1468 case PARISC_SXT_NULL
:
1471 case PARISC_SXT_SYMNDX
:
1472 if (se_value
>= symcnt
)
1474 bfd_set_error (bfd_error_bad_value
);
1477 current_sym_idx
= se_value
- 1;
1480 case PARISC_SXT_ARG_RELOC
:
1481 esyms
[current_sym_idx
].tc_data
.hppa_arg_reloc
= se_value
;
1485 bfd_set_error (bfd_error_bad_value
);
1492 /* Read and attach the symbol extension information for the symbols
1493 in INPUT_BFD to the argument location hash table. Handle locals
1494 if DO_LOCALS is true; likewise for globals when DO_GLOBALS is true. */
1497 elf32_hppa_read_symext_info (input_bfd
, symtab_hdr
, args_hash_table
, local_syms
)
1499 Elf_Internal_Shdr
*symtab_hdr
;
1500 struct elf32_hppa_args_hash_table
*args_hash_table
;
1501 Elf_Internal_Sym
*local_syms
;
1503 asection
*symextn_sec
;
1505 unsigned int i
, n_entries
, current_index
= 0;
1507 /* Get the symbol extension section for this BFD. If no section exists
1508 then there's nothing to do. Likewise if the section exists, but
1510 symextn_sec
= bfd_get_section_by_name (input_bfd
, SYMEXTN_SECTION_NAME
);
1511 if (symextn_sec
== NULL
)
1514 /* Done separately so we can turn off SEC_HAS_CONTENTS (see below). */
1515 if (symextn_sec
->_raw_size
== 0)
1517 symextn_sec
->flags
&= ~SEC_HAS_CONTENTS
;
1521 contents
= (bfd_byte
*) bfd_malloc ((size_t) symextn_sec
->_raw_size
);
1522 if (contents
== NULL
)
1525 /* How gross. We turn off SEC_HAS_CONTENTS for the input symbol extension
1526 sections to keep the generic ELF/BFD code from trying to do anything
1527 with them. We have to undo that hack temporarily so that we can read
1528 in the contents with the generic code. */
1529 symextn_sec
->flags
|= SEC_HAS_CONTENTS
;
1530 if (bfd_get_section_contents (input_bfd
, symextn_sec
, contents
,
1531 0, symextn_sec
->_raw_size
) == false)
1533 symextn_sec
->flags
&= ~SEC_HAS_CONTENTS
;
1538 /* Gross. Turn off SEC_HAS_CONTENTS for the input symbol extension
1539 sections (see above). */
1540 symextn_sec
->flags
&= ~SEC_HAS_CONTENTS
;
1542 n_entries
= symextn_sec
->_raw_size
/ ELF32_PARISC_SX_SIZE
;
1543 for (i
= 0; i
< n_entries
; i
++)
1545 symext_entryS entry
=
1546 ELF32_PARISC_SX_GET (input_bfd
, contents
+ i
* ELF32_PARISC_SX_SIZE
);
1547 unsigned int value
= ELF32_PARISC_SX_VAL (entry
);
1548 unsigned int type
= ELF32_PARISC_SX_TYPE (entry
);
1549 struct elf32_hppa_args_hash_entry
*args_hash
;
1553 case PARISC_SXT_NULL
:
1556 case PARISC_SXT_SYMNDX
:
1557 if (value
>= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
))
1559 bfd_set_error (bfd_error_bad_value
);
1563 current_index
= value
;
1566 case PARISC_SXT_ARG_RELOC
:
1567 if (current_index
< symtab_hdr
->sh_info
)
1569 Elf_Internal_Shdr
*hdr
;
1571 const char *sym_name
;
1575 hdr
= elf_elfsections (input_bfd
)[local_syms
[current_index
].st_shndx
];
1576 sym_sec
= hdr
->bfd_section
;
1577 sym_name
= bfd_elf_string_from_elf_section (input_bfd
,
1578 symtab_hdr
->sh_link
,
1579 local_syms
[current_index
].st_name
);
1580 len
= strlen (sym_name
) + 10;
1581 new_name
= bfd_malloc (len
);
1582 if (new_name
== NULL
)
1587 strcpy (new_name
, sym_name
);
1588 sprintf (new_name
+ len
- 10, "_%08x", (int)sym_sec
);
1590 /* This is a global symbol with argument location info.
1591 We need to enter it into the hash table. */
1592 args_hash
= elf32_hppa_args_hash_lookup (args_hash_table
,
1596 if (args_hash
== NULL
)
1601 args_hash
->arg_bits
= value
;
1604 else if (current_index
>= symtab_hdr
->sh_info
)
1606 struct elf_link_hash_entry
*h
;
1608 current_index
-= symtab_hdr
->sh_info
;
1609 h
= elf_sym_hashes(input_bfd
)[current_index
];
1610 /* This is a global symbol with argument location
1611 information. We need to enter it into the hash table. */
1612 args_hash
= elf32_hppa_args_hash_lookup (args_hash_table
,
1613 h
->root
.root
.string
,
1615 if (args_hash
== NULL
)
1617 bfd_set_error (bfd_error_bad_value
);
1621 args_hash
->arg_bits
= value
;
1628 bfd_set_error (bfd_error_bad_value
);
1637 /* Undo the generic ELF code's subtraction of section->vma from the
1638 value of each external symbol. */
1641 elf32_hppa_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
1643 struct bfd_link_info
*info
;
1644 const Elf_Internal_Sym
*sym
;
1650 *valp
+= (*secp
)->vma
;
1654 /* Determine the name of the stub needed to perform a call assuming the
1655 argument relocation bits for caller and callee are in CALLER and CALLEE
1656 for a call from LOCATION to DESTINATION. Copy the name into STUB_NAME. */
1659 elf32_hppa_name_of_stub (caller
, callee
, location
, destination
, stub_name
)
1660 unsigned int caller
, callee
;
1661 bfd_vma location
, destination
;
1664 arg_reloc_type arg_reloc_types
[5];
1666 if (elf32_hppa_arg_reloc_needed (caller
, callee
, arg_reloc_types
))
1668 arg_reloc_location i
;
1669 /* Fill in the basic template. */
1670 strcpy (stub_name
, "__XX_XX_XX_XX_XX_stub_");
1672 /* Now fix the specifics. */
1673 for (i
= ARG0
; i
<= RET
; i
++)
1674 switch (arg_reloc_types
[i
])
1677 stub_name
[3 * i
+ 2] = 'N';
1678 stub_name
[3 * i
+ 3] = 'O';
1681 stub_name
[3 * i
+ 2] = 'G';
1682 stub_name
[3 * i
+ 3] = 'F';
1685 stub_name
[3 * i
+ 2] = 'F';
1686 stub_name
[3 * i
+ 3] = 'G';
1689 stub_name
[3 * i
+ 2] = 'G';
1690 stub_name
[3 * i
+ 3] = 'D';
1693 stub_name
[3 * i
+ 2] = 'D';
1694 stub_name
[3 * i
+ 3] = 'G';
1699 strcpy (stub_name
, "_____long_branch_stub_");
1702 /* Determine if an argument relocation stub is needed to perform a
1703 call assuming the argument relocation bits for caller and callee
1704 are in CALLER and CALLEE. Place the type of relocations (if any)
1705 into stub_types_p. */
1708 elf32_hppa_arg_reloc_needed (caller
, callee
, stub_types
)
1709 unsigned int caller
, callee
;
1710 arg_reloc_type stub_types
[5];
1712 /* Special case for no relocations. */
1713 if (caller
== 0 || callee
== 0)
1717 arg_location caller_loc
[5];
1718 arg_location callee_loc
[5];
1720 /* Extract the location information for the argument and return
1721 value on both the caller and callee sides. */
1722 caller_loc
[ARG0
] = EXTRACT_ARBITS (caller
, ARG0
);
1723 callee_loc
[ARG0
] = EXTRACT_ARBITS (callee
, ARG0
);
1724 caller_loc
[ARG1
] = EXTRACT_ARBITS (caller
, ARG1
);
1725 callee_loc
[ARG1
] = EXTRACT_ARBITS (callee
, ARG1
);
1726 caller_loc
[ARG2
] = EXTRACT_ARBITS (caller
, ARG2
);
1727 callee_loc
[ARG2
] = EXTRACT_ARBITS (callee
, ARG2
);
1728 caller_loc
[ARG3
] = EXTRACT_ARBITS (caller
, ARG3
);
1729 callee_loc
[ARG3
] = EXTRACT_ARBITS (callee
, ARG3
);
1730 caller_loc
[RET
] = EXTRACT_ARBITS (caller
, RET
);
1731 callee_loc
[RET
] = EXTRACT_ARBITS (callee
, RET
);
1733 /* Check some special combinations. This is necessary to
1734 deal with double precision FP arguments. */
1735 if (caller_loc
[ARG0
] == AR_FU
|| caller_loc
[ARG1
] == AR_FU
)
1737 caller_loc
[ARG0
] = AR_FPDBL1
;
1738 caller_loc
[ARG1
] = AR_NO
;
1740 if (caller_loc
[ARG2
] == AR_FU
|| caller_loc
[ARG3
] == AR_FU
)
1742 caller_loc
[ARG2
] = AR_FPDBL2
;
1743 caller_loc
[ARG3
] = AR_NO
;
1745 if (callee_loc
[ARG0
] == AR_FU
|| callee_loc
[ARG1
] == AR_FU
)
1747 callee_loc
[ARG0
] = AR_FPDBL1
;
1748 callee_loc
[ARG1
] = AR_NO
;
1750 if (callee_loc
[ARG2
] == AR_FU
|| callee_loc
[ARG3
] == AR_FU
)
1752 callee_loc
[ARG2
] = AR_FPDBL2
;
1753 callee_loc
[ARG3
] = AR_NO
;
1756 /* Now look up any relocation needed for each argument and the
1758 stub_types
[ARG0
] = arg_mismatches
[caller_loc
[ARG0
]][callee_loc
[ARG0
]];
1759 stub_types
[ARG1
] = arg_mismatches
[caller_loc
[ARG1
]][callee_loc
[ARG1
]];
1760 stub_types
[ARG2
] = arg_mismatches
[caller_loc
[ARG2
]][callee_loc
[ARG2
]];
1761 stub_types
[ARG3
] = arg_mismatches
[caller_loc
[ARG3
]][callee_loc
[ARG3
]];
1762 stub_types
[RET
] = ret_mismatches
[caller_loc
[RET
]][callee_loc
[RET
]];
1764 return (stub_types
[ARG0
] != NO
1765 || stub_types
[ARG1
] != NO
1766 || stub_types
[ARG2
] != NO
1767 || stub_types
[ARG3
] != NO
1768 || stub_types
[RET
] != NO
);
1772 /* Compute the size of the stub needed to call from LOCATION to DESTINATION
1773 (a function named SYM_NAME), with argument relocation bits CALLER and
1774 CALLEE. Return zero if no stub is needed to perform such a call. */
1777 elf32_hppa_size_of_stub (callee
, caller
, location
, destination
, sym_name
)
1778 unsigned int callee
, caller
;
1779 bfd_vma location
, destination
;
1780 const char *sym_name
;
1782 arg_reloc_type arg_reloc_types
[5];
1784 /* Determine if a long branch or argument relocation stub is needed.
1785 If an argument relocation stub is needed, the relocation will be
1786 stored into arg_reloc_types. */
1787 if (!(((int)(location
- destination
) > 0x3ffff)
1788 || ((int)(location
- destination
) < (int)0xfffc0000)
1789 || elf32_hppa_arg_reloc_needed (caller
, callee
, arg_reloc_types
)))
1792 /* Some kind of stub is needed. Determine how big it needs to be.
1793 First check for argument relocation stubs as they also handle
1794 long calls. Then check for long calls to millicode and finally
1795 the normal long calls. */
1796 if (arg_reloc_types
[ARG0
] != NO
1797 || arg_reloc_types
[ARG1
] != NO
1798 || arg_reloc_types
[ARG2
] != NO
1799 || arg_reloc_types
[ARG3
] != NO
1800 || arg_reloc_types
[RET
] != NO
)
1802 /* Some kind of argument relocation stub is needed. */
1803 unsigned int len
= 16;
1804 arg_reloc_location i
;
1806 /* Each GR or FG relocation takes 2 insns, each GD or DG
1807 relocation takes 3 insns. Plus 4 more insns for the
1808 RP adjustment, ldil & (be | ble) and copy. */
1809 for (i
= ARG0
; i
<= RET
; i
++)
1810 switch (arg_reloc_types
[i
])
1826 /* Extra instructions are needed if we're relocating a return value. */
1827 if (arg_reloc_types
[RET
] != NO
)
1832 else if (!strncmp ("$$", sym_name
, 2)
1833 && strcmp ("$$dyncall", sym_name
))
1839 /* Build one linker stub as defined by the stub hash table entry GEN_ENTRY.
1840 IN_ARGS contains the stub BFD and link info pointers. */
1843 elf32_hppa_build_one_stub (gen_entry
, in_args
)
1844 struct bfd_hash_entry
*gen_entry
;
1847 void **args
= (void **)in_args
;
1848 bfd
*stub_bfd
= (bfd
*)args
[0];
1849 struct bfd_link_info
*info
= (struct bfd_link_info
*)args
[1];
1850 struct elf32_hppa_stub_hash_entry
*entry
;
1851 struct elf32_hppa_stub_hash_table
*stub_hash_table
;
1854 const char *sym_name
;
1856 /* Initialize pointers to the stub hash table, the particular entry we
1857 are building a stub for, and where (in memory) we should place the stub
1859 entry
= (struct elf32_hppa_stub_hash_entry
*)gen_entry
;
1860 stub_hash_table
= elf32_hppa_hash_table(info
)->stub_hash_table
;
1861 loc
= stub_hash_table
->location
;
1863 /* Make a note of the offset within the stubs for this entry. */
1864 entry
->offset
= stub_hash_table
->offset
;
1866 /* The symbol's name starts at offset 22. */
1867 sym_name
= entry
->root
.string
+ 22;
1869 sym_value
= (entry
->target_value
1870 + entry
->target_section
->output_offset
1871 + entry
->target_section
->output_section
->vma
);
1873 if (strncmp ("_____long_branch_stub_", entry
->root
.string
, 22))
1875 /* This must be an argument or return value relocation stub. */
1877 arg_reloc_location i
;
1878 bfd_byte
*begin_loc
= loc
;
1880 /* First the return pointer adjustment. Depending on exact calling
1881 sequence this instruction may be skipped. */
1882 bfd_put_32 (stub_bfd
, LDO_M4_R31_R31
, loc
);
1885 /* If we are relocating a return value, then we're going to have
1886 to return into the stub. So we have to save off the user's
1887 return pointer into the stack at RP'. */
1888 if (strncmp (entry
->root
.string
+ 14, "NO", 2))
1890 bfd_put_32 (stub_bfd
, STW_R31_M8R30
, loc
);
1894 /* Iterate over the argument relocations, emitting instructions
1895 to move them around as necessary. */
1896 for (i
= ARG0
; i
<= ARG3
; i
++)
1898 if (!strncmp (entry
->root
.string
+ 3 * i
+ 2, "GF", 2))
1900 bfd_put_32 (stub_bfd
, STW_ARG_M16R30
| ((26 - i
) << 16), loc
);
1901 bfd_put_32 (stub_bfd
, FLDW_M16R30_FARG
| (4 + i
), loc
+ 4);
1904 else if (!strncmp (entry
->root
.string
+ 3 * i
+ 2, "FG", 2))
1906 bfd_put_32 (stub_bfd
, FSTW_FARG_M16R30
| (4 + i
), loc
);
1907 bfd_put_32 (stub_bfd
, LDW_M16R30_ARG
| ((26 - i
) << 16), loc
+ 4);
1910 else if (!strncmp (entry
->root
.string
+ 3 * i
+ 2, "GD", 2))
1912 bfd_put_32 (stub_bfd
, STW_ARG_M12R30
| ((26 - i
) << 16), loc
);
1913 bfd_put_32 (stub_bfd
, STW_ARG_M16R30
| ((25 - i
) << 16), loc
+ 4);
1914 bfd_put_32 (stub_bfd
, FLDD_M16R30_FARG
| (5 + i
), loc
+ 8);
1917 else if (!strncmp (entry
->root
.string
+ 3 * i
+ 2, "DG", 2))
1919 bfd_put_32 (stub_bfd
, FSTD_FARG_M16R30
| (5 + i
), loc
);
1920 bfd_put_32 (stub_bfd
, LDW_M12R30_ARG
| ((26 - i
) << 16), loc
+ 4);
1921 bfd_put_32 (stub_bfd
, LDW_M16R30_ARG
| ((25 - i
) << 16), loc
+ 8);
1926 /* Load the high bits of the target address into %r1. */
1927 insn
= hppa_rebuild_insn (stub_bfd
, LDIL_R1
,
1928 hppa_field_adjust (sym_value
, 0, e_lrsel
), 21);
1929 bfd_put_32 (stub_bfd
, insn
, loc
);
1932 /* If we are relocating a return value, then we're going to have
1933 to return into the stub, then perform the return value relocation. */
1934 if (strncmp (entry
->root
.string
+ 14, "NO", 2))
1936 /* To return to the stub we "ble" to the target and copy the return
1937 pointer from %r31 into %r2. */
1938 insn
= hppa_rebuild_insn (stub_bfd
,
1940 hppa_field_adjust (sym_value
, 0,
1943 bfd_put_32 (stub_bfd
, insn
, loc
);
1944 bfd_put_32 (stub_bfd
, COPY_R31_R2
, loc
+ 4);
1946 /* Reload the return pointer for our caller from the stack. */
1947 bfd_put_32 (stub_bfd
, LDW_M8R30_R31
, loc
+ 8);
1950 /* Perform the return value relocation. */
1951 if (!strncmp (entry
->root
.string
+ 14, "GF", 2))
1953 bfd_put_32 (stub_bfd
, STW_ARG_M16R30
| (28 << 16), loc
);
1954 bfd_put_32 (stub_bfd
, FLDW_M16R30_FARG
| 4, loc
+ 4);
1957 else if (!strncmp (entry
->root
.string
+ 14, "FG", 2))
1959 bfd_put_32 (stub_bfd
, FSTW_FARG_M16R30
| 4, loc
);
1960 bfd_put_32 (stub_bfd
, LDW_M16R30_ARG
| (28 << 16), loc
+ 4);
1963 else if (!strncmp (entry
->root
.string
+ 2, "GD", 2))
1965 bfd_put_32 (stub_bfd
, STW_ARG_M12R30
| (28 << 16), loc
);
1966 bfd_put_32 (stub_bfd
, STW_ARG_M16R30
| (29 << 16), loc
+ 4);
1967 bfd_put_32 (stub_bfd
, FLDD_M16R30_FARG
| 4, loc
+ 8);
1970 else if (!strncmp (entry
->root
.string
+ 2, "DG", 2))
1972 bfd_put_32 (stub_bfd
, FSTD_FARG_M16R30
| 4, loc
);
1973 bfd_put_32 (stub_bfd
, LDW_M12R30_ARG
| (28 << 16), loc
+ 4);
1974 bfd_put_32 (stub_bfd
, LDW_M16R30_ARG
| (29 << 16), loc
+ 8);
1977 /* Branch back to the user's code now. */
1978 bfd_put_32 (stub_bfd
, BV_N_0_R31
, loc
);
1983 /* No return value relocation, so we can simply "be" to the
1984 target and copy out return pointer into %r2. */
1985 insn
= hppa_rebuild_insn (stub_bfd
, BE_SR4_R1
,
1986 hppa_field_adjust (sym_value
, 0,
1988 bfd_put_32 (stub_bfd
, insn
, loc
);
1989 bfd_put_32 (stub_bfd
, COPY_R31_R2
, loc
+ 4);
1993 /* Update the location and offsets. */
1994 stub_hash_table
->location
+= (loc
- begin_loc
);
1995 stub_hash_table
->offset
+= (loc
- begin_loc
);
1999 /* Create one of two variant long branch stubs. One for $$dyncall and
2000 normal calls, the other for calls to millicode. */
2002 int millicode_call
= 0;
2004 if (!strncmp ("$$", sym_name
, 2) && strcmp ("$$dyncall", sym_name
))
2007 /* First the return pointer adjustment. Depending on exact calling
2008 sequence this instruction may be skipped. */
2009 bfd_put_32 (stub_bfd
, LDO_M4_R31_R31
, loc
);
2011 /* The next two instructions are the long branch itself. A long branch
2012 is formed with "ldil" loading the upper bits of the target address
2013 into a register, then branching with "be" which adds in the lower bits.
2014 Long branches to millicode nullify the delay slot of the "be". */
2015 insn
= hppa_rebuild_insn (stub_bfd
, LDIL_R1
,
2016 hppa_field_adjust (sym_value
, 0, e_lrsel
), 21);
2017 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
2018 insn
= hppa_rebuild_insn (stub_bfd
, BE_SR4_R1
| (millicode_call
? 2 : 0),
2019 hppa_field_adjust (sym_value
, 0, e_rrsel
) >> 2,
2021 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
2023 if (!millicode_call
)
2025 /* The sequence to call this stub places the return pointer into %r31,
2026 the final target expects the return pointer in %r2, so copy the
2027 return pointer into the proper register. */
2028 bfd_put_32 (stub_bfd
, COPY_R31_R2
, loc
+ 12);
2030 /* Update the location and offsets. */
2031 stub_hash_table
->location
+= 16;
2032 stub_hash_table
->offset
+= 16;
2036 /* Update the location and offsets. */
2037 stub_hash_table
->location
+= 12;
2038 stub_hash_table
->offset
+= 12;
2045 /* External entry points for sizing and building linker stubs. */
2047 /* Build all the stubs associated with the current output file. The
2048 stubs are kept in a hash table attached to the main linker hash
2049 table. This is called via hppaelf_finish in the linker. */
2052 elf32_hppa_build_stubs (stub_bfd
, info
)
2054 struct bfd_link_info
*info
;
2056 /* The stub BFD only has one section. */
2057 asection
*stub_sec
= stub_bfd
->sections
;
2058 struct elf32_hppa_stub_hash_table
*table
;
2062 /* So we can pass both the BFD for the stubs and the link info
2063 structure to the routine which actually builds stubs. */
2067 /* Allocate memory to hold the linker stubs. */
2068 size
= bfd_section_size (stub_bfd
, stub_sec
);
2069 stub_sec
->contents
= (unsigned char *) bfd_zalloc (stub_bfd
, size
);
2070 if (stub_sec
->contents
== NULL
)
2072 table
= elf32_hppa_hash_table(info
)->stub_hash_table
;
2073 table
->location
= stub_sec
->contents
;
2075 /* Build the stubs as directed by the stub hash table. */
2076 elf32_hppa_stub_hash_traverse (table
, elf32_hppa_build_one_stub
, args
);
2081 /* Determine and set the size of the stub section for a final link.
2083 The basic idea here is to examine all the relocations looking for
2084 PC-relative calls to a target that is unreachable with a "bl"
2085 instruction or calls where the caller and callee disagree on the
2086 location of their arguments or return value. */
2089 elf32_hppa_size_stubs (stub_bfd
, output_bfd
, link_info
)
2092 struct bfd_link_info
*link_info
;
2095 asection
*section
, *stub_sec
= 0;
2096 Elf_Internal_Shdr
*symtab_hdr
;
2097 Elf_Internal_Sym
*local_syms
, *isym
, **all_local_syms
;
2098 Elf32_External_Sym
*ext_syms
, *esym
;
2099 unsigned int i
, index
, bfd_count
= 0;
2100 struct elf32_hppa_stub_hash_table
*stub_hash_table
= 0;
2101 struct elf32_hppa_args_hash_table
*args_hash_table
= 0;
2103 /* Create and initialize the stub hash table. */
2104 stub_hash_table
= ((struct elf32_hppa_stub_hash_table
*)
2105 bfd_malloc (sizeof (struct elf32_hppa_stub_hash_table
)));
2106 if (!stub_hash_table
)
2109 if (!elf32_hppa_stub_hash_table_init (stub_hash_table
, stub_bfd
,
2110 elf32_hppa_stub_hash_newfunc
))
2113 /* Likewise for the argument location hash table. */
2114 args_hash_table
= ((struct elf32_hppa_args_hash_table
*)
2115 bfd_malloc (sizeof (struct elf32_hppa_args_hash_table
)));
2116 if (!args_hash_table
)
2119 if (!elf32_hppa_args_hash_table_init (args_hash_table
,
2120 elf32_hppa_args_hash_newfunc
))
2123 /* Attach the hash tables to the main hash table. */
2124 elf32_hppa_hash_table(link_info
)->stub_hash_table
= stub_hash_table
;
2125 elf32_hppa_hash_table(link_info
)->args_hash_table
= args_hash_table
;
2127 /* Count the number of input BFDs. */
2128 for (input_bfd
= link_info
->input_bfds
;
2130 input_bfd
= input_bfd
->link_next
)
2133 /* We want to read in symbol extension records only once. To do this
2134 we need to read in the local symbols in parallel and save them for
2135 later use; so hold pointers to the local symbols in an array. */
2137 = (Elf_Internal_Sym
**) bfd_malloc (sizeof (Elf_Internal_Sym
*)
2139 if (all_local_syms
== NULL
)
2141 memset (all_local_syms
, 0, sizeof (Elf_Internal_Sym
*) * bfd_count
);
2143 /* Walk over all the input BFDs adding entries to the args hash table
2144 for all the external functions. */
2145 for (input_bfd
= link_info
->input_bfds
, index
= 0;
2147 input_bfd
= input_bfd
->link_next
, index
++)
2149 /* We'll need the symbol table in a second. */
2150 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2151 if (symtab_hdr
->sh_info
== 0)
2154 /* We need an array of the local symbols attached to the input bfd.
2155 Unfortunately, we're going to have to read & swap them in. */
2157 = (Elf_Internal_Sym
*) bfd_malloc (symtab_hdr
->sh_info
2158 * sizeof (Elf_Internal_Sym
));
2159 if (local_syms
== NULL
)
2161 for (i
= 0; i
< bfd_count
; i
++)
2162 if (all_local_syms
[i
])
2163 free (all_local_syms
[i
]);
2164 free (all_local_syms
);
2167 all_local_syms
[index
] = local_syms
;
2170 = (Elf32_External_Sym
*) bfd_malloc (symtab_hdr
->sh_info
2171 * sizeof (Elf32_External_Sym
));
2172 if (ext_syms
== NULL
)
2174 for (i
= 0; i
< bfd_count
; i
++)
2175 if (all_local_syms
[i
])
2176 free (all_local_syms
[i
]);
2177 free (all_local_syms
);
2181 if (bfd_seek (input_bfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
2182 || bfd_read (ext_syms
, 1,
2183 (symtab_hdr
->sh_info
2184 * sizeof (Elf32_External_Sym
)), input_bfd
)
2185 != (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
)))
2187 for (i
= 0; i
< bfd_count
; i
++)
2188 if (all_local_syms
[i
])
2189 free (all_local_syms
[i
]);
2190 free (all_local_syms
);
2195 /* Swap the local symbols in. */
2198 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++, esym
++, isym
++)
2199 bfd_elf32_swap_symbol_in (input_bfd
, esym
, isym
);
2201 /* Now we can free the external symbols. */
2204 if (elf32_hppa_read_symext_info (input_bfd
, symtab_hdr
, args_hash_table
,
2205 local_syms
) == false)
2207 for (i
= 0; i
< bfd_count
; i
++)
2208 if (all_local_syms
[i
])
2209 free (all_local_syms
[i
]);
2210 free (all_local_syms
);
2215 /* Magic as we know the stub bfd only has one section. */
2216 stub_sec
= stub_bfd
->sections
;
2218 /* If generating a relocateable output file, then we don't
2219 have to examine the relocs. */
2220 if (link_info
->relocateable
)
2222 for (i
= 0; i
< bfd_count
; i
++)
2223 if (all_local_syms
[i
])
2224 free (all_local_syms
[i
]);
2225 free (all_local_syms
);
2229 /* Now that we have argument location information for all the global
2230 functions we can start looking for stubs. */
2231 for (input_bfd
= link_info
->input_bfds
, index
= 0;
2233 input_bfd
= input_bfd
->link_next
, index
++)
2235 /* We'll need the symbol table in a second. */
2236 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2237 if (symtab_hdr
->sh_info
== 0)
2240 local_syms
= all_local_syms
[index
];
2242 /* Walk over each section attached to the input bfd. */
2243 for (section
= input_bfd
->sections
;
2245 section
= section
->next
)
2247 Elf_Internal_Shdr
*input_rel_hdr
;
2248 Elf32_External_Rela
*external_relocs
, *erelaend
, *erela
;
2249 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
2251 /* If there aren't any relocs, then there's nothing to do. */
2252 if ((section
->flags
& SEC_RELOC
) == 0
2253 || section
->reloc_count
== 0)
2256 /* Allocate space for the external relocations. */
2258 = ((Elf32_External_Rela
*)
2259 bfd_malloc (section
->reloc_count
2260 * sizeof (Elf32_External_Rela
)));
2261 if (external_relocs
== NULL
)
2263 for (i
= 0; i
< bfd_count
; i
++)
2264 if (all_local_syms
[i
])
2265 free (all_local_syms
[i
]);
2266 free (all_local_syms
);
2270 /* Likewise for the internal relocations. */
2272 = ((Elf_Internal_Rela
*)
2273 bfd_malloc (section
->reloc_count
* sizeof (Elf_Internal_Rela
)));
2274 if (internal_relocs
== NULL
)
2276 free (external_relocs
);
2277 for (i
= 0; i
< bfd_count
; i
++)
2278 if (all_local_syms
[i
])
2279 free (all_local_syms
[i
]);
2280 free (all_local_syms
);
2284 /* Read in the external relocs. */
2285 input_rel_hdr
= &elf_section_data (section
)->rel_hdr
;
2286 if (bfd_seek (input_bfd
, input_rel_hdr
->sh_offset
, SEEK_SET
) != 0
2287 || bfd_read (external_relocs
, 1, input_rel_hdr
->sh_size
,
2288 input_bfd
) != input_rel_hdr
->sh_size
)
2290 free (external_relocs
);
2291 free (internal_relocs
);
2292 for (i
= 0; i
< bfd_count
; i
++)
2293 if (all_local_syms
[i
])
2294 free (all_local_syms
[i
]);
2295 free (all_local_syms
);
2299 /* Swap in the relocs. */
2300 erela
= external_relocs
;
2301 erelaend
= erela
+ section
->reloc_count
;
2302 irela
= internal_relocs
;
2303 for (; erela
< erelaend
; erela
++, irela
++)
2304 bfd_elf32_swap_reloca_in (input_bfd
, erela
, irela
);
2306 /* We're done with the external relocs, free them. */
2307 free (external_relocs
);
2309 /* Now examine each relocation. */
2310 irela
= internal_relocs
;
2311 irelaend
= irela
+ section
->reloc_count
;
2312 for (; irela
< irelaend
; irela
++)
2314 long r_type
, callee_args
, caller_args
, size_of_stub
;
2315 unsigned long r_index
;
2316 struct elf_link_hash_entry
*hash
;
2317 struct elf32_hppa_stub_hash_entry
*stub_hash
;
2318 struct elf32_hppa_args_hash_entry
*args_hash
;
2319 Elf_Internal_Sym
*sym
;
2321 const char *sym_name
;
2323 bfd_vma location
, destination
;
2324 char *new_name
= NULL
;
2326 r_type
= ELF32_R_TYPE (irela
->r_info
);
2327 r_index
= ELF32_R_SYM (irela
->r_info
);
2329 if (r_type
< 0 || r_type
>= (int) R_PARISC_UNIMPLEMENTED
)
2331 bfd_set_error (bfd_error_bad_value
);
2332 free (internal_relocs
);
2333 for (i
= 0; i
< bfd_count
; i
++)
2334 if (all_local_syms
[i
])
2335 free (all_local_syms
[i
]);
2336 free (all_local_syms
);
2340 /* Only look for stubs on call instructions or plabel
2342 if (r_type
!= R_PARISC_PCREL17F
2343 && r_type
!= R_PARISC_PLABEL32
2344 && r_type
!= R_PARISC_PLABEL21L
2345 && r_type
!= R_PARISC_PLABEL14R
)
2348 /* Now determine the call target, its name, value, section
2349 and argument relocation bits. */
2353 if (r_index
< symtab_hdr
->sh_info
)
2355 /* It's a local symbol. */
2356 Elf_Internal_Shdr
*hdr
;
2358 sym
= local_syms
+ r_index
;
2359 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
2360 sym_sec
= hdr
->bfd_section
;
2361 sym_name
= bfd_elf_string_from_elf_section (input_bfd
,
2362 symtab_hdr
->sh_link
,
2364 sym_value
= (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
2365 ? 0 : sym
->st_value
);
2366 destination
= (sym_value
2367 + sym_sec
->output_offset
2368 + sym_sec
->output_section
->vma
);
2370 /* Tack on an ID so we can uniquely identify this local
2371 symbol in the stub or arg info hash tables. */
2372 new_name
= bfd_malloc (strlen (sym_name
) + 10);
2375 free (internal_relocs
);
2376 for (i
= 0; i
< bfd_count
; i
++)
2377 if (all_local_syms
[i
])
2378 free (all_local_syms
[i
]);
2379 free (all_local_syms
);
2382 sprintf (new_name
, "%s_%08x", sym_name
, (int)sym_sec
);
2383 sym_name
= new_name
;
2387 /* It's an external symbol. */
2390 index
= r_index
- symtab_hdr
->sh_info
;
2391 hash
= elf_sym_hashes (input_bfd
)[index
];
2392 if (hash
->root
.type
== bfd_link_hash_defined
2393 || hash
->root
.type
== bfd_link_hash_defweak
)
2395 sym_sec
= hash
->root
.u
.def
.section
;
2396 sym_name
= hash
->root
.root
.string
;
2397 sym_value
= hash
->root
.u
.def
.value
;
2398 destination
= (sym_value
2399 + sym_sec
->output_offset
2400 + sym_sec
->output_section
->vma
);
2404 bfd_set_error (bfd_error_bad_value
);
2405 free (internal_relocs
);
2406 for (i
= 0; i
< bfd_count
; i
++)
2407 if (all_local_syms
[i
])
2408 free (all_local_syms
[i
]);
2409 free (all_local_syms
);
2414 args_hash
= elf32_hppa_args_hash_lookup (args_hash_table
,
2415 sym_name
, false, false);
2417 /* Get both caller and callee argument information. */
2418 if (args_hash
== NULL
)
2421 callee_args
= args_hash
->arg_bits
;
2423 /* For calls get the caller's bits from the addend of
2424 the call relocation. For PLABELS the caller's bits
2425 are assumed to have all args & return values in general
2426 registers (0x155). */
2427 if (r_type
== R_PARISC_PCREL17F
)
2428 caller_args
= HPPA_R_ARG_RELOC (irela
->r_addend
);
2430 caller_args
= 0x155;
2432 /* Now determine where the call point is. */
2433 location
= (section
->output_offset
2434 + section
->output_section
->vma
2437 /* We only care about the destination for PCREL function
2438 calls (eg. we don't care for PLABELS). */
2439 if (r_type
!= R_PARISC_PCREL17F
)
2440 location
= destination
;
2442 /* Determine what (if any) linker stub is needed and its
2444 size_of_stub
= elf32_hppa_size_of_stub (callee_args
,
2449 if (size_of_stub
!= 0)
2454 /* Get the name of this stub. */
2455 len
= strlen (sym_name
);
2458 stub_name
= bfd_malloc (len
);
2461 /* Because sym_name was mallocd above for local
2463 if (r_index
< symtab_hdr
->sh_info
)
2466 free (internal_relocs
);
2467 for (i
= 0; i
< bfd_count
; i
++)
2468 if (all_local_syms
[i
])
2469 free (all_local_syms
[i
]);
2470 free (all_local_syms
);
2473 elf32_hppa_name_of_stub (caller_args
, callee_args
,
2474 location
, destination
, stub_name
);
2475 strcat (stub_name
+ 22, sym_name
);
2477 /* Because sym_name was malloced above for local symbols. */
2478 if (r_index
< symtab_hdr
->sh_info
)
2482 = elf32_hppa_stub_hash_lookup (stub_hash_table
, stub_name
,
2484 if (stub_hash
!= NULL
)
2486 /* The proper stub has already been created, nothing
2492 bfd_set_section_size (stub_bfd
, stub_sec
,
2493 (bfd_section_size (stub_bfd
,
2497 /* Enter this entry into the linker stub hash table. */
2499 = elf32_hppa_stub_hash_lookup (stub_hash_table
,
2500 stub_name
, true, true);
2501 if (stub_hash
== NULL
)
2504 free (internal_relocs
);
2505 for (i
= 0; i
< bfd_count
; i
++)
2506 if (all_local_syms
[i
])
2507 free (all_local_syms
[i
]);
2508 free (all_local_syms
);
2512 /* We'll need these to determine the address that the
2513 stub will branch to. */
2514 stub_hash
->target_value
= sym_value
;
2515 stub_hash
->target_section
= sym_sec
;
2520 /* We're done with the internal relocs, free them. */
2521 free (internal_relocs
);
2524 /* We're done with the local symbols, free them. */
2525 for (i
= 0; i
< bfd_count
; i
++)
2526 if (all_local_syms
[i
])
2527 free (all_local_syms
[i
]);
2528 free (all_local_syms
);
2532 /* Return gracefully, avoiding dangling references to the hash tables. */
2533 if (stub_hash_table
)
2535 elf32_hppa_hash_table(link_info
)->stub_hash_table
= NULL
;
2536 free (stub_hash_table
);
2538 if (args_hash_table
)
2540 elf32_hppa_hash_table(link_info
)->args_hash_table
= NULL
;
2541 free (args_hash_table
);
2543 /* Set the size of the stub section to zero since we're never going
2544 to create them. Avoids losing when we try to get its contents
2546 bfd_set_section_size (stub_bfd
, stub_sec
, 0);
2550 /* Misc BFD support code. */
2551 #define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
2552 #define bfd_elf32_bfd_is_local_label_name hppa_elf_is_local_label_name
2553 #define elf_info_to_howto elf_hppa_info_to_howto
2554 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel
2556 /* Symbol extension stuff. */
2557 #define bfd_elf32_set_section_contents elf32_hppa_set_section_contents
2558 #define elf_backend_symbol_table_processing \
2559 elf32_hppa_backend_symbol_table_processing
2560 #define elf_backend_begin_write_processing \
2561 elf32_hppa_backend_begin_write_processing
2562 #define elf_backend_final_write_processing \
2563 elf32_hppa_backend_final_write_processing
2565 /* Stuff for the BFD linker. */
2566 #define elf_backend_relocate_section elf32_hppa_relocate_section
2567 #define elf_backend_add_symbol_hook elf32_hppa_add_symbol_hook
2568 #define elf_backend_link_output_symbol_hook \
2569 elf32_hppa_link_output_symbol_hook
2570 #define bfd_elf32_bfd_link_hash_table_create \
2571 elf32_hppa_link_hash_table_create
2573 #define TARGET_BIG_SYM bfd_elf32_hppa_vec
2574 #define TARGET_BIG_NAME "elf32-hppa"
2575 #define ELF_ARCH bfd_arch_hppa
2576 #define ELF_MACHINE_CODE EM_PARISC
2577 #define ELF_MAXPAGESIZE 0x1000
2579 #include "elf32-target.h"