Colin LeMahieu | 2c76920 | 2014-11-06 17:05:51 +0000 | [diff] [blame] | 1 | //===-- 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 Kramer | 799003b | 2015-03-23 19:32:43 +0000 | [diff] [blame] | 14 | #include "llvm/Support/raw_ostream.h" |
Colin LeMahieu | 2c76920 | 2014-11-06 17:05:51 +0000 | [diff] [blame] | 15 | |
| 16 | #define DEBUG_TYPE "hexagon-elf-writer" |
| 17 | |
| 18 | using namespace llvm; |
| 19 | using namespace Hexagon; |
| 20 | |
| 21 | namespace { |
| 22 | |
| 23 | class HexagonELFObjectWriter : public MCELFObjectTargetWriter { |
| 24 | private: |
Colin LeMahieu | b6bbeee | 2014-11-13 16:36:30 +0000 | [diff] [blame] | 25 | StringRef CPU; |
Colin LeMahieu | 2c76920 | 2014-11-06 17:05:51 +0000 | [diff] [blame] | 26 | |
| 27 | public: |
Colin LeMahieu | b6bbeee | 2014-11-13 16:36:30 +0000 | [diff] [blame] | 28 | HexagonELFObjectWriter(uint8_t OSABI, StringRef C); |
Colin LeMahieu | 2c76920 | 2014-11-06 17:05:51 +0000 | [diff] [blame] | 29 | |
Alexander Kornienko | f817c1c | 2015-04-11 02:11:45 +0000 | [diff] [blame] | 30 | unsigned GetRelocType(MCValue const &Target, MCFixup const &Fixup, |
| 31 | bool IsPCRel) const override; |
Colin LeMahieu | 2c76920 | 2014-11-06 17:05:51 +0000 | [diff] [blame] | 32 | }; |
| 33 | } |
| 34 | |
Colin LeMahieu | b6bbeee | 2014-11-13 16:36:30 +0000 | [diff] [blame] | 35 | HexagonELFObjectWriter::HexagonELFObjectWriter(uint8_t OSABI, StringRef C) |
Colin LeMahieu | 2c76920 | 2014-11-06 17:05:51 +0000 | [diff] [blame] | 36 | : MCELFObjectTargetWriter(/*Is64bit*/ false, OSABI, ELF::EM_HEXAGON, |
| 37 | /*HasRelocationAddend*/ true), |
Colin LeMahieu | b6bbeee | 2014-11-13 16:36:30 +0000 | [diff] [blame] | 38 | CPU(C) {} |
Colin LeMahieu | 2c76920 | 2014-11-06 17:05:51 +0000 | [diff] [blame] | 39 | |
| 40 | unsigned 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 | |
Rafael Espindola | 5560a4c | 2015-04-14 22:14:34 +0000 | [diff] [blame^] | 58 | MCObjectWriter *llvm::createHexagonELFObjectWriter(raw_pwrite_stream &OS, |
Colin LeMahieu | 2c76920 | 2014-11-06 17:05:51 +0000 | [diff] [blame] | 59 | uint8_t OSABI, |
| 60 | StringRef CPU) { |
| 61 | MCELFObjectTargetWriter *MOTW = new HexagonELFObjectWriter(OSABI, CPU); |
| 62 | return createELFObjectWriter(MOTW, OS, /*IsLittleEndian*/ true); |
Rafael Espindola | df7305a | 2015-04-09 17:10:57 +0000 | [diff] [blame] | 63 | } |