authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-09-03 08:18:29+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-09-04 09:07:49+02:00
logbff54536ff2cab302924dc77e298d6dbb4171209
tree99daa61165e26a4b325d2b621ae580f8d980a4a4
parent5cc1831ca423a777eeea6b147cedcd5165d1c056

macho: check if we should emit LC_VERSION_MIN_ if target low enough


2 files changed, 20 insertions(+), 8 deletions(-)

src/link/MachO.zig+1-1
......@@ -564,7 +564,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
564564 null;
565565 if (platform.isBuildVersionCompatible()) {
566566 try load_commands.writeBuildVersionLC(platform, sdk_version, lc_writer);
567 } else {
567 } else if (platform.isVersionMinCompatible()) {
568568 try load_commands.writeVersionMinLC(platform, sdk_version, lc_writer);
569569 }
570570 }
src/link/MachO/load_commands.zig+19-7
......@@ -76,13 +76,16 @@ fn calcLCsSize(gpa: Allocator, options: *const link.Options, ctx: CalcLCsSizeCtx
7676 }
7777 // LC_SOURCE_VERSION
7878 sizeofcmds += @sizeOf(macho.source_version_command);
79 // LC_BUILD_VERSION or LC_VERSION_MIN_
80 if (Platform.fromTarget(options.target).isBuildVersionCompatible()) {
81 // LC_BUILD_VERSION
82 sizeofcmds += @sizeOf(macho.build_version_command) + @sizeOf(macho.build_tool_version);
83 } else {
84 // LC_VERSION_MIN_
85 sizeofcmds += @sizeOf(macho.version_min_command);
79 // LC_BUILD_VERSION or LC_VERSION_MIN_ or nothing
80 {
81 const platform = Platform.fromTarget(options.target);
82 if (platform.isBuildVersionCompatible()) {
83 // LC_BUILD_VERSION
84 sizeofcmds += @sizeOf(macho.build_version_command) + @sizeOf(macho.build_tool_version);
85 } else if (platform.isVersionMinCompatible()) {
86 // LC_VERSION_MIN_
87 sizeofcmds += @sizeOf(macho.version_min_command);
88 }
8689 }
8790 // LC_UUID
8891 sizeofcmds += @sizeOf(macho.uuid_command);
......@@ -384,6 +387,15 @@ pub const Platform = struct {
384387 return false;
385388 }
386389
390 pub fn isVersionMinCompatible(plat: Platform) bool {
391 inline for (supported_platforms) |sup_plat| {
392 if (sup_plat[0] == plat.os_tag and sup_plat[1] == plat.abi) {
393 return sup_plat[3] <= plat.toAppleVersion();
394 }
395 }
396 return false;
397 }
398
387399 pub fn fmtTarget(plat: Platform, cpu_arch: std.Target.Cpu.Arch) std.fmt.Formatter(formatTarget) {
388400 return .{ .data = .{ .platform = plat, .cpu_arch = cpu_arch } };
389401 }