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. */
34 /* The internal type of a symbol table extension entry. */
35 typedef unsigned long symext_entryS
;
37 /* The external type of a symbol table extension entry. */
38 #define ELF32_PARISC_SX_SIZE (4)
39 #define ELF32_PARISC_SX_GET(bfd, addr) bfd_h_get_32 ((bfd), (addr))
40 #define ELF32_PARISC_SX_PUT(bfd, val, addr) \
41 bfd_h_put_32 ((bfd), (val), (addr))
43 /* HPPA symbol table extension entry types */
44 enum elf32_hppa_symextn_types
51 /* These macros compose and decompose the value of a symextn entry:
53 entry_type = ELF32_PARISC_SX_TYPE(word);
54 entry_value = ELF32_PARISC_SX_VAL(word);
55 word = ELF32_PARISC_SX_WORD(type,val); */
57 #define ELF32_PARISC_SX_TYPE(p) ((p) >> 24)
58 #define ELF32_PARISC_SX_VAL(p) ((p) & 0xFFFFFF)
59 #define ELF32_PARISC_SX_WORD(type,val) (((type) << 24) + (val & 0xFFFFFF))
61 /* The following was added facilitate implementation of the .hppa_symextn
62 section. This section is built after the symbol table is built in the
63 elf_write_object_contents routine (called from bfd_close). It is built
64 so late because it requires information that is not known until
65 the symbol and string table sections have been allocated, and
66 the symbol table has been built. */
68 #define SYMEXTN_SECTION_NAME ".PARISC.symext"
73 struct symext_chain
*next
;
76 typedef struct symext_chain symext_chainS
;
78 /* We use three different hash tables to hold information for
79 linking PA ELF objects.
81 The first is the elf32_hppa_link_hash_table which is derived
82 from the standard ELF linker hash table. We use this as a place to
83 attach other hash tables and static information.
85 The second is the stub hash table which is derived from the
86 base BFD hash table. The stub hash table holds the information
87 necessary to build the linker stubs during a link.
89 The last hash table keeps track of argument location information needed
90 to build hash tables. Each function with nonzero argument location
91 bits will have an entry in this table. */
93 /* Hash table for linker stubs. */
95 struct elf32_hppa_stub_hash_entry
97 /* Base hash table entry structure, we can get the name of the stub
98 (and thus know exactly what actions it performs) from the base
100 struct bfd_hash_entry root
;
102 /* Offset of the beginning of this stub. */
105 /* Given the symbol's value and its section we can determine its final
106 value when building the stubs (so the stub knows where to jump. */
107 symvalue target_value
;
108 asection
*target_section
;
111 struct elf32_hppa_stub_hash_table
113 /* The hash table itself. */
114 struct bfd_hash_table root
;
119 /* Where to place the next stub. */
122 /* Current offset in the stub section. */
127 /* Hash table for argument location information. */
129 struct elf32_hppa_args_hash_entry
131 /* Base hash table entry structure. */
132 struct bfd_hash_entry root
;
134 /* The argument location bits for this entry. */
138 struct elf32_hppa_args_hash_table
140 /* The hash table itself. */
141 struct bfd_hash_table root
;
144 struct elf32_hppa_link_hash_entry
146 struct elf_link_hash_entry root
;
149 struct elf32_hppa_link_hash_table
151 /* The main hash table. */
152 struct elf_link_hash_table root
;
154 /* The stub hash table. */
155 struct elf32_hppa_stub_hash_table
*stub_hash_table
;
157 /* The argument relocation bits hash table. */
158 struct elf32_hppa_args_hash_table
*args_hash_table
;
160 /* A count of the number of output symbols. */
161 unsigned int output_symbol_count
;
163 /* Stuff so we can handle DP relative relocations. */
165 int global_sym_defined
;
170 #define RETURN_VALUE 1
172 /* The various argument relocations that may be performed. */
177 /* Relocate 32 bits from GR to FP register. */
179 /* Relocate 64 bits from a GR pair to FP pair. */
181 /* Relocate 32 bits from FP to GR. */
183 /* Relocate 64 bits from FP pair to GR pair. */
187 /* What is being relocated (eg which argument or the return value). */
190 ARG0
, ARG1
, ARG2
, ARG3
, RET
,
191 } arg_reloc_location
;
194 /* ELF32/HPPA relocation support
196 This file contains ELF32/HPPA relocation support as specified
197 in the Stratus FTX/Golf Object File Format (SED-1762) dated
200 #include "elf32-hppa.h"
201 #include "hppa_stubs.h"
203 static bfd_reloc_status_type hppa_elf_reloc
204 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
206 static unsigned long hppa_elf_relocate_insn
207 PARAMS ((bfd
*, asection
*, unsigned long, unsigned long, long,
208 long, unsigned long, unsigned long, unsigned long));
210 static bfd_reloc_status_type hppa_elf_reloc
211 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
213 static reloc_howto_type
* elf_hppa_reloc_type_lookup
214 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
216 static boolean elf32_hppa_set_section_contents
217 PARAMS ((bfd
*, sec_ptr
, PTR
, file_ptr
, bfd_size_type
));
219 static void elf32_hppa_info_to_howto
220 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rela
*));
222 static boolean elf32_hppa_backend_symbol_table_processing
223 PARAMS ((bfd
*, elf_symbol_type
*, unsigned int));
225 static void elf32_hppa_backend_begin_write_processing
226 PARAMS ((bfd
*, struct bfd_link_info
*));
228 static void elf32_hppa_backend_final_write_processing
229 PARAMS ((bfd
*, boolean
));
231 static void add_entry_to_symext_chain
232 PARAMS ((bfd
*, unsigned int, unsigned int, symext_chainS
**,
236 elf_hppa_tc_make_sections
PARAMS ((bfd
*, symext_chainS
*));
238 static boolean hppa_elf_is_local_label_name
PARAMS ((bfd
*, const char *));
240 static boolean elf32_hppa_add_symbol_hook
241 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
242 const char **, flagword
*, asection
**, bfd_vma
*));
244 static bfd_reloc_status_type elf32_hppa_bfd_final_link_relocate
245 PARAMS ((reloc_howto_type
*, bfd
*, bfd
*, asection
*,
246 bfd_byte
*, bfd_vma
, bfd_vma
, bfd_vma
, struct bfd_link_info
*,
247 asection
*, const char *, int));
249 static struct bfd_link_hash_table
*elf32_hppa_link_hash_table_create
252 static struct bfd_hash_entry
*
253 elf32_hppa_stub_hash_newfunc
254 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
256 static struct bfd_hash_entry
*
257 elf32_hppa_args_hash_newfunc
258 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
261 elf32_hppa_relocate_section
262 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*,
263 bfd_byte
*, Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
266 elf32_hppa_stub_hash_table_init
267 PARAMS ((struct elf32_hppa_stub_hash_table
*, bfd
*,
268 struct bfd_hash_entry
*(*) PARAMS ((struct bfd_hash_entry
*,
269 struct bfd_hash_table
*,
273 elf32_hppa_build_one_stub
PARAMS ((struct bfd_hash_entry
*, PTR
));
276 elf32_hppa_read_symext_info
277 PARAMS ((bfd
*, Elf_Internal_Shdr
*, struct elf32_hppa_args_hash_table
*,
278 Elf_Internal_Sym
*));
280 static unsigned int elf32_hppa_size_of_stub
281 PARAMS ((unsigned int, unsigned int, bfd_vma
, bfd_vma
, const char *));
283 static boolean elf32_hppa_arg_reloc_needed
284 PARAMS ((unsigned int, unsigned int, arg_reloc_type
[]));
286 static void elf32_hppa_name_of_stub
287 PARAMS ((unsigned int, unsigned int, bfd_vma
, bfd_vma
, char *));
289 static boolean elf32_hppa_size_symext
PARAMS ((struct bfd_hash_entry
*, PTR
));
291 static boolean elf32_hppa_link_output_symbol_hook
292 PARAMS ((bfd
*, struct bfd_link_info
*, const char *,
293 Elf_Internal_Sym
*, asection
*));
295 /* ELF/PA relocation howto entries. */
297 static reloc_howto_type elf_hppa_howto_table
[ELF_HOWTO_TABLE_SIZE
] =
299 {R_PARISC_NONE
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_NONE"},
300 /* The values in DIR32 are to placate the check in
301 _bfd_stab_section_find_nearest_line. */
302 {R_PARISC_DIR32
, 0, 2, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DIR32", false, 0, 0xffffffff, false},
303 {R_PARISC_DIR21L
, 0, 0, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DIR21L"},
304 {R_PARISC_DIR17R
, 0, 0, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DIR17R"},
305 {R_PARISC_DIR17F
, 0, 0, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DIR17F"},
306 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
307 {R_PARISC_DIR14R
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DIR14R"},
308 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
310 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
311 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
312 {R_PARISC_PCREL21L
, 0, 0, 21, true, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PCREL21L"},
313 {R_PARISC_PCREL17R
, 0, 0, 17, true, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PCREL17R"},
314 {R_PARISC_PCREL17F
, 0, 0, 17, true, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PCREL17F"},
315 {R_PARISC_PCREL17C
, 0, 0, 17, true, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PCREL17C"},
316 {R_PARISC_PCREL14R
, 0, 0, 14, true, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PCREL14R"},
317 {R_PARISC_PCREL14F
, 0, 0, 14, true, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PCREL14F"},
319 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
320 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
321 {R_PARISC_DPREL21L
, 0, 0, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DPREL21L"},
322 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
323 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
324 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
325 {R_PARISC_DPREL14R
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DPREL14R"},
326 {R_PARISC_DPREL14F
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DPREL14F"},
328 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
329 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
330 {R_PARISC_DLTREL21L
, 0, 0, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DLTREL21L"},
331 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
332 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
333 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
334 {R_PARISC_DLTREL14R
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DLTREL14R"},
335 {R_PARISC_DLTREL14F
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DLTREL14F"},
337 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
338 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
339 {R_PARISC_DLTIND21L
, 0, 0, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DLTIND21L"},
340 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
341 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
342 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
343 {R_PARISC_DLTIND14R
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DLTIND14R"},
344 {R_PARISC_DLTIND14F
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DLTIND14F"},
346 {R_PARISC_SETBASE
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_SETBASE"},
347 {R_PARISC_BASEREL32
, 0, 0, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_BASEREL32"},
348 {R_PARISC_BASEREL21L
, 0, 0, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_BASEREL21L"},
349 {R_PARISC_BASEREL17R
, 0, 0, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_BASEREL17R"},
350 {R_PARISC_BASEREL17F
, 0, 0, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_BASEREL17F"},
351 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
352 {R_PARISC_BASEREL14R
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_BASEREL14R"},
353 {R_PARISC_BASEREL14F
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_BASEREL14F"},
355 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
356 {R_PARISC_TEXTREL32
, 0, 0, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_TEXTREL32"},
357 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
358 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
359 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
360 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
361 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
362 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
364 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
365 {R_PARISC_DATAREL32
, 0, 0, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
366 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
367 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
368 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
369 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
370 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
371 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
374 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
375 {R_PARISC_PLABEL32
, 0, 0, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PLABEL32"},
376 {R_PARISC_PLABEL21L
, 0, 0, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PLABEL21L"},
377 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
378 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
379 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
380 {R_PARISC_PLABEL14R
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PLABEL14R"},
381 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
383 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
384 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
385 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
386 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
387 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
388 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
389 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
390 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
392 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
393 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
394 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
395 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
396 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
397 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
398 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
399 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
400 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
401 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
402 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
403 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
404 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
405 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
406 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
407 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
409 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
410 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
411 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
412 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
413 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
414 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
415 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
416 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
417 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
418 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
419 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
420 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
421 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
422 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
423 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
424 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
426 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
427 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
428 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
429 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
430 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
431 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
432 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
433 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
434 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
435 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
436 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
437 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
438 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
439 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
440 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
441 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
444 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
445 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
446 {R_PARISC_PLTIND21L
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PLTIND21L"},
447 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
448 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
449 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
450 {R_PARISC_PLTIND14R
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PLTIND14R"},
451 {R_PARISC_PLTIND14F
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PLTIND14F"},
454 {R_PARISC_COPY
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_COPY"},
455 {R_PARISC_GLOB_DAT
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_GLOB_DAT"},
456 {R_PARISC_JMP_SLOT
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_JMP_SLOT"},
457 {R_PARISC_RELATIVE
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_RELATIVE"},
459 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_dont
, NULL
, "R_PARISC_UNIMPLEMENTED"},
462 /* Where (what register type) is an argument comming from? */
473 /* Horizontal represents the callee's argument location information,
474 vertical represents caller's argument location information. Value at a
475 particular X,Y location represents what (if any) argument relocation
476 needs to be performed to make caller and callee agree. */
478 static CONST arg_reloc_type arg_mismatches
[6][6] =
480 {NO
, NO
, NO
, NO
, NO
, NO
},
481 {NO
, NO
, GF
, NO
, GD
, NO
},
482 {NO
, FG
, NO
, NO
, NO
, NO
},
483 {NO
, NO
, NO
, NO
, NO
, NO
},
484 {NO
, DG
, NO
, NO
, NO
, NO
},
485 {NO
, DG
, NO
, NO
, NO
, NO
},
488 /* Likewise, but reversed for the return value. */
489 static CONST arg_reloc_type ret_mismatches
[6][6] =
491 {NO
, NO
, NO
, NO
, NO
, NO
},
492 {NO
, NO
, FG
, NO
, DG
, NO
},
493 {NO
, GF
, NO
, NO
, NO
, NO
},
494 {NO
, NO
, NO
, NO
, NO
, NO
},
495 {NO
, GD
, NO
, NO
, NO
, NO
},
496 {NO
, GD
, NO
, NO
, NO
, NO
},
499 /* Misc static crud for symbol extension records. */
500 static symext_chainS
*symext_rootP
;
501 static symext_chainS
*symext_lastP
;
502 static bfd_size_type symext_chain_size
;
504 /* FIXME: We should be able to try this static variable! */
505 static bfd_byte
*symextn_contents
;
508 /* For linker stub hash tables. */
509 #define elf32_hppa_stub_hash_lookup(table, string, create, copy) \
510 ((struct elf32_hppa_stub_hash_entry *) \
511 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
513 #define elf32_hppa_stub_hash_traverse(table, func, info) \
516 (boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) (func), \
519 /* For linker args hash tables. */
520 #define elf32_hppa_args_hash_lookup(table, string, create, copy) \
521 ((struct elf32_hppa_args_hash_entry *) \
522 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
524 #define elf32_hppa_args_hash_traverse(table, func, info) \
527 (boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) (func), \
530 #define elf32_hppa_args_hash_table_init(table, newfunc) \
531 (bfd_hash_table_init \
533 (struct bfd_hash_entry *(*) PARAMS ((struct bfd_hash_entry *, \
534 struct bfd_hash_table *, \
535 const char *))) (newfunc)))
537 /* For HPPA linker hash table. */
539 #define elf32_hppa_link_hash_lookup(table, string, create, copy, follow)\
540 ((struct elf32_hppa_link_hash_entry *) \
541 elf_link_hash_lookup (&(table)->root, (string), (create), \
544 #define elf32_hppa_link_hash_traverse(table, func, info) \
545 (elf_link_hash_traverse \
547 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
550 /* Get the PA ELF linker hash table from a link_info structure. */
552 #define elf32_hppa_hash_table(p) \
553 ((struct elf32_hppa_link_hash_table *) ((p)->hash))
556 /* Extract specific argument location bits for WHICH from
557 the full argument location in AR. */
558 #define EXTRACT_ARBITS(ar, which) ((ar) >> (8 - ((which) * 2))) & 3
560 /* Assorted hash table functions. */
562 /* Initialize an entry in the stub hash table. */
564 static struct bfd_hash_entry
*
565 elf32_hppa_stub_hash_newfunc (entry
, table
, string
)
566 struct bfd_hash_entry
*entry
;
567 struct bfd_hash_table
*table
;
570 struct elf32_hppa_stub_hash_entry
*ret
;
572 ret
= (struct elf32_hppa_stub_hash_entry
*) entry
;
574 /* Allocate the structure if it has not already been allocated by a
577 ret
= ((struct elf32_hppa_stub_hash_entry
*)
578 bfd_hash_allocate (table
,
579 sizeof (struct elf32_hppa_stub_hash_entry
)));
583 /* Call the allocation method of the superclass. */
584 ret
= ((struct elf32_hppa_stub_hash_entry
*)
585 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
589 /* Initialize the local fields. */
591 ret
->target_value
= 0;
592 ret
->target_section
= NULL
;
595 return (struct bfd_hash_entry
*) ret
;
598 /* Initialize a stub hash table. */
601 elf32_hppa_stub_hash_table_init (table
, stub_bfd
, newfunc
)
602 struct elf32_hppa_stub_hash_table
*table
;
604 struct bfd_hash_entry
*(*newfunc
) PARAMS ((struct bfd_hash_entry
*,
605 struct bfd_hash_table
*,
610 table
->stub_bfd
= stub_bfd
;
611 return (bfd_hash_table_init (&table
->root
, newfunc
));
614 /* Initialize an entry in the argument location hash table. */
616 static struct bfd_hash_entry
*
617 elf32_hppa_args_hash_newfunc (entry
, table
, string
)
618 struct bfd_hash_entry
*entry
;
619 struct bfd_hash_table
*table
;
622 struct elf32_hppa_args_hash_entry
*ret
;
624 ret
= (struct elf32_hppa_args_hash_entry
*) entry
;
626 /* Allocate the structure if it has not already been allocated by a
629 ret
= ((struct elf32_hppa_args_hash_entry
*)
630 bfd_hash_allocate (table
,
631 sizeof (struct elf32_hppa_args_hash_entry
)));
635 /* Call the allocation method of the superclass. */
636 ret
= ((struct elf32_hppa_args_hash_entry
*)
637 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
639 /* Initialize the local fields. */
643 return (struct bfd_hash_entry
*) ret
;
646 /* Create the derived linker hash table. The PA ELF port uses the derived
647 hash table to keep information specific to the PA ELF linker (without
648 using static variables). */
650 static struct bfd_link_hash_table
*
651 elf32_hppa_link_hash_table_create (abfd
)
654 struct elf32_hppa_link_hash_table
*ret
;
656 ret
= ((struct elf32_hppa_link_hash_table
*)
657 bfd_alloc (abfd
, sizeof (struct elf32_hppa_link_hash_table
)));
660 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
661 _bfd_elf_link_hash_newfunc
))
663 bfd_release (abfd
, ret
);
666 ret
->stub_hash_table
= NULL
;
667 ret
->args_hash_table
= NULL
;
668 ret
->output_symbol_count
= 0;
669 ret
->global_value
= 0;
670 ret
->global_sym_defined
= 0;
672 return &ret
->root
.root
;
675 /* Relocate the given INSN given the various input parameters.
677 FIXME: endianness and sizeof (long) issues abound here. */
680 hppa_elf_relocate_insn (abfd
, input_sect
, insn
, address
, sym_value
,
681 r_addend
, r_format
, r_field
, pcrel
)
683 asection
*input_sect
;
685 unsigned long address
;
688 unsigned long r_format
;
689 unsigned long r_field
;
692 unsigned char opcode
= get_opcode (insn
);
712 constant_value
= HPPA_R_CONSTANT (r_addend
);
715 sym_value
-= address
;
717 sym_value
= hppa_field_adjust (sym_value
, constant_value
, r_field
);
718 return hppa_rebuild_insn (abfd
, insn
, sym_value
, r_format
);
723 /* XXX computing constant_value is not needed??? */
724 constant_value
= assemble_17 ((insn
& 0x001f0000) >> 16,
725 (insn
& 0x00001ffc) >> 2,
728 constant_value
= (constant_value
<< 15) >> 15;
732 address
+ input_sect
->output_offset
733 + input_sect
->output_section
->vma
;
734 sym_value
= hppa_field_adjust (sym_value
, -8, r_field
);
737 sym_value
= hppa_field_adjust (sym_value
, constant_value
, r_field
);
739 return hppa_rebuild_insn (abfd
, insn
, sym_value
>> 2, r_format
);
744 constant_value
= HPPA_R_CONSTANT (r_addend
);
747 sym_value
-= address
;
749 return hppa_field_adjust (sym_value
, constant_value
, r_field
);
756 /* Relocate an HPPA ELF section. */
759 elf32_hppa_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
760 contents
, relocs
, local_syms
, local_sections
)
762 struct bfd_link_info
*info
;
764 asection
*input_section
;
766 Elf_Internal_Rela
*relocs
;
767 Elf_Internal_Sym
*local_syms
;
768 asection
**local_sections
;
770 Elf_Internal_Shdr
*symtab_hdr
;
771 Elf_Internal_Rela
*rel
;
772 Elf_Internal_Rela
*relend
;
774 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
777 relend
= relocs
+ input_section
->reloc_count
;
778 for (; rel
< relend
; rel
++)
781 reloc_howto_type
*howto
;
782 unsigned long r_symndx
;
783 struct elf_link_hash_entry
*h
;
784 Elf_Internal_Sym
*sym
;
787 bfd_reloc_status_type r
;
788 const char *sym_name
;
790 r_type
= ELF32_R_TYPE (rel
->r_info
);
791 if (r_type
< 0 || r_type
>= (int) R_PARISC_UNIMPLEMENTED
)
793 bfd_set_error (bfd_error_bad_value
);
796 howto
= elf_hppa_howto_table
+ r_type
;
798 r_symndx
= ELF32_R_SYM (rel
->r_info
);
800 if (info
->relocateable
)
802 /* This is a relocateable link. We don't have to change
803 anything, unless the reloc is against a section symbol,
804 in which case we have to adjust according to where the
805 section symbol winds up in the output section. */
806 if (r_symndx
< symtab_hdr
->sh_info
)
808 sym
= local_syms
+ r_symndx
;
809 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
811 sym_sec
= local_sections
[r_symndx
];
812 rel
->r_addend
+= sym_sec
->output_offset
;
819 /* This is a final link. */
823 if (r_symndx
< symtab_hdr
->sh_info
)
825 sym
= local_syms
+ r_symndx
;
826 sym_sec
= local_sections
[r_symndx
];
827 relocation
= ((ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
829 + sym_sec
->output_offset
830 + sym_sec
->output_section
->vma
);
836 indx
= r_symndx
- symtab_hdr
->sh_info
;
837 h
= elf_sym_hashes (input_bfd
)[indx
];
838 while (h
->root
.type
== bfd_link_hash_indirect
839 || h
->root
.type
== bfd_link_hash_warning
)
840 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
841 if (h
->root
.type
== bfd_link_hash_defined
842 || h
->root
.type
== bfd_link_hash_defweak
)
844 sym_sec
= h
->root
.u
.def
.section
;
845 relocation
= (h
->root
.u
.def
.value
846 + sym_sec
->output_offset
847 + sym_sec
->output_section
->vma
);
849 else if (h
->root
.type
== bfd_link_hash_undefweak
)
853 if (!((*info
->callbacks
->undefined_symbol
)
854 (info
, h
->root
.root
.string
, input_bfd
,
855 input_section
, rel
->r_offset
)))
862 sym_name
= h
->root
.root
.string
;
865 sym_name
= bfd_elf_string_from_elf_section (input_bfd
,
868 if (sym_name
== NULL
)
870 if (*sym_name
== '\0')
871 sym_name
= bfd_section_name (input_bfd
, sym_sec
);
874 /* If args_hash_table is NULL, then we have encountered some
875 kind of link error (ex. undefined symbols). Do not try to
876 apply any relocations, continue the loop so we can notify
877 the user of several errors in a single attempted link. */
878 if (elf32_hppa_hash_table (info
)->args_hash_table
== NULL
)
881 r
= elf32_hppa_bfd_final_link_relocate (howto
, input_bfd
, output_bfd
,
882 input_section
, contents
,
883 rel
->r_offset
, relocation
,
884 rel
->r_addend
, info
, sym_sec
,
885 sym_name
, h
== NULL
);
887 if (r
!= bfd_reloc_ok
)
891 /* This can happen for DP relative relocs if $global$ is
892 undefined. This is a panic situation so we don't try
894 case bfd_reloc_undefined
:
895 case bfd_reloc_notsupported
:
896 if (!((*info
->callbacks
->undefined_symbol
)
897 (info
, "$global$", input_bfd
,
898 input_section
, rel
->r_offset
)))
901 case bfd_reloc_dangerous
:
903 /* We use this return value to indicate that we performed
904 a "dangerous" relocation. This doesn't mean we did
905 the wrong thing, it just means there may be some cleanup
906 that needs to be done here.
908 In particular we had to swap the last call insn and its
909 delay slot. If the delay slot insn needed a relocation,
910 then we'll need to adjust the next relocation entry's
911 offset to account for the fact that the insn moved.
913 This hair wouldn't be necessary if we inserted stubs
914 between procedures and used a "bl" to get to the stub. */
917 Elf_Internal_Rela
*next_rel
= rel
+ 1;
919 if (rel
->r_offset
+ 4 == next_rel
->r_offset
)
920 next_rel
->r_offset
-= 4;
925 case bfd_reloc_outofrange
:
926 case bfd_reloc_overflow
:
928 if (!((*info
->callbacks
->reloc_overflow
)
929 (info
, sym_name
, howto
->name
, (bfd_vma
) 0,
930 input_bfd
, input_section
, rel
->r_offset
)))
941 /* Return one (or more) BFD relocations which implement the base
942 relocation with modifications based on format and field. */
944 elf32_hppa_reloc_type
**
945 hppa_elf_gen_reloc_type (abfd
, base_type
, format
, field
, ignore
, sym
)
947 elf32_hppa_reloc_type base_type
;
953 elf32_hppa_reloc_type
*finaltype
;
954 elf32_hppa_reloc_type
**final_types
;
956 /* Allocate slots for the BFD relocation. */
957 final_types
= ((elf32_hppa_reloc_type
**)
958 bfd_alloc (abfd
, sizeof (elf32_hppa_reloc_type
*) * 2));
959 if (final_types
== NULL
)
962 /* Allocate space for the relocation itself. */
963 finaltype
= ((elf32_hppa_reloc_type
*)
964 bfd_alloc (abfd
, sizeof (elf32_hppa_reloc_type
)));
965 if (finaltype
== NULL
)
968 /* Some reasonable defaults. */
969 final_types
[0] = finaltype
;
970 final_types
[1] = NULL
;
972 #define final_type finaltype[0]
974 final_type
= base_type
;
976 /* Just a tangle of nested switch statements to deal with the braindamage
977 that a different field selector means a completely different relocation
982 case R_HPPA_ABS_CALL
:
990 final_type
= R_PARISC_DIR14R
;
993 final_type
= R_PARISC_DLTREL14R
;
996 final_type
= R_PARISC_DLTREL14F
;
999 final_type
= R_PARISC_PLABEL14R
;
1010 final_type
= R_PARISC_DIR17F
;
1014 final_type
= R_PARISC_DIR17R
;
1026 final_type
= R_PARISC_DIR21L
;
1029 final_type
= R_PARISC_DLTREL21L
;
1032 final_type
= R_PARISC_PLABEL21L
;
1043 final_type
= R_PARISC_DIR32
;
1046 final_type
= R_PARISC_PLABEL32
;
1067 final_type
= R_PARISC_DPREL14R
;
1070 final_type
= R_PARISC_DPREL14F
;
1082 final_type
= R_PARISC_DPREL21L
;
1095 case R_HPPA_PCREL_CALL
:
1103 final_type
= R_PARISC_PCREL14R
;
1106 final_type
= R_PARISC_PCREL14F
;
1118 final_type
= R_PARISC_PCREL17R
;
1121 final_type
= R_PARISC_PCREL17F
;
1133 final_type
= R_PARISC_PCREL21L
;
1154 /* Set the contents of a particular section at a particular location. */
1157 elf32_hppa_set_section_contents (abfd
, section
, location
, offset
, count
)
1162 bfd_size_type count
;
1164 /* Ignore write requests for the symbol extension section until we've
1165 had the chance to rebuild it ourselves. */
1166 if (!strcmp (section
->name
, ".PARISC.symextn") && !symext_chain_size
)
1169 return _bfd_elf_set_section_contents (abfd
, section
, location
,
1173 /* Translate from an elf into field into a howto relocation pointer. */
1176 elf32_hppa_info_to_howto (abfd
, cache_ptr
, dst
)
1179 Elf32_Internal_Rela
*dst
;
1181 BFD_ASSERT (ELF32_R_TYPE(dst
->r_info
) < (unsigned int) R_PARISC_UNIMPLEMENTED
);
1182 cache_ptr
->howto
= &elf_hppa_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
1186 /* Actually perform a relocation. NOTE this is (mostly) superceeded
1187 by elf32_hppa_bfd_final_link_relocate which is called by the new
1190 static bfd_reloc_status_type
1191 hppa_elf_reloc (abfd
, reloc_entry
, symbol_in
, data
, input_section
, output_bfd
,
1194 arelent
*reloc_entry
;
1197 asection
*input_section
;
1199 char **error_message
;
1201 /* It is no longer valid to call hppa_elf_reloc when creating
1202 a final executable. */
1205 reloc_entry
->address
+= input_section
->output_offset
;
1207 /* Work around lossage in generic elf code to write relocations.
1208 (maps different section symbols into the same symbol index). */
1209 if ((symbol_in
->flags
& BSF_SECTION_SYM
)
1210 && symbol_in
->section
)
1211 reloc_entry
->addend
+= symbol_in
->section
->output_offset
;
1212 return bfd_reloc_ok
;
1216 *error_message
= (char *) "Unsupported call to hppa_elf_reloc";
1217 return bfd_reloc_notsupported
;
1221 /* Actually perform a relocation as part of a final link. This can get
1222 rather hairy when linker stubs are needed. */
1224 static bfd_reloc_status_type
1225 elf32_hppa_bfd_final_link_relocate (howto
, input_bfd
, output_bfd
,
1226 input_section
, contents
, offset
, value
,
1227 addend
, info
, sym_sec
, sym_name
, is_local
)
1228 reloc_howto_type
*howto
;
1231 asection
*input_section
;
1236 struct bfd_link_info
*info
;
1238 const char *sym_name
;
1242 unsigned long r_type
= howto
->type
;
1243 unsigned long r_format
= howto
->bitsize
;
1244 unsigned long r_field
= e_fsel
;
1245 bfd_byte
*hit_data
= contents
+ offset
;
1246 boolean r_pcrel
= howto
->pc_relative
;
1248 insn
= bfd_get_32 (input_bfd
, hit_data
);
1250 /* Make sure we have a value for $global$. FIXME isn't this effectively
1251 just like the gp pointer on MIPS? Can we use those routines for this
1253 if (!elf32_hppa_hash_table (info
)->global_sym_defined
)
1255 struct elf_link_hash_entry
*h
;
1258 h
= elf_link_hash_lookup (elf_hash_table (info
), "$global$", false,
1261 /* If there isn't a $global$, then we're in deep trouble. */
1263 return bfd_reloc_notsupported
;
1265 /* If $global$ isn't a defined symbol, then we're still in deep
1267 if (h
->root
.type
!= bfd_link_hash_defined
)
1268 return bfd_reloc_undefined
;
1270 sec
= h
->root
.u
.def
.section
;
1271 elf32_hppa_hash_table (info
)->global_value
= (h
->root
.u
.def
.value
1272 + sec
->output_section
->vma
1273 + sec
->output_offset
);
1274 elf32_hppa_hash_table (info
)->global_sym_defined
= 1;
1282 case R_PARISC_DIR32
:
1283 case R_PARISC_DIR17F
:
1284 case R_PARISC_PCREL17C
:
1286 goto do_basic_type_1
;
1287 case R_PARISC_DIR21L
:
1288 case R_PARISC_PCREL21L
:
1290 goto do_basic_type_1
;
1291 case R_PARISC_DIR17R
:
1292 case R_PARISC_PCREL17R
:
1293 case R_PARISC_DIR14R
:
1294 case R_PARISC_PCREL14R
:
1296 goto do_basic_type_1
;
1298 /* For all the DP relative relocations, we need to examine the symbol's
1299 section. If it's a code section, then "data pointer relative" makes
1300 no sense. In that case we don't adjust the "value", and for 21 bit
1301 addil instructions, we change the source addend register from %dp to
1303 case R_PARISC_DPREL21L
:
1305 if (sym_sec
->flags
& SEC_CODE
)
1307 if ((insn
& 0xfc000000) >> 26 == 0xa
1308 && (insn
& 0x03e00000) >> 21 == 0x1b)
1309 insn
&= ~0x03e00000;
1312 value
-= elf32_hppa_hash_table (info
)->global_value
;
1313 goto do_basic_type_1
;
1314 case R_PARISC_DPREL14R
:
1316 if ((sym_sec
->flags
& SEC_CODE
) == 0)
1317 value
-= elf32_hppa_hash_table (info
)->global_value
;
1318 goto do_basic_type_1
;
1319 case R_PARISC_DPREL14F
:
1321 if ((sym_sec
->flags
& SEC_CODE
) == 0)
1322 value
-= elf32_hppa_hash_table (info
)->global_value
;
1323 goto do_basic_type_1
;
1325 /* These cases are separate as they may involve a lot more work
1326 to deal with linker stubs. */
1327 case R_PARISC_PLABEL32
:
1328 case R_PARISC_PLABEL21L
:
1329 case R_PARISC_PLABEL14R
:
1330 case R_PARISC_PCREL17F
:
1333 unsigned int len
, caller_args
, callee_args
;
1334 arg_reloc_type arg_reloc_types
[5];
1335 struct elf32_hppa_args_hash_table
*args_hash_table
;
1336 struct elf32_hppa_args_hash_entry
*args_hash
;
1337 char *new_name
, *stub_name
;
1339 /* Get the field selector right. We'll need it in a minute. */
1340 if (r_type
== R_PARISC_PCREL17F
1341 || r_type
== R_PARISC_PLABEL32
)
1343 else if (r_type
== R_PARISC_PLABEL21L
)
1345 else if (r_type
== R_PARISC_PLABEL14R
)
1348 /* Find out where we are and where we're going. */
1349 location
= (offset
+
1350 input_section
->output_offset
+
1351 input_section
->output_section
->vma
);
1353 /* Now look for the argument relocation bits associated with the
1355 len
= strlen (sym_name
) + 1;
1358 new_name
= bfd_malloc (len
);
1360 return bfd_reloc_notsupported
;
1361 strcpy (new_name
, sym_name
);
1363 /* Local symbols have unique IDs. */
1365 sprintf (new_name
+ len
- 10, "_%08x", (int)sym_sec
);
1367 args_hash_table
= elf32_hppa_hash_table (info
)->args_hash_table
;
1369 args_hash
= elf32_hppa_args_hash_lookup (args_hash_table
,
1370 new_name
, false, false);
1371 if (args_hash
== NULL
)
1374 callee_args
= args_hash
->arg_bits
;
1376 /* If this is a CALL relocation, then get the caller's bits
1377 from the addend. Else use the magic 0x155 value for PLABELS.
1379 Also we don't care about the destination (value) for PLABELS. */
1380 if (r_type
== R_PARISC_PCREL17F
)
1381 caller_args
= HPPA_R_ARG_RELOC (addend
);
1384 caller_args
= 0x155;
1388 /* Any kind of linker stub needed? */
1389 if (((int)(value
- location
) > 0x3ffff)
1390 || ((int)(value
- location
) < (int)0xfffc0000)
1391 || elf32_hppa_arg_reloc_needed (caller_args
, callee_args
,
1394 struct elf32_hppa_stub_hash_table
*stub_hash_table
;
1395 struct elf32_hppa_stub_hash_entry
*stub_hash
;
1396 asection
*stub_section
;
1398 /* Build a name for the stub. */
1400 len
= strlen (new_name
);
1402 stub_name
= bfd_malloc (len
);
1404 return bfd_reloc_notsupported
;
1405 elf32_hppa_name_of_stub (caller_args
, callee_args
,
1406 location
, value
, stub_name
);
1407 strcat (stub_name
, new_name
);
1410 stub_hash_table
= elf32_hppa_hash_table (info
)->stub_hash_table
;
1413 = elf32_hppa_stub_hash_lookup (stub_hash_table
, stub_name
,
1416 /* We're done with that name. */
1419 /* The stub BFD only has one section. */
1420 stub_section
= stub_hash_table
->stub_bfd
->sections
;
1422 if (stub_hash
!= NULL
)
1425 if (r_type
== R_PARISC_PCREL17F
)
1427 unsigned long delay_insn
;
1428 unsigned int opcode
, rtn_reg
, ldo_target_reg
, ldo_src_reg
;
1430 /* We'll need to peek at the next insn. */
1431 delay_insn
= bfd_get_32 (input_bfd
, hit_data
+ 4);
1432 opcode
= get_opcode (delay_insn
);
1434 /* We also need to know the return register for this
1436 rtn_reg
= (insn
& 0x03e00000) >> 21;
1438 ldo_src_reg
= (delay_insn
& 0x03e00000) >> 21;
1439 ldo_target_reg
= (delay_insn
& 0x001f0000) >> 16;
1441 /* Munge up the value and other parameters for
1442 hppa_elf_relocate_insn. */
1444 value
= (stub_hash
->offset
1445 + stub_section
->output_offset
1446 + stub_section
->output_section
->vma
);
1453 /* We need to peek at the delay insn and determine if
1454 we'll need to swap the branch and its delay insn. */
1457 && ldo_target_reg
== rtn_reg
)
1458 || (delay_insn
== 0x08000240))
1460 /* No need to swap the branch and its delay slot, but
1461 we do need to make sure to jump past the return
1462 pointer update in the stub. */
1465 /* If the delay insn does a return pointer adjustment,
1466 then we have to make sure it stays valid. */
1468 && ldo_target_reg
== rtn_reg
)
1470 delay_insn
&= 0xfc00ffff;
1471 delay_insn
|= ((31 << 21) | (31 << 16));
1472 bfd_put_32 (input_bfd
, delay_insn
, hit_data
+ 4);
1474 /* Use a BLE to reach the stub. */
1479 /* Wonderful, we have to swap the call insn and its
1481 bfd_put_32 (input_bfd
, delay_insn
, hit_data
);
1482 /* Use a BLE,n to reach the stub. */
1483 insn
= (BLE_SR4_R0
| 0x2);
1484 bfd_put_32 (input_bfd
, insn
, hit_data
+ 4);
1485 insn
= hppa_elf_relocate_insn (input_bfd
,
1491 /* Update the instruction word. */
1492 bfd_put_32 (input_bfd
, insn
, hit_data
+ 4);
1493 return bfd_reloc_dangerous
;
1498 /* PLABEL stuff is easy. */
1500 value
= (stub_hash
->offset
1501 + stub_section
->output_offset
1502 + stub_section
->output_section
->vma
);
1503 /* We don't need the RP adjustment for PLABELs. */
1505 if (r_type
== R_PARISC_PLABEL32
)
1507 else if (r_type
== R_PARISC_PLABEL21L
)
1509 else if (r_type
== R_PARISC_PLABEL14R
)
1517 return bfd_reloc_notsupported
;
1519 goto do_basic_type_1
;
1523 insn
= hppa_elf_relocate_insn (input_bfd
, input_section
, insn
,
1524 offset
, value
, addend
, r_format
,
1528 /* Something we don't know how to handle. */
1530 return bfd_reloc_notsupported
;
1533 /* Update the instruction word. */
1534 bfd_put_32 (input_bfd
, insn
, hit_data
);
1535 return (bfd_reloc_ok
);
1538 /* Return the address of the howto table entry to perform the CODE
1539 relocation for an ARCH machine. */
1541 static reloc_howto_type
*
1542 elf_hppa_reloc_type_lookup (abfd
, code
)
1544 bfd_reloc_code_real_type code
;
1546 if ((int) code
< (int) R_PARISC_UNIMPLEMENTED
)
1548 BFD_ASSERT ((int) elf_hppa_howto_table
[(int) code
].type
== (int) code
);
1549 return &elf_hppa_howto_table
[(int) code
];
1554 /* Return true if SYM represents a local label symbol. */
1557 hppa_elf_is_local_label_name (abfd
, name
)
1561 return (name
[0] == 'L' && name
[1] == '$');
1564 /* Do any backend specific processing when beginning to write an object
1565 file. For PA ELF we need to determine the size of the symbol extension
1566 section *before* any other output processing happens. */
1569 elf32_hppa_backend_begin_write_processing (abfd
, info
)
1571 struct bfd_link_info
*info
;
1574 asection
*symextn_sec
;
1576 /* Size up the symbol extension section. */
1577 if ((abfd
->outsymbols
== NULL
1579 || symext_chain_size
!= 0)
1584 /* We were not called from the BFD ELF linker code, so we need
1585 to examine the output BFD's outsymbols.
1587 Note we can not build the symbol extensions now as the symbol
1588 map hasn't been set up. */
1589 for (i
= 0; i
< abfd
->symcount
; i
++)
1591 elf_symbol_type
*symbol
= (elf_symbol_type
*)abfd
->outsymbols
[i
];
1593 /* Only functions ever need an entry in the symbol extension
1595 if (!(symbol
->symbol
.flags
& BSF_FUNCTION
))
1598 /* And only if they specify the locations of their arguments. */
1599 if (symbol
->tc_data
.hppa_arg_reloc
== 0)
1602 /* Yup. This function symbol needs an entry. */
1603 symext_chain_size
+= 2 * ELF32_PARISC_SX_SIZE
;
1606 else if (info
->relocateable
== true)
1608 struct elf32_hppa_args_hash_table
*table
;
1609 table
= elf32_hppa_hash_table (info
)->args_hash_table
;
1611 /* Determine the size of the symbol extension section. */
1612 elf32_hppa_args_hash_traverse (table
,
1613 elf32_hppa_size_symext
,
1614 &symext_chain_size
);
1617 /* Now create the section and set its size. We'll fill in the
1619 symextn_sec
= bfd_get_section_by_name (abfd
, SYMEXTN_SECTION_NAME
);
1620 if (symextn_sec
== NULL
)
1621 symextn_sec
= bfd_make_section (abfd
, SYMEXTN_SECTION_NAME
);
1623 bfd_set_section_flags (abfd
, symextn_sec
,
1624 SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_DATA
);
1625 symextn_sec
->output_section
= symextn_sec
;
1626 symextn_sec
->output_offset
= 0;
1627 bfd_set_section_alignment (abfd
, symextn_sec
, 2);
1628 bfd_set_section_size (abfd
, symextn_sec
, symext_chain_size
);
1631 /* Called for each entry in the args location hash table. For each
1632 entry we bump the size pointer by 2 records (16 bytes). */
1635 elf32_hppa_size_symext (gen_entry
, in_args
)
1636 struct bfd_hash_entry
*gen_entry
;
1639 bfd_size_type
*sizep
= (bfd_size_type
*)in_args
;
1641 *sizep
+= 2 * ELF32_PARISC_SX_SIZE
;
1645 /* Backend routine called by the linker for each output symbol.
1647 For PA ELF we use this opportunity to add an appropriate entry
1648 to the symbol extension chain for function symbols. */
1651 elf32_hppa_link_output_symbol_hook (abfd
, info
, name
, sym
, section
)
1653 struct bfd_link_info
*info
;
1655 Elf_Internal_Sym
*sym
;
1659 unsigned int len
, index
;
1660 struct elf32_hppa_args_hash_table
*args_hash_table
;
1661 struct elf32_hppa_args_hash_entry
*args_hash
;
1663 /* If the args hash table is NULL, then we've encountered an error
1664 of some sorts (for example, an undefined symbol). In that case
1665 we've got nothing else to do.
1667 NOTE: elf_link_output_symbol will abort if we return false here! */
1668 if (elf32_hppa_hash_table (info
)->args_hash_table
== NULL
)
1671 index
= elf32_hppa_hash_table (info
)->output_symbol_count
++;
1673 /* We need to look up this symbol in the args hash table to see if
1674 it has argument relocation bits. */
1675 if (ELF_ST_TYPE (sym
->st_info
) != STT_FUNC
)
1678 /* We know it's a function symbol of some kind. */
1679 len
= strlen (name
) + 1;
1680 if (ELF_ST_BIND (sym
->st_info
) == STB_LOCAL
)
1683 new_name
= bfd_malloc (len
);
1684 if (new_name
== NULL
)
1687 strcpy (new_name
, name
);
1688 if (ELF_ST_BIND (sym
->st_info
) == STB_LOCAL
)
1689 sprintf (new_name
+ len
- 10, "_%08x", (int)section
);
1691 /* Now that we have the unique name, we can look it up in the
1693 args_hash_table
= elf32_hppa_hash_table (info
)->args_hash_table
;
1694 args_hash
= elf32_hppa_args_hash_lookup (args_hash_table
, new_name
,
1697 if (args_hash
== NULL
)
1700 /* We know this symbol has arg reloc bits. */
1701 add_entry_to_symext_chain (abfd
, args_hash
->arg_bits
,
1702 index
, &symext_rootP
, &symext_lastP
);
1706 /* Perform any processing needed late in the object file writing process.
1707 For PA ELF we build and set the contents of the symbol extension
1711 elf32_hppa_backend_final_write_processing (abfd
, linker
)
1715 asection
*symextn_sec
;
1718 /* Now build the symbol extension section. */
1719 if (symext_chain_size
== 0)
1724 /* We were not called from the backend linker, so we still need
1725 to build the symbol extension chain.
1727 Look at each symbol, adding the appropriate information to the
1728 symbol extension section list as necessary. */
1729 for (i
= 0; i
< abfd
->symcount
; i
++)
1731 elf_symbol_type
*symbol
= (elf_symbol_type
*) abfd
->outsymbols
[i
];
1733 /* Only functions ever need an entry in the symbol extension
1735 if (!(symbol
->symbol
.flags
& BSF_FUNCTION
))
1738 /* And only if they specify the locations of their arguments. */
1739 if (symbol
->tc_data
.hppa_arg_reloc
== 0)
1742 /* Add this symbol's information to the chain. */
1743 add_entry_to_symext_chain (abfd
, symbol
->tc_data
.hppa_arg_reloc
,
1744 symbol
->symbol
.udata
.i
, &symext_rootP
,
1749 /* Now fill in the contents of the symbol extension section. */
1750 elf_hppa_tc_make_sections (abfd
, symext_rootP
);
1752 /* And attach that as the section's contents. */
1753 symextn_sec
= bfd_get_section_by_name (abfd
, SYMEXTN_SECTION_NAME
);
1754 if (symextn_sec
== (asection
*) 0)
1757 symextn_sec
->contents
= (void *)symextn_contents
;
1759 bfd_set_section_contents (abfd
, symextn_sec
, symextn_sec
->contents
,
1760 symextn_sec
->output_offset
, symextn_sec
->_raw_size
);
1763 /* Update the symbol extention chain to include the symbol pointed to
1764 by SYMBOLP if SYMBOLP is a function symbol. Used internally and by GAS. */
1767 add_entry_to_symext_chain (abfd
, arg_reloc
, sym_idx
, symext_root
, symext_last
)
1769 unsigned int arg_reloc
;
1770 unsigned int sym_idx
;
1771 symext_chainS
**symext_root
;
1772 symext_chainS
**symext_last
;
1774 symext_chainS
*symextP
;
1776 /* Allocate memory and initialize this entry. */
1777 symextP
= (symext_chainS
*) bfd_alloc (abfd
, sizeof (symext_chainS
) * 2);
1779 abort(); /* FIXME */
1781 symextP
[0].entry
= ELF32_PARISC_SX_WORD (PARISC_SXT_SYMNDX
, sym_idx
);
1782 symextP
[0].next
= &symextP
[1];
1784 symextP
[1].entry
= ELF32_PARISC_SX_WORD (PARISC_SXT_ARG_RELOC
, arg_reloc
);
1785 symextP
[1].next
= NULL
;
1787 /* Now update the chain itself so it can be walked later to build
1788 the symbol extension section. */
1789 if (*symext_root
== NULL
)
1791 *symext_root
= &symextP
[0];
1792 *symext_last
= &symextP
[1];
1796 (*symext_last
)->next
= &symextP
[0];
1797 *symext_last
= &symextP
[1];
1801 /* Build the symbol extension section. */
1804 elf_hppa_tc_make_sections (abfd
, symext_root
)
1806 symext_chainS
*symext_root
;
1808 symext_chainS
*symextP
;
1810 asection
*symextn_sec
;
1812 symextn_sec
= bfd_get_section_by_name (abfd
, SYMEXTN_SECTION_NAME
);
1814 /* Grab some memory for the contents of the symbol extension section
1816 symextn_contents
= (bfd_byte
*) bfd_zalloc (abfd
,
1817 symextn_sec
->_raw_size
);
1818 if (!symextn_contents
)
1819 abort(); /* FIXME */
1821 /* Fill in the contents of the symbol extension chain. */
1822 for (i
= 0, symextP
= symext_root
; symextP
; symextP
= symextP
->next
, ++i
)
1823 ELF32_PARISC_SX_PUT (abfd
, (bfd_vma
) symextP
->entry
,
1824 symextn_contents
+ i
* ELF32_PARISC_SX_SIZE
);
1829 /* Do some PA ELF specific work after reading in the symbol table.
1830 In particular attach the argument relocation from the
1831 symbol extension section to the appropriate symbols. */
1834 elf32_hppa_backend_symbol_table_processing (abfd
, esyms
,symcnt
)
1836 elf_symbol_type
*esyms
;
1837 unsigned int symcnt
;
1839 Elf32_Internal_Shdr
*symextn_hdr
=
1840 bfd_elf_find_section (abfd
, SYMEXTN_SECTION_NAME
);
1841 unsigned int i
, current_sym_idx
= 0;
1843 /* If no symbol extension existed, then all symbol extension information
1844 is assumed to be zero. */
1845 if (symextn_hdr
== NULL
)
1847 for (i
= 0; i
< symcnt
; i
++)
1848 esyms
[i
].tc_data
.hppa_arg_reloc
= 0;
1852 /* FIXME: Why not use bfd_get_section_contents here? Also should give
1853 memory back when we're done. */
1854 /* Allocate a buffer of the appropriate size for the symextn section. */
1855 symextn_hdr
->contents
= bfd_zalloc(abfd
,symextn_hdr
->sh_size
);
1856 if (!symextn_hdr
->contents
)
1859 /* Read in the symextn section. */
1860 if (bfd_seek (abfd
, symextn_hdr
->sh_offset
, SEEK_SET
) == -1)
1862 if (bfd_read ((PTR
) symextn_hdr
->contents
, 1, symextn_hdr
->sh_size
, abfd
)
1863 != symextn_hdr
->sh_size
)
1866 /* Parse entries in the symbol extension section, updating the symtab
1868 for (i
= 0; i
< symextn_hdr
->sh_size
/ ELF32_PARISC_SX_SIZE
; i
++)
1871 ELF32_PARISC_SX_GET (abfd
,
1872 ((unsigned char *)symextn_hdr
->contents
1873 + i
* ELF32_PARISC_SX_SIZE
));
1874 unsigned int se_value
= ELF32_PARISC_SX_VAL (se
);
1875 unsigned int se_type
= ELF32_PARISC_SX_TYPE (se
);
1879 case PARISC_SXT_NULL
:
1882 case PARISC_SXT_SYMNDX
:
1883 if (se_value
>= symcnt
)
1885 bfd_set_error (bfd_error_bad_value
);
1888 current_sym_idx
= se_value
- 1;
1891 case PARISC_SXT_ARG_RELOC
:
1892 esyms
[current_sym_idx
].tc_data
.hppa_arg_reloc
= se_value
;
1896 bfd_set_error (bfd_error_bad_value
);
1903 /* Read and attach the symbol extension information for the symbols
1904 in INPUT_BFD to the argument location hash table. Handle locals
1905 if DO_LOCALS is true; likewise for globals when DO_GLOBALS is true. */
1908 elf32_hppa_read_symext_info (input_bfd
, symtab_hdr
, args_hash_table
, local_syms
)
1910 Elf_Internal_Shdr
*symtab_hdr
;
1911 struct elf32_hppa_args_hash_table
*args_hash_table
;
1912 Elf_Internal_Sym
*local_syms
;
1914 asection
*symextn_sec
;
1916 unsigned int i
, n_entries
, current_index
= 0;
1918 /* Get the symbol extension section for this BFD. If no section exists
1919 then there's nothing to do. Likewise if the section exists, but
1921 symextn_sec
= bfd_get_section_by_name (input_bfd
, SYMEXTN_SECTION_NAME
);
1922 if (symextn_sec
== NULL
)
1925 /* Done separately so we can turn off SEC_HAS_CONTENTS (see below). */
1926 if (symextn_sec
->_raw_size
== 0)
1928 symextn_sec
->flags
&= ~SEC_HAS_CONTENTS
;
1932 contents
= (bfd_byte
*) bfd_malloc ((size_t) symextn_sec
->_raw_size
);
1933 if (contents
== NULL
)
1936 /* How gross. We turn off SEC_HAS_CONTENTS for the input symbol extension
1937 sections to keep the generic ELF/BFD code from trying to do anything
1938 with them. We have to undo that hack temporarily so that we can read
1939 in the contents with the generic code. */
1940 symextn_sec
->flags
|= SEC_HAS_CONTENTS
;
1941 if (bfd_get_section_contents (input_bfd
, symextn_sec
, contents
,
1942 0, symextn_sec
->_raw_size
) == false)
1944 symextn_sec
->flags
&= ~SEC_HAS_CONTENTS
;
1949 /* Gross. Turn off SEC_HAS_CONTENTS for the input symbol extension
1950 sections (see above). */
1951 symextn_sec
->flags
&= ~SEC_HAS_CONTENTS
;
1953 n_entries
= symextn_sec
->_raw_size
/ ELF32_PARISC_SX_SIZE
;
1954 for (i
= 0; i
< n_entries
; i
++)
1956 symext_entryS entry
=
1957 ELF32_PARISC_SX_GET (input_bfd
, contents
+ i
* ELF32_PARISC_SX_SIZE
);
1958 unsigned int value
= ELF32_PARISC_SX_VAL (entry
);
1959 unsigned int type
= ELF32_PARISC_SX_TYPE (entry
);
1960 struct elf32_hppa_args_hash_entry
*args_hash
;
1964 case PARISC_SXT_NULL
:
1967 case PARISC_SXT_SYMNDX
:
1968 if (value
>= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
))
1970 bfd_set_error (bfd_error_bad_value
);
1974 current_index
= value
;
1977 case PARISC_SXT_ARG_RELOC
:
1978 if (current_index
< symtab_hdr
->sh_info
)
1980 Elf_Internal_Shdr
*hdr
;
1982 const char *sym_name
;
1986 hdr
= elf_elfsections (input_bfd
)[local_syms
[current_index
].st_shndx
];
1987 sym_sec
= hdr
->bfd_section
;
1988 sym_name
= bfd_elf_string_from_elf_section (input_bfd
,
1989 symtab_hdr
->sh_link
,
1990 local_syms
[current_index
].st_name
);
1991 len
= strlen (sym_name
) + 10;
1992 new_name
= bfd_malloc (len
);
1993 if (new_name
== NULL
)
1998 strcpy (new_name
, sym_name
);
1999 sprintf (new_name
+ len
- 10, "_%08x", (int)sym_sec
);
2001 /* This is a global symbol with argument location info.
2002 We need to enter it into the hash table. */
2003 args_hash
= elf32_hppa_args_hash_lookup (args_hash_table
,
2007 if (args_hash
== NULL
)
2012 args_hash
->arg_bits
= value
;
2015 else if (current_index
>= symtab_hdr
->sh_info
)
2017 struct elf_link_hash_entry
*h
;
2019 current_index
-= symtab_hdr
->sh_info
;
2020 h
= elf_sym_hashes(input_bfd
)[current_index
];
2021 /* This is a global symbol with argument location
2022 information. We need to enter it into the hash table. */
2023 args_hash
= elf32_hppa_args_hash_lookup (args_hash_table
,
2024 h
->root
.root
.string
,
2026 if (args_hash
== NULL
)
2028 bfd_set_error (bfd_error_bad_value
);
2032 args_hash
->arg_bits
= value
;
2039 bfd_set_error (bfd_error_bad_value
);
2048 /* Undo the generic ELF code's subtraction of section->vma from the
2049 value of each external symbol. */
2052 elf32_hppa_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
2054 struct bfd_link_info
*info
;
2055 const Elf_Internal_Sym
*sym
;
2061 *valp
+= (*secp
)->vma
;
2065 /* Determine the name of the stub needed to perform a call assuming the
2066 argument relocation bits for caller and callee are in CALLER and CALLEE
2067 for a call from LOCATION to DESTINATION. Copy the name into STUB_NAME. */
2070 elf32_hppa_name_of_stub (caller
, callee
, location
, destination
, stub_name
)
2071 unsigned int caller
, callee
;
2072 bfd_vma location
, destination
;
2075 arg_reloc_type arg_reloc_types
[5];
2077 if (elf32_hppa_arg_reloc_needed (caller
, callee
, arg_reloc_types
))
2079 arg_reloc_location i
;
2080 /* Fill in the basic template. */
2081 strcpy (stub_name
, "__XX_XX_XX_XX_XX_stub_");
2083 /* Now fix the specifics. */
2084 for (i
= ARG0
; i
<= RET
; i
++)
2085 switch (arg_reloc_types
[i
])
2088 stub_name
[3 * i
+ 2] = 'N';
2089 stub_name
[3 * i
+ 3] = 'O';
2092 stub_name
[3 * i
+ 2] = 'G';
2093 stub_name
[3 * i
+ 3] = 'F';
2096 stub_name
[3 * i
+ 2] = 'F';
2097 stub_name
[3 * i
+ 3] = 'G';
2100 stub_name
[3 * i
+ 2] = 'G';
2101 stub_name
[3 * i
+ 3] = 'D';
2104 stub_name
[3 * i
+ 2] = 'D';
2105 stub_name
[3 * i
+ 3] = 'G';
2110 strcpy (stub_name
, "_____long_branch_stub_");
2113 /* Determine if an argument relocation stub is needed to perform a
2114 call assuming the argument relocation bits for caller and callee
2115 are in CALLER and CALLEE. Place the type of relocations (if any)
2116 into stub_types_p. */
2119 elf32_hppa_arg_reloc_needed (caller
, callee
, stub_types
)
2120 unsigned int caller
, callee
;
2121 arg_reloc_type stub_types
[5];
2123 /* Special case for no relocations. */
2124 if (caller
== 0 || callee
== 0)
2128 arg_location caller_loc
[5];
2129 arg_location callee_loc
[5];
2131 /* Extract the location information for the argument and return
2132 value on both the caller and callee sides. */
2133 caller_loc
[ARG0
] = EXTRACT_ARBITS (caller
, ARG0
);
2134 callee_loc
[ARG0
] = EXTRACT_ARBITS (callee
, ARG0
);
2135 caller_loc
[ARG1
] = EXTRACT_ARBITS (caller
, ARG1
);
2136 callee_loc
[ARG1
] = EXTRACT_ARBITS (callee
, ARG1
);
2137 caller_loc
[ARG2
] = EXTRACT_ARBITS (caller
, ARG2
);
2138 callee_loc
[ARG2
] = EXTRACT_ARBITS (callee
, ARG2
);
2139 caller_loc
[ARG3
] = EXTRACT_ARBITS (caller
, ARG3
);
2140 callee_loc
[ARG3
] = EXTRACT_ARBITS (callee
, ARG3
);
2141 caller_loc
[RET
] = EXTRACT_ARBITS (caller
, RET
);
2142 callee_loc
[RET
] = EXTRACT_ARBITS (callee
, RET
);
2144 /* Check some special combinations. This is necessary to
2145 deal with double precision FP arguments. */
2146 if (caller_loc
[ARG0
] == AR_FU
|| caller_loc
[ARG1
] == AR_FU
)
2148 caller_loc
[ARG0
] = AR_FPDBL1
;
2149 caller_loc
[ARG1
] = AR_NO
;
2151 if (caller_loc
[ARG2
] == AR_FU
|| caller_loc
[ARG3
] == AR_FU
)
2153 caller_loc
[ARG2
] = AR_FPDBL2
;
2154 caller_loc
[ARG3
] = AR_NO
;
2156 if (callee_loc
[ARG0
] == AR_FU
|| callee_loc
[ARG1
] == AR_FU
)
2158 callee_loc
[ARG0
] = AR_FPDBL1
;
2159 callee_loc
[ARG1
] = AR_NO
;
2161 if (callee_loc
[ARG2
] == AR_FU
|| callee_loc
[ARG3
] == AR_FU
)
2163 callee_loc
[ARG2
] = AR_FPDBL2
;
2164 callee_loc
[ARG3
] = AR_NO
;
2167 /* Now look up any relocation needed for each argument and the
2169 stub_types
[ARG0
] = arg_mismatches
[caller_loc
[ARG0
]][callee_loc
[ARG0
]];
2170 stub_types
[ARG1
] = arg_mismatches
[caller_loc
[ARG1
]][callee_loc
[ARG1
]];
2171 stub_types
[ARG2
] = arg_mismatches
[caller_loc
[ARG2
]][callee_loc
[ARG2
]];
2172 stub_types
[ARG3
] = arg_mismatches
[caller_loc
[ARG3
]][callee_loc
[ARG3
]];
2173 stub_types
[RET
] = ret_mismatches
[caller_loc
[RET
]][callee_loc
[RET
]];
2175 return (stub_types
[ARG0
] != NO
2176 || stub_types
[ARG1
] != NO
2177 || stub_types
[ARG2
] != NO
2178 || stub_types
[ARG3
] != NO
2179 || stub_types
[RET
] != NO
);
2183 /* Compute the size of the stub needed to call from LOCATION to DESTINATION
2184 (a function named SYM_NAME), with argument relocation bits CALLER and
2185 CALLEE. Return zero if no stub is needed to perform such a call. */
2188 elf32_hppa_size_of_stub (callee
, caller
, location
, destination
, sym_name
)
2189 unsigned int callee
, caller
;
2190 bfd_vma location
, destination
;
2191 const char *sym_name
;
2193 arg_reloc_type arg_reloc_types
[5];
2195 /* Determine if a long branch or argument relocation stub is needed.
2196 If an argument relocation stub is needed, the relocation will be
2197 stored into arg_reloc_types. */
2198 if (!(((int)(location
- destination
) > 0x3ffff)
2199 || ((int)(location
- destination
) < (int)0xfffc0000)
2200 || elf32_hppa_arg_reloc_needed (caller
, callee
, arg_reloc_types
)))
2203 /* Some kind of stub is needed. Determine how big it needs to be.
2204 First check for argument relocation stubs as they also handle
2205 long calls. Then check for long calls to millicode and finally
2206 the normal long calls. */
2207 if (arg_reloc_types
[ARG0
] != NO
2208 || arg_reloc_types
[ARG1
] != NO
2209 || arg_reloc_types
[ARG2
] != NO
2210 || arg_reloc_types
[ARG3
] != NO
2211 || arg_reloc_types
[RET
] != NO
)
2213 /* Some kind of argument relocation stub is needed. */
2214 unsigned int len
= 16;
2215 arg_reloc_location i
;
2217 /* Each GR or FG relocation takes 2 insns, each GD or DG
2218 relocation takes 3 insns. Plus 4 more insns for the
2219 RP adjustment, ldil & (be | ble) and copy. */
2220 for (i
= ARG0
; i
<= RET
; i
++)
2221 switch (arg_reloc_types
[i
])
2237 /* Extra instructions are needed if we're relocating a return value. */
2238 if (arg_reloc_types
[RET
] != NO
)
2243 else if (!strncmp ("$$", sym_name
, 2)
2244 && strcmp ("$$dyncall", sym_name
))
2250 /* Build one linker stub as defined by the stub hash table entry GEN_ENTRY.
2251 IN_ARGS contains the stub BFD and link info pointers. */
2254 elf32_hppa_build_one_stub (gen_entry
, in_args
)
2255 struct bfd_hash_entry
*gen_entry
;
2258 void **args
= (void **)in_args
;
2259 bfd
*stub_bfd
= (bfd
*)args
[0];
2260 struct bfd_link_info
*info
= (struct bfd_link_info
*)args
[1];
2261 struct elf32_hppa_stub_hash_entry
*entry
;
2262 struct elf32_hppa_stub_hash_table
*stub_hash_table
;
2265 const char *sym_name
;
2267 /* Initialize pointers to the stub hash table, the particular entry we
2268 are building a stub for, and where (in memory) we should place the stub
2270 entry
= (struct elf32_hppa_stub_hash_entry
*)gen_entry
;
2271 stub_hash_table
= elf32_hppa_hash_table(info
)->stub_hash_table
;
2272 loc
= stub_hash_table
->location
;
2274 /* Make a note of the offset within the stubs for this entry. */
2275 entry
->offset
= stub_hash_table
->offset
;
2277 /* The symbol's name starts at offset 22. */
2278 sym_name
= entry
->root
.string
+ 22;
2280 sym_value
= (entry
->target_value
2281 + entry
->target_section
->output_offset
2282 + entry
->target_section
->output_section
->vma
);
2284 if (strncmp ("_____long_branch_stub_", entry
->root
.string
, 22))
2286 /* This must be an argument or return value relocation stub. */
2288 arg_reloc_location i
;
2289 bfd_byte
*begin_loc
= loc
;
2291 /* First the return pointer adjustment. Depending on exact calling
2292 sequence this instruction may be skipped. */
2293 bfd_put_32 (stub_bfd
, LDO_M4_R31_R31
, loc
);
2296 /* If we are relocating a return value, then we're going to have
2297 to return into the stub. So we have to save off the user's
2298 return pointer into the stack at RP'. */
2299 if (strncmp (entry
->root
.string
+ 14, "NO", 2))
2301 bfd_put_32 (stub_bfd
, STW_R31_M8R30
, loc
);
2305 /* Iterate over the argument relocations, emitting instructions
2306 to move them around as necessary. */
2307 for (i
= ARG0
; i
<= ARG3
; i
++)
2309 if (!strncmp (entry
->root
.string
+ 3 * i
+ 2, "GF", 2))
2311 bfd_put_32 (stub_bfd
, STW_ARG_M16R30
| ((26 - i
) << 16), loc
);
2312 bfd_put_32 (stub_bfd
, FLDW_M16R30_FARG
| (4 + i
), loc
+ 4);
2315 else if (!strncmp (entry
->root
.string
+ 3 * i
+ 2, "FG", 2))
2317 bfd_put_32 (stub_bfd
, FSTW_FARG_M16R30
| (4 + i
), loc
);
2318 bfd_put_32 (stub_bfd
, LDW_M16R30_ARG
| ((26 - i
) << 16), loc
+ 4);
2321 else if (!strncmp (entry
->root
.string
+ 3 * i
+ 2, "GD", 2))
2323 bfd_put_32 (stub_bfd
, STW_ARG_M12R30
| ((26 - i
) << 16), loc
);
2324 bfd_put_32 (stub_bfd
, STW_ARG_M16R30
| ((25 - i
) << 16), loc
+ 4);
2325 bfd_put_32 (stub_bfd
, FLDD_M16R30_FARG
| (5 + i
), loc
+ 8);
2328 else if (!strncmp (entry
->root
.string
+ 3 * i
+ 2, "DG", 2))
2330 bfd_put_32 (stub_bfd
, FSTD_FARG_M16R30
| (5 + i
), loc
);
2331 bfd_put_32 (stub_bfd
, LDW_M12R30_ARG
| ((26 - i
) << 16), loc
+ 4);
2332 bfd_put_32 (stub_bfd
, LDW_M16R30_ARG
| ((25 - i
) << 16), loc
+ 8);
2337 /* Load the high bits of the target address into %r1. */
2338 insn
= hppa_rebuild_insn (stub_bfd
, LDIL_R1
,
2339 hppa_field_adjust (sym_value
, 0, e_lrsel
), 21);
2340 bfd_put_32 (stub_bfd
, insn
, loc
);
2343 /* If we are relocating a return value, then we're going to have
2344 to return into the stub, then perform the return value relocation. */
2345 if (strncmp (entry
->root
.string
+ 14, "NO", 2))
2347 /* To return to the stub we "ble" to the target and copy the return
2348 pointer from %r31 into %r2. */
2349 insn
= hppa_rebuild_insn (stub_bfd
,
2351 hppa_field_adjust (sym_value
, 0,
2354 bfd_put_32 (stub_bfd
, insn
, loc
);
2355 bfd_put_32 (stub_bfd
, COPY_R31_R2
, loc
+ 4);
2357 /* Reload the return pointer for our caller from the stack. */
2358 bfd_put_32 (stub_bfd
, LDW_M8R30_R31
, loc
+ 8);
2361 /* Perform the return value relocation. */
2362 if (!strncmp (entry
->root
.string
+ 14, "GF", 2))
2364 bfd_put_32 (stub_bfd
, STW_ARG_M16R30
| (28 << 16), loc
);
2365 bfd_put_32 (stub_bfd
, FLDW_M16R30_FARG
| 4, loc
+ 4);
2368 else if (!strncmp (entry
->root
.string
+ 14, "FG", 2))
2370 bfd_put_32 (stub_bfd
, FSTW_FARG_M16R30
| 4, loc
);
2371 bfd_put_32 (stub_bfd
, LDW_M16R30_ARG
| (28 << 16), loc
+ 4);
2374 else if (!strncmp (entry
->root
.string
+ 2, "GD", 2))
2376 bfd_put_32 (stub_bfd
, STW_ARG_M12R30
| (28 << 16), loc
);
2377 bfd_put_32 (stub_bfd
, STW_ARG_M16R30
| (29 << 16), loc
+ 4);
2378 bfd_put_32 (stub_bfd
, FLDD_M16R30_FARG
| 4, loc
+ 8);
2381 else if (!strncmp (entry
->root
.string
+ 2, "DG", 2))
2383 bfd_put_32 (stub_bfd
, FSTD_FARG_M16R30
| 4, loc
);
2384 bfd_put_32 (stub_bfd
, LDW_M12R30_ARG
| (28 << 16), loc
+ 4);
2385 bfd_put_32 (stub_bfd
, LDW_M16R30_ARG
| (29 << 16), loc
+ 8);
2388 /* Branch back to the user's code now. */
2389 bfd_put_32 (stub_bfd
, BV_N_0_R31
, loc
);
2394 /* No return value relocation, so we can simply "be" to the
2395 target and copy out return pointer into %r2. */
2396 insn
= hppa_rebuild_insn (stub_bfd
, BE_SR4_R1
,
2397 hppa_field_adjust (sym_value
, 0,
2399 bfd_put_32 (stub_bfd
, insn
, loc
);
2400 bfd_put_32 (stub_bfd
, COPY_R31_R2
, loc
+ 4);
2404 /* Update the location and offsets. */
2405 stub_hash_table
->location
+= (loc
- begin_loc
);
2406 stub_hash_table
->offset
+= (loc
- begin_loc
);
2410 /* Create one of two variant long branch stubs. One for $$dyncall and
2411 normal calls, the other for calls to millicode. */
2413 int millicode_call
= 0;
2415 if (!strncmp ("$$", sym_name
, 2) && strcmp ("$$dyncall", sym_name
))
2418 /* First the return pointer adjustment. Depending on exact calling
2419 sequence this instruction may be skipped. */
2420 bfd_put_32 (stub_bfd
, LDO_M4_R31_R31
, loc
);
2422 /* The next two instructions are the long branch itself. A long branch
2423 is formed with "ldil" loading the upper bits of the target address
2424 into a register, then branching with "be" which adds in the lower bits.
2425 Long branches to millicode nullify the delay slot of the "be". */
2426 insn
= hppa_rebuild_insn (stub_bfd
, LDIL_R1
,
2427 hppa_field_adjust (sym_value
, 0, e_lrsel
), 21);
2428 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
2429 insn
= hppa_rebuild_insn (stub_bfd
, BE_SR4_R1
| (millicode_call
? 2 : 0),
2430 hppa_field_adjust (sym_value
, 0, e_rrsel
) >> 2,
2432 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
2434 if (!millicode_call
)
2436 /* The sequence to call this stub places the return pointer into %r31,
2437 the final target expects the return pointer in %r2, so copy the
2438 return pointer into the proper register. */
2439 bfd_put_32 (stub_bfd
, COPY_R31_R2
, loc
+ 12);
2441 /* Update the location and offsets. */
2442 stub_hash_table
->location
+= 16;
2443 stub_hash_table
->offset
+= 16;
2447 /* Update the location and offsets. */
2448 stub_hash_table
->location
+= 12;
2449 stub_hash_table
->offset
+= 12;
2456 /* External entry points for sizing and building linker stubs. */
2458 /* Build all the stubs associated with the current output file. The
2459 stubs are kept in a hash table attached to the main linker hash
2460 table. This is called via hppaelf_finish in the linker. */
2463 elf32_hppa_build_stubs (stub_bfd
, info
)
2465 struct bfd_link_info
*info
;
2467 /* The stub BFD only has one section. */
2468 asection
*stub_sec
= stub_bfd
->sections
;
2469 struct elf32_hppa_stub_hash_table
*table
;
2473 /* So we can pass both the BFD for the stubs and the link info
2474 structure to the routine which actually builds stubs. */
2478 /* Allocate memory to hold the linker stubs. */
2479 size
= bfd_section_size (stub_bfd
, stub_sec
);
2480 stub_sec
->contents
= (unsigned char *) bfd_zalloc (stub_bfd
, size
);
2481 if (stub_sec
->contents
== NULL
)
2483 table
= elf32_hppa_hash_table(info
)->stub_hash_table
;
2484 table
->location
= stub_sec
->contents
;
2486 /* Build the stubs as directed by the stub hash table. */
2487 elf32_hppa_stub_hash_traverse (table
, elf32_hppa_build_one_stub
, args
);
2492 /* Determine and set the size of the stub section for a final link.
2494 The basic idea here is to examine all the relocations looking for
2495 PC-relative calls to a target that is unreachable with a "bl"
2496 instruction or calls where the caller and callee disagree on the
2497 location of their arguments or return value. */
2500 elf32_hppa_size_stubs (stub_bfd
, output_bfd
, link_info
)
2503 struct bfd_link_info
*link_info
;
2506 asection
*section
, *stub_sec
= 0;
2507 Elf_Internal_Shdr
*symtab_hdr
;
2508 Elf_Internal_Sym
*local_syms
, *isym
, **all_local_syms
;
2509 Elf32_External_Sym
*ext_syms
, *esym
;
2510 unsigned int i
, index
, bfd_count
= 0;
2511 struct elf32_hppa_stub_hash_table
*stub_hash_table
= 0;
2512 struct elf32_hppa_args_hash_table
*args_hash_table
= 0;
2514 /* Create and initialize the stub hash table. */
2515 stub_hash_table
= ((struct elf32_hppa_stub_hash_table
*)
2516 bfd_malloc (sizeof (struct elf32_hppa_stub_hash_table
)));
2517 if (!stub_hash_table
)
2520 if (!elf32_hppa_stub_hash_table_init (stub_hash_table
, stub_bfd
,
2521 elf32_hppa_stub_hash_newfunc
))
2524 /* Likewise for the argument location hash table. */
2525 args_hash_table
= ((struct elf32_hppa_args_hash_table
*)
2526 bfd_malloc (sizeof (struct elf32_hppa_args_hash_table
)));
2527 if (!args_hash_table
)
2530 if (!elf32_hppa_args_hash_table_init (args_hash_table
,
2531 elf32_hppa_args_hash_newfunc
))
2534 /* Attach the hash tables to the main hash table. */
2535 elf32_hppa_hash_table(link_info
)->stub_hash_table
= stub_hash_table
;
2536 elf32_hppa_hash_table(link_info
)->args_hash_table
= args_hash_table
;
2538 /* Count the number of input BFDs. */
2539 for (input_bfd
= link_info
->input_bfds
;
2541 input_bfd
= input_bfd
->link_next
)
2544 /* We want to read in symbol extension records only once. To do this
2545 we need to read in the local symbols in parallel and save them for
2546 later use; so hold pointers to the local symbols in an array. */
2548 = (Elf_Internal_Sym
**) bfd_malloc (sizeof (Elf_Internal_Sym
*)
2550 if (all_local_syms
== NULL
)
2552 memset (all_local_syms
, 0, sizeof (Elf_Internal_Sym
*) * bfd_count
);
2554 /* Walk over all the input BFDs adding entries to the args hash table
2555 for all the external functions. */
2556 for (input_bfd
= link_info
->input_bfds
, index
= 0;
2558 input_bfd
= input_bfd
->link_next
, index
++)
2560 /* We'll need the symbol table in a second. */
2561 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2562 if (symtab_hdr
->sh_info
== 0)
2565 /* We need an array of the local symbols attached to the input bfd.
2566 Unfortunately, we're going to have to read & swap them in. */
2568 = (Elf_Internal_Sym
*) bfd_malloc (symtab_hdr
->sh_info
2569 * sizeof (Elf_Internal_Sym
));
2570 if (local_syms
== NULL
)
2572 for (i
= 0; i
< bfd_count
; i
++)
2573 if (all_local_syms
[i
])
2574 free (all_local_syms
[i
]);
2575 free (all_local_syms
);
2578 all_local_syms
[index
] = local_syms
;
2581 = (Elf32_External_Sym
*) bfd_malloc (symtab_hdr
->sh_info
2582 * sizeof (Elf32_External_Sym
));
2583 if (ext_syms
== NULL
)
2585 for (i
= 0; i
< bfd_count
; i
++)
2586 if (all_local_syms
[i
])
2587 free (all_local_syms
[i
]);
2588 free (all_local_syms
);
2592 if (bfd_seek (input_bfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
2593 || bfd_read (ext_syms
, 1,
2594 (symtab_hdr
->sh_info
2595 * sizeof (Elf32_External_Sym
)), input_bfd
)
2596 != (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
)))
2598 for (i
= 0; i
< bfd_count
; i
++)
2599 if (all_local_syms
[i
])
2600 free (all_local_syms
[i
]);
2601 free (all_local_syms
);
2606 /* Swap the local symbols in. */
2609 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++, esym
++, isym
++)
2610 bfd_elf32_swap_symbol_in (input_bfd
, esym
, isym
);
2612 /* Now we can free the external symbols. */
2615 if (elf32_hppa_read_symext_info (input_bfd
, symtab_hdr
, args_hash_table
,
2616 local_syms
) == false)
2618 for (i
= 0; i
< bfd_count
; i
++)
2619 if (all_local_syms
[i
])
2620 free (all_local_syms
[i
]);
2621 free (all_local_syms
);
2626 /* Magic as we know the stub bfd only has one section. */
2627 stub_sec
= stub_bfd
->sections
;
2629 /* If generating a relocateable output file, then we don't
2630 have to examine the relocs. */
2631 if (link_info
->relocateable
)
2633 for (i
= 0; i
< bfd_count
; i
++)
2634 if (all_local_syms
[i
])
2635 free (all_local_syms
[i
]);
2636 free (all_local_syms
);
2640 /* Now that we have argument location information for all the global
2641 functions we can start looking for stubs. */
2642 for (input_bfd
= link_info
->input_bfds
, index
= 0;
2644 input_bfd
= input_bfd
->link_next
, index
++)
2646 /* We'll need the symbol table in a second. */
2647 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2648 if (symtab_hdr
->sh_info
== 0)
2651 local_syms
= all_local_syms
[index
];
2653 /* Walk over each section attached to the input bfd. */
2654 for (section
= input_bfd
->sections
;
2656 section
= section
->next
)
2658 Elf_Internal_Shdr
*input_rel_hdr
;
2659 Elf32_External_Rela
*external_relocs
, *erelaend
, *erela
;
2660 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
2662 /* If there aren't any relocs, then there's nothing to do. */
2663 if ((section
->flags
& SEC_RELOC
) == 0
2664 || section
->reloc_count
== 0)
2667 /* Allocate space for the external relocations. */
2669 = ((Elf32_External_Rela
*)
2670 bfd_malloc (section
->reloc_count
2671 * sizeof (Elf32_External_Rela
)));
2672 if (external_relocs
== NULL
)
2674 for (i
= 0; i
< bfd_count
; i
++)
2675 if (all_local_syms
[i
])
2676 free (all_local_syms
[i
]);
2677 free (all_local_syms
);
2681 /* Likewise for the internal relocations. */
2683 = ((Elf_Internal_Rela
*)
2684 bfd_malloc (section
->reloc_count
* sizeof (Elf_Internal_Rela
)));
2685 if (internal_relocs
== NULL
)
2687 free (external_relocs
);
2688 for (i
= 0; i
< bfd_count
; i
++)
2689 if (all_local_syms
[i
])
2690 free (all_local_syms
[i
]);
2691 free (all_local_syms
);
2695 /* Read in the external relocs. */
2696 input_rel_hdr
= &elf_section_data (section
)->rel_hdr
;
2697 if (bfd_seek (input_bfd
, input_rel_hdr
->sh_offset
, SEEK_SET
) != 0
2698 || bfd_read (external_relocs
, 1, input_rel_hdr
->sh_size
,
2699 input_bfd
) != input_rel_hdr
->sh_size
)
2701 free (external_relocs
);
2702 free (internal_relocs
);
2703 for (i
= 0; i
< bfd_count
; i
++)
2704 if (all_local_syms
[i
])
2705 free (all_local_syms
[i
]);
2706 free (all_local_syms
);
2710 /* Swap in the relocs. */
2711 erela
= external_relocs
;
2712 erelaend
= erela
+ section
->reloc_count
;
2713 irela
= internal_relocs
;
2714 for (; erela
< erelaend
; erela
++, irela
++)
2715 bfd_elf32_swap_reloca_in (input_bfd
, erela
, irela
);
2717 /* We're done with the external relocs, free them. */
2718 free (external_relocs
);
2720 /* Now examine each relocation. */
2721 irela
= internal_relocs
;
2722 irelaend
= irela
+ section
->reloc_count
;
2723 for (; irela
< irelaend
; irela
++)
2725 long r_type
, callee_args
, caller_args
, size_of_stub
;
2726 unsigned long r_index
;
2727 struct elf_link_hash_entry
*hash
;
2728 struct elf32_hppa_stub_hash_entry
*stub_hash
;
2729 struct elf32_hppa_args_hash_entry
*args_hash
;
2730 Elf_Internal_Sym
*sym
;
2732 const char *sym_name
;
2734 bfd_vma location
, destination
;
2735 char *new_name
= NULL
;
2737 r_type
= ELF32_R_TYPE (irela
->r_info
);
2738 r_index
= ELF32_R_SYM (irela
->r_info
);
2740 if (r_type
< 0 || r_type
>= (int) R_PARISC_UNIMPLEMENTED
)
2742 bfd_set_error (bfd_error_bad_value
);
2743 free (internal_relocs
);
2744 for (i
= 0; i
< bfd_count
; i
++)
2745 if (all_local_syms
[i
])
2746 free (all_local_syms
[i
]);
2747 free (all_local_syms
);
2751 /* Only look for stubs on call instructions or plabel
2753 if (r_type
!= R_PARISC_PCREL17F
2754 && r_type
!= R_PARISC_PLABEL32
2755 && r_type
!= R_PARISC_PLABEL21L
2756 && r_type
!= R_PARISC_PLABEL14R
)
2759 /* Now determine the call target, its name, value, section
2760 and argument relocation bits. */
2764 if (r_index
< symtab_hdr
->sh_info
)
2766 /* It's a local symbol. */
2767 Elf_Internal_Shdr
*hdr
;
2769 sym
= local_syms
+ r_index
;
2770 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
2771 sym_sec
= hdr
->bfd_section
;
2772 sym_name
= bfd_elf_string_from_elf_section (input_bfd
,
2773 symtab_hdr
->sh_link
,
2775 sym_value
= (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
2776 ? 0 : sym
->st_value
);
2777 destination
= (sym_value
2778 + sym_sec
->output_offset
2779 + sym_sec
->output_section
->vma
);
2781 /* Tack on an ID so we can uniquely identify this local
2782 symbol in the stub or arg info hash tables. */
2783 new_name
= bfd_malloc (strlen (sym_name
) + 10);
2786 free (internal_relocs
);
2787 for (i
= 0; i
< bfd_count
; i
++)
2788 if (all_local_syms
[i
])
2789 free (all_local_syms
[i
]);
2790 free (all_local_syms
);
2793 sprintf (new_name
, "%s_%08x", sym_name
, (int)sym_sec
);
2794 sym_name
= new_name
;
2798 /* It's an external symbol. */
2801 index
= r_index
- symtab_hdr
->sh_info
;
2802 hash
= elf_sym_hashes (input_bfd
)[index
];
2803 if (hash
->root
.type
== bfd_link_hash_defined
2804 || hash
->root
.type
== bfd_link_hash_defweak
)
2806 sym_sec
= hash
->root
.u
.def
.section
;
2807 sym_name
= hash
->root
.root
.string
;
2808 sym_value
= hash
->root
.u
.def
.value
;
2809 destination
= (sym_value
2810 + sym_sec
->output_offset
2811 + sym_sec
->output_section
->vma
);
2815 bfd_set_error (bfd_error_bad_value
);
2816 free (internal_relocs
);
2817 for (i
= 0; i
< bfd_count
; i
++)
2818 if (all_local_syms
[i
])
2819 free (all_local_syms
[i
]);
2820 free (all_local_syms
);
2825 args_hash
= elf32_hppa_args_hash_lookup (args_hash_table
,
2826 sym_name
, false, false);
2828 /* Get both caller and callee argument information. */
2829 if (args_hash
== NULL
)
2832 callee_args
= args_hash
->arg_bits
;
2834 /* For calls get the caller's bits from the addend of
2835 the call relocation. For PLABELS the caller's bits
2836 are assumed to have all args & return values in general
2837 registers (0x155). */
2838 if (r_type
== R_PARISC_PCREL17F
)
2839 caller_args
= HPPA_R_ARG_RELOC (irela
->r_addend
);
2841 caller_args
= 0x155;
2843 /* Now determine where the call point is. */
2844 location
= (section
->output_offset
2845 + section
->output_section
->vma
2848 /* We only care about the destination for PCREL function
2849 calls (eg. we don't care for PLABELS). */
2850 if (r_type
!= R_PARISC_PCREL17F
)
2851 location
= destination
;
2853 /* Determine what (if any) linker stub is needed and its
2855 size_of_stub
= elf32_hppa_size_of_stub (callee_args
,
2860 if (size_of_stub
!= 0)
2865 /* Get the name of this stub. */
2866 len
= strlen (sym_name
);
2869 stub_name
= bfd_malloc (len
);
2872 /* Because sym_name was mallocd above for local
2874 if (r_index
< symtab_hdr
->sh_info
)
2877 free (internal_relocs
);
2878 for (i
= 0; i
< bfd_count
; i
++)
2879 if (all_local_syms
[i
])
2880 free (all_local_syms
[i
]);
2881 free (all_local_syms
);
2884 elf32_hppa_name_of_stub (caller_args
, callee_args
,
2885 location
, destination
, stub_name
);
2886 strcat (stub_name
+ 22, sym_name
);
2888 /* Because sym_name was malloced above for local symbols. */
2889 if (r_index
< symtab_hdr
->sh_info
)
2893 = elf32_hppa_stub_hash_lookup (stub_hash_table
, stub_name
,
2895 if (stub_hash
!= NULL
)
2897 /* The proper stub has already been created, nothing
2903 bfd_set_section_size (stub_bfd
, stub_sec
,
2904 (bfd_section_size (stub_bfd
,
2908 /* Enter this entry into the linker stub hash table. */
2910 = elf32_hppa_stub_hash_lookup (stub_hash_table
,
2911 stub_name
, true, true);
2912 if (stub_hash
== NULL
)
2915 free (internal_relocs
);
2916 for (i
= 0; i
< bfd_count
; i
++)
2917 if (all_local_syms
[i
])
2918 free (all_local_syms
[i
]);
2919 free (all_local_syms
);
2923 /* We'll need these to determine the address that the
2924 stub will branch to. */
2925 stub_hash
->target_value
= sym_value
;
2926 stub_hash
->target_section
= sym_sec
;
2931 /* We're done with the internal relocs, free them. */
2932 free (internal_relocs
);
2935 /* We're done with the local symbols, free them. */
2936 for (i
= 0; i
< bfd_count
; i
++)
2937 if (all_local_syms
[i
])
2938 free (all_local_syms
[i
]);
2939 free (all_local_syms
);
2943 /* Return gracefully, avoiding dangling references to the hash tables. */
2944 if (stub_hash_table
)
2946 elf32_hppa_hash_table(link_info
)->stub_hash_table
= NULL
;
2947 free (stub_hash_table
);
2949 if (args_hash_table
)
2951 elf32_hppa_hash_table(link_info
)->args_hash_table
= NULL
;
2952 free (args_hash_table
);
2954 /* Set the size of the stub section to zero since we're never going
2955 to create them. Avoids losing when we try to get its contents
2957 bfd_set_section_size (stub_bfd
, stub_sec
, 0);
2961 /* Misc BFD support code. */
2962 #define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
2963 #define bfd_elf32_bfd_is_local_label_name hppa_elf_is_local_label_name
2965 /* Symbol extension stuff. */
2966 #define bfd_elf32_set_section_contents elf32_hppa_set_section_contents
2967 #define elf_info_to_howto elf32_hppa_info_to_howto
2968 #define elf_backend_symbol_table_processing \
2969 elf32_hppa_backend_symbol_table_processing
2970 #define elf_backend_begin_write_processing \
2971 elf32_hppa_backend_begin_write_processing
2972 #define elf_backend_final_write_processing \
2973 elf32_hppa_backend_final_write_processing
2975 /* Stuff for the BFD linker. */
2976 #define elf_backend_relocate_section elf32_hppa_relocate_section
2977 #define elf_backend_add_symbol_hook elf32_hppa_add_symbol_hook
2978 #define elf_backend_link_output_symbol_hook \
2979 elf32_hppa_link_output_symbol_hook
2980 #define bfd_elf32_bfd_link_hash_table_create \
2981 elf32_hppa_link_hash_table_create
2983 #define TARGET_BIG_SYM bfd_elf32_hppa_vec
2984 #define TARGET_BIG_NAME "elf32-hppa"
2985 #define ELF_ARCH bfd_arch_hppa
2986 #define ELF_MACHINE_CODE EM_PARISC
2987 #define ELF_MAXPAGESIZE 0x1000
2989 #include "elf32-target.h"