[clang] 5251678 - [X86][CET] Add Diags for targets pre to i686 for `-fcf-protection`

Phoebe Wang via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 3 21:38:39 PDT 2022


Author: Phoebe Wang
Date: 2022-11-04T12:38:29+08:00
New Revision: 52516782972730ff065a34123a9d8876da08c254

URL: https://github.com/llvm/llvm-project/commit/52516782972730ff065a34123a9d8876da08c254
DIFF: https://github.com/llvm/llvm-project/commit/52516782972730ff065a34123a9d8876da08c254.diff

LOG: [X86][CET] Add Diags for targets pre to i686 for `-fcf-protection`

Intel Control-flow Enforcement Technology (CET) provides new instructions `endbr32/64` for the indirect branch control. They are NOPs on i686 and new targets. We need to check for that in case it crashes on older targets.

Fixes #58737

Reviewed By: nickdesaulniers

Differential Revision: https://reviews.llvm.org/D137317

Added: 
    

Modified: 
    clang/lib/Basic/Targets/X86.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 71ab94601858..d4e6097f152f 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -241,12 +241,16 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public TargetInfo {
 
   bool
   checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override {
-    return true;
+    if (CPU == llvm::X86::CK_None || CPU >= llvm::X86::CK_PentiumPro)
+      return true;
+    return TargetInfo::checkCFProtectionReturnSupported(Diags);
   };
 
   bool
   checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const override {
-    return true;
+    if (CPU == llvm::X86::CK_None || CPU >= llvm::X86::CK_PentiumPro)
+      return true;
+    return TargetInfo::checkCFProtectionBranchSupported(Diags);
   };
 
   virtual bool validateOperandSize(const llvm::StringMap<bool> &FeatureMap,


        


More information about the cfe-commits mailing list