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 static boolean som_bfd_is_local_label
PARAMS ((bfd
*, asymbol
*));
274 /* ELF/PA relocation howto entries. */
276 static reloc_howto_type elf_hppa_howto_table
[ELF_HOWTO_TABLE_SIZE
] =
278 {R_HPPA_NONE
, 0, 3, 19, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_NONE"},
279 {R_HPPA_32
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_32"},
280 {R_HPPA_11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_11"},
281 {R_HPPA_14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_14"},
282 {R_HPPA_17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_17"},
283 {R_HPPA_L21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_L21"},
284 {R_HPPA_R11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_R11"},
285 {R_HPPA_R14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_R14"},
286 {R_HPPA_R17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_R17"},
287 {R_HPPA_LS21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_LS21"},
288 {R_HPPA_RS11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RS11"},
289 {R_HPPA_RS14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RS14"},
290 {R_HPPA_RS17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RS17"},
291 {R_HPPA_LD21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_LD21"},
292 {R_HPPA_RD11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RD11"},
293 {R_HPPA_RD14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RD14"},
294 {R_HPPA_RD17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RD17"},
295 {R_HPPA_LR21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_LR21"},
296 {R_HPPA_RR14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RR14"},
297 {R_HPPA_RR17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RR17"},
298 {R_HPPA_GOTOFF_11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_11"},
299 {R_HPPA_GOTOFF_14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_14"},
300 {R_HPPA_GOTOFF_L21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_L21"},
301 {R_HPPA_GOTOFF_R11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_R11"},
302 {R_HPPA_GOTOFF_R14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_R14"},
303 {R_HPPA_GOTOFF_LS21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_LS21"},
304 {R_HPPA_GOTOFF_RS11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_RS11"},
305 {R_HPPA_GOTOFF_RS14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_RS14"},
306 {R_HPPA_GOTOFF_LD21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_LD21"},
307 {R_HPPA_GOTOFF_RD11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_RD11"},
308 {R_HPPA_GOTOFF_RD14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_RD14"},
309 {R_HPPA_GOTOFF_LR21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_LR21"},
310 {R_HPPA_GOTOFF_RR14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_RR14"},
311 {R_HPPA_ABS_CALL_11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_11"},
312 {R_HPPA_ABS_CALL_14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_14"},
313 {R_HPPA_ABS_CALL_17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_17"},
314 {R_HPPA_ABS_CALL_L21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_L21"},
315 {R_HPPA_ABS_CALL_R11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_R11"},
316 {R_HPPA_ABS_CALL_R14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_R14"},
317 {R_HPPA_ABS_CALL_R17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_R17"},
318 {R_HPPA_ABS_CALL_LS21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_LS21"},
319 {R_HPPA_ABS_CALL_RS11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RS11"},
320 {R_HPPA_ABS_CALL_RS14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RS14"},
321 {R_HPPA_ABS_CALL_RS17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RS17"},
322 {R_HPPA_ABS_CALL_LD21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_LD21"},
323 {R_HPPA_ABS_CALL_RD11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RD11"},
324 {R_HPPA_ABS_CALL_RD14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RD14"},
325 {R_HPPA_ABS_CALL_RD17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RD17"},
326 {R_HPPA_ABS_CALL_LR21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_LR21"},
327 {R_HPPA_ABS_CALL_RR14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RR14"},
328 {R_HPPA_ABS_CALL_RR17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RR17"},
329 {R_HPPA_PCREL_CALL_11
, 0, 3, 11, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_11"},
330 {R_HPPA_PCREL_CALL_14
, 0, 3, 14, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_14"},
331 {R_HPPA_PCREL_CALL_17
, 0, 3, 17, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_17"},
332 {R_HPPA_PCREL_CALL_12
, 0, 3, 12, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_12"},
333 {R_HPPA_PCREL_CALL_L21
, 0, 3, 21, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_L21"},
334 {R_HPPA_PCREL_CALL_R11
, 0, 3, 11, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_R11"},
335 {R_HPPA_PCREL_CALL_R14
, 0, 3, 14, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_R14"},
336 {R_HPPA_PCREL_CALL_R17
, 0, 3, 17, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_R17"},
337 {R_HPPA_PCREL_CALL_LS21
, 0, 3, 21, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_LS21"},
338 {R_HPPA_PCREL_CALL_RS11
, 0, 3, 11, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RS11"},
339 {R_HPPA_PCREL_CALL_RS14
, 0, 3, 14, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RS14"},
340 {R_HPPA_PCREL_CALL_RS17
, 0, 3, 17, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RS17"},
341 {R_HPPA_PCREL_CALL_LD21
, 0, 3, 21, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_LD21"},
342 {R_HPPA_PCREL_CALL_RD11
, 0, 3, 11, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RD11"},
343 {R_HPPA_PCREL_CALL_RD14
, 0, 3, 14, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RD14"},
344 {R_HPPA_PCREL_CALL_RD17
, 0, 3, 17, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RD17"},
345 {R_HPPA_PCREL_CALL_LR21
, 0, 3, 21, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_LR21"},
346 {R_HPPA_PCREL_CALL_RR14
, 0, 3, 14, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RR14"},
347 {R_HPPA_PCREL_CALL_RR17
, 0, 3, 17, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RR17"},
348 {R_HPPA_PLABEL_32
, 0, 3, 32, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PLABEL_32"},
349 {R_HPPA_PLABEL_11
, 0, 3, 11, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PLABEL_11"},
350 {R_HPPA_PLABEL_14
, 0, 3, 14, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PLABEL_14"},
351 {R_HPPA_PLABEL_L21
, 0, 3, 21, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PLABEL_L21"},
352 {R_HPPA_PLABEL_R11
, 0, 3, 11, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PLABEL_R11"},
353 {R_HPPA_PLABEL_R14
, 0, 3, 14, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PLABEL_R14"},
354 {R_HPPA_DLT_32
, 0, 3, 32, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_DLT_32"},
355 {R_HPPA_DLT_11
, 0, 3, 11, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_DLT_11"},
356 {R_HPPA_DLT_14
, 0, 3, 14, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_DLT_14"},
357 {R_HPPA_DLT_L21
, 0, 3, 21, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_DLT_L21"},
358 {R_HPPA_DLT_R11
, 0, 3, 11, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_DLT_R11"},
359 {R_HPPA_DLT_R14
, 0, 3, 14, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_DLT_R14"},
360 {R_HPPA_UNWIND_ENTRY
, 0, 3, 32, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_UNWIND_ENTRY"},
361 {R_HPPA_UNWIND_ENTRIES
, 0, 3, 32, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_UNWIND_ENTRIES"},
362 {R_HPPA_PUSH_CONST
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_CONST"},
363 {R_HPPA_PUSH_PC
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_PC"},
364 {R_HPPA_PUSH_SYM
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_SYM"},
365 {R_HPPA_PUSH_GOTOFF
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_GOTOFF"},
366 {R_HPPA_PUSH_ABS_CALL
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_ABS_CALL"},
367 {R_HPPA_PUSH_PCREL_CALL
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_PCREL_CALL"},
368 {R_HPPA_PUSH_PLABEL
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_PLABEL"},
369 {R_HPPA_MAX
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_MAX"},
370 {R_HPPA_MIN
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_MIN"},
371 {R_HPPA_ADD
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ADD"},
372 {R_HPPA_SUB
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_SUB"},
373 {R_HPPA_MULT
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_MULT"},
374 {R_HPPA_DIV
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_DIV"},
375 {R_HPPA_MOD
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_MOD"},
376 {R_HPPA_AND
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_AND"},
377 {R_HPPA_OR
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_OR"},
378 {R_HPPA_XOR
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_XOR"},
379 {R_HPPA_NOT
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_NOT"},
380 {R_HPPA_LSHIFT
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_LSHIFT"},
381 {R_HPPA_ARITH_RSHIFT
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ARITH_RSHIFT"},
382 {R_HPPA_LOGIC_RSHIFT
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_LOGIC_RSHIFT"},
383 {R_HPPA_EXPR_F
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_L"},
384 {R_HPPA_EXPR_L
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_L"},
385 {R_HPPA_EXPR_R
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_R"},
386 {R_HPPA_EXPR_LS
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_LS"},
387 {R_HPPA_EXPR_RS
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_RS"},
388 {R_HPPA_EXPR_LD
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_LD"},
389 {R_HPPA_EXPR_RD
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_RD"},
390 {R_HPPA_EXPR_LR
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_LR"},
391 {R_HPPA_EXPR_RR
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_RR"},
392 {R_HPPA_EXPR_32
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_32"},
393 {R_HPPA_EXPR_21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_21"},
394 {R_HPPA_EXPR_11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_11"},
395 {R_HPPA_EXPR_14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_14"},
396 {R_HPPA_EXPR_17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_17"},
397 {R_HPPA_EXPR_12
, 0, 3, 12, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_12"},
398 {R_HPPA_STUB_CALL_17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_STUB_CALL_17"},
399 {R_HPPA_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_dont
, NULL
, "R_HPPA_UNIMPLEMENTED"},
402 static symext_chainS
*symext_rootP
;
403 static symext_chainS
*symext_lastP
;
404 static boolean symext_chain_built
;
405 static long global_value
;
406 static long GOT_value
;
407 static asymbol
*global_symbol
;
408 static int global_sym_defined
;
409 static symext_entryS
*symextn_contents
;
410 static unsigned int symextn_contents_real_size
;
411 static elf32_hppa_stub_description
*elf_hppa_stub_rootP
;
412 static boolean stubs_finished
= false;
413 static struct elf32_hppa_symextn_map_struct
*elf32_hppa_symextn_map
;
414 static int elf32_hppa_symextn_map_size
;
416 static char *linker_stubs
= NULL
;
417 static int linker_stubs_size
= 0;
418 static int linker_stubs_max_size
= 0;
419 #define STUB_ALLOC_INCR 100
420 #define STUB_SYM_BUFFER_INC 5
422 /* Relocate the given INSN given the various input parameters.
424 FIXME: endianness and sizeof (long) issues abound here. */
427 hppa_elf_relocate_insn (abfd
, input_sect
, insn
, address
, sym_value
,
428 r_addend
, r_format
, r_field
, pcrel
)
430 asection
*input_sect
;
432 unsigned long address
;
435 unsigned long r_format
;
436 unsigned long r_field
;
439 unsigned char opcode
= get_opcode (insn
);
460 constant_value
= HPPA_R_CONSTANT (r_addend
);
463 sym_value
-= address
;
465 sym_value
= hppa_field_adjust (sym_value
, constant_value
, r_field
);
466 return hppa_rebuild_insn (abfd
, insn
, sym_value
, r_format
);
471 arg_reloc
= HPPA_R_ARG_RELOC (r_addend
);
473 /* XXX computing constant_value is not needed??? */
474 constant_value
= assemble_17 ((insn
& 0x001f0000) >> 16,
475 (insn
& 0x00001ffc) >> 2,
478 constant_value
= (constant_value
<< 15) >> 15;
482 address
+ input_sect
->output_offset
483 + input_sect
->output_section
->vma
;
484 sym_value
= hppa_field_adjust (sym_value
, -8, r_field
);
487 sym_value
= hppa_field_adjust (sym_value
, constant_value
, r_field
);
489 return hppa_rebuild_insn (abfd
, insn
, sym_value
>> 2, r_format
);
494 constant_value
= HPPA_R_CONSTANT (r_addend
);
497 sym_value
-= address
;
499 return hppa_field_adjust (sym_value
, constant_value
, r_field
);
506 /* Relocate a single unwind entry, or an entire table of them. */
509 hppa_elf_relocate_unwind_table (abfd
, data
, address
, sym_value
,
510 r_addend
, r_type
, r_field
)
513 unsigned long address
;
516 unsigned long r_type
;
517 unsigned long r_field
;
519 bfd_byte
*hit_data
= address
+ (bfd_byte
*) data
;
522 long relocated_value
;
527 case R_HPPA_UNWIND_ENTRY
:
528 /* Need to relocate the first two 32bit fields in the unwind. They
529 correspond to a function's start and end address. */
530 start_offset
= bfd_get_32 (abfd
, hit_data
);
531 relocated_value
= hppa_field_adjust (sym_value
, start_offset
, r_field
);
532 bfd_put_32 (abfd
, relocated_value
, hit_data
);
534 hit_data
+= sizeof (unsigned long);
535 end_offset
= bfd_get_32 (abfd
, hit_data
);
536 relocated_value
= hppa_field_adjust (sym_value
, end_offset
, r_field
);
537 bfd_put_32 (abfd
, relocated_value
, hit_data
);
540 case R_HPPA_UNWIND_ENTRIES
:
541 /* Relocate a mass of unwind entires. The count is passed in r_addend
542 (who's braindamaged idea was this anyway? */
543 for (i
= 0; i
< r_addend
; i
++, hit_data
+= 3 * sizeof (unsigned long))
545 unsigned int adjustment
;
546 /* Adjust the first 32bit field in the unwind entry. It's
547 the starting offset of a function. */
548 start_offset
= bfd_get_32 (abfd
, hit_data
);
549 bfd_put_32 (abfd
, sym_value
, hit_data
);
550 adjustment
= sym_value
- start_offset
;
552 /* Now adjust the second 32bit field, it's the ending offset
554 hit_data
+= sizeof (unsigned long);
555 end_offset
= adjustment
+ bfd_get_32 (abfd
, hit_data
);
556 bfd_put_32 (abfd
, end_offset
, hit_data
);
558 /* Prepare for the next iteration. */
559 start_offset
= bfd_get_32 (abfd
,
560 hit_data
+ 3 * sizeof (unsigned long));
561 sym_value
= start_offset
+ adjustment
;
570 /* Return the relocated value of the given symbol. */
573 get_symbol_value (symbol
)
577 || symbol
->section
== &bfd_com_section
)
580 return symbol
->value
+ symbol
->section
->output_section
->vma
581 + symbol
->section
->output_offset
;
584 /* Return one (or more) BFD relocations which implement the base
585 relocation with modifications based on format and field. */
587 elf32_hppa_reloc_type
**
588 hppa_elf_gen_reloc_type (abfd
, base_type
, format
, field
)
590 elf32_hppa_reloc_type base_type
;
594 elf32_hppa_reloc_type
*finaltype
;
595 elf32_hppa_reloc_type
**final_types
;
597 /* Allocate slots for the BFD relocation. */
598 final_types
= (elf32_hppa_reloc_type
**)
599 bfd_alloc_by_size_t (abfd
, sizeof (elf32_hppa_reloc_type
*) * 2);
600 BFD_ASSERT (final_types
!= 0); /* FIXME */
602 /* Allocate space for the relocation itself. */
603 finaltype
= (elf32_hppa_reloc_type
*)
604 bfd_alloc_by_size_t (abfd
, sizeof (elf32_hppa_reloc_type
));
605 BFD_ASSERT (finaltype
!= 0); /* FIXME */
607 /* Some reasonable defaults. */
608 final_types
[0] = finaltype
;
609 final_types
[1] = NULL
;
611 #define final_type finaltype[0]
613 final_type
= base_type
;
615 /* Just a tangle of nested switch statements to deal with the braindamage
616 that a different field selector means a completely different relocation
627 final_type
= R_HPPA_11
;
630 final_type
= R_HPPA_R11
;
633 final_type
= R_HPPA_RS11
;
636 final_type
= R_HPPA_RD11
;
639 final_type
= R_HPPA_PLABEL_11
;
642 final_type
= R_HPPA_PLABEL_R11
;
645 final_type
= R_HPPA_DLT_11
;
648 final_type
= R_HPPA_DLT_R11
;
660 final_type
= R_HPPA_R14
;
663 final_type
= R_HPPA_RS14
;
666 final_type
= R_HPPA_RD14
;
669 final_type
= R_HPPA_RR14
;
672 final_type
= R_HPPA_PLABEL_14
;
675 final_type
= R_HPPA_PLABEL_R14
;
678 final_type
= R_HPPA_DLT_14
;
681 final_type
= R_HPPA_DLT_R14
;
693 final_type
= R_HPPA_17
;
696 final_type
= R_HPPA_R17
;
699 final_type
= R_HPPA_RS17
;
702 final_type
= R_HPPA_RD17
;
705 final_type
= R_HPPA_RR17
;
717 final_type
= R_HPPA_L21
;
720 final_type
= R_HPPA_LS21
;
723 final_type
= R_HPPA_LD21
;
726 final_type
= R_HPPA_LR21
;
729 final_type
= R_HPPA_PLABEL_L21
;
732 final_type
= R_HPPA_PLABEL_L21
;
744 final_type
= R_HPPA_32
;
747 final_type
= R_HPPA_PLABEL_32
;
750 final_type
= R_HPPA_DLT_32
;
772 final_type
= R_HPPA_GOTOFF_R11
;
775 final_type
= R_HPPA_GOTOFF_RS11
;
778 final_type
= R_HPPA_GOTOFF_RD11
;
781 final_type
= R_HPPA_GOTOFF_11
;
793 final_type
= R_HPPA_GOTOFF_R14
;
796 final_type
= R_HPPA_GOTOFF_RS14
;
799 final_type
= R_HPPA_GOTOFF_RD14
;
802 final_type
= R_HPPA_GOTOFF_RR14
;
805 final_type
= R_HPPA_GOTOFF_14
;
817 final_type
= R_HPPA_GOTOFF_L21
;
820 final_type
= R_HPPA_GOTOFF_LS21
;
823 final_type
= R_HPPA_GOTOFF_LD21
;
826 final_type
= R_HPPA_GOTOFF_LR21
;
841 case R_HPPA_PCREL_CALL
:
848 final_type
= R_HPPA_PCREL_CALL_R11
;
851 final_type
= R_HPPA_PCREL_CALL_RS11
;
854 final_type
= R_HPPA_PCREL_CALL_RD11
;
857 final_type
= R_HPPA_PCREL_CALL_11
;
869 final_type
= R_HPPA_PCREL_CALL_R14
;
872 final_type
= R_HPPA_PCREL_CALL_RS14
;
875 final_type
= R_HPPA_PCREL_CALL_RD14
;
878 final_type
= R_HPPA_PCREL_CALL_RR14
;
881 final_type
= R_HPPA_PCREL_CALL_14
;
893 final_type
= R_HPPA_PCREL_CALL_R17
;
896 final_type
= R_HPPA_PCREL_CALL_RS17
;
899 final_type
= R_HPPA_PCREL_CALL_RD17
;
902 final_type
= R_HPPA_PCREL_CALL_RR17
;
905 final_type
= R_HPPA_PCREL_CALL_17
;
917 final_type
= R_HPPA_PCREL_CALL_L21
;
920 final_type
= R_HPPA_PCREL_CALL_LS21
;
923 final_type
= R_HPPA_PCREL_CALL_LD21
;
926 final_type
= R_HPPA_PCREL_CALL_LR21
;
948 final_type
= R_HPPA_PLABEL_11
;
951 final_type
= R_HPPA_PLABEL_R11
;
963 final_type
= R_HPPA_PLABEL_14
;
966 final_type
= R_HPPA_PLABEL_R14
;
978 final_type
= R_HPPA_PLABEL_L21
;
990 final_type
= R_HPPA_PLABEL_32
;
1004 case R_HPPA_ABS_CALL
:
1011 final_type
= R_HPPA_ABS_CALL_R11
;
1014 final_type
= R_HPPA_ABS_CALL_RS11
;
1017 final_type
= R_HPPA_ABS_CALL_RD11
;
1020 final_type
= R_HPPA_ABS_CALL_11
;
1032 final_type
= R_HPPA_ABS_CALL_R14
;
1035 final_type
= R_HPPA_ABS_CALL_RS14
;
1038 final_type
= R_HPPA_ABS_CALL_RD14
;
1041 final_type
= R_HPPA_ABS_CALL_RR14
;
1044 final_type
= R_HPPA_ABS_CALL_14
;
1056 final_type
= R_HPPA_ABS_CALL_R17
;
1059 final_type
= R_HPPA_ABS_CALL_RS17
;
1062 final_type
= R_HPPA_ABS_CALL_RD17
;
1065 final_type
= R_HPPA_ABS_CALL_RR17
;
1068 final_type
= R_HPPA_ABS_CALL_17
;
1080 final_type
= R_HPPA_ABS_CALL_L21
;
1083 final_type
= R_HPPA_ABS_CALL_LS21
;
1086 final_type
= R_HPPA_ABS_CALL_LD21
;
1089 final_type
= R_HPPA_ABS_CALL_LR21
;
1105 final_type
= R_HPPA_UNWIND_ENTRY
;
1109 case R_HPPA_COMPLEX
:
1110 case R_HPPA_COMPLEX_PCREL_CALL
:
1111 case R_HPPA_COMPLEX_ABS_CALL
:
1112 /* The code originally here was horribly broken, and apparently
1113 never used. Zap it. When we need complex relocations rewrite
1119 final_type
= base_type
;
1129 /* Actually perform a relocation. */
1131 static bfd_reloc_status_type
1132 hppa_elf_reloc (abfd
, reloc_entry
, symbol_in
, data
, input_section
, output_bfd
,
1135 arelent
*reloc_entry
;
1138 asection
*input_section
;
1140 char **error_message
;
1144 unsigned long addr
= reloc_entry
->address
;
1145 bfd_byte
*hit_data
= addr
+ (bfd_byte
*) data
;
1146 unsigned long r_type
= reloc_entry
->howto
->type
;
1147 unsigned long r_field
= e_fsel
;
1148 boolean r_pcrel
= reloc_entry
->howto
->pc_relative
;
1149 unsigned r_format
= reloc_entry
->howto
->bitsize
;
1150 long r_addend
= reloc_entry
->addend
;
1152 /* If only performing a partial link, get out early. */
1155 reloc_entry
->address
+= input_section
->output_offset
;
1156 return bfd_reloc_ok
;
1159 /* If performing final link and the symbol we're relocating against
1160 is undefined, then return an error. */
1161 if (symbol_in
&& symbol_in
->section
== &bfd_und_section
)
1162 return bfd_reloc_undefined
;
1164 /* Get the final relocated value. */
1165 sym_value
= get_symbol_value (symbol_in
);
1167 /* Compute the value of $global$.
1168 FIXME: None of this should be necessary. $global$ is just a
1169 marker and shouldn't really figure into these computations.
1171 Once that's fixed we'll need to teach this backend to change
1172 DP-relative relocations involving symbols in the text section
1173 to be simple absolute relocations. */
1174 if (!global_sym_defined
)
1178 global_value
= (global_symbol
->value
1179 + global_symbol
->section
->output_section
->vma
1180 + global_symbol
->section
->output_offset
);
1181 GOT_value
= global_value
;
1182 global_sym_defined
++;
1186 /* Get the instruction word. */
1187 insn
= bfd_get_32 (abfd
, hit_data
);
1189 /* Relocate the value based on one of the basic relocation types
1191 basic_type_1: relocation is relative to $global$
1192 basic_type_2: relocation is relative to the current GOT
1193 basic_type_3: relocation is an absolute call
1194 basic_type_4: relocation is an PC-relative call
1195 basic_type_5: relocation is plabel reference
1196 basic_type_6: relocation is an unwind table relocation
1197 extended_type: unimplemented */
1204 /* Handle all the basic type 1 relocations. */
1210 goto do_basic_type_1
;
1213 goto do_basic_type_1
;
1218 goto do_basic_type_1
;
1221 goto do_basic_type_1
;
1226 goto do_basic_type_1
;
1229 goto do_basic_type_1
;
1234 goto do_basic_type_1
;
1237 goto do_basic_type_1
;
1243 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
, addr
,
1244 sym_value
, r_addend
, r_format
,
1248 /* Handle all the basic type 2 relocations. */
1249 case R_HPPA_GOTOFF_11
:
1250 case R_HPPA_GOTOFF_14
:
1252 goto do_basic_type_2
;
1253 case R_HPPA_GOTOFF_L21
:
1255 goto do_basic_type_2
;
1256 case R_HPPA_GOTOFF_R11
:
1257 case R_HPPA_GOTOFF_R14
:
1259 goto do_basic_type_2
;
1260 case R_HPPA_GOTOFF_LS21
:
1262 goto do_basic_type_2
;
1263 case R_HPPA_GOTOFF_RS11
:
1264 case R_HPPA_GOTOFF_RS14
:
1266 goto do_basic_type_2
;
1267 case R_HPPA_GOTOFF_LD21
:
1269 goto do_basic_type_2
;
1270 case R_HPPA_GOTOFF_RD11
:
1271 case R_HPPA_GOTOFF_RD14
:
1273 goto do_basic_type_2
;
1274 case R_HPPA_GOTOFF_LR21
:
1276 goto do_basic_type_2
;
1277 case R_HPPA_GOTOFF_RR14
:
1281 sym_value
-= GOT_value
;
1282 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
, addr
,
1283 sym_value
, r_addend
, r_format
,
1287 /* Handle all the basic type 3 relocations. */
1288 case R_HPPA_ABS_CALL_11
:
1289 case R_HPPA_ABS_CALL_14
:
1290 case R_HPPA_ABS_CALL_17
:
1292 goto do_basic_type_3
;
1293 case R_HPPA_ABS_CALL_L21
:
1295 goto do_basic_type_3
;
1296 case R_HPPA_ABS_CALL_R11
:
1297 case R_HPPA_ABS_CALL_R14
:
1298 case R_HPPA_ABS_CALL_R17
:
1300 goto do_basic_type_3
;
1301 case R_HPPA_ABS_CALL_LS21
:
1303 goto do_basic_type_3
;
1304 case R_HPPA_ABS_CALL_RS11
:
1305 case R_HPPA_ABS_CALL_RS14
:
1306 case R_HPPA_ABS_CALL_RS17
:
1308 goto do_basic_type_3
;
1309 case R_HPPA_ABS_CALL_LD21
:
1311 goto do_basic_type_3
;
1312 case R_HPPA_ABS_CALL_RD11
:
1313 case R_HPPA_ABS_CALL_RD14
:
1314 case R_HPPA_ABS_CALL_RD17
:
1316 goto do_basic_type_3
;
1317 case R_HPPA_ABS_CALL_LR21
:
1319 goto do_basic_type_3
;
1320 case R_HPPA_ABS_CALL_RR14
:
1321 case R_HPPA_ABS_CALL_RR17
:
1325 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
, addr
,
1326 sym_value
, r_addend
, r_format
,
1330 /* Handle all the basic type 4 relocations. */
1331 case R_HPPA_PCREL_CALL_11
:
1332 case R_HPPA_PCREL_CALL_14
:
1333 case R_HPPA_PCREL_CALL_17
:
1335 goto do_basic_type_4
;
1336 case R_HPPA_PCREL_CALL_L21
:
1338 goto do_basic_type_4
;
1339 case R_HPPA_PCREL_CALL_R11
:
1340 case R_HPPA_PCREL_CALL_R14
:
1341 case R_HPPA_PCREL_CALL_R17
:
1343 goto do_basic_type_4
;
1344 case R_HPPA_PCREL_CALL_LS21
:
1346 goto do_basic_type_4
;
1347 case R_HPPA_PCREL_CALL_RS11
:
1348 case R_HPPA_PCREL_CALL_RS14
:
1349 case R_HPPA_PCREL_CALL_RS17
:
1351 goto do_basic_type_4
;
1352 case R_HPPA_PCREL_CALL_LD21
:
1354 goto do_basic_type_4
;
1355 case R_HPPA_PCREL_CALL_RD11
:
1356 case R_HPPA_PCREL_CALL_RD14
:
1357 case R_HPPA_PCREL_CALL_RD17
:
1359 goto do_basic_type_4
;
1360 case R_HPPA_PCREL_CALL_LR21
:
1362 goto do_basic_type_4
;
1363 case R_HPPA_PCREL_CALL_RR14
:
1364 case R_HPPA_PCREL_CALL_RR17
:
1368 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
, addr
,
1369 sym_value
, r_addend
, r_format
,
1373 /* Handle all the basic type 5 relocations. */
1374 case R_HPPA_PLABEL_32
:
1375 case R_HPPA_PLABEL_11
:
1376 case R_HPPA_PLABEL_14
:
1378 goto do_basic_type_5
;
1379 case R_HPPA_PLABEL_L21
:
1381 goto do_basic_type_5
;
1382 case R_HPPA_PLABEL_R11
:
1383 case R_HPPA_PLABEL_R14
:
1386 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
, addr
,
1387 sym_value
, r_addend
, r_format
,
1391 /* Handle all basic type 6 relocations. */
1392 case R_HPPA_UNWIND_ENTRY
:
1393 case R_HPPA_UNWIND_ENTRIES
:
1394 hppa_elf_relocate_unwind_table (abfd
, data
, addr
,
1395 sym_value
, r_addend
,
1397 return bfd_reloc_ok
;
1399 /* This is a linker internal relocation. */
1400 case R_HPPA_STUB_CALL_17
:
1401 /* This relocation is for a branch to a long branch stub.
1402 Change instruction to a BLE,N. It may also be necessary
1403 to interchange the branch and its delay slot.
1404 The original instruction stream is
1406 bl <foo>,r ; call foo using register r as
1407 ; the return pointer
1408 XXX ; delay slot instruction
1410 The new instruction stream will be:
1412 XXX ; delay slot instruction
1413 ble <foo_stub> ; call the long call stub for foo
1414 ; using r31 as the return pointer
1416 This braindamage is necessary because the compiler may put
1417 an instruction which uses %r31 in the delay slot of the original
1418 call. By changing the call instruction from a "bl" to a "ble"
1419 %r31 gets clobbered before the delay slot executes. This
1420 also means the stub has to play funny games to make sure
1421 we return to the instruction just after the BLE rather than
1422 two instructions after the BLE.
1424 We do not interchange the branch and delay slot if the delay
1425 slot was already nullified, or if the instruction in the delay
1426 slot modifies the return pointer to avoid an unconditional
1427 jump after the call returns (GCC optimization).
1429 None of this horseshit would be necessary if we put the
1430 stubs between functions and just redirected the "bl" to
1431 the stub. Live and learn. */
1433 /* Is this instruction nullified? (does this ever happen?) */
1436 insn
= BLE_N_XXX_0_0
;
1437 bfd_put_32 (abfd
, insn
, hit_data
);
1438 r_type
= R_HPPA_ABS_CALL_17
;
1440 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1441 addr
, sym_value
, r_addend
,
1442 r_format
, r_field
, r_pcrel
);
1446 /* So much for the trivial case... */
1447 unsigned long old_delay_slot_insn
= bfd_get_32 (abfd
, hit_data
+ 4);
1448 unsigned rtn_reg
= (insn
& 0x03e00000) >> 21;
1450 if (get_opcode (old_delay_slot_insn
) == LDO
)
1452 unsigned ldo_src_reg
= (old_delay_slot_insn
& 0x03e00000) >> 21;
1453 unsigned ldo_target_reg
= (old_delay_slot_insn
& 0x001f0000) >> 16;
1455 /* If the target of the LDO is the same as the return
1456 register then there is no reordering. We can leave the
1457 instuction as a non-nullified BLE in this case.
1459 FIXME: This test looks wrong. If we had a ble using
1460 ldo_target_reg as the *source* we'd fuck this up. */
1461 if (ldo_target_reg
== rtn_reg
)
1463 unsigned long new_delay_slot_insn
= old_delay_slot_insn
;
1465 BFD_ASSERT (ldo_src_reg
== ldo_target_reg
);
1466 new_delay_slot_insn
&= 0xfc00ffff;
1467 new_delay_slot_insn
|= ((31 << 21) | (31 << 16));
1468 bfd_put_32 (abfd
, new_delay_slot_insn
, hit_data
+ 4);
1470 r_type
= R_HPPA_ABS_CALL_17
;
1472 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1473 addr
, sym_value
, r_addend
,
1474 r_format
, r_field
, r_pcrel
);
1475 bfd_put_32 (abfd
, insn
, hit_data
);
1476 return bfd_reloc_ok
;
1478 else if (rtn_reg
== 31)
1480 /* The return register is r31, so this is a millicode
1481 call. Do not perform any instruction reordering. */
1483 r_type
= R_HPPA_ABS_CALL_17
;
1485 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1489 bfd_put_32 (abfd
, insn
, hit_data
);
1490 return bfd_reloc_ok
;
1494 /* Check to see if the delay slot instruction has a
1495 relocation. If so, we need to change the address
1496 field of it because the instruction it relocates
1497 is going to be moved. Oh what a mess. */
1498 arelent
* next_reloc_entry
= reloc_entry
+1;
1500 if (next_reloc_entry
->address
== reloc_entry
->address
+ 4)
1501 next_reloc_entry
->address
-= 4;
1503 insn
= old_delay_slot_insn
;
1504 bfd_put_32 (abfd
, insn
, hit_data
);
1505 insn
= BLE_N_XXX_0_0
;
1506 bfd_put_32 (abfd
, insn
, hit_data
+ 4);
1507 r_type
= R_HPPA_ABS_CALL_17
;
1509 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1511 sym_value
, r_addend
,
1512 r_format
, r_field
, r_pcrel
);
1513 bfd_put_32 (abfd
, insn
, hit_data
+ 4);
1514 return bfd_reloc_ok
;
1517 /* Same comments as above regarding incorrect test. */
1518 else if (rtn_reg
== 31)
1520 /* The return register is r31, so this is a millicode call.
1521 Perform no instruction reordering in this case. */
1523 r_type
= R_HPPA_ABS_CALL_17
;
1525 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1529 bfd_put_32 (abfd
, insn
, hit_data
);
1530 return bfd_reloc_ok
;
1534 /* Check to see if the delay slot instruction has a
1535 relocation. If so, we need to change its address
1536 field because the instruction it relocates is going
1538 arelent
* next_reloc_entry
= reloc_entry
+1;
1540 if (next_reloc_entry
->address
== reloc_entry
->address
+ 4)
1541 next_reloc_entry
->address
-= 4;
1543 insn
= old_delay_slot_insn
;
1544 bfd_put_32 (abfd
, insn
, hit_data
);
1545 insn
= BLE_N_XXX_0_0
;
1546 bfd_put_32 (abfd
, insn
, hit_data
+ 4);
1547 r_type
= R_HPPA_ABS_CALL_17
;
1549 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1550 addr
+ 4, sym_value
,
1553 bfd_put_32 (abfd
, insn
, hit_data
+ 4);
1554 return bfd_reloc_ok
;
1559 /* Something we don't know how to handle. */
1561 *error_message
= (char *) "Unrecognized reloc";
1562 return bfd_reloc_notsupported
;
1565 /* Update the instruction word. */
1566 bfd_put_32 (abfd
, insn
, hit_data
);
1567 return (bfd_reloc_ok
);
1570 /* Return the address of the howto table entry to perform the CODE
1571 relocation for an ARCH machine. */
1573 static CONST reloc_howto_type
*
1574 elf_hppa_reloc_type_lookup (arch
, code
)
1575 bfd_arch_info_type
*arch
;
1576 bfd_reloc_code_real_type code
;
1578 if ((int) code
< (int) R_HPPA_UNIMPLEMENTED
)
1580 BFD_ASSERT ((int) elf_hppa_howto_table
[(int) code
].type
== (int) code
);
1581 return &elf_hppa_howto_table
[(int) code
];
1586 /* Return true if SYM represents a local label symbol. */
1589 hppa_elf_is_local_label (abfd
, sym
)
1593 return (sym
->name
[0] == 'L' && sym
->name
[1] == '$');
1596 /* Update the symbol extention chain to include the symbol pointed to
1597 by SYMBOLP if SYMBOLP is a function symbol. Used internally and by GAS. */
1600 elf_hppa_tc_symbol (abfd
, symbolP
, sym_idx
, symext_root
, symext_last
)
1602 elf_symbol_type
*symbolP
;
1604 symext_chainS
**symext_root
;
1605 symext_chainS
**symext_last
;
1607 symext_chainS
*symextP
;
1608 unsigned int arg_reloc
;
1610 /* Only functions can have argument relocations. */
1611 if (!(symbolP
->symbol
.flags
& BSF_FUNCTION
))
1614 arg_reloc
= symbolP
->tc_data
.hppa_arg_reloc
;
1616 /* If there are no argument relocation bits, then no relocation is
1617 necessary. Do not add this to the symextn section. */
1621 /* Allocate memory and initialize this entry. */
1622 symextP
= (symext_chainS
*) bfd_alloc (abfd
, sizeof (symext_chainS
) * 2);
1625 bfd_set_error (bfd_error_no_memory
);
1626 abort(); /* FIXME */
1629 symextP
[0].entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX
, sym_idx
);
1630 symextP
[0].next
= &symextP
[1];
1632 symextP
[1].entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_ARG_RELOC
, arg_reloc
);
1633 symextP
[1].next
= NULL
;
1635 /* Now update the chain itself so it can be walked later to build
1636 the symbol extension section. */
1637 if (*symext_root
== NULL
)
1639 *symext_root
= &symextP
[0];
1640 *symext_last
= &symextP
[1];
1644 (*symext_last
)->next
= &symextP
[0];
1645 *symext_last
= &symextP
[1];
1649 /* Build the symbol extension section. Used internally and by GAS. */
1652 elf_hppa_tc_make_sections (abfd
, symext_root
)
1654 symext_chainS
*symext_root
;
1656 symext_chainS
*symextP
;
1658 asection
*symextn_sec
;
1660 /* FIXME: Huh? I don't see what this is supposed to do for us. */
1661 hppa_elf_stub_finish (abfd
);
1663 /* If there are no entries in the symbol extension chain, then
1664 there is no symbol extension section. */
1665 if (symext_root
== NULL
)
1668 /* Count the number of entries on the chain. */
1669 for (n
= 0, symextP
= symext_root
; symextP
; symextP
= symextP
->next
, ++n
)
1672 /* Create the symbol extension section and set some appropriate
1674 size
= sizeof (symext_entryS
) * n
;
1675 symextn_sec
= bfd_get_section_by_name (abfd
, SYMEXTN_SECTION_NAME
);
1676 if (symextn_sec
== (asection
*) 0)
1678 symextn_sec
= bfd_make_section (abfd
, SYMEXTN_SECTION_NAME
);
1679 bfd_set_section_flags (abfd
,
1681 SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_DATA
);
1682 symextn_sec
->output_section
= symextn_sec
;
1683 symextn_sec
->output_offset
= 0;
1684 bfd_set_section_alignment (abfd
, symextn_sec
, 2);
1686 bfd_set_section_size (abfd
, symextn_sec
, symextn_contents_real_size
);
1687 symextn_contents_real_size
= size
;
1689 /* Grab some memory for the contents of the symbol extension section
1691 symextn_contents
= (symext_entryS
*) bfd_alloc (abfd
, size
);
1692 if (!symextn_contents
)
1694 bfd_set_error (bfd_error_no_memory
);
1695 abort(); /* FIXME */
1698 /* Fill in the contents of the symbol extension section. */
1699 for (i
= 0, symextP
= symext_root
; symextP
; symextP
= symextP
->next
, ++i
)
1700 symextn_contents
[i
] = symextP
->entry
;
1705 /* Return the symbol extension record of type TYPE for the symbol SYM. */
1707 static symext_entryS
1708 elf32_hppa_get_sym_extn (abfd
, sym
, type
)
1715 case HPPA_SXT_SYMNDX
:
1717 return (symext_entryS
) 0;
1718 case HPPA_SXT_ARG_RELOC
:
1720 elf_symbol_type
*esymP
= (elf_symbol_type
*) sym
;
1722 return (symext_entryS
) esymP
->tc_data
.hppa_arg_reloc
;
1724 /* This should never happen. */
1730 /* Search the chain of stub descriptions and locate the stub
1731 description for this the given section within the given bfd.
1733 FIXME: I see yet another wonderful linear linked list search
1734 here. This is probably bad. */
1736 static elf32_hppa_stub_description
*
1737 find_stubs (abfd
, stub_sec
)
1741 elf32_hppa_stub_description
*stubP
;
1743 for (stubP
= elf_hppa_stub_rootP
; stubP
; stubP
= stubP
->next
)
1745 /* Is this the right one? */
1746 if (stubP
->this_bfd
== abfd
&& stubP
->stub_sec
== stub_sec
)
1752 static elf32_hppa_stub_description
*
1753 new_stub (abfd
, stub_sec
, link_info
)
1756 struct bfd_link_info
*link_info
;
1758 elf32_hppa_stub_description
*stub
= find_stubs (abfd
, stub_sec
);
1760 /* If we found a list for this bfd, then use it. */
1764 /* Nope, allocate and initialize a new entry in the stub list chain. */
1765 stub
= (elf32_hppa_stub_description
*)
1766 bfd_zalloc (abfd
, sizeof (elf32_hppa_stub_description
));
1769 stub
->this_bfd
= abfd
;
1770 stub
->stub_sec
= stub_sec
;
1771 stub
->real_size
= 0;
1772 stub
->allocated_size
= 0;
1773 stub
->stub_contents
= NULL
;
1774 stub
->stub_secp
= NULL
;
1775 stub
->link_info
= link_info
;
1777 stub
->next
= elf_hppa_stub_rootP
;
1778 elf_hppa_stub_rootP
= stub
;
1782 bfd_set_error (bfd_error_no_memory
);
1783 abort(); /* FIXME */
1789 /* Try and locate a stub with the name NAME within the stubs
1790 associated with ABFD. More linked list searches. */
1792 static elf32_hppa_stub_name_list
*
1793 find_stub_by_name (abfd
, stub_sec
, name
)
1798 /* Find the stubs associated with this bfd. */
1799 elf32_hppa_stub_description
*stub
= find_stubs (abfd
, stub_sec
);
1801 /* If found, then we have to walk down them looking for a match. */
1804 elf32_hppa_stub_name_list
*name_listP
;
1806 for (name_listP
= stub
->stub_listP
;
1808 name_listP
= name_listP
->next
)
1810 if (!strcmp (name_listP
->sym
->name
, name
))
1819 /* Add a new stub (SYM) to the list of stubs associated with the given BFD. */
1820 static elf32_hppa_stub_name_list
*
1821 add_stub_by_name(abfd
, stub_sec
, sym
, link_info
)
1825 struct bfd_link_info
*link_info
;
1827 elf32_hppa_stub_description
*stub
= find_stubs (abfd
, stub_sec
);
1828 elf32_hppa_stub_name_list
*stub_entry
;
1830 /* If no stubs are associated with this bfd, then we have to make
1831 a chain-of-stubs associated with this bfd. */
1833 stub
= new_stub (abfd
, stub_sec
, link_info
);
1837 /* Allocate and initialize an entry in the stub chain. */
1838 stub_entry
= (elf32_hppa_stub_name_list
*)
1839 bfd_zalloc (abfd
, sizeof (elf32_hppa_stub_name_list
));
1843 stub_entry
->size
= 0;
1844 stub_entry
->sym
= sym
;
1845 stub_entry
->stub_desc
= stub
;
1846 /* First byte of this stub is the pointer to
1847 the next available location in the stub buffer. */
1848 stub_entry
->stub_secp
= stub
->stub_secp
;
1849 /* Add it to the chain. */
1850 if (stub
->stub_listP
)
1851 stub_entry
->next
= stub
->stub_listP
;
1853 stub_entry
->next
= NULL
;
1854 stub
->stub_listP
= stub_entry
;
1859 bfd_set_error (bfd_error_no_memory
);
1860 abort(); /* FIXME */
1863 /* Death by mis-adventure. */
1865 return (elf32_hppa_stub_name_list
*)NULL
;
1868 /* For the given caller/callee argument location information and the
1869 type of relocation (arguments or return value), return the type
1870 of argument relocation needed to make caller and callee happy. */
1872 static arg_reloc_type
1873 type_of_mismatch (caller_bits
, callee_bits
, type
)
1881 return mismatches
[caller_bits
][callee_bits
];
1883 return retval_mismatches
[caller_bits
][callee_bits
];
1885 return ARG_RELOC_ERR
;
1888 /* Extract specific argument location bits for WHICH from the
1889 the full argument location information in AR. */
1890 #define EXTRACT_ARBITS(ar, which) ((ar) >> (8 - ((which) * 2))) & 3
1892 /* Add the new instruction INSN into the stub area denoted by ENTRY.
1893 FIXME: Looks like more cases where we assume sizeof (int) ==
1894 sizeof (insn) which may not be true if building cross tools. */
1895 #define NEW_INSTRUCTION(entry, insn) \
1897 *((entry)->stub_desc->stub_secp)++ = (insn); \
1898 (entry)->stub_desc->real_size += sizeof (int); \
1899 (entry)->size += sizeof(int); \
1900 bfd_set_section_size((entry)->stub_desc->this_bfd, \
1901 (entry)->stub_desc->stub_sec, \
1902 (entry)->stub_desc->real_size); \
1905 /* Find the offset of the current stub? Looks more like it
1906 finds the offset of the last instruction to me. */
1907 #define CURRENT_STUB_OFFSET(entry) \
1908 ((char *)(entry)->stub_desc->stub_secp \
1909 - (char *)(entry)->stub_desc->stub_contents - 4)
1911 /* All the stubs have already been built, finish up stub stuff
1912 by applying relocations to the stubs. */
1915 hppa_elf_stub_finish (output_bfd
)
1918 elf32_hppa_stub_description
*stub_list
= elf_hppa_stub_rootP
;
1920 /* If the stubs have been finished, then we're already done. */
1924 /* Walk down the list of stub lists. */
1925 for (; stub_list
; stub_list
= stub_list
->next
)
1927 /* If this list has stubs, then do something. */
1928 if (stub_list
->real_size
)
1930 bfd
*stub_bfd
= stub_list
->this_bfd
;
1931 asection
*stub_sec
= bfd_get_section_by_name (stub_bfd
,
1932 ".hppa_linker_stubs");
1933 bfd_size_type reloc_size
;
1934 arelent
**reloc_vector
;
1936 /* Some sanity checking. */
1937 BFD_ASSERT (stub_sec
== stub_list
->stub_sec
);
1938 BFD_ASSERT (stub_sec
);
1940 /* For stub sections raw_size == cooked_size. Also update
1941 reloc_done as we're handling the relocs now. */
1942 stub_sec
->_cooked_size
= stub_sec
->_raw_size
;
1943 stub_sec
->reloc_done
= true;
1945 /* Make space to hold the relocations for the stub section. */
1946 reloc_size
= bfd_get_reloc_upper_bound (stub_bfd
, stub_sec
);
1947 reloc_vector
= (arelent
**) malloc (reloc_size
);
1948 if (reloc_vector
== NULL
&& reloc_size
!= 0)
1950 /* FIXME: should be returning an error so the caller can
1955 /* If we have relocations, do them. */
1956 if (bfd_canonicalize_reloc (stub_bfd
, stub_sec
, reloc_vector
,
1957 output_bfd
->outsymbols
))
1960 for (parent
= reloc_vector
; *parent
!= NULL
; parent
++)
1963 bfd_reloc_status_type r
=
1964 bfd_perform_relocation (stub_bfd
, *parent
,
1965 stub_list
->stub_contents
,
1966 stub_sec
, (bfd
*) NULL
, &err
);
1968 /* If there was an error, tell someone about it. */
1969 if (r
!= bfd_reloc_ok
)
1971 struct bfd_link_info
*link_info
= stub_list
->link_info
;
1975 case bfd_reloc_undefined
:
1976 if (! ((*link_info
->callbacks
->undefined_symbol
)
1978 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
1979 stub_bfd
, stub_sec
, (*parent
)->address
)))
1982 case bfd_reloc_dangerous
:
1983 if (! ((*link_info
->callbacks
->reloc_dangerous
)
1984 (link_info
, err
, stub_bfd
, stub_sec
,
1985 (*parent
)->address
)))
1988 case bfd_reloc_overflow
:
1990 if (! ((*link_info
->callbacks
->reloc_overflow
)
1992 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
1993 (*parent
)->howto
->name
,
1996 (*parent
)->address
)))
2000 case bfd_reloc_outofrange
:
2008 free (reloc_vector
);
2010 /* All done with the relocations. Set the final contents
2011 of the stub section. FIXME: no check of return value! */
2012 bfd_set_section_contents (output_bfd
, stub_sec
,
2013 stub_list
->stub_contents
,
2014 0, stub_list
->real_size
);
2018 stubs_finished
= true;
2021 /* Allocate a new relocation entry to be used in a linker stub. */
2024 hppa_elf_stub_reloc (stub_desc
, output_bfd
, target_sym
, offset
, type
)
2025 elf32_hppa_stub_description
*stub_desc
;
2027 asymbol
**target_sym
;
2029 elf32_hppa_reloc_type type
;
2033 Elf_Internal_Shdr
*rela_hdr
;
2035 /* I really don't like the realloc nonsense in here. FIXME. */
2036 if (stub_desc
->relocs_allocated_cnt
== stub_desc
->stub_sec
->reloc_count
)
2038 /* Allocate the first few relocation entries. */
2039 if (stub_desc
->stub_sec
->relocation
== NULL
)
2041 stub_desc
->relocs_allocated_cnt
= STUB_RELOC_INCR
;
2042 size
= sizeof (arelent
) * stub_desc
->relocs_allocated_cnt
;
2043 stub_desc
->stub_sec
->relocation
= (arelent
*) bfd_zmalloc (size
);
2047 /* We've used all the entries we've already allocated. So get
2049 stub_desc
->relocs_allocated_cnt
+= STUB_RELOC_INCR
;
2050 size
= sizeof (arelent
) * stub_desc
->relocs_allocated_cnt
;
2051 stub_desc
->stub_sec
->relocation
= (arelent
*)
2052 realloc (stub_desc
->stub_sec
->relocation
, size
);
2054 if (!stub_desc
->stub_sec
->relocation
)
2056 bfd_set_error (bfd_error_no_memory
);
2057 abort (); /* FIXME */
2061 rela_hdr
= &elf_section_data(stub_desc
->stub_sec
)->rel_hdr
;
2062 rela_hdr
->sh_size
+= sizeof(Elf32_External_Rela
);
2064 /* Fill in the details. */
2065 relent
.address
= offset
;
2067 relent
.sym_ptr_ptr
= target_sym
;
2068 relent
.howto
= bfd_reloc_type_lookup (stub_desc
->this_bfd
, type
);
2070 /* Save it in the array of relocations for the stub section. */
2071 memcpy (&stub_desc
->stub_sec
->relocation
[stub_desc
->stub_sec
->reloc_count
++],
2072 &relent
, sizeof (arelent
));
2075 /* Build an argument relocation stub. RTN_ADJUST is a hint that an
2076 adjust to the return pointer from within the stub itself may be
2080 hppa_elf_build_linker_stub (abfd
, output_bfd
, link_info
, reloc_entry
,
2081 stub_types
, rtn_adjust
, data
, linker_stub_type
)
2084 struct bfd_link_info
*link_info
;
2085 arelent
*reloc_entry
;
2086 arg_reloc_type stub_types
[5];
2089 hppa_stub_type linker_stub_type
;
2092 boolean milli
, dyncall
;
2093 char stub_sym_name
[128];
2094 elf32_hppa_stub_name_list
*stub_entry
;
2095 /* Some initialization. */
2096 unsigned insn
= data
[0];
2097 asymbol
*stub_sym
= NULL
;
2098 asymbol
**orig_sym
= reloc_entry
->sym_ptr_ptr
;
2099 asection
*stub_sec
= bfd_get_section_by_name (abfd
, ".hppa_linker_stubs");
2100 elf32_hppa_stub_description
*stub_desc
= find_stubs (abfd
, stub_sec
);
2102 /* Perform some additional checks on whether we should really do the
2103 return adjustment. For example, if the instruction is nullified
2104 or if the delay slot contains an instruction that modifies the return
2105 pointer, then the branch instructions should not be rearranged
2106 (rtn_adjust is false). */
2107 if (insn
& 2 || insn
== 0)
2111 unsigned delay_insn
= data
[1];
2113 if (get_opcode (delay_insn
) == LDO
2114 && (((insn
& 0x03e00000) >> 21) == ((delay_insn
& 0x001f0000) >> 16)))
2118 /* Some special code for long-call stubs. */
2119 if (linker_stub_type
== HPPA_STUB_LONG_CALL
)
2122 /* Is this a millicode call? If so, the return address
2123 comes in on r31 rather than r2 (rp) so a slightly
2124 different code sequence is needed. */
2125 unsigned rtn_reg
= (insn
& 0x03e00000) >> 21;
2129 /* Dyncall is special because the user code has already
2130 put the return pointer in %r2 (aka RP). Other millicode
2131 calls have the return pointer in %r31. */
2132 if (strcmp ((*orig_sym
)->name
, "$$dyncall") == 0)
2135 /* If we are creating a call from a stub to another stub, then
2136 never do the instruction reordering. We can tell if we are
2137 going to be calling one stub from another by the fact that
2138 the symbol name has '_stub_' (arg. reloc. stub) or '_lb_stub_'
2139 prepended to the name. Alternatively, the section of the
2140 symbol will be '.hppa_linker_stubs'. This is only an issue
2141 for long-calls; they are the only stubs allowed to call another
2143 if ((strncmp ((*orig_sym
)->name
, "_stub_", 6) == 0)
2144 || (strncmp ((*orig_sym
)->name
, "_lb_stub_", 9) == 0))
2146 BFD_ASSERT (strcmp ((*orig_sym
)->section
->name
, ".hppa_linker_stubs")
2152 /* Create the stub section if necessary. */
2155 BFD_ASSERT (stub_desc
== NULL
);
2156 hppa_elf_create_stub_sec (abfd
, output_bfd
, &stub_sec
, link_info
);
2157 stub_desc
= new_stub (abfd
, stub_sec
, link_info
);
2160 /* Make the stub if we did not find one already. */
2162 stub_desc
= new_stub (abfd
, stub_sec
, link_info
);
2164 /* Allocate space to write the stub.
2165 FIXME: Why using realloc?!? */
2166 if (!stub_desc
->stub_contents
)
2168 stub_desc
->allocated_size
= STUB_BUFFER_INCR
;
2169 stub_desc
->stub_contents
= (char *) malloc (STUB_BUFFER_INCR
);
2171 else if ((stub_desc
->allocated_size
- stub_desc
->real_size
) < STUB_MAX_SIZE
)
2173 stub_desc
->allocated_size
= stub_desc
->allocated_size
+ STUB_BUFFER_INCR
;
2174 stub_desc
->stub_contents
= (char *) realloc (stub_desc
->stub_contents
,
2175 stub_desc
->allocated_size
);
2178 /* If no memory die. (I seriously doubt the other routines
2179 are prepared to get a NULL return value). */
2180 if (!stub_desc
->stub_contents
)
2182 bfd_set_error (bfd_error_no_memory
);
2186 /* Generate an appropriate name for this stub. */
2187 if (linker_stub_type
== HPPA_STUB_ARG_RELOC
)
2188 sprintf (stub_sym_name
,
2189 "_stub_%s_%02d_%02d_%02d_%02d_%02d_%s",
2190 reloc_entry
->sym_ptr_ptr
[0]->name
,
2191 stub_types
[0], stub_types
[1], stub_types
[2],
2192 stub_types
[3], stub_types
[4],
2193 rtn_adjust
? "RA" : "");
2195 sprintf (stub_sym_name
,
2196 "_lb_stub_%s_%s", reloc_entry
->sym_ptr_ptr
[0]->name
,
2197 rtn_adjust
? "RA" : "");
2200 stub_desc
->stub_secp
2201 = (int *) (stub_desc
->stub_contents
+ stub_desc
->real_size
);
2202 stub_entry
= find_stub_by_name (abfd
, stub_sec
, stub_sym_name
);
2204 /* See if we already have one by this name. */
2207 /* Yes, re-use it. Redirect the original relocation from the
2208 old symbol (a function symbol) to the stub (the stub will call
2209 the original function). */
2210 stub_sym
= stub_entry
->sym
;
2211 reloc_entry
->sym_ptr_ptr
= (asymbol
**) bfd_zalloc (abfd
,
2212 sizeof (asymbol
**));
2213 if (reloc_entry
->sym_ptr_ptr
== NULL
)
2215 bfd_set_error (bfd_error_no_memory
);
2218 reloc_entry
->sym_ptr_ptr
[0] = stub_sym
;
2219 if (linker_stub_type
== HPPA_STUB_LONG_CALL
2220 || (reloc_entry
->howto
->type
!= R_HPPA_PLABEL_32
2221 && (get_opcode(insn
) == BLE
2222 || get_opcode (insn
) == BE
2223 || get_opcode (insn
) == BL
)))
2224 reloc_entry
->howto
= bfd_reloc_type_lookup (abfd
, R_HPPA_STUB_CALL_17
);
2228 /* Create a new symbol to point to this stub. */
2229 stub_sym
= bfd_make_empty_symbol (abfd
);
2232 bfd_set_error (bfd_error_no_memory
);
2235 stub_sym
->name
= bfd_zalloc (abfd
, strlen (stub_sym_name
) + 1);
2236 if (!stub_sym
->name
)
2238 bfd_set_error (bfd_error_no_memory
);
2241 strcpy ((char *) stub_sym
->name
, stub_sym_name
);
2243 = (char *) stub_desc
->stub_secp
- (char *) stub_desc
->stub_contents
;
2244 stub_sym
->section
= stub_sec
;
2245 stub_sym
->flags
= BSF_LOCAL
| BSF_FUNCTION
;
2246 stub_entry
= add_stub_by_name (abfd
, stub_sec
, stub_sym
, link_info
);
2248 /* Redirect the original relocation from the old symbol (a function)
2249 to the stub (the stub calls the function). */
2250 reloc_entry
->sym_ptr_ptr
= (asymbol
**) bfd_zalloc (abfd
,
2251 sizeof (asymbol
**));
2252 if (reloc_entry
->sym_ptr_ptr
== NULL
)
2254 bfd_set_error (bfd_error_no_memory
);
2257 reloc_entry
->sym_ptr_ptr
[0] = stub_sym
;
2258 if (linker_stub_type
== HPPA_STUB_LONG_CALL
2259 || (reloc_entry
->howto
->type
!= R_HPPA_PLABEL_32
2260 && (get_opcode (insn
) == BLE
2261 || get_opcode (insn
) == BE
2262 || get_opcode (insn
) == BL
)))
2263 reloc_entry
->howto
= bfd_reloc_type_lookup (abfd
, R_HPPA_STUB_CALL_17
);
2265 /* Now generate the code for the stub. Starting with two
2266 common instructions.
2268 FIXME: Do we still need the SP adjustment?
2269 Do we still need to muck with space registers? */
2270 NEW_INSTRUCTION (stub_entry
, LDSID_31_1
)
2271 NEW_INSTRUCTION (stub_entry
, MTSP_1_SR0
)
2273 if (linker_stub_type
== HPPA_STUB_ARG_RELOC
)
2275 NEW_INSTRUCTION (stub_entry
, ADDI_8_SP
)
2277 /* Examine each argument, generating code to relocate it
2278 into a different register if necessary. */
2279 for (i
= ARG0
; i
< ARG3
; i
++)
2281 switch (stub_types
[i
])
2291 NEW_INSTRUCTION (stub_entry
, STWS_ARG0_M8SP
)
2292 NEW_INSTRUCTION (stub_entry
, FLDWS_M8SP_FARG0
)
2295 NEW_INSTRUCTION (stub_entry
, STWS_ARG1_M8SP
)
2296 NEW_INSTRUCTION (stub_entry
, FLDWS_M8SP_FARG1
)
2299 NEW_INSTRUCTION (stub_entry
, STWS_ARG2_M8SP
)
2300 NEW_INSTRUCTION (stub_entry
, FLDWS_M8SP_FARG2
)
2303 NEW_INSTRUCTION (stub_entry
, STWS_ARG3_M8SP
)
2304 NEW_INSTRUCTION (stub_entry
, FLDWS_M8SP_FARG3
)
2313 NEW_INSTRUCTION (stub_entry
, STWS_ARG0_M4SP
)
2314 NEW_INSTRUCTION (stub_entry
, STWS_ARG1_M8SP
)
2315 NEW_INSTRUCTION (stub_entry
, FLDDS_M8SP_FARG1
)
2327 NEW_INSTRUCTION (stub_entry
, STWS_ARG2_M4SP
)
2328 NEW_INSTRUCTION (stub_entry
, STWS_ARG3_M8SP
)
2329 NEW_INSTRUCTION (stub_entry
, FLDDS_M8SP_FARG3
)
2341 NEW_INSTRUCTION (stub_entry
, FSTWS_FARG0_M8SP
)
2342 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG0
)
2345 NEW_INSTRUCTION (stub_entry
, FSTWS_FARG1_M8SP
)
2346 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG1
)
2349 NEW_INSTRUCTION (stub_entry
, FSTWS_FARG2_M8SP
)
2350 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG2
)
2353 NEW_INSTRUCTION (stub_entry
, FSTWS_FARG3_M8SP
)
2354 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG3
)
2363 NEW_INSTRUCTION (stub_entry
, FSTDS_FARG1_M8SP
)
2364 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG0
)
2365 NEW_INSTRUCTION (stub_entry
, LDWS_M8SP_ARG1
)
2377 NEW_INSTRUCTION (stub_entry
, FSTDS_FARG3_M8SP
)
2378 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG2
)
2379 NEW_INSTRUCTION (stub_entry
, LDWS_M8SP_ARG3
)
2393 /* Put the stack pointer back. FIXME: Is this still necessary? */
2394 NEW_INSTRUCTION (stub_entry
, ADDI_M8_SP_SP
)
2397 /* Common code again. Return pointer adjustment and the like. */
2400 /* This isn't dyncall. */
2403 /* It's not a millicode call, so get the correct return
2404 value into %r2 (aka RP). */
2406 NEW_INSTRUCTION (stub_entry
, ADDI_M4_31_RP
)
2408 NEW_INSTRUCTION (stub_entry
, COPY_31_2
)
2412 /* It is a millicode call, so get the correct return
2413 value into %r1?!?. FIXME: Shouldn't this be
2414 %r31? Yes, and a little re-arrangement of the
2415 code below would make that possible. */
2417 NEW_INSTRUCTION (stub_entry
, ADDI_M4_31_1
)
2419 NEW_INSTRUCTION (stub_entry
, COPY_31_1
)
2424 /* This is dyncall, so the code is a little different as the
2425 return pointer is already in %r2 (aka RP). */
2427 NEW_INSTRUCTION (stub_entry
, ADDI_M4_31_RP
)
2430 /* Save the return address. */
2431 if (linker_stub_type
== HPPA_STUB_ARG_RELOC
)
2432 NEW_INSTRUCTION (stub_entry
, STW_RP_M8SP
)
2434 /* Long branch to the target function. */
2435 NEW_INSTRUCTION (stub_entry
, LDIL_XXX_31
)
2436 hppa_elf_stub_reloc (stub_entry
->stub_desc
,
2438 CURRENT_STUB_OFFSET (stub_entry
),
2440 NEW_INSTRUCTION (stub_entry
, BLE_XXX_0_31
)
2441 hppa_elf_stub_reloc (stub_entry
->stub_desc
,
2443 CURRENT_STUB_OFFSET (stub_entry
),
2444 R_HPPA_ABS_CALL_R17
);
2446 if (linker_stub_type
== HPPA_STUB_ARG_RELOC
)
2448 /* In delay slot of long-call, copy %r31 into %r2 so that
2449 the callee can return in the normal fashion. */
2450 NEW_INSTRUCTION (stub_entry
, COPY_31_2
)
2452 /* Restore the return address. */
2453 NEW_INSTRUCTION (stub_entry
, LDW_M8SP_RP
)
2455 /* Generate the code to move the return value around. */
2456 switch (stub_types
[RETVAL
])
2462 NEW_INSTRUCTION (stub_entry
, STWS_RET0_M8SP
)
2463 NEW_INSTRUCTION (stub_entry
, FLDWS_M8SP_FRET0
)
2467 NEW_INSTRUCTION (stub_entry
, FSTWS_FRET0_M8SP
)
2468 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_RET0
)
2476 /* Return back to the main code stream. */
2477 NEW_INSTRUCTION (stub_entry
, BV_N_0_RP
)
2483 /* Get return address into %r31. Both variants may be necessary
2484 (I think) as we could be cascading into another stub. */
2486 NEW_INSTRUCTION (stub_entry
, COPY_2_31
)
2488 NEW_INSTRUCTION (stub_entry
, COPY_1_31
)
2492 /* Get the return address into %r31 too. Might be necessary
2493 (I think) as we could be cascading into another stub. */
2494 NEW_INSTRUCTION (stub_entry
, COPY_2_31
)
2497 /* No need for a return to the main stream. */
2503 /* Return nonzero if an argument relocation will be needed to call
2504 the function (symbol in RELOC_ENTRY) assuming the caller has
2505 argument relocation bugs CALLER_AR. */
2508 hppa_elf_arg_reloc_needed_p (abfd
, reloc_entry
, stub_types
, caller_ar
)
2510 arelent
*reloc_entry
;
2511 arg_reloc_type stub_types
[5];
2512 symext_entryS caller_ar
;
2514 /* If the symbol is still undefined, then it's impossible to know
2515 if an argument relocation is needed. */
2516 if (reloc_entry
->sym_ptr_ptr
[0]
2517 && reloc_entry
->sym_ptr_ptr
[0]->section
!= &bfd_und_section
)
2519 symext_entryS callee_ar
= elf32_hppa_get_sym_extn (abfd
,
2520 reloc_entry
->sym_ptr_ptr
[0],
2521 HPPA_SXT_ARG_RELOC
);
2523 /* Now examine all the argument and return value location
2524 information to determine if a relocation stub will be needed. */
2525 if (caller_ar
&& callee_ar
)
2527 arg_location caller_loc
[5];
2528 arg_location callee_loc
[5];
2530 /* Extract the location information for the return value
2531 and argument registers separately. */
2532 callee_loc
[RETVAL
] = EXTRACT_ARBITS (callee_ar
, RETVAL
);
2533 caller_loc
[RETVAL
] = EXTRACT_ARBITS (caller_ar
, RETVAL
);
2534 callee_loc
[ARG0
] = EXTRACT_ARBITS (callee_ar
, ARG0
);
2535 caller_loc
[ARG0
] = EXTRACT_ARBITS (caller_ar
, ARG0
);
2536 callee_loc
[ARG1
] = EXTRACT_ARBITS (callee_ar
, ARG1
);
2537 caller_loc
[ARG1
] = EXTRACT_ARBITS (caller_ar
, ARG1
);
2538 callee_loc
[ARG2
] = EXTRACT_ARBITS (callee_ar
, ARG2
);
2539 caller_loc
[ARG2
] = EXTRACT_ARBITS (caller_ar
, ARG2
);
2540 callee_loc
[ARG3
] = EXTRACT_ARBITS (callee_ar
, ARG3
);
2541 caller_loc
[ARG3
] = EXTRACT_ARBITS (caller_ar
, ARG3
);
2543 /* Check some special combinations. For example, if FU
2544 appears in ARG1 or ARG3, we can move it to ARG0 or ARG2,
2545 respectively. (I guess this braindamage is correct? It'd
2546 take an hour or two of reading PA calling conventions to
2549 if (caller_loc
[ARG0
] == AR_FU
|| caller_loc
[ARG1
] == AR_FU
)
2551 caller_loc
[ARG0
] = AR_DBL01
;
2552 caller_loc
[ARG1
] = AR_NO
;
2554 if (caller_loc
[ARG2
] == AR_FU
|| caller_loc
[ARG3
] == AR_FU
)
2556 caller_loc
[ARG2
] = AR_DBL23
;
2557 caller_loc
[ARG3
] = AR_NO
;
2559 if (callee_loc
[ARG0
] == AR_FU
|| callee_loc
[ARG1
] == AR_FU
)
2561 callee_loc
[ARG0
] = AR_DBL01
;
2562 callee_loc
[ARG1
] = AR_NO
;
2564 if (callee_loc
[ARG2
] == AR_FU
|| callee_loc
[ARG3
] == AR_FU
)
2566 callee_loc
[ARG2
] = AR_DBL23
;
2567 callee_loc
[ARG3
] = AR_NO
;
2570 /* Now look up potential mismatches. */
2571 stub_types
[ARG0
] = type_of_mismatch (caller_loc
[ARG0
],
2574 stub_types
[ARG1
] = type_of_mismatch (caller_loc
[ARG1
],
2577 stub_types
[ARG2
] = type_of_mismatch (caller_loc
[ARG2
],
2580 stub_types
[ARG3
] = type_of_mismatch (caller_loc
[ARG3
],
2583 stub_types
[RETVAL
] = type_of_mismatch (caller_loc
[RETVAL
],
2587 /* If any of the arguments or return value need an argument
2588 relocation, then we will need an argument relocation stub. */
2589 if (stub_types
[ARG0
] != NO_ARG_RELOC
2590 || stub_types
[ARG1
] != NO_ARG_RELOC
2591 || stub_types
[ARG2
] != NO_ARG_RELOC
2592 || stub_types
[ARG3
] != NO_ARG_RELOC
2593 || stub_types
[RETVAL
] != NO_ARG_RELOC
)
2600 /* Create the linker stub section. */
2603 hppa_elf_create_stub_sec (abfd
, output_bfd
, secptr
, link_info
)
2607 struct bfd_link_info
*link_info
;
2609 asection
*output_text_section
;
2611 output_text_section
= bfd_get_section_by_name (output_bfd
, ".text");
2612 *secptr
= bfd_make_section (abfd
, ".hppa_linker_stubs");
2613 bfd_set_section_flags (abfd
, *secptr
,
2614 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
2615 | SEC_RELOC
| SEC_CODE
| SEC_READONLY
);
2616 (*secptr
)->output_section
= output_text_section
->output_section
;
2617 (*secptr
)->output_offset
= 0;
2619 /* Set up the ELF section header for this new section. This
2620 is basically the same processing as elf_make_sections().
2621 elf_make_sections is static and therefore not accessable
2624 Elf_Internal_Shdr
*this_hdr
;
2625 this_hdr
= &elf_section_data ((*secptr
))->this_hdr
;
2627 /* Set the sizes of this section. The contents have already
2629 this_hdr
->sh_addr
= (*secptr
)->vma
;
2630 this_hdr
->sh_size
= (*secptr
)->_raw_size
;
2632 /* Set appropriate flags for sections with relocations. */
2633 if ((*secptr
)->flags
& SEC_RELOC
)
2635 Elf_Internal_Shdr
*rela_hdr
;
2636 int use_rela_p
= get_elf_backend_data (abfd
)->use_rela_p
;
2638 rela_hdr
= &elf_section_data ((*secptr
))->rel_hdr
;
2642 rela_hdr
->sh_type
= SHT_RELA
;
2643 rela_hdr
->sh_entsize
= sizeof (Elf32_External_Rela
);
2647 rela_hdr
->sh_type
= SHT_REL
;
2648 rela_hdr
->sh_entsize
= sizeof (Elf32_External_Rel
);
2650 rela_hdr
->sh_flags
= 0;
2651 rela_hdr
->sh_addr
= 0;
2652 rela_hdr
->sh_offset
= 0;
2653 rela_hdr
->sh_addralign
= 0;
2657 if ((*secptr
)->flags
& SEC_ALLOC
)
2658 this_hdr
->sh_flags
|= SHF_ALLOC
;
2660 if (!((*secptr
)->flags
& SEC_READONLY
))
2661 this_hdr
->sh_flags
|= SHF_WRITE
;
2663 if ((*secptr
)->flags
& SEC_CODE
)
2664 this_hdr
->sh_flags
|= SHF_EXECINSTR
;
2667 bfd_set_section_alignment (abfd
, *secptr
, 2);
2670 /* Return nonzero if a long-call stub will be needed to call the
2671 function (symbol in RELOC_ENTRY). */
2674 hppa_elf_long_branch_needed_p (abfd
, asec
, reloc_entry
, symbol
, insn
)
2677 arelent
*reloc_entry
;
2681 long sym_value
= get_symbol_value (symbol
);
2682 int fmt
= reloc_entry
->howto
->bitsize
;
2683 unsigned char op
= get_opcode (insn
);
2686 #define too_far(val,num_bits) \
2687 ((int)(val) > (1 << (num_bits)) - 1) || ((int)(val) < (-1 << (num_bits)))
2693 reloc_entry
->address
+ asec
->output_offset
+ asec
->output_section
->vma
;
2694 /* If the symbol and raddr (relocated addr?) are too far away from
2695 each other, then a long-call stub will be needed. */
2696 if (too_far (sym_value
- raddr
, fmt
+ 1))
2703 /* Search the given section and determine if linker stubs will be
2704 needed for any calls within that section.
2706 Return any new stub symbols created.
2708 Used out of hppaelf.em in the linker. */
2711 hppa_look_for_stubs_in_section (stub_bfd
, abfd
, output_bfd
, asec
,
2712 new_sym_cnt
, link_info
)
2718 struct bfd_link_info
*link_info
;
2721 arg_reloc_type stub_types
[5];
2722 asymbol
*new_syms
= NULL
;
2725 arelent
**reloc_vector
= NULL
;
2727 /* Relocations are in different places depending on whether this is
2728 an output section or an input section. Also, the relocations are
2729 in different forms. Sigh. Luckily, we have bfd_canonicalize_reloc()
2730 to straighten this out for us . */
2731 if (asec
->reloc_count
> 0)
2734 = (arelent
**) malloc (asec
->reloc_count
* (sizeof (arelent
*) + 1));
2735 if (reloc_vector
== NULL
)
2737 bfd_set_error (bfd_error_no_memory
);
2741 /* Make sure the canonical symbols are hanging around in a convient
2743 if (bfd_get_outsymbols (abfd
) == NULL
)
2747 symsize
= get_symtab_upper_bound (abfd
);
2748 abfd
->outsymbols
= (asymbol
**) bfd_alloc (abfd
, symsize
);
2749 if (!abfd
->outsymbols
)
2751 bfd_set_error (bfd_error_no_memory
);
2754 abfd
->symcount
= bfd_canonicalize_symtab (abfd
, abfd
->outsymbols
);
2757 /* Now get the relocations. */
2758 bfd_canonicalize_reloc (abfd
, asec
, reloc_vector
,
2759 bfd_get_outsymbols (abfd
));
2761 /* Examine each relocation entry in this section. */
2762 for (i
= 0; i
< asec
->reloc_count
; i
++)
2764 arelent
*rle
= reloc_vector
[i
];
2766 switch (rle
->howto
->type
)
2768 /* Any call could need argument relocation stubs, and
2769 some may need long-call stubs. */
2770 case R_HPPA_ABS_CALL_11
:
2771 case R_HPPA_ABS_CALL_14
:
2772 case R_HPPA_ABS_CALL_17
:
2773 case R_HPPA_ABS_CALL_L21
:
2774 case R_HPPA_ABS_CALL_R11
:
2775 case R_HPPA_ABS_CALL_R14
:
2776 case R_HPPA_ABS_CALL_R17
:
2777 case R_HPPA_ABS_CALL_LS21
:
2778 case R_HPPA_ABS_CALL_RS11
:
2779 case R_HPPA_ABS_CALL_RS14
:
2780 case R_HPPA_ABS_CALL_RS17
:
2781 case R_HPPA_ABS_CALL_LD21
:
2782 case R_HPPA_ABS_CALL_RD11
:
2783 case R_HPPA_ABS_CALL_RD14
:
2784 case R_HPPA_ABS_CALL_RD17
:
2785 case R_HPPA_ABS_CALL_LR21
:
2786 case R_HPPA_ABS_CALL_RR14
:
2787 case R_HPPA_ABS_CALL_RR17
:
2788 case R_HPPA_PCREL_CALL_11
:
2789 case R_HPPA_PCREL_CALL_14
:
2790 case R_HPPA_PCREL_CALL_17
:
2791 case R_HPPA_PCREL_CALL_12
:
2792 case R_HPPA_PCREL_CALL_L21
:
2793 case R_HPPA_PCREL_CALL_R11
:
2794 case R_HPPA_PCREL_CALL_R14
:
2795 case R_HPPA_PCREL_CALL_R17
:
2796 case R_HPPA_PCREL_CALL_LS21
:
2797 case R_HPPA_PCREL_CALL_RS11
:
2798 case R_HPPA_PCREL_CALL_RS14
:
2799 case R_HPPA_PCREL_CALL_RS17
:
2800 case R_HPPA_PCREL_CALL_LD21
:
2801 case R_HPPA_PCREL_CALL_RD11
:
2802 case R_HPPA_PCREL_CALL_RD14
:
2803 case R_HPPA_PCREL_CALL_RD17
:
2804 case R_HPPA_PCREL_CALL_LR21
:
2805 case R_HPPA_PCREL_CALL_RR14
:
2806 case R_HPPA_PCREL_CALL_RR17
:
2808 symext_entryS caller_ar
2809 = (symext_entryS
) HPPA_R_ARG_RELOC (rle
->addend
);
2812 /* We'll need this for the long-call checks. */
2813 bfd_get_section_contents (abfd
, asec
, insn
, rle
->address
,
2816 /* See if this call needs an argument relocation stub. */
2817 if (hppa_elf_arg_reloc_needed_p (abfd
, rle
, stub_types
,
2820 /* Generate a stub and keep track of the new symbol. */
2823 if (new_cnt
== new_max
)
2825 new_max
+= STUB_SYM_BUFFER_INC
;
2826 new_syms
= (asymbol
*)
2827 realloc (new_syms
, new_max
* sizeof (asymbol
));
2828 if (new_syms
== NULL
)
2830 bfd_set_error (bfd_error_no_memory
);
2835 /* Build the argument relocation stub. */
2836 r
= hppa_elf_build_linker_stub (stub_bfd
, output_bfd
,
2838 stub_types
, true, insn
,
2839 HPPA_STUB_ARG_RELOC
);
2840 new_syms
[new_cnt
++] = *r
;
2843 /* See if this call needs a long-call stub. */
2844 if (hppa_elf_long_branch_needed_p (abfd
, asec
, rle
,
2845 rle
->sym_ptr_ptr
[0],
2848 /* Generate a stub and keep track of the new symbol. */
2851 if (new_cnt
== new_max
)
2853 new_max
+= STUB_SYM_BUFFER_INC
;
2854 new_syms
= (asymbol
*)
2855 realloc (new_syms
, (new_max
* sizeof (asymbol
)));
2858 bfd_set_error (bfd_error_no_memory
);
2863 /* Build the long-call stub. */
2864 r
= hppa_elf_build_linker_stub (stub_bfd
, output_bfd
,
2867 HPPA_STUB_LONG_CALL
);
2868 new_syms
[new_cnt
++] = *r
;
2873 /* PLABELs may need argument relocation stubs. */
2874 case R_HPPA_PLABEL_32
:
2875 case R_HPPA_PLABEL_11
:
2876 case R_HPPA_PLABEL_14
:
2877 case R_HPPA_PLABEL_L21
:
2878 case R_HPPA_PLABEL_R11
:
2879 case R_HPPA_PLABEL_R14
:
2881 /* On a plabel relocation, assume the arguments of the
2882 caller are set up in general registers (indirect
2883 calls only use general registers.
2884 NOTE: 0x155 = ARGW0=GR,ARGW1=GR,ARGW2=GR,RETVAL=GR. */
2885 symext_entryS caller_ar
= (symext_entryS
) 0x155;
2888 /* Do we really need this? */
2889 bfd_get_section_contents (abfd
, asec
, insn
, rle
->address
,
2892 /* See if this call needs an argument relocation stub. */
2893 if (hppa_elf_arg_reloc_needed_p (abfd
, rle
, stub_types
,
2896 /* Generate a plabel stub and keep track of the
2901 if (new_cnt
== new_max
)
2903 new_max
+= STUB_SYM_BUFFER_INC
;
2904 new_syms
= (asymbol
*) realloc (new_syms
, new_max
2905 * sizeof (asymbol
));
2908 /* Determine whether a return adjustment
2909 (see the relocation code for relocation type
2910 R_HPPA_STUB_CALL_17) is possible. Basically,
2911 determine whether we are looking at a branch or not. */
2912 if (rle
->howto
->type
== R_HPPA_PLABEL_32
)
2916 switch (get_opcode(insn
[0]))
2927 /* Build the argument relocation stub. */
2928 r
= hppa_elf_build_linker_stub (stub_bfd
, output_bfd
,
2929 link_info
, rle
, stub_types
,
2931 HPPA_STUB_ARG_RELOC
);
2932 new_syms
[new_cnt
++] = *r
;
2943 if (reloc_vector
!= NULL
)
2944 free (reloc_vector
);
2945 /* Return the new symbols and update the counters. */
2946 *new_sym_cnt
= new_cnt
;
2950 if (reloc_vector
!= NULL
)
2951 free (reloc_vector
);
2952 /* FIXME: This is bogus. We should be returning NULL. But do the callers
2957 /* Set the contents of a particular section at a particular location. */
2960 hppa_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
2965 bfd_size_type count
;
2967 /* Linker stubs are handled a little differently. */
2968 if (! strcmp (section
->name
, ".hppa_linker_stubs"))
2970 if (linker_stubs_max_size
< offset
+ count
)
2972 linker_stubs_max_size
= offset
+ count
+ STUB_ALLOC_INCR
;
2973 linker_stubs
= (char *)realloc (linker_stubs
, linker_stubs_max_size
);
2978 if (offset
+ count
> linker_stubs_size
)
2979 linker_stubs_size
= offset
+ count
;
2981 /* Set the contents. */
2982 memcpy(linker_stubs
+ offset
, location
, count
);
2986 /* For everything but the linker stub section, use the generic
2988 return bfd_elf32_set_section_contents (abfd
, section
, location
,
2992 /* Get the contents of the given section.
2994 This is special for PA ELF because some sections (such as linker stubs)
2995 may reside in memory rather than on disk, or in the case of the symbol
2996 extension section, the contents may need to be generated from other
2997 information contained in the BFD. */
3000 hppa_elf_get_section_contents (abfd
, section
, location
, offset
, count
)
3005 bfd_size_type count
;
3007 /* If this is the linker stub section, then its contents are contained
3008 in memory rather than on disk. FIXME. Is that always right? What
3009 about the case where a final executable is read in and a user tries
3010 to get the contents of this section? In that case the contents would
3011 be on disk like everything else. */
3012 if (strcmp (section
->name
, ".hppa_linker_stubs") == 0)
3014 elf32_hppa_stub_description
*stub_desc
= find_stubs (abfd
, section
);
3019 /* Sanity check our arguments. */
3020 if ((bfd_size_type
) (offset
+ count
) > section
->_raw_size
3021 || (bfd_size_type
) (offset
+ count
) > stub_desc
->real_size
)
3024 memcpy (location
, stub_desc
->stub_contents
+ offset
, count
);
3028 /* The symbol extension section also needs special handling. Its
3029 contents might be on the disk, in memory, or still need to
3031 else if (strcmp (section
->name
, ".hppa_symextn") == 0)
3033 /* If there are no output sections, then read the contents of the
3034 symbol extension section from disk. */
3035 if (section
->output_section
== NULL
3036 && abfd
->direction
== read_direction
)
3038 return bfd_generic_get_section_contents (abfd
, section
, location
,
3042 /* If this is the first time through, and there are output sections,
3043 then build the symbol extension section based on other information
3044 contained in the BFD. */
3045 else if (! symext_chain_built
)
3049 (int *) elf_sym_extra (section
->output_section
->owner
);
3051 for (i
= 0; i
< section
->output_section
->owner
->symcount
; i
++)
3053 elf_hppa_tc_symbol (section
->output_section
->owner
,
3054 ((elf_symbol_type
*)
3055 section
->output_section
->owner
->outsymbols
[i
]),
3056 symtab_map
[i
], &symext_rootP
, &symext_lastP
);
3058 symext_chain_built
++;
3059 elf_hppa_tc_make_sections (section
->output_section
->owner
,
3063 /* At this point we know that the symbol extension section has been
3064 built. We just need to copy it into the user's buffer. */
3068 /* Sanity check our arguments. */
3069 if ((bfd_size_type
) (offset
+ count
) > section
->_raw_size
3070 || (bfd_size_type
) (offset
+ count
) > symextn_contents_real_size
)
3074 (char *)symextn_contents
+ section
->output_offset
+ offset
,
3079 /* It's not the symbol extension or linker stub sections, use
3080 the generic routines. */
3081 return bfd_generic_get_section_contents (abfd
, section
, location
,
3085 /* Translate from an elf into field into a howto relocation pointer. */
3088 elf_info_to_howto (abfd
, cache_ptr
, dst
)
3091 Elf32_Internal_Rela
*dst
;
3093 BFD_ASSERT (ELF32_R_TYPE(dst
->r_info
) < (unsigned int) R_HPPA_UNIMPLEMENTED
);
3094 cache_ptr
->howto
= &elf_hppa_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
3097 /* Do PA ELF specific processing for symbols. Needed to find the
3098 value of $global$. */
3101 elf32_hppa_backend_symbol_processing (abfd
, sym
)
3105 /* Is this a definition of $global$? If so, keep it because it will be
3106 needed if any relocations are performed. */
3107 if (!strcmp (sym
->name
, "$global$")
3108 && sym
->section
!= &bfd_und_section
)
3110 global_symbol
= sym
;
3114 /* Do some PA ELF specific work after reading in the symbol table.
3115 In particular attach the argument relocation from the
3116 symbol extension section to the appropriate symbols. */
3118 elf32_hppa_backend_symbol_table_processing (abfd
, esyms
,symcnt
)
3120 elf_symbol_type
*esyms
;
3123 Elf32_Internal_Shdr
*symextn_hdr
=
3124 bfd_elf_find_section (abfd
, SYMEXTN_SECTION_NAME
);
3125 int i
, current_sym_idx
= 0;
3127 /* If no symbol extension existed, then all symbol extension information
3128 is assumed to be zero. */
3129 if (symextn_hdr
== NULL
)
3131 for (i
= 0; i
< symcnt
; i
++)
3132 esyms
[i
].tc_data
.hppa_arg_reloc
= 0;
3136 /* Allocate a buffer of the appropriate size for the symextn section. */
3137 symextn_hdr
->contents
= bfd_zalloc(abfd
,symextn_hdr
->sh_size
);
3138 if (!symextn_hdr
->contents
)
3140 bfd_set_error (bfd_error_no_memory
);
3143 symextn_hdr
->size
= symextn_hdr
->sh_size
;
3145 /* Read in the symextn section. */
3146 if (bfd_seek (abfd
, symextn_hdr
->sh_offset
, SEEK_SET
) == -1)
3148 if (bfd_read ((PTR
) symextn_hdr
->contents
, 1, symextn_hdr
->size
, abfd
)
3149 != symextn_hdr
->size
)
3152 /* Parse entries in the symbol extension section, updating the symtab
3154 for (i
= 0; i
< symextn_hdr
->size
/ sizeof(symext_entryS
); i
++)
3156 symext_entryS
*seP
= ((symext_entryS
*)symextn_hdr
->contents
) + i
;
3157 int se_value
= ELF32_HPPA_SX_VAL (*seP
);
3158 int se_type
= ELF32_HPPA_SX_TYPE (*seP
);
3165 case HPPA_SXT_SYMNDX
:
3166 if (se_value
>= symcnt
)
3168 bfd_set_error (bfd_error_bad_value
);
3171 current_sym_idx
= se_value
- 1;
3174 case HPPA_SXT_ARG_RELOC
:
3175 esyms
[current_sym_idx
].tc_data
.hppa_arg_reloc
= se_value
;
3179 bfd_set_error (bfd_error_bad_value
);
3186 /* Perform on PA ELF specific processing once a section has been
3187 read in. In particular keep the symbol indexes correct for
3188 the symbol extension information. */
3191 elf32_hppa_backend_section_processing (abfd
, secthdr
)
3193 Elf32_Internal_Shdr
*secthdr
;
3197 if (secthdr
->sh_type
== SHT_HPPA_SYMEXTN
)
3199 for (i
= 0; i
< secthdr
->size
/ sizeof (symext_entryS
); i
++)
3201 symext_entryS
*seP
= ((symext_entryS
*)secthdr
->contents
) + i
;
3202 int se_value
= ELF32_HPPA_SX_VAL (*seP
);
3203 int se_type
= ELF32_HPPA_SX_TYPE (*seP
);
3210 case HPPA_SXT_SYMNDX
:
3211 for (j
= 0; j
< abfd
->symcount
; j
++)
3213 /* Locate the map entry for this symbol and modify the
3214 symbol extension section symbol index entry to reflect
3215 the new symbol table index. */
3216 for (k
= 0; k
< elf32_hppa_symextn_map_size
; k
++)
3218 if (elf32_hppa_symextn_map
[k
].old_index
== se_value
3219 && elf32_hppa_symextn_map
[k
].bfd
3220 == abfd
->outsymbols
[j
]->the_bfd
3221 && elf32_hppa_symextn_map
[k
].sym
3222 == abfd
->outsymbols
[j
])
3225 ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX
, j
),
3232 case HPPA_SXT_ARG_RELOC
:
3236 bfd_set_error (bfd_error_bad_value
);
3244 /* What does this really do? Just determine if there is an appropriate
3245 mapping from ELF section headers to backend sections? More symbol
3246 extension braindamage. */
3249 elf32_hppa_backend_section_from_shdr (abfd
, hdr
, name
)
3251 Elf32_Internal_Shdr
*hdr
;
3256 if (hdr
->sh_type
== SHT_HPPA_SYMEXTN
)
3258 BFD_ASSERT (strcmp (name
, ".hppa_symextn") == 0);
3260 /* Bits that get saved. This one is real. */
3263 newsect
= bfd_make_section (abfd
, name
);
3264 if (newsect
!= NULL
)
3266 newsect
->vma
= hdr
->sh_addr
;
3267 newsect
->_raw_size
= hdr
->sh_size
;
3268 newsect
->filepos
= hdr
->sh_offset
;
3269 newsect
->flags
|= SEC_HAS_CONTENTS
;
3270 newsect
->alignment_power
= hdr
->sh_addralign
;
3272 if (hdr
->sh_flags
& SHF_ALLOC
)
3274 newsect
->flags
|= SEC_ALLOC
;
3275 newsect
->flags
|= SEC_LOAD
;
3278 if (!(hdr
->sh_flags
& SHF_WRITE
))
3279 newsect
->flags
|= SEC_READONLY
;
3281 if (hdr
->sh_flags
& SHF_EXECINSTR
)
3282 newsect
->flags
|= SEC_CODE
;
3284 newsect
->flags
|= SEC_DATA
;
3286 hdr
->rawdata
= (void *) newsect
;
3294 /* Return true if the given section is a fake section. */
3297 elf32_hppa_backend_fake_sections (abfd
, secthdr
, asect
)
3299 Elf_Internal_Shdr
*secthdr
;
3303 if (strcmp(asect
->name
, ".hppa_symextn") == 0)
3305 secthdr
->sh_type
= SHT_HPPA_SYMEXTN
;
3306 secthdr
->sh_flags
= 0;
3307 secthdr
->sh_info
= elf_section_data(asect
)->rel_hdr
.sh_link
;
3308 secthdr
->sh_link
= elf_onesymtab(abfd
);
3312 if (!strcmp (asect
->name
, ".hppa_unwind"))
3314 secthdr
->sh_type
= SHT_PROGBITS
;
3315 /* Unwind descriptors are not part of the program memory image. */
3316 secthdr
->sh_flags
= 0;
3317 secthdr
->sh_info
= 0;
3318 secthdr
->sh_link
= 0;
3319 secthdr
->sh_entsize
= 16;
3323 /* @@ Should this be CPU specific?? KR */
3324 if (!strcmp (asect
->name
, ".stabstr"))
3326 secthdr
->sh_type
= SHT_STRTAB
;
3327 secthdr
->sh_flags
= 0;
3328 secthdr
->sh_info
= 0;
3329 secthdr
->sh_link
= 0;
3330 secthdr
->sh_entsize
= 0;
3337 /* Return true if there is a mapping from bfd section into a
3341 elf32_hppa_backend_section_from_bfd_section (abfd
, hdr
, asect
, ignored
)
3343 Elf32_Internal_Shdr
*hdr
;
3347 if (hdr
->sh_type
== SHT_HPPA_SYMEXTN
)
3351 if (((struct sec
*) (hdr
->rawdata
)) == asect
)
3353 BFD_ASSERT (strcmp (asect
->name
, ".hppa_symextn") == 0);
3358 else if (hdr
->sh_type
== SHT_STRTAB
)
3362 if (((struct sec
*) (hdr
->rawdata
)) == asect
)
3364 BFD_ASSERT (strcmp (asect
->name
, ".stabstr") == 0);
3373 #define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
3374 #define elf_backend_section_from_bfd_section elf32_hppa_backend_section_from_bfd_section
3376 #define elf_backend_symbol_processing elf32_hppa_backend_symbol_processing
3377 #define elf_backend_symbol_table_processing elf32_hppa_backend_symbol_table_processing
3379 #define bfd_generic_get_section_contents hppa_elf_get_section_contents
3380 #define bfd_elf32_set_section_contents hppa_elf_set_section_contents
3381 #define bfd_elf32_bfd_is_local_label hppa_elf_is_local_label
3383 #define elf_backend_section_processing elf32_hppa_backend_section_processing
3385 #define elf_backend_section_from_shdr elf32_hppa_backend_section_from_shdr
3386 #define elf_backend_fake_sections elf32_hppa_backend_fake_sections
3388 #define TARGET_BIG_SYM bfd_elf32_hppa_vec
3389 #define TARGET_BIG_NAME "elf32-hppa"
3390 #define ELF_ARCH bfd_arch_hppa
3391 #define ELF_MACHINE_CODE EM_HPPA
3392 #define ELF_MAXPAGESIZE 0x1000
3394 #include "elf32-target.h"