From 565e907d6f04ca2ef2fecc259124bdb9d0fd080f Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Mon, 27 Oct 2025 14:07:53 +0000 Subject: [PATCH 1/3] [wasm-split] End module names with : in manifests Suggested by by @sbc100 (https://github.com/emscripten-core/emscripten/pull/25577#discussion_r2456521570). Currently this supports both module names with a `:` and without it for backwards compatibility and also to pass the CI. --- src/support/istring.h | 18 ++++++++++++++++++ src/tools/wasm-split/wasm-split.cpp | 3 +++ test/lit/wasm-split/multi-split.wast.manifest | 6 +++--- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/support/istring.h b/src/support/istring.h index 7501f85bea7..dad20b8fb00 100644 --- a/src/support/istring.h +++ b/src/support/istring.h @@ -88,6 +88,24 @@ struct IString { return startsWith(std::string_view(str)); } + bool endsWith(std::string_view suffix) const { + // TODO: Use C++20 `ends_with`. + if (suffix.size() > str.size()) { + return false; + } + return str.substr(str.size() - suffix.size()) == suffix; + } + bool endsWith(IString str) const { return endsWith(str.str); } + + // Disambiguate for string literals. + template bool endsWith(const char (&str)[N]) const { + return endsWith(std::string_view(str)); + } + + IString substr(size_t pos, size_t len = std::string_view::npos) const { + return IString(str.substr(pos, len)); + } + size_t size() const { return str.size(); } }; diff --git a/src/tools/wasm-split/wasm-split.cpp b/src/tools/wasm-split/wasm-split.cpp index 1126c55be66..877e086bd6c 100644 --- a/src/tools/wasm-split/wasm-split.cpp +++ b/src/tools/wasm-split/wasm-split.cpp @@ -419,6 +419,9 @@ void multiSplitModule(const WasmSplitOptions& options) { } Name name = WasmBinaryReader::escape(line); if (newSection) { + if (name.endsWith(":")) { + name = name.substr(0, name.size() - 1); + } if (moduleNameSet.count(name)) { Fatal() << "Module name " << name << " is listed more than once\n"; } diff --git a/test/lit/wasm-split/multi-split.wast.manifest b/test/lit/wasm-split/multi-split.wast.manifest index f6e710feda1..23df277e74c 100644 --- a/test/lit/wasm-split/multi-split.wast.manifest +++ b/test/lit/wasm-split/multi-split.wast.manifest @@ -1,8 +1,8 @@ -1 +1: A -2 +2: B -3 +3: C From d46f5e2fca04694ac575f8520af7e7e02ab1e625 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Mon, 27 Oct 2025 15:01:40 +0000 Subject: [PATCH 2/3] Update more manifest --- test/lit/wasm-split/multi-split-escape-names.wast.manifest | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/lit/wasm-split/multi-split-escape-names.wast.manifest b/test/lit/wasm-split/multi-split-escape-names.wast.manifest index 23533e6dcf6..8ff81f419c8 100644 --- a/test/lit/wasm-split/multi-split-escape-names.wast.manifest +++ b/test/lit/wasm-split/multi-split-escape-names.wast.manifest @@ -1,8 +1,8 @@ -1 +1: wasm::Type::getFeatures() const -2 +2: wasm::Literal::Literal(std::__2::array const&) -3 +3: std::operator<<(std::__2::basic_ostream>&, wasm::Module&) From fdc141af4257bf8ff9027776af1051a8ffa8b5f5 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Mon, 27 Oct 2025 15:24:42 +0000 Subject: [PATCH 3/3] Error out when module name is empty --- src/tools/wasm-split/wasm-split.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/tools/wasm-split/wasm-split.cpp b/src/tools/wasm-split/wasm-split.cpp index 877e086bd6c..b2e65399774 100644 --- a/src/tools/wasm-split/wasm-split.cpp +++ b/src/tools/wasm-split/wasm-split.cpp @@ -421,6 +421,9 @@ void multiSplitModule(const WasmSplitOptions& options) { if (newSection) { if (name.endsWith(":")) { name = name.substr(0, name.size() - 1); + if (name.size() == 0) { + Fatal() << "Module name is empty\n"; + } } if (moduleNameSet.count(name)) { Fatal() << "Module name " << name << " is listed more than once\n";