diff options
author | Sam Clegg <sbc@chromium.org> | 2019-04-16 13:05:04 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-16 13:05:04 -0700 |
commit | a76c9dcddf1280b76b0c18c2605453d66a2af410 (patch) | |
tree | b66c02a987ae4142c8b8496e66dc8b65d12445bb /src/wasm/wasm-emscripten.cpp | |
parent | 324238cc44e51c65637d29a938c435248d384154 (diff) | |
download | binaryen-a76c9dcddf1280b76b0c18c2605453d66a2af410.tar.gz binaryen-a76c9dcddf1280b76b0c18c2605453d66a2af410.tar.bz2 binaryen-a76c9dcddf1280b76b0c18c2605453d66a2af410.zip |
Make sure we always add signature to `fp$` functions (#1994)
Previously we were searching for the function by name but this
doesn't work when the internal name for the function is different.
In order to repro such a case the shared.c test was converted to C++
since then binaryen's internal name is different since it comes from
the de-mangled name section.
Diffstat (limited to 'src/wasm/wasm-emscripten.cpp')
-rw-r--r-- | src/wasm/wasm-emscripten.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp index da2604383..b969a1fbd 100644 --- a/src/wasm/wasm-emscripten.cpp +++ b/src/wasm/wasm-emscripten.cpp @@ -230,10 +230,20 @@ Function* EmscriptenGlueGenerator::generateAssignGOTEntriesFunction() { } for (Global* g : got_entries_func) { - Name getter(std::string("fp$") + g->base.c_str()); - if (auto* f = wasm.getFunctionOrNull(g->base)) { - getter.set((getter.c_str() + std::string("$") + getSig(f)).c_str(), false); + Function* f = nullptr; + // The function has to exist either as export or an import. + // Note that we don't search for the function by name since its internal + // name may be different. + auto* ex = wasm.getExportOrNull(g->base); + if (ex) { + assert(ex->kind == ExternalKind::Function); + f = wasm.getFunction(ex->value); + } else { + ImportInfo info(wasm); + f = info.getImportedFunction(ENV, g->base); } + + Name getter((std::string("fp$") + g->base.c_str() + std::string("$") + getSig(f)).c_str()); ensureFunctionImport(&wasm, getter, "i"); Expression* call = builder.makeCall(getter, {}, i32); SetGlobal* set_global = builder.makeSetGlobal(g->name, call); |