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
28 changes: 18 additions & 10 deletions lld/test/wasm/mutable-global-exports.s
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

.globl _start
.globl foo_global
.globl bar_global

.globaltype bar_global, i32, immutable
bar_global:

.globaltype foo_global, i32
foo_global:
Expand All @@ -33,6 +37,7 @@ _start:
.ascii "atomics"

# CHECK-ERR: mutable global exported but 'mutable-globals' feature not present in inputs: `foo_global`. Use --no-check-features to suppress
# CHECK-ERR-NOT: bar_global

# CHECK: - Type: EXPORT
# CHECK-NEXT: Exports:
Expand Down Expand Up @@ -74,36 +79,39 @@ _start:
# CHECK-ALL-NEXT: - Name: foo_global
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 1
# CHECK-ALL-NEXT: - Name: __dso_handle
# CHECK-ALL-NEXT: - Name: bar_global
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 2
# CHECK-ALL-NEXT: - Name: __data_end
# CHECK-ALL-NEXT: - Name: __dso_handle
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 3
# CHECK-ALL-NEXT: - Name: __stack_low
# CHECK-ALL-NEXT: - Name: __data_end
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 4
# CHECK-ALL-NEXT: - Name: __stack_high
# CHECK-ALL-NEXT: - Name: __stack_low
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 5
# CHECK-ALL-NEXT: - Name: __global_base
# CHECK-ALL-NEXT: - Name: __stack_high
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 6
# CHECK-ALL-NEXT: - Name: __heap_base
# CHECK-ALL-NEXT: - Name: __global_base
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 7
# CHECK-ALL-NEXT: - Name: __heap_end
# CHECK-ALL-NEXT: - Name: __heap_base
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 8
# CHECK-ALL-NEXT: - Name: __memory_base
# CHECK-ALL-NEXT: - Name: __heap_end
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 9
# CHECK-ALL-NEXT: - Name: __table_base
# CHECK-ALL-NEXT: - Name: __memory_base
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 10
# CHECK-ALL-NEXT: - Name: __wasm_first_page_end
# CHECK-ALL-NEXT: - Name: __table_base
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 11
# CHECK-ALL-NEXT: - Name: __wasm_first_page_end
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 12
# CHECK-ALL-NEXT: - Type: CODE

# CHECK-ALL: Name: target_features
Expand Down
12 changes: 7 additions & 5 deletions lld/wasm/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ void Writer::populateTargetFeatures() {

if (ctx.isPic) {
// This should not be necessary because all PIC objects should
// contain the mutable-globals feature.
// contain the `mutable-globals` feature.
// TODO (https://github.com/llvm/llvm-project/issues/51681)
allowed.insert("mutable-globals");
}
Expand Down Expand Up @@ -703,10 +703,12 @@ void Writer::checkImportExportTargetFeatures() {
}
}
for (const Symbol *sym : out.exportSec->exportedSymbols) {
if (isa<GlobalSymbol>(sym)) {
error(Twine("mutable global exported but 'mutable-globals' feature "
"not present in inputs: `") +
toString(*sym) + "`. Use --no-check-features to suppress.");
if (auto *global = dyn_cast<GlobalSymbol>(sym)) {
if (global->getGlobalType()->Mutable) {
error(Twine("mutable global exported but 'mutable-globals' feature "
"not present in inputs: `") +
toString(*sym) + "`. Use --no-check-features to suppress.");
}
}
}
}
Expand Down