Skip to content

Commit a4f95b1

Browse files
committed
std.debug.Dwarf.Unwind: deal with invalid def_cfa_reg by GNU toolchains
1 parent 97de46d commit a4f95b1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/std/debug/Dwarf/Unwind/VirtualMachine.zig

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,18 @@ fn evalInstructions(
256256
.offset = cfa.offset_sf * cie.data_alignment_factor,
257257
} },
258258
.def_cfa_reg => |register| switch (vm.current_row.cfa) {
259-
.none, .expression => return error.InvalidOperation,
259+
.none => {
260+
// According to the DWARF specification, this is not valid, because this
261+
// instruction can only be used to replace the register if the rule is already a
262+
// `.reg_off`. However, this is emitted in practice by GNU toolchains for some
263+
// targets, and so by convention is interpreted as equivalent to `.def_cfa` with
264+
// an offset of 0.
265+
vm.current_row.cfa = .{ .reg_off = .{
266+
.register = register,
267+
.offset = 0,
268+
} };
269+
},
270+
.expression => return error.InvalidOperation,
260271
.reg_off => |*ro| ro.register = register,
261272
},
262273
.def_cfa_offset => |offset| switch (vm.current_row.cfa) {

0 commit comments

Comments
 (0)