From 59fbd50fdee6fd10886163ee4a02008cea61311f Mon Sep 17 00:00:00 2001 From: juj Date: Tue, 13 Sep 2022 19:15:47 +0300 Subject: The name of the import object might not always be "env" (e.g. when Emscripten minifies the import name to a shorter string "a"). Adjust LogExecution pass to discover the import name that is used. (#4746) --- src/passes/LogExecution.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/passes/LogExecution.cpp b/src/passes/LogExecution.cpp index 5978ecc72..63ada5819 100644 --- a/src/passes/LogExecution.cpp +++ b/src/passes/LogExecution.cpp @@ -59,7 +59,26 @@ struct LogExecution : public WalkerPass> { // Add the import auto import = Builder::makeFunction(LOGGER, Signature(Type::i32, Type::none), {}); - import->module = ENV; + + // Import the log function from import "env" if the module + // imports other functions from that name. + for (auto& func : curr->functions) { + if (func->imported() && func->module == ENV) { + import->module = func->module; + break; + } + } + + // If not, then pick the import name of the first function we find. + if (!import->module) { + for (auto& func : curr->functions) { + if (func->imported()) { + import->module = func->module; + break; + } + } + } + import->base = LOGGER; curr->addFunction(std::move(import)); } -- cgit v1.2.3