Skip to content

Commit 68f4da9

Browse files
authored
LegalizeAndPruneJSInterface: Prune illegal globals (#8435)
Previously the pass handled only functions. Handling globals will allow more fuzzing of exported globals.
1 parent 6b851ed commit 68f4da9

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/passes/LegalizeJSInterface.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,19 @@ struct LegalizeAndPruneJSInterface : public LegalizeJSInterface {
414414
ReFinalize().run(getPassRunner(), module);
415415
ReFinalize().runOnModuleCode(getPassRunner(), module);
416416

417-
// TODO: globals etc.
417+
// Globals.
418+
std::vector<Name> illegalExports;
419+
for (auto& exp : module->exports) {
420+
if (exp->kind == ExternalKind::Global) {
421+
auto name = *exp->getInternalName();
422+
if (isIllegal(module->getGlobal(name)->type)) {
423+
illegalExports.push_back(exp->name);
424+
}
425+
}
426+
}
427+
for (auto name : illegalExports) {
428+
module->removeExport(name);
429+
}
418430
}
419431

420432
bool isIllegal(Type type) {

test/lit/passes/legalize-and-prune-js-interface.wast

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,23 @@
245245
;; and also prune the export, so it remains neither an import nor an export.
246246
(export "imported-v128" (func $imported-v128))
247247
)
248+
248249
;; CHECK: (type $0 (func (result v128)))
249250

250251
;; CHECK: (func $imported-v128 (type $0) (result v128)
251252
;; CHECK-NEXT: (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000)
252253
;; CHECK-NEXT: )
254+
(module
255+
;; CHECK: (global $i32 i32 (i32.const 42))
256+
(global $i32 i32 (i32.const 42))
257+
258+
;; CHECK: (global $v128 v128 (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000))
259+
(global $v128 v128 (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000))
260+
261+
;; The illegal export will vanish, but not the legal one.
262+
263+
(export "illegal" (global $v128))
264+
;; CHECK: (export "legal" (global $i32))
265+
(export "legal" (global $i32))
266+
)
267+

0 commit comments

Comments
 (0)