Skip to content

Commit a349643

Browse files
authored
Add --strip-debug option to wasm-split (WebAssembly#8432)
wasm-split needs `-g` to use the name section (for `--keep-funcs`, `--split-funcs`, and `--manifest` options), but it leaves the name section (and any debug section if any) in the output, which you need to strip in a separate step. This option strips the debug section at the end.
1 parent 622a0ef commit a349643

File tree

5 files changed

+55
-1
lines changed

5 files changed

+55
-1
lines changed

src/tools/wasm-split/split-options.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,13 @@ WasmSplitOptions::WasmSplitOptions()
359359
[&](Options* o, const std::string& arguments) {
360360
passOptions.debugInfo = true;
361361
})
362+
.add("--strip-debug",
363+
"",
364+
"Strip debug info (including the names section)",
365+
WasmSplitOption,
366+
{Mode::Split, Mode::MultiSplit, Mode::Instrument},
367+
Options::Arguments::Zero,
368+
[&](Options* o, const std::string& arguments) { stripDebug = true; })
362369
.add("--output",
363370
"-o",
364371
"Output file.",

src/tools/wasm-split/split-options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ struct WasmSplitOptions : ToolOptions {
5151
bool symbolMap = false;
5252
bool placeholderMap = false;
5353
bool jspi = false;
54+
bool stripDebug = false;
5455

5556
// TODO: Remove this. See the comment in wasm-binary.h.
5657
bool emitModuleNames = false;

src/tools/wasm-split/wasm-split.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,14 @@ void adjustTableSize(Module& wasm, int initialSize, bool secondary = false) {
9595
void writeModule(Module& wasm,
9696
std::string filename,
9797
const WasmSplitOptions& options) {
98+
if (options.stripDebug) {
99+
PassRunner runner(&wasm, options.passOptions);
100+
runner.add("strip-debug");
101+
runner.run();
102+
}
98103
ModuleWriter writer(options.passOptions);
99104
writer.setBinary(options.emitBinary);
100-
writer.setDebugInfo(options.passOptions.debugInfo);
105+
writer.setDebugInfo(options.passOptions.debugInfo && !options.stripDebug);
101106
if (options.emitModuleNames) {
102107
writer.setEmitModuleName(true);
103108
}

test/lit/help/wasm-split.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@
153153
;; CHECK-NEXT: names section in wasm binary (or full
154154
;; CHECK-NEXT: debuginfo in wast)
155155
;; CHECK-NEXT:
156+
;; CHECK-NEXT: --strip-debug [split, multi-split, instrument] Strip
157+
;; CHECK-NEXT: debug info (including the names section)
158+
;; CHECK-NEXT:
156159
;; CHECK-NEXT: --output,-o [instrument, merge-profiles, multi-split]
157160
;; CHECK-NEXT: Output file.
158161
;; CHECK-NEXT:
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
;; RUN: wasm-split %s --keep-funcs=foo -o1 %t.1.wasm -o2 %t.2.wasm -g --strip-debug
2+
;; RUN: wasm-dis %t.1.wasm | filecheck %s --check-prefix=PRIMARY
3+
;; RUN: wasm-dis %t.2.wasm | filecheck %s --check-prefix=SECONDARY
4+
5+
;; Check that names are stripped from the output.
6+
;; PRIMARY-NOT: $foo
7+
;; SECONDARY-NOT: $bar
8+
9+
;; PRIMARY: (module
10+
;; PRIMARY-NEXT: (type $0 (func))
11+
;; PRIMARY-NEXT: (import "placeholder.deferred" "0" (func $fimport$0))
12+
;; PRIMARY-NEXT: (table $0 1 funcref)
13+
;; PRIMARY-NEXT: (elem $0 (i32.const 0) $fimport$0)
14+
;; PRIMARY-NEXT: (export "table" (table $0))
15+
;; PRIMARY-NEXT: (func $0
16+
;; PRIMARY-NEXT: (call_indirect (type $0)
17+
;; PRIMARY-NEXT: (i32.const 0)
18+
;; PRIMARY-NEXT: )
19+
;; PRIMARY-NEXT: )
20+
;; PRIMARY-NEXT: )
21+
22+
;; SECONDARY: (module
23+
;; SECONDARY-NEXT: (type $0 (func))
24+
;; SECONDARY-NEXT: (import "primary" "table" (table $timport$0 1 funcref))
25+
;; SECONDARY-NEXT: (elem $0 (i32.const 0) $0)
26+
;; SECONDARY-NEXT: (func $0
27+
;; SECONDARY-NEXT: (nop)
28+
;; SECONDARY-NEXT: )
29+
;; SECONDARY-NEXT: )
30+
31+
(module
32+
(func $foo
33+
(call $bar)
34+
)
35+
(func $bar
36+
(nop)
37+
)
38+
)

0 commit comments

Comments
 (0)