[llvm] [llvm-dwarfdump] Fix parsing DW_CFA_AARCH64_negate_ra_state (PR #84128)
Igor Kudrin via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 5 23:24:41 PST 2024
https://github.com/igorkudrin created https://github.com/llvm/llvm-project/pull/84128
The saved state of the AARCH64_DWARF_PAUTH_RA_STATE register was not updated, so `llvm-dwarfdump` continued to dump it as `reg34=1` even if the correct value is `0`:
```
> llvm-dwarfdump -v test.o
...
0000002c 00000024 00000030 FDE cie=00000000 pc=00000030...00000064
Format: DWARF32
DW_CFA_advance_loc: 4
DW_CFA_AARCH64_negate_ra_state:
DW_CFA_advance_loc: 4
DW_CFA_def_cfa_offset: +16
DW_CFA_offset: W30 -16
DW_CFA_remember_state:
DW_CFA_advance_loc: 16
DW_CFA_def_cfa_offset: +0
DW_CFA_advance_loc: 4
DW_CFA_AARCH64_negate_ra_state:
DW_CFA_restore: W30
DW_CFA_advance_loc: 4
DW_CFA_restore_state:
DW_CFA_advance_loc: 12
DW_CFA_def_cfa_offset: +0
DW_CFA_advance_loc: 4
DW_CFA_AARCH64_negate_ra_state:
DW_CFA_restore: W30
DW_CFA_nop:
0x30: CFA=WSP
0x34: CFA=WSP: reg34=1
0x38: CFA=WSP+16: W30=[CFA-16], reg34=1
0x48: CFA=WSP: W30=[CFA-16], reg34=1
0x4c: CFA=WSP: reg34=1 <--- should be '=0'
0x50: CFA=WSP+16: W30=[CFA-16], reg34=1
0x5c: CFA=WSP: W30=[CFA-16], reg34=1
0x60: CFA=WSP: reg34=1 <--- should be '=0'
```
>From 569671d2e76edcbf0464714c035308a048e70d53 Mon Sep 17 00:00:00 2001
From: Igor Kudrin <ikudrin at accesssoftek.com>
Date: Tue, 5 Mar 2024 23:15:10 -0800
Subject: [PATCH] [llvm-dwarfdump] Fix parsing DW_CFA_AARCH64_negate_ra_state
The saved state of the AARCH64_DWARF_PAUTH_RA_STATE register was not
updated, so `llvm-dwarfdump` continued to dump it as `reg34=1` even if
the correct value is `0`:
```
> llvm-dwarfdump -v test.o
...
0000002c 00000024 00000030 FDE cie=00000000 pc=00000030...00000064
Format: DWARF32
DW_CFA_advance_loc: 4
DW_CFA_AARCH64_negate_ra_state:
DW_CFA_advance_loc: 4
DW_CFA_def_cfa_offset: +16
DW_CFA_offset: W30 -16
DW_CFA_remember_state:
DW_CFA_advance_loc: 16
DW_CFA_def_cfa_offset: +0
DW_CFA_advance_loc: 4
DW_CFA_AARCH64_negate_ra_state:
DW_CFA_restore: W30
DW_CFA_advance_loc: 4
DW_CFA_restore_state:
DW_CFA_advance_loc: 12
DW_CFA_def_cfa_offset: +0
DW_CFA_advance_loc: 4
DW_CFA_AARCH64_negate_ra_state:
DW_CFA_restore: W30
DW_CFA_nop:
0x30: CFA=WSP
0x34: CFA=WSP: reg34=1
0x38: CFA=WSP+16: W30=[CFA-16], reg34=1
0x48: CFA=WSP: W30=[CFA-16], reg34=1
0x4c: CFA=WSP: reg34=1 <--- should be '=0'
0x50: CFA=WSP+16: W30=[CFA-16], reg34=1
0x5c: CFA=WSP: W30=[CFA-16], reg34=1
0x60: CFA=WSP: reg34=1 <--- should be '=0'
```
---
llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp | 2 ++
...sign-return-address-cfi-negate-ra-state.ll | 19 +++++++++++++++++++
2 files changed, 21 insertions(+)
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
index aae1668c1639c4..0c968703f80b0d 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
@@ -630,6 +630,8 @@ Error UnwindTable::parseRows(const CFIProgram &CFIP, UnwindRow &Row,
if (LRLoc->getLocation() == UnwindLocation::Constant) {
// Toggle the constant value from 0 to 1 or 1 to 0.
LRLoc->setConstant(LRLoc->getConstant() ^ 1);
+ Row.getRegisterLocations().setRegisterLocation(
+ AArch64DWARFPAuthRaState, *LRLoc);
} else {
return createStringError(
errc::invalid_argument,
diff --git a/llvm/test/CodeGen/AArch64/sign-return-address-cfi-negate-ra-state.ll b/llvm/test/CodeGen/AArch64/sign-return-address-cfi-negate-ra-state.ll
index da2c2985acf971..9464e3447993b3 100644
--- a/llvm/test/CodeGen/AArch64/sign-return-address-cfi-negate-ra-state.ll
+++ b/llvm/test/CodeGen/AArch64/sign-return-address-cfi-negate-ra-state.ll
@@ -213,6 +213,10 @@ attributes #0 = { "sign-return-address"="all" }
; CHECK-DUMP-NOT: DW_CFA_remember_state
; CHECK-DUMP-NOT: DW_CFA_restore_state
+; CHECK-DUMP: CFA=WSP{{$}}
+; CHECK-DUMP: reg34=1
+; CHECK-DUMP-NOT: reg34=0
+
; baz_async
; CHECK-DUMP-LABEL: FDE
; CHECK-DUMP: Format: DWARF32
@@ -222,9 +226,24 @@ attributes #0 = { "sign-return-address"="all" }
; CHECK-DUMP: DW_CFA_restore_state:
; CHECK-DUMP: DW_CFA_AARCH64_negate_ra_state:
+; CHECK-DUMP: CFA=WSP{{$}}
+;; First DW_CFA_AARCH64_negate_ra_state:
+; CHECK-DUMP: reg34=1
+;; Second DW_CFA_AARCH64_negate_ra_state:
+; CHECK-DUMP: reg34=0
+;; DW_CFA_restore_state:
+; CHECK-DUMP: reg34=1
+;; Third DW_CFA_AARCH64_negate_ra_state:
+; CHECK-DUMP: reg34=0
+; CHECK-DUMP-NOT: reg34=
+
; baz_sync
; CHECK-DUMP-LABEL: FDE
; CHECK-DUMP: DW_CFA_AARCH64_negate_ra_state:
; CHECK-DUMP-NOT: DW_CFA_AARCH64_negate_ra_state
; CHECK-DUMP-NOT: DW_CFA_remember_state
; CHECK-DUMP-NOT: DW_CFA_restore_state
+
+; CHECK-DUMP: CFA=WSP{{$}}
+; CHECK-DUMP: reg34=1
+; CHECK-DUMP-NOT: reg34=0
More information about the llvm-commits
mailing list