diff options
author | Sam Clegg <sbc@chromium.org> | 2018-08-29 13:30:36 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-29 13:30:36 -0700 |
commit | f35b208a360882570bf97bfa7ff8d1293017dc95 (patch) | |
tree | 251c9945707315efb507c16510262ed7369d6f28 /src/wasm/wasm-emscripten.cpp | |
parent | 1c2871993bd219042814705a59b3bf81e4cbee58 (diff) | |
download | binaryen-f35b208a360882570bf97bfa7ff8d1293017dc95.tar.gz binaryen-f35b208a360882570bf97bfa7ff8d1293017dc95.tar.bz2 binaryen-f35b208a360882570bf97bfa7ff8d1293017dc95.zip |
wasm-emscripten-finalize: Don't allow duplicates in 'declares'/'invok… (#1655)
Allowing duplicates here was causes emscripten to generate a JS
object with duplicate keys.
Diffstat (limited to 'src/wasm/wasm-emscripten.cpp')
-rw-r--r-- | src/wasm/wasm-emscripten.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp index c70069e76..580510ecb 100644 --- a/src/wasm/wasm-emscripten.cpp +++ b/src/wasm/wasm-emscripten.cpp @@ -724,6 +724,12 @@ std::string EmscriptenGlueGenerator::generateEmscriptenMetadata( meta << "]"; } + // Avoid adding duplicate imports to `declares' or `invokeFuncs`. Even + // though we might import the same function multiple times (i.e. with + // different sigs) we only need to list is in the metadata once. + std::set<std::string> declares; + std::set<std::string> invokeFuncs; + // We use the `base` rather than the `name` of the imports here and below // becasue this is the externally visible name that the embedder (JS) will // see. @@ -735,7 +741,8 @@ std::string EmscriptenGlueGenerator::generateEmscriptenMetadata( !import->base.startsWith(EMSCRIPTEN_ASM_CONST.str) && !import->base.startsWith("invoke_") && !import->base.startsWith("jsCall_")) { - meta << maybeComma() << '"' << import->base.str << '"'; + if (declares.insert(import->base.str).second) + meta << maybeComma() << '"' << import->base.str << '"'; } } meta << "]"; @@ -769,7 +776,8 @@ std::string EmscriptenGlueGenerator::generateEmscriptenMetadata( commaFirst = true; for (const auto& import : wasm.imports) { if (import->base.startsWith("invoke_")) { - meta << maybeComma() << '"' << import->base.str << '"'; + if (invokeFuncs.insert(import->base.str).second) + meta << maybeComma() << '"' << import->base.str << '"'; } } meta << "]"; |