blob: d39f419077e3db06f10491d3beb387d47c8bedb3 [file] [log] [blame]
Erik de Castro Lopo6b00dc22016-12-05 18:57:47 +11001dnl Copyright (C) 2013-2016 Xiph.org Foundation
Erik de Castro Lopo195470f2013-03-13 18:58:16 +11002dnl
3dnl Redistribution and use in source and binary forms, with or without
4dnl modification, are permitted provided that the following conditions
5dnl are met:
6dnl
7dnl - Redistributions of source code must retain the above copyright
8dnl notice, this list of conditions and the following disclaimer.
9dnl
10dnl - Redistributions in binary form must reproduce the above copyright
11dnl notice, this list of conditions and the following disclaimer in the
12dnl documentation and/or other materials provided with the distribution.
13dnl
14dnl - Neither the name of the Xiph.org Foundation nor the names of its
15dnl contributors may be used to endorse or promote products derived from
16dnl this software without specific prior written permission.
17dnl
18dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19dnl ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21dnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
22dnl CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23dnl EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24dnl PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25dnl PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26dnl LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27dnl NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28dnl SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
NotTsunamif706f282019-11-19 16:28:22 -050030dnl We want to know if GCC stack protector works, for the C and for the C++
Erik de Castro Lopo195470f2013-03-13 18:58:16 +110031dnl compiler.
32dnl
33dnl Just checking if the compiler accepts the required CFLAGSs is not enough
34dnl because we have seen at least one instance where this check was
35dnl in-sufficient.
36dnl
37dnl Instead, try to compile and link a test program with the stack protector
38dnl flags. If that works, we use it.
39
40AC_DEFUN([XIPH_GCC_STACK_PROTECTOR],
41[AC_LANG_ASSERT(C)
42 AC_MSG_CHECKING([if $CC supports stack smash protection])
43 xiph_stack_check_old_cflags="$CFLAGS"
NotTsunamif706f282019-11-19 16:28:22 -050044 SSP_FLAGS="-fstack-protector-strong"
Erik de Castro Lopo195470f2013-03-13 18:58:16 +110045 CFLAGS=$SSP_FLAGS
46 AC_TRY_LINK([
47 #include <stdio.h>
48 ],
49 [puts("Hello, World!"); return 0;],
50 AC_MSG_RESULT([yes])
51 CFLAGS="$xiph_stack_check_old_cflags $SSP_FLAGS",
52 AC_MSG_RESULT([no])
53 CFLAGS="$xiph_stack_check_old_cflags"
54 )
55])# XIPH_GCC_STACK_PROTECTOR
56
57AC_DEFUN([XIPH_GXX_STACK_PROTECTOR],
58[AC_LANG_PUSH([C++])
59 AC_MSG_CHECKING([if $CXX supports stack smash protection])
60 xiph_stack_check_old_cflags="$CFLAGS"
NotTsunamif706f282019-11-19 16:28:22 -050061 SSP_FLAGS="-fstack-protector-strong"
Erik de Castro Lopo195470f2013-03-13 18:58:16 +110062 CFLAGS=$SSP_FLAGS
63 AC_TRY_LINK([
64 #include <cstdio>
65 ],
66 [puts("Hello, World!"); return 0;],
67 AC_MSG_RESULT([yes])
68 CFLAGS="$xiph_stack_check_old_cflags $SSP_FLAGS",
69 AC_MSG_RESULT([no])
70 CFLAGS="$xiph_stack_check_old_cflags"
71 )
72 AC_LANG_POP([C++])
73])# XIPH_GXX_STACK_PROTECTOR