LLVM  8.0.1
ARMWinCOFFObjectWriter.cpp
Go to the documentation of this file.
1 //===-- ARMWinCOFFObjectWriter.cpp - ARM Windows COFF Object Writer -- C++ -==//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
11 #include "llvm/ADT/Twine.h"
12 #include "llvm/BinaryFormat/COFF.h"
13 #include "llvm/MC/MCAsmBackend.h"
14 #include "llvm/MC/MCExpr.h"
15 #include "llvm/MC/MCFixup.h"
17 #include "llvm/MC/MCObjectWriter.h"
18 #include "llvm/MC/MCValue.h"
22 #include <cassert>
23 
24 using namespace llvm;
25 
26 namespace {
27 
28 class ARMWinCOFFObjectWriter : public MCWinCOFFObjectTargetWriter {
29 public:
30  ARMWinCOFFObjectWriter(bool Is64Bit)
32  assert(!Is64Bit && "AArch64 support not yet implemented");
33  }
34 
35  ~ARMWinCOFFObjectWriter() override = default;
36 
37  unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
38  const MCFixup &Fixup, bool IsCrossSection,
39  const MCAsmBackend &MAB) const override;
40 
41  bool recordRelocation(const MCFixup &) const override;
42 };
43 
44 } // end anonymous namespace
45 
47  const MCValue &Target,
48  const MCFixup &Fixup,
49  bool IsCrossSection,
50  const MCAsmBackend &MAB) const {
51  assert(getMachine() == COFF::IMAGE_FILE_MACHINE_ARMNT &&
52  "AArch64 support not yet implemented");
53 
55  Target.isAbsolute() ? MCSymbolRefExpr::VK_None : Target.getSymA()->getKind();
56 
57  switch (static_cast<unsigned>(Fixup.getKind())) {
58  default: {
59  const MCFixupKindInfo &Info = MAB.getFixupKindInfo(Fixup.getKind());
60  report_fatal_error(Twine("unsupported relocation type: ") + Info.Name);
61  }
62  case FK_Data_4:
63  switch (Modifier) {
68  default:
70  }
71  case FK_SecRel_2:
73  case FK_SecRel_4:
85  }
86 }
87 
88 bool ARMWinCOFFObjectWriter::recordRelocation(const MCFixup &Fixup) const {
89  return static_cast<unsigned>(Fixup.getKind()) != ARM::fixup_t2_movt_hi16;
90 }
91 
92 namespace llvm {
93 
94 std::unique_ptr<MCObjectTargetWriter>
96  return llvm::make_unique<ARMWinCOFFObjectWriter>(Is64Bit);
97 }
98 
99 } // end namespace llvm
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
This class represents lattice values for constants.
Definition: AllocatorList.h:24
This represents an "assembler immediate".
Definition: MCValue.h:40
VariantKind getKind() const
Definition: MCExpr.h:338
virtual const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.
bool isAbsolute() const
Is this an absolute (as opposed to relocatable) value.
Definition: MCValue.h:53
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:74
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
const char * Name
A target specific name for the fixup kind.
static unsigned getRelocType(const MCValue &Target, const MCFixupKind FixupKind, const bool IsPCRel)
Translates generic PPC fixup kind to Mach-O/PPC relocation type enum.
A four-byte section relative fixup.
Definition: MCFixup.h:42
A four-byte fixup.
Definition: MCFixup.h:26
Context object for machine code objects.
Definition: MCContext.h:63
A two-byte section relative fixup.
Definition: MCFixup.h:41
Analysis containing CSE Info
Definition: CSEInfo.cpp:21
const MCSymbolRefExpr * getSymA() const
Definition: MCValue.h:48
Target - Wrapper for Target specific information.
std::unique_ptr< MCObjectTargetWriter > createARMWinCOFFObjectWriter(bool Is64Bit)
Construct an ARM PE/COFF object writer.
Target independent information on a fixup kind.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:42
MCFixupKind getKind() const
Definition: MCFixup.h:123