[lld] r350819 - [LLD][ELF] - Support MSP430.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 10 05:43:07 PST 2019
Author: grimar
Date: Thu Jan 10 05:43:06 2019
New Revision: 350819
URL: http://llvm.org/viewvc/llvm-project?rev=350819&view=rev
Log:
[LLD][ELF] - Support MSP430.
Patch by Michael Skvortsov!
This change adds a basic support for linking static MSP430 ELF code.
Implemented relocation types are intended to correspond to the BFD.
Differential revision: https://reviews.llvm.org/D56535
Added:
lld/trunk/ELF/Arch/MSP430.cpp
lld/trunk/test/ELF/Inputs/msp430.s
Modified:
lld/trunk/ELF/CMakeLists.txt
lld/trunk/ELF/InputFiles.cpp
lld/trunk/ELF/Target.cpp
lld/trunk/ELF/Target.h
lld/trunk/test/lit.cfg.py
Added: lld/trunk/ELF/Arch/MSP430.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/MSP430.cpp?rev=350819&view=auto
==============================================================================
--- lld/trunk/ELF/Arch/MSP430.cpp (added)
+++ lld/trunk/ELF/Arch/MSP430.cpp Thu Jan 10 05:43:06 2019
@@ -0,0 +1,94 @@
+//===- MSP430.cpp ---------------------------------------------------------===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// The MSP430 is a 16-bit microcontroller RISC architecture. The instruction set
+// has only 27 core instructions orthogonally augmented with a variety
+// of addressing modes for source and destination operands. Entire address space
+// of MSP430 is 64KB (the extended MSP430X architecture is not considered here).
+// A typical MSP430 MCU has several kilobytes of RAM and ROM, plenty
+// of peripherals and is generally optimized for a low power consumption.
+//
+//===----------------------------------------------------------------------===//
+
+#include "InputFiles.h"
+#include "Symbols.h"
+#include "Target.h"
+#include "lld/Common/ErrorHandler.h"
+#include "llvm/Object/ELF.h"
+#include "llvm/Support/Endian.h"
+
+using namespace llvm;
+using namespace llvm::object;
+using namespace llvm::support::endian;
+using namespace llvm::ELF;
+using namespace lld;
+using namespace lld::elf;
+
+namespace {
+class MSP430 final : public TargetInfo {
+public:
+ MSP430();
+ RelExpr getRelExpr(RelType Type, const Symbol &S,
+ const uint8_t *Loc) const override;
+ void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override;
+};
+} // namespace
+
+MSP430::MSP430() {
+ // mov.b #0, r3
+ TrapInstr = {0x43, 0x43};
+}
+
+RelExpr MSP430::getRelExpr(RelType Type, const Symbol &S,
+ const uint8_t *Loc) const {
+ switch (Type) {
+ case R_MSP430_10_PCREL:
+ case R_MSP430_16_PCREL:
+ case R_MSP430_16_PCREL_BYTE:
+ case R_MSP430_2X_PCREL:
+ case R_MSP430_RL_PCREL:
+ case R_MSP430_SYM_DIFF:
+ return R_PC;
+ default:
+ return R_ABS;
+ }
+}
+
+void MSP430::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
+ switch (Type) {
+ case R_MSP430_8:
+ checkIntUInt(Loc, Val, 8, Type);
+ *Loc = Val;
+ break;
+ case R_MSP430_16:
+ case R_MSP430_16_PCREL:
+ case R_MSP430_16_BYTE:
+ case R_MSP430_16_PCREL_BYTE:
+ checkIntUInt(Loc, Val, 16, Type);
+ write16le(Loc, Val);
+ break;
+ case R_MSP430_32:
+ checkIntUInt(Loc, Val, 32, Type);
+ write32le(Loc, Val);
+ break;
+ case R_MSP430_10_PCREL: {
+ int16_t Offset = ((int16_t)Val >> 1) - 1;
+ checkInt(Loc, Offset, 10, Type);
+ write16le(Loc, (read16le(Loc) & 0xFC00) | (Offset & 0x3FF));
+ break;
+ }
+ default:
+ error(getErrorLocation(Loc) + "unrecognized reloc " + toString(Type));
+ }
+}
+
+TargetInfo *elf::getMSP430TargetInfo() {
+ static MSP430 Target;
+ return &Target;
+}
Modified: lld/trunk/ELF/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/CMakeLists.txt?rev=350819&r1=350818&r2=350819&view=diff
==============================================================================
--- lld/trunk/ELF/CMakeLists.txt (original)
+++ lld/trunk/ELF/CMakeLists.txt Thu Jan 10 05:43:06 2019
@@ -15,6 +15,7 @@ add_lld_library(lldELF
Arch/Hexagon.cpp
Arch/Mips.cpp
Arch/MipsArchTree.cpp
+ Arch/MSP430.cpp
Arch/PPC.cpp
Arch/PPC64.cpp
Arch/RISCV.cpp
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=350819&r1=350818&r2=350819&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Thu Jan 10 05:43:06 2019
@@ -1081,6 +1081,8 @@ static uint8_t getBitcodeMachineKind(Str
case Triple::mips64:
case Triple::mips64el:
return EM_MIPS;
+ case Triple::msp430:
+ return EM_MSP430;
case Triple::ppc:
return EM_PPC;
case Triple::ppc64:
Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=350819&r1=350818&r2=350819&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Thu Jan 10 05:43:06 2019
@@ -75,6 +75,8 @@ TargetInfo *elf::getTarget() {
default:
llvm_unreachable("unsupported MIPS target");
}
+ case EM_MSP430:
+ return getMSP430TargetInfo();
case EM_PPC:
return getPPCTargetInfo();
case EM_PPC64:
Modified: lld/trunk/ELF/Target.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.h?rev=350819&r1=350818&r2=350819&view=diff
==============================================================================
--- lld/trunk/ELF/Target.h (original)
+++ lld/trunk/ELF/Target.h Thu Jan 10 05:43:06 2019
@@ -146,6 +146,7 @@ TargetInfo *getAMDGPUTargetInfo();
TargetInfo *getARMTargetInfo();
TargetInfo *getAVRTargetInfo();
TargetInfo *getHexagonTargetInfo();
+TargetInfo *getMSP430TargetInfo();
TargetInfo *getPPC64TargetInfo();
TargetInfo *getPPCTargetInfo();
TargetInfo *getRISCVTargetInfo();
Added: lld/trunk/test/ELF/Inputs/msp430.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/msp430.s?rev=350819&view=auto
==============================================================================
--- lld/trunk/test/ELF/Inputs/msp430.s (added)
+++ lld/trunk/test/ELF/Inputs/msp430.s Thu Jan 10 05:43:06 2019
@@ -0,0 +1,4 @@
+ .text
+ .global _start
+_start:
+ nop
Modified: lld/trunk/test/lit.cfg.py
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/lit.cfg.py?rev=350819&r1=350818&r2=350819&view=diff
==============================================================================
--- lld/trunk/test/lit.cfg.py (original)
+++ lld/trunk/test/lit.cfg.py Thu Jan 10 05:43:06 2019
@@ -72,6 +72,7 @@ llvm_config.feature_config(
'AVR': 'avr',
'Hexagon': 'hexagon',
'Mips': 'mips',
+ 'MSP430': 'msp430',
'PowerPC': 'ppc',
'RISCV': 'riscv',
'Sparc': 'sparc',
More information about the llvm-commits
mailing list