LLVM  10.0.0svn
MSP430ELFObjectWriter.cpp
Go to the documentation of this file.
1 //===-- MSP430ELFObjectWriter.cpp - MSP430 ELF Writer ---------------------===//
2 //
3 // 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
6 //
7 //===----------------------------------------------------------------------===//
8 
11 
14 #include "llvm/MC/MCFixup.h"
15 #include "llvm/MC/MCObjectWriter.h"
16 #include "llvm/MC/MCValue.h"
18 
19 using namespace llvm;
20 
21 namespace {
22 class MSP430ELFObjectWriter : public MCELFObjectTargetWriter {
23 public:
24  MSP430ELFObjectWriter(uint8_t OSABI)
26  /*HasRelocationAddend*/ true) {}
27 
28  ~MSP430ELFObjectWriter() override {}
29 
30 protected:
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 (Fixup.getTargetKind()) {
35  case FK_Data_1: return ELF::R_MSP430_8;
36  case FK_Data_2: return ELF::R_MSP430_16_BYTE;
37  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 
55 std::unique_ptr<MCObjectTargetWriter>
57  return std::make_unique<MSP430ELFObjectWriter>(OSABI);
58 }
This class represents lattice values for constants.
Definition: AllocatorList.h:23
This represents an "assembler immediate".
Definition: MCValue.h:39
block Block Frequency true
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:77
static unsigned getRelocType(const MCValue &Target, const MCFixupKind FixupKind, const bool IsPCRel)
Translates generic PPC fixup kind to Mach-O/PPC relocation type enum.
A four-byte fixup.
Definition: MCFixup.h:26
Context object for machine code objects.
Definition: MCContext.h:65
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
A one-byte fixup.
Definition: MCFixup.h:24
std::unique_ptr< MCObjectTargetWriter > createMSP430ELFObjectWriter(uint8_t OSABI)
Target - Wrapper for Target specific information.
unsigned getTargetKind() const
Definition: MCFixup.h:128
A two-byte fixup.
Definition: MCFixup.h:25