From c8572ab50fe56cb899164ae1d23e6c6a0c5a1c83 Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Thu, 14 Nov 2024 14:59:08 +0200 Subject: [PATCH] fix: mark exported only functions that were exported from Wasm core module Close #351 --- frontend-wasm/src/module/build_ir.rs | 7 ++++++- frontend-wasm/src/module/mod.rs | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/frontend-wasm/src/module/build_ir.rs b/frontend-wasm/src/module/build_ir.rs index 2a7da134c..7aeea9701 100644 --- a/frontend-wasm/src/module/build_ir.rs +++ b/frontend-wasm/src/module/build_ir.rs @@ -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()); diff --git a/frontend-wasm/src/module/mod.rs b/frontend-wasm/src/module/mod.rs index 58952595c..d55ec5895 100644 --- a/frontend-wasm/src/module/mod.rs +++ b/frontend-wasm/src/module/mod.rs @@ -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 {