LLVM 22.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"
19#include "llvm/MC/MCValue.h"
23#include <cassert>
24
25using namespace llvm;
26
27namespace {
28
29class AArch64WinCOFFObjectWriter : public MCWinCOFFObjectTargetWriter {
30public:
31 AArch64WinCOFFObjectWriter(const Triple &TheTriple)
32 : MCWinCOFFObjectTargetWriter(TheTriple.isWindowsArm64EC()
35
36 ~AArch64WinCOFFObjectWriter() override = default;
37
38 unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
39 const MCFixup &Fixup, bool IsCrossSection,
40 const MCAsmBackend &MAB) const override;
41
42 bool recordRelocation(const MCFixup &) const override;
43};
44
45} // end anonymous namespace
46
47unsigned AArch64WinCOFFObjectWriter::getRelocType(
48 MCContext &Ctx, const MCValue &Target, const MCFixup &Fixup,
49 bool IsCrossSection, const MCAsmBackend &MAB) const {
50 unsigned FixupKind = Fixup.getKind();
51 bool PCRel = Fixup.isPCRel();
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 (PCRel || (FixupKind != FK_Data_4 && FixupKind != FK_Data_8)) {
58 Ctx.reportError(Fixup.getLoc(), "Cannot represent this expression");
60 }
62 PCRel = true;
63 }
64
65 auto Spec = Target.getSpecifier();
66 const MCExpr *Expr = Fixup.getValue();
67
68 if (auto *A64E = dyn_cast<MCSpecifierExpr>(Expr)) {
69 AArch64::Specifier Spec = A64E->getSpecifier();
70 switch (AArch64::getSymbolLoc(Spec)) {
71 case AArch64::S_ABS:
73 // Supported
74 break;
75 default:
76 Ctx.reportError(Fixup.getLoc(),
77 "relocation specifier " +
78 AArch64::getSpecifierName(A64E->getSpecifier()) +
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 (auto *A64E = dyn_cast<MCSpecifierExpr>(Expr)) {
87 Ctx.reportError(Fixup.getLoc(),
88 "relocation specifier " +
89 AArch64::getSpecifierName(A64E->getSpecifier()) +
90 " unsupported on COFF targets");
91 } else {
92 MCFixupKindInfo Info = MAB.getFixupKindInfo(Fixup.getKind());
93 Ctx.reportError(Fixup.getLoc(), Twine("relocation type ") + Info.Name +
94 " unsupported on COFF targets");
95 }
96 return COFF::IMAGE_REL_ARM64_ABSOLUTE; // Dummy return value
97 }
98
99 case FK_Data_4:
100 if (PCRel)
102 switch (Spec) {
103 default:
107 }
108
109 case FK_Data_8:
111
112 case FK_SecRel_2:
114
115 case FK_SecRel_4:
117
119 if (auto *A64E = dyn_cast<MCSpecifierExpr>(Expr)) {
120 AArch64::Specifier Spec = A64E->getSpecifier();
121 if (Spec == AArch64::S_SECREL_LO12)
123 if (Spec == AArch64::S_SECREL_HI12)
125 }
127
133 if (auto *A64E = dyn_cast<MCSpecifierExpr>(Expr)) {
134 AArch64::Specifier Spec = A64E->getSpecifier();
135 if (Spec == AArch64::S_SECREL_LO12)
137 }
139
142
145
148
151
155 }
156}
157
158bool AArch64WinCOFFObjectWriter::recordRelocation(const MCFixup &Fixup) const {
159 return true;
160}
161
162std::unique_ptr<MCObjectTargetWriter>
164 return std::make_unique<AArch64WinCOFFObjectWriter>(TheTriple);
165}
Analysis containing CSE Info
Definition CSEInfo.cpp:27
PowerPC TLS Dynamic Call Fixup
Generic interface to target specific assembler backends.
virtual MCFixupKindInfo getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.
Context object for machine code objects.
Definition MCContext.h:83
LLVM_ABI void reportError(SMLoc L, const Twine &Msg)
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition MCFixup.h:61
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
Specifier getSymbolLoc(Specifier S)
StringRef getSpecifierName(Specifier S)
Return the string representation of the ELF relocation specifier (e.g.
@ IMAGE_FILE_MACHINE_ARM64
Definition COFF.h:101
@ IMAGE_FILE_MACHINE_ARM64EC
Definition COFF.h:102
@ IMAGE_REL_ARM64_SECREL
Definition COFF.h:409
@ IMAGE_REL_ARM64_BRANCH19
Definition COFF.h:416
@ IMAGE_REL_ARM64_REL32
Definition COFF.h:418
@ IMAGE_REL_ARM64_SECREL_LOW12A
Definition COFF.h:410
@ IMAGE_REL_ARM64_ADDR32
Definition COFF.h:402
@ IMAGE_REL_ARM64_SECTION
Definition COFF.h:414
@ IMAGE_REL_ARM64_SECREL_HIGH12A
Definition COFF.h:411
@ IMAGE_REL_ARM64_ABSOLUTE
Definition COFF.h:401
@ IMAGE_REL_ARM64_PAGEOFFSET_12A
Definition COFF.h:407
@ IMAGE_REL_ARM64_BRANCH14
Definition COFF.h:417
@ IMAGE_REL_ARM64_BRANCH26
Definition COFF.h:404
@ IMAGE_REL_ARM64_PAGEOFFSET_12L
Definition COFF.h:408
@ IMAGE_REL_ARM64_SECREL_LOW12L
Definition COFF.h:412
@ IMAGE_REL_ARM64_ADDR32NB
Definition COFF.h:403
@ IMAGE_REL_ARM64_PAGEBASE_REL21
Definition COFF.h:405
@ IMAGE_REL_ARM64_REL21
Definition COFF.h:406
@ IMAGE_REL_ARM64_ADDR64
Definition COFF.h:415
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:649
std::unique_ptr< MCObjectTargetWriter > createAArch64WinCOFFObjectWriter(const Triple &TheTriple)
static Lanai::Fixups FixupKind(const MCExpr *Expr)
@ FK_SecRel_2
A two-byte section relative fixup.
Definition MCFixup.h:40
@ FK_Data_8
A eight-byte fixup.
Definition MCFixup.h:37
@ FK_Data_4
A four-byte fixup.
Definition MCFixup.h:36
@ FK_SecRel_4
A four-byte section relative fixup.
Definition MCFixup.h:41