| ... | ... | @@ -532,11 +532,19 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { |
| 532 | 532 | // Create an LLD command line and invoke it. |
| 533 | 533 | var argv = std.ArrayList([]const u8).init(self.base.allocator); |
| 534 | 534 | defer argv.deinit(); |
| 535 | | // Even though we're calling LLD as a library it thinks the first argument is its own exe name. |
| 536 | | try argv.append("lld"); |
| 537 | 535 | |
| 538 | | try argv.append("-error-limit"); |
| 539 | | try argv.append("0"); |
| 536 | // TODO https://github.com/ziglang/zig/issues/6971 |
| 537 | // Note that there is no need to check if running natively since we do that already |
| 538 | // when setting `system_linker_hack` in Compilation struct. |
| 539 | if (self.base.options.system_linker_hack) { |
| 540 | try argv.append("ld"); |
| 541 | } else { |
| 542 | // Even though we're calling LLD as a library it thinks the first argument is its own exe name. |
| 543 | try argv.append("lld"); |
| 544 | |
| 545 | try argv.append("-error-limit"); |
| 546 | try argv.append("0"); |
| 547 | } |
| 540 | 548 | |
| 541 | 549 | try argv.append("-demangle"); |
| 542 | 550 | |
| ... | ... | @@ -703,42 +711,65 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { |
| 703 | 711 | Compilation.dump_argv(argv.items); |
| 704 | 712 | } |
| 705 | 713 | |
| 706 | | const new_argv = try arena.allocSentinel(?[*:0]const u8, argv.items.len, null); |
| 707 | | for (argv.items) |arg, i| { |
| 708 | | new_argv[i] = try arena.dupeZ(u8, arg); |
| 709 | | } |
| 714 | // TODO https://github.com/ziglang/zig/issues/6971 |
| 715 | // Note that there is no need to check if running natively since we do that already |
| 716 | // when setting `system_linker_hack` in Compilation struct. |
| 717 | if (self.base.options.system_linker_hack) { |
| 718 | const result = try std.ChildProcess.exec(.{ .allocator = self.base.allocator, .argv = argv.items }); |
| 719 | defer { |
| 720 | self.base.allocator.free(result.stdout); |
| 721 | self.base.allocator.free(result.stderr); |
| 722 | } |
| 723 | if (result.stdout.len != 0) { |
| 724 | std.log.warn("unexpected LD stdout: {}", .{result.stdout}); |
| 725 | } |
| 726 | if (result.stderr.len != 0) { |
| 727 | std.log.warn("unexpected LD stderr: {}", .{result.stderr}); |
| 728 | } |
| 729 | if (result.term != .Exited or result.term.Exited != 0) { |
| 730 | // TODO parse this output and surface with the Compilation API rather than |
| 731 | // directly outputting to stderr here. |
| 732 | std.debug.print("{}", .{result.stderr}); |
| 733 | return error.LDReportedFailure; |
| 734 | } |
| 735 | } else { |
| 736 | const new_argv = try arena.allocSentinel(?[*:0]const u8, argv.items.len, null); |
| 737 | for (argv.items) |arg, i| { |
| 738 | new_argv[i] = try arena.dupeZ(u8, arg); |
| 739 | } |
| 710 | 740 | |
| 711 | | var stderr_context: LLDContext = .{ |
| 712 | | .macho = self, |
| 713 | | .data = std.ArrayList(u8).init(self.base.allocator), |
| 714 | | }; |
| 715 | | defer stderr_context.data.deinit(); |
| 716 | | var stdout_context: LLDContext = .{ |
| 717 | | .macho = self, |
| 718 | | .data = std.ArrayList(u8).init(self.base.allocator), |
| 719 | | }; |
| 720 | | defer stdout_context.data.deinit(); |
| 721 | | const llvm = @import("../llvm.zig"); |
| 722 | | const ok = llvm.Link( |
| 723 | | .MachO, |
| 724 | | new_argv.ptr, |
| 725 | | new_argv.len, |
| 726 | | append_diagnostic, |
| 727 | | @ptrToInt(&stdout_context), |
| 728 | | @ptrToInt(&stderr_context), |
| 729 | | ); |
| 730 | | if (stderr_context.oom or stdout_context.oom) return error.OutOfMemory; |
| 731 | | if (stdout_context.data.items.len != 0) { |
| 732 | | std.log.warn("unexpected LLD stdout: {}", .{stdout_context.data.items}); |
| 733 | | } |
| 734 | | if (!ok) { |
| 735 | | // TODO parse this output and surface with the Compilation API rather than |
| 736 | | // directly outputting to stderr here. |
| 737 | | std.debug.print("{}", .{stderr_context.data.items}); |
| 738 | | return error.LLDReportedFailure; |
| 739 | | } |
| 740 | | if (stderr_context.data.items.len != 0) { |
| 741 | | std.log.warn("unexpected LLD stderr: {}", .{stderr_context.data.items}); |
| 741 | var stderr_context: LLDContext = .{ |
| 742 | .macho = self, |
| 743 | .data = std.ArrayList(u8).init(self.base.allocator), |
| 744 | }; |
| 745 | defer stderr_context.data.deinit(); |
| 746 | var stdout_context: LLDContext = .{ |
| 747 | .macho = self, |
| 748 | .data = std.ArrayList(u8).init(self.base.allocator), |
| 749 | }; |
| 750 | defer stdout_context.data.deinit(); |
| 751 | const llvm = @import("../llvm.zig"); |
| 752 | const ok = llvm.Link( |
| 753 | .MachO, |
| 754 | new_argv.ptr, |
| 755 | new_argv.len, |
| 756 | append_diagnostic, |
| 757 | @ptrToInt(&stdout_context), |
| 758 | @ptrToInt(&stderr_context), |
| 759 | ); |
| 760 | if (stderr_context.oom or stdout_context.oom) return error.OutOfMemory; |
| 761 | if (stdout_context.data.items.len != 0) { |
| 762 | std.log.warn("unexpected LLD stdout: {}", .{stdout_context.data.items}); |
| 763 | } |
| 764 | if (!ok) { |
| 765 | // TODO parse this output and surface with the Compilation API rather than |
| 766 | // directly outputting to stderr here. |
| 767 | std.debug.print("{}", .{stderr_context.data.items}); |
| 768 | return error.LLDReportedFailure; |
| 769 | } |
| 770 | if (stderr_context.data.items.len != 0) { |
| 771 | std.log.warn("unexpected LLD stderr: {}", .{stderr_context.data.items}); |
| 772 | } |
| 742 | 773 | } |
| 743 | 774 | } |
| 744 | 775 | |