diff options
-rw-r--r-- | src/tools/wasm-split/instrumenter.cpp | 26 | ||||
-rw-r--r-- | test/lit/wasm-split/imported-memory.wast | 12 |
2 files changed, 26 insertions, 12 deletions
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)); } } diff --git a/test/lit/wasm-split/imported-memory.wast b/test/lit/wasm-split/imported-memory.wast new file mode 100644 index 000000000..39e2a0073 --- /dev/null +++ b/test/lit/wasm-split/imported-memory.wast @@ -0,0 +1,12 @@ +;; RUN: wasm-split --instrument %s -all -S -o - | filecheck %s + +;; Check that an imported memory is not exported as "profile-memory" + +(module + (import "env" "mem" (memory $mem 1 1)) +) + +;; CHECK: (import "env" "mem" (memory $mem 1 1)) +;; CHECK: (export "__write_profile" (func $__write_profile)) + +;; CHECK-NOT: (export "profile-memory" (memory $mem)) |