[Cluster-devel] [PATCH 2/2] gfs2-utils: Build with -D_FORTIFY_SOURCE=2

Andrew Price anprice at redhat.com
Thu Jun 30 10:55:36 UTC 2016


A survey of popular Linux distros shows that they all compile their
packages with _FORTIFY_SOURCE=2 defined so it makes sense to enable it
upstream too, in order to fix any issues it highlights before they reach
the distros. It will also allow us to factor the overhead it adds into
perf measurements.

Briefly, using this flag adds buffer overflow detection to some
functions, and enables -Wunused-result warnings.

It requires the optimization level to be -O1 or higher so it is only
added to CPPFLAGS when --enable-debug is not used.

Signed-off-by: Andrew Price <anprice at redhat.com>
---
 configure.ac | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index b421fbe..cc49642 100644
--- a/configure.ac
+++ b/configure.ac
@@ -143,8 +143,10 @@ ENV_LDFLAGS="$LDFLAGS"
 if test "x${enable_debug}" = xyes; then
 	AC_DEFINE_UNQUOTED([DEBUG], [1], [Compiling Debugging code])
 	OPT_CFLAGS="-O0"
+	OPT_CPPFLAGS=""
 else
 	OPT_CFLAGS="-O2"
+	OPT_CPPFLAGS="-D_FORTIFY_SOURCE=2"
 fi
 
 # gdb flags
@@ -203,7 +205,7 @@ for j in $WARNLIST; do
 done
 
 CFLAGS="$ENV_CFLAGS $OPT_CFLAGS $GDB_FLAGS $EXTRA_WARNINGS $WERROR_CFLAGS"
-CPPFLAGS="-I\$(top_builddir)/make -I\$(top_srcdir)/make -I. $ENV_CPPFLAGS"
+CPPFLAGS="-I\$(top_builddir)/make -I\$(top_srcdir)/make -I. $ENV_CPPFLAGS $OPT_CPPFLAGS"
 LDFLAGS="$ENV_LDFLAGS"
 
 AC_CONFIG_TESTDIR([tests], [gfs2/libgfs2:gfs2/mkfs:gfs2/fsck:gfs2/edit:gfs2/convert:gfs2/tune:tests])
-- 
2.7.4




More information about the Cluster-devel mailing list