-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[lld][WebAssembly] Fix check for exporting mutable globals #160787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
We were not actually checking whether the global in question was actually mutable before reporting the error.
|
@llvm/pr-subscribers-lld-wasm Author: Sam Clegg (sbc100) ChangesWe were not actually checking whether the global in question was actually mutable before reporting the error. Full diff: https://github.com/llvm/llvm-project/pull/160787.diff 2 Files Affected:
diff --git a/lld/test/wasm/mutable-global-exports.s b/lld/test/wasm/mutable-global-exports.s
index 59308496ab4cc..4ffaf0a6cbaf0 100644
--- a/lld/test/wasm/mutable-global-exports.s
+++ b/lld/test/wasm/mutable-global-exports.s
@@ -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:
@@ -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:
@@ -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
diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp
index b704677d36c93..0d36893653110 100644
--- a/lld/wasm/Writer.cpp
+++ b/lld/wasm/Writer.cpp
@@ -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");
}
@@ -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.");
+ }
}
}
}
|
|
@llvm/pr-subscribers-lld Author: Sam Clegg (sbc100) ChangesWe were not actually checking whether the global in question was actually mutable before reporting the error. Full diff: https://github.com/llvm/llvm-project/pull/160787.diff 2 Files Affected:
diff --git a/lld/test/wasm/mutable-global-exports.s b/lld/test/wasm/mutable-global-exports.s
index 59308496ab4cc..4ffaf0a6cbaf0 100644
--- a/lld/test/wasm/mutable-global-exports.s
+++ b/lld/test/wasm/mutable-global-exports.s
@@ -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:
@@ -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:
@@ -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
diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp
index b704677d36c93..0d36893653110 100644
--- a/lld/wasm/Writer.cpp
+++ b/lld/wasm/Writer.cpp
@@ -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");
}
@@ -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.");
+ }
}
}
}
|
We were not actually checking whether the global in question was actually mutable before reporting the error.
We were not actually checking whether the global in question was actually mutable before reporting the error.