Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lld/test/wasm/mutable-global-exports.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion lld/wasm/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down