diff -r 45760158aca3 -r 8f8b94c987fe scripts/build/cc/gcc.sh
--- a/scripts/build/cc/gcc.sh Tue Feb 04 07:55:11 2014 +0000
+++ b/scripts/build/cc/gcc.sh Tue Feb 04 08:08:40 2014 +0000
@@ -375,6 +375,7 @@

     if [ "${CT_MULTILIB}" = "y" ]; then
         extra_config+=("--enable-multilib")
+        extra_config+=("--enable-targets=all")
     else
         extra_config+=("--disable-multilib")
     fi
diff -r 45760158aca3 -r 8f8b94c987fe scripts/build/libc/glibc-eglibc.sh-common
--- a/scripts/build/libc/glibc-eglibc.sh-common Tue Feb 04 07:55:11 2014 +0000
+++ b/scripts/build/libc/glibc-eglibc.sh-common Tue Feb 04 08:08:40 2014 +0000
@@ -76,6 +76,9 @@
     local multilib
     local multi_dir
     local multi_flags
+    local multi_arch
+    local native_arch
+    local rest_of_triplet
     local extra_dir
     local libc_headers libc_startfiles libc_full
     local hdr
@@ -85,6 +88,9 @@
         eval "${arg// /\\ }"
     done

+    native_arch=$(echo "${CT_TARGET}" | ${sed} "s,\(^[^\-]*\).*,\1,g")
+    rest_of_triplet=$(echo "${CT_TARGET}" | ${sed} "s,^[^\-]*\(.*\),\1,g")
+
     case "${libc_mode}" in
         startfiles)
             CT_DoStep INFO "Installing C library headers & start files"
@@ -103,8 +109,16 @@

     # If gcc is not configured for multilib, it still prints
     # a single line for the default settings
-    multilibs=( $("${CT_TARGET}-gcc" -print-multi-lib 2>/dev/null) )
+    # sort -r is a hack so that x86_64 gets built last because
+    # pre-2.16 only the x86_64 headers were applicable to both
+    # i686 and x86_64.
+    # The headers were unified (x86-64 won!) between 2.15 and
+    # 2.16 (BZ14117). This hack makes too many of assumptions
+    # and needs to be replaced with more robust logic. We need
+    # to force x86_64 arch to be last element in the array.
+    multilibs=( $("${CT_TARGET}-gcc" -print-multi-lib 2>/dev/null | sort -r) )
     for multilib in "${multilibs[@]}"; do
+        multi_arch="${native_arch}"
         multi_dir="${multilib%%;*}"
         if [ "${multi_dir}" != "." ]; then
             CT_DoStep INFO "Building for multilib subdir='${multi_dir}'"
@@ -114,6 +128,14 @@
                           )"
             extra_dir="/${multi_dir}"

+            # If more substitutions are needed then they
+            # should be added here, AArch64 for example?
+            if [ "${extra_flags}" = " -m32" ]; then
+              multi_arch=${native_arch/x86_64/i686}
+            elif [ "${extra_flags}" = " -m64" ]; then
+              multi_arch=${native_arch/i686/x86_64}
+            fi
+
             # glibc install its files in ${extra_dir}/{usr/,}lib
             # while gcc expects them in {,usr/}lib/${extra_dir}.
             # Prepare some symlinks so glibc installs in fact in
@@ -140,36 +162,15 @@

         CT_mkdir_pushd
"${CT_BUILD_DIR}/build-libc-${libc_mode}${extra_dir//\//_}"

-        do_libc_backend_once extra_dir="${extra_dir}"               \
-                             extra_flags="${extra_flags}"           \
-                             libc_headers="${libc_headers}"         \
-                             libc_startfiles="${libc_startfiles}"   \
+        do_libc_backend_once extra_dir="${extra_dir}"
          \
+                             extra_flags="${extra_flags}"
          \
+                             libc_headers="${libc_headers}"
          \
+                             libc_startfiles="${libc_startfiles}"
          \
+
libc_triplet="${multi_arch}${rest_of_triplet}"     \
                              libc_full="${libc_full}"

         CT_Popd

-        if [ "${multi_dir}" != "." ]; then
-            if [ "${libc_mode}" = "final" ]; then
-                CT_DoLog EXTRA "Fixing up multilib location"
-
-                # rewrite the library multiplexers
-                for d in "lib/${multi_dir}" "usr/lib/${multi_dir}"; do
-                    for l in libc libpthread libgcc_s; do
-                        if [    -f "${CT_SYSROOT_DIR}/${d}/${l}.so"    \
-                             -a ! -L ${CT_SYSROOT_DIR}/${d}/${l}.so    ]
-                        then
-                            CT_DoExecLog DEBUG ${sed} -r -i
                      \
-                                                      -e
"s:/lib/:/lib/${multi_dir}/:g;"    \
-
"${CT_SYSROOT_DIR}/${d}/${l}.so"
-                        fi
-                    done
-                done
