diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2020-12-11 17:11:40 +0100 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2020-12-17 10:04:53 +0100 |
| commit | f5a0b9315b4920c5e9e9f886e29101dcc8ae7cc7 (patch) | |
| tree | fcd3fc913712ef910ba6823b76d781d474d0bdc3 /src | |
| parent | cc2592969df1c0b2ea6d62eb9384b0022b98305b (diff) | |
| download | zig-f5a0b9315b4920c5e9e9f886e29101dcc8ae7cc7.tar.gz zig-f5a0b9315b4920c5e9e9f886e29101dcc8ae7cc7.zip | |
macho: calculate next available dylib ordinal
Diffstat (limited to 'src')
| -rw-r--r-- | src/link/MachO.zig | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/link/MachO.zig b/src/link/MachO.zig index 8f3852b61c..681c06b06d 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -107,7 +107,6 @@ offset_table: std.ArrayListUnmanaged(u64) = .{}, error_flags: File.ErrorFlags = File.ErrorFlags{}, cmd_table_dirty: bool = false, -other_dylibs_present: bool = false, /// A list of text blocks that have surplus capacity. This list can have false /// positives, as functions grow and shrink over time, only sometimes being added @@ -755,8 +754,8 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { // binaries up! const out_file = try directory.handle.openFile(self.base.options.emit.?.sub_path, .{ .write = true }); try self.parseFromFile(out_file); + if (self.libsystem_cmd_index == null) { - if (self.other_dylibs_present) return; // TODO We cannot handle this situation yet. const text_segment = self.load_commands.items[self.text_segment_cmd_index.?].Segment; const text_section = text_segment.sections.items[self.text_section_index.?]; const after_last_cmd_offset = self.header.?.sizeofcmds + @sizeOf(macho.mach_header_64); @@ -769,6 +768,18 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { return error.NotEnoughPadding; } + // Calculate next available dylib ordinal. + const next_ordinal = blk: { + var ordinal: u32 = 1; + for (self.load_commands.items) |cmd| { + switch (cmd) { + .Dylib => ordinal += 1, + else => {}, + } + } + break :blk ordinal; + }; + // Add load dylib load command self.libsystem_cmd_index = @intCast(u16, self.load_commands.items.len); 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 { const x = cmd.Dylib; if (parseAndCmpName(x.data, mem.spanZ(LIB_SYSTEM_PATH))) { self.libsystem_cmd_index = i; - } else { - self.other_dylibs_present = true; } }, macho.LC_FUNCTION_STARTS => { |
