1 diff --git a/config.sub b/config.sub
4 @@ -125,6 +125,7 @@ esac
5 maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
7 nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
9 linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
10 knetbsd*-gnu* | netbsd*-gnu* | \
11 kopensolaris*-gnu* | \
12 @@ -1346,6 +1347,7 @@ case $os in
13 | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
14 | -mingw32* | -linux-gnu* | -linux-android* \
15 | -linux-newlib* | -linux-uclibc* \
17 | -uxpv* | -beos* | -mpeix* | -udk* \
18 | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
19 | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
20 diff --git a/gcc/config.gcc b/gcc/config.gcc
23 @@ -514,7 +514,7 @@ case ${target} in
27 -tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3"
28 +tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3 LIBC_MUSL=4"
30 # Common parts for widely ported systems.
32 @@ -617,6 +617,9 @@ case ${target} in
34 tm_defines="$tm_defines DEFAULT_LIBC=LIBC_UCLIBC"
37 + tm_defines="$tm_defines DEFAULT_LIBC=LIBC_MUSL"
40 tm_defines="$tm_defines DEFAULT_LIBC=LIBC_GLIBC"
42 diff --git a/gcc/config/arm/linux-eabi.h b/gcc/config/arm/linux-eabi.h
43 --- a/gcc/config/arm/linux-eabi.h
44 +++ b/gcc/config/arm/linux-eabi.h
46 #undef GLIBC_DYNAMIC_LINKER
47 #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.3"
49 +/* musl has no "classic" (i.e. broken) mode */
50 +#undef MUSL_DYNAMIC_LINKER
51 +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-arm.so.1"
53 /* At this point, bpabi.h will have clobbered LINK_SPEC. We want to
54 use the GNU/Linux version, not the generic BPABI version. */
56 diff --git a/gcc/config/i386/linux.h b/gcc/config/i386/linux.h
57 --- a/gcc/config/i386/linux.h
58 +++ b/gcc/config/i386/linux.h
59 @@ -22,3 +22,4 @@ along with GCC; see the file COPYING3. If not see
61 #define GNU_USER_LINK_EMULATION "elf_i386"
62 #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
63 +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-i386.so.1"
64 diff --git a/gcc/config/i386/linux64.h b/gcc/config/i386/linux64.h
65 --- a/gcc/config/i386/linux64.h
66 +++ b/gcc/config/i386/linux64.h
67 @@ -31,3 +31,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
68 #define GLIBC_DYNAMIC_LINKER32 "/lib/ld-linux.so.2"
69 #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-linux-x86-64.so.2"
70 #define GLIBC_DYNAMIC_LINKERX32 "/libx32/ld-linux-x32.so.2"
72 +#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-i386.so.1"
73 +#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-x86_64.so.1"
74 +#define MUSL_DYNAMIC_LINKERX32 "/lib/ld-musl-x32.so.1"
75 diff --git a/gcc/config/linux.h b/gcc/config/linux.h
76 --- a/gcc/config/linux.h
77 +++ b/gcc/config/linux.h
78 @@ -33,10 +33,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
79 #define OPTION_GLIBC (DEFAULT_LIBC == LIBC_GLIBC)
80 #define OPTION_UCLIBC (DEFAULT_LIBC == LIBC_UCLIBC)
81 #define OPTION_BIONIC (DEFAULT_LIBC == LIBC_BIONIC)
82 +#define OPTION_MUSL (DEFAULT_LIBC == LIBC_MUSL)
84 #define OPTION_GLIBC (linux_libc == LIBC_GLIBC)
85 #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
86 #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
87 +#define OPTION_MUSL (linux_libc == LIBC_MUSL)
90 #define GNU_USER_TARGET_OS_CPP_BUILTINS() \
91 @@ -54,18 +56,21 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
92 uClibc or Bionic is the default C library and whether
93 -muclibc or -mglibc or -mbionic has been passed to change the default. */
95 -#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LD1, LD2, LD3) \
96 - "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:" LD1 "}}"
97 +#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LIBC4, LD1, LD2, LD3, LD4) \
98 + "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:%{" LIBC4 ":" LD4 ";:" LD1 "}}}"
100 #if DEFAULT_LIBC == LIBC_GLIBC
101 -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
102 - CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", G, U, B)
103 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
104 + CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", "mmusl", G, U, B, M)
105 #elif DEFAULT_LIBC == LIBC_UCLIBC
106 -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
107 - CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", U, G, B)
108 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
109 + CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", "mmusl", U, G, B, M)
110 #elif DEFAULT_LIBC == LIBC_BIONIC
111 -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
112 - CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", B, G, U)
113 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
114 + CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", "mmusl", B, G, U, M)
115 +#elif DEFAULT_LIBC == LIBC_MUSL
116 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
117 + CHOOSE_DYNAMIC_LINKER1 ("mmusl", "mglibc", "muclibc", "mbionic", M, G, U, B)
119 #error "Unsupported DEFAULT_LIBC"
120 #endif /* DEFAULT_LIBC */
121 @@ -85,16 +90,16 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
123 #define GNU_USER_DYNAMIC_LINKER \
124 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, \
125 - BIONIC_DYNAMIC_LINKER)
126 + BIONIC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
127 #define GNU_USER_DYNAMIC_LINKER32 \
128 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, \
129 - BIONIC_DYNAMIC_LINKER32)
130 + BIONIC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
131 #define GNU_USER_DYNAMIC_LINKER64 \
132 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
133 - BIONIC_DYNAMIC_LINKER64)
134 + BIONIC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
135 #define GNU_USER_DYNAMIC_LINKERX32 \
136 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \
137 - BIONIC_DYNAMIC_LINKERX32)
138 + BIONIC_DYNAMIC_LINKERX32, MUSL_DYNAMIC_LINKERX32)
140 /* Determine whether the entire c99 runtime
141 is present in the runtime library. */
142 diff --git a/gcc/config/linux.opt b/gcc/config/linux.opt
143 --- a/gcc/config/linux.opt
144 +++ b/gcc/config/linux.opt
145 @@ -30,3 +30,7 @@ Use GNU C library
147 Target Report RejectNegative Var(linux_libc,LIBC_UCLIBC) Negative(mbionic)
151 +Target Report RejectNegative Var(linux_libc,LIBC_MUSL) Negative(mglibc)
153 diff --git a/gcc/config/mips/linux.h b/gcc/config/mips/linux.h
154 --- a/gcc/config/mips/linux.h
155 +++ b/gcc/config/mips/linux.h
156 @@ -19,3 +19,5 @@ along with GCC; see the file COPYING3. If not see
157 <http://www.gnu.org/licenses/>. */
159 #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
161 +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-mips.so.1"
162 diff --git a/gcc/ginclude/stddef.h b/gcc/ginclude/stddef.h
163 --- a/gcc/ginclude/stddef.h
164 +++ b/gcc/ginclude/stddef.h
165 @@ -184,6 +184,7 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t;
169 +#ifndef __DEFINED_size_t /* musl */
170 #define __size_t__ /* BeOS */
171 #define __SIZE_T__ /* Cray Unicos/Mk */
173 @@ -200,6 +201,7 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t;
174 #define ___int_size_t_h
177 +#define __DEFINED_size_t /* musl */
178 #if (defined (__FreeBSD__) && (__FreeBSD__ >= 5)) \
179 || defined(__FreeBSD_kernel__)
180 /* __size_t is a typedef on FreeBSD 5, must not trash it. */
181 @@ -215,6 +217,7 @@ typedef __SIZE_TYPE__ size_t;
182 typedef long ssize_t;
183 #endif /* __BEOS__ */
184 #endif /* !(defined (__GNUG__) && defined (size_t)) */
185 +#endif /* __DEFINED_size_t */
186 #endif /* __size_t */
188 #endif /* _GCC_SIZE_T */
189 diff --git a/libgomp/config/posix/time.c b/libgomp/config/posix/time.c
190 --- a/libgomp/config/posix/time.c
191 +++ b/libgomp/config/posix/time.c
193 The following implementation uses the most simple POSIX routines.
194 If present, POSIX 4 clocks should be used instead. */
196 +#define _POSIX_C_SOURCE 199309L /* for clocks */
200 #if TIME_WITH_SYS_TIME
201 diff --git a/libitm/config/arm/hwcap.cc b/libitm/config/arm/hwcap.cc
202 --- a/libitm/config/arm/hwcap.cc
203 +++ b/libitm/config/arm/hwcap.cc
204 @@ -40,7 +40,11 @@ int GTM_hwcap HIDDEN = 0
209 #include <sys/fcntl.h>
215 static void __attribute__((constructor))
216 diff --git a/libitm/config/linux/x86/tls.h b/libitm/config/linux/x86/tls.h
217 --- a/libitm/config/linux/x86/tls.h
218 +++ b/libitm/config/linux/x86/tls.h
220 #ifndef LIBITM_X86_TLS_H
221 #define LIBITM_X86_TLS_H 1
223 -#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
224 +#if defined(__GLIBC_PREREQ)
225 +#if __GLIBC_PREREQ(2, 10)
226 /* Use slots in the TCB head rather than __thread lookups.
227 GLIBC has reserved words 10 through 13 for TM. */
228 #define HAVE_ARCH_GTM_THREAD 1
229 #define HAVE_ARCH_GTM_THREAD_DISP 1
233 #include "config/generic/tls.h"
235 -#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
236 +#if defined(__GLIBC_PREREQ)
237 +#if __GLIBC_PREREQ(2, 10)
238 namespace GTM HIDDEN {
241 @@ -101,5 +104,6 @@ static inline void set_abi_disp(struct abi_dispatch *x)
244 #endif /* >= GLIBC 2.10 */
247 #endif // LIBITM_X86_TLS_H
248 diff --git a/libstdc++-v3/configure.host b/libstdc++-v3/configure.host
249 --- a/libstdc++-v3/configure.host
250 +++ b/libstdc++-v3/configure.host
251 @@ -243,6 +243,13 @@ case "${host_os}" in
252 os_include_dir="os/bsd/freebsd"
254 gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu)
255 + # check for musl by target
256 + case "${host_os}" in
258 + os_include_dir="os/generic"
262 if [ "$uclibc" = "yes" ]; then
263 os_include_dir="os/uclibc"
264 elif [ "$bionic" = "yes" ]; then
265 @@ -251,6 +258,9 @@ case "${host_os}" in
266 os_include_dir="os/gnu-linux"
273 os_include_dir="os/hpux"