aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authorAlex Rønne Petersen <alex@alexrp.com>2024-11-13 06:04:04 +0100
committerAlex Rønne Petersen <alex@alexrp.com>2024-12-11 00:10:15 +0100
commit8af82621d75f9f0d96ebf734f5ea862d06a5f1fa (patch)
treee004815ccdc1ae57557d69a2e42270edd81ca469 /src/Compilation.zig
parent0b67463b9285158d818d6cd196c5f2ba9961a05e (diff)
downloadzig-8af82621d75f9f0d96ebf734f5ea862d06a5f1fa.tar.gz
zig-8af82621d75f9f0d96ebf734f5ea862d06a5f1fa.zip
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.
Diffstat (limited to 'src/Compilation.zig')
-rw-r--r--src/Compilation.zig27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index c198b5af82..16d3589b5d 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -1261,12 +1261,15 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
// 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_unwind_tables = switch (options.config.any_unwind_tables) {
+ .none => options.root_mod.unwind_tables,
+ .sync, .@"async" => |uwt| uwt,
+ };
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 any_fuzz = options.config.any_fuzz or options.root_mod.fuzz;
- const link_eh_frame_hdr = options.link_eh_frame_hdr or any_unwind_tables;
+ const link_eh_frame_hdr = options.link_eh_frame_hdr or any_unwind_tables != .none;
const build_id = options.build_id orelse .none;
const link_libc = options.config.link_libc;
@@ -1354,6 +1357,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
cache.hash.add(options.config.pie);
cache.hash.add(options.config.lto);
cache.hash.add(options.config.link_mode);
+ cache.hash.add(options.config.any_unwind_tables);
cache.hash.add(options.function_sections);
cache.hash.add(options.data_sections);
cache.hash.add(link_libc);
@@ -5538,10 +5542,17 @@ pub fn addCCArgs(
try argv.append("-Werror=date-time");
}
- if (mod.unwind_tables) {
- try argv.append("-funwind-tables");
- } else {
- try argv.append("-fno-unwind-tables");
+ switch (mod.unwind_tables) {
+ .none => {
+ try argv.append("-fno-unwind-tables");
+ try argv.append("-fno-asynchronous-unwind-tables");
+ },
+ .sync => {
+ // Need to override Clang's convoluted default logic.
+ try argv.append("-fno-asynchronous-unwind-tables");
+ try argv.append("-funwind-tables");
+ },
+ .@"async" => try argv.append("-fasynchronous-unwind-tables"),
}
},
.shared_library, .ll, .bc, .unknown, .static_library, .object, .def, .zig, .res, .manifest => {},
@@ -6273,6 +6284,7 @@ pub const CrtFileOptions = struct {
function_sections: ?bool = null,
data_sections: ?bool = null,
omit_frame_pointer: ?bool = null,
+ unwind_tables: ?std.builtin.UnwindTables = null,
pic: ?bool = null,
no_builtin: ?bool = null,
};
@@ -6334,7 +6346,8 @@ pub fn build_crt_file(
// Some libcs (e.g. musl) are opinionated about -fomit-frame-pointer.
.omit_frame_pointer = options.omit_frame_pointer orelse comp.root_mod.omit_frame_pointer,
.valgrind = false,
- .unwind_tables = false,
+ // Some libcs (e.g. MinGW) are opinionated about -funwind-tables.
+ .unwind_tables = options.unwind_tables orelse .none,
// Some CRT objects (e.g. musl's rcrt1.o and Scrt1.o) are opinionated about PIC.
.pic = options.pic orelse comp.root_mod.pic,
.optimize_mode = comp.compilerRtOptMode(),