| ... | ... | @@ -478,50 +478,59 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No |
| 478 | 478 | defer if (!self.base.options.disable_lld_caching) man.deinit(); |
| 479 | 479 | |
| 480 | 480 | var digest: [Cache.hex_digest_len]u8 = undefined; |
| 481 | | var cache_miss: bool = self.cold_start; |
| 481 | man = comp.cache_parent.obtain(); |
| 482 | self.base.releaseLock(); |
| 482 | 483 | |
| 483 | | if (!self.base.options.disable_lld_caching) { |
| 484 | | man = comp.cache_parent.obtain(); |
| 485 | | self.base.releaseLock(); |
| 484 | man.hash.addListOfBytes(libs.keys()); |
| 486 | 485 | |
| 487 | | man.hash.addListOfBytes(libs.keys()); |
| 488 | | |
| 489 | | _ = try man.hit(); |
| 490 | | digest = man.final(); |
| 486 | _ = try man.hit(); |
| 487 | digest = man.final(); |
| 491 | 488 | |
| 492 | | var prev_digest_buf: [digest.len]u8 = undefined; |
| 493 | | const prev_digest: []u8 = Cache.readSmallFile( |
| 494 | | cache_dir_handle, |
| 495 | | id_symlink_basename, |
| 496 | | &prev_digest_buf, |
| 497 | | ) catch |err| blk: { |
| 498 | | log.debug("MachO Zld new_digest={s} error: {s}", .{ |
| 499 | | std.fmt.fmtSliceHexLower(&digest), |
| 500 | | @errorName(err), |
| 501 | | }); |
| 502 | | // Handle this as a cache miss. |
| 503 | | break :blk prev_digest_buf[0..0]; |
| 504 | | }; |
| 489 | var prev_digest_buf: [digest.len]u8 = undefined; |
| 490 | const prev_digest: []u8 = Cache.readSmallFile( |
| 491 | cache_dir_handle, |
| 492 | id_symlink_basename, |
| 493 | &prev_digest_buf, |
| 494 | ) catch |err| blk: { |
| 495 | log.debug("MachO Zld new_digest={s} error: {s}", .{ |
| 496 | std.fmt.fmtSliceHexLower(&digest), |
| 497 | @errorName(err), |
| 498 | }); |
| 499 | // Handle this as a cache miss. |
| 500 | break :blk prev_digest_buf[0..0]; |
| 501 | }; |
| 502 | const cache_miss: bool = cache_miss: { |
| 505 | 503 | if (mem.eql(u8, prev_digest, &digest)) { |
| 506 | | log.debug("MachO Zld digest={s} match - skipping parsing linker line objects", .{ |
| 504 | log.debug("MachO Zld digest={s} match", .{ |
| 507 | 505 | std.fmt.fmtSliceHexLower(&digest), |
| 508 | 506 | }); |
| 509 | | self.base.lock = man.toOwnedLock(); |
| 510 | | } else { |
| 511 | | log.debug("MachO Zld prev_digest={s} new_digest={s}", .{ |
| 512 | | std.fmt.fmtSliceHexLower(prev_digest), |
| 513 | | std.fmt.fmtSliceHexLower(&digest), |
| 514 | | }); |
| 515 | | // We are about to change the output file to be different, so we invalidate the build hash now. |
| 516 | | cache_dir_handle.deleteFile(id_symlink_basename) catch |err| switch (err) { |
| 517 | | error.FileNotFound => {}, |
| 518 | | else => |e| return e, |
| 519 | | }; |
| 520 | | cache_miss = true; |
| 507 | if (!self.cold_start) { |
| 508 | log.debug(" skipping parsing linker line objects", .{}); |
| 509 | break :cache_miss false; |
| 510 | } else { |
| 511 | log.debug(" TODO parse prelinked binary and continue linking where we left off", .{}); |
| 512 | } |
| 521 | 513 | } |
| 522 | | } |
| 514 | log.debug("MachO Zld prev_digest={s} new_digest={s}", .{ |
| 515 | std.fmt.fmtSliceHexLower(prev_digest), |
| 516 | std.fmt.fmtSliceHexLower(&digest), |
| 517 | }); |
| 518 | // We are about to change the output file to be different, so we invalidate the build hash now. |
| 519 | cache_dir_handle.deleteFile(id_symlink_basename) catch |err| switch (err) { |
| 520 | error.FileNotFound => {}, |
| 521 | else => |e| return e, |
| 522 | }; |
| 523 | break :cache_miss true; |
| 524 | }; |
| 523 | 525 | |
| 524 | 526 | if (cache_miss) { |
| 527 | for (self.dylibs.items) |*dylib| { |
| 528 | dylib.deinit(self.base.allocator); |
| 529 | } |
| 530 | self.dylibs.clearRetainingCapacity(); |
| 531 | self.dylibs_map.clearRetainingCapacity(); |
| 532 | self.referenced_dylibs.clearRetainingCapacity(); |
| 533 | |
| 525 | 534 | var dependent_libs = std.fifo.LinearFifo(struct { |
| 526 | 535 | id: Dylib.Id, |
| 527 | 536 | parent: u16, |
| ... | ... | @@ -607,7 +616,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No |
| 607 | 616 | try self.snapshotState(); |
| 608 | 617 | } |
| 609 | 618 | |
| 610 | | if (!self.base.options.disable_lld_caching and cache_miss) { |
| 619 | if (cache_miss) { |
| 611 | 620 | // Update the file with the digest. If it fails we can continue; it only |
| 612 | 621 | // means that the next invocation will have an unnecessary cache miss. |
| 613 | 622 | Cache.writeSmallFile(cache_dir_handle, id_symlink_basename, &digest) catch |err| { |