diff --git a/CMakeLists.txt b/CMakeLists.txt index 8efa759fc9b..5510de25540 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,10 +66,17 @@ if(MINIMAL_BUILD) endif() if(MUSL_OPTIMIZED_BUILD) - set(MUSL_FLAGS "-static -Os") + set(MUSL_FLAGS "-static -Os -fPIE -pie") endif() -set(CMAKE_COMMON_FLAGS "-Wall -ggdb ${DRAIOS_FEATURE_FLAGS} ${MINIMAL_BUILD_FLAGS} ${MUSL_FLAGS}") +# explicitly set hardening flags +set(CMAKE_POSITION_INDEPENDENT_CODE ON) +set(FALCO_SECURITY_FLAGS "-Wl,-z,relro,-z,now -fstack-protector-strong") +if(CMAKE_BUILD_TYPE STREQUAL "release") + set(FALCO_SECURITY_FLAGS "${FALCO_SECURITY_FLAGS} -D_FORTIFY_SOURCE=2") +endif() + +set(CMAKE_COMMON_FLAGS "${FALCO_SECURITY_FLAGS} -Wall -ggdb ${DRAIOS_FEATURE_FLAGS} ${MINIMAL_BUILD_FLAGS} ${MUSL_FLAGS}") if(BUILD_WARNINGS_AS_ERRORS) set(CMAKE_SUPPRESSED_WARNINGS