From 33fa29601921d88097a1ee3c0d92b93047a5186d Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 6 Feb 2022 22:29:40 -0700 Subject: [PATCH] stage2: pass proper can_exit_early value to LLD and adjust the warning message for invoking LLD twice in the same process. --- src/link/Coff.zig | 2 +- src/link/Elf.zig | 2 +- src/link/Wasm.zig | 2 +- src/main.zig | 16 ++++++++++------ 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/link/Coff.zig b/src/link/Coff.zig index 8426e5d50c8ba5c2e9cad050399431ffbf0057c0..bc5837fe470b58c28565e22ce7335d4ba61be30b 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -1417,7 +1417,7 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void { } } } else { - const exit_code = try lldMain(arena, argv.items); + const exit_code = try lldMain(arena, argv.items, false); if (exit_code != 0) { if (comp.clang_passthrough_mode) { std.process.exit(exit_code); diff --git a/src/link/Elf.zig b/src/link/Elf.zig index 2a550d26e6d44a5821f6e23c9b06cca51e304c1a..afaf41a2f93b2c3dffaec9dc836adb9dcf46d555 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -2009,7 +2009,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void { } } } else { - const exit_code = try lldMain(arena, argv.items); + const exit_code = try lldMain(arena, argv.items, false); if (exit_code != 0) { if (comp.clang_passthrough_mode) { std.process.exit(exit_code); diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index 91952468cc5f4a416e13f75db54eb8836a4c4f6b..e6988e9232200752f8983cc20fe45dd67be45c1e 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -1545,7 +1545,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { } } } else { - const exit_code = try lldMain(arena, argv.items); + const exit_code = try lldMain(arena, argv.items, false); if (exit_code != 0) { if (comp.clang_passthrough_mode) { std.process.exit(exit_code); diff --git a/src/main.zig b/src/main.zig index 6a1416cd6b7e98e1a1321574598305e0432a0367..3f38fd1f780dff11a56b7e1dcc1ffa62e35f8cfd 100644 --- a/src/main.zig +++ b/src/main.zig @@ -236,7 +236,7 @@ pub fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi mem.eql(u8, cmd, "lld-link") or mem.eql(u8, cmd, "wasm-ld")) { - return process.exit(try lldMain(arena, args)); + return process.exit(try lldMain(arena, args, true)); } else if (mem.eql(u8, cmd, "build")) { return cmdBuild(gpa, arena, cmd_args); } else if (mem.eql(u8, cmd, "fmt")) { @@ -4119,7 +4119,11 @@ pub fn llvmArMain(alloc: Allocator, args: []const []const u8) error{OutOfMemory} /// * `ld.lld` - ELF /// * `lld-link` - COFF /// * `wasm-ld` - WebAssembly -pub fn lldMain(alloc: Allocator, args: []const []const u8) error{OutOfMemory}!u8 { +pub fn lldMain( + alloc: Allocator, + args: []const []const u8, + can_exit_early: bool, +) error{OutOfMemory}!u8 { if (!build_options.have_llvm) fatal("`zig {s}` unavailable: compiler built without LLVM extensions", .{args[0]}); @@ -4130,7 +4134,7 @@ pub fn lldMain(alloc: Allocator, args: []const []const u8) error{OutOfMemory}!u8 var count: usize = 0; }; if (CallCounter.count == 1) { // Issue the warning on the first repeat call - warn("calling lldMain repeatedly within the same process can have side effects (https://github.com/ziglang/zig/issues/3825)", .{}); + warn("invoking LLD for the second time within the same process because the host OS ({s}) does not support spawning child processes. This sometimes activates LLD bugs", .{@tagName(builtin.os.tag)}); } CallCounter.count += 1; @@ -4145,11 +4149,11 @@ pub fn lldMain(alloc: Allocator, args: []const []const u8) error{OutOfMemory}!u8 const llvm = @import("codegen/llvm/bindings.zig"); const argc = @intCast(c_int, argv.len); if (mem.eql(u8, args[1], "ld.lld")) { - break :rc llvm.LinkELF(argc, argv.ptr, true); + break :rc llvm.LinkELF(argc, argv.ptr, can_exit_early); } else if (mem.eql(u8, args[1], "lld-link")) { - break :rc llvm.LinkCOFF(argc, argv.ptr, true); + break :rc llvm.LinkCOFF(argc, argv.ptr, can_exit_early); } else if (mem.eql(u8, args[1], "wasm-ld")) { - break :rc llvm.LinkWasm(argc, argv.ptr, true); + break :rc llvm.LinkWasm(argc, argv.ptr, can_exit_early); } else { unreachable; } -- 2.54.0