1 /* BFD back-end for HP PA-RISC ELF files.
2 Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc.
6 Center for Software Science
7 Department of Computer Science
10 This file is part of BFD, the Binary File Descriptor library.
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
34 /* HPPA symbol table extension entry types */
35 enum elf32_hppa_symextn_types
42 /* These macros compose and decompose the value of a symextn entry:
44 entry_type = ELF32_PARISC_SX_TYPE(word);
45 entry_value = ELF32_PARISC_SX_VAL(word);
46 word = ELF32_PARISC_SX_WORD(type,val); */
48 #define ELF32_PARISC_SX_TYPE(p) ((p) >> 24)
49 #define ELF32_PARISC_SX_VAL(p) ((p) & 0xFFFFFF)
50 #define ELF32_PARISC_SX_WORD(type,val) (((type) << 24) + (val & 0xFFFFFF))
52 /* The following was added facilitate implementation of the .hppa_symextn
53 section. This section is built after the symbol table is built in the
54 elf_write_object_contents routine (called from bfd_close). It is built
55 so late because it requires information that is not known until
56 the symbol and string table sections have been allocated, and
57 the symbol table has been built. */
59 #define SYMEXTN_SECTION_NAME ".PARISC.symext"
61 /* FIXME. Are these external? (For example used by GAS?). If so the
62 names need to change to avoid namespace pollution, if not they should
63 be moved into elf32-hppa.c. */
64 typedef unsigned long symext_entryS
;
68 struct symext_chain
*next
;
71 typedef struct symext_chain symext_chainS
;
73 /* We use three different hash tables to hold information for
74 linking PA ELF objects.
76 The first is the elf32_hppa_link_hash_table which is derived
77 from the standard ELF linker hash table. We use this as a place to
78 attach other hash tables and static information.
80 The second is the stub hash table which is derived from the
81 base BFD hash table. The stub hash table holds the information
82 necessary to build the linker stubs during a link.
84 The last hash table keeps track of argument location information needed
85 to build hash tables. Each function with nonzero argument location
86 bits will have an entry in this table. */
88 /* Hash table for linker stubs. */
90 struct elf32_hppa_stub_hash_entry
92 /* Base hash table entry structure, we can get the name of the stub
93 (and thus know exactly what actions it performs) from the base
95 struct bfd_hash_entry root
;
97 /* Offset of the beginning of this stub. */
100 /* Given the symbol's value and its section we can determine its final
101 value when building the stubs (so the stub knows where to jump. */
102 symvalue target_value
;
103 asection
*target_section
;
106 struct elf32_hppa_stub_hash_table
108 /* The hash table itself. */
109 struct bfd_hash_table root
;
114 /* Where to place the next stub. */
117 /* Current offset in the stub section. */
122 /* Hash table for argument location information. */
124 struct elf32_hppa_args_hash_entry
126 /* Base hash table entry structure. */
127 struct bfd_hash_entry root
;
129 /* The argument location bits for this entry. */
133 struct elf32_hppa_args_hash_table
135 /* The hash table itself. */
136 struct bfd_hash_table root
;
139 struct elf32_hppa_link_hash_entry
141 struct elf_link_hash_entry root
;
144 struct elf32_hppa_link_hash_table
146 /* The main hash table. */
147 struct elf_link_hash_table root
;
149 /* The stub hash table. */
150 struct elf32_hppa_stub_hash_table
*stub_hash_table
;
152 /* The argument relocation bits hash table. */
153 struct elf32_hppa_args_hash_table
*args_hash_table
;
155 /* A count of the number of output symbols. */
156 unsigned int output_symbol_count
;
158 /* Stuff so we can handle DP relative relocations. */
160 int global_sym_defined
;
163 typedef unsigned int symextn_entry
;
167 #define RETURN_VALUE 1
169 /* The various argument relocations that may be performed. */
174 /* Relocate 32 bits from GR to FP register. */
176 /* Relocate 64 bits from a GR pair to FP pair. */
178 /* Relocate 32 bits from FP to GR. */
180 /* Relocate 64 bits from FP pair to GR pair. */
184 /* What is being relocated (eg which argument or the return value). */
187 ARG0
, ARG1
, ARG2
, ARG3
, RET
,
188 } arg_reloc_location
;
191 /* ELF32/HPPA relocation support
193 This file contains ELF32/HPPA relocation support as specified
194 in the Stratus FTX/Golf Object File Format (SED-1762) dated
197 #include "elf32-hppa.h"
198 #include "hppa_stubs.h"
200 static bfd_reloc_status_type hppa_elf_reloc
201 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
203 static unsigned long hppa_elf_relocate_insn
204 PARAMS ((bfd
*, asection
*, unsigned long, unsigned long, long,
205 long, unsigned long, unsigned long, unsigned long));
207 static bfd_reloc_status_type hppa_elf_reloc
208 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
210 static CONST reloc_howto_type
* elf_hppa_reloc_type_lookup
211 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
213 static boolean elf32_hppa_set_section_contents
214 PARAMS ((bfd
*, sec_ptr
, PTR
, file_ptr
, bfd_size_type
));
216 static void elf_info_to_howto
217 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rela
*));
219 static boolean elf32_hppa_backend_symbol_table_processing
220 PARAMS ((bfd
*, elf_symbol_type
*, int));
222 static void elf32_hppa_backend_begin_write_processing
223 PARAMS ((bfd
*, struct bfd_link_info
*));
225 static void elf32_hppa_backend_final_write_processing
226 PARAMS ((bfd
*, boolean
));
228 static void add_entry_to_symext_chain
229 PARAMS ((bfd
*, unsigned int, unsigned int, symext_chainS
**,
233 elf_hppa_tc_make_sections
PARAMS ((bfd
*, symext_chainS
*));
235 static boolean hppa_elf_is_local_label
PARAMS ((bfd
*, asymbol
*));
237 static boolean elf32_hppa_add_symbol_hook
238 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
239 const char **, flagword
*, asection
**, bfd_vma
*));
241 static bfd_reloc_status_type elf32_hppa_bfd_final_link_relocate
242 PARAMS ((const reloc_howto_type
*, bfd
*, bfd
*, asection
*,
243 bfd_byte
*, bfd_vma
, bfd_vma
, bfd_vma
, struct bfd_link_info
*,
244 asection
*, const char *, int));
246 static struct bfd_link_hash_table
*elf32_hppa_link_hash_table_create
249 static struct bfd_hash_entry
*
250 elf32_hppa_stub_hash_newfunc
251 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
253 static struct bfd_hash_entry
*
254 elf32_hppa_args_hash_newfunc
255 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
258 elf32_hppa_relocate_section
259 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*,
260 bfd_byte
*, Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
263 elf32_hppa_stub_hash_table_init
264 PARAMS ((struct elf32_hppa_stub_hash_table
*, bfd
*,
265 struct bfd_hash_entry
*(*) PARAMS ((struct bfd_hash_entry
*,
266 struct bfd_hash_table
*,
270 elf32_hppa_build_one_stub
PARAMS ((struct bfd_hash_entry
*, PTR
));
273 elf32_hppa_read_symext_info
274 PARAMS ((bfd
*, Elf_Internal_Shdr
*, struct elf32_hppa_args_hash_table
*,
275 Elf_Internal_Sym
*, boolean
, boolean
));
277 static unsigned int elf32_hppa_size_of_stub
278 PARAMS ((unsigned int, unsigned int, bfd_vma
, bfd_vma
, const char *));
280 static boolean elf32_hppa_arg_reloc_needed
281 PARAMS ((unsigned int, unsigned int, arg_reloc_type
[]));
283 static void elf32_hppa_name_of_stub
284 PARAMS ((unsigned int, unsigned int, bfd_vma
, bfd_vma
, char *));
286 static boolean elf32_hppa_size_symext
PARAMS ((struct bfd_hash_entry
*, PTR
));
288 static boolean elf32_hppa_link_output_symbol_hook
289 PARAMS ((bfd
*, struct bfd_link_info
*, const char *,
290 Elf_Internal_Sym
*, asection
*));
292 /* ELF/PA relocation howto entries. */
294 static reloc_howto_type elf_hppa_howto_table
[ELF_HOWTO_TABLE_SIZE
] =
296 {R_PARISC_NONE
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_NONE"},
297 {R_PARISC_DIR32
, 0, 0, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DIR32"},
298 {R_PARISC_DIR21L
, 0, 0, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DIR21L"},
299 {R_PARISC_DIR17R
, 0, 0, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DIR17R"},
300 {R_PARISC_DIR17F
, 0, 0, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DIR17F"},
301 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
302 {R_PARISC_DIR14R
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DIR14R"},
303 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
305 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
306 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
307 {R_PARISC_PCREL21L
, 0, 0, 21, true, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PCREL21L"},
308 {R_PARISC_PCREL17R
, 0, 0, 17, true, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PCREL17R"},
309 {R_PARISC_PCREL17F
, 0, 0, 17, true, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PCREL17F"},
310 {R_PARISC_PCREL17C
, 0, 0, 17, true, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PCREL17C"},
311 {R_PARISC_PCREL14R
, 0, 0, 14, true, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PCREL14R"},
312 {R_PARISC_PCREL14F
, 0, 0, 14, true, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PCREL14F"},
314 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
315 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
316 {R_PARISC_DPREL21L
, 0, 0, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DPREL21L"},
317 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
318 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
319 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
320 {R_PARISC_DPREL14R
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DPREL14R"},
321 {R_PARISC_DPREL14F
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DPREL14F"},
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_DLTREL21L
, 0, 0, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DLTREL21L"},
326 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
327 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
328 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
329 {R_PARISC_DLTREL14R
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DLTREL14R"},
330 {R_PARISC_DLTREL14F
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DLTREL14F"},
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_DLTIND21L
, 0, 0, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DLTIND21L"},
335 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
336 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
337 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
338 {R_PARISC_DLTIND14R
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DLTIND14R"},
339 {R_PARISC_DLTIND14F
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DLTIND14F"},
341 {R_PARISC_SETBASE
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_SETBASE"},
342 {R_PARISC_BASEREL32
, 0, 0, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_BASEREL32"},
343 {R_PARISC_BASEREL21L
, 0, 0, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_BASEREL21L"},
344 {R_PARISC_BASEREL17R
, 0, 0, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_BASEREL17R"},
345 {R_PARISC_BASEREL17F
, 0, 0, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_BASEREL17F"},
346 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
347 {R_PARISC_BASEREL14R
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_BASEREL14R"},
348 {R_PARISC_BASEREL14F
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_BASEREL14F"},
350 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
351 {R_PARISC_TEXTREL32
, 0, 0, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_TEXTREL32"},
352 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
353 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
354 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
355 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
356 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
357 {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_DATAREL32
, 0, 0, 32, 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"},
363 {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_UNIMPLEMENTED
, 0, 0, 0, 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"},
369 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
370 {R_PARISC_PLABEL32
, 0, 0, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PLABEL32"},
371 {R_PARISC_PLABEL21L
, 0, 0, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PLABEL21L"},
372 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
373 {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_PLABEL14R
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PLABEL14R"},
376 {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_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
381 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
382 {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"},
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"},
391 {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"},
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"},
408 {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"},
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"},
425 {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"},
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_PLTIND21L
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PLTIND21L"},
442 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
443 {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_PLTIND14R
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PLTIND14R"},
446 {R_PARISC_PLTIND14F
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PLTIND14F"},
449 {R_PARISC_COPY
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_COPY"},
450 {R_PARISC_GLOB_DAT
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_GLOB_DAT"},
451 {R_PARISC_JMP_SLOT
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_JMP_SLOT"},
452 {R_PARISC_RELATIVE
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_RELATIVE"},
454 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_dont
, NULL
, "R_PARISC_UNIMPLEMENTED"},
457 /* Where (what register type) is an argument comming from? */
468 /* Horizontal represents the callee's argument location information,
469 vertical represents caller's argument location information. Value at a
470 particular X,Y location represents what (if any) argument relocation
471 needs to be performed to make caller and callee agree. */
473 static CONST arg_reloc_type arg_mismatches
[6][6] =
475 {NO
, NO
, NO
, NO
, NO
, NO
},
476 {NO
, NO
, GF
, NO
, GD
, NO
},
477 {NO
, FG
, NO
, NO
, NO
, NO
},
478 {NO
, NO
, NO
, NO
, NO
, NO
},
479 {NO
, DG
, NO
, NO
, NO
, NO
},
480 {NO
, DG
, NO
, NO
, NO
, NO
},
483 /* Likewise, but reversed for the return value. */
484 static CONST arg_reloc_type ret_mismatches
[6][6] =
486 {NO
, NO
, NO
, NO
, NO
, NO
},
487 {NO
, NO
, FG
, NO
, DG
, NO
},
488 {NO
, GF
, NO
, NO
, NO
, NO
},
489 {NO
, NO
, NO
, NO
, NO
, NO
},
490 {NO
, GD
, NO
, NO
, NO
, NO
},
491 {NO
, GD
, NO
, NO
, NO
, NO
},
494 /* Misc static crud for symbol extension records. */
495 static symext_chainS
*symext_rootP
;
496 static symext_chainS
*symext_lastP
;
497 static int symext_chain_size
;
499 /* FIXME: We should be able to try this static variable! */
500 static symext_entryS
*symextn_contents
;
503 /* For linker stub hash tables. */
504 #define elf32_hppa_stub_hash_lookup(table, string, create, copy) \
505 ((struct elf32_hppa_stub_hash_entry *) \
506 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
508 #define elf32_hppa_stub_hash_traverse(table, func, info) \
511 (boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) (func), \
514 /* For linker args hash tables. */
515 #define elf32_hppa_args_hash_lookup(table, string, create, copy) \
516 ((struct elf32_hppa_args_hash_entry *) \
517 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
519 #define elf32_hppa_args_hash_traverse(table, func, info) \
522 (boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) (func), \
525 #define elf32_hppa_args_hash_table_init(table, newfunc) \
526 (bfd_hash_table_init \
528 (struct bfd_hash_entry *(*) PARAMS ((struct bfd_hash_entry *, \
529 struct bfd_hash_table *, \
530 const char *))) (newfunc)))
532 /* For HPPA linker hash table. */
534 #define elf32_hppa_link_hash_lookup(table, string, create, copy, follow)\
535 ((struct elf32_hppa_link_hash_entry *) \
536 elf_link_hash_lookup (&(table)->root, (string), (create), \
539 #define elf32_hppa_link_hash_traverse(table, func, info) \
540 (elf_link_hash_traverse \
542 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
545 /* Get the PA ELF linker hash table from a link_info structure. */
547 #define elf32_hppa_hash_table(p) \
548 ((struct elf32_hppa_link_hash_table *) ((p)->hash))
551 /* Extract specific argument location bits for WHICH from
552 the full argument location in AR. */
553 #define EXTRACT_ARBITS(ar, which) ((ar) >> (8 - ((which) * 2))) & 3
555 /* Assorted hash table functions. */
557 /* Initialize an entry in the stub hash table. */
559 static struct bfd_hash_entry
*
560 elf32_hppa_stub_hash_newfunc (entry
, table
, string
)
561 struct bfd_hash_entry
*entry
;
562 struct bfd_hash_table
*table
;
565 struct elf32_hppa_stub_hash_entry
*ret
;
567 ret
= (struct elf32_hppa_stub_hash_entry
*) entry
;
569 /* Allocate the structure if it has not already been allocated by a
572 ret
= ((struct elf32_hppa_stub_hash_entry
*)
573 bfd_hash_allocate (table
,
574 sizeof (struct elf32_hppa_stub_hash_entry
)));
577 bfd_set_error (bfd_error_no_memory
);
581 /* Call the allocation method of the superclass. */
582 ret
= ((struct elf32_hppa_stub_hash_entry
*)
583 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
587 /* Initialize the local fields. */
589 ret
->target_value
= 0;
590 ret
->target_section
= NULL
;
593 return (struct bfd_hash_entry
*) ret
;
596 /* Initialize a stub hash table. */
599 elf32_hppa_stub_hash_table_init (table
, stub_bfd
, newfunc
)
600 struct elf32_hppa_stub_hash_table
*table
;
602 struct bfd_hash_entry
*(*newfunc
) PARAMS ((struct bfd_hash_entry
*,
603 struct bfd_hash_table
*,
608 table
->stub_bfd
= stub_bfd
;
609 return (bfd_hash_table_init (&table
->root
, newfunc
));
612 /* Initialize an entry in the argument location hash table. */
614 static struct bfd_hash_entry
*
615 elf32_hppa_args_hash_newfunc (entry
, table
, string
)
616 struct bfd_hash_entry
*entry
;
617 struct bfd_hash_table
*table
;
620 struct elf32_hppa_args_hash_entry
*ret
;
622 ret
= (struct elf32_hppa_args_hash_entry
*) entry
;
624 /* Allocate the structure if it has not already been allocated by a
627 ret
= ((struct elf32_hppa_args_hash_entry
*)
628 bfd_hash_allocate (table
,
629 sizeof (struct elf32_hppa_args_hash_entry
)));
632 bfd_set_error (bfd_error_no_memory
);
636 /* Call the allocation method of the superclass. */
637 ret
= ((struct elf32_hppa_args_hash_entry
*)
638 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
640 /* Initialize the local fields. */
644 return (struct bfd_hash_entry
*) ret
;
647 /* Create the derived linker hash table. The PA ELF port uses the derived
648 hash table to keep information specific to the PA ELF linker (without
649 using static variables). */
651 static struct bfd_link_hash_table
*
652 elf32_hppa_link_hash_table_create (abfd
)
655 struct elf32_hppa_link_hash_table
*ret
;
657 ret
= ((struct elf32_hppa_link_hash_table
*)
658 bfd_alloc (abfd
, sizeof (struct elf32_hppa_link_hash_table
)));
661 bfd_set_error (bfd_error_no_memory
);
664 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
665 _bfd_elf_link_hash_newfunc
))
667 bfd_release (abfd
, ret
);
670 ret
->stub_hash_table
= NULL
;
671 ret
->args_hash_table
= NULL
;
672 ret
->output_symbol_count
= 0;
673 ret
->global_value
= 0;
674 ret
->global_sym_defined
= 0;
676 return &ret
->root
.root
;
679 /* Relocate the given INSN given the various input parameters.
681 FIXME: endianness and sizeof (long) issues abound here. */
684 hppa_elf_relocate_insn (abfd
, input_sect
, insn
, address
, sym_value
,
685 r_addend
, r_format
, r_field
, pcrel
)
687 asection
*input_sect
;
689 unsigned long address
;
692 unsigned long r_format
;
693 unsigned long r_field
;
696 unsigned char opcode
= get_opcode (insn
);
716 constant_value
= HPPA_R_CONSTANT (r_addend
);
719 sym_value
-= address
;
721 sym_value
= hppa_field_adjust (sym_value
, constant_value
, r_field
);
722 return hppa_rebuild_insn (abfd
, insn
, sym_value
, r_format
);
727 /* XXX computing constant_value is not needed??? */
728 constant_value
= assemble_17 ((insn
& 0x001f0000) >> 16,
729 (insn
& 0x00001ffc) >> 2,
732 constant_value
= (constant_value
<< 15) >> 15;
736 address
+ input_sect
->output_offset
737 + input_sect
->output_section
->vma
;
738 sym_value
= hppa_field_adjust (sym_value
, -8, r_field
);
741 sym_value
= hppa_field_adjust (sym_value
, constant_value
, r_field
);
743 return hppa_rebuild_insn (abfd
, insn
, sym_value
>> 2, r_format
);
748 constant_value
= HPPA_R_CONSTANT (r_addend
);
751 sym_value
-= address
;
753 return hppa_field_adjust (sym_value
, constant_value
, r_field
);
760 /* Relocate an HPPA ELF section. */
763 elf32_hppa_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
764 contents
, relocs
, local_syms
, local_sections
)
766 struct bfd_link_info
*info
;
768 asection
*input_section
;
770 Elf_Internal_Rela
*relocs
;
771 Elf_Internal_Sym
*local_syms
;
772 asection
**local_sections
;
774 Elf_Internal_Shdr
*symtab_hdr
;
775 Elf_Internal_Rela
*rel
;
776 Elf_Internal_Rela
*relend
;
778 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
781 relend
= relocs
+ input_section
->reloc_count
;
782 for (; rel
< relend
; rel
++)
785 const reloc_howto_type
*howto
;
787 struct elf_link_hash_entry
*h
;
788 Elf_Internal_Sym
*sym
;
791 bfd_reloc_status_type r
;
792 const char *sym_name
;
794 r_type
= ELF32_R_TYPE (rel
->r_info
);
795 if (r_type
< 0 || r_type
>= (int) R_PARISC_UNIMPLEMENTED
)
797 bfd_set_error (bfd_error_bad_value
);
800 howto
= elf_hppa_howto_table
+ r_type
;
802 r_symndx
= ELF32_R_SYM (rel
->r_info
);
804 if (info
->relocateable
)
806 /* This is a relocateable link. We don't have to change
807 anything, unless the reloc is against a section symbol,
808 in which case we have to adjust according to where the
809 section symbol winds up in the output section. */
810 if (r_symndx
< symtab_hdr
->sh_info
)
812 sym
= local_syms
+ r_symndx
;
813 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
815 sym_sec
= local_sections
[r_symndx
];
816 rel
->r_addend
+= sym_sec
->output_offset
;
823 /* This is a final link. */
827 if (r_symndx
< symtab_hdr
->sh_info
)
829 sym
= local_syms
+ r_symndx
;
830 sym_sec
= local_sections
[r_symndx
];
831 relocation
= ((ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
833 + sym_sec
->output_offset
834 + sym_sec
->output_section
->vma
);
840 indx
= r_symndx
- symtab_hdr
->sh_info
;
841 h
= elf_sym_hashes (input_bfd
)[indx
];
842 if (h
->root
.type
== bfd_link_hash_defined
)
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_weak
)
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
= 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 case bfd_reloc_dangerous
:
893 /* We use this return value to indicate that we performed
894 a "dangerous" relocation. This doesn't mean we did
895 the wrong thing, it just means there may be some cleanup
896 that needs to be done here.
898 In particular we had to swap the last call insn and its
899 delay slot. If the delay slot insn needed a relocation,
900 then we'll need to adjust the next relocation entry's
901 offset to account for the fact that the insn moved.
903 This hair wouldn't be necessary if we inserted stubs
904 between procedures and used a "bl" to get to the stub. */
907 Elf_Internal_Rela
*next_rel
= rel
+ 1;
909 if (rel
->r_offset
+ 4 == next_rel
->r_offset
)
910 next_rel
->r_offset
-= 4;
915 case bfd_reloc_outofrange
:
916 case bfd_reloc_overflow
:
918 if (!((*info
->callbacks
->reloc_overflow
)
919 (info
, sym_name
, howto
->name
, (bfd_vma
) 0,
920 input_bfd
, input_section
, rel
->r_offset
)))
931 /* Return one (or more) BFD relocations which implement the base
932 relocation with modifications based on format and field. */
934 elf32_hppa_reloc_type
**
935 hppa_elf_gen_reloc_type (abfd
, base_type
, format
, field
)
937 elf32_hppa_reloc_type base_type
;
941 elf32_hppa_reloc_type
*finaltype
;
942 elf32_hppa_reloc_type
**final_types
;
944 /* Allocate slots for the BFD relocation. */
945 final_types
= (elf32_hppa_reloc_type
**)
946 bfd_alloc_by_size_t (abfd
, sizeof (elf32_hppa_reloc_type
*) * 2);
947 if (final_types
== NULL
)
950 /* Allocate space for the relocation itself. */
951 finaltype
= (elf32_hppa_reloc_type
*)
952 bfd_alloc_by_size_t (abfd
, sizeof (elf32_hppa_reloc_type
));
953 if (finaltype
== NULL
)
956 /* Some reasonable defaults. */
957 final_types
[0] = finaltype
;
958 final_types
[1] = NULL
;
960 #define final_type finaltype[0]
962 final_type
= base_type
;
964 /* Just a tangle of nested switch statements to deal with the braindamage
965 that a different field selector means a completely different relocation
970 case R_HPPA_ABS_CALL
:
978 final_type
= R_PARISC_DIR14R
;
981 final_type
= R_PARISC_DLTREL14R
;
984 final_type
= R_PARISC_DLTREL14F
;
987 final_type
= R_PARISC_PLABEL14R
;
998 final_type
= R_PARISC_DIR17F
;
1002 final_type
= R_PARISC_DIR17R
;
1014 final_type
= R_PARISC_DIR21L
;
1017 final_type
= R_PARISC_DLTREL21L
;
1020 final_type
= R_PARISC_PLABEL21L
;
1031 final_type
= R_PARISC_DIR32
;
1034 final_type
= R_PARISC_PLABEL32
;
1055 final_type
= R_PARISC_DPREL14R
;
1058 final_type
= R_PARISC_DPREL14F
;
1070 final_type
= R_PARISC_DPREL21L
;
1083 case R_HPPA_PCREL_CALL
:
1091 final_type
= R_PARISC_PCREL14R
;
1094 final_type
= R_PARISC_PCREL14F
;
1106 final_type
= R_PARISC_PCREL17R
;
1109 final_type
= R_PARISC_PCREL17F
;
1121 final_type
= R_PARISC_PCREL21L
;
1142 /* Set the contents of a particular section at a particular location. */
1145 elf32_hppa_set_section_contents (abfd
, section
, location
, offset
, count
)
1150 bfd_size_type count
;
1152 /* Ignore write requests for the symbol extension section until we've
1153 had the chance to rebuild it ourselves. */
1154 if (!strcmp (section
->name
, ".PARISC.symextn") && !symext_chain_size
)
1157 return bfd_elf32_set_section_contents (abfd
, section
, location
,
1161 /* Translate from an elf into field into a howto relocation pointer. */
1164 elf_info_to_howto (abfd
, cache_ptr
, dst
)
1167 Elf32_Internal_Rela
*dst
;
1169 BFD_ASSERT (ELF32_R_TYPE(dst
->r_info
) < (unsigned int) R_PARISC_UNIMPLEMENTED
);
1170 cache_ptr
->howto
= &elf_hppa_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
1174 /* Actually perform a relocation. NOTE this is (mostly) superceeded
1175 by elf32_hppa_bfd_final_link_relocate which is called by the new
1178 static bfd_reloc_status_type
1179 hppa_elf_reloc (abfd
, reloc_entry
, symbol_in
, data
, input_section
, output_bfd
,
1182 arelent
*reloc_entry
;
1185 asection
*input_section
;
1187 char **error_message
;
1189 /* It is no longer valid to call hppa_elf_reloc when creating
1190 a final executable. */
1193 reloc_entry
->address
+= input_section
->output_offset
;
1195 /* Work around lossage in generic elf code to write relocations.
1196 (maps different section symbols into the same symbol index). */
1197 if ((symbol_in
->flags
& BSF_SECTION_SYM
)
1198 && symbol_in
->section
)
1199 reloc_entry
->addend
+= symbol_in
->section
->output_offset
;
1200 return bfd_reloc_ok
;
1204 *error_message
= (char *) "Unsupported call to hppa_elf_reloc";
1205 return bfd_reloc_notsupported
;
1209 /* Actually perform a relocation as part of a final link. This can get
1210 rather hairy when linker stubs are needed. */
1212 static bfd_reloc_status_type
1213 elf32_hppa_bfd_final_link_relocate (howto
, input_bfd
, output_bfd
,
1214 input_section
, contents
, offset
, value
,
1215 addend
, info
, sym_sec
, sym_name
, is_local
)
1216 const reloc_howto_type
*howto
;
1219 asection
*input_section
;
1224 struct bfd_link_info
*info
;
1226 const char *sym_name
;
1230 unsigned long r_type
= howto
->type
;
1231 unsigned long r_format
= howto
->bitsize
;
1232 unsigned long r_field
= e_fsel
;
1233 bfd_byte
*hit_data
= contents
+ offset
+ input_section
->vma
;
1234 boolean r_pcrel
= howto
->pc_relative
;
1236 insn
= bfd_get_32 (input_bfd
, hit_data
);
1238 /* Make sure we have a value for $global$. FIXME isn't this effectively
1239 just like the gp pointer on MIPS? Can we use those routines for this
1241 if (!elf32_hppa_hash_table (info
)->global_sym_defined
)
1243 struct elf_link_hash_entry
*h
;
1246 h
= elf_link_hash_lookup (elf_hash_table (info
), "$global$", false,
1249 /* If there isn't a $global$, then we're in deep trouble. */
1251 return bfd_reloc_notsupported
;
1253 sec
= h
->root
.u
.def
.section
;
1254 elf32_hppa_hash_table (info
)->global_value
= (h
->root
.u
.def
.value
1256 + sec
->output_offset
);
1257 elf32_hppa_hash_table (info
)->global_sym_defined
= 1;
1265 case R_PARISC_DIR32
:
1266 case R_PARISC_DIR17F
:
1267 case R_PARISC_PCREL17C
:
1269 goto do_basic_type_1
;
1270 case R_PARISC_DIR21L
:
1271 case R_PARISC_PCREL21L
:
1273 goto do_basic_type_1
;
1274 case R_PARISC_DIR17R
:
1275 case R_PARISC_PCREL17R
:
1276 case R_PARISC_DIR14R
:
1277 case R_PARISC_PCREL14R
:
1279 goto do_basic_type_1
;
1281 /* For all the DP relative relocations, we need to examine the symbol's
1282 section. If it's a code section, then "data pointer relative" makes
1283 no sense. In that case we don't adjust the "value", and for 21 bit
1284 addil instructions, we change the source addend register from %dp to
1286 case R_PARISC_DPREL21L
:
1288 if (sym_sec
->flags
& SEC_CODE
)
1289 insn
&= ~0x03e00000;
1291 value
-= elf32_hppa_hash_table (info
)->global_value
;
1292 goto do_basic_type_1
;
1293 case R_PARISC_DPREL14R
:
1295 if ((sym_sec
->flags
& SEC_CODE
) == 0)
1296 value
-= elf32_hppa_hash_table (info
)->global_value
;
1297 goto do_basic_type_1
;
1298 case R_PARISC_DPREL14F
:
1300 if ((sym_sec
->flags
& SEC_CODE
) == 0)
1301 value
-= elf32_hppa_hash_table (info
)->global_value
;
1302 goto do_basic_type_1
;
1304 /* These cases are separate as they may involve a lot more work
1305 to deal with linker stubs. */
1306 case R_PARISC_PLABEL32
:
1307 case R_PARISC_PLABEL21L
:
1308 case R_PARISC_PLABEL14R
:
1309 case R_PARISC_PCREL17F
:
1312 unsigned int len
, caller_args
, callee_args
;
1313 arg_reloc_type arg_reloc_types
[5];
1314 struct elf32_hppa_args_hash_table
*args_hash_table
;
1315 struct elf32_hppa_args_hash_entry
*args_hash
;
1316 char *new_name
, *stub_name
;
1318 /* Get the field selector right. We'll need it in a minute. */
1319 if (r_type
== R_PARISC_PCREL17F
1320 || r_type
== R_PARISC_PLABEL32
)
1322 else if (r_type
== R_PARISC_PLABEL21L
)
1324 else if (r_type
== R_PARISC_PLABEL14R
)
1327 /* Find out where we are and where we're going. */
1328 location
= (offset
+
1329 input_section
->output_offset
+
1330 input_section
->output_section
->vma
);
1332 /* Now look for the argument relocation bits associated with the
1334 len
= strlen (sym_name
) + 1;
1337 new_name
= malloc (len
);
1340 bfd_set_error (bfd_error_no_memory
);
1341 return bfd_reloc_notsupported
;
1343 strcpy (new_name
, sym_name
);
1345 /* Local symbols have unique IDs. */
1347 sprintf (new_name
+ len
- 10, "_%08x", (int)sym_sec
);
1349 args_hash_table
= elf32_hppa_hash_table (info
)->args_hash_table
;
1351 args_hash
= elf32_hppa_args_hash_lookup (args_hash_table
,
1352 new_name
, false, false);
1353 if (args_hash
== NULL
)
1356 callee_args
= args_hash
->arg_bits
;
1358 /* If this is a CALL relocation, then get the caller's bits
1359 from the addend. Else use the magic 0x155 value for PLABELS.
1361 Also we don't care about the destination (value) for PLABELS. */
1362 if (r_type
== R_PARISC_PCREL17F
)
1363 caller_args
= HPPA_R_ARG_RELOC (addend
);
1366 caller_args
= 0x155;
1370 /* Any kind of linker stub needed? */
1371 if (((int)(value
- location
) > 0x3ffff)
1372 || ((int)(value
- location
) < (int)0xfffc0000)
1373 || elf32_hppa_arg_reloc_needed (caller_args
, callee_args
,
1376 struct elf32_hppa_stub_hash_table
*stub_hash_table
;
1377 struct elf32_hppa_stub_hash_entry
*stub_hash
;
1378 asection
*stub_section
;
1380 /* Build a name for the stub. */
1382 len
= strlen (new_name
);
1384 stub_name
= malloc (len
);
1387 bfd_set_error (bfd_error_no_memory
);
1388 return bfd_reloc_notsupported
;
1390 elf32_hppa_name_of_stub (caller_args
, callee_args
,
1391 location
, value
, stub_name
);
1392 strcat (stub_name
, new_name
);
1395 stub_hash_table
= elf32_hppa_hash_table (info
)->stub_hash_table
;
1398 = elf32_hppa_stub_hash_lookup (stub_hash_table
, stub_name
,
1401 /* We're done with that name. */
1404 /* The stub BFD only has one section. */
1405 stub_section
= stub_hash_table
->stub_bfd
->sections
;
1407 if (stub_hash
!= NULL
)
1410 if (r_type
== R_PARISC_PCREL17F
)
1412 unsigned long delay_insn
;
1413 unsigned int opcode
, rtn_reg
, ldo_target_reg
, ldo_src_reg
;
1415 /* We'll need to peek at the next insn. */
1416 delay_insn
= bfd_get_32 (input_bfd
, hit_data
+ 4);
1417 opcode
= get_opcode (delay_insn
);
1419 /* We also need to know the return register for this
1421 rtn_reg
= (insn
& 0x03e00000) >> 21;
1423 ldo_src_reg
= (delay_insn
& 0x03e00000) >> 21;
1424 ldo_target_reg
= (delay_insn
& 0x001f0000) >> 16;
1426 /* Munge up the value and other parameters for
1427 hppa_elf_relocate_insn. */
1429 value
= (stub_hash
->offset
1430 + stub_section
->output_offset
1431 + stub_section
->output_section
->vma
);
1438 /* We need to peek at the delay insn and determine if
1439 we'll need to swap the branch and its delay insn. */
1442 && ldo_target_reg
== rtn_reg
)
1443 || (delay_insn
== 0x08000240))
1445 /* No need to swap the branch and its delay slot, but
1446 we do need to make sure to jump past the return
1447 pointer update in the stub. */
1450 /* If the delay insn does a return pointer adjustment,
1451 then we have to make sure it stays valid. */
1453 && ldo_target_reg
== rtn_reg
)
1455 delay_insn
&= 0xfc00ffff;
1456 delay_insn
|= ((31 << 21) | (31 << 16));
1457 bfd_put_32 (input_bfd
, delay_insn
, hit_data
+ 4);
1459 /* Use a BLE to reach the stub. */
1464 /* Wonderful, we have to swap the call insn and its
1466 bfd_put_32 (input_bfd
, delay_insn
, hit_data
);
1467 /* Use a BLE,n to reach the stub. */
1468 insn
= (BLE_SR4_R0
| 0x2);
1469 bfd_put_32 (input_bfd
, insn
, hit_data
+ 4);
1470 insn
= hppa_elf_relocate_insn (input_bfd
,
1476 /* Update the instruction word. */
1477 bfd_put_32 (input_bfd
, insn
, hit_data
+ 4);
1478 return bfd_reloc_dangerous
;
1483 /* PLABEL stuff is easy. */
1485 value
= (stub_hash
->offset
1486 + stub_section
->output_offset
1487 + stub_section
->output_section
->vma
);
1488 /* We don't need the RP adjustment for PLABELs. */
1490 if (r_type
== R_PARISC_PLABEL32
)
1492 else if (r_type
== R_PARISC_PLABEL21L
)
1494 else if (r_type
== R_PARISC_PLABEL14R
)
1502 return bfd_reloc_notsupported
;
1504 goto do_basic_type_1
;
1508 insn
= hppa_elf_relocate_insn (input_bfd
, input_section
, insn
,
1509 offset
, value
, addend
, r_format
,
1513 /* Something we don't know how to handle. */
1515 return bfd_reloc_notsupported
;
1518 /* Update the instruction word. */
1519 bfd_put_32 (input_bfd
, insn
, hit_data
);
1520 return (bfd_reloc_ok
);
1523 /* Return the address of the howto table entry to perform the CODE
1524 relocation for an ARCH machine. */
1526 static CONST reloc_howto_type
*
1527 elf_hppa_reloc_type_lookup (abfd
, code
)
1529 bfd_reloc_code_real_type code
;
1531 if ((int) code
< (int) R_PARISC_UNIMPLEMENTED
)
1533 BFD_ASSERT ((int) elf_hppa_howto_table
[(int) code
].type
== (int) code
);
1534 return &elf_hppa_howto_table
[(int) code
];
1539 /* Return true if SYM represents a local label symbol. */
1542 hppa_elf_is_local_label (abfd
, sym
)
1546 return (sym
->name
[0] == 'L' && sym
->name
[1] == '$');
1549 /* Do any backend specific processing when beginning to write an object
1550 file. For PA ELF we need to determine the size of the symbol extension
1551 section *before* any other output processing happens. */
1554 elf32_hppa_backend_begin_write_processing (abfd
, info
)
1556 struct bfd_link_info
*info
;
1559 asection
*symextn_sec
;
1561 /* Size up the symbol extension section. */
1562 if ((abfd
->outsymbols
== NULL
1564 || symext_chain_size
!= 0)
1569 /* We were not called from the BFD ELF linker code, so we need
1570 to examine the output BFD's outsymbols.
1572 Note we can not build the symbol extensions now as the symbol
1573 map hasn't been set up. */
1574 for (i
= 0; i
< abfd
->symcount
; i
++)
1576 elf_symbol_type
*symbol
= (elf_symbol_type
*)abfd
->outsymbols
[i
];
1578 /* Only functions ever need an entry in the symbol extension
1580 if (!(symbol
->symbol
.flags
& BSF_FUNCTION
))
1583 /* And only if they specify the locations of their arguments. */
1584 if (symbol
->tc_data
.hppa_arg_reloc
== 0)
1587 /* Yup. This function symbol needs an entry. */
1588 symext_chain_size
+= 2 * sizeof (symext_entryS
);
1591 else if (info
->relocateable
== true)
1593 struct elf32_hppa_args_hash_table
*table
;
1594 table
= elf32_hppa_hash_table (info
)->args_hash_table
;
1596 /* Determine the size of the symbol extension section. */
1597 elf32_hppa_args_hash_traverse (table
,
1598 elf32_hppa_size_symext
,
1599 &symext_chain_size
);
1602 /* Now create the section and set its size. We'll fill in the
1604 symextn_sec
= bfd_get_section_by_name (abfd
, SYMEXTN_SECTION_NAME
);
1605 if (symextn_sec
== NULL
)
1606 symextn_sec
= bfd_make_section (abfd
, SYMEXTN_SECTION_NAME
);
1608 bfd_set_section_flags (abfd
, symextn_sec
,
1609 SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_DATA
);
1610 symextn_sec
->output_section
= symextn_sec
;
1611 symextn_sec
->output_offset
= 0;
1612 bfd_set_section_alignment (abfd
, symextn_sec
, 2);
1613 bfd_set_section_size (abfd
, symextn_sec
, symext_chain_size
);
1616 /* Called for each entry in the args location hash table. For each
1617 entry we bump the size pointer by 2 records (16 bytes). */
1620 elf32_hppa_size_symext (gen_entry
, in_args
)
1621 struct bfd_hash_entry
*gen_entry
;
1624 unsigned int *sizep
= (unsigned int *)in_args
;
1626 *sizep
+= 2 * sizeof (symext_entryS
);
1630 /* Backend routine called by the linker for each output symbol.
1632 For PA ELF we use this opportunity to add an appropriate entry
1633 to the symbol extension chain for function symbols. */
1636 elf32_hppa_link_output_symbol_hook (abfd
, info
, name
, sym
, section
)
1638 struct bfd_link_info
*info
;
1640 Elf_Internal_Sym
*sym
;
1644 unsigned int len
, index
;
1645 struct elf32_hppa_args_hash_table
*args_hash_table
;
1646 struct elf32_hppa_args_hash_entry
*args_hash
;
1648 /* If the args hash table is NULL, then we've encountered an error
1649 of some sorts (for example, an undefined symbol). In that case
1650 we've got nothing else to do.
1652 NOTE: elf_link_output_symbol will abort if we return false here! */
1653 if (elf32_hppa_hash_table (info
)->args_hash_table
== NULL
)
1656 index
= elf32_hppa_hash_table (info
)->output_symbol_count
++;
1658 /* We need to look up this symbol in the args hash table to see if
1659 it has argument relocation bits. */
1660 if (ELF_ST_TYPE (sym
->st_info
) != STT_FUNC
)
1663 /* We know it's a function symbol of some kind. */
1664 len
= strlen (name
) + 1;
1665 if (ELF_ST_BIND (sym
->st_info
) == STB_LOCAL
)
1668 new_name
= malloc (len
);
1669 if (new_name
== NULL
)
1671 bfd_set_error (bfd_error_no_memory
);
1675 strcpy (new_name
, name
);
1676 if (ELF_ST_BIND (sym
->st_info
) == STB_LOCAL
)
1677 sprintf (new_name
+ len
- 10, "_%08x", (int)section
);
1679 /* Now that we have the unique name, we can look it up in the
1681 args_hash_table
= elf32_hppa_hash_table (info
)->args_hash_table
;
1682 args_hash
= elf32_hppa_args_hash_lookup (args_hash_table
, new_name
,
1685 if (args_hash
== NULL
)
1688 /* We know this symbol has arg reloc bits. */
1689 add_entry_to_symext_chain (abfd
, args_hash
->arg_bits
,
1690 index
, &symext_rootP
, &symext_lastP
);
1694 /* Perform any processing needed late in the object file writing process.
1695 For PA ELF we build and set the contents of the symbol extension
1699 elf32_hppa_backend_final_write_processing (abfd
, linker
)
1703 asection
*symextn_sec
;
1704 unsigned int i
, *symtab_map
= (unsigned int *) elf_sym_extra (abfd
);
1706 /* Now build the symbol extension section. */
1707 if (symext_chain_size
== 0)
1712 /* We were not called from the backend linker, so we still need
1713 to build the symbol extension chain.
1715 Look at each symbol, adding the appropriate information to the
1716 symbol extension section list as necessary. */
1717 for (i
= 0; i
< abfd
->symcount
; i
++)
1719 elf_symbol_type
*symbol
= (elf_symbol_type
*) abfd
->outsymbols
[i
];
1721 /* Only functions ever need an entry in the symbol extension
1723 if (!(symbol
->symbol
.flags
& BSF_FUNCTION
))
1726 /* And only if they specify the locations of their arguments. */
1727 if (symbol
->tc_data
.hppa_arg_reloc
== 0)
1730 /* Add this symbol's information to the chain. */
1731 add_entry_to_symext_chain (abfd
, symbol
->tc_data
.hppa_arg_reloc
,
1732 symtab_map
[i
], &symext_rootP
,
1737 /* Now fill in the contents of the symbol extension section. */
1738 elf_hppa_tc_make_sections (abfd
, symext_rootP
);
1740 /* And attach that as the section's contents. */
1741 symextn_sec
= bfd_get_section_by_name (abfd
, SYMEXTN_SECTION_NAME
);
1742 if (symextn_sec
== (asection
*) 0)
1745 symextn_sec
->contents
= (void *)symextn_contents
;
1747 bfd_set_section_contents (abfd
, symextn_sec
, symextn_sec
->contents
,
1748 symextn_sec
->output_offset
, symextn_sec
->_raw_size
);
1751 /* Update the symbol extention chain to include the symbol pointed to
1752 by SYMBOLP if SYMBOLP is a function symbol. Used internally and by GAS. */
1755 add_entry_to_symext_chain (abfd
, arg_reloc
, sym_idx
, symext_root
, symext_last
)
1757 unsigned int arg_reloc
;
1758 unsigned int sym_idx
;
1759 symext_chainS
**symext_root
;
1760 symext_chainS
**symext_last
;
1762 symext_chainS
*symextP
;
1764 /* Allocate memory and initialize this entry. */
1765 symextP
= (symext_chainS
*) bfd_alloc (abfd
, sizeof (symext_chainS
) * 2);
1768 bfd_set_error (bfd_error_no_memory
);
1769 abort(); /* FIXME */
1772 symextP
[0].entry
= ELF32_PARISC_SX_WORD (PARISC_SXT_SYMNDX
, sym_idx
);
1773 symextP
[0].next
= &symextP
[1];
1775 symextP
[1].entry
= ELF32_PARISC_SX_WORD (PARISC_SXT_ARG_RELOC
, arg_reloc
);
1776 symextP
[1].next
= NULL
;
1778 /* Now update the chain itself so it can be walked later to build
1779 the symbol extension section. */
1780 if (*symext_root
== NULL
)
1782 *symext_root
= &symextP
[0];
1783 *symext_last
= &symextP
[1];
1787 (*symext_last
)->next
= &symextP
[0];
1788 *symext_last
= &symextP
[1];
1792 /* Build the symbol extension section. */
1795 elf_hppa_tc_make_sections (abfd
, symext_root
)
1797 symext_chainS
*symext_root
;
1799 symext_chainS
*symextP
;
1801 asection
*symextn_sec
;
1803 symextn_sec
= bfd_get_section_by_name (abfd
, SYMEXTN_SECTION_NAME
);
1805 /* Grab some memory for the contents of the symbol extension section
1807 symextn_contents
= (symext_entryS
*) bfd_zalloc (abfd
,
1808 symextn_sec
->_raw_size
);
1809 if (!symextn_contents
)
1811 bfd_set_error (bfd_error_no_memory
);
1812 abort(); /* FIXME */
1815 /* Fill in the contents of the symbol extension chain. */
1816 for (i
= 0, symextP
= symext_root
; symextP
; symextP
= symextP
->next
, ++i
)
1817 symextn_contents
[i
] = symextP
->entry
;
1822 /* Do some PA ELF specific work after reading in the symbol table.
1823 In particular attach the argument relocation from the
1824 symbol extension section to the appropriate symbols. */
1827 elf32_hppa_backend_symbol_table_processing (abfd
, esyms
,symcnt
)
1829 elf_symbol_type
*esyms
;
1832 Elf32_Internal_Shdr
*symextn_hdr
=
1833 bfd_elf_find_section (abfd
, SYMEXTN_SECTION_NAME
);
1834 unsigned int i
, current_sym_idx
= 0;
1836 /* If no symbol extension existed, then all symbol extension information
1837 is assumed to be zero. */
1838 if (symextn_hdr
== NULL
)
1840 for (i
= 0; i
< symcnt
; i
++)
1841 esyms
[i
].tc_data
.hppa_arg_reloc
= 0;
1845 /* FIXME: Why not use bfd_get_section_contents here? Also should give
1846 memory back when we're done. */
1847 /* Allocate a buffer of the appropriate size for the symextn section. */
1848 symextn_hdr
->contents
= bfd_zalloc(abfd
,symextn_hdr
->sh_size
);
1849 if (!symextn_hdr
->contents
)
1851 bfd_set_error (bfd_error_no_memory
);
1854 symextn_hdr
->size
= symextn_hdr
->sh_size
;
1856 /* Read in the symextn section. */
1857 if (bfd_seek (abfd
, symextn_hdr
->sh_offset
, SEEK_SET
) == -1)
1859 if (bfd_read ((PTR
) symextn_hdr
->contents
, 1, symextn_hdr
->size
, abfd
)
1860 != symextn_hdr
->size
)
1863 /* Parse entries in the symbol extension section, updating the symtab
1865 for (i
= 0; i
< symextn_hdr
->size
/ sizeof(symext_entryS
); i
++)
1867 symext_entryS
*seP
= ((symext_entryS
*)symextn_hdr
->contents
) + i
;
1868 unsigned int se_value
= ELF32_PARISC_SX_VAL (*seP
);
1869 unsigned int se_type
= ELF32_PARISC_SX_TYPE (*seP
);
1873 case PARISC_SXT_NULL
:
1876 case PARISC_SXT_SYMNDX
:
1877 if (se_value
>= symcnt
)
1879 bfd_set_error (bfd_error_bad_value
);
1882 current_sym_idx
= se_value
- 1;
1885 case PARISC_SXT_ARG_RELOC
:
1886 esyms
[current_sym_idx
].tc_data
.hppa_arg_reloc
= se_value
;
1890 bfd_set_error (bfd_error_bad_value
);
1897 /* Read and attach the symbol extension information for the symbols
1898 in INPUT_BFD to the argument location hash table. Handle locals
1899 if DO_LOCALS is true; likewise for globals when DO_GLOBALS is true. */
1902 elf32_hppa_read_symext_info (input_bfd
, symtab_hdr
, args_hash_table
,
1903 local_syms
, do_locals
, do_globals
)
1905 Elf_Internal_Shdr
*symtab_hdr
;
1906 struct elf32_hppa_args_hash_table
*args_hash_table
;
1907 Elf_Internal_Sym
*local_syms
;
1911 asection
*symextn_sec
;
1912 symextn_entry
*contents
;
1913 unsigned int i
, n_entries
, current_index
= 0;
1915 /* Get the symbol extension section for this BFD. If no section exists
1916 then there's nothing to do. Likewise if the section exists, but
1918 symextn_sec
= bfd_get_section_by_name (input_bfd
, SYMEXTN_SECTION_NAME
);
1919 if (symextn_sec
== NULL
)
1922 /* Done separately so we can turn off SEC_HAS_CONTENTS (see below). */
1923 if (symextn_sec
->_raw_size
== 0)
1925 symextn_sec
->flags
&= ~SEC_HAS_CONTENTS
;
1929 contents
= (symextn_entry
*) malloc (symextn_sec
->_raw_size
);
1930 if (contents
== NULL
)
1932 bfd_set_error (bfd_error_no_memory
);
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
/ sizeof (symextn_entry
);
1954 for (i
= 0; i
< n_entries
; i
++)
1956 symextn_entry entry
= contents
[i
];
1957 unsigned int value
= ELF32_PARISC_SX_VAL (entry
);
1958 unsigned int type
= ELF32_PARISC_SX_TYPE (entry
);
1959 struct elf32_hppa_args_hash_entry
*args_hash
;
1963 case PARISC_SXT_NULL
:
1966 case PARISC_SXT_SYMNDX
:
1967 if (value
>= symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
))
1969 bfd_set_error (bfd_error_bad_value
);
1973 current_index
= value
;
1976 case PARISC_SXT_ARG_RELOC
:
1977 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
= 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
= malloc (len
);
1993 if (new_name
== NULL
)
1995 bfd_set_error (bfd_error_no_memory
);
1999 strcpy (new_name
, sym_name
);
2000 sprintf (new_name
+ len
- 10, "_%08x", (int)sym_sec
);
2002 /* This is a global symbol with argument location info.
2003 We need to enter it into the hash table. */
2004 args_hash
= elf32_hppa_args_hash_lookup (args_hash_table
,
2008 if (args_hash
== NULL
)
2013 args_hash
->arg_bits
= value
;
2016 else if (current_index
>= symtab_hdr
->sh_info
2019 struct elf_link_hash_entry
*h
;
2021 current_index
-= symtab_hdr
->sh_info
;
2022 h
= elf_sym_hashes(input_bfd
)[current_index
];
2023 /* This is a global symbol with argument location
2024 information. We need to enter it into the hash table. */
2025 args_hash
= elf32_hppa_args_hash_lookup (args_hash_table
,
2026 h
->root
.root
.string
,
2028 if (args_hash
== NULL
)
2030 bfd_set_error (bfd_error_bad_value
);
2034 args_hash
->arg_bits
= value
;
2041 bfd_set_error (bfd_error_bad_value
);
2050 /* Undo the generic ELF code's subtraction of section->vma from the
2051 value of each external symbol. */
2054 elf32_hppa_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
2056 struct bfd_link_info
*info
;
2057 const Elf_Internal_Sym
*sym
;
2063 *valp
+= (*secp
)->vma
;
2067 /* Determine the name of the stub needed to perform a call assuming the
2068 argument relocation bits for caller and callee are in CALLER and CALLEE
2069 for a call from LOCATION to DESTINATION. Copy the name into STUB_NAME. */
2072 elf32_hppa_name_of_stub (caller
, callee
, location
, destination
, stub_name
)
2073 unsigned int caller
, callee
;
2074 bfd_vma location
, destination
;
2077 arg_reloc_type arg_reloc_types
[5];
2079 if (elf32_hppa_arg_reloc_needed (caller
, callee
, arg_reloc_types
))
2081 arg_reloc_location i
;
2082 /* Fill in the basic template. */
2083 strcpy (stub_name
, "__XX_XX_XX_XX_XX_stub_");
2085 /* Now fix the specifics. */
2086 for (i
= ARG0
; i
<= RET
; i
++)
2087 switch (arg_reloc_types
[i
])
2090 stub_name
[3 * i
+ 2] = 'N';
2091 stub_name
[3 * i
+ 3] = 'O';
2094 stub_name
[3 * i
+ 2] = 'G';
2095 stub_name
[3 * i
+ 3] = 'F';
2098 stub_name
[3 * i
+ 2] = 'F';
2099 stub_name
[3 * i
+ 3] = 'G';
2102 stub_name
[3 * i
+ 2] = 'G';
2103 stub_name
[3 * i
+ 3] = 'D';
2106 stub_name
[3 * i
+ 2] = 'D';
2107 stub_name
[3 * i
+ 3] = 'G';
2112 strcpy (stub_name
, "_____long_branch_stub_");
2115 /* Determine if an argument relocation stub is needed to perform a
2116 call assuming the argument relocation bits for caller and callee
2117 are in CALLER and CALLEE. Place the type of relocations (if any)
2118 into stub_types_p. */
2121 elf32_hppa_arg_reloc_needed (caller
, callee
, stub_types
)
2122 unsigned int caller
, callee
;
2123 arg_reloc_type stub_types
[5];
2125 /* Special case for no relocations. */
2126 if (caller
== 0 || callee
== 0)
2130 arg_location caller_loc
[5];
2131 arg_location callee_loc
[5];
2133 /* Extract the location information for the argument and return
2134 value on both the caller and callee sides. */
2135 caller_loc
[ARG0
] = EXTRACT_ARBITS (caller
, ARG0
);
2136 callee_loc
[ARG0
] = EXTRACT_ARBITS (callee
, ARG0
);
2137 caller_loc
[ARG1
] = EXTRACT_ARBITS (caller
, ARG1
);
2138 callee_loc
[ARG1
] = EXTRACT_ARBITS (callee
, ARG1
);
2139 caller_loc
[ARG2
] = EXTRACT_ARBITS (caller
, ARG2
);
2140 callee_loc
[ARG2
] = EXTRACT_ARBITS (callee
, ARG2
);
2141 caller_loc
[ARG3
] = EXTRACT_ARBITS (caller
, ARG3
);
2142 callee_loc
[ARG3
] = EXTRACT_ARBITS (callee
, ARG3
);
2143 caller_loc
[RET
] = EXTRACT_ARBITS (caller
, RET
);
2144 callee_loc
[RET
] = EXTRACT_ARBITS (callee
, RET
);
2146 /* Check some special combinations. This is necessary to
2147 deal with double precision FP arguments. */
2148 if (caller_loc
[ARG0
] == AR_FU
|| caller_loc
[ARG1
] == AR_FU
)
2150 caller_loc
[ARG0
] = AR_FPDBL1
;
2151 caller_loc
[ARG1
] = AR_NO
;
2153 if (caller_loc
[ARG2
] == AR_FU
|| caller_loc
[ARG3
] == AR_FU
)
2155 caller_loc
[ARG2
] = AR_FPDBL2
;
2156 caller_loc
[ARG3
] = AR_NO
;
2158 if (callee_loc
[ARG0
] == AR_FU
|| callee_loc
[ARG1
] == AR_FU
)
2160 callee_loc
[ARG0
] = AR_FPDBL1
;
2161 callee_loc
[ARG1
] = AR_NO
;
2163 if (callee_loc
[ARG2
] == AR_FU
|| callee_loc
[ARG3
] == AR_FU
)
2165 callee_loc
[ARG2
] = AR_FPDBL2
;
2166 callee_loc
[ARG3
] = AR_NO
;
2169 /* Now look up any relocation needed for each argument and the
2171 stub_types
[ARG0
] = arg_mismatches
[caller_loc
[ARG0
]][callee_loc
[ARG0
]];
2172 stub_types
[ARG1
] = arg_mismatches
[caller_loc
[ARG1
]][callee_loc
[ARG1
]];
2173 stub_types
[ARG2
] = arg_mismatches
[caller_loc
[ARG2
]][callee_loc
[ARG2
]];
2174 stub_types
[ARG3
] = arg_mismatches
[caller_loc
[ARG3
]][callee_loc
[ARG3
]];
2175 stub_types
[RET
] = ret_mismatches
[caller_loc
[RET
]][callee_loc
[RET
]];
2177 return (stub_types
[ARG0
] != NO
2178 || stub_types
[ARG1
] != NO
2179 || stub_types
[ARG2
] != NO
2180 || stub_types
[ARG3
] != NO
2181 || stub_types
[RET
] != NO
);
2185 /* Compute the size of the stub needed to call from LOCATION to DESTINATION
2186 (a function named SYM_NAME), with argument relocation bits CALLER and
2187 CALLEE. Return zero if no stub is needed to perform such a call. */
2190 elf32_hppa_size_of_stub (callee
, caller
, location
, destination
, sym_name
)
2191 unsigned int callee
, caller
;
2192 bfd_vma location
, destination
;
2193 const char *sym_name
;
2195 arg_reloc_type arg_reloc_types
[5];
2197 /* Determine if a long branch or argument relocation stub is needed.
2198 If an argument relocation stub is needed, the relocation will be
2199 stored into arg_reloc_types. */
2200 if (!(((int)(location
- destination
) > 0x3ffff)
2201 || ((int)(location
- destination
) < (int)0xfffc0000)
2202 || elf32_hppa_arg_reloc_needed (caller
, callee
, arg_reloc_types
)))
2205 /* Some kind of stub is needed. Determine how big it needs to be.
2206 First check for argument relocation stubs as they also handle
2207 long calls. Then check for long calls to millicode and finally
2208 the normal long calls. */
2209 if (arg_reloc_types
[ARG0
] != NO
2210 || arg_reloc_types
[ARG1
] != NO
2211 || arg_reloc_types
[ARG2
] != NO
2212 || arg_reloc_types
[ARG3
] != NO
2213 || arg_reloc_types
[RET
] != NO
)
2215 /* Some kind of argument relocation stub is needed. */
2216 unsigned int len
= 16;
2217 arg_reloc_location i
;
2219 /* Each GR or FG relocation takes 2 insns, each GD or DG
2220 relocation takes 3 insns. Plus 4 more insns for the
2221 RP adjustment, ldil & (be | ble) and copy. */
2222 for (i
= ARG0
; i
<= RET
; i
++)
2223 switch (arg_reloc_types
[i
])
2239 /* Extra instructions are needed if we're relocating a return value. */
2240 if (arg_reloc_types
[RET
] != NO
)
2245 else if (!strncmp ("$$", sym_name
, 2)
2246 && strcmp ("$$dyncall", sym_name
))
2252 /* Build one linker stub as defined by the stub hash table entry GEN_ENTRY.
2253 IN_ARGS contains the stub BFD and link info pointers. */
2256 elf32_hppa_build_one_stub (gen_entry
, in_args
)
2257 struct bfd_hash_entry
*gen_entry
;
2260 void **args
= (void **)in_args
;
2261 bfd
*stub_bfd
= (bfd
*)args
[0];
2262 struct bfd_link_info
*info
= (struct bfd_link_info
*)args
[1];
2263 struct elf32_hppa_stub_hash_entry
*entry
;
2264 struct elf32_hppa_stub_hash_table
*stub_hash_table
;
2267 const char *sym_name
;
2269 /* Initialize pointers to the stub hash table, the particular entry we
2270 are building a stub for, and where (in memory) we should place the stub
2272 entry
= (struct elf32_hppa_stub_hash_entry
*)gen_entry
;
2273 stub_hash_table
= elf32_hppa_hash_table(info
)->stub_hash_table
;
2274 loc
= stub_hash_table
->location
;
2276 /* Make a note of the offset within the stubs for this entry. */
2277 entry
->offset
= stub_hash_table
->offset
;
2279 /* The symbol's name starts at offset 22. */
2280 sym_name
= entry
->root
.string
+ 22;
2282 sym_value
= (entry
->target_value
2283 + entry
->target_section
->output_offset
2284 + entry
->target_section
->output_section
->vma
);
2286 if (strncmp ("_____long_branch_stub_", entry
->root
.string
, 22))
2288 /* This must be an argument or return value relocation stub. */
2290 arg_reloc_location i
;
2291 bfd_byte
*begin_loc
= loc
;
2293 /* First the return pointer adjustment. Depending on exact calling
2294 sequence this instruction may be skipped. */
2295 bfd_put_32 (stub_bfd
, LDO_M4_R31_R31
, loc
);
2298 /* If we are relocating a return value, then we're going to have
2299 to return into the stub. So we have to save off the user's
2300 return pointer into the stack at RP'. */
2301 if (strncmp (entry
->root
.string
+ 14, "NO", 2))
2303 bfd_put_32 (stub_bfd
, STW_R31_M8R30
, loc
);
2307 /* Iterate over the argument relocations, emitting instructions
2308 to move them around as necessary. */
2309 for (i
= ARG0
; i
<= ARG3
; i
++)
2311 if (!strncmp (entry
->root
.string
+ 3 * i
+ 2, "GF", 2))
2313 bfd_put_32 (stub_bfd
, STW_ARG_M16R30
| ((26 - i
) << 16), loc
);
2314 bfd_put_32 (stub_bfd
, FLDW_M16R30_FARG
| (4 + i
), loc
+ 4);
2317 else if (!strncmp (entry
->root
.string
+ 3 * i
+ 2, "FG", 2))
2319 bfd_put_32 (stub_bfd
, FSTW_FARG_M16R30
| (4 + i
), loc
);
2320 bfd_put_32 (stub_bfd
, LDW_M16R30_ARG
| ((26 - i
) << 16), loc
+ 4);
2323 else if (!strncmp (entry
->root
.string
+ 3 * i
+ 2, "GD", 2))
2325 bfd_put_32 (stub_bfd
, STW_ARG_M12R30
| ((26 - i
) << 16), loc
);
2326 bfd_put_32 (stub_bfd
, STW_ARG_M16R30
| ((25 - i
) << 16), loc
+ 4);
2327 bfd_put_32 (stub_bfd
, FLDD_M16R30_FARG
| (5 + i
), loc
+ 8);
2330 else if (!strncmp (entry
->root
.string
+ 3 * i
+ 2, "DG", 2))
2332 bfd_put_32 (stub_bfd
, FSTD_FARG_M16R30
| (5 + i
), loc
);
2333 bfd_put_32 (stub_bfd
, LDW_M12R30_ARG
| ((26 - i
) << 16), loc
+ 4);
2334 bfd_put_32 (stub_bfd
, LDW_M16R30_ARG
| ((25 - i
) << 16), loc
+ 8);
2339 /* Load the high bits of the target address into %r1. */
2340 insn
= hppa_rebuild_insn (stub_bfd
, LDIL_R1
,
2341 hppa_field_adjust (sym_value
, 0, e_lrsel
), 21);
2342 bfd_put_32 (stub_bfd
, insn
, loc
);
2345 /* If we are relocating a return value, then we're going to have
2346 to return into the stub, then perform the return value relocation. */
2347 if (strncmp (entry
->root
.string
+ 14, "NO", 2))
2349 /* To return to the stub we "ble" to the target and copy the return
2350 pointer from %r31 into %r2. */
2351 insn
= hppa_rebuild_insn (stub_bfd
,
2353 hppa_field_adjust (sym_value
, 0,
2356 bfd_put_32 (stub_bfd
, insn
, loc
);
2357 bfd_put_32 (stub_bfd
, COPY_R31_R2
, loc
+ 4);
2359 /* Reload the return pointer for our caller from the stack. */
2360 bfd_put_32 (stub_bfd
, LDW_M8R30_R31
, loc
+ 8);
2363 /* Perform the return value relocation. */
2364 if (!strncmp (entry
->root
.string
+ 14, "GF", 2))
2366 bfd_put_32 (stub_bfd
, STW_ARG_M16R30
| (28 << 16), loc
);
2367 bfd_put_32 (stub_bfd
, FLDW_M16R30_FARG
| 4, loc
+ 4);
2370 else if (!strncmp (entry
->root
.string
+ 14, "FG", 2))
2372 bfd_put_32 (stub_bfd
, FSTW_FARG_M16R30
| 4, loc
);
2373 bfd_put_32 (stub_bfd
, LDW_M16R30_ARG
| (28 << 16), loc
+ 4);
2376 else if (!strncmp (entry
->root
.string
+ 2, "GD", 2))
2378 bfd_put_32 (stub_bfd
, STW_ARG_M12R30
| (28 << 16), loc
);
2379 bfd_put_32 (stub_bfd
, STW_ARG_M16R30
| (29 << 16), loc
+ 4);
2380 bfd_put_32 (stub_bfd
, FLDD_M16R30_FARG
| 4, loc
+ 8);
2383 else if (!strncmp (entry
->root
.string
+ 2, "DG", 2))
2385 bfd_put_32 (stub_bfd
, FSTD_FARG_M16R30
| 4, loc
);
2386 bfd_put_32 (stub_bfd
, LDW_M12R30_ARG
| (28 << 16), loc
+ 4);
2387 bfd_put_32 (stub_bfd
, LDW_M16R30_ARG
| (29 << 16), loc
+ 8);
2390 /* Branch back to the user's code now. */
2391 bfd_put_32 (stub_bfd
, BV_N_0_R31
, loc
);
2396 /* No return value relocation, so we can simply "be" to the
2397 target and copy out return pointer into %r2. */
2398 insn
= hppa_rebuild_insn (stub_bfd
, BE_SR4_R1
,
2399 hppa_field_adjust (sym_value
, 0,
2401 bfd_put_32 (stub_bfd
, insn
, loc
);
2402 bfd_put_32 (stub_bfd
, COPY_R31_R2
, loc
+ 4);
2406 /* Update the location and offsets. */
2407 stub_hash_table
->location
+= (loc
- begin_loc
);
2408 stub_hash_table
->offset
+= (loc
- begin_loc
);
2412 /* Create one of two variant long branch stubs. One for $$dyncall and
2413 normal calls, the other for calls to millicode. */
2415 int millicode_call
= 0;
2417 if (!strncmp ("$$", sym_name
, 2) && strcmp ("$$dyncall", sym_name
))
2420 /* First the return pointer adjustment. Depending on exact calling
2421 sequence this instruction may be skipped. */
2422 bfd_put_32 (stub_bfd
, LDO_M4_R31_R31
, loc
);
2424 /* The next two instructions are the long branch itself. A long branch
2425 is formed with "ldil" loading the upper bits of the target address
2426 into a register, then branching with "be" which adds in the lower bits.
2427 Long branches to millicode nullify the delay slot of the "be". */
2428 insn
= hppa_rebuild_insn (stub_bfd
, LDIL_R1
,
2429 hppa_field_adjust (sym_value
, 0, e_lrsel
), 21);
2430 bfd_put_32 (stub_bfd
, insn
, loc
+ 4);
2431 insn
= hppa_rebuild_insn (stub_bfd
, BE_SR4_R1
| (millicode_call
? 2 : 0),
2432 hppa_field_adjust (sym_value
, 0, e_rrsel
) >> 2,
2434 bfd_put_32 (stub_bfd
, insn
, loc
+ 8);
2436 if (!millicode_call
)
2438 /* The sequence to call this stub places the return pointer into %r31,
2439 the final target expects the return pointer in %r2, so copy the
2440 return pointer into the proper register. */
2441 bfd_put_32 (stub_bfd
, COPY_R31_R2
, loc
+ 12);
2443 /* Update the location and offsets. */
2444 stub_hash_table
->location
+= 16;
2445 stub_hash_table
->offset
+= 16;
2449 /* Update the location and offsets. */
2450 stub_hash_table
->location
+= 12;
2451 stub_hash_table
->offset
+= 12;
2458 /* External entry points for sizing and building linker stubs. */
2460 /* Build all the stubs associated with the current output file. The
2461 stubs are kept in a hash table attached to the main linker hash
2462 table. This is called via hppaelf_finish in the linker. */
2465 elf32_hppa_build_stubs (stub_bfd
, info
)
2467 struct bfd_link_info
*info
;
2469 /* The stub BFD only has one section. */
2470 asection
*stub_sec
= stub_bfd
->sections
;
2471 struct elf32_hppa_stub_hash_table
*table
;
2475 /* So we can pass both the BFD for the stubs and the link info
2476 structure to the routine which actually builds stubs. */
2480 /* Allocate memory to hold the linker stubs. */
2481 size
= bfd_section_size (stub_bfd
, stub_sec
);
2482 stub_sec
->contents
= (unsigned char *) bfd_zalloc (stub_bfd
, size
);
2483 if (stub_sec
->contents
== NULL
)
2485 bfd_set_error (bfd_error_no_memory
);
2488 table
= elf32_hppa_hash_table(info
)->stub_hash_table
;
2489 table
->location
= stub_sec
->contents
;
2491 /* Build the stubs as directed by the stub hash table. */
2492 elf32_hppa_stub_hash_traverse (table
, elf32_hppa_build_one_stub
, args
);
2497 /* Determine and set the size of the stub section for a final link.
2499 The basic idea here is to examine all the relocations looking for
2500 PC-relative calls to a target that is unreachable with a "bl"
2501 instruction or calls where the caller and callee disagree on the
2502 location of their arguments or return value. */
2505 elf32_hppa_size_stubs (stub_bfd
, output_bfd
, link_info
)
2508 struct bfd_link_info
*link_info
;
2511 asection
*section
, *stub_sec
;
2512 Elf_Internal_Shdr
*symtab_hdr
;
2513 Elf_Internal_Sym
*local_syms
, *isym
;
2514 Elf32_External_Sym
*ext_syms
, *esym
;
2515 struct elf32_hppa_stub_hash_table
*stub_hash_table
= 0;
2516 struct elf32_hppa_args_hash_table
*args_hash_table
= 0;
2518 /* Create and initialize the stub hash table. */
2519 stub_hash_table
= ((struct elf32_hppa_stub_hash_table
*)
2520 malloc (sizeof (struct elf32_hppa_stub_hash_table
)));
2521 if (!stub_hash_table
)
2523 bfd_set_error (bfd_error_no_memory
);
2527 if (!elf32_hppa_stub_hash_table_init (stub_hash_table
, stub_bfd
,
2528 elf32_hppa_stub_hash_newfunc
))
2531 /* Likewise for the argument location hash table. */
2532 args_hash_table
= ((struct elf32_hppa_args_hash_table
*)
2533 malloc (sizeof (struct elf32_hppa_args_hash_table
)));
2534 if (!args_hash_table
)
2536 bfd_set_error (bfd_error_no_memory
);
2540 if (!elf32_hppa_args_hash_table_init (args_hash_table
,
2541 elf32_hppa_args_hash_newfunc
))
2544 /* Attach the hash tables to the main hash table. */
2545 elf32_hppa_hash_table(link_info
)->stub_hash_table
= stub_hash_table
;
2546 elf32_hppa_hash_table(link_info
)->args_hash_table
= args_hash_table
;
2548 /* Walk over all the input BFDs adding entries to the args hash table
2549 for all the external functions. */
2550 for (input_bfd
= link_info
->input_bfds
;
2552 input_bfd
= input_bfd
->link_next
)
2554 /* We'll need the symbol table in a second. */
2555 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2556 if (symtab_hdr
->sh_info
== 0)
2559 if (elf32_hppa_read_symext_info (input_bfd
, symtab_hdr
, args_hash_table
,
2560 NULL
, false, true) == false)
2564 /* Magic as we know the stub bfd only has one section. */
2565 stub_sec
= stub_bfd
->sections
;
2567 /* Now that we have argument location information for all the global
2568 functions we can start looking for stubs. */
2569 for (input_bfd
= link_info
->input_bfds
;
2571 input_bfd
= input_bfd
->link_next
)
2575 /* We'll need the symbol table in a second. */
2576 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2577 if (symtab_hdr
->sh_info
== 0)
2580 /* We need an array of the local symbols attached to the input bfd.
2581 Unfortunately, we're going to have to read & swap them in. */
2583 = (Elf_Internal_Sym
*)malloc (symtab_hdr
->sh_info
2584 * sizeof (Elf_Internal_Sym
));
2585 if (local_syms
== NULL
)
2587 bfd_set_error (bfd_error_no_memory
);
2592 = (Elf32_External_Sym
*)malloc (symtab_hdr
->sh_info
2593 * sizeof (Elf32_External_Sym
));
2594 if (ext_syms
== NULL
)
2596 bfd_set_error (bfd_error_no_memory
);
2601 if (bfd_seek (input_bfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
2602 || bfd_read (ext_syms
, 1,
2603 (symtab_hdr
->sh_info
2604 * sizeof (Elf32_External_Sym
)), input_bfd
)
2605 != (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
)))
2612 /* Swap the local symbols in. */
2615 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++, esym
++, isym
++)
2616 bfd_elf32_swap_symbol_in (input_bfd
, esym
, isym
);
2618 /* Now we can free the external symbols. */
2621 if (elf32_hppa_read_symext_info (input_bfd
, symtab_hdr
, args_hash_table
,
2622 local_syms
, true, false) == false)
2628 /* If generating a relocateable output file, then we don't
2629 have to examine the relocs. */
2630 if (link_info
->relocateable
)
2636 /* Walk over each section attached to the input bfd. */
2637 for (section
= input_bfd
->sections
;
2639 section
= section
->next
)
2641 Elf_Internal_Shdr
*input_rel_hdr
;
2642 Elf32_External_Rela
*external_relocs
, *erelaend
, *erela
;
2643 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
2645 /* If there aren't any relocs, then there's nothing to do. */
2646 if ((section
->flags
& SEC_RELOC
) == 0
2647 || section
->reloc_count
== 0)
2650 /* Allocate space for the external relocations. */
2652 = (Elf32_External_Rela
*) malloc (section
->reloc_count
* sizeof (Elf32_External_Rela
));
2653 if (external_relocs
== NULL
)
2655 bfd_set_error (bfd_error_no_memory
);
2660 /* Likewise for the internal relocations. */
2662 = (Elf_Internal_Rela
*) malloc (section
->reloc_count
* sizeof (Elf_Internal_Rela
));
2663 if (internal_relocs
== NULL
)
2665 bfd_set_error (bfd_error_no_memory
);
2666 free (external_relocs
);
2671 /* Read in the external relocs. */
2672 input_rel_hdr
= &elf_section_data (section
)->rel_hdr
;
2673 if (bfd_seek (input_bfd
, input_rel_hdr
->sh_offset
, SEEK_SET
) != 0
2674 || bfd_read (external_relocs
, 1, input_rel_hdr
->sh_size
,
2675 input_bfd
) != input_rel_hdr
->sh_size
)
2677 free (external_relocs
);
2678 free (internal_relocs
);
2683 /* Swap in the relocs. */
2684 erela
= external_relocs
;
2685 erelaend
= erela
+ section
->reloc_count
;
2686 irela
= internal_relocs
;
2687 for (; erela
< erelaend
; erela
++, irela
++)
2688 bfd_elf32_swap_reloca_in (input_bfd
, erela
, irela
);
2690 /* We're done with the external relocs, free them. */
2691 free (external_relocs
);
2693 /* Now examine each relocation. */
2694 irela
= internal_relocs
;
2695 irelaend
= irela
+ section
->reloc_count
;
2696 for (; irela
< irelaend
; irela
++)
2698 long r_type
, callee_args
, caller_args
, r_index
, size_of_stub
;
2699 struct elf_link_hash_entry
*hash
;
2700 struct elf32_hppa_stub_hash_entry
*stub_hash
;
2701 struct elf32_hppa_args_hash_entry
*args_hash
;
2702 Elf_Internal_Sym
*sym
;
2704 const char *sym_name
;
2706 bfd_vma location
, destination
;
2707 char *new_name
= NULL
;
2709 r_type
= ELF32_R_TYPE (irela
->r_info
);
2710 r_index
= ELF32_R_SYM (irela
->r_info
);
2712 if (r_type
< 0 || r_type
>= (int) R_PARISC_UNIMPLEMENTED
)
2714 bfd_set_error (bfd_error_bad_value
);
2715 free (internal_relocs
);
2720 /* Only look for stubs on call instructions or plabel
2722 if (r_type
!= R_PARISC_PCREL17F
2723 && r_type
!= R_PARISC_PLABEL32
2724 && r_type
!= R_PARISC_PLABEL21L
2725 && r_type
!= R_PARISC_PLABEL14R
)
2728 /* Now determine the call target, its name, value, section
2729 and argument relocation bits. */
2733 if (r_index
< symtab_hdr
->sh_info
)
2735 /* It's a local symbol. */
2736 Elf_Internal_Shdr
*hdr
;
2738 sym
= local_syms
+ r_index
;
2739 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
2740 sym_sec
= hdr
->bfd_section
;
2741 sym_name
= elf_string_from_elf_section (input_bfd
,
2742 symtab_hdr
->sh_link
,
2744 sym_value
= (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
2745 ? 0 : sym
->st_value
);
2746 destination
= (sym_value
2747 + sym_sec
->output_offset
2748 + sym_sec
->output_section
->vma
);
2750 /* Tack on an ID so we can uniquely identify this local
2751 symbol in the stub or arg info hash tables. */
2752 new_name
= malloc (strlen (sym_name
) + 10);
2755 bfd_set_error (bfd_error_bad_value
);
2756 free (internal_relocs
);
2760 sprintf (new_name
, "%s_%08x", sym_name
, (int)sym_sec
);
2761 sym_name
= new_name
;
2765 /* It's an external symbol. */
2768 index
= r_index
- symtab_hdr
->sh_info
;
2769 hash
= elf_sym_hashes (input_bfd
)[index
];
2770 if (hash
->root
.type
== bfd_link_hash_defined
)
2772 sym_sec
= hash
->root
.u
.def
.section
;
2773 sym_name
= hash
->root
.root
.string
;
2774 sym_value
= hash
->root
.u
.def
.value
;
2775 destination
= (sym_value
2776 + sym_sec
->output_offset
2777 + sym_sec
->output_section
->vma
);
2781 bfd_set_error (bfd_error_bad_value
);
2782 free (internal_relocs
);
2788 args_hash
= elf32_hppa_args_hash_lookup (args_hash_table
,
2789 sym_name
, false, false);
2791 /* Get both caller and callee argument information. */
2792 if (args_hash
== NULL
)
2795 callee_args
= args_hash
->arg_bits
;
2797 /* For calls get the caller's bits from the addend of
2798 the call relocation. For PLABELS the caller's bits
2799 are assumed to have all args & return values in general
2800 registers (0x155). */
2801 if (r_type
== R_PARISC_PCREL17F
)
2802 caller_args
= HPPA_R_ARG_RELOC (irela
->r_addend
);
2804 caller_args
= 0x155;
2806 /* Now determine where the call point is. */
2807 location
= (section
->output_offset
2808 + section
->output_section
->vma
2811 /* We only care about the destination for PCREL function
2812 calls (eg. we don't care for PLABELS). */
2813 if (r_type
!= R_PARISC_PCREL17F
)
2814 location
= destination
;
2816 /* Determine what (if any) linker stub is needed and its
2818 size_of_stub
= elf32_hppa_size_of_stub (callee_args
,
2823 if (size_of_stub
!= 0)
2828 /* Get the name of this stub. */
2829 len
= strlen (sym_name
);
2832 stub_name
= malloc (len
);
2835 bfd_set_error (bfd_error_no_memory
);
2837 /* Because sym_name was mallocd above for local
2839 if (r_index
< symtab_hdr
->sh_info
)
2842 free (internal_relocs
);
2846 elf32_hppa_name_of_stub (caller_args
, callee_args
,
2847 location
, destination
, stub_name
);
2848 strcat (stub_name
+ 22, sym_name
);
2850 /* Because sym_name was malloced above for local symbols. */
2851 if (r_index
< symtab_hdr
->sh_info
)
2855 = elf32_hppa_stub_hash_lookup (stub_hash_table
, stub_name
,
2857 if (stub_hash
!= NULL
)
2859 /* The proper stub has already been created, nothing
2865 bfd_set_section_size (stub_bfd
, stub_sec
,
2866 (bfd_section_size (stub_bfd
,
2870 /* Enter this entry into the linker stub hash table. */
2872 = elf32_hppa_stub_hash_lookup (stub_hash_table
,
2873 stub_name
, true, true);
2874 if (stub_hash
== NULL
)
2876 bfd_set_error (bfd_error_no_memory
);
2878 free (internal_relocs
);
2883 /* We'll need these to determine the address that the
2884 stub will branch to. */
2885 stub_hash
->target_value
= sym_value
;
2886 stub_hash
->target_section
= sym_sec
;
2891 /* We're done with the internal relocs, free them. */
2892 free (internal_relocs
);
2894 /* We're done with the local symbols, free them. */
2900 /* Return gracefully, avoiding dangling references to the hash tables. */
2901 if (stub_hash_table
)
2903 elf32_hppa_hash_table(link_info
)->stub_hash_table
= NULL
;
2904 free (stub_hash_table
);
2906 if (args_hash_table
)
2908 elf32_hppa_hash_table(link_info
)->args_hash_table
= NULL
;
2909 free (args_hash_table
);
2914 /* Misc BFD support code. */
2915 #define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
2916 #define bfd_elf32_bfd_is_local_label hppa_elf_is_local_label
2918 /* Symbol extension stuff. */
2919 #define bfd_elf32_set_section_contents elf32_hppa_set_section_contents
2920 #define elf_backend_symbol_table_processing \
2921 elf32_hppa_backend_symbol_table_processing
2922 #define elf_backend_begin_write_processing \
2923 elf32_hppa_backend_begin_write_processing
2924 #define elf_backend_final_write_processing \
2925 elf32_hppa_backend_final_write_processing
2927 /* Stuff for the BFD linker. */
2928 #define elf_backend_relocate_section elf32_hppa_relocate_section
2929 #define elf_backend_add_symbol_hook elf32_hppa_add_symbol_hook
2930 #define elf_backend_link_output_symbol_hook \
2931 elf32_hppa_link_output_symbol_hook
2932 #define bfd_elf32_bfd_link_hash_table_create \
2933 elf32_hppa_link_hash_table_create
2935 #define TARGET_BIG_SYM bfd_elf32_hppa_vec
2936 #define TARGET_BIG_NAME "elf32-hppa"
2937 #define ELF_ARCH bfd_arch_hppa
2938 #define ELF_MACHINE_CODE EM_PARISC
2939 #define ELF_MAXPAGESIZE 0x1000
2941 #include "elf32-target.h"