public inbox for crossgcc@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/3] v2: Experimental patches and musl-libc
@ 2014-07-27  1:05 Bryan Hundven
  2014-07-27  1:05 ` [PATCH 2/3] Add support for musl-libc Bryan Hundven
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Bryan Hundven @ 2014-07-27  1:05 UTC (permalink / raw)
  To: Yann E. MORIN; +Cc: crossgcc

This patch series is based on a patch by Timo TerÃs:
    http://patchwork.ozlabs.org/patch/257187/

I ran into a brick wall trying to do this the first time here:
    https://sourceware.org/ml/crossgcc/2014-07/msg00017.html

and this is my attempt to make things more manageable and explicit that these patches are experimental and not supported by crosstool-ng.

As with the previous patch set, this is [RFC].

I have one more patch to send that is more RFC then this set that allows specific patch tuning, but in the meantime this patch set works.

Also, to note my previous patch set:
Currently a minimal armel- is the only target tested. Please let me know your experiences, comments, feedback, and/or suggestions.


--
For unsubscribe information see http://sourceware.org/lists.html#faq

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/3] Add support for musl-libc
  2014-07-27  1:05 [PATCH 0/3] v2: Experimental patches and musl-libc Bryan Hundven
@ 2014-07-27  1:05 ` Bryan Hundven
  2014-07-27 23:15   ` Yann E. MORIN
  2014-07-27  1:05 ` [PATCH 3/3] Add musl patches for gcc Bryan Hundven
  2014-07-27  1:05 ` [PATCH 1/3] Add main EXPERIMENTAL_PATCHES setting Bryan Hundven
  2 siblings, 1 reply; 7+ messages in thread
From: Bryan Hundven @ 2014-07-27  1:05 UTC (permalink / raw)
  To: Yann E. MORIN; +Cc: crossgcc, Bryan Hundven

"Musl-libc is a new standard library to power a new generation of Linux-based
devices. musl is lightweight, fast, simple, free, and strives to be correct in
the sense of standards-conformance and safety."

This patch adds support for musl to be selected and built by crosstool-ng.
NOTE: Experimental patches are needed for gcc and possibly other components.
Later patches include this support.

Signed-off-by: Bryan Hundven <bryanhundven@gmail.com>
---
 config/libc.in             |  11 +++++
 config/libc/musl.in        |  47 +++++++++++++++++++
 config/libc/musl.in.2      |   2 +
 scripts/build/arch/arm.sh  |   1 +
 scripts/build/libc/musl.sh | 111 +++++++++++++++++++++++++++++++++++++++++++++
 scripts/functions          |   1 +
 6 files changed, 173 insertions(+)
 create mode 100644 config/libc/musl.in
 create mode 100644 config/libc/musl.in.2
 create mode 100644 scripts/build/libc/musl.sh

diff --git a/config/libc.in b/config/libc.in
index 03f5db2..ff9ce9e 100644
--- a/config/libc.in
+++ b/config/libc.in
@@ -28,6 +28,10 @@ config LIBC_SUPPORT_NPTL
     bool
     select LIBC_SUPPORT_THREADS_ANY
 
+config LIBC_SUPPORT_MUSL
+    bool
+    select LIBC_SUPPORT_THREADS_ANY
+
 config LIBC_SUPPORT_LINUXTHREADS
     bool
     select LIBC_SUPPORT_THREADS_ANY
@@ -42,6 +46,7 @@ config LIBC_SUPPORT_THREADS_NONE
 config THREADS
     string
     default "nptl"          if THREADS_NPTL
+    default "musl"          if THREADS_MUSL
     default "linuxthreads"  if THREADS_LINUXTHREADS
     default "win32"         if THREADS_WIN32THREADS
     default "none"          if THREADS_NONE || LIBC_none
@@ -55,6 +60,7 @@ choice
     bool
     prompt "Threading implementation to use:"
     default THREADS_NPTL           if LIBC_SUPPORT_NPTL
+    default THREADS_MUSL           if LIBC_SUPPORT_MUSL
     default THREADS_LINUXTHREADS   if LIBC_SUPPORT_LINUXTHREADS && ! LIBC_SUPPORT_NPTL
     default THREADS_WIN32          if LIBC_SUPPORT_WIN32THREADS
     default THREADS_NONE           if ! LIBC_SUPPORT_THREADS_ANY
@@ -64,6 +70,11 @@ config THREADS_NPTL
     prompt "nptl"
     depends on LIBC_SUPPORT_NPTL
 
+config THREADS_MUSL
+    bool
+    prompt "musl"
+    depends on LIBC_SUPPORT_MUSL
+
 config THREADS_LINUXTHREADS
     bool
     prompt "linuxthreads"
diff --git a/config/libc/musl.in b/config/libc/musl.in
new file mode 100644
index 0000000..69f465c
--- /dev/null
+++ b/config/libc/musl.in
@@ -0,0 +1,47 @@
+# musl options
+
+## depends on ! WINDOWS && ! BARE_METAL
+##
+## select LIBC_SUPPORT_MUSL
+## select CC_CORE_PASSES_NEEDED
+##
+## help Musl is a new standard library to power a new generation of Linux-based
+## help devices. musl is lightweight, fast, simple, free, and strives to be
+## help correct in the sense of standards-conformance and safety.
+
+choice
+    bool
+    prompt "musl version"
+# Don't remove next line
+# CT_INSERT_VERSION_BELOW
+
+config LIBC_MUSL_V_1_1_3
+    bool
+    prompt "1.1.3 (Mainline)"
+    select LIBC_MUSL_DEFAULTS
+    depends on EXPERIMENTAL
+
+config LIBC_MUSL_V_1_0_3
+    bool
+    prompt "1.0.3 (Stable)"
+    select LIBC_MUSL_DEFAULTS
+
+config LIBC_MUSL_V_CUSTOM
+    bool
+    prompt "Custom musl"
+    select LIBC_MUSL_DEFAULTS
+    depends on EXPERIMENTAL
+
+endchoice
+
+config LIBC_MUSL_DEFAULTS
+    bool
+    select LIBC_SUPPORT_MUSL
+
+config LIBC_VERSION
+    string
+# Don't remove next line
+# CT_INSERT_VERSION_STRING_BELOW
+    default "1.1.3" if LIBC_MUSL_V_1_1_3
+    default "1.0.3" if LIBC_MUSL_V_1_0_3
+    default "custom" if LIBC_MUSL_V_CUSTOM
diff --git a/config/libc/musl.in.2 b/config/libc/musl.in.2
new file mode 100644
index 0000000..bf4fb71
--- /dev/null
+++ b/config/libc/musl.in.2
@@ -0,0 +1,2 @@
+# musl second-part options
+
diff --git a/scripts/build/arch/arm.sh b/scripts/build/arch/arm.sh
index 430bdde..ba87e0c 100644
--- a/scripts/build/arch/arm.sh
+++ b/scripts/build/arch/arm.sh
@@ -17,6 +17,7 @@ CT_DoArchTupleValues() {
     case "${CT_LIBC},${CT_ARCH_ARM_EABI}" in
         *glibc,y)   CT_TARGET_SYS=gnueabi;;
         uClibc,y)   CT_TARGET_SYS=uclibcgnueabi;;
+        musl,y)     CT_TARGET_SYS=muslgnueabi;;
         *,y)        CT_TARGET_SYS=eabi;;
     esac
 
diff --git a/scripts/build/libc/musl.sh b/scripts/build/libc/musl.sh
new file mode 100644
index 0000000..f72517c
--- /dev/null
+++ b/scripts/build/libc/musl.sh
@@ -0,0 +1,111 @@
+# This file adds functions to build the musl C library
+# Copyright 2013 Timo Teräs
+# Licensed under the GPL v2. See COPYING in the root of this package
+
+do_libc_get() {
+    local libc_src
+
+    libc_src="http://www.musl-libc.org/releases"
+
+    if [ "${CT_LIBC_MUSL_CUSTOM}" = "y" ]; then
+        CT_GetCustom "musl" "${CT_LIBC_VERSION}"      \
+                     "${CT_LIBC_MUSL_CUSTOM_LOCATION}"
+    else # ! custom location
+        CT_GetFile "musl-${CT_LIBC_VERSION}" "${libc_src}"
+    fi # ! custom location
+}
+
+do_libc_extract() {
+    # If using custom directory location, nothing to do.
+    if [ "${CT_LIBC_MUSL_CUSTOM}" = "y" ]; then
+        # Abort if the custom directory is not found.
+        if ! [ -d "${CT_SRC_DIR}/musl-${CT_LIBC_VERSION}" ]; then
+            CT_Abort "Directory not found: ${CT_SRC_DIR}/musl-${CT_LIBC_VERSION}"
+        fi
+
+        return 0
+    fi
+
+    CT_Extract "musl-${CT_LIBC_VERSION}"
+    CT_Patch "musl" "${CT_LIBC_VERSION}"
+}
+
+do_libc_check_config() {
+    :
+}
+
+do_libc_configure() {
+    CT_DoLog EXTRA "Configuring C library"
+    local -a extra_cflags
+
+    # From buildroot:
+    # gcc constant folding bug with weak aliases workaround
+    # See http://www.openwall.com/lists/musl/2014/05/15/1
+    if [ "${CT_CC_GCC_4_9_or_later}" = "y" ]; then
+        extra_cflags+=("-fno-toplevel-reorder")
+    fi
+
+    # NOTE: musl handles the build/host/target a little bit differently
+    # then one would expect:
+    #   build   : not used
+    #   host    : the machine building musl
+    #   target  : the machine musl runs on
+    CT_DoExecLog CFG                \
+    CFLAGS="${extra_cflags[@]}"     \
+    CROSS_COMPILE="${CT_TARGET}-"   \
+    ./configure                     \
+        --host="${CT_BUILD}"        \
+        --target="${CT_TARGET}"     \
+        --prefix="/usr"             \
+        --disable-gcc-wrapper
+}
+
+do_libc_start_files() {
+    local ARCH
+
+    CT_DoStep INFO "Installing C library headers"
+
+    # Simply copy files until musl has the ability to build out-of-tree
+    CT_DoLog EXTRA "Copying sources to build directory"
+    CT_DoExecLog ALL cp -av "${CT_SRC_DIR}/musl-${CT_LIBC_VERSION}" \
+                            "${CT_BUILD_DIR}/build-libc-headers"
+    cd "${CT_BUILD_DIR}/build-libc-headers"
+
+    # musl can be installed without gcc if arch is known
+    case "${CT_TARGET}" in
+        arm*) ARCH=arm ;;
+        i?86*) ARCH=i386 ;;
+        x86_64*) ARCH=x86_64 ;;
+        mips-*|mipsel-*) ARCH=mips ;;
+        microblaze-*) ARCH=microblaze ;;
+        powerpc-*) ARCH=powerpc ;;
+        sh-*|sh[34]-*) ARCH=sh ;;
+        x32-*) ARCH=x32 ;;
+        *) return 1 ;;
+    esac
+
+    CT_DoLog EXTRA "Installing headers"
+    CT_DoExecLog ALL make ARCH="${ARCH}" install-headers DESTDIR="${CT_SYSROOT_DIR}/"
+
+    CT_EndStep
+}
+
+do_libc() {
+    CT_DoStep INFO "Installing C library"
+
+    # Simply copy files until musl has the ability to build out-of-tree
+    CT_DoLog EXTRA "Copying sources to build directory"
+    CT_DoExecLog ALL cp -av "${CT_SRC_DIR}/musl-${CT_LIBC_VERSION}" \
+                            "${CT_BUILD_DIR}/build-libc"
+    cd "${CT_BUILD_DIR}/build-libc"
+
+    do_libc_configure
+
+    CT_DoLog EXTRA "Building C library"
+    CT_DoExecLog ALL make ${JOBSFLAGS}
+
+    CT_DoLog EXTRA "Installing C library"
+    CT_DoExecLog ALL make install DESTDIR="${CT_SYSROOT_DIR}/"
+
+    CT_EndStep
+}
diff --git a/scripts/functions b/scripts/functions
index 2e4d4fa..eae3b95 100644
--- a/scripts/functions
+++ b/scripts/functions
@@ -1182,6 +1182,7 @@ CT_DoBuildTargetTuple() {
     case "${CT_LIBC}" in
         *glibc) CT_TARGET_SYS=gnu;;
         uClibc) CT_TARGET_SYS=uclibc;;
+        musl)   CT_TARGET_SYS=musl;;
         *)      CT_TARGET_SYS=elf;;
     esac
 
-- 
2.0.1


--
For unsubscribe information see http://sourceware.org/lists.html#faq

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] Add main EXPERIMENTAL_PATCHES setting
  2014-07-27  1:05 [PATCH 0/3] v2: Experimental patches and musl-libc Bryan Hundven
  2014-07-27  1:05 ` [PATCH 2/3] Add support for musl-libc Bryan Hundven
  2014-07-27  1:05 ` [PATCH 3/3] Add musl patches for gcc Bryan Hundven
@ 2014-07-27  1:05 ` Bryan Hundven
  2014-07-27 23:23   ` Yann E. MORIN
  2 siblings, 1 reply; 7+ messages in thread
From: Bryan Hundven @ 2014-07-27  1:05 UTC (permalink / raw)
  To: Yann E. MORIN; +Cc: crossgcc, Bryan Hundven

This change adds support for experimental patches to be introduced to
crosstool-ng. The patches enabled by this option are to be located here:

    patches/experimental/<package>/<version>/XXXX-NAME.patch

Where, XXXX is the patch number to be applied in order, like:
    0001-some_patch_one.patch
    0002-some_patch_two.patch
    9999-some_patch_to_be_applied_last.patch

In the first patch series, all patches in the EXPERIMENTAL_PATCHES
option will be applied all at once, or none at all.

In a later [RFC] patch, I plan on adding finer tuned patch
enable/disable options based on the name of the patch and where it is
located in the patches/experimental sub-tree. So the name of the patch
should use underscores between words in the patch name.

Signed-off-by: Bryan Hundven <bryanhundven@gmail.com>
---
 config/global/ct-behave.in | 10 ++++++++++
 scripts/functions          | 16 ++++++++++++----
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/config/global/ct-behave.in b/config/global/ct-behave.in
index ba723cf..9f3354f 100644
--- a/config/global/ct-behave.in
+++ b/config/global/ct-behave.in
@@ -29,6 +29,16 @@ config EXPERIMENTAL
         - non-existant, in which case you could also try hacking it in and send me
           the result
 
+config EXPERIMENTAL_PATCHES
+    bool
+    depends on EXPERIMENTAL
+    prompt "Enable patches marked as EXPERIMENTAL_PATCHES"
+    help
+        ***WARNING*** This is not supported by crosstool-ng! ***WARNING***
+
+        If you set this to Y, then you will be able to enable experimental
+        patches that are not supported by crosstool-ng.
+
 config ALLOW_BUILD_AS_ROOT
     bool
     prompt "Allow building as root user (READ HELP!)"
diff --git a/scripts/functions b/scripts/functions
index b15601a..2e4d4fa 100644
--- a/scripts/functions
+++ b/scripts/functions
@@ -1034,6 +1034,8 @@ CT_Patch() {
     local -a patch_dirs
     local bundled_patch_dir
     local local_patch_dir
+    local bundled_exp_patch_dir
+    local local_exp_patch_dir
 
     if [ "${nochdir}" = "nochdir" ]; then
         shift
@@ -1072,11 +1074,17 @@ CT_Patch() {
     bundled_patch_dir="${CT_LIB_DIR}/patches/${pkgname}/${version}"
     local_patch_dir="${CT_LOCAL_PATCH_DIR}/${pkgname}/${version}"
 
+    # Check for experimental patches, if enabled.
+    if [ "${CT_EXPERIMENTAL_PATCHES}" = "y" ]; then
+        bundled_exp_patch_dir="${CT_LIB_DIR}/patches/experimental/${pkgname}/${version}"
+        local_exp_patch_dir="${CT_LOCAL_PATCH_DIR}/experimental/${pkgname}/${version}"
+    fi
+
     case "${CT_PATCH_ORDER}" in
-        bundled)        patch_dirs=("${bundled_patch_dir}");;
-        local)          patch_dirs=("${local_patch_dir}");;
-        bundled,local)  patch_dirs=("${bundled_patch_dir}" "${local_patch_dir}");;
-        local,bundled)  patch_dirs=("${local_patch_dir}" "${bundled_patch_dir}");;
+        bundled)        patch_dirs=("${bundled_patch_dir}" "${bundled_exp_patch_dir}");;
+        local)          patch_dirs=("${local_patch_dir}" "${local_exp_patch_dir}");;
+        bundled,local)  patch_dirs=("${bundled_patch_dir}" "${bundled_exp_patch_dir}" "${local_patch_dir}" "${local_exp_patch_dir}");;
+        local,bundled)  patch_dirs=("${local_patch_dir}" "${local_exp_patch_dir}" "${bundled_patch_dir}" "${bundled_exp_patch_dir}");;
         none)           patch_dirs=;;
     esac
 
-- 
2.0.1


--
For unsubscribe information see http://sourceware.org/lists.html#faq

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/3] Add musl patches for gcc
  2014-07-27  1:05 [PATCH 0/3] v2: Experimental patches and musl-libc Bryan Hundven
  2014-07-27  1:05 ` [PATCH 2/3] Add support for musl-libc Bryan Hundven
@ 2014-07-27  1:05 ` Bryan Hundven
  2014-07-27  1:05 ` [PATCH 1/3] Add main EXPERIMENTAL_PATCHES setting Bryan Hundven
  2 siblings, 0 replies; 7+ messages in thread
From: Bryan Hundven @ 2014-07-27  1:05 UTC (permalink / raw)
  To: Yann E. MORIN; +Cc: crossgcc, Bryan Hundven

These experimental patches enable feature support for musl-libc in gcc.

Signed-off-by: Bryan Hundven <bryanhundven@gmail.com>
---
 patches/experimental/gcc/4.8.0/0001-musl.patch | 401 +++++++++++++
 patches/experimental/gcc/4.8.1/0001-musl.patch | 626 +++++++++++++++++++++
 patches/experimental/gcc/4.8.2/0001-musl.patch | 750 +++++++++++++++++++++++++
 patches/experimental/gcc/4.8.3/0001-musl.patch | 736 ++++++++++++++++++++++++
 patches/experimental/gcc/4.9.0/0001-musl.patch | 706 +++++++++++++++++++++++
 5 files changed, 3219 insertions(+)
 create mode 100644 patches/experimental/gcc/4.8.0/0001-musl.patch
 create mode 100644 patches/experimental/gcc/4.8.1/0001-musl.patch
 create mode 100644 patches/experimental/gcc/4.8.2/0001-musl.patch
 create mode 100644 patches/experimental/gcc/4.8.3/0001-musl.patch
 create mode 100644 patches/experimental/gcc/4.9.0/0001-musl.patch

diff --git a/patches/experimental/gcc/4.8.0/0001-musl.patch b/patches/experimental/gcc/4.8.0/0001-musl.patch
new file mode 100644
index 0000000..e250298
--- /dev/null
+++ b/patches/experimental/gcc/4.8.0/0001-musl.patch
@@ -0,0 +1,401 @@
+This patch enables support for musl-libc in gcc.
+
+This patch is not supported by crosstool-ng and was originally found here:
+    https://bitbucket.org/GregorR/musl-cross/src/27953a1f7085/patches/gcc-4.8.0-musl.diff
+
+Added-By: Bryan Hundven <bryanhundven@gmail.com>
+---
+diff -r 6b1b8174ce29 gcc/config/arm/linux-eabi.h
+--- a/gcc/config/arm/linux-eabi.h	Fri Mar 29 16:41:20 2013 -0400
++++ b/gcc/config/arm/linux-eabi.h	Fri Mar 29 16:41:23 2013 -0400
+@@ -77,6 +77,10 @@
+     %{mfloat-abi=soft*:" GLIBC_DYNAMIC_LINKER_SOFT_FLOAT "} \
+     %{!mfloat-abi=*:" GLIBC_DYNAMIC_LINKER_DEFAULT "}"
+ 
++/* musl has no "classic" (i.e. broken) mode */
++#undef  MUSL_DYNAMIC_LINKER
++#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-arm.so.1"
++
+ /* At this point, bpabi.h will have clobbered LINK_SPEC.  We want to
+    use the GNU/Linux version, not the generic BPABI version.  */
+ #undef  LINK_SPEC
+diff -r 6b1b8174ce29 libitm/config/arm/hwcap.cc
+--- a/libitm/config/arm/hwcap.cc	Fri Mar 29 16:41:20 2013 -0400
++++ b/libitm/config/arm/hwcap.cc	Fri Mar 29 16:41:23 2013 -0400
+@@ -40,7 +40,11 @@
+ 
+ #ifdef __linux__
+ #include <unistd.h>
++#ifdef __GLIBC__
+ #include <sys/fcntl.h>
++#else
++#include <fcntl.h>
++#endif
+ #include <elf.h>
+ 
+ static void __attribute__((constructor))
+# HG changeset patch
+# Parent 2b29df135cf04fe23c38301f6d0fc5796366aecf
+Adding -mmusl as a musl libc specifier, and the necessary hacks for it to know how to find musl's dynamic linker.
+
+diff -r 2b29df135cf0 gcc/config.gcc
+--- a/gcc/config.gcc	Fri Mar 29 16:41:11 2013 -0400
++++ b/gcc/config.gcc	Fri Mar 29 16:41:14 2013 -0400
+@@ -549,7 +549,7 @@
+ esac
+ 
+ # Common C libraries.
+-tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3"
++tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3 LIBC_MUSL=4"
+ 
+ # Common parts for widely ported systems.
+ case ${target} in
+@@ -652,6 +652,9 @@
+     *-*-*uclibc*)
+       tm_defines="$tm_defines DEFAULT_LIBC=LIBC_UCLIBC"
+       ;;
++    *-*-*musl*)
++      tm_defines="$tm_defines DEFAULT_LIBC=LIBC_MUSL"
++      ;;
+     *)
+       tm_defines="$tm_defines DEFAULT_LIBC=LIBC_GLIBC"
+       ;;
+diff -r 2b29df135cf0 gcc/config/linux.h
+--- a/gcc/config/linux.h	Fri Mar 29 16:41:11 2013 -0400
++++ b/gcc/config/linux.h	Fri Mar 29 16:41:14 2013 -0400
+@@ -32,10 +32,12 @@
+ #define OPTION_GLIBC  (DEFAULT_LIBC == LIBC_GLIBC)
+ #define OPTION_UCLIBC (DEFAULT_LIBC == LIBC_UCLIBC)
+ #define OPTION_BIONIC (DEFAULT_LIBC == LIBC_BIONIC)
++#define OPTION_MUSL   (DEFAULT_LIBC == LIBC_MUSL)
+ #else
+ #define OPTION_GLIBC  (linux_libc == LIBC_GLIBC)
+ #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
+ #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
++#define OPTION_MUSL   (linux_libc == LIBC_MUSL)
+ #endif
+ 
+ #define GNU_USER_TARGET_OS_CPP_BUILTINS()			\
+@@ -53,18 +55,21 @@
+    uClibc or Bionic is the default C library and whether
+    -muclibc or -mglibc or -mbionic has been passed to change the default.  */
+ 
+-#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LD1, LD2, LD3)	\
+-  "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:" LD1 "}}"
++#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LIBC4, LD1, LD2, LD3, LD4)	\
++  "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:%{" LIBC4 ":" LD4 ";:" LD1 "}}}"
+ 
+ #if DEFAULT_LIBC == LIBC_GLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
+-  CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", G, U, B)
++#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
++  CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", "mmusl", G, U, B, M)
+ #elif DEFAULT_LIBC == LIBC_UCLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
+-  CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", U, G, B)
++#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
++  CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", "mmusl", U, G, B, M)
+ #elif DEFAULT_LIBC == LIBC_BIONIC
+-#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
+-  CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", B, G, U)
++#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
++  CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", "mmusl", B, G, U, M)
++#elif DEFAULT_LIBC == LIBC_MUSL
++#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
++  CHOOSE_DYNAMIC_LINKER1 ("mmusl", "mglibc", "muclibc", "mbionic", M, G, U, B)
+ #else
+ #error "Unsupported DEFAULT_LIBC"
+ #endif /* DEFAULT_LIBC */
+@@ -84,16 +89,16 @@
+ 
+ #define GNU_USER_DYNAMIC_LINKER						\
+   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER,	\
+-			 BIONIC_DYNAMIC_LINKER)
++			 BIONIC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
+ #define GNU_USER_DYNAMIC_LINKER32					\
+   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, \
+-			 BIONIC_DYNAMIC_LINKER32)
++			 BIONIC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
+ #define GNU_USER_DYNAMIC_LINKER64					\
+   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
+-			 BIONIC_DYNAMIC_LINKER64)
++			 BIONIC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
+ #define GNU_USER_DYNAMIC_LINKERX32					\
+   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \
+-			 BIONIC_DYNAMIC_LINKERX32)
++			 BIONIC_DYNAMIC_LINKERX32, MUSL_DYNAMIC_LINKERX32)
+ 
+ /* Determine whether the entire c99 runtime
+    is present in the runtime library.  */
+diff -r 2b29df135cf0 gcc/config/linux.opt
+--- a/gcc/config/linux.opt	Fri Mar 29 16:41:11 2013 -0400
++++ b/gcc/config/linux.opt	Fri Mar 29 16:41:14 2013 -0400
+@@ -30,3 +30,7 @@
+ muclibc
+ Target Report RejectNegative Var(linux_libc,LIBC_UCLIBC) Negative(mbionic)
+ Use uClibc C library
++
++mmusl
++Target Report RejectNegative Var(linux_libc,LIBC_MUSL) Negative(mglibc)
++Use musl C library
+diff -r 2b29df135cf0 gcc/ginclude/stddef.h
+--- a/gcc/ginclude/stddef.h	Fri Mar 29 16:41:11 2013 -0400
++++ b/gcc/ginclude/stddef.h	Fri Mar 29 16:41:14 2013 -0400
+@@ -181,6 +181,7 @@
+ #ifndef _GCC_SIZE_T
+ #ifndef _SIZET_
+ #ifndef __size_t
++#ifndef __DEFINED_size_t /* musl */
+ #define __size_t__	/* BeOS */
+ #define __SIZE_T__	/* Cray Unicos/Mk */
+ #define _SIZE_T
+@@ -197,6 +198,7 @@
+ #define ___int_size_t_h
+ #define _GCC_SIZE_T
+ #define _SIZET_
++#define __DEFINED_size_t /* musl */
+ #if (defined (__FreeBSD__) && (__FreeBSD__ >= 5)) \
+   || defined(__FreeBSD_kernel__)
+ /* __size_t is a typedef on FreeBSD 5, must not trash it. */
+@@ -214,6 +216,7 @@
+ typedef long ssize_t;
+ #endif /* __BEOS__ */
+ #endif /* !(defined (__GNUG__) && defined (size_t)) */
++#endif /* __DEFINED_size_t */
+ #endif /* __size_t */
+ #endif /* _SIZET_ */
+ #endif /* _GCC_SIZE_T */
+# HG changeset patch
+# Parent 2b94537ce2496c88e7e797c617e5b95e8d7e4785
+A fix for libgomp to correctly request a POSIX version for time support.
+
+diff -r 2b94537ce249 libgomp/config/posix/time.c
+--- a/libgomp/config/posix/time.c	Fri Mar 29 16:41:14 2013 -0400
++++ b/libgomp/config/posix/time.c	Fri Mar 29 16:41:17 2013 -0400
+@@ -28,6 +28,8 @@
+    The following implementation uses the most simple POSIX routines.
+    If present, POSIX 4 clocks should be used instead.  */
+ 
++#define _POSIX_C_SOURCE 199309L /* for clocks */
++
+ #include "libgomp.h"
+ #include <unistd.h>
+ #if TIME_WITH_SYS_TIME
+# HG changeset patch
+# Parent f50bb54f331f73405131a30b4f353cfda1c70304
+Use the generic implementation of libstdc++ primitives when we're on musl, not the glibc one.
+
+diff -r f50bb54f331f libstdc++-v3/configure.host
+--- a/libstdc++-v3/configure.host	Fri Mar 29 16:38:52 2013 -0400
++++ b/libstdc++-v3/configure.host	Fri Mar 29 16:41:10 2013 -0400
+@@ -264,6 +264,13 @@
+     os_include_dir="os/bsd/freebsd"
+     ;;
+   gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu)
++    # check for musl by target
++    case "${host_os}" in
++      *-musl*)
++        os_include_dir="os/generic"
++        ;;
++      *)
++
+     if [ "$uclibc" = "yes" ]; then
+       os_include_dir="os/uclibc"
+     elif [ "$bionic" = "yes" ]; then
+@@ -272,6 +279,9 @@
+       os_include_dir="os/gnu-linux"
+     fi
+     ;;
++
++    esac
++    ;;
+   hpux*)
+     os_include_dir="os/hpux"
+     ;;
+# HG changeset patch
+# Parent 62831d7bf931658019ba16092c48375177d014b1
+Support for mips-linux-musl.
+
+diff -r 62831d7bf931 gcc/config/mips/linux.h
+--- a/gcc/config/mips/linux.h	Fri Mar 29 16:41:23 2013 -0400
++++ b/gcc/config/mips/linux.h	Fri Mar 29 16:41:25 2013 -0400
+@@ -18,3 +18,5 @@
+ <http://www.gnu.org/licenses/>.  */
+ 
+ #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
++
++#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-mips.so.1"
+# HG changeset patch
+# Parent 2ffe76b215fdb082cbbc262536077627757fa9bf
+Support for powerpc-linux-musl.
+
+diff -r 2ffe76b215fd gcc/config.gcc
+--- a/gcc/config.gcc	Fri Mar 29 16:41:26 2013 -0400
++++ b/gcc/config.gcc	Fri Mar 29 16:41:28 2013 -0400
+@@ -2112,6 +2112,10 @@
+ 	    powerpc*-*-linux*paired*)
+ 		tm_file="${tm_file} rs6000/750cl.h" ;;
+ 	esac
++        case ${target} in
++            *-linux*-musl*)
++                enable_secureplt=yes ;;
++        esac
+ 	if test x${enable_secureplt} = xyes; then
+ 		tm_file="rs6000/secureplt.h ${tm_file}"
+ 	fi
+diff -r 2ffe76b215fd gcc/config/rs6000/linux64.h
+--- a/gcc/config/rs6000/linux64.h	Fri Mar 29 16:41:26 2013 -0400
++++ b/gcc/config/rs6000/linux64.h	Fri Mar 29 16:41:28 2013 -0400
+@@ -364,17 +364,21 @@
+ #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld64.so.1"
+ #define UCLIBC_DYNAMIC_LINKER32 "/lib/ld-uClibc.so.0"
+ #define UCLIBC_DYNAMIC_LINKER64 "/lib/ld64-uClibc.so.0"
++#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-powerpc.so.1"
++#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-powerpc64.so.1"
+ #if DEFAULT_LIBC == LIBC_UCLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
+ #elif DEFAULT_LIBC == LIBC_GLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
++#elif DEFAULT_LIBC == LIBC_MUSL
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
+ #else
+ #error "Unsupported DEFAULT_LIBC"
+ #endif
+ #define GNU_USER_DYNAMIC_LINKER32 \
+-  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32)
++  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
+ #define GNU_USER_DYNAMIC_LINKER64 \
+-  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64)
++  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
+ 
+ 
+ #define LINK_OS_LINUX_SPEC32 "-m elf32ppclinux %{!shared: %{!static: \
+diff -r 2ffe76b215fd gcc/config/rs6000/secureplt.h
+--- a/gcc/config/rs6000/secureplt.h	Fri Mar 29 16:41:26 2013 -0400
++++ b/gcc/config/rs6000/secureplt.h	Fri Mar 29 16:41:28 2013 -0400
+@@ -18,3 +18,4 @@
+ <http://www.gnu.org/licenses/>.  */
+ 
+ #define CC1_SECURE_PLT_DEFAULT_SPEC "-msecure-plt"
++#define LINK_SECURE_PLT_DEFAULT_SPEC "--secure-plt"
+diff -r 2ffe76b215fd gcc/config/rs6000/sysv4.h
+--- a/gcc/config/rs6000/sysv4.h	Fri Mar 29 16:41:26 2013 -0400
++++ b/gcc/config/rs6000/sysv4.h	Fri Mar 29 16:41:28 2013 -0400
+@@ -551,6 +551,9 @@
+ #ifndef CC1_SECURE_PLT_DEFAULT_SPEC
+ #define CC1_SECURE_PLT_DEFAULT_SPEC ""
+ #endif
++#ifndef LINK_SECURE_PLT_DEFAULT_SPEC
++#define LINK_SECURE_PLT_DEFAULT_SPEC ""
++#endif
+ 
+ /* Pass -G xxx to the compiler and set correct endian mode.  */
+ #define	CC1_SPEC "%{G*} %(cc1_cpu) \
+@@ -611,7 +614,8 @@
+ %{mlittle: --oformat elf32-powerpcle } %{mlittle-endian: --oformat elf32-powerpcle } \
+ %{!mlittle: %{!mlittle-endian: %{!mbig: %{!mbig-endian: \
+     %{mcall-i960-old: --oformat elf32-powerpcle} \
+-  }}}}"
++  }}}} \
++%{!mbss-plt: %{!msecure-plt: %(link_secure_plt_default)}}"
+ 
+ /* Any specific OS flags.  */
+ #define LINK_OS_SPEC "\
+@@ -789,15 +793,18 @@
+ 
+ #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
+ #define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0"
++#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-powerpc.so.1"
+ #if DEFAULT_LIBC == LIBC_UCLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
++#elif DEFAULT_LIBC == LIBC_MUSL
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
+ #elif !defined (DEFAULT_LIBC) || DEFAULT_LIBC == LIBC_GLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
+ #else
+ #error "Unsupported DEFAULT_LIBC"
+ #endif
+ #define GNU_USER_DYNAMIC_LINKER \
+-  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER)
++  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
+ 
+ #define LINK_OS_LINUX_SPEC "-m elf32ppclinux %{!shared: %{!static: \
+   %{rdynamic:-export-dynamic} \
+@@ -923,6 +930,7 @@
+   { "cc1_endian_little",	CC1_ENDIAN_LITTLE_SPEC },		\
+   { "cc1_endian_default",	CC1_ENDIAN_DEFAULT_SPEC },		\
+   { "cc1_secure_plt_default",	CC1_SECURE_PLT_DEFAULT_SPEC },		\
++  { "link_secure_plt_default",	LINK_SECURE_PLT_DEFAULT_SPEC },		\
+   { "cpp_os_ads",		CPP_OS_ADS_SPEC },			\
+   { "cpp_os_yellowknife",	CPP_OS_YELLOWKNIFE_SPEC },		\
+   { "cpp_os_mvme",		CPP_OS_MVME_SPEC },			\
+diff -r 2ffe76b215fd libgcc/config/rs6000/linux-unwind.h
+--- a/libgcc/config/rs6000/linux-unwind.h	Fri Mar 29 16:41:26 2013 -0400
++++ b/libgcc/config/rs6000/linux-unwind.h	Fri Mar 29 16:41:28 2013 -0400
+@@ -258,6 +258,7 @@
+ 
+   return _URC_NO_REASON;
+ }
++#endif
+ 
+ #define MD_FROB_UPDATE_CONTEXT frob_update_context
+ 
+# HG changeset patch
+# Parent 3ea10cd626cb7abdfd56d3fe8d2c9ed58a82797b
+Support for i386-linux-musl and x86_64-linux-musl.
+
+diff -r 3ea10cd626cb gcc/config/i386/linux.h
+--- a/gcc/config/i386/linux.h	Fri Mar 29 16:41:17 2013 -0400
++++ b/gcc/config/i386/linux.h	Fri Mar 29 16:41:20 2013 -0400
+@@ -21,3 +21,4 @@
+ 
+ #define GNU_USER_LINK_EMULATION "elf_i386"
+ #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
++#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-i386.so.1"
+diff -r 3ea10cd626cb gcc/config/i386/linux64.h
+--- a/gcc/config/i386/linux64.h	Fri Mar 29 16:41:17 2013 -0400
++++ b/gcc/config/i386/linux64.h	Fri Mar 29 16:41:20 2013 -0400
+@@ -30,3 +30,7 @@
+ #define GLIBC_DYNAMIC_LINKER32 "/lib/ld-linux.so.2"
+ #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-linux-x86-64.so.2"
+ #define GLIBC_DYNAMIC_LINKERX32 "/libx32/ld-linux-x32.so.2"
++
++#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-i386.so.1"
++#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-x86_64.so.1"
++#define MUSL_DYNAMIC_LINKERX32 "/lib/ld-musl-x32.so.1"
+diff -r 3ea10cd626cb libitm/config/linux/x86/tls.h
+--- a/libitm/config/linux/x86/tls.h	Fri Mar 29 16:41:17 2013 -0400
++++ b/libitm/config/linux/x86/tls.h	Fri Mar 29 16:41:20 2013 -0400
+@@ -25,16 +25,19 @@
+ #ifndef LIBITM_X86_TLS_H
+ #define LIBITM_X86_TLS_H 1
+ 
+-#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
++#if defined(__GLIBC_PREREQ)
++#if __GLIBC_PREREQ(2, 10)
+ /* Use slots in the TCB head rather than __thread lookups.
+    GLIBC has reserved words 10 through 13 for TM.  */
+ #define HAVE_ARCH_GTM_THREAD 1
+ #define HAVE_ARCH_GTM_THREAD_DISP 1
+ #endif
++#endif
+ 
+ #include "config/generic/tls.h"
+ 
+-#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
++#if defined(__GLIBC_PREREQ)
++#if __GLIBC_PREREQ(2, 10)
+ namespace GTM HIDDEN {
+ 
+ #ifdef __x86_64__
+@@ -101,5 +104,6 @@
+ 
+ } // namespace GTM
+ #endif /* >= GLIBC 2.10 */
++#endif
+ 
+ #endif // LIBITM_X86_TLS_H
diff --git a/patches/experimental/gcc/4.8.1/0001-musl.patch b/patches/experimental/gcc/4.8.1/0001-musl.patch
new file mode 100644
index 0000000..2c1c0d3
--- /dev/null
+++ b/patches/experimental/gcc/4.8.1/0001-musl.patch
@@ -0,0 +1,626 @@
+This patch enables support for musl-libc in gcc.
+
+This patch is not supported by crosstool-ng and was originally found here:
+    https://bitbucket.org/GregorR/musl-cross/src/27953a1f7085/patches/gcc-4.8.1-musl.diff
+
+Added-By: Bryan Hundven <bryanhundven@gmail.com>
+---
+diff -r f50bb54f331f libstdc++-v3/configure.host
+--- a/libstdc++-v3/configure.host	Fri Mar 29 16:38:52 2013 -0400
++++ b/libstdc++-v3/configure.host	Fri Mar 29 16:41:10 2013 -0400
+@@ -264,6 +264,13 @@
+     os_include_dir="os/bsd/freebsd"
+     ;;
+   gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu)
++    # check for musl by target
++    case "${host_os}" in
++      *-musl*)
++        os_include_dir="os/generic"
++        ;;
++      *)
++
+     if [ "$uclibc" = "yes" ]; then
+       os_include_dir="os/uclibc"
+     elif [ "$bionic" = "yes" ]; then
+@@ -272,6 +279,9 @@
+       os_include_dir="os/gnu-linux"
+     fi
+     ;;
++
++    esac
++    ;;
+   hpux*)
+     os_include_dir="os/hpux"
+     ;;
+# HG changeset patch
+# Parent 572f7b4d1c50cefde3aa2c43d06040fc308ad989
+Adding -mmusl as a musl libc specifier, and the necessary hacks for it to know how to find musl's dynamic linker.
+
+diff -r 572f7b4d1c50 gcc/config.gcc
+--- a/gcc/config.gcc	Sun Sep 08 22:58:18 2013 -0400
++++ b/gcc/config.gcc	Mon Sep 09 12:48:34 2013 -0400
+@@ -549,7 +549,7 @@
+ esac
+ 
+ # Common C libraries.
+-tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3"
++tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3 LIBC_MUSL=4"
+ 
+ # Common parts for widely ported systems.
+ case ${target} in
+@@ -652,6 +652,9 @@
+     *-*-*uclibc*)
+       tm_defines="$tm_defines DEFAULT_LIBC=LIBC_UCLIBC"
+       ;;
++    *-*-*musl*)
++      tm_defines="$tm_defines DEFAULT_LIBC=LIBC_MUSL"
++      ;;
+     *)
+       tm_defines="$tm_defines DEFAULT_LIBC=LIBC_GLIBC"
+       ;;
+diff -r 572f7b4d1c50 gcc/config/linux.h
+--- a/gcc/config/linux.h	Sun Sep 08 22:58:18 2013 -0400
++++ b/gcc/config/linux.h	Mon Sep 09 12:48:34 2013 -0400
+@@ -32,10 +32,12 @@
+ #define OPTION_GLIBC  (DEFAULT_LIBC == LIBC_GLIBC)
+ #define OPTION_UCLIBC (DEFAULT_LIBC == LIBC_UCLIBC)
+ #define OPTION_BIONIC (DEFAULT_LIBC == LIBC_BIONIC)
++#define OPTION_MUSL   (DEFAULT_LIBC == LIBC_MUSL)
+ #else
+ #define OPTION_GLIBC  (linux_libc == LIBC_GLIBC)
+ #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
+ #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
++#define OPTION_MUSL   (linux_libc == LIBC_MUSL)
+ #endif
+ 
+ #define GNU_USER_TARGET_OS_CPP_BUILTINS()			\
+@@ -53,18 +55,21 @@
+    uClibc or Bionic is the default C library and whether
+    -muclibc or -mglibc or -mbionic has been passed to change the default.  */
+ 
+-#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LD1, LD2, LD3)	\
+-  "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:" LD1 "}}"
++#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LIBC4, LD1, LD2, LD3, LD4)	\
++  "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:%{" LIBC4 ":" LD4 ";:" LD1 "}}}"
+ 
+ #if DEFAULT_LIBC == LIBC_GLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
+-  CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", G, U, B)
++#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
++  CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", "mmusl", G, U, B, M)
+ #elif DEFAULT_LIBC == LIBC_UCLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
+-  CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", U, G, B)
++#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
++  CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", "mmusl", U, G, B, M)
+ #elif DEFAULT_LIBC == LIBC_BIONIC
+-#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
+-  CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", B, G, U)
++#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
++  CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", "mmusl", B, G, U, M)
++#elif DEFAULT_LIBC == LIBC_MUSL
++#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
++  CHOOSE_DYNAMIC_LINKER1 ("mmusl", "mglibc", "muclibc", "mbionic", M, G, U, B)
+ #else
+ #error "Unsupported DEFAULT_LIBC"
+ #endif /* DEFAULT_LIBC */
+@@ -84,21 +89,21 @@
+ 
+ #define GNU_USER_DYNAMIC_LINKER						\
+   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER,	\
+-			 BIONIC_DYNAMIC_LINKER)
++			 BIONIC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
+ #define GNU_USER_DYNAMIC_LINKER32					\
+   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, \
+-			 BIONIC_DYNAMIC_LINKER32)
++			 BIONIC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
+ #define GNU_USER_DYNAMIC_LINKER64					\
+   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
+-			 BIONIC_DYNAMIC_LINKER64)
++			 BIONIC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
+ #define GNU_USER_DYNAMIC_LINKERX32					\
+   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \
+-			 BIONIC_DYNAMIC_LINKERX32)
++			 BIONIC_DYNAMIC_LINKERX32, MUSL_DYNAMIC_LINKERX32)
+ 
+ /* Determine whether the entire c99 runtime
+    is present in the runtime library.  */
+ #undef TARGET_C99_FUNCTIONS
+-#define TARGET_C99_FUNCTIONS (OPTION_GLIBC)
++#define TARGET_C99_FUNCTIONS (OPTION_GLIBC || OPTION_MUSL)
+ 
+ /* Whether we have sincos that follows the GNU extension.  */
+ #undef TARGET_HAS_SINCOS
+@@ -107,3 +112,74 @@
+ /* Whether we have Bionic libc runtime */
+ #undef TARGET_HAS_BIONIC
+ #define TARGET_HAS_BIONIC (OPTION_BIONIC)
++
++/* musl avoids problematic includes by rearranging the include directories.
++ * Unfortunately, this is mostly duplicated from cppdefault.c */
++#if DEFAULT_LIBC == LIBC_MUSL
++#define INCLUDE_DEFAULTS_MUSL_GPP			\
++    { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1,		\
++      GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },		\
++    { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1,		\
++      GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 },		\
++    { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1,	\
++      GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },
++
++#ifdef LOCAL_INCLUDE_DIR
++#define INCLUDE_DEFAULTS_MUSL_LOCAL			\
++    { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 },		\
++    { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 },
++#else
++#define INCLUDE_DEFAULTS_MUSL_LOCAL
++#endif
++
++#ifdef PREFIX_INCLUDE_DIR
++#define INCLUDE_DEFAULTS_MUSL_PREFIX			\
++    { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0},
++#else
++#define INCLUDE_DEFAULTS_MUSL_PREFIX
++#endif
++
++#ifdef CROSS_INCLUDE_DIR
++#define INCLUDE_DEFAULTS_MUSL_CROSS			\
++    { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0},
++#else
++#define INCLUDE_DEFAULTS_MUSL_CROSS
++#endif
++
++#ifdef TOOL_INCLUDE_DIR
++#define INCLUDE_DEFAULTS_MUSL_TOOL			\
++    { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0},
++#else
++#define INCLUDE_DEFAULTS_MUSL_TOOL
++#endif
++
++#ifdef NATIVE_SYSTEM_HEADER_DIR
++#define INCLUDE_DEFAULTS_MUSL_NATIVE			\
++    { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 2 },	\
++    { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 0 },
++#else
++#define INCLUDE_DEFAULTS_MUSL_NATIVE
++#endif
++
++#if defined (CROSS_DIRECTORY_STRUCTURE) && !defined (TARGET_SYSTEM_ROOT)
++# undef INCLUDE_DEFAULTS_MUSL_LOCAL
++# define INCLUDE_DEFAULTS_MUSL_LOCAL
++# undef INCLUDE_DEFAULTS_MUSL_NATIVE
++# define INCLUDE_DEFAULTS_MUSL_NATIVE
++#else
++# undef INCLUDE_DEFAULTS_MUSL_CROSS
++# define INCLUDE_DEFAULTS_MUSL_CROSS
++#endif
++
++#undef INCLUDE_DEFAULTS
++#define INCLUDE_DEFAULTS				\
++  {							\
++    INCLUDE_DEFAULTS_MUSL_GPP				\
++    INCLUDE_DEFAULTS_MUSL_PREFIX			\
++    INCLUDE_DEFAULTS_MUSL_CROSS				\
++    INCLUDE_DEFAULTS_MUSL_TOOL				\
++    INCLUDE_DEFAULTS_MUSL_NATIVE			\
++    { GCC_INCLUDE_DIR, "GCC", 0, 1, 0, 0 },		\
++    { 0, 0, 0, 0, 0, 0 }				\
++  }
++#endif
+diff -r 572f7b4d1c50 gcc/config/linux.opt
+--- a/gcc/config/linux.opt	Sun Sep 08 22:58:18 2013 -0400
++++ b/gcc/config/linux.opt	Mon Sep 09 12:48:34 2013 -0400
+@@ -30,3 +30,7 @@
+ muclibc
+ Target Report RejectNegative Var(linux_libc,LIBC_UCLIBC) Negative(mbionic)
+ Use uClibc C library
++
++mmusl
++Target Report RejectNegative Var(linux_libc,LIBC_MUSL) Negative(mglibc)
++Use musl C library
+diff -r 572f7b4d1c50 gcc/ginclude/stddef.h
+--- a/gcc/ginclude/stddef.h	Sun Sep 08 22:58:18 2013 -0400
++++ b/gcc/ginclude/stddef.h	Mon Sep 09 12:48:34 2013 -0400
+@@ -181,6 +181,7 @@
+ #ifndef _GCC_SIZE_T
+ #ifndef _SIZET_
+ #ifndef __size_t
++#ifndef __DEFINED_size_t /* musl */
+ #define __size_t__	/* BeOS */
+ #define __SIZE_T__	/* Cray Unicos/Mk */
+ #define _SIZE_T
+@@ -197,6 +198,7 @@
+ #define ___int_size_t_h
+ #define _GCC_SIZE_T
+ #define _SIZET_
++#define __DEFINED_size_t /* musl */
+ #if (defined (__FreeBSD__) && (__FreeBSD__ >= 5)) \
+   || defined(__FreeBSD_kernel__)
+ /* __size_t is a typedef on FreeBSD 5, must not trash it. */
+@@ -214,6 +216,7 @@
+ typedef long ssize_t;
+ #endif /* __BEOS__ */
+ #endif /* !(defined (__GNUG__) && defined (size_t)) */
++#endif /* __DEFINED_size_t */
+ #endif /* __size_t */
+ #endif /* _SIZET_ */
+ #endif /* _GCC_SIZE_T */
+# HG changeset patch
+# Parent 2b94537ce2496c88e7e797c617e5b95e8d7e4785
+A fix for libgomp to correctly request a POSIX version for time support.
+
+diff -r 2b94537ce249 libgomp/config/posix/time.c
+--- a/libgomp/config/posix/time.c	Fri Mar 29 16:41:14 2013 -0400
++++ b/libgomp/config/posix/time.c	Fri Mar 29 16:41:17 2013 -0400
+@@ -28,6 +28,8 @@
+    The following implementation uses the most simple POSIX routines.
+    If present, POSIX 4 clocks should be used instead.  */
+ 
++#define _POSIX_C_SOURCE 199309L /* for clocks */
++
+ #include "libgomp.h"
+ #include <unistd.h>
+ #if TIME_WITH_SYS_TIME
+diff -r 7cba4201a2ae libgcc/unwind-dw2-fde-dip.c
+--- a/libgcc/unwind-dw2-fde-dip.c	Sat Jul 27 22:53:05 2013 -0400
++++ b/libgcc/unwind-dw2-fde-dip.c	Sat Jul 27 22:57:08 2013 -0400
+@@ -46,33 +46,13 @@
+ #include "unwind-compat.h"
+ #include "gthr.h"
+ 
+-#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
+-    && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) \
+-	|| (__GLIBC__ == 2 && __GLIBC_MINOR__ == 2 && defined(DT_CONFIG)))
++#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) && defined(TARGET_DL_ITERATE_PHDR)
+ # define USE_PT_GNU_EH_FRAME
+-#endif
+-
+-#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
+-    && defined(__BIONIC__)
+-# define USE_PT_GNU_EH_FRAME
+-#endif
+-
+-#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
+-    && defined(__FreeBSD__) && __FreeBSD__ >= 7
+-# define ElfW __ElfN
+-# define USE_PT_GNU_EH_FRAME
+-#endif
+-
+-#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
+-    && defined(__OpenBSD__)
+-# define ElfW(type) Elf_##type
+-# define USE_PT_GNU_EH_FRAME
+-#endif
+-
+-#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
+-    && defined(TARGET_DL_ITERATE_PHDR) \
+-    && defined(__sun__) && defined(__svr4__)
+-# define USE_PT_GNU_EH_FRAME
++# ifdef __OpenBSD__
++#  define ElfW(type) Elf_##typ
++# elif defined(__FreeBSD__) && __FreeBSD__ >= 7
++#  define ElfW __ElfN
++# endif
+ #endif
+ 
+ #if defined(USE_PT_GNU_EH_FRAME)
+diff -r 75d9c38318a7 gcc/configure
+--- a/gcc/configure	Tue Sep 24 06:52:49 2013 -0400
++++ b/gcc/configure	Tue Sep 24 06:54:33 2013 -0400
+@@ -26736,6 +26736,9 @@
+ else
+   gcc_cv_libc_provides_ssp=no
+     case "$target" in
++       *-*-musl*)
++         # All versions of musl provide stack protector
++	 gcc_cv_libc_provides_ssp=yes;;
+        *-*-linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu)
+       # glibc 2.4 and later provides __stack_chk_fail and
+       # either __stack_chk_guard, or TLS access to stack guard canary.
+@@ -26769,6 +26772,7 @@
+ 	 # <http://gcc.gnu.org/ml/gcc/2008-10/msg00130.html>) and for now
+ 	 # simply assert that glibc does provide this, which is true for all
+ 	 # realistically usable GNU/Hurd configurations.
++	 # All supported versions of musl provide it as well
+ 	 gcc_cv_libc_provides_ssp=yes;;
+        *-*-darwin* | *-*-freebsd*)
+ 	 ac_fn_c_check_func "$LINENO" "__stack_chk_fail" "ac_cv_func___stack_chk_fail"
+@@ -26851,6 +26855,9 @@
+       gcc_cv_target_dl_iterate_phdr=no
+     fi
+     ;;
++  *-linux-musl*)
++    gcc_cv_target_dl_iterate_phdr=yes
++    ;;
+ esac
+ 
+ if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
+diff -r 75d9c38318a7 gcc/configure.ac
+--- a/gcc/configure.ac	Tue Sep 24 06:52:49 2013 -0400
++++ b/gcc/configure.ac	Tue Sep 24 06:54:33 2013 -0400
+@@ -4719,6 +4719,9 @@
+       gcc_cv_libc_provides_ssp,
+       [gcc_cv_libc_provides_ssp=no
+     case "$target" in
++       *-*-musl*)
++         # All versions of musl provide stack protector
++	 gcc_cv_libc_provides_ssp=yes;;
+        *-*-linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu)
+       [# glibc 2.4 and later provides __stack_chk_fail and
+       # either __stack_chk_guard, or TLS access to stack guard canary.
+@@ -4752,6 +4755,7 @@
+ 	 # <http://gcc.gnu.org/ml/gcc/2008-10/msg00130.html>) and for now
+ 	 # simply assert that glibc does provide this, which is true for all
+ 	 # realistically usable GNU/Hurd configurations.
++	 # All supported versions of musl provide it as well
+ 	 gcc_cv_libc_provides_ssp=yes;;
+        *-*-darwin* | *-*-freebsd*)
+ 	 AC_CHECK_FUNC(__stack_chk_fail,[gcc_cv_libc_provides_ssp=yes],
+@@ -4817,6 +4821,9 @@
+       gcc_cv_target_dl_iterate_phdr=no
+     fi
+     ;;
++  *-linux-musl*)
++    gcc_cv_target_dl_iterate_phdr=yes
++    ;;
+ esac
+ GCC_TARGET_TEMPLATE([TARGET_DL_ITERATE_PHDR])
+ if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
+# HG changeset patch
+# Parent 94e435662aff38e86c9ca0dff4bbf451e0190b34
+Get rid of ever-broken fixincludes on musl.
+
+
+diff -r 94e435662aff -r e27957848dc8 fixincludes/mkfixinc.sh
+--- a/fixincludes/mkfixinc.sh	Sat Jul 27 23:37:20 2013 -0400
++++ b/fixincludes/mkfixinc.sh	Sat Jul 27 23:43:03 2013 -0400
+@@ -19,7 +19,8 @@
+     powerpc-*-eabi*    | \
+     powerpc-*-rtems*   | \
+     powerpcle-*-eabisim* | \
+-    powerpcle-*-eabi* )
++    powerpcle-*-eabi* | \
++    *-musl* )
+ 	#  IF there is no include fixing,
+ 	#  THEN create a no-op fixer and exit
+ 	(echo "#! /bin/sh" ; echo "exit 0" ) > ${target}
+# HG changeset patch
+# Parent 3ea10cd626cb7abdfd56d3fe8d2c9ed58a82797b
+Support for i386-linux-musl and x86_64-linux-musl.
+
+diff -r 3ea10cd626cb gcc/config/i386/linux.h
+--- a/gcc/config/i386/linux.h	Fri Mar 29 16:41:17 2013 -0400
++++ b/gcc/config/i386/linux.h	Fri Mar 29 16:41:20 2013 -0400
+@@ -21,3 +21,4 @@
+ 
+ #define GNU_USER_LINK_EMULATION "elf_i386"
+ #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
++#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-i386.so.1"
+diff -r 3ea10cd626cb gcc/config/i386/linux64.h
+--- a/gcc/config/i386/linux64.h	Fri Mar 29 16:41:17 2013 -0400
++++ b/gcc/config/i386/linux64.h	Fri Mar 29 16:41:20 2013 -0400
+@@ -30,3 +30,7 @@
+ #define GLIBC_DYNAMIC_LINKER32 "/lib/ld-linux.so.2"
+ #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-linux-x86-64.so.2"
+ #define GLIBC_DYNAMIC_LINKERX32 "/libx32/ld-linux-x32.so.2"
++
++#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-i386.so.1"
++#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-x86_64.so.1"
++#define MUSL_DYNAMIC_LINKERX32 "/lib/ld-musl-x32.so.1"
+diff -r 3ea10cd626cb libitm/config/linux/x86/tls.h
+--- a/libitm/config/linux/x86/tls.h	Fri Mar 29 16:41:17 2013 -0400
++++ b/libitm/config/linux/x86/tls.h	Fri Mar 29 16:41:20 2013 -0400
+@@ -25,16 +25,19 @@
+ #ifndef LIBITM_X86_TLS_H
+ #define LIBITM_X86_TLS_H 1
+ 
+-#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
++#if defined(__GLIBC_PREREQ)
++#if __GLIBC_PREREQ(2, 10)
+ /* Use slots in the TCB head rather than __thread lookups.
+    GLIBC has reserved words 10 through 13 for TM.  */
+ #define HAVE_ARCH_GTM_THREAD 1
+ #define HAVE_ARCH_GTM_THREAD_DISP 1
+ #endif
++#endif
+ 
+ #include "config/generic/tls.h"
+ 
+-#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
++#if defined(__GLIBC_PREREQ)
++#if __GLIBC_PREREQ(2, 10)
+ namespace GTM HIDDEN {
+ 
+ #ifdef __x86_64__
+@@ -101,5 +104,6 @@
+ 
+ } // namespace GTM
+ #endif /* >= GLIBC 2.10 */
++#endif
+ 
+ #endif // LIBITM_X86_TLS_H
+# HG changeset patch
+# Parent c3eb69047e35491fda9cd9ab1ee2ace1299c793c
+Support for arm-linux-musl.
+
+diff -r c3eb69047e35 gcc/config/arm/linux-eabi.h
+--- a/gcc/config/arm/linux-eabi.h	Thu Sep 19 07:11:38 2013 -0400
++++ b/gcc/config/arm/linux-eabi.h	Thu Sep 19 08:56:47 2013 -0400
+@@ -77,6 +77,23 @@
+     %{mfloat-abi=soft*:" GLIBC_DYNAMIC_LINKER_SOFT_FLOAT "} \
+     %{!mfloat-abi=*:" GLIBC_DYNAMIC_LINKER_DEFAULT "}"
+ 
++/* For ARM musl currently supports four dynamic linkers:
++   - ld-musl-arm.so.1 - for the EABI-derived soft-float ABI
++   - ld-musl-armhf.so.1 - for the EABI-derived hard-float ABI
++   - ld-musl-armeb.so.1 - for the EABI-derived soft-float ABI, EB
++   - ld-musl-armebhf.so.1 - for the EABI-derived hard-float ABI, EB
++   musl does not support the legacy OABI mode.
++   All the dynamic linkers live in /lib.
++   We default to soft-float, EL. */
++#undef  MUSL_DYNAMIC_LINKER
++#if TARGET_BIG_ENDIAN_DEFAULT
++#define MUSL_DYNAMIC_LINKER_E "%{mlittle-endian:;:eb}"
++#else
++#define MUSL_DYNAMIC_LINKER_E "%{mbig-endian:eb}"
++#endif
++#define MUSL_DYNAMIC_LINKER \
++  "/lib/ld-musl-arm" MUSL_DYNAMIC_LINKER_E "%{mfloat-abi=hard:hf}.so.1"
++
+ /* At this point, bpabi.h will have clobbered LINK_SPEC.  We want to
+    use the GNU/Linux version, not the generic BPABI version.  */
+ #undef  LINK_SPEC
+diff -r c3eb69047e35 libitm/config/arm/hwcap.cc
+--- a/libitm/config/arm/hwcap.cc	Thu Sep 19 07:11:38 2013 -0400
++++ b/libitm/config/arm/hwcap.cc	Thu Sep 19 08:56:47 2013 -0400
+@@ -40,7 +40,11 @@
+ 
+ #ifdef __linux__
+ #include <unistd.h>
++#ifdef __GLIBC__
+ #include <sys/fcntl.h>
++#else
++#include <fcntl.h>
++#endif
+ #include <elf.h>
+ 
+ static void __attribute__((constructor))
+# HG changeset patch
+# Parent 4618ad6f036f1e944a5262ae5875dcdf62c41f8b
+Support for mips-linux-musl.
+
+diff -r 4618ad6f036f gcc/config/mips/linux.h
+--- a/gcc/config/mips/linux.h	Thu Sep 19 08:56:47 2013 -0400
++++ b/gcc/config/mips/linux.h	Thu Sep 19 09:08:11 2013 -0400
+@@ -18,3 +18,10 @@
+ <http://www.gnu.org/licenses/>.  */
+ 
+ #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
++
++#if TARGET_ENDIAN_DEFAULT == 0 /* LE */
++#define MUSL_DYNAMIC_LINKER_E "%{EB:;:el}"
++#else
++#define MUSL_DYNAMIC_LINKER_E "%{EL:el}"
++#endif
++#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-mips" MUSL_DYNAMIC_LINKER_E ".so.1"
+# HG changeset patch
+# Parent 2ffe76b215fdb082cbbc262536077627757fa9bf
+Support for powerpc-linux-musl.
+
+diff -r 2ffe76b215fd gcc/config.gcc
+--- a/gcc/config.gcc	Fri Mar 29 16:41:26 2013 -0400
++++ b/gcc/config.gcc	Fri Mar 29 16:41:28 2013 -0400
+@@ -2112,6 +2112,10 @@
+ 	    powerpc*-*-linux*paired*)
+ 		tm_file="${tm_file} rs6000/750cl.h" ;;
+ 	esac
++        case ${target} in
++            *-linux*-musl*)
++                enable_secureplt=yes ;;
++        esac
+ 	if test x${enable_secureplt} = xyes; then
+ 		tm_file="rs6000/secureplt.h ${tm_file}"
+ 	fi
+diff -r 2ffe76b215fd gcc/config/rs6000/linux64.h
+--- a/gcc/config/rs6000/linux64.h	Fri Mar 29 16:41:26 2013 -0400
++++ b/gcc/config/rs6000/linux64.h	Fri Mar 29 16:41:28 2013 -0400
+@@ -364,17 +364,21 @@
+ #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld64.so.1"
+ #define UCLIBC_DYNAMIC_LINKER32 "/lib/ld-uClibc.so.0"
+ #define UCLIBC_DYNAMIC_LINKER64 "/lib/ld64-uClibc.so.0"
++#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-powerpc.so.1"
++#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-powerpc64.so.1"
+ #if DEFAULT_LIBC == LIBC_UCLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
+ #elif DEFAULT_LIBC == LIBC_GLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
++#elif DEFAULT_LIBC == LIBC_MUSL
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
+ #else
+ #error "Unsupported DEFAULT_LIBC"
+ #endif
+ #define GNU_USER_DYNAMIC_LINKER32 \
+-  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32)
++  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
+ #define GNU_USER_DYNAMIC_LINKER64 \
+-  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64)
++  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
+ 
+ 
+ #define LINK_OS_LINUX_SPEC32 "-m elf32ppclinux %{!shared: %{!static: \
+diff -r 2ffe76b215fd gcc/config/rs6000/secureplt.h
+--- a/gcc/config/rs6000/secureplt.h	Fri Mar 29 16:41:26 2013 -0400
++++ b/gcc/config/rs6000/secureplt.h	Fri Mar 29 16:41:28 2013 -0400
+@@ -18,3 +18,4 @@
+ <http://www.gnu.org/licenses/>.  */
+ 
+ #define CC1_SECURE_PLT_DEFAULT_SPEC "-msecure-plt"
++#define LINK_SECURE_PLT_DEFAULT_SPEC "--secure-plt"
+diff -r 2ffe76b215fd gcc/config/rs6000/sysv4.h
+--- a/gcc/config/rs6000/sysv4.h	Fri Mar 29 16:41:26 2013 -0400
++++ b/gcc/config/rs6000/sysv4.h	Fri Mar 29 16:41:28 2013 -0400
+@@ -551,6 +551,9 @@
+ #ifndef CC1_SECURE_PLT_DEFAULT_SPEC
+ #define CC1_SECURE_PLT_DEFAULT_SPEC ""
+ #endif
++#ifndef LINK_SECURE_PLT_DEFAULT_SPEC
++#define LINK_SECURE_PLT_DEFAULT_SPEC ""
++#endif
+ 
+ /* Pass -G xxx to the compiler and set correct endian mode.  */
+ #define	CC1_SPEC "%{G*} %(cc1_cpu) \
+@@ -611,7 +614,8 @@
+ %{mlittle: --oformat elf32-powerpcle } %{mlittle-endian: --oformat elf32-powerpcle } \
+ %{!mlittle: %{!mlittle-endian: %{!mbig: %{!mbig-endian: \
+     %{mcall-i960-old: --oformat elf32-powerpcle} \
+-  }}}}"
++  }}}} \
++%{!mbss-plt: %{!msecure-plt: %(link_secure_plt_default)}}"
+ 
+ /* Any specific OS flags.  */
+ #define LINK_OS_SPEC "\
+@@ -789,15 +793,18 @@
+ 
+ #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
+ #define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0"
++#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-powerpc.so.1"
+ #if DEFAULT_LIBC == LIBC_UCLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
++#elif DEFAULT_LIBC == LIBC_MUSL
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
+ #elif !defined (DEFAULT_LIBC) || DEFAULT_LIBC == LIBC_GLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
+ #else
+ #error "Unsupported DEFAULT_LIBC"
+ #endif
+ #define GNU_USER_DYNAMIC_LINKER \
+-  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER)
++  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
+ 
+ #define LINK_OS_LINUX_SPEC "-m elf32ppclinux %{!shared: %{!static: \
+   %{rdynamic:-export-dynamic} \
+@@ -923,6 +930,7 @@
+   { "cc1_endian_little",	CC1_ENDIAN_LITTLE_SPEC },		\
+   { "cc1_endian_default",	CC1_ENDIAN_DEFAULT_SPEC },		\
+   { "cc1_secure_plt_default",	CC1_SECURE_PLT_DEFAULT_SPEC },		\
++  { "link_secure_plt_default",	LINK_SECURE_PLT_DEFAULT_SPEC },		\
+   { "cpp_os_ads",		CPP_OS_ADS_SPEC },			\
+   { "cpp_os_yellowknife",	CPP_OS_YELLOWKNIFE_SPEC },		\
+   { "cpp_os_mvme",		CPP_OS_MVME_SPEC },			\
+--- a/gcc/config/aarch64/aarch64-linux.h	2013-01-10 21:38:27.000000000 +0100
++++ b/gcc/config/aarch64/aarch64-linux.h	2013-09-12 21:39:34.004829498 +0200
+@@ -21,7 +21,11 @@
+ #ifndef GCC_AARCH64_LINUX_H
+ #define GCC_AARCH64_LINUX_H
+ 
++/* The AArch64 port currently supports two dynamic linkers:
++   - ld-linux-aarch64.so.1 - GLIBC dynamic linker
++   - ld-musl-aarch64.so.1 - musl libc dynamic linker  */
+ #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux-aarch64.so.1"
++#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-aarch64.so.1"
+ 
+ #define LINUX_TARGET_LINK_SPEC  "%{h*}		\
+    %{static:-Bstatic}				\
diff --git a/patches/experimental/gcc/4.8.2/0001-musl.patch b/patches/experimental/gcc/4.8.2/0001-musl.patch
new file mode 100644
index 0000000..3ff2e30
--- /dev/null
+++ b/patches/experimental/gcc/4.8.2/0001-musl.patch
@@ -0,0 +1,750 @@
+This patch enables support for musl-libc in gcc.
+
+This patch is not supported by crosstool-ng and was originally found here:
+    https://bitbucket.org/GregorR/musl-cross/src/27953a1f7085/patches/gcc-4.8.2-musl.diff
+
+Added-By: Bryan Hundven <bryanhundven@gmail.com>
+---
+diff -r df1a439b9058 libstdc++-v3/configure.host
+--- a/libstdc++-v3/configure.host	Tue Dec 31 14:52:24 2013 -0500
++++ b/libstdc++-v3/configure.host	Tue Dec 31 14:54:49 2013 -0500
+@@ -264,6 +264,13 @@
+     os_include_dir="os/bsd/freebsd"
+     ;;
+   gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu)
++    # check for musl by target
++    case "${host_os}" in
++      *-musl*)
++        os_include_dir="os/generic"
++        ;;
++      *)
++
+     if [ "$uclibc" = "yes" ]; then
+       os_include_dir="os/uclibc"
+     elif [ "$bionic" = "yes" ]; then
+@@ -272,6 +279,9 @@
+       os_include_dir="os/gnu-linux"
+     fi
+     ;;
++
++    esac
++    ;;
+   hpux*)
+     os_include_dir="os/hpux"
+     ;;
+# HG changeset patch
+# Parent e5b4564f249f8634194bdabef4b3057d0e54ee97
+Adding -mmusl as a musl libc specifier, and the necessary hacks for it to know how to find musl's dynamic linker.
+
+diff -r e5b4564f249f gcc/config.gcc
+--- a/gcc/config.gcc	Tue Dec 31 14:54:49 2013 -0500
++++ b/gcc/config.gcc	Tue Dec 31 14:54:52 2013 -0500
+@@ -550,7 +550,7 @@
+ esac
+ 
+ # Common C libraries.
+-tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3"
++tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3 LIBC_MUSL=4"
+ 
+ # Common parts for widely ported systems.
+ case ${target} in
+@@ -653,6 +653,9 @@
+     *-*-*uclibc*)
+       tm_defines="$tm_defines DEFAULT_LIBC=LIBC_UCLIBC"
+       ;;
++    *-*-*musl*)
++      tm_defines="$tm_defines DEFAULT_LIBC=LIBC_MUSL"
++      ;;
+     *)
+       tm_defines="$tm_defines DEFAULT_LIBC=LIBC_GLIBC"
+       ;;
+diff -r e5b4564f249f gcc/config/linux.h
+--- a/gcc/config/linux.h	Tue Dec 31 14:54:49 2013 -0500
++++ b/gcc/config/linux.h	Tue Dec 31 14:54:52 2013 -0500
+@@ -32,10 +32,12 @@
+ #define OPTION_GLIBC  (DEFAULT_LIBC == LIBC_GLIBC)
+ #define OPTION_UCLIBC (DEFAULT_LIBC == LIBC_UCLIBC)
+ #define OPTION_BIONIC (DEFAULT_LIBC == LIBC_BIONIC)
++#define OPTION_MUSL   (DEFAULT_LIBC == LIBC_MUSL)
+ #else
+ #define OPTION_GLIBC  (linux_libc == LIBC_GLIBC)
+ #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
+ #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
++#define OPTION_MUSL   (linux_libc == LIBC_MUSL)
+ #endif
+ 
+ #define GNU_USER_TARGET_OS_CPP_BUILTINS()			\
+@@ -53,18 +55,21 @@
+    uClibc or Bionic is the default C library and whether
+    -muclibc or -mglibc or -mbionic has been passed to change the default.  */
+ 
+-#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LD1, LD2, LD3)	\
+-  "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:" LD1 "}}"
++#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LIBC4, LD1, LD2, LD3, LD4)	\
++  "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:%{" LIBC4 ":" LD4 ";:" LD1 "}}}"
+ 
+ #if DEFAULT_LIBC == LIBC_GLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
+-  CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", G, U, B)
++#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
++  CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", "mmusl", G, U, B, M)
+ #elif DEFAULT_LIBC == LIBC_UCLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
+-  CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", U, G, B)
++#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
++  CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", "mmusl", U, G, B, M)
+ #elif DEFAULT_LIBC == LIBC_BIONIC
+-#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
+-  CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", B, G, U)
++#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
++  CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", "mmusl", B, G, U, M)
++#elif DEFAULT_LIBC == LIBC_MUSL
++#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
++  CHOOSE_DYNAMIC_LINKER1 ("mmusl", "mglibc", "muclibc", "mbionic", M, G, U, B)
+ #else
+ #error "Unsupported DEFAULT_LIBC"
+ #endif /* DEFAULT_LIBC */
+@@ -84,21 +89,21 @@
+ 
+ #define GNU_USER_DYNAMIC_LINKER						\
+   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER,	\
+-			 BIONIC_DYNAMIC_LINKER)
++			 BIONIC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
+ #define GNU_USER_DYNAMIC_LINKER32					\
+   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, \
+-			 BIONIC_DYNAMIC_LINKER32)
++			 BIONIC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
+ #define GNU_USER_DYNAMIC_LINKER64					\
+   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
+-			 BIONIC_DYNAMIC_LINKER64)
++			 BIONIC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
+ #define GNU_USER_DYNAMIC_LINKERX32					\
+   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \
+-			 BIONIC_DYNAMIC_LINKERX32)
++			 BIONIC_DYNAMIC_LINKERX32, MUSL_DYNAMIC_LINKERX32)
+ 
+ /* Determine whether the entire c99 runtime
+    is present in the runtime library.  */
+ #undef TARGET_C99_FUNCTIONS
+-#define TARGET_C99_FUNCTIONS (OPTION_GLIBC)
++#define TARGET_C99_FUNCTIONS (OPTION_GLIBC || OPTION_MUSL)
+ 
+ /* Whether we have sincos that follows the GNU extension.  */
+ #undef TARGET_HAS_SINCOS
+@@ -107,3 +112,74 @@
+ /* Whether we have Bionic libc runtime */
+ #undef TARGET_HAS_BIONIC
+ #define TARGET_HAS_BIONIC (OPTION_BIONIC)
++
++/* musl avoids problematic includes by rearranging the include directories.
++ * Unfortunately, this is mostly duplicated from cppdefault.c */
++#if DEFAULT_LIBC == LIBC_MUSL
++#define INCLUDE_DEFAULTS_MUSL_GPP			\
++    { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1,		\
++      GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },		\
++    { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1,		\
++      GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 },		\
++    { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1,	\
++      GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },
++
++#ifdef LOCAL_INCLUDE_DIR
++#define INCLUDE_DEFAULTS_MUSL_LOCAL			\
++    { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 },		\
++    { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 },
++#else
++#define INCLUDE_DEFAULTS_MUSL_LOCAL
++#endif
++
++#ifdef PREFIX_INCLUDE_DIR
++#define INCLUDE_DEFAULTS_MUSL_PREFIX			\
++    { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0},
++#else
++#define INCLUDE_DEFAULTS_MUSL_PREFIX
++#endif
++
++#ifdef CROSS_INCLUDE_DIR
++#define INCLUDE_DEFAULTS_MUSL_CROSS			\
++    { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0},
++#else
++#define INCLUDE_DEFAULTS_MUSL_CROSS
++#endif
++
++#ifdef TOOL_INCLUDE_DIR
++#define INCLUDE_DEFAULTS_MUSL_TOOL			\
++    { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0},
++#else
++#define INCLUDE_DEFAULTS_MUSL_TOOL
++#endif
++
++#ifdef NATIVE_SYSTEM_HEADER_DIR
++#define INCLUDE_DEFAULTS_MUSL_NATIVE			\
++    { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 2 },	\
++    { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 0 },
++#else
++#define INCLUDE_DEFAULTS_MUSL_NATIVE
++#endif
++
++#if defined (CROSS_DIRECTORY_STRUCTURE) && !defined (TARGET_SYSTEM_ROOT)
++# undef INCLUDE_DEFAULTS_MUSL_LOCAL
++# define INCLUDE_DEFAULTS_MUSL_LOCAL
++# undef INCLUDE_DEFAULTS_MUSL_NATIVE
++# define INCLUDE_DEFAULTS_MUSL_NATIVE
++#else
++# undef INCLUDE_DEFAULTS_MUSL_CROSS
++# define INCLUDE_DEFAULTS_MUSL_CROSS
++#endif
++
++#undef INCLUDE_DEFAULTS
++#define INCLUDE_DEFAULTS				\
++  {							\
++    INCLUDE_DEFAULTS_MUSL_GPP				\
++    INCLUDE_DEFAULTS_MUSL_PREFIX			\
++    INCLUDE_DEFAULTS_MUSL_CROSS				\
++    INCLUDE_DEFAULTS_MUSL_TOOL				\
++    INCLUDE_DEFAULTS_MUSL_NATIVE			\
++    { GCC_INCLUDE_DIR, "GCC", 0, 1, 0, 0 },		\
++    { 0, 0, 0, 0, 0, 0 }				\
++  }
++#endif
+diff -r e5b4564f249f gcc/config/linux.opt
+--- a/gcc/config/linux.opt	Tue Dec 31 14:54:49 2013 -0500
++++ b/gcc/config/linux.opt	Tue Dec 31 14:54:52 2013 -0500
+@@ -30,3 +30,7 @@
+ muclibc
+ Target Report RejectNegative Var(linux_libc,LIBC_UCLIBC) Negative(mbionic)
+ Use uClibc C library
++
++mmusl
++Target Report RejectNegative Var(linux_libc,LIBC_MUSL) Negative(mglibc)
++Use musl C library
+diff -r e5b4564f249f gcc/ginclude/stddef.h
+--- a/gcc/ginclude/stddef.h	Tue Dec 31 14:54:49 2013 -0500
++++ b/gcc/ginclude/stddef.h	Tue Dec 31 14:54:52 2013 -0500
+@@ -181,6 +181,7 @@
+ #ifndef _GCC_SIZE_T
+ #ifndef _SIZET_
+ #ifndef __size_t
++#ifndef __DEFINED_size_t /* musl */
+ #define __size_t__	/* BeOS */
+ #define __SIZE_T__	/* Cray Unicos/Mk */
+ #define _SIZE_T
+@@ -197,6 +198,7 @@
+ #define ___int_size_t_h
+ #define _GCC_SIZE_T
+ #define _SIZET_
++#define __DEFINED_size_t /* musl */
+ #if (defined (__FreeBSD__) && (__FreeBSD__ >= 5)) \
+   || defined(__FreeBSD_kernel__)
+ /* __size_t is a typedef on FreeBSD 5, must not trash it. */
+@@ -214,6 +216,7 @@
+ typedef long ssize_t;
+ #endif /* __BEOS__ */
+ #endif /* !(defined (__GNUG__) && defined (size_t)) */
++#endif /* __DEFINED_size_t */
+ #endif /* __size_t */
+ #endif /* _SIZET_ */
+ #endif /* _GCC_SIZE_T */
+# HG changeset patch
+# Parent e08e44e39f5edde422f444487422046147d5821e
+A fix for libgomp to correctly request a POSIX version for time support.
+
+diff -r e08e44e39f5e libgomp/config/posix/time.c
+--- a/libgomp/config/posix/time.c	Tue Dec 31 14:54:52 2013 -0500
++++ b/libgomp/config/posix/time.c	Tue Dec 31 14:54:55 2013 -0500
+@@ -28,6 +28,8 @@
+    The following implementation uses the most simple POSIX routines.
+    If present, POSIX 4 clocks should be used instead.  */
+ 
++#define _POSIX_C_SOURCE 199309L /* for clocks */
++
+ #include "libgomp.h"
+ #include <unistd.h>
+ #if TIME_WITH_SYS_TIME
+diff -r 809c85574bfe libgcc/unwind-dw2-fde-dip.c
+--- a/libgcc/unwind-dw2-fde-dip.c	Tue Dec 31 14:54:55 2013 -0500
++++ b/libgcc/unwind-dw2-fde-dip.c	Tue Dec 31 14:54:58 2013 -0500
+@@ -46,33 +46,13 @@
+ #include "unwind-compat.h"
+ #include "gthr.h"
+ 
+-#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
+-    && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) \
+-	|| (__GLIBC__ == 2 && __GLIBC_MINOR__ == 2 && defined(DT_CONFIG)))
++#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) && defined(TARGET_DL_ITERATE_PHDR)
+ # define USE_PT_GNU_EH_FRAME
+-#endif
+-
+-#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
+-    && defined(__BIONIC__)
+-# define USE_PT_GNU_EH_FRAME
+-#endif
+-
+-#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
+-    && defined(__FreeBSD__) && __FreeBSD__ >= 7
+-# define ElfW __ElfN
+-# define USE_PT_GNU_EH_FRAME
+-#endif
+-
+-#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
+-    && defined(__OpenBSD__)
+-# define ElfW(type) Elf_##type
+-# define USE_PT_GNU_EH_FRAME
+-#endif
+-
+-#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
+-    && defined(TARGET_DL_ITERATE_PHDR) \
+-    && defined(__sun__) && defined(__svr4__)
+-# define USE_PT_GNU_EH_FRAME
++# ifdef __OpenBSD__
++#  define ElfW(type) Elf_##type
++# elif defined(__FreeBSD__) && __FreeBSD__ >= 7
++#  define ElfW __ElfN
++# endif
+ #endif
+ 
+ #if defined(USE_PT_GNU_EH_FRAME)
+diff -r 03604918697c gcc/configure
+--- a/gcc/configure	Tue Dec 31 14:54:58 2013 -0500
++++ b/gcc/configure	Tue Dec 31 14:55:01 2013 -0500
+@@ -26739,6 +26739,9 @@
+ else
+   gcc_cv_libc_provides_ssp=no
+     case "$target" in
++       *-*-musl*)
++         # All versions of musl provide stack protector
++	 gcc_cv_libc_provides_ssp=yes;;
+        *-*-linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu)
+       # glibc 2.4 and later provides __stack_chk_fail and
+       # either __stack_chk_guard, or TLS access to stack guard canary.
+@@ -26772,6 +26775,7 @@
+ 	 # <http://gcc.gnu.org/ml/gcc/2008-10/msg00130.html>) and for now
+ 	 # simply assert that glibc does provide this, which is true for all
+ 	 # realistically usable GNU/Hurd configurations.
++	 # All supported versions of musl provide it as well
+ 	 gcc_cv_libc_provides_ssp=yes;;
+        *-*-darwin* | *-*-freebsd*)
+ 	 ac_fn_c_check_func "$LINENO" "__stack_chk_fail" "ac_cv_func___stack_chk_fail"
+@@ -26854,6 +26858,9 @@
+       gcc_cv_target_dl_iterate_phdr=no
+     fi
+     ;;
++  *-linux-musl*)
++    gcc_cv_target_dl_iterate_phdr=yes
++    ;;
+ esac
+ 
+ if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
+diff -r 03604918697c gcc/configure.ac
+--- a/gcc/configure.ac	Tue Dec 31 14:54:58 2013 -0500
++++ b/gcc/configure.ac	Tue Dec 31 14:55:01 2013 -0500
+@@ -4722,6 +4722,9 @@
+       gcc_cv_libc_provides_ssp,
+       [gcc_cv_libc_provides_ssp=no
+     case "$target" in
++       *-*-musl*)
++         # All versions of musl provide stack protector
++	 gcc_cv_libc_provides_ssp=yes;;
+        *-*-linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu)
+       [# glibc 2.4 and later provides __stack_chk_fail and
+       # either __stack_chk_guard, or TLS access to stack guard canary.
+@@ -4755,6 +4758,7 @@
+ 	 # <http://gcc.gnu.org/ml/gcc/2008-10/msg00130.html>) and for now
+ 	 # simply assert that glibc does provide this, which is true for all
+ 	 # realistically usable GNU/Hurd configurations.
++	 # All supported versions of musl provide it as well
+ 	 gcc_cv_libc_provides_ssp=yes;;
+        *-*-darwin* | *-*-freebsd*)
+ 	 AC_CHECK_FUNC(__stack_chk_fail,[gcc_cv_libc_provides_ssp=yes],
+@@ -4820,6 +4824,9 @@
+       gcc_cv_target_dl_iterate_phdr=no
+     fi
+     ;;
++  *-linux-musl*)
++    gcc_cv_target_dl_iterate_phdr=yes
++    ;;
+ esac
+ GCC_TARGET_TEMPLATE([TARGET_DL_ITERATE_PHDR])
+ if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
+# HG changeset patch
+# Parent 600a8a422ccaf5627ad1f5a138e7398df2b9e9d8
+Get rid of ever-broken fixincludes on musl.
+
+diff -r 600a8a422cca fixincludes/mkfixinc.sh
+--- a/fixincludes/mkfixinc.sh	Tue Dec 31 14:55:01 2013 -0500
++++ b/fixincludes/mkfixinc.sh	Tue Dec 31 14:55:04 2013 -0500
+@@ -19,7 +19,8 @@
+     powerpc-*-eabi*    | \
+     powerpc-*-rtems*   | \
+     powerpcle-*-eabisim* | \
+-    powerpcle-*-eabi* )
++    powerpcle-*-eabi* | \
++    *-musl* )
+ 	#  IF there is no include fixing,
+ 	#  THEN create a no-op fixer and exit
+ 	(echo "#! /bin/sh" ; echo "exit 0" ) > ${target}
+# HG changeset patch
+# Parent 4696c3bf3d913eca88e9385ea9717541dfe1e033
+Support for i386-linux-musl and x86_64-linux-musl.
+
+diff -r 4696c3bf3d91 gcc/config/i386/linux.h
+--- a/gcc/config/i386/linux.h	Tue Dec 31 14:55:04 2013 -0500
++++ b/gcc/config/i386/linux.h	Tue Dec 31 14:55:08 2013 -0500
+@@ -21,3 +21,4 @@
+ 
+ #define GNU_USER_LINK_EMULATION "elf_i386"
+ #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
++#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-i386.so.1"
+diff -r 4696c3bf3d91 gcc/config/i386/linux64.h
+--- a/gcc/config/i386/linux64.h	Tue Dec 31 14:55:04 2013 -0500
++++ b/gcc/config/i386/linux64.h	Tue Dec 31 14:55:08 2013 -0500
+@@ -30,3 +30,7 @@
+ #define GLIBC_DYNAMIC_LINKER32 "/lib/ld-linux.so.2"
+ #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-linux-x86-64.so.2"
+ #define GLIBC_DYNAMIC_LINKERX32 "/libx32/ld-linux-x32.so.2"
++
++#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-i386.so.1"
++#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-x86_64.so.1"
++#define MUSL_DYNAMIC_LINKERX32 "/lib/ld-musl-x32.so.1"
+diff -r 4696c3bf3d91 libitm/config/linux/x86/tls.h
+--- a/libitm/config/linux/x86/tls.h	Tue Dec 31 14:55:04 2013 -0500
++++ b/libitm/config/linux/x86/tls.h	Tue Dec 31 14:55:08 2013 -0500
+@@ -25,16 +25,19 @@
+ #ifndef LIBITM_X86_TLS_H
+ #define LIBITM_X86_TLS_H 1
+ 
+-#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
++#if defined(__GLIBC_PREREQ)
++#if __GLIBC_PREREQ(2, 10)
+ /* Use slots in the TCB head rather than __thread lookups.
+    GLIBC has reserved words 10 through 13 for TM.  */
+ #define HAVE_ARCH_GTM_THREAD 1
+ #define HAVE_ARCH_GTM_THREAD_DISP 1
+ #endif
++#endif
+ 
+ #include "config/generic/tls.h"
+ 
+-#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
++#if defined(__GLIBC_PREREQ)
++#if __GLIBC_PREREQ(2, 10)
+ namespace GTM HIDDEN {
+ 
+ #ifdef __x86_64__
+@@ -101,5 +104,6 @@
+ 
+ } // namespace GTM
+ #endif /* >= GLIBC 2.10 */
++#endif
+ 
+ #endif // LIBITM_X86_TLS_H
+# HG changeset patch
+# Parent 6738fd6f6fcc2a72f2ba527bda3325642af26885
+Support for arm-linux-musl.
+
+diff -r 6738fd6f6fcc gcc/config/arm/linux-eabi.h
+--- a/gcc/config/arm/linux-eabi.h	Tue Dec 31 14:55:08 2013 -0500
++++ b/gcc/config/arm/linux-eabi.h	Tue Dec 31 14:55:11 2013 -0500
+@@ -77,6 +77,23 @@
+     %{mfloat-abi=soft*:" GLIBC_DYNAMIC_LINKER_SOFT_FLOAT "} \
+     %{!mfloat-abi=*:" GLIBC_DYNAMIC_LINKER_DEFAULT "}"
+ 
++/* For ARM musl currently supports four dynamic linkers:
++   - ld-musl-arm.so.1 - for the EABI-derived soft-float ABI
++   - ld-musl-armhf.so.1 - for the EABI-derived hard-float ABI
++   - ld-musl-armeb.so.1 - for the EABI-derived soft-float ABI, EB
++   - ld-musl-armebhf.so.1 - for the EABI-derived hard-float ABI, EB
++   musl does not support the legacy OABI mode.
++   All the dynamic linkers live in /lib.
++   We default to soft-float, EL. */
++#undef  MUSL_DYNAMIC_LINKER
++#if TARGET_BIG_ENDIAN_DEFAULT
++#define MUSL_DYNAMIC_LINKER_E "%{mlittle-endian:;:eb}"
++#else
++#define MUSL_DYNAMIC_LINKER_E "%{mbig-endian:eb}"
++#endif
++#define MUSL_DYNAMIC_LINKER \
++  "/lib/ld-musl-arm" MUSL_DYNAMIC_LINKER_E "%{mfloat-abi=hard:hf}.so.1"
++
+ /* At this point, bpabi.h will have clobbered LINK_SPEC.  We want to
+    use the GNU/Linux version, not the generic BPABI version.  */
+ #undef  LINK_SPEC
+diff -r 6738fd6f6fcc libitm/config/arm/hwcap.cc
+--- a/libitm/config/arm/hwcap.cc	Tue Dec 31 14:55:08 2013 -0500
++++ b/libitm/config/arm/hwcap.cc	Tue Dec 31 14:55:11 2013 -0500
+@@ -40,7 +40,11 @@
+ 
+ #ifdef __linux__
+ #include <unistd.h>
++#ifdef __GLIBC__
+ #include <sys/fcntl.h>
++#else
++#include <fcntl.h>
++#endif
+ #include <elf.h>
+ 
+ static void __attribute__((constructor))
+# HG changeset patch
+# Parent 7d7383f638705a01fdc18e0e7e0c9cdb6387fc5d
+Support for mips-linux-musl.
+
+diff -r 7d7383f63870 gcc/config/mips/linux.h
+--- a/gcc/config/mips/linux.h	Tue Dec 31 14:55:11 2013 -0500
++++ b/gcc/config/mips/linux.h	Tue Dec 31 14:55:14 2013 -0500
+@@ -18,3 +18,10 @@
+ <http://www.gnu.org/licenses/>.  */
+ 
+ #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
++
++#if TARGET_ENDIAN_DEFAULT == 0 /* LE */
++#define MUSL_DYNAMIC_LINKER_E "%{EB:;:el}"
++#else
++#define MUSL_DYNAMIC_LINKER_E "%{EL:el}"
++#endif
++#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-mips" MUSL_DYNAMIC_LINKER_E ".so.1"
+# HG changeset patch
+# Parent 89df6d7e91c686da676ce27ef9b9d10522810c26
+Support for powerpc-linux-musl.
+
+diff -r 89df6d7e91c6 gcc/config.gcc
+--- a/gcc/config.gcc	Tue Dec 31 14:55:14 2013 -0500
++++ b/gcc/config.gcc	Tue Dec 31 14:55:17 2013 -0500
+@@ -2117,6 +2117,10 @@
+ 	    powerpc*-*-linux*paired*)
+ 		tm_file="${tm_file} rs6000/750cl.h" ;;
+ 	esac
++        case ${target} in
++            *-linux*-musl*)
++                enable_secureplt=yes ;;
++        esac
+ 	if test x${enable_secureplt} = xyes; then
+ 		tm_file="rs6000/secureplt.h ${tm_file}"
+ 	fi
+diff -r 89df6d7e91c6 gcc/config/rs6000/linux64.h
+--- a/gcc/config/rs6000/linux64.h	Tue Dec 31 14:55:14 2013 -0500
++++ b/gcc/config/rs6000/linux64.h	Tue Dec 31 14:55:17 2013 -0500
+@@ -354,17 +354,21 @@
+ #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld64.so.1"
+ #define UCLIBC_DYNAMIC_LINKER32 "/lib/ld-uClibc.so.0"
+ #define UCLIBC_DYNAMIC_LINKER64 "/lib/ld64-uClibc.so.0"
++#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-powerpc.so.1"
++#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-powerpc64.so.1"
+ #if DEFAULT_LIBC == LIBC_UCLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
+ #elif DEFAULT_LIBC == LIBC_GLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
++#elif DEFAULT_LIBC == LIBC_MUSL
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
+ #else
+ #error "Unsupported DEFAULT_LIBC"
+ #endif
+ #define GNU_USER_DYNAMIC_LINKER32 \
+-  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32)
++  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
+ #define GNU_USER_DYNAMIC_LINKER64 \
+-  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64)
++  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
+ 
+ #undef  DEFAULT_ASM_ENDIAN
+ #if (TARGET_DEFAULT & MASK_LITTLE_ENDIAN)
+diff -r 89df6d7e91c6 gcc/config/rs6000/secureplt.h
+--- a/gcc/config/rs6000/secureplt.h	Tue Dec 31 14:55:14 2013 -0500
++++ b/gcc/config/rs6000/secureplt.h	Tue Dec 31 14:55:17 2013 -0500
+@@ -18,3 +18,4 @@
+ <http://www.gnu.org/licenses/>.  */
+ 
+ #define CC1_SECURE_PLT_DEFAULT_SPEC "-msecure-plt"
++#define LINK_SECURE_PLT_DEFAULT_SPEC "--secure-plt"
+diff -r 89df6d7e91c6 gcc/config/rs6000/sysv4.h
+--- a/gcc/config/rs6000/sysv4.h	Tue Dec 31 14:55:14 2013 -0500
++++ b/gcc/config/rs6000/sysv4.h	Tue Dec 31 14:55:17 2013 -0500
+@@ -550,6 +550,9 @@
+ #ifndef CC1_SECURE_PLT_DEFAULT_SPEC
+ #define CC1_SECURE_PLT_DEFAULT_SPEC ""
+ #endif
++#ifndef LINK_SECURE_PLT_DEFAULT_SPEC
++#define LINK_SECURE_PLT_DEFAULT_SPEC ""
++#endif
+ 
+ /* Pass -G xxx to the compiler and set correct endian mode.  */
+ #define	CC1_SPEC "%{G*} %(cc1_cpu)" \
+@@ -600,7 +603,8 @@
+ 
+ /* Override the default target of the linker.  */
+ #define	LINK_TARGET_SPEC \
+-  ENDIAN_SELECT("", " --oformat elf32-powerpcle", "")
++  ENDIAN_SELECT("", " --oformat elf32-powerpcle", "") \
++  "%{!mbss-plt: %{!msecure-plt: %(link_secure_plt_default)}}"
+ 
+ /* Any specific OS flags.  */
+ #define LINK_OS_SPEC "\
+@@ -778,15 +782,18 @@
+ 
+ #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
+ #define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0"
++#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-powerpc.so.1"
+ #if DEFAULT_LIBC == LIBC_UCLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
++#elif DEFAULT_LIBC == LIBC_MUSL
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
+ #elif !defined (DEFAULT_LIBC) || DEFAULT_LIBC == LIBC_GLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
+ #else
+ #error "Unsupported DEFAULT_LIBC"
+ #endif
+ #define GNU_USER_DYNAMIC_LINKER \
+-  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER)
++  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
+ 
+ #define LINK_OS_LINUX_SPEC "-m elf32ppclinux %{!shared: %{!static: \
+   %{rdynamic:-export-dynamic} \
+@@ -912,6 +919,7 @@
+   { "cc1_endian_little",	CC1_ENDIAN_LITTLE_SPEC },		\
+   { "cc1_endian_default",	CC1_ENDIAN_DEFAULT_SPEC },		\
+   { "cc1_secure_plt_default",	CC1_SECURE_PLT_DEFAULT_SPEC },		\
++  { "link_secure_plt_default",	LINK_SECURE_PLT_DEFAULT_SPEC },		\
+   { "cpp_os_ads",		CPP_OS_ADS_SPEC },			\
+   { "cpp_os_yellowknife",	CPP_OS_YELLOWKNIFE_SPEC },		\
+   { "cpp_os_mvme",		CPP_OS_MVME_SPEC },			\
+diff -r d7ce17b2f2d6 gcc/config/aarch64/aarch64-linux.h
+--- a/gcc/config/aarch64/aarch64-linux.h	Tue Dec 31 14:55:17 2013 -0500
++++ b/gcc/config/aarch64/aarch64-linux.h	Tue Dec 31 14:55:20 2013 -0500
+@@ -21,7 +21,11 @@
+ #ifndef GCC_AARCH64_LINUX_H
+ #define GCC_AARCH64_LINUX_H
+ 
++/* The AArch64 port currently supports two dynamic linkers:
++   - ld-linux-aarch64.so.1 - GLIBC dynamic linker
++   - ld-musl-aarch64.so.1 - musl libc dynamic linker  */
+ #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux-aarch64.so.1"
++#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-aarch64.so.1"
+ 
+ #define CPP_SPEC "%{pthread:-D_REENTRANT}"
+ 
+# HG changeset patch
+# Parent f2601e4063d0d58d8ab04185e8baefd560d09496
+Microblaze support (again).
+
+
+diff -r f2601e4063d0 -r 0736dfe1aa0d gcc/config/microblaze/linux.h
+--- a/gcc/config/microblaze/linux.h	Tue Dec 31 14:55:20 2013 -0500
++++ b/gcc/config/microblaze/linux.h	Tue Dec 31 15:09:52 2013 -0500
+@@ -25,7 +25,22 @@
+ #undef TLS_NEEDS_GOT
+ #define TLS_NEEDS_GOT 1
+ 
+-#define DYNAMIC_LINKER "/lib/ld.so.1"
++#if TARGET_BIG_ENDIAN_DEFAULT == 0 /* LE */
++#define MUSL_DYNAMIC_LINKER_E "%{EB:;:el}"
++#else
++#define MUSL_DYNAMIC_LINKER_E "%{EL:el}"
++#endif
++
++#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-microblaze" MUSL_DYNAMIC_LINKER_E ".so.1"
++#define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
++
++#if DEFAULT_LIBC == LIBC_MUSL
++#define DYNAMIC_LINKER MUSL_DYNAMIC_LINKER
++#else
++#define DYNAMIC_LINKER GLIBC_DYNAMIC_LINKER
++#endif
++
++
+ #undef  SUBTARGET_EXTRA_SPECS
+ #define SUBTARGET_EXTRA_SPECS \
+   { "dynamic_linker", DYNAMIC_LINKER }
+From 478ee0c03a08e2ef9371fd88d516738936943e78 Mon Sep 17 00:00:00 2001
+From: David Holsgrove <david.holsgrove@xilinx.com>
+Date: Fri, 28 Sep 2012 16:32:03 +1000
+Subject: [PATCH 06/11] [Patch, microblaze]: Add SIZE_TYPE and PTRDIFF_TYPE to
+ microblaze.h
+
+Fixes warnings like;
+
+warning: format '%zX' expects argument of type 'size_t',
+but argument 3 has type 'unsigned int' [-Wformat]
+
+Changelog
+
+2013-03-18  David Holsgrove <david.holsgrove@xilinx.com>
+
+ * gcc/config/microblaze/microblaze.h: Define SIZE_TYPE
+   and PTRDIFF_TYPE.
+
+Signed-off-by: David Holsgrove <david.holsgrove@xilinx.com>
+---
+ gcc/config/microblaze/microblaze.h |    6 ++++++
+ 1 file changed, 6 insertions(+)
+
+diff --git a/gcc/config/microblaze/microblaze.h b/gcc/config/microblaze/microblaze.h
+index 19cdfed..e772a3f 100644
+--- a/gcc/config/microblaze/microblaze.h
++++ b/gcc/config/microblaze/microblaze.h
+@@ -213,6 +213,12 @@ extern enum pipeline_type microblaze_pipe;
+ #define STRICT_ALIGNMENT        1
+ #define PCC_BITFIELD_TYPE_MATTERS 1
+ 
++#undef SIZE_TYPE
++#define SIZE_TYPE "unsigned int"
++
++#undef PTRDIFF_TYPE
++#define PTRDIFF_TYPE "int"
++
+ #define CONSTANT_ALIGNMENT(EXP, ALIGN)					\
+   ((TREE_CODE (EXP) == STRING_CST  || TREE_CODE (EXP) == CONSTRUCTOR)	\
+    && (ALIGN) < BITS_PER_WORD						\
+-- 
+1.7.9.5
+
+--- gcc-4.8.2.org/gcc/config/sh/linux.h
++++ gcc-4.8.2/gcc/config/sh/linux.h
+@@ -43,7 +43,14 @@
+ 
+ #define TARGET_ASM_FILE_END file_end_indicate_exec_stack
+ 
++#if TARGET_BIG_ENDIAN_DEFAULT /* BE */
++#define MUSL_DYNAMIC_LINKER_E "eb"
++#else
++#define MUSL_DYNAMIC_LINKER_E
++#endif
++
+ #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
++#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-sh" MUSL_DYNAMIC_LINKER_E ".so.1"
+ 
+ #undef SUBTARGET_LINK_EMUL_SUFFIX
+ #define SUBTARGET_LINK_EMUL_SUFFIX "_linux"
+--- gcc-4.8.2.org/gcc/config/sh/sh.c
++++ gcc-4.8.2/gcc/config/sh/sh.c
+@@ -22,8 +22,17 @@
+ /* FIXME: This is a temporary hack, so that we can include <algorithm>
+    below.  <algorithm> will try to include <cstdlib> which will reference
+    malloc & co, which are poisoned by "system.h".  The proper solution is
+-   to include <cstdlib> in "system.h" instead of <stdlib.h>.  */
++   to include <cstdlib> in "system.h" instead of <stdlib.h>.
++   It's also a temporary hack as the inclusion of sstream will cause inclusion
++   of libc's pthread.h (istream->ios->ios_base->atomicity->gth->gthr-default)
++   which in turn includes sched.h, which defines the CPU_ALLOC, which uses
++   the poisoned calloc. the proper fix would be to shield the poison pragmas
++   with some define that is only set when gcc developers do testing.
++*/
+ #include <cstdlib>
++#include <sstream>
++#include <vector>
++#include <algorithm>
+ 
+ #include "config.h"
+ #include "system.h"
+@@ -59,10 +68,6 @@
+ #include "alloc-pool.h"
+ #include "tm-constrs.h"
+ #include "opts.h"
+-
+-#include <sstream>
+-#include <vector>
+-#include <algorithm>
+ 
+ int code_for_indirect_jump_scratch = CODE_FOR_indirect_jump_scratch;
+ 
diff --git a/patches/experimental/gcc/4.8.3/0001-musl.patch b/patches/experimental/gcc/4.8.3/0001-musl.patch
new file mode 100644
index 0000000..3e23402
--- /dev/null
+++ b/patches/experimental/gcc/4.8.3/0001-musl.patch
@@ -0,0 +1,736 @@
+This patch enables support for musl-libc in gcc.
+
+This patch is not supported by crosstool-ng and was originally found here:
+    https://bitbucket.org/GregorR/musl-cross/src/27953a1f7085/patches/gcc-4.8.3-musl.diff
+
+Added-By: Bryan Hundven <bryanhundven@gmail.com>
+---
+diff -r 3265a3936a0f libstdc++-v3/configure.host
+--- a/libstdc++-v3/configure.host	Tue May 27 17:11:50 2014 -0400
++++ b/libstdc++-v3/configure.host	Tue May 27 17:18:49 2014 -0400
+@@ -264,6 +264,13 @@
+     os_include_dir="os/bsd/freebsd"
+     ;;
+   gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu)
++    # check for musl by target
++    case "${host_os}" in
++      *-musl*)
++        os_include_dir="os/generic"
++        ;;
++      *)
++
+     if [ "$uclibc" = "yes" ]; then
+       os_include_dir="os/uclibc"
+     elif [ "$bionic" = "yes" ]; then
+@@ -272,6 +279,9 @@
+       os_include_dir="os/gnu-linux"
+     fi
+     ;;
++
++    esac
++    ;;
+   hpux*)
+     os_include_dir="os/hpux"
+     ;;
+# HG changeset patch
+# Parent feba6705f7e390f69e474a7c761a0eb7add7d414
+Adding -mmusl as a musl libc specifier, and the necessary hacks for it to know how to find musl's dynamic linker.
+
+diff -r feba6705f7e3 gcc/config.gcc
+--- a/gcc/config.gcc	Tue May 27 17:18:49 2014 -0400
++++ b/gcc/config.gcc	Tue May 27 17:18:52 2014 -0400
+@@ -550,7 +550,7 @@
+ esac
+ 
+ # Common C libraries.
+-tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3"
++tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3 LIBC_MUSL=4"
+ 
+ # Common parts for widely ported systems.
+ case ${target} in
+@@ -653,6 +653,9 @@
+     *-*-*uclibc*)
+       tm_defines="$tm_defines DEFAULT_LIBC=LIBC_UCLIBC"
+       ;;
++    *-*-*musl*)
++      tm_defines="$tm_defines DEFAULT_LIBC=LIBC_MUSL"
++      ;;
+     *)
+       tm_defines="$tm_defines DEFAULT_LIBC=LIBC_GLIBC"
+       ;;
+diff -r feba6705f7e3 gcc/config/linux.h
+--- a/gcc/config/linux.h	Tue May 27 17:18:49 2014 -0400
++++ b/gcc/config/linux.h	Tue May 27 17:18:52 2014 -0400
+@@ -32,10 +32,12 @@
+ #define OPTION_GLIBC  (DEFAULT_LIBC == LIBC_GLIBC)
+ #define OPTION_UCLIBC (DEFAULT_LIBC == LIBC_UCLIBC)
+ #define OPTION_BIONIC (DEFAULT_LIBC == LIBC_BIONIC)
++#define OPTION_MUSL   (DEFAULT_LIBC == LIBC_MUSL)
+ #else
+ #define OPTION_GLIBC  (linux_libc == LIBC_GLIBC)
+ #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
+ #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
++#define OPTION_MUSL   (linux_libc == LIBC_MUSL)
+ #endif
+ 
+ #define GNU_USER_TARGET_OS_CPP_BUILTINS()			\
+@@ -53,18 +55,21 @@
+    uClibc or Bionic is the default C library and whether
+    -muclibc or -mglibc or -mbionic has been passed to change the default.  */
+ 
+-#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LD1, LD2, LD3)	\
+-  "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:" LD1 "}}"
++#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LIBC4, LD1, LD2, LD3, LD4)	\
++  "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:%{" LIBC4 ":" LD4 ";:" LD1 "}}}"
+ 
+ #if DEFAULT_LIBC == LIBC_GLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
+-  CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", G, U, B)
++#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
++  CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", "mmusl", G, U, B, M)
+ #elif DEFAULT_LIBC == LIBC_UCLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
+-  CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", U, G, B)
++#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
++  CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", "mmusl", U, G, B, M)
+ #elif DEFAULT_LIBC == LIBC_BIONIC
+-#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
+-  CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", B, G, U)
++#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
++  CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", "mmusl", B, G, U, M)
++#elif DEFAULT_LIBC == LIBC_MUSL
++#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
++  CHOOSE_DYNAMIC_LINKER1 ("mmusl", "mglibc", "muclibc", "mbionic", M, G, U, B)
+ #else
+ #error "Unsupported DEFAULT_LIBC"
+ #endif /* DEFAULT_LIBC */
+@@ -84,21 +89,21 @@
+ 
+ #define GNU_USER_DYNAMIC_LINKER						\
+   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER,	\
+-			 BIONIC_DYNAMIC_LINKER)
++			 BIONIC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
+ #define GNU_USER_DYNAMIC_LINKER32					\
+   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, \
+-			 BIONIC_DYNAMIC_LINKER32)
++			 BIONIC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
+ #define GNU_USER_DYNAMIC_LINKER64					\
+   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
+-			 BIONIC_DYNAMIC_LINKER64)
++			 BIONIC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
+ #define GNU_USER_DYNAMIC_LINKERX32					\
+   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \
+-			 BIONIC_DYNAMIC_LINKERX32)
++			 BIONIC_DYNAMIC_LINKERX32, MUSL_DYNAMIC_LINKERX32)
+ 
+ /* Determine whether the entire c99 runtime
+    is present in the runtime library.  */
+ #undef TARGET_C99_FUNCTIONS
+-#define TARGET_C99_FUNCTIONS (OPTION_GLIBC)
++#define TARGET_C99_FUNCTIONS (OPTION_GLIBC || OPTION_MUSL)
+ 
+ /* Whether we have sincos that follows the GNU extension.  */
+ #undef TARGET_HAS_SINCOS
+@@ -107,3 +112,74 @@
+ /* Whether we have Bionic libc runtime */
+ #undef TARGET_HAS_BIONIC
+ #define TARGET_HAS_BIONIC (OPTION_BIONIC)
++
++/* musl avoids problematic includes by rearranging the include directories.
++ * Unfortunately, this is mostly duplicated from cppdefault.c */
++#if DEFAULT_LIBC == LIBC_MUSL
++#define INCLUDE_DEFAULTS_MUSL_GPP			\
++    { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1,		\
++      GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },		\
++    { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1,		\
++      GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 },		\
++    { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1,	\
++      GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },
++
++#ifdef LOCAL_INCLUDE_DIR
++#define INCLUDE_DEFAULTS_MUSL_LOCAL			\
++    { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 },		\
++    { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 },
++#else
++#define INCLUDE_DEFAULTS_MUSL_LOCAL
++#endif
++
++#ifdef PREFIX_INCLUDE_DIR
++#define INCLUDE_DEFAULTS_MUSL_PREFIX			\
++    { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0},
++#else
++#define INCLUDE_DEFAULTS_MUSL_PREFIX
++#endif
++
++#ifdef CROSS_INCLUDE_DIR
++#define INCLUDE_DEFAULTS_MUSL_CROSS			\
++    { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0},
++#else
++#define INCLUDE_DEFAULTS_MUSL_CROSS
++#endif
++
++#ifdef TOOL_INCLUDE_DIR
++#define INCLUDE_DEFAULTS_MUSL_TOOL			\
++    { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0},
++#else
++#define INCLUDE_DEFAULTS_MUSL_TOOL
++#endif
++
++#ifdef NATIVE_SYSTEM_HEADER_DIR
++#define INCLUDE_DEFAULTS_MUSL_NATIVE			\
++    { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 2 },	\
++    { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 0 },
++#else
++#define INCLUDE_DEFAULTS_MUSL_NATIVE
++#endif
++
++#if defined (CROSS_DIRECTORY_STRUCTURE) && !defined (TARGET_SYSTEM_ROOT)
++# undef INCLUDE_DEFAULTS_MUSL_LOCAL
++# define INCLUDE_DEFAULTS_MUSL_LOCAL
++# undef INCLUDE_DEFAULTS_MUSL_NATIVE
++# define INCLUDE_DEFAULTS_MUSL_NATIVE
++#else
++# undef INCLUDE_DEFAULTS_MUSL_CROSS
++# define INCLUDE_DEFAULTS_MUSL_CROSS
++#endif
++
++#undef INCLUDE_DEFAULTS
++#define INCLUDE_DEFAULTS				\
++  {							\
++    INCLUDE_DEFAULTS_MUSL_GPP				\
++    INCLUDE_DEFAULTS_MUSL_PREFIX			\
++    INCLUDE_DEFAULTS_MUSL_CROSS				\
++    INCLUDE_DEFAULTS_MUSL_TOOL				\
++    INCLUDE_DEFAULTS_MUSL_NATIVE			\
++    { GCC_INCLUDE_DIR, "GCC", 0, 1, 0, 0 },		\
++    { 0, 0, 0, 0, 0, 0 }				\
++  }
++#endif
+diff -r feba6705f7e3 gcc/config/linux.opt
+--- a/gcc/config/linux.opt	Tue May 27 17:18:49 2014 -0400
++++ b/gcc/config/linux.opt	Tue May 27 17:18:52 2014 -0400
+@@ -30,3 +30,7 @@
+ muclibc
+ Target Report RejectNegative Var(linux_libc,LIBC_UCLIBC) Negative(mbionic)
+ Use uClibc C library
++
++mmusl
++Target Report RejectNegative Var(linux_libc,LIBC_MUSL) Negative(mglibc)
++Use musl C library
+diff -r feba6705f7e3 gcc/ginclude/stddef.h
+--- a/gcc/ginclude/stddef.h	Tue May 27 17:18:49 2014 -0400
++++ b/gcc/ginclude/stddef.h	Tue May 27 17:18:52 2014 -0400
+@@ -181,6 +181,7 @@
+ #ifndef _GCC_SIZE_T
+ #ifndef _SIZET_
+ #ifndef __size_t
++#ifndef __DEFINED_size_t /* musl */
+ #define __size_t__	/* BeOS */
+ #define __SIZE_T__	/* Cray Unicos/Mk */
+ #define _SIZE_T
+@@ -197,6 +198,7 @@
+ #define ___int_size_t_h
+ #define _GCC_SIZE_T
+ #define _SIZET_
++#define __DEFINED_size_t /* musl */
+ #if (defined (__FreeBSD__) && (__FreeBSD__ >= 5)) \
+   || defined(__FreeBSD_kernel__)
+ /* __size_t is a typedef on FreeBSD 5, must not trash it. */
+@@ -214,6 +216,7 @@
+ typedef long ssize_t;
+ #endif /* __BEOS__ */
+ #endif /* !(defined (__GNUG__) && defined (size_t)) */
++#endif /* __DEFINED_size_t */
+ #endif /* __size_t */
+ #endif /* _SIZET_ */
+ #endif /* _GCC_SIZE_T */
+# HG changeset patch
+# Parent 77fd601051c4644b37838a8e5305c6971feab94f
+A fix for libgomp to correctly request a POSIX version for time support.
+
+diff -r 77fd601051c4 libgomp/config/posix/time.c
+--- a/libgomp/config/posix/time.c	Tue May 27 17:18:52 2014 -0400
++++ b/libgomp/config/posix/time.c	Tue May 27 17:18:55 2014 -0400
+@@ -28,6 +28,8 @@
+    The following implementation uses the most simple POSIX routines.
+    If present, POSIX 4 clocks should be used instead.  */
+ 
++#define _POSIX_C_SOURCE 199309L /* for clocks */
++
+ #include "libgomp.h"
+ #include <unistd.h>
+ #if TIME_WITH_SYS_TIME
+diff -r abebeb8818d8 libgcc/unwind-dw2-fde-dip.c
+--- a/libgcc/unwind-dw2-fde-dip.c	Tue May 27 17:18:55 2014 -0400
++++ b/libgcc/unwind-dw2-fde-dip.c	Tue May 27 17:18:58 2014 -0400
+@@ -46,33 +46,13 @@
+ #include "unwind-compat.h"
+ #include "gthr.h"
+ 
+-#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
+-    && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) \
+-	|| (__GLIBC__ == 2 && __GLIBC_MINOR__ == 2 && defined(DT_CONFIG)))
++#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) && defined(TARGET_DL_ITERATE_PHDR)
+ # define USE_PT_GNU_EH_FRAME
+-#endif
+-
+-#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
+-    && defined(__BIONIC__)
+-# define USE_PT_GNU_EH_FRAME
+-#endif
+-
+-#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
+-    && defined(__FreeBSD__) && __FreeBSD__ >= 7
+-# define ElfW __ElfN
+-# define USE_PT_GNU_EH_FRAME
+-#endif
+-
+-#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
+-    && defined(__OpenBSD__)
+-# define ElfW(type) Elf_##type
+-# define USE_PT_GNU_EH_FRAME
+-#endif
+-
+-#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
+-    && defined(TARGET_DL_ITERATE_PHDR) \
+-    && defined(__sun__) && defined(__svr4__)
+-# define USE_PT_GNU_EH_FRAME
++# ifdef __OpenBSD__
++#  define ElfW(type) Elf_##type
++# elif defined(__FreeBSD__) && __FreeBSD__ >= 7
++#  define ElfW __ElfN
++# endif
+ #endif
+ 
+ #if defined(USE_PT_GNU_EH_FRAME)
+diff -r 68e6894cdeea gcc/configure
+--- a/gcc/configure	Tue May 27 17:18:58 2014 -0400
++++ b/gcc/configure	Tue May 27 17:19:01 2014 -0400
+@@ -26821,6 +26821,9 @@
+ else
+   gcc_cv_libc_provides_ssp=no
+     case "$target" in
++       *-*-musl*)
++         # All versions of musl provide stack protector
++	 gcc_cv_libc_provides_ssp=yes;;
+        *-*-linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu)
+       # glibc 2.4 and later provides __stack_chk_fail and
+       # either __stack_chk_guard, or TLS access to stack guard canary.
+@@ -26854,6 +26857,7 @@
+ 	 # <http://gcc.gnu.org/ml/gcc/2008-10/msg00130.html>) and for now
+ 	 # simply assert that glibc does provide this, which is true for all
+ 	 # realistically usable GNU/Hurd configurations.
++	 # All supported versions of musl provide it as well
+ 	 gcc_cv_libc_provides_ssp=yes;;
+        *-*-darwin* | *-*-freebsd*)
+ 	 ac_fn_c_check_func "$LINENO" "__stack_chk_fail" "ac_cv_func___stack_chk_fail"
+@@ -26936,6 +26940,9 @@
+       gcc_cv_target_dl_iterate_phdr=no
+     fi
+     ;;
++  *-linux-musl*)
++    gcc_cv_target_dl_iterate_phdr=yes
++    ;;
+ esac
+ 
+ if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
+diff -r 68e6894cdeea gcc/configure.ac
+--- a/gcc/configure.ac	Tue May 27 17:18:58 2014 -0400
++++ b/gcc/configure.ac	Tue May 27 17:19:01 2014 -0400
+@@ -4750,6 +4750,9 @@
+       gcc_cv_libc_provides_ssp,
+       [gcc_cv_libc_provides_ssp=no
+     case "$target" in
++       *-*-musl*)
++         # All versions of musl provide stack protector
++	 gcc_cv_libc_provides_ssp=yes;;
+        *-*-linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu)
+       [# glibc 2.4 and later provides __stack_chk_fail and
+       # either __stack_chk_guard, or TLS access to stack guard canary.
+@@ -4783,6 +4786,7 @@
+ 	 # <http://gcc.gnu.org/ml/gcc/2008-10/msg00130.html>) and for now
+ 	 # simply assert that glibc does provide this, which is true for all
+ 	 # realistically usable GNU/Hurd configurations.
++	 # All supported versions of musl provide it as well
+ 	 gcc_cv_libc_provides_ssp=yes;;
+        *-*-darwin* | *-*-freebsd*)
+ 	 AC_CHECK_FUNC(__stack_chk_fail,[gcc_cv_libc_provides_ssp=yes],
+@@ -4848,6 +4852,9 @@
+       gcc_cv_target_dl_iterate_phdr=no
+     fi
+     ;;
++  *-linux-musl*)
++    gcc_cv_target_dl_iterate_phdr=yes
++    ;;
+ esac
+ GCC_TARGET_TEMPLATE([TARGET_DL_ITERATE_PHDR])
+ if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
+# HG changeset patch
+# Parent 5e0be25b469181f67d89382c7da201510c229f90
+Get rid of ever-broken fixincludes on musl.
+
+diff -r 5e0be25b4691 fixincludes/mkfixinc.sh
+--- a/fixincludes/mkfixinc.sh	Tue May 27 17:19:01 2014 -0400
++++ b/fixincludes/mkfixinc.sh	Tue May 27 17:19:04 2014 -0400
+@@ -19,7 +19,8 @@
+     powerpc-*-eabi*    | \
+     powerpc-*-rtems*   | \
+     powerpcle-*-eabisim* | \
+-    powerpcle-*-eabi* )
++    powerpcle-*-eabi* | \
++    *-musl* )
+ 	#  IF there is no include fixing,
+ 	#  THEN create a no-op fixer and exit
+ 	(echo "#! /bin/sh" ; echo "exit 0" ) > ${target}
+# HG changeset patch
+# Parent dd2004fbd61c182919b800cec63806060b4228e5
+Support for i386-linux-musl and x86_64-linux-musl.
+
+diff -r dd2004fbd61c gcc/config/i386/linux.h
+--- a/gcc/config/i386/linux.h	Tue May 27 17:19:04 2014 -0400
++++ b/gcc/config/i386/linux.h	Tue May 27 17:19:07 2014 -0400
+@@ -21,3 +21,4 @@
+ 
+ #define GNU_USER_LINK_EMULATION "elf_i386"
+ #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
++#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-i386.so.1"
+diff -r dd2004fbd61c gcc/config/i386/linux64.h
+--- a/gcc/config/i386/linux64.h	Tue May 27 17:19:04 2014 -0400
++++ b/gcc/config/i386/linux64.h	Tue May 27 17:19:07 2014 -0400
+@@ -30,3 +30,7 @@
+ #define GLIBC_DYNAMIC_LINKER32 "/lib/ld-linux.so.2"
+ #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-linux-x86-64.so.2"
+ #define GLIBC_DYNAMIC_LINKERX32 "/libx32/ld-linux-x32.so.2"
++
++#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-i386.so.1"
++#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-x86_64.so.1"
++#define MUSL_DYNAMIC_LINKERX32 "/lib/ld-musl-x32.so.1"
+diff -r dd2004fbd61c libitm/config/linux/x86/tls.h
+--- a/libitm/config/linux/x86/tls.h	Tue May 27 17:19:04 2014 -0400
++++ b/libitm/config/linux/x86/tls.h	Tue May 27 17:19:07 2014 -0400
+@@ -25,16 +25,19 @@
+ #ifndef LIBITM_X86_TLS_H
+ #define LIBITM_X86_TLS_H 1
+ 
+-#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
++#if defined(__GLIBC_PREREQ)
++#if __GLIBC_PREREQ(2, 10)
+ /* Use slots in the TCB head rather than __thread lookups.
+    GLIBC has reserved words 10 through 13 for TM.  */
+ #define HAVE_ARCH_GTM_THREAD 1
+ #define HAVE_ARCH_GTM_THREAD_DISP 1
+ #endif
++#endif
+ 
+ #include "config/generic/tls.h"
+ 
+-#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
++#if defined(__GLIBC_PREREQ)
++#if __GLIBC_PREREQ(2, 10)
+ namespace GTM HIDDEN {
+ 
+ #ifdef __x86_64__
+@@ -101,5 +104,6 @@
+ 
+ } // namespace GTM
+ #endif /* >= GLIBC 2.10 */
++#endif
+ 
+ #endif // LIBITM_X86_TLS_H
+# HG changeset patch
+# Parent 42eeea84a212601568b5a6d17eb28cfba4b45e1d
+Support for arm-linux-musl.
+
+diff -r 42eeea84a212 gcc/config/arm/linux-eabi.h
+--- a/gcc/config/arm/linux-eabi.h	Tue May 27 17:19:07 2014 -0400
++++ b/gcc/config/arm/linux-eabi.h	Tue May 27 17:19:11 2014 -0400
+@@ -77,6 +77,23 @@
+     %{mfloat-abi=soft*:" GLIBC_DYNAMIC_LINKER_SOFT_FLOAT "} \
+     %{!mfloat-abi=*:" GLIBC_DYNAMIC_LINKER_DEFAULT "}"
+ 
++/* For ARM musl currently supports four dynamic linkers:
++   - ld-musl-arm.so.1 - for the EABI-derived soft-float ABI
++   - ld-musl-armhf.so.1 - for the EABI-derived hard-float ABI
++   - ld-musl-armeb.so.1 - for the EABI-derived soft-float ABI, EB
++   - ld-musl-armebhf.so.1 - for the EABI-derived hard-float ABI, EB
++   musl does not support the legacy OABI mode.
++   All the dynamic linkers live in /lib.
++   We default to soft-float, EL. */
++#undef  MUSL_DYNAMIC_LINKER
++#if TARGET_BIG_ENDIAN_DEFAULT
++#define MUSL_DYNAMIC_LINKER_E "%{mlittle-endian:;:eb}"
++#else
++#define MUSL_DYNAMIC_LINKER_E "%{mbig-endian:eb}"
++#endif
++#define MUSL_DYNAMIC_LINKER \
++  "/lib/ld-musl-arm" MUSL_DYNAMIC_LINKER_E "%{mfloat-abi=hard:hf}.so.1"
++
+ /* At this point, bpabi.h will have clobbered LINK_SPEC.  We want to
+    use the GNU/Linux version, not the generic BPABI version.  */
+ #undef  LINK_SPEC
+diff -r 42eeea84a212 libitm/config/arm/hwcap.cc
+--- a/libitm/config/arm/hwcap.cc	Tue May 27 17:19:07 2014 -0400
++++ b/libitm/config/arm/hwcap.cc	Tue May 27 17:19:11 2014 -0400
+@@ -40,7 +40,11 @@
+ 
+ #ifdef __linux__
+ #include <unistd.h>
++#ifdef __GLIBC__
+ #include <sys/fcntl.h>
++#else
++#include <fcntl.h>
++#endif
+ #include <elf.h>
+ 
+ static void __attribute__((constructor))
+# HG changeset patch
+# Parent fae0f2a79418e010ac48deb6dc84b16524158f4d
+Support for mips-linux-musl.
+
+diff -r fae0f2a79418 gcc/config/mips/linux.h
+--- a/gcc/config/mips/linux.h	Tue May 27 17:19:10 2014 -0400
++++ b/gcc/config/mips/linux.h	Tue May 27 17:19:14 2014 -0400
+@@ -18,3 +18,10 @@
+ <http://www.gnu.org/licenses/>.  */
+ 
+ #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
++
++#if TARGET_ENDIAN_DEFAULT == 0 /* LE */
++#define MUSL_DYNAMIC_LINKER_E "%{EB:;:el}"
++#else
++#define MUSL_DYNAMIC_LINKER_E "%{EL:el}"
++#endif
++#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-mips" MUSL_DYNAMIC_LINKER_E ".so.1"
+# HG changeset patch
+# Parent 5f732d28ac6e18a515050808509c12a97a63af48
+Support for powerpc-linux-musl.
+
+diff -r 5f732d28ac6e gcc/config.gcc
+--- a/gcc/config.gcc	Tue May 27 17:19:13 2014 -0400
++++ b/gcc/config.gcc	Tue May 27 17:19:17 2014 -0400
+@@ -2138,6 +2138,10 @@
+ 	    powerpc*-*-linux*paired*)
+ 		tm_file="${tm_file} rs6000/750cl.h" ;;
+ 	esac
++        case ${target} in
++            *-linux*-musl*)
++                enable_secureplt=yes ;;
++        esac
+ 	if test x${enable_secureplt} = xyes; then
+ 		tm_file="rs6000/secureplt.h ${tm_file}"
+ 	fi
+diff -r 5f732d28ac6e gcc/config/rs6000/linux64.h
+--- a/gcc/config/rs6000/linux64.h	Tue May 27 17:19:13 2014 -0400
++++ b/gcc/config/rs6000/linux64.h	Tue May 27 17:19:17 2014 -0400
+@@ -374,17 +374,21 @@
+ #endif
+ #define UCLIBC_DYNAMIC_LINKER32 "/lib/ld-uClibc.so.0"
+ #define UCLIBC_DYNAMIC_LINKER64 "/lib/ld64-uClibc.so.0"
++#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-powerpc.so.1"
++#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-powerpc64.so.1"
+ #if DEFAULT_LIBC == LIBC_UCLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
+ #elif DEFAULT_LIBC == LIBC_GLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
++#elif DEFAULT_LIBC == LIBC_MUSL
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
+ #else
+ #error "Unsupported DEFAULT_LIBC"
+ #endif
+ #define GNU_USER_DYNAMIC_LINKER32 \
+-  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32)
++  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
+ #define GNU_USER_DYNAMIC_LINKER64 \
+-  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64)
++  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
+ 
+ #undef  DEFAULT_ASM_ENDIAN
+ #if (TARGET_DEFAULT & MASK_LITTLE_ENDIAN)
+diff -r 5f732d28ac6e gcc/config/rs6000/secureplt.h
+--- a/gcc/config/rs6000/secureplt.h	Tue May 27 17:19:13 2014 -0400
++++ b/gcc/config/rs6000/secureplt.h	Tue May 27 17:19:17 2014 -0400
+@@ -18,3 +18,4 @@
+ <http://www.gnu.org/licenses/>.  */
+ 
+ #define CC1_SECURE_PLT_DEFAULT_SPEC "-msecure-plt"
++#define LINK_SECURE_PLT_DEFAULT_SPEC "--secure-plt"
+diff -r 5f732d28ac6e gcc/config/rs6000/sysv4.h
+--- a/gcc/config/rs6000/sysv4.h	Tue May 27 17:19:13 2014 -0400
++++ b/gcc/config/rs6000/sysv4.h	Tue May 27 17:19:17 2014 -0400
+@@ -537,6 +537,9 @@
+ #ifndef CC1_SECURE_PLT_DEFAULT_SPEC
+ #define CC1_SECURE_PLT_DEFAULT_SPEC ""
+ #endif
++#ifndef LINK_SECURE_PLT_DEFAULT_SPEC
++#define LINK_SECURE_PLT_DEFAULT_SPEC ""
++#endif
+ 
+ /* Pass -G xxx to the compiler.  */
+ #define	CC1_SPEC "%{G*} %(cc1_cpu)" \
+@@ -585,7 +588,8 @@
+ 
+ /* Override the default target of the linker.  */
+ #define	LINK_TARGET_SPEC \
+-  ENDIAN_SELECT("", " --oformat elf32-powerpcle", "")
++  ENDIAN_SELECT("", " --oformat elf32-powerpcle", "") \
++  "%{!mbss-plt: %{!msecure-plt: %(link_secure_plt_default)}}"
+ 
+ /* Any specific OS flags.  */
+ #define LINK_OS_SPEC "\
+@@ -763,15 +767,18 @@
+ 
+ #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
+ #define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0"
++#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-powerpc.so.1"
+ #if DEFAULT_LIBC == LIBC_UCLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
++#elif DEFAULT_LIBC == LIBC_MUSL
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
+ #elif !defined (DEFAULT_LIBC) || DEFAULT_LIBC == LIBC_GLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
+ #else
+ #error "Unsupported DEFAULT_LIBC"
+ #endif
+ #define GNU_USER_DYNAMIC_LINKER \
+-  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER)
++  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
+ 
+ #define LINK_OS_LINUX_SPEC "-m elf32ppclinux %{!shared: %{!static: \
+   %{rdynamic:-export-dynamic} \
+@@ -894,6 +901,7 @@
+   { "link_os_openbsd",		LINK_OS_OPENBSD_SPEC },			\
+   { "link_os_default",		LINK_OS_DEFAULT_SPEC },			\
+   { "cc1_secure_plt_default",	CC1_SECURE_PLT_DEFAULT_SPEC },		\
++  { "link_secure_plt_default",	LINK_SECURE_PLT_DEFAULT_SPEC },		\
+   { "cpp_os_ads",		CPP_OS_ADS_SPEC },			\
+   { "cpp_os_yellowknife",	CPP_OS_YELLOWKNIFE_SPEC },		\
+   { "cpp_os_mvme",		CPP_OS_MVME_SPEC },			\
+diff -r 4d2277f95a50 gcc/config/aarch64/aarch64-linux.h
+--- a/gcc/config/aarch64/aarch64-linux.h	Tue May 27 17:19:17 2014 -0400
++++ b/gcc/config/aarch64/aarch64-linux.h	Tue May 27 17:19:20 2014 -0400
+@@ -21,7 +21,11 @@
+ #ifndef GCC_AARCH64_LINUX_H
+ #define GCC_AARCH64_LINUX_H
+ 
++/* The AArch64 port currently supports two dynamic linkers:
++   - ld-linux-aarch64.so.1 - GLIBC dynamic linker
++   - ld-musl-aarch64.so.1 - musl libc dynamic linker  */
+ #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux-aarch64.so.1"
++#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-aarch64.so.1"
+ 
+ #define CPP_SPEC "%{pthread:-D_REENTRANT}"
+ 
+# HG changeset patch
+# Parent 11f8f95e9940bff12445f189dae33a4a8074ed1a
+Microblaze support (again).
+
+diff -r 11f8f95e9940 gcc/config/microblaze/linux.h
+--- a/gcc/config/microblaze/linux.h	Tue May 27 17:19:20 2014 -0400
++++ b/gcc/config/microblaze/linux.h	Tue May 27 17:19:23 2014 -0400
+@@ -25,7 +25,22 @@
+ #undef TLS_NEEDS_GOT
+ #define TLS_NEEDS_GOT 1
+ 
+-#define DYNAMIC_LINKER "/lib/ld.so.1"
++#if TARGET_BIG_ENDIAN_DEFAULT == 0 /* LE */
++#define MUSL_DYNAMIC_LINKER_E "%{EB:;:el}"
++#else
++#define MUSL_DYNAMIC_LINKER_E "%{EL:el}"
++#endif
++
++#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-microblaze" MUSL_DYNAMIC_LINKER_E ".so.1"
++#define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
++
++#if DEFAULT_LIBC == LIBC_MUSL
++#define DYNAMIC_LINKER MUSL_DYNAMIC_LINKER
++#else
++#define DYNAMIC_LINKER GLIBC_DYNAMIC_LINKER
++#endif
++
++
+ #undef  SUBTARGET_EXTRA_SPECS
+ #define SUBTARGET_EXTRA_SPECS \
+   { "dynamic_linker", DYNAMIC_LINKER }
+From 478ee0c03a08e2ef9371fd88d516738936943e78 Mon Sep 17 00:00:00 2001
+From: David Holsgrove <david.holsgrove@xilinx.com>
+Date: Fri, 28 Sep 2012 16:32:03 +1000
+Subject: [PATCH 06/11] [Patch, microblaze]: Add SIZE_TYPE and PTRDIFF_TYPE to
+ microblaze.h
+
+Fixes warnings like;
+
+warning: format '%zX' expects argument of type 'size_t',
+but argument 3 has type 'unsigned int' [-Wformat]
+
+Changelog
+
+2013-03-18  David Holsgrove <david.holsgrove@xilinx.com>
+
+ * gcc/config/microblaze/microblaze.h: Define SIZE_TYPE
+   and PTRDIFF_TYPE.
+
+Signed-off-by: David Holsgrove <david.holsgrove@xilinx.com>
+---
+ gcc/config/microblaze/microblaze.h |    6 ++++++
+ 1 file changed, 6 insertions(+)
+
+diff -r 2af2905d4b10 gcc/config/microblaze/microblaze.h
+--- a/gcc/config/microblaze/microblaze.h	Tue May 27 17:19:22 2014 -0400
++++ b/gcc/config/microblaze/microblaze.h	Tue May 27 17:19:26 2014 -0400
+@@ -219,6 +219,12 @@
+ #undef PTRDIFF_TYPE
+ #define PTRDIFF_TYPE "int"
+ 
++#undef SIZE_TYPE
++#define SIZE_TYPE "unsigned int"
++
++#undef PTRDIFF_TYPE
++#define PTRDIFF_TYPE "int"
++
+ #define CONSTANT_ALIGNMENT(EXP, ALIGN)					\
+   ((TREE_CODE (EXP) == STRING_CST  || TREE_CODE (EXP) == CONSTRUCTOR)	\
+    && (ALIGN) < BITS_PER_WORD						\
+diff -Nur gcc-4.8.3.orig/gcc/config/microblaze/microblaze.md gcc-4.8.3/gcc/config/microblaze/microblaze.md
+--- gcc-4.8.3.orig/gcc/config/microblaze/microblaze.md	2014-02-23 19:59:26.000000000 +0100
++++ gcc-4.8.3/gcc/config/microblaze/microblaze.md	2014-05-31 20:39:29.978608468 +0200
+@@ -1119,18 +1119,6 @@
+   }
+ )
+ 
+-;;Load and store reverse
+-(define_insn "movsi4_rev"
+-  [(set (match_operand:SI 0 "reg_or_mem_operand" "=r,Q")
+-        (bswap:SI (match_operand:SF 1 "reg_or_mem_operand" "Q,r")))]
+-  "TARGET_REORDER"
+-  "@
+-   lwr\t%0,%y1,r0
+-   swr\t%1,%y0,r0"
+-  [(set_attr "type"     "load,store")
+-  (set_attr "mode"      "SI")
+-  (set_attr "length"    "4,4")])
+-
+ ;; 32-bit floating point moves
+ 
+ (define_expand "movsf"
+diff -r 596e2430c627 gcc/config/sh/linux.h
+--- a/gcc/config/sh/linux.h	Fri Sep 28 16:32:03 2012 +1000
++++ b/gcc/config/sh/linux.h	Tue May 27 17:19:29 2014 -0400
+@@ -43,7 +43,14 @@
+ 
+ #define TARGET_ASM_FILE_END file_end_indicate_exec_stack
+ 
++#if TARGET_BIG_ENDIAN_DEFAULT /* BE */
++#define MUSL_DYNAMIC_LINKER_E "eb"
++#else
++#define MUSL_DYNAMIC_LINKER_E
++#endif
++
+ #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
++#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-sh" MUSL_DYNAMIC_LINKER_E ".so.1"
+ 
+ #undef SUBTARGET_LINK_EMUL_SUFFIX
+ #define SUBTARGET_LINK_EMUL_SUFFIX "_linux"
diff --git a/patches/experimental/gcc/4.9.0/0001-musl.patch b/patches/experimental/gcc/4.9.0/0001-musl.patch
new file mode 100644
index 0000000..de6f532
--- /dev/null
+++ b/patches/experimental/gcc/4.9.0/0001-musl.patch
@@ -0,0 +1,706 @@
+This patch enables support for musl-libc in gcc.
+
+This patch is not supported by crosstool-ng and was originally found here:
+    https://bitbucket.org/GregorR/musl-cross/src/27953a1f7085/patches/gcc-4.9.0-musl.diff
+
+Added-By: Bryan Hundven <bryanhundven@gmail.com>
+---
+diff -r 2f9df662aaab libstdc++-v3/configure.host
+--- a/libstdc++-v3/configure.host	Tue May 20 11:00:21 2014 -0400
++++ b/libstdc++-v3/configure.host	Tue May 20 11:05:42 2014 -0400
+@@ -264,6 +264,13 @@
+     os_include_dir="os/bsd/freebsd"
+     ;;
+   gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu)
++    # check for musl by target
++    case "${host_os}" in
++      *-musl*)
++        os_include_dir="os/generic"
++        ;;
++      *)
++
+     if [ "$uclibc" = "yes" ]; then
+       os_include_dir="os/uclibc"
+     elif [ "$bionic" = "yes" ]; then
+@@ -272,6 +279,9 @@
+       os_include_dir="os/gnu-linux"
+     fi
+     ;;
++
++    esac
++    ;;
+   hpux*)
+     os_include_dir="os/hpux"
+     ;;
+# HG changeset patch
+# Parent b6f4ce05a3155dbcbc06d72aebdb67e2f8abc094
+Adding -mmusl as a musl libc specifier, and the necessary hacks for it to know how to find musl's dynamic linker.
+
+diff -r b6f4ce05a315 gcc/config.gcc
+--- a/gcc/config.gcc	Tue May 20 11:05:42 2014 -0400
++++ b/gcc/config.gcc	Tue May 20 11:05:45 2014 -0400
+@@ -594,7 +594,7 @@
+ esac
+ 
+ # Common C libraries.
+-tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3"
++tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3 LIBC_MUSL=4"
+ 
+ # 32-bit x86 processors supported by --with-arch=.  Each processor
+ # MUST be separated by exactly one space.
+@@ -719,6 +719,9 @@
+     *-*-*uclibc*)
+       tm_defines="$tm_defines DEFAULT_LIBC=LIBC_UCLIBC"
+       ;;
++    *-*-*musl*)
++      tm_defines="$tm_defines DEFAULT_LIBC=LIBC_MUSL"
++      ;;
+     *)
+       tm_defines="$tm_defines DEFAULT_LIBC=LIBC_GLIBC"
+       ;;
+diff -r b6f4ce05a315 gcc/config/linux.h
+--- a/gcc/config/linux.h	Tue May 20 11:05:42 2014 -0400
++++ b/gcc/config/linux.h	Tue May 20 11:05:45 2014 -0400
+@@ -32,10 +32,12 @@
+ #define OPTION_GLIBC  (DEFAULT_LIBC == LIBC_GLIBC)
+ #define OPTION_UCLIBC (DEFAULT_LIBC == LIBC_UCLIBC)
+ #define OPTION_BIONIC (DEFAULT_LIBC == LIBC_BIONIC)
++#define OPTION_MUSL   (DEFAULT_LIBC == LIBC_MUSL)
+ #else
+ #define OPTION_GLIBC  (linux_libc == LIBC_GLIBC)
+ #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
+ #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
++#define OPTION_MUSL   (linux_libc == LIBC_MUSL)
+ #endif
+ 
+ #define GNU_USER_TARGET_OS_CPP_BUILTINS()			\
+@@ -53,18 +55,21 @@
+    uClibc or Bionic is the default C library and whether
+    -muclibc or -mglibc or -mbionic has been passed to change the default.  */
+ 
+-#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LD1, LD2, LD3)	\
+-  "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:" LD1 "}}"
++#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LIBC4, LD1, LD2, LD3, LD4)	\
++  "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:%{" LIBC4 ":" LD4 ";:" LD1 "}}}"
+ 
+ #if DEFAULT_LIBC == LIBC_GLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
+-  CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", G, U, B)
++#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
++  CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", "mmusl", G, U, B, M)
+ #elif DEFAULT_LIBC == LIBC_UCLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
+-  CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", U, G, B)
++#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
++  CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", "mmusl", U, G, B, M)
+ #elif DEFAULT_LIBC == LIBC_BIONIC
+-#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
+-  CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", B, G, U)
++#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
++  CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", "mmusl", B, G, U, M)
++#elif DEFAULT_LIBC == LIBC_MUSL
++#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
++  CHOOSE_DYNAMIC_LINKER1 ("mmusl", "mglibc", "muclibc", "mbionic", M, G, U, B)
+ #else
+ #error "Unsupported DEFAULT_LIBC"
+ #endif /* DEFAULT_LIBC */
+@@ -84,21 +89,92 @@
+ 
+ #define GNU_USER_DYNAMIC_LINKER						\
+   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER,	\
+-			 BIONIC_DYNAMIC_LINKER)
++			 BIONIC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
+ #define GNU_USER_DYNAMIC_LINKER32					\
+   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, \
+-			 BIONIC_DYNAMIC_LINKER32)
++			 BIONIC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
+ #define GNU_USER_DYNAMIC_LINKER64					\
+   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
+-			 BIONIC_DYNAMIC_LINKER64)
++			 BIONIC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
+ #define GNU_USER_DYNAMIC_LINKERX32					\
+   CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \
+-			 BIONIC_DYNAMIC_LINKERX32)
++			 BIONIC_DYNAMIC_LINKERX32, MUSL_DYNAMIC_LINKERX32)
+ 
+ /* Whether we have Bionic libc runtime */
+ #undef TARGET_HAS_BIONIC
+ #define TARGET_HAS_BIONIC (OPTION_BIONIC)
+ 
++/* musl avoids problematic includes by rearranging the include directories.
++ * Unfortunately, this is mostly duplicated from cppdefault.c */
++#if DEFAULT_LIBC == LIBC_MUSL
++#define INCLUDE_DEFAULTS_MUSL_GPP			\
++    { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1,		\
++      GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },		\
++    { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1,		\
++      GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 },		\
++    { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1,	\
++      GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },
++
++#ifdef LOCAL_INCLUDE_DIR
++#define INCLUDE_DEFAULTS_MUSL_LOCAL			\
++    { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 },		\
++    { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 },
++#else
++#define INCLUDE_DEFAULTS_MUSL_LOCAL
++#endif
++
++#ifdef PREFIX_INCLUDE_DIR
++#define INCLUDE_DEFAULTS_MUSL_PREFIX			\
++    { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0},
++#else
++#define INCLUDE_DEFAULTS_MUSL_PREFIX
++#endif
++
++#ifdef CROSS_INCLUDE_DIR
++#define INCLUDE_DEFAULTS_MUSL_CROSS			\
++    { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0},
++#else
++#define INCLUDE_DEFAULTS_MUSL_CROSS
++#endif
++
++#ifdef TOOL_INCLUDE_DIR
++#define INCLUDE_DEFAULTS_MUSL_TOOL			\
++    { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0},
++#else
++#define INCLUDE_DEFAULTS_MUSL_TOOL
++#endif
++
++#ifdef NATIVE_SYSTEM_HEADER_DIR
++#define INCLUDE_DEFAULTS_MUSL_NATIVE			\
++    { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 2 },	\
++    { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 0 },
++#else
++#define INCLUDE_DEFAULTS_MUSL_NATIVE
++#endif
++
++#if defined (CROSS_DIRECTORY_STRUCTURE) && !defined (TARGET_SYSTEM_ROOT)
++# undef INCLUDE_DEFAULTS_MUSL_LOCAL
++# define INCLUDE_DEFAULTS_MUSL_LOCAL
++# undef INCLUDE_DEFAULTS_MUSL_NATIVE
++# define INCLUDE_DEFAULTS_MUSL_NATIVE
++#else
++# undef INCLUDE_DEFAULTS_MUSL_CROSS
++# define INCLUDE_DEFAULTS_MUSL_CROSS
++#endif
++
++#undef INCLUDE_DEFAULTS
++#define INCLUDE_DEFAULTS				\
++  {							\
++    INCLUDE_DEFAULTS_MUSL_GPP				\
++    INCLUDE_DEFAULTS_MUSL_PREFIX			\
++    INCLUDE_DEFAULTS_MUSL_CROSS				\
++    INCLUDE_DEFAULTS_MUSL_TOOL				\
++    INCLUDE_DEFAULTS_MUSL_NATIVE			\
++    { GCC_INCLUDE_DIR, "GCC", 0, 1, 0, 0 },		\
++    { 0, 0, 0, 0, 0, 0 }				\
++  }
++#endif
++
+ #if (DEFAULT_LIBC == LIBC_UCLIBC) && defined (SINGLE_LIBC) /* uClinux */
+ /* This is a *uclinux* target.  We don't define below macros to normal linux
+    versions, because doing so would require *uclinux* targets to include
+diff -r b6f4ce05a315 gcc/config/linux.opt
+--- a/gcc/config/linux.opt	Tue May 20 11:05:42 2014 -0400
++++ b/gcc/config/linux.opt	Tue May 20 11:05:45 2014 -0400
+@@ -30,3 +30,7 @@
+ muclibc
+ Target Report RejectNegative Var(linux_libc,LIBC_UCLIBC) Negative(mbionic)
+ Use uClibc C library
++
++mmusl
++Target Report RejectNegative Var(linux_libc,LIBC_MUSL) Negative(mglibc)
++Use musl C library
+diff -r b6f4ce05a315 gcc/ginclude/stddef.h
+--- a/gcc/ginclude/stddef.h	Tue May 20 11:05:42 2014 -0400
++++ b/gcc/ginclude/stddef.h	Tue May 20 11:05:45 2014 -0400
+@@ -181,6 +181,7 @@
+ #ifndef _GCC_SIZE_T
+ #ifndef _SIZET_
+ #ifndef __size_t
++#ifndef __DEFINED_size_t /* musl */
+ #define __size_t__	/* BeOS */
+ #define __SIZE_T__	/* Cray Unicos/Mk */
+ #define _SIZE_T
+@@ -197,6 +198,7 @@
+ #define ___int_size_t_h
+ #define _GCC_SIZE_T
+ #define _SIZET_
++#define __DEFINED_size_t /* musl */
+ #if (defined (__FreeBSD__) && (__FreeBSD__ >= 5)) \
+   || defined(__FreeBSD_kernel__)
+ /* __size_t is a typedef on FreeBSD 5, must not trash it. */
+@@ -214,6 +216,7 @@
+ typedef long ssize_t;
+ #endif /* __BEOS__ */
+ #endif /* !(defined (__GNUG__) && defined (size_t)) */
++#endif /* __DEFINED_size_t */
+ #endif /* __size_t */
+ #endif /* _SIZET_ */
+ #endif /* _GCC_SIZE_T */
+# HG changeset patch
+# Parent 65d595ef9fc3cdbbde4894d927593f1b0f5bbcb7
+A fix for libgomp to correctly request a POSIX version for time support.
+
+diff -r 65d595ef9fc3 libgomp/config/posix/time.c
+--- a/libgomp/config/posix/time.c	Tue May 20 11:05:45 2014 -0400
++++ b/libgomp/config/posix/time.c	Tue May 20 11:05:48 2014 -0400
+@@ -28,6 +28,8 @@
+    The following implementation uses the most simple POSIX routines.
+    If present, POSIX 4 clocks should be used instead.  */
+ 
++#define _POSIX_C_SOURCE 199309L /* for clocks */
++
+ #include "libgomp.h"
+ #include <unistd.h>
+ #if TIME_WITH_SYS_TIME
+diff -r 95f4f1d7668b libgcc/unwind-dw2-fde-dip.c
+--- a/libgcc/unwind-dw2-fde-dip.c	Tue May 20 11:05:48 2014 -0400
++++ b/libgcc/unwind-dw2-fde-dip.c	Tue May 20 11:05:52 2014 -0400
+@@ -46,33 +46,13 @@
+ #include "unwind-compat.h"
+ #include "gthr.h"
+ 
+-#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
+-    && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) \
+-	|| (__GLIBC__ == 2 && __GLIBC_MINOR__ == 2 && defined(DT_CONFIG)))
++#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) && defined(TARGET_DL_ITERATE_PHDR)
+ # define USE_PT_GNU_EH_FRAME
+-#endif
+-
+-#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
+-    && defined(__BIONIC__)
+-# define USE_PT_GNU_EH_FRAME
+-#endif
+-
+-#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
+-    && defined(__FreeBSD__) && __FreeBSD__ >= 7
+-# define ElfW __ElfN
+-# define USE_PT_GNU_EH_FRAME
+-#endif
+-
+-#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
+-    && defined(__OpenBSD__)
+-# define ElfW(type) Elf_##type
+-# define USE_PT_GNU_EH_FRAME
+-#endif
+-
+-#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
+-    && defined(TARGET_DL_ITERATE_PHDR) \
+-    && defined(__sun__) && defined(__svr4__)
+-# define USE_PT_GNU_EH_FRAME
++# ifdef __OpenBSD__
++#  define ElfW(type) Elf_##type
++# elif defined(__FreeBSD__) && __FreeBSD__ >= 7
++#  define ElfW __ElfN
++# endif
+ #endif
+ 
+ #if defined(USE_PT_GNU_EH_FRAME)
+diff -r ff03fa61c6b3 gcc/configure
+--- a/gcc/configure	Tue May 20 11:05:51 2014 -0400
++++ b/gcc/configure	Tue May 20 11:05:55 2014 -0400
+@@ -27300,6 +27300,9 @@
+ else
+   gcc_cv_libc_provides_ssp=no
+     case "$target" in
++       *-*-musl*)
++         # All versions of musl provide stack protector
++	 gcc_cv_libc_provides_ssp=yes;;
+        *-*-linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu)
+       # glibc 2.4 and later provides __stack_chk_fail and
+       # either __stack_chk_guard, or TLS access to stack guard canary.
+@@ -27332,6 +27335,7 @@
+ 	 # <http://gcc.gnu.org/ml/gcc/2008-10/msg00130.html>) and for now
+ 	 # simply assert that glibc does provide this, which is true for all
+ 	 # realistically usable GNU/Hurd configurations.
++	 # All supported versions of musl provide it as well
+ 	 gcc_cv_libc_provides_ssp=yes;;
+        *-*-darwin* | *-*-freebsd*)
+ 	 ac_fn_c_check_func "$LINENO" "__stack_chk_fail" "ac_cv_func___stack_chk_fail"
+@@ -27421,6 +27425,9 @@
+       gcc_cv_target_dl_iterate_phdr=no
+     fi
+     ;;
++  *-linux-musl*)
++    gcc_cv_target_dl_iterate_phdr=yes
++    ;;
+ esac
+ 
+ if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
+diff -r ff03fa61c6b3 gcc/configure.ac
+--- a/gcc/configure.ac	Tue May 20 11:05:51 2014 -0400
++++ b/gcc/configure.ac	Tue May 20 11:05:55 2014 -0400
+@@ -5001,6 +5001,9 @@
+       gcc_cv_libc_provides_ssp,
+       [gcc_cv_libc_provides_ssp=no
+     case "$target" in
++       *-*-musl*)
++         # All versions of musl provide stack protector
++	 gcc_cv_libc_provides_ssp=yes;;
+        *-*-linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu)
+       # glibc 2.4 and later provides __stack_chk_fail and
+       # either __stack_chk_guard, or TLS access to stack guard canary.
+@@ -5027,6 +5030,7 @@
+ 	 # <http://gcc.gnu.org/ml/gcc/2008-10/msg00130.html>) and for now
+ 	 # simply assert that glibc does provide this, which is true for all
+ 	 # realistically usable GNU/Hurd configurations.
++	 # All supported versions of musl provide it as well
+ 	 gcc_cv_libc_provides_ssp=yes;;
+        *-*-darwin* | *-*-freebsd*)
+ 	 AC_CHECK_FUNC(__stack_chk_fail,[gcc_cv_libc_provides_ssp=yes],
+@@ -5093,6 +5097,9 @@
+       gcc_cv_target_dl_iterate_phdr=no
+     fi
+     ;;
++  *-linux-musl*)
++    gcc_cv_target_dl_iterate_phdr=yes
++    ;;
+ esac
+ GCC_TARGET_TEMPLATE([TARGET_DL_ITERATE_PHDR])
+ if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
+# HG changeset patch
+# Parent 26f591b9e77e3df3d0f772b840bd9c13ec24bd4c
+Get rid of ever-broken fixincludes on musl.
+
+diff -r 26f591b9e77e fixincludes/mkfixinc.sh
+--- a/fixincludes/mkfixinc.sh	Tue May 20 11:05:55 2014 -0400
++++ b/fixincludes/mkfixinc.sh	Tue May 20 11:05:58 2014 -0400
+@@ -19,7 +19,8 @@
+     powerpc-*-eabi*    | \
+     powerpc-*-rtems*   | \
+     powerpcle-*-eabisim* | \
+-    powerpcle-*-eabi* )
++    powerpcle-*-eabi* | \
++    *-musl* )
+ 	#  IF there is no include fixing,
+ 	#  THEN create a no-op fixer and exit
+ 	(echo "#! /bin/sh" ; echo "exit 0" ) > ${target}
+# HG changeset patch
+# Parent bc117c35705fcc39396c19af046101411f251161
+Support for i386-linux-musl and x86_64-linux-musl.
+
+diff -r bc117c35705f gcc/config/i386/linux.h
+--- a/gcc/config/i386/linux.h	Tue May 20 11:05:58 2014 -0400
++++ b/gcc/config/i386/linux.h	Tue May 20 11:06:01 2014 -0400
+@@ -21,3 +21,4 @@
+ 
+ #define GNU_USER_LINK_EMULATION "elf_i386"
+ #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
++#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-i386.so.1"
+diff -r bc117c35705f gcc/config/i386/linux64.h
+--- a/gcc/config/i386/linux64.h	Tue May 20 11:05:58 2014 -0400
++++ b/gcc/config/i386/linux64.h	Tue May 20 11:06:01 2014 -0400
+@@ -30,3 +30,7 @@
+ #define GLIBC_DYNAMIC_LINKER32 "/lib/ld-linux.so.2"
+ #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-linux-x86-64.so.2"
+ #define GLIBC_DYNAMIC_LINKERX32 "/libx32/ld-linux-x32.so.2"
++
++#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-i386.so.1"
++#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-x86_64.so.1"
++#define MUSL_DYNAMIC_LINKERX32 "/lib/ld-musl-x32.so.1"
+diff -r bc117c35705f libitm/config/linux/x86/tls.h
+--- a/libitm/config/linux/x86/tls.h	Tue May 20 11:05:58 2014 -0400
++++ b/libitm/config/linux/x86/tls.h	Tue May 20 11:06:01 2014 -0400
+@@ -25,16 +25,19 @@
+ #ifndef LIBITM_X86_TLS_H
+ #define LIBITM_X86_TLS_H 1
+ 
+-#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
++#if defined(__GLIBC_PREREQ)
++#if __GLIBC_PREREQ(2, 10)
+ /* Use slots in the TCB head rather than __thread lookups.
+    GLIBC has reserved words 10 through 13 for TM.  */
+ #define HAVE_ARCH_GTM_THREAD 1
+ #define HAVE_ARCH_GTM_THREAD_DISP 1
+ #endif
++#endif
+ 
+ #include "config/generic/tls.h"
+ 
+-#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
++#if defined(__GLIBC_PREREQ)
++#if __GLIBC_PREREQ(2, 10)
+ namespace GTM HIDDEN {
+ 
+ #ifdef __x86_64__
+@@ -101,5 +104,6 @@
+ 
+ } // namespace GTM
+ #endif /* >= GLIBC 2.10 */
++#endif
+ 
+ #endif // LIBITM_X86_TLS_H
+# HG changeset patch
+# Parent 933c4f064622eb96a0b2ab213abd0cddbd977d1a
+Support for arm-linux-musl.
+
+diff -r 933c4f064622 gcc/config/arm/linux-eabi.h
+--- a/gcc/config/arm/linux-eabi.h	Tue May 20 11:06:01 2014 -0400
++++ b/gcc/config/arm/linux-eabi.h	Tue May 20 11:06:04 2014 -0400
+@@ -77,6 +77,23 @@
+     %{mfloat-abi=soft*:" GLIBC_DYNAMIC_LINKER_SOFT_FLOAT "} \
+     %{!mfloat-abi=*:" GLIBC_DYNAMIC_LINKER_DEFAULT "}"
+ 
++/* For ARM musl currently supports four dynamic linkers:
++   - ld-musl-arm.so.1 - for the EABI-derived soft-float ABI
++   - ld-musl-armhf.so.1 - for the EABI-derived hard-float ABI
++   - ld-musl-armeb.so.1 - for the EABI-derived soft-float ABI, EB
++   - ld-musl-armebhf.so.1 - for the EABI-derived hard-float ABI, EB
++   musl does not support the legacy OABI mode.
++   All the dynamic linkers live in /lib.
++   We default to soft-float, EL. */
++#undef  MUSL_DYNAMIC_LINKER
++#if TARGET_BIG_ENDIAN_DEFAULT
++#define MUSL_DYNAMIC_LINKER_E "%{mlittle-endian:;:eb}"
++#else
++#define MUSL_DYNAMIC_LINKER_E "%{mbig-endian:eb}"
++#endif
++#define MUSL_DYNAMIC_LINKER \
++  "/lib/ld-musl-arm" MUSL_DYNAMIC_LINKER_E "%{mfloat-abi=hard:hf}.so.1"
++
+ /* At this point, bpabi.h will have clobbered LINK_SPEC.  We want to
+    use the GNU/Linux version, not the generic BPABI version.  */
+ #undef  LINK_SPEC
+diff -r 933c4f064622 libitm/config/arm/hwcap.cc
+--- a/libitm/config/arm/hwcap.cc	Tue May 20 11:06:01 2014 -0400
++++ b/libitm/config/arm/hwcap.cc	Tue May 20 11:06:04 2014 -0400
+@@ -40,7 +40,11 @@
+ 
+ #ifdef __linux__
+ #include <unistd.h>
++#ifdef __GLIBC__
+ #include <sys/fcntl.h>
++#else
++#include <fcntl.h>
++#endif
+ #include <elf.h>
+ 
+ static void __attribute__((constructor))
+# HG changeset patch
+# Parent 03fe896f3acaa911e935a8e999d15c7542ee73d1
+Support for mips-linux-musl.
+
+diff -r 03fe896f3aca gcc/config/mips/linux.h
+--- a/gcc/config/mips/linux.h	Tue May 20 11:06:04 2014 -0400
++++ b/gcc/config/mips/linux.h	Tue May 20 11:06:08 2014 -0400
+@@ -23,3 +23,10 @@
+ #undef UCLIBC_DYNAMIC_LINKER
+ #define UCLIBC_DYNAMIC_LINKER \
+   "%{mnan=2008:/lib/ld-uClibc-mipsn8.so.0;:/lib/ld-uClibc.so.0}"
++
++#if TARGET_ENDIAN_DEFAULT == 0 /* LE */
++#define MUSL_DYNAMIC_LINKER_E "%{EB:;:el}"
++#else
++#define MUSL_DYNAMIC_LINKER_E "%{EL:el}"
++#endif
++#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-mips" MUSL_DYNAMIC_LINKER_E ".so.1"
+# HG changeset patch
+# Parent 6097333f2ab47a4ce37ccfb18b0f07a0cdcfec49
+Support for powerpc-linux-musl.
+
+diff -r 6097333f2ab4 gcc/config.gcc
+--- a/gcc/config.gcc	Tue May 20 11:06:08 2014 -0400
++++ b/gcc/config.gcc	Tue May 20 11:06:11 2014 -0400
+@@ -2326,6 +2326,10 @@
+ 	    powerpc*-*-linux*paired*)
+ 		tm_file="${tm_file} rs6000/750cl.h" ;;
+ 	esac
++        case ${target} in
++            *-linux*-musl*)
++                enable_secureplt=yes ;;
++        esac
+ 	if test x${enable_secureplt} = xyes; then
+ 		tm_file="rs6000/secureplt.h ${tm_file}"
+ 	fi
+diff -r 6097333f2ab4 gcc/config/rs6000/linux64.h
+--- a/gcc/config/rs6000/linux64.h	Tue May 20 11:06:08 2014 -0400
++++ b/gcc/config/rs6000/linux64.h	Tue May 20 11:06:11 2014 -0400
+@@ -375,17 +375,21 @@
+ #endif
+ #define UCLIBC_DYNAMIC_LINKER32 "/lib/ld-uClibc.so.0"
+ #define UCLIBC_DYNAMIC_LINKER64 "/lib/ld64-uClibc.so.0"
++#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-powerpc.so.1"
++#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-powerpc64.so.1"
+ #if DEFAULT_LIBC == LIBC_UCLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
+ #elif DEFAULT_LIBC == LIBC_GLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
++#elif DEFAULT_LIBC == LIBC_MUSL
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
+ #else
+ #error "Unsupported DEFAULT_LIBC"
+ #endif
+ #define GNU_USER_DYNAMIC_LINKER32 \
+-  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32)
++  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
+ #define GNU_USER_DYNAMIC_LINKER64 \
+-  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64)
++  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
+ 
+ #undef  DEFAULT_ASM_ENDIAN
+ #if (TARGET_DEFAULT & MASK_LITTLE_ENDIAN)
+diff -r 6097333f2ab4 gcc/config/rs6000/secureplt.h
+--- a/gcc/config/rs6000/secureplt.h	Tue May 20 11:06:08 2014 -0400
++++ b/gcc/config/rs6000/secureplt.h	Tue May 20 11:06:11 2014 -0400
+@@ -18,3 +18,4 @@
+ <http://www.gnu.org/licenses/>.  */
+ 
+ #define CC1_SECURE_PLT_DEFAULT_SPEC "-msecure-plt"
++#define LINK_SECURE_PLT_DEFAULT_SPEC "--secure-plt"
+diff -r 6097333f2ab4 gcc/config/rs6000/sysv4.h
+--- a/gcc/config/rs6000/sysv4.h	Tue May 20 11:06:08 2014 -0400
++++ b/gcc/config/rs6000/sysv4.h	Tue May 20 11:06:11 2014 -0400
+@@ -537,6 +537,9 @@
+ #ifndef CC1_SECURE_PLT_DEFAULT_SPEC
+ #define CC1_SECURE_PLT_DEFAULT_SPEC ""
+ #endif
++#ifndef LINK_SECURE_PLT_DEFAULT_SPEC
++#define LINK_SECURE_PLT_DEFAULT_SPEC ""
++#endif
+ 
+ /* Pass -G xxx to the compiler.  */
+ #define	CC1_SPEC "%{G*} %(cc1_cpu)" \
+@@ -585,7 +588,8 @@
+ 
+ /* Override the default target of the linker.  */
+ #define	LINK_TARGET_SPEC \
+-  ENDIAN_SELECT("", " --oformat elf32-powerpcle", "")
++  ENDIAN_SELECT("", " --oformat elf32-powerpcle", "") \
++  "%{!mbss-plt: %{!msecure-plt: %(link_secure_plt_default)}}"
+ 
+ /* Any specific OS flags.  */
+ #define LINK_OS_SPEC "\
+@@ -763,15 +767,18 @@
+ 
+ #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
+ #define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0"
++#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-powerpc.so.1"
+ #if DEFAULT_LIBC == LIBC_UCLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
++#elif DEFAULT_LIBC == LIBC_MUSL
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
+ #elif !defined (DEFAULT_LIBC) || DEFAULT_LIBC == LIBC_GLIBC
+-#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
++#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
+ #else
+ #error "Unsupported DEFAULT_LIBC"
+ #endif
+ #define GNU_USER_DYNAMIC_LINKER \
+-  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER)
++  CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
+ 
+ #define LINK_OS_LINUX_SPEC "-m elf32ppclinux %{!shared: %{!static: \
+   %{rdynamic:-export-dynamic} \
+@@ -894,6 +901,7 @@
+   { "link_os_openbsd",		LINK_OS_OPENBSD_SPEC },			\
+   { "link_os_default",		LINK_OS_DEFAULT_SPEC },			\
+   { "cc1_secure_plt_default",	CC1_SECURE_PLT_DEFAULT_SPEC },		\
++  { "link_secure_plt_default",	LINK_SECURE_PLT_DEFAULT_SPEC },		\
+   { "cpp_os_ads",		CPP_OS_ADS_SPEC },			\
+   { "cpp_os_yellowknife",	CPP_OS_YELLOWKNIFE_SPEC },		\
+   { "cpp_os_mvme",		CPP_OS_MVME_SPEC },			\
+diff -r 813971b9f083 gcc/config/aarch64/aarch64-linux.h
+--- a/gcc/config/aarch64/aarch64-linux.h	Tue May 20 11:06:11 2014 -0400
++++ b/gcc/config/aarch64/aarch64-linux.h	Tue May 20 11:06:14 2014 -0400
+@@ -23,6 +23,8 @@
+ 
+ #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux-aarch64%{mbig-endian:_be}.so.1"
+ 
++#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-aarch64.so.1"
++
+ #define CPP_SPEC "%{pthread:-D_REENTRANT}"
+ 
+ #define LINUX_TARGET_LINK_SPEC  "%{h*}		\
+# HG changeset patch
+# Parent 4a62a6813db995fe195d47ff73234d455975ac30
+Microblaze support (again).
+
+diff -r 4a62a6813db9 gcc/config/microblaze/linux.h
+--- a/gcc/config/microblaze/linux.h	Tue May 20 11:06:14 2014 -0400
++++ b/gcc/config/microblaze/linux.h	Tue May 20 11:06:17 2014 -0400
+@@ -25,7 +25,22 @@
+ #undef TLS_NEEDS_GOT
+ #define TLS_NEEDS_GOT 1
+ 
+-#define DYNAMIC_LINKER "/lib/ld.so.1"
++#if TARGET_BIG_ENDIAN_DEFAULT == 0 /* LE */
++#define MUSL_DYNAMIC_LINKER_E "%{EB:;:el}"
++#else
++#define MUSL_DYNAMIC_LINKER_E "%{EL:el}"
++#endif
++
++#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-microblaze" MUSL_DYNAMIC_LINKER_E ".so.1"
++#define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
++
++#if DEFAULT_LIBC == LIBC_MUSL
++#define DYNAMIC_LINKER MUSL_DYNAMIC_LINKER
++#else
++#define DYNAMIC_LINKER GLIBC_DYNAMIC_LINKER
++#endif
++
++
+ #undef  SUBTARGET_EXTRA_SPECS
+ #define SUBTARGET_EXTRA_SPECS \
+   { "dynamic_linker", DYNAMIC_LINKER }
+From 478ee0c03a08e2ef9371fd88d516738936943e78 Mon Sep 17 00:00:00 2001
+From: David Holsgrove <david.holsgrove@xilinx.com>
+Date: Fri, 28 Sep 2012 16:32:03 +1000
+Subject: [PATCH 06/11] [Patch, microblaze]: Add SIZE_TYPE and PTRDIFF_TYPE to
+ microblaze.h
+
+Fixes warnings like;
+
+warning: format '%zX' expects argument of type 'size_t',
+but argument 3 has type 'unsigned int' [-Wformat]
+
+Changelog
+
+2013-03-18  David Holsgrove <david.holsgrove@xilinx.com>
+
+ * gcc/config/microblaze/microblaze.h: Define SIZE_TYPE
+   and PTRDIFF_TYPE.
+
+Signed-off-by: David Holsgrove <david.holsgrove@xilinx.com>
+---
+ gcc/config/microblaze/microblaze.h |    6 ++++++
+ 1 file changed, 6 insertions(+)
+
+diff -r 20d1c995f5de gcc/config/microblaze/microblaze.h
+--- a/gcc/config/microblaze/microblaze.h	Tue May 20 11:06:17 2014 -0400
++++ b/gcc/config/microblaze/microblaze.h	Tue May 20 11:06:20 2014 -0400
+@@ -218,6 +218,12 @@
+ #undef PTRDIFF_TYPE
+ #define PTRDIFF_TYPE "int"
+ 
++#undef SIZE_TYPE
++#define SIZE_TYPE "unsigned int"
++
++#undef PTRDIFF_TYPE
++#define PTRDIFF_TYPE "int"
++
+ #define CONSTANT_ALIGNMENT(EXP, ALIGN)					\
+   ((TREE_CODE (EXP) == STRING_CST  || TREE_CODE (EXP) == CONSTRUCTOR)	\
+    && (ALIGN) < BITS_PER_WORD						\
+diff -r 2f999fc929da gcc/config/sh/linux.h
+--- a/gcc/config/sh/linux.h	Fri Sep 28 16:32:03 2012 +1000
++++ b/gcc/config/sh/linux.h	Tue May 20 11:06:23 2014 -0400
+@@ -43,7 +43,14 @@
+ 
+ #define TARGET_ASM_FILE_END file_end_indicate_exec_stack
+ 
++#if TARGET_BIG_ENDIAN_DEFAULT /* BE */
++#define MUSL_DYNAMIC_LINKER_E "eb"
++#else
++#define MUSL_DYNAMIC_LINKER_E
++#endif
++
+ #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
++#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-sh" MUSL_DYNAMIC_LINKER_E ".so.1"
+ 
+ #undef SUBTARGET_LINK_EMUL_SUFFIX
+ #define SUBTARGET_LINK_EMUL_SUFFIX "_linux"
-- 
2.0.1


--
For unsubscribe information see http://sourceware.org/lists.html#faq

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] Add support for musl-libc
  2014-07-27  1:05 ` [PATCH 2/3] Add support for musl-libc Bryan Hundven
@ 2014-07-27 23:15   ` Yann E. MORIN
  2014-07-27 23:50     ` Bryan Hundven
  0 siblings, 1 reply; 7+ messages in thread
From: Yann E. MORIN @ 2014-07-27 23:15 UTC (permalink / raw)
  To: Bryan Hundven; +Cc: crossgcc

Bryan, All,

Here are a few comments...

On 2014-07-26 18:04 -0700, Bryan Hundven spake thusly:
> "Musl-libc is a new standard library to power a new generation of Linux-based
> devices. musl is lightweight, fast, simple, free, and strives to be correct in
> the sense of standards-conformance and safety."
> 
> This patch adds support for musl to be selected and built by crosstool-ng.
> NOTE: Experimental patches are needed for gcc and possibly other components.
> Later patches include this support.

I know we discussed this on IRC, but maybe we were too quick when
setting up the plan. Maybe the patches could be added in this
changeset, no?

I can see that splitting is easier for review, but in the end, it does
not really make sense to add musl support without the gcc patches,
right? So, we may just squash your patches 2 and 3 into a single one
when applying for upstreaming?

> Signed-off-by: Bryan Hundven <bryanhundven@gmail.com>
[--SNIP diffstat--]
> diff --git a/config/libc.in b/config/libc.in
> index 03f5db2..ff9ce9e 100644
> --- a/config/libc.in
> +++ b/config/libc.in
> @@ -28,6 +28,10 @@ config LIBC_SUPPORT_NPTL
>      bool
>      select LIBC_SUPPORT_THREADS_ANY
>  
> +config LIBC_SUPPORT_MUSL
> +    bool
> +    select LIBC_SUPPORT_THREADS_ANY
> +

All changes in this file is to add a new type of threads implementation,
specific to musl.

I've pushed to a temporary WIP clone a reworked infra for threads;
    http://ymorin.is-a-geek.org/git/crosstool-ng/ yem/threads-rework

So, all those changes you've done here should no longer be needed,
hopefully.

>  config LIBC_SUPPORT_LINUXTHREADS
>      bool
>      select LIBC_SUPPORT_THREADS_ANY
> @@ -42,6 +46,7 @@ config LIBC_SUPPORT_THREADS_NONE
>  config THREADS
>      string
>      default "nptl"          if THREADS_NPTL
> +    default "musl"          if THREADS_MUSL

This default should now go into the musl.in file, as:

    config THREADS
        default "XXXX"

We should see if XXX can be set to just "nptl" and abuse that so we have
no special handling to do in the gcc build script.

Otherwise, "musl" is a good compromise, but the gcc build script should
be adapted accordingly, which I don't see in this patch.

[--SNIP--]
> diff --git a/config/libc/musl.in b/config/libc/musl.in
> new file mode 100644
> index 0000000..69f465c
> --- /dev/null
> +++ b/config/libc/musl.in
> @@ -0,0 +1,47 @@
> +# musl options
> +
> +## depends on ! WINDOWS && ! BARE_METAL
> +##
> +## select LIBC_SUPPORT_MUSL
> +## select CC_CORE_PASSES_NEEDED
> +##
> +## help Musl is a new standard library to power a new generation of Linux-based
> +## help devices. musl is lightweight, fast, simple, free, and strives to be
> +## help correct in the sense of standards-conformance and safety.

Here, add the "config THREADS" discussed just above.

it needs not be conditional, since the parsing of this file is already
conditional to musl being selected.

> +choice
> +    bool
> +    prompt "musl version"
> +# Don't remove next line
> +# CT_INSERT_VERSION_BELOW
> +
> +config LIBC_MUSL_V_1_1_3
> +    bool
> +    prompt "1.1.3 (Mainline)"
> +    select LIBC_MUSL_DEFAULTS
> +    depends on EXPERIMENTAL
> +
> +config LIBC_MUSL_V_1_0_3
> +    bool
> +    prompt "1.0.3 (Stable)"
> +    select LIBC_MUSL_DEFAULTS
> +
> +config LIBC_MUSL_V_CUSTOM
> +    bool
> +    prompt "Custom musl"
> +    select LIBC_MUSL_DEFAULTS
> +    depends on EXPERIMENTAL
> +
> +endchoice
> +
> +config LIBC_MUSL_DEFAULTS
> +    bool
> +    select LIBC_SUPPORT_MUSL

No longer needed.

[--SNIP--]
> diff --git a/config/libc/musl.in.2 b/config/libc/musl.in.2
> new file mode 100644
> index 0000000..bf4fb71
> --- /dev/null
> +++ b/config/libc/musl.in.2
> @@ -0,0 +1,2 @@
> +# musl second-part options

If there is nothing to set here, do not provide that file.

[--SNIP--]
> diff --git a/scripts/build/libc/musl.sh b/scripts/build/libc/musl.sh
> new file mode 100644
> index 0000000..f72517c
> --- /dev/null
> +++ b/scripts/build/libc/musl.sh
> @@ -0,0 +1,111 @@

I have not completely reviewd that file, but have at least a few
comments:

[--SNIP--]
> +do_libc_configure() {
> +    CT_DoLog EXTRA "Configuring C library"
> +    local -a extra_cflags
> +
> +    # From buildroot:
> +    # gcc constant folding bug with weak aliases workaround
> +    # See http://www.openwall.com/lists/musl/2014/05/15/1
> +    if [ "${CT_CC_GCC_4_9_or_later}" = "y" ]; then

Completely off-topic: gcc-4.9 is utterly broken. See this thread where
Linus Torvalds, in his usual coloured language, bashes gcc-4.9:
    http://lkml.iu.edu//hypermail/linux/kernel/1407.3/00650.html

> +        extra_cflags+=("-fno-toplevel-reorder")

Is that still needed with the current version of musl?

> +    fi
> +
> +    # NOTE: musl handles the build/host/target a little bit differently
> +    # then one would expect:
> +    #   build   : not used
> +    #   host    : the machine building musl
> +    #   target  : the machine musl runs on
> +    CT_DoExecLog CFG                \
> +    CFLAGS="${extra_cflags[@]}"     \
> +    CROSS_COMPILE="${CT_TARGET}-"   \
> +    ./configure                     \
> +        --host="${CT_BUILD}"        \
> +        --target="${CT_TARGET}"     \
> +        --prefix="/usr"             \
> +        --disable-gcc-wrapper
> +}
> +
> +do_libc_start_files() {
> +    local ARCH
> +
> +    CT_DoStep INFO "Installing C library headers"
> +
> +    # Simply copy files until musl has the ability to build out-of-tree
> +    CT_DoLog EXTRA "Copying sources to build directory"
> +    CT_DoExecLog ALL cp -av "${CT_SRC_DIR}/musl-${CT_LIBC_VERSION}" \
> +                            "${CT_BUILD_DIR}/build-libc-headers"
> +    cd "${CT_BUILD_DIR}/build-libc-headers"
> +
> +    # musl can be installed without gcc if arch is known
> +    case "${CT_TARGET}" in
> +        arm*) ARCH=arm ;;
> +        i?86*) ARCH=i386 ;;
> +        x86_64*) ARCH=x86_64 ;;
> +        mips-*|mipsel-*) ARCH=mips ;;
> +        microblaze-*) ARCH=microblaze ;;
> +        powerpc-*) ARCH=powerpc ;;
> +        sh-*|sh[34]-*) ARCH=sh ;;
> +        x32-*) ARCH=x32 ;;
> +        *) return 1 ;;
> +    esac

You forgot to call do_libc_configure here. That should be the reason for
the incorrect install daggs1-work reported incorrect install path (on
IRC.)

[--SNIP--]
> diff --git a/scripts/functions b/scripts/functions
> index 2e4d4fa..eae3b95 100644
> --- a/scripts/functions
> +++ b/scripts/functions
> @@ -1182,6 +1182,7 @@ CT_DoBuildTargetTuple() {
>      case "${CT_LIBC}" in
>          *glibc) CT_TARGET_SYS=gnu;;
>          uClibc) CT_TARGET_SYS=uclibc;;
> +        musl)   CT_TARGET_SYS=musl;;
>          *)      CT_TARGET_SYS=elf;;
>      esac

Regards,
Yann E. MORIN.

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'

--
For unsubscribe information see http://sourceware.org/lists.html#faq

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] Add main EXPERIMENTAL_PATCHES setting
  2014-07-27  1:05 ` [PATCH 1/3] Add main EXPERIMENTAL_PATCHES setting Bryan Hundven
@ 2014-07-27 23:23   ` Yann E. MORIN
  0 siblings, 0 replies; 7+ messages in thread
From: Yann E. MORIN @ 2014-07-27 23:23 UTC (permalink / raw)
  To: Bryan Hundven; +Cc: crossgcc

Bryan, All,

On 2014-07-26 18:04 -0700, Bryan Hundven spake thusly:
> This change adds support for experimental patches to be introduced to
> crosstool-ng. The patches enabled by this option are to be located here:
> 
>     patches/experimental/<package>/<version>/XXXX-NAME.patch
> 
> Where, XXXX is the patch number to be applied in order, like:
>     0001-some_patch_one.patch
>     0002-some_patch_two.patch
>     9999-some_patch_to_be_applied_last.patch
> 
> In the first patch series, all patches in the EXPERIMENTAL_PATCHES
> option will be applied all at once, or none at all.
> 
> In a later [RFC] patch, I plan on adding finer tuned patch
> enable/disable options based on the name of the patch and where it is
> located in the patches/experimental sub-tree. So the name of the patch
> should use underscores between words in the patch name.
> 
> Signed-off-by: Bryan Hundven <bryanhundven@gmail.com>

Applied, thanks!

I slightly tweaked the prompt, nothing important.

Regards,
Yann E. MORIN.

> ---
>  config/global/ct-behave.in | 10 ++++++++++
>  scripts/functions          | 16 ++++++++++++----
>  2 files changed, 22 insertions(+), 4 deletions(-)
> 
> diff --git a/config/global/ct-behave.in b/config/global/ct-behave.in
> index ba723cf..9f3354f 100644
> --- a/config/global/ct-behave.in
> +++ b/config/global/ct-behave.in
> @@ -29,6 +29,16 @@ config EXPERIMENTAL
>          - non-existant, in which case you could also try hacking it in and send me
>            the result
>  
> +config EXPERIMENTAL_PATCHES
> +    bool
> +    depends on EXPERIMENTAL
> +    prompt "Enable patches marked as EXPERIMENTAL_PATCHES"
> +    help
> +        ***WARNING*** This is not supported by crosstool-ng! ***WARNING***
> +
> +        If you set this to Y, then you will be able to enable experimental
> +        patches that are not supported by crosstool-ng.
> +
>  config ALLOW_BUILD_AS_ROOT
>      bool
>      prompt "Allow building as root user (READ HELP!)"
> diff --git a/scripts/functions b/scripts/functions
> index b15601a..2e4d4fa 100644
> --- a/scripts/functions
> +++ b/scripts/functions
> @@ -1034,6 +1034,8 @@ CT_Patch() {
>      local -a patch_dirs
>      local bundled_patch_dir
>      local local_patch_dir
> +    local bundled_exp_patch_dir
> +    local local_exp_patch_dir
>  
>      if [ "${nochdir}" = "nochdir" ]; then
>          shift
> @@ -1072,11 +1074,17 @@ CT_Patch() {
>      bundled_patch_dir="${CT_LIB_DIR}/patches/${pkgname}/${version}"
>      local_patch_dir="${CT_LOCAL_PATCH_DIR}/${pkgname}/${version}"
>  
> +    # Check for experimental patches, if enabled.
> +    if [ "${CT_EXPERIMENTAL_PATCHES}" = "y" ]; then
> +        bundled_exp_patch_dir="${CT_LIB_DIR}/patches/experimental/${pkgname}/${version}"
> +        local_exp_patch_dir="${CT_LOCAL_PATCH_DIR}/experimental/${pkgname}/${version}"
> +    fi
> +
>      case "${CT_PATCH_ORDER}" in
> -        bundled)        patch_dirs=("${bundled_patch_dir}");;
> -        local)          patch_dirs=("${local_patch_dir}");;
> -        bundled,local)  patch_dirs=("${bundled_patch_dir}" "${local_patch_dir}");;
> -        local,bundled)  patch_dirs=("${local_patch_dir}" "${bundled_patch_dir}");;
> +        bundled)        patch_dirs=("${bundled_patch_dir}" "${bundled_exp_patch_dir}");;
> +        local)          patch_dirs=("${local_patch_dir}" "${local_exp_patch_dir}");;
> +        bundled,local)  patch_dirs=("${bundled_patch_dir}" "${bundled_exp_patch_dir}" "${local_patch_dir}" "${local_exp_patch_dir}");;
> +        local,bundled)  patch_dirs=("${local_patch_dir}" "${local_exp_patch_dir}" "${bundled_patch_dir}" "${bundled_exp_patch_dir}");;
>          none)           patch_dirs=;;
>      esac
>  
> -- 
> 2.0.1
> 

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'

--
For unsubscribe information see http://sourceware.org/lists.html#faq

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] Add support for musl-libc
  2014-07-27 23:15   ` Yann E. MORIN
@ 2014-07-27 23:50     ` Bryan Hundven
  0 siblings, 0 replies; 7+ messages in thread
From: Bryan Hundven @ 2014-07-27 23:50 UTC (permalink / raw)
  To: Yann E. MORIN; +Cc: crossgcc maillist

Yann, List,

On Sun, Jul 27, 2014 at 4:15 PM, Yann E. MORIN <yann.morin.1998@free.fr> wrote:
> Bryan, All,
>
> Here are a few comments...
>
> On 2014-07-26 18:04 -0700, Bryan Hundven spake thusly:
>> "Musl-libc is a new standard library to power a new generation of Linux-based
>> devices. musl is lightweight, fast, simple, free, and strives to be correct in
>> the sense of standards-conformance and safety."
>>
>> This patch adds support for musl to be selected and built by crosstool-ng.
>> NOTE: Experimental patches are needed for gcc and possibly other components.
>> Later patches include this support.
>
> I know we discussed this on IRC, but maybe we were too quick when
> setting up the plan. Maybe the patches could be added in this
> changeset, no?
>
> I can see that splitting is easier for review, but in the end, it does
> not really make sense to add musl support without the gcc patches,
> right? So, we may just squash your patches 2 and 3 into a single one
> when applying for upstreaming?

Sure, I'll do that in my next revision. (*cough* plus some other fixes
*cough*) :)

>> Signed-off-by: Bryan Hundven <bryanhundven@gmail.com>
> [--SNIP diffstat--]
>> diff --git a/config/libc.in b/config/libc.in
>> index 03f5db2..ff9ce9e 100644
>> --- a/config/libc.in
>> +++ b/config/libc.in
>> @@ -28,6 +28,10 @@ config LIBC_SUPPORT_NPTL
>>      bool
>>      select LIBC_SUPPORT_THREADS_ANY
>>
>> +config LIBC_SUPPORT_MUSL
>> +    bool
>> +    select LIBC_SUPPORT_THREADS_ANY
>> +
>
> All changes in this file is to add a new type of threads implementation,
> specific to musl.
>
> I've pushed to a temporary WIP clone a reworked infra for threads;
>     http://ymorin.is-a-geek.org/git/crosstool-ng/ yem/threads-rework
>
> So, all those changes you've done here should no longer be needed,
> hopefully.

Excellent!

>>  config LIBC_SUPPORT_LINUXTHREADS
>>      bool
>>      select LIBC_SUPPORT_THREADS_ANY
>> @@ -42,6 +46,7 @@ config LIBC_SUPPORT_THREADS_NONE
>>  config THREADS
>>      string
>>      default "nptl"          if THREADS_NPTL
>> +    default "musl"          if THREADS_MUSL
>
> This default should now go into the musl.in file, as:
>
>     config THREADS
>         default "XXXX"
>
> We should see if XXX can be set to just "nptl" and abuse that so we have
> no special handling to do in the gcc build script.
>
> Otherwise, "musl" is a good compromise, but the gcc build script should
> be adapted accordingly, which I don't see in this patch.

Perfect!

> [--SNIP--]
>> diff --git a/config/libc/musl.in b/config/libc/musl.in
>> new file mode 100644
>> index 0000000..69f465c
>> --- /dev/null
>> +++ b/config/libc/musl.in
>> @@ -0,0 +1,47 @@
>> +# musl options
>> +
>> +## depends on ! WINDOWS && ! BARE_METAL
>> +##
>> +## select LIBC_SUPPORT_MUSL
>> +## select CC_CORE_PASSES_NEEDED
>> +##
>> +## help Musl is a new standard library to power a new generation of Linux-based
>> +## help devices. musl is lightweight, fast, simple, free, and strives to be
>> +## help correct in the sense of standards-conformance and safety.
>
> Here, add the "config THREADS" discussed just above.
>
> it needs not be conditional, since the parsing of this file is already
> conditional to musl being selected.

Right. I like it!

>> +choice
>> +    bool
>> +    prompt "musl version"
>> +# Don't remove next line
>> +# CT_INSERT_VERSION_BELOW
>> +
>> +config LIBC_MUSL_V_1_1_3
>> +    bool
>> +    prompt "1.1.3 (Mainline)"
>> +    select LIBC_MUSL_DEFAULTS
>> +    depends on EXPERIMENTAL
>> +
>> +config LIBC_MUSL_V_1_0_3
>> +    bool
>> +    prompt "1.0.3 (Stable)"
>> +    select LIBC_MUSL_DEFAULTS
>> +
>> +config LIBC_MUSL_V_CUSTOM
>> +    bool
>> +    prompt "Custom musl"
>> +    select LIBC_MUSL_DEFAULTS
>> +    depends on EXPERIMENTAL
>> +
>> +endchoice
>> +
>> +config LIBC_MUSL_DEFAULTS
>> +    bool
>> +    select LIBC_SUPPORT_MUSL
>
> No longer needed.

Check!

> [--SNIP--]
>> diff --git a/config/libc/musl.in.2 b/config/libc/musl.in.2
>> new file mode 100644
>> index 0000000..bf4fb71
>> --- /dev/null
>> +++ b/config/libc/musl.in.2
>> @@ -0,0 +1,2 @@
>> +# musl second-part options
>
> If there is nothing to set here, do not provide that file.

Ack.

> [--SNIP--]
>> diff --git a/scripts/build/libc/musl.sh b/scripts/build/libc/musl.sh
>> new file mode 100644
>> index 0000000..f72517c
>> --- /dev/null
>> +++ b/scripts/build/libc/musl.sh
>> @@ -0,0 +1,111 @@
>
> I have not completely reviewd that file, but have at least a few
> comments:
>
> [--SNIP--]
>> +do_libc_configure() {
>> +    CT_DoLog EXTRA "Configuring C library"
>> +    local -a extra_cflags
>> +
>> +    # From buildroot:
>> +    # gcc constant folding bug with weak aliases workaround
>> +    # See http://www.openwall.com/lists/musl/2014/05/15/1
>> +    if [ "${CT_CC_GCC_4_9_or_later}" = "y" ]; then
>
> Completely off-topic: gcc-4.9 is utterly broken. See this thread where
> Linus Torvalds, in his usual coloured language, bashes gcc-4.9:
>     http://lkml.iu.edu//hypermail/linux/kernel/1407.3/00650.html

Technically:

https://lkml.org/lkml/2014/7/24/584

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61904
"The bad compiler versions are 4.5.0 (when debug_insn came in) to
4.8.3 and 4.9.0 and 4.9.1."

They are all broken, on host/build/target = x86_64, in some configurations.

>> +        extra_cflags+=("-fno-toplevel-reorder")
>
> Is that still needed with the current version of musl?

Yes, I got this from buildroot.

>> +    fi
>> +
>> +    # NOTE: musl handles the build/host/target a little bit differently
>> +    # then one would expect:
>> +    #   build   : not used
>> +    #   host    : the machine building musl
>> +    #   target  : the machine musl runs on
>> +    CT_DoExecLog CFG                \
>> +    CFLAGS="${extra_cflags[@]}"     \
>> +    CROSS_COMPILE="${CT_TARGET}-"   \
>> +    ./configure                     \
>> +        --host="${CT_BUILD}"        \
>> +        --target="${CT_TARGET}"     \
>> +        --prefix="/usr"             \
>> +        --disable-gcc-wrapper
>> +}
>> +
>> +do_libc_start_files() {
>> +    local ARCH
>> +
>> +    CT_DoStep INFO "Installing C library headers"
>> +
>> +    # Simply copy files until musl has the ability to build out-of-tree
>> +    CT_DoLog EXTRA "Copying sources to build directory"
>> +    CT_DoExecLog ALL cp -av "${CT_SRC_DIR}/musl-${CT_LIBC_VERSION}" \
>> +                            "${CT_BUILD_DIR}/build-libc-headers"
>> +    cd "${CT_BUILD_DIR}/build-libc-headers"
>> +
>> +    # musl can be installed without gcc if arch is known
>> +    case "${CT_TARGET}" in
>> +        arm*) ARCH=arm ;;
>> +        i?86*) ARCH=i386 ;;
>> +        x86_64*) ARCH=x86_64 ;;
>> +        mips-*|mipsel-*) ARCH=mips ;;
>> +        microblaze-*) ARCH=microblaze ;;
>> +        powerpc-*) ARCH=powerpc ;;
>> +        sh-*|sh[34]-*) ARCH=sh ;;
>> +        x32-*) ARCH=x32 ;;
>> +        *) return 1 ;;
>> +    esac
>
> You forgot to call do_libc_configure here. That should be the reason for
> the incorrect install daggs1-work reported incorrect install path (on
> IRC.)

Yup, noted, as we discussed on irc. fixed in the next revision (should
fix the sysroot/usr/local/musl/include issue).

> [--SNIP--]
>> diff --git a/scripts/functions b/scripts/functions
>> index 2e4d4fa..eae3b95 100644
>> --- a/scripts/functions
>> +++ b/scripts/functions
>> @@ -1182,6 +1182,7 @@ CT_DoBuildTargetTuple() {
>>      case "${CT_LIBC}" in
>>          *glibc) CT_TARGET_SYS=gnu;;
>>          uClibc) CT_TARGET_SYS=uclibc;;
>> +        musl)   CT_TARGET_SYS=musl;;
>>          *)      CT_TARGET_SYS=elf;;
>>      esac
>
> Regards,
> Yann E. MORIN.
>
> --
> .-----------------.--------------------.------------------.--------------------.
> |  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
> | +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
> | +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
> | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
> '------------------------------^-------^------------------^--------------------'

Thanks for the review!

-Bryan

--
For unsubscribe information see http://sourceware.org/lists.html#faq

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-07-27 23:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-27  1:05 [PATCH 0/3] v2: Experimental patches and musl-libc Bryan Hundven
2014-07-27  1:05 ` [PATCH 2/3] Add support for musl-libc Bryan Hundven
2014-07-27 23:15   ` Yann E. MORIN
2014-07-27 23:50     ` Bryan Hundven
2014-07-27  1:05 ` [PATCH 3/3] Add musl patches for gcc Bryan Hundven
2014-07-27  1:05 ` [PATCH 1/3] Add main EXPERIMENTAL_PATCHES setting Bryan Hundven
2014-07-27 23:23   ` Yann E. MORIN

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).