Fix binutils build for .init_array and -pie support

The --enable-initfini-array switch is necessary for the linker
to support the modern style of constructor magic that is the only
thing we support for dynamic linking.

The binutils patch (from forthcoming upstream 2.27 release) fixes
aarch64's missing -pie support, which we need for dynamic linking.

Change-Id: Iebf211fccca4428bd5c51279431d6aed0f525157
diff --git a/doit b/doit
index 07bf068..60a9e57 100755
--- a/doit
+++ b/doit
@@ -221,7 +221,7 @@
         echo building binutils
         mkdir -p $BINBUILDPATH
         pushd $BINBUILDPATH
-        log ../binutils-$BINVER/configure --target=$TARGET --prefix=$INSTALLPATH --disable-werror
+        log ../binutils-$BINVER/configure --target=$TARGET --prefix=$INSTALLPATH --disable-werror --enable-initfini-array
         log $MAKE $PARALLEL
         log $MAKE install
         touch built.txt
diff --git a/patches/binutils-patch.txt b/patches/binutils-patch.txt
index e69de29..592de0d 100644
--- a/patches/binutils-patch.txt
+++ b/patches/binutils-patch.txt
@@ -0,0 +1,38 @@
+commit 8d1a739279315a6abafbb1632da51cda60160217
+Author: Roland McGrath <mcgrathr@chromium.org>
+Date:   Tue Jul 19 10:19:06 2016 -0700
+
+    Support -pie for aarch64*-elf targets.
+    
+    ld/
+    	* emulparams/aarch64elf.sh (GENERATE_PIE_SCRIPT): Set to yes.
+    	* emulparams/aarch64elf32.sh: Likewise.
+    
+    (cherry picked from commit 3af09e8db3084f5e03b7f09768a2ab6415418e63)
+
+diff --git a/ld/emulparams/aarch64elf.sh b/ld/emulparams/aarch64elf.sh
+index 6864d65..6eb2bad 100644
+--- a/ld/emulparams/aarch64elf.sh
++++ b/ld/emulparams/aarch64elf.sh
+@@ -13,6 +13,8 @@ TEMPLATE_NAME=elf32
+ EXTRA_EM_FILE=aarch64elf
+ 
+ GENERATE_SHLIB_SCRIPT=yes
++GENERATE_PIE_SCRIPT=yes
++
+ MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
+ 
+ ENTRY=_start
+diff --git a/ld/emulparams/aarch64elf32.sh b/ld/emulparams/aarch64elf32.sh
+index f85c9ff..c0d6b72 100644
+--- a/ld/emulparams/aarch64elf32.sh
++++ b/ld/emulparams/aarch64elf32.sh
+@@ -13,6 +13,8 @@ TEMPLATE_NAME=elf32
+ EXTRA_EM_FILE=aarch64elf
+ 
+ GENERATE_SHLIB_SCRIPT=yes
++GENERATE_PIE_SCRIPT=yes
++
+ MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
+ 
+ ENTRY=_start