From 1ddf58a2abc67f46690ed1ce78e7fdf1d66a19d5 Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Sun, 19 Jan 2014 10:13:30 +0000 Subject: [PATCH] Don't redefine _FORTIFY_SOURCE if compiler already defines it (cherry picked from commit 72f171dd0dcdb6fb616c36199b7f26fb74325157) --- configure.ac | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 303c6403..04f163f8 100644 --- a/configure.ac +++ b/configure.ac @@ -69,8 +69,6 @@ appendLD () { fi } -appendCXX "-D_FORTIFY_SOURCE=2" - case "${host_os}" in freebsd*) # -D__GNU_LIBRARY__ makes this work on fbsd 4.11 @@ -165,6 +163,24 @@ if test "x$with_systemdsystemunitdir" != xno; then fi AM_CONDITIONAL(HAVE_SYSTEMD, [test -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != xno ]) +# In old times needed to define _FORTIFY_SOURCE to 2 ourself. +# Then GCC started to define it itself to 2. It was ok. +# But then GCC 4.7 started to define it to 0 or 2 depending on optimization level, and it started to conflict with our define. +AC_MSG_CHECKING([whether compiler predefines _FORTIFY_SOURCE]) +AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([[ + ]], [[ + #ifndef _FORTIFY_SOURCE + #error "Just checking, nothing fatal here" + #endif + ]]) +], [ + AC_MSG_RESULT([yes]) +], [ + AC_MSG_RESULT([no]) + appendCXX "-D_FORTIFY_SOURCE=2" +]) + if test "$DEBUG" != "no"; then appendCXX -ggdb3 AC_DEFINE([_DEBUG], [1], [Define for debugging])