authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-06-19 12:53:26+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-06-19 12:53:26+02:00
log8087c134dbeaa2925948597883d6a401f251a716
tree507644a52f144c677652e89f8eb3a9daff729b3b
parentc2554cf0f17668659d0b898fcb43b3efb8694d3a

macho: calculate UUID chunk size based on available thread count


2 files changed, 3 insertions(+), 3 deletions(-)

CMakeLists.txt+1
...@@ -597,6 +597,7 @@ set(ZIG_STAGE2_SOURCES...@@ -597,6 +597,7 @@ set(ZIG_STAGE2_SOURCES
597 "${CMAKE_SOURCE_DIR}/src/link/MachO/hasher.zig"597 "${CMAKE_SOURCE_DIR}/src/link/MachO/hasher.zig"
598 "${CMAKE_SOURCE_DIR}/src/link/MachO/load_commands.zig"598 "${CMAKE_SOURCE_DIR}/src/link/MachO/load_commands.zig"
599 "${CMAKE_SOURCE_DIR}/src/link/MachO/thunks.zig"599 "${CMAKE_SOURCE_DIR}/src/link/MachO/thunks.zig"
600 "${CMAKE_SOURCE_DIR}/src/link/MachO/uuid.zig"
600 "${CMAKE_SOURCE_DIR}/src/link/MachO/zld.zig"601 "${CMAKE_SOURCE_DIR}/src/link/MachO/zld.zig"
601 "${CMAKE_SOURCE_DIR}/src/link/Plan9.zig"602 "${CMAKE_SOURCE_DIR}/src/link/Plan9.zig"
602 "${CMAKE_SOURCE_DIR}/src/link/Plan9/aout.zig"603 "${CMAKE_SOURCE_DIR}/src/link/Plan9/aout.zig"
src/link/MachO/uuid.zig+2-3
...@@ -7,9 +7,6 @@ const Compilation = @import("../../Compilation.zig");...@@ -7,9 +7,6 @@ const Compilation = @import("../../Compilation.zig");
7const Md5 = std.crypto.hash.Md5;7const Md5 = std.crypto.hash.Md5;
8const Hasher = @import("hasher.zig").ParallelHasher;8const Hasher = @import("hasher.zig").ParallelHasher;
99
10/// Somewhat random chunk size for MD5 hash calculation.
11pub const chunk_size = 0x4000;
12
13/// Calculates Md5 hash of each chunk in parallel and then hashes all Md5 hashes to produce10/// Calculates Md5 hash of each chunk in parallel and then hashes all Md5 hashes to produce
14/// the final digest.11/// the final digest.
15/// While this is NOT a correct MD5 hash of the contents, this methodology is used by LLVM/LLD12/// While this is NOT a correct MD5 hash of the contents, this methodology is used by LLVM/LLD
...@@ -17,6 +14,8 @@ pub const chunk_size = 0x4000;...@@ -17,6 +14,8 @@ pub const chunk_size = 0x4000;
17/// TODO LLD also hashes the output filename to disambiguate between same builds with different14/// TODO LLD also hashes the output filename to disambiguate between same builds with different
18/// output files. Should we also do that?15/// output files. Should we also do that?
19pub fn calcUuid(comp: *const Compilation, file: fs.File, file_size: u64, out: *[Md5.digest_length]u8) !void {16pub fn calcUuid(comp: *const Compilation, file: fs.File, file_size: u64, out: *[Md5.digest_length]u8) !void {
17 const num_chunks = @intCast(u64, comp.thread_pool.threads.len) * 10;
18 const chunk_size = @divTrunc(file_size + num_chunks - 1, num_chunks);
20 const total_hashes = mem.alignForward(u64, file_size, chunk_size) / chunk_size;19 const total_hashes = mem.alignForward(u64, file_size, chunk_size) / chunk_size;
2120
22 const hashes = try comp.gpa.alloc([Md5.digest_length]u8, total_hashes);21 const hashes = try comp.gpa.alloc([Md5.digest_length]u8, total_hashes);