LLVM
22.0.0git
include
llvm
DWARFCFIChecker
DWARFCFIAnalysis.h
Go to the documentation of this file.
1
//===----------------------------------------------------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
///
9
/// \file
10
/// This file declares `DWARFCFIAnalysis` class.
11
/// `DWARFCFIAnalysis` is a minimal implementation of a DWARF CFI checker
12
/// described in this link:
13
/// https://discourse.llvm.org/t/rfc-dwarf-cfi-validation/86936
14
///
15
/// The goal of the checker is to validate DWARF CFI directives using the
16
/// prologue directives and the machine instructions. The main proposed
17
/// algorithm validates the directives by comparing the CFI state in each
18
/// instruction with the state achieved by abstract execution of the instruction
19
/// on the CFI state. However, the current version implemented here is a simple
20
/// conditional check based on the registers modified by each instruction.
21
///
22
//===----------------------------------------------------------------------===//
23
24
#ifndef LLVM_DWARFCFICHECKER_DWARFCFIANALYSIS_H
25
#define LLVM_DWARFCFICHECKER_DWARFCFIANALYSIS_H
26
27
#include "
DWARFCFIState.h
"
28
#include "
llvm/ADT/ArrayRef.h
"
29
#include "
llvm/ADT/SmallSet.h
"
30
#include "
llvm/ADT/SmallVector.h
"
31
#include "
llvm/DebugInfo/DWARF/LowLevel/DWARFUnwindTable.h
"
32
#include "
llvm/MC/MCContext.h
"
33
#include "
llvm/MC/MCDwarf.h
"
34
#include "
llvm/MC/MCExpr.h
"
35
#include "
llvm/MC/MCInst.h
"
36
#include "
llvm/MC/MCInstrInfo.h
"
37
#include "
llvm/MC/MCRegisterInfo.h
"
38
#include "
llvm/MC/MCStreamer.h
"
39
#include "
llvm/MC/MCSubtargetInfo.h
"
40
#include "
llvm/MC/TargetRegistry.h
"
41
#include "
llvm/Support/Compiler.h
"
42
43
namespace
llvm
{
44
45
/// `DWARFCFIAnalysis` validates the DWARF Call Frame Information one machine
46
/// instruction at a time. This class maintains an internal CFI state
47
/// initialized with the prologue directives and updated with each instruction's
48
/// associated directives. In each update, it checks if the machine
49
/// instruction changes the CFI state in a way that matches the changes
50
/// from the CFI directives. This checking may results in errors and warnings.
51
///
52
/// In current stage, the analysis is only aware of what registers the
53
/// instruction modifies. If the modification is happening to a sub-register,
54
/// the analysis considers the super-register is modified.
55
///
56
/// In each update, for each register (or CFA), the following cases can happen:
57
/// 1. The unwinding rule is not changed:
58
/// a. The registers involved in this rule are not modified: the analysis
59
/// proceeds without emitting error or warning.
60
/// b. The registers involved in this rule are modified: it emits an error.
61
/// 2. The unwinding rule is changed:
62
/// a. The rule is structurally modified (i.e., the location is changed): It
63
/// emits a warning.
64
/// b. The rule is structurally the same, but the register set is changed: it
65
/// emits a warning.
66
/// c. The rule is structurally the same, using the same set of registers, but
67
/// the offset is changed:
68
/// i. If the registers included in the rule are modified as well: It
69
/// emits a warning.
70
/// ii. If the registers included in the rule are not modified: It emits an
71
/// error.
72
///
73
/// The analysis only checks the CFA unwinding rule when the rule is a register
74
/// plus some offset. Therefore, for CFA, only cases 1, 2.b, and 2.c are
75
/// checked, and in all other case(s), a warning is emitted.
76
class
DWARFCFIAnalysis
{
77
public
:
78
LLVM_ABI
DWARFCFIAnalysis
(
MCContext
*Context,
MCInstrInfo
const
&MCII,
79
bool
IsEH,
ArrayRef<MCCFIInstruction>
Prologue);
80
81
LLVM_ABI
void
update
(
const
MCInst
&Inst,
82
ArrayRef<MCCFIInstruction>
Directives);
83
84
private
:
85
void
checkRegDiff(
const
MCInst
&Inst,
DWARFRegNum
Reg
,
86
const
dwarf::UnwindRow
&PrevRow,
87
const
dwarf::UnwindRow
&NextRow,
88
const
SmallSet<DWARFRegNum, 4>
&Reads,
89
const
SmallSet<DWARFRegNum, 4>
&Writes);
90
91
void
checkCFADiff(
const
MCInst
&Inst,
const
dwarf::UnwindRow
&PrevRow,
92
const
dwarf::UnwindRow
&NextRow,
93
const
SmallSet<DWARFRegNum, 4>
&Reads,
94
const
SmallSet<DWARFRegNum, 4>
&Writes);
95
96
private
:
97
DWARFCFIState
State;
98
MCContext
*Context;
99
MCInstrInfo
const
&MCII;
100
MCRegisterInfo
const
*MCRI;
101
bool
IsEH;
102
};
103
104
}
// namespace llvm
105
106
#endif
ArrayRef.h
Compiler.h
LLVM_ABI
#define LLVM_ABI
Definition
Compiler.h:213
DWARFCFIState.h
This file declares DWARFCFIState class.
DWARFUnwindTable.h
MCContext.h
MCDwarf.h
MCExpr.h
MCInst.h
MCInstrInfo.h
MCRegisterInfo.h
MCStreamer.h
MCSubtargetInfo.h
Reg
Register Reg
Definition
MachineSink.cpp:2117
SmallSet.h
This file defines the SmallSet class.
SmallVector.h
This file defines the SmallVector class.
TargetRegistry.h
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition
ArrayRef.h:41
llvm::DWARFCFIAnalysis::update
LLVM_ABI void update(const MCInst &Inst, ArrayRef< MCCFIInstruction > Directives)
Definition
DWARFCFIAnalysis.cpp:125
llvm::DWARFCFIAnalysis::DWARFCFIAnalysis
LLVM_ABI DWARFCFIAnalysis(MCContext *Context, MCInstrInfo const &MCII, bool IsEH, ArrayRef< MCCFIInstruction > Prologue)
Definition
DWARFCFIAnalysis.cpp:83
llvm::DWARFCFIState
This class is used to maintain a CFI state, referred to as an unwinding row, during CFI analysis.
Definition
DWARFCFIState.h:30
llvm::MCContext
Context object for machine code objects.
Definition
MCContext.h:83
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition
MCInst.h:188
llvm::MCInstrInfo
Interface to description of machine instruction set.
Definition
MCInstrInfo.h:27
llvm::MCRegisterInfo
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Definition
MCRegisterInfo.h:150
llvm::SmallSet
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition
SmallSet.h:133
llvm::dwarf::UnwindRow
A class that represents a single row in the unwind table that is decoded by parsing the DWARF Call Fr...
Definition
DWARFUnwindTable.h:231
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition
AddressRanges.h:18
llvm::DWARFRegNum
uint32_t DWARFRegNum
Definition
DWARFCFIState.h:25
Generated on
for LLVM by
1.14.0