Skip to content

Commit bd7b2cc

Browse files
authored
Merge pull request #20620 from kcbanner/fixup_msvc_bootstrap
Fixes for bootrapping with MSVC
2 parents fba618a + c318710 commit bd7b2cc

File tree

4 files changed

+99
-42
lines changed

4 files changed

+99
-42
lines changed

lib/std/Build/Step/Compile.zig

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3749-
zig_msvc_atomics( u8, uint8_t, char, 8)
3750-
zig_msvc_atomics( i8, int8_t, char, 8)
3751-
zig_msvc_atomics(u16, uint16_t, short, 16)
3752-
zig_msvc_atomics(i16, int16_t, short, 16)
3753-
zig_msvc_atomics(u32, uint32_t, long, )
3754-
zig_msvc_atomics(i32, int32_t, long, )
3759+
zig_msvc_atomics( u8, uint8_t, char, 8, 8)
3760+
zig_msvc_atomics( i8, int8_t, char, 8, 8)
3761+
zig_msvc_atomics(u16, uint16_t, short, 16, 16)
3762+
zig_msvc_atomics(i16, int16_t, short, 16, 16)
3763+
zig_msvc_atomics(u32, uint32_t, long, , 32)
3764+
zig_msvc_atomics(i32, int32_t, long, , 32)
37553765

37563766
#if _M_X64
3757-
zig_msvc_atomics(u64, uint64_t, __int64, 64)
3758-
zig_msvc_atomics(i64, int64_t, __int64, 64)
3767+
zig_msvc_atomics(u64, uint64_t, __int64, 64, 64)
3768+
zig_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
}
3785-
zig_msvc_flt_atomics(f32, long, )
3809+
3810+
zig_msvc_flt_atomics(f32, long, , 32)
37863811
#if _M_X64
3787-
zig_msvc_flt_atomics(f64, int64_t, 64)
3812+
zig_msvc_flt_atomics(f64, int64_t, 64, 64)
37883813
#endif
37893814

37903815
#if _M_IX86

src/main.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3749-
zig_msvc_atomics( u8, uint8_t, char, 8)
3750-
zig_msvc_atomics( i8, int8_t, char, 8)
3751-
zig_msvc_atomics(u16, uint16_t, short, 16)
3752-
zig_msvc_atomics(i16, int16_t, short, 16)
3753-
zig_msvc_atomics(u32, uint32_t, long, )
3754-
zig_msvc_atomics(i32, int32_t, long, )
3759+
zig_msvc_atomics( u8, uint8_t, char, 8, 8)
3760+
zig_msvc_atomics( i8, int8_t, char, 8, 8)
3761+
zig_msvc_atomics(u16, uint16_t, short, 16, 16)
3762+
zig_msvc_atomics(i16, int16_t, short, 16, 16)
3763+
zig_msvc_atomics(u32, uint32_t, long, , 32)
3764+
zig_msvc_atomics(i32, int32_t, long, , 32)
37553765

37563766
#if _M_X64
3757-
zig_msvc_atomics(u64, uint64_t, __int64, 64)
3758-
zig_msvc_atomics(i64, int64_t, __int64, 64)
3767+
zig_msvc_atomics(u64, uint64_t, __int64, 64, 64)
3768+
zig_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
}
3785-
zig_msvc_flt_atomics(f32, long, )
3809+
3810+
zig_msvc_flt_atomics(f32, long, , 32)
37863811
#if _M_X64
3787-
zig_msvc_flt_atomics(f64, int64_t, 64)
3812+
zig_msvc_flt_atomics(f64, int64_t, 64, 64)
37883813
#endif
37893814

37903815
#if _M_IX86

0 commit comments

Comments
 (0)