Fix .cfi_restore with register numbers > 64

Summary:
DW_CFA_restore can only encode register numbers up to 64 (6 bits unsigned
int). For regsiter numbers > 64 we have to use DW_CFA_restore_extended
instead which uses a ULEB128 value.
I discovered this problem in the out-of-tree CHERI target since we use
DWARF register number 89 for our return capability register.

Reviewers: probinson, dblaikie, aprantl, espindola

Reviewed By: dblaikie

Subscribers: JohnReagan, emaste, JDevlieghere, llvm-commits

Differential Revision: https://reviews.llvm.org/D54420

llvm-svn: 346751
This commit is contained in:
Alexander Richardson 2018-11-13 10:54:49 +00:00
parent 4eb93907f7
commit dbfa6e616c
2 changed files with 23 additions and 1 deletions

View File

@ -1418,7 +1418,12 @@ void FrameEmitterImpl::EmitCFIInstruction(const MCCFIInstruction &Instr) {
unsigned Reg = Instr.getRegister();
if (!IsEH)
Reg = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg);
Streamer.EmitIntValue(dwarf::DW_CFA_restore | Reg, 1);
if (Reg < 64) {
Streamer.EmitIntValue(dwarf::DW_CFA_restore | Reg, 1);
} else {
Streamer.EmitIntValue(dwarf::DW_CFA_restore_extended, 1);
Streamer.EmitULEB128IntValue(Reg);
}
return;
}
case MCCFIInstruction::OpGnuArgsSize:

View File

@ -0,0 +1,17 @@
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | llvm-dwarfdump -debug-frame - | FileCheck %s
// Check that register numbers greater than 63 can be used in .cfi_restore directives
f:
.cfi_startproc
nop
// CHECK: DW_CFA_advance_loc: 1
.cfi_restore %rbp
// CHECK-NEXT: DW_CFA_restore: reg6
nop
// CHECK-NEXT: DW_CFA_advance_loc: 1
.cfi_restore 89
// CHECK-NEXT: DW_CFA_restore_extended: reg89
// CHECK-NEXT: DW_CFA_nop:
nop
.cfi_endproc