From e77d85fecd2bfe707f3e9b7ab84cfd6744bdc7b7 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 7 Apr 2020 17:55:40 -0700 Subject: 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. --- src/wasm/wasm-emscripten.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src') 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)) -- cgit v1.2.3