authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-08-26 06:30:54+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-08-26 06:30:54+02:00
log55dc81ba2a86519a2fd5bfd985d2d6465ccf4966
treefee0515cdaead8803553ec7fa12eb73620335832
parent43b6d0e4b17524fb016fcb396e87bf2df4e32456
signature Commit is signed but in an unrecognized format.

Hardcode runtime (libSystem) version to minimum possible

While we try to work out what the correlation between the OS and runtime versions is, this commit hardcodes the latter to the minimum (compat) version of 1.0.0. Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>

1 files changed, 48 insertions(+), 52 deletions(-)

src-self-hosted/link/MachO.zig+48-52
......@@ -16,8 +16,6 @@ const Module = @import("../Module.zig");
1616const link = @import("../link.zig");
1717const File = link.File;
1818
19const is_darwin = std.Target.current.os.tag.isDarwin();
20
2119pub const base_tag: File.Tag = File.Tag.macho;
2220
2321base: File,
......@@ -227,63 +225,61 @@ pub fn flush(self: *MachO, module: *Module) !void {
227225
228226 switch (self.base.options.output_mode) {
229227 .Exe => {
230 if (is_darwin) {
231 {
232 // Specify path to dynamic linker dyld
233 const cmdsize = commandSize(@sizeOf(macho.dylinker_command) + mem.lenZ(DEFAULT_DYLD_PATH));
234 const load_dylinker = [1]macho.dylinker_command{
235 .{
236 .cmd = macho.LC_LOAD_DYLINKER,
237 .cmdsize = cmdsize,
238 .name = @sizeOf(macho.dylinker_command),
239 },
240 };
241 try self.commands.append(self.base.allocator, .{
228 {
229 // Specify path to dynamic linker dyld
230 const cmdsize = commandSize(@sizeOf(macho.dylinker_command) + mem.lenZ(DEFAULT_DYLD_PATH));
231 const load_dylinker = [1]macho.dylinker_command{
232 .{
242233 .cmd = macho.LC_LOAD_DYLINKER,
243234 .cmdsize = cmdsize,
244 });
245
246 try self.base.file.?.pwriteAll(mem.sliceAsBytes(load_dylinker[0..1]), self.command_file_offset.?);
247
248 const file_offset = self.command_file_offset.? + @sizeOf(macho.dylinker_command);
249 try self.addPadding(cmdsize - @sizeOf(macho.dylinker_command), file_offset);
250
251 try self.base.file.?.pwriteAll(mem.spanZ(DEFAULT_DYLD_PATH), file_offset);
252 self.command_file_offset.? += cmdsize;
253 }
254
255 {
256 // Link against libSystem
257 const cmdsize = commandSize(@sizeOf(macho.dylib_command) + mem.lenZ(LIB_SYSTEM_PATH));
258 // According to Apple's manual, we should obtain current libSystem version using libc call
259 // NSVersionOfRunTimeLibrary.
260 const version = std.c.NSVersionOfRunTimeLibrary(LIB_SYSTEM_NAME);
261 const dylib = .{
262 .name = @sizeOf(macho.dylib_command),
263 .timestamp = 2, // not sure why not simply 0; this is reverse engineered from Mach-O files
264 .current_version = version,
265 .compatibility_version = 0x10000, // not sure why this either; value from reverse engineering
266 };
267 const load_dylib = [1]macho.dylib_command{
268 .{
269 .cmd = macho.LC_LOAD_DYLIB,
270 .cmdsize = cmdsize,
271 .dylib = dylib,
272 },
273 };
274 try self.commands.append(self.base.allocator, .{
235 .name = @sizeOf(macho.dylinker_command),
236 },
237 };
238 try self.commands.append(self.base.allocator, .{
239 .cmd = macho.LC_LOAD_DYLINKER,
240 .cmdsize = cmdsize,
241 });
242
243 try self.base.file.?.pwriteAll(mem.sliceAsBytes(load_dylinker[0..1]), self.command_file_offset.?);
244
245 const file_offset = self.command_file_offset.? + @sizeOf(macho.dylinker_command);
246 try self.addPadding(cmdsize - @sizeOf(macho.dylinker_command), file_offset);
247
248 try self.base.file.?.pwriteAll(mem.spanZ(DEFAULT_DYLD_PATH), file_offset);
249 self.command_file_offset.? += cmdsize;
250 }
251
252 {
253 // Link against libSystem
254 const cmdsize = commandSize(@sizeOf(macho.dylib_command) + mem.lenZ(LIB_SYSTEM_PATH));
255 // TODO Find a way to work out runtime version from the OS version triple stored in std.Target.
256 // In the meantime, we're gonna hardcode to the minimum compatibility version of 1.0.0.
257 const min_version = 0x10000;
258 const dylib = .{
259 .name = @sizeOf(macho.dylib_command),
260 .timestamp = 2, // not sure why not simply 0; this is reverse engineered from Mach-O files
261 .current_version = min_version,
262 .compatibility_version = min_version,
263 };
264 const load_dylib = [1]macho.dylib_command{
265 .{
275266 .cmd = macho.LC_LOAD_DYLIB,
276267 .cmdsize = cmdsize,
277 });
268 .dylib = dylib,
269 },
270 };
271 try self.commands.append(self.base.allocator, .{
272 .cmd = macho.LC_LOAD_DYLIB,
273 .cmdsize = cmdsize,
274 });
278275
279 try self.base.file.?.pwriteAll(mem.sliceAsBytes(load_dylib[0..1]), self.command_file_offset.?);
276 try self.base.file.?.pwriteAll(mem.sliceAsBytes(load_dylib[0..1]), self.command_file_offset.?);
280277
281 const file_offset = self.command_file_offset.? + @sizeOf(macho.dylib_command);
282 try self.addPadding(cmdsize - @sizeOf(macho.dylib_command), file_offset);
278 const file_offset = self.command_file_offset.? + @sizeOf(macho.dylib_command);
279 try self.addPadding(cmdsize - @sizeOf(macho.dylib_command), file_offset);
283280
284 try self.base.file.?.pwriteAll(mem.spanZ(LIB_SYSTEM_PATH), file_offset);
285 self.command_file_offset.? += cmdsize;
286 }
281 try self.base.file.?.pwriteAll(mem.spanZ(LIB_SYSTEM_PATH), file_offset);
282 self.command_file_offset.? += cmdsize;
287283 }
288284 },
289285 .Obj => return error.TODOImplementWritingObjFiles,