Skip to content

Commit bb6a97c

Browse files
Sebastian Poptru
authored andcommitted
[AArch64] fix bug #55005 handle DW_CFA_GNU_NegateRAState
GCC on AArch64 uses DW_CFA_GNU_NegateRAState for return address signing. Differential Revision: https://reviews.llvm.org/D142572 (cherry picked from commit 9921197)
1 parent aef3508 commit bb6a97c

File tree

3 files changed

+83
-6
lines changed

3 files changed

+83
-6
lines changed

bolt/lib/Core/Exceptions.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -626,18 +626,25 @@ bool CFIReaderWriter::fillCFIInfoFor(BinaryFunction &Function) const {
626626
errs() << "BOLT-WARNING: DW_CFA_MIPS_advance_loc unimplemented\n";
627627
return false;
628628
case DW_CFA_GNU_window_save:
629+
// DW_CFA_GNU_window_save and DW_CFA_GNU_NegateRAState just use the same
630+
// id but mean different things. The latter is used in AArch64.
631+
if (Function.getBinaryContext().isAArch64()) {
632+
Function.addCFIInstruction(
633+
Offset, MCCFIInstruction::createNegateRAState(nullptr));
634+
break;
635+
}
636+
if (opts::Verbosity >= 1)
637+
errs() << "BOLT-WARNING: DW_CFA_GNU_window_save unimplemented\n";
638+
return false;
629639
case DW_CFA_lo_user:
630640
case DW_CFA_hi_user:
631-
if (opts::Verbosity >= 1) {
632-
errs() << "BOLT-WARNING: DW_CFA_GNU_* and DW_CFA_*_user "
633-
"unimplemented\n";
634-
}
641+
if (opts::Verbosity >= 1)
642+
errs() << "BOLT-WARNING: DW_CFA_*_user unimplemented\n";
635643
return false;
636644
default:
637-
if (opts::Verbosity >= 1) {
645+
if (opts::Verbosity >= 1)
638646
errs() << "BOLT-WARNING: Unrecognized CFI instruction: " << Instr.Opcode
639647
<< '\n';
640-
}
641648
return false;
642649
}
643650

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
--- !ELF
2+
FileHeader:
3+
Class: ELFCLASS64
4+
Data: ELFDATA2LSB
5+
Type: ET_EXEC
6+
Machine: EM_AARCH64
7+
Entry: 0x4100C0
8+
ProgramHeaders:
9+
- Type: PT_LOAD
10+
Flags: [ PF_X, PF_R ]
11+
FirstSec: .init
12+
LastSec: .fini
13+
VAddr: 0x410000
14+
Align: 0x10000
15+
Sections:
16+
- Name: .init
17+
Type: SHT_PROGBITS
18+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
19+
Address: 0x410000
20+
AddressAlign: 0x4
21+
Offset: 0x10000
22+
Content: 3F2303D5FD7BBFA9FD0300913F000094FD7BC1A8BF2303D5C0035FD6
23+
- Name: .plt
24+
Type: SHT_PROGBITS
25+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
26+
Address: 0x410020
27+
AddressAlign: 0x10
28+
Content: F07BBFA9700100F011FE47F910E23F9120021FD61F2003D51F2003D51F2003D590010090110240F91002009120021FD690010090110640F91022009120021FD690010090110A40F91042009120021FD6
29+
- Name: .text
30+
Type: SHT_PROGBITS
31+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
32+
Address: 0x410080
33+
AddressAlign: 0x40
34+
Content: 00008052C0035FD61F2003D51F2003D51F2003D51F2003D51F2003D51F2003D51F2003D51F2003D51F2003D51F2003D51F2003D51F2003D51F2003D51F2003D55F2403D51D0080D21E0080D2E50300AAE10340F9E2230091E60300910000009000D00391030080D2040080D2D5FFFF97D8FFFF975F2403D5E2FFFF171F2003D55F2403D5C0035FD6600100F000F047F9400000B4D3FFFF17C0035FD61F2003D5800100908101009000800091218000913F0000EBC000005481000090210840F9610000B4F00301AA00021FD6C0035FD680010090810100900080009121800091210000CB22FC7FD3410C818B21FC4193C10000B482000090420C40F9620000B4F00302AA00021FD6C0035FD63F2303D5FD7BBEA9FD030091F30B00F9930100906082403980000035DEFFFF972000805260820039F30B40F9FD7BC2A8BF2303D5C0035FD65F2403D5E2FFFF17
35+
- Name: .fini
36+
Type: SHT_PROGBITS
37+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
38+
Address: 0x4101CC
39+
AddressAlign: 0x4
40+
Content: 3F2303D5FD7BBFA9FD030091FD7BC1A8BF2303D5C0035FD6
41+
- Name: .eh_frame
42+
Type: SHT_PROGBITS
43+
Flags: [ SHF_ALLOC ]
44+
Address: 0x420068
45+
AddressAlign: 0x8
46+
Content: 1000000000000000017A520004781E011B0C1F0010000000180000003C00FFFF3C0000000041071E140000002C0000006800FFFF08000000000000000000000010000000440000007000FFFF300000000000000010000000580000008C00FFFF3C00000000000000240000006C000000B400FFFF3800000000412D410E209D049E0342930248DEDDD30E00412D0000001400000094000000C400FFFF08000000000000000000000010000000AC00000068FFFEFF080000000000000000000000
47+
- Name: .rela.text
48+
Type: SHT_RELA
49+
Flags: [ SHF_INFO_LINK ]
50+
Link: .symtab
51+
AddressAlign: 0x8
52+
Info: .text
53+
Symbols:
54+
- Name: .text
55+
Type: STT_SECTION
56+
Section: .text
57+
Value: 0x410080
58+
- Name: _ITM_deregisterTMCloneTable
59+
Binding: STB_WEAK
60+
- Name: _ITM_registerTMCloneTable
61+
Binding: STB_WEAK
62+
...
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Check that llvm-bolt can handle DW_CFA_GNU_window_save on AArch64.
2+
3+
RUN: yaml2obj %p/Inputs/dw_cfa_gnu_window_save.yaml &> %t.exe
4+
RUN: llvm-bolt %t.exe -o %t.bolt 2>&1 | FileCheck %s
5+
6+
CHECK-NOT: paciasp
7+
CHECK-NOT: autiasp
8+
CHECK-NOT: ERROR: unable to fill CFI.

0 commit comments

Comments
 (0)