authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-11-05 17:22:25-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-11-06 01:16:09-05:00
loge74ced21b70f229167765d863613d3d5033b93fe
treeffcd8bf108d712e273b0e19f60dc9cd842f3b148
parent1b0b46a8a9f5ed3ebaf35e3018fd5402957552ae

frontend: fix -fsingle-threaded default detection logic

The logic in 509be7cf1f10c5d329d2b0524f2af6bfcabd52de assumed that `use_llvm` meant that the LLVM backend would be used, however, use_llvm is false when there are no zig files to compile, which is the case for zig cc. This logic resulted in `-fsingle-threaded` which made libc++ fail to compile for C++ code that includes the threading abstractions (such as LLVM).

2 files changed, 23 insertions(+), 7 deletions(-)

src/Compilation.zig+16-7
...@@ -1112,13 +1112,22 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1112,13 +1112,22 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
11121112
1113 const include_compiler_rt = options.want_compiler_rt orelse needs_c_symbols;1113 const include_compiler_rt = options.want_compiler_rt orelse needs_c_symbols;
11141114
1115 const must_single_thread = target_util.isSingleThreaded(options.target);1115 const single_threaded = st: {
1116 const single_threaded = options.single_threaded orelse must_single_thread or1116 if (target_util.isSingleThreaded(options.target)) {
1117 // x86_64 codegen doesn't support TLV for most object formats1117 if (options.single_threaded == false)
1118 (!use_llvm and options.target.cpu.arch == .x86_64 and options.target.ofmt != .macho);1118 return error.TargetRequiresSingleThreaded;
1119 if (must_single_thread and !single_threaded) {1119 break :st true;
1120 return error.TargetRequiresSingleThreaded;1120 }
1121 }1121 if (options.main_mod != null) {
1122 const zig_backend = zigBackend(options.target, use_llvm);
1123 if (!target_util.supportsThreads(options.target, zig_backend)) {
1124 if (options.single_threaded == false)
1125 return error.BackendRequiresSingleThreaded;
1126 break :st true;
1127 }
1128 }
1129 break :st options.single_threaded orelse false;
1130 };
11221131
1123 const llvm_cpu_features: ?[*:0]const u8 = if (use_llvm) blk: {1132 const llvm_cpu_features: ?[*:0]const u8 = if (use_llvm) blk: {
1124 var buf = std.ArrayList(u8).init(arena);1133 var buf = std.ArrayList(u8).init(arena);
src/target.zig+7
...@@ -641,6 +641,13 @@ pub fn supportsTailCall(target: std.Target, backend: std.builtin.CompilerBackend...@@ -641,6 +641,13 @@ pub fn supportsTailCall(target: std.Target, backend: std.builtin.CompilerBackend
641 }641 }
642}642}
643643
644pub fn supportsThreads(target: std.Target, backend: std.builtin.CompilerBackend) bool {
645 return switch (backend) {
646 .stage2_x86_64 => target.ofmt == .macho,
647 else => true,
648 };
649}
650
644pub fn libcFloatPrefix(float_bits: u16) []const u8 {651pub fn libcFloatPrefix(float_bits: u16) []const u8 {
645 return switch (float_bits) {652 return switch (float_bits) {
646 16, 80 => "__",653 16, 80 => "__",