Skip to content

Commit 71d07cb

Browse files
committed
New-style command support.
This enables [new-style command support]. Instead of calling `__wasm_call_ctors` and `__wasm_call_dtors` directly, this lets wasm-ld automatically call them. [new-style command support]: https://reviews.llvm.org/D81689
1 parent 4e45d2b commit 71d07cb

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

libc-bottom-half/crt/crt1.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,17 @@
22
extern void __wasm_call_ctors(void);
33
extern int __original_main(void);
44
extern void __wasm_call_dtors(void);
5+
_Noreturn void exit(int);
56

67
__attribute__((export_name("_start")))
78
void _start(void) {
8-
// The linker synthesizes this to call constructors.
9-
__wasm_call_ctors();
10-
119
// Call `__original_main` which will either be the application's zero-argument
1210
// `__original_main` function or a libc routine which calls `__main_void`.
1311
// TODO: Call `main` directly once we no longer have to support old compilers.
1412
int r = __original_main();
1513

16-
// Call atexit functions, destructors, stdio cleanup, etc.
17-
__wasm_call_dtors();
18-
19-
// If main exited successfully, just return, otherwise call
20-
// `__wasi_proc_exit`.
14+
// If main exited successfully, just return, otherwise call `exit`.
2115
if (r != 0) {
22-
__wasi_proc_exit(r);
16+
exit(r);
2317
}
2418
}

0 commit comments

Comments
 (0)