This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] add a configure option for using RELRO by default


2015-01-14  Daniel Micay  <danielmicay@gmail.com>

	* ld/configure.ac: Add --enable-default-relro switch.
	* ld/emultempl/elf32.em: Handle ENABLE_DEFAULT_RELRO.
	* ld/testsuite/config/default.exp: Disable RELRO.
	* ld/testsuite/ld-bootstrap/bootstrap.exp: Disable RELRO.
	* ld/config.in: Regenerate.
	* ld/configure: Regenerate.
---
 ld/ChangeLog                            |  9 +++++++++
 ld/config.in                            |  3 +++
 ld/configure                            | 16 ++++++++++++++--
 ld/configure.ac                         |  7 +++++++
 ld/emultempl/elf32.em                   |  3 +++
 ld/testsuite/config/default.exp         |  6 +++---
 ld/testsuite/ld-bootstrap/bootstrap.exp |  8 +++++++-
 7 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/ld/ChangeLog b/ld/ChangeLog
index be4617f..be24325 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,12 @@
+2015-01-14  Daniel Micay  <danielmicay@gmail.com>
+
+	* configure.ac: Add --enable-default-relro switch.
+	* emultempl/elf32.em: Handle ENABLE_DEFAULT_RELRO.
+	* testsuite/config/default.exp: Disable RELRO.
+	* testsuite/ld-bootstrap/bootstrap.exp: Disable RELRO.
+	* config.in: Regenerate.
+	* configure: Regenerate.
+
 2015-01-01  Alan Modra  <amodra@gmail.com>
 
 	* ldver.c (ldversion): Just print current year.
diff --git a/ld/config.in b/ld/config.in
index 2ab4844..8afcc16 100644
--- a/ld/config.in
+++ b/ld/config.in
@@ -17,6 +17,9 @@
 /* Define to choose default GOT handling scheme */
 #undef GOT_HANDLING_DEFAULT
 
+/* Define to mark relocations read-only by default. */
+#undef ENABLE_DEFAULT_RELRO
+
 /* Define to 1 if you have the `close' function. */
 #undef HAVE_CLOSE
 
diff --git a/ld/configure b/ld/configure
index 8a7bd20..337e68c 100755
--- a/ld/configure
+++ b/ld/configure
@@ -785,6 +785,7 @@ enable_64_bit_bfd
 with_sysroot
 enable_gold
 enable_got
+enable_default_relro
 enable_werror
 enable_build_warnings
 enable_nls
@@ -1442,6 +1443,7 @@ Optional Features:
   --enable-gold[=ARG]     build gold [ARG={default,yes,no}]
   --enable-got=<type>     GOT handling scheme (target, single, negative,
                           multigot)
+  --enable-default-relro       mark relocations read-only by default
   --enable-werror         treat compile warnings as errors
   --enable-build-warnings enable build-time compiler warnings
   --disable-nls           do not use Native Language Support
@@ -11712,7 +11714,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11715 "configure"
+#line 11717 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11818,7 +11820,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11821 "configure"
+#line 11823 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -15520,6 +15522,16 @@ $as_echo "#define GOT_HANDLING_DEFAULT GOT_HANDLING_MULTIGOT" >>confdefs.h
   *)  as_fn_error "bad value ${got_handling} for --enable-got option" "$LINENO" 5 ;;
 esac
 
+# Check whether --enable-default-relro was given.
+if test "${enable_default_relro+set}" = set; then :
+  enableval=$enable_default_relro;
+
+$as_echo "#define ENABLE_DEFAULT_RELRO  " >>confdefs.h
+
+
+fi
+
+
 
 # Set the 'development' global.
 . $srcdir/../bfd/development.sh
diff --git a/ld/configure.ac b/ld/configure.ac
index 043c597..1e5153f 100644
--- a/ld/configure.ac
+++ b/ld/configure.ac
@@ -142,6 +142,13 @@ case "${got_handling}" in
   *)  AC_MSG_ERROR(bad value ${got_handling} for --enable-got option) ;;
 esac
 
+AC_ARG_ENABLE(default-relro,
+              [  --enable-default-relro       mark relocations read-only by default],
+[
+  AC_DEFINE([ENABLE_DEFAULT_RELRO], [ ],
+            [Define to mark relocations read-only by default.])
+], [])
+
 AM_BINUTILS_WARNINGS
 
 AM_LC_MESSAGES
diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
index 34a729e..c994783 100644
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -102,6 +102,9 @@ gld${EMULATION_NAME}_before_parse (void)
   input_flags.dynamic = ${DYNAMIC_LINK-TRUE};
   config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`;
   config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo TRUE ; else echo FALSE ; fi`;
+#ifdef ENABLE_DEFAULT_RELRO
+  link_info.relro = TRUE;
+#endif
 }
 
 EOF
diff --git a/ld/testsuite/config/default.exp b/ld/testsuite/config/default.exp
index e25189b..5eadf07 100644
--- a/ld/testsuite/config/default.exp
+++ b/ld/testsuite/config/default.exp
@@ -22,7 +22,7 @@
 #
 
 if ![info exists ld] then {
-    set ld [findfile $base_dir/ld-new $base_dir/ld-new [transform ld]]
+    set ld "[findfile $base_dir/ld-new $base_dir/ld-new [transform ld]] -znorelro"
 }
 
 if ![info exists as] then {
@@ -60,7 +60,7 @@ if {![file isdirectory tmpdir/ld]} then {
     catch "exec ln -s ld tmpdir/ld/collect-ld" status
     catch "exec ln -s ../../../gas/as-new tmpdir/ld/as" status
 }
-set gcc_B_opt "-B[pwd]/tmpdir/ld/"
+set gcc_B_opt "-B[pwd]/tmpdir/ld/ -Wl,-z,norelro"
 
 # load the linker path
 set ld_L_opt ""
@@ -272,7 +272,7 @@ if ![info exists READELFFLAGS] then {
 }
 
 if ![info exists LD] then {
-    set LD [findfile $base_dir/ld-new ./ld-new [transform ld]]
+    set LD "[findfile $base_dir/ld-new ./ld-new [transform ld]] -znorelro"
 }
 
 if ![info exists LDFLAGS] then {
diff --git a/ld/testsuite/ld-bootstrap/bootstrap.exp b/ld/testsuite/ld-bootstrap/bootstrap.exp
index fe8031d..23b0e10 100644
--- a/ld/testsuite/ld-bootstrap/bootstrap.exp
+++ b/ld/testsuite/ld-bootstrap/bootstrap.exp
@@ -78,7 +78,13 @@ foreach flags $test_flags {
 
     # This test can only be run if we have the ld build directory,
     # since we need the object files.
-    if {$ld != "$objdir/ld-new"} {
+    set ldexe $ld
+    set ldparm [string first " " $ld]
+    if { $ldparm > 0 } then {
+	set ldparm [expr $ldparm - 1]
+	set ldexe [string range $ld 0 $ldparm]
+    }
+    if {$ldexe != "$objdir/ld-new"} {
 	untested $testname
 	continue
     }
-- 
2.2.2


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]