Skip to content

Commit 2fca51d

Browse files
author
Jim Grosbach
committed
X86: Assembly files with .cfi_cfa_def shouldn't hit llvm_unreachable()
On darwin, when trying to create compact unwind info, a .cfi_cfa_def directive would case an llvm_unreachable() to be hit. Back off when we see this directive and generate the regular DWARF style eh_frame. rdar://15406518 llvm-svn: 194285
1 parent 8a06570 commit 2fca51d

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,9 @@ class DarwinX86AsmBackend : public X86AsmBackend {
450450

451451
switch (Inst.getOperation()) {
452452
default:
453-
llvm_unreachable("cannot handle CFI directive for compact unwind!");
453+
// Any other CFI directives indicate a frame that we aren't prepared
454+
// to represent via compact unwind, so just bail out.
455+
return 0;
454456
case MCCFIInstruction::OpDefCfaRegister: {
455457
// Defines a frame pointer. E.g.
456458
//

llvm/test/MC/X86/cfi_def_cfa-crash.s

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// RUN: llvm-mc -triple x86_64-apple-darwin -filetype=obj %s -o - | macho-dump | FileCheck %s
2+
3+
// We were trying to generate compact unwind info for assembly like this.
4+
// The .cfi_def_cfa directive, however, throws a wrench into that and was
5+
// causing an llvm_unreachable() failure. Make sure the assembler can handle
6+
// the input. The actual eh_frames created using these directives are checked
7+
// elsewhere. This test is a simpler "does the code assemble" check.
8+
9+
// rdar://15406518
10+
11+
.macro SaveRegisters
12+
13+
push %rbp
14+
.cfi_def_cfa_offset 16
15+
.cfi_offset rbp, -16
16+
17+
mov %rsp, %rbp
18+
.cfi_def_cfa_register rbp
19+
20+
sub $$0x80+8, %rsp
21+
22+
movdqa %xmm0, -0x80(%rbp)
23+
push %rax
24+
movdqa %xmm1, -0x70(%rbp)
25+
push %rdi
26+
movdqa %xmm2, -0x60(%rbp)
27+
push %rsi
28+
movdqa %xmm3, -0x50(%rbp)
29+
push %rdx
30+
movdqa %xmm4, -0x40(%rbp)
31+
push %rcx
32+
movdqa %xmm5, -0x30(%rbp)
33+
push %r8
34+
movdqa %xmm6, -0x20(%rbp)
35+
push %r9
36+
movdqa %xmm7, -0x10(%rbp)
37+
38+
.endmacro
39+
.macro RestoreRegisters
40+
41+
movdqa -0x80(%rbp), %xmm0
42+
pop %r9
43+
movdqa -0x70(%rbp), %xmm1
44+
pop %r8
45+
movdqa -0x60(%rbp), %xmm2
46+
pop %rcx
47+
movdqa -0x50(%rbp), %xmm3
48+
pop %rdx
49+
movdqa -0x40(%rbp), %xmm4
50+
pop %rsi
51+
movdqa -0x30(%rbp), %xmm5
52+
pop %rdi
53+
movdqa -0x20(%rbp), %xmm6
54+
pop %rax
55+
movdqa -0x10(%rbp), %xmm7
56+
57+
leave
58+
.cfi_def_cfa rsp, 8
59+
.cfi_same_value rbp
60+
61+
.endmacro
62+
63+
_foo:
64+
.cfi_startproc
65+
SaveRegisters
66+
67+
RestoreRegisters
68+
ret
69+
.cfi_endproc
70+
71+
72+
73+
// CHECK: 'section_name', '__eh_frame\x00

0 commit comments

Comments
 (0)