commit bd7b2cc4b49127474a028e6726fce33c5db3df12 (tree)
parent fba618a6c9ae4f70dc8a7879975adf31d3a44d4d
Author: Andrew Kelley <andrew@ziglang.org>
Date: Sat, 13 Jul 2024 22:42:04 -0700
Merge pull request #20620 from kcbanner/fixup_msvc_bootstrap
Fixes for bootrapping with MSVC
Diffstat:
4 files changed, 99 insertions(+), 42 deletions(-)
diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig
@@ -1635,9 +1635,16 @@ fn getZigArgs(compile: *Compile) ![][]const u8 {
});
}
- if (compile.zig_lib_dir) |dir| {
+ const opt_zig_lib_dir = if (compile.zig_lib_dir) |dir|
+ dir.getPath2(b, step)
+ else if (b.graph.zig_lib_directory.path) |_|
+ b.fmt("{}", .{b.graph.zig_lib_directory})
+ else
+ null;
+
+ if (opt_zig_lib_dir) |zig_lib_dir| {
try zig_args.append("--zig-lib-dir");
- try zig_args.append(dir.getPath2(b, step));
+ try zig_args.append(zig_lib_dir);
}
try addFlag(&zig_args, "PIE", compile.pie);
diff --git a/lib/zig.h b/lib/zig.h
@@ -3636,7 +3636,7 @@ typedef int zig_memory_order;
#define zig_atomicrmw_min(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_min_ ##Type(obj, arg)
#define zig_atomicrmw_max(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_max_ ##Type(obj, arg)
#define zig_atomic_store( obj, arg, order, Type, ReprType) zig_msvc_atomic_store_ ##Type(obj, arg)
-#define zig_atomic_load(res, obj, order, Type, ReprType) res = zig_msvc_atomic_load_ ##Type(obj)
+#define zig_atomic_load(res, obj, order, Type, ReprType) res = zig_msvc_atomic_load_ ##order##_##Type(obj)
#if _M_X64
#define zig_fence(order) __faststorefence()
#else
@@ -3670,7 +3670,7 @@ typedef int zig_memory_order;
/* TODO: zig_msvc_atomic_load should load 32 bit without interlocked on x86, and load 64 bit without interlocked on x64 */
-#define zig_msvc_atomics(ZigType, Type, SigType, suffix) \
+#define zig_msvc_atomics(ZigType, Type, SigType, suffix, iso_suffix) \
static inline bool zig_msvc_cmpxchg_##ZigType(Type volatile* obj, Type* expected, Type desired) { \
Type comparand = *expected; \
Type initial = _InterlockedCompareExchange##suffix((SigType volatile*)obj, (SigType)desired, (SigType)comparand); \
@@ -3741,24 +3741,34 @@ typedef int zig_memory_order;
} \
static inline void zig_msvc_atomic_store_##ZigType(Type volatile* obj, Type value) { \
(void)_InterlockedExchange##suffix((SigType volatile*)obj, (SigType)value); \
+ } \
+ static inline Type zig_msvc_atomic_load_zig_memory_order_relaxed_##ZigType(Type volatile* obj) { \
+ return __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
} \
- static inline Type zig_msvc_atomic_load_##ZigType(Type volatile* obj) { \
- return _InterlockedExchangeAdd##suffix((SigType volatile*)obj, (SigType)0); \
+ static inline Type zig_msvc_atomic_load_zig_memory_order_acquire_##ZigType(Type volatile* obj) { \
+ Type val = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
+ _ReadWriteBarrier(); \
+ return val; \
+ } \
+ static inline Type zig_msvc_atomic_load_zig_memory_order_seq_cst_##ZigType(Type volatile* obj) { \
+ Type val = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
+ _ReadWriteBarrier(); \
+ return val; \
}
-zig_msvc_atomics( u8, uint8_t, char, 8)
-zig_msvc_atomics( i8, int8_t, char, 8)
-zig_msvc_atomics(u16, uint16_t, short, 16)
-zig_msvc_atomics(i16, int16_t, short, 16)
-zig_msvc_atomics(u32, uint32_t, long, )
-zig_msvc_atomics(i32, int32_t, long, )
+zig_msvc_atomics( u8, uint8_t, char, 8, 8)
+zig_msvc_atomics( i8, int8_t, char, 8, 8)
+zig_msvc_atomics(u16, uint16_t, short, 16, 16)
+zig_msvc_atomics(i16, int16_t, short, 16, 16)
+zig_msvc_atomics(u32, uint32_t, long, , 32)
+zig_msvc_atomics(i32, int32_t, long, , 32)
#if _M_X64
-zig_msvc_atomics(u64, uint64_t, __int64, 64)
-zig_msvc_atomics(i64, int64_t, __int64, 64)
+zig_msvc_atomics(u64, uint64_t, __int64, 64, 64)
+zig_msvc_atomics(i64, int64_t, __int64, 64, 64)
#endif
-#define zig_msvc_flt_atomics(Type, SigType, suffix) \
+#define zig_msvc_flt_atomics(Type, SigType, suffix, iso_suffix) \
static inline bool zig_msvc_cmpxchg_##Type(zig_##Type volatile* obj, zig_##Type* expected, zig_##Type desired) { \
SigType exchange; \
SigType comparand; \
@@ -3776,15 +3786,30 @@ zig_msvc_atomics(i64, int64_t, __int64, 64)
memcpy(&value, &arg, sizeof(value)); \
(void)_InterlockedExchange##suffix((SigType volatile*)obj, value); \
} \
- static inline zig_##Type zig_msvc_atomic_load_##Type(zig_##Type volatile* obj) { \
+ static inline zig_##Type zig_msvc_atomic_load_zig_memory_order_relaxed_##Type(zig_##Type volatile* obj) { \
zig_##Type result; \
- SigType initial = _InterlockedExchangeAdd##suffix((SigType volatile*)obj, (SigType)0); \
+ SigType initial = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
memcpy(&result, &initial, sizeof(result)); \
return result; \
+ } \
+ static inline zig_##Type zig_msvc_atomic_load_zig_memory_order_acquire_##Type(zig_##Type volatile* obj) { \
+ zig_##Type result; \
+ SigType initial = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
+ _ReadWriteBarrier(); \
+ memcpy(&result, &initial, sizeof(result)); \
+ return result; \
+ } \
+ static inline zig_##Type zig_msvc_atomic_load_zig_memory_order_seq_cst_##Type(zig_##Type volatile* obj) { \
+ zig_##Type result; \
+ SigType initial = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
+ _ReadWriteBarrier(); \
+ memcpy(&result, &initial, sizeof(result)); \
+ return result; \
}
-zig_msvc_flt_atomics(f32, long, )
+
+zig_msvc_flt_atomics(f32, long, , 32)
#if _M_X64
-zig_msvc_flt_atomics(f64, int64_t, 64)
+zig_msvc_flt_atomics(f64, int64_t, 64, 64)
#endif
#if _M_IX86
diff --git a/src/main.zig b/src/main.zig
@@ -2710,7 +2710,7 @@ fn buildOutputType(
break :d getWasiPreopen("/lib");
} else if (self_exe_path) |p| {
break :d introspect.findZigLibDirFromSelfExe(arena, p) catch |err| {
- fatal("unable to find zig installation directory: {s}", .{@errorName(err)});
+ fatal("unable to find zig installation directory '{s}': {s}", .{ p, @errorName(err) });
};
} else {
unreachable;
@@ -7403,7 +7403,7 @@ fn findTemplates(gpa: Allocator, arena: Allocator) Templates {
fatal("unable to find self exe path: {s}", .{@errorName(err)});
};
var zig_lib_directory = introspect.findZigLibDirFromSelfExe(arena, self_exe_path) catch |err| {
- fatal("unable to find zig installation directory: {s}", .{@errorName(err)});
+ fatal("unable to find zig installation directory '{s}': {s}", .{ self_exe_path, @errorName(err) });
};
const s = fs.path.sep_str;
diff --git a/stage1/zig.h b/stage1/zig.h
@@ -207,16 +207,16 @@ typedef char bool;
__asm(zig_mangle_c(name) " = " zig_mangle_c(symbol))
#endif
+#define zig_mangled_tentative zig_mangled
+#define zig_mangled_final zig_mangled
#if _MSC_VER
-#define zig_mangled_tentative(mangled, unmangled)
-#define zig_mangled_final(mangled, unmangled) ; \
+#define zig_mangled(mangled, unmangled) ; \
zig_export(#mangled, unmangled)
#define zig_mangled_export(mangled, unmangled, symbol) \
zig_export(unmangled, #mangled) \
zig_export(symbol, unmangled)
#else /* _MSC_VER */
-#define zig_mangled_tentative(mangled, unmangled) __asm(zig_mangle_c(unmangled))
-#define zig_mangled_final(mangled, unmangled) zig_mangled_tentative(mangled, unmangled)
+#define zig_mangled(mangled, unmangled) __asm(zig_mangle_c(unmangled))
#define zig_mangled_export(mangled, unmangled, symbol) \
zig_mangled_final(mangled, unmangled) \
zig_export(symbol, unmangled)
@@ -3636,7 +3636,7 @@ typedef int zig_memory_order;
#define zig_atomicrmw_min(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_min_ ##Type(obj, arg)
#define zig_atomicrmw_max(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_max_ ##Type(obj, arg)
#define zig_atomic_store( obj, arg, order, Type, ReprType) zig_msvc_atomic_store_ ##Type(obj, arg)
-#define zig_atomic_load(res, obj, order, Type, ReprType) res = zig_msvc_atomic_load_ ##Type(obj)
+#define zig_atomic_load(res, obj, order, Type, ReprType) res = zig_msvc_atomic_load_ ##order##_##Type(obj)
#if _M_X64
#define zig_fence(order) __faststorefence()
#else
@@ -3670,7 +3670,7 @@ typedef int zig_memory_order;
/* TODO: zig_msvc_atomic_load should load 32 bit without interlocked on x86, and load 64 bit without interlocked on x64 */
-#define zig_msvc_atomics(ZigType, Type, SigType, suffix) \
+#define zig_msvc_atomics(ZigType, Type, SigType, suffix, iso_suffix) \
static inline bool zig_msvc_cmpxchg_##ZigType(Type volatile* obj, Type* expected, Type desired) { \
Type comparand = *expected; \
Type initial = _InterlockedCompareExchange##suffix((SigType volatile*)obj, (SigType)desired, (SigType)comparand); \
@@ -3741,24 +3741,34 @@ typedef int zig_memory_order;
} \
static inline void zig_msvc_atomic_store_##ZigType(Type volatile* obj, Type value) { \
(void)_InterlockedExchange##suffix((SigType volatile*)obj, (SigType)value); \
+ } \
+ static inline Type zig_msvc_atomic_load_zig_memory_order_relaxed_##ZigType(Type volatile* obj) { \
+ return __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
} \
- static inline Type zig_msvc_atomic_load_##ZigType(Type volatile* obj) { \
- return _InterlockedExchangeAdd##suffix((SigType volatile*)obj, (SigType)0); \
+ static inline Type zig_msvc_atomic_load_zig_memory_order_acquire_##ZigType(Type volatile* obj) { \
+ Type val = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
+ _ReadWriteBarrier(); \
+ return val; \
+ } \
+ static inline Type zig_msvc_atomic_load_zig_memory_order_seq_cst_##ZigType(Type volatile* obj) { \
+ Type val = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
+ _ReadWriteBarrier(); \
+ return val; \
}
-zig_msvc_atomics( u8, uint8_t, char, 8)
-zig_msvc_atomics( i8, int8_t, char, 8)
-zig_msvc_atomics(u16, uint16_t, short, 16)
-zig_msvc_atomics(i16, int16_t, short, 16)
-zig_msvc_atomics(u32, uint32_t, long, )
-zig_msvc_atomics(i32, int32_t, long, )
+zig_msvc_atomics( u8, uint8_t, char, 8, 8)
+zig_msvc_atomics( i8, int8_t, char, 8, 8)
+zig_msvc_atomics(u16, uint16_t, short, 16, 16)
+zig_msvc_atomics(i16, int16_t, short, 16, 16)
+zig_msvc_atomics(u32, uint32_t, long, , 32)
+zig_msvc_atomics(i32, int32_t, long, , 32)
#if _M_X64
-zig_msvc_atomics(u64, uint64_t, __int64, 64)
-zig_msvc_atomics(i64, int64_t, __int64, 64)
+zig_msvc_atomics(u64, uint64_t, __int64, 64, 64)
+zig_msvc_atomics(i64, int64_t, __int64, 64, 64)
#endif
-#define zig_msvc_flt_atomics(Type, SigType, suffix) \
+#define zig_msvc_flt_atomics(Type, SigType, suffix, iso_suffix) \
static inline bool zig_msvc_cmpxchg_##Type(zig_##Type volatile* obj, zig_##Type* expected, zig_##Type desired) { \
SigType exchange; \
SigType comparand; \
@@ -3776,15 +3786,30 @@ zig_msvc_atomics(i64, int64_t, __int64, 64)
memcpy(&value, &arg, sizeof(value)); \
(void)_InterlockedExchange##suffix((SigType volatile*)obj, value); \
} \
- static inline zig_##Type zig_msvc_atomic_load_##Type(zig_##Type volatile* obj) { \
+ static inline zig_##Type zig_msvc_atomic_load_zig_memory_order_relaxed_##Type(zig_##Type volatile* obj) { \
zig_##Type result; \
- SigType initial = _InterlockedExchangeAdd##suffix((SigType volatile*)obj, (SigType)0); \
+ SigType initial = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
memcpy(&result, &initial, sizeof(result)); \
return result; \
+ } \
+ static inline zig_##Type zig_msvc_atomic_load_zig_memory_order_acquire_##Type(zig_##Type volatile* obj) { \
+ zig_##Type result; \
+ SigType initial = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
+ _ReadWriteBarrier(); \
+ memcpy(&result, &initial, sizeof(result)); \
+ return result; \
+ } \
+ static inline zig_##Type zig_msvc_atomic_load_zig_memory_order_seq_cst_##Type(zig_##Type volatile* obj) { \
+ zig_##Type result; \
+ SigType initial = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
+ _ReadWriteBarrier(); \
+ memcpy(&result, &initial, sizeof(result)); \
+ return result; \
}
-zig_msvc_flt_atomics(f32, long, )
+
+zig_msvc_flt_atomics(f32, long, , 32)
#if _M_X64
-zig_msvc_flt_atomics(f64, int64_t, 64)
+zig_msvc_flt_atomics(f64, int64_t, 64, 64)
#endif
#if _M_IX86