Skip to content
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

Merged
merged 1 commit into from
Jan 7, 2022
Merged

Use musl/native version of atexit #15905

merged 1 commit into from
Jan 7, 2022

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Jan 7, 2022

This implementation uses shared memory to store the list of atexit functions
and 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 #14479
there should be more code size saving to be had by doing everything on
the native side.

Fixes #15868

Copy link
Member

@kripken kripken left a 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?

emcc.py Show resolved Hide resolved
@sbc100
Copy link
Collaborator Author

sbc100 commented Jan 7, 2022

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.

@sbc100 sbc100 changed the title Avoid proxying atexit calls back to main thread. Use musl/native version of atexit Jan 7, 2022
@sbc100 sbc100 requested a review from kripken January 7, 2022 16:30
emcc.py Show resolved Hide resolved
tests/other/metadce/hello_libcxx_O2.size Outdated Show resolved Hide resolved
tests/pthread/test_pthread_busy_wait_atexit.cpp Outdated Show resolved Hide resolved
@sbc100 sbc100 force-pushed the atexit_no_proxy branch 5 times, most recently from 7e6b02c to 129fe7e Compare January 7, 2022 19:01
Copy link
Member

@kripken kripken left a 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:

emscripten/emcc.py

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
@sbc100 sbc100 enabled auto-merge (squash) January 7, 2022 20:18
@sbc100 sbc100 merged commit 250e9e1 into main Jan 7, 2022
@sbc100 sbc100 deleted the atexit_no_proxy branch January 7, 2022 21:58
sbc100 added a commit to WebAssembly/binaryen that referenced this pull request Jan 8, 2022
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.
sbc100 added a commit to WebAssembly/binaryen that referenced this pull request Jan 9, 2022
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.
kripken added a commit to WebAssembly/binaryen that referenced this pull request Jan 26, 2022
After emscripten-core/emscripten#15905 lands Emscripten will no longer use it,
and nothing else needs it AFAIK.
sbc100 added a commit that referenced this pull request Jun 23, 2022
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.
sbc100 added a commit that referenced this pull request Jun 23, 2022
Followup to #17303.

The last usage of the func/arg type of callback was removed in #15905
and I don't think we ever advertised this as part of the API.
sbc100 added a commit that referenced this pull request Jun 23, 2022
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.
sbc100 added a commit that referenced this pull request Jun 23, 2022
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.
sbc100 added a commit that referenced this pull request Jun 23, 2022
Followup to #17303.

The last usage of the func/arg type of callback was removed in #15905
and I don't think we ever advertised this as part of the API.
sbc100 added a commit that referenced this pull request Jun 23, 2022
Followup to #17303.

The last usage of the func/arg type of callback was removed in #15905
and I don't think we ever advertised this as part of the API.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

thread can't spawn synchronously even with PTHREAD_POOL_SIZE=4
2 participants