From 0da23da653c273874a3efa8b57db264ab2dadfea Mon Sep 17 00:00:00 2001 From: "Kelvin M. Klann" Date: Wed, 20 Mar 2024 07:28:50 +0000 Subject: build: fix "warning: "_FORTIFY_SOURCE" redefined" (#6283) The warning is being produced on Arch since pacman 6.1, which changed `-D_FORTIFY_SOURCE=2` to `-D_FORTIFY_SOURCE=3` in CFLAGS in makepkg.conf: $ pacman -Q gcc pacman gcc 13.2.1-5 pacman 6.1.0-3 $ makepkg [...] make -C src/lib gcc [...] -D_FORTIFY_SOURCE=2 [...] -Wp,-D_FORTIFY_SOURCE=3 [...] -c ../../src/lib/common.c -o ../../src/lib/common.o : warning: "_FORTIFY_SOURCE" redefined : note: this is the location of the previous definition To fix this, only add `-D_FORTIFY_SOURCE` to EXTRA_CFLAGS if it does not cause any warnings with CFLAGS and CPPFLAGS during compilation. The effect remains the same: The build system still defines the macro by default (if there are no warnings) and the user/distribution can still override it through CFLAGS/CPPFLAGS. Fixes #6282. Reported-by: @glitsj16 --- configure.ac | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index 2762c2ef0..73bd334f8 100644 --- a/configure.ac +++ b/configure.ac @@ -30,6 +30,10 @@ AX_CHECK_COMPILE_FLAG([-MMD -MP], [ DEPS_CFLAGS="$DEPS_CFLAGS -MMD -MP" ]) +AX_CHECK_COMPILE_FLAG([-D_FORTIFY_SOURCE=2], [ + EXTRA_CFLAGS="$EXTRA_CFLAGS -D_FORTIFY_SOURCE=2" +], [], [$CFLAGS $CPPFLAGS -Werror]) + HAVE_SPECTRE="no" AX_CHECK_COMPILE_FLAG([-mindirect-branch=thunk], [ HAVE_SPECTRE="yes" -- cgit v1.2.3-70-g09d2