Skip to content

Commit fc91c70

Browse files
committed
Revert D135411 "Add generic KCFI operand bundle lowering"
This reverts commit eb2a57e. llvm/include/llvm/Transforms/Instrumentation/KCFI.h including llvm/CodeGen is a layering violation. We should use an approach where Instrumementation/ doesn't need to include CodeGen/. Sorry for not spotting this in the review.
1 parent c9320bc commit fc91c70

File tree

12 files changed

+5
-232
lines changed

12 files changed

+5
-232
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
#include "llvm/Transforms/Instrumentation/GCOVProfiler.h"
7373
#include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h"
7474
#include "llvm/Transforms/Instrumentation/InstrProfiling.h"
75-
#include "llvm/Transforms/Instrumentation/KCFI.h"
7675
#include "llvm/Transforms/Instrumentation/MemProfiler.h"
7776
#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
7877
#include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
@@ -645,31 +644,6 @@ static OptimizationLevel mapToLevel(const CodeGenOptions &Opts) {
645644
}
646645
}
647646

648-
static void addKCFIPass(TargetMachine *TM, const Triple &TargetTriple,
649-
const LangOptions &LangOpts, PassBuilder &PB) {
650-
// If the back-end supports KCFI operand bundle lowering, skip KCFIPass.
651-
if (TargetTriple.getArch() == llvm::Triple::x86_64 ||
652-
TargetTriple.isAArch64(64))
653-
return;
654-
655-
// Ensure we lower KCFI operand bundles with -O0.
656-
PB.registerOptimizerLastEPCallback(
657-
[&, TM](ModulePassManager &MPM, OptimizationLevel Level) {
658-
if (Level == OptimizationLevel::O0 &&
659-
LangOpts.Sanitize.has(SanitizerKind::KCFI))
660-
MPM.addPass(createModuleToFunctionPassAdaptor(KCFIPass(TM)));
661-
});
662-
663-
// When optimizations are requested, run KCIFPass after InstCombine to
664-
// avoid unnecessary checks.
665-
PB.registerPeepholeEPCallback(
666-
[&, TM](FunctionPassManager &FPM, OptimizationLevel Level) {
667-
if (Level != OptimizationLevel::O0 &&
668-
LangOpts.Sanitize.has(SanitizerKind::KCFI))
669-
FPM.addPass(KCFIPass(TM));
670-
});
671-
}
672-
673647
static void addSanitizers(const Triple &TargetTriple,
674648
const CodeGenOptions &CodeGenOpts,
675649
const LangOptions &LangOpts, PassBuilder &PB) {
@@ -972,10 +946,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
972946

973947
// Don't add sanitizers if we are here from ThinLTO PostLink. That already
974948
// done on PreLink stage.
975-
if (!IsThinLTOPostLink) {
949+
if (!IsThinLTOPostLink)
976950
addSanitizers(TargetTriple, CodeGenOpts, LangOpts, PB);
977-
addKCFIPass(TM.get(), TargetTriple, LangOpts, PB);
978-
}
979951

980952
if (Optional<GCOVOptions> Options = getGCOVOptions(CodeGenOpts, LangOpts))
981953
PB.registerPipelineStartEPCallback(

clang/lib/Driver/ToolChain.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,14 +1089,17 @@ SanitizerMask ToolChain::getSupportedSanitizers() const {
10891089
~SanitizerKind::Function) |
10901090
(SanitizerKind::CFI & ~SanitizerKind::CFIICall) |
10911091
SanitizerKind::CFICastStrict | SanitizerKind::FloatDivideByZero |
1092-
SanitizerKind::KCFI | SanitizerKind::UnsignedIntegerOverflow |
1092+
SanitizerKind::UnsignedIntegerOverflow |
10931093
SanitizerKind::UnsignedShiftBase | SanitizerKind::ImplicitConversion |
10941094
SanitizerKind::Nullability | SanitizerKind::LocalBounds;
10951095
if (getTriple().getArch() == llvm::Triple::x86 ||
10961096
getTriple().getArch() == llvm::Triple::x86_64 ||
10971097
getTriple().getArch() == llvm::Triple::arm || getTriple().isWasm() ||
10981098
getTriple().isAArch64() || getTriple().isRISCV())
10991099
Res |= SanitizerKind::CFIICall;
1100+
if (getTriple().getArch() == llvm::Triple::x86_64 ||
1101+
getTriple().isAArch64(64))
1102+
Res |= SanitizerKind::KCFI;
11001103
if (getTriple().getArch() == llvm::Triple::x86_64 ||
11011104
getTriple().isAArch64(64) || getTriple().isRISCV())
11021105
Res |= SanitizerKind::ShadowCallStack;

llvm/include/llvm/InitializePasses.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ void initializeLowerInvokeLegacyPassPass(PassRegistry&);
258258
void initializeLowerSwitchLegacyPassPass(PassRegistry &);
259259
void initializeLowerMatrixIntrinsicsLegacyPassPass(PassRegistry &);
260260
void initializeLowerMatrixIntrinsicsMinimalLegacyPassPass(PassRegistry &);
261-
void initializeKCFIPass(PassRegistry &);
262261
void initializeMIRAddFSDiscriminatorsPass(PassRegistry &);
263262
void initializeMIRCanonicalizerPass(PassRegistry &);
264263
void initializeMIRNamerPass(PassRegistry &);

llvm/include/llvm/Transforms/Instrumentation/KCFI.h

Lines changed: 0 additions & 31 deletions
This file was deleted.

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@
137137
#include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h"
138138
#include "llvm/Transforms/Instrumentation/InstrOrderFile.h"
139139
#include "llvm/Transforms/Instrumentation/InstrProfiling.h"
140-
#include "llvm/Transforms/Instrumentation/KCFI.h"
141140
#include "llvm/Transforms/Instrumentation/MemProfiler.h"
142141
#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
143142
#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"

llvm/lib/Passes/PassRegistry.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,6 @@ FUNCTION_PASS("nary-reassociate", NaryReassociatePass())
322322
FUNCTION_PASS("newgvn", NewGVNPass())
323323
FUNCTION_PASS("jump-threading", JumpThreadingPass())
324324
FUNCTION_PASS("partially-inline-libcalls", PartiallyInlineLibCallsPass())
325-
FUNCTION_PASS("kcfi", KCFIPass(TM))
326325
FUNCTION_PASS("lcssa", LCSSAPass())
327326
FUNCTION_PASS("loop-data-prefetch", LoopDataPrefetchPass())
328327
FUNCTION_PASS("loop-load-elim", LoopLoadEliminationPass())

llvm/lib/Transforms/Instrumentation/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ add_llvm_component_library(LLVMInstrumentation
1111
Instrumentation.cpp
1212
InstrOrderFile.cpp
1313
InstrProfiling.cpp
14-
KCFI.cpp
1514
PGOInstrumentation.cpp
1615
PGOMemOPSizeOpt.cpp
1716
PoisonChecking.cpp

llvm/lib/Transforms/Instrumentation/KCFI.cpp

Lines changed: 0 additions & 115 deletions
This file was deleted.

llvm/test/Transforms/KCFI/kcfi-patchable-function-prefix.ll

Lines changed: 0 additions & 12 deletions
This file was deleted.

llvm/test/Transforms/KCFI/kcfi-supported.ll

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)