-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid proxying atexit calls back to main thread. (#15905)
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
- Loading branch information
Showing
16 changed files
with
100 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright 2022 The Emscripten Authors. All rights reserved. | ||
* Emscripten is available under two separate licenses, the MIT license and the | ||
* University of Illinois/NCSA Open Source License. Both these licenses can be | ||
* found in the LICENSE file. | ||
*/ | ||
|
||
// Stub implementations of atexit function. These will be included | ||
// in favor of the regular ones in system/lib/libc/musl/src/exit/atexit.c | ||
// when EXIT_RUNTIME == 0. | ||
|
||
#include <stdlib.h> | ||
|
||
int atexit(void (*function)(void)) { return 0; } | ||
|
||
int __cxa_atexit(void (*func)(void *), void *arg, void *dso) { return 0; } | ||
|
||
void __cxa_finalize(void *dso) { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
98361 | ||
98236 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
__cxa_atexit | ||
abort | ||
emscripten_memcpy_big | ||
emscripten_resize_heap | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
111833 | ||
111708 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
__cxa_allocate_exception | ||
__cxa_atexit | ||
__cxa_begin_catch | ||
__cxa_end_catch | ||
__cxa_find_matching_catch_2 | ||
|
2 changes: 1 addition & 1 deletion
2
tests/other/metadce/hello_libcxx_O2_fexceptions_DEMANGLE_SUPPORT.jssize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
112820 | ||
112695 |
1 change: 0 additions & 1 deletion
1
tests/other/metadce/hello_libcxx_O2_fexceptions_DEMANGLE_SUPPORT.sent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
__cxa_allocate_exception | ||
__cxa_atexit | ||
__cxa_begin_catch | ||
__cxa_end_catch | ||
__cxa_find_matching_catch_2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <stdatomic.h> | ||
#include <stdbool.h> | ||
#include <pthread.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <emscripten/console.h> | ||
|
||
_Atomic bool done = false; | ||
|
||
void exit_handler() { | ||
printf("exit_handler\n"); | ||
} | ||
|
||
void* thread_main(void*) { | ||
// Avoid using printf here since stdio is proxied back to the | ||
// main thread which is busy looping | ||
_emscripten_out("in thread"); | ||
atexit(exit_handler); | ||
done = true; | ||
return NULL; | ||
} | ||
|
||
// Similar to test_pthread_busy_wait.cpp but with lower level pthreads | ||
// API and explcit use of atexit before setting done to true. | ||
// We also don't make any calls during the busy loop which means that | ||
// proxied calls are *not* processed. | ||
int main() { | ||
printf("in main\n"); | ||
pthread_t t; | ||
pthread_create(&t, NULL, thread_main, NULL); | ||
|
||
while (!done) { } | ||
|
||
pthread_join(t, NULL); | ||
printf("done main\n"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
in main | ||
in thread | ||
done main | ||
exit_handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters