File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -48,8 +48,19 @@ struct RemoveImports : public WalkerPass<PostWalker<RemoveImports>> {
4848 std::vector<Name> names;
4949 ModuleUtils::iterImportedFunctions (
5050 *curr, [&](Function* func) { names.push_back (func->name ); });
51+ // Do not remove names referenced in a table
52+ std::set<Name> indirectNames;
53+ if (curr->table .exists ) {
54+ for (auto & segment : curr->table .segments ) {
55+ for (auto & name : segment.data ) {
56+ indirectNames.insert (name);
57+ }
58+ }
59+ }
5160 for (auto & name : names) {
52- curr->removeFunction (name);
61+ if (indirectNames.find (name) == indirectNames.end ()) {
62+ curr->removeFunction (name);
63+ }
5364 }
5465 }
5566};
Original file line number Diff line number Diff line change 22 (type $FUNCSIG$v (func))
33 (type $FUNCSIG$i (func (result i32)))
44 (type $FUNCSIG$d (func (result f64)))
5+ (import "env" "table" (table $0 1 1 funcref))
6+ (elem (i32.const 0) $waka-sneaky)
57 (import "env" "memBase" (global $import$global0 i32))
8+ (import "somewhere" "waka-sneaky" (func $waka-sneaky))
69 (memory $0 1024 1024)
7- (func $nada (; 0 ;) (type $FUNCSIG$v)
10+ (func $nada (; 1 ;) (type $FUNCSIG$v)
811 (nop)
912 (drop
1013 (i32.const 0)
1114 )
1215 (drop
1316 (f64.const 0)
1417 )
18+ (call_indirect (type $FUNCSIG$v)
19+ (i32.const 0)
20+ )
1521 )
1622)
Original file line number Diff line number Diff line change 66 (import $waka " somewhere" " waka" )
77 (import $waka-ret " somewhere" " waka-ret" (result i32 ))
88 (import $waka-ret-d " somewhere" " waka-ret-d" (result f64 ))
9+ (import $waka-sneaky " somewhere" " waka-sneaky" )
910 (import " env" " memBase" (global i32 ))
11+ (import " env" " table" (table $table 1 1 funcref ))
12+ (elem (i32.const 0 ) $waka-sneaky )
1013 (func $nada (type $FUNCSIG$v )
1114 (call $waka )
1215 (drop
1518 (drop
1619 (call $waka-ret-d )
1720 )
21+ (call_indirect (i32.const 0 ))
1822 )
1923)
You can’t perform that action at this time.
0 commit comments