-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use musl/native version of atexit
#15905
Conversation
e89185d
to
ee67165
Compare
7215d83
to
76e5833
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the PR title could be "Move atexit() to C, and run them on each thread" or such?
But the atexit function still only run on the main thread. I will update the title though. |
atexit
7e6b02c
to
129fe7e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good idea to link in stubs for atexit. Yes, I think that's the right approach.
lgtm, but also please delete these 2 lines:
Lines 540 to 541 in 8988358
if not settings.EXIT_RUNTIME: | |
passes += ['--no-exit-runtime'] |
That pass removes calls to atexit as JS imports. Now that we have no more JS imports for them it does not do anything. We can remove it from Binaryen after this lands actually.
To achieve this we manage the `atexit` functions in native code using existing musl code. This is small step towards a large change to just use musl for all `atexit` handling: #14479. The codesize implications of this change are a mixed bag. In some places we see saving but in other cases the extra export causes a small regression (only when EXIT_RUNTIME=1). In the long, once we land #14479 there should be more code size saving to be had by doing everything on the native side. Fixes #15868
129fe7e
to
217252a
Compare
Since emscripten-core/emscripten#15905 landed emscripten now includes its own dummy atexit function when building with EXIT_RUNTIME=0. This dummy function conflicts with the emscripten-provided one: ``` wasm-ld: error: duplicate symbol: atexit >>> defined in CMakeFiles/binaryen_wasm.dir/src/binaryen-c.cpp.o >>> defined in ...wasm32-emscripten/lto/libnoexit.a(atexit_dummy.o) ``` Normally overriding symbols from libc does not causes issues but one needs to be sure to override all the symbols in a given object file so that the object in question (atexit_dummy.o) does not get linked in. In this case some other symbol being defined in in atexit_dummy.o (e.g. __cxa_atexit) is likely the cause of the conflict. Overriding symbols from libc is likely to break in this way as the libc evolves, and since emscripten is now providing a dummy, just as we want, its better/safer to simply remove our dummy.
Since emscripten-core/emscripten#15905 landed emscripten now includes its own dummy atexit function when building with EXIT_RUNTIME=0. This dummy function conflicts with the emscripten-provided one: ``` wasm-ld: error: duplicate symbol: atexit >>> defined in CMakeFiles/binaryen_wasm.dir/src/binaryen-c.cpp.o >>> defined in ...wasm32-emscripten/lto/libnoexit.a(atexit_dummy.o) ``` Normally overriding symbols from libc does not causes issues but one needs to be sure to override all the symbols in a given object file so that the object in question (atexit_dummy.o) does not get linked in. In this case some other symbol being defined in in atexit_dummy.o (e.g. __cxa_atexit) is likely the cause of the conflict. Overriding symbols from libc is likely to break in this way as the libc evolves, and since emscripten is now providing a dummy, just as we want, its better/safer to simply remove our dummy.
After emscripten-core/emscripten#15905 lands Emscripten will no longer use it, and nothing else needs it AFAIK.
Runtime callbacks can only be functions, not numbers. In the past we used to handle C atexit using this mechansim which is why this used to be needed but that changd in #15905.
Runtime callbacks can only be functions, not numbers. In the past we used to handle C atexit using this mechansim which is why this used to be needed but that changd in #15905.
Runtime callbacks can only be functions, not numbers. In the past we used to handle C atexit using this mechansim which is why this used to be needed but that changd in #15905.
This implementation uses shared memory to store the list of
atexit
functionsand avoids proxying
atexit
calls back to main thread.This is small step towards a large change to just use musl for all
atexit
handling: #14479.The codesize implications of this change are a mixed bag. In some
places we see saving but in other cases the extra export causes a small
regression (only when
EXIT_RUNTIME=1
). In the long, once we land #14479there should be more code size saving to be had by doing everything on
the native side.
Fixes #15868