From 951c5b3f67e086c50ba8d0cd9318cb770fd3f724 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 26 Dec 2023 17:09:40 -0700 Subject: frontend: fix "any" default resolution ambiguity In Compilation.create, update the resolved config to account for the default resolution of the root module. This makes it so that, for example, reading comp.config.any_non_single_threaded is valid in order to determine whether any module has single_threaded=false. --- src/Compilation.zig | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/Compilation.zig') diff --git a/src/Compilation.zig b/src/Compilation.zig index 00d6ec3193..15b507b7a4 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1198,7 +1198,12 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { const use_llvm = options.config.use_llvm; - const any_unwind_tables = options.config.any_unwind_tables; + // The "any" values provided by resolved config only account for + // explicitly-provided settings. We now make them additionally account + // for default setting resolution. + const any_unwind_tables = options.config.any_unwind_tables or options.root_mod.unwind_tables; + const any_non_single_threaded = options.config.any_non_single_threaded or !options.root_mod.single_threaded; + const any_sanitize_thread = options.config.any_sanitize_thread or options.root_mod.sanitize_thread; const link_eh_frame_hdr = options.link_eh_frame_hdr or any_unwind_tables; const build_id = options.build_id orelse .none; @@ -1503,6 +1508,12 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { .native_system_include_paths = options.native_system_include_paths, }; + // Prevent some footguns by making the "any" fields of config reflect + // the default Module settings. + comp.config.any_unwind_tables = any_unwind_tables; + comp.config.any_non_single_threaded = any_non_single_threaded; + comp.config.any_sanitize_thread = any_sanitize_thread; + const lf_open_opts: link.File.OpenOptions = .{ .linker_script = options.linker_script, .z_nodelete = options.linker_z_nodelete, -- cgit v1.2.3