diff options
author | Fangrui Song <i@maskray.me> | 2022-11-17 22:45:29 +0000 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2022-11-17 22:45:30 +0000 |
commit | fc91c705937d7ba3b92da38f3a883dde720c41f2 (patch) | |
tree | 6ba2f4a461fd181645ecb6a8c2ddfbd3cb7ab704 /clang/lib | |
parent | c9320bc87121af2a198f174c8d58f75295efbbd7 (diff) | |
download | llvm-fc91c705937d7ba3b92da38f3a883dde720c41f2.zip llvm-fc91c705937d7ba3b92da38f3a883dde720c41f2.tar.gz llvm-fc91c705937d7ba3b92da38f3a883dde720c41f2.tar.bz2 |
Revert D135411 "Add generic KCFI operand bundle lowering"
This reverts commit eb2a57ebc7aaad551af30462097a9e06c96db925.
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.
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/CodeGen/BackendUtil.cpp | 30 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChain.cpp | 5 |
2 files changed, 5 insertions, 30 deletions
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 7082fb7..8498ca2 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -72,7 +72,6 @@ #include "llvm/Transforms/Instrumentation/GCOVProfiler.h" #include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h" #include "llvm/Transforms/Instrumentation/InstrProfiling.h" -#include "llvm/Transforms/Instrumentation/KCFI.h" #include "llvm/Transforms/Instrumentation/MemProfiler.h" #include "llvm/Transforms/Instrumentation/MemorySanitizer.h" #include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h" @@ -645,31 +644,6 @@ static OptimizationLevel mapToLevel(const CodeGenOptions &Opts) { } } -static void addKCFIPass(TargetMachine *TM, const Triple &TargetTriple, - const LangOptions &LangOpts, PassBuilder &PB) { - // If the back-end supports KCFI operand bundle lowering, skip KCFIPass. - if (TargetTriple.getArch() == llvm::Triple::x86_64 || - TargetTriple.isAArch64(64)) - return; - - // Ensure we lower KCFI operand bundles with -O0. - PB.registerOptimizerLastEPCallback( - [&, TM](ModulePassManager &MPM, OptimizationLevel Level) { - if (Level == OptimizationLevel::O0 && - LangOpts.Sanitize.has(SanitizerKind::KCFI)) - MPM.addPass(createModuleToFunctionPassAdaptor(KCFIPass(TM))); - }); - - // When optimizations are requested, run KCIFPass after InstCombine to - // avoid unnecessary checks. - PB.registerPeepholeEPCallback( - [&, TM](FunctionPassManager &FPM, OptimizationLevel Level) { - if (Level != OptimizationLevel::O0 && - LangOpts.Sanitize.has(SanitizerKind::KCFI)) - FPM.addPass(KCFIPass(TM)); - }); -} - static void addSanitizers(const Triple &TargetTriple, const CodeGenOptions &CodeGenOpts, const LangOptions &LangOpts, PassBuilder &PB) { @@ -972,10 +946,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline( // Don't add sanitizers if we are here from ThinLTO PostLink. That already // done on PreLink stage. - if (!IsThinLTOPostLink) { + if (!IsThinLTOPostLink) addSanitizers(TargetTriple, CodeGenOpts, LangOpts, PB); - addKCFIPass(TM.get(), TargetTriple, LangOpts, PB); - } if (Optional<GCOVOptions> Options = getGCOVOptions(CodeGenOpts, LangOpts)) PB.registerPipelineStartEPCallback( diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 1cb9506..695741f 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -1089,7 +1089,7 @@ SanitizerMask ToolChain::getSupportedSanitizers() const { ~SanitizerKind::Function) | (SanitizerKind::CFI & ~SanitizerKind::CFIICall) | SanitizerKind::CFICastStrict | SanitizerKind::FloatDivideByZero | - SanitizerKind::KCFI | SanitizerKind::UnsignedIntegerOverflow | + SanitizerKind::UnsignedIntegerOverflow | SanitizerKind::UnsignedShiftBase | SanitizerKind::ImplicitConversion | SanitizerKind::Nullability | SanitizerKind::LocalBounds; if (getTriple().getArch() == llvm::Triple::x86 || @@ -1098,6 +1098,9 @@ SanitizerMask ToolChain::getSupportedSanitizers() const { getTriple().isAArch64() || getTriple().isRISCV()) Res |= SanitizerKind::CFIICall; if (getTriple().getArch() == llvm::Triple::x86_64 || + getTriple().isAArch64(64)) + Res |= SanitizerKind::KCFI; + if (getTriple().getArch() == llvm::Triple::x86_64 || getTriple().isAArch64(64) || getTriple().isRISCV()) Res |= SanitizerKind::ShadowCallStack; if (getTriple().isAArch64(64)) |