From 94eb9af366800d8baffc280c00bf6b10d4810fbf Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 11 Aug 2015 15:02:58 +0200 Subject: [PATCH] build system: enable gcc's stack protection Implements #1370. --- Rakefile | 1 + ac/compiler_flags.m4 | 8 +++++++- build-config.in | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index b436baa31..0a2104ec5 100755 --- a/Rakefile +++ b/Rakefile @@ -108,6 +108,7 @@ def setup_globals cflags_common += " #{c(:WNO_INCONSISTENT_MISSING_OVERRIDE)} #{c(:WNO_POTENTIALLY_EVALUATED_EXPRESSION)}" cflags_common += " #{c(:OPTIMIZATION_CFLAGS)} -D_FILE_OFFSET_BITS=64" cflags_common += " -DMTX_LOCALE_DIR=\\\"#{c(:localedir)}\\\" -DMTX_PKG_DATA_DIR=\\\"#{c(:pkgdatadir)}\\\" -DMTX_DOC_DIR=\\\"#{c(:docdir)}\\\"" + cflags_common += " #{c(:FSTACK_PROTECTOR)}" cflags_common += " -Ilib/libebml -Ilib/libmatroska" if c?(:EBML_MATROSKA_INTERNAL) cflags_common += " #{c(:MATROSKA_CFLAGS)} #{c(:EBML_CFLAGS)} #{c(:EXTRA_CFLAGS)} #{c(:DEBUG_CFLAGS)} #{c(:PROFILING_CFLAGS)} #{c(:USER_CPPFLAGS)}" cflags_common += " -mno-ms-bitfields -DWINVER=0x0500 -D_WIN32_WINNT=0x0500 " if c?(:MINGW) diff --git a/ac/compiler_flags.m4 b/ac/compiler_flags.m4 index fd0bfa743..59f8615cc 100644 --- a/ac/compiler_flags.m4 +++ b/ac/compiler_flags.m4 @@ -7,6 +7,7 @@ if test x"$ac_cv_compiler_is_clang" = xyes; then QUNUSED_ARGUMENTS="-Qunused-arguments" WNO_SELF_ASSIGN="-Wno-self-assign" WNO_MISMATCHED_TAGS="-Wno-mismatched-tags" + FSTACK_PROTECTOR="" ac_save_CXXFLAGS="$CXXFLAGS" AC_LANG_PUSH(C++) @@ -22,12 +23,17 @@ if test x"$ac_cv_compiler_is_clang" = xyes; then else WNO_MAYBE_UNINITIALIZED="-Wno-maybe-uninitialized" + FSTACK_PROTECTOR="-fstack-protector" - if check_version 4.8.0 $ac_cv_gcc_version ; then + if check_version 4.9.0 $ac_cv_gcc_version ; then + FSTACK_PROTECTOR="-fstack-protector-strong" + + elif check_version 4.8.0 $ac_cv_gcc_version ; then WLOGICAL_OP="-Wlogical-op" fi fi +AC_SUBST(FSTACK_PROTECTOR) AC_SUBST(QUNUSED_ARGUMENTS) AC_SUBST(WNO_SELF_ASSIGN) AC_SUBST(WNO_MISMATCHED_TAGS) diff --git a/build-config.in b/build-config.in index 95948cd9b..2f7aa3ad5 100644 --- a/build-config.in +++ b/build-config.in @@ -85,6 +85,7 @@ EBML_MATROSKA_INTERNAL = @EBML_MATROSKA_INTERNAL@ EGREP = @EGREP@ EXTRA_CFLAGS = @EXTRA_CFLAGS@ EXTRA_LDFLAGS = @EXTRA_LDFLAGS@ +FSTACK_PROTECTOR = @FSTACK_PROTECTOR@ GTEST_TYPE = @GTEST_TYPE@ LDFLAGS_RPATHS = @LDFLAGS_RPATHS@ FLAC_LIBS = @FLAC_LIBS@