Index: ELF/InputFiles.cpp =================================================================== --- ELF/InputFiles.cpp +++ ELF/InputFiles.cpp @@ -821,6 +821,8 @@ case Triple::arm: case Triple::thumb: return EM_ARM; + case Triple::avr: + return EM_AVR; case Triple::mips: case Triple::mipsel: case Triple::mips64: Index: ELF/Target.cpp =================================================================== --- ELF/Target.cpp +++ ELF/Target.cpp @@ -230,6 +230,13 @@ 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 MipsTargetInfo final : public TargetInfo { public: MipsTargetInfo(); @@ -260,6 +267,8 @@ return make(); case EM_ARM: return make(); + case EM_AVR: + return make(); case EM_MIPS: switch (Config->EKind) { case ELF32LEKind: @@ -2046,6 +2055,32 @@ } } +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 MipsTargetInfo::MipsTargetInfo() { GotPltHeaderEntriesNum = 2; DefaultMaxPageSize = 65536; Index: test/ELF/basic-avr.s =================================================================== --- test/ELF/basic-avr.s +++ test/ELF/basic-avr.s @@ -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 +# CHECK: foo: +# CHECK-NEXT: 4: 0c 94 02 00 Index: test/lit.cfg =================================================================== --- test/lit.cfg +++ test/lit.cfg @@ -247,6 +247,8 @@ 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):