authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-07-05 02:05:39+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-07-05 10:39:03+02:00
log7e8d4c3065f7f80464ea5ebd916e734d8448c0c4
treeeb7e0213b86ad4d0ecb57dc299b228c36bb00c16
parent02efcc88c15ecd53ba9b6ddd05bf7e5b353c38fe
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

compiler: inherit uwtables/fp settings for vendored libs from root module

We previously tried to just match whatever upstream did. But since we control compilation of these libraries, we may as well provide a better debugging experience where we can. * Frame pointer omission is now always inherited from the root module in all vendored libraries. * The unwind tables level is now inherited from the root module in vendored libc and crt0 components. Some libraries (libunwind, libcxxabi, libtsan) still enable unwind tables independently of the root module because they need the tables for correctness. This happens to fix std.debug's ability to DWARF unwind through musl startup code on 32-bit ARM; previously, it would get stuck trying to unwind through libc_start_main_stage2() because it had incomplete CFI.

7 files changed, 6 insertions(+), 24 deletions(-)

src/Compilation.zig+3-7
......@@ -7327,8 +7327,6 @@ fn buildOutputFromZig(
73277327pub const CrtFileOptions = struct {
73287328 function_sections: bool = true,
73297329 data_sections: bool = true,
7330 omit_frame_pointer: ?bool = null,
7331 unwind_tables: ?std.lang.UnwindTables = null,
73327330 pic: ?bool = null,
73337331 no_builtin: ?bool = null,
73347332
......@@ -7375,7 +7373,7 @@ pub fn build_crt_file(
73757373 .root_optimize_mode = comp.compilerRtOptMode(),
73767374 .root_strip = comp.compilerRtStrip(),
73777375 .link_libc = false,
7378 .any_unwind_tables = options.unwind_tables != .none,
7376 .any_unwind_tables = comp.root_mod.unwind_tables != .none,
73797377 .lto = switch (output_mode) {
73807378 .Lib => if (options.allow_lto) comp.config.lto else .none,
73817379 .Obj, .Exe => .none,
......@@ -7398,11 +7396,9 @@ pub fn build_crt_file(
73987396 .sanitize_c = .off,
73997397 .sanitize_thread = false,
74007398 .red_zone = comp.root_mod.red_zone,
7401 // Some libcs (e.g. musl) are opinionated about -fomit-frame-pointer.
7402 .omit_frame_pointer = options.omit_frame_pointer orelse comp.root_mod.omit_frame_pointer,
7399 .omit_frame_pointer = comp.root_mod.omit_frame_pointer,
74037400 .valgrind = false,
7404 // Some libcs (e.g. MinGW) are opinionated about -funwind-tables.
7405 .unwind_tables = options.unwind_tables orelse .none,
7401 .unwind_tables = comp.root_mod.unwind_tables,
74067402 // Some CRT objects (e.g. musl's rcrt1.o and Scrt1.o) are opinionated about PIC.
74077403 .pic = options.pic orelse comp.root_mod.pic,
74087404 .optimize_mode = comp.compilerRtOptMode(),
src/libs/freebsd.zig-1
......@@ -242,7 +242,6 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
242242 prog_node,
243243 files,
244244 .{
245 .omit_frame_pointer = false,
246245 .pic = true,
247246 },
248247 );
src/libs/libcxx.zig+1-1
......@@ -325,7 +325,7 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
325325 // See the `-fno-exceptions` logic for WASI.
326326 // The old 32-bit x86 variant of SEH doesn't use tables.
327327 const unwind_tables: std.lang.UnwindTables =
328 if (target.os.tag == .wasi or (target.cpu.arch == .x86 and target.os.tag == .windows)) .none else .async;
328 if (target.cpu.arch == .x86 and target.os.tag == .windows) .none else .async;
329329
330330 const config = Compilation.Config.resolve(.{
331331 .output_mode = output_mode,
src/libs/libtsan.zig+1-1
......@@ -96,7 +96,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
9696 .sanitize_c = .off,
9797 .sanitize_thread = false,
9898 .red_zone = comp.root_mod.red_zone,
99 .omit_frame_pointer = optimize_mode != .Debug and !target.os.tag.isDarwin(),
99 .omit_frame_pointer = comp.root_mod.omit_frame_pointer,
100100 .valgrind = false,
101101 .unwind_tables = unwind_tables,
102102 .optimize_mode = optimize_mode,
src/libs/mingw.zig+1-8
......@@ -39,9 +39,6 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
3939 const arena = arena_allocator.allocator();
4040 const target = comp.getTarget();
4141
42 // The old 32-bit x86 variant of SEH doesn't use tables.
43 const unwind_tables: std.lang.UnwindTables = if (target.cpu.arch != .x86) .async else .none;
44
4542 switch (crt_file) {
4643 .crt2_o => {
4744 var args = std.array_list.Managed([]const u8).init(arena);
......@@ -60,7 +57,6 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
6057 };
6158 return comp.build_crt_file("crt2", .Obj, .@"mingw-w64 crt2.o", prog_node, &files, .{
6259 .function_sections = false, // https://codeberg.org/ziglang/zig/issues/30702
63 .unwind_tables = unwind_tables,
6460 });
6561 },
6662
......@@ -76,9 +72,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
7672 .owner = undefined,
7773 },
7874 };
79 return comp.build_crt_file("dllcrt2", .Obj, .@"mingw-w64 dllcrt2.o", prog_node, &files, .{
80 .unwind_tables = unwind_tables,
81 });
75 return comp.build_crt_file("dllcrt2", .Obj, .@"mingw-w64 dllcrt2.o", prog_node, &files, .{});
8276 },
8377
8478 .libmingw32_lib => {
......@@ -157,7 +151,6 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
157151 }
158152
159153 return comp.build_crt_file("libmingw32", .Lib, .@"mingw-w64 libmingw32.lib", prog_node, c_source_files.items, .{
160 .unwind_tables = unwind_tables,
161154 // https://github.com/llvm/llvm-project/issues/43698#issuecomment-2542660611
162155 .allow_lto = false,
163156 });
src/libs/musl.zig-4
......@@ -43,7 +43,6 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
4343 },
4444 };
4545 return comp.build_crt_file("crt1", .Obj, .@"musl crt1.o", prog_node, &files, .{
46 .omit_frame_pointer = true,
4746 .no_builtin = true,
4847 });
4948 },
......@@ -61,7 +60,6 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
6160 },
6261 };
6362 return comp.build_crt_file("rcrt1", .Obj, .@"musl rcrt1.o", prog_node, &files, .{
64 .omit_frame_pointer = true,
6563 .pic = true,
6664 .no_builtin = true,
6765 });
......@@ -80,7 +78,6 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
8078 },
8179 };
8280 return comp.build_crt_file("Scrt1", .Obj, .@"musl Scrt1.o", prog_node, &files, .{
83 .omit_frame_pointer = true,
8481 .pic = true,
8582 .no_builtin = true,
8683 });
......@@ -166,7 +163,6 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
166163 };
167164 }
168165 return comp.build_crt_file("c", .Lib, .@"musl libc.a", prog_node, c_source_files.items, .{
169 .omit_frame_pointer = true,
170166 .no_builtin = true,
171167 });
172168 },
src/libs/openbsd.zig-2
......@@ -125,8 +125,6 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
125125 const files = files_buf[0..files_index];
126126
127127 return comp.build_crt_file("crt0", .Obj, .@"openbsd libc Scrt0.o", prog_node, files, .{
128 // Unclear why OpenBSD does this, but we'll do the same.
129 .omit_frame_pointer = if (target.cpu.arch.isX86()) false else null,
130128 .pic = true,
131129 });
132130 },