2 dnl Useful macros for autoconf to check for ssp-patched gcc
3 dnl 1.0 - September 2003 - Tiago Sousa <mirage@kaotik.org>
4 dnl 1.1 - August 2006 - Ted Percival <ted@midg3t.net>
5 dnl * Stricter language checking (C or C++)
6 dnl * Adds GCC_STACK_PROTECT_LIB to add -lssp to LDFLAGS as necessary
7 dnl * Caches all results
8 dnl * Uses macros to ensure correct ouput in quiet/silent mode
11 dnl GCC extension for protecting applications from stack-smashing attacks
12 dnl http://www.research.ibm.com/trl/projects/security/ssp/
15 dnl Call GCC_STACK_PROTECT_LIB to determine if the library implementing SSP is
16 dnl available, then the appropriate C or C++ language's test. If you are using
17 dnl both C and C++ you will need to use AC_LANG_PUSH and AC_LANG_POP to ensure
18 dnl the right language is being used for each test.
20 dnl GCC_STACK_PROTECT_LIB
21 dnl adds libssp to the LDFLAGS if it is available
23 dnl GCC_STACK_PROTECT_CC
24 dnl checks -fstack-protector with the C compiler, if it exists then updates
25 dnl CFLAGS and defines ENABLE_SSP_CC
27 dnl GCC_STACK_PROTECT_CXX
28 dnl checks -fstack-protector with the C++ compiler, if it exists then updates
29 dnl CXXFLAGS and defines ENABLE_SSP_CXX
32 AC_DEFUN([GCC_STACK_PROTECT_LIB],[
33 AC_CACHE_CHECK([whether libssp exists], ssp_cv_lib,
34 [ssp_old_ldflags="$LDFLAGS"
35 LDFLAGS="$LDFLAGS -lssp"
36 AC_TRY_LINK(,, ssp_cv_lib=yes, ssp_cv_lib=no)
37 LDFLAGS="$ssp_old_ldflags"
39 if test $ssp_cv_lib = yes; then
40 LDFLAGS="$LDFLAGS -lssp"
44 AC_DEFUN([GCC_STACK_PROTECT_CC],[
46 if test "X$CC" != "X"; then
47 AC_CACHE_CHECK([whether ${CC} accepts -fstack-protector],
49 [ssp_old_cflags="$CFLAGS"
50 CFLAGS="$CFLAGS -fstack-protector"
51 AC_TRY_COMPILE(,, ssp_cv_cc=yes, ssp_cv_cc=no)
52 CFLAGS="$ssp_old_cflags"
54 if test $ssp_cv_cc = yes; then
55 CFLAGS="$CFLAGS -fstack-protector"
56 AC_DEFINE([ENABLE_SSP_CC], 1, [Define if SSP C support is enabled.])
61 AC_DEFUN([GCC_STACK_PROTECT_CXX],[
63 if test "X$CXX" != "X"; then
64 AC_CACHE_CHECK([whether ${CXX} accepts -fstack-protector],
66 [ssp_old_cxxflags="$CXXFLAGS"
67 CXXFLAGS="$CXXFLAGS -fstack-protector"
68 AC_TRY_COMPILE(,, ssp_cv_cxx=yes, ssp_cv_cxx=no)
69 CXXFLAGS="$ssp_old_cxxflags"
71 if test $ssp_cv_cxx = yes; then
72 CXXFLAGS="$CXXFLAGS -fstack-protector"
73 AC_DEFINE([ENABLE_SSP_CXX], 1, [Define if SSP C++ support is enabled.])