|
15 | 15 | #define __WIZER_EXTERN_C extern
|
16 | 16 | #endif
|
17 | 17 |
|
| 18 | +#ifdef __clang_major__ |
| 19 | +// wasi-sdk-16 was the first wasi-sdk version that shipped with a version of |
| 20 | +// wasi-libc that did not include __original_main. However, wasi-sdk-15 shipped |
| 21 | +// with clang-14.0.0. To correctly identify the boundary where __original_main |
| 22 | +// no longer exists, we check for either clang-15+ or specifically clang-14.0.4. |
| 23 | +// |
| 24 | +// wasi-sdk-17 ships with clang-15.0.6 |
| 25 | +// wasi-sdk-16 ships with clang-14.0.4 |
| 26 | +#if __clang_major__ >= 15 || (__clang_major__ == 14 && __clang_patchlevel__ == 4) |
| 27 | +#define WIZER_MAIN_VOID __main_void |
| 28 | +#else |
| 29 | +#define WIZER_MAIN_VOID __original_main |
| 30 | +#endif |
| 31 | +#endif |
| 32 | + |
| 33 | +// We default to assuming that the compiler is new enough to provide |
| 34 | +// __main_void. |
| 35 | +#ifndef WIZER_MAIN_VOID |
| 36 | +#define WIZER_MAIN_VOID __main_void |
| 37 | +#endif |
| 38 | + |
18 | 39 | /*
|
19 | 40 | * This macro inserts the exported functions necessary to allow Wizer to
|
20 | 41 | * pre-initialize a Wasm module.
|
|
63 | 84 | #define WIZER_INIT(init_func) \
|
64 | 85 | __WIZER_EXTERN_C void __wasm_call_ctors(); \
|
65 | 86 | __WIZER_EXTERN_C void __wasm_call_dtors(); \
|
66 |
| - __WIZER_EXTERN_C int __main_void(); \ |
| 87 | + __WIZER_EXTERN_C int WIZER_MAIN_VOID(); \ |
67 | 88 | /* This function's export name `wizer.initialize` is specially */ \
|
68 | 89 | /* recognized by Wizer. It is the direct entry point for pre-init. */ \
|
69 | 90 | __attribute__((export_name("wizer.initialize"))) void \
|
|
87 | 108 | /* `main()`. This may change in the future; when it does, we will */ \
|
88 | 109 | /* coordinate with the WASI-SDK toolchain to implement this entry */ \
|
89 | 110 | /* point in an alternate way. */ \
|
90 |
| - __main_void(); \ |
| 111 | + WIZER_MAIN_VOID(); \ |
91 | 112 | /* Because we are replacing `_start()`, we need to manually invoke */ \
|
92 | 113 | /* destructors as well. */ \
|
93 | 114 | __wasm_call_dtors(); \
|
|
0 commit comments