macho: calculate UUID chunk size based on available thread count
This commit is contained in:
@@ -597,6 +597,7 @@ set(ZIG_STAGE2_SOURCES
|
||||
"${CMAKE_SOURCE_DIR}/src/link/MachO/hasher.zig"
|
||||
"${CMAKE_SOURCE_DIR}/src/link/MachO/load_commands.zig"
|
||||
"${CMAKE_SOURCE_DIR}/src/link/MachO/thunks.zig"
|
||||
"${CMAKE_SOURCE_DIR}/src/link/MachO/uuid.zig"
|
||||
"${CMAKE_SOURCE_DIR}/src/link/MachO/zld.zig"
|
||||
"${CMAKE_SOURCE_DIR}/src/link/Plan9.zig"
|
||||
"${CMAKE_SOURCE_DIR}/src/link/Plan9/aout.zig"
|
||||
|
||||
@@ -7,9 +7,6 @@ const Compilation = @import("../../Compilation.zig");
|
||||
const Md5 = std.crypto.hash.Md5;
|
||||
const Hasher = @import("hasher.zig").ParallelHasher;
|
||||
|
||||
/// Somewhat random chunk size for MD5 hash calculation.
|
||||
pub const chunk_size = 0x4000;
|
||||
|
||||
/// Calculates Md5 hash of each chunk in parallel and then hashes all Md5 hashes to produce
|
||||
/// the final digest.
|
||||
/// 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;
|
||||
/// TODO LLD also hashes the output filename to disambiguate between same builds with different
|
||||
/// output files. Should we also do that?
|
||||
pub fn calcUuid(comp: *const Compilation, file: fs.File, file_size: u64, out: *[Md5.digest_length]u8) !void {
|
||||
const num_chunks = @intCast(u64, comp.thread_pool.threads.len) * 10;
|
||||
const chunk_size = @divTrunc(file_size + num_chunks - 1, num_chunks);
|
||||
const total_hashes = mem.alignForward(u64, file_size, chunk_size) / chunk_size;
|
||||
|
||||
const hashes = try comp.gpa.alloc([Md5.digest_length]u8, total_hashes);
|
||||
|
||||
Reference in New Issue
Block a user