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