configure.ac : Add hardening compile options.

Extra compile options are detected at configure time with new
XIPH_ADD_*FLAGS m4 macros.

Options enabled include -Wextra, -D_FORTIFY_SOURCE=2 and stack
protection.
This commit is contained in:
Erik de Castro Lopo 2013-03-05 21:53:18 +11:00
parent 9d057c7179
commit 05609d5b4b
3 changed files with 41 additions and 0 deletions

View File

@ -356,6 +356,10 @@ fi
XIPH_GCC_VERSION
XIPH_ADD_CFLAGS([-Wextra])
XIPH_ADD_CFLAGS([-D_FORTIFY_SOURCE=2])
XIPH_ADD_CFLAGS([-fstack-protector --param ssp-buffer-size=4])
if test x$ac_cv_c_compiler_gnu = xyes ; then
if test x$enable_gcc_werror = "xyes" ; then
CFLAGS="-Wall -Wextra -Werror $CFLAGS"

18
m4/add_cflags.m4 Normal file
View File

@ -0,0 +1,18 @@
dnl @synopsis XIPH_ADD_CFLAGS
dnl
dnl Add the given option to CFLAGS, if it doesn't break the compiler
AC_DEFUN([XIPH_ADD_CFLAGS],
[AC_MSG_CHECKING([if $CC accepts $1])
ac_add_cflags__old_cflags="$CFLAGS"
CFLAGS="$1"
AC_TRY_LINK([
#include <stdio.h>
],
[puts("Hello, World!"); return 0;],
AC_MSG_RESULT([yes])
CFLAGS="$ac_add_cflags__old_cflags $1",
AC_MSG_RESULT([no])
CFLAGS="$ac_add_cflags__old_cflags"
)
])# XIPH_ADD_CFLAGS

19
m4/add_cxxflags.m4 Normal file
View File

@ -0,0 +1,19 @@
dnl @synopsis XIPH_ADD_CXXFLAGS
dnl
dnl Add the given option to CXXFLAGS, if it doesn't break the compiler
AC_DEFUN([XIPH_ADD_CXXFLAGS],
[AC_MSG_CHECKING([if $CXX accepts $1])
AC_LANG_ASSERT([C++])
ac_add_cxxflags__old_cxxflags="$CXXFLAGS"
CXXFLAGS="$1"
AC_TRY_LINK([
#include <cstdio>
],
[puts("Hello, World!"); return 0;],
AC_MSG_RESULT([yes])
CXXFLAGS="$ac_add_cxxflags__old_cxxflags $1",
AC_MSG_RESULT([no])
CXXFLAGS="$ac_add_cxxflags__old_cxxflags"
)
])# XIPH_ADD_CXXFLAGS