Skip to content

Commit af4c6d9

Browse files
committed
[wasm-merge] Preserve function names when writing a profile
When wasm-merge writes a wasm-split profile, it uses names to identify functions. It is never correct to then throw those names away when writing the binary, because that would make the profile useless. To avoid this problem, have --output-manifest imply --debuginfo and preserve the function names.
1 parent 604f547 commit af4c6d9

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

src/tools/wasm-merge.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,11 +697,13 @@ Input source maps can be specified by adding an -ism option right after the modu
697697
"",
698698
"Write a wasm-split manifest to the specified file. This manifest can "
699699
"be given to wasm-split to split the merged module along the lines of "
700-
"the original modules.",
700+
"the original modules. Implies --debuginfo to preserve function names "
701+
"in the output module.",
701702
WasmMergeOption,
702703
Options::Arguments::One,
703-
[&manifestFile](Options* o, const std::string& argument) {
704+
[&](Options* o, const std::string& argument) {
704705
manifestFile = argument;
706+
debugInfo = true;
705707
})
706708
.add("--rename-export-conflicts",
707709
"-rec",

test/lit/help/wasm-merge.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
;; CHECK-NEXT: specified file. This manifest can be
3939
;; CHECK-NEXT: given to wasm-split to split the merged
4040
;; CHECK-NEXT: module along the lines of the original
41-
;; CHECK-NEXT: modules.
41+
;; CHECK-NEXT: modules. Implies --debuginfo to preserve
42+
;; CHECK-NEXT: function names in the output module.
4243
;; CHECK-NEXT:
4344
;; CHECK-NEXT: --rename-export-conflicts,-rec Rename exports to avoid conflicts (rather
4445
;; CHECK-NEXT: than error)

test/lit/merge/manifest.wat

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
;; RUN: wasm-merge %s first %s.second second %s.third third --output-manifest %t.manifest -S -o %t.wasm
1+
;; RUN: wasm-merge %s first %s.second second %s.third third --output-manifest %t.manifest -o %t.wasm
22
;; RUN: cat %t.manifest | filecheck %s
3+
;; RUN: wasm-dis %t.wasm -o - | filecheck %s --check-prefix MERGED
34

45
;; The first module is the primary module and does not appear in the manifest.
56
;; CHECK-NOT: first
@@ -12,6 +13,30 @@
1213
;; CHECK-NEXT: third
1314
;; CHECK-NEXT: qux
1415

16+
;; The binary should contain the original function names.
17+
;; MERGED: (module
18+
;; MERGED-NEXT: (type $0 (func))
19+
;; MERGED-NEXT: (import "env" "imported_first" (func $imported_first))
20+
;; MERGED-NEXT: (import "env" "imported_second" (func $imported_second))
21+
;; MERGED-NEXT: (import "env" "imported_third" (func $imported_third))
22+
;; MERGED-NEXT: (export "foo" (func $foo))
23+
;; MERGED-NEXT: (export "bar" (func $bar))
24+
;; MERGED-NEXT: (export "baz" (func $baz))
25+
;; MERGED-NEXT: (export "qux" (func $qux))
26+
;; MERGED-NEXT: (func $foo
27+
;; MERGED-NEXT: (call $imported_first)
28+
;; MERGED-NEXT: )
29+
;; MERGED-NEXT: (func $bar
30+
;; MERGED-NEXT: (nop)
31+
;; MERGED-NEXT: )
32+
;; MERGED-NEXT: (func $baz
33+
;; MERGED-NEXT: (call $imported_second)
34+
;; MERGED-NEXT: )
35+
;; MERGED-NEXT: (func $qux
36+
;; MERGED-NEXT: (call $imported_third)
37+
;; MERGED-NEXT: )
38+
;; MERGED-NEXT: )
39+
1540
(module
1641
(import "env" "imported_first" (func $imported_first))
1742
(func $foo (export "foo")

0 commit comments

Comments
 (0)