Skip to content

Commit

Permalink
fix: mark exported only functions that were exported from Wasm core m…
Browse files Browse the repository at this point in the history
…odule

Close #351
  • Loading branch information
greenhat committed Nov 20, 2024
1 parent 9c4c9b3 commit c8572ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion frontend-wasm/src/module/build_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ pub fn build_ir_module(
let func_name = &parsed_module.module.func_name(*func_index);
let wasm_func_type = module_types[func_type.signature].clone();
let ir_func_type = ir_func_type(&wasm_func_type, &session.diagnostics)?;
let sig = ir_func_sig(&ir_func_type, CallConv::SystemV, Linkage::External);
let linkage = if parsed_module.module.is_exported_function(func_index) {
Linkage::External
} else {
Linkage::Internal
};
let sig = ir_func_sig(&ir_func_type, CallConv::SystemV, linkage);
let mut module_func_builder = module_builder.function(func_name.as_str(), sig.clone())?;
let FunctionBodyData { validator, body } = body_data;
let mut func_validator = validator.into_validator(Default::default());
Expand Down
7 changes: 7 additions & 0 deletions frontend-wasm/src/module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ impl Module {
index.index() < self.num_imported_funcs
}

pub fn is_exported_function(&self, index: &FuncIndex) -> bool {
self.exports.values().any(|export| match export {
EntityIndex::Function(func_id) => func_id == index,
_ => false,
})
}

/// Convert a `DefinedTableIndex` into a `TableIndex`.
#[inline]
pub fn table_index(&self, defined_table: DefinedTableIndex) -> TableIndex {
Expand Down

0 comments on commit c8572ab

Please sign in to comment.