authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-12-11 17:11:40+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-12-17 10:04:53+01:00
logf5a0b9315b4920c5e9e9f886e29101dcc8ae7cc7
treefcd3fc913712ef910ba6823b76d781d474d0bdc3
parentcc2592969df1c0b2ea6d62eb9384b0022b98305b

macho: calculate next available dylib ordinal


1 files changed, 13 insertions(+), 4 deletions(-)

src/link/MachO.zig+13-4
......@@ -107,7 +107,6 @@ offset_table: std.ArrayListUnmanaged(u64) = .{},
107107error_flags: File.ErrorFlags = File.ErrorFlags{},
108108
109109cmd_table_dirty: bool = false,
110other_dylibs_present: bool = false,
111110
112111/// A list of text blocks that have surplus capacity. This list can have false
113112/// positives, as functions grow and shrink over time, only sometimes being added
......@@ -755,8 +754,8 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
755754 // binaries up!
756755 const out_file = try directory.handle.openFile(self.base.options.emit.?.sub_path, .{ .write = true });
757756 try self.parseFromFile(out_file);
757
758758 if (self.libsystem_cmd_index == null) {
759 if (self.other_dylibs_present) return; // TODO We cannot handle this situation yet.
760759 const text_segment = self.load_commands.items[self.text_segment_cmd_index.?].Segment;
761760 const text_section = text_segment.sections.items[self.text_section_index.?];
762761 const after_last_cmd_offset = self.header.?.sizeofcmds + @sizeOf(macho.mach_header_64);
......@@ -769,6 +768,18 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
769768 return error.NotEnoughPadding;
770769 }
771770
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
772783 // Add load dylib load command
773784 self.libsystem_cmd_index = @intCast(u16, self.load_commands.items.len);
774785 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 {
20072018 const x = cmd.Dylib;
20082019 if (parseAndCmpName(x.data, mem.spanZ(LIB_SYSTEM_PATH))) {
20092020 self.libsystem_cmd_index = i;
2010 } else {
2011 self.other_dylibs_present = true;
20122021 }
20132022 },
20142023 macho.LC_FUNCTION_STARTS => {