40348ac647f90e2c6901cc904dcc0dead8b7ce31
[openwrt/openwrt.git] / toolchain / gcc / patches / 4.7.2 / 200-musl.patch
1 diff --git a/config.sub b/config.sub
2 --- a/config.sub
3 +++ b/config.sub
4 @@ -125,6 +125,7 @@
5 maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
6 case $maybe_os in
7 nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
8 + linux-musl* | \
9 linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
10 knetbsd*-gnu* | netbsd*-gnu* | \
11 kopensolaris*-gnu* | \
12 @@ -1346,6 +1347,7 @@
13 | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
14 | -mingw32* | -linux-gnu* | -linux-android* \
15 | -linux-newlib* | -linux-uclibc* \
16 + | -linux-musl* \
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
21 --- a/gcc/config.gcc
22 +++ b/gcc/config.gcc
23 @@ -522,7 +522,7 @@
24 esac
25
26 # Common C libraries.
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"
29
30 # Common parts for widely ported systems.
31 case ${target} in
32 @@ -625,6 +625,9 @@
33 *-*-*uclibc*)
34 tm_defines="$tm_defines DEFAULT_LIBC=LIBC_UCLIBC"
35 ;;
36 + *-*-*musl*)
37 + tm_defines="$tm_defines DEFAULT_LIBC=LIBC_MUSL"
38 + ;;
39 *)
40 tm_defines="$tm_defines DEFAULT_LIBC=LIBC_GLIBC"
41 ;;
42 @@ -1722,6 +1725,7 @@
43 tm_file="${tm_file} dbxelf.h gnu-user.h linux.h microblaze/linux.h"
44 c_target_objs="${c_target_objs} microblaze-c.o"
45 cxx_target_objs="${cxx_target_objs} microblaze-c.o"
46 + tmake_file="${tmake_file} microblaze/t-microblaze"
47 ;;
48 microblaze*-*-*)
49 tm_file="${tm_file} dbxelf.h"
50 diff --git a/gcc/config/arm/linux-eabi.h b/gcc/config/arm/linux-eabi.h
51 --- a/gcc/config/arm/linux-eabi.h
52 +++ b/gcc/config/arm/linux-eabi.h
53 @@ -64,6 +64,10 @@
54 #undef GLIBC_DYNAMIC_LINKER
55 #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.3"
56
57 +/* musl has no "classic" (i.e. broken) mode */
58 +#undef MUSL_DYNAMIC_LINKER
59 +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-arm.so.1"
60 +
61 /* At this point, bpabi.h will have clobbered LINK_SPEC. We want to
62 use the GNU/Linux version, not the generic BPABI version. */
63 #undef LINK_SPEC
64 diff --git a/gcc/config/i386/linux.h b/gcc/config/i386/linux.h
65 --- a/gcc/config/i386/linux.h
66 +++ b/gcc/config/i386/linux.h
67 @@ -22,3 +22,4 @@
68
69 #define GNU_USER_LINK_EMULATION "elf_i386"
70 #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
71 +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-i386.so.1"
72 diff --git a/gcc/config/i386/linux64.h b/gcc/config/i386/linux64.h
73 --- a/gcc/config/i386/linux64.h
74 +++ b/gcc/config/i386/linux64.h
75 @@ -31,3 +31,7 @@
76 #define GLIBC_DYNAMIC_LINKER32 "/lib/ld-linux.so.2"
77 #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-linux-x86-64.so.2"
78 #define GLIBC_DYNAMIC_LINKERX32 "/libx32/ld-linux-x32.so.2"
79 +
80 +#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-i386.so.1"
81 +#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-x86_64.so.1"
82 +#define MUSL_DYNAMIC_LINKERX32 "/lib/ld-musl-x32.so.1"
83 diff --git a/gcc/config/linux.h b/gcc/config/linux.h
84 --- a/gcc/config/linux.h
85 +++ b/gcc/config/linux.h
86 @@ -33,10 +33,12 @@
87 #define OPTION_GLIBC (DEFAULT_LIBC == LIBC_GLIBC)
88 #define OPTION_UCLIBC (DEFAULT_LIBC == LIBC_UCLIBC)
89 #define OPTION_BIONIC (DEFAULT_LIBC == LIBC_BIONIC)
90 +#define OPTION_MUSL (DEFAULT_LIBC == LIBC_MUSL)
91 #else
92 #define OPTION_GLIBC (linux_libc == LIBC_GLIBC)
93 #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
94 #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
95 +#define OPTION_MUSL (linux_libc == LIBC_MUSL)
96 #endif
97
98 #define GNU_USER_TARGET_OS_CPP_BUILTINS() \
99 @@ -54,18 +56,21 @@
100 uClibc or Bionic is the default C library and whether
101 -muclibc or -mglibc or -mbionic has been passed to change the default. */
102
103 -#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LD1, LD2, LD3) \
104 - "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:" LD1 "}}"
105 +#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LIBC4, LD1, LD2, LD3, LD4) \
106 + "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:%{" LIBC4 ":" LD4 ";:" LD1 "}}}"
107
108 #if DEFAULT_LIBC == LIBC_GLIBC
109 -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
110 - CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", G, U, B)
111 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
112 + CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", "mmusl", G, U, B, M)
113 #elif DEFAULT_LIBC == LIBC_UCLIBC
114 -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
115 - CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", U, G, B)
116 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
117 + CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", "mmusl", U, G, B, M)
118 #elif DEFAULT_LIBC == LIBC_BIONIC
119 -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
120 - CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", B, G, U)
121 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
122 + CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", "mmusl", B, G, U, M)
123 +#elif DEFAULT_LIBC == LIBC_MUSL
124 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
125 + CHOOSE_DYNAMIC_LINKER1 ("mmusl", "mglibc", "muclibc", "mbionic", M, G, U, B)
126 #else
127 #error "Unsupported DEFAULT_LIBC"
128 #endif /* DEFAULT_LIBC */
129 @@ -85,16 +90,16 @@
130
131 #define GNU_USER_DYNAMIC_LINKER \
132 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, \
133 - BIONIC_DYNAMIC_LINKER)
134 + BIONIC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
135 #define GNU_USER_DYNAMIC_LINKER32 \
136 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, \
137 - BIONIC_DYNAMIC_LINKER32)
138 + BIONIC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
139 #define GNU_USER_DYNAMIC_LINKER64 \
140 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
141 - BIONIC_DYNAMIC_LINKER64)
142 + BIONIC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
143 #define GNU_USER_DYNAMIC_LINKERX32 \
144 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \
145 - BIONIC_DYNAMIC_LINKERX32)
146 + BIONIC_DYNAMIC_LINKERX32, MUSL_DYNAMIC_LINKERX32)
147
148 /* Determine whether the entire c99 runtime
149 is present in the runtime library. */
150 diff --git a/gcc/config/linux.opt b/gcc/config/linux.opt
151 --- a/gcc/config/linux.opt
152 +++ b/gcc/config/linux.opt
153 @@ -30,3 +30,7 @@
154 muclibc
155 Target Report RejectNegative Var(linux_libc,LIBC_UCLIBC) Negative(mbionic)
156 Use uClibc C library
157 +
158 +mmusl
159 +Target Report RejectNegative Var(linux_libc,LIBC_MUSL) Negative(mglibc)
160 +Use musl C library
161 diff --git a/gcc/config/mips/linux.h b/gcc/config/mips/linux.h
162 --- a/gcc/config/mips/linux.h
163 +++ b/gcc/config/mips/linux.h
164 @@ -19,3 +19,5 @@
165 <http://www.gnu.org/licenses/>. */
166
167 #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
168 +
169 +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-mips.so.1"
170 diff --git a/gcc/config/rs6000/linux64.h b/gcc/config/rs6000/linux64.h
171 --- a/gcc/config/rs6000/linux64.h
172 +++ b/gcc/config/rs6000/linux64.h
173 @@ -362,17 +362,21 @@
174 #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld64.so.1"
175 #define UCLIBC_DYNAMIC_LINKER32 "/lib/ld-uClibc.so.0"
176 #define UCLIBC_DYNAMIC_LINKER64 "/lib/ld64-uClibc.so.0"
177 +#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-powerpc.so.1"
178 +#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-powerpc64.so.1"
179 #if DEFAULT_LIBC == LIBC_UCLIBC
180 -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
181 +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
182 #elif DEFAULT_LIBC == LIBC_GLIBC
183 -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
184 +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
185 +#elif DEFAULT_LIBC == LIBC_MUSL
186 +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
187 #else
188 #error "Unsupported DEFAULT_LIBC"
189 #endif
190 #define GNU_USER_DYNAMIC_LINKER32 \
191 - CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32)
192 + CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
193 #define GNU_USER_DYNAMIC_LINKER64 \
194 - CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64)
195 + CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
196
197
198 #define LINK_OS_LINUX_SPEC32 "-m elf32ppclinux %{!shared: %{!static: \
199 diff --git a/gcc/config/rs6000/sysv4.h b/gcc/config/rs6000/sysv4.h
200 --- a/gcc/config/rs6000/sysv4.h
201 +++ b/gcc/config/rs6000/sysv4.h
202 @@ -804,15 +804,18 @@
203
204 #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
205 #define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0"
206 +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-powerpc.so.1"
207 #if DEFAULT_LIBC == LIBC_UCLIBC
208 -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
209 +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
210 +#elif DEFAULT_LIBC == LIBC_MUSL
211 +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
212 #elif !defined (DEFAULT_LIBC) || DEFAULT_LIBC == LIBC_GLIBC
213 -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
214 +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
215 #else
216 #error "Unsupported DEFAULT_LIBC"
217 #endif
218 #define GNU_USER_DYNAMIC_LINKER \
219 - CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER)
220 + CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
221
222 #define LINK_OS_LINUX_SPEC "-m elf32ppclinux %{!shared: %{!static: \
223 %{rdynamic:-export-dynamic} \
224 diff --git a/gcc/ginclude/stddef.h b/gcc/ginclude/stddef.h
225 --- a/gcc/ginclude/stddef.h
226 +++ b/gcc/ginclude/stddef.h
227 @@ -184,6 +184,7 @@
228 #ifndef _GCC_SIZE_T
229 #ifndef _SIZET_
230 #ifndef __size_t
231 +#ifndef __DEFINED_size_t /* musl */
232 #define __size_t__ /* BeOS */
233 #define __SIZE_T__ /* Cray Unicos/Mk */
234 #define _SIZE_T
235 @@ -200,6 +201,7 @@
236 #define ___int_size_t_h
237 #define _GCC_SIZE_T
238 #define _SIZET_
239 +#define __DEFINED_size_t /* musl */
240 #if (defined (__FreeBSD__) && (__FreeBSD__ >= 5)) \
241 || defined(__FreeBSD_kernel__)
242 /* __size_t is a typedef on FreeBSD 5, must not trash it. */
243 @@ -215,6 +217,7 @@
244 typedef long ssize_t;
245 #endif /* __BEOS__ */
246 #endif /* !(defined (__GNUG__) && defined (size_t)) */
247 +#endif /* __DEFINED_size_t */
248 #endif /* __size_t */
249 #endif /* _SIZET_ */
250 #endif /* _GCC_SIZE_T */
251 diff --git a/libgomp/config/posix/time.c b/libgomp/config/posix/time.c
252 --- a/libgomp/config/posix/time.c
253 +++ b/libgomp/config/posix/time.c
254 @@ -28,6 +28,8 @@
255 The following implementation uses the most simple POSIX routines.
256 If present, POSIX 4 clocks should be used instead. */
257
258 +#define _POSIX_C_SOURCE 199309L /* for clocks */
259 +
260 #include "libgomp.h"
261 #include <unistd.h>
262 #if TIME_WITH_SYS_TIME
263 diff --git a/libitm/config/arm/hwcap.cc b/libitm/config/arm/hwcap.cc
264 --- a/libitm/config/arm/hwcap.cc
265 +++ b/libitm/config/arm/hwcap.cc
266 @@ -40,7 +40,11 @@
267
268 #ifdef __linux__
269 #include <unistd.h>
270 +#ifdef __GLIBC__
271 #include <sys/fcntl.h>
272 +#else
273 +#include <fcntl.h>
274 +#endif
275 #include <elf.h>
276
277 static void __attribute__((constructor))
278 diff --git a/libitm/config/linux/x86/tls.h b/libitm/config/linux/x86/tls.h
279 --- a/libitm/config/linux/x86/tls.h
280 +++ b/libitm/config/linux/x86/tls.h
281 @@ -25,16 +25,19 @@
282 #ifndef LIBITM_X86_TLS_H
283 #define LIBITM_X86_TLS_H 1
284
285 -#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
286 +#if defined(__GLIBC_PREREQ)
287 +#if __GLIBC_PREREQ(2, 10)
288 /* Use slots in the TCB head rather than __thread lookups.
289 GLIBC has reserved words 10 through 13 for TM. */
290 #define HAVE_ARCH_GTM_THREAD 1
291 #define HAVE_ARCH_GTM_THREAD_DISP 1
292 #endif
293 +#endif
294
295 #include "config/generic/tls.h"
296
297 -#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
298 +#if defined(__GLIBC_PREREQ)
299 +#if __GLIBC_PREREQ(2, 10)
300 namespace GTM HIDDEN {
301
302 #ifdef __x86_64__
303 @@ -101,5 +104,6 @@
304
305 } // namespace GTM
306 #endif /* >= GLIBC 2.10 */
307 +#endif
308
309 #endif // LIBITM_X86_TLS_H
310 diff --git a/libstdc++-v3/configure.host b/libstdc++-v3/configure.host
311 --- a/libstdc++-v3/configure.host
312 +++ b/libstdc++-v3/configure.host
313 @@ -243,6 +243,13 @@
314 os_include_dir="os/bsd/freebsd"
315 ;;
316 gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu)
317 + # check for musl by target
318 + case "${host_os}" in
319 + *-musl*)
320 + os_include_dir="os/generic"
321 + ;;
322 + *)
323 +
324 if [ "$uclibc" = "yes" ]; then
325 os_include_dir="os/uclibc"
326 elif [ "$bionic" = "yes" ]; then
327 @@ -251,6 +258,9 @@
328 os_include_dir="os/gnu-linux"
329 fi
330 ;;
331 +
332 + esac
333 + ;;
334 hpux*)
335 os_include_dir="os/hpux"
336 ;;
337 diff --git a/gcc/config/mips/linux64.h b/gcc/config/mips/linux64.h
338 --- a/gcc/config/mips/linux64.h 2012-11-13 12:42:00.000000000 +0100
339 +++ n/gcc/config/mips/linux64.h 2012-11-29 15:35:10.434361723 +0100
340 @@ -28,6 +28,9 @@
341 #define GLIBC_DYNAMIC_LINKERN32 "/lib32/ld.so.1"
342 #define UCLIBC_DYNAMIC_LINKERN32 "/lib32/ld-uClibc.so.0"
343 #define BIONIC_DYNAMIC_LINKERN32 "/system/bin/linker32"
344 +#define MUSL_DYNAMIC_LINKERN32 "/lib/ld-musl-mips.so.1"
345 +#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-mips.so.1"
346 +#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-mips.so.1"
347 #define GNU_USER_DYNAMIC_LINKERN32 \
348 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERN32, UCLIBC_DYNAMIC_LINKERN32, \
349 - BIONIC_DYNAMIC_LINKERN32)
350 + BIONIC_DYNAMIC_LINKERN32, MUSL_DYNAMIC_LINKERN32)