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(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.