From 2a9fc04635c6c0b9a822f3c0aafeade1422fb8d9 Mon Sep 17 00:00:00 2001 From: Sergei Trofimovich Date: Sat, 1 Oct 2022 08:27:38 +0100 Subject: [PATCH] cc-wrapper/add-hardening.sh: always unset _FORTIFY_SOURCE before re-setting it On darwin clang driver always sets -D_FORTIFY_SOURCE=0 under asan. This causes -Werror to trip over macro redefinition: :1:9: error: '_FORTIFY_SOURCE' macro redefined [-Werror,-Wmacro-redefined] #define _FORTIFY_SOURCE 2 ^ To avoid it let's always explicitly undefine it first before redefining. --- pkgs/build-support/cc-wrapper/add-hardening.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/cc-wrapper/add-hardening.sh b/pkgs/build-support/cc-wrapper/add-hardening.sh index e5d296f6c9c5..b23fda1fed75 100644 --- a/pkgs/build-support/cc-wrapper/add-hardening.sh +++ b/pkgs/build-support/cc-wrapper/add-hardening.sh @@ -38,7 +38,9 @@ for flag in "${!hardeningEnableMap[@]}"; do case $flag in fortify) if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling fortify >&2; fi - hardeningCFlags+=('-O2' '-D_FORTIFY_SOURCE=2') + # Use -U_FORTIFY_SOURCE to avoid warnings on toolchains that explicitly + # set -D_FORTIFY_SOURCE=0 (like 'clang -fsanitize=address'). + hardeningCFlags+=('-O2' '-U_FORTIFY_SOURCE' '-D_FORTIFY_SOURCE=2') ;; stackprotector) if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling stackprotector >&2; fi