18
18
#include " X86.h"
19
19
#include " X86InstrInfo.h"
20
20
#include " X86Subtarget.h"
21
- #include " X86TargetMachine.h"
22
21
#include " llvm/ADT/Statistic.h"
23
22
#include " llvm/CodeGen/MachineFunctionPass.h"
24
23
#include " llvm/CodeGen/MachineInstrBuilder.h"
@@ -103,16 +102,7 @@ bool X86IndirectBranchTrackingPass::runOnMachineFunction(MachineFunction &MF) {
103
102
// Check that the cf-protection-branch is enabled.
104
103
Metadata *isCFProtectionSupported =
105
104
MF.getMMI ().getModule ()->getModuleFlag (" cf-protection-branch" );
106
- // NB: We need to enable IBT in jitted code if JIT compiler is CET
107
- // enabled.
108
- const X86TargetMachine *TM =
109
- static_cast <const X86TargetMachine *>(&MF.getTarget ());
110
- #ifdef __CET__
111
- bool isJITwithCET = TM->isJIT ();
112
- #else
113
- bool isJITwithCET = false ;
114
- #endif
115
- if (!isCFProtectionSupported && !IndirectBranchTracking && !isJITwithCET)
105
+ if (!isCFProtectionSupported && !IndirectBranchTracking)
116
106
return false ;
117
107
118
108
// True if the current MF was changed and false otherwise.
@@ -121,11 +111,10 @@ bool X86IndirectBranchTrackingPass::runOnMachineFunction(MachineFunction &MF) {
121
111
TII = SubTarget.getInstrInfo ();
122
112
EndbrOpcode = SubTarget.is64Bit () ? X86::ENDBR64 : X86::ENDBR32;
123
113
124
- // Large code model, non-internal function or function whose address
125
- // was taken, can be accessed through indirect calls. Mark the first
126
- // BB with ENDBR instruction unless nocf_check attribute is used.
127
- if ((TM->getCodeModel () == CodeModel::Large ||
128
- MF.getFunction ().hasAddressTaken () ||
114
+ // Non-internal function or function whose address was taken, can be
115
+ // accessed through indirect calls. Mark the first BB with ENDBR instruction
116
+ // unless nocf_check attribute is used.
117
+ if ((MF.getFunction ().hasAddressTaken () ||
129
118
!MF.getFunction ().hasLocalLinkage ()) &&
130
119
!MF.getFunction ().doesNoCfCheck ()) {
131
120
auto MBB = MF.begin ();
@@ -147,8 +136,8 @@ bool X86IndirectBranchTrackingPass::runOnMachineFunction(MachineFunction &MF) {
147
136
Changed |= addENDBR (MBB, std::next (I));
148
137
149
138
if (EHPadIBTNeeded && I->isEHLabel ()) {
150
- Changed |= addENDBR (MBB, std::next (I));
151
- EHPadIBTNeeded = false ;
139
+ Changed |= addENDBR (MBB, std::next (I));
140
+ EHPadIBTNeeded = false ;
152
141
}
153
142
}
154
143
}
0 commit comments