blob: 56c9dc712a6e918df1823e60fad7f5fa19f81aea [file] [log] [blame]
Colin LeMahieu2c769202014-11-06 17:05:51 +00001//===-- HexagonELFObjectWriter.cpp - Hexagon Target Descriptions ----------===//
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 "Hexagon.h"
11#include "llvm/MC/MCAssembler.h"
12#include "llvm/MC/MCELFObjectWriter.h"
13#include "llvm/Support/Debug.h"
14
15#define DEBUG_TYPE "hexagon-elf-writer"
16
17using namespace llvm;
18using namespace Hexagon;
19
20namespace {
21
22class HexagonELFObjectWriter : public MCELFObjectTargetWriter {
23private:
Colin LeMahieub6bbeee2014-11-13 16:36:30 +000024 StringRef CPU;
Colin LeMahieu2c769202014-11-06 17:05:51 +000025
26public:
Colin LeMahieub6bbeee2014-11-13 16:36:30 +000027 HexagonELFObjectWriter(uint8_t OSABI, StringRef C);
Colin LeMahieu2c769202014-11-06 17:05:51 +000028
29 virtual unsigned GetRelocType(MCValue const &Target, MCFixup const &Fixup,
30 bool IsPCRel) const override;
31};
32}
33
Colin LeMahieub6bbeee2014-11-13 16:36:30 +000034HexagonELFObjectWriter::HexagonELFObjectWriter(uint8_t OSABI, StringRef C)
Colin LeMahieu2c769202014-11-06 17:05:51 +000035 : MCELFObjectTargetWriter(/*Is64bit*/ false, OSABI, ELF::EM_HEXAGON,
36 /*HasRelocationAddend*/ true),
Colin LeMahieub6bbeee2014-11-13 16:36:30 +000037 CPU(C) {}
Colin LeMahieu2c769202014-11-06 17:05:51 +000038
39unsigned HexagonELFObjectWriter::GetRelocType(MCValue const &/*Target*/,
40 MCFixup const &Fixup,
41 bool IsPCRel) const {
42 unsigned Type = (unsigned)ELF::R_HEX_NONE;
43 llvm::MCFixupKind Kind = Fixup.getKind();
44
45 switch (Kind) {
46 default:
47 DEBUG(dbgs() << "unrecognized relocation " << Fixup.getKind() << "\n");
48 llvm_unreachable("Unimplemented Fixup kind!");
49 break;
50 case FK_Data_4:
51 Type = (IsPCRel) ? ELF::R_HEX_32_PCREL : ELF::R_HEX_32;
52 break;
53 }
54 return Type;
55}
56
57MCObjectWriter *llvm::createHexagonELFObjectWriter(raw_ostream &OS,
58 uint8_t OSABI,
59 StringRef CPU) {
60 MCELFObjectTargetWriter *MOTW = new HexagonELFObjectWriter(OSABI, CPU);
61 return createELFObjectWriter(MOTW, OS, /*IsLittleEndian*/ true);
62}