[lld] 2482373 - [lld/mac] Extract a reportUndefinedSymbol function
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 3 06:18:12 PDT 2022
Author: Nico Weber
Date: 2022-10-03T09:17:57-04:00
New Revision: 248237364b7df8b3216a9f44ffceeff6807eaa97
URL: https://github.com/llvm/llvm-project/commit/248237364b7df8b3216a9f44ffceeff6807eaa97
DIFF: https://github.com/llvm/llvm-project/commit/248237364b7df8b3216a9f44ffceeff6807eaa97.diff
LOG: [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
Added:
Modified:
lld/MachO/SymbolTable.cpp
Removed:
################################################################################
diff --git a/lld/MachO/SymbolTable.cpp b/lld/MachO/SymbolTable.cpp
index 301692ff583f..5173fa069e22 100644
--- a/lld/MachO/SymbolTable.cpp
+++ b/lld/MachO/SymbolTable.cpp
@@ -392,53 +392,53 @@ void macho::reportPendingDuplicateSymbols() {
}
}
-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();
More information about the llvm-commits
mailing list