LLVM  6.0.0svn
AArch64WinCOFFObjectWriter.cpp
Go to the documentation of this file.
1 //= AArch64WinCOFFObjectWriter.cpp - AArch64 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 AArch64WinCOFFObjectWriter : public MCWinCOFFObjectTargetWriter {
29 public:
30  AArch64WinCOFFObjectWriter()
32 
33  ~AArch64WinCOFFObjectWriter() 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 
45  MCContext &Ctx, const MCValue &Target, const MCFixup &Fixup,
46  bool IsCrossSection, const MCAsmBackend &MAB) const {
47  auto Modifier = Target.isAbsolute() ? MCSymbolRefExpr::VK_None
48  : Target.getSymA()->getKind();
49 
50  switch (static_cast<unsigned>(Fixup.getKind())) {
51  default: {
52  const MCFixupKindInfo &Info = MAB.getFixupKindInfo(Fixup.getKind());
53  report_fatal_error(Twine("unsupported relocation type: ") + Info.Name);
54  }
55 
56  case FK_Data_4:
57  switch (Modifier) {
58  default:
64  }
65 
66  case FK_Data_8:
68 
69  case FK_SecRel_2:
71 
72  case FK_SecRel_4:
74 
77 
84 
87 
91  }
92 }
93 
94 bool AArch64WinCOFFObjectWriter::recordRelocation(const MCFixup &Fixup) const {
95  return true;
96 }
97 
98 namespace llvm {
99 
100 std::unique_ptr<MCObjectWriter>
102  auto MOTW = llvm::make_unique<AArch64WinCOFFObjectWriter>();
103  return createWinCOFFObjectWriter(std::move(MOTW), OS);
104 }
105 
106 } // 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:103
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
This represents an "assembler immediate".
Definition: MCValue.h:40
VariantKind getKind() const
Definition: MCExpr.h:320
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:66
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:59
A two-byte section relative fixup.
Definition: MCFixup.h:41
const MCSymbolRefExpr * getSymA() const
Definition: MCValue.h:48
std::unique_ptr< MCObjectWriter > createWinCOFFObjectWriter(std::unique_ptr< MCWinCOFFObjectTargetWriter > MOTW, raw_pwrite_stream &OS)
Construct a new Win COFF writer instance.
std::unique_ptr< MCObjectWriter > createAArch64WinCOFFObjectWriter(raw_pwrite_stream &OS)
Target - Wrapper for Target specific information.
A eight-byte fixup.
Definition: MCFixup.h:27
Target independent information on a fixup kind.
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:337
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:35
MCFixupKind getKind() const
Definition: MCFixup.h:93