Don't generate PLT relocations for now binding
authorH.J. Lu <hjl.tools@gmail.com>
Sat, 16 May 2015 14:00:21 +0000 (07:00 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Sat, 16 May 2015 14:00:55 +0000 (07:00 -0700)
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/ChangeLog
bfd/elf32-i386.c
bfd/elf64-x86-64.c
ld/testsuite/ChangeLog
ld/testsuite/ld-i386/i386.exp
ld/testsuite/ld-i386/pr17689now.rd [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr17689now.rd [new file with mode: 0644]
ld/testsuite/ld-x86-64/x86-64.exp

index 3cc88398082e8a0be1c679898115cab40304ee4f..3727e35b59d1722806a532beea90e096bc3264b6 100644 (file)
@@ -1,3 +1,14 @@
+2015-05-16  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * 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.
+
 2015-05-14  H.J. Lu  <hongjiu.lu@intel.com>
 
        * bfd.c (bfd_update_compression_header): Also write the zlib
index 815473dcde47ec543ac5aa3639928116929346ad..c6ff7463a359ebf7299c485239d56a3fcbb689ef 100644 (file)
@@ -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.  */
index e9b560184c74e921db752e6ce93268d2ec5393c6..01df2308ea4b90a5decf49e07c75ffb102a0b26d 100644 (file)
@@ -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.  */
index 43c7c2488a5772fb1882fd369b8e1a6d9966d86d..e6a551c7728850bb82fb97ebbf7eeb785c1c1339 100644 (file)
@@ -1,3 +1,10 @@
+2015-05-16  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * 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
+
 2015-05-15  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR binutis/18386
index bbc6005160a78447b1f2b54d3920f2f212266e6f..a26cffd3abc94fea0ae2b7276eea102fa09ae3b6 100644 (file)
@@ -405,6 +405,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" \
@@ -429,6 +437,14 @@ if { [isnative]
            {{readelf {-Wr} pr17689.rd}} \
            "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" \
@@ -483,6 +499,14 @@ if { [isnative]
            "pr17689" \
            "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 (file)
index 0000000..9741df8
--- /dev/null
@@ -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 (file)
index 0000000..8fd9371
--- /dev/null
@@ -0,0 +1,4 @@
+#failif
+#...
+[0-9a-f ]+R_X86_64_JUMP_SLOT +0+ +.*
+#...
index a312271431405dfe139a36ce123e2b098e98849b..8281dc43f1f7b761718896e7fd4dc3749650f794 100644 (file)
@@ -439,6 +439,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" \
@@ -447,6 +455,14 @@ if { [isnative] && [which $CC] != 0 } {
            {{readelf {-Wr} pr17689.rd}} \
            "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*"] \