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 {
722722 sdk: u32,
723723};
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
725738/// After MacOS X 10.1 when a new load command is added that is required to be
726739/// understood by the dynamic linker for the image to execute properly the
727740/// 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) {
3434 Dylib: macho.dylib_command,
3535 EntryPoint: macho.entry_point_command,
3636 MinVersion: macho.version_min_command,
37 SourceVersion: macho.source_version_command,
3738
3839 pub fn cmdsize(self: LoadCommand) u32 {
3940 return switch (self) {
......@@ -46,6 +47,7 @@ const LoadCommand = union(enum) {
4647 .Dylib => |x| x.cmdsize,
4748 .EntryPoint => |x| x.cmdsize,
4849 .MinVersion => |x| x.cmdsize,
50 .SourceVersion => |x| x.cmdsize,
4951 };
5052 }
5153
......@@ -60,6 +62,7 @@ const LoadCommand = union(enum) {
6062 .Dylib => |cmd| writeGeneric(cmd, file, offset),
6163 .EntryPoint => |cmd| writeGeneric(cmd, file, offset),
6264 .MinVersion => |cmd| writeGeneric(cmd, file, offset),
65 .SourceVersion => |cmd| writeGeneric(cmd, file, offset),
6366 };
6467 }
6568
......@@ -101,6 +104,8 @@ function_starts_cmd_index: ?u16 = null,
101104main_cmd_index: ?u16 = null,
102105/// Minimum OS version
103106version_min_cmd_index: ?u16 = null,
107/// Source version
108source_version_cmd_index: ?u16 = null,
104109
105110/// Table of all sections
106111sections: std.ArrayListUnmanaged(macho.section_64) = .{},
......@@ -1377,6 +1382,16 @@ pub fn populateMissingMetadata(self: *MachO) !void {
13771382 },
13781383 });
13791384 }
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 }
13801395 {
13811396 const linkedit = &self.load_commands.items[self.linkedit_segment_cmd_index.?].Segment;
13821397 const dyld_info = &self.load_commands.items[self.dyld_info_cmd_index.?].DyldInfo;