LLVM  10.0.0svn
ARMWinCOFFObjectWriter.cpp
Go to the documentation of this file.
1 //===-- ARMWinCOFFObjectWriter.cpp - ARM Windows COFF Object Writer -- C++ -==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 #include "llvm/ADT/Twine.h"
11 #include "llvm/BinaryFormat/COFF.h"
12 #include "llvm/MC/MCAsmBackend.h"
13 #include "llvm/MC/MCExpr.h"
14 #include "llvm/MC/MCFixup.h"
16 #include "llvm/MC/MCObjectWriter.h"
17 #include "llvm/MC/MCValue.h"
21 #include <cassert>
22 
23 using namespace llvm;
24 
25 namespace {
26 
27 class ARMWinCOFFObjectWriter : public MCWinCOFFObjectTargetWriter {
28 public:
29  ARMWinCOFFObjectWriter(bool Is64Bit)
31  assert(!Is64Bit && "AArch64 support not yet implemented");
32  }
33 
34  ~ARMWinCOFFObjectWriter() 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  const MCValue &Target,
47  const MCFixup &Fixup,
48  bool IsCrossSection,
49  const MCAsmBackend &MAB) const {
50  assert(getMachine() == COFF::IMAGE_FILE_MACHINE_ARMNT &&
51  "AArch64 support not yet implemented");
52 
54  Target.isAbsolute() ? MCSymbolRefExpr::VK_None : Target.getSymA()->getKind();
55 
56  switch (static_cast<unsigned>(Fixup.getKind())) {
57  default: {
58  const MCFixupKindInfo &Info = MAB.getFixupKindInfo(Fixup.getKind());
59  report_fatal_error(Twine("unsupported relocation type: ") + Info.Name);
60  }
61  case FK_Data_4:
62  switch (Modifier) {
67  default:
69  }
70  case FK_SecRel_2:
72  case FK_SecRel_4:
84  }
85 }
86 
87 bool ARMWinCOFFObjectWriter::recordRelocation(const MCFixup &Fixup) const {
88  return static_cast<unsigned>(Fixup.getKind()) != ARM::fixup_t2_movt_hi16;
89 }
90 
91 namespace llvm {
92 
93 std::unique_ptr<MCObjectTargetWriter>
95  return std::make_unique<ARMWinCOFFObjectWriter>(Is64Bit);
96 }
97 
98 } // 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
This class represents lattice values for constants.
Definition: AllocatorList.h:23
This represents an "assembler immediate".
Definition: MCValue.h:39
VariantKind getKind() const
Definition: MCExpr.h:344
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:52
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:77
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
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:43
A four-byte fixup.
Definition: MCFixup.h:26
Context object for machine code objects.
Definition: MCContext.h:65
A two-byte section relative fixup.
Definition: MCFixup.h:42
Analysis containing CSE Info
Definition: CSEInfo.cpp:20
const MCSymbolRefExpr * getSymA() const
Definition: MCValue.h:47
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:41
MCFixupKind getKind() const
Definition: MCFixup.h:126