wasi-libc/libc-bottom-half/crt/crt1-command.c
Dan Gohman 614d783e92
New-style command support. (#203)
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>
2020-10-03 14:18:39 -07:00

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);
}
}