Skip to content

Commit 4ead624

Browse files
authored
[wasm-split] Allow --import-namespace in --multi-split mode (#7758)
Fixes #7721.
1 parent 70fca92 commit 4ead624

File tree

4 files changed

+111
-9
lines changed

4 files changed

+111
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ WasmSplitOptions::WasmSplitOptions()
231231
"module into the secondary module. In instrument mode, refers to the "
232232
"namespace from which to import the secondary memory, if any.",
233233
WasmSplitOption,
234-
{Mode::Split, Mode::Instrument},
234+
{Mode::Split, Mode::Instrument, Mode::MultiSplit},
235235
Options::Arguments::One,
236236
[&](Options* o, const std::string& argument) {
237237
importNamespace = argument;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ void multiSplitModule(const WasmSplitOptions& options) {
416416

417417
ModuleSplitting::Config config;
418418
config.usePlaceholders = false;
419-
config.importNamespace = "";
419+
config.importNamespace = options.importNamespace;
420420
config.minimizeNewExportNames = true;
421421
for (auto& [mod, funcs] : moduleFuncs) {
422422
if (options.verbose) {

test/lit/help/wasm-split.test

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@
7575
;; CHECK-NEXT: --placeholdermap [split] Write a file mapping placeholder
7676
;; CHECK-NEXT: indices to the function names.
7777
;; CHECK-NEXT:
78-
;; CHECK-NEXT: --import-namespace [split, instrument] When provided as an
79-
;; CHECK-NEXT: option for module splitting, the
80-
;; CHECK-NEXT: namespace from which to import objects
81-
;; CHECK-NEXT: from the primary module into the
82-
;; CHECK-NEXT: secondary module. In instrument mode,
83-
;; CHECK-NEXT: refers to the namespace from which to
84-
;; CHECK-NEXT: import the secondary memory, if any.
78+
;; CHECK-NEXT: --import-namespace [split, instrument, multi-split] When
79+
;; CHECK-NEXT: provided as an option for module
80+
;; CHECK-NEXT: splitting, the namespace from which to
81+
;; CHECK-NEXT: import objects from the primary module
82+
;; CHECK-NEXT: into the secondary module. In instrument
83+
;; CHECK-NEXT: mode, refers to the namespace from which
84+
;; CHECK-NEXT: to import the secondary memory, if any.
8585
;; CHECK-NEXT:
8686
;; CHECK-NEXT: --placeholder-namespace [split] The namespace from which to
8787
;; CHECK-NEXT: import placeholder functions into the

test/lit/wasm-split/multi-split.wast

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
;; RUN: wasm-dis %t1.wasm | filecheck %s --check-prefix=CHECK-A
66
;; RUN: wasm-dis %t2.wasm | filecheck %s --check-prefix=CHECK-B
77
;; RUN: wasm-dis %t3.wasm | filecheck %s --check-prefix=CHECK-C
8+
;;
9+
;; Check if --import-namespace option works.
10+
;; RUN: wasm-split -all -g --multi-split %s --manifest %s.manifest --out-prefix=%t --import-namespace=custom_env -o %t.wasm
11+
;; RUN: wasm-dis %t1.wasm | filecheck %s --check-prefix=CHECK-A-NS
12+
;; RUN: wasm-dis %t2.wasm | filecheck %s --check-prefix=CHECK-B-NS
13+
;; RUN: wasm-dis %t3.wasm | filecheck %s --check-prefix=CHECK-C-NS
814

915
(module
1016
;; PRIMARY: (type $ret-i64 (func (result i64)))
@@ -46,6 +52,38 @@
4652
;; CHECK-A-NEXT: )
4753
;; CHECK-A-NEXT: (i32.const 0)
4854
;; CHECK-A-NEXT: )
55+
;; CHECK-A-NS: (type $0 (func (result i64)))
56+
57+
;; CHECK-A-NS: (type $1 (func (result f32)))
58+
59+
;; CHECK-A-NS: (type $2 (func (result i32)))
60+
61+
;; CHECK-A-NS: (import "custom_env" "c" (table $timport$0 1 funcref))
62+
63+
;; CHECK-A-NS: (import "custom_env" "a" (func $B (result i64)))
64+
65+
;; CHECK-A-NS: (import "custom_env" "b" (func $C (result f32)))
66+
67+
;; CHECK-A-NS: (elem $0 (i32.const 0) $A)
68+
69+
;; CHECK-A-NS: (func $A (result i32)
70+
;; CHECK-A-NS-NEXT: (drop
71+
;; CHECK-A-NS-NEXT: (call_ref $2
72+
;; CHECK-A-NS-NEXT: (ref.func $A)
73+
;; CHECK-A-NS-NEXT: )
74+
;; CHECK-A-NS-NEXT: )
75+
;; CHECK-A-NS-NEXT: (drop
76+
;; CHECK-A-NS-NEXT: (call_ref $0
77+
;; CHECK-A-NS-NEXT: (ref.func $B)
78+
;; CHECK-A-NS-NEXT: )
79+
;; CHECK-A-NS-NEXT: )
80+
;; CHECK-A-NS-NEXT: (drop
81+
;; CHECK-A-NS-NEXT: (call_ref $1
82+
;; CHECK-A-NS-NEXT: (ref.func $C)
83+
;; CHECK-A-NS-NEXT: )
84+
;; CHECK-A-NS-NEXT: )
85+
;; CHECK-A-NS-NEXT: (i32.const 0)
86+
;; CHECK-A-NS-NEXT: )
4987
(func $A (type $ret-i32) (result i32)
5088
(drop
5189
(call_ref $ret-i32
@@ -96,6 +134,38 @@
96134
;; CHECK-B-NEXT: )
97135
;; CHECK-B-NEXT: (i64.const 0)
98136
;; CHECK-B-NEXT: )
137+
;; CHECK-B-NS: (type $0 (func (result f32)))
138+
139+
;; CHECK-B-NS: (type $1 (func (result i32)))
140+
141+
;; CHECK-B-NS: (type $2 (func (result i64)))
142+
143+
;; CHECK-B-NS: (import "custom_env" "e" (table $timport$0 1 funcref))
144+
145+
;; CHECK-B-NS: (import "custom_env" "b" (func $C (result f32)))
146+
147+
;; CHECK-B-NS: (import "custom_env" "d" (func $fimport$1 (result i32)))
148+
149+
;; CHECK-B-NS: (elem $0 (i32.const 0) $B)
150+
151+
;; CHECK-B-NS: (func $B (result i64)
152+
;; CHECK-B-NS-NEXT: (drop
153+
;; CHECK-B-NS-NEXT: (call_ref $1
154+
;; CHECK-B-NS-NEXT: (ref.func $fimport$1)
155+
;; CHECK-B-NS-NEXT: )
156+
;; CHECK-B-NS-NEXT: )
157+
;; CHECK-B-NS-NEXT: (drop
158+
;; CHECK-B-NS-NEXT: (call_ref $2
159+
;; CHECK-B-NS-NEXT: (ref.func $B)
160+
;; CHECK-B-NS-NEXT: )
161+
;; CHECK-B-NS-NEXT: )
162+
;; CHECK-B-NS-NEXT: (drop
163+
;; CHECK-B-NS-NEXT: (call_ref $0
164+
;; CHECK-B-NS-NEXT: (ref.func $C)
165+
;; CHECK-B-NS-NEXT: )
166+
;; CHECK-B-NS-NEXT: )
167+
;; CHECK-B-NS-NEXT: (i64.const 0)
168+
;; CHECK-B-NS-NEXT: )
99169
(func $B (type $ret-i64) (result i64)
100170
(drop
101171
(call_ref $ret-i32
@@ -146,6 +216,38 @@
146216
;; CHECK-C-NEXT: )
147217
;; CHECK-C-NEXT: (f32.const 0)
148218
;; CHECK-C-NEXT: )
219+
;; CHECK-C-NS: (type $0 (func (result i32)))
220+
221+
;; CHECK-C-NS: (type $1 (func (result i64)))
222+
223+
;; CHECK-C-NS: (type $2 (func (result f32)))
224+
225+
;; CHECK-C-NS: (import "custom_env" "g" (table $timport$0 1 funcref))
226+
227+
;; CHECK-C-NS: (import "custom_env" "d" (func $fimport$0 (result i32)))
228+
229+
;; CHECK-C-NS: (import "custom_env" "f" (func $fimport$1 (result i64)))
230+
231+
;; CHECK-C-NS: (elem $0 (i32.const 0) $C)
232+
233+
;; CHECK-C-NS: (func $C (result f32)
234+
;; CHECK-C-NS-NEXT: (drop
235+
;; CHECK-C-NS-NEXT: (call_ref $0
236+
;; CHECK-C-NS-NEXT: (ref.func $fimport$0)
237+
;; CHECK-C-NS-NEXT: )
238+
;; CHECK-C-NS-NEXT: )
239+
;; CHECK-C-NS-NEXT: (drop
240+
;; CHECK-C-NS-NEXT: (call_ref $1
241+
;; CHECK-C-NS-NEXT: (ref.func $fimport$1)
242+
;; CHECK-C-NS-NEXT: )
243+
;; CHECK-C-NS-NEXT: )
244+
;; CHECK-C-NS-NEXT: (drop
245+
;; CHECK-C-NS-NEXT: (call_ref $2
246+
;; CHECK-C-NS-NEXT: (ref.func $C)
247+
;; CHECK-C-NS-NEXT: )
248+
;; CHECK-C-NS-NEXT: )
249+
;; CHECK-C-NS-NEXT: (f32.const 0)
250+
;; CHECK-C-NS-NEXT: )
149251
(func $C (type $ret-f32) (result f32)
150252
(drop
151253
(call_ref $ret-i32

0 commit comments

Comments
 (0)