| ... | ... | @@ -107,7 +107,6 @@ offset_table: std.ArrayListUnmanaged(u64) = .{}, |
| 107 | 107 | error_flags: File.ErrorFlags = File.ErrorFlags{}, |
| 108 | 108 | |
| 109 | 109 | cmd_table_dirty: bool = false, |
| 110 | | other_dylibs_present: bool = false, |
| 111 | 110 | |
| 112 | 111 | /// A list of text blocks that have surplus capacity. This list can have false |
| 113 | 112 | /// positives, as functions grow and shrink over time, only sometimes being added |
| ... | ... | @@ -755,8 +754,8 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { |
| 755 | 754 | // binaries up! |
| 756 | 755 | const out_file = try directory.handle.openFile(self.base.options.emit.?.sub_path, .{ .write = true }); |
| 757 | 756 | try self.parseFromFile(out_file); |
| 757 | |
| 758 | 758 | if (self.libsystem_cmd_index == null) { |
| 759 | | if (self.other_dylibs_present) return; // TODO We cannot handle this situation yet. |
| 760 | 759 | const text_segment = self.load_commands.items[self.text_segment_cmd_index.?].Segment; |
| 761 | 760 | const text_section = text_segment.sections.items[self.text_section_index.?]; |
| 762 | 761 | const after_last_cmd_offset = self.header.?.sizeofcmds + @sizeOf(macho.mach_header_64); |
| ... | ... | @@ -769,6 +768,18 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { |
| 769 | 768 | return error.NotEnoughPadding; |
| 770 | 769 | } |
| 771 | 770 | |
| 771 | // Calculate next available dylib ordinal. |
| 772 | const next_ordinal = blk: { |
| 773 | var ordinal: u32 = 1; |
| 774 | for (self.load_commands.items) |cmd| { |
| 775 | switch (cmd) { |
| 776 | .Dylib => ordinal += 1, |
| 777 | else => {}, |
| 778 | } |
| 779 | } |
| 780 | break :blk ordinal; |
| 781 | }; |
| 782 | |
| 772 | 783 | // Add load dylib load command |
| 773 | 784 | self.libsystem_cmd_index = @intCast(u16, self.load_commands.items.len); |
| 774 | 785 | const cmdsize = mem.alignForwardGeneric(u64, @sizeOf(macho.dylib_command) + mem.lenZ(LIB_SYSTEM_PATH), @sizeOf(u64)); |
| ... | ... | @@ -2007,8 +2018,6 @@ fn parseFromFile(self: *MachO, file: fs.File) !void { |
| 2007 | 2018 | const x = cmd.Dylib; |
| 2008 | 2019 | if (parseAndCmpName(x.data, mem.spanZ(LIB_SYSTEM_PATH))) { |
| 2009 | 2020 | self.libsystem_cmd_index = i; |
| 2010 | | } else { |
| 2011 | | self.other_dylibs_present = true; |
| 2012 | 2021 | } |
| 2013 | 2022 | }, |
| 2014 | 2023 | macho.LC_FUNCTION_STARTS => { |