[lld] r305444 - [ELF] Initial migration of AVR target
Leslie Zhai via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 14 19:27:50 PDT 2017
Author: xiangzhai
Date: Wed Jun 14 21:27:50 2017
New Revision: 305444
URL: http://llvm.org/viewvc/llvm-project?rev=305444&view=rev
Log:
[ELF] Initial migration of AVR target
Reviewers: ruiu, rafael, grimar, atanasyan, psmith, dylanmckay
Reviewed By: ruiu, rafael, grimar, dylanmckay
Differential Revision: https://reviews.llvm.org/D32991
Added:
lld/trunk/test/ELF/basic-avr.s
Modified:
lld/trunk/ELF/InputFiles.cpp
lld/trunk/ELF/Target.cpp
lld/trunk/test/lit.cfg
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=305444&r1=305443&r2=305444&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Wed Jun 14 21:27:50 2017
@@ -821,6 +821,8 @@ static uint8_t getBitcodeMachineKind(Str
case Triple::arm:
case Triple::thumb:
return EM_ARM;
+ case Triple::avr:
+ return EM_AVR;
case Triple::mips:
case Triple::mipsel:
case Triple::mips64:
Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=305444&r1=305443&r2=305444&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Wed Jun 14 21:27:50 2017
@@ -230,6 +230,13 @@ public:
void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override;
};
+class AVRTargetInfo final : public TargetInfo {
+public:
+ RelExpr getRelExpr(uint32_t Type, const SymbolBody &S,
+ const uint8_t *Loc) const override;
+ void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override;
+};
+
template <class ELFT> class MipsTargetInfo final : public TargetInfo {
public:
MipsTargetInfo();
@@ -260,6 +267,8 @@ TargetInfo *createTarget() {
return make<AMDGPUTargetInfo>();
case EM_ARM:
return make<ARMTargetInfo>();
+ case EM_AVR:
+ return make<AVRTargetInfo>();
case EM_MIPS:
switch (Config->EKind) {
case ELF32LEKind:
@@ -2046,6 +2055,32 @@ int64_t ARMTargetInfo::getImplicitAddend
}
}
+RelExpr AVRTargetInfo::getRelExpr(uint32_t Type, const SymbolBody &S,
+ const uint8_t *Loc) const {
+ switch (Type) {
+ case R_AVR_CALL:
+ return R_ABS;
+ default:
+ error(toString(S.File) + ": unknown relocation type: " + toString(Type));
+ return R_HINT;
+ }
+}
+
+void AVRTargetInfo::relocateOne(uint8_t *Loc, uint32_t Type,
+ uint64_t Val) const {
+ switch (Type) {
+ case R_AVR_CALL: {
+ uint16_t Hi = Val >> 17;
+ uint16_t Lo = Val >> 1;
+ write16le(Loc, read16le(Loc) | ((Hi >> 1) << 4) | (Hi & 1));
+ write16le(Loc + 2, Lo);
+ break;
+ }
+ default:
+ error(getErrorLocation(Loc) + "unrecognized reloc " + toString(Type));
+ }
+}
+
template <class ELFT> MipsTargetInfo<ELFT>::MipsTargetInfo() {
GotPltHeaderEntriesNum = 2;
DefaultMaxPageSize = 65536;
Added: lld/trunk/test/ELF/basic-avr.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/basic-avr.s?rev=305444&view=auto
==============================================================================
--- lld/trunk/test/ELF/basic-avr.s (added)
+++ lld/trunk/test/ELF/basic-avr.s Wed Jun 14 21:27:50 2017
@@ -0,0 +1,14 @@
+# REQUIRES: avr
+# RUN: llvm-mc -filetype=obj -triple=avr-unknown-linux -mcpu=atmega328p %s -o %t.o
+# RUN: ld.lld %t.o -o %t.exe -Ttext=0
+# RUN: llvm-objdump -d %t.exe | FileCheck %s
+
+main:
+ call foo
+foo:
+ jmp foo
+
+# CHECK: main:
+# CHECK-NEXT: 0: 0e 94 02 00 <unknown>
+# CHECK: foo:
+# CHECK-NEXT: 4: 0c 94 02 00 <unknown>
Modified: lld/trunk/test/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/lit.cfg?rev=305444&r1=305443&r2=305444&view=diff
==============================================================================
--- lld/trunk/test/lit.cfg (original)
+++ lld/trunk/test/lit.cfg Wed Jun 14 21:27:50 2017
@@ -247,6 +247,8 @@ if re.search(r'AArch64', archs):
config.available_features.add('aarch64')
if re.search(r'ARM', archs):
config.available_features.add('arm')
+if re.search(r'AVR', archs):
+ config.available_features.add('avr')
if re.search(r'Mips', archs):
config.available_features.add('mips')
if re.search(r'X86', archs):
More information about the llvm-commits
mailing list