forked from bminor/binutils-gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelf64-s390.c
4138 lines (3659 loc) · 126 KB
/
elf64-s390.c
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
/* IBM S/390-specific support for 64-bit ELF
Copyright (C) 2000-2025 Free Software Foundation, Inc.
Contributed Martin Schwidefsky ([email protected]).
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, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
02110-1301, USA. */
#include "sysdep.h"
#include "bfd.h"
#include "bfdlink.h"
#include "libbfd.h"
#include "elf-bfd.h"
#include "elf/s390.h"
#include "elf-s390.h"
#include "dwarf2.h"
#include <stdarg.h>
/* In case we're on a 32-bit machine, construct a 64-bit "-1" value
from smaller values. Start with zero, widen, *then* decrement. */
#define MINUS_ONE (((bfd_vma)0) - 1)
static bfd_reloc_status_type
s390_tls_reloc (bfd *, arelent *, asymbol *, void *,
asection *, bfd *, char **);
static bfd_reloc_status_type
s390_elf_ldisp_reloc (bfd *, arelent *, asymbol *, void *,
asection *, bfd *, char **);
/* The relocation "howto" table. */
static reloc_howto_type elf_howto_table[] =
{
HOWTO (R_390_NONE, /* type */
0, /* rightshift */
0, /* size */
0, /* bitsize */
false, /* pc_relative */
0, /* bitpos */
complain_overflow_dont, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_390_NONE", /* name */
false, /* partial_inplace */
0, /* src_mask */
0, /* dst_mask */
false), /* pcrel_offset */
HOWTO(R_390_8, 0, 1, 8, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_8", false, 0,0x000000ff, false),
HOWTO(R_390_12, 0, 2, 12, false, 0, complain_overflow_dont,
bfd_elf_generic_reloc, "R_390_12", false, 0,0x00000fff, false),
HOWTO(R_390_16, 0, 2, 16, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_16", false, 0,0x0000ffff, false),
HOWTO(R_390_32, 0, 4, 32, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_32", false, 0,0xffffffff, false),
HOWTO(R_390_PC32, 0, 4, 32, true, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_PC32", false, 0,0xffffffff, true),
HOWTO(R_390_GOT12, 0, 2, 12, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_GOT12", false, 0,0x00000fff, false),
HOWTO(R_390_GOT32, 0, 4, 32, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_GOT32", false, 0,0xffffffff, false),
HOWTO(R_390_PLT32, 0, 4, 32, true, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_PLT32", false, 0,0xffffffff, true),
HOWTO(R_390_COPY, 0, 8, 64, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_COPY", false, 0,MINUS_ONE, false),
HOWTO(R_390_GLOB_DAT, 0, 8, 64, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_GLOB_DAT", false, 0,MINUS_ONE, false),
HOWTO(R_390_JMP_SLOT, 0, 8, 64, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_JMP_SLOT", false, 0,MINUS_ONE, false),
HOWTO(R_390_RELATIVE, 0, 8, 64, true, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_RELATIVE", false, 0,MINUS_ONE, false),
HOWTO(R_390_GOTOFF32, 0, 4, 32, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_GOTOFF32", false, 0,MINUS_ONE, false),
HOWTO(R_390_GOTPC, 0, 8, 64, true, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_GOTPC", false, 0,MINUS_ONE, true),
HOWTO(R_390_GOT16, 0, 2, 16, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_GOT16", false, 0,0x0000ffff, false),
HOWTO(R_390_PC16, 0, 2, 16, true, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_PC16", false, 0,0x0000ffff, true),
HOWTO(R_390_PC16DBL, 1, 2, 16, true, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_PC16DBL", false, 0,0x0000ffff, true),
HOWTO(R_390_PLT16DBL, 1, 2, 16, true, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_PLT16DBL", false, 0,0x0000ffff, true),
HOWTO(R_390_PC32DBL, 1, 4, 32, true, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_PC32DBL", false, 0,0xffffffff, true),
HOWTO(R_390_PLT32DBL, 1, 4, 32, true, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_PLT32DBL", false, 0,0xffffffff, true),
HOWTO(R_390_GOTPCDBL, 1, 4, 32, true, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_GOTPCDBL", false, 0,MINUS_ONE, true),
HOWTO(R_390_64, 0, 8, 64, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_64", false, 0,MINUS_ONE, false),
HOWTO(R_390_PC64, 0, 8, 64, true, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_PC64", false, 0,MINUS_ONE, true),
HOWTO(R_390_GOT64, 0, 8, 64, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_GOT64", false, 0,MINUS_ONE, false),
HOWTO(R_390_PLT64, 0, 8, 64, true, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_PLT64", false, 0,MINUS_ONE, true),
HOWTO(R_390_GOTENT, 1, 4, 32, true, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_GOTENT", false, 0,MINUS_ONE, true),
HOWTO(R_390_GOTOFF16, 0, 2, 16, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_GOTOFF16", false, 0,0x0000ffff, false),
HOWTO(R_390_GOTOFF64, 0, 8, 64, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_GOTOFF64", false, 0,MINUS_ONE, false),
HOWTO(R_390_GOTPLT12, 0, 2, 12, false, 0, complain_overflow_dont,
bfd_elf_generic_reloc, "R_390_GOTPLT12", false, 0,0x00000fff, false),
HOWTO(R_390_GOTPLT16, 0, 2, 16, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_GOTPLT16", false, 0,0x0000ffff, false),
HOWTO(R_390_GOTPLT32, 0, 4, 32, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_GOTPLT32", false, 0,0xffffffff, false),
HOWTO(R_390_GOTPLT64, 0, 8, 64, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_GOTPLT64", false, 0,MINUS_ONE, false),
HOWTO(R_390_GOTPLTENT, 1, 4, 32, true, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_GOTPLTENT",false, 0,MINUS_ONE, true),
HOWTO(R_390_PLTOFF16, 0, 2, 16, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_PLTOFF16", false, 0,0x0000ffff, false),
HOWTO(R_390_PLTOFF32, 0, 4, 32, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_PLTOFF32", false, 0,0xffffffff, false),
HOWTO(R_390_PLTOFF64, 0, 8, 64, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_PLTOFF64", false, 0,MINUS_ONE, false),
HOWTO(R_390_TLS_LOAD, 0, 0, 0, false, 0, complain_overflow_dont,
s390_tls_reloc, "R_390_TLS_LOAD", false, 0, 0, false),
HOWTO(R_390_TLS_GDCALL, 0, 0, 0, false, 0, complain_overflow_dont,
s390_tls_reloc, "R_390_TLS_GDCALL", false, 0, 0, false),
HOWTO(R_390_TLS_LDCALL, 0, 0, 0, false, 0, complain_overflow_dont,
s390_tls_reloc, "R_390_TLS_LDCALL", false, 0, 0, false),
EMPTY_HOWTO (R_390_TLS_GD32), /* Empty entry for R_390_TLS_GD32. */
HOWTO(R_390_TLS_GD64, 0, 8, 64, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_TLS_GD64", false, 0, MINUS_ONE, false),
HOWTO(R_390_TLS_GOTIE12, 0, 2, 12, false, 0, complain_overflow_dont,
bfd_elf_generic_reloc, "R_390_TLS_GOTIE12", false, 0, 0x00000fff, false),
EMPTY_HOWTO (R_390_TLS_GOTIE32), /* Empty entry for R_390_TLS_GOTIE32. */
HOWTO(R_390_TLS_GOTIE64, 0, 8, 64, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_TLS_GOTIE64", false, 0, MINUS_ONE, false),
EMPTY_HOWTO (R_390_TLS_LDM32), /* Empty entry for R_390_TLS_LDM32. */
HOWTO(R_390_TLS_LDM64, 0, 8, 64, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_TLS_LDM64", false, 0, MINUS_ONE, false),
EMPTY_HOWTO (R_390_TLS_IE32), /* Empty entry for R_390_TLS_IE32. */
HOWTO(R_390_TLS_IE64, 0, 8, 64, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_TLS_IE64", false, 0, MINUS_ONE, false),
HOWTO(R_390_TLS_IEENT, 1, 4, 32, true, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_TLS_IEENT", false, 0, MINUS_ONE, true),
EMPTY_HOWTO (R_390_TLS_LE32), /* Empty entry for R_390_TLS_LE32. */
HOWTO(R_390_TLS_LE64, 0, 4, 32, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_TLS_LE64", false, 0, MINUS_ONE, false),
EMPTY_HOWTO (R_390_TLS_LDO32), /* Empty entry for R_390_TLS_LDO32. */
HOWTO(R_390_TLS_LDO64, 0, 8, 64, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_TLS_LDO64", false, 0, MINUS_ONE, false),
HOWTO(R_390_TLS_DTPMOD, 0, 8, 64, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_TLS_DTPMOD", false, 0, MINUS_ONE, false),
HOWTO(R_390_TLS_DTPOFF, 0, 8, 64, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_TLS_DTPOFF", false, 0, MINUS_ONE, false),
HOWTO(R_390_TLS_TPOFF, 0, 8, 64, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_TLS_TPOFF", false, 0, MINUS_ONE, false),
HOWTO(R_390_20, 0, 4, 20, false, 8, complain_overflow_dont,
s390_elf_ldisp_reloc, "R_390_20", false, 0,0x0fffff00, false),
HOWTO(R_390_GOT20, 0, 4, 20, false, 8, complain_overflow_dont,
s390_elf_ldisp_reloc, "R_390_GOT20", false, 0,0x0fffff00, false),
HOWTO(R_390_GOTPLT20, 0, 4, 20, false, 8, complain_overflow_dont,
s390_elf_ldisp_reloc, "R_390_GOTPLT20", false, 0,0x0fffff00, false),
HOWTO(R_390_TLS_GOTIE20, 0, 4, 20, false, 8, complain_overflow_dont,
s390_elf_ldisp_reloc, "R_390_TLS_GOTIE20", false, 0,0x0fffff00, false),
HOWTO(R_390_IRELATIVE, 0, 8, 64, false, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_IRELATIVE", false, 0, MINUS_ONE, false),
HOWTO(R_390_PC12DBL, 1, 2, 12, true, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_PC12DBL", false, 0,0x00000fff, true),
HOWTO(R_390_PLT12DBL, 1, 2, 12, true, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_PLT12DBL", false, 0,0x00000fff, true),
HOWTO(R_390_PC24DBL, 1, 4, 24, true, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_PC24DBL", false, 0,0x00ffffff, true),
HOWTO(R_390_PLT24DBL, 1, 4, 24, true, 0, complain_overflow_bitfield,
bfd_elf_generic_reloc, "R_390_PLT24DBL", false, 0,0x00ffffff, true),
};
/* GNU extension to record C++ vtable hierarchy. */
static reloc_howto_type elf64_s390_vtinherit_howto =
HOWTO (R_390_GNU_VTINHERIT, 0,8,0,false,0,complain_overflow_dont, NULL, "R_390_GNU_VTINHERIT", false,0, 0, false);
static reloc_howto_type elf64_s390_vtentry_howto =
HOWTO (R_390_GNU_VTENTRY, 0,8,0,false,0,complain_overflow_dont, _bfd_elf_rel_vtable_reloc_fn,"R_390_GNU_VTENTRY", false,0,0, false);
static reloc_howto_type *
elf_s390_reloc_type_lookup (bfd *abfd,
bfd_reloc_code_real_type code)
{
switch (code)
{
case BFD_RELOC_NONE:
return &elf_howto_table[(int) R_390_NONE];
case BFD_RELOC_8:
return &elf_howto_table[(int) R_390_8];
case BFD_RELOC_390_12:
return &elf_howto_table[(int) R_390_12];
case BFD_RELOC_16:
return &elf_howto_table[(int) R_390_16];
case BFD_RELOC_32:
return &elf_howto_table[(int) R_390_32];
case BFD_RELOC_CTOR:
return &elf_howto_table[(int) R_390_32];
case BFD_RELOC_32_PCREL:
return &elf_howto_table[(int) R_390_PC32];
case BFD_RELOC_390_GOT12:
return &elf_howto_table[(int) R_390_GOT12];
case BFD_RELOC_32_GOT_PCREL:
return &elf_howto_table[(int) R_390_GOT32];
case BFD_RELOC_390_PLT32:
return &elf_howto_table[(int) R_390_PLT32];
case BFD_RELOC_390_COPY:
return &elf_howto_table[(int) R_390_COPY];
case BFD_RELOC_390_GLOB_DAT:
return &elf_howto_table[(int) R_390_GLOB_DAT];
case BFD_RELOC_390_JMP_SLOT:
return &elf_howto_table[(int) R_390_JMP_SLOT];
case BFD_RELOC_390_RELATIVE:
return &elf_howto_table[(int) R_390_RELATIVE];
case BFD_RELOC_32_GOTOFF:
return &elf_howto_table[(int) R_390_GOTOFF32];
case BFD_RELOC_390_GOTPC:
return &elf_howto_table[(int) R_390_GOTPC];
case BFD_RELOC_390_GOT16:
return &elf_howto_table[(int) R_390_GOT16];
case BFD_RELOC_16_PCREL:
return &elf_howto_table[(int) R_390_PC16];
case BFD_RELOC_390_PC12DBL:
return &elf_howto_table[(int) R_390_PC12DBL];
case BFD_RELOC_390_PLT12DBL:
return &elf_howto_table[(int) R_390_PLT12DBL];
case BFD_RELOC_390_PC16DBL:
return &elf_howto_table[(int) R_390_PC16DBL];
case BFD_RELOC_390_PLT16DBL:
return &elf_howto_table[(int) R_390_PLT16DBL];
case BFD_RELOC_390_PC24DBL:
return &elf_howto_table[(int) R_390_PC24DBL];
case BFD_RELOC_390_PLT24DBL:
return &elf_howto_table[(int) R_390_PLT24DBL];
case BFD_RELOC_390_PC32DBL:
return &elf_howto_table[(int) R_390_PC32DBL];
case BFD_RELOC_390_PLT32DBL:
return &elf_howto_table[(int) R_390_PLT32DBL];
case BFD_RELOC_390_GOTPCDBL:
return &elf_howto_table[(int) R_390_GOTPCDBL];
case BFD_RELOC_64:
return &elf_howto_table[(int) R_390_64];
case BFD_RELOC_64_PCREL:
return &elf_howto_table[(int) R_390_PC64];
case BFD_RELOC_390_GOT64:
return &elf_howto_table[(int) R_390_GOT64];
case BFD_RELOC_390_PLT64:
return &elf_howto_table[(int) R_390_PLT64];
case BFD_RELOC_390_GOTENT:
return &elf_howto_table[(int) R_390_GOTENT];
case BFD_RELOC_16_GOTOFF:
return &elf_howto_table[(int) R_390_GOTOFF16];
case BFD_RELOC_390_GOTOFF64:
return &elf_howto_table[(int) R_390_GOTOFF64];
case BFD_RELOC_390_GOTPLT12:
return &elf_howto_table[(int) R_390_GOTPLT12];
case BFD_RELOC_390_GOTPLT16:
return &elf_howto_table[(int) R_390_GOTPLT16];
case BFD_RELOC_390_GOTPLT32:
return &elf_howto_table[(int) R_390_GOTPLT32];
case BFD_RELOC_390_GOTPLT64:
return &elf_howto_table[(int) R_390_GOTPLT64];
case BFD_RELOC_390_GOTPLTENT:
return &elf_howto_table[(int) R_390_GOTPLTENT];
case BFD_RELOC_390_PLTOFF16:
return &elf_howto_table[(int) R_390_PLTOFF16];
case BFD_RELOC_390_PLTOFF32:
return &elf_howto_table[(int) R_390_PLTOFF32];
case BFD_RELOC_390_PLTOFF64:
return &elf_howto_table[(int) R_390_PLTOFF64];
case BFD_RELOC_390_TLS_LOAD:
return &elf_howto_table[(int) R_390_TLS_LOAD];
case BFD_RELOC_390_TLS_GDCALL:
return &elf_howto_table[(int) R_390_TLS_GDCALL];
case BFD_RELOC_390_TLS_LDCALL:
return &elf_howto_table[(int) R_390_TLS_LDCALL];
case BFD_RELOC_390_TLS_GD64:
return &elf_howto_table[(int) R_390_TLS_GD64];
case BFD_RELOC_390_TLS_GOTIE12:
return &elf_howto_table[(int) R_390_TLS_GOTIE12];
case BFD_RELOC_390_TLS_GOTIE64:
return &elf_howto_table[(int) R_390_TLS_GOTIE64];
case BFD_RELOC_390_TLS_LDM64:
return &elf_howto_table[(int) R_390_TLS_LDM64];
case BFD_RELOC_390_TLS_IE64:
return &elf_howto_table[(int) R_390_TLS_IE64];
case BFD_RELOC_390_TLS_IEENT:
return &elf_howto_table[(int) R_390_TLS_IEENT];
case BFD_RELOC_390_TLS_LE64:
return &elf_howto_table[(int) R_390_TLS_LE64];
case BFD_RELOC_390_TLS_LDO64:
return &elf_howto_table[(int) R_390_TLS_LDO64];
case BFD_RELOC_390_TLS_DTPMOD:
return &elf_howto_table[(int) R_390_TLS_DTPMOD];
case BFD_RELOC_390_TLS_DTPOFF:
return &elf_howto_table[(int) R_390_TLS_DTPOFF];
case BFD_RELOC_390_TLS_TPOFF:
return &elf_howto_table[(int) R_390_TLS_TPOFF];
case BFD_RELOC_390_20:
return &elf_howto_table[(int) R_390_20];
case BFD_RELOC_390_GOT20:
return &elf_howto_table[(int) R_390_GOT20];
case BFD_RELOC_390_GOTPLT20:
return &elf_howto_table[(int) R_390_GOTPLT20];
case BFD_RELOC_390_TLS_GOTIE20:
return &elf_howto_table[(int) R_390_TLS_GOTIE20];
case BFD_RELOC_390_IRELATIVE:
return &elf_howto_table[(int) R_390_IRELATIVE];
case BFD_RELOC_VTABLE_INHERIT:
return &elf64_s390_vtinherit_howto;
case BFD_RELOC_VTABLE_ENTRY:
return &elf64_s390_vtentry_howto;
default:
break;
}
/* xgettext:c-format */
_bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, (int) code);
bfd_set_error (bfd_error_bad_value);
return NULL;
}
static reloc_howto_type *
elf_s390_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
const char *r_name)
{
unsigned int i;
for (i = 0;
i < sizeof (elf_howto_table) / sizeof (elf_howto_table[0]);
i++)
if (elf_howto_table[i].name != NULL
&& strcasecmp (elf_howto_table[i].name, r_name) == 0)
return &elf_howto_table[i];
if (strcasecmp (elf64_s390_vtinherit_howto.name, r_name) == 0)
return &elf64_s390_vtinherit_howto;
if (strcasecmp (elf64_s390_vtentry_howto.name, r_name) == 0)
return &elf64_s390_vtentry_howto;
return NULL;
}
/* We need to use ELF64_R_TYPE so we have our own copy of this function,
and elf64-s390.c has its own copy. */
static bool
elf_s390_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
arelent *cache_ptr,
Elf_Internal_Rela *dst)
{
unsigned int r_type = ELF64_R_TYPE(dst->r_info);
switch (r_type)
{
case R_390_GNU_VTINHERIT:
cache_ptr->howto = &elf64_s390_vtinherit_howto;
break;
case R_390_GNU_VTENTRY:
cache_ptr->howto = &elf64_s390_vtentry_howto;
break;
default:
if (r_type >= sizeof (elf_howto_table) / sizeof (elf_howto_table[0]))
{
/* 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 = &elf_howto_table[r_type];
}
return true;
}
/* A relocation function which doesn't do anything. */
static bfd_reloc_status_type
s390_tls_reloc (bfd *abfd ATTRIBUTE_UNUSED,
arelent *reloc_entry,
asymbol *symbol ATTRIBUTE_UNUSED,
void * data ATTRIBUTE_UNUSED,
asection *input_section,
bfd *output_bfd,
char **error_message ATTRIBUTE_UNUSED)
{
if (output_bfd)
reloc_entry->address += input_section->output_offset;
return bfd_reloc_ok;
}
/* Handle the large displacement relocs. */
static bfd_reloc_status_type
s390_elf_ldisp_reloc (bfd *abfd,
arelent *reloc_entry,
asymbol *symbol,
void * data,
asection *input_section,
bfd *output_bfd,
char **error_message ATTRIBUTE_UNUSED)
{
reloc_howto_type *howto = reloc_entry->howto;
bfd_vma relocation;
bfd_vma insn;
if (output_bfd != (bfd *) NULL
&& (symbol->flags & BSF_SECTION_SYM) == 0
&& (! howto->partial_inplace
|| reloc_entry->addend == 0))
{
reloc_entry->address += input_section->output_offset;
return bfd_reloc_ok;
}
if (output_bfd != NULL)
return bfd_reloc_continue;
if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
relocation = (symbol->value
+ symbol->section->output_section->vma
+ symbol->section->output_offset);
relocation += reloc_entry->addend;
if (howto->pc_relative)
{
relocation -= (input_section->output_section->vma
+ input_section->output_offset);
relocation -= reloc_entry->address;
}
insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
insn |= (relocation & 0xfff) << 16 | (relocation & 0xff000) >> 4;
bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
if ((bfd_signed_vma) relocation < - 0x80000
|| (bfd_signed_vma) relocation > 0x7ffff)
return bfd_reloc_overflow;
else
return bfd_reloc_ok;
}
static bool
elf_s390_is_local_label_name (bfd *abfd, const char *name)
{
if (name[0] == '.' && (name[1] == 'X' || name[1] == 'L'))
return true;
return _bfd_elf_is_local_label_name (abfd, name);
}
/* Functions for the 390 ELF linker. */
/* The name of the dynamic interpreter. This is put in the .interp
section. */
#define ELF_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
/* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
copying dynamic variables from a shared lib into an app's dynbss
section, and instead use a dynamic relocation to point into the
shared lib. */
#define ELIMINATE_COPY_RELOCS 1
/* The size in bytes of the first entry in the procedure linkage table. */
#define PLT_FIRST_ENTRY_SIZE 32
/* The size in bytes of an entry in the procedure linkage table. */
#define PLT_ENTRY_SIZE 32
#define GOT_ENTRY_SIZE 8
#define RELA_ENTRY_SIZE sizeof (Elf64_External_Rela)
/* The first three entries in a global offset table are reserved,
and the initial contents are unimportant (we zero them out).
Subsequent entries look like this. See the SVR4 ABI 386
supplement to see how this works. */
/* For the s390, simple addr offset can only be 0 - 4096.
To use the full 16777216 TB address space, several instructions
are needed to load an address in a register and execute
a branch( or just saving the address)
Furthermore, only r 0 and 1 are free to use!!! */
/* The first 3 words in the GOT are then reserved.
Word 0 is the address of the dynamic table.
Word 1 is a pointer to a structure describing the object
Word 2 is used to point to the loader entry address.
The code for PLT entries looks like this:
The GOT holds the address in the PLT to be executed.
The loader then gets:
48(15) = Pointer to the structure describing the object.
56(15) = Offset in symbol table
The loader must then find the module where the function is
and insert the address in the GOT.
PLT1: LARL 1,<fn>@GOTENT # 6 bytes Load address of GOT entry in r1
LG 1,0(1) # 6 bytes Load address from GOT in r1
BCR 15,1 # 2 bytes Jump to address
RET1: BASR 1,0 # 2 bytes Return from GOT 1st time
LGF 1,12(1) # 6 bytes Load rela.plt offset into r1
BRCL 15,-x # 6 bytes Jump to first PLT entry
.long ? # 4 bytes offset into .rela.plt
Total = 32 bytes per PLT entry
Fixup at offset 2: relative address to GOT entry
Fixup at offset 22: relative branch to PLT0
Fixup at offset 28: 32 bit offset into .rela.plt
A 32 bit offset into the symbol table is enough. It allows for
.rela.plt sections up to a size of 2 gigabyte. A single dynamic
object (the main program, any shared library) is limited to 4GB in
size. Having a .rela.plt of 2GB would already make the .plt
section bigger than 8GB. */
static const bfd_byte elf_s390x_plt_entry[PLT_ENTRY_SIZE] =
{
0xc0, 0x10, 0x00, 0x00, 0x00, 0x00, /* larl %r1,. */
0xe3, 0x10, 0x10, 0x00, 0x00, 0x04, /* lg %r1,0(%r1) */
0x07, 0xf1, /* br %r1 */
0x0d, 0x10, /* basr %r1,%r0 */
0xe3, 0x10, 0x10, 0x0c, 0x00, 0x14, /* lgf %r1,12(%r1) */
0xc0, 0xf4, 0x00, 0x00, 0x00, 0x00, /* jg first plt */
0x00, 0x00, 0x00, 0x00 /* .long 0x00000000 */
};
/* The first PLT entry pushes the offset into the symbol table
from R1 onto the stack at 56(15) and the loader object info
at 48(15), loads the loader address in R1 and jumps to it. */
/* The first entry in the PLT:
PLT0:
STG 1,56(15) # r1 contains the offset into the symbol table
LARL 1,_GLOBAL_OFFSET_TABLE # load address of global offset table
MVC 48(8,15),8(1) # move loader ino (object struct address) to stack
LG 1,16(1) # get entry address of loader
BCR 15,1 # jump to loader
Fixup at offset 8: relative address to start of GOT. */
static const bfd_byte elf_s390x_first_plt_entry[PLT_FIRST_ENTRY_SIZE] =
{
0xe3, 0x10, 0xf0, 0x38, 0x00, 0x24, /* stg %r1,56(%r15) */
0xc0, 0x10, 0x00, 0x00, 0x00, 0x00, /* larl %r1,. */
0xd2, 0x07, 0xf0, 0x30, 0x10, 0x08, /* mvc 48(8,%r15),8(%r1) */
0xe3, 0x10, 0x10, 0x10, 0x00, 0x04, /* lg %r1,16(%r1) */
0x07, 0xf1, /* br %r1 */
0x07, 0x00, /* nopr %r0 */
0x07, 0x00, /* nopr %r0 */
0x07, 0x00 /* nopr %r0 */
};
/* .eh_frame covering the .plt section. */
#define PLT_CIE_SIZE 24
#define PLT_FDE_SIZE 20
#define PLT_FDE_START_OFFSET (PLT_CIE_SIZE + 8)
#define PLT_FDE_LEN_OFFSET (PLT_CIE_SIZE + 12)
static const bfd_byte elf_s390x_eh_frame_plt[] =
{
0, 0, 0, PLT_CIE_SIZE - 4, /* CIE length */
0, 0, 0, 0, /* CIE ID */
1, /* CIE version */
'z', 'R', 0, /* Augmentation string */
1, /* Code alignment factor */
0x78, /* Data alignment factor */
14, /* Return address column */
1, /* Augmentation size */
DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
DW_CFA_def_cfa, 15, 0xa0, 0x01, /* DW_CFA_def_cfa: r15 ofs 160 */
DW_CFA_nop, DW_CFA_nop, DW_CFA_nop,
0, 0, 0, PLT_FDE_SIZE - 4, /* FDE length */
0, 0, 0, PLT_CIE_SIZE + 4, /* CIE pointer */
0, 0, 0, 0, /* R_S390_PC32 .plt goes here */
0, 0, 0, 0, /* .plt size goes here */
0, /* Augmentation size */
DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
};
/* s390 ELF linker hash entry. */
struct elf_s390_link_hash_entry
{
struct elf_link_hash_entry elf;
/* Number of GOTPLT references for a function. */
bfd_signed_vma gotplt_refcount;
#define GOT_UNKNOWN 0
#define GOT_NORMAL 1
#define GOT_TLS_GD 2
#define GOT_TLS_IE 3
#define GOT_TLS_IE_NLT 3
unsigned char tls_type;
/* For pointer equality reasons we might need to change the symbol
type from STT_GNU_IFUNC to STT_FUNC together with its value and
section entry. So after alloc_dynrelocs only these values should
be used. In order to check whether a symbol is IFUNC use
s390_is_ifunc_symbol_p. */
bfd_vma ifunc_resolver_address;
asection *ifunc_resolver_section;
};
#define elf_s390_hash_entry(ent) \
((struct elf_s390_link_hash_entry *)(ent))
/* This structure represents an entry in the local PLT list needed for
local IFUNC symbols. */
struct plt_entry
{
/* The section of the local symbol.
Set in relocate_section and used in finish_dynamic_sections. */
asection *sec;
union
{
bfd_signed_vma refcount;
bfd_vma offset;
} plt;
};
/* NOTE: Keep this structure in sync with
the one declared in elf32-s390.c. */
struct elf_s390_obj_tdata
{
struct elf_obj_tdata root;
/* A local PLT is needed for ifunc symbols. */
struct plt_entry *local_plt;
/* TLS type for each local got entry. */
char *local_got_tls_type;
};
#define elf_s390_tdata(abfd) \
((struct elf_s390_obj_tdata *) (abfd)->tdata.any)
#define elf_s390_local_plt(abfd) \
(elf_s390_tdata (abfd)->local_plt)
#define elf_s390_local_got_tls_type(abfd) \
(elf_s390_tdata (abfd)->local_got_tls_type)
#define is_s390_elf(bfd) \
(bfd_get_flavour (bfd) == bfd_target_elf_flavour \
&& elf_tdata (bfd) != NULL \
&& elf_object_id (bfd) == S390_ELF_DATA)
static bool
elf_s390_mkobject (bfd *abfd)
{
return bfd_elf_allocate_object (abfd, sizeof (struct elf_s390_obj_tdata));
}
static bool
elf_s390_object_p (bfd *abfd)
{
/* Set the right machine number for an s390 elf32 file. */
return bfd_default_set_arch_mach (abfd, bfd_arch_s390, bfd_mach_s390_64);
}
/* s390 ELF linker hash table. */
struct elf_s390_link_hash_table
{
struct elf_link_hash_table elf;
/* Short-cuts to get to dynamic linker sections. */
asection *irelifunc;
asection *plt_eh_frame;
union {
bfd_signed_vma refcount;
bfd_vma offset;
} tls_ldm_got;
/* Options passed from the linker. */
struct s390_elf_params *params;
};
/* Get the s390 ELF linker hash table from a link_info structure. */
#define elf_s390_hash_table(p) \
((is_elf_hash_table ((p)->hash) \
&& elf_hash_table_id (elf_hash_table (p)) == S390_ELF_DATA) \
? (struct elf_s390_link_hash_table *) (p)->hash : NULL)
#define ELF64 1
#include "elf-s390-common.c"
/* Create an entry in an s390 ELF linker hash table. */
static struct bfd_hash_entry *
link_hash_newfunc (struct bfd_hash_entry *entry,
struct bfd_hash_table *table,
const char *string)
{
/* Allocate the structure if it has not already been allocated by a
subclass. */
if (entry == NULL)
{
entry = bfd_hash_allocate (table,
sizeof (struct elf_s390_link_hash_entry));
if (entry == NULL)
return entry;
}
/* Call the allocation method of the superclass. */
entry = _bfd_elf_link_hash_newfunc (entry, table, string);
if (entry != NULL)
{
struct elf_s390_link_hash_entry *eh;
eh = (struct elf_s390_link_hash_entry *) entry;
eh->gotplt_refcount = 0;
eh->tls_type = GOT_UNKNOWN;
eh->ifunc_resolver_address = 0;
eh->ifunc_resolver_section = NULL;
}
return entry;
}
/* Create an s390 ELF linker hash table. */
static struct bfd_link_hash_table *
elf_s390_link_hash_table_create (bfd *abfd)
{
struct elf_s390_link_hash_table *ret;
size_t amt = sizeof (struct elf_s390_link_hash_table);
ret = (struct elf_s390_link_hash_table *) bfd_zmalloc (amt);
if (ret == NULL)
return NULL;
if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc,
sizeof (struct elf_s390_link_hash_entry)))
{
free (ret);
return NULL;
}
return &ret->elf.root;
}
/* Copy the extra info we tack onto an elf_link_hash_entry. */
static void
elf_s390_copy_indirect_symbol (struct bfd_link_info *info,
struct elf_link_hash_entry *dir,
struct elf_link_hash_entry *ind)
{
struct elf_s390_link_hash_entry *edir, *eind;
edir = (struct elf_s390_link_hash_entry *) dir;
eind = (struct elf_s390_link_hash_entry *) ind;
if (ind->root.type == bfd_link_hash_indirect
&& dir->got.refcount <= 0)
{
edir->tls_type = eind->tls_type;
eind->tls_type = GOT_UNKNOWN;
}
if (ELIMINATE_COPY_RELOCS
&& ind->root.type != bfd_link_hash_indirect
&& dir->dynamic_adjusted)
{
/* If called to transfer flags for a weakdef during processing
of elf_adjust_dynamic_symbol, don't copy non_got_ref.
We clear it ourselves for ELIMINATE_COPY_RELOCS. */
if (dir->versioned != versioned_hidden)
dir->ref_dynamic |= ind->ref_dynamic;
dir->ref_regular |= ind->ref_regular;
dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
dir->needs_plt |= ind->needs_plt;
}
else
_bfd_elf_link_hash_copy_indirect (info, dir, ind);
}
static int
elf_s390_tls_transition (struct bfd_link_info *info,
int r_type,
int is_local)
{
if (bfd_link_dll (info))
return r_type;
switch (r_type)
{
case R_390_TLS_GD64:
case R_390_TLS_IE64:
if (is_local)
return R_390_TLS_LE64;
return R_390_TLS_IE64;
case R_390_TLS_GOTIE64:
if (is_local)
return R_390_TLS_LE64;
return R_390_TLS_GOTIE64;
case R_390_TLS_LDM64:
return R_390_TLS_LE64;
}
return r_type;
}
/* Look through the relocs for a section during the first phase, and
allocate space in the global offset table or procedure linkage
table. */
static bool
elf_s390_check_relocs (bfd *abfd,
struct bfd_link_info *info,
asection *sec,
const Elf_Internal_Rela *relocs)
{
struct elf_s390_link_hash_table *htab;
Elf_Internal_Shdr *symtab_hdr;
struct elf_link_hash_entry **sym_hashes;
const Elf_Internal_Rela *rel;
const Elf_Internal_Rela *rel_end;
asection *sreloc;
bfd_signed_vma *local_got_refcounts;
int tls_type, old_tls_type;
if (bfd_link_relocatable (info))
return true;
BFD_ASSERT (is_s390_elf (abfd));
htab = elf_s390_hash_table (info);
if (htab == NULL)
return false;
symtab_hdr = &elf_symtab_hdr (abfd);
sym_hashes = elf_sym_hashes (abfd);
local_got_refcounts = elf_local_got_refcounts (abfd);
sreloc = NULL;
rel_end = relocs + sec->reloc_count;
for (rel = relocs; rel < rel_end; rel++)
{
unsigned int r_type;
unsigned int r_symndx;
struct elf_link_hash_entry *h;
Elf_Internal_Sym *isym;
r_symndx = ELF64_R_SYM (rel->r_info);
if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
{
/* xgettext:c-format */
_bfd_error_handler (_("%pB: bad symbol index: %d"),
abfd, r_symndx);
return false;
}
if (r_symndx < symtab_hdr->sh_info)
{
/* A local symbol. */
isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache,
abfd, r_symndx);
if (isym == NULL)
return false;
if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
{
struct plt_entry *plt;
if (htab->elf.dynobj == NULL)
htab->elf.dynobj = abfd;
if (!s390_elf_create_ifunc_sections (htab->elf.dynobj, info))
return false;
if (local_got_refcounts == NULL)
{
if (!elf_s390_allocate_local_syminfo (abfd, symtab_hdr))
return false;
local_got_refcounts = elf_local_got_refcounts (abfd);
}
plt = elf_s390_local_plt (abfd);
plt[r_symndx].plt.refcount++;
}
h = NULL;
}
else
{
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
while (h->root.type == bfd_link_hash_indirect
|| h->root.type == bfd_link_hash_warning)
h = (struct elf_link_hash_entry *) h->root.u.i.link;
}
/* Create got section and local_got_refcounts array if they
are needed. */
r_type = elf_s390_tls_transition (info,
ELF64_R_TYPE (rel->r_info),
h == NULL);
switch (r_type)
{
case R_390_GOT12:
case R_390_GOT16:
case R_390_GOT20:
case R_390_GOT32:
case R_390_GOT64:
case R_390_GOTENT:
case R_390_GOTPLT12:
case R_390_GOTPLT16:
case R_390_GOTPLT20:
case R_390_GOTPLT32:
case R_390_GOTPLT64:
case R_390_GOTPLTENT:
case R_390_TLS_GD64:
case R_390_TLS_GOTIE12:
case R_390_TLS_GOTIE20:
case R_390_TLS_GOTIE64:
case R_390_TLS_IEENT:
case R_390_TLS_IE64:
case R_390_TLS_LDM64:
if (h == NULL
&& local_got_refcounts == NULL)
{
if (!elf_s390_allocate_local_syminfo (abfd, symtab_hdr))
return false;
local_got_refcounts = elf_local_got_refcounts (abfd);
}
/* Fall through. */
case R_390_GOTOFF16:
case R_390_GOTOFF32:
case R_390_GOTOFF64:
case R_390_GOTPC:
case R_390_GOTPCDBL:
if (htab->elf.sgot == NULL)
{
if (htab->elf.dynobj == NULL)
htab->elf.dynobj = abfd;
if (!_bfd_elf_create_got_section (htab->elf.dynobj, info))
return false;
}
}
if (h != NULL)
{
if (htab->elf.dynobj == NULL)
htab->elf.dynobj = abfd;
if (!s390_elf_create_ifunc_sections (htab->elf.dynobj, info))
return false;
/* Make sure an IFUNC symbol defined in a non-shared object
always gets a PLT slot. */
if (s390_is_ifunc_symbol_p (h) && h->def_regular)
{
/* The symbol is called by the dynamic loader in order
to resolve the relocation. So it is in fact also
referenced. */
h->ref_regular = 1;
h->needs_plt = 1;
}
}
switch (r_type)
{
case R_390_GOTPC:
case R_390_GOTPCDBL:
/* These relocs do not need a GOT slot. They just load the
GOT pointer itself or address something else relative to
the GOT. Since the GOT pointer has been set up above we
are done. */
break;
case R_390_GOTOFF16:
case R_390_GOTOFF32:
case R_390_GOTOFF64:
if (h == NULL || !s390_is_ifunc_symbol_p (h) || !h->def_regular)
break;
/* Fall through. */
case R_390_PLT12DBL: