authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-06 22:29:40-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-06 22:29:40-07:00
log33fa29601921d88097a1ee3c0d92b93047a5186d
tree5926ea2d182a76f80429776a5473202738c9b656
parentc1cf158729f4d726639a5695754957f9f45f89da

stage2: pass proper can_exit_early value to LLD

and adjust the warning message for invoking LLD twice in the same process.

4 files changed, 13 insertions(+), 9 deletions(-)

src/link/Coff.zig+1-1
......@@ -1417,7 +1417,7 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
14171417 }
14181418 }
14191419 } else {
1420 const exit_code = try lldMain(arena, argv.items);
1420 const exit_code = try lldMain(arena, argv.items, false);
14211421 if (exit_code != 0) {
14221422 if (comp.clang_passthrough_mode) {
14231423 std.process.exit(exit_code);
src/link/Elf.zig+1-1
......@@ -2009,7 +2009,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
20092009 }
20102010 }
20112011 } else {
2012 const exit_code = try lldMain(arena, argv.items);
2012 const exit_code = try lldMain(arena, argv.items, false);
20132013 if (exit_code != 0) {
20142014 if (comp.clang_passthrough_mode) {
20152015 std.process.exit(exit_code);
src/link/Wasm.zig+1-1
......@@ -1545,7 +1545,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
15451545 }
15461546 }
15471547 } else {
1548 const exit_code = try lldMain(arena, argv.items);
1548 const exit_code = try lldMain(arena, argv.items, false);
15491549 if (exit_code != 0) {
15501550 if (comp.clang_passthrough_mode) {
15511551 std.process.exit(exit_code);
src/main.zig+10-6
......@@ -236,7 +236,7 @@ pub fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
236236 mem.eql(u8, cmd, "lld-link") or
237237 mem.eql(u8, cmd, "wasm-ld"))
238238 {
239 return process.exit(try lldMain(arena, args));
239 return process.exit(try lldMain(arena, args, true));
240240 } else if (mem.eql(u8, cmd, "build")) {
241241 return cmdBuild(gpa, arena, cmd_args);
242242 } else if (mem.eql(u8, cmd, "fmt")) {
......@@ -4119,7 +4119,11 @@ pub fn llvmArMain(alloc: Allocator, args: []const []const u8) error{OutOfMemory}
41194119/// * `ld.lld` - ELF
41204120/// * `lld-link` - COFF
41214121/// * `wasm-ld` - WebAssembly
4122pub fn lldMain(alloc: Allocator, args: []const []const u8) error{OutOfMemory}!u8 {
4122pub fn lldMain(
4123 alloc: Allocator,
4124 args: []const []const u8,
4125 can_exit_early: bool,
4126) error{OutOfMemory}!u8 {
41234127 if (!build_options.have_llvm)
41244128 fatal("`zig {s}` unavailable: compiler built without LLVM extensions", .{args[0]});
41254129
......@@ -4130,7 +4134,7 @@ pub fn lldMain(alloc: Allocator, args: []const []const u8) error{OutOfMemory}!u8
41304134 var count: usize = 0;
41314135 };
41324136 if (CallCounter.count == 1) { // Issue the warning on the first repeat call
4133 warn("calling lldMain repeatedly within the same process can have side effects (https://github.com/ziglang/zig/issues/3825)", .{});
4137 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)});
41344138 }
41354139 CallCounter.count += 1;
41364140
......@@ -4145,11 +4149,11 @@ pub fn lldMain(alloc: Allocator, args: []const []const u8) error{OutOfMemory}!u8
41454149 const llvm = @import("codegen/llvm/bindings.zig");
41464150 const argc = @intCast(c_int, argv.len);
41474151 if (mem.eql(u8, args[1], "ld.lld")) {
4148 break :rc llvm.LinkELF(argc, argv.ptr, true);
4152 break :rc llvm.LinkELF(argc, argv.ptr, can_exit_early);
41494153 } else if (mem.eql(u8, args[1], "lld-link")) {
4150 break :rc llvm.LinkCOFF(argc, argv.ptr, true);
4154 break :rc llvm.LinkCOFF(argc, argv.ptr, can_exit_early);
41514155 } else if (mem.eql(u8, args[1], "wasm-ld")) {
4152 break :rc llvm.LinkWasm(argc, argv.ptr, true);
4156 break :rc llvm.LinkWasm(argc, argv.ptr, can_exit_early);
41534157 } else {
41544158 unreachable;
41554159 }