llvm.org GIT mirror llvm / bca1a1a
[COFF, ARM64] Add initial relocation types Reviewers: compnerd, ruiu, rnk Reviewed By: compnerd Subscribers: mstorsjo, aemerson, javed.absar, kristof.beyls, llvm-commits Differential Revision: https://reviews.llvm.org/D34857 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@308154 91177308-0d34-0410-b5e6-96231b3b80d8 Mandeep Singh Grang 3 years ago
3 changed file(s) with 107 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
103103 case FK_Data_1:
104104 return 1;
105105
106 case AArch64::fixup_aarch64_movw:
106107 case FK_Data_2:
107 case AArch64::fixup_aarch64_movw:
108 case FK_SecRel_2:
108109 return 2;
109110
110111 case AArch64::fixup_aarch64_pcrel_branch14:
123124 case AArch64::fixup_aarch64_pcrel_branch26:
124125 case AArch64::fixup_aarch64_pcrel_call26:
125126 case FK_Data_4:
127 case FK_SecRel_4:
126128 return 4;
127129
128130 case FK_Data_8:
217219 case FK_Data_2:
218220 case FK_Data_4:
219221 case FK_Data_8:
222 case FK_SecRel_2:
223 case FK_SecRel_4:
220224 return Value;
221225 }
222226 }
2626 class AArch64WinCOFFObjectWriter : public MCWinCOFFObjectTargetWriter {
2727 public:
2828 AArch64WinCOFFObjectWriter()
29 : MCWinCOFFObjectTargetWriter(COFF::IMAGE_FILE_MACHINE_ARM64) {
30 }
29 : MCWinCOFFObjectTargetWriter(COFF::IMAGE_FILE_MACHINE_ARM64) {}
3130
3231 ~AArch64WinCOFFObjectWriter() override = default;
3332
3534 const MCFixup &Fixup, bool IsCrossSection,
3635 const MCAsmBackend &MAB) const override;
3736
38 bool recordRelocation(const MCFixup &) const override;
37 bool recordRelocation(const MCFixup &) const override;
3938 };
4039
4140 } // end anonymous namespace
4241
43 unsigned
44 AArch64WinCOFFObjectWriter::getRelocType(MCContext &Ctx,
45 const MCValue &Target,
46 const MCFixup &Fixup,
47 bool IsCrossSection,
48 const MCAsmBackend &MAB) const {
49 const MCFixupKindInfo &Info = MAB.getFixupKindInfo(Fixup.getKind());
50 report_fatal_error(Twine("unsupported relocation type: ") + Info.Name);
42 unsigned AArch64WinCOFFObjectWriter::getRelocType(
43 MCContext &Ctx, const MCValue &Target, const MCFixup &Fixup,
44 bool IsCrossSection, const MCAsmBackend &MAB) const {
45 auto Modifier = Target.isAbsolute() ? MCSymbolRefExpr::VK_None
46 : Target.getSymA()->getKind();
47
48 switch (static_cast(Fixup.getKind())) {
49 default: {
50 const MCFixupKindInfo &Info = MAB.getFixupKindInfo(Fixup.getKind());
51 report_fatal_error(Twine("unsupported relocation type: ") + Info.Name);
52 }
53
54 case FK_Data_4:
55 switch (Modifier) {
56 default:
57 return COFF::IMAGE_REL_ARM64_ADDR32;
58 case MCSymbolRefExpr::VK_COFF_IMGREL32:
59 return COFF::IMAGE_REL_ARM64_ADDR32NB;
60 case MCSymbolRefExpr::VK_SECREL:
61 return COFF::IMAGE_REL_ARM64_SECREL;
62 }
63
64 case FK_Data_8:
65 return COFF::IMAGE_REL_ARM64_ADDR64;
66
67 case FK_SecRel_2:
68 return COFF::IMAGE_REL_ARM64_SECTION;
69
70 case FK_SecRel_4:
71 return COFF::IMAGE_REL_ARM64_SECREL;
72
73 case AArch64::fixup_aarch64_add_imm12:
74 return COFF::IMAGE_REL_ARM64_PAGEOFFSET_12A;
75
76 case AArch64::fixup_aarch64_ldst_imm12_scale1:
77 case AArch64::fixup_aarch64_ldst_imm12_scale2:
78 case AArch64::fixup_aarch64_ldst_imm12_scale4:
79 case AArch64::fixup_aarch64_ldst_imm12_scale8:
80 case AArch64::fixup_aarch64_ldst_imm12_scale16:
81 return COFF::IMAGE_REL_ARM64_PAGEOFFSET_12L;
82
83 case AArch64::fixup_aarch64_pcrel_adrp_imm21:
84 return COFF::IMAGE_REL_ARM64_PAGEBASE_REL21;
85
86 case AArch64::fixup_aarch64_pcrel_branch26:
87 case AArch64::fixup_aarch64_pcrel_call26:
88 return COFF::IMAGE_REL_ARM64_BRANCH26;
89 }
5190 }
5291
5392 bool AArch64WinCOFFObjectWriter::recordRelocation(const MCFixup &Fixup) const {
0 ; RUN: llvm-mc -triple aarch64-windows -filetype obj -o - %s | \
1 ; RUN: llvm-readobj -r - | FileCheck %s
2
3 ; IMAGE_REL_ARM64_ADDR32
4 .Linfo_foo:
5 .asciz "foo"
6 .long foo
7
8 ; IMAGE_REL_ARM64_ADDR32NB
9 .long func@IMGREL
10
11 ; IMAGE_REL_ARM64_ADDR64
12 .globl struc
13 struc:
14 .quad arr
15
16 ; IMAGE_REL_ARM64_BRANCH26
17 b target
18
19 ; IMAGE_REL_ARM64_PAGEBASE_REL21
20 adrp x0, foo
21
22 ; IMAGE_REL_ARM64_PAGEOFFSET_12A
23 add x0, x0, :lo12:foo
24
25 ; IMAGE_REL_ARM64_PAGEOFFSET_12L
26 ldr x0, [x0, :lo12:foo]
27
28 ; IMAGE_REL_ARM64_SECREL
29 .secrel32 .Linfo_bar
30 .Linfo_bar:
31
32 ; IMAGE_REL_ARM64_SECTION
33 .secidx func
34
35
36 ; CHECK: Format: COFF-ARM64
37 ; CHECK: Arch: aarch64
38 ; CHECK: AddressSize: 64bit
39 ; CHECK: Relocations [
40 ; CHECK: Section (1) .text {
41 ; CHECK: 0x4 IMAGE_REL_ARM64_ADDR32 foo
42 ; CHECK: 0x8 IMAGE_REL_ARM64_ADDR32NB func
43 ; CHECK: 0xC IMAGE_REL_ARM64_ADDR64 arr
44 ; CHECK: 0x14 IMAGE_REL_ARM64_BRANCH26 target
45 ; CHECK: 0x18 IMAGE_REL_ARM64_PAGEBASE_REL21 foo
46 ; CHECK: 0x1C IMAGE_REL_ARM64_PAGEOFFSET_12A foo
47 ; CHECK: 0x20 IMAGE_REL_ARM64_PAGEOFFSET_12L foo
48 ; CHECK: 0x24 IMAGE_REL_ARM64_SECREL .text
49 ; CHECK: 0x28 IMAGE_REL_ARM64_SECTION func
50 ; CHECK: }
51 ; CHECK: ]