1 /* 32-bit ELF support for C-SKY.
2 Copyright (C) 1998-2021 Free Software Foundation, Inc.
3 Contributed by C-SKY Microsystems and Mentor Graphics.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
28 #include "opcode/csky.h"
30 #include "libiberty.h"
31 #include "elf32-csky.h"
33 /* Data structures used for merging different arch variants.
34 V1 (510/610) and V2 (8xx) processors are incompatible, but
35 we can merge wthin each family. */
43 typedef const struct csky_arch_for_merge
46 const unsigned long arch_eflag
;
47 /* The files can merge only if they are in same class. */
48 enum merge_class
class;
49 /* When input files have different levels,
50 the target sets arch_eflag to the largest level file's arch_eflag. */
51 unsigned int class_level
;
52 /* Control whether to print warning when merging with different arch. */
53 unsigned int do_warning
;
54 } csky_arch_for_merge
;
56 static csky_arch_for_merge csky_archs
[] =
58 /* 510 and 610 merge to 610 without warning. */
59 { "ck510", CSKY_ARCH_510
, CSKY_V1
, 0, 0},
60 { "ck610", CSKY_ARCH_610
, CSKY_V1
, 1, 0},
61 /* 801, 802, 803, 807, 810 merge to largest one. */
62 { "ck801", CSKY_ARCH_801
, CSKY_V2
, 0, 1},
63 { "ck802", CSKY_ARCH_802
, CSKY_V2
, 1, 1},
64 { "ck803", CSKY_ARCH_803
, CSKY_V2
, 2, 1},
65 { "ck807", CSKY_ARCH_807
, CSKY_V2
, 3, 1},
66 { "ck810", CSKY_ARCH_810
, CSKY_V2
, 4, 1},
67 { "ck860", CSKY_ARCH_860
, CSKY_V2
, 5, 1},
71 /* Return the ARCH bits out of ABFD. */
72 #define bfd_csky_arch(abfd) \
73 (elf_elfheader (abfd)->e_flags & CSKY_ARCH_MASK)
75 /* Return the ABI bits out of ABFD. */
76 #define bfd_csky_abi(abfd) \
77 (elf_elfheader (abfd)->e_flags & CSKY_ABI_MASK)
80 /* The index of a howto-item is implicitly equal to
81 the corresponding Relocation Type Encoding. */
82 static reloc_howto_type csky_elf_howto_table
[] =
85 HOWTO (R_CKCORE_NONE
, /* type */
89 FALSE
, /* pc_relative */
91 complain_overflow_dont
, /* complain_on_overflow */
92 NULL
, /* special_function */
93 "R_CKCORE_NONE", /* name */
94 FALSE
, /* partial_inplace */
97 FALSE
), /* pcrel_offset */
100 HOWTO (R_CKCORE_ADDR32
, /* type */
104 FALSE
, /* pc_relative */
106 complain_overflow_dont
, /* complain_on_overflow */
107 bfd_elf_generic_reloc
, /* special_function */
108 "R_CKCORE_ADDR32", /* name */
109 FALSE
, /* partial_inplace */
111 0xffffffff, /* dst_mask */
112 FALSE
), /* pcrel_offset */
114 /* 2: Only for csky v1. */
115 HOWTO (R_CKCORE_PCREL_IMM8BY4
, /* type */
119 TRUE
, /* pc_relative */
121 complain_overflow_bitfield
, /* complain_on_overflow */
122 NULL
, /* special_function */
123 "R_CKCORE_PCREL_IMM8BY4", /* name */
124 FALSE
, /* partial_inplace */
127 TRUE
), /* pcrel_offset */
129 /* 3: Only for csky v1. */
130 HOWTO (R_CKCORE_PCREL_IMM11BY2
, /* type */
134 TRUE
, /* pc_relative */
136 complain_overflow_signed
, /* complain_on_overflow */
137 bfd_elf_generic_reloc
, /* special_function */
138 "R_CKCORE_PCREL_IMM11BY2", /* name */
139 FALSE
, /* partial_inplace */
140 0x7ff, /* src_mask */
141 0x7ff, /* dst_mask */
142 TRUE
), /* pcrel_offset */
145 HOWTO (R_CKCORE_PCREL_IMM4BY2
,0,0,0,0,0,0,0,"R_CKCORE_PCREL_IMM4BY2",0,0,0,0),
148 HOWTO (R_CKCORE_PCREL32
, /* type */
152 TRUE
, /* pc_relative */
154 complain_overflow_dont
, /* complain_on_overflow */
155 bfd_elf_generic_reloc
, /* special_function */
156 "R_CKCORE_PCREL32", /* name */
157 FALSE
, /* partial_inplace */
159 0xffffffff, /* dst_mask */
160 TRUE
), /* pcrel_offset */
162 /* 6: Only for csky v1. */
163 HOWTO (R_CKCORE_PCREL_JSR_IMM11BY2
, /* type */
167 TRUE
, /* pc_relative */
169 complain_overflow_signed
, /* complain_on_overflow */
170 bfd_elf_generic_reloc
, /* special_function */
171 "R_CKCORE_PCREL_JSR_IMM11BY2", /* name */
172 FALSE
, /* partial_inplace */
173 0x7ff, /* src_mask */
174 0x7ff, /* dst_mask */
175 TRUE
), /* pcrel_offset */
177 /* 7: GNU extension to record C++ vtable member usage. */
178 HOWTO (R_CKCORE_GNU_VTENTRY
, /* type */
182 FALSE
, /* pc_relative */
184 complain_overflow_dont
, /* complain_on_overflow */
185 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
186 "R_CKCORE_GNU_VTENTRY", /* name */
187 FALSE
, /* partial_inplace */
190 FALSE
), /* pcrel_offset */
192 /* 8: GNU extension to record C++ vtable hierarchy. */
193 HOWTO (R_CKCORE_GNU_VTINHERIT
, /* type */
197 FALSE
, /* pc_relative */
199 complain_overflow_dont
, /* complain_on_overflow */
200 NULL
, /* special_function */
201 "R_CKCORE_GNU_VTINHERIT", /* name */
202 FALSE
, /* partial_inplace */
205 FALSE
), /* pcrel_offset */
208 HOWTO (R_CKCORE_RELATIVE
, /* type */
212 FALSE
, /* pc_relative */
214 complain_overflow_signed
, /* complain_on_overflow */
215 bfd_elf_generic_reloc
, /* special_function */
216 "R_CKCORE_RELATIVE", /* name */
217 TRUE
, /* partial_inplace */
219 0xffffffff, /* dst_mask */
220 FALSE
), /* pcrel_offset */
223 /* FIXME: It is a bug that copy relocations are not implemented. */
224 HOWTO (R_CKCORE_COPY
, /* type */
228 FALSE
, /* pc_relative */
230 complain_overflow_bitfield
, /* complain_on_overflow */
231 bfd_elf_generic_reloc
, /* special_function */
232 "R_CKCORE_COPY", /* name */
233 TRUE
, /* partial_inplace */
234 0xffffffff, /* src_mask */
235 0xffffffff, /* dst_mask */
236 FALSE
), /* pcrel_offset */
239 HOWTO (R_CKCORE_GLOB_DAT
,0,0,0,0,0,0,0,"R_CKCORE_GLOB_DAT",0,0,0,0),
242 HOWTO (R_CKCORE_JUMP_SLOT
,0,0,0,0,0,0,0,"R_CKCORE_JUMP_SLOT",0,0,0,0),
245 HOWTO (R_CKCORE_GOTOFF
, /* type */
249 FALSE
, /* pc_relative */
251 complain_overflow_dont
, /* complain_on_overflow */
252 bfd_elf_generic_reloc
, /* special_function */
253 "R_CKCORE_GOTOFF", /* name */
254 TRUE
, /* partial_inplace */
256 0xffffffffl
, /* dst_mask */
257 FALSE
), /* pcrel_offset */
260 HOWTO (R_CKCORE_GOTPC
, /* type */
264 TRUE
, /* pc_relative */
266 complain_overflow_dont
, /* complain_on_overflow */
267 bfd_elf_generic_reloc
, /* special_function */
268 "R_CKCORE_GOTPC", /* name */
269 TRUE
, /* partial_inplace */
271 0xffffffff, /* dst_mask */
272 FALSE
), /* pcrel_offset */
275 HOWTO (R_CKCORE_GOT32
, /* type */
279 FALSE
, /* pc_relative */
281 complain_overflow_dont
, /* complain_on_overflow */
282 bfd_elf_generic_reloc
, /* special_function */
283 "R_CKCORE_GOT32", /* name */
284 TRUE
, /* partial_inplace */
286 0xffffffff, /* dst_mask */
287 TRUE
), /* pcrel_offset */
290 HOWTO (R_CKCORE_PLT32
, /* type */
294 FALSE
, /* pc_relative */
296 complain_overflow_dont
, /* complain_on_overflow */
297 bfd_elf_generic_reloc
, /* special_function */
298 "R_CKCORE_PLT32", /* name */
299 TRUE
, /* partial_inplace */
301 0xffffffff, /* dst_mask */
302 TRUE
), /* pcrel_offset */
305 HOWTO (R_CKCORE_ADDRGOT
,0,0,0,0,0,0,0,"R_CKCORE_ADDRGOT",0,0,0,0),
308 HOWTO (R_CKCORE_ADDRPLT
,0,0,0,0,0,0,0,"R_CKCORE_ADDRPLT",0,0,0,0),
310 /* 19: Only for csky v2. */
311 HOWTO (R_CKCORE_PCREL_IMM26BY2
, /* type */
315 TRUE
, /* pc_relative */
317 complain_overflow_signed
, /* complain_on_overflow */
318 bfd_elf_generic_reloc
, /* special_function */
319 "R_CKCORE_PCREL_IMM26BY2", /* name */
320 FALSE
, /* partial_inplace */
322 0x3ffffff, /* dst_mask */
323 TRUE
), /* pcrel_offset */
325 /* 20: Only for csky v2. */
326 HOWTO (R_CKCORE_PCREL_IMM16BY2
, /* type */
330 TRUE
, /* pc_relative */
332 complain_overflow_signed
, /* complain_on_overflow */
333 NULL
, /* special_function */
334 "R_CKCORE_PCREL_IMM16BY2", /* name */
335 FALSE
, /* partial_inplace */
337 0xffff, /* dst_mask */
338 TRUE
), /* pcrel_offset */
340 /* 21: Only for csky v2. */
341 HOWTO (R_CKCORE_PCREL_IMM16BY4
, /* type */
345 TRUE
, /* pc_relative */
347 complain_overflow_bitfield
, /* complain_on_overflow */
348 NULL
, /* special_function */
349 "R_CKCORE_PCREL_IMM16BY4", /* name */
350 FALSE
, /* partial_inplace */
351 0xffff0000, /* src_mask */
352 0xffff, /* dst_mask */
353 TRUE
), /* pcrel_offset */
355 /* 22: Only for csky v2. */
356 HOWTO (R_CKCORE_PCREL_IMM10BY2
, /* type */
360 TRUE
, /* pc_relative */
362 complain_overflow_signed
, /* complain_on_overflow */
363 bfd_elf_generic_reloc
, /* special_function */
364 "R_CKCORE_PCREL_IMM10BY2", /* name */
365 FALSE
, /* partial_inplace */
367 0x3ff, /* dst_mask */
368 TRUE
), /* pcrel_offset */
370 /* 23: Only for csky v2. */
371 HOWTO (R_CKCORE_PCREL_IMM10BY4
, /* type */
375 TRUE
, /* pc_relative */
377 complain_overflow_bitfield
, /* complain_on_overflow */
378 NULL
, /* special_function */
379 "R_CKCORE_PCREL_IMM10BY4", /* name */
380 FALSE
, /* partial_inplace */
382 0x3ff, /* dst_mask */
383 TRUE
), /* pcrel_offset */
385 /* 24: Only for csky v2. */
386 HOWTO (R_CKCORE_ADDR_HI16
, /* type */
390 FALSE
, /* pc_relative */
392 complain_overflow_dont
, /* complain_on_overflow */
393 bfd_elf_generic_reloc
, /* special_function */
394 "R_CKCORE_ADDR_HI16", /* name */
395 FALSE
, /* partial_inplace */
397 0xffff, /* dst_mask */
398 FALSE
), /* pcrel_offset */
401 HOWTO (R_CKCORE_ADDR_LO16
, /* type */
405 FALSE
, /* pc_relative */
407 complain_overflow_dont
, /* complain_on_overflow */
408 bfd_elf_generic_reloc
, /* special_function */
409 "R_CKCORE_ADDR_LO16", /* name */
410 FALSE
, /* partial_inplace */
412 0xffff, /* dst_mask */
413 FALSE
), /* pcrel_offset */
416 HOWTO (R_CKCORE_GOTPC_HI16
, /* type */
420 TRUE
, /* pc_relative */
422 complain_overflow_dont
, /* complain_on_overflow */
423 bfd_elf_generic_reloc
, /* special_function */
424 "R_CKCORE_GOTPC_HI16", /* name */
425 FALSE
, /* partial_inplace */
427 0xffff, /* dst_mask */
428 FALSE
), /* pcrel_offset */
431 HOWTO (R_CKCORE_GOTPC_LO16
, /* type */
435 TRUE
, /* pc_relative */
437 complain_overflow_dont
, /* complain_on_overflow */
438 bfd_elf_generic_reloc
, /* special_function */
439 "R_CKCORE_GOTPC_LO16", /* name */
440 FALSE
, /* partial_inplace */
442 0xffff, /* dst_mask */
443 FALSE
), /* pcrel_offset */
446 HOWTO (R_CKCORE_GOTOFF_HI16
, /* type */
450 FALSE
, /* pc_relative */
452 complain_overflow_dont
, /* complain_on_overflow */
453 bfd_elf_generic_reloc
, /* special_function */
454 "R_CKCORE_GOTOFF_HI16", /* name */
455 FALSE
, /* partial_inplace */
457 0xffff, /* dst_mask */
458 FALSE
), /* pcrel_offset */
461 HOWTO (R_CKCORE_GOTOFF_LO16
, /* type */
465 FALSE
, /* pc_relative */
467 complain_overflow_dont
, /* complain_on_overflow */
468 bfd_elf_generic_reloc
, /* special_function */
469 "R_CKCORE_GOTOFF_LO16", /* name */
470 FALSE
, /* partial_inplace */
472 0xffff, /* dst_mask */
473 FALSE
), /* pcrel_offset */
476 HOWTO (R_CKCORE_GOT12
, /* type */
480 FALSE
, /* pc_relative */
482 complain_overflow_bitfield
, /* complain_on_overflow */
483 bfd_elf_generic_reloc
, /* special_function */
484 "R_CKCORE_GOT12", /* name */
485 TRUE
, /* partial_inplace */
487 0xfff, /* dst_mask */
488 FALSE
), /* pcrel_offset */
491 HOWTO (R_CKCORE_GOT_HI16
, /* type */
495 FALSE
, /* pc_relative */
497 complain_overflow_dont
, /* complain_on_overflow */
498 bfd_elf_generic_reloc
, /* special_function */
499 "R_CKCORE_GOT_HI16", /* name */
500 TRUE
, /* partial_inplace */
502 0xffff, /* dst_mask */
503 FALSE
), /* pcrel_offset */
506 HOWTO (R_CKCORE_GOT_LO16
, /* type */
510 FALSE
, /* pc_relative */
512 complain_overflow_dont
, /* complain_on_overflow */
513 bfd_elf_generic_reloc
, /* special_function */
514 "R_CKCORE_GOT_LO16", /* name */
515 TRUE
, /* partial_inplace */
517 0xffff, /* dst_mask */
518 FALSE
), /* pcrel_offset */
521 HOWTO (R_CKCORE_PLT12
, /* type */
525 FALSE
, /* pc_relative */
527 complain_overflow_bitfield
, /* complain_on_overflow */
528 bfd_elf_generic_reloc
, /* special_function */
529 "R_CKCORE_PLT12", /* name */
530 TRUE
, /* partial_inplace */
532 0xfff, /* dst_mask */
533 FALSE
), /* pcrel_offset */
536 HOWTO (R_CKCORE_PLT_HI16
, /* type */
540 FALSE
, /* pc_relative */
542 complain_overflow_dont
, /* complain_on_overflow */
543 bfd_elf_generic_reloc
, /* special_function */
544 "R_CKCORE_PLT_HI16", /* name */
545 TRUE
, /* partial_inplace */
547 0xffff, /* dst_mask */
548 FALSE
), /* pcrel_offset */
551 HOWTO (R_CKCORE_PLT_LO16
, /* type */
555 FALSE
, /* pc_relative */
557 complain_overflow_dont
, /* complain_on_overflow */
558 bfd_elf_generic_reloc
, /* special_function */
559 "R_CKCORE_PLT_LO16", /* name */
560 TRUE
, /* partial_inplace */
562 0xffff, /* dst_mask */
563 FALSE
), /* pcrel_offset */
566 HOWTO (R_CKCORE_ADDRGOT_HI16
,0,0,0,0,0,0,0,"R_CKCORE_",0,0,0,0),
569 HOWTO (R_CKCORE_ADDRGOT_LO16
,0,0,0,0,0,0,0,"R_CKCORE_",0,0,0,0),
572 HOWTO (R_CKCORE_ADDRPLT_HI16
,0,0,0,0,0,0,0,"R_CKCORE_",0,0,0,0),
575 HOWTO (R_CKCORE_ADDRPLT_LO16
,0,0,0,0,0,0,0,"R_CKCORE_",0,0,0,0),
578 HOWTO (R_CKCORE_PCREL_JSR_IMM26BY2
, /* type */
582 TRUE
, /* pc_relative */
584 complain_overflow_signed
, /* complain_on_overflow */
585 bfd_elf_generic_reloc
, /* special_function */
586 "R_CKCORE_PCREL_JSR_IMM26BY2", /* name */
587 FALSE
, /* partial_inplace */
589 0x3ffffff, /* dst_mask */
590 TRUE
), /* pcrel_offset */
593 HOWTO (R_CKCORE_TOFFSET_LO16
, /* type */
597 FALSE
, /* pc_relative */
599 complain_overflow_unsigned
, /* complain_on_overflow */
600 NULL
, /* special_function */
601 "R_CKCORE_TOFFSET_LO16", /* name */
602 FALSE
, /* partial_inplace */
604 0xffff, /* dst_mask */
605 FALSE
), /* pcrel_offset */
608 HOWTO (R_CKCORE_DOFFSET_LO16
, /* type */
612 FALSE
, /* pc_relative */
614 complain_overflow_unsigned
, /* complain_on_overflow */
615 NULL
, /* special_function */
616 "R_CKCORE_DOFFSET_LO16", /* name */
617 FALSE
, /* partial_inplace */
619 0xffff, /* dst_mask */
620 FALSE
), /* pcrel_offset */
623 HOWTO (R_CKCORE_PCREL_IMM18BY2
, /* type */
627 TRUE
, /* pc_relative */
629 complain_overflow_signed
, /* complain_on_overflow */
630 NULL
, /* special_function */
631 "R_CKCORE_PCREL_IMM18BY2", /* name */
632 FALSE
, /* partial_inplace */
634 0x3ffff, /* dst_mask */
635 TRUE
), /* pcrel_offset */
638 HOWTO (R_CKCORE_DOFFSET_IMM18
, /* type */
642 FALSE
, /* pc_relative */
644 complain_overflow_unsigned
, /* complain_on_overflow */
645 NULL
, /* special_function */
646 "R_CKCORE_DOFFSET_IMM18", /* name */
647 FALSE
, /* partial_inplace */
649 0x3ffff, /* dst_mask */
650 FALSE
), /* pcrel_offset */
653 HOWTO (R_CKCORE_DOFFSET_IMM18BY2
, /* type */
657 FALSE
, /* pc_relative */
659 complain_overflow_unsigned
, /* complain_on_overflow */
660 NULL
, /* special_function */
661 "R_CKCORE_DOFFSET_IMM18BY2", /* name */
662 FALSE
, /* partial_inplace */
664 0x3ffff, /* dst_mask */
665 FALSE
), /* pcrel_offset */
668 HOWTO (R_CKCORE_DOFFSET_IMM18BY4
, /* type */
672 FALSE
, /* pc_relative */
674 complain_overflow_unsigned
, /* complain_on_overflow */
675 NULL
, /* special_function */
676 "R_CKCORE_DOFFSET_IMM18BY4", /* name */
677 FALSE
, /* partial_inplace */
679 0x3ffff, /* dst_mask */
680 FALSE
), /* pcrel_offset */
683 HOWTO (R_CKCORE_GOTOFF_IMM18
, /* type */
687 FALSE
, /* pc_relative */
689 complain_overflow_bitfield
, /* complain_on_overflow */
690 bfd_elf_generic_reloc
, /* special_function */
691 "R_CKCORE_GOTOFF_IMM18", /* name */
692 TRUE
, /* partial_inplace */
693 0xfffc, /* src_mask */
694 0x3ffff, /* dst_mask */
695 FALSE
), /* pcrel_offset */
698 HOWTO (R_CKCORE_GOT_IMM18BY4
, /* type */
702 FALSE
, /* pc_relative */
704 complain_overflow_bitfield
, /* complain_on_overflow */
705 bfd_elf_generic_reloc
, /* special_function */
706 "R_CKCORE_GOT_IMM18BY4", /* name */
707 TRUE
, /* partial_inplace */
708 0xfffc, /* src_mask */
709 0x3ffff, /* dst_mask */
710 FALSE
), /* pcrel_offset */
713 HOWTO (R_CKCORE_PLT_IMM18BY4
, /* type */
717 FALSE
, /* pc_relative */
719 complain_overflow_bitfield
, /* complain_on_overflow */
720 bfd_elf_generic_reloc
, /* special_function */
721 "R_CKCORE_PLT_IMM18BY4", /* name */
722 TRUE
, /* partial_inplace */
723 0xfffc, /* src_mask */
724 0x3ffff, /* dst_mask */
725 TRUE
), /* pcrel_offset */
728 HOWTO (R_CKCORE_PCREL_IMM7BY4
, /* type */
732 TRUE
, /* pc_relative */
734 complain_overflow_bitfield
, /* complain_on_overflow */
735 bfd_elf_generic_reloc
, /* special_function */
736 "R_CKCORE_PCREL_IMM7BY4", /* name */
737 FALSE
, /* partial_inplace */
738 0xec1f, /* src_mask */
739 0x31f, /* dst_mask */
740 TRUE
), /* pcrel_offset */
742 /* 51: for static nptl. */
743 HOWTO (R_CKCORE_TLS_LE32
, /* type */
747 FALSE
, /* pc_relative */
749 complain_overflow_dont
, /* complain_on_overflow */
750 bfd_elf_generic_reloc
, /* special_function */
751 "R_CKCORE_TLS_LE32", /* name */
752 FALSE
, /* partial_inplace */
754 0xffffffff, /* dst_mask */
755 TRUE
), /* pcrel_offset */
757 /* 52: for static nptl. */
758 HOWTO (R_CKCORE_TLS_IE32
, /* type */
762 FALSE
, /* pc_relative */
764 complain_overflow_dont
, /* complain_on_overflow */
765 bfd_elf_generic_reloc
, /* special_function */
766 "R_CKCORE_TLS_IE32", /* name */
767 FALSE
, /* partial_inplace */
769 0xffffffff, /* dst_mask */
770 TRUE
), /* pcrel_offset */
772 /* 53: for pic nptl. */
773 HOWTO (R_CKCORE_TLS_GD32
, /* type */
777 FALSE
, /* pc_relative */
779 complain_overflow_dont
, /* complain_on_overflow */
780 bfd_elf_generic_reloc
, /* special_function */
781 "R_CKCORE_TLS_GD32", /* name */
782 FALSE
, /* partial_inplace */
784 0xffffffff, /* dst_mask */
785 TRUE
), /* pcrel_offset */
787 /* 54: for pic nptl. */
788 HOWTO (R_CKCORE_TLS_LDM32
, /* type */
792 FALSE
, /* pc_relative */
794 complain_overflow_dont
, /* complain_on_overflow */
795 bfd_elf_generic_reloc
, /* special_function */
796 "R_CKCORE_TLS_LDM32", /* name */
797 FALSE
, /* partial_inplace */
799 0xffffffff, /* dst_mask */
800 TRUE
), /* pcrel_offset */
802 /* 55: for pic nptl. */
803 HOWTO (R_CKCORE_TLS_LDO32
, /* type */
807 FALSE
, /* pc_relative */
809 complain_overflow_dont
, /* complain_on_overflow */
810 bfd_elf_generic_reloc
, /* special_function */
811 "R_CKCORE_TLS_LDO32", /* name */
812 FALSE
, /* partial_inplace */
814 0xffffffff, /* dst_mask */
815 TRUE
), /* pcrel_offset */
817 /* 56: for linker. */
818 HOWTO (R_CKCORE_TLS_DTPMOD32
,0,0,0,0,0,0,0,"R_CKCORE_TLS_DTPMOD32",0,0,0,0),
820 /* 57: for linker. */
821 HOWTO (R_CKCORE_TLS_DTPOFF32
,0,0,0,0,0,0,0,"R_CKCORE_TLS_DTPOFF32",0,0,0,0),
823 /* 58: for linker. */
824 HOWTO (R_CKCORE_TLS_TPOFF32
,0,0,0,0,0,0,0,"R_CKCORE_TLS_TPOFF32",0,0,0,0),
826 /* 59: for ck807f. */
827 HOWTO (R_CKCORE_PCREL_FLRW_IMM8BY4
, /* type */
831 TRUE
, /* pc_relative */
833 complain_overflow_bitfield
, /* complain_on_overflow */
834 NULL
, /* special_function */
835 "R_CKCORE_PCREL_FLRW_IMM8BY4", /* name */
836 FALSE
, /* partial_inplace */
837 0xfe1fff0f, /* src_mask */
838 0x1e000f0, /* dst_mask */
839 TRUE
), /* pcrel_offset */
841 /* 60: for 810 not to generate jsri. */
842 HOWTO (R_CKCORE_NOJSRI
, /* type */
846 FALSE
, /* pc_relative */
848 complain_overflow_dont
, /* complain_on_overflow */
849 bfd_elf_generic_reloc
, /* special_function */
850 "R_CKCORE_NOJSRI", /* name */
851 FALSE
, /* partial_inplace */
852 0xffff, /* src_mask */
853 0xffff, /* dst_mask */
854 FALSE
), /* pcrel_offset */
856 /* 61: for callgraph. */
857 HOWTO (R_CKCORE_CALLGRAPH
, /* type */
861 FALSE
, /* pc_relative */
863 complain_overflow_dont
, /* complain_on_overflow */
864 NULL
, /* special_function */
865 "R_CKCORE_CALLGRAPH", /* name */
866 FALSE
, /* partial_inplace */
869 TRUE
), /* pcrel_offset */
872 HOWTO (R_CKCORE_IRELATIVE
,0,0,0,0,0,0,0,"R_CKCORE_IRELATIVE",0,0,0,0),
874 /* 63: for bloop instruction */
875 HOWTO (R_CKCORE_PCREL_BLOOP_IMM4BY4
, /* type */
881 complain_overflow_signed
, /* complain_on_overflow */
882 bfd_elf_generic_reloc
, /* special_function */
883 "R_CKCORE_PCREL_BLOOP_IMM4BY4", /* name */
884 FALSE
, /* partial_inplace */
887 TRUE
), /* pcrel_offset */
888 /* 64: for bloop instruction */
889 HOWTO (R_CKCORE_PCREL_BLOOP_IMM12BY4
, /* type */
895 complain_overflow_signed
, /* complain_on_overflow */
896 bfd_elf_generic_reloc
, /* special_function */
897 "R_CKCORE_PCREL_BLOOP_IMM12BY4", /* name */
898 FALSE
, /* partial_inplace */
900 0xfff, /* dst_mask */
901 TRUE
), /* pcrel_offset */
907 /* Whether GOT overflow checking is needed. */
908 static int check_got_overflow
= 0;
910 /* Whether the target 32 bits is forced so that the high
911 16 bits is at the low address. */
912 static int need_reverse_bits
;
914 /* Used for relaxation. See csky_relocate_contents. */
915 static bfd_vma read_content_substitute
;
918 The way the following two look-up functions work demands
919 that BFD_RELOC_CKCORE_xxx are defined contiguously. */
921 static reloc_howto_type
*
922 csky_elf_reloc_type_lookup (bfd
* abfd ATTRIBUTE_UNUSED
,
923 bfd_reloc_code_real_type code
)
925 int csky_code
= code
- BFD_RELOC_CKCORE_NONE
;
927 if (csky_code
< 0 || csky_code
>= R_CKCORE_MAX
)
932 csky_code
= R_CKCORE_NONE
;
935 csky_code
= R_CKCORE_ADDR32
;
937 case BFD_RELOC_32_PCREL
:
938 csky_code
= R_CKCORE_PCREL32
;
940 case BFD_RELOC_VTABLE_INHERIT
:
941 csky_code
= R_CKCORE_GNU_VTINHERIT
;
943 case BFD_RELOC_VTABLE_ENTRY
:
944 csky_code
= R_CKCORE_GNU_VTENTRY
;
947 csky_code
= R_CKCORE_RELATIVE
;
950 return (reloc_howto_type
*)NULL
;
953 /* Note: when adding csky bfd reloc types in bfd-in2.h
954 and csky elf reloc types in elf/csky.h,
955 the order of the two reloc type tables should be consistent. */
956 return &csky_elf_howto_table
[csky_code
];
959 static reloc_howto_type
*
960 csky_elf_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
964 for (i
= 0; i
< R_CKCORE_MAX
; i
++)
965 if (strcasecmp (csky_elf_howto_table
[i
].name
, r_name
) == 0)
966 return &csky_elf_howto_table
[i
];
970 static reloc_howto_type
*
971 elf32_csky_howto_from_type (unsigned int r_type
)
973 if (r_type
< R_CKCORE_MAX
)
974 return &csky_elf_howto_table
[r_type
];
980 csky_elf_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
,
982 Elf_Internal_Rela
*dst
)
986 r_type
= ELF32_R_TYPE (dst
->r_info
);
987 cache_ptr
->howto
= elf32_csky_howto_from_type (r_type
);
988 if (cache_ptr
->howto
== NULL
)
990 /* xgettext:c-format */
991 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
993 bfd_set_error (bfd_error_bad_value
);
999 /* The Global Offset Table max size. */
1000 #define GOT_MAX_SIZE 0xFFFF8
1002 /* The name of the dynamic interpreter. This is put in the .interp
1004 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1006 /* The size in bytes of an entry in the procedure linkage table. */
1007 #define PLT_ENTRY_SIZE 12
1008 #define PLT_ENTRY_SIZE_P 16
1010 /* The first entry in a procedure linkage table looks like
1011 this. It is set up so that any shared library function that is
1012 called before the relocation has been set up calls the dynamic
1014 static const bfd_vma csky_elf_plt_entry_v2
[PLT_ENTRY_SIZE
/ 4] =
1016 0xd99c2002, /* ldw r12, (gb, 8) */
1017 0xea0d0000, /* movi r13,offset */
1018 0xe8cc0000 /* jmp r12 */
1021 static const bfd_vma csky_elf_plt_entry_v1
[PLT_ENTRY_SIZE
/ 2 ] =
1023 0x25f0, /* subi r0, 32 */
1024 0x9200, /* stw r2, (r0, 0) */
1025 0x9310, /* stw r3, (r0, 4) */
1026 0x822e, /* ldw r2, (gb, 8) */
1027 0x7301, /* lrw r3, #offset */
1028 0x00c2, /* jmp r2 */
1031 /* Branch stub support. */
1040 bfd_boolean use_branch_stub
= TRUE
;
1044 enum stub_insn_type type
;
1045 unsigned int r_type
;
1049 static const insn_sequence elf32_csky_stub_long_branch
[] =
1051 {0xea8d0002, INSN32
, R_CKCORE_NONE
, 0x0}, /* lrw t1,[pc+8] */
1052 {0x7834, INSN16
, R_CKCORE_NONE
, 0x0}, /* jmp t1 */
1053 {0x6c03, INSN16
, R_CKCORE_NONE
, 0x0}, /* nop */
1054 {0x0, DATA_TYPE
, R_CKCORE_ADDR32
, 0x0} /* .long addr */
1057 static const insn_sequence elf32_csky_stub_long_branch_jmpi
[] =
1059 {0xeac00001, INSN32
, R_CKCORE_NONE
, 0x0}, /* jmpi [pc+4] */
1060 {0x0, DATA_TYPE
, R_CKCORE_ADDR32
, 0x0} /* .long addr */
1063 /* The bsr instruction offset limit. */
1064 #define BSR_MAX_FWD_BRANCH_OFFSET (((1 << 25) - 1) << 1)
1065 #define BSR_MAX_BWD_BRANCH_OFFSET (-(1 << 26))
1067 #define STUB_SUFFIX ".stub"
1068 #define STUB_ENTRY_NAME "__%s_veneer"
1070 /* One entry per long/short branch stub defined above. */
1072 DEF_STUB(long_branch) \
1073 DEF_STUB(long_branch_jmpi)
1075 #define DEF_STUB(x) csky_stub_##x,
1076 enum elf32_csky_stub_type
1085 const insn_sequence
* template_sequence
;
1089 #define DEF_STUB(x) {elf32_csky_stub_##x, ARRAY_SIZE(elf32_csky_stub_##x)},
1090 static const stub_def stub_definitions
[] = {
1095 /* The size of the thread control block. */
1098 struct csky_elf_obj_tdata
1100 struct elf_obj_tdata root
;
1102 /* tls_type for each local got entry. */
1103 char *local_got_tls_type
;
1106 #define csky_elf_local_got_tls_type(bfd) \
1107 (csky_elf_tdata (bfd)->local_got_tls_type)
1109 #define csky_elf_tdata(bfd) \
1110 ((struct csky_elf_obj_tdata *) (bfd)->tdata.any)
1112 struct elf32_csky_stub_hash_entry
1114 /* Base hash table entry structure. */
1115 struct bfd_hash_entry root
;
1117 /* The stub section. */
1120 /* Offset within stub_sec of the beginning of this stub. */
1121 bfd_vma stub_offset
;
1123 /* Given the symbol's value and its section we can determine its final
1124 value when building the stubs (so the stub knows where to jump). */
1125 bfd_vma target_value
;
1126 asection
*target_section
;
1128 /* Offset to apply to relocation referencing target_value. */
1129 bfd_vma target_addend
;
1131 /* The stub type. */
1132 enum elf32_csky_stub_type stub_type
;
1133 /* Its encoding size in bytes. */
1136 const insn_sequence
*stub_template
;
1137 /* The size of the template (number of entries). */
1138 int stub_template_size
;
1140 /* The symbol table entry, if any, that this was derived from. */
1141 struct csky_elf_link_hash_entry
*h
;
1143 /* Destination symbol type. */
1144 unsigned char st_type
;
1146 /* Where this stub is being called from, or, in the case of combined
1147 stub sections, the first input section in the group. */
1150 /* The name for the local symbol at the start of this stub. The
1151 stub name in the hash table has to be unique; this does not, so
1152 it can be friendlier. */
1156 #define csky_stub_hash_lookup(table, string, create, copy) \
1157 ((struct elf32_csky_stub_hash_entry *) \
1158 bfd_hash_lookup ((table), (string), (create), (copy)))
1160 /* C-SKY ELF linker hash entry. */
1161 struct csky_elf_link_hash_entry
1163 struct elf_link_hash_entry elf
;
1165 /* For sub jsri2bsr relocs count. */
1166 int jsri2bsr_refcount
;
1168 #define GOT_UNKNOWN 0
1169 #define GOT_NORMAL 1
1170 #define GOT_TLS_GD 2
1171 #define GOT_TLS_IE 4
1173 unsigned char tls_type
;
1175 /* A pointer to the most recently used stub hash entry against this
1177 struct elf32_csky_stub_hash_entry
*stub_cache
;
1180 /* Traverse an C-SKY ELF linker hash table. */
1181 #define csky_elf_link_hash_traverse(table, func, info) \
1182 (elf_link_hash_traverse \
1184 (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
1187 /* Get the C-SKY ELF linker hash table from a link_info structure. */
1188 #define csky_elf_hash_table(p) \
1189 ((is_elf_hash_table ((p)->hash) \
1190 && elf_hash_table_id (elf_hash_table (p)) == CSKY_ELF_DATA) \
1191 ? (struct csky_elf_link_hash_table *) (p)->hash : NULL)
1193 #define csky_elf_hash_entry(ent) ((struct csky_elf_link_hash_entry*)(ent))
1195 /* Array to keep track of which stub sections have been created, and
1196 information on stub grouping. */
1199 /* This is the section to which stubs in the group will be
1202 /* The stub section. */
1206 /* C-SKY ELF linker hash table. */
1207 struct csky_elf_link_hash_table
1209 struct elf_link_hash_table elf
;
1211 /* Data for R_CKCORE_TLS_LDM32 relocations. */
1214 bfd_signed_vma refcount
;
1218 /* The stub hash table. */
1219 struct bfd_hash_table stub_hash_table
;
1221 /* Linker stub bfd. */
1224 /* Linker call-backs. */
1225 asection
* (*add_stub_section
) (const char *, asection
*);
1226 void (*layout_sections_again
) (void);
1228 /* Array to keep track of which stub sections have been created, and
1229 * information on stub grouping. */
1230 struct map_stub
*stub_group
;
1232 /* Number of elements in stub_group. */
1233 unsigned int top_id
;
1235 /* Assorted information used by elf32_csky_size_stubs. */
1236 unsigned int bfd_count
;
1237 unsigned int top_index
;
1238 asection
**input_list
;
1241 /* We can't change vectors in the bfd target which will apply to
1242 data sections, however we only do this to the text sections. */
1245 csky_get_insn_32 (bfd
*input_bfd
,
1248 if (bfd_big_endian (input_bfd
))
1249 return bfd_get_32 (input_bfd
, location
);
1251 return (bfd_get_16 (input_bfd
, location
) << 16
1252 | bfd_get_16 (input_bfd
, location
+ 2));
1256 csky_put_insn_32 (bfd
*input_bfd
,
1260 if (bfd_big_endian (input_bfd
))
1261 bfd_put_32 (input_bfd
, x
, location
);
1264 bfd_put_16 (input_bfd
, x
>> 16, location
);
1265 bfd_put_16 (input_bfd
, x
& 0xffff, location
+ 2);
1269 /* Find or create a stub section. Returns a pointer to the stub section, and
1270 the section to which the stub section will be attached (in *LINK_SEC_P).
1271 LINK_SEC_P may be NULL. */
1274 elf32_csky_create_or_find_stub_sec (asection
**link_sec_p
, asection
*section
,
1275 struct csky_elf_link_hash_table
*htab
)
1280 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
1281 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
1282 if (stub_sec
== NULL
)
1284 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
1285 if (stub_sec
== NULL
)
1291 namelen
= strlen (link_sec
->name
);
1292 len
= namelen
+ sizeof (STUB_SUFFIX
);
1293 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
1297 memcpy (s_name
, link_sec
->name
, namelen
);
1298 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
1299 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
1300 if (stub_sec
== NULL
)
1302 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
1304 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
1308 *link_sec_p
= link_sec
;
1313 /* Build a name for an entry in the stub hash table. */
1316 elf32_csky_stub_name (const asection
*input_section
,
1317 const asection
*sym_sec
,
1318 const struct csky_elf_link_hash_entry
*hash
,
1319 const Elf_Internal_Rela
*rel
)
1326 len
= 8 + 1 + strlen (hash
->elf
.root
.root
.string
) + 1 + 8 + 1;
1327 stub_name
= bfd_malloc (len
);
1328 if (stub_name
!= NULL
)
1329 sprintf (stub_name
, "%08x_%s+%x",
1330 input_section
->id
& 0xffffffff,
1331 hash
->elf
.root
.root
.string
,
1332 (int) rel
->r_addend
& 0xffffffff);
1336 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
1337 stub_name
= bfd_malloc (len
);
1338 if (stub_name
!= NULL
)
1339 sprintf (stub_name
, "%08x_%x:%x+%x",
1340 input_section
->id
& 0xffffffff,
1341 sym_sec
->id
& 0xffffffff,
1342 (int) ELF32_R_SYM (rel
->r_info
) & 0xffffffff,
1343 (int) rel
->r_addend
& 0xffffffff);
1349 /* Determine the type of stub needed, if any, for a call. */
1351 static enum elf32_csky_stub_type
1352 csky_type_of_stub (struct bfd_link_info
*info
,
1353 asection
*input_sec
,
1354 const Elf_Internal_Rela
*rel
,
1355 unsigned char st_type
,
1356 struct csky_elf_link_hash_entry
*hash
,
1357 bfd_vma destination
,
1358 asection
*sym_sec ATTRIBUTE_UNUSED
,
1359 bfd
*input_bfd ATTRIBUTE_UNUSED
,
1360 const char *name ATTRIBUTE_UNUSED
)
1363 bfd_signed_vma branch_offset
;
1364 unsigned int r_type
;
1365 enum elf32_csky_stub_type stub_type
= csky_stub_none
;
1366 struct elf_link_hash_entry
* h
= &hash
->elf
;
1368 /* We don't know the actual type of destination in case it is of
1369 type STT_SECTION: give up. */
1370 if (st_type
== STT_SECTION
)
1373 location
= (input_sec
->output_offset
1374 + input_sec
->output_section
->vma
1377 branch_offset
= (bfd_signed_vma
)(destination
- location
);
1378 r_type
= ELF32_R_TYPE (rel
->r_info
);
1379 if (r_type
== R_CKCORE_PCREL_IMM26BY2
1381 && ((h
->def_dynamic
&& !h
->def_regular
)
1382 || (bfd_link_pic (info
)
1383 && h
->root
.type
== bfd_link_hash_defweak
)))
1384 || branch_offset
> BSR_MAX_FWD_BRANCH_OFFSET
1385 || branch_offset
< BSR_MAX_BWD_BRANCH_OFFSET
))
1387 if (bfd_csky_arch (info
->output_bfd
) == CSKY_ARCH_810
1388 || bfd_csky_arch (info
->output_bfd
) == CSKY_ARCH_807
)
1389 stub_type
= csky_stub_long_branch_jmpi
;
1391 stub_type
= csky_stub_long_branch
;
1397 /* Create an entry in an C-SKY ELF linker hash table. */
1399 static struct bfd_hash_entry
*
1400 csky_elf_link_hash_newfunc (struct bfd_hash_entry
* entry
,
1401 struct bfd_hash_table
* table
,
1402 const char * string
)
1404 struct csky_elf_link_hash_entry
* ret
=
1405 (struct csky_elf_link_hash_entry
*) entry
;
1407 /* Allocate the structure if it has not already been allocated by a
1411 ret
= (struct csky_elf_link_hash_entry
*)
1412 bfd_hash_allocate (table
,
1413 sizeof (struct csky_elf_link_hash_entry
));
1415 return (struct bfd_hash_entry
*) ret
;
1418 /* Call the allocation method of the superclass. */
1419 ret
= ((struct csky_elf_link_hash_entry
*)
1420 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*)ret
,
1424 struct csky_elf_link_hash_entry
*eh
;
1426 eh
= (struct csky_elf_link_hash_entry
*) ret
;
1427 eh
->plt_refcount
= 0;
1428 eh
->jsri2bsr_refcount
= 0;
1429 eh
->tls_type
= GOT_NORMAL
;
1430 ret
->stub_cache
= NULL
;
1433 return (struct bfd_hash_entry
*) ret
;
1436 /* Initialize an entry in the stub hash table. */
1438 static struct bfd_hash_entry
*
1439 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
1440 struct bfd_hash_table
*table
,
1443 /* Allocate the structure if it has not already been allocated by a
1447 entry
= ((struct bfd_hash_entry
*)
1448 bfd_hash_allocate (table
,
1449 sizeof (struct elf32_csky_stub_hash_entry
)));
1454 /* Call the allocation method of the superclass. */
1455 entry
= bfd_hash_newfunc (entry
, table
, string
);
1458 struct elf32_csky_stub_hash_entry
*eh
;
1460 /* Initialize the local fields. */
1461 eh
= (struct elf32_csky_stub_hash_entry
*) entry
;
1462 eh
->stub_sec
= NULL
;
1463 eh
->stub_offset
= 0;
1464 eh
->target_value
= 0;
1465 eh
->target_section
= NULL
;
1466 eh
->target_addend
= 0;
1467 eh
->stub_type
= csky_stub_none
;
1469 eh
->stub_template
= NULL
;
1470 eh
->stub_template_size
= -1;
1473 eh
->output_name
= NULL
;
1479 /* Free the derived linker hash table. */
1482 csky_elf_link_hash_table_free (bfd
*obfd
)
1484 struct csky_elf_link_hash_table
*ret
1485 = (struct csky_elf_link_hash_table
*) obfd
->link
.hash
;
1487 bfd_hash_table_free (&ret
->stub_hash_table
);
1488 _bfd_elf_link_hash_table_free (obfd
);
1491 /* Create an CSKY elf linker hash table. */
1493 static struct bfd_link_hash_table
*
1494 csky_elf_link_hash_table_create (bfd
*abfd
)
1496 struct csky_elf_link_hash_table
*ret
;
1497 size_t amt
= sizeof (struct csky_elf_link_hash_table
);
1499 ret
= (struct csky_elf_link_hash_table
*) bfd_zmalloc (amt
);
1503 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
1504 csky_elf_link_hash_newfunc
,
1505 sizeof (struct csky_elf_link_hash_entry
),
1512 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
,
1513 sizeof (struct elf32_csky_stub_hash_entry
)))
1518 ret
->elf
.root
.hash_table_free
= csky_elf_link_hash_table_free
;
1519 return &ret
->elf
.root
;
1523 csky_elf_mkobject (bfd
*abfd
)
1525 return bfd_elf_allocate_object (abfd
, sizeof (struct csky_elf_obj_tdata
),
1529 /* Adjust a symbol defined by a dynamic object and referenced by a
1530 regular object. The current definition is in some section of the
1531 dynamic object, but we're not including those sections. We have to
1532 change the definition to something the rest of the link can
1536 csky_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1537 struct elf_link_hash_entry
*h
)
1539 struct csky_elf_link_hash_entry
*eh
;
1540 struct csky_elf_link_hash_table
*htab
;
1543 eh
= (struct csky_elf_link_hash_entry
*)h
;
1547 htab
= csky_elf_hash_table (info
);
1551 /* Clear jsri2bsr_refcount, if creating shared library files. */
1552 if (bfd_link_pic (info
) && eh
->jsri2bsr_refcount
> 0)
1553 eh
->jsri2bsr_refcount
= 0;
1555 /* If there is a function, put it in the procedure linkage table. We
1556 will fill in the contents of the procedure linkage table later. */
1559 /* Calls to STT_GNU_IFUNC symbols always use a PLT, even if the
1560 symbol binds locally. */
1561 if (h
->plt
.refcount
<= 0
1562 || (h
->type
!= STT_GNU_IFUNC
1563 && (SYMBOL_CALLS_LOCAL (info
, h
)
1564 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1565 && h
->root
.type
== bfd_link_hash_undefweak
))))
1568 /* This case can occur if we saw a PLT32 reloc in an input
1569 file, but the symbol was never referred to by a dynamic
1570 object, or if all references were garbage collected. In
1571 such a case, we don't actually need to build a procedure
1572 linkage table, and we can just do a PC32 reloc instead. */
1573 h
->plt
.offset
= (bfd_vma
) -1;
1575 if (h
->got
.refcount
== 0)
1576 h
->got
.refcount
+= 1;
1578 else if (h
->got
.refcount
!= 0)
1580 h
->got
.refcount
-= eh
->plt_refcount
;
1581 eh
->plt_refcount
= 0;
1586 /* It's possible that we incorrectly decided a .plt reloc was
1587 needed for an R_CKCORE_PC32 or similar reloc to a non-function
1588 sym in check_relocs. We can't decide accurately between function
1589 and non-function syms in check_relocs; objects loaded later in
1590 the link may change h->type. So fix it now. */
1591 h
->plt
.offset
= (bfd_vma
) -1;
1593 /* If this is a weak symbol, and there is a real definition, the
1594 processor independent code will have arranged for us to see the
1595 real definition first, and we can just use the same value. */
1596 if (h
->is_weakalias
)
1598 struct elf_link_hash_entry
*def
= weakdef (h
);
1599 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
1600 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
1601 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
1605 /* If there are no non-GOT references, we do not need a copy
1607 if (!h
->non_got_ref
)
1610 /* This is a reference to a symbol defined by a dynamic object which
1611 is not a function. */
1613 /* If we are creating a shared library, we must presume that the
1614 only references to the symbol are via the global offset table.
1615 For such cases we need not do anything here; the relocations will
1616 be handled correctly by relocate_section. */
1617 if (bfd_link_pic (info
) || htab
->elf
.is_relocatable_executable
)
1620 /* We must allocate the symbol in our .dynbss section, which will
1621 become part of the .bss section of the executable. There will be
1622 an entry for this symbol in the .dynsym section. The dynamic
1623 object will contain position independent code, so all references
1624 from the dynamic object to this symbol will go through the global
1625 offset table. The dynamic linker will use the .dynsym entry to
1626 determine the address it must put in the global offset table, so
1627 both the dynamic object and the regular object will refer to the
1628 same memory location for the variable. */
1629 /* We must generate a R_CKCORE_COPY reloc to tell the dynamic linker to
1630 copy the initial value out of the dynamic object and into the
1631 runtime process image. We need to remember the offset into the
1632 .rela.bss section we are going to use. */
1633 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
1635 s
= htab
->elf
.sdynrelro
;
1636 srel
= htab
->elf
.sreldynrelro
;
1640 s
= htab
->elf
.sdynbss
;
1641 srel
= htab
->elf
.srelbss
;
1643 if (info
->nocopyreloc
== 0
1644 && (h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0
1649 srel
->size
+= sizeof (Elf32_External_Rela
);
1651 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
1658 /* Allocate space in .plt, .got and associated reloc sections for
1662 csky_allocate_dynrelocs (struct elf_link_hash_entry
*h
, PTR inf
)
1664 struct bfd_link_info
*info
;
1665 struct csky_elf_link_hash_table
*htab
;
1666 struct csky_elf_link_hash_entry
*eh
;
1667 struct elf_dyn_relocs
*p
;
1669 /* For indirect case, such as _ZdlPv to _ZdlPv@@GLIBCXX_3.4. */
1670 if (h
->root
.type
== bfd_link_hash_indirect
)
1673 if (h
->root
.type
== bfd_link_hash_warning
)
1674 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1677 info
= (struct bfd_link_info
*) inf
;
1678 htab
= csky_elf_hash_table (info
);
1681 /*TODO: how to deal with weak symbol relocs. */
1682 if ((htab
->elf
.dynamic_sections_created
|| h
->type
== STT_GNU_IFUNC
)
1683 && h
->plt
.refcount
> 0)
1685 /* Make sure this symbol is output as a dynamic symbol.
1686 Undefined weak syms won't yet be marked as dynamic. */
1687 if (h
->dynindx
== -1 && !h
->forced_local
1688 && h
->root
.type
== bfd_link_hash_undefweak
1689 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
1691 if (bfd_link_pic (info
) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
1693 asection
*splt
= htab
->elf
.splt
;
1695 /* If this is the first .plt entry, make room for the special
1697 if (splt
->size
== 0)
1699 if (bfd_csky_abi (info
->output_bfd
) == CSKY_ABI_V1
)
1700 splt
->size
+= PLT_ENTRY_SIZE_P
;
1702 splt
->size
+= PLT_ENTRY_SIZE
;
1704 h
->plt
.offset
= splt
->size
;
1706 /* If this symbol is not defined in a regular file, and we are
1707 not generating a shared library, then set the symbol to this
1708 location in the .plt. This is required to make function
1709 pointers compare as equal between the normal executable and
1710 the shared library. */
1711 if (!bfd_link_pic (info
) && !h
->def_regular
)
1713 h
->root
.u
.def
.section
= splt
;
1714 h
->root
.u
.def
.value
= h
->plt
.offset
;
1717 /* Make room for this entry. */
1718 if (bfd_csky_abi (info
->output_bfd
) == CSKY_ABI_V1
)
1719 splt
->size
+= PLT_ENTRY_SIZE_P
;
1721 splt
->size
+= PLT_ENTRY_SIZE
;
1722 /* We also need to make an entry in the .rela.plt section. */
1723 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rela
);
1725 /* We also need to make an entry in the .got.plt section, which
1726 will be placed in the .got section by the linker script. */
1727 htab
->elf
.sgotplt
->size
+= 4;
1731 h
->plt
.offset
= (bfd_vma
) -1;
1737 h
->plt
.offset
= (bfd_vma
) -1;
1741 if (h
->got
.refcount
> 0)
1747 int tls_type
= csky_elf_hash_entry (h
)->tls_type
;
1748 /* Make sure this symbol is output as a dynamic symbol.
1749 Undefined weak syms won't yet be marked as dynamic. */
1750 if (h
->dynindx
== -1 && !h
->forced_local
1751 && h
->root
.type
== bfd_link_hash_undefweak
1752 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
1755 sgot
= htab
->elf
.sgot
;
1756 h
->got
.offset
= sgot
->size
;
1757 BFD_ASSERT (tls_type
!= GOT_UNKNOWN
);
1758 if (tls_type
== GOT_NORMAL
)
1759 /* Non-TLS symbols need one GOT slot. */
1763 if (tls_type
& GOT_TLS_GD
)
1764 /* R_CKCORE_TLS_GD32 needs 2 consecutive GOT slots. */
1766 if (tls_type
& GOT_TLS_IE
)
1767 /* R_CKCORE_TLS_IE32 needs one GOT slot. */
1770 dyn
= htab
->elf
.dynamic_sections_created
;
1772 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
)
1773 && (! bfd_link_pic (info
) || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
1776 if (tls_type
!= GOT_NORMAL
1777 && (bfd_link_pic (info
) || indx
!= 0)
1778 && ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1779 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
1780 || h
->root
.type
!= bfd_link_hash_undefweak
))
1782 if (tls_type
& GOT_TLS_IE
)
1783 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rela
);
1784 if (tls_type
& GOT_TLS_GD
)
1785 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rela
);
1786 if ((tls_type
& GOT_TLS_GD
) && indx
!= 0)
1787 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rela
);
1789 else if (((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1790 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
1791 || h
->root
.type
!= bfd_link_hash_undefweak
)
1792 && (bfd_link_pic (info
)
1793 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)
1794 || h
->plt
.offset
== (bfd_vma
) -1))
1795 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rela
);
1798 h
->got
.offset
= (bfd_vma
) -1;
1800 eh
= (struct csky_elf_link_hash_entry
*) h
;
1801 if (h
->dyn_relocs
== NULL
)
1804 /* In the shared -Bsymbolic case, discard space allocated for
1805 dynamic pc-relative relocs against symbols which turn out to be
1806 defined in regular objects. For the normal shared case, discard
1807 space for pc-relative relocs that have become local due to symbol
1808 visibility changes. */
1810 if (bfd_link_pic (info
))
1812 if (SYMBOL_CALLS_LOCAL (info
, h
))
1814 struct elf_dyn_relocs
**pp
;
1816 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
1818 p
->count
-= p
->pc_count
;
1827 if (eh
->jsri2bsr_refcount
1828 && h
->root
.type
== bfd_link_hash_defined
1829 && h
->dyn_relocs
!= NULL
)
1830 h
->dyn_relocs
->count
-= eh
->jsri2bsr_refcount
;
1832 /* Also discard relocs on undefined weak syms with non-default
1834 if (h
->dyn_relocs
!= NULL
1835 && h
->root
.type
== bfd_link_hash_undefweak
)
1837 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1838 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
1839 h
->dyn_relocs
= NULL
;
1841 /* Make sure undefined weak symbols are output as a dynamic
1843 else if (h
->dynindx
== -1
1845 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
1852 /* For the non-shared case, discard space for relocs against
1853 symbols which turn out to need copy relocs or are not
1857 && ((h
->def_dynamic
&& !h
->def_regular
)
1858 || (htab
->elf
.dynamic_sections_created
1859 && (h
->root
.type
== bfd_link_hash_undefweak
1860 || h
->root
.type
== bfd_link_hash_indirect
1861 || h
->root
.type
== bfd_link_hash_undefined
))))
1863 /* Make sure this symbol is output as a dynamic symbol.
1864 Undefined weak syms won't yet be marked as dynamic. */
1865 if (h
->dynindx
== -1 && !h
->forced_local
1866 && h
->root
.type
== bfd_link_hash_undefweak
)
1868 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
1872 /* If that succeeded, we know we'll be keeping all the
1874 if (h
->dynindx
!= -1)
1878 h
->dyn_relocs
= NULL
;
1883 /* Finally, allocate space. */
1884 for (p
= h
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1886 asection
*srelgot
= htab
->elf
.srelgot
;
1887 srelgot
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
1893 /* Set the sizes of the dynamic sections. */
1896 csky_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
1897 struct bfd_link_info
*info
)
1899 struct csky_elf_link_hash_table
*htab
;
1905 htab
= csky_elf_hash_table (info
);
1908 dynobj
= htab
->elf
.dynobj
;
1912 if (htab
->elf
.dynamic_sections_created
)
1914 /* Set the contents of the .interp section to the interpreter. */
1915 if (!bfd_link_pic (info
) && !info
->nointerp
)
1917 s
= bfd_get_section_by_name (dynobj
, ".interp");
1918 BFD_ASSERT (s
!= NULL
);
1919 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1920 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1924 /* Set up .got offsets for local syms, and space for local dynamic
1926 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
1928 bfd_signed_vma
*local_got_refcounts
;
1929 bfd_signed_vma
*end_local_got
;
1930 bfd_size_type locsymcount
;
1931 Elf_Internal_Shdr
*symtab_hdr
;
1932 asection
*srelgot
, *sgot
;
1933 char *local_tls_type
;
1935 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
1938 sgot
= htab
->elf
.sgot
;
1939 srelgot
= htab
->elf
.srelgot
;
1941 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
1943 struct elf_dyn_relocs
*p
;
1945 for (p
= *((struct elf_dyn_relocs
**)
1946 &elf_section_data (s
)->local_dynrel
);
1950 if (!bfd_is_abs_section (p
->sec
)
1951 && bfd_is_abs_section (p
->sec
->output_section
))
1952 /* Input section has been discarded, either because
1953 it is a copy of a linkonce section or due to
1954 linker script /DISCARD/, so we'll be discarding
1957 else if (p
->count
!= 0)
1959 srelgot
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
1960 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
1961 info
->flags
|= DF_TEXTREL
;
1966 local_got_refcounts
= elf_local_got_refcounts (ibfd
);
1967 if (!local_got_refcounts
)
1970 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
1971 locsymcount
= symtab_hdr
->sh_info
;
1972 end_local_got
= local_got_refcounts
+ locsymcount
;
1973 local_tls_type
= csky_elf_local_got_tls_type (ibfd
);
1975 for (; local_got_refcounts
< end_local_got
;
1976 ++local_got_refcounts
, ++local_tls_type
)
1978 if (*local_got_refcounts
> 0)
1980 /* GOT_TLS_GD and GOT_TLS_IE type for TLS, GOT_NORMAL type
1981 for GOT. If output file is shared library, we should output
1982 GOT_TLS_GD type relocation in .rel.got. */
1983 *local_got_refcounts
= sgot
->size
;
1984 if (*local_tls_type
& GOT_TLS_GD
)
1985 /* TLS_GD relocs need an 8-byte structure in the GOT. */
1987 if (*local_tls_type
& GOT_TLS_IE
)
1989 if (*local_tls_type
== GOT_NORMAL
)
1991 if (bfd_link_pic (info
) || *local_tls_type
== GOT_TLS_GD
)
1992 srelgot
->size
+= sizeof (Elf32_External_Rela
);
1995 *local_got_refcounts
= (bfd_vma
) -1;
1999 if (htab
->tls_ldm_got
.refcount
> 0)
2001 /* Allocate two GOT entries and one dynamic relocation (if necessary)
2002 for R_CSKY_TLS_LDM32 relocations. */
2003 htab
->tls_ldm_got
.offset
= htab
->elf
.sgot
->size
;
2004 htab
->elf
.sgot
->size
+= 8;
2005 if (bfd_link_pic (info
))
2006 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rela
);
2009 htab
->tls_ldm_got
.offset
= -1;
2011 /* Allocate global sym .plt and .got entries, and space for global
2012 sym dynamic relocs. */
2013 elf_link_hash_traverse (&htab
->elf
, csky_allocate_dynrelocs
, (PTR
) info
);
2015 /* Check for GOT overflow. */
2016 if (check_got_overflow
== 1
2017 && htab
->elf
.sgot
->size
+ htab
->elf
.sgotplt
->size
> GOT_MAX_SIZE
)
2019 _bfd_error_handler (_("GOT table size out of range")); /* */
2023 /* We now have determined the sizes of the various dynamic sections.
2024 Allocate memory for them. */
2026 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2028 bfd_boolean strip_section
= TRUE
;
2030 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2033 if (s
== htab
->elf
.splt
2034 || s
== htab
->elf
.sgot
2035 || s
== htab
->elf
.sgotplt
2036 || s
== htab
->elf
.sdynrelro
2037 || s
== htab
->elf
.sreldynrelro
)
2039 /* Strip this section if we don't need it;
2040 see the comment below. */
2041 /* We'd like to strip these sections if they aren't needed, but if
2042 we've exported dynamic symbols from them we must leave them.
2043 It's too late to tell BFD to get rid of the symbols. */
2045 if (htab
->elf
.hplt
!= NULL
)
2046 strip_section
= FALSE
;
2048 else if (CONST_STRNEQ (bfd_section_name (s
), ".rel") )
2053 /* We use the reloc_count field as a counter if we need
2054 to copy relocs into the output file. */
2058 /* It's not one of our sections, so don't allocate space. */
2061 /* Strip this section if we don't need it; see the
2065 /* If we don't need this section, strip it from the
2066 output file. This is mostly to handle .rel.bss and
2067 .rel.plt. We must create both sections in
2068 create_dynamic_sections, because they must be created
2069 before the linker maps input sections to output
2070 sections. The linker does that before
2071 adjust_dynamic_symbol is called, and it is that
2072 function which decides whether anything needs to go
2073 into these sections. */
2075 s
->flags
|= SEC_EXCLUDE
;
2079 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2082 /* Allocate memory for the section contents. We use bfd_zalloc
2083 here in case unused entries are not reclaimed before the
2084 section's contents are written out. This should not happen,
2085 but this way if it does, we get a R_CKCORE_NONE reloc instead
2087 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
2088 if (s
->contents
== NULL
)
2092 if (htab
->elf
.dynamic_sections_created
)
2093 htab
->elf
.dt_pltgot_required
= htab
->elf
.sgot
->size
!= 0;
2094 return _bfd_elf_add_dynamic_tags (output_bfd
, info
, relocs
);
2097 /* Finish up dynamic symbol handling. We set the contents of various
2098 dynamic sections here. */
2101 csky_elf_finish_dynamic_symbol (bfd
*output_bfd
,
2102 struct bfd_link_info
*info
,
2103 struct elf_link_hash_entry
*h
,
2104 Elf_Internal_Sym
*sym
)
2106 struct csky_elf_link_hash_table
*htab
;
2108 htab
= csky_elf_hash_table (info
);
2112 /* Sanity check to make sure no unexpected symbol reaches here.
2113 This matches the test in csky_elf_relocate_section handling
2114 of GOT/PLT entries. */
2115 BFD_ASSERT (! (h
->dynindx
== -1
2117 && h
->root
.type
!= bfd_link_hash_undefweak
2118 && bfd_link_pic (info
)));
2120 if (h
->plt
.offset
!= (bfd_vma
) -1)
2124 Elf_Internal_Rela rel
;
2126 asection
*plt
, *relplt
, *gotplt
;
2128 plt
= htab
->elf
.splt
;
2129 relplt
= htab
->elf
.srelplt
;
2130 gotplt
= htab
->elf
.sgotplt
;
2132 /* This symbol has an entry in the procedure linkage table. Set
2134 BFD_ASSERT (h
->dynindx
!= -1
2135 || ((h
->forced_local
|| bfd_link_executable (info
))
2136 && h
->def_regular
));
2137 BFD_ASSERT (plt
!= NULL
&& gotplt
!= NULL
&& relplt
!= NULL
);
2138 if (bfd_csky_abi (output_bfd
) == CSKY_ABI_V2
)
2139 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
2141 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE_P
- 1;
2142 got_offset
= (plt_index
+ 3) * 4;
2144 /* Fill in the entry in the procedure linkage table. */
2145 if (bfd_csky_abi (output_bfd
) == CSKY_ABI_V2
)
2147 csky_put_insn_32 (output_bfd
, csky_elf_plt_entry_v2
[0],
2148 plt
->contents
+ h
->plt
.offset
);
2149 csky_put_insn_32 (output_bfd
,
2150 (csky_elf_plt_entry_v2
[1] | plt_index
),
2151 plt
->contents
+ h
->plt
.offset
+ 4);
2152 csky_put_insn_32 (output_bfd
, csky_elf_plt_entry_v2
[2],
2153 plt
->contents
+ h
->plt
.offset
+ 8);
2158 for (i
= 0; i
< 6; i
++)
2159 bfd_put_16 (output_bfd
, csky_elf_plt_entry_v1
[i
],
2160 plt
->contents
+ h
->plt
.offset
+ i
* 2);
2161 bfd_put_32 (output_bfd
, plt_index
,
2162 plt
->contents
+ h
->plt
.offset
+ i
* 2);
2165 /* Fill in the entry in the .rel.plt section. */
2166 rel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
2167 + htab
->elf
.sgotplt
->output_offset
2169 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_CKCORE_JUMP_SLOT
);
2170 rel
.r_addend
= (plt
->output_section
->vma
2171 + plt
->output_offset
2173 loc
= (htab
->elf
.srelplt
->contents
2174 + plt_index
* sizeof (Elf32_External_Rela
));
2177 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
2178 if (! h
->def_regular
)
2180 /* Mark the symbol as undefined, rather than as defined in
2181 the .plt section. Leave the value alone. */
2182 sym
->st_shndx
= SHN_UNDEF
;
2183 /* If the symbol is weak, we do need to clear the value.
2184 Otherwise, the PLT entry would provide a definition for
2185 the symbol even if the symbol wasn't defined anywhere,
2186 and so the symbol would never be NULL. Leave the value if
2187 there were any relocations where pointer equality matters
2188 (this is a clue for the dynamic linker, to make function
2189 pointer comparisons work between an application and shared
2191 if (!h
->ref_regular_nonweak
|| !h
->pointer_equality_needed
)
2196 /* Fill in the entry in the .got section. */
2197 if (h
->got
.offset
!= (bfd_vma
) -1
2198 && ((csky_elf_hash_entry (h
)->tls_type
& GOT_TLS_GD
) == 0)
2199 && ((csky_elf_hash_entry (h
)->tls_type
& GOT_TLS_IE
) == 0))
2201 Elf_Internal_Rela rel
;
2204 /* This symbol has an entry in the global offset table.
2206 BFD_ASSERT (htab
->elf
.sgot
!= NULL
&& htab
->elf
.srelgot
!= NULL
);
2208 rel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
2209 + htab
->elf
.sgot
->output_offset
2210 + (h
->got
.offset
& ~(bfd_vma
) 1));
2212 /* If this is a static link, or it is a -Bsymbolic link and the
2213 symbol is defined locally or was forced to be local because
2214 of a version file, we just want to emit a RELATIVE reloc.
2215 The entry in the global offset table will already have been
2216 initialized in the relocate_section function. */
2217 if (bfd_link_pic (info
) && SYMBOL_REFERENCES_LOCAL (info
, h
))
2219 BFD_ASSERT ((h
->got
.offset
& 1) != 0);
2220 rel
.r_info
= ELF32_R_INFO (0, R_CKCORE_RELATIVE
);
2221 rel
.r_addend
= (h
->root
.u
.def
.value
2222 + h
->root
.u
.def
.section
->output_offset
2223 + h
->root
.u
.def
.section
->output_section
->vma
);
2227 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
2228 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
2229 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
2230 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_CKCORE_GLOB_DAT
);
2234 loc
= htab
->elf
.srelgot
->contents
;
2235 loc
+= htab
->elf
.srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
2238 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
2244 Elf_Internal_Rela rela
;
2247 /* This symbol needs a copy reloc. Set it up. */
2248 BFD_ASSERT (h
->dynindx
!= -1
2249 && (h
->root
.type
== bfd_link_hash_defined
2250 || h
->root
.type
== bfd_link_hash_defweak
));
2252 rela
.r_offset
= (h
->root
.u
.def
.value
2253 + h
->root
.u
.def
.section
->output_section
->vma
2254 + h
->root
.u
.def
.section
->output_offset
);
2255 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_CKCORE_COPY
);
2257 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
2258 s
= htab
->elf
.sreldynrelro
;
2260 s
= htab
->elf
.srelbss
;
2261 BFD_ASSERT (s
!= NULL
);
2262 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
2263 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
2266 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
2267 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
2268 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2269 sym
->st_shndx
= SHN_ABS
;
2274 /* Finish up the dynamic sections. */
2277 csky_elf_finish_dynamic_sections (bfd
*output_bfd
,
2278 struct bfd_link_info
*info
)
2280 struct csky_elf_link_hash_table
*htab
;
2285 htab
= csky_elf_hash_table (info
);
2289 dynobj
= htab
->elf
.dynobj
;
2290 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2292 if (htab
->elf
.dynamic_sections_created
)
2294 Elf32_External_Dyn
*dyncon
, *dynconend
;
2296 BFD_ASSERT (sdyn
!= NULL
&& htab
->elf
.sgot
!= NULL
);
2298 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
2299 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
2300 for (; dyncon
< dynconend
; dyncon
++)
2302 Elf_Internal_Dyn dyn
;
2303 bfd_boolean size
= FALSE
;
2304 const char *name
= NULL
;
2306 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2324 dyn
.d_un
.d_ptr
= htab
->elf
.sgot
->output_section
->vma
;
2327 dyn
.d_un
.d_ptr
= htab
->elf
.srelplt
->output_section
->vma
2328 + htab
->elf
.srelplt
->output_offset
;
2334 asection
*s
= bfd_get_section_by_name (output_bfd
, name
);
2339 dyn
.d_un
.d_ptr
= s
->vma
;
2341 dyn
.d_un
.d_val
= s
->size
;
2343 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2347 /* Fill in the first three entries in the global offset table. */
2348 if (htab
->elf
.sgotplt
)
2349 got_sec
= htab
->elf
.sgotplt
;
2351 got_sec
= htab
->elf
.sgot
;
2352 if (got_sec
!= NULL
)
2354 if (got_sec
->size
> 0)
2356 bfd_put_32 (output_bfd
,
2357 (sdyn
== NULL
? (bfd_vma
) 0
2358 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
2360 bfd_put_32 (output_bfd
, (bfd_vma
) 0, got_sec
->contents
+ 4);
2361 bfd_put_32 (output_bfd
, (bfd_vma
) 0, got_sec
->contents
+ 8);
2363 elf_section_data (got_sec
->output_section
)->this_hdr
.sh_entsize
= 4;
2368 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2371 csky_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
2372 struct elf_link_hash_entry
*dir
,
2373 struct elf_link_hash_entry
*ind
)
2375 struct csky_elf_link_hash_entry
*edir
, *eind
;
2377 edir
= (struct csky_elf_link_hash_entry
*) dir
;
2378 eind
= (struct csky_elf_link_hash_entry
*) ind
;
2380 if (ind
->root
.type
== bfd_link_hash_indirect
2381 && dir
->got
.refcount
<= 0)
2383 edir
->tls_type
= eind
->tls_type
;
2384 eind
->tls_type
= GOT_UNKNOWN
;
2386 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
2389 /* Used to decide how to sort relocs in an optimal manner for the
2390 dynamic linker, before writing them out. */
2392 static enum elf_reloc_type_class
2393 csky_elf_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2394 const asection
*rel_sec ATTRIBUTE_UNUSED
,
2395 const Elf_Internal_Rela
*rela
)
2397 switch ((int) ELF32_R_TYPE (rela
->r_info
))
2399 case R_CKCORE_RELATIVE
:
2400 return reloc_class_relative
;
2401 case R_CKCORE_JUMP_SLOT
:
2402 return reloc_class_plt
;
2404 return reloc_class_copy
;
2405 case R_CKCORE_IRELATIVE
:
2406 return reloc_class_ifunc
;
2408 return reloc_class_normal
;
2412 /* Return the section that should be marked against GC for a given
2416 csky_elf_gc_mark_hook (asection
*sec
,
2417 struct bfd_link_info
*info
,
2418 Elf_Internal_Rela
*rel
,
2419 struct elf_link_hash_entry
*h
,
2420 Elf_Internal_Sym
*sym
)
2424 switch (ELF32_R_TYPE (rel
->r_info
))
2426 case R_CKCORE_GNU_VTINHERIT
:
2427 case R_CKCORE_GNU_VTENTRY
:
2432 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
2435 /* Look through the relocs for a section during the first phase.
2436 Since we don't do .gots or .plts, we just need to consider the
2437 virtual table relocs for gc. */
2440 csky_elf_check_relocs (bfd
* abfd
,
2441 struct bfd_link_info
* info
,
2443 const Elf_Internal_Rela
* relocs
)
2445 Elf_Internal_Shdr
* symtab_hdr
;
2446 struct elf_link_hash_entry
** sym_hashes
;
2447 const Elf_Internal_Rela
* rel
;
2448 const Elf_Internal_Rela
* rel_end
;
2449 struct csky_elf_link_hash_table
*htab
;
2452 /* if output type is relocatable, return. */
2453 if (bfd_link_relocatable (info
))
2456 htab
= csky_elf_hash_table (info
);
2460 symtab_hdr
= & elf_tdata (abfd
)->symtab_hdr
;
2461 sym_hashes
= elf_sym_hashes (abfd
);
2463 rel_end
= relocs
+ sec
->reloc_count
;
2465 for (rel
= relocs
; rel
< rel_end
; rel
++)
2467 struct elf_link_hash_entry
*h
;
2468 unsigned long r_symndx
;
2469 Elf_Internal_Sym
*isym
;
2472 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2473 r_type
= ELF32_R_TYPE (rel
->r_info
);
2474 if (r_symndx
< symtab_hdr
->sh_info
)
2476 /* A local symbol. */
2477 isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
,
2486 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2487 while (h
->root
.type
== bfd_link_hash_indirect
2488 || h
->root
.type
== bfd_link_hash_warning
)
2489 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2494 case R_CKCORE_PCREL_IMM26BY2
:
2495 case R_CKCORE_PCREL_IMM11BY2
:
2496 case R_CKCORE_PCREL_JSR_IMM11BY2
:
2497 case R_CKCORE_PCREL_JSR_IMM26BY2
:
2498 /* If the symbol is '*UND*', means this reloc is used for
2499 * callgraph, don't need to leave to shared object. */
2502 /* Else fall through. */
2503 case R_CKCORE_ADDR32
:
2504 case R_CKCORE_ADDR_HI16
:
2505 case R_CKCORE_ADDR_LO16
:
2507 && bfd_link_executable (info
)
2508 && r_type
== R_CKCORE_ADDR32
2509 && h
->type
== STT_OBJECT
2510 && (sec
->flags
& SEC_ALLOC
) != 0
2511 && (sec
->flags
& SEC_READONLY
))
2512 /* If this reloc is in a read-only section, we might
2513 need a copy reloc. We can't check reliably at this
2514 stage whether the section is read-only, as input
2515 sections have not yet been mapped to output sections.
2516 Tentatively set the flag for now, and correct in
2517 adjust_dynamic_symbol. */
2520 /* If we are creating a shared library or relocatable executable,
2521 and this is a reloc against a global symbol, then we need to
2522 copy the reloc into the shared library. However, if we are
2523 linking with -Bsymbolic, we do not need to copy a reloc
2524 against a global symbol which is defined in an object we are
2525 including in the link (i.e., DEF_REGULAR is set). At
2526 this point we have not seen all the input files, so it is
2527 possible that DEF_REGULAR is not set now but will be set
2528 later (it is never cleared). We account for that possibility
2529 below by storing information in the relocs_copied field of
2530 the hash table entry. */
2531 if ((bfd_link_pic (info
) && (sec
->flags
& SEC_ALLOC
) != 0)
2532 || (!bfd_link_pic (info
)
2533 && (sec
->flags
& SEC_ALLOC
) != 0
2535 && (h
->root
.type
== bfd_link_hash_defweak
2536 || !h
->def_regular
)))
2538 struct elf_dyn_relocs
*p
;
2539 struct elf_dyn_relocs
**head
;
2540 /* We must copy these reloc types into the output file.
2541 Create a reloc section in dynobj and make room for
2545 if (htab
->elf
.dynobj
== NULL
)
2546 htab
->elf
.dynobj
= abfd
;
2548 sreloc
= _bfd_elf_make_dynamic_reloc_section
2549 (sec
, htab
->elf
.dynobj
, 2, abfd
, TRUE
);
2555 if (h
== NULL
&& !use_branch_stub
2556 && ((ELF32_R_TYPE (rel
->r_info
)
2557 == R_CKCORE_PCREL_IMM26BY2
)
2558 || (ELF32_R_TYPE (rel
->r_info
)
2559 == R_CKCORE_PCREL_IMM11BY2
)))
2562 /* If this is a global symbol, we count the number of
2563 relocations we need for this symbol. */
2566 struct csky_elf_link_hash_entry
*eh
;
2567 eh
= (struct csky_elf_link_hash_entry
*)h
;
2568 if ((ELF32_R_TYPE (rel
->r_info
)
2569 == R_CKCORE_PCREL_JSR_IMM26BY2
)
2570 || (ELF32_R_TYPE (rel
->r_info
)
2571 == R_CKCORE_PCREL_JSR_IMM11BY2
))
2572 eh
->jsri2bsr_refcount
+= 1;
2573 head
= &h
->dyn_relocs
;
2577 /* Track dynamic relocs needed for local syms too.
2578 We really need local syms available to do this
2582 Elf_Internal_Sym
*loc_isym
;
2584 loc_isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
,
2586 if (loc_isym
== NULL
)
2588 s
= bfd_section_from_elf_index (abfd
, loc_isym
->st_shndx
);
2591 vpp
= &elf_section_data (s
)->local_dynrel
;
2592 head
= (struct elf_dyn_relocs
**)vpp
;
2596 if (p
== NULL
|| p
->sec
!= sec
)
2598 size_t amt
= sizeof *p
;
2599 p
= ((struct elf_dyn_relocs
*)
2600 bfd_alloc (htab
->elf
.dynobj
, amt
));
2610 if (ELF32_R_TYPE (rel
->r_info
) == R_CKCORE_PCREL_IMM26BY2
2611 || ELF32_R_TYPE (rel
->r_info
) == R_CKCORE_PCREL_IMM11BY2
)
2617 case R_CKCORE_PLT_IMM18BY4
:
2618 case R_CKCORE_PLT32
:
2619 /* This symbol requires a procedure linkage table entry. We
2620 actually build the entry in adjust_dynamic_symbol,
2621 because this might be a case of linking PIC code which is
2622 never referenced by a dynamic object, in which case we
2623 don't need to generate a procedure linkage table entry
2626 /* If this is a local symbol, we resolve it directly without
2627 creating a procedure linkage table entry. */
2630 if (ELF32_R_TYPE (rel
->r_info
) == R_CKCORE_PLT_IMM18BY4
)
2631 check_got_overflow
= 1;
2634 h
->plt
.refcount
+= 1;
2635 h
->got
.refcount
+= 1;
2636 ((struct csky_elf_link_hash_entry
*)h
)->plt_refcount
+= 1;
2639 case R_CKCORE_GOT12
:
2640 case R_CKCORE_PLT12
:
2641 case R_CKCORE_GOT32
:
2642 case R_CKCORE_GOT_HI16
:
2643 case R_CKCORE_GOT_LO16
:
2644 case R_CKCORE_PLT_HI16
:
2645 case R_CKCORE_PLT_LO16
:
2646 case R_CKCORE_GOT_IMM18BY4
:
2647 case R_CKCORE_TLS_IE32
:
2648 case R_CKCORE_TLS_GD32
:
2650 int tls_type
, old_tls_type
;
2653 && bfd_link_executable (info
)
2654 && r_type
== R_CKCORE_GOT_IMM18BY4
2655 && (sec
->flags
& SEC_ALLOC
) != 0
2656 && (sec
->flags
& SEC_READONLY
))
2657 /* If this reloc is in a read-only section, we might
2658 need a copy reloc. We can't check reliably at this
2659 stage whether the section is read-only, as input
2660 sections have not yet been mapped to output sections.
2661 Tentatively set the flag for now, and correct in
2662 adjust_dynamic_symbol. */
2665 switch (ELF32_R_TYPE (rel
->r_info
))
2667 case R_CKCORE_TLS_IE32
:
2668 tls_type
= GOT_TLS_IE
;
2670 case R_CKCORE_TLS_GD32
:
2671 tls_type
= GOT_TLS_GD
;
2674 tls_type
= GOT_NORMAL
;
2679 if (ELF32_R_TYPE (rel
->r_info
) == R_CKCORE_GOT_IMM18BY4
)
2680 check_got_overflow
= 1;
2681 h
->got
.refcount
+= 1;
2682 old_tls_type
= csky_elf_hash_entry (h
)->tls_type
;
2686 bfd_signed_vma
*local_got_refcounts
;
2688 /* This is a global offset table entry for a local symbol. */
2689 /* we can write a new function named
2690 elf32_csky_allocate_local_sym_info() to replace
2692 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2693 if (local_got_refcounts
== NULL
)
2697 size
= symtab_hdr
->sh_info
;
2698 size
*= (sizeof (bfd_signed_vma
) + sizeof (char));
2699 local_got_refcounts
= ((bfd_signed_vma
*)
2700 bfd_zalloc (abfd
, size
));
2701 if (local_got_refcounts
== NULL
)
2703 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2704 csky_elf_local_got_tls_type (abfd
)
2705 = (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
2707 local_got_refcounts
[r_symndx
] += 1;
2708 old_tls_type
= csky_elf_local_got_tls_type (abfd
)[r_symndx
];
2711 /* We will already have issued an error message if there is a
2712 TLS / non-TLS mismatch, based on the symbol type. We don't
2713 support any linker relaxations. So just combine any TLS
2715 if (old_tls_type
!= GOT_UNKNOWN
&& old_tls_type
!= GOT_NORMAL
2716 && tls_type
!= GOT_NORMAL
)
2717 tls_type
|= old_tls_type
;
2719 if (old_tls_type
!= tls_type
)
2722 csky_elf_hash_entry (h
)->tls_type
= tls_type
;
2724 csky_elf_local_got_tls_type (abfd
)[r_symndx
] = tls_type
;
2729 case R_CKCORE_TLS_LDM32
:
2730 if (ELF32_R_TYPE (rel
->r_info
) == R_CKCORE_TLS_LDM32
)
2731 htab
->tls_ldm_got
.refcount
++;
2734 case R_CKCORE_GOTOFF
:
2735 case R_CKCORE_GOTPC
:
2736 case R_CKCORE_GOTOFF_HI16
:
2737 case R_CKCORE_GOTOFF_LO16
:
2738 case R_CKCORE_GOTPC_HI16
:
2739 case R_CKCORE_GOTPC_LO16
:
2740 case R_CKCORE_GOTOFF_IMM18
:
2741 if (htab
->elf
.sgot
== NULL
)
2743 if (htab
->elf
.dynobj
== NULL
)
2744 htab
->elf
.dynobj
= abfd
;
2745 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
2750 /* This relocation describes the C++ object vtable hierarchy.
2751 Reconstruct it for later use during GC. */
2752 case R_CKCORE_GNU_VTINHERIT
:
2753 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2757 /* This relocation describes which C++ vtable entries are actually
2758 used. Record for later use during GC. */
2759 case R_CKCORE_GNU_VTENTRY
:
2760 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2769 static const struct bfd_elf_special_section csky_elf_special_sections
[]=
2771 { STRING_COMMA_LEN (".ctors"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2772 { STRING_COMMA_LEN (".dtors"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2773 { NULL
, 0, 0, 0, 0 }
2776 /* Function to keep CSKY specific flags in the ELF header. */
2779 csky_elf_set_private_flags (bfd
* abfd
, flagword flags
)
2781 BFD_ASSERT (! elf_flags_init (abfd
)
2782 || elf_elfheader (abfd
)->e_flags
== flags
);
2784 elf_elfheader (abfd
)->e_flags
= flags
;
2785 elf_flags_init (abfd
) = TRUE
;
2789 static csky_arch_for_merge
*
2790 csky_find_arch_with_eflag (const unsigned long arch_eflag
)
2792 csky_arch_for_merge
*csky_arch
= NULL
;
2794 for (csky_arch
= csky_archs
; csky_arch
->name
!= NULL
; csky_arch
++)
2795 if (csky_arch
->arch_eflag
== arch_eflag
)
2797 if (csky_arch
== NULL
)
2799 _bfd_error_handler (_("warning: unrecognized arch eflag '%#lx'"),
2801 bfd_set_error (bfd_error_wrong_format
);
2806 static csky_arch_for_merge
*
2807 csky_find_arch_with_name (const char *name
)
2809 csky_arch_for_merge
*csky_arch
= NULL
;
2815 for (csky_arch
= csky_archs
; csky_arch
->name
!= NULL
; csky_arch
++)
2817 if (strncmp (csky_arch
->name
, name
, strlen (csky_arch
->name
)) == 0)
2820 if (csky_arch
== NULL
)
2822 msg
= _("warning: unrecognised arch name '%#x'");
2823 (*_bfd_error_handler
) (msg
, name
);
2824 bfd_set_error (bfd_error_wrong_format
);
2830 elf32_csky_merge_attributes (bfd
*ibfd
, struct bfd_link_info
*info
)
2832 bfd
*obfd
= info
->output_bfd
;
2833 obj_attribute
*in_attr
;
2834 obj_attribute
*out_attr
;
2835 obj_attribute tattr
;
2836 csky_arch_for_merge
*old_arch
= NULL
;
2837 csky_arch_for_merge
*new_arch
= NULL
;
2839 bfd_boolean result
= TRUE
;
2840 const char *msg
= NULL
;
2842 const char *sec_name
= get_elf_backend_data (ibfd
)->obj_attrs_section
;
2844 /* Skip the linker stubs file. This preserves previous behavior
2845 of accepting unknown attributes in the first input file - but
2847 if (ibfd
->flags
& BFD_LINKER_CREATED
)
2850 /* Skip any input that hasn't attribute section.
2851 This enables to link object files without attribute section with
2853 if (bfd_get_section_by_name (ibfd
, sec_name
) == NULL
)
2858 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
2860 /* This is the first object. Copy the attributes. */
2861 out_attr
= elf_known_obj_attributes_proc (obfd
);
2863 /* If Tag_CSKY_CPU_NAME is already set, save it. */
2864 memcpy (&tattr
, &out_attr
[Tag_CSKY_ARCH_NAME
], sizeof (tattr
));
2866 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
2868 out_attr
= elf_known_obj_attributes_proc (obfd
);
2870 /* Restore Tag_CSKY_CPU_NAME. */
2871 memcpy (&out_attr
[Tag_CSKY_ARCH_NAME
], &tattr
, sizeof (tattr
));
2873 /* Use the Tag_null value to indicate the attributes have been
2878 in_attr
= elf_known_obj_attributes_proc (ibfd
);
2879 out_attr
= elf_known_obj_attributes_proc (obfd
);
2881 for (i
= LEAST_KNOWN_OBJ_ATTRIBUTE
; i
< NUM_KNOWN_OBJ_ATTRIBUTES
; i
++)
2883 /* Merge this attribute with existing attributes. */
2886 case Tag_CSKY_CPU_NAME
:
2887 case Tag_CSKY_ARCH_NAME
:
2888 /* Do arch merge. */
2889 new_arch
= csky_find_arch_with_name (in_attr
[Tag_CSKY_ARCH_NAME
].s
);
2890 old_arch
= csky_find_arch_with_name (out_attr
[Tag_CSKY_ARCH_NAME
].s
);
2892 if (new_arch
!= NULL
&& old_arch
!= NULL
)
2894 if (new_arch
->class != old_arch
->class)
2896 msg
= _("%pB: machine flag conflict with target");
2897 (*_bfd_error_handler
) (msg
, ibfd
);
2898 bfd_set_error (bfd_error_wrong_format
);
2901 else if (new_arch
->class_level
!= old_arch
->class_level
)
2903 csky_arch_for_merge
*newest_arch
=
2904 ((new_arch
->class_level
> old_arch
->class_level
) ?
2905 new_arch
: old_arch
);
2907 if (new_arch
->do_warning
|| old_arch
->do_warning
)
2909 msg
= _("warning: file %pB's arch flag %s conflict "
2910 "with target %s,set target arch flag to %s");
2911 (*_bfd_error_handler
) (msg
, ibfd
, new_arch
->name
,
2913 (newest_arch
->name
));
2914 bfd_set_error (bfd_error_wrong_format
);
2917 if (out_attr
[Tag_CSKY_ARCH_NAME
].s
!= NULL
)
2918 bfd_release (obfd
, out_attr
[Tag_CSKY_ARCH_NAME
].s
);
2920 out_attr
[Tag_CSKY_ARCH_NAME
].s
=
2921 _bfd_elf_attr_strdup (obfd
, newest_arch
->name
);
2927 case Tag_CSKY_ISA_FLAGS
:
2928 case Tag_CSKY_ISA_EXT_FLAGS
:
2932 case Tag_CSKY_VDSP_VERSION
:
2933 if (out_attr
[i
].i
== 0)
2934 out_attr
[i
].i
= in_attr
[i
].i
;
2935 else if (out_attr
[i
].i
!= in_attr
[i
].i
)
2938 (_("Error: %pB and %pB has different VDSP version"), ibfd
, obfd
);
2943 case Tag_CSKY_FPU_VERSION
:
2944 if (out_attr
[i
].i
<= in_attr
[i
].i
2945 && out_attr
[i
].i
== 0)
2946 out_attr
[i
].i
= in_attr
[i
].i
;
2949 case Tag_CSKY_DSP_VERSION
:
2950 if (out_attr
[i
].i
== 0)
2951 out_attr
[i
].i
= in_attr
[i
].i
;
2952 else if (out_attr
[i
].i
!= in_attr
[i
].i
)
2955 (_("Error: %pB and %pB has different DSP version"), ibfd
, obfd
);
2960 case Tag_CSKY_FPU_ABI
:
2961 if (out_attr
[i
].i
!= in_attr
[i
].i
2962 && (out_attr
[i
].i
== 0
2963 || (out_attr
[i
].i
== VAL_CSKY_FPU_ABI_SOFT
2964 && in_attr
[i
].i
== VAL_CSKY_FPU_ABI_SOFTFP
)))
2966 out_attr
[i
].i
= in_attr
[i
].i
;
2968 else if (out_attr
[i
].i
== VAL_CSKY_FPU_ABI_HARD
2969 && (out_attr
[i
].i
!= in_attr
[i
].i
2970 && in_attr
[i
].i
!= 0))
2973 (_("Error: %pB and %pB has different FPU ABI"), ibfd
, obfd
);
2980 result
&& _bfd_elf_merge_unknown_attribute_low (ibfd
, obfd
, i
);
2984 /* If out_attr was copied from in_attr then it won't have a type yet. */
2985 if (in_attr
[i
].type
&& !out_attr
[i
].type
)
2986 out_attr
[i
].type
= in_attr
[i
].type
;
2989 /* Merge Tag_compatibility attributes and any common GNU ones. */
2990 if (!_bfd_elf_merge_object_attributes (ibfd
, info
))
2993 /* Check for any attributes not known on CSKY. */
2994 result
&= _bfd_elf_merge_unknown_attribute_list (ibfd
, obfd
);
2999 /* Merge backend specific data from an object file to the output
3000 object file when linking. */
3003 csky_elf_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
3005 bfd
*obfd
= info
->output_bfd
;
3008 csky_arch_for_merge
*old_arch
= NULL
;
3009 csky_arch_for_merge
*new_arch
= NULL
;
3010 flagword newest_flag
= 0;
3011 const char *sec_name
;
3012 obj_attribute
*out_attr
;
3014 /* Check if we have the same endianness. */
3015 if (! _bfd_generic_verify_endian_match (ibfd
, info
))
3018 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
3019 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
3022 /* Merge ".csky.attribute" section. */
3023 if (!elf32_csky_merge_attributes (ibfd
, info
))
3026 if (! elf_flags_init (obfd
))
3028 /* First call, no flags set. */
3029 elf_flags_init (obfd
) = TRUE
;
3032 /* Try to merge e_flag. */
3033 new_flags
= elf_elfheader (ibfd
)->e_flags
;
3034 old_flags
= elf_elfheader (obfd
)->e_flags
;
3035 out_attr
= elf_known_obj_attributes_proc (obfd
);
3037 /* the flags like"e , f ,g ..." , we take collection. */
3038 newest_flag
= (old_flags
& (~CSKY_ARCH_MASK
))
3039 | (new_flags
& (~CSKY_ARCH_MASK
));
3041 sec_name
= get_elf_backend_data (ibfd
)->obj_attrs_section
;
3042 if (bfd_get_section_by_name (ibfd
, sec_name
) == NULL
)
3044 /* Input BFDs have no ".csky.attribute" section. */
3045 new_arch
= csky_find_arch_with_eflag (new_flags
& CSKY_ARCH_MASK
);
3046 old_arch
= csky_find_arch_with_name (out_attr
[Tag_CSKY_ARCH_NAME
].s
);
3048 if (new_arch
!= NULL
&& old_arch
!= NULL
)
3050 if (new_arch
->class != old_arch
->class)
3053 /* xgettext:c-format */
3054 (_("%pB: machine flag conflict with target"), ibfd
);
3055 bfd_set_error (bfd_error_wrong_format
);
3058 else if (new_arch
->class_level
!= old_arch
->class_level
)
3060 csky_arch_for_merge
*newest_arch
=
3061 (new_arch
->class_level
> old_arch
->class_level
3062 ? new_arch
: old_arch
);
3064 if (new_arch
->do_warning
|| old_arch
->do_warning
)
3067 /* xgettext:c-format */
3068 (_("warning: file %pB's arch flag %s conflicts with "
3069 "target ck%s, using %s"),
3070 ibfd
, new_arch
->name
, old_arch
->name
,
3072 bfd_set_error (bfd_error_wrong_format
);
3075 if (out_attr
[Tag_CSKY_ARCH_NAME
].s
!= NULL
)
3076 bfd_release (obfd
, out_attr
[Tag_CSKY_ARCH_NAME
].s
);
3078 out_attr
[Tag_CSKY_ARCH_NAME
].s
=
3079 _bfd_elf_attr_strdup (obfd
, newest_arch
->name
);
3082 newest_flag
|= ((new_flags
& (CSKY_ARCH_MASK
| CSKY_ABI_MASK
))
3083 | (old_flags
& (CSKY_ARCH_MASK
| CSKY_ABI_MASK
)));
3087 if (new_arch
&& new_arch
->name
!= NULL
)
3088 out_attr
[Tag_CSKY_ARCH_NAME
].s
=
3089 _bfd_elf_attr_strdup (obfd
, new_arch
->name
);
3093 elf_elfheader (obfd
)->e_flags
= newest_flag
;
3098 /* Ignore the discarded relocs in special sections in link time. */
3101 csky_elf_ignore_discarded_relocs (asection
*sec
)
3103 if (strcmp (sec
->name
, ".csky_stack_size") == 0)
3108 /* .csky_stack_size are not referenced directly. This pass marks all of
3109 them as required. */
3112 elf32_csky_gc_mark_extra_sections (struct bfd_link_info
*info
,
3113 elf_gc_mark_hook_fn gc_mark_hook ATTRIBUTE_UNUSED
)
3117 _bfd_elf_gc_mark_extra_sections (info
, gc_mark_hook
);
3119 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link
.next
)
3123 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
3124 if (strcmp (o
->name
, ".csky_stack_size") == 0)
3131 /* The linker repeatedly calls this function for each input section,
3132 in the order that input sections are linked into output sections.
3133 Build lists of input sections to determine groupings between which
3134 we may insert linker stubs. */
3137 elf32_csky_next_input_section (struct bfd_link_info
*info
,
3140 struct csky_elf_link_hash_table
*htab
= csky_elf_hash_table (info
);
3143 if (isec
->output_section
->index
<= htab
->top_index
)
3145 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
3147 if (*list
!= bfd_abs_section_ptr
)
3149 /* Steal the link_sec pointer for our list. */
3150 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
3151 /* This happens to make the list in reverse order,
3152 which we reverse later in group_sections. */
3153 PREV_SEC (isec
) = *list
;
3159 /* See whether we can group stub sections together. Grouping stub
3160 sections may result in fewer stubs. More importantly, we need to
3161 put all .init* and .fini* stubs at the end of the .init or
3162 .fini output sections respectively, because glibc splits the
3163 _init and _fini functions into multiple parts. Putting a stub in
3164 the middle of a function is not a good idea. */
3167 group_sections (struct csky_elf_link_hash_table
*htab
,
3168 bfd_size_type stub_group_size
,
3169 bfd_boolean stubs_always_after_branch
)
3171 asection
**list
= htab
->input_list
;
3175 asection
*tail
= *list
;
3178 if (tail
== bfd_abs_section_ptr
)
3181 /* Reverse the list: we must avoid placing stubs at the
3182 beginning of the section because the beginning of the text
3183 section may be required for an interrupt vector in bare metal
3185 #define NEXT_SEC PREV_SEC
3187 while (tail
!= NULL
)
3189 /* Pop from tail. */
3190 asection
*item
= tail
;
3191 tail
= PREV_SEC (item
);
3194 NEXT_SEC (item
) = head
;
3198 while (head
!= NULL
)
3202 bfd_vma stub_group_start
= head
->output_offset
;
3203 bfd_vma end_of_next
;
3206 while (NEXT_SEC (curr
) != NULL
)
3208 next
= NEXT_SEC (curr
);
3209 end_of_next
= next
->output_offset
+ next
->size
;
3210 if (end_of_next
- stub_group_start
>= stub_group_size
)
3211 /* End of NEXT is too far from start, so stop. */
3216 /* OK, the size from the start to the start of CURR is less
3217 * than stub_group_size and thus can be handled by one stub
3218 * section. (Or the head section is itself larger than
3219 * stub_group_size, in which case we may be toast.)
3220 * We should really be keeping track of the total size of
3221 * stubs added here, as stubs contribute to the final output
3225 next
= NEXT_SEC (head
);
3226 /* Set up this stub group. */
3227 htab
->stub_group
[head
->id
].link_sec
= curr
;
3229 while (head
!= curr
&& (head
= next
) != NULL
);
3231 /* But wait, there's more! Input sections up to stub_group_size
3232 * bytes after the stub section can be handled by it too. */
3233 if (!stubs_always_after_branch
)
3235 stub_group_start
= curr
->output_offset
+ curr
->size
;
3237 while (next
!= NULL
)
3239 end_of_next
= next
->output_offset
+ next
->size
;
3240 if (end_of_next
- stub_group_start
>= stub_group_size
)
3241 /* End of NEXT is too far from stubs, so stop. */
3243 /* Add NEXT to the stub group. */
3245 next
= NEXT_SEC (head
);
3246 htab
->stub_group
[head
->id
].link_sec
= curr
;
3252 while (list
++ != htab
->input_list
+ htab
->top_index
);
3254 free (htab
->input_list
);
3259 /* If the symbol referenced by bsr is defined in shared object file,
3260 or it is a weak symbol and we aim to create shared object file,
3261 we must create a stub for this bsr. */
3264 sym_must_create_stub (struct elf_link_hash_entry
*h
,
3265 struct bfd_link_info
*info
)
3268 && ((h
->def_dynamic
&& !h
->def_regular
)
3269 || (bfd_link_pic (info
) && h
->root
.type
== bfd_link_hash_defweak
)))
3275 /* Calculate the template, template size and instruction size for a stub.
3276 Return value is the instruction size. */
3279 find_stub_size_and_template (enum elf32_csky_stub_type stub_type
,
3280 const insn_sequence
**stub_template
,
3281 int *stub_template_size
)
3283 const insn_sequence
*template_sequence
= NULL
;
3284 int template_size
= 0;
3288 template_sequence
= stub_definitions
[stub_type
].template_sequence
;
3289 template_size
= stub_definitions
[stub_type
].template_size
;
3292 for (i
= 0; i
< template_size
; i
++)
3294 switch (template_sequence
[i
].type
)
3312 *stub_template
= template_sequence
;
3313 if (stub_template_size
)
3314 *stub_template_size
= template_size
;
3319 /* As above, but don't actually build the stub. Just bump offset so
3320 we know stub section sizes. */
3323 csky_size_one_stub (struct bfd_hash_entry
*gen_entry
,
3324 void * in_arg ATTRIBUTE_UNUSED
)
3326 struct elf32_csky_stub_hash_entry
*stub_entry
;
3327 const insn_sequence
*template_sequence
= NULL
;
3328 int template_size
= 0;
3331 /* Massage our args to the form they really have. */
3332 stub_entry
= (struct elf32_csky_stub_hash_entry
*) gen_entry
;
3334 BFD_ASSERT (stub_entry
->stub_type
> csky_stub_none
3335 && stub_entry
->stub_type
< ARRAY_SIZE (stub_definitions
));
3336 size
= find_stub_size_and_template (stub_entry
->stub_type
,
3337 &template_sequence
, &template_size
);
3338 stub_entry
->stub_size
= size
;
3339 stub_entry
->stub_template
= template_sequence
;
3340 stub_entry
->stub_template_size
= template_size
;
3342 size
= (size
+ 7) & ~7;
3343 stub_entry
->stub_sec
->size
+= size
;
3347 /* Add a new stub entry to the stub hash. Not all fields of the new
3348 stub entry are initialised. */
3350 static struct elf32_csky_stub_hash_entry
*
3351 elf32_csky_add_stub (const char *stub_name
,
3353 struct csky_elf_link_hash_table
*htab
)
3357 struct elf32_csky_stub_hash_entry
*stub_entry
;
3359 stub_sec
= elf32_csky_create_or_find_stub_sec (&link_sec
, section
, htab
);
3360 if (stub_sec
== NULL
)
3363 /* Enter this entry into the linker stub hash table. */
3364 stub_entry
= csky_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3366 if (stub_entry
== NULL
)
3368 _bfd_error_handler (_("%pB: cannot create stub entry %s"),
3369 section
->owner
, stub_name
);
3373 stub_entry
->stub_sec
= stub_sec
;
3374 stub_entry
->stub_offset
= 0;
3375 stub_entry
->id_sec
= link_sec
;
3380 /* Determine and set the size of the stub section for a final link.
3381 The basic idea here is to examine all the relocations looking for
3382 PC-relative calls to a target that is unreachable with a "bsr"
3386 elf32_csky_size_stubs (bfd
*output_bfd
,
3388 struct bfd_link_info
*info
,
3389 bfd_signed_vma group_size
,
3390 asection
*(*add_stub_section
) (const char*, asection
*),
3391 void (*layout_sections_again
) (void))
3393 bfd_size_type stub_group_size
;
3394 bfd_boolean stubs_always_after_branch
;
3395 struct csky_elf_link_hash_table
*htab
= csky_elf_hash_table (info
);
3400 /* Propagate mach to stub bfd, because it may not have been
3401 finalized when we created stub_bfd. */
3402 bfd_set_arch_mach (stub_bfd
, bfd_get_arch (output_bfd
),
3403 bfd_get_mach (output_bfd
));
3405 /* Stash our params away. */
3406 htab
->stub_bfd
= stub_bfd
;
3407 htab
->add_stub_section
= add_stub_section
;
3408 htab
->layout_sections_again
= layout_sections_again
;
3409 stubs_always_after_branch
= group_size
< 0;
3412 stub_group_size
= -group_size
;
3414 stub_group_size
= group_size
;
3416 if (stub_group_size
== 1)
3417 /* The 'bsr' range in abiv2 is +-64MB has to be used as the
3418 default maximum size.
3419 This value is 128K less than that, which allows for 131072
3420 byte stubs. If we exceed that, then we will fail to link.
3421 The user will have to relink with an explicit group size
3423 stub_group_size
= 66977792;
3425 group_sections (htab
, stub_group_size
, stubs_always_after_branch
);
3430 unsigned int bfd_indx
;
3432 bfd_boolean stub_changed
= FALSE
;
3434 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
3436 input_bfd
= input_bfd
->link
.next
, bfd_indx
++)
3438 Elf_Internal_Shdr
*symtab_hdr
;
3440 Elf_Internal_Sym
*local_syms
= NULL
;
3442 /* We'll need the symbol table in a second. */
3443 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3444 if (symtab_hdr
->sh_info
== 0)
3447 /* Walk over each section attached to the input bfd. */
3448 for (section
= input_bfd
->sections
;
3450 section
= section
->next
)
3452 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
3454 /* If there aren't any relocs, then there's nothing more
3456 if ((section
->flags
& SEC_RELOC
) == 0
3457 || section
->reloc_count
== 0
3458 || (section
->flags
& SEC_CODE
) == 0)
3461 /* If this section is a link-once section that will be
3462 discarded, then don't create any stubs. */
3463 if (section
->output_section
== NULL
3464 || section
->output_section
->owner
!= output_bfd
)
3467 /* Get the relocs. */
3468 internal_relocs
= _bfd_elf_link_read_relocs (input_bfd
,
3473 if (internal_relocs
== NULL
)
3474 goto error_ret_free_local
;
3476 /* Now examine each relocation. */
3477 irela
= internal_relocs
;
3478 irelaend
= irela
+ section
->reloc_count
;
3479 for (; irela
< irelaend
; irela
++)
3481 unsigned int r_type
, r_indx
;
3482 enum elf32_csky_stub_type stub_type
;
3483 struct elf32_csky_stub_hash_entry
*stub_entry
;
3486 bfd_vma destination
;
3487 struct csky_elf_link_hash_entry
*hash
;
3488 const char *sym_name
;
3490 const asection
*id_sec
;
3491 unsigned char st_type
;
3493 r_type
= ELF32_R_TYPE (irela
->r_info
);
3494 r_indx
= ELF32_R_SYM (irela
->r_info
);
3495 if (r_type
>= (unsigned int) R_CKCORE_MAX
)
3497 bfd_set_error (bfd_error_bad_value
);
3498 error_ret_free_internal
:
3499 if (elf_section_data (section
)->relocs
== NULL
)
3500 free (internal_relocs
);
3501 goto error_ret_free_local
;
3504 /* Only look for stubs on branch instructions. */
3505 if (r_type
!= (unsigned int) R_CKCORE_PCREL_IMM26BY2
)
3507 /* Now determine the call target, its name, value,
3514 if (r_indx
< symtab_hdr
->sh_info
)
3516 /* It's a local symbol. */
3517 Elf_Internal_Sym
*sym
;
3518 Elf_Internal_Shdr
*hdr
;
3519 if (local_syms
== NULL
)
3521 (Elf_Internal_Sym
*) symtab_hdr
->contents
;
3522 if (local_syms
== NULL
)
3525 bfd_elf_get_elf_syms (input_bfd
,
3527 symtab_hdr
->sh_info
,
3528 0, NULL
, NULL
, NULL
);
3529 if (local_syms
== NULL
)
3530 goto error_ret_free_internal
;
3532 sym
= local_syms
+ r_indx
;
3533 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
3534 sym_sec
= hdr
->bfd_section
;
3536 /* This is an undefined symbol. It can never
3539 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
3540 sym_value
= sym
->st_value
;
3541 destination
= (sym_value
+ irela
->r_addend
3542 + sym_sec
->output_offset
3543 + sym_sec
->output_section
->vma
);
3544 st_type
= ELF_ST_TYPE (sym
->st_info
);
3546 bfd_elf_string_from_elf_section (input_bfd
,
3547 symtab_hdr
->sh_link
,
3552 /* It's an external symbol. */
3554 e_indx
= r_indx
- symtab_hdr
->sh_info
;
3555 hash
= ((struct csky_elf_link_hash_entry
*)
3556 elf_sym_hashes (input_bfd
)[e_indx
]);
3558 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
3559 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
3560 hash
= ((struct csky_elf_link_hash_entry
*)
3561 hash
->elf
.root
.u
.i
.link
);
3562 if (hash
->elf
.root
.type
== bfd_link_hash_defined
3563 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
3565 sym_sec
= hash
->elf
.root
.u
.def
.section
;
3566 sym_value
= hash
->elf
.root
.u
.def
.value
;
3568 struct csky_elf_link_hash_table
*globals
=
3569 csky_elf_hash_table (info
);
3570 /* FIXME For a destination in a shared library. */
3571 if (globals
->elf
.splt
!= NULL
&& hash
!= NULL
3572 && hash
->elf
.plt
.offset
!= (bfd_vma
) -1)
3574 else if (sym_sec
->output_section
!= NULL
)
3575 destination
= (sym_value
+ irela
->r_addend
3576 + sym_sec
->output_offset
3577 + sym_sec
->output_section
->vma
);
3579 else if (hash
->elf
.root
.type
== bfd_link_hash_undefined
3580 || (hash
->elf
.root
.type
3581 == bfd_link_hash_undefweak
))
3582 /* FIXME For a destination in a shared library. */
3586 bfd_set_error (bfd_error_bad_value
);
3587 goto error_ret_free_internal
;
3589 st_type
= ELF_ST_TYPE (hash
->elf
.type
);
3590 sym_name
= hash
->elf
.root
.root
.string
;
3594 /* Determine what (if any) linker stub is needed. */
3595 stub_type
= csky_type_of_stub (info
, section
, irela
,
3597 destination
, sym_sec
,
3598 input_bfd
, sym_name
);
3599 if (stub_type
== csky_stub_none
)
3602 /* Support for grouping stub sections. */
3603 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
3605 /* Get the name of this stub. */
3606 stub_name
= elf32_csky_stub_name (id_sec
, sym_sec
, hash
,
3609 goto error_ret_free_internal
;
3610 /* We've either created a stub for this reloc already,
3611 or we are about to. */
3613 = csky_stub_hash_lookup (&htab
->stub_hash_table
,
3616 if (stub_entry
!= NULL
)
3618 /* The proper stub has already been created. */
3620 stub_entry
->target_value
= sym_value
;
3623 stub_entry
= elf32_csky_add_stub (stub_name
, section
,
3625 if (stub_entry
== NULL
)
3628 goto error_ret_free_internal
;
3630 stub_entry
->target_value
= sym_value
;
3631 stub_entry
->target_section
= sym_sec
;
3632 stub_entry
->stub_type
= stub_type
;
3633 stub_entry
->h
= hash
;
3634 stub_entry
->st_type
= st_type
;
3636 if (sym_name
== NULL
)
3637 sym_name
= "unnamed";
3638 stub_entry
->output_name
=
3639 bfd_alloc (htab
->stub_bfd
,
3640 (sizeof (STUB_ENTRY_NAME
)
3641 + strlen (sym_name
)));
3642 if (stub_entry
->output_name
== NULL
)
3645 goto error_ret_free_internal
;
3647 sprintf (stub_entry
->output_name
, STUB_ENTRY_NAME
,
3649 stub_changed
= TRUE
;
3653 /* We're done with the internal relocs, free them. */
3654 if (elf_section_data (section
)->relocs
== NULL
)
3655 free (internal_relocs
);
3660 /* OK, we've added some stubs. Find out the new size of the
3662 for (stub_sec
= htab
->stub_bfd
->sections
;
3664 stub_sec
= stub_sec
->next
)
3666 /* Ignore non-stub sections. */
3667 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
3671 bfd_hash_traverse (&htab
->stub_hash_table
, csky_size_one_stub
, htab
);
3672 /* Ask the linker to do its stuff. */
3673 (*htab
->layout_sections_again
) ();
3677 error_ret_free_local
:
3682 csky_build_one_stub (struct bfd_hash_entry
*gen_entry
,
3686 struct elf32_csky_stub_hash_entry
*stub_entry
;
3687 struct bfd_link_info
*info
;
3694 const insn_sequence
*template_sequence
;
3696 struct csky_elf_link_hash_table
* globals
;
3697 int stub_reloc_idx
[MAXRELOCS
] = {-1, -1};
3698 int stub_reloc_offset
[MAXRELOCS
] = {0, 0};
3700 struct elf_link_hash_entry
*h
= NULL
;
3702 /* Massage our args to the form they really have. */
3703 stub_entry
= (struct elf32_csky_stub_hash_entry
*)gen_entry
;
3704 info
= (struct bfd_link_info
*) in_arg
;
3706 /* Fail if the target section could not be assigned to an output
3707 section. The user should fix his linker script. */
3708 if (stub_entry
->target_section
->output_section
== NULL
3709 && info
->non_contiguous_regions
)
3710 info
->callbacks
->einfo (_("%F%P: Could not assign '%pA' to an output section. "
3711 "Retry without --enable-non-contiguous-regions.\n"),
3712 stub_entry
->target_section
);
3714 globals
= csky_elf_hash_table (info
);
3715 if (globals
== NULL
)
3717 stub_sec
= stub_entry
->stub_sec
;
3719 /* Make a note of the offset within the stubs for this entry. */
3720 stub_entry
->stub_offset
= stub_sec
->size
;
3721 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
3723 stub_bfd
= stub_sec
->owner
;
3725 /* This is the address of the stub destination. */
3726 h
= &stub_entry
->h
->elf
;
3727 if (sym_must_create_stub (h
, info
)
3728 && !(bfd_link_pic (info
)
3729 && h
->root
.type
== bfd_link_hash_defweak
3731 && !h
->def_dynamic
))
3734 sym_value
= (stub_entry
->target_value
3735 + stub_entry
->target_section
->output_offset
3736 + stub_entry
->target_section
->output_section
->vma
);
3738 template_sequence
= stub_entry
->stub_template
;
3739 template_size
= stub_entry
->stub_template_size
;
3742 for (i
= 0; i
< template_size
; i
++)
3743 switch (template_sequence
[i
].type
)
3746 bfd_put_16 (stub_bfd
, (bfd_vma
) template_sequence
[i
].data
,
3751 csky_put_insn_32 (stub_bfd
, (bfd_vma
) template_sequence
[i
].data
,
3756 bfd_put_32 (stub_bfd
, (bfd_vma
) template_sequence
[i
].data
,
3758 stub_reloc_idx
[nrelocs
] = i
;
3759 stub_reloc_offset
[nrelocs
++] = size
;
3766 stub_sec
->size
+= size
;
3768 /* Stub size has already been computed in csky_size_one_stub. Check
3770 BFD_ASSERT (size
== stub_entry
->stub_size
);
3772 /* Assume there is at least one and at most MAXRELOCS entries to relocate
3774 BFD_ASSERT (nrelocs
!= 0 && nrelocs
<= MAXRELOCS
);
3776 for (i
= 0; i
< nrelocs
; i
++)
3778 if (sym_must_create_stub (h
, info
))
3780 Elf_Internal_Rela outrel
;
3781 asection
* sreloc
= globals
->elf
.srelgot
;
3783 outrel
.r_offset
= stub_entry
->stub_offset
+ stub_reloc_offset
[i
];
3785 ELF32_R_INFO (h
->dynindx
,
3786 template_sequence
[stub_reloc_idx
[i
]].r_type
);
3787 outrel
.r_addend
= template_sequence
[stub_reloc_idx
[i
]].reloc_addend
;
3789 loc
= sreloc
->contents
;
3790 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
3793 bfd_elf32_swap_reloca_out (info
->output_bfd
, &outrel
, loc
);
3795 _bfd_final_link_relocate (elf32_csky_howto_from_type
3796 (template_sequence
[stub_reloc_idx
[i
]].r_type
),
3797 stub_bfd
, stub_sec
, stub_sec
->contents
,
3798 stub_entry
->stub_offset
+ stub_reloc_offset
[i
],
3799 sym_value
+ stub_entry
->target_addend
,
3800 template_sequence
[stub_reloc_idx
[i
]].reloc_addend
);
3807 /* Build all the stubs associated with the current output file. The
3808 stubs are kept in a hash table attached to the main linker hash
3809 table. We also set up the .plt entries for statically linked PIC
3810 functions here. This function is called via arm_elf_finish in the
3814 elf32_csky_build_stubs (struct bfd_link_info
*info
)
3817 struct bfd_hash_table
*table
;
3818 struct csky_elf_link_hash_table
*htab
;
3820 htab
= csky_elf_hash_table (info
);
3825 for (stub_sec
= htab
->stub_bfd
->sections
;
3827 stub_sec
= stub_sec
->next
)
3831 /* Ignore non-stub sections. */
3832 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
3835 /* Allocate memory to hold the linker stubs. */
3836 size
= stub_sec
->size
;
3837 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, size
);
3838 if (stub_sec
->contents
== NULL
&& size
!= 0)
3843 /* Build the stubs as directed by the stub hash table. */
3844 table
= &htab
->stub_hash_table
;
3845 bfd_hash_traverse (table
, csky_build_one_stub
, info
);
3850 /* Set up various things so that we can make a list of input sections
3851 for each output section included in the link. Returns -1 on error,
3852 0 when no stubs will be needed, and 1 on success. */
3855 elf32_csky_setup_section_lists (bfd
*output_bfd
,
3856 struct bfd_link_info
*info
)
3859 unsigned int bfd_count
;
3860 unsigned int top_id
, top_index
;
3862 asection
**input_list
, **list
;
3864 struct csky_elf_link_hash_table
*htab
= csky_elf_hash_table (info
);
3868 if (! is_elf_hash_table (htab
))
3871 /* Count the number of input BFDs and find the top input section id. */
3872 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
3874 input_bfd
= input_bfd
->link
.next
)
3877 for (section
= input_bfd
->sections
;
3879 section
= section
->next
)
3880 if (top_id
< section
->id
)
3881 top_id
= section
->id
;
3883 htab
->bfd_count
= bfd_count
;
3884 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
3885 htab
->stub_group
= bfd_zmalloc (amt
);
3886 if (htab
->stub_group
== NULL
)
3889 /* We can't use output_bfd->section_count here to find the top output
3890 section index as some sections may have been removed, and
3891 _bfd_strip_section_from_output doesn't renumber the indices. */
3892 for (section
= output_bfd
->sections
, top_index
= 0;
3894 section
= section
->next
)
3895 if (top_index
< section
->index
)
3896 top_index
= section
->index
;
3897 htab
->top_index
= top_index
;
3898 amt
= sizeof (asection
*) * (top_index
+ 1);
3899 input_list
= bfd_malloc (amt
);
3900 htab
->input_list
= input_list
;
3901 if (input_list
== NULL
)
3903 /* For sections we aren't interested in, mark their entries with a
3904 value we can check later. */
3905 list
= input_list
+ top_index
;
3907 *list
= bfd_abs_section_ptr
;
3908 while (list
-- != input_list
);
3909 for (section
= output_bfd
->sections
;
3911 section
= section
->next
)
3912 if ((section
->flags
& SEC_CODE
) != 0)
3913 input_list
[section
->index
] = NULL
;
3918 static bfd_reloc_status_type
3919 csky_relocate_contents (reloc_howto_type
*howto
,
3926 bfd_reloc_status_type flag
;
3927 unsigned int rightshift
= howto
->rightshift
;
3928 unsigned int bitpos
= howto
->bitpos
;
3931 relocation
= -relocation
;
3933 /* FIXME: these macros should be defined at file head or head file head. */
3934 #define CSKY_INSN_ADDI_TO_SUBI 0x04000000
3935 #define CSKY_INSN_MOV_RTB 0xc41d4820 /* mov32 rx, r29, 0 */
3936 #define CSKY_INSN_MOV_RDB 0xc41c4820 /* mov32 rx, r28, 0 */
3937 #define CSKY_INSN_GET_ADDI_RZ(x) (((x) & 0x03e00000) >> 21)
3938 #define CSKY_INSN_SET_MOV_RZ(x) ((x) & 0x0000001f)
3939 #define CSKY_INSN_JSRI_TO_LRW 0xea9a0000
3940 #define CSKY_INSN_JSR_R26 0xe8fa0000
3942 /* Get the value we are going to relocate. */
3943 size
= bfd_get_reloc_size (howto
);
3950 x
= bfd_get_8 (input_bfd
, location
);
3953 x
= bfd_get_16 (input_bfd
, location
);
3956 if (need_reverse_bits
)
3958 x
= csky_get_insn_32 (input_bfd
, location
);
3960 if (R_CKCORE_DOFFSET_LO16
== howto
->type
)
3962 if ((bfd_signed_vma
) relocation
< 0)
3964 x
|= CSKY_INSN_ADDI_TO_SUBI
;
3965 relocation
= -relocation
;
3967 else if (0 == relocation
)
3968 x
= (CSKY_INSN_MOV_RDB
|
3969 CSKY_INSN_SET_MOV_RZ (CSKY_INSN_GET_ADDI_RZ (x
)));
3971 else if (R_CKCORE_TOFFSET_LO16
== howto
->type
)
3973 if ((bfd_signed_vma
) relocation
< 0)
3975 x
|= CSKY_INSN_ADDI_TO_SUBI
;
3976 relocation
= -relocation
;
3978 else if (0 == relocation
)
3979 x
= (CSKY_INSN_MOV_RTB
|
3980 CSKY_INSN_SET_MOV_RZ (CSKY_INSN_GET_ADDI_RZ (x
)));
3984 x
= bfd_get_32 (input_bfd
, location
);
3987 /* Check for overflow. FIXME: We may drop bits during the addition
3988 which we don't check for. We must either check at every single
3989 operation, which would be tedious, or we must do the computations
3990 in a type larger than bfd_vma, which would be inefficient. */
3991 flag
= bfd_reloc_ok
;
3992 if (howto
->complain_on_overflow
!= complain_overflow_dont
)
4001 /* Get the values to be added together. For signed and unsigned
4002 relocations, we assume that all values should be truncated to
4003 the size of an address. For bitfields, all the bits matter.
4004 See also bfd_check_overflow. */
4005 #define N_ONES(n) (((((bfd_vma) 1 << ((n) - 1)) - 1) << 1) | 1)
4006 fieldmask
= N_ONES (howto
->bitsize
);
4007 signmask
= ~fieldmask
;
4008 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
4009 a
= (relocation
& addrmask
) >> rightshift
;
4010 if (read_content_substitute
)
4011 x
= read_content_substitute
;
4012 b
= (x
& howto
->src_mask
& addrmask
) >> bitpos
;
4014 switch (howto
->complain_on_overflow
)
4016 case complain_overflow_signed
:
4017 /* If any sign bits are set, all sign bits must be set.
4018 That is, A must be a valid negative address after
4020 signmask
= ~(fieldmask
>> 1);
4023 case complain_overflow_bitfield
:
4024 /* Much like the signed check, but for a field one bit
4025 wider. We allow a bitfield to represent numbers in the
4026 range -2**n to 2**n-1, where n is the number of bits in the
4027 field. Note that when bfd_vma is 32 bits, a 32-bit reloc
4028 can't overflow, which is exactly what we want. */
4030 if (ss
!= 0 && ss
!= ((addrmask
>> rightshift
) & signmask
))
4031 flag
= bfd_reloc_overflow
;
4032 /* We only need this next bit of code if the sign bit of B
4033 is below the sign bit of A. This would only happen if
4034 SRC_MASK had fewer bits than BITSIZE. Note that if
4035 SRC_MASK has more bits than BITSIZE, we can get into
4036 trouble; we would need to verify that B is in range, as
4037 we do for A above. */
4038 ss
= ((~howto
->src_mask
) >> 1) & howto
->src_mask
;
4041 /* Set all the bits above the sign bit. */
4044 /* Now we can do the addition. */
4047 /* See if the result has the correct sign. Bits above the
4048 sign bit are junk now; ignore them. If the sum is
4049 positive, make sure we did not have all negative inputs;
4050 if the sum is negative, make sure we did not have all
4051 positive inputs. The test below looks only at the sign
4052 bits, and it really just
4053 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
4055 We mask with addrmask here to explicitly allow an address
4056 wrap-around. The Linux kernel relies on it, and it is
4057 the only way to write assembler code which can run when
4058 loaded at a location 0x80000000 away from the location at
4059 which it is linked. */
4061 if (((~(a
^ b
)) & (a
^ sum
)) & signmask
& addrmask
)
4062 flag
= bfd_reloc_overflow
;
4064 case complain_overflow_unsigned
:
4065 /* Checking for an unsigned overflow is relatively easy:
4066 trim the addresses and add, and trim the result as well.
4067 Overflow is normally indicated when the result does not
4068 fit in the field. However, we also need to consider the
4069 case when, e.g., fieldmask is 0x7fffffff or smaller, an
4070 input is 0x80000000, and bfd_vma is only 32 bits; then we
4071 will get sum == 0, but there is an overflow, since the
4072 inputs did not fit in the field. Instead of doing a
4073 separate test, we can check for this by or-ing in the
4074 operands when testing for the sum overflowing its final
4076 sum
= (a
+ b
) & addrmask
;
4077 if ((a
| b
| sum
) & signmask
)
4078 flag
= bfd_reloc_overflow
;
4085 /* Put RELOCATION in the right bits. */
4086 relocation
>>= rightshift
;
4088 if ((howto
->type
== R_CKCORE_DOFFSET_LO16
4089 || howto
->type
== R_CKCORE_TOFFSET_LO16
)
4091 /* Do nothing lsli32 rx, rz, 0. */
4095 /* Fir V1, all this relocation must be x -1. */
4096 if (howto
->type
== R_CKCORE_PCREL_IMM11BY2
4097 || howto
->type
== R_CKCORE_PCREL_JSR_IMM11BY2
4098 || howto
->type
== R_CKCORE_DOFFSET_LO16
4099 || howto
->type
== R_CKCORE_TOFFSET_LO16
)
4101 else if (howto
->type
== R_CKCORE_PCREL_IMM7BY4
)
4102 relocation
= (relocation
& 0x1f) + ((relocation
<< 3) & 0x300);
4103 else if (howto
->type
== R_CKCORE_PCREL_FLRW_IMM8BY4
)
4105 = ((relocation
<< 4) & 0xf0) + ((relocation
<< 17) & 0x1e00000);
4106 else if (howto
->type
== R_CKCORE_NOJSRI
)
4108 x
= (x
& howto
->dst_mask
) | CSKY_INSN_JSRI_TO_LRW
;
4110 csky_put_insn_32 (input_bfd
, CSKY_INSN_JSR_R26
, location
+ 4);
4113 relocation
<<= bitpos
;
4114 /* Add RELOCATION to the right bits of X. */
4115 x
= ((x
& ~howto
->dst_mask
)
4116 | (((x
& howto
->src_mask
) + relocation
) & howto
->dst_mask
));
4118 /* Put the relocated value back in the object file. */
4124 bfd_put_8 (input_bfd
, x
, location
);
4127 bfd_put_16 (input_bfd
, x
, location
);
4130 if (need_reverse_bits
)
4131 csky_put_insn_32 (input_bfd
, x
, location
);
4133 bfd_put_32 (input_bfd
, x
, location
);
4139 /* Look up an entry in the stub hash. Stub entries are cached because
4140 creating the stub name takes a bit of time. */
4142 static struct elf32_csky_stub_hash_entry
*
4143 elf32_csky_get_stub_entry (const asection
*input_section
,
4144 const asection
*sym_sec
,
4145 struct elf_link_hash_entry
*hash
,
4146 const Elf_Internal_Rela
*rel
,
4147 struct csky_elf_link_hash_table
*htab
)
4149 struct elf32_csky_stub_hash_entry
*stub_entry
;
4150 struct csky_elf_link_hash_entry
*h
4151 = (struct csky_elf_link_hash_entry
*) hash
;
4152 const asection
*id_sec
;
4154 if ((input_section
->flags
& SEC_CODE
) == 0)
4157 /* If this input section is part of a group of sections sharing one
4158 stub section, then use the id of the first section in the group.
4159 Stub names need to include a section id, as there may well be
4160 more than one stub used to reach say, printf, and we need to
4161 distinguish between them. */
4162 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
4163 if (h
!= NULL
&& h
->stub_cache
!= NULL
4164 && h
->stub_cache
->h
== h
&& h
->stub_cache
->id_sec
== id_sec
)
4165 stub_entry
= h
->stub_cache
;
4169 stub_name
= elf32_csky_stub_name (id_sec
, sym_sec
, h
, rel
);
4170 if (stub_name
== NULL
)
4172 stub_entry
= csky_stub_hash_lookup (&htab
->stub_hash_table
,
4173 stub_name
, FALSE
, FALSE
);
4175 h
->stub_cache
= stub_entry
;
4182 static bfd_reloc_status_type
4183 csky_final_link_relocate (reloc_howto_type
*howto
,
4185 asection
*input_section
,
4193 /* Sanity check the address. */
4194 if (address
> bfd_get_section_limit (input_bfd
, input_section
))
4195 return bfd_reloc_outofrange
;
4197 /* This function assumes that we are dealing with a basic relocation
4198 against a symbol. We want to compute the value of the symbol to
4199 relocate to. This is just VALUE, the value of the symbol,
4200 plus ADDEND, any addend associated with the reloc. */
4201 relocation
= value
+ addend
;
4203 /* If the relocation is PC relative, we want to set RELOCATION to
4204 the distance between the symbol (currently in RELOCATION) and the
4205 location we are relocating. Some targets (e.g., i386-aout)
4206 arrange for the contents of the section to be the negative of the
4207 offset of the location within the section; for such targets
4208 pcrel_offset is FALSE. Other targets (e.g., m88kbcs or ELF)
4209 simply leave the contents of the section as zero; for such
4210 targets pcrel_offset is TRUE. If pcrel_offset is FALSE we do not
4211 need to subtract out the offset of the location within the
4212 section (which is just ADDRESS). */
4213 if (howto
->pc_relative
)
4215 relocation
-= (input_section
->output_section
->vma
4216 + input_section
->output_offset
);
4217 if (howto
->pcrel_offset
)
4218 relocation
-= address
;
4221 return csky_relocate_contents (howto
, input_bfd
, relocation
,
4222 contents
+ address
);
4226 /* Return the base VMA address which should be subtracted from real addresses
4227 when resolving @dtpoff relocation.
4228 This is PT_TLS segment p_vaddr. */
4231 dtpoff_base (struct bfd_link_info
*info
)
4233 /* If tls_sec is NULL, we should have signalled an error already. */
4234 if (elf_hash_table (info
)->tls_sec
== NULL
)
4236 return elf_hash_table (info
)->tls_sec
->vma
;
4239 /* Return the relocation value for @tpoff relocation
4240 if STT_TLS virtual address is ADDRESS. */
4243 tpoff (struct bfd_link_info
*info
, bfd_vma address
)
4245 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
4248 /* If tls_sec is NULL, we should have signalled an error already. */
4249 if (htab
->tls_sec
== NULL
)
4251 base
= align_power ((bfd_vma
) TCB_SIZE
, htab
->tls_sec
->alignment_power
);
4252 return address
- htab
->tls_sec
->vma
+ base
;
4255 /* Relocate a csky section. */
4258 csky_elf_relocate_section (bfd
* output_bfd
,
4259 struct bfd_link_info
* info
,
4261 asection
* input_section
,
4262 bfd_byte
* contents
,
4263 Elf_Internal_Rela
* relocs
,
4264 Elf_Internal_Sym
* local_syms
,
4265 asection
** local_sections
)
4267 Elf_Internal_Shdr
*symtab_hdr
;
4268 struct elf_link_hash_entry
**sym_hashes
;
4269 Elf_Internal_Rela
*rel
;
4270 Elf_Internal_Rela
*relend
;
4272 bfd_boolean ret
= TRUE
;
4273 struct csky_elf_link_hash_table
* htab
;
4274 bfd_vma
*local_got_offsets
= elf_local_got_offsets (input_bfd
);
4276 htab
= csky_elf_hash_table (info
);
4280 symtab_hdr
= & elf_symtab_hdr (input_bfd
);
4281 sym_hashes
= elf_sym_hashes (input_bfd
);
4284 relend
= relocs
+ input_section
->reloc_count
;
4285 for (; rel
< relend
; rel
++)
4287 enum elf_csky_reloc_type r_type
4288 = (enum elf_csky_reloc_type
) ELF32_R_TYPE (rel
->r_info
);
4289 unsigned long r_symndx
;
4290 reloc_howto_type
* howto
;
4291 Elf_Internal_Sym
* sym
;
4295 struct elf_link_hash_entry
* h
;
4296 bfd_vma addend
= (bfd_vma
)rel
->r_addend
;
4297 bfd_reloc_status_type r
= bfd_reloc_ok
;
4298 bfd_boolean unresolved_reloc
= FALSE
;
4299 int do_final_relocate
= TRUE
;
4300 bfd_boolean relative_reloc
= FALSE
;
4301 bfd_signed_vma disp
;
4303 /* Ignore these relocation types:
4304 R_CKCORE_GNU_VTINHERIT, R_CKCORE_GNU_VTENTRY. */
4305 if (r_type
== R_CKCORE_GNU_VTINHERIT
|| r_type
== R_CKCORE_GNU_VTENTRY
)
4308 if ((unsigned) r_type
>= (unsigned) R_CKCORE_MAX
)
4310 /* The r_type is error, not support it. */
4311 /* xgettext:c-format */
4312 _bfd_error_handler (_("%pB: unsupported relocation type: %#x"),
4314 bfd_set_error (bfd_error_bad_value
);
4319 howto
= &csky_elf_howto_table
[(int) r_type
];
4321 r_symndx
= ELF32_R_SYM(rel
->r_info
);
4325 unresolved_reloc
= FALSE
;
4327 if (r_symndx
< symtab_hdr
->sh_info
)
4329 /* Get symbol table entry. */
4330 sym
= local_syms
+ r_symndx
;
4331 sec
= local_sections
[r_symndx
];
4332 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
4333 addend
= (bfd_vma
)rel
->r_addend
;
4337 bfd_boolean warned
, ignored
;
4339 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
4340 r_symndx
, symtab_hdr
, sym_hashes
,
4342 unresolved_reloc
, warned
, ignored
);
4345 if (sec
!= NULL
&& discarded_section (sec
))
4347 /* For relocs against symbols from removed linkonce sections,
4348 or sections discarded by a linker script, we just want the
4349 section contents zeroed. Avoid any special processing.
4350 And if the symbol is referenced in '.csky_stack_size' section,
4351 set the address to SEC_DISCARDED(0xffffffff). */
4353 /* The .csky_stack_size section is just for callgraph. */
4354 if (strcmp (input_section
->name
, ".csky_stack_size") == 0)
4356 /* FIXME: it should define in head file. */
4357 #define SEC_DISCARDED 0xffffffff
4358 bfd_put_32 (input_bfd
, SEC_DISCARDED
, contents
+ rel
->r_offset
);
4365 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
4366 rel
, 1, relend
, howto
, 0,
4370 if (bfd_link_relocatable (info
))
4373 read_content_substitute
= 0;
4377 + (bfd_signed_vma
) addend
4378 - input_section
->output_section
->vma
4379 - input_section
->output_offset
4381 /* It is for ck8xx. */
4382 #define CSKY_INSN_BSR32 0xe0000000
4383 /* It is for ck5xx/ck6xx. */
4384 #define CSKY_INSN_BSR16 0xf800
4385 #define within_range(x, L) (-(1 << (L - 1)) < (x) && (x) < (1 << (L -1)) - 2)
4386 switch (howto
->type
)
4388 case R_CKCORE_PCREL_IMM18BY2
:
4389 /* When h is NULL, means the instruction written as
4391 if the highest bit is set, prevent the high 32bits
4392 turn to 0xffffffff when signed extern in 64bit
4394 if (h
== NULL
&& (addend
& 0x80000000))
4395 addend
&= 0xffffffff;
4398 case R_CKCORE_PCREL32
:
4401 case R_CKCORE_GOT12
:
4402 case R_CKCORE_PLT12
:
4403 case R_CKCORE_GOT_HI16
:
4404 case R_CKCORE_GOT_LO16
:
4405 case R_CKCORE_PLT_HI16
:
4406 case R_CKCORE_PLT_LO16
:
4407 case R_CKCORE_GOT32
:
4408 case R_CKCORE_GOT_IMM18BY4
:
4409 /* Relocation is to the entry for this symbol in the global
4411 BFD_ASSERT (htab
->elf
.sgot
!= NULL
);
4414 /* Global symbol is defined by other modules. */
4416 off
= h
->got
.offset
;
4417 dyn
= htab
->elf
.dynamic_sections_created
;
4418 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
4419 bfd_link_pic (info
), h
)
4420 || (bfd_link_pic (info
) && SYMBOL_REFERENCES_LOCAL (info
,h
))
4421 || (ELF_ST_VISIBILITY(h
->other
)
4422 && h
->root
.type
== bfd_link_hash_undefweak
))
4424 /* This is actually a static link, or it is a
4425 -Bsymbolic link and the symbol is defined
4426 locally, or the symbol was forced to be local
4427 because of a version file. We must initialize
4428 this entry in the global offset table. Since the
4429 offset must always be a multiple of 4, we use the
4430 least significant bit to record whether we have
4431 initialized it already.
4432 When doing a dynamic link, we create a .rela.dyn
4433 relocation entry to initialize the value. This
4434 is done in the finish_dynamic_symbol routine. FIXME */
4439 bfd_put_32 (output_bfd
, relocation
,
4440 htab
->elf
.sgot
->contents
+ off
);
4443 /* TRUE if relative relocation should be generated. GOT reference to
4444 global symbol in PIC will lead to dynamic symbol. It becomes a
4445 problem when "time" or "times" is defined as a variable in an
4446 executable, clashing with functions of the same name in libc. If a
4447 symbol isn't undefined weak symbol, don't make it dynamic in PIC and
4448 generate relative relocation. */
4449 #define GENERATE_RELATIVE_RELOC_P(INFO, H) \
4450 ((H)->dynindx == -1 \
4451 && !(H)->forced_local \
4452 && (H)->root.type != bfd_link_hash_undefweak \
4453 && bfd_link_pic (INFO))
4455 if (GENERATE_RELATIVE_RELOC_P (info
, h
))
4456 /* If this symbol isn't dynamic
4457 in PIC, generate R_CKCORE_RELATIVE here. */
4458 relative_reloc
= TRUE
;
4462 unresolved_reloc
= FALSE
;
4463 } /* End if h != NULL. */
4466 BFD_ASSERT (local_got_offsets
!= NULL
);
4467 off
= local_got_offsets
[r_symndx
];
4469 /* The offset must always be a multiple of 4. We use
4470 the least significant bit to record whether we have
4471 already generated the necessary reloc. */
4476 bfd_put_32 (output_bfd
, relocation
,
4477 htab
->elf
.sgot
->contents
+ off
);
4478 local_got_offsets
[r_symndx
] |= 1;
4479 if (bfd_link_pic (info
))
4480 relative_reloc
= TRUE
;
4486 Elf_Internal_Rela outrel
;
4489 srelgot
= htab
->elf
.srelgot
;
4490 BFD_ASSERT (srelgot
!= NULL
);
4493 = (htab
->elf
.sgot
->output_section
->vma
4494 + htab
->elf
.sgot
->output_offset
+ off
);
4495 outrel
.r_info
= ELF32_R_INFO (0, R_CKCORE_RELATIVE
);
4496 outrel
.r_addend
= relocation
;
4497 loc
= srelgot
->contents
;
4498 loc
+= (srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
));
4500 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4502 relocation
= htab
->elf
.sgot
->output_offset
+ off
;
4505 case R_CKCORE_GOTOFF_IMM18
:
4506 case R_CKCORE_GOTOFF
:
4507 case R_CKCORE_GOTOFF_HI16
:
4508 case R_CKCORE_GOTOFF_LO16
:
4509 /* Relocation is relative to the start of the global offset
4511 /* Note that sgot->output_offset is not involved in this
4512 calculation. We always want the start of .got. If we
4513 defined _GLOBAL_OFFSET_TABLE in a different way, as is
4514 permitted by the ABI, we might have to change this
4516 relocation
-= htab
->elf
.sgot
->output_section
->vma
;
4519 case R_CKCORE_GOTPC
:
4520 case R_CKCORE_GOTPC_HI16
:
4521 case R_CKCORE_GOTPC_LO16
:
4522 /* Use global offset table as symbol value. */
4523 relocation
= htab
->elf
.sgot
->output_section
->vma
;
4525 unresolved_reloc
= FALSE
;
4528 case R_CKCORE_DOFFSET_IMM18
:
4529 case R_CKCORE_DOFFSET_IMM18BY2
:
4530 case R_CKCORE_DOFFSET_IMM18BY4
:
4532 asection
*sdata
= bfd_get_section_by_name (output_bfd
, ".data");
4533 relocation
-= sdata
->output_section
->vma
;
4537 case R_CKCORE_DOFFSET_LO16
:
4539 asection
*sdata
= bfd_get_section_by_name (output_bfd
, ".data");
4540 relocation
-= sdata
->output_section
->vma
;
4544 case R_CKCORE_TOFFSET_LO16
:
4546 asection
*stext
= bfd_get_section_by_name (output_bfd
, ".text");
4548 relocation
-= stext
->output_section
->vma
;
4552 case R_CKCORE_PLT_IMM18BY4
:
4553 case R_CKCORE_PLT32
:
4554 /* Relocation is to the entry for this symbol in the
4555 procedure linkage table. */
4557 /* Resolve a PLT32 reloc against a local symbol directly,
4558 without using the procedure linkage table. */
4562 if (h
->plt
.offset
== (bfd_vma
) -1 || htab
->elf
.splt
== NULL
)
4564 /* We didn't make a PLT entry for this symbol. This
4565 happens when statically linking PIC code, or when
4566 using -Bsymbolic. */
4567 if (h
->got
.offset
!= (bfd_vma
) -1)
4571 off
= h
->got
.offset
;
4572 dyn
= htab
->elf
.dynamic_sections_created
;
4573 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
4574 bfd_link_pic (info
), h
)
4575 || (bfd_link_pic (info
)
4576 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4577 || (ELF_ST_VISIBILITY (h
->other
)
4578 && h
->root
.type
== bfd_link_hash_undefweak
))
4580 /* This is actually a static link, or it is a
4581 -Bsymbolic link and the symbol is defined
4582 locally, or the symbol was forced to be local
4583 because of a version file. We must initialize
4584 this entry in the global offset table. Since the
4585 offset must always be a multiple of 4, we use the
4586 least significant bit to record whether we have
4587 initialized it already.
4589 When doing a dynamic link, we create a .rela.dyn
4590 relocation entry to initialize the value. This
4591 is done in the finish_dynamic_symbol routine.
4598 if (GENERATE_RELATIVE_RELOC_P (info
, h
))
4599 relative_reloc
= TRUE
;
4602 bfd_put_32 (output_bfd
, relocation
,
4603 htab
->elf
.sgot
->contents
+ off
);
4608 Elf_Internal_Rela outrel
;
4611 srelgot
= htab
->elf
.srelgot
;
4612 BFD_ASSERT (srelgot
!= NULL
);
4615 = (htab
->elf
.sgot
->output_section
->vma
4616 + htab
->elf
.sgot
->output_offset
+ off
);
4617 outrel
.r_info
= ELF32_R_INFO (0, R_CKCORE_RELATIVE
);
4618 outrel
.r_addend
= relocation
;
4619 loc
= srelgot
->contents
;
4620 loc
+= (srelgot
->reloc_count
++
4621 * sizeof (Elf32_External_Rela
));
4623 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4625 relocation
= off
+ htab
->elf
.sgot
->output_offset
;
4629 /* The relocation is the got offset. */
4630 if (bfd_csky_abi (output_bfd
) == CSKY_ABI_V2
)
4631 relocation
= (h
->plt
.offset
/ PLT_ENTRY_SIZE
+ 2) * 4;
4633 relocation
= (h
->plt
.offset
/ PLT_ENTRY_SIZE_P
+ 2) * 4;
4634 unresolved_reloc
= FALSE
;
4637 case R_CKCORE_PCREL_IMM26BY2
:
4638 case R_CKCORE_PCREL_JSR_IMM26BY2
:
4639 case R_CKCORE_PCREL_JSR_IMM11BY2
:
4640 case R_CKCORE_PCREL_IMM11BY2
:
4641 case R_CKCORE_CALLGRAPH
:
4642 /* Emit callgraph information first. */
4643 /* TODO: deal with callgraph. */
4644 if (ELF32_R_TYPE (rel
->r_info
) == R_CKCORE_CALLGRAPH
)
4646 /* Some reloc need further handling. */
4647 /* h == NULL means the symbol is a local symbol,
4648 r_symndx == 0 means the symbol is 'ABS' and
4649 the relocation is already handled in assemble,
4650 here just use for callgraph. */
4651 /* TODO: deal with callgraph. */
4652 if (h
== NULL
&& r_symndx
== 0)
4654 do_final_relocate
= FALSE
;
4658 /* Ignore weak references to undefined symbols. */
4659 if (h
!= NULL
&& h
->root
.type
== bfd_link_hash_undefweak
)
4661 do_final_relocate
= FALSE
;
4665 /* Using branch stub. */
4666 if (use_branch_stub
== TRUE
4667 && ELF32_R_TYPE (rel
->r_info
) == R_CKCORE_PCREL_IMM26BY2
)
4669 struct elf32_csky_stub_hash_entry
*stub_entry
= NULL
;
4670 if (sym_must_create_stub (h
, info
))
4671 stub_entry
= elf32_csky_get_stub_entry (input_section
,
4674 else if (disp
> BSR_MAX_FWD_BRANCH_OFFSET
4675 || disp
< BSR_MAX_BWD_BRANCH_OFFSET
)
4676 stub_entry
= elf32_csky_get_stub_entry (input_section
,
4679 if (stub_entry
!= NULL
)
4681 = (stub_entry
->stub_offset
4682 + stub_entry
->stub_sec
->output_offset
4683 + stub_entry
->stub_sec
->output_section
->vma
);
4688 || (h
->root
.type
== bfd_link_hash_defined
4689 && h
->dynindx
== -1)
4690 || ((h
->def_regular
&& !h
->def_dynamic
)
4691 && (h
->root
.type
!= bfd_link_hash_defweak
4692 || ! bfd_link_pic (info
))))
4694 if (ELF32_R_TYPE (rel
->r_info
) == R_CKCORE_PCREL_JSR_IMM26BY2
)
4696 if (within_range (disp
, 26))
4698 /* In range for BSR32. */
4699 howto
= &csky_elf_howto_table
[R_CKCORE_PCREL_IMM26BY2
];
4700 read_content_substitute
= CSKY_INSN_BSR32
;
4702 else if (bfd_csky_arch (output_bfd
) == CSKY_ARCH_810
)
4703 /* if bsr32 cannot reach, generate
4704 "lrw r25, label; jsr r25" instead of
4706 howto
= &csky_elf_howto_table
[R_CKCORE_NOJSRI
];
4707 } /* if ELF32_R_TYPE (rel->r_info)... */
4708 else if (ELF32_R_TYPE (rel
->r_info
)
4709 == R_CKCORE_PCREL_JSR_IMM11BY2
)
4711 if (within_range (disp
, 11))
4713 /* In range for BSR16. */
4714 howto
= &csky_elf_howto_table
[R_CKCORE_PCREL_IMM11BY2
];
4715 read_content_substitute
= CSKY_INSN_BSR16
;
4719 } /* else if h == NULL... */
4721 else if (bfd_csky_arch (output_bfd
) == CSKY_ARCH_810
4722 && (ELF32_R_TYPE (rel
->r_info
)
4723 == R_CKCORE_PCREL_JSR_IMM26BY2
))
4725 howto
= &csky_elf_howto_table
[R_CKCORE_NOJSRI
];
4728 /* Other situation, h->def_dynamic == 1,
4729 undefined_symbol when output file is shared object, etc. */
4730 /* Else fall through. */
4732 case R_CKCORE_ADDR_HI16
:
4733 case R_CKCORE_ADDR_LO16
:
4734 if (bfd_link_pic (info
)
4735 || (!bfd_link_pic (info
)
4739 && ((h
->def_dynamic
&& !h
->def_regular
)
4740 || (htab
->elf
.dynamic_sections_created
4741 && (h
->root
.type
== bfd_link_hash_undefweak
4742 || h
->root
.type
== bfd_link_hash_undefined
4743 || h
->root
.type
== bfd_link_hash_indirect
)))))
4745 Elf_Internal_Rela outrel
;
4746 bfd_boolean skip
, relocate
;
4749 /* When generating a shared object, these relocations
4750 are copied into the output file to be resolved at
4756 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4758 if (outrel
.r_offset
== (bfd_vma
) -1)
4760 else if (outrel
.r_offset
== (bfd_vma
) -2)
4765 outrel
.r_offset
+= (input_section
->output_section
->vma
4766 + input_section
->output_offset
);
4768 memset (&outrel
, 0, sizeof (outrel
));
4771 && (!bfd_link_pic (info
)
4772 || (!SYMBOLIC_BIND (info
, h
)
4773 && h
->root
.type
== bfd_link_hash_defweak
)
4774 || !h
->def_regular
))
4776 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
4777 outrel
.r_addend
= rel
->r_addend
;
4781 /* This symbol is local, or marked to become local. */
4783 outrel
.r_info
= ELF32_R_INFO (0, r_type
);
4784 outrel
.r_addend
= relocation
+ rel
->r_addend
;
4786 loc
= htab
->elf
.srelgot
->contents
;
4787 loc
+= (htab
->elf
.srelgot
->reloc_count
++
4788 * sizeof (Elf32_External_Rela
));
4791 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4793 /* If this reloc is against an external symbol, we do not
4794 want to diddle with the addend. Otherwise, we need to
4795 include the symbol value so that it becomes an addend
4796 for the dynamic reloc. */
4799 } /* if bfd_link_pic (info) ... */
4802 case R_CKCORE_ADDR32
:
4803 /* r_symndx will be zero only for relocs against symbols
4804 from removed linkonce sections, or sections discarded
4806 This relocation don't nedd to handle, the value will
4807 be set to SEC_DISCARDED(0xffffffff). */
4809 && strcmp (sec
->name
, ".csky_stack_size") == 0)
4811 do_final_relocate
= FALSE
;
4814 if (r_symndx
>= symtab_hdr
->sh_info
4816 && bfd_link_executable (info
))
4819 if (r_symndx
== 0 || (input_section
->flags
& SEC_ALLOC
) == 0)
4822 if (bfd_link_pic (info
)
4825 && ((h
->def_dynamic
&& !h
->def_regular
)
4826 || (htab
->elf
.dynamic_sections_created
4827 && (h
->root
.type
== bfd_link_hash_undefweak
4828 || h
->root
.type
== bfd_link_hash_undefined
4829 || h
->root
.type
== bfd_link_hash_indirect
)))))
4831 Elf_Internal_Rela outrel
;
4832 bfd_boolean skip
, relocate
;
4835 /* When generating a shared object, these relocations
4836 are copied into the output file to be resolved at
4842 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4845 if (outrel
.r_offset
== (bfd_vma
) -1)
4847 else if (outrel
.r_offset
== (bfd_vma
) -2)
4853 outrel
.r_offset
+= (input_section
->output_section
->vma
4854 + input_section
->output_offset
);
4857 memset (&outrel
, 0, sizeof (outrel
));
4860 && (!bfd_link_pic (info
)
4861 || (!SYMBOLIC_BIND (info
, h
)
4862 && h
->root
.type
== bfd_link_hash_defweak
)
4863 || !h
->def_regular
))
4865 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
4866 outrel
.r_addend
= rel
->r_addend
;
4870 /* This symbol is local, or marked to become local. */
4871 outrel
.r_info
= ELF32_R_INFO (0, R_CKCORE_RELATIVE
);
4872 outrel
.r_addend
= relocation
+ rel
->r_addend
;
4875 loc
= htab
->elf
.srelgot
->contents
;
4876 loc
+= (htab
->elf
.srelgot
->reloc_count
++
4877 * sizeof (Elf32_External_Rela
));
4880 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4882 /* If this reloc is against an external symbol, we do
4883 want to diddle with the addend. Otherwise, we need to
4884 include the symbol value so that it becomes an addend
4885 for the dynamic reloc. */
4891 case R_CKCORE_TLS_LDO32
:
4892 relocation
= relocation
- dtpoff_base (info
);
4895 case R_CKCORE_TLS_LDM32
:
4896 BFD_ASSERT (htab
->elf
.sgot
!= NULL
);
4897 off
= htab
->tls_ldm_got
.offset
;
4902 /* If we don't know the module number,
4903 create a relocation for it. */
4904 if (!bfd_link_executable (info
))
4906 Elf_Internal_Rela outrel
;
4909 BFD_ASSERT (htab
->elf
.srelgot
!= NULL
);
4910 outrel
.r_addend
= 0;
4912 = (htab
->elf
.sgot
->output_section
->vma
4913 + htab
->elf
.sgot
->output_offset
+ off
);
4914 outrel
.r_info
= ELF32_R_INFO (0, R_CKCORE_TLS_DTPMOD32
);
4915 bfd_put_32 (output_bfd
, outrel
.r_addend
,
4916 htab
->elf
.sgot
->contents
+ off
);
4918 loc
= htab
->elf
.srelgot
->contents
;
4919 loc
+= (htab
->elf
.srelgot
->reloc_count
++
4920 * sizeof (Elf32_External_Rela
));
4922 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4925 bfd_put_32 (output_bfd
, 1,
4926 htab
->elf
.sgot
->contents
+ off
);
4927 htab
->tls_ldm_got
.offset
|= 1;
4930 = (htab
->elf
.sgot
->output_section
->vma
4931 + htab
->elf
.sgot
->output_offset
+ off
4932 - (input_section
->output_section
->vma
4933 + input_section
->output_offset
+ rel
->r_offset
));
4935 case R_CKCORE_TLS_LE32
:
4936 if (bfd_link_dll (info
))
4939 /* xgettext:c-format */
4940 (_("%pB(%pA+%#" PRIx64
"): %s relocation not permitted "
4941 "in shared object"),
4942 input_bfd
, input_section
, (uint64_t)rel
->r_offset
,
4947 relocation
= tpoff (info
, relocation
);
4949 case R_CKCORE_TLS_GD32
:
4950 case R_CKCORE_TLS_IE32
:
4955 BFD_ASSERT (htab
->elf
.sgot
!= NULL
);
4961 dyn
= htab
->elf
.dynamic_sections_created
;
4962 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
4963 bfd_link_pic (info
), h
)
4964 && (!bfd_link_pic (info
)
4965 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
4967 unresolved_reloc
= FALSE
;
4970 off
= h
->got
.offset
;
4971 tls_type
= ((struct csky_elf_link_hash_entry
*)h
)->tls_type
;
4975 BFD_ASSERT (local_got_offsets
!= NULL
);
4976 off
= local_got_offsets
[r_symndx
];
4977 tls_type
= csky_elf_local_got_tls_type (input_bfd
)[r_symndx
];
4980 BFD_ASSERT (tls_type
!= GOT_UNKNOWN
);
4986 bfd_boolean need_relocs
= FALSE
;
4987 Elf_Internal_Rela outrel
;
4988 bfd_byte
*loc
= NULL
;
4990 /* The GOT entries have not been initialized yet. Do it
4991 now, and emit any relocations. If both an IE GOT and a
4992 GD GOT are necessary, we emit the GD first. */
4993 if ((!bfd_link_executable (info
) || indx
!= 0)
4995 || (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4996 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
4997 || h
->root
.type
!= bfd_link_hash_undefined
))
5000 BFD_ASSERT (htab
->elf
.srelgot
!= NULL
);
5002 loc
= htab
->elf
.srelgot
->contents
;
5003 loc
+= (htab
->elf
.srelgot
->reloc_count
5004 * sizeof (Elf32_External_Rela
));
5006 if (tls_type
& GOT_TLS_GD
)
5010 outrel
.r_addend
= 0;
5012 = (htab
->elf
.sgot
->output_section
->vma
5013 + htab
->elf
.sgot
->output_offset
5016 = ELF32_R_INFO (indx
, R_CKCORE_TLS_DTPMOD32
);
5017 bfd_put_32 (output_bfd
, outrel
.r_addend
,
5018 htab
->elf
.sgot
->contents
+ cur_off
);
5020 bfd_elf32_swap_reloca_out (output_bfd
,
5022 loc
+= sizeof (Elf32_External_Rela
);
5023 htab
->elf
.srelgot
->reloc_count
++;
5025 bfd_put_32 (output_bfd
,
5026 relocation
- dtpoff_base (info
),
5027 (htab
->elf
.sgot
->contents
5031 outrel
.r_addend
= 0;
5033 = ELF32_R_INFO (indx
, R_CKCORE_TLS_DTPOFF32
);
5034 outrel
.r_offset
+= 4;
5035 bfd_put_32 (output_bfd
, outrel
.r_addend
,
5036 (htab
->elf
.sgot
->contents
5040 R_CKCORE_TLS_DTPOFF32
);
5042 bfd_elf32_swap_reloca_out (output_bfd
,
5045 htab
->elf
.srelgot
->reloc_count
++;
5046 loc
+= sizeof (Elf32_External_Rela
);
5052 /* If are not emitting relocations for a
5053 general dynamic reference, then we must be in a
5054 static link or an executable link with the
5055 symbol binding locally. Mark it as belonging
5056 to module 1, the executable. */
5057 bfd_put_32 (output_bfd
, 1,
5058 htab
->elf
.sgot
->contents
+ cur_off
);
5059 bfd_put_32 (output_bfd
,
5060 relocation
- dtpoff_base (info
),
5061 htab
->elf
.sgot
->contents
5066 if (tls_type
& GOT_TLS_IE
)
5071 outrel
.r_addend
= relocation
- dtpoff_base (info
);
5073 outrel
.r_addend
= 0;
5075 = (htab
->elf
.sgot
->output_section
->vma
5076 + htab
->elf
.sgot
->output_offset
+ cur_off
);
5078 = ELF32_R_INFO (indx
, R_CKCORE_TLS_TPOFF32
);
5080 bfd_put_32 (output_bfd
, outrel
.r_addend
,
5081 htab
->elf
.sgot
->contents
+ cur_off
);
5083 bfd_elf32_swap_reloca_out (output_bfd
,
5085 htab
->elf
.srelgot
->reloc_count
++;
5086 loc
+= sizeof (Elf32_External_Rela
);
5089 bfd_put_32 (output_bfd
, tpoff (info
, relocation
),
5090 htab
->elf
.sgot
->contents
+ cur_off
);
5095 local_got_offsets
[r_symndx
] |= 1;
5097 if ((tls_type
& GOT_TLS_GD
) && howto
->type
!= R_CKCORE_TLS_GD32
)
5100 = (htab
->elf
.sgot
->output_section
->vma
5101 + htab
->elf
.sgot
->output_offset
+ off
5102 - (input_section
->output_section
->vma
5103 + input_section
->output_offset
5108 /* No substitution when final linking. */
5109 read_content_substitute
= 0;
5111 } /* End switch (howto->type). */
5113 /* Make sure 32-bit data in the text section will not be affected by
5114 our special endianness.
5115 However, this currently affects noting, since the ADDR32 howto type
5116 does no change with the data read. But we may need this mechanism in
5119 if (howto
->size
== 2
5120 && (howto
->type
== R_CKCORE_ADDR32
5121 || howto
->type
== R_CKCORE_PCREL32
5122 || howto
->type
== R_CKCORE_GOT32
5123 || howto
->type
== R_CKCORE_GOTOFF
5124 || howto
->type
== R_CKCORE_GOTPC
5125 || howto
->type
== R_CKCORE_PLT32
5126 || howto
->type
== R_CKCORE_TLS_LE32
5127 || howto
->type
== R_CKCORE_TLS_IE32
5128 || howto
->type
== R_CKCORE_TLS_LDM32
5129 || howto
->type
== R_CKCORE_TLS_GD32
5130 || howto
->type
== R_CKCORE_TLS_LDO32
5131 || howto
->type
== R_CKCORE_RELATIVE
))
5132 need_reverse_bits
= 0;
5134 need_reverse_bits
= 1;
5135 /* Do the final link. */
5136 if (howto
->type
!= R_CKCORE_PCREL_JSR_IMM11BY2
5137 && howto
->type
!= R_CKCORE_PCREL_JSR_IMM26BY2
5138 && howto
->type
!= R_CKCORE_CALLGRAPH
5139 && do_final_relocate
)
5140 r
= csky_final_link_relocate (howto
, input_bfd
, input_section
,
5141 contents
, rel
->r_offset
,
5142 relocation
, addend
);
5144 if (r
!= bfd_reloc_ok
)
5151 case bfd_reloc_overflow
:
5156 name
= bfd_elf_string_from_elf_section (input_bfd
,
5157 symtab_hdr
->sh_link
,
5162 name
= bfd_section_name (sec
);
5164 (*info
->callbacks
->reloc_overflow
)
5166 (h
? &h
->root
: NULL
),
5167 name
, howto
->name
, (bfd_vma
) 0,
5168 input_bfd
, input_section
, rel
->r_offset
);
5172 } /* End for (;rel < relend; rel++). */
5177 csky_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
5182 switch (note
->descsz
)
5186 /* Sizeof (struct elf_prstatus) on C-SKY V1 arch. */
5188 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
5189 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
5193 /* Sizeof (struct elf_prstatus) on C-SKY V1 arch. */
5195 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
5196 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
5201 /* Make a ".reg/999" section. */
5202 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
5203 size
, note
->descpos
+ offset
);
5207 csky_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
5209 switch (note
->descsz
)
5214 /* Sizeof (struct elf_prpsinfo) on linux csky. */
5216 elf_tdata (abfd
)->core
->program
5217 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
5218 elf_tdata (abfd
)->core
->command
5219 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
5222 /* Note that for some reason, a spurious space is tacked
5223 onto the end of the args in some (at least one anyway)
5224 implementations, so strip it off if it exists. */
5226 char *command
= elf_tdata (abfd
)->core
->command
;
5227 int n
= strlen (command
);
5229 if (0 < n
&& command
[n
- 1] == ' ')
5230 command
[n
- 1] = '\0';
5236 /* Determine whether an object attribute tag takes an integer, a
5240 elf32_csky_obj_attrs_arg_type (int tag
)
5244 case Tag_compatibility
:
5245 return ATTR_TYPE_FLAG_INT_VAL
| ATTR_TYPE_FLAG_STR_VAL
;
5246 case Tag_CSKY_ARCH_NAME
:
5247 case Tag_CSKY_CPU_NAME
:
5248 case Tag_CSKY_FPU_NUMBER_MODULE
:
5249 return ATTR_TYPE_FLAG_STR_VAL
;
5250 case Tag_CSKY_ISA_FLAGS
:
5251 case Tag_CSKY_ISA_EXT_FLAGS
:
5252 case Tag_CSKY_DSP_VERSION
:
5253 case Tag_CSKY_VDSP_VERSION
:
5254 case Tag_CSKY_FPU_VERSION
:
5255 case Tag_CSKY_FPU_ABI
:
5256 case Tag_CSKY_FPU_ROUNDING
:
5257 case Tag_CSKY_FPU_HARDFP
:
5258 case Tag_CSKY_FPU_Exception
:
5259 case Tag_CSKY_FPU_DENORMAL
:
5260 return ATTR_TYPE_FLAG_INT_VAL
;
5265 return (tag
& 1) != 0 ? ATTR_TYPE_FLAG_STR_VAL
: ATTR_TYPE_FLAG_INT_VAL
;
5268 /* Attribute numbers >=64 (mod 128) can be safely ignored. */
5271 elf32_csky_obj_attrs_handle_unknown (bfd
*abfd ATTRIBUTE_UNUSED
,
5272 int tag ATTRIBUTE_UNUSED
)
5277 /* End of external entry points for sizing and building linker stubs. */
5279 /* CPU-related basic API. */
5280 #define TARGET_BIG_SYM csky_elf32_be_vec
5281 #define TARGET_BIG_NAME "elf32-csky-big"
5282 #define TARGET_LITTLE_SYM csky_elf32_le_vec
5283 #define TARGET_LITTLE_NAME "elf32-csky-little"
5284 #define ELF_ARCH bfd_arch_csky
5285 #define ELF_MACHINE_CODE EM_CSKY
5286 #define ELF_MACHINE_ALT1 EM_CSKY_OLD
5287 #define ELF_MAXPAGESIZE 0x1000
5288 #define elf_info_to_howto csky_elf_info_to_howto
5289 #define elf_info_to_howto_rel NULL
5290 #define elf_backend_special_sections csky_elf_special_sections
5291 #define bfd_elf32_bfd_link_hash_table_create csky_elf_link_hash_table_create
5293 /* Target related API. */
5294 #define bfd_elf32_mkobject csky_elf_mkobject
5295 #define bfd_elf32_bfd_merge_private_bfd_data csky_elf_merge_private_bfd_data
5296 #define bfd_elf32_bfd_set_private_flags csky_elf_set_private_flags
5297 #define elf_backend_copy_indirect_symbol csky_elf_copy_indirect_symbol
5299 /* GC section related API. */
5300 #define elf_backend_can_gc_sections 1
5301 #define elf_backend_gc_mark_hook csky_elf_gc_mark_hook
5302 #define elf_backend_gc_mark_extra_sections elf32_csky_gc_mark_extra_sections
5304 /* Relocation related API. */
5305 #define elf_backend_reloc_type_class csky_elf_reloc_type_class
5306 #define bfd_elf32_bfd_reloc_type_lookup csky_elf_reloc_type_lookup
5307 #define bfd_elf32_bfd_reloc_name_lookup csky_elf_reloc_name_lookup
5308 #define elf_backend_ignore_discarded_relocs csky_elf_ignore_discarded_relocs
5309 #define elf_backend_relocate_section csky_elf_relocate_section
5310 #define elf_backend_check_relocs csky_elf_check_relocs
5312 /* Dynamic relocate related API. */
5313 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
5314 #define elf_backend_adjust_dynamic_symbol csky_elf_adjust_dynamic_symbol
5315 #define elf_backend_size_dynamic_sections csky_elf_size_dynamic_sections
5316 #define elf_backend_finish_dynamic_symbol csky_elf_finish_dynamic_symbol
5317 #define elf_backend_finish_dynamic_sections csky_elf_finish_dynamic_sections
5318 #define elf_backend_rela_normal 1
5319 #define elf_backend_can_refcount 1
5320 #define elf_backend_plt_readonly 1
5321 #define elf_backend_want_got_sym 1
5322 #define elf_backend_want_dynrelro 1
5323 #define elf_backend_got_header_size 12
5324 #define elf_backend_want_got_plt 1
5326 /* C-SKY coredump support. */
5327 #define elf_backend_grok_prstatus csky_elf_grok_prstatus
5328 #define elf_backend_grok_psinfo csky_elf_grok_psinfo
5330 /* Attribute sections. */
5331 #undef elf_backend_obj_attrs_vendor
5332 #define elf_backend_obj_attrs_vendor "csky"
5333 #undef elf_backend_obj_attrs_section
5334 #define elf_backend_obj_attrs_section ".csky.attributes"
5335 #undef elf_backend_obj_attrs_arg_type
5336 #define elf_backend_obj_attrs_arg_type elf32_csky_obj_attrs_arg_type
5337 #undef elf_backend_obj_attrs_section_type
5338 #define elf_backend_obj_attrs_section_type SHT_CSKY_ATTRIBUTES
5339 #define elf_backend_obj_attrs_handle_unknown elf32_csky_obj_attrs_handle_unknown
5341 #include "elf32-target.h"