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. */
33 /* Note there isn't much error handling code in here yet. Unexpected
34 conditions are handled by just calling abort. FIXME damnit! */
36 /* ELF32/HPPA relocation support
38 This file contains ELF32/HPPA relocation support as specified
39 in the Stratus FTX/Golf Object File Format (SED-1762) dated
42 #include "elf32-hppa.h"
43 #include "aout/aout64.h"
44 #include "hppa_stubs.h"
46 /* The basic stub types supported. If/when shared libraries are
47 implemented some form of IMPORT and EXPORT stubs will be needed. */
55 /* This is a list of all the stubs for a particular BFD. */
57 typedef struct elf32_hppa_stub_name_list_struct
59 /* The symbol associated with this stub. */
61 /* Pointer to chain of all stub chains. */
62 struct elf32_hppa_stub_description_struct
*stub_desc
;
63 /* Pointer to the stub contents (eg instructions). */
65 /* Size of this stub? (in what units? FIXME). */
67 /* Pointer to the next stub entry in the chain. */
68 struct elf32_hppa_stub_name_list_struct
*next
;
69 } elf32_hppa_stub_name_list
;
71 /* This is a linked list in which each entry describes all the
72 linker stubs for a particular bfd. */
74 typedef struct elf32_hppa_stub_description_struct
76 /* The next group of stubs. */
77 struct elf32_hppa_stub_description_struct
*next
;
78 /* Used to identify this group of stubs as belonging
79 to a particular bfd. */
81 /* FIXME: The stub section for this group of stubs? Is
82 this redundant with stub_listP->sym->section? */
84 /* FIXME: what the hell is this? */
85 unsigned relocs_allocated_cnt
;
86 /* The current real size of the stubs (in bytes?). */
88 /* How much space we have allocated for stubs (in bytes?). */
89 unsigned allocated_size
;
90 /* Pointer to the first available space for new stubs. */
92 /* Pointer to the beginning of the stubs. FIXME: Why an int *
93 above and a char * here? */
95 /* The list of stubs for this bfd. */
96 elf32_hppa_stub_name_list
*stub_listP
;
97 /* I guess we just carry this around for fun. */
98 struct bfd_link_info
*link_info
;
99 } elf32_hppa_stub_description
;
103 #define RETURN_VALUE 1
105 /* The various argument relocations that may be performed.
106 Note GRX,GRY really means ARGX,ARGY. */
111 /* Relocate 32 bits from general to FP register. */
113 /* Relocate 64 bits from arg0,arg1 to FParg1. */
115 /* Relocate 64 bits from arg2,arg3 to FParg3. */
117 /* Relocate 32 bits from FP to general register. */
119 /* Relocate 64 bits from FParg1 to arg0,arg1. */
121 /* Relocate 64 bits from FParg3 to arg2,arg3. */
127 /* Where (what register type) is an argument comming from? */
130 /* Not in a register. */
132 /* In a general argument register. */
134 /* In right half of a FP argument register. */
136 /* In upper (left) half of a FP argument register. */
138 /* In general argument register pair 0 (arg0, arg1). */
140 /* In general argument register pair 1 (arg2, arg3). */
144 /* What is being relocated (eg which argument or the return value). */
147 ARG0
, ARG1
, ARG2
, ARG3
, RETVAL
,
148 } arg_reloc_location
;
150 /* Horizontal represents callee's argument location information, vertical
151 represents caller's argument location information. Value at a particular
152 X, Y location represents what (if any) argument relocation needs to
153 be performed to make caller and callee agree. */
154 static CONST arg_reloc_type mismatches
[6][6] =
156 {NO_ARG_RELOC
, NO_ARG_RELOC
, NO_ARG_RELOC
, NO_ARG_RELOC
,
157 NO_ARG_RELOC
, NO_ARG_RELOC
},
158 {NO_ARG_RELOC
, NO_ARG_RELOC
, R_TO_FR
, ARG_RELOC_ERR
,
159 R01_TO_FR
, ARG_RELOC_ERR
},
160 {NO_ARG_RELOC
, FR_TO_R
, NO_ARG_RELOC
, ARG_RELOC_ERR
,
161 ARG_RELOC_ERR
, ARG_RELOC_ERR
},
162 {ARG_RELOC_ERR
, ARG_RELOC_ERR
, ARG_RELOC_ERR
, ARG_RELOC_ERR
,
163 ARG_RELOC_ERR
, ARG_RELOC_ERR
},
164 {NO_ARG_RELOC
, FR_TO_R01
, NO_ARG_RELOC
, ARG_RELOC_ERR
,
165 NO_ARG_RELOC
, ARG_RELOC_ERR
},
166 {NO_ARG_RELOC
, FR_TO_R23
, NO_ARG_RELOC
, ARG_RELOC_ERR
,
167 ARG_RELOC_ERR
, NO_ARG_RELOC
},
170 /* Likewise for the return value. */
171 static CONST arg_reloc_type retval_mismatches
[6][6] =
173 {NO_ARG_RELOC
, NO_ARG_RELOC
, NO_ARG_RELOC
, NO_ARG_RELOC
,
174 NO_ARG_RELOC
, NO_ARG_RELOC
},
175 {NO_ARG_RELOC
, NO_ARG_RELOC
, FR_TO_R
, ARG_RELOC_ERR
,
176 FR_TO_R01
, ARG_RELOC_ERR
},
177 {NO_ARG_RELOC
, R_TO_FR
, NO_ARG_RELOC
, ARG_RELOC_ERR
,
178 ARG_RELOC_ERR
, ARG_RELOC_ERR
},
179 {ARG_RELOC_ERR
, ARG_RELOC_ERR
, ARG_RELOC_ERR
, ARG_RELOC_ERR
,
180 ARG_RELOC_ERR
, ARG_RELOC_ERR
},
181 {NO_ARG_RELOC
, R01_TO_FR
, NO_ARG_RELOC
, ARG_RELOC_ERR
,
182 NO_ARG_RELOC
, ARG_RELOC_ERR
},
183 {NO_ARG_RELOC
, R23_TO_FR
, NO_ARG_RELOC
, ARG_RELOC_ERR
,
184 ARG_RELOC_ERR
, NO_ARG_RELOC
},
187 /* Used for index mapping in symbol-extension sections. */
188 struct elf32_hppa_symextn_map_struct
196 static bfd_reloc_status_type hppa_elf_reloc
197 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
199 static unsigned long hppa_elf_relocate_insn
200 PARAMS ((bfd
*, asection
*, unsigned long, unsigned long, long,
201 long, unsigned long, unsigned long, unsigned long));
203 static long get_symbol_value
PARAMS ((asymbol
*));
205 static bfd_reloc_status_type hppa_elf_reloc
206 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
208 static CONST reloc_howto_type
* elf_hppa_reloc_type_lookup
209 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
211 static symext_entryS elf32_hppa_get_sym_extn
PARAMS ((bfd
*, asymbol
*, int));
213 static elf32_hppa_stub_description
* find_stubs
PARAMS ((bfd
*, asection
*));
215 static elf32_hppa_stub_description
* new_stub
216 PARAMS ((bfd
*, asection
*, struct bfd_link_info
*));
218 static arg_reloc_type type_of_mismatch
PARAMS ((int, int, int));
220 static elf32_hppa_stub_name_list
* find_stub_by_name
221 PARAMS ((bfd
*, asection
*, char *));
223 static elf32_hppa_stub_name_list
* add_stub_by_name
224 PARAMS ((bfd
*, asection
*, asymbol
*, struct bfd_link_info
*));
226 static void hppa_elf_stub_finish
PARAMS ((bfd
*));
228 static void hppa_elf_stub_reloc
229 PARAMS ((elf32_hppa_stub_description
*, bfd
*, asymbol
**, int,
230 elf32_hppa_reloc_type
));
232 static int hppa_elf_arg_reloc_needed_p
233 PARAMS ((bfd
*, arelent
*, arg_reloc_type
[5], symext_entryS
));
235 static asymbol
* hppa_elf_build_linker_stub
236 PARAMS ((bfd
*, bfd
*, struct bfd_link_info
*, arelent
*,
237 arg_reloc_type
[5], int, unsigned *, hppa_stub_type
));
239 static void hppa_elf_create_stub_sec
240 PARAMS ((bfd
*, bfd
*, asection
**, struct bfd_link_info
*));
242 static int hppa_elf_long_branch_needed_p
243 PARAMS ((bfd
*, asection
*, arelent
*, asymbol
*, unsigned));
245 static boolean hppa_elf_set_section_contents
246 PARAMS ((bfd
*, sec_ptr
, PTR
, file_ptr
, bfd_size_type
));
248 static void elf_info_to_howto
249 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rela
*));
251 static void elf32_hppa_backend_symbol_processing
PARAMS ((bfd
*, asymbol
*));
253 static boolean elf32_hppa_backend_section_processing
254 PARAMS ((bfd
*, Elf32_Internal_Shdr
*));
256 static boolean elf32_hppa_backend_symbol_table_processing
257 PARAMS ((bfd
*, elf_symbol_type
*, int));
259 static boolean elf32_hppa_backend_section_from_shdr
260 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, char *));
262 static boolean elf32_hppa_backend_fake_sections
263 PARAMS ((bfd
*, Elf_Internal_Shdr
*, asection
*));
265 static boolean elf32_hppa_backend_section_from_bfd_section
266 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, asection
*, int *));
268 static void elf32_hppa_backend_begin_write_processing
PARAMS ((bfd
*));
270 static void elf32_hppa_backend_final_write_processing
PARAMS ((bfd
*));
272 static void add_entry_to_symext_chain
273 PARAMS ((bfd
*, elf_symbol_type
*, int, symext_chainS
**, symext_chainS
**));
276 elf_hppa_tc_make_sections
PARAMS ((bfd
*, symext_chainS
*));
278 static boolean hppa_elf_is_local_label
PARAMS ((bfd
*, asymbol
*));
280 /* ELF/PA relocation howto entries. */
282 static reloc_howto_type elf_hppa_howto_table
[ELF_HOWTO_TABLE_SIZE
] =
284 {R_PARISC_NONE
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_NONE"},
285 {R_PARISC_DIR32
, 0, 0, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DIR32"},
286 {R_PARISC_DIR21L
, 0, 0, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DIR21L"},
287 {R_PARISC_DIR17R
, 0, 0, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DIR17R"},
288 {R_PARISC_DIR17F
, 0, 0, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DIR17F"},
289 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
290 {R_PARISC_DIR14R
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DIR14R"},
291 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
293 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
294 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
295 {R_PARISC_PCREL21L
, 0, 0, 21, true, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PCREL21L"},
296 {R_PARISC_PCREL17R
, 0, 0, 17, true, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PCREL17R"},
297 {R_PARISC_PCREL17F
, 0, 0, 17, true, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PCREL17F"},
298 {R_PARISC_PCREL17C
, 0, 0, 17, true, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PCREL17C"},
299 {R_PARISC_PCREL14R
, 0, 0, 14, true, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PCREL14R"},
300 {R_PARISC_PCREL14F
, 0, 0, 14, true, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PCREL14F"},
302 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
303 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
304 {R_PARISC_DPREL21L
, 0, 0, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DPREL21L"},
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_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
308 {R_PARISC_DPREL14R
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DPREL14R"},
309 {R_PARISC_DPREL14F
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DPREL14F"},
311 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
312 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
313 {R_PARISC_DLTREL21L
, 0, 0, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DLTREL21L"},
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_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
317 {R_PARISC_DLTREL14R
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DLTREL14R"},
318 {R_PARISC_DLTREL14F
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DLTREL14F"},
320 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
321 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
322 {R_PARISC_DLTIND21L
, 0, 0, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DLTIND21L"},
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_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
326 {R_PARISC_DLTIND14R
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DLTIND14R"},
327 {R_PARISC_DLTIND14F
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_DLTIND14F"},
329 {R_PARISC_SETBASE
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_SETBASE"},
330 {R_PARISC_BASEREL32
, 0, 0, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_BASEREL32"},
331 {R_PARISC_BASEREL21L
, 0, 0, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_BASEREL21L"},
332 {R_PARISC_BASEREL17R
, 0, 0, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_BASEREL17R"},
333 {R_PARISC_BASEREL17F
, 0, 0, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_BASEREL17F"},
334 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
335 {R_PARISC_BASEREL14R
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_BASEREL14R"},
336 {R_PARISC_BASEREL14F
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_BASEREL14F"},
338 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
339 {R_PARISC_TEXTREL32
, 0, 0, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_TEXTREL32"},
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_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
344 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
345 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
347 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
348 {R_PARISC_DATAREL32
, 0, 0, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
349 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
350 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
351 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
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"},
357 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
358 {R_PARISC_PLABEL32
, 0, 0, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PLABEL32"},
359 {R_PARISC_PLABEL21L
, 0, 0, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PLABEL21L"},
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"},
363 {R_PARISC_PLABEL14R
, 0, 0, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PLABEL14R"},
364 {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"},
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"},
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"},
375 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
376 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_UNIMPLEMENTED"},
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_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"},
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"},
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_PLTIND21L
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PLTIND21L"},
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_PLTIND14R
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PLTIND14R"},
434 {R_PARISC_PLTIND14F
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_PLTIND14F"},
437 {R_PARISC_COPY
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_COPY"},
438 {R_PARISC_GLOB_DAT
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_GLOB_DAT"},
439 {R_PARISC_JMP_SLOT
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_JMP_SLOT"},
440 {R_PARISC_RELATIVE
, 0, 0, 0, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_RELATIVE"},
441 {R_PARISC_STUB_CALL_17
, 0, 0, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_PARISC_STUB_CALL_17"},
443 {R_PARISC_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_dont
, NULL
, "R_PARISC_UNIMPLEMENTED"},
446 static symext_chainS
*symext_rootP
;
447 static symext_chainS
*symext_lastP
;
448 static int symext_chain_size
;
449 static long global_value
;
450 static long GOT_value
;
451 static asymbol
*global_symbol
;
452 static int global_sym_defined
;
453 static symext_entryS
*symextn_contents
;
454 static elf32_hppa_stub_description
*elf_hppa_stub_rootP
;
455 static boolean stubs_finished
= false;
456 static struct elf32_hppa_symextn_map_struct
*elf32_hppa_symextn_map
;
457 static int elf32_hppa_symextn_map_size
;
459 static char *linker_stubs
= NULL
;
460 static int linker_stubs_size
= 0;
461 static int linker_stubs_max_size
= 0;
462 #define STUB_ALLOC_INCR 100
463 #define STUB_SYM_BUFFER_INC 5
465 /* Relocate the given INSN given the various input parameters.
467 FIXME: endianness and sizeof (long) issues abound here. */
470 hppa_elf_relocate_insn (abfd
, input_sect
, insn
, address
, sym_value
,
471 r_addend
, r_format
, r_field
, pcrel
)
473 asection
*input_sect
;
475 unsigned long address
;
478 unsigned long r_format
;
479 unsigned long r_field
;
482 unsigned char opcode
= get_opcode (insn
);
503 constant_value
= HPPA_R_CONSTANT (r_addend
);
506 sym_value
-= address
;
508 sym_value
= hppa_field_adjust (sym_value
, constant_value
, r_field
);
509 return hppa_rebuild_insn (abfd
, insn
, sym_value
, r_format
);
514 arg_reloc
= HPPA_R_ARG_RELOC (r_addend
);
516 /* XXX computing constant_value is not needed??? */
517 constant_value
= assemble_17 ((insn
& 0x001f0000) >> 16,
518 (insn
& 0x00001ffc) >> 2,
521 constant_value
= (constant_value
<< 15) >> 15;
525 address
+ input_sect
->output_offset
526 + input_sect
->output_section
->vma
;
527 sym_value
= hppa_field_adjust (sym_value
, -8, r_field
);
530 sym_value
= hppa_field_adjust (sym_value
, constant_value
, r_field
);
532 return hppa_rebuild_insn (abfd
, insn
, sym_value
>> 2, r_format
);
537 constant_value
= HPPA_R_CONSTANT (r_addend
);
540 sym_value
-= address
;
542 return hppa_field_adjust (sym_value
, constant_value
, r_field
);
549 /* Return the relocated value of the given symbol. */
552 get_symbol_value (symbol
)
556 || symbol
->section
== &bfd_com_section
)
559 return symbol
->value
+ symbol
->section
->output_section
->vma
560 + symbol
->section
->output_offset
;
563 /* Return one (or more) BFD relocations which implement the base
564 relocation with modifications based on format and field. */
566 elf32_hppa_reloc_type
**
567 hppa_elf_gen_reloc_type (abfd
, base_type
, format
, field
)
569 elf32_hppa_reloc_type base_type
;
573 elf32_hppa_reloc_type
*finaltype
;
574 elf32_hppa_reloc_type
**final_types
;
576 /* Allocate slots for the BFD relocation. */
577 final_types
= (elf32_hppa_reloc_type
**)
578 bfd_alloc_by_size_t (abfd
, sizeof (elf32_hppa_reloc_type
*) * 2);
579 BFD_ASSERT (final_types
!= 0); /* FIXME */
581 /* Allocate space for the relocation itself. */
582 finaltype
= (elf32_hppa_reloc_type
*)
583 bfd_alloc_by_size_t (abfd
, sizeof (elf32_hppa_reloc_type
));
584 BFD_ASSERT (finaltype
!= 0); /* FIXME */
586 /* Some reasonable defaults. */
587 final_types
[0] = finaltype
;
588 final_types
[1] = NULL
;
590 #define final_type finaltype[0]
592 final_type
= base_type
;
594 /* Just a tangle of nested switch statements to deal with the braindamage
595 that a different field selector means a completely different relocation
607 final_type
= R_PARISC_DIR14R
;
610 final_type
= R_PARISC_DLTREL14R
;
613 final_type
= R_PARISC_DLTREL14F
;
616 final_type
= R_PARISC_PLABEL14R
;
628 final_type
= R_PARISC_DIR17F
;
632 final_type
= R_PARISC_DIR17R
;
645 final_type
= R_PARISC_DIR21L
;
648 final_type
= R_PARISC_DLTREL21L
;
651 final_type
= R_PARISC_PLABEL21L
;
663 final_type
= R_PARISC_DIR32
;
666 final_type
= R_PARISC_PLABEL32
;
689 final_type
= R_PARISC_DPREL14R
;
692 final_type
= R_PARISC_DPREL14F
;
705 final_type
= R_PARISC_DPREL21L
;
720 case R_HPPA_PCREL_CALL
:
728 final_type
= R_PARISC_PCREL14R
;
731 final_type
= R_PARISC_PCREL14F
;
744 final_type
= R_PARISC_PCREL17R
;
747 final_type
= R_PARISC_PCREL17F
;
760 final_type
= R_PARISC_PCREL21L
;
785 /* Actually perform a relocation. */
787 static bfd_reloc_status_type
788 hppa_elf_reloc (abfd
, reloc_entry
, symbol_in
, data
, input_section
, output_bfd
,
791 arelent
*reloc_entry
;
794 asection
*input_section
;
796 char **error_message
;
800 unsigned long addr
= reloc_entry
->address
;
801 bfd_byte
*hit_data
= addr
+ (bfd_byte
*) data
;
802 unsigned long r_type
= reloc_entry
->howto
->type
;
803 unsigned long r_field
= e_fsel
;
804 boolean r_pcrel
= reloc_entry
->howto
->pc_relative
;
805 unsigned r_format
= reloc_entry
->howto
->bitsize
;
806 long r_addend
= reloc_entry
->addend
;
808 /* If only performing a partial link, get out early. */
811 reloc_entry
->address
+= input_section
->output_offset
;
813 /* Work around lossage in generic elf code to write relocations.
814 (maps different section symbols into the same symbol index). */
815 if ((symbol_in
->flags
& BSF_SECTION_SYM
)
816 && symbol_in
->section
)
817 reloc_entry
->addend
+= symbol_in
->section
->output_offset
;
821 /* If performing final link and the symbol we're relocating against
822 is undefined, then return an error. */
823 if (symbol_in
&& symbol_in
->section
== &bfd_und_section
)
824 return bfd_reloc_undefined
;
826 /* Get the final relocated value. */
827 sym_value
= get_symbol_value (symbol_in
);
829 /* Compute the value of $global$.
830 FIXME: None of this should be necessary. $global$ is just a
831 marker and shouldn't really figure into these computations.
833 Once that's fixed we'll need to teach this backend to change
834 DP-relative relocations involving symbols in the text section
835 to be simple absolute relocations. */
836 if (!global_sym_defined
)
840 global_value
= (global_symbol
->value
841 + global_symbol
->section
->output_section
->vma
842 + global_symbol
->section
->output_offset
);
843 GOT_value
= global_value
;
844 global_sym_defined
++;
848 /* Get the instruction word. */
849 insn
= bfd_get_32 (abfd
, hit_data
);
857 case R_PARISC_DIR17F
:
858 case R_PARISC_PCREL17F
:
859 case R_PARISC_PCREL17C
:
860 case R_PARISC_PLABEL32
:
861 case R_PARISC_PCREL14F
:
863 goto do_basic_type_1
;
864 case R_PARISC_DIR21L
:
865 case R_PARISC_PCREL21L
:
866 case R_PARISC_PLABEL21L
:
868 goto do_basic_type_1
;
869 case R_PARISC_DIR17R
:
870 case R_PARISC_PCREL17R
:
871 case R_PARISC_DIR14R
:
872 case R_PARISC_PCREL14R
:
873 case R_PARISC_PLABEL14R
:
875 goto do_basic_type_1
;
877 case R_PARISC_DPREL21L
:
879 sym_value
-= GOT_value
;
880 goto do_basic_type_1
;
881 case R_PARISC_DPREL14R
:
883 sym_value
-= GOT_value
;
884 goto do_basic_type_1
;
885 case R_PARISC_DPREL14F
:
887 sym_value
-= GOT_value
;
888 goto do_basic_type_1
;
892 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
, addr
,
893 sym_value
, r_addend
, r_format
,
898 /* This is a linker internal relocation. */
899 case R_PARISC_STUB_CALL_17
:
900 /* This relocation is for a branch to a long branch stub.
901 Change instruction to a BLE,N. It may also be necessary
902 to interchange the branch and its delay slot.
903 The original instruction stream is
905 bl <foo>,r ; call foo using register r as
907 XXX ; delay slot instruction
909 The new instruction stream will be:
911 XXX ; delay slot instruction
912 ble <foo_stub> ; call the long call stub for foo
913 ; using r31 as the return pointer
915 This braindamage is necessary because the compiler may put
916 an instruction which uses %r31 in the delay slot of the original
917 call. By changing the call instruction from a "bl" to a "ble"
918 %r31 gets clobbered before the delay slot executes. This
919 also means the stub has to play funny games to make sure
920 we return to the instruction just after the BLE rather than
921 two instructions after the BLE.
923 We do not interchange the branch and delay slot if the delay
924 slot was already nullified, or if the instruction in the delay
925 slot modifies the return pointer to avoid an unconditional
926 jump after the call returns (GCC optimization).
928 None of this horseshit would be necessary if we put the
929 stubs between functions and just redirected the "bl" to
930 the stub. Live and learn. */
932 /* Is this instruction nullified? (does this ever happen?) */
935 insn
= BLE_N_XXX_0_0
;
936 bfd_put_32 (abfd
, insn
, hit_data
);
937 r_type
= R_PARISC_DIR17F
;
939 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
940 addr
, sym_value
, r_addend
,
941 r_format
, r_field
, r_pcrel
);
945 /* So much for the trivial case... */
946 unsigned long old_delay_slot_insn
= bfd_get_32 (abfd
, hit_data
+ 4);
947 unsigned rtn_reg
= (insn
& 0x03e00000) >> 21;
949 if (get_opcode (old_delay_slot_insn
) == LDO
)
951 unsigned ldo_src_reg
= (old_delay_slot_insn
& 0x03e00000) >> 21;
952 unsigned ldo_target_reg
= (old_delay_slot_insn
& 0x001f0000) >> 16;
954 /* If the target of the LDO is the same as the return
955 register then there is no reordering. We can leave the
956 instuction as a non-nullified BLE in this case.
958 FIXME: This test looks wrong. If we had a ble using
959 ldo_target_reg as the *source* we'd fuck this up. */
960 if (ldo_target_reg
== rtn_reg
)
962 unsigned long new_delay_slot_insn
= old_delay_slot_insn
;
964 BFD_ASSERT (ldo_src_reg
== ldo_target_reg
);
965 new_delay_slot_insn
&= 0xfc00ffff;
966 new_delay_slot_insn
|= ((31 << 21) | (31 << 16));
967 bfd_put_32 (abfd
, new_delay_slot_insn
, hit_data
+ 4);
969 r_type
= R_PARISC_DIR17F
;
971 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
972 addr
, sym_value
, r_addend
,
973 r_format
, r_field
, r_pcrel
);
974 bfd_put_32 (abfd
, insn
, hit_data
);
977 else if (rtn_reg
== 31)
979 /* The return register is r31, so this is a millicode
980 call. Do not perform any instruction reordering. */
982 r_type
= R_PARISC_DIR17F
;
984 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
988 bfd_put_32 (abfd
, insn
, hit_data
);
993 /* Check to see if the delay slot instruction has a
994 relocation. If so, we need to change the address
995 field of it because the instruction it relocates
996 is going to be moved. Oh what a mess. */
997 arelent
* next_reloc_entry
= reloc_entry
+1;
999 if (next_reloc_entry
->address
== reloc_entry
->address
+ 4)
1000 next_reloc_entry
->address
-= 4;
1002 insn
= old_delay_slot_insn
;
1003 bfd_put_32 (abfd
, insn
, hit_data
);
1004 insn
= BLE_N_XXX_0_0
;
1005 bfd_put_32 (abfd
, insn
, hit_data
+ 4);
1006 r_type
= R_PARISC_DIR17F
;
1008 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1010 sym_value
, r_addend
,
1011 r_format
, r_field
, r_pcrel
);
1012 bfd_put_32 (abfd
, insn
, hit_data
+ 4);
1013 return bfd_reloc_ok
;
1016 /* Same comments as above regarding incorrect test. */
1017 else if (rtn_reg
== 31)
1019 /* The return register is r31, so this is a millicode call.
1020 Perform no instruction reordering in this case. */
1022 r_type
= R_PARISC_DIR17F
;
1024 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1028 bfd_put_32 (abfd
, insn
, hit_data
);
1029 return bfd_reloc_ok
;
1033 /* Check to see if the delay slot instruction has a
1034 relocation. If so, we need to change its address
1035 field because the instruction it relocates is going
1037 arelent
* next_reloc_entry
= reloc_entry
+1;
1039 if (next_reloc_entry
->address
== reloc_entry
->address
+ 4)
1040 next_reloc_entry
->address
-= 4;
1042 insn
= old_delay_slot_insn
;
1043 bfd_put_32 (abfd
, insn
, hit_data
);
1044 insn
= BLE_N_XXX_0_0
;
1045 bfd_put_32 (abfd
, insn
, hit_data
+ 4);
1046 r_type
= R_PARISC_DIR17F
;
1048 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1049 addr
+ 4, sym_value
,
1052 bfd_put_32 (abfd
, insn
, hit_data
+ 4);
1053 return bfd_reloc_ok
;
1058 /* Something we don't know how to handle. */
1060 *error_message
= (char *) "Unrecognized reloc";
1061 return bfd_reloc_notsupported
;
1064 /* Update the instruction word. */
1065 bfd_put_32 (abfd
, insn
, hit_data
);
1066 return (bfd_reloc_ok
);
1069 /* Return the address of the howto table entry to perform the CODE
1070 relocation for an ARCH machine. */
1072 static CONST reloc_howto_type
*
1073 elf_hppa_reloc_type_lookup (abfd
, code
)
1075 bfd_reloc_code_real_type code
;
1077 if ((int) code
< (int) R_PARISC_UNIMPLEMENTED
)
1079 BFD_ASSERT ((int) elf_hppa_howto_table
[(int) code
].type
== (int) code
);
1080 return &elf_hppa_howto_table
[(int) code
];
1085 /* Return true if SYM represents a local label symbol. */
1088 hppa_elf_is_local_label (abfd
, sym
)
1092 return (sym
->name
[0] == 'L' && sym
->name
[1] == '$');
1095 /* Do any backend specific processing when beginning to write an object
1096 file. For PA ELF we need to determine the size of the symbol extension
1097 section *before* any other output processing happens. */
1100 elf32_hppa_backend_begin_write_processing (abfd
)
1104 asection
*symextn_sec
;
1106 /* Size up the symbol extension section. We can't built it just
1107 yet as the elf_symbol_map hasn't been built. */
1108 if (abfd
->outsymbols
== NULL
|| symext_chain_size
!= 0)
1111 /* Look at each symbol, and determine if it will need an entry in
1112 the symbol extension section. */
1113 for (i
= 0; i
< abfd
->symcount
; i
++)
1115 elf_symbol_type
*symbol
= (elf_symbol_type
*)abfd
->outsymbols
[i
];
1117 /* Only functions ever need an entry in the symbol extension
1119 if (!(symbol
->symbol
.flags
& BSF_FUNCTION
))
1122 /* And only if they specify the locations of their arguments. */
1123 if (symbol
->tc_data
.hppa_arg_reloc
== 0)
1126 /* Yup. This function symbol needs an entry. */
1127 symext_chain_size
+= 2 * sizeof (symext_entryS
);
1130 /* Now create the section and set its size. We'll fill in the
1132 symextn_sec
= bfd_get_section_by_name (abfd
, SYMEXTN_SECTION_NAME
);
1133 if (symextn_sec
== NULL
)
1135 symextn_sec
= bfd_make_section (abfd
, SYMEXTN_SECTION_NAME
);
1136 bfd_set_section_flags (abfd
, symextn_sec
,
1137 SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_DATA
);
1138 symextn_sec
->output_section
= symextn_sec
;
1139 symextn_sec
->output_offset
= 0;
1140 bfd_set_section_alignment (abfd
, symextn_sec
, 2);
1141 bfd_set_section_size (abfd
, symextn_sec
, symext_chain_size
);
1146 /* Perform any processing needed late in the object file writing process.
1147 For PA ELF we build and set the contents of the symbol extension
1151 elf32_hppa_backend_final_write_processing (abfd
)
1154 asection
*symextn_sec
;
1155 int i
, *symtab_map
= (int *) elf_sym_extra (abfd
);
1157 /* Now build the symbol extension section. */
1158 if (symext_chain_size
== 0)
1161 /* Look at each symbol, adding the appropriate information to the
1162 symbol extension section list as necessary. */
1163 for (i
= 0; i
< abfd
->symcount
; i
++)
1165 elf_symbol_type
*symbol
= (elf_symbol_type
*) abfd
->outsymbols
[i
];
1167 /* Only functions ever need an entry in the symbol extension
1169 if (!(symbol
->symbol
.flags
& BSF_FUNCTION
))
1172 /* And only if they specify the locations of their arguments. */
1173 if (symbol
->tc_data
.hppa_arg_reloc
== 0)
1176 /* Add this symbol's information to the chain. */
1177 add_entry_to_symext_chain (abfd
, symbol
, symtab_map
[i
],
1178 &symext_rootP
, &symext_lastP
);
1181 /* Now fill in the contents of the symbol extension chain. */
1182 elf_hppa_tc_make_sections (abfd
, symext_rootP
);
1184 /* And attach that as the section's contents. */
1185 symextn_sec
= bfd_get_section_by_name (abfd
, SYMEXTN_SECTION_NAME
);
1186 if (symextn_sec
== (asection
*) 0)
1189 symextn_sec
->contents
= (void *)symextn_contents
;
1191 bfd_set_section_contents (abfd
, symextn_sec
, symextn_sec
->contents
,
1192 symextn_sec
->output_offset
, symextn_sec
->_raw_size
);
1195 /* Update the symbol extention chain to include the symbol pointed to
1196 by SYMBOLP if SYMBOLP is a function symbol. Used internally and by GAS. */
1199 add_entry_to_symext_chain (abfd
, symbol
, sym_idx
, symext_root
, symext_last
)
1201 elf_symbol_type
*symbol
;
1203 symext_chainS
**symext_root
;
1204 symext_chainS
**symext_last
;
1206 symext_chainS
*symextP
;
1207 unsigned int arg_reloc
= symbol
->tc_data
.hppa_arg_reloc
;
1209 /* Allocate memory and initialize this entry. */
1210 symextP
= (symext_chainS
*) bfd_alloc (abfd
, sizeof (symext_chainS
) * 2);
1213 bfd_set_error (bfd_error_no_memory
);
1214 abort(); /* FIXME */
1217 symextP
[0].entry
= ELF32_PARISC_SX_WORD (PARISC_SXT_SYMNDX
, sym_idx
);
1218 symextP
[0].next
= &symextP
[1];
1220 symextP
[1].entry
= ELF32_PARISC_SX_WORD (PARISC_SXT_ARG_RELOC
, arg_reloc
);
1221 symextP
[1].next
= NULL
;
1223 /* Now update the chain itself so it can be walked later to build
1224 the symbol extension section. */
1225 if (*symext_root
== NULL
)
1227 *symext_root
= &symextP
[0];
1228 *symext_last
= &symextP
[1];
1232 (*symext_last
)->next
= &symextP
[0];
1233 *symext_last
= &symextP
[1];
1237 /* Build the symbol extension section. Used internally and by GAS. */
1240 elf_hppa_tc_make_sections (abfd
, symext_root
)
1242 symext_chainS
*symext_root
;
1244 symext_chainS
*symextP
;
1246 asection
*symextn_sec
;
1248 /* FIXME: Huh? I don't see what this is supposed to do for us. */
1249 hppa_elf_stub_finish (abfd
);
1251 symextn_sec
= bfd_get_section_by_name (abfd
, SYMEXTN_SECTION_NAME
);
1253 /* Grab some memory for the contents of the symbol extension section
1255 symextn_contents
= (symext_entryS
*) bfd_zalloc (abfd
,
1256 symextn_sec
->_raw_size
);
1257 if (!symextn_contents
)
1259 bfd_set_error (bfd_error_no_memory
);
1260 abort(); /* FIXME */
1263 /* Fill in the contents of the symbol extension chain. */
1264 for (i
= 0, symextP
= symext_root
; symextP
; symextP
= symextP
->next
, ++i
)
1265 symextn_contents
[i
] = symextP
->entry
;
1270 /* Return the symbol extension record of type TYPE for the symbol SYM. */
1272 static symext_entryS
1273 elf32_hppa_get_sym_extn (abfd
, sym
, type
)
1280 case PARISC_SXT_SYMNDX
:
1281 case PARISC_SXT_NULL
:
1282 return (symext_entryS
) 0;
1283 case PARISC_SXT_ARG_RELOC
:
1285 elf_symbol_type
*esymP
= (elf_symbol_type
*) sym
;
1287 return (symext_entryS
) esymP
->tc_data
.hppa_arg_reloc
;
1289 /* This should never happen. */
1295 /* Search the chain of stub descriptions and locate the stub
1296 description for this the given section within the given bfd.
1298 FIXME: I see yet another wonderful linear linked list search
1299 here. This is probably bad. */
1301 static elf32_hppa_stub_description
*
1302 find_stubs (abfd
, stub_sec
)
1306 elf32_hppa_stub_description
*stubP
;
1308 for (stubP
= elf_hppa_stub_rootP
; stubP
; stubP
= stubP
->next
)
1310 /* Is this the right one? */
1311 if (stubP
->this_bfd
== abfd
&& stubP
->stub_sec
== stub_sec
)
1317 static elf32_hppa_stub_description
*
1318 new_stub (abfd
, stub_sec
, link_info
)
1321 struct bfd_link_info
*link_info
;
1323 elf32_hppa_stub_description
*stub
= find_stubs (abfd
, stub_sec
);
1325 /* If we found a list for this bfd, then use it. */
1329 /* Nope, allocate and initialize a new entry in the stub list chain. */
1330 stub
= (elf32_hppa_stub_description
*)
1331 bfd_zalloc (abfd
, sizeof (elf32_hppa_stub_description
));
1334 stub
->this_bfd
= abfd
;
1335 stub
->stub_sec
= stub_sec
;
1336 stub
->real_size
= 0;
1337 stub
->allocated_size
= 0;
1338 stub
->stub_contents
= NULL
;
1339 stub
->stub_secp
= NULL
;
1340 stub
->link_info
= link_info
;
1342 stub
->next
= elf_hppa_stub_rootP
;
1343 elf_hppa_stub_rootP
= stub
;
1347 bfd_set_error (bfd_error_no_memory
);
1348 abort(); /* FIXME */
1354 /* Try and locate a stub with the name NAME within the stubs
1355 associated with ABFD. More linked list searches. */
1357 static elf32_hppa_stub_name_list
*
1358 find_stub_by_name (abfd
, stub_sec
, name
)
1363 /* Find the stubs associated with this bfd. */
1364 elf32_hppa_stub_description
*stub
= find_stubs (abfd
, stub_sec
);
1366 /* If found, then we have to walk down them looking for a match. */
1369 elf32_hppa_stub_name_list
*name_listP
;
1371 for (name_listP
= stub
->stub_listP
;
1373 name_listP
= name_listP
->next
)
1375 if (!strcmp (name_listP
->sym
->name
, name
))
1384 /* Add a new stub (SYM) to the list of stubs associated with the given BFD. */
1385 static elf32_hppa_stub_name_list
*
1386 add_stub_by_name(abfd
, stub_sec
, sym
, link_info
)
1390 struct bfd_link_info
*link_info
;
1392 elf32_hppa_stub_description
*stub
= find_stubs (abfd
, stub_sec
);
1393 elf32_hppa_stub_name_list
*stub_entry
;
1395 /* If no stubs are associated with this bfd, then we have to make
1396 a chain-of-stubs associated with this bfd. */
1398 stub
= new_stub (abfd
, stub_sec
, link_info
);
1402 /* Allocate and initialize an entry in the stub chain. */
1403 stub_entry
= (elf32_hppa_stub_name_list
*)
1404 bfd_zalloc (abfd
, sizeof (elf32_hppa_stub_name_list
));
1408 stub_entry
->size
= 0;
1409 stub_entry
->sym
= sym
;
1410 stub_entry
->stub_desc
= stub
;
1411 /* First byte of this stub is the pointer to
1412 the next available location in the stub buffer. */
1413 stub_entry
->stub_secp
= stub
->stub_secp
;
1414 /* Add it to the chain. */
1415 if (stub
->stub_listP
)
1416 stub_entry
->next
= stub
->stub_listP
;
1418 stub_entry
->next
= NULL
;
1419 stub
->stub_listP
= stub_entry
;
1424 bfd_set_error (bfd_error_no_memory
);
1425 abort(); /* FIXME */
1428 /* Death by mis-adventure. */
1430 return (elf32_hppa_stub_name_list
*)NULL
;
1433 /* For the given caller/callee argument location information and the
1434 type of relocation (arguments or return value), return the type
1435 of argument relocation needed to make caller and callee happy. */
1437 static arg_reloc_type
1438 type_of_mismatch (caller_bits
, callee_bits
, type
)
1446 return mismatches
[caller_bits
][callee_bits
];
1448 return retval_mismatches
[caller_bits
][callee_bits
];
1450 return ARG_RELOC_ERR
;
1453 /* Extract specific argument location bits for WHICH from the
1454 the full argument location information in AR. */
1455 #define EXTRACT_ARBITS(ar, which) ((ar) >> (8 - ((which) * 2))) & 3
1457 /* Add the new instruction INSN into the stub area denoted by ENTRY.
1458 FIXME: Looks like more cases where we assume sizeof (int) ==
1459 sizeof (insn) which may not be true if building cross tools. */
1460 #define NEW_INSTRUCTION(entry, insn) \
1462 *((entry)->stub_desc->stub_secp)++ = (insn); \
1463 (entry)->stub_desc->real_size += sizeof (int); \
1464 (entry)->size += sizeof(int); \
1465 bfd_set_section_size((entry)->stub_desc->this_bfd, \
1466 (entry)->stub_desc->stub_sec, \
1467 (entry)->stub_desc->real_size); \
1470 /* Find the offset of the current stub? Looks more like it
1471 finds the offset of the last instruction to me. */
1472 #define CURRENT_STUB_OFFSET(entry) \
1473 ((char *)(entry)->stub_desc->stub_secp \
1474 - (char *)(entry)->stub_desc->stub_contents - 4)
1476 /* All the stubs have already been built, finish up stub stuff
1477 by applying relocations to the stubs. */
1480 hppa_elf_stub_finish (output_bfd
)
1483 elf32_hppa_stub_description
*stub_list
= elf_hppa_stub_rootP
;
1485 /* If the stubs have been finished, then we're already done. */
1489 /* Walk down the list of stub lists. */
1490 for (; stub_list
; stub_list
= stub_list
->next
)
1492 /* If this list has stubs, then do something. */
1493 if (stub_list
->real_size
)
1495 bfd
*stub_bfd
= stub_list
->this_bfd
;
1496 asection
*stub_sec
= bfd_get_section_by_name (stub_bfd
,
1499 arelent
**reloc_vector
;
1502 /* Some sanity checking. */
1503 BFD_ASSERT (stub_sec
== stub_list
->stub_sec
);
1504 BFD_ASSERT (stub_sec
);
1506 /* For stub sections raw_size == cooked_size. Also update
1507 reloc_done as we're handling the relocs now. */
1508 stub_sec
->_cooked_size
= stub_sec
->_raw_size
;
1509 stub_sec
->reloc_done
= true;
1511 /* Make space to hold the relocations for the stub section. */
1512 reloc_size
= bfd_get_reloc_upper_bound (stub_bfd
, stub_sec
);
1515 /* FIXME: Should return an error. */
1518 reloc_vector
= (arelent
**) malloc (reloc_size
);
1519 if (reloc_vector
== NULL
&& reloc_size
!= 0)
1521 /* FIXME: should be returning an error so the caller can
1526 /* If we have relocations, do them. */
1527 reloc_count
= bfd_canonicalize_reloc (stub_bfd
, stub_sec
,
1529 output_bfd
->outsymbols
);
1530 if (reloc_count
< 0)
1532 /* FIXME: Should return an error. */
1535 if (reloc_count
> 0)
1538 for (parent
= reloc_vector
; *parent
!= NULL
; parent
++)
1541 bfd_reloc_status_type r
=
1542 bfd_perform_relocation (stub_bfd
, *parent
,
1543 stub_list
->stub_contents
,
1544 stub_sec
, (bfd
*) NULL
, &err
);
1546 /* If there was an error, tell someone about it. */
1547 if (r
!= bfd_reloc_ok
)
1549 struct bfd_link_info
*link_info
= stub_list
->link_info
;
1553 case bfd_reloc_undefined
:
1554 if (! ((*link_info
->callbacks
->undefined_symbol
)
1556 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
1557 stub_bfd
, stub_sec
, (*parent
)->address
)))
1560 case bfd_reloc_dangerous
:
1561 if (! ((*link_info
->callbacks
->reloc_dangerous
)
1562 (link_info
, err
, stub_bfd
, stub_sec
,
1563 (*parent
)->address
)))
1566 case bfd_reloc_overflow
:
1568 if (! ((*link_info
->callbacks
->reloc_overflow
)
1570 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
1571 (*parent
)->howto
->name
,
1574 (*parent
)->address
)))
1578 case bfd_reloc_outofrange
:
1586 free (reloc_vector
);
1588 /* All done with the relocations. Set the final contents
1589 of the stub section. FIXME: no check of return value! */
1590 bfd_set_section_contents (output_bfd
, stub_sec
,
1591 stub_list
->stub_contents
,
1592 0, stub_list
->real_size
);
1596 stubs_finished
= true;
1599 /* Allocate a new relocation entry to be used in a linker stub. */
1602 hppa_elf_stub_reloc (stub_desc
, output_bfd
, target_sym
, offset
, type
)
1603 elf32_hppa_stub_description
*stub_desc
;
1605 asymbol
**target_sym
;
1607 elf32_hppa_reloc_type type
;
1611 Elf_Internal_Shdr
*rela_hdr
;
1613 /* I really don't like the realloc nonsense in here. FIXME. */
1614 if (stub_desc
->relocs_allocated_cnt
== stub_desc
->stub_sec
->reloc_count
)
1616 /* Allocate the first few relocation entries. */
1617 if (stub_desc
->stub_sec
->relocation
== NULL
)
1619 stub_desc
->relocs_allocated_cnt
= STUB_RELOC_INCR
;
1620 size
= sizeof (arelent
) * stub_desc
->relocs_allocated_cnt
;
1621 stub_desc
->stub_sec
->relocation
= (arelent
*) bfd_zmalloc (size
);
1625 /* We've used all the entries we've already allocated. So get
1627 stub_desc
->relocs_allocated_cnt
+= STUB_RELOC_INCR
;
1628 size
= sizeof (arelent
) * stub_desc
->relocs_allocated_cnt
;
1629 stub_desc
->stub_sec
->relocation
= (arelent
*)
1630 realloc (stub_desc
->stub_sec
->relocation
, size
);
1632 if (!stub_desc
->stub_sec
->relocation
)
1634 bfd_set_error (bfd_error_no_memory
);
1635 abort (); /* FIXME */
1639 rela_hdr
= &elf_section_data(stub_desc
->stub_sec
)->rel_hdr
;
1640 rela_hdr
->sh_size
+= sizeof(Elf32_External_Rela
);
1642 /* Fill in the details. */
1643 relent
.address
= offset
;
1645 relent
.sym_ptr_ptr
= target_sym
;
1646 relent
.howto
= bfd_reloc_type_lookup (stub_desc
->this_bfd
, type
);
1648 /* Save it in the array of relocations for the stub section. */
1649 memcpy (&stub_desc
->stub_sec
->relocation
[stub_desc
->stub_sec
->reloc_count
++],
1650 &relent
, sizeof (arelent
));
1653 /* Build an argument relocation stub. RTN_ADJUST is a hint that an
1654 adjust to the return pointer from within the stub itself may be
1658 hppa_elf_build_linker_stub (abfd
, output_bfd
, link_info
, reloc_entry
,
1659 stub_types
, rtn_adjust
, data
, linker_stub_type
)
1662 struct bfd_link_info
*link_info
;
1663 arelent
*reloc_entry
;
1664 arg_reloc_type stub_types
[5];
1667 hppa_stub_type linker_stub_type
;
1670 boolean milli
, dyncall
;
1671 char stub_sym_name
[128];
1672 elf32_hppa_stub_name_list
*stub_entry
;
1673 /* Some initialization. */
1674 unsigned insn
= data
[0];
1675 asymbol
*stub_sym
= NULL
;
1676 asymbol
**orig_sym
= reloc_entry
->sym_ptr_ptr
;
1677 asection
*stub_sec
= bfd_get_section_by_name (abfd
, ".PARISC.stubs");
1678 elf32_hppa_stub_description
*stub_desc
= find_stubs (abfd
, stub_sec
);
1680 /* Perform some additional checks on whether we should really do the
1681 return adjustment. For example, if the instruction is nullified
1682 or if the delay slot contains an instruction that modifies the return
1683 pointer, then the branch instructions should not be rearranged
1684 (rtn_adjust is false). */
1685 if (insn
& 2 || insn
== 0)
1689 unsigned delay_insn
= data
[1];
1691 if (get_opcode (delay_insn
) == LDO
1692 && (((insn
& 0x03e00000) >> 21) == ((delay_insn
& 0x001f0000) >> 16)))
1696 /* Some special code for long-call stubs. */
1697 if (linker_stub_type
== HPPA_STUB_LONG_CALL
)
1700 /* Is this a millicode call? If so, the return address
1701 comes in on r31 rather than r2 (rp) so a slightly
1702 different code sequence is needed. */
1703 unsigned rtn_reg
= (insn
& 0x03e00000) >> 21;
1707 /* Dyncall is special because the user code has already
1708 put the return pointer in %r2 (aka RP). Other millicode
1709 calls have the return pointer in %r31. */
1710 if (strcmp ((*orig_sym
)->name
, "$$dyncall") == 0)
1713 /* If we are creating a call from a stub to another stub, then
1714 never do the instruction reordering. We can tell if we are
1715 going to be calling one stub from another by the fact that
1716 the symbol name has '_stub_' (arg. reloc. stub) or '_lb_stub_'
1717 prepended to the name. Alternatively, the section of the
1718 symbol will be '.PARISC.stubs'. This is only an issue
1719 for long-calls; they are the only stubs allowed to call another
1721 if ((strncmp ((*orig_sym
)->name
, "_stub_", 6) == 0)
1722 || (strncmp ((*orig_sym
)->name
, "_lb_stub_", 9) == 0))
1724 BFD_ASSERT (strcmp ((*orig_sym
)->section
->name
, ".PARISC.stubs")
1730 /* Create the stub section if necessary. */
1733 BFD_ASSERT (stub_desc
== NULL
);
1734 hppa_elf_create_stub_sec (abfd
, output_bfd
, &stub_sec
, link_info
);
1735 stub_desc
= new_stub (abfd
, stub_sec
, link_info
);
1738 /* Make the stub if we did not find one already. */
1740 stub_desc
= new_stub (abfd
, stub_sec
, link_info
);
1742 /* Allocate space to write the stub.
1743 FIXME: Why using realloc?!? */
1744 if (!stub_desc
->stub_contents
)
1746 stub_desc
->allocated_size
= STUB_BUFFER_INCR
;
1747 stub_desc
->stub_contents
= (char *) malloc (STUB_BUFFER_INCR
);
1749 else if ((stub_desc
->allocated_size
- stub_desc
->real_size
) < STUB_MAX_SIZE
)
1751 stub_desc
->allocated_size
= stub_desc
->allocated_size
+ STUB_BUFFER_INCR
;
1752 stub_desc
->stub_contents
= (char *) realloc (stub_desc
->stub_contents
,
1753 stub_desc
->allocated_size
);
1756 /* If no memory die. (I seriously doubt the other routines
1757 are prepared to get a NULL return value). */
1758 if (!stub_desc
->stub_contents
)
1760 bfd_set_error (bfd_error_no_memory
);
1764 /* Generate an appropriate name for this stub. */
1765 if (linker_stub_type
== HPPA_STUB_ARG_RELOC
)
1766 sprintf (stub_sym_name
,
1767 "_stub_%s_%02d_%02d_%02d_%02d_%02d_%s",
1768 reloc_entry
->sym_ptr_ptr
[0]->name
,
1769 stub_types
[0], stub_types
[1], stub_types
[2],
1770 stub_types
[3], stub_types
[4],
1771 rtn_adjust
? "RA" : "");
1773 sprintf (stub_sym_name
,
1774 "_lb_stub_%s_%s", reloc_entry
->sym_ptr_ptr
[0]->name
,
1775 rtn_adjust
? "RA" : "");
1778 stub_desc
->stub_secp
1779 = (int *) (stub_desc
->stub_contents
+ stub_desc
->real_size
);
1780 stub_entry
= find_stub_by_name (abfd
, stub_sec
, stub_sym_name
);
1782 /* See if we already have one by this name. */
1785 /* Yes, re-use it. Redirect the original relocation from the
1786 old symbol (a function symbol) to the stub (the stub will call
1787 the original function). */
1788 stub_sym
= stub_entry
->sym
;
1789 reloc_entry
->sym_ptr_ptr
= (asymbol
**) bfd_zalloc (abfd
,
1790 sizeof (asymbol
**));
1791 if (reloc_entry
->sym_ptr_ptr
== NULL
)
1793 bfd_set_error (bfd_error_no_memory
);
1796 reloc_entry
->sym_ptr_ptr
[0] = stub_sym
;
1797 if (linker_stub_type
== HPPA_STUB_LONG_CALL
1798 || (reloc_entry
->howto
->type
!= R_PARISC_PLABEL32
1799 && (get_opcode(insn
) == BLE
1800 || get_opcode (insn
) == BE
1801 || get_opcode (insn
) == BL
)))
1802 reloc_entry
->howto
= bfd_reloc_type_lookup (abfd
, R_PARISC_STUB_CALL_17
);
1806 /* Create a new symbol to point to this stub. */
1807 stub_sym
= bfd_make_empty_symbol (abfd
);
1810 bfd_set_error (bfd_error_no_memory
);
1813 stub_sym
->name
= bfd_zalloc (abfd
, strlen (stub_sym_name
) + 1);
1814 if (!stub_sym
->name
)
1816 bfd_set_error (bfd_error_no_memory
);
1819 strcpy ((char *) stub_sym
->name
, stub_sym_name
);
1821 = (char *) stub_desc
->stub_secp
- (char *) stub_desc
->stub_contents
;
1822 stub_sym
->section
= stub_sec
;
1823 stub_sym
->flags
= BSF_LOCAL
| BSF_FUNCTION
;
1824 stub_entry
= add_stub_by_name (abfd
, stub_sec
, stub_sym
, link_info
);
1826 /* Redirect the original relocation from the old symbol (a function)
1827 to the stub (the stub calls the function). */
1828 reloc_entry
->sym_ptr_ptr
= (asymbol
**) bfd_zalloc (abfd
,
1829 sizeof (asymbol
**));
1830 if (reloc_entry
->sym_ptr_ptr
== NULL
)
1832 bfd_set_error (bfd_error_no_memory
);
1835 reloc_entry
->sym_ptr_ptr
[0] = stub_sym
;
1836 if (linker_stub_type
== HPPA_STUB_LONG_CALL
1837 || (reloc_entry
->howto
->type
!= R_PARISC_PLABEL32
1838 && (get_opcode (insn
) == BLE
1839 || get_opcode (insn
) == BE
1840 || get_opcode (insn
) == BL
)))
1841 reloc_entry
->howto
= bfd_reloc_type_lookup (abfd
, R_PARISC_STUB_CALL_17
);
1843 /* Now generate the code for the stub. Starting with two
1844 common instructions.
1846 FIXME: Do we still need the SP adjustment?
1847 Do we still need to muck with space registers? */
1848 NEW_INSTRUCTION (stub_entry
, LDSID_31_1
)
1849 NEW_INSTRUCTION (stub_entry
, MTSP_1_SR0
)
1851 if (linker_stub_type
== HPPA_STUB_ARG_RELOC
)
1853 NEW_INSTRUCTION (stub_entry
, ADDI_8_SP
)
1855 /* Examine each argument, generating code to relocate it
1856 into a different register if necessary. */
1857 for (i
= ARG0
; i
< ARG3
; i
++)
1859 switch (stub_types
[i
])
1869 NEW_INSTRUCTION (stub_entry
, STWS_ARG0_M8SP
)
1870 NEW_INSTRUCTION (stub_entry
, FLDWS_M8SP_FARG0
)
1873 NEW_INSTRUCTION (stub_entry
, STWS_ARG1_M8SP
)
1874 NEW_INSTRUCTION (stub_entry
, FLDWS_M8SP_FARG1
)
1877 NEW_INSTRUCTION (stub_entry
, STWS_ARG2_M8SP
)
1878 NEW_INSTRUCTION (stub_entry
, FLDWS_M8SP_FARG2
)
1881 NEW_INSTRUCTION (stub_entry
, STWS_ARG3_M8SP
)
1882 NEW_INSTRUCTION (stub_entry
, FLDWS_M8SP_FARG3
)
1891 NEW_INSTRUCTION (stub_entry
, STWS_ARG0_M4SP
)
1892 NEW_INSTRUCTION (stub_entry
, STWS_ARG1_M8SP
)
1893 NEW_INSTRUCTION (stub_entry
, FLDDS_M8SP_FARG1
)
1905 NEW_INSTRUCTION (stub_entry
, STWS_ARG2_M4SP
)
1906 NEW_INSTRUCTION (stub_entry
, STWS_ARG3_M8SP
)
1907 NEW_INSTRUCTION (stub_entry
, FLDDS_M8SP_FARG3
)
1919 NEW_INSTRUCTION (stub_entry
, FSTWS_FARG0_M8SP
)
1920 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG0
)
1923 NEW_INSTRUCTION (stub_entry
, FSTWS_FARG1_M8SP
)
1924 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG1
)
1927 NEW_INSTRUCTION (stub_entry
, FSTWS_FARG2_M8SP
)
1928 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG2
)
1931 NEW_INSTRUCTION (stub_entry
, FSTWS_FARG3_M8SP
)
1932 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG3
)
1941 NEW_INSTRUCTION (stub_entry
, FSTDS_FARG1_M8SP
)
1942 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG0
)
1943 NEW_INSTRUCTION (stub_entry
, LDWS_M8SP_ARG1
)
1955 NEW_INSTRUCTION (stub_entry
, FSTDS_FARG3_M8SP
)
1956 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG2
)
1957 NEW_INSTRUCTION (stub_entry
, LDWS_M8SP_ARG3
)
1971 /* Put the stack pointer back. FIXME: Is this still necessary? */
1972 NEW_INSTRUCTION (stub_entry
, ADDI_M8_SP_SP
)
1975 /* Common code again. Return pointer adjustment and the like. */
1978 /* This isn't dyncall. */
1981 /* It's not a millicode call, so get the correct return
1982 value into %r2 (aka RP). */
1984 NEW_INSTRUCTION (stub_entry
, ADDI_M4_31_RP
)
1986 NEW_INSTRUCTION (stub_entry
, COPY_31_2
)
1990 /* It is a millicode call, so get the correct return
1991 value into %r1?!?. FIXME: Shouldn't this be
1992 %r31? Yes, and a little re-arrangement of the
1993 code below would make that possible. */
1995 NEW_INSTRUCTION (stub_entry
, ADDI_M4_31_1
)
1997 NEW_INSTRUCTION (stub_entry
, COPY_31_1
)
2002 /* This is dyncall, so the code is a little different as the
2003 return pointer is already in %r2 (aka RP). */
2005 NEW_INSTRUCTION (stub_entry
, ADDI_M4_31_RP
)
2008 /* Save the return address. */
2009 if (linker_stub_type
== HPPA_STUB_ARG_RELOC
)
2010 NEW_INSTRUCTION (stub_entry
, STW_RP_M8SP
)
2012 /* Long branch to the target function. */
2013 NEW_INSTRUCTION (stub_entry
, LDIL_XXX_31
)
2014 hppa_elf_stub_reloc (stub_entry
->stub_desc
,
2016 CURRENT_STUB_OFFSET (stub_entry
),
2018 NEW_INSTRUCTION (stub_entry
, BLE_XXX_0_31
)
2019 hppa_elf_stub_reloc (stub_entry
->stub_desc
,
2021 CURRENT_STUB_OFFSET (stub_entry
),
2024 if (linker_stub_type
== HPPA_STUB_ARG_RELOC
)
2026 /* In delay slot of long-call, copy %r31 into %r2 so that
2027 the callee can return in the normal fashion. */
2028 NEW_INSTRUCTION (stub_entry
, COPY_31_2
)
2030 /* Restore the return address. */
2031 NEW_INSTRUCTION (stub_entry
, LDW_M8SP_RP
)
2033 /* Generate the code to move the return value around. */
2034 switch (stub_types
[RETVAL
])
2040 NEW_INSTRUCTION (stub_entry
, STWS_RET0_M8SP
)
2041 NEW_INSTRUCTION (stub_entry
, FLDWS_M8SP_FRET0
)
2045 NEW_INSTRUCTION (stub_entry
, FSTWS_FRET0_M8SP
)
2046 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_RET0
)
2054 /* Return back to the main code stream. */
2055 NEW_INSTRUCTION (stub_entry
, BV_N_0_RP
)
2061 /* Get return address into %r31. Both variants may be necessary
2062 (I think) as we could be cascading into another stub. */
2064 NEW_INSTRUCTION (stub_entry
, COPY_2_31
)
2066 NEW_INSTRUCTION (stub_entry
, COPY_1_31
)
2070 /* Get the return address into %r31 too. Might be necessary
2071 (I think) as we could be cascading into another stub. */
2072 NEW_INSTRUCTION (stub_entry
, COPY_2_31
)
2075 /* No need for a return to the main stream. */
2081 /* Return nonzero if an argument relocation will be needed to call
2082 the function (symbol in RELOC_ENTRY) assuming the caller has
2083 argument relocation bugs CALLER_AR. */
2086 hppa_elf_arg_reloc_needed_p (abfd
, reloc_entry
, stub_types
, caller_ar
)
2088 arelent
*reloc_entry
;
2089 arg_reloc_type stub_types
[5];
2090 symext_entryS caller_ar
;
2092 /* If the symbol is still undefined, then it's impossible to know
2093 if an argument relocation is needed. */
2094 if (reloc_entry
->sym_ptr_ptr
[0]
2095 && reloc_entry
->sym_ptr_ptr
[0]->section
!= &bfd_und_section
)
2097 symext_entryS callee_ar
= elf32_hppa_get_sym_extn (abfd
,
2098 reloc_entry
->sym_ptr_ptr
[0],
2099 PARISC_SXT_ARG_RELOC
);
2101 /* Now examine all the argument and return value location
2102 information to determine if a relocation stub will be needed. */
2103 if (caller_ar
&& callee_ar
)
2105 arg_location caller_loc
[5];
2106 arg_location callee_loc
[5];
2108 /* Extract the location information for the return value
2109 and argument registers separately. */
2110 callee_loc
[RETVAL
] = EXTRACT_ARBITS (callee_ar
, RETVAL
);
2111 caller_loc
[RETVAL
] = EXTRACT_ARBITS (caller_ar
, RETVAL
);
2112 callee_loc
[ARG0
] = EXTRACT_ARBITS (callee_ar
, ARG0
);
2113 caller_loc
[ARG0
] = EXTRACT_ARBITS (caller_ar
, ARG0
);
2114 callee_loc
[ARG1
] = EXTRACT_ARBITS (callee_ar
, ARG1
);
2115 caller_loc
[ARG1
] = EXTRACT_ARBITS (caller_ar
, ARG1
);
2116 callee_loc
[ARG2
] = EXTRACT_ARBITS (callee_ar
, ARG2
);
2117 caller_loc
[ARG2
] = EXTRACT_ARBITS (caller_ar
, ARG2
);
2118 callee_loc
[ARG3
] = EXTRACT_ARBITS (callee_ar
, ARG3
);
2119 caller_loc
[ARG3
] = EXTRACT_ARBITS (caller_ar
, ARG3
);
2121 /* Check some special combinations. For example, if FU
2122 appears in ARG1 or ARG3, we can move it to ARG0 or ARG2,
2123 respectively. (I guess this braindamage is correct? It'd
2124 take an hour or two of reading PA calling conventions to
2127 if (caller_loc
[ARG0
] == AR_FU
|| caller_loc
[ARG1
] == AR_FU
)
2129 caller_loc
[ARG0
] = AR_DBL01
;
2130 caller_loc
[ARG1
] = AR_NO
;
2132 if (caller_loc
[ARG2
] == AR_FU
|| caller_loc
[ARG3
] == AR_FU
)
2134 caller_loc
[ARG2
] = AR_DBL23
;
2135 caller_loc
[ARG3
] = AR_NO
;
2137 if (callee_loc
[ARG0
] == AR_FU
|| callee_loc
[ARG1
] == AR_FU
)
2139 callee_loc
[ARG0
] = AR_DBL01
;
2140 callee_loc
[ARG1
] = AR_NO
;
2142 if (callee_loc
[ARG2
] == AR_FU
|| callee_loc
[ARG3
] == AR_FU
)
2144 callee_loc
[ARG2
] = AR_DBL23
;
2145 callee_loc
[ARG3
] = AR_NO
;
2148 /* Now look up potential mismatches. */
2149 stub_types
[ARG0
] = type_of_mismatch (caller_loc
[ARG0
],
2152 stub_types
[ARG1
] = type_of_mismatch (caller_loc
[ARG1
],
2155 stub_types
[ARG2
] = type_of_mismatch (caller_loc
[ARG2
],
2158 stub_types
[ARG3
] = type_of_mismatch (caller_loc
[ARG3
],
2161 stub_types
[RETVAL
] = type_of_mismatch (caller_loc
[RETVAL
],
2165 /* If any of the arguments or return value need an argument
2166 relocation, then we will need an argument relocation stub. */
2167 if (stub_types
[ARG0
] != NO_ARG_RELOC
2168 || stub_types
[ARG1
] != NO_ARG_RELOC
2169 || stub_types
[ARG2
] != NO_ARG_RELOC
2170 || stub_types
[ARG3
] != NO_ARG_RELOC
2171 || stub_types
[RETVAL
] != NO_ARG_RELOC
)
2178 /* Create the linker stub section. */
2181 hppa_elf_create_stub_sec (abfd
, output_bfd
, secptr
, link_info
)
2185 struct bfd_link_info
*link_info
;
2187 asection
*output_text_section
;
2189 output_text_section
= bfd_get_section_by_name (output_bfd
, ".text");
2190 *secptr
= bfd_make_section (abfd
, ".PARISC.stubs");
2191 bfd_set_section_flags (abfd
, *secptr
,
2192 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
2193 | SEC_RELOC
| SEC_CODE
| SEC_READONLY
);
2194 (*secptr
)->output_section
= output_text_section
->output_section
;
2195 (*secptr
)->output_offset
= 0;
2197 /* Set up the ELF section header for this new section. This
2198 is basically the same processing as elf_make_sections().
2199 elf_make_sections is static and therefore not accessable
2202 Elf_Internal_Shdr
*this_hdr
;
2203 this_hdr
= &elf_section_data ((*secptr
))->this_hdr
;
2205 /* Set the sizes of this section. The contents have already
2207 this_hdr
->sh_addr
= (*secptr
)->vma
;
2208 this_hdr
->sh_size
= (*secptr
)->_raw_size
;
2210 /* Set appropriate flags for sections with relocations. */
2211 if ((*secptr
)->flags
& SEC_RELOC
)
2213 Elf_Internal_Shdr
*rela_hdr
;
2214 int use_rela_p
= get_elf_backend_data (abfd
)->use_rela_p
;
2216 rela_hdr
= &elf_section_data ((*secptr
))->rel_hdr
;
2220 rela_hdr
->sh_type
= SHT_RELA
;
2221 rela_hdr
->sh_entsize
= sizeof (Elf32_External_Rela
);
2225 rela_hdr
->sh_type
= SHT_REL
;
2226 rela_hdr
->sh_entsize
= sizeof (Elf32_External_Rel
);
2228 rela_hdr
->sh_flags
= 0;
2229 rela_hdr
->sh_addr
= 0;
2230 rela_hdr
->sh_offset
= 0;
2231 rela_hdr
->sh_addralign
= 0;
2235 if ((*secptr
)->flags
& SEC_ALLOC
)
2236 this_hdr
->sh_flags
|= SHF_ALLOC
;
2238 if (!((*secptr
)->flags
& SEC_READONLY
))
2239 this_hdr
->sh_flags
|= SHF_WRITE
;
2241 if ((*secptr
)->flags
& SEC_CODE
)
2242 this_hdr
->sh_flags
|= SHF_EXECINSTR
;
2245 bfd_set_section_alignment (abfd
, *secptr
, 2);
2248 /* Return nonzero if a long-call stub will be needed to call the
2249 function (symbol in RELOC_ENTRY). */
2252 hppa_elf_long_branch_needed_p (abfd
, asec
, reloc_entry
, symbol
, insn
)
2255 arelent
*reloc_entry
;
2259 long sym_value
= get_symbol_value (symbol
);
2260 int fmt
= reloc_entry
->howto
->bitsize
;
2261 unsigned char op
= get_opcode (insn
);
2264 #define too_far(val,num_bits) \
2265 ((int)(val) > (1 << (num_bits)) - 1) || ((int)(val) < (-1 << (num_bits)))
2271 reloc_entry
->address
+ asec
->output_offset
+ asec
->output_section
->vma
;
2272 /* If the symbol and raddr (relocated addr?) are too far away from
2273 each other, then a long-call stub will be needed. */
2274 if (too_far (sym_value
- raddr
, fmt
+ 1))
2281 /* Search the given section and determine if linker stubs will be
2282 needed for any calls within that section.
2284 Return any new stub symbols created.
2286 Used out of hppaelf.em in the linker. */
2289 hppa_look_for_stubs_in_section (stub_bfd
, abfd
, output_bfd
, asec
,
2290 new_sym_cnt
, link_info
)
2296 struct bfd_link_info
*link_info
;
2299 arg_reloc_type stub_types
[5];
2300 asymbol
*new_syms
= NULL
;
2303 arelent
**reloc_vector
= NULL
;
2305 /* Relocations are in different places depending on whether this is
2306 an output section or an input section. Also, the relocations are
2307 in different forms. Sigh. Luckily, we have bfd_canonicalize_reloc()
2308 to straighten this out for us . */
2309 if (asec
->reloc_count
> 0)
2312 = (arelent
**) malloc (asec
->reloc_count
* (sizeof (arelent
*) + 1));
2313 if (reloc_vector
== NULL
)
2315 bfd_set_error (bfd_error_no_memory
);
2319 /* Make sure the canonical symbols are hanging around in a convient
2321 if (bfd_get_outsymbols (abfd
) == NULL
)
2326 symsize
= bfd_get_symtab_upper_bound (abfd
);
2329 abfd
->outsymbols
= (asymbol
**) bfd_alloc (abfd
, symsize
);
2330 if (!abfd
->outsymbols
&& symsize
!= 0)
2332 bfd_set_error (bfd_error_no_memory
);
2335 symcount
= bfd_canonicalize_symtab (abfd
, abfd
->outsymbols
);
2338 abfd
->symcount
= symcount
;
2341 /* Now get the relocations. */
2342 if (bfd_canonicalize_reloc (abfd
, asec
, reloc_vector
,
2343 bfd_get_outsymbols (abfd
)) < 0)
2346 /* Examine each relocation entry in this section. */
2347 for (i
= 0; i
< asec
->reloc_count
; i
++)
2349 arelent
*rle
= reloc_vector
[i
];
2351 switch (rle
->howto
->type
)
2353 /* Any call could need argument relocation stubs, and
2354 some may need long-call stubs. */
2355 case R_PARISC_PCREL21L
:
2356 case R_PARISC_PCREL17R
:
2357 case R_PARISC_PCREL17F
:
2358 case R_PARISC_PCREL17C
:
2359 case R_PARISC_PCREL14R
:
2360 case R_PARISC_PCREL14F
:
2362 symext_entryS caller_ar
2363 = (symext_entryS
) HPPA_R_ARG_RELOC (rle
->addend
);
2366 /* We'll need this for the long-call checks. */
2367 bfd_get_section_contents (abfd
, asec
, insn
, rle
->address
,
2370 /* See if this call needs an argument relocation stub. */
2371 if (hppa_elf_arg_reloc_needed_p (abfd
, rle
, stub_types
,
2374 /* Generate a stub and keep track of the new symbol. */
2377 if (new_cnt
== new_max
)
2379 new_max
+= STUB_SYM_BUFFER_INC
;
2380 new_syms
= (asymbol
*)
2381 realloc (new_syms
, new_max
* sizeof (asymbol
));
2382 if (new_syms
== NULL
)
2384 bfd_set_error (bfd_error_no_memory
);
2389 /* Build the argument relocation stub. */
2390 r
= hppa_elf_build_linker_stub (stub_bfd
, output_bfd
,
2392 stub_types
, true, insn
,
2393 HPPA_STUB_ARG_RELOC
);
2394 new_syms
[new_cnt
++] = *r
;
2397 /* See if this call needs a long-call stub. */
2398 if (hppa_elf_long_branch_needed_p (abfd
, asec
, rle
,
2399 rle
->sym_ptr_ptr
[0],
2402 /* Generate a stub and keep track of the new symbol. */
2405 if (new_cnt
== new_max
)
2407 new_max
+= STUB_SYM_BUFFER_INC
;
2408 new_syms
= (asymbol
*)
2409 realloc (new_syms
, (new_max
* sizeof (asymbol
)));
2412 bfd_set_error (bfd_error_no_memory
);
2417 /* Build the long-call stub. */
2418 r
= hppa_elf_build_linker_stub (stub_bfd
, output_bfd
,
2421 HPPA_STUB_LONG_CALL
);
2422 new_syms
[new_cnt
++] = *r
;
2427 /* PLABELs may need argument relocation stubs. */
2428 case R_PARISC_PLABEL32
:
2429 case R_PARISC_PLABEL21L
:
2430 case R_PARISC_PLABEL14R
:
2432 /* On a plabel relocation, assume the arguments of the
2433 caller are set up in general registers (indirect
2434 calls only use general registers.
2435 NOTE: 0x155 = ARGW0=GR,ARGW1=GR,ARGW2=GR,RETVAL=GR. */
2436 symext_entryS caller_ar
= (symext_entryS
) 0x155;
2439 /* Do we really need this? */
2440 bfd_get_section_contents (abfd
, asec
, insn
, rle
->address
,
2443 /* See if this call needs an argument relocation stub. */
2444 if (hppa_elf_arg_reloc_needed_p (abfd
, rle
, stub_types
,
2447 /* Generate a plabel stub and keep track of the
2452 if (new_cnt
== new_max
)
2454 new_max
+= STUB_SYM_BUFFER_INC
;
2455 new_syms
= (asymbol
*) realloc (new_syms
, new_max
2456 * sizeof (asymbol
));
2459 /* Determine whether a return adjustment
2460 (see the relocation code for relocation type
2461 R_PARISC_STUB_CALL_17) is possible. Basically,
2462 determine whether we are looking at a branch or not. */
2463 if (rle
->howto
->type
== R_PARISC_PLABEL32
)
2467 switch (get_opcode(insn
[0]))
2478 /* Build the argument relocation stub. */
2479 r
= hppa_elf_build_linker_stub (stub_bfd
, output_bfd
,
2480 link_info
, rle
, stub_types
,
2482 HPPA_STUB_ARG_RELOC
);
2483 new_syms
[new_cnt
++] = *r
;
2494 if (reloc_vector
!= NULL
)
2495 free (reloc_vector
);
2496 /* Return the new symbols and update the counters. */
2497 *new_sym_cnt
= new_cnt
;
2501 if (reloc_vector
!= NULL
)
2502 free (reloc_vector
);
2503 /* FIXME: This is bogus. We should be returning NULL. But do the callers
2508 /* Set the contents of a particular section at a particular location. */
2511 hppa_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
2516 bfd_size_type count
;
2518 /* Linker stubs are handled a little differently. */
2519 if (! strcmp (section
->name
, ".PARISC.stubs"))
2521 if (linker_stubs_max_size
< offset
+ count
)
2523 linker_stubs_max_size
= offset
+ count
+ STUB_ALLOC_INCR
;
2524 linker_stubs
= (char *)realloc (linker_stubs
, linker_stubs_max_size
);
2529 if (offset
+ count
> linker_stubs_size
)
2530 linker_stubs_size
= offset
+ count
;
2532 /* Set the contents. */
2533 memcpy(linker_stubs
+ offset
, location
, count
);
2536 /* Ignore write requests for the symbol extension section until we've
2537 had the chance to rebuild it ourselves. */
2538 else if (! strcmp (section
->name
, ".PARISC.symextn") && !symext_chain_size
)
2541 return bfd_elf32_set_section_contents (abfd
, section
, location
,
2545 /* Get the contents of the given section.
2547 This is special for PA ELF because some sections (such as linker stubs)
2548 may reside in memory rather than on disk, or in the case of the symbol
2549 extension section, the contents may need to be generated from other
2550 information contained in the BFD. */
2553 hppa_elf_get_section_contents (abfd
, section
, location
, offset
, count
)
2558 bfd_size_type count
;
2560 /* If this is the linker stub section, then its contents are contained
2561 in memory rather than on disk. FIXME. Is that always right? What
2562 about the case where a final executable is read in and a user tries
2563 to get the contents of this section? In that case the contents would
2564 be on disk like everything else. */
2565 if (strcmp (section
->name
, ".PARISC.stubs") == 0)
2567 elf32_hppa_stub_description
*stub_desc
= find_stubs (abfd
, section
);
2572 /* Sanity check our arguments. */
2573 if ((bfd_size_type
) (offset
+ count
) > section
->_raw_size
2574 || (bfd_size_type
) (offset
+ count
) > stub_desc
->real_size
)
2577 memcpy (location
, stub_desc
->stub_contents
+ offset
, count
);
2581 /* It's not the linker stub section, use the generic routines. */
2582 return _bfd_generic_get_section_contents (abfd
, section
, location
,
2586 /* Translate from an elf into field into a howto relocation pointer. */
2589 elf_info_to_howto (abfd
, cache_ptr
, dst
)
2592 Elf32_Internal_Rela
*dst
;
2594 BFD_ASSERT (ELF32_R_TYPE(dst
->r_info
) < (unsigned int) R_PARISC_UNIMPLEMENTED
);
2595 cache_ptr
->howto
= &elf_hppa_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
2598 /* Do PA ELF specific processing for symbols. Needed to find the
2599 value of $global$. */
2602 elf32_hppa_backend_symbol_processing (abfd
, sym
)
2606 /* Is this a definition of $global$? If so, keep it because it will be
2607 needed if any relocations are performed. */
2608 if (!strcmp (sym
->name
, "$global$")
2609 && sym
->section
!= &bfd_und_section
)
2611 global_symbol
= sym
;
2615 /* Do some PA ELF specific work after reading in the symbol table.
2616 In particular attach the argument relocation from the
2617 symbol extension section to the appropriate symbols. */
2619 elf32_hppa_backend_symbol_table_processing (abfd
, esyms
,symcnt
)
2621 elf_symbol_type
*esyms
;
2624 Elf32_Internal_Shdr
*symextn_hdr
=
2625 bfd_elf_find_section (abfd
, SYMEXTN_SECTION_NAME
);
2626 int i
, current_sym_idx
= 0;
2628 /* If no symbol extension existed, then all symbol extension information
2629 is assumed to be zero. */
2630 if (symextn_hdr
== NULL
)
2632 for (i
= 0; i
< symcnt
; i
++)
2633 esyms
[i
].tc_data
.hppa_arg_reloc
= 0;
2637 /* Allocate a buffer of the appropriate size for the symextn section. */
2638 symextn_hdr
->contents
= bfd_zalloc(abfd
,symextn_hdr
->sh_size
);
2639 if (!symextn_hdr
->contents
)
2641 bfd_set_error (bfd_error_no_memory
);
2644 symextn_hdr
->size
= symextn_hdr
->sh_size
;
2646 /* Read in the symextn section. */
2647 if (bfd_seek (abfd
, symextn_hdr
->sh_offset
, SEEK_SET
) == -1)
2649 if (bfd_read ((PTR
) symextn_hdr
->contents
, 1, symextn_hdr
->size
, abfd
)
2650 != symextn_hdr
->size
)
2653 /* Parse entries in the symbol extension section, updating the symtab
2655 for (i
= 0; i
< symextn_hdr
->size
/ sizeof(symext_entryS
); i
++)
2657 symext_entryS
*seP
= ((symext_entryS
*)symextn_hdr
->contents
) + i
;
2658 int se_value
= ELF32_PARISC_SX_VAL (*seP
);
2659 int se_type
= ELF32_PARISC_SX_TYPE (*seP
);
2663 case PARISC_SXT_NULL
:
2666 case PARISC_SXT_SYMNDX
:
2667 if (se_value
>= symcnt
)
2669 bfd_set_error (bfd_error_bad_value
);
2672 current_sym_idx
= se_value
- 1;
2675 case PARISC_SXT_ARG_RELOC
:
2676 esyms
[current_sym_idx
].tc_data
.hppa_arg_reloc
= se_value
;
2680 bfd_set_error (bfd_error_bad_value
);
2687 /* Perform on PA ELF specific processing once a section has been
2688 read in. In particular keep the symbol indexes correct for
2689 the symbol extension information. */
2692 elf32_hppa_backend_section_processing (abfd
, secthdr
)
2694 Elf32_Internal_Shdr
*secthdr
;
2698 if (secthdr
->sh_type
== SHT_PARISC_SYMEXTN
)
2700 for (i
= 0; i
< secthdr
->size
/ sizeof (symext_entryS
); i
++)
2702 symext_entryS
*seP
= ((symext_entryS
*)secthdr
->contents
) + i
;
2703 int se_value
= ELF32_PARISC_SX_VAL (*seP
);
2704 int se_type
= ELF32_PARISC_SX_TYPE (*seP
);
2708 case PARISC_SXT_NULL
:
2711 case PARISC_SXT_SYMNDX
:
2712 for (j
= 0; j
< abfd
->symcount
; j
++)
2714 /* Locate the map entry for this symbol and modify the
2715 symbol extension section symbol index entry to reflect
2716 the new symbol table index. */
2717 for (k
= 0; k
< elf32_hppa_symextn_map_size
; k
++)
2719 if (elf32_hppa_symextn_map
[k
].old_index
== se_value
2720 && elf32_hppa_symextn_map
[k
].bfd
2721 == abfd
->outsymbols
[j
]->the_bfd
2722 && elf32_hppa_symextn_map
[k
].sym
2723 == abfd
->outsymbols
[j
])
2726 ELF32_PARISC_SX_WORD (PARISC_SXT_SYMNDX
, j
),
2733 case PARISC_SXT_ARG_RELOC
:
2737 bfd_set_error (bfd_error_bad_value
);
2745 /* What does this really do? Just determine if there is an appropriate
2746 mapping from ELF section headers to backend sections? More symbol
2747 extension braindamage. */
2750 elf32_hppa_backend_section_from_shdr (abfd
, hdr
, name
)
2752 Elf32_Internal_Shdr
*hdr
;
2757 if (hdr
->sh_type
== SHT_PARISC_SYMEXTN
)
2759 BFD_ASSERT (strcmp (name
, ".PARISC.symextn") == 0);
2761 /* Bits that get saved. This one is real. */
2764 newsect
= bfd_make_section (abfd
, name
);
2765 if (newsect
!= NULL
)
2767 newsect
->vma
= hdr
->sh_addr
;
2768 newsect
->_raw_size
= hdr
->sh_size
;
2769 newsect
->filepos
= hdr
->sh_offset
;
2770 newsect
->flags
|= SEC_HAS_CONTENTS
;
2771 newsect
->alignment_power
= hdr
->sh_addralign
;
2773 if (hdr
->sh_flags
& SHF_ALLOC
)
2775 newsect
->flags
|= SEC_ALLOC
;
2776 newsect
->flags
|= SEC_LOAD
;
2779 if (!(hdr
->sh_flags
& SHF_WRITE
))
2780 newsect
->flags
|= SEC_READONLY
;
2782 if (hdr
->sh_flags
& SHF_EXECINSTR
)
2783 newsect
->flags
|= SEC_CODE
;
2785 newsect
->flags
|= SEC_DATA
;
2787 hdr
->rawdata
= (void *) newsect
;
2795 /* Return true if the given section is a fake section. */
2798 elf32_hppa_backend_fake_sections (abfd
, secthdr
, asect
)
2800 Elf_Internal_Shdr
*secthdr
;
2804 if (strcmp(asect
->name
, ".PARISC.symextn") == 0)
2806 secthdr
->sh_type
= SHT_PARISC_SYMEXTN
;
2807 secthdr
->sh_flags
= 0;
2808 secthdr
->sh_info
= elf_section_data(asect
)->rel_hdr
.sh_link
;
2809 secthdr
->sh_link
= elf_onesymtab(abfd
);
2813 if (!strcmp (asect
->name
, ".PARISC.unwind"))
2815 secthdr
->sh_type
= SHT_PROGBITS
;
2816 /* Unwind descriptors are not part of the program memory image. */
2817 secthdr
->sh_flags
= 0;
2818 secthdr
->sh_info
= 0;
2819 secthdr
->sh_link
= 0;
2820 secthdr
->sh_entsize
= 16;
2824 /* @@ Should this be CPU specific?? KR */
2825 if (!strcmp (asect
->name
, ".stabstr"))
2827 secthdr
->sh_type
= SHT_STRTAB
;
2828 secthdr
->sh_flags
= 0;
2829 secthdr
->sh_info
= 0;
2830 secthdr
->sh_link
= 0;
2831 secthdr
->sh_entsize
= 0;
2838 /* Return true if there is a mapping from bfd section into a
2842 elf32_hppa_backend_section_from_bfd_section (abfd
, hdr
, asect
, ignored
)
2844 Elf32_Internal_Shdr
*hdr
;
2848 if (hdr
->sh_type
== SHT_PARISC_SYMEXTN
)
2852 if (((struct sec
*) (hdr
->rawdata
)) == asect
)
2854 BFD_ASSERT (strcmp (asect
->name
, ".PARISC.symextn") == 0);
2859 else if (hdr
->sh_type
== SHT_STRTAB
)
2863 if (((struct sec
*) (hdr
->rawdata
)) == asect
)
2865 BFD_ASSERT (strcmp (asect
->name
, ".stabstr") == 0);
2874 #define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
2875 #define elf_backend_section_from_bfd_section elf32_hppa_backend_section_from_bfd_section
2877 #define elf_backend_symbol_processing elf32_hppa_backend_symbol_processing
2878 #define elf_backend_symbol_table_processing elf32_hppa_backend_symbol_table_processing
2880 #define bfd_elf32_get_section_contents hppa_elf_get_section_contents
2881 #define bfd_elf32_set_section_contents hppa_elf_set_section_contents
2882 #define bfd_elf32_bfd_is_local_label hppa_elf_is_local_label
2884 #define elf_backend_section_processing elf32_hppa_backend_section_processing
2886 #define elf_backend_section_from_shdr elf32_hppa_backend_section_from_shdr
2887 #define elf_backend_fake_sections elf32_hppa_backend_fake_sections
2888 #define elf_backend_begin_write_processing \
2889 elf32_hppa_backend_begin_write_processing
2890 #define elf_backend_final_write_processing \
2891 elf32_hppa_backend_final_write_processing
2893 #define TARGET_BIG_SYM bfd_elf32_hppa_vec
2894 #define TARGET_BIG_NAME "elf32-hppa"
2895 #define ELF_ARCH bfd_arch_hppa
2896 #define ELF_MACHINE_CODE EM_PARISC
2897 #define ELF_MAXPAGESIZE 0x1000
2899 #include "elf32-target.h"