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