This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
RFC: x86: Enable -z separate-code by default
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: binutils at sourceware dot org
- Date: Mon, 19 Feb 2018 05:15:55 -0800
- Subject: RFC: x86: Enable -z separate-code by default
- Authentication-results: sourceware.org; auth=none
This patch enables -z separate-code by default for x86. To reduce
x86-64 binary size, set ELF_MAXPAGESIZE to 4KB.
Should I add an ld configure option, --enable-separate-code, instead?
H.J.
---
bfd/
* elf64-x86-64.c (ELF_MAXPAGESIZE): Set to 0x1000.
ld/
* emulparams/elf32_x86_64.sh (DEFAULT_SEPARATE_CODE): New.
* emulparams/elf_i386.sh (DEFAULT_SEPARATE_CODE): Likewise.
* emulparams/elf_x86_64.sh (DEFAULT_SEPARATE_CODE): Likewise.
* emultempl/elf32.em (gld${EMULATION_NAME}_before_parse): Set
link_info.separate_code to TRUE if ${DEFAULT_SEPARATE_CODE} is
yes.
---
bfd/elf64-x86-64.c | 4 ++--
ld/emulparams/elf32_x86_64.sh | 1 +
ld/emulparams/elf_i386.sh | 1 +
ld/emulparams/elf_x86_64.sh | 1 +
ld/emultempl/elf32.em | 1 +
5 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 00ed5d17a5..51c301bae6 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -4934,7 +4934,7 @@ 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
+#define ELF_MAXPAGESIZE 0x1000
#define ELF_MINPAGESIZE 0x1000
#define ELF_COMMONPAGESIZE 0x1000
@@ -5327,7 +5327,7 @@ elf64_l1om_elf_object_p (bfd *abfd)
#undef ELF_MAXPAGESIZE
#undef ELF_MINPAGESIZE
#undef ELF_COMMONPAGESIZE
-#define ELF_MAXPAGESIZE 0x200000
+#define ELF_MAXPAGESIZE 0x1000
#define ELF_MINPAGESIZE 0x1000
#define ELF_COMMONPAGESIZE 0x1000
#undef elf_backend_plt_alignment
diff --git a/ld/emulparams/elf32_x86_64.sh b/ld/emulparams/elf32_x86_64.sh
index 9ce6533bd9..f8e004829d 100644
--- a/ld/emulparams/elf32_x86_64.sh
+++ b/ld/emulparams/elf32_x86_64.sh
@@ -14,6 +14,7 @@ COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
ARCH="i386:x64-32"
MACHINE=
TEMPLATE_NAME=elf32
+DEFAULT_SEPARATE_CODE=yes
GENERATE_SHLIB_SCRIPT=yes
GENERATE_PIE_SCRIPT=yes
NO_SMALL_DATA=yes
diff --git a/ld/emulparams/elf_i386.sh b/ld/emulparams/elf_i386.sh
index 2cef106e3d..6c451aac8a 100644
--- a/ld/emulparams/elf_i386.sh
+++ b/ld/emulparams/elf_i386.sh
@@ -12,6 +12,7 @@ COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
ARCH=i386
MACHINE=
TEMPLATE_NAME=elf32
+DEFAULT_SEPARATE_CODE=yes
GENERATE_SHLIB_SCRIPT=yes
GENERATE_PIE_SCRIPT=yes
NO_SMALL_DATA=yes
diff --git a/ld/emulparams/elf_x86_64.sh b/ld/emulparams/elf_x86_64.sh
index d8c6e54894..8e18d81bdf 100644
--- a/ld/emulparams/elf_x86_64.sh
+++ b/ld/emulparams/elf_x86_64.sh
@@ -14,6 +14,7 @@ COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
ARCH="i386:x86-64"
MACHINE=
TEMPLATE_NAME=elf32
+DEFAULT_SEPARATE_CODE=yes
GENERATE_SHLIB_SCRIPT=yes
GENERATE_PIE_SCRIPT=yes
NO_SMALL_DATA=yes
diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
index c0925fc9b9..1325b4742f 100644
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -104,6 +104,7 @@ gld${EMULATION_NAME}_before_parse (void)
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`;
`if test -n "$CALL_NOP_BYTE" ; then echo link_info.call_nop_byte = $CALL_NOP_BYTE; fi`;
+ link_info.separate_code = `if test "x${DEFAULT_SEPARATE_CODE}" = xyes ; then echo TRUE ; else echo FALSE ; fi`;
link_info.check_relocs_after_open_input = TRUE;
link_info.relro = DEFAULT_LD_Z_RELRO;
}
--
2.14.3