authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-01 20:39:16-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-04 00:27:08-08:00
log85fe35d246d0076d403fc5ee90f4434da7206fd5
tree611e789c83a8257d8f8b0b0c5a8f860e783e4d36
parentf28802a9c6c3bd36368101981243aab7cf4f453f

compiler: fix -Denable-llvm compilation failures


11 files changed, 67 insertions(+), 54 deletions(-)

lib/std/Io/Threaded.zig-11
......@@ -14279,17 +14279,6 @@ fn testArgvToCommandLineWindows(argv: []const []const u8, expected_cmd_line: []c
1427914279 try std.testing.expectEqualStrings(expected_cmd_line, cmd_line);
1428014280}
1428114281
14282/// Replaces the current process image with the executed process. If this
14283/// function succeeds, it does not return.
14284///
14285/// This operation is not available on all targets. `can_execv`
14286///
14287/// This function also uses the PATH environment variable to get the full path to the executable.
14288/// If `file` is an absolute path, this is the same as `execveZ`.
14289///
14290/// Like `execvpeZ` except if `arg0_expand` is `.expand`, then `argv` is mutable,
14291/// and `argv[0]` is expanded to be the same absolute path that is passed to the execve syscall.
14292/// If this function returns with an error, `argv[0]` will be restored to the value it was when it was passed in.
1429314282fn execvpeZ_expandArg0(
1429414283 arg0_expand: process.ArgExpansion,
1429514284 file: [*:0]const u8,
src/Compilation.zig+53-40
......@@ -54,7 +54,7 @@ gpa: Allocator,
5454/// threads at once.
5555arena: Allocator,
5656io: Io,
57environ_map: *std.process.Environ.Map,
57environ_map: *const std.process.Environ.Map,
5858thread_limit: usize,
5959/// Not every Compilation compiles .zig code! For example you could do `zig build-exe foo.o`.
6060zcu: ?*Zcu,
......@@ -762,12 +762,12 @@ pub const Directories = struct {
762762 .wasi => void,
763763 else => []const u8,
764764 },
765 env_map: *std.process.Environ.Map,
765 env_map: *const std.process.Environ.Map,
766766 ) Directories {
767767 const wasi = builtin.target.os.tag == .wasi;
768768
769769 const cwd = introspect.getResolvedCwd(arena) catch |err| {
770 fatal("unable to get cwd: {s}", .{@errorName(err)});
770 fatal("unable to get cwd: {t}", .{err});
771771 };
772772
773773 const zig_lib: Cache.Directory = d: {
......@@ -1799,7 +1799,7 @@ pub const CreateOptions = struct {
17991799
18001800 parent_whole_cache: ?ParentWholeCache = null,
18011801
1802 environ_map: *std.process.Environ.Map,
1802 environ_map: *const std.process.Environ.Map,
18031803
18041804 pub const Entry = link.File.OpenOptions.Entry;
18051805
......@@ -5713,7 +5713,7 @@ pub fn translateC(
57135713 translated_basename: []const u8,
57145714 owner_mod: *Package.Module,
57155715 prog_node: std.Progress.Node,
5716 env_map: *std.process.Environ.Map,
5716 env_map: *const std.process.Environ.Map,
57175717) !CImportResult {
57185718 dev.check(.translate_c_command);
57195719
......@@ -6260,7 +6260,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
62606260 // that we could "tail call" clang by doing an execve, and any use of
62616261 // the caching system would actually be problematic since the user is
62626262 // presumably doing their own caching by using dep file flags.
6263 if (std.process.can_execv and direct_o and
6263 if (std.process.can_replace and direct_o and
62646264 comp.disable_c_depfile and comp.clang_passthrough_mode)
62656265 {
62666266 try comp.addCCArgs(arena, &argv, ext, null, c_object.src.owner);
......@@ -6292,8 +6292,8 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
62926292 try dumpArgv(io, argv.items);
62936293 }
62946294
6295 const err = std.process.execv(arena, argv.items);
6296 fatal("unable to execv clang: {s}", .{@errorName(err)});
6295 const err = std.process.replace(io, .{ .argv = argv.items });
6296 fatal("unable to replace process with clang: {t}", .{err});
62976297 }
62986298
62996299 // We can't know the digest until we do the C compiler invocation,
......@@ -6348,14 +6348,21 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
63486348 else => log.warn("failed to delete '{s}': {s}", .{ dep_file_path, @errorName(err) }),
63496349 };
63506350 if (std.process.can_spawn) {
6351 var child = std.process.Child.init(argv.items, arena);
63526351 if (comp.clang_passthrough_mode) {
6353 child.stdin_behavior = .inherit;
6354 child.stdout_behavior = .inherit;
6355 child.stderr_behavior = .inherit;
6356
6357 const term = child.spawnAndWait(io) catch |err| {
6358 return comp.failCObj(c_object, "failed to spawn zig clang (passthrough mode) {s}: {s}", .{ argv.items[0], @errorName(err) });
6352 var child = std.process.spawn(io, .{
6353 .argv = argv.items,
6354 .stdin = .inherit,
6355 .stdout = .inherit,
6356 .stderr = .inherit,
6357 }) catch |err| {
6358 return comp.failCObj(c_object, "failed to spawn zig clang (passthrough mode) {s}: {t}", .{
6359 argv.items[0], err,
6360 });
6361 };
6362 const term = child.wait(io) catch |err| {
6363 return comp.failCObj(c_object, "failed to wait zig clang (passthrough mode) {s}: {t}", .{
6364 argv.items[0], err,
6365 });
63596366 };
63606367 switch (term) {
63616368 .exited => |code| {
......@@ -6367,36 +6374,41 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
63676374 },
63686375 else => std.process.abort(),
63696376 }
6370 } else {
6371 child.stdin_behavior = .ignore;
6372 child.stdout_behavior = .ignore;
6373 child.stderr_behavior = .pipe;
6377 unreachable;
6378 }
63746379
6375 try child.spawn(io);
6380 var child = try std.process.spawn(io, .{
6381 .argv = argv.items,
6382 .stdin = .ignore,
6383 .stdout = .ignore,
6384 .stderr = .pipe,
6385 });
63766386
6377 var stderr_reader = child.stderr.?.readerStreaming(io, &.{});
6378 const stderr = try stderr_reader.interface.allocRemaining(arena, .limited(std.math.maxInt(u32)));
6387 var stderr_reader = child.stderr.?.readerStreaming(io, &.{});
6388 const stderr = try stderr_reader.interface.allocRemaining(arena, .limited(std.math.maxInt(u32)));
63796389
6380 const term = child.wait(io) catch |err| {
6381 return comp.failCObj(c_object, "failed to spawn zig clang {s}: {s}", .{ argv.items[0], @errorName(err) });
6382 };
6390 const term = child.wait(io) catch |err|
6391 return comp.failCObj(c_object, "failed to spawn zig clang {s}: {t}", .{ argv.items[0], err });
63836392
6384 switch (term) {
6385 .exited => |code| if (code != 0) if (out_diag_path) |diag_file_path| {
6386 const bundle = CObject.Diag.Bundle.parse(gpa, io, diag_file_path) catch |err| {
6387 log.err("{}: failed to parse clang diagnostics: {s}", .{ err, stderr });
6388 return comp.failCObj(c_object, "clang exited with code {d}", .{code});
6389 };
6390 return comp.failCObjWithOwnedDiagBundle(c_object, bundle);
6391 } else {
6392 log.err("clang failed with stderr: {s}", .{stderr});
6393 switch (term) {
6394 .exited => |code| if (code != 0) if (out_diag_path) |diag_file_path| {
6395 const bundle = CObject.Diag.Bundle.parse(gpa, io, diag_file_path) catch |err| {
6396 log.err("{}: failed to parse clang diagnostics: {s}", .{ err, stderr });
63936397 return comp.failCObj(c_object, "clang exited with code {d}", .{code});
6394 },
6395 else => {
6396 log.err("clang terminated with stderr: {s}", .{stderr});
6397 return comp.failCObj(c_object, "clang terminated unexpectedly", .{});
6398 },
6399 }
6398 };
6399 return comp.failCObjWithOwnedDiagBundle(c_object, bundle);
6400 } else {
6401 log.err("clang failed with stderr: {s}", .{stderr});
6402 return comp.failCObj(c_object, "clang exited with code {d}", .{code});
6403 },
6404 .signal => |sig| {
6405 log.err("clang failed with stderr: {s}", .{stderr});
6406 return comp.failCObj(c_object, "clang terminated with signal {t}", .{sig});
6407 },
6408 else => {
6409 log.err("clang terminated with stderr: {s}", .{stderr});
6410 return comp.failCObj(c_object, "clang terminated unexpectedly", .{});
6411 },
64006412 }
64016413 } else {
64026414 const exit_code = try clangMain(arena, argv.items);
......@@ -8113,6 +8125,7 @@ pub fn build_crt_file(
81138125 .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,
81148126 .clang_passthrough_mode = comp.clang_passthrough_mode,
81158127 .skip_linker_dependencies = true,
8128 .environ_map = comp.environ_map,
81168129 }) catch |err| switch (err) {
81178130 error.CreateFail => {
81188131 comp.lockAndSetMiscFailure(misc_task_tag, "sub-compilation of {t} failed: {f}", .{ misc_task_tag, sub_create_diag });
src/introspect.zig+1-1
......@@ -102,7 +102,7 @@ pub fn findZigLibDirFromSelfExe(
102102 return error.FileNotFound;
103103}
104104
105pub fn resolveGlobalCacheDir(arena: Allocator, env_map: *std.process.Environ.Map) ![]const u8 {
105pub fn resolveGlobalCacheDir(arena: Allocator, env_map: *const std.process.Environ.Map) ![]const u8 {
106106 if (std.zig.EnvVar.ZIG_GLOBAL_CACHE_DIR.get(env_map)) |value| return value;
107107
108108 const app_name = "zig";
src/libs/freebsd.zig+2
......@@ -445,6 +445,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
445445 .gpa = gpa,
446446 .io = io,
447447 .manifest_dir = try comp.dirs.global_cache.handle.createDirPathOpen(io, "h", .{}),
448 .cwd = comp.dirs.cwd,
448449 };
449450 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
450451 cache.addPrefix(comp.dirs.zig_lib);
......@@ -1119,6 +1120,7 @@ fn buildSharedLib(
11191120 .soname = soname,
11201121 .c_source_files = &c_source_files,
11211122 .skip_linker_dependencies = true,
1123 .environ_map = comp.environ_map,
11221124 }) catch |err| switch (err) {
11231125 error.CreateFail => {
11241126 comp.lockAndSetMiscFailure(misc_task, "sub-compilation of {t} failed: {f}", .{ misc_task, sub_create_diag });
src/libs/glibc.zig+2
......@@ -680,6 +680,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
680680 .gpa = gpa,
681681 .io = io,
682682 .manifest_dir = try comp.dirs.global_cache.handle.createDirPathOpen(io, "h", .{}),
683 .cwd = comp.dirs.cwd,
683684 };
684685 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
685686 cache.addPrefix(comp.dirs.zig_lib);
......@@ -1258,6 +1259,7 @@ fn buildSharedLib(
12581259 .soname = soname,
12591260 .c_source_files = &c_source_files,
12601261 .skip_linker_dependencies = true,
1262 .environ_map = comp.environ_map,
12611263 }) catch |err| switch (err) {
12621264 error.CreateFail => {
12631265 comp.lockAndSetMiscFailure(misc_task, "sub-compilation of {t} failed: {f}", .{ misc_task, sub_create_diag });
src/libs/libcxx.zig+2
......@@ -275,6 +275,7 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError!
275275 .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,
276276 .clang_passthrough_mode = comp.clang_passthrough_mode,
277277 .skip_linker_dependencies = true,
278 .environ_map = comp.environ_map,
278279 }) catch |err| {
279280 switch (err) {
280281 else => comp.lockAndSetMiscFailure(misc_task, "unable to build libc++: create compilation failed: {t}", .{err}),
......@@ -468,6 +469,7 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
468469 .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,
469470 .clang_passthrough_mode = comp.clang_passthrough_mode,
470471 .skip_linker_dependencies = true,
472 .environ_map = comp.environ_map,
471473 }) catch |err| {
472474 switch (err) {
473475 else => comp.lockAndSetMiscFailure(misc_task, "unable to build libc++abi: create compilation failed: {t}", .{err}),
src/libs/libtsan.zig+1
......@@ -301,6 +301,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
301301 .linker_allow_shlib_undefined = linker_allow_shlib_undefined,
302302 .install_name = install_name,
303303 .headerpad_size = headerpad_size,
304 .environ_map = comp.environ_map,
304305 }) catch |err| {
305306 switch (err) {
306307 else => comp.lockAndSetMiscFailure(misc_task, "unable to build {t}: create compilation failed: {t}", .{ misc_task, err }),
src/libs/libunwind.zig+1
......@@ -166,6 +166,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
166166 .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,
167167 .clang_passthrough_mode = comp.clang_passthrough_mode,
168168 .skip_linker_dependencies = true,
169 .environ_map = comp.environ_map,
169170 }) catch |err| {
170171 switch (err) {
171172 else => comp.lockAndSetMiscFailure(misc_task, "unable to build {t}: create compilation failed: {t}", .{ misc_task, err }),
src/libs/musl.zig+1
......@@ -272,6 +272,7 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
272272 },
273273 .skip_linker_dependencies = true,
274274 .soname = "libc.so",
275 .environ_map = comp.environ_map,
275276 }) catch |err| switch (err) {
276277 error.CreateFail => {
277278 comp.lockAndSetMiscFailure(misc_task, "sub-compilation of {t} failed: {f}", .{ misc_task, sub_create_diag });
src/libs/netbsd.zig+2
......@@ -386,6 +386,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
386386 .gpa = gpa,
387387 .io = io,
388388 .manifest_dir = try comp.dirs.global_cache.handle.createDirPathOpen(io, "h", .{}),
389 .cwd = comp.dirs.cwd,
389390 };
390391 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
391392 cache.addPrefix(comp.dirs.zig_lib);
......@@ -761,6 +762,7 @@ fn buildSharedLib(
761762 .soname = soname,
762763 .c_source_files = &c_source_files,
763764 .skip_linker_dependencies = true,
765 .environ_map = comp.environ_map,
764766 }) catch |err| switch (err) {
765767 error.CreateFail => {
766768 comp.lockAndSetMiscFailure(misc_task, "sub-compilation of {t} failed: {f}", .{ misc_task, sub_create_diag });
src/main.zig+2-2
......@@ -4708,7 +4708,7 @@ pub fn translateC(
47084708 arena: Allocator,
47094709 io: Io,
47104710 argv: []const []const u8,
4711 env_map: *process.Environ.Map,
4711 env_map: *const process.Environ.Map,
47124712 prog_node: std.Progress.Node,
47134713 capture: ?*[]u8,
47144714) !void {
......@@ -5516,7 +5516,7 @@ fn jitCmd(
55165516 arena: Allocator,
55175517 io: Io,
55185518 args: []const []const u8,
5519 env_map: *process.Environ.Map,
5519 env_map: *const process.Environ.Map,
55205520 options: JitCmdOptions,
55215521) !void {
55225522 dev.check(.jit_command);