diff --git a/src/link/MachO.zig b/src/link/MachO.zig index 4cca79f994..6a1f21778d 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -530,7 +530,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No try self.writeLinkeditSegmentData(); - var codesig: ?CodeSignature = if (self.requiresCodeSignature()) blk: { + var codesig: ?CodeSignature = if (requiresCodeSignature(&self.base.options)) blk: { // Preallocate space for the code signature. // We need to do this at this stage so that we have the load commands with proper values // written out to the file. @@ -4767,11 +4767,11 @@ pub inline fn getPageSize(cpu_arch: std.Target.Cpu.Arch) u16 { }; } -pub fn requiresCodeSignature(self: MachO) bool { - if (self.base.options.entitlements) |_| return true; - const cpu_arch = self.base.options.target.cpu.arch; - const os_tag = self.base.options.target.os.tag; - const abi = self.base.options.target.abi; +pub fn requiresCodeSignature(options: *const link.Options) bool { + if (options.entitlements) |_| return true; + const cpu_arch = options.target.cpu.arch; + const os_tag = options.target.os.tag; + const abi = options.target.abi; if (cpu_arch == .aarch64 and (os_tag == .macos or abi == .simulator)) return true; return false; } diff --git a/src/link/MachO/load_commands.zig b/src/link/MachO/load_commands.zig index b548bee2fc..d7b13104bf 100644 --- a/src/link/MachO/load_commands.zig +++ b/src/link/MachO/load_commands.zig @@ -91,17 +91,8 @@ fn calcLCsSize(gpa: Allocator, options: *const link.Options, ctx: CalcLCsSizeCtx ); } // LC_CODE_SIGNATURE - { - const target = options.target; - const requires_codesig = blk: { - if (options.entitlements) |_| break :blk true; - if (target.cpu.arch == .aarch64 and (target.os.tag == .macos or target.abi == .simulator)) - break :blk true; - break :blk false; - }; - if (requires_codesig) { - sizeofcmds += @sizeOf(macho.linkedit_data_command); - } + if (MachO.requiresCodeSignature(options)) { + sizeofcmds += @sizeOf(macho.linkedit_data_command); } return @as(u32, @intCast(sizeofcmds)); @@ -374,3 +365,4 @@ const mem = std.mem; const Allocator = mem.Allocator; const Dylib = @import("Dylib.zig"); +const MachO = @import("../MachO.zig"); diff --git a/src/link/MachO/zld.zig b/src/link/MachO/zld.zig index efa23d4641..011158ba24 100644 --- a/src/link/MachO/zld.zig +++ b/src/link/MachO/zld.zig @@ -529,7 +529,7 @@ pub fn linkWithZld( } // Write code signature padding if required - var codesig: ?CodeSignature = if (macho_file.requiresCodeSignature()) blk: { + var codesig: ?CodeSignature = if (MachO.requiresCodeSignature(&macho_file.base.options)) blk: { // Preallocate space for the code signature. // We need to do this at this stage so that we have the load commands with proper values // written out to the file.