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 void hppa_elf_relocate_unwind_table
204 PARAMS ((bfd
*, PTR
, unsigned long, long, long,
205 unsigned long, unsigned long));
207 static long get_symbol_value
PARAMS ((asymbol
*));
209 static bfd_reloc_status_type hppa_elf_reloc
210 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
212 static CONST reloc_howto_type
* elf_hppa_reloc_type_lookup
213 PARAMS ((bfd_arch_info_type
*, bfd_reloc_code_real_type
));
215 static symext_entryS elf32_hppa_get_sym_extn
PARAMS ((bfd
*, asymbol
*, int));
217 static elf32_hppa_stub_description
* find_stubs
PARAMS ((bfd
*, asection
*));
219 static elf32_hppa_stub_description
* new_stub
220 PARAMS ((bfd
*, asection
*, struct bfd_link_info
*));
222 static arg_reloc_type type_of_mismatch
PARAMS ((int, int, int));
224 static elf32_hppa_stub_name_list
* find_stub_by_name
225 PARAMS ((bfd
*, asection
*, char *));
227 static elf32_hppa_stub_name_list
* add_stub_by_name
228 PARAMS ((bfd
*, asection
*, asymbol
*, struct bfd_link_info
*));
230 static void hppa_elf_stub_finish
PARAMS ((bfd
*));
232 static void hppa_elf_stub_reloc
233 PARAMS ((elf32_hppa_stub_description
*, bfd
*, asymbol
**, int,
234 elf32_hppa_reloc_type
));
236 static int hppa_elf_arg_reloc_needed_p
237 PARAMS ((bfd
*, arelent
*, arg_reloc_type
[5], symext_entryS
));
239 static asymbol
* hppa_elf_build_linker_stub
240 PARAMS ((bfd
*, bfd
*, struct bfd_link_info
*, arelent
*,
241 arg_reloc_type
[5], int, unsigned *, hppa_stub_type
));
243 static void hppa_elf_create_stub_sec
244 PARAMS ((bfd
*, bfd
*, asection
**, struct bfd_link_info
*));
246 static int hppa_elf_long_branch_needed_p
247 PARAMS ((bfd
*, asection
*, arelent
*, asymbol
*, unsigned));
249 static boolean hppa_elf_set_section_contents
250 PARAMS ((bfd
*, sec_ptr
, PTR
, file_ptr
, bfd_size_type
));
252 static void elf_info_to_howto
253 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rela
*));
255 static void elf32_hppa_backend_symbol_processing
PARAMS ((bfd
*, asymbol
*));
257 static boolean elf32_hppa_backend_section_processing
258 PARAMS ((bfd
*, Elf32_Internal_Shdr
*));
260 static boolean elf32_hppa_backend_symbol_table_processing
261 PARAMS ((bfd
*, elf_symbol_type
*, int));
263 static boolean elf32_hppa_backend_section_from_shdr
264 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, char *));
266 static boolean elf32_hppa_backend_fake_sections
267 PARAMS ((bfd
*, Elf_Internal_Shdr
*, asection
*));
269 static boolean elf32_hppa_backend_section_from_bfd_section
270 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, asection
*, int *));
272 /* ELF/PA relocation howto entries. */
274 static reloc_howto_type elf_hppa_howto_table
[ELF_HOWTO_TABLE_SIZE
] =
276 {R_HPPA_NONE
, 0, 3, 19, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_NONE"},
277 {R_HPPA_32
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_32"},
278 {R_HPPA_11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_11"},
279 {R_HPPA_14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_14"},
280 {R_HPPA_17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_17"},
281 {R_HPPA_L21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_L21"},
282 {R_HPPA_R11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_R11"},
283 {R_HPPA_R14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_R14"},
284 {R_HPPA_R17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_R17"},
285 {R_HPPA_LS21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_LS21"},
286 {R_HPPA_RS11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RS11"},
287 {R_HPPA_RS14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RS14"},
288 {R_HPPA_RS17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RS17"},
289 {R_HPPA_LD21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_LD21"},
290 {R_HPPA_RD11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RD11"},
291 {R_HPPA_RD14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RD14"},
292 {R_HPPA_RD17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RD17"},
293 {R_HPPA_LR21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_LR21"},
294 {R_HPPA_RR14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RR14"},
295 {R_HPPA_RR17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RR17"},
296 {R_HPPA_GOTOFF_11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_11"},
297 {R_HPPA_GOTOFF_14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_14"},
298 {R_HPPA_GOTOFF_L21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_L21"},
299 {R_HPPA_GOTOFF_R11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_R11"},
300 {R_HPPA_GOTOFF_R14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_R14"},
301 {R_HPPA_GOTOFF_LS21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_LS21"},
302 {R_HPPA_GOTOFF_RS11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_RS11"},
303 {R_HPPA_GOTOFF_RS14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_RS14"},
304 {R_HPPA_GOTOFF_LD21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_LD21"},
305 {R_HPPA_GOTOFF_RD11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_RD11"},
306 {R_HPPA_GOTOFF_RD14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_RD14"},
307 {R_HPPA_GOTOFF_LR21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_LR21"},
308 {R_HPPA_GOTOFF_RR14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_RR14"},
309 {R_HPPA_ABS_CALL_11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_11"},
310 {R_HPPA_ABS_CALL_14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_14"},
311 {R_HPPA_ABS_CALL_17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_17"},
312 {R_HPPA_ABS_CALL_L21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_L21"},
313 {R_HPPA_ABS_CALL_R11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_R11"},
314 {R_HPPA_ABS_CALL_R14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_R14"},
315 {R_HPPA_ABS_CALL_R17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_R17"},
316 {R_HPPA_ABS_CALL_LS21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_LS21"},
317 {R_HPPA_ABS_CALL_RS11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RS11"},
318 {R_HPPA_ABS_CALL_RS14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RS14"},
319 {R_HPPA_ABS_CALL_RS17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RS17"},
320 {R_HPPA_ABS_CALL_LD21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_LD21"},
321 {R_HPPA_ABS_CALL_RD11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RD11"},
322 {R_HPPA_ABS_CALL_RD14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RD14"},
323 {R_HPPA_ABS_CALL_RD17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RD17"},
324 {R_HPPA_ABS_CALL_LR21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_LR21"},
325 {R_HPPA_ABS_CALL_RR14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RR14"},
326 {R_HPPA_ABS_CALL_RR17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RR17"},
327 {R_HPPA_PCREL_CALL_11
, 0, 3, 11, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_11"},
328 {R_HPPA_PCREL_CALL_14
, 0, 3, 14, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_14"},
329 {R_HPPA_PCREL_CALL_17
, 0, 3, 17, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_17"},
330 {R_HPPA_PCREL_CALL_12
, 0, 3, 12, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_12"},
331 {R_HPPA_PCREL_CALL_L21
, 0, 3, 21, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_L21"},
332 {R_HPPA_PCREL_CALL_R11
, 0, 3, 11, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_R11"},
333 {R_HPPA_PCREL_CALL_R14
, 0, 3, 14, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_R14"},
334 {R_HPPA_PCREL_CALL_R17
, 0, 3, 17, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_R17"},
335 {R_HPPA_PCREL_CALL_LS21
, 0, 3, 21, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_LS21"},
336 {R_HPPA_PCREL_CALL_RS11
, 0, 3, 11, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RS11"},
337 {R_HPPA_PCREL_CALL_RS14
, 0, 3, 14, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RS14"},
338 {R_HPPA_PCREL_CALL_RS17
, 0, 3, 17, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RS17"},
339 {R_HPPA_PCREL_CALL_LD21
, 0, 3, 21, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_LD21"},
340 {R_HPPA_PCREL_CALL_RD11
, 0, 3, 11, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RD11"},
341 {R_HPPA_PCREL_CALL_RD14
, 0, 3, 14, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RD14"},
342 {R_HPPA_PCREL_CALL_RD17
, 0, 3, 17, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RD17"},
343 {R_HPPA_PCREL_CALL_LR21
, 0, 3, 21, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_LR21"},
344 {R_HPPA_PCREL_CALL_RR14
, 0, 3, 14, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RR14"},
345 {R_HPPA_PCREL_CALL_RR17
, 0, 3, 17, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RR17"},
346 {R_HPPA_PLABEL_32
, 0, 3, 32, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PLABEL_32"},
347 {R_HPPA_PLABEL_11
, 0, 3, 11, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PLABEL_11"},
348 {R_HPPA_PLABEL_14
, 0, 3, 14, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PLABEL_14"},
349 {R_HPPA_PLABEL_L21
, 0, 3, 21, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PLABEL_L21"},
350 {R_HPPA_PLABEL_R11
, 0, 3, 11, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PLABEL_R11"},
351 {R_HPPA_PLABEL_R14
, 0, 3, 14, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PLABEL_R14"},
352 {R_HPPA_DLT_32
, 0, 3, 32, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_DLT_32"},
353 {R_HPPA_DLT_11
, 0, 3, 11, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_DLT_11"},
354 {R_HPPA_DLT_14
, 0, 3, 14, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_DLT_14"},
355 {R_HPPA_DLT_L21
, 0, 3, 21, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_DLT_L21"},
356 {R_HPPA_DLT_R11
, 0, 3, 11, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_DLT_R11"},
357 {R_HPPA_DLT_R14
, 0, 3, 14, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_DLT_R14"},
358 {R_HPPA_UNWIND_ENTRY
, 0, 3, 32, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_UNWIND_ENTRY"},
359 {R_HPPA_UNWIND_ENTRIES
, 0, 3, 32, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_UNWIND_ENTRIES"},
360 {R_HPPA_PUSH_CONST
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_CONST"},
361 {R_HPPA_PUSH_PC
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_PC"},
362 {R_HPPA_PUSH_SYM
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_SYM"},
363 {R_HPPA_PUSH_GOTOFF
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_GOTOFF"},
364 {R_HPPA_PUSH_ABS_CALL
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_ABS_CALL"},
365 {R_HPPA_PUSH_PCREL_CALL
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_PCREL_CALL"},
366 {R_HPPA_PUSH_PLABEL
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_PLABEL"},
367 {R_HPPA_MAX
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_MAX"},
368 {R_HPPA_MIN
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_MIN"},
369 {R_HPPA_ADD
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ADD"},
370 {R_HPPA_SUB
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_SUB"},
371 {R_HPPA_MULT
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_MULT"},
372 {R_HPPA_DIV
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_DIV"},
373 {R_HPPA_MOD
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_MOD"},
374 {R_HPPA_AND
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_AND"},
375 {R_HPPA_OR
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_OR"},
376 {R_HPPA_XOR
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_XOR"},
377 {R_HPPA_NOT
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_NOT"},
378 {R_HPPA_LSHIFT
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_LSHIFT"},
379 {R_HPPA_ARITH_RSHIFT
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ARITH_RSHIFT"},
380 {R_HPPA_LOGIC_RSHIFT
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_LOGIC_RSHIFT"},
381 {R_HPPA_EXPR_F
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_L"},
382 {R_HPPA_EXPR_L
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_L"},
383 {R_HPPA_EXPR_R
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_R"},
384 {R_HPPA_EXPR_LS
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_LS"},
385 {R_HPPA_EXPR_RS
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_RS"},
386 {R_HPPA_EXPR_LD
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_LD"},
387 {R_HPPA_EXPR_RD
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_RD"},
388 {R_HPPA_EXPR_LR
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_LR"},
389 {R_HPPA_EXPR_RR
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_RR"},
390 {R_HPPA_EXPR_32
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_32"},
391 {R_HPPA_EXPR_21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_21"},
392 {R_HPPA_EXPR_11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_11"},
393 {R_HPPA_EXPR_14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_14"},
394 {R_HPPA_EXPR_17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_17"},
395 {R_HPPA_EXPR_12
, 0, 3, 12, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_12"},
396 {R_HPPA_STUB_CALL_17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_STUB_CALL_17"},
397 {R_HPPA_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_dont
, NULL
, "R_HPPA_UNIMPLEMENTED"},
400 static symext_chainS
*symext_rootP
;
401 static symext_chainS
*symext_lastP
;
402 static boolean symext_chain_built
;
403 static long global_value
;
404 static long GOT_value
;
405 static asymbol
*global_symbol
;
406 static int global_sym_defined
;
407 static symext_entryS
*symextn_contents
;
408 static unsigned int symextn_contents_real_size
;
409 static elf32_hppa_stub_description
*elf_hppa_stub_rootP
;
410 static boolean stubs_finished
= false;
411 static struct elf32_hppa_symextn_map_struct
*elf32_hppa_symextn_map
;
412 static int elf32_hppa_symextn_map_size
;
414 static char *linker_stubs
= NULL
;
415 static int linker_stubs_size
= 0;
416 static int linker_stubs_max_size
= 0;
417 #define STUB_ALLOC_INCR 100
418 #define STUB_SYM_BUFFER_INC 5
420 /* Relocate the given INSN given the various input parameters.
422 FIXME: endianness and sizeof (long) issues abound here. */
425 hppa_elf_relocate_insn (abfd
, input_sect
, insn
, address
, sym_value
,
426 r_addend
, r_format
, r_field
, pcrel
)
428 asection
*input_sect
;
430 unsigned long address
;
433 unsigned long r_format
;
434 unsigned long r_field
;
437 unsigned char opcode
= get_opcode (insn
);
458 constant_value
= HPPA_R_CONSTANT (r_addend
);
461 sym_value
-= address
;
463 sym_value
= hppa_field_adjust (sym_value
, constant_value
, r_field
);
464 return hppa_rebuild_insn (abfd
, insn
, sym_value
, r_format
);
469 arg_reloc
= HPPA_R_ARG_RELOC (r_addend
);
471 /* XXX computing constant_value is not needed??? */
472 constant_value
= assemble_17 ((insn
& 0x001f0000) >> 16,
473 (insn
& 0x00001ffc) >> 2,
476 constant_value
= (constant_value
<< 15) >> 15;
480 address
+ input_sect
->output_offset
481 + input_sect
->output_section
->vma
;
482 sym_value
= hppa_field_adjust (sym_value
, -8, r_field
);
485 sym_value
= hppa_field_adjust (sym_value
, constant_value
, r_field
);
487 return hppa_rebuild_insn (abfd
, insn
, sym_value
>> 2, r_format
);
492 constant_value
= HPPA_R_CONSTANT (r_addend
);
495 sym_value
-= address
;
497 return hppa_field_adjust (sym_value
, constant_value
, r_field
);
504 /* Relocate a single unwind entry, or an entire table of them. */
507 hppa_elf_relocate_unwind_table (abfd
, data
, address
, sym_value
,
508 r_addend
, r_type
, r_field
)
511 unsigned long address
;
514 unsigned long r_type
;
515 unsigned long r_field
;
517 bfd_byte
*hit_data
= address
+ (bfd_byte
*) data
;
520 long relocated_value
;
525 case R_HPPA_UNWIND_ENTRY
:
526 /* Need to relocate the first two 32bit fields in the unwind. They
527 correspond to a function's start and end address. */
528 start_offset
= bfd_get_32 (abfd
, hit_data
);
529 relocated_value
= hppa_field_adjust (sym_value
, start_offset
, r_field
);
530 bfd_put_32 (abfd
, relocated_value
, hit_data
);
532 hit_data
+= sizeof (unsigned long);
533 end_offset
= bfd_get_32 (abfd
, hit_data
);
534 relocated_value
= hppa_field_adjust (sym_value
, end_offset
, r_field
);
535 bfd_put_32 (abfd
, relocated_value
, hit_data
);
538 case R_HPPA_UNWIND_ENTRIES
:
539 /* Relocate a mass of unwind entires. The count is passed in r_addend
540 (who's braindamaged idea was this anyway? */
541 for (i
= 0; i
< r_addend
; i
++, hit_data
+= 3 * sizeof (unsigned long))
543 unsigned int adjustment
;
544 /* Adjust the first 32bit field in the unwind entry. It's
545 the starting offset of a function. */
546 start_offset
= bfd_get_32 (abfd
, hit_data
);
547 bfd_put_32 (abfd
, sym_value
, hit_data
);
548 adjustment
= sym_value
- start_offset
;
550 /* Now adjust the second 32bit field, it's the ending offset
552 hit_data
+= sizeof (unsigned long);
553 end_offset
= adjustment
+ bfd_get_32 (abfd
, hit_data
);
554 bfd_put_32 (abfd
, end_offset
, hit_data
);
556 /* Prepare for the next iteration. */
557 start_offset
= bfd_get_32 (abfd
,
558 hit_data
+ 3 * sizeof (unsigned long));
559 sym_value
= start_offset
+ adjustment
;
568 /* Return the relocated value of the given symbol. */
571 get_symbol_value (symbol
)
575 || symbol
->section
== &bfd_com_section
)
578 return symbol
->value
+ symbol
->section
->output_section
->vma
579 + symbol
->section
->output_offset
;
582 /* Return one (or more) BFD relocations which implement the base
583 relocation with modifications based on format and field. */
585 elf32_hppa_reloc_type
**
586 hppa_elf_gen_reloc_type (abfd
, base_type
, format
, field
)
588 elf32_hppa_reloc_type base_type
;
592 elf32_hppa_reloc_type
*finaltype
;
593 elf32_hppa_reloc_type
**final_types
;
595 /* Allocate slots for the BFD relocation. */
596 final_types
= (elf32_hppa_reloc_type
**)
597 bfd_alloc_by_size_t (abfd
, sizeof (elf32_hppa_reloc_type
*) * 2);
598 BFD_ASSERT (final_types
!= 0); /* FIXME */
600 /* Allocate space for the relocation itself. */
601 finaltype
= (elf32_hppa_reloc_type
*)
602 bfd_alloc_by_size_t (abfd
, sizeof (elf32_hppa_reloc_type
));
603 BFD_ASSERT (finaltype
!= 0); /* FIXME */
605 /* Some reasonable defaults. */
606 final_types
[0] = finaltype
;
607 final_types
[1] = NULL
;
609 #define final_type finaltype[0]
611 final_type
= base_type
;
613 /* Just a tangle of nested switch statements to deal with the braindamage
614 that a different field selector means a completely different relocation
625 final_type
= R_HPPA_11
;
628 final_type
= R_HPPA_R11
;
631 final_type
= R_HPPA_RS11
;
634 final_type
= R_HPPA_RD11
;
637 final_type
= R_HPPA_PLABEL_11
;
640 final_type
= R_HPPA_PLABEL_R11
;
643 final_type
= R_HPPA_DLT_11
;
646 final_type
= R_HPPA_DLT_R11
;
658 final_type
= R_HPPA_R14
;
661 final_type
= R_HPPA_RS14
;
664 final_type
= R_HPPA_RD14
;
667 final_type
= R_HPPA_RR14
;
670 final_type
= R_HPPA_PLABEL_14
;
673 final_type
= R_HPPA_PLABEL_R14
;
676 final_type
= R_HPPA_DLT_14
;
679 final_type
= R_HPPA_DLT_R14
;
691 final_type
= R_HPPA_17
;
694 final_type
= R_HPPA_R17
;
697 final_type
= R_HPPA_RS17
;
700 final_type
= R_HPPA_RD17
;
703 final_type
= R_HPPA_RR17
;
715 final_type
= R_HPPA_L21
;
718 final_type
= R_HPPA_LS21
;
721 final_type
= R_HPPA_LD21
;
724 final_type
= R_HPPA_LR21
;
727 final_type
= R_HPPA_PLABEL_L21
;
730 final_type
= R_HPPA_PLABEL_L21
;
742 final_type
= R_HPPA_32
;
745 final_type
= R_HPPA_PLABEL_32
;
748 final_type
= R_HPPA_DLT_32
;
770 final_type
= R_HPPA_GOTOFF_R11
;
773 final_type
= R_HPPA_GOTOFF_RS11
;
776 final_type
= R_HPPA_GOTOFF_RD11
;
779 final_type
= R_HPPA_GOTOFF_11
;
791 final_type
= R_HPPA_GOTOFF_R14
;
794 final_type
= R_HPPA_GOTOFF_RS14
;
797 final_type
= R_HPPA_GOTOFF_RD14
;
800 final_type
= R_HPPA_GOTOFF_RR14
;
803 final_type
= R_HPPA_GOTOFF_14
;
815 final_type
= R_HPPA_GOTOFF_L21
;
818 final_type
= R_HPPA_GOTOFF_LS21
;
821 final_type
= R_HPPA_GOTOFF_LD21
;
824 final_type
= R_HPPA_GOTOFF_LR21
;
839 case R_HPPA_PCREL_CALL
:
846 final_type
= R_HPPA_PCREL_CALL_R11
;
849 final_type
= R_HPPA_PCREL_CALL_RS11
;
852 final_type
= R_HPPA_PCREL_CALL_RD11
;
855 final_type
= R_HPPA_PCREL_CALL_11
;
867 final_type
= R_HPPA_PCREL_CALL_R14
;
870 final_type
= R_HPPA_PCREL_CALL_RS14
;
873 final_type
= R_HPPA_PCREL_CALL_RD14
;
876 final_type
= R_HPPA_PCREL_CALL_RR14
;
879 final_type
= R_HPPA_PCREL_CALL_14
;
891 final_type
= R_HPPA_PCREL_CALL_R17
;
894 final_type
= R_HPPA_PCREL_CALL_RS17
;
897 final_type
= R_HPPA_PCREL_CALL_RD17
;
900 final_type
= R_HPPA_PCREL_CALL_RR17
;
903 final_type
= R_HPPA_PCREL_CALL_17
;
915 final_type
= R_HPPA_PCREL_CALL_L21
;
918 final_type
= R_HPPA_PCREL_CALL_LS21
;
921 final_type
= R_HPPA_PCREL_CALL_LD21
;
924 final_type
= R_HPPA_PCREL_CALL_LR21
;
946 final_type
= R_HPPA_PLABEL_11
;
949 final_type
= R_HPPA_PLABEL_R11
;
961 final_type
= R_HPPA_PLABEL_14
;
964 final_type
= R_HPPA_PLABEL_R14
;
976 final_type
= R_HPPA_PLABEL_L21
;
988 final_type
= R_HPPA_PLABEL_32
;
1002 case R_HPPA_ABS_CALL
:
1009 final_type
= R_HPPA_ABS_CALL_R11
;
1012 final_type
= R_HPPA_ABS_CALL_RS11
;
1015 final_type
= R_HPPA_ABS_CALL_RD11
;
1018 final_type
= R_HPPA_ABS_CALL_11
;
1030 final_type
= R_HPPA_ABS_CALL_R14
;
1033 final_type
= R_HPPA_ABS_CALL_RS14
;
1036 final_type
= R_HPPA_ABS_CALL_RD14
;
1039 final_type
= R_HPPA_ABS_CALL_RR14
;
1042 final_type
= R_HPPA_ABS_CALL_14
;
1054 final_type
= R_HPPA_ABS_CALL_R17
;
1057 final_type
= R_HPPA_ABS_CALL_RS17
;
1060 final_type
= R_HPPA_ABS_CALL_RD17
;
1063 final_type
= R_HPPA_ABS_CALL_RR17
;
1066 final_type
= R_HPPA_ABS_CALL_17
;
1078 final_type
= R_HPPA_ABS_CALL_L21
;
1081 final_type
= R_HPPA_ABS_CALL_LS21
;
1084 final_type
= R_HPPA_ABS_CALL_LD21
;
1087 final_type
= R_HPPA_ABS_CALL_LR21
;
1103 final_type
= R_HPPA_UNWIND_ENTRY
;
1107 case R_HPPA_COMPLEX
:
1108 case R_HPPA_COMPLEX_PCREL_CALL
:
1109 case R_HPPA_COMPLEX_ABS_CALL
:
1110 /* The code originally here was horribly broken, and apparently
1111 never used. Zap it. When we need complex relocations rewrite
1117 final_type
= base_type
;
1127 /* Actually perform a relocation. */
1129 static bfd_reloc_status_type
1130 hppa_elf_reloc (abfd
, reloc_entry
, symbol_in
, data
, input_section
, output_bfd
,
1133 arelent
*reloc_entry
;
1136 asection
*input_section
;
1138 char **error_message
;
1142 unsigned long addr
= reloc_entry
->address
;
1143 bfd_byte
*hit_data
= addr
+ (bfd_byte
*) data
;
1144 unsigned long r_type
= reloc_entry
->howto
->type
;
1145 unsigned long r_field
= e_fsel
;
1146 boolean r_pcrel
= reloc_entry
->howto
->pc_relative
;
1147 unsigned r_format
= reloc_entry
->howto
->bitsize
;
1148 long r_addend
= reloc_entry
->addend
;
1150 /* If only performing a partial link, get out early. */
1153 reloc_entry
->address
+= input_section
->output_offset
;
1154 return bfd_reloc_ok
;
1157 /* If performing final link and the symbol we're relocating against
1158 is undefined, then return an error. */
1159 if (symbol_in
&& symbol_in
->section
== &bfd_und_section
)
1160 return bfd_reloc_undefined
;
1162 /* Get the final relocated value. */
1163 sym_value
= get_symbol_value (symbol_in
);
1165 /* Compute the value of $global$.
1166 FIXME: None of this should be necessary. $global$ is just a
1167 marker and shouldn't really figure into these computations.
1169 Once that's fixed we'll need to teach this backend to change
1170 DP-relative relocations involving symbols in the text section
1171 to be simple absolute relocations. */
1172 if (!global_sym_defined
)
1176 global_value
= (global_symbol
->value
1177 + global_symbol
->section
->output_section
->vma
1178 + global_symbol
->section
->output_offset
);
1179 GOT_value
= global_value
;
1180 global_sym_defined
++;
1184 /* Get the instruction word. */
1185 insn
= bfd_get_32 (abfd
, hit_data
);
1187 /* Relocate the value based on one of the basic relocation types
1189 basic_type_1: relocation is relative to $global$
1190 basic_type_2: relocation is relative to the current GOT
1191 basic_type_3: relocation is an absolute call
1192 basic_type_4: relocation is an PC-relative call
1193 basic_type_5: relocation is plabel reference
1194 basic_type_6: relocation is an unwind table relocation
1195 extended_type: unimplemented */
1202 /* Handle all the basic type 1 relocations. */
1208 goto do_basic_type_1
;
1211 goto do_basic_type_1
;
1216 goto do_basic_type_1
;
1219 goto do_basic_type_1
;
1224 goto do_basic_type_1
;
1227 goto do_basic_type_1
;
1232 goto do_basic_type_1
;
1235 goto do_basic_type_1
;
1241 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
, addr
,
1242 sym_value
, r_addend
, r_format
,
1246 /* Handle all the basic type 2 relocations. */
1247 case R_HPPA_GOTOFF_11
:
1248 case R_HPPA_GOTOFF_14
:
1250 goto do_basic_type_2
;
1251 case R_HPPA_GOTOFF_L21
:
1253 goto do_basic_type_2
;
1254 case R_HPPA_GOTOFF_R11
:
1255 case R_HPPA_GOTOFF_R14
:
1257 goto do_basic_type_2
;
1258 case R_HPPA_GOTOFF_LS21
:
1260 goto do_basic_type_2
;
1261 case R_HPPA_GOTOFF_RS11
:
1262 case R_HPPA_GOTOFF_RS14
:
1264 goto do_basic_type_2
;
1265 case R_HPPA_GOTOFF_LD21
:
1267 goto do_basic_type_2
;
1268 case R_HPPA_GOTOFF_RD11
:
1269 case R_HPPA_GOTOFF_RD14
:
1271 goto do_basic_type_2
;
1272 case R_HPPA_GOTOFF_LR21
:
1274 goto do_basic_type_2
;
1275 case R_HPPA_GOTOFF_RR14
:
1279 sym_value
-= GOT_value
;
1280 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
, addr
,
1281 sym_value
, r_addend
, r_format
,
1285 /* Handle all the basic type 3 relocations. */
1286 case R_HPPA_ABS_CALL_11
:
1287 case R_HPPA_ABS_CALL_14
:
1288 case R_HPPA_ABS_CALL_17
:
1290 goto do_basic_type_3
;
1291 case R_HPPA_ABS_CALL_L21
:
1293 goto do_basic_type_3
;
1294 case R_HPPA_ABS_CALL_R11
:
1295 case R_HPPA_ABS_CALL_R14
:
1296 case R_HPPA_ABS_CALL_R17
:
1298 goto do_basic_type_3
;
1299 case R_HPPA_ABS_CALL_LS21
:
1301 goto do_basic_type_3
;
1302 case R_HPPA_ABS_CALL_RS11
:
1303 case R_HPPA_ABS_CALL_RS14
:
1304 case R_HPPA_ABS_CALL_RS17
:
1306 goto do_basic_type_3
;
1307 case R_HPPA_ABS_CALL_LD21
:
1309 goto do_basic_type_3
;
1310 case R_HPPA_ABS_CALL_RD11
:
1311 case R_HPPA_ABS_CALL_RD14
:
1312 case R_HPPA_ABS_CALL_RD17
:
1314 goto do_basic_type_3
;
1315 case R_HPPA_ABS_CALL_LR21
:
1317 goto do_basic_type_3
;
1318 case R_HPPA_ABS_CALL_RR14
:
1319 case R_HPPA_ABS_CALL_RR17
:
1323 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
, addr
,
1324 sym_value
, r_addend
, r_format
,
1328 /* Handle all the basic type 4 relocations. */
1329 case R_HPPA_PCREL_CALL_11
:
1330 case R_HPPA_PCREL_CALL_14
:
1331 case R_HPPA_PCREL_CALL_17
:
1333 goto do_basic_type_4
;
1334 case R_HPPA_PCREL_CALL_L21
:
1336 goto do_basic_type_4
;
1337 case R_HPPA_PCREL_CALL_R11
:
1338 case R_HPPA_PCREL_CALL_R14
:
1339 case R_HPPA_PCREL_CALL_R17
:
1341 goto do_basic_type_4
;
1342 case R_HPPA_PCREL_CALL_LS21
:
1344 goto do_basic_type_4
;
1345 case R_HPPA_PCREL_CALL_RS11
:
1346 case R_HPPA_PCREL_CALL_RS14
:
1347 case R_HPPA_PCREL_CALL_RS17
:
1349 goto do_basic_type_4
;
1350 case R_HPPA_PCREL_CALL_LD21
:
1352 goto do_basic_type_4
;
1353 case R_HPPA_PCREL_CALL_RD11
:
1354 case R_HPPA_PCREL_CALL_RD14
:
1355 case R_HPPA_PCREL_CALL_RD17
:
1357 goto do_basic_type_4
;
1358 case R_HPPA_PCREL_CALL_LR21
:
1360 goto do_basic_type_4
;
1361 case R_HPPA_PCREL_CALL_RR14
:
1362 case R_HPPA_PCREL_CALL_RR17
:
1366 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
, addr
,
1367 sym_value
, r_addend
, r_format
,
1371 /* Handle all the basic type 5 relocations. */
1372 case R_HPPA_PLABEL_32
:
1373 case R_HPPA_PLABEL_11
:
1374 case R_HPPA_PLABEL_14
:
1376 goto do_basic_type_5
;
1377 case R_HPPA_PLABEL_L21
:
1379 goto do_basic_type_5
;
1380 case R_HPPA_PLABEL_R11
:
1381 case R_HPPA_PLABEL_R14
:
1384 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
, addr
,
1385 sym_value
, r_addend
, r_format
,
1389 /* Handle all basic type 6 relocations. */
1390 case R_HPPA_UNWIND_ENTRY
:
1391 case R_HPPA_UNWIND_ENTRIES
:
1392 hppa_elf_relocate_unwind_table (abfd
, data
, addr
,
1393 sym_value
, r_addend
,
1395 return bfd_reloc_ok
;
1397 /* This is a linker internal relocation. */
1398 case R_HPPA_STUB_CALL_17
:
1399 /* This relocation is for a branch to a long branch stub.
1400 Change instruction to a BLE,N. It may also be necessary
1401 to interchange the branch and its delay slot.
1402 The original instruction stream is
1404 bl <foo>,r ; call foo using register r as
1405 ; the return pointer
1406 XXX ; delay slot instruction
1408 The new instruction stream will be:
1410 XXX ; delay slot instruction
1411 ble <foo_stub> ; call the long call stub for foo
1412 ; using r31 as the return pointer
1414 This braindamage is necessary because the compiler may put
1415 an instruction which uses %r31 in the delay slot of the original
1416 call. By changing the call instruction from a "bl" to a "ble"
1417 %r31 gets clobbered before the delay slot executes. This
1418 also means the stub has to play funny games to make sure
1419 we return to the instruction just after the BLE rather than
1420 two instructions after the BLE.
1422 We do not interchange the branch and delay slot if the delay
1423 slot was already nullified, or if the instruction in the delay
1424 slot modifies the return pointer to avoid an unconditional
1425 jump after the call returns (GCC optimization).
1427 None of this horseshit would be necessary if we put the
1428 stubs between functions and just redirected the "bl" to
1429 the stub. Live and learn. */
1431 /* Is this instruction nullified? (does this ever happen?) */
1434 insn
= BLE_N_XXX_0_0
;
1435 bfd_put_32 (abfd
, insn
, hit_data
);
1436 r_type
= R_HPPA_ABS_CALL_17
;
1438 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1439 addr
, sym_value
, r_addend
,
1440 r_format
, r_field
, r_pcrel
);
1444 /* So much for the trivial case... */
1445 unsigned long old_delay_slot_insn
= bfd_get_32 (abfd
, hit_data
+ 4);
1446 unsigned rtn_reg
= (insn
& 0x03e00000) >> 21;
1448 if (get_opcode (old_delay_slot_insn
) == LDO
)
1450 unsigned ldo_src_reg
= (old_delay_slot_insn
& 0x03e00000) >> 21;
1451 unsigned ldo_target_reg
= (old_delay_slot_insn
& 0x001f0000) >> 16;
1453 /* If the target of the LDO is the same as the return
1454 register then there is no reordering. We can leave the
1455 instuction as a non-nullified BLE in this case.
1457 FIXME: This test looks wrong. If we had a ble using
1458 ldo_target_reg as the *source* we'd fuck this up. */
1459 if (ldo_target_reg
== rtn_reg
)
1461 unsigned long new_delay_slot_insn
= old_delay_slot_insn
;
1463 BFD_ASSERT (ldo_src_reg
== ldo_target_reg
);
1464 new_delay_slot_insn
&= 0xfc00ffff;
1465 new_delay_slot_insn
|= ((31 << 21) | (31 << 16));
1466 bfd_put_32 (abfd
, new_delay_slot_insn
, hit_data
+ 4);
1468 r_type
= R_HPPA_ABS_CALL_17
;
1470 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1471 addr
, sym_value
, r_addend
,
1472 r_format
, r_field
, r_pcrel
);
1473 bfd_put_32 (abfd
, insn
, hit_data
);
1474 return bfd_reloc_ok
;
1476 else if (rtn_reg
== 31)
1478 /* The return register is r31, so this is a millicode
1479 call. Do not perform any instruction reordering. */
1481 r_type
= R_HPPA_ABS_CALL_17
;
1483 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1487 bfd_put_32 (abfd
, insn
, hit_data
);
1488 return bfd_reloc_ok
;
1492 /* Check to see if the delay slot instruction has a
1493 relocation. If so, we need to change the address
1494 field of it because the instruction it relocates
1495 is going to be moved. Oh what a mess. */
1496 arelent
* next_reloc_entry
= reloc_entry
+1;
1498 if (next_reloc_entry
->address
== reloc_entry
->address
+ 4)
1499 next_reloc_entry
->address
-= 4;
1501 insn
= old_delay_slot_insn
;
1502 bfd_put_32 (abfd
, insn
, hit_data
);
1503 insn
= BLE_N_XXX_0_0
;
1504 bfd_put_32 (abfd
, insn
, hit_data
+ 4);
1505 r_type
= R_HPPA_ABS_CALL_17
;
1507 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1509 sym_value
, r_addend
,
1510 r_format
, r_field
, r_pcrel
);
1511 bfd_put_32 (abfd
, insn
, hit_data
+ 4);
1512 return bfd_reloc_ok
;
1515 /* Same comments as above regarding incorrect test. */
1516 else if (rtn_reg
== 31)
1518 /* The return register is r31, so this is a millicode call.
1519 Perform no instruction reordering in this case. */
1521 r_type
= R_HPPA_ABS_CALL_17
;
1523 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1527 bfd_put_32 (abfd
, insn
, hit_data
);
1528 return bfd_reloc_ok
;
1532 /* Check to see if the delay slot instruction has a
1533 relocation. If so, we need to change its address
1534 field because the instruction it relocates is going
1536 arelent
* next_reloc_entry
= reloc_entry
+1;
1538 if (next_reloc_entry
->address
== reloc_entry
->address
+ 4)
1539 next_reloc_entry
->address
-= 4;
1541 insn
= old_delay_slot_insn
;
1542 bfd_put_32 (abfd
, insn
, hit_data
);
1543 insn
= BLE_N_XXX_0_0
;
1544 bfd_put_32 (abfd
, insn
, hit_data
+ 4);
1545 r_type
= R_HPPA_ABS_CALL_17
;
1547 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1548 addr
+ 4, sym_value
,
1551 bfd_put_32 (abfd
, insn
, hit_data
+ 4);
1552 return bfd_reloc_ok
;
1557 /* Something we don't know how to handle. */
1559 *error_message
= (char *) "Unrecognized reloc";
1560 return bfd_reloc_notsupported
;
1563 /* Update the instruction word. */
1564 bfd_put_32 (abfd
, insn
, hit_data
);
1565 return (bfd_reloc_ok
);
1568 /* Return the address of the howto table entry to perform the CODE
1569 relocation for an ARCH machine. */
1571 static CONST reloc_howto_type
*
1572 elf_hppa_reloc_type_lookup (arch
, code
)
1573 bfd_arch_info_type
*arch
;
1574 bfd_reloc_code_real_type code
;
1576 if ((int) code
< (int) R_HPPA_UNIMPLEMENTED
)
1578 BFD_ASSERT ((int) elf_hppa_howto_table
[(int) code
].type
== (int) code
);
1579 return &elf_hppa_howto_table
[(int) code
];
1585 /* Update the symbol extention chain to include the symbol pointed to
1586 by SYMBOLP if SYMBOLP is a function symbol. Used internally and by GAS. */
1589 elf_hppa_tc_symbol (abfd
, symbolP
, sym_idx
, symext_root
, symext_last
)
1591 elf_symbol_type
*symbolP
;
1593 symext_chainS
**symext_root
;
1594 symext_chainS
**symext_last
;
1596 symext_chainS
*symextP
;
1597 unsigned int arg_reloc
;
1599 /* Only functions can have argument relocations. */
1600 if (!(symbolP
->symbol
.flags
& BSF_FUNCTION
))
1603 arg_reloc
= symbolP
->tc_data
.hppa_arg_reloc
;
1605 /* If there are no argument relocation bits, then no relocation is
1606 necessary. Do not add this to the symextn section. */
1610 /* Allocate memory and initialize this entry. */
1611 symextP
= (symext_chainS
*) bfd_alloc (abfd
, sizeof (symext_chainS
) * 2);
1614 bfd_set_error (bfd_error_no_memory
);
1615 abort(); /* FIXME */
1618 symextP
[0].entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX
, sym_idx
);
1619 symextP
[0].next
= &symextP
[1];
1621 symextP
[1].entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_ARG_RELOC
, arg_reloc
);
1622 symextP
[1].next
= NULL
;
1624 /* Now update the chain itself so it can be walked later to build
1625 the symbol extension section. */
1626 if (*symext_root
== NULL
)
1628 *symext_root
= &symextP
[0];
1629 *symext_last
= &symextP
[1];
1633 (*symext_last
)->next
= &symextP
[0];
1634 *symext_last
= &symextP
[1];
1638 /* Build the symbol extension section. Used internally and by GAS. */
1641 elf_hppa_tc_make_sections (abfd
, symext_root
)
1643 symext_chainS
*symext_root
;
1645 symext_chainS
*symextP
;
1647 asection
*symextn_sec
;
1649 /* FIXME: Huh? I don't see what this is supposed to do for us. */
1650 hppa_elf_stub_finish (abfd
);
1652 /* If there are no entries in the symbol extension chain, then
1653 there is no symbol extension section. */
1654 if (symext_root
== NULL
)
1657 /* Count the number of entries on the chain. */
1658 for (n
= 0, symextP
= symext_root
; symextP
; symextP
= symextP
->next
, ++n
)
1661 /* Create the symbol extension section and set some appropriate
1663 size
= sizeof (symext_entryS
) * n
;
1664 symextn_sec
= bfd_get_section_by_name (abfd
, SYMEXTN_SECTION_NAME
);
1665 if (symextn_sec
== (asection
*) 0)
1667 symextn_sec
= bfd_make_section (abfd
, SYMEXTN_SECTION_NAME
);
1668 bfd_set_section_flags (abfd
,
1670 SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_DATA
);
1671 symextn_sec
->output_section
= symextn_sec
;
1672 symextn_sec
->output_offset
= 0;
1673 bfd_set_section_alignment (abfd
, symextn_sec
, 2);
1675 bfd_set_section_size (abfd
, symextn_sec
, symextn_contents_real_size
);
1676 symextn_contents_real_size
= size
;
1678 /* Grab some memory for the contents of the symbol extension section
1680 symextn_contents
= (symext_entryS
*) bfd_alloc (abfd
, size
);
1681 if (!symextn_contents
)
1683 bfd_set_error (bfd_error_no_memory
);
1684 abort(); /* FIXME */
1687 /* Fill in the contents of the symbol extension section. */
1688 for (i
= 0, symextP
= symext_root
; symextP
; symextP
= symextP
->next
, ++i
)
1689 symextn_contents
[i
] = symextP
->entry
;
1694 /* Return the symbol extension record of type TYPE for the symbol SYM. */
1696 static symext_entryS
1697 elf32_hppa_get_sym_extn (abfd
, sym
, type
)
1704 case HPPA_SXT_SYMNDX
:
1706 return (symext_entryS
) 0;
1707 case HPPA_SXT_ARG_RELOC
:
1709 elf_symbol_type
*esymP
= (elf_symbol_type
*) sym
;
1711 return (symext_entryS
) esymP
->tc_data
.hppa_arg_reloc
;
1713 /* This should never happen. */
1719 /* Search the chain of stub descriptions and locate the stub
1720 description for this the given section within the given bfd.
1722 FIXME: I see yet another wonderful linear linked list search
1723 here. This is probably bad. */
1725 static elf32_hppa_stub_description
*
1726 find_stubs (abfd
, stub_sec
)
1730 elf32_hppa_stub_description
*stubP
;
1732 for (stubP
= elf_hppa_stub_rootP
; stubP
; stubP
= stubP
->next
)
1734 /* Is this the right one? */
1735 if (stubP
->this_bfd
== abfd
&& stubP
->stub_sec
== stub_sec
)
1741 static elf32_hppa_stub_description
*
1742 new_stub (abfd
, stub_sec
, link_info
)
1745 struct bfd_link_info
*link_info
;
1747 elf32_hppa_stub_description
*stub
= find_stubs (abfd
, stub_sec
);
1749 /* If we found a list for this bfd, then use it. */
1753 /* Nope, allocate and initialize a new entry in the stub list chain. */
1754 stub
= (elf32_hppa_stub_description
*)
1755 bfd_zalloc (abfd
, sizeof (elf32_hppa_stub_description
));
1758 stub
->this_bfd
= abfd
;
1759 stub
->stub_sec
= stub_sec
;
1760 stub
->real_size
= 0;
1761 stub
->allocated_size
= 0;
1762 stub
->stub_contents
= NULL
;
1763 stub
->stub_secp
= NULL
;
1764 stub
->link_info
= link_info
;
1766 stub
->next
= elf_hppa_stub_rootP
;
1767 elf_hppa_stub_rootP
= stub
;
1771 bfd_set_error (bfd_error_no_memory
);
1772 abort(); /* FIXME */
1778 /* Try and locate a stub with the name NAME within the stubs
1779 associated with ABFD. More linked list searches. */
1781 static elf32_hppa_stub_name_list
*
1782 find_stub_by_name (abfd
, stub_sec
, name
)
1787 /* Find the stubs associated with this bfd. */
1788 elf32_hppa_stub_description
*stub
= find_stubs (abfd
, stub_sec
);
1790 /* If found, then we have to walk down them looking for a match. */
1793 elf32_hppa_stub_name_list
*name_listP
;
1795 for (name_listP
= stub
->stub_listP
;
1797 name_listP
= name_listP
->next
)
1799 if (!strcmp (name_listP
->sym
->name
, name
))
1808 /* Add a new stub (SYM) to the list of stubs associated with the given BFD. */
1809 static elf32_hppa_stub_name_list
*
1810 add_stub_by_name(abfd
, stub_sec
, sym
, link_info
)
1814 struct bfd_link_info
*link_info
;
1816 elf32_hppa_stub_description
*stub
= find_stubs (abfd
, stub_sec
);
1817 elf32_hppa_stub_name_list
*stub_entry
;
1819 /* If no stubs are associated with this bfd, then we have to make
1820 a chain-of-stubs associated with this bfd. */
1822 stub
= new_stub (abfd
, stub_sec
, link_info
);
1826 /* Allocate and initialize an entry in the stub chain. */
1827 stub_entry
= (elf32_hppa_stub_name_list
*)
1828 bfd_zalloc (abfd
, sizeof (elf32_hppa_stub_name_list
));
1832 stub_entry
->size
= 0;
1833 stub_entry
->sym
= sym
;
1834 stub_entry
->stub_desc
= stub
;
1835 /* First byte of this stub is the pointer to
1836 the next available location in the stub buffer. */
1837 stub_entry
->stub_secp
= stub
->stub_secp
;
1838 /* Add it to the chain. */
1839 if (stub
->stub_listP
)
1840 stub_entry
->next
= stub
->stub_listP
;
1842 stub_entry
->next
= NULL
;
1843 stub
->stub_listP
= stub_entry
;
1848 bfd_set_error (bfd_error_no_memory
);
1849 abort(); /* FIXME */
1852 /* Death by mis-adventure. */
1854 return (elf32_hppa_stub_name_list
*)NULL
;
1857 /* For the given caller/callee argument location information and the
1858 type of relocation (arguments or return value), return the type
1859 of argument relocation needed to make caller and callee happy. */
1861 static arg_reloc_type
1862 type_of_mismatch (caller_bits
, callee_bits
, type
)
1870 return mismatches
[caller_bits
][callee_bits
];
1872 return retval_mismatches
[caller_bits
][callee_bits
];
1874 return ARG_RELOC_ERR
;
1877 /* Extract specific argument location bits for WHICH from the
1878 the full argument location information in AR. */
1879 #define EXTRACT_ARBITS(ar, which) ((ar) >> (8 - ((which) * 2))) & 3
1881 /* Add the new instruction INSN into the stub area denoted by ENTRY.
1882 FIXME: Looks like more cases where we assume sizeof (int) ==
1883 sizeof (insn) which may not be true if building cross tools. */
1884 #define NEW_INSTRUCTION(entry, insn) \
1886 *((entry)->stub_desc->stub_secp)++ = (insn); \
1887 (entry)->stub_desc->real_size += sizeof (int); \
1888 (entry)->size += sizeof(int); \
1889 bfd_set_section_size((entry)->stub_desc->this_bfd, \
1890 (entry)->stub_desc->stub_sec, \
1891 (entry)->stub_desc->real_size); \
1894 /* Find the offset of the current stub? Looks more like it
1895 finds the offset of the last instruction to me. */
1896 #define CURRENT_STUB_OFFSET(entry) \
1897 ((char *)(entry)->stub_desc->stub_secp \
1898 - (char *)(entry)->stub_desc->stub_contents - 4)
1900 /* All the stubs have already been built, finish up stub stuff
1901 by applying relocations to the stubs. */
1904 hppa_elf_stub_finish (output_bfd
)
1907 elf32_hppa_stub_description
*stub_list
= elf_hppa_stub_rootP
;
1909 /* If the stubs have been finished, then we're already done. */
1913 /* Walk down the list of stub lists. */
1914 for (; stub_list
; stub_list
= stub_list
->next
)
1916 /* If this list has stubs, then do something. */
1917 if (stub_list
->real_size
)
1919 bfd
*stub_bfd
= stub_list
->this_bfd
;
1920 asection
*stub_sec
= bfd_get_section_by_name (stub_bfd
,
1921 ".hppa_linker_stubs");
1922 bfd_size_type reloc_size
;
1923 arelent
**reloc_vector
;
1925 /* Some sanity checking. */
1926 BFD_ASSERT (stub_sec
== stub_list
->stub_sec
);
1927 BFD_ASSERT (stub_sec
);
1929 /* For stub sections raw_size == cooked_size. Also update
1930 reloc_done as we're handling the relocs now. */
1931 stub_sec
->_cooked_size
= stub_sec
->_raw_size
;
1932 stub_sec
->reloc_done
= true;
1934 /* Make space to hold the relocations for the stub section. */
1935 reloc_size
= bfd_get_reloc_upper_bound (stub_bfd
, stub_sec
);
1936 reloc_vector
= (arelent
**) malloc (reloc_size
);
1937 if (reloc_vector
== NULL
)
1939 /* FIXME: should be returning an error so the caller can
1944 /* If we have relocations, do them. */
1945 if (bfd_canonicalize_reloc (stub_bfd
, stub_sec
, reloc_vector
,
1946 output_bfd
->outsymbols
))
1949 for (parent
= reloc_vector
; *parent
!= NULL
; parent
++)
1952 bfd_reloc_status_type r
=
1953 bfd_perform_relocation (stub_bfd
, *parent
,
1954 stub_list
->stub_contents
,
1955 stub_sec
, (bfd
*) NULL
, &err
);
1957 /* If there was an error, tell someone about it. */
1958 if (r
!= bfd_reloc_ok
)
1960 struct bfd_link_info
*link_info
= stub_list
->link_info
;
1964 case bfd_reloc_undefined
:
1965 if (! ((*link_info
->callbacks
->undefined_symbol
)
1967 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
1968 stub_bfd
, stub_sec
, (*parent
)->address
)))
1971 case bfd_reloc_dangerous
:
1972 if (! ((*link_info
->callbacks
->reloc_dangerous
)
1973 (link_info
, err
, stub_bfd
, stub_sec
,
1974 (*parent
)->address
)))
1977 case bfd_reloc_overflow
:
1979 if (! ((*link_info
->callbacks
->reloc_overflow
)
1981 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
1982 (*parent
)->howto
->name
,
1985 (*parent
)->address
)))
1989 case bfd_reloc_outofrange
:
1997 free (reloc_vector
);
1999 /* All done with the relocations. Set the final contents
2000 of the stub section. FIXME: no check of return value! */
2001 bfd_set_section_contents (output_bfd
, stub_sec
,
2002 stub_list
->stub_contents
,
2003 0, stub_list
->real_size
);
2007 stubs_finished
= true;
2010 /* Allocate a new relocation entry to be used in a linker stub. */
2013 hppa_elf_stub_reloc (stub_desc
, output_bfd
, target_sym
, offset
, type
)
2014 elf32_hppa_stub_description
*stub_desc
;
2016 asymbol
**target_sym
;
2018 elf32_hppa_reloc_type type
;
2022 Elf_Internal_Shdr
*rela_hdr
;
2024 /* I really don't like the realloc nonsense in here. FIXME. */
2025 if (stub_desc
->relocs_allocated_cnt
== stub_desc
->stub_sec
->reloc_count
)
2027 /* Allocate the first few relocation entries. */
2028 if (stub_desc
->stub_sec
->relocation
== NULL
)
2030 stub_desc
->relocs_allocated_cnt
= STUB_RELOC_INCR
;
2031 size
= sizeof (arelent
) * stub_desc
->relocs_allocated_cnt
;
2032 stub_desc
->stub_sec
->relocation
= (arelent
*) bfd_zmalloc (size
);
2036 /* We've used all the entries we've already allocated. So get
2038 stub_desc
->relocs_allocated_cnt
+= STUB_RELOC_INCR
;
2039 size
= sizeof (arelent
) * stub_desc
->relocs_allocated_cnt
;
2040 stub_desc
->stub_sec
->relocation
= (arelent
*)
2041 realloc (stub_desc
->stub_sec
->relocation
, size
);
2043 if (!stub_desc
->stub_sec
->relocation
)
2045 bfd_set_error (bfd_error_no_memory
);
2046 abort (); /* FIXME */
2050 rela_hdr
= &elf_section_data(stub_desc
->stub_sec
)->rel_hdr
;
2051 rela_hdr
->sh_size
+= sizeof(Elf32_External_Rela
);
2053 /* Fill in the details. */
2054 relent
.address
= offset
;
2056 relent
.sym_ptr_ptr
= target_sym
;
2057 relent
.howto
= bfd_reloc_type_lookup (stub_desc
->this_bfd
, type
);
2059 /* Save it in the array of relocations for the stub section. */
2060 memcpy (&stub_desc
->stub_sec
->relocation
[stub_desc
->stub_sec
->reloc_count
++],
2061 &relent
, sizeof (arelent
));
2064 /* Build an argument relocation stub. RTN_ADJUST is a hint that an
2065 adjust to the return pointer from within the stub itself may be
2069 hppa_elf_build_linker_stub (abfd
, output_bfd
, link_info
, reloc_entry
,
2070 stub_types
, rtn_adjust
, data
, linker_stub_type
)
2073 struct bfd_link_info
*link_info
;
2074 arelent
*reloc_entry
;
2075 arg_reloc_type stub_types
[5];
2078 hppa_stub_type linker_stub_type
;
2081 boolean milli
, dyncall
;
2082 char stub_sym_name
[128];
2083 elf32_hppa_stub_name_list
*stub_entry
;
2084 /* Some initialization. */
2085 unsigned insn
= data
[0];
2086 asymbol
*stub_sym
= NULL
;
2087 asymbol
**orig_sym
= reloc_entry
->sym_ptr_ptr
;
2088 asection
*stub_sec
= bfd_get_section_by_name (abfd
, ".hppa_linker_stubs");
2089 elf32_hppa_stub_description
*stub_desc
= find_stubs (abfd
, stub_sec
);
2091 /* Perform some additional checks on whether we should really do the
2092 return adjustment. For example, if the instruction is nullified
2093 or if the delay slot contains an instruction that modifies the return
2094 pointer, then the branch instructions should not be rearranged
2095 (rtn_adjust is false). */
2096 if (insn
& 2 || insn
== 0)
2100 unsigned delay_insn
= data
[1];
2102 if (get_opcode (delay_insn
) == LDO
2103 && (((insn
& 0x03e00000) >> 21) == ((delay_insn
& 0x001f0000) >> 16)))
2107 /* Some special code for long-call stubs. */
2108 if (linker_stub_type
== HPPA_STUB_LONG_CALL
)
2111 /* Is this a millicode call? If so, the return address
2112 comes in on r31 rather than r2 (rp) so a slightly
2113 different code sequence is needed. */
2114 unsigned rtn_reg
= (insn
& 0x03e00000) >> 21;
2118 /* Dyncall is special because the user code has already
2119 put the return pointer in %r2 (aka RP). Other millicode
2120 calls have the return pointer in %r31. */
2121 if (strcmp ((*orig_sym
)->name
, "$$dyncall") == 0)
2124 /* If we are creating a call from a stub to another stub, then
2125 never do the instruction reordering. We can tell if we are
2126 going to be calling one stub from another by the fact that
2127 the symbol name has '_stub_' (arg. reloc. stub) or '_lb_stub_'
2128 prepended to the name. Alternatively, the section of the
2129 symbol will be '.hppa_linker_stubs'. This is only an issue
2130 for long-calls; they are the only stubs allowed to call another
2132 if ((strncmp ((*orig_sym
)->name
, "_stub_", 6) == 0)
2133 || (strncmp ((*orig_sym
)->name
, "_lb_stub_", 9) == 0))
2135 BFD_ASSERT (strcmp ((*orig_sym
)->section
->name
, ".hppa_linker_stubs")
2141 /* Create the stub section if necessary. */
2144 BFD_ASSERT (stub_desc
== NULL
);
2145 hppa_elf_create_stub_sec (abfd
, output_bfd
, &stub_sec
, link_info
);
2146 stub_desc
= new_stub (abfd
, stub_sec
, link_info
);
2149 /* Make the stub if we did not find one already. */
2151 stub_desc
= new_stub (abfd
, stub_sec
, link_info
);
2153 /* Allocate space to write the stub.
2154 FIXME: Why using realloc?!? */
2155 if (!stub_desc
->stub_contents
)
2157 stub_desc
->allocated_size
= STUB_BUFFER_INCR
;
2158 stub_desc
->stub_contents
= (char *) malloc (STUB_BUFFER_INCR
);
2160 else if ((stub_desc
->allocated_size
- stub_desc
->real_size
) < STUB_MAX_SIZE
)
2162 stub_desc
->allocated_size
= stub_desc
->allocated_size
+ STUB_BUFFER_INCR
;
2163 stub_desc
->stub_contents
= (char *) realloc (stub_desc
->stub_contents
,
2164 stub_desc
->allocated_size
);
2167 /* If no memory die. (I seriously doubt the other routines
2168 are prepared to get a NULL return value). */
2169 if (!stub_desc
->stub_contents
)
2171 bfd_set_error (bfd_error_no_memory
);
2175 /* Generate an appropriate name for this stub. */
2176 if (linker_stub_type
== HPPA_STUB_ARG_RELOC
)
2177 sprintf (stub_sym_name
,
2178 "_stub_%s_%02d_%02d_%02d_%02d_%02d_%s",
2179 reloc_entry
->sym_ptr_ptr
[0]->name
,
2180 stub_types
[0], stub_types
[1], stub_types
[2],
2181 stub_types
[3], stub_types
[4],
2182 rtn_adjust
? "RA" : "");
2184 sprintf (stub_sym_name
,
2185 "_lb_stub_%s_%s", reloc_entry
->sym_ptr_ptr
[0]->name
,
2186 rtn_adjust
? "RA" : "");
2189 stub_desc
->stub_secp
2190 = (int *) (stub_desc
->stub_contents
+ stub_desc
->real_size
);
2191 stub_entry
= find_stub_by_name (abfd
, stub_sec
, stub_sym_name
);
2193 /* See if we already have one by this name. */
2196 /* Yes, re-use it. Redirect the original relocation from the
2197 old symbol (a function symbol) to the stub (the stub will call
2198 the original function). */
2199 stub_sym
= stub_entry
->sym
;
2200 reloc_entry
->sym_ptr_ptr
= (asymbol
**) bfd_zalloc (abfd
,
2201 sizeof (asymbol
**));
2202 if (reloc_entry
->sym_ptr_ptr
== NULL
)
2204 bfd_set_error (bfd_error_no_memory
);
2207 reloc_entry
->sym_ptr_ptr
[0] = stub_sym
;
2208 if (linker_stub_type
== HPPA_STUB_LONG_CALL
2209 || (reloc_entry
->howto
->type
!= R_HPPA_PLABEL_32
2210 && (get_opcode(insn
) == BLE
2211 || get_opcode (insn
) == BE
2212 || get_opcode (insn
) == BL
)))
2213 reloc_entry
->howto
= bfd_reloc_type_lookup (abfd
, R_HPPA_STUB_CALL_17
);
2217 /* Create a new symbol to point to this stub. */
2218 stub_sym
= bfd_make_empty_symbol (abfd
);
2221 bfd_set_error (bfd_error_no_memory
);
2224 stub_sym
->name
= bfd_zalloc (abfd
, strlen (stub_sym_name
) + 1);
2225 if (!stub_sym
->name
)
2227 bfd_set_error (bfd_error_no_memory
);
2230 strcpy ((char *) stub_sym
->name
, stub_sym_name
);
2232 = (char *) stub_desc
->stub_secp
- (char *) stub_desc
->stub_contents
;
2233 stub_sym
->section
= stub_sec
;
2234 stub_sym
->flags
= BSF_LOCAL
| BSF_FUNCTION
;
2235 stub_entry
= add_stub_by_name (abfd
, stub_sec
, stub_sym
, link_info
);
2237 /* Redirect the original relocation from the old symbol (a function)
2238 to the stub (the stub calls the function). */
2239 reloc_entry
->sym_ptr_ptr
= (asymbol
**) bfd_zalloc (abfd
,
2240 sizeof (asymbol
**));
2241 if (reloc_entry
->sym_ptr_ptr
== NULL
)
2243 bfd_set_error (bfd_error_no_memory
);
2246 reloc_entry
->sym_ptr_ptr
[0] = stub_sym
;
2247 if (linker_stub_type
== HPPA_STUB_LONG_CALL
2248 || (reloc_entry
->howto
->type
!= R_HPPA_PLABEL_32
2249 && (get_opcode (insn
) == BLE
2250 || get_opcode (insn
) == BE
2251 || get_opcode (insn
) == BL
)))
2252 reloc_entry
->howto
= bfd_reloc_type_lookup (abfd
, R_HPPA_STUB_CALL_17
);
2254 /* Now generate the code for the stub. Starting with two
2255 common instructions.
2257 FIXME: Do we still need the SP adjustment?
2258 Do we still need to muck with space registers? */
2259 NEW_INSTRUCTION (stub_entry
, LDSID_31_1
)
2260 NEW_INSTRUCTION (stub_entry
, MTSP_1_SR0
)
2262 if (linker_stub_type
== HPPA_STUB_ARG_RELOC
)
2264 NEW_INSTRUCTION (stub_entry
, ADDI_8_SP
)
2266 /* Examine each argument, generating code to relocate it
2267 into a different register if necessary. */
2268 for (i
= ARG0
; i
< ARG3
; i
++)
2270 switch (stub_types
[i
])
2280 NEW_INSTRUCTION (stub_entry
, STWS_ARG0_M8SP
)
2281 NEW_INSTRUCTION (stub_entry
, FLDWS_M8SP_FARG0
)
2284 NEW_INSTRUCTION (stub_entry
, STWS_ARG1_M8SP
)
2285 NEW_INSTRUCTION (stub_entry
, FLDWS_M8SP_FARG1
)
2288 NEW_INSTRUCTION (stub_entry
, STWS_ARG2_M8SP
)
2289 NEW_INSTRUCTION (stub_entry
, FLDWS_M8SP_FARG2
)
2292 NEW_INSTRUCTION (stub_entry
, STWS_ARG3_M8SP
)
2293 NEW_INSTRUCTION (stub_entry
, FLDWS_M8SP_FARG3
)
2302 NEW_INSTRUCTION (stub_entry
, STWS_ARG0_M4SP
)
2303 NEW_INSTRUCTION (stub_entry
, STWS_ARG1_M8SP
)
2304 NEW_INSTRUCTION (stub_entry
, FLDDS_M8SP_FARG1
)
2316 NEW_INSTRUCTION (stub_entry
, STWS_ARG2_M4SP
)
2317 NEW_INSTRUCTION (stub_entry
, STWS_ARG3_M8SP
)
2318 NEW_INSTRUCTION (stub_entry
, FLDDS_M8SP_FARG3
)
2330 NEW_INSTRUCTION (stub_entry
, FSTWS_FARG0_M8SP
)
2331 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG0
)
2334 NEW_INSTRUCTION (stub_entry
, FSTWS_FARG1_M8SP
)
2335 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG1
)
2338 NEW_INSTRUCTION (stub_entry
, FSTWS_FARG2_M8SP
)
2339 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG2
)
2342 NEW_INSTRUCTION (stub_entry
, FSTWS_FARG3_M8SP
)
2343 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG3
)
2352 NEW_INSTRUCTION (stub_entry
, FSTDS_FARG1_M8SP
)
2353 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG0
)
2354 NEW_INSTRUCTION (stub_entry
, LDWS_M8SP_ARG1
)
2366 NEW_INSTRUCTION (stub_entry
, FSTDS_FARG3_M8SP
)
2367 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG2
)
2368 NEW_INSTRUCTION (stub_entry
, LDWS_M8SP_ARG3
)
2382 /* Put the stack pointer back. FIXME: Is this still necessary? */
2383 NEW_INSTRUCTION (stub_entry
, ADDI_M8_SP_SP
)
2386 /* Common code again. Return pointer adjustment and the like. */
2389 /* This isn't dyncall. */
2392 /* It's not a millicode call, so get the correct return
2393 value into %r2 (aka RP). */
2395 NEW_INSTRUCTION (stub_entry
, ADDI_M4_31_RP
)
2397 NEW_INSTRUCTION (stub_entry
, COPY_31_2
)
2401 /* It is a millicode call, so get the correct return
2402 value into %r1?!?. FIXME: Shouldn't this be
2403 %r31? Yes, and a little re-arrangement of the
2404 code below would make that possible. */
2406 NEW_INSTRUCTION (stub_entry
, ADDI_M4_31_1
)
2408 NEW_INSTRUCTION (stub_entry
, COPY_31_1
)
2413 /* This is dyncall, so the code is a little different as the
2414 return pointer is already in %r2 (aka RP). */
2416 NEW_INSTRUCTION (stub_entry
, ADDI_M4_31_RP
)
2419 /* Save the return address. */
2420 if (linker_stub_type
== HPPA_STUB_ARG_RELOC
)
2421 NEW_INSTRUCTION (stub_entry
, STW_RP_M8SP
)
2423 /* Long branch to the target function. */
2424 NEW_INSTRUCTION (stub_entry
, LDIL_XXX_31
)
2425 hppa_elf_stub_reloc (stub_entry
->stub_desc
,
2427 CURRENT_STUB_OFFSET (stub_entry
),
2429 NEW_INSTRUCTION (stub_entry
, BLE_XXX_0_31
)
2430 hppa_elf_stub_reloc (stub_entry
->stub_desc
,
2432 CURRENT_STUB_OFFSET (stub_entry
),
2433 R_HPPA_ABS_CALL_R17
);
2435 if (linker_stub_type
== HPPA_STUB_ARG_RELOC
)
2437 /* In delay slot of long-call, copy %r31 into %r2 so that
2438 the callee can return in the normal fashion. */
2439 NEW_INSTRUCTION (stub_entry
, COPY_31_2
)
2441 /* Restore the return address. */
2442 NEW_INSTRUCTION (stub_entry
, LDW_M8SP_RP
)
2444 /* Generate the code to move the return value around. */
2445 switch (stub_types
[RETVAL
])
2451 NEW_INSTRUCTION (stub_entry
, STWS_RET0_M8SP
)
2452 NEW_INSTRUCTION (stub_entry
, FLDWS_M8SP_FRET0
)
2456 NEW_INSTRUCTION (stub_entry
, FSTWS_FRET0_M8SP
)
2457 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_RET0
)
2465 /* Return back to the main code stream. */
2466 NEW_INSTRUCTION (stub_entry
, BV_N_0_RP
)
2472 /* Get return address into %r31. Both variants may be necessary
2473 (I think) as we could be cascading into another stub. */
2475 NEW_INSTRUCTION (stub_entry
, COPY_2_31
)
2477 NEW_INSTRUCTION (stub_entry
, COPY_1_31
)
2481 /* Get the return address into %r31 too. Might be necessary
2482 (I think) as we could be cascading into another stub. */
2483 NEW_INSTRUCTION (stub_entry
, COPY_2_31
)
2486 /* No need for a return to the main stream. */
2492 /* Return nonzero if an argument relocation will be needed to call
2493 the function (symbol in RELOC_ENTRY) assuming the caller has
2494 argument relocation bugs CALLER_AR. */
2497 hppa_elf_arg_reloc_needed_p (abfd
, reloc_entry
, stub_types
, caller_ar
)
2499 arelent
*reloc_entry
;
2500 arg_reloc_type stub_types
[5];
2501 symext_entryS caller_ar
;
2503 /* If the symbol is still undefined, then it's impossible to know
2504 if an argument relocation is needed. */
2505 if (reloc_entry
->sym_ptr_ptr
[0]
2506 && reloc_entry
->sym_ptr_ptr
[0]->section
!= &bfd_und_section
)
2508 symext_entryS callee_ar
= elf32_hppa_get_sym_extn (abfd
,
2509 reloc_entry
->sym_ptr_ptr
[0],
2510 HPPA_SXT_ARG_RELOC
);
2512 /* Now examine all the argument and return value location
2513 information to determine if a relocation stub will be needed. */
2514 if (caller_ar
&& callee_ar
)
2516 arg_location caller_loc
[5];
2517 arg_location callee_loc
[5];
2519 /* Extract the location information for the return value
2520 and argument registers separately. */
2521 callee_loc
[RETVAL
] = EXTRACT_ARBITS (callee_ar
, RETVAL
);
2522 caller_loc
[RETVAL
] = EXTRACT_ARBITS (caller_ar
, RETVAL
);
2523 callee_loc
[ARG0
] = EXTRACT_ARBITS (callee_ar
, ARG0
);
2524 caller_loc
[ARG0
] = EXTRACT_ARBITS (caller_ar
, ARG0
);
2525 callee_loc
[ARG1
] = EXTRACT_ARBITS (callee_ar
, ARG1
);
2526 caller_loc
[ARG1
] = EXTRACT_ARBITS (caller_ar
, ARG1
);
2527 callee_loc
[ARG2
] = EXTRACT_ARBITS (callee_ar
, ARG2
);
2528 caller_loc
[ARG2
] = EXTRACT_ARBITS (caller_ar
, ARG2
);
2529 callee_loc
[ARG3
] = EXTRACT_ARBITS (callee_ar
, ARG3
);
2530 caller_loc
[ARG3
] = EXTRACT_ARBITS (caller_ar
, ARG3
);
2532 /* Check some special combinations. For example, if FU
2533 appears in ARG1 or ARG3, we can move it to ARG0 or ARG2,
2534 respectively. (I guess this braindamage is correct? It'd
2535 take an hour or two of reading PA calling conventions to
2538 if (caller_loc
[ARG0
] == AR_FU
|| caller_loc
[ARG1
] == AR_FU
)
2540 caller_loc
[ARG0
] = AR_DBL01
;
2541 caller_loc
[ARG1
] = AR_NO
;
2543 if (caller_loc
[ARG2
] == AR_FU
|| caller_loc
[ARG3
] == AR_FU
)
2545 caller_loc
[ARG2
] = AR_DBL23
;
2546 caller_loc
[ARG3
] = AR_NO
;
2548 if (callee_loc
[ARG0
] == AR_FU
|| callee_loc
[ARG1
] == AR_FU
)
2550 callee_loc
[ARG0
] = AR_DBL01
;
2551 callee_loc
[ARG1
] = AR_NO
;
2553 if (callee_loc
[ARG2
] == AR_FU
|| callee_loc
[ARG3
] == AR_FU
)
2555 callee_loc
[ARG2
] = AR_DBL23
;
2556 callee_loc
[ARG3
] = AR_NO
;
2559 /* Now look up potential mismatches. */
2560 stub_types
[ARG0
] = type_of_mismatch (caller_loc
[ARG0
],
2563 stub_types
[ARG1
] = type_of_mismatch (caller_loc
[ARG1
],
2566 stub_types
[ARG2
] = type_of_mismatch (caller_loc
[ARG2
],
2569 stub_types
[ARG3
] = type_of_mismatch (caller_loc
[ARG3
],
2572 stub_types
[RETVAL
] = type_of_mismatch (caller_loc
[RETVAL
],
2576 /* If any of the arguments or return value need an argument
2577 relocation, then we will need an argument relocation stub. */
2578 if (stub_types
[ARG0
] != NO_ARG_RELOC
2579 || stub_types
[ARG1
] != NO_ARG_RELOC
2580 || stub_types
[ARG2
] != NO_ARG_RELOC
2581 || stub_types
[ARG3
] != NO_ARG_RELOC
2582 || stub_types
[RETVAL
] != NO_ARG_RELOC
)
2589 /* Create the linker stub section. */
2592 hppa_elf_create_stub_sec (abfd
, output_bfd
, secptr
, link_info
)
2596 struct bfd_link_info
*link_info
;
2598 asection
*output_text_section
;
2600 output_text_section
= bfd_get_section_by_name (output_bfd
, ".text");
2601 *secptr
= bfd_make_section (abfd
, ".hppa_linker_stubs");
2602 bfd_set_section_flags (abfd
, *secptr
,
2603 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
2604 | SEC_RELOC
| SEC_CODE
| SEC_READONLY
);
2605 (*secptr
)->output_section
= output_text_section
->output_section
;
2606 (*secptr
)->output_offset
= 0;
2608 /* Set up the ELF section header for this new section. This
2609 is basically the same processing as elf_make_sections().
2610 elf_make_sections is static and therefore not accessable
2613 Elf_Internal_Shdr
*this_hdr
;
2614 this_hdr
= &elf_section_data ((*secptr
))->this_hdr
;
2616 /* Set the sizes of this section. The contents have already
2618 this_hdr
->sh_addr
= (*secptr
)->vma
;
2619 this_hdr
->sh_size
= (*secptr
)->_raw_size
;
2621 /* Set appropriate flags for sections with relocations. */
2622 if ((*secptr
)->flags
& SEC_RELOC
)
2624 Elf_Internal_Shdr
*rela_hdr
;
2625 int use_rela_p
= get_elf_backend_data (abfd
)->use_rela_p
;
2627 rela_hdr
= &elf_section_data ((*secptr
))->rel_hdr
;
2631 rela_hdr
->sh_type
= SHT_RELA
;
2632 rela_hdr
->sh_entsize
= sizeof (Elf32_External_Rela
);
2636 rela_hdr
->sh_type
= SHT_REL
;
2637 rela_hdr
->sh_entsize
= sizeof (Elf32_External_Rel
);
2639 rela_hdr
->sh_flags
= 0;
2640 rela_hdr
->sh_addr
= 0;
2641 rela_hdr
->sh_offset
= 0;
2642 rela_hdr
->sh_addralign
= 0;
2646 if ((*secptr
)->flags
& SEC_ALLOC
)
2647 this_hdr
->sh_flags
|= SHF_ALLOC
;
2649 if (!((*secptr
)->flags
& SEC_READONLY
))
2650 this_hdr
->sh_flags
|= SHF_WRITE
;
2652 if ((*secptr
)->flags
& SEC_CODE
)
2653 this_hdr
->sh_flags
|= SHF_EXECINSTR
;
2656 bfd_set_section_alignment (abfd
, *secptr
, 2);
2659 /* Return nonzero if a long-call stub will be needed to call the
2660 function (symbol in RELOC_ENTRY). */
2663 hppa_elf_long_branch_needed_p (abfd
, asec
, reloc_entry
, symbol
, insn
)
2666 arelent
*reloc_entry
;
2670 long sym_value
= get_symbol_value (symbol
);
2671 int fmt
= reloc_entry
->howto
->bitsize
;
2672 unsigned char op
= get_opcode (insn
);
2675 #define too_far(val,num_bits) \
2676 ((int)(val) > (1 << (num_bits)) - 1) || ((int)(val) < (-1 << (num_bits)))
2682 reloc_entry
->address
+ asec
->output_offset
+ asec
->output_section
->vma
;
2683 /* If the symbol and raddr (relocated addr?) are too far away from
2684 each other, then a long-call stub will be needed. */
2685 if (too_far (sym_value
- raddr
, fmt
+ 1))
2692 /* Search the given section and determine if linker stubs will be
2693 needed for any calls within that section.
2695 Return any new stub symbols created.
2697 Used out of hppaelf.em in the linker. */
2700 hppa_look_for_stubs_in_section (stub_bfd
, abfd
, output_bfd
, asec
,
2701 new_sym_cnt
, link_info
)
2707 struct bfd_link_info
*link_info
;
2710 arg_reloc_type stub_types
[5];
2711 asymbol
*new_syms
= NULL
;
2714 arelent
**reloc_vector
= NULL
;
2716 /* Relocations are in different places depending on whether this is
2717 an output section or an input section. Also, the relocations are
2718 in different forms. Sigh. Luckily, we have bfd_canonicalize_reloc()
2719 to straighten this out for us . */
2720 if (asec
->reloc_count
> 0)
2723 = (arelent
**) malloc (asec
->reloc_count
* (sizeof (arelent
*) + 1));
2724 if (reloc_vector
== NULL
)
2726 bfd_set_error (bfd_error_no_memory
);
2730 /* Make sure the canonical symbols are hanging around in a convient
2732 if (bfd_get_outsymbols (abfd
) == NULL
)
2736 symsize
= get_symtab_upper_bound (abfd
);
2737 abfd
->outsymbols
= (asymbol
**) bfd_alloc (abfd
, symsize
);
2738 if (!abfd
->outsymbols
)
2740 bfd_set_error (bfd_error_no_memory
);
2743 abfd
->symcount
= bfd_canonicalize_symtab (abfd
, abfd
->outsymbols
);
2746 /* Now get the relocations. */
2747 bfd_canonicalize_reloc (abfd
, asec
, reloc_vector
,
2748 bfd_get_outsymbols (abfd
));
2750 /* Examine each relocation entry in this section. */
2751 for (i
= 0; i
< asec
->reloc_count
; i
++)
2753 arelent
*rle
= reloc_vector
[i
];
2755 switch (rle
->howto
->type
)
2757 /* Any call could need argument relocation stubs, and
2758 some may need long-call stubs. */
2759 case R_HPPA_ABS_CALL_11
:
2760 case R_HPPA_ABS_CALL_14
:
2761 case R_HPPA_ABS_CALL_17
:
2762 case R_HPPA_ABS_CALL_L21
:
2763 case R_HPPA_ABS_CALL_R11
:
2764 case R_HPPA_ABS_CALL_R14
:
2765 case R_HPPA_ABS_CALL_R17
:
2766 case R_HPPA_ABS_CALL_LS21
:
2767 case R_HPPA_ABS_CALL_RS11
:
2768 case R_HPPA_ABS_CALL_RS14
:
2769 case R_HPPA_ABS_CALL_RS17
:
2770 case R_HPPA_ABS_CALL_LD21
:
2771 case R_HPPA_ABS_CALL_RD11
:
2772 case R_HPPA_ABS_CALL_RD14
:
2773 case R_HPPA_ABS_CALL_RD17
:
2774 case R_HPPA_ABS_CALL_LR21
:
2775 case R_HPPA_ABS_CALL_RR14
:
2776 case R_HPPA_ABS_CALL_RR17
:
2777 case R_HPPA_PCREL_CALL_11
:
2778 case R_HPPA_PCREL_CALL_14
:
2779 case R_HPPA_PCREL_CALL_17
:
2780 case R_HPPA_PCREL_CALL_12
:
2781 case R_HPPA_PCREL_CALL_L21
:
2782 case R_HPPA_PCREL_CALL_R11
:
2783 case R_HPPA_PCREL_CALL_R14
:
2784 case R_HPPA_PCREL_CALL_R17
:
2785 case R_HPPA_PCREL_CALL_LS21
:
2786 case R_HPPA_PCREL_CALL_RS11
:
2787 case R_HPPA_PCREL_CALL_RS14
:
2788 case R_HPPA_PCREL_CALL_RS17
:
2789 case R_HPPA_PCREL_CALL_LD21
:
2790 case R_HPPA_PCREL_CALL_RD11
:
2791 case R_HPPA_PCREL_CALL_RD14
:
2792 case R_HPPA_PCREL_CALL_RD17
:
2793 case R_HPPA_PCREL_CALL_LR21
:
2794 case R_HPPA_PCREL_CALL_RR14
:
2795 case R_HPPA_PCREL_CALL_RR17
:
2797 symext_entryS caller_ar
2798 = (symext_entryS
) HPPA_R_ARG_RELOC (rle
->addend
);
2801 /* We'll need this for the long-call checks. */
2802 bfd_get_section_contents (abfd
, asec
, insn
, rle
->address
,
2805 /* See if this call needs an argument relocation stub. */
2806 if (hppa_elf_arg_reloc_needed_p (abfd
, rle
, stub_types
,
2809 /* Generate a stub and keep track of the new symbol. */
2812 if (new_cnt
== new_max
)
2814 new_max
+= STUB_SYM_BUFFER_INC
;
2815 new_syms
= (asymbol
*)
2816 realloc (new_syms
, new_max
* sizeof (asymbol
));
2817 if (new_syms
== NULL
)
2819 bfd_set_error (bfd_error_no_memory
);
2824 /* Build the argument relocation stub. */
2825 r
= hppa_elf_build_linker_stub (stub_bfd
, output_bfd
,
2827 stub_types
, true, insn
,
2828 HPPA_STUB_ARG_RELOC
);
2829 new_syms
[new_cnt
++] = *r
;
2832 /* See if this call needs a long-call stub. */
2833 if (hppa_elf_long_branch_needed_p (abfd
, asec
, rle
,
2834 rle
->sym_ptr_ptr
[0],
2837 /* Generate a stub and keep track of the new symbol. */
2840 if (new_cnt
== new_max
)
2842 new_max
+= STUB_SYM_BUFFER_INC
;
2843 new_syms
= (asymbol
*)
2844 realloc (new_syms
, (new_max
* sizeof (asymbol
)));
2847 bfd_set_error (bfd_error_no_memory
);
2852 /* Build the long-call stub. */
2853 r
= hppa_elf_build_linker_stub (stub_bfd
, output_bfd
,
2856 HPPA_STUB_LONG_CALL
);
2857 new_syms
[new_cnt
++] = *r
;
2862 /* PLABELs may need argument relocation stubs. */
2863 case R_HPPA_PLABEL_32
:
2864 case R_HPPA_PLABEL_11
:
2865 case R_HPPA_PLABEL_14
:
2866 case R_HPPA_PLABEL_L21
:
2867 case R_HPPA_PLABEL_R11
:
2868 case R_HPPA_PLABEL_R14
:
2870 /* On a plabel relocation, assume the arguments of the
2871 caller are set up in general registers (indirect
2872 calls only use general registers.
2873 NOTE: 0x155 = ARGW0=GR,ARGW1=GR,ARGW2=GR,RETVAL=GR. */
2874 symext_entryS caller_ar
= (symext_entryS
) 0x155;
2877 /* Do we really need this? */
2878 bfd_get_section_contents (abfd
, asec
, insn
, rle
->address
,
2881 /* See if this call needs an argument relocation stub. */
2882 if (hppa_elf_arg_reloc_needed_p (abfd
, rle
, stub_types
,
2885 /* Generate a plabel stub and keep track of the
2890 if (new_cnt
== new_max
)
2892 new_max
+= STUB_SYM_BUFFER_INC
;
2893 new_syms
= (asymbol
*) realloc (new_syms
, new_max
2894 * sizeof (asymbol
));
2897 /* Determine whether a return adjustment
2898 (see the relocation code for relocation type
2899 R_HPPA_STUB_CALL_17) is possible. Basically,
2900 determine whether we are looking at a branch or not. */
2901 if (rle
->howto
->type
== R_HPPA_PLABEL_32
)
2905 switch (get_opcode(insn
[0]))
2916 /* Build the argument relocation stub. */
2917 r
= hppa_elf_build_linker_stub (stub_bfd
, output_bfd
,
2918 link_info
, rle
, stub_types
,
2920 HPPA_STUB_ARG_RELOC
);
2921 new_syms
[new_cnt
++] = *r
;
2932 if (reloc_vector
!= NULL
)
2933 free (reloc_vector
);
2934 /* Return the new symbols and update the counters. */
2935 *new_sym_cnt
= new_cnt
;
2939 if (reloc_vector
!= NULL
)
2940 free (reloc_vector
);
2941 /* FIXME: This is bogus. We should be returning NULL. But do the callers
2946 /* Set the contents of a particular section at a particular location. */
2949 hppa_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
2954 bfd_size_type count
;
2956 /* Linker stubs are handled a little differently. */
2957 if (! strcmp (section
->name
, ".hppa_linker_stubs"))
2959 if (linker_stubs_max_size
< offset
+ count
)
2961 linker_stubs_max_size
= offset
+ count
+ STUB_ALLOC_INCR
;
2962 linker_stubs
= (char *)realloc (linker_stubs
, linker_stubs_max_size
);
2967 if (offset
+ count
> linker_stubs_size
)
2968 linker_stubs_size
= offset
+ count
;
2970 /* Set the contents. */
2971 memcpy(linker_stubs
+ offset
, location
, count
);
2975 /* For everything but the linker stub section, use the generic
2977 return bfd_elf32_set_section_contents (abfd
, section
, location
,
2981 /* Get the contents of the given section.
2983 This is special for PA ELF because some sections (such as linker stubs)
2984 may reside in memory rather than on disk, or in the case of the symbol
2985 extension section, the contents may need to be generated from other
2986 information contained in the BFD. */
2989 hppa_elf_get_section_contents (abfd
, section
, location
, offset
, count
)
2994 bfd_size_type count
;
2996 /* If this is the linker stub section, then its contents are contained
2997 in memory rather than on disk. FIXME. Is that always right? What
2998 about the case where a final executable is read in and a user tries
2999 to get the contents of this section? In that case the contents would
3000 be on disk like everything else. */
3001 if (strcmp (section
->name
, ".hppa_linker_stubs") == 0)
3003 elf32_hppa_stub_description
*stub_desc
= find_stubs (abfd
, section
);
3008 /* Sanity check our arguments. */
3009 if ((bfd_size_type
) (offset
+ count
) > section
->_raw_size
3010 || (bfd_size_type
) (offset
+ count
) > stub_desc
->real_size
)
3013 memcpy (location
, stub_desc
->stub_contents
+ offset
, count
);
3017 /* The symbol extension section also needs special handling. Its
3018 contents might be on the disk, in memory, or still need to
3020 else if (strcmp (section
->name
, ".hppa_symextn") == 0)
3022 /* If there are no output sections, then read the contents of the
3023 symbol extension section from disk. */
3024 if (section
->output_section
== NULL
3025 && abfd
->direction
== read_direction
)
3027 return bfd_generic_get_section_contents (abfd
, section
, location
,
3031 /* If this is the first time through, and there are output sections,
3032 then build the symbol extension section based on other information
3033 contained in the BFD. */
3034 else if (! symext_chain_built
)
3038 (int *) elf_sym_extra (section
->output_section
->owner
);
3040 for (i
= 0; i
< section
->output_section
->owner
->symcount
; i
++)
3042 elf_hppa_tc_symbol (section
->output_section
->owner
,
3043 ((elf_symbol_type
*)
3044 section
->output_section
->owner
->outsymbols
[i
]),
3045 symtab_map
[i
], &symext_rootP
, &symext_lastP
);
3047 symext_chain_built
++;
3048 elf_hppa_tc_make_sections (section
->output_section
->owner
,
3052 /* At this point we know that the symbol extension section has been
3053 built. We just need to copy it into the user's buffer. */
3057 /* Sanity check our arguments. */
3058 if ((bfd_size_type
) (offset
+ count
) > section
->_raw_size
3059 || (bfd_size_type
) (offset
+ count
) > symextn_contents_real_size
)
3063 (char *)symextn_contents
+ section
->output_offset
+ offset
,
3068 /* It's not the symbol extension or linker stub sections, use
3069 the generic routines. */
3070 return bfd_generic_get_section_contents (abfd
, section
, location
,
3074 /* Translate from an elf into field into a howto relocation pointer. */
3077 elf_info_to_howto (abfd
, cache_ptr
, dst
)
3080 Elf32_Internal_Rela
*dst
;
3082 BFD_ASSERT (ELF32_R_TYPE(dst
->r_info
) < (unsigned int) R_HPPA_UNIMPLEMENTED
);
3083 cache_ptr
->howto
= &elf_hppa_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
3086 /* Do PA ELF specific processing for symbols. Needed to find the
3087 value of $global$. */
3090 elf32_hppa_backend_symbol_processing (abfd
, sym
)
3094 /* Is this a definition of $global$? If so, keep it because it will be
3095 needed if any relocations are performed. */
3096 if (!strcmp (sym
->name
, "$global$")
3097 && sym
->section
!= &bfd_und_section
)
3099 global_symbol
= sym
;
3103 /* Do some PA ELF specific work after reading in the symbol table.
3104 In particular attach the argument relocation from the
3105 symbol extension section to the appropriate symbols. */
3107 elf32_hppa_backend_symbol_table_processing (abfd
, esyms
,symcnt
)
3109 elf_symbol_type
*esyms
;
3112 Elf32_Internal_Shdr
*symextn_hdr
=
3113 bfd_elf_find_section (abfd
, SYMEXTN_SECTION_NAME
);
3114 int i
, current_sym_idx
= 0;
3116 /* If no symbol extension existed, then all symbol extension information
3117 is assumed to be zero. */
3118 if (symextn_hdr
== NULL
)
3120 for (i
= 0; i
< symcnt
; i
++)
3121 esyms
[i
].tc_data
.hppa_arg_reloc
= 0;
3125 /* Allocate a buffer of the appropriate size for the symextn section. */
3126 symextn_hdr
->contents
= bfd_zalloc(abfd
,symextn_hdr
->sh_size
);
3127 if (!symextn_hdr
->contents
)
3129 bfd_set_error (bfd_error_no_memory
);
3132 symextn_hdr
->size
= symextn_hdr
->sh_size
;
3134 /* Read in the symextn section. */
3135 if (bfd_seek (abfd
, symextn_hdr
->sh_offset
, SEEK_SET
) == -1)
3137 bfd_set_error (bfd_error_system_call
);
3140 if (bfd_read ((PTR
) symextn_hdr
->contents
, 1, symextn_hdr
->size
, abfd
)
3141 != symextn_hdr
->size
)
3143 bfd_set_error (bfd_error_system_call
);
3147 /* Parse entries in the symbol extension section, updating the symtab
3149 for (i
= 0; i
< symextn_hdr
->size
/ sizeof(symext_entryS
); i
++)
3151 symext_entryS
*seP
= ((symext_entryS
*)symextn_hdr
->contents
) + i
;
3152 int se_value
= ELF32_HPPA_SX_VAL (*seP
);
3153 int se_type
= ELF32_HPPA_SX_TYPE (*seP
);
3160 case HPPA_SXT_SYMNDX
:
3161 if (se_value
>= symcnt
)
3163 bfd_set_error (bfd_error_bad_value
);
3166 current_sym_idx
= se_value
- 1;
3169 case HPPA_SXT_ARG_RELOC
:
3170 esyms
[current_sym_idx
].tc_data
.hppa_arg_reloc
= se_value
;
3174 bfd_set_error (bfd_error_bad_value
);
3181 /* Perform on PA ELF specific processing once a section has been
3182 read in. In particular keep the symbol indexes correct for
3183 the symbol extension information. */
3186 elf32_hppa_backend_section_processing (abfd
, secthdr
)
3188 Elf32_Internal_Shdr
*secthdr
;
3192 if (secthdr
->sh_type
== SHT_HPPA_SYMEXTN
)
3194 for (i
= 0; i
< secthdr
->size
/ sizeof (symext_entryS
); i
++)
3196 symext_entryS
*seP
= ((symext_entryS
*)secthdr
->contents
) + i
;
3197 int se_value
= ELF32_HPPA_SX_VAL (*seP
);
3198 int se_type
= ELF32_HPPA_SX_TYPE (*seP
);
3205 case HPPA_SXT_SYMNDX
:
3206 for (j
= 0; j
< abfd
->symcount
; j
++)
3208 /* Locate the map entry for this symbol and modify the
3209 symbol extension section symbol index entry to reflect
3210 the new symbol table index. */
3211 for (k
= 0; k
< elf32_hppa_symextn_map_size
; k
++)
3213 if (elf32_hppa_symextn_map
[k
].old_index
== se_value
3214 && elf32_hppa_symextn_map
[k
].bfd
3215 == abfd
->outsymbols
[j
]->the_bfd
3216 && elf32_hppa_symextn_map
[k
].sym
3217 == abfd
->outsymbols
[j
])
3220 ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX
, j
),
3227 case HPPA_SXT_ARG_RELOC
:
3231 bfd_set_error (bfd_error_bad_value
);
3239 /* What does this really do? Just determine if there is an appropriate
3240 mapping from ELF section headers to backend sections? More symbol
3241 extension braindamage. */
3244 elf32_hppa_backend_section_from_shdr (abfd
, hdr
, name
)
3246 Elf32_Internal_Shdr
*hdr
;
3251 if (hdr
->sh_type
== SHT_HPPA_SYMEXTN
)
3253 BFD_ASSERT (strcmp (name
, ".hppa_symextn") == 0);
3255 /* Bits that get saved. This one is real. */
3258 newsect
= bfd_make_section (abfd
, name
);
3259 if (newsect
!= NULL
)
3261 newsect
->vma
= hdr
->sh_addr
;
3262 newsect
->_raw_size
= hdr
->sh_size
;
3263 newsect
->filepos
= hdr
->sh_offset
;
3264 newsect
->flags
|= SEC_HAS_CONTENTS
;
3265 newsect
->alignment_power
= hdr
->sh_addralign
;
3267 if (hdr
->sh_flags
& SHF_ALLOC
)
3269 newsect
->flags
|= SEC_ALLOC
;
3270 newsect
->flags
|= SEC_LOAD
;
3273 if (!(hdr
->sh_flags
& SHF_WRITE
))
3274 newsect
->flags
|= SEC_READONLY
;
3276 if (hdr
->sh_flags
& SHF_EXECINSTR
)
3277 newsect
->flags
|= SEC_CODE
;
3279 newsect
->flags
|= SEC_DATA
;
3281 hdr
->rawdata
= (void *) newsect
;
3289 /* Return true if the given section is a fake section. */
3292 elf32_hppa_backend_fake_sections (abfd
, secthdr
, asect
)
3294 Elf_Internal_Shdr
*secthdr
;
3298 if (strcmp(asect
->name
, ".hppa_symextn") == 0)
3300 secthdr
->sh_type
= SHT_HPPA_SYMEXTN
;
3301 secthdr
->sh_flags
= 0;
3302 secthdr
->sh_info
= elf_section_data(asect
)->rel_hdr
.sh_link
;
3303 secthdr
->sh_link
= elf_onesymtab(abfd
);
3307 if (!strcmp (asect
->name
, ".hppa_unwind"))
3309 secthdr
->sh_type
= SHT_PROGBITS
;
3310 /* Unwind descriptors are not part of the program memory image. */
3311 secthdr
->sh_flags
= 0;
3312 secthdr
->sh_info
= 0;
3313 secthdr
->sh_link
= 0;
3314 secthdr
->sh_entsize
= 16;
3318 /* @@ Should this be CPU specific?? KR */
3319 if (!strcmp (asect
->name
, ".stabstr"))
3321 secthdr
->sh_type
= SHT_STRTAB
;
3322 secthdr
->sh_flags
= 0;
3323 secthdr
->sh_info
= 0;
3324 secthdr
->sh_link
= 0;
3325 secthdr
->sh_entsize
= 0;
3332 /* Return true if there is a mapping from bfd section into a
3336 elf32_hppa_backend_section_from_bfd_section (abfd
, hdr
, asect
, ignored
)
3338 Elf32_Internal_Shdr
*hdr
;
3342 if (hdr
->sh_type
== SHT_HPPA_SYMEXTN
)
3346 if (((struct sec
*) (hdr
->rawdata
)) == asect
)
3348 BFD_ASSERT (strcmp (asect
->name
, ".hppa_symextn") == 0);
3353 else if (hdr
->sh_type
== SHT_STRTAB
)
3357 if (((struct sec
*) (hdr
->rawdata
)) == asect
)
3359 BFD_ASSERT (strcmp (asect
->name
, ".stabstr") == 0);
3368 #define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
3369 #define elf_backend_section_from_bfd_section elf32_hppa_backend_section_from_bfd_section
3371 #define elf_backend_symbol_processing elf32_hppa_backend_symbol_processing
3372 #define elf_backend_symbol_table_processing elf32_hppa_backend_symbol_table_processing
3374 #define bfd_generic_get_section_contents hppa_elf_get_section_contents
3375 #define bfd_elf32_set_section_contents hppa_elf_set_section_contents
3377 #define elf_backend_section_processing elf32_hppa_backend_section_processing
3379 #define elf_backend_section_from_shdr elf32_hppa_backend_section_from_shdr
3380 #define elf_backend_fake_sections elf32_hppa_backend_fake_sections
3382 #define TARGET_BIG_SYM bfd_elf32_hppa_vec
3383 #define TARGET_BIG_NAME "elf32-hppa"
3384 #define ELF_ARCH bfd_arch_hppa
3385 #define ELF_MACHINE_CODE EM_HPPA
3386 #define ELF_MAXPAGESIZE 0x1000
3388 #include "elf32-target.h"