+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.
+ * configure.tgt (ac_default_ld_z_relro): Default it to 1 for
+ some Linux targets.
+ * config.in: Regenerated.
+ * configure: Likewise.
+ * emultempl/elf32.em (gld${EMULATION_NAME}_before_parse): Set
+ link_info.relro to DEFAULT_LD_Z_RELRO.
+ * testsuite/config/default.exp (ld_elf_shared_opt): New.
+ * testsuite/lib/ld-lib.exp (run_dump_test): Pass
+ $ld_elf_shared_opt to ld for ELF targets with shared object
+ support.
+ (run_ld_link_tests): Likewise.
+
2016-06-21 Maciej W. Rozycki <macro@imgtec.com>
* testsuite/ld-mips-elf/mode-change-error-1a.s: Trigger an error
-*- text -*-
+* Add a configure option --enable-relro to decide whether -z relro should
+ be enabled in ELF linker by default. Default to yes for all Linux
+ targets except FRV, HPPA, IA64 and MIPS.
+
* Support for -z noreloc-overflow in the x86-64 ELF linker to disable
relocation overflow check.
/* Define if you want compressed debug sections by default. */
#undef DEFAULT_FLAG_COMPRESS_DEBUG
+/* 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
enable_gold
enable_got
enable_compressed_debug_sections
+enable_relro
enable_werror
enable_build_warnings
enable_nls
multigot)
--enable-compressed-debug-sections={all,ld,none}
compress debug sections by default]
+ --enable-relro enable -z relro in ELF linker 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
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 11724 "configure"
+#line 11726 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 11830 "configure"
+#line 11832 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
esac
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
+
# Set the 'development' global.
. $srcdir/../bfd/development.sh
fi
+if test "${ac_default_ld_z_relro}" = unset; then
+ ac_default_ld_z_relro=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define DEFAULT_LD_Z_RELRO $ac_default_ld_z_relro
+_ACEOF
+
+
,no, | ,none,) ac_default_compressed_debug_sections=no ;;
esac])dnl
+# 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
+
AM_BINUTILS_WARNINGS
AM_LC_MESSAGES
AC_DEFINE(DEFAULT_FLAG_COMPRESS_DEBUG, 1, [Define if you want compressed debug sections by default.])
fi
+if test "${ac_default_ld_z_relro}" = unset; then
+ ac_default_ld_z_relro=0
+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_SUBST(elf_list_options)
AC_SUBST(elf_shlib_list_options)
AC_SUBST(elf_plt_unwind_list_options)
;;
esac
+
+case "${target}" in
+frv-*-* | hppa*-*-* | ia64-*-* | mips*-*-*)
+ # Don't enable -z relro by default since many relro tests fail on these
+ # targets:
+ # FAIL: strip -z relro (relro1)
+ # FAIL: strip -z relro -shared (relro1)
+ # FAIL: objcopy -z relro (relro1)
+ # FAIL: objcopy -z relro -shared (relro1)
+ # FAIL: objcopy -z relro (tdata1)
+ # FAIL: objcopy -shared -z relro (tdata1)
+ # FAIL: objcopy -z relro (tdata2)
+ # FAIL: objcopy -shared -z relro (tdata2)
+ # FAIL: objcopy -z relro (tdata3)
+ # FAIL: objcopy -shared -z relro (tdata3)
+ # FAIL: objcopy -shared -z relro (tbss1)
+ # FAIL: objcopy -shared -z relro (tbss2)
+ # FAIL: objcopy -shared -z relro (tbss3)
+ ;;
+*-*-linux*)
+ if test ${ac_default_ld_z_relro} = unset; then
+ ac_default_ld_z_relro=1
+ fi
+ ;;
+esac
config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo TRUE ; else echo FALSE ; fi`;
`if test -n "$CALL_NOP_BYTE" ; then echo link_info.call_nop_byte = $CALL_NOP_BYTE; fi`;
link_info.check_relocs_after_open_input = `if test "x${CHECK_RELOCS_AFTER_OPEN_INPUT}" = xyes ; then echo TRUE ; else echo FALSE ; fi`;
+ link_info.relro = DEFAULT_LD_Z_RELRO;
}
EOF
}
}
+# Many ELF testcases expect that "-z relro" is off.
+set ld_elf_shared_opt "-z norelro"
+
# The "make check" target in the Makefile passes in
# "CC=$(CC_FOR_TARGET)". But, if the user invokes runtest directly
# (as when testing an installed linker), these flags may not be set.
global OBJDUMPFLAGS NMFLAGS ASFLAGS OBJCOPYFLAGS READELFFLAGS LDFLAGS
global host_triplet runtests
global env verbose
+ global ld_elf_shared_opt
+
+ if { [is_elf_format] && [check_shared_lib_support] } {
+ set ld_extra_opt "$ld_elf_shared_opt"
+ } else {
+ set ld_extra_opt ""
+ }
if [string match "*/*" $name] {
set file $name
# Add -L$srcdir/$subdir so that the linker command can use
# linker scripts in the source directory.
- set cmd "$LD $LDFLAGS -L$srcdir/$subdir \
+ set cmd "$LD $ld_extra_opt $LDFLAGS -L$srcdir/$subdir \
$opts(ld) -o $objfile $objfiles $opts(ld_after_inputfiles)"
# If needed then check for, or add a -Map option.
global CFLAGS
global runtests
global exec_output
+ global ld_elf_shared_opt
+
+ if { [is_elf_format] && [check_shared_lib_support] } {
+ set ld_extra_opt "$ld_elf_shared_opt"
+ } else {
+ set ld_extra_opt ""
+ }
foreach testitem $ldtests {
set testname [lindex $testitem 0]
if { ![ar_simple_create $ar $ld_options $binfile "$objfiles $ld_after"] } {
set failed 1
}
- } elseif { ![ld_simple_link $ld $binfile "-L$srcdir/$subdir $ld_options $objfiles $ld_after"] } {
+ } elseif { ![ld_simple_link $ld $binfile "$ld_extra_opt -L$srcdir/$subdir $ld_options $objfiles $ld_after"] } {
set maybe_failed 1
set ld_output "$exec_output"
}