wasm: Use Export section to initialise Name section

Works even if the preloaded Name section is missing.
This commit is contained in:
Brian Carroll 2022-04-09 09:59:23 +01:00
parent 1dd374a9ab
commit 1e5f659be1
3 changed files with 56 additions and 57 deletions

View file

@ -5,7 +5,7 @@ pub mod opcodes;
pub mod sections;
pub mod serialize;
use bumpalo::Bump;
use bumpalo::{collections::Vec, Bump};
pub use code_builder::{Align, CodeBuilder, LocalId, ValueType, VmSymbolState};
pub use linking::SymInfo;
use roc_error_macros::internal_error;
@ -144,7 +144,7 @@ impl<'a> WasmModule<'a> {
let global = GlobalSection::preload(arena, bytes, &mut cursor);
let export = ExportSection::preload_globals(arena, bytes, &mut cursor);
let export = ExportSection::preload(arena, bytes, &mut cursor);
let start = OpaqueSection::preload(SectionId::Start, arena, bytes, &mut cursor);
@ -190,10 +190,18 @@ impl<'a> WasmModule<'a> {
arena: &'a Bump,
called_preload_fns: T,
) {
let exported_fn_iter = self
.export
.exports
.iter()
.filter(|ex| ex.ty == ExportType::Func)
.map(|ex| ex.index);
let function_indices = Vec::from_iter_in(exported_fn_iter, arena);
self.code.remove_dead_preloads(
arena,
self.import.function_count,
&self.export.function_indices,
&function_indices,
called_preload_fns,
)
}