forked from bminor/binutils-gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoff64-rs6000.c
2982 lines (2629 loc) · 85.8 KB
/
coff64-rs6000.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
/* BFD back-end for IBM RS/6000 "XCOFF64" files.
Copyright (C) 2000-2025 Free Software Foundation, Inc.
Written Clinton Popetz.
Contributed by Cygnus Support.
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 "coff/internal.h"
#include "coff/xcoff.h"
#include "coff/rs6k64.h"
#include "libcoff.h"
#include "libxcoff.h"
#define GET_FILEHDR_SYMPTR H_GET_64
#define PUT_FILEHDR_SYMPTR H_PUT_64
#define GET_AOUTHDR_DATA_START H_GET_64
#define PUT_AOUTHDR_DATA_START H_PUT_64
#define GET_AOUTHDR_TEXT_START H_GET_64
#define PUT_AOUTHDR_TEXT_START H_PUT_64
#define GET_AOUTHDR_TSIZE H_GET_64
#define PUT_AOUTHDR_TSIZE H_PUT_64
#define GET_AOUTHDR_DSIZE H_GET_64
#define PUT_AOUTHDR_DSIZE H_PUT_64
#define GET_AOUTHDR_BSIZE H_GET_64
#define PUT_AOUTHDR_BSIZE H_PUT_64
#define GET_AOUTHDR_ENTRY H_GET_64
#define PUT_AOUTHDR_ENTRY H_PUT_64
#define GET_SCNHDR_PADDR H_GET_64
#define PUT_SCNHDR_PADDR H_PUT_64
#define GET_SCNHDR_VADDR H_GET_64
#define PUT_SCNHDR_VADDR H_PUT_64
#define GET_SCNHDR_SIZE H_GET_64
#define PUT_SCNHDR_SIZE H_PUT_64
#define GET_SCNHDR_SCNPTR H_GET_64
#define PUT_SCNHDR_SCNPTR H_PUT_64
#define GET_SCNHDR_RELPTR H_GET_64
#define PUT_SCNHDR_RELPTR H_PUT_64
#define GET_SCNHDR_LNNOPTR H_GET_64
#define PUT_SCNHDR_LNNOPTR H_PUT_64
#define GET_SCNHDR_NRELOC H_GET_32
#define MAX_SCNHDR_NRELOC 0xffffffff
#define PUT_SCNHDR_NRELOC H_PUT_32
#define GET_SCNHDR_NLNNO H_GET_32
#define MAX_SCNHDR_NLNNO 0xffffffff
#define PUT_SCNHDR_NLNNO H_PUT_32
#define GET_RELOC_VADDR H_GET_64
#define PUT_RELOC_VADDR H_PUT_64
#define COFF_FORCE_SYMBOLS_IN_STRINGS
#define COFF_DEBUG_STRING_WIDE_PREFIX
#define COFF_ADJUST_SCNHDR_OUT_POST(ABFD, INT, EXT) \
do \
{ \
memset (((SCNHDR *) EXT)->s_pad, 0, \
sizeof (((SCNHDR *) EXT)->s_pad)); \
} \
while (0)
#define NO_COFF_LINENOS
#define coff_SWAP_lineno_in _bfd_xcoff64_swap_lineno_in
#define coff_SWAP_lineno_out _bfd_xcoff64_swap_lineno_out
static void _bfd_xcoff64_swap_lineno_in
(bfd *, void *, void *);
static unsigned int _bfd_xcoff64_swap_lineno_out
(bfd *, void *, void *);
static bool _bfd_xcoff64_put_symbol_name
(struct bfd_link_info *, struct bfd_strtab_hash *,
struct internal_syment *, const char *);
static bool _bfd_xcoff64_put_ldsymbol_name
(bfd *, struct xcoff_loader_info *, struct internal_ldsym *, const char *);
static void _bfd_xcoff64_swap_sym_in
(bfd *, void *, void *);
static unsigned int _bfd_xcoff64_swap_sym_out
(bfd *, void *, void *);
static void _bfd_xcoff64_swap_aux_in
(bfd *, void *, int, int, int, int, void *);
static unsigned int _bfd_xcoff64_swap_aux_out
(bfd *, void *, int, int, int, int, void *);
static void xcoff64_swap_reloc_in
(bfd *, void *, void *);
static unsigned int xcoff64_swap_reloc_out
(bfd *, void *, void *);
extern bool _bfd_xcoff_mkobject
(bfd *);
extern bool _bfd_xcoff_copy_private_bfd_data
(bfd *, bfd *);
extern bool _bfd_xcoff_is_local_label_name
(bfd *, const char *);
extern void xcoff64_rtype2howto
(arelent *, struct internal_reloc *);
extern reloc_howto_type * xcoff64_reloc_type_lookup
(bfd *, bfd_reloc_code_real_type);
extern bool _bfd_xcoff_slurp_armap
(bfd *);
extern void *_bfd_xcoff_read_ar_hdr
(bfd *);
extern bfd *_bfd_xcoff_openr_next_archived_file
(bfd *, bfd *);
extern int _bfd_xcoff_stat_arch_elt
(bfd *, struct stat *);
extern bool _bfd_xcoff_write_armap
(bfd *, unsigned int, struct orl *, unsigned int, int);
extern bool _bfd_xcoff_write_archive_contents
(bfd *);
extern int _bfd_xcoff_sizeof_headers
(bfd *, struct bfd_link_info *);
extern void _bfd_xcoff_swap_sym_in
(bfd *, void *, void *);
extern unsigned int _bfd_xcoff_swap_sym_out
(bfd *, void *, void *);
extern void _bfd_xcoff_swap_aux_in
(bfd *, void *, int, int, int, int, void *);
extern unsigned int _bfd_xcoff_swap_aux_out
(bfd *, void *, int, int, int, int, void *);
static void xcoff64_swap_ldhdr_in
(bfd *, const void *, struct internal_ldhdr *);
static void xcoff64_swap_ldhdr_out
(bfd *, const struct internal_ldhdr *, void *d);
static void xcoff64_swap_ldsym_in
(bfd *, const void *, struct internal_ldsym *);
static void xcoff64_swap_ldsym_out
(bfd *, const struct internal_ldsym *, void *d);
static void xcoff64_swap_ldrel_in
(bfd *, const void *, struct internal_ldrel *);
static void xcoff64_swap_ldrel_out
(bfd *, const struct internal_ldrel *, void *d);
static bool xcoff64_ppc_relocate_section
(bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
struct internal_reloc *, struct internal_syment *,
asection **);
static bool xcoff64_slurp_armap
(bfd *);
static bfd_cleanup xcoff64_archive_p
(bfd *);
static bfd *xcoff64_openr_next_archived_file
(bfd *, bfd *);
static int xcoff64_sizeof_headers
(bfd *, struct bfd_link_info *);
static asection *xcoff64_create_csect_from_smclas
(bfd *, union internal_auxent *, const char *);
static bool xcoff64_is_lineno_count_overflow
(bfd *, bfd_vma);
static bool xcoff64_is_reloc_count_overflow
(bfd *, bfd_vma);
static bfd_vma xcoff64_loader_symbol_offset
(bfd *, struct internal_ldhdr *);
static bfd_vma xcoff64_loader_reloc_offset
(bfd *, struct internal_ldhdr *);
static bool xcoff64_generate_rtinit
(bfd *, const char *, const char *, bool);
static bool xcoff64_bad_format_hook
(bfd *, void *);
/* Relocation functions */
static xcoff_reloc_function xcoff64_reloc_type_br;
xcoff_reloc_function *const
xcoff64_calculate_relocation[XCOFF_MAX_CALCULATE_RELOCATION] =
{
xcoff_reloc_type_pos, /* R_POS (0x00) */
xcoff_reloc_type_neg, /* R_NEG (0x01) */
xcoff_reloc_type_rel, /* R_REL (0x02) */
xcoff_reloc_type_toc, /* R_TOC (0x03) */
xcoff_reloc_type_toc, /* R_TRL (0x04) */
xcoff_reloc_type_toc, /* R_GL (0x05) */
xcoff_reloc_type_toc, /* R_TCL (0x06) */
xcoff_reloc_type_fail, /* (0x07) */
xcoff_reloc_type_ba, /* R_BA (0x08) */
xcoff_reloc_type_fail, /* (0x09) */
xcoff64_reloc_type_br, /* R_BR (0x0a) */
xcoff_reloc_type_fail, /* (0x0b) */
xcoff_reloc_type_pos, /* R_RL (0x0c) */
xcoff_reloc_type_pos, /* R_RLA (0x0d) */
xcoff_reloc_type_fail, /* (0x0e) */
xcoff_reloc_type_noop, /* R_REF (0x0f) */
xcoff_reloc_type_fail, /* (0x10) */
xcoff_reloc_type_fail, /* (0x11) */
xcoff_reloc_type_fail, /* (0x12) */
xcoff_reloc_type_toc, /* R_TRLA (0x13) */
xcoff_reloc_type_fail, /* R_RRTBI (0x14) */
xcoff_reloc_type_fail, /* R_RRTBA (0x15) */
xcoff_reloc_type_ba, /* R_CAI (0x16) */
xcoff_reloc_type_crel, /* R_CREL (0x17) */
xcoff_reloc_type_ba, /* R_RBA (0x18) */
xcoff_reloc_type_ba, /* R_RBAC (0x19) */
xcoff64_reloc_type_br, /* R_RBR (0x1a) */
xcoff_reloc_type_ba, /* R_RBRC (0x1b) */
xcoff_reloc_type_fail, /* (0x1c) */
xcoff_reloc_type_fail, /* (0x1d) */
xcoff_reloc_type_fail, /* (0x1e) */
xcoff_reloc_type_fail, /* (0x1f) */
xcoff_reloc_type_tls, /* R_TLS (0x20) */
xcoff_reloc_type_tls, /* R_TLS_IE (0x21) */
xcoff_reloc_type_tls, /* R_TLS_LD (0x22) */
xcoff_reloc_type_tls, /* R_TLS_LE (0x23) */
xcoff_reloc_type_tls, /* R_TLSM (0x24) */
xcoff_reloc_type_tls, /* R_TLSML (0x25) */
xcoff_reloc_type_fail, /* (0x26) */
xcoff_reloc_type_fail, /* (0x27) */
xcoff_reloc_type_fail, /* (0x28) */
xcoff_reloc_type_fail, /* (0x29) */
xcoff_reloc_type_fail, /* (0x2a) */
xcoff_reloc_type_fail, /* (0x2b) */
xcoff_reloc_type_fail, /* (0x2c) */
xcoff_reloc_type_fail, /* (0x2d) */
xcoff_reloc_type_fail, /* (0x2e) */
xcoff_reloc_type_fail, /* (0x2f) */
xcoff_reloc_type_toc, /* R_TOCU (0x30) */
xcoff_reloc_type_toc, /* R_TOCL (0x31) */
};
/* coffcode.h needs these to be defined. */
/* Internalcoff.h and coffcode.h modify themselves based on these flags. */
#define XCOFF64
#define RS6000COFF_C 1
#define SELECT_RELOC(internal, howto) \
{ \
internal.r_type = howto->type; \
internal.r_size = \
((howto->complain_on_overflow == complain_overflow_signed \
? 0x80 \
: 0) \
| (howto->bitsize - 1)); \
}
#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
#define COFF_LONG_FILENAMES
#define NO_COFF_SYMBOLS
#define RTYPE2HOWTO(cache_ptr, dst) xcoff64_rtype2howto (cache_ptr, dst)
#define coff_mkobject _bfd_xcoff_mkobject
#define coff_bfd_copy_private_bfd_data _bfd_xcoff_copy_private_bfd_data
#define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
#define coff_bfd_reloc_type_lookup xcoff64_reloc_type_lookup
#define coff_bfd_reloc_name_lookup xcoff64_reloc_name_lookup
#ifdef AIX_CORE
extern bfd_cleanup rs6000coff_core_p
(bfd *abfd);
extern bool rs6000coff_core_file_matches_executable_p
(bfd *cbfd, bfd *ebfd);
extern char *rs6000coff_core_file_failing_command
(bfd *abfd);
extern int rs6000coff_core_file_failing_signal
(bfd *abfd);
#define CORE_FILE_P rs6000coff_core_p
#define coff_core_file_failing_command \
rs6000coff_core_file_failing_command
#define coff_core_file_failing_signal \
rs6000coff_core_file_failing_signal
#define coff_core_file_matches_executable_p \
rs6000coff_core_file_matches_executable_p
#define coff_core_file_pid \
_bfd_nocore_core_file_pid
#else
#define CORE_FILE_P _bfd_dummy_target
#define coff_core_file_failing_command \
_bfd_nocore_core_file_failing_command
#define coff_core_file_failing_signal \
_bfd_nocore_core_file_failing_signal
#define coff_core_file_matches_executable_p \
_bfd_nocore_core_file_matches_executable_p
#define coff_core_file_pid \
_bfd_nocore_core_file_pid
#endif
#define coff_SWAP_sym_in _bfd_xcoff64_swap_sym_in
#define coff_SWAP_sym_out _bfd_xcoff64_swap_sym_out
#define coff_SWAP_aux_in _bfd_xcoff64_swap_aux_in
#define coff_SWAP_aux_out _bfd_xcoff64_swap_aux_out
#define coff_swap_reloc_in xcoff64_swap_reloc_in
#define coff_swap_reloc_out xcoff64_swap_reloc_out
#define NO_COFF_RELOCS
#ifndef bfd_pe_print_pdata
#define bfd_pe_print_pdata NULL
#endif
#include "coffcode.h"
/* For XCOFF64, the effective width of symndx changes depending on
whether we are the first entry. Sigh. */
static void
_bfd_xcoff64_swap_lineno_in (bfd *abfd, void *ext1, void *in1)
{
LINENO *ext = (LINENO *) ext1;
struct internal_lineno *in = (struct internal_lineno *) in1;
in->l_lnno = H_GET_32 (abfd, (ext->l_lnno));
if (in->l_lnno == 0)
in->l_addr.l_symndx = H_GET_32 (abfd, ext->l_addr.l_symndx);
else
in->l_addr.l_paddr = H_GET_64 (abfd, ext->l_addr.l_paddr);
}
static unsigned int
_bfd_xcoff64_swap_lineno_out (bfd *abfd, void *inp, void *outp)
{
struct internal_lineno *in = (struct internal_lineno *) inp;
struct external_lineno *ext = (struct external_lineno *) outp;
H_PUT_32 (abfd, in->l_addr.l_symndx, ext->l_addr.l_symndx);
H_PUT_32 (abfd, in->l_lnno, (ext->l_lnno));
if (in->l_lnno == 0)
H_PUT_32 (abfd, in->l_addr.l_symndx, ext->l_addr.l_symndx);
else
H_PUT_64 (abfd, in->l_addr.l_paddr, ext->l_addr.l_paddr);
return bfd_coff_linesz (abfd);
}
static void
_bfd_xcoff64_swap_sym_in (bfd *abfd, void *ext1, void *in1)
{
struct external_syment *ext = (struct external_syment *) ext1;
struct internal_syment *in = (struct internal_syment *) in1;
in->_n._n_n._n_zeroes = 0;
in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e_offset);
in->n_value = H_GET_64 (abfd, ext->e_value);
in->n_scnum = (short) H_GET_16 (abfd, ext->e_scnum);
in->n_type = H_GET_16 (abfd, ext->e_type);
in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
}
static unsigned int
_bfd_xcoff64_swap_sym_out (bfd *abfd, void *inp, void *extp)
{
struct internal_syment *in = (struct internal_syment *) inp;
struct external_syment *ext = (struct external_syment *) extp;
H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e_offset);
H_PUT_64 (abfd, in->n_value, ext->e_value);
H_PUT_16 (abfd, in->n_scnum, ext->e_scnum);
H_PUT_16 (abfd, in->n_type, ext->e_type);
H_PUT_8 (abfd, in->n_sclass, ext->e_sclass);
H_PUT_8 (abfd, in->n_numaux, ext->e_numaux);
return bfd_coff_symesz (abfd);
}
static void
_bfd_xcoff64_swap_aux_in (bfd *abfd, void *ext1, int type ATTRIBUTE_UNUSED,
int in_class, int indx, int numaux, void *in1)
{
union external_auxent *ext = (union external_auxent *) ext1;
union internal_auxent *in = (union internal_auxent *) in1;
unsigned char auxtype;
switch (in_class)
{
default:
_bfd_error_handler
/* xgettext: c-format */
(_("%pB: unsupported swap_aux_in for storage class %#x"),
abfd, (unsigned int) in_class);
bfd_set_error (bfd_error_bad_value);
break;
case C_FILE:
auxtype = H_GET_8 (abfd, ext->x_file.x_auxtype);
if (auxtype != _AUX_FILE)
goto error;
if (ext->x_file.x_n.x_n.x_zeroes[0] == 0)
{
in->x_file.x_n.x_n.x_zeroes = 0;
in->x_file.x_n.x_n.x_offset =
H_GET_32 (abfd, ext->x_file.x_n.x_n.x_offset);
}
else
memcpy (in->x_file.x_n.x_fname, ext->x_file.x_n.x_fname, FILNMLEN);
in->x_file.x_ftype = H_GET_8 (abfd, ext->x_file.x_ftype);
break;
/* RS/6000 "csect" auxents.
There is always a CSECT auxiliary entry. But functions can
have FCN and EXCEPT ones too. In this case, CSECT is always the last
one.
For now, we only support FCN types. */
case C_EXT:
case C_AIX_WEAKEXT:
case C_HIDEXT:
if (indx + 1 == numaux)
{
/* C_EXT can have several aux enties. But the _AUX_CSECT is always
the last one. */
auxtype = H_GET_8 (abfd, ext->x_csect.x_auxtype);
if (auxtype != _AUX_CSECT)
goto error;
bfd_vma h = H_GET_32 (abfd, ext->x_csect.x_scnlen_hi);
bfd_vma l = H_GET_32 (abfd, ext->x_csect.x_scnlen_lo);
in->x_csect.x_scnlen.u64 = h << 32 | (l & 0xffffffff);
in->x_csect.x_parmhash = H_GET_32 (abfd, ext->x_csect.x_parmhash);
in->x_csect.x_snhash = H_GET_16 (abfd, ext->x_csect.x_snhash);
/* We don't have to hack bitfields in x_smtyp because it's
defined by shifts-and-ands, which are equivalent on all
byte orders. */
in->x_csect.x_smtyp = H_GET_8 (abfd, ext->x_csect.x_smtyp);
in->x_csect.x_smclas = H_GET_8 (abfd, ext->x_csect.x_smclas);
}
else
{
/* It can also be a _AUX_EXCEPT entry. But it's not supported
for now. */
auxtype = H_GET_8 (abfd, ext->x_fcn.x_auxtype);
if (auxtype != _AUX_FCN)
goto error;
in->x_sym.x_fcnary.x_fcn.x_lnnoptr
= H_GET_64 (abfd, ext->x_fcn.x_lnnoptr);
in->x_sym.x_misc.x_fsize
= H_GET_32 (abfd, ext->x_fcn.x_fsize);
in->x_sym.x_fcnary.x_fcn.x_endndx.u32
= H_GET_32 (abfd, ext->x_fcn.x_endndx);
}
break;
case C_STAT:
_bfd_error_handler
/* xgettext: c-format */
(_("%pB: C_STAT isn't supported by XCOFF64"),
abfd);
bfd_set_error (bfd_error_bad_value);
break;
case C_BLOCK:
case C_FCN:
auxtype = H_GET_8 (abfd, ext->x_sym.x_auxtype);
if (auxtype != _AUX_SYM)
goto error;
in->x_sym.x_misc.x_lnsz.x_lnno
= H_GET_32 (abfd, ext->x_sym.x_lnno);
break;
case C_DWARF:
auxtype = H_GET_8 (abfd, ext->x_sect.x_auxtype);
if (auxtype != _AUX_SECT)
goto error;
in->x_sect.x_scnlen = H_GET_64 (abfd, ext->x_sect.x_scnlen);
in->x_sect.x_nreloc = H_GET_64 (abfd, ext->x_sect.x_nreloc);
break;
}
return;
error:
_bfd_error_handler
/* xgettext: c-format */
(_("%pB: wrong auxtype %#x for storage class %#x"),
abfd, auxtype, (unsigned int) in_class);
bfd_set_error (bfd_error_bad_value);
}
static unsigned int
_bfd_xcoff64_swap_aux_out (bfd *abfd, void *inp, int type ATTRIBUTE_UNUSED,
int in_class, int indx, int numaux, void *extp)
{
union internal_auxent *in = (union internal_auxent *) inp;
union external_auxent *ext = (union external_auxent *) extp;
memset (ext, 0, bfd_coff_auxesz (abfd));
switch (in_class)
{
default:
_bfd_error_handler
/* xgettext: c-format */
(_("%pB: unsupported swap_aux_out for storage class %#x"),
abfd, (unsigned int) in_class);
bfd_set_error (bfd_error_bad_value);
break;
case C_FILE:
if (in->x_file.x_n.x_n.x_zeroes == 0)
{
H_PUT_32 (abfd, 0, ext->x_file.x_n.x_n.x_zeroes);
H_PUT_32 (abfd, in->x_file.x_n.x_n.x_offset,
ext->x_file.x_n.x_n.x_offset);
}
else
memcpy (ext->x_file.x_n.x_fname, in->x_file.x_n.x_fname, FILNMLEN);
H_PUT_8 (abfd, in->x_file.x_ftype, ext->x_file.x_ftype);
H_PUT_8 (abfd, _AUX_FILE, ext->x_file.x_auxtype);
break;
/* RS/6000 "csect" auxents.
There is always a CSECT auxiliary entry. But functions can
have FCN and EXCEPT ones too. In this case, CSECT is always the last
one.
For now, we only support FCN types. */
case C_EXT:
case C_AIX_WEAKEXT:
case C_HIDEXT:
if (indx + 1 == numaux)
{
bfd_vma temp;
temp = in->x_csect.x_scnlen.u64 & 0xffffffff;
H_PUT_32 (abfd, temp, ext->x_csect.x_scnlen_lo);
temp = in->x_csect.x_scnlen.u64 >> 32;
H_PUT_32 (abfd, temp, ext->x_csect.x_scnlen_hi);
H_PUT_32 (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash);
H_PUT_16 (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash);
/* We don't have to hack bitfields in x_smtyp because it's
defined by shifts-and-ands, which are equivalent on all
byte orders. */
H_PUT_8 (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp);
H_PUT_8 (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas);
H_PUT_8 (abfd, _AUX_CSECT, ext->x_csect.x_auxtype);
}
else
{
H_PUT_64 (abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr,
ext->x_fcn.x_lnnoptr);
H_PUT_32 (abfd, in->x_sym.x_misc.x_fsize, ext->x_fcn.x_fsize);
H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.u32,
ext->x_fcn.x_endndx);
H_PUT_8 (abfd, _AUX_FCN, ext->x_csect.x_auxtype);
}
break;
case C_STAT:
_bfd_error_handler
/* xgettext: c-format */
(_("%pB: C_STAT isn't supported by XCOFF64"),
abfd);
bfd_set_error (bfd_error_bad_value);
break;
case C_BLOCK:
case C_FCN:
H_PUT_32 (abfd, in->x_sym.x_misc.x_lnsz.x_lnno, ext->x_sym.x_lnno);
H_PUT_8 (abfd, _AUX_SYM, ext->x_sym.x_auxtype);
break;
case C_DWARF:
H_PUT_64 (abfd, in->x_sect.x_scnlen, ext->x_sect.x_scnlen);
H_PUT_64 (abfd, in->x_sect.x_nreloc, ext->x_sect.x_nreloc);
H_PUT_8 (abfd, _AUX_SECT, ext->x_sect.x_auxtype);
break;
}
return bfd_coff_auxesz (abfd);
}
static bool
_bfd_xcoff64_put_symbol_name (struct bfd_link_info *info,
struct bfd_strtab_hash *strtab,
struct internal_syment *sym,
const char *name)
{
bool hash;
bfd_size_type indx;
hash = !info->traditional_format;
indx = _bfd_stringtab_add (strtab, name, hash, false);
if (indx == (bfd_size_type) -1)
return false;
sym->_n._n_n._n_zeroes = 0;
sym->_n._n_n._n_offset = STRING_SIZE_SIZE + indx;
return true;
}
static bool
_bfd_xcoff64_put_ldsymbol_name (bfd *abfd ATTRIBUTE_UNUSED,
struct xcoff_loader_info *ldinfo,
struct internal_ldsym *ldsym,
const char *name)
{
size_t len;
len = strlen (name);
if (ldinfo->string_size + len + 3 > ldinfo->string_alc)
{
bfd_size_type newalc;
char *newstrings;
newalc = ldinfo->string_alc * 2;
if (newalc == 0)
newalc = 32;
while (ldinfo->string_size + len + 3 > newalc)
newalc *= 2;
newstrings = bfd_realloc (ldinfo->strings, newalc);
if (newstrings == NULL)
{
ldinfo->failed = true;
return false;
}
ldinfo->string_alc = newalc;
ldinfo->strings = newstrings;
}
ldinfo->strings[ldinfo->string_size] = ((len + 1) >> 8) & 0xff;
ldinfo->strings[ldinfo->string_size + 1] = ((len + 1)) & 0xff;
strcpy (ldinfo->strings + ldinfo->string_size + 2, name);
ldsym->_l._l_l._l_zeroes = 0;
ldsym->_l._l_l._l_offset = ldinfo->string_size + 2;
ldinfo->string_size += len + 3;
return true;
}
/* Routines to swap information in the XCOFF .loader section. If we
ever need to write an XCOFF loader, this stuff will need to be
moved to another file shared by the linker (which XCOFF calls the
``binder'') and the loader. */
/* Swap in the ldhdr structure. */
static void
xcoff64_swap_ldhdr_in (bfd *abfd,
const void *s,
struct internal_ldhdr *dst)
{
const struct external_ldhdr *src = (const struct external_ldhdr *) s;
dst->l_version = bfd_get_32 (abfd, src->l_version);
dst->l_nsyms = bfd_get_32 (abfd, src->l_nsyms);
dst->l_nreloc = bfd_get_32 (abfd, src->l_nreloc);
dst->l_istlen = bfd_get_32 (abfd, src->l_istlen);
dst->l_nimpid = bfd_get_32 (abfd, src->l_nimpid);
dst->l_stlen = bfd_get_32 (abfd, src->l_stlen);
dst->l_impoff = bfd_get_64 (abfd, src->l_impoff);
dst->l_stoff = bfd_get_64 (abfd, src->l_stoff);
dst->l_symoff = bfd_get_64 (abfd, src->l_symoff);
dst->l_rldoff = bfd_get_64 (abfd, src->l_rldoff);
}
/* Swap out the ldhdr structure. */
static void
xcoff64_swap_ldhdr_out (bfd *abfd, const struct internal_ldhdr *src, void *d)
{
struct external_ldhdr *dst = (struct external_ldhdr *) d;
bfd_put_32 (abfd, (bfd_vma) src->l_version, dst->l_version);
bfd_put_32 (abfd, src->l_nsyms, dst->l_nsyms);
bfd_put_32 (abfd, src->l_nreloc, dst->l_nreloc);
bfd_put_32 (abfd, src->l_istlen, dst->l_istlen);
bfd_put_32 (abfd, src->l_nimpid, dst->l_nimpid);
bfd_put_32 (abfd, src->l_stlen, dst->l_stlen);
bfd_put_64 (abfd, src->l_impoff, dst->l_impoff);
bfd_put_64 (abfd, src->l_stoff, dst->l_stoff);
bfd_put_64 (abfd, src->l_symoff, dst->l_symoff);
bfd_put_64 (abfd, src->l_rldoff, dst->l_rldoff);
}
/* Swap in the ldsym structure. */
static void
xcoff64_swap_ldsym_in (bfd *abfd, const void *s, struct internal_ldsym *dst)
{
const struct external_ldsym *src = (const struct external_ldsym *) s;
/* XCOFF64 does not use l_zeroes like XCOFF32
Set the internal l_zeroes to 0 so the common 32/64 code uses l_value
as an offset into the loader symbol table. */
dst->_l._l_l._l_zeroes = 0;
dst->_l._l_l._l_offset = bfd_get_32 (abfd, src->l_offset);
dst->l_value = bfd_get_64 (abfd, src->l_value);
dst->l_scnum = bfd_get_16 (abfd, src->l_scnum);
dst->l_smtype = bfd_get_8 (abfd, src->l_smtype);
dst->l_smclas = bfd_get_8 (abfd, src->l_smclas);
dst->l_ifile = bfd_get_32 (abfd, src->l_ifile);
dst->l_parm = bfd_get_32 (abfd, src->l_parm);
}
/* Swap out the ldsym structure. */
static void
xcoff64_swap_ldsym_out (bfd *abfd, const struct internal_ldsym *src, void *d)
{
struct external_ldsym *dst = (struct external_ldsym *) d;
bfd_put_64 (abfd, src->l_value, dst->l_value);
bfd_put_32 (abfd, (bfd_vma) src->_l._l_l._l_offset, dst->l_offset);
bfd_put_16 (abfd, (bfd_vma) src->l_scnum, dst->l_scnum);
bfd_put_8 (abfd, src->l_smtype, dst->l_smtype);
bfd_put_8 (abfd, src->l_smclas, dst->l_smclas);
bfd_put_32 (abfd, src->l_ifile, dst->l_ifile);
bfd_put_32 (abfd, src->l_parm, dst->l_parm);
}
static void
xcoff64_swap_reloc_in (bfd *abfd, void *s, void *d)
{
struct external_reloc *src = (struct external_reloc *) s;
struct internal_reloc *dst = (struct internal_reloc *) d;
memset (dst, 0, sizeof (struct internal_reloc));
dst->r_vaddr = bfd_get_64 (abfd, src->r_vaddr);
dst->r_symndx = bfd_get_32 (abfd, src->r_symndx);
dst->r_size = bfd_get_8 (abfd, src->r_size);
dst->r_type = bfd_get_8 (abfd, src->r_type);
}
static unsigned int
xcoff64_swap_reloc_out (bfd *abfd, void *s, void *d)
{
struct internal_reloc *src = (struct internal_reloc *) s;
struct external_reloc *dst = (struct external_reloc *) d;
bfd_put_64 (abfd, src->r_vaddr, dst->r_vaddr);
bfd_put_32 (abfd, src->r_symndx, dst->r_symndx);
bfd_put_8 (abfd, src->r_type, dst->r_type);
bfd_put_8 (abfd, src->r_size, dst->r_size);
return bfd_coff_relsz (abfd);
}
/* Swap in the ldrel structure. */
static void
xcoff64_swap_ldrel_in (bfd *abfd, const void *s, struct internal_ldrel *dst)
{
const struct external_ldrel *src = (const struct external_ldrel *) s;
dst->l_vaddr = bfd_get_64 (abfd, src->l_vaddr);
dst->l_symndx = bfd_get_32 (abfd, src->l_symndx);
dst->l_rtype = bfd_get_16 (abfd, src->l_rtype);
dst->l_rsecnm = bfd_get_16 (abfd, src->l_rsecnm);
}
/* Swap out the ldrel structure. */
static void
xcoff64_swap_ldrel_out (bfd *abfd, const struct internal_ldrel *src, void *d)
{
struct external_ldrel *dst = (struct external_ldrel *) d;
bfd_put_64 (abfd, src->l_vaddr, dst->l_vaddr);
bfd_put_16 (abfd, (bfd_vma) src->l_rtype, dst->l_rtype);
bfd_put_16 (abfd, (bfd_vma) src->l_rsecnm, dst->l_rsecnm);
bfd_put_32 (abfd, src->l_symndx, dst->l_symndx);
}
static bool
xcoff64_reloc_type_br (bfd *input_bfd,
asection *input_section,
bfd *output_bfd ATTRIBUTE_UNUSED,
struct internal_reloc *rel,
struct internal_syment *sym ATTRIBUTE_UNUSED,
struct reloc_howto_struct *howto,
bfd_vma val,
bfd_vma addend,
bfd_vma *relocation,
bfd_byte *contents,
struct bfd_link_info *info)
{
struct xcoff_link_hash_entry *h;
bfd_vma section_offset;
struct xcoff_stub_hash_entry *stub_entry = NULL;
enum xcoff_stub_type stub_type;
if (0 > rel->r_symndx)
return false;
h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx];
section_offset = rel->r_vaddr - input_section->vma;
/* If we see an R_BR or R_RBR reloc which is jumping to global
linkage code, and it is followed by an appropriate cror nop
instruction, we replace the cror with ld r2,40(r1). This
restores the TOC after the glink code. Contrariwise, if the
call is followed by a ld r2,40(r1), but the call is not
going to global linkage code, we can replace the load with a
cror. */
if (NULL != h
&& (bfd_link_hash_defined == h->root.type
|| bfd_link_hash_defweak == h->root.type)
&& section_offset + 8 <= input_section->size)
{
bfd_byte *pnext;
unsigned long next;
pnext = contents + section_offset + 4;
next = bfd_get_32 (input_bfd, pnext);
/* The _ptrgl function is magic. It is used by the AIX compiler to call
a function through a pointer. */
if (h->smclas == XMC_GL || strcmp (h->root.root.string, "._ptrgl") == 0)
{
if (next == 0x4def7b82 /* cror 15,15,15 */
|| next == 0x4ffffb82 /* cror 31,31,31 */
|| next == 0x60000000) /* ori r0,r0,0 */
bfd_put_32 (input_bfd, 0xe8410028, pnext); /* ld r2,40(r1) */
}
else
{
if (next == 0xe8410028) /* ld r2,40(r1) */
bfd_put_32 (input_bfd, 0x60000000, pnext); /* ori r0,r0,0 */
}
}
else if (NULL != h && bfd_link_hash_undefined == h->root.type)
{
/* Normally, this relocation is against a defined symbol. In the
case where this is a partial link and the output section offset
is greater than 2^25, the linker will return an invalid error
message that the relocation has been truncated. Yes it has been
truncated but no it not important. For this case, disable the
overflow checking. */
howto->complain_on_overflow = complain_overflow_dont;
}
/* Check if a stub is needed. */
stub_type = bfd_xcoff_type_of_stub (input_section, rel, val, h);
if (stub_type != xcoff_stub_none)
{
asection *stub_csect;
stub_entry = bfd_xcoff_get_stub_entry (input_section, h, info);
if (stub_entry == NULL)
{
_bfd_error_handler (_("Unable to find the stub entry targeting %s"),
h->root.root.string);
bfd_set_error (bfd_error_bad_value);
return false;
}
stub_csect = stub_entry->hcsect->root.u.def.section;
val = (stub_entry->stub_offset
+ stub_csect->output_section->vma
+ stub_csect->output_offset);
}
/* The original PC-relative relocation is biased by -r_vaddr, so adding
the value below will give the absolute target address. */
*relocation = val + addend + rel->r_vaddr;
howto->src_mask &= ~3;
howto->dst_mask = howto->src_mask;
if (h != NULL
&& (h->root.type == bfd_link_hash_defined
|| h->root.type == bfd_link_hash_defweak)
&& bfd_is_abs_section (h->root.u.def.section)
&& section_offset + 4 <= input_section->size)
{
bfd_byte *ptr;
bfd_vma insn;
/* Turn the relative branch into an absolute one by setting the
AA bit. */
ptr = contents + section_offset;
insn = bfd_get_32 (input_bfd, ptr);
insn |= 2;
bfd_put_32 (input_bfd, insn, ptr);
/* Make the howto absolute too. */
howto->pc_relative = false;
howto->complain_on_overflow = complain_overflow_bitfield;
}
else
{
/* Use a PC-relative howto and subtract the instruction's address
from the target address we calculated above. */
howto->pc_relative = true;
*relocation -= (input_section->output_section->vma
+ input_section->output_offset
+ section_offset);
}
return true;
}
/* The XCOFF reloc table.
Cf xcoff_howto_table comments. */
reloc_howto_type xcoff64_howto_table[] =
{
/* 0x00: Standard 64 bit relocation. */
HOWTO (R_POS, /* type */
0, /* rightshift */
8, /* size */
64, /* bitsize */
false, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
0, /* special_function */
"R_POS_64", /* name */
true, /* partial_inplace */
MINUS_ONE, /* src_mask */
MINUS_ONE, /* dst_mask */
false), /* pcrel_offset */
/* 0x01: 64 bit relocation, but store negative value. */
HOWTO (R_NEG, /* type */
0, /* rightshift */
-8, /* size */
64, /* bitsize */
false, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
0, /* special_function */
"R_NEG", /* name */
true, /* partial_inplace */
MINUS_ONE, /* src_mask */
MINUS_ONE, /* dst_mask */
false), /* pcrel_offset */
/* 0x02: 64 bit PC relative relocation. */
HOWTO (R_REL, /* type */
0, /* rightshift */
8, /* size */
64, /* bitsize */
true, /* pc_relative */
0, /* bitpos */
complain_overflow_signed, /* complain_on_overflow */
0, /* special_function */
"R_REL", /* name */
true, /* partial_inplace */
MINUS_ONE, /* src_mask */
MINUS_ONE, /* dst_mask */
false), /* pcrel_offset */
/* 0x03: 16 bit TOC relative relocation. */
HOWTO (R_TOC, /* type */
0, /* rightshift */
2, /* size */
16, /* bitsize */
false, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
0, /* special_function */
"R_TOC", /* name */
true, /* partial_inplace */
0, /* src_mask */
0xffff, /* dst_mask */
false), /* pcrel_offset */
/* 0x04: Same as R_TOC. */
HOWTO (R_TRL, /* type */
0, /* rightshift */
2, /* size */
16, /* bitsize */
false, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
0, /* special_function */
"R_TRL", /* name */
true, /* partial_inplace */
0, /* src_mask */
0xffff, /* dst_mask */
false), /* pcrel_offset */
/* 0x05: External TOC relative symbol. */
HOWTO (R_GL, /* type */
0, /* rightshift */
2, /* size */
16, /* bitsize */
false, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
0, /* special_function */
"R_GL", /* name */
true, /* partial_inplace */
0, /* src_mask */
0xffff, /* dst_mask */
false), /* pcrel_offset */
/* 0x06: Local TOC relative symbol. */
HOWTO (R_TCL, /* type */
0, /* rightshift */
2, /* size */
16, /* bitsize */