authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-13 22:42:04-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-07-13 22:42:04-07:00
logbd7b2cc4b49127474a028e6726fce33c5db3df12
tree01e71492173186830a10157adfcc118a1e83806c
parentfba618a6c9ae4f70dc8a7879975adf31d3a44d4d
parentc31871065394c78d7d316b2a1709077437d29ccf
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #20620 from kcbanner/fixup_msvc_bootstrap

Fixes for bootrapping with MSVC

4 files changed, 99 insertions(+), 42 deletions(-)

lib/std/Build/Step/Compile.zig+9-2
......@@ -1635,9 +1635,16 @@ fn getZigArgs(compile: *Compile) ![][]const u8 {
16351635 });
16361636 }
16371637
1638 if (compile.zig_lib_dir) |dir| {
1638 const opt_zig_lib_dir = if (compile.zig_lib_dir) |dir|
1639 dir.getPath2(b, step)
1640 else if (b.graph.zig_lib_directory.path) |_|
1641 b.fmt("{}", .{b.graph.zig_lib_directory})
1642 else
1643 null;
1644
1645 if (opt_zig_lib_dir) |zig_lib_dir| {
16391646 try zig_args.append("--zig-lib-dir");
1640 try zig_args.append(dir.getPath2(b, step));
1647 try zig_args.append(zig_lib_dir);
16411648 }
16421649
16431650 try addFlag(&zig_args, "PIE", compile.pie);
lib/zig.h+42-17
......@@ -3636,7 +3636,7 @@ typedef int zig_memory_order;
36363636#define zig_atomicrmw_min(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_min_ ##Type(obj, arg)
36373637#define zig_atomicrmw_max(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_max_ ##Type(obj, arg)
36383638#define zig_atomic_store( obj, arg, order, Type, ReprType) zig_msvc_atomic_store_ ##Type(obj, arg)
3639#define zig_atomic_load(res, obj, order, Type, ReprType) res = zig_msvc_atomic_load_ ##Type(obj)
3639#define zig_atomic_load(res, obj, order, Type, ReprType) res = zig_msvc_atomic_load_ ##order##_##Type(obj)
36403640#if _M_X64
36413641#define zig_fence(order) __faststorefence()
36423642#else
......@@ -3670,7 +3670,7 @@ typedef int zig_memory_order;
36703670
36713671/* TODO: zig_msvc_atomic_load should load 32 bit without interlocked on x86, and load 64 bit without interlocked on x64 */
36723672
3673#define zig_msvc_atomics(ZigType, Type, SigType, suffix) \
3673#define zig_msvc_atomics(ZigType, Type, SigType, suffix, iso_suffix) \
36743674 static inline bool zig_msvc_cmpxchg_##ZigType(Type volatile* obj, Type* expected, Type desired) { \
36753675 Type comparand = *expected; \
36763676 Type initial = _InterlockedCompareExchange##suffix((SigType volatile*)obj, (SigType)desired, (SigType)comparand); \
......@@ -3741,24 +3741,34 @@ typedef int zig_memory_order;
37413741 } \
37423742 static inline void zig_msvc_atomic_store_##ZigType(Type volatile* obj, Type value) { \
37433743 (void)_InterlockedExchange##suffix((SigType volatile*)obj, (SigType)value); \
3744 } \
3745 static inline Type zig_msvc_atomic_load_zig_memory_order_relaxed_##ZigType(Type volatile* obj) { \
3746 return __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
37443747 } \
3745 static inline Type zig_msvc_atomic_load_##ZigType(Type volatile* obj) { \
3746 return _InterlockedExchangeAdd##suffix((SigType volatile*)obj, (SigType)0); \
3748 static inline Type zig_msvc_atomic_load_zig_memory_order_acquire_##ZigType(Type volatile* obj) { \
3749 Type val = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
3750 _ReadWriteBarrier(); \
3751 return val; \
3752 } \
3753 static inline Type zig_msvc_atomic_load_zig_memory_order_seq_cst_##ZigType(Type volatile* obj) { \
3754 Type val = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
3755 _ReadWriteBarrier(); \
3756 return val; \
37473757 }
37483758
3749zig_msvc_atomics( u8, uint8_t, char, 8)
3750zig_msvc_atomics( i8, int8_t, char, 8)
3751zig_msvc_atomics(u16, uint16_t, short, 16)
3752zig_msvc_atomics(i16, int16_t, short, 16)
3753zig_msvc_atomics(u32, uint32_t, long, )
3754zig_msvc_atomics(i32, int32_t, long, )
3759zig_msvc_atomics( u8, uint8_t, char, 8, 8)
3760zig_msvc_atomics( i8, int8_t, char, 8, 8)
3761zig_msvc_atomics(u16, uint16_t, short, 16, 16)
3762zig_msvc_atomics(i16, int16_t, short, 16, 16)
3763zig_msvc_atomics(u32, uint32_t, long, , 32)
3764zig_msvc_atomics(i32, int32_t, long, , 32)
37553765
37563766#if _M_X64
3757zig_msvc_atomics(u64, uint64_t, __int64, 64)
3758zig_msvc_atomics(i64, int64_t, __int64, 64)
3767zig_msvc_atomics(u64, uint64_t, __int64, 64, 64)
3768zig_msvc_atomics(i64, int64_t, __int64, 64, 64)
37593769#endif
37603770
3761#define zig_msvc_flt_atomics(Type, SigType, suffix) \
3771#define zig_msvc_flt_atomics(Type, SigType, suffix, iso_suffix) \
37623772 static inline bool zig_msvc_cmpxchg_##Type(zig_##Type volatile* obj, zig_##Type* expected, zig_##Type desired) { \
37633773 SigType exchange; \
37643774 SigType comparand; \
......@@ -3776,15 +3786,30 @@ zig_msvc_atomics(i64, int64_t, __int64, 64)
37763786 memcpy(&value, &arg, sizeof(value)); \
37773787 (void)_InterlockedExchange##suffix((SigType volatile*)obj, value); \
37783788 } \
3779 static inline zig_##Type zig_msvc_atomic_load_##Type(zig_##Type volatile* obj) { \
3789 static inline zig_##Type zig_msvc_atomic_load_zig_memory_order_relaxed_##Type(zig_##Type volatile* obj) { \
37803790 zig_##Type result; \
3781 SigType initial = _InterlockedExchangeAdd##suffix((SigType volatile*)obj, (SigType)0); \
3791 SigType initial = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
37823792 memcpy(&result, &initial, sizeof(result)); \
37833793 return result; \
3794 } \
3795 static inline zig_##Type zig_msvc_atomic_load_zig_memory_order_acquire_##Type(zig_##Type volatile* obj) { \
3796 zig_##Type result; \
3797 SigType initial = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
3798 _ReadWriteBarrier(); \
3799 memcpy(&result, &initial, sizeof(result)); \
3800 return result; \
3801 } \
3802 static inline zig_##Type zig_msvc_atomic_load_zig_memory_order_seq_cst_##Type(zig_##Type volatile* obj) { \
3803 zig_##Type result; \
3804 SigType initial = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
3805 _ReadWriteBarrier(); \
3806 memcpy(&result, &initial, sizeof(result)); \
3807 return result; \
37843808 }
3785zig_msvc_flt_atomics(f32, long, )
3809
3810zig_msvc_flt_atomics(f32, long, , 32)
37863811#if _M_X64
3787zig_msvc_flt_atomics(f64, int64_t, 64)
3812zig_msvc_flt_atomics(f64, int64_t, 64, 64)
37883813#endif
37893814
37903815#if _M_IX86
src/main.zig+2-2
......@@ -2710,7 +2710,7 @@ fn buildOutputType(
27102710 break :d getWasiPreopen("/lib");
27112711 } else if (self_exe_path) |p| {
27122712 break :d introspect.findZigLibDirFromSelfExe(arena, p) catch |err| {
2713 fatal("unable to find zig installation directory: {s}", .{@errorName(err)});
2713 fatal("unable to find zig installation directory '{s}': {s}", .{ p, @errorName(err) });
27142714 };
27152715 } else {
27162716 unreachable;
......@@ -7403,7 +7403,7 @@ fn findTemplates(gpa: Allocator, arena: Allocator) Templates {
74037403 fatal("unable to find self exe path: {s}", .{@errorName(err)});
74047404 };
74057405 var zig_lib_directory = introspect.findZigLibDirFromSelfExe(arena, self_exe_path) catch |err| {
7406 fatal("unable to find zig installation directory: {s}", .{@errorName(err)});
7406 fatal("unable to find zig installation directory '{s}': {s}", .{ self_exe_path, @errorName(err) });
74077407 };
74087408
74097409 const s = fs.path.sep_str;
stage1/zig.h+46-21
......@@ -207,16 +207,16 @@ typedef char bool;
207207 __asm(zig_mangle_c(name) " = " zig_mangle_c(symbol))
208208#endif
209209
210#define zig_mangled_tentative zig_mangled
211#define zig_mangled_final zig_mangled
210212#if _MSC_VER
211#define zig_mangled_tentative(mangled, unmangled)
212#define zig_mangled_final(mangled, unmangled) ; \
213#define zig_mangled(mangled, unmangled) ; \
213214 zig_export(#mangled, unmangled)
214215#define zig_mangled_export(mangled, unmangled, symbol) \
215216 zig_export(unmangled, #mangled) \
216217 zig_export(symbol, unmangled)
217218#else /* _MSC_VER */
218#define zig_mangled_tentative(mangled, unmangled) __asm(zig_mangle_c(unmangled))
219#define zig_mangled_final(mangled, unmangled) zig_mangled_tentative(mangled, unmangled)
219#define zig_mangled(mangled, unmangled) __asm(zig_mangle_c(unmangled))
220220#define zig_mangled_export(mangled, unmangled, symbol) \
221221 zig_mangled_final(mangled, unmangled) \
222222 zig_export(symbol, unmangled)
......@@ -3636,7 +3636,7 @@ typedef int zig_memory_order;
36363636#define zig_atomicrmw_min(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_min_ ##Type(obj, arg)
36373637#define zig_atomicrmw_max(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_max_ ##Type(obj, arg)
36383638#define zig_atomic_store( obj, arg, order, Type, ReprType) zig_msvc_atomic_store_ ##Type(obj, arg)
3639#define zig_atomic_load(res, obj, order, Type, ReprType) res = zig_msvc_atomic_load_ ##Type(obj)
3639#define zig_atomic_load(res, obj, order, Type, ReprType) res = zig_msvc_atomic_load_ ##order##_##Type(obj)
36403640#if _M_X64
36413641#define zig_fence(order) __faststorefence()
36423642#else
......@@ -3670,7 +3670,7 @@ typedef int zig_memory_order;
36703670
36713671/* TODO: zig_msvc_atomic_load should load 32 bit without interlocked on x86, and load 64 bit without interlocked on x64 */
36723672
3673#define zig_msvc_atomics(ZigType, Type, SigType, suffix) \
3673#define zig_msvc_atomics(ZigType, Type, SigType, suffix, iso_suffix) \
36743674 static inline bool zig_msvc_cmpxchg_##ZigType(Type volatile* obj, Type* expected, Type desired) { \
36753675 Type comparand = *expected; \
36763676 Type initial = _InterlockedCompareExchange##suffix((SigType volatile*)obj, (SigType)desired, (SigType)comparand); \
......@@ -3741,24 +3741,34 @@ typedef int zig_memory_order;
37413741 } \
37423742 static inline void zig_msvc_atomic_store_##ZigType(Type volatile* obj, Type value) { \
37433743 (void)_InterlockedExchange##suffix((SigType volatile*)obj, (SigType)value); \
3744 } \
3745 static inline Type zig_msvc_atomic_load_zig_memory_order_relaxed_##ZigType(Type volatile* obj) { \
3746 return __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
37443747 } \
3745 static inline Type zig_msvc_atomic_load_##ZigType(Type volatile* obj) { \
3746 return _InterlockedExchangeAdd##suffix((SigType volatile*)obj, (SigType)0); \
3748 static inline Type zig_msvc_atomic_load_zig_memory_order_acquire_##ZigType(Type volatile* obj) { \
3749 Type val = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
3750 _ReadWriteBarrier(); \
3751 return val; \
3752 } \
3753 static inline Type zig_msvc_atomic_load_zig_memory_order_seq_cst_##ZigType(Type volatile* obj) { \
3754 Type val = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
3755 _ReadWriteBarrier(); \
3756 return val; \
37473757 }
37483758
3749zig_msvc_atomics( u8, uint8_t, char, 8)
3750zig_msvc_atomics( i8, int8_t, char, 8)
3751zig_msvc_atomics(u16, uint16_t, short, 16)
3752zig_msvc_atomics(i16, int16_t, short, 16)
3753zig_msvc_atomics(u32, uint32_t, long, )
3754zig_msvc_atomics(i32, int32_t, long, )
3759zig_msvc_atomics( u8, uint8_t, char, 8, 8)
3760zig_msvc_atomics( i8, int8_t, char, 8, 8)
3761zig_msvc_atomics(u16, uint16_t, short, 16, 16)
3762zig_msvc_atomics(i16, int16_t, short, 16, 16)
3763zig_msvc_atomics(u32, uint32_t, long, , 32)
3764zig_msvc_atomics(i32, int32_t, long, , 32)
37553765
37563766#if _M_X64
3757zig_msvc_atomics(u64, uint64_t, __int64, 64)
3758zig_msvc_atomics(i64, int64_t, __int64, 64)
3767zig_msvc_atomics(u64, uint64_t, __int64, 64, 64)
3768zig_msvc_atomics(i64, int64_t, __int64, 64, 64)
37593769#endif
37603770
3761#define zig_msvc_flt_atomics(Type, SigType, suffix) \
3771#define zig_msvc_flt_atomics(Type, SigType, suffix, iso_suffix) \
37623772 static inline bool zig_msvc_cmpxchg_##Type(zig_##Type volatile* obj, zig_##Type* expected, zig_##Type desired) { \
37633773 SigType exchange; \
37643774 SigType comparand; \
......@@ -3776,15 +3786,30 @@ zig_msvc_atomics(i64, int64_t, __int64, 64)
37763786 memcpy(&value, &arg, sizeof(value)); \
37773787 (void)_InterlockedExchange##suffix((SigType volatile*)obj, value); \
37783788 } \
3779 static inline zig_##Type zig_msvc_atomic_load_##Type(zig_##Type volatile* obj) { \
3789 static inline zig_##Type zig_msvc_atomic_load_zig_memory_order_relaxed_##Type(zig_##Type volatile* obj) { \
37803790 zig_##Type result; \
3781 SigType initial = _InterlockedExchangeAdd##suffix((SigType volatile*)obj, (SigType)0); \
3791 SigType initial = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
37823792 memcpy(&result, &initial, sizeof(result)); \
37833793 return result; \
3794 } \
3795 static inline zig_##Type zig_msvc_atomic_load_zig_memory_order_acquire_##Type(zig_##Type volatile* obj) { \
3796 zig_##Type result; \
3797 SigType initial = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
3798 _ReadWriteBarrier(); \
3799 memcpy(&result, &initial, sizeof(result)); \
3800 return result; \
3801 } \
3802 static inline zig_##Type zig_msvc_atomic_load_zig_memory_order_seq_cst_##Type(zig_##Type volatile* obj) { \
3803 zig_##Type result; \
3804 SigType initial = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
3805 _ReadWriteBarrier(); \
3806 memcpy(&result, &initial, sizeof(result)); \
3807 return result; \
37843808 }
3785zig_msvc_flt_atomics(f32, long, )
3809
3810zig_msvc_flt_atomics(f32, long, , 32)
37863811#if _M_X64
3787zig_msvc_flt_atomics(f64, int64_t, 64)
3812zig_msvc_flt_atomics(f64, int64_t, 64, 64)
37883813#endif
37893814
37903815#if _M_IX86