1 /* 32-bit ELF support for C-SKY.
2 Copyright (C) 1998-2020 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 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 struct csky_arch_for_merge csky_archs
[] =
58 /* 510 and 610 merge to 610 without warning. */
59 { "510", CSKY_ARCH_510
, CSKY_V1
, 0, 0},
60 { "610", CSKY_ARCH_610
, CSKY_V1
, 1, 0},
61 /* 801, 802, 803, 807, 810 merge to largest one. */
62 { "801", CSKY_ARCH_801
, CSKY_V2
, 0, 1},
63 { "802", CSKY_ARCH_802
, CSKY_V2
, 1, 1},
64 { "803", CSKY_ARCH_803
, CSKY_V2
, 2, 1},
65 { "807", CSKY_ARCH_807
, CSKY_V2
, 3, 1},
66 { "810", CSKY_ARCH_810
, CSKY_V2
, 4, 1},
70 /* Return the ARCH bits out of ABFD. */
71 #define bfd_csky_arch(abfd) \
72 (elf_elfheader (abfd)->e_flags & CSKY_ARCH_MASK)
74 /* Return the ABI bits out of ABFD. */
75 #define bfd_csky_abi(abfd) \
76 (elf_elfheader (abfd)->e_flags & CSKY_ABI_MASK)
79 /* The index of a howto-item is implicitly equal to
80 the corresponding Relocation Type Encoding. */
81 static reloc_howto_type csky_elf_howto_table
[] =
84 HOWTO (R_CKCORE_NONE
, /* type */
88 FALSE
, /* pc_relative */
90 complain_overflow_dont
, /* complain_on_overflow */
91 NULL
, /* special_function */
92 "R_CKCORE_NONE", /* name */
93 FALSE
, /* partial_inplace */
96 FALSE
), /* pcrel_offset */
99 HOWTO (R_CKCORE_ADDR32
, /* type */
103 FALSE
, /* pc_relative */
105 complain_overflow_dont
, /* complain_on_overflow */
106 bfd_elf_generic_reloc
, /* special_function */
107 "R_CKCORE_ADDR32", /* name */
108 FALSE
, /* partial_inplace */
110 0xffffffff, /* dst_mask */
111 FALSE
), /* pcrel_offset */
113 /* 2: Only for csky v1. */
114 HOWTO (R_CKCORE_PCREL_IMM8BY4
, /* type */
118 TRUE
, /* pc_relative */
120 complain_overflow_bitfield
, /* complain_on_overflow */
121 NULL
, /* special_function */
122 "R_CKCORE_PCREL_IMM8BY4", /* name */
123 FALSE
, /* partial_inplace */
126 TRUE
), /* pcrel_offset */
128 /* 3: Only for csky v1. */
129 HOWTO (R_CKCORE_PCREL_IMM11BY2
, /* type */
133 TRUE
, /* pc_relative */
135 complain_overflow_signed
, /* complain_on_overflow */
136 bfd_elf_generic_reloc
, /* special_function */
137 "R_CKCORE_PCREL_IMM11BY2", /* name */
138 FALSE
, /* partial_inplace */
139 0x7ff, /* src_mask */
140 0x7ff, /* dst_mask */
141 TRUE
), /* pcrel_offset */
144 HOWTO (R_CKCORE_PCREL_IMM4BY2
,0,0,0,0,0,0,0,"R_CKCORE_PCREL_IMM4BY2",0,0,0,0),
147 HOWTO (R_CKCORE_PCREL32
, /* type */
151 TRUE
, /* pc_relative */
153 complain_overflow_dont
, /* complain_on_overflow */
154 bfd_elf_generic_reloc
, /* special_function */
155 "R_CKCORE_PCREL32", /* name */
156 FALSE
, /* partial_inplace */
158 0xffffffff, /* dst_mask */
159 TRUE
), /* pcrel_offset */
161 /* 6: Only for csky v1. */
162 HOWTO (R_CKCORE_PCREL_JSR_IMM11BY2
, /* type */
166 TRUE
, /* pc_relative */
168 complain_overflow_signed
, /* complain_on_overflow */
169 bfd_elf_generic_reloc
, /* special_function */
170 "R_CKCORE_PCREL_JSR_IMM11BY2", /* name */
171 FALSE
, /* partial_inplace */
172 0x7ff, /* src_mask */
173 0x7ff, /* dst_mask */
174 TRUE
), /* pcrel_offset */
176 /* 7: GNU extension to record C++ vtable member usage. */
177 HOWTO (R_CKCORE_GNU_VTENTRY
, /* type */
181 FALSE
, /* pc_relative */
183 complain_overflow_dont
, /* complain_on_overflow */
184 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
185 "R_CKCORE_GNU_VTENTRY", /* name */
186 FALSE
, /* partial_inplace */
189 FALSE
), /* pcrel_offset */
191 /* 8: GNU extension to record C++ vtable hierarchy. */
192 HOWTO (R_CKCORE_GNU_VTINHERIT
, /* type */
196 FALSE
, /* pc_relative */
198 complain_overflow_dont
, /* complain_on_overflow */
199 NULL
, /* special_function */
200 "R_CKCORE_GNU_VTINHERIT", /* name */
201 FALSE
, /* partial_inplace */
204 FALSE
), /* pcrel_offset */
207 HOWTO (R_CKCORE_RELATIVE
, /* type */
211 FALSE
, /* pc_relative */
213 complain_overflow_signed
, /* complain_on_overflow */
214 bfd_elf_generic_reloc
, /* special_function */
215 "R_CKCORE_RELATIVE", /* name */
216 TRUE
, /* partial_inplace */
218 0xffffffff, /* dst_mask */
219 FALSE
), /* pcrel_offset */
222 /* FIXME: It is a bug that copy relocations are not implemented. */
223 HOWTO (R_CKCORE_COPY
, /* type */
227 FALSE
, /* pc_relative */
229 complain_overflow_bitfield
, /* complain_on_overflow */
230 bfd_elf_generic_reloc
, /* special_function */
231 "R_CKCORE_COPY", /* name */
232 TRUE
, /* partial_inplace */
233 0xffffffff, /* src_mask */
234 0xffffffff, /* dst_mask */
235 FALSE
), /* pcrel_offset */
238 HOWTO (R_CKCORE_GLOB_DAT
,0,0,0,0,0,0,0,"R_CKCORE_GLOB_DAT",0,0,0,0),
241 HOWTO (R_CKCORE_JUMP_SLOT
,0,0,0,0,0,0,0,"R_CKCORE_JUMP_SLOT",0,0,0,0),
244 HOWTO (R_CKCORE_GOTOFF
, /* type */
248 FALSE
, /* pc_relative */
250 complain_overflow_dont
, /* complain_on_overflow */
251 bfd_elf_generic_reloc
, /* special_function */
252 "R_CKCORE_GOTOFF", /* name */
253 TRUE
, /* partial_inplace */
255 0xffffffffl
, /* dst_mask */
256 FALSE
), /* pcrel_offset */
259 HOWTO (R_CKCORE_GOTPC
, /* type */
263 TRUE
, /* pc_relative */
265 complain_overflow_dont
, /* complain_on_overflow */
266 bfd_elf_generic_reloc
, /* special_function */
267 "R_CKCORE_GOTPC", /* name */
268 TRUE
, /* partial_inplace */
270 0xffffffff, /* dst_mask */
271 FALSE
), /* pcrel_offset */
274 HOWTO (R_CKCORE_GOT32
, /* type */
278 FALSE
, /* pc_relative */
280 complain_overflow_dont
, /* complain_on_overflow */
281 bfd_elf_generic_reloc
, /* special_function */
282 "R_CKCORE_GOT32", /* name */
283 TRUE
, /* partial_inplace */
285 0xffffffff, /* dst_mask */
286 TRUE
), /* pcrel_offset */
289 HOWTO (R_CKCORE_PLT32
, /* type */
293 FALSE
, /* pc_relative */
295 complain_overflow_dont
, /* complain_on_overflow */
296 bfd_elf_generic_reloc
, /* special_function */
297 "R_CKCORE_PLT32", /* name */
298 TRUE
, /* partial_inplace */
300 0xffffffff, /* dst_mask */
301 TRUE
), /* pcrel_offset */
304 HOWTO (R_CKCORE_ADDRGOT
,0,0,0,0,0,0,0,"R_CKCORE_ADDRGOT",0,0,0,0),
307 HOWTO (R_CKCORE_ADDRPLT
,0,0,0,0,0,0,0,"R_CKCORE_ADDRPLT",0,0,0,0),
309 /* 19: Only for csky v2. */
310 HOWTO (R_CKCORE_PCREL_IMM26BY2
, /* type */
314 TRUE
, /* pc_relative */
316 complain_overflow_signed
, /* complain_on_overflow */
317 bfd_elf_generic_reloc
, /* special_function */
318 "R_CKCORE_PCREL_IMM26BY2", /* name */
319 FALSE
, /* partial_inplace */
321 0x3ffffff, /* dst_mask */
322 TRUE
), /* pcrel_offset */
324 /* 20: Only for csky v2. */
325 HOWTO (R_CKCORE_PCREL_IMM16BY2
, /* type */
329 TRUE
, /* pc_relative */
331 complain_overflow_signed
, /* complain_on_overflow */
332 NULL
, /* special_function */
333 "R_CKCORE_PCREL_IMM16BY2", /* name */
334 FALSE
, /* partial_inplace */
336 0xffff, /* dst_mask */
337 TRUE
), /* pcrel_offset */
339 /* 21: Only for csky v2. */
340 HOWTO (R_CKCORE_PCREL_IMM16BY4
, /* type */
344 TRUE
, /* pc_relative */
346 complain_overflow_bitfield
, /* complain_on_overflow */
347 NULL
, /* special_function */
348 "R_CKCORE_PCREL_IMM16BY4", /* name */
349 FALSE
, /* partial_inplace */
350 0xffff0000, /* src_mask */
351 0xffff, /* dst_mask */
352 TRUE
), /* pcrel_offset */
354 /* 22: Only for csky v2. */
355 HOWTO (R_CKCORE_PCREL_IMM10BY2
, /* type */
359 TRUE
, /* pc_relative */
361 complain_overflow_signed
, /* complain_on_overflow */
362 bfd_elf_generic_reloc
, /* special_function */
363 "R_CKCORE_PCREL_IMM10BY2", /* name */
364 FALSE
, /* partial_inplace */
366 0x3ff, /* dst_mask */
367 TRUE
), /* pcrel_offset */
369 /* 23: Only for csky v2. */
370 HOWTO (R_CKCORE_PCREL_IMM10BY4
, /* type */
374 TRUE
, /* pc_relative */
376 complain_overflow_bitfield
, /* complain_on_overflow */
377 NULL
, /* special_function */
378 "R_CKCORE_PCREL_IMM10BY4", /* name */
379 FALSE
, /* partial_inplace */
381 0x3ff, /* dst_mask */
382 TRUE
), /* pcrel_offset */
384 /* 24: Only for csky v2. */
385 HOWTO (R_CKCORE_ADDR_HI16
, /* type */
389 FALSE
, /* pc_relative */
391 complain_overflow_dont
, /* complain_on_overflow */
392 bfd_elf_generic_reloc
, /* special_function */
393 "R_CKCORE_ADDR_HI16", /* name */
394 FALSE
, /* partial_inplace */
396 0xffff, /* dst_mask */
397 FALSE
), /* pcrel_offset */
400 HOWTO (R_CKCORE_ADDR_LO16
, /* type */
404 FALSE
, /* pc_relative */
406 complain_overflow_dont
, /* complain_on_overflow */
407 bfd_elf_generic_reloc
, /* special_function */
408 "R_CKCORE_ADDR_LO16", /* name */
409 FALSE
, /* partial_inplace */
411 0xffff, /* dst_mask */
412 FALSE
), /* pcrel_offset */
415 HOWTO (R_CKCORE_GOTPC_HI16
, /* type */
419 TRUE
, /* pc_relative */
421 complain_overflow_dont
, /* complain_on_overflow */
422 bfd_elf_generic_reloc
, /* special_function */
423 "R_CKCORE_GOTPC_HI16", /* name */
424 FALSE
, /* partial_inplace */
426 0xffff, /* dst_mask */
427 FALSE
), /* pcrel_offset */
430 HOWTO (R_CKCORE_GOTPC_LO16
, /* type */
434 TRUE
, /* pc_relative */
436 complain_overflow_dont
, /* complain_on_overflow */
437 bfd_elf_generic_reloc
, /* special_function */
438 "R_CKCORE_GOTPC_LO16", /* name */
439 FALSE
, /* partial_inplace */
441 0xffff, /* dst_mask */
442 FALSE
), /* pcrel_offset */
445 HOWTO (R_CKCORE_GOTOFF_HI16
, /* type */
449 FALSE
, /* pc_relative */
451 complain_overflow_dont
, /* complain_on_overflow */
452 bfd_elf_generic_reloc
, /* special_function */
453 "R_CKCORE_GOTOFF_HI16", /* name */
454 FALSE
, /* partial_inplace */
456 0xffff, /* dst_mask */
457 FALSE
), /* pcrel_offset */
460 HOWTO (R_CKCORE_GOTOFF_LO16
, /* type */
464 FALSE
, /* pc_relative */
466 complain_overflow_dont
, /* complain_on_overflow */
467 bfd_elf_generic_reloc
, /* special_function */
468 "R_CKCORE_GOTOFF_LO16", /* name */
469 FALSE
, /* partial_inplace */
471 0xffff, /* dst_mask */
472 FALSE
), /* pcrel_offset */
475 HOWTO (R_CKCORE_GOT12
, /* type */
479 FALSE
, /* pc_relative */
481 complain_overflow_bitfield
, /* complain_on_overflow */
482 bfd_elf_generic_reloc
, /* special_function */
483 "R_CKCORE_GOT12", /* name */
484 TRUE
, /* partial_inplace */
486 0xfff, /* dst_mask */
487 FALSE
), /* pcrel_offset */
490 HOWTO (R_CKCORE_GOT_HI16
, /* type */
494 FALSE
, /* pc_relative */
496 complain_overflow_dont
, /* complain_on_overflow */
497 bfd_elf_generic_reloc
, /* special_function */
498 "R_CKCORE_GOT_HI16", /* name */
499 TRUE
, /* partial_inplace */
501 0xffff, /* dst_mask */
502 FALSE
), /* pcrel_offset */
505 HOWTO (R_CKCORE_GOT_LO16
, /* type */
509 FALSE
, /* pc_relative */
511 complain_overflow_dont
, /* complain_on_overflow */
512 bfd_elf_generic_reloc
, /* special_function */
513 "R_CKCORE_GOT_LO16", /* name */
514 TRUE
, /* partial_inplace */
516 0xffff, /* dst_mask */
517 FALSE
), /* pcrel_offset */
520 HOWTO (R_CKCORE_PLT12
, /* type */
524 FALSE
, /* pc_relative */
526 complain_overflow_bitfield
, /* complain_on_overflow */
527 bfd_elf_generic_reloc
, /* special_function */
528 "R_CKCORE_PLT12", /* name */
529 TRUE
, /* partial_inplace */
531 0xfff, /* dst_mask */
532 FALSE
), /* pcrel_offset */
535 HOWTO (R_CKCORE_PLT_HI16
, /* type */
539 FALSE
, /* pc_relative */
541 complain_overflow_dont
, /* complain_on_overflow */
542 bfd_elf_generic_reloc
, /* special_function */
543 "R_CKCORE_PLT_HI16", /* name */
544 TRUE
, /* partial_inplace */
546 0xffff, /* dst_mask */
547 FALSE
), /* pcrel_offset */
550 HOWTO (R_CKCORE_PLT_LO16
, /* type */
554 FALSE
, /* pc_relative */
556 complain_overflow_dont
, /* complain_on_overflow */
557 bfd_elf_generic_reloc
, /* special_function */
558 "R_CKCORE_PLT_LO16", /* name */
559 TRUE
, /* partial_inplace */
561 0xffff, /* dst_mask */
562 FALSE
), /* pcrel_offset */
565 HOWTO (R_CKCORE_ADDRGOT_HI16
,0,0,0,0,0,0,0,"R_CKCORE_",0,0,0,0),
568 HOWTO (R_CKCORE_ADDRGOT_LO16
,0,0,0,0,0,0,0,"R_CKCORE_",0,0,0,0),
571 HOWTO (R_CKCORE_ADDRPLT_HI16
,0,0,0,0,0,0,0,"R_CKCORE_",0,0,0,0),
574 HOWTO (R_CKCORE_ADDRPLT_LO16
,0,0,0,0,0,0,0,"R_CKCORE_",0,0,0,0),
577 HOWTO (R_CKCORE_PCREL_JSR_IMM26BY2
, /* type */
581 TRUE
, /* pc_relative */
583 complain_overflow_signed
, /* complain_on_overflow */
584 bfd_elf_generic_reloc
, /* special_function */
585 "R_CKCORE_PCREL_JSR_IMM26BY2", /* name */
586 FALSE
, /* partial_inplace */
588 0x3ffffff, /* dst_mask */
589 TRUE
), /* pcrel_offset */
592 HOWTO (R_CKCORE_TOFFSET_LO16
, /* type */
596 FALSE
, /* pc_relative */
598 complain_overflow_unsigned
, /* complain_on_overflow */
599 NULL
, /* special_function */
600 "R_CKCORE_TOFFSET_LO16", /* name */
601 FALSE
, /* partial_inplace */
603 0xffff, /* dst_mask */
604 FALSE
), /* pcrel_offset */
607 HOWTO (R_CKCORE_DOFFSET_LO16
, /* type */
611 FALSE
, /* pc_relative */
613 complain_overflow_unsigned
, /* complain_on_overflow */
614 NULL
, /* special_function */
615 "R_CKCORE_DOFFSET_LO16", /* name */
616 FALSE
, /* partial_inplace */
618 0xffff, /* dst_mask */
619 FALSE
), /* pcrel_offset */
622 HOWTO (R_CKCORE_PCREL_IMM18BY2
, /* type */
626 TRUE
, /* pc_relative */
628 complain_overflow_signed
, /* complain_on_overflow */
629 NULL
, /* special_function */
630 "R_CKCORE_PCREL_IMM18BY2", /* name */
631 FALSE
, /* partial_inplace */
633 0x3ffff, /* dst_mask */
634 TRUE
), /* pcrel_offset */
637 HOWTO (R_CKCORE_DOFFSET_IMM18
, /* type */
641 FALSE
, /* pc_relative */
643 complain_overflow_unsigned
, /* complain_on_overflow */
644 NULL
, /* special_function */
645 "R_CKCORE_DOFFSET_IMM18", /* name */
646 FALSE
, /* partial_inplace */
648 0x3ffff, /* dst_mask */
649 FALSE
), /* pcrel_offset */
652 HOWTO (R_CKCORE_DOFFSET_IMM18BY2
, /* type */
656 FALSE
, /* pc_relative */
658 complain_overflow_unsigned
, /* complain_on_overflow */
659 NULL
, /* special_function */
660 "R_CKCORE_DOFFSET_IMM18BY2", /* name */
661 FALSE
, /* partial_inplace */
663 0x3ffff, /* dst_mask */
664 FALSE
), /* pcrel_offset */
667 HOWTO (R_CKCORE_DOFFSET_IMM18BY4
, /* type */
671 FALSE
, /* pc_relative */
673 complain_overflow_unsigned
, /* complain_on_overflow */
674 NULL
, /* special_function */
675 "R_CKCORE_DOFFSET_IMM18BY4", /* name */
676 FALSE
, /* partial_inplace */
678 0x3ffff, /* dst_mask */
679 FALSE
), /* pcrel_offset */
682 HOWTO (R_CKCORE_GOTOFF_IMM18
, /* type */
686 FALSE
, /* pc_relative */
688 complain_overflow_bitfield
, /* complain_on_overflow */
689 bfd_elf_generic_reloc
, /* special_function */
690 "R_CKCORE_GOTOFF_IMM18", /* name */
691 TRUE
, /* partial_inplace */
692 0xfffc, /* src_mask */
693 0x3ffff, /* dst_mask */
694 FALSE
), /* pcrel_offset */
697 HOWTO (R_CKCORE_GOT_IMM18BY4
, /* type */
701 FALSE
, /* pc_relative */
703 complain_overflow_bitfield
, /* complain_on_overflow */
704 bfd_elf_generic_reloc
, /* special_function */
705 "R_CKCORE_GOT_IMM18BY4", /* name */
706 TRUE
, /* partial_inplace */
707 0xfffc, /* src_mask */
708 0x3ffff, /* dst_mask */
709 FALSE
), /* pcrel_offset */
712 HOWTO (R_CKCORE_PLT_IMM18BY4
, /* type */
716 FALSE
, /* pc_relative */
718 complain_overflow_bitfield
, /* complain_on_overflow */
719 bfd_elf_generic_reloc
, /* special_function */
720 "R_CKCORE_PLT_IMM18BY4", /* name */
721 TRUE
, /* partial_inplace */
722 0xfffc, /* src_mask */
723 0x3ffff, /* dst_mask */
724 TRUE
), /* pcrel_offset */
727 HOWTO (R_CKCORE_PCREL_IMM7BY4
, /* type */
731 TRUE
, /* pc_relative */
733 complain_overflow_bitfield
, /* complain_on_overflow */
734 bfd_elf_generic_reloc
, /* special_function */
735 "R_CKCORE_PCREL_IMM7BY4", /* name */
736 FALSE
, /* partial_inplace */
737 0xec1f, /* src_mask */
738 0x31f, /* dst_mask */
739 TRUE
), /* pcrel_offset */
741 /* 51: for static nptl. */
742 HOWTO (R_CKCORE_TLS_LE32
, /* type */
746 FALSE
, /* pc_relative */
748 complain_overflow_dont
, /* complain_on_overflow */
749 bfd_elf_generic_reloc
, /* special_function */
750 "R_CKCORE_TLS_LE32", /* name */
751 FALSE
, /* partial_inplace */
753 0xffffffff, /* dst_mask */
754 TRUE
), /* pcrel_offset */
756 /* 52: for static nptl. */
757 HOWTO (R_CKCORE_TLS_IE32
, /* type */
761 FALSE
, /* pc_relative */
763 complain_overflow_dont
, /* complain_on_overflow */
764 bfd_elf_generic_reloc
, /* special_function */
765 "R_CKCORE_TLS_IE32", /* name */
766 FALSE
, /* partial_inplace */
768 0xffffffff, /* dst_mask */
769 TRUE
), /* pcrel_offset */
771 /* 53: for pic nptl. */
772 HOWTO (R_CKCORE_TLS_GD32
, /* type */
776 FALSE
, /* pc_relative */
778 complain_overflow_dont
, /* complain_on_overflow */
779 bfd_elf_generic_reloc
, /* special_function */
780 "R_CKCORE_TLS_GD32", /* name */
781 FALSE
, /* partial_inplace */
783 0xffffffff, /* dst_mask */
784 TRUE
), /* pcrel_offset */
786 /* 54: for pic nptl. */
787 HOWTO (R_CKCORE_TLS_LDM32
, /* type */
791 FALSE
, /* pc_relative */
793 complain_overflow_dont
, /* complain_on_overflow */
794 bfd_elf_generic_reloc
, /* special_function */
795 "R_CKCORE_TLS_LDM32", /* name */
796 FALSE
, /* partial_inplace */
798 0xffffffff, /* dst_mask */
799 TRUE
), /* pcrel_offset */
801 /* 55: for pic nptl. */
802 HOWTO (R_CKCORE_TLS_LDO32
, /* type */
806 FALSE
, /* pc_relative */
808 complain_overflow_dont
, /* complain_on_overflow */
809 bfd_elf_generic_reloc
, /* special_function */
810 "R_CKCORE_TLS_LDO32", /* name */
811 FALSE
, /* partial_inplace */
813 0xffffffff, /* dst_mask */
814 TRUE
), /* pcrel_offset */
816 /* 56: for linker. */
817 HOWTO (R_CKCORE_TLS_DTPMOD32
,0,0,0,0,0,0,0,"R_CKCORE_TLS_DTPMOD32",0,0,0,0),
819 /* 57: for linker. */
820 HOWTO (R_CKCORE_TLS_DTPOFF32
,0,0,0,0,0,0,0,"R_CKCORE_TLS_DTPOFF32",0,0,0,0),
822 /* 58: for linker. */
823 HOWTO (R_CKCORE_TLS_TPOFF32
,0,0,0,0,0,0,0,"R_CKCORE_TLS_TPOFF32",0,0,0,0),
825 /* 59: for ck807f. */
826 HOWTO (R_CKCORE_PCREL_FLRW_IMM8BY4
, /* type */
830 TRUE
, /* pc_relative */
832 complain_overflow_bitfield
, /* complain_on_overflow */
833 NULL
, /* special_function */
834 "R_CKCORE_PCREL_FLRW_IMM8BY4", /* name */
835 FALSE
, /* partial_inplace */
836 0xfe1fff0f, /* src_mask */
837 0x1e000f0, /* dst_mask */
838 TRUE
), /* pcrel_offset */
840 /* 60: for 810 not to generate jsri. */
841 HOWTO (R_CKCORE_NOJSRI
, /* type */
845 FALSE
, /* pc_relative */
847 complain_overflow_dont
, /* complain_on_overflow */
848 bfd_elf_generic_reloc
, /* special_function */
849 "R_CKCORE_NOJSRI", /* name */
850 FALSE
, /* partial_inplace */
851 0xffff, /* src_mask */
852 0xffff, /* dst_mask */
853 FALSE
), /* pcrel_offset */
855 /* 61: for callgraph. */
856 HOWTO (R_CKCORE_CALLGRAPH
, /* type */
860 FALSE
, /* pc_relative */
862 complain_overflow_dont
, /* complain_on_overflow */
863 NULL
, /* special_function */
864 "R_CKCORE_CALLGRAPH", /* name */
865 FALSE
, /* partial_inplace */
868 TRUE
), /* pcrel_offset */
871 HOWTO (R_CKCORE_IRELATIVE
,0,0,0,0,0,0,0,"R_CKCORE_IRELATIVE",0,0,0,0),
873 /* 63: for bloop instruction */
874 HOWTO (R_CKCORE_PCREL_BLOOP_IMM4BY4
, /* type */
880 complain_overflow_signed
, /* complain_on_overflow */
881 bfd_elf_generic_reloc
, /* special_function */
882 "R_CKCORE_PCREL_BLOOP_IMM4BY4", /* name */
883 FALSE
, /* partial_inplace */
886 TRUE
), /* pcrel_offset */
887 /* 64: for bloop instruction */
888 HOWTO (R_CKCORE_PCREL_BLOOP_IMM12BY4
, /* type */
894 complain_overflow_signed
, /* complain_on_overflow */
895 bfd_elf_generic_reloc
, /* special_function */
896 "R_CKCORE_PCREL_BLOOP_IMM12BY4", /* name */
897 FALSE
, /* partial_inplace */
899 0xfff, /* dst_mask */
900 TRUE
), /* pcrel_offset */
906 /* Whether GOT overflow checking is needed. */
907 static int check_got_overflow
= 0;
909 /* Whether the target 32 bits is forced so that the high
910 16 bits is at the low address. */
911 static int need_reverse_bits
;
913 /* Used for relaxation. See csky_relocate_contents. */
914 static bfd_vma read_content_substitute
;
917 The way the following two look-up functions work demands
918 that BFD_RELOC_CKCORE_xxx are defined contiguously. */
920 static reloc_howto_type
*
921 csky_elf_reloc_type_lookup (bfd
* abfd ATTRIBUTE_UNUSED
,
922 bfd_reloc_code_real_type code
)
924 int csky_code
= code
- BFD_RELOC_CKCORE_NONE
;
926 if (csky_code
< 0 || csky_code
>= R_CKCORE_MAX
)
931 csky_code
= R_CKCORE_NONE
;
934 csky_code
= R_CKCORE_ADDR32
;
936 case BFD_RELOC_32_PCREL
:
937 csky_code
= R_CKCORE_PCREL32
;
939 case BFD_RELOC_VTABLE_INHERIT
:
940 csky_code
= R_CKCORE_GNU_VTINHERIT
;
942 case BFD_RELOC_VTABLE_ENTRY
:
943 csky_code
= R_CKCORE_GNU_VTENTRY
;
946 csky_code
= R_CKCORE_RELATIVE
;
949 return (reloc_howto_type
*)NULL
;
952 /* Note: when adding csky bfd reloc types in bfd-in2.h
953 and csky elf reloc types in elf/csky.h,
954 the order of the two reloc type tables should be consistent. */
955 return &csky_elf_howto_table
[csky_code
];
958 static reloc_howto_type
*
959 csky_elf_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
963 for (i
= 0; i
< R_CKCORE_MAX
; i
++)
964 if (strcasecmp (csky_elf_howto_table
[i
].name
, r_name
) == 0)
965 return &csky_elf_howto_table
[i
];
969 static reloc_howto_type
*
970 elf32_csky_howto_from_type (unsigned int r_type
)
972 if (r_type
< R_CKCORE_MAX
)
973 return &csky_elf_howto_table
[r_type
];
979 csky_elf_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
,
981 Elf_Internal_Rela
*dst
)
985 r_type
= ELF32_R_TYPE (dst
->r_info
);
986 cache_ptr
->howto
= elf32_csky_howto_from_type (r_type
);
987 if (cache_ptr
->howto
== NULL
)
989 /* xgettext:c-format */
990 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
992 bfd_set_error (bfd_error_bad_value
);
998 /* The Global Offset Table max size. */
999 #define GOT_MAX_SIZE 0xFFFF8
1001 /* The name of the dynamic interpreter. This is put in the .interp
1003 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1005 /* The size in bytes of an entry in the procedure linkage table. */
1006 #define PLT_ENTRY_SIZE 12
1007 #define PLT_ENTRY_SIZE_P 16
1009 /* The first entry in a procedure linkage table looks like
1010 this. It is set up so that any shared library function that is
1011 called before the relocation has been set up calls the dynamic
1013 static const bfd_vma csky_elf_plt_entry_v2
[PLT_ENTRY_SIZE
/ 4] =
1015 0xd99c2002, /* ldw r12, (gb, 8) */
1016 0xea0d0000, /* movi r13,offset */
1017 0xe8cc0000 /* jmp r12 */
1020 static const bfd_vma csky_elf_plt_entry_v1
[PLT_ENTRY_SIZE
/ 2 ] =
1022 0x25f0, /* subi r0, 32 */
1023 0x9200, /* stw r2, (r0, 0) */
1024 0x9310, /* stw r3, (r0, 4) */
1025 0x822e, /* ldw r2, (gb, 8) */
1026 0x7301, /* lrw r3, #offset */
1027 0x00c2, /* jmp r2 */
1030 /* Branch stub support. */
1039 bfd_boolean use_branch_stub
= TRUE
;
1043 enum stub_insn_type type
;
1044 unsigned int r_type
;
1048 static const insn_sequence elf32_csky_stub_long_branch
[] =
1050 {0xea8d0002, INSN32
, R_CKCORE_NONE
, 0x0}, /* lrw t1,[pc+8] */
1051 {0x7834, INSN16
, R_CKCORE_NONE
, 0x0}, /* jmp t1 */
1052 {0x6c03, INSN16
, R_CKCORE_NONE
, 0x0}, /* nop */
1053 {0x0, DATA_TYPE
, R_CKCORE_ADDR32
, 0x0} /* .long addr */
1056 static const insn_sequence elf32_csky_stub_long_branch_jmpi
[] =
1058 {0xeac00001, INSN32
, R_CKCORE_NONE
, 0x0}, /* jmpi [pc+4] */
1059 {0x0, DATA_TYPE
, R_CKCORE_ADDR32
, 0x0} /* .long addr */
1062 /* The bsr instruction offset limit. */
1063 #define BSR_MAX_FWD_BRANCH_OFFSET (((1 << 25) - 1) << 1)
1064 #define BSR_MAX_BWD_BRANCH_OFFSET (-(1 << 26))
1066 #define STUB_SUFFIX ".stub"
1067 #define STUB_ENTRY_NAME "__%s_veneer"
1069 /* One entry per long/short branch stub defined above. */
1071 DEF_STUB(long_branch) \
1072 DEF_STUB(long_branch_jmpi)
1074 #define DEF_STUB(x) csky_stub_##x,
1075 enum elf32_csky_stub_type
1084 const insn_sequence
* template_sequence
;
1088 #define DEF_STUB(x) {elf32_csky_stub_##x, ARRAY_SIZE(elf32_csky_stub_##x)},
1089 static const stub_def stub_definitions
[] = {
1094 /* The size of the thread control block. */
1097 struct csky_elf_obj_tdata
1099 struct elf_obj_tdata root
;
1101 /* tls_type for each local got entry. */
1102 char *local_got_tls_type
;
1105 #define csky_elf_local_got_tls_type(bfd) \
1106 (csky_elf_tdata (bfd)->local_got_tls_type)
1108 #define csky_elf_tdata(bfd) \
1109 ((struct csky_elf_obj_tdata *) (bfd)->tdata.any)
1111 struct elf32_csky_stub_hash_entry
1113 /* Base hash table entry structure. */
1114 struct bfd_hash_entry root
;
1116 /* The stub section. */
1119 /* Offset within stub_sec of the beginning of this stub. */
1120 bfd_vma stub_offset
;
1122 /* Given the symbol's value and its section we can determine its final
1123 value when building the stubs (so the stub knows where to jump). */
1124 bfd_vma target_value
;
1125 asection
*target_section
;
1127 /* Offset to apply to relocation referencing target_value. */
1128 bfd_vma target_addend
;
1130 /* The stub type. */
1131 enum elf32_csky_stub_type stub_type
;
1132 /* Its encoding size in bytes. */
1135 const insn_sequence
*stub_template
;
1136 /* The size of the template (number of entries). */
1137 int stub_template_size
;
1139 /* The symbol table entry, if any, that this was derived from. */
1140 struct csky_elf_link_hash_entry
*h
;
1142 /* Destination symbol type. */
1143 unsigned char st_type
;
1145 /* Where this stub is being called from, or, in the case of combined
1146 stub sections, the first input section in the group. */
1149 /* The name for the local symbol at the start of this stub. The
1150 stub name in the hash table has to be unique; this does not, so
1151 it can be friendlier. */
1155 #define csky_stub_hash_lookup(table, string, create, copy) \
1156 ((struct elf32_csky_stub_hash_entry *) \
1157 bfd_hash_lookup ((table), (string), (create), (copy)))
1159 /* C-SKY ELF linker hash entry. */
1160 struct csky_elf_link_hash_entry
1162 struct elf_link_hash_entry elf
;
1164 /* For sub jsri2bsr relocs count. */
1165 int jsri2bsr_refcount
;
1167 #define GOT_UNKNOWN 0
1168 #define GOT_NORMAL 1
1169 #define GOT_TLS_GD 2
1170 #define GOT_TLS_IE 4
1172 unsigned char tls_type
;
1174 /* A pointer to the most recently used stub hash entry against this
1176 struct elf32_csky_stub_hash_entry
*stub_cache
;
1179 /* Traverse an C-SKY ELF linker hash table. */
1180 #define csky_elf_link_hash_traverse(table, func, info) \
1181 (elf_link_hash_traverse \
1183 (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
1186 /* Get the C-SKY ELF linker hash table from a link_info structure. */
1187 #define csky_elf_hash_table(info) \
1188 ((elf_hash_table_id ((struct elf_link_hash_table *) ((info)->hash)) \
1190 ? ((struct csky_elf_link_hash_table *) ((info)->hash)) \
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 /* Small local sym cache. */
1212 struct sym_cache sym_cache
;
1214 /* Data for R_CKCORE_TLS_LDM32 relocations. */
1217 bfd_signed_vma refcount
;
1221 /* The stub hash table. */
1222 struct bfd_hash_table stub_hash_table
;
1224 /* Linker stub bfd. */
1227 /* Linker call-backs. */
1228 asection
* (*add_stub_section
) (const char *, asection
*);
1229 void (*layout_sections_again
) (void);
1231 /* Array to keep track of which stub sections have been created, and
1232 * information on stub grouping. */
1233 struct map_stub
*stub_group
;
1235 /* Number of elements in stub_group. */
1236 unsigned int top_id
;
1238 /* Assorted information used by elf32_csky_size_stubs. */
1239 unsigned int bfd_count
;
1240 unsigned int top_index
;
1241 asection
**input_list
;
1244 /* We can't change vectors in the bfd target which will apply to
1245 data sections, however we only do this to the text sections. */
1248 csky_get_insn_32 (bfd
*input_bfd
,
1251 if (bfd_big_endian (input_bfd
))
1252 return bfd_get_32 (input_bfd
, location
);
1254 return (bfd_get_16 (input_bfd
, location
) << 16
1255 | bfd_get_16 (input_bfd
, location
+ 2));
1259 csky_put_insn_32 (bfd
*input_bfd
,
1263 if (bfd_big_endian (input_bfd
))
1264 bfd_put_32 (input_bfd
, x
, location
);
1267 bfd_put_16 (input_bfd
, x
>> 16, location
);
1268 bfd_put_16 (input_bfd
, x
& 0xffff, location
+ 2);
1272 /* Find or create a stub section. Returns a pointer to the stub section, and
1273 the section to which the stub section will be attached (in *LINK_SEC_P).
1274 LINK_SEC_P may be NULL. */
1277 elf32_csky_create_or_find_stub_sec (asection
**link_sec_p
, asection
*section
,
1278 struct csky_elf_link_hash_table
*htab
)
1283 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
1284 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
1285 if (stub_sec
== NULL
)
1287 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
1288 if (stub_sec
== NULL
)
1294 namelen
= strlen (link_sec
->name
);
1295 len
= namelen
+ sizeof (STUB_SUFFIX
);
1296 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
1300 memcpy (s_name
, link_sec
->name
, namelen
);
1301 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
1302 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
1303 if (stub_sec
== NULL
)
1305 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
1307 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
1311 *link_sec_p
= link_sec
;
1316 /* Build a name for an entry in the stub hash table. */
1319 elf32_csky_stub_name (const asection
*input_section
,
1320 const asection
*sym_sec
,
1321 const struct csky_elf_link_hash_entry
*hash
,
1322 const Elf_Internal_Rela
*rel
)
1329 len
= 8 + 1 + strlen (hash
->elf
.root
.root
.string
) + 1 + 8 + 1;
1330 stub_name
= bfd_malloc (len
);
1331 if (stub_name
!= NULL
)
1332 sprintf (stub_name
, "%08x_%s+%x",
1333 input_section
->id
& 0xffffffff,
1334 hash
->elf
.root
.root
.string
,
1335 (int) rel
->r_addend
& 0xffffffff);
1339 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
1340 stub_name
= bfd_malloc (len
);
1341 if (stub_name
!= NULL
)
1342 sprintf (stub_name
, "%08x_%x:%x+%x",
1343 input_section
->id
& 0xffffffff,
1344 sym_sec
->id
& 0xffffffff,
1345 (int) ELF32_R_SYM (rel
->r_info
) & 0xffffffff,
1346 (int) rel
->r_addend
& 0xffffffff);
1352 /* Determine the type of stub needed, if any, for a call. */
1354 static enum elf32_csky_stub_type
1355 csky_type_of_stub (struct bfd_link_info
*info
,
1356 asection
*input_sec
,
1357 const Elf_Internal_Rela
*rel
,
1358 unsigned char st_type
,
1359 struct csky_elf_link_hash_entry
*hash
,
1360 bfd_vma destination
,
1361 asection
*sym_sec ATTRIBUTE_UNUSED
,
1362 bfd
*input_bfd ATTRIBUTE_UNUSED
,
1363 const char *name ATTRIBUTE_UNUSED
)
1366 bfd_signed_vma branch_offset
;
1367 unsigned int r_type
;
1368 enum elf32_csky_stub_type stub_type
= csky_stub_none
;
1369 struct elf_link_hash_entry
* h
= &hash
->elf
;
1371 /* We don't know the actual type of destination in case it is of
1372 type STT_SECTION: give up. */
1373 if (st_type
== STT_SECTION
)
1376 location
= (input_sec
->output_offset
1377 + input_sec
->output_section
->vma
1380 branch_offset
= (bfd_signed_vma
)(destination
- location
);
1381 r_type
= ELF32_R_TYPE (rel
->r_info
);
1382 if (r_type
== R_CKCORE_PCREL_IMM26BY2
1384 && ((h
->def_dynamic
&& !h
->def_regular
)
1385 || (bfd_link_pic (info
)
1386 && h
->root
.type
== bfd_link_hash_defweak
)))
1387 || branch_offset
> BSR_MAX_FWD_BRANCH_OFFSET
1388 || branch_offset
< BSR_MAX_BWD_BRANCH_OFFSET
))
1390 if (bfd_csky_arch (info
->output_bfd
) == CSKY_ARCH_810
1391 || bfd_csky_arch (info
->output_bfd
) == CSKY_ARCH_807
)
1392 stub_type
= csky_stub_long_branch_jmpi
;
1394 stub_type
= csky_stub_long_branch
;
1400 /* Create an entry in an C-SKY ELF linker hash table. */
1402 static struct bfd_hash_entry
*
1403 csky_elf_link_hash_newfunc (struct bfd_hash_entry
* entry
,
1404 struct bfd_hash_table
* table
,
1405 const char * string
)
1407 struct csky_elf_link_hash_entry
* ret
=
1408 (struct csky_elf_link_hash_entry
*) entry
;
1410 /* Allocate the structure if it has not already been allocated by a
1414 ret
= (struct csky_elf_link_hash_entry
*)
1415 bfd_hash_allocate (table
,
1416 sizeof (struct csky_elf_link_hash_entry
));
1418 return (struct bfd_hash_entry
*) ret
;
1421 /* Call the allocation method of the superclass. */
1422 ret
= ((struct csky_elf_link_hash_entry
*)
1423 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*)ret
,
1427 struct csky_elf_link_hash_entry
*eh
;
1429 eh
= (struct csky_elf_link_hash_entry
*) ret
;
1430 eh
->plt_refcount
= 0;
1431 eh
->jsri2bsr_refcount
= 0;
1432 eh
->tls_type
= GOT_NORMAL
;
1433 ret
->stub_cache
= NULL
;
1436 return (struct bfd_hash_entry
*) ret
;
1439 /* Initialize an entry in the stub hash table. */
1441 static struct bfd_hash_entry
*
1442 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
1443 struct bfd_hash_table
*table
,
1446 /* Allocate the structure if it has not already been allocated by a
1450 entry
= ((struct bfd_hash_entry
*)
1451 bfd_hash_allocate (table
,
1452 sizeof (struct elf32_csky_stub_hash_entry
)));
1457 /* Call the allocation method of the superclass. */
1458 entry
= bfd_hash_newfunc (entry
, table
, string
);
1461 struct elf32_csky_stub_hash_entry
*eh
;
1463 /* Initialize the local fields. */
1464 eh
= (struct elf32_csky_stub_hash_entry
*) entry
;
1465 eh
->stub_sec
= NULL
;
1466 eh
->stub_offset
= 0;
1467 eh
->target_value
= 0;
1468 eh
->target_section
= NULL
;
1469 eh
->target_addend
= 0;
1470 eh
->stub_type
= csky_stub_none
;
1472 eh
->stub_template
= NULL
;
1473 eh
->stub_template_size
= -1;
1476 eh
->output_name
= NULL
;
1482 /* Free the derived linker hash table. */
1485 csky_elf_link_hash_table_free (bfd
*obfd
)
1487 struct csky_elf_link_hash_table
*ret
1488 = (struct csky_elf_link_hash_table
*) obfd
->link
.hash
;
1490 bfd_hash_table_free (&ret
->stub_hash_table
);
1491 _bfd_elf_link_hash_table_free (obfd
);
1494 /* Create an CSKY elf linker hash table. */
1496 static struct bfd_link_hash_table
*
1497 csky_elf_link_hash_table_create (bfd
*abfd
)
1499 struct csky_elf_link_hash_table
*ret
;
1500 size_t amt
= sizeof (struct csky_elf_link_hash_table
);
1502 ret
= (struct csky_elf_link_hash_table
*) bfd_zmalloc (amt
);
1506 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
1507 csky_elf_link_hash_newfunc
,
1508 sizeof (struct csky_elf_link_hash_entry
),
1515 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
,
1516 sizeof (struct elf32_csky_stub_hash_entry
)))
1521 ret
->elf
.root
.hash_table_free
= csky_elf_link_hash_table_free
;
1522 return &ret
->elf
.root
;
1526 csky_elf_mkobject (bfd
*abfd
)
1528 return bfd_elf_allocate_object (abfd
, sizeof (struct csky_elf_obj_tdata
),
1532 /* Adjust a symbol defined by a dynamic object and referenced by a
1533 regular object. The current definition is in some section of the
1534 dynamic object, but we're not including those sections. We have to
1535 change the definition to something the rest of the link can
1539 csky_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1540 struct elf_link_hash_entry
*h
)
1542 struct csky_elf_link_hash_entry
*eh
;
1543 struct csky_elf_link_hash_table
*htab
;
1546 eh
= (struct csky_elf_link_hash_entry
*)h
;
1550 htab
= csky_elf_hash_table (info
);
1554 /* Clear jsri2bsr_refcount, if creating shared library files. */
1555 if (bfd_link_pic (info
) && eh
->jsri2bsr_refcount
> 0)
1556 eh
->jsri2bsr_refcount
= 0;
1558 /* If there is a function, put it in the procedure linkage table. We
1559 will fill in the contents of the procedure linkage table later. */
1562 /* Calls to STT_GNU_IFUNC symbols always use a PLT, even if the
1563 symbol binds locally. */
1564 if (h
->plt
.refcount
<= 0
1565 || (h
->type
!= STT_GNU_IFUNC
1566 && (SYMBOL_CALLS_LOCAL (info
, h
)
1567 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1568 && h
->root
.type
== bfd_link_hash_undefweak
))))
1571 /* This case can occur if we saw a PLT32 reloc in an input
1572 file, but the symbol was never referred to by a dynamic
1573 object, or if all references were garbage collected. In
1574 such a case, we don't actually need to build a procedure
1575 linkage table, and we can just do a PC32 reloc instead. */
1576 h
->plt
.offset
= (bfd_vma
) -1;
1578 if (h
->got
.refcount
== 0)
1579 h
->got
.refcount
+= 1;
1581 else if (h
->got
.refcount
!= 0)
1583 h
->got
.refcount
-= eh
->plt_refcount
;
1584 eh
->plt_refcount
= 0;
1589 /* It's possible that we incorrectly decided a .plt reloc was
1590 needed for an R_CKCORE_PC32 or similar reloc to a non-function
1591 sym in check_relocs. We can't decide accurately between function
1592 and non-function syms in check_relocs; objects loaded later in
1593 the link may change h->type. So fix it now. */
1594 h
->plt
.offset
= (bfd_vma
) -1;
1596 /* If this is a weak symbol, and there is a real definition, the
1597 processor independent code will have arranged for us to see the
1598 real definition first, and we can just use the same value. */
1599 if (h
->is_weakalias
)
1601 struct elf_link_hash_entry
*def
= weakdef (h
);
1602 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
1603 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
1604 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
1608 /* If there are no non-GOT references, we do not need a copy
1610 if (!h
->non_got_ref
)
1613 /* This is a reference to a symbol defined by a dynamic object which
1614 is not a function. */
1616 /* If we are creating a shared library, we must presume that the
1617 only references to the symbol are via the global offset table.
1618 For such cases we need not do anything here; the relocations will
1619 be handled correctly by relocate_section. */
1620 if (bfd_link_pic (info
) || htab
->elf
.is_relocatable_executable
)
1623 /* We must allocate the symbol in our .dynbss section, which will
1624 become part of the .bss section of the executable. There will be
1625 an entry for this symbol in the .dynsym section. The dynamic
1626 object will contain position independent code, so all references
1627 from the dynamic object to this symbol will go through the global
1628 offset table. The dynamic linker will use the .dynsym entry to
1629 determine the address it must put in the global offset table, so
1630 both the dynamic object and the regular object will refer to the
1631 same memory location for the variable. */
1632 /* We must generate a R_CKCORE_COPY reloc to tell the dynamic linker to
1633 copy the initial value out of the dynamic object and into the
1634 runtime process image. We need to remember the offset into the
1635 .rela.bss section we are going to use. */
1636 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
1638 s
= htab
->elf
.sdynrelro
;
1639 srel
= htab
->elf
.sreldynrelro
;
1643 s
= htab
->elf
.sdynbss
;
1644 srel
= htab
->elf
.srelbss
;
1646 if (info
->nocopyreloc
== 0
1647 && (h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0
1652 srel
->size
+= sizeof (Elf32_External_Rela
);
1654 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
1661 /* Allocate space in .plt, .got and associated reloc sections for
1665 csky_allocate_dynrelocs (struct elf_link_hash_entry
*h
, PTR inf
)
1667 struct bfd_link_info
*info
;
1668 struct csky_elf_link_hash_table
*htab
;
1669 struct csky_elf_link_hash_entry
*eh
;
1670 struct elf_dyn_relocs
*p
;
1672 /* For indirect case, such as _ZdlPv to _ZdlPv@@GLIBCXX_3.4. */
1673 if (h
->root
.type
== bfd_link_hash_indirect
)
1676 if (h
->root
.type
== bfd_link_hash_warning
)
1677 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1680 info
= (struct bfd_link_info
*) inf
;
1681 htab
= csky_elf_hash_table (info
);
1684 /*TODO: how to deal with weak symbol relocs. */
1685 if ((htab
->elf
.dynamic_sections_created
|| h
->type
== STT_GNU_IFUNC
)
1686 && h
->plt
.refcount
> 0)
1688 /* Make sure this symbol is output as a dynamic symbol.
1689 Undefined weak syms won't yet be marked as dynamic. */
1690 if (h
->dynindx
== -1 && !h
->forced_local
1691 && h
->root
.type
== bfd_link_hash_undefweak
1692 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
1694 if (bfd_link_pic (info
) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
1696 asection
*splt
= htab
->elf
.splt
;
1698 /* If this is the first .plt entry, make room for the special
1700 if (splt
->size
== 0)
1702 if (bfd_csky_abi (info
->output_bfd
) == CSKY_ABI_V1
)
1703 splt
->size
+= PLT_ENTRY_SIZE_P
;
1705 splt
->size
+= PLT_ENTRY_SIZE
;
1707 h
->plt
.offset
= splt
->size
;
1709 /* If this symbol is not defined in a regular file, and we are
1710 not generating a shared library, then set the symbol to this
1711 location in the .plt. This is required to make function
1712 pointers compare as equal between the normal executable and
1713 the shared library. */
1714 if (!bfd_link_pic (info
) && !h
->def_regular
)
1716 h
->root
.u
.def
.section
= splt
;
1717 h
->root
.u
.def
.value
= h
->plt
.offset
;
1720 /* Make room for this entry. */
1721 if (bfd_csky_abi (info
->output_bfd
) == CSKY_ABI_V1
)
1722 splt
->size
+= PLT_ENTRY_SIZE_P
;
1724 splt
->size
+= PLT_ENTRY_SIZE
;
1725 /* We also need to make an entry in the .rela.plt section. */
1726 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rela
);
1728 /* We also need to make an entry in the .got.plt section, which
1729 will be placed in the .got section by the linker script. */
1730 htab
->elf
.sgotplt
->size
+= 4;
1734 h
->plt
.offset
= (bfd_vma
) -1;
1740 h
->plt
.offset
= (bfd_vma
) -1;
1744 if (h
->got
.refcount
> 0)
1750 int tls_type
= csky_elf_hash_entry (h
)->tls_type
;
1751 /* Make sure this symbol is output as a dynamic symbol.
1752 Undefined weak syms won't yet be marked as dynamic. */
1753 if (h
->dynindx
== -1 && !h
->forced_local
1754 && h
->root
.type
== bfd_link_hash_undefweak
1755 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
1758 sgot
= htab
->elf
.sgot
;
1759 h
->got
.offset
= sgot
->size
;
1760 BFD_ASSERT (tls_type
!= GOT_UNKNOWN
);
1761 if (tls_type
== GOT_NORMAL
)
1762 /* Non-TLS symbols need one GOT slot. */
1766 if (tls_type
& GOT_TLS_GD
)
1767 /* R_CKCORE_TLS_GD32 needs 2 consecutive GOT slots. */
1769 if (tls_type
& GOT_TLS_IE
)
1770 /* R_CKCORE_TLS_IE32 needs one GOT slot. */
1773 dyn
= htab
->elf
.dynamic_sections_created
;
1775 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
), h
)
1776 && (! bfd_link_pic (info
) || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
1779 if (tls_type
!= GOT_NORMAL
1780 && (bfd_link_pic (info
) || indx
!= 0)
1781 && ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1782 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
1783 || h
->root
.type
!= bfd_link_hash_undefweak
))
1785 if (tls_type
& GOT_TLS_IE
)
1786 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rela
);
1787 if (tls_type
& GOT_TLS_GD
)
1788 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rela
);
1789 if ((tls_type
& GOT_TLS_GD
) && indx
!= 0)
1790 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rela
);
1792 else if (((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1793 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
1794 || h
->root
.type
!= bfd_link_hash_undefweak
)
1795 && (bfd_link_pic (info
)
1796 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)
1797 || h
->plt
.offset
== (bfd_vma
) -1))
1798 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rela
);
1801 h
->got
.offset
= (bfd_vma
) -1;
1803 eh
= (struct csky_elf_link_hash_entry
*) h
;
1804 if (h
->dyn_relocs
== NULL
)
1807 /* In the shared -Bsymbolic case, discard space allocated for
1808 dynamic pc-relative relocs against symbols which turn out to be
1809 defined in regular objects. For the normal shared case, discard
1810 space for pc-relative relocs that have become local due to symbol
1811 visibility changes. */
1813 if (bfd_link_pic (info
))
1815 if (SYMBOL_CALLS_LOCAL (info
, h
))
1817 struct elf_dyn_relocs
**pp
;
1819 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
1821 p
->count
-= p
->pc_count
;
1830 if (eh
->jsri2bsr_refcount
1831 && h
->root
.type
== bfd_link_hash_defined
1832 && h
->dyn_relocs
!= NULL
)
1833 h
->dyn_relocs
->count
-= eh
->jsri2bsr_refcount
;
1835 /* Also discard relocs on undefined weak syms with non-default
1837 if (h
->dyn_relocs
!= NULL
1838 && h
->root
.type
== bfd_link_hash_undefweak
)
1840 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1841 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
1842 h
->dyn_relocs
= NULL
;
1844 /* Make sure undefined weak symbols are output as a dynamic
1846 else if (h
->dynindx
== -1
1848 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
1855 /* For the non-shared case, discard space for relocs against
1856 symbols which turn out to need copy relocs or are not
1860 && ((h
->def_dynamic
&& !h
->def_regular
)
1861 || (htab
->elf
.dynamic_sections_created
1862 && (h
->root
.type
== bfd_link_hash_undefweak
1863 || h
->root
.type
== bfd_link_hash_indirect
1864 || h
->root
.type
== bfd_link_hash_undefined
))))
1866 /* Make sure this symbol is output as a dynamic symbol.
1867 Undefined weak syms won't yet be marked as dynamic. */
1868 if (h
->dynindx
== -1 && !h
->forced_local
1869 && h
->root
.type
== bfd_link_hash_undefweak
)
1871 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
1875 /* If that succeeded, we know we'll be keeping all the
1877 if (h
->dynindx
!= -1)
1881 h
->dyn_relocs
= NULL
;
1886 /* Finally, allocate space. */
1887 for (p
= h
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
1889 asection
*srelgot
= htab
->elf
.srelgot
;
1890 srelgot
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
1896 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
1897 read-only sections. */
1900 maybe_set_textrel (struct elf_link_hash_entry
*h
, void *info_p
)
1904 if (h
->root
.type
== bfd_link_hash_indirect
)
1907 sec
= _bfd_elf_readonly_dynrelocs (h
);
1910 struct bfd_link_info
*info
= (struct bfd_link_info
*) info_p
;
1912 info
->flags
|= DF_TEXTREL
;
1913 info
->callbacks
->minfo
1914 (_("%pB: dynamic relocation against `%pT' in read-only section `%pA'\n"),
1915 sec
->owner
, h
->root
.root
.string
, sec
);
1917 /* Not an error, just cut short the traversal. */
1923 /* Set the sizes of the dynamic sections. */
1926 csky_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
1927 struct bfd_link_info
*info
)
1929 struct csky_elf_link_hash_table
*htab
;
1935 htab
= csky_elf_hash_table (info
);
1938 dynobj
= htab
->elf
.dynobj
;
1942 if (htab
->elf
.dynamic_sections_created
)
1944 /* Set the contents of the .interp section to the interpreter. */
1945 if (!bfd_link_pic (info
) && !info
->nointerp
)
1947 s
= bfd_get_section_by_name (dynobj
, ".interp");
1948 BFD_ASSERT (s
!= NULL
);
1949 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1950 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1954 /* Set up .got offsets for local syms, and space for local dynamic
1956 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
1958 bfd_signed_vma
*local_got_refcounts
;
1959 bfd_signed_vma
*end_local_got
;
1960 bfd_size_type locsymcount
;
1961 Elf_Internal_Shdr
*symtab_hdr
;
1962 asection
*srelgot
, *sgot
;
1963 char *local_tls_type
;
1965 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
1968 sgot
= htab
->elf
.sgot
;
1969 srelgot
= htab
->elf
.srelgot
;
1971 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
1973 struct elf_dyn_relocs
*p
;
1975 for (p
= *((struct elf_dyn_relocs
**)
1976 &elf_section_data (s
)->local_dynrel
);
1980 if (!bfd_is_abs_section (p
->sec
)
1981 && bfd_is_abs_section (p
->sec
->output_section
))
1982 /* Input section has been discarded, either because
1983 it is a copy of a linkonce section or due to
1984 linker script /DISCARD/, so we'll be discarding
1987 else if (p
->count
!= 0)
1989 srelgot
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
1990 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
1991 info
->flags
|= DF_TEXTREL
;
1996 local_got_refcounts
= elf_local_got_refcounts (ibfd
);
1997 if (!local_got_refcounts
)
2000 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
2001 locsymcount
= symtab_hdr
->sh_info
;
2002 end_local_got
= local_got_refcounts
+ locsymcount
;
2003 local_tls_type
= csky_elf_local_got_tls_type (ibfd
);
2005 for (; local_got_refcounts
< end_local_got
;
2006 ++local_got_refcounts
, ++local_tls_type
)
2008 if (*local_got_refcounts
> 0)
2010 /* GOT_TLS_GD and GOT_TLS_IE type for TLS, GOT_NORMAL type
2011 for GOT. If output file is shared library, we should output
2012 GOT_TLS_GD type relocation in .rel.got. */
2013 *local_got_refcounts
= sgot
->size
;
2014 if (*local_tls_type
& GOT_TLS_GD
)
2015 /* TLS_GD relocs need an 8-byte structure in the GOT. */
2017 if (*local_tls_type
& GOT_TLS_IE
)
2019 if (*local_tls_type
== GOT_NORMAL
)
2021 if (bfd_link_pic (info
) || *local_tls_type
== GOT_TLS_GD
)
2022 srelgot
->size
+= sizeof (Elf32_External_Rela
);
2025 *local_got_refcounts
= (bfd_vma
) -1;
2029 if (htab
->tls_ldm_got
.refcount
> 0)
2031 /* Allocate two GOT entries and one dynamic relocation (if necessary)
2032 for R_CSKY_TLS_LDM32 relocations. */
2033 htab
->tls_ldm_got
.offset
= htab
->elf
.sgot
->size
;
2034 htab
->elf
.sgot
->size
+= 8;
2035 if (bfd_link_pic (info
))
2036 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rela
);
2039 htab
->tls_ldm_got
.offset
= -1;
2041 /* Allocate global sym .plt and .got entries, and space for global
2042 sym dynamic relocs. */
2043 elf_link_hash_traverse (&htab
->elf
, csky_allocate_dynrelocs
, (PTR
) info
);
2045 /* Check for GOT overflow. */
2046 if (check_got_overflow
== 1
2047 && htab
->elf
.sgot
->size
+ htab
->elf
.sgotplt
->size
> GOT_MAX_SIZE
)
2049 _bfd_error_handler (_("GOT table size out of range")); /* */
2053 /* We now have determined the sizes of the various dynamic sections.
2054 Allocate memory for them. */
2056 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2058 bfd_boolean strip_section
= TRUE
;
2060 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2063 if (s
== htab
->elf
.splt
2064 || s
== htab
->elf
.sgot
2065 || s
== htab
->elf
.sgotplt
2066 || s
== htab
->elf
.sdynrelro
2067 || s
== htab
->elf
.sreldynrelro
)
2069 /* Strip this section if we don't need it;
2070 see the comment below. */
2071 /* We'd like to strip these sections if they aren't needed, but if
2072 we've exported dynamic symbols from them we must leave them.
2073 It's too late to tell BFD to get rid of the symbols. */
2075 if (htab
->elf
.hplt
!= NULL
)
2076 strip_section
= FALSE
;
2078 else if (CONST_STRNEQ (bfd_section_name (s
), ".rel") )
2083 /* We use the reloc_count field as a counter if we need
2084 to copy relocs into the output file. */
2088 /* It's not one of our sections, so don't allocate space. */
2091 /* Strip this section if we don't need it; see the
2095 /* If we don't need this section, strip it from the
2096 output file. This is mostly to handle .rel.bss and
2097 .rel.plt. We must create both sections in
2098 create_dynamic_sections, because they must be created
2099 before the linker maps input sections to output
2100 sections. The linker does that before
2101 adjust_dynamic_symbol is called, and it is that
2102 function which decides whether anything needs to go
2103 into these sections. */
2105 s
->flags
|= SEC_EXCLUDE
;
2109 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2112 /* Allocate memory for the section contents. We use bfd_zalloc
2113 here in case unused entries are not reclaimed before the
2114 section's contents are written out. This should not happen,
2115 but this way if it does, we get a R_CKCORE_NONE reloc instead
2117 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
2118 if (s
->contents
== NULL
)
2122 if (htab
->elf
.dynamic_sections_created
)
2124 /* Add some entries to the .dynamic section. We fill in the
2125 values later, in csky_elf_finish_dynamic_sections, but we
2126 must add the entries now so that we get the correct size for
2127 the .dynamic section. The DT_DEBUG entry is filled in by the
2128 dynamic linker and used by the debugger. */
2129 #define add_dynamic_entry(TAG, VAL) \
2130 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2132 if (bfd_link_executable (info
) && !add_dynamic_entry (DT_DEBUG
, 0))
2135 if (htab
->elf
.sgot
->size
!= 0 || htab
->elf
.splt
->size
)
2137 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2138 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2139 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
2140 || !add_dynamic_entry (DT_JMPREL
, 0))
2146 if (!add_dynamic_entry (DT_RELA
, 0)
2147 || !add_dynamic_entry (DT_RELASZ
, 0)
2148 || !add_dynamic_entry (DT_RELAENT
,
2149 sizeof (Elf32_External_Rela
)))
2152 /* If any dynamic relocs apply to a read-only section,
2153 then we need a DT_TEXTREL entry. */
2154 if ((info
->flags
& DF_TEXTREL
) == 0)
2155 elf_link_hash_traverse (&htab
->elf
, maybe_set_textrel
, info
);
2157 if ((info
->flags
& DF_TEXTREL
) != 0
2158 && !add_dynamic_entry (DT_TEXTREL
, 0))
2162 #undef add_dynamic_entry
2167 /* Finish up dynamic symbol handling. We set the contents of various
2168 dynamic sections here. */
2171 csky_elf_finish_dynamic_symbol (bfd
*output_bfd
,
2172 struct bfd_link_info
*info
,
2173 struct elf_link_hash_entry
*h
,
2174 Elf_Internal_Sym
*sym
)
2176 struct csky_elf_link_hash_table
*htab
;
2178 htab
= csky_elf_hash_table (info
);
2182 /* Sanity check to make sure no unexpected symbol reaches here.
2183 This matches the test in csky_elf_relocate_section handling
2184 of GOT/PLT entries. */
2185 BFD_ASSERT (! (h
->dynindx
== -1
2187 && h
->root
.type
!= bfd_link_hash_undefweak
2188 && bfd_link_pic (info
)));
2190 if (h
->plt
.offset
!= (bfd_vma
) -1)
2194 Elf_Internal_Rela rel
;
2196 asection
*plt
, *relplt
, *gotplt
;
2198 plt
= htab
->elf
.splt
;
2199 relplt
= htab
->elf
.srelplt
;
2200 gotplt
= htab
->elf
.sgotplt
;
2202 /* This symbol has an entry in the procedure linkage table. Set
2204 BFD_ASSERT (h
->dynindx
!= -1
2205 || ((h
->forced_local
|| bfd_link_executable (info
))
2206 && h
->def_regular
));
2207 BFD_ASSERT (plt
!= NULL
&& gotplt
!= NULL
&& relplt
!= NULL
);
2208 if (bfd_csky_abi (output_bfd
) == CSKY_ABI_V2
)
2209 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
2211 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE_P
- 1;
2212 got_offset
= (plt_index
+ 3) * 4;
2214 /* Fill in the entry in the procedure linkage table. */
2215 if (bfd_csky_abi (output_bfd
) == CSKY_ABI_V2
)
2217 csky_put_insn_32 (output_bfd
, csky_elf_plt_entry_v2
[0],
2218 plt
->contents
+ h
->plt
.offset
);
2219 csky_put_insn_32 (output_bfd
,
2220 (csky_elf_plt_entry_v2
[1] | plt_index
),
2221 plt
->contents
+ h
->plt
.offset
+ 4);
2222 csky_put_insn_32 (output_bfd
, csky_elf_plt_entry_v2
[2],
2223 plt
->contents
+ h
->plt
.offset
+ 8);
2228 for (i
= 0; i
< 6; i
++)
2229 bfd_put_16 (output_bfd
, csky_elf_plt_entry_v1
[i
],
2230 plt
->contents
+ h
->plt
.offset
+ i
* 2);
2231 bfd_put_32 (output_bfd
, plt_index
,
2232 plt
->contents
+ h
->plt
.offset
+ i
* 2);
2235 /* Fill in the entry in the .rel.plt section. */
2236 rel
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
2237 + htab
->elf
.sgotplt
->output_offset
2239 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_CKCORE_JUMP_SLOT
);
2240 rel
.r_addend
= (plt
->output_section
->vma
2241 + plt
->output_offset
2243 loc
= (htab
->elf
.srelplt
->contents
2244 + plt_index
* sizeof (Elf32_External_Rela
));
2247 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
2248 if (! h
->def_regular
)
2250 /* Mark the symbol as undefined, rather than as defined in
2251 the .plt section. Leave the value alone. */
2252 sym
->st_shndx
= SHN_UNDEF
;
2253 /* If the symbol is weak, we do need to clear the value.
2254 Otherwise, the PLT entry would provide a definition for
2255 the symbol even if the symbol wasn't defined anywhere,
2256 and so the symbol would never be NULL. Leave the value if
2257 there were any relocations where pointer equality matters
2258 (this is a clue for the dynamic linker, to make function
2259 pointer comparisons work between an application and shared
2261 if (!h
->ref_regular_nonweak
|| !h
->pointer_equality_needed
)
2266 /* Fill in the entry in the .got section. */
2267 if (h
->got
.offset
!= (bfd_vma
) -1
2268 && ((csky_elf_hash_entry (h
)->tls_type
& GOT_TLS_GD
) == 0)
2269 && ((csky_elf_hash_entry (h
)->tls_type
& GOT_TLS_IE
) == 0))
2271 Elf_Internal_Rela rel
;
2274 /* This symbol has an entry in the global offset table.
2276 BFD_ASSERT (htab
->elf
.sgot
!= NULL
&& htab
->elf
.srelgot
!= NULL
);
2278 rel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
2279 + htab
->elf
.sgot
->output_offset
2280 + (h
->got
.offset
& ~(bfd_vma
) 1));
2282 /* If this is a static link, or it is a -Bsymbolic link and the
2283 symbol is defined locally or was forced to be local because
2284 of a version file, we just want to emit a RELATIVE reloc.
2285 The entry in the global offset table will already have been
2286 initialized in the relocate_section function. */
2287 if (bfd_link_pic (info
) && SYMBOL_REFERENCES_LOCAL (info
, h
))
2289 BFD_ASSERT ((h
->got
.offset
& 1) != 0);
2290 rel
.r_info
= ELF32_R_INFO (0, R_CKCORE_RELATIVE
);
2291 rel
.r_addend
= (h
->root
.u
.def
.value
2292 + h
->root
.u
.def
.section
->output_offset
2293 + h
->root
.u
.def
.section
->output_section
->vma
);
2297 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
2298 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
2299 htab
->elf
.sgot
->contents
+ h
->got
.offset
);
2300 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_CKCORE_GLOB_DAT
);
2304 loc
= htab
->elf
.srelgot
->contents
;
2305 loc
+= htab
->elf
.srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
2308 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
2314 Elf_Internal_Rela rela
;
2317 /* This symbol needs a copy reloc. Set it up. */
2318 BFD_ASSERT (h
->dynindx
!= -1
2319 && (h
->root
.type
== bfd_link_hash_defined
2320 || h
->root
.type
== bfd_link_hash_defweak
));
2322 rela
.r_offset
= (h
->root
.u
.def
.value
2323 + h
->root
.u
.def
.section
->output_section
->vma
2324 + h
->root
.u
.def
.section
->output_offset
);
2325 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_CKCORE_COPY
);
2327 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
2328 s
= htab
->elf
.sreldynrelro
;
2330 s
= htab
->elf
.srelbss
;
2331 BFD_ASSERT (s
!= NULL
);
2332 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
2333 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
2336 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
2337 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
2338 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2339 sym
->st_shndx
= SHN_ABS
;
2344 /* Finish up the dynamic sections. */
2347 csky_elf_finish_dynamic_sections (bfd
*output_bfd
,
2348 struct bfd_link_info
*info
)
2350 struct csky_elf_link_hash_table
*htab
;
2355 htab
= csky_elf_hash_table (info
);
2359 dynobj
= htab
->elf
.dynobj
;
2360 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2362 if (htab
->elf
.dynamic_sections_created
)
2364 Elf32_External_Dyn
*dyncon
, *dynconend
;
2366 BFD_ASSERT (sdyn
!= NULL
&& htab
->elf
.sgot
!= NULL
);
2368 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
2369 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
2370 for (; dyncon
< dynconend
; dyncon
++)
2372 Elf_Internal_Dyn dyn
;
2373 bfd_boolean size
= FALSE
;
2374 const char *name
= NULL
;
2376 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2394 dyn
.d_un
.d_ptr
= htab
->elf
.sgot
->output_section
->vma
;
2397 dyn
.d_un
.d_ptr
= htab
->elf
.srelplt
->output_section
->vma
2398 + htab
->elf
.srelplt
->output_offset
;
2404 asection
*s
= bfd_get_section_by_name (output_bfd
, name
);
2409 dyn
.d_un
.d_ptr
= s
->vma
;
2411 dyn
.d_un
.d_val
= s
->size
;
2413 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2417 /* Fill in the first three entries in the global offset table. */
2418 if (htab
->elf
.sgotplt
)
2419 got_sec
= htab
->elf
.sgotplt
;
2421 got_sec
= htab
->elf
.sgot
;
2422 if (got_sec
!= NULL
)
2424 if (got_sec
->size
> 0)
2426 bfd_put_32 (output_bfd
,
2427 (sdyn
== NULL
? (bfd_vma
) 0
2428 : sdyn
->output_section
->vma
+ sdyn
->output_offset
),
2430 bfd_put_32 (output_bfd
, (bfd_vma
) 0, got_sec
->contents
+ 4);
2431 bfd_put_32 (output_bfd
, (bfd_vma
) 0, got_sec
->contents
+ 8);
2433 elf_section_data (got_sec
->output_section
)->this_hdr
.sh_entsize
= 4;
2438 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2441 csky_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
2442 struct elf_link_hash_entry
*dir
,
2443 struct elf_link_hash_entry
*ind
)
2445 struct csky_elf_link_hash_entry
*edir
, *eind
;
2447 edir
= (struct csky_elf_link_hash_entry
*) dir
;
2448 eind
= (struct csky_elf_link_hash_entry
*) ind
;
2450 if (ind
->root
.type
== bfd_link_hash_indirect
2451 && dir
->got
.refcount
<= 0)
2453 edir
->tls_type
= eind
->tls_type
;
2454 eind
->tls_type
= GOT_UNKNOWN
;
2456 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
2459 /* Used to decide how to sort relocs in an optimal manner for the
2460 dynamic linker, before writing them out. */
2462 static enum elf_reloc_type_class
2463 csky_elf_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2464 const asection
*rel_sec ATTRIBUTE_UNUSED
,
2465 const Elf_Internal_Rela
*rela
)
2467 switch ((int) ELF32_R_TYPE (rela
->r_info
))
2469 case R_CKCORE_RELATIVE
:
2470 return reloc_class_relative
;
2471 case R_CKCORE_JUMP_SLOT
:
2472 return reloc_class_plt
;
2474 return reloc_class_copy
;
2475 case R_CKCORE_IRELATIVE
:
2476 return reloc_class_ifunc
;
2478 return reloc_class_normal
;
2482 /* Return the section that should be marked against GC for a given
2486 csky_elf_gc_mark_hook (asection
*sec
,
2487 struct bfd_link_info
*info
,
2488 Elf_Internal_Rela
*rel
,
2489 struct elf_link_hash_entry
*h
,
2490 Elf_Internal_Sym
*sym
)
2494 switch (ELF32_R_TYPE (rel
->r_info
))
2496 case R_CKCORE_GNU_VTINHERIT
:
2497 case R_CKCORE_GNU_VTENTRY
:
2502 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
2505 /* Look through the relocs for a section during the first phase.
2506 Since we don't do .gots or .plts, we just need to consider the
2507 virtual table relocs for gc. */
2510 csky_elf_check_relocs (bfd
* abfd
,
2511 struct bfd_link_info
* info
,
2513 const Elf_Internal_Rela
* relocs
)
2515 Elf_Internal_Shdr
* symtab_hdr
;
2516 struct elf_link_hash_entry
** sym_hashes
;
2517 const Elf_Internal_Rela
* rel
;
2518 const Elf_Internal_Rela
* rel_end
;
2519 struct csky_elf_link_hash_table
*htab
;
2522 /* if output type is relocatable, return. */
2523 if (bfd_link_relocatable (info
))
2526 htab
= csky_elf_hash_table (info
);
2530 symtab_hdr
= & elf_tdata (abfd
)->symtab_hdr
;
2531 sym_hashes
= elf_sym_hashes (abfd
);
2533 rel_end
= relocs
+ sec
->reloc_count
;
2535 for (rel
= relocs
; rel
< rel_end
; rel
++)
2537 struct elf_link_hash_entry
*h
;
2538 unsigned long r_symndx
;
2539 Elf_Internal_Sym
*isym
;
2542 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2543 r_type
= ELF32_R_TYPE (rel
->r_info
);
2544 if (r_symndx
< symtab_hdr
->sh_info
)
2546 /* A local symbol. */
2547 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2556 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2557 while (h
->root
.type
== bfd_link_hash_indirect
2558 || h
->root
.type
== bfd_link_hash_warning
)
2559 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2564 case R_CKCORE_PCREL_IMM26BY2
:
2565 case R_CKCORE_PCREL_IMM11BY2
:
2566 case R_CKCORE_PCREL_JSR_IMM11BY2
:
2567 case R_CKCORE_PCREL_JSR_IMM26BY2
:
2568 /* If the symbol is '*UND*', means this reloc is used for
2569 * callgraph, don't need to leave to shared object. */
2572 /* Else fall through. */
2573 case R_CKCORE_ADDR32
:
2574 case R_CKCORE_ADDR_HI16
:
2575 case R_CKCORE_ADDR_LO16
:
2577 && bfd_link_executable (info
)
2578 && r_type
== R_CKCORE_ADDR32
2579 && h
->type
== STT_OBJECT
2580 && (sec
->flags
& SEC_ALLOC
) != 0
2581 && (sec
->flags
& SEC_READONLY
))
2582 /* If this reloc is in a read-only section, we might
2583 need a copy reloc. We can't check reliably at this
2584 stage whether the section is read-only, as input
2585 sections have not yet been mapped to output sections.
2586 Tentatively set the flag for now, and correct in
2587 adjust_dynamic_symbol. */
2590 /* If we are creating a shared library or relocatable executable,
2591 and this is a reloc against a global symbol, then we need to
2592 copy the reloc into the shared library. However, if we are
2593 linking with -Bsymbolic, we do not need to copy a reloc
2594 against a global symbol which is defined in an object we are
2595 including in the link (i.e., DEF_REGULAR is set). At
2596 this point we have not seen all the input files, so it is
2597 possible that DEF_REGULAR is not set now but will be set
2598 later (it is never cleared). We account for that possibility
2599 below by storing information in the relocs_copied field of
2600 the hash table entry. */
2601 if ((bfd_link_pic (info
) && (sec
->flags
& SEC_ALLOC
) != 0)
2602 || (!bfd_link_pic (info
)
2603 && (sec
->flags
& SEC_ALLOC
) != 0
2605 && (h
->root
.type
== bfd_link_hash_defweak
2606 || !h
->def_regular
)))
2608 struct elf_dyn_relocs
*p
;
2609 struct elf_dyn_relocs
**head
;
2610 /* We must copy these reloc types into the output file.
2611 Create a reloc section in dynobj and make room for
2615 if (htab
->elf
.dynobj
== NULL
)
2616 htab
->elf
.dynobj
= abfd
;
2618 sreloc
= _bfd_elf_make_dynamic_reloc_section
2619 (sec
, htab
->elf
.dynobj
, 2, abfd
, TRUE
);
2625 if (h
== NULL
&& !use_branch_stub
2626 && ((ELF32_R_TYPE (rel
->r_info
)
2627 == R_CKCORE_PCREL_IMM26BY2
)
2628 || (ELF32_R_TYPE (rel
->r_info
)
2629 == R_CKCORE_PCREL_IMM11BY2
)))
2632 /* If this is a global symbol, we count the number of
2633 relocations we need for this symbol. */
2636 struct csky_elf_link_hash_entry
*eh
;
2637 eh
= (struct csky_elf_link_hash_entry
*)h
;
2638 if ((ELF32_R_TYPE (rel
->r_info
)
2639 == R_CKCORE_PCREL_JSR_IMM26BY2
)
2640 || (ELF32_R_TYPE (rel
->r_info
)
2641 == R_CKCORE_PCREL_JSR_IMM11BY2
))
2642 eh
->jsri2bsr_refcount
+= 1;
2643 head
= &h
->dyn_relocs
;
2647 /* Track dynamic relocs needed for local syms too.
2648 We really need local syms available to do this
2652 Elf_Internal_Sym
*loc_isym
;
2654 loc_isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
2656 if (loc_isym
== NULL
)
2658 s
= bfd_section_from_elf_index (abfd
, loc_isym
->st_shndx
);
2661 vpp
= &elf_section_data (s
)->local_dynrel
;
2662 head
= (struct elf_dyn_relocs
**)vpp
;
2666 if (p
== NULL
|| p
->sec
!= sec
)
2668 size_t amt
= sizeof *p
;
2669 p
= ((struct elf_dyn_relocs
*)
2670 bfd_alloc (htab
->elf
.dynobj
, amt
));
2680 if (ELF32_R_TYPE (rel
->r_info
) == R_CKCORE_PCREL_IMM26BY2
2681 || ELF32_R_TYPE (rel
->r_info
) == R_CKCORE_PCREL_IMM11BY2
)
2687 case R_CKCORE_PLT_IMM18BY4
:
2688 case R_CKCORE_PLT32
:
2689 /* This symbol requires a procedure linkage table entry. We
2690 actually build the entry in adjust_dynamic_symbol,
2691 because this might be a case of linking PIC code which is
2692 never referenced by a dynamic object, in which case we
2693 don't need to generate a procedure linkage table entry
2696 /* If this is a local symbol, we resolve it directly without
2697 creating a procedure linkage table entry. */
2700 if (ELF32_R_TYPE (rel
->r_info
) == R_CKCORE_PLT_IMM18BY4
)
2701 check_got_overflow
= 1;
2704 h
->plt
.refcount
+= 1;
2705 h
->got
.refcount
+= 1;
2706 ((struct csky_elf_link_hash_entry
*)h
)->plt_refcount
+= 1;
2709 case R_CKCORE_GOT12
:
2710 case R_CKCORE_PLT12
:
2711 case R_CKCORE_GOT32
:
2712 case R_CKCORE_GOT_HI16
:
2713 case R_CKCORE_GOT_LO16
:
2714 case R_CKCORE_PLT_HI16
:
2715 case R_CKCORE_PLT_LO16
:
2716 case R_CKCORE_GOT_IMM18BY4
:
2717 case R_CKCORE_TLS_IE32
:
2718 case R_CKCORE_TLS_GD32
:
2720 int tls_type
, old_tls_type
;
2723 && bfd_link_executable (info
)
2724 && r_type
== R_CKCORE_GOT_IMM18BY4
2725 && (sec
->flags
& SEC_ALLOC
) != 0
2726 && (sec
->flags
& SEC_READONLY
))
2727 /* If this reloc is in a read-only section, we might
2728 need a copy reloc. We can't check reliably at this
2729 stage whether the section is read-only, as input
2730 sections have not yet been mapped to output sections.
2731 Tentatively set the flag for now, and correct in
2732 adjust_dynamic_symbol. */
2735 switch (ELF32_R_TYPE (rel
->r_info
))
2737 case R_CKCORE_TLS_IE32
:
2738 tls_type
= GOT_TLS_IE
;
2740 case R_CKCORE_TLS_GD32
:
2741 tls_type
= GOT_TLS_GD
;
2744 tls_type
= GOT_NORMAL
;
2749 if (ELF32_R_TYPE (rel
->r_info
) == R_CKCORE_GOT_IMM18BY4
)
2750 check_got_overflow
= 1;
2751 h
->got
.refcount
+= 1;
2752 old_tls_type
= csky_elf_hash_entry (h
)->tls_type
;
2756 bfd_signed_vma
*local_got_refcounts
;
2758 /* This is a global offset table entry for a local symbol. */
2759 /* we can write a new function named
2760 elf32_csky_allocate_local_sym_info() to replace
2762 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2763 if (local_got_refcounts
== NULL
)
2767 size
= symtab_hdr
->sh_info
;
2768 size
*= (sizeof (bfd_signed_vma
) + sizeof (char));
2769 local_got_refcounts
= ((bfd_signed_vma
*)
2770 bfd_zalloc (abfd
, size
));
2771 if (local_got_refcounts
== NULL
)
2773 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2774 csky_elf_local_got_tls_type (abfd
)
2775 = (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
2777 local_got_refcounts
[r_symndx
] += 1;
2778 old_tls_type
= csky_elf_local_got_tls_type (abfd
)[r_symndx
];
2781 /* We will already have issued an error message if there is a
2782 TLS / non-TLS mismatch, based on the symbol type. We don't
2783 support any linker relaxations. So just combine any TLS
2785 if (old_tls_type
!= GOT_UNKNOWN
&& old_tls_type
!= GOT_NORMAL
2786 && tls_type
!= GOT_NORMAL
)
2787 tls_type
|= old_tls_type
;
2789 if (old_tls_type
!= tls_type
)
2792 csky_elf_hash_entry (h
)->tls_type
= tls_type
;
2794 csky_elf_local_got_tls_type (abfd
)[r_symndx
] = tls_type
;
2799 case R_CKCORE_TLS_LDM32
:
2800 if (ELF32_R_TYPE (rel
->r_info
) == R_CKCORE_TLS_LDM32
)
2801 htab
->tls_ldm_got
.refcount
++;
2804 case R_CKCORE_GOTOFF
:
2805 case R_CKCORE_GOTPC
:
2806 case R_CKCORE_GOTOFF_HI16
:
2807 case R_CKCORE_GOTOFF_LO16
:
2808 case R_CKCORE_GOTPC_HI16
:
2809 case R_CKCORE_GOTPC_LO16
:
2810 case R_CKCORE_GOTOFF_IMM18
:
2811 if (htab
->elf
.sgot
== NULL
)
2813 if (htab
->elf
.dynobj
== NULL
)
2814 htab
->elf
.dynobj
= abfd
;
2815 if (!_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
2820 /* This relocation describes the C++ object vtable hierarchy.
2821 Reconstruct it for later use during GC. */
2822 case R_CKCORE_GNU_VTINHERIT
:
2823 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2827 /* This relocation describes which C++ vtable entries are actually
2828 used. Record for later use during GC. */
2829 case R_CKCORE_GNU_VTENTRY
:
2830 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2839 static const struct bfd_elf_special_section csky_elf_special_sections
[]=
2841 { STRING_COMMA_LEN (".ctors"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2842 { STRING_COMMA_LEN (".dtors"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2843 { NULL
, 0, 0, 0, 0 }
2846 /* Function to keep CSKY specific flags in the ELF header. */
2849 csky_elf_set_private_flags (bfd
* abfd
, flagword flags
)
2851 BFD_ASSERT (! elf_flags_init (abfd
)
2852 || elf_elfheader (abfd
)->e_flags
== flags
);
2854 elf_elfheader (abfd
)->e_flags
= flags
;
2855 elf_flags_init (abfd
) = TRUE
;
2859 static csky_arch_for_merge
*
2860 csky_find_arch_with_eflag (const unsigned long arch_eflag
)
2862 csky_arch_for_merge
*csky_arch
= NULL
;
2864 for (csky_arch
= csky_archs
; csky_arch
->name
!= NULL
; csky_arch
++)
2865 if (csky_arch
->arch_eflag
== arch_eflag
)
2867 if (csky_arch
== NULL
)
2869 _bfd_error_handler (_("warning: unrecognized arch eflag '%#lx'"),
2871 bfd_set_error (bfd_error_wrong_format
);
2876 /* Merge backend specific data from an object file to the output
2877 object file when linking. */
2880 csky_elf_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
2882 bfd
*obfd
= info
->output_bfd
;
2885 csky_arch_for_merge
*old_arch
= NULL
;
2886 csky_arch_for_merge
*new_arch
= NULL
;
2888 /* Check if we have the same endianness. */
2889 if (! _bfd_generic_verify_endian_match (ibfd
, info
))
2892 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2893 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2896 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2897 old_flags
= elf_elfheader (obfd
)->e_flags
;
2899 if (! elf_flags_init (obfd
))
2901 /* First call, no flags set. */
2902 elf_flags_init (obfd
) = TRUE
;
2903 elf_elfheader (obfd
)->e_flags
= new_flags
;
2905 else if (new_flags
== old_flags
)
2908 else if (new_flags
== 0 || old_flags
== 0)
2909 /* When one flag is 0, assign the other one's flag. */
2910 elf_elfheader (obfd
)->e_flags
= new_flags
| old_flags
;
2913 flagword newest_flag
= 0;
2915 if ((new_flags
& CSKY_ARCH_MASK
) != 0
2916 && (old_flags
& CSKY_ARCH_MASK
) != 0)
2918 new_arch
= csky_find_arch_with_eflag (new_flags
& CSKY_ARCH_MASK
);
2919 old_arch
= csky_find_arch_with_eflag (old_flags
& CSKY_ARCH_MASK
);
2920 /* Collect flags like e, f, g. */
2921 newest_flag
= (old_flags
& (~CSKY_ARCH_MASK
))
2922 | (new_flags
& (~CSKY_ARCH_MASK
));
2923 if (new_arch
!= NULL
&& old_arch
!= NULL
)
2925 if (new_arch
->class != old_arch
->class)
2928 /* xgettext:c-format */
2929 (_("%pB: machine flag conflict with target"), ibfd
);
2930 bfd_set_error (bfd_error_wrong_format
);
2933 else if (new_arch
->class_level
!= old_arch
->class_level
)
2935 csky_arch_for_merge
*newest_arch
2936 = (new_arch
->class_level
> old_arch
->class_level
2937 ? new_arch
: old_arch
);
2938 if (new_arch
->do_warning
|| old_arch
->do_warning
)
2941 /* xgettext:c-format */
2942 (_("warning: file %pB's arch flag ck%s conflicts with "
2943 "target ck%s, using ck%s"),
2944 ibfd
, new_arch
->name
, old_arch
->name
,
2946 bfd_set_error (bfd_error_wrong_format
);
2949 newest_flag
|= newest_arch
->arch_eflag
;
2952 newest_flag
|= ((new_flags
& (CSKY_ARCH_MASK
| CSKY_ABI_MASK
))
2954 & (CSKY_ARCH_MASK
| CSKY_ABI_MASK
)));
2957 newest_flag
|= ((new_flags
& (CSKY_ARCH_MASK
| CSKY_ABI_MASK
))
2958 | (old_flags
& (CSKY_ARCH_MASK
| CSKY_ABI_MASK
)));
2961 newest_flag
|= ((new_flags
& (CSKY_ARCH_MASK
| CSKY_ABI_MASK
))
2962 | (old_flags
& (CSKY_ARCH_MASK
| CSKY_ABI_MASK
)));
2964 elf_elfheader (obfd
)->e_flags
= newest_flag
;
2969 /* Ignore the discarded relocs in special sections in link time. */
2972 csky_elf_ignore_discarded_relocs (asection
*sec
)
2974 if (strcmp (sec
->name
, ".csky_stack_size") == 0)
2979 /* .csky_stack_size are not referenced directly. This pass marks all of
2980 them as required. */
2983 elf32_csky_gc_mark_extra_sections (struct bfd_link_info
*info
,
2984 elf_gc_mark_hook_fn gc_mark_hook ATTRIBUTE_UNUSED
)
2988 _bfd_elf_gc_mark_extra_sections (info
, gc_mark_hook
);
2990 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link
.next
)
2994 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
2995 if (strcmp (o
->name
, ".csky_stack_size") == 0)
3002 /* The linker repeatedly calls this function for each input section,
3003 in the order that input sections are linked into output sections.
3004 Build lists of input sections to determine groupings between which
3005 we may insert linker stubs. */
3008 elf32_csky_next_input_section (struct bfd_link_info
*info
,
3011 struct csky_elf_link_hash_table
*htab
= csky_elf_hash_table (info
);
3014 if (isec
->output_section
->index
<= htab
->top_index
)
3016 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
3018 if (*list
!= bfd_abs_section_ptr
)
3020 /* Steal the link_sec pointer for our list. */
3021 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
3022 /* This happens to make the list in reverse order,
3023 which we reverse later in group_sections. */
3024 PREV_SEC (isec
) = *list
;
3030 /* See whether we can group stub sections together. Grouping stub
3031 sections may result in fewer stubs. More importantly, we need to
3032 put all .init* and .fini* stubs at the end of the .init or
3033 .fini output sections respectively, because glibc splits the
3034 _init and _fini functions into multiple parts. Putting a stub in
3035 the middle of a function is not a good idea. */
3038 group_sections (struct csky_elf_link_hash_table
*htab
,
3039 bfd_size_type stub_group_size
,
3040 bfd_boolean stubs_always_after_branch
)
3042 asection
**list
= htab
->input_list
;
3046 asection
*tail
= *list
;
3049 if (tail
== bfd_abs_section_ptr
)
3052 /* Reverse the list: we must avoid placing stubs at the
3053 beginning of the section because the beginning of the text
3054 section may be required for an interrupt vector in bare metal
3056 #define NEXT_SEC PREV_SEC
3058 while (tail
!= NULL
)
3060 /* Pop from tail. */
3061 asection
*item
= tail
;
3062 tail
= PREV_SEC (item
);
3065 NEXT_SEC (item
) = head
;
3069 while (head
!= NULL
)
3073 bfd_vma stub_group_start
= head
->output_offset
;
3074 bfd_vma end_of_next
;
3077 while (NEXT_SEC (curr
) != NULL
)
3079 next
= NEXT_SEC (curr
);
3080 end_of_next
= next
->output_offset
+ next
->size
;
3081 if (end_of_next
- stub_group_start
>= stub_group_size
)
3082 /* End of NEXT is too far from start, so stop. */
3087 /* OK, the size from the start to the start of CURR is less
3088 * than stub_group_size and thus can be handled by one stub
3089 * section. (Or the head section is itself larger than
3090 * stub_group_size, in which case we may be toast.)
3091 * We should really be keeping track of the total size of
3092 * stubs added here, as stubs contribute to the final output
3096 next
= NEXT_SEC (head
);
3097 /* Set up this stub group. */
3098 htab
->stub_group
[head
->id
].link_sec
= curr
;
3100 while (head
!= curr
&& (head
= next
) != NULL
);
3102 /* But wait, there's more! Input sections up to stub_group_size
3103 * bytes after the stub section can be handled by it too. */
3104 if (!stubs_always_after_branch
)
3106 stub_group_start
= curr
->output_offset
+ curr
->size
;
3108 while (next
!= NULL
)
3110 end_of_next
= next
->output_offset
+ next
->size
;
3111 if (end_of_next
- stub_group_start
>= stub_group_size
)
3112 /* End of NEXT is too far from stubs, so stop. */
3114 /* Add NEXT to the stub group. */
3116 next
= NEXT_SEC (head
);
3117 htab
->stub_group
[head
->id
].link_sec
= curr
;
3123 while (list
++ != htab
->input_list
+ htab
->top_index
);
3125 free (htab
->input_list
);
3130 /* If the symbol referenced by bsr is defined in shared object file,
3131 or it is a weak symbol and we aim to create shared object file,
3132 we must create a stub for this bsr. */
3135 sym_must_create_stub (struct elf_link_hash_entry
*h
,
3136 struct bfd_link_info
*info
)
3139 && ((h
->def_dynamic
&& !h
->def_regular
)
3140 || (bfd_link_pic (info
) && h
->root
.type
== bfd_link_hash_defweak
)))
3146 /* Calculate the template, template size and instruction size for a stub.
3147 Return value is the instruction size. */
3150 find_stub_size_and_template (enum elf32_csky_stub_type stub_type
,
3151 const insn_sequence
**stub_template
,
3152 int *stub_template_size
)
3154 const insn_sequence
*template_sequence
= NULL
;
3155 int template_size
= 0;
3159 template_sequence
= stub_definitions
[stub_type
].template_sequence
;
3160 template_size
= stub_definitions
[stub_type
].template_size
;
3163 for (i
= 0; i
< template_size
; i
++)
3165 switch (template_sequence
[i
].type
)
3183 *stub_template
= template_sequence
;
3184 if (stub_template_size
)
3185 *stub_template_size
= template_size
;
3190 /* As above, but don't actually build the stub. Just bump offset so
3191 we know stub section sizes. */
3194 csky_size_one_stub (struct bfd_hash_entry
*gen_entry
,
3195 void * in_arg ATTRIBUTE_UNUSED
)
3197 struct elf32_csky_stub_hash_entry
*stub_entry
;
3198 const insn_sequence
*template_sequence
= NULL
;
3199 int template_size
= 0;
3202 /* Massage our args to the form they really have. */
3203 stub_entry
= (struct elf32_csky_stub_hash_entry
*) gen_entry
;
3205 BFD_ASSERT (stub_entry
->stub_type
> csky_stub_none
3206 && stub_entry
->stub_type
< ARRAY_SIZE (stub_definitions
));
3207 size
= find_stub_size_and_template (stub_entry
->stub_type
,
3208 &template_sequence
, &template_size
);
3209 stub_entry
->stub_size
= size
;
3210 stub_entry
->stub_template
= template_sequence
;
3211 stub_entry
->stub_template_size
= template_size
;
3213 size
= (size
+ 7) & ~7;
3214 stub_entry
->stub_sec
->size
+= size
;
3218 /* Add a new stub entry to the stub hash. Not all fields of the new
3219 stub entry are initialised. */
3221 static struct elf32_csky_stub_hash_entry
*
3222 elf32_csky_add_stub (const char *stub_name
,
3224 struct csky_elf_link_hash_table
*htab
)
3228 struct elf32_csky_stub_hash_entry
*stub_entry
;
3230 stub_sec
= elf32_csky_create_or_find_stub_sec (&link_sec
, section
, htab
);
3231 if (stub_sec
== NULL
)
3234 /* Enter this entry into the linker stub hash table. */
3235 stub_entry
= csky_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3237 if (stub_entry
== NULL
)
3239 _bfd_error_handler (_("%pB: cannot create stub entry %s"),
3240 section
->owner
, stub_name
);
3244 stub_entry
->stub_sec
= stub_sec
;
3245 stub_entry
->stub_offset
= 0;
3246 stub_entry
->id_sec
= link_sec
;
3251 /* Determine and set the size of the stub section for a final link.
3252 The basic idea here is to examine all the relocations looking for
3253 PC-relative calls to a target that is unreachable with a "bsr"
3257 elf32_csky_size_stubs (bfd
*output_bfd
,
3259 struct bfd_link_info
*info
,
3260 bfd_signed_vma group_size
,
3261 asection
*(*add_stub_section
) (const char*, asection
*),
3262 void (*layout_sections_again
) (void))
3264 bfd_size_type stub_group_size
;
3265 bfd_boolean stubs_always_after_branch
;
3266 struct csky_elf_link_hash_table
*htab
= csky_elf_hash_table (info
);
3271 /* Propagate mach to stub bfd, because it may not have been
3272 finalized when we created stub_bfd. */
3273 bfd_set_arch_mach (stub_bfd
, bfd_get_arch (output_bfd
),
3274 bfd_get_mach (output_bfd
));
3276 /* Stash our params away. */
3277 htab
->stub_bfd
= stub_bfd
;
3278 htab
->add_stub_section
= add_stub_section
;
3279 htab
->layout_sections_again
= layout_sections_again
;
3280 stubs_always_after_branch
= group_size
< 0;
3283 stub_group_size
= -group_size
;
3285 stub_group_size
= group_size
;
3287 if (stub_group_size
== 1)
3288 /* The 'bsr' range in abiv2 is +-64MB has to be used as the
3289 default maximum size.
3290 This value is 128K less than that, which allows for 131072
3291 byte stubs. If we exceed that, then we will fail to link.
3292 The user will have to relink with an explicit group size
3294 stub_group_size
= 66977792;
3296 group_sections (htab
, stub_group_size
, stubs_always_after_branch
);
3301 unsigned int bfd_indx
;
3303 bfd_boolean stub_changed
= FALSE
;
3305 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
3307 input_bfd
= input_bfd
->link
.next
, bfd_indx
++)
3309 Elf_Internal_Shdr
*symtab_hdr
;
3311 Elf_Internal_Sym
*local_syms
= NULL
;
3313 /* We'll need the symbol table in a second. */
3314 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3315 if (symtab_hdr
->sh_info
== 0)
3318 /* Walk over each section attached to the input bfd. */
3319 for (section
= input_bfd
->sections
;
3321 section
= section
->next
)
3323 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
3325 /* If there aren't any relocs, then there's nothing more
3327 if ((section
->flags
& SEC_RELOC
) == 0
3328 || section
->reloc_count
== 0
3329 || (section
->flags
& SEC_CODE
) == 0)
3332 /* If this section is a link-once section that will be
3333 discarded, then don't create any stubs. */
3334 if (section
->output_section
== NULL
3335 || section
->output_section
->owner
!= output_bfd
)
3338 /* Get the relocs. */
3339 internal_relocs
= _bfd_elf_link_read_relocs (input_bfd
,
3344 if (internal_relocs
== NULL
)
3345 goto error_ret_free_local
;
3347 /* Now examine each relocation. */
3348 irela
= internal_relocs
;
3349 irelaend
= irela
+ section
->reloc_count
;
3350 for (; irela
< irelaend
; irela
++)
3352 unsigned int r_type
, r_indx
;
3353 enum elf32_csky_stub_type stub_type
;
3354 struct elf32_csky_stub_hash_entry
*stub_entry
;
3357 bfd_vma destination
;
3358 struct csky_elf_link_hash_entry
*hash
;
3359 const char *sym_name
;
3361 const asection
*id_sec
;
3362 unsigned char st_type
;
3364 r_type
= ELF32_R_TYPE (irela
->r_info
);
3365 r_indx
= ELF32_R_SYM (irela
->r_info
);
3366 if (r_type
>= (unsigned int) R_CKCORE_MAX
)
3368 bfd_set_error (bfd_error_bad_value
);
3369 error_ret_free_internal
:
3370 if (elf_section_data (section
)->relocs
== NULL
)
3371 free (internal_relocs
);
3372 goto error_ret_free_local
;
3375 /* Only look for stubs on branch instructions. */
3376 if (r_type
!= (unsigned int) R_CKCORE_PCREL_IMM26BY2
)
3378 /* Now determine the call target, its name, value,
3385 if (r_indx
< symtab_hdr
->sh_info
)
3387 /* It's a local symbol. */
3388 Elf_Internal_Sym
*sym
;
3389 Elf_Internal_Shdr
*hdr
;
3390 if (local_syms
== NULL
)
3392 (Elf_Internal_Sym
*) symtab_hdr
->contents
;
3393 if (local_syms
== NULL
)
3396 bfd_elf_get_elf_syms (input_bfd
,
3398 symtab_hdr
->sh_info
,
3399 0, NULL
, NULL
, NULL
);
3400 if (local_syms
== NULL
)
3401 goto error_ret_free_internal
;
3403 sym
= local_syms
+ r_indx
;
3404 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
3405 sym_sec
= hdr
->bfd_section
;
3407 /* This is an undefined symbol. It can never
3410 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
3411 sym_value
= sym
->st_value
;
3412 destination
= (sym_value
+ irela
->r_addend
3413 + sym_sec
->output_offset
3414 + sym_sec
->output_section
->vma
);
3415 st_type
= ELF_ST_TYPE (sym
->st_info
);
3417 bfd_elf_string_from_elf_section (input_bfd
,
3418 symtab_hdr
->sh_link
,
3423 /* It's an external symbol. */
3425 e_indx
= r_indx
- symtab_hdr
->sh_info
;
3426 hash
= ((struct csky_elf_link_hash_entry
*)
3427 elf_sym_hashes (input_bfd
)[e_indx
]);
3429 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
3430 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
3431 hash
= ((struct csky_elf_link_hash_entry
*)
3432 hash
->elf
.root
.u
.i
.link
);
3433 if (hash
->elf
.root
.type
== bfd_link_hash_defined
3434 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
3436 sym_sec
= hash
->elf
.root
.u
.def
.section
;
3437 sym_value
= hash
->elf
.root
.u
.def
.value
;
3439 struct csky_elf_link_hash_table
*globals
=
3440 csky_elf_hash_table (info
);
3441 /* FIXME For a destination in a shared library. */
3442 if (globals
->elf
.splt
!= NULL
&& hash
!= NULL
3443 && hash
->elf
.plt
.offset
!= (bfd_vma
) -1)
3445 else if (sym_sec
->output_section
!= NULL
)
3446 destination
= (sym_value
+ irela
->r_addend
3447 + sym_sec
->output_offset
3448 + sym_sec
->output_section
->vma
);
3450 else if (hash
->elf
.root
.type
== bfd_link_hash_undefined
3451 || (hash
->elf
.root
.type
3452 == bfd_link_hash_undefweak
))
3453 /* FIXME For a destination in a shared library. */
3457 bfd_set_error (bfd_error_bad_value
);
3458 goto error_ret_free_internal
;
3460 st_type
= ELF_ST_TYPE (hash
->elf
.type
);
3461 sym_name
= hash
->elf
.root
.root
.string
;
3465 /* Determine what (if any) linker stub is needed. */
3466 stub_type
= csky_type_of_stub (info
, section
, irela
,
3468 destination
, sym_sec
,
3469 input_bfd
, sym_name
);
3470 if (stub_type
== csky_stub_none
)
3473 /* Support for grouping stub sections. */
3474 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
3476 /* Get the name of this stub. */
3477 stub_name
= elf32_csky_stub_name (id_sec
, sym_sec
, hash
,
3480 goto error_ret_free_internal
;
3481 /* We've either created a stub for this reloc already,
3482 or we are about to. */
3484 = csky_stub_hash_lookup (&htab
->stub_hash_table
,
3487 if (stub_entry
!= NULL
)
3489 /* The proper stub has already been created. */
3491 stub_entry
->target_value
= sym_value
;
3494 stub_entry
= elf32_csky_add_stub (stub_name
, section
,
3496 if (stub_entry
== NULL
)
3499 goto error_ret_free_internal
;
3501 stub_entry
->target_value
= sym_value
;
3502 stub_entry
->target_section
= sym_sec
;
3503 stub_entry
->stub_type
= stub_type
;
3504 stub_entry
->h
= hash
;
3505 stub_entry
->st_type
= st_type
;
3507 if (sym_name
== NULL
)
3508 sym_name
= "unnamed";
3509 stub_entry
->output_name
=
3510 bfd_alloc (htab
->stub_bfd
,
3511 (sizeof (STUB_ENTRY_NAME
)
3512 + strlen (sym_name
)));
3513 if (stub_entry
->output_name
== NULL
)
3516 goto error_ret_free_internal
;
3518 sprintf (stub_entry
->output_name
, STUB_ENTRY_NAME
,
3520 stub_changed
= TRUE
;
3524 /* We're done with the internal relocs, free them. */
3525 if (elf_section_data (section
)->relocs
== NULL
)
3526 free (internal_relocs
);
3531 /* OK, we've added some stubs. Find out the new size of the
3533 for (stub_sec
= htab
->stub_bfd
->sections
;
3535 stub_sec
= stub_sec
->next
)
3537 /* Ignore non-stub sections. */
3538 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
3542 bfd_hash_traverse (&htab
->stub_hash_table
, csky_size_one_stub
, htab
);
3543 /* Ask the linker to do its stuff. */
3544 (*htab
->layout_sections_again
) ();
3548 error_ret_free_local
:
3553 csky_build_one_stub (struct bfd_hash_entry
*gen_entry
,
3557 struct elf32_csky_stub_hash_entry
*stub_entry
;
3558 struct bfd_link_info
*info
;
3565 const insn_sequence
*template_sequence
;
3567 struct csky_elf_link_hash_table
* globals
;
3568 int stub_reloc_idx
[MAXRELOCS
] = {-1, -1};
3569 int stub_reloc_offset
[MAXRELOCS
] = {0, 0};
3571 struct elf_link_hash_entry
*h
= NULL
;
3573 /* Massage our args to the form they really have. */
3574 stub_entry
= (struct elf32_csky_stub_hash_entry
*)gen_entry
;
3575 info
= (struct bfd_link_info
*) in_arg
;
3577 /* Fail if the target section could not be assigned to an output
3578 section. The user should fix his linker script. */
3579 if (stub_entry
->target_section
->output_section
== NULL
3580 && info
->non_contiguous_regions
)
3581 info
->callbacks
->einfo (_("%F%P: Could not assign '%pA' to an output section. "
3582 "Retry without --enable-non-contiguous-regions.\n"),
3583 stub_entry
->target_section
);
3585 globals
= csky_elf_hash_table (info
);
3586 if (globals
== NULL
)
3588 stub_sec
= stub_entry
->stub_sec
;
3590 /* Make a note of the offset within the stubs for this entry. */
3591 stub_entry
->stub_offset
= stub_sec
->size
;
3592 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
3594 stub_bfd
= stub_sec
->owner
;
3596 /* This is the address of the stub destination. */
3597 h
= &stub_entry
->h
->elf
;
3598 if (sym_must_create_stub (h
, info
)
3599 && !(bfd_link_pic (info
)
3600 && h
->root
.type
== bfd_link_hash_defweak
3602 && !h
->def_dynamic
))
3605 sym_value
= (stub_entry
->target_value
3606 + stub_entry
->target_section
->output_offset
3607 + stub_entry
->target_section
->output_section
->vma
);
3609 template_sequence
= stub_entry
->stub_template
;
3610 template_size
= stub_entry
->stub_template_size
;
3613 for (i
= 0; i
< template_size
; i
++)
3614 switch (template_sequence
[i
].type
)
3617 bfd_put_16 (stub_bfd
, (bfd_vma
) template_sequence
[i
].data
,
3622 csky_put_insn_32 (stub_bfd
, (bfd_vma
) template_sequence
[i
].data
,
3627 bfd_put_32 (stub_bfd
, (bfd_vma
) template_sequence
[i
].data
,
3629 stub_reloc_idx
[nrelocs
] = i
;
3630 stub_reloc_offset
[nrelocs
++] = size
;
3637 stub_sec
->size
+= size
;
3639 /* Stub size has already been computed in csky_size_one_stub. Check
3641 BFD_ASSERT (size
== stub_entry
->stub_size
);
3643 /* Assume there is at least one and at most MAXRELOCS entries to relocate
3645 BFD_ASSERT (nrelocs
!= 0 && nrelocs
<= MAXRELOCS
);
3647 for (i
= 0; i
< nrelocs
; i
++)
3649 if (sym_must_create_stub (h
, info
))
3651 Elf_Internal_Rela outrel
;
3652 asection
* sreloc
= globals
->elf
.srelgot
;
3654 outrel
.r_offset
= stub_entry
->stub_offset
+ stub_reloc_offset
[i
];
3656 ELF32_R_INFO (h
->dynindx
,
3657 template_sequence
[stub_reloc_idx
[i
]].r_type
);
3658 outrel
.r_addend
= template_sequence
[stub_reloc_idx
[i
]].reloc_addend
;
3660 loc
= sreloc
->contents
;
3661 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
3664 bfd_elf32_swap_reloca_out (info
->output_bfd
, &outrel
, loc
);
3666 _bfd_final_link_relocate (elf32_csky_howto_from_type
3667 (template_sequence
[stub_reloc_idx
[i
]].r_type
),
3668 stub_bfd
, stub_sec
, stub_sec
->contents
,
3669 stub_entry
->stub_offset
+ stub_reloc_offset
[i
],
3670 sym_value
+ stub_entry
->target_addend
,
3671 template_sequence
[stub_reloc_idx
[i
]].reloc_addend
);
3678 /* Build all the stubs associated with the current output file. The
3679 stubs are kept in a hash table attached to the main linker hash
3680 table. We also set up the .plt entries for statically linked PIC
3681 functions here. This function is called via arm_elf_finish in the
3685 elf32_csky_build_stubs (struct bfd_link_info
*info
)
3688 struct bfd_hash_table
*table
;
3689 struct csky_elf_link_hash_table
*htab
;
3691 htab
= csky_elf_hash_table (info
);
3696 for (stub_sec
= htab
->stub_bfd
->sections
;
3698 stub_sec
= stub_sec
->next
)
3702 /* Ignore non-stub sections. */
3703 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
3706 /* Allocate memory to hold the linker stubs. */
3707 size
= stub_sec
->size
;
3708 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, size
);
3709 if (stub_sec
->contents
== NULL
&& size
!= 0)
3714 /* Build the stubs as directed by the stub hash table. */
3715 table
= &htab
->stub_hash_table
;
3716 bfd_hash_traverse (table
, csky_build_one_stub
, info
);
3721 /* Set up various things so that we can make a list of input sections
3722 for each output section included in the link. Returns -1 on error,
3723 0 when no stubs will be needed, and 1 on success. */
3726 elf32_csky_setup_section_lists (bfd
*output_bfd
,
3727 struct bfd_link_info
*info
)
3730 unsigned int bfd_count
;
3731 unsigned int top_id
, top_index
;
3733 asection
**input_list
, **list
;
3735 struct csky_elf_link_hash_table
*htab
= csky_elf_hash_table (info
);
3739 if (! is_elf_hash_table (htab
))
3742 /* Count the number of input BFDs and find the top input section id. */
3743 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
3745 input_bfd
= input_bfd
->link
.next
)
3748 for (section
= input_bfd
->sections
;
3750 section
= section
->next
)
3751 if (top_id
< section
->id
)
3752 top_id
= section
->id
;
3754 htab
->bfd_count
= bfd_count
;
3755 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
3756 htab
->stub_group
= bfd_zmalloc (amt
);
3757 if (htab
->stub_group
== NULL
)
3760 /* We can't use output_bfd->section_count here to find the top output
3761 section index as some sections may have been removed, and
3762 _bfd_strip_section_from_output doesn't renumber the indices. */
3763 for (section
= output_bfd
->sections
, top_index
= 0;
3765 section
= section
->next
)
3766 if (top_index
< section
->index
)
3767 top_index
= section
->index
;
3768 htab
->top_index
= top_index
;
3769 amt
= sizeof (asection
*) * (top_index
+ 1);
3770 input_list
= bfd_malloc (amt
);
3771 htab
->input_list
= input_list
;
3772 if (input_list
== NULL
)
3774 /* For sections we aren't interested in, mark their entries with a
3775 value we can check later. */
3776 list
= input_list
+ top_index
;
3778 *list
= bfd_abs_section_ptr
;
3779 while (list
-- != input_list
);
3780 for (section
= output_bfd
->sections
;
3782 section
= section
->next
)
3783 if ((section
->flags
& SEC_CODE
) != 0)
3784 input_list
[section
->index
] = NULL
;
3789 static bfd_reloc_status_type
3790 csky_relocate_contents (reloc_howto_type
*howto
,
3797 bfd_reloc_status_type flag
;
3798 unsigned int rightshift
= howto
->rightshift
;
3799 unsigned int bitpos
= howto
->bitpos
;
3801 /* If the size is negative, negate RELOCATION. This isn't very
3803 if (howto
->size
< 0)
3804 relocation
= -relocation
;
3806 /* FIXME: these macros should be defined at file head or head file head. */
3807 #define CSKY_INSN_ADDI_TO_SUBI 0x04000000
3808 #define CSKY_INSN_MOV_RTB 0xc41d4820 // mov32 rx, r29, 0
3809 #define CSKY_INSN_MOV_RDB 0xc41c4820 // mov32 rx, r28, 0
3810 #define CSKY_INSN_GET_ADDI_RZ(x) (((x) & 0x03e00000) >> 21)
3811 #define CSKY_INSN_SET_MOV_RZ(x) ((x) & 0x0000001f)
3812 #define CSKY_INSN_JSRI_TO_LRW 0xea9a0000
3813 #define CSKY_INSN_JSR_R26 0xe8fa0000
3815 /* Get the value we are going to relocate. */
3816 size
= bfd_get_reloc_size (howto
);
3823 x
= bfd_get_8 (input_bfd
, location
);
3826 x
= bfd_get_16 (input_bfd
, location
);
3829 if (need_reverse_bits
)
3831 x
= csky_get_insn_32 (input_bfd
, location
);
3833 if (R_CKCORE_DOFFSET_LO16
== howto
->type
)
3835 if ((signed) relocation
< 0)
3837 x
|= CSKY_INSN_ADDI_TO_SUBI
;
3838 relocation
= -relocation
;
3840 else if (0 == relocation
)
3841 x
= (CSKY_INSN_MOV_RDB
|
3842 CSKY_INSN_SET_MOV_RZ (CSKY_INSN_GET_ADDI_RZ (x
)));
3844 else if (R_CKCORE_TOFFSET_LO16
== howto
->type
)
3846 if ((signed) relocation
< 0)
3848 x
|= CSKY_INSN_ADDI_TO_SUBI
;
3849 relocation
= -relocation
;
3851 else if (0 == relocation
)
3852 x
= (CSKY_INSN_MOV_RTB
|
3853 CSKY_INSN_SET_MOV_RZ (CSKY_INSN_GET_ADDI_RZ (x
)));
3857 x
= bfd_get_32 (input_bfd
, location
);
3860 /* Check for overflow. FIXME: We may drop bits during the addition
3861 which we don't check for. We must either check at every single
3862 operation, which would be tedious, or we must do the computations
3863 in a type larger than bfd_vma, which would be inefficient. */
3864 flag
= bfd_reloc_ok
;
3865 if (howto
->complain_on_overflow
!= complain_overflow_dont
)
3874 /* Get the values to be added together. For signed and unsigned
3875 relocations, we assume that all values should be truncated to
3876 the size of an address. For bitfields, all the bits matter.
3877 See also bfd_check_overflow. */
3878 #define N_ONES(n) (((((bfd_vma) 1 << ((n) - 1)) - 1) << 1) | 1)
3879 fieldmask
= N_ONES (howto
->bitsize
);
3880 signmask
= ~fieldmask
;
3881 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
3882 a
= (relocation
& addrmask
) >> rightshift
;
3883 if (read_content_substitute
)
3884 x
= read_content_substitute
;
3885 b
= (x
& howto
->src_mask
& addrmask
) >> bitpos
;
3887 switch (howto
->complain_on_overflow
)
3889 case complain_overflow_signed
:
3890 /* If any sign bits are set, all sign bits must be set.
3891 That is, A must be a valid negative address after
3893 signmask
= ~(fieldmask
>> 1);
3896 case complain_overflow_bitfield
:
3897 /* Much like the signed check, but for a field one bit
3898 wider. We allow a bitfield to represent numbers in the
3899 range -2**n to 2**n-1, where n is the number of bits in the
3900 field. Note that when bfd_vma is 32 bits, a 32-bit reloc
3901 can't overflow, which is exactly what we want. */
3903 if (ss
!= 0 && ss
!= ((addrmask
>> rightshift
) & signmask
))
3904 flag
= bfd_reloc_overflow
;
3905 /* We only need this next bit of code if the sign bit of B
3906 is below the sign bit of A. This would only happen if
3907 SRC_MASK had fewer bits than BITSIZE. Note that if
3908 SRC_MASK has more bits than BITSIZE, we can get into
3909 trouble; we would need to verify that B is in range, as
3910 we do for A above. */
3911 ss
= ((~howto
->src_mask
) >> 1) & howto
->src_mask
;
3914 /* Set all the bits above the sign bit. */
3917 /* Now we can do the addition. */
3920 /* See if the result has the correct sign. Bits above the
3921 sign bit are junk now; ignore them. If the sum is
3922 positive, make sure we did not have all negative inputs;
3923 if the sum is negative, make sure we did not have all
3924 positive inputs. The test below looks only at the sign
3925 bits, and it really just
3926 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
3928 We mask with addrmask here to explicitly allow an address
3929 wrap-around. The Linux kernel relies on it, and it is
3930 the only way to write assembler code which can run when
3931 loaded at a location 0x80000000 away from the location at
3932 which it is linked. */
3934 if (((~(a
^ b
)) & (a
^ sum
)) & signmask
& addrmask
)
3935 flag
= bfd_reloc_overflow
;
3937 case complain_overflow_unsigned
:
3938 /* Checking for an unsigned overflow is relatively easy:
3939 trim the addresses and add, and trim the result as well.
3940 Overflow is normally indicated when the result does not
3941 fit in the field. However, we also need to consider the
3942 case when, e.g., fieldmask is 0x7fffffff or smaller, an
3943 input is 0x80000000, and bfd_vma is only 32 bits; then we
3944 will get sum == 0, but there is an overflow, since the
3945 inputs did not fit in the field. Instead of doing a
3946 separate test, we can check for this by or-ing in the
3947 operands when testing for the sum overflowing its final
3949 sum
= (a
+ b
) & addrmask
;
3950 if ((a
| b
| sum
) & signmask
)
3951 flag
= bfd_reloc_overflow
;
3958 /* Put RELOCATION in the right bits. */
3959 relocation
>>= (bfd_vma
) rightshift
;
3961 if ((howto
->type
== R_CKCORE_DOFFSET_LO16
3962 || howto
->type
== R_CKCORE_TOFFSET_LO16
)
3964 /* Do nothing lsli32 rx, rz, 0. */
3968 /* Fir V1, all this relocation must be x -1. */
3969 if (howto
->type
== R_CKCORE_PCREL_IMM11BY2
3970 || howto
->type
== R_CKCORE_PCREL_JSR_IMM11BY2
3971 || howto
->type
== R_CKCORE_DOFFSET_LO16
3972 || howto
->type
== R_CKCORE_TOFFSET_LO16
)
3974 else if (howto
->type
== R_CKCORE_PCREL_IMM7BY4
)
3975 relocation
= (relocation
& 0x1f) + ((relocation
<< 3) & 0x300);
3976 else if (howto
->type
== R_CKCORE_PCREL_FLRW_IMM8BY4
)
3978 = ((relocation
<< 4) & 0xf0) + ((relocation
<< 17) & 0x1e00000);
3979 else if (howto
->type
== R_CKCORE_NOJSRI
)
3981 x
= (x
& howto
->dst_mask
) | CSKY_INSN_JSRI_TO_LRW
;
3983 csky_put_insn_32 (input_bfd
, CSKY_INSN_JSR_R26
, location
+ 4);
3986 relocation
<<= (bfd_vma
) bitpos
;
3987 /* Add RELOCATION to the right bits of X. */
3988 x
= ((x
& ~howto
->dst_mask
)
3989 | (((x
& howto
->src_mask
) + relocation
) & howto
->dst_mask
));
3991 /* Put the relocated value back in the object file. */
3997 bfd_put_8 (input_bfd
, x
, location
);
4000 bfd_put_16 (input_bfd
, x
, location
);
4003 if (need_reverse_bits
)
4004 csky_put_insn_32 (input_bfd
, x
, location
);
4006 bfd_put_32 (input_bfd
, x
, location
);
4012 /* Look up an entry in the stub hash. Stub entries are cached because
4013 creating the stub name takes a bit of time. */
4015 static struct elf32_csky_stub_hash_entry
*
4016 elf32_csky_get_stub_entry (const asection
*input_section
,
4017 const asection
*sym_sec
,
4018 struct elf_link_hash_entry
*hash
,
4019 const Elf_Internal_Rela
*rel
,
4020 struct csky_elf_link_hash_table
*htab
)
4022 struct elf32_csky_stub_hash_entry
*stub_entry
;
4023 struct csky_elf_link_hash_entry
*h
4024 = (struct csky_elf_link_hash_entry
*) hash
;
4025 const asection
*id_sec
;
4027 if ((input_section
->flags
& SEC_CODE
) == 0)
4030 /* If this input section is part of a group of sections sharing one
4031 stub section, then use the id of the first section in the group.
4032 Stub names need to include a section id, as there may well be
4033 more than one stub used to reach say, printf, and we need to
4034 distinguish between them. */
4035 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
4036 if (h
!= NULL
&& h
->stub_cache
!= NULL
4037 && h
->stub_cache
->h
== h
&& h
->stub_cache
->id_sec
== id_sec
)
4038 stub_entry
= h
->stub_cache
;
4042 stub_name
= elf32_csky_stub_name (id_sec
, sym_sec
, h
, rel
);
4043 if (stub_name
== NULL
)
4045 stub_entry
= csky_stub_hash_lookup (&htab
->stub_hash_table
,
4046 stub_name
, FALSE
, FALSE
);
4048 h
->stub_cache
= stub_entry
;
4055 static bfd_reloc_status_type
4056 csky_final_link_relocate (reloc_howto_type
*howto
,
4058 asection
*input_section
,
4066 /* Sanity check the address. */
4067 if (address
> bfd_get_section_limit (input_bfd
, input_section
))
4068 return bfd_reloc_outofrange
;
4070 /* This function assumes that we are dealing with a basic relocation
4071 against a symbol. We want to compute the value of the symbol to
4072 relocate to. This is just VALUE, the value of the symbol,
4073 plus ADDEND, any addend associated with the reloc. */
4074 relocation
= value
+ addend
;
4076 /* If the relocation is PC relative, we want to set RELOCATION to
4077 the distance between the symbol (currently in RELOCATION) and the
4078 location we are relocating. Some targets (e.g., i386-aout)
4079 arrange for the contents of the section to be the negative of the
4080 offset of the location within the section; for such targets
4081 pcrel_offset is FALSE. Other targets (e.g., m88kbcs or ELF)
4082 simply leave the contents of the section as zero; for such
4083 targets pcrel_offset is TRUE. If pcrel_offset is FALSE we do not
4084 need to subtract out the offset of the location within the
4085 section (which is just ADDRESS). */
4086 if (howto
->pc_relative
)
4088 relocation
-= (input_section
->output_section
->vma
4089 + input_section
->output_offset
);
4090 if (howto
->pcrel_offset
)
4091 relocation
-= address
;
4094 return csky_relocate_contents (howto
, input_bfd
, relocation
,
4095 contents
+ address
);
4099 /* Return the base VMA address which should be subtracted from real addresses
4100 when resolving @dtpoff relocation.
4101 This is PT_TLS segment p_vaddr. */
4104 dtpoff_base (struct bfd_link_info
*info
)
4106 /* If tls_sec is NULL, we should have signalled an error already. */
4107 if (elf_hash_table (info
)->tls_sec
== NULL
)
4109 return elf_hash_table (info
)->tls_sec
->vma
;
4112 /* Return the relocation value for @tpoff relocation
4113 if STT_TLS virtual address is ADDRESS. */
4116 tpoff (struct bfd_link_info
*info
, bfd_vma address
)
4118 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
4121 /* If tls_sec is NULL, we should have signalled an error already. */
4122 if (htab
->tls_sec
== NULL
)
4124 base
= align_power ((bfd_vma
) TCB_SIZE
, htab
->tls_sec
->alignment_power
);
4125 return address
- htab
->tls_sec
->vma
+ base
;
4128 /* Relocate a csky section. */
4131 csky_elf_relocate_section (bfd
* output_bfd
,
4132 struct bfd_link_info
* info
,
4134 asection
* input_section
,
4135 bfd_byte
* contents
,
4136 Elf_Internal_Rela
* relocs
,
4137 Elf_Internal_Sym
* local_syms
,
4138 asection
** local_sections
)
4140 Elf_Internal_Shdr
*symtab_hdr
;
4141 struct elf_link_hash_entry
**sym_hashes
;
4142 Elf_Internal_Rela
*rel
;
4143 Elf_Internal_Rela
*relend
;
4145 bfd_boolean ret
= TRUE
;
4146 struct csky_elf_link_hash_table
* htab
;
4147 bfd_vma
*local_got_offsets
= elf_local_got_offsets (input_bfd
);
4149 htab
= csky_elf_hash_table (info
);
4153 symtab_hdr
= & elf_symtab_hdr (input_bfd
);
4154 sym_hashes
= elf_sym_hashes (input_bfd
);
4157 relend
= relocs
+ input_section
->reloc_count
;
4158 for (; rel
< relend
; rel
++)
4160 enum elf_csky_reloc_type r_type
4161 = (enum elf_csky_reloc_type
) ELF32_R_TYPE (rel
->r_info
);
4162 unsigned long r_symndx
;
4163 reloc_howto_type
* howto
;
4164 Elf_Internal_Sym
* sym
;
4168 struct elf_link_hash_entry
* h
;
4169 bfd_vma addend
= (bfd_vma
)rel
->r_addend
;
4170 bfd_reloc_status_type r
= bfd_reloc_ok
;
4171 bfd_boolean unresolved_reloc
= FALSE
;
4172 int do_final_relocate
= TRUE
;
4173 bfd_boolean relative_reloc
= FALSE
;
4174 bfd_signed_vma disp
;
4176 /* Ignore these relocation types:
4177 R_CKCORE_GNU_VTINHERIT, R_CKCORE_GNU_VTENTRY. */
4178 if (r_type
== R_CKCORE_GNU_VTINHERIT
|| r_type
== R_CKCORE_GNU_VTENTRY
)
4181 if ((unsigned) r_type
>= (unsigned) R_CKCORE_MAX
)
4183 /* The r_type is error, not support it. */
4184 /* xgettext:c-format */
4185 _bfd_error_handler (_("%pB: unsupported relocation type: %#x"),
4187 bfd_set_error (bfd_error_bad_value
);
4192 howto
= &csky_elf_howto_table
[(int) r_type
];
4194 r_symndx
= ELF32_R_SYM(rel
->r_info
);
4198 unresolved_reloc
= FALSE
;
4200 if (r_symndx
< symtab_hdr
->sh_info
)
4202 /* Get symbol table entry. */
4203 sym
= local_syms
+ r_symndx
;
4204 sec
= local_sections
[r_symndx
];
4205 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
4206 addend
= (bfd_vma
)rel
->r_addend
;
4210 bfd_boolean warned
, ignored
;
4212 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
4213 r_symndx
, symtab_hdr
, sym_hashes
,
4215 unresolved_reloc
, warned
, ignored
);
4218 if (sec
!= NULL
&& discarded_section (sec
))
4220 /* For relocs against symbols from removed linkonce sections,
4221 or sections discarded by a linker script, we just want the
4222 section contents zeroed. Avoid any special processing.
4223 And if the symbol is referenced in '.csky_stack_size' section,
4224 set the address to SEC_DISCARDED(0xffffffff). */
4226 /* The .csky_stack_size section is just for callgraph. */
4227 if (strcmp (input_section
->name
, ".csky_stack_size") == 0)
4229 /* FIXME: it should define in head file. */
4230 #define SEC_DISCARDED 0xffffffff
4231 bfd_put_32 (input_bfd
, SEC_DISCARDED
, contents
+ rel
->r_offset
);
4238 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
4239 rel
, 1, relend
, howto
, 0,
4243 if (bfd_link_relocatable (info
))
4246 read_content_substitute
= 0;
4250 + (bfd_signed_vma
) addend
4251 - input_section
->output_section
->vma
4252 - input_section
->output_offset
4254 /* It is for ck8xx. */
4255 #define CSKY_INSN_BSR32 0xe0000000
4256 /* It is for ck5xx/ck6xx. */
4257 #define CSKY_INSN_BSR16 0xf800
4258 #define within_range(x, L) (-(1 << (L - 1)) < (x) && (x) < (1 << (L -1)) - 2)
4259 switch (howto
->type
)
4261 case R_CKCORE_PCREL_IMM18BY2
:
4262 /* When h is NULL, means the instruction written as
4264 if the highest bit is set, prevent the high 32bits
4265 turn to 0xffffffff when signed extern in 64bit
4267 if (h
== NULL
&& (addend
& 0x80000000))
4268 addend
&= 0xffffffff;
4271 case R_CKCORE_PCREL32
:
4274 case R_CKCORE_GOT12
:
4275 case R_CKCORE_PLT12
:
4276 case R_CKCORE_GOT_HI16
:
4277 case R_CKCORE_GOT_LO16
:
4278 case R_CKCORE_PLT_HI16
:
4279 case R_CKCORE_PLT_LO16
:
4280 case R_CKCORE_GOT32
:
4281 case R_CKCORE_GOT_IMM18BY4
:
4282 /* Relocation is to the entry for this symbol in the global
4284 BFD_ASSERT (htab
->elf
.sgot
!= NULL
);
4287 /* Global symbol is defined by other modules. */
4289 off
= h
->got
.offset
;
4290 dyn
= htab
->elf
.dynamic_sections_created
;
4291 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
4292 bfd_link_pic (info
), h
)
4293 || (bfd_link_pic (info
) && SYMBOL_REFERENCES_LOCAL (info
,h
))
4294 || (ELF_ST_VISIBILITY(h
->other
)
4295 && h
->root
.type
== bfd_link_hash_undefweak
))
4297 /* This is actually a static link, or it is a
4298 -Bsymbolic link and the symbol is defined
4299 locally, or the symbol was forced to be local
4300 because of a version file. We must initialize
4301 this entry in the global offset table. Since the
4302 offset must always be a multiple of 4, we use the
4303 least significant bit to record whether we have
4304 initialized it already.
4305 When doing a dynamic link, we create a .rela.dyn
4306 relocation entry to initialize the value. This
4307 is done in the finish_dynamic_symbol routine. FIXME */
4312 bfd_put_32 (output_bfd
, relocation
,
4313 htab
->elf
.sgot
->contents
+ off
);
4316 /* TRUE if relative relocation should be generated. GOT reference to
4317 global symbol in PIC will lead to dynamic symbol. It becomes a
4318 problem when "time" or "times" is defined as a variable in an
4319 executable, clashing with functions of the same name in libc. If a
4320 symbol isn't undefined weak symbol, don't make it dynamic in PIC and
4321 generate relative relocation. */
4322 #define GENERATE_RELATIVE_RELOC_P(INFO, H) \
4323 ((H)->dynindx == -1 \
4324 && !(H)->forced_local \
4325 && (H)->root.type != bfd_link_hash_undefweak \
4326 && bfd_link_pic (INFO))
4328 if (GENERATE_RELATIVE_RELOC_P (info
, h
))
4329 /* If this symbol isn't dynamic
4330 in PIC, generate R_CKCORE_RELATIVE here. */
4331 relative_reloc
= TRUE
;
4335 unresolved_reloc
= FALSE
;
4336 } /* End if h != NULL. */
4339 BFD_ASSERT (local_got_offsets
!= NULL
);
4340 off
= local_got_offsets
[r_symndx
];
4342 /* The offset must always be a multiple of 4. We use
4343 the least significant bit to record whether we have
4344 already generated the necessary reloc. */
4349 bfd_put_32 (output_bfd
, relocation
,
4350 htab
->elf
.sgot
->contents
+ off
);
4351 local_got_offsets
[r_symndx
] |= 1;
4352 if (bfd_link_pic (info
))
4353 relative_reloc
= TRUE
;
4359 Elf_Internal_Rela outrel
;
4362 srelgot
= htab
->elf
.srelgot
;
4363 BFD_ASSERT (srelgot
!= NULL
);
4366 = (htab
->elf
.sgot
->output_section
->vma
4367 + htab
->elf
.sgot
->output_offset
+ off
);
4368 outrel
.r_info
= ELF32_R_INFO (0, R_CKCORE_RELATIVE
);
4369 outrel
.r_addend
= relocation
;
4370 loc
= srelgot
->contents
;
4371 loc
+= (srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
));
4373 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4375 relocation
= htab
->elf
.sgot
->output_offset
+ off
;
4378 case R_CKCORE_GOTOFF_IMM18
:
4379 case R_CKCORE_GOTOFF
:
4380 case R_CKCORE_GOTOFF_HI16
:
4381 case R_CKCORE_GOTOFF_LO16
:
4382 /* Relocation is relative to the start of the global offset
4384 /* Note that sgot->output_offset is not involved in this
4385 calculation. We always want the start of .got. If we
4386 defined _GLOBAL_OFFSET_TABLE in a different way, as is
4387 permitted by the ABI, we might have to change this
4389 relocation
-= htab
->elf
.sgot
->output_section
->vma
;
4392 case R_CKCORE_GOTPC
:
4393 case R_CKCORE_GOTPC_HI16
:
4394 case R_CKCORE_GOTPC_LO16
:
4395 /* Use global offset table as symbol value. */
4396 relocation
= htab
->elf
.sgot
->output_section
->vma
;
4398 unresolved_reloc
= FALSE
;
4401 case R_CKCORE_DOFFSET_IMM18
:
4402 case R_CKCORE_DOFFSET_IMM18BY2
:
4403 case R_CKCORE_DOFFSET_IMM18BY4
:
4405 asection
*sdata
= bfd_get_section_by_name (output_bfd
, ".data");
4406 relocation
-= sdata
->output_section
->vma
;
4410 case R_CKCORE_DOFFSET_LO16
:
4412 asection
*sdata
= bfd_get_section_by_name (output_bfd
, ".data");
4413 relocation
-= sdata
->output_section
->vma
;
4417 case R_CKCORE_TOFFSET_LO16
:
4419 asection
*stext
= bfd_get_section_by_name (output_bfd
, ".text");
4421 relocation
-= stext
->output_section
->vma
;
4425 case R_CKCORE_PLT_IMM18BY4
:
4426 case R_CKCORE_PLT32
:
4427 /* Relocation is to the entry for this symbol in the
4428 procedure linkage table. */
4430 /* Resolve a PLT32 reloc against a local symbol directly,
4431 without using the procedure linkage table. */
4435 if (h
->plt
.offset
== (bfd_vma
) -1 || htab
->elf
.splt
== NULL
)
4437 /* We didn't make a PLT entry for this symbol. This
4438 happens when statically linking PIC code, or when
4439 using -Bsymbolic. */
4440 if (h
->got
.offset
!= (bfd_vma
) -1)
4444 off
= h
->got
.offset
;
4445 dyn
= htab
->elf
.dynamic_sections_created
;
4446 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
4447 bfd_link_pic (info
), h
)
4448 || (bfd_link_pic (info
)
4449 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4450 || (ELF_ST_VISIBILITY (h
->other
)
4451 && h
->root
.type
== bfd_link_hash_undefweak
))
4453 /* This is actually a static link, or it is a
4454 -Bsymbolic link and the symbol is defined
4455 locally, or the symbol was forced to be local
4456 because of a version file. We must initialize
4457 this entry in the global offset table. Since the
4458 offset must always be a multiple of 4, we use the
4459 least significant bit to record whether we have
4460 initialized it already.
4462 When doing a dynamic link, we create a .rela.dyn
4463 relocation entry to initialize the value. This
4464 is done in the finish_dynamic_symbol routine.
4471 if (GENERATE_RELATIVE_RELOC_P (info
, h
))
4472 relative_reloc
= TRUE
;
4475 bfd_put_32 (output_bfd
, relocation
,
4476 htab
->elf
.sgot
->contents
+ off
);
4481 Elf_Internal_Rela outrel
;
4484 srelgot
= htab
->elf
.srelgot
;
4485 BFD_ASSERT (srelgot
!= NULL
);
4488 = (htab
->elf
.sgot
->output_section
->vma
4489 + htab
->elf
.sgot
->output_offset
+ off
);
4490 outrel
.r_info
= ELF32_R_INFO (0, R_CKCORE_RELATIVE
);
4491 outrel
.r_addend
= relocation
;
4492 loc
= srelgot
->contents
;
4493 loc
+= (srelgot
->reloc_count
++
4494 * sizeof (Elf32_External_Rela
));
4496 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4498 relocation
= off
+ htab
->elf
.sgot
->output_offset
;
4502 /* The relocation is the got offset. */
4503 if (bfd_csky_abi (output_bfd
) == CSKY_ABI_V2
)
4504 relocation
= (h
->plt
.offset
/ PLT_ENTRY_SIZE
+ 2) * 4;
4506 relocation
= (h
->plt
.offset
/ PLT_ENTRY_SIZE_P
+ 2) * 4;
4507 unresolved_reloc
= FALSE
;
4510 case R_CKCORE_PCREL_IMM26BY2
:
4511 case R_CKCORE_PCREL_JSR_IMM26BY2
:
4512 case R_CKCORE_PCREL_JSR_IMM11BY2
:
4513 case R_CKCORE_PCREL_IMM11BY2
:
4514 case R_CKCORE_CALLGRAPH
:
4515 /* Emit callgraph information first. */
4516 /* TODO: deal with callgraph. */
4517 if (ELF32_R_TYPE (rel
->r_info
) == R_CKCORE_CALLGRAPH
)
4519 /* Some reloc need further handling. */
4520 /* h == NULL means the symbol is a local symbol,
4521 r_symndx == 0 means the symbol is 'ABS' and
4522 the relocation is already handled in assemble,
4523 here just use for callgraph. */
4524 /* TODO: deal with callgraph. */
4525 if (h
== NULL
&& r_symndx
== 0)
4527 do_final_relocate
= FALSE
;
4531 /* Ignore weak references to undefined symbols. */
4532 if (h
!= NULL
&& h
->root
.type
== bfd_link_hash_undefweak
)
4534 do_final_relocate
= FALSE
;
4538 /* Using branch stub. */
4539 if (use_branch_stub
== TRUE
4540 && ELF32_R_TYPE (rel
->r_info
) == R_CKCORE_PCREL_IMM26BY2
)
4542 struct elf32_csky_stub_hash_entry
*stub_entry
= NULL
;
4543 if (sym_must_create_stub (h
, info
))
4544 stub_entry
= elf32_csky_get_stub_entry (input_section
,
4547 else if (disp
> BSR_MAX_FWD_BRANCH_OFFSET
4548 || disp
< BSR_MAX_BWD_BRANCH_OFFSET
)
4549 stub_entry
= elf32_csky_get_stub_entry (input_section
,
4552 if (stub_entry
!= NULL
)
4554 = (stub_entry
->stub_offset
4555 + stub_entry
->stub_sec
->output_offset
4556 + stub_entry
->stub_sec
->output_section
->vma
);
4561 || (h
->root
.type
== bfd_link_hash_defined
4562 && h
->dynindx
== -1)
4563 || ((h
->def_regular
&& !h
->def_dynamic
)
4564 && (h
->root
.type
!= bfd_link_hash_defweak
4565 || ! bfd_link_pic (info
))))
4567 if (ELF32_R_TYPE (rel
->r_info
) == R_CKCORE_PCREL_JSR_IMM26BY2
)
4569 if (within_range (disp
, 26))
4571 /* In range for BSR32. */
4572 howto
= &csky_elf_howto_table
[R_CKCORE_PCREL_IMM26BY2
];
4573 read_content_substitute
= CSKY_INSN_BSR32
;
4575 else if (bfd_csky_arch (output_bfd
) == CSKY_ARCH_810
)
4576 /* if bsr32 cannot reach, generate
4577 "lrw r25, label; jsr r25" instead of
4579 howto
= &csky_elf_howto_table
[R_CKCORE_NOJSRI
];
4580 } /* if ELF32_R_TYPE (rel->r_info)... */
4581 else if (ELF32_R_TYPE (rel
->r_info
)
4582 == R_CKCORE_PCREL_JSR_IMM11BY2
)
4584 if (within_range (disp
, 11))
4586 /* In range for BSR16. */
4587 howto
= &csky_elf_howto_table
[R_CKCORE_PCREL_IMM11BY2
];
4588 read_content_substitute
= CSKY_INSN_BSR16
;
4592 } /* else if h == NULL... */
4594 else if (bfd_csky_arch (output_bfd
) == CSKY_ARCH_810
4595 && (ELF32_R_TYPE (rel
->r_info
)
4596 == R_CKCORE_PCREL_JSR_IMM26BY2
))
4598 howto
= &csky_elf_howto_table
[R_CKCORE_NOJSRI
];
4601 /* Other situation, h->def_dynamic == 1,
4602 undefined_symbol when output file is shared object, etc. */
4603 /* Else fall through. */
4605 case R_CKCORE_ADDR_HI16
:
4606 case R_CKCORE_ADDR_LO16
:
4607 if (bfd_link_pic (info
)
4608 || (!bfd_link_pic (info
)
4612 && ((h
->def_dynamic
&& !h
->def_regular
)
4613 || (htab
->elf
.dynamic_sections_created
4614 && (h
->root
.type
== bfd_link_hash_undefweak
4615 || h
->root
.type
== bfd_link_hash_undefined
4616 || h
->root
.type
== bfd_link_hash_indirect
)))))
4618 Elf_Internal_Rela outrel
;
4619 bfd_boolean skip
, relocate
;
4622 /* When generating a shared object, these relocations
4623 are copied into the output file to be resolved at
4629 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4631 if (outrel
.r_offset
== (bfd_vma
) -1)
4633 else if (outrel
.r_offset
== (bfd_vma
) -2)
4638 outrel
.r_offset
+= (input_section
->output_section
->vma
4639 + input_section
->output_offset
);
4641 memset (&outrel
, 0, sizeof (outrel
));
4644 && (!bfd_link_pic (info
)
4645 || (!SYMBOLIC_BIND (info
, h
)
4646 && h
->root
.type
== bfd_link_hash_defweak
)
4647 || !h
->def_regular
))
4649 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
4650 outrel
.r_addend
= rel
->r_addend
;
4654 /* This symbol is local, or marked to become local. */
4656 outrel
.r_info
= ELF32_R_INFO (0, r_type
);
4657 outrel
.r_addend
= relocation
+ rel
->r_addend
;
4659 loc
= htab
->elf
.srelgot
->contents
;
4660 loc
+= (htab
->elf
.srelgot
->reloc_count
++
4661 * sizeof (Elf32_External_Rela
));
4664 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4666 /* If this reloc is against an external symbol, we do not
4667 want to diddle with the addend. Otherwise, we need to
4668 include the symbol value so that it becomes an addend
4669 for the dynamic reloc. */
4672 } /* if bfd_link_pic (info) ... */
4675 case R_CKCORE_ADDR32
:
4676 /* r_symndx will be zero only for relocs against symbols
4677 from removed linkonce sections, or sections discarded
4679 This relocation don't nedd to handle, the value will
4680 be set to SEC_DISCARDED(0xffffffff). */
4682 && strcmp (sec
->name
, ".csky_stack_size") == 0)
4684 do_final_relocate
= FALSE
;
4687 if (r_symndx
>= symtab_hdr
->sh_info
4689 && bfd_link_executable (info
))
4692 if (r_symndx
== 0 || (input_section
->flags
& SEC_ALLOC
) == 0)
4695 if (bfd_link_pic (info
)
4698 && ((h
->def_dynamic
&& !h
->def_regular
)
4699 || (htab
->elf
.dynamic_sections_created
4700 && (h
->root
.type
== bfd_link_hash_undefweak
4701 || h
->root
.type
== bfd_link_hash_undefined
4702 || h
->root
.type
== bfd_link_hash_indirect
)))))
4704 Elf_Internal_Rela outrel
;
4705 bfd_boolean skip
, relocate
;
4708 /* When generating a shared object, these relocations
4709 are copied into the output file to be resolved at
4715 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4718 if (outrel
.r_offset
== (bfd_vma
) -1)
4720 else if (outrel
.r_offset
== (bfd_vma
) -2)
4726 outrel
.r_offset
+= (input_section
->output_section
->vma
4727 + input_section
->output_offset
);
4730 memset (&outrel
, 0, sizeof (outrel
));
4733 && (!bfd_link_pic (info
)
4734 || (!SYMBOLIC_BIND (info
, h
)
4735 && h
->root
.type
== bfd_link_hash_defweak
)
4736 || !h
->def_regular
))
4738 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
4739 outrel
.r_addend
= rel
->r_addend
;
4743 /* This symbol is local, or marked to become local. */
4744 outrel
.r_info
= ELF32_R_INFO (0, R_CKCORE_RELATIVE
);
4745 outrel
.r_addend
= relocation
+ rel
->r_addend
;
4748 loc
= htab
->elf
.srelgot
->contents
;
4749 loc
+= (htab
->elf
.srelgot
->reloc_count
++
4750 * sizeof (Elf32_External_Rela
));
4753 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4755 /* If this reloc is against an external symbol, we do
4756 want to diddle with the addend. Otherwise, we need to
4757 include the symbol value so that it becomes an addend
4758 for the dynamic reloc. */
4764 case R_CKCORE_TLS_LDO32
:
4765 relocation
= relocation
- dtpoff_base (info
);
4768 case R_CKCORE_TLS_LDM32
:
4769 BFD_ASSERT (htab
->elf
.sgot
!= NULL
);
4770 off
= htab
->tls_ldm_got
.offset
;
4775 /* If we don't know the module number,
4776 create a relocation for it. */
4777 if (!bfd_link_executable (info
))
4779 Elf_Internal_Rela outrel
;
4782 BFD_ASSERT (htab
->elf
.srelgot
!= NULL
);
4783 outrel
.r_addend
= 0;
4785 = (htab
->elf
.sgot
->output_section
->vma
4786 + htab
->elf
.sgot
->output_offset
+ off
);
4787 outrel
.r_info
= ELF32_R_INFO (0, R_CKCORE_TLS_DTPMOD32
);
4788 bfd_put_32 (output_bfd
, outrel
.r_addend
,
4789 htab
->elf
.sgot
->contents
+ off
);
4791 loc
= htab
->elf
.srelgot
->contents
;
4792 loc
+= (htab
->elf
.srelgot
->reloc_count
++
4793 * sizeof (Elf32_External_Rela
));
4795 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4798 bfd_put_32 (output_bfd
, 1,
4799 htab
->elf
.sgot
->contents
+ off
);
4800 htab
->tls_ldm_got
.offset
|= 1;
4803 = (htab
->elf
.sgot
->output_section
->vma
4804 + htab
->elf
.sgot
->output_offset
+ off
4805 - (input_section
->output_section
->vma
4806 + input_section
->output_offset
+ rel
->r_offset
));
4808 case R_CKCORE_TLS_LE32
:
4809 if (bfd_link_dll (info
))
4812 /* xgettext:c-format */
4813 (_("%pB(%pA+%#" PRIx64
"): %s relocation not permitted "
4814 "in shared object"),
4815 input_bfd
, input_section
, (uint64_t)rel
->r_offset
,
4820 relocation
= tpoff (info
, relocation
);
4822 case R_CKCORE_TLS_GD32
:
4823 case R_CKCORE_TLS_IE32
:
4828 BFD_ASSERT (htab
->elf
.sgot
!= NULL
);
4834 dyn
= htab
->elf
.dynamic_sections_created
;
4835 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
4836 bfd_link_pic (info
), h
)
4837 && (!bfd_link_pic (info
)
4838 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
4840 unresolved_reloc
= FALSE
;
4843 off
= h
->got
.offset
;
4844 tls_type
= ((struct csky_elf_link_hash_entry
*)h
)->tls_type
;
4848 BFD_ASSERT (local_got_offsets
!= NULL
);
4849 off
= local_got_offsets
[r_symndx
];
4850 tls_type
= csky_elf_local_got_tls_type (input_bfd
)[r_symndx
];
4853 BFD_ASSERT (tls_type
!= GOT_UNKNOWN
);
4859 bfd_boolean need_relocs
= FALSE
;
4860 Elf_Internal_Rela outrel
;
4861 bfd_byte
*loc
= NULL
;
4863 /* The GOT entries have not been initialized yet. Do it
4864 now, and emit any relocations. If both an IE GOT and a
4865 GD GOT are necessary, we emit the GD first. */
4866 if ((!bfd_link_executable (info
) || indx
!= 0)
4868 || (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4869 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
4870 || h
->root
.type
!= bfd_link_hash_undefined
))
4873 BFD_ASSERT (htab
->elf
.srelgot
!= NULL
);
4875 loc
= htab
->elf
.srelgot
->contents
;
4876 loc
+= (htab
->elf
.srelgot
->reloc_count
4877 * sizeof (Elf32_External_Rela
));
4879 if (tls_type
& GOT_TLS_GD
)
4883 outrel
.r_addend
= 0;
4885 = (htab
->elf
.sgot
->output_section
->vma
4886 + htab
->elf
.sgot
->output_offset
4889 = ELF32_R_INFO (indx
, R_CKCORE_TLS_DTPMOD32
);
4890 bfd_put_32 (output_bfd
, outrel
.r_addend
,
4891 htab
->elf
.sgot
->contents
+ cur_off
);
4893 bfd_elf32_swap_reloca_out (output_bfd
,
4895 loc
+= sizeof (Elf32_External_Rela
);
4896 htab
->elf
.srelgot
->reloc_count
++;
4898 bfd_put_32 (output_bfd
,
4899 relocation
- dtpoff_base (info
),
4900 (htab
->elf
.sgot
->contents
4904 outrel
.r_addend
= 0;
4906 = ELF32_R_INFO (indx
, R_CKCORE_TLS_DTPOFF32
);
4907 outrel
.r_offset
+= 4;
4908 bfd_put_32 (output_bfd
, outrel
.r_addend
,
4909 (htab
->elf
.sgot
->contents
4913 R_CKCORE_TLS_DTPOFF32
);
4915 bfd_elf32_swap_reloca_out (output_bfd
,
4918 htab
->elf
.srelgot
->reloc_count
++;
4919 loc
+= sizeof (Elf32_External_Rela
);
4925 /* If are not emitting relocations for a
4926 general dynamic reference, then we must be in a
4927 static link or an executable link with the
4928 symbol binding locally. Mark it as belonging
4929 to module 1, the executable. */
4930 bfd_put_32 (output_bfd
, 1,
4931 htab
->elf
.sgot
->contents
+ cur_off
);
4932 bfd_put_32 (output_bfd
,
4933 relocation
- dtpoff_base (info
),
4934 htab
->elf
.sgot
->contents
4939 if (tls_type
& GOT_TLS_IE
)
4944 outrel
.r_addend
= relocation
- dtpoff_base (info
);
4946 outrel
.r_addend
= 0;
4948 = (htab
->elf
.sgot
->output_section
->vma
4949 + htab
->elf
.sgot
->output_offset
+ cur_off
);
4951 = ELF32_R_INFO (indx
, R_CKCORE_TLS_TPOFF32
);
4953 bfd_put_32 (output_bfd
, outrel
.r_addend
,
4954 htab
->elf
.sgot
->contents
+ cur_off
);
4956 bfd_elf32_swap_reloca_out (output_bfd
,
4958 htab
->elf
.srelgot
->reloc_count
++;
4959 loc
+= sizeof (Elf32_External_Rela
);
4962 bfd_put_32 (output_bfd
, tpoff (info
, relocation
),
4963 htab
->elf
.sgot
->contents
+ cur_off
);
4968 local_got_offsets
[r_symndx
] |= 1;
4970 if ((tls_type
& GOT_TLS_GD
) && howto
->type
!= R_CKCORE_TLS_GD32
)
4973 = (htab
->elf
.sgot
->output_section
->vma
4974 + htab
->elf
.sgot
->output_offset
+ off
4975 - (input_section
->output_section
->vma
4976 + input_section
->output_offset
4981 /* No substitution when final linking. */
4982 read_content_substitute
= 0;
4984 } /* End switch (howto->type). */
4986 /* Make sure 32-bit data in the text section will not be affected by
4987 our special endianness.
4988 However, this currently affects noting, since the ADDR32 howto type
4989 does no change with the data read. But we may need this mechanism in
4992 if (howto
->size
== 2
4993 && (howto
->type
== R_CKCORE_ADDR32
4994 || howto
->type
== R_CKCORE_PCREL32
4995 || howto
->type
== R_CKCORE_GOT32
4996 || howto
->type
== R_CKCORE_GOTOFF
4997 || howto
->type
== R_CKCORE_GOTPC
4998 || howto
->type
== R_CKCORE_PLT32
4999 || howto
->type
== R_CKCORE_TLS_LE32
5000 || howto
->type
== R_CKCORE_TLS_IE32
5001 || howto
->type
== R_CKCORE_TLS_LDM32
5002 || howto
->type
== R_CKCORE_TLS_GD32
5003 || howto
->type
== R_CKCORE_TLS_LDO32
5004 || howto
->type
== R_CKCORE_RELATIVE
))
5005 need_reverse_bits
= 0;
5007 need_reverse_bits
= 1;
5008 /* Do the final link. */
5009 if (howto
->type
!= R_CKCORE_PCREL_JSR_IMM11BY2
5010 && howto
->type
!= R_CKCORE_PCREL_JSR_IMM26BY2
5011 && howto
->type
!= R_CKCORE_CALLGRAPH
5012 && do_final_relocate
)
5013 r
= csky_final_link_relocate (howto
, input_bfd
, input_section
,
5014 contents
, rel
->r_offset
,
5015 relocation
, addend
);
5017 if (r
!= bfd_reloc_ok
)
5024 case bfd_reloc_overflow
:
5029 name
= bfd_elf_string_from_elf_section (input_bfd
,
5030 symtab_hdr
->sh_link
,
5035 name
= bfd_section_name (sec
);
5037 (*info
->callbacks
->reloc_overflow
)
5039 (h
? &h
->root
: NULL
),
5040 name
, howto
->name
, (bfd_vma
) 0,
5041 input_bfd
, input_section
, rel
->r_offset
);
5045 } /* End for (;rel < relend; rel++). */
5050 csky_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
5055 switch (note
->descsz
)
5059 /* Sizeof (struct elf_prstatus) on C-SKY V1 arch. */
5061 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
5062 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
5066 /* Sizeof (struct elf_prstatus) on C-SKY V1 arch. */
5068 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
5069 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
5074 /* Make a ".reg/999" section. */
5075 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
5076 size
, note
->descpos
+ offset
);
5080 csky_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
5082 switch (note
->descsz
)
5087 /* Sizeof (struct elf_prpsinfo) on linux csky. */
5089 elf_tdata (abfd
)->core
->program
5090 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
5091 elf_tdata (abfd
)->core
->command
5092 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
5095 /* Note that for some reason, a spurious space is tacked
5096 onto the end of the args in some (at least one anyway)
5097 implementations, so strip it off if it exists. */
5099 char *command
= elf_tdata (abfd
)->core
->command
;
5100 int n
= strlen (command
);
5102 if (0 < n
&& command
[n
- 1] == ' ')
5103 command
[n
- 1] = '\0';
5109 /* End of external entry points for sizing and building linker stubs. */
5111 /* CPU-related basic API. */
5112 #define TARGET_BIG_SYM csky_elf32_be_vec
5113 #define TARGET_BIG_NAME "elf32-csky-big"
5114 #define TARGET_LITTLE_SYM csky_elf32_le_vec
5115 #define TARGET_LITTLE_NAME "elf32-csky-little"
5116 #define ELF_ARCH bfd_arch_csky
5117 #define ELF_MACHINE_CODE EM_CSKY
5118 #define ELF_MACHINE_ALT1 EM_CSKY_OLD
5119 #define ELF_MAXPAGESIZE 0x1000
5120 #define elf_info_to_howto csky_elf_info_to_howto
5121 #define elf_info_to_howto_rel NULL
5122 #define elf_backend_special_sections csky_elf_special_sections
5123 #define bfd_elf32_bfd_link_hash_table_create csky_elf_link_hash_table_create
5125 /* Target related API. */
5126 #define bfd_elf32_mkobject csky_elf_mkobject
5127 #define bfd_elf32_bfd_merge_private_bfd_data csky_elf_merge_private_bfd_data
5128 #define bfd_elf32_bfd_set_private_flags csky_elf_set_private_flags
5129 #define elf_backend_copy_indirect_symbol csky_elf_copy_indirect_symbol
5131 /* GC section related API. */
5132 #define elf_backend_can_gc_sections 1
5133 #define elf_backend_gc_mark_hook csky_elf_gc_mark_hook
5134 #define elf_backend_gc_mark_extra_sections elf32_csky_gc_mark_extra_sections
5136 /* Relocation related API. */
5137 #define elf_backend_reloc_type_class csky_elf_reloc_type_class
5138 #define bfd_elf32_bfd_reloc_type_lookup csky_elf_reloc_type_lookup
5139 #define bfd_elf32_bfd_reloc_name_lookup csky_elf_reloc_name_lookup
5140 #define elf_backend_ignore_discarded_relocs csky_elf_ignore_discarded_relocs
5141 #define elf_backend_relocate_section csky_elf_relocate_section
5142 #define elf_backend_check_relocs csky_elf_check_relocs
5144 /* Dynamic relocate related API. */
5145 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
5146 #define elf_backend_adjust_dynamic_symbol csky_elf_adjust_dynamic_symbol
5147 #define elf_backend_size_dynamic_sections csky_elf_size_dynamic_sections
5148 #define elf_backend_finish_dynamic_symbol csky_elf_finish_dynamic_symbol
5149 #define elf_backend_finish_dynamic_sections csky_elf_finish_dynamic_sections
5150 #define elf_backend_rela_normal 1
5151 #define elf_backend_can_refcount 1
5152 #define elf_backend_plt_readonly 1
5153 #define elf_backend_want_got_sym 1
5154 #define elf_backend_want_dynrelro 1
5155 #define elf_backend_got_header_size 12
5156 #define elf_backend_want_got_plt 1
5158 /* C-SKY coredump support. */
5159 #define elf_backend_grok_prstatus csky_elf_grok_prstatus
5160 #define elf_backend_grok_psinfo csky_elf_grok_psinfo
5162 #include "elf32-target.h"