* [committed, PATCH] Don't generate PLT relocations for now binding
@ 2015-05-16 14:02 H.J. Lu
0 siblings, 0 replies; only message in thread
From: H.J. Lu @ 2015-05-16 14:02 UTC (permalink / raw)
To: binutils
There is no need for PLT relocations with -z now. We can use GOT
relocations, which take less space, instead and replace 16-byte .plt
entres with 8-byte .plt.got entries.
bfd/
* elf32-i386.c (elf_i386_check_relocs): Create .plt.got section
for now binding.
(elf_i386_allocate_dynrelocs): Use .plt.got section for now
binding.
* elf64-x86-64.c (elf_x86_64_check_relocs): Create .plt.got
section for now binding.
(elf_x86_64_allocate_dynrelocs): Use .plt.got section for now
binding.
ld/testsuite/
* ld-i386/i386.exp: Run PR ld/17689 tests with -z now.
* ld-x86-64/x86-64.exp: Likewise
* ld-i386/pr17689now.rd: New file.
* ld-x86-64/pr17689now.rd: Likewise
---
bfd/elf32-i386.c | 16 ++++++++++++++--
bfd/elf64-x86-64.c | 16 ++++++++++++++--
ld/testsuite/ld-i386/i386.exp | 24 ++++++++++++++++++++++++
ld/testsuite/ld-i386/pr17689now.rd | 4 ++++
ld/testsuite/ld-x86-64/pr17689now.rd | 4 ++++
ld/testsuite/ld-x86-64/x86-64.exp | 24 ++++++++++++++++++++++++
6 files changed, 84 insertions(+), 4 deletions(-)
create mode 100644 ld/testsuite/ld-i386/pr17689now.rd
create mode 100644 ld/testsuite/ld-x86-64/pr17689now.rd
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 815473d..c6ff746 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -1885,7 +1885,7 @@ do_size:
if (use_plt_got
&& h != NULL
&& h->plt.refcount > 0
- && h->got.refcount > 0
+ && ((info->flags & DF_BIND_NOW) || h->got.refcount > 0)
&& htab->plt_got == NULL)
{
/* Create the GOT procedure linkage table. */
@@ -2321,7 +2321,19 @@ elf_i386_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
else if (htab->elf.dynamic_sections_created
&& (h->plt.refcount > 0 || eh->plt_got.refcount > 0))
{
- bfd_boolean use_plt_got = eh->plt_got.refcount > 0;
+ bfd_boolean use_plt_got;
+
+ if ((info->flags & DF_BIND_NOW))
+ {
+ /* Don't use the regular PLT for DF_BIND_NOW. */
+ h->plt.offset = (bfd_vma) -1;
+
+ /* Use the GOT PLT. */
+ h->got.refcount = 1;
+ eh->plt_got.refcount = 1;
+ }
+
+ use_plt_got = eh->plt_got.refcount > 0;
/* Make sure this symbol is output as a dynamic symbol.
Undefined weak syms won't yet be marked as dynamic. */
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index e9b5601..01df230 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -2080,7 +2080,7 @@ do_size:
if (use_plt_got
&& h != NULL
&& h->plt.refcount > 0
- && h->got.refcount > 0
+ && ((info->flags & DF_BIND_NOW) || h->got.refcount > 0)
&& htab->plt_got == NULL)
{
/* Create the GOT procedure linkage table. */
@@ -2540,7 +2540,19 @@ elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
else if (htab->elf.dynamic_sections_created
&& (h->plt.refcount > 0 || eh->plt_got.refcount > 0))
{
- bfd_boolean use_plt_got = eh->plt_got.refcount > 0;
+ bfd_boolean use_plt_got;
+
+ if ((info->flags & DF_BIND_NOW))
+ {
+ /* Don't use the regular PLT for DF_BIND_NOW. */
+ h->plt.offset = (bfd_vma) -1;
+
+ /* Use the GOT PLT. */
+ h->got.refcount = 1;
+ eh->plt_got.refcount = 1;
+ }
+
+ use_plt_got = eh->plt_got.refcount > 0;
/* Make sure this symbol is output as a dynamic symbol.
Undefined weak syms won't yet be marked as dynamic. */
diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
index bbc6005..a26cffd 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -406,6 +406,14 @@ if { [isnative]
"pr17689.so" \
] \
[list \
+ "Build pr17689.so with -z now" \
+ "-shared -Wl,-z,now" \
+ "-fPIC" \
+ { pr17689a.c } \
+ {{readelf {-Wr} pr17689now.rd}} \
+ "pr17689now.so" \
+ ] \
+ [list \
"Build pr17689ver.so" \
"-shared -Wl,--version-script,pr17689a.t" \
"-fPIC" \
@@ -430,6 +438,14 @@ if { [isnative]
"pr17689" \
] \
[list \
+ "Build pr17689 with PIE, -z now and GOTOFF" \
+ "tmpdir/pr17689b.o tmpdir/pr17689.so -pie -Wl,-z,now" \
+ "" \
+ { dummy.c } \
+ {{readelf {-Wr} pr17689now.rd}} \
+ "pr17689now" \
+ ] \
+ [list \
"Build pr17689ver with PIE and GOTOFF" \
"tmpdir/pr17689b.o tmpdir/pr17689ver.so -pie" \
"" \
@@ -484,6 +500,14 @@ if { [isnative]
"pr17689.out" \
] \
[list \
+ "Run pr17689 with PIE, -z now and GOTOFF" \
+ "tmpdir/pr17689b.o tmpdir/pr17689.so -pie -z now" \
+ "" \
+ { dummy.c } \
+ "pr17689now" \
+ "pr17689.out" \
+ ] \
+ [list \
"Run pr17689ver with PIE and GOTOFF" \
"tmpdir/pr17689b.o tmpdir/pr17689ver.so -pie" \
"" \
diff --git a/ld/testsuite/ld-i386/pr17689now.rd b/ld/testsuite/ld-i386/pr17689now.rd
new file mode 100644
index 0000000..9741df8
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr17689now.rd
@@ -0,0 +1,4 @@
+#failif
+#...
+[0-9a-f ]+R_386_JUMP_SLOT +0+.*
+#...
diff --git a/ld/testsuite/ld-x86-64/pr17689now.rd b/ld/testsuite/ld-x86-64/pr17689now.rd
new file mode 100644
index 0000000..8fd9371
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr17689now.rd
@@ -0,0 +1,4 @@
+#failif
+#...
+[0-9a-f ]+R_X86_64_JUMP_SLOT +0+ +.*
+#...
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index a312271..8281dc4 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -440,6 +440,14 @@ if { [isnative] && [which $CC] != 0 } {
"pr17689.so" \
] \
[list \
+ "Build pr17689now.so with -z now" \
+ "-shared -Wl,-z,now" \
+ "-fPIC" \
+ { pr17689a.c } \
+ {{readelf {-Wr} pr17689now.rd}} \
+ "pr17689now.so" \
+ ] \
+ [list \
"Build pr17689 with PIE without -fPIE" \
"tmpdir/pr17689.so -pie" \
"" \
@@ -448,6 +456,14 @@ if { [isnative] && [which $CC] != 0 } {
"pr17689" \
] \
[list \
+ "Build pr17689 with PIE -z now without -fPIE" \
+ "tmpdir/pr17689.so -pie -Wl,-z,now" \
+ "" \
+ { pr17689b.S } \
+ {{readelf {-Wr} pr17689now.rd}} \
+ "pr17689now" \
+ ] \
+ [list \
"Build pr17827 with PIE without -fPIE" \
"tmpdir/pr17689.so -pie" \
"" \
@@ -493,6 +509,14 @@ if { [isnative] && [which $CC] != 0 } {
"pr17689" \
"pr17689.out" \
] \
+ [list \
+ "Run pr17689 with PIE -z now without -fPIE" \
+ "tmpdir/pr17689.so -pie -z now" \
+ "" \
+ { pr17689b.S } \
+ "pr17689now" \
+ "pr17689.out" \
+ ] \
]
if { [istarget "x86_64-*-linux*"] \
--
2.1.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2015-05-16 14:02 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-16 14:02 [committed, PATCH] Don't generate PLT relocations for now binding H.J. Lu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).