summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuhang Zhao <2546789017@qq.com>2020-11-03 12:02:01 +0800
committerYuhang Zhao <2546789017@qq.com>2020-12-07 22:25:43 +0800
commit886db3a2f3600d15ceb2447c9502f20ce9b3f000 (patch)
treef81e6f88a67b0fabb1f43a5660daa2823dd1ea1a
parent509c25752112583e6bc997e8c9442f6b69136816 (diff)
MSVC: Enable control flow guard for release builds
This makes the applications and libraries more safe and won't cause any binary incompatibility. It's not supported for MSVC 2015, but since we only support MSVC 2019 or later in Qt6, it's safe to use this parameter. The "-guard:cf" parameter is supported by clang-cl and intel-cl as well, MinGW doesn't support it. [1] https://docs.microsoft.com/en-us/cpp/build/reference/guard-enable-control-flow-guard?view=msvc-160 [2] https://docs.microsoft.com/en-us/cpp/build/reference/guard-enable-guard-checks?view=msvc-160 Change-Id: I7b035b4b0f22617a7f3c067cddde0bed2e13dd1c Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r--cmake/QtInternalTargets.cmake8
-rw-r--r--mkspecs/features/qt_module.prf9
2 files changed, 15 insertions, 2 deletions
diff --git a/cmake/QtInternalTargets.cmake b/cmake/QtInternalTargets.cmake
index 2fd99c7be3..7dbaed0d31 100644
--- a/cmake/QtInternalTargets.cmake
+++ b/cmake/QtInternalTargets.cmake
@@ -167,7 +167,7 @@ if (MSVC)
-FS
-Zc:rvalueCast
-Zc:inline
- )
+ )
endif()
if (MSVC_VERSION GREATER_EQUAL 1899)
target_compile_options(PlatformCommonInternal INTERFACE
@@ -192,9 +192,13 @@ if (MSVC)
target_compile_options(PlatformCommonInternal INTERFACE -Zc:wchar_t)
+ target_compile_options(PlatformCommonInternal INTERFACE
+ $<$<NOT:$<CONFIG:Debug>>:-guard:cf>
+ )
+
target_link_options(PlatformCommonInternal INTERFACE
-DYNAMICBASE -NXCOMPAT
- $<$<NOT:$<CONFIG:Debug>>:-OPT:REF -OPT:ICF>
+ $<$<NOT:$<CONFIG:Debug>>:-OPT:REF -OPT:ICF -GUARD:CF>
)
endif()
diff --git a/mkspecs/features/qt_module.prf b/mkspecs/features/qt_module.prf
index 3cacc8dfde..62d225b14d 100644
--- a/mkspecs/features/qt_module.prf
+++ b/mkspecs/features/qt_module.prf
@@ -336,4 +336,13 @@ win32 {
}
DEFINES *= QT_DEPRECATED_WARNINGS_SINCE=0x060000
+msvc {
+ QMAKE_CFLAGS_RELEASE += -guard:cf
+ QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -guard:cf
+ QMAKE_CXXFLAGS_RELEASE += -guard:cf
+ QMAKE_CXXFLAGS_RELEASE_WITH_DEBUGINFO += -guard:cf
+ QMAKE_LFLAGS_RELEASE += /GUARD:CF
+ QMAKE_LFLAGS_RELEASE_WITH_DEBUGINFO += /GUARD:CF
+}
+
TARGET = $$qt5LibraryTarget($$TARGET$$QT_LIBINFIX) # Do this towards the end