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