Skip to content

Commit 6b851ed

Browse files
authored
StubUnsupportedJSOps: Remove global exports (#8436)
This pass removes things we can't handle in wasm2js, and globals are such a feature: wasm2js emits them in a partial way (it emits simple fake objects, which are not actually WebAssembly.Global instances, and can mix up the fuzzer). Note that this pass is only used in the fuzzer - it is not part of wasm2js's normal pipeline, so this does not affect any production workload. Also, this PR makes the pass non-parallel (it is just easier), but that also is not a problem for this reason. Doing this will allow fuzzing more global things (this will avoid breakage in wasm2js).
1 parent d1cd2cf commit 6b851ed

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

src/passes/RemoveNonJSOps.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,6 @@ struct RemoveNonJSOpsPass : public WalkerPass<PostWalker<RemoveNonJSOpsPass>> {
337337

338338
struct StubUnsupportedJSOpsPass
339339
: public WalkerPass<PostWalker<StubUnsupportedJSOpsPass>> {
340-
bool isFunctionParallel() override { return true; }
341-
342-
std::unique_ptr<Pass> create() override {
343-
return std::make_unique<StubUnsupportedJSOpsPass>();
344-
}
345340

346341
void visitUnary(Unary* curr) {
347342
switch (curr->op) {
@@ -386,6 +381,21 @@ struct StubUnsupportedJSOpsPass
386381
}
387382
replaceCurrent(replacement);
388383
}
384+
385+
void visitModule(Module* module) {
386+
// We remove global exports, as wasm2js doesn't emit them in a fully
387+
// compatible form yet (they aren't instances of WebAssembly.Global).
388+
// Globals.
389+
std::vector<Name> badExports;
390+
for (auto& exp : module->exports) {
391+
if (exp->kind == ExternalKind::Global) {
392+
badExports.push_back(exp->name);
393+
}
394+
}
395+
for (auto name : badExports) {
396+
module->removeExport(name);
397+
}
398+
}
389399
};
390400

391401
Pass* createRemoveNonJSOpsPass() { return new RemoveNonJSOpsPass(); }
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
2+
3+
;; RUN: foreach %s %t wasm-opt -all --stub-unsupported-js -S -o - | filecheck %s
4+
5+
;; We should remove global exports, as wasm2js doesn't emit them in a fully
6+
;; compatible form yet (they aren't instances of WebAssembly.Global). All the
7+
;; global exports below should vanish, but not the function export.
8+
9+
(module
10+
;; CHECK: (type $0 (func))
11+
12+
;; CHECK: (global $i32 i32 (i32.const 42))
13+
(global $i32 i32 (i32.const 42))
14+
15+
;; CHECK: (global $v128 v128 (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000))
16+
(global $v128 v128 (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000))
17+
18+
(export "bad1" (global $v128))
19+
20+
(export "bad2" (global $i32))
21+
22+
;; CHECK: (export "good" (func $func))
23+
(export "good" (func $func))
24+
25+
;; CHECK: (func $func (type $0)
26+
;; CHECK-NEXT: )
27+
(func $func
28+
)
29+
)
30+

0 commit comments

Comments
 (0)