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 {
815815 hh.add(mod.sanitize_thread);
816816 hh.add(mod.unwind_tables);
817817 hh.add(mod.structured_cfg);
818 hh.addListOfBytes(mod.cc_argv);
818819 }
819820
820821 pub fn addResolvedTarget(
......@@ -2398,10 +2399,6 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes
23982399 try addModuleTableToCacheHash(gpa, arena, &man.hash, mod.main_mod, .{ .files = man });
23992400
24002401 // 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);
24052402 man.hash.add(comp.config.test_evented_io);
24062403 man.hash.addOptionalBytes(comp.test_filter);
24072404 man.hash.addOptionalBytes(comp.test_name_prefix);
......@@ -2439,18 +2436,42 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes
24392436 }
24402437 }
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
24422448 man.hash.addOptionalBytes(comp.sysroot);
24432449 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);
24442453 man.hash.addListOfBytes(comp.rc_include_dir_list);
24452454 man.hash.addListOfBytes(comp.force_undefined_symbols.keys());
2455 man.hash.addListOfBytes(comp.framework_dirs);
2456 try link.hashAddSystemLibs(man, comp.system_libs);
24462457
24472458 cache_helpers.addOptionalEmitLoc(&man.hash, comp.emit_asm);
24482459 cache_helpers.addOptionalEmitLoc(&man.hash, comp.emit_llvm_ir);
24492460 cache_helpers.addOptionalEmitLoc(&man.hash, comp.emit_llvm_bc);
24502461
2451 man.hash.add(comp.skip_linker_dependencies);
2452 man.hash.add(comp.include_compiler_rt);
2453 man.hash.add(comp.link_eh_frame_hdr);
2462 const opts = comp.cache_use.whole.lf_open_opts;
2463
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);
24542475 if (comp.config.link_libc) {
24552476 man.hash.add(comp.libc_installation != null);
24562477 const target = comp.root_mod.resolved_target.result;
......@@ -2463,86 +2484,45 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes
24632484 }
24642485 man.hash.addOptionalBytes(target.dynamic_linker.get());
24652486 }
2466 try link.hashAddSystemLibs(man, comp.system_libs);
2467
2468 man.hash.add(comp.config.use_llvm);
2469 man.hash.add(comp.config.use_lib_llvm);
2470 man.hash.add(comp.config.is_test);
2471 man.hash.add(comp.config.import_memory);
2472 man.hash.add(comp.config.export_memory);
2473 man.hash.add(comp.config.shared_memory);
2474 man.hash.add(comp.config.dll_export_fns);
2475 man.hash.add(comp.config.rdynamic);
2476
2477 if (comp.bin_file) |lf| {
2478 man.hash.add(lf.stack_size);
2479 man.hash.add(lf.gc_sections);
2480 man.hash.addListOfBytes(lf.rpath_list);
2481 man.hash.add(lf.build_id);
2482 man.hash.add(lf.allow_shlib_undefined);
2483
2484 switch (lf.tag) {
2485 .elf => {
2486 const elf = lf.cast(link.File.Elf).?;
2487 man.hash.add(elf.image_base);
2488 man.hash.add(elf.emit_relocs);
2489 man.hash.add(elf.z_nodelete);
2490 man.hash.add(elf.z_notext);
2491 man.hash.add(elf.z_defs);
2492 man.hash.add(elf.z_origin);
2493 man.hash.add(elf.z_nocopyreloc);
2494 man.hash.add(elf.z_now);
2495 man.hash.add(elf.z_relro);
2496 man.hash.add(elf.z_common_page_size orelse 0);
2497 man.hash.add(elf.z_max_page_size orelse 0);
2498 man.hash.addListOfBytes(elf.lib_dirs);
2499 man.hash.add(elf.hash_style);
2500 man.hash.add(elf.compress_debug_sections);
2501 man.hash.addListOfBytes(elf.symbol_wrap_set.keys());
2502 man.hash.add(elf.each_lib_rpath);
2503 man.hash.addOptional(elf.sort_section);
2504 man.hash.addOptionalBytes(elf.soname);
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 }
2487 man.hash.addOptional(opts.allow_shlib_undefined);
2488 man.hash.add(opts.bind_global_refs_locally);
2489
2490 // ELF specific stuff
2491 man.hash.add(opts.z_nodelete);
2492 man.hash.add(opts.z_notext);
2493 man.hash.add(opts.z_defs);
2494 man.hash.add(opts.z_origin);
2495 man.hash.add(opts.z_nocopyreloc);
2496 man.hash.add(opts.z_now);
2497 man.hash.add(opts.z_relro);
2498 man.hash.add(opts.z_common_page_size orelse 0);
2499 man.hash.add(opts.z_max_page_size orelse 0);
2500 man.hash.add(opts.hash_style);
2501 man.hash.add(opts.compress_debug_sections);
2502 man.hash.addOptional(opts.sort_section);
2503 man.hash.addOptionalBytes(opts.soname);
2504 man.hash.add(opts.build_id);
2505
2506 // WASM specific stuff
2507 man.hash.addOptional(opts.initial_memory);
2508 man.hash.addOptional(opts.max_memory);
2509 man.hash.addOptional(opts.global_base);
2510
2511 // Mach-O specific stuff
2512 try link.File.MachO.hashAddFrameworks(man, opts.frameworks);
2513 try man.addOptionalFile(opts.entitlements);
2514 man.hash.addOptional(opts.pagezero_size);
2515 man.hash.addOptional(opts.headerpad_size);
2516 man.hash.add(opts.headerpad_max_install_names);
2517 man.hash.add(opts.dead_strip_dylibs);
2518
2519 // COFF specific stuff
2520 man.hash.addOptional(opts.subsystem);
2521 man.hash.add(opts.tsaware);
2522 man.hash.add(opts.nxcompat);
2523 man.hash.add(opts.dynamicbase);
2524 man.hash.addOptional(opts.major_subsystem_version);
2525 man.hash.addOptional(opts.minor_subsystem_version);
25462526}
25472527
25482528fn emitOthers(comp: *Compilation) void {
......@@ -3848,7 +3828,6 @@ pub fn obtainCObjectCacheManifest(
38483828 // that apply both to @cImport and compiling C objects. No linking stuff here!
38493829 // Also nothing that applies only to compiling .zig code.
38503830 cache_helpers.addModule(&man.hash, owner_mod);
3851 man.hash.addListOfBytes(owner_mod.cc_argv);
38523831 man.hash.add(comp.config.link_libcpp);
38533832
38543833 // When libc_installation is null it means that Zig generated this dir list