mirror of
https://git.proxmox.com/git/wasi-libc
synced 2025-11-02 17:47:23 +00:00
This adds a new crt1-command.c startup file, which uses [new-style command support]. Instead of calling `__wasm_call_ctors` and `__wasm_call_dtors` directly, this lets wasm-ld automatically call them. This preserves the existing crt1.c, so that the same wasi-libc build can support old-style and new-style commands, for compatibility during the transition. [new-style command support]: https://reviews.llvm.org/D81689 Co-authored-by: Dan Gohman <sunfish@mozilla.com>
19 lines
602 B
C
19 lines
602 B
C
#include <wasi/api.h>
|
|
#include <stdlib.h>
|
|
extern void __wasm_call_ctors(void);
|
|
extern int __original_main(void);
|
|
extern void __wasm_call_dtors(void);
|
|
|
|
__attribute__((export_name("_start")))
|
|
void _start(void) {
|
|
// 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();
|
|
|
|
// If main exited successfully, just return, otherwise call `exit`.
|
|
if (r != 0) {
|
|
exit(r);
|
|
}
|
|
}
|