| ... | @@ -339,26 +339,10 @@ fn parseDylibs(self: *Zld, shared_libs: []const []const u8) !void { | ... | @@ -339,26 +339,10 @@ fn parseDylibs(self: *Zld, shared_libs: []const []const u8) !void { |
| 339 | try self.dylibs.append(self.allocator, dylib); | 339 | try self.dylibs.append(self.allocator, dylib); |
| 340 | | 340 | |
| 341 | // Add LC_LOAD_DYLIB command | 341 | // Add LC_LOAD_DYLIB command |
| 342 | const cmdsize = @intCast(u32, mem.alignForwardGeneric( | 342 | // TODO Read the timestamp and versions from the dylib itself. |
| 343 | u64, | 343 | var dylib_cmd = try createLoadDylibCommand(self.allocator, dylib.name.?, 2, 0, 0); |
| 344 | @sizeOf(macho.dylib_command) + dylib.name.?.len, | 344 | errdefer dylib_cmd.deinit(self.allocator); |
| 345 | @sizeOf(u64), | 345 | |
| 346 | )); | | |
| 347 | // TODO Read the min version from the dylib itself. | | |
| 348 | const min_version = 0x0; | | |
| 349 | var dylib_cmd = emptyGenericCommandWithData(macho.dylib_command{ | | |
| 350 | .cmd = macho.LC_LOAD_DYLIB, | | |
| 351 | .cmdsize = cmdsize, | | |
| 352 | .dylib = .{ | | |
| 353 | .name = @sizeOf(macho.dylib_command), | | |
| 354 | .timestamp = 2, // TODO parse from the dylib. | | |
| 355 | .current_version = min_version, | | |
| 356 | .compatibility_version = min_version, | | |
| 357 | }, | | |
| 358 | }); | | |
| 359 | dylib_cmd.data = try self.allocator.alloc(u8, cmdsize - dylib_cmd.inner.dylib.name); | | |
| 360 | mem.set(u8, dylib_cmd.data, 0); | | |
| 361 | mem.copy(u8, dylib_cmd.data, dylib.name.?); | | |
| 362 | try self.load_commands.append(self.allocator, .{ .Dylib = dylib_cmd }); | 346 | try self.load_commands.append(self.allocator, .{ .Dylib = dylib_cmd }); |
| 363 | } | 347 | } |
| 364 | } | 348 | } |
| ... | @@ -2061,27 +2045,10 @@ fn populateMetadata(self: *Zld) !void { | ... | @@ -2061,27 +2045,10 @@ fn populateMetadata(self: *Zld) !void { |
| 2061 | | 2045 | |
| 2062 | if (self.libsystem_cmd_index == null) { | 2046 | if (self.libsystem_cmd_index == null) { |
| 2063 | self.libsystem_cmd_index = @intCast(u16, self.load_commands.items.len); | 2047 | self.libsystem_cmd_index = @intCast(u16, self.load_commands.items.len); |
| 2064 | const cmdsize = @intCast(u32, mem.alignForwardGeneric( | 2048 | |
| 2065 | u64, | 2049 | var dylib_cmd = try createLoadDylibCommand(self.allocator, mem.spanZ(LIB_SYSTEM_PATH), 2, 0, 0); |
| 2066 | @sizeOf(macho.dylib_command) + mem.lenZ(LIB_SYSTEM_PATH), | 2050 | errdefer dylib_cmd.deinit(self.allocator); |
| 2067 | @sizeOf(u64), | 2051 | |
| 2068 | )); | | |
| 2069 | // TODO Find a way to work out runtime version from the OS version triple stored in std.Target. | | |
| 2070 | // In the meantime, we're gonna hardcode to the minimum compatibility version of 0.0.0. | | |
| 2071 | const min_version = 0x0; | | |
| 2072 | var dylib_cmd = emptyGenericCommandWithData(macho.dylib_command{ | | |
| 2073 | .cmd = macho.LC_LOAD_DYLIB, | | |
| 2074 | .cmdsize = cmdsize, | | |
| 2075 | .dylib = .{ | | |
| 2076 | .name = @sizeOf(macho.dylib_command), | | |
| 2077 | .timestamp = 2, // not sure why not simply 0; this is reverse engineered from Mach-O files | | |
| 2078 | .current_version = min_version, | | |
| 2079 | .compatibility_version = min_version, | | |
| 2080 | }, | | |
| 2081 | }); | | |
| 2082 | dylib_cmd.data = try self.allocator.alloc(u8, cmdsize - dylib_cmd.inner.dylib.name); | | |
| 2083 | mem.set(u8, dylib_cmd.data, 0); | | |
| 2084 | mem.copy(u8, dylib_cmd.data, mem.spanZ(LIB_SYSTEM_PATH)); | | |
| 2085 | try self.load_commands.append(self.allocator, .{ .Dylib = dylib_cmd }); | 2052 | try self.load_commands.append(self.allocator, .{ .Dylib = dylib_cmd }); |
| 2086 | } | 2053 | } |
| 2087 | | 2054 | |
| ... | @@ -2738,11 +2705,15 @@ fn writeSymbolTable(self: *Zld) !void { | ... | @@ -2738,11 +2705,15 @@ fn writeSymbolTable(self: *Zld) !void { |
| 2738 | | 2705 | |
| 2739 | for (self.imports.items()) |entry| { | 2706 | for (self.imports.items()) |entry| { |
| 2740 | const sym = entry.value; | 2707 | const sym = entry.value; |
| | 2708 | const ordinal = ordinal: { |
| | 2709 | const dylib = sym.cast(Symbol.Proxy).?.dylib orelse break :ordinal 1; // TODO handle libSystem |
| | 2710 | break :ordinal dylib.ordinal.?; |
| | 2711 | }; |
| 2741 | try undefs.append(.{ | 2712 | try undefs.append(.{ |
| 2742 | .n_strx = try self.makeString(sym.name), | 2713 | .n_strx = try self.makeString(sym.name), |
| 2743 | .n_type = macho.N_UNDF | macho.N_EXT, | 2714 | .n_type = macho.N_UNDF | macho.N_EXT, |
| 2744 | .n_sect = 0, | 2715 | .n_sect = 0, |
| 2745 | .n_desc = macho.N_SYMBOL_RESOLVER | macho.REFERENCE_FLAG_UNDEFINED_NON_LAZY, | 2716 | .n_desc = (ordinal * macho.N_SYMBOL_RESOLVER) | macho.REFERENCE_FLAG_UNDEFINED_NON_LAZY, |
| 2746 | .n_value = 0, | 2717 | .n_value = 0, |
| 2747 | }); | 2718 | }); |
| 2748 | } | 2719 | } |