LLVM 17.0.0git
AArch64WinCOFFObjectWriter.cpp
Go to the documentation of this file.
1//= AArch64WinCOFFObjectWriter.cpp - AArch64 Windows COFF Object Writer C++ =//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===---------------------------------------------------------------------===//
8
12#include "llvm/ADT/Twine.h"
15#include "llvm/MC/MCContext.h"
16#include "llvm/MC/MCExpr.h"
17#include "llvm/MC/MCFixup.h"
20#include "llvm/MC/MCValue.h"
25#include <cassert>
26
27using namespace llvm;
28
29namespace {
30
31class AArch64WinCOFFObjectWriter : public MCWinCOFFObjectTargetWriter {
32public:
33 AArch64WinCOFFObjectWriter(const Triple &TheTriple)
34 : MCWinCOFFObjectTargetWriter(TheTriple.isWindowsArm64EC()
37
38 ~AArch64WinCOFFObjectWriter() override = default;
39
40 unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
41 const MCFixup &Fixup, bool IsCrossSection,
42 const MCAsmBackend &MAB) const override;
43
44 bool recordRelocation(const MCFixup &) const override;
45};
46
47} // end anonymous namespace
48
49unsigned AArch64WinCOFFObjectWriter::getRelocType(
50 MCContext &Ctx, const MCValue &Target, const MCFixup &Fixup,
51 bool IsCrossSection, const MCAsmBackend &MAB) const {
52 unsigned FixupKind = Fixup.getKind();
53 if (IsCrossSection) {
54 // IMAGE_REL_ARM64_REL64 does not exist. We treat FK_Data_8 as FK_PCRel_4 so
55 // that .xword a-b can lower to IMAGE_REL_ARM64_REL32. This allows generic
56 // instrumentation to not bother with the COFF limitation. A negative value
57 // needs attention.
58 if (FixupKind != FK_Data_4 && FixupKind != FK_Data_8) {
59 Ctx.reportError(Fixup.getLoc(), "Cannot represent this expression");
61 }
63 }
64
65 auto Modifier = Target.isAbsolute() ? MCSymbolRefExpr::VK_None
66 : Target.getSymA()->getKind();
67 const MCExpr *Expr = Fixup.getValue();
68
69 if (const AArch64MCExpr *A64E = dyn_cast<AArch64MCExpr>(Expr)) {
70 AArch64MCExpr::VariantKind RefKind = A64E->getKind();
71 switch (AArch64MCExpr::getSymbolLoc(RefKind)) {
74 // Supported
75 break;
76 default:
77 Ctx.reportError(Fixup.getLoc(), "relocation variant " +
78 A64E->getVariantKindName() +
79 " unsupported on COFF targets");
80 return COFF::IMAGE_REL_ARM64_ABSOLUTE; // Dummy return value
81 }
82 }
83
84 switch (FixupKind) {
85 default: {
86 if (const AArch64MCExpr *A64E = dyn_cast<AArch64MCExpr>(Expr)) {
87 Ctx.reportError(Fixup.getLoc(), "relocation type " +
88 A64E->getVariantKindName() +
89 " unsupported on COFF targets");
90 } else {
91 const MCFixupKindInfo &Info = MAB.getFixupKindInfo(Fixup.getKind());
92 Ctx.reportError(Fixup.getLoc(), Twine("relocation type ") + Info.Name +
93 " unsupported on COFF targets");
94 }
95 return COFF::IMAGE_REL_ARM64_ABSOLUTE; // Dummy return value
96 }
97
98 case FK_PCRel_4:
100
101 case FK_Data_4:
102 switch (Modifier) {
103 default:
109 }
110
111 case FK_Data_8:
113
114 case FK_SecRel_2:
116
117 case FK_SecRel_4:
119
121 if (const AArch64MCExpr *A64E = dyn_cast<AArch64MCExpr>(Expr)) {
122 AArch64MCExpr::VariantKind RefKind = A64E->getKind();
123 if (RefKind == AArch64MCExpr::VK_SECREL_LO12)
125 if (RefKind == AArch64MCExpr::VK_SECREL_HI12)
127 }
129
135 if (const AArch64MCExpr *A64E = dyn_cast<AArch64MCExpr>(Expr)) {
136 AArch64MCExpr::VariantKind RefKind = A64E->getKind();
137 if (RefKind == AArch64MCExpr::VK_SECREL_LO12)
139 }
141
144
147
150
153
157 }
158}
159
160bool AArch64WinCOFFObjectWriter::recordRelocation(const MCFixup &Fixup) const {
161 return true;
162}
163
164std::unique_ptr<MCObjectTargetWriter>
166 return std::make_unique<AArch64WinCOFFObjectWriter>(TheTriple);
167}
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
PowerPC TLS Dynamic Call Fixup
static VariantKind getSymbolLoc(VariantKind Kind)
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:41
virtual const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.
Context object for machine code objects.
Definition: MCContext.h:76
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:1055
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:71
This represents an "assembler immediate".
Definition: MCValue.h:36
virtual bool recordRelocation(const MCFixup &) const
virtual unsigned getRelocType(MCContext &Ctx, const MCValue &Target, const MCFixup &Fixup, bool IsCrossSection, const MCAsmBackend &MAB) const =0
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
@ fixup_aarch64_ldst_imm12_scale16
@ IMAGE_FILE_MACHINE_ARM64
Definition: COFF.h:100
@ IMAGE_FILE_MACHINE_ARM64EC
Definition: COFF.h:101
@ IMAGE_REL_ARM64_SECREL
Definition: COFF.h:394
@ IMAGE_REL_ARM64_BRANCH19
Definition: COFF.h:401
@ IMAGE_REL_ARM64_REL32
Definition: COFF.h:403
@ IMAGE_REL_ARM64_SECREL_LOW12A
Definition: COFF.h:395
@ IMAGE_REL_ARM64_ADDR32
Definition: COFF.h:387
@ IMAGE_REL_ARM64_SECTION
Definition: COFF.h:399
@ IMAGE_REL_ARM64_SECREL_HIGH12A
Definition: COFF.h:396
@ IMAGE_REL_ARM64_ABSOLUTE
Definition: COFF.h:386
@ IMAGE_REL_ARM64_PAGEOFFSET_12A
Definition: COFF.h:392
@ IMAGE_REL_ARM64_BRANCH14
Definition: COFF.h:402
@ IMAGE_REL_ARM64_BRANCH26
Definition: COFF.h:389
@ IMAGE_REL_ARM64_PAGEOFFSET_12L
Definition: COFF.h:393
@ IMAGE_REL_ARM64_SECREL_LOW12L
Definition: COFF.h:397
@ IMAGE_REL_ARM64_ADDR32NB
Definition: COFF.h:388
@ IMAGE_REL_ARM64_PAGEBASE_REL21
Definition: COFF.h:390
@ IMAGE_REL_ARM64_REL21
Definition: COFF.h:391
@ IMAGE_REL_ARM64_ADDR64
Definition: COFF.h:400
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
std::unique_ptr< MCObjectTargetWriter > createAArch64WinCOFFObjectWriter(const Triple &TheTriple)
@ FK_PCRel_4
A four-byte pc relative fixup.
Definition: MCFixup.h:30
@ FK_SecRel_2
A two-byte section relative fixup.
Definition: MCFixup.h:41
@ FK_Data_8
A eight-byte fixup.
Definition: MCFixup.h:26
@ FK_Data_4
A four-byte fixup.
Definition: MCFixup.h:25
@ FK_SecRel_4
A four-byte section relative fixup.
Definition: MCFixup.h:42
Target independent information on a fixup kind.