Index: ELF/InputFiles.cpp =================================================================== --- ELF/InputFiles.cpp +++ ELF/InputFiles.cpp @@ -803,6 +803,8 @@ return T.isOSIAMCU() ? EM_IAMCU : EM_386; case Triple::x86_64: return EM_X86_64; + case Triple::avr: + return EM_AVR; default: fatal(Path + ": could not infer e_machine from bitcode target triple " + T.str()); Index: ELF/Target.cpp =================================================================== --- ELF/Target.cpp +++ ELF/Target.cpp @@ -247,6 +247,15 @@ void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override; bool usesOnlyLowPageBits(uint32_t Type) const override; }; + +class AVRTargetInfo final : public TargetInfo { +public: + AVRTargetInfo(); + RelExpr getRelExpr(uint32_t Type, const SymbolBody &S, + const uint8_t *Loc) const override; + int64_t getImplicitAddend(const uint8_t *Buf, uint32_t Type) const override; + void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override; +}; } // anonymous namespace TargetInfo *createTarget() { @@ -281,6 +290,8 @@ if (Config->EKind == ELF32LEKind) return make>(); return make>(); + case EM_AVR: + return make(); } fatal("unknown target machine"); } @@ -2403,5 +2414,42 @@ bool MipsTargetInfo::usesOnlyLowPageBits(uint32_t Type) const { return Type == R_MIPS_LO16 || Type == R_MIPS_GOT_OFST; } + +AVRTargetInfo::AVRTargetInfo() { +} + +RelExpr AVRTargetInfo::getRelExpr(uint32_t Type, const SymbolBody &S, + const uint8_t *Loc) const { + switch (Type) { + default: + return R_ABS; + case R_AVR_NONE: + return R_NONE; + } +} + +int64_t AVRTargetInfo::getImplicitAddend(const uint8_t *Buf, + uint32_t Type) const { + switch (Type) { + default: + return 0; + case R_AVR_32: + return SignExtend64<32>(read32le(Buf)); + } +} + +void AVRTargetInfo::relocateOne(uint8_t *Loc, uint32_t Type, + uint64_t Val) const { + switch (Type) { + case R_AVR_32: + write32le(Loc, Val); + break; + case R_AVR_CALL: + error(getErrorLocation(Loc) + "unimplemented relocation type: R_AVR_CALL"); + break; + default: + error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type)); + } +} } } Index: test/ELF/avr-call.s =================================================================== --- test/ELF/avr-call.s +++ test/ELF/avr-call.s @@ -0,0 +1,27 @@ +# Check R_AVR_CALL relocation handling. + +# RUN: llvm-mc -filetype=obj -triple=avr-unknown-linux %s -o %t1.o +# RUN: ld.lld %t1.o -o %t.exe +# RUN: llvm-objdump -d %t.exe | FileCheck %s + +# REQUIRES: avr + +loc: + nop + + .text + .globl setup +setup: + call bar # R_AVR_CALL + call foo # R_AVR_CALL + ret + + .globl loop +loop: + ret + + .globl __start +__start: + ldi r24, 0 + ldi r25, 0 + ret