| author | |
| committer | |
| log | 22540e5402799d1c4ee12b5163744cf7431a4c2c |
| tree | 87cbe3fc96ad976fb6fe07a8e35195560622babc |
| parent | ef9d6331fc9067f7ba47eccee204fa2f0c5d0a18 |
3 files changed, 16 insertions(+), 11 deletions(-)
src/link/MachO.zig+6-4| ... | @@ -769,7 +769,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No | ... | @@ -769,7 +769,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No |
| 769 | const ncmds = load_commands.calcNumOfLCs(lc_buffer.items); | 769 | const ncmds = load_commands.calcNumOfLCs(lc_buffer.items); |
| 770 | try self.base.file.?.pwriteAll(lc_buffer.items, @sizeOf(macho.mach_header_64)); | 770 | try self.base.file.?.pwriteAll(lc_buffer.items, @sizeOf(macho.mach_header_64)); |
| 771 | try self.writeHeader(ncmds, @intCast(u32, lc_buffer.items.len)); | 771 | try self.writeHeader(ncmds, @intCast(u32, lc_buffer.items.len)); |
| 772 | try self.writeUuid(comp, uuid_cmd_offset); | 772 | try self.writeUuid(comp, uuid_cmd_offset, requires_codesig); |
| 773 | 773 | ||
| 774 | if (codesig) |*csig| { | 774 | if (codesig) |*csig| { |
| 775 | try self.writeCodeSignature(comp, csig); // code signing always comes last | 775 | try self.writeCodeSignature(comp, csig); // code signing always comes last |
| ... | @@ -3507,9 +3507,11 @@ fn writeDysymtab(self: *MachO, ctx: SymtabCtx) !void { | ... | @@ -3507,9 +3507,11 @@ fn writeDysymtab(self: *MachO, ctx: SymtabCtx) !void { |
| 3507 | self.dysymtab_cmd.nindirectsyms = nindirectsyms; | 3507 | self.dysymtab_cmd.nindirectsyms = nindirectsyms; |
| 3508 | } | 3508 | } |
| 3509 | 3509 | ||
| 3510 | fn writeUuid(self: *MachO, comp: *const Compilation, uuid_cmd_offset: u32) !void { | 3510 | fn writeUuid(self: *MachO, comp: *const Compilation, uuid_cmd_offset: u32, has_codesig: bool) !void { |
| 3511 | const seg = self.getLinkeditSegmentPtr(); | 3511 | const file_size = if (!has_codesig) blk: { |
| 3512 | const file_size = seg.fileoff + seg.filesize; | 3512 | const seg = self.getLinkeditSegmentPtr(); |
| 3513 | break :blk seg.fileoff + seg.filesize; | ||
| 3514 | } else self.codesig_cmd.dataoff; | ||
| 3513 | try calcUuid(comp, self.base.file.?, file_size, &self.uuid_cmd.uuid); | 3515 | try calcUuid(comp, self.base.file.?, file_size, &self.uuid_cmd.uuid); |
| 3514 | const offset = uuid_cmd_offset + @sizeOf(macho.load_command); | 3516 | const offset = uuid_cmd_offset + @sizeOf(macho.load_command); |
| 3515 | try self.base.file.?.pwriteAll(&self.uuid_cmd.uuid, offset); | 3517 | try self.base.file.?.pwriteAll(&self.uuid_cmd.uuid, offset); |
src/link/MachO/uuid.zig+4-3| ... | @@ -15,9 +15,10 @@ const Hasher = @import("hasher.zig").ParallelHasher; | ... | @@ -15,9 +15,10 @@ const Hasher = @import("hasher.zig").ParallelHasher; |
| 15 | /// output files. Should we also do that? | 15 | /// output files. Should we also do that? |
| 16 | pub fn calcUuid(comp: *const Compilation, file: fs.File, file_size: u64, out: *[Md5.digest_length]u8) !void { | 16 | pub fn calcUuid(comp: *const Compilation, file: fs.File, file_size: u64, out: *[Md5.digest_length]u8) !void { |
| 17 | const num_chunks = comp.thread_pool.threads.len * 0x10; | 17 | const num_chunks = comp.thread_pool.threads.len * 0x10; |
| 18 | const chunk_size = @divTrunc(file_size + num_chunks - 1, num_chunks); | 18 | const chunk_size = @divTrunc(file_size, num_chunks); |
| 19 | const actual_num_chunks = if (@rem(file_size, num_chunks) > 0) num_chunks + 1 else num_chunks; | ||
| 19 | 20 | ||
| 20 | const hashes = try comp.gpa.alloc([Md5.digest_length]u8, num_chunks); | 21 | const hashes = try comp.gpa.alloc([Md5.digest_length]u8, actual_num_chunks); |
| 21 | defer comp.gpa.free(hashes); | 22 | defer comp.gpa.free(hashes); |
| 22 | 23 | ||
| 23 | var hasher = Hasher(Md5){ .allocator = comp.gpa, .thread_pool = comp.thread_pool }; | 24 | var hasher = Hasher(Md5){ .allocator = comp.gpa, .thread_pool = comp.thread_pool }; |
| ... | @@ -26,7 +27,7 @@ pub fn calcUuid(comp: *const Compilation, file: fs.File, file_size: u64, out: *[ | ... | @@ -26,7 +27,7 @@ pub fn calcUuid(comp: *const Compilation, file: fs.File, file_size: u64, out: *[ |
| 26 | .max_file_size = file_size, | 27 | .max_file_size = file_size, |
| 27 | }); | 28 | }); |
| 28 | 29 | ||
| 29 | const final_buffer = try comp.gpa.alloc(u8, num_chunks * Md5.digest_length); | 30 | const final_buffer = try comp.gpa.alloc(u8, actual_num_chunks * Md5.digest_length); |
| 30 | defer comp.gpa.free(final_buffer); | 31 | defer comp.gpa.free(final_buffer); |
| 31 | 32 | ||
| 32 | for (hashes, 0..) |hash, i| { | 33 | for (hashes, 0..) |hash, i| { |
src/link/MachO/zld.zig+6-4| ... | @@ -2576,9 +2576,11 @@ pub const Zld = struct { | ... | @@ -2576,9 +2576,11 @@ pub const Zld = struct { |
| 2576 | self.dysymtab_cmd.nindirectsyms = nindirectsyms; | 2576 | self.dysymtab_cmd.nindirectsyms = nindirectsyms; |
| 2577 | } | 2577 | } |
| 2578 | 2578 | ||
| 2579 | fn writeUuid(self: *Zld, comp: *const Compilation, uuid_cmd_offset: u32) !void { | 2579 | fn writeUuid(self: *Zld, comp: *const Compilation, uuid_cmd_offset: u32, has_codesig: bool) !void { |
| 2580 | const seg = self.getLinkeditSegmentPtr(); | 2580 | const file_size = if (!has_codesig) blk: { |
| 2581 | const file_size = seg.fileoff + seg.filesize; | 2581 | const seg = self.getLinkeditSegmentPtr(); |
| 2582 | break :blk seg.fileoff + seg.filesize; | ||
| 2583 | } else self.codesig_cmd.dataoff; | ||
| 2582 | try calcUuid(comp, self.file, file_size, &self.uuid_cmd.uuid); | 2584 | try calcUuid(comp, self.file, file_size, &self.uuid_cmd.uuid); |
| 2583 | const offset = uuid_cmd_offset + @sizeOf(macho.load_command); | 2585 | const offset = uuid_cmd_offset + @sizeOf(macho.load_command); |
| 2584 | try self.file.pwriteAll(&self.uuid_cmd.uuid, offset); | 2586 | try self.file.pwriteAll(&self.uuid_cmd.uuid, offset); |
| ... | @@ -3953,7 +3955,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr | ... | @@ -3953,7 +3955,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr |
| 3953 | const ncmds = load_commands.calcNumOfLCs(lc_buffer.items); | 3955 | const ncmds = load_commands.calcNumOfLCs(lc_buffer.items); |
| 3954 | try zld.file.pwriteAll(lc_buffer.items, @sizeOf(macho.mach_header_64)); | 3956 | try zld.file.pwriteAll(lc_buffer.items, @sizeOf(macho.mach_header_64)); |
| 3955 | try zld.writeHeader(ncmds, @intCast(u32, lc_buffer.items.len)); | 3957 | try zld.writeHeader(ncmds, @intCast(u32, lc_buffer.items.len)); |
| 3956 | try zld.writeUuid(comp, uuid_cmd_offset); | 3958 | try zld.writeUuid(comp, uuid_cmd_offset, requires_codesig); |
| 3957 | 3959 | ||
| 3958 | if (codesig) |*csig| { | 3960 | if (codesig) |*csig| { |
| 3959 | try zld.writeCodeSignature(comp, csig); // code signing always comes last | 3961 | try zld.writeCodeSignature(comp, csig); // code signing always comes last |