From 1110d0c1f1b17dbd7f1af6a7319bfa0cbafff323 Mon Sep 17 00:00:00 2001 From: Fabian Greffrath Date: Fri, 28 Apr 2023 12:32:54 +0200 Subject: [PATCH] make hardening flags optional, but enable for CI --- .github/workflows/main.yml | 2 +- cmake/WoofSettings.cmake | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5239fb18..b7af93fd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,7 +35,7 @@ jobs: - name: Configure env: CC: ${{ matrix.compiler }} - run: cmake -B build -G "Ninja" -DENABLE_WERROR=ON + run: cmake -B build -G "Ninja" -DENABLE_WERROR=ON -DENABLE_HARDENING=ON - name: Build run: cmake --build build diff --git a/cmake/WoofSettings.cmake b/cmake/WoofSettings.cmake index a49c7b60..0193bee8 100644 --- a/cmake/WoofSettings.cmake +++ b/cmake/WoofSettings.cmake @@ -44,12 +44,6 @@ _checked_add_compile_option(-Wnull-dereference) _checked_add_compile_option(-Wredundant-decls) _checked_add_compile_option(-Wrestrict) -# Hardening flags (from dpkg-buildflags) - -_checked_add_compile_option(-fstack-protector-strong) -_checked_add_compile_option(-D_FORTIFY_SOURCE=2) -_checked_add_link_option(-Wl,-z,relro) - if(MSVC) # Silence the usual warnings for POSIX and standard C functions. list(APPEND COMMON_COMPILE_OPTIONS "/D_CRT_NONSTDC_NO_DEPRECATE") @@ -93,6 +87,13 @@ if(ENABLE_ASAN) _checked_add_link_option(-fsanitize=address) endif() +option(ENABLE_HARDENING "Enable hardening flags" OFF) +if(ENABLE_HARDENING) + _checked_add_compile_option(-fstack-protector-strong) + _checked_add_compile_option(-D_FORTIFY_SOURCE=2) + _checked_add_link_option(-Wl,-z,relro) +endif() + if(${FORCE_COLORED_OUTPUT}) _checked_add_compile_option(-fdiagnostics-color=always F_DIAG_COLOR) if (NOT F_DIAG_COLOR)