summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--system/binutils/APKBUILD138
-rw-r--r--system/binutils/CVE-2017-7614.patch84
-rw-r--r--system/binutils/binutils-ld-fix-static-linking.patch46
-rw-r--r--system/binutils/disable-gnu-mbind.patch32
-rw-r--r--system/binutils/disable-preinit-array-tests.patch29
-rw-r--r--system/binutils/fix-plt-main-bnd-test.patch11
-rw-r--r--system/binutils/gold-mips.patch39
-rw-r--r--system/binutils/hash-style-configure-flag.patch348
-rw-r--r--system/binutils/mips-illegal-memcpy.patch11
-rw-r--r--system/binutils/remove-no-static-plt-test.patch21
-rw-r--r--system/binutils/remove-pr19553c-test.patch14
-rw-r--r--system/binutils/remove-pr2404-tests.patch73
12 files changed, 846 insertions, 0 deletions
diff --git a/system/binutils/APKBUILD b/system/binutils/APKBUILD
new file mode 100644
index 000000000..454a2bcca
--- /dev/null
+++ b/system/binutils/APKBUILD
@@ -0,0 +1,138 @@
+# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
+pkgname=binutils
+pkgver=2.29
+pkgrel=2
+pkgdesc="Tools necessary to build programs"
+url="http://www.gnu.org/software/binutils/"
+depends=""
+makedepends_build="bison flex texinfo"
+makedepends_host="zlib-dev"
+makedepends="$makedepends_build $makedepends_host"
+checkdepends="dejagnu"
+arch="all"
+license="GPL2 GPL3+ LGPL2 BSD"
+subpackages="$pkgname-dev $pkgname-doc $pkgname-libs"
+[ "${CARCH}" != "mips" ] && subpackages="$subpackages $pkgname-gold"
+source="http://ftp.gnu.org/gnu/$pkgname/$pkgname-$pkgver.tar.bz2
+ binutils-ld-fix-static-linking.patch
+ disable-gnu-mbind.patch
+ disable-preinit-array-tests.patch
+ fix-plt-main-bnd-test.patch
+ mips-illegal-memcpy.patch
+ remove-no-static-plt-test.patch
+ remove-pr2404-tests.patch
+ remove-pr19553c-test.patch
+ gold-mips.patch
+ "
+builddir="$srcdir/$pkgname-$pkgver"
+
+if [ "$CHOST" != "$CTARGET" ]; then
+ pkgname="$pkgname-$CTARGET_ARCH"
+ subpackages=""
+ options="!check"
+ sonameprefix="$pkgname:"
+fi
+
+# secfixes:
+# 2.28-r1:
+# - CVE-2017-7614
+
+build() {
+ local _sysroot=/
+ local _cross_configure="--enable-install-libiberty"
+ local _arch_configure=""
+
+ if [ "$CHOST" != "$CTARGET" ]; then
+ _sysroot="$CBUILDROOT"
+ _cross_configure="--disable-install-libiberty"
+ fi
+
+ if [ "$CTARGET_ARCH" = "x86_64" ]; then
+ _arch_configure="--enable-targets=x86_64-pep"
+ fi
+
+ case "$CTARGET_ARCH" in
+ mips*) _hash_style_configure="--enable-default-hash-style=sysv" ;;
+ *) _hash_style_configure="--enable-default-hash-style=gnu" ;;
+ esac
+
+ cd "$builddir"
+ ./configure \
+ --build=$CBUILD \
+ --host=$CHOST \
+ --target=$CTARGET \
+ --with-build-sysroot="$CBUILDROOT" \
+ --with-sysroot=$_sysroot \
+ --prefix=/usr \
+ --mandir=/usr/share/man \
+ --infodir=/usr/share/info \
+ --disable-multilib \
+ --enable-shared \
+ --enable-ld=default \
+ --enable-64-bit-bfd \
+ --enable-plugins \
+ --enable-relro \
+ --enable-gold \
+ --enable-deterministic-archives \
+ $_cross_configure \
+ $_arch_configure \
+ $_hash_style_configure \
+ --disable-werror \
+ --disable-nls \
+ --with-system-zlib \
+ || return 1
+ make || return 1
+}
+
+package() {
+ cd "$builddir"
+ make install DESTDIR="$pkgdir" || return 1
+ if [ -d "$pkgdir"/usr/lib64 ]; then
+ mv "$pkgdir"/usr/lib64/* "$pkgdir"/usr/lib/
+ rmdir "$pkgdir"/usr/lib64
+ fi
+ if [ "$CHOST" != "$CTARGET" ]; then
+ # creating cross tools: remove any files that would conflict
+ # with the native tools, or other cross tools
+ rm -r "$pkgdir"/usr/share
+ rm -f "$pkgdir"/usr/lib/libiberty.a
+ fi
+}
+
+check() {
+ cd "$builddir"
+ # We can't run the gold test suite, because it cannot be used
+ # on a system with default PIE/PIC.
+ make -C binutils check
+ make -C gas check
+ make -C ld check
+}
+
+libs() {
+ pkgdesc="Runtime libraries from binutils - libbfd and libopcodes"
+
+ mkdir -p "$subpkgdir"/usr/lib
+ mv "$pkgdir"/usr/lib/lib*.so "$subpkgdir"/usr/lib/ || return 1
+}
+
+gold() {
+ pkgdesc="GNU binutils - gold linker"
+
+ if [ -e "$pkgdir"/usr/bin/ld.gold ]; then
+ mkdir -p "$subpkgdir"/usr/bin
+ mv "$pkgdir"/usr/bin/ld.gold "$subpkgdir"/usr/bin
+ fi
+ mkdir -p "$subpkgdir"/usr/$CTARGET/bin
+ mv "$pkgdir"/usr/$CTARGET/bin/ld.gold "$subpkgdir"/usr/$CTARGET/bin/ld.gold
+}
+
+sha512sums="8148587d7e4f14ebcbcb3f984b116deaae5d4008228628acde14bc242a64a4b53faf1f6077a2c4ca4750e2f254b698ba506bd657f79e1202e87e7029b0069337 binutils-2.29.tar.bz2
+ecee33b0e435aa704af1c334e560f201638ff79e199aa11ed78a72f7c9b46f85fbb227af5748e735fd681d1965fcc42ac81b0c8824e540430ce0c706c81e8b49 binutils-ld-fix-static-linking.patch
+d378fdf1964f8f2bd0b1e62827ac5884bdf943aa435ec89c29fc84bb045d406b733fffaff8fdd8bd1cba8ddea7701c4cf6ccf3ed76a8a3df9c72b447737575a6 disable-gnu-mbind.patch
+3537752e63cef0b5ef136d003ff7e814ba66b12624d817430112d0f291a792e8960fa69a78036f526af835441b3ee483d6a53d55c7b3dd8ee96f0399682dbcbe disable-preinit-array-tests.patch
+01149e3b772c92783048cc65a4fe6d63770c9f8351ff087901679ba886ccad0bdaeec83033be4537651570de0b042f2cb8e2fad0bcab70afae773053dfda11be fix-plt-main-bnd-test.patch
+06422157349abf02e79a5ef8bd9f51100e7e996aab65250d518e0cf0d7ac8ed922d3bf1603c4f5b4fd8fb179266b7b4c41db32dcb241d60a7f1c21d1df0c36dd mips-illegal-memcpy.patch
+b40f9a3841a7af8fc12e8a4044cd672df5614bfda8461b0ca45efa57a42c3bc8490e491ea490c6c05d319a52d69993c4fca33a0aeb044090e7b7f4e4e30c6517 remove-no-static-plt-test.patch
+32ab4215669c728648179c124632467573a3d4675e79f0f0d221c22eb2ec1ca5488b79910bd09142f90a1e0d0b81d99ca4846297f4f9561f158db63745facb66 remove-pr2404-tests.patch
+39ef9c76dd5db6b15f11ffa8061f7ca844fb79c3fb9879c3b1466eef332a28b833597c87003ab9f260b1b85023fae264659088aee27cad7e5aa77b2d58b9a3f6 remove-pr19553c-test.patch
+f55cf2e0bf82f97583a1abe10710e4013ecf7d64f1da2ef8659a44a06d0dd8beaf58dab98a183488ea137f03e32d62efc878d95f018f836f8cec870bc448556f gold-mips.patch"
diff --git a/system/binutils/CVE-2017-7614.patch b/system/binutils/CVE-2017-7614.patch
new file mode 100644
index 000000000..5f3b550f2
--- /dev/null
+++ b/system/binutils/CVE-2017-7614.patch
@@ -0,0 +1,84 @@
+From ad32986fdf9da1c8748e47b8b45100398223dba8 Mon Sep 17 00:00:00 2001
+From: Nick Clifton <nickc@redhat.com>
+Date: Tue, 4 Apr 2017 11:23:36 +0100
+Subject: [PATCH] Fix null pointer dereferences when using a link built with
+ clang.
+
+ PR binutils/21342
+ * elflink.c (_bfd_elf_define_linkage_sym): Prevent null pointer
+ dereference.
+ (bfd_elf_final_link): Only initialize the extended symbol index
+ section if there are extended symbol tables to list.
+---
+ bfd/elflink.c | 35 +++++++++++++++++++++--------------
+ 2 files changed, 29 insertions(+), 14 deletions(-)
+
+diff --git a/bfd/elflink.c b/bfd/elflink.c
+index 776357f..9bf75c8 100644
+--- a/bfd/elflink.c
++++ b/bfd/elflink.c
+@@ -119,15 +119,18 @@ _bfd_elf_define_linkage_sym (bfd *abfd,
+ defined in shared libraries can't be overridden, because we
+ lose the link to the bfd which is via the symbol section. */
+ h->root.type = bfd_link_hash_new;
++ bh = &h->root;
+ }
++ else
++ bh = NULL;
+
+- bh = &h->root;
+ bed = get_elf_backend_data (abfd);
+ if (!_bfd_generic_link_add_one_symbol (info, abfd, name, BSF_GLOBAL,
+ sec, 0, NULL, FALSE, bed->collect,
+ &bh))
+ return NULL;
+ h = (struct elf_link_hash_entry *) bh;
++ BFD_ASSERT (h != NULL);
+ h->def_regular = 1;
+ h->non_elf = 0;
+ h->root.linker_def = 1;
+@@ -12038,24 +12041,28 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
+ {
+ /* Finish up and write out the symbol string table (.strtab)
+ section. */
+- Elf_Internal_Shdr *symstrtab_hdr;
++ Elf_Internal_Shdr *symstrtab_hdr = NULL;
+ file_ptr off = symtab_hdr->sh_offset + symtab_hdr->sh_size;
+
+- symtab_shndx_hdr = & elf_symtab_shndx_list (abfd)->hdr;
+- if (symtab_shndx_hdr != NULL && symtab_shndx_hdr->sh_name != 0)
++ if (elf_symtab_shndx_list (abfd))
+ {
+- symtab_shndx_hdr->sh_type = SHT_SYMTAB_SHNDX;
+- symtab_shndx_hdr->sh_entsize = sizeof (Elf_External_Sym_Shndx);
+- symtab_shndx_hdr->sh_addralign = sizeof (Elf_External_Sym_Shndx);
+- amt = bfd_get_symcount (abfd) * sizeof (Elf_External_Sym_Shndx);
+- symtab_shndx_hdr->sh_size = amt;
++ symtab_shndx_hdr = & elf_symtab_shndx_list (abfd)->hdr;
+
+- off = _bfd_elf_assign_file_position_for_section (symtab_shndx_hdr,
+- off, TRUE);
++ if (symtab_shndx_hdr != NULL && symtab_shndx_hdr->sh_name != 0)
++ {
++ symtab_shndx_hdr->sh_type = SHT_SYMTAB_SHNDX;
++ symtab_shndx_hdr->sh_entsize = sizeof (Elf_External_Sym_Shndx);
++ symtab_shndx_hdr->sh_addralign = sizeof (Elf_External_Sym_Shndx);
++ amt = bfd_get_symcount (abfd) * sizeof (Elf_External_Sym_Shndx);
++ symtab_shndx_hdr->sh_size = amt;
+
+- if (bfd_seek (abfd, symtab_shndx_hdr->sh_offset, SEEK_SET) != 0
+- || (bfd_bwrite (flinfo.symshndxbuf, amt, abfd) != amt))
+- return FALSE;
++ off = _bfd_elf_assign_file_position_for_section (symtab_shndx_hdr,
++ off, TRUE);
++
++ if (bfd_seek (abfd, symtab_shndx_hdr->sh_offset, SEEK_SET) != 0
++ || (bfd_bwrite (flinfo.symshndxbuf, amt, abfd) != amt))
++ return FALSE;
++ }
+ }
+
+ symstrtab_hdr = &elf_tdata (abfd)->strtab_hdr;
+--
+2.9.3
+
diff --git a/system/binutils/binutils-ld-fix-static-linking.patch b/system/binutils/binutils-ld-fix-static-linking.patch
new file mode 100644
index 000000000..bc5d76265
--- /dev/null
+++ b/system/binutils/binutils-ld-fix-static-linking.patch
@@ -0,0 +1,46 @@
+This fixes static linking for our hardened toolchain
+diff --git a/ld/scripttempl/elf.sc b/ld/scripttempl/elf.sc
+index e8126cb..9532bfb 100644
+--- a/ld/scripttempl/elf.sc
++++ b/ld/scripttempl/elf.sc
+@@ -235,8 +235,8 @@ test "${LARGE_SECTIONS}" = "yes" && LARGE_SECTIONS="
+ if test "${ENABLE_INITFINI_ARRAY}" = "yes"; then
+ SORT_INIT_ARRAY="KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))"
+ SORT_FINI_ARRAY="KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))"
+- CTORS_IN_INIT_ARRAY="EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .ctors"
+- DTORS_IN_FINI_ARRAY="EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .dtors"
++ CTORS_IN_INIT_ARRAY="EXCLUDE_FILE (*crtbegin*.o *crtend*.o $OTHER_EXCLUDE_FILES) .ctors"
++ DTORS_IN_FINI_ARRAY="EXCLUDE_FILE (*crtbegin*.o *crtend*.o $OTHER_EXCLUDE_FILES) .dtors"
+ else
+ SORT_INIT_ARRAY="KEEP (*(SORT(.init_array.*)))"
+ SORT_FINI_ARRAY="KEEP (*(SORT(.fini_array.*)))"
+@@ -270,15 +270,14 @@ CTOR=".ctors ${CONSTRUCTING-0} :
+ doesn't matter which directory crtbegin.o
+ is in. */
+
+- KEEP (*crtbegin.o(.ctors))
+- KEEP (*crtbegin?.o(.ctors))
++ KEEP (*crtbegin*.o(.ctors))
+
+ /* We don't want to include the .ctor section from
+ the crtend.o file until after the sorted ctors.
+ The .ctor section from the crtend file contains the
+ end of ctors marker and it must be last */
+
+- KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .ctors))
++ KEEP (*(EXCLUDE_FILE (*crtend*.o $OTHER_EXCLUDE_FILES) .ctors))
+ KEEP (*(SORT(.ctors.*)))
+ KEEP (*(.ctors))
+ ${CONSTRUCTING+${CTOR_END}}
+@@ -286,9 +285,8 @@ CTOR=".ctors ${CONSTRUCTING-0} :
+ DTOR=".dtors ${CONSTRUCTING-0} :
+ {
+ ${CONSTRUCTING+${DTOR_START}}
+- KEEP (*crtbegin.o(.dtors))
+- KEEP (*crtbegin?.o(.dtors))
+- KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .dtors))
++ KEEP (*crtbegin*.o(.dtors))
++ KEEP (*(EXCLUDE_FILE (*crtend*.o $OTHER_EXCLUDE_FILES) .dtors))
+ KEEP (*(SORT(.dtors.*)))
+ KEEP (*(.dtors))
+ ${CONSTRUCTING+${DTOR_END}}
diff --git a/system/binutils/disable-gnu-mbind.patch b/system/binutils/disable-gnu-mbind.patch
new file mode 100644
index 000000000..796e6d0fc
--- /dev/null
+++ b/system/binutils/disable-gnu-mbind.patch
@@ -0,0 +1,32 @@
+These tests do not work on PIE. Disable them.
+
+--- binutils-2.29/ld/testsuite/ld-elf/elf.exp.old 2017-08-19 22:39:31.236907813 +0000
++++ binutils-2.29/ld/testsuite/ld-elf/elf.exp 2017-08-20 00:12:04.735925829 +0000
+@@ -296,27 +296,6 @@
+ || [istarget *-*-nacl*]
+ || [istarget *-*-gnu*] } {
+ run_ld_link_exec_tests $array_tests_pie $xfails
+-
+- run_ld_link_exec_tests [list \
+- [list \
+- "Run mbind2a" \
+- "$NOPIE_LDFLAGS -Wl,-z,common-page-size=0x4000" \
+- "" \
+- { mbind2a.s mbind2b.c } \
+- "mbind2a" \
+- "pass.out" \
+- "-O2 -I../bfd" \
+- ] \
+- [list \
+- "Run mbind2b" \
+- "-static -Wl,-z,common-page-size=0x4000" \
+- "" \
+- { mbind2a.s mbind2b.c } \
+- "mbind2b" \
+- "pass.out" \
+- "-O2 -I../bfd" \
+- ] \
+- ]
+ }
+
+ # <http://www.gnu.org/software/hurd/open_issues/binutils.html#static>
diff --git a/system/binutils/disable-preinit-array-tests.patch b/system/binutils/disable-preinit-array-tests.patch
new file mode 100644
index 000000000..f3d36c1b3
--- /dev/null
+++ b/system/binutils/disable-preinit-array-tests.patch
@@ -0,0 +1,29 @@
+--- binutils-2.29/ld/testsuite/ld-elf/elf.exp.old 2017-07-04 08:43:21.000000000 +0000
++++ binutils-2.29/ld/testsuite/ld-elf/elf.exp 2017-08-19 04:46:32.214460537 +0000
+@@ -262,8 +262,6 @@
+ }
+
+ set array_tests {
+- {"preinit array" "" ""
+- {preinit.c} "preinit" "preinit.out"}
+ {"init array" "" ""
+ {init.c} "init" "init.out"}
+ {"fini array" "" ""
+@@ -272,8 +270,6 @@
+ {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
+ }
+ set array_tests_pie {
+- {"PIE preinit array" "-pie" ""
+- {preinit.c} "preinit" "preinit.out" "-fPIE"}
+ {"PIE init array" "-pie" ""
+ {init.c} "init" "init.out" "-fPIE"}
+ {"PIE fini array" "-pie" ""
+@@ -284,8 +280,6 @@
+ {pr14525.c} "pr14525" "pr14525.out" "-fPIE"}
+ }
+ set array_tests_static {
+- {"static preinit array" "-static" ""
+- {preinit.c} "preinit" "preinit.out"}
+ {"static init array" "-static" ""
+ {init.c} "init" "init.out"}
+ {"static fini array" "-static" ""
diff --git a/system/binutils/fix-plt-main-bnd-test.patch b/system/binutils/fix-plt-main-bnd-test.patch
new file mode 100644
index 000000000..867bf15f4
--- /dev/null
+++ b/system/binutils/fix-plt-main-bnd-test.patch
@@ -0,0 +1,11 @@
+--- binutils-2.29/ld/testsuite/ld-x86-64/plt-main-bnd.dd.old 2017-07-04 08:43:21.000000000 +0000
++++ binutils-2.29/ld/testsuite/ld-x86-64/plt-main-bnd.dd 2017-08-19 04:41:37.838409573 +0000
+@@ -1,7 +1,7 @@
+ #...
+ Disassembly of section .plt.got:
+
+-[a-f0-9]+ <[a-z]+@plt>:
++[a-f0-9]+ <[a-z_]+@plt>:
+ [ ]*[a-f0-9]+: f2 ff 25 .. .. 20 00 bnd jmpq \*0x20....\(%rip\) # ...... <.*>
+ [ ]*[a-f0-9]+: 90 nop
+ #pass
diff --git a/system/binutils/gold-mips.patch b/system/binutils/gold-mips.patch
new file mode 100644
index 000000000..291a2aae6
--- /dev/null
+++ b/system/binutils/gold-mips.patch
@@ -0,0 +1,39 @@
+# DP: Fix gold on mips64 targets.
+
+gold/
+
+2016-08-09 Aurelien Jarno <aurelien@aurel32.net>
+
+ * configure.tgt: Add mips64el*-*-*|mips64le*-*-* and mips64*-*-*.
+
+
+--- a/gold/configure.tgt
++++ b/gold/configure.tgt
+@@ -153,6 +153,13 @@ aarch64*-*)
+ targ_big_endian=false
+ targ_extra_big_endian=true
+ ;;
++mips*64*el*-*-*|mips*64*le*-*-*)
++ targ_obj=mips
++ targ_machine=EM_MIPS_RS3_LE
++ targ_size=64
++ targ_big_endian=false
++ targ_extra_big_endian=true
++ ;;
+ mips*el*-*-*|mips*le*-*-*)
+ targ_obj=mips
+ targ_machine=EM_MIPS_RS3_LE
+@@ -160,6 +167,13 @@ mips*el*-*-*|mips*le*-*-*)
+ targ_big_endian=false
+ targ_extra_big_endian=true
+ ;;
++mips*64*-*-*)
++ targ_obj=mips
++ targ_machine=EM_MIPS
++ targ_size=64
++ targ_big_endian=true
++ targ_extra_big_endian=false
++ ;;
+ mips*-*-*)
+ targ_obj=mips
+ targ_machine=EM_MIPS
diff --git a/system/binutils/hash-style-configure-flag.patch b/system/binutils/hash-style-configure-flag.patch
new file mode 100644
index 000000000..6d4db4bca
--- /dev/null
+++ b/system/binutils/hash-style-configure-flag.patch
@@ -0,0 +1,348 @@
+From 2760f24c4942853eac7b921e4b8843d57a602654 Mon Sep 17 00:00:00 2001
+From: Romain Geissler <romain.geissler@gmail.com>
+Date: Tue, 8 Aug 2017 07:25:39 +0930
+Subject: [PATCH] Add configure flag to enable gnu hash style by default.
+
+ld/
+ * configure.ac: Add --enable-default-hash-style option.
+ * ldmain.c (main): Set link_info.emit_hash to DEFAULT_EMIT_SYSV_HASH.
+ Set link_info.emit_gnu_hash to DEFAULT_EMIT_GNU_HASH.
+ * configure: Regenerate.
+ * config.in: Regenerate.
+
+gold/
+ * configure.ac: Add --enable-default-hash-style option.
+ * options.h (hash_style): Use DEFAULT_HASH_STYLE as default value.
+ * configure: Regenerate.
+ * config.in: Regenerate.
+---
+ gold/ChangeLog | 8 ++++++++
+ gold/config.in | 3 +++
+ gold/configure | 27 +++++++++++++++++++++++++++
+ gold/configure.ac | 20 ++++++++++++++++++++
+ gold/options.h | 2 +-
+ ld/ChangeLog | 9 +++++++++
+ ld/config.in | 6 ++++++
+ ld/configure | 42 ++++++++++++++++++++++++++++++++++++++----
+ ld/configure.ac | 34 ++++++++++++++++++++++++++++++++++
+ ld/ldmain.c | 3 ++-
+ 10 files changed, 148 insertions(+), 6 deletions(-)
+
+diff --git a/gold/ChangeLog b/gold/ChangeLog
+index d598386..93836dd 100644
+--- a/gold/ChangeLog
++++ b/gold/ChangeLog
+@@ -1,3 +1,11 @@
++2017-08-08 Romain Geissler <romain.geissler@gmail.com>
++ Alan Modra <amodra@gmail.com>
++
++ * configure.ac: Add --enable-default-hash-style option.
++ * options.h (hash_style): Use DEFAULT_HASH_STYLE as default value.
++ * configure: Regenerate.
++ * config.in: Regenerate.
++
+ 2017-02-22 Alan Modra <amodra@gmail.com>
+
+ * powerpc.cc (Target_powerpc::make_iplt_section): Check that
+diff --git a/gold/config.in b/gold/config.in
+index d9f7b76..5855fca 100644
+--- a/gold/config.in
++++ b/gold/config.in
+@@ -10,6 +10,9 @@
+ /* Define if building universal (internal helper macro) */
+ #undef AC_APPLE_UNIVERSAL_BUILD
+
++/* Set the default --hash-style value */
++#undef DEFAULT_HASH_STYLE
++
+ /* Define to 1 if you want to enable -z relro in ELF linker by default. */
+ #undef DEFAULT_LD_Z_RELRO
+
+diff --git a/gold/configure b/gold/configure
+index cb020be..90a706d 100755
+--- a/gold/configure
++++ b/gold/configure
+@@ -797,6 +797,7 @@ enable_threads
+ enable_plugins
+ enable_relro
+ enable_targets
++enable_default_hash_style
+ with_lib_path
+ enable_dependency_tracking
+ enable_nls
+@@ -1447,6 +1448,8 @@ Optional Features:
+ --enable-plugins linker plugins
+ --enable-relro enable -z relro in ELF linker by default
+ --enable-targets alternative target configurations
++ --enable-default-hash-style={sysv,gnu,both}
++ use this default hash style
+ --disable-dependency-tracking speeds up one-time build
+ --enable-dependency-tracking do not reject slow dependency extractors
+ --disable-nls do not use Native Language Support
+@@ -3410,6 +3413,30 @@ if test -n "$enable_targets"; then
+ done
+ fi
+
++# Decide which "--hash-style" to use by default
++# Provide a configure time option to override our default.
++# Check whether --enable-default-hash-style was given.
++if test "${enable_default_hash_style+set}" = set; then :
++ enableval=$enable_default_hash_style; case "${enable_default_hash_style}" in
++ sysv | gnu | both) ;;
++ *) as_fn_error "bad value ${enable_default_hash_style} for enable-default-hash-style option" "$LINENO" 5 ;;
++esac
++else
++ case "${target}" in
++ # Enable gnu hash only on GNU targets, but not mips
++ mips*-*-*) enable_default_hash_style=sysv ;;
++ *-*-gnu* | *-*-linux* | *-*-nacl*) enable_default_hash_style=both ;;
++ *) enable_default_hash_style=sysv ;;
++esac
++fi
++
++
++
++cat >>confdefs.h <<_ACEOF
++#define DEFAULT_HASH_STYLE "${enable_default_hash_style}"
++_ACEOF
++
++
+ # See which specific instantiations we need.
+ targetobjs=
+ all_targets=
+diff --git a/gold/configure.ac b/gold/configure.ac
+index cbe3380..d7fa1f8 100644
+--- a/gold/configure.ac
++++ b/gold/configure.ac
+@@ -161,6 +161,26 @@ if test -n "$enable_targets"; then
+ done
+ fi
+
++# Decide which "--hash-style" to use by default
++# Provide a configure time option to override our default.
++AC_ARG_ENABLE([default-hash-style],
++AS_HELP_STRING([--enable-default-hash-style={sysv,gnu,both}],
++ [use this default hash style]),
++[case "${enable_default_hash_style}" in
++ sysv | gnu | both) ;;
++ *) AC_MSG_ERROR([bad value ${enable_default_hash_style} for enable-default-hash-style option]) ;;
++esac],
++[case "${target}" in
++ # Enable gnu hash only on GNU targets, but not mips
++ mips*-*-*) enable_default_hash_style=sysv ;;
++ *-*-gnu* | *-*-linux* | *-*-nacl*) enable_default_hash_style=both ;;
++ *) enable_default_hash_style=sysv ;;
++esac])
++
++AC_DEFINE_UNQUOTED([DEFAULT_HASH_STYLE],
++ ["${enable_default_hash_style}"],
++ [Set the default --hash-style value])
++
+ # See which specific instantiations we need.
+ targetobjs=
+ all_targets=
+diff --git a/gold/options.h b/gold/options.h
+index a8b1d46..ce21a42 100644
+--- a/gold/options.h
++++ b/gold/options.h
+@@ -921,7 +921,7 @@ class General_options
+ N_("Min fraction of empty buckets in dynamic hash"),
+ N_("FRACTION"));
+
+- DEFINE_enum(hash_style, options::TWO_DASHES, '\0', "sysv",
++ DEFINE_enum(hash_style, options::TWO_DASHES, '\0', DEFAULT_HASH_STYLE,
+ N_("Dynamic hash style"), N_("[sysv,gnu,both]"),
+ {"sysv", "gnu", "both"});
+
+diff --git a/ld/ChangeLog b/ld/ChangeLog
+index ba7d1d4..cf91d55 100644
+--- a/ld/ChangeLog
++++ b/ld/ChangeLog
+@@ -1,3 +1,12 @@
++2017-08-08 Romain Geissler <romain.geissler@gmail.com>
++ Alan Modra <amodra@gmail.com>
++
++ * configure.ac: Add --enable-default-hash-style option.
++ * ldmain.c (main): Set link_info.emit_hash to DEFAULT_EMIT_SYSV_HASH.
++ Set link_info.emit_gnu_hash to DEFAULT_EMIT_GNU_HASH.
++ * configure: Regenerate.
++ * config.in: Regenerate.
++
+ 2017-03-02 Tristan Gingold <gingold@adacore.com>
+
+ * configure: Regenerate.
+diff --git a/ld/config.in b/ld/config.in
+index 2c6d698..b2318e1 100644
+--- a/ld/config.in
++++ b/ld/config.in
+@@ -7,6 +7,12 @@
+ #endif
+ #define __CONFIG_H__ 1
+
++/* Define to 1 if you want to emit gnu hash in the ELF linker by default. */
++#undef DEFAULT_EMIT_GNU_HASH
++
++/* Define to 1 if you want to emit sysv hash in the ELF linker by default. */
++#undef DEFAULT_EMIT_SYSV_HASH
++
+ /* Define if you want compressed debug sections by default. */
+ #undef DEFAULT_FLAG_COMPRESS_DEBUG
+
+diff --git a/ld/configure b/ld/configure
+index 36af969..40c67fd 100755
+--- a/ld/configure
++++ b/ld/configure
+@@ -793,6 +793,7 @@ enable_gold
+ enable_got
+ enable_compressed_debug_sections
+ enable_relro
++enable_default_hash_style
+ enable_werror
+ enable_build_warnings
+ enable_nls
+@@ -1452,6 +1453,8 @@ Optional Features:
+ --enable-compressed-debug-sections={all,ld,none}
+ compress debug sections by default]
+ --enable-relro enable -z relro in ELF linker by default
++ --enable-default-hash-style={sysv,gnu,both}
++ use this default hash style
+ --enable-werror treat compile warnings as errors
+ --enable-build-warnings enable build-time compiler warnings
+ --disable-nls do not use Native Language Support
+@@ -11724,7 +11727,7 @@ else
+ lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+ lt_status=$lt_dlunknown
+ cat > conftest.$ac_ext <<_LT_EOF
+-#line 11727 "configure"
++#line 11730 "configure"
+ #include "confdefs.h"
+
+ #if HAVE_DLFCN_H
+@@ -11830,7 +11833,7 @@ else
+ lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+ lt_status=$lt_dlunknown
+ cat > conftest.$ac_ext <<_LT_EOF
+-#line 11833 "configure"
++#line 11836 "configure"
+ #include "confdefs.h"
+
+ #if HAVE_DLFCN_H
+@@ -15555,6 +15558,33 @@ if test "${enable_relro+set}" = set; then :
+ esac
+ fi
+
++# Decide which "--hash-style" to use by default
++# Provide a configure time option to override our default.
++# Check whether --enable-default-hash-style was given.
++if test "${enable_default_hash_style+set}" = set; then :
++ enableval=$enable_default_hash_style; case "${enable_default_hash_style}" in
++ sysv | gnu | both) ;;
++ *) as_fn_error "bad value ${enable_default_hash_style} for enable-default-hash-style option" "$LINENO" 5 ;;
++esac
++else
++ case "${target}" in
++ # Enable gnu hash only on GNU targets, but not mips
++ mips*-*-*) enable_default_hash_style=sysv ;;
++ *-*-gnu* | *-*-linux* | *-*-nacl*) enable_default_hash_style=both ;;
++ *) enable_default_hash_style=sysv ;;
++esac
++fi
++
++
++case "${enable_default_hash_style}" in
++ sysv | both) ac_default_emit_sysv_hash=1 ;;
++ *) ac_default_emit_sysv_hash=0 ;;
++esac
++
++case "${enable_default_hash_style}" in
++ gnu | both) ac_default_emit_gnu_hash=1 ;;
++ *) ac_default_emit_gnu_hash=0 ;;
++esac
+
+ # Set the 'development' global.
+ . $srcdir/../bfd/development.sh
+@@ -17212,9 +17242,13 @@ cat >>confdefs.h <<_ACEOF
+ #define DEFAULT_LD_Z_RELRO $ac_default_ld_z_relro
+ _ACEOF
+
++cat >>confdefs.h <<_ACEOF
++#define DEFAULT_EMIT_SYSV_HASH $ac_default_emit_sysv_hash
++_ACEOF
+
+-
+-
++cat >>confdefs.h <<_ACEOF
++#define DEFAULT_EMIT_GNU_HASH $ac_default_emit_gnu_hash
++_ACEOF
+
+
+
+diff --git a/ld/configure.ac b/ld/configure.ac
+index 36a9f50..1876ad7 100644
+--- a/ld/configure.ac
++++ b/ld/configure.ac
+@@ -166,6 +166,32 @@ AC_ARG_ENABLE(relro,
+ no) ac_default_ld_z_relro=0 ;;
+ esac])dnl
+
++# Decide which "--hash-style" to use by default
++# Provide a configure time option to override our default.
++AC_ARG_ENABLE([default-hash-style],
++AS_HELP_STRING([--enable-default-hash-style={sysv,gnu,both}],
++ [use this default hash style]),
++[case "${enable_default_hash_style}" in
++ sysv | gnu | both) ;;
++ *) AC_MSG_ERROR([bad value ${enable_default_hash_style} for enable-default-hash-style option]) ;;
++esac],
++[case "${target}" in
++ # Enable gnu hash only on GNU targets, but not mips
++ mips*-*-*) enable_default_hash_style=sysv ;;
++ *-*-gnu* | *-*-linux* | *-*-nacl*) enable_default_hash_style=both ;;
++ *) enable_default_hash_style=sysv ;;
++esac])
++
++case "${enable_default_hash_style}" in
++ sysv | both) ac_default_emit_sysv_hash=1 ;;
++ *) ac_default_emit_sysv_hash=0 ;;
++esac
++
++case "${enable_default_hash_style}" in
++ gnu | both) ac_default_emit_gnu_hash=1 ;;
++ *) ac_default_emit_gnu_hash=0 ;;
++esac
++
+ AM_BINUTILS_WARNINGS
+
+ AM_LC_MESSAGES
+@@ -394,6 +420,14 @@ AC_DEFINE_UNQUOTED(DEFAULT_LD_Z_RELRO,
+ $ac_default_ld_z_relro,
+ [Define to 1 if you want to enable -z relro in ELF linker by default.])
+
++AC_DEFINE_UNQUOTED([DEFAULT_EMIT_SYSV_HASH],
++ [$ac_default_emit_sysv_hash],
++ [Define to 1 if you want to emit sysv hash in the ELF linker by default.])
++
++AC_DEFINE_UNQUOTED([DEFAULT_EMIT_GNU_HASH],
++ [$ac_default_emit_gnu_hash],
++ [Define to 1 if you want to emit gnu hash in the ELF linker by default.])
++
+ AC_SUBST(elf_list_options)
+ AC_SUBST(elf_shlib_list_options)
+ AC_SUBST(elf_plt_unwind_list_options)
+diff --git a/ld/ldmain.c b/ld/ldmain.c
+index 1e48b1a..579d961 100644
+--- a/ld/ldmain.c
++++ b/ld/ldmain.c
+@@ -282,7 +282,8 @@ main (int argc, char **argv)
+ link_info.keep_memory = TRUE;
+ link_info.combreloc = TRUE;
+ link_info.strip_discarded = TRUE;
+- link_info.emit_hash = TRUE;
++ link_info.emit_hash = DEFAULT_EMIT_SYSV_HASH;
++ link_info.emit_gnu_hash = DEFAULT_EMIT_GNU_HASH;
+ 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
+--
+2.14.2
+
diff --git a/system/binutils/mips-illegal-memcpy.patch b/system/binutils/mips-illegal-memcpy.patch
new file mode 100644
index 000000000..d76af178a
--- /dev/null
+++ b/system/binutils/mips-illegal-memcpy.patch
@@ -0,0 +1,11 @@
+--- binutils-2.29/gas/config/tc-mips.c.old 2017-07-04 03:43:20.000000000 -0500
++++ binutils-2.29/gas/config/tc-mips.c 2017-08-25 17:21:51.449460074 -0500
+@@ -13956,7 +13956,7 @@
+ suffix = 0;
+ if (suffix)
+ {
+- memcpy (name + opend - 2, name + opend, length - opend + 1);
++ memmove (name + opend - 2, name + opend, length - opend + 1);
+ insn = (struct mips_opcode *) hash_find (hash, name);
+ if (insn)
+ {
diff --git a/system/binutils/remove-no-static-plt-test.patch b/system/binutils/remove-no-static-plt-test.patch
new file mode 100644
index 000000000..ab6bc02e6
--- /dev/null
+++ b/system/binutils/remove-no-static-plt-test.patch
@@ -0,0 +1,21 @@
+The compiler generates relative addresses instead of absolute, confusing the
+regex used. Disable this test since it would pass anyway.
+
+--- binutils-2.29/ld/testsuite/ld-x86-64/no-plt.exp.old 2017-07-04 08:43:21.000000000 +0000
++++ binutils-2.29/ld/testsuite/ld-x86-64/no-plt.exp 2017-08-19 18:13:48.566481023 +0000
+@@ -100,15 +100,6 @@
+ "no-plt-1c" \
+ ] \
+ [list \
+- "No PLT (static 1d)" \
+- "-static tmpdir/no-plt-check1.o tmpdir/no-plt-main1.o \
+- tmpdir/no-plt-func1.o tmpdir/no-plt-extern1.o" \
+- "" \
+- {dummy.s} \
+- {{readelf -Wr no-plt-1d.rd} {objdump -dwrj.text no-plt-1d.dd}} \
+- "no-plt-1d" \
+- ] \
+- [list \
+ "No PLT (PIE 1e)" \
+ "-pie tmpdir/no-plt-check1.o tmpdir/no-plt-main1.o \
+ tmpdir/no-plt-func1.o tmpdir/no-plt-extern1.o" \
diff --git a/system/binutils/remove-pr19553c-test.patch b/system/binutils/remove-pr19553c-test.patch
new file mode 100644
index 000000000..7e5b76ab0
--- /dev/null
+++ b/system/binutils/remove-pr19553c-test.patch
@@ -0,0 +1,14 @@
+This test requires symbol versioning which the musl libc does not support.
+
+--- binutils-2.29/ld/testsuite/ld-elf/indirect.exp.old 2017-07-04 08:43:21.000000000 +0000
++++ binutils-2.29/ld/testsuite/ld-elf/indirect.exp 2017-08-19 05:00:13.086002872 +0000
+@@ -186,9 +186,6 @@
+ {"Run with libpr19553b.so"
+ "-Wl,--no-as-needed tmpdir/libpr19553b.so tmpdir/libpr19553d.so -Wl,-rpath-link,." ""
+ {pr19553a.c} "pr19553b" "pr19553b.out"}
+- {"Run with libpr19553c.so"
+- "-Wl,--no-as-needed tmpdir/libpr19553c.so tmpdir/libpr19553b.so tmpdir/libpr19553d.so" ""
+- {pr19553a.c} "pr19553c" "pr19553c.out"}
+ {"Run with libpr19553d.so"
+ "-Wl,--no-as-needed tmpdir/libpr19553d.so tmpdir/libpr19553b.so -Wl,-rpath-link,." ""
+ {pr19553a.c} "pr19553d" "pr19553d.out"}
diff --git a/system/binutils/remove-pr2404-tests.patch b/system/binutils/remove-pr2404-tests.patch
new file mode 100644
index 000000000..9efdf5242
--- /dev/null
+++ b/system/binutils/remove-pr2404-tests.patch
@@ -0,0 +1,73 @@
+These tests fail to link correctly on musl.
+
+--- binutils-2.29/ld/testsuite/ld-elf/shared.exp.old 2017-07-04 08:43:21.000000000 +0000
++++ binutils-2.29/ld/testsuite/ld-elf/shared.exp 2017-08-19 04:59:05.319481464 +0000
+@@ -375,15 +375,6 @@
+ {"Build needed3"
+ "tmpdir/needed3.o -Wl,--as-needed -Ltmpdir -lneeded3a -lneeded3b -lneeded1b" ""
+ {dummy.c} {} "needed3"}
+- {"Build libpr2404a.so"
+- "-shared" "-fPIC"
+- {pr2404a.c} {} "libpr2404a.so"}
+- {"Build libpr2404n.so"
+- "-shared -Wl,-z,now" "-fPIC"
+- {pr2404a.c} {} "libpr2404n.so"}
+- {"Build libpr2404b.a"
+- "" ""
+- {pr2404b.c} {} "libpr2404b.a"}
+ {"Build rdynamic-1"
+ "-Wl,--no-dynamic-linker,-export-dynamic,--gc-sections" "-ffunction-sections"
+ {rdynamic-1.c} {{readelf {-s} rdynamic-1.rd}} "rdynamic-1"}
+@@ -531,12 +522,6 @@
+ [list "Run relmain" \
+ "-Wl,--no-as-needed,-rpath=tmpdir -Ltmpdir -lrel" "" \
+ {relmain.c} "relmain" "relmain.out" ] \
+- [list "Run pr2404" \
+- "-Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404a.so" "" \
+- {dummy.c} "pr2404" "pr2404.out" ] \
+- [list "Run pr2404n" \
+- "-Wl,-z,now -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404n.so" "" \
+- {dummy.c} "pr2404n" "pr2404.out" ] \
+ [list "Run pr18458" \
+ "-Wl,--no-as-needed,-z,now tmpdir/libpr18458a.so tmpdir/libpr18458b.so" "" \
+ {pr18458c.c} "pr18458" "pass.out" ] \
+@@ -675,14 +660,6 @@
+ || [istarget *-*-gnu*] } {
+ run_cc_link_tests [list \
+ [list \
+- "Build libpr2404b.a with PIE" \
+- "" \
+- "-fPIE" \
+- { pr2404b.c } \
+- {} \
+- "libpr2404b.a" \
+- ] \
+- [list \
+ "Build pr19579a.o" \
+ "" "-fPIE" \
+ {pr19579a.c} \
+@@ -717,24 +694,6 @@
+ "-fPIE" \
+ ] \
+ [list \
+- "Run pr2404 with PIE" \
+- "-pie -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404a.so" \
+- "" \
+- { dummy.c } \
+- "pr2404pie" \
+- "pr2404.out" \
+- "-fPIE" \
+- ] \
+- [list \
+- "Run pr2404 with PIE (-z now)" \
+- "-pie -Wl,-z,now -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404n.so" \
+- "" \
+- { dummy.c } \
+- "pr2404pien" \
+- "pr2404.out" \
+- "-fPIE" \
+- ] \
+- [list \
+ "Run pr18718" \
+ "" \
+ "" \