From e663775ea6467caee4a93681e3363939d610ccf0 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Wed, 10 Dec 2025 02:20:18 +0000 Subject: [PATCH 1/4] Update source map names field in prolog/epilog #8068 failed to update `prologLocation` and `epilogLocation`, which caused the CI failure: https://app.circleci.com/pipelines/github/emscripten-core/emscripten/47832/workflows/ea0292aa-124d-4a3f-b988-0a96823e9bcd/jobs/1089017/tests This updates them properly. --- src/wasm/wasm-binary.cpp | 20 ++++++++++++++++---- test/lit/source-map-names.wast | 10 +++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index c4f123375d9..af9801ff541 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -1245,14 +1245,20 @@ void WasmBinaryWriter::writeSourceMapProlog() { std::map oldToNewIndex; // Collect all used symbol name indexes. - for (auto& func : wasm->functions) { - for (auto& [_, location] : func->debugLocations) { + auto prepareIndexMap = + [&](std::optional& location) { if (location && location->symbolNameIndex) { uint32_t oldIndex = *location->symbolNameIndex; assert(oldIndex < wasm->debugInfoSymbolNames.size()); oldToNewIndex[oldIndex] = 0; // placeholder } + }; + for (auto& func : wasm->functions) { + for (auto& [_, location] : func->debugLocations) { + prepareIndexMap(location); } + prepareIndexMap(func->prologLocation); + prepareIndexMap(func->epilogLocation); } // Create the new list of names and the mapping from old to new indices. @@ -1263,13 +1269,19 @@ void WasmBinaryWriter::writeSourceMapProlog() { } // Update all debug locations to point to the new indices. - for (auto& func : wasm->functions) { - for (auto& [_, location] : func->debugLocations) { + auto updateIndexMap = + [&](std::optional& location) { if (location && location->symbolNameIndex) { uint32_t oldIndex = *location->symbolNameIndex; location->symbolNameIndex = oldToNewIndex[oldIndex]; } + }; + for (auto& func : wasm->functions) { + for (auto& [_, location] : func->debugLocations) { + updateIndexMap(location); } + updateIndexMap(func->prologLocation); + updateIndexMap(func->epilogLocation); } // Replace the old symbol names with the new, pruned list. diff --git a/test/lit/source-map-names.wast b/test/lit/source-map-names.wast index b0a184bb588..1b49b14e269 100644 --- a/test/lit/source-map-names.wast +++ b/test/lit/source-map-names.wast @@ -5,11 +5,12 @@ ;; After --remove-unused-module-elements, the output source map's 'names' field ;; should NOT contain 'unused' -;; OUT-MAP: "names":["used","used2"] +;; OUT-MAP: "names":["used","used2","usedProlog"] (module (export "used" (func $used)) (export "used2" (func $used2)) + (export "usedProlog" (func $usedProlog)) (func $unused ;;@ src.cpp:1:1:unused @@ -29,4 +30,11 @@ ;;@ src.cpp:3:1:used2 (nop) ) + + ;; OUT-WAST: ;;@ src.cpp:4:1:usedProlog + ;; OUT-WAST-NEXT: (func + ;;@ src.cpp:4:1:usedProlog + (func $usedProlog + (nop) + ) ) From 4f1cf9c29884b72e36bc792b2b482306fcad74e0 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Wed, 10 Dec 2025 04:57:52 +0000 Subject: [PATCH 2/4] Rename function --- src/wasm/wasm-binary.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index af9801ff541..f5ed0947961 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -1269,7 +1269,7 @@ void WasmBinaryWriter::writeSourceMapProlog() { } // Update all debug locations to point to the new indices. - auto updateIndexMap = + auto updateIndex = [&](std::optional& location) { if (location && location->symbolNameIndex) { uint32_t oldIndex = *location->symbolNameIndex; @@ -1278,10 +1278,10 @@ void WasmBinaryWriter::writeSourceMapProlog() { }; for (auto& func : wasm->functions) { for (auto& [_, location] : func->debugLocations) { - updateIndexMap(location); + updateIndex(location); } - updateIndexMap(func->prologLocation); - updateIndexMap(func->epilogLocation); + updateIndex(func->prologLocation); + updateIndex(func->epilogLocation); } // Replace the old symbol names with the new, pruned list. From 86e0fc098ff5049f7ab65f7a25d51e5f9bd0b890 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Wed, 10 Dec 2025 08:00:39 +0000 Subject: [PATCH 3/4] clang-format --- src/wasm/wasm-binary.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index f5ed0947961..504f96bed74 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -1269,13 +1269,12 @@ void WasmBinaryWriter::writeSourceMapProlog() { } // Update all debug locations to point to the new indices. - auto updateIndex = - [&](std::optional& location) { - if (location && location->symbolNameIndex) { - uint32_t oldIndex = *location->symbolNameIndex; - location->symbolNameIndex = oldToNewIndex[oldIndex]; - } - }; + auto updateIndex = [&](std::optional& location) { + if (location && location->symbolNameIndex) { + uint32_t oldIndex = *location->symbolNameIndex; + location->symbolNameIndex = oldToNewIndex[oldIndex]; + } + }; for (auto& func : wasm->functions) { for (auto& [_, location] : func->debugLocations) { updateIndex(location); From 3e05ac10f0e7afb318733e02a09668be43d48779 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Wed, 10 Dec 2025 11:19:31 -0800 Subject: [PATCH 4/4] Update src/wasm/wasm-binary.cpp Co-authored-by: Alon Zakai --- src/wasm/wasm-binary.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 504f96bed74..df8b6a28df5 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -1246,7 +1246,7 @@ void WasmBinaryWriter::writeSourceMapProlog() { // Collect all used symbol name indexes. auto prepareIndexMap = - [&](std::optional& location) { + [&](const std::optional& location) { if (location && location->symbolNameIndex) { uint32_t oldIndex = *location->symbolNameIndex; assert(oldIndex < wasm->debugInfoSymbolNames.size());