authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-12-27 11:22:31-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-01 19:49:07-07:00
log7f13754778ff1c0709b5b3e63de40ffbf5049164
tree458d63b09df3770a61ab7f7e21e77ab30cb56424
parent5b05e99dd48520c0efd5f624760b3218bc1311ec

Compilation: fix whole mode cache hash

before this commit it was trying to hash based on resolved bin_file settings, but bin_file was always null since cache mode is always whole when this function is called! hash based on the lf_open_opts instead.

1 files changed, 67 insertions(+), 88 deletions(-)

src/Compilation.zig+67-88
...@@ -815,6 +815,7 @@ pub const cache_helpers = struct {...@@ -815,6 +815,7 @@ pub const cache_helpers = struct {
815 hh.add(mod.sanitize_thread);815 hh.add(mod.sanitize_thread);
816 hh.add(mod.unwind_tables);816 hh.add(mod.unwind_tables);
817 hh.add(mod.structured_cfg);817 hh.add(mod.structured_cfg);
818 hh.addListOfBytes(mod.cc_argv);
818 }819 }
819820
820 pub fn addResolvedTarget(821 pub fn addResolvedTarget(
...@@ -2398,10 +2399,6 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes...@@ -2398,10 +2399,6 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes
2398 try addModuleTableToCacheHash(gpa, arena, &man.hash, mod.main_mod, .{ .files = man });2399 try addModuleTableToCacheHash(gpa, arena, &man.hash, mod.main_mod, .{ .files = man });
23992400
2400 // Synchronize with other matching comments: ZigOnlyHashStuff2401 // Synchronize with other matching comments: ZigOnlyHashStuff
2401 man.hash.add(comp.config.use_llvm);
2402 man.hash.add(comp.config.use_lib_llvm);
2403 man.hash.add(comp.config.dll_export_fns);
2404 man.hash.add(comp.config.is_test);
2405 man.hash.add(comp.config.test_evented_io);2402 man.hash.add(comp.config.test_evented_io);
2406 man.hash.addOptionalBytes(comp.test_filter);2403 man.hash.addOptionalBytes(comp.test_filter);
2407 man.hash.addOptionalBytes(comp.test_name_prefix);2404 man.hash.addOptionalBytes(comp.test_name_prefix);
...@@ -2439,18 +2436,42 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes...@@ -2439,18 +2436,42 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes
2439 }2436 }
2440 }2437 }
24412438
2439 man.hash.add(comp.config.use_llvm);
2440 man.hash.add(comp.config.use_lib_llvm);
2441 man.hash.add(comp.config.is_test);
2442 man.hash.add(comp.config.import_memory);
2443 man.hash.add(comp.config.export_memory);
2444 man.hash.add(comp.config.shared_memory);
2445 man.hash.add(comp.config.dll_export_fns);
2446 man.hash.add(comp.config.rdynamic);
2447
2442 man.hash.addOptionalBytes(comp.sysroot);2448 man.hash.addOptionalBytes(comp.sysroot);
2443 man.hash.addOptional(comp.version);2449 man.hash.addOptional(comp.version);
2450 man.hash.add(comp.link_eh_frame_hdr);
2451 man.hash.add(comp.skip_linker_dependencies);
2452 man.hash.add(comp.include_compiler_rt);
2444 man.hash.addListOfBytes(comp.rc_include_dir_list);2453 man.hash.addListOfBytes(comp.rc_include_dir_list);
2445 man.hash.addListOfBytes(comp.force_undefined_symbols.keys());2454 man.hash.addListOfBytes(comp.force_undefined_symbols.keys());
2455 man.hash.addListOfBytes(comp.framework_dirs);
2456 try link.hashAddSystemLibs(man, comp.system_libs);
24462457
2447 cache_helpers.addOptionalEmitLoc(&man.hash, comp.emit_asm);2458 cache_helpers.addOptionalEmitLoc(&man.hash, comp.emit_asm);
2448 cache_helpers.addOptionalEmitLoc(&man.hash, comp.emit_llvm_ir);2459 cache_helpers.addOptionalEmitLoc(&man.hash, comp.emit_llvm_ir);
2449 cache_helpers.addOptionalEmitLoc(&man.hash, comp.emit_llvm_bc);2460 cache_helpers.addOptionalEmitLoc(&man.hash, comp.emit_llvm_bc);
24502461
2451 man.hash.add(comp.skip_linker_dependencies);2462 const opts = comp.cache_use.whole.lf_open_opts;
2452 man.hash.add(comp.include_compiler_rt);2463
2453 man.hash.add(comp.link_eh_frame_hdr);2464 try man.addOptionalFile(opts.linker_script);
2465 try man.addOptionalFile(opts.version_script);
2466
2467 man.hash.addOptional(opts.stack_size);
2468 man.hash.addOptional(opts.image_base);
2469 man.hash.addOptional(opts.gc_sections);
2470 man.hash.add(opts.emit_relocs);
2471 man.hash.addListOfBytes(opts.lib_dirs);
2472 man.hash.addListOfBytes(opts.rpath_list);
2473 man.hash.addListOfBytes(opts.symbol_wrap_set.keys());
2474 man.hash.add(opts.each_lib_rpath);
2454 if (comp.config.link_libc) {2475 if (comp.config.link_libc) {
2455 man.hash.add(comp.libc_installation != null);2476 man.hash.add(comp.libc_installation != null);
2456 const target = comp.root_mod.resolved_target.result;2477 const target = comp.root_mod.resolved_target.result;
...@@ -2463,86 +2484,45 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes...@@ -2463,86 +2484,45 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes
2463 }2484 }
2464 man.hash.addOptionalBytes(target.dynamic_linker.get());2485 man.hash.addOptionalBytes(target.dynamic_linker.get());
2465 }2486 }
2466 try link.hashAddSystemLibs(man, comp.system_libs);2487 man.hash.addOptional(opts.allow_shlib_undefined);
24672488 man.hash.add(opts.bind_global_refs_locally);
2468 man.hash.add(comp.config.use_llvm);2489
2469 man.hash.add(comp.config.use_lib_llvm);2490 // ELF specific stuff
2470 man.hash.add(comp.config.is_test);2491 man.hash.add(opts.z_nodelete);
2471 man.hash.add(comp.config.import_memory);2492 man.hash.add(opts.z_notext);
2472 man.hash.add(comp.config.export_memory);2493 man.hash.add(opts.z_defs);
2473 man.hash.add(comp.config.shared_memory);2494 man.hash.add(opts.z_origin);
2474 man.hash.add(comp.config.dll_export_fns);2495 man.hash.add(opts.z_nocopyreloc);
2475 man.hash.add(comp.config.rdynamic);2496 man.hash.add(opts.z_now);
24762497 man.hash.add(opts.z_relro);
2477 if (comp.bin_file) |lf| {2498 man.hash.add(opts.z_common_page_size orelse 0);
2478 man.hash.add(lf.stack_size);2499 man.hash.add(opts.z_max_page_size orelse 0);
2479 man.hash.add(lf.gc_sections);2500 man.hash.add(opts.hash_style);
2480 man.hash.addListOfBytes(lf.rpath_list);2501 man.hash.add(opts.compress_debug_sections);
2481 man.hash.add(lf.build_id);2502 man.hash.addOptional(opts.sort_section);
2482 man.hash.add(lf.allow_shlib_undefined);2503 man.hash.addOptionalBytes(opts.soname);
24832504 man.hash.add(opts.build_id);
2484 switch (lf.tag) {2505
2485 .elf => {2506 // WASM specific stuff
2486 const elf = lf.cast(link.File.Elf).?;2507 man.hash.addOptional(opts.initial_memory);
2487 man.hash.add(elf.image_base);2508 man.hash.addOptional(opts.max_memory);
2488 man.hash.add(elf.emit_relocs);2509 man.hash.addOptional(opts.global_base);
2489 man.hash.add(elf.z_nodelete);2510
2490 man.hash.add(elf.z_notext);2511 // Mach-O specific stuff
2491 man.hash.add(elf.z_defs);2512 try link.File.MachO.hashAddFrameworks(man, opts.frameworks);
2492 man.hash.add(elf.z_origin);2513 try man.addOptionalFile(opts.entitlements);
2493 man.hash.add(elf.z_nocopyreloc);2514 man.hash.addOptional(opts.pagezero_size);
2494 man.hash.add(elf.z_now);2515 man.hash.addOptional(opts.headerpad_size);
2495 man.hash.add(elf.z_relro);2516 man.hash.add(opts.headerpad_max_install_names);
2496 man.hash.add(elf.z_common_page_size orelse 0);2517 man.hash.add(opts.dead_strip_dylibs);
2497 man.hash.add(elf.z_max_page_size orelse 0);2518
2498 man.hash.addListOfBytes(elf.lib_dirs);2519 // COFF specific stuff
2499 man.hash.add(elf.hash_style);2520 man.hash.addOptional(opts.subsystem);
2500 man.hash.add(elf.compress_debug_sections);2521 man.hash.add(opts.tsaware);
2501 man.hash.addListOfBytes(elf.symbol_wrap_set.keys());2522 man.hash.add(opts.nxcompat);
2502 man.hash.add(elf.each_lib_rpath);2523 man.hash.add(opts.dynamicbase);
2503 man.hash.addOptional(elf.sort_section);2524 man.hash.addOptional(opts.major_subsystem_version);
2504 man.hash.addOptionalBytes(elf.soname);2525 man.hash.addOptional(opts.minor_subsystem_version);
2505 man.hash.add(elf.bind_global_refs_locally);
2506 try man.addOptionalFile(elf.linker_script);
2507 try man.addOptionalFile(elf.version_script);
2508 },
2509 .wasm => {
2510 const wasm = lf.cast(link.File.Wasm).?;
2511 man.hash.addOptional(wasm.initial_memory);
2512 man.hash.addOptional(wasm.max_memory);
2513 man.hash.addOptional(wasm.global_base);
2514 },
2515 .macho => {
2516 const macho = lf.cast(link.File.MachO).?;
2517 man.hash.addListOfBytes(comp.framework_dirs);
2518 try link.File.MachO.hashAddFrameworks(man, macho.frameworks);
2519 try man.addOptionalFile(macho.entitlements);
2520 man.hash.add(macho.pagezero_vmsize);
2521 man.hash.add(macho.headerpad_size);
2522 man.hash.add(macho.headerpad_max_install_names);
2523 man.hash.add(macho.dead_strip_dylibs);
2524 },
2525 .coff => {
2526 const coff = lf.cast(link.File.Coff).?;
2527 man.hash.add(coff.image_base);
2528 man.hash.addOptional(coff.subsystem);
2529 man.hash.add(coff.tsaware);
2530 man.hash.add(coff.nxcompat);
2531 man.hash.add(coff.dynamicbase);
2532 man.hash.add(coff.major_subsystem_version);
2533 man.hash.add(coff.minor_subsystem_version);
2534 man.hash.addListOfBytes(coff.lib_dirs);
2535 },
2536 .spirv => {
2537 const spirv = lf.cast(link.File.SpirV).?;
2538 _ = spirv;
2539 // TODO
2540 },
2541 .c => {}, // TODO
2542 .plan9 => {}, // TODO
2543 .nvptx => {}, // TODO
2544 }
2545 }
2546}2526}
25472527
2548fn emitOthers(comp: *Compilation) void {2528fn emitOthers(comp: *Compilation) void {
...@@ -3848,7 +3828,6 @@ pub fn obtainCObjectCacheManifest(...@@ -3848,7 +3828,6 @@ pub fn obtainCObjectCacheManifest(
3848 // that apply both to @cImport and compiling C objects. No linking stuff here!3828 // that apply both to @cImport and compiling C objects. No linking stuff here!
3849 // Also nothing that applies only to compiling .zig code.3829 // Also nothing that applies only to compiling .zig code.
3850 cache_helpers.addModule(&man.hash, owner_mod);3830 cache_helpers.addModule(&man.hash, owner_mod);
3851 man.hash.addListOfBytes(owner_mod.cc_argv);
3852 man.hash.add(comp.config.link_libcpp);3831 man.hash.add(comp.config.link_libcpp);
38533832
3854 // When libc_installation is null it means that Zig generated this dir list3833 // When libc_installation is null it means that Zig generated this dir list