aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2018-02-27 11:34:20 -0800
committerH.J. Lu <hjl.tools@gmail.com>2018-02-27 11:34:29 -0800
commitf6aec96dce1ddbd8961a3aa8a2925db2021719bb (patch)
tree0837083a3f8011754f0fa415afa4a6fb27795580 /bfd
parent55089490f79ce1ddb9610fd6abeeaf896825fb71 (diff)
downloadgdb-f6aec96dce1ddbd8961a3aa8a2925db2021719bb.zip
gdb-f6aec96dce1ddbd8961a3aa8a2925db2021719bb.tar.gz
gdb-f6aec96dce1ddbd8961a3aa8a2925db2021719bb.tar.bz2
ld: Add --enable-separate-code
This patch adds --enable-separate-code to ld configure to turn on -z separate-code by default and enables it by default for Linux/x86. This avoids mixing code pages with data to improve cache performance as well as security. To reduce x86-64 executable and shared object sizes, the maximum page size is reduced from 2MB to 4KB when -z separate-code is turned on by default. Note: -z max-page-size= can be used to set the maximum page size. We compared SPEC CPU 2017 performance before and after this change on Skylake server. There are no any significant performance changes. Everything is mostly below +/-1%. bfd/ * config.in: Regenerated. * configure: Likewise. * configure.ac: Add --enable-separate-code. (DEFAULT_LD_Z_SEPARATE_CODE): New AC_DEFINE_UNQUOTED. Default to 1 for Linux/x86 targets, * elf64-x86-64.c (ELF_MAXPAGESIZE): Set to 0x1000 if DEFAULT_LD_Z_SEPARATE_CODE is 1. ld/ * NEWS: Mention --enable-separate-code. * configure.ac: Add --enable-separate-code. (DEFAULT_LD_Z_SEPARATE_CODE): New AC_DEFINE_UNQUOTED. * configure.tgt: Default ac_default_ld_z_separate_code to 1 for Linux/x86 targets. * config.in: Regenerated. * configure: Likewise. * emultempl/elf32.em (gld${EMULATION_NAME}_before_parse): Set link_info.separate_code DEFAULT_LD_Z_SEPARATE_CODE.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog10
-rw-r--r--bfd/config.in4
-rwxr-xr-xbfd/configure33
-rw-r--r--bfd/configure.ac24
-rw-r--r--bfd/elf64-x86-64.c12
5 files changed, 79 insertions, 4 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 5c2a888..59f7c9c 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,13 @@
+2018-02-27 H.J. Lu <hongjiu.lu@intel.com>
+
+ * config.in: Regenerated.
+ * configure: Likewise.
+ * configure.ac: Add --enable-separate-code.
+ (DEFAULT_LD_Z_SEPARATE_CODE): New AC_DEFINE_UNQUOTED. Default
+ to 1 for Linux/x86 targets,
+ * elf64-x86-64.c (ELF_MAXPAGESIZE): Set to 0x1000 if
+ DEFAULT_LD_Z_SEPARATE_CODE is 1.
+
2018-02-27 Nick Clifton <nickc@redhat.com>
* aout-cris.c (swap_ext_reloc_out): Standadize error/warning
diff --git a/bfd/config.in b/bfd/config.in
index 75a5ff0..186741d 100644
--- a/bfd/config.in
+++ b/bfd/config.in
@@ -10,6 +10,10 @@
/* Name of host specific core header file to include in elf.c. */
#undef CORE_HEADER
+/* Define to 1 if you want to enable -z separate-code in ELF linker by
+ default. */
+#undef DEFAULT_LD_Z_SEPARATE_CODE
+
/* Define to 1 if translation of program messages to the user's native
language is requested. */
#undef ENABLE_NLS
diff --git a/bfd/configure b/bfd/configure
index 6c2b24e..d1fe335 100755
--- a/bfd/configure
+++ b/bfd/configure
@@ -793,6 +793,7 @@ enable_targets
enable_64_bit_archive
with_mmap
enable_secureplt
+enable_separate_code
enable_leading_mingw64_underscores
with_separate_debug_dir
with_pkgversion
@@ -1446,6 +1447,7 @@ Optional Features:
--enable-targets alternative target configurations
--enable-64-bit-archive force 64-bit archives
--enable-secureplt Default to creating read-only plt entries
+ --enable-separate-code enable -z separate-code in ELF linker by default
--enable-leading-mingw64-underscores
Enable leading underscores on 64 bit mingw targets
--enable-werror treat compile warnings as errors
@@ -11428,7 +11430,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 11431 "configure"
+#line 11433 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -11534,7 +11536,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 11537 "configure"
+#line 11539 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -12171,6 +12173,33 @@ $as_echo "#define USE_SECUREPLT 1" >>confdefs.h
fi
+# Decide if -z separate-code should be enabled in ELF linker by default.
+ac_default_ld_z_separate_code=unset
+# Check whether --enable-separate-code was given.
+if test "${enable_separate_code+set}" = set; then :
+ enableval=$enable_separate_code; case "${enableval}" in
+ yes) ac_default_ld_z_separate_code=1 ;;
+ no) ac_default_ld_z_separate_code=0 ;;
+esac
+fi
+
+# Enable -z separate-code by default for Linux/x86.
+case "${target}" in
+i3-786-*-linux-* | x86_64-*-linux-*)
+ if test ${ac_default_ld_z_separate_code} = unset; then
+ ac_default_ld_z_separate_code=1
+ fi
+ ;;
+esac
+if test "${ac_default_ld_z_separate_code}" = unset; then
+ ac_default_ld_z_separate_code=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define DEFAULT_LD_Z_SEPARATE_CODE $ac_default_ld_z_separate_code
+_ACEOF
+
+
# Check whether --enable-leading-mingw64-underscores was given.
if test "${enable_leading_mingw64_underscores+set}" = set; then :
enableval=$enable_leading_mingw64_underscores;
diff --git a/bfd/configure.ac b/bfd/configure.ac
index 2342f3f..20e2c02 100644
--- a/bfd/configure.ac
+++ b/bfd/configure.ac
@@ -97,6 +97,30 @@ if test $use_secureplt = true; then
[Define if we should default to creating read-only plt entries])
fi
+# Decide if -z separate-code should be enabled in ELF linker by default.
+ac_default_ld_z_separate_code=unset
+AC_ARG_ENABLE(separate-code,
+ AS_HELP_STRING([--enable-separate-code],
+ [enable -z separate-code in ELF linker by default]),
+[case "${enableval}" in
+ yes) ac_default_ld_z_separate_code=1 ;;
+ no) ac_default_ld_z_separate_code=0 ;;
+esac])
+# Enable -z separate-code by default for Linux/x86.
+case "${target}" in
+i[3-7]86-*-linux-* | x86_64-*-linux-*)
+ if test ${ac_default_ld_z_separate_code} = unset; then
+ ac_default_ld_z_separate_code=1
+ fi
+ ;;
+esac
+if test "${ac_default_ld_z_separate_code}" = unset; then
+ ac_default_ld_z_separate_code=0
+fi
+AC_DEFINE_UNQUOTED(DEFAULT_LD_Z_SEPARATE_CODE,
+ $ac_default_ld_z_separate_code,
+ [Define to 1 if you want to enable -z separate-code in ELF linker by default.])
+
AC_ARG_ENABLE(leading-mingw64-underscores,
AS_HELP_STRING([--enable-leading-mingw64-underscores],
[Enable leading underscores on 64 bit mingw targets]),
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 02a3d37..7016964 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -4942,7 +4942,11 @@ elf_x86_64_special_sections[]=
#define ELF_ARCH bfd_arch_i386
#define ELF_TARGET_ID X86_64_ELF_DATA
#define ELF_MACHINE_CODE EM_X86_64
-#define ELF_MAXPAGESIZE 0x200000
+#if DEFAULT_LD_Z_SEPARATE_CODE
+# define ELF_MAXPAGESIZE 0x1000
+#else
+# define ELF_MAXPAGESIZE 0x200000
+#endif
#define ELF_MINPAGESIZE 0x1000
#define ELF_COMMONPAGESIZE 0x1000
@@ -5335,7 +5339,11 @@ elf64_l1om_elf_object_p (bfd *abfd)
#undef ELF_MAXPAGESIZE
#undef ELF_MINPAGESIZE
#undef ELF_COMMONPAGESIZE
-#define ELF_MAXPAGESIZE 0x200000
+#if DEFAULT_LD_Z_SEPARATE_CODE
+# define ELF_MAXPAGESIZE 0x1000
+#else
+# define ELF_MAXPAGESIZE 0x200000
+#endif
#define ELF_MINPAGESIZE 0x1000
#define ELF_COMMONPAGESIZE 0x1000
#undef elf_backend_plt_alignment