Skip to content

Commit d6c0dfa

Browse files
authored
Add option to enable control flow guard during compilation (#1586)
Signed-off-by: Isaev, Ilya <[email protected]>
1 parent 4719ac1 commit d6c0dfa

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ option(TBB_CPF "Enable preview features of the library" OFF)
116116
option(TBB_FIND_PACKAGE "Enable search for external oneTBB using find_package instead of build from sources" OFF)
117117
option(TBB_DISABLE_HWLOC_AUTOMATIC_SEARCH "Disable HWLOC automatic search by pkg-config tool" ${CMAKE_CROSSCOMPILING})
118118
option(TBB_ENABLE_IPO "Enable Interprocedural Optimization (IPO) during the compilation" ON)
119+
option(TBB_CONTROL_FLOW_GUARD "Enable Control Flow Guard (CFG) during the compilation" OFF)
119120
option(TBB_FUZZ_TESTING "Enable fuzz testing" OFF)
120121
option(TBB_INSTALL "Enable installation" ON)
121122
option(TBB_FILE_TRIM "Enable __FILE__ trim" ON)
@@ -247,6 +248,10 @@ if (TBB_FILE_TRIM)
247248
file(TO_NATIVE_PATH ${TBB_RELATIVE_BIN_PATH} NATIVE_TBB_RELATIVE_BIN_PATH)
248249
endif ()
249250

251+
if (TBB_CONTROL_FLOW_GUARD)
252+
message(STATUS "Control Flow Guard (CFG) enabled")
253+
endif()
254+
250255
set(TBB_COMPILER_SETTINGS_FILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/compilers/${CMAKE_CXX_COMPILER_ID}.cmake)
251256
if (EXISTS ${TBB_COMPILER_SETTINGS_FILE})
252257
include(${TBB_COMPILER_SETTINGS_FILE})

cmake/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ TBB_INSTALL_VARS:BOOL - Enable auto-generated vars installation(packages generat
2020
TBB_VALGRIND_MEMCHECK:BOOL - Enable scan for memory leaks using Valgrind (OFF by default)
2121
TBB_DISABLE_HWLOC_AUTOMATIC_SEARCH - Disable HWLOC automatic search by pkg-config tool (OFF by default)
2222
TBB_ENABLE_IPO - Enable Interprocedural Optimization (IPO) during the compilation (ON by default)
23+
TBB_CONTROL_FLOW_GUARD:BOOL - Enable Control Flow Guard (CFG) during the compilation (OFF by default)
2324
TBB_BUILD_APPLE_FRAMEWORKS - Enable the Apple* frameworks instead of dylibs, only available on the Apple platform. (OFF by default)
2425
TBB_FILE_TRIM - Enable __FILE__ trim, replace a build-time full path with a relative path in the debug info and macro __FILE__; use it to make
2526
reproducible location-independent builds (ON by default)

cmake/compilers/MSVC.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ if (TBB_FILE_TRIM)
8383
"$<$<COMPILE_LANGUAGE:CXX>:/d1trimfile:${CMAKE_SOURCE_DIR}/>")
8484
endif()
8585

86+
if (TBB_CONTROL_FLOW_GUARD)
87+
set(TBB_LIB_COMPILE_FLAGS ${TBB_LIB_COMPILE_FLAGS} /guard:cf)
88+
set(TBB_LIB_LINK_FLAGS ${TBB_LIB_LINK_FLAGS} /guard:cf)
89+
endif()
90+
8691
if (CMAKE_CXX_COMPILER_ID MATCHES "(Clang|IntelLLVM)")
8792
if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86|AMD64|i.86)")
8893
set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -mrtm -mwaitpkg)

0 commit comments

Comments
 (0)