Skip to content

Commit 6f52f2a

Browse files
authored
Fix logic for is_enabled in the threads transform (#1791)
The threads transform is implicitly enabled nowadays when the memory looks like it's shared, so ensure that's taken into account in the `is_enabled` check.
1 parent f4a7fe3 commit 6f52f2a

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

crates/cli-support/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ impl Bindgen {
283283
// pointer, so temporarily export it so that our many GC's don't remove
284284
// it before the xform runs.
285285
let mut exported_shadow_stack_pointer = false;
286-
if self.multi_value || self.threads.is_enabled() {
286+
if self.multi_value || self.threads.is_enabled(&module) {
287287
wasm_conventions::export_shadow_stack_pointer(&mut module)?;
288288
exported_shadow_stack_pointer = true;
289289
}

crates/threads-xform/src/lib.rs

+16-13
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,21 @@ impl Config {
3131
}
3232

3333
/// Is threaded Wasm enabled?
34-
pub fn is_enabled(&self) -> bool {
35-
self.enabled
34+
pub fn is_enabled(&self, module: &Module) -> bool {
35+
if self.enabled {
36+
return true;
37+
}
38+
39+
// Compatibility with older LLVM outputs. Newer LLVM outputs, when
40+
// atomics are enabled, emit a shared memory. That's a good indicator
41+
// that we have work to do. If shared memory isn't enabled, though then
42+
// this isn't an atomic module so there's nothing to do. We still allow,
43+
// though, an environment variable to force us to go down this path to
44+
// remain compatibile with older LLVM outputs.
45+
match wasm_conventions::get_memory(module) {
46+
Ok(memory) => module.memories.get(memory).shared,
47+
Err(_) => false,
48+
}
3649
}
3750

3851
/// Specify the maximum amount of memory the wasm module can ever have.
@@ -87,21 +100,11 @@ impl Config {
87100
///
88101
/// More and/or less may happen here over time, stay tuned!
89102
pub fn run(&self, module: &mut Module) -> Result<(), Error> {
90-
if !self.enabled {
103+
if !self.is_enabled(module) {
91104
return Ok(());
92105
}
93106

94-
// Compatibility with older LLVM outputs. Newer LLVM outputs, when
95-
// atomics are enabled, emit a shared memory. That's a good indicator
96-
// that we have work to do. If shared memory isn't enabled, though then
97-
// this isn't an atomic module so there's nothing to do. We still allow,
98-
// though, an environment variable to force us to go down this path to
99-
// remain compatibile with older LLVM outputs.
100107
let memory = wasm_conventions::get_memory(module)?;
101-
if !module.memories.get(memory).shared {
102-
return Ok(());
103-
}
104-
105108
let stack_pointer = wasm_conventions::get_shadow_stack_pointer(module)?;
106109
let addr = allocate_static_data(module, memory, 4, 4)?;
107110
let zero = InitExpr::Value(Value::I32(0));

0 commit comments

Comments
 (0)