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 {...@@ -1417,7 +1417,7 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
1417 }1417 }
1418 }1418 }
1419 } else {1419 } else {
1420 const exit_code = try lldMain(arena, argv.items);1420 const exit_code = try lldMain(arena, argv.items, false);
1421 if (exit_code != 0) {1421 if (exit_code != 0) {
1422 if (comp.clang_passthrough_mode) {1422 if (comp.clang_passthrough_mode) {
1423 std.process.exit(exit_code);1423 std.process.exit(exit_code);
src/link/Elf.zig+1-1
...@@ -2009,7 +2009,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {...@@ -2009,7 +2009,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
2009 }2009 }
2010 }2010 }
2011 } else {2011 } else {
2012 const exit_code = try lldMain(arena, argv.items);2012 const exit_code = try lldMain(arena, argv.items, false);
2013 if (exit_code != 0) {2013 if (exit_code != 0) {
2014 if (comp.clang_passthrough_mode) {2014 if (comp.clang_passthrough_mode) {
2015 std.process.exit(exit_code);2015 std.process.exit(exit_code);
src/link/Wasm.zig+1-1
...@@ -1545,7 +1545,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {...@@ -1545,7 +1545,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
1545 }1545 }
1546 }1546 }
1547 } else {1547 } else {
1548 const exit_code = try lldMain(arena, argv.items);1548 const exit_code = try lldMain(arena, argv.items, false);
1549 if (exit_code != 0) {1549 if (exit_code != 0) {
1550 if (comp.clang_passthrough_mode) {1550 if (comp.clang_passthrough_mode) {
1551 std.process.exit(exit_code);1551 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...@@ -236,7 +236,7 @@ pub fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
236 mem.eql(u8, cmd, "lld-link") or236 mem.eql(u8, cmd, "lld-link") or
237 mem.eql(u8, cmd, "wasm-ld"))237 mem.eql(u8, cmd, "wasm-ld"))
238 {238 {
239 return process.exit(try lldMain(arena, args));239 return process.exit(try lldMain(arena, args, true));
240 } else if (mem.eql(u8, cmd, "build")) {240 } else if (mem.eql(u8, cmd, "build")) {
241 return cmdBuild(gpa, arena, cmd_args);241 return cmdBuild(gpa, arena, cmd_args);
242 } else if (mem.eql(u8, cmd, "fmt")) {242 } else if (mem.eql(u8, cmd, "fmt")) {
...@@ -4119,7 +4119,11 @@ pub fn llvmArMain(alloc: Allocator, args: []const []const u8) error{OutOfMemory}...@@ -4119,7 +4119,11 @@ pub fn llvmArMain(alloc: Allocator, args: []const []const u8) error{OutOfMemory}
4119/// * `ld.lld` - ELF4119/// * `ld.lld` - ELF
4120/// * `lld-link` - COFF4120/// * `lld-link` - COFF
4121/// * `wasm-ld` - WebAssembly4121/// * `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 {
4123 if (!build_options.have_llvm)4127 if (!build_options.have_llvm)
4124 fatal("`zig {s}` unavailable: compiler built without LLVM extensions", .{args[0]});4128 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...@@ -4130,7 +4134,7 @@ pub fn lldMain(alloc: Allocator, args: []const []const u8) error{OutOfMemory}!u8
4130 var count: usize = 0;4134 var count: usize = 0;
4131 };4135 };
4132 if (CallCounter.count == 1) { // Issue the warning on the first repeat call4136 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)});
4134 }4138 }
4135 CallCounter.count += 1;4139 CallCounter.count += 1;
41364140
...@@ -4145,11 +4149,11 @@ pub fn lldMain(alloc: Allocator, args: []const []const u8) error{OutOfMemory}!u8...@@ -4145,11 +4149,11 @@ pub fn lldMain(alloc: Allocator, args: []const []const u8) error{OutOfMemory}!u8
4145 const llvm = @import("codegen/llvm/bindings.zig");4149 const llvm = @import("codegen/llvm/bindings.zig");
4146 const argc = @intCast(c_int, argv.len);4150 const argc = @intCast(c_int, argv.len);
4147 if (mem.eql(u8, args[1], "ld.lld")) {4151 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);
4149 } else if (mem.eql(u8, args[1], "lld-link")) {4153 } 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);
4151 } else if (mem.eql(u8, args[1], "wasm-ld")) {4155 } 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);
4153 } else {4157 } else {
4154 unreachable;4158 unreachable;
4155 }4159 }