summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2018-12-03 16:54:58 -0800
committerGitHub <noreply@github.com>2018-12-03 16:54:58 -0800
commit99cad87cea463fc3b978850a1d1416d9b338a14c (patch)
tree8c0fe0f10e08848dc6ec13c1cf21a2a820197908
parentd53c64875ff0367dbc28ccea3d3299809fd8ee36 (diff)
downloadbinaryen-99cad87cea463fc3b978850a1d1416d9b338a14c.tar.gz
binaryen-99cad87cea463fc3b978850a1d1416d9b338a14c.tar.bz2
binaryen-99cad87cea463fc3b978850a1d1416d9b338a14c.zip
wasm-emscripten-finalize: ensure table/memory imports use emscripten's expected names (#1795)
This means lld can emscripten can disagree about the naming of these imports and emscripten-wasm-finalize will take care of paper over the differences.
-rwxr-xr-xauto_update_tests.py10
-rw-r--r--src/tools/wasm-emscripten-finalize.cpp25
-rw-r--r--test/lld/duplicate_imports.wast.out4
-rw-r--r--test/lld/em_asm.wast.out4
-rw-r--r--test/lld/hello_world.wast.mem.out4
-rw-r--r--test/lld/hello_world.wast.out4
-rw-r--r--test/lld/init.wast.out4
-rw-r--r--test/lld/recursive.wast.out4
-rw-r--r--test/lld/reserved_func_ptr.wast.jscall.out4
-rw-r--r--test/lld/reserved_func_ptr.wast.out4
10 files changed, 39 insertions, 28 deletions
diff --git a/auto_update_tests.py b/auto_update_tests.py
index d11a8f6aa..2e5a4a090 100755
--- a/auto_update_tests.py
+++ b/auto_update_tests.py
@@ -74,12 +74,14 @@ def update_asm_js_tests():
def update_lld_tests():
print '\n[ checking wasm-emscripten-finalize testcases... ]\n'
- extension_arg_map = {
- '.out': [],
- '.jscall.out': ['--emscripten-reserved-function-pointers=3'],
- }
for wast_path in files_with_pattern('test', 'lld', '*.wast'):
print '..', wast_path
+ mem_file = wast_path + '.mem'
+ extension_arg_map = {
+ '.out': [],
+ '.jscall.out': ['--emscripten-reserved-function-pointers=3'],
+ '.mem.out': ['--separate-data-segments', mem_file],
+ }
for ext, ext_args in extension_arg_map.items():
out_path = wast_path + ext
if ext != '.out' and not os.path.exists(out_path):
diff --git a/src/tools/wasm-emscripten-finalize.cpp b/src/tools/wasm-emscripten-finalize.cpp
index 1a3499757..861af845a 100644
--- a/src/tools/wasm-emscripten-finalize.cpp
+++ b/src/tools/wasm-emscripten-finalize.cpp
@@ -168,19 +168,28 @@ int main(int argc, const char *argv[]) {
std::vector<Name> initializerFunctions;
+ // The names of standard imports/exports used by lld doesn't quite match that
+ // expected by emscripten.
+ // TODO(sbc): Unify these
+ if (Export* ex = wasm.getExportOrNull("__wasm_call_ctors")) {
+ ex->name = "__post_instantiate";
+ }
+ if (wasm.table.imported()) {
+ if (wasm.table.base != "table") wasm.table.base = Name("table");
+ }
+ if (wasm.memory.imported()) {
+ if (wasm.table.base != "memory") wasm.memory.base = Name("memory");
+ }
+
if (isSideModule) {
generator.replaceStackPointerGlobal();
- // rename __wasm_call_ctors to __post_instantiate which is what
- // emscripten expects.
- // TODO(sbc): Unify these two names
- if (Export* ex = wasm.getExportOrNull("__wasm_call_ctors")) {
- ex->name = "__post_instantiate";
- }
} else {
generator.generateRuntimeFunctions();
generator.generateMemoryGrowthFunction();
- if (wasm.getFunctionOrNull("__wasm_call_ctors")) {
- initializerFunctions.push_back("__wasm_call_ctors");
+ // emscripten calls this by default for side libraries so we only need
+ // to include in as a static ctor for main module case.
+ if (wasm.getFunctionOrNull("__post_instantiate")) {
+ initializerFunctions.push_back("__post_instantiate");
}
}
diff --git a/test/lld/duplicate_imports.wast.out b/test/lld/duplicate_imports.wast.out
index b9ef5599c..6e5868afa 100644
--- a/test/lld/duplicate_imports.wast.out
+++ b/test/lld/duplicate_imports.wast.out
@@ -20,7 +20,7 @@
(global $global$1 i32 (i32.const 66128))
(global $global$2 i32 (i32.const 581))
(export "memory" (memory $0))
- (export "__wasm_call_ctors" (func $__wasm_call_ctors))
+ (export "__post_instantiate" (func $__wasm_call_ctors))
(export "main" (func $main))
(export "__heap_base" (global $global$1))
(export "__data_end" (global $global$2))
@@ -101,4 +101,4 @@
)
)
)
-;; METADATA: { "asmConsts": {},"staticBump": 13, "initializers": ["__wasm_call_ctors"], "declares": ["puts"], "externs": [], "implementedFunctions": ["___wasm_call_ctors","_main","_stackSave","_stackAlloc","_stackRestore","___growWasmMemory"], "exports": ["memory","__wasm_call_ctors","main","__heap_base","__data_end","stackSave","stackAlloc","stackRestore","__growWasmMemory"], "invokeFuncs": ["invoke_ffd"] }
+;; METADATA: { "asmConsts": {},"staticBump": 13, "initializers": [], "declares": ["puts"], "externs": [], "implementedFunctions": ["___post_instantiate","_main","_stackSave","_stackAlloc","_stackRestore","___growWasmMemory"], "exports": ["memory","__post_instantiate","main","__heap_base","__data_end","stackSave","stackAlloc","stackRestore","__growWasmMemory"], "invokeFuncs": ["invoke_ffd"] }
diff --git a/test/lld/em_asm.wast.out b/test/lld/em_asm.wast.out
index 31d91316a..f33743f7a 100644
--- a/test/lld/em_asm.wast.out
+++ b/test/lld/em_asm.wast.out
@@ -17,7 +17,7 @@
(global $global$1 i32 (i32.const 66192))
(global $global$2 i32 (i32.const 652))
(export "memory" (memory $0))
- (export "__wasm_call_ctors" (func $__wasm_call_ctors))
+ (export "__post_instantiate" (func $__wasm_call_ctors))
(export "main" (func $main))
(export "__heap_base" (global $global$1))
(export "__data_end" (global $global$2))
@@ -75,4 +75,4 @@
)
)
)
-;; METADATA: { "asmConsts": {"2": ["{ Module.print(\"Got \" + $0); }", ["ii"], [""]],"0": ["{ Module.print(\"Hello world\"); }", ["i"], [""]],"1": ["{ return $0 + $1; }", ["iii"], [""]]},"staticBump": 84, "initializers": ["__wasm_call_ctors"], "declares": [], "externs": [], "implementedFunctions": ["___wasm_call_ctors","_main","_stackSave","_stackAlloc","_stackRestore","___growWasmMemory"], "exports": ["memory","__wasm_call_ctors","main","__heap_base","__data_end","stackSave","stackAlloc","stackRestore","__growWasmMemory"], "invokeFuncs": [] }
+;; METADATA: { "asmConsts": {"2": ["{ Module.print(\"Got \" + $0); }", ["ii"], [""]],"0": ["{ Module.print(\"Hello world\"); }", ["i"], [""]],"1": ["{ return $0 + $1; }", ["iii"], [""]]},"staticBump": 84, "initializers": [], "declares": [], "externs": [], "implementedFunctions": ["___post_instantiate","_main","_stackSave","_stackAlloc","_stackRestore","___growWasmMemory"], "exports": ["memory","__post_instantiate","main","__heap_base","__data_end","stackSave","stackAlloc","stackRestore","__growWasmMemory"], "invokeFuncs": [] }
diff --git a/test/lld/hello_world.wast.mem.out b/test/lld/hello_world.wast.mem.out
index f54d9cbbd..4e2ad9312 100644
--- a/test/lld/hello_world.wast.mem.out
+++ b/test/lld/hello_world.wast.mem.out
@@ -10,7 +10,7 @@
(global $global$1 i32 (i32.const 66128))
(global $global$2 i32 (i32.const 581))
(export "memory" (memory $0))
- (export "__wasm_call_ctors" (func $__wasm_call_ctors))
+ (export "__post_instantiate" (func $__wasm_call_ctors))
(export "main" (func $main))
(export "__heap_base" (global $global$1))
(export "__data_end" (global $global$2))
@@ -58,4 +58,4 @@
)
)
)
-;; METADATA: { "asmConsts": {},"staticBump": 13, "initializers": ["__wasm_call_ctors"], "declares": ["puts"], "externs": [], "implementedFunctions": ["___wasm_call_ctors","_main","_stackSave","_stackAlloc","_stackRestore","___growWasmMemory"], "exports": ["memory","__wasm_call_ctors","main","__heap_base","__data_end","stackSave","stackAlloc","stackRestore","__growWasmMemory"], "invokeFuncs": [] }
+;; METADATA: { "asmConsts": {},"staticBump": 13, "initializers": [], "declares": ["puts"], "externs": [], "implementedFunctions": ["___post_instantiate","_main","_stackSave","_stackAlloc","_stackRestore","___growWasmMemory"], "exports": ["memory","__post_instantiate","main","__heap_base","__data_end","stackSave","stackAlloc","stackRestore","__growWasmMemory"], "invokeFuncs": [] }
diff --git a/test/lld/hello_world.wast.out b/test/lld/hello_world.wast.out
index 2e891cfa5..72df62ec6 100644
--- a/test/lld/hello_world.wast.out
+++ b/test/lld/hello_world.wast.out
@@ -11,7 +11,7 @@
(global $global$1 i32 (i32.const 66128))
(global $global$2 i32 (i32.const 581))
(export "memory" (memory $0))
- (export "__wasm_call_ctors" (func $__wasm_call_ctors))
+ (export "__post_instantiate" (func $__wasm_call_ctors))
(export "main" (func $main))
(export "__heap_base" (global $global$1))
(export "__data_end" (global $global$2))
@@ -59,4 +59,4 @@
)
)
)
-;; METADATA: { "asmConsts": {},"staticBump": 13, "initializers": ["__wasm_call_ctors"], "declares": ["puts"], "externs": [], "implementedFunctions": ["___wasm_call_ctors","_main","_stackSave","_stackAlloc","_stackRestore","___growWasmMemory"], "exports": ["memory","__wasm_call_ctors","main","__heap_base","__data_end","stackSave","stackAlloc","stackRestore","__growWasmMemory"], "invokeFuncs": [] }
+;; METADATA: { "asmConsts": {},"staticBump": 13, "initializers": [], "declares": ["puts"], "externs": [], "implementedFunctions": ["___post_instantiate","_main","_stackSave","_stackAlloc","_stackRestore","___growWasmMemory"], "exports": ["memory","__post_instantiate","main","__heap_base","__data_end","stackSave","stackAlloc","stackRestore","__growWasmMemory"], "invokeFuncs": [] }
diff --git a/test/lld/init.wast.out b/test/lld/init.wast.out
index cdc6a55c3..d82e9d989 100644
--- a/test/lld/init.wast.out
+++ b/test/lld/init.wast.out
@@ -8,7 +8,7 @@
(global $global$1 i32 (i32.const 66112))
(global $global$2 i32 (i32.const 576))
(export "memory" (memory $0))
- (export "__wasm_call_ctors" (func $__wasm_call_ctors))
+ (export "__post_instantiate" (func $__wasm_call_ctors))
(export "main" (func $main))
(export "__heap_base" (global $global$1))
(export "__data_end" (global $global$2))
@@ -71,4 +71,4 @@
)
)
)
-;; METADATA: { "asmConsts": {},"staticBump": 8, "initializers": ["__wasm_call_ctors"], "declares": [], "externs": [], "implementedFunctions": ["___wasm_call_ctors","_main","_stackSave","_stackAlloc","_stackRestore","___growWasmMemory"], "exports": ["memory","__wasm_call_ctors","main","__heap_base","__data_end","stackSave","stackAlloc","stackRestore","__growWasmMemory"], "invokeFuncs": [] }
+;; METADATA: { "asmConsts": {},"staticBump": 8, "initializers": [], "declares": [], "externs": [], "implementedFunctions": ["___post_instantiate","_main","_stackSave","_stackAlloc","_stackRestore","___growWasmMemory"], "exports": ["memory","__post_instantiate","main","__heap_base","__data_end","stackSave","stackAlloc","stackRestore","__growWasmMemory"], "invokeFuncs": [] }
diff --git a/test/lld/recursive.wast.out b/test/lld/recursive.wast.out
index 75a907564..8d9dc411e 100644
--- a/test/lld/recursive.wast.out
+++ b/test/lld/recursive.wast.out
@@ -11,7 +11,7 @@
(global $global$1 i32 (i32.const 66128))
(global $global$2 i32 (i32.const 587))
(export "memory" (memory $0))
- (export "__wasm_call_ctors" (func $__wasm_call_ctors))
+ (export "__post_instantiate" (func $__wasm_call_ctors))
(export "main" (func $main))
(export "__heap_base" (global $global$1))
(export "__data_end" (global $global$2))
@@ -117,4 +117,4 @@
)
)
)
-;; METADATA: { "asmConsts": {},"staticBump": 19, "initializers": ["__wasm_call_ctors"], "declares": ["printf"], "externs": [], "implementedFunctions": ["___wasm_call_ctors","_main","_stackSave","_stackAlloc","_stackRestore","___growWasmMemory"], "exports": ["memory","__wasm_call_ctors","main","__heap_base","__data_end","stackSave","stackAlloc","stackRestore","__growWasmMemory"], "invokeFuncs": [] }
+;; METADATA: { "asmConsts": {},"staticBump": 19, "initializers": [], "declares": ["printf"], "externs": [], "implementedFunctions": ["___post_instantiate","_main","_stackSave","_stackAlloc","_stackRestore","___growWasmMemory"], "exports": ["memory","__post_instantiate","main","__heap_base","__data_end","stackSave","stackAlloc","stackRestore","__growWasmMemory"], "invokeFuncs": [] }
diff --git a/test/lld/reserved_func_ptr.wast.jscall.out b/test/lld/reserved_func_ptr.wast.jscall.out
index c38c60fa7..9d979b3a2 100644
--- a/test/lld/reserved_func_ptr.wast.jscall.out
+++ b/test/lld/reserved_func_ptr.wast.jscall.out
@@ -32,7 +32,7 @@
(global $global$1 i32 (i32.const 66112))
(global $global$2 i32 (i32.const 568))
(export "memory" (memory $0))
- (export "__wasm_call_ctors" (func $__wasm_call_ctors))
+ (export "__post_instantiate" (func $__wasm_call_ctors))
(export "main" (func $main))
(export "__heap_base" (global $global$1))
(export "__data_end" (global $global$2))
@@ -294,4 +294,4 @@
)
)
)
-;; METADATA: { "asmConsts": {},"staticBump": 0, "initializers": ["__wasm_call_ctors"], "jsCallStartIndex": 3, "jsCallFuncType": ["ddi","fffi","iii","v","vi","viii"], "declares": ["_Z4atoiPKc"], "externs": [], "implementedFunctions": ["___wasm_call_ctors","_main","_stackSave","_stackAlloc","_stackRestore","___growWasmMemory","_dynCall_viii"], "exports": ["memory","__wasm_call_ctors","main","__heap_base","__data_end","stackSave","stackAlloc","stackRestore","__growWasmMemory","dynCall_viii"], "invokeFuncs": [] }
+;; METADATA: { "asmConsts": {},"staticBump": 0, "initializers": [], "jsCallStartIndex": 3, "jsCallFuncType": ["ddi","fffi","iii","v","vi","viii"], "declares": ["_Z4atoiPKc"], "externs": [], "implementedFunctions": ["___post_instantiate","_main","_stackSave","_stackAlloc","_stackRestore","___growWasmMemory","_dynCall_viii"], "exports": ["memory","__post_instantiate","main","__heap_base","__data_end","stackSave","stackAlloc","stackRestore","__growWasmMemory","dynCall_viii"], "invokeFuncs": [] }
diff --git a/test/lld/reserved_func_ptr.wast.out b/test/lld/reserved_func_ptr.wast.out
index a7b57b04c..230a94f59 100644
--- a/test/lld/reserved_func_ptr.wast.out
+++ b/test/lld/reserved_func_ptr.wast.out
@@ -16,7 +16,7 @@
(global $global$1 i32 (i32.const 66112))
(global $global$2 i32 (i32.const 568))
(export "memory" (memory $0))
- (export "__wasm_call_ctors" (func $__wasm_call_ctors))
+ (export "__post_instantiate" (func $__wasm_call_ctors))
(export "main" (func $main))
(export "__heap_base" (global $global$1))
(export "__data_end" (global $global$2))
@@ -155,4 +155,4 @@
)
)
)
-;; METADATA: { "asmConsts": {},"staticBump": 0, "initializers": ["__wasm_call_ctors"], "declares": ["_Z4atoiPKc"], "externs": [], "implementedFunctions": ["___wasm_call_ctors","_main","_stackSave","_stackAlloc","_stackRestore","___growWasmMemory","_dynCall_viii"], "exports": ["memory","__wasm_call_ctors","main","__heap_base","__data_end","stackSave","stackAlloc","stackRestore","__growWasmMemory","dynCall_viii"], "invokeFuncs": [] }
+;; METADATA: { "asmConsts": {},"staticBump": 0, "initializers": [], "declares": ["_Z4atoiPKc"], "externs": [], "implementedFunctions": ["___post_instantiate","_main","_stackSave","_stackAlloc","_stackRestore","___growWasmMemory","_dynCall_viii"], "exports": ["memory","__post_instantiate","main","__heap_base","__data_end","stackSave","stackAlloc","stackRestore","__growWasmMemory","dynCall_viii"], "invokeFuncs": [] }