Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* Hitachi SH specific support for 32-bit ELF |
fbca6ad9 | 2 | Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 |
7898deda | 3 | Free Software Foundation, Inc. |
252b5132 RH |
4 | Contributed by Ian Lance Taylor, Cygnus Support. |
5 | ||
6 | This file is part of BFD, the Binary File Descriptor library. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
21 | ||
22 | #include "bfd.h" | |
23 | #include "sysdep.h" | |
24 | #include "bfdlink.h" | |
25 | #include "libbfd.h" | |
26 | #include "elf-bfd.h" | |
27 | #include "elf/sh.h" | |
28 | ||
29 | static bfd_reloc_status_type sh_elf_reloc | |
30 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
31 | static bfd_reloc_status_type sh_elf_ignore_reloc | |
32 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
33 | static reloc_howto_type *sh_elf_reloc_type_lookup | |
34 | PARAMS ((bfd *, bfd_reloc_code_real_type)); | |
35 | static void sh_elf_info_to_howto | |
36 | PARAMS ((bfd *, arelent *, Elf_Internal_Rela *)); | |
d4845d57 JR |
37 | static boolean sh_elf_set_private_flags |
38 | PARAMS ((bfd *, flagword)); | |
39 | static boolean sh_elf_copy_private_data | |
40 | PARAMS ((bfd *, bfd *)); | |
41 | static boolean sh_elf_merge_private_data | |
42 | PARAMS ((bfd *, bfd *)); | |
1630fd2b | 43 | static boolean sh_elf_set_mach_from_flags |
d4845d57 | 44 | PARAMS ((bfd *)); |
252b5132 RH |
45 | static boolean sh_elf_relax_section |
46 | PARAMS ((bfd *, asection *, struct bfd_link_info *, boolean *)); | |
47 | static boolean sh_elf_relax_delete_bytes | |
48 | PARAMS ((bfd *, asection *, bfd_vma, int)); | |
49 | static boolean sh_elf_align_loads | |
50 | PARAMS ((bfd *, asection *, Elf_Internal_Rela *, bfd_byte *, boolean *)); | |
51 | static boolean sh_elf_swap_insns | |
52 | PARAMS ((bfd *, asection *, PTR, bfd_byte *, bfd_vma)); | |
53 | static boolean sh_elf_relocate_section | |
54 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, | |
55 | Elf_Internal_Rela *, Elf_Internal_Sym *, asection **)); | |
56 | static bfd_byte *sh_elf_get_relocated_section_contents | |
57 | PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *, | |
58 | bfd_byte *, boolean, asymbol **)); | |
37c644f2 AO |
59 | static boolean sh_elf_check_relocs |
60 | PARAMS ((bfd *, struct bfd_link_info *, asection *, | |
61 | const Elf_Internal_Rela *)); | |
62 | static struct bfd_hash_entry *sh_elf_link_hash_newfunc | |
63 | PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); | |
64 | static struct bfd_link_hash_table *sh_elf_link_hash_table_create | |
65 | PARAMS ((bfd *)); | |
66 | static boolean sh_elf_adjust_dynamic_symbol | |
67 | PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *)); | |
68 | static boolean sh_elf_size_dynamic_sections | |
69 | PARAMS ((bfd *, struct bfd_link_info *)); | |
70 | static boolean sh_elf_finish_dynamic_symbol | |
71 | PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *, | |
72 | Elf_Internal_Sym *)); | |
73 | static boolean sh_elf_finish_dynamic_sections | |
74 | PARAMS ((bfd *, struct bfd_link_info *)); | |
917583ad NC |
75 | static bfd_reloc_status_type sh_elf_reloc_loop |
76 | PARAMS ((int, bfd *, asection *, bfd_byte *, bfd_vma, asection *, | |
77 | bfd_vma, bfd_vma)); | |
78 | static boolean sh_elf_create_dynamic_sections | |
79 | PARAMS ((bfd *, struct bfd_link_info *)); | |
80 | static asection * sh_elf_gc_mark_hook | |
81 | PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *, | |
82 | struct elf_link_hash_entry *, Elf_Internal_Sym *)); | |
83 | static boolean sh_elf_gc_sweep_hook | |
84 | PARAMS ((bfd *, struct bfd_link_info *, asection *, | |
85 | const Elf_Internal_Rela *)); | |
99e4ae17 | 86 | static enum elf_reloc_type_class sh_elf_reloc_type_class |
f51e552e | 87 | PARAMS ((const Elf_Internal_Rela *)); |
518313c3 AO |
88 | #ifdef INCLUDE_SHMEDIA |
89 | inline static void movi_shori_putval PARAMS ((bfd *, unsigned long, char *)); | |
90 | #endif | |
37c644f2 AO |
91 | |
92 | /* The name of the dynamic interpreter. This is put in the .interp | |
93 | section. */ | |
94 | ||
95 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1" | |
252b5132 | 96 | |
38b1a46c NC |
97 | static reloc_howto_type sh_elf_howto_table[] = |
98 | { | |
252b5132 RH |
99 | /* No relocation. */ |
100 | HOWTO (R_SH_NONE, /* type */ | |
101 | 0, /* rightshift */ | |
102 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
103 | 0, /* bitsize */ | |
104 | false, /* pc_relative */ | |
105 | 0, /* bitpos */ | |
106 | complain_overflow_dont, /* complain_on_overflow */ | |
015551fc | 107 | sh_elf_ignore_reloc, /* special_function */ |
252b5132 RH |
108 | "R_SH_NONE", /* name */ |
109 | false, /* partial_inplace */ | |
110 | 0, /* src_mask */ | |
111 | 0, /* dst_mask */ | |
112 | false), /* pcrel_offset */ | |
113 | ||
114 | /* 32 bit absolute relocation. Setting partial_inplace to true and | |
115 | src_mask to a non-zero value is similar to the COFF toolchain. */ | |
116 | HOWTO (R_SH_DIR32, /* type */ | |
117 | 0, /* rightshift */ | |
118 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
119 | 32, /* bitsize */ | |
120 | false, /* pc_relative */ | |
121 | 0, /* bitpos */ | |
122 | complain_overflow_bitfield, /* complain_on_overflow */ | |
123 | sh_elf_reloc, /* special_function */ | |
124 | "R_SH_DIR32", /* name */ | |
125 | true, /* partial_inplace */ | |
126 | 0xffffffff, /* src_mask */ | |
127 | 0xffffffff, /* dst_mask */ | |
128 | false), /* pcrel_offset */ | |
129 | ||
130 | /* 32 bit PC relative relocation. */ | |
131 | HOWTO (R_SH_REL32, /* type */ | |
132 | 0, /* rightshift */ | |
133 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
134 | 32, /* bitsize */ | |
135 | true, /* pc_relative */ | |
136 | 0, /* bitpos */ | |
137 | complain_overflow_signed, /* complain_on_overflow */ | |
015551fc | 138 | sh_elf_ignore_reloc, /* special_function */ |
252b5132 | 139 | "R_SH_REL32", /* name */ |
146be91a HPN |
140 | true, /* partial_inplace */ |
141 | 0xffffffff, /* src_mask */ | |
252b5132 RH |
142 | 0xffffffff, /* dst_mask */ |
143 | true), /* pcrel_offset */ | |
144 | ||
145 | /* 8 bit PC relative branch divided by 2. */ | |
146 | HOWTO (R_SH_DIR8WPN, /* type */ | |
147 | 1, /* rightshift */ | |
148 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
149 | 8, /* bitsize */ | |
150 | true, /* pc_relative */ | |
151 | 0, /* bitpos */ | |
152 | complain_overflow_signed, /* complain_on_overflow */ | |
015551fc | 153 | sh_elf_ignore_reloc, /* special_function */ |
252b5132 RH |
154 | "R_SH_DIR8WPN", /* name */ |
155 | true, /* partial_inplace */ | |
156 | 0xff, /* src_mask */ | |
157 | 0xff, /* dst_mask */ | |
158 | true), /* pcrel_offset */ | |
159 | ||
160 | /* 12 bit PC relative branch divided by 2. */ | |
161 | HOWTO (R_SH_IND12W, /* type */ | |
162 | 1, /* rightshift */ | |
163 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
164 | 12, /* bitsize */ | |
165 | true, /* pc_relative */ | |
166 | 0, /* bitpos */ | |
167 | complain_overflow_signed, /* complain_on_overflow */ | |
168 | sh_elf_reloc, /* special_function */ | |
169 | "R_SH_IND12W", /* name */ | |
170 | true, /* partial_inplace */ | |
171 | 0xfff, /* src_mask */ | |
172 | 0xfff, /* dst_mask */ | |
173 | true), /* pcrel_offset */ | |
174 | ||
175 | /* 8 bit unsigned PC relative divided by 4. */ | |
176 | HOWTO (R_SH_DIR8WPL, /* type */ | |
177 | 2, /* rightshift */ | |
178 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
179 | 8, /* bitsize */ | |
180 | true, /* pc_relative */ | |
181 | 0, /* bitpos */ | |
182 | complain_overflow_unsigned, /* complain_on_overflow */ | |
015551fc | 183 | sh_elf_ignore_reloc, /* special_function */ |
252b5132 RH |
184 | "R_SH_DIR8WPL", /* name */ |
185 | true, /* partial_inplace */ | |
186 | 0xff, /* src_mask */ | |
187 | 0xff, /* dst_mask */ | |
188 | true), /* pcrel_offset */ | |
189 | ||
190 | /* 8 bit unsigned PC relative divided by 2. */ | |
191 | HOWTO (R_SH_DIR8WPZ, /* type */ | |
192 | 1, /* rightshift */ | |
193 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
194 | 8, /* bitsize */ | |
195 | true, /* pc_relative */ | |
196 | 0, /* bitpos */ | |
197 | complain_overflow_unsigned, /* complain_on_overflow */ | |
015551fc | 198 | sh_elf_ignore_reloc, /* special_function */ |
252b5132 RH |
199 | "R_SH_DIR8WPZ", /* name */ |
200 | true, /* partial_inplace */ | |
201 | 0xff, /* src_mask */ | |
202 | 0xff, /* dst_mask */ | |
203 | true), /* pcrel_offset */ | |
204 | ||
205 | /* 8 bit GBR relative. FIXME: This only makes sense if we have some | |
206 | special symbol for the GBR relative area, and that is not | |
207 | implemented. */ | |
208 | HOWTO (R_SH_DIR8BP, /* type */ | |
209 | 0, /* rightshift */ | |
210 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
211 | 8, /* bitsize */ | |
212 | false, /* pc_relative */ | |
213 | 0, /* bitpos */ | |
214 | complain_overflow_unsigned, /* complain_on_overflow */ | |
015551fc | 215 | sh_elf_ignore_reloc, /* special_function */ |
252b5132 RH |
216 | "R_SH_DIR8BP", /* name */ |
217 | false, /* partial_inplace */ | |
218 | 0, /* src_mask */ | |
219 | 0xff, /* dst_mask */ | |
220 | true), /* pcrel_offset */ | |
221 | ||
222 | /* 8 bit GBR relative divided by 2. FIXME: This only makes sense if | |
223 | we have some special symbol for the GBR relative area, and that | |
224 | is not implemented. */ | |
225 | HOWTO (R_SH_DIR8W, /* type */ | |
226 | 1, /* rightshift */ | |
227 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
228 | 8, /* bitsize */ | |
229 | false, /* pc_relative */ | |
230 | 0, /* bitpos */ | |
231 | complain_overflow_unsigned, /* complain_on_overflow */ | |
015551fc | 232 | sh_elf_ignore_reloc, /* special_function */ |
252b5132 RH |
233 | "R_SH_DIR8W", /* name */ |
234 | false, /* partial_inplace */ | |
235 | 0, /* src_mask */ | |
236 | 0xff, /* dst_mask */ | |
237 | true), /* pcrel_offset */ | |
238 | ||
239 | /* 8 bit GBR relative divided by 4. FIXME: This only makes sense if | |
240 | we have some special symbol for the GBR relative area, and that | |
241 | is not implemented. */ | |
242 | HOWTO (R_SH_DIR8L, /* type */ | |
243 | 2, /* rightshift */ | |
244 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
245 | 8, /* bitsize */ | |
246 | false, /* pc_relative */ | |
247 | 0, /* bitpos */ | |
248 | complain_overflow_unsigned, /* complain_on_overflow */ | |
015551fc | 249 | sh_elf_ignore_reloc, /* special_function */ |
252b5132 RH |
250 | "R_SH_DIR8L", /* name */ |
251 | false, /* partial_inplace */ | |
252 | 0, /* src_mask */ | |
253 | 0xff, /* dst_mask */ | |
254 | true), /* pcrel_offset */ | |
255 | ||
06bb75c1 AO |
256 | EMPTY_HOWTO (10), |
257 | EMPTY_HOWTO (11), | |
258 | EMPTY_HOWTO (12), | |
259 | EMPTY_HOWTO (13), | |
260 | EMPTY_HOWTO (14), | |
261 | EMPTY_HOWTO (15), | |
262 | EMPTY_HOWTO (16), | |
263 | EMPTY_HOWTO (17), | |
5f771d47 ILT |
264 | EMPTY_HOWTO (18), |
265 | EMPTY_HOWTO (19), | |
266 | EMPTY_HOWTO (20), | |
267 | EMPTY_HOWTO (21), | |
268 | EMPTY_HOWTO (22), | |
269 | EMPTY_HOWTO (23), | |
270 | EMPTY_HOWTO (24), | |
252b5132 RH |
271 | |
272 | /* The remaining relocs are a GNU extension used for relaxing. The | |
273 | final pass of the linker never needs to do anything with any of | |
274 | these relocs. Any required operations are handled by the | |
275 | relaxation code. */ | |
276 | ||
277 | /* A 16 bit switch table entry. This is generated for an expression | |
278 | such as ``.word L1 - L2''. The offset holds the difference | |
279 | between the reloc address and L2. */ | |
280 | HOWTO (R_SH_SWITCH16, /* type */ | |
281 | 0, /* rightshift */ | |
282 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
283 | 16, /* bitsize */ | |
284 | false, /* pc_relative */ | |
285 | 0, /* bitpos */ | |
286 | complain_overflow_unsigned, /* complain_on_overflow */ | |
287 | sh_elf_ignore_reloc, /* special_function */ | |
288 | "R_SH_SWITCH16", /* name */ | |
289 | false, /* partial_inplace */ | |
290 | 0, /* src_mask */ | |
291 | 0, /* dst_mask */ | |
292 | true), /* pcrel_offset */ | |
293 | ||
294 | /* A 32 bit switch table entry. This is generated for an expression | |
295 | such as ``.long L1 - L2''. The offset holds the difference | |
296 | between the reloc address and L2. */ | |
297 | HOWTO (R_SH_SWITCH32, /* type */ | |
298 | 0, /* rightshift */ | |
299 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
300 | 32, /* bitsize */ | |
301 | false, /* pc_relative */ | |
302 | 0, /* bitpos */ | |
303 | complain_overflow_unsigned, /* complain_on_overflow */ | |
304 | sh_elf_ignore_reloc, /* special_function */ | |
305 | "R_SH_SWITCH32", /* name */ | |
306 | false, /* partial_inplace */ | |
307 | 0, /* src_mask */ | |
308 | 0, /* dst_mask */ | |
309 | true), /* pcrel_offset */ | |
310 | ||
311 | /* Indicates a .uses pseudo-op. The compiler will generate .uses | |
312 | pseudo-ops when it finds a function call which can be relaxed. | |
313 | The offset field holds the PC relative offset to the instruction | |
314 | which loads the register used in the function call. */ | |
315 | HOWTO (R_SH_USES, /* type */ | |
316 | 0, /* rightshift */ | |
317 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
318 | 0, /* bitsize */ | |
319 | false, /* pc_relative */ | |
320 | 0, /* bitpos */ | |
321 | complain_overflow_unsigned, /* complain_on_overflow */ | |
322 | sh_elf_ignore_reloc, /* special_function */ | |
323 | "R_SH_USES", /* name */ | |
324 | false, /* partial_inplace */ | |
325 | 0, /* src_mask */ | |
326 | 0, /* dst_mask */ | |
327 | true), /* pcrel_offset */ | |
328 | ||
329 | /* The assembler will generate this reloc for addresses referred to | |
330 | by the register loads associated with USES relocs. The offset | |
331 | field holds the number of times the address is referenced in the | |
332 | object file. */ | |
333 | HOWTO (R_SH_COUNT, /* type */ | |
334 | 0, /* rightshift */ | |
335 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
336 | 0, /* bitsize */ | |
337 | false, /* pc_relative */ | |
338 | 0, /* bitpos */ | |
339 | complain_overflow_unsigned, /* complain_on_overflow */ | |
340 | sh_elf_ignore_reloc, /* special_function */ | |
341 | "R_SH_COUNT", /* name */ | |
342 | false, /* partial_inplace */ | |
343 | 0, /* src_mask */ | |
344 | 0, /* dst_mask */ | |
345 | true), /* pcrel_offset */ | |
346 | ||
347 | /* Indicates an alignment statement. The offset field is the power | |
348 | of 2 to which subsequent portions of the object file must be | |
349 | aligned. */ | |
350 | HOWTO (R_SH_ALIGN, /* type */ | |
351 | 0, /* rightshift */ | |
352 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
353 | 0, /* bitsize */ | |
354 | false, /* pc_relative */ | |
355 | 0, /* bitpos */ | |
356 | complain_overflow_unsigned, /* complain_on_overflow */ | |
357 | sh_elf_ignore_reloc, /* special_function */ | |
358 | "R_SH_ALIGN", /* name */ | |
359 | false, /* partial_inplace */ | |
360 | 0, /* src_mask */ | |
361 | 0, /* dst_mask */ | |
362 | true), /* pcrel_offset */ | |
363 | ||
364 | /* The assembler will generate this reloc before a block of | |
365 | instructions. A section should be processed as assumining it | |
366 | contains data, unless this reloc is seen. */ | |
367 | HOWTO (R_SH_CODE, /* type */ | |
368 | 0, /* rightshift */ | |
369 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
370 | 0, /* bitsize */ | |
371 | false, /* pc_relative */ | |
372 | 0, /* bitpos */ | |
373 | complain_overflow_unsigned, /* complain_on_overflow */ | |
374 | sh_elf_ignore_reloc, /* special_function */ | |
375 | "R_SH_CODE", /* name */ | |
376 | false, /* partial_inplace */ | |
377 | 0, /* src_mask */ | |
378 | 0, /* dst_mask */ | |
379 | true), /* pcrel_offset */ | |
380 | ||
381 | /* The assembler will generate this reloc after a block of | |
382 | instructions when it sees data that is not instructions. */ | |
383 | HOWTO (R_SH_DATA, /* type */ | |
384 | 0, /* rightshift */ | |
385 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
386 | 0, /* bitsize */ | |
387 | false, /* pc_relative */ | |
388 | 0, /* bitpos */ | |
389 | complain_overflow_unsigned, /* complain_on_overflow */ | |
390 | sh_elf_ignore_reloc, /* special_function */ | |
391 | "R_SH_DATA", /* name */ | |
392 | false, /* partial_inplace */ | |
393 | 0, /* src_mask */ | |
394 | 0, /* dst_mask */ | |
395 | true), /* pcrel_offset */ | |
396 | ||
397 | /* The assembler generates this reloc for each label within a block | |
398 | of instructions. This permits the linker to avoid swapping | |
399 | instructions which are the targets of branches. */ | |
400 | HOWTO (R_SH_LABEL, /* type */ | |
401 | 0, /* rightshift */ | |
402 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
403 | 0, /* bitsize */ | |
404 | false, /* pc_relative */ | |
405 | 0, /* bitpos */ | |
406 | complain_overflow_unsigned, /* complain_on_overflow */ | |
407 | sh_elf_ignore_reloc, /* special_function */ | |
408 | "R_SH_LABEL", /* name */ | |
409 | false, /* partial_inplace */ | |
410 | 0, /* src_mask */ | |
411 | 0, /* dst_mask */ | |
412 | true), /* pcrel_offset */ | |
413 | ||
414 | /* An 8 bit switch table entry. This is generated for an expression | |
415 | such as ``.word L1 - L2''. The offset holds the difference | |
416 | between the reloc address and L2. */ | |
417 | HOWTO (R_SH_SWITCH8, /* type */ | |
418 | 0, /* rightshift */ | |
419 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
420 | 8, /* bitsize */ | |
421 | false, /* pc_relative */ | |
422 | 0, /* bitpos */ | |
423 | complain_overflow_unsigned, /* complain_on_overflow */ | |
424 | sh_elf_ignore_reloc, /* special_function */ | |
425 | "R_SH_SWITCH8", /* name */ | |
426 | false, /* partial_inplace */ | |
427 | 0, /* src_mask */ | |
428 | 0, /* dst_mask */ | |
429 | true), /* pcrel_offset */ | |
430 | ||
431 | /* GNU extension to record C++ vtable hierarchy */ | |
432 | HOWTO (R_SH_GNU_VTINHERIT, /* type */ | |
433 | 0, /* rightshift */ | |
434 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
435 | 0, /* bitsize */ | |
436 | false, /* pc_relative */ | |
437 | 0, /* bitpos */ | |
438 | complain_overflow_dont, /* complain_on_overflow */ | |
439 | NULL, /* special_function */ | |
440 | "R_SH_GNU_VTINHERIT", /* name */ | |
441 | false, /* partial_inplace */ | |
442 | 0, /* src_mask */ | |
443 | 0, /* dst_mask */ | |
444 | false), /* pcrel_offset */ | |
445 | ||
446 | /* GNU extension to record C++ vtable member usage */ | |
447 | HOWTO (R_SH_GNU_VTENTRY, /* type */ | |
448 | 0, /* rightshift */ | |
449 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
450 | 0, /* bitsize */ | |
451 | false, /* pc_relative */ | |
452 | 0, /* bitpos */ | |
453 | complain_overflow_dont, /* complain_on_overflow */ | |
454 | _bfd_elf_rel_vtable_reloc_fn, /* special_function */ | |
455 | "R_SH_GNU_VTENTRY", /* name */ | |
456 | false, /* partial_inplace */ | |
457 | 0, /* src_mask */ | |
458 | 0, /* dst_mask */ | |
459 | false), /* pcrel_offset */ | |
460 | ||
015551fc JR |
461 | /* 8 bit PC relative divided by 2 - but specified in a very odd way. */ |
462 | HOWTO (R_SH_LOOP_START, /* type */ | |
463 | 1, /* rightshift */ | |
464 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
465 | 8, /* bitsize */ | |
466 | false, /* pc_relative */ | |
467 | 0, /* bitpos */ | |
468 | complain_overflow_signed, /* complain_on_overflow */ | |
469 | sh_elf_ignore_reloc, /* special_function */ | |
470 | "R_SH_LOOP_START", /* name */ | |
471 | true, /* partial_inplace */ | |
472 | 0xff, /* src_mask */ | |
473 | 0xff, /* dst_mask */ | |
474 | true), /* pcrel_offset */ | |
475 | ||
476 | /* 8 bit PC relative divided by 2 - but specified in a very odd way. */ | |
477 | HOWTO (R_SH_LOOP_END, /* type */ | |
478 | 1, /* rightshift */ | |
479 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
480 | 8, /* bitsize */ | |
481 | false, /* pc_relative */ | |
482 | 0, /* bitpos */ | |
483 | complain_overflow_signed, /* complain_on_overflow */ | |
484 | sh_elf_ignore_reloc, /* special_function */ | |
485 | "R_SH_LOOP_END", /* name */ | |
486 | true, /* partial_inplace */ | |
487 | 0xff, /* src_mask */ | |
488 | 0xff, /* dst_mask */ | |
489 | true), /* pcrel_offset */ | |
490 | ||
06bb75c1 AO |
491 | EMPTY_HOWTO (38), |
492 | EMPTY_HOWTO (39), | |
493 | EMPTY_HOWTO (40), | |
494 | EMPTY_HOWTO (41), | |
495 | EMPTY_HOWTO (42), | |
496 | EMPTY_HOWTO (43), | |
497 | EMPTY_HOWTO (44), | |
fbca6ad9 AO |
498 | |
499 | #ifdef INCLUDE_SHMEDIA | |
500 | /* Used in SHLLI.L and SHLRI.L. */ | |
501 | HOWTO (R_SH_DIR5U, /* type */ | |
502 | 0, /* rightshift */ | |
503 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
504 | 5, /* bitsize */ | |
505 | false, /* pc_relative */ | |
506 | 10, /* bitpos */ | |
507 | complain_overflow_unsigned, /* complain_on_overflow */ | |
508 | bfd_elf_generic_reloc, /* special_function */ | |
509 | "R_SH_DIR5U", /* name */ | |
510 | false, /* partial_inplace */ | |
511 | 0, /* src_mask */ | |
512 | 0xfc00, /* dst_mask */ | |
513 | false), /* pcrel_offset */ | |
514 | ||
515 | /* Used in SHARI, SHLLI et al. */ | |
516 | HOWTO (R_SH_DIR6U, /* type */ | |
517 | 0, /* rightshift */ | |
518 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
519 | 6, /* bitsize */ | |
520 | false, /* pc_relative */ | |
521 | 10, /* bitpos */ | |
522 | complain_overflow_unsigned, /* complain_on_overflow */ | |
523 | bfd_elf_generic_reloc, /* special_function */ | |
524 | "R_SH_DIR6U", /* name */ | |
525 | false, /* partial_inplace */ | |
526 | 0, /* src_mask */ | |
527 | 0xfc00, /* dst_mask */ | |
528 | false), /* pcrel_offset */ | |
529 | ||
530 | /* Used in BxxI, LDHI.L et al. */ | |
531 | HOWTO (R_SH_DIR6S, /* type */ | |
532 | 0, /* rightshift */ | |
533 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
534 | 6, /* bitsize */ | |
535 | false, /* pc_relative */ | |
536 | 10, /* bitpos */ | |
537 | complain_overflow_signed, /* complain_on_overflow */ | |
538 | bfd_elf_generic_reloc, /* special_function */ | |
539 | "R_SH_DIR6S", /* name */ | |
540 | false, /* partial_inplace */ | |
541 | 0, /* src_mask */ | |
542 | 0xfc00, /* dst_mask */ | |
543 | false), /* pcrel_offset */ | |
544 | ||
545 | /* Used in ADDI, ANDI et al. */ | |
546 | HOWTO (R_SH_DIR10S, /* type */ | |
547 | 0, /* rightshift */ | |
548 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
549 | 10, /* bitsize */ | |
550 | false, /* pc_relative */ | |
551 | 10, /* bitpos */ | |
552 | complain_overflow_signed, /* complain_on_overflow */ | |
553 | bfd_elf_generic_reloc, /* special_function */ | |
554 | "R_SH_DIR10S", /* name */ | |
555 | false, /* partial_inplace */ | |
556 | 0, /* src_mask */ | |
557 | 0xffc00, /* dst_mask */ | |
558 | false), /* pcrel_offset */ | |
559 | ||
560 | /* Used in LD.UW, ST.W et al. */ | |
561 | HOWTO (R_SH_DIR10SW, /* type */ | |
562 | 1, /* rightshift */ | |
563 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
564 | 11, /* bitsize */ | |
565 | false, /* pc_relative */ | |
566 | 10, /* bitpos */ | |
567 | complain_overflow_signed, /* complain_on_overflow */ | |
568 | bfd_elf_generic_reloc, /* special_function */ | |
569 | "R_SH_DIR10SW", /* name */ | |
570 | false, /* partial_inplace */ | |
571 | 0, /* src_mask */ | |
572 | 0xffc00, /* dst_mask */ | |
573 | false), /* pcrel_offset */ | |
574 | ||
575 | /* Used in LD.L, FLD.S et al. */ | |
576 | HOWTO (R_SH_DIR10SL, /* type */ | |
577 | 2, /* rightshift */ | |
578 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
579 | 12, /* bitsize */ | |
580 | false, /* pc_relative */ | |
581 | 10, /* bitpos */ | |
582 | complain_overflow_signed, /* complain_on_overflow */ | |
583 | bfd_elf_generic_reloc, /* special_function */ | |
584 | "R_SH_DIR10SL", /* name */ | |
585 | false, /* partial_inplace */ | |
586 | 0, /* src_mask */ | |
587 | 0xffc00, /* dst_mask */ | |
588 | false), /* pcrel_offset */ | |
589 | ||
590 | /* Used in FLD.D, FST.P et al. */ | |
591 | HOWTO (R_SH_DIR10SQ, /* type */ | |
592 | 3, /* rightshift */ | |
593 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
594 | 13, /* bitsize */ | |
595 | false, /* pc_relative */ | |
596 | 10, /* bitpos */ | |
597 | complain_overflow_signed, /* complain_on_overflow */ | |
598 | bfd_elf_generic_reloc, /* special_function */ | |
599 | "R_SH_DIR10SQ", /* name */ | |
600 | false, /* partial_inplace */ | |
601 | 0, /* src_mask */ | |
602 | 0xffc00, /* dst_mask */ | |
603 | false), /* pcrel_offset */ | |
604 | ||
605 | #else | |
06bb75c1 AO |
606 | EMPTY_HOWTO (45), |
607 | EMPTY_HOWTO (46), | |
608 | EMPTY_HOWTO (47), | |
609 | EMPTY_HOWTO (48), | |
610 | EMPTY_HOWTO (49), | |
611 | EMPTY_HOWTO (50), | |
612 | EMPTY_HOWTO (51), | |
fbca6ad9 AO |
613 | #endif |
614 | ||
06bb75c1 AO |
615 | EMPTY_HOWTO (52), |
616 | EMPTY_HOWTO (53), | |
617 | EMPTY_HOWTO (54), | |
618 | EMPTY_HOWTO (55), | |
619 | EMPTY_HOWTO (56), | |
620 | EMPTY_HOWTO (57), | |
621 | EMPTY_HOWTO (58), | |
622 | EMPTY_HOWTO (59), | |
623 | EMPTY_HOWTO (60), | |
624 | EMPTY_HOWTO (61), | |
625 | EMPTY_HOWTO (62), | |
626 | EMPTY_HOWTO (63), | |
627 | EMPTY_HOWTO (64), | |
628 | EMPTY_HOWTO (65), | |
629 | EMPTY_HOWTO (66), | |
630 | EMPTY_HOWTO (67), | |
631 | EMPTY_HOWTO (68), | |
632 | EMPTY_HOWTO (69), | |
633 | EMPTY_HOWTO (70), | |
634 | EMPTY_HOWTO (71), | |
635 | EMPTY_HOWTO (72), | |
636 | EMPTY_HOWTO (73), | |
637 | EMPTY_HOWTO (74), | |
638 | EMPTY_HOWTO (75), | |
639 | EMPTY_HOWTO (76), | |
640 | EMPTY_HOWTO (77), | |
641 | EMPTY_HOWTO (78), | |
642 | EMPTY_HOWTO (79), | |
643 | EMPTY_HOWTO (80), | |
644 | EMPTY_HOWTO (81), | |
645 | EMPTY_HOWTO (82), | |
646 | EMPTY_HOWTO (83), | |
647 | EMPTY_HOWTO (84), | |
648 | EMPTY_HOWTO (85), | |
649 | EMPTY_HOWTO (86), | |
650 | EMPTY_HOWTO (87), | |
651 | EMPTY_HOWTO (88), | |
652 | EMPTY_HOWTO (89), | |
653 | EMPTY_HOWTO (90), | |
654 | EMPTY_HOWTO (91), | |
655 | EMPTY_HOWTO (92), | |
656 | EMPTY_HOWTO (93), | |
657 | EMPTY_HOWTO (94), | |
658 | EMPTY_HOWTO (95), | |
659 | EMPTY_HOWTO (96), | |
660 | EMPTY_HOWTO (97), | |
661 | EMPTY_HOWTO (98), | |
662 | EMPTY_HOWTO (99), | |
663 | EMPTY_HOWTO (100), | |
664 | EMPTY_HOWTO (101), | |
665 | EMPTY_HOWTO (102), | |
666 | EMPTY_HOWTO (103), | |
667 | EMPTY_HOWTO (104), | |
668 | EMPTY_HOWTO (105), | |
669 | EMPTY_HOWTO (106), | |
670 | EMPTY_HOWTO (107), | |
671 | EMPTY_HOWTO (108), | |
672 | EMPTY_HOWTO (109), | |
673 | EMPTY_HOWTO (110), | |
674 | EMPTY_HOWTO (111), | |
675 | EMPTY_HOWTO (112), | |
676 | EMPTY_HOWTO (113), | |
677 | EMPTY_HOWTO (114), | |
678 | EMPTY_HOWTO (115), | |
679 | EMPTY_HOWTO (116), | |
680 | EMPTY_HOWTO (117), | |
681 | EMPTY_HOWTO (118), | |
682 | EMPTY_HOWTO (119), | |
683 | EMPTY_HOWTO (120), | |
684 | EMPTY_HOWTO (121), | |
685 | EMPTY_HOWTO (122), | |
686 | EMPTY_HOWTO (123), | |
687 | EMPTY_HOWTO (124), | |
688 | EMPTY_HOWTO (125), | |
689 | EMPTY_HOWTO (126), | |
690 | EMPTY_HOWTO (127), | |
691 | EMPTY_HOWTO (128), | |
692 | EMPTY_HOWTO (129), | |
693 | EMPTY_HOWTO (130), | |
694 | EMPTY_HOWTO (131), | |
695 | EMPTY_HOWTO (132), | |
696 | EMPTY_HOWTO (133), | |
697 | EMPTY_HOWTO (134), | |
698 | EMPTY_HOWTO (135), | |
699 | EMPTY_HOWTO (136), | |
700 | EMPTY_HOWTO (137), | |
701 | EMPTY_HOWTO (138), | |
702 | EMPTY_HOWTO (139), | |
703 | EMPTY_HOWTO (140), | |
704 | EMPTY_HOWTO (141), | |
705 | EMPTY_HOWTO (142), | |
706 | EMPTY_HOWTO (143), | |
707 | EMPTY_HOWTO (144), | |
708 | EMPTY_HOWTO (145), | |
709 | EMPTY_HOWTO (146), | |
710 | EMPTY_HOWTO (147), | |
711 | EMPTY_HOWTO (148), | |
712 | EMPTY_HOWTO (149), | |
713 | EMPTY_HOWTO (150), | |
714 | EMPTY_HOWTO (151), | |
715 | EMPTY_HOWTO (152), | |
716 | EMPTY_HOWTO (153), | |
717 | EMPTY_HOWTO (154), | |
718 | EMPTY_HOWTO (155), | |
719 | EMPTY_HOWTO (156), | |
720 | EMPTY_HOWTO (157), | |
721 | EMPTY_HOWTO (158), | |
722 | EMPTY_HOWTO (159), | |
723 | ||
724 | HOWTO (R_SH_GOT32, /* type */ | |
725 | 0, /* rightshift */ | |
726 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
727 | 32, /* bitsize */ | |
728 | false, /* pc_relative */ | |
729 | 0, /* bitpos */ | |
730 | complain_overflow_bitfield, /* complain_on_overflow */ | |
731 | bfd_elf_generic_reloc, /* */ | |
732 | "R_SH_GOT32", /* name */ | |
733 | true, /* partial_inplace */ | |
734 | 0xffffffff, /* src_mask */ | |
735 | 0xffffffff, /* dst_mask */ | |
736 | false), /* pcrel_offset */ | |
737 | ||
738 | HOWTO (R_SH_PLT32, /* type */ | |
739 | 0, /* rightshift */ | |
740 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
741 | 32, /* bitsize */ | |
742 | true, /* pc_relative */ | |
743 | 0, /* bitpos */ | |
744 | complain_overflow_bitfield, /* complain_on_overflow */ | |
745 | bfd_elf_generic_reloc, /* */ | |
746 | "R_SH_PLT32", /* name */ | |
747 | true, /* partial_inplace */ | |
748 | 0xffffffff, /* src_mask */ | |
749 | 0xffffffff, /* dst_mask */ | |
750 | true), /* pcrel_offset */ | |
751 | ||
752 | HOWTO (R_SH_COPY, /* type */ | |
753 | 0, /* rightshift */ | |
754 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
755 | 32, /* bitsize */ | |
756 | false, /* pc_relative */ | |
757 | 0, /* bitpos */ | |
758 | complain_overflow_bitfield, /* complain_on_overflow */ | |
759 | bfd_elf_generic_reloc, /* */ | |
760 | "R_SH_COPY", /* name */ | |
761 | true, /* partial_inplace */ | |
762 | 0xffffffff, /* src_mask */ | |
763 | 0xffffffff, /* dst_mask */ | |
764 | false), /* pcrel_offset */ | |
765 | ||
766 | HOWTO (R_SH_GLOB_DAT, /* type */ | |
767 | 0, /* rightshift */ | |
768 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
769 | 32, /* bitsize */ | |
770 | false, /* pc_relative */ | |
771 | 0, /* bitpos */ | |
772 | complain_overflow_bitfield, /* complain_on_overflow */ | |
773 | bfd_elf_generic_reloc, /* */ | |
774 | "R_SH_GLOB_DAT", /* name */ | |
775 | true, /* partial_inplace */ | |
776 | 0xffffffff, /* src_mask */ | |
777 | 0xffffffff, /* dst_mask */ | |
778 | false), /* pcrel_offset */ | |
779 | ||
780 | HOWTO (R_SH_JMP_SLOT, /* type */ | |
781 | 0, /* rightshift */ | |
782 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
783 | 32, /* bitsize */ | |
784 | false, /* pc_relative */ | |
785 | 0, /* bitpos */ | |
786 | complain_overflow_bitfield, /* complain_on_overflow */ | |
787 | bfd_elf_generic_reloc, /* */ | |
788 | "R_SH_JMP_SLOT", /* name */ | |
789 | true, /* partial_inplace */ | |
790 | 0xffffffff, /* src_mask */ | |
791 | 0xffffffff, /* dst_mask */ | |
792 | false), /* pcrel_offset */ | |
793 | ||
794 | HOWTO (R_SH_RELATIVE, /* type */ | |
795 | 0, /* rightshift */ | |
796 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
797 | 32, /* bitsize */ | |
798 | false, /* pc_relative */ | |
799 | 0, /* bitpos */ | |
800 | complain_overflow_bitfield, /* complain_on_overflow */ | |
801 | bfd_elf_generic_reloc, /* */ | |
802 | "R_SH_RELATIVE", /* name */ | |
803 | true, /* partial_inplace */ | |
804 | 0xffffffff, /* src_mask */ | |
805 | 0xffffffff, /* dst_mask */ | |
806 | false), /* pcrel_offset */ | |
807 | ||
808 | HOWTO (R_SH_GOTOFF, /* type */ | |
809 | 0, /* rightshift */ | |
810 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
811 | 32, /* bitsize */ | |
812 | false, /* pc_relative */ | |
813 | 0, /* bitpos */ | |
814 | complain_overflow_bitfield, /* complain_on_overflow */ | |
815 | bfd_elf_generic_reloc, /* */ | |
816 | "R_SH_GOTOFF", /* name */ | |
817 | true, /* partial_inplace */ | |
818 | 0xffffffff, /* src_mask */ | |
819 | 0xffffffff, /* dst_mask */ | |
820 | false), /* pcrel_offset */ | |
821 | ||
822 | HOWTO (R_SH_GOTPC, /* type */ | |
823 | 0, /* rightshift */ | |
824 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
825 | 32, /* bitsize */ | |
826 | true, /* pc_relative */ | |
827 | 0, /* bitpos */ | |
828 | complain_overflow_bitfield, /* complain_on_overflow */ | |
829 | bfd_elf_generic_reloc, /* */ | |
830 | "R_SH_GOTPC", /* name */ | |
831 | true, /* partial_inplace */ | |
832 | 0xffffffff, /* src_mask */ | |
833 | 0xffffffff, /* dst_mask */ | |
834 | true), /* pcrel_offset */ | |
835 | ||
fbca6ad9 AO |
836 | HOWTO (R_SH_GOTPLT32, /* type */ |
837 | 0, /* rightshift */ | |
838 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
839 | 32, /* bitsize */ | |
840 | false, /* pc_relative */ | |
841 | 0, /* bitpos */ | |
842 | complain_overflow_bitfield, /* complain_on_overflow */ | |
843 | bfd_elf_generic_reloc, /* */ | |
844 | "R_SH_GOTPLT32", /* name */ | |
845 | false, /* partial_inplace */ | |
846 | 0xffffffff, /* src_mask */ | |
847 | 0xffffffff, /* dst_mask */ | |
848 | false), /* pcrel_offset */ | |
849 | ||
850 | #ifdef INCLUDE_SHMEDIA | |
851 | /* Used in MOVI and SHORI (x & 65536). */ | |
852 | HOWTO (R_SH_GOT_LOW16, /* type */ | |
853 | 0, /* rightshift */ | |
854 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
855 | 64, /* bitsize */ | |
856 | false, /* pc_relative */ | |
857 | 10, /* bitpos */ | |
858 | complain_overflow_dont, /* complain_on_overflow */ | |
859 | bfd_elf_generic_reloc, /* special_function */ | |
860 | "R_SH_GOT_LOW16", /* name */ | |
861 | false, /* partial_inplace */ | |
862 | 0, /* src_mask */ | |
863 | 0x3fffc00, /* dst_mask */ | |
864 | false), /* pcrel_offset */ | |
865 | ||
866 | /* Used in MOVI and SHORI ((x >> 16) & 65536). */ | |
867 | HOWTO (R_SH_GOT_MEDLOW16, /* type */ | |
868 | 16, /* rightshift */ | |
869 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
870 | 64, /* bitsize */ | |
871 | false, /* pc_relative */ | |
872 | 10, /* bitpos */ | |
873 | complain_overflow_dont, /* complain_on_overflow */ | |
874 | bfd_elf_generic_reloc, /* special_function */ | |
875 | "R_SH_GOT_MEDLOW16", /* name */ | |
876 | false, /* partial_inplace */ | |
877 | 0, /* src_mask */ | |
878 | 0x3fffc00, /* dst_mask */ | |
879 | false), /* pcrel_offset */ | |
880 | ||
881 | /* Used in MOVI and SHORI ((x >> 32) & 65536). */ | |
882 | HOWTO (R_SH_GOT_MEDHI16, /* type */ | |
883 | 32, /* rightshift */ | |
884 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
885 | 64, /* bitsize */ | |
886 | false, /* pc_relative */ | |
887 | 10, /* bitpos */ | |
888 | complain_overflow_dont, /* complain_on_overflow */ | |
889 | bfd_elf_generic_reloc, /* special_function */ | |
890 | "R_SH_GOT_MEDHI16", /* name */ | |
891 | false, /* partial_inplace */ | |
892 | 0, /* src_mask */ | |
893 | 0x3fffc00, /* dst_mask */ | |
894 | false), /* pcrel_offset */ | |
895 | ||
896 | /* Used in MOVI and SHORI ((x >> 48) & 65536). */ | |
897 | HOWTO (R_SH_GOT_HI16, /* type */ | |
898 | 48, /* rightshift */ | |
899 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
900 | 64, /* bitsize */ | |
901 | false, /* pc_relative */ | |
902 | 10, /* bitpos */ | |
903 | complain_overflow_dont, /* complain_on_overflow */ | |
904 | bfd_elf_generic_reloc, /* special_function */ | |
905 | "R_SH_GOT_HI16", /* name */ | |
906 | false, /* partial_inplace */ | |
907 | 0, /* src_mask */ | |
908 | 0x3fffc00, /* dst_mask */ | |
909 | false), /* pcrel_offset */ | |
910 | ||
911 | /* Used in MOVI and SHORI (x & 65536). */ | |
912 | HOWTO (R_SH_GOTPLT_LOW16, /* type */ | |
913 | 0, /* rightshift */ | |
914 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
915 | 64, /* bitsize */ | |
916 | false, /* pc_relative */ | |
917 | 10, /* bitpos */ | |
918 | complain_overflow_dont, /* complain_on_overflow */ | |
919 | bfd_elf_generic_reloc, /* special_function */ | |
920 | "R_SH_GOTPLT_LOW16", /* name */ | |
921 | false, /* partial_inplace */ | |
922 | 0, /* src_mask */ | |
923 | 0x3fffc00, /* dst_mask */ | |
924 | false), /* pcrel_offset */ | |
925 | ||
926 | /* Used in MOVI and SHORI ((x >> 16) & 65536). */ | |
927 | HOWTO (R_SH_GOTPLT_MEDLOW16, /* type */ | |
928 | 16, /* rightshift */ | |
929 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
930 | 64, /* bitsize */ | |
931 | false, /* pc_relative */ | |
932 | 10, /* bitpos */ | |
933 | complain_overflow_dont, /* complain_on_overflow */ | |
934 | bfd_elf_generic_reloc, /* special_function */ | |
935 | "R_SH_GOTPLT_MEDLOW16", /* name */ | |
936 | false, /* partial_inplace */ | |
937 | 0, /* src_mask */ | |
938 | 0x3fffc00, /* dst_mask */ | |
939 | false), /* pcrel_offset */ | |
940 | ||
941 | /* Used in MOVI and SHORI ((x >> 32) & 65536). */ | |
942 | HOWTO (R_SH_GOTPLT_MEDHI16, /* type */ | |
943 | 32, /* rightshift */ | |
944 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
945 | 64, /* bitsize */ | |
946 | false, /* pc_relative */ | |
947 | 10, /* bitpos */ | |
948 | complain_overflow_dont, /* complain_on_overflow */ | |
949 | bfd_elf_generic_reloc, /* special_function */ | |
950 | "R_SH_GOTPLT_MEDHI16", /* name */ | |
951 | false, /* partial_inplace */ | |
952 | 0, /* src_mask */ | |
953 | 0x3fffc00, /* dst_mask */ | |
954 | false), /* pcrel_offset */ | |
955 | ||
956 | /* Used in MOVI and SHORI ((x >> 48) & 65536). */ | |
957 | HOWTO (R_SH_GOTPLT_HI16, /* type */ | |
958 | 48, /* rightshift */ | |
959 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
960 | 64, /* bitsize */ | |
961 | false, /* pc_relative */ | |
962 | 10, /* bitpos */ | |
963 | complain_overflow_dont, /* complain_on_overflow */ | |
964 | bfd_elf_generic_reloc, /* special_function */ | |
965 | "R_SH_GOTPLT_HI16", /* name */ | |
966 | false, /* partial_inplace */ | |
967 | 0, /* src_mask */ | |
968 | 0x3fffc00, /* dst_mask */ | |
969 | false), /* pcrel_offset */ | |
970 | ||
971 | /* Used in MOVI and SHORI (x & 65536). */ | |
972 | HOWTO (R_SH_PLT_LOW16, /* type */ | |
973 | 0, /* rightshift */ | |
974 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
975 | 64, /* bitsize */ | |
976 | true, /* pc_relative */ | |
977 | 10, /* bitpos */ | |
978 | complain_overflow_dont, /* complain_on_overflow */ | |
979 | bfd_elf_generic_reloc, /* special_function */ | |
980 | "R_SH_PLT_LOW16", /* name */ | |
981 | false, /* partial_inplace */ | |
982 | 0, /* src_mask */ | |
983 | 0x3fffc00, /* dst_mask */ | |
984 | true), /* pcrel_offset */ | |
985 | ||
986 | /* Used in MOVI and SHORI ((x >> 16) & 65536). */ | |
987 | HOWTO (R_SH_PLT_MEDLOW16, /* type */ | |
988 | 16, /* rightshift */ | |
989 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
990 | 64, /* bitsize */ | |
991 | true, /* pc_relative */ | |
992 | 10, /* bitpos */ | |
993 | complain_overflow_dont, /* complain_on_overflow */ | |
994 | bfd_elf_generic_reloc, /* special_function */ | |
995 | "R_SH_PLT_MEDLOW16", /* name */ | |
996 | false, /* partial_inplace */ | |
997 | 0, /* src_mask */ | |
998 | 0x3fffc00, /* dst_mask */ | |
999 | true), /* pcrel_offset */ | |
1000 | ||
1001 | /* Used in MOVI and SHORI ((x >> 32) & 65536). */ | |
1002 | HOWTO (R_SH_PLT_MEDHI16, /* type */ | |
1003 | 32, /* rightshift */ | |
1004 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1005 | 64, /* bitsize */ | |
1006 | true, /* pc_relative */ | |
1007 | 10, /* bitpos */ | |
1008 | complain_overflow_dont, /* complain_on_overflow */ | |
1009 | bfd_elf_generic_reloc, /* special_function */ | |
1010 | "R_SH_PLT_MEDHI16", /* name */ | |
1011 | false, /* partial_inplace */ | |
1012 | 0, /* src_mask */ | |
1013 | 0x3fffc00, /* dst_mask */ | |
1014 | true), /* pcrel_offset */ | |
1015 | ||
1016 | /* Used in MOVI and SHORI ((x >> 48) & 65536). */ | |
1017 | HOWTO (R_SH_PLT_HI16, /* type */ | |
1018 | 48, /* rightshift */ | |
1019 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1020 | 64, /* bitsize */ | |
1021 | true, /* pc_relative */ | |
1022 | 10, /* bitpos */ | |
1023 | complain_overflow_dont, /* complain_on_overflow */ | |
1024 | bfd_elf_generic_reloc, /* special_function */ | |
1025 | "R_SH_PLT_HI16", /* name */ | |
1026 | false, /* partial_inplace */ | |
1027 | 0, /* src_mask */ | |
1028 | 0x3fffc00, /* dst_mask */ | |
1029 | true), /* pcrel_offset */ | |
1030 | ||
1031 | /* Used in MOVI and SHORI (x & 65536). */ | |
1032 | HOWTO (R_SH_GOTOFF_LOW16, /* type */ | |
1033 | 0, /* rightshift */ | |
1034 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1035 | 64, /* bitsize */ | |
1036 | false, /* pc_relative */ | |
1037 | 10, /* bitpos */ | |
1038 | complain_overflow_dont, /* complain_on_overflow */ | |
1039 | bfd_elf_generic_reloc, /* special_function */ | |
1040 | "R_SH_GOTOFF_LOW16", /* name */ | |
1041 | false, /* partial_inplace */ | |
1042 | 0, /* src_mask */ | |
1043 | 0x3fffc00, /* dst_mask */ | |
1044 | false), /* pcrel_offset */ | |
1045 | ||
1046 | /* Used in MOVI and SHORI ((x >> 16) & 65536). */ | |
1047 | HOWTO (R_SH_GOTOFF_MEDLOW16, /* type */ | |
1048 | 16, /* rightshift */ | |
1049 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1050 | 64, /* bitsize */ | |
1051 | false, /* pc_relative */ | |
1052 | 10, /* bitpos */ | |
1053 | complain_overflow_dont, /* complain_on_overflow */ | |
1054 | bfd_elf_generic_reloc, /* special_function */ | |
1055 | "R_SH_GOTOFF_MEDLOW16", /* name */ | |
1056 | false, /* partial_inplace */ | |
1057 | 0, /* src_mask */ | |
1058 | 0x3fffc00, /* dst_mask */ | |
1059 | false), /* pcrel_offset */ | |
1060 | ||
1061 | /* Used in MOVI and SHORI ((x >> 32) & 65536). */ | |
1062 | HOWTO (R_SH_GOTOFF_MEDHI16, /* type */ | |
1063 | 32, /* rightshift */ | |
1064 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1065 | 64, /* bitsize */ | |
1066 | false, /* pc_relative */ | |
1067 | 10, /* bitpos */ | |
1068 | complain_overflow_dont, /* complain_on_overflow */ | |
1069 | bfd_elf_generic_reloc, /* special_function */ | |
1070 | "R_SH_GOTOFF_MEDHI16", /* name */ | |
1071 | false, /* partial_inplace */ | |
1072 | 0, /* src_mask */ | |
1073 | 0x3fffc00, /* dst_mask */ | |
1074 | false), /* pcrel_offset */ | |
1075 | ||
1076 | /* Used in MOVI and SHORI ((x >> 48) & 65536). */ | |
1077 | HOWTO (R_SH_GOTOFF_HI16, /* type */ | |
1078 | 48, /* rightshift */ | |
1079 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1080 | 64, /* bitsize */ | |
1081 | false, /* pc_relative */ | |
1082 | 10, /* bitpos */ | |
1083 | complain_overflow_dont, /* complain_on_overflow */ | |
1084 | bfd_elf_generic_reloc, /* special_function */ | |
1085 | "R_SH_GOTOFF_HI16", /* name */ | |
1086 | false, /* partial_inplace */ | |
1087 | 0, /* src_mask */ | |
1088 | 0x3fffc00, /* dst_mask */ | |
1089 | false), /* pcrel_offset */ | |
1090 | ||
1091 | /* Used in MOVI and SHORI (x & 65536). */ | |
1092 | HOWTO (R_SH_GOTPC_LOW16, /* type */ | |
1093 | 0, /* rightshift */ | |
1094 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1095 | 64, /* bitsize */ | |
1096 | true, /* pc_relative */ | |
1097 | 10, /* bitpos */ | |
1098 | complain_overflow_dont, /* complain_on_overflow */ | |
1099 | bfd_elf_generic_reloc, /* special_function */ | |
1100 | "R_SH_GOTPC_LOW16", /* name */ | |
1101 | false, /* partial_inplace */ | |
1102 | 0, /* src_mask */ | |
1103 | 0x3fffc00, /* dst_mask */ | |
1104 | true), /* pcrel_offset */ | |
1105 | ||
1106 | /* Used in MOVI and SHORI ((x >> 16) & 65536). */ | |
1107 | HOWTO (R_SH_GOTPC_MEDLOW16, /* type */ | |
1108 | 16, /* rightshift */ | |
1109 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1110 | 64, /* bitsize */ | |
1111 | true, /* pc_relative */ | |
1112 | 10, /* bitpos */ | |
1113 | complain_overflow_dont, /* complain_on_overflow */ | |
1114 | bfd_elf_generic_reloc, /* special_function */ | |
1115 | "R_SH_GOTPC_MEDLOW16", /* name */ | |
1116 | false, /* partial_inplace */ | |
1117 | 0, /* src_mask */ | |
1118 | 0x3fffc00, /* dst_mask */ | |
1119 | true), /* pcrel_offset */ | |
1120 | ||
1121 | /* Used in MOVI and SHORI ((x >> 32) & 65536). */ | |
1122 | HOWTO (R_SH_GOTPC_MEDHI16, /* type */ | |
1123 | 32, /* rightshift */ | |
1124 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1125 | 64, /* bitsize */ | |
1126 | true, /* pc_relative */ | |
1127 | 10, /* bitpos */ | |
1128 | complain_overflow_dont, /* complain_on_overflow */ | |
1129 | bfd_elf_generic_reloc, /* special_function */ | |
1130 | "R_SH_GOTPC_MEDHI16", /* name */ | |
1131 | false, /* partial_inplace */ | |
1132 | 0, /* src_mask */ | |
1133 | 0x3fffc00, /* dst_mask */ | |
1134 | true), /* pcrel_offset */ | |
1135 | ||
1136 | /* Used in MOVI and SHORI ((x >> 48) & 65536). */ | |
1137 | HOWTO (R_SH_GOTPC_HI16, /* type */ | |
1138 | 48, /* rightshift */ | |
1139 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1140 | 64, /* bitsize */ | |
1141 | true, /* pc_relative */ | |
1142 | 10, /* bitpos */ | |
1143 | complain_overflow_dont, /* complain_on_overflow */ | |
1144 | bfd_elf_generic_reloc, /* special_function */ | |
1145 | "R_SH_GOTPC_HI16", /* name */ | |
1146 | false, /* partial_inplace */ | |
1147 | 0, /* src_mask */ | |
1148 | 0x3fffc00, /* dst_mask */ | |
1149 | true), /* pcrel_offset */ | |
1150 | ||
1151 | /* Used in LD.L, FLD.S et al. */ | |
1152 | HOWTO (R_SH_GOT10BY4, /* type */ | |
1153 | 2, /* rightshift */ | |
1154 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1155 | 12, /* bitsize */ | |
1156 | false, /* pc_relative */ | |
1157 | 10, /* bitpos */ | |
1158 | complain_overflow_signed, /* complain_on_overflow */ | |
1159 | bfd_elf_generic_reloc, /* special_function */ | |
1160 | "R_SH_GOT10BY4", /* name */ | |
1161 | false, /* partial_inplace */ | |
1162 | 0, /* src_mask */ | |
1163 | 0xffc00, /* dst_mask */ | |
1164 | false), /* pcrel_offset */ | |
1165 | ||
1166 | /* Used in LD.L, FLD.S et al. */ | |
1167 | HOWTO (R_SH_GOTPLT10BY4, /* type */ | |
1168 | 2, /* rightshift */ | |
1169 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1170 | 12, /* bitsize */ | |
1171 | false, /* pc_relative */ | |
1172 | 10, /* bitpos */ | |
1173 | complain_overflow_signed, /* complain_on_overflow */ | |
1174 | bfd_elf_generic_reloc, /* special_function */ | |
1175 | "R_SH_GOTPLT10BY4", /* name */ | |
1176 | false, /* partial_inplace */ | |
1177 | 0, /* src_mask */ | |
1178 | 0xffc00, /* dst_mask */ | |
1179 | false), /* pcrel_offset */ | |
1180 | ||
1181 | /* Used in FLD.D, FST.P et al. */ | |
1182 | HOWTO (R_SH_GOT10BY8, /* type */ | |
1183 | 3, /* rightshift */ | |
1184 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1185 | 13, /* bitsize */ | |
1186 | false, /* pc_relative */ | |
1187 | 10, /* bitpos */ | |
1188 | complain_overflow_signed, /* complain_on_overflow */ | |
1189 | bfd_elf_generic_reloc, /* special_function */ | |
1190 | "R_SH_GOT10BY8", /* name */ | |
1191 | false, /* partial_inplace */ | |
1192 | 0, /* src_mask */ | |
1193 | 0xffc00, /* dst_mask */ | |
1194 | false), /* pcrel_offset */ | |
1195 | ||
1196 | /* Used in FLD.D, FST.P et al. */ | |
1197 | HOWTO (R_SH_GOTPLT10BY8, /* type */ | |
1198 | 3, /* rightshift */ | |
1199 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1200 | 13, /* bitsize */ | |
1201 | false, /* pc_relative */ | |
1202 | 10, /* bitpos */ | |
1203 | complain_overflow_signed, /* complain_on_overflow */ | |
1204 | bfd_elf_generic_reloc, /* special_function */ | |
1205 | "R_SH_GOTPLT10BY8", /* name */ | |
1206 | false, /* partial_inplace */ | |
1207 | 0, /* src_mask */ | |
1208 | 0xffc00, /* dst_mask */ | |
1209 | false), /* pcrel_offset */ | |
1210 | ||
1211 | HOWTO (R_SH_COPY64, /* type */ | |
1212 | 0, /* rightshift */ | |
1213 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1214 | 64, /* bitsize */ | |
1215 | false, /* pc_relative */ | |
1216 | 0, /* bitpos */ | |
1217 | complain_overflow_dont, /* complain_on_overflow */ | |
1218 | bfd_elf_generic_reloc, /* special_function */ | |
1219 | "R_SH_COPY64", /* name */ | |
1220 | false, /* partial_inplace */ | |
1221 | 0, /* src_mask */ | |
1222 | ((bfd_vma) 0) - 1, /* dst_mask */ | |
1223 | false), /* pcrel_offset */ | |
1224 | ||
1225 | HOWTO (R_SH_GLOB_DAT64, /* type */ | |
1226 | 0, /* rightshift */ | |
1227 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1228 | 64, /* bitsize */ | |
1229 | false, /* pc_relative */ | |
1230 | 0, /* bitpos */ | |
1231 | complain_overflow_dont, /* complain_on_overflow */ | |
1232 | bfd_elf_generic_reloc, /* special_function */ | |
1233 | "R_SH_GLOB_DAT64", /* name */ | |
1234 | false, /* partial_inplace */ | |
1235 | 0, /* src_mask */ | |
1236 | ((bfd_vma) 0) - 1, /* dst_mask */ | |
1237 | false), /* pcrel_offset */ | |
1238 | ||
1239 | HOWTO (R_SH_JMP_SLOT64, /* type */ | |
1240 | 0, /* rightshift */ | |
1241 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1242 | 64, /* bitsize */ | |
1243 | false, /* pc_relative */ | |
1244 | 0, /* bitpos */ | |
1245 | complain_overflow_dont, /* complain_on_overflow */ | |
1246 | bfd_elf_generic_reloc, /* special_function */ | |
1247 | "R_SH_JMP_SLOT64", /* name */ | |
1248 | false, /* partial_inplace */ | |
1249 | 0, /* src_mask */ | |
1250 | ((bfd_vma) 0) - 1, /* dst_mask */ | |
1251 | false), /* pcrel_offset */ | |
1252 | ||
1253 | HOWTO (R_SH_RELATIVE64, /* type */ | |
1254 | 0, /* rightshift */ | |
1255 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1256 | 64, /* bitsize */ | |
1257 | false, /* pc_relative */ | |
1258 | 0, /* bitpos */ | |
1259 | complain_overflow_dont, /* complain_on_overflow */ | |
1260 | bfd_elf_generic_reloc, /* special_function */ | |
1261 | "R_SH_RELATIVE64", /* name */ | |
1262 | false, /* partial_inplace */ | |
1263 | 0, /* src_mask */ | |
1264 | ((bfd_vma) 0) - 1, /* dst_mask */ | |
1265 | false), /* pcrel_offset */ | |
1266 | ||
1267 | EMPTY_HOWTO (197), | |
1268 | EMPTY_HOWTO (198), | |
1269 | EMPTY_HOWTO (199), | |
1270 | EMPTY_HOWTO (200), | |
1271 | EMPTY_HOWTO (201), | |
1272 | EMPTY_HOWTO (202), | |
1273 | EMPTY_HOWTO (203), | |
1274 | EMPTY_HOWTO (204), | |
1275 | EMPTY_HOWTO (205), | |
1276 | EMPTY_HOWTO (206), | |
1277 | EMPTY_HOWTO (207), | |
1278 | EMPTY_HOWTO (208), | |
1279 | EMPTY_HOWTO (209), | |
1280 | EMPTY_HOWTO (210), | |
1281 | EMPTY_HOWTO (211), | |
1282 | EMPTY_HOWTO (212), | |
1283 | EMPTY_HOWTO (213), | |
1284 | EMPTY_HOWTO (214), | |
1285 | EMPTY_HOWTO (215), | |
1286 | EMPTY_HOWTO (216), | |
1287 | EMPTY_HOWTO (217), | |
1288 | EMPTY_HOWTO (218), | |
1289 | EMPTY_HOWTO (219), | |
1290 | EMPTY_HOWTO (220), | |
1291 | EMPTY_HOWTO (221), | |
1292 | EMPTY_HOWTO (222), | |
1293 | EMPTY_HOWTO (223), | |
1294 | EMPTY_HOWTO (224), | |
1295 | EMPTY_HOWTO (225), | |
1296 | EMPTY_HOWTO (226), | |
1297 | EMPTY_HOWTO (227), | |
1298 | EMPTY_HOWTO (228), | |
1299 | EMPTY_HOWTO (229), | |
1300 | EMPTY_HOWTO (230), | |
1301 | EMPTY_HOWTO (231), | |
1302 | EMPTY_HOWTO (232), | |
1303 | EMPTY_HOWTO (233), | |
1304 | EMPTY_HOWTO (234), | |
1305 | EMPTY_HOWTO (235), | |
1306 | EMPTY_HOWTO (236), | |
1307 | EMPTY_HOWTO (237), | |
1308 | EMPTY_HOWTO (238), | |
1309 | EMPTY_HOWTO (239), | |
1310 | EMPTY_HOWTO (240), | |
1311 | EMPTY_HOWTO (241), | |
1312 | ||
1313 | /* Relocations for SHmedia code. None of these are partial_inplace or | |
1314 | use the field being relocated (except R_SH_PT_16). */ | |
1315 | ||
1316 | /* The assembler will generate this reloc before a block of SHmedia | |
1317 | instructions. A section should be processed as assuming it contains | |
1318 | data, unless this reloc is seen. Note that a block of SHcompact | |
1319 | instructions are instead preceded by R_SH_CODE. | |
1320 | This is currently not implemented, but should be used for SHmedia | |
1321 | linker relaxation. */ | |
1322 | HOWTO (R_SH_SHMEDIA_CODE, /* type */ | |
1323 | 0, /* rightshift */ | |
1324 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1325 | 0, /* bitsize */ | |
1326 | false, /* pc_relative */ | |
1327 | 0, /* bitpos */ | |
1328 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1329 | sh_elf_ignore_reloc, /* special_function */ | |
1330 | "R_SH_SHMEDIA_CODE", /* name */ | |
1331 | false, /* partial_inplace */ | |
1332 | 0, /* src_mask */ | |
1333 | 0, /* dst_mask */ | |
1334 | false), /* pcrel_offset */ | |
1335 | ||
1336 | /* The assembler will generate this reloc at a PTA or PTB instruction, | |
1337 | and the linker checks the right type of target, or changes a PTA to a | |
1338 | PTB, if the original insn was PT. */ | |
1339 | HOWTO (R_SH_PT_16, /* type */ | |
1340 | 2, /* rightshift */ | |
1341 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1342 | 18, /* bitsize */ | |
1343 | true, /* pc_relative */ | |
1344 | 10, /* bitpos */ | |
1345 | complain_overflow_signed, /* complain_on_overflow */ | |
1346 | bfd_elf_generic_reloc, /* special_function */ | |
1347 | "R_SH_PT_16", /* name */ | |
1348 | false, /* partial_inplace */ | |
1349 | 0, /* src_mask */ | |
1350 | 0x3fffc00, /* dst_mask */ | |
1351 | true), /* pcrel_offset */ | |
1352 | ||
1353 | /* Used in unexpanded MOVI. */ | |
1354 | HOWTO (R_SH_IMMS16, /* type */ | |
1355 | 0, /* rightshift */ | |
1356 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1357 | 16, /* bitsize */ | |
1358 | false, /* pc_relative */ | |
1359 | 10, /* bitpos */ | |
1360 | complain_overflow_signed, /* complain_on_overflow */ | |
1361 | bfd_elf_generic_reloc, /* special_function */ | |
1362 | "R_SH_IMMS16", /* name */ | |
1363 | false, /* partial_inplace */ | |
1364 | 0, /* src_mask */ | |
1365 | 0x3fffc00, /* dst_mask */ | |
1366 | false), /* pcrel_offset */ | |
1367 | ||
1368 | /* Used in SHORI. */ | |
1369 | HOWTO (R_SH_IMMU16, /* type */ | |
1370 | 0, /* rightshift */ | |
1371 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1372 | 16, /* bitsize */ | |
1373 | false, /* pc_relative */ | |
1374 | 10, /* bitpos */ | |
1375 | complain_overflow_unsigned, /* complain_on_overflow */ | |
1376 | bfd_elf_generic_reloc, /* special_function */ | |
1377 | "R_SH_IMMU16", /* name */ | |
1378 | false, /* partial_inplace */ | |
1379 | 0, /* src_mask */ | |
1380 | 0x3fffc00, /* dst_mask */ | |
1381 | false), /* pcrel_offset */ | |
1382 | ||
1383 | /* Used in MOVI and SHORI (x & 65536). */ | |
1384 | HOWTO (R_SH_IMM_LOW16, /* type */ | |
1385 | 0, /* rightshift */ | |
1386 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1387 | 64, /* bitsize */ | |
1388 | false, /* pc_relative */ | |
1389 | 10, /* bitpos */ | |
1390 | complain_overflow_dont, /* complain_on_overflow */ | |
1391 | bfd_elf_generic_reloc, /* special_function */ | |
1392 | "R_SH_IMM_LOW16", /* name */ | |
1393 | false, /* partial_inplace */ | |
1394 | 0, /* src_mask */ | |
1395 | 0x3fffc00, /* dst_mask */ | |
1396 | false), /* pcrel_offset */ | |
1397 | ||
1398 | /* Used in MOVI and SHORI ((x - $) & 65536). */ | |
1399 | HOWTO (R_SH_IMM_LOW16_PCREL, /* type */ | |
1400 | 0, /* rightshift */ | |
1401 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1402 | 64, /* bitsize */ | |
1403 | true, /* pc_relative */ | |
1404 | 10, /* bitpos */ | |
1405 | complain_overflow_dont, /* complain_on_overflow */ | |
1406 | bfd_elf_generic_reloc, /* special_function */ | |
1407 | "R_SH_IMM_LOW16_PCREL", /* name */ | |
1408 | false, /* partial_inplace */ | |
1409 | 0, /* src_mask */ | |
1410 | 0x3fffc00, /* dst_mask */ | |
1411 | true), /* pcrel_offset */ | |
1412 | ||
1413 | /* Used in MOVI and SHORI ((x >> 16) & 65536). */ | |
1414 | HOWTO (R_SH_IMM_MEDLOW16, /* type */ | |
1415 | 16, /* rightshift */ | |
1416 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1417 | 64, /* bitsize */ | |
1418 | false, /* pc_relative */ | |
1419 | 10, /* bitpos */ | |
1420 | complain_overflow_dont, /* complain_on_overflow */ | |
1421 | bfd_elf_generic_reloc, /* special_function */ | |
1422 | "R_SH_IMM_MEDLOW16", /* name */ | |
1423 | false, /* partial_inplace */ | |
1424 | 0, /* src_mask */ | |
1425 | 0x3fffc00, /* dst_mask */ | |
1426 | false), /* pcrel_offset */ | |
1427 | ||
1428 | /* Used in MOVI and SHORI (((x - $) >> 16) & 65536). */ | |
1429 | HOWTO (R_SH_IMM_MEDLOW16_PCREL, /* type */ | |
1430 | 16, /* rightshift */ | |
1431 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1432 | 64, /* bitsize */ | |
1433 | true, /* pc_relative */ | |
1434 | 10, /* bitpos */ | |
1435 | complain_overflow_dont, /* complain_on_overflow */ | |
1436 | bfd_elf_generic_reloc, /* special_function */ | |
1437 | "R_SH_IMM_MEDLOW16_PCREL", /* name */ | |
1438 | false, /* partial_inplace */ | |
1439 | 0, /* src_mask */ | |
1440 | 0x3fffc00, /* dst_mask */ | |
1441 | true), /* pcrel_offset */ | |
1442 | ||
1443 | /* Used in MOVI and SHORI ((x >> 32) & 65536). */ | |
1444 | HOWTO (R_SH_IMM_MEDHI16, /* type */ | |
1445 | 32, /* rightshift */ | |
1446 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1447 | 64, /* bitsize */ | |
1448 | false, /* pc_relative */ | |
1449 | 10, /* bitpos */ | |
1450 | complain_overflow_dont, /* complain_on_overflow */ | |
1451 | bfd_elf_generic_reloc, /* special_function */ | |
1452 | "R_SH_IMM_MEDHI16", /* name */ | |
1453 | false, /* partial_inplace */ | |
1454 | 0, /* src_mask */ | |
1455 | 0x3fffc00, /* dst_mask */ | |
1456 | false), /* pcrel_offset */ | |
1457 | ||
1458 | /* Used in MOVI and SHORI (((x - $) >> 32) & 65536). */ | |
1459 | HOWTO (R_SH_IMM_MEDHI16_PCREL, /* type */ | |
1460 | 32, /* rightshift */ | |
1461 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1462 | 64, /* bitsize */ | |
1463 | true, /* pc_relative */ | |
1464 | 10, /* bitpos */ | |
1465 | complain_overflow_dont, /* complain_on_overflow */ | |
1466 | bfd_elf_generic_reloc, /* special_function */ | |
1467 | "R_SH_IMM_MEDHI16_PCREL", /* name */ | |
1468 | false, /* partial_inplace */ | |
1469 | 0, /* src_mask */ | |
1470 | 0x3fffc00, /* dst_mask */ | |
1471 | true), /* pcrel_offset */ | |
1472 | ||
1473 | /* Used in MOVI and SHORI ((x >> 48) & 65536). */ | |
1474 | HOWTO (R_SH_IMM_HI16, /* type */ | |
1475 | 48, /* rightshift */ | |
1476 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1477 | 64, /* bitsize */ | |
1478 | false, /* pc_relative */ | |
1479 | 10, /* bitpos */ | |
1480 | complain_overflow_dont, /* complain_on_overflow */ | |
1481 | bfd_elf_generic_reloc, /* special_function */ | |
1482 | "R_SH_IMM_HI16", /* name */ | |
1483 | false, /* partial_inplace */ | |
1484 | 0, /* src_mask */ | |
1485 | 0x3fffc00, /* dst_mask */ | |
1486 | false), /* pcrel_offset */ | |
1487 | ||
1488 | /* Used in MOVI and SHORI (((x - $) >> 48) & 65536). */ | |
1489 | HOWTO (R_SH_IMM_HI16_PCREL, /* type */ | |
1490 | 48, /* rightshift */ | |
1491 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1492 | 64, /* bitsize */ | |
1493 | true, /* pc_relative */ | |
1494 | 10, /* bitpos */ | |
1495 | complain_overflow_dont, /* complain_on_overflow */ | |
1496 | bfd_elf_generic_reloc, /* special_function */ | |
1497 | "R_SH_IMM_HI16_PCREL", /* name */ | |
1498 | false, /* partial_inplace */ | |
1499 | 0, /* src_mask */ | |
1500 | 0x3fffc00, /* dst_mask */ | |
1501 | true), /* pcrel_offset */ | |
1502 | ||
1503 | /* For the .uaquad pseudo. */ | |
1504 | HOWTO (R_SH_64, /* type */ | |
1505 | 0, /* rightshift */ | |
1506 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1507 | 64, /* bitsize */ | |
1508 | false, /* pc_relative */ | |
1509 | 0, /* bitpos */ | |
1510 | complain_overflow_dont, /* complain_on_overflow */ | |
1511 | bfd_elf_generic_reloc, /* special_function */ | |
1512 | "R_SH_64", /* name */ | |
1513 | false, /* partial_inplace */ | |
1514 | 0, /* src_mask */ | |
1515 | ((bfd_vma) 0) - 1, /* dst_mask */ | |
1516 | false), /* pcrel_offset */ | |
1517 | ||
1518 | /* For the .uaquad pseudo, (x - $). */ | |
1519 | HOWTO (R_SH_64_PCREL, /* type */ | |
1520 | 48, /* rightshift */ | |
1521 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1522 | 64, /* bitsize */ | |
1523 | true, /* pc_relative */ | |
1524 | 10, /* bitpos */ | |
1525 | complain_overflow_dont, /* complain_on_overflow */ | |
1526 | bfd_elf_generic_reloc, /* special_function */ | |
1527 | "R_SH_64_PCREL", /* name */ | |
1528 | false, /* partial_inplace */ | |
1529 | 0, /* src_mask */ | |
1530 | ((bfd_vma) 0) - 1, /* dst_mask */ | |
1531 | true), /* pcrel_offset */ | |
1532 | ||
1533 | #endif | |
252b5132 RH |
1534 | }; |
1535 | ||
015551fc JR |
1536 | static bfd_reloc_status_type |
1537 | sh_elf_reloc_loop (r_type, input_bfd, input_section, contents, addr, | |
435b1e90 | 1538 | symbol_section, start, end) |
61ff1804 | 1539 | int r_type ATTRIBUTE_UNUSED; |
015551fc JR |
1540 | bfd *input_bfd; |
1541 | asection *input_section; | |
1542 | bfd_byte *contents; | |
1543 | bfd_vma addr; | |
1544 | asection *symbol_section; | |
1545 | bfd_vma start, end; | |
1546 | { | |
1547 | static bfd_vma last_addr; | |
00fdaf47 | 1548 | static asection *last_symbol_section; |
015551fc JR |
1549 | bfd_byte *free_contents = NULL; |
1550 | bfd_byte *start_ptr, *ptr, *last_ptr; | |
1551 | int diff, cum_diff; | |
1552 | bfd_signed_vma x; | |
1553 | int insn; | |
1554 | ||
1555 | /* Sanity check the address. */ | |
1556 | if (addr > input_section->_raw_size) | |
1557 | return bfd_reloc_outofrange; | |
1558 | ||
1559 | /* We require the start and end relocations to be processed consecutively - | |
1560 | although we allow then to be processed forwards or backwards. */ | |
1561 | if (! last_addr) | |
1562 | { | |
1563 | last_addr = addr; | |
1564 | last_symbol_section = symbol_section; | |
1565 | return bfd_reloc_ok; | |
1566 | } | |
1567 | if (last_addr != addr) | |
1568 | abort (); | |
1569 | last_addr = 0; | |
1570 | ||
1571 | if (! symbol_section || last_symbol_section != symbol_section || end < start) | |
1572 | return bfd_reloc_outofrange; | |
1573 | ||
1574 | /* Get the symbol_section contents. */ | |
1575 | if (symbol_section != input_section) | |
1576 | { | |
1577 | if (elf_section_data (symbol_section)->this_hdr.contents != NULL) | |
1578 | contents = elf_section_data (symbol_section)->this_hdr.contents; | |
1579 | else | |
1580 | { | |
dc810e39 | 1581 | contents = (bfd_byte *) bfd_malloc (symbol_section->_raw_size); |
015551fc JR |
1582 | if (contents == NULL) |
1583 | return bfd_reloc_outofrange; | |
dc810e39 | 1584 | free_contents = contents; |
015551fc JR |
1585 | if (! bfd_get_section_contents (input_bfd, symbol_section, contents, |
1586 | (file_ptr) 0, | |
1587 | symbol_section->_raw_size)) | |
1588 | { | |
1589 | free (contents); | |
1590 | return bfd_reloc_outofrange; | |
1591 | } | |
1592 | } | |
1593 | } | |
1594 | #define IS_PPI(PTR) ((bfd_get_16 (input_bfd, (PTR)) & 0xfc00) == 0xf800) | |
1595 | start_ptr = contents + start; | |
1596 | for (cum_diff = -6, ptr = contents + end; cum_diff < 0 && ptr > start_ptr;) | |
1597 | { | |
1598 | for (last_ptr = ptr, ptr -= 4; ptr >= start_ptr && IS_PPI (ptr);) | |
1599 | ptr -= 2; | |
1600 | ptr += 2; | |
61ff1804 | 1601 | diff = (last_ptr - ptr) >> 1; |
015551fc JR |
1602 | cum_diff += diff & 1; |
1603 | cum_diff += diff; | |
1604 | } | |
1605 | /* Calculate the start / end values to load into rs / re minus four - | |
1606 | so that will cancel out the four we would otherwise have to add to | |
1607 | addr to get the value to subtract in order to get relative addressing. */ | |
1608 | if (cum_diff >= 0) | |
1609 | { | |
1610 | start -= 4; | |
1611 | end = (ptr + cum_diff * 2) - contents; | |
1612 | } | |
1613 | else | |
1614 | { | |
1615 | bfd_vma start0 = start - 4; | |
1616 | ||
a0fc8ba1 | 1617 | while (start0 && IS_PPI (contents + start0)) |
015551fc JR |
1618 | start0 -= 2; |
1619 | start0 = start - 2 - ((start - start0) & 2); | |
1620 | start = start0 - cum_diff - 2; | |
1621 | end = start0; | |
1622 | } | |
1623 | ||
1624 | if (free_contents) | |
1625 | free (free_contents); | |
1626 | ||
1627 | insn = bfd_get_16 (input_bfd, contents + addr); | |
1628 | ||
1629 | x = (insn & 0x200 ? end : start) - addr; | |
1630 | if (input_section != symbol_section) | |
1631 | x += ((symbol_section->output_section->vma + symbol_section->output_offset) | |
1632 | - (input_section->output_section->vma | |
1633 | + input_section->output_offset)); | |
1634 | x >>= 1; | |
1635 | if (x < -128 || x > 127) | |
1636 | return bfd_reloc_overflow; | |
1637 | ||
61ff1804 | 1638 | x = (insn & ~0xff) | (x & 0xff); |
dc810e39 | 1639 | bfd_put_16 (input_bfd, (bfd_vma) x, contents + addr); |
015551fc JR |
1640 | |
1641 | return bfd_reloc_ok; | |
1642 | } | |
1643 | ||
1644 | /* This function is used for normal relocs. This used to be like the COFF | |
252b5132 RH |
1645 | function, and is almost certainly incorrect for other ELF targets. */ |
1646 | ||
1647 | static bfd_reloc_status_type | |
1648 | sh_elf_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd, | |
435b1e90 | 1649 | error_message) |
252b5132 RH |
1650 | bfd *abfd; |
1651 | arelent *reloc_entry; | |
1652 | asymbol *symbol_in; | |
1653 | PTR data; | |
1654 | asection *input_section; | |
1655 | bfd *output_bfd; | |
5f771d47 | 1656 | char **error_message ATTRIBUTE_UNUSED; |
252b5132 RH |
1657 | { |
1658 | unsigned long insn; | |
1659 | bfd_vma sym_value; | |
1660 | enum elf_sh_reloc_type r_type; | |
1661 | bfd_vma addr = reloc_entry->address; | |
1662 | bfd_byte *hit_data = addr + (bfd_byte *) data; | |
1663 | ||
1664 | r_type = (enum elf_sh_reloc_type) reloc_entry->howto->type; | |
1665 | ||
1666 | if (output_bfd != NULL) | |
1667 | { | |
1668 | /* Partial linking--do nothing. */ | |
1669 | reloc_entry->address += input_section->output_offset; | |
1670 | return bfd_reloc_ok; | |
1671 | } | |
1672 | ||
1673 | /* Almost all relocs have to do with relaxing. If any work must be | |
1674 | done for them, it has been done in sh_relax_section. */ | |
015551fc | 1675 | if (r_type == R_SH_IND12W && (symbol_in->flags & BSF_LOCAL) != 0) |
252b5132 RH |
1676 | return bfd_reloc_ok; |
1677 | ||
1678 | if (symbol_in != NULL | |
1679 | && bfd_is_und_section (symbol_in->section)) | |
1680 | return bfd_reloc_undefined; | |
1681 | ||
1682 | if (bfd_is_com_section (symbol_in->section)) | |
435b1e90 KH |
1683 | sym_value = 0; |
1684 | else | |
252b5132 RH |
1685 | sym_value = (symbol_in->value + |
1686 | symbol_in->section->output_section->vma + | |
1687 | symbol_in->section->output_offset); | |
1688 | ||
1689 | switch (r_type) | |
1690 | { | |
1691 | case R_SH_DIR32: | |
1692 | insn = bfd_get_32 (abfd, hit_data); | |
1693 | insn += sym_value + reloc_entry->addend; | |
dc810e39 | 1694 | bfd_put_32 (abfd, (bfd_vma) insn, hit_data); |
252b5132 RH |
1695 | break; |
1696 | case R_SH_IND12W: | |
1697 | insn = bfd_get_16 (abfd, hit_data); | |
1698 | sym_value += reloc_entry->addend; | |
1699 | sym_value -= (input_section->output_section->vma | |
1700 | + input_section->output_offset | |
1701 | + addr | |
1702 | + 4); | |
1703 | sym_value += (insn & 0xfff) << 1; | |
1704 | if (insn & 0x800) | |
1705 | sym_value -= 0x1000; | |
1706 | insn = (insn & 0xf000) | (sym_value & 0xfff); | |
dc810e39 | 1707 | bfd_put_16 (abfd, (bfd_vma) insn, hit_data); |
252b5132 RH |
1708 | if (sym_value < (bfd_vma) -0x1000 || sym_value >= 0x1000) |
1709 | return bfd_reloc_overflow; | |
1710 | break; | |
1711 | default: | |
1712 | abort (); | |
1713 | break; | |
1714 | } | |
1715 | ||
1716 | return bfd_reloc_ok; | |
1717 | } | |
1718 | ||
1719 | /* This function is used for relocs which are only used for relaxing, | |
1720 | which the linker should otherwise ignore. */ | |
1721 | ||
1722 | static bfd_reloc_status_type | |
1723 | sh_elf_ignore_reloc (abfd, reloc_entry, symbol, data, input_section, | |
1724 | output_bfd, error_message) | |
5f771d47 | 1725 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 | 1726 | arelent *reloc_entry; |
5f771d47 ILT |
1727 | asymbol *symbol ATTRIBUTE_UNUSED; |
1728 | PTR data ATTRIBUTE_UNUSED; | |
252b5132 RH |
1729 | asection *input_section; |
1730 | bfd *output_bfd; | |
5f771d47 | 1731 | char **error_message ATTRIBUTE_UNUSED; |
252b5132 RH |
1732 | { |
1733 | if (output_bfd != NULL) | |
1734 | reloc_entry->address += input_section->output_offset; | |
1735 | return bfd_reloc_ok; | |
1736 | } | |
1737 | ||
1738 | /* This structure is used to map BFD reloc codes to SH ELF relocs. */ | |
1739 | ||
38b1a46c NC |
1740 | struct elf_reloc_map |
1741 | { | |
252b5132 RH |
1742 | bfd_reloc_code_real_type bfd_reloc_val; |
1743 | unsigned char elf_reloc_val; | |
1744 | }; | |
1745 | ||
1746 | /* An array mapping BFD reloc codes to SH ELF relocs. */ | |
1747 | ||
38b1a46c NC |
1748 | static const struct elf_reloc_map sh_reloc_map[] = |
1749 | { | |
252b5132 RH |
1750 | { BFD_RELOC_NONE, R_SH_NONE }, |
1751 | { BFD_RELOC_32, R_SH_DIR32 }, | |
1752 | { BFD_RELOC_CTOR, R_SH_DIR32 }, | |
1753 | { BFD_RELOC_32_PCREL, R_SH_REL32 }, | |
1754 | { BFD_RELOC_SH_PCDISP8BY2, R_SH_DIR8WPN }, | |
1755 | { BFD_RELOC_SH_PCDISP12BY2, R_SH_IND12W }, | |
1756 | { BFD_RELOC_SH_PCRELIMM8BY2, R_SH_DIR8WPZ }, | |
1757 | { BFD_RELOC_SH_PCRELIMM8BY4, R_SH_DIR8WPL }, | |
1758 | { BFD_RELOC_8_PCREL, R_SH_SWITCH8 }, | |
1759 | { BFD_RELOC_SH_SWITCH16, R_SH_SWITCH16 }, | |
1760 | { BFD_RELOC_SH_SWITCH32, R_SH_SWITCH32 }, | |
1761 | { BFD_RELOC_SH_USES, R_SH_USES }, | |
1762 | { BFD_RELOC_SH_COUNT, R_SH_COUNT }, | |
1763 | { BFD_RELOC_SH_ALIGN, R_SH_ALIGN }, | |
1764 | { BFD_RELOC_SH_CODE, R_SH_CODE }, | |
1765 | { BFD_RELOC_SH_DATA, R_SH_DATA }, | |
1766 | { BFD_RELOC_SH_LABEL, R_SH_LABEL }, | |
1767 | { BFD_RELOC_VTABLE_INHERIT, R_SH_GNU_VTINHERIT }, | |
1768 | { BFD_RELOC_VTABLE_ENTRY, R_SH_GNU_VTENTRY }, | |
015551fc JR |
1769 | { BFD_RELOC_SH_LOOP_START, R_SH_LOOP_START }, |
1770 | { BFD_RELOC_SH_LOOP_END, R_SH_LOOP_END }, | |
37c644f2 AO |
1771 | { BFD_RELOC_32_GOT_PCREL, R_SH_GOT32 }, |
1772 | { BFD_RELOC_32_PLT_PCREL, R_SH_PLT32 }, | |
1773 | { BFD_RELOC_SH_COPY, R_SH_COPY }, | |
1774 | { BFD_RELOC_SH_GLOB_DAT, R_SH_GLOB_DAT }, | |
1775 | { BFD_RELOC_SH_JMP_SLOT, R_SH_JMP_SLOT }, | |
1776 | { BFD_RELOC_SH_RELATIVE, R_SH_RELATIVE }, | |
1777 | { BFD_RELOC_32_GOTOFF, R_SH_GOTOFF }, | |
1778 | { BFD_RELOC_SH_GOTPC, R_SH_GOTPC }, | |
fbca6ad9 AO |
1779 | { BFD_RELOC_SH_GOTPLT32, R_SH_GOTPLT32 }, |
1780 | #ifdef INCLUDE_SHMEDIA | |
1781 | { BFD_RELOC_SH_GOT_LOW16, R_SH_GOT_LOW16 }, | |
1782 | { BFD_RELOC_SH_GOT_MEDLOW16, R_SH_GOT_MEDLOW16 }, | |
1783 | { BFD_RELOC_SH_GOT_MEDHI16, R_SH_GOT_MEDHI16 }, | |
1784 | { BFD_RELOC_SH_GOT_HI16, R_SH_GOT_HI16 }, | |
1785 | { BFD_RELOC_SH_GOTPLT_LOW16, R_SH_GOTPLT_LOW16 }, | |
1786 | { BFD_RELOC_SH_GOTPLT_MEDLOW16, R_SH_GOTPLT_MEDLOW16 }, | |
1787 | { BFD_RELOC_SH_GOTPLT_MEDHI16, R_SH_GOTPLT_MEDHI16 }, | |
1788 | { BFD_RELOC_SH_GOTPLT_HI16, R_SH_GOTPLT_HI16 }, | |
1789 | { BFD_RELOC_SH_PLT_LOW16, R_SH_PLT_LOW16 }, | |
1790 | { BFD_RELOC_SH_PLT_MEDLOW16, R_SH_PLT_MEDLOW16 }, | |
1791 | { BFD_RELOC_SH_PLT_MEDHI16, R_SH_PLT_MEDHI16 }, | |
1792 | { BFD_RELOC_SH_PLT_HI16, R_SH_PLT_HI16 }, | |
1793 | { BFD_RELOC_SH_GOTOFF_LOW16, R_SH_GOTOFF_LOW16 }, | |
1794 | { BFD_RELOC_SH_GOTOFF_MEDLOW16, R_SH_GOTOFF_MEDLOW16 }, | |
1795 | { BFD_RELOC_SH_GOTOFF_MEDHI16, R_SH_GOTOFF_MEDHI16 }, | |
1796 | { BFD_RELOC_SH_GOTOFF_HI16, R_SH_GOTOFF_HI16 }, | |
1797 | { BFD_RELOC_SH_GOTPC_LOW16, R_SH_GOTPC_LOW16 }, | |
1798 | { BFD_RELOC_SH_GOTPC_MEDLOW16, R_SH_GOTPC_MEDLOW16 }, | |
1799 | { BFD_RELOC_SH_GOTPC_MEDHI16, R_SH_GOTPC_MEDHI16 }, | |
1800 | { BFD_RELOC_SH_GOTPC_HI16, R_SH_GOTPC_HI16 }, | |
1801 | { BFD_RELOC_SH_COPY64, R_SH_COPY64 }, | |
1802 | { BFD_RELOC_SH_GLOB_DAT64, R_SH_GLOB_DAT64 }, | |
1803 | { BFD_RELOC_SH_JMP_SLOT64, R_SH_JMP_SLOT64 }, | |
1804 | { BFD_RELOC_SH_RELATIVE64, R_SH_RELATIVE64 }, | |
1805 | { BFD_RELOC_SH_GOT10BY4, R_SH_GOT10BY4 }, | |
1806 | { BFD_RELOC_SH_GOT10BY8, R_SH_GOT10BY8 }, | |
1807 | { BFD_RELOC_SH_GOTPLT10BY4, R_SH_GOTPLT10BY4 }, | |
1808 | { BFD_RELOC_SH_GOTPLT10BY8, R_SH_GOTPLT10BY8 }, | |
1809 | { BFD_RELOC_SH_PT_16, R_SH_PT_16 }, | |
1810 | { BFD_RELOC_SH_SHMEDIA_CODE, R_SH_SHMEDIA_CODE }, | |
1811 | { BFD_RELOC_SH_IMMU5, R_SH_DIR5U }, | |
1812 | { BFD_RELOC_SH_IMMS6, R_SH_DIR6S }, | |
1813 | { BFD_RELOC_SH_IMMU6, R_SH_DIR6U }, | |
1814 | { BFD_RELOC_SH_IMMS10, R_SH_DIR10S }, | |
1815 | { BFD_RELOC_SH_IMMS10BY2, R_SH_DIR10SW }, | |
1816 | { BFD_RELOC_SH_IMMS10BY4, R_SH_DIR10SL }, | |
1817 | { BFD_RELOC_SH_IMMS10BY8, R_SH_DIR10SQ }, | |
1818 | { BFD_RELOC_SH_IMMS16, R_SH_IMMS16 }, | |
1819 | { BFD_RELOC_SH_IMMU16, R_SH_IMMU16 }, | |
1820 | { BFD_RELOC_SH_IMM_LOW16, R_SH_IMM_LOW16 }, | |
1821 | { BFD_RELOC_SH_IMM_LOW16_PCREL, R_SH_IMM_LOW16_PCREL }, | |
1822 | { BFD_RELOC_SH_IMM_MEDLOW16, R_SH_IMM_MEDLOW16 }, | |
1823 | { BFD_RELOC_SH_IMM_MEDLOW16_PCREL, R_SH_IMM_MEDLOW16_PCREL }, | |
1824 | { BFD_RELOC_SH_IMM_MEDHI16, R_SH_IMM_MEDHI16 }, | |
1825 | { BFD_RELOC_SH_IMM_MEDHI16_PCREL, R_SH_IMM_MEDHI16_PCREL }, | |
1826 | { BFD_RELOC_SH_IMM_HI16, R_SH_IMM_HI16 }, | |
1827 | { BFD_RELOC_SH_IMM_HI16_PCREL, R_SH_IMM_HI16_PCREL }, | |
1828 | { BFD_RELOC_64, R_SH_64 }, | |
1829 | { BFD_RELOC_64_PCREL, R_SH_64_PCREL }, | |
1830 | #endif /* not INCLUDE_SHMEDIA */ | |
252b5132 RH |
1831 | }; |
1832 | ||
1833 | /* Given a BFD reloc code, return the howto structure for the | |
1834 | corresponding SH ELf reloc. */ | |
1835 | ||
1836 | static reloc_howto_type * | |
1837 | sh_elf_reloc_type_lookup (abfd, code) | |
5f771d47 | 1838 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
1839 | bfd_reloc_code_real_type code; |
1840 | { | |
1841 | unsigned int i; | |
1842 | ||
1843 | for (i = 0; i < sizeof (sh_reloc_map) / sizeof (struct elf_reloc_map); i++) | |
1844 | { | |
1845 | if (sh_reloc_map[i].bfd_reloc_val == code) | |
1846 | return &sh_elf_howto_table[(int) sh_reloc_map[i].elf_reloc_val]; | |
1847 | } | |
1848 | ||
1849 | return NULL; | |
1850 | } | |
1851 | ||
1852 | /* Given an ELF reloc, fill in the howto field of a relent. */ | |
1853 | ||
1854 | static void | |
1855 | sh_elf_info_to_howto (abfd, cache_ptr, dst) | |
5f771d47 | 1856 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
1857 | arelent *cache_ptr; |
1858 | Elf_Internal_Rela *dst; | |
1859 | { | |
1860 | unsigned int r; | |
1861 | ||
1862 | r = ELF32_R_TYPE (dst->r_info); | |
1863 | ||
1864 | BFD_ASSERT (r < (unsigned int) R_SH_max); | |
1865 | BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC || r > R_SH_LAST_INVALID_RELOC); | |
06bb75c1 | 1866 | BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_2 || r > R_SH_LAST_INVALID_RELOC_2); |
fbca6ad9 AO |
1867 | BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_3 || r > R_SH_LAST_INVALID_RELOC_3); |
1868 | BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_4 || r > R_SH_LAST_INVALID_RELOC_4); | |
252b5132 RH |
1869 | |
1870 | cache_ptr->howto = &sh_elf_howto_table[r]; | |
1871 | } | |
1872 | \f | |
1873 | /* This function handles relaxing for SH ELF. See the corresponding | |
1874 | function in coff-sh.c for a description of what this does. FIXME: | |
1875 | There is a lot of duplication here between this code and the COFF | |
1876 | specific code. The format of relocs and symbols is wound deeply | |
1877 | into this code, but it would still be better if the duplication | |
1878 | could be eliminated somehow. Note in particular that although both | |
1879 | functions use symbols like R_SH_CODE, those symbols have different | |
1880 | values; in coff-sh.c they come from include/coff/sh.h, whereas here | |
1881 | they come from enum elf_sh_reloc_type in include/elf/sh.h. */ | |
1882 | ||
435b1e90 | 1883 | static boolean |
252b5132 RH |
1884 | sh_elf_relax_section (abfd, sec, link_info, again) |
1885 | bfd *abfd; | |
1886 | asection *sec; | |
1887 | struct bfd_link_info *link_info; | |
1888 | boolean *again; | |
1889 | { | |
1890 | Elf_Internal_Shdr *symtab_hdr; | |
9ad5cbcf | 1891 | Elf_Internal_Shdr *shndx_hdr; |
252b5132 RH |
1892 | Elf_Internal_Rela *internal_relocs; |
1893 | Elf_Internal_Rela *free_relocs = NULL; | |
1894 | boolean have_code; | |
1895 | Elf_Internal_Rela *irel, *irelend; | |
1896 | bfd_byte *contents = NULL; | |
1897 | bfd_byte *free_contents = NULL; | |
1898 | Elf32_External_Sym *extsyms = NULL; | |
1899 | Elf32_External_Sym *free_extsyms = NULL; | |
9ad5cbcf | 1900 | Elf_External_Sym_Shndx *shndx_buf = NULL; |
252b5132 RH |
1901 | |
1902 | *again = false; | |
1903 | ||
1904 | if (link_info->relocateable | |
1905 | || (sec->flags & SEC_RELOC) == 0 | |
1906 | || sec->reloc_count == 0) | |
1907 | return true; | |
1908 | ||
fbca6ad9 AO |
1909 | #ifdef INCLUDE_SHMEDIA |
1910 | if (elf_section_data (sec)->this_hdr.sh_flags | |
1911 | & (SHF_SH5_ISA32 | SHF_SH5_ISA32_MIXED)) | |
1912 | { | |
1913 | return true; | |
1914 | } | |
1915 | #endif | |
1916 | ||
252b5132 RH |
1917 | /* If this is the first time we have been called for this section, |
1918 | initialize the cooked size. */ | |
1919 | if (sec->_cooked_size == 0) | |
1920 | sec->_cooked_size = sec->_raw_size; | |
1921 | ||
1922 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
9ad5cbcf | 1923 | shndx_hdr = &elf_tdata (abfd)->symtab_shndx_hdr; |
252b5132 RH |
1924 | |
1925 | internal_relocs = (_bfd_elf32_link_read_relocs | |
1926 | (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL, | |
1927 | link_info->keep_memory)); | |
1928 | if (internal_relocs == NULL) | |
1929 | goto error_return; | |
1930 | if (! link_info->keep_memory) | |
1931 | free_relocs = internal_relocs; | |
1932 | ||
1933 | have_code = false; | |
1934 | ||
1935 | irelend = internal_relocs + sec->reloc_count; | |
1936 | for (irel = internal_relocs; irel < irelend; irel++) | |
1937 | { | |
1938 | bfd_vma laddr, paddr, symval; | |
1939 | unsigned short insn; | |
1940 | Elf_Internal_Rela *irelfn, *irelscan, *irelcount; | |
1941 | bfd_signed_vma foff; | |
1942 | ||
1943 | if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_CODE) | |
1944 | have_code = true; | |
1945 | ||
1946 | if (ELF32_R_TYPE (irel->r_info) != (int) R_SH_USES) | |
1947 | continue; | |
1948 | ||
1949 | /* Get the section contents. */ | |
1950 | if (contents == NULL) | |
1951 | { | |
1952 | if (elf_section_data (sec)->this_hdr.contents != NULL) | |
1953 | contents = elf_section_data (sec)->this_hdr.contents; | |
1954 | else | |
1955 | { | |
1956 | contents = (bfd_byte *) bfd_malloc (sec->_raw_size); | |
1957 | if (contents == NULL) | |
1958 | goto error_return; | |
1959 | free_contents = contents; | |
1960 | ||
1961 | if (! bfd_get_section_contents (abfd, sec, contents, | |
1962 | (file_ptr) 0, sec->_raw_size)) | |
1963 | goto error_return; | |
1964 | } | |
1965 | } | |
1966 | ||
1967 | /* The r_addend field of the R_SH_USES reloc will point us to | |
1968 | the register load. The 4 is because the r_addend field is | |
1969 | computed as though it were a jump offset, which are based | |
1970 | from 4 bytes after the jump instruction. */ | |
1971 | laddr = irel->r_offset + 4 + irel->r_addend; | |
1972 | if (laddr >= sec->_raw_size) | |
1973 | { | |
1974 | (*_bfd_error_handler) (_("%s: 0x%lx: warning: bad R_SH_USES offset"), | |
8f615d07 | 1975 | bfd_archive_filename (abfd), |
252b5132 RH |
1976 | (unsigned long) irel->r_offset); |
1977 | continue; | |
1978 | } | |
1979 | insn = bfd_get_16 (abfd, contents + laddr); | |
1980 | ||
1981 | /* If the instruction is not mov.l NN,rN, we don't know what to | |
1982 | do. */ | |
1983 | if ((insn & 0xf000) != 0xd000) | |
1984 | { | |
1985 | ((*_bfd_error_handler) | |
1986 | (_("%s: 0x%lx: warning: R_SH_USES points to unrecognized insn 0x%x"), | |
8f615d07 | 1987 | bfd_archive_filename (abfd), (unsigned long) irel->r_offset, insn)); |
252b5132 RH |
1988 | continue; |
1989 | } | |
1990 | ||
1991 | /* Get the address from which the register is being loaded. The | |
99e4ae17 AJ |
1992 | displacement in the mov.l instruction is quadrupled. It is a |
1993 | displacement from four bytes after the movl instruction, but, | |
1994 | before adding in the PC address, two least significant bits | |
1995 | of the PC are cleared. We assume that the section is aligned | |
1996 | on a four byte boundary. */ | |
252b5132 RH |
1997 | paddr = insn & 0xff; |
1998 | paddr *= 4; | |
dc810e39 | 1999 | paddr += (laddr + 4) &~ (bfd_vma) 3; |
252b5132 RH |
2000 | if (paddr >= sec->_raw_size) |
2001 | { | |
2002 | ((*_bfd_error_handler) | |
2003 | (_("%s: 0x%lx: warning: bad R_SH_USES load offset"), | |
8f615d07 | 2004 | bfd_archive_filename (abfd), (unsigned long) irel->r_offset)); |
252b5132 RH |
2005 | continue; |
2006 | } | |
2007 | ||
2008 | /* Get the reloc for the address from which the register is | |
2009 | being loaded. This reloc will tell us which function is | |
2010 | actually being called. */ | |
2011 | for (irelfn = internal_relocs; irelfn < irelend; irelfn++) | |
2012 | if (irelfn->r_offset == paddr | |
2013 | && ELF32_R_TYPE (irelfn->r_info) == (int) R_SH_DIR32) | |
2014 | break; | |
2015 | if (irelfn >= irelend) | |
2016 | { | |
2017 | ((*_bfd_error_handler) | |
2018 | (_("%s: 0x%lx: warning: could not find expected reloc"), | |
8f615d07 | 2019 | bfd_archive_filename (abfd), (unsigned long) paddr)); |
252b5132 RH |
2020 | continue; |
2021 | } | |
2022 | ||
2023 | /* Read this BFD's symbols if we haven't done so already. */ | |
2024 | if (extsyms == NULL) | |
2025 | { | |
2026 | if (symtab_hdr->contents != NULL) | |
2027 | extsyms = (Elf32_External_Sym *) symtab_hdr->contents; | |
2028 | else | |
2029 | { | |
9ad5cbcf AM |
2030 | bfd_size_type amt; |
2031 | ||
2032 | amt = symtab_hdr->sh_info; | |
2033 | amt *= sizeof (Elf32_External_Sym); | |
2034 | extsyms = (Elf32_External_Sym *) bfd_malloc (amt); | |
252b5132 RH |
2035 | if (extsyms == NULL) |
2036 | goto error_return; | |
2037 | free_extsyms = extsyms; | |
2038 | if (bfd_seek (abfd, symtab_hdr->sh_offset, SEEK_SET) != 0 | |
9ad5cbcf | 2039 | || bfd_bread ((PTR) extsyms, amt, abfd) != amt) |
252b5132 | 2040 | goto error_return; |
9ad5cbcf AM |
2041 | symtab_hdr->contents = (bfd_byte *) extsyms; |
2042 | } | |
2043 | ||
2044 | if (shndx_hdr->sh_size != 0) | |
2045 | { | |
2046 | bfd_size_type amt; | |
2047 | ||
2048 | amt = symtab_hdr->sh_info; | |
2049 | amt *= sizeof (Elf_External_Sym_Shndx); | |
2050 | shndx_buf = (Elf_External_Sym_Shndx *) bfd_malloc (amt); | |
2051 | if (shndx_buf == NULL) | |
2052 | goto error_return; | |
2053 | if (bfd_seek (abfd, shndx_hdr->sh_offset, SEEK_SET) != 0 | |
2054 | || bfd_bread ((PTR) shndx_buf, amt, abfd) != amt) | |
2055 | goto error_return; | |
2056 | shndx_hdr->contents = (bfd_byte *) shndx_buf; | |
252b5132 RH |
2057 | } |
2058 | } | |
2059 | ||
2060 | /* Get the value of the symbol referred to by the reloc. */ | |
2061 | if (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info) | |
2062 | { | |
9ad5cbcf AM |
2063 | /* A local symbol. */ |
2064 | Elf32_External_Sym *esym; | |
2065 | Elf_External_Sym_Shndx *shndx; | |
252b5132 RH |
2066 | Elf_Internal_Sym isym; |
2067 | ||
9ad5cbcf AM |
2068 | esym = extsyms + ELF32_R_SYM (irelfn->r_info); |
2069 | shndx = shndx_buf + (shndx_buf ? ELF32_R_SYM (irelfn->r_info) : 0); | |
2070 | bfd_elf32_swap_symbol_in (abfd, esym, shndx, &isym); | |
252b5132 | 2071 | |
d426c6b0 DJ |
2072 | if (isym.st_shndx |
2073 | != (unsigned int) _bfd_elf_section_from_bfd_section (abfd, sec)) | |
252b5132 RH |
2074 | { |
2075 | ((*_bfd_error_handler) | |
2076 | (_("%s: 0x%lx: warning: symbol in unexpected section"), | |
8f615d07 | 2077 | bfd_archive_filename (abfd), (unsigned long) paddr)); |
252b5132 RH |
2078 | continue; |
2079 | } | |
2080 | ||
2081 | symval = (isym.st_value | |
2082 | + sec->output_section->vma | |
2083 | + sec->output_offset); | |
2084 | } | |
2085 | else | |
2086 | { | |
2087 | unsigned long indx; | |
2088 | struct elf_link_hash_entry *h; | |
2089 | ||
2090 | indx = ELF32_R_SYM (irelfn->r_info) - symtab_hdr->sh_info; | |
2091 | h = elf_sym_hashes (abfd)[indx]; | |
2092 | BFD_ASSERT (h != NULL); | |
2093 | if (h->root.type != bfd_link_hash_defined | |
2094 | && h->root.type != bfd_link_hash_defweak) | |
2095 | { | |
2096 | /* This appears to be a reference to an undefined | |
2097 | symbol. Just ignore it--it will be caught by the | |
2098 | regular reloc processing. */ | |
2099 | continue; | |
2100 | } | |
2101 | ||
2102 | symval = (h->root.u.def.value | |
2103 | + h->root.u.def.section->output_section->vma | |
2104 | + h->root.u.def.section->output_offset); | |
2105 | } | |
2106 | ||
2107 | symval += bfd_get_32 (abfd, contents + paddr); | |
2108 | ||
2109 | /* See if this function call can be shortened. */ | |
2110 | foff = (symval | |
2111 | - (irel->r_offset | |
2112 | + sec->output_section->vma | |
2113 | + sec->output_offset | |
2114 | + 4)); | |
2115 | if (foff < -0x1000 || foff >= 0x1000) | |
2116 | { | |
2117 | /* After all that work, we can't shorten this function call. */ | |
2118 | continue; | |
2119 | } | |
2120 | ||
2121 | /* Shorten the function call. */ | |
2122 | ||
2123 | /* For simplicity of coding, we are going to modify the section | |
2124 | contents, the section relocs, and the BFD symbol table. We | |
2125 | must tell the rest of the code not to free up this | |
2126 | information. It would be possible to instead create a table | |
2127 | of changes which have to be made, as is done in coff-mips.c; | |
2128 | that would be more work, but would require less memory when | |
2129 | the linker is run. */ | |
2130 | ||
2131 | elf_section_data (sec)->relocs = internal_relocs; | |
2132 | free_relocs = NULL; | |
2133 | ||
2134 | elf_section_data (sec)->this_hdr.contents = contents; | |
2135 | free_contents = NULL; | |
2136 | ||
252b5132 RH |
2137 | free_extsyms = NULL; |
2138 | ||
2139 | /* Replace the jsr with a bsr. */ | |
2140 | ||
2141 | /* Change the R_SH_USES reloc into an R_SH_IND12W reloc, and | |
2142 | replace the jsr with a bsr. */ | |
2143 | irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irelfn->r_info), R_SH_IND12W); | |
2144 | if (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info) | |
2145 | { | |
2146 | /* If this needs to be changed because of future relaxing, | |
2147 | it will be handled here like other internal IND12W | |
2148 | relocs. */ | |
2149 | bfd_put_16 (abfd, | |
dc810e39 | 2150 | (bfd_vma) 0xb000 | ((foff >> 1) & 0xfff), |
252b5132 RH |
2151 | contents + irel->r_offset); |
2152 | } | |
2153 | else | |
2154 | { | |
2155 | /* We can't fully resolve this yet, because the external | |
2156 | symbol value may be changed by future relaxing. We let | |
2157 | the final link phase handle it. */ | |
dc810e39 | 2158 | bfd_put_16 (abfd, (bfd_vma) 0xb000, contents + irel->r_offset); |
252b5132 RH |
2159 | } |
2160 | ||
2161 | /* See if there is another R_SH_USES reloc referring to the same | |
2162 | register load. */ | |
2163 | for (irelscan = internal_relocs; irelscan < irelend; irelscan++) | |
2164 | if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_USES | |
2165 | && laddr == irelscan->r_offset + 4 + irelscan->r_addend) | |
2166 | break; | |
2167 | if (irelscan < irelend) | |
2168 | { | |
2169 | /* Some other function call depends upon this register load, | |
2170 | and we have not yet converted that function call. | |
2171 | Indeed, we may never be able to convert it. There is | |
2172 | nothing else we can do at this point. */ | |
2173 | continue; | |
2174 | } | |
2175 | ||
2176 | /* Look for a R_SH_COUNT reloc on the location where the | |
2177 | function address is stored. Do this before deleting any | |
2178 | bytes, to avoid confusion about the address. */ | |
2179 | for (irelcount = internal_relocs; irelcount < irelend; irelcount++) | |
2180 | if (irelcount->r_offset == paddr | |
2181 | && ELF32_R_TYPE (irelcount->r_info) == (int) R_SH_COUNT) | |
2182 | break; | |
2183 | ||
2184 | /* Delete the register load. */ | |
2185 | if (! sh_elf_relax_delete_bytes (abfd, sec, laddr, 2)) | |
2186 | goto error_return; | |
2187 | ||
2188 | /* That will change things, so, just in case it permits some | |
2189 | other function call to come within range, we should relax | |
2190 | again. Note that this is not required, and it may be slow. */ | |
2191 | *again = true; | |
2192 | ||
2193 | /* Now check whether we got a COUNT reloc. */ | |
2194 | if (irelcount >= irelend) | |
2195 | { | |
2196 | ((*_bfd_error_handler) | |
2197 | (_("%s: 0x%lx: warning: could not find expected COUNT reloc"), | |
8f615d07 | 2198 | bfd_archive_filename (abfd), (unsigned long) paddr)); |
252b5132 RH |
2199 | continue; |
2200 | } | |
2201 | ||
2202 | /* The number of uses is stored in the r_addend field. We've | |
2203 | just deleted one. */ | |
2204 | if (irelcount->r_addend == 0) | |
2205 | { | |
2206 | ((*_bfd_error_handler) (_("%s: 0x%lx: warning: bad count"), | |
8f615d07 | 2207 | bfd_archive_filename (abfd), |
252b5132 RH |
2208 | (unsigned long) paddr)); |
2209 | continue; | |
2210 | } | |
2211 | ||
2212 | --irelcount->r_addend; | |
2213 | ||
2214 | /* If there are no more uses, we can delete the address. Reload | |
2215 | the address from irelfn, in case it was changed by the | |
2216 | previous call to sh_elf_relax_delete_bytes. */ | |
2217 | if (irelcount->r_addend == 0) | |
2218 | { | |
2219 | if (! sh_elf_relax_delete_bytes (abfd, sec, irelfn->r_offset, 4)) | |
2220 | goto error_return; | |
2221 | } | |
2222 | ||
2223 | /* We've done all we can with that function call. */ | |
2224 | } | |
2225 | ||
2226 | /* Look for load and store instructions that we can align on four | |
2227 | byte boundaries. */ | |
2228 | if (have_code) | |
2229 | { | |
2230 | boolean swapped; | |
2231 | ||
2232 | /* Get the section contents. */ | |
2233 | if (contents == NULL) | |
2234 | { | |
2235 | if (elf_section_data (sec)->this_hdr.contents != NULL) | |
2236 | contents = elf_section_data (sec)->this_hdr.contents; | |
2237 | else | |
2238 | { | |
2239 | contents = (bfd_byte *) bfd_malloc (sec->_raw_size); | |
2240 | if (contents == NULL) | |
2241 | goto error_return; | |
2242 | free_contents = contents; | |
2243 | ||
2244 | if (! bfd_get_section_contents (abfd, sec, contents, | |
2245 | (file_ptr) 0, sec->_raw_size)) | |
2246 | goto error_return; | |
2247 | } | |
2248 | } | |
2249 | ||
2250 | if (! sh_elf_align_loads (abfd, sec, internal_relocs, contents, | |
2251 | &swapped)) | |
2252 | goto error_return; | |
2253 | ||
2254 | if (swapped) | |
2255 | { | |
2256 | elf_section_data (sec)->relocs = internal_relocs; | |
2257 | free_relocs = NULL; | |
2258 | ||
2259 | elf_section_data (sec)->this_hdr.contents = contents; | |
2260 | free_contents = NULL; | |
2261 | ||
252b5132 RH |
2262 | free_extsyms = NULL; |
2263 | } | |
2264 | } | |
2265 | ||
2266 | if (free_relocs != NULL) | |
9ad5cbcf | 2267 | free (free_relocs); |
252b5132 RH |
2268 | |
2269 | if (free_contents != NULL) | |
2270 | { | |
2271 | if (! link_info->keep_memory) | |
2272 | free (free_contents); | |
2273 | else | |
2274 | { | |
2275 | /* Cache the section contents for elf_link_input_bfd. */ | |
2276 | elf_section_data (sec)->this_hdr.contents = contents; | |
2277 | } | |
9ad5cbcf AM |
2278 | } |
2279 | ||
2280 | if (shndx_buf != NULL) | |
2281 | { | |
2282 | shndx_hdr->contents = NULL; | |
2283 | free (shndx_buf); | |
252b5132 RH |
2284 | } |
2285 | ||
2286 | if (free_extsyms != NULL) | |
2287 | { | |
2288 | if (! link_info->keep_memory) | |
252b5132 | 2289 | { |
9ad5cbcf AM |
2290 | symtab_hdr->contents = NULL; |
2291 | free (free_extsyms); | |
252b5132 | 2292 | } |
252b5132 RH |
2293 | } |
2294 | ||
2295 | return true; | |
2296 | ||
2297 | error_return: | |
2298 | if (free_relocs != NULL) | |
2299 | free (free_relocs); | |
2300 | if (free_contents != NULL) | |
2301 | free (free_contents); | |
9ad5cbcf AM |
2302 | if (shndx_buf != NULL) |
2303 | { | |
2304 | shndx_hdr->contents = NULL; | |
2305 | free (shndx_buf); | |
2306 | } | |
252b5132 | 2307 | if (free_extsyms != NULL) |
9ad5cbcf AM |
2308 | { |
2309 | symtab_hdr->contents = NULL; | |
2310 | free (free_extsyms); | |
2311 | } | |
2312 | ||
252b5132 RH |
2313 | return false; |
2314 | } | |
2315 | ||
2316 | /* Delete some bytes from a section while relaxing. FIXME: There is a | |
2317 | lot of duplication between this function and sh_relax_delete_bytes | |
2318 | in coff-sh.c. */ | |
2319 | ||
2320 | static boolean | |
2321 | sh_elf_relax_delete_bytes (abfd, sec, addr, count) | |
2322 | bfd *abfd; | |
2323 | asection *sec; | |
2324 | bfd_vma addr; | |
2325 | int count; | |
2326 | { | |
2327 | Elf_Internal_Shdr *symtab_hdr; | |
9ad5cbcf | 2328 | Elf_Internal_Shdr *shndx_hdr; |
252b5132 | 2329 | Elf32_External_Sym *extsyms; |
9ad5cbcf | 2330 | unsigned int sec_shndx; |
252b5132 RH |
2331 | bfd_byte *contents; |
2332 | Elf_Internal_Rela *irel, *irelend; | |
2333 | Elf_Internal_Rela *irelalign; | |
2334 | bfd_vma toaddr; | |
2335 | Elf32_External_Sym *esym, *esymend; | |
9ad5cbcf AM |
2336 | Elf_External_Sym_Shndx *shndx_buf, *shndx; |
2337 | struct elf_link_hash_entry **sym_hashes; | |
2338 | struct elf_link_hash_entry **end_hashes; | |
2339 | unsigned int symcount; | |
252b5132 RH |
2340 | asection *o; |
2341 | ||
2342 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
2343 | extsyms = (Elf32_External_Sym *) symtab_hdr->contents; | |
2344 | ||
9ad5cbcf AM |
2345 | shndx_hdr = &elf_tdata (abfd)->symtab_shndx_hdr; |
2346 | shndx_buf = (Elf_External_Sym_Shndx *) shndx_hdr->contents; | |
2347 | ||
2348 | sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec); | |
252b5132 RH |
2349 | |
2350 | contents = elf_section_data (sec)->this_hdr.contents; | |
2351 | ||
2352 | /* The deletion must stop at the next ALIGN reloc for an aligment | |
2353 | power larger than the number of bytes we are deleting. */ | |
2354 | ||
2355 | irelalign = NULL; | |
2356 | toaddr = sec->_cooked_size; | |
2357 | ||
2358 | irel = elf_section_data (sec)->relocs; | |
2359 | irelend = irel + sec->reloc_count; | |
2360 | for (; irel < irelend; irel++) | |
2361 | { | |
2362 | if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_ALIGN | |
2363 | && irel->r_offset > addr | |
2364 | && count < (1 << irel->r_addend)) | |
2365 | { | |
2366 | irelalign = irel; | |
2367 | toaddr = irel->r_offset; | |
2368 | break; | |
2369 | } | |
2370 | } | |
2371 | ||
2372 | /* Actually delete the bytes. */ | |
dc810e39 AM |
2373 | memmove (contents + addr, contents + addr + count, |
2374 | (size_t) (toaddr - addr - count)); | |
252b5132 RH |
2375 | if (irelalign == NULL) |
2376 | sec->_cooked_size -= count; | |
2377 | else | |
2378 | { | |
2379 | int i; | |
2380 | ||
2381 | #define NOP_OPCODE (0x0009) | |
2382 | ||
2383 | BFD_ASSERT ((count & 1) == 0); | |
2384 | for (i = 0; i < count; i += 2) | |
dc810e39 | 2385 | bfd_put_16 (abfd, (bfd_vma) NOP_OPCODE, contents + toaddr - count + i); |
252b5132 RH |
2386 | } |
2387 | ||
2388 | /* Adjust all the relocs. */ | |
2389 | for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++) | |
2390 | { | |
2391 | bfd_vma nraddr, stop; | |
2392 | bfd_vma start = 0; | |
2393 | int insn = 0; | |
2394 | Elf_Internal_Sym sym; | |
2395 | int off, adjust, oinsn; | |
2396 | bfd_signed_vma voff = 0; | |
2397 | boolean overflow; | |
2398 | ||
2399 | /* Get the new reloc address. */ | |
2400 | nraddr = irel->r_offset; | |
2401 | if ((irel->r_offset > addr | |
2402 | && irel->r_offset < toaddr) | |
2403 | || (ELF32_R_TYPE (irel->r_info) == (int) R_SH_ALIGN | |
2404 | && irel->r_offset == toaddr)) | |
2405 | nraddr -= count; | |
2406 | ||
2407 | /* See if this reloc was for the bytes we have deleted, in which | |
2408 | case we no longer care about it. Don't delete relocs which | |
2409 | represent addresses, though. */ | |
2410 | if (irel->r_offset >= addr | |
2411 | && irel->r_offset < addr + count | |
2412 | && ELF32_R_TYPE (irel->r_info) != (int) R_SH_ALIGN | |
2413 | && ELF32_R_TYPE (irel->r_info) != (int) R_SH_CODE | |
2414 | && ELF32_R_TYPE (irel->r_info) != (int) R_SH_DATA | |
2415 | && ELF32_R_TYPE (irel->r_info) != (int) R_SH_LABEL) | |
2416 | irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), | |
2417 | (int) R_SH_NONE); | |
2418 | ||
2419 | /* If this is a PC relative reloc, see if the range it covers | |
2420 | includes the bytes we have deleted. */ | |
2421 | switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info)) | |
2422 | { | |
2423 | default: | |
2424 | break; | |
2425 | ||
2426 | case R_SH_DIR8WPN: | |
2427 | case R_SH_IND12W: | |
2428 | case R_SH_DIR8WPZ: | |
2429 | case R_SH_DIR8WPL: | |
2430 | start = irel->r_offset; | |
2431 | insn = bfd_get_16 (abfd, contents + nraddr); | |
2432 | break; | |
2433 | } | |
2434 | ||
2435 | switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info)) | |
2436 | { | |
2437 | default: | |
2438 | start = stop = addr; | |
2439 | break; | |
2440 | ||
2441 | case R_SH_DIR32: | |
2442 | /* If this reloc is against a symbol defined in this | |
2443 | section, and the symbol will not be adjusted below, we | |
2444 | must check the addend to see it will put the value in | |
2445 | range to be adjusted, and hence must be changed. */ | |
2446 | if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info) | |
2447 | { | |
9ad5cbcf AM |
2448 | esym = extsyms + ELF32_R_SYM (irel->r_info); |
2449 | shndx = shndx_buf + (shndx_buf ? ELF32_R_SYM (irel->r_info) : 0); | |
2450 | bfd_elf32_swap_symbol_in (abfd, esym, shndx, &sym); | |
2451 | ||
2452 | if (sym.st_shndx == sec_shndx | |
252b5132 RH |
2453 | && (sym.st_value <= addr |
2454 | || sym.st_value >= toaddr)) | |
2455 | { | |
2456 | bfd_vma val; | |
2457 | ||
2458 | val = bfd_get_32 (abfd, contents + nraddr); | |
2459 | val += sym.st_value; | |
2460 | if (val > addr && val < toaddr) | |
2461 | bfd_put_32 (abfd, val - count, contents + nraddr); | |
2462 | } | |
2463 | } | |
2464 | start = stop = addr; | |
2465 | break; | |
2466 | ||
2467 | case R_SH_DIR8WPN: | |
2468 | off = insn & 0xff; | |
2469 | if (off & 0x80) | |
2470 | off -= 0x100; | |
2471 | stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2); | |
2472 | break; | |
2473 | ||
2474 | case R_SH_IND12W: | |
2475 | if (ELF32_R_SYM (irel->r_info) >= symtab_hdr->sh_info) | |
2476 | start = stop = addr; | |
2477 | else | |
2478 | { | |
2479 | off = insn & 0xfff; | |
2480 | if (off & 0x800) | |
2481 | off -= 0x1000; | |
2482 | stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2); | |
2483 | } | |
2484 | break; | |
2485 | ||
2486 | case R_SH_DIR8WPZ: | |
2487 | off = insn & 0xff; | |
2488 | stop = start + 4 + off * 2; | |
2489 | break; | |
2490 | ||
2491 | case R_SH_DIR8WPL: | |
2492 | off = insn & 0xff; | |
435b1e90 | 2493 | stop = (start & ~(bfd_vma) 3) + 4 + off * 4; |
252b5132 RH |
2494 | break; |
2495 | ||
2496 | case R_SH_SWITCH8: | |
2497 | case R_SH_SWITCH16: | |
2498 | case R_SH_SWITCH32: | |
2499 | /* These relocs types represent | |
2500 | .word L2-L1 | |
06e1ba78 | 2501 | The r_addend field holds the difference between the reloc |
252b5132 RH |
2502 | address and L1. That is the start of the reloc, and |
2503 | adding in the contents gives us the top. We must adjust | |
06e1ba78 JR |
2504 | both the r_offset field and the section contents. |
2505 | N.B. in gas / coff bfd, the elf bfd r_addend is called r_offset, | |
2506 | and the elf bfd r_offset is called r_vaddr. */ | |
252b5132 | 2507 | |
06e1ba78 JR |
2508 | stop = irel->r_offset; |
2509 | start = (bfd_vma) ((bfd_signed_vma) stop - (long) irel->r_addend); | |
252b5132 RH |
2510 | |
2511 | if (start > addr | |
2512 | && start < toaddr | |
2513 | && (stop <= addr || stop >= toaddr)) | |
2514 | irel->r_addend += count; | |
2515 | else if (stop > addr | |
2516 | && stop < toaddr | |
2517 | && (start <= addr || start >= toaddr)) | |
2518 | irel->r_addend -= count; | |
2519 | ||
252b5132 RH |
2520 | if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_SWITCH16) |
2521 | voff = bfd_get_signed_16 (abfd, contents + nraddr); | |
2522 | else if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_SWITCH8) | |
2523 | voff = bfd_get_8 (abfd, contents + nraddr); | |
2524 | else | |
2525 | voff = bfd_get_signed_32 (abfd, contents + nraddr); | |
2526 | stop = (bfd_vma) ((bfd_signed_vma) start + voff); | |
2527 | ||
2528 | break; | |
2529 | ||
2530 | case R_SH_USES: | |
2531 | start = irel->r_offset; | |
2532 | stop = (bfd_vma) ((bfd_signed_vma) start | |
2533 | + (long) irel->r_addend | |
2534 | + 4); | |
2535 | break; | |
2536 | } | |
2537 | ||
2538 | if (start > addr | |
2539 | && start < toaddr | |
2540 | && (stop <= addr || stop >= toaddr)) | |
2541 | adjust = count; | |
2542 | else if (stop > addr | |
2543 | && stop < toaddr | |
2544 | && (start <= addr || start >= toaddr)) | |
2545 | adjust = - count; | |
2546 | else | |
2547 | adjust = 0; | |
2548 | ||
2549 | if (adjust != 0) | |
2550 | { | |
2551 | oinsn = insn; | |
2552 | overflow = false; | |
2553 | switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info)) | |
2554 | { | |
2555 | default: | |
2556 | abort (); | |
2557 | break; | |
2558 | ||
2559 | case R_SH_DIR8WPN: | |
2560 | case R_SH_DIR8WPZ: | |
2561 | insn += adjust / 2; | |
2562 | if ((oinsn & 0xff00) != (insn & 0xff00)) | |
2563 | overflow = true; | |
dc810e39 | 2564 | bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr); |
252b5132 RH |
2565 | break; |
2566 | ||
2567 | case R_SH_IND12W: | |
2568 | insn += adjust / 2; | |
2569 | if ((oinsn & 0xf000) != (insn & 0xf000)) | |
2570 | overflow = true; | |
dc810e39 | 2571 | bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr); |
252b5132 RH |
2572 | break; |
2573 | ||
2574 | case R_SH_DIR8WPL: | |
2575 | BFD_ASSERT (adjust == count || count >= 4); | |
2576 | if (count >= 4) | |
2577 | insn += adjust / 4; | |
2578 | else | |
2579 | { | |
2580 | if ((irel->r_offset & 3) == 0) | |
2581 | ++insn; | |
2582 | } | |
2583 | if ((oinsn & 0xff00) != (insn & 0xff00)) | |
2584 | overflow = true; | |
dc810e39 | 2585 | bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr); |
252b5132 RH |
2586 | break; |
2587 | ||
851cde10 JR |
2588 | case R_SH_SWITCH8: |
2589 | voff += adjust; | |
2590 | if (voff < 0 || voff >= 0xff) | |
2591 | overflow = true; | |
2592 | bfd_put_8 (abfd, voff, contents + nraddr); | |
2593 | break; | |
2594 | ||
252b5132 RH |
2595 | case R_SH_SWITCH16: |
2596 | voff += adjust; | |
2597 | if (voff < - 0x8000 || voff >= 0x8000) | |
2598 | overflow = true; | |
dc810e39 | 2599 | bfd_put_signed_16 (abfd, (bfd_vma) voff, contents + nraddr); |
252b5132 RH |
2600 | break; |
2601 | ||
2602 | case R_SH_SWITCH32: | |
2603 | voff += adjust; | |
dc810e39 | 2604 | bfd_put_signed_32 (abfd, (bfd_vma) voff, contents + nraddr); |
252b5132 RH |
2605 | break; |
2606 | ||
2607 | case R_SH_USES: | |
2608 | irel->r_addend += adjust; | |
2609 | break; | |
2610 | } | |
2611 | ||
2612 | if (overflow) | |
2613 | { | |
2614 | ((*_bfd_error_handler) | |
2615 | (_("%s: 0x%lx: fatal: reloc overflow while relaxing"), | |
8f615d07 | 2616 | bfd_archive_filename (abfd), (unsigned long) irel->r_offset)); |
252b5132 RH |
2617 | bfd_set_error (bfd_error_bad_value); |
2618 | return false; | |
2619 | } | |
2620 | } | |
2621 | ||
2622 | irel->r_offset = nraddr; | |
2623 | } | |
2624 | ||
2625 | /* Look through all the other sections. If there contain any IMM32 | |
2626 | relocs against internal symbols which we are not going to adjust | |
2627 | below, we may need to adjust the addends. */ | |
2628 | for (o = abfd->sections; o != NULL; o = o->next) | |
2629 | { | |
2630 | Elf_Internal_Rela *internal_relocs; | |
2631 | Elf_Internal_Rela *irelscan, *irelscanend; | |
2632 | bfd_byte *ocontents; | |
2633 | ||
2634 | if (o == sec | |
2635 | || (o->flags & SEC_RELOC) == 0 | |
2636 | || o->reloc_count == 0) | |
2637 | continue; | |
2638 | ||
2639 | /* We always cache the relocs. Perhaps, if info->keep_memory is | |
2640 | false, we should free them, if we are permitted to, when we | |
2641 | leave sh_coff_relax_section. */ | |
2642 | internal_relocs = (_bfd_elf32_link_read_relocs | |
2643 | (abfd, o, (PTR) NULL, (Elf_Internal_Rela *) NULL, | |
2644 | true)); | |
2645 | if (internal_relocs == NULL) | |
2646 | return false; | |
2647 | ||
2648 | ocontents = NULL; | |
2649 | irelscanend = internal_relocs + o->reloc_count; | |
2650 | for (irelscan = internal_relocs; irelscan < irelscanend; irelscan++) | |
2651 | { | |
2652 | Elf_Internal_Sym sym; | |
2653 | ||
084aa3aa JR |
2654 | /* Dwarf line numbers use R_SH_SWITCH32 relocs. */ |
2655 | if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_SWITCH32) | |
2656 | { | |
2657 | bfd_vma start, stop; | |
2658 | bfd_signed_vma voff; | |
2659 | ||
2660 | if (ocontents == NULL) | |
2661 | { | |
2662 | if (elf_section_data (o)->this_hdr.contents != NULL) | |
2663 | ocontents = elf_section_data (o)->this_hdr.contents; | |
2664 | else | |
2665 | { | |
2666 | /* We always cache the section contents. | |
2667 | Perhaps, if info->keep_memory is false, we | |
2668 | should free them, if we are permitted to, | |
2669 | when we leave sh_coff_relax_section. */ | |
2670 | ocontents = (bfd_byte *) bfd_malloc (o->_raw_size); | |
2671 | if (ocontents == NULL) | |
2672 | return false; | |
2673 | if (! bfd_get_section_contents (abfd, o, ocontents, | |
2674 | (file_ptr) 0, | |
2675 | o->_raw_size)) | |
2676 | return false; | |
2677 | elf_section_data (o)->this_hdr.contents = ocontents; | |
2678 | } | |
2679 | } | |
2680 | ||
2681 | stop = irelscan->r_offset; | |
2682 | start | |
2683 | = (bfd_vma) ((bfd_signed_vma) stop - (long) irelscan->r_addend); | |
2684 | ||
2685 | /* STOP is in a different section, so it won't change. */ | |
2686 | if (start > addr && start < toaddr) | |
2687 | irelscan->r_addend += count; | |
2688 | ||
2689 | voff = bfd_get_signed_32 (abfd, ocontents + irelscan->r_offset); | |
2690 | stop = (bfd_vma) ((bfd_signed_vma) start + voff); | |
2691 | ||
2692 | if (start > addr | |
2693 | && start < toaddr | |
2694 | && (stop <= addr || stop >= toaddr)) | |
dc810e39 | 2695 | bfd_put_signed_32 (abfd, (bfd_vma) voff + count, |
084aa3aa JR |
2696 | ocontents + irelscan->r_offset); |
2697 | else if (stop > addr | |
2698 | && stop < toaddr | |
2699 | && (start <= addr || start >= toaddr)) | |
dc810e39 | 2700 | bfd_put_signed_32 (abfd, (bfd_vma) voff - count, |
084aa3aa JR |
2701 | ocontents + irelscan->r_offset); |
2702 | } | |
2703 | ||
252b5132 RH |
2704 | if (ELF32_R_TYPE (irelscan->r_info) != (int) R_SH_DIR32) |
2705 | continue; | |
2706 | ||
2707 | if (ELF32_R_SYM (irelscan->r_info) >= symtab_hdr->sh_info) | |
2708 | continue; | |
2709 | ||
252b5132 | 2710 | |
9ad5cbcf AM |
2711 | esym = extsyms + ELF32_R_SYM (irelscan->r_info); |
2712 | shndx = shndx_buf + (shndx_buf ? ELF32_R_SYM (irelscan->r_info) : 0); | |
2713 | bfd_elf32_swap_symbol_in (abfd, esym, shndx, &sym); | |
2714 | ||
2715 | if (sym.st_shndx == sec_shndx | |
252b5132 RH |
2716 | && (sym.st_value <= addr |
2717 | || sym.st_value >= toaddr)) | |
2718 | { | |
2719 | bfd_vma val; | |
2720 | ||
2721 | if (ocontents == NULL) | |
2722 | { | |
2723 | if (elf_section_data (o)->this_hdr.contents != NULL) | |
2724 | ocontents = elf_section_data (o)->this_hdr.contents; | |
2725 | else | |
2726 | { | |
2727 | /* We always cache the section contents. | |
2728 | Perhaps, if info->keep_memory is false, we | |
2729 | should free them, if we are permitted to, | |
2730 | when we leave sh_coff_relax_section. */ | |
2731 | ocontents = (bfd_byte *) bfd_malloc (o->_raw_size); | |
2732 | if (ocontents == NULL) | |
2733 | return false; | |
2734 | if (! bfd_get_section_contents (abfd, o, ocontents, | |
2735 | (file_ptr) 0, | |
2736 | o->_raw_size)) | |
2737 | return false; | |
2738 | elf_section_data (o)->this_hdr.contents = ocontents; | |
2739 | } | |
2740 | } | |
2741 | ||
2742 | val = bfd_get_32 (abfd, ocontents + irelscan->r_offset); | |
2743 | val += sym.st_value; | |
2744 | if (val > addr && val < toaddr) | |
2745 | bfd_put_32 (abfd, val - count, | |
2746 | ocontents + irelscan->r_offset); | |
2747 | } | |
2748 | } | |
2749 | } | |
2750 | ||
2751 | /* Adjust the local symbols defined in this section. */ | |
9ad5cbcf | 2752 | shndx = shndx_buf; |
252b5132 RH |
2753 | esym = extsyms; |
2754 | esymend = esym + symtab_hdr->sh_info; | |
9ad5cbcf | 2755 | for (; esym < esymend; esym++, shndx = (shndx ? shndx + 1 : NULL)) |
252b5132 RH |
2756 | { |
2757 | Elf_Internal_Sym isym; | |
9ad5cbcf | 2758 | Elf_External_Sym_Shndx dummy; |
252b5132 | 2759 | |
9ad5cbcf | 2760 | bfd_elf32_swap_symbol_in (abfd, esym, shndx, &isym); |
252b5132 | 2761 | |
9ad5cbcf | 2762 | if (isym.st_shndx == sec_shndx |
252b5132 RH |
2763 | && isym.st_value > addr |
2764 | && isym.st_value < toaddr) | |
2765 | { | |
2766 | isym.st_value -= count; | |
9ad5cbcf | 2767 | bfd_elf32_swap_symbol_out (abfd, &isym, (PTR) esym, (PTR) &dummy); |
252b5132 RH |
2768 | } |
2769 | } | |
2770 | ||
2771 | /* Now adjust the global symbols defined in this section. */ | |
9ad5cbcf AM |
2772 | symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym) |
2773 | - symtab_hdr->sh_info); | |
2774 | sym_hashes = elf_sym_hashes (abfd); | |
2775 | end_hashes = sym_hashes + symcount; | |
2776 | for (; sym_hashes < end_hashes; sym_hashes++) | |
252b5132 | 2777 | { |
9ad5cbcf AM |
2778 | struct elf_link_hash_entry *sym_hash = *sym_hashes; |
2779 | if ((sym_hash->root.type == bfd_link_hash_defined | |
2780 | || sym_hash->root.type == bfd_link_hash_defweak) | |
2781 | && sym_hash->root.u.def.section == sec | |
2782 | && sym_hash->root.u.def.value > addr | |
2783 | && sym_hash->root.u.def.value < toaddr) | |
252b5132 | 2784 | { |
9ad5cbcf | 2785 | sym_hash->root.u.def.value -= count; |
252b5132 RH |
2786 | } |
2787 | } | |
2788 | ||
2789 | /* See if we can move the ALIGN reloc forward. We have adjusted | |
2790 | r_offset for it already. */ | |
2791 | if (irelalign != NULL) | |
2792 | { | |
2793 | bfd_vma alignto, alignaddr; | |
2794 | ||
2795 | alignto = BFD_ALIGN (toaddr, 1 << irelalign->r_addend); | |
2796 | alignaddr = BFD_ALIGN (irelalign->r_offset, | |
2797 | 1 << irelalign->r_addend); | |
2798 | if (alignto != alignaddr) | |
2799 | { | |
2800 | /* Tail recursion. */ | |
2801 | return sh_elf_relax_delete_bytes (abfd, sec, alignaddr, | |
dc810e39 | 2802 | (int) (alignto - alignaddr)); |
252b5132 RH |
2803 | } |
2804 | } | |
2805 | ||
2806 | return true; | |
2807 | } | |
2808 | ||
2809 | /* Look for loads and stores which we can align to four byte | |
2810 | boundaries. This is like sh_align_loads in coff-sh.c. */ | |
2811 | ||
2812 | static boolean | |
2813 | sh_elf_align_loads (abfd, sec, internal_relocs, contents, pswapped) | |
518313c3 | 2814 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
2815 | asection *sec; |
2816 | Elf_Internal_Rela *internal_relocs; | |
518313c3 | 2817 | bfd_byte *contents ATTRIBUTE_UNUSED; |
252b5132 RH |
2818 | boolean *pswapped; |
2819 | { | |
2820 | Elf_Internal_Rela *irel, *irelend; | |
2821 | bfd_vma *labels = NULL; | |
2822 | bfd_vma *label, *label_end; | |
dc810e39 | 2823 | bfd_size_type amt; |
252b5132 RH |
2824 | |
2825 | *pswapped = false; | |
2826 | ||
2827 | irelend = internal_relocs + sec->reloc_count; | |
2828 | ||
2829 | /* Get all the addresses with labels on them. */ | |
dc810e39 AM |
2830 | amt = sec->reloc_count; |
2831 | amt *= sizeof (bfd_vma); | |
2832 | labels = (bfd_vma *) bfd_malloc (amt); | |
252b5132 RH |
2833 | if (labels == NULL) |
2834 | goto error_return; | |
2835 | label_end = labels; | |
2836 | for (irel = internal_relocs; irel < irelend; irel++) | |
2837 | { | |
2838 | if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_LABEL) | |
2839 | { | |
2840 | *label_end = irel->r_offset; | |
2841 | ++label_end; | |
2842 | } | |
2843 | } | |
2844 | ||
2845 | /* Note that the assembler currently always outputs relocs in | |
2846 | address order. If that ever changes, this code will need to sort | |
2847 | the label values and the relocs. */ | |
2848 | ||
2849 | label = labels; | |
2850 | ||
2851 | for (irel = internal_relocs; irel < irelend; irel++) | |
2852 | { | |
2853 | bfd_vma start, stop; | |
2854 | ||
2855 | if (ELF32_R_TYPE (irel->r_info) != (int) R_SH_CODE) | |
2856 | continue; | |
2857 | ||
2858 | start = irel->r_offset; | |
2859 | ||
2860 | for (irel++; irel < irelend; irel++) | |
2861 | if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_DATA) | |
2862 | break; | |
2863 | if (irel < irelend) | |
2864 | stop = irel->r_offset; | |
2865 | else | |
2866 | stop = sec->_cooked_size; | |
2867 | ||
2868 | if (! _bfd_sh_align_load_span (abfd, sec, contents, sh_elf_swap_insns, | |
2869 | (PTR) internal_relocs, &label, | |
2870 | label_end, start, stop, pswapped)) | |
2871 | goto error_return; | |
2872 | } | |
2873 | ||
2874 | free (labels); | |
2875 | ||
2876 | return true; | |
2877 | ||
2878 | error_return: | |
2879 | if (labels != NULL) | |
2880 | free (labels); | |
2881 | return false; | |
2882 | } | |
2883 | ||
2884 | /* Swap two SH instructions. This is like sh_swap_insns in coff-sh.c. */ | |
2885 | ||
2886 | static boolean | |
2887 | sh_elf_swap_insns (abfd, sec, relocs, contents, addr) | |
2888 | bfd *abfd; | |
2889 | asection *sec; | |
2890 | PTR relocs; | |
2891 | bfd_byte *contents; | |
2892 | bfd_vma addr; | |
2893 | { | |
2894 | Elf_Internal_Rela *internal_relocs = (Elf_Internal_Rela *) relocs; | |
2895 | unsigned short i1, i2; | |
2896 | Elf_Internal_Rela *irel, *irelend; | |
2897 | ||
2898 | /* Swap the instructions themselves. */ | |
2899 | i1 = bfd_get_16 (abfd, contents + addr); | |
2900 | i2 = bfd_get_16 (abfd, contents + addr + 2); | |
dc810e39 AM |
2901 | bfd_put_16 (abfd, (bfd_vma) i2, contents + addr); |
2902 | bfd_put_16 (abfd, (bfd_vma) i1, contents + addr + 2); | |
252b5132 RH |
2903 | |
2904 | /* Adjust all reloc addresses. */ | |
2905 | irelend = internal_relocs + sec->reloc_count; | |
2906 | for (irel = internal_relocs; irel < irelend; irel++) | |
2907 | { | |
2908 | enum elf_sh_reloc_type type; | |
2909 | int add; | |
2910 | ||
2911 | /* There are a few special types of relocs that we don't want to | |
2912 | adjust. These relocs do not apply to the instruction itself, | |
2913 | but are only associated with the address. */ | |
2914 | type = (enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info); | |
2915 | if (type == R_SH_ALIGN | |
2916 | || type == R_SH_CODE | |
2917 | || type == R_SH_DATA | |
2918 | || type == R_SH_LABEL) | |
2919 | continue; | |
2920 | ||
2921 | /* If an R_SH_USES reloc points to one of the addresses being | |
2922 | swapped, we must adjust it. It would be incorrect to do this | |
2923 | for a jump, though, since we want to execute both | |
2924 | instructions after the jump. (We have avoided swapping | |
2925 | around a label, so the jump will not wind up executing an | |
2926 | instruction it shouldn't). */ | |
2927 | if (type == R_SH_USES) | |
2928 | { | |
2929 | bfd_vma off; | |
2930 | ||
2931 | off = irel->r_offset + 4 + irel->r_addend; | |
2932 | if (off == addr) | |
2933 | irel->r_offset += 2; | |
2934 | else if (off == addr + 2) | |
2935 | irel->r_offset -= 2; | |
2936 | } | |
2937 | ||
2938 | if (irel->r_offset == addr) | |
2939 | { | |
2940 | irel->r_offset += 2; | |
2941 | add = -2; | |
2942 | } | |
2943 | else if (irel->r_offset == addr + 2) | |
2944 | { | |
2945 | irel->r_offset -= 2; | |
2946 | add = 2; | |
2947 | } | |
2948 | else | |
2949 | add = 0; | |
2950 | ||
2951 | if (add != 0) | |
2952 | { | |
2953 | bfd_byte *loc; | |
2954 | unsigned short insn, oinsn; | |
2955 | boolean overflow; | |
2956 | ||
2957 | loc = contents + irel->r_offset; | |
2958 | overflow = false; | |
2959 | switch (type) | |
2960 | { | |
2961 | default: | |
2962 | break; | |
2963 | ||
2964 | case R_SH_DIR8WPN: | |
2965 | case R_SH_DIR8WPZ: | |
2966 | insn = bfd_get_16 (abfd, loc); | |
2967 | oinsn = insn; | |
2968 | insn += add / 2; | |
2969 | if ((oinsn & 0xff00) != (insn & 0xff00)) | |
2970 | overflow = true; | |
dc810e39 | 2971 | bfd_put_16 (abfd, (bfd_vma) insn, loc); |
252b5132 RH |
2972 | break; |
2973 | ||
2974 | case R_SH_IND12W: | |
2975 | insn = bfd_get_16 (abfd, loc); | |
2976 | oinsn = insn; | |
2977 | insn += add / 2; | |
2978 | if ((oinsn & 0xf000) != (insn & 0xf000)) | |
2979 | overflow = true; | |
dc810e39 | 2980 | bfd_put_16 (abfd, (bfd_vma) insn, loc); |
252b5132 RH |
2981 | break; |
2982 | ||
2983 | case R_SH_DIR8WPL: | |
2984 | /* This reloc ignores the least significant 3 bits of | |
2985 | the program counter before adding in the offset. | |
2986 | This means that if ADDR is at an even address, the | |
2987 | swap will not affect the offset. If ADDR is an at an | |
2988 | odd address, then the instruction will be crossing a | |
2989 | four byte boundary, and must be adjusted. */ | |
2990 | if ((addr & 3) != 0) | |
2991 | { | |
2992 | insn = bfd_get_16 (abfd, loc); | |
2993 | oinsn = insn; | |
2994 | insn += add / 2; | |
2995 | if ((oinsn & 0xff00) != (insn & 0xff00)) | |
2996 | overflow = true; | |
dc810e39 | 2997 | bfd_put_16 (abfd, (bfd_vma) insn, loc); |
252b5132 RH |
2998 | } |
2999 | ||
3000 | break; | |
3001 | } | |
3002 | ||
3003 | if (overflow) | |
3004 | { | |
3005 | ((*_bfd_error_handler) | |
3006 | (_("%s: 0x%lx: fatal: reloc overflow while relaxing"), | |
8f615d07 | 3007 | bfd_archive_filename (abfd), (unsigned long) irel->r_offset)); |
252b5132 RH |
3008 | bfd_set_error (bfd_error_bad_value); |
3009 | return false; | |
3010 | } | |
3011 | } | |
3012 | } | |
3013 | ||
3014 | return true; | |
3015 | } | |
3016 | \f | |
fbca6ad9 AO |
3017 | #ifdef INCLUDE_SHMEDIA |
3018 | ||
3019 | /* The size in bytes of an entry in the procedure linkage table. */ | |
3020 | ||
3021 | #define PLT_ENTRY_SIZE 64 | |
3022 | ||
3023 | /* First entry in an absolute procedure linkage table look like this. */ | |
3024 | ||
3025 | static const bfd_byte elf_sh_plt0_entry_be[PLT_ENTRY_SIZE] = | |
3026 | { | |
3027 | 0xcc, 0x00, 0x01, 0x10, /* movi .got.plt >> 16, r17 */ | |
3028 | 0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */ | |
3029 | 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */ | |
3030 | 0x6b, 0xf1, 0x46, 0x00, /* ptabs r17, tr0 */ | |
3031 | 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */ | |
3032 | 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */ | |
3033 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ | |
3034 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ | |
3035 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ | |
3036 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ | |
3037 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ | |
3038 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ | |
3039 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ | |
3040 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ | |
3041 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ | |
3042 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ | |
3043 | }; | |
3044 | ||
3045 | static const bfd_byte elf_sh_plt0_entry_le[PLT_ENTRY_SIZE] = | |
3046 | { | |
3047 | 0x10, 0x01, 0x00, 0xcc, /* movi .got.plt >> 16, r17 */ | |
3048 | 0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */ | |
3049 | 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */ | |
3050 | 0x00, 0x46, 0xf1, 0x6b, /* ptabs r17, tr0 */ | |
3051 | 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */ | |
3052 | 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */ | |
3053 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ | |
3054 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ | |
3055 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ | |
3056 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ | |
3057 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ | |
3058 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ | |
3059 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ | |
3060 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ | |
3061 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ | |
3062 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ | |
3063 | }; | |
3064 | ||
3065 | /* Sebsequent entries in an absolute procedure linkage table look like | |
3066 | this. */ | |
3067 | ||
3068 | static const bfd_byte elf_sh_plt_entry_be[PLT_ENTRY_SIZE] = | |
3069 | { | |
3070 | 0xcc, 0x00, 0x01, 0x90, /* movi nameN-in-GOT >> 16, r25 */ | |
3071 | 0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */ | |
3072 | 0x89, 0x90, 0x01, 0x90, /* ld.l r25, 0, r25 */ | |
3073 | 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */ | |
3074 | 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */ | |
3075 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ | |
3076 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ | |
3077 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ | |
3078 | 0xcc, 0x00, 0x01, 0x90, /* movi .PLT0 >> 16, r25 */ | |
3079 | 0xc8, 0x00, 0x01, 0x90, /* shori .PLT0 & 65535, r25 */ | |
3080 | 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */ | |
3081 | 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */ | |
3082 | 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */ | |
3083 | 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */ | |
3084 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ | |
3085 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ | |
3086 | }; | |
3087 | ||
3088 | static const bfd_byte elf_sh_plt_entry_le[PLT_ENTRY_SIZE] = | |
3089 | { | |
3090 | 0x90, 0x01, 0x00, 0xcc, /* movi nameN-in-GOT >> 16, r25 */ | |
3091 | 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */ | |
3092 | 0x90, 0x01, 0x90, 0x89, /* ld.l r25, 0, r25 */ | |
3093 | 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */ | |
3094 | 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */ | |
3095 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ | |
3096 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ | |
3097 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ | |
3098 | 0x90, 0x01, 0x00, 0xcc, /* movi .PLT0 >> 16, r25 */ | |
3099 | 0x90, 0x01, 0x00, 0xc8, /* shori .PLT0 & 65535, r25 */ | |
3100 | 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */ | |
3101 | 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */ | |
3102 | 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */ | |
3103 | 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */ | |
3104 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ | |
3105 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ | |
3106 | }; | |
3107 | ||
3108 | /* Entries in a PIC procedure linkage table look like this. */ | |
3109 | ||
3110 | static const bfd_byte elf_sh_pic_plt_entry_be[PLT_ENTRY_SIZE] = | |
3111 | { | |
3112 | 0xcc, 0x00, 0x01, 0x90, /* movi nameN@GOT >> 16, r25 */ | |
3113 | 0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */ | |
3114 | 0x40, 0xc2, 0x65, 0x90, /* ldx.l r12, r25, r25 */ | |
3115 | 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */ | |
3116 | 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */ | |
3117 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ | |
3118 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ | |
3119 | 0x6f, 0xf0, 0xff, 0xf0, /* nop */ | |
3120 | 0xce, 0x00, 0x01, 0x10, /* movi -GOT_BIAS, r17 */ | |
3121 | 0x00, 0xca, 0x45, 0x10, /* sub.l r12, r17, r17 */ | |
3122 | 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */ | |
3123 | 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */ | |
3124 | 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */ | |
3125 | 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */ | |
3126 | 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */ | |
3127 | 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */ | |
3128 | }; | |
3129 | ||
3130 | static const bfd_byte elf_sh_pic_plt_entry_le[PLT_ENTRY_SIZE] = | |
3131 | { | |
3132 | 0x90, 0x01, 0x00, 0xcc, /* movi nameN@GOT >> 16, r25 */ | |
3133 | 0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */ | |
3134 | 0x90, 0x65, 0xc2, 0x40, /* ldx.l r12, r25, r25 */ | |
3135 | 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */ | |
3136 | 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */ | |
3137 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ | |
3138 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ | |
3139 | 0xf0, 0xff, 0xf0, 0x6f, /* nop */ | |
3140 | 0x10, 0x01, 0x00, 0xce, /* movi -GOT_BIAS, r17 */ | |
3141 | 0x10, 0x45, 0xca, 0x00, /* sub.l r12, r17, r17 */ | |
3142 | 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */ | |
3143 | 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */ | |
3144 | 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */ | |
3145 | 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */ | |
3146 | 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */ | |
3147 | 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */ | |
3148 | }; | |
3149 | ||
3150 | static const bfd_byte *elf_sh_plt0_entry; | |
3151 | static const bfd_byte *elf_sh_plt_entry; | |
3152 | static const bfd_byte *elf_sh_pic_plt_entry; | |
3153 | ||
3154 | /* Return size of a PLT entry. */ | |
3155 | #define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE | |
3156 | ||
3157 | /* Return offset of the PLT0 address in an absolute PLT entry. */ | |
3158 | #define elf_sh_plt_plt0_offset(info) 32 | |
3159 | ||
3160 | /* Return offset of the linker in PLT0 entry. */ | |
3161 | #define elf_sh_plt0_gotplt_offset(info) 0 | |
3162 | ||
3163 | /* Return offset of the trampoline in PLT entry */ | |
3164 | #define elf_sh_plt_temp_offset(info) 33 /* Add one because it's SHmedia. */ | |
3165 | ||
3166 | /* Return offset of the symbol in PLT entry. */ | |
3167 | #define elf_sh_plt_symbol_offset(info) 0 | |
3168 | ||
3169 | /* Return offset of the relocation in PLT entry. */ | |
3170 | #define elf_sh_plt_reloc_offset(info) (info->shared ? 52 : 44) | |
3171 | ||
3172 | inline static void | |
3173 | movi_shori_putval (output_bfd, value, addr) | |
3174 | bfd *output_bfd; | |
3175 | unsigned long value; | |
3176 | char *addr; | |
3177 | { | |
3178 | bfd_put_32 (output_bfd, | |
3179 | bfd_get_32 (output_bfd, addr) | |
3180 | | ((value >> 6) & 0x3fffc00), | |
3181 | addr); | |
3182 | bfd_put_32 (output_bfd, | |
3183 | bfd_get_32 (output_bfd, addr + 4) | |
3184 | | ((value << 10) & 0x3fffc00), | |
3185 | addr + 4); | |
3186 | } | |
3187 | ||
3188 | #else | |
37c644f2 | 3189 | /* The size in bytes of an entry in the procedure linkage table. */ |
252b5132 | 3190 | |
37c644f2 AO |
3191 | #define PLT_ENTRY_SIZE 28 |
3192 | ||
3193 | /* First entry in an absolute procedure linkage table look like this. */ | |
3194 | ||
6c426cf3 NC |
3195 | #if 1 |
3196 | /* Note - this code has been "optimised" not to use r2. r2 is used by | |
3197 | GCC to return the address of large strutcures, so it should not be | |
3198 | corrupted here. This does mean however, that this PLT does not conform | |
3199 | to the SH PIC ABI. That spec says that r0 contains the type of the PLT | |
3200 | and r2 contains the GOT id. This version stores the GOT id in r0 and | |
3201 | ignores the type. Loaders can easily detect this difference however, | |
3202 | since the type will always be 0 or 8, and the GOT ids will always be | |
3203 | greater than or equal to 12. */ | |
3204 | static const bfd_byte elf_sh_plt0_entry_be[PLT_ENTRY_SIZE] = | |
3205 | { | |
3206 | 0xd0, 0x05, /* mov.l 2f,r0 */ | |
3207 | 0x60, 0x02, /* mov.l @r0,r0 */ | |
3208 | 0x2f, 0x06, /* mov.l r0,@-r15 */ | |
3209 | 0xd0, 0x03, /* mov.l 1f,r0 */ | |
3210 | 0x60, 0x02, /* mov.l @r0,r0 */ | |
3211 | 0x40, 0x2b, /* jmp @r0 */ | |
3212 | 0x60, 0xf6, /* mov.l @r15+,r0 */ | |
3213 | 0x00, 0x09, /* nop */ | |
3214 | 0x00, 0x09, /* nop */ | |
3215 | 0x00, 0x09, /* nop */ | |
3216 | 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */ | |
3217 | 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */ | |
3218 | }; | |
3219 | ||
3220 | static const bfd_byte elf_sh_plt0_entry_le[PLT_ENTRY_SIZE] = | |
3221 | { | |
3222 | 0x05, 0xd0, /* mov.l 2f,r0 */ | |
3223 | 0x02, 0x60, /* mov.l @r0,r0 */ | |
3224 | 0x06, 0x2f, /* mov.l r0,@-r15 */ | |
3225 | 0x03, 0xd0, /* mov.l 1f,r0 */ | |
3226 | 0x02, 0x60, /* mov.l @r0,r0 */ | |
3227 | 0x2b, 0x40, /* jmp @r0 */ | |
3228 | 0xf6, 0x60, /* mov.l @r15+,r0 */ | |
3229 | 0x09, 0x00, /* nop */ | |
3230 | 0x09, 0x00, /* nop */ | |
3231 | 0x09, 0x00, /* nop */ | |
3232 | 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */ | |
3233 | 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */ | |
3234 | }; | |
3235 | ||
3236 | /* Sebsequent entries in an absolute procedure linkage table look like | |
3237 | this. */ | |
3238 | ||
3239 | static const bfd_byte elf_sh_plt_entry_be[PLT_ENTRY_SIZE] = | |
3240 | { | |
3241 | 0xd0, 0x04, /* mov.l 1f,r0 */ | |
3242 | 0x60, 0x02, /* mov.l @r0,r0 */ | |
3243 | 0xd1, 0x02, /* mov.l 0f,r1 */ | |
3244 | 0x40, 0x2b, /* jmp @r0 */ | |
3245 | 0x60, 0x13, /* mov r1,r0 */ | |
3246 | 0xd1, 0x03, /* mov.l 2f,r1 */ | |
3247 | 0x40, 0x2b, /* jmp @r0 */ | |
3248 | 0x00, 0x09, /* nop */ | |
3249 | 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */ | |
3250 | 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */ | |
3251 | 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */ | |
3252 | }; | |
3253 | ||
3254 | static const bfd_byte elf_sh_plt_entry_le[PLT_ENTRY_SIZE] = | |
3255 | { | |
3256 | 0x04, 0xd0, /* mov.l 1f,r0 */ | |
3257 | 0x02, 0x60, /* mov.l @r0,r0 */ | |
3258 | 0x02, 0xd1, /* mov.l 0f,r1 */ | |
3259 | 0x2b, 0x40, /* jmp @r0 */ | |
3260 | 0x13, 0x60, /* mov r1,r0 */ | |
3261 | 0x03, 0xd1, /* mov.l 2f,r1 */ | |
3262 | 0x2b, 0x40, /* jmp @r0 */ | |
3263 | 0x09, 0x00, /* nop */ | |
3264 | 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */ | |
3265 | 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */ | |
3266 | 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */ | |
3267 | }; | |
3268 | ||
3269 | /* Entries in a PIC procedure linkage table look like this. */ | |
3270 | ||
3271 | static const bfd_byte elf_sh_pic_plt_entry_be[PLT_ENTRY_SIZE] = | |
3272 | { | |
3273 | 0xd0, 0x04, /* mov.l 1f,r0 */ | |
3274 | 0x00, 0xce, /* mov.l @(r0,r12),r0 */ | |
3275 | 0x40, 0x2b, /* jmp @r0 */ | |
3276 | 0x00, 0x09, /* nop */ | |
3277 | 0x50, 0xc2, /* mov.l @(8,r12),r0 */ | |
3278 | 0xd1, 0x03, /* mov.l 2f,r1 */ | |
3279 | 0x40, 0x2b, /* jmp @r0 */ | |
3280 | 0x50, 0xc1, /* mov.l @(4,r12),r0 */ | |
3281 | 0x00, 0x09, /* nop */ | |
3282 | 0x00, 0x09, /* nop */ | |
3283 | 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */ | |
3284 | 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */ | |
3285 | }; | |
3286 | ||
3287 | static const bfd_byte elf_sh_pic_plt_entry_le[PLT_ENTRY_SIZE] = | |
3288 | { | |
3289 | 0x04, 0xd0, /* mov.l 1f,r0 */ | |
3290 | 0xce, 0x00, /* mov.l @(r0,r12),r0 */ | |
3291 | 0x2b, 0x40, /* jmp @r0 */ | |
3292 | 0x09, 0x00, /* nop */ | |
3293 | 0xc2, 0x50, /* mov.l @(8,r12),r0 */ | |
3294 | 0x03, 0xd1, /* mov.l 2f,r1 */ | |
3295 | 0x2b, 0x40, /* jmp @r0 */ | |
3296 | 0xc1, 0x50, /* mov.l @(4,r12),r0 */ | |
3297 | 0x09, 0x00, /* nop */ | |
3298 | 0x09, 0x00, /* nop */ | |
3299 | 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */ | |
3300 | 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */ | |
3301 | }; | |
3302 | ||
3303 | #else /* These are the old style PLT entries. */ | |
38b1a46c NC |
3304 | static const bfd_byte elf_sh_plt0_entry_be[PLT_ENTRY_SIZE] = |
3305 | { | |
37c644f2 AO |
3306 | 0xd0, 0x04, /* mov.l 1f,r0 */ |
3307 | 0xd2, 0x05, /* mov.l 2f,r2 */ | |
3308 | 0x60, 0x02, /* mov.l @r0,r0 */ | |
3309 | 0x62, 0x22, /* mov.l @r2,r2 */ | |
3310 | 0x40, 0x2b, /* jmp @r0 */ | |
3311 | 0xe0, 0x00, /* mov #0,r0 */ | |
3312 | 0x00, 0x09, /* nop */ | |
3313 | 0x00, 0x09, /* nop */ | |
3314 | 0x00, 0x09, /* nop */ | |
3315 | 0x00, 0x09, /* nop */ | |
3316 | 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */ | |
3317 | 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */ | |
3318 | }; | |
252b5132 | 3319 | |
38b1a46c NC |
3320 | static const bfd_byte elf_sh_plt0_entry_le[PLT_ENTRY_SIZE] = |
3321 | { | |
37c644f2 AO |
3322 | 0x04, 0xd0, /* mov.l 1f,r0 */ |
3323 | 0x05, 0xd2, /* mov.l 2f,r2 */ | |
3324 | 0x02, 0x60, /* mov.l @r0,r0 */ | |
3325 | 0x22, 0x62, /* mov.l @r2,r2 */ | |
3326 | 0x2b, 0x40, /* jmp @r0 */ | |
3327 | 0x00, 0xe0, /* mov #0,r0 */ | |
3328 | 0x09, 0x00, /* nop */ | |
3329 | 0x09, 0x00, /* nop */ | |
3330 | 0x09, 0x00, /* nop */ | |
3331 | 0x09, 0x00, /* nop */ | |
3332 | 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */ | |
3333 | 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */ | |
3334 | }; | |
252b5132 | 3335 | |
37c644f2 AO |
3336 | /* Sebsequent entries in an absolute procedure linkage table look like |
3337 | this. */ | |
252b5132 | 3338 | |
38b1a46c NC |
3339 | static const bfd_byte elf_sh_plt_entry_be[PLT_ENTRY_SIZE] = |
3340 | { | |
37c644f2 AO |
3341 | 0xd0, 0x04, /* mov.l 1f,r0 */ |
3342 | 0x60, 0x02, /* mov.l @r0,r0 */ | |
3343 | 0xd2, 0x02, /* mov.l 0f,r2 */ | |
3344 | 0x40, 0x2b, /* jmp @r0 */ | |
3345 | 0x60, 0x23, /* mov r2,r0 */ | |
3346 | 0xd1, 0x03, /* mov.l 2f,r1 */ | |
3347 | 0x40, 0x2b, /* jmp @r0 */ | |
3348 | 0x00, 0x09, /* nop */ | |
3349 | 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */ | |
3350 | 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */ | |
3351 | 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */ | |
3352 | }; | |
252b5132 | 3353 | |
38b1a46c NC |
3354 | static const bfd_byte elf_sh_plt_entry_le[PLT_ENTRY_SIZE] = |
3355 | { | |
37c644f2 AO |
3356 | 0x04, 0xd0, /* mov.l 1f,r0 */ |
3357 | 0x02, 0x60, /* mov.l @r0,r0 */ | |
3358 | 0x02, 0xd2, /* mov.l 0f,r2 */ | |
3359 | 0x2b, 0x40, /* jmp @r0 */ | |
3360 | 0x23, 0x60, /* mov r2,r0 */ | |
3361 | 0x03, 0xd1, /* mov.l 2f,r1 */ | |
3362 | 0x2b, 0x40, /* jmp @r0 */ | |
3363 | 0x09, 0x00, /* nop */ | |
3364 | 0, 0, 0, 0, /* 0: replaced with address of .PLT. */ | |
3365 | 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */ | |
3366 | 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */ | |
3367 | }; | |
252b5132 | 3368 | |
37c644f2 | 3369 | /* Entries in a PIC procedure linkage table look like this. */ |
252b5132 | 3370 | |
38b1a46c NC |
3371 | static const bfd_byte elf_sh_pic_plt_entry_be[PLT_ENTRY_SIZE] = |
3372 | { | |
37c644f2 AO |
3373 | 0xd0, 0x04, /* mov.l 1f,r0 */ |
3374 | 0x00, 0xce, /* mov.l @(r0,r12),r0 */ | |
3375 | 0x40, 0x2b, /* jmp @r0 */ | |
3376 | 0x00, 0x09, /* nop */ | |
3377 | 0x50, 0xc2, /* 0: mov.l @(8,r12),r0 */ | |
3378 | 0x52, 0xc1, /* 1: mov.l @(4,r12),r2 */ | |
3379 | 0xd1, 0x02, /* mov.l 2f,r1 */ | |
3380 | 0x40, 0x2b, /* jmp @r0 */ | |
3381 | 0xe0, 0x00, /* mov #0,r0 ! shows the type of PLT. */ | |
3382 | 0x00, 0x09, /* nop */ | |
3383 | 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */ | |
3384 | 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */ | |
3385 | }; | |
252b5132 | 3386 | |
38b1a46c NC |
3387 | static const bfd_byte elf_sh_pic_plt_entry_le[PLT_ENTRY_SIZE] = |
3388 | { | |
37c644f2 AO |
3389 | 0x04, 0xd0, /* mov.l 1f,r0 */ |
3390 | 0xce, 0x00, /* mov.l @(r0,r12),r0 */ | |
3391 | 0x2b, 0x40, /* jmp @r0 */ | |
3392 | 0x09, 0x00, /* nop */ | |
3393 | 0xc2, 0x50, /* 0: mov.l @(8,r12),r0 */ | |
3394 | 0xc1, 0x52, /* 1: mov.l @(4,r12),r2 */ | |
3395 | 0x02, 0xd1, /* mov.l 2f,r1 */ | |
3396 | 0x2b, 0x40, /* jmp @r0 */ | |
3397 | 0x00, 0xe0, /* mov #0,r0 ! shows the type of PLT. */ | |
3398 | 0x09, 0x00, /* nop */ | |
3399 | 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */ | |
3400 | 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */ | |
3401 | }; | |
6c426cf3 | 3402 | #endif /* old style PLT entries. */ |
252b5132 | 3403 | |
37c644f2 AO |
3404 | static const bfd_byte *elf_sh_plt0_entry; |
3405 | static const bfd_byte *elf_sh_plt_entry; | |
3406 | static const bfd_byte *elf_sh_pic_plt_entry; | |
252b5132 | 3407 | |
37c644f2 AO |
3408 | /* Return size of a PLT entry. */ |
3409 | #define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE | |
252b5132 | 3410 | |
37c644f2 AO |
3411 | /* Return offset of the PLT0 address in an absolute PLT entry. */ |
3412 | #define elf_sh_plt_plt0_offset(info) 16 | |
252b5132 | 3413 | |
37c644f2 AO |
3414 | /* Return offset of the linker in PLT0 entry. */ |
3415 | #define elf_sh_plt0_linker_offset(info) 20 | |
9bdafcce | 3416 | |
37c644f2 AO |
3417 | /* Return offset of the GOT id in PLT0 entry. */ |
3418 | #define elf_sh_plt0_gotid_offset(info) 24 | |
9bdafcce | 3419 | |
37c644f2 AO |
3420 | /* Return offset of the tempoline in PLT entry */ |
3421 | #define elf_sh_plt_temp_offset(info) 8 | |
9bdafcce | 3422 | |
37c644f2 AO |
3423 | /* Return offset of the symbol in PLT entry. */ |
3424 | #define elf_sh_plt_symbol_offset(info) 20 | |
9bdafcce | 3425 | |
37c644f2 AO |
3426 | /* Return offset of the relocation in PLT entry. */ |
3427 | #define elf_sh_plt_reloc_offset(info) 24 | |
fbca6ad9 | 3428 | #endif |
015551fc | 3429 | |
37c644f2 AO |
3430 | /* The sh linker needs to keep track of the number of relocs that it |
3431 | decides to copy in check_relocs for each symbol. This is so that | |
3432 | it can discard PC relative relocs if it doesn't need them when | |
3433 | linking with -Bsymbolic. We store the information in a field | |
3434 | extending the regular ELF linker hash table. */ | |
9bdafcce | 3435 | |
37c644f2 AO |
3436 | /* This structure keeps track of the number of PC relative relocs we |
3437 | have copied for a given symbol. */ | |
252b5132 | 3438 | |
38b1a46c NC |
3439 | struct elf_sh_pcrel_relocs_copied |
3440 | { | |
37c644f2 AO |
3441 | /* Next section. */ |
3442 | struct elf_sh_pcrel_relocs_copied *next; | |
3443 | /* A section in dynobj. */ | |
3444 | asection *section; | |
3445 | /* Number of relocs copied in this section. */ | |
3446 | bfd_size_type count; | |
3447 | }; | |
252b5132 | 3448 | |
37c644f2 AO |
3449 | /* sh ELF linker hash entry. */ |
3450 | ||
38b1a46c NC |
3451 | struct elf_sh_link_hash_entry |
3452 | { | |
37c644f2 AO |
3453 | struct elf_link_hash_entry root; |
3454 | ||
fbca6ad9 AO |
3455 | #ifdef INCLUDE_SHMEDIA |
3456 | bfd_vma datalabel_got_offset; | |
3457 | #endif | |
3458 | ||
37c644f2 AO |
3459 | /* Number of PC relative relocs copied for this symbol. */ |
3460 | struct elf_sh_pcrel_relocs_copied *pcrel_relocs_copied; | |
3461 | }; | |
3462 | ||
3463 | /* sh ELF linker hash table. */ | |
3464 | ||
38b1a46c NC |
3465 | struct elf_sh_link_hash_table |
3466 | { | |
37c644f2 AO |
3467 | struct elf_link_hash_table root; |
3468 | }; | |
3469 | ||
3470 | /* Declare this now that the above structures are defined. */ | |
3471 | ||
3472 | static boolean sh_elf_discard_copies | |
3473 | PARAMS ((struct elf_sh_link_hash_entry *, PTR)); | |
3474 | ||
3475 | /* Traverse an sh ELF linker hash table. */ | |
3476 | ||
3477 | #define sh_elf_link_hash_traverse(table, func, info) \ | |
3478 | (elf_link_hash_traverse \ | |
3479 | (&(table)->root, \ | |
3480 | (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \ | |
3481 | (info))) | |
3482 | ||
3483 | /* Get the sh ELF linker hash table from a link_info structure. */ | |
3484 | ||
3485 | #define sh_elf_hash_table(p) \ | |
3486 | ((struct elf_sh_link_hash_table *) ((p)->hash)) | |
3487 | ||
3488 | /* Create an entry in an sh ELF linker hash table. */ | |
3489 | ||
3490 | static struct bfd_hash_entry * | |
3491 | sh_elf_link_hash_newfunc (entry, table, string) | |
3492 | struct bfd_hash_entry *entry; | |
3493 | struct bfd_hash_table *table; | |
3494 | const char *string; | |
3495 | { | |
3496 | struct elf_sh_link_hash_entry *ret = | |
3497 | (struct elf_sh_link_hash_entry *) entry; | |
3498 | ||
3499 | /* Allocate the structure if it has not already been allocated by a | |
3500 | subclass. */ | |
3501 | if (ret == (struct elf_sh_link_hash_entry *) NULL) | |
3502 | ret = ((struct elf_sh_link_hash_entry *) | |
3503 | bfd_hash_allocate (table, | |
3504 | sizeof (struct elf_sh_link_hash_entry))); | |
3505 | if (ret == (struct elf_sh_link_hash_entry *) NULL) | |
3506 | return (struct bfd_hash_entry *) ret; | |
3507 | ||
3508 | /* Call the allocation method of the superclass. */ | |
3509 | ret = ((struct elf_sh_link_hash_entry *) | |
3510 | _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, | |
3511 | table, string)); | |
3512 | if (ret != (struct elf_sh_link_hash_entry *) NULL) | |
3513 | { | |
3514 | ret->pcrel_relocs_copied = NULL; | |
fbca6ad9 AO |
3515 | #ifdef INCLUDE_SHMEDIA |
3516 | ret->datalabel_got_offset = (bfd_vma) -1; | |
3517 | #endif | |
37c644f2 AO |
3518 | } |
3519 | ||
3520 | return (struct bfd_hash_entry *) ret; | |
3521 | } | |
3522 | ||
3523 | /* Create an sh ELF linker hash table. */ | |
3524 | ||
3525 | static struct bfd_link_hash_table * | |
3526 | sh_elf_link_hash_table_create (abfd) | |
3527 | bfd *abfd; | |
3528 | { | |
3529 | struct elf_sh_link_hash_table *ret; | |
dc810e39 | 3530 | bfd_size_type amt = sizeof (struct elf_sh_link_hash_table); |
37c644f2 | 3531 | |
dc810e39 | 3532 | ret = (struct elf_sh_link_hash_table *) bfd_alloc (abfd, amt); |
37c644f2 AO |
3533 | if (ret == (struct elf_sh_link_hash_table *) NULL) |
3534 | return NULL; | |
3535 | ||
3536 | if (! _bfd_elf_link_hash_table_init (&ret->root, abfd, | |
3537 | sh_elf_link_hash_newfunc)) | |
3538 | { | |
3539 | bfd_release (abfd, ret); | |
3540 | return NULL; | |
3541 | } | |
3542 | ||
3543 | return &ret->root.root; | |
3544 | } | |
3545 | ||
3546 | /* Create dynamic sections when linking against a dynamic object. */ | |
3547 | ||
3548 | static boolean | |
3549 | sh_elf_create_dynamic_sections (abfd, info) | |
3550 | bfd *abfd; | |
3551 | struct bfd_link_info *info; | |
3552 | { | |
3553 | flagword flags, pltflags; | |
3554 | register asection *s; | |
3555 | struct elf_backend_data *bed = get_elf_backend_data (abfd); | |
3556 | int ptralign = 0; | |
3557 | ||
3558 | switch (bed->s->arch_size) | |
3559 | { | |
3560 | case 32: | |
3561 | ptralign = 2; | |
3562 | break; | |
3563 | ||
3564 | case 64: | |
3565 | ptralign = 3; | |
3566 | break; | |
3567 | ||
3568 | default: | |
3569 | bfd_set_error (bfd_error_bad_value); | |
3570 | return false; | |
3571 | } | |
3572 | ||
3573 | /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and | |
3574 | .rel[a].bss sections. */ | |
3575 | ||
3576 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | |
3577 | | SEC_LINKER_CREATED); | |
3578 | ||
3579 | pltflags = flags; | |
3580 | pltflags |= SEC_CODE; | |
3581 | if (bed->plt_not_loaded) | |
3582 | pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS); | |
3583 | if (bed->plt_readonly) | |
3584 | pltflags |= SEC_READONLY; | |
3585 | ||
3586 | s = bfd_make_section (abfd, ".plt"); | |
3587 | if (s == NULL | |
3588 | || ! bfd_set_section_flags (abfd, s, pltflags) | |
3589 | || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment)) | |
3590 | return false; | |
3591 | ||
3592 | if (bed->want_plt_sym) | |
3593 | { | |
3594 | /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the | |
3595 | .plt section. */ | |
3596 | struct elf_link_hash_entry *h = NULL; | |
3597 | if (! (_bfd_generic_link_add_one_symbol | |
3598 | (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s, | |
3599 | (bfd_vma) 0, (const char *) NULL, false, | |
3600 | get_elf_backend_data (abfd)->collect, | |
3601 | (struct bfd_link_hash_entry **) &h))) | |
3602 | return false; | |
3603 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; | |
3604 | h->type = STT_OBJECT; | |
3605 | ||
3606 | if (info->shared | |
3607 | && ! _bfd_elf_link_record_dynamic_symbol (info, h)) | |
3608 | return false; | |
3609 | } | |
3610 | ||
435b1e90 | 3611 | s = bfd_make_section (abfd, |
37c644f2 AO |
3612 | bed->default_use_rela_p ? ".rela.plt" : ".rel.plt"); |
3613 | if (s == NULL | |
3614 | || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY) | |
3615 | || ! bfd_set_section_alignment (abfd, s, ptralign)) | |
3616 | return false; | |
3617 | ||
3618 | if (! _bfd_elf_create_got_section (abfd, info)) | |
3619 | return false; | |
3620 | ||
3621 | { | |
3622 | const char *secname; | |
3623 | char *relname; | |
3624 | flagword secflags; | |
3625 | asection *sec; | |
3626 | ||
3627 | for (sec = abfd->sections; sec; sec = sec->next) | |
3628 | { | |
3629 | secflags = bfd_get_section_flags (abfd, sec); | |
3630 | if ((secflags & (SEC_DATA | SEC_LINKER_CREATED)) | |
3631 | || ((secflags & SEC_HAS_CONTENTS) != SEC_HAS_CONTENTS)) | |
3632 | continue; | |
3633 | secname = bfd_get_section_name (abfd, sec); | |
dc810e39 | 3634 | relname = (char *) bfd_malloc ((bfd_size_type) strlen (secname) + 6); |
37c644f2 AO |
3635 | strcpy (relname, ".rela"); |
3636 | strcat (relname, secname); | |
3637 | s = bfd_make_section (abfd, relname); | |
3638 | if (s == NULL | |
3639 | || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY) | |
3640 | || ! bfd_set_section_alignment (abfd, s, ptralign)) | |
3641 | return false; | |
3642 | } | |
3643 | } | |
3644 | ||
3645 | if (bed->want_dynbss) | |
3646 | { | |
3647 | /* The .dynbss section is a place to put symbols which are defined | |
3648 | by dynamic objects, are referenced by regular objects, and are | |
3649 | not functions. We must allocate space for them in the process | |
3650 | image and use a R_*_COPY reloc to tell the dynamic linker to | |
3651 | initialize them at run time. The linker script puts the .dynbss | |
3652 | section into the .bss section of the final image. */ | |
3653 | s = bfd_make_section (abfd, ".dynbss"); | |
3654 | if (s == NULL | |
3655 | || ! bfd_set_section_flags (abfd, s, SEC_ALLOC)) | |
3656 | return false; | |
3657 | ||
3658 | /* The .rel[a].bss section holds copy relocs. This section is not | |
3659 | normally needed. We need to create it here, though, so that the | |
3660 | linker will map it to an output section. We can't just create it | |
3661 | only if we need it, because we will not know whether we need it | |
3662 | until we have seen all the input files, and the first time the | |
3663 | main linker code calls BFD after examining all the input files | |
3664 | (size_dynamic_sections) the input sections have already been | |
3665 | mapped to the output sections. If the section turns out not to | |
3666 | be needed, we can discard it later. We will never need this | |
3667 | section when generating a shared object, since they do not use | |
3668 | copy relocs. */ | |
3669 | if (! info->shared) | |
3670 | { | |
435b1e90 KH |
3671 | s = bfd_make_section (abfd, |
3672 | (bed->default_use_rela_p | |
3673 | ? ".rela.bss" : ".rel.bss")); | |
37c644f2 AO |
3674 | if (s == NULL |
3675 | || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY) | |
3676 | || ! bfd_set_section_alignment (abfd, s, ptralign)) | |
3677 | return false; | |
3678 | } | |
3679 | } | |
3680 | ||
3681 | return true; | |
3682 | } | |
3683 | \f | |
37c644f2 AO |
3684 | /* Adjust a symbol defined by a dynamic object and referenced by a |
3685 | regular object. The current definition is in some section of the | |
3686 | dynamic object, but we're not including those sections. We have to | |
3687 | change the definition to something the rest of the link can | |
3688 | understand. */ | |
3689 | ||
3690 | static boolean | |
3691 | sh_elf_adjust_dynamic_symbol (info, h) | |
3692 | struct bfd_link_info *info; | |
3693 | struct elf_link_hash_entry *h; | |
3694 | { | |
3695 | bfd *dynobj; | |
3696 | asection *s; | |
3697 | unsigned int power_of_two; | |
3698 | ||
3699 | dynobj = elf_hash_table (info)->dynobj; | |
3700 | ||
3701 | /* Make sure we know what is going on here. */ | |
3702 | BFD_ASSERT (dynobj != NULL | |
3703 | && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) | |
3704 | || h->weakdef != NULL | |
3705 | || ((h->elf_link_hash_flags | |
3706 | & ELF_LINK_HASH_DEF_DYNAMIC) != 0 | |
3707 | && (h->elf_link_hash_flags | |
3708 | & ELF_LINK_HASH_REF_REGULAR) != 0 | |
3709 | && (h->elf_link_hash_flags | |
3710 | & ELF_LINK_HASH_DEF_REGULAR) == 0))); | |
3711 | ||
3712 | /* If this is a function, put it in the procedure linkage table. We | |
3713 | will fill in the contents of the procedure linkage table later, | |
3714 | when we know the address of the .got section. */ | |
3715 | if (h->type == STT_FUNC | |
3716 | || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) | |
3717 | { | |
3718 | if (! info->shared | |
3719 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0 | |
3720 | && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0) | |
3721 | { | |
3722 | /* This case can occur if we saw a PLT reloc in an input | |
3723 | file, but the symbol was never referred to by a dynamic | |
3724 | object. In such a case, we don't actually need to build | |
3725 | a procedure linkage table, and we can just do a REL32 | |
3726 | reloc instead. */ | |
3727 | BFD_ASSERT ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0); | |
3728 | return true; | |
3729 | } | |
3730 | ||
3731 | /* Make sure this symbol is output as a dynamic symbol. */ | |
3732 | if (h->dynindx == -1) | |
3733 | { | |
3734 | if (! bfd_elf32_link_record_dynamic_symbol (info, h)) | |
3735 | return false; | |
3736 | } | |
3737 | ||
3738 | s = bfd_get_section_by_name (dynobj, ".plt"); | |
3739 | BFD_ASSERT (s != NULL); | |
3740 | ||
3741 | /* If this is the first .plt entry, make room for the special | |
3742 | first entry. */ | |
3743 | if (s->_raw_size == 0) | |
3744 | s->_raw_size += PLT_ENTRY_SIZE; | |
3745 | ||
3746 | /* If this symbol is not defined in a regular file, and we are | |
3747 | not generating a shared library, then set the symbol to this | |
3748 | location in the .plt. This is required to make function | |
3749 | pointers compare as equal between the normal executable and | |
3750 | the shared library. */ | |
3751 | if (! info->shared | |
3752 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
3753 | { | |
3754 | h->root.u.def.section = s; | |
3755 | h->root.u.def.value = s->_raw_size; | |
3756 | } | |
3757 | ||
3758 | h->plt.offset = s->_raw_size; | |
3759 | ||
3760 | /* Make room for this entry. */ | |
3761 | s->_raw_size += elf_sh_sizeof_plt (info); | |
3762 | ||
3763 | /* We also need to make an entry in the .got.plt section, which | |
3764 | will be placed in the .got section by the linker script. */ | |
3765 | ||
3766 | s = bfd_get_section_by_name (dynobj, ".got.plt"); | |
3767 | BFD_ASSERT (s != NULL); | |
3768 | s->_raw_size += 4; | |
3769 | ||
3770 | /* We also need to make an entry in the .rela.plt section. */ | |
3771 | ||
3772 | s = bfd_get_section_by_name (dynobj, ".rela.plt"); | |
3773 | BFD_ASSERT (s != NULL); | |
3774 | s->_raw_size += sizeof (Elf32_External_Rela); | |
3775 | ||
3776 | return true; | |
3777 | } | |
3778 | ||
3779 | /* If this is a weak symbol, and there is a real definition, the | |
3780 | processor independent code will have arranged for us to see the | |
3781 | real definition first, and we can just use the same value. */ | |
3782 | if (h->weakdef != NULL) | |
3783 | { | |
3784 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined | |
3785 | || h->weakdef->root.type == bfd_link_hash_defweak); | |
3786 | h->root.u.def.section = h->weakdef->root.u.def.section; | |
3787 | h->root.u.def.value = h->weakdef->root.u.def.value; | |
3788 | return true; | |
3789 | } | |
3790 | ||
3791 | /* This is a reference to a symbol defined by a dynamic object which | |
3792 | is not a function. */ | |
3793 | ||
3794 | /* If we are creating a shared library, we must presume that the | |
3795 | only references to the symbol are via the global offset table. | |
3796 | For such cases we need not do anything here; the relocations will | |
3797 | be handled correctly by relocate_section. */ | |
3798 | if (info->shared) | |
3799 | return true; | |
3800 | ||
3801 | /* If there are no references to this symbol that do not use the | |
3802 | GOT, we don't need to generate a copy reloc. */ | |
3803 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0) | |
3804 | return true; | |
3805 | ||
3806 | /* We must allocate the symbol in our .dynbss section, which will | |
3807 | become part of the .bss section of the executable. There will be | |
3808 | an entry for this symbol in the .dynsym section. The dynamic | |
3809 | object will contain position independent code, so all references | |
3810 | from the dynamic object to this symbol will go through the global | |
3811 | offset table. The dynamic linker will use the .dynsym entry to | |
3812 | determine the address it must put in the global offset table, so | |
3813 | both the dynamic object and the regular object will refer to the | |
3814 | same memory location for the variable. */ | |
3815 | ||
3816 | s = bfd_get_section_by_name (dynobj, ".dynbss"); | |
3817 | BFD_ASSERT (s != NULL); | |
3818 | ||
3819 | /* We must generate a R_SH_COPY reloc to tell the dynamic linker to | |
3820 | copy the initial value out of the dynamic object and into the | |
3821 | runtime process image. We need to remember the offset into the | |
3822 | .rela.bss section we are going to use. */ | |
3823 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) | |
3824 | { | |
3825 | asection *srel; | |
3826 | ||
3827 | srel = bfd_get_section_by_name (dynobj, ".rela.bss"); | |
3828 | BFD_ASSERT (srel != NULL); | |
3829 | srel->_raw_size += sizeof (Elf32_External_Rela); | |
3830 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY; | |
3831 | } | |
3832 | ||
3833 | /* We need to figure out the alignment required for this symbol. I | |
3834 | have no idea how ELF linkers handle this. */ | |
3835 | power_of_two = bfd_log2 (h->size); | |
3836 | if (power_of_two > 3) | |
3837 | power_of_two = 3; | |
3838 | ||
3839 | /* Apply the required alignment. */ | |
3840 | s->_raw_size = BFD_ALIGN (s->_raw_size, | |
3841 | (bfd_size_type) (1 << power_of_two)); | |
3842 | if (power_of_two > bfd_get_section_alignment (dynobj, s)) | |
3843 | { | |
3844 | if (! bfd_set_section_alignment (dynobj, s, power_of_two)) | |
3845 | return false; | |
3846 | } | |
3847 | ||
3848 | /* Define the symbol as being at this point in the section. */ | |
3849 | h->root.u.def.section = s; | |
3850 | h->root.u.def.value = s->_raw_size; | |
3851 | ||
3852 | /* Increment the section size to make room for the symbol. */ | |
3853 | s->_raw_size += h->size; | |
3854 | ||
3855 | return true; | |
3856 | } | |
3857 | ||
3858 | /* Set the sizes of the dynamic sections. */ | |
3859 | ||
3860 | static boolean | |
3861 | sh_elf_size_dynamic_sections (output_bfd, info) | |
99e4ae17 | 3862 | bfd *output_bfd ATTRIBUTE_UNUSED; |
37c644f2 AO |
3863 | struct bfd_link_info *info; |
3864 | { | |
3865 | bfd *dynobj; | |
3866 | asection *s; | |
3867 | boolean plt; | |
3868 | boolean relocs; | |
37c644f2 AO |
3869 | |
3870 | dynobj = elf_hash_table (info)->dynobj; | |
3871 | BFD_ASSERT (dynobj != NULL); | |
3872 | ||
3873 | if (elf_hash_table (info)->dynamic_sections_created) | |
3874 | { | |
3875 | /* Set the contents of the .interp section to the interpreter. */ | |
3876 | if (! info->shared) | |
3877 | { | |
3878 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
3879 | BFD_ASSERT (s != NULL); | |
3880 | s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER; | |
3881 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; | |
3882 | } | |
3883 | } | |
3884 | else | |
3885 | { | |
3886 | /* We may have created entries in the .rela.got section. | |
3887 | However, if we are not creating the dynamic sections, we will | |
3888 | not actually use these entries. Reset the size of .rela.got, | |
3889 | which will cause it to get stripped from the output file | |
3890 | below. */ | |
3891 | s = bfd_get_section_by_name (dynobj, ".rela.got"); | |
3892 | if (s != NULL) | |
3893 | s->_raw_size = 0; | |
3894 | } | |
3895 | ||
3896 | /* If this is a -Bsymbolic shared link, then we need to discard all | |
3897 | PC relative relocs against symbols defined in a regular object. | |
3898 | We allocated space for them in the check_relocs routine, but we | |
3899 | will not fill them in in the relocate_section routine. */ | |
3900 | if (info->shared && info->symbolic) | |
3901 | sh_elf_link_hash_traverse (sh_elf_hash_table (info), | |
3902 | sh_elf_discard_copies, | |
3903 | (PTR) NULL); | |
3904 | ||
3905 | /* The check_relocs and adjust_dynamic_symbol entry points have | |
3906 | determined the sizes of the various dynamic sections. Allocate | |
3907 | memory for them. */ | |
3908 | plt = false; | |
3909 | relocs = false; | |
37c644f2 AO |
3910 | for (s = dynobj->sections; s != NULL; s = s->next) |
3911 | { | |
3912 | const char *name; | |
3913 | boolean strip; | |
3914 | ||
3915 | if ((s->flags & SEC_LINKER_CREATED) == 0) | |
3916 | continue; | |
3917 | ||
3918 | /* It's OK to base decisions on the section name, because none | |
3919 | of the dynobj section names depend upon the input files. */ | |
3920 | name = bfd_get_section_name (dynobj, s); | |
3921 | ||
3922 | strip = false; | |
3923 | ||
3924 | if (strcmp (name, ".plt") == 0) | |
3925 | { | |
3926 | if (s->_raw_size == 0) | |
3927 | { | |
3928 | /* Strip this section if we don't need it; see the | |
3929 | comment below. */ | |
3930 | strip = true; | |
3931 | } | |
3932 | else | |
3933 | { | |
3934 | /* Remember whether there is a PLT. */ | |
3935 | plt = true; | |
3936 | } | |
3937 | } | |
3938 | else if (strncmp (name, ".rela", 5) == 0) | |
3939 | { | |
3940 | if (s->_raw_size == 0) | |
3941 | { | |
3942 | /* If we don't need this section, strip it from the | |
3943 | output file. This is mostly to handle .rela.bss and | |
3944 | .rela.plt. We must create both sections in | |
3945 | create_dynamic_sections, because they must be created | |
3946 | before the linker maps input sections to output | |
3947 | sections. The linker does that before | |
3948 | adjust_dynamic_symbol is called, and it is that | |
3949 | function which decides whether anything needs to go | |
3950 | into these sections. */ | |
3951 | strip = true; | |
3952 | } | |
3953 | else | |
3954 | { | |
37c644f2 AO |
3955 | /* Remember whether there are any reloc sections other |
3956 | than .rela.plt. */ | |
3957 | if (strcmp (name, ".rela.plt") != 0) | |
99e4ae17 | 3958 | relocs = true; |
37c644f2 AO |
3959 | |
3960 | /* We use the reloc_count field as a counter if we need | |
3961 | to copy relocs into the output file. */ | |
3962 | s->reloc_count = 0; | |
3963 | } | |
3964 | } | |
3965 | else if (strncmp (name, ".got", 4) != 0) | |
3966 | { | |
3967 | /* It's not one of our sections, so don't allocate space. */ | |
3968 | continue; | |
3969 | } | |
3970 | ||
3971 | if (strip) | |
3972 | { | |
3973 | _bfd_strip_section_from_output (info, s); | |
3974 | continue; | |
3975 | } | |
3976 | ||
3977 | /* Allocate memory for the section contents. */ | |
3978 | s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size); | |
3979 | if (s->contents == NULL && s->_raw_size != 0) | |
3980 | return false; | |
3981 | } | |
3982 | ||
3983 | if (elf_hash_table (info)->dynamic_sections_created) | |
3984 | { | |
3985 | /* Add some entries to the .dynamic section. We fill in the | |
3986 | values later, in sh_elf_finish_dynamic_sections, but we | |
3987 | must add the entries now so that we get the correct size for | |
3988 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
3989 | dynamic linker and used by the debugger. */ | |
dc810e39 AM |
3990 | #define add_dynamic_entry(TAG, VAL) \ |
3991 | bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL)) | |
3992 | ||
37c644f2 AO |
3993 | if (! info->shared) |
3994 | { | |
dc810e39 | 3995 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
37c644f2 AO |
3996 | return false; |
3997 | } | |
3998 | ||
3999 | if (plt) | |
4000 | { | |
dc810e39 AM |
4001 | if (!add_dynamic_entry (DT_PLTGOT, 0) |
4002 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
4003 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) | |
4004 | || !add_dynamic_entry (DT_JMPREL, 0)) | |
37c644f2 AO |
4005 | return false; |
4006 | } | |
4007 | ||
4008 | if (relocs) | |
4009 | { | |
dc810e39 AM |
4010 | if (!add_dynamic_entry (DT_RELA, 0) |
4011 | || !add_dynamic_entry (DT_RELASZ, 0) | |
4012 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela))) | |
37c644f2 AO |
4013 | return false; |
4014 | } | |
4015 | ||
99e4ae17 | 4016 | if ((info->flags & DF_TEXTREL) != 0) |
37c644f2 | 4017 | { |
dc810e39 | 4018 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
37c644f2 AO |
4019 | return false; |
4020 | } | |
4021 | } | |
dc810e39 | 4022 | #undef add_dynamic_entry |
37c644f2 AO |
4023 | |
4024 | return true; | |
4025 | } | |
4026 | ||
4027 | /* This function is called via sh_elf_link_hash_traverse if we are | |
4028 | creating a shared object with -Bsymbolic. It discards the space | |
4029 | allocated to copy PC relative relocs against symbols which are | |
4030 | defined in regular objects. We allocated space for them in the | |
4031 | check_relocs routine, but we won't fill them in in the | |
4032 | relocate_section routine. */ | |
4033 | ||
37c644f2 AO |
4034 | static boolean |
4035 | sh_elf_discard_copies (h, ignore) | |
4036 | struct elf_sh_link_hash_entry *h; | |
4037 | PTR ignore ATTRIBUTE_UNUSED; | |
4038 | { | |
4039 | struct elf_sh_pcrel_relocs_copied *s; | |
4040 | ||
4041 | /* We only discard relocs for symbols defined in a regular object. */ | |
4042 | if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
4043 | return true; | |
4044 | ||
4045 | for (s = h->pcrel_relocs_copied; s != NULL; s = s->next) | |
4046 | s->section->_raw_size -= s->count * sizeof (Elf32_External_Rela); | |
4047 | ||
4048 | return true; | |
4049 | } | |
37c644f2 AO |
4050 | \f |
4051 | /* Relocate an SH ELF section. */ | |
4052 | ||
4053 | static boolean | |
4054 | sh_elf_relocate_section (output_bfd, info, input_bfd, input_section, | |
4055 | contents, relocs, local_syms, local_sections) | |
f8df10f4 | 4056 | bfd *output_bfd; |
37c644f2 AO |
4057 | struct bfd_link_info *info; |
4058 | bfd *input_bfd; | |
4059 | asection *input_section; | |
4060 | bfd_byte *contents; | |
4061 | Elf_Internal_Rela *relocs; | |
4062 | Elf_Internal_Sym *local_syms; | |
4063 | asection **local_sections; | |
4064 | { | |
4065 | Elf_Internal_Shdr *symtab_hdr; | |
4066 | struct elf_link_hash_entry **sym_hashes; | |
4067 | Elf_Internal_Rela *rel, *relend; | |
4068 | bfd *dynobj; | |
4069 | bfd_vma *local_got_offsets; | |
4070 | asection *sgot; | |
fbca6ad9 | 4071 | asection *sgotplt; |
37c644f2 AO |
4072 | asection *splt; |
4073 | asection *sreloc; | |
4074 | ||
4075 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
4076 | sym_hashes = elf_sym_hashes (input_bfd); | |
4077 | dynobj = elf_hash_table (info)->dynobj; | |
4078 | local_got_offsets = elf_local_got_offsets (input_bfd); | |
4079 | ||
4080 | sgot = NULL; | |
fbca6ad9 | 4081 | sgotplt = NULL; |
37c644f2 AO |
4082 | splt = NULL; |
4083 | sreloc = NULL; | |
4084 | ||
4085 | rel = relocs; | |
4086 | relend = relocs + input_section->reloc_count; | |
4087 | for (; rel < relend; rel++) | |
4088 | { | |
4089 | int r_type; | |
4090 | reloc_howto_type *howto; | |
4091 | unsigned long r_symndx; | |
4092 | Elf_Internal_Sym *sym; | |
4093 | asection *sec; | |
4094 | struct elf_link_hash_entry *h; | |
4095 | bfd_vma relocation; | |
435b1e90 | 4096 | bfd_vma addend = (bfd_vma) 0; |
37c644f2 | 4097 | bfd_reloc_status_type r; |
fbca6ad9 | 4098 | int seen_stt_datalabel = 0; |
37c644f2 AO |
4099 | |
4100 | r_symndx = ELF32_R_SYM (rel->r_info); | |
4101 | ||
37c644f2 AO |
4102 | r_type = ELF32_R_TYPE (rel->r_info); |
4103 | ||
4104 | /* Many of the relocs are only used for relaxing, and are | |
4105 | handled entirely by the relaxation code. */ | |
4106 | if (r_type > (int) R_SH_LAST_INVALID_RELOC | |
4107 | && r_type < (int) R_SH_LOOP_START) | |
4108 | continue; | |
c5aeb40f AO |
4109 | if (r_type == (int) R_SH_NONE) |
4110 | continue; | |
37c644f2 AO |
4111 | |
4112 | if (r_type < 0 | |
4113 | || r_type >= R_SH_max | |
4114 | || (r_type >= (int) R_SH_FIRST_INVALID_RELOC | |
06bb75c1 | 4115 | && r_type <= (int) R_SH_LAST_INVALID_RELOC) |
fbca6ad9 AO |
4116 | || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_3 |
4117 | && r_type <= (int) R_SH_LAST_INVALID_RELOC_3) | |
4118 | || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_4 | |
4119 | && r_type <= (int) R_SH_LAST_INVALID_RELOC_4) | |
06bb75c1 AO |
4120 | || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_2 |
4121 | && r_type <= (int) R_SH_LAST_INVALID_RELOC_2)) | |
37c644f2 AO |
4122 | { |
4123 | bfd_set_error (bfd_error_bad_value); | |
4124 | return false; | |
4125 | } | |
4126 | ||
4127 | howto = sh_elf_howto_table + r_type; | |
4128 | ||
146be91a HPN |
4129 | /* For relocs that aren't partial_inplace, we get the addend from |
4130 | the relocation. */ | |
4131 | if (! howto->partial_inplace) | |
4132 | addend = rel->r_addend; | |
4133 | ||
37c644f2 AO |
4134 | h = NULL; |
4135 | sym = NULL; | |
4136 | sec = NULL; | |
4137 | if (r_symndx < symtab_hdr->sh_info) | |
4138 | { | |
4139 | sym = local_syms + r_symndx; | |
4140 | sec = local_sections[r_symndx]; | |
4141 | relocation = (sec->output_section->vma | |
4142 | + sec->output_offset | |
4143 | + sym->st_value); | |
fbca6ad9 AO |
4144 | /* A local symbol never has STO_SH5_ISA32, so we don't need |
4145 | datalabel processing here. Make sure this does not change | |
4146 | without notice. */ | |
4147 | if ((sym->st_other & STO_SH5_ISA32) != 0) | |
4148 | ((*info->callbacks->reloc_dangerous) | |
4149 | (info, | |
4150 | _("Unexpected STO_SH5_ISA32 on local symbol is not handled"), | |
4151 | input_bfd, input_section, rel->r_offset)); | |
8a3975e6 AO |
4152 | if (info->relocateable) |
4153 | { | |
4154 | /* This is a relocateable link. We don't have to change | |
4155 | anything, unless the reloc is against a section symbol, | |
4156 | in which case we have to adjust according to where the | |
4157 | section symbol winds up in the output section. */ | |
4158 | sym = local_syms + r_symndx; | |
4159 | if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
146be91a HPN |
4160 | { |
4161 | if (! howto->partial_inplace) | |
4162 | { | |
4163 | /* For relocations with the addend in the | |
4164 | relocation, we need just to update the addend. | |
4165 | All real relocs are of type partial_inplace; this | |
4166 | code is mostly for completeness. */ | |
4167 | rel->r_addend += sec->output_offset + sym->st_value; | |
4168 | ||
4169 | continue; | |
4170 | } | |
4171 | ||
4172 | /* Relocs of type partial_inplace need to pick up the | |
4173 | contents in the contents and add the offset resulting | |
4174 | from the changed location of the section symbol. | |
4175 | Using _bfd_final_link_relocate (e.g. goto | |
4176 | final_link_relocate) here would be wrong, because | |
4177 | relocations marked pc_relative would get the current | |
4178 | location subtracted, and we must only do that at the | |
4179 | final link. */ | |
4180 | r = _bfd_relocate_contents (howto, input_bfd, | |
4181 | sec->output_offset | |
4182 | + sym->st_value, | |
4183 | contents + rel->r_offset); | |
4184 | goto relocation_done; | |
4185 | } | |
8a3975e6 AO |
4186 | |
4187 | continue; | |
4188 | } | |
f8df10f4 JJ |
4189 | else if (! howto->partial_inplace) |
4190 | { | |
4191 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel); | |
4192 | addend = rel->r_addend; | |
4193 | } | |
4194 | else if ((sec->flags & SEC_MERGE) | |
4195 | && ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
4196 | { | |
4197 | asection *msec; | |
4198 | ||
4199 | if (howto->rightshift || howto->src_mask != 0xffffffff) | |
4200 | { | |
4201 | (*_bfd_error_handler) | |
4202 | (_("%s(%s+0x%lx): %s relocation against SEC_MERGE section"), | |
4203 | bfd_archive_filename (input_bfd), | |
4204 | bfd_get_section_name (input_bfd, input_section), | |
4205 | (long) rel->r_offset, howto->name); | |
4206 | return false; | |
4207 | } | |
4208 | ||
4209 | addend = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
4210 | msec = sec; | |
4211 | addend = | |
c629eae0 | 4212 | _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend) |
f8df10f4 JJ |
4213 | - relocation; |
4214 | addend += msec->output_section->vma + msec->output_offset; | |
4215 | bfd_put_32 (input_bfd, addend, contents + rel->r_offset); | |
4216 | addend = 0; | |
4217 | } | |
37c644f2 AO |
4218 | } |
4219 | else | |
4220 | { | |
8a3975e6 AO |
4221 | /* Section symbol are never (?) placed in the hash table, so |
4222 | we can just ignore hash relocations when creating a | |
4223 | relocateable object file. */ | |
4224 | if (info->relocateable) | |
4225 | continue; | |
4226 | ||
37c644f2 AO |
4227 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
4228 | while (h->root.type == bfd_link_hash_indirect | |
4229 | || h->root.type == bfd_link_hash_warning) | |
fbca6ad9 AO |
4230 | { |
4231 | #ifdef INCLUDE_SHMEDIA | |
4232 | /* If the reference passes a symbol marked with | |
4233 | STT_DATALABEL, then any STO_SH5_ISA32 on the final value | |
4234 | doesn't count. */ | |
4235 | seen_stt_datalabel |= h->type == STT_DATALABEL; | |
4236 | #endif | |
4237 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
4238 | } | |
37c644f2 AO |
4239 | if (h->root.type == bfd_link_hash_defined |
4240 | || h->root.type == bfd_link_hash_defweak) | |
4241 | { | |
4242 | sec = h->root.u.def.section; | |
4243 | /* In these cases, we don't need the relocation value. | |
4244 | We check specially because in some obscure cases | |
435b1e90 | 4245 | sec->output_section will be NULL. */ |
37c644f2 | 4246 | if (r_type == R_SH_GOTPC |
fbca6ad9 AO |
4247 | || r_type == R_SH_GOTPC_LOW16 |
4248 | || r_type == R_SH_GOTPC_MEDLOW16 | |
4249 | || r_type == R_SH_GOTPC_MEDHI16 | |
4250 | || r_type == R_SH_GOTPC_HI16 | |
4251 | || ((r_type == R_SH_PLT32 | |
4252 | || r_type == R_SH_PLT_LOW16 | |
4253 | || r_type == R_SH_PLT_MEDLOW16 | |
4254 | || r_type == R_SH_PLT_MEDHI16 | |
4255 | || r_type == R_SH_PLT_HI16) | |
37c644f2 | 4256 | && h->plt.offset != (bfd_vma) -1) |
fbca6ad9 AO |
4257 | || ((r_type == R_SH_GOT32 |
4258 | || r_type == R_SH_GOT_LOW16 | |
4259 | || r_type == R_SH_GOT_MEDLOW16 | |
4260 | || r_type == R_SH_GOT_MEDHI16 | |
4261 | || r_type == R_SH_GOT_HI16) | |
37c644f2 AO |
4262 | && elf_hash_table (info)->dynamic_sections_created |
4263 | && (! info->shared | |
4264 | || (! info->symbolic && h->dynindx != -1) | |
4265 | || (h->elf_link_hash_flags | |
4266 | & ELF_LINK_HASH_DEF_REGULAR) == 0)) | |
4267 | /* The cases above are those in which relocation is | |
4268 | overwritten in the switch block below. The cases | |
4269 | below are those in which we must defer relocation | |
4270 | to run-time, because we can't resolve absolute | |
4271 | addresses when creating a shared library. */ | |
4272 | || (info->shared | |
4273 | && ((! info->symbolic && h->dynindx != -1) | |
4274 | || (h->elf_link_hash_flags | |
4275 | & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
4276 | && ((r_type == R_SH_DIR32 | |
4277 | && !(ELF_ST_VISIBILITY (h->other) == STV_INTERNAL | |
4278 | || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)) | |
4279 | || r_type == R_SH_REL32) | |
4280 | && ((input_section->flags & SEC_ALLOC) != 0 | |
4281 | /* DWARF will emit R_SH_DIR32 relocations in its | |
4282 | sections against symbols defined externally | |
4283 | in shared libraries. We can't do anything | |
4284 | with them here. */ | |
4285 | || (input_section->flags & SEC_DEBUGGING) != 0))) | |
4286 | relocation = 0; | |
4287 | else if (sec->output_section == NULL) | |
4288 | { | |
4289 | (*_bfd_error_handler) | |
4290 | (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"), | |
8f615d07 | 4291 | bfd_archive_filename (input_bfd), h->root.root.string, |
37c644f2 AO |
4292 | bfd_get_section_name (input_bfd, input_section)); |
4293 | relocation = 0; | |
4294 | } | |
4295 | else | |
fbca6ad9 | 4296 | relocation = ((h->root.u.def.value |
37c644f2 | 4297 | + sec->output_section->vma |
fbca6ad9 AO |
4298 | + sec->output_offset) |
4299 | /* A STO_SH5_ISA32 causes a "bitor 1" to the | |
4300 | symbol value, unless we've seen | |
4301 | STT_DATALABEL on the way to it. */ | |
4302 | | ((h->other & STO_SH5_ISA32) != 0 | |
4303 | && ! seen_stt_datalabel)); | |
37c644f2 AO |
4304 | } |
4305 | else if (h->root.type == bfd_link_hash_undefweak) | |
4306 | relocation = 0; | |
671bae9c NC |
4307 | else if (info->shared |
4308 | && (!info->symbolic || info->allow_shlib_undefined) | |
4309 | && !info->no_undefined) | |
37c644f2 AO |
4310 | relocation = 0; |
4311 | else | |
4312 | { | |
4313 | if (! ((*info->callbacks->undefined_symbol) | |
4314 | (info, h->root.root.string, input_bfd, | |
4315 | input_section, rel->r_offset, true))) | |
4316 | return false; | |
4317 | relocation = 0; | |
4318 | } | |
4319 | } | |
4320 | ||
435b1e90 | 4321 | switch ((int) r_type) |
37c644f2 AO |
4322 | { |
4323 | final_link_relocate: | |
4324 | /* COFF relocs don't use the addend. The addend is used for | |
435b1e90 | 4325 | R_SH_DIR32 to be compatible with other compilers. */ |
37c644f2 AO |
4326 | r = _bfd_final_link_relocate (howto, input_bfd, input_section, |
4327 | contents, rel->r_offset, | |
4328 | relocation, addend); | |
4329 | break; | |
4330 | ||
4331 | case R_SH_IND12W: | |
cd6ec716 DD |
4332 | relocation -= 4; |
4333 | goto final_link_relocate; | |
4334 | ||
37c644f2 AO |
4335 | case R_SH_DIR8WPN: |
4336 | case R_SH_DIR8WPZ: | |
4337 | case R_SH_DIR8WPL: | |
cd6ec716 DD |
4338 | /* If the reloc is against the start of this section, then |
4339 | the assembler has already taken care of it and the reloc | |
4340 | is here only to assist in relaxing. If the reloc is not | |
4341 | against the start of this section, then it's against an | |
4342 | external symbol and we must deal with it ourselves. */ | |
4343 | if (input_section->output_section->vma + input_section->output_offset | |
4344 | != relocation) | |
4345 | { | |
4346 | int disp = (relocation | |
4347 | - input_section->output_section->vma | |
4348 | - input_section->output_offset | |
4349 | - rel->r_offset); | |
4350 | int mask = 0; | |
4351 | switch (r_type) | |
4352 | { | |
4353 | case R_SH_DIR8WPN: | |
4354 | case R_SH_DIR8WPZ: mask = 1; break; | |
4355 | case R_SH_DIR8WPL: mask = 3; break; | |
4356 | default: mask = 0; break; | |
4357 | } | |
4358 | if (disp & mask) | |
4359 | { | |
4360 | ((*_bfd_error_handler) | |
4361 | (_("%s: 0x%lx: fatal: unaligned branch target for relax-support relocation"), | |
8f615d07 | 4362 | bfd_archive_filename (input_section->owner), |
cd6ec716 DD |
4363 | (unsigned long) rel->r_offset)); |
4364 | bfd_set_error (bfd_error_bad_value); | |
4365 | return false; | |
4366 | } | |
4367 | relocation -= 4; | |
4368 | goto final_link_relocate; | |
4369 | } | |
4370 | r = bfd_reloc_ok; | |
4371 | break; | |
37c644f2 AO |
4372 | |
4373 | default: | |
fbca6ad9 AO |
4374 | #ifdef INCLUDE_SHMEDIA |
4375 | if (shmedia_prepare_reloc (info, input_bfd, input_section, | |
4376 | contents, rel, &relocation)) | |
4377 | goto final_link_relocate; | |
4378 | #endif | |
37c644f2 AO |
4379 | bfd_set_error (bfd_error_bad_value); |
4380 | return false; | |
4381 | ||
4382 | case R_SH_DIR32: | |
4383 | case R_SH_REL32: | |
4384 | if (info->shared | |
ec338859 | 4385 | && r_symndx != 0 |
37c644f2 AO |
4386 | && (input_section->flags & SEC_ALLOC) != 0 |
4387 | && (r_type != R_SH_REL32 | |
4388 | || (h != NULL | |
4389 | && h->dynindx != -1 | |
4390 | && (! info->symbolic | |
4391 | || (h->elf_link_hash_flags | |
4392 | & ELF_LINK_HASH_DEF_REGULAR) == 0)))) | |
4393 | { | |
4394 | Elf_Internal_Rela outrel; | |
4395 | boolean skip, relocate; | |
4396 | ||
4397 | /* When generating a shared object, these relocations | |
4398 | are copied into the output file to be resolved at run | |
4399 | time. */ | |
4400 | ||
4401 | if (sreloc == NULL) | |
4402 | { | |
4403 | const char *name; | |
4404 | ||
4405 | name = (bfd_elf_string_from_elf_section | |
4406 | (input_bfd, | |
4407 | elf_elfheader (input_bfd)->e_shstrndx, | |
4408 | elf_section_data (input_section)->rel_hdr.sh_name)); | |
4409 | if (name == NULL) | |
4410 | return false; | |
4411 | ||
4412 | BFD_ASSERT (strncmp (name, ".rela", 5) == 0 | |
4413 | && strcmp (bfd_get_section_name (input_bfd, | |
4414 | input_section), | |
4415 | name + 5) == 0); | |
4416 | ||
4417 | sreloc = bfd_get_section_by_name (dynobj, name); | |
4418 | BFD_ASSERT (sreloc != NULL); | |
4419 | } | |
4420 | ||
4421 | skip = false; | |
0bb2d96a | 4422 | relocate = false; |
37c644f2 | 4423 | |
c629eae0 JJ |
4424 | outrel.r_offset = |
4425 | _bfd_elf_section_offset (output_bfd, info, input_section, | |
4426 | rel->r_offset); | |
4427 | if (outrel.r_offset == (bfd_vma) -1) | |
4428 | skip = true; | |
0bb2d96a JJ |
4429 | else if (outrel.r_offset == (bfd_vma) -2) |
4430 | skip = true, relocate = true; | |
37c644f2 AO |
4431 | outrel.r_offset += (input_section->output_section->vma |
4432 | + input_section->output_offset); | |
4433 | ||
4434 | if (skip) | |
0bb2d96a | 4435 | memset (&outrel, 0, sizeof outrel); |
37c644f2 AO |
4436 | else if (r_type == R_SH_REL32) |
4437 | { | |
4438 | BFD_ASSERT (h != NULL && h->dynindx != -1); | |
37c644f2 | 4439 | outrel.r_info = ELF32_R_INFO (h->dynindx, R_SH_REL32); |
146be91a HPN |
4440 | outrel.r_addend |
4441 | = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
37c644f2 AO |
4442 | } |
4443 | else | |
4444 | { | |
4445 | /* h->dynindx may be -1 if this symbol was marked to | |
4446 | become local. */ | |
4447 | if (h == NULL | |
4448 | || ((info->symbolic || h->dynindx == -1) | |
4449 | && (h->elf_link_hash_flags | |
4450 | & ELF_LINK_HASH_DEF_REGULAR) != 0)) | |
4451 | { | |
4452 | relocate = true; | |
4453 | outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE); | |
146be91a HPN |
4454 | outrel.r_addend |
4455 | = relocation + bfd_get_32 (input_bfd, | |
4456 | contents + rel->r_offset); | |
37c644f2 AO |
4457 | } |
4458 | else | |
4459 | { | |
4460 | BFD_ASSERT (h->dynindx != -1); | |
37c644f2 | 4461 | outrel.r_info = ELF32_R_INFO (h->dynindx, R_SH_DIR32); |
146be91a HPN |
4462 | outrel.r_addend |
4463 | = relocation + bfd_get_32 (input_bfd, | |
4464 | contents + rel->r_offset); | |
37c644f2 AO |
4465 | } |
4466 | } | |
4467 | ||
4468 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, | |
435b1e90 KH |
4469 | (((Elf32_External_Rela *) |
4470 | sreloc->contents) | |
4471 | + sreloc->reloc_count)); | |
37c644f2 AO |
4472 | ++sreloc->reloc_count; |
4473 | ||
4474 | /* If this reloc is against an external symbol, we do | |
4475 | not want to fiddle with the addend. Otherwise, we | |
4476 | need to include the symbol value so that it becomes | |
4477 | an addend for the dynamic reloc. */ | |
4478 | if (! relocate) | |
4479 | continue; | |
4480 | } | |
37c644f2 AO |
4481 | goto final_link_relocate; |
4482 | ||
fbca6ad9 AO |
4483 | case R_SH_GOTPLT32: |
4484 | #ifdef INCLUDE_SHMEDIA | |
4485 | case R_SH_GOTPLT_LOW16: | |
4486 | case R_SH_GOTPLT_MEDLOW16: | |
4487 | case R_SH_GOTPLT_MEDHI16: | |
4488 | case R_SH_GOTPLT_HI16: | |
4489 | case R_SH_GOTPLT10BY4: | |
4490 | case R_SH_GOTPLT10BY8: | |
4491 | #endif | |
4492 | /* Relocation is to the entry for this symbol in the | |
4493 | procedure linkage table. */ | |
4494 | ||
4495 | if (h == NULL | |
4496 | || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL | |
4497 | || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN | |
4498 | || ! info->shared | |
4499 | || info->symbolic | |
4500 | || h->dynindx == -1 | |
4501 | || h->plt.offset == (bfd_vma) -1 | |
4502 | || h->got.offset != (bfd_vma) -1) | |
4503 | goto force_got; | |
4504 | ||
4505 | /* Relocation is to the entry for this symbol in the global | |
4506 | offset table extension for the procedure linkage table. */ | |
4507 | if (sgotplt == NULL) | |
4508 | { | |
4509 | sgotplt = bfd_get_section_by_name (dynobj, ".got.plt"); | |
4510 | BFD_ASSERT (sgotplt != NULL); | |
4511 | } | |
4512 | ||
4513 | relocation = (sgotplt->output_offset | |
4514 | + ((h->plt.offset / elf_sh_sizeof_plt (info) | |
4515 | - 1 + 3) * 4)); | |
4516 | ||
4517 | #ifdef GOT_BIAS | |
4518 | relocation -= GOT_BIAS; | |
4519 | #endif | |
4520 | ||
4521 | goto final_link_relocate; | |
4522 | ||
4523 | force_got: | |
37c644f2 | 4524 | case R_SH_GOT32: |
fbca6ad9 AO |
4525 | #ifdef INCLUDE_SHMEDIA |
4526 | case R_SH_GOT_LOW16: | |
4527 | case R_SH_GOT_MEDLOW16: | |
4528 | case R_SH_GOT_MEDHI16: | |
4529 | case R_SH_GOT_HI16: | |
4530 | case R_SH_GOT10BY4: | |
4531 | case R_SH_GOT10BY8: | |
4532 | #endif | |
37c644f2 AO |
4533 | /* Relocation is to the entry for this symbol in the global |
4534 | offset table. */ | |
4535 | if (sgot == NULL) | |
4536 | { | |
4537 | sgot = bfd_get_section_by_name (dynobj, ".got"); | |
4538 | BFD_ASSERT (sgot != NULL); | |
4539 | } | |
4540 | ||
4541 | if (h != NULL) | |
4542 | { | |
4543 | bfd_vma off; | |
4544 | ||
4545 | off = h->got.offset; | |
fbca6ad9 AO |
4546 | #ifdef INCLUDE_SHMEDIA |
4547 | if (seen_stt_datalabel) | |
4548 | { | |
4549 | struct elf_sh_link_hash_entry *hsh; | |
4550 | ||
4551 | hsh = (struct elf_sh_link_hash_entry *)h; | |
4552 | off = hsh->datalabel_got_offset; | |
4553 | } | |
4554 | #endif | |
37c644f2 AO |
4555 | BFD_ASSERT (off != (bfd_vma) -1); |
4556 | ||
4557 | if (! elf_hash_table (info)->dynamic_sections_created | |
4558 | || (info->shared | |
4559 | && (info->symbolic || h->dynindx == -1 | |
4560 | || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL | |
4561 | || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN) | |
4562 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))) | |
4563 | { | |
4564 | /* This is actually a static link, or it is a | |
4565 | -Bsymbolic link and the symbol is defined | |
4566 | locally, or the symbol was forced to be local | |
4567 | because of a version file. We must initialize | |
4568 | this entry in the global offset table. Since the | |
4569 | offset must always be a multiple of 4, we use the | |
4570 | least significant bit to record whether we have | |
4571 | initialized it already. | |
4572 | ||
4573 | When doing a dynamic link, we create a .rela.got | |
4574 | relocation entry to initialize the value. This | |
4575 | is done in the finish_dynamic_symbol routine. */ | |
4576 | if ((off & 1) != 0) | |
4577 | off &= ~1; | |
4578 | else | |
4579 | { | |
4580 | bfd_put_32 (output_bfd, relocation, | |
4581 | sgot->contents + off); | |
fbca6ad9 AO |
4582 | #ifdef INCLUDE_SHMEDIA |
4583 | if (seen_stt_datalabel) | |
4584 | { | |
4585 | struct elf_sh_link_hash_entry *hsh; | |
4586 | ||
4587 | hsh = (struct elf_sh_link_hash_entry *)h; | |
4588 | hsh->datalabel_got_offset |= 1; | |
4589 | } | |
4590 | else | |
4591 | #endif | |
4592 | h->got.offset |= 1; | |
37c644f2 AO |
4593 | } |
4594 | } | |
4595 | ||
4596 | relocation = sgot->output_offset + off; | |
4597 | } | |
4598 | else | |
4599 | { | |
4600 | bfd_vma off; | |
4601 | ||
fbca6ad9 AO |
4602 | #ifdef INCLUDE_SHMEDIA |
4603 | if (rel->r_addend) | |
4604 | { | |
4605 | BFD_ASSERT (local_got_offsets != NULL | |
4606 | && (local_got_offsets[symtab_hdr->sh_info | |
4607 | + r_symndx] | |
4608 | != (bfd_vma) -1)); | |
4609 | ||
4610 | off = local_got_offsets[symtab_hdr->sh_info | |
4611 | + r_symndx]; | |
4612 | } | |
4613 | else | |
4614 | { | |
4615 | #endif | |
37c644f2 AO |
4616 | BFD_ASSERT (local_got_offsets != NULL |
4617 | && local_got_offsets[r_symndx] != (bfd_vma) -1); | |
4618 | ||
4619 | off = local_got_offsets[r_symndx]; | |
fbca6ad9 AO |
4620 | #ifdef INCLUDE_SHMEDIA |
4621 | } | |
4622 | #endif | |
37c644f2 AO |
4623 | |
4624 | /* The offset must always be a multiple of 4. We use | |
4625 | the least significant bit to record whether we have | |
4626 | already generated the necessary reloc. */ | |
4627 | if ((off & 1) != 0) | |
4628 | off &= ~1; | |
4629 | else | |
4630 | { | |
4631 | bfd_put_32 (output_bfd, relocation, sgot->contents + off); | |
4632 | ||
4633 | if (info->shared) | |
4634 | { | |
4635 | asection *srelgot; | |
4636 | Elf_Internal_Rela outrel; | |
4637 | ||
4638 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); | |
4639 | BFD_ASSERT (srelgot != NULL); | |
4640 | ||
4641 | outrel.r_offset = (sgot->output_section->vma | |
4642 | + sgot->output_offset | |
4643 | + off); | |
4644 | outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE); | |
4645 | outrel.r_addend = relocation; | |
4646 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, | |
4647 | (((Elf32_External_Rela *) | |
4648 | srelgot->contents) | |
4649 | + srelgot->reloc_count)); | |
4650 | ++srelgot->reloc_count; | |
4651 | } | |
4652 | ||
fbca6ad9 AO |
4653 | #ifdef INCLUDE_SHMEDIA |
4654 | if (rel->r_addend) | |
4655 | local_got_offsets[symtab_hdr->sh_info + r_symndx] |= 1; | |
4656 | else | |
4657 | #endif | |
4658 | local_got_offsets[r_symndx] |= 1; | |
37c644f2 AO |
4659 | } |
4660 | ||
4661 | relocation = sgot->output_offset + off; | |
4662 | } | |
4663 | ||
fbca6ad9 AO |
4664 | #ifdef GOT_BIAS |
4665 | relocation -= GOT_BIAS; | |
4666 | #endif | |
4667 | ||
37c644f2 AO |
4668 | goto final_link_relocate; |
4669 | ||
4670 | case R_SH_GOTOFF: | |
fbca6ad9 AO |
4671 | #ifdef INCLUDE_SHMEDIA |
4672 | case R_SH_GOTOFF_LOW16: | |
4673 | case R_SH_GOTOFF_MEDLOW16: | |
4674 | case R_SH_GOTOFF_MEDHI16: | |
4675 | case R_SH_GOTOFF_HI16: | |
4676 | #endif | |
37c644f2 AO |
4677 | /* Relocation is relative to the start of the global offset |
4678 | table. */ | |
4679 | ||
4680 | if (sgot == NULL) | |
4681 | { | |
4682 | sgot = bfd_get_section_by_name (dynobj, ".got"); | |
4683 | BFD_ASSERT (sgot != NULL); | |
4684 | } | |
4685 | ||
4686 | /* Note that sgot->output_offset is not involved in this | |
4687 | calculation. We always want the start of .got. If we | |
4688 | defined _GLOBAL_OFFSET_TABLE in a different way, as is | |
4689 | permitted by the ABI, we might have to change this | |
4690 | calculation. */ | |
4691 | relocation -= sgot->output_section->vma; | |
4692 | ||
fbca6ad9 AO |
4693 | #ifdef GOT_BIAS |
4694 | relocation -= GOT_BIAS; | |
4695 | #endif | |
4696 | ||
4697 | addend = rel->r_addend; | |
4698 | ||
37c644f2 AO |
4699 | goto final_link_relocate; |
4700 | ||
4701 | case R_SH_GOTPC: | |
fbca6ad9 AO |
4702 | #ifdef INCLUDE_SHMEDIA |
4703 | case R_SH_GOTPC_LOW16: | |
4704 | case R_SH_GOTPC_MEDLOW16: | |
4705 | case R_SH_GOTPC_MEDHI16: | |
4706 | case R_SH_GOTPC_HI16: | |
4707 | #endif | |
37c644f2 AO |
4708 | /* Use global offset table as symbol value. */ |
4709 | ||
4710 | if (sgot == NULL) | |
4711 | { | |
4712 | sgot = bfd_get_section_by_name (dynobj, ".got"); | |
4713 | BFD_ASSERT (sgot != NULL); | |
4714 | } | |
4715 | ||
4716 | relocation = sgot->output_section->vma; | |
4717 | ||
fbca6ad9 AO |
4718 | #ifdef GOT_BIAS |
4719 | relocation += GOT_BIAS; | |
4720 | #endif | |
4721 | ||
4722 | addend = rel->r_addend; | |
4723 | ||
37c644f2 AO |
4724 | goto final_link_relocate; |
4725 | ||
4726 | case R_SH_PLT32: | |
fbca6ad9 AO |
4727 | #ifdef INCLUDE_SHMEDIA |
4728 | case R_SH_PLT_LOW16: | |
4729 | case R_SH_PLT_MEDLOW16: | |
4730 | case R_SH_PLT_MEDHI16: | |
4731 | case R_SH_PLT_HI16: | |
4732 | #endif | |
37c644f2 AO |
4733 | /* Relocation is to the entry for this symbol in the |
4734 | procedure linkage table. */ | |
4735 | ||
4736 | /* Resolve a PLT reloc against a local symbol directly, | |
4737 | without using the procedure linkage table. */ | |
4738 | if (h == NULL) | |
4739 | goto final_link_relocate; | |
4740 | ||
4741 | if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL | |
4742 | || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN) | |
4743 | goto final_link_relocate; | |
4744 | ||
4745 | if (h->plt.offset == (bfd_vma) -1) | |
4746 | { | |
4747 | /* We didn't make a PLT entry for this symbol. This | |
4748 | happens when statically linking PIC code, or when | |
4749 | using -Bsymbolic. */ | |
4750 | goto final_link_relocate; | |
4751 | } | |
4752 | ||
4753 | if (splt == NULL) | |
4754 | { | |
4755 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
4756 | BFD_ASSERT (splt != NULL); | |
4757 | } | |
4758 | ||
4759 | relocation = (splt->output_section->vma | |
4760 | + splt->output_offset | |
4761 | + h->plt.offset); | |
4762 | ||
fbca6ad9 AO |
4763 | #ifdef INCLUDE_SHMEDIA |
4764 | relocation++; | |
4765 | #endif | |
4766 | ||
4767 | addend = rel->r_addend; | |
4768 | ||
37c644f2 AO |
4769 | goto final_link_relocate; |
4770 | ||
4771 | case R_SH_LOOP_START: | |
4772 | { | |
4773 | static bfd_vma start, end; | |
4774 | ||
4775 | start = (relocation + rel->r_addend | |
4776 | - (sec->output_section->vma + sec->output_offset)); | |
4777 | r = sh_elf_reloc_loop (r_type, input_bfd, input_section, contents, | |
4778 | rel->r_offset, sec, start, end); | |
4779 | break; | |
4780 | ||
4781 | case R_SH_LOOP_END: | |
4782 | end = (relocation + rel->r_addend | |
4783 | - (sec->output_section->vma + sec->output_offset)); | |
4784 | r = sh_elf_reloc_loop (r_type, input_bfd, input_section, contents, | |
4785 | rel->r_offset, sec, start, end); | |
4786 | break; | |
4787 | } | |
4788 | } | |
4789 | ||
146be91a | 4790 | relocation_done: |
37c644f2 AO |
4791 | if (r != bfd_reloc_ok) |
4792 | { | |
4793 | switch (r) | |
4794 | { | |
4795 | default: | |
4796 | case bfd_reloc_outofrange: | |
4797 | abort (); | |
4798 | case bfd_reloc_overflow: | |
4799 | { | |
4800 | const char *name; | |
4801 | ||
4802 | if (h != NULL) | |
4803 | name = h->root.root.string; | |
4804 | else | |
4805 | { | |
252b5132 RH |
4806 | name = (bfd_elf_string_from_elf_section |
4807 | (input_bfd, symtab_hdr->sh_link, sym->st_name)); | |
4808 | if (name == NULL) | |
4809 | return false; | |
4810 | if (*name == '\0') | |
4811 | name = bfd_section_name (input_bfd, sec); | |
4812 | } | |
4813 | if (! ((*info->callbacks->reloc_overflow) | |
4814 | (info, name, howto->name, (bfd_vma) 0, | |
4815 | input_bfd, input_section, rel->r_offset))) | |
4816 | return false; | |
4817 | } | |
4818 | break; | |
4819 | } | |
4820 | } | |
4821 | } | |
4822 | ||
4823 | return true; | |
4824 | } | |
4825 | ||
4826 | /* This is a version of bfd_generic_get_relocated_section_contents | |
4827 | which uses sh_elf_relocate_section. */ | |
4828 | ||
4829 | static bfd_byte * | |
4830 | sh_elf_get_relocated_section_contents (output_bfd, link_info, link_order, | |
435b1e90 | 4831 | data, relocateable, symbols) |
252b5132 RH |
4832 | bfd *output_bfd; |
4833 | struct bfd_link_info *link_info; | |
4834 | struct bfd_link_order *link_order; | |
4835 | bfd_byte *data; | |
4836 | boolean relocateable; | |
4837 | asymbol **symbols; | |
4838 | { | |
4839 | Elf_Internal_Shdr *symtab_hdr; | |
9ad5cbcf | 4840 | Elf_Internal_Shdr *shndx_hdr; |
252b5132 RH |
4841 | asection *input_section = link_order->u.indirect.section; |
4842 | bfd *input_bfd = input_section->owner; | |
4843 | asection **sections = NULL; | |
4844 | Elf_Internal_Rela *internal_relocs = NULL; | |
4845 | Elf32_External_Sym *external_syms = NULL; | |
9ad5cbcf AM |
4846 | Elf_External_Sym_Shndx *shndx_buf = NULL; |
4847 | Elf_External_Sym_Shndx *shndx; | |
252b5132 RH |
4848 | Elf_Internal_Sym *internal_syms = NULL; |
4849 | ||
4850 | /* We only need to handle the case of relaxing, or of having a | |
4851 | particular set of section contents, specially. */ | |
4852 | if (relocateable | |
4853 | || elf_section_data (input_section)->this_hdr.contents == NULL) | |
4854 | return bfd_generic_get_relocated_section_contents (output_bfd, link_info, | |
4855 | link_order, data, | |
4856 | relocateable, | |
4857 | symbols); | |
4858 | ||
4859 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
9ad5cbcf | 4860 | shndx_hdr = &elf_tdata (input_bfd)->symtab_shndx_hdr; |
252b5132 RH |
4861 | |
4862 | memcpy (data, elf_section_data (input_section)->this_hdr.contents, | |
dc810e39 | 4863 | (size_t) input_section->_raw_size); |
252b5132 RH |
4864 | |
4865 | if ((input_section->flags & SEC_RELOC) != 0 | |
4866 | && input_section->reloc_count > 0) | |
4867 | { | |
4868 | Elf_Internal_Sym *isymp; | |
4869 | asection **secpp; | |
4870 | Elf32_External_Sym *esym, *esymend; | |
9ad5cbcf | 4871 | bfd_size_type amt; |
252b5132 RH |
4872 | |
4873 | if (symtab_hdr->contents != NULL) | |
4874 | external_syms = (Elf32_External_Sym *) symtab_hdr->contents; | |
9ad5cbcf | 4875 | else if (symtab_hdr->sh_info != 0) |
252b5132 | 4876 | { |
9ad5cbcf AM |
4877 | amt = symtab_hdr->sh_info; |
4878 | amt *= sizeof (Elf32_External_Sym); | |
4879 | external_syms = (Elf32_External_Sym *) bfd_malloc (amt); | |
4880 | if (external_syms == NULL) | |
252b5132 RH |
4881 | goto error_return; |
4882 | if (bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0 | |
9ad5cbcf AM |
4883 | || bfd_bread ((PTR) external_syms, amt, input_bfd) != amt) |
4884 | goto error_return; | |
4885 | } | |
4886 | ||
4887 | if (symtab_hdr->sh_info != 0 && shndx_hdr->sh_size != 0) | |
4888 | { | |
4889 | amt = symtab_hdr->sh_info; | |
4890 | amt *= sizeof (Elf_External_Sym_Shndx); | |
4891 | shndx_buf = (Elf_External_Sym_Shndx *) bfd_malloc (amt); | |
4892 | if (shndx_buf == NULL) | |
4893 | goto error_return; | |
4894 | if (bfd_seek (input_bfd, shndx_hdr->sh_offset, SEEK_SET) != 0 | |
4895 | || bfd_bread ((PTR) shndx_buf, amt, input_bfd) != amt) | |
252b5132 RH |
4896 | goto error_return; |
4897 | } | |
4898 | ||
4899 | internal_relocs = (_bfd_elf32_link_read_relocs | |
4900 | (input_bfd, input_section, (PTR) NULL, | |
4901 | (Elf_Internal_Rela *) NULL, false)); | |
4902 | if (internal_relocs == NULL) | |
4903 | goto error_return; | |
4904 | ||
9ad5cbcf AM |
4905 | amt = symtab_hdr->sh_info; |
4906 | amt *= sizeof (Elf_Internal_Sym); | |
4907 | internal_syms = (Elf_Internal_Sym *) bfd_malloc (amt); | |
4908 | if (internal_syms == NULL && amt != 0) | |
252b5132 RH |
4909 | goto error_return; |
4910 | ||
9ad5cbcf AM |
4911 | amt = symtab_hdr->sh_info; |
4912 | amt *= sizeof (asection *); | |
4913 | sections = (asection **) bfd_malloc (amt); | |
4914 | if (sections == NULL && amt != 0) | |
252b5132 RH |
4915 | goto error_return; |
4916 | ||
9ad5cbcf AM |
4917 | for (isymp = internal_syms, secpp = sections, shndx = shndx_buf, |
4918 | esym = external_syms, esymend = esym + symtab_hdr->sh_info; | |
4919 | esym < esymend; | |
4920 | ++esym, ++isymp, ++secpp, shndx = (shndx ? shndx + 1 : NULL)) | |
252b5132 RH |
4921 | { |
4922 | asection *isec; | |
4923 | ||
9ad5cbcf | 4924 | bfd_elf32_swap_symbol_in (input_bfd, esym, shndx, isymp); |
252b5132 RH |
4925 | |
4926 | if (isymp->st_shndx == SHN_UNDEF) | |
4927 | isec = bfd_und_section_ptr; | |
252b5132 RH |
4928 | else if (isymp->st_shndx == SHN_ABS) |
4929 | isec = bfd_abs_section_ptr; | |
4930 | else if (isymp->st_shndx == SHN_COMMON) | |
4931 | isec = bfd_com_section_ptr; | |
4932 | else | |
9ad5cbcf | 4933 | isec = bfd_section_from_elf_index (input_bfd, isymp->st_shndx); |
252b5132 RH |
4934 | |
4935 | *secpp = isec; | |
4936 | } | |
4937 | ||
4938 | if (! sh_elf_relocate_section (output_bfd, link_info, input_bfd, | |
4939 | input_section, data, internal_relocs, | |
4940 | internal_syms, sections)) | |
4941 | goto error_return; | |
4942 | ||
4943 | if (sections != NULL) | |
4944 | free (sections); | |
252b5132 RH |
4945 | if (internal_syms != NULL) |
4946 | free (internal_syms); | |
9ad5cbcf AM |
4947 | if (shndx_buf != NULL) |
4948 | free (shndx_buf); | |
252b5132 RH |
4949 | if (external_syms != NULL && symtab_hdr->contents == NULL) |
4950 | free (external_syms); | |
252b5132 RH |
4951 | if (internal_relocs != elf_section_data (input_section)->relocs) |
4952 | free (internal_relocs); | |
252b5132 RH |
4953 | } |
4954 | ||
4955 | return data; | |
4956 | ||
4957 | error_return: | |
4958 | if (internal_relocs != NULL | |
4959 | && internal_relocs != elf_section_data (input_section)->relocs) | |
4960 | free (internal_relocs); | |
9ad5cbcf AM |
4961 | if (shndx_buf != NULL) |
4962 | free (shndx_buf); | |
252b5132 RH |
4963 | if (external_syms != NULL && symtab_hdr->contents == NULL) |
4964 | free (external_syms); | |
4965 | if (internal_syms != NULL) | |
4966 | free (internal_syms); | |
4967 | if (sections != NULL) | |
4968 | free (sections); | |
4969 | return NULL; | |
4970 | } | |
917583ad | 4971 | |
252b5132 RH |
4972 | static asection * |
4973 | sh_elf_gc_mark_hook (abfd, info, rel, h, sym) | |
435b1e90 KH |
4974 | bfd *abfd; |
4975 | struct bfd_link_info *info ATTRIBUTE_UNUSED; | |
4976 | Elf_Internal_Rela *rel; | |
4977 | struct elf_link_hash_entry *h; | |
4978 | Elf_Internal_Sym *sym; | |
252b5132 RH |
4979 | { |
4980 | if (h != NULL) | |
4981 | { | |
4982 | switch (ELF32_R_TYPE (rel->r_info)) | |
435b1e90 KH |
4983 | { |
4984 | case R_SH_GNU_VTINHERIT: | |
4985 | case R_SH_GNU_VTENTRY: | |
4986 | break; | |
252b5132 | 4987 | |
435b1e90 KH |
4988 | default: |
4989 | switch (h->root.type) | |
4990 | { | |
4991 | case bfd_link_hash_defined: | |
4992 | case bfd_link_hash_defweak: | |
4993 | return h->root.u.def.section; | |
252b5132 | 4994 | |
435b1e90 KH |
4995 | case bfd_link_hash_common: |
4996 | return h->root.u.c.p->section; | |
e049a0de | 4997 | |
435b1e90 KH |
4998 | default: |
4999 | break; | |
5000 | } | |
5001 | } | |
5002 | } | |
5003 | else | |
5004 | { | |
9ad5cbcf | 5005 | return bfd_section_from_elf_index (abfd, sym->st_shndx); |
435b1e90 | 5006 | } |
9ad5cbcf | 5007 | |
252b5132 RH |
5008 | return NULL; |
5009 | } | |
5010 | ||
37c644f2 AO |
5011 | /* Update the got entry reference counts for the section being removed. */ |
5012 | ||
252b5132 RH |
5013 | static boolean |
5014 | sh_elf_gc_sweep_hook (abfd, info, sec, relocs) | |
5f771d47 ILT |
5015 | bfd *abfd ATTRIBUTE_UNUSED; |
5016 | struct bfd_link_info *info ATTRIBUTE_UNUSED; | |
5017 | asection *sec ATTRIBUTE_UNUSED; | |
5018 | const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED; | |
252b5132 | 5019 | { |
37c644f2 AO |
5020 | /* We use got and plt entries for sh, but it would seem that the |
5021 | existing SH code does no sort of reference counting or whatnot on | |
5022 | its GOT and PLT entries, so it is not possible to garbage collect | |
435b1e90 | 5023 | them at this time. */ |
252b5132 RH |
5024 | return true; |
5025 | } | |
5026 | ||
5027 | /* Look through the relocs for a section during the first phase. | |
5028 | Since we don't do .gots or .plts, we just need to consider the | |
5029 | virtual table relocs for gc. */ | |
435b1e90 | 5030 | |
252b5132 RH |
5031 | static boolean |
5032 | sh_elf_check_relocs (abfd, info, sec, relocs) | |
5033 | bfd *abfd; | |
5034 | struct bfd_link_info *info; | |
5035 | asection *sec; | |
5036 | const Elf_Internal_Rela *relocs; | |
5037 | { | |
5038 | Elf_Internal_Shdr *symtab_hdr; | |
5039 | struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; | |
5040 | const Elf_Internal_Rela *rel; | |
5041 | const Elf_Internal_Rela *rel_end; | |
37c644f2 AO |
5042 | bfd *dynobj; |
5043 | bfd_vma *local_got_offsets; | |
5044 | asection *sgot; | |
5045 | asection *srelgot; | |
5046 | asection *sreloc; | |
435b1e90 | 5047 | |
37c644f2 AO |
5048 | sgot = NULL; |
5049 | srelgot = NULL; | |
5050 | sreloc = NULL; | |
5051 | ||
252b5132 RH |
5052 | if (info->relocateable) |
5053 | return true; | |
435b1e90 | 5054 | |
252b5132 RH |
5055 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
5056 | sym_hashes = elf_sym_hashes (abfd); | |
435b1e90 | 5057 | sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof (Elf32_External_Sym); |
252b5132 RH |
5058 | if (!elf_bad_symtab (abfd)) |
5059 | sym_hashes_end -= symtab_hdr->sh_info; | |
435b1e90 | 5060 | |
37c644f2 AO |
5061 | dynobj = elf_hash_table (info)->dynobj; |
5062 | local_got_offsets = elf_local_got_offsets (abfd); | |
5063 | ||
252b5132 RH |
5064 | rel_end = relocs + sec->reloc_count; |
5065 | for (rel = relocs; rel < rel_end; rel++) | |
5066 | { | |
5067 | struct elf_link_hash_entry *h; | |
5068 | unsigned long r_symndx; | |
435b1e90 | 5069 | |
252b5132 RH |
5070 | r_symndx = ELF32_R_SYM (rel->r_info); |
5071 | if (r_symndx < symtab_hdr->sh_info) | |
435b1e90 | 5072 | h = NULL; |
252b5132 | 5073 | else |
435b1e90 KH |
5074 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
5075 | ||
37c644f2 AO |
5076 | /* Some relocs require a global offset table. */ |
5077 | if (dynobj == NULL) | |
5078 | { | |
5079 | switch (ELF32_R_TYPE (rel->r_info)) | |
5080 | { | |
fbca6ad9 | 5081 | case R_SH_GOTPLT32: |
37c644f2 AO |
5082 | case R_SH_GOT32: |
5083 | case R_SH_GOTOFF: | |
5084 | case R_SH_GOTPC: | |
fbca6ad9 AO |
5085 | #ifdef INCLUDE_SHMEDIA |
5086 | case R_SH_GOTPLT_LOW16: | |
5087 | case R_SH_GOTPLT_MEDLOW16: | |
5088 | case R_SH_GOTPLT_MEDHI16: | |
5089 | case R_SH_GOTPLT_HI16: | |
5090 | case R_SH_GOTPLT10BY4: | |
5091 | case R_SH_GOTPLT10BY8: | |
5092 | case R_SH_GOT_LOW16: | |
5093 | case R_SH_GOT_MEDLOW16: | |
5094 | case R_SH_GOT_MEDHI16: | |
5095 | case R_SH_GOT_HI16: | |
5096 | case R_SH_GOT10BY4: | |
5097 | case R_SH_GOT10BY8: | |
5098 | case R_SH_GOTOFF_LOW16: | |
5099 | case R_SH_GOTOFF_MEDLOW16: | |
5100 | case R_SH_GOTOFF_MEDHI16: | |
5101 | case R_SH_GOTOFF_HI16: | |
5102 | case R_SH_GOTPC_LOW16: | |
5103 | case R_SH_GOTPC_MEDLOW16: | |
5104 | case R_SH_GOTPC_MEDHI16: | |
5105 | case R_SH_GOTPC_HI16: | |
5106 | #endif | |
37c644f2 AO |
5107 | elf_hash_table (info)->dynobj = dynobj = abfd; |
5108 | if (! _bfd_elf_create_got_section (dynobj, info)) | |
5109 | return false; | |
5110 | break; | |
5111 | ||
5112 | default: | |
5113 | break; | |
5114 | } | |
5115 | } | |
5116 | ||
252b5132 RH |
5117 | switch (ELF32_R_TYPE (rel->r_info)) |
5118 | { | |
5119 | /* This relocation describes the C++ object vtable hierarchy. | |
5120 | Reconstruct it for later use during GC. */ | |
435b1e90 KH |
5121 | case R_SH_GNU_VTINHERIT: |
5122 | if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) | |
5123 | return false; | |
5124 | break; | |
5125 | ||
252b5132 RH |
5126 | /* This relocation describes which C++ vtable entries are actually |
5127 | used. Record for later use during GC. */ | |
435b1e90 KH |
5128 | case R_SH_GNU_VTENTRY: |
5129 | if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend)) | |
5130 | return false; | |
5131 | break; | |
37c644f2 | 5132 | |
fbca6ad9 | 5133 | force_got: |
37c644f2 | 5134 | case R_SH_GOT32: |
fbca6ad9 AO |
5135 | #ifdef INCLUDE_SHMEDIA |
5136 | case R_SH_GOT_LOW16: | |
5137 | case R_SH_GOT_MEDLOW16: | |
5138 | case R_SH_GOT_MEDHI16: | |
5139 | case R_SH_GOT_HI16: | |
5140 | case R_SH_GOT10BY4: | |
5141 | case R_SH_GOT10BY8: | |
5142 | #endif | |
37c644f2 AO |
5143 | /* This symbol requires a global offset table entry. */ |
5144 | ||
5145 | if (sgot == NULL) | |
5146 | { | |
5147 | sgot = bfd_get_section_by_name (dynobj, ".got"); | |
5148 | BFD_ASSERT (sgot != NULL); | |
5149 | } | |
5150 | ||
5151 | if (srelgot == NULL | |
5152 | && (h != NULL || info->shared)) | |
5153 | { | |
5154 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); | |
5155 | if (srelgot == NULL) | |
5156 | { | |
5157 | srelgot = bfd_make_section (dynobj, ".rela.got"); | |
5158 | if (srelgot == NULL | |
5159 | || ! bfd_set_section_flags (dynobj, srelgot, | |
5160 | (SEC_ALLOC | |
5161 | | SEC_LOAD | |
5162 | | SEC_HAS_CONTENTS | |
5163 | | SEC_IN_MEMORY | |
5164 | | SEC_LINKER_CREATED | |
5165 | | SEC_READONLY)) | |
5166 | || ! bfd_set_section_alignment (dynobj, srelgot, 2)) | |
5167 | return false; | |
5168 | } | |
5169 | } | |
5170 | ||
5171 | if (h != NULL) | |
5172 | { | |
fbca6ad9 AO |
5173 | #ifdef INCLUDE_SHMEDIA |
5174 | if (h->type == STT_DATALABEL) | |
5175 | { | |
5176 | struct elf_sh_link_hash_entry *hsh; | |
5177 | ||
5178 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5179 | hsh = (struct elf_sh_link_hash_entry *)h; | |
5180 | if (hsh->datalabel_got_offset != (bfd_vma) -1) | |
5181 | break; | |
5182 | ||
5183 | hsh->datalabel_got_offset = sgot->_raw_size; | |
5184 | } | |
5185 | else | |
5186 | { | |
5187 | #endif | |
37c644f2 AO |
5188 | if (h->got.offset != (bfd_vma) -1) |
5189 | { | |
5190 | /* We have already allocated space in the .got. */ | |
5191 | break; | |
5192 | } | |
5193 | h->got.offset = sgot->_raw_size; | |
fbca6ad9 AO |
5194 | #ifdef INCLUDE_SHMEDIA |
5195 | } | |
5196 | #endif | |
37c644f2 AO |
5197 | |
5198 | /* Make sure this symbol is output as a dynamic symbol. */ | |
5199 | if (h->dynindx == -1) | |
5200 | { | |
5201 | if (! bfd_elf32_link_record_dynamic_symbol (info, h)) | |
5202 | return false; | |
5203 | } | |
5204 | ||
5205 | srelgot->_raw_size += sizeof (Elf32_External_Rela); | |
5206 | } | |
5207 | else | |
5208 | { | |
435b1e90 KH |
5209 | /* This is a global offset table entry for a local |
5210 | symbol. */ | |
37c644f2 AO |
5211 | if (local_got_offsets == NULL) |
5212 | { | |
dc810e39 | 5213 | bfd_size_type size; |
37c644f2 AO |
5214 | register unsigned int i; |
5215 | ||
dc810e39 AM |
5216 | size = symtab_hdr->sh_info; |
5217 | size *= sizeof (bfd_vma); | |
fbca6ad9 AO |
5218 | #ifdef INCLUDE_SHMEDIA |
5219 | /* Reserve space for both the datalabel and | |
5220 | codelabel local GOT offsets. */ | |
5221 | size *= 2; | |
5222 | #endif | |
37c644f2 AO |
5223 | local_got_offsets = (bfd_vma *) bfd_alloc (abfd, size); |
5224 | if (local_got_offsets == NULL) | |
5225 | return false; | |
5226 | elf_local_got_offsets (abfd) = local_got_offsets; | |
5227 | for (i = 0; i < symtab_hdr->sh_info; i++) | |
5228 | local_got_offsets[i] = (bfd_vma) -1; | |
fbca6ad9 AO |
5229 | #ifdef INCLUDE_SHMEDIA |
5230 | for (; i < 2 * symtab_hdr->sh_info; i++) | |
5231 | local_got_offsets[i] = (bfd_vma) -1; | |
5232 | #endif | |
37c644f2 | 5233 | } |
fbca6ad9 AO |
5234 | #ifdef INCLUDE_SHMEDIA |
5235 | if ((rel->r_addend & 1) != 0) | |
5236 | { | |
5237 | if (local_got_offsets[symtab_hdr->sh_info | |
5238 | + r_symndx] != (bfd_vma) -1) | |
5239 | { | |
5240 | /* We have already allocated space in the .got. */ | |
5241 | break; | |
5242 | } | |
5243 | local_got_offsets[symtab_hdr->sh_info | |
5244 | + r_symndx] = sgot->_raw_size; | |
5245 | } | |
5246 | else | |
5247 | { | |
5248 | #endif | |
37c644f2 AO |
5249 | if (local_got_offsets[r_symndx] != (bfd_vma) -1) |
5250 | { | |
5251 | /* We have already allocated space in the .got. */ | |
5252 | break; | |
5253 | } | |
5254 | local_got_offsets[r_symndx] = sgot->_raw_size; | |
fbca6ad9 AO |
5255 | #ifdef INCLUDE_SHMEDIA |
5256 | } | |
5257 | #endif | |
37c644f2 AO |
5258 | |
5259 | if (info->shared) | |
5260 | { | |
5261 | /* If we are generating a shared object, we need to | |
5262 | output a R_SH_RELATIVE reloc so that the dynamic | |
5263 | linker can adjust this GOT entry. */ | |
5264 | srelgot->_raw_size += sizeof (Elf32_External_Rela); | |
5265 | } | |
5266 | } | |
5267 | ||
5268 | sgot->_raw_size += 4; | |
5269 | ||
5270 | break; | |
5271 | ||
fbca6ad9 AO |
5272 | case R_SH_GOTPLT32: |
5273 | #ifdef INCLUDE_SHMEDIA | |
5274 | case R_SH_GOTPLT_LOW16: | |
5275 | case R_SH_GOTPLT_MEDLOW16: | |
5276 | case R_SH_GOTPLT_MEDHI16: | |
5277 | case R_SH_GOTPLT_HI16: | |
5278 | case R_SH_GOTPLT10BY4: | |
5279 | case R_SH_GOTPLT10BY8: | |
5280 | #endif | |
5281 | /* If this is a local symbol, we resolve it directly without | |
5282 | creating a procedure linkage table entry. */ | |
5283 | ||
5284 | if (h == NULL | |
5285 | || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL | |
5286 | || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN | |
5287 | || ! info->shared | |
5288 | || info->symbolic | |
5289 | || h->dynindx == -1 | |
5290 | || h->got.offset != (bfd_vma) -1) | |
5291 | goto force_got; | |
5292 | ||
5293 | /* Make sure this symbol is output as a dynamic symbol. */ | |
5294 | if (h->dynindx == -1) | |
5295 | { | |
5296 | if (! bfd_elf32_link_record_dynamic_symbol (info, h)) | |
5297 | return false; | |
5298 | } | |
5299 | ||
5300 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; | |
5301 | ||
5302 | break; | |
5303 | ||
37c644f2 | 5304 | case R_SH_PLT32: |
fbca6ad9 AO |
5305 | #ifdef INCLUDE_SHMEDIA |
5306 | case R_SH_PLT_LOW16: | |
5307 | case R_SH_PLT_MEDLOW16: | |
5308 | case R_SH_PLT_MEDHI16: | |
5309 | case R_SH_PLT_HI16: | |
5310 | #endif | |
37c644f2 AO |
5311 | /* This symbol requires a procedure linkage table entry. We |
5312 | actually build the entry in adjust_dynamic_symbol, | |
5313 | because this might be a case of linking PIC code which is | |
5314 | never referenced by a dynamic object, in which case we | |
5315 | don't need to generate a procedure linkage table entry | |
5316 | after all. */ | |
5317 | ||
5318 | /* If this is a local symbol, we resolve it directly without | |
5319 | creating a procedure linkage table entry. */ | |
5320 | if (h == NULL) | |
5321 | continue; | |
5322 | ||
5323 | if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL | |
5324 | || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN) | |
5325 | break; | |
5326 | ||
5327 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; | |
5328 | ||
5329 | break; | |
5330 | ||
5331 | case R_SH_DIR32: | |
5332 | case R_SH_REL32: | |
5333 | if (h != NULL) | |
5334 | h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF; | |
5335 | ||
5336 | /* If we are creating a shared library, and this is a reloc | |
5337 | against a global symbol, or a non PC relative reloc | |
5338 | against a local symbol, then we need to copy the reloc | |
5339 | into the shared library. However, if we are linking with | |
5340 | -Bsymbolic, we do not need to copy a reloc against a | |
5341 | global symbol which is defined in an object we are | |
5342 | including in the link (i.e., DEF_REGULAR is set). At | |
5343 | this point we have not seen all the input files, so it is | |
5344 | possible that DEF_REGULAR is not set now but will be set | |
5345 | later (it is never cleared). We account for that | |
5346 | possibility below by storing information in the | |
5347 | pcrel_relocs_copied field of the hash table entry. */ | |
5348 | if (info->shared | |
5349 | && (sec->flags & SEC_ALLOC) != 0 | |
5350 | && (ELF32_R_TYPE (rel->r_info) != R_SH_REL32 | |
5351 | || (h != NULL | |
5352 | && (! info->symbolic | |
5353 | || (h->elf_link_hash_flags | |
5354 | & ELF_LINK_HASH_DEF_REGULAR) == 0)))) | |
5355 | { | |
5356 | /* When creating a shared object, we must copy these | |
5357 | reloc types into the output file. We create a reloc | |
5358 | section in dynobj and make room for this reloc. */ | |
5359 | if (sreloc == NULL) | |
5360 | { | |
5361 | const char *name; | |
5362 | ||
5363 | name = (bfd_elf_string_from_elf_section | |
5364 | (abfd, | |
5365 | elf_elfheader (abfd)->e_shstrndx, | |
5366 | elf_section_data (sec)->rel_hdr.sh_name)); | |
5367 | if (name == NULL) | |
5368 | return false; | |
5369 | ||
5370 | BFD_ASSERT (strncmp (name, ".rela", 5) == 0 | |
5371 | && strcmp (bfd_get_section_name (abfd, sec), | |
5372 | name + 5) == 0); | |
5373 | ||
5374 | sreloc = bfd_get_section_by_name (dynobj, name); | |
5375 | if (sreloc == NULL) | |
5376 | { | |
5377 | flagword flags; | |
5378 | ||
5379 | sreloc = bfd_make_section (dynobj, name); | |
5380 | flags = (SEC_HAS_CONTENTS | SEC_READONLY | |
5381 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
5382 | if ((sec->flags & SEC_ALLOC) != 0) | |
5383 | flags |= SEC_ALLOC | SEC_LOAD; | |
5384 | if (sreloc == NULL | |
5385 | || ! bfd_set_section_flags (dynobj, sreloc, flags) | |
5386 | || ! bfd_set_section_alignment (dynobj, sreloc, 2)) | |
5387 | return false; | |
5388 | } | |
99e4ae17 AJ |
5389 | if (sec->flags & SEC_READONLY) |
5390 | info->flags |= DF_TEXTREL; | |
37c644f2 AO |
5391 | } |
5392 | ||
5393 | sreloc->_raw_size += sizeof (Elf32_External_Rela); | |
5394 | ||
5395 | /* If we are linking with -Bsymbolic, and this is a | |
5396 | global symbol, we count the number of PC relative | |
5397 | relocations we have entered for this symbol, so that | |
5398 | we can discard them again if the symbol is later | |
5399 | defined by a regular object. Note that this function | |
5400 | is only called if we are using an elf_sh linker | |
5401 | hash table, which means that h is really a pointer to | |
5402 | an elf_sh_link_hash_entry. */ | |
5403 | if (h != NULL && info->symbolic | |
5404 | && ELF32_R_TYPE (rel->r_info) == R_SH_REL32) | |
5405 | { | |
5406 | struct elf_sh_link_hash_entry *eh; | |
5407 | struct elf_sh_pcrel_relocs_copied *p; | |
5408 | ||
5409 | eh = (struct elf_sh_link_hash_entry *) h; | |
5410 | ||
5411 | for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next) | |
5412 | if (p->section == sreloc) | |
5413 | break; | |
5414 | ||
5415 | if (p == NULL) | |
5416 | { | |
5417 | p = ((struct elf_sh_pcrel_relocs_copied *) | |
dc810e39 | 5418 | bfd_alloc (dynobj, (bfd_size_type) sizeof *p)); |
37c644f2 AO |
5419 | if (p == NULL) |
5420 | return false; | |
5421 | p->next = eh->pcrel_relocs_copied; | |
5422 | eh->pcrel_relocs_copied = p; | |
5423 | p->section = sreloc; | |
5424 | p->count = 0; | |
5425 | } | |
5426 | ||
5427 | ++p->count; | |
5428 | } | |
5429 | } | |
5430 | ||
5431 | break; | |
435b1e90 | 5432 | } |
252b5132 | 5433 | } |
435b1e90 | 5434 | |
252b5132 RH |
5435 | return true; |
5436 | } | |
5437 | ||
fbca6ad9 | 5438 | #ifndef sh_elf_set_mach_from_flags |
1630fd2b | 5439 | static boolean |
d4845d57 | 5440 | sh_elf_set_mach_from_flags (abfd) |
435b1e90 | 5441 | bfd *abfd; |
d4845d57 JR |
5442 | { |
5443 | flagword flags = elf_elfheader (abfd)->e_flags; | |
5444 | ||
86033394 | 5445 | switch (flags & EF_SH_MACH_MASK) |
d4845d57 JR |
5446 | { |
5447 | case EF_SH1: | |
5448 | bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh); | |
5449 | break; | |
5450 | case EF_SH2: | |
5451 | bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh2); | |
5452 | break; | |
5453 | case EF_SH_DSP: | |
5454 | bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh_dsp); | |
5455 | break; | |
5456 | case EF_SH3: | |
5457 | bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh3); | |
5458 | break; | |
5459 | case EF_SH3_DSP: | |
5460 | bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh3_dsp); | |
5461 | break; | |
5462 | case EF_SH3E: | |
5463 | bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh3e); | |
5464 | break; | |
5465 | case EF_SH_UNKNOWN: | |
5466 | case EF_SH4: | |
5467 | bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh4); | |
5468 | break; | |
5469 | default: | |
5470 | return false; | |
5471 | } | |
5472 | return true; | |
5473 | } | |
fbca6ad9 | 5474 | #endif /* not sh_elf_set_mach_from_flags */ |
d4845d57 | 5475 | |
fbca6ad9 | 5476 | #ifndef sh_elf_set_private_flags |
435b1e90 KH |
5477 | /* Function to keep SH specific file flags. */ |
5478 | ||
d4845d57 JR |
5479 | static boolean |
5480 | sh_elf_set_private_flags (abfd, flags) | |
435b1e90 | 5481 | bfd *abfd; |
d4845d57 JR |
5482 | flagword flags; |
5483 | { | |
5484 | BFD_ASSERT (! elf_flags_init (abfd) | |
5485 | || elf_elfheader (abfd)->e_flags == flags); | |
5486 | ||
5487 | elf_elfheader (abfd)->e_flags = flags; | |
5488 | elf_flags_init (abfd) = true; | |
5489 | return sh_elf_set_mach_from_flags (abfd); | |
5490 | } | |
fbca6ad9 | 5491 | #endif /* not sh_elf_set_private_flags */ |
d4845d57 | 5492 | |
fbca6ad9 | 5493 | #ifndef sh_elf_copy_private_data |
d4845d57 | 5494 | /* Copy backend specific data from one object module to another */ |
435b1e90 | 5495 | |
d4845d57 JR |
5496 | static boolean |
5497 | sh_elf_copy_private_data (ibfd, obfd) | |
38b1a46c NC |
5498 | bfd * ibfd; |
5499 | bfd * obfd; | |
d4845d57 | 5500 | { |
38b1a46c | 5501 | if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
d4845d57 JR |
5502 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) |
5503 | return true; | |
5504 | ||
5505 | return sh_elf_set_private_flags (obfd, elf_elfheader (ibfd)->e_flags); | |
5506 | } | |
fbca6ad9 | 5507 | #endif /* not sh_elf_copy_private_data */ |
d4845d57 | 5508 | |
fbca6ad9 | 5509 | #ifndef sh_elf_merge_private_data |
d4845d57 JR |
5510 | /* This routine checks for linking big and little endian objects |
5511 | together, and for linking sh-dsp with sh3e / sh4 objects. */ | |
5512 | ||
5513 | static boolean | |
5514 | sh_elf_merge_private_data (ibfd, obfd) | |
5515 | bfd *ibfd; | |
5516 | bfd *obfd; | |
5517 | { | |
5518 | flagword old_flags, new_flags; | |
5519 | ||
5520 | if (_bfd_generic_verify_endian_match (ibfd, obfd) == false) | |
5521 | return false; | |
5522 | ||
5523 | if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour | |
5524 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) | |
5525 | return true; | |
5526 | ||
5527 | if (! elf_flags_init (obfd)) | |
5528 | { | |
a39b79b9 | 5529 | /* This happens when ld starts out with a 'blank' output file. */ |
d4845d57 | 5530 | elf_flags_init (obfd) = true; |
a39b79b9 | 5531 | elf_elfheader (obfd)->e_flags = EF_SH1; |
d4845d57 JR |
5532 | } |
5533 | old_flags = elf_elfheader (obfd)->e_flags; | |
5534 | new_flags = elf_elfheader (ibfd)->e_flags; | |
5535 | if ((EF_SH_HAS_DSP (old_flags) && EF_SH_HAS_FP (new_flags)) | |
5536 | || (EF_SH_HAS_DSP (new_flags) && EF_SH_HAS_FP (old_flags))) | |
5537 | { | |
5538 | (*_bfd_error_handler) | |
5539 | ("%s: uses %s instructions while previous modules use %s instructions", | |
8f615d07 | 5540 | bfd_archive_filename (ibfd), |
d4845d57 JR |
5541 | EF_SH_HAS_DSP (new_flags) ? "dsp" : "floating point", |
5542 | EF_SH_HAS_DSP (new_flags) ? "floating point" : "dsp"); | |
5543 | bfd_set_error (bfd_error_bad_value); | |
5544 | return false; | |
5545 | } | |
5546 | elf_elfheader (obfd)->e_flags = EF_SH_MERGE_MACH (old_flags, new_flags); | |
5547 | ||
5548 | return sh_elf_set_mach_from_flags (obfd); | |
5549 | } | |
fbca6ad9 | 5550 | #endif /* not sh_elf_merge_private_data */ |
d4845d57 | 5551 | |
37c644f2 AO |
5552 | /* Finish up dynamic symbol handling. We set the contents of various |
5553 | dynamic sections here. */ | |
5554 | ||
5555 | static boolean | |
5556 | sh_elf_finish_dynamic_symbol (output_bfd, info, h, sym) | |
5557 | bfd *output_bfd; | |
5558 | struct bfd_link_info *info; | |
5559 | struct elf_link_hash_entry *h; | |
5560 | Elf_Internal_Sym *sym; | |
5561 | { | |
5562 | bfd *dynobj; | |
5563 | ||
5564 | dynobj = elf_hash_table (info)->dynobj; | |
5565 | ||
5566 | if (h->plt.offset != (bfd_vma) -1) | |
5567 | { | |
5568 | asection *splt; | |
5569 | asection *sgot; | |
5570 | asection *srel; | |
5571 | ||
5572 | bfd_vma plt_index; | |
5573 | bfd_vma got_offset; | |
5574 | Elf_Internal_Rela rel; | |
5575 | ||
5576 | /* This symbol has an entry in the procedure linkage table. Set | |
5577 | it up. */ | |
5578 | ||
5579 | BFD_ASSERT (h->dynindx != -1); | |
5580 | ||
5581 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
5582 | sgot = bfd_get_section_by_name (dynobj, ".got.plt"); | |
5583 | srel = bfd_get_section_by_name (dynobj, ".rela.plt"); | |
5584 | BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL); | |
5585 | ||
5586 | /* Get the index in the procedure linkage table which | |
5587 | corresponds to this symbol. This is the index of this symbol | |
5588 | in all the symbols for which we are making plt entries. The | |
5589 | first entry in the procedure linkage table is reserved. */ | |
5590 | plt_index = h->plt.offset / elf_sh_sizeof_plt (info) - 1; | |
5591 | ||
5592 | /* Get the offset into the .got table of the entry that | |
5593 | corresponds to this function. Each .got entry is 4 bytes. | |
5594 | The first three are reserved. */ | |
5595 | got_offset = (plt_index + 3) * 4; | |
5596 | ||
fbca6ad9 AO |
5597 | #ifdef GOT_BIAS |
5598 | got_offset -= GOT_BIAS; | |
5599 | #endif | |
5600 | ||
37c644f2 AO |
5601 | /* Fill in the entry in the procedure linkage table. */ |
5602 | if (! info->shared) | |
5603 | { | |
5604 | if (elf_sh_plt_entry == NULL) | |
5605 | { | |
435b1e90 | 5606 | elf_sh_plt_entry = (bfd_big_endian (output_bfd) ? |
37c644f2 AO |
5607 | elf_sh_plt_entry_be : elf_sh_plt_entry_le); |
5608 | } | |
5609 | memcpy (splt->contents + h->plt.offset, elf_sh_plt_entry, | |
5610 | elf_sh_sizeof_plt (info)); | |
fbca6ad9 AO |
5611 | #ifdef INCLUDE_SHMEDIA |
5612 | movi_shori_putval (output_bfd, | |
5613 | (sgot->output_section->vma | |
5614 | + sgot->output_offset | |
5615 | + got_offset), | |
5616 | (splt->contents + h->plt.offset | |
5617 | + elf_sh_plt_symbol_offset (info))); | |
5618 | ||
5619 | movi_shori_putval (output_bfd, | |
5620 | (splt->output_section->vma + splt->output_offset), | |
5621 | (splt->contents + h->plt.offset | |
5622 | + elf_sh_plt_plt0_offset (info))); | |
5623 | #else | |
37c644f2 AO |
5624 | bfd_put_32 (output_bfd, |
5625 | (sgot->output_section->vma | |
5626 | + sgot->output_offset | |
5627 | + got_offset), | |
5628 | (splt->contents + h->plt.offset | |
5629 | + elf_sh_plt_symbol_offset (info))); | |
5630 | ||
5631 | bfd_put_32 (output_bfd, | |
5632 | (splt->output_section->vma + splt->output_offset), | |
5633 | (splt->contents + h->plt.offset | |
5634 | + elf_sh_plt_plt0_offset (info))); | |
fbca6ad9 | 5635 | #endif |
37c644f2 AO |
5636 | } |
5637 | else | |
5638 | { | |
5639 | if (elf_sh_pic_plt_entry == NULL) | |
5640 | { | |
435b1e90 | 5641 | elf_sh_pic_plt_entry = (bfd_big_endian (output_bfd) ? |
37c644f2 AO |
5642 | elf_sh_pic_plt_entry_be : |
5643 | elf_sh_pic_plt_entry_le); | |
5644 | } | |
5645 | memcpy (splt->contents + h->plt.offset, elf_sh_pic_plt_entry, | |
5646 | elf_sh_sizeof_plt (info)); | |
fbca6ad9 AO |
5647 | #ifdef INCLUDE_SHMEDIA |
5648 | movi_shori_putval (output_bfd, got_offset, | |
5649 | (splt->contents + h->plt.offset | |
5650 | + elf_sh_plt_symbol_offset (info))); | |
5651 | #else | |
37c644f2 AO |
5652 | bfd_put_32 (output_bfd, got_offset, |
5653 | (splt->contents + h->plt.offset | |
5654 | + elf_sh_plt_symbol_offset (info))); | |
fbca6ad9 | 5655 | #endif |
37c644f2 AO |
5656 | } |
5657 | ||
fbca6ad9 AO |
5658 | #ifdef GOT_BIAS |
5659 | got_offset += GOT_BIAS; | |
5660 | #endif | |
5661 | ||
5662 | #ifdef INCLUDE_SHMEDIA | |
5663 | movi_shori_putval (output_bfd, | |
5664 | plt_index * sizeof (Elf32_External_Rela), | |
5665 | (splt->contents + h->plt.offset | |
5666 | + elf_sh_plt_reloc_offset (info))); | |
5667 | #else | |
37c644f2 AO |
5668 | bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela), |
5669 | (splt->contents + h->plt.offset | |
5670 | + elf_sh_plt_reloc_offset (info))); | |
fbca6ad9 | 5671 | #endif |
37c644f2 AO |
5672 | |
5673 | /* Fill in the entry in the global offset table. */ | |
5674 | bfd_put_32 (output_bfd, | |
5675 | (splt->output_section->vma | |
5676 | + splt->output_offset | |
5677 | + h->plt.offset | |
5678 | + elf_sh_plt_temp_offset (info)), | |
5679 | sgot->contents + got_offset); | |
5680 | ||
5681 | /* Fill in the entry in the .rela.plt section. */ | |
5682 | rel.r_offset = (sgot->output_section->vma | |
5683 | + sgot->output_offset | |
5684 | + got_offset); | |
5685 | rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_JMP_SLOT); | |
5686 | rel.r_addend = 0; | |
fbca6ad9 AO |
5687 | #ifdef GOT_BIAS |
5688 | rel.r_addend = GOT_BIAS; | |
5689 | #endif | |
37c644f2 AO |
5690 | bfd_elf32_swap_reloca_out (output_bfd, &rel, |
5691 | ((Elf32_External_Rela *) srel->contents | |
5692 | + plt_index)); | |
5693 | ||
5694 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
5695 | { | |
5696 | /* Mark the symbol as undefined, rather than as defined in | |
5697 | the .plt section. Leave the value alone. */ | |
5698 | sym->st_shndx = SHN_UNDEF; | |
5699 | } | |
5700 | } | |
5701 | ||
5702 | if (h->got.offset != (bfd_vma) -1) | |
5703 | { | |
5704 | asection *sgot; | |
5705 | asection *srel; | |
5706 | Elf_Internal_Rela rel; | |
5707 | ||
5708 | /* This symbol has an entry in the global offset table. Set it | |
5709 | up. */ | |
5710 | ||
5711 | sgot = bfd_get_section_by_name (dynobj, ".got"); | |
5712 | srel = bfd_get_section_by_name (dynobj, ".rela.got"); | |
5713 | BFD_ASSERT (sgot != NULL && srel != NULL); | |
5714 | ||
5715 | rel.r_offset = (sgot->output_section->vma | |
5716 | + sgot->output_offset | |
dc810e39 | 5717 | + (h->got.offset &~ (bfd_vma) 1)); |
37c644f2 AO |
5718 | |
5719 | /* If this is a -Bsymbolic link, and the symbol is defined | |
5720 | locally, we just want to emit a RELATIVE reloc. Likewise if | |
5721 | the symbol was forced to be local because of a version file. | |
5722 | The entry in the global offset table will already have been | |
5723 | initialized in the relocate_section function. */ | |
5724 | if (info->shared | |
5725 | && (info->symbolic || h->dynindx == -1) | |
5726 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)) | |
5727 | { | |
5728 | rel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE); | |
5729 | rel.r_addend = (h->root.u.def.value | |
5730 | + h->root.u.def.section->output_section->vma | |
5731 | + h->root.u.def.section->output_offset); | |
5732 | } | |
5733 | else | |
5734 | { | |
5735 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset); | |
5736 | rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_GLOB_DAT); | |
5737 | rel.r_addend = 0; | |
5738 | } | |
5739 | ||
5740 | bfd_elf32_swap_reloca_out (output_bfd, &rel, | |
435b1e90 KH |
5741 | ((Elf32_External_Rela *) srel->contents |
5742 | + srel->reloc_count)); | |
37c644f2 AO |
5743 | ++srel->reloc_count; |
5744 | } | |
5745 | ||
5746 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0) | |
5747 | { | |
5748 | asection *s; | |
5749 | Elf_Internal_Rela rel; | |
5750 | ||
5751 | /* This symbol needs a copy reloc. Set it up. */ | |
5752 | ||
5753 | BFD_ASSERT (h->dynindx != -1 | |
5754 | && (h->root.type == bfd_link_hash_defined | |
5755 | || h->root.type == bfd_link_hash_defweak)); | |
5756 | ||
5757 | s = bfd_get_section_by_name (h->root.u.def.section->owner, | |
5758 | ".rela.bss"); | |
5759 | BFD_ASSERT (s != NULL); | |
5760 | ||
5761 | rel.r_offset = (h->root.u.def.value | |
5762 | + h->root.u.def.section->output_section->vma | |
5763 | + h->root.u.def.section->output_offset); | |
5764 | rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_COPY); | |
5765 | rel.r_addend = 0; | |
5766 | bfd_elf32_swap_reloca_out (output_bfd, &rel, | |
435b1e90 KH |
5767 | ((Elf32_External_Rela *) s->contents |
5768 | + s->reloc_count)); | |
37c644f2 AO |
5769 | ++s->reloc_count; |
5770 | } | |
5771 | ||
5772 | /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */ | |
5773 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0 | |
5774 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) | |
5775 | sym->st_shndx = SHN_ABS; | |
5776 | ||
5777 | return true; | |
5778 | } | |
5779 | ||
5780 | /* Finish up the dynamic sections. */ | |
5781 | ||
5782 | static boolean | |
5783 | sh_elf_finish_dynamic_sections (output_bfd, info) | |
5784 | bfd *output_bfd; | |
5785 | struct bfd_link_info *info; | |
5786 | { | |
5787 | bfd *dynobj; | |
5788 | asection *sgot; | |
5789 | asection *sdyn; | |
5790 | ||
5791 | dynobj = elf_hash_table (info)->dynobj; | |
5792 | ||
5793 | sgot = bfd_get_section_by_name (dynobj, ".got.plt"); | |
5794 | BFD_ASSERT (sgot != NULL); | |
5795 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); | |
5796 | ||
5797 | if (elf_hash_table (info)->dynamic_sections_created) | |
5798 | { | |
5799 | asection *splt; | |
5800 | Elf32_External_Dyn *dyncon, *dynconend; | |
5801 | ||
5802 | BFD_ASSERT (sdyn != NULL); | |
5803 | ||
5804 | dyncon = (Elf32_External_Dyn *) sdyn->contents; | |
5805 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size); | |
5806 | for (; dyncon < dynconend; dyncon++) | |
5807 | { | |
5808 | Elf_Internal_Dyn dyn; | |
5809 | const char *name; | |
5810 | asection *s; | |
5811 | ||
5812 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); | |
5813 | ||
5814 | switch (dyn.d_tag) | |
5815 | { | |
5816 | default: | |
5817 | break; | |
5818 | ||
5819 | case DT_PLTGOT: | |
5820 | name = ".got"; | |
5821 | goto get_vma; | |
5822 | ||
5823 | case DT_JMPREL: | |
5824 | name = ".rela.plt"; | |
5825 | get_vma: | |
5826 | s = bfd_get_section_by_name (output_bfd, name); | |
5827 | BFD_ASSERT (s != NULL); | |
5828 | dyn.d_un.d_ptr = s->vma; | |
5829 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
5830 | break; | |
5831 | ||
5832 | case DT_PLTRELSZ: | |
5833 | s = bfd_get_section_by_name (output_bfd, ".rela.plt"); | |
5834 | BFD_ASSERT (s != NULL); | |
5835 | if (s->_cooked_size != 0) | |
5836 | dyn.d_un.d_val = s->_cooked_size; | |
5837 | else | |
5838 | dyn.d_un.d_val = s->_raw_size; | |
5839 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
5840 | break; | |
5841 | ||
5842 | case DT_RELASZ: | |
5843 | /* My reading of the SVR4 ABI indicates that the | |
5844 | procedure linkage table relocs (DT_JMPREL) should be | |
5845 | included in the overall relocs (DT_RELA). This is | |
5846 | what Solaris does. However, UnixWare can not handle | |
5847 | that case. Therefore, we override the DT_RELASZ entry | |
5848 | here to make it not include the JMPREL relocs. Since | |
5849 | the linker script arranges for .rela.plt to follow all | |
5850 | other relocation sections, we don't have to worry | |
5851 | about changing the DT_RELA entry. */ | |
5852 | s = bfd_get_section_by_name (output_bfd, ".rela.plt"); | |
5853 | if (s != NULL) | |
5854 | { | |
5855 | if (s->_cooked_size != 0) | |
5856 | dyn.d_un.d_val -= s->_cooked_size; | |
5857 | else | |
5858 | dyn.d_un.d_val -= s->_raw_size; | |
5859 | } | |
5860 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
5861 | break; | |
5862 | } | |
5863 | } | |
5864 | ||
5865 | /* Fill in the first entry in the procedure linkage table. */ | |
5866 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
5867 | if (splt && splt->_raw_size > 0) | |
5868 | { | |
5869 | if (info->shared) | |
5870 | { | |
5871 | if (elf_sh_pic_plt_entry == NULL) | |
5872 | { | |
435b1e90 | 5873 | elf_sh_pic_plt_entry = (bfd_big_endian (output_bfd) ? |
37c644f2 AO |
5874 | elf_sh_pic_plt_entry_be : |
5875 | elf_sh_pic_plt_entry_le); | |
5876 | } | |
5877 | memcpy (splt->contents, elf_sh_pic_plt_entry, | |
5878 | elf_sh_sizeof_plt (info)); | |
5879 | } | |
5880 | else | |
5881 | { | |
5882 | if (elf_sh_plt0_entry == NULL) | |
5883 | { | |
435b1e90 | 5884 | elf_sh_plt0_entry = (bfd_big_endian (output_bfd) ? |
37c644f2 AO |
5885 | elf_sh_plt0_entry_be : |
5886 | elf_sh_plt0_entry_le); | |
5887 | } | |
5888 | memcpy (splt->contents, elf_sh_plt0_entry, PLT_ENTRY_SIZE); | |
fbca6ad9 AO |
5889 | #ifdef INCLUDE_SHMEDIA |
5890 | movi_shori_putval (output_bfd, | |
5891 | sgot->output_section->vma | |
5892 | + sgot->output_offset, | |
5893 | splt->contents | |
5894 | + elf_sh_plt0_gotplt_offset (info)); | |
5895 | #else | |
37c644f2 AO |
5896 | bfd_put_32 (output_bfd, |
5897 | sgot->output_section->vma + sgot->output_offset + 4, | |
5898 | splt->contents + elf_sh_plt0_gotid_offset (info)); | |
5899 | bfd_put_32 (output_bfd, | |
5900 | sgot->output_section->vma + sgot->output_offset + 8, | |
5901 | splt->contents + elf_sh_plt0_linker_offset (info)); | |
fbca6ad9 | 5902 | #endif |
37c644f2 AO |
5903 | } |
5904 | ||
5905 | /* UnixWare sets the entsize of .plt to 4, although that doesn't | |
5906 | really seem like the right value. */ | |
5907 | elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4; | |
5908 | } | |
5909 | } | |
5910 | ||
5911 | /* Fill in the first three entries in the global offset table. */ | |
5912 | if (sgot->_raw_size > 0) | |
5913 | { | |
5914 | if (sdyn == NULL) | |
5915 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents); | |
5916 | else | |
5917 | bfd_put_32 (output_bfd, | |
5918 | sdyn->output_section->vma + sdyn->output_offset, | |
5919 | sgot->contents); | |
5920 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4); | |
5921 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8); | |
5922 | } | |
5923 | ||
5924 | elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; | |
5925 | ||
5926 | return true; | |
5927 | } | |
5928 | ||
99e4ae17 | 5929 | static enum elf_reloc_type_class |
f51e552e AM |
5930 | sh_elf_reloc_type_class (rela) |
5931 | const Elf_Internal_Rela *rela; | |
99e4ae17 | 5932 | { |
f51e552e | 5933 | switch ((int) ELF32_R_TYPE (rela->r_info)) |
99e4ae17 AJ |
5934 | { |
5935 | case R_SH_RELATIVE: | |
5936 | return reloc_class_relative; | |
5937 | case R_SH_JMP_SLOT: | |
5938 | return reloc_class_plt; | |
5939 | case R_SH_COPY: | |
5940 | return reloc_class_copy; | |
5941 | default: | |
5942 | return reloc_class_normal; | |
5943 | } | |
5944 | } | |
5945 | ||
b129bfef | 5946 | #ifndef ELF_ARCH |
252b5132 RH |
5947 | #define TARGET_BIG_SYM bfd_elf32_sh_vec |
5948 | #define TARGET_BIG_NAME "elf32-sh" | |
5949 | #define TARGET_LITTLE_SYM bfd_elf32_shl_vec | |
5950 | #define TARGET_LITTLE_NAME "elf32-shl" | |
5951 | #define ELF_ARCH bfd_arch_sh | |
5952 | #define ELF_MACHINE_CODE EM_SH | |
4bb5e078 | 5953 | #define ELF_MAXPAGESIZE 128 |
252b5132 RH |
5954 | |
5955 | #define elf_symbol_leading_char '_' | |
b129bfef | 5956 | #endif /* ELF_ARCH */ |
252b5132 RH |
5957 | |
5958 | #define bfd_elf32_bfd_reloc_type_lookup sh_elf_reloc_type_lookup | |
5959 | #define elf_info_to_howto sh_elf_info_to_howto | |
5960 | #define bfd_elf32_bfd_relax_section sh_elf_relax_section | |
5961 | #define elf_backend_relocate_section sh_elf_relocate_section | |
5962 | #define bfd_elf32_bfd_get_relocated_section_contents \ | |
5963 | sh_elf_get_relocated_section_contents | |
d4845d57 JR |
5964 | #define elf_backend_object_p sh_elf_set_mach_from_flags |
5965 | #define bfd_elf32_bfd_set_private_bfd_flags \ | |
5966 | sh_elf_set_private_flags | |
5967 | #define bfd_elf32_bfd_copy_private_bfd_data \ | |
5968 | sh_elf_copy_private_data | |
875f7f69 | 5969 | #define bfd_elf32_bfd_merge_private_bfd_data \ |
d4845d57 | 5970 | sh_elf_merge_private_data |
252b5132 RH |
5971 | |
5972 | #define elf_backend_gc_mark_hook sh_elf_gc_mark_hook | |
5973 | #define elf_backend_gc_sweep_hook sh_elf_gc_sweep_hook | |
5974 | #define elf_backend_check_relocs sh_elf_check_relocs | |
5975 | ||
37c644f2 AO |
5976 | #define elf_backend_can_gc_sections 1 |
5977 | #define elf_backend_create_dynamic_sections \ | |
5978 | sh_elf_create_dynamic_sections | |
5979 | #define bfd_elf32_bfd_link_hash_table_create \ | |
5980 | sh_elf_link_hash_table_create | |
5981 | #define elf_backend_adjust_dynamic_symbol \ | |
5982 | sh_elf_adjust_dynamic_symbol | |
5983 | #define elf_backend_size_dynamic_sections \ | |
5984 | sh_elf_size_dynamic_sections | |
5985 | #define elf_backend_finish_dynamic_symbol \ | |
5986 | sh_elf_finish_dynamic_symbol | |
5987 | #define elf_backend_finish_dynamic_sections \ | |
5988 | sh_elf_finish_dynamic_sections | |
99e4ae17 | 5989 | #define elf_backend_reloc_type_class sh_elf_reloc_type_class |
37c644f2 AO |
5990 | |
5991 | #define elf_backend_want_got_plt 1 | |
5992 | #define elf_backend_plt_readonly 1 | |
5993 | #define elf_backend_want_plt_sym 0 | |
5994 | #define elf_backend_got_header_size 12 | |
5995 | #define elf_backend_plt_header_size PLT_ENTRY_SIZE | |
252b5132 | 5996 | #include "elf32-target.h" |