forked from OSchip/llvm-project
[lld/mac] Extract a reportUndefinedSymbol function
Makes things look more similar to the ELF port, and removes some slightly deep nesting. No behavior change. Differential Revision: https://reviews.llvm.org/D135032
This commit is contained in:
parent
8291fa0817
commit
248237364b
|
@ -392,53 +392,53 @@ void macho::reportPendingDuplicateSymbols() {
|
|||
}
|
||||
}
|
||||
|
||||
void macho::reportPendingUndefinedSymbols() {
|
||||
for (const auto &undef : undefs) {
|
||||
const UndefinedDiag &locations = undef.second;
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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");
|
||||
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;
|
||||
}
|
||||
|
||||
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();
|
||||
|
|
Loading…
Reference in New Issue