Index: llvm/lib/ExecutionEngine/Orc/Core.cpp =================================================================== --- llvm/lib/ExecutionEngine/Orc/Core.cpp +++ llvm/lib/ExecutionEngine/Orc/Core.cpp @@ -374,13 +374,20 @@ #ifndef NDEBUG for (auto &KV : Symbols) { auto I = SymbolFlags.find(KV.first); - assert(I != SymbolFlags.end() && - "Resolving symbol outside this responsibility set"); + + // Certain file formats like COFF add symbols to the symbol table + // that don't exist in the IR. Therefore, we just ignore it if + // there are extra symbols. + if (I == SymbolFlags.end()) + continue; + + // Mask out Exported for compatibility with COFF. + constexpr auto Mask = ~JITSymbolFlags::Exported; if (I->second.isWeak()) - assert(I->second == (KV.second.getFlags() | JITSymbolFlags::Weak) && + assert((I->second & Mask) == ((KV.second.getFlags() | JITSymbolFlags::Weak) & Mask) && "Resolving symbol with incorrect flags"); else - assert(I->second == KV.second.getFlags() && + assert((I->second & Mask) == (KV.second.getFlags() & Mask) && "Resolving symbol with incorrect flags"); } #endif @@ -864,19 +871,31 @@ auto I = Symbols.find(Name); - assert(I != Symbols.end() && "Symbol not found"); + // Certain file formats like COFF add symbols to the symbol table + // that don't exist in the IR. Therefore, we just ignore it if + // there are extra symbols. + if (I == Symbols.end()) + continue; + assert(!I->second.hasMaterializerAttached() && "Resolving symbol with materializer attached?"); assert(I->second.getState() == SymbolState::Materializing && "Symbol should be materializing"); assert(I->second.getAddress() == 0 && "Symbol has already been resolved"); - assert((Sym.getFlags() & ~JITSymbolFlags::Weak) == - (I->second.getFlags() & ~JITSymbolFlags::Weak) && + // Mask out Exported for compatibility with COFF. + constexpr auto Mask = ~(JITSymbolFlags::Weak | JITSymbolFlags::Exported); + assert((Sym.getFlags() & Mask) == + (I->second.getFlags() & Mask) && "Resolved flags should match the declared flags"); // Once resolved, symbols can never be weak. - JITSymbolFlags ResolvedFlags = Sym.getFlags(); + // IMPORTANT: We use I->second.getFlags() because we want + // to reuse the flags from the original IR. Some + // object file formats like COFF don't have an + // exported flag, for example, so we want to preserve + // IR flags. + JITSymbolFlags ResolvedFlags = I->second.getFlags(); ResolvedFlags &= ~JITSymbolFlags::Weak; I->second.setAddress(Sym.getAddress()); I->second.setFlags(ResolvedFlags);