| author | |
| committer | |
| log | edd592d3710801d263ac2d82ef867db6214e4f47 |
| tree | c75769fa3b2c8809d1ed8112dda16386022427e9 |
| parent | 968941b535052e2842f47dd9e7e45fa94f8f79c2 |
4 files changed, 41 insertions(+), 17 deletions(-)
src/link.zig+15-5| ... | ... | @@ -1030,6 +1030,17 @@ pub const File = struct { |
| 1030 | 1030 | const tracy = trace(@src()); |
| 1031 | 1031 | defer tracy.end(); |
| 1032 | 1032 | |
| 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 | 1044 | const comp = base.comp; |
| 1034 | 1045 | |
| 1035 | 1046 | const directory = base.emit.root_dir; // Just an alias to make it shorter to type. |
| ... | ... | @@ -1528,7 +1539,7 @@ pub fn spawnLld( |
| 1528 | 1539 | const exit_code = try lldMain(arena, argv, false); |
| 1529 | 1540 | if (exit_code == 0) return; |
| 1530 | 1541 | if (comp.clang_passthrough_mode) std.process.exit(exit_code); |
| 1531 | return error.LLDReportedFailure; | |
| 1542 | return error.LinkFailure; | |
| 1532 | 1543 | } |
| 1533 | 1544 | |
| 1534 | 1545 | var stderr: []u8 = &.{}; |
| ... | ... | @@ -1605,17 +1616,16 @@ pub fn spawnLld( |
| 1605 | 1616 | return error.UnableToSpawnSelf; |
| 1606 | 1617 | }; |
| 1607 | 1618 | |
| 1619 | const diags = &comp.link_diags; | |
| 1608 | 1620 | switch (term) { |
| 1609 | 1621 | .Exited => |code| if (code != 0) { |
| 1610 | 1622 | if (comp.clang_passthrough_mode) std.process.exit(code); |
| 1611 | const diags = &comp.link_diags; | |
| 1612 | 1623 | diags.lockAndParseLldStderr(argv[1], stderr); |
| 1613 | return error.LLDReportedFailure; | |
| 1624 | return error.LinkFailure; | |
| 1614 | 1625 | }, |
| 1615 | 1626 | else => { |
| 1616 | 1627 | 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 }); | |
| 1619 | 1629 | }, |
| 1620 | 1630 | } |
| 1621 | 1631 |
src/link/Coff.zig+6-2| ... | ... | @@ -1683,10 +1683,14 @@ fn resolveGlobalSymbol(coff: *Coff, current: SymbolWithLoc) !void { |
| 1683 | 1683 | pub fn flush(coff: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.Progress.Node) link.File.FlushError!void { |
| 1684 | 1684 | const comp = coff.base.comp; |
| 1685 | 1685 | const use_lld = build_options.have_llvm and comp.config.use_lld; |
| 1686 | const diags = &comp.link_diags; | |
| 1686 | 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 | 1694 | switch (comp.config.output_mode) { |
| 1691 | 1695 | .Exe, .Obj => return coff.flushModule(arena, tid, prog_node), |
| 1692 | 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 | 795 | } |
| 796 | 796 | |
| 797 | 797 | pub 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 | 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 | 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 | 2134 | pub fn flush(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.Progress.Node) link.File.FlushError!void { |
| 2135 | 2135 | const comp = wasm.base.comp; |
| 2136 | 2136 | const use_lld = build_options.have_llvm and comp.config.use_lld; |
| 2137 | const diags = &comp.link_diags; | |
| 2137 | 2138 | |
| 2138 | 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 | 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 | 2420 | defer tracy.end(); |
| 2416 | 2421 | |
| 2417 | 2422 | const comp = wasm.base.comp; |
| 2423 | const diags = &comp.link_diags; | |
| 2418 | 2424 | const shared_memory = comp.config.shared_memory; |
| 2419 | 2425 | const export_memory = comp.config.export_memory; |
| 2420 | 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 | 2474 | } |
| 2469 | 2475 | try man.addOptionalFile(module_obj_path); |
| 2470 | 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 | 2478 | man.hash.add(wasm.base.stack_size); |
| 2473 | 2479 | man.hash.add(wasm.base.build_id); |
| 2474 | 2480 | man.hash.add(import_memory); |
| ... | ... | @@ -2617,7 +2623,7 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: |
| 2617 | 2623 | try argv.append("--export-dynamic"); |
| 2618 | 2624 | } |
| 2619 | 2625 | |
| 2620 | if (wasm.optionalStringSlice(wasm.entry_name)) |entry_name| { | |
| 2626 | if (wasm.entry_name.slice(wasm)) |entry_name| { | |
| 2621 | 2627 | try argv.appendSlice(&.{ "--entry", entry_name }); |
| 2622 | 2628 | } else { |
| 2623 | 2629 | try argv.append("--no-entry"); |
| ... | ... | @@ -2759,14 +2765,12 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: |
| 2759 | 2765 | switch (term) { |
| 2760 | 2766 | .Exited => |code| { |
| 2761 | 2767 | if (code != 0) { |
| 2762 | const diags = &comp.link_diags; | |
| 2763 | 2768 | diags.lockAndParseLldStderr(linker_command, stderr); |
| 2764 | return error.LLDReportedFailure; | |
| 2769 | return error.LinkFailure; | |
| 2765 | 2770 | } |
| 2766 | 2771 | }, |
| 2767 | 2772 | 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 }); | |
| 2770 | 2774 | }, |
| 2771 | 2775 | } |
| 2772 | 2776 | |
| ... | ... | @@ -2780,7 +2784,7 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: |
| 2780 | 2784 | if (comp.clang_passthrough_mode) { |
| 2781 | 2785 | std.process.exit(exit_code); |
| 2782 | 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 | } |