LLVM  5.0.0
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/MCValue.h"
21 #include <cassert>
22 
23 using namespace llvm;
24 
25 namespace {
26 
27 class AArch64WinCOFFObjectWriter : public MCWinCOFFObjectTargetWriter {
28 public:
29  AArch64WinCOFFObjectWriter()
31 
32  ~AArch64WinCOFFObjectWriter() override = default;
33 
34  unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
35  const MCFixup &Fixup, bool IsCrossSection,
36  const MCAsmBackend &MAB) const override;
37 
38  bool recordRelocation(const MCFixup &) const override;
39 };
40 
41 } // end anonymous namespace
42 
44  MCContext &Ctx, const MCValue &Target, const MCFixup &Fixup,
45  bool IsCrossSection, const MCAsmBackend &MAB) const {
46  auto Modifier = Target.isAbsolute() ? MCSymbolRefExpr::VK_None
47  : Target.getSymA()->getKind();
48 
49  switch (static_cast<unsigned>(Fixup.getKind())) {
50  default: {
51  const MCFixupKindInfo &Info = MAB.getFixupKindInfo(Fixup.getKind());
52  report_fatal_error(Twine("unsupported relocation type: ") + Info.Name);
53  }
54 
55  case FK_Data_4:
56  switch (Modifier) {
57  default:
63  }
64 
65  case FK_Data_8:
67 
68  case FK_SecRel_2:
70 
71  case FK_SecRel_4:
73 
76 
83 
86 
90  }
91 }
92 
93 bool AArch64WinCOFFObjectWriter::recordRelocation(const MCFixup &Fixup) const {
94  return true;
95 }
96 
97 namespace llvm {
98 
100  MCWinCOFFObjectTargetWriter *MOTW = new AArch64WinCOFFObjectWriter();
101  return createWinCOFFObjectWriter(MOTW, OS);
102 }
103 
104 } // 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
This represents an "assembler immediate".
Definition: MCValue.h:40
Defines the object file and target independent interfaces used by the assembler backend to write nati...
MCObjectWriter * createAArch64WinCOFFObjectWriter(raw_pwrite_stream &OS)
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
bool isAbsolute() const
Is this an absolute (as opposed to relocatable) value.
Definition: MCValue.h:52
MCFixupKind getKind() const
Definition: MCFixup.h:93
const MCSymbolRefExpr * getSymA() const
Definition: MCValue.h:47
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:333
VariantKind getKind() const
Definition: MCExpr.h:320
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:35
MCObjectWriter * createWinCOFFObjectWriter(MCWinCOFFObjectTargetWriter *MOTW, raw_pwrite_stream &OS)
Construct a new Win COFF writer instance.
virtual const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.