authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-16 13:41:53-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-16 13:41:53-07:00
log3256b3c48536407e64b641b55bde064a9ac34606
tree15c4692e81be97170175662263f3043937adfefc
parent670260aab6e3ee720b4ef6d6d0234f48ed83b76b

stage2: glibc shared objects use ok file to detect cache hits


1 files changed, 30 insertions(+), 13 deletions(-)

src-self-hosted/glibc.zig+30-13
......@@ -773,13 +773,26 @@ pub fn buildSharedObjects(comp: *Compilation) !void {
773773 const hit = try cache.hit();
774774 const digest = cache.final();
775775 const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest });
776 if (!hit) {
777 var o_directory: Compilation.Directory = .{
778 .handle = try comp.zig_cache_directory.handle.makeOpenPath(o_sub_path, .{}),
779 .path = try path.join(arena, &[_][]const u8{ comp.zig_cache_directory.path.?, o_sub_path }),
776
777 // Even if we get a hit, it doesn't guarantee that we finished the job last time.
778 // We use the presence of an "ok" file to determine if it is a true hit.
779
780 var o_directory: Compilation.Directory = .{
781 .handle = try comp.zig_cache_directory.handle.makeOpenPath(o_sub_path, .{}),
782 .path = try path.join(arena, &[_][]const u8{ comp.zig_cache_directory.path.?, o_sub_path }),
783 };
784 defer o_directory.handle.close();
785
786 const ok_basename = "ok";
787 const actual_hit = if (hit) blk: {
788 o_directory.handle.access(ok_basename, .{}) catch |err| switch (err) {
789 error.FileNotFound => break :blk false,
790 else => |e| return e,
780791 };
781 defer o_directory.handle.close();
792 break :blk true;
793 } else false;
782794
795 if (!actual_hit) {
783796 const metadata = try loadMetaData(comp.gpa, comp.zig_lib_directory.handle);
784797 defer metadata.destroy(comp.gpa);
785798
......@@ -869,16 +882,16 @@ pub fn buildSharedObjects(comp: *Compilation) !void {
869882 const want_two_ats = chosen_def_ver_index != 255 and ver_index == chosen_def_ver_index;
870883 const at_sign_str = "@@"[0 .. @boolToInt(want_two_ats) + @as(usize, 1)];
871884 if (ver.patch == 0) {
872 try zig_body.writer().print(" \\\\ .symver {s}, {s}{s}GLIBC_{d}.{d}\n", .{
885 try zig_body.writer().print(" \\\\.symver {s}, {s}{s}GLIBC_{d}.{d}\n", .{
873886 stub_name, sym_name, at_sign_str, ver.major, ver.minor,
874887 });
875888 } else {
876 try zig_body.writer().print(" \\\\ .symver {s}, {s}{s}GLIBC_{d}.{d}.{d}\n", .{
889 try zig_body.writer().print(" \\\\.symver {s}, {s}{s}GLIBC_{d}.{d}.{d}\n", .{
877890 stub_name, sym_name, at_sign_str, ver.major, ver.minor, ver.patch,
878891 });
879892 }
880893 // Hide the stub to keep the symbol table clean
881 try zig_body.writer().print(" \\\\ .hidden {s}\n", .{stub_name});
894 try zig_body.writer().print(" \\\\.hidden {s}\n", .{stub_name});
882895 }
883896 }
884897 }
......@@ -896,9 +909,13 @@ pub fn buildSharedObjects(comp: *Compilation) !void {
896909
897910 try buildSharedLib(comp, arena, comp.zig_cache_directory, o_directory, zig_file_basename, lib);
898911 }
899 cache.writeManifest() catch |err| {
900 std.log.warn("glibc shared objects: failed to write cache manifest: {}", .{@errorName(err)});
901 };
912 // No need to write the manifest because there are no file inputs associated with this cache hash.
913 // However we do need to write the ok file now.
914 if (o_directory.handle.createFile(ok_basename, .{})) |file| {
915 file.close();
916 } else |err| {
917 std.log.warn("glibc shared objects: failed to mark completion: {}", .{@errorName(err)});
918 }
902919 }
903920
904921 assert(comp.glibc_so_files == null);
......@@ -935,7 +952,7 @@ fn buildSharedLib(
935952 .zig_lib_directory = comp.zig_lib_directory,
936953 .target = comp.getTarget(),
937954 .root_name = lib.name,
938 .root_pkg = null,
955 .root_pkg = root_pkg,
939956 .output_mode = .Lib,
940957 .link_mode = .Dynamic,
941958 .rand = comp.rand,
......@@ -971,7 +988,7 @@ fn updateSubCompilation(sub_compilation: *Compilation) !void {
971988
972989 if (errors.list.len != 0) {
973990 for (errors.list) |full_err_msg| {
974 std.log.err("{}:{}:{}: error: {}\n", .{
991 std.log.err("{}:{}:{}: {}\n", .{
975992 full_err_msg.src_path,
976993 full_err_msg.line + 1,
977994 full_err_msg.column + 1,