diff options
-rw-r--r-- | src/wasm/wasm-validator.cpp | 15 | ||||
-rw-r--r-- | test/export-import.wast | 8 | ||||
-rw-r--r-- | test/export-import.wast.from-wast | 9 | ||||
-rw-r--r-- | test/export-import.wast.fromBinary | 10 | ||||
-rw-r--r-- | test/export-import.wast.fromBinary.noDebugInfo | 10 |
5 files changed, 43 insertions, 9 deletions
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index ef70cc9e7..df88a5f32 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -926,16 +926,13 @@ static void validateExports(Module& module, ValidationInfo& info) { for (auto& exp : module.exports) { Name name = exp->value; if (exp->kind == ExternalKind::Function) { - bool found = false; - for (auto& func : module.functions) { - if (func->name == name) { - found = true; - break; - } - } - info.shouldBeTrue(found, name, "module function exports must be found"); + Import* imp; + info.shouldBeTrue(module.getFunctionOrNull(name) || + ((imp = module.getImportOrNull(name)) && imp->kind == ExternalKind::Function), name, "module function exports must be found"); } else if (exp->kind == ExternalKind::Global) { - info.shouldBeTrue(module.getGlobalOrNull(name), name, "module global exports must be found"); + Import* imp; + info.shouldBeTrue(module.getGlobalOrNull(name) || + ((imp = module.getImportOrNull(name)) && imp->kind == ExternalKind::Global), name, "module global exports must be found"); } else if (exp->kind == ExternalKind::Table) { info.shouldBeTrue(name == Name("0") || name == module.table.name, name, "module table exports must be found"); } else if (exp->kind == ExternalKind::Memory) { diff --git a/test/export-import.wast b/test/export-import.wast new file mode 100644 index 000000000..5dc2185c6 --- /dev/null +++ b/test/export-import.wast @@ -0,0 +1,8 @@ +(module + (type $v (func)) + (import "env" "test1" (func $test1)) + (import "env" "test2" (global $test2 i32)) + (export "test1" (func $test1)) + (export "test2" (global $test2)) +) + diff --git a/test/export-import.wast.from-wast b/test/export-import.wast.from-wast new file mode 100644 index 000000000..3675ae243 --- /dev/null +++ b/test/export-import.wast.from-wast @@ -0,0 +1,9 @@ +(module + (type $v (func)) + (type $FUNCSIG$v (func)) + (import "env" "test1" (func $test1)) + (import "env" "test2" (global $test2 i32)) + (memory $0 0) + (export "test1" (func $test1)) + (export "test2" (global $test2)) +) diff --git a/test/export-import.wast.fromBinary b/test/export-import.wast.fromBinary new file mode 100644 index 000000000..468498a94 --- /dev/null +++ b/test/export-import.wast.fromBinary @@ -0,0 +1,10 @@ +(module + (type $0 (func)) + (type $1 (func)) + (import "env" "test2" (global $import$1 i32)) + (import "env" "test1" (func $test1)) + (memory $0 0) + (export "test1" (func $test1)) + (export "test2" (global $import$1)) +) + diff --git a/test/export-import.wast.fromBinary.noDebugInfo b/test/export-import.wast.fromBinary.noDebugInfo new file mode 100644 index 000000000..562a51cc6 --- /dev/null +++ b/test/export-import.wast.fromBinary.noDebugInfo @@ -0,0 +1,10 @@ +(module + (type $0 (func)) + (type $1 (func)) + (import "env" "test2" (global $import$1 i32)) + (import "env" "test1" (func $import$0)) + (memory $0 0) + (export "test1" (func $import$0)) + (export "test2" (global $import$1)) +) + |