Permalink
Browse files

Don't redefine _FORTIFY_SOURCE if compiler already defines it

(cherry picked from commit 72f171d)
  • Loading branch information...
1 parent c34b0d3 commit 1ddf58a2abc67f46690ed1ce78e7fdf1d66a19d5 @DarthGandalf DarthGandalf committed Jan 19, 2014
Showing with 18 additions and 2 deletions.
  1. +18 −2 configure.ac
View
@@ -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])

0 comments on commit 1ddf58a

Please sign in to comment.