From 8af82621d75f9f0d96ebf734f5ea862d06a5f1fa Mon Sep 17 00:00:00 2001 From: Alex Rønne Petersen Date: Wed, 13 Nov 2024 06:04:04 +0100 Subject: compiler: Improve the handling of unwind table levels. The goal here is to support both levels of unwind tables (sync and async) in zig cc and zig build. Previously, the LLVM backend always used async tables while zig cc was partially influenced by whatever was Clang's default. --- src/Compilation/Config.zig | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/Compilation') diff --git a/src/Compilation/Config.zig b/src/Compilation/Config.zig index 4458d474bb..baaa6c9f47 100644 --- a/src/Compilation/Config.zig +++ b/src/Compilation/Config.zig @@ -12,13 +12,14 @@ link_libunwind: 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 not `.none` if any `Module` has `unwind_tables` set explicitly to a +/// value other than `.none`. Until `Compilation.create()` is called, it is +/// possible for this to be `.none` while in fact all `Module` instances have +/// `unwind_tables != .none` due to the default. After `Compilation.create()` is +/// called, this will also take into account the default setting, making this +/// value `.sync` or `.@"async"` if and only if any `Module` has +/// `unwind_tables != .none`. +any_unwind_tables: std.builtin.UnwindTables, /// 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 @@ -85,7 +86,7 @@ pub const Options = struct { any_non_single_threaded: bool = false, any_sanitize_thread: bool = false, any_fuzz: bool = false, - any_unwind_tables: bool = false, + any_unwind_tables: std.builtin.UnwindTables = .none, any_dyn_libs: bool = false, any_c_source_files: bool = false, any_non_stripped: bool = false, @@ -356,8 +357,11 @@ pub fn resolve(options: Options) ResolveError!Config { break :b false; }; - const any_unwind_tables = options.any_unwind_tables or - link_libunwind or target_util.needUnwindTables(target); + const any_unwind_tables = b: { + if (options.any_unwind_tables != .none) break :b options.any_unwind_tables; + + break :b target_util.needUnwindTables(target, link_libunwind, options.any_sanitize_thread); + }; const link_mode = b: { const explicitly_exe_or_dyn_lib = switch (options.output_mode) { -- cgit v1.2.3