LLVM  3.7.0
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/MC/MCAsmBackend.h"
13 #include "llvm/MC/MCFixup.h"
15 #include "llvm/MC/MCValue.h"
17 #include "llvm/Support/COFF.h"
18 #include "llvm/Support/Debug.h"
19 
20 using namespace llvm;
21 
22 namespace {
23 class ARMWinCOFFObjectWriter : public MCWinCOFFObjectTargetWriter {
24 public:
25  ARMWinCOFFObjectWriter(bool Is64Bit)
27  assert(!Is64Bit && "AArch64 support not yet implemented");
28  }
29  ~ARMWinCOFFObjectWriter() override {}
30 
31  unsigned getRelocType(const MCValue &Target, const MCFixup &Fixup,
32  bool IsCrossSection,
33  const MCAsmBackend &MAB) const override;
34 
35  bool recordRelocation(const MCFixup &) const override;
36 };
37 
39  const MCFixup &Fixup,
40  bool IsCrossSection,
41  const MCAsmBackend &MAB) const {
42  assert(getMachine() == COFF::IMAGE_FILE_MACHINE_ARMNT &&
43  "AArch64 support not yet implemented");
44 
46  Target.isAbsolute() ? MCSymbolRefExpr::VK_None : Target.getSymA()->getKind();
47 
48  switch (static_cast<unsigned>(Fixup.getKind())) {
49  default: {
50  const MCFixupKindInfo &Info = MAB.getFixupKindInfo(Fixup.getKind());
51  report_fatal_error(Twine("unsupported relocation type: ") + Info.Name);
52  }
53  case FK_Data_4:
54  switch (Modifier) {
59  default:
61  }
62  case FK_SecRel_2:
64  case FK_SecRel_4:
76  }
77 }
78 
79 bool ARMWinCOFFObjectWriter::recordRelocation(const MCFixup &Fixup) const {
80  return static_cast<unsigned>(Fixup.getKind()) != ARM::fixup_t2_movt_hi16;
81 }
82 }
83 
84 namespace llvm {
86  bool Is64Bit) {
87  MCWinCOFFObjectTargetWriter *MOTW = new ARMWinCOFFObjectWriter(Is64Bit);
88  return createWinCOFFObjectWriter(MOTW, OS);
89 }
90 }
91 
MCObjectWriter * createARMWinCOFFObjectWriter(raw_pwrite_stream &OS, bool Is64Bit)
Construct an ARM PE/COFF object writer.
This represents an "assembler immediate".
Definition: MCValue.h:44
Defines the object file and target independent interfaces used by the assembler backend to write nati...
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
Reports a serious error, calling any installed error handler.
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:62
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
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:38
A four-byte fixup.
Definition: MCFixup.h:26
A two-byte section relative fixup.
Definition: MCFixup.h:37
bool isAbsolute() const
Is this an absolute (as opposed to relocatable) value.
Definition: MCValue.h:56
MCFixupKind getKind() const
Definition: MCFixup.h:89
PowerPC TLS Dynamic Call Fixup
const MCSymbolRefExpr * getSymA() const
Definition: MCValue.h:51
Target - Wrapper for Target specific information.
Target independent information on a fixup kind.
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:321
VariantKind getKind() const
Definition: MCExpr.h:330
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:34
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.