From 42287255d38bf493b5731396b99bc9cd7b1baba4 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Fri, 19 Nov 2021 10:29:27 +0800 Subject: [PATCH] Build system: Allow user to enable Intel CET MSVC: https://docs.microsoft.com/en-us/cpp/build/reference/guard-enable-eh-continuation-metadata?view=msvc-170 https://docs.microsoft.com/en-us/cpp/build/reference/cetcompat?view=msvc-170 GCC: https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/Instrumentation-Options.html Clang: Don't know where's the documentation but should use the same parameter with GCC. Change-Id: I654618e45743a5ad1394c930932b9d0044572725 Reviewed-by: Alexandru Croitor Reviewed-by: Thiago Macieira --- cmake/QtInternalTargets.cmake | 15 +++++++++++++++ config_help.txt | 1 + configure.cmake | 3 ++- qt_cmdline.cmake | 1 + 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cmake/QtInternalTargets.cmake b/cmake/QtInternalTargets.cmake index b60a8b26019..78c5ec898e3 100644 --- a/cmake/QtInternalTargets.cmake +++ b/cmake/QtInternalTargets.cmake @@ -278,6 +278,21 @@ if (GCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "9.2") target_compile_options(PlatformCommonInternal INTERFACE $<$:-Wsuggest-override>) endif() +if(QT_FEATURE_intelcet) + if(MSVC) + target_compile_options(PlatformCommonInternal INTERFACE + -guard:ehcont + ) + target_link_options(PlatformCommonInternal INTERFACE + -guard:ehcont -CETCOMPAT + ) + else() + target_compile_options(PlatformCommonInternal INTERFACE + -fcf-protection + ) + endif() +endif() + if(QT_FEATURE_force_asserts) target_compile_definitions(PlatformCommonInternal INTERFACE QT_FORCE_ASSERTS) endif() diff --git a/config_help.txt b/config_help.txt index fc978bb446e..2a97f525ea0 100644 --- a/config_help.txt +++ b/config_help.txt @@ -137,6 +137,7 @@ Build options: -pch ................. Use precompiled headers [auto] -ltcg ................ Use Link Time Code Generation [no] + -intelcet ............ Use Intel Control-flow Enforcement Technology [no] -linker [bfd,gold,lld,mold] Force use of the GNU ld, GNU gold, LLVM/LLD or mold linker instead of default one (GCC and clang only) diff --git a/configure.cmake b/configure.cmake index 2274f1554de..30d9551b6b3 100644 --- a/configure.cmake +++ b/configure.cmake @@ -1034,7 +1034,7 @@ qt_feature("relocatable" PRIVATE ) qt_feature("intelcet" PRIVATE LABEL "Using Intel CET" - CONDITION TEST_intelcet + CONDITION ( INPUT_intelcet STREQUAL yes ) OR TEST_intelcet ) qt_configure_add_summary_build_type_and_config() qt_configure_add_summary_section(NAME "Build options") @@ -1085,6 +1085,7 @@ qt_configure_add_summary_entry( qt_configure_add_summary_entry(ARGS "relocatable") qt_configure_add_summary_entry(ARGS "precompile_header") qt_configure_add_summary_entry(ARGS "ltcg") +qt_configure_add_summary_entry(ARGS "intelcet") qt_configure_add_summary_section(NAME "Target compiler supports") qt_configure_add_summary_entry( TYPE "featureList" diff --git a/qt_cmdline.cmake b/qt_cmdline.cmake index d5774bb14cf..a6dd809bf64 100644 --- a/qt_cmdline.cmake +++ b/qt_cmdline.cmake @@ -67,6 +67,7 @@ qt_commandline_option(incredibuild-xge TYPE boolean NAME incredibuild_xge) qt_commandline_option(libudev TYPE boolean) qt_commandline_option(linker TYPE optionalString VALUES bfd gold lld mold) qt_commandline_option(ltcg TYPE boolean) +qt_commandline_option(intelcet TYPE boolean) # special case begin qt_commandline_option(make TYPE addString VALUES examples libs tests tools benchmarks manual-tests minimal-static-tests)