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