1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

[cfi] Add flag to always generate .debug_frame

This adds a flag to LLVM and clang to always generate a .debug_frame
section, even if other debug information is not being generated. In
situations where .eh_frame would normally be emitted, both .debug_frame
and .eh_frame will be used.

Differential Revision: https://reviews.llvm.org/D67216
This commit is contained in:
David Candler 2019-10-31 08:55:57 +00:00
parent 64b44c3d31
commit 4e46779660
15 changed files with 75 additions and 24 deletions

View File

@ -276,6 +276,11 @@ static cl::opt<bool>
cl::desc("Emit debug info about parameter's entry values"), cl::desc("Emit debug info about parameter's entry values"),
cl::init(false)); cl::init(false));
static cl::opt<bool>
ForceDwarfFrameSection("force-dwarf-frame-section",
cl::desc("Always emit a debug frame section."),
cl::init(false));
// Common utility function tightly tied to the options listed here. Initializes // Common utility function tightly tied to the options listed here. Initializes
// a TargetOptions object with CodeGen flags and returns it. // a TargetOptions object with CodeGen flags and returns it.
static TargetOptions InitTargetOptionsFromCodeGenFlags() { static TargetOptions InitTargetOptionsFromCodeGenFlags() {
@ -306,6 +311,7 @@ static TargetOptions InitTargetOptionsFromCodeGenFlags() {
Options.EmitStackSizeSection = EnableStackSizeSection; Options.EmitStackSizeSection = EnableStackSizeSection;
Options.EmitAddrsig = EnableAddrsig; Options.EmitAddrsig = EnableAddrsig;
Options.EnableDebugEntryValues = EnableDebugEntryValues; Options.EnableDebugEntryValues = EnableDebugEntryValues;
Options.ForceDwarfFrameSection = ForceDwarfFrameSection;
Options.MCOptions = InitMCTargetOptionsFromFlags(); Options.MCOptions = InitMCTargetOptionsFromFlags();

View File

@ -560,6 +560,9 @@ public:
} }
void setHasWinCFI(bool v) { HasWinCFI = v; } void setHasWinCFI(bool v) { HasWinCFI = v; }
/// True if this function needs frame moves for debug or exceptions.
bool needsFrameMoves() const;
/// Get the function properties /// Get the function properties
const MachineFunctionProperties &getProperties() const { return Properties; } const MachineFunctionProperties &getProperties() const { return Properties; }
MachineFunctionProperties &getProperties() { return Properties; } MachineFunctionProperties &getProperties() { return Properties; }

View File

@ -119,7 +119,7 @@ namespace llvm {
ExplicitEmulatedTLS(false), EnableIPRA(false), ExplicitEmulatedTLS(false), EnableIPRA(false),
EmitStackSizeSection(false), EnableMachineOutliner(false), EmitStackSizeSection(false), EnableMachineOutliner(false),
SupportsDefaultOutlining(false), EmitAddrsig(false), SupportsDefaultOutlining(false), EmitAddrsig(false),
EnableDebugEntryValues(false) {} EnableDebugEntryValues(false), ForceDwarfFrameSection(false) {}
/// PrintMachineCode - This flag is enabled when the -print-machineinstrs /// PrintMachineCode - This flag is enabled when the -print-machineinstrs
/// option is specified on the command line, and should enable debugging /// option is specified on the command line, and should enable debugging
@ -256,6 +256,9 @@ namespace llvm {
/// Emit debug info about parameter's entry values. /// Emit debug info about parameter's entry values.
unsigned EnableDebugEntryValues : 1; unsigned EnableDebugEntryValues : 1;
/// Emit DWARF debug frame section.
unsigned ForceDwarfFrameSection : 1;
/// FloatABIType - This setting is set by -float-abi=xxx option is specfied /// FloatABIType - This setting is set by -float-abi=xxx option is specfied
/// on the command line. This setting may either be Default, Soft, or Hard. /// on the command line. This setting may either be Default, Soft, or Hard.
/// Default selects the target's default behavior. Soft selects the ABI for /// Default selects the target's default behavior. Soft selects the ABI for

View File

@ -935,7 +935,7 @@ AsmPrinter::CFIMoveType AsmPrinter::needsCFIMoves() const {
MF->getFunction().needsUnwindTableEntry()) MF->getFunction().needsUnwindTableEntry())
return CFI_M_EH; return CFI_M_EH;
if (MMI->hasDebugInfo()) if (MMI->hasDebugInfo() || MF->getTarget().Options.ForceDwarfFrameSection)
return CFI_M_Debug; return CFI_M_Debug;
return CFI_M_None; return CFI_M_None;

View File

@ -29,6 +29,7 @@
#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormattedStream.h" #include "llvm/Support/FormattedStream.h"
#include "llvm/Target/TargetLoweringObjectFile.h" #include "llvm/Target/TargetLoweringObjectFile.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h" #include "llvm/Target/TargetOptions.h"
using namespace llvm; using namespace llvm;
@ -133,6 +134,8 @@ void DwarfCFIException::beginFragment(const MachineBasicBlock *MBB,
if (!hasEmittedCFISections) { if (!hasEmittedCFISections) {
if (Asm->needsOnlyDebugCFIMoves()) if (Asm->needsOnlyDebugCFIMoves())
Asm->OutStreamer->EmitCFISections(false, true); Asm->OutStreamer->EmitCFISections(false, true);
else if (Asm->TM.Options.ForceDwarfFrameSection)
Asm->OutStreamer->EmitCFISections(true, true);
hasEmittedCFISections = true; hasEmittedCFISections = true;
} }

View File

@ -48,8 +48,7 @@ class CFIInstrInserter : public MachineFunctionPass {
} }
bool runOnMachineFunction(MachineFunction &MF) override { bool runOnMachineFunction(MachineFunction &MF) override {
if (!MF.getMMI().hasDebugInfo() && if (!MF.needsFrameMoves())
!MF.getFunction().needsUnwindTableEntry())
return false; return false;
MBBVector.resize(MF.getNumBlockIDs()); MBBVector.resize(MF.getNumBlockIDs());

View File

@ -520,6 +520,13 @@ void MachineFunction::print(raw_ostream &OS, const SlotIndexes *Indexes) const {
OS << "\n# End machine code for function " << getName() << ".\n\n"; OS << "\n# End machine code for function " << getName() << ".\n\n";
} }
/// True if this function needs frame moves for debug or exceptions.
bool MachineFunction::needsFrameMoves() const {
return getMMI().hasDebugInfo() ||
getTarget().Options.ForceDwarfFrameSection ||
F.needsUnwindTableEntry();
}
namespace llvm { namespace llvm {
template<> template<>

View File

@ -844,8 +844,8 @@ void AArch64FrameLowering::emitPrologue(MachineFunction &MF,
const TargetInstrInfo *TII = Subtarget.getInstrInfo(); const TargetInstrInfo *TII = Subtarget.getInstrInfo();
MachineModuleInfo &MMI = MF.getMMI(); MachineModuleInfo &MMI = MF.getMMI();
AArch64FunctionInfo *AFI = MF.getInfo<AArch64FunctionInfo>(); AArch64FunctionInfo *AFI = MF.getInfo<AArch64FunctionInfo>();
bool needsFrameMoves = (MMI.hasDebugInfo() || F.needsUnwindTableEntry()) && bool needsFrameMoves =
!MF.getTarget().getMCAsmInfo()->usesWindowsCFI(); MF.needsFrameMoves() && !MF.getTarget().getMCAsmInfo()->usesWindowsCFI();
bool HasFP = hasFP(MF); bool HasFP = hasFP(MF);
bool NeedsWinCFI = needsWinCFI(MF); bool NeedsWinCFI = needsWinCFI(MF);
bool HasWinCFI = false; bool HasWinCFI = false;

View File

@ -128,7 +128,7 @@ static void ReplaceFrameIndex(MachineBasicBlock::iterator II,
ARCRegisterInfo::ARCRegisterInfo() : ARCGenRegisterInfo(ARC::BLINK) {} ARCRegisterInfo::ARCRegisterInfo() : ARCGenRegisterInfo(ARC::BLINK) {}
bool ARCRegisterInfo::needsFrameMoves(const MachineFunction &MF) { bool ARCRegisterInfo::needsFrameMoves(const MachineFunction &MF) {
return MF.getMMI().hasDebugInfo() || MF.getFunction().needsUnwindTableEntry(); return MF.needsFrameMoves();
} }
const MCPhysReg * const MCPhysReg *

View File

@ -223,8 +223,7 @@ namespace {
bool HexagonCallFrameInformation::runOnMachineFunction(MachineFunction &MF) { bool HexagonCallFrameInformation::runOnMachineFunction(MachineFunction &MF) {
auto &HFI = *MF.getSubtarget<HexagonSubtarget>().getFrameLowering(); auto &HFI = *MF.getSubtarget<HexagonSubtarget>().getFrameLowering();
bool NeedCFI = MF.getMMI().hasDebugInfo() || bool NeedCFI = MF.needsFrameMoves();
MF.getFunction().needsUnwindTableEntry();
if (!NeedCFI) if (!NeedCFI)
return false; return false;

View File

@ -782,8 +782,7 @@ void PPCFrameLowering::emitPrologue(MachineFunction &MF,
MachineModuleInfo &MMI = MF.getMMI(); MachineModuleInfo &MMI = MF.getMMI();
const MCRegisterInfo *MRI = MMI.getContext().getRegisterInfo(); const MCRegisterInfo *MRI = MMI.getContext().getRegisterInfo();
DebugLoc dl; DebugLoc dl;
bool needsCFI = MMI.hasDebugInfo() || bool needsCFI = MF.needsFrameMoves();
MF.getFunction().needsUnwindTableEntry();
// Get processor type. // Get processor type.
bool isPPC64 = Subtarget.isPPC64(); bool isPPC64 = Subtarget.isPPC64();

View File

@ -993,8 +993,7 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF,
bool NeedsWinFPO = bool NeedsWinFPO =
!IsFunclet && STI.isTargetWin32() && MMI.getModule()->getCodeViewFlag(); !IsFunclet && STI.isTargetWin32() && MMI.getModule()->getCodeViewFlag();
bool NeedsWinCFI = NeedsWin64CFI || NeedsWinFPO; bool NeedsWinCFI = NeedsWin64CFI || NeedsWinFPO;
bool NeedsDwarfCFI = bool NeedsDwarfCFI = !IsWin64Prologue && MF.needsFrameMoves();
!IsWin64Prologue && (MMI.hasDebugInfo() || Fn.needsUnwindTableEntry());
Register FramePtr = TRI->getFrameRegister(MF); Register FramePtr = TRI->getFrameRegister(MF);
const Register MachineFramePtr = const Register MachineFramePtr =
STI.isTarget64BitILP32() STI.isTarget64BitILP32()
@ -1614,10 +1613,9 @@ void X86FrameLowering::emitEpilogue(MachineFunction &MF,
bool HasFP = hasFP(MF); bool HasFP = hasFP(MF);
uint64_t NumBytes = 0; uint64_t NumBytes = 0;
bool NeedsDwarfCFI = bool NeedsDwarfCFI = (!MF.getTarget().getTargetTriple().isOSDarwin() &&
(!MF.getTarget().getTargetTriple().isOSDarwin() && !MF.getTarget().getTargetTriple().isOSWindows()) &&
!MF.getTarget().getTargetTriple().isOSWindows()) && MF.needsFrameMoves();
(MF.getMMI().hasDebugInfo() || MF.getFunction().needsUnwindTableEntry());
if (IsFunclet) { if (IsFunclet) {
assert(HasFP && "EH funclets without FP not yet implemented"); assert(HasFP && "EH funclets without FP not yet implemented");
@ -2812,11 +2810,9 @@ eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
unsigned StackAlign = getStackAlignment(); unsigned StackAlign = getStackAlignment();
Amount = alignTo(Amount, StackAlign); Amount = alignTo(Amount, StackAlign);
MachineModuleInfo &MMI = MF.getMMI();
const Function &F = MF.getFunction(); const Function &F = MF.getFunction();
bool WindowsCFI = MF.getTarget().getMCAsmInfo()->usesWindowsCFI(); bool WindowsCFI = MF.getTarget().getMCAsmInfo()->usesWindowsCFI();
bool DwarfCFI = !WindowsCFI && bool DwarfCFI = !WindowsCFI && MF.needsFrameMoves();
(MMI.hasDebugInfo() || F.needsUnwindTableEntry());
// If we have any exception handlers in this function, and we adjust // If we have any exception handlers in this function, and we adjust
// the SP before calls, we may need to indicate this to the unwinder // the SP before calls, we may need to indicate this to the unwinder

View File

@ -3963,9 +3963,7 @@ static bool ExpandMOVImmSExti8(MachineInstrBuilder &MIB,
MachineFunction &MF = *MBB.getParent(); MachineFunction &MF = *MBB.getParent();
const X86FrameLowering *TFL = Subtarget.getFrameLowering(); const X86FrameLowering *TFL = Subtarget.getFrameLowering();
bool IsWin64Prologue = MF.getTarget().getMCAsmInfo()->usesWindowsCFI(); bool IsWin64Prologue = MF.getTarget().getMCAsmInfo()->usesWindowsCFI();
bool NeedsDwarfCFI = bool NeedsDwarfCFI = !IsWin64Prologue && MF.needsFrameMoves();
!IsWin64Prologue &&
(MF.getMMI().hasDebugInfo() || MF.getFunction().needsUnwindTableEntry());
bool EmitCFI = !TFL->hasFP(MF) && NeedsDwarfCFI; bool EmitCFI = !TFL->hasFP(MF) && NeedsDwarfCFI;
if (EmitCFI) { if (EmitCFI) {
TFL->BuildCFI(MBB, I, DL, TFL->BuildCFI(MBB, I, DL,

View File

@ -203,7 +203,7 @@ static void InsertSPConstInst(MachineBasicBlock::iterator II,
} }
bool XCoreRegisterInfo::needsFrameMoves(const MachineFunction &MF) { bool XCoreRegisterInfo::needsFrameMoves(const MachineFunction &MF) {
return MF.getMMI().hasDebugInfo() || MF.getFunction().needsUnwindTableEntry(); return MF.needsFrameMoves();
} }
const MCPhysReg * const MCPhysReg *

View File

@ -0,0 +1,38 @@
; RUN: llc -mtriple armv7-unknown -frame-pointer=all -filetype=asm -o - %s | FileCheck %s --check-prefix=CHECK-NO-CFI
; RUN: llc -mtriple armv7-unknown -frame-pointer=all -filetype=asm -force-dwarf-frame-section -o - %s | FileCheck %s --check-prefix=CHECK-ALWAYS-CFI
declare void @dummy_use(i32*, i32)
define void @test_basic() #0 {
%mem = alloca i32, i32 10
call void @dummy_use (i32* %mem, i32 10)
ret void
}
; CHECK-NO-CFI-LABEL: test_basic:
; CHECK-NO-CFI: .fnstart
; CHECK-NO-CFI-NOT: .cfi_sections .debug_frame
; CHECK-NO-CFI-NOT: .cfi_startproc
; CHECK-NO-CFI: @ %bb.0:
; CHECK-NO-CFI: push {r11, lr}
; CHECK-NO-CFI-NOT: .cfi_def_cfa_offset 8
; CHECK-NO-CFI-NOT: .cfi_offset lr, -4
; CHECK-NO-CFI-NOT: .cfi_offset r11, -8
; CHECK-NO-CFI: mov r11, sp
; CHECK-NO-CFI-NOT: .cfi_def_cfa_register r11
; CHECK-NO-CFI-NOT: .cfi_endproc
; CHECK-NO-CFI: .fnend
; CHECK-ALWAYS-CFI-LABEL: test_basic:
; CHECK-ALWAYS-CFI: .fnstart
; CHECK-ALWAYS-CFI: .cfi_sections .debug_frame
; CHECK-ALWAYS-CFI: .cfi_startproc
; CHECK-ALWAYS-CFI: @ %bb.0:
; CHECK-ALWAYS-CFI: push {r11, lr}
; CHECK-ALWAYS-CFI: .cfi_def_cfa_offset 8
; CHECK-ALWAYS-CFI: .cfi_offset lr, -4
; CHECK-ALWAYS-CFI: .cfi_offset r11, -8
; CHECK-ALWAYS-CFI: mov r11, sp
; CHECK-ALWAYS-CFI: .cfi_def_cfa_register r11
; CHECK-ALWAYS-CFI: .cfi_endproc
; CHECK-ALWAYS-CFI: .fnend