1 //===-- MBlazeELFObjectWriter.cpp - MBlaze ELF Writer ---------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "MCTargetDesc/MBlazeMCTargetDesc.h"
11 #include "llvm/MC/MCELFObjectWriter.h"
12 #include "llvm/MC/MCFixup.h"
13 #include "llvm/Support/ErrorHandling.h"
18 class MBlazeELFObjectWriter : public MCELFObjectTargetWriter {
20 MBlazeELFObjectWriter(uint8_t OSABI);
22 virtual ~MBlazeELFObjectWriter();
24 virtual unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,
25 bool IsPCRel, bool IsRelocWithSymbol,
26 int64_t Addend) const;
30 MBlazeELFObjectWriter::MBlazeELFObjectWriter(uint8_t OSABI)
31 : MCELFObjectTargetWriter(/*Is64Bit*/ false, OSABI, ELF::EM_MBLAZE,
32 /*HasRelocationAddend*/ false) {}
34 MBlazeELFObjectWriter::~MBlazeELFObjectWriter() {
37 unsigned MBlazeELFObjectWriter::GetRelocType(const MCValue &Target,
40 bool IsRelocWithSymbol,
41 int64_t Addend) const {
42 // determine the type of the relocation
45 switch ((unsigned)Fixup.getKind()) {
47 llvm_unreachable("Unimplemented");
49 Type = ELF::R_MICROBLAZE_64_PCREL;
52 Type = ELF::R_MICROBLAZE_32_PCREL;
56 switch ((unsigned)Fixup.getKind()) {
57 default: llvm_unreachable("invalid fixup kind!");
59 Type = ((IsRelocWithSymbol || Addend !=0)
60 ? ELF::R_MICROBLAZE_32
61 : ELF::R_MICROBLAZE_64);
64 Type = ELF::R_MICROBLAZE_32;
73 MCObjectWriter *llvm::createMBlazeELFObjectWriter(raw_ostream &OS,
75 MCELFObjectTargetWriter *MOTW = new MBlazeELFObjectWriter(OSABI);
76 return createELFObjectWriter(MOTW, OS, /*IsLittleEndian=*/ false);