LLVM 17.0.0git
ARMWinCOFFObjectWriter.cpp
Go to the documentation of this file.
1//===-- ARMWinCOFFObjectWriter.cpp - ARM 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
10#include "llvm/ADT/Twine.h"
13#include "llvm/MC/MCContext.h"
14#include "llvm/MC/MCExpr.h"
15#include "llvm/MC/MCFixup.h"
18#include "llvm/MC/MCValue.h"
22#include <cassert>
23
24using namespace llvm;
25
26namespace {
27
28class ARMWinCOFFObjectWriter : public MCWinCOFFObjectTargetWriter {
29public:
30 ARMWinCOFFObjectWriter()
32 }
33
34 ~ARMWinCOFFObjectWriter() override = default;
35
36 unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
37 const MCFixup &Fixup, bool IsCrossSection,
38 const MCAsmBackend &MAB) const override;
39
40 bool recordRelocation(const MCFixup &) const override;
41};
42
43} // end anonymous namespace
44
45unsigned ARMWinCOFFObjectWriter::getRelocType(MCContext &Ctx,
46 const MCValue &Target,
47 const MCFixup &Fixup,
48 bool IsCrossSection,
49 const MCAsmBackend &MAB) const {
51 Target.isAbsolute() ? MCSymbolRefExpr::VK_None : Target.getSymA()->getKind();
52
53 unsigned FixupKind = Fixup.getKind();
54 if (IsCrossSection) {
55 if (FixupKind != FK_Data_4) {
56 Ctx.reportError(Fixup.getLoc(), "Cannot represent this expression");
58 }
60 }
61
62
63 switch (FixupKind) {
64 default: {
65 const MCFixupKindInfo &Info = MAB.getFixupKindInfo(Fixup.getKind());
66 report_fatal_error(Twine("unsupported relocation type: ") + Info.Name);
67 }
68 case FK_Data_4:
69 switch (Modifier) {
74 default:
76 }
77 case FK_PCRel_4:
79 case FK_SecRel_2:
81 case FK_SecRel_4:
93 }
94}
95
96bool ARMWinCOFFObjectWriter::recordRelocation(const MCFixup &Fixup) const {
97 return static_cast<unsigned>(Fixup.getKind()) != ARM::fixup_t2_movt_hi16;
98}
99
100namespace llvm {
101
102std::unique_ptr<MCObjectTargetWriter>
104 return std::make_unique<ARMWinCOFFObjectWriter>();
105}
106
107} // end namespace llvm
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
PowerPC TLS Dynamic Call Fixup
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
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.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
@ fixup_t2_movt_hi16
Definition: ARMFixupKinds.h:99
@ fixup_arm_thumb_blx
Definition: ARMFixupKinds.h:84
@ fixup_t2_uncondbranch
Definition: ARMFixupKinds.h:57
@ fixup_t2_condbranch
Definition: ARMFixupKinds.h:54
@ fixup_arm_thumb_bl
Definition: ARMFixupKinds.h:81
@ fixup_t2_movw_lo16
@ IMAGE_FILE_MACHINE_ARMNT
Definition: COFF.h:99
@ IMAGE_REL_ARM_BRANCH20T
Definition: COFF.h:379
@ IMAGE_REL_ARM_ADDR32NB
Definition: COFF.h:368
@ IMAGE_REL_ARM_ADDR32
Definition: COFF.h:367
@ IMAGE_REL_ARM_MOV32T
Definition: COFF.h:378
@ IMAGE_REL_ARM_BRANCH24T
Definition: COFF.h:380
@ IMAGE_REL_ARM_REL32
Definition: COFF.h:374
@ IMAGE_REL_ARM_BLX23T
Definition: COFF.h:381
@ IMAGE_REL_ARM_SECREL
Definition: COFF.h:376
@ IMAGE_REL_ARM_SECTION
Definition: COFF.h:375
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:145
@ 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_4
A four-byte fixup.
Definition: MCFixup.h:25
@ FK_SecRel_4
A four-byte section relative fixup.
Definition: MCFixup.h:42
std::unique_ptr< MCObjectTargetWriter > createARMWinCOFFObjectWriter()
Construct an ARM PE/COFF object writer.
Target independent information on a fixup kind.