[PATCH] D46881: [X86][CET] Changing -fcf-protection behavior to comply with gcc (clang part)
This revision was automatically updated to reflect the committed changes. Closed by commit rC332704: This patch aims to match the changes introduced (authored by aivchenk, committed by ). Changed prior to commit: https://reviews.llvm.org/D46881?vs=147292=147476#toc Repository: rC Clang https://reviews.llvm.org/D46881 Files: docs/ClangCommandLineReference.rst include/clang/Basic/DiagnosticCommonKinds.td include/clang/Basic/TargetInfo.h include/clang/Driver/Options.td lib/Basic/TargetInfo.cpp lib/Basic/Targets/X86.cpp lib/Basic/Targets/X86.h lib/Frontend/CompilerInvocation.cpp test/CodeGen/attributes.c test/CodeGen/builtins-x86.c test/CodeGen/x86-cf-protection.c test/Driver/x86-target-features.c test/Preprocessor/x86_target_features.c test/Sema/attr-nocf_check.c test/Sema/attr-nocf_check.cpp Index: lib/Basic/TargetInfo.cpp === --- lib/Basic/TargetInfo.cpp +++ lib/Basic/TargetInfo.cpp @@ -14,6 +14,7 @@ #include "clang/Basic/TargetInfo.h" #include "clang/Basic/AddressSpaces.h" #include "clang/Basic/CharInfo.h" +#include "clang/Basic/Diagnostic.h" #include "clang/Basic/LangOptions.h" #include "llvm/ADT/APFloat.h" #include "llvm/ADT/STLExtras.h" @@ -115,6 +116,18 @@ // Out of line virtual dtor for TargetInfo. TargetInfo::~TargetInfo() {} +bool +TargetInfo::checkCFProtectionBranchSupported(DiagnosticsEngine ) const { + Diags.Report(diag::err_opt_not_valid_on_target) << "cf-protection=branch"; + return false; +} + +bool +TargetInfo::checkCFProtectionReturnSupported(DiagnosticsEngine ) const { + Diags.Report(diag::err_opt_not_valid_on_target) << "cf-protection=return"; + return false; +} + /// getTypeName - Return the user string for the specified integer type enum. /// For example, SignedShort -> "short". const char *TargetInfo::getTypeName(IntType T) { Index: lib/Basic/Targets/X86.h === --- lib/Basic/Targets/X86.h +++ lib/Basic/Targets/X86.h @@ -81,7 +81,6 @@ bool HasSHA = false; bool HasMPX = false; bool HasSHSTK = false; - bool HasIBT = false; bool HasSGX = false; bool HasCX16 = false; bool HasFXSR = false; @@ -171,10 +170,15 @@ bool validateInputSize(StringRef Constraint, unsigned Size) const override; virtual bool - checkCFProtectionReturnSupported(DiagnosticsEngine ) const override; + checkCFProtectionReturnSupported(DiagnosticsEngine ) const override { +return true; + }; virtual bool - checkCFProtectionBranchSupported(DiagnosticsEngine ) const override; + checkCFProtectionBranchSupported(DiagnosticsEngine ) const override { +return true; + }; + virtual bool validateOperandSize(StringRef Constraint, unsigned Size) const; Index: lib/Basic/Targets/X86.cpp === --- lib/Basic/Targets/X86.cpp +++ lib/Basic/Targets/X86.cpp @@ -102,26 +102,6 @@ return false; } -bool X86TargetInfo::checkCFProtectionReturnSupported( -DiagnosticsEngine ) const { - if (HasSHSTK) -return true; - - Diags.Report(diag::err_opt_not_valid_without_opt) << "cf-protection=return" -<< "-mshstk"; - return false; -} - -bool X86TargetInfo::checkCFProtectionBranchSupported( -DiagnosticsEngine ) const { - if (HasIBT) -return true; - - Diags.Report(diag::err_opt_not_valid_without_opt) << "cf-protection=branch" -<< "-mibt"; - return false; -} - bool X86TargetInfo::initFeatureMap( llvm::StringMap , DiagnosticsEngine , StringRef CPU, const std::vector ) const { @@ -781,8 +761,6 @@ HasMPX = true; } else if (Feature == "+shstk") { HasSHSTK = true; -} else if (Feature == "+ibt") { - HasIBT = true; } else if (Feature == "+movbe") { HasMOVBE = true; } else if (Feature == "+sgx") { @@ -1175,8 +1153,6 @@ Builder.defineMacro("__MPX__"); if (HasSHSTK) Builder.defineMacro("__SHSTK__"); - if (HasIBT) -Builder.defineMacro("__IBT__"); if (HasSGX) Builder.defineMacro("__SGX__"); if (HasPREFETCHWT1) @@ -1394,7 +1370,6 @@ .Case("fsgsbase", HasFSGSBASE) .Case("fxsr", HasFXSR) .Case("gfni", HasGFNI) - .Case("ibt", HasIBT) .Case("lwp", HasLWP) .Case("lzcnt", HasLZCNT) .Case("mm3dnow", MMX3DNowLevel >= AMD3DNow) Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -2829,6 +2829,17 @@ } } + // Add the __CET__ macro if a CFProtection option is set. + if (const Arg *A = Args.getLastArg(OPT_fcf_protection_EQ)) { +StringRef Name = A->getValue(); +if (Name == "branch") + Opts.addMacroDef("__CET__=1"); +else if (Name == "return") +
[PATCH] D46881: [X86][CET] Changing -fcf-protection behavior to comply with gcc (clang part)
craig.topper added a comment. LGTM https://reviews.llvm.org/D46881 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46881: [X86][CET] Changing -fcf-protection behavior to comply with gcc (clang part)
mike.dvoretsky updated this revision to Diff 147292. mike.dvoretsky added a comment. Removed the unused HasIBT variable declaration from X86.h. https://reviews.llvm.org/D46881 Files: clang/docs/ClangCommandLineReference.rst clang/include/clang/Basic/DiagnosticCommonKinds.td clang/include/clang/Basic/TargetInfo.h clang/include/clang/Driver/Options.td clang/lib/Basic/TargetInfo.cpp clang/lib/Basic/Targets/X86.cpp clang/lib/Basic/Targets/X86.h clang/lib/Frontend/CompilerInvocation.cpp clang/test/CodeGen/attributes.c clang/test/CodeGen/builtins-x86.c clang/test/CodeGen/x86-cf-protection.c clang/test/Driver/x86-target-features.c clang/test/Preprocessor/x86_target_features.c clang/test/Sema/attr-nocf_check.c clang/test/Sema/attr-nocf_check.cpp Index: clang/test/Sema/attr-nocf_check.cpp === --- clang/test/Sema/attr-nocf_check.cpp +++ clang/test/Sema/attr-nocf_check.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple=i386-unknown-unknown -verify -fcf-protection=branch -target-feature +ibt -std=c++11 -fsyntax-only %s +// RUN: %clang_cc1 -triple=i386-unknown-unknown -verify -fcf-protection=branch -std=c++11 -fsyntax-only %s // Function pointer definition. [[gnu::nocf_check]] typedef void (*FuncPointerWithNoCfCheck)(void); // no-warning Index: clang/test/Sema/attr-nocf_check.c === --- clang/test/Sema/attr-nocf_check.c +++ clang/test/Sema/attr-nocf_check.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -verify -fcf-protection=branch -target-feature +ibt -fsyntax-only %s +// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -verify -fcf-protection=branch -fsyntax-only %s // Function pointer definition. typedef void (*FuncPointerWithNoCfCheck)(void) __attribute__((nocf_check)); // no-warning Index: clang/test/Preprocessor/x86_target_features.c === --- clang/test/Preprocessor/x86_target_features.c +++ clang/test/Preprocessor/x86_target_features.c @@ -380,10 +380,6 @@ // SHSTK: #define __SHSTK__ 1 -// RUN: %clang -target i386-unknown-unknown -mibt -x c -E -dM -o - %s | FileCheck -match-full-lines --check-prefix=IBT %s - -// IBT: #define __IBT__ 1 - // RUN: %clang -target i386-unknown-unknown -march=atom -mrdseed -x c -E -dM -o - %s | FileCheck -match-full-lines --check-prefix=RDSEED %s // RDSEED: #define __RDSEED__ 1 Index: clang/test/Driver/x86-target-features.c === --- clang/test/Driver/x86-target-features.c +++ clang/test/Driver/x86-target-features.c @@ -80,11 +80,6 @@ // CETSS: "-target-feature" "+shstk" // NO-CETSS: "-target-feature" "-shstk" -// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mibt %s -### -o %t.o 2>&1 | FileCheck -check-prefix=CETIBT %s -// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-ibt %s -### -o %t.o 2>&1 | FileCheck -check-prefix=NO-CETIBT %s -// CETIBT: "-target-feature" "+ibt" -// NO-CETIBT: "-target-feature" "-ibt" - // RUN: %clang -target i386-unknown-linux-gnu -march=i386 -msgx %s -### -o %t.o 2>&1 | FileCheck -check-prefix=SGX %s // RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-sgx %s -### -o %t.o 2>&1 | FileCheck -check-prefix=NO-SGX %s // SGX: "-target-feature" "+sgx" Index: clang/test/CodeGen/x86-cf-protection.c === --- clang/test/CodeGen/x86-cf-protection.c +++ clang/test/CodeGen/x86-cf-protection.c @@ -1,6 +1,8 @@ -// RUN: not %clang_cc1 -fsyntax-only -S -o %t -triple i386-unknown-unknown -fcf-protection=return %s 2>&1 | FileCheck %s --check-prefix=RETURN -// RUN: not %clang_cc1 -fsyntax-only -S -o %t -triple i386-unknown-unknown -fcf-protection=branch %s 2>&1 | FileCheck %s --check-prefix=BRANCH +// RUN: %clang -target i386-unknown-unknown -x c -E -dM -o - -fcf-protection=return %s | FileCheck %s --check-prefix=RETURN +// RUN: %clang -target i386-unknown-unknown -x c -E -dM -o - -fcf-protection=branch %s | FileCheck %s --check-prefix=BRANCH +// RUN: %clang -target i386-unknown-unknown -x c -E -dM -o - -fcf-protection=full %s | FileCheck %s --check-prefix=FULL -// RETURN: error: option 'cf-protection=return' cannot be specified without '-mshstk' -// BRANCH: error: option 'cf-protection=branch' cannot be specified without '-mibt' +// RETURN: #define __CET__ 2 +// BRANCH: #define __CET__ 1 +// FULL: #define __CET__ 3 void foo() {} Index: clang/test/CodeGen/builtins-x86.c === --- clang/test/CodeGen/builtins-x86.c +++ clang/test/CodeGen/builtins-x86.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -DUSE_64 -triple x86_64-unknown-unknown -target-feature +fxsr -target-feature +avx -target-feature +xsaveopt -target-feature +xsaves -target-feature +xsavec -target-feature +mwaitx -target-feature +clzero
[PATCH] D46881: [X86][CET] Changing -fcf-protection behavior to comply with gcc (clang part)
craig.topper accepted this revision. craig.topper added a comment. This revision is now accepted and ready to land. LGTM Repository: rC Clang https://reviews.llvm.org/D46881 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46881: [X86][CET] Changing -fcf-protection behavior to comply with gcc (clang part)
mike.dvoretsky created this revision. mike.dvoretsky added a reviewer: craig.topper. Herald added a subscriber: cfe-commits. This patch aims to match the changes introduced in gcc by https://gcc.gnu.org/ml/gcc-cvs/2018-04/msg00534.html. The -mibt feature flag is being removed, and the -fcf-protection option now also defines a __CET__ macro and causes errors when used on non-X86 targets, while X86 targets no longer check for -mibt and -mshstk to determine if -fcf-protection is supported. -mshstk is now used only to determine availability of shadow stack intrinsics. Comes with an LLVM patch. Repository: rC Clang https://reviews.llvm.org/D46881 Files: clang/docs/ClangCommandLineReference.rst clang/include/clang/Basic/DiagnosticCommonKinds.td clang/include/clang/Basic/TargetInfo.h clang/include/clang/Driver/Options.td clang/lib/Basic/TargetInfo.cpp clang/lib/Basic/Targets/X86.cpp clang/lib/Basic/Targets/X86.h clang/lib/Frontend/CompilerInvocation.cpp clang/test/CodeGen/attributes.c clang/test/CodeGen/builtins-x86.c clang/test/CodeGen/x86-cf-protection.c clang/test/Driver/x86-target-features.c clang/test/Preprocessor/x86_target_features.c clang/test/Sema/attr-nocf_check.c clang/test/Sema/attr-nocf_check.cpp Index: clang/test/Sema/attr-nocf_check.cpp === --- clang/test/Sema/attr-nocf_check.cpp +++ clang/test/Sema/attr-nocf_check.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple=i386-unknown-unknown -verify -fcf-protection=branch -target-feature +ibt -std=c++11 -fsyntax-only %s +// RUN: %clang_cc1 -triple=i386-unknown-unknown -verify -fcf-protection=branch -std=c++11 -fsyntax-only %s // Function pointer definition. [[gnu::nocf_check]] typedef void (*FuncPointerWithNoCfCheck)(void); // no-warning Index: clang/test/Sema/attr-nocf_check.c === --- clang/test/Sema/attr-nocf_check.c +++ clang/test/Sema/attr-nocf_check.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -verify -fcf-protection=branch -target-feature +ibt -fsyntax-only %s +// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -verify -fcf-protection=branch -fsyntax-only %s // Function pointer definition. typedef void (*FuncPointerWithNoCfCheck)(void) __attribute__((nocf_check)); // no-warning Index: clang/test/Preprocessor/x86_target_features.c === --- clang/test/Preprocessor/x86_target_features.c +++ clang/test/Preprocessor/x86_target_features.c @@ -380,10 +380,6 @@ // SHSTK: #define __SHSTK__ 1 -// RUN: %clang -target i386-unknown-unknown -mibt -x c -E -dM -o - %s | FileCheck -match-full-lines --check-prefix=IBT %s - -// IBT: #define __IBT__ 1 - // RUN: %clang -target i386-unknown-unknown -march=atom -mrdseed -x c -E -dM -o - %s | FileCheck -match-full-lines --check-prefix=RDSEED %s // RDSEED: #define __RDSEED__ 1 Index: clang/test/Driver/x86-target-features.c === --- clang/test/Driver/x86-target-features.c +++ clang/test/Driver/x86-target-features.c @@ -80,11 +80,6 @@ // CETSS: "-target-feature" "+shstk" // NO-CETSS: "-target-feature" "-shstk" -// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mibt %s -### -o %t.o 2>&1 | FileCheck -check-prefix=CETIBT %s -// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-ibt %s -### -o %t.o 2>&1 | FileCheck -check-prefix=NO-CETIBT %s -// CETIBT: "-target-feature" "+ibt" -// NO-CETIBT: "-target-feature" "-ibt" - // RUN: %clang -target i386-unknown-linux-gnu -march=i386 -msgx %s -### -o %t.o 2>&1 | FileCheck -check-prefix=SGX %s // RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-sgx %s -### -o %t.o 2>&1 | FileCheck -check-prefix=NO-SGX %s // SGX: "-target-feature" "+sgx" Index: clang/test/CodeGen/x86-cf-protection.c === --- clang/test/CodeGen/x86-cf-protection.c +++ clang/test/CodeGen/x86-cf-protection.c @@ -1,6 +1,8 @@ -// RUN: not %clang_cc1 -fsyntax-only -S -o %t -triple i386-unknown-unknown -fcf-protection=return %s 2>&1 | FileCheck %s --check-prefix=RETURN -// RUN: not %clang_cc1 -fsyntax-only -S -o %t -triple i386-unknown-unknown -fcf-protection=branch %s 2>&1 | FileCheck %s --check-prefix=BRANCH +// RUN: %clang -target i386-unknown-unknown -x c -E -dM -o - -fcf-protection=return %s | FileCheck %s --check-prefix=RETURN +// RUN: %clang -target i386-unknown-unknown -x c -E -dM -o - -fcf-protection=branch %s | FileCheck %s --check-prefix=BRANCH +// RUN: %clang -target i386-unknown-unknown -x c -E -dM -o - -fcf-protection=full %s | FileCheck %s --check-prefix=FULL -// RETURN: error: option 'cf-protection=return' cannot be specified without '-mshstk' -// BRANCH: error: option 'cf-protection=branch' cannot be specified without '-mibt' +// RETURN: #define __CET__ 2 +// BRANCH: #define