LLVM  8.0.1
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<MCObjectTargetWriter>
92  return llvm::make_unique<LanaiELFObjectWriter>(OSABI);
93 }
This class represents lattice values for constants.
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
block Block Frequency true
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:74
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:63
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
std::unique_ptr< MCObjectTargetWriter > createLanaiELFObjectWriter(uint8_t OSABI)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Target - Wrapper for Target specific information.
const unsigned Kind
MCFixupKind getKind() const
Definition: MCFixup.h:123