From 05609d5b4b02e87c17c01a0ebb9fc2e05b799d90 Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Tue, 5 Mar 2013 21:53:18 +1100 Subject: [PATCH] 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. --- configure.ac | 4 ++++ m4/add_cflags.m4 | 18 ++++++++++++++++++ m4/add_cxxflags.m4 | 19 +++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 m4/add_cflags.m4 create mode 100644 m4/add_cxxflags.m4 diff --git a/configure.ac b/configure.ac index ac35de22..b99f4027 100644 --- a/configure.ac +++ b/configure.ac @@ -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" diff --git a/m4/add_cflags.m4 b/m4/add_cflags.m4 new file mode 100644 index 00000000..08f4a409 --- /dev/null +++ b/m4/add_cflags.m4 @@ -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 + ], + [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 diff --git a/m4/add_cxxflags.m4 b/m4/add_cxxflags.m4 new file mode 100644 index 00000000..8197dc2d --- /dev/null +++ b/m4/add_cxxflags.m4 @@ -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 + ], + [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