|
23 | 23 | // |
24 | 24 | // wasi-sdk-17 ships with clang-15.0.6 |
25 | 25 | // wasi-sdk-16 ships with clang-14.0.4 |
26 | | -#if __clang_major__ >= 15 || (__clang_major__ == 14 && __clang_patchlevel__ == 4) |
| 26 | +#if __clang_major__ >= 15 || \ |
| 27 | + (__clang_major__ == 14 && __clang_patchlevel__ == 4) |
27 | 28 | #define WIZER_MAIN_VOID __main_void |
28 | 29 | #else |
29 | 30 | #define WIZER_MAIN_VOID __original_main |
|
82 | 83 | * should be run), use `WIZER_DEFAULT_INIT()` instead. |
83 | 84 | */ |
84 | 85 | #define WIZER_INIT(init_func) \ |
85 | | - __WIZER_EXTERN_C void __wasm_call_ctors(); \ |
86 | | - __WIZER_EXTERN_C void __wasm_call_dtors(); \ |
87 | | - __WIZER_EXTERN_C void __wasi_proc_exit(int); \ |
88 | | - __WIZER_EXTERN_C int WIZER_MAIN_VOID(); \ |
89 | | - /* This function's export name `wizer.initialize` is specially */ \ |
90 | | - /* recognized by Wizer. It is the direct entry point for pre-init. */ \ |
91 | | - __attribute__((export_name("wizer.initialize"))) void \ |
92 | | - __wizer_initialize() { \ |
93 | | - /* `__wasm_call_ctors()` is generated by `wasm-ld` and invokes all */ \ |
94 | | - /* of the global constructors. It is safe (and in fact necessary) */ \ |
95 | | - /* to manually invoke it here because `wizer.initialize` is the */ \ |
96 | | - /* direct entry point, and no libc startup (crt1.o or equivalent) */ \ |
97 | | - /* is executed before this code does. */ \ |
98 | | - __wasm_call_ctors(); \ |
99 | | - /* We now invoke the provided init function before returning. */ \ |
100 | | - init_func(); \ |
| 86 | + __WIZER_EXTERN_C void __wasm_call_ctors(); \ |
| 87 | + __WIZER_EXTERN_C void __wasm_call_dtors(); \ |
| 88 | + __WIZER_EXTERN_C void __wasi_proc_exit(int); \ |
| 89 | + __WIZER_EXTERN_C int WIZER_MAIN_VOID(); \ |
| 90 | + /* This function's export name `wizer.initialize` is specially */ \ |
| 91 | + /* recognized by Wizer. It is the direct entry point for pre-init. */ \ |
| 92 | + __attribute__((export_name("wizer.initialize"))) void __wizer_initialize() { \ |
| 93 | + /* `__wasm_call_ctors()` is generated by `wasm-ld` and invokes all */ \ |
| 94 | + /* of the global constructors. It is safe (and in fact necessary) */ \ |
| 95 | + /* to manually invoke it here because `wizer.initialize` is the */ \ |
| 96 | + /* direct entry point, and no libc startup (crt1.o or equivalent) */ \ |
| 97 | + /* is executed before this code does. */ \ |
| 98 | + __wasm_call_ctors(); \ |
| 99 | + /* We now invoke the provided init function before returning. */ \ |
| 100 | + init_func(); \ |
| 101 | + } \ |
| 102 | + /* This function replaces `_start` (the WASI-specified entry point) in */ \ |
| 103 | + /* the pre-initialized Wasm module. */ \ |
| 104 | + __attribute__((export_name("wizer.resume"))) void __wizer_resume() { \ |
| 105 | + /* `__main_void()` is defined by the WASI SDK toolchain due to */ \ |
| 106 | + /* special semantics in C/C++ for the `main()` function, i.e., ito */ \ |
| 107 | + /* can either take argc/argv or not. It collects arguments using */ \ |
| 108 | + /* the appropriate WASI calls and then invokes the user program's */ \ |
| 109 | + /* `main()`. This may change in the future; when it does, we will */ \ |
| 110 | + /* coordinate with the WASI-SDK toolchain to implement this entry */ \ |
| 111 | + /* point in an alternate way. */ \ |
| 112 | + int r = WIZER_MAIN_VOID(); \ |
| 113 | + /* Because we are replacing `_start()`, we need to manually invoke */ \ |
| 114 | + /* destructors as well. */ \ |
| 115 | + __wasm_call_dtors(); \ |
| 116 | + /* If main returned non-zero code, call `__wasi_proc_exit`. */ \ |
| 117 | + if (r != 0) { \ |
| 118 | + __wasi_proc_exit(r); \ |
101 | 119 | } \ |
102 | | - /* This function replaces `_start` (the WASI-specified entry point) in */ \ |
103 | | - /* the pre-initialized Wasm module. */ \ |
104 | | - __attribute__((export_name("wizer.resume"))) void __wizer_resume() { \ |
105 | | - /* `__main_void()` is defined by the WASI SDK toolchain due to */ \ |
106 | | - /* special semantics in C/C++ for the `main()` function, i.e., ito */ \ |
107 | | - /* can either take argc/argv or not. It collects arguments using */ \ |
108 | | - /* the appropriate WASI calls and then invokes the user program's */ \ |
109 | | - /* `main()`. This may change in the future; when it does, we will */ \ |
110 | | - /* coordinate with the WASI-SDK toolchain to implement this entry */ \ |
111 | | - /* point in an alternate way. */ \ |
112 | | - int r = WIZER_MAIN_VOID(); \ |
113 | | - /* Because we are replacing `_start()`, we need to manually invoke */ \ |
114 | | - /* destructors as well. */ \ |
115 | | - __wasm_call_dtors(); \ |
116 | | - /* If main returned non-zero code, call `__wasi_proc_exit`. */ \ |
117 | | - if (r != 0) { \ |
118 | | - __wasi_proc_exit(r); \ |
119 | | - } \ |
120 | | - } |
| 120 | + } |
121 | 121 |
|
122 | 122 | /* |
123 | 123 | * This macro is like `WIZER_INIT()`, but takes no initialization function. |
|
126 | 126 | * |
127 | 127 | * See documentation for `WIZER_INIT()` for more details and usage instructions. |
128 | 128 | */ |
129 | | -#define WIZER_DEFAULT_INIT() \ |
130 | | - static void __empty_init() {} \ |
131 | | - WIZER_INIT(__empty_init) |
| 129 | +#define WIZER_DEFAULT_INIT() \ |
| 130 | + static void __empty_init() {} \ |
| 131 | + WIZER_INIT(__empty_init) |
132 | 132 |
|
133 | | -#endif // _WIZER_H_ |
| 133 | +#endif // _WIZER_H_ |
0 commit comments