mirror of
https://git.proxmox.com/git/wasi-libc
synced 2025-07-14 20:52:52 +00:00

This adds support for the `__main_argc_argv` change, while preserving compatibility with `__original_main`. This is needed by the LTO build because the `__original_main` hack works in LLVM codegen, which is after LTO. The `__main_argc_argv` change is implemented in clang, which makes it properly visible to LTO.
24 lines
748 B
C
24 lines
748 B
C
#include <wasi/api.h>
|
|
extern void __wasm_call_ctors(void);
|
|
extern int __original_main(void);
|
|
extern void __prepare_for_exit(void);
|
|
|
|
void _start(void) {
|
|
// The linker synthesizes this to call constructors.
|
|
__wasm_call_ctors();
|
|
|
|
// Call `__original_main` which will either be the application's zero-argument
|
|
// `__original_main` function or a libc routine which calls `__main_void`.
|
|
// TODO: Call `main` directly once we no longer have to support old compilers.
|
|
int r = __original_main();
|
|
|
|
// Call atexit functions, destructors, stdio cleanup, etc.
|
|
__prepare_for_exit();
|
|
|
|
// If main exited successfully, just return, otherwise call
|
|
// `__wasi_proc_exit`.
|
|
if (r != 0) {
|
|
__wasi_proc_exit(r);
|
|
}
|
|
}
|