authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-07-16 10:32:17+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-07-22 16:58:20+02:00
log4658d857de9198e825f13c136b2342d630e19e62
tree291ecf5d25d29add0ca85e5c081b720db60ff198
parentb380ed6a729d7f0daa6f0ee2b58bf3b54017cc65

macho: fix caching linker line in incremental setting


1 files changed, 45 insertions(+), 36 deletions(-)

src/link/MachO.zig+45-36
......@@ -478,50 +478,59 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
478478 defer if (!self.base.options.disable_lld_caching) man.deinit();
479479
480480 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();
482483
483 if (!self.base.options.disable_lld_caching) {
484 man = comp.cache_parent.obtain();
485 self.base.releaseLock();
484 man.hash.addListOfBytes(libs.keys());
486485
487 man.hash.addListOfBytes(libs.keys());
488
489 _ = try man.hit();
490 digest = man.final();
486 _ = try man.hit();
487 digest = man.final();
491488
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: {
505503 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", .{
507505 std.fmt.fmtSliceHexLower(&digest),
508506 });
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 }
521513 }
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 };
523525
524526 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
525534 var dependent_libs = std.fifo.LinearFifo(struct {
526535 id: Dylib.Id,
527536 parent: u16,
......@@ -607,7 +616,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
607616 try self.snapshotState();
608617 }
609618
610 if (!self.base.options.disable_lld_caching and cache_miss) {
619 if (cache_miss) {
611620 // Update the file with the digest. If it fails we can continue; it only
612621 // means that the next invocation will have an unnecessary cache miss.
613622 Cache.writeSmallFile(cache_dir_handle, id_symlink_basename, &digest) catch |err| {