Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Always emit code assuming the GC heap base might be relocated (#13165)

Nick Fitzgerald939f3d08de2c
diff --git a/crates/environ/src/tunables.rs b/crates/environ/src/tunables.rs
index e235b0cf9b..9bfeccc942 100644
--- a/crates/environ/src/tunables.rs
+++ b/crates/environ/src/tunables.rs
@@ -392,7 +392,13 @@ impl<'a> MemoryTunables<'a> {
pub fn may_move(&self) -> bool {
match self.kind {
MemoryKind::LinearMemory => self.tunables.memory_may_move,
- MemoryKind::GcHeap => self.tunables.gc_heap_may_move,
+ MemoryKind::GcHeap => {
+ // XXX: Lazy GC heap allocation means that the GC heap's base
+ // may always "move" in that it is initially null and then gets
+ // initialized after being lazily allocated.
+ let _ = self.tunables.gc_heap_may_move;
+ true
+ }
}
}
diff --git a/tests/all/gc.rs b/tests/all/gc.rs
index 7e27a6915b..0f7d3e2f87 100644
--- a/tests/all/gc.rs
+++ b/tests/all/gc.rs
@@ -1777,6 +1777,38 @@ fn pooling_gc_different_configs_rejected() -> Result<()> {
Ok(())
}
+#[test]
+#[cfg_attr(miri, ignore)]
+fn issue_13141_gc_heap_may_not_move() -> Result<()> {
+ let mut config = Config::new();
+ config.wasm_gc(true);
+ config.gc_heap_may_move(false);
+ config.gc_heap_reservation(0);
+ let engine = Engine::new(&config)?;
+
+ let module = Module::new(
+ &engine,
+ r#"
+ (module
+ (type $a (array (mut i8)))
+
+ (global $g (mut (ref $a)) (array.new_default $a (i32.const 12)))
+
+ (func (export "array_get_nth") (param $p i32) (result i32)
+ (array.get_u $a (global.get $g) (local.get $p))
+ )
+ )
+ "#,
+ )?;
+
+ let mut store = Store::new(&engine, ());
+ let instance = Instance::new(&mut store, &module, &[])?;
+ let array_get_nth = instance.get_typed_func::<i32, i32>(&mut store, "array_get_nth")?;
+ let result = array_get_nth.call(&mut store, 0)?;
+ assert_eq!(result, 0);
+ Ok(())
+}
+
#[test]
#[cfg_attr(miri, ignore)]
fn memory_guard_pages_but_no_gc_heap_guard_pages() -> Result<()> {
diff --git a/tests/misc_testsuite/gc/issue-13134.wast b/tests/misc_testsuite/gc/issue-13134.wast
new file mode 100644
index 0000000000..d702562dd9
--- /dev/null
+++ b/tests/misc_testsuite/gc/issue-13134.wast
@@ -0,0 +1,13 @@
+;;! gc = true
+
+(module
+ (type $a (array (mut i8)))
+
+ (global $g (mut (ref $a)) (array.new_default $a (i32.const 12)))
+
+ (func (export "array_get_nth") (param $p i32) (result i32)
+ (array.get_u $a (global.get $g) (local.get $p))
+ )
+)
+
+(assert_return (invoke "array_get_nth" (i32.const 0)) (i32.const 0))