Skip to content

Commit c9ee88b

Browse files
committed
Preserve the function table during early gc passes
Recent refactorings of wasm-bindgen have inserted multiple `gc` passes executed by walrus. In these passes though the function table was being removed a bit too aggressively because it's not exported by LLD and it's only later that we realize we need to export it. To handle this case we add synthetic and temporary exports of the function table and these exports are removed just after the GC pass in question. Closes #1603
1 parent 8d90655 commit c9ee88b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

crates/cli-support/src/descriptors.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,24 @@ pub fn execute(module: &mut Module) -> Result<WasmBindgenDescriptorsSectionId, E
4040

4141
// Delete all descriptor functions and imports from the module now that
4242
// we've executed all of them.
43+
//
44+
// Note though that during this GC pass it's a bit aggressive in that it can
45+
// delete the function table entirely. We don't actually know at this point
46+
// whether we need the function table or not. The bindings generation may
47+
// need to export the table so the JS glue can call functions in it, and
48+
// that's only discovered during binding selection. For now we just add
49+
// synthetic root exports for all tables in the module, and then we delete
50+
// the exports just after GC. This should keep tables like the function
51+
// table alive during GC all the way through to the bindings generation
52+
// where we can either actually export it or gc it out since it's not used.
53+
let mut exported_tables = Vec::new();
54+
for table in module.tables.iter() {
55+
exported_tables.push(module.exports.add("foo", table.id()));
56+
}
4357
walrus::passes::gc::run(module);
58+
for export in exported_tables {
59+
module.exports.delete(export);
60+
}
4461

4562
Ok(module.customs.add(section))
4663
}

0 commit comments

Comments
 (0)