Don't allocate .got.plt section if there are no GOT nor PLT entries.
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 14 Jul 2010 00:30:57 +0000 (00:30 +0000)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 14 Jul 2010 00:30:57 +0000 (00:30 +0000)
bfd/

2010-07-13  H.J. Lu  <hongjiu.lu@intel.com>

PR ld/11812
* elf32-i386.c (elf_i386_size_dynamic_sections): Don't
 allocate .got.plt section if there are no GOT nor PLT
 entries.
 * elf64-x86-64.c (elf64_x86_64_size_dynamic_sections): Likewise.

ld/testsuite/

2010-07-13  H.J. Lu  <hongjiu.lu@intel.com>

PR ld/11812
* ld-elf/exclude3b.d: Don't run on ia64-*-*.  Replace .got with
.dynamic.

* ld-elf/exclude3d.d: New.
* ld-i386/nogot1.d: Likewise.
* ld-i386/nogot1.s: Likewise.
* ld-x86-64/nogot1.d: Likewise.
* ld-x86-64/nogot1.s: Likewise.

* ld-i386/i386.exp: Run nogot1.
* ld-x86-64/x86-64.exp: Likewise.

12 files changed:
bfd/ChangeLog
bfd/elf32-i386.c
bfd/elf64-x86-64.c
ld/testsuite/ChangeLog
ld/testsuite/ld-elf/exclude3b.d
ld/testsuite/ld-elf/exclude3d.d [new file with mode: 0644]
ld/testsuite/ld-i386/i386.exp
ld/testsuite/ld-i386/nogot1.d [new file with mode: 0644]
ld/testsuite/ld-i386/nogot1.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/nogot1.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/nogot1.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/x86-64.exp

index e12771ae94c411b5aa126e422f6bde3f559548ed..26b38aec471272857292d15e30f15ab783fdd371 100644 (file)
@@ -1,3 +1,11 @@
+2010-07-13  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/11812
+       * elf32-i386.c (elf_i386_size_dynamic_sections): Don't
+        allocate .got.plt section if there are no GOT nor PLT
+        entries.
+        * elf64-x86-64.c (elf64_x86_64_size_dynamic_sections): Likewise.
+
 2010-07-13  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/11791
index ac9bdb63eb3294c9f2b4ff4819c547d64177a7cf..0ff31471f3efda6be5c5050483b5ee526518d368 100644 (file)
@@ -2555,6 +2555,23 @@ elf_i386_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
   if (htab->elf.srelplt)
     htab->sgotplt_jump_table_size = htab->next_tls_desc_index * 4;
 
+  if (htab->elf.sgotplt)
+    {
+      /* Don't allocate .got.plt section if there are no GOT nor PLT
+         entries.  */
+      if ((htab->elf.sgotplt->size
+          == get_elf_backend_data (output_bfd)->got_header_size)
+         && (htab->elf.splt == NULL
+             || htab->elf.splt->size == 0)
+         && (htab->elf.sgot == NULL
+             || htab->elf.sgot->size == 0)
+         && (htab->elf.iplt == NULL
+             || htab->elf.iplt->size == 0)
+         && (htab->elf.igotplt == NULL
+             || htab->elf.igotplt->size == 0))
+       htab->elf.sgotplt->size = 0;
+    }
+
   /* We now have determined the sizes of the various dynamic sections.
      Allocate memory for them.  */
   relocs = FALSE;
index 108f2578fd6953bae02a75882c74e51d451e0b12..b0bc5c012513d694789a11ccdbbab4d8a01b1e70 100644 (file)
@@ -2374,6 +2374,23 @@ elf64_x86_64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
        }
     }
 
+  if (htab->elf.sgotplt)
+    {
+      /* Don't allocate .got.plt section if there are no GOT nor PLT
+         entries.  */
+      if ((htab->elf.sgotplt->size
+          == get_elf_backend_data (output_bfd)->got_header_size)
+         && (htab->elf.splt == NULL
+             || htab->elf.splt->size == 0)
+         && (htab->elf.sgot == NULL
+             || htab->elf.sgot->size == 0)
+         && (htab->elf.iplt == NULL
+             || htab->elf.iplt->size == 0)
+         && (htab->elf.igotplt == NULL
+             || htab->elf.igotplt->size == 0))
+       htab->elf.sgotplt->size = 0;
+    }
+
   /* We now have determined the sizes of the various dynamic sections.
      Allocate memory for them.  */
   relocs = FALSE;
index a1f9e6b1541d390da615ecf0a91fe94e36ca5264..71ce0e6f188a435aaacf32f478f41e574625b0d1 100644 (file)
@@ -1,3 +1,18 @@
+2010-07-13  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/11812
+       * ld-elf/exclude3b.d: Don't run on ia64-*-*.  Replace .got with
+       .dynamic.
+
+       * ld-elf/exclude3d.d: New.
+       * ld-i386/nogot1.d: Likewise.
+       * ld-i386/nogot1.s: Likewise.
+       * ld-x86-64/nogot1.d: Likewise.
+       * ld-x86-64/nogot1.s: Likewise.
+
+       * ld-i386/i386.exp: Run nogot1.
+       * ld-x86-64/x86-64.exp: Likewise.
+
 2010-07-13  H.J. Lu  <hongjiu.lu@intel.com>
 
        * ld-i386/hidden2.d: Don't hard code expected output.
index f6404492fa843b56a924b8e0dd62d55d825f840e..8d8a43fd98e8fcab9ad572dec7484d5aea3e4b28 100644 (file)
@@ -1,9 +1,9 @@
 #source: exclude3.s
 #ld: --shared
 #readelf: -S --wide
-#target: x86_64-*-* i?86-*-* ia64-*-*
+#target: x86_64-*-* i?86-*-*
 
 #...
-[      ]*\[.*\][       ]+\.got.*[      ]+PROGBITS.*
+[      ]*\[.*\][       ]+\.dynamic[    ]+DYNAMIC.*
 [      ]*\[.*\][       ]+.*STRTAB.*
 #pass
diff --git a/ld/testsuite/ld-elf/exclude3d.d b/ld/testsuite/ld-elf/exclude3d.d
new file mode 100644 (file)
index 0000000..0d487f5
--- /dev/null
@@ -0,0 +1,9 @@
+#source: exclude3.s
+#ld: --shared
+#readelf: -S --wide
+#target: ia64-*-*
+
+#...
+[      ]*\[.*\][       ]+\.got.*[      ]+PROGBITS.*
+[      ]*\[.*\][       ]+.*STRTAB.*
+#pass
index a88a4363348b123b7f9b4935fcbd31201f654521..3f20533c3a9669144b9b18be96d61c68259674e5 100644 (file)
@@ -189,3 +189,4 @@ run_dump_test "protected1"
 run_dump_test "protected2"
 run_dump_test "protected3"
 run_dump_test "tlspie1"
+run_dump_test "nogot1"
diff --git a/ld/testsuite/ld-i386/nogot1.d b/ld/testsuite/ld-i386/nogot1.d
new file mode 100644 (file)
index 0000000..a6c8832
--- /dev/null
@@ -0,0 +1,8 @@
+#ld: --shared -melf_i386
+#readelf: -S --wide
+#as: --32
+
+#...
+[      ]*\[.*\][       ]+\.dynamic[    ]+DYNAMIC.*
+[      ]*\[.*\][       ]+.*STRTAB.*
+#pass
diff --git a/ld/testsuite/ld-i386/nogot1.s b/ld/testsuite/ld-i386/nogot1.s
new file mode 100644 (file)
index 0000000..c657231
--- /dev/null
@@ -0,0 +1,10 @@
+       .type   bar, @function
+bar:
+       ret
+       .size   bar, .-bar
+.globl foo
+       .type   foo, @function
+foo:
+       leal    bar@GOTOFF(%ecx), %eax
+       ret
+       .size   foo, .-foo
diff --git a/ld/testsuite/ld-x86-64/nogot1.d b/ld/testsuite/ld-x86-64/nogot1.d
new file mode 100644 (file)
index 0000000..f6c4cf1
--- /dev/null
@@ -0,0 +1,8 @@
+#ld: --shared -melf_x86_64
+#readelf: -S --wide
+#as: --64
+
+#...
+[      ]*\[.*\][       ]+\.dynamic[    ]+DYNAMIC.*
+[      ]*\[.*\][       ]+.*STRTAB.*
+#pass
diff --git a/ld/testsuite/ld-x86-64/nogot1.s b/ld/testsuite/ld-x86-64/nogot1.s
new file mode 100644 (file)
index 0000000..d884f6f
--- /dev/null
@@ -0,0 +1,10 @@
+       .type   bar, @function
+bar:
+       ret
+       .size   bar, .-bar
+.globl foo
+       .type   foo, @function
+foo:
+       leaq    bar(%rip), %rax
+       ret
+       .size   foo, .-foo
index a8ebd4119f64c2d90e61e1a6780b783508f7a48b..76ac47463c52123c5777c9395d3acb2648aedc80 100644 (file)
@@ -98,3 +98,4 @@ run_dump_test "protected3-l1om"
 run_dump_test "tlsle1"
 run_dump_test "tlspie1"
 run_dump_test "unique1"
+run_dump_test "nogot1"