From 4cc889000192b284913b92417afd0f39f7f6f134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Thu, 12 Feb 2009 23:20:15 +0100 Subject: [PATCH] Link with `-z relro' when available. * acinclude.m4 (GUILE_GNU_LD_RELRO): New macro. * configure.in: Use `GUILE_GNU_LD_RELRO'. --- acinclude.m4 | 19 +++++++++++++++++++ configure.in | 6 +++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/acinclude.m4 b/acinclude.m4 index 345e323b3..3e1dbeb2a 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -1,3 +1,5 @@ +dnl -*- Autoconf -*- + dnl On the NeXT, #including doesn't give you a definition for dnl struct utime, unless you #define _POSIX_SOURCE. @@ -308,3 +310,20 @@ else fi AC_LANG_RESTORE ])dnl ACX_PTHREAD + + +dnl Check whether GNU ld's read-only relocations (the `PT_GNU_RELRO' +dnl ELF segment header) are supported. This allows things like +dnl statically allocated cells (1) to eventually be remapped read-only +dnl by the loader, and (2) to be identified as pointerless by the +dnl garbage collector. +AC_DEFUN([GUILE_GNU_LD_RELRO], [ + AC_MSG_CHECKING([whether the linker understands `-z relro']) + + save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS -Wl,-z -Wl,relro" + AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], + [AC_MSG_RESULT([yes])], + [AC_MSG_RESULT([no]) + LDFLAGS="$save_LDFLAGS"]) +]) diff --git a/configure.in b/configure.in index 3c54bbdcd..c278361b6 100644 --- a/configure.in +++ b/configure.in @@ -4,7 +4,7 @@ dnl define(GUILE_CONFIGURE_COPYRIGHT,[[ -Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. +Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. This file is part of GUILE @@ -1448,6 +1448,10 @@ esac AC_SUBST(GCC_CFLAGS) +# Check for GNU ld's "-z relro". +GUILE_GNU_LD_RELRO + + ## If we're creating a shared library (using libtool!), then we'll ## need to generate a list of .lo files corresponding to the .o files ## given in LIBOBJS. We'll call it LIBLOBJS.