Use ld --hash-style=gnu -O1. Document it in info and man pages. Test suites pass for x86 and x86_64. diff -Naur binutils-2.20.51.0.6.orig/ld/emultempl/elf32.em binutils-2.20.51.0.6/ld/emultempl/elf32.em --- binutils-2.20.51.0.6.orig/ld/emultempl/elf32.em 2010-02-07 14:12:21.000000000 +0000 +++ binutils-2.20.51.0.6/ld/emultempl/elf32.em 2010-03-07 18:23:52.446845477 +0000 @@ -2353,7 +2353,7 @@ fprintf (file, _("\ --eh-frame-hdr Create .eh_frame_hdr section\n")); fprintf (file, _("\ - --hash-style=STYLE Set hash style to sysv, gnu or both\n")); + --hash-style=STYLE Set hash style to sysv, gnu or both (default gnu)\n")); fprintf (file, _("\ -z combreloc Merge dynamic relocs into one section and sort\n")); fprintf (file, _("\ diff -Naur binutils-2.20.51.0.6.orig/ld/ld.texinfo binutils-2.20.51.0.6/ld/ld.texinfo --- binutils-2.20.51.0.6.orig/ld/ld.texinfo 2010-02-07 14:12:22.000000000 +0000 +++ binutils-2.20.51.0.6/ld/ld.texinfo 2010-03-07 18:23:52.450846257 +0000 @@ -818,12 +818,12 @@ @cindex generating optimized output @item -O @var{level} If @var{level} is a numeric values greater than zero @command{ld} optimizes -the output. This might take significantly longer and therefore probably -should only be enabled for the final binary. At the moment this +the output. This might take significantly longer. At the moment this option only affects ELF shared library generation. Future releases of the linker may make more use of this option. Also currently there is no difference in the linker's behaviour for different non-zero values -of this option. Again this may change with future releases. +of this option. Again this may change with future releases. This option +is enabled by default, and can be disabled with @option{-O0}. @kindex -q @kindex --emit-relocs @@ -2103,7 +2103,7 @@ @code{sysv} for classic ELF @code{.hash} section, @code{gnu} for new style GNU @code{.gnu.hash} section or @code{both} for both the classic ELF @code{.hash} and new style GNU @code{.gnu.hash} -hash tables. The default is @code{sysv}. +hash tables. The default is @code{gnu}. @kindex --reduce-memory-overheads @item --reduce-memory-overheads diff -Naur binutils-2.20.51.0.6.orig/ld/ldmain.c binutils-2.20.51.0.6/ld/ldmain.c --- binutils-2.20.51.0.6.orig/ld/ldmain.c 2010-02-07 14:12:22.000000000 +0000 +++ binutils-2.20.51.0.6/ld/ldmain.c 2010-03-07 18:23:52.450846257 +0000 @@ -277,7 +277,13 @@ link_info.keep_memory = TRUE; link_info.combreloc = TRUE; link_info.strip_discarded = TRUE; +#ifdef __mips__ link_info.emit_hash = TRUE; +#else + link_info.emit_hash = FALSE; + link_info.emit_gnu_hash = TRUE; +#endif + link_info.optimize = TRUE; link_info.callbacks = &link_callbacks; link_info.input_bfds_tail = &link_info.input_bfds; /* SVR4 linkers seem to set DT_INIT and DT_FINI based on magic _init diff -Naur binutils-2.20.51.0.6.orig/ld/lexsup.c binutils-2.20.51.0.6/ld/lexsup.c --- binutils-2.20.51.0.6.orig/ld/lexsup.c 2010-02-07 14:12:22.000000000 +0000 +++ binutils-2.20.51.0.6/ld/lexsup.c 2010-03-07 18:23:52.454846666 +0000 @@ -270,7 +270,7 @@ { {"output", required_argument, NULL, 'o'}, 'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES }, { {NULL, required_argument, NULL, '\0'}, - 'O', NULL, N_("Optimize output file"), ONE_DASH }, + 'O', NULL, N_("Optimize output file (default)"), ONE_DASH }, { {"Qy", no_argument, NULL, OPTION_IGNORE}, '\0', NULL, N_("Ignored for SVR4 compatibility"), ONE_DASH }, { {"emit-relocs", no_argument, NULL, 'q'}, diff -Naur binutils-2.20.51.0.6.orig/ld/testsuite/ld-arm/arm-elf.exp binutils-2.20.51.0.6/ld/testsuite/ld-arm/arm-elf.exp --- binutils-2.20.51.0.6.orig/ld/testsuite/ld-arm/arm-elf.exp 2010-02-07 14:10:42.000000000 +0000 +++ binutils-2.20.51.0.6/ld/testsuite/ld-arm/arm-elf.exp 2010-03-07 18:23:52.454846666 +0000 @@ -89,21 +89,21 @@ {"Non-pcrel function reference" "tmpdir/arm-lib.so" "" {arm-app-abs32.s} {{objdump -fdw arm-app-abs32.d} {objdump -Rw arm-app-abs32.r}} "arm-app-abs32"} - {"Thumb shared library with ARM entry points" "-shared -T arm-lib.ld" "-mthumb-interwork" + {"Thumb shared library with ARM entry points" "-shared -T arm-lib.ld -O0" "-mthumb-interwork" {mixed-lib.s} {{objdump -fdw armthumb-lib.d} {readelf -Ds armthumb-lib.sym}} "armthumb-lib.so"} - {"Mixed ARM/Thumb shared library" "-shared -T arm-lib.ld -use-blx" "" + {"Mixed ARM/Thumb shared library" "-shared -T arm-lib.ld -use-blx -O0" "" {mixed-lib.s} {{objdump -fdw mixed-lib.d} {objdump -Rw mixed-lib.r} {readelf -Ds mixed-lib.sym}} "mixed-lib.so"} - {"Mixed ARM/Thumb dynamic application" "tmpdir/mixed-lib.so -T arm-dyn.ld" "" + {"Mixed ARM/Thumb dynamic application" "tmpdir/mixed-lib.so -T arm-dyn.ld -O0" "" {mixed-app.s} {{objdump -fdw mixed-app.d} {objdump -Rw mixed-app.r} {readelf -Ds mixed-app.sym}} "mixed-app"} - {"Mixed ARM/Thumb arch5 dynamic application" "tmpdir/mixed-lib.so -T arm-dyn.ld --use-blx" "" + {"Mixed ARM/Thumb arch5 dynamic application" "tmpdir/mixed-lib.so -T arm-dyn.ld --use-blx -O0" "" {mixed-app.s} {{objdump -fdw mixed-app-v5.d} {objdump -Rw mixed-app.r} {readelf -Ds mixed-app.sym}} @@ -132,7 +132,7 @@ {"TLS shared library" "-shared -T arm-lib.ld" "" {tls-lib.s} {{objdump -fdw tls-lib.d} {objdump -Rw tls-lib.r}} "tls-lib.so"} - {"TLS dynamic application" "-T arm-dyn.ld tmpdir/tls-lib.so" "" {tls-app.s} + {"TLS dynamic application" "-T arm-dyn.ld tmpdir/tls-lib.so -O0" "" {tls-app.s} {{objdump -fdw tls-app.d} {objdump -Rw tls-app.r}} "tls-app"} {"Thumb entry point" "-T arm.ld" "" {thumb-entry.s} @@ -222,7 +222,7 @@ {"arm-pic-veneer" "-static -T arm.ld --pic-veneer" "" {arm-pic-veneer.s} {{objdump -d arm-pic-veneer.d}} "arm-pic-veneer"} - {"Preempt Thumb symbol" "tmpdir/mixed-lib.so -T arm-dyn.ld --use-blx" "" + {"Preempt Thumb symbol" "tmpdir/mixed-lib.so -T arm-dyn.ld --use-blx -O0" "" {preempt-app.s} {{readelf -Ds preempt-app.sym}} "preempt-app"} @@ -414,18 +414,18 @@ {{objdump -d farcall-group-limit.d}} "farcall-group-limit"} - {"Mixed ARM/Thumb dynamic application with farcalls" "tmpdir/mixed-lib.so -T arm-dyn.ld --section-start .far_arm=0x2100000 --section-start .far_thumb=0x2200000" "" + {"Mixed ARM/Thumb dynamic application with farcalls" "tmpdir/mixed-lib.so -T arm-dyn.ld --section-start .far_arm=0x2100000 --section-start .far_thumb=0x2200000 -O0" "" {farcall-mixed-app.s} {{objdump -fdw farcall-mixed-app.d} {objdump -Rw farcall-mixed-app.r} {readelf -Ds farcall-mixed-app.sym}} "farcall-mixed-app"} - {"Mixed ARM/Thumb arch5 dynamic application with farcalls" "tmpdir/mixed-lib.so -T arm-dyn.ld --use-blx --section-start .far_arm=0x2100000 --section-start .far_thumb=0x2200000" "" + {"Mixed ARM/Thumb arch5 dynamic application with farcalls" "tmpdir/mixed-lib.so -T arm-dyn.ld --use-blx --section-start .far_arm=0x2100000 --section-start .far_thumb=0x2200000 -O0" "" {farcall-mixed-app.s} {{objdump -fdw farcall-mixed-app-v5.d} {objdump -Rw farcall-mixed-app.r} {readelf -Ds farcall-mixed-app.sym}} "farcall-mixed-app-v5"} - {"Mixed ARM/Thumb shared library with long branches" "-shared -T arm-lib.ld" "" + {"Mixed ARM/Thumb shared library with long branches" "-shared -T arm-lib.ld -O0" "" {farcall-mixed-lib1.s farcall-mixed-lib2.s} {{objdump -fdw farcall-mixed-lib.d}} "farcall-mixed-lib.so"} diff -Naur binutils-2.20.51.0.6.orig/ld/testsuite/ld-elf/hash.d binutils-2.20.51.0.6/ld/testsuite/ld-elf/hash.d --- binutils-2.20.51.0.6.orig/ld/testsuite/ld-elf/hash.d 2009-10-09 22:25:28.000000000 +0000 +++ binutils-2.20.51.0.6/ld/testsuite/ld-elf/hash.d 2010-03-07 18:23:52.454846666 +0000 @@ -1,6 +1,6 @@ #source: start.s #readelf: -d -s -D -#ld: -shared --hash-style=gnu +#ld: -shared --hash-style=gnu -O0 #target: *-*-linux* #notarget: mips*-*-* diff -Naur binutils-2.20.51.0.6.orig/ld/testsuite/ld-elfvsb/hidden2.d binutils-2.20.51.0.6/ld/testsuite/ld-elfvsb/hidden2.d --- binutils-2.20.51.0.6.orig/ld/testsuite/ld-elfvsb/hidden2.d 2009-10-09 22:25:30.000000000 +0000 +++ binutils-2.20.51.0.6/ld/testsuite/ld-elfvsb/hidden2.d 2010-03-07 18:23:52.454846666 +0000 @@ -1,5 +1,5 @@ #source: hidden2.s -#ld: -shared -T hidden2.ld +#ld: -shared -T hidden2.ld --hash-style=sysv #readelf: -Ds # It is also ok to remove this symbol, but we currently make it local. diff -Naur binutils-2.20.51.0.6.orig/ld/testsuite/ld-i386/hidden2.d binutils-2.20.51.0.6/ld/testsuite/ld-i386/hidden2.d --- binutils-2.20.51.0.6.orig/ld/testsuite/ld-i386/hidden2.d 2008-04-03 16:54:05.000000000 +0000 +++ binutils-2.20.51.0.6/ld/testsuite/ld-i386/hidden2.d 2010-03-07 18:23:52.454846666 +0000 @@ -1,5 +1,5 @@ #as: --32 -#ld: -shared -melf_i386 +#ld: -shared -melf_i386 -O0 --hash-style=sysv #objdump: -drw .*: +file format .* diff -Naur binutils-2.20.51.0.6.orig/ld/testsuite/ld-i386/i386.exp binutils-2.20.51.0.6/ld/testsuite/ld-i386/i386.exp --- binutils-2.20.51.0.6.orig/ld/testsuite/ld-i386/i386.exp 2009-09-08 17:11:37.000000000 +0000 +++ binutils-2.20.51.0.6/ld/testsuite/ld-i386/i386.exp 2010-03-07 18:23:52.454846666 +0000 @@ -117,40 +117,40 @@ # readelf: Apply readelf options on result. Compare with regex (last arg). set i386tests { - {"TLS -fpic -shared transitions" "-shared -melf_i386" + {"TLS -fpic -shared transitions" "-shared -melf_i386 --hash-style=sysv" "--32" {tlspic1.s tlspic2.s} {{readelf -Ssrl tlspic.rd} {objdump -drj.text tlspic.dd} {objdump -sj.got tlspic.sd} {objdump -sj.tdata tlspic.td}} "libtlspic.so"} - {"TLS descriptor -fpic -shared transitions" "-shared -melf_i386" + {"TLS descriptor -fpic -shared transitions" "-shared -melf_i386 --hash-style=sysv -O0" "--32" {tlsdesc.s tlspic2.s} {{readelf -Ssrl tlsdesc.rd} {objdump -drj.text tlsdesc.dd} {objdump "-s -j.got -j.got.plt" tlsdesc.sd} {objdump -sj.tdata tlsdesc.td}} "libtlsdesc.so"} - {"Helper shared library" "-shared -melf_i386" + {"Helper shared library" "-shared -melf_i386 --hash-style=sysv" "--32" {tlslib.s} {} "libtlslib.so"} {"TLS -fpic and -fno-pic exec transitions" - "-melf_i386 tmpdir/libtlslib.so" "--32" {tlsbinpic.s tlsbin.s} + "-melf_i386 tmpdir/libtlslib.so --hash-style=sysv" "--32" {tlsbinpic.s tlsbin.s} {{readelf -Ssrl tlsbin.rd} {objdump -drj.text tlsbin.dd} {objdump -sj.got tlsbin.sd} {objdump -sj.tdata tlsbin.td}} "tlsbin"} {"TLS descriptor -fpic and -fno-pic exec transitions" - "-melf_i386 tmpdir/libtlslib.so" "--32" {tlsbindesc.s tlsbin.s} + "-melf_i386 tmpdir/libtlslib.so --hash-style=sysv" "--32" {tlsbindesc.s tlsbin.s} {{readelf -Ssrl tlsbindesc.rd} {objdump -drj.text tlsbindesc.dd} {objdump -sj.got tlsbindesc.sd} {objdump -sj.tdata tlsbindesc.td}} "tlsbindesc"} - {"TLS -fno-pic -shared" "-shared -melf_i386" + {"TLS -fno-pic -shared" "-shared -melf_i386 --hash-style=sysv" "--32" {tlsnopic1.s tlsnopic2.s} {{readelf -Ssrl tlsnopic.rd} {objdump -drj.text tlsnopic.dd} {objdump -sj.got tlsnopic.sd}} "libtlsnopic.so"} {"TLS with global dynamic and descriptors" - "-shared -melf_i386" "--32" {tlsgdesc.s} + "-shared -melf_i386 --hash-style=sysv" "--32" {tlsgdesc.s} {{readelf -Ssrl tlsgdesc.rd} {objdump -drj.text tlsgdesc.dd}} "libtlsgdesc.so"} {"TLS in debug sections" "-melf_i386" "--32" {tlsg.s} {{objdump -sj.debug_foobar tlsg.sd}} "tlsg"} - {"TLS @indntpoff with %eax" "-melf_i386" "--32" {tlsindntpoff.s} + {"TLS @indntpoff with %eax" "-melf_i386 --hash-style=sysv" "--32" {tlsindntpoff.s} {{objdump -drj.text tlsindntpoff.dd}} "tlsindntpoff"} {"Reloc section order" "-shared -melf_i386 -z nocombreloc" "--32" {reloc.s} {{objdump -hw reloc.d}} "reloc.so"} diff -Naur binutils-2.20.51.0.6.orig/ld/testsuite/ld-ifunc/ifunc-1-local-x86.d binutils-2.20.51.0.6/ld/testsuite/ld-ifunc/ifunc-1-local-x86.d --- binutils-2.20.51.0.6.orig/ld/testsuite/ld-ifunc/ifunc-1-local-x86.d 2009-07-16 21:32:38.000000000 +0000 +++ binutils-2.20.51.0.6/ld/testsuite/ld-ifunc/ifunc-1-local-x86.d 2010-03-07 18:23:52.454846666 +0000 @@ -1,4 +1,4 @@ -#ld: -shared +#ld: -shared -O0 --hash-style=sysv #objdump: -dw #target: x86_64-*-* i?86-*-* diff -Naur binutils-2.20.51.0.6.orig/ld/testsuite/ld-ifunc/ifunc-1-x86.d binutils-2.20.51.0.6/ld/testsuite/ld-ifunc/ifunc-1-x86.d --- binutils-2.20.51.0.6.orig/ld/testsuite/ld-ifunc/ifunc-1-x86.d 2009-07-16 21:32:38.000000000 +0000 +++ binutils-2.20.51.0.6/ld/testsuite/ld-ifunc/ifunc-1-x86.d 2010-03-07 18:23:52.454846666 +0000 @@ -1,4 +1,4 @@ -#ld: -shared +#ld: -shared -O0 --hash-style=sysv #objdump: -dw #target: x86_64-*-* i?86-*-* diff -Naur binutils-2.20.51.0.6.orig/ld/testsuite/ld-ifunc/ifunc-2-local-x86-64.d binutils-2.20.51.0.6/ld/testsuite/ld-ifunc/ifunc-2-local-x86-64.d --- binutils-2.20.51.0.6.orig/ld/testsuite/ld-ifunc/ifunc-2-local-x86-64.d 2009-07-16 21:32:38.000000000 +0000 +++ binutils-2.20.51.0.6/ld/testsuite/ld-ifunc/ifunc-2-local-x86-64.d 2010-03-07 18:23:52.454846666 +0000 @@ -1,5 +1,5 @@ #as: --64 -#ld: -shared -melf_x86_64 +#ld: -shared -melf_x86_64 -O0 --hash-style=sysv #objdump: -dw #target: x86_64-*-* diff -Naur binutils-2.20.51.0.6.orig/ld/testsuite/ld-ifunc/ifunc-2-x86-64.d binutils-2.20.51.0.6/ld/testsuite/ld-ifunc/ifunc-2-x86-64.d --- binutils-2.20.51.0.6.orig/ld/testsuite/ld-ifunc/ifunc-2-x86-64.d 2009-07-16 21:32:38.000000000 +0000 +++ binutils-2.20.51.0.6/ld/testsuite/ld-ifunc/ifunc-2-x86-64.d 2010-03-07 18:23:52.454846666 +0000 @@ -1,5 +1,5 @@ #as: --64 -#ld: -shared -melf_x86_64 +#ld: -shared -melf_x86_64 -O0 --hash-style=sysv #objdump: -dw #target: x86_64-*-* diff -Naur binutils-2.20.51.0.6.orig/ld/testsuite/ld-ifunc/ifunc-3a-x86.d binutils-2.20.51.0.6/ld/testsuite/ld-ifunc/ifunc-3a-x86.d --- binutils-2.20.51.0.6.orig/ld/testsuite/ld-ifunc/ifunc-3a-x86.d 2009-07-16 21:32:38.000000000 +0000 +++ binutils-2.20.51.0.6/ld/testsuite/ld-ifunc/ifunc-3a-x86.d 2010-03-07 18:23:52.454846666 +0000 @@ -1,5 +1,5 @@ #source: ifunc-3-x86.s -#ld: -shared +#ld: -shared -O0 --hash-style=sysv #objdump: -dw #target: x86_64-*-* i?86-*-* diff -Naur binutils-2.20.51.0.6.orig/ld/testsuite/ld-x86-64/hidden2.d binutils-2.20.51.0.6/ld/testsuite/ld-x86-64/hidden2.d --- binutils-2.20.51.0.6.orig/ld/testsuite/ld-x86-64/hidden2.d 2008-04-03 16:54:05.000000000 +0000 +++ binutils-2.20.51.0.6/ld/testsuite/ld-x86-64/hidden2.d 2010-03-07 18:23:52.454846666 +0000 @@ -1,5 +1,5 @@ #as: --64 -#ld: -shared -melf_x86_64 +#ld: -shared -melf_x86_64 -O0 --hash-style=sysv #objdump: -drw .*: +file format .* diff -Naur binutils-2.20.51.0.6.orig/ld/testsuite/ld-x86-64/x86-64.exp binutils-2.20.51.0.6/ld/testsuite/ld-x86-64/x86-64.exp --- binutils-2.20.51.0.6.orig/ld/testsuite/ld-x86-64/x86-64.exp 2009-09-08 17:11:37.000000000 +0000 +++ binutils-2.20.51.0.6/ld/testsuite/ld-x86-64/x86-64.exp 2010-03-07 18:24:49.002843687 +0000 @@ -37,12 +37,12 @@ # readelf: Apply readelf options on result. Compare with regex (last arg). set x86_64tests { - {"TLS -fpic -shared transitions" "-shared -melf_x86_64" + {"TLS -fpic -shared transitions" "-shared -melf_x86_64 --hash-style=sysv" "--64" {tlspic1.s tlspic2.s} {{readelf -WSsrl tlspic.rd} {objdump -drj.text tlspic.dd} {objdump -sj.got tlspic.sd} {objdump -sj.tdata tlspic.td}} "libtlspic.so"} - {"TLS descriptor -fpic -shared transitions" "-shared -melf_x86_64" + {"TLS descriptor -fpic -shared transitions" "-shared -melf_x86_64 -O0 --hash-style=sysv" "--64" {tlsdesc.s tlspic2.s} {{readelf -WSsrld tlsdesc.rd} {objdump -drj.text tlsdesc.dd} {objdump "-s -j.got -j.got.plt" tlsdesc.sd} {objdump -sj.tdata tlsdesc.td} @@ -50,17 +50,17 @@ {"Helper shared library" "-shared -melf_x86_64" "--64" {tlslib.s} {} "libtlslib.so"} {"TLS -fpic and -fno-pic exec transitions" - "-melf_x86_64 tmpdir/libtlslib.so" "--64" {tlsbinpic.s tlsbin.s} + "-melf_x86_64 --hash-style=sysv tmpdir/libtlslib.so" "--64" {tlsbinpic.s tlsbin.s} {{readelf -WSsrl tlsbin.rd} {objdump -drj.text tlsbin.dd} {objdump -sj.got tlsbin.sd} {objdump -sj.tdata tlsbin.td}} "tlsbin"} {"TLS descriptor -fpic and -fno-pic exec transitions" - "-melf_x86_64 tmpdir/libtlslib.so" "--64" {tlsbindesc.s tlsbin.s} + "-melf_x86_64 --hash-style=sysv tmpdir/libtlslib.so" "--64" {tlsbindesc.s tlsbin.s} {{readelf -WSsrl tlsbindesc.rd} {objdump -drj.text tlsbindesc.dd} {objdump -sj.got tlsbindesc.sd} {objdump -sj.tdata tlsbindesc.td}} "tlsbindesc"} {"TLS with global dynamic and descriptors" - "-shared -melf_x86_64" "--64" {tlsgdesc.s} + "-shared -melf_x86_64 -O0 --hash-style=sysv" "--64" {tlsgdesc.s} {{readelf -WSsrl tlsgdesc.rd} {objdump -drj.text tlsgdesc.dd}} "libtlsgdesc.so"} {"TLS in debug sections" "-melf_x86_64"