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