diff options
-rw-r--r-- | src/wasm/wasm-binary.cpp | 8 | ||||
-rw-r--r-- | test/dylib.wasm.fromBinary | 14 | ||||
-rw-r--r-- | test/export-import.wast.fromBinary | 4 | ||||
-rw-r--r-- | test/export-import.wast.fromBinary.noDebugInfo | 8 | ||||
-rw-r--r-- | test/fib-dbg.wasm.fromBinary | 40 | ||||
-rw-r--r-- | test/merge/dylib.wasm.combined | 16 | ||||
-rw-r--r-- | test/merge/dylib.wasm.combined.finalized | 8 | ||||
-rw-r--r-- | test/merge/dylib.wasm.combined.opt | 14 | ||||
-rw-r--r-- | test/unit.wast.fromBinary.noDebugInfo | 10 |
9 files changed, 64 insertions, 58 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 0fed49729..56b35b712 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -1627,12 +1627,15 @@ void WasmBinaryBuilder::readImports() { for (size_t i = 0; i < num; i++) { if (debug) std::cerr << "read one" << std::endl; auto curr = new Import; - curr->name = Name(std::string("import$") + std::to_string(i)); curr->module = getInlineString(); curr->base = getInlineString(); curr->kind = (ExternalKind)getU32LEB(); + // We set a unique prefix for the name based on the kind. This ensures no collisions + // between them, which can't occur here (due to the index i) but could occur later + // due to the names section. switch (curr->kind) { case ExternalKind::Function: { + curr->name = Name(std::string("fimport$") + std::to_string(i)); auto index = getU32LEB(); if (index >= wasm.functionTypes.size()) { throw ParseException("invalid function index " + std::to_string(index) + " / " + std::to_string(wasm.functionTypes.size())); @@ -1644,6 +1647,7 @@ void WasmBinaryBuilder::readImports() { break; } case ExternalKind::Table: { + curr->name = Name(std::string("timport$") + std::to_string(i)); auto elementType = getS32LEB(); WASM_UNUSED(elementType); if (elementType != BinaryConsts::EncodedType::AnyFunc) throw ParseException("Imported table type is not AnyFunc"); @@ -1655,12 +1659,14 @@ void WasmBinaryBuilder::readImports() { break; } case ExternalKind::Memory: { + curr->name = Name(std::string("mimport$") + std::to_string(i)); wasm.memory.exists = true; wasm.memory.imported = true; getResizableLimits(wasm.memory.initial, wasm.memory.max, wasm.memory.shared, Memory::kMaxSize); break; } case ExternalKind::Global: { + curr->name = Name(std::string("gimport$") + std::to_string(i)); curr->globalType = getType(); auto globalMutable = getU32LEB(); // TODO: actually use the globalMutable flag. Currently mutable global diff --git a/test/dylib.wasm.fromBinary b/test/dylib.wasm.fromBinary index aae9b0372..37dcab84f 100644 --- a/test/dylib.wasm.fromBinary +++ b/test/dylib.wasm.fromBinary @@ -2,15 +2,15 @@ (type $0 (func (param i32) (result i32))) (type $1 (func (result i32))) (type $2 (func)) - (import "env" "memoryBase" (global $import$0 i32)) + (import "env" "memoryBase" (global $gimport$0 i32)) (import "env" "memory" (memory $0 256)) (import "env" "table" (table 0 anyfunc)) - (import "env" "tableBase" (global $import$4 i32)) - (import "env" "_puts" (func $import$1 (param i32) (result i32))) + (import "env" "tableBase" (global $gimport$4 i32)) + (import "env" "_puts" (func $fimport$1 (param i32) (result i32))) (global $global$0 (mut i32) (i32.const 0)) (global $global$1 (mut i32) (i32.const 0)) (global $global$2 i32 (i32.const 0)) - (data (get_global $import$0) "hello, world!") + (data (get_global $gimport$0) "hello, world!") (export "__post_instantiate" (func $2)) (export "_main" (func $0)) (export "runPostSets" (func $1)) @@ -18,8 +18,8 @@ (func $0 (; 1 ;) (type $1) (result i32) (block $label$1 (result i32) (drop - (call $import$1 - (get_global $import$0) + (call $fimport$1 + (get_global $gimport$0) ) ) (i32.const 0) @@ -32,7 +32,7 @@ (block $label$1 (set_global $global$0 (i32.add - (get_global $import$0) + (get_global $gimport$0) (i32.const 16) ) ) diff --git a/test/export-import.wast.fromBinary b/test/export-import.wast.fromBinary index f35d385f1..492a05273 100644 --- a/test/export-import.wast.fromBinary +++ b/test/export-import.wast.fromBinary @@ -1,9 +1,9 @@ (module (type $0 (func)) (type $1 (func)) - (import "env" "test2" (global $import$1 i32)) + (import "env" "test2" (global $gimport$1 i32)) (import "env" "test1" (func $test1)) (export "test1" (func $test1)) - (export "test2" (global $import$1)) + (export "test2" (global $gimport$1)) ) diff --git a/test/export-import.wast.fromBinary.noDebugInfo b/test/export-import.wast.fromBinary.noDebugInfo index b9c712134..3064e637d 100644 --- a/test/export-import.wast.fromBinary.noDebugInfo +++ b/test/export-import.wast.fromBinary.noDebugInfo @@ -1,9 +1,9 @@ (module (type $0 (func)) (type $1 (func)) - (import "env" "test2" (global $import$1 i32)) - (import "env" "test1" (func $import$0)) - (export "test1" (func $import$0)) - (export "test2" (global $import$1)) + (import "env" "test2" (global $gimport$1 i32)) + (import "env" "test1" (func $fimport$0)) + (export "test1" (func $fimport$0)) + (export "test2" (global $gimport$1)) ) diff --git a/test/fib-dbg.wasm.fromBinary b/test/fib-dbg.wasm.fromBinary index cd431a054..dec09980e 100644 --- a/test/fib-dbg.wasm.fromBinary +++ b/test/fib-dbg.wasm.fromBinary @@ -4,32 +4,32 @@ (type $2 (func (result i32))) (type $3 (func (param i32))) (type $4 (func)) - (import "env" "DYNAMICTOP_PTR" (global $import$0 i32)) - (import "env" "tempDoublePtr" (global $import$1 i32)) - (import "env" "ABORT" (global $import$2 i32)) - (import "env" "STACKTOP" (global $import$3 i32)) - (import "env" "STACK_MAX" (global $import$4 i32)) - (import "env" "gb" (global $import$5 i32)) - (import "env" "fb" (global $import$6 i32)) - (import "global" "NaN" (global $import$7 f64)) - (import "global" "Infinity" (global $import$8 f64)) + (import "env" "DYNAMICTOP_PTR" (global $gimport$0 i32)) + (import "env" "tempDoublePtr" (global $gimport$1 i32)) + (import "env" "ABORT" (global $gimport$2 i32)) + (import "env" "STACKTOP" (global $gimport$3 i32)) + (import "env" "STACK_MAX" (global $gimport$4 i32)) + (import "env" "gb" (global $gimport$5 i32)) + (import "env" "fb" (global $gimport$6 i32)) + (import "global" "NaN" (global $gimport$7 f64)) + (import "global" "Infinity" (global $gimport$8 f64)) (import "env" "memory" (memory $0 256 256)) (import "env" "table" (table 0 0 anyfunc)) - (import "env" "memoryBase" (global $import$11 i32)) - (import "env" "tableBase" (global $import$12 i32)) - (global $global$0 (mut i32) (get_global $import$0)) - (global $global$1 (mut i32) (get_global $import$1)) - (global $global$2 (mut i32) (get_global $import$2)) - (global $global$3 (mut i32) (get_global $import$3)) - (global $global$4 (mut i32) (get_global $import$4)) - (global $global$5 (mut i32) (get_global $import$5)) - (global $global$6 (mut i32) (get_global $import$6)) + (import "env" "memoryBase" (global $gimport$11 i32)) + (import "env" "tableBase" (global $gimport$12 i32)) + (global $global$0 (mut i32) (get_global $gimport$0)) + (global $global$1 (mut i32) (get_global $gimport$1)) + (global $global$2 (mut i32) (get_global $gimport$2)) + (global $global$3 (mut i32) (get_global $gimport$3)) + (global $global$4 (mut i32) (get_global $gimport$4)) + (global $global$5 (mut i32) (get_global $gimport$5)) + (global $global$6 (mut i32) (get_global $gimport$6)) (global $global$7 (mut i32) (i32.const 0)) (global $global$8 (mut i32) (i32.const 0)) (global $global$9 (mut i32) (i32.const 0)) (global $global$10 (mut i32) (i32.const 0)) - (global $global$11 (mut f64) (get_global $import$7)) - (global $global$12 (mut f64) (get_global $import$8)) + (global $global$11 (mut f64) (get_global $gimport$7)) + (global $global$12 (mut f64) (get_global $gimport$8)) (global $global$13 (mut i32) (i32.const 0)) (global $global$14 (mut i32) (i32.const 0)) (global $global$15 (mut i32) (i32.const 0)) diff --git a/test/merge/dylib.wasm.combined b/test/merge/dylib.wasm.combined index cb892e5cd..9a7d5ddd3 100644 --- a/test/merge/dylib.wasm.combined +++ b/test/merge/dylib.wasm.combined @@ -6,19 +6,19 @@ (type $0$0 (func (param i32 i32))) (type $1$0 (func (result i32))) (type $2$0 (func)) - (import "env" "memoryBase" (global $import$0 i32)) + (import "env" "memoryBase" (global $gimport$0 i32)) (import "env" "memory" (memory $0 256)) (import "env" "table" (table 0 anyfunc)) - (import "env" "tableBase" (global $import$4 i32)) + (import "env" "tableBase" (global $gimport$4 i32)) (import "env" "_puts" (func $import$1 (param i32) (result i32))) - (import "env" "memoryBase" (global $import$0$0 i32)) - (import "env" "tableBase" (global $import$4$0 i32)) + (import "env" "memoryBase" (global $gimport$0$0 i32)) + (import "env" "tableBase" (global $gimport$4$0 i32)) (global $global$0 (mut i32) (i32.const 0)) (global $global$1 (mut i32) (i32.const 0)) (global $global$2 i32 (i32.const 0)) (global $global$0$0 (mut i32) (i32.const 0)) (global $global$1$0 (mut i32) (i32.const 0)) - (data (get_global $import$0) "hello, world!\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") + (data (get_global $gimport$0) "hello, world!\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") (export "__post_instantiate" (func $__post_instantiate)) (export "_main" (func $_main)) (export "runPostSets" (func $runPostSets)) @@ -29,7 +29,7 @@ (block $label$2 (result i32) (drop (call $import$1 - (get_global $import$0) + (get_global $gimport$0) ) ) (i32.const 0) @@ -47,7 +47,7 @@ (block $label$2 (set_global $global$0 (i32.add - (get_global $import$0) + (get_global $gimport$0) (i32.const 16) ) ) @@ -82,7 +82,7 @@ (block $label$2 (set_global $global$0$0 (i32.add - (get_global $import$0$0) + (get_global $gimport$0$0) (i32.const 48) ) ) diff --git a/test/merge/dylib.wasm.combined.finalized b/test/merge/dylib.wasm.combined.finalized index 12952d0a4..10905193c 100644 --- a/test/merge/dylib.wasm.combined.finalized +++ b/test/merge/dylib.wasm.combined.finalized @@ -6,13 +6,13 @@ (type $0$0 (func (param i32 i32))) (type $1$0 (func (result i32))) (type $2$0 (func)) - (import "env" "memoryBase" (global $import$0 i32)) + (import "env" "memoryBase" (global $gimport$0 i32)) (import "env" "memory" (memory $0 256)) (import "env" "table" (table 8 anyfunc)) - (import "env" "tableBase" (global $import$4 i32)) + (import "env" "tableBase" (global $gimport$4 i32)) (import "env" "_puts" (func $import$1 (param i32) (result i32))) - (import "env" "memoryBase" (global $import$0$0 i32)) - (import "env" "tableBase" (global $import$4$0 i32)) + (import "env" "memoryBase" (global $gimport$0$0 i32)) + (import "env" "tableBase" (global $gimport$4$0 i32)) (global $global$0 (mut i32) (i32.const 0)) (global $global$1 (mut i32) (i32.const 0)) (global $global$2 i32 (i32.const 0)) diff --git a/test/merge/dylib.wasm.combined.opt b/test/merge/dylib.wasm.combined.opt index eab9c2ec3..f049197d5 100644 --- a/test/merge/dylib.wasm.combined.opt +++ b/test/merge/dylib.wasm.combined.opt @@ -2,18 +2,18 @@ (type $1 (func (param i32) (result i32))) (type $2 (func (result i32))) (type $3 (func)) - (import "env" "memoryBase" (global $import$0 i32)) + (import "env" "memoryBase" (global $gimport$0 i32)) (import "env" "memory" (memory $0 256)) (import "env" "table" (table 0 anyfunc)) - (import "env" "tableBase" (global $import$4 i32)) + (import "env" "tableBase" (global $gimport$4 i32)) (import "env" "_puts" (func $import$1 (param i32) (result i32))) - (import "env" "memoryBase" (global $import$0$0 i32)) + (import "env" "memoryBase" (global $gimport$0$0 i32)) (global $global$0 (mut i32) (i32.const 0)) (global $global$1 (mut i32) (i32.const 0)) (global $global$2 i32 (i32.const 0)) (global $global$0$0 (mut i32) (i32.const 0)) (global $global$1$0 (mut i32) (i32.const 0)) - (data (get_global $import$0) "hello, world!") + (data (get_global $gimport$0) "hello, world!") (export "__post_instantiate" (func $__post_instantiate)) (export "_main" (func $_main)) (export "runPostSets" (func $runPostSets)) @@ -24,7 +24,7 @@ (block $label$2 (result i32) (drop (call $import$1 - (get_global $import$0) + (get_global $gimport$0) ) ) (i32.const 0) @@ -40,7 +40,7 @@ (block $label$2 (set_global $global$0 (i32.add - (get_global $import$0) + (get_global $gimport$0) (i32.const 16) ) ) @@ -73,7 +73,7 @@ (block $label$2 (set_global $global$0$0 (i32.add - (get_global $import$0$0) + (get_global $gimport$0$0) (i32.const 48) ) ) diff --git a/test/unit.wast.fromBinary.noDebugInfo b/test/unit.wast.fromBinary.noDebugInfo index 4fe3d9015..5402df154 100644 --- a/test/unit.wast.fromBinary.noDebugInfo +++ b/test/unit.wast.fromBinary.noDebugInfo @@ -9,9 +9,9 @@ (type $7 (func (param f64) (result f64))) (type $8 (func (result i64))) (type $9 (func (param i32 i64))) - (import "env" "_emscripten_asm_const_vi" (func $import$0)) - (import "asm2wasm" "f64-to-int" (func $import$1 (param f64) (result i32))) - (import "asm2wasm" "f64-rem" (func $import$2 (param f64 f64) (result f64))) + (import "env" "_emscripten_asm_const_vi" (func $fimport$0)) + (import "asm2wasm" "f64-to-int" (func $fimport$1 (param f64) (result i32))) + (import "asm2wasm" "f64-rem" (func $fimport$2 (param f64 f64) (result f64))) (table 10 anyfunc) (elem (i32.const 0) $17 $0 $17 $17 $18 $18 $1 $18 $17 $15) (memory $0 4096 4096) @@ -153,7 +153,7 @@ (local $var$0 i32) (local $var$1 f64) (set_local $var$0 - (call $import$1 + (call $fimport$1 (get_local $var$1) ) ) @@ -274,7 +274,7 @@ ) ) (func $9 (; 12 ;) (type $4) (result f64) - (call $import$2 + (call $fimport$2 (f64.const 5.5) (f64.const 1.2) ) |