| | 59 | # -fstack-protector |
| | 60 | AC_ARG_ENABLE([stack-protector], |
| | 61 | [AS_HELP_STRING([--disable-stack-protector], |
| | 62 | [Disable GCC's/libc's stack-smashing protection])], |
| | 63 | [case "${enableval}" in |
| | 64 | yes) enable_ssp=yes ;; |
| | 65 | no) enable_ssp=no ;; |
| | 66 | *) AC_MSG_ERROR([invalid value ${enableval} for --disable-stack-protector]) ;; |
| | 67 | esac], |
| | 68 | [enable_ssp=yes]) |
| | 69 | |
| | 70 | if test x"$enable_ssp" = x"yes" && test x"$GCC" != x"yes"; then |
| | 71 | AC_MSG_NOTICE([Disabling stack-smashing protection because compiler is not GCC]) |
| | 72 | enable_ssp=no |
| | 73 | fi |
| | 74 | |
| | 75 | if test x"$enable_ssp" = x"yes"; then |
| | 76 | # Check for broken ssp in libc: http://www.avahi.org/ticket/105 |
| | 77 | # libc's brokenness will get in the way regardless of whether -lssp is |
| | 78 | # provided, but provide it anyway (otherwise non-libc ssp would wrongly |
| | 79 | # break here) |
| | 80 | |
| | 81 | # Get -lssp if it exists |
| | 82 | GCC_STACK_PROTECT_LIB |
| | 83 | |
| | 84 | AC_MSG_CHECKING([whether stack-smashing protection is available]) |
| | 85 | ssp_old_cflags="$CFLAGS" |
| | 86 | ssp_old_ldflags="$LDFLAGS" |
| | 87 | CFLAGS="$CFLAGS -fstack-protector-all -fPIC" |
| | 88 | LDFLAGS="$LDFLAGS -Wl,-z,defs" |
| | 89 | cat confdefs.h > conftest.c |
| | 90 | cat >>conftest.c <<_ACEOF |
| | 91 | void test_broken_ssp(c) |
| | 92 | const char *c; |
| | 93 | { |
| | 94 | char arr[[123]], *p; /* beware of possible double-braces if copying this */ |
| | 95 | for (p = arr; *c; ++p) { |
| | 96 | *p = *c; |
| | 97 | ++c; |
| | 98 | } |
| | 99 | } |
| | 100 | _ACEOF |
| | 101 | rm -f conftest.o |
| | 102 | |
| | 103 | if $CC -c $CFLAGS $CPPFLAGS -o conftest.o conftest.c >/dev/null 2>&1; then |
| | 104 | AC_MSG_RESULT([yes]) |
| | 105 | AC_MSG_CHECKING([whether stack-smashing protection is buggy]) |
| | 106 | if $CC -o conftest.so $LDFLAGS -shared conftest.o $LIBS >/dev/null 2>&1; then |
| | 107 | AC_MSG_RESULT([no]) |
| | 108 | else |
| | 109 | AC_MSG_RESULT([yes]) |
| | 110 | enable_ssp=no |
| | 111 | fi |
| | 112 | else |
| | 113 | AC_MSG_RESULT([no]) |
| | 114 | fi |
| | 115 | |
| | 116 | rm -f conftest.c conftest.o conftest.so |
| | 117 | |
| | 118 | CFLAGS="$ssp_old_cflags" |
| | 119 | LDFLAGS="$ssp_old_ldflags" |
| | 120 | fi |
| | 121 | |
| | 122 | if test x"$enable_ssp" = x"yes"; then |
| | 123 | # Do this the long way so we don't call GCC_STACK_PROTECT_LIB twice |
| | 124 | GCC_STACK_PROTECT_CC |
| | 125 | |
| | 126 | AC_LANG_PUSH([C++]) |
| | 127 | GCC_STACK_PROTECT_CXX |
| | 128 | AC_LANG_POP([C++]) |
| | 129 | # XXX: Update the enable_ssp value now for output later? |
| | 130 | fi |
| | 131 | |