1# noexecstack.m4
2dnl Copyright (C) 1995-2006 Free Software Foundation, Inc.
3dnl
4dnl This library is free software; you can redistribute it and/or
5dnl modify it under the terms of the GNU Lesser General Public
6dnl License as published by the Free Software Foundation; either
7dnl version 2.1 of the License, or (at your option) any later version.
8dnl
9dnl This library is distributed in the hope that it will be useful,
10dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12dnl Lesser General Public License for more details.
13dnl
14dnl You should have received a copy of the GNU Lesser General Public
15dnl License along with this library; if not, write to the Free Software
16dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
17
18dnl Checks whether the stack can be marked nonexecutable by passing an
19dnl option to the C-compiler when acting on .s files.  Returns that
20dnl option in NOEXECSTACK_FLAGS.
21dnl This macro is adapted from one found in GLIBC-2.3.5.
22AC_DEFUN([CL_AS_NOEXECSTACK],[
23AC_REQUIRE([AC_PROG_CC])
24AC_REQUIRE([AM_PROG_AS])
25
26AC_MSG_CHECKING([whether non excutable stack support is requested])
27AC_ARG_ENABLE(noexecstack,
28              AC_HELP_STRING([--disable-noexecstack],
29                             [disable non executable stack support]),
30              noexecstack_support=$enableval, noexecstack_support=yes)
31AC_MSG_RESULT($noexecstack_support)
32
33AC_CACHE_CHECK([whether assembler supports --noexecstack option],
34onms_cv_as_noexecstack, [dnl
35  cat > conftest.c <<EOF
36void foo() {}
37EOF
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    onms_cv_as_noexecstack=yes
45  else
46    onms_cv_as_noexecstack=no
47  fi
48  rm -f conftest*])
49  if test "$noexecstack_support" = yes -a "$onms_cv_as_noexecstack" = yes; then
50	NOEXECSTACK_ASFLAGS="-Wa,--noexecstack"
51  else
52        NOEXECSTACK_ASFLAGS=
53  fi
54  AC_SUBST(NOEXECSTACK_ASFLAGS)
55
56AC_CACHE_CHECK([whether ld supports -z noexecstack option],
57onms_cv_ld_noexecstack, [dnl
58  cat > conftest.c <<EOF
59void foo() {}
60EOF
61  if AC_TRY_COMMAND([${CC} $CFLAGS $CPPFLAGS -Wl,-z,noexecstack -c -o conftest.o conftest.c >/dev/null])
62  then
63    onms_cv_ld_noexecstack=yes
64  else
65    onms_cv_ld_noexecstack=no
66  fi
67  rm -f conftest*])
68  if test "$noexecstack_support" = yes -a "$onms_cv_ld_noexecstack" = yes; then
69	NOEXECSTACK_LDFLAGS="-Wa,--noexecstack"
70  else
71        NOEXECSTACK_LDFLAGS=
72  fi
73  AC_SUBST(NOEXECSTACK_LDFLAGS)
74
75])
76