Debian Codegraph @

m4/noexecstack.m4

raw
1 # noexecstack.m4
2 dnl Copyright (C) 1995-2006 Free Software Foundation, Inc.
3 dnl
4 dnl This library is free software; you can redistribute it and/or
5 dnl modify it under the terms of the GNU Lesser General Public
6 dnl License as published by the Free Software Foundation; either
7 dnl version 2.1 of the License, or (at your option) any later version.
8 dnl
9 dnl This library is distributed in the hope that it will be useful,
10 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 dnl Lesser General Public License for more details.
13 dnl
14 dnl You should have received a copy of the GNU Lesser General Public
15 dnl License along with this library; if not, see <https://www.gnu.org/licenses/>.
16 dnl SPDX-License-Identifier: LGPL-2.1-or-later
17
18 dnl Checks whether the stack can be marked nonexecutable by passing an
19 dnl option to the C-compiler when acting on .s files. Returns that
20 dnl option in NOEXECSTACK_FLAGS.
21 dnl This macro is adapted from one found in GLIBC-2.3.5.
22 AC_DEFUN([CL_AS_NOEXECSTACK],[
23 AC_REQUIRE([AC_PROG_CC])
24 AC_REQUIRE([AM_PROG_AS])
25
26 AC_MSG_CHECKING([whether non excutable stack support is requested])
27 AC_ARG_ENABLE(noexecstack,
28 AS_HELP_STRING([--disable-noexecstack],
29 [disable non executable stack support]),
30 noexecstack_support=$enableval, noexecstack_support=yes)
31 AC_MSG_RESULT($noexecstack_support)
32
33 AC_CACHE_CHECK([whether assembler supports --noexecstack option],
34 cl_cv_as_noexecstack, [dnl
35 cat > conftest.c <<EOF
36 void foo(void) {}
37 EOF
38 if AC_TRY_COMMAND([${CC} $CFLAGS $CPPFLAGS
39 -S -o conftest.s conftest.c >/dev/null]) \
40 && grep .note.GNU-stack conftest.s >/dev/null \
41 && AC_TRY_COMMAND([${CCAS} $CCASFLAGS $CPPFLAGS -Wa,--noexecstack
42 -c -o conftest.o conftest.s >/dev/null])
43 then
44 cl_cv_as_noexecstack=yes
45 else
46 cl_cv_as_noexecstack=no
47 fi
48 rm -f conftest*])
49 if test "$noexecstack_support" = yes && test "$cl_cv_as_noexecstack" = yes; then
50 NOEXECSTACK_FLAGS="-Wa,--noexecstack"
51 else
52 NOEXECSTACK_FLAGS=
53 fi
54 AC_SUBST(NOEXECSTACK_FLAGS)
55 ])