xref: /llvm-project/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp (revision 6b2cca7f8f37f4929328d970582892354a893f5a)
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*/ false) {}
33 
34 RISCVELFObjectWriter::~RISCVELFObjectWriter() {}
35 
36 unsigned RISCVELFObjectWriter::getRelocType(MCContext &Ctx,
37                                             const MCValue &Target,
38                                             const MCFixup &Fixup,
39                                             bool IsPCRel) const {
40   // Determine the type of the relocation
41   switch ((unsigned)Fixup.getKind()) {
42   default:
43     llvm_unreachable("invalid fixup kind!");
44   }
45 }
46 
47 MCObjectWriter *llvm::createRISCVELFObjectWriter(raw_pwrite_stream &OS,
48                                                  uint8_t OSABI, bool Is64Bit) {
49   MCELFObjectTargetWriter *MOTW = new RISCVELFObjectWriter(OSABI, Is64Bit);
50   return createELFObjectWriter(MOTW, OS, /*IsLittleEndian*/ true);
51 }
52