[lld] e925e52 - [lld][WebAssembly] Fix check for implicitly exported mutable globals (#160966)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 26 17:16:49 PDT 2025
Author: Sam Clegg
Date: 2025-09-26T17:16:45-07:00
New Revision: e925e528d9750a424f1a3c8519aae9e0288d13a4
URL: https://github.com/llvm/llvm-project/commit/e925e528d9750a424f1a3c8519aae9e0288d13a4
DIFF: https://github.com/llvm/llvm-project/commit/e925e528d9750a424f1a3c8519aae9e0288d13a4.diff
LOG: [lld][WebAssembly] Fix check for implicitly exported mutable globals (#160966)
This check is designed to avoid exporting mutable globals in the case
when mutable globals are not available. However, it was being applied in
all cases even when mutable globals was enabled.
This error is particularly bad since mutable-globals have been enabled
in default CPU for a while now, meaning that this condition should not
be firing in the wild very often.
Added:
Modified:
lld/test/wasm/mutable-global-exports.s
lld/wasm/Writer.cpp
Removed:
################################################################################
diff --git a/lld/test/wasm/mutable-global-exports.s b/lld/test/wasm/mutable-global-exports.s
index 4ffaf0a6cbaf0..1c10e92083b5c 100644
--- a/lld/test/wasm/mutable-global-exports.s
+++ b/lld/test/wasm/mutable-global-exports.s
@@ -73,6 +73,9 @@ _start:
# CHECK-ALL-NEXT: - Name: __wasm_call_ctors
# CHECK-ALL-NEXT: Kind: FUNCTION
# CHECK-ALL-NEXT: Index: 0
+# CHECK-ALL-NEXT: - Name: __stack_pointer
+# CHECK-ALL-NEXT: Kind: GLOBAL
+# CHECK-ALL-NEXT: Index: 0
# CHECK-ALL-NEXT: - Name: _start
# CHECK-ALL-NEXT: Kind: FUNCTION
# CHECK-ALL-NEXT: Index: 1
diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp
index 0d36893653110..9a5b56fc52e2f 100644
--- a/lld/wasm/Writer.cpp
+++ b/lld/wasm/Writer.cpp
@@ -784,6 +784,9 @@ void Writer::calculateExports() {
unsigned globalIndex =
out.importSec->getNumImportedGlobals() + out.globalSec->numGlobals();
+ bool hasMutableGlobals =
+ out.targetFeaturesSec->features.count("mutable-globals") > 0;
+
for (Symbol *sym : symtab->symbols()) {
if (!sym->isExported())
continue;
@@ -801,7 +804,8 @@ void Writer::calculateExports() {
}
export_ = {name, WASM_EXTERNAL_FUNCTION, f->getExportedFunctionIndex()};
} else if (auto *g = dyn_cast<DefinedGlobal>(sym)) {
- if (g->getGlobalType()->Mutable && !g->getFile() && !g->forceExport) {
+ if (!hasMutableGlobals && g->getGlobalType()->Mutable && !g->getFile() &&
+ !g->isExportedExplicit()) {
// Avoid exporting mutable globals are linker synthesized (e.g.
// __stack_pointer or __tls_base) unless they are explicitly exported
// from the command line.
More information about the llvm-commits
mailing list