authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-12-12 17:47:40-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-01-15 15:11:35-08:00
logedd592d3710801d263ac2d82ef867db6214e4f47
treec75769fa3b2c8809d1ed8112dda16386022427e9
parent968941b535052e2842f47dd9e7e45fa94f8f79c2

fix compilation when enabling llvm


4 files changed, 41 insertions(+), 17 deletions(-)

src/link.zig+15-5
......@@ -1030,6 +1030,17 @@ pub const File = struct {
10301030 const tracy = trace(@src());
10311031 defer tracy.end();
10321032
1033 const comp = base.comp;
1034 const diags = &comp.link_diags;
1035
1036 return linkAsArchiveInner(base, arena, tid, prog_node) catch |err| switch (err) {
1037 error.OutOfMemory => return error.OutOfMemory,
1038 error.LinkFailure => return error.LinkFailure,
1039 else => |e| return diags.fail("failed to link as archive: {s}", .{@errorName(e)}),
1040 };
1041 }
1042
1043 fn linkAsArchiveInner(base: *File, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.Progress.Node) !void {
10331044 const comp = base.comp;
10341045
10351046 const directory = base.emit.root_dir; // Just an alias to make it shorter to type.
......@@ -1528,7 +1539,7 @@ pub fn spawnLld(
15281539 const exit_code = try lldMain(arena, argv, false);
15291540 if (exit_code == 0) return;
15301541 if (comp.clang_passthrough_mode) std.process.exit(exit_code);
1531 return error.LLDReportedFailure;
1542 return error.LinkFailure;
15321543 }
15331544
15341545 var stderr: []u8 = &.{};
......@@ -1605,17 +1616,16 @@ pub fn spawnLld(
16051616 return error.UnableToSpawnSelf;
16061617 };
16071618
1619 const diags = &comp.link_diags;
16081620 switch (term) {
16091621 .Exited => |code| if (code != 0) {
16101622 if (comp.clang_passthrough_mode) std.process.exit(code);
1611 const diags = &comp.link_diags;
16121623 diags.lockAndParseLldStderr(argv[1], stderr);
1613 return error.LLDReportedFailure;
1624 return error.LinkFailure;
16141625 },
16151626 else => {
16161627 if (comp.clang_passthrough_mode) std.process.abort();
1617 log.err("{s} terminated with stderr:\n{s}", .{ argv[0], stderr });
1618 return error.LLDCrashed;
1628 return diags.fail("{s} terminated with stderr:\n{s}", .{ argv[0], stderr });
16191629 },
16201630 }
16211631
src/link/Coff.zig+6-2
......@@ -1683,10 +1683,14 @@ fn resolveGlobalSymbol(coff: *Coff, current: SymbolWithLoc) !void {
16831683pub fn flush(coff: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.Progress.Node) link.File.FlushError!void {
16841684 const comp = coff.base.comp;
16851685 const use_lld = build_options.have_llvm and comp.config.use_lld;
1686 const diags = &comp.link_diags;
16861687 if (use_lld) {
1687 return coff.linkWithLLD(arena, tid, prog_node);
1688 return coff.linkWithLLD(arena, tid, prog_node) catch |err| switch (err) {
1689 error.OutOfMemory => return error.OutOfMemory,
1690 error.LinkFailure => return error.LinkFailure,
1691 else => |e| return diags.fail("failed to link with LLD: {s}", .{@errorName(e)}),
1692 };
16881693 }
1689 const diags = &comp.link_diags;
16901694 switch (comp.config.output_mode) {
16911695 .Exe, .Obj => return coff.flushModule(arena, tid, prog_node),
16921696 .Lib => return diags.fail("writing lib files not yet implemented for COFF", .{}),
src/link/Elf.zig+8-2
......@@ -795,9 +795,15 @@ pub fn loadInput(self: *Elf, input: link.Input) !void {
795795}
796796
797797pub fn flush(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.Progress.Node) link.File.FlushError!void {
798 const use_lld = build_options.have_llvm and self.base.comp.config.use_lld;
798 const comp = self.base.comp;
799 const use_lld = build_options.have_llvm and comp.config.use_lld;
800 const diags = &comp.link_diags;
799801 if (use_lld) {
800 return self.linkWithLLD(arena, tid, prog_node);
802 return self.linkWithLLD(arena, tid, prog_node) catch |err| switch (err) {
803 error.OutOfMemory => return error.OutOfMemory,
804 error.LinkFailure => return error.LinkFailure,
805 else => |e| return diags.fail("failed to link with LLD: {s}", .{@errorName(e)}),
806 };
801807 }
802808 try self.flushModule(arena, tid, prog_node);
803809}
src/link/Wasm.zig+12-8
......@@ -2134,9 +2134,14 @@ pub fn loadInput(wasm: *Wasm, input: link.Input) !void {
21342134pub fn flush(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.Progress.Node) link.File.FlushError!void {
21352135 const comp = wasm.base.comp;
21362136 const use_lld = build_options.have_llvm and comp.config.use_lld;
2137 const diags = &comp.link_diags;
21372138
21382139 if (use_lld) {
2139 return wasm.linkWithLLD(arena, tid, prog_node);
2140 return wasm.linkWithLLD(arena, tid, prog_node) catch |err| switch (err) {
2141 error.OutOfMemory => return error.OutOfMemory,
2142 error.LinkFailure => return error.LinkFailure,
2143 else => |e| return diags.fail("failed to link with LLD: {s}", .{@errorName(e)}),
2144 };
21402145 }
21412146 return wasm.flushModule(arena, tid, prog_node);
21422147}
......@@ -2415,6 +2420,7 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
24152420 defer tracy.end();
24162421
24172422 const comp = wasm.base.comp;
2423 const diags = &comp.link_diags;
24182424 const shared_memory = comp.config.shared_memory;
24192425 const export_memory = comp.config.export_memory;
24202426 const import_memory = comp.config.import_memory;
......@@ -2468,7 +2474,7 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
24682474 }
24692475 try man.addOptionalFile(module_obj_path);
24702476 try man.addOptionalFilePath(compiler_rt_path);
2471 man.hash.addOptionalBytes(wasm.optionalStringSlice(wasm.entry_name));
2477 man.hash.addOptionalBytes(wasm.entry_name.slice(wasm));
24722478 man.hash.add(wasm.base.stack_size);
24732479 man.hash.add(wasm.base.build_id);
24742480 man.hash.add(import_memory);
......@@ -2617,7 +2623,7 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
26172623 try argv.append("--export-dynamic");
26182624 }
26192625
2620 if (wasm.optionalStringSlice(wasm.entry_name)) |entry_name| {
2626 if (wasm.entry_name.slice(wasm)) |entry_name| {
26212627 try argv.appendSlice(&.{ "--entry", entry_name });
26222628 } else {
26232629 try argv.append("--no-entry");
......@@ -2759,14 +2765,12 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
27592765 switch (term) {
27602766 .Exited => |code| {
27612767 if (code != 0) {
2762 const diags = &comp.link_diags;
27632768 diags.lockAndParseLldStderr(linker_command, stderr);
2764 return error.LLDReportedFailure;
2769 return error.LinkFailure;
27652770 }
27662771 },
27672772 else => {
2768 log.err("{s} terminated with stderr:\n{s}", .{ argv.items[0], stderr });
2769 return error.LLDCrashed;
2773 return diags.fail("{s} terminated with stderr:\n{s}", .{ argv.items[0], stderr });
27702774 },
27712775 }
27722776
......@@ -2780,7 +2784,7 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
27802784 if (comp.clang_passthrough_mode) {
27812785 std.process.exit(exit_code);
27822786 } else {
2783 return error.LLDReportedFailure;
2787 return diags.fail("{s} returned exit code {d}:\n{s}", .{ argv.items[0], exit_code });
27842788 }
27852789 }
27862790 }