From a3090c2c98facbab3d47aa23a94f8d2caeb78d71 Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Thu, 20 Jul 2023 11:35:54 -0300 Subject: scripts: Fix fortify checks if compiler does not support _FORTIFY_SOURCE=3 The 30379efad1 added _FORTIFY_SOURCE checks without check if compiler does support all used fortify levels. This patch fixes it by first checking at configure time the maximum support fortify level and using it instead of a pre-defined one. Checked on x86_64 with gcc 11, 12, and 13. Reviewed-by: Siddhesh Poyarekar Tested-by: Florian Weimer --- scripts/check-installed-headers.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/check-installed-headers.sh b/scripts/check-installed-headers.sh index 23506a2514..ee9f534ab0 100644 --- a/scripts/check-installed-headers.sh +++ b/scripts/check-installed-headers.sh @@ -29,11 +29,12 @@ cxx_modes="-std=c++98 -std=gnu++98 -std=c++11 -std=gnu++11" # These are probably the most commonly used three. lib_modes="-D_DEFAULT_SOURCE=1 -D_GNU_SOURCE=1 -D_XOPEN_SOURCE=700" -# Also check for fortify modes, since it might be enabled as default. -fortify_modes="1 2 3" +# Also check for fortify modes, since it might be enabled as default. The +# maximum value to be checked is define by maximum_fortify argument. +fortify_modes="" if [ $# -lt 3 ]; then - echo "usage: $0 c|c++ \"compile command\" header header header..." >&2 + echo "usage: $0 c|c++ maximum_fortify \"compile command\" header header header..." >&2 exit 2 fi case "$1" in @@ -50,6 +51,8 @@ case "$1" in exit 2;; esac shift +fortify_modes=$(seq -s' ' 1 $1) +shift cc_cmd="$1" shift trap "rm -f '$cih_test_c'" 0 @@ -104,7 +107,6 @@ EOF for lang_mode in "" $lang_modes; do for lib_mode in "" $lib_modes; do for fortify_mode in "" $fortify_modes; do - echo :::: $lang_mode $lib_mode $fortify_mode if [ -z "$lib_mode" ]; then expanded_lib_mode='/* default library mode */' else @@ -114,6 +116,7 @@ EOF if [ ! -z $fortify_mode ]; then fortify_mode="#define _FORTIFY_SOURCE $fortify_mode" fi + echo :::: $lang_mode $lib_mode $fortify_mode cat >"$cih_test_c" <