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