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 10 #include "MCTargetDesc/RISCVMCTargetDesc.h" 11 #include "llvm/MC/MCELFObjectWriter.h" 12 #include "llvm/MC/MCFixup.h" 13 #include "llvm/Support/ErrorHandling.h" 14 15 using namespace llvm; 16 17 namespace { 18 class RISCVELFObjectWriter : public MCELFObjectTargetWriter { 19 public: 20 RISCVELFObjectWriter(uint8_t OSABI, bool Is64Bit); 21 22 ~RISCVELFObjectWriter() override; 23 24 protected: 25 unsigned getRelocType(MCContext &Ctx, const MCValue &Target, 26 const MCFixup &Fixup, bool IsPCRel) const override; 27 }; 28 } 29 30 RISCVELFObjectWriter::RISCVELFObjectWriter(uint8_t OSABI, bool Is64Bit) 31 : MCELFObjectTargetWriter(Is64Bit, OSABI, ELF::EM_RISCV, 32 /*HasRelocationAddend*/ true) {} 33 34 RISCVELFObjectWriter::~RISCVELFObjectWriter() {} 35 36 unsigned RISCVELFObjectWriter::getRelocType(MCContext &Ctx, 37 const MCValue &Target, 38 const MCFixup &Fixup, 39 bool IsPCRel) const { 40 report_fatal_error("invalid fixup kind!"); 41 } 42 43 MCObjectWriter *llvm::createRISCVELFObjectWriter(raw_pwrite_stream &OS, 44 uint8_t OSABI, bool Is64Bit) { 45 MCELFObjectTargetWriter *MOTW = new RISCVELFObjectWriter(OSABI, Is64Bit); 46 return createELFObjectWriter(MOTW, OS, /*IsLittleEndian*/ true); 47 } 48