summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2020-04-07 17:55:40 -0700
committerGitHub <noreply@github.com>2020-04-07 17:55:40 -0700
commite77d85fecd2bfe707f3e9b7ab84cfd6744bdc7b7 (patch)
treecd674b0322cec50feeb132e634bc17eeedf40ab5 /src
parenteaa7240105811ffa565dc97768f1399e7855744b (diff)
downloadbinaryen-e77d85fecd2bfe707f3e9b7ab84cfd6744bdc7b7.tar.gz
binaryen-e77d85fecd2bfe707f3e9b7ab84cfd6744bdc7b7.tar.bz2
binaryen-e77d85fecd2bfe707f3e9b7ab84cfd6744bdc7b7.zip
Only do fp$ optimization in the main module (#2720)
Weak symbols and interposition etc. mean that we should not replace an fp$ call with a symbol from the module itself if there is a chance there is another symbol that would have overridden it. In side modules this risk exists and so this PR makes us stop doing that. In main modules it is ok because they are loaded first and so any symbol they provide will "win" over others anyhow.
Diffstat (limited to 'src')
-rw-r--r--src/wasm/wasm-emscripten.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp
index 0d71e8f00..75598875c 100644
--- a/src/wasm/wasm-emscripten.cpp
+++ b/src/wasm/wasm-emscripten.cpp
@@ -306,13 +306,13 @@ Function* EmscriptenGlueGenerator::generateAssignGOTEntriesFunction() {
// 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) {
+ // If this is exported then it must be one of the functions implemented
+ // here, and if this is a main module, then we can simply place the function
+ // in the table: the loader will see it there and resolve all other uses
+ // to this one.
+ if (ex && !sideModule) {
assert(ex->kind == ExternalKind::Function);
auto* f = wasm.getFunction(ex->value);
- // This is exported, so must be one of the functions implemented here.
- // Simply add it to the table, and use that index. The loader will
- // know to reuse that index for other modules so they all share the
- // same index and function pointer equality works.
if (f->imported()) {
Fatal() << "GOT.func entry is both imported and exported: " << g->base;
}
@@ -337,10 +337,14 @@ Function* EmscriptenGlueGenerator::generateAssignGOTEntriesFunction() {
block->list.push_back(globalSet);
continue;
}
- // This is imported. Create an fp$ import to get the function table index.
+ // This is imported or in a side module. Create an fp$ import to get the
+ // function table index from the dynamic loader.
auto* f = importInfo.getImportedFunction(ENV, g->base);
if (!f) {
- Fatal() << "GOT.func entry with no import/export: " << g->base;
+ if (!ex) {
+ Fatal() << "GOT.func entry with no import/export: " << g->base;
+ }
+ f = wasm.getFunction(ex->value);
}
Name getter(
(std::string("fp$") + g->base.c_str() + std::string("$") + getSig(f))