Skip to content

Commit eaad7a4

Browse files
committed
[CFIFixup] Fixup CFI for split functions with synchronous uwtables
Commit 6e54fcc disables CFI fixup for functions with synchronous tables, breaking CFI for split functions. Instead, we can disable *block-level* CFI fixup for functions with synchronous tables. Unwind tables can be: - N/A (not present) - Asynchronous - Synchronous Functions without unwind tables don't need CFI fixup (since they don't care about CFI). Functions with asynchronous unwind tables must be accurate for each basic block, so full CFI fixup is necessary. Functions with synchronous unwind tables only need to be accurate for each function (specifically, the portion of a function in a given section). Disabling CFI fixup entirely for functions with synchronous uwtables may break CFI for a function split between two sections. The portion in the first section may have valid CFI, while the portion in the second section is missing a call frame. Ex: ``` (.text.hot) Foo (BB1): <Call frame information> ... BB2: ... (.text.split) BB3: ... BB4: <epilogue> ``` Even if `Foo` has a synchronous unwind table, we still need to insert call frame information into `BB3` so that unwinding the call stack from `BB3` or `BB4` works properly.
1 parent 6e98d8b commit eaad7a4

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

llvm/lib/CodeGen/CFIFixup.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
#include "llvm/CodeGen/TargetSubtargetInfo.h"
8181
#include "llvm/MC/MCAsmInfo.h"
8282
#include "llvm/MC/MCDwarf.h"
83+
#include "llvm/Support/CodeGen.h"
8384
#include "llvm/Target/TargetMachine.h"
8485

8586
#include <iterator>
@@ -243,12 +244,18 @@ fixupBlock(MachineBasicBlock &CurrBB, const BlockFlagsVector &BlockInfo,
243244
SmallDenseMap<MBBSectionID, InsertionPoint> &InsertionPts,
244245
const InsertionPoint &Prologue) {
245246
const MachineFunction &MF = *CurrBB.getParent();
247+
const Function &F = MF.getFunction();
246248
const TargetFrameLowering &TFL = *MF.getSubtarget().getFrameLowering();
247249
const BlockFlags &Info = BlockInfo[CurrBB.getNumber()];
248250

249251
if (!Info.Reachable)
250252
return false;
251253

254+
// Only async unwind tables need to fix up CFI at the block level. Otherwise,
255+
// the function/section level is sufficient.
256+
if (F.getUWTableKind() != UWTableKind::Async && !CurrBB.isBeginSection())
257+
return false;
258+
252259
// If the previous block and the current block are in the same section,
253260
// the frame info will propagate from the previous block to the current one.
254261
const BlockFlags &PrevInfo =

llvm/lib/Target/AArch64/AArch64FrameLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2611,7 +2611,7 @@ void AArch64FrameLowering::emitEpilogue(MachineFunction &MF,
26112611

26122612
bool AArch64FrameLowering::enableCFIFixup(MachineFunction &MF) const {
26132613
return TargetFrameLowering::enableCFIFixup(MF) &&
2614-
MF.getInfo<AArch64FunctionInfo>()->needsAsyncDwarfUnwindInfo(MF);
2614+
MF.getInfo<AArch64FunctionInfo>()->needsDwarfUnwindInfo(MF);
26152615
}
26162616

26172617
/// getFrameIndexReference - Provide a base+offset reference to an FI slot for

llvm/test/CodeGen/AArch64/cfi-fixup-multi-section.mir

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,10 @@ body: |
285285
; CHECK-NEXT: successors: %bb.5(0x80000000)
286286
; CHECK-NEXT: liveins: $w0
287287
; CHECK-NEXT: {{ $}}
288+
; CHECK-NEXT: frame-setup CFI_INSTRUCTION escape 0x16, 0x12, 0x02, 0x82, 0x78
289+
; CHECK-NEXT: frame-setup CFI_INSTRUCTION negate_ra_sign_state
290+
; CHECK-NEXT: frame-setup CFI_INSTRUCTION def_cfa_offset 16
291+
; CHECK-NEXT: frame-setup CFI_INSTRUCTION offset $w30, -16
288292
; CHECK-NEXT: renamable $w0 = nsw SUBWri killed renamable $w0, 1, 0
289293
; CHECK-NEXT: BL @g, csr_aarch64_aapcs_scs, implicit-def dead $lr, implicit $sp, implicit killed $w0, implicit-def $sp, implicit-def $w0
290294
; CHECK-NEXT: renamable $w0 = nsw ADDWri killed renamable $w0, 1, 0

0 commit comments

Comments
 (0)