| ... | @@ -23,6 +23,7 @@ const target_util = @import("../target.zig"); | ... | @@ -23,6 +23,7 @@ const target_util = @import("../target.zig"); |
| 23 | | 23 | |
| 24 | const Trie = @import("MachO/Trie.zig"); | 24 | const Trie = @import("MachO/Trie.zig"); |
| 25 | const CodeSignature = @import("MachO/CodeSignature.zig"); | 25 | const CodeSignature = @import("MachO/CodeSignature.zig"); |
| | 26 | const Parser = @import("MachO/Parser.zig"); |
| 26 | | 27 | |
| 27 | pub const base_tag: File.Tag = File.Tag.macho; | 28 | pub const base_tag: File.Tag = File.Tag.macho; |
| 28 | | 29 | |
| ... | @@ -801,6 +802,38 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { | ... | @@ -801,6 +802,38 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { |
| 801 | if (stderr_context.data.items.len != 0) { | 802 | if (stderr_context.data.items.len != 0) { |
| 802 | std.log.warn("unexpected LLD stderr: {}", .{stderr_context.data.items}); | 803 | std.log.warn("unexpected LLD stderr: {}", .{stderr_context.data.items}); |
| 803 | } | 804 | } |
| | 805 | |
| | 806 | // At this stage, LLD has done its job. It is time to patch the resultant |
| | 807 | // binaries up! |
| | 808 | var parser = Parser.init(self.base.allocator); |
| | 809 | defer parser.deinit(); |
| | 810 | const out_file = try directory.handle.openFile(full_out_path, .{}); |
| | 811 | try parser.parseFile(out_file); |
| | 812 | out_file.close(); |
| | 813 | var end_pos: ?usize = null; |
| | 814 | var text_fileoff: ?usize = null; |
| | 815 | var text_filesize: ?usize = null; |
| | 816 | for (parser.load_commands.items) |cmd| { |
| | 817 | switch (cmd.cmd()) { |
| | 818 | macho.LC_SYMTAB => switch (cmd) { |
| | 819 | .Symtab => |x| { |
| | 820 | end_pos = x.stroff + x.strsize; |
| | 821 | }, |
| | 822 | else => unreachable, |
| | 823 | }, |
| | 824 | macho.LC_SEGMENT_64 => switch (cmd) { |
| | 825 | .Segment => |x| { |
| | 826 | if (!mem.eql(u8, x.inner.segname[0..6], "__TEXT")) continue; |
| | 827 | text_fileoff = x.inner.fileoff; |
| | 828 | text_filesize = x.inner.filesize; |
| | 829 | }, |
| | 830 | else => unreachable, |
| | 831 | }, |
| | 832 | else => {}, |
| | 833 | } |
| | 834 | } |
| | 835 | // Pad out space for code signature |
| | 836 | std.debug.print("end_pos={},text_fileoff={},text_filesize={}\n", .{ end_pos, text_fileoff, text_filesize }); |
| 804 | } | 837 | } |
| 805 | } | 838 | } |
| 806 | | 839 | |