]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
PowerPC64 --plt-align
authorAlan Modra <amodra@gmail.com>
Sat, 9 Sep 2017 12:25:22 +0000 (21:55 +0930)
committerAlan Modra <amodra@gmail.com>
Sun, 10 Sep 2017 08:52:20 +0000 (18:22 +0930)
This changes the PowerPC64 --plt-align option to perform the usual
alignment of code as suggested by its name, as well as the previous
behaviour of padding so as to reduce boundary crossing.  The old
behaviour is had by using a negative parameter.

The default is also changed to align plt stub code by default to 32
byte boundaries, the point being to get better bctr branch prediction
on power8 and power9 hardware.

bfd/
* elf64-ppp.c (plt_stub_pad): Handle positive and negative
plt_stub_align.
ld/
* ld.texinfo (--plt-align): Describe new behaviour of option.
* emultempl/ppc64elf.em (params): Default plt_stub_align to 5.
* testsuite/ld-powerpc/powerpc.exp: Pass --no-plt-align for
selected tests.
* testsuite/ld-powerpc/relbrlt.d: Pass --no-plt-align.
* testsuite/ld-powerpc/elfv2so.d: Adjust expected output.

(cherry picked from commit 2420fff633eff03ec1f85eba82a926cd0ecf4229)
(and commit bab55c05 for part of elfv2so.d change)

bfd/ChangeLog
bfd/elf64-ppc.c
ld/ChangeLog
ld/emultempl/ppc64elf.em
ld/ld.texinfo
ld/testsuite/ld-powerpc/elfv2so.d
ld/testsuite/ld-powerpc/powerpc.exp
ld/testsuite/ld-powerpc/relbrlt.d

index a78e8192aeb8a32a94b110a4df77df88bf360385..708a4bf8f76d1aa6665680e6c795298a069c6dc2 100644 (file)
@@ -1,3 +1,8 @@
+2017-09-10  Alan Modra  <amodra@gmail.com>
+
+       * elf64-ppp.c (plt_stub_pad): Handle positive and negative
+       plt_stub_align.
+
 2017-09-09  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR binutils/22018
index 4ff3f064f3998cd6b644a1a9760ef00e8f06bf15..3f01ae62a190c95ef36d124146a9c9f07f97309c 100644 (file)
@@ -10606,17 +10606,30 @@ plt_stub_size (struct ppc_link_hash_table *htab,
   return size;
 }
 
-/* If this stub would cross fewer 2**plt_stub_align boundaries if we align,
-   then return the padding needed to do so.  */
+/* Depending on the sign of plt_stub_align:
+   If positive, return the padding to align to a 2**plt_stub_align
+   boundary.
+   If negative, if this stub would cross fewer 2**plt_stub_align
+   boundaries if we align, then return the padding needed to do so.  */
+
 static inline unsigned int
 plt_stub_pad (struct ppc_link_hash_table *htab,
              struct ppc_stub_hash_entry *stub_entry,
              bfd_vma plt_off)
 {
-  int stub_align = 1 << htab->params->plt_stub_align;
+  int stub_align;
   unsigned stub_size = plt_stub_size (htab, stub_entry, plt_off);
   bfd_vma stub_off = stub_entry->group->stub_sec->size;
 
+  if (htab->params->plt_stub_align >= 0)
+    {
+      stub_align = 1 << htab->params->plt_stub_align;
+      if ((stub_off & (stub_align - 1)) != 0)
+       return stub_align - (stub_off & (stub_align - 1));
+      return 0;
+    }
+
+  stub_align = 1 << -htab->params->plt_stub_align;
   if (((stub_off + stub_size - 1) & -stub_align) - (stub_off & -stub_align)
       > ((stub_size - 1) & -stub_align))
     return stub_align - (stub_off & (stub_align - 1));
index e8ee459241054b299c440ee066780606a9364727..f1acd5b6d328c4c68e3c934a8d32dd17f573748d 100644 (file)
@@ -1,3 +1,12 @@
+2017-09-10  Alan Modra  <amodra@gmail.com>
+
+       * ld.texinfo (--plt-align): Describe new behaviour of option.
+       * emultempl/ppc64elf.em (params): Default plt_stub_align to 5.
+       * testsuite/ld-powerpc/powerpc.exp: Pass --no-plt-align for
+       selected tests.
+       * testsuite/ld-powerpc/relbrlt.d: Pass --no-plt-align.
+       * testsuite/ld-powerpc/elfv2so.d: Adjust expected output.
+
 2017-09-04  Nick Clifton  <nickc@redhat.com>
 
        Import from mainline:
index 58cb798cb1254955ef810462f2bdbe0fe4bc2c7d..cf75957fa9cc987eeea614079bf2970f5f5de155 100644 (file)
@@ -37,7 +37,7 @@ static struct ppc64_elf_params params = { NULL,
                                          &ppc_add_stub_section,
                                          &ppc_layout_sections_again,
                                          1, -1, 0,
-                                         ${DEFAULT_PLT_STATIC_CHAIN-0}, -1, 0,
+                                         ${DEFAULT_PLT_STATIC_CHAIN-0}, -1, 5,
                                          -1, 0, -1, -1, 0};
 
 /* Fake input file for stubs.  */
index 5d0b007ffa5ea083784412ca5809f159fe3e171a..950c79470889a548d238a6248de1ae68c2ccdc57 100644 (file)
@@ -7572,10 +7572,12 @@ off this feature.
 @item --plt-align
 @itemx --no-plt-align
 Use these options to control whether individual PLT call stubs are
-padded so that they don't cross a 32-byte boundary, or to the
-specified power of two boundary when using @code{--plt-align=}.  Note
-that this isn't alignment in the usual sense.  By default PLT call
-stubs are packed tightly.
+aligned to a 32-byte boundary, or to the specified power of two
+boundary when using @code{--plt-align=}.  A negative value may be
+specified to pad PLT call stubs so that they do not cross the
+specified power of two boundary (or the minimum number of boundaries
+if a PLT stub is so large that it must cross a boundary).  By default
+PLT call stubs are aligned to 32-byte boundaries.
 
 @cindex PowerPC64 PLT call stub static chain
 @kindex --plt-static-chain
index f3962ac04134aa79e88a642bf88bfe8bee14d3cc..a577b2a7ea8db6dc1b17537ba8c58259f1c6cebb 100644 (file)
@@ -7,53 +7,57 @@
 
 Disassembly of section \.text:
 
-0+300 <.*\.plt_call\.f4>:
+.* <.*\.plt_call\.f4>:
 .*:    (f8 41 00 18|18 00 41 f8)       std     r2,24\(r1\)
 .*:    (e9 82 80 38|38 80 82 e9)       ld      r12,-32712\(r2\)
 .*:    (7d 89 03 a6|a6 03 89 7d)       mtctr   r12
 .*:    (4e 80 04 20|20 04 80 4e)       bctr
+       \.\.\.
 
-0+310 <.*\.plt_call\.f3>:
+.* <.*\.plt_call\.f3>:
 .*:    (f8 41 00 18|18 00 41 f8)       std     r2,24\(r1\)
 .*:    (e9 82 80 28|28 80 82 e9)       ld      r12,-32728\(r2\)
 .*:    (7d 89 03 a6|a6 03 89 7d)       mtctr   r12
 .*:    (4e 80 04 20|20 04 80 4e)       bctr
+       \.\.\.
 
-0+320 <.*\.plt_call\.f2>:
+.* <.*\.plt_call\.f2>:
 .*:    (f8 41 00 18|18 00 41 f8)       std     r2,24\(r1\)
 .*:    (e9 82 80 30|30 80 82 e9)       ld      r12,-32720\(r2\)
 .*:    (7d 89 03 a6|a6 03 89 7d)       mtctr   r12
 .*:    (4e 80 04 20|20 04 80 4e)       bctr
+       \.\.\.
 
-0+330 <.*\.plt_call\.f1>:
+.* <.*\.plt_call\.f1>:
 .*:    (f8 41 00 18|18 00 41 f8)       std     r2,24\(r1\)
 .*:    (e9 82 80 40|40 80 82 e9)       ld      r12,-32704\(r2\)
 .*:    (7d 89 03 a6|a6 03 89 7d)       mtctr   r12
 .*:    (4e 80 04 20|20 04 80 4e)       bctr
+       \.\.\.
 
-0+340 <f1>:
+.* <f1>:
 .*:    (3c 4c 00 02|02 00 4c 3c)       addis   r2,r12,2
-.*:    (38 42 82 c0|c0 82 42 38)       addi    r2,r2,-32064
+.*:    (38 42 .. ..|.. .. 42 38)       addi    r2,r2,.*
 .*:    (7c 08 02 a6|a6 02 08 7c)       mflr    r0
 .*:    (f8 21 ff e1|e1 ff 21 f8)       stdu    r1,-32\(r1\)
 .*:    (f8 01 00 30|30 00 01 f8)       std     r0,48\(r1\)
-.*:    (4b ff ff dd|dd ff ff 4b)       bl      .*\.plt_call\.f1>
+.*:    (4b ff ff cd|cd ff ff 4b)       bl      .*\.plt_call\.f1>
 .*:    (e8 62 80 08|08 80 62 e8)       ld      r3,-32760\(r2\)
-.*:    (4b ff ff c5|c5 ff ff 4b)       bl      .*\.plt_call\.f2>
+.*:    (4b ff ff a5|a5 ff ff 4b)       bl      .*\.plt_call\.f2>
 .*:    (e8 41 00 18|18 00 41 e8)       ld      r2,24\(r1\)
 .*:    (e8 62 80 10|10 80 62 e8)       ld      r3,-32752\(r2\)
-.*:    (4b ff ff a9|a9 ff ff 4b)       bl      .*\.plt_call\.f3>
+.*:    (4b ff ff 79|79 ff ff 4b)       bl      .*\.plt_call\.f3>
 .*:    (e8 41 00 18|18 00 41 e8)       ld      r2,24\(r1\)
-.*:    (4b ff ff 91|91 ff ff 4b)       bl      .*\.plt_call\.f4>
+.*:    (4b ff ff 51|51 ff ff 4b)       bl      .*\.plt_call\.f4>
 .*:    (e8 41 00 18|18 00 41 e8)       ld      r2,24\(r1\)
 .*:    (e8 01 00 30|30 00 01 e8)       ld      r0,48\(r1\)
 .*:    (38 21 00 20|20 00 21 38)       addi    r1,r1,32
 .*:    (7c 08 03 a6|a6 03 08 7c)       mtlr    r0
 .*:    (4e 80 00 20|20 00 80 4e)       blr
-.*:    (00 00 00 00|80 02 01 00)       .*
-.*:    (00 01 02 80|00 00 00 00)       .*
+.*
+.*
 
-0+390 <__glink_PLTresolve>:
+.* <__glink_PLTresolve>:
 .*:    (7c 08 02 a6|a6 02 08 7c)       mflr    r0
 .*:    (42 9f 00 05|05 00 9f 42)       bcl     .*
 .*:    (7d 68 02 a6|a6 02 68 7d)       mflr    r11
index 6249ccbdb9f86edf360544ff3073b3c7dc6f0448..cfbc7b2001a32b1bfc07ad8841a8b28e172f6e1a 100644 (file)
@@ -156,22 +156,22 @@ set ppcelftests {
 }
 
 set ppc64elftests {
-    {"TLS static exec" "-melf64ppc" "" "-a64"  {tls.s tlslib.s}
+    {"TLS static exec" "-melf64ppc --no-plt-align" "" "-a64"  {tls.s tlslib.s}
      {{objdump -dr tls.d} {objdump -sj.got tls.g} {objdump -sj.tdata tls.t}}
       "tls"}
     {"TLS helper shared library" "-shared -melf64ppc tmpdir/tlslib.o" "" "" {}
      {} "libtlslib.so"}
     {"TLS helper old shared lib" "-shared -melf64ppc" "" "-a64" {oldtlslib.s}
      {} "liboldlib.so"}
-    {"TLS dynamic exec" "-melf64ppc --no-ld-generated-unwind-info tmpdir/tls.o tmpdir/libtlslib.so" "" "" {}
+    {"TLS dynamic exec" "-melf64ppc --no-plt-align --no-ld-generated-unwind-info tmpdir/tls.o tmpdir/libtlslib.so" "" "" {}
      {{readelf -WSsrl tlsexe.r} {objdump -dr tlsexe.d}
       {objdump -sj.got tlsexe.g} {objdump -sj.tdata tlsexe.t}}
       "tlsexe"}
-    {"TLS dynamic old" "-melf64ppc --no-ld-generated-unwind-info tmpdir/tls.o tmpdir/liboldlib.so" "" "" {}
+    {"TLS dynamic old" "-melf64ppc --no-plt-align --no-ld-generated-unwind-info tmpdir/tls.o tmpdir/liboldlib.so" "" "" {}
      {{readelf -WSsrl tlsexe.r} {objdump -dr tlsexe.d}
       {objdump -sj.got tlsexe.g} {objdump -sj.tdata tlsexe.t}}
       "tlsexeold"}
-    {"TLS shared" "-shared -melf64ppc --no-ld-generated-unwind-info tmpdir/tls.o" "" "" {}
+    {"TLS shared" "-shared -melf64ppc --no-plt-align --no-ld-generated-unwind-info tmpdir/tls.o" "" "" {}
      {{readelf -WSsrl tlsso.r} {objdump -dr tlsso.d}
       {objdump -sj.got tlsso.g} {objdump -sj.tdata tlsso.t}}
       "tls.so"}
@@ -179,17 +179,17 @@ set ppc64elftests {
      {{objdump -dr tlstoc.d} {objdump -sj.got tlstoc.g}
       {objdump -sj.tdata tlstoc.t}}
       "tlstoc"}
-    {"TLSTOC dynamic exec" "-melf64ppc --no-ld-generated-unwind-info tmpdir/tlstoc.o tmpdir/libtlslib.so" ""
+    {"TLSTOC dynamic exec" "-melf64ppc --no-plt-align --no-ld-generated-unwind-info tmpdir/tlstoc.o tmpdir/libtlslib.so" ""
      "" {}
      {{readelf -WSsrl tlsexetoc.r} {objdump -dr tlsexetoc.d}
       {objdump -sj.got tlsexetoc.g} {objdump -sj.tdata tlsexetoc.t}}
       "tlsexetoc"}
-    {"TLSTOC dynamic old" "-melf64ppc --no-ld-generated-unwind-info tmpdir/tlstoc.o tmpdir/liboldlib.so" ""
+    {"TLSTOC dynamic old" "-melf64ppc --no-plt-align --no-ld-generated-unwind-info tmpdir/tlstoc.o tmpdir/liboldlib.so" ""
      "" {}
      {{readelf -WSsrl tlsexetoc.r} {objdump -dr tlsexetoc.d}
       {objdump -sj.got tlsexetoc.g} {objdump -sj.tdata tlsexetoc.t}}
       "tlsexetocold"}
-    {"TLSTOC shared" "-shared -melf64ppc --no-ld-generated-unwind-info tmpdir/tlstoc.o" "" "" {}
+    {"TLSTOC shared" "-shared -melf64ppc --no-plt-align --no-ld-generated-unwind-info tmpdir/tlstoc.o" "" "" {}
      {{readelf -WSsrl tlstocso.r} {objdump -dr tlstocso.d}
       {objdump -sj.got tlstocso.g} {objdump -sj.tdata tlstocso.t}}
       "tlstoc.so"}
@@ -210,7 +210,7 @@ set ppc64elftests {
       "tlsopt4"}
     {"TLS DLL" "-shared -melf64ppc --version-script tlsdll.ver" "" "-a64" {tlsdll.s}
      {} "tlsdll.so"}
-    {"TLS opt 5" "-melf64ppc -shared --gc-sections --no-plt-localentry tmpdir/tlsdll.so" "" "-a64"  {tlsopt5.s}
+    {"TLS opt 5" "-melf64ppc --no-plt-align -shared --gc-sections --no-plt-localentry tmpdir/tlsdll.so" "" "-a64"  {tlsopt5.s}
      {{objdump -dr tlsopt5.d} {readelf -wf tlsopt5.wf}}
       "tlsopt5"}
     {"sym@tocbase" "-shared -melf64ppc" "" "-a64" {symtocbase-1.s symtocbase-2.s}
index a5f2437d08379eaf70b3dac81b19713f6656c757..a00b1ffd0c593d7b2b27f3b36d440b61aeef52a0 100644 (file)
@@ -1,6 +1,6 @@
 #source: relbrlt.s
 #as: -a64
-#ld: -melf64ppc --no-ld-generated-unwind-info --emit-relocs
+#ld: -melf64ppc --no-plt-align --no-ld-generated-unwind-info --emit-relocs
 #objdump: -Dr
 
 .*