-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathncpu32k-binutils-2.32.patch
10534 lines (10501 loc) · 330 KB
/
ncpu32k-binutils-2.32.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff -Nur -x cgen -x tags -x build -x .cproject -x .project -x .settings binutils-2.32/bfd/archures.c binutils-ncpu32k-2.32/bfd/archures.c
--- binutils-2.32/bfd/archures.c 2019-01-19 11:01:32.000000000 -0500
+++ binutils-ncpu32k-2.32/bfd/archures.c 2020-10-23 11:57:14.012675082 -0400
@@ -542,6 +542,10 @@
.#define bfd_mach_ck803 5
.#define bfd_mach_ck807 6
.#define bfd_mach_ck810 7
+.
+. bfd_arch_ncpu32k, {* nano-CPU32k. *}
+.#define bfd_mach_ncpu32k 1
+.
. bfd_arch_last
. };
*/
@@ -633,6 +637,7 @@
extern const bfd_arch_info_type bfd_ft32_arch;
extern const bfd_arch_info_type bfd_msp430_arch;
extern const bfd_arch_info_type bfd_mt_arch;
+extern const bfd_arch_info_type bfd_ncpu32k_arch;
extern const bfd_arch_info_type bfd_nds32_arch;
extern const bfd_arch_info_type bfd_nfp_arch;
extern const bfd_arch_info_type bfd_nios2_arch;
@@ -724,6 +729,7 @@
&bfd_ft32_arch,
&bfd_msp430_arch,
&bfd_mt_arch,
+ &bfd_ncpu32k_arch,
&bfd_nds32_arch,
&bfd_nfp_arch,
&bfd_nios2_arch,
diff -Nur -x cgen -x tags -x build -x .cproject -x .project -x .settings binutils-2.32/bfd/bfd-in2.h binutils-ncpu32k-2.32/bfd/bfd-in2.h
--- binutils-2.32/bfd/bfd-in2.h 2019-01-19 11:01:32.000000000 -0500
+++ binutils-ncpu32k-2.32/bfd/bfd-in2.h 2021-03-31 09:18:17.239661357 -0400
@@ -2441,6 +2441,10 @@
#define bfd_mach_ck803 5
#define bfd_mach_ck807 6
#define bfd_mach_ck810 7
+
+ bfd_arch_ncpu32k, /* nano-CPU32k. */
+#define bfd_mach_ncpu32k 1
+
bfd_arch_last
};
@@ -5643,6 +5647,25 @@
BFD_RELOC_NIOS2_R2_T1X1I6,
BFD_RELOC_NIOS2_R2_T1X1I6_2,
+/* nano-cpu32k Relocations. */
+ BFD_RELOC_NCPU32K_INSN_LO15,
+ BFD_RELOC_NCPU32K_INSN_HI15,
+ BFD_RELOC_NCPU32K_INSN_LO17,
+ BFD_RELOC_NCPU32K_INSN_HI17,
+ BFD_RELOC_NCPU32K_INSN_REL15,
+ BFD_RELOC_NCPU32K_INSN_REL25,
+ BFD_RELOC_NCPU32K_GLOB_DAT,
+ BFD_RELOC_NCPU32K_JMP_SLOT,
+ BFD_RELOC_NCPU32K_RELATIVE,
+ BFD_RELOC_NCPU32K_COPY,
+ BFD_RELOC_NCPU32K_GOT_PCREL_HI17,
+ BFD_RELOC_NCPU32K_GOT_PCREL_LO15,
+ BFD_RELOC_NCPU32K_PLT_REL25,
+ BFD_RELOC_NCPU32K_GOTOFF_HI17,
+ BFD_RELOC_NCPU32K_GOTOFF_LO15,
+ BFD_RELOC_NCPU32K_GOT15,
+ BFD_RELOC_NCPU32K_RELAX,
+
/* PRU LDI 16-bit unsigned data-memory relocation. */
BFD_RELOC_PRU_U16,
diff -Nur -x cgen -x tags -x build -x .cproject -x .project -x .settings binutils-2.32/bfd/config.bfd binutils-ncpu32k-2.32/bfd/config.bfd
--- binutils-2.32/bfd/config.bfd 2019-01-19 11:01:32.000000000 -0500
+++ binutils-ncpu32k-2.32/bfd/config.bfd 2020-10-23 11:57:14.064674606 -0400
@@ -183,6 +183,7 @@
s12z*) targ_archs=bfd_s12z_arch ;;
microblaze*) targ_archs=bfd_microblaze_arch ;;
mips*) targ_archs=bfd_mips_arch ;;
+ncpu32k*) targ_archs=bfd_ncpu32k_arch ;;
nds32*) targ_archs=bfd_nds32_arch ;;
nfp) targ_archs=bfd_nfp_arch ;;
nios2*) targ_archs=bfd_nios2_arch ;;
@@ -987,6 +988,10 @@
targ_selvecs=msp430_elf32_ti_vec
;;
+ ncpu32k-*-elf | ncpu32k-*-linux*)
+ targ_defvec=ncpu32k_elf32_vec
+ ;;
+
nds32*le-*-linux*)
targ_defvec=nds32_elf32_linux_le_vec
targ_selvecs=nds32_elf32_linux_be_vec
diff -Nur -x cgen -x tags -x build -x .cproject -x .project -x .settings binutils-2.32/bfd/configure binutils-ncpu32k-2.32/bfd/configure
--- binutils-2.32/bfd/configure 2019-02-02 10:47:56.000000000 -0500
+++ binutils-ncpu32k-2.32/bfd/configure 2020-10-23 11:57:14.066674587 -0400
@@ -14805,6 +14805,7 @@
msp430_elf32_vec) tb="$tb elf32-msp430.lo elf32.lo $elf" ;;
msp430_elf32_ti_vec) tb="$tb elf32-msp430.lo elf32.lo $elf" ;;
mt_elf32_vec) tb="$tb elf32-mt.lo elf32.lo $elf" ;;
+ ncpu32k_elf32_vec) tb="$tb elf32-ncpu32k.lo elf32.lo $elf" ;;
nds32_elf32_be_vec) tb="$tb elf32-nds32.lo elf32.lo $elf" ;;
nds32_elf32_le_vec) tb="$tb elf32-nds32.lo elf32.lo $elf" ;;
nds32_elf32_linux_be_vec) tb="$tb elf32-nds32.lo elf32.lo $elf" ;;
diff -Nur -x cgen -x tags -x build -x .cproject -x .project -x .settings binutils-2.32/bfd/configure.ac binutils-ncpu32k-2.32/bfd/configure.ac
--- binutils-2.32/bfd/configure.ac 2019-01-19 11:01:32.000000000 -0500
+++ binutils-ncpu32k-2.32/bfd/configure.ac 2020-10-23 11:57:14.068674569 -0400
@@ -573,6 +573,7 @@
msp430_elf32_vec) tb="$tb elf32-msp430.lo elf32.lo $elf" ;;
msp430_elf32_ti_vec) tb="$tb elf32-msp430.lo elf32.lo $elf" ;;
mt_elf32_vec) tb="$tb elf32-mt.lo elf32.lo $elf" ;;
+ ncpu32k_elf32_vec) tb="$tb elf32-ncpu32k.lo elf32.lo $elf" ;;
nds32_elf32_be_vec) tb="$tb elf32-nds32.lo elf32.lo $elf" ;;
nds32_elf32_le_vec) tb="$tb elf32-nds32.lo elf32.lo $elf" ;;
nds32_elf32_linux_be_vec) tb="$tb elf32-nds32.lo elf32.lo $elf" ;;
diff -Nur -x cgen -x tags -x build -x .cproject -x .project -x .settings binutils-2.32/bfd/cpu-ncpu32k.c binutils-ncpu32k-2.32/bfd/cpu-ncpu32k.c
--- binutils-2.32/bfd/cpu-ncpu32k.c 1969-12-31 19:00:00.000000000 -0500
+++ binutils-ncpu32k-2.32/bfd/cpu-ncpu32k.c 2020-10-23 11:57:14.068674569 -0400
@@ -0,0 +1,39 @@
+/* BFD support for the ncpu32k architecture.
+ Copyright (C) 2019 Free Software Foundation, Inc.
+
+ This file is part of BFD, the Binary File Descriptor library.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#include "sysdep.h"
+#include "bfd.h"
+#include "libbfd.h"
+
+const bfd_arch_info_type bfd_ncpu32k_arch =
+ {
+ 32, /* 32 bits in a word. */
+ 32, /* 32 bits in an address. */
+ 8, /* 8 bits in a byte. */
+ bfd_arch_ncpu32k,
+ bfd_mach_ncpu32k,
+ "ncpu32k",
+ "ncpu32k",
+ 4,
+ TRUE,
+ bfd_default_compatible,
+ bfd_default_scan,
+ bfd_arch_default_fill,
+ NULL
+ };
+
diff -Nur -x cgen -x tags -x build -x .cproject -x .project -x .settings binutils-2.32/bfd/elf32-ncpu32k.c binutils-ncpu32k-2.32/bfd/elf32-ncpu32k.c
--- binutils-2.32/bfd/elf32-ncpu32k.c 1969-12-31 19:00:00.000000000 -0500
+++ binutils-ncpu32k-2.32/bfd/elf32-ncpu32k.c 2021-09-26 10:50:35.699969706 -0400
@@ -0,0 +1,2689 @@
+/* nano-CPU32k-specific support for 32-bit ELF.
+ Copyright (C) 2019 Free Software Foundation, Inc.
+ largely based on elf32-or1k.c elf32-m32r.c elf32-microblaze.c and
+ elfnn-riscv.c
+
+ This file is part of BFD, the Binary File Descriptor library.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#include "sysdep.h"
+#include "bfd.h"
+#include "libbfd.h"
+#include "elf-bfd.h"
+#include "elf/ncpu32k.h"
+#include "opcode/ncpu32k.h"
+#include "libiberty.h"
+
+#define MINUS_ONE ((bfd_vma)0 - 1)
+#define N_ONES(X) (((bfd_vma)2 << (X)) - 1)
+
+#define PLT_ENTRY_SIZE 16
+
+#define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
+
+#define sec_addr(sec) ((sec)->output_section->vma + (sec)->output_offset)
+
+static bfd_reloc_status_type bfd_elf_ncpu32k_rel25_reloc (bfd *abfd ATTRIBUTE_UNUSED,
+ arelent *reloc_entry,
+ asymbol *symbol,
+ void *data ATTRIBUTE_UNUSED,
+ asection *input_section,
+ bfd *output_bfd,
+ char **error_message ATTRIBUTE_UNUSED);
+
+static reloc_howto_type ncpu32k_elf_howto_table[] =
+{
+ /* This reloc does nothing. */
+ HOWTO (R_NCPU32K_NONE, /* type */
+ 0, /* rightshift */
+ 3, /* size (0 = byte, 1 = short, 2 = long) */
+ 0, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_NCPU32K_NONE", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
+ HOWTO (R_NCPU32K_32,
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 32, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_unsigned, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_NCPU32K_32", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0xffffffff, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
+ HOWTO (R_NCPU32K_16,
+ 0, /* rightshift */
+ 1, /* size (0 = byte, 1 = short, 2 = long) */
+ 16, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_unsigned, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_NCPU32K_16", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0xffff, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
+ HOWTO (R_NCPU32K_8,
+ 0, /* rightshift */
+ 0, /* size (0 = byte, 1 = short, 2 = long) */
+ 8, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_unsigned, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_NCPU32K_8", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0xff, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
+ HOWTO (R_NCPU32K_INSN_LO15,
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 15, /* bitsize */
+ FALSE, /* pc_relative */
+ 17, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_NCPU32K_INSN_LO15", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0xfffe0000, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
+ HOWTO (R_NCPU32K_INSN_HI15,
+ 17, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 15, /* bitsize */
+ FALSE, /* pc_relative */
+ 17, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_NCPU32K_INSN_HI15", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0xfffe0000, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
+ HOWTO (R_NCPU32K_INSN_LO17,
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 17, /* bitsize */
+ FALSE, /* pc_relative */
+ 15, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_NCPU32K_INSN_LO17", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0xffff8000, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
+ HOWTO (R_NCPU32K_INSN_HI17,
+ 15, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 17, /* bitsize */
+ FALSE, /* pc_relative */
+ 15, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_NCPU32K_INSN_HI17", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0xffff8000, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
+ /* A PC relative 15 bit relocation, right shifted by 2. */
+ HOWTO (R_NCPU32K_INSN_REL15, /* type */
+ 2, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 15, /* bitsize */
+ TRUE, /* pc_relative */
+ 17, /* bitpos */
+ complain_overflow_signed, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_NCPU32K_INSN_REL15", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0xfffe0000, /* dst_mask */
+ TRUE), /* pcrel_offset */
+
+ /* A PC relative 25 bit relocation, right shifted by 2. */
+ HOWTO (R_NCPU32K_INSN_REL25, /* type */
+ 2, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 25, /* bitsize */
+ TRUE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_signed, /* complain_on_overflow */
+ bfd_elf_ncpu32k_rel25_reloc, /* special_function */
+ "R_NCPU32K_INSN_REL25", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0xfffff01f, /* dst_mask */
+ TRUE), /* pcrel_offset */
+
+ /* GNU extension to record C++ vtable hierarchy. */
+ HOWTO (R_NCPU32K_GNU_VTINHERIT, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 0, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ NULL, /* special_function */
+ "R_NCPU32K_GNU_VTINHERIT", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
+ /* GNU extension to record C++ vtable member usage. */
+ HOWTO (R_NCPU32K_GNU_VTENTRY, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 0, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ _bfd_elf_rel_vtable_reloc_fn, /* special_function */
+ "R_NCPU32K_GNU_VTENTRY", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
+ HOWTO (R_NCPU32K_COPY, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 32, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_bitfield, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_NCPU32K_COPY", /* name */
+ FALSE, /* partial_inplace */
+ 0xffffffff, /* src_mask */
+ 0xffffffff, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
+ HOWTO (R_NCPU32K_GLOB_DAT, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 32, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_bitfield, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_NCPU32K_GLOB_DAT", /* name */
+ FALSE, /* partial_inplace */
+ 0xffffffff, /* src_mask */
+ 0xffffffff, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
+ HOWTO (R_NCPU32K_JMP_SLOT, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 32, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_bitfield, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_NCPU32K_JMP_SLOT", /* name */
+ FALSE, /* partial_inplace */
+ 0xffffffff, /* src_mask */
+ 0xffffffff, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
+ HOWTO (R_NCPU32K_RELATIVE, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 32, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_bitfield, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_NCPU32K_RELATIVE", /* name */
+ FALSE, /* partial_inplace */
+ 0xffffffff, /* src_mask */
+ 0xffffffff, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
+ HOWTO (R_NCPU32K_GOT_PCREL_HI17, /* Type. */
+ 15, /* Rightshift. */
+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
+ 17, /* Bitsize. */
+ TRUE, /* PC_relative. */
+ 15, /* Bitpos. */
+ complain_overflow_dont, /* Complain on overflow. */
+ bfd_elf_generic_reloc, /* Special Function. */
+ "R_NCPU32K_GOT_PCREL_HI17", /* Name. */
+ FALSE, /* Partial Inplace. */
+ 0, /* Source Mask. */
+ 0xffff8000, /* Dest Mask. */
+ TRUE), /* PC relative offset? */
+
+ HOWTO (R_NCPU32K_GOT_PCREL_LO15, /* Type. */
+ 0, /* Rightshift. */
+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
+ 15, /* Bitsize. */
+ TRUE, /* PC_relative. */
+ 17, /* Bitpos. */
+ complain_overflow_dont, /* Complain on overflow. */
+ bfd_elf_generic_reloc, /* Special Function. */
+ "R_NCPU32K_GOT_PCREL_LO15", /* Name. */
+ FALSE, /* Partial Inplace. */
+ 0, /* Source Mask. */
+ 0xfffe0000, /* Dest Mask. */
+ TRUE), /* PC relative offset? */
+
+ HOWTO (R_NCPU32K_PLT_REL25, /* Type. */
+ 2, /* Rightshift. */
+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
+ 25, /* Bitsize. */
+ TRUE, /* pc_relative. */
+ 0, /* Bitpos. */
+ complain_overflow_signed, /* Complain on overflow. */
+ bfd_elf_ncpu32k_rel25_reloc, /* Special Function. */
+ "R_NCPU32K_PLT_REL25", /* Name. */
+ FALSE, /* Partial Inplace. */
+ 0, /* Source Mask. */
+ 0xfffff01f, /* Dest Mask. */
+ TRUE), /* PC relative offset? */
+
+ HOWTO (R_NCPU32K_GOTOFF_HI17, /* type */
+ 15, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 17, /* bitsize */
+ FALSE, /* pc_relative */
+ 15, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_NCPU32K_GOTOFF_HI17", /* name */
+ FALSE, /* partial_inplace */
+ 0x0, /* src_mask */
+ 0xffff8000, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
+ HOWTO (R_NCPU32K_GOTOFF_LO15, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 15, /* bitsize */
+ FALSE, /* pc_relative */
+ 17, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_NCPU32K_GOTOFF_LO15", /* name */
+ FALSE, /* partial_inplace */
+ 0x0, /* src_mask */
+ 0xfffe0000, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
+ HOWTO (R_NCPU32K_GOT15, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 15, /* bitsize */
+ FALSE, /* pc_relative */
+ 17, /* bitpos */
+ complain_overflow_signed, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_NCPU32K_GOT15", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0xfffe0000, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
+ /* The paired relocation may be relaxed. */
+ HOWTO (R_NCPU32K_RELAX, /* type */
+ 0, /* rightshift */
+ 3, /* size */
+ 0, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_NCPU32K_RELAX", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
+};
+
+/* Map BFD reloc types to ncpu32k ELF reloc types. */
+
+struct ncpu32k_reloc_map
+{
+ bfd_reloc_code_real_type bfd_reloc_val;
+ unsigned int ncpu32k_reloc_val;
+};
+
+static const struct ncpu32k_reloc_map ncpu32k_reloc_map[] =
+{
+ { BFD_RELOC_NONE, R_NCPU32K_NONE },
+ { BFD_RELOC_32, R_NCPU32K_32 },
+ { BFD_RELOC_16, R_NCPU32K_16 },
+ { BFD_RELOC_8, R_NCPU32K_8 },
+ { BFD_RELOC_NCPU32K_INSN_LO15, R_NCPU32K_INSN_LO15 },
+ { BFD_RELOC_NCPU32K_INSN_HI15, R_NCPU32K_INSN_HI15 },
+ { BFD_RELOC_NCPU32K_INSN_LO17, R_NCPU32K_INSN_LO17 },
+ { BFD_RELOC_NCPU32K_INSN_HI17, R_NCPU32K_INSN_HI17 },
+ { BFD_RELOC_NCPU32K_INSN_REL15, R_NCPU32K_INSN_REL15 },
+ { BFD_RELOC_NCPU32K_INSN_REL25, R_NCPU32K_INSN_REL25 },
+ { BFD_RELOC_NCPU32K_GLOB_DAT, R_NCPU32K_GLOB_DAT },
+ { BFD_RELOC_NCPU32K_JMP_SLOT, R_NCPU32K_JMP_SLOT },
+ { BFD_RELOC_NCPU32K_RELATIVE, R_NCPU32K_RELATIVE },
+ { BFD_RELOC_NCPU32K_COPY, R_NCPU32K_COPY },
+ { BFD_RELOC_NCPU32K_GOT_PCREL_HI17, R_NCPU32K_GOT_PCREL_HI17 },
+ { BFD_RELOC_NCPU32K_GOT_PCREL_LO15, R_NCPU32K_GOT_PCREL_LO15 },
+ { BFD_RELOC_NCPU32K_PLT_REL25, R_NCPU32K_PLT_REL25 },
+ { BFD_RELOC_NCPU32K_GOTOFF_HI17, R_NCPU32K_GOTOFF_HI17 },
+ { BFD_RELOC_NCPU32K_GOTOFF_LO15, R_NCPU32K_GOTOFF_LO15 },
+ { BFD_RELOC_NCPU32K_GOT15, R_NCPU32K_GOT15 },
+ { BFD_RELOC_NCPU32K_RELAX, R_NCPU32K_RELAX },
+ { BFD_RELOC_VTABLE_ENTRY, R_NCPU32K_GNU_VTENTRY },
+ { BFD_RELOC_VTABLE_INHERIT, R_NCPU32K_GNU_VTINHERIT },
+};
+
+#define TLS_UNKNOWN 0
+#define TLS_NONE 1
+#define TLS_GD 2
+#define TLS_LD 3
+#define TLS_IE 4
+#define TLS_LE 5
+
+/* ELF linker hash entry. */
+struct elf_ncpu32k_link_hash_entry
+{
+ struct elf_link_hash_entry root;
+
+ /* Track dynamic relocs copied for this symbol. */
+ struct elf_dyn_relocs *dyn_relocs;
+
+ /* Track type of TLS access. */
+ unsigned char tls_type;
+};
+
+/* ELF object data. */
+struct elf_ncpu32k_obj_tdata
+{
+ struct elf_obj_tdata root;
+
+ /* tls_type for each local got entry. */
+ unsigned char *local_tls_type;
+};
+
+#define elf_ncpu32k_tdata(abfd) \
+ ((struct elf_ncpu32k_obj_tdata *) (abfd)->tdata.any)
+
+#define elf_ncpu32k_local_tls_type(abfd) \
+ (elf_ncpu32k_tdata (abfd)->local_tls_type)
+
+/* ELF linker hash table. */
+struct elf_ncpu32k_link_hash_table
+{
+ struct elf_link_hash_table root;
+
+ /* Small local sym to section mapping cache. */
+ struct sym_cache sym_sec;
+};
+
+/* Get the ELF linker hash table from a link_info structure. */
+#define ncpu32k_elf_hash_table(p) \
+ (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
+ == NCPU32K_ELF_DATA ? ((struct elf_ncpu32k_link_hash_table *) ((p)->hash)) : NULL)
+
+static bfd_boolean
+elf_ncpu32k_mkobject (bfd *abfd)
+{
+ return bfd_elf_allocate_object (abfd, sizeof (struct elf_ncpu32k_obj_tdata),
+ NCPU32K_ELF_DATA);
+}
+
+/* Create an entry in an ncpu32k ELF linker hash table. */
+
+static struct bfd_hash_entry *
+ncpu32k_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
+ struct bfd_hash_table *table,
+ const char *string)
+{
+ struct elf_ncpu32k_link_hash_entry *ret =
+ (struct elf_ncpu32k_link_hash_entry *) entry;
+
+ /* Allocate the structure if it has not already been allocated by a
+ subclass. */
+ if (ret == NULL)
+ ret = bfd_hash_allocate (table,
+ sizeof (struct elf_ncpu32k_link_hash_entry));
+ if (ret == NULL)
+ return NULL;
+
+ /* Call the allocation method of the superclass. */
+ ret = ((struct elf_ncpu32k_link_hash_entry *)
+ _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
+ table, string));
+ if (ret != NULL)
+ {
+ struct elf_ncpu32k_link_hash_entry *eh;
+
+ eh = (struct elf_ncpu32k_link_hash_entry *) ret;
+ eh->dyn_relocs = NULL;
+ eh->tls_type = TLS_UNKNOWN;
+ }
+
+ return (struct bfd_hash_entry *) ret;
+}
+
+/* Create an ncpu32k ELF linker hash table. */
+
+static struct bfd_link_hash_table *
+ncpu32k_elf_link_hash_table_create (bfd *abfd)
+{
+ struct elf_ncpu32k_link_hash_table *ret;
+ bfd_size_type amt = sizeof (struct elf_ncpu32k_link_hash_table);
+
+ ret = bfd_zmalloc (amt);
+ if (ret == NULL)
+ return NULL;
+
+ if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
+ ncpu32k_elf_link_hash_newfunc,
+ sizeof (struct elf_ncpu32k_link_hash_entry),
+ NCPU32K_ELF_DATA))
+ {
+ free (ret);
+ return NULL;
+ }
+
+ return &ret->root.root;
+}
+
+static reloc_howto_type *
+ncpu32k_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
+ bfd_reloc_code_real_type bcode)
+{
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE (ncpu32k_reloc_map); i++)
+ if (ncpu32k_reloc_map[i].bfd_reloc_val == bcode)
+ {
+ unsigned int ocode = ncpu32k_reloc_map[i].ncpu32k_reloc_val;
+ if (ocode < (unsigned int) R_NCPU32K_max)
+ return &ncpu32k_elf_howto_table[ocode];
+ else
+ break;
+ }
+
+ return NULL;
+}
+
+static reloc_howto_type *
+ncpu32k_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
+ const char *r_name)
+{
+ unsigned int i;
+
+ for (i = 0; i < R_NCPU32K_max; i++)
+ if (ncpu32k_elf_howto_table[i].name != NULL
+ && strcasecmp (ncpu32k_elf_howto_table[i].name, r_name) == 0)
+ return &ncpu32k_elf_howto_table[i];
+
+ return NULL;
+}
+
+/* Set the howto pointer for an ncpu32k ELF reloc. */
+
+static bfd_boolean
+ncpu32k_info_to_howto_rela (bfd * abfd,
+ arelent * cache_ptr,
+ Elf_Internal_Rela * dst)
+{
+ unsigned int r_type;
+
+ r_type = ELF32_R_TYPE (dst->r_info);
+ if (r_type >= (unsigned int) R_NCPU32K_max)
+ {
+ /* xgettext:c-format */
+ _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
+ abfd, r_type);
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+ }
+ cache_ptr->howto = & ncpu32k_elf_howto_table[r_type];
+ return TRUE;
+}
+
+
+#if 0
+/* Return the relocation value for @tpoff relocations.. */
+static bfd_vma
+tpoff (struct bfd_link_info *info, bfd_vma address)
+{
+ /* If tls_sec is NULL, we should have signalled an error already. */
+ if (elf_hash_table (info)->tls_sec == NULL)
+ return 0;
+
+ /* The thread pointer on ncpu32k stores the address after the TCB where
+ the data is, just compute the difference. No need to compensate
+ for the size of TCB. */
+ return (address - elf_hash_table (info)->tls_sec->vma);
+}
+#endif
+
+/* Like _bfd_final_link_relocate, but handles non-contiguous fields. */
+
+static bfd_reloc_status_type
+ncpu32k_final_link_relocate (reloc_howto_type *howto, bfd *input_bfd,
+ asection *input_section, bfd_byte *contents, Elf_Internal_Rela *rel, Elf_Internal_Rela *relend,
+ bfd_vma offset, bfd_vma value)
+{
+ bfd_reloc_status_type status = bfd_reloc_ok;
+ int size = bfd_get_reloc_size (howto);
+ bfd_vma x, place;
+
+ /* Sanity check the address. */
+ if (offset + size > bfd_get_section_limit_octets (input_bfd, input_section))
+ return bfd_reloc_outofrange;
+
+ place = (input_section->output_section->vma
+ + input_section->output_offset
+ + (howto->pcrel_offset ? offset : 0));
+
+ if (howto->pc_relative)
+ value -= place;
+
+ switch (howto->type)
+ {
+ case R_NCPU32K_INSN_REL15:
+ case R_NCPU32K_INSN_REL25:
+ case R_NCPU32K_PLT_REL25:
+ /* Diagnose mis-aligned (non 4 byte) branch targets. */
+ if (value & 0x3)
+ {
+ status = bfd_reloc_dangerous;
+ goto done;
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ /* Expand the branch insn if it is paired with a R_NCPU32K_RELAX
+ and the branch target is out of range */
+ if (howto->type == R_NCPU32K_INSN_REL15
+ && rel != relend - 1
+ && ELF32_R_TYPE ((rel + 1)->r_info) == R_NCPU32K_RELAX
+ && rel->r_offset + 4 == (rel + 1)->r_offset)
+ {
+ if ((value + (bfd_vma)NCPU32K_BCC_REACH/2) < (bfd_vma)NCPU32K_BCC_REACH)
+ {
+ /* The trampoline slot is not used */
+ (rel + 1)->r_info = ELF32_R_INFO(ELF32_R_SYM ((rel + 1)->r_info), R_NCPU32K_NONE);
+ }
+ else
+ {
+ uint32_t insn, opcode;
+ /* Invert the branch condition. Branch over the jump. */
+ insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
+ opcode = NCPU32K_GET_INSN_FIELD(insn, OPCODE);
+ switch(opcode)
+ {
+ case NCPU32K_OP_BEQ:
+ opcode = NCPU32K_OP_BNE;
+ break;
+ case NCPU32K_OP_BNE:
+ opcode = NCPU32K_OP_BEQ;
+ break;
+ case NCPU32K_OP_BGT:
+ opcode = NCPU32K_OP_BLE;
+ break;
+ case NCPU32K_OP_BGTU:
+ opcode = NCPU32K_OP_BLEU;
+ break;
+ case NCPU32K_OP_BLE:
+ opcode = NCPU32K_OP_BGT;
+ break;
+ case NCPU32K_OP_BLEU:
+ opcode = NCPU32K_OP_BGTU;
+ break;
+ default:
+ status = bfd_reloc_dangerous;
+ goto done;
+ }
+ insn &= (~NCPU32K_MASK_OPCODE & ~NCPU32K_MASK_REL15);
+ insn |= (opcode << NCPU32K_SHIFTRIGHT_OPCODE);
+ insn |= 0x2U << NCPU32K_SHIFTRIGHT_REL15;
+ bfd_put (8 * 4, input_bfd, insn, contents + offset);
+ rel->r_info = ELF32_R_INFO(ELF32_R_SYM (rel->r_info), R_NCPU32K_NONE);
+
+ /* Replace the trampoline slot with a far jump */
+ insn = NCPU32K_GEN_REL25(0, NCPU32K_OP_JMP_I);
+ bfd_put (8 * 4, input_bfd, insn, contents + offset + 4);
+
+ /* The outer loop will relocate the replaced insn in the next iteration */
+ (rel + 1)->r_info = ELF32_R_INFO(ELF32_R_SYM ((rel + 1)->r_info), R_NCPU32K_INSN_REL25);
+ goto done;
+ }
+ }
+
+ status = bfd_check_overflow (howto->complain_on_overflow,
+ howto->bitsize,
+ howto->rightshift,
+ bfd_arch_bits_per_address (input_bfd),
+ value);
+
+ value >>= howto->rightshift;
+
+ /* If we're overwriting the entire destination,
+ then no need to read the current contents. */
+ if (size == 0 || howto->dst_mask == N_ONES (size))
+ x = 0;
+ else
+ {
+ BFD_ASSERT (size == 4);
+ x = bfd_get_32 (input_bfd, contents + offset);
+ }
+
+ switch (howto->type)
+ {
+ case R_NCPU32K_INSN_REL25:
+ case R_NCPU32K_PLT_REL25:
+ {
+ bfd_vma fieldmask = howto->dst_mask;
+ x = (x & ~fieldmask) | (value & 0x1f) | (((value>>5)&0xfffff)<<12);
+ }
+ break;
+
+ default:
+ {
+ bfd_vma fieldmask = howto->dst_mask;
+ value <<= howto->bitpos;
+ x = (x & ~fieldmask) | (value & fieldmask);
+ }
+ break;
+ }
+
+ /* Put the relocated value back in the object file. */
+ switch (size)
+ {
+ case 0:
+ break;
+ case 1:
+ bfd_put_8 (input_bfd, x, contents + offset);
+ break;
+ case 2:
+ bfd_put_16 (input_bfd, x, contents + offset);
+ break;
+ case 4:
+ bfd_put_32 (input_bfd, x, contents + offset);
+ break;
+#ifdef BFD64
+ case 8:
+ bfd_put_64 (input_bfd, x, contents + offset);
+ break;
+#endif
+ default:
+ _bfd_error_handler
+ (_("%pB: Cannot handle relocation value size of %d"),
+ input_bfd, size);
+ abort ();
+ }
+done:
+ return status;
+}
+
+/* Special relocate for REL25 */
+bfd_reloc_status_type
+bfd_elf_ncpu32k_rel25_reloc (bfd *input_bfd,
+ arelent *reloc_entry,
+ asymbol *symbol,
+ void *data,
+ asection *input_section,
+ bfd *output_bfd,
+ char **error_message)
+{
+ bfd_reloc_status_type status;
+ bfd_vma x, place;
+ bfd_vma offset, value;
+ unsigned int size;
+
+ status = bfd_elf_generic_reloc(
+ input_bfd, reloc_entry, symbol, data, input_section, output_bfd, error_message);
+ if (status != bfd_reloc_continue)
+ return status;
+
+ size = bfd_get_reloc_size (reloc_entry->howto);
+
+ BFD_ASSERT((reloc_entry->howto->type == R_NCPU32K_INSN_REL25) ||
+ (reloc_entry->howto->type == R_NCPU32K_PLT_REL25));
+ BFD_ASSERT(size == 4);
+
+ offset = reloc_entry->address;
+
+ /* Sanity check the address. */
+ if (offset + size > bfd_get_section_limit_octets (input_bfd, input_section))
+ return bfd_reloc_outofrange;
+
+ if (bfd_is_und_section (symbol->section)
+ && output_bfd == NULL)
+ return bfd_reloc_undefined;
+ if (bfd_is_com_section (symbol->section)
+ || output_bfd != NULL)
+ value = 0;
+ else
+ value = symbol->value;
+
+ /* Only do this for a final link. */
+ if (output_bfd == NULL)
+ {
+ value += symbol->section->output_section->vma;
+ value += symbol->section->output_offset;
+ }
+
+ value += reloc_entry->addend;
+
+ place = (input_section->output_section->vma
+ + input_section->output_offset
+ + (reloc_entry->howto->pcrel_offset ? offset : 0));
+
+ if (reloc_entry->howto->pc_relative)
+ value -= place;
+
+ /* Diagnose mis-aligned (non 4 byte) branch targets. */
+ if (value & 0x3)
+ return bfd_reloc_dangerous;
+
+ status = bfd_check_overflow (reloc_entry->howto->complain_on_overflow,
+ reloc_entry->howto->bitsize,
+ reloc_entry->howto->rightshift,
+ bfd_arch_bits_per_address (input_bfd),
+ value);
+
+ value >>= reloc_entry->howto->rightshift;
+
+ x = bfd_get_32 (input_bfd, data + offset);
+
+ bfd_vma fieldmask = reloc_entry->howto->dst_mask;
+ x = (x & ~fieldmask) | (value & 0x1f) | (((value>>5)&0xfffff)<<12);
+
+ /* Put the relocated value back in the object file. */
+ bfd_put_32 (input_bfd, x, data + offset);
+
+ if (output_bfd != NULL)
+ reloc_entry->address += input_section->output_offset;