From: Frederic Marchal Date: Sun, 21 Sep 2014 08:56:21 +0000 (+0200) Subject: Fix _FORTIFY_SOURCE redefinition error X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fd749ca939b28425db90e0374f591aa85dfaa434;p=thirdparty%2Fsarg.git Fix _FORTIFY_SOURCE redefinition error Some systems define _FORTIFY_SOURCE by default. It conflicts with our use of that macro when --enable-extraprotection is passed to the configuration script. The solution is to undefine it before redefining it with value 2. If a higher _FORTIFY_LEVEL level ever appears, it will have to be used in this program to benefit from the highest protection possible. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index feb61c6..ddda566 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -345,7 +345,8 @@ ENDIF(CMAKE_SYSTEM_NAME STREQUAL "solaris") OPTION(ENABLE_EXTRA_PROTECT "Enable compile and runtime extra protections" OFF) IF(ENABLE_EXTRA_PROTECT) GET_TARGET_PROPERTY(TMPCFLAGS sarg COMPILE_FLAGS) - SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "${TMPCFLAGS} -fstack-protector -D_FORTIFY_SOURCE=2 -Werror") + # _FORTIFY_SOURCE may have been defined by the system. It must be undefined before it is changed to the value we want. + SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "${TMPCFLAGS} -fstack-protector -U _FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Werror") CHECK_C_COMPILER_FLAG("-Wformat -Werror=format-security" HAVE_WERROR_FORMAT_SECURITY) IF(HAVE_WERROR_FORMAT_SECURITY) diff --git a/configure.in b/configure.in index ea19248..c2993b5 100644 --- a/configure.in +++ b/configure.in @@ -285,7 +285,8 @@ AS_HELP_STRING([--enable-extraprotection], [Enable compile and runtime extra protections]), [ if test "$enableval"; then - CFLAGS="${CFLAGS} -fstack-protector -D_FORTIFY_SOURCE=2" + # _FORTIFY_SOURCE may have been defined by the system. It must be undefined before it is changed to the value we want. + CFLAGS="${CFLAGS} -fstack-protector -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2" if test "x$werror_status" != "xfail" ; then CFLAGS="${CFLAGS} -Werror" fi