diff options
author | Sam Clegg <sbc@chromium.org> | 2019-04-04 15:45:57 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-04 15:45:57 -0700 |
commit | 2129cef6acbbe4acd5fd675fbb00c329e2220a40 (patch) | |
tree | a92d18f24b4281d07b7695e87193335db557c019 | |
parent | cac81ba0ec2e477f106632f0eb0e774a2e10d491 (diff) | |
download | binaryen-2129cef6acbbe4acd5fd675fbb00c329e2220a40.tar.gz binaryen-2129cef6acbbe4acd5fd675fbb00c329e2220a40.tar.bz2 binaryen-2129cef6acbbe4acd5fd675fbb00c329e2220a40.zip |
wasm-emscripten-finalize: add namedGlobals to output metadata (#1979)
This key is used by emscripten when building with MAIN_MODULE in order
to export global variables from the main module to the side modules.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | src/tools/wasm-emscripten-finalize.cpp | 11 | ||||
-rw-r--r-- | src/wasm/wasm-emscripten.cpp | 18 | ||||
-rw-r--r-- | test/lld/duplicate_imports.wast.out | 7 | ||||
-rw-r--r-- | test/lld/em_asm.wast.mem.out | 7 | ||||
-rw-r--r-- | test/lld/em_asm.wast.out | 7 | ||||
-rw-r--r-- | test/lld/em_asm_O0.wast.out | 7 | ||||
-rw-r--r-- | test/lld/em_asm_table.wast.out | 4 | ||||
-rw-r--r-- | test/lld/em_js_O0.wast.out | 6 | ||||
-rw-r--r-- | test/lld/hello_world.wast.mem.out | 7 | ||||
-rw-r--r-- | test/lld/hello_world.wast.out | 7 | ||||
-rw-r--r-- | test/lld/init.wast.out | 7 | ||||
-rw-r--r-- | test/lld/recursive.wast.out | 7 | ||||
-rw-r--r-- | test/lld/reserved_func_ptr.wast.out | 7 | ||||
-rw-r--r-- | test/lld/shared.wast.out | 2 |
15 files changed, 67 insertions, 38 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index ae94e9bc8..052fe100d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ full changeset diff at the end of each section. Current Trunk ------------- +- Add `namedGlobals` to metadata output of wasm-emscripten-finalize - Add support for llvm PIC code. - Add --side-module option to wasm-emscripten-finalize. diff --git a/src/tools/wasm-emscripten-finalize.cpp b/src/tools/wasm-emscripten-finalize.cpp index 180383a90..0ed0e0857 100644 --- a/src/tools/wasm-emscripten-finalize.cpp +++ b/src/tools/wasm-emscripten-finalize.cpp @@ -135,12 +135,6 @@ int main(int argc, const char *argv[]) { WasmPrinter::printModule(&wasm, std::cerr); } - for (const UserSection& section : wasm.userSections) { - if (section.name == BinaryConsts::UserSections::Dylink) { - isSideModule = true; - } - } - uint32_t dataSize = 0; if (!isSideModule) { @@ -187,6 +181,11 @@ int main(int argc, const char *argv[]) { generator.generateStackInitialization(initialStackPointer); // For side modules these gets called via __post_instantiate if (Function* F = generator.generateAssignGOTEntriesFunction()) { + auto* ex = new Export(); + ex->value = F->name; + ex->name = F->name; + ex->kind = ExternalKind::Function; + wasm.addExport(ex); initializerFunctions.push_back(F->name); } if (auto* e = wasm.getExportOrNull(WASM_CALL_CTORS)) { diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp index 404d93ca3..0c02c758e 100644 --- a/src/wasm/wasm-emscripten.cpp +++ b/src/wasm/wasm-emscripten.cpp @@ -261,7 +261,6 @@ void EmscriptenGlueGenerator::generatePostInstantiateFunction() { ex->name = POST_INSTANTIATE; ex->kind = ExternalKind::Function; wasm.addExport(ex); - wasm.updateMaps(); } Function* EmscriptenGlueGenerator::generateMemoryGrowthFunction() { @@ -897,9 +896,24 @@ std::string EmscriptenGlueGenerator::generateEmscriptenMetadata( meta << " \"exports\": ["; commaFirst = true; for (const auto& ex : wasm.exports) { - meta << nextElement() << '"' << ex->name.str << '"'; + if (ex->kind == ExternalKind::Function) { + meta << nextElement() << '"' << ex->name.str << '"'; + } } meta << "\n ],\n"; + + meta << " \"namedGlobals\": {"; + commaFirst = true; + for (const auto& ex : wasm.exports) { + if (ex->kind == ExternalKind::Global) { + const Global* g = wasm.getGlobal(ex->value); + assert(g->type == i32); + Const* init = g->init->cast<Const>(); + uint32_t addr = init->value.geti32(); + meta << nextElement() << '"' << ex->name.str << "\" : \"" << addr << '"'; + } + } + meta << "\n },\n"; } meta << " \"invokeFuncs\": ["; diff --git a/test/lld/duplicate_imports.wast.out b/test/lld/duplicate_imports.wast.out index f01f8bb96..e7d36127f 100644 --- a/test/lld/duplicate_imports.wast.out +++ b/test/lld/duplicate_imports.wast.out @@ -123,16 +123,17 @@ "___growWasmMemory" ], "exports": [ - "memory", "__wasm_call_ctors", "main", - "__heap_base", - "__data_end", "stackSave", "stackAlloc", "stackRestore", "__growWasmMemory" ], + "namedGlobals": { + "__heap_base" : "66128", + "__data_end" : "581" + }, "invokeFuncs": [ "invoke_ffd" ] diff --git a/test/lld/em_asm.wast.mem.out b/test/lld/em_asm.wast.mem.out index 08bca193e..647342134 100644 --- a/test/lld/em_asm.wast.mem.out +++ b/test/lld/em_asm.wast.mem.out @@ -248,16 +248,17 @@ "___growWasmMemory" ], "exports": [ - "memory", "__wasm_call_ctors", - "__heap_base", - "__data_end", "main", "stackSave", "stackAlloc", "stackRestore", "__growWasmMemory" ], + "namedGlobals": { + "__heap_base" : "66192", + "__data_end" : "652" + }, "invokeFuncs": [ ] } diff --git a/test/lld/em_asm.wast.out b/test/lld/em_asm.wast.out index 50d4628c9..5e293f541 100644 --- a/test/lld/em_asm.wast.out +++ b/test/lld/em_asm.wast.out @@ -249,16 +249,17 @@ "___growWasmMemory" ], "exports": [ - "memory", "__wasm_call_ctors", - "__heap_base", - "__data_end", "main", "stackSave", "stackAlloc", "stackRestore", "__growWasmMemory" ], + "namedGlobals": { + "__heap_base" : "66192", + "__data_end" : "652" + }, "invokeFuncs": [ ] } diff --git a/test/lld/em_asm_O0.wast.out b/test/lld/em_asm_O0.wast.out index c45799980..099da3746 100644 --- a/test/lld/em_asm_O0.wast.out +++ b/test/lld/em_asm_O0.wast.out @@ -109,16 +109,17 @@ "___growWasmMemory" ], "exports": [ - "memory", "__wasm_call_ctors", "main", - "__heap_base", - "__data_end", "stackSave", "stackAlloc", "stackRestore", "__growWasmMemory" ], + "namedGlobals": { + "__heap_base" : "66192", + "__data_end" : "652" + }, "invokeFuncs": [ ] } diff --git a/test/lld/em_asm_table.wast.out b/test/lld/em_asm_table.wast.out index ae3675d40..06cfc9fc6 100644 --- a/test/lld/em_asm_table.wast.out +++ b/test/lld/em_asm_table.wast.out @@ -80,7 +80,6 @@ "_dynCall_iiii" ], "exports": [ - "__data_end", "stackSave", "stackAlloc", "stackRestore", @@ -88,6 +87,9 @@ "dynCall_vii", "dynCall_iiii" ], + "namedGlobals": { + "__data_end" : "1048" + }, "invokeFuncs": [ ] } diff --git a/test/lld/em_js_O0.wast.out b/test/lld/em_js_O0.wast.out index 9b3307d5e..385daf8d5 100644 --- a/test/lld/em_js_O0.wast.out +++ b/test/lld/em_js_O0.wast.out @@ -61,13 +61,15 @@ "___growWasmMemory" ], "exports": [ - "__heap_base", - "__data_end", "stackSave", "stackAlloc", "stackRestore", "__growWasmMemory" ], + "namedGlobals": { + "__heap_base" : "5250112", + "__data_end" : "7232" + }, "invokeFuncs": [ ] } diff --git a/test/lld/hello_world.wast.mem.out b/test/lld/hello_world.wast.mem.out index 32f8ddc14..ce0c93510 100644 --- a/test/lld/hello_world.wast.mem.out +++ b/test/lld/hello_world.wast.mem.out @@ -84,16 +84,17 @@ "___growWasmMemory" ], "exports": [ - "memory", "__wasm_call_ctors", - "__heap_base", - "__data_end", "main", "stackSave", "stackAlloc", "stackRestore", "__growWasmMemory" ], + "namedGlobals": { + "__heap_base" : "66128", + "__data_end" : "581" + }, "invokeFuncs": [ ] } diff --git a/test/lld/hello_world.wast.out b/test/lld/hello_world.wast.out index 20ffaf2cd..20539c0d5 100644 --- a/test/lld/hello_world.wast.out +++ b/test/lld/hello_world.wast.out @@ -85,16 +85,17 @@ "___growWasmMemory" ], "exports": [ - "memory", "__wasm_call_ctors", - "__heap_base", - "__data_end", "main", "stackSave", "stackAlloc", "stackRestore", "__growWasmMemory" ], + "namedGlobals": { + "__heap_base" : "66128", + "__data_end" : "581" + }, "invokeFuncs": [ ] } diff --git a/test/lld/init.wast.out b/test/lld/init.wast.out index 90c95263b..e9ca29152 100644 --- a/test/lld/init.wast.out +++ b/test/lld/init.wast.out @@ -96,16 +96,17 @@ "___growWasmMemory" ], "exports": [ - "memory", "__wasm_call_ctors", - "__heap_base", - "__data_end", "main", "stackSave", "stackAlloc", "stackRestore", "__growWasmMemory" ], + "namedGlobals": { + "__heap_base" : "66112", + "__data_end" : "576" + }, "invokeFuncs": [ ] } diff --git a/test/lld/recursive.wast.out b/test/lld/recursive.wast.out index 95f82f767..be0a0f007 100644 --- a/test/lld/recursive.wast.out +++ b/test/lld/recursive.wast.out @@ -142,16 +142,17 @@ "___growWasmMemory" ], "exports": [ - "memory", "__wasm_call_ctors", - "__heap_base", - "__data_end", "main", "stackSave", "stackAlloc", "stackRestore", "__growWasmMemory" ], + "namedGlobals": { + "__heap_base" : "66128", + "__data_end" : "587" + }, "invokeFuncs": [ ] } diff --git a/test/lld/reserved_func_ptr.wast.out b/test/lld/reserved_func_ptr.wast.out index 6afc10291..86d61bc82 100644 --- a/test/lld/reserved_func_ptr.wast.out +++ b/test/lld/reserved_func_ptr.wast.out @@ -178,10 +178,7 @@ "_dynCall_viii" ], "exports": [ - "memory", "__wasm_call_ctors", - "__heap_base", - "__data_end", "main", "stackSave", "stackAlloc", @@ -189,6 +186,10 @@ "__growWasmMemory", "dynCall_viii" ], + "namedGlobals": { + "__heap_base" : "66112", + "__data_end" : "568" + }, "invokeFuncs": [ ] } diff --git a/test/lld/shared.wast.out b/test/lld/shared.wast.out index c4f110972..67f4739dd 100644 --- a/test/lld/shared.wast.out +++ b/test/lld/shared.wast.out @@ -68,6 +68,8 @@ "print_message", "__post_instantiate" ], + "namedGlobals": { + }, "invokeFuncs": [ ] } |