blob: 38b7da32c24690725b847550315d3ed2792de666 [file] [log] [blame]
Anton Korobeynikovf0001f42018-11-15 12:35:04 +00001//===-- MSP430ELFObjectWriter.cpp - MSP430 ELF Writer ---------------------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Anton Korobeynikovf0001f42018-11-15 12:35:04 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "MCTargetDesc/MSP430FixupKinds.h"
10#include "MCTargetDesc/MSP430MCTargetDesc.h"
11
12#include "MCTargetDesc/MSP430MCTargetDesc.h"
13#include "llvm/MC/MCELFObjectWriter.h"
14#include "llvm/MC/MCFixup.h"
15#include "llvm/MC/MCObjectWriter.h"
16#include "llvm/MC/MCValue.h"
17#include "llvm/Support/ErrorHandling.h"
18
19using namespace llvm;
20
21namespace {
22class MSP430ELFObjectWriter : public MCELFObjectTargetWriter {
23public:
24 MSP430ELFObjectWriter(uint8_t OSABI)
25 : MCELFObjectTargetWriter(false, OSABI, ELF::EM_MSP430,
26 /*HasRelocationAddend*/ true) {}
27
28 ~MSP430ELFObjectWriter() override {}
29
30protected:
31 unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
32 const MCFixup &Fixup, bool IsPCRel) const override {
33 // Translate fixup kind to ELF relocation type.
34 switch ((unsigned)Fixup.getKind()) {
35 case FK_Data_1: return ELF::R_MSP430_8;
Anton Korobeynikov883c7092018-11-16 19:20:51 +000036 case FK_Data_2: return ELF::R_MSP430_16_BYTE;
Anton Korobeynikovf0001f42018-11-15 12:35:04 +000037 case FK_Data_4: return ELF::R_MSP430_32;
38 case MSP430::fixup_32: return ELF::R_MSP430_32;
39 case MSP430::fixup_10_pcrel: return ELF::R_MSP430_10_PCREL;
40 case MSP430::fixup_16: return ELF::R_MSP430_16;
41 case MSP430::fixup_16_pcrel: return ELF::R_MSP430_16_PCREL;
42 case MSP430::fixup_16_byte: return ELF::R_MSP430_16_BYTE;
43 case MSP430::fixup_16_pcrel_byte: return ELF::R_MSP430_16_PCREL_BYTE;
44 case MSP430::fixup_2x_pcrel: return ELF::R_MSP430_2X_PCREL;
45 case MSP430::fixup_rl_pcrel: return ELF::R_MSP430_RL_PCREL;
46 case MSP430::fixup_8: return ELF::R_MSP430_8;
47 case MSP430::fixup_sym_diff: return ELF::R_MSP430_SYM_DIFF;
48 default:
49 llvm_unreachable("Invalid fixup kind");
50 }
51 }
52};
53} // end of anonymous namespace
54
55std::unique_ptr<MCObjectTargetWriter>
56llvm::createMSP430ELFObjectWriter(uint8_t OSABI) {
57 return llvm::make_unique<MSP430ELFObjectWriter>(OSABI);
58}