diff --git a/libc-bottom-half/crt/crt1-command.c b/libc-bottom-half/crt/crt1-command.c index 706ab97e..b3906dc5 100644 --- a/libc-bottom-half/crt/crt1-command.c +++ b/libc-bottom-half/crt/crt1-command.c @@ -1,18 +1,24 @@ #include -#include extern void __wasm_call_ctors(void); extern int __main_void(void); extern void __wasm_call_dtors(void); __attribute__((export_name("_start"))) void _start(void) { + // The linker synthesizes this to call constructors. + __wasm_call_ctors(); + // Call `__main_void` which will either be the application's zero-argument // `__main_void` function or a libc routine which obtains the command-line // arguments and calls `__main_argv_argc`. int r = __main_void(); - // If main exited successfully, just return, otherwise call `exit`. + // Call atexit functions, destructors, stdio cleanup, etc. + __wasm_call_dtors(); + + // If main exited successfully, just return, otherwise call + // `__wasi_proc_exit`. if (r != 0) { - exit(r); + __wasi_proc_exit(r); } } diff --git a/libc-bottom-half/crt/crt1.c b/libc-bottom-half/crt/crt1.c index b3906dc5..039c0194 100644 --- a/libc-bottom-half/crt/crt1.c +++ b/libc-bottom-half/crt/crt1.c @@ -1,24 +1,3 @@ -#include -extern void __wasm_call_ctors(void); -extern int __main_void(void); -extern void __wasm_call_dtors(void); - -__attribute__((export_name("_start"))) -void _start(void) { - // The linker synthesizes this to call constructors. - __wasm_call_ctors(); - - // Call `__main_void` which will either be the application's zero-argument - // `__main_void` function or a libc routine which obtains the command-line - // arguments and calls `__main_argv_argc`. - int r = __main_void(); - - // Call atexit functions, destructors, stdio cleanup, etc. - __wasm_call_dtors(); - - // If main exited successfully, just return, otherwise call - // `__wasi_proc_exit`. - if (r != 0) { - __wasi_proc_exit(r); - } -} +// We compile a plain crt1.o for toolchain compatibility, but it's +// identical to crt1-command.o. +#include