Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/wasm/wasm-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1373,9 +1373,19 @@ void WasmBinaryWriter::writeSourceMapEpilog() {

void WasmBinaryWriter::writeLateCustomSections() {
for (auto& section : wasm->customSections) {
if (section.name != BinaryConsts::CustomSections::Dylink) {
writeCustomSection(section);
if (section.name == BinaryConsts::CustomSections::Dylink) {
// This is an early custom section.
continue;
}

if (section.name == BinaryConsts::CustomSections::SourceMapUrl &&
sourceMap && !sourceMapUrl.empty()) {
// We are writing a SourceMapURL manually, following the user's request.
// Do not emit the existing custom section as a second one.
continue;
}

writeCustomSection(section);
}
}

Expand Down
37 changes: 37 additions & 0 deletions test/lit/debug/source-map-url.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
(module
(func $test (param i32) (result i32)
;;@ waka:100:1
(i32.const 42)
)
)

;; 1. Generate a binary with a source map and url.
;;
;; RUN: wasm-opt %s -g -o %t.wasm -osm %t.wasm.map -osu=one
;; RUN: wasm-dis %t.wasm | filecheck %s --check-prefix=ONE

;; ONE: ;; custom section "sourceMappingURL", size 4


;; 2. Round-trip that binary, again using -osu. This should not end up with two
;; sourceMappingURL sections (one could arrive from the flag, and one from the
;; existing custom section, if we copy it). Note the length increases, from
;; "one\0" (4) to "swap\0" (5), as we swap the URL.
;;
;; RUN: wasm-opt %t.wasm -o %t.wasm2 -ism %t.wasm.map -osm %t.wasm.map2 -osu=swap
;; RUN: wasm-dis %t.wasm2 | filecheck %s --check-prefix=SWAP

;; Look for a wrong section both before and after the correct one.

;; SWAP-NOT: ;; custom section "sourceMappingURL", size 4
;; SWAP: ;; custom section "sourceMappingURL", size 5
;; SWAP-NOT: ;; custom section "sourceMappingURL"


;; 3. Round-trip without -osu. Now we just copy the old URL.
;;
;; RUN: wasm-opt %t.wasm2 -o %t.wasm3 -ism %t.wasm.map2 -osm %t.wasm.map3
;; RUN: wasm-dis %t.wasm3 | filecheck %s --check-prefix=ROUND

;; ROUND: ;; custom section "sourceMappingURL", size 5

Loading