File tree 2 files changed +32
-11
lines changed 2 files changed +32
-11
lines changed Original file line number Diff line number Diff line change @@ -5008,8 +5008,16 @@ static void init(CodeGen *g) {
5008
5008
const char *target_specific_cpu_args;
5009
5009
const char *target_specific_features;
5010
5010
if (g->is_native_target ) {
5011
- target_specific_cpu_args = ZigLLVMGetHostCPUName ();
5012
- target_specific_features = ZigLLVMGetNativeFeatures ();
5011
+ // LLVM creates invalid binaries on Windows sometimes.
5012
+ // See https://github.com/zig-lang/zig/issues/508
5013
+ // As a workaround we do not use target native features on Windows.
5014
+ if (g->zig_target .os == ZigLLVM_Win32) {
5015
+ target_specific_cpu_args = " " ;
5016
+ target_specific_features = " " ;
5017
+ } else {
5018
+ target_specific_cpu_args = ZigLLVMGetHostCPUName ();
5019
+ target_specific_features = ZigLLVMGetNativeFeatures ();
5020
+ }
5013
5021
} else {
5014
5022
target_specific_cpu_args = " " ;
5015
5023
target_specific_features = " " ;
Original file line number Diff line number Diff line change @@ -129,8 +129,9 @@ export nakedcc fn _chkstk() align(4) {
129
129
@setGlobalLinkage (_chkstk , strong_linkage );
130
130
asm volatile (
131
131
\\ push %%ecx
132
+ \\ push %%eax
132
133
\\ cmp $0x1000,%%eax
133
- \\ lea 8 (%%esp),%%ecx // esp before calling this routine -> ecx
134
+ \\ lea 12 (%%esp),%%ecx
134
135
\\ jb 1f
135
136
\\ 2:
136
137
\\ sub $0x1000,%%ecx
@@ -141,12 +142,8 @@ export nakedcc fn _chkstk() align(4) {
141
142
\\ 1:
142
143
\\ sub %%eax,%%ecx
143
144
\\ test %%ecx,(%%ecx)
144
- \\
145
- \\ lea 4(%%esp),%%eax // load pointer to the return address into eax
146
- \\ mov %%ecx,%%esp // install the new top of stack pointer into esp
147
- \\ mov -4(%%eax),%%ecx // restore ecx
148
- \\ push (%%eax) // push return address onto the stack
149
- \\ sub %%esp,%%eax // restore the original value in eax
145
+ \\ pop %%eax
146
+ \\ pop %%ecx
150
147
\\ ret
151
148
);
152
149
unreachable ;
@@ -159,13 +156,29 @@ export nakedcc fn _chkstk() align(4) {
159
156
// the implementation from disassembled ntdll seems to depend on
160
157
// thread local storage. So we have given up this safety check
161
158
// and simply have `ret`.
162
- export nakedcc fn __chkstk () align (8 ) {
159
+ export nakedcc fn __chkstk () align (4 ) {
163
160
@setDebugSafety (this , false );
164
161
165
162
if (win64_nocrt ) {
166
163
@setGlobalLinkage (__chkstk , strong_linkage );
167
164
asm volatile (
168
- \\ ret
165
+ \\ push %%rcx
166
+ \\ push %%rax
167
+ \\ cmp $0x1000,%%rax
168
+ \\ lea 24(%%rsp),%%rcx
169
+ \\ jb 1f
170
+ \\2:
171
+ \\ sub $0x1000,%%rcx
172
+ \\ test %%rcx,(%%rcx)
173
+ \\ sub $0x1000,%%rax
174
+ \\ cmp $0x1000,%%rax
175
+ \\ ja 2b
176
+ \\1:
177
+ \\ sub %%rax,%%rcx
178
+ \\ test %%rcx,(%%rcx)
179
+ \\ pop %%rax
180
+ \\ pop %%rcx
181
+ \\ ret
169
182
);
170
183
unreachable ;
171
184
}
You can’t perform that action at this time.
0 commit comments