LLVM
20.0.0git
lib
Target
ARM
MCTargetDesc
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
9
#include "
MCTargetDesc/ARMFixupKinds.h
"
10
#include "
llvm/ADT/Twine.h
"
11
#include "
llvm/BinaryFormat/COFF.h
"
12
#include "
llvm/MC/MCAsmBackend.h
"
13
#include "
llvm/MC/MCContext.h
"
14
#include "
llvm/MC/MCExpr.h
"
15
#include "
llvm/MC/MCFixup.h
"
16
#include "
llvm/MC/MCFixupKindInfo.h
"
17
#include "
llvm/MC/MCObjectWriter.h
"
18
#include "
llvm/MC/MCValue.h
"
19
#include "
llvm/MC/MCWinCOFFObjectWriter.h
"
20
#include "
llvm/Support/ErrorHandling.h
"
21
#include "
llvm/Support/raw_ostream.h
"
22
23
using namespace
llvm
;
24
25
namespace
{
26
27
class
ARMWinCOFFObjectWriter :
public
MCWinCOFFObjectTargetWriter
{
28
public
:
29
ARMWinCOFFObjectWriter()
30
:
MCWinCOFFObjectTargetWriter
(
COFF
::
IMAGE_FILE_MACHINE_ARMNT
) {
31
}
32
33
~ARMWinCOFFObjectWriter()
override
=
default
;
34
35
unsigned
getRelocType
(
MCContext
&Ctx,
const
MCValue
&
Target
,
36
const
MCFixup
&
Fixup
,
bool
IsCrossSection,
37
const
MCAsmBackend
&MAB)
const override
;
38
39
bool
recordRelocation
(
const
MCFixup
&)
const override
;
40
};
41
42
}
// end anonymous namespace
43
44
unsigned
ARMWinCOFFObjectWriter::getRelocType(
MCContext
&Ctx,
45
const
MCValue
&
Target
,
46
const
MCFixup
&
Fixup
,
47
bool
IsCrossSection,
48
const
MCAsmBackend
&MAB)
const
{
49
MCSymbolRefExpr::VariantKind
Modifier =
50
Target
.isAbsolute() ?
MCSymbolRefExpr::VK_None
:
Target
.getSymA()->getKind();
51
52
unsigned
FixupKind
=
Fixup
.getKind();
53
if
(IsCrossSection) {
54
if
(FixupKind !=
FK_Data_4
) {
55
Ctx.
reportError
(
Fixup
.getLoc(),
"Cannot represent this expression"
);
56
return
COFF::IMAGE_REL_ARM_ADDR32
;
57
}
58
FixupKind
=
FK_PCRel_4
;
59
}
60
61
62
switch
(FixupKind) {
63
default
: {
64
Ctx.
reportError
(
Fixup
.getLoc(),
"unsupported relocation type"
);
65
return
COFF::IMAGE_REL_ARM_ABSOLUTE
;
66
}
67
case
FK_Data_4
:
68
switch
(Modifier) {
69
case
MCSymbolRefExpr::VK_COFF_IMGREL32
:
70
return
COFF::IMAGE_REL_ARM_ADDR32NB
;
71
case
MCSymbolRefExpr::VK_SECREL
:
72
return
COFF::IMAGE_REL_ARM_SECREL
;
73
default
:
74
return
COFF::IMAGE_REL_ARM_ADDR32
;
75
}
76
case
FK_PCRel_4
:
77
return
COFF::IMAGE_REL_ARM_REL32
;
78
case
FK_SecRel_2
:
79
return
COFF::IMAGE_REL_ARM_SECTION
;
80
case
FK_SecRel_4
:
81
return
COFF::IMAGE_REL_ARM_SECREL
;
82
case
ARM::fixup_t2_condbranch
:
83
return
COFF::IMAGE_REL_ARM_BRANCH20T
;
84
case
ARM::fixup_t2_uncondbranch
:
85
case
ARM::fixup_arm_thumb_bl
:
86
return
COFF::IMAGE_REL_ARM_BRANCH24T
;
87
case
ARM::fixup_arm_thumb_blx
:
88
return
COFF::IMAGE_REL_ARM_BLX23T
;
89
case
ARM::fixup_t2_movw_lo16
:
90
case
ARM::fixup_t2_movt_hi16
:
91
return
COFF::IMAGE_REL_ARM_MOV32T
;
92
}
93
}
94
95
bool
ARMWinCOFFObjectWriter::recordRelocation(
const
MCFixup
&
Fixup
)
const
{
96
return
static_cast<
unsigned
>
(
Fixup
.getKind()) !=
ARM::fixup_t2_movt_hi16
;
97
}
98
99
namespace
llvm
{
100
101
std::unique_ptr<MCObjectTargetWriter>
102
createARMWinCOFFObjectWriter
() {
103
return
std::make_unique<ARMWinCOFFObjectWriter>();
104
}
105
106
}
// end namespace llvm
ARMFixupKinds.h
COFF.h
MCAsmBackend.h
MCContext.h
MCExpr.h
MCFixupKindInfo.h
MCFixup.h
MCObjectWriter.h
MCValue.h
MCWinCOFFObjectWriter.h
Fixup
PowerPC TLS Dynamic Call Fixup
Definition:
PPCTLSDynamicCall.cpp:340
Twine.h
llvm::MCAsmBackend
Generic interface to target specific assembler backends.
Definition:
MCAsmBackend.h:42
llvm::MCContext
Context object for machine code objects.
Definition:
MCContext.h:83
llvm::MCContext::reportError
void reportError(SMLoc L, const Twine &Msg)
Definition:
MCContext.cpp:1068
llvm::MCFixup
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition:
MCFixup.h:71
llvm::MCSymbolRefExpr::VariantKind
VariantKind
Definition:
MCExpr.h:190
llvm::MCSymbolRefExpr::VK_None
@ VK_None
Definition:
MCExpr.h:191
llvm::MCSymbolRefExpr::VK_SECREL
@ VK_SECREL
Definition:
MCExpr.h:219
llvm::MCSymbolRefExpr::VK_COFF_IMGREL32
@ VK_COFF_IMGREL32
Definition:
MCExpr.h:322
llvm::MCValue
This represents an "assembler immediate".
Definition:
MCValue.h:36
llvm::MCWinCOFFObjectTargetWriter
Definition:
MCWinCOFFObjectWriter.h:23
llvm::MCWinCOFFObjectTargetWriter::recordRelocation
virtual bool recordRelocation(const MCFixup &) const
Definition:
MCWinCOFFObjectWriter.h:43
llvm::MCWinCOFFObjectTargetWriter::getRelocType
virtual unsigned getRelocType(MCContext &Ctx, const MCValue &Target, const MCFixup &Fixup, bool IsCrossSection, const MCAsmBackend &MAB) const =0
llvm::Target
Target - Wrapper for Target specific information.
Definition:
TargetRegistry.h:144
ErrorHandling.h
llvm::ARM::fixup_t2_movt_hi16
@ fixup_t2_movt_hi16
Definition:
ARMFixupKinds.h:99
llvm::ARM::fixup_arm_thumb_blx
@ fixup_arm_thumb_blx
Definition:
ARMFixupKinds.h:84
llvm::ARM::fixup_t2_uncondbranch
@ fixup_t2_uncondbranch
Definition:
ARMFixupKinds.h:57
llvm::ARM::fixup_t2_condbranch
@ fixup_t2_condbranch
Definition:
ARMFixupKinds.h:54
llvm::ARM::fixup_arm_thumb_bl
@ fixup_arm_thumb_bl
Definition:
ARMFixupKinds.h:81
llvm::ARM::fixup_t2_movw_lo16
@ fixup_t2_movw_lo16
Definition:
ARMFixupKinds.h:100
llvm::BPF::FixupKind
FixupKind
Definition:
BPFMCFixups.h:16
llvm::COFF::IMAGE_FILE_MACHINE_ARMNT
@ IMAGE_FILE_MACHINE_ARMNT
Definition:
COFF.h:99
llvm::COFF::IMAGE_REL_ARM_BRANCH20T
@ IMAGE_REL_ARM_BRANCH20T
Definition:
COFF.h:393
llvm::COFF::IMAGE_REL_ARM_ADDR32NB
@ IMAGE_REL_ARM_ADDR32NB
Definition:
COFF.h:382
llvm::COFF::IMAGE_REL_ARM_ADDR32
@ IMAGE_REL_ARM_ADDR32
Definition:
COFF.h:381
llvm::COFF::IMAGE_REL_ARM_MOV32T
@ IMAGE_REL_ARM_MOV32T
Definition:
COFF.h:392
llvm::COFF::IMAGE_REL_ARM_BRANCH24T
@ IMAGE_REL_ARM_BRANCH24T
Definition:
COFF.h:394
llvm::COFF::IMAGE_REL_ARM_ABSOLUTE
@ IMAGE_REL_ARM_ABSOLUTE
Definition:
COFF.h:380
llvm::COFF::IMAGE_REL_ARM_REL32
@ IMAGE_REL_ARM_REL32
Definition:
COFF.h:388
llvm::COFF::IMAGE_REL_ARM_BLX23T
@ IMAGE_REL_ARM_BLX23T
Definition:
COFF.h:395
llvm::COFF::IMAGE_REL_ARM_SECREL
@ IMAGE_REL_ARM_SECREL
Definition:
COFF.h:390
llvm::COFF::IMAGE_REL_ARM_SECTION
@ IMAGE_REL_ARM_SECTION
Definition:
COFF.h:389
llvm::logicalview::LVBinaryType::COFF
@ COFF
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:
AddressRanges.h:18
llvm::FK_PCRel_4
@ FK_PCRel_4
A four-byte pc relative fixup.
Definition:
MCFixup.h:30
llvm::FK_SecRel_2
@ FK_SecRel_2
A two-byte section relative fixup.
Definition:
MCFixup.h:41
llvm::FK_Data_4
@ FK_Data_4
A four-byte fixup.
Definition:
MCFixup.h:25
llvm::FK_SecRel_4
@ FK_SecRel_4
A four-byte section relative fixup.
Definition:
MCFixup.h:42
llvm::createARMWinCOFFObjectWriter
std::unique_ptr< MCObjectTargetWriter > createARMWinCOFFObjectWriter()
Construct an ARM PE/COFF object writer.
Definition:
ARMWinCOFFObjectWriter.cpp:102
raw_ostream.h
Generated on Tue Nov 12 2024 16:07:41 for LLVM by
1.9.6