diff -Naur crosstool-ng-1.13.0/Makefile.local.mk crosstool-ng-1.13.0-w0/Makefile.local.mk
--- crosstool-ng-1.13.0/Makefile.local.mk	1970-01-01 01:00:00.000000000 +0100
+++ crosstool-ng-1.13.0-w0/Makefile.local.mk	2011-12-13 09:03:51.000000000 +0100
@@ -0,0 +1,26 @@
+all:
+	@echo "do_install    : install ctng in ./build/"
+	@echo "do_menuconfig : run ./build/bin/ctng menuconfig"
+	@echo "do_build      : run ./build/bin/ctng build, STOP and RESTART as options"
+	@echo "do_list_steps : run ./build/bin/ctng do_list_steps"
+
+do_install:
+	mkdir -p $(CURDIR)/build/ctng
+	tar cf - . --exclude ./build | tar -x -C $(CURDIR)/build/ctng
+	cd $(CURDIR)/build/ctng; ./configure --prefix=$(CURDIR)/build; make MAKELEVEL=0; make MAKELEVEL=0 install;
+
+do_menuconfig:
+	mkdir -p $(CURDIR)/build/ctng;
+	export PATH=$(CURDIR)/build/bin:$$PATH;cd $(CURDIR)/build/ctng;$(CURDIR)/build/bin/ct-ng menuconfig
+
+do_build:
+	mkdir -p $(CURDIR)/build/ctng;
+	export PATH=$(CURDIR)/build/bin:$$PATH;cd $(CURDIR)/build/ctng;$(CURDIR)/build/bin/ct-ng build V=2 $(if $(STOP),STOP=$(STOP),) $(if $(RESTART),RESTART=$(RESTART))
+
+do_list_steps:
+	mkdir -p $(CURDIR)/build/ctng;
+	export PATH=$(CURDIR)/build/bin:$$PATH;cd $(CURDIR)/build/ctng;$(CURDIR)/build/bin/ct-ng list-steps 
+
+do_clean:
+	mkdir -p $(CURDIR)/build/ctng;
+	export PATH=$(CURDIR)/build/bin:$$PATH;cd $(CURDIR)/build/ctng;$(CURDIR)/build/bin/ct-ng clean
diff -Naur crosstool-ng-1.13.0/build/ctng/.config crosstool-ng-1.13.0-w0/build/ctng/.config
--- crosstool-ng-1.13.0/build/ctng/.config	1970-01-01 01:00:00.000000000 +0100
+++ crosstool-ng-1.13.0-w0/build/ctng/.config	2011-12-13 09:03:51.000000000 +0100
@@ -0,0 +1,468 @@
+#
+# Automatically generated make config: don't edit
+# crosstool-NG  Configuration
+# Fri Nov 11 14:19:28 2011
+#
+CT_CONFIGURE_has_xzutils=y
+CT_CONFIGURE_has_cvs=y
+CT_CONFIGURE_has_svn=y
+CT_MODULES=y
+
+#
+# Paths and misc options
+#
+
+#
+# crosstool-NG behavior
+#
+# CT_OBSOLETE is not set
+CT_EXPERIMENTAL=y
+CT_DEBUG_CT=y
+# CT_DEBUG_PAUSE_STEPS is not set
+CT_DEBUG_CT_SAVE_STEPS=y
+# CT_DEBUG_CT_SAVE_STEPS_GZIP is not set
+# CT_NO_OVERIDE_LC_MESSAGES is not set
+
+#
+# Paths
+#
+CT_LOCAL_TARBALLS_DIR=""
+CT_WORK_DIR="${CT_TOP_DIR}/.build"
+CT_PREFIX_DIR="/opt/sparc-linux-4.6.0-toolchains/multilib"
+CT_INSTALL_DIR="${CT_PREFIX_DIR}"
+CT_RM_RF_PREFIX_DIR=y
+CT_REMOVE_DOCS=y
+CT_INSTALL_DIR_RO=y
+CT_STRIP_ALL_TOOLCHAIN_EXECUTABLES=y
+
+#
+# Downloading
+#
+# CT_FORBID_DOWNLOAD is not set
+# CT_FORCE_DOWNLOAD is not set
+CT_CONNECT_TIMEOUT=10
+# CT_ONLY_DOWNLOAD is not set
+# CT_USE_MIRROR is not set
+
+#
+# Extracting
+#
+# CT_FORCE_EXTRACT is not set
+CT_OVERIDE_CONFIG_GUESS_SUB=y
+# CT_ONLY_EXTRACT is not set
+CT_PATCH_BUNDLED=y
+# CT_PATCH_LOCAL is not set
+# CT_PATCH_BUNDLED_LOCAL is not set
+# CT_PATCH_LOCAL_BUNDLED is not set
+# CT_PATCH_BUNDLED_FALLBACK_LOCAL is not set
+# CT_PATCH_LOCAL_FALLBACK_BUNDLED is not set
+# CT_PATCH_NONE is not set
+CT_PATCH_ORDER="bundled"
+
+#
+# Build behavior
+#
+CT_PARALLEL_JOBS=0
+CT_LOAD=0
+CT_USE_PIPES=y
+CT_EXTRA_FLAGS_FOR_HOST=""
+# CT_CONFIG_SHELL_SH is not set
+# CT_CONFIG_SHELL_ASH is not set
+CT_CONFIG_SHELL_BASH=y
+# CT_CONFIG_SHELL_CUSTOM is not set
+CT_CONFIG_SHELL="${bash}"
+
+#
+# Logging
+#
+# CT_LOG_ERROR is not set
+# CT_LOG_WARN is not set
+CT_LOG_INFO=y
+# CT_LOG_EXTRA is not set
+# CT_LOG_ALL is not set
+# CT_LOG_DEBUG is not set
+CT_LOG_LEVEL_MAX="INFO"
+# CT_LOG_SEE_TOOLS_WARN is not set
+CT_LOG_PROGRESS_BAR=y
+CT_LOG_TO_FILE=y
+CT_LOG_FILE_COMPRESS=y
+
+#
+# Target options
+#
+CT_ARCH="sparc"
+CT_ARCH_SUPPORTS_32=y
+CT_ARCH_SUPPORTS_64=y
+CT_ARCH_SUPPORT_CPU=y
+CT_ARCH_SUPPORT_TUNE=y
+CT_ARCH_DEFAULT_32=y
+CT_ARCH_CPU=""
+CT_ARCH_TUNE=""
+CT_ARCH_32=y
+# CT_ARCH_64 is not set
+CT_ARCH_BITNESS=32
+CT_ARCH_FLOAT_HW=y
+# CT_ARCH_FLOAT_SW is not set
+CT_TARGET_CFLAGS=""
+CT_TARGET_LDFLAGS=""
+# CT_ARCH_alpha is not set
+# CT_ARCH_arm is not set
+# CT_ARCH_avr32 is not set
+# CT_ARCH_blackfin is not set
+# CT_ARCH_m68k is not set
+# CT_ARCH_mips is not set
+# CT_ARCH_powerpc is not set
+# CT_ARCH_s390 is not set
+# CT_ARCH_sh is not set
+CT_ARCH_sparc=y
+# CT_ARCH_x86 is not set
+CT_ARCH_alpha_AVAILABLE=y
+CT_ARCH_arm_AVAILABLE=y
+CT_ARCH_avr32_AVAILABLE=y
+CT_ARCH_blackfin_AVAILABLE=y
+CT_ARCH_m68k_AVAILABLE=y
+CT_ARCH_mips_AVAILABLE=y
+CT_ARCH_powerpc_AVAILABLE=y
+CT_ARCH_s390_AVAILABLE=y
+CT_ARCH_sh_AVAILABLE=y
+CT_ARCH_sparc_AVAILABLE=y
+CT_ARCH_x86_AVAILABLE=y
+
+#
+# Generic target options
+#
+CT_ARCH_USE_MMU=y
+
+#
+# Target optimisations
+#
+
+#
+# Toolchain options
+#
+
+#
+# General toolchain options
+#
+CT_FORCE_SYSROOT=y
+CT_USE_SYSROOT=y
+CT_SYSROOT_NAME="sysroot"
+CT_SYSROOT_DIR_PREFIX=""
+CT_WANTS_STATIC_LINK=y
+# CT_STATIC_TOOLCHAIN is not set
+CT_TOOLCHAIN_PKGVERSION=""
+CT_TOOLCHAIN_BUGURL=""
+
+#
+# Tuple completion and aliasing
+#
+CT_TARGET_VENDOR="leon3"
+CT_TARGET_ALIAS_SED_EXPR=""
+CT_TARGET_ALIAS=""
+
+#
+# Toolchain type
+#
+# CT_NATIVE is not set
+CT_CROSS=y
+# CT_CROSS_NATIVE is not set
+# CT_CANADIAN is not set
+CT_TOOLCHAIN_TYPE="cross"
+
+#
+# Build system
+#
+CT_BUILD=""
+CT_BUILD_PREFIX=""
+CT_BUILD_SUFFIX=""
+
+#
+# Operating System
+#
+CT_KERNEL_SUPPORTS_SHARED_LIBS=y
+CT_KERNEL="linux"
+CT_KERNEL_VERSION="3.0.4"
+# CT_KERNEL_bare_metal is not set
+CT_KERNEL_linux=y
+CT_KERNEL_bare_metal_AVAILABLE=y
+CT_KERNEL_linux_AVAILABLE=y
+CT_KERNEL_V_3_0_4=y
+# CT_KERNEL_V_3_0_3 is not set
+# CT_KERNEL_V_3_0_2 is not set
+# CT_KERNEL_V_3_0_1 is not set
+# CT_KERNEL_V_3_0 is not set
+# CT_KERNEL_V_2_6_39_4 is not set
+# CT_KERNEL_V_2_6_38_8 is not set
+# CT_KERNEL_V_2_6_37_6 is not set
+# CT_KERNEL_V_2_6_36_4 is not set
+# CT_KERNEL_V_2_6_35_14 is not set
+# CT_KERNEL_V_2_6_34_10 is not set
+# CT_KERNEL_V_2_6_33_19 is not set
+# CT_KERNEL_V_2_6_32_46 is not set
+# CT_KERNEL_V_2_6_31_14 is not set
+# CT_KERNEL_V_2_6_27_59 is not set
+# CT_KERNEL_LINUX_CUSTOM is not set
+CT_KERNEL_mingw32_AVAILABLE=y
+
+#
+# Common kernel options
+#
+CT_SHARED_LIBS=y
+
+#
+# linux other options
+#
+CT_KERNEL_LINUX_VERBOSITY_0=y
+# CT_KERNEL_LINUX_VERBOSITY_1 is not set
+# CT_KERNEL_LINUX_VERBOSITY_2 is not set
+CT_KERNEL_LINUX_VERBOSE_LEVEL=0
+CT_KERNEL_LINUX_INSTALL_CHECK=y
+
+#
+# Binary utilities
+#
+CT_ARCH_BINFMT_ELF=y
+
+#
+# GNU binutils
+#
+# CT_BINUTILS_V_2_21_53 is not set
+CT_BINUTILS_V_2_21_1a=y
+# CT_BINUTILS_V_2_20_1a is not set
+# CT_BINUTILS_V_2_19_1a is not set
+# CT_BINUTILS_V_2_18a is not set
+CT_BINUTILS_VERSION="2.21.1a"
+CT_BINUTILS_2_21_or_later=y
+CT_BINUTILS_2_20_or_later=y
+CT_BINUTILS_2_19_or_later=y
+CT_BINUTILS_2_18_or_later=y
+CT_BINUTILS_HAS_GOLD=y
+CT_BINUTILS_HAS_PLUGINS=y
+CT_BINUTILS_HAS_PKGVERSION_BUGURL=y
+CT_BINUTILS_FORCE_LD_BFD=y
+CT_BINUTILS_LINKER_LD=y
+CT_BINUTILS_LINKERS_LIST="ld"
+CT_BINUTILS_LINKER_DEFAULT="bfd"
+# CT_BINUTILS_PLUGINS is not set
+CT_BINUTILS_EXTRA_CONFIG_ARRAY=""
+# CT_BINUTILS_FOR_TARGET is not set
+
+#
+# C compiler
+#
+CT_CC="gcc"
+CT_CC_VERSION="4.6.0"
+CT_CC_gcc=y
+# CT_CC_GCC_SHOW_LINARO is not set
+# CT_CC_V_4_6_1 is not set
+CT_CC_V_4_6_0=y
+# CT_CC_V_4_5_3 is not set
+# CT_CC_V_4_5_2 is not set
+# CT_CC_V_4_5_1 is not set
+# CT_CC_V_4_5_0 is not set
+# CT_CC_V_4_4_6 is not set
+# CT_CC_V_4_4_5 is not set
+# CT_CC_V_4_4_4 is not set
+# CT_CC_V_4_4_3 is not set
+# CT_CC_V_4_4_2 is not set
+# CT_CC_V_4_4_1 is not set
+# CT_CC_V_4_4_0 is not set
+# CT_CC_V_4_3_6 is not set
+# CT_CC_V_4_3_5 is not set
+# CT_CC_V_4_3_4 is not set
+# CT_CC_V_4_3_3 is not set
+# CT_CC_V_4_3_2 is not set
+# CT_CC_V_4_3_1 is not set
+# CT_CC_V_4_2_4 is not set
+# CT_CC_V_4_2_2 is not set
+CT_CC_GCC_4_2_or_later=y
+CT_CC_GCC_4_3_or_later=y
+CT_CC_GCC_4_4_or_later=y
+CT_CC_GCC_4_5_or_later=y
+CT_CC_GCC_4_6=y
+CT_CC_GCC_4_6_or_later=y
+CT_CC_GCC_HAS_GRAPHITE=y
+CT_CC_GCC_HAS_LTO=y
+CT_CC_GCC_HAS_PKGVERSION_BUGURL=y
+CT_CC_GCC_HAS_BUILD_ID=y
+CT_CC_GCC_USE_GMP_MPFR=y
+CT_CC_GCC_USE_PPL_CLOOG=y
+CT_CC_GCC_USE_MPC=y
+# CT_CC_LANG_FORTRAN is not set
+CT_CC_SUPPORT_CXX=y
+CT_CC_SUPPORT_FORTRAN=y
+CT_CC_SUPPORT_JAVA=y
+CT_CC_SUPPORT_ADA=y
+CT_CC_SUPPORT_OBJC=y
+CT_CC_SUPPORT_OBJCXX=y
+
+#
+# Additional supported languages:
+#
+# CT_CC_LANG_CXX is not set
+# CT_CC_LANG_JAVA is not set
+# CT_CC_LANG_ADA is not set
+# CT_CC_LANG_OBJC is not set
+# CT_CC_LANG_OBJCXX is not set
+CT_CC_LANG_OTHERS=""
+
+#
+# gcc other options
+#
+CT_CC_MULTILIB=y
+CT_CC_ENABLE_CXX_FLAGS=""
+CT_CC_CORE_EXTRA_CONFIG_ARRAY=""
+CT_CC_EXTRA_CONFIG_ARRAY=""
+CT_CC_STATIC_LIBSTDCXX=y
+
+#
+# Optimisation features
+#
+CT_CC_GCC_USE_GRAPHITE=y
+CT_CC_GCC_USE_LTO=y
+
+#
+# Settings for libraries running on target
+#
+CT_CC_GCC_ENABLE_TARGET_OPTSPACE=y
+# CT_CC_GCC_LIBMUDFLAP is not set
+# CT_CC_GCC_LIBGOMP is not set
+# CT_CC_GCC_LIBSSP is not set
+
+#
+# Misc. obscure options.
+#
+CT_CC_CXA_ATEXIT=y
+# CT_CC_GCC_DISABLE_PCH is not set
+CT_CC_GCC_SJLJ_EXCEPTIONS=m
+CT_CC_GCC_LDBL_128=m
+# CT_CC_GCC_BUILD_ID is not set
+
+#
+# C-library
+#
+CT_LIBC="glibc"
+CT_LIBC_VERSION="2.14"
+# CT_LIBC_eglibc is not set
+CT_LIBC_glibc=y
+# CT_LIBC_uClibc is not set
+CT_LIBC_eglibc_AVAILABLE=y
+CT_LIBC_glibc_AVAILABLE=y
+CT_LIBC_GLIBC_TARBALL=y
+CT_LIBC_GLIBC_V_2_14=y
+# CT_LIBC_GLIBC_V_2_13 is not set
+# CT_LIBC_GLIBC_V_2_12_2 is not set
+# CT_LIBC_GLIBC_V_2_12_1 is not set
+# CT_LIBC_GLIBC_V_2_11_1 is not set
+# CT_LIBC_GLIBC_V_2_11 is not set
+# CT_LIBC_GLIBC_V_2_10_1 is not set
+# CT_LIBC_GLIBC_V_2_9 is not set
+# CT_LIBC_GLIBC_V_2_8 is not set
+CT_LIBC_mingw_AVAILABLE=y
+CT_LIBC_newlib_AVAILABLE=y
+CT_LIBC_none_AVAILABLE=y
+CT_LIBC_uClibc_AVAILABLE=y
+CT_LIBC_SUPPORT_THREADS_ANY=y
+CT_LIBC_SUPPORT_NPTL=y
+CT_THREADS="nptl"
+
+#
+# Common C library options
+#
+CT_THREADS_NPTL=y
+CT_LIBC_XLDD=y
+CT_LIBC_glibc_familly=y
+CT_LIBC_GLIBC_EXTRA_CONFIG_ARRAY=""
+CT_LIBC_GLIBC_CONFIGPARMS=""
+CT_LIBC_GLIBC_EXTRA_CFLAGS="-g -U_FORTIFY_SOURCE"
+CT_LIBC_EXTRA_CC_ARGS=""
+# CT_LIBC_ENABLE_FORTIFIED_BUILD is not set
+# CT_LIBC_DISABLE_VERSIONING is not set
+CT_LIBC_OLDEST_ABI=""
+CT_LIBC_GLIBC_FORCE_UNWIND=y
+# CT_LIBC_GLIBC_USE_PORTS is not set
+CT_LIBC_ADDONS_LIST=""
+# CT_LIBC_LOCALES is not set
+# CT_LIBC_GLIBC_KERNEL_VERSION_NONE is not set
+CT_LIBC_GLIBC_KERNEL_VERSION_AS_HEADERS=y
+# CT_LIBC_GLIBC_KERNEL_VERSION_CHOSEN is not set
+CT_LIBC_GLIBC_MIN_KERNEL="3.0.4"
+
+#
+# glibc other options
+#
+
+#
+# Debug facilities
+#
+# CT_DEBUG_dmalloc is not set
+# CT_DEBUG_duma is not set
+# CT_DEBUG_gdb is not set
+# CT_DEBUG_ltrace is not set
+# CT_DEBUG_strace is not set
+
+#
+# Companion libraries
+#
+CT_COMPLIBS_NEEDED=y
+CT_GMP_NEEDED=y
+CT_MPFR_NEEDED=y
+CT_PPL_NEEDED=y
+CT_CLOOG_NEEDED=y
+CT_MPC_NEEDED=y
+CT_COMPLIBS=y
+CT_GMP=y
+CT_MPFR=y
+CT_PPL=y
+CT_CLOOG=y
+CT_MPC=y
+CT_GMP_V_5_0_2=y
+# CT_GMP_V_5_0_1 is not set
+# CT_GMP_V_4_3_2 is not set
+# CT_GMP_V_4_3_1 is not set
+# CT_GMP_V_4_3_0 is not set
+CT_GMP_VERSION="5.0.2"
+CT_MPFR_V_3_0_1=y
+# CT_MPFR_V_3_0_0 is not set
+# CT_MPFR_V_2_4_2 is not set
+# CT_MPFR_V_2_4_1 is not set
+# CT_MPFR_V_2_4_0 is not set
+CT_MPFR_VERSION="3.0.1"
+CT_PPL_V_0_11_2=y
+# CT_PPL_V_0_11_1 is not set
+# CT_PPL_V_0_11 is not set
+# CT_PPL_V_0_10_2 is not set
+CT_PPL_VERSION="0.11.2"
+CT_PPL_0_11=y
+CT_PPL_NEEDS_LIBPWL=y
+CT_CLOOG_V_0_15_11=y
+# CT_CLOOG_V_0_15_10 is not set
+# CT_CLOOG_V_0_15_9 is not set
+# CT_CLOOG_V_0_15_8 is not set
+# CT_CLOOG_V_0_15_7 is not set
+# CT_CLOOG_V_0_15_6 is not set
+CT_CLOOG_VERSION="0.15.11"
+CT_MPC_V_0_9=y
+# CT_MPC_V_0_8_2 is not set
+# CT_MPC_V_0_8_1 is not set
+# CT_MPC_V_0_7 is not set
+CT_MPC_VERSION="0.9"
+
+#
+# Companion libraries common options
+#
+# CT_COMPLIBS_CHECK is not set
+
+#
+# Companion tools
+#
+
+#
+# READ HELP before you say 'Y' below !!!
+#
+# CT_COMP_TOOLS is not set
+
+#
+# Test suite
+#
+# CT_TEST_SUITE_GCC is not set
diff -Naur crosstool-ng-1.13.0/config/cc/gcc.in.2 crosstool-ng-1.13.0-w0/config/cc/gcc.in.2
--- crosstool-ng-1.13.0/config/cc/gcc.in.2	2011-10-24 22:06:36.000000000 +0200
+++ crosstool-ng-1.13.0-w0/config/cc/gcc.in.2	2011-12-13 09:03:51.000000000 +0100
@@ -1,4 +1,10 @@
 # gcc configuration options
+config CC_MULTILIB
+    bool
+    prompt "enable multilib"
+    default n
+    help
+      Enable multilib build of libc
 
 config CC_ENABLE_CXX_FLAGS
     string
@@ -11,6 +17,7 @@
       Note: just pass in the option _value_, that is only the part that goes
       after the '=' sign.
 
+      
 config CC_CORE_EXTRA_CONFIG_ARRAY
     string
     prompt "Core gcc extra config"
diff -Naur crosstool-ng-1.13.0/patches/binutils/2.21.1a/400-sparc-leon.patch crosstool-ng-1.13.0-w0/patches/binutils/2.21.1a/400-sparc-leon.patch
--- crosstool-ng-1.13.0/patches/binutils/2.21.1a/400-sparc-leon.patch	1970-01-01 01:00:00.000000000 +0100
+++ crosstool-ng-1.13.0-w0/patches/binutils/2.21.1a/400-sparc-leon.patch	2011-12-13 09:03:51.000000000 +0100
@@ -0,0 +1,107 @@
+diff -Naur binutils-2.21.1.ori/gas/config/tc-sparc.c binutils-2.21.1/gas/config/tc-sparc.c
+--- binutils-2.21.1.ori/gas/config/tc-sparc.c	2011-11-10 11:55:35.000000000 +0100
++++ binutils-2.21.1/gas/config/tc-sparc.c	2011-11-10 12:00:24.000000000 +0100
+@@ -212,7 +212,7 @@
+    for this use.  That table is for opcodes only.  This table is for opcodes
+    and file formats.  */
+ 
+-enum sparc_arch_types {v6, v7, v8, sparclet, sparclite, sparc86x, v8plus,
++enum sparc_arch_types {v6, v7, v8, leon, sparclet, sparclite, sparc86x, v8plus,
+ 		       v8plusa, v9, v9a, v9b, v9_64};
+ 
+ static struct sparc_arch {
+@@ -228,6 +228,7 @@
+   { "v6", "v6", v6, 0, 1 },
+   { "v7", "v7", v7, 0, 1 },
+   { "v8", "v8", v8, 32, 1 },
++  { "leon", "leon", leon, 32, 1 },
+   { "sparclet", "sparclet", sparclet, 32, 1 },
+   { "sparclite", "sparclite", sparclite, 32, 1 },
+   { "sparc86x", "sparclite", sparc86x, 32, 1 },
+diff -Naur binutils-2.21.1.ori/gas/configure.tgt binutils-2.21.1/gas/configure.tgt
+--- binutils-2.21.1.ori/gas/configure.tgt	2011-11-10 11:55:34.000000000 +0100
++++ binutils-2.21.1/gas/configure.tgt	2011-11-10 12:01:43.000000000 +0100
+@@ -80,6 +80,11 @@
+   sparclet*)		cpu_type=sparc arch=sparclet ;;
+   sparclite*)		cpu_type=sparc arch=sparclite ;;
+   sparc*)		cpu_type=sparc arch=sparclite ;; # ??? See tc-sparc.c.
++  sparc*)
++     case ${vendor} in
++         *leon*)        cpu_type=sparc arch=leon ;;
++         *)             cpu_type=sparc arch=sparclite ;; # ??? See tc-sparc.c.
++     esac ;;
+   strongarm*be)		cpu_type=arm endian=big ;;
+   strongarm*b)		cpu_type=arm endian=big ;;
+   strongarm*)		cpu_type=arm endian=little ;;
+diff -Naur binutils-2.21.1.ori/include/opcode/sparc.h binutils-2.21.1/include/opcode/sparc.h
+--- binutils-2.21.1.ori/include/opcode/sparc.h	2011-11-10 11:55:35.000000000 +0100
++++ binutils-2.21.1/include/opcode/sparc.h	2011-11-10 11:56:05.000000000 +0100
+@@ -42,6 +42,7 @@
+   SPARC_OPCODE_ARCH_V6 = 0,
+   SPARC_OPCODE_ARCH_V7,
+   SPARC_OPCODE_ARCH_V8,
++  SPARC_OPCODE_ARCH_LEON,
+   SPARC_OPCODE_ARCH_SPARCLET,
+   SPARC_OPCODE_ARCH_SPARCLITE,
+   /* V9 variants must appear last.  */
+diff -Naur binutils-2.21.1.ori/opcodes/sparc-opc.c binutils-2.21.1/opcodes/sparc-opc.c
+--- binutils-2.21.1.ori/opcodes/sparc-opc.c	2011-11-10 11:55:36.000000000 +0100
++++ binutils-2.21.1/opcodes/sparc-opc.c	2011-11-10 11:56:05.000000000 +0100
+@@ -33,6 +33,7 @@
+ #define MASK_V6		SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V6)
+ #define MASK_V7		SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V7)
+ #define MASK_V8		SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V8)
++#define MASK_LEON	SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_LEON)
+ #define MASK_SPARCLET	SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_SPARCLET)
+ #define MASK_SPARCLITE	SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_SPARCLITE)
+ #define MASK_V9		SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V9)
+@@ -56,6 +57,7 @@
+    recognizes all v8 insns.  */
+ #define v8		(MASK_V8 | MASK_SPARCLET | MASK_SPARCLITE \
+ 			 | MASK_V9 | MASK_V9A | MASK_V9B)
++#define leon		(MASK_LEON)
+ #define sparclet	(MASK_SPARCLET)
+ #define sparclite	(MASK_SPARCLITE)
+ #define v9		(MASK_V9 | MASK_V9A | MASK_V9B)
+@@ -76,6 +78,7 @@
+   { "v6", MASK_V6 },
+   { "v7", MASK_V6 | MASK_V7 },
+   { "v8", MASK_V6 | MASK_V7 | MASK_V8 },
++  { "leon", MASK_V6 | MASK_V7 | MASK_V8 | MASK_LEON },
+   { "sparclet", MASK_V6 | MASK_V7 | MASK_V8 | MASK_SPARCLET },
+   { "sparclite", MASK_V6 | MASK_V7 | MASK_V8 | MASK_SPARCLITE },
+   /* ??? Don't some v8 priviledged insns conflict with v9?  */
+@@ -1640,9 +1643,8 @@
+ { "cpop2",	F3(2, 0x37, 0), F3(~2, ~0x37, ~1), "[1+2],d", F_ALIAS, v6notv9 },
+ 
+ /* sparclet specific insns */
+-
+-COMMUTEOP ("umac", 0x3e, sparclet),
+-COMMUTEOP ("smac", 0x3f, sparclet),
++COMMUTEOP ("umac", 0x3e, sparclet|MASK_LEON),
++COMMUTEOP ("smac", 0x3f, sparclet|MASK_LEON),
+ COMMUTEOP ("umacd", 0x2e, sparclet),
+ COMMUTEOP ("smacd", 0x2f, sparclet),
+ COMMUTEOP ("umuld", 0x09, sparclet),
+@@ -1693,8 +1695,8 @@
+ #undef SLCBCC2
+ #undef SLCBCC
+ 
+-{ "casa",	F3(3, 0x3c, 0), F3(~3, ~0x3c, ~0), "[1]A,2,d", 0, v9 },
+-{ "casa",	F3(3, 0x3c, 1), F3(~3, ~0x3c, ~1), "[1]o,2,d", 0, v9 },
++{ "casa",	F3(3, 0x3c, 0), F3(~3, ~0x3c, ~0), "[1]A,2,d", 0, v9|MASK_LEON },
++{ "casa",	F3(3, 0x3c, 1), F3(~3, ~0x3c, ~1), "[1]o,2,d", 0, v9|MASK_LEON },
+ { "casxa",	F3(3, 0x3e, 0), F3(~3, ~0x3e, ~0), "[1]A,2,d", 0, v9 },
+ { "casxa",	F3(3, 0x3e, 1), F3(~3, ~0x3e, ~1), "[1]o,2,d", 0, v9 },
+ 
+@@ -1704,8 +1706,8 @@
+ { "signx",	F3(2, 0x27, 0), F3(~2, ~0x27, ~0)|(1<<12)|ASI(~0)|RS2_G0, "r", F_ALIAS, v9 }, /* sra rd,%g0,rd */
+ { "clruw",	F3(2, 0x26, 0), F3(~2, ~0x26, ~0)|(1<<12)|ASI(~0)|RS2_G0, "1,d", F_ALIAS, v9 }, /* srl rs1,%g0,rd */
+ { "clruw",	F3(2, 0x26, 0), F3(~2, ~0x26, ~0)|(1<<12)|ASI(~0)|RS2_G0, "r", F_ALIAS, v9 }, /* srl rd,%g0,rd */
+-{ "cas",	F3(3, 0x3c, 0)|ASI(0x80), F3(~3, ~0x3c, ~0)|ASI(~0x80), "[1],2,d", F_ALIAS, v9 }, /* casa [rs1]ASI_P,rs2,rd */
+-{ "casl",	F3(3, 0x3c, 0)|ASI(0x88), F3(~3, ~0x3c, ~0)|ASI(~0x88), "[1],2,d", F_ALIAS, v9 }, /* casa [rs1]ASI_P_L,rs2,rd */
++{ "cas",	F3(3, 0x3c, 0)|ASI(0x80), F3(~3, ~0x3c, ~0)|ASI(~0x80), "[1],2,d", F_ALIAS, v9|MASK_LEON }, /* casa [rs1]ASI_P,rs2,rd */
++{ "casl",	F3(3, 0x3c, 0)|ASI(0x88), F3(~3, ~0x3c, ~0)|ASI(~0x88), "[1],2,d", F_ALIAS, v9|MASK_LEON }, /* casa [rs1]ASI_P_L,rs2,rd */
+ { "casx",	F3(3, 0x3e, 0)|ASI(0x80), F3(~3, ~0x3e, ~0)|ASI(~0x80), "[1],2,d", F_ALIAS, v9 }, /* casxa [rs1]ASI_P,rs2,rd */
+ { "casxl",	F3(3, 0x3e, 0)|ASI(0x88), F3(~3, ~0x3e, ~0)|ASI(~0x88), "[1],2,d", F_ALIAS, v9 }, /* casxa [rs1]ASI_P_L,rs2,rd */
+ 
diff -Naur crosstool-ng-1.13.0/patches/gcc/4.6.0/200-sparc-leon.patch crosstool-ng-1.13.0-w0/patches/gcc/4.6.0/200-sparc-leon.patch
--- crosstool-ng-1.13.0/patches/gcc/4.6.0/200-sparc-leon.patch	1970-01-01 01:00:00.000000000 +0100
+++ crosstool-ng-1.13.0-w0/patches/gcc/4.6.0/200-sparc-leon.patch	2011-12-13 09:03:51.000000000 +0100
@@ -0,0 +1,423 @@
+diff --git a/gcc/config.gcc b/gcc/config.gcc
+index 39d9a19..6808f12 100644
+--- a/gcc/config.gcc
++++ b/gcc/config.gcc
+@@ -2524,12 +2524,13 @@ sh-wrs-vxworks)
+ 	;;
+ sparc-*-elf*)
+ 	tm_file="${tm_file} dbxelf.h elfos.h newlib-stdint.h sparc/sysv4.h sparc/sp-elf.h"
+-	case ${target} in
++	leonver=`echo ${target} | sed -e "s/sparc-//" | sed -e 's/-.*$//' | sed -e 's/leon[3-9]/leon3/' `
++      	case ${target} in
+ 	    *-leon-*)
+-		tmake_file="sparc/t-leon"
++		tmake_file="sparc/t-${leonver}"
+ 		;;
+-	    *-leon[3-9]*)
+-		tmake_file="sparc/t-leon3"
++	    *-leon[3-9]*|*-sfleon*|*-hfleon*)
++		tmake_file="sparc/t-${leonver}"
+ 		;;
+ 	    *)
+ 		tmake_file="sparc/t-elf"
+@@ -2546,12 +2547,13 @@ sparc-*-rtems*)
+ sparc-*-linux*)
+ 	tm_file="${tm_file} dbxelf.h elfos.h sparc/sysv4.h gnu-user.h linux.h glibc-stdint.h"
+ 	extra_options="${extra_options} sparc/long-double-switch.opt"
++	leonver=`echo ${target} | sed -e "s/sparc-//" | sed -e 's/-.*$//' | sed -e 's/leon[3-9]/leon3/' `
+ 	case ${target} in
+ 	    *-leon-*)
+-		tmake_file="${tmake_file} sparc/t-leon"
++		tmake_file="${tmake_file} sparc/t-${leonver}"
+ 		;;
+-	    *-leon[3-9]*)
+-		tmake_file="${tmake_file} sparc/t-leon3"
++	    *-leon[3-9]*|*-sfleon*|*-hfleon*)
++		tmake_file="${tmake_file} sparc/t-${leonver}"
+ 		;;
+ 	    *)
+ 		tmake_file="${tmake_file} sparc/t-linux"
+@@ -3043,8 +3045,13 @@ if test x$with_cpu = x ; then
+     mips*-*-vxworks)
+       with_arch=mips2
+       ;;
+-    sparc-leon*-*)
+-      with_cpu=v8;
++    sparc-sfleon*-*|sparc-hfleon*-*)
++      leonver=`echo ${target} | sed -e "s/sparc-//" | sed -e 's/-.*$//' | sed -e 's/leon[3-9]/leon/' `
++      with_cpu="${leonver}";
++      ;;
++    sparc-*leon*-*)
++      leonver=`echo ${target} | sed -e "s/sparc-//" | sed -e 's/-.*$//' | sed -e 's/leon[3-9]/leon/' `
++      with_cpu="${leonver}";
+       ;;
+     sparc*-*-*)
+       with_cpu="`echo ${target} | sed 's/-.*$//'`"
+@@ -3567,7 +3574,7 @@ case "${target}" in
+ 			case ${val} in
+ 			"" | sparc | sparcv9 | sparc64 \
+ 			| v7 | cypress \
+-			| v8 | supersparc | hypersparc | leon \
++			| v8 | supersparc | hypersparc | *leon* \
+ 			| sparclite | f930 | f934 | sparclite86x \
+ 			| sparclet | tsc701 \
+ 			| v9 | ultrasparc | ultrasparc3 | niagara | niagara2)
+@@ -3713,9 +3720,10 @@ case ${target} in
+ 		cxx_target_objs="${cxx_target_objs} sh-c.o"
+ 		;;
+ 
+-	sparc-leon*-*)
++	sparc-*leon*-*)
++		leonver=`echo ${target} | sed -e "s/sparc-//" | sed -e 's/-.*$//' | sed -e 's/leon[3-9]/leon/' `
+ 		if test x$with_tune = x ; then
+-		  with_tune=leon;
++		  with_tune="${leonver}";
+ 		fi
+ 
+ 		# The SPARC port checks this value at compile-time.
+diff --git a/gcc/config/sparc/sparc.c b/gcc/config/sparc/sparc.c
+index 1c2ba93..5aadff6 100644
+--- a/gcc/config/sparc/sparc.c
++++ b/gcc/config/sparc/sparc.c
+@@ -497,7 +497,9 @@ enum processor_type sparc_cpu;
+ 
+ /* Whetheran FPU option was specified.  */
+ static bool fpu_option_set = false;
+-
++/* Weather -mv8 was specified. */
++static bool mv8_option_set = false;
++   
+ /* Implement TARGET_OPTION_OPTIMIZATION_TABLE.  */
+ static const struct default_options sparc_option_optimization_table[] =
+   {
+@@ -690,6 +692,10 @@ sparc_handle_option (size_t code, const char *arg, int value ATTRIBUTE_UNUSED)
+       fpu_option_set = true;
+       break;
+ 
++    case OPT_mv8:
++      mv8_option_set = true;
++      break;
++
+     case OPT_mcpu_:
+       sparc_select[1].string = arg;
+       break;
+@@ -739,6 +745,10 @@ sparc_option_override (void)
+     { TARGET_CPU_ultrasparc3, "ultrasparc3" },
+     { TARGET_CPU_niagara, "niagara" },
+     { TARGET_CPU_niagara2, "niagara2" },
++    { TARGET_CPU_sparchfleon, "hfleon" },
++    { TARGET_CPU_sparchfleonv8, "hfleonv8" },
++    { TARGET_CPU_sparcsfleon, "sfleon" },
++    { TARGET_CPU_sparcsfleonv8, "sfleonv8" },
+     { 0, 0 }
+   };
+   const struct cpu_default *def;
+@@ -756,8 +766,12 @@ sparc_option_override (void)
+     { "supersparc", PROCESSOR_SUPERSPARC, MASK_ISA, MASK_V8 },
+     { "hypersparc", PROCESSOR_HYPERSPARC, MASK_ISA, MASK_V8|MASK_FPU },
+     /* LEON */
+-    { "leon",       PROCESSOR_LEON, MASK_ISA, MASK_V8|MASK_FPU },
++    { "leon",       PROCESSOR_LEON, MASK_ISA, MASK_FPU },
+     { "sparclite",  PROCESSOR_SPARCLITE, MASK_ISA, MASK_SPARCLITE },
++    { "hfleon",   PROCESSOR_LEON, MASK_ISA, MASK_FPU },
++    { "hfleonv8", PROCESSOR_LEON, MASK_ISA & ~(MASK_V8), MASK_V8|MASK_FPU },
++    { "sfleon",   PROCESSOR_LEON, MASK_ISA | MASK_FPU, 0 },
++    { "sfleonv8", PROCESSOR_LEON, (MASK_ISA | MASK_FPU) & ~(MASK_V8), MASK_V8 },
+     /* The Fujitsu MB86930 is the original sparclite chip, with no FPU.  */
+     { "f930",       PROCESSOR_F930, MASK_ISA|MASK_FPU, MASK_SPARCLITE },
+     /* The Fujitsu MB86934 is the recent sparclite chip, with an FPU.  */
+@@ -865,7 +879,9 @@ sparc_option_override (void)
+      the processor default.  */
+   if (fpu_option_set)
+     target_flags = (target_flags & ~MASK_FPU) | fpu;
+-
++  if (mv8_option_set)
++    target_flags |= MASK_V8;
++  
+   /* Don't allow -mvis if FPU is disabled.  */
+   if (! TARGET_FPU)
+     target_flags &= ~MASK_VIS;
+diff --git a/gcc/config/sparc/sparc.h b/gcc/config/sparc/sparc.h
+index 297844f..5e28646 100644
+--- a/gcc/config/sparc/sparc.h
++++ b/gcc/config/sparc/sparc.h
+@@ -247,6 +247,10 @@ extern enum cmodel sparc_cmodel;
+ #define TARGET_CPU_ultrasparc3	10
+ #define TARGET_CPU_niagara	11
+ #define TARGET_CPU_niagara2	12
++#define TARGET_CPU_sparchfleon  13
++#define TARGET_CPU_sparchfleonv8 14
++#define TARGET_CPU_sparcsfleon  15
++#define TARGET_CPU_sparcsfleonv8 16
+ 
+ #if TARGET_CPU_DEFAULT == TARGET_CPU_v9 \
+  || TARGET_CPU_DEFAULT == TARGET_CPU_ultrasparc \
+@@ -319,10 +323,31 @@ extern enum cmodel sparc_cmodel;
+ #endif
+ 
+ #if TARGET_CPU_DEFAULT == TARGET_CPU_leon
+-#define CPP_CPU32_DEFAULT_SPEC "-D__leon__ -D__sparc_v8__"
+-#define ASM_CPU32_DEFAULT_SPEC ""
++#define CPP_CPU32_DEFAULT_SPEC "-D__leon__ "
++#define ASM_CPU32_DEFAULT_SPEC "-Aleon"
++#endif
++
++#if TARGET_CPU_DEFAULT == TARGET_CPU_sparchfleon
++#define CPP_CPU32_DEFAULT_SPEC "-D__leon__ "
++#define ASM_CPU32_DEFAULT_SPEC "-Aleon"
++#endif
++
++#if TARGET_CPU_DEFAULT == TARGET_CPU_sparcsfleon
++#define CPP_CPU32_DEFAULT_SPEC "-D__leon__ -D_SOFT_FLOAT"
++#define ASM_CPU32_DEFAULT_SPEC "-Aleon"
+ #endif
+ 
++#if TARGET_CPU_DEFAULT == TARGET_CPU_sparchfleonv8
++#define CPP_CPU32_DEFAULT_SPEC "-D__leon__ -D__sparc_v8__ "
++#define ASM_CPU32_DEFAULT_SPEC "-Aleon"
++#endif
++
++#if TARGET_CPU_DEFAULT == TARGET_CPU_sparcsfleonv8
++#define CPP_CPU32_DEFAULT_SPEC "-D__leon__ -D__sparc_v8__ -D_SOFT_FLOAT"
++#define ASM_CPU32_DEFAULT_SPEC "-Aleon"
++#endif
++
++
+ #endif
+ 
+ #if !defined(CPP_CPU32_DEFAULT_SPEC) || !defined(CPP_CPU64_DEFAULT_SPEC)
+@@ -368,12 +393,16 @@ extern enum cmodel sparc_cmodel;
+ %{mcpu=v8:-D__sparc_v8__} \
+ %{mcpu=supersparc:-D__supersparc__ -D__sparc_v8__} \
+ %{mcpu=hypersparc:-D__hypersparc__ -D__sparc_v8__} \
+-%{mcpu=leon:-D__leon__ -D__sparc_v8__} \
++%{mcpu=leon:-D__leon__ } \
+ %{mcpu=v9:-D__sparc_v9__} \
+ %{mcpu=ultrasparc:-D__sparc_v9__} \
+ %{mcpu=ultrasparc3:-D__sparc_v9__} \
+ %{mcpu=niagara:-D__sparc_v9__} \
+ %{mcpu=niagara2:-D__sparc_v9__} \
++%{mcpu=hfleon:-D__leon__} \
++%{mcpu=hfleonv8:-D__leon__ -D__sparc_v8__} \
++%{mcpu=sfleon:-D__leon__ -D_SOFT_FLOAT} \
++%{mcpu=sfleonv8:-D__leon__ -D_SOFT_FLOAT -D__sparc_v8__} \
+ %{!mcpu*:%(cpp_cpu_default)} \
+ "
+ #define CPP_ARCH32_SPEC ""
+@@ -409,6 +438,11 @@ extern enum cmodel sparc_cmodel;
+ %{mcpu=sparclite86x:-Asparclite} \
+ %{mcpu=f930:-Asparclite} %{mcpu=f934:-Asparclite} \
+ %{mv8plus:-Av8plus} \
++%{mcpu=leon:-Aleon} \
++%{mcpu=hfleon:-Aleon} \
++%{mcpu=hfleonv8:-Aleon} \
++%{mcpu=sfleon:-Aleon} \
++%{mcpu=sfleonv8:-Aleon} \
+ %{mcpu=v9:-Av9} \
+ %{mcpu=ultrasparc:%{!mv8plus:-Av9a}} \
+ %{mcpu=ultrasparc3:%{!mv8plus:-Av9b}} \
+diff --git a/gcc/config/sparc/sparc.opt b/gcc/config/sparc/sparc.opt
+index a97cad1..68afe28 100644
+--- a/gcc/config/sparc/sparc.opt
++++ b/gcc/config/sparc/sparc.opt
+@@ -115,8 +115,9 @@ Mask(SPARCLITE)
+ Mask(SPARCLET)
+ ;; Generate code for SPARClet
+ 
+-Mask(V8)
+-;; Generate code for SPARC-V8
++mv8
++Target Report Mask(V8)
++Generate code for SPARC-V8, use hardware smul/sdiv
+ 
+ Mask(V9)
+ ;; Generate code for SPARC-V9
+diff --git a/gcc/config/sparc/t-hfleon b/gcc/config/sparc/t-hfleon
+new file mode 100644
+index 0000000..192a502
+--- /dev/null
++++ b/gcc/config/sparc/t-hfleon
+@@ -0,0 +1,37 @@
++# Copyright (C) 2010 Free Software Foundation, Inc.
++#
++# This file is part of GCC.
++#
++# GCC is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3, or (at your option)
++# any later version.
++#
++# GCC is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with GCC; see the file COPYING3.  If not see
++# <http://www.gnu.org/licenses/>.
++
++# We want fine grained libraries, so use the new code to build the
++# floating point emulation libraries.
++FPBIT = fp-bit.c
++DPBIT = dp-bit.c
++
++dp-bit.c: $(srcdir)/config/fp-bit.c
++	cat $(srcdir)/config/fp-bit.c > dp-bit.c
++
++fp-bit.c: $(srcdir)/config/fp-bit.c
++	echo '#define FLOAT' > fp-bit.c
++	cat $(srcdir)/config/fp-bit.c >> fp-bit.c
++
++# Multilibs for LEON3
++#MULTILIB_OPTIONS = msoft-float
++#MULTILIB_DIRNAMES = soft
++#MULTILIB_MATCHES = msoft-float=mno-fpu
++
++LIBGCC = stmp-multilib
++INSTALL_LIBGCC = install-multilib
+diff --git a/gcc/config/sparc/t-hfleonv8 b/gcc/config/sparc/t-hfleonv8
+new file mode 100644
+index 0000000..192a502
+--- /dev/null
++++ b/gcc/config/sparc/t-hfleonv8
+@@ -0,0 +1,37 @@
++# Copyright (C) 2010 Free Software Foundation, Inc.
++#
++# This file is part of GCC.
++#
++# GCC is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3, or (at your option)
++# any later version.
++#
++# GCC is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with GCC; see the file COPYING3.  If not see
++# <http://www.gnu.org/licenses/>.
++
++# We want fine grained libraries, so use the new code to build the
++# floating point emulation libraries.
++FPBIT = fp-bit.c
++DPBIT = dp-bit.c
++
++dp-bit.c: $(srcdir)/config/fp-bit.c
++	cat $(srcdir)/config/fp-bit.c > dp-bit.c
++
++fp-bit.c: $(srcdir)/config/fp-bit.c
++	echo '#define FLOAT' > fp-bit.c
++	cat $(srcdir)/config/fp-bit.c >> fp-bit.c
++
++# Multilibs for LEON3
++#MULTILIB_OPTIONS = msoft-float
++#MULTILIB_DIRNAMES = soft
++#MULTILIB_MATCHES = msoft-float=mno-fpu
++
++LIBGCC = stmp-multilib
++INSTALL_LIBGCC = install-multilib
+diff --git a/gcc/config/sparc/t-leon3 b/gcc/config/sparc/t-leon3
+index ce57d16..2bb1621 100644
+--- a/gcc/config/sparc/t-leon3
++++ b/gcc/config/sparc/t-leon3
+@@ -29,9 +29,9 @@ fp-bit.c: $(srcdir)/config/fp-bit.c
+ 	cat $(srcdir)/config/fp-bit.c >> fp-bit.c
+ 
+ # Multilibs for LEON3
+-MULTILIB_OPTIONS = msoft-float
+-MULTILIB_DIRNAMES = soft
+-MULTILIB_MATCHES = msoft-float=mno-fpu
++MULTILIB_OPTIONS = msoft-float mv8
++MULTILIB_DIRNAMES = soft v8
++MULTILIB_MATCHES = msoft-float=mno-fpu mv8=mcpu?v8
+ 
+ LIBGCC = stmp-multilib
+ INSTALL_LIBGCC = install-multilib
+diff --git a/gcc/config/sparc/t-sfleon b/gcc/config/sparc/t-sfleon
+new file mode 100644
+index 0000000..192a502
+--- /dev/null
++++ b/gcc/config/sparc/t-sfleon
+@@ -0,0 +1,37 @@
++# Copyright (C) 2010 Free Software Foundation, Inc.
++#
++# This file is part of GCC.
++#
++# GCC is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3, or (at your option)
++# any later version.
++#
++# GCC is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with GCC; see the file COPYING3.  If not see
++# <http://www.gnu.org/licenses/>.
++
++# We want fine grained libraries, so use the new code to build the
++# floating point emulation libraries.
++FPBIT = fp-bit.c
++DPBIT = dp-bit.c
++
++dp-bit.c: $(srcdir)/config/fp-bit.c
++	cat $(srcdir)/config/fp-bit.c > dp-bit.c
++
++fp-bit.c: $(srcdir)/config/fp-bit.c
++	echo '#define FLOAT' > fp-bit.c
++	cat $(srcdir)/config/fp-bit.c >> fp-bit.c
++
++# Multilibs for LEON3
++#MULTILIB_OPTIONS = msoft-float
++#MULTILIB_DIRNAMES = soft
++#MULTILIB_MATCHES = msoft-float=mno-fpu
++
++LIBGCC = stmp-multilib
++INSTALL_LIBGCC = install-multilib
+diff --git a/gcc/config/sparc/t-sfleonv8 b/gcc/config/sparc/t-sfleonv8
+new file mode 100644
+index 0000000..192a502
+--- /dev/null
++++ b/gcc/config/sparc/t-sfleonv8
+@@ -0,0 +1,37 @@
++# Copyright (C) 2010 Free Software Foundation, Inc.
++#
++# This file is part of GCC.
++#
++# GCC is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3, or (at your option)
++# any later version.
++#
++# GCC is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with GCC; see the file COPYING3.  If not see
++# <http://www.gnu.org/licenses/>.
++
++# We want fine grained libraries, so use the new code to build the
++# floating point emulation libraries.
++FPBIT = fp-bit.c
++DPBIT = dp-bit.c
++
++dp-bit.c: $(srcdir)/config/fp-bit.c
++	cat $(srcdir)/config/fp-bit.c > dp-bit.c
++
++fp-bit.c: $(srcdir)/config/fp-bit.c
++	echo '#define FLOAT' > fp-bit.c
++	cat $(srcdir)/config/fp-bit.c >> fp-bit.c
++
++# Multilibs for LEON3
++#MULTILIB_OPTIONS = msoft-float
++#MULTILIB_DIRNAMES = soft
++#MULTILIB_MATCHES = msoft-float=mno-fpu
++
++LIBGCC = stmp-multilib
++INSTALL_LIBGCC = install-multilib
diff -Naur crosstool-ng-1.13.0/patches/glibc/2.14/400-sparc-leon.patch crosstool-ng-1.13.0-w0/patches/glibc/2.14/400-sparc-leon.patch
--- crosstool-ng-1.13.0/patches/glibc/2.14/400-sparc-leon.patch	1970-01-01 01:00:00.000000000 +0100
+++ crosstool-ng-1.13.0-w0/patches/glibc/2.14/400-sparc-leon.patch	2011-12-13 09:03:51.000000000 +0100
@@ -0,0 +1,85 @@
+diff -Naur glibc-2.14.ori/math/math.h glibc-2.14.p2/math/math.h
+--- glibc-2.14.ori/math/math.h	2011-05-31 06:12:33.000000000 +0200
++++ glibc-2.14.p2/math/math.h	2011-11-10 17:03:08.000000000 +0100
+@@ -396,7 +396,7 @@
+ # define __NO_MATH_INLINES	1
+ #endif
+ 
+-#if defined __USE_ISOC99 && __GNUC_PREREQ(2,97)
++#if (!(defined(__sparc__) &&  defined(_SOFT_FLOAT))) && defined __USE_ISOC99 && __GNUC_PREREQ(2,97)
+ /* ISO C99 defines some macros to compare number while taking care for
+    unordered numbers.  Many FPUs provide special instructions to support
+    these operations.  Generic support in GCC for these as builtins went
+diff -Naur glibc-2.14.ori/sysdeps/sparc/fpu/bits/mathinline.h glibc-2.14.p2/sysdeps/sparc/fpu/bits/mathinline.h
+--- glibc-2.14.ori/sysdeps/sparc/fpu/bits/mathinline.h	2011-05-31 06:12:33.000000000 +0200
++++ glibc-2.14.p2/sysdeps/sparc/fpu/bits/mathinline.h	2011-11-10 17:03:35.000000000 +0100
+@@ -232,6 +232,9 @@
+ 
+ /* This code is used internally in the GNU libc.  */
+ #  ifdef __LIBC_INTERNAL_MATH_INLINES
++
++#ifndef _SOFT_FLOAT
++
+ __MATH_INLINE double
+ __ieee754_sqrt (double __x)
+ {
+@@ -248,6 +251,8 @@
+   return __r;
+ }
+ 
++#endif
++
+ #   if __WORDSIZE == 64
+ __MATH_INLINE long double
+ __ieee754_sqrtl (long double __x)
+diff -Naur glibc-2.14.ori/sysdeps/sparc/fpu/fraiseexcpt.c glibc-2.14.p2/sysdeps/sparc/fpu/fraiseexcpt.c
+--- glibc-2.14.ori/sysdeps/sparc/fpu/fraiseexcpt.c	2011-05-31 06:12:33.000000000 +0200
++++ glibc-2.14.p2/sysdeps/sparc/fpu/fraiseexcpt.c	2011-11-10 17:03:58.000000000 +0100
+@@ -32,6 +32,10 @@
+   };
+   double d;
+ 
++#ifdef _SOFT_FLOAT
++#define __asm(...)
++#endif
++  
+   /* Raise exceptions represented by EXPECTS.  But we must raise only
+      one signal at a time.  It is important the if the overflow/underflow
+      exception and the inexact exception are given at the same time,
+diff -Naur glibc-2.14.ori/sysdeps/sparc/sparc32/Makefile glibc-2.14.p2/sysdeps/sparc/sparc32/Makefile
+--- glibc-2.14.ori/sysdeps/sparc/sparc32/Makefile	2011-05-31 06:12:33.000000000 +0200
++++ glibc-2.14.p2/sysdeps/sparc/sparc32/Makefile	2011-11-10 17:04:56.000000000 +0100
+@@ -24,6 +24,11 @@
+ CFLAGS-initfini.s += -mcpu=v7
+ endif
+ 
++ifeq ($(with-fp),no)
+++cflags += -msoft-float -D_SOFT_FLOAT
++sysdep-LDFLAGS += -msoft-float
++endif
++
+ # We distribute these files, even though they are generated,
+ # so as to avoid the need for a functioning m4 to build the library.
+ divrem := sdiv udiv rem urem
+diff -Naur glibc-2.14.ori/sysdeps/sparc/sparc32/e_sqrt.c glibc-2.14.p2/sysdeps/sparc/sparc32/e_sqrt.c
+--- glibc-2.14.ori/sysdeps/sparc/sparc32/e_sqrt.c	2011-05-31 06:12:33.000000000 +0200
++++ glibc-2.14.p2/sysdeps/sparc/sparc32/e_sqrt.c	2011-11-10 17:04:24.000000000 +0100
+@@ -23,6 +23,8 @@
+   #error This file uses GNU C extensions; you must compile with GCC.
+ #endif
+ 
++#ifndef _SOFT_FLOAT
++
+ /* Return the square root of X.  */
+ double
+ __ieee754_sqrt (x)
+@@ -32,3 +34,9 @@
+   asm ("fsqrtd %1, %0" : "=f" (result) : "f" (x));
+   return result;
+ }
++#else 
++
++#include <sysdeps/ieee754/dbl-64/e_sqrt.c>
++
++#endif
++
diff -Naur crosstool-ng-1.13.0/patches/glibc/2.14/401-s_fma_f.patch crosstool-ng-1.13.0-w0/patches/glibc/2.14/401-s_fma_f.patch
--- crosstool-ng-1.13.0/patches/glibc/2.14/401-s_fma_f.patch	1970-01-01 01:00:00.000000000 +0100
+++ crosstool-ng-1.13.0-w0/patches/glibc/2.14/401-s_fma_f.patch	2011-12-13 09:03:51.000000000 +0100
@@ -0,0 +1,52 @@
+diff -Naur glibc-2.14.base/sysdeps/ieee754/dbl-64/s_fmaf.c glibc-2.14/sysdeps/ieee754/dbl-64/s_fmaf.c
+--- glibc-2.14.base/sysdeps/ieee754/dbl-64/s_fmaf.c	2011-11-11 09:48:40.000000000 +0100
++++ glibc-2.14/sysdeps/ieee754/dbl-64/s_fmaf.c	2011-11-11 10:03:51.000000000 +0100
+@@ -18,6 +18,10 @@
+    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+    02111-1307 USA.  */
+ 
++#ifdef _SOFT_FLOAT
++#include <math/s_fmaf.c>
++#else
++
+ #include <math.h>
+ #include <fenv.h>
+ #include <ieee754.h>
+@@ -48,3 +52,4 @@
+ #ifndef __fmaf
+ weak_alias (__fmaf, fmaf)
+ #endif
++#endif
+diff -Naur glibc-2.14.base/sysdeps/ieee754/ldbl-opt/s_fma.c glibc-2.14/sysdeps/ieee754/ldbl-opt/s_fma.c
+--- glibc-2.14.base/sysdeps/ieee754/ldbl-opt/s_fma.c	2011-11-11 09:48:40.000000000 +0100
++++ glibc-2.14/sysdeps/ieee754/ldbl-opt/s_fma.c	2011-11-11 10:00:13.000000000 +0100
+@@ -1,5 +1,9 @@
+ #include <math_ldbl_opt.h>
++#ifdef _SOFT_FLOAT
++#include <math/s_fma.c>
++#else
+ #include <sysdeps/ieee754/dbl-64/s_fma.c>
++#endif
+ #if LONG_DOUBLE_COMPAT(libm, GLIBC_2_1)
+ compat_symbol (libm, __fma, fmal, GLIBC_2_1);
+ #endif
+diff -Naur glibc-2.14.ori/sysdeps/ieee754/ldbl-128/s_fmal.c glibc-2.14/sysdeps/ieee754/ldbl-128/s_fmal.c
+--- glibc-2.14.ori/sysdeps/ieee754/ldbl-128/s_fmal.c    2011-11-11 11:03:30.000000000 +0100
++++ glibc-2.14/sysdeps/ieee754/ldbl-128/s_fmal.c        2011-11-11 11:07:32.000000000 +0100
+@@ -18,6 +18,10 @@
+    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+    02111-1307 USA.  */
+
++#ifdef _SOFT_FLOAT
++#include <math/s_fmal.c>
++#else
++
+ #include <float.h>
+ #include <math.h>
+ #include <fenv.h>
+@@ -221,3 +225,5 @@
+     }
+ }
+ weak_alias (__fmal, fmal)
++
++#endif
diff -Naur crosstool-ng-1.13.0/scripts/build/binutils/binutils.sh crosstool-ng-1.13.0-w0/scripts/build/binutils/binutils.sh
--- crosstool-ng-1.13.0/scripts/build/binutils/binutils.sh	2011-10-24 22:06:36.000000000 +0200
+++ crosstool-ng-1.13.0-w0/scripts/build/binutils/binutils.sh	2011-12-13 09:03:51.000000000 +0100
@@ -59,6 +59,11 @@
         extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
         [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
     fi
+    if [ "${CT_CC_MULTILIB}" = "n" ]; then
+        extra_config+=("--disable-multilib")
+    else
+        extra_config+=("--enable-multilib")
+    fi
 
     CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
 
@@ -71,7 +76,6 @@
         --target=${CT_TARGET}                                   \
         --prefix=${CT_PREFIX_DIR}                               \
         --disable-nls                                           \
-        --disable-multilib                                      \
         --disable-werror                                        \
         "${extra_config[@]}"                                    \
         ${CT_ARCH_WITH_FLOAT}                                   \
@@ -151,7 +155,12 @@
             extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
             [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
         fi
-
+	if [ "${CT_CC_MULTILIB}" = "n" ]; then
+            extra_config+=("--disable-multilib")
+	else
+            extra_config+=("--enable-multilib")
+	fi
+    
         CT_DoExecLog CFG                                            \
         "${CT_SRC_DIR}/binutils-${CT_BINUTILS_VERSION}/configure"   \
             --build=${CT_BUILD}                                     \
@@ -162,7 +171,6 @@
             --enable-shared                                         \
             --enable-static                                         \
             --disable-nls                                           \
-            --disable-multilib                                      \
             "${extra_config[@]}"                                    \
             ${CT_ARCH_WITH_FLOAT}                                   \
             "${CT_BINUTILS_EXTRA_CONFIG[@]}"
diff -Naur crosstool-ng-1.13.0/scripts/build/cc/gcc.sh crosstool-ng-1.13.0-w0/scripts/build/cc/gcc.sh
--- crosstool-ng-1.13.0/scripts/build/cc/gcc.sh	2011-10-24 22:06:36.000000000 +0200
+++ crosstool-ng-1.13.0-w0/scripts/build/cc/gcc.sh	2011-12-13 09:03:51.000000000 +0100
@@ -288,6 +288,12 @@
     extra_config+=(--disable-libgomp)
     extra_config+=(--disable-libmudflap)
 
+   if [ "${CT_CC_MULTILIB}" = "n" ]; then
+        extra_config+=("--disable-multilib")
+    else
+        extra_config+=("--enable-multilib")
+    fi
+
     CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
 
     # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
@@ -301,7 +307,6 @@
         --target=${CT_TARGET}                       \
         --prefix="${core_prefix_dir}"               \
         --with-local-prefix="${CT_SYSROOT_DIR}"     \
-        --disable-multilib                          \
         --disable-libmudflap                        \
         ${CC_CORE_SYSROOT_ARG}                      \
         "${extra_config[@]}"                        \
@@ -424,7 +429,13 @@
     lang_opt=$(echo "${lang_opt},${CT_CC_LANG_OTHERS}" |sed -r -e 's/,+/,/g; s/,*$//;')
 
     extra_config+=("--enable-languages=${lang_opt}")
-    extra_config+=("--disable-multilib")
+    
+    if [ "${CT_CC_MULTILIB}" = "n" ]; then
+        extra_config+=("--disable-multilib")
+    else
+        extra_config+=("--enable-multilib")
+    fi
+ 
     for tmp in ARCH ABI CPU TUNE FPU FLOAT; do
         eval tmp="\${CT_ARCH_WITH_${tmp}}"
         if [ -n "${tmp}" ]; then
diff -Naur crosstool-ng-1.13.0/scripts/build/libc/glibc-eglibc.sh-common crosstool-ng-1.13.0-w0/scripts/build/libc/glibc-eglibc.sh-common
--- crosstool-ng-1.13.0/scripts/build/libc/glibc-eglibc.sh-common	2011-10-24 22:06:36.000000000 +0200
+++ crosstool-ng-1.13.0-w0/scripts/build/libc/glibc-eglibc.sh-common	2011-12-13 09:03:51.000000000 +0100
@@ -57,18 +57,103 @@
 do_libc_start_files() {
     # Start files and Headers should be configured the same way as the
     # final libc, but built and installed differently.
-    do_libc_backend libc_mode=startfiles
+    do_libc_backend_multilib libc_mode=startfiles
 }
 
 # This function builds and install the full C library
 do_libc() {
-    do_libc_backend libc_mode=final
+    do_libc_backend_multilib libc_mode=final
 }
 
+# installation is done into ${CT_SYSROOT_DIR}/${dir}. The multilib prefix has to be included
+# to reflect the runtime setting.
+do_libc_backend_rearrange() {
+    local libc_mode
+    
+    while [ $# -ne 0 ]; do
+        eval "${1// /\\ }"
+        shift
+    done
+    
+    if [ "${libc_mode}" = "final" ]; then
+        cross_cc=$(CT_Which "${CT_TARGET}-gcc")
+        for i in `${cross_cc} --print-multi-lib 2>/dev/null`; do
+           dir="${i%%;*}"
+	   bdir="$(echo ${dir} | ${sed} -r -e 's:/:\\\\/:g')"
+           if [ "${dir}" != "." ]; then 
+               flags="$(echo $i | ${sed} -r -e 's/^[^;]*;//' -e 's/@/ -/g')";
+               CT_DoStep DEBUG "Fixing up multilib location ${CT_SYSROOT_DIR}/${dir}/lib to ${CT_SYSROOT_DIR}/lib/${dir}"
+               mkdir -p ${CT_SYSROOT_DIR}/lib/${dir}
+               mkdir -p ${CT_SYSROOT_DIR}/usr/lib/${dir}
+
+               # recreate the symbolic links for multilib 
+               for f in $(find ${CT_SYSROOT_DIR}/usr/lib/${dir}/ -type l -maxdepth 1); do
+                   fn=`basename $f`
+                   ln=`readlink $f`
+                   ln=`basename $ln`
+		   # go toward root. Count the numer of "/" and asseble a "../.." prefix 
+                   pre=$( echo ${dir} | awk '{r="";
+		       c=split($0,b,"/");
+		       for(i=0;i<c;i++){
+		           if(i!=0){r=r "/";}
+			   r=r "..";
+		       };
+		       printf("%s",r);
+		   }')
+		   CT_Pushd "${CT_SYSROOT_DIR}/usr/lib/${dir}/"
+                   ln -sf ../../${pre}/lib/${dir}/$ln $fn
+		   CT_Popd
+               done
+
+               # rewrite the library multiplexers
+               for l in libc libpthread libgcc_s; do
+                   for d in lib/${dir} usr/lib/${dir}; do
+                       if [ -f "${CT_SYSROOT_DIR}/${d}/${l}.so" -a ! -L ${CT_SYSROOT_DIR}/${d}/${l}.so ]; then
+                           if [ ! -f "${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i" ]; then
+                               cp ${CT_SYSROOT_DIR}/${d}/${l}.so ${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i
+                               cat ${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i | ${sed} -r -e "s/\/lib\/$l/\/lib\/$bdir\/$l/g" > ${CT_SYSROOT_DIR}/${d}/${l}.so
+			   else
+			       CT_DoLog WARN "${CT_SYSROOT_DIR}/${d}/${l}.so has already been patched, skipping"
+                           fi
+                       fi
+                   done
+               done
+               CT_EndStep
+           fi
+        done;
+    fi
+}
+
+# call do_libc_backend <multilib> times with varying <extra_dir> and <extra_flags> options
+do_libc_backend_multilib() {
+    local flags=""
+    local i
+    local dir
+    # We need to call the backend at least once,
+    # with all settings set to the defaults
+    do_libc_backend "$@"
+    cross_cc=$(CT_Which "${CT_TARGET}-gcc")
+    if [ "${CT_CC_MULTILIB}" = "y" ]; then
+       for i in `${cross_cc} --print-multi-lib 2>/dev/null`; do
+           dir="${i%%;*}"
+           if [ "${dir}" != "." ]; then 
+               flags="$(echo $i | ${sed} -r -e 's/^[^;]*;//' -e 's/@/ -/g')";
+               CT_DoStep INFO "C Library with multilib. Flags: \"${flags}\" Dir: \"${dir}\""
+               do_libc_backend "$@" extra_dir="/${dir}" extra_flags="${flags}" 
+               CT_EndStep
+           fi
+       done;
+       do_libc_backend_rearrange "$@"
+    fi
+}		       
+
 do_libc_backend() {
     local src_dir="${CT_SRC_DIR}/${CT_LIBC}-${CT_LIBC_VERSION}"
     local libc_mode=final
     local extra_cc_args
+    local extra_dir=""
+    local extra_dir_p
+    local extra_flags=""
     local -a extra_config
     local -a extra_make_args
     local glibc_cflags
@@ -77,15 +162,16 @@
         eval "${1// /\\ }"
         shift
     done
-
+    extra_dir_p="$(echo ${extra_dir} | ${sed} -r -e 's/\///g')"
+	
     if [ "${libc_mode}" = "startfiles" ]; then
         CT_DoStep INFO "Installing C library headers & start files"
-        mkdir -p "${CT_BUILD_DIR}/build-libc-start-files"
-        cd "${CT_BUILD_DIR}/build-libc-start-files"
+        mkdir -p "${CT_BUILD_DIR}/build-libc-start-files${extra_dir_p}"
+        cd "${CT_BUILD_DIR}/build-libc-start-files${extra_dir_p}"
     else # libc_mode = final
         CT_DoStep INFO "Installing C library"
-        mkdir -p "${CT_BUILD_DIR}/build-libc"
-        cd "${CT_BUILD_DIR}/build-libc"
+        mkdir -p "${CT_BUILD_DIR}/build-libc${extra_dir_p}"
+        cd "${CT_BUILD_DIR}/build-libc${extra_dir_p}"
     fi
 
     CT_DoLog EXTRA "Configuring C library"
@@ -133,7 +219,13 @@
     esac
 
     case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
-        y,) extra_config+=("--with-fp");;
+        y,) # if it is a <multilib> build then check if -msoft-float is given
+	    if [ "x`expr "${extra_flags}" : '.*-msoft-float.*'`" != "x0" ]; then
+	    	extra_config+=("--with-fp=no");
+	    else
+	    	extra_config+=("--with-fp");
+	    fi
+	    ;;
         ,y) extra_config+=("--without-fp");;
     esac
 
@@ -173,7 +265,7 @@
     CT_DoLog DEBUG "Extra config args passed: '${extra_config[*]}'"
     CT_DoLog DEBUG "Extra CC args passed    : '${extra_cc_args}'"
 
-    glibc_cflags="${CT_TARGET_CFLAGS} ${CT_LIBC_GLIBC_EXTRA_CFLAGS} ${OPTIMIZE}"
+    glibc_cflags="${CT_TARGET_CFLAGS} ${CT_LIBC_GLIBC_EXTRA_CFLAGS} ${OPTIMIZE} ${extra_flags}"
     case "${CT_LIBC_ENABLE_FORTIFIED_BUILD}" in
         y)  ;;
         *)  glibc_cflags+=" -U_FORTIFY_SOURCE";;
@@ -236,7 +328,7 @@
         # use the 'install-headers' makefile target to install the
         # headers
         CT_DoExecLog ALL make ${JOBSFLAGS}              \
-                         install_root=${CT_SYSROOT_DIR} \
+                         install_root=${CT_SYSROOT_DIR}${extra_dir} \
                          install-bootstrap-headers=yes  \
                          "${extra_make_args[@]}"        \
                          install-headers
@@ -273,12 +365,12 @@
 
             # there are a few object files needed to link shared libraries,
             # which we build and install by hand
-            CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}/usr/lib"
+            CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}${extra_dir}/usr/lib"
             CT_DoExecLog ALL make ${JOBSFLAGS}  \
                         "${extra_make_args[@]}" \
                         csu/subdir_lib
             CT_DoExecLog ALL cp csu/crt1.o csu/crti.o csu/crtn.o \
-                                "${CT_SYSROOT_DIR}/usr/lib"
+                                "${CT_SYSROOT_DIR}${extra_dir}/usr/lib"
 
             # Finally, 'libgcc_s.so' requires a 'libc.so' to link against.
             # However, since we will never actually execute its code,
@@ -288,7 +380,7 @@
                                            -nostartfiles    \
                                            -shared          \
                                            -x c /dev/null   \
-                                           -o "${CT_SYSROOT_DIR}/usr/lib/libc.so"
+                                           -o "${CT_SYSROOT_DIR}${extra_dir}/usr/lib/libc.so"
         fi # threads == nptl
     else # libc_mode = final
         CT_DoLog EXTRA "Building C library"
@@ -299,7 +391,7 @@
         CT_DoLog EXTRA "Installing C library"
         CT_DoExecLog ALL make ${JOBSFLAGS}                      \
                               "${extra_make_args[@]}"           \
-                              install_root="${CT_SYSROOT_DIR}"  \
+                              install_root="${CT_SYSROOT_DIR}${extra_dir}"  \
                               install
 
         if [ "${CT_LIBC_LOCALES}" = "y" ]; then
