Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ option(FLB_RELEASE "Build with release mode (-O2 -g -DNDEBUG)" No)
set(FLB_IPO "ReleaseOnly" CACHE STRING "Build with interprocedural optimization")
set_property(CACHE FLB_IPO PROPERTY STRINGS "On;Off;ReleaseOnly")
option(FLB_SMALL "Optimise for small size" No)
set(FLB_SECURITY "ReleaseOnly" CACHE STRING "Build with security optimizations")
set_property(CACHE FLB_SECURITY PROPERTY STRINGS "On;Off;ReleaseOnly")
option(FLB_COVERAGE "Build with code-coverage" No)
option(FLB_JEMALLOC "Build with Jemalloc support" No)
option(FLB_REGEX "Build with Regex support" Yes)
Expand Down Expand Up @@ -442,6 +444,21 @@ if(FLB_IPO STREQUAL "On" OR (FLB_IPO STREQUAL "ReleaseOnly" AND FLB_RELEASE))
endif()
endif()

# Harden release binary against security vulnerabilities
if(FLB_SECURITY STREQUAL "On" OR (FLB_SECURITY STREQUAL "ReleaseOnly" AND FLB_RELEASE))
if (NOT MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-z,relro,-z,now")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-z,noexecstack")
if(NOT FLB_SMALL)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector")
# Fortify requires optimization
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FORTIFY_SOURCE=1")
endif()
endif()
endif()
endif()

if(FLB_PARSER)
FLB_DEFINITION(FLB_HAVE_PARSER)
message(STATUS "Enabling FLB_REGEX since FLB_PARSER requires")
Expand Down