Skip to content

Commit

Permalink
Added support for Clang build hardening (including Apple)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshabunin committed May 7, 2019
1 parent 7bb8d89 commit 5acfa52
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cmake/OpenCVCompilerDefenses.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# - https://wiki.debian.org/Hardening
# - https://wiki.gentoo.org/wiki/Hardened/Toolchain
# - https://docs.microsoft.com/en-us/cpp/build/reference/sdl-enable-additional-security-checks

# - https://developer.apple.com/library/archive/documentation/Security/Conceptual/SecureCodingGuide/Articles/BufferOverflows.html

set(OPENCV_LINKER_DEFENSES_FLAGS_COMMON "")

Expand Down Expand Up @@ -44,6 +44,12 @@ if(MSVC)
if(NOT X86_64)
set(OPENCV_LINKER_DEFENSES_FLAGS_COMMON "${OPENCV_LINKER_DEFENSES_FLAGS_COMMON} /safeseh")
endif()
elseif(CV_CLANG)
ocv_add_defense_compiler_flag("-fstack-protector-strong")
ocv_add_defense_compiler_flag_release("-D_FORTIFY_SOURCE=2")
if (NOT APPLE)
set(OPENCV_LINKER_DEFENSES_FLAGS_COMMON "${OPENCV_LINKER_DEFENSES_FLAGS_COMMON} -z noexecstack -z relro -z now" )
endif()
elseif(CV_GCC)
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9")
ocv_add_defense_compiler_flag("-fstack-protector")
Expand Down

0 comments on commit 5acfa52

Please sign in to comment.