authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-12-09 11:38:11+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-12-09 20:36:58+01:00
log184c0f3c4e140d3f0971bac184f0abce00d8d336
treeb04396a82a82f7ff351a7f7a7825f7e4f023fc1f
parent601600dec981e41d43bb72113d9284cbb9e1d9ae

stage2+macho: write code signature only when targeting aarch64


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

src/link/MachO.zig+18-10
...@@ -301,7 +301,10 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {...@@ -301,7 +301,10 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
301 const tracy = trace(@src());301 const tracy = trace(@src());
302 defer tracy.end();302 defer tracy.end();
303303
304 switch (self.base.options.output_mode) {304 const output_mode = self.base.options.output_mode;
305 const target = self.base.options.target;
306
307 switch (output_mode) {
305 .Exe => {308 .Exe => {
306 if (self.entry_addr) |addr| {309 if (self.entry_addr) |addr| {
307 // Update LC_MAIN with entry offset.310 // Update LC_MAIN with entry offset.
...@@ -312,12 +315,15 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {...@@ -312,12 +315,15 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
312 try self.writeExportTrie();315 try self.writeExportTrie();
313 try self.writeSymbolTable();316 try self.writeSymbolTable();
314 try self.writeStringTable();317 try self.writeStringTable();
315 // Preallocate space for the code signature.318
316 // We need to do this at this stage so that we have the load commands with proper values319 if (target.cpu.arch == .aarch64) {
317 // written out to the file.320 // Preallocate space for the code signature.
318 // The most important here is to have the correct vm and filesize of the __LINKEDIT segment321 // We need to do this at this stage so that we have the load commands with proper values
319 // where the code signature goes into.322 // written out to the file.
320 try self.writeCodeSignaturePadding();323 // The most important here is to have the correct vm and filesize of the __LINKEDIT segment
324 // where the code signature goes into.
325 try self.writeCodeSignaturePadding();
326 }
321 },327 },
322 .Obj => {},328 .Obj => {},
323 .Lib => return error.TODOImplementWritingLibFiles,329 .Lib => return error.TODOImplementWritingLibFiles,
...@@ -339,9 +345,11 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {...@@ -339,9 +345,11 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
339345
340 assert(!self.cmd_table_dirty);346 assert(!self.cmd_table_dirty);
341347
342 switch (self.base.options.output_mode) {348 if (target.cpu.arch == .aarch64) {
343 .Exe, .Lib => try self.writeCodeSignature(), // code signing always comes last349 switch (output_mode) {
344 else => {},350 .Exe, .Lib => try self.writeCodeSignature(), // code signing always comes last
351 else => {},
352 }
345 }353 }
346}354}
347355