Index: lld/ELF/Arch/AVR.cpp =================================================================== --- lld/ELF/Arch/AVR.cpp +++ lld/ELF/Arch/AVR.cpp @@ -43,6 +43,7 @@ class AVR final : public TargetInfo { public: AVR(); + uint32_t calcEFlags() const override; RelExpr getRelExpr(RelType type, const Symbol &s, const uint8_t *loc) const override; void relocate(uint8_t *loc, const Relocation &rel, @@ -196,3 +197,30 @@ static AVR target; return ⌖ } + +static uint32_t getEFlags(InputFile *file) { + return cast>(file)->getObj().getHeader().e_flags; +} + +uint32_t AVR::calcEFlags() const { + assert(!objectFiles.empty()); + + uint32_t flags = getEFlags(objectFiles[0]); + bool hasLinkerRelaxFlag = flags & EF_AVR_LINKRELAX_PREPARED; + + for (InputFile *f : makeArrayRef(objectFiles).slice(1)) { + uint32_t objFlags = getEFlags(f); + + if ((objFlags & EF_AVR_ARCH_MASK) != (flags & EF_AVR_ARCH_MASK)) + error(toString(f) + + ": cannot link object files with incompatible target ISA"); + + if (!(objFlags & EF_AVR_LINKRELAX_PREPARED)) + hasLinkerRelaxFlag = false; + } + + if (!hasLinkerRelaxFlag) + flags &= ~EF_AVR_LINKRELAX_PREPARED; + + return flags; +} Index: llvm/include/llvm/BinaryFormat/ELF.h =================================================================== --- llvm/include/llvm/BinaryFormat/ELF.h +++ llvm/include/llvm/BinaryFormat/ELF.h @@ -484,7 +484,12 @@ EF_AVR_ARCH_XMEGA4 = 104, EF_AVR_ARCH_XMEGA5 = 105, EF_AVR_ARCH_XMEGA6 = 106, - EF_AVR_ARCH_XMEGA7 = 107 + EF_AVR_ARCH_XMEGA7 = 107, + + EF_AVR_ARCH_MASK = 0x7f, // EF_AVR_ARCH_xxx selection mask + + EF_AVR_LINKRELAX_PREPARED = 0x80, // The file is prepared for linker + // relaxation to be applied }; // ELF Relocation types for AVR