1
0
mirror of https://github.com/fluencelabs/wasm-bindgen synced 2025-03-31 17:31:06 +00:00

Fix logic for is_enabled in the threads transform ()

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.
This commit is contained in:
Alex Crichton 2019-09-25 11:58:55 -05:00 committed by GitHub
parent f4a7fe3ddb
commit 6f52f2a37c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 14 deletions
crates
cli-support/src
threads-xform/src

@ -283,7 +283,7 @@ impl Bindgen {
// pointer, so temporarily export it so that our many GC's don't remove // pointer, so temporarily export it so that our many GC's don't remove
// it before the xform runs. // it before the xform runs.
let mut exported_shadow_stack_pointer = false; let mut exported_shadow_stack_pointer = false;
if self.multi_value || self.threads.is_enabled() { if self.multi_value || self.threads.is_enabled(&module) {
wasm_conventions::export_shadow_stack_pointer(&mut module)?; wasm_conventions::export_shadow_stack_pointer(&mut module)?;
exported_shadow_stack_pointer = true; exported_shadow_stack_pointer = true;
} }

@ -31,8 +31,21 @@ impl Config {
} }
/// Is threaded Wasm enabled? /// Is threaded Wasm enabled?
pub fn is_enabled(&self) -> bool { pub fn is_enabled(&self, module: &Module) -> bool {
self.enabled if self.enabled {
return true;
}
// Compatibility with older LLVM outputs. Newer LLVM outputs, when
// atomics are enabled, emit a shared memory. That's a good indicator
// that we have work to do. If shared memory isn't enabled, though then
// this isn't an atomic module so there's nothing to do. We still allow,
// though, an environment variable to force us to go down this path to
// remain compatibile with older LLVM outputs.
match wasm_conventions::get_memory(module) {
Ok(memory) => module.memories.get(memory).shared,
Err(_) => false,
}
} }
/// Specify the maximum amount of memory the wasm module can ever have. /// Specify the maximum amount of memory the wasm module can ever have.
@ -87,21 +100,11 @@ impl Config {
/// ///
/// More and/or less may happen here over time, stay tuned! /// More and/or less may happen here over time, stay tuned!
pub fn run(&self, module: &mut Module) -> Result<(), Error> { pub fn run(&self, module: &mut Module) -> Result<(), Error> {
if !self.enabled { if !self.is_enabled(module) {
return Ok(()); return Ok(());
} }
// Compatibility with older LLVM outputs. Newer LLVM outputs, when
// atomics are enabled, emit a shared memory. That's a good indicator
// that we have work to do. If shared memory isn't enabled, though then
// this isn't an atomic module so there's nothing to do. We still allow,
// though, an environment variable to force us to go down this path to
// remain compatibile with older LLVM outputs.
let memory = wasm_conventions::get_memory(module)?; let memory = wasm_conventions::get_memory(module)?;
if !module.memories.get(memory).shared {
return Ok(());
}
let stack_pointer = wasm_conventions::get_shadow_stack_pointer(module)?; let stack_pointer = wasm_conventions::get_shadow_stack_pointer(module)?;
let addr = allocate_static_data(module, memory, 4, 4)?; let addr = allocate_static_data(module, memory, 4, 4)?;
let zero = InitExpr::Value(Value::I32(0)); let zero = InitExpr::Value(Value::I32(0));