Index: lld/MachO/SymbolTable.cpp =================================================================== --- lld/MachO/SymbolTable.cpp +++ lld/MachO/SymbolTable.cpp @@ -392,53 +392,53 @@ } } -void macho::reportPendingUndefinedSymbols() { - for (const auto &undef : undefs) { - const UndefinedDiag &locations = undef.second; - - std::string message = "undefined symbol"; - if (config->archMultiple) - message += (" for arch " + getArchitectureName(config->arch())).str(); - message += ": " + toString(*undef.first); - - const size_t maxUndefinedReferences = 3; - size_t i = 0; - for (const std::string &loc : locations.otherReferences) { - if (i >= maxUndefinedReferences) - break; - message += "\n>>> referenced by " + loc; - ++i; - } - - for (const UndefinedDiag::SectionAndOffset &loc : - locations.codeReferences) { - if (i >= maxUndefinedReferences) - break; - message += "\n>>> referenced by "; - std::string src = loc.isec->getSourceLocation(loc.offset); - if (!src.empty()) - message += src + "\n>>> "; - message += loc.isec->getLocation(loc.offset); - ++i; - } +static void reportUndefinedSymbol(const Undefined &sym, + const UndefinedDiag &locations) { + std::string message = "undefined symbol"; + if (config->archMultiple) + message += (" for arch " + getArchitectureName(config->arch())).str(); + message += ": " + toString(sym); + + const size_t maxUndefinedReferences = 3; + size_t i = 0; + for (const std::string &loc : locations.otherReferences) { + if (i >= maxUndefinedReferences) + break; + message += "\n>>> referenced by " + loc; + ++i; + } - size_t totalReferences = - locations.otherReferences.size() + locations.codeReferences.size(); - if (totalReferences > i) - message += - ("\n>>> referenced " + Twine(totalReferences - i) + " more times") - .str(); - - if (config->undefinedSymbolTreatment == UndefinedSymbolTreatment::error) - error(message); - else if (config->undefinedSymbolTreatment == - UndefinedSymbolTreatment::warning) - warn(message); - else - assert(false && - "diagnostics make sense for -undefined error|warning only"); + for (const UndefinedDiag::SectionAndOffset &loc : locations.codeReferences) { + if (i >= maxUndefinedReferences) + break; + message += "\n>>> referenced by "; + std::string src = loc.isec->getSourceLocation(loc.offset); + if (!src.empty()) + message += src + "\n>>> "; + message += loc.isec->getLocation(loc.offset); + ++i; } + size_t totalReferences = + locations.otherReferences.size() + locations.codeReferences.size(); + if (totalReferences > i) + message += + ("\n>>> referenced " + Twine(totalReferences - i) + " more times") + .str(); + + if (config->undefinedSymbolTreatment == UndefinedSymbolTreatment::error) + error(message); + else if (config->undefinedSymbolTreatment == + UndefinedSymbolTreatment::warning) + warn(message); + else + assert(false && "diagnostics make sense for -undefined error|warning only"); +} + +void macho::reportPendingUndefinedSymbols() { + for (const auto &undef : undefs) + reportUndefinedSymbol(*undef.first, undef.second); + // This function is called multiple times during execution. Clear the printed // diagnostics to avoid printing the same things again the next time. undefs.clear();