This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [committed, PATCH] Allocate the first .plt entry space only if needed
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Binutils <binutils at sourceware dot org>
- Date: Wed, 24 Jun 2015 13:51:09 -0700
- Subject: Re: [committed, PATCH] Allocate the first .plt entry space only if needed
- Authentication-results: sourceware.org; auth=none
- References: <20150512201740 dot GB9067 at intel dot com>
On Tue, May 12, 2015 at 1:17 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:
> Commit dd7e64d45b317128f5fe813a8da0b13b4ad046ae may optimize out
> i386/x86-64 JUMP_SLOT relocation. If there is no JUMP_SLOT relocation
> left, we don't need to the first .plt entry. This patch allocates
> space for the first .plt entry only if we also reserve space for a PLT
> slot for JUMP_SLOT relocation.
>
> bfd/
>
> * elf32-i386.c (elf_i386_allocate_dynrelocs): Allocate space
> for the first .plt entry only if needed.
> * elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Likewise.
>
> ld/testsuite/
>
> * ld-i386/i386.exp: Run pltgot-1 for Linux targets.
> * ld-x86-64/x86-64.exp: Likewise.
> * ld-i386/pltgot-1.d: New file.
> * ld-i386/pltgot-1.s: Likewise.
> * ld-x86-64/pltgot-1.d: Likewise.
> * ld-x86-64/pltgot-1.s: Likewise.
> ---
> bfd/ChangeLog | 6 ++++++
> bfd/elf32-i386.c | 13 +++++++------
> bfd/elf64-x86-64.c | 9 ++++-----
> ld/testsuite/ChangeLog | 9 +++++++++
> ld/testsuite/ld-i386/i386.exp | 8 ++++++++
> ld/testsuite/ld-i386/pltgot-1.d | 8 ++++++++
> ld/testsuite/ld-i386/pltgot-1.s | 6 ++++++
> ld/testsuite/ld-x86-64/pltgot-1.d | 8 ++++++++
> ld/testsuite/ld-x86-64/pltgot-1.s | 6 ++++++
> ld/testsuite/ld-x86-64/x86-64.exp | 1 +
> 10 files changed, 63 insertions(+), 11 deletions(-)
> create mode 100644 ld/testsuite/ld-i386/pltgot-1.d
> create mode 100644 ld/testsuite/ld-i386/pltgot-1.s
> create mode 100644 ld/testsuite/ld-x86-64/pltgot-1.d
> create mode 100644 ld/testsuite/ld-x86-64/pltgot-1.s
>
This change breaks prelink which uses the .plt section and DT_PLTGOT
to undo prelinking for dynamic relocations. I checked in this patch to
revert it.
--
H.J.
From 7c1e8d3ed5e48b3339d60450fdb5b29ae54edebe Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Wed, 24 Jun 2015 13:37:05 -0700
Subject: [PATCH] Keep .plt section and DT_PLTGOT for prelink
Since the .plt section and DT_PLTGOT are used by prelink to undo
prelinking for dynamic relocations, we must keep them even if there is
no PLT relocation. This patch reverted commit a3747075a.
bfd/
* elf32-i386.c (elf_i386_allocate_dynrelocs): Always allocate
space for the first .plt entry.
(elf_i386_size_dynamic_sections): Always add DT_PLTGOT for .plt
section. Add DT_PLTRELSZ, DT_PLTREL and DT_JMPREL only if
there are PLT relocations.
* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Always
allocate space for the first .plt entry.
(elf_x86_64_size_dynamic_sections): Always add DT_PLTGOT for
.plt section. Add DT_PLTRELSZ, DT_PLTREL and DT_JMPREL only if
there are PLT relocations.
ld/testsuite/
* ld-i386/i386.exp: Run pltgot-2 for Linux targets.
* ld-x86-64/x86-64.exp: Likewise.
* ld-i386/pltgot-1.d: Updated.
* ld-x86-64/pltgot-1.d: Likewise.
* ld-i386/pltgot-2.d: New file.
* ld-x86-64/pltgot-2.d: Likewise.
---
bfd/ChangeLog | 13 +++++++++++++
bfd/elf32-i386.c | 29 ++++++++++++++++++-----------
bfd/elf64-x86-64.c | 25 +++++++++++++++++--------
ld/testsuite/ChangeLog | 9 +++++++++
ld/testsuite/ld-i386/i386.exp | 1 +
ld/testsuite/ld-i386/pltgot-1.d | 5 +++--
ld/testsuite/ld-i386/pltgot-2.d | 9 +++++++++
ld/testsuite/ld-x86-64/pltgot-1.d | 5 +++--
ld/testsuite/ld-x86-64/pltgot-2.d | 9 +++++++++
ld/testsuite/ld-x86-64/x86-64.exp | 1 +
10 files changed, 83 insertions(+), 23 deletions(-)
create mode 100644 ld/testsuite/ld-i386/pltgot-2.d
create mode 100644 ld/testsuite/ld-x86-64/pltgot-2.d
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 8918851..49303b3 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,18 @@
2015-06-24 H.J. Lu <hongjiu.lu@intel.com>
+ * elf32-i386.c (elf_i386_allocate_dynrelocs): Always allocate
+ space for the first .plt entry.
+ (elf_i386_size_dynamic_sections): Always add DT_PLTGOT for .plt
+ section. Add DT_PLTRELSZ, DT_PLTREL and DT_JMPREL only if
+ there are PLT relocations.
+ * elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Always
+ allocate space for the first .plt entry.
+ (elf_x86_64_size_dynamic_sections): Always add DT_PLTGOT for
+ .plt section. Add DT_PLTRELSZ, DT_PLTREL and DT_JMPREL only if
+ there are PLT relocations.
+
+2015-06-24 H.J. Lu <hongjiu.lu@intel.com>
+
PR ld/18591
* elf64-x86-64.c (elf_x86_64_convert_mov_to_lea): Don't convert
R_X86_64_GOTPCREL to R_X86_64_PC32 if it will cause relocation
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index f3aee96..92e7f72 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -2351,16 +2351,16 @@ elf_i386_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
asection *s = htab->elf.splt;
asection *got_s = htab->plt_got;
+ /* If this is the first .plt entry, make room for the special
+ first entry. The .plt section is used by prelink to undo
+ prelinking for dynamic relocations. */
+ if (s->size == 0)
+ s->size = plt_entry_size;
+
if (use_plt_got)
eh->plt_got.offset = got_s->size;
else
- {
- /* If this is the first .plt entry, make room for the
- special first entry. */
- if (s->size == 0)
- s->size = plt_entry_size;
- h->plt.offset = s->size;
- }
+ h->plt.offset = s->size;
/* If this symbol is not defined in a regular file, and we are
not generating a shared library, then set the symbol to this
@@ -3119,11 +3119,18 @@ elf_i386_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
if (htab->elf.splt->size != 0)
{
- if (!add_dynamic_entry (DT_PLTGOT, 0)
- || !add_dynamic_entry (DT_PLTRELSZ, 0)
- || !add_dynamic_entry (DT_PLTREL, DT_REL)
- || !add_dynamic_entry (DT_JMPREL, 0))
+ /* DT_PLTGOT is used by prelink even if there is no PLT
+ relocation. */
+ if (!add_dynamic_entry (DT_PLTGOT, 0))
return FALSE;
+
+ if (htab->elf.srelplt->size != 0)
+ {
+ if (!add_dynamic_entry (DT_PLTRELSZ, 0)
+ || !add_dynamic_entry (DT_PLTREL, DT_REL)
+ || !add_dynamic_entry (DT_JMPREL, 0))
+ return FALSE;
+ }
}
if (relocs)
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index f7aea98..fb22602 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -2571,14 +2571,16 @@ elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
asection *bnd_s = htab->plt_bnd;
asection *got_s = htab->plt_got;
+ /* If this is the first .plt entry, make room for the special
+ first entry. The .plt section is used by prelink to undo
+ prelinking for dynamic relocations. */
+ if (s->size == 0)
+ s->size = plt_entry_size;
+
if (use_plt_got)
eh->plt_got.offset = got_s->size;
else
{
- /* If this is the first .plt entry, make room for the
- special first entry. */
- if (s->size == 0)
- s->size = plt_entry_size;
h->plt.offset = s->size;
if (bnd_s)
eh->plt_bnd.offset = bnd_s->size;
@@ -3464,12 +3466,19 @@ elf_x86_64_size_dynamic_sections (bfd *output_bfd,
if (htab->elf.splt->size != 0)
{
- if (!add_dynamic_entry (DT_PLTGOT, 0)
- || !add_dynamic_entry (DT_PLTRELSZ, 0)
- || !add_dynamic_entry (DT_PLTREL, DT_RELA)
- || !add_dynamic_entry (DT_JMPREL, 0))
+ /* DT_PLTGOT is used by prelink even if there is no PLT
+ relocation. */
+ if (!add_dynamic_entry (DT_PLTGOT, 0))
return FALSE;
+ if (htab->elf.srelplt->size != 0)
+ {
+ if (!add_dynamic_entry (DT_PLTRELSZ, 0)
+ || !add_dynamic_entry (DT_PLTREL, DT_RELA)
+ || !add_dynamic_entry (DT_JMPREL, 0))
+ return FALSE;
+ }
+
if (htab->tlsdesc_plt
&& (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
|| !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index 812549c..2031bc8 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,12 @@
+2015-06-24 H.J. Lu <hongjiu.lu@intel.com>
+
+ * ld-i386/i386.exp: Run pltgot-2 for Linux targets.
+ * ld-x86-64/x86-64.exp: Likewise.
+ * ld-i386/pltgot-1.d: Updated.
+ * ld-x86-64/pltgot-1.d: Likewise.
+ * ld-i386/pltgot-2.d: New file.
+ * ld-x86-64/pltgot-2.d: Likewise.
+
2015-06-23 Jiong Wang <jiong.wang@arm.com>
* ld-aarch64/dt_textrel.s: New testcase.
diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
index a26cffd..61f9599 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -525,3 +525,4 @@ if { !([istarget "i?86-*-linux*"]
# Linux only tests
run_dump_test "pltgot-1"
+run_dump_test "pltgot-2"
diff --git a/ld/testsuite/ld-i386/pltgot-1.d b/ld/testsuite/ld-i386/pltgot-1.d
index 6629635..165ae33 100644
--- a/ld/testsuite/ld-i386/pltgot-1.d
+++ b/ld/testsuite/ld-i386/pltgot-1.d
@@ -2,7 +2,8 @@
#readelf: -S --wide
#as: --32
-#failif
#...
- +\[ [0-9]+\] \.plt +PROGBITS +.*
+ +\[ *[0-9]+\] \.plt +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+10 +.*
#...
+ +\[ *[0-9]+\] \.got\.plt +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+c +.*
+#pass
diff --git a/ld/testsuite/ld-i386/pltgot-2.d b/ld/testsuite/ld-i386/pltgot-2.d
new file mode 100644
index 0000000..3b87898
--- /dev/null
+++ b/ld/testsuite/ld-i386/pltgot-2.d
@@ -0,0 +1,9 @@
+#source: pltgot-1.s
+#ld: -shared -melf_i386
+#readelf: -d --wide
+#as: --32
+
+#failif
+#...
+ +0x[0-9a-f]+ +\(PLTREL.*
+#...
diff --git a/ld/testsuite/ld-x86-64/pltgot-1.d b/ld/testsuite/ld-x86-64/pltgot-1.d
index 9a6c2fd6..17d4f43 100644
--- a/ld/testsuite/ld-x86-64/pltgot-1.d
+++ b/ld/testsuite/ld-x86-64/pltgot-1.d
@@ -2,7 +2,8 @@
#readelf: -S --wide
#as: --64
-#failif
#...
- +\[ [0-9]+\] \.plt +PROGBITS +.*
+ +\[ *[0-9]+\] \.plt +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+10 +.*
#...
+ +\[ *[0-9]+\] \.got\.plt +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+18 +.*
+#pass
diff --git a/ld/testsuite/ld-x86-64/pltgot-2.d b/ld/testsuite/ld-x86-64/pltgot-2.d
new file mode 100644
index 0000000..086d6dd
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pltgot-2.d
@@ -0,0 +1,9 @@
+#source: pltgot-1.s
+#ld: -shared -melf_x86_64
+#readelf: -d --wide
+#as: --64
+
+#failif
+#...
+ +0x[0-9a-f]+ +\(PLTREL.*
+#...
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index 8281dc4..3669446 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -574,3 +574,4 @@ if { ![istarget "x86_64-*-linux*"]} {
# Linux only tests
run_dump_test "pr17618"
run_dump_test "pltgot-1"
+run_dump_test "pltgot-2"
--
1.9.3