On Sun, 7 Aug 2005, Richard B. Kreckel wrote:

> I am still pondering how to make this a little bit more generic.
> Maybe it's best to pass --noexecstack to gas indirectly via the
> -Wa,--noexecstack compiler flag? I would need to determine whether
> gas is new enough to  support --noexecstack, though.

> Does this appear to be the right way? 

(Shamelessly ripped from 
http://lists.gnu.org/archive/html/axiom-developer/2003-11/msg00165.html)

When GCC compiles a module that does not contain any code requiring
executable stack, it emits the complementary marker section with no
SHF_EXECINSTR flag bit:

        .section .note.GNU-stack, "", @progbits
        .previous

If you have assembly code of your own, then you need to add these markers.
The best way is to amend the source code with one of the assembly
directives above.  If that is problematic for some reason, another thing
you can do is tell the assembler directly what to emit on the command line
using -Wa,--execstack or -Wa,--noexecstack.  Finally, if you want to punt
altogether on marking your .o files properly, you can tell the linker to
ignore the marker sections and override its output setting directly on the
command using -Wl,-z,execstack or -Wl,-z,noexecstack.


> Has anybody bothered writing an autconf macro for this?

Yes. See attached file. It seems to work for me. However, I use
plain automake+autoconf instead of original CLN build system.

Best regards, 
  Alexei

dnl Suggested usage:
dnl 
dnl AC_PROG_CC
dnl AX_AS_NOEXECSTACK
dnl AM_PROG_AS
dnl
dnl Checks if assembler used by AC_PROG_CC supports `--noexecstack'
dnl option, and if so, appends '-Wa,--noexecstack' to CFLAGS
dnl  
dnl Author: Alexei Sheplyakov
dnl License: all-permissive

AC_DEFUN([AX_AS_NOEXECSTACK],[
AC_REQUIRE([AC_PROG_CC])
AC_MSG_CHECKING([if assembler used by ${CC-cc} supports --noexecstack option])
ac_cv_prog_cc_noexecstack=no
AC_LANG_PUSH([C])
save_CFLAGS="$CFLAGS"
CFLAGS="-Wa,--noexecstack $CFLAGS"

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>]],
[[printf("OK\n")]])],

[ac_cv_prog_cc_noexecstack="yes"; AC_MSG_RESULT([yes])],
[ac_cv_prog_cc_noexecstack="no";
CFLAGS="$save_CFLAGS"; AC_MSG_RESULT([no])])

AC_LANG_POP([C])])

Attachment: signature.asc
Description: Digital signature

Reply via email to