File tree Expand file tree Collapse file tree 2 files changed +49
-2
lines changed
Expand file tree Collapse file tree 2 files changed +49
-2
lines changed Original file line number Diff line number Diff line change @@ -1373,9 +1373,19 @@ void WasmBinaryWriter::writeSourceMapEpilog() {
13731373
13741374void WasmBinaryWriter::writeLateCustomSections () {
13751375 for (auto & section : wasm->customSections ) {
1376- if (section.name != BinaryConsts::CustomSections::Dylink) {
1377- writeCustomSection (section);
1376+ if (section.name == BinaryConsts::CustomSections::Dylink) {
1377+ // This is an early custom section.
1378+ continue ;
13781379 }
1380+
1381+ if (section.name == BinaryConsts::CustomSections::SourceMapUrl &&
1382+ sourceMap && !sourceMapUrl.empty ()) {
1383+ // We are writing a SourceMapURL manually, following the user's request.
1384+ // Do not emit the existing custom section as a second one.
1385+ continue ;
1386+ }
1387+
1388+ writeCustomSection (section);
13791389 }
13801390}
13811391
Original file line number Diff line number Diff line change 1+ (module
2+ (func $test (param i32 ) (result i32 )
3+ ;; @ waka:100:1
4+ (i32.const 42 )
5+ )
6+ )
7+
8+ ;; 1. Generate a binary with a source map and url.
9+ ;;
10+ ;; RUN: wasm-opt %s -g -o %t.wasm -osm %t.wasm.map -osu=one
11+ ;; RUN: wasm-dis %t.wasm | filecheck %s --check-prefix=ONE
12+
13+ ;; ONE: ;; custom section "sourceMappingURL", size 4
14+
15+
16+ ;; 2. Round-trip that binary, again using -osu. This should not end up with two
17+ ;; sourceMappingURL sections (one could arrive from the flag, and one from the
18+ ;; existing custom section, if we copy it). Note the length increases, from
19+ ;; "one\0" (4) to "swap\0" (5), as we swap the URL.
20+ ;;
21+ ;; RUN: wasm-opt %t.wasm -o %t.wasm2 -ism %t.wasm.map -osm %t.wasm.map2 -osu=swap
22+ ;; RUN: wasm-dis %t.wasm2 | filecheck %s --check-prefix=SWAP
23+
24+ ;; Look for a wrong section both before and after the correct one.
25+
26+ ;; SWAP-NOT: ;; custom section "sourceMappingURL", size 4
27+ ;; SWAP: ;; custom section "sourceMappingURL", size 5
28+ ;; SWAP-NOT: ;; custom section "sourceMappingURL"
29+
30+
31+ ;; 3. Round-trip without -osu. Now we just copy the old URL.
32+ ;;
33+ ;; RUN: wasm-opt %t.wasm2 -o %t.wasm3 -ism %t.wasm.map2 -osm %t.wasm.map3
34+ ;; RUN: wasm-dis %t.wasm3 | filecheck %s --check-prefix=ROUND
35+
36+ ;; ROUND: ;; custom section "sourceMappingURL", size 5
37+
You can’t perform that action at this time.
0 commit comments