LLVM  6.0.0svn
RISCVELFObjectWriter.cpp
Go to the documentation of this file.
1 //===-- RISCVELFObjectWriter.cpp - RISCV 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/MC/MCFixup.h"
14 #include "llvm/MC/MCObjectWriter.h"
16 
17 using namespace llvm;
18 
19 namespace {
20 class RISCVELFObjectWriter : public MCELFObjectTargetWriter {
21 public:
22  RISCVELFObjectWriter(uint8_t OSABI, bool Is64Bit);
23 
24  ~RISCVELFObjectWriter() override;
25 
26 protected:
27  unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
28  const MCFixup &Fixup, bool IsPCRel) const override;
29 };
30 }
31 
32 RISCVELFObjectWriter::RISCVELFObjectWriter(uint8_t OSABI, bool Is64Bit)
33  : MCELFObjectTargetWriter(Is64Bit, OSABI, ELF::EM_RISCV,
34  /*HasRelocationAddend*/ true) {}
35 
36 RISCVELFObjectWriter::~RISCVELFObjectWriter() {}
37 
39  const MCValue &Target,
40  const MCFixup &Fixup,
41  bool IsPCRel) const {
42  // Determine the type of the relocation
43  switch ((unsigned)Fixup.getKind()) {
44  default:
45  llvm_unreachable("invalid fixup kind!");
46  case FK_Data_4:
47  return ELF::R_RISCV_32;
48  case FK_Data_8:
49  return ELF::R_RISCV_64;
51  return ELF::R_RISCV_HI20;
53  return ELF::R_RISCV_LO12_I;
55  return ELF::R_RISCV_LO12_S;
57  return ELF::R_RISCV_PCREL_HI20;
59  return ELF::R_RISCV_JAL;
61  return ELF::R_RISCV_BRANCH;
62  }
63 }
64 
65 std::unique_ptr<MCObjectWriter>
67  bool Is64Bit) {
68  return createELFObjectWriter(
69  llvm::make_unique<RISCVELFObjectWriter>(OSABI, Is64Bit), OS,
70  /*IsLittleEndian=*/true);
71 }
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
This represents an "assembler immediate".
Definition: MCValue.h:40
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.
std::unique_ptr< MCObjectWriter > createRISCVELFObjectWriter(raw_pwrite_stream &OS, uint8_t OSABI, bool Is64Bit)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Target - Wrapper for Target specific information.
Basic Alias true
A eight-byte fixup.
Definition: MCFixup.h:27
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:337
MCFixupKind getKind() const
Definition: MCFixup.h:93