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...@@ -530,7 +530,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
530530
531 try self.writeLinkeditSegmentData();531 try self.writeLinkeditSegmentData();
532532
533 var codesig: ?CodeSignature = if (self.requiresCodeSignature()) blk: {533 var codesig: ?CodeSignature = if (requiresCodeSignature(&self.base.options)) blk: {
534 // Preallocate space for the code signature.534 // Preallocate space for the code signature.
535 // We need to do this at this stage so that we have the load commands with proper values535 // We need to do this at this stage so that we have the load commands with proper values
536 // written out to the file.536 // written out to the file.
...@@ -4767,11 +4767,11 @@ pub inline fn getPageSize(cpu_arch: std.Target.Cpu.Arch) u16 {...@@ -4767,11 +4767,11 @@ pub inline fn getPageSize(cpu_arch: std.Target.Cpu.Arch) u16 {
4767 };4767 };
4768}4768}
47694769
4770pub fn requiresCodeSignature(self: MachO) bool {4770pub fn requiresCodeSignature(options: *const link.Options) bool {
4771 if (self.base.options.entitlements) |_| return true;4771 if (options.entitlements) |_| return true;
4772 const cpu_arch = self.base.options.target.cpu.arch;4772 const cpu_arch = options.target.cpu.arch;
4773 const os_tag = self.base.options.target.os.tag;4773 const os_tag = options.target.os.tag;
4774 const abi = self.base.options.target.abi;4774 const abi = options.target.abi;
4775 if (cpu_arch == .aarch64 and (os_tag == .macos or abi == .simulator)) return true;4775 if (cpu_arch == .aarch64 and (os_tag == .macos or abi == .simulator)) return true;
4776 return false;4776 return false;
4777}4777}
src/link/MachO/load_commands.zig+3-11
...@@ -91,17 +91,8 @@ fn calcLCsSize(gpa: Allocator, options: *const link.Options, ctx: CalcLCsSizeCtx...@@ -91,17 +91,8 @@ fn calcLCsSize(gpa: Allocator, options: *const link.Options, ctx: CalcLCsSizeCtx
91 );91 );
92 }92 }
93 // LC_CODE_SIGNATURE93 // LC_CODE_SIGNATURE
94 {94 if (MachO.requiresCodeSignature(options)) {
95 const target = options.target;95 sizeofcmds += @sizeOf(macho.linkedit_data_command);
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 }
105 }96 }
10697
107 return @as(u32, @intCast(sizeofcmds));98 return @as(u32, @intCast(sizeofcmds));
...@@ -374,3 +365,4 @@ const mem = std.mem;...@@ -374,3 +365,4 @@ const mem = std.mem;
374365
375const Allocator = mem.Allocator;366const Allocator = mem.Allocator;
376const Dylib = @import("Dylib.zig");367const Dylib = @import("Dylib.zig");
368const MachO = @import("../MachO.zig");
src/link/MachO/zld.zig+1-1
...@@ -529,7 +529,7 @@ pub fn linkWithZld(...@@ -529,7 +529,7 @@ pub fn linkWithZld(
529 }529 }
530530
531 // Write code signature padding if required531 // 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: {
533 // Preallocate space for the code signature.533 // Preallocate space for the code signature.
534 // We need to do this at this stage so that we have the load commands with proper values534 // We need to do this at this stage so that we have the load commands with proper values
535 // written out to the file.535 // written out to the file.