Skip to content

Commit 39d0606

Browse files
authored
Add more hardening flags to library build (#1680)
1 parent 621af05 commit 39d0606

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

cmake/compilers/Clang.cmake

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2020-2024 Intel Corporation
1+
# Copyright (c) 2020-2025 Intel Corporation
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -65,6 +65,10 @@ endif()
6565
# Clang flags to prevent compiler from optimizing out security checks
6666
set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -Wformat -Wformat-security -Werror=format-security -fPIC $<$<NOT:$<BOOL:${EMSCRIPTEN}>>:-fstack-protector-strong>)
6767

68+
if (NOT APPLE AND NOT ANDROID_PLATFORM)
69+
set(TBB_LIB_COMPILE_FLAGS ${TBB_LIB_COMPILE_FLAGS} -fstack-clash-protection $<$<NOT:$<BOOL:${EMSCRIPTEN}>>:-fcf-protection=full>)
70+
endif()
71+
6872
# -z switch is not supported on MacOS
6973
if (NOT APPLE)
7074
set(TBB_LIB_LINK_FLAGS ${TBB_LIB_LINK_FLAGS} -Wl,-z,relro,-z,now)

cmake/compilers/GNU.cmake

+5
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ endif ()
107107
set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -fno-strict-overflow -fno-delete-null-pointer-checks -fwrapv)
108108
set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -Wformat -Wformat-security -Werror=format-security
109109
-fstack-protector-strong )
110+
if (NOT CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" AND NOT EMSCRIPTEN)
111+
set(TBB_LIB_COMPILE_FLAGS ${TBB_LIB_COMPILE_FLAGS} $<$<NOT:$<VERSION_LESS:${CMAKE_CXX_COMPILER_VERSION},8.0>>:-fcf-protection=full>)
112+
endif ()
113+
set(TBB_LIB_COMPILE_FLAGS ${TBB_LIB_COMPILE_FLAGS} $<$<NOT:$<VERSION_LESS:${CMAKE_CXX_COMPILER_VERSION},8.0>>:-fstack-clash-protection>)
114+
110115
# -z switch is not supported on MacOS and MinGW
111116
if (NOT APPLE AND NOT MINGW)
112117
set(TBB_LIB_LINK_FLAGS ${TBB_LIB_LINK_FLAGS} -Wl,-z,relro,-z,now,-z,noexecstack)

0 commit comments

Comments
 (0)