Allocate the first .plt entry space only if needed
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 12 May 2015 20:11:48 +0000 (13:11 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 12 May 2015 20:11:48 +0000 (13:11 -0700)
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
bfd/elf32-i386.c
bfd/elf64-x86-64.c
ld/testsuite/ChangeLog
ld/testsuite/ld-i386/i386.exp
ld/testsuite/ld-i386/pltgot-1.d [new file with mode: 0644]
ld/testsuite/ld-i386/pltgot-1.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/pltgot-1.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pltgot-1.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/x86-64.exp

index d27830bdd2f6af77c589cc6d73092bf32a4920e6..398476b613855643c3c72f3490c08effc0a88483 100644 (file)
@@ -1,3 +1,9 @@
+2015-05-12  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * 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.
+
 2015-05-11  H.J. Lu  <hongjiu.lu@intel.com>
 
        * Makefile.am (ALL_MACHINES): Add cpu-iamcu.lo.
index f7a7818248dacb534342318f804f88b269cff9f4..815473dcde47ec543ac5aa3639928116929346ad 100644 (file)
@@ -2338,15 +2338,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.  */
-         if (s->size == 0)
-           s->size = plt_entry_size;
-
          if (use_plt_got)
            eh->plt_got.offset = got_s->size;
          else
-           h->plt.offset = s->size;
+           {
+             /* 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 this symbol is not defined in a regular file, and we are
             not generating a shared library, then set the symbol to this
index 34e0f835cddccd1300954365af83ccea4c963e4f..e9b560184c74e921db752e6ce93268d2ec5393c6 100644 (file)
@@ -2558,15 +2558,14 @@ 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.  */
-         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;
index 89f695cb2ac3f2df33752d42c2dbdbfcad296972..f7bd9b7327c93958a5502053443e28ce0b38c9d5 100644 (file)
@@ -1,3 +1,12 @@
+2015-05-12  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * 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.
+
 2015-05-11  H.J. Lu  <hongjiu.lu@intel.com>
 
        * ld-i386/i386.exp (iamcu_tests): Run iamcu-4.
index 2e59522f95957bc70c7863b108f43c83267f397e..bbc6005160a78447b1f2b54d3920f2f212266e6f 100644 (file)
@@ -493,3 +493,11 @@ if { [isnative]
        ] \
     ]
 }
+
+if { !([istarget "i?86-*-linux*"]
+       || [istarget "x86_64-*-linux*"]) } {
+    return
+}
+
+# Linux only tests
+run_dump_test "pltgot-1"
diff --git a/ld/testsuite/ld-i386/pltgot-1.d b/ld/testsuite/ld-i386/pltgot-1.d
new file mode 100644 (file)
index 0000000..6629635
--- /dev/null
@@ -0,0 +1,8 @@
+#ld: -shared -melf_i386
+#readelf: -S --wide
+#as: --32
+
+#failif
+#...
+ +\[ [0-9]+\] \.plt +PROGBITS +.*
+#...
diff --git a/ld/testsuite/ld-i386/pltgot-1.s b/ld/testsuite/ld-i386/pltgot-1.s
new file mode 100644 (file)
index 0000000..0e23078
--- /dev/null
@@ -0,0 +1,6 @@
+       .text
+       .globl  plt     
+       .type   plt, @function
+plt:
+       call   *puts@GOT(%ebx)
+       jmp     puts@PLT
diff --git a/ld/testsuite/ld-x86-64/pltgot-1.d b/ld/testsuite/ld-x86-64/pltgot-1.d
new file mode 100644 (file)
index 0000000..9a6c2fd
--- /dev/null
@@ -0,0 +1,8 @@
+#ld: -shared -melf_x86_64
+#readelf: -S --wide
+#as: --64
+
+#failif
+#...
+ +\[ [0-9]+\] \.plt +PROGBITS +.*
+#...
diff --git a/ld/testsuite/ld-x86-64/pltgot-1.s b/ld/testsuite/ld-x86-64/pltgot-1.s
new file mode 100644 (file)
index 0000000..2197c75
--- /dev/null
@@ -0,0 +1,6 @@
+       .text
+       .globl  plt     
+       .type   plt, @function
+plt:
+       call   *puts@GOTPCREL(%rip)
+       jmp     puts@PLT
index 8352ad9591d0d6ba8cc4f9e811e9fb1a48ef6313..58e598e69c043e324922ae179489df1a18ec7bec 100644 (file)
@@ -549,3 +549,4 @@ if { ![istarget "x86_64-*-linux*"]} {
 
 # Linux only tests
 run_dump_test "pr17618"
+run_dump_test "pltgot-1"