From d3e70f90d5b6ca975af8f19f171e4190d3652913 Mon Sep 17 00:00:00 2001 From: Thomas Lively <7121787+tlively@users.noreply.github.com> Date: Wed, 8 Sep 2021 13:13:33 -0700 Subject: [wasm-split] Do not add exports of imported memories (#4133) We can assume that imported memories (and the profiling data they contain) are already accessible from the module's environment, so there's no need to export them. This also avoids needing to add knowledge of "profile-memory" to Emscripten's library_dylink.js. --- src/tools/wasm-split/instrumenter.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/tools/wasm-split/instrumenter.cpp b/src/tools/wasm-split/instrumenter.cpp index 36875bfc0..c23a70f06 100644 --- a/src/tools/wasm-split/instrumenter.cpp +++ b/src/tools/wasm-split/instrumenter.cpp @@ -266,19 +266,21 @@ void Instrumenter::addProfileExport() { } } - // Export the memory if it is not already exported. - bool memoryExported = false; - for (auto& ex : wasm->exports) { - if (ex->kind == ExternalKind::Memory) { - memoryExported = true; - break; + // Export the memory if it is not already exported or imported. + if (!wasm->memory.imported()) { + bool memoryExported = false; + for (auto& ex : wasm->exports) { + if (ex->kind == ExternalKind::Memory) { + memoryExported = true; + break; + } + } + if (!memoryExported) { + wasm->addExport( + Builder::makeExport("profile-memory", + Names::getValidExportName(*wasm, wasm->memory.name), + ExternalKind::Memory)); } - } - if (!memoryExported) { - wasm->addExport( - Builder::makeExport("profile-memory", - Names::getValidExportName(*wasm, wasm->memory.name), - ExternalKind::Memory)); } } -- cgit v1.2.3