Skip to content

Commit 1b6be6b

Browse files
committed
New-style command support.
This enables [new-style command support]. Instead of calling `__wasm_call_ctors` and `__wasm_call_dtors` directly, this lets wasm-ld automatically call them. And, this comments out a use of "protected" visibility, since [WebAssembly doesn't support it]. [new-style command support]: https://reviews.llvm.org/D81689 [WebAssembly doesn't support it]: https://reviews.llvm.org/D81688
1 parent 4e45d2b commit 1b6be6b

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

libc-bottom-half/crt/crt1.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,17 @@
22
extern void __wasm_call_ctors(void);
33
extern int __original_main(void);
44
extern void __wasm_call_dtors(void);
5+
_Noreturn void exit(int);
56

67
__attribute__((export_name("_start")))
78
void _start(void) {
8-
// The linker synthesizes this to call constructors.
9-
__wasm_call_ctors();
10-
119
// Call `__original_main` which will either be the application's zero-argument
1210
// `__original_main` function or a libc routine which calls `__main_void`.
1311
// TODO: Call `main` directly once we no longer have to support old compilers.
1412
int r = __original_main();
1513

16-
// Call atexit functions, destructors, stdio cleanup, etc.
17-
__wasm_call_dtors();
18-
19-
// If main exited successfully, just return, otherwise call
20-
// `__wasi_proc_exit`.
14+
// If main exited successfully, just return, otherwise call `exit`.
2115
if (r != 0) {
22-
__wasi_proc_exit(r);
16+
exit(r);
2317
}
2418
}

libc-top-half/musl/src/internal/stdio_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ hidden int __towrite(FILE *);
8989
hidden void __stdio_exit(void);
9090
hidden void __stdio_exit_needed(void);
9191

92+
#ifdef __wasilibc_unmodified_upstream // wasm has no "protected" visibility
9293
#if defined(__PIC__) && (100*__GNUC__+__GNUC_MINOR__ >= 303)
9394
__attribute__((visibility("protected")))
9495
#endif
96+
#endif
9597
int __overflow(FILE *, int), __uflow(FILE *);
9698

9799
hidden int __fseeko(FILE *, off_t, int);

0 commit comments

Comments
 (0)