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