[PATCH] D79822: [AArch64] Emit CFI instruction for updating x18 when using ShadowCallStack with exception unwinding
Leonard Chan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 12 16:11:31 PDT 2020
leonardchan created this revision.
leonardchan added reviewers: pcc, phosek, mcgrathr, eugenis.
leonardchan added a project: LLVM.
Herald added subscribers: danielkiss, hiraditya, kristof.beyls.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D79822
Files:
llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
llvm/test/CodeGen/AArch64/shadow-call-stack.ll
Index: llvm/test/CodeGen/AArch64/shadow-call-stack.ll
===================================================================
--- llvm/test/CodeGen/AArch64/shadow-call-stack.ll
+++ llvm/test/CodeGen/AArch64/shadow-call-stack.ll
@@ -54,3 +54,11 @@
%res1 = add i32 %res, 1
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
+}
Index: llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
===================================================================
--- llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
+++ llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
@@ -2144,22 +2144,20 @@
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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79822.263554.patch
Type: text/x-patch
Size: 2338 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200512/26782a61/attachment.bin>
More information about the llvm-commits
mailing list