[libunwind] [llvm] [AArch64][Libunwind] Add Support for FEAT_PAuthLR DWARF Instruction (PR #112171)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 14 02:02:46 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 7fc3491c045bf6acb9c904a5da95bbac66ad487f 18b24b0f077dbca8b2296b8d18acbaf69eeac834 --extensions h,hpp,cpp -- libunwind/src/DwarfInstructions.hpp libunwind/src/DwarfParser.hpp libunwind/src/dwarf2.h llvm/include/llvm/MC/MCDwarf.h llvm/include/llvm/MC/MCStreamer.h llvm/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp llvm/lib/CodeGen/CFIInstrInserter.cpp llvm/lib/CodeGen/MIRParser/MILexer.cpp llvm/lib/CodeGen/MIRParser/MILexer.h llvm/lib/CodeGen/MIRParser/MIParser.cpp llvm/lib/CodeGen/MachineOperand.cpp llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp llvm/lib/MC/MCAsmStreamer.cpp llvm/lib/MC/MCDwarf.cpp llvm/lib/MC/MCStreamer.cpp llvm/lib/Target/AArch64/AArch64FrameLowering.cpp llvm/lib/Target/AArch64/AArch64PointerAuth.cpp llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp llvm/unittests/DebugInfo/DWARF/DWARFDebugFrameTest.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/libunwind/src/DwarfInstructions.hpp b/libunwind/src/DwarfInstructions.hpp
index e7c467de80..e7be0d6d5d 100644
--- a/libunwind/src/DwarfInstructions.hpp
+++ b/libunwind/src/DwarfInstructions.hpp
@@ -318,14 +318,19 @@ int DwarfInstructions<A, R>::stepWithDwarf(A &addressSpace, pint_t pc,
// We use the hint versions of the authentication instructions below to
// ensure they're assembled by the compiler even for targets with no
// FEAT_PAuth/FEAT_PAuth_LR support.
- if(isReturnAddressSignedWithPC(addressSpace, registers, cfa, prolog)) {
- register unsigned long long x15 __asm("x15") = prolog.ptrAuthDiversifier;
- if(cieInfo.addressesSignedWithBKey) {
+ if (isReturnAddressSignedWithPC(addressSpace, registers, cfa, prolog)) {
+ register unsigned long long x15 __asm("x15") =
+ prolog.ptrAuthDiversifier;
+ if (cieInfo.addressesSignedWithBKey) {
asm("hint 0x27\n\t" // pacm
- "hint 0xe" : "+r"(x17) : "r"(x16), "r"(x15)); // autib1716
+ "hint 0xe"
+ : "+r"(x17)
+ : "r"(x16), "r"(x15)); // autib1716
} else {
asm("hint 0x27\n\t" // pacm
- "hint 0xc" : "+r"(x17) : "r"(x16), "r"(x15)); // autia1716
+ "hint 0xc"
+ : "+r"(x17)
+ : "r"(x16), "r"(x15)); // autia1716
}
} else {
if (cieInfo.addressesSignedWithBKey)
diff --git a/libunwind/src/DwarfParser.hpp b/libunwind/src/DwarfParser.hpp
index b104d773ed..3b099af2ea 100644
--- a/libunwind/src/DwarfParser.hpp
+++ b/libunwind/src/DwarfParser.hpp
@@ -91,9 +91,9 @@ public:
int64_t cfaExpression; // CFA = expression
uint32_t spExtraArgSize;
RegisterLocation savedRegisters[kMaxRegisterNumber + 1];
- #if defined(_LIBUNWIND_TARGET_AARCH64)
- pint_t ptrAuthDiversifier;
- #endif
+#if defined(_LIBUNWIND_TARGET_AARCH64)
+ pint_t ptrAuthDiversifier;
+#endif
enum class InitializeTime { kLazy, kNormal };
// When saving registers, this data structure is lazily initialized.
@@ -808,15 +808,16 @@ bool CFI_Parser<A>::parseFDEInstructions(A &addressSpace,
results->savedRegisters[UNW_AARCH64_RA_SIGN_STATE].value ^ 0x3;
results->setRegisterValue(UNW_AARCH64_RA_SIGN_STATE, value,
initialState);
- // When calucating the value of the PC, it is assumed that the CFI instruction
- // is placed before the signing instruction, however it is placed after. Because
- // of this, we need to take into account the CFI instruction is one instruction
- // call later than expected, and reduce the PC value by 4 bytes to compensate.
+ // When calucating the value of the PC, it is assumed that the CFI
+ // instruction is placed before the signing instruction, however it is
+ // placed after. Because of this, we need to take into account the CFI
+ // instruction is one instruction call later than expected, and reduce
+ // the PC value by 4 bytes to compensate.
results->ptrAuthDiversifier = fdeInfo.pcStart + codeOffset - 0x4;
- _LIBUNWIND_TRACE_DWARF("DW_CFA_AARCH64_negate_ra_state_with_pc(pc=0x%" PRIx64 ")\n",
- static_cast<uint64_t>(results->ptrAuthDiversifier));
- }
- break;
+ _LIBUNWIND_TRACE_DWARF(
+ "DW_CFA_AARCH64_negate_ra_state_with_pc(pc=0x%" PRIx64 ")\n",
+ static_cast<uint64_t>(results->ptrAuthDiversifier));
+ } break;
#endif
#else
diff --git a/libunwind/src/dwarf2.h b/libunwind/src/dwarf2.h
index 2ad3d3c464..68ad882347 100644
--- a/libunwind/src/dwarf2.h
+++ b/libunwind/src/dwarf2.h
@@ -18,44 +18,43 @@
// DWARF unwind instructions
enum {
- DW_CFA_nop = 0x0,
- DW_CFA_set_loc = 0x1,
- DW_CFA_advance_loc1 = 0x2,
- DW_CFA_advance_loc2 = 0x3,
- DW_CFA_advance_loc4 = 0x4,
- DW_CFA_offset_extended = 0x5,
- DW_CFA_restore_extended = 0x6,
- DW_CFA_undefined = 0x7,
- DW_CFA_same_value = 0x8,
- DW_CFA_register = 0x9,
- DW_CFA_remember_state = 0xA,
- DW_CFA_restore_state = 0xB,
- DW_CFA_def_cfa = 0xC,
- DW_CFA_def_cfa_register = 0xD,
- DW_CFA_def_cfa_offset = 0xE,
- DW_CFA_def_cfa_expression = 0xF,
- DW_CFA_expression = 0x10,
+ DW_CFA_nop = 0x0,
+ DW_CFA_set_loc = 0x1,
+ DW_CFA_advance_loc1 = 0x2,
+ DW_CFA_advance_loc2 = 0x3,
+ DW_CFA_advance_loc4 = 0x4,
+ DW_CFA_offset_extended = 0x5,
+ DW_CFA_restore_extended = 0x6,
+ DW_CFA_undefined = 0x7,
+ DW_CFA_same_value = 0x8,
+ DW_CFA_register = 0x9,
+ DW_CFA_remember_state = 0xA,
+ DW_CFA_restore_state = 0xB,
+ DW_CFA_def_cfa = 0xC,
+ DW_CFA_def_cfa_register = 0xD,
+ DW_CFA_def_cfa_offset = 0xE,
+ DW_CFA_def_cfa_expression = 0xF,
+ DW_CFA_expression = 0x10,
DW_CFA_offset_extended_sf = 0x11,
- DW_CFA_def_cfa_sf = 0x12,
- DW_CFA_def_cfa_offset_sf = 0x13,
- DW_CFA_val_offset = 0x14,
- DW_CFA_val_offset_sf = 0x15,
- DW_CFA_val_expression = 0x16,
- DW_CFA_advance_loc = 0x40, // high 2 bits are 0x1, lower 6 bits are delta
- DW_CFA_offset = 0x80, // high 2 bits are 0x2, lower 6 bits are register
- DW_CFA_restore = 0xC0, // high 2 bits are 0x3, lower 6 bits are register
+ DW_CFA_def_cfa_sf = 0x12,
+ DW_CFA_def_cfa_offset_sf = 0x13,
+ DW_CFA_val_offset = 0x14,
+ DW_CFA_val_offset_sf = 0x15,
+ DW_CFA_val_expression = 0x16,
+ DW_CFA_advance_loc = 0x40, // high 2 bits are 0x1, lower 6 bits are delta
+ DW_CFA_offset = 0x80, // high 2 bits are 0x2, lower 6 bits are register
+ DW_CFA_restore = 0xC0, // high 2 bits are 0x3, lower 6 bits are register
// GNU extensions
- DW_CFA_GNU_window_save = 0x2D,
- DW_CFA_GNU_args_size = 0x2E,
+ DW_CFA_GNU_window_save = 0x2D,
+ DW_CFA_GNU_args_size = 0x2E,
DW_CFA_GNU_negative_offset_extended = 0x2F,
// AARCH64 extensions
DW_CFA_AARCH64_negate_ra_state_with_pc = 0x2C,
- DW_CFA_AARCH64_negate_ra_state = 0x2D
+ DW_CFA_AARCH64_negate_ra_state = 0x2D
};
-
// FSF exception handling Pointer-Encoding constants
// Used in CFI augmentation by GCC
enum {
diff --git a/llvm/include/llvm/MC/MCDwarf.h b/llvm/include/llvm/MC/MCDwarf.h
index 2ceea906ea..1392336968 100644
--- a/llvm/include/llvm/MC/MCDwarf.h
+++ b/llvm/include/llvm/MC/MCDwarf.h
@@ -649,7 +649,6 @@ public:
return MCCFIInstruction(OpNegateRAStateWithPC, L, 0, INT64_C(0), Loc);
}
-
/// .cfi_restore says that the rule for Register is now the same as it
/// was at the beginning of the function, after all initial instructions added
/// by .cfi_startproc were executed.
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
index 38e264f233..96cb86ad4c 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
@@ -668,26 +668,26 @@ Error UnwindTable::parseRows(const CFIProgram &CFIP, UnwindRow &Row,
break;
case dwarf::DW_CFA_AARCH64_negate_ra_state_with_pc: {
- constexpr uint32_t AArch64DWARFPAuthRaState = 34;
- auto LRLoc = Row.getRegisterLocations().getRegisterLocation(
- AArch64DWARFPAuthRaState);
- if (LRLoc) {
- if (LRLoc->getLocation() == UnwindLocation::Constant) {
- // Toggle the constant value of bits[1:0] from 0 to 1 or 1 to 0.
- LRLoc->setConstant(LRLoc->getConstant() ^ 0x3);
- } else {
- return createStringError(
- errc::invalid_argument,
- "%s encountered when existing rule for this register is not "
- "a constant",
- CFIP.callFrameString(Inst.Opcode).str().c_str());
- }
+ constexpr uint32_t AArch64DWARFPAuthRaState = 34;
+ auto LRLoc = Row.getRegisterLocations().getRegisterLocation(
+ AArch64DWARFPAuthRaState);
+ if (LRLoc) {
+ if (LRLoc->getLocation() == UnwindLocation::Constant) {
+ // Toggle the constant value of bits[1:0] from 0 to 1 or 1 to 0.
+ LRLoc->setConstant(LRLoc->getConstant() ^ 0x3);
} else {
- Row.getRegisterLocations().setRegisterLocation(
- AArch64DWARFPAuthRaState, UnwindLocation::createIsConstant(0x3));
+ return createStringError(
+ errc::invalid_argument,
+ "%s encountered when existing rule for this register is not "
+ "a constant",
+ CFIP.callFrameString(Inst.Opcode).str().c_str());
}
- break;
+ } else {
+ Row.getRegisterLocations().setRegisterLocation(
+ AArch64DWARFPAuthRaState, UnwindLocation::createIsConstant(0x3));
}
+ break;
+ }
case dwarf::DW_CFA_undefined: {
llvm::Expected<uint64_t> RegNum = Inst.getOperandAsUnsigned(CFIP, 0);
diff --git a/llvm/lib/Target/AArch64/AArch64PointerAuth.cpp b/llvm/lib/Target/AArch64/AArch64PointerAuth.cpp
index c3ad488fb8..2e5688cf60 100644
--- a/llvm/lib/Target/AArch64/AArch64PointerAuth.cpp
+++ b/llvm/lib/Target/AArch64/AArch64PointerAuth.cpp
@@ -224,13 +224,15 @@ void AArch64PointerAuth::authenticateLR(
TII->get(UseBKey ? AArch64::AUTIBSPPCi : AArch64::AUTIASPPCi))
.addSym(PACSym)
.setMIFlag(MachineInstr::FrameDestroy);
- emitPACCFI(*Subtarget, MBB, MBBI, DL, MachineInstr::FrameDestroy, EmitAsyncCFI);
+ emitPACCFI(*Subtarget, MBB, MBBI, DL, MachineInstr::FrameDestroy,
+ EmitAsyncCFI);
} else {
BuildPACM(*Subtarget, MBB, MBBI, DL, MachineInstr::FrameDestroy, PACSym);
BuildMI(MBB, MBBI, DL,
TII->get(UseBKey ? AArch64::AUTIBSP : AArch64::AUTIASP))
.setMIFlag(MachineInstr::FrameDestroy);
- emitPACCFI(*Subtarget, MBB, MBBI, DL, MachineInstr::FrameDestroy, EmitAsyncCFI);
+ emitPACCFI(*Subtarget, MBB, MBBI, DL, MachineInstr::FrameDestroy,
+ EmitAsyncCFI);
}
if (NeedsWinCFI) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/112171
More information about the cfe-commits
mailing list