summaryrefslogtreecommitdiff
path: root/src/passes/LogExecution.cpp
diff options
context:
space:
mode:
authorjuj <jujjyl@gmail.com>2022-09-13 19:15:47 +0300
committerGitHub <noreply@github.com>2022-09-13 19:15:47 +0300
commit59fbd50fdee6fd10886163ee4a02008cea61311f (patch)
treefb63a396391ff15a0210a845c6024f221447cdb6 /src/passes/LogExecution.cpp
parente198f37767af842d696b0d50540d91fdffd43fa8 (diff)
downloadbinaryen-59fbd50fdee6fd10886163ee4a02008cea61311f.tar.gz
binaryen-59fbd50fdee6fd10886163ee4a02008cea61311f.tar.bz2
binaryen-59fbd50fdee6fd10886163ee4a02008cea61311f.zip
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)
Diffstat (limited to 'src/passes/LogExecution.cpp')
-rw-r--r--src/passes/LogExecution.cpp21
1 files changed, 20 insertions, 1 deletions
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<PostWalker<LogExecution>> {
// 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));
}