summaryrefslogtreecommitdiff
path: root/src
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 /src
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.
Diffstat (limited to 'src')
-rw-r--r--src/tools/wasm-emscripten-finalize.cpp25
1 files changed, 17 insertions, 8 deletions
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");
}
}