Commit 951c5b3f67
Changed files (2)
src
Compilation
src/Compilation/Config.zig
@@ -1,4 +1,7 @@
-//! User-specified settings that have all the defaults resolved into concrete values.
+//! User-specified settings that have all the defaults resolved into concrete
+//! values. These values are observable before calling Compilation.create for
+//! the benefit of Module creation API, which needs access to these details in
+//! order to resolve per-Module defaults.
have_zcu: bool,
output_mode: std.builtin.OutputMode,
@@ -6,12 +9,27 @@ link_mode: std.builtin.LinkMode,
link_libc: bool,
link_libcpp: bool,
link_libunwind: bool,
-any_unwind_tables: bool,
+/// True if and only if the c_source_files field will have nonzero length when
+/// calling Compilation.create.
any_c_source_files: bool,
+/// This is true if any Module has unwind_tables set explicitly to true. Until
+/// Compilation.create is called, it is possible for this to be false while in
+/// fact all Module instances have unwind_tables=true due to the default
+/// being unwind_tables=true. After Compilation.create is called this will
+/// also take into account the default setting, making this value true if and
+/// only if any Module has unwind_tables set to true.
+any_unwind_tables: bool,
+/// This is true if any Module has single_threaded set explicitly to false. Until
+/// Compilation.create is called, it is possible for this to be false while in
+/// fact all Module instances have single_threaded=false due to the default
+/// being non-single-threaded. After Compilation.create is called this will
+/// also take into account the default setting, making this value true if and
+/// only if any Module has single_threaded set to false.
any_non_single_threaded: bool,
-/// This is true if any Module has error_tracing set to true. Function types
-/// and function calling convention depend on this global value, however, other
-/// kinds of error tracing are omitted depending on the per-Module setting.
+/// This is true if and only if any Module has error_tracing set to true.
+/// Function types and function calling convention depend on this global value,
+/// however, other kinds of error tracing are omitted depending on the
+/// per-Module setting.
any_error_tracing: bool,
any_sanitize_thread: bool,
pie: bool,
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,