| ... | @@ -77,6 +77,7 @@ system_libs: std.StringArrayHashMapUnmanaged(SystemLib), | ... | @@ -77,6 +77,7 @@ system_libs: std.StringArrayHashMapUnmanaged(SystemLib), |
| 77 | version: ?std.SemanticVersion, | 77 | version: ?std.SemanticVersion, |
| 78 | libc_installation: ?*const LibCInstallation, | 78 | libc_installation: ?*const LibCInstallation, |
| 79 | skip_linker_dependencies: bool, | 79 | skip_linker_dependencies: bool, |
| | 80 | no_builtin: bool, |
| 80 | | 81 | |
| 81 | c_object_table: std.AutoArrayHashMapUnmanaged(*CObject, void) = .{}, | 82 | c_object_table: std.AutoArrayHashMapUnmanaged(*CObject, void) = .{}, |
| 82 | win32_resource_table: if (build_options.only_core_functionality) void else std.AutoArrayHashMapUnmanaged(*Win32Resource, void) = | 83 | win32_resource_table: if (build_options.only_core_functionality) void else std.AutoArrayHashMapUnmanaged(*Win32Resource, void) = |
| ... | @@ -988,10 +989,9 @@ pub const InitOptions = struct { | ... | @@ -988,10 +989,9 @@ pub const InitOptions = struct { |
| 988 | linker_tsaware: bool = false, | 989 | linker_tsaware: bool = false, |
| 989 | linker_nxcompat: bool = false, | 990 | linker_nxcompat: bool = false, |
| 990 | linker_dynamicbase: bool = true, | 991 | linker_dynamicbase: bool = true, |
| 991 | linker_optimization: ?u8 = null, | 992 | linker_compress_debug_sections: ?link.File.Elf.CompressDebugSections = null, |
| 992 | linker_compress_debug_sections: ?link.CompressDebugSections = null, | | |
| 993 | linker_module_definition_file: ?[]const u8 = null, | 993 | linker_module_definition_file: ?[]const u8 = null, |
| 994 | linker_sort_section: ?link.SortSection = null, | 994 | linker_sort_section: ?link.File.Elf.SortSection = null, |
| 995 | major_subsystem_version: ?u32 = null, | 995 | major_subsystem_version: ?u32 = null, |
| 996 | minor_subsystem_version: ?u32 = null, | 996 | minor_subsystem_version: ?u32 = null, |
| 997 | clang_passthrough_mode: bool = false, | 997 | clang_passthrough_mode: bool = false, |
| ... | @@ -1011,7 +1011,7 @@ pub const InitOptions = struct { | ... | @@ -1011,7 +1011,7 @@ pub const InitOptions = struct { |
| 1011 | /// building such dependencies themselves, this flag must be set to avoid | 1011 | /// building such dependencies themselves, this flag must be set to avoid |
| 1012 | /// infinite recursion. | 1012 | /// infinite recursion. |
| 1013 | skip_linker_dependencies: bool = false, | 1013 | skip_linker_dependencies: bool = false, |
| 1014 | hash_style: link.HashStyle = .both, | 1014 | hash_style: link.File.Elf.HashStyle = .both, |
| 1015 | entry: ?[]const u8 = null, | 1015 | entry: ?[]const u8 = null, |
| 1016 | force_undefined_symbols: std.StringArrayHashMapUnmanaged(void) = .{}, | 1016 | force_undefined_symbols: std.StringArrayHashMapUnmanaged(void) = .{}, |
| 1017 | stack_size: ?u64 = null, | 1017 | stack_size: ?u64 = null, |
| ... | @@ -1049,8 +1049,6 @@ pub const InitOptions = struct { | ... | @@ -1049,8 +1049,6 @@ pub const InitOptions = struct { |
| 1049 | /// (Windows) PDB output path | 1049 | /// (Windows) PDB output path |
| 1050 | pdb_out_path: ?[]const u8 = null, | 1050 | pdb_out_path: ?[]const u8 = null, |
| 1051 | error_limit: ?Compilation.Module.ErrorInt = null, | 1051 | error_limit: ?Compilation.Module.ErrorInt = null, |
| 1052 | /// (SPIR-V) whether to generate a structured control flow graph or not | | |
| 1053 | want_structured_cfg: ?bool = null, | | |
| 1054 | }; | 1052 | }; |
| 1055 | | 1053 | |
| 1056 | fn addModuleTableToCacheHash( | 1054 | fn addModuleTableToCacheHash( |
| ... | @@ -1277,10 +1275,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { | ... | @@ -1277,10 +1275,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1277 | } | 1275 | } |
| 1278 | } | 1276 | } |
| 1279 | | 1277 | |
| 1280 | const linker_optimization: u8 = options.linker_optimization orelse switch (options.root_mod.optimize_mode) { | | |
| 1281 | .Debug => @as(u8, 0), | | |
| 1282 | else => @as(u8, 3), | | |
| 1283 | }; | | |
| 1284 | // TODO: https://github.com/ziglang/zig/issues/17969 | 1278 | // TODO: https://github.com/ziglang/zig/issues/17969 |
| 1285 | const formatted_panics = options.formatted_panics orelse (options.root_mod.optimize_mode == .Debug); | 1279 | const formatted_panics = options.formatted_panics orelse (options.root_mod.optimize_mode == .Debug); |
| 1286 | | 1280 | |
| ... | @@ -1359,7 +1353,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { | ... | @@ -1359,7 +1353,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1359 | hash.add(formatted_panics); | 1353 | hash.add(formatted_panics); |
| 1360 | hash.add(options.emit_h != null); | 1354 | hash.add(options.emit_h != null); |
| 1361 | hash.add(error_limit); | 1355 | hash.add(error_limit); |
| 1362 | hash.addOptional(options.want_structured_cfg); | | |
| 1363 | | 1356 | |
| 1364 | // In the case of incremental cache mode, this `zig_cache_artifact_directory` | 1357 | // In the case of incremental cache mode, this `zig_cache_artifact_directory` |
| 1365 | // is computed based on a hash of non-linker inputs, and it is where all | 1358 | // is computed based on a hash of non-linker inputs, and it is where all |
| ... | @@ -1641,13 +1634,13 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { | ... | @@ -1641,13 +1634,13 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1641 | .framework_dirs = options.framework_dirs, | 1634 | .framework_dirs = options.framework_dirs, |
| 1642 | .llvm_opt_bisect_limit = options.llvm_opt_bisect_limit, | 1635 | .llvm_opt_bisect_limit = options.llvm_opt_bisect_limit, |
| 1643 | .skip_linker_dependencies = options.skip_linker_dependencies, | 1636 | .skip_linker_dependencies = options.skip_linker_dependencies, |
| | 1637 | .no_builtin = options.no_builtin, |
| 1644 | }; | 1638 | }; |
| 1645 | | 1639 | |
| 1646 | if (bin_file_emit) |emit| { | 1640 | if (bin_file_emit) |emit| { |
| 1647 | comp.bin_file = try link.File.open(arena, .{ | 1641 | comp.bin_file = try link.File.open(arena, .{ |
| 1648 | .comp = comp, | 1642 | .comp = comp, |
| 1649 | .emit = emit, | 1643 | .emit = emit, |
| 1650 | .optimization = linker_optimization, | | |
| 1651 | .linker_script = options.linker_script, | 1644 | .linker_script = options.linker_script, |
| 1652 | .z_nodelete = options.linker_z_nodelete, | 1645 | .z_nodelete = options.linker_z_nodelete, |
| 1653 | .z_notext = options.linker_z_notext, | 1646 | .z_notext = options.linker_z_notext, |
| ... | @@ -1666,7 +1659,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { | ... | @@ -1666,7 +1659,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1666 | .symbol_wrap_set = options.symbol_wrap_set, | 1659 | .symbol_wrap_set = options.symbol_wrap_set, |
| 1667 | .function_sections = options.function_sections, | 1660 | .function_sections = options.function_sections, |
| 1668 | .data_sections = options.data_sections, | 1661 | .data_sections = options.data_sections, |
| 1669 | .no_builtin = options.no_builtin, | | |
| 1670 | .allow_shlib_undefined = options.linker_allow_shlib_undefined, | 1662 | .allow_shlib_undefined = options.linker_allow_shlib_undefined, |
| 1671 | .bind_global_refs_locally = options.linker_bind_global_refs_locally orelse false, | 1663 | .bind_global_refs_locally = options.linker_bind_global_refs_locally orelse false, |
| 1672 | .compress_debug_sections = options.linker_compress_debug_sections orelse .none, | 1664 | .compress_debug_sections = options.linker_compress_debug_sections orelse .none, |
| ... | @@ -1713,7 +1705,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { | ... | @@ -1713,7 +1705,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1713 | .force_undefined_symbols = options.force_undefined_symbols, | 1705 | .force_undefined_symbols = options.force_undefined_symbols, |
| 1714 | .pdb_source_path = options.pdb_source_path, | 1706 | .pdb_source_path = options.pdb_source_path, |
| 1715 | .pdb_out_path = options.pdb_out_path, | 1707 | .pdb_out_path = options.pdb_out_path, |
| 1716 | .want_structured_cfg = options.want_structured_cfg, | | |
| 1717 | .entry_addr = null, // CLI does not expose this option (yet?) | 1708 | .entry_addr = null, // CLI does not expose this option (yet?) |
| 1718 | }); | 1709 | }); |
| 1719 | } | 1710 | } |
| ... | @@ -2076,7 +2067,7 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void | ... | @@ -2076,7 +2067,7 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void |
| 2076 | }; | 2067 | }; |
| 2077 | if (is_hit) { | 2068 | if (is_hit) { |
| 2078 | comp.last_update_was_cache_hit = true; | 2069 | comp.last_update_was_cache_hit = true; |
| 2079 | log.debug("CacheMode.whole cache hit for {s}", .{comp.bin_file.options.root_name}); | 2070 | log.debug("CacheMode.whole cache hit for {s}", .{comp.root_name}); |
| 2080 | const digest = man.final(); | 2071 | const digest = man.final(); |
| 2081 | | 2072 | |
| 2082 | comp.wholeCacheModeSetBinFilePath(&digest); | 2073 | comp.wholeCacheModeSetBinFilePath(&digest); |
| ... | @@ -2085,7 +2076,7 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void | ... | @@ -2085,7 +2076,7 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void |
| 2085 | comp.bin_file.lock = man.toOwnedLock(); | 2076 | comp.bin_file.lock = man.toOwnedLock(); |
| 2086 | return; | 2077 | return; |
| 2087 | } | 2078 | } |
| 2088 | log.debug("CacheMode.whole cache miss for {s}", .{comp.bin_file.options.root_name}); | 2079 | log.debug("CacheMode.whole cache miss for {s}", .{comp.root_name}); |
| 2089 | | 2080 | |
| 2090 | // Initialize `bin_file.emit` with a temporary Directory so that compilation can | 2081 | // Initialize `bin_file.emit` with a temporary Directory so that compilation can |
| 2091 | // continue on the same path as incremental, using the temporary Directory. | 2082 | // continue on the same path as incremental, using the temporary Directory. |
| ... | @@ -2169,7 +2160,7 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void | ... | @@ -2169,7 +2160,7 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void |
| 2169 | // import_table here. | 2160 | // import_table here. |
| 2170 | // Likewise, in the case of `zig test`, the test runner is the root source file, | 2161 | // Likewise, in the case of `zig test`, the test runner is the root source file, |
| 2171 | // and so there is nothing to import the main file. | 2162 | // and so there is nothing to import the main file. |
| 2172 | if (comp.bin_file.options.is_test) { | 2163 | if (comp.config.is_test) { |
| 2173 | _ = try module.importPkg(module.main_mod); | 2164 | _ = try module.importPkg(module.main_mod); |
| 2174 | } | 2165 | } |
| 2175 | | 2166 | |
| ... | @@ -2194,7 +2185,7 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void | ... | @@ -2194,7 +2185,7 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void |
| 2194 | } | 2185 | } |
| 2195 | | 2186 | |
| 2196 | try comp.work_queue.writeItem(.{ .analyze_mod = std_mod }); | 2187 | try comp.work_queue.writeItem(.{ .analyze_mod = std_mod }); |
| 2197 | if (comp.bin_file.options.is_test) { | 2188 | if (comp.config.is_test) { |
| 2198 | try comp.work_queue.writeItem(.{ .analyze_mod = module.main_mod }); | 2189 | try comp.work_queue.writeItem(.{ .analyze_mod = module.main_mod }); |
| 2199 | } | 2190 | } |
| 2200 | | 2191 | |
| ... | @@ -2208,20 +2199,20 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void | ... | @@ -2208,20 +2199,20 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void |
| 2208 | if (comp.module) |module| { | 2199 | if (comp.module) |module| { |
| 2209 | if (builtin.mode == .Debug and comp.verbose_intern_pool) { | 2200 | if (builtin.mode == .Debug and comp.verbose_intern_pool) { |
| 2210 | std.debug.print("intern pool stats for '{s}':\n", .{ | 2201 | std.debug.print("intern pool stats for '{s}':\n", .{ |
| 2211 | comp.bin_file.options.root_name, | 2202 | comp.root_name, |
| 2212 | }); | 2203 | }); |
| 2213 | module.intern_pool.dump(); | 2204 | module.intern_pool.dump(); |
| 2214 | } | 2205 | } |
| 2215 | | 2206 | |
| 2216 | if (builtin.mode == .Debug and comp.verbose_generic_instances) { | 2207 | if (builtin.mode == .Debug and comp.verbose_generic_instances) { |
| 2217 | std.debug.print("generic instances for '{s}:0x{x}':\n", .{ | 2208 | std.debug.print("generic instances for '{s}:0x{x}':\n", .{ |
| 2218 | comp.bin_file.options.root_name, | 2209 | comp.root_name, |
| 2219 | @as(usize, @intFromPtr(module)), | 2210 | @as(usize, @intFromPtr(module)), |
| 2220 | }); | 2211 | }); |
| 2221 | module.intern_pool.dumpGenericInstances(comp.gpa); | 2212 | module.intern_pool.dumpGenericInstances(comp.gpa); |
| 2222 | } | 2213 | } |
| 2223 | | 2214 | |
| 2224 | if (comp.bin_file.options.is_test and comp.totalErrorCount() == 0) { | 2215 | if (comp.config.is_test and comp.totalErrorCount() == 0) { |
| 2225 | // The `test_functions` decl has been intentionally postponed until now, | 2216 | // The `test_functions` decl has been intentionally postponed until now, |
| 2226 | // at which point we must populate it with the list of test functions that | 2217 | // at which point we must populate it with the list of test functions that |
| 2227 | // have been discovered and not filtered out. | 2218 | // have been discovered and not filtered out. |
| ... | @@ -2336,7 +2327,7 @@ fn maybeGenerateAutodocs(comp: *Compilation, prog_node: *std.Progress.Node) !voi | ... | @@ -2336,7 +2327,7 @@ fn maybeGenerateAutodocs(comp: *Compilation, prog_node: *std.Progress.Node) !voi |
| 2336 | // file copies at the end of generate() can also be extracted to | 2327 | // file copies at the end of generate() can also be extracted to |
| 2337 | // separate jobs | 2328 | // separate jobs |
| 2338 | if (!build_options.only_c and !build_options.only_core_functionality) { | 2329 | if (!build_options.only_c and !build_options.only_core_functionality) { |
| 2339 | if (comp.bin_file.options.docs_emit) |emit| { | 2330 | if (comp.docs_emit) |emit| { |
| 2340 | var dir = try emit.directory.handle.makeOpenPath(emit.sub_path, .{}); | 2331 | var dir = try emit.directory.handle.makeOpenPath(emit.sub_path, .{}); |
| 2341 | defer dir.close(); | 2332 | defer dir.close(); |
| 2342 | | 2333 | |
| ... | @@ -2426,24 +2417,16 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes | ... | @@ -2426,24 +2417,16 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes |
| 2426 | try addModuleTableToCacheHash(gpa, arena, &man.hash, mod.main_mod, .{ .files = man }); | 2417 | try addModuleTableToCacheHash(gpa, arena, &man.hash, mod.main_mod, .{ .files = man }); |
| 2427 | | 2418 | |
| 2428 | // Synchronize with other matching comments: ZigOnlyHashStuff | 2419 | // Synchronize with other matching comments: ZigOnlyHashStuff |
| 2429 | man.hash.add(comp.config.use_llvm); | 2420 | man.hash.add(comp.config.test_evented_io); |
| 2430 | man.hash.add(comp.config.use_lib_llvm); | | |
| 2431 | man.hash.add(comp.bin_file.options.dll_export_fns); | | |
| 2432 | man.hash.add(comp.bin_file.options.is_test); | | |
| 2433 | man.hash.add(comp.test_evented_io); | | |
| 2434 | man.hash.addOptionalBytes(comp.test_filter); | 2421 | man.hash.addOptionalBytes(comp.test_filter); |
| 2435 | man.hash.addOptionalBytes(comp.test_name_prefix); | 2422 | man.hash.addOptionalBytes(comp.test_name_prefix); |
| 2436 | man.hash.add(comp.skip_linker_dependencies); | 2423 | man.hash.add(comp.skip_linker_dependencies); |
| 2437 | man.hash.add(comp.formatted_panics); | 2424 | man.hash.add(comp.formatted_panics); |
| 2438 | man.hash.add(mod.emit_h != null); | 2425 | man.hash.add(mod.emit_h != null); |
| 2439 | man.hash.add(mod.error_limit); | 2426 | man.hash.add(mod.error_limit); |
| 2440 | man.hash.add(comp.bin_file.options.want_structured_cfg); | | |
| 2441 | } | 2427 | } |
| 2442 | | 2428 | |
| 2443 | try man.addOptionalFile(comp.bin_file.options.linker_script); | 2429 | for (comp.objects) |obj| { |
| 2444 | try man.addOptionalFile(comp.bin_file.options.version_script); | | |
| 2445 | | | |
| 2446 | for (comp.bin_file.options.objects) |obj| { | | |
| 2447 | _ = try man.addFile(obj.path, null); | 2430 | _ = try man.addFile(obj.path, null); |
| 2448 | man.hash.add(obj.must_link); | 2431 | man.hash.add(obj.must_link); |
| 2449 | man.hash.add(obj.loption); | 2432 | man.hash.add(obj.loption); |
| ... | @@ -2469,39 +2452,19 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes | ... | @@ -2469,39 +2452,19 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes |
| 2469 | } | 2452 | } |
| 2470 | } | 2453 | } |
| 2471 | | 2454 | |
| | 2455 | man.hash.addOptionalBytes(comp.sysroot); |
| | 2456 | man.hash.addOptional(comp.version); |
| 2472 | man.hash.addListOfBytes(comp.rc_include_dir_list); | 2457 | man.hash.addListOfBytes(comp.rc_include_dir_list); |
| 2473 | | 2458 | |
| 2474 | cache_helpers.addOptionalEmitLoc(&man.hash, comp.emit_asm); | 2459 | cache_helpers.addOptionalEmitLoc(&man.hash, comp.emit_asm); |
| 2475 | cache_helpers.addOptionalEmitLoc(&man.hash, comp.emit_llvm_ir); | 2460 | cache_helpers.addOptionalEmitLoc(&man.hash, comp.emit_llvm_ir); |
| 2476 | cache_helpers.addOptionalEmitLoc(&man.hash, comp.emit_llvm_bc); | 2461 | cache_helpers.addOptionalEmitLoc(&man.hash, comp.emit_llvm_bc); |
| 2477 | | 2462 | |
| 2478 | man.hash.add(comp.bin_file.stack_size); | | |
| 2479 | man.hash.add(comp.bin_file.options.gc_sections); | | |
| 2480 | man.hash.add(comp.bin_file.options.eh_frame_hdr); | | |
| 2481 | man.hash.add(comp.bin_file.options.emit_relocs); | | |
| 2482 | man.hash.add(comp.bin_file.options.rdynamic); | | |
| 2483 | man.hash.addListOfBytes(comp.bin_file.options.lib_dirs); | | |
| 2484 | man.hash.addListOfBytes(comp.bin_file.options.rpath_list); | | |
| 2485 | man.hash.addListOfBytes(comp.bin_file.options.symbol_wrap_set.keys()); | | |
| 2486 | man.hash.add(comp.bin_file.options.each_lib_rpath); | | |
| 2487 | man.hash.add(comp.bin_file.build_id); | | |
| 2488 | man.hash.add(comp.skip_linker_dependencies); | 2463 | man.hash.add(comp.skip_linker_dependencies); |
| 2489 | man.hash.add(comp.bin_file.options.z_nodelete); | | |
| 2490 | man.hash.add(comp.bin_file.options.z_notext); | | |
| 2491 | man.hash.add(comp.bin_file.options.z_defs); | | |
| 2492 | man.hash.add(comp.bin_file.options.z_origin); | | |
| 2493 | man.hash.add(comp.bin_file.options.z_nocopyreloc); | | |
| 2494 | man.hash.add(comp.bin_file.options.z_now); | | |
| 2495 | man.hash.add(comp.bin_file.options.z_relro); | | |
| 2496 | man.hash.add(comp.bin_file.options.z_common_page_size orelse 0); | | |
| 2497 | man.hash.add(comp.bin_file.options.z_max_page_size orelse 0); | | |
| 2498 | man.hash.add(comp.bin_file.options.hash_style); | | |
| 2499 | man.hash.add(comp.bin_file.options.compress_debug_sections); | | |
| 2500 | man.hash.add(comp.include_compiler_rt); | 2464 | man.hash.add(comp.include_compiler_rt); |
| 2501 | man.hash.add(comp.bin_file.options.sort_section); | | |
| 2502 | if (comp.config.link_libc) { | 2465 | if (comp.config.link_libc) { |
| 2503 | man.hash.add(comp.bin_file.options.libc_installation != null); | 2466 | man.hash.add(comp.libc_installation != null); |
| 2504 | if (comp.bin_file.options.libc_installation) |libc_installation| { | 2467 | if (comp.libc_installation) |libc_installation| { |
| 2505 | man.hash.addOptionalBytes(libc_installation.crt_dir); | 2468 | man.hash.addOptionalBytes(libc_installation.crt_dir); |
| 2506 | if (target.abi == .msvc) { | 2469 | if (target.abi == .msvc) { |
| 2507 | man.hash.addOptionalBytes(libc_installation.msvc_lib_dir); | 2470 | man.hash.addOptionalBytes(libc_installation.msvc_lib_dir); |
| ... | @@ -2510,55 +2473,93 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes | ... | @@ -2510,55 +2473,93 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes |
| 2510 | } | 2473 | } |
| 2511 | man.hash.addOptionalBytes(target.dynamic_linker.get()); | 2474 | man.hash.addOptionalBytes(target.dynamic_linker.get()); |
| 2512 | } | 2475 | } |
| 2513 | man.hash.addOptionalBytes(comp.bin_file.options.soname); | | |
| 2514 | man.hash.add(comp.bin_file.options.version); | | |
| 2515 | try link.hashAddSystemLibs(man, comp.system_libs); | 2476 | try link.hashAddSystemLibs(man, comp.system_libs); |
| 2516 | man.hash.addListOfBytes(comp.bin_file.options.force_undefined_symbols.keys()); | 2477 | |
| 2517 | man.hash.add(comp.bin_file.allow_shlib_undefined); | 2478 | man.hash.add(comp.config.use_llvm); |
| 2518 | man.hash.add(comp.bin_file.options.bind_global_refs_locally); | 2479 | man.hash.add(comp.config.use_lib_llvm); |
| 2519 | man.hash.add(comp.bin_file.options.tsan); | 2480 | man.hash.add(comp.config.is_test); |
| 2520 | man.hash.addOptionalBytes(comp.bin_file.options.sysroot); | 2481 | man.hash.add(comp.config.import_memory); |
| 2521 | man.hash.add(comp.bin_file.options.linker_optimization); | 2482 | man.hash.add(comp.config.export_memory); |
| 2522 | | 2483 | man.hash.add(comp.config.shared_memory); |
| 2523 | switch (comp.bin_file.tag) { | 2484 | |
| 2524 | .elf => { | 2485 | if (comp.bin_file) |lf| { |
| 2525 | const elf = comp.bin_file.cast(link.File.Elf).?; | 2486 | man.hash.add(lf.stack_size); |
| 2526 | man.hash.add(elf.image_base); | 2487 | man.hash.add(lf.gc_sections); |
| 2527 | }, | 2488 | man.hash.addListOfBytes(lf.rpath_list); |
| 2528 | .wasm => { | 2489 | man.hash.add(lf.build_id); |
| 2529 | const wasm = comp.bin_file.cast(link.File.Wasm).?; | 2490 | man.hash.addListOfBytes(lf.force_undefined_symbols.keys()); |
| 2530 | man.hash.add(comp.config.import_memory); | 2491 | man.hash.add(lf.allow_shlib_undefined); |
| 2531 | man.hash.add(comp.config.export_memory); | 2492 | |
| 2532 | man.hash.add(comp.config.shared_memory); | 2493 | switch (lf.tag) { |
| 2533 | man.hash.add(wasm.initial_memory); | 2494 | .elf => { |
| 2534 | man.hash.add(wasm.max_memory); | 2495 | const elf = lf.cast(link.File.Elf).?; |
| 2535 | man.hash.add(wasm.global_base); | 2496 | man.hash.add(elf.rdynamic); |
| 2536 | }, | 2497 | man.hash.add(elf.eh_frame_hdr); |
| 2537 | .macho => { | 2498 | man.hash.add(elf.image_base); |
| 2538 | const macho = comp.bin_file.cast(link.File.MachO).?; | 2499 | man.hash.add(elf.emit_relocs); |
| 2539 | man.hash.addListOfBytes(comp.framework_dirs); | 2500 | man.hash.add(elf.z_nodelete); |
| 2540 | try link.hashAddFrameworks(man, macho.frameworks); | 2501 | man.hash.add(elf.z_notext); |
| 2541 | try man.addOptionalFile(macho.entitlements); | 2502 | man.hash.add(elf.z_defs); |
| 2542 | man.hash.add(macho.pagezero_size); | 2503 | man.hash.add(elf.z_origin); |
| 2543 | man.hash.add(macho.headerpad_size); | 2504 | man.hash.add(elf.z_nocopyreloc); |
| 2544 | man.hash.add(macho.headerpad_max_install_names); | 2505 | man.hash.add(elf.z_now); |
| 2545 | man.hash.add(macho.dead_strip_dylibs); | 2506 | man.hash.add(elf.z_relro); |
| 2546 | }, | 2507 | man.hash.add(elf.z_common_page_size orelse 0); |
| 2547 | .coff => { | 2508 | man.hash.add(elf.z_max_page_size orelse 0); |
| 2548 | const coff = comp.bin_file.cast(link.File.Coff).?; | 2509 | man.hash.addListOfBytes(elf.lib_dirs); |
| 2549 | man.hash.add(coff.image_base); | 2510 | man.hash.add(elf.hash_style); |
| 2550 | man.hash.add(coff.subsystem); | 2511 | man.hash.add(elf.compress_debug_sections); |
| 2551 | man.hash.add(coff.tsaware); | 2512 | man.hash.addListOfBytes(elf.symbol_wrap_set.keys()); |
| 2552 | man.hash.add(coff.nxcompat); | 2513 | man.hash.add(elf.each_lib_rpath); |
| 2553 | man.hash.add(coff.dynamicbase); | 2514 | man.hash.addOptional(elf.sort_section); |
| 2554 | man.hash.add(coff.major_subsystem_version); | 2515 | man.hash.addOptionalBytes(elf.soname); |
| 2555 | man.hash.add(coff.minor_subsystem_version); | 2516 | man.hash.add(elf.bind_global_refs_locally); |
| 2556 | }, | 2517 | try man.addOptionalFile(elf.linker_script); |
| | 2518 | try man.addOptionalFile(elf.version_script); |
| | 2519 | }, |
| | 2520 | .wasm => { |
| | 2521 | const wasm = lf.cast(link.File.Wasm).?; |
| | 2522 | man.hash.add(wasm.rdynamic); |
| | 2523 | man.hash.add(wasm.initial_memory); |
| | 2524 | man.hash.add(wasm.max_memory); |
| | 2525 | man.hash.add(wasm.global_base); |
| | 2526 | }, |
| | 2527 | .macho => { |
| | 2528 | const macho = lf.cast(link.File.MachO).?; |
| | 2529 | man.hash.addListOfBytes(comp.framework_dirs); |
| | 2530 | try link.File.MachO.hashAddFrameworks(man, macho.frameworks); |
| | 2531 | try man.addOptionalFile(macho.entitlements); |
| | 2532 | man.hash.add(macho.pagezero_vmsize); |
| | 2533 | man.hash.add(macho.headerpad_size); |
| | 2534 | man.hash.add(macho.headerpad_max_install_names); |
| | 2535 | man.hash.add(macho.dead_strip_dylibs); |
| | 2536 | }, |
| | 2537 | .coff => { |
| | 2538 | const coff = lf.cast(link.File.Coff).?; |
| | 2539 | man.hash.add(coff.dll_export_fns); |
| | 2540 | man.hash.add(coff.image_base); |
| | 2541 | man.hash.addOptional(coff.subsystem); |
| | 2542 | man.hash.add(coff.tsaware); |
| | 2543 | man.hash.add(coff.nxcompat); |
| | 2544 | man.hash.add(coff.dynamicbase); |
| | 2545 | man.hash.add(coff.major_subsystem_version); |
| | 2546 | man.hash.add(coff.minor_subsystem_version); |
| | 2547 | man.hash.addListOfBytes(coff.lib_dirs); |
| | 2548 | }, |
| | 2549 | .spirv => { |
| | 2550 | const spirv = lf.cast(link.File.SpirV).?; |
| | 2551 | _ = spirv; |
| | 2552 | // TODO |
| | 2553 | }, |
| | 2554 | .c => {}, // TODO |
| | 2555 | .plan9 => {}, // TODO |
| | 2556 | .nvptx => {}, // TODO |
| | 2557 | } |
| 2557 | } | 2558 | } |
| 2558 | } | 2559 | } |
| 2559 | | 2560 | |
| 2560 | fn emitOthers(comp: *Compilation) void { | 2561 | fn emitOthers(comp: *Compilation) void { |
| 2561 | if (comp.bin_file.options.output_mode != .Obj or comp.module != null or | 2562 | if (comp.config.output_mode != .Obj or comp.module != null or |
| 2562 | comp.c_object_table.count() == 0) | 2563 | comp.c_object_table.count() == 0) |
| 2563 | { | 2564 | { |
| 2564 | return; | 2565 | return; |
| ... | @@ -2724,10 +2725,10 @@ pub fn saveState(comp: *Compilation) !void { | ... | @@ -2724,10 +2725,10 @@ pub fn saveState(comp: *Compilation) !void { |
| 2724 | var bufs_list: [6]std.os.iovec_const = undefined; | 2725 | var bufs_list: [6]std.os.iovec_const = undefined; |
| 2725 | var bufs_len: usize = 0; | 2726 | var bufs_len: usize = 0; |
| 2726 | | 2727 | |
| 2727 | const emit = comp.bin_file.options.emit orelse return; | 2728 | const lf = comp.bin_file orelse return; |
| 2728 | | 2729 | |
| 2729 | if (comp.module) |mod| { | 2730 | if (comp.module) |zcu| { |
| 2730 | const ip = &mod.intern_pool; | 2731 | const ip = &zcu.intern_pool; |
| 2731 | const header: Header = .{ | 2732 | const header: Header = .{ |
| 2732 | .intern_pool = .{ | 2733 | .intern_pool = .{ |
| 2733 | .items_len = @intCast(ip.items.len), | 2734 | .items_len = @intCast(ip.items.len), |
| ... | @@ -2751,7 +2752,7 @@ pub fn saveState(comp: *Compilation) !void { | ... | @@ -2751,7 +2752,7 @@ pub fn saveState(comp: *Compilation) !void { |
| 2751 | } | 2752 | } |
| 2752 | var basename_buf: [255]u8 = undefined; | 2753 | var basename_buf: [255]u8 = undefined; |
| 2753 | const basename = std.fmt.bufPrint(&basename_buf, "{s}.zcs", .{ | 2754 | const basename = std.fmt.bufPrint(&basename_buf, "{s}.zcs", .{ |
| 2754 | comp.bin_file.options.root_name, | 2755 | comp.root_name, |
| 2755 | }) catch o: { | 2756 | }) catch o: { |
| 2756 | basename_buf[basename_buf.len - 4 ..].* = ".zcs".*; | 2757 | basename_buf[basename_buf.len - 4 ..].* = ".zcs".*; |
| 2757 | break :o &basename_buf; | 2758 | break :o &basename_buf; |
| ... | @@ -2759,7 +2760,7 @@ pub fn saveState(comp: *Compilation) !void { | ... | @@ -2759,7 +2760,7 @@ pub fn saveState(comp: *Compilation) !void { |
| 2759 | | 2760 | |
| 2760 | // Using an atomic file prevents a crash or power failure from corrupting | 2761 | // Using an atomic file prevents a crash or power failure from corrupting |
| 2761 | // the previous incremental compilation state. | 2762 | // the previous incremental compilation state. |
| 2762 | var af = try emit.directory.handle.atomicFile(basename, .{}); | 2763 | var af = try lf.emit.directory.handle.atomicFile(basename, .{}); |
| 2763 | defer af.deinit(); | 2764 | defer af.deinit(); |
| 2764 | try af.file.pwritevAll(bufs_list[0..bufs_len], 0); | 2765 | try af.file.pwritevAll(bufs_list[0..bufs_len], 0); |
| 2765 | try af.finish(); | 2766 | try af.finish(); |
| ... | @@ -3507,7 +3508,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: *std.Progress.Node) !v | ... | @@ -3507,7 +3508,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: *std.Progress.Node) !v |
| 3507 | error.AnalysisFail => return, | 3508 | error.AnalysisFail => return, |
| 3508 | }; | 3509 | }; |
| 3509 | const decl = module.declPtr(decl_index); | 3510 | const decl = module.declPtr(decl_index); |
| 3510 | if (decl.kind == .@"test" and comp.bin_file.options.is_test) { | 3511 | if (decl.kind == .@"test" and comp.config.is_test) { |
| 3511 | // Tests are always emitted in test binaries. The decl_refs are created by | 3512 | // Tests are always emitted in test binaries. The decl_refs are created by |
| 3512 | // Module.populateTestFunctions, but this will not queue body analysis, so do | 3513 | // Module.populateTestFunctions, but this will not queue body analysis, so do |
| 3513 | // that now. | 3514 | // that now. |
| ... | @@ -3850,7 +3851,7 @@ pub fn obtainCObjectCacheManifest(comp: *const Compilation) Cache.Manifest { | ... | @@ -3850,7 +3851,7 @@ pub fn obtainCObjectCacheManifest(comp: *const Compilation) Cache.Manifest { |
| 3850 | // based on the zig library directory alone. The zig lib directory file | 3851 | // based on the zig library directory alone. The zig lib directory file |
| 3851 | // path is purposefully either in the cache or not in the cache. The | 3852 | // path is purposefully either in the cache or not in the cache. The |
| 3852 | // decision should not be overridden here. | 3853 | // decision should not be overridden here. |
| 3853 | if (comp.bin_file.options.libc_installation != null) { | 3854 | if (comp.libc_installation != null) { |
| 3854 | man.hash.addListOfBytes(comp.libc_include_dir_list); | 3855 | man.hash.addListOfBytes(comp.libc_include_dir_list); |
| 3855 | } | 3856 | } |
| 3856 | | 3857 | |
| ... | @@ -4248,9 +4249,9 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P | ... | @@ -4248,9 +4249,9 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P |
| 4248 | // file and building an object we need to link them together, but with just one it should go | 4249 | // file and building an object we need to link them together, but with just one it should go |
| 4249 | // directly to the output file. | 4250 | // directly to the output file. |
| 4250 | const direct_o = comp.c_source_files.len == 1 and comp.module == null and | 4251 | const direct_o = comp.c_source_files.len == 1 and comp.module == null and |
| 4251 | comp.bin_file.options.output_mode == .Obj and comp.bin_file.options.objects.len == 0; | 4252 | comp.config.output_mode == .Obj and comp.objects.len == 0; |
| 4252 | const o_basename_noext = if (direct_o) | 4253 | const o_basename_noext = if (direct_o) |
| 4253 | comp.bin_file.options.root_name | 4254 | comp.root_name |
| 4254 | else | 4255 | else |
| 4255 | c_source_basename[0 .. c_source_basename.len - std.fs.path.extension(c_source_basename).len]; | 4256 | c_source_basename[0 .. c_source_basename.len - std.fs.path.extension(c_source_basename).len]; |
| 4256 | | 4257 | |
| ... | @@ -4304,8 +4305,8 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P | ... | @@ -4304,8 +4305,8 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P |
| 4304 | try argv.appendSlice(c_object.src.extra_flags); | 4305 | try argv.appendSlice(c_object.src.extra_flags); |
| 4305 | try argv.appendSlice(c_object.src.cache_exempt_flags); | 4306 | try argv.appendSlice(c_object.src.cache_exempt_flags); |
| 4306 | | 4307 | |
| 4307 | const out_obj_path = if (comp.bin_file.options.emit) |emit| | 4308 | const out_obj_path = if (comp.bin_file) |lf| |
| 4308 | try emit.directory.join(arena, &.{emit.sub_path}) | 4309 | try lf.emit.directory.join(arena, &.{lf.emit.sub_path}) |
| 4309 | else | 4310 | else |
| 4310 | "/dev/null"; | 4311 | "/dev/null"; |
| 4311 | | 4312 | |
| ... | @@ -4883,8 +4884,9 @@ pub fn addCCArgs( | ... | @@ -4883,8 +4884,9 @@ pub fn addCCArgs( |
| 4883 | argv: *std.ArrayList([]const u8), | 4884 | argv: *std.ArrayList([]const u8), |
| 4884 | ext: FileExt, | 4885 | ext: FileExt, |
| 4885 | out_dep_path: ?[]const u8, | 4886 | out_dep_path: ?[]const u8, |
| | 4887 | mod: *Package.Module, |
| 4886 | ) !void { | 4888 | ) !void { |
| 4887 | const target = comp.getTarget(); | 4889 | const target = mod.resolved_target.result; |
| 4888 | | 4890 | |
| 4889 | // As of Clang 16.x, it will by default read extra flags from /etc/clang. | 4891 | // As of Clang 16.x, it will by default read extra flags from /etc/clang. |
| 4890 | // I'm sure the person who implemented this means well, but they have a lot | 4892 | // I'm sure the person who implemented this means well, but they have a lot |
| ... | @@ -4905,15 +4907,15 @@ pub fn addCCArgs( | ... | @@ -4905,15 +4907,15 @@ pub fn addCCArgs( |
| 4905 | try argv.append("-fno-caret-diagnostics"); | 4907 | try argv.append("-fno-caret-diagnostics"); |
| 4906 | } | 4908 | } |
| 4907 | | 4909 | |
| 4908 | if (comp.bin_file.options.function_sections) { | 4910 | if (comp.bin_file.function_sections) { |
| 4909 | try argv.append("-ffunction-sections"); | 4911 | try argv.append("-ffunction-sections"); |
| 4910 | } | 4912 | } |
| 4911 | | 4913 | |
| 4912 | if (comp.bin_file.options.data_sections) { | 4914 | if (comp.bin_file.data_sections) { |
| 4913 | try argv.append("-fdata-sections"); | 4915 | try argv.append("-fdata-sections"); |
| 4914 | } | 4916 | } |
| 4915 | | 4917 | |
| 4916 | if (comp.bin_file.options.no_builtin) { | 4918 | if (comp.no_builtin) { |
| 4917 | try argv.append("-fno-builtin"); | 4919 | try argv.append("-fno-builtin"); |
| 4918 | } | 4920 | } |
| 4919 | | 4921 | |
| ... | @@ -4953,7 +4955,7 @@ pub fn addCCArgs( | ... | @@ -4953,7 +4955,7 @@ pub fn addCCArgs( |
| 4953 | })); | 4955 | })); |
| 4954 | } | 4956 | } |
| 4955 | | 4957 | |
| 4956 | if (comp.bin_file.options.link_libunwind) { | 4958 | if (comp.config.link_libunwind) { |
| 4957 | const libunwind_include_path = try std.fs.path.join(arena, &[_][]const u8{ | 4959 | const libunwind_include_path = try std.fs.path.join(arena, &[_][]const u8{ |
| 4958 | comp.zig_lib_directory.path.?, "libunwind", "include", | 4960 | comp.zig_lib_directory.path.?, "libunwind", "include", |
| 4959 | }); | 4961 | }); |
| ... | @@ -4987,7 +4989,7 @@ pub fn addCCArgs( | ... | @@ -4987,7 +4989,7 @@ pub fn addCCArgs( |
| 4987 | "-nostdinc", | 4989 | "-nostdinc", |
| 4988 | "-fno-spell-checking", | 4990 | "-fno-spell-checking", |
| 4989 | }); | 4991 | }); |
| 4990 | if (comp.bin_file.options.lto) { | 4992 | if (comp.config.lto) { |
| 4991 | try argv.append("-flto"); | 4993 | try argv.append("-flto"); |
| 4992 | } | 4994 | } |
| 4993 | | 4995 | |
| ... | @@ -5042,9 +5044,8 @@ pub fn addCCArgs( | ... | @@ -5042,9 +5044,8 @@ pub fn addCCArgs( |
| 5042 | argv.appendAssumeCapacity(arg); | 5044 | argv.appendAssumeCapacity(arg); |
| 5043 | } | 5045 | } |
| 5044 | } | 5046 | } |
| 5045 | const code_model = comp.bin_file.options.machine_code_model; | 5047 | if (mod.code_model != .default) { |
| 5046 | if (code_model != .default) { | 5048 | try argv.append(try std.fmt.allocPrint(arena, "-mcmodel={s}", .{@tagName(mod.code_model)})); |
| 5047 | try argv.append(try std.fmt.allocPrint(arena, "-mcmodel={s}", .{@tagName(code_model)})); | | |
| 5048 | } | 5049 | } |
| 5049 | | 5050 | |
| 5050 | switch (target.os.tag) { | 5051 | switch (target.os.tag) { |
| ... | @@ -5093,7 +5094,7 @@ pub fn addCCArgs( | ... | @@ -5093,7 +5094,7 @@ pub fn addCCArgs( |
| 5093 | try argv.append("-mthumb"); | 5094 | try argv.append("-mthumb"); |
| 5094 | } | 5095 | } |
| 5095 | | 5096 | |
| 5096 | if (comp.sanitize_c and !comp.bin_file.options.tsan) { | 5097 | if (mod.sanitize_c and !mod.sanitize_thread) { |
| 5097 | try argv.append("-fsanitize=undefined"); | 5098 | try argv.append("-fsanitize=undefined"); |
| 5098 | try argv.append("-fsanitize-trap=undefined"); | 5099 | try argv.append("-fsanitize-trap=undefined"); |
| 5099 | // It is very common, and well-defined, for a pointer on one side of a C ABI | 5100 | // It is very common, and well-defined, for a pointer on one side of a C ABI |
| ... | @@ -5104,27 +5105,27 @@ pub fn addCCArgs( | ... | @@ -5104,27 +5105,27 @@ pub fn addCCArgs( |
| 5104 | // Without this flag, Clang would invoke UBSAN when such an extern | 5105 | // Without this flag, Clang would invoke UBSAN when such an extern |
| 5105 | // function was called. | 5106 | // function was called. |
| 5106 | try argv.append("-fno-sanitize=function"); | 5107 | try argv.append("-fno-sanitize=function"); |
| 5107 | } else if (comp.sanitize_c and comp.bin_file.options.tsan) { | 5108 | } else if (mod.sanitize_c and mod.sanitize_thread) { |
| 5108 | try argv.append("-fsanitize=undefined,thread"); | 5109 | try argv.append("-fsanitize=undefined,thread"); |
| 5109 | try argv.append("-fsanitize-trap=undefined"); | 5110 | try argv.append("-fsanitize-trap=undefined"); |
| 5110 | try argv.append("-fno-sanitize=function"); | 5111 | try argv.append("-fno-sanitize=function"); |
| 5111 | } else if (!comp.sanitize_c and comp.bin_file.options.tsan) { | 5112 | } else if (!mod.sanitize_c and mod.sanitize_thread) { |
| 5112 | try argv.append("-fsanitize=thread"); | 5113 | try argv.append("-fsanitize=thread"); |
| 5113 | } | 5114 | } |
| 5114 | | 5115 | |
| 5115 | if (comp.bin_file.options.red_zone) { | 5116 | if (mod.red_zone) { |
| 5116 | try argv.append("-mred-zone"); | 5117 | try argv.append("-mred-zone"); |
| 5117 | } else if (target_util.hasRedZone(target)) { | 5118 | } else if (target_util.hasRedZone(target)) { |
| 5118 | try argv.append("-mno-red-zone"); | 5119 | try argv.append("-mno-red-zone"); |
| 5119 | } | 5120 | } |
| 5120 | | 5121 | |
| 5121 | if (comp.bin_file.options.omit_frame_pointer) { | 5122 | if (mod.omit_frame_pointer) { |
| 5122 | try argv.append("-fomit-frame-pointer"); | 5123 | try argv.append("-fomit-frame-pointer"); |
| 5123 | } else { | 5124 | } else { |
| 5124 | try argv.append("-fno-omit-frame-pointer"); | 5125 | try argv.append("-fno-omit-frame-pointer"); |
| 5125 | } | 5126 | } |
| 5126 | | 5127 | |
| 5127 | const ssp_buf_size = comp.bin_file.options.stack_protector; | 5128 | const ssp_buf_size = mod.stack_protector; |
| 5128 | if (ssp_buf_size != 0) { | 5129 | if (ssp_buf_size != 0) { |
| 5129 | try argv.appendSlice(&[_][]const u8{ | 5130 | try argv.appendSlice(&[_][]const u8{ |
| 5130 | "-fstack-protector-strong", | 5131 | "-fstack-protector-strong", |
| ... | @@ -5135,7 +5136,7 @@ pub fn addCCArgs( | ... | @@ -5135,7 +5136,7 @@ pub fn addCCArgs( |
| 5135 | try argv.append("-fno-stack-protector"); | 5136 | try argv.append("-fno-stack-protector"); |
| 5136 | } | 5137 | } |
| 5137 | | 5138 | |
| 5138 | switch (comp.bin_file.options.optimize_mode) { | 5139 | switch (mod.optimize_mode) { |
| 5139 | .Debug => { | 5140 | .Debug => { |
| 5140 | // windows c runtime requires -D_DEBUG if using debug libraries | 5141 | // windows c runtime requires -D_DEBUG if using debug libraries |
| 5141 | try argv.append("-D_DEBUG"); | 5142 | try argv.append("-D_DEBUG"); |
| ... | @@ -5165,7 +5166,7 @@ pub fn addCCArgs( | ... | @@ -5165,7 +5166,7 @@ pub fn addCCArgs( |
| 5165 | }, | 5166 | }, |
| 5166 | } | 5167 | } |
| 5167 | | 5168 | |
| 5168 | if (target_util.supports_fpic(target) and comp.bin_file.options.pic) { | 5169 | if (target_util.supports_fpic(target) and mod.pic) { |
| 5169 | try argv.append("-fPIC"); | 5170 | try argv.append("-fPIC"); |
| 5170 | } | 5171 | } |
| 5171 | | 5172 | |
| ... | @@ -5940,7 +5941,7 @@ pub fn get_libc_crt_file(comp: *Compilation, arena: Allocator, basename: []const | ... | @@ -5940,7 +5941,7 @@ pub fn get_libc_crt_file(comp: *Compilation, arena: Allocator, basename: []const |
| 5940 | { | 5941 | { |
| 5941 | return comp.crt_files.get(basename).?.full_object_path; | 5942 | return comp.crt_files.get(basename).?.full_object_path; |
| 5942 | } | 5943 | } |
| 5943 | const lci = comp.bin_file.options.libc_installation orelse return error.LibCInstallationNotAvailable; | 5944 | const lci = comp.libc_installation orelse return error.LibCInstallationNotAvailable; |
| 5944 | const crt_dir_path = lci.crt_dir orelse return error.LibCInstallationMissingCRTDir; | 5945 | const crt_dir_path = lci.crt_dir orelse return error.LibCInstallationMissingCRTDir; |
| 5945 | const full_path = try std.fs.path.join(arena, &[_][]const u8{ crt_dir_path, basename }); | 5946 | const full_path = try std.fs.path.join(arena, &[_][]const u8{ crt_dir_path, basename }); |
| 5946 | return full_path; | 5947 | return full_path; |
| ... | @@ -6112,7 +6113,7 @@ fn canBuildZigLibC(target: std.Target, use_llvm: bool) bool { | ... | @@ -6112,7 +6113,7 @@ fn canBuildZigLibC(target: std.Target, use_llvm: bool) bool { |
| 6112 | | 6113 | |
| 6113 | pub fn getZigBackend(comp: Compilation) std.builtin.CompilerBackend { | 6114 | pub fn getZigBackend(comp: Compilation) std.builtin.CompilerBackend { |
| 6114 | const target = comp.root_mod.resolved_target.result; | 6115 | const target = comp.root_mod.resolved_target.result; |
| 6115 | return target_util.zigBackend(target, comp.bin_file.options.use_llvm); | 6116 | return target_util.zigBackend(target, comp.config.use_llvm); |
| 6116 | } | 6117 | } |
| 6117 | | 6118 | |
| 6118 | pub fn updateSubCompilation( | 6119 | pub fn updateSubCompilation( |
| ... | @@ -6165,6 +6166,9 @@ fn buildOutputFromZig( | ... | @@ -6165,6 +6166,9 @@ fn buildOutputFromZig( |
| 6165 | | 6166 | |
| 6166 | assert(output_mode != .Exe); | 6167 | assert(output_mode != .Exe); |
| 6167 | | 6168 | |
| | 6169 | const lf = comp.bin_file.?; |
| | 6170 | const unwind_tables = if (lf.cast(link.File.Elf)) |elf| elf.eh_frame_hdr else false; |
| | 6171 | |
| 6168 | const config = try Config.resolve(.{ | 6172 | const config = try Config.resolve(.{ |
| 6169 | .output_mode = output_mode, | 6173 | .output_mode = output_mode, |
| 6170 | .resolved_target = comp.root_mod.resolved_target, | 6174 | .resolved_target = comp.root_mod.resolved_target, |
| ... | @@ -6173,6 +6177,7 @@ fn buildOutputFromZig( | ... | @@ -6173,6 +6177,7 @@ fn buildOutputFromZig( |
| 6173 | .emit_bin = true, | 6177 | .emit_bin = true, |
| 6174 | .root_optimize_mode = comp.compilerRtOptMode(), | 6178 | .root_optimize_mode = comp.compilerRtOptMode(), |
| 6175 | .link_libc = comp.config.link_libc, | 6179 | .link_libc = comp.config.link_libc, |
| | 6180 | .any_unwind_tables = unwind_tables, |
| 6176 | }); | 6181 | }); |
| 6177 | | 6182 | |
| 6178 | const root_mod = Package.Module.create(.{ | 6183 | const root_mod = Package.Module.create(.{ |
| ... | @@ -6187,9 +6192,10 @@ fn buildOutputFromZig( | ... | @@ -6187,9 +6192,10 @@ fn buildOutputFromZig( |
| 6187 | .stack_protector = 0, | 6192 | .stack_protector = 0, |
| 6188 | .red_zone = comp.root_mod.red_zone, | 6193 | .red_zone = comp.root_mod.red_zone, |
| 6189 | .omit_frame_pointer = comp.root_mod.omit_frame_pointer, | 6194 | .omit_frame_pointer = comp.root_mod.omit_frame_pointer, |
| 6190 | .unwind_tables = comp.bin_file.options.eh_frame_hdr, | 6195 | .unwind_tables = unwind_tables, |
| 6191 | .pic = comp.root_mod.pic, | 6196 | .pic = comp.root_mod.pic, |
| 6192 | .optimize_mode = comp.compilerRtOptMode(), | 6197 | .optimize_mode = comp.compilerRtOptMode(), |
| | 6198 | .structured_cfg = comp.root_mod.structured_cfg, |
| 6193 | }, | 6199 | }, |
| 6194 | .global = config, | 6200 | .global = config, |
| 6195 | .cc_argv = &.{}, | 6201 | .cc_argv = &.{}, |
| ... | @@ -6210,21 +6216,21 @@ fn buildOutputFromZig( | ... | @@ -6210,21 +6216,21 @@ fn buildOutputFromZig( |
| 6210 | .global_cache_directory = comp.global_cache_directory, | 6216 | .global_cache_directory = comp.global_cache_directory, |
| 6211 | .local_cache_directory = comp.global_cache_directory, | 6217 | .local_cache_directory = comp.global_cache_directory, |
| 6212 | .zig_lib_directory = comp.zig_lib_directory, | 6218 | .zig_lib_directory = comp.zig_lib_directory, |
| | 6219 | .self_exe_path = comp.self_exe_path, |
| 6213 | .resolved = config, | 6220 | .resolved = config, |
| 6214 | .root_mod = root_mod, | 6221 | .root_mod = root_mod, |
| 6215 | .cache_mode = .whole, | 6222 | .cache_mode = .whole, |
| 6216 | .root_name = root_name, | 6223 | .root_name = root_name, |
| 6217 | .thread_pool = comp.thread_pool, | 6224 | .thread_pool = comp.thread_pool, |
| 6218 | .libc_installation = comp.bin_file.options.libc_installation, | 6225 | .libc_installation = comp.libc_installation, |
| 6219 | .emit_bin = emit_bin, | 6226 | .emit_bin = emit_bin, |
| 6220 | .link_mode = .Static, | 6227 | .link_mode = .Static, |
| 6221 | .function_sections = true, | 6228 | .function_sections = true, |
| 6222 | .data_sections = true, | 6229 | .data_sections = true, |
| 6223 | .no_builtin = true, | 6230 | .no_builtin = true, |
| 6224 | .emit_h = null, | 6231 | .emit_h = null, |
| 6225 | .self_exe_path = comp.self_exe_path, | | |
| 6226 | .verbose_cc = comp.verbose_cc, | 6232 | .verbose_cc = comp.verbose_cc, |
| 6227 | .verbose_link = comp.bin_file.options.verbose_link, | 6233 | .verbose_link = comp.verbose_link, |
| 6228 | .verbose_air = comp.verbose_air, | 6234 | .verbose_air = comp.verbose_air, |
| 6229 | .verbose_intern_pool = comp.verbose_intern_pool, | 6235 | .verbose_intern_pool = comp.verbose_intern_pool, |
| 6230 | .verbose_generic_instances = comp.verbose_intern_pool, | 6236 | .verbose_generic_instances = comp.verbose_intern_pool, |
| ... | @@ -6234,7 +6240,6 @@ fn buildOutputFromZig( | ... | @@ -6234,7 +6240,6 @@ fn buildOutputFromZig( |
| 6234 | .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features, | 6240 | .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features, |
| 6235 | .clang_passthrough_mode = comp.clang_passthrough_mode, | 6241 | .clang_passthrough_mode = comp.clang_passthrough_mode, |
| 6236 | .skip_linker_dependencies = true, | 6242 | .skip_linker_dependencies = true, |
| 6237 | .want_structured_cfg = comp.bin_file.options.want_structured_cfg, | | |
| 6238 | }); | 6243 | }); |
| 6239 | defer sub_compilation.destroy(); | 6244 | defer sub_compilation.destroy(); |
| 6240 | | 6245 | |
| ... | @@ -6242,8 +6247,8 @@ fn buildOutputFromZig( | ... | @@ -6242,8 +6247,8 @@ fn buildOutputFromZig( |
| 6242 | | 6247 | |
| 6243 | assert(out.* == null); | 6248 | assert(out.* == null); |
| 6244 | out.* = Compilation.CRTFile{ | 6249 | out.* = Compilation.CRTFile{ |
| 6245 | .full_object_path = try sub_compilation.bin_file.options.emit.?.directory.join(comp.gpa, &[_][]const u8{ | 6250 | .full_object_path = try sub_compilation.bin_file.?.emit.directory.join(comp.gpa, &[_][]const u8{ |
| 6246 | sub_compilation.bin_file.options.emit.?.sub_path, | 6251 | sub_compilation.bin_file.?.emit.sub_path, |
| 6247 | }), | 6252 | }), |
| 6248 | .lock = sub_compilation.bin_file.toOwnedLock(), | 6253 | .lock = sub_compilation.bin_file.toOwnedLock(), |
| 6249 | }; | 6254 | }; |
| ... | @@ -6260,51 +6265,70 @@ pub fn build_crt_file( | ... | @@ -6260,51 +6265,70 @@ pub fn build_crt_file( |
| 6260 | const tracy_trace = trace(@src()); | 6265 | const tracy_trace = trace(@src()); |
| 6261 | defer tracy_trace.end(); | 6266 | defer tracy_trace.end(); |
| 6262 | | 6267 | |
| 6263 | const target = comp.getTarget(); | 6268 | const gpa = comp.gpa; |
| 6264 | const basename = try std.zig.binNameAlloc(comp.gpa, .{ | 6269 | const basename = try std.zig.binNameAlloc(gpa, .{ |
| 6265 | .root_name = root_name, | 6270 | .root_name = root_name, |
| 6266 | .target = target, | 6271 | .target = comp.root_mod.resolved_target.result, |
| 6267 | .output_mode = output_mode, | 6272 | .output_mode = output_mode, |
| 6268 | }); | 6273 | }); |
| 6269 | errdefer comp.gpa.free(basename); | 6274 | errdefer gpa.free(basename); |
| 6270 | | 6275 | |
| 6271 | const sub_compilation = try Compilation.create(comp.gpa, .{ | 6276 | const config = try Config.resolve(.{ |
| | 6277 | .output_mode = output_mode, |
| | 6278 | .resolved_target = comp.root_mod.resolved_target, |
| | 6279 | .is_test = false, |
| | 6280 | .have_zcu = false, |
| | 6281 | .emit_bin = true, |
| | 6282 | .root_optimize_mode = comp.compilerRtOptMode(), |
| | 6283 | .link_libc = false, |
| | 6284 | .lto = switch (output_mode) { |
| | 6285 | .Lib => comp.config.lto, |
| | 6286 | .Obj, .Exe => false, |
| | 6287 | }, |
| | 6288 | }); |
| | 6289 | const root_mod = Package.Module.create(.{ |
| | 6290 | .paths = .{ |
| | 6291 | .root = .{ .root_dir = comp.zig_lib_directory }, |
| | 6292 | .root_src_path = "", |
| | 6293 | }, |
| | 6294 | .fully_qualified_name = "root", |
| | 6295 | .inherited = .{ |
| | 6296 | .strip = comp.compilerRtStrip(), |
| | 6297 | .stack_check = false, |
| | 6298 | .stack_protector = 0, |
| | 6299 | .sanitize_c = false, |
| | 6300 | .sanitize_thread = false, |
| | 6301 | .red_zone = comp.root_mod.red_zone, |
| | 6302 | .omit_frame_pointer = comp.root_mod.omit_frame_pointer, |
| | 6303 | .valgrind = false, |
| | 6304 | .unwind_tables = false, |
| | 6305 | .pic = comp.root_mod.pic, |
| | 6306 | .optimize_mode = comp.compilerRtOptMode(), |
| | 6307 | .structured_cfg = comp.root_mod.structured_cfg, |
| | 6308 | }, |
| | 6309 | .global = config, |
| | 6310 | .cc_argv = &.{}, |
| | 6311 | }); |
| | 6312 | |
| | 6313 | const sub_compilation = try Compilation.create(gpa, .{ |
| 6272 | .local_cache_directory = comp.global_cache_directory, | 6314 | .local_cache_directory = comp.global_cache_directory, |
| 6273 | .global_cache_directory = comp.global_cache_directory, | 6315 | .global_cache_directory = comp.global_cache_directory, |
| 6274 | .zig_lib_directory = comp.zig_lib_directory, | 6316 | .zig_lib_directory = comp.zig_lib_directory, |
| | 6317 | .self_exe_path = comp.self_exe_path, |
| 6275 | .cache_mode = .whole, | 6318 | .cache_mode = .whole, |
| 6276 | .target = target, | 6319 | .resolved = config, |
| | 6320 | .root_mod = root_mod, |
| 6277 | .root_name = root_name, | 6321 | .root_name = root_name, |
| 6278 | .main_mod = null, | | |
| 6279 | .output_mode = output_mode, | | |
| 6280 | .thread_pool = comp.thread_pool, | 6322 | .thread_pool = comp.thread_pool, |
| 6281 | .libc_installation = comp.bin_file.options.libc_installation, | 6323 | .libc_installation = comp.libc_installation, |
| 6282 | .emit_bin = .{ | 6324 | .emit_bin = .{ |
| 6283 | .directory = null, // Put it in the cache directory. | 6325 | .directory = null, // Put it in the cache directory. |
| 6284 | .basename = basename, | 6326 | .basename = basename, |
| 6285 | }, | 6327 | }, |
| 6286 | .optimize_mode = comp.compilerRtOptMode(), | | |
| 6287 | .want_sanitize_c = false, | | |
| 6288 | .want_stack_check = false, | | |
| 6289 | .want_stack_protector = 0, | | |
| 6290 | .want_red_zone = comp.bin_file.options.red_zone, | | |
| 6291 | .omit_frame_pointer = comp.bin_file.options.omit_frame_pointer, | | |
| 6292 | .want_valgrind = false, | | |
| 6293 | .want_tsan = false, | | |
| 6294 | .want_pic = comp.bin_file.options.pic, | | |
| 6295 | .want_pie = null, | | |
| 6296 | .want_lto = switch (output_mode) { | | |
| 6297 | .Lib => comp.bin_file.options.lto, | | |
| 6298 | .Obj, .Exe => false, | | |
| 6299 | }, | | |
| 6300 | .emit_h = null, | 6328 | .emit_h = null, |
| 6301 | .strip = comp.compilerRtStrip(), | | |
| 6302 | .is_native_os = comp.bin_file.options.is_native_os, | | |
| 6303 | .is_native_abi = comp.bin_file.options.is_native_abi, | | |
| 6304 | .self_exe_path = comp.self_exe_path, | | |
| 6305 | .c_source_files = c_source_files, | 6329 | .c_source_files = c_source_files, |
| 6306 | .verbose_cc = comp.verbose_cc, | 6330 | .verbose_cc = comp.verbose_cc, |
| 6307 | .verbose_link = comp.bin_file.options.verbose_link, | 6331 | .verbose_link = comp.verbose_link, |
| 6308 | .verbose_air = comp.verbose_air, | 6332 | .verbose_air = comp.verbose_air, |
| 6309 | .verbose_intern_pool = comp.verbose_intern_pool, | 6333 | .verbose_intern_pool = comp.verbose_intern_pool, |
| 6310 | .verbose_generic_instances = comp.verbose_generic_instances, | 6334 | .verbose_generic_instances = comp.verbose_generic_instances, |
| ... | @@ -6314,17 +6338,16 @@ pub fn build_crt_file( | ... | @@ -6314,17 +6338,16 @@ pub fn build_crt_file( |
| 6314 | .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features, | 6338 | .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features, |
| 6315 | .clang_passthrough_mode = comp.clang_passthrough_mode, | 6339 | .clang_passthrough_mode = comp.clang_passthrough_mode, |
| 6316 | .skip_linker_dependencies = true, | 6340 | .skip_linker_dependencies = true, |
| 6317 | .want_structured_cfg = comp.bin_file.options.want_structured_cfg, | | |
| 6318 | }); | 6341 | }); |
| 6319 | defer sub_compilation.destroy(); | 6342 | defer sub_compilation.destroy(); |
| 6320 | | 6343 | |
| 6321 | try comp.updateSubCompilation(sub_compilation, misc_task_tag, prog_node); | 6344 | try comp.updateSubCompilation(sub_compilation, misc_task_tag, prog_node); |
| 6322 | | 6345 | |
| 6323 | try comp.crt_files.ensureUnusedCapacity(comp.gpa, 1); | 6346 | try comp.crt_files.ensureUnusedCapacity(gpa, 1); |
| 6324 | | 6347 | |
| 6325 | comp.crt_files.putAssumeCapacityNoClobber(basename, .{ | 6348 | comp.crt_files.putAssumeCapacityNoClobber(basename, .{ |
| 6326 | .full_object_path = try sub_compilation.bin_file.options.emit.?.directory.join(comp.gpa, &[_][]const u8{ | 6349 | .full_object_path = try sub_compilation.bin_file.?.emit.directory.join(gpa, &[_][]const u8{ |
| 6327 | sub_compilation.bin_file.options.emit.?.sub_path, | 6350 | sub_compilation.bin_file.?.emit.sub_path, |
| 6328 | }), | 6351 | }), |
| 6329 | .lock = sub_compilation.bin_file.toOwnedLock(), | 6352 | .lock = sub_compilation.bin_file.toOwnedLock(), |
| 6330 | }); | 6353 | }); |
| ... | @@ -6357,10 +6380,11 @@ pub fn addLinkLib(comp: *Compilation, lib_name: []const u8) !void { | ... | @@ -6357,10 +6380,11 @@ pub fn addLinkLib(comp: *Compilation, lib_name: []const u8) !void { |
| 6357 | /// compiler-rt, libcxx, libc, libunwind, etc. | 6380 | /// compiler-rt, libcxx, libc, libunwind, etc. |
| 6358 | pub fn compilerRtOptMode(comp: Compilation) std.builtin.OptimizeMode { | 6381 | pub fn compilerRtOptMode(comp: Compilation) std.builtin.OptimizeMode { |
| 6359 | if (comp.debug_compiler_runtime_libs) { | 6382 | if (comp.debug_compiler_runtime_libs) { |
| 6360 | return comp.bin_file.options.optimize_mode; | 6383 | return comp.root_mod.optimize_mode; |
| 6361 | } | 6384 | } |
| 6362 | switch (comp.bin_file.options.optimize_mode) { | 6385 | const target = comp.root_mod.resolved_target.result; |
| 6363 | .Debug, .ReleaseSafe => return target_util.defaultCompilerRtOptimizeMode(comp.getTarget()), | 6386 | switch (comp.root_mod.optimize_mode) { |
| | 6387 | .Debug, .ReleaseSafe => return target_util.defaultCompilerRtOptimizeMode(target), |
| 6364 | .ReleaseFast => return .ReleaseFast, | 6388 | .ReleaseFast => return .ReleaseFast, |
| 6365 | .ReleaseSmall => return .ReleaseSmall, | 6389 | .ReleaseSmall => return .ReleaseSmall, |
| 6366 | } | 6390 | } |
| ... | @@ -6369,5 +6393,5 @@ pub fn compilerRtOptMode(comp: Compilation) std.builtin.OptimizeMode { | ... | @@ -6369,5 +6393,5 @@ pub fn compilerRtOptMode(comp: Compilation) std.builtin.OptimizeMode { |
| 6369 | /// This decides whether to strip debug info for all zig-provided libraries, including | 6393 | /// This decides whether to strip debug info for all zig-provided libraries, including |
| 6370 | /// compiler-rt, libcxx, libc, libunwind, etc. | 6394 | /// compiler-rt, libcxx, libc, libunwind, etc. |
| 6371 | pub fn compilerRtStrip(comp: Compilation) bool { | 6395 | pub fn compilerRtStrip(comp: Compilation) bool { |
| 6372 | return comp.bin_file.options.strip; | 6396 | return comp.root_mod.strip; |
| 6373 | } | 6397 | } |