[lld] 84a2155 - [lld-macho]Limit "cannot-export-hidden-symbol" warnings to only 3 to avoid crowding logs.
Vy Nguyen via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 7 10:51:54 PDT 2023
Author: Vy Nguyen
Date: 2023-09-07T13:50:55-04:00
New Revision: 84a215592121fc8a80ea3aaab47a2914f50b55b4
URL: https://github.com/llvm/llvm-project/commit/84a215592121fc8a80ea3aaab47a2914f50b55b4
DIFF: https://github.com/llvm/llvm-project/commit/84a215592121fc8a80ea3aaab47a2914f50b55b4.diff
LOG: [lld-macho]Limit "cannot-export-hidden-symbol" warnings to only 3 to avoid crowding logs.
Details:
We often use wildcard symbols in the exported_symbols list, and sometimes they match autohide symbols, which triggers these "cannot export hidden symbols" warnings that can be a bit noisy.
It'd be more user-friendly if LLD could truncate these.
Differential Revision: https://reviews.llvm.org/D159095
Added:
Modified:
lld/MachO/Driver.cpp
lld/test/MachO/export-options.s
Removed:
################################################################################
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index e175b59e159f27..2ef170254c2ec4 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -1355,8 +1355,10 @@ static void createAliases() {
}
static void handleExplicitExports() {
+ static constexpr int kMaxWarnings = 3;
if (config->hasExplicitExports) {
- parallelForEach(symtab->getSymbols(), [](Symbol *sym) {
+ std::atomic<uint64_t> warningsCount{0};
+ parallelForEach(symtab->getSymbols(), [&warningsCount](Symbol *sym) {
if (auto *defined = dyn_cast<Defined>(sym)) {
if (config->exportedSymbols.match(sym->getName())) {
if (defined->privateExtern) {
@@ -1367,8 +1369,12 @@ static void handleExplicitExports() {
// The former can be exported but the latter cannot.
defined->privateExtern = false;
} else {
- warn("cannot export hidden symbol " + toString(*defined) +
- "\n>>> defined in " + toString(defined->getFile()));
+ // Only print the first 3 warnings verbosely, and
+ // shorten the rest to avoid crowding logs.
+ if (warningsCount.fetch_add(1, std::memory_order_relaxed) <
+ kMaxWarnings)
+ warn("cannot export hidden symbol " + toString(*defined) +
+ "\n>>> defined in " + toString(defined->getFile()));
}
}
} else {
@@ -1378,6 +1384,9 @@ static void handleExplicitExports() {
dysym->shouldReexport = config->exportedSymbols.match(sym->getName());
}
});
+ if (warningsCount > kMaxWarnings)
+ warn("<... " + Twine(warningsCount - kMaxWarnings) +
+ " more similar warnings...>");
} else if (!config->unexportedSymbols.empty()) {
parallelForEach(symtab->getSymbols(), [](Symbol *sym) {
if (auto *defined = dyn_cast<Defined>(sym))
diff --git a/lld/test/MachO/export-options.s b/lld/test/MachO/export-options.s
index 3a63afc6d5a3d0..1a5d409e83383a 100644
--- a/lld/test/MachO/export-options.s
+++ b/lld/test/MachO/export-options.s
@@ -4,6 +4,7 @@
# RUN: echo "" | llvm-mc -filetype=obj -triple=x86_64-apple-macos -o %t/empty.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos %t/default.s -o %t/default.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos %t/lazydef.s -o %t/lazydef.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos %t/too-many-warnings.s -o %t/too-many-warnings.o
# RUN: llvm-ar --format=darwin rcs %t/lazydef.a %t/lazydef.o
## Check that mixing exported and unexported symbol options yields an error
@@ -209,6 +210,17 @@
# RUN: llvm-objdump --macho --exports-trie %t/unexport-dylib | FileCheck %s \
# RUN: --check-prefix=EMPTY-TRIE
+## Check that warnings are truncated to the first 3 only.
+# RUN: %no-fatal-warnings-lld -dylib %t/too-many-warnings.o -o %t/too-many.out \
+# RUN: -exported_symbol "_private_extern*" 2>&1 | \
+# RUN: FileCheck --check-prefix=TRUNCATE %s
+
+# TRUNCATE: warning: cannot export hidden symbol _private_extern{{.+}}
+# TRUNCATE: warning: cannot export hidden symbol _private_extern{{.+}}
+# TRUNCATE: warning: cannot export hidden symbol _private_extern{{.+}}
+# TRUNCATE: warning: <... 7 more similar warnings...>
+# TRUNCATE-EMPTY:
+
#--- default.s
.globl _keep_globl, _hide_globl, _tlv
@@ -283,3 +295,45 @@ _foo:
.private_extern _foo
_foo:
retq
+
+#--- too-many-warnings.s
+.private_extern _private_extern1
+.private_extern _private_extern2
+.private_extern _private_extern3
+.private_extern _private_extern4
+.private_extern _private_extern5
+.private_extern _private_extern6
+.private_extern _private_extern7
+.private_extern _private_extern8
+.private_extern _private_extern9
+.private_extern _private_extern10
+
+_private_extern1:
+ retq
+
+_private_extern2:
+ retq
+
+_private_extern3:
+ retq
+
+_private_extern4:
+ retq
+
+_private_extern5:
+ retq
+
+_private_extern6:
+ retq
+
+_private_extern7:
+ retq
+
+_private_extern8:
+ retq
+
+_private_extern9:
+ retq
+
+_private_extern10:
+ retq
More information about the llvm-commits
mailing list