diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-10-03 00:27:14 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-10-03 00:29:41 -0400 |
| commit | b5054625093ef22b3f228199b6fbf70e1c50b703 (patch) | |
| tree | 09b000d9205b1f378d0d6a78700c3f3b642894d8 /std/special/bootstrap.zig | |
| parent | f1bd02e6f46821415d96f54f6a3258159ba5a9c5 (diff) | |
| download | zig-b5054625093ef22b3f228199b6fbf70e1c50b703.tar.gz zig-b5054625093ef22b3f228199b6fbf70e1c50b703.zip | |
replace __chkstk function with a stub that does not crash
Closes #508
See #302
Diffstat (limited to 'std/special/bootstrap.zig')
| -rw-r--r-- | std/special/bootstrap.zig | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/std/special/bootstrap.zig b/std/special/bootstrap.zig index 3067406431..fea062712b 100644 --- a/std/special/bootstrap.zig +++ b/std/special/bootstrap.zig @@ -5,12 +5,13 @@ const root = @import("@root"); const std = @import("std"); const builtin = @import("builtin"); +const is_windows = builtin.os == builtin.Os.windows; const want_main_symbol = builtin.link_libc; -const want_start_symbol = !want_main_symbol; +const want_start_symbol = !want_main_symbol and !is_windows; +const want_WinMainCRTStartup = is_windows and !builtin.link_libc; var argc_ptr: &usize = undefined; -const is_windows = builtin.os == builtin.Os.windows; export nakedcc fn _start() -> noreturn { if (!want_start_symbol) { @@ -18,18 +19,6 @@ export nakedcc fn _start() -> noreturn { unreachable; } - if (is_windows) { - if (builtin.arch == builtin.Arch.x86_64) { - // Align the stack pointer to 16 bytes. - asm volatile ( - \\ and $0xfffffffffffffff0,%%rsp - \\ sub $0x10,%%rsp - :::"rsp" - ); - } - windowsCallMainAndExit() - } - switch (builtin.arch) { builtin.Arch.x86_64 => { argc_ptr = asm("lea (%%rsp), %[argc]": [argc] "=r" (-> &usize)); @@ -42,8 +31,13 @@ export nakedcc fn _start() -> noreturn { posixCallMainAndExit() } -fn windowsCallMainAndExit() -> noreturn { +export fn WinMainCRTStartup() -> noreturn { + if (!want_WinMainCRTStartup) { + @setGlobalLinkage(WinMainCRTStartup, builtin.GlobalLinkage.Internal); + unreachable; + } @setAlignStack(16); + std.debug.user_main_fn = root.main; root.main() %% std.os.windows.ExitProcess(1); std.os.windows.ExitProcess(0); |
