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"); } @@ -2411,5 +2422,34 @@ 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 { + return R_ABS; +} + +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; + default: + error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type)); + } +} } }