| author | |
| committer | |
| log | 7e8d4c3065f7f80464ea5ebd916e734d8448c0c4 |
| tree | eb7e0213b86ad4d0ecb57dc299b228c36bb00c16 |
| parent | 02efcc88c15ecd53ba9b6ddd05bf7e5b353c38fe |
| signature |
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( | ... | @@ -7327,8 +7327,6 @@ fn buildOutputFromZig( |
| 7327 | pub const CrtFileOptions = struct { | 7327 | pub const CrtFileOptions = struct { |
| 7328 | function_sections: bool = true, | 7328 | function_sections: bool = true, |
| 7329 | data_sections: bool = true, | 7329 | data_sections: bool = true, |
| 7330 | omit_frame_pointer: ?bool = null, | ||
| 7331 | unwind_tables: ?std.lang.UnwindTables = null, | ||
| 7332 | pic: ?bool = null, | 7330 | pic: ?bool = null, |
| 7333 | no_builtin: ?bool = null, | 7331 | no_builtin: ?bool = null, |
| 7334 | 7332 | ||
| ... | @@ -7375,7 +7373,7 @@ pub fn build_crt_file( | ... | @@ -7375,7 +7373,7 @@ pub fn build_crt_file( |
| 7375 | .root_optimize_mode = comp.compilerRtOptMode(), | 7373 | .root_optimize_mode = comp.compilerRtOptMode(), |
| 7376 | .root_strip = comp.compilerRtStrip(), | 7374 | .root_strip = comp.compilerRtStrip(), |
| 7377 | .link_libc = false, | 7375 | .link_libc = false, |
| 7378 | .any_unwind_tables = options.unwind_tables != .none, | 7376 | .any_unwind_tables = comp.root_mod.unwind_tables != .none, |
| 7379 | .lto = switch (output_mode) { | 7377 | .lto = switch (output_mode) { |
| 7380 | .Lib => if (options.allow_lto) comp.config.lto else .none, | 7378 | .Lib => if (options.allow_lto) comp.config.lto else .none, |
| 7381 | .Obj, .Exe => .none, | 7379 | .Obj, .Exe => .none, |
| ... | @@ -7398,11 +7396,9 @@ pub fn build_crt_file( | ... | @@ -7398,11 +7396,9 @@ pub fn build_crt_file( |
| 7398 | .sanitize_c = .off, | 7396 | .sanitize_c = .off, |
| 7399 | .sanitize_thread = false, | 7397 | .sanitize_thread = false, |
| 7400 | .red_zone = comp.root_mod.red_zone, | 7398 | .red_zone = comp.root_mod.red_zone, |
| 7401 | // Some libcs (e.g. musl) are opinionated about -fomit-frame-pointer. | 7399 | .omit_frame_pointer = comp.root_mod.omit_frame_pointer, |
| 7402 | .omit_frame_pointer = options.omit_frame_pointer orelse comp.root_mod.omit_frame_pointer, | ||
| 7403 | .valgrind = false, | 7400 | .valgrind = false, |
| 7404 | // Some libcs (e.g. MinGW) are opinionated about -funwind-tables. | 7401 | .unwind_tables = comp.root_mod.unwind_tables, |
| 7405 | .unwind_tables = options.unwind_tables orelse .none, | ||
| 7406 | // Some CRT objects (e.g. musl's rcrt1.o and Scrt1.o) are opinionated about PIC. | 7402 | // Some CRT objects (e.g. musl's rcrt1.o and Scrt1.o) are opinionated about PIC. |
| 7407 | .pic = options.pic orelse comp.root_mod.pic, | 7403 | .pic = options.pic orelse comp.root_mod.pic, |
| 7408 | .optimize_mode = comp.compilerRtOptMode(), | 7404 | .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 | ... | @@ -242,7 +242,6 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre |
| 242 | prog_node, | 242 | prog_node, |
| 243 | files, | 243 | files, |
| 244 | .{ | 244 | .{ |
| 245 | .omit_frame_pointer = false, | ||
| 246 | .pic = true, | 245 | .pic = true, |
| 247 | }, | 246 | }, |
| 248 | ); | 247 | ); |
src/libs/libcxx.zig+1-1| ... | @@ -325,7 +325,7 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr | ... | @@ -325,7 +325,7 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr |
| 325 | // See the `-fno-exceptions` logic for WASI. | 325 | // See the `-fno-exceptions` logic for WASI. |
| 326 | // The old 32-bit x86 variant of SEH doesn't use tables. | 326 | // The old 32-bit x86 variant of SEH doesn't use tables. |
| 327 | const unwind_tables: std.lang.UnwindTables = | 327 | 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; |
| 329 | 329 | ||
| 330 | const config = Compilation.Config.resolve(.{ | 330 | const config = Compilation.Config.resolve(.{ |
| 331 | .output_mode = output_mode, | 331 | .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 | ... | @@ -96,7 +96,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo |
| 96 | .sanitize_c = .off, | 96 | .sanitize_c = .off, |
| 97 | .sanitize_thread = false, | 97 | .sanitize_thread = false, |
| 98 | .red_zone = comp.root_mod.red_zone, | 98 | .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, |
| 100 | .valgrind = false, | 100 | .valgrind = false, |
| 101 | .unwind_tables = unwind_tables, | 101 | .unwind_tables = unwind_tables, |
| 102 | .optimize_mode = optimize_mode, | 102 | .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 | ... | @@ -39,9 +39,6 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre |
| 39 | const arena = arena_allocator.allocator(); | 39 | const arena = arena_allocator.allocator(); |
| 40 | const target = comp.getTarget(); | 40 | const target = comp.getTarget(); |
| 41 | 41 | ||
| 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 | |||
| 45 | switch (crt_file) { | 42 | switch (crt_file) { |
| 46 | .crt2_o => { | 43 | .crt2_o => { |
| 47 | var args = std.array_list.Managed([]const u8).init(arena); | 44 | 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 | ... | @@ -60,7 +57,6 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre |
| 60 | }; | 57 | }; |
| 61 | return comp.build_crt_file("crt2", .Obj, .@"mingw-w64 crt2.o", prog_node, &files, .{ | 58 | return comp.build_crt_file("crt2", .Obj, .@"mingw-w64 crt2.o", prog_node, &files, .{ |
| 62 | .function_sections = false, // https://codeberg.org/ziglang/zig/issues/30702 | 59 | .function_sections = false, // https://codeberg.org/ziglang/zig/issues/30702 |
| 63 | .unwind_tables = unwind_tables, | ||
| 64 | }); | 60 | }); |
| 65 | }, | 61 | }, |
| 66 | 62 | ||
| ... | @@ -76,9 +72,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre | ... | @@ -76,9 +72,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre |
| 76 | .owner = undefined, | 72 | .owner = undefined, |
| 77 | }, | 73 | }, |
| 78 | }; | 74 | }; |
| 79 | return comp.build_crt_file("dllcrt2", .Obj, .@"mingw-w64 dllcrt2.o", prog_node, &files, .{ | 75 | return comp.build_crt_file("dllcrt2", .Obj, .@"mingw-w64 dllcrt2.o", prog_node, &files, .{}); |
| 80 | .unwind_tables = unwind_tables, | ||
| 81 | }); | ||
| 82 | }, | 76 | }, |
| 83 | 77 | ||
| 84 | .libmingw32_lib => { | 78 | .libmingw32_lib => { |
| ... | @@ -157,7 +151,6 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre | ... | @@ -157,7 +151,6 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre |
| 157 | } | 151 | } |
| 158 | 152 | ||
| 159 | return comp.build_crt_file("libmingw32", .Lib, .@"mingw-w64 libmingw32.lib", prog_node, c_source_files.items, .{ | 153 | return comp.build_crt_file("libmingw32", .Lib, .@"mingw-w64 libmingw32.lib", prog_node, c_source_files.items, .{ |
| 160 | .unwind_tables = unwind_tables, | ||
| 161 | // https://github.com/llvm/llvm-project/issues/43698#issuecomment-2542660611 | 154 | // https://github.com/llvm/llvm-project/issues/43698#issuecomment-2542660611 |
| 162 | .allow_lto = false, | 155 | .allow_lto = false, |
| 163 | }); | 156 | }); |
src/libs/musl.zig-4| ... | @@ -43,7 +43,6 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro | ... | @@ -43,7 +43,6 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro |
| 43 | }, | 43 | }, |
| 44 | }; | 44 | }; |
| 45 | return comp.build_crt_file("crt1", .Obj, .@"musl crt1.o", prog_node, &files, .{ | 45 | return comp.build_crt_file("crt1", .Obj, .@"musl crt1.o", prog_node, &files, .{ |
| 46 | .omit_frame_pointer = true, | ||
| 47 | .no_builtin = true, | 46 | .no_builtin = true, |
| 48 | }); | 47 | }); |
| 49 | }, | 48 | }, |
| ... | @@ -61,7 +60,6 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro | ... | @@ -61,7 +60,6 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro |
| 61 | }, | 60 | }, |
| 62 | }; | 61 | }; |
| 63 | return comp.build_crt_file("rcrt1", .Obj, .@"musl rcrt1.o", prog_node, &files, .{ | 62 | return comp.build_crt_file("rcrt1", .Obj, .@"musl rcrt1.o", prog_node, &files, .{ |
| 64 | .omit_frame_pointer = true, | ||
| 65 | .pic = true, | 63 | .pic = true, |
| 66 | .no_builtin = true, | 64 | .no_builtin = true, |
| 67 | }); | 65 | }); |
| ... | @@ -80,7 +78,6 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro | ... | @@ -80,7 +78,6 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro |
| 80 | }, | 78 | }, |
| 81 | }; | 79 | }; |
| 82 | return comp.build_crt_file("Scrt1", .Obj, .@"musl Scrt1.o", prog_node, &files, .{ | 80 | return comp.build_crt_file("Scrt1", .Obj, .@"musl Scrt1.o", prog_node, &files, .{ |
| 83 | .omit_frame_pointer = true, | ||
| 84 | .pic = true, | 81 | .pic = true, |
| 85 | .no_builtin = true, | 82 | .no_builtin = true, |
| 86 | }); | 83 | }); |
| ... | @@ -166,7 +163,6 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro | ... | @@ -166,7 +163,6 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro |
| 166 | }; | 163 | }; |
| 167 | } | 164 | } |
| 168 | return comp.build_crt_file("c", .Lib, .@"musl libc.a", prog_node, c_source_files.items, .{ | 165 | return comp.build_crt_file("c", .Lib, .@"musl libc.a", prog_node, c_source_files.items, .{ |
| 169 | .omit_frame_pointer = true, | ||
| 170 | .no_builtin = true, | 166 | .no_builtin = true, |
| 171 | }); | 167 | }); |
| 172 | }, | 168 | }, |
src/libs/openbsd.zig-2| ... | @@ -125,8 +125,6 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre | ... | @@ -125,8 +125,6 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre |
| 125 | const files = files_buf[0..files_index]; | 125 | const files = files_buf[0..files_index]; |
| 126 | 126 | ||
| 127 | return comp.build_crt_file("crt0", .Obj, .@"openbsd libc Scrt0.o", prog_node, files, .{ | 127 | 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, | ||
| 130 | .pic = true, | 128 | .pic = true, |
| 131 | }); | 129 | }); |
| 132 | }, | 130 | }, |