LLVM 20.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"
24#include <cassert>
25
26using namespace llvm;
27
28namespace {
29
30class AArch64WinCOFFObjectWriter : public MCWinCOFFObjectTargetWriter {
31public:
32 AArch64WinCOFFObjectWriter(const Triple &TheTriple)
33 : MCWinCOFFObjectTargetWriter(TheTriple.isWindowsArm64EC()
36
37 ~AArch64WinCOFFObjectWriter() override = default;
38
39 unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
40 const MCFixup &Fixup, bool IsCrossSection,
41 const MCAsmBackend &MAB) const override;
42
43 bool recordRelocation(const MCFixup &) const override;
44};
45
46} // end anonymous namespace
47
48unsigned AArch64WinCOFFObjectWriter::getRelocType(
49 MCContext &Ctx, const MCValue &Target, const MCFixup &Fixup,
50 bool IsCrossSection, const MCAsmBackend &MAB) const {
51 unsigned FixupKind = Fixup.getKind();
52 if (IsCrossSection) {
53 // IMAGE_REL_ARM64_REL64 does not exist. We treat FK_Data_8 as FK_PCRel_4 so
54 // that .xword a-b can lower to IMAGE_REL_ARM64_REL32. This allows generic
55 // instrumentation to not bother with the COFF limitation. A negative value
56 // needs attention.
57 if (FixupKind != FK_Data_4 && FixupKind != FK_Data_8) {
58 Ctx.reportError(Fixup.getLoc(), "Cannot represent this expression");
60 }
62 }
63
64 auto Modifier = Target.isAbsolute() ? MCSymbolRefExpr::VK_None
65 : Target.getSymA()->getKind();
66 const MCExpr *Expr = Fixup.getValue();
67
68 if (const AArch64MCExpr *A64E = dyn_cast<AArch64MCExpr>(Expr)) {
69 AArch64MCExpr::VariantKind RefKind = A64E->getKind();
70 switch (AArch64MCExpr::getSymbolLoc(RefKind)) {
73 // Supported
74 break;
75 default:
76 Ctx.reportError(Fixup.getLoc(), "relocation variant " +
77 A64E->getVariantKindName() +
78 " unsupported on COFF targets");
79 return COFF::IMAGE_REL_ARM64_ABSOLUTE; // Dummy return value
80 }
81 }
82
83 switch (FixupKind) {
84 default: {
85 if (const AArch64MCExpr *A64E = dyn_cast<AArch64MCExpr>(Expr)) {
86 Ctx.reportError(Fixup.getLoc(), "relocation type " +
87 A64E->getVariantKindName() +
88 " unsupported on COFF targets");
89 } else {
90 const MCFixupKindInfo &Info = MAB.getFixupKindInfo(Fixup.getKind());
91 Ctx.reportError(Fixup.getLoc(), Twine("relocation type ") + Info.Name +
92 " unsupported on COFF targets");
93 }
94 return COFF::IMAGE_REL_ARM64_ABSOLUTE; // Dummy return value
95 }
96
97 case FK_PCRel_4:
99
100 case FK_Data_4:
101 switch (Modifier) {
102 default:
108 }
109
110 case FK_Data_8:
112
113 case FK_SecRel_2:
115
116 case FK_SecRel_4:
118
120 if (const AArch64MCExpr *A64E = dyn_cast<AArch64MCExpr>(Expr)) {
121 AArch64MCExpr::VariantKind RefKind = A64E->getKind();
122 if (RefKind == AArch64MCExpr::VK_SECREL_LO12)
124 if (RefKind == AArch64MCExpr::VK_SECREL_HI12)
126 }
128
134 if (const AArch64MCExpr *A64E = dyn_cast<AArch64MCExpr>(Expr)) {
135 AArch64MCExpr::VariantKind RefKind = A64E->getKind();
136 if (RefKind == AArch64MCExpr::VK_SECREL_LO12)
138 }
140
143
146
149
152
156 }
157}
158
159bool AArch64WinCOFFObjectWriter::recordRelocation(const MCFixup &Fixup) const {
160 return true;
161}
162
163std::unique_ptr<MCObjectTargetWriter>
165 return std::make_unique<AArch64WinCOFFObjectWriter>(TheTriple);
166}
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:42
virtual const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.
Context object for machine code objects.
Definition: MCContext.h:83
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:1072
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
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:408
@ IMAGE_REL_ARM64_BRANCH19
Definition: COFF.h:415
@ IMAGE_REL_ARM64_REL32
Definition: COFF.h:417
@ IMAGE_REL_ARM64_SECREL_LOW12A
Definition: COFF.h:409
@ IMAGE_REL_ARM64_ADDR32
Definition: COFF.h:401
@ IMAGE_REL_ARM64_SECTION
Definition: COFF.h:413
@ IMAGE_REL_ARM64_SECREL_HIGH12A
Definition: COFF.h:410
@ IMAGE_REL_ARM64_ABSOLUTE
Definition: COFF.h:400
@ IMAGE_REL_ARM64_PAGEOFFSET_12A
Definition: COFF.h:406
@ IMAGE_REL_ARM64_BRANCH14
Definition: COFF.h:416
@ IMAGE_REL_ARM64_BRANCH26
Definition: COFF.h:403
@ IMAGE_REL_ARM64_PAGEOFFSET_12L
Definition: COFF.h:407
@ IMAGE_REL_ARM64_SECREL_LOW12L
Definition: COFF.h:411
@ IMAGE_REL_ARM64_ADDR32NB
Definition: COFF.h:402
@ IMAGE_REL_ARM64_PAGEBASE_REL21
Definition: COFF.h:404
@ IMAGE_REL_ARM64_REL21
Definition: COFF.h:405
@ IMAGE_REL_ARM64_ADDR64
Definition: COFF.h:414
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.