[llvm] 4dc462b - [AArch64] Emit CFI instruction for updating x18 when using ShadowCallStack with exception unwinding
Leonard Chan via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 8 14:21:25 PDT 2021
Author: Leonard Chan
Date: 2021-10-08T14:20:26-07:00
New Revision: 4dc462b58909a73a2ae219863f4b7219483ba23e
URL: https://github.com/llvm/llvm-project/commit/4dc462b58909a73a2ae219863f4b7219483ba23e
DIFF: https://github.com/llvm/llvm-project/commit/4dc462b58909a73a2ae219863f4b7219483ba23e.diff
LOG: [AArch64] Emit CFI instruction for updating x18 when using ShadowCallStack with exception unwinding
PR45875 notes an instance where exception handling crashes on aarch64-fuchsia
where SCS is enabled by default. The underlying issue seems to be that within libunwind,
various _Unwind_* functions, the x18 register is not updated if a function is marked
with nounwind. This removes the check for nounwind and emits the CFI instruction that updates x18.
Differential Revision: https://reviews.llvm.org/D79822
Added:
Modified:
llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
llvm/test/CodeGen/AArch64/shadow-call-stack.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp b/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
index 9883f63bf9217..635642d13a778 100644
--- a/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
@@ -2494,22 +2494,20 @@ bool AArch64FrameLowering::spillCalleeSavedRegisters(
BuildMI(MBB, MI, DL, TII.get(AArch64::SEH_Nop))
.setMIFlag(MachineInstr::FrameSetup);
- if (!MF.getFunction().hasFnAttribute(Attribute::NoUnwind)) {
- // Emit a CFI instruction that causes 8 to be subtracted from the value of
- // x18 when unwinding past this frame.
- static const char CFIInst[] = {
- dwarf::DW_CFA_val_expression,
- 18, // register
- 2, // length
- static_cast<char>(unsigned(dwarf::DW_OP_breg18)),
- static_cast<char>(-8) & 0x7f, // addend (sleb128)
- };
- unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::createEscape(
- nullptr, StringRef(CFIInst, sizeof(CFIInst))));
- BuildMI(MBB, MI, DL, TII.get(AArch64::CFI_INSTRUCTION))
- .addCFIIndex(CFIIndex)
- .setMIFlag(MachineInstr::FrameSetup);
- }
+ // Emit a CFI instruction that causes 8 to be subtracted from the value of
+ // x18 when unwinding past this frame.
+ static const char CFIInst[] = {
+ dwarf::DW_CFA_val_expression,
+ 18, // register
+ 2, // length
+ static_cast<char>(unsigned(dwarf::DW_OP_breg18)),
+ static_cast<char>(-8) & 0x7f, // addend (sleb128)
+ };
+ unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::createEscape(
+ nullptr, StringRef(CFIInst, sizeof(CFIInst))));
+ BuildMI(MBB, MI, DL, TII.get(AArch64::CFI_INSTRUCTION))
+ .addCFIIndex(CFIIndex)
+ .setMIFlag(MachineInstr::FrameSetup);
// This instruction also makes x18 live-in to the entry block.
MBB.addLiveIn(AArch64::X18);
diff --git a/llvm/test/CodeGen/AArch64/shadow-call-stack.ll b/llvm/test/CodeGen/AArch64/shadow-call-stack.ll
index 73c17810994ae..e29b54b5b3ee5 100644
--- a/llvm/test/CodeGen/AArch64/shadow-call-stack.ll
+++ b/llvm/test/CodeGen/AArch64/shadow-call-stack.ll
@@ -58,3 +58,10 @@ define i32 @f5() shadowcallstack nounwind {
ret i32 %res
}
+define i32 @f6() shadowcallstack nounwind uwtable {
+ ; CHECK: f6:
+ ; CHECK: .cfi_escape 0x16, 0x12, 0x02, 0x82, 0x78
+ %res = call i32 @bar()
+ %res1 = add i32 %res, 1
+ ret i32 %res
+}
More information about the llvm-commits
mailing list