]>
Commit | Line | Data |
---|---|---|
4c85cbfa | 1 | /* BFD back-end for HP PA-RISC ELF files. |
f4bd7a8f | 2 | Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc. |
4c85cbfa KR |
3 | |
4 | Written by | |
e8f2240a | 5 | |
4c85cbfa KR |
6 | Center for Software Science |
7 | Department of Computer Science | |
8 | University of Utah | |
9 | ||
10 | This file is part of BFD, the Binary File Descriptor library. | |
11 | ||
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. | |
16 | ||
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. | |
21 | ||
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. */ | |
25 | ||
26 | #include "bfd.h" | |
27 | #include "sysdep.h" | |
28 | #include "libbfd.h" | |
29 | #include "obstack.h" | |
4991ebb9 | 30 | #include "bfdlink.h" |
4c85cbfa KR |
31 | #include "libelf.h" |
32 | ||
f5bfdacd JL |
33 | /* Note there isn't much error handling code in here yet. Unexpected |
34 | conditions are handled by just calling abort. FIXME damnit! */ | |
35 | ||
4c85cbfa KR |
36 | /* ELF32/HPPA relocation support |
37 | ||
38 | This file contains ELF32/HPPA relocation support as specified | |
39 | in the Stratus FTX/Golf Object File Format (SED-1762) dated | |
f5bfdacd | 40 | November 19, 1992. */ |
4c85cbfa | 41 | |
4c85cbfa | 42 | #include "elf32-hppa.h" |
e8f2240a | 43 | #include "aout/aout64.h" |
d9ad93bc | 44 | #include "hppa_stubs.h" |
4c85cbfa | 45 | |
e08b9ad7 JL |
46 | /* The basic stub types supported. If/when shared libraries are |
47 | implemented some form of IMPORT and EXPORT stubs will be needed. */ | |
48 | typedef enum | |
49 | { | |
50 | HPPA_STUB_ILLEGAL, | |
51 | HPPA_STUB_ARG_RELOC, | |
52 | HPPA_STUB_LONG_CALL, | |
53 | } hppa_stub_type; | |
54 | ||
55 | /* This is a list of all the stubs for a particular BFD. */ | |
56 | ||
57 | typedef struct elf32_hppa_stub_name_list_struct | |
58 | { | |
59 | /* The symbol associated with this stub. */ | |
60 | asymbol *sym; | |
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). */ | |
64 | int *stub_secp; | |
65 | /* Size of this stub? (in what units? FIXME). */ | |
66 | unsigned size; | |
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; | |
70 | ||
71 | /* This is a linked list in which each entry describes all the | |
72 | linker stubs for a particular bfd. */ | |
73 | ||
74 | typedef struct elf32_hppa_stub_description_struct | |
75 | { | |
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. */ | |
80 | bfd *this_bfd; | |
81 | /* FIXME: The stub section for this group of stubs? Is | |
82 | this redundant with stub_listP->sym->section? */ | |
83 | asection *stub_sec; | |
84 | /* FIXME: what the hell is this? */ | |
85 | unsigned relocs_allocated_cnt; | |
86 | /* The current real size of the stubs (in bytes?). */ | |
87 | unsigned real_size; | |
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. */ | |
91 | int *stub_secp; | |
92 | /* Pointer to the beginning of the stubs. FIXME: Why an int * | |
93 | above and a char * here? */ | |
94 | char *stub_contents; | |
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; | |
100 | ||
101 | /* FIXME. */ | |
102 | #define ARGUMENTS 0 | |
103 | #define RETURN_VALUE 1 | |
104 | ||
105 | /* The various argument relocations that may be performed. | |
106 | Note GRX,GRY really means ARGX,ARGY. */ | |
107 | typedef enum | |
108 | { | |
109 | /* No relocation. */ | |
110 | NO_ARG_RELOC, | |
111 | /* Relocate 32 bits from general to FP register. */ | |
112 | R_TO_FR, | |
113 | /* Relocate 64 bits from arg0,arg1 to FParg1. */ | |
114 | R01_TO_FR, | |
115 | /* Relocate 64 bits from arg2,arg3 to FParg3. */ | |
116 | R23_TO_FR, | |
117 | /* Relocate 32 bits from FP to general register. */ | |
118 | FR_TO_R, | |
119 | /* Relocate 64 bits from FParg1 to arg0,arg1. */ | |
120 | FR_TO_R01, | |
121 | /* Relocate 64 bits from FParg3 to arg2,arg3. */ | |
122 | FR_TO_R23, | |
123 | /* Death. */ | |
124 | ARG_RELOC_ERR, | |
125 | } arg_reloc_type; | |
126 | ||
127 | /* Where (what register type) is an argument comming from? */ | |
128 | typedef enum | |
129 | { | |
130 | /* Not in a register. */ | |
131 | AR_NO, | |
132 | /* In a general argument register. */ | |
133 | AR_GR, | |
134 | /* In right half of a FP argument register. */ | |
135 | AR_FR, | |
136 | /* In upper (left) half of a FP argument register. */ | |
137 | AR_FU, | |
138 | /* In general argument register pair 0 (arg0, arg1). */ | |
139 | AR_DBL01, | |
140 | /* In general argument register pair 1 (arg2, arg3). */ | |
141 | AR_DBL23, | |
142 | } arg_location; | |
143 | ||
144 | /* What is being relocated (eg which argument or the return value). */ | |
145 | typedef enum | |
146 | { | |
147 | ARG0, ARG1, ARG2, ARG3, RETVAL, | |
148 | } arg_reloc_location; | |
149 | ||
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] = | |
155 | { | |
f3b477be | 156 | {NO_ARG_RELOC, NO_ARG_RELOC, NO_ARG_RELOC, NO_ARG_RELOC, |
e08b9ad7 JL |
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}, | |
168 | }; | |
169 | ||
170 | /* Likewise for the return value. */ | |
171 | static CONST arg_reloc_type retval_mismatches[6][6] = | |
172 | { | |
f3b477be | 173 | {NO_ARG_RELOC, NO_ARG_RELOC, NO_ARG_RELOC, NO_ARG_RELOC, |
e08b9ad7 JL |
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}, | |
185 | }; | |
186 | ||
187 | /* Used for index mapping in symbol-extension sections. */ | |
188 | struct elf32_hppa_symextn_map_struct | |
189 | { | |
190 | int old_index; | |
191 | bfd *bfd; | |
192 | asymbol *sym; | |
193 | int new_index; | |
194 | }; | |
4c85cbfa | 195 | |
4991ebb9 ILT |
196 | static bfd_reloc_status_type hppa_elf_reloc |
197 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
4c85cbfa | 198 | |
f5bfdacd JL |
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)); | |
202 | ||
203 | static void hppa_elf_relocate_unwind_table | |
204 | PARAMS ((bfd *, PTR, unsigned long, long, long, | |
205 | unsigned long, unsigned long)); | |
206 | ||
207 | static long get_symbol_value PARAMS ((asymbol *)); | |
e08b9ad7 | 208 | |
f5bfdacd JL |
209 | static bfd_reloc_status_type hppa_elf_reloc |
210 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd*, char **)); | |
211 | ||
212 | static CONST reloc_howto_type * elf_hppa_reloc_type_lookup | |
7ed5e970 | 213 | PARAMS ((bfd *, bfd_reloc_code_real_type)); |
f5bfdacd | 214 | |
e08b9ad7 JL |
215 | static symext_entryS elf32_hppa_get_sym_extn PARAMS ((bfd *, asymbol *, int)); |
216 | ||
217 | static elf32_hppa_stub_description * find_stubs PARAMS ((bfd *, asection *)); | |
218 | ||
219 | static elf32_hppa_stub_description * new_stub | |
220 | PARAMS ((bfd *, asection *, struct bfd_link_info *)); | |
221 | ||
222 | static arg_reloc_type type_of_mismatch PARAMS ((int, int, int)); | |
223 | ||
224 | static elf32_hppa_stub_name_list * find_stub_by_name | |
225 | PARAMS ((bfd *, asection *, char *)); | |
226 | ||
227 | static elf32_hppa_stub_name_list * add_stub_by_name | |
228 | PARAMS ((bfd *, asection *, asymbol *, struct bfd_link_info *)); | |
229 | ||
230 | static void hppa_elf_stub_finish PARAMS ((bfd *)); | |
231 | ||
232 | static void hppa_elf_stub_reloc | |
6e58a4e5 | 233 | PARAMS ((elf32_hppa_stub_description *, bfd *, asymbol **, int, |
e08b9ad7 JL |
234 | elf32_hppa_reloc_type)); |
235 | ||
236 | static int hppa_elf_arg_reloc_needed_p | |
237 | PARAMS ((bfd *, arelent *, arg_reloc_type [5], symext_entryS)); | |
238 | ||
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)); | |
242 | ||
243 | static void hppa_elf_create_stub_sec | |
244 | PARAMS ((bfd *, bfd *, asection **, struct bfd_link_info *)); | |
245 | ||
246 | static int hppa_elf_long_branch_needed_p | |
247 | PARAMS ((bfd *, asection *, arelent *, asymbol *, unsigned)); | |
248 | ||
249 | static boolean hppa_elf_set_section_contents | |
250 | PARAMS ((bfd *, sec_ptr, PTR, file_ptr, bfd_size_type)); | |
251 | ||
252 | static void elf_info_to_howto | |
253 | PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *)); | |
254 | ||
255 | static void elf32_hppa_backend_symbol_processing PARAMS ((bfd *, asymbol *)); | |
256 | ||
257 | static boolean elf32_hppa_backend_section_processing | |
258 | PARAMS ((bfd *, Elf32_Internal_Shdr *)); | |
259 | ||
260 | static boolean elf32_hppa_backend_symbol_table_processing | |
261 | PARAMS ((bfd *, elf_symbol_type *, int)); | |
262 | ||
263 | static boolean elf32_hppa_backend_section_from_shdr | |
264 | PARAMS ((bfd *, Elf32_Internal_Shdr *, char *)); | |
265 | ||
266 | static boolean elf32_hppa_backend_fake_sections | |
267 | PARAMS ((bfd *, Elf_Internal_Shdr *, asection *)); | |
268 | ||
269 | static boolean elf32_hppa_backend_section_from_bfd_section | |
270 | PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *, int *)); | |
271 | ||
7ed5e970 | 272 | static boolean hppa_elf_is_local_label PARAMS ((bfd *, asymbol *)); |
25057836 | 273 | |
e08b9ad7 JL |
274 | /* ELF/PA relocation howto entries. */ |
275 | ||
d9ad93bc | 276 | static reloc_howto_type elf_hppa_howto_table[ELF_HOWTO_TABLE_SIZE] = |
4c85cbfa | 277 | { |
d9ad93bc KR |
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"}, | |
d9ad93bc KR |
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"}, | |
d9ad93bc KR |
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"}, | |
d9ad93bc KR |
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"}, | |
4861ac76 JL |
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"}, | |
4861ac76 JL |
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"}, | |
d9ad93bc KR |
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"}, | |
d9ad93bc KR |
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"}, | |
d9ad93bc KR |
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"}, | |
e8f2240a | 400 | }; |
4c85cbfa | 401 | |
d9ad93bc KR |
402 | static symext_chainS *symext_rootP; |
403 | static symext_chainS *symext_lastP; | |
7218bb04 | 404 | static boolean symext_chain_built; |
f5bfdacd JL |
405 | static long global_value; |
406 | static long GOT_value; | |
407 | static asymbol *global_symbol; | |
408 | static int global_sym_defined; | |
f5bfdacd JL |
409 | static symext_entryS *symextn_contents; |
410 | static unsigned int symextn_contents_real_size; | |
e08b9ad7 JL |
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; | |
415 | ||
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 | |
e8f2240a | 421 | |
f5bfdacd | 422 | /* Relocate the given INSN given the various input parameters. |
e8f2240a | 423 | |
f5bfdacd | 424 | FIXME: endianness and sizeof (long) issues abound here. */ |
4c85cbfa KR |
425 | |
426 | static unsigned long | |
f5bfdacd JL |
427 | hppa_elf_relocate_insn (abfd, input_sect, insn, address, sym_value, |
428 | r_addend, r_format, r_field, pcrel) | |
f4bd7a8f DM |
429 | bfd *abfd; |
430 | asection *input_sect; | |
431 | unsigned long insn; | |
432 | unsigned long address; | |
f4bd7a8f DM |
433 | long sym_value; |
434 | long r_addend; | |
f5bfdacd JL |
435 | unsigned long r_format; |
436 | unsigned long r_field; | |
437 | unsigned long pcrel; | |
4c85cbfa | 438 | { |
e8f2240a KR |
439 | unsigned char opcode = get_opcode (insn); |
440 | long constant_value; | |
441 | unsigned arg_reloc; | |
442 | ||
443 | switch (opcode) | |
444 | { | |
445 | case LDO: | |
446 | case LDB: | |
447 | case LDH: | |
448 | case LDW: | |
449 | case LDWM: | |
450 | case STB: | |
451 | case STH: | |
452 | case STW: | |
453 | case STWM: | |
f5bfdacd JL |
454 | case COMICLR: |
455 | case SUBI: | |
456 | case ADDIT: | |
457 | case ADDI: | |
458 | case LDIL: | |
459 | case ADDIL: | |
7218bb04 | 460 | constant_value = HPPA_R_CONSTANT (r_addend); |
e8f2240a KR |
461 | |
462 | if (pcrel) | |
463 | sym_value -= address; | |
e8f2240a | 464 | |
e8f2240a | 465 | sym_value = hppa_field_adjust (sym_value, constant_value, r_field); |
f5bfdacd | 466 | return hppa_rebuild_insn (abfd, insn, sym_value, r_format); |
e8f2240a KR |
467 | |
468 | case BL: | |
469 | case BE: | |
470 | case BLE: | |
7218bb04 | 471 | arg_reloc = HPPA_R_ARG_RELOC (r_addend); |
e8f2240a | 472 | |
e8f2240a KR |
473 | /* XXX computing constant_value is not needed??? */ |
474 | constant_value = assemble_17 ((insn & 0x001f0000) >> 16, | |
475 | (insn & 0x00001ffc) >> 2, | |
476 | insn & 1); | |
f5bfdacd | 477 | |
e8f2240a KR |
478 | constant_value = (constant_value << 15) >> 15; |
479 | if (pcrel) | |
480 | { | |
481 | sym_value -= | |
482 | address + input_sect->output_offset | |
483 | + input_sect->output_section->vma; | |
484 | sym_value = hppa_field_adjust (sym_value, -8, r_field); | |
485 | } | |
486 | else | |
487 | sym_value = hppa_field_adjust (sym_value, constant_value, r_field); | |
4c85cbfa | 488 | |
f5bfdacd | 489 | return hppa_rebuild_insn (abfd, insn, sym_value >> 2, r_format); |
4c85cbfa | 490 | |
e8f2240a KR |
491 | default: |
492 | if (opcode == 0) | |
493 | { | |
7218bb04 | 494 | constant_value = HPPA_R_CONSTANT (r_addend); |
e8f2240a | 495 | |
f5bfdacd JL |
496 | if (pcrel) |
497 | sym_value -= address; | |
498 | ||
e8f2240a KR |
499 | return hppa_field_adjust (sym_value, constant_value, r_field); |
500 | } | |
501 | else | |
f5bfdacd | 502 | abort (); |
e8f2240a | 503 | } |
4c85cbfa KR |
504 | } |
505 | ||
f5bfdacd JL |
506 | /* Relocate a single unwind entry, or an entire table of them. */ |
507 | ||
4c85cbfa | 508 | static void |
f5bfdacd JL |
509 | hppa_elf_relocate_unwind_table (abfd, data, address, sym_value, |
510 | r_addend, r_type, r_field) | |
f4bd7a8f | 511 | bfd *abfd; |
f4bd7a8f DM |
512 | PTR data; |
513 | unsigned long address; | |
f4bd7a8f DM |
514 | long sym_value; |
515 | long r_addend; | |
f5bfdacd JL |
516 | unsigned long r_type; |
517 | unsigned long r_field; | |
4c85cbfa | 518 | { |
f5bfdacd | 519 | bfd_byte *hit_data = address + (bfd_byte *) data; |
e8f2240a KR |
520 | long start_offset; |
521 | long end_offset; | |
522 | long relocated_value; | |
523 | int i; | |
524 | ||
e8f2240a KR |
525 | switch (r_type) |
526 | { | |
527 | case R_HPPA_UNWIND_ENTRY: | |
f5bfdacd JL |
528 | /* Need to relocate the first two 32bit fields in the unwind. They |
529 | correspond to a function's start and end address. */ | |
e8f2240a KR |
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); | |
533 | ||
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); | |
538 | break; | |
539 | ||
540 | case R_HPPA_UNWIND_ENTRIES: | |
f5bfdacd JL |
541 | /* Relocate a mass of unwind entires. The count is passed in r_addend |
542 | (who's braindamaged idea was this anyway? */ | |
e8f2240a KR |
543 | for (i = 0; i < r_addend; i++, hit_data += 3 * sizeof (unsigned long)) |
544 | { | |
d9ad93bc | 545 | unsigned int adjustment; |
f5bfdacd JL |
546 | /* Adjust the first 32bit field in the unwind entry. It's |
547 | the starting offset of a function. */ | |
e8f2240a | 548 | start_offset = bfd_get_32 (abfd, hit_data); |
e8f2240a | 549 | bfd_put_32 (abfd, sym_value, hit_data); |
d9ad93bc | 550 | adjustment = sym_value - start_offset; |
e8f2240a | 551 | |
f5bfdacd JL |
552 | /* Now adjust the second 32bit field, it's the ending offset |
553 | of a function. */ | |
e8f2240a | 554 | hit_data += sizeof (unsigned long); |
d9ad93bc KR |
555 | end_offset = adjustment + bfd_get_32 (abfd, hit_data); |
556 | bfd_put_32 (abfd, end_offset, hit_data); | |
e8f2240a | 557 | |
f5bfdacd JL |
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; | |
4c85cbfa | 562 | } |
e8f2240a KR |
563 | break; |
564 | ||
565 | default: | |
f5bfdacd | 566 | abort (); |
e8f2240a | 567 | } |
4c85cbfa KR |
568 | } |
569 | ||
f5bfdacd JL |
570 | /* Return the relocated value of the given symbol. */ |
571 | ||
e8f2240a KR |
572 | static long |
573 | get_symbol_value (symbol) | |
574 | asymbol *symbol; | |
575 | { | |
f5bfdacd JL |
576 | if (symbol == NULL |
577 | || symbol->section == &bfd_com_section) | |
578 | return 0; | |
e8f2240a | 579 | else |
f5bfdacd JL |
580 | return symbol->value + symbol->section->output_section->vma |
581 | + symbol->section->output_offset; | |
4c85cbfa KR |
582 | } |
583 | ||
f5bfdacd | 584 | /* Return one (or more) BFD relocations which implement the base |
e08b9ad7 | 585 | relocation with modifications based on format and field. */ |
4c85cbfa | 586 | |
e8f2240a KR |
587 | elf32_hppa_reloc_type ** |
588 | hppa_elf_gen_reloc_type (abfd, base_type, format, field) | |
589 | bfd *abfd; | |
590 | elf32_hppa_reloc_type base_type; | |
591 | int format; | |
592 | int field; | |
4c85cbfa | 593 | { |
e8f2240a KR |
594 | elf32_hppa_reloc_type *finaltype; |
595 | elf32_hppa_reloc_type **final_types; | |
e8f2240a | 596 | |
f5bfdacd JL |
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); | |
9783e04a | 600 | BFD_ASSERT (final_types != 0); /* FIXME */ |
e8f2240a | 601 | |
f5bfdacd JL |
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)); | |
9783e04a | 605 | BFD_ASSERT (finaltype != 0); /* FIXME */ |
e8f2240a | 606 | |
f5bfdacd | 607 | /* Some reasonable defaults. */ |
e8f2240a KR |
608 | final_types[0] = finaltype; |
609 | final_types[1] = NULL; | |
610 | ||
611 | #define final_type finaltype[0] | |
612 | ||
613 | final_type = base_type; | |
614 | ||
f5bfdacd JL |
615 | /* Just a tangle of nested switch statements to deal with the braindamage |
616 | that a different field selector means a completely different relocation | |
617 | for PA ELF. */ | |
e8f2240a KR |
618 | switch (base_type) |
619 | { | |
620 | case R_HPPA: | |
621 | switch (format) | |
622 | { | |
623 | case 11: | |
624 | switch (field) | |
625 | { | |
626 | case e_fsel: | |
627 | final_type = R_HPPA_11; | |
628 | break; | |
629 | case e_rsel: | |
630 | final_type = R_HPPA_R11; | |
631 | break; | |
632 | case e_rssel: | |
633 | final_type = R_HPPA_RS11; | |
634 | break; | |
635 | case e_rdsel: | |
636 | final_type = R_HPPA_RD11; | |
637 | break; | |
e8f2240a KR |
638 | case e_psel: |
639 | final_type = R_HPPA_PLABEL_11; | |
640 | break; | |
641 | case e_rpsel: | |
642 | final_type = R_HPPA_PLABEL_R11; | |
643 | break; | |
e8f2240a | 644 | case e_tsel: |
a36b6f1d JL |
645 | final_type = R_HPPA_DLT_11; |
646 | break; | |
e8f2240a | 647 | case e_rtsel: |
a36b6f1d JL |
648 | final_type = R_HPPA_DLT_R11; |
649 | break; | |
e8f2240a | 650 | default: |
f5bfdacd | 651 | abort (); |
e8f2240a KR |
652 | break; |
653 | } | |
654 | break; | |
f5bfdacd | 655 | |
e8f2240a KR |
656 | case 14: |
657 | switch (field) | |
658 | { | |
659 | case e_rsel: | |
660 | final_type = R_HPPA_R14; | |
661 | break; | |
662 | case e_rssel: | |
663 | final_type = R_HPPA_RS14; | |
664 | break; | |
665 | case e_rdsel: | |
666 | final_type = R_HPPA_RD14; | |
667 | break; | |
668 | case e_rrsel: | |
669 | final_type = R_HPPA_RR14; | |
670 | break; | |
e8f2240a KR |
671 | case e_psel: |
672 | final_type = R_HPPA_PLABEL_14; | |
673 | break; | |
674 | case e_rpsel: | |
675 | final_type = R_HPPA_PLABEL_R14; | |
676 | break; | |
e8f2240a | 677 | case e_tsel: |
a36b6f1d JL |
678 | final_type = R_HPPA_DLT_14; |
679 | break; | |
e8f2240a | 680 | case e_rtsel: |
a36b6f1d JL |
681 | final_type = R_HPPA_DLT_R14; |
682 | break; | |
e8f2240a | 683 | default: |
f5bfdacd | 684 | abort (); |
e8f2240a KR |
685 | break; |
686 | } | |
687 | break; | |
f5bfdacd | 688 | |
e8f2240a KR |
689 | case 17: |
690 | switch (field) | |
691 | { | |
692 | case e_fsel: | |
693 | final_type = R_HPPA_17; | |
694 | break; | |
695 | case e_rsel: | |
696 | final_type = R_HPPA_R17; | |
697 | break; | |
698 | case e_rssel: | |
699 | final_type = R_HPPA_RS17; | |
700 | break; | |
701 | case e_rdsel: | |
702 | final_type = R_HPPA_RD17; | |
703 | break; | |
704 | case e_rrsel: | |
705 | final_type = R_HPPA_RR17; | |
706 | break; | |
e8f2240a | 707 | default: |
f5bfdacd | 708 | abort (); |
e8f2240a KR |
709 | break; |
710 | } | |
711 | break; | |
f5bfdacd | 712 | |
e8f2240a KR |
713 | case 21: |
714 | switch (field) | |
715 | { | |
716 | case e_lsel: | |
717 | final_type = R_HPPA_L21; | |
718 | break; | |
719 | case e_lssel: | |
720 | final_type = R_HPPA_LS21; | |
721 | break; | |
722 | case e_ldsel: | |
723 | final_type = R_HPPA_LD21; | |
724 | break; | |
725 | case e_lrsel: | |
726 | final_type = R_HPPA_LR21; | |
727 | break; | |
728 | case e_lpsel: | |
729 | final_type = R_HPPA_PLABEL_L21; | |
730 | break; | |
a36b6f1d JL |
731 | case e_ltsel: |
732 | final_type = R_HPPA_PLABEL_L21; | |
733 | break; | |
e8f2240a | 734 | default: |
f5bfdacd | 735 | abort (); |
e8f2240a KR |
736 | break; |
737 | } | |
738 | break; | |
f5bfdacd | 739 | |
e8f2240a KR |
740 | case 32: |
741 | switch (field) | |
742 | { | |
743 | case e_fsel: | |
744 | final_type = R_HPPA_32; | |
745 | break; | |
746 | case e_psel: | |
747 | final_type = R_HPPA_PLABEL_32; | |
748 | break; | |
a36b6f1d | 749 | case e_tsel: |
7a60ed8c | 750 | final_type = R_HPPA_DLT_32; |
a36b6f1d | 751 | break; |
e8f2240a | 752 | default: |
f5bfdacd | 753 | abort (); |
e8f2240a KR |
754 | break; |
755 | } | |
756 | break; | |
f5bfdacd | 757 | |
e8f2240a | 758 | default: |
f5bfdacd | 759 | abort (); |
e8f2240a KR |
760 | break; |
761 | } | |
762 | break; | |
f5bfdacd JL |
763 | |
764 | ||
e8f2240a KR |
765 | case R_HPPA_GOTOFF: |
766 | switch (format) | |
767 | { | |
768 | case 11: | |
769 | switch (field) | |
770 | { | |
771 | case e_rsel: | |
772 | final_type = R_HPPA_GOTOFF_R11; | |
773 | break; | |
774 | case e_rssel: | |
775 | final_type = R_HPPA_GOTOFF_RS11; | |
776 | break; | |
777 | case e_rdsel: | |
778 | final_type = R_HPPA_GOTOFF_RD11; | |
779 | break; | |
780 | case e_fsel: | |
781 | final_type = R_HPPA_GOTOFF_11; | |
782 | break; | |
e8f2240a | 783 | default: |
f5bfdacd | 784 | abort (); |
e8f2240a KR |
785 | break; |
786 | } | |
787 | break; | |
f5bfdacd | 788 | |
e8f2240a KR |
789 | case 14: |
790 | switch (field) | |
791 | { | |
792 | case e_rsel: | |
793 | final_type = R_HPPA_GOTOFF_R14; | |
794 | break; | |
795 | case e_rssel: | |
796 | final_type = R_HPPA_GOTOFF_RS14; | |
797 | break; | |
798 | case e_rdsel: | |
799 | final_type = R_HPPA_GOTOFF_RD14; | |
800 | break; | |
801 | case e_rrsel: | |
802 | final_type = R_HPPA_GOTOFF_RR14; | |
803 | break; | |
804 | case e_fsel: | |
805 | final_type = R_HPPA_GOTOFF_14; | |
806 | break; | |
e8f2240a | 807 | default: |
f5bfdacd | 808 | abort (); |
e8f2240a KR |
809 | break; |
810 | } | |
811 | break; | |
f5bfdacd | 812 | |
e8f2240a KR |
813 | case 21: |
814 | switch (field) | |
815 | { | |
816 | case e_lsel: | |
817 | final_type = R_HPPA_GOTOFF_L21; | |
818 | break; | |
819 | case e_lssel: | |
820 | final_type = R_HPPA_GOTOFF_LS21; | |
821 | break; | |
822 | case e_ldsel: | |
823 | final_type = R_HPPA_GOTOFF_LD21; | |
824 | break; | |
825 | case e_lrsel: | |
826 | final_type = R_HPPA_GOTOFF_LR21; | |
827 | break; | |
e8f2240a | 828 | default: |
f5bfdacd | 829 | abort (); |
e8f2240a KR |
830 | break; |
831 | } | |
832 | break; | |
f5bfdacd | 833 | |
e8f2240a | 834 | default: |
f5bfdacd | 835 | abort (); |
e8f2240a KR |
836 | break; |
837 | } | |
838 | break; | |
f5bfdacd JL |
839 | |
840 | ||
e8f2240a KR |
841 | case R_HPPA_PCREL_CALL: |
842 | switch (format) | |
843 | { | |
844 | case 11: | |
845 | switch (field) | |
846 | { | |
847 | case e_rsel: | |
848 | final_type = R_HPPA_PCREL_CALL_R11; | |
849 | break; | |
850 | case e_rssel: | |
851 | final_type = R_HPPA_PCREL_CALL_RS11; | |
852 | break; | |
853 | case e_rdsel: | |
854 | final_type = R_HPPA_PCREL_CALL_RD11; | |
855 | break; | |
856 | case e_fsel: | |
857 | final_type = R_HPPA_PCREL_CALL_11; | |
858 | break; | |
e8f2240a | 859 | default: |
f5bfdacd | 860 | abort (); |
e8f2240a KR |
861 | break; |
862 | } | |
863 | break; | |
f5bfdacd | 864 | |
e8f2240a KR |
865 | case 14: |
866 | switch (field) | |
867 | { | |
868 | case e_rsel: | |
869 | final_type = R_HPPA_PCREL_CALL_R14; | |
870 | break; | |
871 | case e_rssel: | |
872 | final_type = R_HPPA_PCREL_CALL_RS14; | |
873 | break; | |
874 | case e_rdsel: | |
875 | final_type = R_HPPA_PCREL_CALL_RD14; | |
876 | break; | |
877 | case e_rrsel: | |
878 | final_type = R_HPPA_PCREL_CALL_RR14; | |
879 | break; | |
880 | case e_fsel: | |
881 | final_type = R_HPPA_PCREL_CALL_14; | |
882 | break; | |
e8f2240a | 883 | default: |
f5bfdacd | 884 | abort (); |
e8f2240a KR |
885 | break; |
886 | } | |
887 | break; | |
f5bfdacd | 888 | |
e8f2240a KR |
889 | case 17: |
890 | switch (field) | |
891 | { | |
892 | case e_rsel: | |
893 | final_type = R_HPPA_PCREL_CALL_R17; | |
894 | break; | |
895 | case e_rssel: | |
896 | final_type = R_HPPA_PCREL_CALL_RS17; | |
897 | break; | |
898 | case e_rdsel: | |
899 | final_type = R_HPPA_PCREL_CALL_RD17; | |
900 | break; | |
901 | case e_rrsel: | |
902 | final_type = R_HPPA_PCREL_CALL_RR17; | |
903 | break; | |
904 | case e_fsel: | |
905 | final_type = R_HPPA_PCREL_CALL_17; | |
906 | break; | |
e8f2240a | 907 | default: |
f5bfdacd | 908 | abort (); |
e8f2240a KR |
909 | break; |
910 | } | |
911 | break; | |
f5bfdacd | 912 | |
e8f2240a KR |
913 | case 21: |
914 | switch (field) | |
915 | { | |
916 | case e_lsel: | |
917 | final_type = R_HPPA_PCREL_CALL_L21; | |
918 | break; | |
919 | case e_lssel: | |
920 | final_type = R_HPPA_PCREL_CALL_LS21; | |
921 | break; | |
922 | case e_ldsel: | |
923 | final_type = R_HPPA_PCREL_CALL_LD21; | |
924 | break; | |
925 | case e_lrsel: | |
926 | final_type = R_HPPA_PCREL_CALL_LR21; | |
927 | break; | |
e8f2240a | 928 | default: |
f5bfdacd | 929 | abort (); |
e8f2240a KR |
930 | break; |
931 | } | |
932 | break; | |
f5bfdacd | 933 | |
e8f2240a | 934 | default: |
f5bfdacd | 935 | abort (); |
e8f2240a KR |
936 | break; |
937 | } | |
938 | break; | |
f5bfdacd JL |
939 | |
940 | ||
e8f2240a KR |
941 | case R_HPPA_PLABEL: |
942 | switch (format) | |
943 | { | |
944 | case 11: | |
945 | switch (field) | |
946 | { | |
947 | case e_fsel: | |
948 | final_type = R_HPPA_PLABEL_11; | |
949 | break; | |
950 | case e_rsel: | |
951 | final_type = R_HPPA_PLABEL_R11; | |
952 | break; | |
953 | default: | |
f5bfdacd | 954 | abort (); |
e8f2240a KR |
955 | break; |
956 | } | |
957 | break; | |
f5bfdacd | 958 | |
e8f2240a KR |
959 | case 14: |
960 | switch (field) | |
961 | { | |
962 | case e_fsel: | |
963 | final_type = R_HPPA_PLABEL_14; | |
964 | break; | |
965 | case e_rsel: | |
966 | final_type = R_HPPA_PLABEL_R14; | |
967 | break; | |
968 | default: | |
f5bfdacd | 969 | abort (); |
e8f2240a KR |
970 | break; |
971 | } | |
972 | break; | |
f5bfdacd | 973 | |
e8f2240a KR |
974 | case 21: |
975 | switch (field) | |
976 | { | |
977 | case e_lsel: | |
978 | final_type = R_HPPA_PLABEL_L21; | |
979 | break; | |
980 | default: | |
f5bfdacd | 981 | abort (); |
e8f2240a KR |
982 | break; |
983 | } | |
984 | break; | |
f5bfdacd | 985 | |
e8f2240a KR |
986 | case 32: |
987 | switch (field) | |
988 | { | |
989 | case e_fsel: | |
990 | final_type = R_HPPA_PLABEL_32; | |
991 | break; | |
992 | default: | |
f5bfdacd | 993 | abort (); |
e8f2240a KR |
994 | break; |
995 | } | |
996 | break; | |
f5bfdacd | 997 | |
e8f2240a | 998 | default: |
f5bfdacd | 999 | abort (); |
e8f2240a KR |
1000 | break; |
1001 | } | |
f5bfdacd JL |
1002 | |
1003 | ||
e8f2240a KR |
1004 | case R_HPPA_ABS_CALL: |
1005 | switch (format) | |
1006 | { | |
1007 | case 11: | |
1008 | switch (field) | |
1009 | { | |
1010 | case e_rsel: | |
1011 | final_type = R_HPPA_ABS_CALL_R11; | |
1012 | break; | |
1013 | case e_rssel: | |
1014 | final_type = R_HPPA_ABS_CALL_RS11; | |
1015 | break; | |
1016 | case e_rdsel: | |
1017 | final_type = R_HPPA_ABS_CALL_RD11; | |
1018 | break; | |
1019 | case e_fsel: | |
1020 | final_type = R_HPPA_ABS_CALL_11; | |
1021 | break; | |
4c85cbfa | 1022 | default: |
f5bfdacd | 1023 | abort (); |
e8f2240a KR |
1024 | break; |
1025 | } | |
1026 | break; | |
f5bfdacd | 1027 | |
e8f2240a KR |
1028 | case 14: |
1029 | switch (field) | |
1030 | { | |
1031 | case e_rsel: | |
1032 | final_type = R_HPPA_ABS_CALL_R14; | |
1033 | break; | |
1034 | case e_rssel: | |
1035 | final_type = R_HPPA_ABS_CALL_RS14; | |
1036 | break; | |
1037 | case e_rdsel: | |
1038 | final_type = R_HPPA_ABS_CALL_RD14; | |
1039 | break; | |
1040 | case e_rrsel: | |
1041 | final_type = R_HPPA_ABS_CALL_RR14; | |
1042 | break; | |
1043 | case e_fsel: | |
1044 | final_type = R_HPPA_ABS_CALL_14; | |
1045 | break; | |
e8f2240a | 1046 | default: |
f5bfdacd | 1047 | abort (); |
e8f2240a KR |
1048 | break; |
1049 | } | |
1050 | break; | |
f5bfdacd | 1051 | |
e8f2240a KR |
1052 | case 17: |
1053 | switch (field) | |
1054 | { | |
1055 | case e_rsel: | |
1056 | final_type = R_HPPA_ABS_CALL_R17; | |
1057 | break; | |
1058 | case e_rssel: | |
1059 | final_type = R_HPPA_ABS_CALL_RS17; | |
1060 | break; | |
1061 | case e_rdsel: | |
1062 | final_type = R_HPPA_ABS_CALL_RD17; | |
1063 | break; | |
1064 | case e_rrsel: | |
1065 | final_type = R_HPPA_ABS_CALL_RR17; | |
1066 | break; | |
1067 | case e_fsel: | |
1068 | final_type = R_HPPA_ABS_CALL_17; | |
1069 | break; | |
e8f2240a | 1070 | default: |
f5bfdacd | 1071 | abort (); |
e8f2240a KR |
1072 | break; |
1073 | } | |
1074 | break; | |
f5bfdacd | 1075 | |
e8f2240a KR |
1076 | case 21: |
1077 | switch (field) | |
1078 | { | |
1079 | case e_lsel: | |
1080 | final_type = R_HPPA_ABS_CALL_L21; | |
1081 | break; | |
1082 | case e_lssel: | |
1083 | final_type = R_HPPA_ABS_CALL_LS21; | |
1084 | break; | |
1085 | case e_ldsel: | |
1086 | final_type = R_HPPA_ABS_CALL_LD21; | |
1087 | break; | |
1088 | case e_lrsel: | |
1089 | final_type = R_HPPA_ABS_CALL_LR21; | |
1090 | break; | |
e8f2240a | 1091 | default: |
f5bfdacd | 1092 | abort (); |
e8f2240a KR |
1093 | break; |
1094 | } | |
1095 | break; | |
f5bfdacd | 1096 | |
e8f2240a | 1097 | default: |
f5bfdacd | 1098 | abort (); |
e8f2240a KR |
1099 | break; |
1100 | } | |
1101 | break; | |
f5bfdacd JL |
1102 | |
1103 | ||
e8f2240a KR |
1104 | case R_HPPA_UNWIND: |
1105 | final_type = R_HPPA_UNWIND_ENTRY; | |
1106 | break; | |
f5bfdacd JL |
1107 | |
1108 | ||
e8f2240a KR |
1109 | case R_HPPA_COMPLEX: |
1110 | case R_HPPA_COMPLEX_PCREL_CALL: | |
1111 | case R_HPPA_COMPLEX_ABS_CALL: | |
f5bfdacd JL |
1112 | /* The code originally here was horribly broken, and apparently |
1113 | never used. Zap it. When we need complex relocations rewrite | |
1114 | it correctly! */ | |
1115 | abort (); | |
e8f2240a | 1116 | break; |
f5bfdacd | 1117 | |
e8f2240a KR |
1118 | default: |
1119 | final_type = base_type; | |
1120 | break; | |
1121 | } | |
1122 | ||
1123 | return final_types; | |
4c85cbfa KR |
1124 | } |
1125 | ||
e8f2240a KR |
1126 | #undef final_type |
1127 | ||
4c85cbfa | 1128 | |
f5bfdacd | 1129 | /* Actually perform a relocation. */ |
4c85cbfa KR |
1130 | |
1131 | static bfd_reloc_status_type | |
4991ebb9 ILT |
1132 | hppa_elf_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd, |
1133 | error_message) | |
4861ac76 JL |
1134 | bfd *abfd; |
1135 | arelent *reloc_entry; | |
1136 | asymbol *symbol_in; | |
1137 | PTR data; | |
1138 | asection *input_section; | |
1139 | bfd *output_bfd; | |
4991ebb9 | 1140 | char **error_message; |
e8f2240a KR |
1141 | { |
1142 | unsigned long insn; | |
1143 | long sym_value = 0; | |
4861ac76 | 1144 | unsigned long addr = reloc_entry->address; |
f5bfdacd JL |
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; | |
e8f2240a | 1148 | boolean r_pcrel = reloc_entry->howto->pc_relative; |
e8f2240a KR |
1149 | unsigned r_format = reloc_entry->howto->bitsize; |
1150 | long r_addend = reloc_entry->addend; | |
1151 | ||
f5bfdacd | 1152 | /* If only performing a partial link, get out early. */ |
e8f2240a KR |
1153 | if (output_bfd) |
1154 | { | |
e8f2240a KR |
1155 | reloc_entry->address += input_section->output_offset; |
1156 | return bfd_reloc_ok; | |
1157 | } | |
1158 | ||
4861ac76 JL |
1159 | /* If performing final link and the symbol we're relocating against |
1160 | is undefined, then return an error. */ | |
e8f2240a KR |
1161 | if (symbol_in && symbol_in->section == &bfd_und_section) |
1162 | return bfd_reloc_undefined; | |
1163 | ||
f5bfdacd | 1164 | /* Get the final relocated value. */ |
e8f2240a KR |
1165 | sym_value = get_symbol_value (symbol_in); |
1166 | ||
f5bfdacd JL |
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. | |
1170 | ||
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. */ | |
d9ad93bc | 1174 | if (!global_sym_defined) |
e8f2240a | 1175 | { |
d9ad93bc | 1176 | if (global_symbol) |
e8f2240a | 1177 | { |
d9ad93bc KR |
1178 | global_value = (global_symbol->value |
1179 | + global_symbol->section->output_section->vma | |
1180 | + global_symbol->section->output_offset); | |
4861ac76 | 1181 | GOT_value = global_value; |
d9ad93bc | 1182 | global_sym_defined++; |
e8f2240a KR |
1183 | } |
1184 | } | |
1185 | ||
4861ac76 | 1186 | /* Get the instruction word. */ |
e8f2240a KR |
1187 | insn = bfd_get_32 (abfd, hit_data); |
1188 | ||
4861ac76 | 1189 | /* Relocate the value based on one of the basic relocation types |
e8f2240a | 1190 | |
4861ac76 JL |
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 */ | |
e8f2240a KR |
1198 | |
1199 | switch (r_type) | |
1200 | { | |
1201 | case R_HPPA_NONE: | |
1202 | break; | |
4861ac76 JL |
1203 | |
1204 | /* Handle all the basic type 1 relocations. */ | |
1205 | case R_HPPA_32: | |
4861ac76 | 1206 | case R_HPPA_11: |
4861ac76 | 1207 | case R_HPPA_14: |
4861ac76 | 1208 | case R_HPPA_17: |
e8f2240a KR |
1209 | r_field = e_fsel; |
1210 | goto do_basic_type_1; | |
4861ac76 | 1211 | case R_HPPA_L21: |
e8f2240a KR |
1212 | r_field = e_lsel; |
1213 | goto do_basic_type_1; | |
4861ac76 | 1214 | case R_HPPA_R11: |
4861ac76 | 1215 | case R_HPPA_R14: |
4861ac76 | 1216 | case R_HPPA_R17: |
e8f2240a KR |
1217 | r_field = e_rsel; |
1218 | goto do_basic_type_1; | |
4861ac76 | 1219 | case R_HPPA_LS21: |
e8f2240a KR |
1220 | r_field = e_lssel; |
1221 | goto do_basic_type_1; | |
4861ac76 | 1222 | case R_HPPA_RS11: |
4861ac76 | 1223 | case R_HPPA_RS14: |
4861ac76 | 1224 | case R_HPPA_RS17: |
e8f2240a KR |
1225 | r_field = e_ldsel; |
1226 | goto do_basic_type_1; | |
4861ac76 | 1227 | case R_HPPA_LD21: |
e8f2240a KR |
1228 | r_field = e_ldsel; |
1229 | goto do_basic_type_1; | |
4861ac76 | 1230 | case R_HPPA_RD11: |
4861ac76 | 1231 | case R_HPPA_RD14: |
4861ac76 | 1232 | case R_HPPA_RD17: |
e8f2240a KR |
1233 | r_field = e_rdsel; |
1234 | goto do_basic_type_1; | |
4861ac76 | 1235 | case R_HPPA_LR21: |
e8f2240a KR |
1236 | r_field = e_lrsel; |
1237 | goto do_basic_type_1; | |
4861ac76 | 1238 | case R_HPPA_RR14: |
4861ac76 | 1239 | case R_HPPA_RR17: |
e8f2240a KR |
1240 | r_field = e_rrsel; |
1241 | ||
1242 | do_basic_type_1: | |
1243 | insn = hppa_elf_relocate_insn (abfd, input_section, insn, addr, | |
f5bfdacd JL |
1244 | sym_value, r_addend, r_format, |
1245 | r_field, r_pcrel); | |
e8f2240a KR |
1246 | break; |
1247 | ||
4861ac76 JL |
1248 | /* Handle all the basic type 2 relocations. */ |
1249 | case R_HPPA_GOTOFF_11: | |
4861ac76 | 1250 | case R_HPPA_GOTOFF_14: |
e8f2240a KR |
1251 | r_field = e_fsel; |
1252 | goto do_basic_type_2; | |
4861ac76 | 1253 | case R_HPPA_GOTOFF_L21: |
e8f2240a KR |
1254 | r_field = e_lsel; |
1255 | goto do_basic_type_2; | |
4861ac76 | 1256 | case R_HPPA_GOTOFF_R11: |
4861ac76 | 1257 | case R_HPPA_GOTOFF_R14: |
e8f2240a KR |
1258 | r_field = e_rsel; |
1259 | goto do_basic_type_2; | |
4861ac76 | 1260 | case R_HPPA_GOTOFF_LS21: |
e8f2240a KR |
1261 | r_field = e_lssel; |
1262 | goto do_basic_type_2; | |
4861ac76 | 1263 | case R_HPPA_GOTOFF_RS11: |
4861ac76 | 1264 | case R_HPPA_GOTOFF_RS14: |
e8f2240a KR |
1265 | r_field = e_rssel; |
1266 | goto do_basic_type_2; | |
4861ac76 | 1267 | case R_HPPA_GOTOFF_LD21: |
e8f2240a KR |
1268 | r_field = e_ldsel; |
1269 | goto do_basic_type_2; | |
4861ac76 | 1270 | case R_HPPA_GOTOFF_RD11: |
4861ac76 | 1271 | case R_HPPA_GOTOFF_RD14: |
e8f2240a KR |
1272 | r_field = e_rdsel; |
1273 | goto do_basic_type_2; | |
4861ac76 | 1274 | case R_HPPA_GOTOFF_LR21: |
e8f2240a KR |
1275 | r_field = e_lrsel; |
1276 | goto do_basic_type_2; | |
4861ac76 | 1277 | case R_HPPA_GOTOFF_RR14: |
e8f2240a | 1278 | r_field = e_rrsel; |
4861ac76 | 1279 | |
e8f2240a KR |
1280 | do_basic_type_2: |
1281 | sym_value -= GOT_value; | |
1282 | insn = hppa_elf_relocate_insn (abfd, input_section, insn, addr, | |
f5bfdacd JL |
1283 | sym_value, r_addend, r_format, |
1284 | r_field, r_pcrel); | |
e8f2240a KR |
1285 | break; |
1286 | ||
4861ac76 JL |
1287 | /* Handle all the basic type 3 relocations. */ |
1288 | case R_HPPA_ABS_CALL_11: | |
4861ac76 | 1289 | case R_HPPA_ABS_CALL_14: |
4861ac76 | 1290 | case R_HPPA_ABS_CALL_17: |
e8f2240a KR |
1291 | r_field = e_fsel; |
1292 | goto do_basic_type_3; | |
4861ac76 | 1293 | case R_HPPA_ABS_CALL_L21: |
e8f2240a KR |
1294 | r_field = e_lsel; |
1295 | goto do_basic_type_3; | |
4861ac76 | 1296 | case R_HPPA_ABS_CALL_R11: |
4861ac76 | 1297 | case R_HPPA_ABS_CALL_R14: |
4861ac76 | 1298 | case R_HPPA_ABS_CALL_R17: |
e8f2240a KR |
1299 | r_field = e_rsel; |
1300 | goto do_basic_type_3; | |
4861ac76 | 1301 | case R_HPPA_ABS_CALL_LS21: |
e8f2240a KR |
1302 | r_field = e_lssel; |
1303 | goto do_basic_type_3; | |
4861ac76 | 1304 | case R_HPPA_ABS_CALL_RS11: |
4861ac76 | 1305 | case R_HPPA_ABS_CALL_RS14: |
4861ac76 | 1306 | case R_HPPA_ABS_CALL_RS17: |
e8f2240a KR |
1307 | r_field = e_rssel; |
1308 | goto do_basic_type_3; | |
4861ac76 | 1309 | case R_HPPA_ABS_CALL_LD21: |
e8f2240a KR |
1310 | r_field = e_ldsel; |
1311 | goto do_basic_type_3; | |
4861ac76 | 1312 | case R_HPPA_ABS_CALL_RD11: |
4861ac76 | 1313 | case R_HPPA_ABS_CALL_RD14: |
4861ac76 | 1314 | case R_HPPA_ABS_CALL_RD17: |
e8f2240a KR |
1315 | r_field = e_rdsel; |
1316 | goto do_basic_type_3; | |
4861ac76 | 1317 | case R_HPPA_ABS_CALL_LR21: |
e8f2240a KR |
1318 | r_field = e_lrsel; |
1319 | goto do_basic_type_3; | |
4861ac76 | 1320 | case R_HPPA_ABS_CALL_RR14: |
4861ac76 | 1321 | case R_HPPA_ABS_CALL_RR17: |
e8f2240a | 1322 | r_field = e_rrsel; |
4861ac76 | 1323 | |
e8f2240a KR |
1324 | do_basic_type_3: |
1325 | insn = hppa_elf_relocate_insn (abfd, input_section, insn, addr, | |
f5bfdacd JL |
1326 | sym_value, r_addend, r_format, |
1327 | r_field, r_pcrel); | |
e8f2240a KR |
1328 | break; |
1329 | ||
4861ac76 JL |
1330 | /* Handle all the basic type 4 relocations. */ |
1331 | case R_HPPA_PCREL_CALL_11: | |
4861ac76 | 1332 | case R_HPPA_PCREL_CALL_14: |
4861ac76 | 1333 | case R_HPPA_PCREL_CALL_17: |
e8f2240a KR |
1334 | r_field = e_fsel; |
1335 | goto do_basic_type_4; | |
4861ac76 | 1336 | case R_HPPA_PCREL_CALL_L21: |
e8f2240a KR |
1337 | r_field = e_lsel; |
1338 | goto do_basic_type_4; | |
4861ac76 | 1339 | case R_HPPA_PCREL_CALL_R11: |
4861ac76 | 1340 | case R_HPPA_PCREL_CALL_R14: |
4861ac76 | 1341 | case R_HPPA_PCREL_CALL_R17: |
e8f2240a KR |
1342 | r_field = e_rsel; |
1343 | goto do_basic_type_4; | |
4861ac76 | 1344 | case R_HPPA_PCREL_CALL_LS21: |
e8f2240a KR |
1345 | r_field = e_lssel; |
1346 | goto do_basic_type_4; | |
4861ac76 | 1347 | case R_HPPA_PCREL_CALL_RS11: |
4861ac76 | 1348 | case R_HPPA_PCREL_CALL_RS14: |
4861ac76 | 1349 | case R_HPPA_PCREL_CALL_RS17: |
e8f2240a KR |
1350 | r_field = e_rssel; |
1351 | goto do_basic_type_4; | |
4861ac76 | 1352 | case R_HPPA_PCREL_CALL_LD21: |
e8f2240a KR |
1353 | r_field = e_ldsel; |
1354 | goto do_basic_type_4; | |
4861ac76 | 1355 | case R_HPPA_PCREL_CALL_RD11: |
4861ac76 | 1356 | case R_HPPA_PCREL_CALL_RD14: |
4861ac76 | 1357 | case R_HPPA_PCREL_CALL_RD17: |
e8f2240a KR |
1358 | r_field = e_rdsel; |
1359 | goto do_basic_type_4; | |
4861ac76 | 1360 | case R_HPPA_PCREL_CALL_LR21: |
e8f2240a KR |
1361 | r_field = e_lrsel; |
1362 | goto do_basic_type_4; | |
4861ac76 | 1363 | case R_HPPA_PCREL_CALL_RR14: |
4861ac76 | 1364 | case R_HPPA_PCREL_CALL_RR17: |
e8f2240a | 1365 | r_field = e_rrsel; |
4861ac76 | 1366 | |
e8f2240a KR |
1367 | do_basic_type_4: |
1368 | insn = hppa_elf_relocate_insn (abfd, input_section, insn, addr, | |
f5bfdacd JL |
1369 | sym_value, r_addend, r_format, |
1370 | r_field, r_pcrel); | |
e8f2240a KR |
1371 | break; |
1372 | ||
4861ac76 | 1373 | /* Handle all the basic type 5 relocations. */ |
e8f2240a KR |
1374 | case R_HPPA_PLABEL_32: |
1375 | case R_HPPA_PLABEL_11: | |
1376 | case R_HPPA_PLABEL_14: | |
1377 | r_field = e_fsel; | |
1378 | goto do_basic_type_5; | |
1379 | case R_HPPA_PLABEL_L21: | |
1380 | r_field = e_lsel; | |
1381 | goto do_basic_type_5; | |
1382 | case R_HPPA_PLABEL_R11: | |
1383 | case R_HPPA_PLABEL_R14: | |
1384 | r_field = e_rsel; | |
1385 | do_basic_type_5: | |
1386 | insn = hppa_elf_relocate_insn (abfd, input_section, insn, addr, | |
f5bfdacd JL |
1387 | sym_value, r_addend, r_format, |
1388 | r_field, r_pcrel); | |
e8f2240a KR |
1389 | break; |
1390 | ||
4861ac76 | 1391 | /* Handle all basic type 6 relocations. */ |
e8f2240a KR |
1392 | case R_HPPA_UNWIND_ENTRY: |
1393 | case R_HPPA_UNWIND_ENTRIES: | |
f5bfdacd JL |
1394 | hppa_elf_relocate_unwind_table (abfd, data, addr, |
1395 | sym_value, r_addend, | |
1396 | r_type, r_field); | |
4861ac76 JL |
1397 | return bfd_reloc_ok; |
1398 | ||
4861ac76 | 1399 | /* This is a linker internal relocation. */ |
d9ad93bc | 1400 | case R_HPPA_STUB_CALL_17: |
4861ac76 JL |
1401 | /* This relocation is for a branch to a long branch stub. |
1402 | Change instruction to a BLE,N. It may also be necessary | |
f5bfdacd | 1403 | to interchange the branch and its delay slot. |
4861ac76 JL |
1404 | The original instruction stream is |
1405 | ||
1406 | bl <foo>,r ; call foo using register r as | |
1407 | ; the return pointer | |
1408 | XXX ; delay slot instruction | |
1409 | ||
1410 | The new instruction stream will be: | |
1411 | ||
1412 | XXX ; delay slot instruction | |
1413 | ble <foo_stub> ; call the long call stub for foo | |
1414 | ; using r31 as the return pointer | |
1415 | ||
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" | |
f5bfdacd JL |
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. | |
4861ac76 JL |
1423 | |
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 | |
f5bfdacd JL |
1427 | jump after the call returns (GCC optimization). |
1428 | ||
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. */ | |
4861ac76 | 1432 | |
f5bfdacd | 1433 | /* Is this instruction nullified? (does this ever happen?) */ |
4861ac76 | 1434 | if (insn & 2) |
a36b6f1d JL |
1435 | { |
1436 | insn = BLE_N_XXX_0_0; | |
1437 | bfd_put_32 (abfd, insn, hit_data); | |
1438 | r_type = R_HPPA_ABS_CALL_17; | |
1439 | r_pcrel = 0; | |
1440 | insn = hppa_elf_relocate_insn (abfd, input_section, insn, | |
f5bfdacd JL |
1441 | addr, sym_value, r_addend, |
1442 | r_format, r_field, r_pcrel); | |
a36b6f1d | 1443 | } |
d9ad93bc | 1444 | else |
7218bb04 | 1445 | { |
f5bfdacd | 1446 | /* So much for the trivial case... */ |
7218bb04 KR |
1447 | unsigned long old_delay_slot_insn = bfd_get_32 (abfd, hit_data + 4); |
1448 | unsigned rtn_reg = (insn & 0x03e00000) >> 21; | |
1449 | ||
4861ac76 | 1450 | if (get_opcode (old_delay_slot_insn) == LDO) |
7218bb04 KR |
1451 | { |
1452 | unsigned ldo_src_reg = (old_delay_slot_insn & 0x03e00000) >> 21; | |
1453 | unsigned ldo_target_reg = (old_delay_slot_insn & 0x001f0000) >> 16; | |
1454 | ||
4861ac76 JL |
1455 | /* If the target of the LDO is the same as the return |
1456 | register then there is no reordering. We can leave the | |
f5bfdacd JL |
1457 | instuction as a non-nullified BLE in this case. |
1458 | ||
1459 | FIXME: This test looks wrong. If we had a ble using | |
1460 | ldo_target_reg as the *source* we'd fuck this up. */ | |
7218bb04 KR |
1461 | if (ldo_target_reg == rtn_reg) |
1462 | { | |
1463 | unsigned long new_delay_slot_insn = old_delay_slot_insn; | |
1464 | ||
f5bfdacd | 1465 | BFD_ASSERT (ldo_src_reg == ldo_target_reg); |
7218bb04 KR |
1466 | new_delay_slot_insn &= 0xfc00ffff; |
1467 | new_delay_slot_insn |= ((31 << 21) | (31 << 16)); | |
4861ac76 JL |
1468 | bfd_put_32 (abfd, new_delay_slot_insn, hit_data + 4); |
1469 | insn = BLE_XXX_0_0; | |
4861ac76 JL |
1470 | r_type = R_HPPA_ABS_CALL_17; |
1471 | r_pcrel = 0; | |
1472 | insn = hppa_elf_relocate_insn (abfd, input_section, insn, | |
f5bfdacd JL |
1473 | addr, sym_value, r_addend, |
1474 | r_format, r_field, r_pcrel); | |
a36b6f1d | 1475 | bfd_put_32 (abfd, insn, hit_data); |
4861ac76 | 1476 | return bfd_reloc_ok; |
7218bb04 | 1477 | } |
a36b6f1d JL |
1478 | else if (rtn_reg == 31) |
1479 | { | |
1480 | /* The return register is r31, so this is a millicode | |
1481 | call. Do not perform any instruction reordering. */ | |
1482 | insn = BLE_XXX_0_0; | |
1483 | r_type = R_HPPA_ABS_CALL_17; | |
1484 | r_pcrel = 0; | |
1485 | insn = hppa_elf_relocate_insn (abfd, input_section, insn, | |
f5bfdacd JL |
1486 | addr, sym_value, |
1487 | r_addend, r_format, | |
a36b6f1d JL |
1488 | r_field, r_pcrel); |
1489 | bfd_put_32 (abfd, insn, hit_data); | |
1490 | return bfd_reloc_ok; | |
1491 | } | |
4861ac76 JL |
1492 | else |
1493 | { | |
1494 | /* Check to see if the delay slot instruction has a | |
1495 | relocation. If so, we need to change the address | |
f5bfdacd JL |
1496 | field of it because the instruction it relocates |
1497 | is going to be moved. Oh what a mess. */ | |
4861ac76 JL |
1498 | arelent * next_reloc_entry = reloc_entry+1; |
1499 | ||
1500 | if (next_reloc_entry->address == reloc_entry->address + 4) | |
1501 | next_reloc_entry->address -= 4; | |
1502 | ||
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; | |
1508 | r_pcrel = 0; | |
1509 | insn = hppa_elf_relocate_insn (abfd, input_section, insn, | |
f5bfdacd JL |
1510 | addr + 4, |
1511 | sym_value, r_addend, | |
4861ac76 JL |
1512 | r_format, r_field, r_pcrel); |
1513 | bfd_put_32 (abfd, insn, hit_data + 4); | |
1514 | return bfd_reloc_ok; | |
1515 | } | |
1516 | } | |
f5bfdacd | 1517 | /* Same comments as above regarding incorrect test. */ |
a36b6f1d JL |
1518 | else if (rtn_reg == 31) |
1519 | { | |
1520 | /* The return register is r31, so this is a millicode call. | |
1521 | Perform no instruction reordering in this case. */ | |
1522 | insn = BLE_XXX_0_0; | |
1523 | r_type = R_HPPA_ABS_CALL_17; | |
1524 | r_pcrel = 0; | |
1525 | insn = hppa_elf_relocate_insn (abfd, input_section, insn, | |
f5bfdacd JL |
1526 | addr, sym_value, |
1527 | r_addend, r_format, | |
a36b6f1d JL |
1528 | r_field, r_pcrel); |
1529 | bfd_put_32 (abfd, insn, hit_data); | |
1530 | return bfd_reloc_ok; | |
1531 | } | |
4861ac76 JL |
1532 | else |
1533 | { | |
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 | |
1537 | to be moved. */ | |
1538 | arelent * next_reloc_entry = reloc_entry+1; | |
1539 | ||
1540 | if (next_reloc_entry->address == reloc_entry->address + 4) | |
1541 | next_reloc_entry->address -= 4; | |
1542 | ||
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; | |
1548 | r_pcrel = 0; | |
1549 | insn = hppa_elf_relocate_insn (abfd, input_section, insn, | |
f5bfdacd JL |
1550 | addr + 4, sym_value, |
1551 | r_addend, r_format, | |
4861ac76 JL |
1552 | r_field, r_pcrel); |
1553 | bfd_put_32 (abfd, insn, hit_data + 4); | |
1554 | return bfd_reloc_ok; | |
7218bb04 | 1555 | } |
7218bb04 | 1556 | } |
d9ad93bc KR |
1557 | break; |
1558 | ||
f5bfdacd | 1559 | /* Something we don't know how to handle. */ |
e8f2240a | 1560 | default: |
4991ebb9 | 1561 | *error_message = (char *) "Unrecognized reloc"; |
f5bfdacd | 1562 | return bfd_reloc_notsupported; |
e8f2240a KR |
1563 | } |
1564 | ||
4861ac76 | 1565 | /* Update the instruction word. */ |
e8f2240a | 1566 | bfd_put_32 (abfd, insn, hit_data); |
e8f2240a | 1567 | return (bfd_reloc_ok); |
e8f2240a KR |
1568 | } |
1569 | ||
f5bfdacd JL |
1570 | /* Return the address of the howto table entry to perform the CODE |
1571 | relocation for an ARCH machine. */ | |
1572 | ||
1573 | static CONST reloc_howto_type * | |
7ed5e970 ILT |
1574 | elf_hppa_reloc_type_lookup (abfd, code) |
1575 | bfd *abfd; | |
e8f2240a KR |
1576 | bfd_reloc_code_real_type code; |
1577 | { | |
e8f2240a KR |
1578 | if ((int) code < (int) R_HPPA_UNIMPLEMENTED) |
1579 | { | |
1580 | BFD_ASSERT ((int) elf_hppa_howto_table[(int) code].type == (int) code); | |
1581 | return &elf_hppa_howto_table[(int) code]; | |
1582 | } | |
f5bfdacd | 1583 | return NULL; |
e8f2240a KR |
1584 | } |
1585 | ||
25057836 JL |
1586 | /* Return true if SYM represents a local label symbol. */ |
1587 | ||
1588 | static boolean | |
1589 | hppa_elf_is_local_label (abfd, sym) | |
1590 | bfd *abfd; | |
1591 | asymbol *sym; | |
1592 | { | |
1593 | return (sym->name[0] == 'L' && sym->name[1] == '$'); | |
1594 | } | |
e8f2240a | 1595 | |
f5bfdacd JL |
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. */ | |
e8f2240a KR |
1598 | |
1599 | void | |
f5bfdacd | 1600 | elf_hppa_tc_symbol (abfd, symbolP, sym_idx, symext_root, symext_last) |
f4bd7a8f DM |
1601 | bfd *abfd; |
1602 | elf_symbol_type *symbolP; | |
1603 | int sym_idx; | |
f5bfdacd JL |
1604 | symext_chainS **symext_root; |
1605 | symext_chainS **symext_last; | |
e8f2240a KR |
1606 | { |
1607 | symext_chainS *symextP; | |
1608 | unsigned int arg_reloc; | |
1609 | ||
3a70b01d | 1610 | /* Only functions can have argument relocations. */ |
e8f2240a KR |
1611 | if (!(symbolP->symbol.flags & BSF_FUNCTION)) |
1612 | return; | |
1613 | ||
e8f2240a KR |
1614 | arg_reloc = symbolP->tc_data.hppa_arg_reloc; |
1615 | ||
3a70b01d KR |
1616 | /* If there are no argument relocation bits, then no relocation is |
1617 | necessary. Do not add this to the symextn section. */ | |
1618 | if (arg_reloc == 0) | |
1619 | return; | |
1620 | ||
f5bfdacd | 1621 | /* Allocate memory and initialize this entry. */ |
e8f2240a | 1622 | symextP = (symext_chainS *) bfd_alloc (abfd, sizeof (symext_chainS) * 2); |
9783e04a DM |
1623 | if (!symextP) |
1624 | { | |
f5bfdacd | 1625 | bfd_set_error (bfd_error_no_memory); |
9783e04a DM |
1626 | abort(); /* FIXME */ |
1627 | } | |
e8f2240a KR |
1628 | |
1629 | symextP[0].entry = ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX, sym_idx); | |
1630 | symextP[0].next = &symextP[1]; | |
1631 | ||
1632 | symextP[1].entry = ELF32_HPPA_SX_WORD (HPPA_SXT_ARG_RELOC, arg_reloc); | |
1633 | symextP[1].next = NULL; | |
1634 | ||
f5bfdacd JL |
1635 | /* Now update the chain itself so it can be walked later to build |
1636 | the symbol extension section. */ | |
1637 | if (*symext_root == NULL) | |
e8f2240a | 1638 | { |
f5bfdacd JL |
1639 | *symext_root = &symextP[0]; |
1640 | *symext_last = &symextP[1]; | |
e8f2240a KR |
1641 | } |
1642 | else | |
1643 | { | |
f5bfdacd JL |
1644 | (*symext_last)->next = &symextP[0]; |
1645 | *symext_last = &symextP[1]; | |
e8f2240a KR |
1646 | } |
1647 | } | |
1648 | ||
f5bfdacd | 1649 | /* Build the symbol extension section. Used internally and by GAS. */ |
e8f2240a KR |
1650 | |
1651 | void | |
f5bfdacd | 1652 | elf_hppa_tc_make_sections (abfd, symext_root) |
f4bd7a8f | 1653 | bfd *abfd; |
f5bfdacd | 1654 | symext_chainS *symext_root; |
e8f2240a KR |
1655 | { |
1656 | symext_chainS *symextP; | |
f5bfdacd | 1657 | int size, n, i; |
e8f2240a KR |
1658 | asection *symextn_sec; |
1659 | ||
f5bfdacd | 1660 | /* FIXME: Huh? I don't see what this is supposed to do for us. */ |
e8f2240a KR |
1661 | hppa_elf_stub_finish (abfd); |
1662 | ||
f5bfdacd JL |
1663 | /* If there are no entries in the symbol extension chain, then |
1664 | there is no symbol extension section. */ | |
1665 | if (symext_root == NULL) | |
e8f2240a KR |
1666 | return; |
1667 | ||
f5bfdacd JL |
1668 | /* Count the number of entries on the chain. */ |
1669 | for (n = 0, symextP = symext_root; symextP; symextP = symextP->next, ++n) | |
e8f2240a KR |
1670 | ; |
1671 | ||
f5bfdacd JL |
1672 | /* Create the symbol extension section and set some appropriate |
1673 | attributes. */ | |
e8f2240a KR |
1674 | size = sizeof (symext_entryS) * n; |
1675 | symextn_sec = bfd_get_section_by_name (abfd, SYMEXTN_SECTION_NAME); | |
1676 | if (symextn_sec == (asection *) 0) | |
1677 | { | |
1678 | symextn_sec = bfd_make_section (abfd, SYMEXTN_SECTION_NAME); | |
1679 | bfd_set_section_flags (abfd, | |
1680 | symextn_sec, | |
f5bfdacd | 1681 | SEC_LOAD | SEC_HAS_CONTENTS | SEC_DATA); |
e8f2240a KR |
1682 | symextn_sec->output_section = symextn_sec; |
1683 | symextn_sec->output_offset = 0; | |
1684 | bfd_set_section_alignment (abfd, symextn_sec, 2); | |
1685 | } | |
f5bfdacd JL |
1686 | bfd_set_section_size (abfd, symextn_sec, symextn_contents_real_size); |
1687 | symextn_contents_real_size = size; | |
1688 | ||
1689 | /* Grab some memory for the contents of the symbol extension section | |
1690 | itself. */ | |
e8f2240a | 1691 | symextn_contents = (symext_entryS *) bfd_alloc (abfd, size); |
9783e04a DM |
1692 | if (!symextn_contents) |
1693 | { | |
f5bfdacd | 1694 | bfd_set_error (bfd_error_no_memory); |
9783e04a DM |
1695 | abort(); /* FIXME */ |
1696 | } | |
e8f2240a | 1697 | |
f5bfdacd JL |
1698 | /* Fill in the contents of the symbol extension section. */ |
1699 | for (i = 0, symextP = symext_root; symextP; symextP = symextP->next, ++i) | |
e8f2240a | 1700 | symextn_contents[i] = symextP->entry; |
e8f2240a KR |
1701 | |
1702 | return; | |
1703 | } | |
1704 | ||
e08b9ad7 | 1705 | /* Return the symbol extension record of type TYPE for the symbol SYM. */ |
e8f2240a | 1706 | |
e08b9ad7 | 1707 | static symext_entryS |
e8f2240a KR |
1708 | elf32_hppa_get_sym_extn (abfd, sym, type) |
1709 | bfd *abfd; | |
1710 | asymbol *sym; | |
1711 | int type; | |
1712 | { | |
e8f2240a KR |
1713 | switch (type) |
1714 | { | |
e8f2240a | 1715 | case HPPA_SXT_SYMNDX: |
e08b9ad7 JL |
1716 | case HPPA_SXT_NULL: |
1717 | return (symext_entryS) 0; | |
e8f2240a KR |
1718 | case HPPA_SXT_ARG_RELOC: |
1719 | { | |
3a70b01d | 1720 | elf_symbol_type *esymP = (elf_symbol_type *) sym; |
e8f2240a | 1721 | |
e08b9ad7 | 1722 | return (symext_entryS) esymP->tc_data.hppa_arg_reloc; |
e8f2240a | 1723 | } |
d9ad93bc KR |
1724 | /* This should never happen. */ |
1725 | default: | |
1726 | abort(); | |
e8f2240a | 1727 | } |
e8f2240a KR |
1728 | } |
1729 | ||
e08b9ad7 JL |
1730 | /* Search the chain of stub descriptions and locate the stub |
1731 | description for this the given section within the given bfd. | |
e8f2240a | 1732 | |
e08b9ad7 JL |
1733 | FIXME: I see yet another wonderful linear linked list search |
1734 | here. This is probably bad. */ | |
e8f2240a | 1735 | |
3a70b01d | 1736 | static elf32_hppa_stub_description * |
e8f2240a KR |
1737 | find_stubs (abfd, stub_sec) |
1738 | bfd *abfd; | |
1739 | asection *stub_sec; | |
1740 | { | |
3a70b01d | 1741 | elf32_hppa_stub_description *stubP; |
e8f2240a KR |
1742 | |
1743 | for (stubP = elf_hppa_stub_rootP; stubP; stubP = stubP->next) | |
1744 | { | |
e08b9ad7 JL |
1745 | /* Is this the right one? */ |
1746 | if (stubP->this_bfd == abfd && stubP->stub_sec == stub_sec) | |
3a70b01d | 1747 | return stubP; |
e8f2240a | 1748 | } |
e08b9ad7 | 1749 | return NULL; |
e8f2240a KR |
1750 | } |
1751 | ||
3a70b01d | 1752 | static elf32_hppa_stub_description * |
4991ebb9 | 1753 | new_stub (abfd, stub_sec, link_info) |
e8f2240a KR |
1754 | bfd *abfd; |
1755 | asection *stub_sec; | |
4991ebb9 | 1756 | struct bfd_link_info *link_info; |
e8f2240a | 1757 | { |
3a70b01d | 1758 | elf32_hppa_stub_description *stub = find_stubs (abfd, stub_sec); |
e8f2240a | 1759 | |
e08b9ad7 | 1760 | /* If we found a list for this bfd, then use it. */ |
e8f2240a KR |
1761 | if (stub) |
1762 | return stub; | |
1763 | ||
e08b9ad7 JL |
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)); | |
3a70b01d KR |
1767 | if (stub) |
1768 | { | |
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; | |
4991ebb9 | 1775 | stub->link_info = link_info; |
3a70b01d KR |
1776 | |
1777 | stub->next = elf_hppa_stub_rootP; | |
1778 | elf_hppa_stub_rootP = stub; | |
1779 | } | |
1780 | else | |
1781 | { | |
f5bfdacd | 1782 | bfd_set_error (bfd_error_no_memory); |
9783e04a | 1783 | abort(); /* FIXME */ |
3a70b01d | 1784 | } |
e8f2240a KR |
1785 | |
1786 | return stub; | |
1787 | } | |
1788 | ||
e08b9ad7 JL |
1789 | /* Try and locate a stub with the name NAME within the stubs |
1790 | associated with ABFD. More linked list searches. */ | |
1791 | ||
3a70b01d KR |
1792 | static elf32_hppa_stub_name_list * |
1793 | find_stub_by_name (abfd, stub_sec, name) | |
1794 | bfd *abfd; | |
1795 | asection *stub_sec; | |
1796 | char *name; | |
1797 | { | |
e08b9ad7 | 1798 | /* Find the stubs associated with this bfd. */ |
3a70b01d KR |
1799 | elf32_hppa_stub_description *stub = find_stubs (abfd, stub_sec); |
1800 | ||
e08b9ad7 | 1801 | /* If found, then we have to walk down them looking for a match. */ |
3a70b01d KR |
1802 | if (stub) |
1803 | { | |
1804 | elf32_hppa_stub_name_list *name_listP; | |
1805 | ||
e08b9ad7 JL |
1806 | for (name_listP = stub->stub_listP; |
1807 | name_listP; | |
1808 | name_listP = name_listP->next) | |
3a70b01d KR |
1809 | { |
1810 | if (!strcmp (name_listP->sym->name, name)) | |
1811 | return name_listP; | |
1812 | } | |
1813 | } | |
1814 | ||
e08b9ad7 | 1815 | /* Not found. */ |
3a70b01d KR |
1816 | return 0; |
1817 | } | |
1818 | ||
e08b9ad7 | 1819 | /* Add a new stub (SYM) to the list of stubs associated with the given BFD. */ |
3a70b01d | 1820 | static elf32_hppa_stub_name_list * |
4991ebb9 | 1821 | add_stub_by_name(abfd, stub_sec, sym, link_info) |
3a70b01d KR |
1822 | bfd *abfd; |
1823 | asection *stub_sec; | |
1824 | asymbol *sym; | |
4991ebb9 | 1825 | struct bfd_link_info *link_info; |
e8f2240a | 1826 | { |
3a70b01d KR |
1827 | elf32_hppa_stub_description *stub = find_stubs (abfd, stub_sec); |
1828 | elf32_hppa_stub_name_list *stub_entry; | |
e8f2240a | 1829 | |
e08b9ad7 JL |
1830 | /* If no stubs are associated with this bfd, then we have to make |
1831 | a chain-of-stubs associated with this bfd. */ | |
3a70b01d | 1832 | if (!stub) |
e08b9ad7 | 1833 | stub = new_stub (abfd, stub_sec, link_info); |
e8f2240a | 1834 | |
3a70b01d | 1835 | if (stub) |
e8f2240a | 1836 | { |
e08b9ad7 | 1837 | /* Allocate and initialize an entry in the stub chain. */ |
3a70b01d KR |
1838 | stub_entry = (elf32_hppa_stub_name_list *) |
1839 | bfd_zalloc (abfd, sizeof (elf32_hppa_stub_name_list)); | |
e8f2240a | 1840 | |
3a70b01d | 1841 | if (stub_entry) |
e8f2240a | 1842 | { |
3a70b01d KR |
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; | |
e08b9ad7 | 1849 | /* Add it to the chain. */ |
3a70b01d KR |
1850 | if (stub->stub_listP) |
1851 | stub_entry->next = stub->stub_listP; | |
1852 | else | |
1853 | stub_entry->next = NULL; | |
1854 | stub->stub_listP = stub_entry; | |
1855 | return stub_entry; | |
4c85cbfa | 1856 | } |
e8f2240a KR |
1857 | else |
1858 | { | |
f5bfdacd | 1859 | bfd_set_error (bfd_error_no_memory); |
9783e04a | 1860 | abort(); /* FIXME */ |
e8f2240a KR |
1861 | } |
1862 | } | |
e08b9ad7 JL |
1863 | /* Death by mis-adventure. */ |
1864 | abort (); | |
3a70b01d | 1865 | return (elf32_hppa_stub_name_list *)NULL; |
e8f2240a KR |
1866 | } |
1867 | ||
e08b9ad7 JL |
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. */ | |
e8f2240a | 1871 | |
e08b9ad7 | 1872 | static arg_reloc_type |
e8f2240a KR |
1873 | type_of_mismatch (caller_bits, callee_bits, type) |
1874 | int caller_bits; | |
1875 | int callee_bits; | |
1876 | int type; | |
1877 | { | |
1878 | switch (type) | |
1879 | { | |
1880 | case ARGUMENTS: | |
1881 | return mismatches[caller_bits][callee_bits]; | |
1882 | case RETURN_VALUE: | |
1883 | return retval_mismatches[caller_bits][callee_bits]; | |
1884 | } | |
e08b9ad7 | 1885 | return ARG_RELOC_ERR; |
e8f2240a KR |
1886 | } |
1887 | ||
e08b9ad7 JL |
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 | |
e8f2240a | 1891 | |
e08b9ad7 JL |
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) \ | |
4861ac76 | 1896 | { \ |
3a70b01d | 1897 | *((entry)->stub_desc->stub_secp)++ = (insn); \ |
e08b9ad7 | 1898 | (entry)->stub_desc->real_size += sizeof (int); \ |
3a70b01d KR |
1899 | (entry)->size += sizeof(int); \ |
1900 | bfd_set_section_size((entry)->stub_desc->this_bfd, \ | |
1901 | (entry)->stub_desc->stub_sec, \ | |
4861ac76 JL |
1902 | (entry)->stub_desc->real_size); \ |
1903 | } | |
e8f2240a | 1904 | |
e08b9ad7 JL |
1905 | /* Find the offset of the current stub? Looks more like it |
1906 | finds the offset of the last instruction to me. */ | |
3a70b01d | 1907 | #define CURRENT_STUB_OFFSET(entry) \ |
9783e04a DM |
1908 | ((char *)(entry)->stub_desc->stub_secp \ |
1909 | - (char *)(entry)->stub_desc->stub_contents - 4) | |
d9ad93bc | 1910 | |
e08b9ad7 JL |
1911 | /* All the stubs have already been built, finish up stub stuff |
1912 | by applying relocations to the stubs. */ | |
d9ad93bc | 1913 | |
e08b9ad7 | 1914 | static void |
e8f2240a KR |
1915 | hppa_elf_stub_finish (output_bfd) |
1916 | bfd *output_bfd; | |
1917 | { | |
3a70b01d | 1918 | elf32_hppa_stub_description *stub_list = elf_hppa_stub_rootP; |
e8f2240a | 1919 | |
e08b9ad7 | 1920 | /* If the stubs have been finished, then we're already done. */ |
f5bfdacd | 1921 | if (stubs_finished) |
d9ad93bc KR |
1922 | return; |
1923 | ||
e08b9ad7 | 1924 | /* Walk down the list of stub lists. */ |
e8f2240a KR |
1925 | for (; stub_list; stub_list = stub_list->next) |
1926 | { | |
e08b9ad7 | 1927 | /* If this list has stubs, then do something. */ |
3a70b01d | 1928 | if (stub_list->real_size) |
e8f2240a | 1929 | { |
3a70b01d | 1930 | bfd *stub_bfd = stub_list->this_bfd; |
e08b9ad7 JL |
1931 | asection *stub_sec = bfd_get_section_by_name (stub_bfd, |
1932 | ".hppa_linker_stubs"); | |
326e32d7 | 1933 | long reloc_size; |
e8f2240a | 1934 | arelent **reloc_vector; |
326e32d7 | 1935 | long reloc_count; |
e8f2240a | 1936 | |
e08b9ad7 | 1937 | /* Some sanity checking. */ |
3a70b01d | 1938 | BFD_ASSERT (stub_sec == stub_list->stub_sec); |
e8f2240a KR |
1939 | BFD_ASSERT (stub_sec); |
1940 | ||
e08b9ad7 JL |
1941 | /* For stub sections raw_size == cooked_size. Also update |
1942 | reloc_done as we're handling the relocs now. */ | |
e8f2240a KR |
1943 | stub_sec->_cooked_size = stub_sec->_raw_size; |
1944 | stub_sec->reloc_done = true; | |
1945 | ||
e08b9ad7 JL |
1946 | /* Make space to hold the relocations for the stub section. */ |
1947 | reloc_size = bfd_get_reloc_upper_bound (stub_bfd, stub_sec); | |
326e32d7 ILT |
1948 | if (reloc_size < 0) |
1949 | { | |
1950 | /* FIXME: Should return an error. */ | |
1951 | abort (); | |
1952 | } | |
80425e6c | 1953 | reloc_vector = (arelent **) malloc (reloc_size); |
25057836 | 1954 | if (reloc_vector == NULL && reloc_size != 0) |
80425e6c JK |
1955 | { |
1956 | /* FIXME: should be returning an error so the caller can | |
1957 | clean up */ | |
1958 | abort (); | |
1959 | } | |
e8f2240a | 1960 | |
e08b9ad7 | 1961 | /* If we have relocations, do them. */ |
326e32d7 ILT |
1962 | reloc_count = bfd_canonicalize_reloc (stub_bfd, stub_sec, |
1963 | reloc_vector, | |
1964 | output_bfd->outsymbols); | |
1965 | if (reloc_count < 0) | |
1966 | { | |
1967 | /* FIXME: Should return an error. */ | |
1968 | abort (); | |
1969 | } | |
1970 | if (reloc_count > 0) | |
e8f2240a KR |
1971 | { |
1972 | arelent **parent; | |
e08b9ad7 | 1973 | for (parent = reloc_vector; *parent != NULL; parent++) |
e8f2240a | 1974 | { |
e08b9ad7 | 1975 | char *err = NULL; |
e8f2240a | 1976 | bfd_reloc_status_type r = |
e08b9ad7 | 1977 | bfd_perform_relocation (stub_bfd, *parent, |
4991ebb9 ILT |
1978 | stub_list->stub_contents, |
1979 | stub_sec, (bfd *) NULL, &err); | |
e8f2240a | 1980 | |
e08b9ad7 | 1981 | /* If there was an error, tell someone about it. */ |
e8f2240a KR |
1982 | if (r != bfd_reloc_ok) |
1983 | { | |
4991ebb9 ILT |
1984 | struct bfd_link_info *link_info = stub_list->link_info; |
1985 | ||
e8f2240a KR |
1986 | switch (r) |
1987 | { | |
1988 | case bfd_reloc_undefined: | |
4991ebb9 ILT |
1989 | if (! ((*link_info->callbacks->undefined_symbol) |
1990 | (link_info, | |
1991 | bfd_asymbol_name (*(*parent)->sym_ptr_ptr), | |
1992 | stub_bfd, stub_sec, (*parent)->address))) | |
1993 | abort (); | |
e8f2240a KR |
1994 | break; |
1995 | case bfd_reloc_dangerous: | |
4991ebb9 ILT |
1996 | if (! ((*link_info->callbacks->reloc_dangerous) |
1997 | (link_info, err, stub_bfd, stub_sec, | |
1998 | (*parent)->address))) | |
1999 | abort (); | |
e8f2240a | 2000 | break; |
e8f2240a | 2001 | case bfd_reloc_overflow: |
4991ebb9 ILT |
2002 | { |
2003 | if (! ((*link_info->callbacks->reloc_overflow) | |
2004 | (link_info, | |
2005 | bfd_asymbol_name (*(*parent)->sym_ptr_ptr), | |
2006 | (*parent)->howto->name, | |
2007 | (*parent)->addend, | |
2008 | stub_bfd, stub_sec, | |
2009 | (*parent)->address))) | |
2010 | abort (); | |
2011 | } | |
e8f2240a | 2012 | break; |
4991ebb9 | 2013 | case bfd_reloc_outofrange: |
e8f2240a KR |
2014 | default: |
2015 | abort (); | |
2016 | break; | |
2017 | } | |
2018 | } | |
2019 | } | |
2020 | } | |
80425e6c | 2021 | free (reloc_vector); |
e8f2240a | 2022 | |
e08b9ad7 JL |
2023 | /* All done with the relocations. Set the final contents |
2024 | of the stub section. FIXME: no check of return value! */ | |
2025 | bfd_set_section_contents (output_bfd, stub_sec, | |
3a70b01d | 2026 | stub_list->stub_contents, |
e08b9ad7 | 2027 | 0, stub_list->real_size); |
e8f2240a KR |
2028 | } |
2029 | } | |
e08b9ad7 | 2030 | /* All done. */ |
d9ad93bc | 2031 | stubs_finished = true; |
e8f2240a KR |
2032 | } |
2033 | ||
e08b9ad7 | 2034 | /* Allocate a new relocation entry to be used in a linker stub. */ |
d9ad93bc | 2035 | |
e08b9ad7 JL |
2036 | static void |
2037 | hppa_elf_stub_reloc (stub_desc, output_bfd, target_sym, offset, type) | |
f4bd7a8f DM |
2038 | elf32_hppa_stub_description *stub_desc; |
2039 | bfd *output_bfd; | |
6e58a4e5 | 2040 | asymbol **target_sym; |
f4bd7a8f DM |
2041 | int offset; |
2042 | elf32_hppa_reloc_type type; | |
d9ad93bc | 2043 | { |
d9ad93bc KR |
2044 | arelent relent; |
2045 | int size; | |
2046 | Elf_Internal_Shdr *rela_hdr; | |
2047 | ||
e08b9ad7 | 2048 | /* I really don't like the realloc nonsense in here. FIXME. */ |
d9ad93bc KR |
2049 | if (stub_desc->relocs_allocated_cnt == stub_desc->stub_sec->reloc_count) |
2050 | { | |
e08b9ad7 | 2051 | /* Allocate the first few relocation entries. */ |
d9ad93bc KR |
2052 | if (stub_desc->stub_sec->relocation == NULL) |
2053 | { | |
2054 | stub_desc->relocs_allocated_cnt = STUB_RELOC_INCR; | |
2055 | size = sizeof (arelent) * stub_desc->relocs_allocated_cnt; | |
f4bd7a8f | 2056 | stub_desc->stub_sec->relocation = (arelent *) bfd_zmalloc (size); |
d9ad93bc KR |
2057 | } |
2058 | else | |
2059 | { | |
e08b9ad7 JL |
2060 | /* We've used all the entries we've already allocated. So get |
2061 | some more. */ | |
d9ad93bc KR |
2062 | stub_desc->relocs_allocated_cnt += STUB_RELOC_INCR; |
2063 | size = sizeof (arelent) * stub_desc->relocs_allocated_cnt; | |
e08b9ad7 JL |
2064 | stub_desc->stub_sec->relocation = (arelent *) |
2065 | realloc (stub_desc->stub_sec->relocation, size); | |
d9ad93bc | 2066 | } |
9783e04a DM |
2067 | if (!stub_desc->stub_sec->relocation) |
2068 | { | |
f5bfdacd | 2069 | bfd_set_error (bfd_error_no_memory); |
e08b9ad7 | 2070 | abort (); /* FIXME */ |
9783e04a | 2071 | } |
d9ad93bc KR |
2072 | } |
2073 | ||
2074 | rela_hdr = &elf_section_data(stub_desc->stub_sec)->rel_hdr; | |
2075 | rela_hdr->sh_size += sizeof(Elf32_External_Rela); | |
2076 | ||
2077 | /* Fill in the details. */ | |
2078 | relent.address = offset; | |
2079 | relent.addend = 0; | |
6e58a4e5 | 2080 | relent.sym_ptr_ptr = target_sym; |
d9ad93bc | 2081 | relent.howto = bfd_reloc_type_lookup (stub_desc->this_bfd, type); |
e8f2240a | 2082 | |
e08b9ad7 | 2083 | /* Save it in the array of relocations for the stub section. */ |
e8f2240a | 2084 | memcpy (&stub_desc->stub_sec->relocation[stub_desc->stub_sec->reloc_count++], |
e08b9ad7 | 2085 | &relent, sizeof (arelent)); |
e8f2240a KR |
2086 | } |
2087 | ||
e08b9ad7 JL |
2088 | /* Build an argument relocation stub. RTN_ADJUST is a hint that an |
2089 | adjust to the return pointer from within the stub itself may be | |
2090 | needed. */ | |
2091 | ||
2092 | static asymbol * | |
2093 | hppa_elf_build_linker_stub (abfd, output_bfd, link_info, reloc_entry, | |
2094 | stub_types, rtn_adjust, data, linker_stub_type) | |
e8f2240a KR |
2095 | bfd *abfd; |
2096 | bfd *output_bfd; | |
4991ebb9 | 2097 | struct bfd_link_info *link_info; |
e8f2240a | 2098 | arelent *reloc_entry; |
e08b9ad7 | 2099 | arg_reloc_type stub_types[5]; |
4861ac76 JL |
2100 | int rtn_adjust; |
2101 | unsigned *data; | |
e08b9ad7 | 2102 | hppa_stub_type linker_stub_type; |
e8f2240a | 2103 | { |
e8f2240a | 2104 | int i; |
e08b9ad7 | 2105 | boolean milli, dyncall; |
e8f2240a | 2106 | char stub_sym_name[128]; |
3a70b01d | 2107 | elf32_hppa_stub_name_list *stub_entry; |
e08b9ad7 | 2108 | /* Some initialization. */ |
4861ac76 | 2109 | unsigned insn = data[0]; |
e08b9ad7 | 2110 | asymbol *stub_sym = NULL; |
f3b477be | 2111 | asymbol **orig_sym = reloc_entry->sym_ptr_ptr; |
e08b9ad7 JL |
2112 | asection *stub_sec = bfd_get_section_by_name (abfd, ".hppa_linker_stubs"); |
2113 | elf32_hppa_stub_description *stub_desc = find_stubs (abfd, stub_sec); | |
4861ac76 JL |
2114 | |
2115 | /* Perform some additional checks on whether we should really do the | |
2116 | return adjustment. For example, if the instruction is nullified | |
2117 | or if the delay slot contains an instruction that modifies the return | |
2118 | pointer, then the branch instructions should not be rearranged | |
2119 | (rtn_adjust is false). */ | |
2120 | if (insn & 2 || insn == 0) | |
2121 | rtn_adjust = false; | |
2122 | else | |
2123 | { | |
2124 | unsigned delay_insn = data[1]; | |
e8f2240a | 2125 | |
4861ac76 JL |
2126 | if (get_opcode (delay_insn) == LDO |
2127 | && (((insn & 0x03e00000) >> 21) == ((delay_insn & 0x001f0000) >> 16))) | |
2128 | rtn_adjust = false; | |
2129 | } | |
2130 | ||
e08b9ad7 JL |
2131 | /* Some special code for long-call stubs. */ |
2132 | if (linker_stub_type == HPPA_STUB_LONG_CALL) | |
2133 | { | |
2134 | ||
2135 | /* Is this a millicode call? If so, the return address | |
2136 | comes in on r31 rather than r2 (rp) so a slightly | |
2137 | different code sequence is needed. */ | |
2138 | unsigned rtn_reg = (insn & 0x03e00000) >> 21; | |
2139 | if (rtn_reg == 31) | |
2140 | milli = true; | |
2141 | ||
2142 | /* Dyncall is special because the user code has already | |
2143 | put the return pointer in %r2 (aka RP). Other millicode | |
2144 | calls have the return pointer in %r31. */ | |
f3b477be | 2145 | if (strcmp ((*orig_sym)->name, "$$dyncall") == 0) |
e08b9ad7 JL |
2146 | dyncall = true; |
2147 | ||
2148 | /* If we are creating a call from a stub to another stub, then | |
2149 | never do the instruction reordering. We can tell if we are | |
2150 | going to be calling one stub from another by the fact that | |
2151 | the symbol name has '_stub_' (arg. reloc. stub) or '_lb_stub_' | |
2152 | prepended to the name. Alternatively, the section of the | |
2153 | symbol will be '.hppa_linker_stubs'. This is only an issue | |
2154 | for long-calls; they are the only stubs allowed to call another | |
2155 | stub. */ | |
f3b477be JL |
2156 | if ((strncmp ((*orig_sym)->name, "_stub_", 6) == 0) |
2157 | || (strncmp ((*orig_sym)->name, "_lb_stub_", 9) == 0)) | |
e08b9ad7 | 2158 | { |
f3b477be | 2159 | BFD_ASSERT (strcmp ((*orig_sym)->section->name, ".hppa_linker_stubs") |
e08b9ad7 JL |
2160 | == 0); |
2161 | rtn_adjust = false; | |
2162 | } | |
2163 | } | |
2164 | ||
2165 | /* Create the stub section if necessary. */ | |
e8f2240a KR |
2166 | if (!stub_sec) |
2167 | { | |
2168 | BFD_ASSERT (stub_desc == NULL); | |
e08b9ad7 | 2169 | hppa_elf_create_stub_sec (abfd, output_bfd, &stub_sec, link_info); |
4991ebb9 | 2170 | stub_desc = new_stub (abfd, stub_sec, link_info); |
e8f2240a KR |
2171 | } |
2172 | ||
4861ac76 | 2173 | /* Make the stub if we did not find one already. */ |
e8f2240a | 2174 | if (!stub_desc) |
4991ebb9 | 2175 | stub_desc = new_stub (abfd, stub_sec, link_info); |
e8f2240a | 2176 | |
4861ac76 | 2177 | /* Allocate space to write the stub. |
e08b9ad7 | 2178 | FIXME: Why using realloc?!? */ |
e8f2240a KR |
2179 | if (!stub_desc->stub_contents) |
2180 | { | |
2181 | stub_desc->allocated_size = STUB_BUFFER_INCR; | |
9783e04a | 2182 | stub_desc->stub_contents = (char *) malloc (STUB_BUFFER_INCR); |
e8f2240a KR |
2183 | } |
2184 | else if ((stub_desc->allocated_size - stub_desc->real_size) < STUB_MAX_SIZE) | |
2185 | { | |
2186 | stub_desc->allocated_size = stub_desc->allocated_size + STUB_BUFFER_INCR; | |
a5ccdad1 ILT |
2187 | stub_desc->stub_contents = (char *) realloc (stub_desc->stub_contents, |
2188 | stub_desc->allocated_size); | |
e8f2240a KR |
2189 | } |
2190 | ||
e08b9ad7 JL |
2191 | /* If no memory die. (I seriously doubt the other routines |
2192 | are prepared to get a NULL return value). */ | |
2193 | if (!stub_desc->stub_contents) | |
2194 | { | |
2195 | bfd_set_error (bfd_error_no_memory); | |
2196 | abort (); | |
2197 | } | |
2198 | ||
2199 | /* Generate an appropriate name for this stub. */ | |
2200 | if (linker_stub_type == HPPA_STUB_ARG_RELOC) | |
2201 | sprintf (stub_sym_name, | |
2202 | "_stub_%s_%02d_%02d_%02d_%02d_%02d_%s", | |
2203 | reloc_entry->sym_ptr_ptr[0]->name, | |
2204 | stub_types[0], stub_types[1], stub_types[2], | |
2205 | stub_types[3], stub_types[4], | |
2206 | rtn_adjust ? "RA" : ""); | |
2207 | else | |
2208 | sprintf (stub_sym_name, | |
2209 | "_lb_stub_%s_%s", reloc_entry->sym_ptr_ptr[0]->name, | |
2210 | rtn_adjust ? "RA" : ""); | |
2211 | ||
2212 | ||
4861ac76 JL |
2213 | stub_desc->stub_secp |
2214 | = (int *) (stub_desc->stub_contents + stub_desc->real_size); | |
4861ac76 | 2215 | stub_entry = find_stub_by_name (abfd, stub_sec, stub_sym_name); |
e8f2240a | 2216 | |
e08b9ad7 | 2217 | /* See if we already have one by this name. */ |
3a70b01d KR |
2218 | if (stub_entry) |
2219 | { | |
e08b9ad7 JL |
2220 | /* Yes, re-use it. Redirect the original relocation from the |
2221 | old symbol (a function symbol) to the stub (the stub will call | |
2222 | the original function). */ | |
3a70b01d | 2223 | stub_sym = stub_entry->sym; |
44fd6622 JL |
2224 | reloc_entry->sym_ptr_ptr = (asymbol **) bfd_zalloc (abfd, |
2225 | sizeof (asymbol **)); | |
6e58a4e5 JL |
2226 | if (reloc_entry->sym_ptr_ptr == NULL) |
2227 | { | |
2228 | bfd_set_error (bfd_error_no_memory); | |
2229 | abort (); | |
2230 | } | |
2231 | reloc_entry->sym_ptr_ptr[0] = stub_sym; | |
e08b9ad7 JL |
2232 | if (linker_stub_type == HPPA_STUB_LONG_CALL |
2233 | || (reloc_entry->howto->type != R_HPPA_PLABEL_32 | |
2234 | && (get_opcode(insn) == BLE | |
2235 | || get_opcode (insn) == BE | |
2236 | || get_opcode (insn) == BL))) | |
4861ac76 | 2237 | reloc_entry->howto = bfd_reloc_type_lookup (abfd, R_HPPA_STUB_CALL_17); |
3a70b01d KR |
2238 | } |
2239 | else | |
2240 | { | |
4861ac76 | 2241 | /* Create a new symbol to point to this stub. */ |
3a70b01d | 2242 | stub_sym = bfd_make_empty_symbol (abfd); |
9783e04a DM |
2243 | if (!stub_sym) |
2244 | { | |
f5bfdacd | 2245 | bfd_set_error (bfd_error_no_memory); |
e08b9ad7 | 2246 | abort (); |
9783e04a | 2247 | } |
3a70b01d | 2248 | stub_sym->name = bfd_zalloc (abfd, strlen (stub_sym_name) + 1); |
9783e04a DM |
2249 | if (!stub_sym->name) |
2250 | { | |
f5bfdacd | 2251 | bfd_set_error (bfd_error_no_memory); |
e08b9ad7 | 2252 | abort (); |
9783e04a | 2253 | } |
3a70b01d | 2254 | strcpy ((char *) stub_sym->name, stub_sym_name); |
4861ac76 | 2255 | stub_sym->value |
9783e04a | 2256 | = (char *) stub_desc->stub_secp - (char *) stub_desc->stub_contents; |
3a70b01d KR |
2257 | stub_sym->section = stub_sec; |
2258 | stub_sym->flags = BSF_LOCAL | BSF_FUNCTION; | |
4991ebb9 | 2259 | stub_entry = add_stub_by_name (abfd, stub_sec, stub_sym, link_info); |
3a70b01d | 2260 | |
4861ac76 | 2261 | /* Redirect the original relocation from the old symbol (a function) |
e08b9ad7 | 2262 | to the stub (the stub calls the function). */ |
44fd6622 JL |
2263 | reloc_entry->sym_ptr_ptr = (asymbol **) bfd_zalloc (abfd, |
2264 | sizeof (asymbol **)); | |
6e58a4e5 JL |
2265 | if (reloc_entry->sym_ptr_ptr == NULL) |
2266 | { | |
2267 | bfd_set_error (bfd_error_no_memory); | |
2268 | abort (); | |
2269 | } | |
2270 | reloc_entry->sym_ptr_ptr[0] = stub_sym; | |
e08b9ad7 JL |
2271 | if (linker_stub_type == HPPA_STUB_LONG_CALL |
2272 | || (reloc_entry->howto->type != R_HPPA_PLABEL_32 | |
2273 | && (get_opcode (insn) == BLE | |
2274 | || get_opcode (insn) == BE | |
2275 | || get_opcode (insn) == BL))) | |
4861ac76 | 2276 | reloc_entry->howto = bfd_reloc_type_lookup (abfd, R_HPPA_STUB_CALL_17); |
3a70b01d | 2277 | |
e08b9ad7 JL |
2278 | /* Now generate the code for the stub. Starting with two |
2279 | common instructions. | |
3a70b01d | 2280 | |
e08b9ad7 JL |
2281 | FIXME: Do we still need the SP adjustment? |
2282 | Do we still need to muck with space registers? */ | |
2283 | NEW_INSTRUCTION (stub_entry, LDSID_31_1) | |
2284 | NEW_INSTRUCTION (stub_entry, MTSP_1_SR0) | |
3a70b01d | 2285 | |
e08b9ad7 | 2286 | if (linker_stub_type == HPPA_STUB_ARG_RELOC) |
3a70b01d | 2287 | { |
e08b9ad7 | 2288 | NEW_INSTRUCTION (stub_entry, ADDI_8_SP) |
e8f2240a | 2289 | |
e08b9ad7 JL |
2290 | /* Examine each argument, generating code to relocate it |
2291 | into a different register if necessary. */ | |
2292 | for (i = ARG0; i < ARG3; i++) | |
2293 | { | |
2294 | switch (stub_types[i]) | |
2295 | { | |
4861ac76 | 2296 | |
e08b9ad7 JL |
2297 | case NO_ARG_RELOC: |
2298 | continue; | |
2299 | ||
2300 | case R_TO_FR: | |
2301 | switch (i) | |
2302 | { | |
2303 | case ARG0: | |
2304 | NEW_INSTRUCTION (stub_entry, STWS_ARG0_M8SP) | |
2305 | NEW_INSTRUCTION (stub_entry, FLDWS_M8SP_FARG0) | |
2306 | break; | |
2307 | case ARG1: | |
2308 | NEW_INSTRUCTION (stub_entry, STWS_ARG1_M8SP) | |
2309 | NEW_INSTRUCTION (stub_entry, FLDWS_M8SP_FARG1) | |
2310 | break; | |
2311 | case ARG2: | |
2312 | NEW_INSTRUCTION (stub_entry, STWS_ARG2_M8SP) | |
2313 | NEW_INSTRUCTION (stub_entry, FLDWS_M8SP_FARG2) | |
2314 | break; | |
2315 | case ARG3: | |
2316 | NEW_INSTRUCTION (stub_entry, STWS_ARG3_M8SP) | |
2317 | NEW_INSTRUCTION (stub_entry, FLDWS_M8SP_FARG3) | |
2318 | break; | |
2319 | } | |
2320 | continue; | |
2321 | ||
2322 | case R01_TO_FR: | |
2323 | switch (i) | |
2324 | { | |
2325 | case ARG0: | |
2326 | NEW_INSTRUCTION (stub_entry, STWS_ARG0_M4SP) | |
2327 | NEW_INSTRUCTION (stub_entry, STWS_ARG1_M8SP) | |
2328 | NEW_INSTRUCTION (stub_entry, FLDDS_M8SP_FARG1) | |
2329 | break; | |
2330 | default: | |
2331 | abort (); | |
2332 | break; | |
2333 | } | |
2334 | continue; | |
2335 | ||
2336 | case R23_TO_FR: | |
2337 | switch (i) | |
2338 | { | |
2339 | case ARG2: | |
2340 | NEW_INSTRUCTION (stub_entry, STWS_ARG2_M4SP) | |
2341 | NEW_INSTRUCTION (stub_entry, STWS_ARG3_M8SP) | |
2342 | NEW_INSTRUCTION (stub_entry, FLDDS_M8SP_FARG3) | |
2343 | break; | |
2344 | default: | |
2345 | abort (); | |
2346 | break; | |
2347 | } | |
2348 | continue; | |
2349 | ||
2350 | case FR_TO_R: | |
2351 | switch (i) | |
2352 | { | |
2353 | case ARG0: | |
2354 | NEW_INSTRUCTION (stub_entry, FSTWS_FARG0_M8SP) | |
2355 | NEW_INSTRUCTION (stub_entry, LDWS_M4SP_ARG0) | |
2356 | break; | |
2357 | case ARG1: | |
2358 | NEW_INSTRUCTION (stub_entry, FSTWS_FARG1_M8SP) | |
2359 | NEW_INSTRUCTION (stub_entry, LDWS_M4SP_ARG1) | |
2360 | break; | |
2361 | case ARG2: | |
2362 | NEW_INSTRUCTION (stub_entry, FSTWS_FARG2_M8SP) | |
2363 | NEW_INSTRUCTION (stub_entry, LDWS_M4SP_ARG2) | |
2364 | break; | |
2365 | case ARG3: | |
2366 | NEW_INSTRUCTION (stub_entry, FSTWS_FARG3_M8SP) | |
2367 | NEW_INSTRUCTION (stub_entry, LDWS_M4SP_ARG3) | |
2368 | break; | |
2369 | } | |
2370 | continue; | |
2371 | ||
2372 | case FR_TO_R01: | |
2373 | switch (i) | |
2374 | { | |
2375 | case ARG0: | |
2376 | NEW_INSTRUCTION (stub_entry, FSTDS_FARG1_M8SP) | |
2377 | NEW_INSTRUCTION (stub_entry, LDWS_M4SP_ARG0) | |
2378 | NEW_INSTRUCTION (stub_entry, LDWS_M8SP_ARG1) | |
2379 | break; | |
2380 | default: | |
2381 | abort (); | |
2382 | break; | |
2383 | } | |
2384 | continue; | |
2385 | ||
2386 | case FR_TO_R23: | |
2387 | switch (i) | |
2388 | { | |
2389 | case ARG2: | |
2390 | NEW_INSTRUCTION (stub_entry, FSTDS_FARG3_M8SP) | |
2391 | NEW_INSTRUCTION (stub_entry, LDWS_M4SP_ARG2) | |
2392 | NEW_INSTRUCTION (stub_entry, LDWS_M8SP_ARG3) | |
2393 | break; | |
2394 | default: | |
2395 | abort (); | |
2396 | break; | |
2397 | } | |
2398 | continue; | |
2399 | ||
2400 | default: | |
2401 | abort (); | |
2402 | break; | |
2403 | } | |
2404 | } | |
2405 | ||
2406 | /* Put the stack pointer back. FIXME: Is this still necessary? */ | |
2407 | NEW_INSTRUCTION (stub_entry, ADDI_M8_SP_SP) | |
2408 | } | |
2409 | ||
2410 | /* Common code again. Return pointer adjustment and the like. */ | |
2411 | if (!dyncall) | |
4861ac76 | 2412 | { |
e08b9ad7 JL |
2413 | /* This isn't dyncall. */ |
2414 | if (!milli) | |
2415 | { | |
2416 | /* It's not a millicode call, so get the correct return | |
2417 | value into %r2 (aka RP). */ | |
2418 | if (rtn_adjust) | |
2419 | NEW_INSTRUCTION (stub_entry, ADDI_M4_31_RP) | |
2420 | else | |
2421 | NEW_INSTRUCTION (stub_entry, COPY_31_2) | |
2422 | } | |
2423 | else | |
2424 | { | |
2425 | /* It is a millicode call, so get the correct return | |
2426 | value into %r1?!?. FIXME: Shouldn't this be | |
2427 | %r31? Yes, and a little re-arrangement of the | |
2428 | code below would make that possible. */ | |
2429 | if (rtn_adjust) | |
2430 | NEW_INSTRUCTION (stub_entry, ADDI_M4_31_1) | |
2431 | else | |
2432 | NEW_INSTRUCTION (stub_entry, COPY_31_1) | |
2433 | } | |
4861ac76 | 2434 | } |
4991ebb9 | 2435 | else |
e08b9ad7 JL |
2436 | { |
2437 | /* This is dyncall, so the code is a little different as the | |
2438 | return pointer is already in %r2 (aka RP). */ | |
2439 | if (rtn_adjust) | |
2440 | NEW_INSTRUCTION (stub_entry, ADDI_M4_31_RP) | |
2441 | } | |
e8f2240a | 2442 | |
4861ac76 | 2443 | /* Save the return address. */ |
e08b9ad7 JL |
2444 | if (linker_stub_type == HPPA_STUB_ARG_RELOC) |
2445 | NEW_INSTRUCTION (stub_entry, STW_RP_M8SP) | |
e8f2240a | 2446 | |
4861ac76 | 2447 | /* Long branch to the target function. */ |
e08b9ad7 | 2448 | NEW_INSTRUCTION (stub_entry, LDIL_XXX_31) |
3a70b01d | 2449 | hppa_elf_stub_reloc (stub_entry->stub_desc, |
f3b477be | 2450 | abfd, orig_sym, |
4861ac76 | 2451 | CURRENT_STUB_OFFSET (stub_entry), |
3a70b01d | 2452 | R_HPPA_L21); |
e08b9ad7 | 2453 | NEW_INSTRUCTION (stub_entry, BLE_XXX_0_31) |
3a70b01d | 2454 | hppa_elf_stub_reloc (stub_entry->stub_desc, |
f3b477be | 2455 | abfd, orig_sym, |
4861ac76 | 2456 | CURRENT_STUB_OFFSET (stub_entry), |
3a70b01d | 2457 | R_HPPA_ABS_CALL_R17); |
4861ac76 | 2458 | |
e08b9ad7 JL |
2459 | if (linker_stub_type == HPPA_STUB_ARG_RELOC) |
2460 | { | |
2461 | /* In delay slot of long-call, copy %r31 into %r2 so that | |
2462 | the callee can return in the normal fashion. */ | |
2463 | NEW_INSTRUCTION (stub_entry, COPY_31_2) | |
2464 | ||
2465 | /* Restore the return address. */ | |
2466 | NEW_INSTRUCTION (stub_entry, LDW_M8SP_RP) | |
3a70b01d | 2467 | |
e08b9ad7 JL |
2468 | /* Generate the code to move the return value around. */ |
2469 | switch (stub_types[RETVAL]) | |
2470 | { | |
2471 | case NO_ARG_RELOC: | |
2472 | break; | |
2473 | ||
2474 | case R_TO_FR: | |
2475 | NEW_INSTRUCTION (stub_entry, STWS_RET0_M8SP) | |
2476 | NEW_INSTRUCTION (stub_entry, FLDWS_M8SP_FRET0) | |
2477 | break; | |
2478 | ||
2479 | case FR_TO_R: | |
2480 | NEW_INSTRUCTION (stub_entry, FSTWS_FRET0_M8SP) | |
2481 | NEW_INSTRUCTION (stub_entry, LDWS_M4SP_RET0) | |
2482 | break; | |
2483 | ||
2484 | default: | |
2485 | abort (); | |
2486 | break; | |
2487 | } | |
2488 | ||
2489 | /* Return back to the main code stream. */ | |
2490 | NEW_INSTRUCTION (stub_entry, BV_N_0_RP) | |
2491 | } | |
2492 | else | |
e8f2240a | 2493 | { |
e08b9ad7 | 2494 | if (!dyncall) |
e8f2240a | 2495 | { |
e08b9ad7 JL |
2496 | /* Get return address into %r31. Both variants may be necessary |
2497 | (I think) as we could be cascading into another stub. */ | |
2498 | if (!milli) | |
2499 | NEW_INSTRUCTION (stub_entry, COPY_2_31) | |
2500 | else | |
2501 | NEW_INSTRUCTION (stub_entry, COPY_1_31) | |
2502 | } | |
2503 | else | |
2504 | { | |
2505 | /* Get the return address into %r31 too. Might be necessary | |
2506 | (I think) as we could be cascading into another stub. */ | |
2507 | NEW_INSTRUCTION (stub_entry, COPY_2_31) | |
e8f2240a | 2508 | } |
e08b9ad7 JL |
2509 | |
2510 | /* No need for a return to the main stream. */ | |
e8f2240a KR |
2511 | } |
2512 | } | |
e8f2240a KR |
2513 | return stub_sym; |
2514 | } | |
2515 | ||
e08b9ad7 JL |
2516 | /* Return nonzero if an argument relocation will be needed to call |
2517 | the function (symbol in RELOC_ENTRY) assuming the caller has | |
2518 | argument relocation bugs CALLER_AR. */ | |
2519 | ||
2520 | static int | |
3a70b01d | 2521 | hppa_elf_arg_reloc_needed_p (abfd, reloc_entry, stub_types, caller_ar) |
e8f2240a KR |
2522 | bfd *abfd; |
2523 | arelent *reloc_entry; | |
e08b9ad7 | 2524 | arg_reloc_type stub_types[5]; |
3a70b01d | 2525 | symext_entryS caller_ar; |
e8f2240a | 2526 | { |
e08b9ad7 JL |
2527 | /* If the symbol is still undefined, then it's impossible to know |
2528 | if an argument relocation is needed. */ | |
2529 | if (reloc_entry->sym_ptr_ptr[0] | |
2530 | && reloc_entry->sym_ptr_ptr[0]->section != &bfd_und_section) | |
e8f2240a | 2531 | { |
e8f2240a KR |
2532 | symext_entryS callee_ar = elf32_hppa_get_sym_extn (abfd, |
2533 | reloc_entry->sym_ptr_ptr[0], | |
2534 | HPPA_SXT_ARG_RELOC); | |
2535 | ||
e08b9ad7 JL |
2536 | /* Now examine all the argument and return value location |
2537 | information to determine if a relocation stub will be needed. */ | |
e8f2240a KR |
2538 | if (caller_ar && callee_ar) |
2539 | { | |
e08b9ad7 JL |
2540 | arg_location caller_loc[5]; |
2541 | arg_location callee_loc[5]; | |
e8f2240a | 2542 | |
e08b9ad7 JL |
2543 | /* Extract the location information for the return value |
2544 | and argument registers separately. */ | |
e8f2240a KR |
2545 | callee_loc[RETVAL] = EXTRACT_ARBITS (callee_ar, RETVAL); |
2546 | caller_loc[RETVAL] = EXTRACT_ARBITS (caller_ar, RETVAL); | |
2547 | callee_loc[ARG0] = EXTRACT_ARBITS (callee_ar, ARG0); | |
2548 | caller_loc[ARG0] = EXTRACT_ARBITS (caller_ar, ARG0); | |
2549 | callee_loc[ARG1] = EXTRACT_ARBITS (callee_ar, ARG1); | |
2550 | caller_loc[ARG1] = EXTRACT_ARBITS (caller_ar, ARG1); | |
2551 | callee_loc[ARG2] = EXTRACT_ARBITS (callee_ar, ARG2); | |
2552 | caller_loc[ARG2] = EXTRACT_ARBITS (caller_ar, ARG2); | |
2553 | callee_loc[ARG3] = EXTRACT_ARBITS (callee_ar, ARG3); | |
2554 | caller_loc[ARG3] = EXTRACT_ARBITS (caller_ar, ARG3); | |
2555 | ||
e08b9ad7 JL |
2556 | /* Check some special combinations. For example, if FU |
2557 | appears in ARG1 or ARG3, we can move it to ARG0 or ARG2, | |
2558 | respectively. (I guess this braindamage is correct? It'd | |
2559 | take an hour or two of reading PA calling conventions to | |
2560 | really know). */ | |
e8f2240a KR |
2561 | |
2562 | if (caller_loc[ARG0] == AR_FU || caller_loc[ARG1] == AR_FU) | |
2563 | { | |
d9ad93bc | 2564 | caller_loc[ARG0] = AR_DBL01; |
e8f2240a KR |
2565 | caller_loc[ARG1] = AR_NO; |
2566 | } | |
2567 | if (caller_loc[ARG2] == AR_FU || caller_loc[ARG3] == AR_FU) | |
2568 | { | |
d9ad93bc | 2569 | caller_loc[ARG2] = AR_DBL23; |
e8f2240a KR |
2570 | caller_loc[ARG3] = AR_NO; |
2571 | } | |
2572 | if (callee_loc[ARG0] == AR_FU || callee_loc[ARG1] == AR_FU) | |
2573 | { | |
d9ad93bc | 2574 | callee_loc[ARG0] = AR_DBL01; |
e8f2240a KR |
2575 | callee_loc[ARG1] = AR_NO; |
2576 | } | |
2577 | if (callee_loc[ARG2] == AR_FU || callee_loc[ARG3] == AR_FU) | |
2578 | { | |
d9ad93bc | 2579 | callee_loc[ARG2] = AR_DBL23; |
e8f2240a KR |
2580 | callee_loc[ARG3] = AR_NO; |
2581 | } | |
2582 | ||
e08b9ad7 JL |
2583 | /* Now look up potential mismatches. */ |
2584 | stub_types[ARG0] = type_of_mismatch (caller_loc[ARG0], | |
2585 | callee_loc[ARG0], | |
2586 | ARGUMENTS); | |
2587 | stub_types[ARG1] = type_of_mismatch (caller_loc[ARG1], | |
2588 | callee_loc[ARG1], | |
2589 | ARGUMENTS); | |
2590 | stub_types[ARG2] = type_of_mismatch (caller_loc[ARG2], | |
2591 | callee_loc[ARG2], | |
2592 | ARGUMENTS); | |
2593 | stub_types[ARG3] = type_of_mismatch (caller_loc[ARG3], | |
2594 | callee_loc[ARG3], | |
2595 | ARGUMENTS); | |
2596 | stub_types[RETVAL] = type_of_mismatch (caller_loc[RETVAL], | |
2597 | callee_loc[RETVAL], | |
2598 | RETURN_VALUE); | |
2599 | ||
2600 | /* If any of the arguments or return value need an argument | |
2601 | relocation, then we will need an argument relocation stub. */ | |
2602 | if (stub_types[ARG0] != NO_ARG_RELOC | |
2603 | || stub_types[ARG1] != NO_ARG_RELOC | |
2604 | || stub_types[ARG2] != NO_ARG_RELOC | |
2605 | || stub_types[ARG3] != NO_ARG_RELOC | |
2606 | || stub_types[RETVAL] != NO_ARG_RELOC) | |
2607 | return 1; | |
e8f2240a KR |
2608 | } |
2609 | } | |
2610 | return 0; | |
2611 | } | |
2612 | ||
e08b9ad7 JL |
2613 | /* Create the linker stub section. */ |
2614 | ||
2615 | static void | |
2616 | hppa_elf_create_stub_sec (abfd, output_bfd, secptr, link_info) | |
d9ad93bc KR |
2617 | bfd *abfd; |
2618 | bfd *output_bfd; | |
e08b9ad7 | 2619 | asection **secptr; |
4991ebb9 | 2620 | struct bfd_link_info *link_info; |
d9ad93bc | 2621 | { |
e08b9ad7 JL |
2622 | asection *output_text_section; |
2623 | ||
2624 | output_text_section = bfd_get_section_by_name (output_bfd, ".text"); | |
2625 | *secptr = bfd_make_section (abfd, ".hppa_linker_stubs"); | |
2626 | bfd_set_section_flags (abfd, *secptr, | |
2627 | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | |
2628 | | SEC_RELOC | SEC_CODE | SEC_READONLY); | |
2629 | (*secptr)->output_section = output_text_section->output_section; | |
2630 | (*secptr)->output_offset = 0; | |
2631 | ||
2632 | /* Set up the ELF section header for this new section. This | |
2633 | is basically the same processing as elf_make_sections(). | |
2634 | elf_make_sections is static and therefore not accessable | |
2635 | here. */ | |
2636 | { | |
2637 | Elf_Internal_Shdr *this_hdr; | |
2638 | this_hdr = &elf_section_data ((*secptr))->this_hdr; | |
2639 | ||
2640 | /* Set the sizes of this section. The contents have already | |
2641 | been set up ?!? */ | |
2642 | this_hdr->sh_addr = (*secptr)->vma; | |
2643 | this_hdr->sh_size = (*secptr)->_raw_size; | |
2644 | ||
2645 | /* Set appropriate flags for sections with relocations. */ | |
2646 | if ((*secptr)->flags & SEC_RELOC) | |
d9ad93bc | 2647 | { |
e08b9ad7 JL |
2648 | Elf_Internal_Shdr *rela_hdr; |
2649 | int use_rela_p = get_elf_backend_data (abfd)->use_rela_p; | |
4861ac76 | 2650 | |
e08b9ad7 | 2651 | rela_hdr = &elf_section_data ((*secptr))->rel_hdr; |
4861ac76 | 2652 | |
e08b9ad7 | 2653 | if (use_rela_p) |
d9ad93bc | 2654 | { |
e08b9ad7 JL |
2655 | rela_hdr->sh_type = SHT_RELA; |
2656 | rela_hdr->sh_entsize = sizeof (Elf32_External_Rela); | |
d9ad93bc | 2657 | } |
e08b9ad7 | 2658 | else |
d9ad93bc | 2659 | { |
e08b9ad7 JL |
2660 | rela_hdr->sh_type = SHT_REL; |
2661 | rela_hdr->sh_entsize = sizeof (Elf32_External_Rel); | |
d9ad93bc | 2662 | } |
e08b9ad7 JL |
2663 | rela_hdr->sh_flags = 0; |
2664 | rela_hdr->sh_addr = 0; | |
2665 | rela_hdr->sh_offset = 0; | |
2666 | rela_hdr->sh_addralign = 0; | |
2667 | rela_hdr->size = 0; | |
d9ad93bc | 2668 | } |
4861ac76 | 2669 | |
e08b9ad7 JL |
2670 | if ((*secptr)->flags & SEC_ALLOC) |
2671 | this_hdr->sh_flags |= SHF_ALLOC; | |
2672 | ||
2673 | if (!((*secptr)->flags & SEC_READONLY)) | |
2674 | this_hdr->sh_flags |= SHF_WRITE; | |
2675 | ||
2676 | if ((*secptr)->flags & SEC_CODE) | |
2677 | this_hdr->sh_flags |= SHF_EXECINSTR; | |
4861ac76 JL |
2678 | } |
2679 | ||
e08b9ad7 | 2680 | bfd_set_section_alignment (abfd, *secptr, 2); |
d9ad93bc KR |
2681 | } |
2682 | ||
e08b9ad7 JL |
2683 | /* Return nonzero if a long-call stub will be needed to call the |
2684 | function (symbol in RELOC_ENTRY). */ | |
2685 | ||
2686 | static int | |
d9ad93bc KR |
2687 | hppa_elf_long_branch_needed_p (abfd, asec, reloc_entry, symbol, insn) |
2688 | bfd *abfd; | |
2689 | asection *asec; | |
2690 | arelent *reloc_entry; | |
2691 | asymbol *symbol; | |
2692 | unsigned insn; | |
2693 | { | |
e08b9ad7 | 2694 | long sym_value = get_symbol_value (symbol); |
d9ad93bc | 2695 | int fmt = reloc_entry->howto->bitsize; |
e08b9ad7 | 2696 | unsigned char op = get_opcode (insn); |
d9ad93bc KR |
2697 | unsigned raddr; |
2698 | ||
e08b9ad7 JL |
2699 | #define too_far(val,num_bits) \ |
2700 | ((int)(val) > (1 << (num_bits)) - 1) || ((int)(val) < (-1 << (num_bits))) | |
d9ad93bc | 2701 | |
d9ad93bc KR |
2702 | switch (op) |
2703 | { | |
2704 | case BL: | |
2705 | raddr = | |
2706 | reloc_entry->address + asec->output_offset + asec->output_section->vma; | |
e08b9ad7 JL |
2707 | /* If the symbol and raddr (relocated addr?) are too far away from |
2708 | each other, then a long-call stub will be needed. */ | |
2709 | if (too_far (sym_value - raddr, fmt + 1)) | |
d9ad93bc | 2710 | return 1; |
d9ad93bc KR |
2711 | break; |
2712 | } | |
2713 | return 0; | |
2714 | } | |
2715 | ||
e08b9ad7 JL |
2716 | /* Search the given section and determine if linker stubs will be |
2717 | needed for any calls within that section. | |
2718 | ||
2719 | Return any new stub symbols created. | |
e8f2240a | 2720 | |
e08b9ad7 JL |
2721 | Used out of hppaelf.em in the linker. */ |
2722 | ||
e8f2240a | 2723 | asymbol * |
4861ac76 | 2724 | hppa_look_for_stubs_in_section (stub_bfd, abfd, output_bfd, asec, |
6e58a4e5 | 2725 | new_sym_cnt, link_info) |
d9ad93bc | 2726 | bfd *stub_bfd; |
e8f2240a KR |
2727 | bfd *abfd; |
2728 | bfd *output_bfd; | |
2729 | asection *asec; | |
e8f2240a | 2730 | int *new_sym_cnt; |
4991ebb9 | 2731 | struct bfd_link_info *link_info; |
e8f2240a KR |
2732 | { |
2733 | int i; | |
e08b9ad7 JL |
2734 | arg_reloc_type stub_types[5]; |
2735 | asymbol *new_syms = NULL; | |
e8f2240a KR |
2736 | int new_cnt = 0; |
2737 | int new_max = 0; | |
80425e6c | 2738 | arelent **reloc_vector = NULL; |
e8f2240a | 2739 | |
3a70b01d KR |
2740 | /* Relocations are in different places depending on whether this is |
2741 | an output section or an input section. Also, the relocations are | |
e08b9ad7 JL |
2742 | in different forms. Sigh. Luckily, we have bfd_canonicalize_reloc() |
2743 | to straighten this out for us . */ | |
e8f2240a KR |
2744 | if (asec->reloc_count > 0) |
2745 | { | |
80425e6c JK |
2746 | reloc_vector |
2747 | = (arelent **) malloc (asec->reloc_count * (sizeof (arelent *) + 1)); | |
2748 | if (reloc_vector == NULL) | |
2749 | { | |
2750 | bfd_set_error (bfd_error_no_memory); | |
2751 | goto error_return; | |
2752 | } | |
e8f2240a | 2753 | |
6e58a4e5 JL |
2754 | /* Make sure the canonical symbols are hanging around in a convient |
2755 | location. */ | |
2756 | if (bfd_get_outsymbols (abfd) == NULL) | |
2757 | { | |
326e32d7 ILT |
2758 | long symsize; |
2759 | long symcount; | |
6e58a4e5 | 2760 | |
326e32d7 ILT |
2761 | symsize = bfd_get_symtab_upper_bound (abfd); |
2762 | if (symsize < 0) | |
2763 | goto error_return; | |
6e58a4e5 | 2764 | abfd->outsymbols = (asymbol **) bfd_alloc (abfd, symsize); |
326e32d7 | 2765 | if (!abfd->outsymbols && symsize != 0) |
6e58a4e5 JL |
2766 | { |
2767 | bfd_set_error (bfd_error_no_memory); | |
80425e6c | 2768 | goto error_return; |
6e58a4e5 | 2769 | } |
326e32d7 ILT |
2770 | symcount = bfd_canonicalize_symtab (abfd, abfd->outsymbols); |
2771 | if (symcount < 0) | |
2772 | goto error_return; | |
2773 | abfd->symcount = symcount; | |
6e58a4e5 JL |
2774 | } |
2775 | ||
2776 | /* Now get the relocations. */ | |
326e32d7 ILT |
2777 | if (bfd_canonicalize_reloc (abfd, asec, reloc_vector, |
2778 | bfd_get_outsymbols (abfd)) < 0) | |
2779 | goto error_return; | |
e08b9ad7 JL |
2780 | |
2781 | /* Examine each relocation entry in this section. */ | |
e8f2240a KR |
2782 | for (i = 0; i < asec->reloc_count; i++) |
2783 | { | |
e8f2240a KR |
2784 | arelent *rle = reloc_vector[i]; |
2785 | ||
2786 | switch (rle->howto->type) | |
2787 | { | |
e08b9ad7 JL |
2788 | /* Any call could need argument relocation stubs, and |
2789 | some may need long-call stubs. */ | |
4861ac76 JL |
2790 | case R_HPPA_ABS_CALL_11: |
2791 | case R_HPPA_ABS_CALL_14: | |
2792 | case R_HPPA_ABS_CALL_17: | |
2793 | case R_HPPA_ABS_CALL_L21: | |
2794 | case R_HPPA_ABS_CALL_R11: | |
2795 | case R_HPPA_ABS_CALL_R14: | |
2796 | case R_HPPA_ABS_CALL_R17: | |
2797 | case R_HPPA_ABS_CALL_LS21: | |
2798 | case R_HPPA_ABS_CALL_RS11: | |
2799 | case R_HPPA_ABS_CALL_RS14: | |
2800 | case R_HPPA_ABS_CALL_RS17: | |
2801 | case R_HPPA_ABS_CALL_LD21: | |
2802 | case R_HPPA_ABS_CALL_RD11: | |
2803 | case R_HPPA_ABS_CALL_RD14: | |
2804 | case R_HPPA_ABS_CALL_RD17: | |
2805 | case R_HPPA_ABS_CALL_LR21: | |
2806 | case R_HPPA_ABS_CALL_RR14: | |
2807 | case R_HPPA_ABS_CALL_RR17: | |
2808 | case R_HPPA_PCREL_CALL_11: | |
2809 | case R_HPPA_PCREL_CALL_14: | |
2810 | case R_HPPA_PCREL_CALL_17: | |
2811 | case R_HPPA_PCREL_CALL_12: | |
2812 | case R_HPPA_PCREL_CALL_L21: | |
2813 | case R_HPPA_PCREL_CALL_R11: | |
2814 | case R_HPPA_PCREL_CALL_R14: | |
2815 | case R_HPPA_PCREL_CALL_R17: | |
2816 | case R_HPPA_PCREL_CALL_LS21: | |
2817 | case R_HPPA_PCREL_CALL_RS11: | |
2818 | case R_HPPA_PCREL_CALL_RS14: | |
2819 | case R_HPPA_PCREL_CALL_RS17: | |
2820 | case R_HPPA_PCREL_CALL_LD21: | |
2821 | case R_HPPA_PCREL_CALL_RD11: | |
2822 | case R_HPPA_PCREL_CALL_RD14: | |
2823 | case R_HPPA_PCREL_CALL_RD17: | |
2824 | case R_HPPA_PCREL_CALL_LR21: | |
2825 | case R_HPPA_PCREL_CALL_RR14: | |
2826 | case R_HPPA_PCREL_CALL_RR17: | |
3a70b01d | 2827 | { |
4861ac76 JL |
2828 | symext_entryS caller_ar |
2829 | = (symext_entryS) HPPA_R_ARG_RELOC (rle->addend); | |
2830 | unsigned insn[2]; | |
2831 | ||
e08b9ad7 | 2832 | /* We'll need this for the long-call checks. */ |
4861ac76 JL |
2833 | bfd_get_section_contents (abfd, asec, insn, rle->address, |
2834 | sizeof(insn)); | |
e08b9ad7 JL |
2835 | |
2836 | /* See if this call needs an argument relocation stub. */ | |
3a70b01d KR |
2837 | if (hppa_elf_arg_reloc_needed_p (abfd, rle, stub_types, |
2838 | caller_ar)) | |
2839 | { | |
4861ac76 | 2840 | /* Generate a stub and keep track of the new symbol. */ |
3a70b01d | 2841 | asymbol *r; |
d9ad93bc | 2842 | |
3a70b01d KR |
2843 | if (new_cnt == new_max) |
2844 | { | |
2845 | new_max += STUB_SYM_BUFFER_INC; | |
4861ac76 JL |
2846 | new_syms = (asymbol *) |
2847 | realloc (new_syms, new_max * sizeof (asymbol)); | |
e08b9ad7 | 2848 | if (new_syms == NULL) |
80425e6c JK |
2849 | { |
2850 | bfd_set_error (bfd_error_no_memory); | |
2851 | goto error_return; | |
2852 | } | |
3a70b01d | 2853 | } |
4861ac76 | 2854 | |
e08b9ad7 JL |
2855 | /* Build the argument relocation stub. */ |
2856 | r = hppa_elf_build_linker_stub (stub_bfd, output_bfd, | |
2857 | link_info, rle, | |
2858 | stub_types, true, insn, | |
2859 | HPPA_STUB_ARG_RELOC); | |
3a70b01d KR |
2860 | new_syms[new_cnt++] = *r; |
2861 | } | |
d9ad93bc | 2862 | |
e08b9ad7 | 2863 | /* See if this call needs a long-call stub. */ |
4861ac76 JL |
2864 | if (hppa_elf_long_branch_needed_p (abfd, asec, rle, |
2865 | rle->sym_ptr_ptr[0], | |
2866 | insn[0])) | |
2867 | { | |
2868 | /* Generate a stub and keep track of the new symbol. */ | |
2869 | asymbol *r; | |
3a70b01d | 2870 | |
4861ac76 JL |
2871 | if (new_cnt == new_max) |
2872 | { | |
2873 | new_max += STUB_SYM_BUFFER_INC; | |
2874 | new_syms = (asymbol *) | |
2875 | realloc (new_syms, (new_max * sizeof (asymbol))); | |
e08b9ad7 | 2876 | if (! new_syms) |
80425e6c JK |
2877 | { |
2878 | bfd_set_error (bfd_error_no_memory); | |
2879 | goto error_return; | |
2880 | } | |
4861ac76 | 2881 | } |
e08b9ad7 JL |
2882 | |
2883 | /* Build the long-call stub. */ | |
2884 | r = hppa_elf_build_linker_stub (stub_bfd, output_bfd, | |
2885 | link_info, rle, | |
2886 | NULL, true, insn, | |
2887 | HPPA_STUB_LONG_CALL); | |
4861ac76 JL |
2888 | new_syms[new_cnt++] = *r; |
2889 | } | |
3a70b01d KR |
2890 | } |
2891 | break; | |
2892 | ||
e08b9ad7 | 2893 | /* PLABELs may need argument relocation stubs. */ |
4861ac76 JL |
2894 | case R_HPPA_PLABEL_32: |
2895 | case R_HPPA_PLABEL_11: | |
2896 | case R_HPPA_PLABEL_14: | |
2897 | case R_HPPA_PLABEL_L21: | |
2898 | case R_HPPA_PLABEL_R11: | |
2899 | case R_HPPA_PLABEL_R14: | |
d9ad93bc | 2900 | { |
3a70b01d | 2901 | /* On a plabel relocation, assume the arguments of the |
e08b9ad7 JL |
2902 | caller are set up in general registers (indirect |
2903 | calls only use general registers. | |
2904 | NOTE: 0x155 = ARGW0=GR,ARGW1=GR,ARGW2=GR,RETVAL=GR. */ | |
3a70b01d | 2905 | symext_entryS caller_ar = (symext_entryS) 0x155; |
4861ac76 JL |
2906 | unsigned insn[2]; |
2907 | ||
e08b9ad7 | 2908 | /* Do we really need this? */ |
4861ac76 JL |
2909 | bfd_get_section_contents (abfd, asec, insn, rle->address, |
2910 | sizeof(insn)); | |
d9ad93bc | 2911 | |
e08b9ad7 | 2912 | /* See if this call needs an argument relocation stub. */ |
3a70b01d KR |
2913 | if (hppa_elf_arg_reloc_needed_p (abfd, rle, stub_types, |
2914 | caller_ar)) | |
d9ad93bc | 2915 | { |
4861ac76 JL |
2916 | /* Generate a plabel stub and keep track of the |
2917 | new symbol. */ | |
d9ad93bc | 2918 | asymbol *r; |
4861ac76 | 2919 | int rtn_adjust; |
d9ad93bc KR |
2920 | |
2921 | if (new_cnt == new_max) | |
2922 | { | |
2923 | new_max += STUB_SYM_BUFFER_INC; | |
4861ac76 JL |
2924 | new_syms = (asymbol *) realloc (new_syms, new_max |
2925 | * sizeof (asymbol)); | |
d9ad93bc | 2926 | } |
4861ac76 JL |
2927 | |
2928 | /* Determine whether a return adjustment | |
2929 | (see the relocation code for relocation type | |
2930 | R_HPPA_STUB_CALL_17) is possible. Basically, | |
2931 | determine whether we are looking at a branch or not. */ | |
4861ac76 JL |
2932 | if (rle->howto->type == R_HPPA_PLABEL_32) |
2933 | rtn_adjust = false; | |
2934 | else | |
2935 | { | |
2936 | switch (get_opcode(insn[0])) | |
2937 | { | |
2938 | case BLE: | |
2939 | case BE: | |
2940 | rtn_adjust = true; | |
2941 | break; | |
2942 | default: | |
2943 | rtn_adjust = false; | |
2944 | } | |
2945 | } | |
e08b9ad7 JL |
2946 | |
2947 | /* Build the argument relocation stub. */ | |
2948 | r = hppa_elf_build_linker_stub (stub_bfd, output_bfd, | |
2949 | link_info, rle, stub_types, | |
2950 | rtn_adjust, insn, | |
2951 | HPPA_STUB_ARG_RELOC); | |
d9ad93bc KR |
2952 | new_syms[new_cnt++] = *r; |
2953 | } | |
2954 | } | |
e8f2240a | 2955 | break; |
4c85cbfa | 2956 | |
e8f2240a KR |
2957 | default: |
2958 | break; | |
e8f2240a KR |
2959 | } |
2960 | } | |
2961 | } | |
e08b9ad7 | 2962 | |
80425e6c JK |
2963 | if (reloc_vector != NULL) |
2964 | free (reloc_vector); | |
e08b9ad7 | 2965 | /* Return the new symbols and update the counters. */ |
e8f2240a KR |
2966 | *new_sym_cnt = new_cnt; |
2967 | return new_syms; | |
80425e6c JK |
2968 | |
2969 | error_return: | |
2970 | if (reloc_vector != NULL) | |
2971 | free (reloc_vector); | |
2972 | /* FIXME: This is bogus. We should be returning NULL. But do the callers | |
2973 | check for that? */ | |
2974 | abort (); | |
4c85cbfa KR |
2975 | } |
2976 | ||
e08b9ad7 | 2977 | /* Set the contents of a particular section at a particular location. */ |
d9ad93bc | 2978 | |
e08b9ad7 | 2979 | static boolean |
f4bd7a8f DM |
2980 | hppa_elf_set_section_contents (abfd, section, location, offset, count) |
2981 | bfd *abfd; | |
2982 | sec_ptr section; | |
2983 | PTR location; | |
2984 | file_ptr offset; | |
2985 | bfd_size_type count; | |
4c85cbfa | 2986 | { |
e08b9ad7 JL |
2987 | /* Linker stubs are handled a little differently. */ |
2988 | if (! strcmp (section->name, ".hppa_linker_stubs")) | |
d9ad93bc | 2989 | { |
f5bfdacd | 2990 | if (linker_stubs_max_size < offset + count) |
d9ad93bc KR |
2991 | { |
2992 | linker_stubs_max_size = offset + count + STUB_ALLOC_INCR; | |
e08b9ad7 JL |
2993 | linker_stubs = (char *)realloc (linker_stubs, linker_stubs_max_size); |
2994 | if (! linker_stubs) | |
2995 | abort (); | |
d9ad93bc KR |
2996 | } |
2997 | ||
f5bfdacd | 2998 | if (offset + count > linker_stubs_size) |
d9ad93bc KR |
2999 | linker_stubs_size = offset + count; |
3000 | ||
e08b9ad7 JL |
3001 | /* Set the contents. */ |
3002 | memcpy(linker_stubs + offset, location, count); | |
d9ad93bc KR |
3003 | return (true); |
3004 | } | |
3005 | else | |
e08b9ad7 JL |
3006 | /* For everything but the linker stub section, use the generic |
3007 | code. */ | |
d9ad93bc KR |
3008 | return bfd_elf32_set_section_contents (abfd, section, location, |
3009 | offset, count); | |
e8f2240a | 3010 | } |
4c85cbfa | 3011 | |
7218bb04 KR |
3012 | /* Get the contents of the given section. |
3013 | ||
3014 | This is special for PA ELF because some sections (such as linker stubs) | |
3015 | may reside in memory rather than on disk, or in the case of the symbol | |
3016 | extension section, the contents may need to be generated from other | |
3017 | information contained in the BFD. */ | |
3018 | ||
e8f2240a | 3019 | boolean |
7218bb04 KR |
3020 | hppa_elf_get_section_contents (abfd, section, location, offset, count) |
3021 | bfd *abfd; | |
3022 | sec_ptr section; | |
3023 | PTR location; | |
3024 | file_ptr offset; | |
3025 | bfd_size_type count; | |
e8f2240a | 3026 | { |
7218bb04 KR |
3027 | /* If this is the linker stub section, then its contents are contained |
3028 | in memory rather than on disk. FIXME. Is that always right? What | |
3029 | about the case where a final executable is read in and a user tries | |
3030 | to get the contents of this section? In that case the contents would | |
3031 | be on disk like everything else. */ | |
e8f2240a KR |
3032 | if (strcmp (section->name, ".hppa_linker_stubs") == 0) |
3033 | { | |
3a70b01d | 3034 | elf32_hppa_stub_description *stub_desc = find_stubs (abfd, section); |
7218bb04 | 3035 | |
e8f2240a KR |
3036 | if (count == 0) |
3037 | return true; | |
7218bb04 KR |
3038 | |
3039 | /* Sanity check our arguments. */ | |
3040 | if ((bfd_size_type) (offset + count) > section->_raw_size | |
3041 | || (bfd_size_type) (offset + count) > stub_desc->real_size) | |
3042 | return (false); | |
3043 | ||
e8f2240a KR |
3044 | memcpy (location, stub_desc->stub_contents + offset, count); |
3045 | return (true); | |
3046 | } | |
7218bb04 KR |
3047 | |
3048 | /* The symbol extension section also needs special handling. Its | |
3049 | contents might be on the disk, in memory, or still need to | |
3050 | be generated. */ | |
e8f2240a KR |
3051 | else if (strcmp (section->name, ".hppa_symextn") == 0) |
3052 | { | |
4861ac76 | 3053 | /* If there are no output sections, then read the contents of the |
a5ccdad1 ILT |
3054 | symbol extension section from disk. */ |
3055 | if (section->output_section == NULL | |
3056 | && abfd->direction == read_direction) | |
7218bb04 | 3057 | { |
6812b607 ILT |
3058 | return _bfd_generic_get_section_contents (abfd, section, location, |
3059 | offset, count); | |
7218bb04 KR |
3060 | } |
3061 | ||
3062 | /* If this is the first time through, and there are output sections, | |
3063 | then build the symbol extension section based on other information | |
3064 | contained in the BFD. */ | |
3065 | else if (! symext_chain_built) | |
3066 | { | |
3067 | int i; | |
a5ccdad1 | 3068 | int *symtab_map = |
e08b9ad7 | 3069 | (int *) elf_sym_extra (section->output_section->owner); |
7218bb04 | 3070 | |
f5bfdacd | 3071 | for (i = 0; i < section->output_section->owner->symcount; i++) |
7218bb04 | 3072 | { |
e08b9ad7 JL |
3073 | elf_hppa_tc_symbol (section->output_section->owner, |
3074 | ((elf_symbol_type *) | |
3075 | section->output_section->owner->outsymbols[i]), | |
3076 | symtab_map[i], &symext_rootP, &symext_lastP); | |
7218bb04 KR |
3077 | } |
3078 | symext_chain_built++; | |
f5bfdacd JL |
3079 | elf_hppa_tc_make_sections (section->output_section->owner, |
3080 | symext_rootP); | |
7218bb04 | 3081 | } |
a5ccdad1 ILT |
3082 | |
3083 | /* At this point we know that the symbol extension section has been | |
3084 | built. We just need to copy it into the user's buffer. */ | |
e8f2240a KR |
3085 | if (count == 0) |
3086 | return true; | |
7218bb04 KR |
3087 | |
3088 | /* Sanity check our arguments. */ | |
3089 | if ((bfd_size_type) (offset + count) > section->_raw_size | |
3090 | || (bfd_size_type) (offset + count) > symextn_contents_real_size) | |
3091 | return (false); | |
3092 | ||
3093 | memcpy (location, | |
e08b9ad7 | 3094 | (char *)symextn_contents + section->output_offset + offset, |
7218bb04 | 3095 | count); |
e8f2240a KR |
3096 | return (true); |
3097 | } | |
3098 | else | |
e08b9ad7 JL |
3099 | /* It's not the symbol extension or linker stub sections, use |
3100 | the generic routines. */ | |
6812b607 ILT |
3101 | return _bfd_generic_get_section_contents (abfd, section, location, |
3102 | offset, count); | |
4c85cbfa KR |
3103 | } |
3104 | ||
e08b9ad7 JL |
3105 | /* Translate from an elf into field into a howto relocation pointer. */ |
3106 | ||
8ddd7ab3 | 3107 | static void |
f4bd7a8f DM |
3108 | elf_info_to_howto (abfd, cache_ptr, dst) |
3109 | bfd *abfd; | |
3110 | arelent *cache_ptr; | |
3111 | Elf32_Internal_Rela *dst; | |
4c85cbfa | 3112 | { |
d9ad93bc | 3113 | BFD_ASSERT (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_HPPA_UNIMPLEMENTED); |
e08b9ad7 | 3114 | cache_ptr->howto = &elf_hppa_howto_table[ELF32_R_TYPE (dst->r_info)]; |
d9ad93bc KR |
3115 | } |
3116 | ||
e08b9ad7 JL |
3117 | /* Do PA ELF specific processing for symbols. Needed to find the |
3118 | value of $global$. */ | |
3119 | ||
d9ad93bc | 3120 | static void |
f4bd7a8f DM |
3121 | elf32_hppa_backend_symbol_processing (abfd, sym) |
3122 | bfd *abfd; | |
3123 | asymbol *sym; | |
d9ad93bc KR |
3124 | { |
3125 | /* Is this a definition of $global$? If so, keep it because it will be | |
3126 | needed if any relocations are performed. */ | |
d9ad93bc KR |
3127 | if (!strcmp (sym->name, "$global$") |
3128 | && sym->section != &bfd_und_section) | |
3129 | { | |
3130 | global_symbol = sym; | |
3131 | } | |
3132 | } | |
3133 | ||
e08b9ad7 JL |
3134 | /* Do some PA ELF specific work after reading in the symbol table. |
3135 | In particular attach the argument relocation from the | |
3136 | symbol extension section to the appropriate symbols. */ | |
d9ad93bc | 3137 | static boolean |
f4bd7a8f DM |
3138 | elf32_hppa_backend_symbol_table_processing (abfd, esyms,symcnt) |
3139 | bfd *abfd; | |
3140 | elf_symbol_type *esyms; | |
3141 | int symcnt; | |
d9ad93bc | 3142 | { |
e08b9ad7 JL |
3143 | Elf32_Internal_Shdr *symextn_hdr = |
3144 | bfd_elf_find_section (abfd, SYMEXTN_SECTION_NAME); | |
3145 | int i, current_sym_idx = 0; | |
d9ad93bc | 3146 | |
e08b9ad7 JL |
3147 | /* If no symbol extension existed, then all symbol extension information |
3148 | is assumed to be zero. */ | |
f5bfdacd | 3149 | if (symextn_hdr == NULL) |
d9ad93bc | 3150 | { |
f5bfdacd | 3151 | for (i = 0; i < symcnt; i++) |
e08b9ad7 | 3152 | esyms[i].tc_data.hppa_arg_reloc = 0; |
d9ad93bc KR |
3153 | return (true); |
3154 | } | |
3155 | ||
e08b9ad7 | 3156 | /* Allocate a buffer of the appropriate size for the symextn section. */ |
d9ad93bc | 3157 | symextn_hdr->contents = bfd_zalloc(abfd,symextn_hdr->sh_size); |
9783e04a DM |
3158 | if (!symextn_hdr->contents) |
3159 | { | |
f5bfdacd | 3160 | bfd_set_error (bfd_error_no_memory); |
9783e04a DM |
3161 | return false; |
3162 | } | |
d9ad93bc KR |
3163 | symextn_hdr->size = symextn_hdr->sh_size; |
3164 | ||
e08b9ad7 | 3165 | /* Read in the symextn section. */ |
d9ad93bc | 3166 | if (bfd_seek (abfd, symextn_hdr->sh_offset, SEEK_SET) == -1) |
25057836 | 3167 | return false; |
d9ad93bc KR |
3168 | if (bfd_read ((PTR) symextn_hdr->contents, 1, symextn_hdr->size, abfd) |
3169 | != symextn_hdr->size) | |
25057836 | 3170 | return false; |
d9ad93bc | 3171 | |
e08b9ad7 JL |
3172 | /* Parse entries in the symbol extension section, updating the symtab |
3173 | entries as we go */ | |
f5bfdacd | 3174 | for (i = 0; i < symextn_hdr->size / sizeof(symext_entryS); i++) |
d9ad93bc KR |
3175 | { |
3176 | symext_entryS *seP = ((symext_entryS *)symextn_hdr->contents) + i; | |
e08b9ad7 JL |
3177 | int se_value = ELF32_HPPA_SX_VAL (*seP); |
3178 | int se_type = ELF32_HPPA_SX_TYPE (*seP); | |
d9ad93bc | 3179 | |
f5bfdacd | 3180 | switch (se_type) |
d9ad93bc KR |
3181 | { |
3182 | case HPPA_SXT_NULL: | |
3183 | break; | |
3184 | ||
3185 | case HPPA_SXT_SYMNDX: | |
f5bfdacd | 3186 | if (se_value >= symcnt) |
d9ad93bc | 3187 | { |
f5bfdacd | 3188 | bfd_set_error (bfd_error_bad_value); |
d9ad93bc KR |
3189 | return (false); |
3190 | } | |
3191 | current_sym_idx = se_value - 1; | |
3192 | break; | |
3193 | ||
3194 | case HPPA_SXT_ARG_RELOC: | |
3195 | esyms[current_sym_idx].tc_data.hppa_arg_reloc = se_value; | |
3196 | break; | |
3197 | ||
3198 | default: | |
f5bfdacd | 3199 | bfd_set_error (bfd_error_bad_value); |
d9ad93bc KR |
3200 | return (false); |
3201 | } | |
3202 | } | |
3203 | return (true); | |
3204 | } | |
3205 | ||
e08b9ad7 JL |
3206 | /* Perform on PA ELF specific processing once a section has been |
3207 | read in. In particular keep the symbol indexes correct for | |
3208 | the symbol extension information. */ | |
d9ad93bc KR |
3209 | |
3210 | static boolean | |
f4bd7a8f DM |
3211 | elf32_hppa_backend_section_processing (abfd, secthdr) |
3212 | bfd *abfd; | |
3213 | Elf32_Internal_Shdr *secthdr; | |
d9ad93bc | 3214 | { |
e08b9ad7 | 3215 | int i, j, k; |
d9ad93bc | 3216 | |
f5bfdacd | 3217 | if (secthdr->sh_type == SHT_HPPA_SYMEXTN) |
d9ad93bc | 3218 | { |
e08b9ad7 | 3219 | for (i = 0; i < secthdr->size / sizeof (symext_entryS); i++) |
d9ad93bc KR |
3220 | { |
3221 | symext_entryS *seP = ((symext_entryS *)secthdr->contents) + i; | |
e08b9ad7 JL |
3222 | int se_value = ELF32_HPPA_SX_VAL (*seP); |
3223 | int se_type = ELF32_HPPA_SX_TYPE (*seP); | |
d9ad93bc | 3224 | |
f5bfdacd | 3225 | switch (se_type) |
d9ad93bc KR |
3226 | { |
3227 | case HPPA_SXT_NULL: | |
3228 | break; | |
3229 | ||
3230 | case HPPA_SXT_SYMNDX: | |
f5bfdacd | 3231 | for (j = 0; j < abfd->symcount; j++) |
d9ad93bc | 3232 | { |
e08b9ad7 JL |
3233 | /* Locate the map entry for this symbol and modify the |
3234 | symbol extension section symbol index entry to reflect | |
3235 | the new symbol table index. */ | |
f5bfdacd | 3236 | for (k = 0; k < elf32_hppa_symextn_map_size; k++) |
d9ad93bc | 3237 | { |
f5bfdacd | 3238 | if (elf32_hppa_symextn_map[k].old_index == se_value |
e08b9ad7 JL |
3239 | && elf32_hppa_symextn_map[k].bfd |
3240 | == abfd->outsymbols[j]->the_bfd | |
3241 | && elf32_hppa_symextn_map[k].sym | |
3242 | == abfd->outsymbols[j]) | |
d9ad93bc KR |
3243 | { |
3244 | bfd_put_32(abfd, | |
3245 | ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX, j), | |
3246 | (char *)seP); | |
3247 | } | |
3248 | } | |
3249 | } | |
3250 | break; | |
3251 | ||
3252 | case HPPA_SXT_ARG_RELOC: | |
3253 | break; | |
3254 | ||
3255 | default: | |
f5bfdacd | 3256 | bfd_set_error (bfd_error_bad_value); |
d9ad93bc KR |
3257 | return (false); |
3258 | } | |
3259 | } | |
3260 | } | |
3261 | return true; | |
3262 | } | |
3263 | ||
e08b9ad7 JL |
3264 | /* What does this really do? Just determine if there is an appropriate |
3265 | mapping from ELF section headers to backend sections? More symbol | |
3266 | extension braindamage. */ | |
d9ad93bc KR |
3267 | |
3268 | static boolean | |
f4bd7a8f DM |
3269 | elf32_hppa_backend_section_from_shdr (abfd, hdr, name) |
3270 | bfd *abfd; | |
3271 | Elf32_Internal_Shdr *hdr; | |
3272 | char *name; | |
d9ad93bc KR |
3273 | { |
3274 | asection *newsect; | |
3275 | ||
f5bfdacd | 3276 | if (hdr->sh_type == SHT_HPPA_SYMEXTN) |
d9ad93bc | 3277 | { |
e08b9ad7 | 3278 | BFD_ASSERT (strcmp (name, ".hppa_symextn") == 0); |
d9ad93bc | 3279 | |
e08b9ad7 | 3280 | /* Bits that get saved. This one is real. */ |
d9ad93bc KR |
3281 | if (!hdr->rawdata) |
3282 | { | |
3283 | newsect = bfd_make_section (abfd, name); | |
3284 | if (newsect != NULL) | |
3285 | { | |
3286 | newsect->vma = hdr->sh_addr; | |
3287 | newsect->_raw_size = hdr->sh_size; | |
e08b9ad7 | 3288 | newsect->filepos = hdr->sh_offset; |
d9ad93bc KR |
3289 | newsect->flags |= SEC_HAS_CONTENTS; |
3290 | newsect->alignment_power = hdr->sh_addralign; | |
3291 | ||
3292 | if (hdr->sh_flags & SHF_ALLOC) | |
3293 | { | |
3294 | newsect->flags |= SEC_ALLOC; | |
3295 | newsect->flags |= SEC_LOAD; | |
3296 | } | |
3297 | ||
3298 | if (!(hdr->sh_flags & SHF_WRITE)) | |
3299 | newsect->flags |= SEC_READONLY; | |
3300 | ||
3301 | if (hdr->sh_flags & SHF_EXECINSTR) | |
e08b9ad7 | 3302 | newsect->flags |= SEC_CODE; |
d9ad93bc KR |
3303 | else |
3304 | newsect->flags |= SEC_DATA; | |
3305 | ||
3306 | hdr->rawdata = (void *) newsect; | |
3307 | } | |
3308 | } | |
3309 | return true; | |
3310 | } | |
3311 | return false; | |
3312 | } | |
3313 | ||
e08b9ad7 | 3314 | /* Return true if the given section is a fake section. */ |
d9ad93bc KR |
3315 | |
3316 | static boolean | |
f4bd7a8f DM |
3317 | elf32_hppa_backend_fake_sections (abfd, secthdr, asect) |
3318 | bfd *abfd; | |
3319 | Elf_Internal_Shdr *secthdr; | |
3320 | asection *asect; | |
d9ad93bc KR |
3321 | { |
3322 | ||
f5bfdacd | 3323 | if (strcmp(asect->name, ".hppa_symextn") == 0) |
d9ad93bc KR |
3324 | { |
3325 | secthdr->sh_type = SHT_HPPA_SYMEXTN; | |
3326 | secthdr->sh_flags = 0; | |
3327 | secthdr->sh_info = elf_section_data(asect)->rel_hdr.sh_link; | |
3328 | secthdr->sh_link = elf_onesymtab(abfd); | |
3329 | return true; | |
3330 | } | |
3331 | ||
3332 | if (!strcmp (asect->name, ".hppa_unwind")) | |
3333 | { | |
3334 | secthdr->sh_type = SHT_PROGBITS; | |
3335 | /* Unwind descriptors are not part of the program memory image. */ | |
3336 | secthdr->sh_flags = 0; | |
3337 | secthdr->sh_info = 0; | |
3338 | secthdr->sh_link = 0; | |
3339 | secthdr->sh_entsize = 16; | |
3340 | return true; | |
3341 | } | |
3342 | ||
7218bb04 KR |
3343 | /* @@ Should this be CPU specific?? KR */ |
3344 | if (!strcmp (asect->name, ".stabstr")) | |
3345 | { | |
3346 | secthdr->sh_type = SHT_STRTAB; | |
3347 | secthdr->sh_flags = 0; | |
3348 | secthdr->sh_info = 0; | |
3349 | secthdr->sh_link = 0; | |
3350 | secthdr->sh_entsize = 0; | |
3351 | return true; | |
3352 | } | |
3353 | ||
d9ad93bc KR |
3354 | return false; |
3355 | } | |
3356 | ||
e08b9ad7 JL |
3357 | /* Return true if there is a mapping from bfd section into a |
3358 | backend section. */ | |
d9ad93bc KR |
3359 | |
3360 | static boolean | |
e08b9ad7 | 3361 | elf32_hppa_backend_section_from_bfd_section (abfd, hdr, asect, ignored) |
f4bd7a8f DM |
3362 | bfd *abfd; |
3363 | Elf32_Internal_Shdr *hdr; | |
3364 | asection *asect; | |
e08b9ad7 | 3365 | int *ignored; |
d9ad93bc | 3366 | { |
f5bfdacd | 3367 | if (hdr->sh_type == SHT_HPPA_SYMEXTN) |
d9ad93bc KR |
3368 | { |
3369 | if (hdr->rawdata) | |
3370 | { | |
3371 | if (((struct sec *) (hdr->rawdata)) == asect) | |
3372 | { | |
e08b9ad7 | 3373 | BFD_ASSERT (strcmp (asect->name, ".hppa_symextn") == 0); |
d9ad93bc KR |
3374 | return true; |
3375 | } | |
3376 | } | |
3377 | } | |
f5bfdacd | 3378 | else if (hdr->sh_type == SHT_STRTAB) |
7218bb04 KR |
3379 | { |
3380 | if (hdr->rawdata) | |
3381 | { | |
3382 | if (((struct sec *) (hdr->rawdata)) == asect) | |
3383 | { | |
f5bfdacd | 3384 | BFD_ASSERT (strcmp (asect->name, ".stabstr") == 0); |
7218bb04 KR |
3385 | return true; |
3386 | } | |
3387 | } | |
3388 | } | |
d9ad93bc KR |
3389 | |
3390 | return false; | |
8ddd7ab3 | 3391 | } |
4c85cbfa | 3392 | |
f5bfdacd | 3393 | #define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup |
d9ad93bc KR |
3394 | #define elf_backend_section_from_bfd_section elf32_hppa_backend_section_from_bfd_section |
3395 | ||
e08b9ad7 JL |
3396 | #define elf_backend_symbol_processing elf32_hppa_backend_symbol_processing |
3397 | #define elf_backend_symbol_table_processing elf32_hppa_backend_symbol_table_processing | |
3398 | ||
6812b607 | 3399 | #define bfd_elf32_get_section_contents hppa_elf_get_section_contents |
d9ad93bc | 3400 | #define bfd_elf32_set_section_contents hppa_elf_set_section_contents |
25057836 | 3401 | #define bfd_elf32_bfd_is_local_label hppa_elf_is_local_label |
d9ad93bc | 3402 | |
e08b9ad7 JL |
3403 | #define elf_backend_section_processing elf32_hppa_backend_section_processing |
3404 | ||
3405 | #define elf_backend_section_from_shdr elf32_hppa_backend_section_from_shdr | |
3406 | #define elf_backend_fake_sections elf32_hppa_backend_fake_sections | |
3407 | ||
e8f2240a | 3408 | #define TARGET_BIG_SYM bfd_elf32_hppa_vec |
8ddd7ab3 KR |
3409 | #define TARGET_BIG_NAME "elf32-hppa" |
3410 | #define ELF_ARCH bfd_arch_hppa | |
a5ccdad1 | 3411 | #define ELF_MACHINE_CODE EM_HPPA |
3a70b01d | 3412 | #define ELF_MAXPAGESIZE 0x1000 |
8ddd7ab3 KR |
3413 | |
3414 | #include "elf32-target.h" |