1 /* Renesas / SuperH SH specific support for 32-bit ELF
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006 Free Software Foundation, Inc.
4 Contributed by Ian Lance Taylor, Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
28 #include "libiberty.h"
29 #include "../opcodes/sh-opc.h"
31 static bfd_reloc_status_type sh_elf_reloc
32 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
33 static bfd_reloc_status_type sh_elf_ignore_reloc
34 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
35 static bfd_boolean sh_elf_relax_delete_bytes
36 (bfd
*, asection
*, bfd_vma
, int);
37 static bfd_boolean sh_elf_align_loads
38 (bfd
*, asection
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_boolean
*);
40 static bfd_boolean sh_elf_swap_insns
41 (bfd
*, asection
*, void *, bfd_byte
*, bfd_vma
);
43 static int sh_elf_optimized_tls_reloc
44 (struct bfd_link_info
*, int, int);
45 static bfd_vma dtpoff_base
46 (struct bfd_link_info
*);
48 (struct bfd_link_info
*, bfd_vma
);
50 /* The name of the dynamic interpreter. This is put in the .interp
53 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
55 static reloc_howto_type sh_elf_howto_table
[] =
58 HOWTO (R_SH_NONE
, /* type */
60 0, /* size (0 = byte, 1 = short, 2 = long) */
62 FALSE
, /* pc_relative */
64 complain_overflow_dont
, /* complain_on_overflow */
65 sh_elf_ignore_reloc
, /* special_function */
66 "R_SH_NONE", /* name */
67 FALSE
, /* partial_inplace */
70 FALSE
), /* pcrel_offset */
72 /* 32 bit absolute relocation. Setting partial_inplace to TRUE and
73 src_mask to a non-zero value is similar to the COFF toolchain. */
74 HOWTO (R_SH_DIR32
, /* type */
76 2, /* size (0 = byte, 1 = short, 2 = long) */
78 FALSE
, /* pc_relative */
80 complain_overflow_bitfield
, /* complain_on_overflow */
81 sh_elf_reloc
, /* special_function */
82 "R_SH_DIR32", /* name */
83 TRUE
, /* partial_inplace */
84 0xffffffff, /* src_mask */
85 0xffffffff, /* dst_mask */
86 FALSE
), /* pcrel_offset */
88 /* 32 bit PC relative relocation. */
89 HOWTO (R_SH_REL32
, /* type */
91 2, /* size (0 = byte, 1 = short, 2 = long) */
93 TRUE
, /* pc_relative */
95 complain_overflow_signed
, /* complain_on_overflow */
96 sh_elf_ignore_reloc
, /* special_function */
97 "R_SH_REL32", /* name */
98 TRUE
, /* partial_inplace */
99 0xffffffff, /* src_mask */
100 0xffffffff, /* dst_mask */
101 TRUE
), /* pcrel_offset */
103 /* 8 bit PC relative branch divided by 2. */
104 HOWTO (R_SH_DIR8WPN
, /* type */
106 1, /* size (0 = byte, 1 = short, 2 = long) */
108 TRUE
, /* pc_relative */
110 complain_overflow_signed
, /* complain_on_overflow */
111 sh_elf_ignore_reloc
, /* special_function */
112 "R_SH_DIR8WPN", /* name */
113 TRUE
, /* partial_inplace */
116 TRUE
), /* pcrel_offset */
118 /* 12 bit PC relative branch divided by 2. */
119 /* This cannot be partial_inplace because relaxation can't know the
120 eventual value of a symbol. */
121 HOWTO (R_SH_IND12W
, /* type */
123 1, /* size (0 = byte, 1 = short, 2 = long) */
125 TRUE
, /* pc_relative */
127 complain_overflow_signed
, /* complain_on_overflow */
128 NULL
, /* special_function */
129 "R_SH_IND12W", /* name */
130 FALSE
, /* partial_inplace */
132 0xfff, /* dst_mask */
133 TRUE
), /* pcrel_offset */
135 /* 8 bit unsigned PC relative divided by 4. */
136 HOWTO (R_SH_DIR8WPL
, /* type */
138 1, /* size (0 = byte, 1 = short, 2 = long) */
140 TRUE
, /* pc_relative */
142 complain_overflow_unsigned
, /* complain_on_overflow */
143 sh_elf_ignore_reloc
, /* special_function */
144 "R_SH_DIR8WPL", /* name */
145 TRUE
, /* partial_inplace */
148 TRUE
), /* pcrel_offset */
150 /* 8 bit unsigned PC relative divided by 2. */
151 HOWTO (R_SH_DIR8WPZ
, /* type */
153 1, /* size (0 = byte, 1 = short, 2 = long) */
155 TRUE
, /* pc_relative */
157 complain_overflow_unsigned
, /* complain_on_overflow */
158 sh_elf_ignore_reloc
, /* special_function */
159 "R_SH_DIR8WPZ", /* name */
160 TRUE
, /* partial_inplace */
163 TRUE
), /* pcrel_offset */
165 /* 8 bit GBR relative. FIXME: This only makes sense if we have some
166 special symbol for the GBR relative area, and that is not
168 HOWTO (R_SH_DIR8BP
, /* type */
170 1, /* size (0 = byte, 1 = short, 2 = long) */
172 FALSE
, /* pc_relative */
174 complain_overflow_unsigned
, /* complain_on_overflow */
175 sh_elf_ignore_reloc
, /* special_function */
176 "R_SH_DIR8BP", /* name */
177 FALSE
, /* partial_inplace */
180 TRUE
), /* pcrel_offset */
182 /* 8 bit GBR relative divided by 2. FIXME: This only makes sense if
183 we have some special symbol for the GBR relative area, and that
184 is not implemented. */
185 HOWTO (R_SH_DIR8W
, /* type */
187 1, /* size (0 = byte, 1 = short, 2 = long) */
189 FALSE
, /* pc_relative */
191 complain_overflow_unsigned
, /* complain_on_overflow */
192 sh_elf_ignore_reloc
, /* special_function */
193 "R_SH_DIR8W", /* name */
194 FALSE
, /* partial_inplace */
197 TRUE
), /* pcrel_offset */
199 /* 8 bit GBR relative divided by 4. FIXME: This only makes sense if
200 we have some special symbol for the GBR relative area, and that
201 is not implemented. */
202 HOWTO (R_SH_DIR8L
, /* type */
204 1, /* size (0 = byte, 1 = short, 2 = long) */
206 FALSE
, /* pc_relative */
208 complain_overflow_unsigned
, /* complain_on_overflow */
209 sh_elf_ignore_reloc
, /* special_function */
210 "R_SH_DIR8L", /* name */
211 FALSE
, /* partial_inplace */
214 TRUE
), /* pcrel_offset */
216 /* 8 bit PC relative divided by 2 - but specified in a very odd way. */
217 HOWTO (R_SH_LOOP_START
, /* type */
219 1, /* size (0 = byte, 1 = short, 2 = long) */
221 FALSE
, /* pc_relative */
223 complain_overflow_signed
, /* complain_on_overflow */
224 sh_elf_ignore_reloc
, /* special_function */
225 "R_SH_LOOP_START", /* name */
226 TRUE
, /* partial_inplace */
229 TRUE
), /* pcrel_offset */
231 /* 8 bit PC relative divided by 2 - but specified in a very odd way. */
232 HOWTO (R_SH_LOOP_END
, /* type */
234 1, /* size (0 = byte, 1 = short, 2 = long) */
236 FALSE
, /* pc_relative */
238 complain_overflow_signed
, /* complain_on_overflow */
239 sh_elf_ignore_reloc
, /* special_function */
240 "R_SH_LOOP_END", /* name */
241 TRUE
, /* partial_inplace */
244 TRUE
), /* pcrel_offset */
257 /* The remaining relocs are a GNU extension used for relaxing. The
258 final pass of the linker never needs to do anything with any of
259 these relocs. Any required operations are handled by the
262 /* GNU extension to record C++ vtable hierarchy */
263 HOWTO (R_SH_GNU_VTINHERIT
, /* type */
265 2, /* size (0 = byte, 1 = short, 2 = long) */
267 FALSE
, /* pc_relative */
269 complain_overflow_dont
, /* complain_on_overflow */
270 NULL
, /* special_function */
271 "R_SH_GNU_VTINHERIT", /* name */
272 FALSE
, /* partial_inplace */
275 FALSE
), /* pcrel_offset */
277 /* GNU extension to record C++ vtable member usage */
278 HOWTO (R_SH_GNU_VTENTRY
, /* type */
280 2, /* size (0 = byte, 1 = short, 2 = long) */
282 FALSE
, /* pc_relative */
284 complain_overflow_dont
, /* complain_on_overflow */
285 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
286 "R_SH_GNU_VTENTRY", /* name */
287 FALSE
, /* partial_inplace */
290 FALSE
), /* pcrel_offset */
292 /* An 8 bit switch table entry. This is generated for an expression
293 such as ``.word L1 - L2''. The offset holds the difference
294 between the reloc address and L2. */
295 HOWTO (R_SH_SWITCH8
, /* type */
297 0, /* size (0 = byte, 1 = short, 2 = long) */
299 FALSE
, /* pc_relative */
301 complain_overflow_unsigned
, /* complain_on_overflow */
302 sh_elf_ignore_reloc
, /* special_function */
303 "R_SH_SWITCH8", /* name */
304 FALSE
, /* partial_inplace */
307 TRUE
), /* pcrel_offset */
309 /* A 16 bit switch table entry. This is generated for an expression
310 such as ``.word L1 - L2''. The offset holds the difference
311 between the reloc address and L2. */
312 HOWTO (R_SH_SWITCH16
, /* type */
314 1, /* size (0 = byte, 1 = short, 2 = long) */
316 FALSE
, /* pc_relative */
318 complain_overflow_unsigned
, /* complain_on_overflow */
319 sh_elf_ignore_reloc
, /* special_function */
320 "R_SH_SWITCH16", /* name */
321 FALSE
, /* partial_inplace */
324 TRUE
), /* pcrel_offset */
326 /* A 32 bit switch table entry. This is generated for an expression
327 such as ``.long L1 - L2''. The offset holds the difference
328 between the reloc address and L2. */
329 HOWTO (R_SH_SWITCH32
, /* type */
331 2, /* size (0 = byte, 1 = short, 2 = long) */
333 FALSE
, /* pc_relative */
335 complain_overflow_unsigned
, /* complain_on_overflow */
336 sh_elf_ignore_reloc
, /* special_function */
337 "R_SH_SWITCH32", /* name */
338 FALSE
, /* partial_inplace */
341 TRUE
), /* pcrel_offset */
343 /* Indicates a .uses pseudo-op. The compiler will generate .uses
344 pseudo-ops when it finds a function call which can be relaxed.
345 The offset field holds the PC relative offset to the instruction
346 which loads the register used in the function call. */
347 HOWTO (R_SH_USES
, /* type */
349 1, /* size (0 = byte, 1 = short, 2 = long) */
351 FALSE
, /* pc_relative */
353 complain_overflow_unsigned
, /* complain_on_overflow */
354 sh_elf_ignore_reloc
, /* special_function */
355 "R_SH_USES", /* name */
356 FALSE
, /* partial_inplace */
359 TRUE
), /* pcrel_offset */
361 /* The assembler will generate this reloc for addresses referred to
362 by the register loads associated with USES relocs. The offset
363 field holds the number of times the address is referenced in the
365 HOWTO (R_SH_COUNT
, /* type */
367 1, /* size (0 = byte, 1 = short, 2 = long) */
369 FALSE
, /* pc_relative */
371 complain_overflow_unsigned
, /* complain_on_overflow */
372 sh_elf_ignore_reloc
, /* special_function */
373 "R_SH_COUNT", /* name */
374 FALSE
, /* partial_inplace */
377 TRUE
), /* pcrel_offset */
379 /* Indicates an alignment statement. The offset field is the power
380 of 2 to which subsequent portions of the object file must be
382 HOWTO (R_SH_ALIGN
, /* type */
384 1, /* size (0 = byte, 1 = short, 2 = long) */
386 FALSE
, /* pc_relative */
388 complain_overflow_unsigned
, /* complain_on_overflow */
389 sh_elf_ignore_reloc
, /* special_function */
390 "R_SH_ALIGN", /* name */
391 FALSE
, /* partial_inplace */
394 TRUE
), /* pcrel_offset */
396 /* The assembler will generate this reloc before a block of
397 instructions. A section should be processed as assuming it
398 contains data, unless this reloc is seen. */
399 HOWTO (R_SH_CODE
, /* type */
401 1, /* size (0 = byte, 1 = short, 2 = long) */
403 FALSE
, /* pc_relative */
405 complain_overflow_unsigned
, /* complain_on_overflow */
406 sh_elf_ignore_reloc
, /* special_function */
407 "R_SH_CODE", /* name */
408 FALSE
, /* partial_inplace */
411 TRUE
), /* pcrel_offset */
413 /* The assembler will generate this reloc after a block of
414 instructions when it sees data that is not instructions. */
415 HOWTO (R_SH_DATA
, /* type */
417 1, /* size (0 = byte, 1 = short, 2 = long) */
419 FALSE
, /* pc_relative */
421 complain_overflow_unsigned
, /* complain_on_overflow */
422 sh_elf_ignore_reloc
, /* special_function */
423 "R_SH_DATA", /* name */
424 FALSE
, /* partial_inplace */
427 TRUE
), /* pcrel_offset */
429 /* The assembler generates this reloc for each label within a block
430 of instructions. This permits the linker to avoid swapping
431 instructions which are the targets of branches. */
432 HOWTO (R_SH_LABEL
, /* type */
434 1, /* size (0 = byte, 1 = short, 2 = long) */
436 FALSE
, /* pc_relative */
438 complain_overflow_unsigned
, /* complain_on_overflow */
439 sh_elf_ignore_reloc
, /* special_function */
440 "R_SH_LABEL", /* name */
441 FALSE
, /* partial_inplace */
444 TRUE
), /* pcrel_offset */
446 /* The next 12 are only supported via linking in SHC-generated objects. */
447 HOWTO (R_SH_DIR16
, /* type */
449 1, /* size (0 = byte, 1 = short, 2 = long) */
451 FALSE
, /* pc_relative */
453 complain_overflow_dont
, /* complain_on_overflow */
454 bfd_elf_generic_reloc
, /* special_function */
455 "R_SH_DIR16", /* name */
456 FALSE
, /* partial_inplace */
458 0xffff, /* dst_mask */
459 FALSE
), /* pcrel_offset */
461 HOWTO (R_SH_DIR8
, /* type */
463 0, /* size (0 = byte, 1 = short, 2 = long) */
465 FALSE
, /* pc_relative */
467 complain_overflow_dont
, /* complain_on_overflow */
468 bfd_elf_generic_reloc
, /* special_function */
469 "R_SH_DIR8", /* name */
470 FALSE
, /* partial_inplace */
473 FALSE
), /* pcrel_offset */
475 HOWTO (R_SH_DIR8UL
, /* type */
477 0, /* size (0 = byte, 1 = short, 2 = long) */
479 FALSE
, /* pc_relative */
481 complain_overflow_unsigned
, /* complain_on_overflow */
482 bfd_elf_generic_reloc
, /* special_function */
483 "R_SH_DIR8UL", /* name */
484 FALSE
, /* partial_inplace */
487 FALSE
), /* pcrel_offset */
489 HOWTO (R_SH_DIR8UW
, /* type */
491 0, /* size (0 = byte, 1 = short, 2 = long) */
493 FALSE
, /* pc_relative */
495 complain_overflow_unsigned
, /* complain_on_overflow */
496 bfd_elf_generic_reloc
, /* special_function */
497 "R_SH_DIR8UW", /* name */
498 FALSE
, /* partial_inplace */
501 FALSE
), /* pcrel_offset */
503 HOWTO (R_SH_DIR8U
, /* type */
505 0, /* size (0 = byte, 1 = short, 2 = long) */
507 FALSE
, /* pc_relative */
509 complain_overflow_unsigned
, /* complain_on_overflow */
510 bfd_elf_generic_reloc
, /* special_function */
511 "R_SH_DIR8U", /* name */
512 FALSE
, /* partial_inplace */
515 FALSE
), /* pcrel_offset */
517 HOWTO (R_SH_DIR8SW
, /* type */
519 0, /* size (0 = byte, 1 = short, 2 = long) */
521 FALSE
, /* pc_relative */
523 complain_overflow_signed
, /* complain_on_overflow */
524 bfd_elf_generic_reloc
, /* special_function */
525 "R_SH_DIR8SW", /* name */
526 FALSE
, /* partial_inplace */
529 FALSE
), /* pcrel_offset */
531 HOWTO (R_SH_DIR8S
, /* type */
533 0, /* size (0 = byte, 1 = short, 2 = long) */
535 FALSE
, /* pc_relative */
537 complain_overflow_signed
, /* complain_on_overflow */
538 bfd_elf_generic_reloc
, /* special_function */
539 "R_SH_DIR8S", /* name */
540 FALSE
, /* partial_inplace */
543 FALSE
), /* pcrel_offset */
545 HOWTO (R_SH_DIR4UL
, /* type */
547 0, /* size (0 = byte, 1 = short, 2 = long) */
549 FALSE
, /* pc_relative */
551 complain_overflow_unsigned
, /* complain_on_overflow */
552 bfd_elf_generic_reloc
, /* special_function */
553 "R_SH_DIR4UL", /* name */
554 FALSE
, /* partial_inplace */
557 FALSE
), /* pcrel_offset */
559 HOWTO (R_SH_DIR4UW
, /* type */
561 0, /* size (0 = byte, 1 = short, 2 = long) */
563 FALSE
, /* pc_relative */
565 complain_overflow_unsigned
, /* complain_on_overflow */
566 bfd_elf_generic_reloc
, /* special_function */
567 "R_SH_DIR4UW", /* name */
568 FALSE
, /* partial_inplace */
571 FALSE
), /* pcrel_offset */
573 HOWTO (R_SH_DIR4U
, /* type */
575 0, /* size (0 = byte, 1 = short, 2 = long) */
577 FALSE
, /* pc_relative */
579 complain_overflow_unsigned
, /* complain_on_overflow */
580 bfd_elf_generic_reloc
, /* special_function */
581 "R_SH_DIR4U", /* name */
582 FALSE
, /* partial_inplace */
585 FALSE
), /* pcrel_offset */
587 HOWTO (R_SH_PSHA
, /* type */
589 1, /* size (0 = byte, 1 = short, 2 = long) */
591 FALSE
, /* pc_relative */
593 complain_overflow_signed
, /* complain_on_overflow */
594 bfd_elf_generic_reloc
, /* special_function */
595 "R_SH_PSHA", /* name */
596 FALSE
, /* partial_inplace */
599 FALSE
), /* pcrel_offset */
601 HOWTO (R_SH_PSHL
, /* type */
603 1, /* size (0 = byte, 1 = short, 2 = long) */
605 FALSE
, /* pc_relative */
607 complain_overflow_signed
, /* complain_on_overflow */
608 bfd_elf_generic_reloc
, /* special_function */
609 "R_SH_PSHL", /* name */
610 FALSE
, /* partial_inplace */
613 FALSE
), /* pcrel_offset */
615 #ifdef INCLUDE_SHMEDIA
616 /* Used in SHLLI.L and SHLRI.L. */
617 HOWTO (R_SH_DIR5U
, /* type */
619 2, /* size (0 = byte, 1 = short, 2 = long) */
621 FALSE
, /* pc_relative */
623 complain_overflow_unsigned
, /* complain_on_overflow */
624 bfd_elf_generic_reloc
, /* special_function */
625 "R_SH_DIR5U", /* name */
626 FALSE
, /* partial_inplace */
628 0xfc00, /* dst_mask */
629 FALSE
), /* pcrel_offset */
631 /* Used in SHARI, SHLLI et al. */
632 HOWTO (R_SH_DIR6U
, /* type */
634 2, /* size (0 = byte, 1 = short, 2 = long) */
636 FALSE
, /* pc_relative */
638 complain_overflow_unsigned
, /* complain_on_overflow */
639 bfd_elf_generic_reloc
, /* special_function */
640 "R_SH_DIR6U", /* name */
641 FALSE
, /* partial_inplace */
643 0xfc00, /* dst_mask */
644 FALSE
), /* pcrel_offset */
646 /* Used in BxxI, LDHI.L et al. */
647 HOWTO (R_SH_DIR6S
, /* type */
649 2, /* size (0 = byte, 1 = short, 2 = long) */
651 FALSE
, /* pc_relative */
653 complain_overflow_signed
, /* complain_on_overflow */
654 bfd_elf_generic_reloc
, /* special_function */
655 "R_SH_DIR6S", /* name */
656 FALSE
, /* partial_inplace */
658 0xfc00, /* dst_mask */
659 FALSE
), /* pcrel_offset */
661 /* Used in ADDI, ANDI et al. */
662 HOWTO (R_SH_DIR10S
, /* type */
664 2, /* size (0 = byte, 1 = short, 2 = long) */
666 FALSE
, /* pc_relative */
668 complain_overflow_signed
, /* complain_on_overflow */
669 bfd_elf_generic_reloc
, /* special_function */
670 "R_SH_DIR10S", /* name */
671 FALSE
, /* partial_inplace */
673 0xffc00, /* dst_mask */
674 FALSE
), /* pcrel_offset */
676 /* Used in LD.UW, ST.W et al. */
677 HOWTO (R_SH_DIR10SW
, /* type */
679 2, /* size (0 = byte, 1 = short, 2 = long) */
681 FALSE
, /* pc_relative */
683 complain_overflow_signed
, /* complain_on_overflow */
684 bfd_elf_generic_reloc
, /* special_function */
685 "R_SH_DIR10SW", /* name */
686 FALSE
, /* partial_inplace */
688 0xffc00, /* dst_mask */
689 FALSE
), /* pcrel_offset */
691 /* Used in LD.L, FLD.S et al. */
692 HOWTO (R_SH_DIR10SL
, /* type */
694 2, /* size (0 = byte, 1 = short, 2 = long) */
696 FALSE
, /* pc_relative */
698 complain_overflow_signed
, /* complain_on_overflow */
699 bfd_elf_generic_reloc
, /* special_function */
700 "R_SH_DIR10SL", /* name */
701 FALSE
, /* partial_inplace */
703 0xffc00, /* dst_mask */
704 FALSE
), /* pcrel_offset */
706 /* Used in FLD.D, FST.P et al. */
707 HOWTO (R_SH_DIR10SQ
, /* type */
709 2, /* size (0 = byte, 1 = short, 2 = long) */
711 FALSE
, /* pc_relative */
713 complain_overflow_signed
, /* complain_on_overflow */
714 bfd_elf_generic_reloc
, /* special_function */
715 "R_SH_DIR10SQ", /* name */
716 FALSE
, /* partial_inplace */
718 0xffc00, /* dst_mask */
719 FALSE
), /* pcrel_offset */
733 HOWTO (R_SH_DIR16S
, /* type */
735 1, /* size (0 = byte, 1 = short, 2 = long) */
737 FALSE
, /* pc_relative */
739 complain_overflow_signed
, /* complain_on_overflow */
740 bfd_elf_generic_reloc
, /* special_function */
741 "R_SH_DIR16S", /* name */
742 FALSE
, /* partial_inplace */
744 0xffff, /* dst_mask */
745 FALSE
), /* pcrel_offset */
838 HOWTO (R_SH_TLS_GD_32
, /* type */
840 2, /* size (0 = byte, 1 = short, 2 = long) */
842 FALSE
, /* pc_relative */
844 complain_overflow_bitfield
, /* complain_on_overflow */
845 bfd_elf_generic_reloc
, /* */
846 "R_SH_TLS_GD_32", /* name */
847 TRUE
, /* partial_inplace */
848 0xffffffff, /* src_mask */
849 0xffffffff, /* dst_mask */
850 FALSE
), /* pcrel_offset */
852 HOWTO (R_SH_TLS_LD_32
, /* type */
854 2, /* size (0 = byte, 1 = short, 2 = long) */
856 FALSE
, /* pc_relative */
858 complain_overflow_bitfield
, /* complain_on_overflow */
859 bfd_elf_generic_reloc
, /* */
860 "R_SH_TLS_LD_32", /* name */
861 TRUE
, /* partial_inplace */
862 0xffffffff, /* src_mask */
863 0xffffffff, /* dst_mask */
864 FALSE
), /* pcrel_offset */
866 HOWTO (R_SH_TLS_LDO_32
, /* type */
868 2, /* size (0 = byte, 1 = short, 2 = long) */
870 FALSE
, /* pc_relative */
872 complain_overflow_bitfield
, /* complain_on_overflow */
873 bfd_elf_generic_reloc
, /* */
874 "R_SH_TLS_LDO_32", /* name */
875 TRUE
, /* partial_inplace */
876 0xffffffff, /* src_mask */
877 0xffffffff, /* dst_mask */
878 FALSE
), /* pcrel_offset */
880 HOWTO (R_SH_TLS_IE_32
, /* type */
882 2, /* size (0 = byte, 1 = short, 2 = long) */
884 FALSE
, /* pc_relative */
886 complain_overflow_bitfield
, /* complain_on_overflow */
887 bfd_elf_generic_reloc
, /* */
888 "R_SH_TLS_IE_32", /* name */
889 TRUE
, /* partial_inplace */
890 0xffffffff, /* src_mask */
891 0xffffffff, /* dst_mask */
892 FALSE
), /* pcrel_offset */
894 HOWTO (R_SH_TLS_LE_32
, /* type */
896 2, /* size (0 = byte, 1 = short, 2 = long) */
898 FALSE
, /* pc_relative */
900 complain_overflow_bitfield
, /* complain_on_overflow */
901 bfd_elf_generic_reloc
, /* */
902 "R_SH_TLS_LE_32", /* name */
903 TRUE
, /* partial_inplace */
904 0xffffffff, /* src_mask */
905 0xffffffff, /* dst_mask */
906 FALSE
), /* pcrel_offset */
908 HOWTO (R_SH_TLS_DTPMOD32
, /* type */
910 2, /* size (0 = byte, 1 = short, 2 = long) */
912 FALSE
, /* pc_relative */
914 complain_overflow_bitfield
, /* complain_on_overflow */
915 bfd_elf_generic_reloc
, /* */
916 "R_SH_TLS_DTPMOD32", /* name */
917 TRUE
, /* partial_inplace */
918 0xffffffff, /* src_mask */
919 0xffffffff, /* dst_mask */
920 FALSE
), /* pcrel_offset */
922 HOWTO (R_SH_TLS_DTPOFF32
, /* type */
924 2, /* size (0 = byte, 1 = short, 2 = long) */
926 FALSE
, /* pc_relative */
928 complain_overflow_bitfield
, /* complain_on_overflow */
929 bfd_elf_generic_reloc
, /* */
930 "R_SH_TLS_DTPOFF32", /* name */
931 TRUE
, /* partial_inplace */
932 0xffffffff, /* src_mask */
933 0xffffffff, /* dst_mask */
934 FALSE
), /* pcrel_offset */
936 HOWTO (R_SH_TLS_TPOFF32
, /* type */
938 2, /* size (0 = byte, 1 = short, 2 = long) */
940 FALSE
, /* pc_relative */
942 complain_overflow_bitfield
, /* complain_on_overflow */
943 bfd_elf_generic_reloc
, /* */
944 "R_SH_TLS_TPOFF32", /* name */
945 TRUE
, /* partial_inplace */
946 0xffffffff, /* src_mask */
947 0xffffffff, /* dst_mask */
948 FALSE
), /* pcrel_offset */
959 HOWTO (R_SH_GOT32
, /* type */
961 2, /* size (0 = byte, 1 = short, 2 = long) */
963 FALSE
, /* pc_relative */
965 complain_overflow_bitfield
, /* complain_on_overflow */
966 bfd_elf_generic_reloc
, /* */
967 "R_SH_GOT32", /* name */
968 TRUE
, /* partial_inplace */
969 0xffffffff, /* src_mask */
970 0xffffffff, /* dst_mask */
971 FALSE
), /* pcrel_offset */
973 HOWTO (R_SH_PLT32
, /* type */
975 2, /* size (0 = byte, 1 = short, 2 = long) */
977 TRUE
, /* pc_relative */
979 complain_overflow_bitfield
, /* complain_on_overflow */
980 bfd_elf_generic_reloc
, /* */
981 "R_SH_PLT32", /* name */
982 TRUE
, /* partial_inplace */
983 0xffffffff, /* src_mask */
984 0xffffffff, /* dst_mask */
985 TRUE
), /* pcrel_offset */
987 HOWTO (R_SH_COPY
, /* type */
989 2, /* size (0 = byte, 1 = short, 2 = long) */
991 FALSE
, /* pc_relative */
993 complain_overflow_bitfield
, /* complain_on_overflow */
994 bfd_elf_generic_reloc
, /* */
995 "R_SH_COPY", /* name */
996 TRUE
, /* partial_inplace */
997 0xffffffff, /* src_mask */
998 0xffffffff, /* dst_mask */
999 FALSE
), /* pcrel_offset */
1001 HOWTO (R_SH_GLOB_DAT
, /* type */
1003 2, /* size (0 = byte, 1 = short, 2 = long) */
1005 FALSE
, /* pc_relative */
1007 complain_overflow_bitfield
, /* complain_on_overflow */
1008 bfd_elf_generic_reloc
, /* */
1009 "R_SH_GLOB_DAT", /* name */
1010 TRUE
, /* partial_inplace */
1011 0xffffffff, /* src_mask */
1012 0xffffffff, /* dst_mask */
1013 FALSE
), /* pcrel_offset */
1015 HOWTO (R_SH_JMP_SLOT
, /* type */
1017 2, /* size (0 = byte, 1 = short, 2 = long) */
1019 FALSE
, /* pc_relative */
1021 complain_overflow_bitfield
, /* complain_on_overflow */
1022 bfd_elf_generic_reloc
, /* */
1023 "R_SH_JMP_SLOT", /* name */
1024 TRUE
, /* partial_inplace */
1025 0xffffffff, /* src_mask */
1026 0xffffffff, /* dst_mask */
1027 FALSE
), /* pcrel_offset */
1029 HOWTO (R_SH_RELATIVE
, /* type */
1031 2, /* size (0 = byte, 1 = short, 2 = long) */
1033 FALSE
, /* pc_relative */
1035 complain_overflow_bitfield
, /* complain_on_overflow */
1036 bfd_elf_generic_reloc
, /* */
1037 "R_SH_RELATIVE", /* name */
1038 TRUE
, /* partial_inplace */
1039 0xffffffff, /* src_mask */
1040 0xffffffff, /* dst_mask */
1041 FALSE
), /* pcrel_offset */
1043 HOWTO (R_SH_GOTOFF
, /* type */
1045 2, /* size (0 = byte, 1 = short, 2 = long) */
1047 FALSE
, /* pc_relative */
1049 complain_overflow_bitfield
, /* complain_on_overflow */
1050 bfd_elf_generic_reloc
, /* */
1051 "R_SH_GOTOFF", /* name */
1052 TRUE
, /* partial_inplace */
1053 0xffffffff, /* src_mask */
1054 0xffffffff, /* dst_mask */
1055 FALSE
), /* pcrel_offset */
1057 HOWTO (R_SH_GOTPC
, /* type */
1059 2, /* size (0 = byte, 1 = short, 2 = long) */
1061 TRUE
, /* pc_relative */
1063 complain_overflow_bitfield
, /* complain_on_overflow */
1064 bfd_elf_generic_reloc
, /* */
1065 "R_SH_GOTPC", /* name */
1066 TRUE
, /* partial_inplace */
1067 0xffffffff, /* src_mask */
1068 0xffffffff, /* dst_mask */
1069 TRUE
), /* pcrel_offset */
1071 HOWTO (R_SH_GOTPLT32
, /* type */
1073 2, /* size (0 = byte, 1 = short, 2 = long) */
1075 FALSE
, /* pc_relative */
1077 complain_overflow_bitfield
, /* complain_on_overflow */
1078 bfd_elf_generic_reloc
, /* */
1079 "R_SH_GOTPLT32", /* name */
1080 FALSE
, /* partial_inplace */
1081 0xffffffff, /* src_mask */
1082 0xffffffff, /* dst_mask */
1083 FALSE
), /* pcrel_offset */
1085 #ifdef INCLUDE_SHMEDIA
1086 /* Used in MOVI and SHORI (x & 65536). */
1087 HOWTO (R_SH_GOT_LOW16
, /* type */
1089 2, /* size (0 = byte, 1 = short, 2 = long) */
1091 FALSE
, /* pc_relative */
1093 complain_overflow_dont
, /* complain_on_overflow */
1094 bfd_elf_generic_reloc
, /* special_function */
1095 "R_SH_GOT_LOW16", /* name */
1096 FALSE
, /* partial_inplace */
1098 0x3fffc00, /* dst_mask */
1099 FALSE
), /* pcrel_offset */
1101 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1102 HOWTO (R_SH_GOT_MEDLOW16
, /* type */
1103 16, /* rightshift */
1104 2, /* size (0 = byte, 1 = short, 2 = long) */
1106 FALSE
, /* pc_relative */
1108 complain_overflow_dont
, /* complain_on_overflow */
1109 bfd_elf_generic_reloc
, /* special_function */
1110 "R_SH_GOT_MEDLOW16", /* name */
1111 FALSE
, /* partial_inplace */
1113 0x3fffc00, /* dst_mask */
1114 FALSE
), /* pcrel_offset */
1116 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1117 HOWTO (R_SH_GOT_MEDHI16
, /* type */
1118 32, /* rightshift */
1119 2, /* size (0 = byte, 1 = short, 2 = long) */
1121 FALSE
, /* pc_relative */
1123 complain_overflow_dont
, /* complain_on_overflow */
1124 bfd_elf_generic_reloc
, /* special_function */
1125 "R_SH_GOT_MEDHI16", /* name */
1126 FALSE
, /* partial_inplace */
1128 0x3fffc00, /* dst_mask */
1129 FALSE
), /* pcrel_offset */
1131 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1132 HOWTO (R_SH_GOT_HI16
, /* type */
1133 48, /* rightshift */
1134 2, /* size (0 = byte, 1 = short, 2 = long) */
1136 FALSE
, /* pc_relative */
1138 complain_overflow_dont
, /* complain_on_overflow */
1139 bfd_elf_generic_reloc
, /* special_function */
1140 "R_SH_GOT_HI16", /* name */
1141 FALSE
, /* partial_inplace */
1143 0x3fffc00, /* dst_mask */
1144 FALSE
), /* pcrel_offset */
1146 /* Used in MOVI and SHORI (x & 65536). */
1147 HOWTO (R_SH_GOTPLT_LOW16
, /* type */
1149 2, /* size (0 = byte, 1 = short, 2 = long) */
1151 FALSE
, /* pc_relative */
1153 complain_overflow_dont
, /* complain_on_overflow */
1154 bfd_elf_generic_reloc
, /* special_function */
1155 "R_SH_GOTPLT_LOW16", /* name */
1156 FALSE
, /* partial_inplace */
1158 0x3fffc00, /* dst_mask */
1159 FALSE
), /* pcrel_offset */
1161 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1162 HOWTO (R_SH_GOTPLT_MEDLOW16
, /* type */
1163 16, /* rightshift */
1164 2, /* size (0 = byte, 1 = short, 2 = long) */
1166 FALSE
, /* pc_relative */
1168 complain_overflow_dont
, /* complain_on_overflow */
1169 bfd_elf_generic_reloc
, /* special_function */
1170 "R_SH_GOTPLT_MEDLOW16", /* name */
1171 FALSE
, /* partial_inplace */
1173 0x3fffc00, /* dst_mask */
1174 FALSE
), /* pcrel_offset */
1176 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1177 HOWTO (R_SH_GOTPLT_MEDHI16
, /* type */
1178 32, /* rightshift */
1179 2, /* size (0 = byte, 1 = short, 2 = long) */
1181 FALSE
, /* pc_relative */
1183 complain_overflow_dont
, /* complain_on_overflow */
1184 bfd_elf_generic_reloc
, /* special_function */
1185 "R_SH_GOTPLT_MEDHI16", /* name */
1186 FALSE
, /* partial_inplace */
1188 0x3fffc00, /* dst_mask */
1189 FALSE
), /* pcrel_offset */
1191 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1192 HOWTO (R_SH_GOTPLT_HI16
, /* type */
1193 48, /* rightshift */
1194 2, /* size (0 = byte, 1 = short, 2 = long) */
1196 FALSE
, /* pc_relative */
1198 complain_overflow_dont
, /* complain_on_overflow */
1199 bfd_elf_generic_reloc
, /* special_function */
1200 "R_SH_GOTPLT_HI16", /* name */
1201 FALSE
, /* partial_inplace */
1203 0x3fffc00, /* dst_mask */
1204 FALSE
), /* pcrel_offset */
1206 /* Used in MOVI and SHORI (x & 65536). */
1207 HOWTO (R_SH_PLT_LOW16
, /* type */
1209 2, /* size (0 = byte, 1 = short, 2 = long) */
1211 TRUE
, /* pc_relative */
1213 complain_overflow_dont
, /* complain_on_overflow */
1214 bfd_elf_generic_reloc
, /* special_function */
1215 "R_SH_PLT_LOW16", /* name */
1216 FALSE
, /* partial_inplace */
1218 0x3fffc00, /* dst_mask */
1219 TRUE
), /* pcrel_offset */
1221 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1222 HOWTO (R_SH_PLT_MEDLOW16
, /* type */
1223 16, /* rightshift */
1224 2, /* size (0 = byte, 1 = short, 2 = long) */
1226 TRUE
, /* pc_relative */
1228 complain_overflow_dont
, /* complain_on_overflow */
1229 bfd_elf_generic_reloc
, /* special_function */
1230 "R_SH_PLT_MEDLOW16", /* name */
1231 FALSE
, /* partial_inplace */
1233 0x3fffc00, /* dst_mask */
1234 TRUE
), /* pcrel_offset */
1236 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1237 HOWTO (R_SH_PLT_MEDHI16
, /* type */
1238 32, /* rightshift */
1239 2, /* size (0 = byte, 1 = short, 2 = long) */
1241 TRUE
, /* pc_relative */
1243 complain_overflow_dont
, /* complain_on_overflow */
1244 bfd_elf_generic_reloc
, /* special_function */
1245 "R_SH_PLT_MEDHI16", /* name */
1246 FALSE
, /* partial_inplace */
1248 0x3fffc00, /* dst_mask */
1249 TRUE
), /* pcrel_offset */
1251 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1252 HOWTO (R_SH_PLT_HI16
, /* type */
1253 48, /* rightshift */
1254 2, /* size (0 = byte, 1 = short, 2 = long) */
1256 TRUE
, /* pc_relative */
1258 complain_overflow_dont
, /* complain_on_overflow */
1259 bfd_elf_generic_reloc
, /* special_function */
1260 "R_SH_PLT_HI16", /* name */
1261 FALSE
, /* partial_inplace */
1263 0x3fffc00, /* dst_mask */
1264 TRUE
), /* pcrel_offset */
1266 /* Used in MOVI and SHORI (x & 65536). */
1267 HOWTO (R_SH_GOTOFF_LOW16
, /* type */
1269 2, /* size (0 = byte, 1 = short, 2 = long) */
1271 FALSE
, /* pc_relative */
1273 complain_overflow_dont
, /* complain_on_overflow */
1274 bfd_elf_generic_reloc
, /* special_function */
1275 "R_SH_GOTOFF_LOW16", /* name */
1276 FALSE
, /* partial_inplace */
1278 0x3fffc00, /* dst_mask */
1279 FALSE
), /* pcrel_offset */
1281 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1282 HOWTO (R_SH_GOTOFF_MEDLOW16
, /* type */
1283 16, /* rightshift */
1284 2, /* size (0 = byte, 1 = short, 2 = long) */
1286 FALSE
, /* pc_relative */
1288 complain_overflow_dont
, /* complain_on_overflow */
1289 bfd_elf_generic_reloc
, /* special_function */
1290 "R_SH_GOTOFF_MEDLOW16", /* name */
1291 FALSE
, /* partial_inplace */
1293 0x3fffc00, /* dst_mask */
1294 FALSE
), /* pcrel_offset */
1296 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1297 HOWTO (R_SH_GOTOFF_MEDHI16
, /* type */
1298 32, /* rightshift */
1299 2, /* size (0 = byte, 1 = short, 2 = long) */
1301 FALSE
, /* pc_relative */
1303 complain_overflow_dont
, /* complain_on_overflow */
1304 bfd_elf_generic_reloc
, /* special_function */
1305 "R_SH_GOTOFF_MEDHI16", /* name */
1306 FALSE
, /* partial_inplace */
1308 0x3fffc00, /* dst_mask */
1309 FALSE
), /* pcrel_offset */
1311 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1312 HOWTO (R_SH_GOTOFF_HI16
, /* type */
1313 48, /* rightshift */
1314 2, /* size (0 = byte, 1 = short, 2 = long) */
1316 FALSE
, /* pc_relative */
1318 complain_overflow_dont
, /* complain_on_overflow */
1319 bfd_elf_generic_reloc
, /* special_function */
1320 "R_SH_GOTOFF_HI16", /* name */
1321 FALSE
, /* partial_inplace */
1323 0x3fffc00, /* dst_mask */
1324 FALSE
), /* pcrel_offset */
1326 /* Used in MOVI and SHORI (x & 65536). */
1327 HOWTO (R_SH_GOTPC_LOW16
, /* type */
1329 2, /* size (0 = byte, 1 = short, 2 = long) */
1331 TRUE
, /* pc_relative */
1333 complain_overflow_dont
, /* complain_on_overflow */
1334 bfd_elf_generic_reloc
, /* special_function */
1335 "R_SH_GOTPC_LOW16", /* name */
1336 FALSE
, /* partial_inplace */
1338 0x3fffc00, /* dst_mask */
1339 TRUE
), /* pcrel_offset */
1341 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1342 HOWTO (R_SH_GOTPC_MEDLOW16
, /* type */
1343 16, /* rightshift */
1344 2, /* size (0 = byte, 1 = short, 2 = long) */
1346 TRUE
, /* pc_relative */
1348 complain_overflow_dont
, /* complain_on_overflow */
1349 bfd_elf_generic_reloc
, /* special_function */
1350 "R_SH_GOTPC_MEDLOW16", /* name */
1351 FALSE
, /* partial_inplace */
1353 0x3fffc00, /* dst_mask */
1354 TRUE
), /* pcrel_offset */
1356 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1357 HOWTO (R_SH_GOTPC_MEDHI16
, /* type */
1358 32, /* rightshift */
1359 2, /* size (0 = byte, 1 = short, 2 = long) */
1361 TRUE
, /* pc_relative */
1363 complain_overflow_dont
, /* complain_on_overflow */
1364 bfd_elf_generic_reloc
, /* special_function */
1365 "R_SH_GOTPC_MEDHI16", /* name */
1366 FALSE
, /* partial_inplace */
1368 0x3fffc00, /* dst_mask */
1369 TRUE
), /* pcrel_offset */
1371 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1372 HOWTO (R_SH_GOTPC_HI16
, /* type */
1373 48, /* rightshift */
1374 2, /* size (0 = byte, 1 = short, 2 = long) */
1376 TRUE
, /* pc_relative */
1378 complain_overflow_dont
, /* complain_on_overflow */
1379 bfd_elf_generic_reloc
, /* special_function */
1380 "R_SH_GOTPC_HI16", /* name */
1381 FALSE
, /* partial_inplace */
1383 0x3fffc00, /* dst_mask */
1384 TRUE
), /* pcrel_offset */
1386 /* Used in LD.L, FLD.S et al. */
1387 HOWTO (R_SH_GOT10BY4
, /* type */
1389 2, /* size (0 = byte, 1 = short, 2 = long) */
1391 FALSE
, /* pc_relative */
1393 complain_overflow_signed
, /* complain_on_overflow */
1394 bfd_elf_generic_reloc
, /* special_function */
1395 "R_SH_GOT10BY4", /* name */
1396 FALSE
, /* partial_inplace */
1398 0xffc00, /* dst_mask */
1399 FALSE
), /* pcrel_offset */
1401 /* Used in LD.L, FLD.S et al. */
1402 HOWTO (R_SH_GOTPLT10BY4
, /* type */
1404 2, /* size (0 = byte, 1 = short, 2 = long) */
1406 FALSE
, /* pc_relative */
1408 complain_overflow_signed
, /* complain_on_overflow */
1409 bfd_elf_generic_reloc
, /* special_function */
1410 "R_SH_GOTPLT10BY4", /* name */
1411 FALSE
, /* partial_inplace */
1413 0xffc00, /* dst_mask */
1414 FALSE
), /* pcrel_offset */
1416 /* Used in FLD.D, FST.P et al. */
1417 HOWTO (R_SH_GOT10BY8
, /* type */
1419 2, /* size (0 = byte, 1 = short, 2 = long) */
1421 FALSE
, /* pc_relative */
1423 complain_overflow_signed
, /* complain_on_overflow */
1424 bfd_elf_generic_reloc
, /* special_function */
1425 "R_SH_GOT10BY8", /* name */
1426 FALSE
, /* partial_inplace */
1428 0xffc00, /* dst_mask */
1429 FALSE
), /* pcrel_offset */
1431 /* Used in FLD.D, FST.P et al. */
1432 HOWTO (R_SH_GOTPLT10BY8
, /* type */
1434 2, /* size (0 = byte, 1 = short, 2 = long) */
1436 FALSE
, /* pc_relative */
1438 complain_overflow_signed
, /* complain_on_overflow */
1439 bfd_elf_generic_reloc
, /* special_function */
1440 "R_SH_GOTPLT10BY8", /* name */
1441 FALSE
, /* partial_inplace */
1443 0xffc00, /* dst_mask */
1444 FALSE
), /* pcrel_offset */
1446 HOWTO (R_SH_COPY64
, /* type */
1448 4, /* size (0 = byte, 1 = short, 2 = long) */
1450 FALSE
, /* pc_relative */
1452 complain_overflow_dont
, /* complain_on_overflow */
1453 bfd_elf_generic_reloc
, /* special_function */
1454 "R_SH_COPY64", /* name */
1455 FALSE
, /* partial_inplace */
1457 ((bfd_vma
) 0) - 1, /* dst_mask */
1458 FALSE
), /* pcrel_offset */
1460 HOWTO (R_SH_GLOB_DAT64
, /* type */
1462 4, /* size (0 = byte, 1 = short, 2 = long) */
1464 FALSE
, /* pc_relative */
1466 complain_overflow_dont
, /* complain_on_overflow */
1467 bfd_elf_generic_reloc
, /* special_function */
1468 "R_SH_GLOB_DAT64", /* name */
1469 FALSE
, /* partial_inplace */
1471 ((bfd_vma
) 0) - 1, /* dst_mask */
1472 FALSE
), /* pcrel_offset */
1474 HOWTO (R_SH_JMP_SLOT64
, /* type */
1476 4, /* size (0 = byte, 1 = short, 2 = long) */
1478 FALSE
, /* pc_relative */
1480 complain_overflow_dont
, /* complain_on_overflow */
1481 bfd_elf_generic_reloc
, /* special_function */
1482 "R_SH_JMP_SLOT64", /* name */
1483 FALSE
, /* partial_inplace */
1485 ((bfd_vma
) 0) - 1, /* dst_mask */
1486 FALSE
), /* pcrel_offset */
1488 HOWTO (R_SH_RELATIVE64
, /* type */
1490 4, /* size (0 = byte, 1 = short, 2 = long) */
1492 FALSE
, /* pc_relative */
1494 complain_overflow_dont
, /* complain_on_overflow */
1495 bfd_elf_generic_reloc
, /* special_function */
1496 "R_SH_RELATIVE64", /* name */
1497 FALSE
, /* partial_inplace */
1499 ((bfd_vma
) 0) - 1, /* dst_mask */
1500 FALSE
), /* pcrel_offset */
1548 /* Relocations for SHmedia code. None of these are partial_inplace or
1549 use the field being relocated (except R_SH_PT_16). */
1551 /* The assembler will generate this reloc before a block of SHmedia
1552 instructions. A section should be processed as assuming it contains
1553 data, unless this reloc is seen. Note that a block of SHcompact
1554 instructions are instead preceded by R_SH_CODE.
1555 This is currently not implemented, but should be used for SHmedia
1556 linker relaxation. */
1557 HOWTO (R_SH_SHMEDIA_CODE
, /* type */
1559 1, /* size (0 = byte, 1 = short, 2 = long) */
1561 FALSE
, /* pc_relative */
1563 complain_overflow_unsigned
, /* complain_on_overflow */
1564 sh_elf_ignore_reloc
, /* special_function */
1565 "R_SH_SHMEDIA_CODE", /* name */
1566 FALSE
, /* partial_inplace */
1569 FALSE
), /* pcrel_offset */
1571 /* The assembler will generate this reloc at a PTA or PTB instruction,
1572 and the linker checks the right type of target, or changes a PTA to a
1573 PTB, if the original insn was PT. */
1574 HOWTO (R_SH_PT_16
, /* type */
1576 2, /* size (0 = byte, 1 = short, 2 = long) */
1578 TRUE
, /* pc_relative */
1580 complain_overflow_signed
, /* complain_on_overflow */
1581 bfd_elf_generic_reloc
, /* special_function */
1582 "R_SH_PT_16", /* name */
1583 FALSE
, /* partial_inplace */
1585 0x3fffc00, /* dst_mask */
1586 TRUE
), /* pcrel_offset */
1588 /* Used in unexpanded MOVI. */
1589 HOWTO (R_SH_IMMS16
, /* type */
1591 2, /* size (0 = byte, 1 = short, 2 = long) */
1593 FALSE
, /* pc_relative */
1595 complain_overflow_signed
, /* complain_on_overflow */
1596 bfd_elf_generic_reloc
, /* special_function */
1597 "R_SH_IMMS16", /* name */
1598 FALSE
, /* partial_inplace */
1600 0x3fffc00, /* dst_mask */
1601 FALSE
), /* pcrel_offset */
1603 /* Used in SHORI. */
1604 HOWTO (R_SH_IMMU16
, /* type */
1606 2, /* size (0 = byte, 1 = short, 2 = long) */
1608 FALSE
, /* pc_relative */
1610 complain_overflow_unsigned
, /* complain_on_overflow */
1611 bfd_elf_generic_reloc
, /* special_function */
1612 "R_SH_IMMU16", /* name */
1613 FALSE
, /* partial_inplace */
1615 0x3fffc00, /* dst_mask */
1616 FALSE
), /* pcrel_offset */
1618 /* Used in MOVI and SHORI (x & 65536). */
1619 HOWTO (R_SH_IMM_LOW16
, /* type */
1621 2, /* size (0 = byte, 1 = short, 2 = long) */
1623 FALSE
, /* pc_relative */
1625 complain_overflow_dont
, /* complain_on_overflow */
1626 bfd_elf_generic_reloc
, /* special_function */
1627 "R_SH_IMM_LOW16", /* name */
1628 FALSE
, /* partial_inplace */
1630 0x3fffc00, /* dst_mask */
1631 FALSE
), /* pcrel_offset */
1633 /* Used in MOVI and SHORI ((x - $) & 65536). */
1634 HOWTO (R_SH_IMM_LOW16_PCREL
, /* type */
1636 2, /* size (0 = byte, 1 = short, 2 = long) */
1638 TRUE
, /* pc_relative */
1640 complain_overflow_dont
, /* complain_on_overflow */
1641 bfd_elf_generic_reloc
, /* special_function */
1642 "R_SH_IMM_LOW16_PCREL", /* name */
1643 FALSE
, /* partial_inplace */
1645 0x3fffc00, /* dst_mask */
1646 TRUE
), /* pcrel_offset */
1648 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1649 HOWTO (R_SH_IMM_MEDLOW16
, /* type */
1650 16, /* rightshift */
1651 2, /* size (0 = byte, 1 = short, 2 = long) */
1653 FALSE
, /* pc_relative */
1655 complain_overflow_dont
, /* complain_on_overflow */
1656 bfd_elf_generic_reloc
, /* special_function */
1657 "R_SH_IMM_MEDLOW16", /* name */
1658 FALSE
, /* partial_inplace */
1660 0x3fffc00, /* dst_mask */
1661 FALSE
), /* pcrel_offset */
1663 /* Used in MOVI and SHORI (((x - $) >> 16) & 65536). */
1664 HOWTO (R_SH_IMM_MEDLOW16_PCREL
, /* type */
1665 16, /* rightshift */
1666 2, /* size (0 = byte, 1 = short, 2 = long) */
1668 TRUE
, /* pc_relative */
1670 complain_overflow_dont
, /* complain_on_overflow */
1671 bfd_elf_generic_reloc
, /* special_function */
1672 "R_SH_IMM_MEDLOW16_PCREL", /* name */
1673 FALSE
, /* partial_inplace */
1675 0x3fffc00, /* dst_mask */
1676 TRUE
), /* pcrel_offset */
1678 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1679 HOWTO (R_SH_IMM_MEDHI16
, /* type */
1680 32, /* rightshift */
1681 2, /* size (0 = byte, 1 = short, 2 = long) */
1683 FALSE
, /* pc_relative */
1685 complain_overflow_dont
, /* complain_on_overflow */
1686 bfd_elf_generic_reloc
, /* special_function */
1687 "R_SH_IMM_MEDHI16", /* name */
1688 FALSE
, /* partial_inplace */
1690 0x3fffc00, /* dst_mask */
1691 FALSE
), /* pcrel_offset */
1693 /* Used in MOVI and SHORI (((x - $) >> 32) & 65536). */
1694 HOWTO (R_SH_IMM_MEDHI16_PCREL
, /* type */
1695 32, /* rightshift */
1696 2, /* size (0 = byte, 1 = short, 2 = long) */
1698 TRUE
, /* pc_relative */
1700 complain_overflow_dont
, /* complain_on_overflow */
1701 bfd_elf_generic_reloc
, /* special_function */
1702 "R_SH_IMM_MEDHI16_PCREL", /* name */
1703 FALSE
, /* partial_inplace */
1705 0x3fffc00, /* dst_mask */
1706 TRUE
), /* pcrel_offset */
1708 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1709 HOWTO (R_SH_IMM_HI16
, /* type */
1710 48, /* rightshift */
1711 2, /* size (0 = byte, 1 = short, 2 = long) */
1713 FALSE
, /* pc_relative */
1715 complain_overflow_dont
, /* complain_on_overflow */
1716 bfd_elf_generic_reloc
, /* special_function */
1717 "R_SH_IMM_HI16", /* name */
1718 FALSE
, /* partial_inplace */
1720 0x3fffc00, /* dst_mask */
1721 FALSE
), /* pcrel_offset */
1723 /* Used in MOVI and SHORI (((x - $) >> 48) & 65536). */
1724 HOWTO (R_SH_IMM_HI16_PCREL
, /* type */
1725 48, /* rightshift */
1726 2, /* size (0 = byte, 1 = short, 2 = long) */
1728 TRUE
, /* pc_relative */
1730 complain_overflow_dont
, /* complain_on_overflow */
1731 bfd_elf_generic_reloc
, /* special_function */
1732 "R_SH_IMM_HI16_PCREL", /* name */
1733 FALSE
, /* partial_inplace */
1735 0x3fffc00, /* dst_mask */
1736 TRUE
), /* pcrel_offset */
1738 /* For the .uaquad pseudo. */
1739 HOWTO (R_SH_64
, /* type */
1741 4, /* size (0 = byte, 1 = short, 2 = long) */
1743 FALSE
, /* pc_relative */
1745 complain_overflow_dont
, /* complain_on_overflow */
1746 bfd_elf_generic_reloc
, /* special_function */
1747 "R_SH_64", /* name */
1748 FALSE
, /* partial_inplace */
1750 ((bfd_vma
) 0) - 1, /* dst_mask */
1751 FALSE
), /* pcrel_offset */
1753 /* For the .uaquad pseudo, (x - $). */
1754 HOWTO (R_SH_64_PCREL
, /* type */
1755 48, /* rightshift */
1756 2, /* size (0 = byte, 1 = short, 2 = long) */
1758 TRUE
, /* pc_relative */
1760 complain_overflow_dont
, /* complain_on_overflow */
1761 bfd_elf_generic_reloc
, /* special_function */
1762 "R_SH_64_PCREL", /* name */
1763 FALSE
, /* partial_inplace */
1765 ((bfd_vma
) 0) - 1, /* dst_mask */
1766 TRUE
), /* pcrel_offset */
1771 static bfd_reloc_status_type
1772 sh_elf_reloc_loop (int r_type ATTRIBUTE_UNUSED
, bfd
*input_bfd
,
1773 asection
*input_section
, bfd_byte
*contents
,
1774 bfd_vma addr
, asection
*symbol_section
,
1775 bfd_vma start
, bfd_vma end
)
1777 static bfd_vma last_addr
;
1778 static asection
*last_symbol_section
;
1779 bfd_byte
*start_ptr
, *ptr
, *last_ptr
;
1784 /* Sanity check the address. */
1785 if (addr
> bfd_get_section_limit (input_bfd
, input_section
))
1786 return bfd_reloc_outofrange
;
1788 /* We require the start and end relocations to be processed consecutively -
1789 although we allow then to be processed forwards or backwards. */
1793 last_symbol_section
= symbol_section
;
1794 return bfd_reloc_ok
;
1796 if (last_addr
!= addr
)
1800 if (! symbol_section
|| last_symbol_section
!= symbol_section
|| end
< start
)
1801 return bfd_reloc_outofrange
;
1803 /* Get the symbol_section contents. */
1804 if (symbol_section
!= input_section
)
1806 if (elf_section_data (symbol_section
)->this_hdr
.contents
!= NULL
)
1807 contents
= elf_section_data (symbol_section
)->this_hdr
.contents
;
1810 if (!bfd_malloc_and_get_section (input_bfd
, symbol_section
,
1813 if (contents
!= NULL
)
1815 return bfd_reloc_outofrange
;
1819 #define IS_PPI(PTR) ((bfd_get_16 (input_bfd, (PTR)) & 0xfc00) == 0xf800)
1820 start_ptr
= contents
+ start
;
1821 for (cum_diff
= -6, ptr
= contents
+ end
; cum_diff
< 0 && ptr
> start_ptr
;)
1823 for (last_ptr
= ptr
, ptr
-= 4; ptr
>= start_ptr
&& IS_PPI (ptr
);)
1826 diff
= (last_ptr
- ptr
) >> 1;
1827 cum_diff
+= diff
& 1;
1830 /* Calculate the start / end values to load into rs / re minus four -
1831 so that will cancel out the four we would otherwise have to add to
1832 addr to get the value to subtract in order to get relative addressing. */
1836 end
= (ptr
+ cum_diff
* 2) - contents
;
1840 bfd_vma start0
= start
- 4;
1842 while (start0
&& IS_PPI (contents
+ start0
))
1844 start0
= start
- 2 - ((start
- start0
) & 2);
1845 start
= start0
- cum_diff
- 2;
1849 if (contents
!= NULL
1850 && elf_section_data (symbol_section
)->this_hdr
.contents
!= contents
)
1853 insn
= bfd_get_16 (input_bfd
, contents
+ addr
);
1855 x
= (insn
& 0x200 ? end
: start
) - addr
;
1856 if (input_section
!= symbol_section
)
1857 x
+= ((symbol_section
->output_section
->vma
+ symbol_section
->output_offset
)
1858 - (input_section
->output_section
->vma
1859 + input_section
->output_offset
));
1861 if (x
< -128 || x
> 127)
1862 return bfd_reloc_overflow
;
1864 x
= (insn
& ~0xff) | (x
& 0xff);
1865 bfd_put_16 (input_bfd
, (bfd_vma
) x
, contents
+ addr
);
1867 return bfd_reloc_ok
;
1870 /* This function is used for normal relocs. This used to be like the COFF
1871 function, and is almost certainly incorrect for other ELF targets. */
1873 static bfd_reloc_status_type
1874 sh_elf_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol_in
,
1875 void *data
, asection
*input_section
, bfd
*output_bfd
,
1876 char **error_message ATTRIBUTE_UNUSED
)
1880 enum elf_sh_reloc_type r_type
;
1881 bfd_vma addr
= reloc_entry
->address
;
1882 bfd_byte
*hit_data
= addr
+ (bfd_byte
*) data
;
1884 r_type
= (enum elf_sh_reloc_type
) reloc_entry
->howto
->type
;
1886 if (output_bfd
!= NULL
)
1888 /* Partial linking--do nothing. */
1889 reloc_entry
->address
+= input_section
->output_offset
;
1890 return bfd_reloc_ok
;
1893 /* Almost all relocs have to do with relaxing. If any work must be
1894 done for them, it has been done in sh_relax_section. */
1895 if (r_type
== R_SH_IND12W
&& (symbol_in
->flags
& BSF_LOCAL
) != 0)
1896 return bfd_reloc_ok
;
1898 if (symbol_in
!= NULL
1899 && bfd_is_und_section (symbol_in
->section
))
1900 return bfd_reloc_undefined
;
1902 if (bfd_is_com_section (symbol_in
->section
))
1905 sym_value
= (symbol_in
->value
+
1906 symbol_in
->section
->output_section
->vma
+
1907 symbol_in
->section
->output_offset
);
1912 insn
= bfd_get_32 (abfd
, hit_data
);
1913 insn
+= sym_value
+ reloc_entry
->addend
;
1914 bfd_put_32 (abfd
, (bfd_vma
) insn
, hit_data
);
1917 insn
= bfd_get_16 (abfd
, hit_data
);
1918 sym_value
+= reloc_entry
->addend
;
1919 sym_value
-= (input_section
->output_section
->vma
1920 + input_section
->output_offset
1923 sym_value
+= (insn
& 0xfff) << 1;
1925 sym_value
-= 0x1000;
1926 insn
= (insn
& 0xf000) | (sym_value
& 0xfff);
1927 bfd_put_16 (abfd
, (bfd_vma
) insn
, hit_data
);
1928 if (sym_value
< (bfd_vma
) -0x1000 || sym_value
>= 0x1000)
1929 return bfd_reloc_overflow
;
1936 return bfd_reloc_ok
;
1939 /* This function is used for relocs which are only used for relaxing,
1940 which the linker should otherwise ignore. */
1942 static bfd_reloc_status_type
1943 sh_elf_ignore_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
1944 asymbol
*symbol ATTRIBUTE_UNUSED
,
1945 void *data ATTRIBUTE_UNUSED
, asection
*input_section
,
1947 char **error_message ATTRIBUTE_UNUSED
)
1949 if (output_bfd
!= NULL
)
1950 reloc_entry
->address
+= input_section
->output_offset
;
1951 return bfd_reloc_ok
;
1954 /* This structure is used to map BFD reloc codes to SH ELF relocs. */
1956 struct elf_reloc_map
1958 bfd_reloc_code_real_type bfd_reloc_val
;
1959 unsigned char elf_reloc_val
;
1962 /* An array mapping BFD reloc codes to SH ELF relocs. */
1964 static const struct elf_reloc_map sh_reloc_map
[] =
1966 { BFD_RELOC_NONE
, R_SH_NONE
},
1967 { BFD_RELOC_32
, R_SH_DIR32
},
1968 { BFD_RELOC_16
, R_SH_DIR16
},
1969 { BFD_RELOC_8
, R_SH_DIR8
},
1970 { BFD_RELOC_CTOR
, R_SH_DIR32
},
1971 { BFD_RELOC_32_PCREL
, R_SH_REL32
},
1972 { BFD_RELOC_SH_PCDISP8BY2
, R_SH_DIR8WPN
},
1973 { BFD_RELOC_SH_PCDISP12BY2
, R_SH_IND12W
},
1974 { BFD_RELOC_SH_PCRELIMM8BY2
, R_SH_DIR8WPZ
},
1975 { BFD_RELOC_SH_PCRELIMM8BY4
, R_SH_DIR8WPL
},
1976 { BFD_RELOC_8_PCREL
, R_SH_SWITCH8
},
1977 { BFD_RELOC_SH_SWITCH16
, R_SH_SWITCH16
},
1978 { BFD_RELOC_SH_SWITCH32
, R_SH_SWITCH32
},
1979 { BFD_RELOC_SH_USES
, R_SH_USES
},
1980 { BFD_RELOC_SH_COUNT
, R_SH_COUNT
},
1981 { BFD_RELOC_SH_ALIGN
, R_SH_ALIGN
},
1982 { BFD_RELOC_SH_CODE
, R_SH_CODE
},
1983 { BFD_RELOC_SH_DATA
, R_SH_DATA
},
1984 { BFD_RELOC_SH_LABEL
, R_SH_LABEL
},
1985 { BFD_RELOC_VTABLE_INHERIT
, R_SH_GNU_VTINHERIT
},
1986 { BFD_RELOC_VTABLE_ENTRY
, R_SH_GNU_VTENTRY
},
1987 { BFD_RELOC_SH_LOOP_START
, R_SH_LOOP_START
},
1988 { BFD_RELOC_SH_LOOP_END
, R_SH_LOOP_END
},
1989 { BFD_RELOC_SH_TLS_GD_32
, R_SH_TLS_GD_32
},
1990 { BFD_RELOC_SH_TLS_LD_32
, R_SH_TLS_LD_32
},
1991 { BFD_RELOC_SH_TLS_LDO_32
, R_SH_TLS_LDO_32
},
1992 { BFD_RELOC_SH_TLS_IE_32
, R_SH_TLS_IE_32
},
1993 { BFD_RELOC_SH_TLS_LE_32
, R_SH_TLS_LE_32
},
1994 { BFD_RELOC_SH_TLS_DTPMOD32
, R_SH_TLS_DTPMOD32
},
1995 { BFD_RELOC_SH_TLS_DTPOFF32
, R_SH_TLS_DTPOFF32
},
1996 { BFD_RELOC_SH_TLS_TPOFF32
, R_SH_TLS_TPOFF32
},
1997 { BFD_RELOC_32_GOT_PCREL
, R_SH_GOT32
},
1998 { BFD_RELOC_32_PLT_PCREL
, R_SH_PLT32
},
1999 { BFD_RELOC_SH_COPY
, R_SH_COPY
},
2000 { BFD_RELOC_SH_GLOB_DAT
, R_SH_GLOB_DAT
},
2001 { BFD_RELOC_SH_JMP_SLOT
, R_SH_JMP_SLOT
},
2002 { BFD_RELOC_SH_RELATIVE
, R_SH_RELATIVE
},
2003 { BFD_RELOC_32_GOTOFF
, R_SH_GOTOFF
},
2004 { BFD_RELOC_SH_GOTPC
, R_SH_GOTPC
},
2005 { BFD_RELOC_SH_GOTPLT32
, R_SH_GOTPLT32
},
2006 #ifdef INCLUDE_SHMEDIA
2007 { BFD_RELOC_SH_GOT_LOW16
, R_SH_GOT_LOW16
},
2008 { BFD_RELOC_SH_GOT_MEDLOW16
, R_SH_GOT_MEDLOW16
},
2009 { BFD_RELOC_SH_GOT_MEDHI16
, R_SH_GOT_MEDHI16
},
2010 { BFD_RELOC_SH_GOT_HI16
, R_SH_GOT_HI16
},
2011 { BFD_RELOC_SH_GOTPLT_LOW16
, R_SH_GOTPLT_LOW16
},
2012 { BFD_RELOC_SH_GOTPLT_MEDLOW16
, R_SH_GOTPLT_MEDLOW16
},
2013 { BFD_RELOC_SH_GOTPLT_MEDHI16
, R_SH_GOTPLT_MEDHI16
},
2014 { BFD_RELOC_SH_GOTPLT_HI16
, R_SH_GOTPLT_HI16
},
2015 { BFD_RELOC_SH_PLT_LOW16
, R_SH_PLT_LOW16
},
2016 { BFD_RELOC_SH_PLT_MEDLOW16
, R_SH_PLT_MEDLOW16
},
2017 { BFD_RELOC_SH_PLT_MEDHI16
, R_SH_PLT_MEDHI16
},
2018 { BFD_RELOC_SH_PLT_HI16
, R_SH_PLT_HI16
},
2019 { BFD_RELOC_SH_GOTOFF_LOW16
, R_SH_GOTOFF_LOW16
},
2020 { BFD_RELOC_SH_GOTOFF_MEDLOW16
, R_SH_GOTOFF_MEDLOW16
},
2021 { BFD_RELOC_SH_GOTOFF_MEDHI16
, R_SH_GOTOFF_MEDHI16
},
2022 { BFD_RELOC_SH_GOTOFF_HI16
, R_SH_GOTOFF_HI16
},
2023 { BFD_RELOC_SH_GOTPC_LOW16
, R_SH_GOTPC_LOW16
},
2024 { BFD_RELOC_SH_GOTPC_MEDLOW16
, R_SH_GOTPC_MEDLOW16
},
2025 { BFD_RELOC_SH_GOTPC_MEDHI16
, R_SH_GOTPC_MEDHI16
},
2026 { BFD_RELOC_SH_GOTPC_HI16
, R_SH_GOTPC_HI16
},
2027 { BFD_RELOC_SH_COPY64
, R_SH_COPY64
},
2028 { BFD_RELOC_SH_GLOB_DAT64
, R_SH_GLOB_DAT64
},
2029 { BFD_RELOC_SH_JMP_SLOT64
, R_SH_JMP_SLOT64
},
2030 { BFD_RELOC_SH_RELATIVE64
, R_SH_RELATIVE64
},
2031 { BFD_RELOC_SH_GOT10BY4
, R_SH_GOT10BY4
},
2032 { BFD_RELOC_SH_GOT10BY8
, R_SH_GOT10BY8
},
2033 { BFD_RELOC_SH_GOTPLT10BY4
, R_SH_GOTPLT10BY4
},
2034 { BFD_RELOC_SH_GOTPLT10BY8
, R_SH_GOTPLT10BY8
},
2035 { BFD_RELOC_SH_PT_16
, R_SH_PT_16
},
2036 { BFD_RELOC_SH_SHMEDIA_CODE
, R_SH_SHMEDIA_CODE
},
2037 { BFD_RELOC_SH_IMMU5
, R_SH_DIR5U
},
2038 { BFD_RELOC_SH_IMMS6
, R_SH_DIR6S
},
2039 { BFD_RELOC_SH_IMMU6
, R_SH_DIR6U
},
2040 { BFD_RELOC_SH_IMMS10
, R_SH_DIR10S
},
2041 { BFD_RELOC_SH_IMMS10BY2
, R_SH_DIR10SW
},
2042 { BFD_RELOC_SH_IMMS10BY4
, R_SH_DIR10SL
},
2043 { BFD_RELOC_SH_IMMS10BY8
, R_SH_DIR10SQ
},
2044 { BFD_RELOC_SH_IMMS16
, R_SH_IMMS16
},
2045 { BFD_RELOC_SH_IMMU16
, R_SH_IMMU16
},
2046 { BFD_RELOC_SH_IMM_LOW16
, R_SH_IMM_LOW16
},
2047 { BFD_RELOC_SH_IMM_LOW16_PCREL
, R_SH_IMM_LOW16_PCREL
},
2048 { BFD_RELOC_SH_IMM_MEDLOW16
, R_SH_IMM_MEDLOW16
},
2049 { BFD_RELOC_SH_IMM_MEDLOW16_PCREL
, R_SH_IMM_MEDLOW16_PCREL
},
2050 { BFD_RELOC_SH_IMM_MEDHI16
, R_SH_IMM_MEDHI16
},
2051 { BFD_RELOC_SH_IMM_MEDHI16_PCREL
, R_SH_IMM_MEDHI16_PCREL
},
2052 { BFD_RELOC_SH_IMM_HI16
, R_SH_IMM_HI16
},
2053 { BFD_RELOC_SH_IMM_HI16_PCREL
, R_SH_IMM_HI16_PCREL
},
2054 { BFD_RELOC_64
, R_SH_64
},
2055 { BFD_RELOC_64_PCREL
, R_SH_64_PCREL
},
2056 #endif /* not INCLUDE_SHMEDIA */
2059 /* Given a BFD reloc code, return the howto structure for the
2060 corresponding SH ELf reloc. */
2062 static reloc_howto_type
*
2063 sh_elf_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2064 bfd_reloc_code_real_type code
)
2068 for (i
= 0; i
< sizeof (sh_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
2070 if (sh_reloc_map
[i
].bfd_reloc_val
== code
)
2071 return &sh_elf_howto_table
[(int) sh_reloc_map
[i
].elf_reloc_val
];
2077 /* Given an ELF reloc, fill in the howto field of a relent. */
2080 sh_elf_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
2081 Elf_Internal_Rela
*dst
)
2085 r
= ELF32_R_TYPE (dst
->r_info
);
2087 BFD_ASSERT (r
< (unsigned int) R_SH_max
);
2088 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC
|| r
> R_SH_LAST_INVALID_RELOC
);
2089 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_2
|| r
> R_SH_LAST_INVALID_RELOC_2
);
2090 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_3
|| r
> R_SH_LAST_INVALID_RELOC_3
);
2091 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_4
|| r
> R_SH_LAST_INVALID_RELOC_4
);
2092 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_5
|| r
> R_SH_LAST_INVALID_RELOC_5
);
2094 cache_ptr
->howto
= &sh_elf_howto_table
[r
];
2097 /* This function handles relaxing for SH ELF. See the corresponding
2098 function in coff-sh.c for a description of what this does. FIXME:
2099 There is a lot of duplication here between this code and the COFF
2100 specific code. The format of relocs and symbols is wound deeply
2101 into this code, but it would still be better if the duplication
2102 could be eliminated somehow. Note in particular that although both
2103 functions use symbols like R_SH_CODE, those symbols have different
2104 values; in coff-sh.c they come from include/coff/sh.h, whereas here
2105 they come from enum elf_sh_reloc_type in include/elf/sh.h. */
2108 sh_elf_relax_section (bfd
*abfd
, asection
*sec
,
2109 struct bfd_link_info
*link_info
, bfd_boolean
*again
)
2111 Elf_Internal_Shdr
*symtab_hdr
;
2112 Elf_Internal_Rela
*internal_relocs
;
2113 bfd_boolean have_code
;
2114 Elf_Internal_Rela
*irel
, *irelend
;
2115 bfd_byte
*contents
= NULL
;
2116 Elf_Internal_Sym
*isymbuf
= NULL
;
2120 if (link_info
->relocatable
2121 || (sec
->flags
& SEC_RELOC
) == 0
2122 || sec
->reloc_count
== 0)
2125 #ifdef INCLUDE_SHMEDIA
2126 if (elf_section_data (sec
)->this_hdr
.sh_flags
2127 & (SHF_SH5_ISA32
| SHF_SH5_ISA32_MIXED
))
2133 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2135 internal_relocs
= (_bfd_elf_link_read_relocs
2136 (abfd
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
2137 link_info
->keep_memory
));
2138 if (internal_relocs
== NULL
)
2143 irelend
= internal_relocs
+ sec
->reloc_count
;
2144 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2146 bfd_vma laddr
, paddr
, symval
;
2147 unsigned short insn
;
2148 Elf_Internal_Rela
*irelfn
, *irelscan
, *irelcount
;
2149 bfd_signed_vma foff
;
2151 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_CODE
)
2154 if (ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_USES
)
2157 /* Get the section contents. */
2158 if (contents
== NULL
)
2160 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2161 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2164 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
2169 /* The r_addend field of the R_SH_USES reloc will point us to
2170 the register load. The 4 is because the r_addend field is
2171 computed as though it were a jump offset, which are based
2172 from 4 bytes after the jump instruction. */
2173 laddr
= irel
->r_offset
+ 4 + irel
->r_addend
;
2174 if (laddr
>= sec
->size
)
2176 (*_bfd_error_handler
) (_("%B: 0x%lx: warning: bad R_SH_USES offset"),
2178 (unsigned long) irel
->r_offset
);
2181 insn
= bfd_get_16 (abfd
, contents
+ laddr
);
2183 /* If the instruction is not mov.l NN,rN, we don't know what to
2185 if ((insn
& 0xf000) != 0xd000)
2187 ((*_bfd_error_handler
)
2188 (_("%B: 0x%lx: warning: R_SH_USES points to unrecognized insn 0x%x"),
2189 abfd
, (unsigned long) irel
->r_offset
, insn
));
2193 /* Get the address from which the register is being loaded. The
2194 displacement in the mov.l instruction is quadrupled. It is a
2195 displacement from four bytes after the movl instruction, but,
2196 before adding in the PC address, two least significant bits
2197 of the PC are cleared. We assume that the section is aligned
2198 on a four byte boundary. */
2199 paddr
= insn
& 0xff;
2201 paddr
+= (laddr
+ 4) &~ (bfd_vma
) 3;
2202 if (paddr
>= sec
->size
)
2204 ((*_bfd_error_handler
)
2205 (_("%B: 0x%lx: warning: bad R_SH_USES load offset"),
2206 abfd
, (unsigned long) irel
->r_offset
));
2210 /* Get the reloc for the address from which the register is
2211 being loaded. This reloc will tell us which function is
2212 actually being called. */
2213 for (irelfn
= internal_relocs
; irelfn
< irelend
; irelfn
++)
2214 if (irelfn
->r_offset
== paddr
2215 && ELF32_R_TYPE (irelfn
->r_info
) == (int) R_SH_DIR32
)
2217 if (irelfn
>= irelend
)
2219 ((*_bfd_error_handler
)
2220 (_("%B: 0x%lx: warning: could not find expected reloc"),
2221 abfd
, (unsigned long) paddr
));
2225 /* Read this BFD's symbols if we haven't done so already. */
2226 if (isymbuf
== NULL
&& symtab_hdr
->sh_info
!= 0)
2228 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2229 if (isymbuf
== NULL
)
2230 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
2231 symtab_hdr
->sh_info
, 0,
2233 if (isymbuf
== NULL
)
2237 /* Get the value of the symbol referred to by the reloc. */
2238 if (ELF32_R_SYM (irelfn
->r_info
) < symtab_hdr
->sh_info
)
2240 /* A local symbol. */
2241 Elf_Internal_Sym
*isym
;
2243 isym
= isymbuf
+ ELF32_R_SYM (irelfn
->r_info
);
2245 != (unsigned int) _bfd_elf_section_from_bfd_section (abfd
, sec
))
2247 ((*_bfd_error_handler
)
2248 (_("%B: 0x%lx: warning: symbol in unexpected section"),
2249 abfd
, (unsigned long) paddr
));
2253 symval
= (isym
->st_value
2254 + sec
->output_section
->vma
2255 + sec
->output_offset
);
2260 struct elf_link_hash_entry
*h
;
2262 indx
= ELF32_R_SYM (irelfn
->r_info
) - symtab_hdr
->sh_info
;
2263 h
= elf_sym_hashes (abfd
)[indx
];
2264 BFD_ASSERT (h
!= NULL
);
2265 if (h
->root
.type
!= bfd_link_hash_defined
2266 && h
->root
.type
!= bfd_link_hash_defweak
)
2268 /* This appears to be a reference to an undefined
2269 symbol. Just ignore it--it will be caught by the
2270 regular reloc processing. */
2274 symval
= (h
->root
.u
.def
.value
2275 + h
->root
.u
.def
.section
->output_section
->vma
2276 + h
->root
.u
.def
.section
->output_offset
);
2279 symval
+= bfd_get_32 (abfd
, contents
+ paddr
);
2281 /* See if this function call can be shortened. */
2284 + sec
->output_section
->vma
2285 + sec
->output_offset
2287 if (foff
< -0x1000 || foff
>= 0x1000)
2289 /* After all that work, we can't shorten this function call. */
2293 /* Shorten the function call. */
2295 /* For simplicity of coding, we are going to modify the section
2296 contents, the section relocs, and the BFD symbol table. We
2297 must tell the rest of the code not to free up this
2298 information. It would be possible to instead create a table
2299 of changes which have to be made, as is done in coff-mips.c;
2300 that would be more work, but would require less memory when
2301 the linker is run. */
2303 elf_section_data (sec
)->relocs
= internal_relocs
;
2304 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2305 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2307 /* Replace the jsr with a bsr. */
2309 /* Change the R_SH_USES reloc into an R_SH_IND12W reloc, and
2310 replace the jsr with a bsr. */
2311 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irelfn
->r_info
), R_SH_IND12W
);
2312 /* We used to test (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
2313 here, but that only checks if the symbol is an external symbol,
2314 not if the symbol is in a different section. Besides, we need
2315 a consistent meaning for the relocation, so we just assume here that
2316 the value of the symbol is not available. */
2318 /* We can't fully resolve this yet, because the external
2319 symbol value may be changed by future relaxing. We let
2320 the final link phase handle it. */
2321 bfd_put_16 (abfd
, (bfd_vma
) 0xb000, contents
+ irel
->r_offset
);
2323 irel
->r_addend
= -4;
2325 /* See if there is another R_SH_USES reloc referring to the same
2327 for (irelscan
= internal_relocs
; irelscan
< irelend
; irelscan
++)
2328 if (ELF32_R_TYPE (irelscan
->r_info
) == (int) R_SH_USES
2329 && laddr
== irelscan
->r_offset
+ 4 + irelscan
->r_addend
)
2331 if (irelscan
< irelend
)
2333 /* Some other function call depends upon this register load,
2334 and we have not yet converted that function call.
2335 Indeed, we may never be able to convert it. There is
2336 nothing else we can do at this point. */
2340 /* Look for a R_SH_COUNT reloc on the location where the
2341 function address is stored. Do this before deleting any
2342 bytes, to avoid confusion about the address. */
2343 for (irelcount
= internal_relocs
; irelcount
< irelend
; irelcount
++)
2344 if (irelcount
->r_offset
== paddr
2345 && ELF32_R_TYPE (irelcount
->r_info
) == (int) R_SH_COUNT
)
2348 /* Delete the register load. */
2349 if (! sh_elf_relax_delete_bytes (abfd
, sec
, laddr
, 2))
2352 /* That will change things, so, just in case it permits some
2353 other function call to come within range, we should relax
2354 again. Note that this is not required, and it may be slow. */
2357 /* Now check whether we got a COUNT reloc. */
2358 if (irelcount
>= irelend
)
2360 ((*_bfd_error_handler
)
2361 (_("%B: 0x%lx: warning: could not find expected COUNT reloc"),
2362 abfd
, (unsigned long) paddr
));
2366 /* The number of uses is stored in the r_addend field. We've
2367 just deleted one. */
2368 if (irelcount
->r_addend
== 0)
2370 ((*_bfd_error_handler
) (_("%B: 0x%lx: warning: bad count"),
2372 (unsigned long) paddr
));
2376 --irelcount
->r_addend
;
2378 /* If there are no more uses, we can delete the address. Reload
2379 the address from irelfn, in case it was changed by the
2380 previous call to sh_elf_relax_delete_bytes. */
2381 if (irelcount
->r_addend
== 0)
2383 if (! sh_elf_relax_delete_bytes (abfd
, sec
, irelfn
->r_offset
, 4))
2387 /* We've done all we can with that function call. */
2390 /* Look for load and store instructions that we can align on four
2392 if ((elf_elfheader (abfd
)->e_flags
& EF_SH_MACH_MASK
) != EF_SH4
2395 bfd_boolean swapped
;
2397 /* Get the section contents. */
2398 if (contents
== NULL
)
2400 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2401 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2404 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
2409 if (! sh_elf_align_loads (abfd
, sec
, internal_relocs
, contents
,
2415 elf_section_data (sec
)->relocs
= internal_relocs
;
2416 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2417 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2422 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
2424 if (! link_info
->keep_memory
)
2428 /* Cache the symbols for elf_link_input_bfd. */
2429 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2433 if (contents
!= NULL
2434 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2436 if (! link_info
->keep_memory
)
2440 /* Cache the section contents for elf_link_input_bfd. */
2441 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2445 if (internal_relocs
!= NULL
2446 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2447 free (internal_relocs
);
2453 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
2455 if (contents
!= NULL
2456 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2458 if (internal_relocs
!= NULL
2459 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2460 free (internal_relocs
);
2465 /* Delete some bytes from a section while relaxing. FIXME: There is a
2466 lot of duplication between this function and sh_relax_delete_bytes
2470 sh_elf_relax_delete_bytes (bfd
*abfd
, asection
*sec
, bfd_vma addr
,
2473 Elf_Internal_Shdr
*symtab_hdr
;
2474 unsigned int sec_shndx
;
2476 Elf_Internal_Rela
*irel
, *irelend
;
2477 Elf_Internal_Rela
*irelalign
;
2479 Elf_Internal_Sym
*isymbuf
, *isym
, *isymend
;
2480 struct elf_link_hash_entry
**sym_hashes
;
2481 struct elf_link_hash_entry
**end_hashes
;
2482 unsigned int symcount
;
2485 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2486 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2488 sec_shndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
2490 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2492 /* The deletion must stop at the next ALIGN reloc for an aligment
2493 power larger than the number of bytes we are deleting. */
2498 irel
= elf_section_data (sec
)->relocs
;
2499 irelend
= irel
+ sec
->reloc_count
;
2500 for (; irel
< irelend
; irel
++)
2502 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_ALIGN
2503 && irel
->r_offset
> addr
2504 && count
< (1 << irel
->r_addend
))
2507 toaddr
= irel
->r_offset
;
2512 /* Actually delete the bytes. */
2513 memmove (contents
+ addr
, contents
+ addr
+ count
,
2514 (size_t) (toaddr
- addr
- count
));
2515 if (irelalign
== NULL
)
2521 #define NOP_OPCODE (0x0009)
2523 BFD_ASSERT ((count
& 1) == 0);
2524 for (i
= 0; i
< count
; i
+= 2)
2525 bfd_put_16 (abfd
, (bfd_vma
) NOP_OPCODE
, contents
+ toaddr
- count
+ i
);
2528 /* Adjust all the relocs. */
2529 for (irel
= elf_section_data (sec
)->relocs
; irel
< irelend
; irel
++)
2531 bfd_vma nraddr
, stop
;
2534 int off
, adjust
, oinsn
;
2535 bfd_signed_vma voff
= 0;
2536 bfd_boolean overflow
;
2538 /* Get the new reloc address. */
2539 nraddr
= irel
->r_offset
;
2540 if ((irel
->r_offset
> addr
2541 && irel
->r_offset
< toaddr
)
2542 || (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_ALIGN
2543 && irel
->r_offset
== toaddr
))
2546 /* See if this reloc was for the bytes we have deleted, in which
2547 case we no longer care about it. Don't delete relocs which
2548 represent addresses, though. */
2549 if (irel
->r_offset
>= addr
2550 && irel
->r_offset
< addr
+ count
2551 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_ALIGN
2552 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_CODE
2553 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_DATA
2554 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_LABEL
)
2555 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
2558 /* If this is a PC relative reloc, see if the range it covers
2559 includes the bytes we have deleted. */
2560 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
2569 start
= irel
->r_offset
;
2570 insn
= bfd_get_16 (abfd
, contents
+ nraddr
);
2574 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
2577 start
= stop
= addr
;
2581 /* If this reloc is against a symbol defined in this
2582 section, and the symbol will not be adjusted below, we
2583 must check the addend to see it will put the value in
2584 range to be adjusted, and hence must be changed. */
2585 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
2587 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
2588 if (isym
->st_shndx
== sec_shndx
2589 && (isym
->st_value
<= addr
2590 || isym
->st_value
>= toaddr
))
2594 val
= bfd_get_32 (abfd
, contents
+ nraddr
);
2595 val
+= isym
->st_value
;
2596 if (val
> addr
&& val
< toaddr
)
2597 bfd_put_32 (abfd
, val
- count
, contents
+ nraddr
);
2600 start
= stop
= addr
;
2607 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ 4 + off
* 2);
2614 /* This has been made by previous relaxation. Since the
2615 relocation will be against an external symbol, the
2616 final relocation will just do the right thing. */
2617 start
= stop
= addr
;
2623 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ 4 + off
* 2);
2625 /* The addend will be against the section symbol, thus
2626 for adjusting the addend, the relevant start is the
2627 start of the section.
2628 N.B. If we want to abandon in-place changes here and
2629 test directly using symbol + addend, we have to take into
2630 account that the addend has already been adjusted by -4. */
2631 if (stop
> addr
&& stop
< toaddr
)
2632 irel
->r_addend
-= count
;
2638 stop
= start
+ 4 + off
* 2;
2643 stop
= (start
& ~(bfd_vma
) 3) + 4 + off
* 4;
2649 /* These relocs types represent
2651 The r_addend field holds the difference between the reloc
2652 address and L1. That is the start of the reloc, and
2653 adding in the contents gives us the top. We must adjust
2654 both the r_offset field and the section contents.
2655 N.B. in gas / coff bfd, the elf bfd r_addend is called r_offset,
2656 and the elf bfd r_offset is called r_vaddr. */
2658 stop
= irel
->r_offset
;
2659 start
= (bfd_vma
) ((bfd_signed_vma
) stop
- (long) irel
->r_addend
);
2663 && (stop
<= addr
|| stop
>= toaddr
))
2664 irel
->r_addend
+= count
;
2665 else if (stop
> addr
2667 && (start
<= addr
|| start
>= toaddr
))
2668 irel
->r_addend
-= count
;
2670 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_SWITCH16
)
2671 voff
= bfd_get_signed_16 (abfd
, contents
+ nraddr
);
2672 else if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_SWITCH8
)
2673 voff
= bfd_get_8 (abfd
, contents
+ nraddr
);
2675 voff
= bfd_get_signed_32 (abfd
, contents
+ nraddr
);
2676 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ voff
);
2681 start
= irel
->r_offset
;
2682 stop
= (bfd_vma
) ((bfd_signed_vma
) start
2683 + (long) irel
->r_addend
2690 && (stop
<= addr
|| stop
>= toaddr
))
2692 else if (stop
> addr
2694 && (start
<= addr
|| start
>= toaddr
))
2703 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
2712 if ((oinsn
& 0xff00) != (insn
& 0xff00))
2714 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
2719 if ((oinsn
& 0xf000) != (insn
& 0xf000))
2721 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
2725 BFD_ASSERT (adjust
== count
|| count
>= 4);
2730 if ((irel
->r_offset
& 3) == 0)
2733 if ((oinsn
& 0xff00) != (insn
& 0xff00))
2735 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
2740 if (voff
< 0 || voff
>= 0xff)
2742 bfd_put_8 (abfd
, voff
, contents
+ nraddr
);
2747 if (voff
< - 0x8000 || voff
>= 0x8000)
2749 bfd_put_signed_16 (abfd
, (bfd_vma
) voff
, contents
+ nraddr
);
2754 bfd_put_signed_32 (abfd
, (bfd_vma
) voff
, contents
+ nraddr
);
2758 irel
->r_addend
+= adjust
;
2764 ((*_bfd_error_handler
)
2765 (_("%B: 0x%lx: fatal: reloc overflow while relaxing"),
2766 abfd
, (unsigned long) irel
->r_offset
));
2767 bfd_set_error (bfd_error_bad_value
);
2772 irel
->r_offset
= nraddr
;
2775 /* Look through all the other sections. If there contain any IMM32
2776 relocs against internal symbols which we are not going to adjust
2777 below, we may need to adjust the addends. */
2778 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
2780 Elf_Internal_Rela
*internal_relocs
;
2781 Elf_Internal_Rela
*irelscan
, *irelscanend
;
2782 bfd_byte
*ocontents
;
2785 || (o
->flags
& SEC_RELOC
) == 0
2786 || o
->reloc_count
== 0)
2789 /* We always cache the relocs. Perhaps, if info->keep_memory is
2790 FALSE, we should free them, if we are permitted to, when we
2791 leave sh_coff_relax_section. */
2792 internal_relocs
= (_bfd_elf_link_read_relocs
2793 (abfd
, o
, NULL
, (Elf_Internal_Rela
*) NULL
, TRUE
));
2794 if (internal_relocs
== NULL
)
2798 irelscanend
= internal_relocs
+ o
->reloc_count
;
2799 for (irelscan
= internal_relocs
; irelscan
< irelscanend
; irelscan
++)
2801 /* Dwarf line numbers use R_SH_SWITCH32 relocs. */
2802 if (ELF32_R_TYPE (irelscan
->r_info
) == (int) R_SH_SWITCH32
)
2804 bfd_vma start
, stop
;
2805 bfd_signed_vma voff
;
2807 if (ocontents
== NULL
)
2809 if (elf_section_data (o
)->this_hdr
.contents
!= NULL
)
2810 ocontents
= elf_section_data (o
)->this_hdr
.contents
;
2813 /* We always cache the section contents.
2814 Perhaps, if info->keep_memory is FALSE, we
2815 should free them, if we are permitted to,
2816 when we leave sh_coff_relax_section. */
2817 if (!bfd_malloc_and_get_section (abfd
, o
, &ocontents
))
2819 if (ocontents
!= NULL
)
2824 elf_section_data (o
)->this_hdr
.contents
= ocontents
;
2828 stop
= irelscan
->r_offset
;
2830 = (bfd_vma
) ((bfd_signed_vma
) stop
- (long) irelscan
->r_addend
);
2832 /* STOP is in a different section, so it won't change. */
2833 if (start
> addr
&& start
< toaddr
)
2834 irelscan
->r_addend
+= count
;
2836 voff
= bfd_get_signed_32 (abfd
, ocontents
+ irelscan
->r_offset
);
2837 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ voff
);
2841 && (stop
<= addr
|| stop
>= toaddr
))
2842 bfd_put_signed_32 (abfd
, (bfd_vma
) voff
+ count
,
2843 ocontents
+ irelscan
->r_offset
);
2844 else if (stop
> addr
2846 && (start
<= addr
|| start
>= toaddr
))
2847 bfd_put_signed_32 (abfd
, (bfd_vma
) voff
- count
,
2848 ocontents
+ irelscan
->r_offset
);
2851 if (ELF32_R_TYPE (irelscan
->r_info
) != (int) R_SH_DIR32
)
2854 if (ELF32_R_SYM (irelscan
->r_info
) >= symtab_hdr
->sh_info
)
2858 isym
= isymbuf
+ ELF32_R_SYM (irelscan
->r_info
);
2859 if (isym
->st_shndx
== sec_shndx
2860 && (isym
->st_value
<= addr
2861 || isym
->st_value
>= toaddr
))
2865 if (ocontents
== NULL
)
2867 if (elf_section_data (o
)->this_hdr
.contents
!= NULL
)
2868 ocontents
= elf_section_data (o
)->this_hdr
.contents
;
2871 /* We always cache the section contents.
2872 Perhaps, if info->keep_memory is FALSE, we
2873 should free them, if we are permitted to,
2874 when we leave sh_coff_relax_section. */
2875 if (!bfd_malloc_and_get_section (abfd
, o
, &ocontents
))
2877 if (ocontents
!= NULL
)
2882 elf_section_data (o
)->this_hdr
.contents
= ocontents
;
2886 val
= bfd_get_32 (abfd
, ocontents
+ irelscan
->r_offset
);
2887 val
+= isym
->st_value
;
2888 if (val
> addr
&& val
< toaddr
)
2889 bfd_put_32 (abfd
, val
- count
,
2890 ocontents
+ irelscan
->r_offset
);
2895 /* Adjust the local symbols defined in this section. */
2896 isymend
= isymbuf
+ symtab_hdr
->sh_info
;
2897 for (isym
= isymbuf
; isym
< isymend
; isym
++)
2899 if (isym
->st_shndx
== sec_shndx
2900 && isym
->st_value
> addr
2901 && isym
->st_value
< toaddr
)
2902 isym
->st_value
-= count
;
2905 /* Now adjust the global symbols defined in this section. */
2906 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
2907 - symtab_hdr
->sh_info
);
2908 sym_hashes
= elf_sym_hashes (abfd
);
2909 end_hashes
= sym_hashes
+ symcount
;
2910 for (; sym_hashes
< end_hashes
; sym_hashes
++)
2912 struct elf_link_hash_entry
*sym_hash
= *sym_hashes
;
2913 if ((sym_hash
->root
.type
== bfd_link_hash_defined
2914 || sym_hash
->root
.type
== bfd_link_hash_defweak
)
2915 && sym_hash
->root
.u
.def
.section
== sec
2916 && sym_hash
->root
.u
.def
.value
> addr
2917 && sym_hash
->root
.u
.def
.value
< toaddr
)
2919 sym_hash
->root
.u
.def
.value
-= count
;
2923 /* See if we can move the ALIGN reloc forward. We have adjusted
2924 r_offset for it already. */
2925 if (irelalign
!= NULL
)
2927 bfd_vma alignto
, alignaddr
;
2929 alignto
= BFD_ALIGN (toaddr
, 1 << irelalign
->r_addend
);
2930 alignaddr
= BFD_ALIGN (irelalign
->r_offset
,
2931 1 << irelalign
->r_addend
);
2932 if (alignto
!= alignaddr
)
2934 /* Tail recursion. */
2935 return sh_elf_relax_delete_bytes (abfd
, sec
, alignaddr
,
2936 (int) (alignto
- alignaddr
));
2943 /* Look for loads and stores which we can align to four byte
2944 boundaries. This is like sh_align_loads in coff-sh.c. */
2947 sh_elf_align_loads (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
,
2948 Elf_Internal_Rela
*internal_relocs
,
2949 bfd_byte
*contents ATTRIBUTE_UNUSED
,
2950 bfd_boolean
*pswapped
)
2952 Elf_Internal_Rela
*irel
, *irelend
;
2953 bfd_vma
*labels
= NULL
;
2954 bfd_vma
*label
, *label_end
;
2959 irelend
= internal_relocs
+ sec
->reloc_count
;
2961 /* Get all the addresses with labels on them. */
2962 amt
= sec
->reloc_count
;
2963 amt
*= sizeof (bfd_vma
);
2964 labels
= (bfd_vma
*) bfd_malloc (amt
);
2968 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2970 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_LABEL
)
2972 *label_end
= irel
->r_offset
;
2977 /* Note that the assembler currently always outputs relocs in
2978 address order. If that ever changes, this code will need to sort
2979 the label values and the relocs. */
2983 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2985 bfd_vma start
, stop
;
2987 if (ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_CODE
)
2990 start
= irel
->r_offset
;
2992 for (irel
++; irel
< irelend
; irel
++)
2993 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_DATA
)
2996 stop
= irel
->r_offset
;
3000 if (! _bfd_sh_align_load_span (abfd
, sec
, contents
, sh_elf_swap_insns
,
3001 internal_relocs
, &label
,
3002 label_end
, start
, stop
, pswapped
))
3017 /* Swap two SH instructions. This is like sh_swap_insns in coff-sh.c. */
3020 sh_elf_swap_insns (bfd
*abfd
, asection
*sec
, void *relocs
,
3021 bfd_byte
*contents
, bfd_vma addr
)
3023 Elf_Internal_Rela
*internal_relocs
= (Elf_Internal_Rela
*) relocs
;
3024 unsigned short i1
, i2
;
3025 Elf_Internal_Rela
*irel
, *irelend
;
3027 /* Swap the instructions themselves. */
3028 i1
= bfd_get_16 (abfd
, contents
+ addr
);
3029 i2
= bfd_get_16 (abfd
, contents
+ addr
+ 2);
3030 bfd_put_16 (abfd
, (bfd_vma
) i2
, contents
+ addr
);
3031 bfd_put_16 (abfd
, (bfd_vma
) i1
, contents
+ addr
+ 2);
3033 /* Adjust all reloc addresses. */
3034 irelend
= internal_relocs
+ sec
->reloc_count
;
3035 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
3037 enum elf_sh_reloc_type type
;
3040 /* There are a few special types of relocs that we don't want to
3041 adjust. These relocs do not apply to the instruction itself,
3042 but are only associated with the address. */
3043 type
= (enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
);
3044 if (type
== R_SH_ALIGN
3045 || type
== R_SH_CODE
3046 || type
== R_SH_DATA
3047 || type
== R_SH_LABEL
)
3050 /* If an R_SH_USES reloc points to one of the addresses being
3051 swapped, we must adjust it. It would be incorrect to do this
3052 for a jump, though, since we want to execute both
3053 instructions after the jump. (We have avoided swapping
3054 around a label, so the jump will not wind up executing an
3055 instruction it shouldn't). */
3056 if (type
== R_SH_USES
)
3060 off
= irel
->r_offset
+ 4 + irel
->r_addend
;
3062 irel
->r_offset
+= 2;
3063 else if (off
== addr
+ 2)
3064 irel
->r_offset
-= 2;
3067 if (irel
->r_offset
== addr
)
3069 irel
->r_offset
+= 2;
3072 else if (irel
->r_offset
== addr
+ 2)
3074 irel
->r_offset
-= 2;
3083 unsigned short insn
, oinsn
;
3084 bfd_boolean overflow
;
3086 loc
= contents
+ irel
->r_offset
;
3095 insn
= bfd_get_16 (abfd
, loc
);
3098 if ((oinsn
& 0xff00) != (insn
& 0xff00))
3100 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
3104 insn
= bfd_get_16 (abfd
, loc
);
3107 if ((oinsn
& 0xf000) != (insn
& 0xf000))
3109 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
3113 /* This reloc ignores the least significant 3 bits of
3114 the program counter before adding in the offset.
3115 This means that if ADDR is at an even address, the
3116 swap will not affect the offset. If ADDR is an at an
3117 odd address, then the instruction will be crossing a
3118 four byte boundary, and must be adjusted. */
3119 if ((addr
& 3) != 0)
3121 insn
= bfd_get_16 (abfd
, loc
);
3124 if ((oinsn
& 0xff00) != (insn
& 0xff00))
3126 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
3134 ((*_bfd_error_handler
)
3135 (_("%B: 0x%lx: fatal: reloc overflow while relaxing"),
3136 abfd
, (unsigned long) irel
->r_offset
));
3137 bfd_set_error (bfd_error_bad_value
);
3145 #endif /* defined SH64_ELF */
3147 #ifdef INCLUDE_SHMEDIA
3149 /* The size in bytes of an entry in the procedure linkage table. */
3151 #define PLT_ENTRY_SIZE 64
3153 /* First entry in an absolute procedure linkage table look like this. */
3155 static const bfd_byte elf_sh_plt0_entry_be
[PLT_ENTRY_SIZE
] =
3157 0xcc, 0x00, 0x01, 0x10, /* movi .got.plt >> 16, r17 */
3158 0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
3159 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
3160 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3161 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
3162 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3163 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3164 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3165 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3166 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3167 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3168 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3169 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3170 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3171 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3172 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3175 static const bfd_byte elf_sh_plt0_entry_le
[PLT_ENTRY_SIZE
] =
3177 0x10, 0x01, 0x00, 0xcc, /* movi .got.plt >> 16, r17 */
3178 0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
3179 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
3180 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3181 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
3182 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3183 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3184 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3185 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3186 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3187 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3188 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3189 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3190 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3191 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3192 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3195 /* Sebsequent entries in an absolute procedure linkage table look like
3198 static const bfd_byte elf_sh_plt_entry_be
[PLT_ENTRY_SIZE
] =
3200 0xcc, 0x00, 0x01, 0x90, /* movi nameN-in-GOT >> 16, r25 */
3201 0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */
3202 0x89, 0x90, 0x01, 0x90, /* ld.l r25, 0, r25 */
3203 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3204 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3205 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3206 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3207 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3208 0xcc, 0x00, 0x01, 0x90, /* movi .PLT0 >> 16, r25 */
3209 0xc8, 0x00, 0x01, 0x90, /* shori .PLT0 & 65535, r25 */
3210 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3211 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3212 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3213 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3214 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3215 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3218 static const bfd_byte elf_sh_plt_entry_le
[PLT_ENTRY_SIZE
] =
3220 0x90, 0x01, 0x00, 0xcc, /* movi nameN-in-GOT >> 16, r25 */
3221 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
3222 0x90, 0x01, 0x90, 0x89, /* ld.l r25, 0, r25 */
3223 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3224 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3225 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3226 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3227 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3228 0x90, 0x01, 0x00, 0xcc, /* movi .PLT0 >> 16, r25 */
3229 0x90, 0x01, 0x00, 0xc8, /* shori .PLT0 & 65535, r25 */
3230 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3231 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3232 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3233 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3234 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3235 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3238 /* Entries in a PIC procedure linkage table look like this. */
3240 static const bfd_byte elf_sh_pic_plt_entry_be
[PLT_ENTRY_SIZE
] =
3242 0xcc, 0x00, 0x01, 0x90, /* movi nameN@GOT >> 16, r25 */
3243 0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */
3244 0x40, 0xc2, 0x65, 0x90, /* ldx.l r12, r25, r25 */
3245 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3246 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3247 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3248 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3249 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3250 0xce, 0x00, 0x01, 0x10, /* movi -GOT_BIAS, r17 */
3251 0x00, 0xc8, 0x45, 0x10, /* add.l r12, r17, r17 */
3252 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
3253 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3254 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
3255 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3256 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3257 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3260 static const bfd_byte elf_sh_pic_plt_entry_le
[PLT_ENTRY_SIZE
] =
3262 0x90, 0x01, 0x00, 0xcc, /* movi nameN@GOT >> 16, r25 */
3263 0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */
3264 0x90, 0x65, 0xc2, 0x40, /* ldx.l r12, r25, r25 */
3265 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3266 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3267 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3268 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3269 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3270 0x10, 0x01, 0x00, 0xce, /* movi -GOT_BIAS, r17 */
3271 0x10, 0x45, 0xc8, 0x00, /* add.l r12, r17, r17 */
3272 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
3273 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3274 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
3275 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3276 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3277 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3280 static const bfd_byte
*elf_sh_plt0_entry
;
3281 static const bfd_byte
*elf_sh_plt_entry
;
3282 static const bfd_byte
*elf_sh_pic_plt_entry
;
3284 /* Return size of a PLT entry. */
3285 #define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE
3287 /* Return offset of the PLT0 address in an absolute PLT entry. */
3288 #define elf_sh_plt_plt0_offset(info) 32
3290 /* Return offset of the linker in PLT0 entry. */
3291 #define elf_sh_plt0_gotplt_offset(info) 0
3293 /* Return offset of the trampoline in PLT entry */
3294 #define elf_sh_plt_temp_offset(info) 33 /* Add one because it's SHmedia. */
3296 /* Return offset of the symbol in PLT entry. */
3297 #define elf_sh_plt_symbol_offset(info) 0
3299 /* Return offset of the relocation in PLT entry. */
3300 #define elf_sh_plt_reloc_offset(info) (info->shared ? 52 : 44)
3303 movi_shori_putval (bfd
*output_bfd
, unsigned long value
, bfd_byte
*addr
)
3305 bfd_put_32 (output_bfd
,
3306 bfd_get_32 (output_bfd
, addr
)
3307 | ((value
>> 6) & 0x3fffc00),
3309 bfd_put_32 (output_bfd
,
3310 bfd_get_32 (output_bfd
, addr
+ 4)
3311 | ((value
<< 10) & 0x3fffc00),
3316 /* The size in bytes of an entry in the procedure linkage table. */
3318 #define PLT_ENTRY_SIZE 28
3320 /* First entry in an absolute procedure linkage table look like this. */
3322 /* Note - this code has been "optimised" not to use r2. r2 is used by
3323 GCC to return the address of large structures, so it should not be
3324 corrupted here. This does mean however, that this PLT does not conform
3325 to the SH PIC ABI. That spec says that r0 contains the type of the PLT
3326 and r2 contains the GOT id. This version stores the GOT id in r0 and
3327 ignores the type. Loaders can easily detect this difference however,
3328 since the type will always be 0 or 8, and the GOT ids will always be
3329 greater than or equal to 12. */
3330 static const bfd_byte elf_sh_plt0_entry_be
[PLT_ENTRY_SIZE
] =
3332 0xd0, 0x05, /* mov.l 2f,r0 */
3333 0x60, 0x02, /* mov.l @r0,r0 */
3334 0x2f, 0x06, /* mov.l r0,@-r15 */
3335 0xd0, 0x03, /* mov.l 1f,r0 */
3336 0x60, 0x02, /* mov.l @r0,r0 */
3337 0x40, 0x2b, /* jmp @r0 */
3338 0x60, 0xf6, /* mov.l @r15+,r0 */
3339 0x00, 0x09, /* nop */
3340 0x00, 0x09, /* nop */
3341 0x00, 0x09, /* nop */
3342 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3343 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3346 static const bfd_byte elf_sh_plt0_entry_le
[PLT_ENTRY_SIZE
] =
3348 0x05, 0xd0, /* mov.l 2f,r0 */
3349 0x02, 0x60, /* mov.l @r0,r0 */
3350 0x06, 0x2f, /* mov.l r0,@-r15 */
3351 0x03, 0xd0, /* mov.l 1f,r0 */
3352 0x02, 0x60, /* mov.l @r0,r0 */
3353 0x2b, 0x40, /* jmp @r0 */
3354 0xf6, 0x60, /* mov.l @r15+,r0 */
3355 0x09, 0x00, /* nop */
3356 0x09, 0x00, /* nop */
3357 0x09, 0x00, /* nop */
3358 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3359 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3362 /* Sebsequent entries in an absolute procedure linkage table look like
3365 static const bfd_byte elf_sh_plt_entry_be
[PLT_ENTRY_SIZE
] =
3367 0xd0, 0x04, /* mov.l 1f,r0 */
3368 0x60, 0x02, /* mov.l @r0,r0 */
3369 0xd1, 0x02, /* mov.l 0f,r1 */
3370 0x40, 0x2b, /* jmp @r0 */
3371 0x60, 0x13, /* mov r1,r0 */
3372 0xd1, 0x03, /* mov.l 2f,r1 */
3373 0x40, 0x2b, /* jmp @r0 */
3374 0x00, 0x09, /* nop */
3375 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3376 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3377 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3380 static const bfd_byte elf_sh_plt_entry_le
[PLT_ENTRY_SIZE
] =
3382 0x04, 0xd0, /* mov.l 1f,r0 */
3383 0x02, 0x60, /* mov.l @r0,r0 */
3384 0x02, 0xd1, /* mov.l 0f,r1 */
3385 0x2b, 0x40, /* jmp @r0 */
3386 0x13, 0x60, /* mov r1,r0 */
3387 0x03, 0xd1, /* mov.l 2f,r1 */
3388 0x2b, 0x40, /* jmp @r0 */
3389 0x09, 0x00, /* nop */
3390 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3391 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3392 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3395 /* Entries in a PIC procedure linkage table look like this. */
3397 static const bfd_byte elf_sh_pic_plt_entry_be
[PLT_ENTRY_SIZE
] =
3399 0xd0, 0x04, /* mov.l 1f,r0 */
3400 0x00, 0xce, /* mov.l @(r0,r12),r0 */
3401 0x40, 0x2b, /* jmp @r0 */
3402 0x00, 0x09, /* nop */
3403 0x50, 0xc2, /* mov.l @(8,r12),r0 */
3404 0xd1, 0x03, /* mov.l 2f,r1 */
3405 0x40, 0x2b, /* jmp @r0 */
3406 0x50, 0xc1, /* mov.l @(4,r12),r0 */
3407 0x00, 0x09, /* nop */
3408 0x00, 0x09, /* nop */
3409 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3410 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3413 static const bfd_byte elf_sh_pic_plt_entry_le
[PLT_ENTRY_SIZE
] =
3415 0x04, 0xd0, /* mov.l 1f,r0 */
3416 0xce, 0x00, /* mov.l @(r0,r12),r0 */
3417 0x2b, 0x40, /* jmp @r0 */
3418 0x09, 0x00, /* nop */
3419 0xc2, 0x50, /* mov.l @(8,r12),r0 */
3420 0x03, 0xd1, /* mov.l 2f,r1 */
3421 0x2b, 0x40, /* jmp @r0 */
3422 0xc1, 0x50, /* mov.l @(4,r12),r0 */
3423 0x09, 0x00, /* nop */
3424 0x09, 0x00, /* nop */
3425 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3426 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3429 static const bfd_byte
*elf_sh_plt0_entry
;
3430 static const bfd_byte
*elf_sh_plt_entry
;
3431 static const bfd_byte
*elf_sh_pic_plt_entry
;
3433 /* Return size of a PLT entry. */
3434 #define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE
3436 /* Return offset of the PLT0 address in an absolute PLT entry. */
3437 #define elf_sh_plt_plt0_offset(info) 16
3439 /* Return offset of the linker in PLT0 entry. */
3440 #define elf_sh_plt0_linker_offset(info) 20
3442 /* Return offset of the GOT id in PLT0 entry. */
3443 #define elf_sh_plt0_gotid_offset(info) 24
3445 /* Return offset of the temporary in PLT entry */
3446 #define elf_sh_plt_temp_offset(info) 8
3448 /* Return offset of the symbol in PLT entry. */
3449 #define elf_sh_plt_symbol_offset(info) 20
3451 /* Return offset of the relocation in PLT entry. */
3452 #define elf_sh_plt_reloc_offset(info) 24
3455 /* The sh linker needs to keep track of the number of relocs that it
3456 decides to copy as dynamic relocs in check_relocs for each symbol.
3457 This is so that it can later discard them if they are found to be
3458 unnecessary. We store the information in a field extending the
3459 regular ELF linker hash table. */
3461 struct elf_sh_dyn_relocs
3463 struct elf_sh_dyn_relocs
*next
;
3465 /* The input section of the reloc. */
3468 /* Total number of relocs copied for the input section. */
3469 bfd_size_type count
;
3471 /* Number of pc-relative relocs copied for the input section. */
3472 bfd_size_type pc_count
;
3475 /* sh ELF linker hash entry. */
3477 struct elf_sh_link_hash_entry
3479 struct elf_link_hash_entry root
;
3481 #ifdef INCLUDE_SHMEDIA
3484 bfd_signed_vma refcount
;
3489 /* Track dynamic relocs copied for this symbol. */
3490 struct elf_sh_dyn_relocs
*dyn_relocs
;
3492 bfd_signed_vma gotplt_refcount
;
3495 GOT_UNKNOWN
= 0, GOT_NORMAL
, GOT_TLS_GD
, GOT_TLS_IE
3499 #define sh_elf_hash_entry(ent) ((struct elf_sh_link_hash_entry *)(ent))
3501 struct sh_elf_obj_tdata
3503 struct elf_obj_tdata root
;
3505 /* tls_type for each local got entry. */
3506 char *local_got_tls_type
;
3509 #define sh_elf_tdata(abfd) \
3510 ((struct sh_elf_obj_tdata *) (abfd)->tdata.any)
3512 #define sh_elf_local_got_tls_type(abfd) \
3513 (sh_elf_tdata (abfd)->local_got_tls_type)
3515 /* Override the generic function because we need to store sh_elf_obj_tdata
3516 as the specific tdata. */
3519 sh_elf_mkobject (bfd
*abfd
)
3521 bfd_size_type amt
= sizeof (struct sh_elf_obj_tdata
);
3522 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
3523 if (abfd
->tdata
.any
== NULL
)
3528 /* sh ELF linker hash table. */
3530 struct elf_sh_link_hash_table
3532 struct elf_link_hash_table root
;
3534 /* Short-cuts to get to dynamic linker sections. */
3543 /* Small local sym to section mapping cache. */
3544 struct sym_sec_cache sym_sec
;
3546 /* A counter or offset to track a TLS got entry. */
3549 bfd_signed_vma refcount
;
3554 /* Traverse an sh ELF linker hash table. */
3556 #define sh_elf_link_hash_traverse(table, func, info) \
3557 (elf_link_hash_traverse \
3559 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
3562 /* Get the sh ELF linker hash table from a link_info structure. */
3564 #define sh_elf_hash_table(p) \
3565 ((struct elf_sh_link_hash_table *) ((p)->hash))
3567 /* Create an entry in an sh ELF linker hash table. */
3569 static struct bfd_hash_entry
*
3570 sh_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
3571 struct bfd_hash_table
*table
,
3574 struct elf_sh_link_hash_entry
*ret
=
3575 (struct elf_sh_link_hash_entry
*) entry
;
3577 /* Allocate the structure if it has not already been allocated by a
3579 if (ret
== (struct elf_sh_link_hash_entry
*) NULL
)
3580 ret
= ((struct elf_sh_link_hash_entry
*)
3581 bfd_hash_allocate (table
,
3582 sizeof (struct elf_sh_link_hash_entry
)));
3583 if (ret
== (struct elf_sh_link_hash_entry
*) NULL
)
3584 return (struct bfd_hash_entry
*) ret
;
3586 /* Call the allocation method of the superclass. */
3587 ret
= ((struct elf_sh_link_hash_entry
*)
3588 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3590 if (ret
!= (struct elf_sh_link_hash_entry
*) NULL
)
3592 ret
->dyn_relocs
= NULL
;
3593 ret
->gotplt_refcount
= 0;
3594 #ifdef INCLUDE_SHMEDIA
3595 ret
->datalabel_got
.refcount
= ret
->root
.got
.refcount
;
3597 ret
->tls_type
= GOT_UNKNOWN
;
3600 return (struct bfd_hash_entry
*) ret
;
3603 /* Create an sh ELF linker hash table. */
3605 static struct bfd_link_hash_table
*
3606 sh_elf_link_hash_table_create (bfd
*abfd
)
3608 struct elf_sh_link_hash_table
*ret
;
3609 bfd_size_type amt
= sizeof (struct elf_sh_link_hash_table
);
3611 ret
= (struct elf_sh_link_hash_table
*) bfd_malloc (amt
);
3612 if (ret
== (struct elf_sh_link_hash_table
*) NULL
)
3615 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3616 sh_elf_link_hash_newfunc
,
3617 sizeof (struct elf_sh_link_hash_entry
)))
3624 ret
->sgotplt
= NULL
;
3625 ret
->srelgot
= NULL
;
3627 ret
->srelplt
= NULL
;
3628 ret
->sdynbss
= NULL
;
3629 ret
->srelbss
= NULL
;
3630 ret
->sym_sec
.abfd
= NULL
;
3631 ret
->tls_ldm_got
.refcount
= 0;
3633 return &ret
->root
.root
;
3636 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
3637 shortcuts to them in our hash table. */
3640 create_got_section (bfd
*dynobj
, struct bfd_link_info
*info
)
3642 struct elf_sh_link_hash_table
*htab
;
3644 if (! _bfd_elf_create_got_section (dynobj
, info
))
3647 htab
= sh_elf_hash_table (info
);
3648 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
3649 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
3650 if (! htab
->sgot
|| ! htab
->sgotplt
)
3653 htab
->srelgot
= bfd_make_section_with_flags (dynobj
, ".rela.got",
3654 (SEC_ALLOC
| SEC_LOAD
3657 | SEC_LINKER_CREATED
3659 if (htab
->srelgot
== NULL
3660 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 2))
3665 /* Create dynamic sections when linking against a dynamic object. */
3668 sh_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
3670 struct elf_sh_link_hash_table
*htab
;
3671 flagword flags
, pltflags
;
3672 register asection
*s
;
3673 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
3676 switch (bed
->s
->arch_size
)
3687 bfd_set_error (bfd_error_bad_value
);
3691 htab
= sh_elf_hash_table (info
);
3692 if (htab
->root
.dynamic_sections_created
)
3695 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3696 .rel[a].bss sections. */
3698 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3699 | SEC_LINKER_CREATED
);
3702 pltflags
|= SEC_CODE
;
3703 if (bed
->plt_not_loaded
)
3704 pltflags
&= ~ (SEC_LOAD
| SEC_HAS_CONTENTS
);
3705 if (bed
->plt_readonly
)
3706 pltflags
|= SEC_READONLY
;
3708 s
= bfd_make_section_with_flags (abfd
, ".plt", pltflags
);
3711 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
3714 if (bed
->want_plt_sym
)
3716 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3718 struct elf_link_hash_entry
*h
;
3719 struct bfd_link_hash_entry
*bh
= NULL
;
3721 if (! (_bfd_generic_link_add_one_symbol
3722 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
,
3723 (bfd_vma
) 0, (const char *) NULL
, FALSE
,
3724 get_elf_backend_data (abfd
)->collect
, &bh
)))
3727 h
= (struct elf_link_hash_entry
*) bh
;
3729 h
->type
= STT_OBJECT
;
3730 htab
->root
.hplt
= h
;
3733 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
3737 s
= bfd_make_section_with_flags (abfd
,
3738 bed
->default_use_rela_p
? ".rela.plt" : ".rel.plt",
3739 flags
| SEC_READONLY
);
3742 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3745 if (htab
->sgot
== NULL
3746 && !create_got_section (abfd
, info
))
3750 const char *secname
;
3755 for (sec
= abfd
->sections
; sec
; sec
= sec
->next
)
3757 secflags
= bfd_get_section_flags (abfd
, sec
);
3758 if ((secflags
& (SEC_DATA
| SEC_LINKER_CREATED
))
3759 || ((secflags
& SEC_HAS_CONTENTS
) != SEC_HAS_CONTENTS
))
3761 secname
= bfd_get_section_name (abfd
, sec
);
3762 relname
= (char *) bfd_malloc ((bfd_size_type
) strlen (secname
) + 6);
3763 strcpy (relname
, ".rela");
3764 strcat (relname
, secname
);
3765 if (bfd_get_section_by_name (abfd
, secname
))
3767 s
= bfd_make_section_with_flags (abfd
, relname
,
3768 flags
| SEC_READONLY
);
3770 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3775 if (bed
->want_dynbss
)
3777 /* The .dynbss section is a place to put symbols which are defined
3778 by dynamic objects, are referenced by regular objects, and are
3779 not functions. We must allocate space for them in the process
3780 image and use a R_*_COPY reloc to tell the dynamic linker to
3781 initialize them at run time. The linker script puts the .dynbss
3782 section into the .bss section of the final image. */
3783 s
= bfd_make_section_with_flags (abfd
, ".dynbss",
3784 SEC_ALLOC
| SEC_LINKER_CREATED
);
3789 /* The .rel[a].bss section holds copy relocs. This section is not
3790 normally needed. We need to create it here, though, so that the
3791 linker will map it to an output section. We can't just create it
3792 only if we need it, because we will not know whether we need it
3793 until we have seen all the input files, and the first time the
3794 main linker code calls BFD after examining all the input files
3795 (size_dynamic_sections) the input sections have already been
3796 mapped to the output sections. If the section turns out not to
3797 be needed, we can discard it later. We will never need this
3798 section when generating a shared object, since they do not use
3802 s
= bfd_make_section_with_flags (abfd
,
3803 (bed
->default_use_rela_p
3804 ? ".rela.bss" : ".rel.bss"),
3805 flags
| SEC_READONLY
);
3808 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3816 /* Adjust a symbol defined by a dynamic object and referenced by a
3817 regular object. The current definition is in some section of the
3818 dynamic object, but we're not including those sections. We have to
3819 change the definition to something the rest of the link can
3823 sh_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
3824 struct elf_link_hash_entry
*h
)
3826 struct elf_sh_link_hash_table
*htab
;
3827 struct elf_sh_link_hash_entry
*eh
;
3828 struct elf_sh_dyn_relocs
*p
;
3830 unsigned int power_of_two
;
3832 htab
= sh_elf_hash_table (info
);
3834 /* Make sure we know what is going on here. */
3835 BFD_ASSERT (htab
->root
.dynobj
!= NULL
3837 || h
->u
.weakdef
!= NULL
3840 && !h
->def_regular
)));
3842 /* If this is a function, put it in the procedure linkage table. We
3843 will fill in the contents of the procedure linkage table later,
3844 when we know the address of the .got section. */
3845 if (h
->type
== STT_FUNC
3848 if (h
->plt
.refcount
<= 0
3849 || SYMBOL_CALLS_LOCAL (info
, h
)
3850 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3851 && h
->root
.type
== bfd_link_hash_undefweak
))
3853 /* This case can occur if we saw a PLT reloc in an input
3854 file, but the symbol was never referred to by a dynamic
3855 object. In such a case, we don't actually need to build
3856 a procedure linkage table, and we can just do a REL32
3858 h
->plt
.offset
= (bfd_vma
) -1;
3865 h
->plt
.offset
= (bfd_vma
) -1;
3867 /* If this is a weak symbol, and there is a real definition, the
3868 processor independent code will have arranged for us to see the
3869 real definition first, and we can just use the same value. */
3870 if (h
->u
.weakdef
!= NULL
)
3872 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
3873 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
3874 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
3875 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
3876 if (info
->nocopyreloc
)
3877 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
3881 /* This is a reference to a symbol defined by a dynamic object which
3882 is not a function. */
3884 /* If we are creating a shared library, we must presume that the
3885 only references to the symbol are via the global offset table.
3886 For such cases we need not do anything here; the relocations will
3887 be handled correctly by relocate_section. */
3891 /* If there are no references to this symbol that do not use the
3892 GOT, we don't need to generate a copy reloc. */
3893 if (!h
->non_got_ref
)
3896 /* If -z nocopyreloc was given, we won't generate them either. */
3897 if (info
->nocopyreloc
)
3903 eh
= (struct elf_sh_link_hash_entry
*) h
;
3904 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3906 s
= p
->sec
->output_section
;
3907 if (s
!= NULL
&& (s
->flags
& (SEC_READONLY
| SEC_HAS_CONTENTS
)) != 0)
3911 /* If we didn't find any dynamic relocs in sections which needs the
3912 copy reloc, then we'll be keeping the dynamic relocs and avoiding
3922 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
3923 h
->root
.root
.string
);
3927 /* We must allocate the symbol in our .dynbss section, which will
3928 become part of the .bss section of the executable. There will be
3929 an entry for this symbol in the .dynsym section. The dynamic
3930 object will contain position independent code, so all references
3931 from the dynamic object to this symbol will go through the global
3932 offset table. The dynamic linker will use the .dynsym entry to
3933 determine the address it must put in the global offset table, so
3934 both the dynamic object and the regular object will refer to the
3935 same memory location for the variable. */
3938 BFD_ASSERT (s
!= NULL
);
3940 /* We must generate a R_SH_COPY reloc to tell the dynamic linker to
3941 copy the initial value out of the dynamic object and into the
3942 runtime process image. We need to remember the offset into the
3943 .rela.bss section we are going to use. */
3944 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
3948 srel
= htab
->srelbss
;
3949 BFD_ASSERT (srel
!= NULL
);
3950 srel
->size
+= sizeof (Elf32_External_Rela
);
3954 /* We need to figure out the alignment required for this symbol. I
3955 have no idea how ELF linkers handle this. */
3956 power_of_two
= bfd_log2 (h
->size
);
3957 if (power_of_two
> 3)
3960 /* Apply the required alignment. */
3961 s
->size
= BFD_ALIGN (s
->size
, (bfd_size_type
) (1 << power_of_two
));
3962 if (power_of_two
> bfd_get_section_alignment (htab
->root
.dynobj
, s
))
3964 if (! bfd_set_section_alignment (htab
->root
.dynobj
, s
, power_of_two
))
3968 /* Define the symbol as being at this point in the section. */
3969 h
->root
.u
.def
.section
= s
;
3970 h
->root
.u
.def
.value
= s
->size
;
3972 /* Increment the section size to make room for the symbol. */
3978 /* Allocate space in .plt, .got and associated reloc sections for
3982 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
3984 struct bfd_link_info
*info
;
3985 struct elf_sh_link_hash_table
*htab
;
3986 struct elf_sh_link_hash_entry
*eh
;
3987 struct elf_sh_dyn_relocs
*p
;
3989 if (h
->root
.type
== bfd_link_hash_indirect
)
3992 if (h
->root
.type
== bfd_link_hash_warning
)
3993 /* When warning symbols are created, they **replace** the "real"
3994 entry in the hash table, thus we never get to see the real
3995 symbol in a hash traversal. So look at it now. */
3996 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3998 info
= (struct bfd_link_info
*) inf
;
3999 htab
= sh_elf_hash_table (info
);
4001 eh
= (struct elf_sh_link_hash_entry
*) h
;
4002 if ((h
->got
.refcount
> 0
4004 && eh
->gotplt_refcount
> 0)
4006 /* The symbol has been forced local, or we have some direct got refs,
4007 so treat all the gotplt refs as got refs. */
4008 h
->got
.refcount
+= eh
->gotplt_refcount
;
4009 if (h
->plt
.refcount
>= eh
->gotplt_refcount
)
4010 h
->plt
.refcount
-= eh
->gotplt_refcount
;
4013 if (htab
->root
.dynamic_sections_created
4014 && h
->plt
.refcount
> 0
4015 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4016 || h
->root
.type
!= bfd_link_hash_undefweak
))
4018 /* Make sure this symbol is output as a dynamic symbol.
4019 Undefined weak syms won't yet be marked as dynamic. */
4020 if (h
->dynindx
== -1
4021 && !h
->forced_local
)
4023 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4028 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
4030 asection
*s
= htab
->splt
;
4032 /* If this is the first .plt entry, make room for the special
4035 s
->size
+= PLT_ENTRY_SIZE
;
4037 h
->plt
.offset
= s
->size
;
4039 /* If this symbol is not defined in a regular file, and we are
4040 not generating a shared library, then set the symbol to this
4041 location in the .plt. This is required to make function
4042 pointers compare as equal between the normal executable and
4043 the shared library. */
4047 h
->root
.u
.def
.section
= s
;
4048 h
->root
.u
.def
.value
= h
->plt
.offset
;
4051 /* Make room for this entry. */
4052 s
->size
+= PLT_ENTRY_SIZE
;
4054 /* We also need to make an entry in the .got.plt section, which
4055 will be placed in the .got section by the linker script. */
4056 htab
->sgotplt
->size
+= 4;
4058 /* We also need to make an entry in the .rel.plt section. */
4059 htab
->srelplt
->size
+= sizeof (Elf32_External_Rela
);
4063 h
->plt
.offset
= (bfd_vma
) -1;
4069 h
->plt
.offset
= (bfd_vma
) -1;
4073 if (h
->got
.refcount
> 0)
4077 int tls_type
= sh_elf_hash_entry (h
)->tls_type
;
4079 /* Make sure this symbol is output as a dynamic symbol.
4080 Undefined weak syms won't yet be marked as dynamic. */
4081 if (h
->dynindx
== -1
4082 && !h
->forced_local
)
4084 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4089 h
->got
.offset
= s
->size
;
4091 /* R_SH_TLS_GD needs 2 consecutive GOT slots. */
4092 if (tls_type
== GOT_TLS_GD
)
4094 dyn
= htab
->root
.dynamic_sections_created
;
4095 /* R_SH_TLS_IE_32 needs one dynamic relocation if dynamic,
4096 R_SH_TLS_GD needs one if local symbol and two if global. */
4097 if ((tls_type
== GOT_TLS_GD
&& h
->dynindx
== -1)
4098 || (tls_type
== GOT_TLS_IE
&& dyn
))
4099 htab
->srelgot
->size
+= sizeof (Elf32_External_Rela
);
4100 else if (tls_type
== GOT_TLS_GD
)
4101 htab
->srelgot
->size
+= 2 * sizeof (Elf32_External_Rela
);
4102 else if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4103 || h
->root
.type
!= bfd_link_hash_undefweak
)
4105 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
4106 htab
->srelgot
->size
+= sizeof (Elf32_External_Rela
);
4109 h
->got
.offset
= (bfd_vma
) -1;
4111 #ifdef INCLUDE_SHMEDIA
4112 if (eh
->datalabel_got
.refcount
> 0)
4117 /* Make sure this symbol is output as a dynamic symbol.
4118 Undefined weak syms won't yet be marked as dynamic. */
4119 if (h
->dynindx
== -1
4120 && !h
->forced_local
)
4122 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4127 eh
->datalabel_got
.offset
= s
->size
;
4129 dyn
= htab
->root
.dynamic_sections_created
;
4130 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
))
4131 htab
->srelgot
->size
+= sizeof (Elf32_External_Rela
);
4134 eh
->datalabel_got
.offset
= (bfd_vma
) -1;
4137 if (eh
->dyn_relocs
== NULL
)
4140 /* In the shared -Bsymbolic case, discard space allocated for
4141 dynamic pc-relative relocs against symbols which turn out to be
4142 defined in regular objects. For the normal shared case, discard
4143 space for pc-relative relocs that have become local due to symbol
4144 visibility changes. */
4148 if (SYMBOL_CALLS_LOCAL (info
, h
))
4150 struct elf_sh_dyn_relocs
**pp
;
4152 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
4154 p
->count
-= p
->pc_count
;
4163 /* Also discard relocs on undefined weak syms with non-default
4165 if (eh
->dyn_relocs
!= NULL
4166 && h
->root
.type
== bfd_link_hash_undefweak
)
4168 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
4169 eh
->dyn_relocs
= NULL
;
4171 /* Make sure undefined weak symbols are output as a dynamic
4173 else if (h
->dynindx
== -1
4174 && !h
->forced_local
)
4176 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4183 /* For the non-shared case, discard space for relocs against
4184 symbols which turn out to need copy relocs or are not
4190 || (htab
->root
.dynamic_sections_created
4191 && (h
->root
.type
== bfd_link_hash_undefweak
4192 || h
->root
.type
== bfd_link_hash_undefined
))))
4194 /* Make sure this symbol is output as a dynamic symbol.
4195 Undefined weak syms won't yet be marked as dynamic. */
4196 if (h
->dynindx
== -1
4197 && !h
->forced_local
)
4199 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4203 /* If that succeeded, we know we'll be keeping all the
4205 if (h
->dynindx
!= -1)
4209 eh
->dyn_relocs
= NULL
;
4214 /* Finally, allocate space. */
4215 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4217 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
4218 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
4224 /* Find any dynamic relocs that apply to read-only sections. */
4227 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
4229 struct elf_sh_link_hash_entry
*eh
;
4230 struct elf_sh_dyn_relocs
*p
;
4232 if (h
->root
.type
== bfd_link_hash_warning
)
4233 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4235 eh
= (struct elf_sh_link_hash_entry
*) h
;
4236 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4238 asection
*s
= p
->sec
->output_section
;
4240 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
4242 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
4244 info
->flags
|= DF_TEXTREL
;
4246 /* Not an error, just cut short the traversal. */
4253 /* Set the sizes of the dynamic sections. */
4256 sh_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4257 struct bfd_link_info
*info
)
4259 struct elf_sh_link_hash_table
*htab
;
4265 htab
= sh_elf_hash_table (info
);
4266 dynobj
= htab
->root
.dynobj
;
4267 BFD_ASSERT (dynobj
!= NULL
);
4269 if (htab
->root
.dynamic_sections_created
)
4271 /* Set the contents of the .interp section to the interpreter. */
4272 if (info
->executable
)
4274 s
= bfd_get_section_by_name (dynobj
, ".interp");
4275 BFD_ASSERT (s
!= NULL
);
4276 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
4277 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
4281 /* Set up .got offsets for local syms, and space for local dynamic
4283 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4285 bfd_signed_vma
*local_got
;
4286 bfd_signed_vma
*end_local_got
;
4287 char *local_tls_type
;
4288 bfd_size_type locsymcount
;
4289 Elf_Internal_Shdr
*symtab_hdr
;
4292 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
4295 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
4297 struct elf_sh_dyn_relocs
*p
;
4299 for (p
= ((struct elf_sh_dyn_relocs
*)
4300 elf_section_data (s
)->local_dynrel
);
4304 if (! bfd_is_abs_section (p
->sec
)
4305 && bfd_is_abs_section (p
->sec
->output_section
))
4307 /* Input section has been discarded, either because
4308 it is a copy of a linkonce section or due to
4309 linker script /DISCARD/, so we'll be discarding
4312 else if (p
->count
!= 0)
4314 srel
= elf_section_data (p
->sec
)->sreloc
;
4315 srel
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
4316 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
4317 info
->flags
|= DF_TEXTREL
;
4322 local_got
= elf_local_got_refcounts (ibfd
);
4326 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4327 locsymcount
= symtab_hdr
->sh_info
;
4328 #ifdef INCLUDE_SHMEDIA
4329 /* Count datalabel local GOT. */
4332 end_local_got
= local_got
+ locsymcount
;
4333 local_tls_type
= sh_elf_local_got_tls_type (ibfd
);
4335 srel
= htab
->srelgot
;
4336 for (; local_got
< end_local_got
; ++local_got
)
4340 *local_got
= s
->size
;
4342 if (*local_tls_type
== GOT_TLS_GD
)
4345 srel
->size
+= sizeof (Elf32_External_Rela
);
4348 *local_got
= (bfd_vma
) -1;
4353 if (htab
->tls_ldm_got
.refcount
> 0)
4355 /* Allocate 2 got entries and 1 dynamic reloc for R_SH_TLS_LD_32
4357 htab
->tls_ldm_got
.offset
= htab
->sgot
->size
;
4358 htab
->sgot
->size
+= 8;
4359 htab
->srelgot
->size
+= sizeof (Elf32_External_Rela
);
4362 htab
->tls_ldm_got
.offset
= -1;
4364 /* Allocate global sym .plt and .got entries, and space for global
4365 sym dynamic relocs. */
4366 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, info
);
4368 /* We now have determined the sizes of the various dynamic sections.
4369 Allocate memory for them. */
4371 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4373 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
4378 || s
== htab
->sgotplt
4379 || s
== htab
->sdynbss
)
4381 /* Strip this section if we don't need it; see the
4384 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
4386 if (s
->size
!= 0 && s
!= htab
->srelplt
)
4389 /* We use the reloc_count field as a counter if we need
4390 to copy relocs into the output file. */
4395 /* It's not one of our sections, so don't allocate space. */
4401 /* If we don't need this section, strip it from the
4402 output file. This is mostly to handle .rela.bss and
4403 .rela.plt. We must create both sections in
4404 create_dynamic_sections, because they must be created
4405 before the linker maps input sections to output
4406 sections. The linker does that before
4407 adjust_dynamic_symbol is called, and it is that
4408 function which decides whether anything needs to go
4409 into these sections. */
4411 s
->flags
|= SEC_EXCLUDE
;
4415 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
4418 /* Allocate memory for the section contents. We use bfd_zalloc
4419 here in case unused entries are not reclaimed before the
4420 section's contents are written out. This should not happen,
4421 but this way if it does, we get a R_SH_NONE reloc instead
4423 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
4424 if (s
->contents
== NULL
)
4428 if (htab
->root
.dynamic_sections_created
)
4430 /* Add some entries to the .dynamic section. We fill in the
4431 values later, in sh_elf_finish_dynamic_sections, but we
4432 must add the entries now so that we get the correct size for
4433 the .dynamic section. The DT_DEBUG entry is filled in by the
4434 dynamic linker and used by the debugger. */
4435 #define add_dynamic_entry(TAG, VAL) \
4436 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
4438 if (info
->executable
)
4440 if (! add_dynamic_entry (DT_DEBUG
, 0))
4444 if (htab
->splt
->size
!= 0)
4446 if (! add_dynamic_entry (DT_PLTGOT
, 0)
4447 || ! add_dynamic_entry (DT_PLTRELSZ
, 0)
4448 || ! add_dynamic_entry (DT_PLTREL
, DT_RELA
)
4449 || ! add_dynamic_entry (DT_JMPREL
, 0))
4455 if (! add_dynamic_entry (DT_RELA
, 0)
4456 || ! add_dynamic_entry (DT_RELASZ
, 0)
4457 || ! add_dynamic_entry (DT_RELAENT
,
4458 sizeof (Elf32_External_Rela
)))
4461 /* If any dynamic relocs apply to a read-only section,
4462 then we need a DT_TEXTREL entry. */
4463 if ((info
->flags
& DF_TEXTREL
) == 0)
4464 elf_link_hash_traverse (&htab
->root
, readonly_dynrelocs
, info
);
4466 if ((info
->flags
& DF_TEXTREL
) != 0)
4468 if (! add_dynamic_entry (DT_TEXTREL
, 0))
4473 #undef add_dynamic_entry
4478 /* Relocate an SH ELF section. */
4481 sh_elf_relocate_section (bfd
*output_bfd
, struct bfd_link_info
*info
,
4482 bfd
*input_bfd
, asection
*input_section
,
4483 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
4484 Elf_Internal_Sym
*local_syms
,
4485 asection
**local_sections
)
4487 struct elf_sh_link_hash_table
*htab
;
4488 Elf_Internal_Shdr
*symtab_hdr
;
4489 struct elf_link_hash_entry
**sym_hashes
;
4490 Elf_Internal_Rela
*rel
, *relend
;
4492 bfd_vma
*local_got_offsets
;
4499 htab
= sh_elf_hash_table (info
);
4500 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4501 sym_hashes
= elf_sym_hashes (input_bfd
);
4502 dynobj
= htab
->root
.dynobj
;
4503 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4506 sgotplt
= htab
->sgotplt
;
4512 relend
= relocs
+ input_section
->reloc_count
;
4513 for (; rel
< relend
; rel
++)
4516 reloc_howto_type
*howto
;
4517 unsigned long r_symndx
;
4518 Elf_Internal_Sym
*sym
;
4520 struct elf_link_hash_entry
*h
;
4522 bfd_vma addend
= (bfd_vma
) 0;
4523 bfd_reloc_status_type r
;
4524 int seen_stt_datalabel
= 0;
4528 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4530 r_type
= ELF32_R_TYPE (rel
->r_info
);
4532 /* Many of the relocs are only used for relaxing, and are
4533 handled entirely by the relaxation code. */
4534 if (r_type
>= (int) R_SH_GNU_VTINHERIT
4535 && r_type
<= (int) R_SH_LABEL
)
4537 if (r_type
== (int) R_SH_NONE
)
4541 || r_type
>= R_SH_max
4542 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC
4543 && r_type
<= (int) R_SH_LAST_INVALID_RELOC
)
4544 || ( r_type
>= (int) R_SH_FIRST_INVALID_RELOC_3
4545 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_3
)
4546 || ( r_type
>= (int) R_SH_FIRST_INVALID_RELOC_4
4547 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_4
)
4548 || ( r_type
>= (int) R_SH_FIRST_INVALID_RELOC_5
4549 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_5
)
4550 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC_2
4551 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_2
))
4553 bfd_set_error (bfd_error_bad_value
);
4557 howto
= sh_elf_howto_table
+ r_type
;
4559 /* For relocs that aren't partial_inplace, we get the addend from
4561 if (! howto
->partial_inplace
)
4562 addend
= rel
->r_addend
;
4567 if (r_symndx
< symtab_hdr
->sh_info
)
4569 sym
= local_syms
+ r_symndx
;
4570 sec
= local_sections
[r_symndx
];
4571 relocation
= (sec
->output_section
->vma
4572 + sec
->output_offset
4574 /* A local symbol never has STO_SH5_ISA32, so we don't need
4575 datalabel processing here. Make sure this does not change
4577 if ((sym
->st_other
& STO_SH5_ISA32
) != 0)
4578 ((*info
->callbacks
->reloc_dangerous
)
4580 _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
4581 input_bfd
, input_section
, rel
->r_offset
));
4582 if (info
->relocatable
)
4584 /* This is a relocatable link. We don't have to change
4585 anything, unless the reloc is against a section symbol,
4586 in which case we have to adjust according to where the
4587 section symbol winds up in the output section. */
4588 sym
= local_syms
+ r_symndx
;
4589 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4591 if (! howto
->partial_inplace
)
4593 /* For relocations with the addend in the
4594 relocation, we need just to update the addend.
4595 All real relocs are of type partial_inplace; this
4596 code is mostly for completeness. */
4597 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
4602 /* Relocs of type partial_inplace need to pick up the
4603 contents in the contents and add the offset resulting
4604 from the changed location of the section symbol.
4605 Using _bfd_final_link_relocate (e.g. goto
4606 final_link_relocate) here would be wrong, because
4607 relocations marked pc_relative would get the current
4608 location subtracted, and we must only do that at the
4610 r
= _bfd_relocate_contents (howto
, input_bfd
,
4613 contents
+ rel
->r_offset
);
4614 goto relocation_done
;
4619 else if (! howto
->partial_inplace
)
4621 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
4622 addend
= rel
->r_addend
;
4624 else if ((sec
->flags
& SEC_MERGE
)
4625 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4629 if (howto
->rightshift
|| howto
->src_mask
!= 0xffffffff)
4631 (*_bfd_error_handler
)
4632 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
4633 input_bfd
, input_section
,
4634 (long) rel
->r_offset
, howto
->name
);
4638 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4641 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
4643 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
4644 bfd_put_32 (input_bfd
, addend
, contents
+ rel
->r_offset
);
4650 /* FIXME: Ought to make use of the RELOC_FOR_GLOBAL_SYMBOL macro. */
4652 /* Section symbol are never (?) placed in the hash table, so
4653 we can just ignore hash relocations when creating a
4654 relocatable object file. */
4655 if (info
->relocatable
)
4658 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4659 while (h
->root
.type
== bfd_link_hash_indirect
4660 || h
->root
.type
== bfd_link_hash_warning
)
4662 #ifdef INCLUDE_SHMEDIA
4663 /* If the reference passes a symbol marked with
4664 STT_DATALABEL, then any STO_SH5_ISA32 on the final value
4666 seen_stt_datalabel
|= h
->type
== STT_DATALABEL
;
4668 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4670 if (h
->root
.type
== bfd_link_hash_defined
4671 || h
->root
.type
== bfd_link_hash_defweak
)
4675 dyn
= htab
->root
.dynamic_sections_created
;
4676 sec
= h
->root
.u
.def
.section
;
4677 /* In these cases, we don't need the relocation value.
4678 We check specially because in some obscure cases
4679 sec->output_section will be NULL. */
4680 if (r_type
== R_SH_GOTPC
4681 || r_type
== R_SH_GOTPC_LOW16
4682 || r_type
== R_SH_GOTPC_MEDLOW16
4683 || r_type
== R_SH_GOTPC_MEDHI16
4684 || r_type
== R_SH_GOTPC_HI16
4685 || ((r_type
== R_SH_PLT32
4686 || r_type
== R_SH_PLT_LOW16
4687 || r_type
== R_SH_PLT_MEDLOW16
4688 || r_type
== R_SH_PLT_MEDHI16
4689 || r_type
== R_SH_PLT_HI16
)
4690 && h
->plt
.offset
!= (bfd_vma
) -1)
4691 || ((r_type
== R_SH_GOT32
4692 || r_type
== R_SH_GOT_LOW16
4693 || r_type
== R_SH_GOT_MEDLOW16
4694 || r_type
== R_SH_GOT_MEDHI16
4695 || r_type
== R_SH_GOT_HI16
)
4696 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
4698 || (! info
->symbolic
&& h
->dynindx
!= -1)
4699 || !h
->def_regular
))
4700 /* The cases above are those in which relocation is
4701 overwritten in the switch block below. The cases
4702 below are those in which we must defer relocation
4703 to run-time, because we can't resolve absolute
4704 addresses when creating a shared library. */
4706 && ((! info
->symbolic
&& h
->dynindx
!= -1)
4708 && ((r_type
== R_SH_DIR32
4709 && !h
->forced_local
)
4710 || (r_type
== R_SH_REL32
4711 && !SYMBOL_CALLS_LOCAL (info
, h
)))
4712 && ((input_section
->flags
& SEC_ALLOC
) != 0
4713 /* DWARF will emit R_SH_DIR32 relocations in its
4714 sections against symbols defined externally
4715 in shared libraries. We can't do anything
4717 || ((input_section
->flags
& SEC_DEBUGGING
) != 0
4718 && h
->def_dynamic
)))
4719 /* Dynamic relocs are not propagated for SEC_DEBUGGING
4720 sections because such sections are not SEC_ALLOC and
4721 thus ld.so will not process them. */
4722 || (sec
->output_section
== NULL
4723 && ((input_section
->flags
& SEC_DEBUGGING
) != 0
4725 || (sec
->output_section
== NULL
4726 && (sh_elf_hash_entry (h
)->tls_type
== GOT_TLS_IE
4727 || sh_elf_hash_entry (h
)->tls_type
== GOT_TLS_GD
)))
4729 else if (sec
->output_section
== NULL
)
4731 (*_bfd_error_handler
)
4732 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4735 (long) rel
->r_offset
,
4737 h
->root
.root
.string
);
4741 relocation
= ((h
->root
.u
.def
.value
4742 + sec
->output_section
->vma
4743 + sec
->output_offset
)
4744 /* A STO_SH5_ISA32 causes a "bitor 1" to the
4745 symbol value, unless we've seen
4746 STT_DATALABEL on the way to it. */
4747 | ((h
->other
& STO_SH5_ISA32
) != 0
4748 && ! seen_stt_datalabel
));
4750 else if (h
->root
.type
== bfd_link_hash_undefweak
)
4752 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
4753 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
4757 if (! info
->callbacks
->undefined_symbol
4758 (info
, h
->root
.root
.string
, input_bfd
,
4759 input_section
, rel
->r_offset
,
4760 (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
4761 || ELF_ST_VISIBILITY (h
->other
))))
4767 switch ((int) r_type
)
4769 final_link_relocate
:
4770 /* COFF relocs don't use the addend. The addend is used for
4771 R_SH_DIR32 to be compatible with other compilers. */
4772 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4773 contents
, rel
->r_offset
,
4774 relocation
, addend
);
4778 goto final_link_relocate
;
4783 /* If the reloc is against the start of this section, then
4784 the assembler has already taken care of it and the reloc
4785 is here only to assist in relaxing. If the reloc is not
4786 against the start of this section, then it's against an
4787 external symbol and we must deal with it ourselves. */
4788 if (input_section
->output_section
->vma
+ input_section
->output_offset
4791 int disp
= (relocation
4792 - input_section
->output_section
->vma
4793 - input_section
->output_offset
4799 case R_SH_DIR8WPZ
: mask
= 1; break;
4800 case R_SH_DIR8WPL
: mask
= 3; break;
4801 default: mask
= 0; break;
4805 ((*_bfd_error_handler
)
4806 (_("%B: 0x%lx: fatal: unaligned branch target for relax-support relocation"),
4807 input_section
->owner
,
4808 (unsigned long) rel
->r_offset
));
4809 bfd_set_error (bfd_error_bad_value
);
4813 goto final_link_relocate
;
4819 #ifdef INCLUDE_SHMEDIA
4820 if (shmedia_prepare_reloc (info
, input_bfd
, input_section
,
4821 contents
, rel
, &relocation
))
4822 goto final_link_relocate
;
4824 bfd_set_error (bfd_error_bad_value
);
4832 goto final_link_relocate
;
4838 ((*_bfd_error_handler
)
4839 (_("%B: 0x%lx: fatal: unaligned %s relocation 0x%lx"),
4840 input_section
->owner
,
4841 (unsigned long) rel
->r_offset
, howto
->name
,
4842 (unsigned long) relocation
));
4843 bfd_set_error (bfd_error_bad_value
);
4846 goto final_link_relocate
;
4853 ((*_bfd_error_handler
)
4854 (_("%B: 0x%lx: fatal: unaligned %s relocation 0x%lx"),
4855 input_section
->owner
,
4856 (unsigned long) rel
->r_offset
, howto
->name
,
4857 (unsigned long) relocation
));
4858 bfd_set_error (bfd_error_bad_value
);
4861 goto final_link_relocate
;
4864 if ((signed int)relocation
< -32
4865 || (signed int)relocation
> 32)
4867 ((*_bfd_error_handler
)
4868 (_("%B: 0x%lx: fatal: R_SH_PSHA relocation %d not in range -32..32"),
4869 input_section
->owner
,
4870 (unsigned long) rel
->r_offset
,
4871 (unsigned long) relocation
));
4872 bfd_set_error (bfd_error_bad_value
);
4875 goto final_link_relocate
;
4878 if ((signed int)relocation
< -16
4879 || (signed int)relocation
> 16)
4881 ((*_bfd_error_handler
)
4882 (_("%B: 0x%lx: fatal: R_SH_PSHL relocation %d not in range -32..32"),
4883 input_section
->owner
,
4884 (unsigned long) rel
->r_offset
,
4885 (unsigned long) relocation
));
4886 bfd_set_error (bfd_error_bad_value
);
4889 goto final_link_relocate
;
4893 #ifdef INCLUDE_SHMEDIA
4894 case R_SH_IMM_LOW16_PCREL
:
4895 case R_SH_IMM_MEDLOW16_PCREL
:
4896 case R_SH_IMM_MEDHI16_PCREL
:
4897 case R_SH_IMM_HI16_PCREL
:
4901 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4902 || h
->root
.type
!= bfd_link_hash_undefweak
)
4904 && (input_section
->flags
& SEC_ALLOC
) != 0
4905 && (r_type
== R_SH_DIR32
4906 || !SYMBOL_CALLS_LOCAL (info
, h
)))
4908 Elf_Internal_Rela outrel
;
4910 bfd_boolean skip
, relocate
;
4912 /* When generating a shared object, these relocations
4913 are copied into the output file to be resolved at run
4920 name
= (bfd_elf_string_from_elf_section
4922 elf_elfheader (input_bfd
)->e_shstrndx
,
4923 elf_section_data (input_section
)->rel_hdr
.sh_name
));
4927 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
4928 && strcmp (bfd_get_section_name (input_bfd
,
4932 sreloc
= bfd_get_section_by_name (dynobj
, name
);
4933 BFD_ASSERT (sreloc
!= NULL
);
4940 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4942 if (outrel
.r_offset
== (bfd_vma
) -1)
4944 else if (outrel
.r_offset
== (bfd_vma
) -2)
4945 skip
= TRUE
, relocate
= TRUE
;
4946 outrel
.r_offset
+= (input_section
->output_section
->vma
4947 + input_section
->output_offset
);
4950 memset (&outrel
, 0, sizeof outrel
);
4951 else if (r_type
== R_SH_REL32
)
4953 BFD_ASSERT (h
!= NULL
&& h
->dynindx
!= -1);
4954 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_REL32
);
4956 = bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4958 #ifdef INCLUDE_SHMEDIA
4959 else if (r_type
== R_SH_IMM_LOW16_PCREL
4960 || r_type
== R_SH_IMM_MEDLOW16_PCREL
4961 || r_type
== R_SH_IMM_MEDHI16_PCREL
4962 || r_type
== R_SH_IMM_HI16_PCREL
)
4964 BFD_ASSERT (h
!= NULL
&& h
->dynindx
!= -1);
4965 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
4966 outrel
.r_addend
= addend
;
4971 /* h->dynindx may be -1 if this symbol was marked to
4974 || ((info
->symbolic
|| h
->dynindx
== -1)
4978 outrel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
4980 = relocation
+ bfd_get_32 (input_bfd
,
4981 contents
+ rel
->r_offset
);
4985 BFD_ASSERT (h
->dynindx
!= -1);
4986 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_DIR32
);
4988 = relocation
+ bfd_get_32 (input_bfd
,
4989 contents
+ rel
->r_offset
);
4993 loc
= sreloc
->contents
;
4994 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4995 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4997 /* If this reloc is against an external symbol, we do
4998 not want to fiddle with the addend. Otherwise, we
4999 need to include the symbol value so that it becomes
5000 an addend for the dynamic reloc. */
5004 goto final_link_relocate
;
5007 #ifdef INCLUDE_SHMEDIA
5008 case R_SH_GOTPLT_LOW16
:
5009 case R_SH_GOTPLT_MEDLOW16
:
5010 case R_SH_GOTPLT_MEDHI16
:
5011 case R_SH_GOTPLT_HI16
:
5012 case R_SH_GOTPLT10BY4
:
5013 case R_SH_GOTPLT10BY8
:
5015 /* Relocation is to the entry for this symbol in the
5016 procedure linkage table. */
5023 || h
->plt
.offset
== (bfd_vma
) -1
5024 || h
->got
.offset
!= (bfd_vma
) -1)
5027 /* Relocation is to the entry for this symbol in the global
5028 offset table extension for the procedure linkage table. */
5030 BFD_ASSERT (sgotplt
!= NULL
);
5031 relocation
= (sgotplt
->output_offset
5032 + ((h
->plt
.offset
/ elf_sh_sizeof_plt (info
)
5036 relocation
-= GOT_BIAS
;
5039 goto final_link_relocate
;
5043 #ifdef INCLUDE_SHMEDIA
5044 case R_SH_GOT_LOW16
:
5045 case R_SH_GOT_MEDLOW16
:
5046 case R_SH_GOT_MEDHI16
:
5051 /* Relocation is to the entry for this symbol in the global
5054 BFD_ASSERT (sgot
!= NULL
);
5060 off
= h
->got
.offset
;
5061 #ifdef INCLUDE_SHMEDIA
5062 if (seen_stt_datalabel
)
5064 struct elf_sh_link_hash_entry
*hsh
;
5066 hsh
= (struct elf_sh_link_hash_entry
*)h
;
5067 off
= hsh
->datalabel_got
.offset
;
5070 BFD_ASSERT (off
!= (bfd_vma
) -1);
5072 dyn
= htab
->root
.dynamic_sections_created
;
5073 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
5075 && SYMBOL_REFERENCES_LOCAL (info
, h
))
5076 || (ELF_ST_VISIBILITY (h
->other
)
5077 && h
->root
.type
== bfd_link_hash_undefweak
))
5079 /* This is actually a static link, or it is a
5080 -Bsymbolic link and the symbol is defined
5081 locally, or the symbol was forced to be local
5082 because of a version file. We must initialize
5083 this entry in the global offset table. Since the
5084 offset must always be a multiple of 4, we use the
5085 least significant bit to record whether we have
5086 initialized it already.
5088 When doing a dynamic link, we create a .rela.got
5089 relocation entry to initialize the value. This
5090 is done in the finish_dynamic_symbol routine. */
5095 bfd_put_32 (output_bfd
, relocation
,
5096 sgot
->contents
+ off
);
5097 #ifdef INCLUDE_SHMEDIA
5098 if (seen_stt_datalabel
)
5100 struct elf_sh_link_hash_entry
*hsh
;
5102 hsh
= (struct elf_sh_link_hash_entry
*)h
;
5103 hsh
->datalabel_got
.offset
|= 1;
5111 relocation
= sgot
->output_offset
+ off
;
5115 #ifdef INCLUDE_SHMEDIA
5118 BFD_ASSERT (local_got_offsets
!= NULL
5119 && (local_got_offsets
[symtab_hdr
->sh_info
5123 off
= local_got_offsets
[symtab_hdr
->sh_info
5129 BFD_ASSERT (local_got_offsets
!= NULL
5130 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
5132 off
= local_got_offsets
[r_symndx
];
5133 #ifdef INCLUDE_SHMEDIA
5137 /* The offset must always be a multiple of 4. We use
5138 the least significant bit to record whether we have
5139 already generated the necessary reloc. */
5144 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
5148 Elf_Internal_Rela outrel
;
5151 if (srelgot
== NULL
)
5153 srelgot
= bfd_get_section_by_name (dynobj
,
5155 BFD_ASSERT (srelgot
!= NULL
);
5158 outrel
.r_offset
= (sgot
->output_section
->vma
5159 + sgot
->output_offset
5161 outrel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
5162 outrel
.r_addend
= relocation
;
5163 loc
= srelgot
->contents
;
5164 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5165 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5168 #ifdef INCLUDE_SHMEDIA
5170 local_got_offsets
[symtab_hdr
->sh_info
+ r_symndx
] |= 1;
5173 local_got_offsets
[r_symndx
] |= 1;
5176 relocation
= sgot
->output_offset
+ off
;
5180 relocation
-= GOT_BIAS
;
5183 goto final_link_relocate
;
5186 #ifdef INCLUDE_SHMEDIA
5187 case R_SH_GOTOFF_LOW16
:
5188 case R_SH_GOTOFF_MEDLOW16
:
5189 case R_SH_GOTOFF_MEDHI16
:
5190 case R_SH_GOTOFF_HI16
:
5192 /* Relocation is relative to the start of the global offset
5195 BFD_ASSERT (sgot
!= NULL
);
5197 /* Note that sgot->output_offset is not involved in this
5198 calculation. We always want the start of .got. If we
5199 defined _GLOBAL_OFFSET_TABLE in a different way, as is
5200 permitted by the ABI, we might have to change this
5202 relocation
-= sgot
->output_section
->vma
;
5205 relocation
-= GOT_BIAS
;
5208 addend
= rel
->r_addend
;
5210 goto final_link_relocate
;
5213 #ifdef INCLUDE_SHMEDIA
5214 case R_SH_GOTPC_LOW16
:
5215 case R_SH_GOTPC_MEDLOW16
:
5216 case R_SH_GOTPC_MEDHI16
:
5217 case R_SH_GOTPC_HI16
:
5219 /* Use global offset table as symbol value. */
5221 BFD_ASSERT (sgot
!= NULL
);
5222 relocation
= sgot
->output_section
->vma
;
5225 relocation
+= GOT_BIAS
;
5228 addend
= rel
->r_addend
;
5230 goto final_link_relocate
;
5233 #ifdef INCLUDE_SHMEDIA
5234 case R_SH_PLT_LOW16
:
5235 case R_SH_PLT_MEDLOW16
:
5236 case R_SH_PLT_MEDHI16
:
5239 /* Relocation is to the entry for this symbol in the
5240 procedure linkage table. */
5242 /* Resolve a PLT reloc against a local symbol directly,
5243 without using the procedure linkage table. */
5245 goto final_link_relocate
;
5247 if (h
->forced_local
)
5248 goto final_link_relocate
;
5250 if (h
->plt
.offset
== (bfd_vma
) -1)
5252 /* We didn't make a PLT entry for this symbol. This
5253 happens when statically linking PIC code, or when
5254 using -Bsymbolic. */
5255 goto final_link_relocate
;
5258 BFD_ASSERT (splt
!= NULL
);
5259 relocation
= (splt
->output_section
->vma
5260 + splt
->output_offset
5263 #ifdef INCLUDE_SHMEDIA
5267 addend
= rel
->r_addend
;
5269 goto final_link_relocate
;
5271 case R_SH_LOOP_START
:
5273 static bfd_vma start
, end
;
5275 start
= (relocation
+ rel
->r_addend
5276 - (sec
->output_section
->vma
+ sec
->output_offset
));
5277 r
= sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
,
5278 rel
->r_offset
, sec
, start
, end
);
5282 end
= (relocation
+ rel
->r_addend
5283 - (sec
->output_section
->vma
+ sec
->output_offset
));
5284 r
= sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
,
5285 rel
->r_offset
, sec
, start
, end
);
5289 case R_SH_TLS_GD_32
:
5290 case R_SH_TLS_IE_32
:
5291 r_type
= sh_elf_optimized_tls_reloc (info
, r_type
, h
== NULL
);
5292 tls_type
= GOT_UNKNOWN
;
5293 if (h
== NULL
&& local_got_offsets
)
5294 tls_type
= sh_elf_local_got_tls_type (input_bfd
) [r_symndx
];
5297 tls_type
= sh_elf_hash_entry (h
)->tls_type
;
5299 && (h
->dynindx
== -1
5301 r_type
= R_SH_TLS_LE_32
;
5304 if (r_type
== R_SH_TLS_GD_32
&& tls_type
== GOT_TLS_IE
)
5305 r_type
= R_SH_TLS_IE_32
;
5307 if (r_type
== R_SH_TLS_LE_32
)
5310 unsigned short insn
;
5312 if (ELF32_R_TYPE (rel
->r_info
) == R_SH_TLS_GD_32
)
5314 /* GD->LE transition:
5315 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5316 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5317 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5319 mov.l 1f,r4; stc gbr,r0; add r4,r0; nop;
5321 1: .long x@TPOFF; 2: .long __tls_get_addr@PLT; 3:. */
5323 offset
= rel
->r_offset
;
5324 BFD_ASSERT (offset
>= 16);
5325 /* Size of GD instructions is 16 or 18. */
5327 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5328 if ((insn
& 0xff00) == 0xc700)
5330 BFD_ASSERT (offset
>= 2);
5332 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5335 BFD_ASSERT ((insn
& 0xff00) == 0xd400);
5336 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5337 BFD_ASSERT ((insn
& 0xff00) == 0xc700);
5338 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5339 BFD_ASSERT ((insn
& 0xff00) == 0xd100);
5340 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 6);
5341 BFD_ASSERT (insn
== 0x310c);
5342 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 8);
5343 BFD_ASSERT (insn
== 0x410b);
5344 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 10);
5345 BFD_ASSERT (insn
== 0x34cc);
5347 bfd_put_16 (output_bfd
, 0x0012, contents
+ offset
+ 2);
5348 bfd_put_16 (output_bfd
, 0x304c, contents
+ offset
+ 4);
5349 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 6);
5350 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 8);
5351 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 10);
5357 /* IE->LE transition:
5358 mov.l 1f,r0; stc gbr,rN; mov.l @(r0,r12),rM;
5359 bra 2f; add ...; .align 2; 1: x@GOTTPOFF; 2:
5361 mov.l .Ln,rM; stc gbr,rN; nop; ...;
5364 offset
= rel
->r_offset
;
5365 BFD_ASSERT (offset
>= 16);
5366 /* Size of IE instructions is 10 or 12. */
5368 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5369 if ((insn
& 0xf0ff) == 0x0012)
5371 BFD_ASSERT (offset
>= 2);
5373 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5376 BFD_ASSERT ((insn
& 0xff00) == 0xd000);
5377 index
= insn
& 0x00ff;
5378 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5379 BFD_ASSERT ((insn
& 0xf0ff) == 0x0012);
5380 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5381 BFD_ASSERT ((insn
& 0xf0ff) == 0x00ce);
5382 insn
= 0xd000 | (insn
& 0x0f00) | index
;
5383 bfd_put_16 (output_bfd
, insn
, contents
+ offset
+ 0);
5384 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 4);
5387 bfd_put_32 (output_bfd
, tpoff (info
, relocation
),
5388 contents
+ rel
->r_offset
);
5397 off
= h
->got
.offset
;
5400 if (local_got_offsets
== NULL
)
5403 off
= local_got_offsets
[r_symndx
];
5406 /* Relocate R_SH_TLS_IE_32 directly when statically linking. */
5407 if (r_type
== R_SH_TLS_IE_32
5408 && ! htab
->root
.dynamic_sections_created
)
5411 bfd_put_32 (output_bfd
, tpoff (info
, relocation
),
5412 sgot
->contents
+ off
);
5413 bfd_put_32 (output_bfd
, sgot
->output_offset
+ off
,
5414 contents
+ rel
->r_offset
);
5422 Elf_Internal_Rela outrel
;
5426 if (srelgot
== NULL
)
5428 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
5429 BFD_ASSERT (srelgot
!= NULL
);
5432 outrel
.r_offset
= (sgot
->output_section
->vma
5433 + sgot
->output_offset
+ off
);
5435 if (h
== NULL
|| h
->dynindx
== -1)
5440 dr_type
= (r_type
== R_SH_TLS_GD_32
? R_SH_TLS_DTPMOD32
:
5442 if (dr_type
== R_SH_TLS_TPOFF32
&& indx
== 0)
5443 outrel
.r_addend
= relocation
- dtpoff_base (info
);
5445 outrel
.r_addend
= 0;
5446 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
5447 loc
= srelgot
->contents
;
5448 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5449 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5451 if (r_type
== R_SH_TLS_GD_32
)
5455 bfd_put_32 (output_bfd
,
5456 relocation
- dtpoff_base (info
),
5457 sgot
->contents
+ off
+ 4);
5461 outrel
.r_info
= ELF32_R_INFO (indx
,
5463 outrel
.r_offset
+= 4;
5464 outrel
.r_addend
= 0;
5465 srelgot
->reloc_count
++;
5466 loc
+= sizeof (Elf32_External_Rela
);
5467 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5474 local_got_offsets
[r_symndx
] |= 1;
5477 if (off
>= (bfd_vma
) -2)
5480 if (r_type
== (int) ELF32_R_TYPE (rel
->r_info
))
5481 relocation
= sgot
->output_offset
+ off
;
5485 unsigned short insn
;
5487 /* GD->IE transition:
5488 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5489 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5490 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5492 mov.l 1f,r0; stc gbr,r4; mov.l @(r0,r12),r0; add r4,r0;
5493 nop; nop; bra 3f; nop; .align 2;
5494 1: .long x@TPOFF; 2:...; 3:. */
5496 offset
= rel
->r_offset
;
5497 BFD_ASSERT (offset
>= 16);
5498 /* Size of GD instructions is 16 or 18. */
5500 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5501 if ((insn
& 0xff00) == 0xc700)
5503 BFD_ASSERT (offset
>= 2);
5505 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5508 BFD_ASSERT ((insn
& 0xff00) == 0xd400);
5510 /* Replace mov.l 1f,R4 with mov.l 1f,r0. */
5511 bfd_put_16 (output_bfd
, insn
& 0xf0ff, contents
+ offset
);
5513 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5514 BFD_ASSERT ((insn
& 0xff00) == 0xc700);
5515 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5516 BFD_ASSERT ((insn
& 0xff00) == 0xd100);
5517 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 6);
5518 BFD_ASSERT (insn
== 0x310c);
5519 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 8);
5520 BFD_ASSERT (insn
== 0x410b);
5521 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 10);
5522 BFD_ASSERT (insn
== 0x34cc);
5524 bfd_put_16 (output_bfd
, 0x0412, contents
+ offset
+ 2);
5525 bfd_put_16 (output_bfd
, 0x00ce, contents
+ offset
+ 4);
5526 bfd_put_16 (output_bfd
, 0x304c, contents
+ offset
+ 6);
5527 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 8);
5528 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 10);
5530 bfd_put_32 (output_bfd
, sgot
->output_offset
+ off
,
5531 contents
+ rel
->r_offset
);
5536 addend
= rel
->r_addend
;
5538 goto final_link_relocate
;
5540 case R_SH_TLS_LD_32
:
5544 unsigned short insn
;
5546 /* LD->LE transition:
5547 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5548 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5549 1: .long x$TLSLD; 2: .long __tls_get_addr@PLT; 3:
5551 stc gbr,r0; nop; nop; nop;
5552 nop; nop; bra 3f; ...; 3:. */
5554 offset
= rel
->r_offset
;
5555 BFD_ASSERT (offset
>= 16);
5556 /* Size of LD instructions is 16 or 18. */
5558 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5559 if ((insn
& 0xff00) == 0xc700)
5561 BFD_ASSERT (offset
>= 2);
5563 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5566 BFD_ASSERT ((insn
& 0xff00) == 0xd400);
5567 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5568 BFD_ASSERT ((insn
& 0xff00) == 0xc700);
5569 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5570 BFD_ASSERT ((insn
& 0xff00) == 0xd100);
5571 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 6);
5572 BFD_ASSERT (insn
== 0x310c);
5573 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 8);
5574 BFD_ASSERT (insn
== 0x410b);
5575 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 10);
5576 BFD_ASSERT (insn
== 0x34cc);
5578 bfd_put_16 (output_bfd
, 0x0012, contents
+ offset
+ 0);
5579 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 2);
5580 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 4);
5581 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 6);
5582 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 8);
5583 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 10);
5592 off
= htab
->tls_ldm_got
.offset
;
5597 Elf_Internal_Rela outrel
;
5600 srelgot
= htab
->srelgot
;
5601 if (srelgot
== NULL
)
5604 outrel
.r_offset
= (sgot
->output_section
->vma
5605 + sgot
->output_offset
+ off
);
5606 outrel
.r_addend
= 0;
5607 outrel
.r_info
= ELF32_R_INFO (0, R_SH_TLS_DTPMOD32
);
5608 loc
= srelgot
->contents
;
5609 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5610 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5611 htab
->tls_ldm_got
.offset
|= 1;
5614 relocation
= sgot
->output_offset
+ off
;
5615 addend
= rel
->r_addend
;
5617 goto final_link_relocate
;
5619 case R_SH_TLS_LDO_32
:
5621 relocation
= tpoff (info
, relocation
);
5623 relocation
-= dtpoff_base (info
);
5625 addend
= rel
->r_addend
;
5626 goto final_link_relocate
;
5628 case R_SH_TLS_LE_32
:
5631 Elf_Internal_Rela outrel
;
5636 relocation
= tpoff (info
, relocation
);
5637 addend
= rel
->r_addend
;
5638 goto final_link_relocate
;
5645 name
= (bfd_elf_string_from_elf_section
5647 elf_elfheader (input_bfd
)->e_shstrndx
,
5648 elf_section_data (input_section
)->rel_hdr
.sh_name
));
5652 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5653 && strcmp (bfd_get_section_name (input_bfd
,
5657 sreloc
= bfd_get_section_by_name (dynobj
, name
);
5658 BFD_ASSERT (sreloc
!= NULL
);
5661 if (h
== NULL
|| h
->dynindx
== -1)
5666 outrel
.r_offset
= (input_section
->output_section
->vma
5667 + input_section
->output_offset
5669 outrel
.r_info
= ELF32_R_INFO (indx
, R_SH_TLS_TPOFF32
);
5671 outrel
.r_addend
= relocation
- dtpoff_base (info
);
5673 outrel
.r_addend
= 0;
5675 loc
= sreloc
->contents
;
5676 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5677 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5683 if (r
!= bfd_reloc_ok
)
5688 case bfd_reloc_outofrange
:
5690 case bfd_reloc_overflow
:
5698 name
= (bfd_elf_string_from_elf_section
5699 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
5703 name
= bfd_section_name (input_bfd
, sec
);
5705 if (! ((*info
->callbacks
->reloc_overflow
)
5706 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
5707 (bfd_vma
) 0, input_bfd
, input_section
,
5719 /* This is a version of bfd_generic_get_relocated_section_contents
5720 which uses sh_elf_relocate_section. */
5723 sh_elf_get_relocated_section_contents (bfd
*output_bfd
,
5724 struct bfd_link_info
*link_info
,
5725 struct bfd_link_order
*link_order
,
5727 bfd_boolean relocatable
,
5730 Elf_Internal_Shdr
*symtab_hdr
;
5731 asection
*input_section
= link_order
->u
.indirect
.section
;
5732 bfd
*input_bfd
= input_section
->owner
;
5733 asection
**sections
= NULL
;
5734 Elf_Internal_Rela
*internal_relocs
= NULL
;
5735 Elf_Internal_Sym
*isymbuf
= NULL
;
5737 /* We only need to handle the case of relaxing, or of having a
5738 particular set of section contents, specially. */
5740 || elf_section_data (input_section
)->this_hdr
.contents
== NULL
)
5741 return bfd_generic_get_relocated_section_contents (output_bfd
, link_info
,
5746 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5748 memcpy (data
, elf_section_data (input_section
)->this_hdr
.contents
,
5749 (size_t) input_section
->size
);
5751 if ((input_section
->flags
& SEC_RELOC
) != 0
5752 && input_section
->reloc_count
> 0)
5755 Elf_Internal_Sym
*isym
, *isymend
;
5758 internal_relocs
= (_bfd_elf_link_read_relocs
5759 (input_bfd
, input_section
, NULL
,
5760 (Elf_Internal_Rela
*) NULL
, FALSE
));
5761 if (internal_relocs
== NULL
)
5764 if (symtab_hdr
->sh_info
!= 0)
5766 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5767 if (isymbuf
== NULL
)
5768 isymbuf
= bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
5769 symtab_hdr
->sh_info
, 0,
5771 if (isymbuf
== NULL
)
5775 amt
= symtab_hdr
->sh_info
;
5776 amt
*= sizeof (asection
*);
5777 sections
= (asection
**) bfd_malloc (amt
);
5778 if (sections
== NULL
&& amt
!= 0)
5781 isymend
= isymbuf
+ symtab_hdr
->sh_info
;
5782 for (isym
= isymbuf
, secpp
= sections
; isym
< isymend
; ++isym
, ++secpp
)
5786 if (isym
->st_shndx
== SHN_UNDEF
)
5787 isec
= bfd_und_section_ptr
;
5788 else if (isym
->st_shndx
== SHN_ABS
)
5789 isec
= bfd_abs_section_ptr
;
5790 else if (isym
->st_shndx
== SHN_COMMON
)
5791 isec
= bfd_com_section_ptr
;
5793 isec
= bfd_section_from_elf_index (input_bfd
, isym
->st_shndx
);
5798 if (! sh_elf_relocate_section (output_bfd
, link_info
, input_bfd
,
5799 input_section
, data
, internal_relocs
,
5803 if (sections
!= NULL
)
5806 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
5808 if (elf_section_data (input_section
)->relocs
!= internal_relocs
)
5809 free (internal_relocs
);
5815 if (sections
!= NULL
)
5818 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
5820 if (internal_relocs
!= NULL
5821 && elf_section_data (input_section
)->relocs
!= internal_relocs
)
5822 free (internal_relocs
);
5826 /* Return the base VMA address which should be subtracted from real addresses
5827 when resolving @dtpoff relocation.
5828 This is PT_TLS segment p_vaddr. */
5831 dtpoff_base (struct bfd_link_info
*info
)
5833 /* If tls_sec is NULL, we should have signalled an error already. */
5834 if (elf_hash_table (info
)->tls_sec
== NULL
)
5836 return elf_hash_table (info
)->tls_sec
->vma
;
5839 /* Return the relocation value for R_SH_TLS_TPOFF32.. */
5842 tpoff (struct bfd_link_info
*info
, bfd_vma address
)
5844 /* If tls_sec is NULL, we should have signalled an error already. */
5845 if (elf_hash_table (info
)->tls_sec
== NULL
)
5847 /* SH TLS ABI is variant I and static TLS block start just after tcbhead
5848 structure which has 2 pointer fields. */
5849 return (address
- elf_hash_table (info
)->tls_sec
->vma
5850 + align_power ((bfd_vma
) 8,
5851 elf_hash_table (info
)->tls_sec
->alignment_power
));
5855 sh_elf_gc_mark_hook (asection
*sec
,
5856 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5857 Elf_Internal_Rela
*rel
, struct elf_link_hash_entry
*h
,
5858 Elf_Internal_Sym
*sym
)
5862 switch (ELF32_R_TYPE (rel
->r_info
))
5864 case R_SH_GNU_VTINHERIT
:
5865 case R_SH_GNU_VTENTRY
:
5869 #ifdef INCLUDE_SHMEDIA
5870 while (h
->root
.type
== bfd_link_hash_indirect
5871 && h
->root
.u
.i
.link
)
5872 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5874 switch (h
->root
.type
)
5876 case bfd_link_hash_defined
:
5877 case bfd_link_hash_defweak
:
5878 return h
->root
.u
.def
.section
;
5880 case bfd_link_hash_common
:
5881 return h
->root
.u
.c
.p
->section
;
5889 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
5894 /* Update the got entry reference counts for the section being removed. */
5897 sh_elf_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
5898 asection
*sec
, const Elf_Internal_Rela
*relocs
)
5900 Elf_Internal_Shdr
*symtab_hdr
;
5901 struct elf_link_hash_entry
**sym_hashes
;
5902 bfd_signed_vma
*local_got_refcounts
;
5903 const Elf_Internal_Rela
*rel
, *relend
;
5905 elf_section_data (sec
)->local_dynrel
= NULL
;
5907 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5908 sym_hashes
= elf_sym_hashes (abfd
);
5909 local_got_refcounts
= elf_local_got_refcounts (abfd
);
5911 relend
= relocs
+ sec
->reloc_count
;
5912 for (rel
= relocs
; rel
< relend
; rel
++)
5914 unsigned long r_symndx
;
5915 unsigned int r_type
;
5916 struct elf_link_hash_entry
*h
= NULL
;
5917 #ifdef INCLUDE_SHMEDIA
5918 int seen_stt_datalabel
= 0;
5921 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5922 if (r_symndx
>= symtab_hdr
->sh_info
)
5924 struct elf_sh_link_hash_entry
*eh
;
5925 struct elf_sh_dyn_relocs
**pp
;
5926 struct elf_sh_dyn_relocs
*p
;
5928 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5929 while (h
->root
.type
== bfd_link_hash_indirect
5930 || h
->root
.type
== bfd_link_hash_warning
)
5932 #ifdef INCLUDE_SHMEDIA
5933 seen_stt_datalabel
|= h
->type
== STT_DATALABEL
;
5935 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5937 eh
= (struct elf_sh_link_hash_entry
*) h
;
5938 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
5941 /* Everything must go for SEC. */
5947 r_type
= ELF32_R_TYPE (rel
->r_info
);
5948 switch (sh_elf_optimized_tls_reloc (info
, r_type
, h
!= NULL
))
5950 case R_SH_TLS_LD_32
:
5951 if (sh_elf_hash_table (info
)->tls_ldm_got
.refcount
> 0)
5952 sh_elf_hash_table (info
)->tls_ldm_got
.refcount
-= 1;
5958 #ifdef INCLUDE_SHMEDIA
5959 case R_SH_GOT_LOW16
:
5960 case R_SH_GOT_MEDLOW16
:
5961 case R_SH_GOT_MEDHI16
:
5965 case R_SH_GOTOFF_LOW16
:
5966 case R_SH_GOTOFF_MEDLOW16
:
5967 case R_SH_GOTOFF_MEDHI16
:
5968 case R_SH_GOTOFF_HI16
:
5969 case R_SH_GOTPC_LOW16
:
5970 case R_SH_GOTPC_MEDLOW16
:
5971 case R_SH_GOTPC_MEDHI16
:
5972 case R_SH_GOTPC_HI16
:
5974 case R_SH_TLS_GD_32
:
5975 case R_SH_TLS_IE_32
:
5978 #ifdef INCLUDE_SHMEDIA
5979 if (seen_stt_datalabel
)
5981 struct elf_sh_link_hash_entry
*eh
;
5982 eh
= (struct elf_sh_link_hash_entry
*) h
;
5983 if (eh
->datalabel_got
.refcount
> 0)
5984 eh
->datalabel_got
.refcount
-= 1;
5988 if (h
->got
.refcount
> 0)
5989 h
->got
.refcount
-= 1;
5991 else if (local_got_refcounts
!= NULL
)
5993 #ifdef INCLUDE_SHMEDIA
5994 if (rel
->r_addend
& 1)
5996 if (local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] > 0)
5997 local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] -= 1;
6001 if (local_got_refcounts
[r_symndx
] > 0)
6002 local_got_refcounts
[r_symndx
] -= 1;
6013 #ifdef INCLUDE_SHMEDIA
6014 case R_SH_PLT_LOW16
:
6015 case R_SH_PLT_MEDLOW16
:
6016 case R_SH_PLT_MEDHI16
:
6021 if (h
->plt
.refcount
> 0)
6022 h
->plt
.refcount
-= 1;
6027 #ifdef INCLUDE_SHMEDIA
6028 case R_SH_GOTPLT_LOW16
:
6029 case R_SH_GOTPLT_MEDLOW16
:
6030 case R_SH_GOTPLT_MEDHI16
:
6031 case R_SH_GOTPLT_HI16
:
6032 case R_SH_GOTPLT10BY4
:
6033 case R_SH_GOTPLT10BY8
:
6037 struct elf_sh_link_hash_entry
*eh
;
6038 eh
= (struct elf_sh_link_hash_entry
*) h
;
6039 if (eh
->gotplt_refcount
> 0)
6041 eh
->gotplt_refcount
-= 1;
6042 if (h
->plt
.refcount
> 0)
6043 h
->plt
.refcount
-= 1;
6045 #ifdef INCLUDE_SHMEDIA
6046 else if (seen_stt_datalabel
)
6048 if (eh
->datalabel_got
.refcount
> 0)
6049 eh
->datalabel_got
.refcount
-= 1;
6052 else if (h
->got
.refcount
> 0)
6053 h
->got
.refcount
-= 1;
6055 else if (local_got_refcounts
!= NULL
)
6057 #ifdef INCLUDE_SHMEDIA
6058 if (rel
->r_addend
& 1)
6060 if (local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] > 0)
6061 local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] -= 1;
6065 if (local_got_refcounts
[r_symndx
] > 0)
6066 local_got_refcounts
[r_symndx
] -= 1;
6078 /* Copy the extra info we tack onto an elf_link_hash_entry. */
6081 sh_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
6082 struct elf_link_hash_entry
*dir
,
6083 struct elf_link_hash_entry
*ind
)
6085 struct elf_sh_link_hash_entry
*edir
, *eind
;
6087 edir
= (struct elf_sh_link_hash_entry
*) dir
;
6088 eind
= (struct elf_sh_link_hash_entry
*) ind
;
6090 if (eind
->dyn_relocs
!= NULL
)
6092 if (edir
->dyn_relocs
!= NULL
)
6094 struct elf_sh_dyn_relocs
**pp
;
6095 struct elf_sh_dyn_relocs
*p
;
6097 /* Add reloc counts against the indirect sym to the direct sym
6098 list. Merge any entries against the same section. */
6099 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
6101 struct elf_sh_dyn_relocs
*q
;
6103 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
6104 if (q
->sec
== p
->sec
)
6106 q
->pc_count
+= p
->pc_count
;
6107 q
->count
+= p
->count
;
6114 *pp
= edir
->dyn_relocs
;
6117 edir
->dyn_relocs
= eind
->dyn_relocs
;
6118 eind
->dyn_relocs
= NULL
;
6120 edir
->gotplt_refcount
= eind
->gotplt_refcount
;
6121 eind
->gotplt_refcount
= 0;
6122 #ifdef INCLUDE_SHMEDIA
6123 edir
->datalabel_got
.refcount
+= eind
->datalabel_got
.refcount
;
6124 eind
->datalabel_got
.refcount
= 0;
6127 if (ind
->root
.type
== bfd_link_hash_indirect
6128 && dir
->got
.refcount
<= 0)
6130 edir
->tls_type
= eind
->tls_type
;
6131 eind
->tls_type
= GOT_UNKNOWN
;
6134 if (ind
->root
.type
!= bfd_link_hash_indirect
6135 && dir
->dynamic_adjusted
)
6137 /* If called to transfer flags for a weakdef during processing
6138 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
6139 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
6140 dir
->ref_dynamic
|= ind
->ref_dynamic
;
6141 dir
->ref_regular
|= ind
->ref_regular
;
6142 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
6143 dir
->needs_plt
|= ind
->needs_plt
;
6146 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
6150 sh_elf_optimized_tls_reloc (struct bfd_link_info
*info
, int r_type
,
6158 case R_SH_TLS_GD_32
:
6159 case R_SH_TLS_IE_32
:
6161 return R_SH_TLS_LE_32
;
6162 return R_SH_TLS_IE_32
;
6163 case R_SH_TLS_LD_32
:
6164 return R_SH_TLS_LE_32
;
6170 /* Look through the relocs for a section during the first phase.
6171 Since we don't do .gots or .plts, we just need to consider the
6172 virtual table relocs for gc. */
6175 sh_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
, asection
*sec
,
6176 const Elf_Internal_Rela
*relocs
)
6178 Elf_Internal_Shdr
*symtab_hdr
;
6179 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
6180 struct elf_sh_link_hash_table
*htab
;
6181 const Elf_Internal_Rela
*rel
;
6182 const Elf_Internal_Rela
*rel_end
;
6183 bfd_vma
*local_got_offsets
;
6187 unsigned int r_type
;
6188 int tls_type
, old_tls_type
;
6194 if (info
->relocatable
)
6197 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6198 sym_hashes
= elf_sym_hashes (abfd
);
6199 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/sizeof (Elf32_External_Sym
);
6200 if (!elf_bad_symtab (abfd
))
6201 sym_hashes_end
-= symtab_hdr
->sh_info
;
6203 htab
= sh_elf_hash_table (info
);
6204 local_got_offsets
= elf_local_got_offsets (abfd
);
6206 rel_end
= relocs
+ sec
->reloc_count
;
6207 for (rel
= relocs
; rel
< rel_end
; rel
++)
6209 struct elf_link_hash_entry
*h
;
6210 unsigned long r_symndx
;
6211 #ifdef INCLUDE_SHMEDIA
6212 int seen_stt_datalabel
= 0;
6215 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6216 r_type
= ELF32_R_TYPE (rel
->r_info
);
6218 if (r_symndx
< symtab_hdr
->sh_info
)
6222 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6223 while (h
->root
.type
== bfd_link_hash_indirect
6224 || h
->root
.type
== bfd_link_hash_warning
)
6226 #ifdef INCLUDE_SHMEDIA
6227 seen_stt_datalabel
|= h
->type
== STT_DATALABEL
;
6229 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6233 r_type
= sh_elf_optimized_tls_reloc (info
, r_type
, h
== NULL
);
6235 && r_type
== R_SH_TLS_IE_32
6237 && h
->root
.type
!= bfd_link_hash_undefined
6238 && h
->root
.type
!= bfd_link_hash_undefweak
6239 && (h
->dynindx
== -1
6241 r_type
= R_SH_TLS_LE_32
;
6243 /* Some relocs require a global offset table. */
6244 if (htab
->sgot
== NULL
)
6252 #ifdef INCLUDE_SHMEDIA
6253 case R_SH_GOTPLT_LOW16
:
6254 case R_SH_GOTPLT_MEDLOW16
:
6255 case R_SH_GOTPLT_MEDHI16
:
6256 case R_SH_GOTPLT_HI16
:
6257 case R_SH_GOTPLT10BY4
:
6258 case R_SH_GOTPLT10BY8
:
6259 case R_SH_GOT_LOW16
:
6260 case R_SH_GOT_MEDLOW16
:
6261 case R_SH_GOT_MEDHI16
:
6265 case R_SH_GOTOFF_LOW16
:
6266 case R_SH_GOTOFF_MEDLOW16
:
6267 case R_SH_GOTOFF_MEDHI16
:
6268 case R_SH_GOTOFF_HI16
:
6269 case R_SH_GOTPC_LOW16
:
6270 case R_SH_GOTPC_MEDLOW16
:
6271 case R_SH_GOTPC_MEDHI16
:
6272 case R_SH_GOTPC_HI16
:
6274 case R_SH_TLS_GD_32
:
6275 case R_SH_TLS_LD_32
:
6276 case R_SH_TLS_IE_32
:
6277 if (htab
->sgot
== NULL
)
6279 if (htab
->root
.dynobj
== NULL
)
6280 htab
->root
.dynobj
= abfd
;
6281 if (!create_got_section (htab
->root
.dynobj
, info
))
6293 /* This relocation describes the C++ object vtable hierarchy.
6294 Reconstruct it for later use during GC. */
6295 case R_SH_GNU_VTINHERIT
:
6296 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6300 /* This relocation describes which C++ vtable entries are actually
6301 used. Record for later use during GC. */
6302 case R_SH_GNU_VTENTRY
:
6303 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
6307 case R_SH_TLS_IE_32
:
6309 info
->flags
|= DF_STATIC_TLS
;
6313 case R_SH_TLS_GD_32
:
6315 #ifdef INCLUDE_SHMEDIA
6316 case R_SH_GOT_LOW16
:
6317 case R_SH_GOT_MEDLOW16
:
6318 case R_SH_GOT_MEDHI16
:
6326 tls_type
= GOT_NORMAL
;
6328 case R_SH_TLS_GD_32
:
6329 tls_type
= GOT_TLS_GD
;
6331 case R_SH_TLS_IE_32
:
6332 tls_type
= GOT_TLS_IE
;
6338 #ifdef INCLUDE_SHMEDIA
6339 if (seen_stt_datalabel
)
6341 struct elf_sh_link_hash_entry
*eh
6342 = (struct elf_sh_link_hash_entry
*) h
;
6344 eh
->datalabel_got
.refcount
+= 1;
6348 h
->got
.refcount
+= 1;
6349 old_tls_type
= sh_elf_hash_entry (h
)->tls_type
;
6353 bfd_signed_vma
*local_got_refcounts
;
6355 /* This is a global offset table entry for a local
6357 local_got_refcounts
= elf_local_got_refcounts (abfd
);
6358 if (local_got_refcounts
== NULL
)
6362 size
= symtab_hdr
->sh_info
;
6363 size
*= sizeof (bfd_signed_vma
);
6364 #ifdef INCLUDE_SHMEDIA
6365 /* Reserve space for both the datalabel and
6366 codelabel local GOT offsets. */
6369 size
+= symtab_hdr
->sh_info
;
6370 local_got_refcounts
= ((bfd_signed_vma
*)
6371 bfd_zalloc (abfd
, size
));
6372 if (local_got_refcounts
== NULL
)
6374 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
6375 #ifdef INCLUDE_SHMEDIA
6376 /* Take care of both the datalabel and codelabel local
6378 sh_elf_local_got_tls_type (abfd
)
6379 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
6381 sh_elf_local_got_tls_type (abfd
)
6382 = (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
6385 #ifdef INCLUDE_SHMEDIA
6386 if (rel
->r_addend
& 1)
6387 local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] += 1;
6390 local_got_refcounts
[r_symndx
] += 1;
6391 old_tls_type
= sh_elf_local_got_tls_type (abfd
) [r_symndx
];
6394 /* If a TLS symbol is accessed using IE at least once,
6395 there is no point to use dynamic model for it. */
6396 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
6397 && (old_tls_type
!= GOT_TLS_GD
|| tls_type
!= GOT_TLS_IE
))
6399 if (old_tls_type
== GOT_TLS_IE
&& tls_type
== GOT_TLS_GD
)
6400 tls_type
= GOT_TLS_IE
;
6403 (*_bfd_error_handler
)
6404 (_("%B: `%s' accessed both as normal and thread local symbol"),
6405 abfd
, h
->root
.root
.string
);
6410 if (old_tls_type
!= tls_type
)
6413 sh_elf_hash_entry (h
)->tls_type
= tls_type
;
6415 sh_elf_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
6420 case R_SH_TLS_LD_32
:
6421 sh_elf_hash_table(info
)->tls_ldm_got
.refcount
+= 1;
6425 #ifdef INCLUDE_SHMEDIA
6426 case R_SH_GOTPLT_LOW16
:
6427 case R_SH_GOTPLT_MEDLOW16
:
6428 case R_SH_GOTPLT_MEDHI16
:
6429 case R_SH_GOTPLT_HI16
:
6430 case R_SH_GOTPLT10BY4
:
6431 case R_SH_GOTPLT10BY8
:
6433 /* If this is a local symbol, we resolve it directly without
6434 creating a procedure linkage table entry. */
6440 || h
->dynindx
== -1)
6444 h
->plt
.refcount
+= 1;
6445 ((struct elf_sh_link_hash_entry
*) h
)->gotplt_refcount
+= 1;
6450 #ifdef INCLUDE_SHMEDIA
6451 case R_SH_PLT_LOW16
:
6452 case R_SH_PLT_MEDLOW16
:
6453 case R_SH_PLT_MEDHI16
:
6456 /* This symbol requires a procedure linkage table entry. We
6457 actually build the entry in adjust_dynamic_symbol,
6458 because this might be a case of linking PIC code which is
6459 never referenced by a dynamic object, in which case we
6460 don't need to generate a procedure linkage table entry
6463 /* If this is a local symbol, we resolve it directly without
6464 creating a procedure linkage table entry. */
6468 if (h
->forced_local
)
6472 h
->plt
.refcount
+= 1;
6477 #ifdef INCLUDE_SHMEDIA
6478 case R_SH_IMM_LOW16_PCREL
:
6479 case R_SH_IMM_MEDLOW16_PCREL
:
6480 case R_SH_IMM_MEDHI16_PCREL
:
6481 case R_SH_IMM_HI16_PCREL
:
6483 if (h
!= NULL
&& ! info
->shared
)
6486 h
->plt
.refcount
+= 1;
6489 /* If we are creating a shared library, and this is a reloc
6490 against a global symbol, or a non PC relative reloc
6491 against a local symbol, then we need to copy the reloc
6492 into the shared library. However, if we are linking with
6493 -Bsymbolic, we do not need to copy a reloc against a
6494 global symbol which is defined in an object we are
6495 including in the link (i.e., DEF_REGULAR is set). At
6496 this point we have not seen all the input files, so it is
6497 possible that DEF_REGULAR is not set now but will be set
6498 later (it is never cleared). We account for that
6499 possibility below by storing information in the
6500 dyn_relocs field of the hash table entry. A similar
6501 situation occurs when creating shared libraries and symbol
6502 visibility changes render the symbol local.
6504 If on the other hand, we are creating an executable, we
6505 may need to keep relocations for symbols satisfied by a
6506 dynamic library if we manage to avoid copy relocs for the
6509 && (sec
->flags
& SEC_ALLOC
) != 0
6510 && (r_type
!= R_SH_REL32
6512 && (! info
->symbolic
6513 || h
->root
.type
== bfd_link_hash_defweak
6514 || !h
->def_regular
))))
6516 && (sec
->flags
& SEC_ALLOC
) != 0
6518 && (h
->root
.type
== bfd_link_hash_defweak
6519 || !h
->def_regular
)))
6521 struct elf_sh_dyn_relocs
*p
;
6522 struct elf_sh_dyn_relocs
**head
;
6524 if (htab
->root
.dynobj
== NULL
)
6525 htab
->root
.dynobj
= abfd
;
6527 /* When creating a shared object, we must copy these
6528 reloc types into the output file. We create a reloc
6529 section in dynobj and make room for this reloc. */
6534 name
= (bfd_elf_string_from_elf_section
6536 elf_elfheader (abfd
)->e_shstrndx
,
6537 elf_section_data (sec
)->rel_hdr
.sh_name
));
6541 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
6542 && strcmp (bfd_get_section_name (abfd
, sec
),
6545 sreloc
= bfd_get_section_by_name (htab
->root
.dynobj
, name
);
6550 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
6551 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
6552 if ((sec
->flags
& SEC_ALLOC
) != 0)
6553 flags
|= SEC_ALLOC
| SEC_LOAD
;
6554 sreloc
= bfd_make_section_with_flags (htab
->root
.dynobj
,
6558 || ! bfd_set_section_alignment (htab
->root
.dynobj
,
6562 elf_section_data (sec
)->sreloc
= sreloc
;
6565 /* If this is a global symbol, we count the number of
6566 relocations we need for this symbol. */
6568 head
= &((struct elf_sh_link_hash_entry
*) h
)->dyn_relocs
;
6574 /* Track dynamic relocs needed for local syms too. */
6575 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
6580 vpp
= &elf_section_data (s
)->local_dynrel
;
6581 head
= (struct elf_sh_dyn_relocs
**) vpp
;
6585 if (p
== NULL
|| p
->sec
!= sec
)
6587 bfd_size_type amt
= sizeof (*p
);
6588 p
= bfd_alloc (htab
->root
.dynobj
, amt
);
6599 if (r_type
== R_SH_REL32
6600 #ifdef INCLUDE_SHMEDIA
6601 || r_type
== R_SH_IMM_LOW16_PCREL
6602 || r_type
== R_SH_IMM_MEDLOW16_PCREL
6603 || r_type
== R_SH_IMM_MEDHI16_PCREL
6604 || r_type
== R_SH_IMM_HI16_PCREL
6612 case R_SH_TLS_LE_32
:
6615 (*_bfd_error_handler
)
6616 (_("%B: TLS local exec code cannot be linked into shared objects"),
6623 case R_SH_TLS_LDO_32
:
6624 /* Nothing to do. */
6635 #ifndef sh_elf_set_mach_from_flags
6636 static unsigned int sh_ef_bfd_table
[] = { EF_SH_BFD_TABLE
};
6639 sh_elf_set_mach_from_flags (bfd
*abfd
)
6641 flagword flags
= elf_elfheader (abfd
)->e_flags
& EF_SH_MACH_MASK
;
6643 if (flags
>= sizeof(sh_ef_bfd_table
))
6646 if (sh_ef_bfd_table
[flags
] == 0)
6649 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, sh_ef_bfd_table
[flags
]);
6655 /* Reverse table lookup for sh_ef_bfd_table[].
6656 Given a bfd MACH value from archures.c
6657 return the equivalent ELF flags from the table.
6658 Return -1 if no match is found. */
6661 sh_elf_get_flags_from_mach (unsigned long mach
)
6663 int i
= ARRAY_SIZE (sh_ef_bfd_table
) - 1;
6666 if (sh_ef_bfd_table
[i
] == mach
)
6669 /* shouldn't get here */
6674 #endif /* not sh_elf_set_mach_from_flags */
6676 #ifndef sh_elf_set_private_flags
6677 /* Function to keep SH specific file flags. */
6680 sh_elf_set_private_flags (bfd
*abfd
, flagword flags
)
6682 BFD_ASSERT (! elf_flags_init (abfd
)
6683 || elf_elfheader (abfd
)->e_flags
== flags
);
6685 elf_elfheader (abfd
)->e_flags
= flags
;
6686 elf_flags_init (abfd
) = TRUE
;
6687 return sh_elf_set_mach_from_flags (abfd
);
6689 #endif /* not sh_elf_set_private_flags */
6691 #ifndef sh_elf_copy_private_data
6692 /* Copy backend specific data from one object module to another */
6695 sh_elf_copy_private_data (bfd
* ibfd
, bfd
* obfd
)
6697 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6698 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6701 return sh_elf_set_private_flags (obfd
, elf_elfheader (ibfd
)->e_flags
);
6703 #endif /* not sh_elf_copy_private_data */
6705 #ifndef sh_elf_merge_private_data
6707 /* This function returns the ELF architecture number that
6708 corresponds to the given arch_sh* flags. */
6711 sh_find_elf_flags (unsigned int arch_set
)
6713 extern unsigned long sh_get_bfd_mach_from_arch_set (unsigned int);
6714 unsigned long bfd_mach
= sh_get_bfd_mach_from_arch_set (arch_set
);
6716 return sh_elf_get_flags_from_mach (bfd_mach
);
6719 /* This routine initialises the elf flags when required and
6720 calls sh_merge_bfd_arch() to check dsp/fpu compatibility. */
6723 sh_elf_merge_private_data (bfd
*ibfd
, bfd
*obfd
)
6725 extern bfd_boolean
sh_merge_bfd_arch (bfd
*, bfd
*);
6727 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6728 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6731 if (! elf_flags_init (obfd
))
6733 /* This happens when ld starts out with a 'blank' output file. */
6734 elf_flags_init (obfd
) = TRUE
;
6735 elf_elfheader (obfd
)->e_flags
= EF_SH1
;
6736 sh_elf_set_mach_from_flags (obfd
);
6739 if (! sh_merge_bfd_arch (ibfd
, obfd
))
6741 _bfd_error_handler ("%B: uses instructions which are incompatible "
6742 "with instructions used in previous modules",
6744 bfd_set_error (bfd_error_bad_value
);
6748 elf_elfheader (obfd
)->e_flags
=
6749 sh_elf_get_flags_from_mach (bfd_get_mach (obfd
));
6753 #endif /* not sh_elf_merge_private_data */
6755 /* Override the generic function because we need to store sh_elf_obj_tdata
6756 as the specific tdata. We set also the machine architecture from flags
6760 sh_elf_object_p (bfd
*abfd
)
6762 return sh_elf_set_mach_from_flags (abfd
);
6765 /* Finish up dynamic symbol handling. We set the contents of various
6766 dynamic sections here. */
6769 sh_elf_finish_dynamic_symbol (bfd
*output_bfd
, struct bfd_link_info
*info
,
6770 struct elf_link_hash_entry
*h
,
6771 Elf_Internal_Sym
*sym
)
6773 struct elf_sh_link_hash_table
*htab
;
6775 htab
= sh_elf_hash_table (info
);
6777 if (h
->plt
.offset
!= (bfd_vma
) -1)
6785 Elf_Internal_Rela rel
;
6788 /* This symbol has an entry in the procedure linkage table. Set
6791 BFD_ASSERT (h
->dynindx
!= -1);
6794 sgot
= htab
->sgotplt
;
6795 srel
= htab
->srelplt
;
6796 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srel
!= NULL
);
6798 /* Get the index in the procedure linkage table which
6799 corresponds to this symbol. This is the index of this symbol
6800 in all the symbols for which we are making plt entries. The
6801 first entry in the procedure linkage table is reserved. */
6802 plt_index
= h
->plt
.offset
/ elf_sh_sizeof_plt (info
) - 1;
6804 /* Get the offset into the .got table of the entry that
6805 corresponds to this function. Each .got entry is 4 bytes.
6806 The first three are reserved. */
6807 got_offset
= (plt_index
+ 3) * 4;
6811 got_offset
-= GOT_BIAS
;
6814 /* Fill in the entry in the procedure linkage table. */
6817 if (elf_sh_plt_entry
== NULL
)
6819 elf_sh_plt_entry
= (bfd_big_endian (output_bfd
) ?
6820 elf_sh_plt_entry_be
: elf_sh_plt_entry_le
);
6822 memcpy (splt
->contents
+ h
->plt
.offset
, elf_sh_plt_entry
,
6823 elf_sh_sizeof_plt (info
));
6824 #ifdef INCLUDE_SHMEDIA
6825 movi_shori_putval (output_bfd
,
6826 (sgot
->output_section
->vma
6827 + sgot
->output_offset
6829 (splt
->contents
+ h
->plt
.offset
6830 + elf_sh_plt_symbol_offset (info
)));
6832 /* Set bottom bit because its for a branch to SHmedia */
6833 movi_shori_putval (output_bfd
,
6834 (splt
->output_section
->vma
+ splt
->output_offset
)
6836 (splt
->contents
+ h
->plt
.offset
6837 + elf_sh_plt_plt0_offset (info
)));
6839 bfd_put_32 (output_bfd
,
6840 (sgot
->output_section
->vma
6841 + sgot
->output_offset
6843 (splt
->contents
+ h
->plt
.offset
6844 + elf_sh_plt_symbol_offset (info
)));
6846 bfd_put_32 (output_bfd
,
6847 (splt
->output_section
->vma
+ splt
->output_offset
),
6848 (splt
->contents
+ h
->plt
.offset
6849 + elf_sh_plt_plt0_offset (info
)));
6854 if (elf_sh_pic_plt_entry
== NULL
)
6856 elf_sh_pic_plt_entry
= (bfd_big_endian (output_bfd
) ?
6857 elf_sh_pic_plt_entry_be
:
6858 elf_sh_pic_plt_entry_le
);
6860 memcpy (splt
->contents
+ h
->plt
.offset
, elf_sh_pic_plt_entry
,
6861 elf_sh_sizeof_plt (info
));
6862 #ifdef INCLUDE_SHMEDIA
6863 movi_shori_putval (output_bfd
, got_offset
,
6864 (splt
->contents
+ h
->plt
.offset
6865 + elf_sh_plt_symbol_offset (info
)));
6867 bfd_put_32 (output_bfd
, got_offset
,
6868 (splt
->contents
+ h
->plt
.offset
6869 + elf_sh_plt_symbol_offset (info
)));
6875 got_offset
+= GOT_BIAS
;
6878 #ifdef INCLUDE_SHMEDIA
6879 movi_shori_putval (output_bfd
,
6880 plt_index
* sizeof (Elf32_External_Rela
),
6881 (splt
->contents
+ h
->plt
.offset
6882 + elf_sh_plt_reloc_offset (info
)));
6884 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rela
),
6885 (splt
->contents
+ h
->plt
.offset
6886 + elf_sh_plt_reloc_offset (info
)));
6889 /* Fill in the entry in the global offset table. */
6890 bfd_put_32 (output_bfd
,
6891 (splt
->output_section
->vma
6892 + splt
->output_offset
6894 + elf_sh_plt_temp_offset (info
)),
6895 sgot
->contents
+ got_offset
);
6897 /* Fill in the entry in the .rela.plt section. */
6898 rel
.r_offset
= (sgot
->output_section
->vma
6899 + sgot
->output_offset
6901 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_JMP_SLOT
);
6904 rel
.r_addend
= GOT_BIAS
;
6906 loc
= srel
->contents
+ plt_index
* sizeof (Elf32_External_Rela
);
6907 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
6909 if (!h
->def_regular
)
6911 /* Mark the symbol as undefined, rather than as defined in
6912 the .plt section. Leave the value alone. */
6913 sym
->st_shndx
= SHN_UNDEF
;
6917 if (h
->got
.offset
!= (bfd_vma
) -1
6918 && sh_elf_hash_entry (h
)->tls_type
!= GOT_TLS_GD
6919 && sh_elf_hash_entry (h
)->tls_type
!= GOT_TLS_IE
)
6923 Elf_Internal_Rela rel
;
6926 /* This symbol has an entry in the global offset table. Set it
6930 srel
= htab
->srelgot
;
6931 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
6933 rel
.r_offset
= (sgot
->output_section
->vma
6934 + sgot
->output_offset
6935 + (h
->got
.offset
&~ (bfd_vma
) 1));
6937 /* If this is a static link, or it is a -Bsymbolic link and the
6938 symbol is defined locally or was forced to be local because
6939 of a version file, we just want to emit a RELATIVE reloc.
6940 The entry in the global offset table will already have been
6941 initialized in the relocate_section function. */
6943 && SYMBOL_REFERENCES_LOCAL (info
, h
))
6945 rel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
6946 rel
.r_addend
= (h
->root
.u
.def
.value
6947 + h
->root
.u
.def
.section
->output_section
->vma
6948 + h
->root
.u
.def
.section
->output_offset
);
6952 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
6953 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_GLOB_DAT
);
6957 loc
= srel
->contents
;
6958 loc
+= srel
->reloc_count
++ * sizeof (Elf32_External_Rela
);
6959 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
6962 #ifdef INCLUDE_SHMEDIA
6964 struct elf_sh_link_hash_entry
*eh
;
6966 eh
= (struct elf_sh_link_hash_entry
*) h
;
6967 if (eh
->datalabel_got
.offset
!= (bfd_vma
) -1)
6971 Elf_Internal_Rela rel
;
6974 /* This symbol has a datalabel entry in the global offset table.
6978 srel
= htab
->srelgot
;
6979 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
6981 rel
.r_offset
= (sgot
->output_section
->vma
6982 + sgot
->output_offset
6983 + (eh
->datalabel_got
.offset
&~ (bfd_vma
) 1));
6985 /* If this is a static link, or it is a -Bsymbolic link and the
6986 symbol is defined locally or was forced to be local because
6987 of a version file, we just want to emit a RELATIVE reloc.
6988 The entry in the global offset table will already have been
6989 initialized in the relocate_section function. */
6991 && SYMBOL_REFERENCES_LOCAL (info
, h
))
6993 rel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
6994 rel
.r_addend
= (h
->root
.u
.def
.value
6995 + h
->root
.u
.def
.section
->output_section
->vma
6996 + h
->root
.u
.def
.section
->output_offset
);
7000 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
7001 + eh
->datalabel_got
.offset
);
7002 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_GLOB_DAT
);
7006 loc
= srel
->contents
;
7007 loc
+= srel
->reloc_count
++ * sizeof (Elf32_External_Rela
);
7008 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
7016 Elf_Internal_Rela rel
;
7019 /* This symbol needs a copy reloc. Set it up. */
7021 BFD_ASSERT (h
->dynindx
!= -1
7022 && (h
->root
.type
== bfd_link_hash_defined
7023 || h
->root
.type
== bfd_link_hash_defweak
));
7025 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
7027 BFD_ASSERT (s
!= NULL
);
7029 rel
.r_offset
= (h
->root
.u
.def
.value
7030 + h
->root
.u
.def
.section
->output_section
->vma
7031 + h
->root
.u
.def
.section
->output_offset
);
7032 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_COPY
);
7034 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
7035 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
7038 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
7039 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
7040 || h
== htab
->root
.hgot
)
7041 sym
->st_shndx
= SHN_ABS
;
7046 /* Finish up the dynamic sections. */
7049 sh_elf_finish_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
7051 struct elf_sh_link_hash_table
*htab
;
7055 htab
= sh_elf_hash_table (info
);
7056 sgot
= htab
->sgotplt
;
7057 sdyn
= bfd_get_section_by_name (htab
->root
.dynobj
, ".dynamic");
7059 if (htab
->root
.dynamic_sections_created
)
7062 Elf32_External_Dyn
*dyncon
, *dynconend
;
7064 BFD_ASSERT (sgot
!= NULL
&& sdyn
!= NULL
);
7066 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
7067 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
7068 for (; dyncon
< dynconend
; dyncon
++)
7070 Elf_Internal_Dyn dyn
;
7072 #ifdef INCLUDE_SHMEDIA
7076 bfd_elf32_swap_dyn_in (htab
->root
.dynobj
, dyncon
, &dyn
);
7083 #ifdef INCLUDE_SHMEDIA
7085 name
= info
->init_function
;
7089 name
= info
->fini_function
;
7091 if (dyn
.d_un
.d_val
!= 0)
7093 struct elf_link_hash_entry
*h
;
7095 h
= elf_link_hash_lookup (&htab
->root
, name
,
7096 FALSE
, FALSE
, TRUE
);
7097 if (h
!= NULL
&& (h
->other
& STO_SH5_ISA32
))
7099 dyn
.d_un
.d_val
|= 1;
7100 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7107 s
= htab
->sgot
->output_section
;
7111 s
= htab
->srelplt
->output_section
;
7113 BFD_ASSERT (s
!= NULL
);
7114 dyn
.d_un
.d_ptr
= s
->vma
;
7115 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7119 s
= htab
->srelplt
->output_section
;
7120 BFD_ASSERT (s
!= NULL
);
7121 dyn
.d_un
.d_val
= s
->size
;
7122 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7126 /* My reading of the SVR4 ABI indicates that the
7127 procedure linkage table relocs (DT_JMPREL) should be
7128 included in the overall relocs (DT_RELA). This is
7129 what Solaris does. However, UnixWare can not handle
7130 that case. Therefore, we override the DT_RELASZ entry
7131 here to make it not include the JMPREL relocs. Since
7132 the linker script arranges for .rela.plt to follow all
7133 other relocation sections, we don't have to worry
7134 about changing the DT_RELA entry. */
7135 if (htab
->srelplt
!= NULL
)
7137 s
= htab
->srelplt
->output_section
;
7138 dyn
.d_un
.d_val
-= s
->size
;
7140 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7145 /* Fill in the first entry in the procedure linkage table. */
7147 if (splt
&& splt
->size
> 0)
7151 if (elf_sh_pic_plt_entry
== NULL
)
7153 elf_sh_pic_plt_entry
= (bfd_big_endian (output_bfd
) ?
7154 elf_sh_pic_plt_entry_be
:
7155 elf_sh_pic_plt_entry_le
);
7157 memcpy (splt
->contents
, elf_sh_pic_plt_entry
,
7158 elf_sh_sizeof_plt (info
));
7162 if (elf_sh_plt0_entry
== NULL
)
7164 elf_sh_plt0_entry
= (bfd_big_endian (output_bfd
) ?
7165 elf_sh_plt0_entry_be
:
7166 elf_sh_plt0_entry_le
);
7168 memcpy (splt
->contents
, elf_sh_plt0_entry
, PLT_ENTRY_SIZE
);
7169 #ifdef INCLUDE_SHMEDIA
7170 movi_shori_putval (output_bfd
,
7171 sgot
->output_section
->vma
7172 + sgot
->output_offset
,
7174 + elf_sh_plt0_gotplt_offset (info
));
7176 bfd_put_32 (output_bfd
,
7177 sgot
->output_section
->vma
+ sgot
->output_offset
+ 4,
7178 splt
->contents
+ elf_sh_plt0_gotid_offset (info
));
7179 bfd_put_32 (output_bfd
,
7180 sgot
->output_section
->vma
+ sgot
->output_offset
+ 8,
7181 splt
->contents
+ elf_sh_plt0_linker_offset (info
));
7185 /* UnixWare sets the entsize of .plt to 4, although that doesn't
7186 really seem like the right value. */
7187 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
7191 /* Fill in the first three entries in the global offset table. */
7192 if (sgot
&& sgot
->size
> 0)
7195 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
7197 bfd_put_32 (output_bfd
,
7198 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
7200 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
7201 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
7203 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
7209 static enum elf_reloc_type_class
7210 sh_elf_reloc_type_class (const Elf_Internal_Rela
*rela
)
7212 switch ((int) ELF32_R_TYPE (rela
->r_info
))
7215 return reloc_class_relative
;
7217 return reloc_class_plt
;
7219 return reloc_class_copy
;
7221 return reloc_class_normal
;
7225 #if !defined SH_TARGET_ALREADY_DEFINED
7226 /* Support for Linux core dump NOTE sections. */
7229 elf32_shlin_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
7234 switch (note
->descsz
)
7239 case 168: /* Linux/SH */
7241 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
7244 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
7253 /* Make a ".reg/999" section. */
7254 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
7255 size
, note
->descpos
+ offset
);
7259 elf32_shlin_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
7261 switch (note
->descsz
)
7266 case 124: /* Linux/SH elf_prpsinfo */
7267 elf_tdata (abfd
)->core_program
7268 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
7269 elf_tdata (abfd
)->core_command
7270 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
7273 /* Note that for some reason, a spurious space is tacked
7274 onto the end of the args in some (at least one anyway)
7275 implementations, so strip it off if it exists. */
7278 char *command
= elf_tdata (abfd
)->core_command
;
7279 int n
= strlen (command
);
7281 if (0 < n
&& command
[n
- 1] == ' ')
7282 command
[n
- 1] = '\0';
7287 #endif /* not SH_TARGET_ALREADY_DEFINED */
7290 /* Return address for Ith PLT stub in section PLT, for relocation REL
7291 or (bfd_vma) -1 if it should not be included. */
7294 sh_elf_plt_sym_val (bfd_vma i
, const asection
*plt
,
7295 const arelent
*rel ATTRIBUTE_UNUSED
)
7297 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
7300 #if !defined SH_TARGET_ALREADY_DEFINED
7301 #define TARGET_BIG_SYM bfd_elf32_sh_vec
7302 #define TARGET_BIG_NAME "elf32-sh"
7303 #define TARGET_LITTLE_SYM bfd_elf32_shl_vec
7304 #define TARGET_LITTLE_NAME "elf32-shl"
7307 #define ELF_ARCH bfd_arch_sh
7308 #define ELF_MACHINE_CODE EM_SH
7309 #ifdef __QNXTARGET__
7310 #define ELF_MAXPAGESIZE 0x1000
7312 #define ELF_MAXPAGESIZE 0x80
7315 #define elf_symbol_leading_char '_'
7317 #define bfd_elf32_bfd_reloc_type_lookup sh_elf_reloc_type_lookup
7318 #define elf_info_to_howto sh_elf_info_to_howto
7319 #define bfd_elf32_bfd_relax_section sh_elf_relax_section
7320 #define elf_backend_relocate_section sh_elf_relocate_section
7321 #define bfd_elf32_bfd_get_relocated_section_contents \
7322 sh_elf_get_relocated_section_contents
7323 #define bfd_elf32_mkobject sh_elf_mkobject
7324 #define elf_backend_object_p sh_elf_object_p
7325 #define bfd_elf32_bfd_set_private_bfd_flags \
7326 sh_elf_set_private_flags
7327 #define bfd_elf32_bfd_copy_private_bfd_data \
7328 sh_elf_copy_private_data
7329 #define bfd_elf32_bfd_merge_private_bfd_data \
7330 sh_elf_merge_private_data
7332 #define elf_backend_gc_mark_hook sh_elf_gc_mark_hook
7333 #define elf_backend_gc_sweep_hook sh_elf_gc_sweep_hook
7334 #define elf_backend_check_relocs sh_elf_check_relocs
7335 #define elf_backend_copy_indirect_symbol \
7336 sh_elf_copy_indirect_symbol
7337 #define elf_backend_create_dynamic_sections \
7338 sh_elf_create_dynamic_sections
7339 #define bfd_elf32_bfd_link_hash_table_create \
7340 sh_elf_link_hash_table_create
7341 #define elf_backend_adjust_dynamic_symbol \
7342 sh_elf_adjust_dynamic_symbol
7343 #define elf_backend_size_dynamic_sections \
7344 sh_elf_size_dynamic_sections
7345 #define elf_backend_finish_dynamic_symbol \
7346 sh_elf_finish_dynamic_symbol
7347 #define elf_backend_finish_dynamic_sections \
7348 sh_elf_finish_dynamic_sections
7349 #define elf_backend_reloc_type_class sh_elf_reloc_type_class
7350 #define elf_backend_plt_sym_val sh_elf_plt_sym_val
7352 #define elf_backend_can_gc_sections 1
7353 #define elf_backend_can_refcount 1
7354 #define elf_backend_want_got_plt 1
7355 #define elf_backend_plt_readonly 1
7356 #define elf_backend_want_plt_sym 0
7357 #define elf_backend_got_header_size 12
7359 #if !defined INCLUDE_SHMEDIA && !defined SH_TARGET_ALREADY_DEFINED
7361 #include "elf32-target.h"
7363 /* NetBSD support. */
7364 #undef TARGET_BIG_SYM
7365 #define TARGET_BIG_SYM bfd_elf32_shnbsd_vec
7366 #undef TARGET_BIG_NAME
7367 #define TARGET_BIG_NAME "elf32-sh-nbsd"
7368 #undef TARGET_LITTLE_SYM
7369 #define TARGET_LITTLE_SYM bfd_elf32_shlnbsd_vec
7370 #undef TARGET_LITTLE_NAME
7371 #define TARGET_LITTLE_NAME "elf32-shl-nbsd"
7372 #undef ELF_MAXPAGESIZE
7373 #define ELF_MAXPAGESIZE 0x10000
7374 #undef ELF_COMMONPAGESIZE
7375 #undef elf_symbol_leading_char
7376 #define elf_symbol_leading_char 0
7378 #define elf32_bed elf32_sh_nbsd_bed
7380 #include "elf32-target.h"
7383 /* Linux support. */
7384 #undef TARGET_BIG_SYM
7385 #define TARGET_BIG_SYM bfd_elf32_shblin_vec
7386 #undef TARGET_BIG_NAME
7387 #define TARGET_BIG_NAME "elf32-shbig-linux"
7388 #undef TARGET_LITTLE_SYM
7389 #define TARGET_LITTLE_SYM bfd_elf32_shlin_vec
7390 #undef TARGET_LITTLE_NAME
7391 #define TARGET_LITTLE_NAME "elf32-sh-linux"
7392 #undef ELF_COMMONPAGESIZE
7393 #define ELF_COMMONPAGESIZE 0x1000
7395 #undef elf_backend_grok_prstatus
7396 #define elf_backend_grok_prstatus elf32_shlin_grok_prstatus
7397 #undef elf_backend_grok_psinfo
7398 #define elf_backend_grok_psinfo elf32_shlin_grok_psinfo
7400 #define elf32_bed elf32_sh_lin_bed
7402 #include "elf32-target.h"
7404 #endif /* neither INCLUDE_SHMEDIA nor SH_TARGET_ALREADY_DEFINED */