authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-11-12 21:29:25+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-11-26 11:50:09+01:00
log1bec531cf234f04818e22b7b792b18a88c5faf88
tree88230e4f49a5238c644f7c46c5c895547c898b6b
parent72310db1da792aae05edffe96082d97bb04cf7e5

stage2 MachO: add source version load cmd


2 files changed, 28 insertions(+), 0 deletions(-)

lib/std/macho.zig+13
...@@ -722,6 +722,19 @@ pub const version_min_command = extern struct {...@@ -722,6 +722,19 @@ pub const version_min_command = extern struct {
722 sdk: u32,722 sdk: u32,
723};723};
724724
725/// The source_version_command is an optional load command containing
726/// the version of the sources used to build the binary.
727pub const source_version_command = extern struct {
728 /// LC_SOURCE_VERSION
729 cmd: u32,
730
731 /// sizeof(source_version_command)
732 cmdsize: u32,
733
734 /// A.B.C.D.E packed as a24.b10.c10.d10.e10
735 version: u64,
736};
737
725/// After MacOS X 10.1 when a new load command is added that is required to be738/// After MacOS X 10.1 when a new load command is added that is required to be
726/// understood by the dynamic linker for the image to execute properly the739/// understood by the dynamic linker for the image to execute properly the
727/// LC_REQ_DYLD bit will be or'ed into the load command constant. If the dynamic740/// LC_REQ_DYLD bit will be or'ed into the load command constant. If the dynamic
src/link/MachO.zig+15
...@@ -34,6 +34,7 @@ const LoadCommand = union(enum) {...@@ -34,6 +34,7 @@ const LoadCommand = union(enum) {
34 Dylib: macho.dylib_command,34 Dylib: macho.dylib_command,
35 EntryPoint: macho.entry_point_command,35 EntryPoint: macho.entry_point_command,
36 MinVersion: macho.version_min_command,36 MinVersion: macho.version_min_command,
37 SourceVersion: macho.source_version_command,
3738
38 pub fn cmdsize(self: LoadCommand) u32 {39 pub fn cmdsize(self: LoadCommand) u32 {
39 return switch (self) {40 return switch (self) {
...@@ -46,6 +47,7 @@ const LoadCommand = union(enum) {...@@ -46,6 +47,7 @@ const LoadCommand = union(enum) {
46 .Dylib => |x| x.cmdsize,47 .Dylib => |x| x.cmdsize,
47 .EntryPoint => |x| x.cmdsize,48 .EntryPoint => |x| x.cmdsize,
48 .MinVersion => |x| x.cmdsize,49 .MinVersion => |x| x.cmdsize,
50 .SourceVersion => |x| x.cmdsize,
49 };51 };
50 }52 }
5153
...@@ -60,6 +62,7 @@ const LoadCommand = union(enum) {...@@ -60,6 +62,7 @@ const LoadCommand = union(enum) {
60 .Dylib => |cmd| writeGeneric(cmd, file, offset),62 .Dylib => |cmd| writeGeneric(cmd, file, offset),
61 .EntryPoint => |cmd| writeGeneric(cmd, file, offset),63 .EntryPoint => |cmd| writeGeneric(cmd, file, offset),
62 .MinVersion => |cmd| writeGeneric(cmd, file, offset),64 .MinVersion => |cmd| writeGeneric(cmd, file, offset),
65 .SourceVersion => |cmd| writeGeneric(cmd, file, offset),
63 };66 };
64 }67 }
6568
...@@ -101,6 +104,8 @@ function_starts_cmd_index: ?u16 = null,...@@ -101,6 +104,8 @@ function_starts_cmd_index: ?u16 = null,
101main_cmd_index: ?u16 = null,104main_cmd_index: ?u16 = null,
102/// Minimum OS version105/// Minimum OS version
103version_min_cmd_index: ?u16 = null,106version_min_cmd_index: ?u16 = null,
107/// Source version
108source_version_cmd_index: ?u16 = null,
104109
105/// Table of all sections110/// Table of all sections
106sections: std.ArrayListUnmanaged(macho.section_64) = .{},111sections: std.ArrayListUnmanaged(macho.section_64) = .{},
...@@ -1377,6 +1382,16 @@ pub fn populateMissingMetadata(self: *MachO) !void {...@@ -1377,6 +1382,16 @@ pub fn populateMissingMetadata(self: *MachO) !void {
1377 },1382 },
1378 });1383 });
1379 }1384 }
1385 if (self.source_version_cmd_index == null) {
1386 self.source_version_cmd_index = @intCast(u16, self.load_commands.items.len);
1387 try self.load_commands.append(self.base.allocator, .{
1388 .SourceVersion = .{
1389 .cmd = macho.LC_SOURCE_VERSION,
1390 .cmdsize = @sizeOf(macho.source_version_command),
1391 .version = 0x0,
1392 },
1393 });
1394 }
1380 {1395 {
1381 const linkedit = &self.load_commands.items[self.linkedit_segment_cmd_index.?].Segment;1396 const linkedit = &self.load_commands.items[self.linkedit_segment_cmd_index.?].Segment;
1382 const dyld_info = &self.load_commands.items[self.dyld_info_cmd_index.?].DyldInfo;1397 const dyld_info = &self.load_commands.items[self.dyld_info_cmd_index.?].DyldInfo;