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 {...@@ -773,13 +773,26 @@ pub fn buildSharedObjects(comp: *Compilation) !void {
773 const hit = try cache.hit();773 const hit = try cache.hit();
774 const digest = cache.final();774 const digest = cache.final();
775 const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest });775 const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest });
776 if (!hit) {776
777 var o_directory: Compilation.Directory = .{777 // Even if we get a hit, it doesn't guarantee that we finished the job last time.
778 .handle = try comp.zig_cache_directory.handle.makeOpenPath(o_sub_path, .{}),778 // We use the presence of an "ok" file to determine if it is a true hit.
779 .path = try path.join(arena, &[_][]const u8{ comp.zig_cache_directory.path.?, o_sub_path }),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,
780 };791 };
781 defer o_directory.handle.close();792 break :blk true;
793 } else false;
782794
795 if (!actual_hit) {
783 const metadata = try loadMetaData(comp.gpa, comp.zig_lib_directory.handle);796 const metadata = try loadMetaData(comp.gpa, comp.zig_lib_directory.handle);
784 defer metadata.destroy(comp.gpa);797 defer metadata.destroy(comp.gpa);
785798
...@@ -869,16 +882,16 @@ pub fn buildSharedObjects(comp: *Compilation) !void {...@@ -869,16 +882,16 @@ pub fn buildSharedObjects(comp: *Compilation) !void {
869 const want_two_ats = chosen_def_ver_index != 255 and ver_index == chosen_def_ver_index;882 const want_two_ats = chosen_def_ver_index != 255 and ver_index == chosen_def_ver_index;
870 const at_sign_str = "@@"[0 .. @boolToInt(want_two_ats) + @as(usize, 1)];883 const at_sign_str = "@@"[0 .. @boolToInt(want_two_ats) + @as(usize, 1)];
871 if (ver.patch == 0) {884 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", .{
873 stub_name, sym_name, at_sign_str, ver.major, ver.minor,886 stub_name, sym_name, at_sign_str, ver.major, ver.minor,
874 });887 });
875 } else {888 } 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", .{
877 stub_name, sym_name, at_sign_str, ver.major, ver.minor, ver.patch,890 stub_name, sym_name, at_sign_str, ver.major, ver.minor, ver.patch,
878 });891 });
879 }892 }
880 // Hide the stub to keep the symbol table clean893 // 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});
882 }895 }
883 }896 }
884 }897 }
...@@ -896,9 +909,13 @@ pub fn buildSharedObjects(comp: *Compilation) !void {...@@ -896,9 +909,13 @@ pub fn buildSharedObjects(comp: *Compilation) !void {
896909
897 try buildSharedLib(comp, arena, comp.zig_cache_directory, o_directory, zig_file_basename, lib);910 try buildSharedLib(comp, arena, comp.zig_cache_directory, o_directory, zig_file_basename, lib);
898 }911 }
899 cache.writeManifest() catch |err| {912 // No need to write the manifest because there are no file inputs associated with this cache hash.
900 std.log.warn("glibc shared objects: failed to write cache manifest: {}", .{@errorName(err)});913 // However we do need to write the ok file now.
901 };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 }
902 }919 }
903920
904 assert(comp.glibc_so_files == null);921 assert(comp.glibc_so_files == null);
...@@ -935,7 +952,7 @@ fn buildSharedLib(...@@ -935,7 +952,7 @@ fn buildSharedLib(
935 .zig_lib_directory = comp.zig_lib_directory,952 .zig_lib_directory = comp.zig_lib_directory,
936 .target = comp.getTarget(),953 .target = comp.getTarget(),
937 .root_name = lib.name,954 .root_name = lib.name,
938 .root_pkg = null,955 .root_pkg = root_pkg,
939 .output_mode = .Lib,956 .output_mode = .Lib,
940 .link_mode = .Dynamic,957 .link_mode = .Dynamic,
941 .rand = comp.rand,958 .rand = comp.rand,
...@@ -971,7 +988,7 @@ fn updateSubCompilation(sub_compilation: *Compilation) !void {...@@ -971,7 +988,7 @@ fn updateSubCompilation(sub_compilation: *Compilation) !void {
971988
972 if (errors.list.len != 0) {989 if (errors.list.len != 0) {
973 for (errors.list) |full_err_msg| {990 for (errors.list) |full_err_msg| {
974 std.log.err("{}:{}:{}: error: {}\n", .{991 std.log.err("{}:{}:{}: {}\n", .{
975 full_err_msg.src_path,992 full_err_msg.src_path,
976 full_err_msg.line + 1,993 full_err_msg.line + 1,
977 full_err_msg.column + 1,994 full_err_msg.column + 1,