Skip to content

Commit e663775

Browse files
committed
Update source map names field in prolog/epilog
WebAssembly#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.
1 parent 9d94003 commit e663775

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/wasm/wasm-binary.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,14 +1245,20 @@ void WasmBinaryWriter::writeSourceMapProlog() {
12451245
std::map<Index, Index> oldToNewIndex;
12461246

12471247
// Collect all used symbol name indexes.
1248-
for (auto& func : wasm->functions) {
1249-
for (auto& [_, location] : func->debugLocations) {
1248+
auto prepareIndexMap =
1249+
[&](std::optional<Function::DebugLocation>& location) {
12501250
if (location && location->symbolNameIndex) {
12511251
uint32_t oldIndex = *location->symbolNameIndex;
12521252
assert(oldIndex < wasm->debugInfoSymbolNames.size());
12531253
oldToNewIndex[oldIndex] = 0; // placeholder
12541254
}
1255+
};
1256+
for (auto& func : wasm->functions) {
1257+
for (auto& [_, location] : func->debugLocations) {
1258+
prepareIndexMap(location);
12551259
}
1260+
prepareIndexMap(func->prologLocation);
1261+
prepareIndexMap(func->epilogLocation);
12561262
}
12571263

12581264
// Create the new list of names and the mapping from old to new indices.
@@ -1263,13 +1269,19 @@ void WasmBinaryWriter::writeSourceMapProlog() {
12631269
}
12641270

12651271
// Update all debug locations to point to the new indices.
1266-
for (auto& func : wasm->functions) {
1267-
for (auto& [_, location] : func->debugLocations) {
1272+
auto updateIndexMap =
1273+
[&](std::optional<Function::DebugLocation>& location) {
12681274
if (location && location->symbolNameIndex) {
12691275
uint32_t oldIndex = *location->symbolNameIndex;
12701276
location->symbolNameIndex = oldToNewIndex[oldIndex];
12711277
}
1278+
};
1279+
for (auto& func : wasm->functions) {
1280+
for (auto& [_, location] : func->debugLocations) {
1281+
updateIndexMap(location);
12721282
}
1283+
updateIndexMap(func->prologLocation);
1284+
updateIndexMap(func->epilogLocation);
12731285
}
12741286

12751287
// Replace the old symbol names with the new, pruned list.

test/lit/source-map-names.wast

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
;; After --remove-unused-module-elements, the output source map's 'names' field
66
;; should NOT contain 'unused'
77

8-
;; OUT-MAP: "names":["used","used2"]
8+
;; OUT-MAP: "names":["used","used2","usedProlog"]
99

1010
(module
1111
(export "used" (func $used))
1212
(export "used2" (func $used2))
13+
(export "usedProlog" (func $usedProlog))
1314

1415
(func $unused
1516
;;@ src.cpp:1:1:unused
@@ -29,4 +30,11 @@
2930
;;@ src.cpp:3:1:used2
3031
(nop)
3132
)
33+
34+
;; OUT-WAST: ;;@ src.cpp:4:1:usedProlog
35+
;; OUT-WAST-NEXT: (func
36+
;;@ src.cpp:4:1:usedProlog
37+
(func $usedProlog
38+
(nop)
39+
)
3240
)

0 commit comments

Comments
 (0)