Skip to content

Commit

Permalink
[AArch64] fix bug #55005 handle DW_CFA_GNU_NegateRAState
Browse files Browse the repository at this point in the history
GCC on AArch64 uses DW_CFA_GNU_NegateRAState for return address signing.

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

(cherry picked from commit 9921197)
  • Loading branch information
sebpop authored and tru committed Mar 23, 2023
1 parent aef3508 commit bb6a97c
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 6 deletions.
19 changes: 13 additions & 6 deletions bolt/lib/Core/Exceptions.cpp
Expand Up @@ -626,18 +626,25 @@ bool CFIReaderWriter::fillCFIInfoFor(BinaryFunction &Function) const {
errs() << "BOLT-WARNING: DW_CFA_MIPS_advance_loc unimplemented\n";
return false;
case DW_CFA_GNU_window_save:
// DW_CFA_GNU_window_save and DW_CFA_GNU_NegateRAState just use the same
// id but mean different things. The latter is used in AArch64.
if (Function.getBinaryContext().isAArch64()) {
Function.addCFIInstruction(
Offset, MCCFIInstruction::createNegateRAState(nullptr));
break;
}
if (opts::Verbosity >= 1)
errs() << "BOLT-WARNING: DW_CFA_GNU_window_save unimplemented\n";
return false;
case DW_CFA_lo_user:
case DW_CFA_hi_user:
if (opts::Verbosity >= 1) {
errs() << "BOLT-WARNING: DW_CFA_GNU_* and DW_CFA_*_user "
"unimplemented\n";
}
if (opts::Verbosity >= 1)
errs() << "BOLT-WARNING: DW_CFA_*_user unimplemented\n";
return false;
default:
if (opts::Verbosity >= 1) {
if (opts::Verbosity >= 1)
errs() << "BOLT-WARNING: Unrecognized CFI instruction: " << Instr.Opcode
<< '\n';
}
return false;
}

Expand Down
62 changes: 62 additions & 0 deletions bolt/test/AArch64/Inputs/dw_cfa_gnu_window_save.yaml
@@ -0,0 +1,62 @@
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_AARCH64
Entry: 0x4100C0
ProgramHeaders:
- Type: PT_LOAD
Flags: [ PF_X, PF_R ]
FirstSec: .init
LastSec: .fini
VAddr: 0x410000
Align: 0x10000
Sections:
- Name: .init
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
Address: 0x410000
AddressAlign: 0x4
Offset: 0x10000
Content: 3F2303D5FD7BBFA9FD0300913F000094FD7BC1A8BF2303D5C0035FD6
- Name: .plt
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
Address: 0x410020
AddressAlign: 0x10
Content: F07BBFA9700100F011FE47F910E23F9120021FD61F2003D51F2003D51F2003D590010090110240F91002009120021FD690010090110640F91022009120021FD690010090110A40F91042009120021FD6
- Name: .text
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
Address: 0x410080
AddressAlign: 0x40
Content: 00008052C0035FD61F2003D51F2003D51F2003D51F2003D51F2003D51F2003D51F2003D51F2003D51F2003D51F2003D51F2003D51F2003D51F2003D51F2003D55F2403D51D0080D21E0080D2E50300AAE10340F9E2230091E60300910000009000D00391030080D2040080D2D5FFFF97D8FFFF975F2403D5E2FFFF171F2003D55F2403D5C0035FD6600100F000F047F9400000B4D3FFFF17C0035FD61F2003D5800100908101009000800091218000913F0000EBC000005481000090210840F9610000B4F00301AA00021FD6C0035FD680010090810100900080009121800091210000CB22FC7FD3410C818B21FC4193C10000B482000090420C40F9620000B4F00302AA00021FD6C0035FD63F2303D5FD7BBEA9FD030091F30B00F9930100906082403980000035DEFFFF972000805260820039F30B40F9FD7BC2A8BF2303D5C0035FD65F2403D5E2FFFF17
- Name: .fini
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
Address: 0x4101CC
AddressAlign: 0x4
Content: 3F2303D5FD7BBFA9FD030091FD7BC1A8BF2303D5C0035FD6
- Name: .eh_frame
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC ]
Address: 0x420068
AddressAlign: 0x8
Content: 1000000000000000017A520004781E011B0C1F0010000000180000003C00FFFF3C0000000041071E140000002C0000006800FFFF08000000000000000000000010000000440000007000FFFF300000000000000010000000580000008C00FFFF3C00000000000000240000006C000000B400FFFF3800000000412D410E209D049E0342930248DEDDD30E00412D0000001400000094000000C400FFFF08000000000000000000000010000000AC00000068FFFEFF080000000000000000000000
- Name: .rela.text
Type: SHT_RELA
Flags: [ SHF_INFO_LINK ]
Link: .symtab
AddressAlign: 0x8
Info: .text
Symbols:
- Name: .text
Type: STT_SECTION
Section: .text
Value: 0x410080
- Name: _ITM_deregisterTMCloneTable
Binding: STB_WEAK
- Name: _ITM_registerTMCloneTable
Binding: STB_WEAK
...
8 changes: 8 additions & 0 deletions bolt/test/AArch64/dw_cfa_gnu_window_save.test
@@ -0,0 +1,8 @@
# Check that llvm-bolt can handle DW_CFA_GNU_window_save on AArch64.

RUN: yaml2obj %p/Inputs/dw_cfa_gnu_window_save.yaml &> %t.exe
RUN: llvm-bolt %t.exe -o %t.bolt 2>&1 | FileCheck %s

CHECK-NOT: paciasp
CHECK-NOT: autiasp
CHECK-NOT: ERROR: unable to fill CFI.

0 comments on commit bb6a97c

Please sign in to comment.