diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-11-05 17:22:25 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-11-06 01:16:09 -0500 |
| commit | e74ced21b70f229167765d863613d3d5033b93fe (patch) | |
| tree | ffcd8bf108d712e273b0e19f60dc9cd842f3b148 /src/Compilation.zig | |
| parent | 1b0b46a8a9f5ed3ebaf35e3018fd5402957552ae (diff) | |
| download | zig-e74ced21b70f229167765d863613d3d5033b93fe.tar.gz zig-e74ced21b70f229167765d863613d3d5033b93fe.zip | |
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).
Diffstat (limited to 'src/Compilation.zig')
| -rw-r--r-- | src/Compilation.zig | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index f2a0fb5e63..c2a48f57ff 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1112,13 +1112,22 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { const include_compiler_rt = options.want_compiler_rt orelse needs_c_symbols; - const must_single_thread = target_util.isSingleThreaded(options.target); - const single_threaded = options.single_threaded orelse must_single_thread or - // x86_64 codegen doesn't support TLV for most object formats - (!use_llvm and options.target.cpu.arch == .x86_64 and options.target.ofmt != .macho); - if (must_single_thread and !single_threaded) { - return error.TargetRequiresSingleThreaded; - } + const single_threaded = st: { + if (target_util.isSingleThreaded(options.target)) { + if (options.single_threaded == false) + return error.TargetRequiresSingleThreaded; + break :st true; + } + if (options.main_mod != null) { + const zig_backend = zigBackend(options.target, use_llvm); + if (!target_util.supportsThreads(options.target, zig_backend)) { + if (options.single_threaded == false) + return error.BackendRequiresSingleThreaded; + break :st true; + } + } + break :st options.single_threaded orelse false; + }; const llvm_cpu_features: ?[*:0]const u8 = if (use_llvm) blk: { var buf = std.ArrayList(u8).init(arena); |
