@@ -344,6 +344,11 @@ def get_binaryen_passes(options):
344344 # safe heap must run before post-emscripten, so post-emscripten can apply the sbrk ptr
345345 if settings .SAFE_HEAP :
346346 passes += ['--safe-heap' ]
347+ if settings .EMULATE_FUNCTION_POINTER_CASTS :
348+ # fpcast-emu must run before -Ox so that directize (inside -Ox) sees
349+ # the rewritten table entries with matching types. It must also run
350+ # before asyncify so the byn$fpcast-emu thunks get instrumented.
351+ passes += ['--fpcast-emu' ]
347352 if optimizing :
348353 # wasm-emscripten-finalize will strip the features section for us
349354 # automatically, but if we did not modify the wasm then we didn't run it,
@@ -372,11 +377,6 @@ def get_binaryen_passes(options):
372377 # legalize it again now, as the instrumentation may need it
373378 passes += ['--legalize-js-interface' ]
374379 passes += building .js_legalization_pass_flags ()
375- if settings .EMULATE_FUNCTION_POINTER_CASTS :
376- # note that this pass must run before asyncify, as if it runs afterwards we only
377- # generate the byn$fpcast_emu functions after asyncify runs, and so we wouldn't
378- # be able to further process them.
379- passes += ['--fpcast-emu' ]
380380 if settings .ASYNCIFY == 1 :
381381 passes += ['--asyncify' ]
382382 if settings .MAIN_MODULE :
0 commit comments