Better test for conflict between optimization and FORTIFY_SOURCE

This commit is contained in:
John Ralls 2014-05-02 14:02:24 -07:00
parent ac9a6ae606
commit 8cb391b308

View File

@ -1329,22 +1329,21 @@ then
# This is gcc >= 3.4.x # This is gcc >= 3.4.x
warnFLAGS="${warnFLAGS} -Wdeclaration-after-statement" warnFLAGS="${warnFLAGS} -Wdeclaration-after-statement"
fi fi
else if test "`echo ${GCC_VERSION} | cut -d. -f1`" -ge 4; then elif test "`echo ${GCC_VERSION} | cut -d. -f1`" -ge 4; then
AC_MSG_CHECKING(OK To use fortify source?)
# This is gcc >= 4.x.x # This is gcc >= 4.x.x
warnFLAGS="${warnFLAGS} -Wdeclaration-after-statement -Wno-pointer-sign" warnFLAGS="${warnFLAGS} -Wdeclaration-after-statement -Wno-pointer-sign"
# rpmbuild on FC4 forces this flag. Only add it when optimizing # rpmbuild on FC4 forces this flag. Only add it when optimizing
have_optimization= cflags_save="$CFLAGS"
for flag in $CFLAGS; do CFLAGS="$AM_CFLAGS $CFLAGS -Werror -D_FORTIFY_SOURCE=2"
tmp_flag=`echo $flag | sed -e 's,-O.,,'` AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
if `echo $flag | grep -q -- '-O'` ; then #include <stdio.h>
have_optimization=yes ]],
fi [[ printf( "%s\n", "Hello World!");]])],
done [warnFLAGS="${warnFLAGS} -D_FORTIFY_SOURCE=2"
AC_MSG_RESULT(OK)],
if test "x${have_optimization}" = xyes; then [AC_MSG_RESULT(No)])
warnFLAGS="${warnFLAGS} -D_FORTIFY_SOURCE=2" CFLAGS="$cflags_save"
fi
fi
fi fi
AM_CFLAGS="${warnFLAGS} ${AM_CFLAGS}" AM_CFLAGS="${warnFLAGS} ${AM_CFLAGS}"
AM_CXXFLAGS="${warnXXFLAGS} ${AM_CXXFLAGS}" AM_CXXFLAGS="${warnXXFLAGS} ${AM_CXXFLAGS}"