From: Alan Modra Date: Sat, 9 Sep 2017 12:25:22 +0000 (+0930) Subject: PowerPC64 --plt-align X-Git-Tag: binutils-2_29_1~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=38d47c2247aea860c41aa4bdddc4bed34e378731;p=thirdparty%2Fbinutils-gdb.git PowerPC64 --plt-align 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) --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index a78e8192aeb..708a4bf8f76 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,8 @@ +2017-09-10 Alan Modra + + * elf64-ppp.c (plt_stub_pad): Handle positive and negative + plt_stub_align. + 2017-09-09 H.J. Lu PR binutils/22018 diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c index 4ff3f064f39..3f01ae62a19 100644 --- a/bfd/elf64-ppc.c +++ b/bfd/elf64-ppc.c @@ -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)); diff --git a/ld/ChangeLog b/ld/ChangeLog index e8ee4592410..f1acd5b6d32 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,12 @@ +2017-09-10 Alan Modra + + * 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 Import from mainline: diff --git a/ld/emultempl/ppc64elf.em b/ld/emultempl/ppc64elf.em index 58cb798cb12..cf75957fa9c 100644 --- a/ld/emultempl/ppc64elf.em +++ b/ld/emultempl/ppc64elf.em @@ -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. */ diff --git a/ld/ld.texinfo b/ld/ld.texinfo index 5d0b007ffa5..950c7947088 100644 --- a/ld/ld.texinfo +++ b/ld/ld.texinfo @@ -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 diff --git a/ld/testsuite/ld-powerpc/elfv2so.d b/ld/testsuite/ld-powerpc/elfv2so.d index f3962ac0413..a577b2a7ea8 100644 --- a/ld/testsuite/ld-powerpc/elfv2so.d +++ b/ld/testsuite/ld-powerpc/elfv2so.d @@ -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 : +.* : .*: (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 diff --git a/ld/testsuite/ld-powerpc/powerpc.exp b/ld/testsuite/ld-powerpc/powerpc.exp index 6249ccbdb9f..cfbc7b2001a 100644 --- a/ld/testsuite/ld-powerpc/powerpc.exp +++ b/ld/testsuite/ld-powerpc/powerpc.exp @@ -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} diff --git a/ld/testsuite/ld-powerpc/relbrlt.d b/ld/testsuite/ld-powerpc/relbrlt.d index a5f2437d083..a00b1ffd0c5 100644 --- a/ld/testsuite/ld-powerpc/relbrlt.d +++ b/ld/testsuite/ld-powerpc/relbrlt.d @@ -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 .*