blob: 4a3ac8c5f74122706c15ece6f0991a736901abfe [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"
Benjamin Kramer799003b2015-03-23 19:32:43 +000014#include "llvm/Support/raw_ostream.h"
Colin LeMahieu2c769202014-11-06 17:05:51 +000015
16#define DEBUG_TYPE "hexagon-elf-writer"
17
18using namespace llvm;
19using namespace Hexagon;
20
21namespace {
22
23class HexagonELFObjectWriter : public MCELFObjectTargetWriter {
24private:
Colin LeMahieub6bbeee2014-11-13 16:36:30 +000025 StringRef CPU;
Colin LeMahieu2c769202014-11-06 17:05:51 +000026
27public:
Colin LeMahieub6bbeee2014-11-13 16:36:30 +000028 HexagonELFObjectWriter(uint8_t OSABI, StringRef C);
Colin LeMahieu2c769202014-11-06 17:05:51 +000029
30 virtual unsigned GetRelocType(MCValue const &Target, MCFixup const &Fixup,
31 bool IsPCRel) const override;
32};
33}
34
Colin LeMahieub6bbeee2014-11-13 16:36:30 +000035HexagonELFObjectWriter::HexagonELFObjectWriter(uint8_t OSABI, StringRef C)
Colin LeMahieu2c769202014-11-06 17:05:51 +000036 : MCELFObjectTargetWriter(/*Is64bit*/ false, OSABI, ELF::EM_HEXAGON,
37 /*HasRelocationAddend*/ true),
Colin LeMahieub6bbeee2014-11-13 16:36:30 +000038 CPU(C) {}
Colin LeMahieu2c769202014-11-06 17:05:51 +000039
40unsigned HexagonELFObjectWriter::GetRelocType(MCValue const &/*Target*/,
41 MCFixup const &Fixup,
42 bool IsPCRel) const {
43 unsigned Type = (unsigned)ELF::R_HEX_NONE;
44 llvm::MCFixupKind Kind = Fixup.getKind();
45
46 switch (Kind) {
47 default:
48 DEBUG(dbgs() << "unrecognized relocation " << Fixup.getKind() << "\n");
49 llvm_unreachable("Unimplemented Fixup kind!");
50 break;
51 case FK_Data_4:
52 Type = (IsPCRel) ? ELF::R_HEX_32_PCREL : ELF::R_HEX_32;
53 break;
54 }
55 return Type;
56}
57
58MCObjectWriter *llvm::createHexagonELFObjectWriter(raw_ostream &OS,
59 uint8_t OSABI,
60 StringRef CPU) {
61 MCELFObjectTargetWriter *MOTW = new HexagonELFObjectWriter(OSABI, CPU);
62 return createELFObjectWriter(MOTW, OS, /*IsLittleEndian*/ true);
63}