LLVM  4.0.0
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 
13 #include "llvm/Support/ELF.h"
15 
16 using namespace llvm;
17 
18 namespace {
19 
20 class LanaiELFObjectWriter : public MCELFObjectTargetWriter {
21 public:
22  explicit LanaiELFObjectWriter(uint8_t OSABI);
23 
24  ~LanaiELFObjectWriter() override = default;
25 
26 protected:
27  unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
28  const MCFixup &Fixup, bool IsPCRel) const override;
29  bool needsRelocateWithSymbol(const MCSymbol &SD,
30  unsigned Type) const override;
31 };
32 
33 } // end anonymous namespace
34 
35 LanaiELFObjectWriter::LanaiELFObjectWriter(uint8_t OSABI)
36  : MCELFObjectTargetWriter(/*Is64Bit_=*/false, OSABI, ELF::EM_LANAI,
37  /*HasRelocationAddend=*/true) {}
38 
40  const MCValue & /*Target*/,
41  const MCFixup &Fixup,
42  bool /*IsPCRel*/) const {
43  unsigned Type;
44  unsigned Kind = static_cast<unsigned>(Fixup.getKind());
45  switch (Kind) {
47  Type = ELF::R_LANAI_21;
48  break;
50  Type = ELF::R_LANAI_21_F;
51  break;
53  Type = ELF::R_LANAI_25;
54  break;
56  case FK_Data_4:
57  Type = ELF::R_LANAI_32;
58  break;
60  Type = ELF::R_LANAI_HI16;
61  break;
63  Type = ELF::R_LANAI_LO16;
64  break;
66  Type = ELF::R_LANAI_NONE;
67  break;
68 
69  default:
70  llvm_unreachable("Invalid fixup kind!");
71  }
72  return Type;
73 }
74 
75 bool LanaiELFObjectWriter::needsRelocateWithSymbol(const MCSymbol & /*SD*/,
76  unsigned Type) const {
77  switch (Type) {
78  case ELF::R_LANAI_21:
79  case ELF::R_LANAI_21_F:
80  case ELF::R_LANAI_25:
81  case ELF::R_LANAI_32:
82  case ELF::R_LANAI_HI16:
83  return true;
84  default:
85  return false;
86  }
87 }
88 
90  uint8_t OSABI) {
91  MCELFObjectTargetWriter *MOTW = new LanaiELFObjectWriter(OSABI);
92  return createELFObjectWriter(MOTW, OS, /*IsLittleEndian=*/false);
93 }
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:39
Defines the object file and target independent interfaces used by the assembler backend to write nati...
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:51
MCObjectWriter * createLanaiELFObjectWriter(raw_pwrite_stream &OS, uint8_t OSABI)
Function Alias Analysis false
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
MCFixupKind getKind() const
Definition: MCFixup.h:93
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Target - Wrapper for Target specific information.
MCObjectWriter * createELFObjectWriter(MCELFObjectTargetWriter *MOTW, raw_pwrite_stream &OS, bool IsLittleEndian)
Construct a new ELF writer instance.
Basic Alias true
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:333
const unsigned Kind