LLVM  6.0.0svn
LanaiELFObjectWriter.cpp
Go to the documentation of this file.
1 //===-- LanaiELFObjectWriter.cpp - Lanai ELF Writer -----------------------===//
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/BinaryFormat/ELF.h"
14 #include "llvm/MC/MCObjectWriter.h"
16 
17 using namespace llvm;
18 
19 namespace {
20 
21 class LanaiELFObjectWriter : public MCELFObjectTargetWriter {
22 public:
23  explicit LanaiELFObjectWriter(uint8_t OSABI);
24 
25  ~LanaiELFObjectWriter() override = default;
26 
27 protected:
28  unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
29  const MCFixup &Fixup, bool IsPCRel) const override;
30  bool needsRelocateWithSymbol(const MCSymbol &SD,
31  unsigned Type) const override;
32 };
33 
34 } // end anonymous namespace
35 
36 LanaiELFObjectWriter::LanaiELFObjectWriter(uint8_t OSABI)
37  : MCELFObjectTargetWriter(/*Is64Bit_=*/false, OSABI, ELF::EM_LANAI,
38  /*HasRelocationAddend=*/true) {}
39 
41  const MCValue & /*Target*/,
42  const MCFixup &Fixup,
43  bool /*IsPCRel*/) const {
44  unsigned Type;
45  unsigned Kind = static_cast<unsigned>(Fixup.getKind());
46  switch (Kind) {
48  Type = ELF::R_LANAI_21;
49  break;
51  Type = ELF::R_LANAI_21_F;
52  break;
54  Type = ELF::R_LANAI_25;
55  break;
57  case FK_Data_4:
58  Type = ELF::R_LANAI_32;
59  break;
61  Type = ELF::R_LANAI_HI16;
62  break;
64  Type = ELF::R_LANAI_LO16;
65  break;
67  Type = ELF::R_LANAI_NONE;
68  break;
69 
70  default:
71  llvm_unreachable("Invalid fixup kind!");
72  }
73  return Type;
74 }
75 
76 bool LanaiELFObjectWriter::needsRelocateWithSymbol(const MCSymbol & /*SD*/,
77  unsigned Type) const {
78  switch (Type) {
79  case ELF::R_LANAI_21:
80  case ELF::R_LANAI_21_F:
81  case ELF::R_LANAI_25:
82  case ELF::R_LANAI_32:
83  case ELF::R_LANAI_HI16:
84  return true;
85  default:
86  return false;
87  }
88 }
89 
90 std::unique_ptr<MCObjectWriter>
92  return createELFObjectWriter(llvm::make_unique<LanaiELFObjectWriter>(OSABI),
93  OS, /*IsLittleEndian=*/false);
94 }
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
This represents an "assembler immediate".
Definition: MCValue.h:40
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:66
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 fixup.
Definition: MCFixup.h:26
Context object for machine code objects.
Definition: MCContext.h:59
std::unique_ptr< MCObjectWriter > createELFObjectWriter(std::unique_ptr< MCELFObjectTargetWriter > MOTW, raw_pwrite_stream &OS, bool IsLittleEndian)
Construct a new ELF writer instance.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Target - Wrapper for Target specific information.
Basic Alias true
std::unique_ptr< MCObjectWriter > createLanaiELFObjectWriter(raw_pwrite_stream &OS, uint8_t OSABI)
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:337
const unsigned Kind
MCFixupKind getKind() const
Definition: MCFixup.h:93