authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-07-06 12:32:14+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-07-06 12:32:14+02:00
logc5af4c75da81616eadce8cf866aac86fb9e4ba9d
tree222c7084e002e449b36412da3f28f8c1f1077da6
parentc0f9b51d846e71f46f37ffa010152c7776d77991
parentf0fdc9098919ff65daea48b5b54154406b88d107

Merge pull request '`std.debug.SelfInfo.Elf`: enable DWARF unwinding for ARM' (#36035) from alexrp/zig:arm-dwarf-unwind into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/36035 Reviewed-by: mlugg <mlugg@noreply.codeberg.org>

11 files changed, 35 insertions(+), 47 deletions(-)

lib/libc/musl/arch/powerpc/syscall_arch.h+7-7
......@@ -9,7 +9,7 @@ static inline long __syscall0(long n)
99 register long r3 __asm__("r3");
1010 __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
1111 : "+r"(r0), "=r"(r3)
12 :: "memory", "cr0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12");
12 :: "memory", "cr0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "ctr", "xer");
1313 return r3;
1414}
1515
......@@ -19,7 +19,7 @@ static inline long __syscall1(long n, long a)
1919 register long r3 __asm__("r3") = a;
2020 __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
2121 : "+r"(r0), "+r"(r3)
22 :: "memory", "cr0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12");
22 :: "memory", "cr0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "ctr", "xer");
2323 return r3;
2424}
2525
......@@ -30,7 +30,7 @@ static inline long __syscall2(long n, long a, long b)
3030 register long r4 __asm__("r4") = b;
3131 __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
3232 : "+r"(r0), "+r"(r3), "+r"(r4)
33 :: "memory", "cr0", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12");
33 :: "memory", "cr0", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "ctr", "xer");
3434 return r3;
3535}
3636
......@@ -42,7 +42,7 @@ static inline long __syscall3(long n, long a, long b, long c)
4242 register long r5 __asm__("r5") = c;
4343 __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
4444 : "+r"(r0), "+r"(r3), "+r"(r4), "+r"(r5)
45 :: "memory", "cr0", "r6", "r7", "r8", "r9", "r10", "r11", "r12");
45 :: "memory", "cr0", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "ctr", "xer");
4646 return r3;
4747}
4848
......@@ -55,7 +55,7 @@ static inline long __syscall4(long n, long a, long b, long c, long d)
5555 register long r6 __asm__("r6") = d;
5656 __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
5757 : "+r"(r0), "+r"(r3), "+r"(r4), "+r"(r5), "+r"(r6)
58 :: "memory", "cr0", "r7", "r8", "r9", "r10", "r11", "r12");
58 :: "memory", "cr0", "r7", "r8", "r9", "r10", "r11", "r12", "ctr", "xer");
5959 return r3;
6060}
6161
......@@ -69,7 +69,7 @@ static inline long __syscall5(long n, long a, long b, long c, long d, long e)
6969 register long r7 __asm__("r7") = e;
7070 __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
7171 : "+r"(r0), "+r"(r3), "+r"(r4), "+r"(r5), "+r"(r6), "+r"(r7)
72 :: "memory", "cr0", "r8", "r9", "r10", "r11", "r12");
72 :: "memory", "cr0", "r8", "r9", "r10", "r11", "r12", "ctr", "xer");
7373 return r3;
7474}
7575
......@@ -84,7 +84,7 @@ static inline long __syscall6(long n, long a, long b, long c, long d, long e, lo
8484 register long r8 __asm__("r8") = f;
8585 __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
8686 : "+r"(r0), "+r"(r3), "+r"(r4), "+r"(r5), "+r"(r6), "+r"(r7), "+r"(r8)
87 :: "memory", "cr0", "r9", "r10", "r11", "r12");
87 :: "memory", "cr0", "r9", "r10", "r11", "r12", "ctr", "xer");
8888 return r3;
8989}
9090
lib/libc/musl/arch/powerpc64/syscall_arch.h+7-7
......@@ -7,7 +7,7 @@ static inline long __syscall0(long n)
77 register long r3 __asm__("r3");
88 __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
99 : "+r"(r0), "=r"(r3)
10 :: "memory", "cr0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12");
10 :: "memory", "cr0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "ctr", "xer");
1111 return r3;
1212}
1313
......@@ -17,7 +17,7 @@ static inline long __syscall1(long n, long a)
1717 register long r3 __asm__("r3") = a;
1818 __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
1919 : "+r"(r0), "+r"(r3)
20 :: "memory", "cr0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12");
20 :: "memory", "cr0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "ctr", "xer");
2121 return r3;
2222}
2323
......@@ -28,7 +28,7 @@ static inline long __syscall2(long n, long a, long b)
2828 register long r4 __asm__("r4") = b;
2929 __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
3030 : "+r"(r0), "+r"(r3), "+r"(r4)
31 :: "memory", "cr0", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12");
31 :: "memory", "cr0", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "ctr", "xer");
3232 return r3;
3333}
3434
......@@ -40,7 +40,7 @@ static inline long __syscall3(long n, long a, long b, long c)
4040 register long r5 __asm__("r5") = c;
4141 __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
4242 : "+r"(r0), "+r"(r3), "+r"(r4), "+r"(r5)
43 :: "memory", "cr0", "r6", "r7", "r8", "r9", "r10", "r11", "r12");
43 :: "memory", "cr0", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "ctr", "xer");
4444 return r3;
4545}
4646
......@@ -53,7 +53,7 @@ static inline long __syscall4(long n, long a, long b, long c, long d)
5353 register long r6 __asm__("r6") = d;
5454 __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
5555 : "+r"(r0), "+r"(r3), "+r"(r4), "+r"(r5), "+r"(r6)
56 :: "memory", "cr0", "r7", "r8", "r9", "r10", "r11", "r12");
56 :: "memory", "cr0", "r7", "r8", "r9", "r10", "r11", "r12", "ctr", "xer");
5757 return r3;
5858}
5959
......@@ -67,7 +67,7 @@ static inline long __syscall5(long n, long a, long b, long c, long d, long e)
6767 register long r7 __asm__("r7") = e;
6868 __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
6969 : "+r"(r0), "+r"(r3), "+r"(r4), "+r"(r5), "+r"(r6), "+r"(r7)
70 :: "memory", "cr0", "r8", "r9", "r10", "r11", "r12");
70 :: "memory", "cr0", "r8", "r9", "r10", "r11", "r12", "ctr", "xer");
7171 return r3;
7272}
7373
......@@ -82,7 +82,7 @@ static inline long __syscall6(long n, long a, long b, long c, long d, long e, lo
8282 register long r8 __asm__("r8") = f;
8383 __asm__ __volatile__("sc ; bns+ 1f ; neg %1, %1 ; 1:"
8484 : "+r"(r0), "+r"(r3), "+r"(r4), "+r"(r5), "+r"(r6), "+r"(r7), "+r"(r8)
85 :: "memory", "cr0", "r9", "r10", "r11", "r12");
85 :: "memory", "cr0", "r9", "r10", "r11", "r12", "ctr", "xer");
8686 return r3;
8787}
8888
lib/std/debug/SelfInfo/Elf.zig+12-7
......@@ -92,12 +92,10 @@ pub fn getModuleSlide(si: *SelfInfo, io: Io, address: usize) Error!usize {
9292}
9393
9494pub const can_unwind: bool = s: {
95 // Notably, we are yet to support unwinding on ARM. There, unwinding is not done through
96 // `.eh_frame`, but instead with the `.ARM.exidx` section, which has a different format.
9795 const archs: []const std.Target.Cpu.Arch = switch (builtin.target.os.tag) {
98 // Not supported yet: arm
9996 .haiku => &.{
10097 .aarch64,
98 .arm,
10199 .riscv64,
102100 .x86,
103101 .x86_64,
......@@ -106,12 +104,14 @@ pub const can_unwind: bool = s: {
106104 .x86,
107105 .x86_64,
108106 },
109 // Not supported yet: arm/armeb/thumb/thumbeb, hppa, hppa64, microblaze/microblazeel
107 // Not supported yet: hppa, hppa64, microblaze/microblazeel, sh/sheb
110108 .linux => &.{
111109 .aarch64,
112110 .aarch64_be,
113111 .alpha,
114112 .arc,
113 .arm,
114 .armeb,
115115 .csky,
116116 .loongarch32,
117117 .loongarch64,
......@@ -124,6 +124,8 @@ pub const can_unwind: bool = s: {
124124 .riscv32,
125125 .riscv64,
126126 .s390x,
127 .thumb,
128 .thumbeb,
127129 .x86,
128130 .x86_64,
129131 },
......@@ -136,18 +138,20 @@ pub const can_unwind: bool = s: {
136138 .dragonfly => &.{
137139 .x86_64,
138140 },
139 // Not supported yet: arm
140141 .freebsd => &.{
141142 .aarch64,
143 .arm,
142144 .riscv64,
143145 .x86,
144146 .x86_64,
145147 },
146 // Not supported yet: arm/armeb, hppa, mips64/mips64el, sh/sheb
148 // Not supported yet: hppa, mips64/mips64el, sh/sheb
147149 .netbsd => &.{
148150 .aarch64,
149151 .aarch64_be,
150152 .alpha,
153 .arm,
154 .armeb,
151155 .m68k,
152156 .mips,
153157 .mipsel,
......@@ -156,9 +160,10 @@ pub const can_unwind: bool = s: {
156160 .x86,
157161 .x86_64,
158162 },
159 // Not supported yet: arm, hppa, sh
163 // Not supported yet: hppa, sh
160164 .openbsd => &.{
161165 .aarch64,
166 .arm,
162167 .m88k,
163168 .mips64,
164169 .mips64el,
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 },
test/src/StackTrace.zig+3-2
......@@ -72,6 +72,8 @@ fn addCaseTarget(
7272 .mips64el,
7373 .sh,
7474 .sheb,
75 .xtensa,
76 .xtensaeb,
7577 => .useless,
7678 .hexagon,
7779 .powerpc,
......@@ -87,8 +89,7 @@ fn addCaseTarget(
8789 const supports_unwind_tables = switch (target.result.os.tag) {
8890 // x86-windows just has no way to do stack unwinding other then using frame pointers.
8991 .windows => target.result.cpu.arch != .x86,
90 // We do not yet implement support for the AArch32 exception table section `.ARM.exidx`.
91 else => !target.result.cpu.arch.isArm(),
92 else => true,
9293 };
9394
9495 const use_llvm_vals: []const bool = if (both_backends) &.{ true, false } else &.{true};