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 {...@@ -1030,6 +1030,17 @@ pub const File = struct {
1030 const tracy = trace(@src());1030 const tracy = trace(@src());
1031 defer tracy.end();1031 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 {
1033 const comp = base.comp;1044 const comp = base.comp;
10341045
1035 const directory = base.emit.root_dir; // Just an alias to make it shorter to type.1046 const directory = base.emit.root_dir; // Just an alias to make it shorter to type.
...@@ -1528,7 +1539,7 @@ pub fn spawnLld(...@@ -1528,7 +1539,7 @@ pub fn spawnLld(
1528 const exit_code = try lldMain(arena, argv, false);1539 const exit_code = try lldMain(arena, argv, false);
1529 if (exit_code == 0) return;1540 if (exit_code == 0) return;
1530 if (comp.clang_passthrough_mode) std.process.exit(exit_code);1541 if (comp.clang_passthrough_mode) std.process.exit(exit_code);
1531 return error.LLDReportedFailure;1542 return error.LinkFailure;
1532 }1543 }
15331544
1534 var stderr: []u8 = &.{};1545 var stderr: []u8 = &.{};
...@@ -1605,17 +1616,16 @@ pub fn spawnLld(...@@ -1605,17 +1616,16 @@ pub fn spawnLld(
1605 return error.UnableToSpawnSelf;1616 return error.UnableToSpawnSelf;
1606 };1617 };
16071618
1619 const diags = &comp.link_diags;
1608 switch (term) {1620 switch (term) {
1609 .Exited => |code| if (code != 0) {1621 .Exited => |code| if (code != 0) {
1610 if (comp.clang_passthrough_mode) std.process.exit(code);1622 if (comp.clang_passthrough_mode) std.process.exit(code);
1611 const diags = &comp.link_diags;
1612 diags.lockAndParseLldStderr(argv[1], stderr);1623 diags.lockAndParseLldStderr(argv[1], stderr);
1613 return error.LLDReportedFailure;1624 return error.LinkFailure;
1614 },1625 },
1615 else => {1626 else => {
1616 if (comp.clang_passthrough_mode) std.process.abort();1627 if (comp.clang_passthrough_mode) std.process.abort();
1617 log.err("{s} terminated with stderr:\n{s}", .{ argv[0], stderr });1628 return diags.fail("{s} terminated with stderr:\n{s}", .{ argv[0], stderr });
1618 return error.LLDCrashed;
1619 },1629 },
1620 }1630 }
16211631
src/link/Coff.zig+6-2
...@@ -1683,10 +1683,14 @@ fn resolveGlobalSymbol(coff: *Coff, current: SymbolWithLoc) !void {...@@ -1683,10 +1683,14 @@ fn resolveGlobalSymbol(coff: *Coff, current: SymbolWithLoc) !void {
1683pub fn flush(coff: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.Progress.Node) link.File.FlushError!void {1683pub fn flush(coff: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.Progress.Node) link.File.FlushError!void {
1684 const comp = coff.base.comp;1684 const comp = coff.base.comp;
1685 const use_lld = build_options.have_llvm and comp.config.use_lld;1685 const use_lld = build_options.have_llvm and comp.config.use_lld;
1686 const diags = &comp.link_diags;
1686 if (use_lld) {1687 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 };
1688 }1693 }
1689 const diags = &comp.link_diags;
1690 switch (comp.config.output_mode) {1694 switch (comp.config.output_mode) {
1691 .Exe, .Obj => return coff.flushModule(arena, tid, prog_node),1695 .Exe, .Obj => return coff.flushModule(arena, tid, prog_node),
1692 .Lib => return diags.fail("writing lib files not yet implemented for COFF", .{}),1696 .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 {...@@ -795,9 +795,15 @@ pub fn loadInput(self: *Elf, input: link.Input) !void {
795}795}
796796
797pub fn flush(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.Progress.Node) link.File.FlushError!void {797pub 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;
799 if (use_lld) {801 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 };
801 }807 }
802 try self.flushModule(arena, tid, prog_node);808 try self.flushModule(arena, tid, prog_node);
803}809}
src/link/Wasm.zig+12-8
...@@ -2134,9 +2134,14 @@ pub fn loadInput(wasm: *Wasm, input: link.Input) !void {...@@ -2134,9 +2134,14 @@ pub fn loadInput(wasm: *Wasm, input: link.Input) !void {
2134pub fn flush(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.Progress.Node) link.File.FlushError!void {2134pub fn flush(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.Progress.Node) link.File.FlushError!void {
2135 const comp = wasm.base.comp;2135 const comp = wasm.base.comp;
2136 const use_lld = build_options.have_llvm and comp.config.use_lld;2136 const use_lld = build_options.have_llvm and comp.config.use_lld;
2137 const diags = &comp.link_diags;
21372138
2138 if (use_lld) {2139 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 };
2140 }2145 }
2141 return wasm.flushModule(arena, tid, prog_node);2146 return wasm.flushModule(arena, tid, prog_node);
2142}2147}
...@@ -2415,6 +2420,7 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:...@@ -2415,6 +2420,7 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
2415 defer tracy.end();2420 defer tracy.end();
24162421
2417 const comp = wasm.base.comp;2422 const comp = wasm.base.comp;
2423 const diags = &comp.link_diags;
2418 const shared_memory = comp.config.shared_memory;2424 const shared_memory = comp.config.shared_memory;
2419 const export_memory = comp.config.export_memory;2425 const export_memory = comp.config.export_memory;
2420 const import_memory = comp.config.import_memory;2426 const import_memory = comp.config.import_memory;
...@@ -2468,7 +2474,7 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:...@@ -2468,7 +2474,7 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
2468 }2474 }
2469 try man.addOptionalFile(module_obj_path);2475 try man.addOptionalFile(module_obj_path);
2470 try man.addOptionalFilePath(compiler_rt_path);2476 try man.addOptionalFilePath(compiler_rt_path);
2471 man.hash.addOptionalBytes(wasm.optionalStringSlice(wasm.entry_name));2477 man.hash.addOptionalBytes(wasm.entry_name.slice(wasm));
2472 man.hash.add(wasm.base.stack_size);2478 man.hash.add(wasm.base.stack_size);
2473 man.hash.add(wasm.base.build_id);2479 man.hash.add(wasm.base.build_id);
2474 man.hash.add(import_memory);2480 man.hash.add(import_memory);
...@@ -2617,7 +2623,7 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:...@@ -2617,7 +2623,7 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
2617 try argv.append("--export-dynamic");2623 try argv.append("--export-dynamic");
2618 }2624 }
26192625
2620 if (wasm.optionalStringSlice(wasm.entry_name)) |entry_name| {2626 if (wasm.entry_name.slice(wasm)) |entry_name| {
2621 try argv.appendSlice(&.{ "--entry", entry_name });2627 try argv.appendSlice(&.{ "--entry", entry_name });
2622 } else {2628 } else {
2623 try argv.append("--no-entry");2629 try argv.append("--no-entry");
...@@ -2759,14 +2765,12 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:...@@ -2759,14 +2765,12 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
2759 switch (term) {2765 switch (term) {
2760 .Exited => |code| {2766 .Exited => |code| {
2761 if (code != 0) {2767 if (code != 0) {
2762 const diags = &comp.link_diags;
2763 diags.lockAndParseLldStderr(linker_command, stderr);2768 diags.lockAndParseLldStderr(linker_command, stderr);
2764 return error.LLDReportedFailure;2769 return error.LinkFailure;
2765 }2770 }
2766 },2771 },
2767 else => {2772 else => {
2768 log.err("{s} terminated with stderr:\n{s}", .{ argv.items[0], stderr });2773 return diags.fail("{s} terminated with stderr:\n{s}", .{ argv.items[0], stderr });
2769 return error.LLDCrashed;
2770 },2774 },
2771 }2775 }
27722776
...@@ -2780,7 +2784,7 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:...@@ -2780,7 +2784,7 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
2780 if (comp.clang_passthrough_mode) {2784 if (comp.clang_passthrough_mode) {
2781 std.process.exit(exit_code);2785 std.process.exit(exit_code);
2782 } else {2786 } else {
2783 return error.LLDReportedFailure;2787 return diags.fail("{s} returned exit code {d}:\n{s}", .{ argv.items[0], exit_code });
2784 }2788 }
2785 }2789 }
2786 }2790 }