Open kichikuou opened 1 week ago
Asyncify runs after function inlining. You can use ASYNCIFY_ADVISE
to tell you which functions would be instrumented without ASYNCIFY_IGNORE_INDIRECT=1
at the specified optimisation level, but it can't be relied upon for other optimisation levels.
I'd recommend running first with: -O1 -sASYNCIFY=1 -sASYNCIFY_ADVISE=1
. That will tell you which functions have indirect function calls, which should include main
if my_sleep
is being inlined.
(I'm assuming that my_sleep
can still be inlined despite it being defined with EMSCRIPTEN_KEEPALIVE
. If that's not the case, then I don't have an explanation for why main
isn't being propagated.)
Thank you for the explanation. Based on the documentation, this behavior still appears to deviate from what is expected, so I continue to believe this might be a bug.
While unexpected, I don't think it's a bug. If main
never calls my_sleep
, then my_sleep
's instrumentation status can't be propagated to it.
The docs do say:
You can enable the ASYNCIFY_ADVISE setting, which will tell the compiler to output which functions it is currently instrumenting and why. You can then determine whether you should add any functions to ASYNCIFY_REMOVE or whether it would be safe to enable ASYNCIFY_IGNORE_INDIRECT. Note that this phase of the compiler happens after many optimization phases, and several functions maybe be inlined already. To be safe, run it with -O0.
Which I think is misleading advice... because of inlining you really need to do the analysis on the final optimisation level you intend to do. (Haha, I just went digging and see that I wrote that paragraph of the docs! I should submit a PR to update it.)
asyncify_test.c
:Note that
main()
is not instrumented even thoughASYNCIFY_PROPAGATE_ADD
is enabled.The generated
asyncify_test.js
causes an error when executed:It works as expected when built with
-O0
:Removing
-sASYNCIFY_IGNORE_INDIRECT=1
also fixes the issue.