blob: def20dd48e4fa14c68d73eb6dda57e313bb4171d [file] [log] [blame]
Alex Bradbury6b2cca72016-11-01 23:47:30 +00001//===-- 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
15using namespace llvm;
16
17namespace {
18class RISCVELFObjectWriter : public MCELFObjectTargetWriter {
19public:
20 RISCVELFObjectWriter(uint8_t OSABI, bool Is64Bit);
21
22 ~RISCVELFObjectWriter() override;
23
24protected:
25 unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
26 const MCFixup &Fixup, bool IsPCRel) const override;
27};
28}
29
30RISCVELFObjectWriter::RISCVELFObjectWriter(uint8_t OSABI, bool Is64Bit)
31 : MCELFObjectTargetWriter(Is64Bit, OSABI, ELF::EM_RISCV,
32 /*HasRelocationAddend*/ false) {}
33
34RISCVELFObjectWriter::~RISCVELFObjectWriter() {}
35
36unsigned 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
47MCObjectWriter *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}