From 5f8fe3ccf657e2132d366f97f738773c4f4a9e2e Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Thu, 25 Jun 2026 21:32:02 +0000 Subject: [PATCH 1/3] [wasm-merge] Make empty function names explicit with --output-manifest Even for empty function names, they will be written to a manifest file when `--output-manifest` is given. But currently we don't print their names in the name section, making them not searchable by wasm-split that use the manifest file. --- src/tools/wasm-merge.cpp | 5 ++++ test/lit/merge/manifest-explicit-name.wat | 29 +++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 test/lit/merge/manifest-explicit-name.wat diff --git a/src/tools/wasm-merge.cpp b/src/tools/wasm-merge.cpp index 5f92fe2f929..c9e0c1a7da2 100644 --- a/src/tools/wasm-merge.cpp +++ b/src/tools/wasm-merge.cpp @@ -856,6 +856,11 @@ Input source maps can be specified by adding an -ism option right after the modu for (auto& func : currModule->functions) { if (!func->imported()) { funcs.push_back(func->name); + // Even if function name is empty, if we were to put it in the output + // manifest, it has to be emitted in the name section. + if (!manifestFile.empty()) { + merged.getFunction(func->name)->hasExplicitName = true; + } } } diff --git a/test/lit/merge/manifest-explicit-name.wat b/test/lit/merge/manifest-explicit-name.wat new file mode 100644 index 00000000000..b4f60fa5745 --- /dev/null +++ b/test/lit/merge/manifest-explicit-name.wat @@ -0,0 +1,29 @@ +;; RUN: wasm-merge %s first %s second --rename-export-conflicts --output-manifest %t.manifest -o %t.wasm +;; RUN: cat %t.manifest | filecheck %s +;; RUN: wasm-dis %t.wasm -o - | filecheck %s --check-prefix MERGED + +;; This tests if the internal names of empty function names are correctly +;; preserved in the name section so that they can match the names in the +;; manifest file. + +;; CHECK: second +;; CHECK-NEXT: 0_1 +;; CHECK-NEXT: + +;; MERGED: (module +;; MERGED-NEXT: (type $0 (func)) +;; MERGED-NEXT: (export "foo" (func $0)) +;; MERGED-NEXT: (export "foo_1" (func $0_1)) +;; MERGED-NEXT: (func $0 +;; MERGED-NEXT: (nop) +;; MERGED-NEXT: ) +;; MERGED-NEXT: (func $0_1 +;; MERGED-NEXT: (nop) +;; MERGED-NEXT: ) +;; MERGED-NEXT: ) + +(module + (func (export "foo") + nop + ) +) From 72a8892ef939d4ea9a821fbc7d86e6ae574525f6 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Sun, 28 Jun 2026 03:11:24 +0000 Subject: [PATCH 2/3] Move if (!manifestFile.empty()) --- src/tools/wasm-merge.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/tools/wasm-merge.cpp b/src/tools/wasm-merge.cpp index c9e0c1a7da2..1c50ece4830 100644 --- a/src/tools/wasm-merge.cpp +++ b/src/tools/wasm-merge.cpp @@ -852,13 +852,13 @@ Input source maps can be specified by adding an -ism option right after the modu // The functions in the module have been renamed and copied rather than // moved, so we can get their final names directly. (We don't need this // for the first module because it does not appear in the manifest.) - auto& funcs = moduleFuncs[inputFileName]; - for (auto& func : currModule->functions) { - if (!func->imported()) { - funcs.push_back(func->name); - // Even if function name is empty, if we were to put it in the output - // manifest, it has to be emitted in the name section. - if (!manifestFile.empty()) { + if (!manifestFile.empty()) { + auto& funcs = moduleFuncs[inputFileName]; + for (auto& func : currModule->functions) { + if (!func->imported()) { + funcs.push_back(func->name); + // Even if function name is empty, if we were to put it in the + // output manifest, it has to be emitted in the name section. merged.getFunction(func->name)->hasExplicitName = true; } } From 434fa885e03113c2e6217fba5db0453a2944b134 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Sun, 28 Jun 2026 03:15:04 +0000 Subject: [PATCH 3/3] typo --- src/tools/wasm-merge.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/wasm-merge.cpp b/src/tools/wasm-merge.cpp index 1c50ece4830..15367526ed3 100644 --- a/src/tools/wasm-merge.cpp +++ b/src/tools/wasm-merge.cpp @@ -857,7 +857,7 @@ Input source maps can be specified by adding an -ism option right after the modu for (auto& func : currModule->functions) { if (!func->imported()) { funcs.push_back(func->name); - // Even if function name is empty, if we were to put it in the + // Even if the function name is empty, if we were to put it in the // output manifest, it has to be emitted in the name section. merged.getFunction(func->name)->hasExplicitName = true; }