authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-08-28 19:40:10+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-08-29 11:40:20+02:00
logec03619dcfa025442f6a70cbdfeafd5882591b64
treebb12250c1bc67c0e6d7dc662c65f17cae71fb600
parent052984c5ae43a9846f012c3b3b1449c8aef47d2f

macho: make MachO.requiresCodeSignature accept link.Options


3 files changed, 10 insertions(+), 18 deletions(-)

src/link/MachO.zig+6-6
......@@ -530,7 +530,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
530530
531531 try self.writeLinkeditSegmentData();
532532
533 var codesig: ?CodeSignature = if (self.requiresCodeSignature()) blk: {
533 var codesig: ?CodeSignature = if (requiresCodeSignature(&self.base.options)) blk: {
534534 // Preallocate space for the code signature.
535535 // We need to do this at this stage so that we have the load commands with proper values
536536 // written out to the file.
......@@ -4767,11 +4767,11 @@ pub inline fn getPageSize(cpu_arch: std.Target.Cpu.Arch) u16 {
47674767 };
47684768}
47694769
4770pub fn requiresCodeSignature(self: MachO) bool {
4771 if (self.base.options.entitlements) |_| return true;
4772 const cpu_arch = self.base.options.target.cpu.arch;
4773 const os_tag = self.base.options.target.os.tag;
4774 const abi = self.base.options.target.abi;
4770pub fn requiresCodeSignature(options: *const link.Options) bool {
4771 if (options.entitlements) |_| return true;
4772 const cpu_arch = options.target.cpu.arch;
4773 const os_tag = options.target.os.tag;
4774 const abi = options.target.abi;
47754775 if (cpu_arch == .aarch64 and (os_tag == .macos or abi == .simulator)) return true;
47764776 return false;
47774777}
src/link/MachO/load_commands.zig+3-11
......@@ -91,17 +91,8 @@ fn calcLCsSize(gpa: Allocator, options: *const link.Options, ctx: CalcLCsSizeCtx
9191 );
9292 }
9393 // LC_CODE_SIGNATURE
94 {
95 const target = options.target;
96 const requires_codesig = blk: {
97 if (options.entitlements) |_| break :blk true;
98 if (target.cpu.arch == .aarch64 and (target.os.tag == .macos or target.abi == .simulator))
99 break :blk true;
100 break :blk false;
101 };
102 if (requires_codesig) {
103 sizeofcmds += @sizeOf(macho.linkedit_data_command);
104 }
94 if (MachO.requiresCodeSignature(options)) {
95 sizeofcmds += @sizeOf(macho.linkedit_data_command);
10596 }
10697
10798 return @as(u32, @intCast(sizeofcmds));
......@@ -374,3 +365,4 @@ const mem = std.mem;
374365
375366const Allocator = mem.Allocator;
376367const Dylib = @import("Dylib.zig");
368const MachO = @import("../MachO.zig");
src/link/MachO/zld.zig+1-1
......@@ -529,7 +529,7 @@ pub fn linkWithZld(
529529 }
530530
531531 // Write code signature padding if required
532 var codesig: ?CodeSignature = if (macho_file.requiresCodeSignature()) blk: {
532 var codesig: ?CodeSignature = if (MachO.requiresCodeSignature(&macho_file.base.options)) blk: {
533533 // Preallocate space for the code signature.
534534 // We need to do this at this stage so that we have the load commands with proper values
535535 // written out to the file.