diff --git a/configure.ac b/configure.ac index b3c20f9..95116a1 100644 --- a/configure.ac +++ b/configure.ac @@ -137,6 +137,16 @@ fi ], [enable_secure="1"] ) +if test "x$enable_secure" = "x1" ; then + CFLAGS="$CFLAGS -fstack-protector" + LDFLAGS="$LDFLAGS -Wl,-z,relro,-z,now" + + if test "$CFLAGS" != "${CFLAGS%-O0*}" ; then # if CFLAGS contains -O0 + echo "WARNING: Could not apply FORTIFY_SOURCE=2 due to lack of optimization (-O0)" + else + CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2" #FORTITFY_SOURCE does not work with -O0 (ex. if enable_debug=1 or enable_gcov=1) + fi +fi AC_SUBST([enable_secure])