authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-11-28 10:50:15+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-12-01 10:49:31+01:00
loge8ffae60a27e4b82c23c1c9943899850bd18db9a
tree688513ad6d94c776333da604b665c20f7b01d381
parent02e12ede46502e7c0f04ae94292e005a113a84c9

lld: parse output lld file


1 files changed, 33 insertions(+), 0 deletions(-)

src/link/MachO.zig+33
......@@ -23,6 +23,7 @@ const target_util = @import("../target.zig");
2323
2424const Trie = @import("MachO/Trie.zig");
2525const CodeSignature = @import("MachO/CodeSignature.zig");
26const Parser = @import("MachO/Parser.zig");
2627
2728pub const base_tag: File.Tag = File.Tag.macho;
2829
......@@ -801,6 +802,38 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
801802 if (stderr_context.data.items.len != 0) {
802803 std.log.warn("unexpected LLD stderr: {}", .{stderr_context.data.items});
803804 }
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 });
804837 }
805838 }
806839