-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
d2482b7
commit 614d783
Showing
3 changed files
with
20 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,6 +276,7 @@ _exit | |
_flushlbf | ||
_initialize | ||
_start | ||
_start | ||
a64l | ||
abort | ||
abs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#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); | ||
} | ||
} |