LLVM  8.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 
12 #include "llvm/ADT/Twine.h"
13 #include "llvm/BinaryFormat/COFF.h"
14 #include "llvm/MC/MCAsmBackend.h"
15 #include "llvm/MC/MCExpr.h"
16 #include "llvm/MC/MCFixup.h"
18 #include "llvm/MC/MCObjectWriter.h"
19 #include "llvm/MC/MCValue.h"
23 #include <cassert>
24 
25 using namespace llvm;
26 
27 namespace {
28 
29 class AArch64WinCOFFObjectWriter : public MCWinCOFFObjectTargetWriter {
30 public:
31  AArch64WinCOFFObjectWriter()
33 
34  ~AArch64WinCOFFObjectWriter() 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 
46  MCContext &Ctx, const MCValue &Target, const MCFixup &Fixup,
47  bool IsCrossSection, const MCAsmBackend &MAB) const {
48  auto Modifier = Target.isAbsolute() ? MCSymbolRefExpr::VK_None
49  : Target.getSymA()->getKind();
50  const MCExpr *Expr = Fixup.getValue();
51 
52  switch (static_cast<unsigned>(Fixup.getKind())) {
53  default: {
54  const MCFixupKindInfo &Info = MAB.getFixupKindInfo(Fixup.getKind());
55  report_fatal_error(Twine("unsupported relocation type: ") + Info.Name);
56  }
57 
58  case FK_Data_4:
59  switch (Modifier) {
60  default:
66  }
67 
68  case FK_Data_8:
70 
71  case FK_SecRel_2:
73 
74  case FK_SecRel_4:
76 
78  if (const AArch64MCExpr *A64E = dyn_cast<AArch64MCExpr>(Expr)) {
79  AArch64MCExpr::VariantKind RefKind = A64E->getKind();
80  if (RefKind == AArch64MCExpr::VK_SECREL_LO12)
82  if (RefKind == AArch64MCExpr::VK_SECREL_HI12)
84  }
86 
92  if (const AArch64MCExpr *A64E = dyn_cast<AArch64MCExpr>(Expr)) {
93  AArch64MCExpr::VariantKind RefKind = A64E->getKind();
94  if (RefKind == AArch64MCExpr::VK_SECREL_LO12)
96  }
98 
101 
104 
107 
110 
114  }
115 }
116 
117 bool AArch64WinCOFFObjectWriter::recordRelocation(const MCFixup &Fixup) const {
118  return true;
119 }
120 
121 namespace llvm {
122 
123 std::unique_ptr<MCObjectTargetWriter> createAArch64WinCOFFObjectWriter() {
124  return llvm::make_unique<AArch64WinCOFFObjectWriter>();
125 }
126 
127 } // 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:139
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:337
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
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
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
const MCSymbolRefExpr * getSymA() const
Definition: MCValue.h:48
Target - Wrapper for Target specific information.
std::unique_ptr< MCObjectTargetWriter > createAArch64WinCOFFObjectWriter()
A eight-byte fixup.
Definition: MCFixup.h:27
Target independent information on a fixup kind.
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:42
const MCExpr * getValue() const
Definition: MCFixup.h:128
MCFixupKind getKind() const
Definition: MCFixup.h:123