gold: Add a linker configure option --enable-relro
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 22 Jun 2016 12:39:22 +0000 (05:39 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 22 Jun 2016 12:39:39 +0000 (05:39 -0700)
Add a configure option --enable-relro to decide whether -z relro should
be enabled by default.  Default to yes.

PR ld/20283
* NEWS: Mention --enable-relro.
* configure.ac: Add --enable-relro.
(DEFAULT_LD_Z_RELRO): New.  Set by --enable-relro and default
to 1.
* config.in: Regenerated.
* configure: Likewise.
* options.h (General_options::relro): Default to
DEFAULT_LD_Z_RELRO.

gold/ChangeLog
gold/NEWS
gold/config.in
gold/configure
gold/configure.ac
gold/options.h

index 5177da2..e8980b3 100644 (file)
@@ -1,3 +1,15 @@
+2016-06-22  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/20283
+       * NEWS: Mention --enable-relro.
+       * configure.ac: Add --enable-relro.
+       (DEFAULT_LD_Z_RELRO): New.  Set by --enable-relro and default
+       to 1.
+       * config.in: Regenerated.
+       * configure: Likewise.
+       * options.h (General_options::relro): Default to
+       DEFAULT_LD_Z_RELRO.
+
 2016-06-20  Cary Coutant  <ccoutant@gmail.com>
 
        * NEWS: Add new features in 1.12.
index 6f2cf3f..a400489 100644 (file)
--- a/gold/NEWS
+++ b/gold/NEWS
@@ -1,5 +1,8 @@
 Changes in 1.12:
 
+* Add a configure option --enable-relro to decide whether -z relro should
+  be enabled by default.  Default to yes.
+
 * Add support for s390, MIPS, AArch64, and TILE-Gx architectures.
 
 * Add support for STT_GNU_IFUNC symbols.
index 88e8712..d9f7b76 100644 (file)
@@ -10,6 +10,9 @@
 /* Define if building universal (internal helper macro) */
 #undef AC_APPLE_UNIVERSAL_BUILD
 
+/* Define to 1 if you want to enable -z relro in ELF linker by default. */
+#undef DEFAULT_LD_Z_RELRO
+
 /* Define to 1 if translation of program messages to the user's native
    language is requested. */
 #undef ENABLE_NLS
index 6d4f234..a40b2b5 100755 (executable)
@@ -792,6 +792,7 @@ with_sysroot
 enable_gold
 enable_threads
 enable_plugins
+enable_relro
 enable_targets
 with_lib_path
 enable_dependency_tracking
@@ -1441,6 +1442,7 @@ Optional Features:
   --enable-gold[=ARG]     build gold [ARG={default,yes,no}]
   --enable-threads        multi-threaded linking
   --enable-plugins        linker plugins
+  --enable-relro          enable -z relro in ELF linker by default
   --enable-targets        alternative target configurations
   --disable-dependency-tracking  speeds up one-time build
   --enable-dependency-tracking   do not reject slow dependency extractors
@@ -3353,6 +3355,25 @@ else
 fi
 
 
+# Decide if -z relro should be enabled in ELF linker by default.
+ac_default_ld_z_relro=unset
+# Provide a configure time option to override our default.
+# Check whether --enable-relro was given.
+if test "${enable_relro+set}" = set; then :
+  enableval=$enable_relro; case "${enableval}" in
+  yes)  ac_default_ld_z_relro=1 ;;
+  no)  ac_default_ld_z_relro=0 ;;
+esac
+fi
+if test "${ac_default_ld_z_relro}" = unset; then
+  ac_default_ld_z_relro=1
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define DEFAULT_LD_Z_RELRO $ac_default_ld_z_relro
+_ACEOF
+
+
 # Check whether --enable-targets was given.
 if test "${enable_targets+set}" = set; then :
   enableval=$enable_targets; case "${enableval}" in
index 695a2fd..90e2c22 100644 (file)
@@ -114,6 +114,23 @@ if test "$plugins" = "yes"; then
 fi
 AM_CONDITIONAL(PLUGINS, test "$plugins" = "yes")
 
+# Decide if -z relro should be enabled in ELF linker by default.
+ac_default_ld_z_relro=unset
+# Provide a configure time option to override our default.
+AC_ARG_ENABLE(relro,
+             AS_HELP_STRING([--enable-relro],
+             [enable -z relro in ELF linker by default]),
+[case "${enableval}" in
+  yes)  ac_default_ld_z_relro=1 ;;
+  no)  ac_default_ld_z_relro=0 ;;
+esac])dnl
+if test "${ac_default_ld_z_relro}" = unset; then
+  ac_default_ld_z_relro=1
+fi
+AC_DEFINE_UNQUOTED(DEFAULT_LD_Z_RELRO,
+  $ac_default_ld_z_relro,
+  [Define to 1 if you want to enable -z relro in ELF linker by default.])
+
 AC_ARG_ENABLE([targets],
 [  --enable-targets        alternative target configurations],
 [case "${enableval}" in
index 877e6d1..23c9658 100644 (file)
@@ -1336,7 +1336,7 @@ class General_options
   DEFINE_bool(origin, options::DASH_Z, '\0', false,
              N_("Mark DSO to indicate that needs immediate $ORIGIN "
                 "processing at runtime"), NULL);
-  DEFINE_bool(relro, options::DASH_Z, '\0', false,
+  DEFINE_bool(relro, options::DASH_Z, '\0', DEFAULT_LD_Z_RELRO,
              N_("Where possible mark variables read-only after relocation"),
              N_("Don't mark variables read-only after relocation"));
   DEFINE_bool(text, options::DASH_Z, '\0', false,