Add gcc-4.9/binutils-2.24

Now gcc4.8 also compile with binutils-2.24 as well (from 2.23)

Change-Id: I249dd4414182d2b42c231ca9dbe1e2ec960b995e
diff --git a/build/core/add-application.mk b/build/core/add-application.mk
index 3b2cf23..04630e3 100644
--- a/build/core/add-application.mk
+++ b/build/core/add-application.mk
@@ -94,19 +94,19 @@
 # SPECIAL CASES:
 # 1) android-6 and android-7 are the same thing as android-5
 # 2) android-10 and 11 are the same thing as android-9
-# 3) android-19 and up are the same thing as android-19
+# 3) android-20 and up are the same thing as android-20
 #
 APP_PLATFORM_LEVEL := $(strip $(subst android-,,$(APP_PLATFORM)))
 ifneq (,$(filter 6 7,$(APP_PLATFORM_LEVEL)))
     APP_PLATFORM := android-5
-    $(call ndk_log,  Adjusting APP_PLATFORM android-$(APP_PLATFORM_LEVEL) to $(APP_PLATFORM))
 endif
 ifneq (,$(filter 10 11,$(APP_PLATFORM_LEVEL)))
     APP_PLATFORM := android-9
-    $(call ndk_log,  Adjusting APP_PLATFORM android-$(APP_PLATFORM_LEVEL) to $(APP_PLATFORM))
 endif
-ifneq (,$(call gt,$(APP_PLATFORM_LEVEL),19))
-    APP_PLATFORM := android-19
+ifneq (,$(call gt,$(APP_PLATFORM_LEVEL),20))
+    APP_PLATFORM := android-20
+endif
+ifneq ($(APP_PLATFORM),$(APP_PLATFORM_LEVEL))
     $(call ndk_log,  Adjusting APP_PLATFORM android-$(APP_PLATFORM_LEVEL) to $(APP_PLATFORM))
 endif
 
diff --git a/build/core/setup-abi.mk b/build/core/setup-abi.mk
index 478beaf..2fb06bb 100644
--- a/build/core/setup-abi.mk
+++ b/build/core/setup-abi.mk
@@ -26,24 +26,17 @@
 
 TARGET_OUT := $(NDK_APP_OUT)/$(_app)/$(TARGET_ARCH_ABI)
 
-# Special handling for x86: The minimal platform is android-9 here
+# Special handling for x86 and mips: The minimal platform is android-9 here
 # For now, handle this with a simple substitution. We may want to implement
 # more general filtering in the future when introducing other ABIs.
 TARGET_PLATFORM_SAVED := $(TARGET_PLATFORM)
-ifneq ($(filter %x86,$(TARGET_ARCH_ABI)),)
+ifneq ($(filter %x86 %mips,$(TARGET_ARCH_ABI)),)
 $(foreach _plat,3 4 5 8,\
     $(eval TARGET_PLATFORM := $$(subst android-$(_plat),android-9,$$(TARGET_PLATFORM)))\
 )
 endif
 
-# The minimal platform for mips is android-9
-ifneq ($(filter %mips,$(TARGET_ARCH_ABI)),)
-$(foreach _plat,3 4 5 8,\
-    $(eval TARGET_PLATFORM := $$(subst android-$(_plat),android-9,$$(TARGET_PLATFORM)))\
-)
-endif
-
-# The minimal platform for 64-bit is android-20
+# The minimal platform for 64-bit ABIs is android-20
 ifneq ($(filter %arm64-v8a %x86_64 %mips64,$(TARGET_ARCH_ABI)),)
 $(foreach _plat,3 4 5 8 9 10 11 12 13 14 15 16 17 18 19,\
     $(eval TARGET_PLATFORM := $$(subst android-$(_plat),android-20,$$(TARGET_PLATFORM)))\
diff --git a/build/core/setup-toolchain.mk b/build/core/setup-toolchain.mk
index c011e9a..657d94c 100644
--- a/build/core/setup-toolchain.mk
+++ b/build/core/setup-toolchain.mk
@@ -50,7 +50,7 @@
     endif
     # Select the last toolchain from the sorted list.
     # For now, this is enough to select armeabi-4.6 by default for ARM
-    TARGET_TOOLCHAIN := $(lastword $(TARGET_TOOLCHAIN_LIST))
+    TARGET_TOOLCHAIN := $(firstword $(TARGET_TOOLCHAIN_LIST))
 
     # If NDK_TOOLCHAIN_VERSION is defined, we replace the toolchain version
     # suffix with it.
diff --git a/build/tools/build-compiler-rt.sh b/build/tools/build-compiler-rt.sh
index 83d43f0..9dcee46 100755
--- a/build/tools/build-compiler-rt.sh
+++ b/build/tools/build-compiler-rt.sh
@@ -195,7 +195,7 @@
     local BUILDDIR="$2"
     local TYPE="$3"
     local DSTDIR="$4"
-    local GCCVER
+    local GCCVER LLVMVER
 
     mkdir -p "$BUILDDIR"
 
@@ -209,10 +209,18 @@
     if [ -n "$GCC_VERSION" ]; then
         GCCVER=$GCC_VERSION
     else
+        ARCH=$(convert_abi_to_arch $ABI)
+        GCCVER=$(get_default_gcc_version_for_arch $ARCH)
+    fi
+    LLVMVER=$LLVM_VERSION
+    # Hack: clang/llvm for arm64-v8a and mips64 aren't ready yet.  Use GCC instead
+    if [ "$ABI" = "arm64-v8a" -o "$ABI" = "mips64" ]; then
+        log "Auto-hack: Use GCC-$GCCVER instead of llvm-$LLVMVER for arm64-v8a and mips64"
+        LLVMVER=
         GCCVER=$(get_default_gcc_version_for_arch $ARCH)
     fi
 
-    builder_begin_android $ABI "$BUILDDIR" "$GCCVER" "$LLVM_VERSION" "$MAKEFILE"
+    builder_begin_android $ABI "$BUILDDIR" "$GCCVER" "$LLVMVER" "$MAKEFILE"
     builder_set_srcdir "$SRC_DIR"
     builder_set_dstdir "$DSTDIR"
 
diff --git a/build/tools/build-cxx-stl.sh b/build/tools/build-cxx-stl.sh
index 1d27ea0..60675da 100755
--- a/build/tools/build-cxx-stl.sh
+++ b/build/tools/build-cxx-stl.sh
@@ -81,7 +81,6 @@
 register_var_option "--with-debug-info" WITH_DEBUG_INFO "Build with -g.  STL is still built with optimization but with debug info"
 
 EXPLICIT_COMPILER_VERSION=
-AUTO_CONFIG_LLVM_VERSION=
 
 GCC_VERSION=
 register_var_option "--gcc-version=<ver>" GCC_VERSION "Specify GCC version" "$GCC_VERSION"
@@ -174,7 +173,6 @@
   # Use clang to build libc++ by default
   if [ "$EXPLICIT_COMPILER_VERSION" != "true" ]; then
     LLVM_VERSION=$DEFAULT_LLVM_VERSION
-    AUTO_CONFIG_LLVM_VERSION=yes
   fi
 else
   GABIXX_INCLUDES="-I$GABIXX_SRCDIR/include"
@@ -446,7 +444,7 @@
     local DSTDIR="$4"
     local FLOAT_ABI=""
     local DEFAULT_CFLAGS DEFAULT_CXXFLAGS
-    local SRC OBJ OBJECTS EXTRA_CFLAGS EXTRA_CXXFLAGS EXTRA_LDFLAGS LIB_SUFFIX GCCVER
+    local SRC OBJ OBJECTS EXTRA_CFLAGS EXTRA_CXXFLAGS EXTRA_LDFLAGS LIB_SUFFIX GCCVER LLVMVER
 
     mkdir -p "$BUILDDIR"
 
@@ -476,11 +474,11 @@
         GCCVER=$(get_default_gcc_version_for_arch $ARCH)
     fi
     LLVMVER=$LLVM_VERSION
-    if [ "$AUTO_CONFIG_LLVM_VERSION" = "yes" ]; then
-        # clang/llvm for arm64-v8a and mips64 aren't ready yet
-        if [ "$ABI" = "arm64-v8a" -o "$ABI" = "mips64" ]; then
-            LLVMVER=
-        fi
+    # Hack: clang/llvm for arm64-v8a and mips64 aren't ready yet.  Use GCC instead
+    if [ "$ABI" = "arm64-v8a" -o "$ABI" = "mips64" ]; then
+        log "Auto-hack: Use GCC-$GCCVER instead of llvm-$LLVMVER for arm64-v8a and mips64"
+        LLVMVER=
+        GCCVER=$(get_default_gcc_version_for_arch $ARCH)
     fi
 
     # libc++ built with clang (for ABI armeabi-only) produces
diff --git a/build/tools/build-gcc.sh b/build/tools/build-gcc.sh
index 174c0f0..0788764 100755
--- a/build/tools/build-gcc.sh
+++ b/build/tools/build-gcc.sh
@@ -315,6 +315,11 @@
     *) EXTRA_CONFIG_FLAGS=$EXTRA_CONFIG_FLAGS" --enable-libgomp" ;;
 esac
 
+# Disable libcilkrts which needs C++ for now, because libstdlibc++ in NDK is built separately...
+case "$TOOLCHAIN" in
+    x86*-4.9) EXTRA_CONFIG_FLAGS=$EXTRA_CONFIG_FLAGS" --disable-libcilkrts"
+esac
+
 # Disable libsanitizer (which depends on libstdc++ built separately) for now
 EXTRA_CONFIG_FLAGS=$EXTRA_CONFIG_FLAGS" --disable-libsanitizer"
 
@@ -481,7 +486,7 @@
 
 # Only create libgccunwind.a when building default version of gcc
 DEFAULT_GCC_VERSION=$(get_default_gcc_version_for_arch $ARCH)
-if [ "$HOST_OS" = "linux" -a "$GCC_VERSION" = "$DEFAULT_GCC_VERSION" ]; then # or latest gcc ie 4.8?
+if [ "$HOST_OS" = "linux" -a "$GCC_VERSION" = "$DEFAULT_GCC_VERSION" ]; then
     run create_unwind_library $ARCH $NDK_DIR
 fi
 
diff --git a/build/tools/build-gnu-libstdc++.sh b/build/tools/build-gnu-libstdc++.sh
index a9dc578..49d7c5f 100755
--- a/build/tools/build-gnu-libstdc++.sh
+++ b/build/tools/build-gnu-libstdc++.sh
@@ -305,8 +305,19 @@
 }
 
 GCC_VERSION_LIST=$(commas_to_spaces $GCC_VERSION_LIST)
-for VERSION in $GCC_VERSION_LIST; do
-    for ABI in $ABIS; do
+for ABI in $ABIS; do
+    ARCH=$(convert_abi_to_arch $ABI)
+    DEFAULT_GCC_VERSION=$(get_default_gcc_version_for_arch $ARCH)
+    BUILD_IT=
+    for VERSION in $GCC_VERSION_LIST; do
+        # Only build for this GCC version if it on or after DEFAULT_GCC_VERSION
+        if [ -z "$BUILD_IT" -a "$VERSION" = "$DEFAULT_GCC_VERSION" ]; then
+	    BUILD_IT=yes
+	fi
+	if [ -z "$BUILD_IT" ]; then
+            continue
+	fi
+
         build_gnustl_for_abi $ABI "$BUILD_DIR" static $VERSION
         build_gnustl_for_abi $ABI "$BUILD_DIR" shared $VERSION
         # build thumb version of libraries for 32-bit arm
@@ -328,6 +339,9 @@
 
         # Then, one package per version/ABI for libraries
         for ABI in $ABIS; do
+            if [ ! -d "$NDK_DIR/$GNUSTL_SUBDIR/$VERSION/libs/$ABI" ]; then
+                continue
+            fi
             FILES=""
             for LIB in include/bits libsupc++.a libgnustl_static.a libgnustl_shared.so; do
                 FILES="$FILES $GNUSTL_SUBDIR/$VERSION/libs/$ABI/$LIB"
diff --git a/build/tools/builder-funcs.sh b/build/tools/builder-funcs.sh
index b1d0842..53b52f6 100644
--- a/build/tools/builder-funcs.sh
+++ b/build/tools/builder-funcs.sh
@@ -498,7 +498,7 @@
     local ABI BUILDDIR LLVM_VERSION MAKEFILE
     local ARCH SYSROOT FLAGS
     local CRTBEGIN_SO_O CRTEND_SO_O CRTBEGIN_EXE_SO CRTEND_SO_O
-    local BINPREFIX GCC_TOOLCHAIN LLVM_TRIPLE
+    local BINPREFIX GCC_TOOLCHAIN LLVM_TRIPLE GCC_VERSION
     if [ -z "$NDK_DIR" ]; then
         panic "NDK_DIR is not defined!"
     elif [ ! -d "$NDK_DIR/platforms" ]; then
@@ -519,7 +519,7 @@
         BINPREFIX=$NDK_DIR/$(get_toolchain_binprefix_for_arch $ARCH $GCC_VERSION)
     else
         BINPREFIX=$NDK_DIR/$(get_llvm_toolchain_binprefix $LLVM_VERSION)
-        # override GCC_VERSION to pick 4.8 instead of the default
+        # override GCC_VERSION to pick $DEFAULT_LLVM_GCC_VERSION instead
         GCC_VERSION=$DEFAULT_LLVM_GCC_VERSION
         GCC_TOOLCHAIN=`dirname $NDK_DIR/$(get_toolchain_binprefix_for_arch $ARCH $GCC_VERSION)`
         GCC_TOOLCHAIN=`dirname $GCC_TOOLCHAIN`
diff --git a/build/tools/deploy-host-mcld.sh b/build/tools/deploy-host-mcld.sh
index 7deb36a..06335d9 100755
--- a/build/tools/deploy-host-mcld.sh
+++ b/build/tools/deploy-host-mcld.sh
@@ -37,7 +37,7 @@
 If --systems isn't specified, this script discovers all ld.mcld[.exe] in
 toolchains/llvm-$DEFAULT_LLVM_VERSION
 
-Note that one copy of ld.mcld serves all GCC {4.8, 4.7, 4.6, 4.4.3} x {arm, x86, mips} and
+Note that one copy of ld.mcld serves all GCC {4.9, 4.8, 4.7, 4.6, 4.4.3} x {arm, x86, mips} and
 LLVM {3.3, 3.4}.
 
 GCC passes -m flag for ld.mcld to figure out the right target.
@@ -94,7 +94,7 @@
     ALL_LD_MCLDS=
 
     # find all GNU ld with the same SYSTEM
-    ALL_LDS=`find toolchains \( -name "*-ld" -o -name "ld" -o -name "*-ld.exe" -o -name "ld.exe" \) | egrep "/arm|/x86|/mips" | grep $SYSTEM/`
+    ALL_LDS=`find toolchains \( -name "*-ld" -o -name "ld" -o -name "*-ld.exe" -o -name "ld.exe" \) | egrep "/arm|/x86|/mips|/aarch64" | grep $SYSTEM/`
     for LD in $ALL_LDS; do
         LD_NOEXE=${LD%%.exe}
         LD_MCLD=${LD_NOEXE}.mcld$HOST_EXE
diff --git a/build/tools/dev-defaults.sh b/build/tools/dev-defaults.sh
index ef06207..e39f9e9 100644
--- a/build/tools/dev-defaults.sh
+++ b/build/tools/dev-defaults.sh
@@ -9,7 +9,7 @@
 API_LEVELS="3 4 5 8 9 12 13 14 15 16 17 18 19"
 
 # Default ABIs for the target prebuilt binaries.
-PREBUILT_ABIS="armeabi armeabi-v7a x86 mips armeabi-v7a-hard"
+PREBUILT_ABIS="armeabi armeabi-v7a x86 mips armeabi-v7a-hard arm64-v8a x86_64 mips64"
 
 # Location of the STLport sources, relative to the NDK root directory
 STLPORT_SUBDIR=sources/cxx-stl/stlport
@@ -42,7 +42,7 @@
 TOOLCHAIN_GIT_DATE=now
 
 # The space-separated list of all GCC versions we support in this NDK
-DEFAULT_GCC_VERSION_LIST="4.6 4.8"
+DEFAULT_GCC_VERSION_LIST="4.6 4.8 4.9"
 
 # The default GCC version for 32-bit NDK is the first item in $DEFAULT_GCC_VERSION_LIST
 DEFAULT_GCC32_VERSION=$(echo "$DEFAULT_GCC_VERSION_LIST" | tr ' ' '\n' | head -n 1)
@@ -70,7 +70,7 @@
 DEFAULT_PLATFORM=android-9
 
 # The list of default CPU architectures we support
-DEFAULT_ARCHS="arm x86 mips"
+DEFAULT_ARCHS="arm x86 mips arm64 x86_64 mips64"
 
 # Default toolchain names and prefix
 #
@@ -208,13 +208,21 @@
 # Return empty for unknown arch
 get_toolchain_name_list_for_arch ()
 {
-    local PREFIX VERSION RET
+    local PREFIX VERSION RET ADD DEFAULT_GCC_VERSION
     PREFIX=$(eval echo \"\$DEFAULT_ARCH_TOOLCHAIN_NAME_$1\")
     if [ -z "$PREFIX" ]; then
         return 0
     fi
     RET=""
+    DEFAULT_GCC_VERSION=$(get_default_gcc_version_for_arch $1)
+    ADD=""
     for VERSION in $DEFAULT_GCC_VERSION_LIST; do
+        if [ -z "$ADD" -a "$VERSION" = "$DEFAULT_GCC_VERSION" ]; then
+            ADD="yes"
+        fi
+        if [ -z "$ADD" ]; then
+            continue
+        fi
         RET=$RET" $PREFIX-$VERSION"
     done
     RET=${RET## }
@@ -241,7 +249,7 @@
         *-4.4.3) echo "2.19";;
         x86*-4.7) echo "2.23";;  # Use 2.23 to get x32 support in ld.gold
         *-4.7) echo "2.22";;
-        *) echo "2.23";;
+        *) echo "2.24";;
     esac
 }
 
@@ -269,7 +277,7 @@
 get_default_gdb_version_for_gcc ()
 {
     case $1 in
-        x86*|aarch64-*|mips64el-*) echo "7.6";;
+        x86*|aarch64-*|mips64el-*|*-4.9) echo "7.6";;
         *) echo "$DEFAULT_GDB_VERSION";;
     esac
 }
diff --git a/build/tools/download-toolchain-sources.sh b/build/tools/download-toolchain-sources.sh
index 0e42c25..0b21b43 100755
--- a/build/tools/download-toolchain-sources.sh
+++ b/build/tools/download-toolchain-sources.sh
@@ -215,8 +215,8 @@
 toolchain_checkout "" $BRANCH isl .
 toolchain_checkout "" $BRANCH ppl .
 toolchain_checkout "" $BRANCH expat .
-toolchain_checkout "" $BRANCH binutils binutils-2.21 binutils-2.23
-toolchain_checkout "" $BRANCH gcc gcc-4.6 gcc-4.8
+toolchain_checkout "" $BRANCH binutils binutils-2.21 binutils-2.23 binutils-2.24
+toolchain_checkout "" $BRANCH gcc gcc-4.6 gcc-4.8 gcc-4.9
 toolchain_checkout "" $BRANCH gdb gdb-7.3.x gdb-7.6
 toolchain_checkout "" $BRANCH python Python-2.7.5
 toolchain_checkout "" $BRANCH perl perl-5.16.2
diff --git a/build/tools/prebuilt-common.sh b/build/tools/prebuilt-common.sh
index 69e1303..38626aa 100644
--- a/build/tools/prebuilt-common.sh
+++ b/build/tools/prebuilt-common.sh
@@ -1263,7 +1263,7 @@
             if [ "$(arch_in_unknown_archs $ABI)" = "yes" ]; then
                 RET=$ABI
             else
-                >&2 echo "ERROR: Unsupported ABI name: $ABI, use one of: armeabi, armeabi-v7a, x86, mips or armeabi-v7a-hard"
+                >&2 echo "ERROR: Unsupported ABI name: $ABI, use one of: armeabi, armeabi-v7a, x86, mips, armeabi-v7a-hard, arm64-v8a, x86_64 or mips64"
                 exit 1
             fi
             ;;
diff --git a/build/tools/toolchain-patches/gcc/0001-Enable-C-exceptions-and-RTTI-by-default.patch b/build/tools/toolchain-patches/gcc/0001-Enable-C-exceptions-and-RTTI-by-default.patch
index fd727cf..eca3ca9 100644
--- a/build/tools/toolchain-patches/gcc/0001-Enable-C-exceptions-and-RTTI-by-default.patch
+++ b/build/tools/toolchain-patches/gcc/0001-Enable-C-exceptions-and-RTTI-by-default.patch
@@ -6,11 +6,13 @@
 With this change, -fexceptions and -frtti become default options
 when compiling C++ sources.
 ---
- gcc-4.6/gcc/config/linux-android.h   |    4 ++--
- 2 files changed, 4 insertions(+), 4 deletions(-)
+ gcc-4.6/gcc/config/linux-android.h | 4 ++--
+ gcc-4.8/gcc/config/linux-android.h | 4 ++--
+ gcc-4.9/gcc/config/linux-android.h | 4 ++--
+ 3 files changed, 6 insertions(+), 6 deletions(-)
 
 diff --git a/gcc-4.6/gcc/config/linux-android.h b/gcc-4.6/gcc/config/linux-android.h
-index 94c5274..7256082 100644
+index c19b1c1..6fa4f53 100644
 --- a/gcc-4.6/gcc/config/linux-android.h
 +++ b/gcc-4.6/gcc/config/linux-android.h
 @@ -46,8 +46,8 @@
@@ -25,7 +27,7 @@
  #define ANDROID_ASM_SPEC \
    "--noexecstack"
 diff --git a/gcc-4.8/gcc/config/linux-android.h b/gcc-4.8/gcc/config/linux-android.h
-index 2c87c84..47a3e7c 100644
+index 87957e3..e88ab78 100644
 --- a/gcc-4.8/gcc/config/linux-android.h
 +++ b/gcc-4.8/gcc/config/linux-android.h
 @@ -45,8 +45,8 @@
@@ -39,5 +41,21 @@
  
  #define ANDROID_ASM_SPEC \
    "--noexecstack"
+diff --git a/gcc-4.9/gcc/config/linux-android.h b/gcc-4.9/gcc/config/linux-android.h
+index 26f1a74..e5114c2 100644
+--- a/gcc-4.9/gcc/config/linux-android.h
++++ b/gcc-4.9/gcc/config/linux-android.h
+@@ -45,8 +45,8 @@
+   "%{!fno-pic:%{!fno-PIC:%{!fpic:%{!fPIC: -fPIC}}}}"
+ 
+ #define ANDROID_CC1PLUS_SPEC						\
+-  "%{!fexceptions:%{!fno-exceptions: -fno-exceptions}} "		\
+-  "%{!frtti:%{!fno-rtti: -fno-rtti}}"
++  "%{!fexceptions:%{!fno-exceptions: -fexceptions}} "		\
++  "%{!frtti:%{!fno-rtti: -frtti}}"
+ 
+ #define ANDROID_LIB_SPEC \
+   "%{!static: -ldl}"
 -- 
-1.7.6.rc0
+1.9.1.423.g4596e3a
+
diff --git a/build/tools/toolchain-patches/gcc/0002-gcc-prevent-crash-on-Eclair-and-older-platforms.patch b/build/tools/toolchain-patches/gcc/0002-gcc-prevent-crash-on-Eclair-and-older-platforms.patch
index ee9f307..b67cd97 100644
--- a/build/tools/toolchain-patches/gcc/0002-gcc-prevent-crash-on-Eclair-and-older-platforms.patch
+++ b/build/tools/toolchain-patches/gcc/0002-gcc-prevent-crash-on-Eclair-and-older-platforms.patch
@@ -21,8 +21,10 @@
 are all in the C library on Android, unlike legacy Linux systems
 which put them in libpthread.so (and provide weak stubs in libc.so).
 ---
- gcc-4.6/gcc/gthr-posix.h   |   13 +++++++++++++
- 2 files changed, 26 insertions(+), 0 deletions(-)
+ gcc-4.6/gcc/gthr-posix.h    | 13 +++++++++++++
+ gcc-4.8/libgcc/gthr-posix.h | 13 +++++++++++++
+ gcc-4.9/libgcc/gthr-posix.h | 13 +++++++++++++
+ 3 files changed, 39 insertions(+)
 
 diff --git a/gcc-4.6/gcc/gthr-posix.h b/gcc-4.6/gcc/gthr-posix.h
 index ecb06e2..8372c64 100644
@@ -72,6 +74,30 @@
  #include <pthread.h>
  
  #if ((defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)) \
+diff --git a/gcc-4.9/libgcc/gthr-posix.h b/gcc-4.9/libgcc/gthr-posix.h
+index 7003a91..19d7d5f 100644
+--- a/gcc-4.9/libgcc/gthr-posix.h
++++ b/gcc-4.9/libgcc/gthr-posix.h
+@@ -32,6 +32,19 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+ #define __GTHREADS 1
+ #define __GTHREADS_CXX0X 1
+ 
++/* The following should normally be in a different header file,
++ * but I couldn't find the right location. The point of the macro
++ * definition below is to prevent libsupc++ and libstdc++ to reference
++ * weak symbols in their static C++ constructors. Such code crashes
++ * when a shared object linked statically to these libraries is
++ * loaded on Android 2.1 (Eclair) and older platform releases, due
++ * to a dynamic linker bug.
++ */
++#ifdef __ANDROID__
++#undef GTHREAD_USE_WEAK
++#define GTHREAD_USE_WEAK 0
++#endif
++
+ #include <pthread.h>
+ 
+ #if ((defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)) \
 -- 
-1.7.6.rc0
+1.9.1.423.g4596e3a
 
diff --git a/build/tools/toolchain-patches/gcc/0003-Rename-libstdc++.so-to-libgnustl_shared.so.patch b/build/tools/toolchain-patches/gcc/0003-Rename-libstdc++.so-to-libgnustl_shared.so.patch
index e9ef86b..411a330 100644
--- a/build/tools/toolchain-patches/gcc/0003-Rename-libstdc++.so-to-libgnustl_shared.so.patch
+++ b/build/tools/toolchain-patches/gcc/0003-Rename-libstdc++.so-to-libgnustl_shared.so.patch
@@ -10,10 +10,11 @@
 ---
  gcc-4.6/libstdc++-v3/src/Makefile.in | 5 ++++-
  gcc-4.8/libstdc++-v3/src/Makefile.in | 5 ++++-
- 2 files changed, 8 insertions(+), 2 deletions(-)
+ gcc-4.9/libstdc++-v3/src/Makefile.in | 5 ++++-
+ 3 files changed, 12 insertions(+), 3 deletions(-)
 
 diff --git a/gcc-4.6/libstdc++-v3/src/Makefile.in b/gcc-4.6/libstdc++-v3/src/Makefile.in
-index 146ec3f..99f0f56 100644
+index d03acd5..5abd1d2 100644
 --- a/gcc-4.6/libstdc++-v3/src/Makefile.in
 +++ b/gcc-4.6/libstdc++-v3/src/Makefile.in
 @@ -340,7 +340,7 @@ WARN_CXXFLAGS = \
@@ -36,7 +37,7 @@
  	-rm -f *.$(OBJEXT)
  
 diff --git a/gcc-4.8/libstdc++-v3/src/Makefile.in b/gcc-4.8/libstdc++-v3/src/Makefile.in
-index 69001b4..e875539 100644
+index 9721ebb..dd3d426 100644
 --- a/gcc-4.8/libstdc++-v3/src/Makefile.in
 +++ b/gcc-4.8/libstdc++-v3/src/Makefile.in
 @@ -336,7 +336,7 @@ AM_CPPFLAGS = $(GLIBCXX_INCLUDES)
@@ -58,6 +59,29 @@
  mostlyclean-compile:
  	-rm -f *.$(OBJEXT)
  
+diff --git a/gcc-4.9/libstdc++-v3/src/Makefile.in b/gcc-4.9/libstdc++-v3/src/Makefile.in
+index cd3943b..ec04005 100644
+--- a/gcc-4.9/libstdc++-v3/src/Makefile.in
++++ b/gcc-4.9/libstdc++-v3/src/Makefile.in
+@@ -342,7 +342,7 @@ AM_CPPFLAGS = $(GLIBCXX_INCLUDES)
+ SUBDIRS = c++98 c++11
+ 
+ # Cross compiler support.
+-toolexeclib_LTLIBRARIES = libstdc++.la
++toolexeclib_LTLIBRARIES = libgnustl_shared.la
+ @GLIBCXX_LDBL_COMPAT_FALSE@ldbl_compat_sources = 
+ @GLIBCXX_LDBL_COMPAT_TRUE@ldbl_compat_sources = compatibility-ldbl.cc
+ parallel_compat_sources = \
+@@ -552,6 +552,9 @@ clean-toolexeclibLTLIBRARIES:
+ libstdc++.la: $(libstdc___la_OBJECTS) $(libstdc___la_DEPENDENCIES) 
+ 	$(libstdc___la_LINK) -rpath $(toolexeclibdir) $(libstdc___la_OBJECTS) $(libstdc___la_LIBADD) $(LIBS)
+ 
++libgnustl_shared.la: $(libstdc___la_OBJECTS) $(libstdc___la_DEPENDENCIES)
++	$(libstdc___la_LINK) -rpath $(toolexeclibdir) $(libstdc___la_OBJECTS) $(libstdc___la_LIBADD) $(LIBS)
++
+ mostlyclean-compile:
+ 	-rm -f *.$(OBJEXT)
+ 
 -- 
-1.7.6.rc0
+1.9.1.423.g4596e3a
 
diff --git a/toolchains/aarch64-linux-android-4.9/config.mk b/toolchains/aarch64-linux-android-4.9/config.mk
new file mode 100644
index 0000000..79efda1
--- /dev/null
+++ b/toolchains/aarch64-linux-android-4.9/config.mk
@@ -0,0 +1,20 @@
+# Copyright (C) 2014 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# config file for the arm64 gcc-4.9 toolchain for the Android NDK
+# the real meat is in the setup.mk file adjacent to this one
+#
+TOOLCHAIN_ARCH := arm64
+TOOLCHAIN_ABIS := arm64-v8a
diff --git a/toolchains/aarch64-linux-android-4.9/setup.mk b/toolchains/aarch64-linux-android-4.9/setup.mk
new file mode 100644
index 0000000..90089c3
--- /dev/null
+++ b/toolchains/aarch64-linux-android-4.9/setup.mk
@@ -0,0 +1,62 @@
+# Copyright (C) 2014 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# this file is used to prepare the NDK to build with the arm64 gcc-4.9
+# toolchain any number of source files
+#
+# its purpose is to define (or re-define) templates used to build
+# various sources into target object files, libraries or executables.
+#
+# Note that this file may end up being parsed several times in future
+# revisions of the NDK.
+#
+
+TOOLCHAIN_NAME   := aarch64-linux-android-4.9
+TOOLCHAIN_PREFIX := $(TOOLCHAIN_PREBUILT_ROOT)/bin/aarch64-linux-android-
+
+TARGET_CFLAGS := \
+    -fpic \
+    -ffunction-sections \
+    -funwind-tables \
+    -fstack-protector \
+    -no-canonical-prefixes
+
+TARGET_C_INCLUDES := \
+    $(SYSROOT_INC)/usr/include
+
+TARGET_LDFLAGS := -no-canonical-prefixes
+
+TARGET_arm64_release_CFLAGS := -O2 \
+                               -g \
+                               -DNDEBUG \
+                               -fomit-frame-pointer \
+                               -fstrict-aliasing    \
+                               -funswitch-loops     \
+                               -finline-limit=300
+
+TARGET_arm64_debug_CFLAGS := $(TARGET_arm64_release_CFLAGS) \
+                             -O0 \
+                             -UNDEBUG \
+                             -fno-omit-frame-pointer \
+                             -fno-strict-aliasing
+
+# This function will be called to determine the target CFLAGS used to build
+# a C or Assembler source file, based on its tags.
+#
+TARGET-process-src-files-tags = \
+$(eval __debug_sources := $(call get-src-files-with-tag,debug)) \
+$(eval __release_sources := $(call get-src-files-without-tag,debug)) \
+$(call set-src-files-target-cflags, $(__debug_sources), $(TARGET_x86_64_debug_CFLAGS)) \
+$(call set-src-files-target-cflags, $(__release_sources),$(TARGET_x86_64_release_CFLAGS)) \
diff --git a/toolchains/arm-linux-androideabi-4.9/config.mk b/toolchains/arm-linux-androideabi-4.9/config.mk
new file mode 100644
index 0000000..10a7368
--- /dev/null
+++ b/toolchains/arm-linux-androideabi-4.9/config.mk
@@ -0,0 +1,20 @@
+# Copyright (C) 2009 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# config file for the arm gcc-4.9 toolchain for the Android NDK
+# the real meat is in the setup.mk file adjacent to this one
+#
+TOOLCHAIN_ARCH := arm
+TOOLCHAIN_ABIS := armeabi armeabi-v7a armeabi-v7a-hard
diff --git a/toolchains/arm-linux-androideabi-4.9/setup.mk b/toolchains/arm-linux-androideabi-4.9/setup.mk
new file mode 100644
index 0000000..c0d0eac
--- /dev/null
+++ b/toolchains/arm-linux-androideabi-4.9/setup.mk
@@ -0,0 +1,116 @@
+# Copyright (C) 2009 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# this file is used to prepare the NDK to build with the arm gcc-4.9
+# toolchain any number of source files
+#
+# its purpose is to define (or re-define) templates used to build
+# various sources into target object files, libraries or executables.
+#
+# Note that this file may end up being parsed several times in future
+# revisions of the NDK.
+#
+
+TARGET_CFLAGS := \
+    -fpic \
+    -ffunction-sections \
+    -funwind-tables \
+    -fstack-protector \
+    -no-canonical-prefixes
+
+TARGET_LDFLAGS := -no-canonical-prefixes
+
+TARGET_C_INCLUDES := \
+    $(SYSROOT_INC)/usr/include
+
+ifneq ($(filter $(TARGET_ARCH_ABI), armeabi-v7a armeabi-v7a-hard),)
+    TARGET_CFLAGS += -march=armv7-a \
+                     -mfpu=vfpv3-d16
+    TARGET_LDFLAGS += -march=armv7-a \
+                     -Wl,--fix-cortex-a8
+ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
+    TARGET_CFLAGS += -mfloat-abi=softfp
+else
+    TARGET_CFLAGS += -mhard-float \
+                     -D_NDK_MATH_NO_SOFTFP=1
+    TARGET_LDFLAGS += -Wl,--no-warn-mismatch \
+                     -lm_hard
+endif
+
+else
+    TARGET_CFLAGS += -march=armv5te \
+                            -mtune=xscale \
+                            -msoft-float
+endif
+
+TARGET_CFLAGS.neon := -mfpu=neon
+
+TARGET_arm_release_CFLAGS :=  -O2 \
+                              -g \
+                              -DNDEBUG \
+                              -fomit-frame-pointer \
+                              -fstrict-aliasing    \
+                              -funswitch-loops     \
+                              -finline-limit=300
+
+TARGET_thumb_release_CFLAGS := -mthumb \
+                               -Os \
+                               -g \
+                               -DNDEBUG \
+                               -fomit-frame-pointer \
+                               -fno-strict-aliasing \
+                               -finline-limit=64
+
+# When building for debug, compile everything as arm.
+TARGET_arm_debug_CFLAGS := $(TARGET_arm_release_CFLAGS) \
+                           -O0 \
+                           -UNDEBUG \
+                           -fno-omit-frame-pointer \
+                           -fno-strict-aliasing
+
+TARGET_thumb_debug_CFLAGS := $(TARGET_thumb_release_CFLAGS) \
+                             -O0 \
+                             -UNDEBUG \
+                             -marm \
+                             -fno-omit-frame-pointer
+
+# This function will be called to determine the target CFLAGS used to build
+# a C or Assembler source file, based on its tags.
+#
+TARGET-process-src-files-tags = \
+$(eval __arm_sources := $(call get-src-files-with-tag,arm)) \
+$(eval __thumb_sources := $(call get-src-files-without-tag,arm)) \
+$(eval __debug_sources := $(call get-src-files-with-tag,debug)) \
+$(eval __release_sources := $(call get-src-files-without-tag,debug)) \
+$(call set-src-files-target-cflags, \
+    $(call set_intersection,$(__arm_sources),$(__debug_sources)), \
+    $(TARGET_arm_debug_CFLAGS)) \
+$(call set-src-files-target-cflags,\
+    $(call set_intersection,$(__arm_sources),$(__release_sources)),\
+    $(TARGET_arm_release_CFLAGS)) \
+$(call set-src-files-target-cflags,\
+    $(call set_intersection,$(__arm_sources),$(__debug_sources)),\
+    $(TARGET_arm_debug_CFLAGS)) \
+$(call set-src-files-target-cflags,\
+    $(call set_intersection,$(__thumb_sources),$(__release_sources)),\
+    $(TARGET_thumb_release_CFLAGS)) \
+$(call set-src-files-target-cflags,\
+    $(call set_intersection,$(__thumb_sources),$(__debug_sources)),\
+    $(TARGET_thumb_debug_CFLAGS)) \
+$(call add-src-files-target-cflags,\
+    $(call get-src-files-with-tag,neon),\
+    $(TARGET_CFLAGS.neon)) \
+$(call set-src-files-text,$(__arm_sources),arm) \
+$(call set-src-files-text,$(__thumb_sources),thumb)
diff --git a/toolchains/mips64el-linux-android-4.9/config.mk b/toolchains/mips64el-linux-android-4.9/config.mk
new file mode 100644
index 0000000..91fe648
--- /dev/null
+++ b/toolchains/mips64el-linux-android-4.9/config.mk
@@ -0,0 +1,20 @@
+# Copyright (C) 2014 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# config file for the mips64el gcc-4.9 toolchain for the Android NDK
+# the real meat is in the setup.mk file adjacent to this one
+#
+TOOLCHAIN_ARCH := mips64
+TOOLCHAIN_ABIS := mips64
diff --git a/toolchains/mips64el-linux-android-4.9/setup.mk b/toolchains/mips64el-linux-android-4.9/setup.mk
new file mode 100644
index 0000000..a65b0e6
--- /dev/null
+++ b/toolchains/mips64el-linux-android-4.9/setup.mk
@@ -0,0 +1,66 @@
+# Copyright (C) 2014 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# this file is used to prepare the NDK to build with the mips64el gcc-4.9
+# toolchain any number of source files
+#
+# its purpose is to define (or re-define) templates used to build
+# various sources into target object files, libraries or executables.
+#
+# Note that this file may end up being parsed several times in future
+# revisions of the NDK.
+#
+
+TARGET_CFLAGS := \
+        -fpic \
+        -fno-strict-aliasing \
+        -finline-functions \
+        -ffunction-sections \
+        -funwind-tables \
+        -fmessage-length=0 \
+        -fno-inline-functions-called-once \
+        -fgcse-after-reload \
+        -frerun-cse-after-loop \
+        -frename-registers \
+        -no-canonical-prefixes
+
+TARGET_LDFLAGS := -no-canonical-prefixes
+
+TARGET_C_INCLUDES := \
+    $(SYSROOT_INC)/usr/include
+
+TARGET_mips64_release_CFLAGS := -O2 \
+                                -g \
+                                -DNDEBUG \
+                                -fomit-frame-pointer \
+                                -funswitch-loops     \
+                                -finline-limit=300
+
+TARGET_mips64_debug_CFLAGS := -O0 \
+                              -g \
+                              -fno-omit-frame-pointer
+
+
+# This function will be called to determine the target CFLAGS used to build
+# a C or Assembler source file, based on its tags.
+TARGET-process-src-files-tags = \
+$(eval __debug_sources := $(call get-src-files-with-tag,debug)) \
+$(eval __release_sources := $(call get-src-files-without-tag,debug)) \
+$(call set-src-files-target-cflags, \
+    $(__debug_sources),\
+    $(TARGET_mips64_debug_CFLAGS)) \
+$(call set-src-files-target-cflags,\
+    $(__release_sources),\
+    $(TARGET_mips64_release_CFLAGS)) \
diff --git a/toolchains/mipsel-linux-android-4.9/config.mk b/toolchains/mipsel-linux-android-4.9/config.mk
new file mode 100644
index 0000000..7902cc7
--- /dev/null
+++ b/toolchains/mipsel-linux-android-4.9/config.mk
@@ -0,0 +1,20 @@
+# Copyright (C) 2009 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# config file for the mipsel gcc-4.9 toolchain for the Android NDK
+# the real meat is in the setup.mk file adjacent to this one
+#
+TOOLCHAIN_ARCH := mips
+TOOLCHAIN_ABIS := mips
diff --git a/toolchains/mipsel-linux-android-4.9/setup.mk b/toolchains/mipsel-linux-android-4.9/setup.mk
new file mode 100644
index 0000000..f4848e7
--- /dev/null
+++ b/toolchains/mipsel-linux-android-4.9/setup.mk
@@ -0,0 +1,66 @@
+# Copyright (C) 2009 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# this file is used to prepare the NDK to build with the mipsel gcc-4.9
+# toolchain any number of source files
+#
+# its purpose is to define (or re-define) templates used to build
+# various sources into target object files, libraries or executables.
+#
+# Note that this file may end up being parsed several times in future
+# revisions of the NDK.
+#
+
+TARGET_CFLAGS := \
+        -fpic \
+        -fno-strict-aliasing \
+        -finline-functions \
+        -ffunction-sections \
+        -funwind-tables \
+        -fmessage-length=0 \
+        -fno-inline-functions-called-once \
+        -fgcse-after-reload \
+        -frerun-cse-after-loop \
+        -frename-registers \
+        -no-canonical-prefixes
+
+TARGET_LDFLAGS := -no-canonical-prefixes
+
+TARGET_C_INCLUDES := \
+    $(SYSROOT_INC)/usr/include
+
+TARGET_mips_release_CFLAGS := -O2 \
+                              -g \
+                              -DNDEBUG \
+                              -fomit-frame-pointer \
+                              -funswitch-loops     \
+                              -finline-limit=300
+
+TARGET_mips_debug_CFLAGS := -O0 \
+                            -g \
+                            -fno-omit-frame-pointer
+
+
+# This function will be called to determine the target CFLAGS used to build
+# a C or Assembler source file, based on its tags.
+TARGET-process-src-files-tags = \
+$(eval __debug_sources := $(call get-src-files-with-tag,debug)) \
+$(eval __release_sources := $(call get-src-files-without-tag,debug)) \
+$(call set-src-files-target-cflags, \
+    $(__debug_sources),\
+    $(TARGET_mips_debug_CFLAGS)) \
+$(call set-src-files-target-cflags,\
+    $(__release_sources),\
+    $(TARGET_mips_release_CFLAGS)) \
diff --git a/toolchains/x86-4.9/config.mk b/toolchains/x86-4.9/config.mk
new file mode 100644
index 0000000..42e6a0b
--- /dev/null
+++ b/toolchains/x86-4.9/config.mk
@@ -0,0 +1,20 @@
+# Copyright (C) 2009 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# config file for the x86 gcc-4.9 toolchain for the Android NDK
+# the real meat is in the setup.mk file adjacent to this one
+#
+TOOLCHAIN_ARCH := x86
+TOOLCHAIN_ABIS := x86
diff --git a/toolchains/x86-4.9/setup.mk b/toolchains/x86-4.9/setup.mk
new file mode 100644
index 0000000..a6972d0
--- /dev/null
+++ b/toolchains/x86-4.9/setup.mk
@@ -0,0 +1,67 @@
+# Copyright (C) 2009 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# this file is used to prepare the NDK to build with the x86 gcc-4.9
+# toolchain any number of source files
+#
+# its purpose is to define (or re-define) templates used to build
+# various sources into target object files, libraries or executables.
+#
+# Note that this file may end up being parsed several times in future
+# revisions of the NDK.
+#
+
+TOOLCHAIN_NAME   := x86-4.9
+TOOLCHAIN_PREFIX := $(TOOLCHAIN_PREBUILT_ROOT)/bin/i686-linux-android-
+
+TARGET_CFLAGS := \
+    -ffunction-sections \
+    -funwind-tables \
+    -no-canonical-prefixes
+
+TARGET_C_INCLUDES := \
+    $(SYSROOT_INC)/usr/include
+
+# Add and LDFLAGS for the target here
+TARGET_LDFLAGS := -no-canonical-prefixes
+
+TARGET_CFLAGS += -fstack-protector
+
+TARGET_x86_release_CFLAGS := -O2 \
+                             -g \
+                             -DNDEBUG \
+                             -fomit-frame-pointer \
+                             -fstrict-aliasing    \
+                             -funswitch-loops     \
+                             -finline-limit=300
+
+TARGET_x86_debug_CFLAGS := $(TARGET_x86_release_CFLAGS) \
+                           -O0 \
+                           -UNDEBUG \
+                           -fno-omit-frame-pointer \
+                           -fno-strict-aliasing
+
+# This function will be called to determine the target CFLAGS used to build
+# a C or Assembler source file, based on its tags.
+#
+TARGET-process-src-files-tags = \
+$(eval __debug_sources := $(call get-src-files-with-tag,debug)) \
+$(eval __release_sources := $(call get-src-files-without-tag,debug)) \
+$(call set-src-files-target-cflags, $(__debug_sources), $(TARGET_x86_debug_CFLAGS)) \
+$(call set-src-files-target-cflags, $(__release_sources),$(TARGET_x86_release_CFLAGS)) \
+
+# The ABI-specific sub-directory that the SDK tools recognize for
+# this toolchain's generated binaries
+TARGET_ABI_SUBDIR := x86
diff --git a/toolchains/x86_64-4.9/config.mk b/toolchains/x86_64-4.9/config.mk
new file mode 100644
index 0000000..e3ec61d
--- /dev/null
+++ b/toolchains/x86_64-4.9/config.mk
@@ -0,0 +1,20 @@
+# Copyright (C) 2009 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# config file for the x86_64 gcc-4.9 toolchain for the Android NDK
+# the real meat is in the setup.mk file adjacent to this one
+#
+TOOLCHAIN_ARCH := x86_64
+TOOLCHAIN_ABIS := x86_64
diff --git a/toolchains/x86_64-4.9/setup.mk b/toolchains/x86_64-4.9/setup.mk
new file mode 100644
index 0000000..53a5152
--- /dev/null
+++ b/toolchains/x86_64-4.9/setup.mk
@@ -0,0 +1,65 @@
+# Copyright (C) 2009 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# this file is used to prepare the NDK to build with the x86_64 gcc-4.9
+# toolchain any number of source files
+#
+# its purpose is to define (or re-define) templates used to build
+# various sources into target object files, libraries or executables.
+#
+# Note that this file may end up being parsed several times in future
+# revisions of the NDK.
+#
+
+TOOLCHAIN_NAME   := x86_64-4.9
+TOOLCHAIN_PREFIX := $(TOOLCHAIN_PREBUILT_ROOT)/bin/x86_64-linux-android-
+
+TARGET_CFLAGS := \
+    -ffunction-sections \
+    -funwind-tables \
+    -fstack-protector \
+    -no-canonical-prefixes
+
+TARGET_C_INCLUDES := \
+    $(SYSROOT_INC)/usr/include
+
+TARGET_LDFLAGS := -no-canonical-prefixes
+
+TARGET_x86_64_release_CFLAGS := -O2 \
+                             -g \
+                             -DNDEBUG \
+                             -fomit-frame-pointer \
+                             -fstrict-aliasing    \
+                             -funswitch-loops     \
+                             -finline-limit=300
+
+TARGET_x86_64_debug_CFLAGS := $(TARGET_x86_64_release_CFLAGS) \
+                           -O0 \
+                           -UNDEBUG \
+                           -fno-omit-frame-pointer \
+                           -fno-strict-aliasing
+
+# This function will be called to determine the target CFLAGS used to build
+# a C or Assembler source file, based on its tags.
+#
+TARGET-process-src-files-tags = \
+$(eval __debug_sources := $(call get-src-files-with-tag,debug)) \
+$(eval __release_sources := $(call get-src-files-without-tag,debug)) \
+$(call set-src-files-target-cflags, $(__debug_sources), $(TARGET_x86_64_debug_CFLAGS)) \
+$(call set-src-files-target-cflags, $(__release_sources),$(TARGET_x86_64_release_CFLAGS)) \
+
+# The ABI-specific sub-directory that the SDK tools recognize for
+# this toolchain's generated binaries
+TARGET_ABI_SUBDIR := x86_64