| ... | @@ -5,9 +5,6 @@ const arch = builtin.cpu.arch; | ... | @@ -5,9 +5,6 @@ const arch = builtin.cpu.arch; |
| 5 | const abi = builtin.abi; | 5 | const abi = builtin.abi; |
| 6 | const is_test = builtin.is_test; | 6 | const is_test = builtin.is_test; |
| 7 | | 7 | |
| 8 | const is_gnu = abi.isGnu(); | | |
| 9 | const is_mingw = os_tag == .windows and is_gnu; | | |
| 10 | | | |
| 11 | const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .internal else .weak; | 8 | const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .internal else .weak; |
| 12 | const strong_linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .internal else .strong; | 9 | const strong_linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .internal else .strong; |
| 13 | pub const panic = @import("common.zig").panic; | 10 | pub const panic = @import("common.zig").panic; |
| ... | @@ -15,11 +12,11 @@ pub const panic = @import("common.zig").panic; | ... | @@ -15,11 +12,11 @@ pub const panic = @import("common.zig").panic; |
| 15 | comptime { | 12 | comptime { |
| 16 | if (builtin.os.tag == .windows) { | 13 | if (builtin.os.tag == .windows) { |
| 17 | // Default stack-probe functions emitted by LLVM | 14 | // Default stack-probe functions emitted by LLVM |
| 18 | if (is_mingw) { | 15 | if (builtin.target.isMinGW()) { |
| 19 | @export(&_chkstk, .{ .name = "_alloca", .linkage = linkage }); | 16 | @export(&_chkstk, .{ .name = "_alloca", .linkage = linkage }); |
| 20 | @export(&___chkstk_ms, .{ .name = "___chkstk_ms", .linkage = linkage }); | 17 | @export(&___chkstk_ms, .{ .name = "___chkstk_ms", .linkage = linkage }); |
| 21 | | 18 | |
| 22 | if (arch.isAARCH64()) { | 19 | if (arch == .thumb or arch == .aarch64) { |
| 23 | @export(&__chkstk, .{ .name = "__chkstk", .linkage = linkage }); | 20 | @export(&__chkstk, .{ .name = "__chkstk", .linkage = linkage }); |
| 24 | } | 21 | } |
| 25 | } else if (!builtin.link_libc) { | 22 | } else if (!builtin.link_libc) { |
| ... | @@ -100,6 +97,35 @@ fn win_probe_stack_only() void { | ... | @@ -100,6 +97,35 @@ fn win_probe_stack_only() void { |
| 100 | @setRuntimeSafety(false); | 97 | @setRuntimeSafety(false); |
| 101 | | 98 | |
| 102 | switch (arch) { | 99 | switch (arch) { |
| | 100 | .thumb => { |
| | 101 | asm volatile ( |
| | 102 | \\ lsl r4, r4, #2 |
| | 103 | \\ mov r12, sp |
| | 104 | \\ push {r5, r6} |
| | 105 | \\ mov r5, r4 |
| | 106 | \\1: |
| | 107 | \\ sub r12, r12, #4096 |
| | 108 | \\ subs r5, r5, #4096 |
| | 109 | \\ ldr r6, [r12] |
| | 110 | \\ bgt 1b |
| | 111 | \\ pop {r5, r6} |
| | 112 | \\ bx lr |
| | 113 | ); |
| | 114 | }, |
| | 115 | .aarch64 => { |
| | 116 | asm volatile ( |
| | 117 | \\ lsl x16, x15, #4 |
| | 118 | \\ mov x17, sp |
| | 119 | \\1: |
| | 120 | \\ |
| | 121 | \\ sub x17, x17, 4096 |
| | 122 | \\ subs x16, x16, 4096 |
| | 123 | \\ ldr xzr, [x17] |
| | 124 | \\ b.gt 1b |
| | 125 | \\ |
| | 126 | \\ ret |
| | 127 | ); |
| | 128 | }, |
| 103 | .x86_64 => { | 129 | .x86_64 => { |
| 104 | asm volatile ( | 130 | asm volatile ( |
| 105 | \\ push %%rcx | 131 | \\ push %%rcx |
| ... | @@ -144,21 +170,6 @@ fn win_probe_stack_only() void { | ... | @@ -144,21 +170,6 @@ fn win_probe_stack_only() void { |
| 144 | }, | 170 | }, |
| 145 | else => {}, | 171 | else => {}, |
| 146 | } | 172 | } |
| 147 | if (comptime arch.isAARCH64()) { | | |
| 148 | // NOTE: page size hardcoded to 4096 for now | | |
| 149 | asm volatile ( | | |
| 150 | \\ lsl x16, x15, #4 | | |
| 151 | \\ mov x17, sp | | |
| 152 | \\1: | | |
| 153 | \\ | | |
| 154 | \\ sub x17, x17, 4096 | | |
| 155 | \\ subs x16, x16, 4096 | | |
| 156 | \\ ldr xzr, [x17] | | |
| 157 | \\ b.gt 1b | | |
| 158 | \\ | | |
| 159 | \\ ret | | |
| 160 | ); | | |
| 161 | } | | |
| 162 | | 173 | |
| 163 | unreachable; | 174 | unreachable; |
| 164 | } | 175 | } |
| ... | @@ -240,7 +251,7 @@ pub fn _chkstk() callconv(.Naked) void { | ... | @@ -240,7 +251,7 @@ pub fn _chkstk() callconv(.Naked) void { |
| 240 | } | 251 | } |
| 241 | pub fn __chkstk() callconv(.Naked) void { | 252 | pub fn __chkstk() callconv(.Naked) void { |
| 242 | @setRuntimeSafety(false); | 253 | @setRuntimeSafety(false); |
| 243 | if (comptime arch.isAARCH64()) { | 254 | if (arch == .thumb or arch == .aarch64) { |
| 244 | @call(.always_inline, win_probe_stack_only, .{}); | 255 | @call(.always_inline, win_probe_stack_only, .{}); |
| 245 | } else switch (arch) { | 256 | } else switch (arch) { |
| 246 | .x86 => @call(.always_inline, win_probe_stack_adjust_sp, .{}), | 257 | .x86 => @call(.always_inline, win_probe_stack_adjust_sp, .{}), |