toolchain/gcc: refresh patches
[openwrt/openwrt.git] / toolchain / gcc / patches / 4.5-linaro / 200-musl.patch
1 --- a/config.sub
2 +++ b/config.sub
3 @@ -125,6 +125,7 @@ esac
4 maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
5 case $maybe_os in
6 nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
7 + linux-musl* | \
8 linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
9 knetbsd*-gnu* | netbsd*-gnu* | \
10 kopensolaris*-gnu* | \
11 --- a/gcc/config/arm/linux-eabi.h
12 +++ b/gcc/config/arm/linux-eabi.h
13 @@ -63,6 +63,10 @@
14 #undef GLIBC_DYNAMIC_LINKER
15 #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.3"
16
17 +/* musl has no "classic" (i.e. broken) mode */
18 +#undef MUSL_DYNAMIC_LINKER
19 +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-arm.so.1"
20 +
21 /* At this point, bpabi.h will have clobbered LINK_SPEC. We want to
22 use the GNU/Linux version, not the generic BPABI version. */
23 #undef LINK_SPEC
24 --- a/gcc/config/i386/linux.h
25 +++ b/gcc/config/i386/linux.h
26 @@ -101,6 +101,7 @@ along with GCC; see the file COPYING3.
27 /* These macros may be overridden in k*bsd-gnu.h and i386/k*bsd-gnu.h. */
28 #define LINK_EMULATION "elf_i386"
29 #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
30 +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-i386.so.1"
31
32 #undef ASM_SPEC
33 #define ASM_SPEC \
34 --- a/gcc/config/i386/linux64.h
35 +++ b/gcc/config/i386/linux64.h
36 @@ -61,6 +61,9 @@ see the files COPYING3 and COPYING.RUNTI
37 #define GLIBC_DYNAMIC_LINKER32 "/lib/ld-linux.so.2"
38 #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-linux-x86-64.so.2"
39
40 +#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-i386.so.1"
41 +#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-x86_64.so.1"
42 +
43 #if TARGET_64BIT_DEFAULT
44 #define SPEC_32 "m32"
45 #define SPEC_64 "!m32"
46 --- a/gcc/config/linux.h
47 +++ b/gcc/config/linux.h
48 @@ -86,6 +86,7 @@ see the files COPYING3 and COPYING.RUNTI
49 #define OPTION_GLIBC (linux_libc == LIBC_GLIBC)
50 #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
51 #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
52 +#define OPTION_MUSL (linux_libc == LIBC_MUSL)
53
54 #define LINUX_TARGET_OS_CPP_BUILTINS() \
55 do { \
56 @@ -120,18 +121,21 @@ see the files COPYING3 and COPYING.RUNTI
57 uClibc or Bionic is the default C library and whether
58 -muclibc or -mglibc or -mbionic has been passed to change the default. */
59
60 -#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LD1, LD2, LD3) \
61 - "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:" LD1 "}}"
62 +#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LIBC4, LD1, LD2, LD3, LD4) \
63 + "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:%{" LIBC4 ":" LD4 ";:" LD1 "}}}"
64
65 #if DEFAULT_LIBC == LIBC_GLIBC
66 -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
67 - CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", G, U, B)
68 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
69 + CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", "mmusl", G, U, B, M)
70 #elif DEFAULT_LIBC == LIBC_UCLIBC
71 -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
72 - CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", U, G, B)
73 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
74 + CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", "mmusl", U, G, B, M)
75 #elif DEFAULT_LIBC == LIBC_BIONIC
76 -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
77 - CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", B, G, U)
78 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
79 + CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", "mmusl", B, G, U, M)
80 +#elif DEFAULT_LIBC == LIBC_MUSL
81 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
82 + CHOOSE_DYNAMIC_LINKER1 ("mmusl", "mglibc", "muclibc", "mbionic", M, G, U, B)
83 #else
84 #error "Unsupported DEFAULT_LIBC"
85 #endif /* DEFAULT_LIBC */
86 @@ -149,13 +153,13 @@ see the files COPYING3 and COPYING.RUNTI
87
88 #define LINUX_DYNAMIC_LINKER \
89 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, \
90 - BIONIC_DYNAMIC_LINKER)
91 + BIONIC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
92 #define LINUX_DYNAMIC_LINKER32 \
93 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, \
94 - BIONIC_DYNAMIC_LINKER32)
95 + BIONIC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
96 #define LINUX_DYNAMIC_LINKER64 \
97 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
98 - BIONIC_DYNAMIC_LINKER64)
99 + BIONIC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
100
101 /* Determine whether the entire c99 runtime
102 is present in the runtime library. */
103 --- a/gcc/config/linux.opt
104 +++ b/gcc/config/linux.opt
105 @@ -30,3 +30,7 @@ Use GNU C library
106 muclibc
107 Target Report RejectNegative Var(linux_libc,LIBC_UCLIBC) VarExists Negative(mbionic)
108 Use uClibc C library
109 +
110 +mmusl
111 +Target Report RejectNegative Var(linux_libc,LIBC_MUSL) Negative(mglibc)
112 +Use musl C library
113 --- a/gcc/config/mips/linux.h
114 +++ b/gcc/config/mips/linux.h
115 @@ -66,6 +66,8 @@ along with GCC; see the file COPYING3.
116
117 #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
118
119 +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-mips.so.1"
120 +
121 /* Borrowed from sparc/linux.h */
122 #undef LINK_SPEC
123 #define LINK_SPEC \
124 --- a/gcc/config/mips/linux64.h
125 +++ b/gcc/config/mips/linux64.h
126 @@ -39,8 +39,11 @@ along with GCC; see the file COPYING3.
127 #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld.so.1"
128 #define GLIBC_DYNAMIC_LINKERN32 "/lib32/ld.so.1"
129 #define UCLIBC_DYNAMIC_LINKERN32 "/lib32/ld-uClibc.so.0"
130 +#define MUSL_DYNAMIC_LINKERN32 "/lib32/ld-musl-mips.so.1"
131 +#define MUSL_DYNAMIC_LINKER32 "/lib32/ld-musl-mips.so.1"
132 +#define MUSL_DYNAMIC_LINKER64 "/lib64/ld-musl-mips.so.1"
133 #define LINUX_DYNAMIC_LINKERN32 \
134 - CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERN32, UCLIBC_DYNAMIC_LINKERN32)
135 + CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERN32, UCLIBC_DYNAMIC_LINKERN32, MUSL_DYNAMIC_LINKERN32)
136
137 #undef LINK_SPEC
138 #define LINK_SPEC "\
139 --- a/gcc/config.gcc
140 +++ b/gcc/config.gcc
141 @@ -514,7 +514,7 @@ case ${target} in
142 tmake_file="$tmake_file t-gnu";;
143 esac
144 # Common C libraries.
145 - tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3"
146 + tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3 LIBC_MUSL=4"
147 # glibc / uclibc / bionic switch.
148 # uclibc and bionic aren't usable for GNU/Hurd and neither for GNU/k*BSD.
149 case $target in
150 @@ -530,6 +530,9 @@ case ${target} in
151 *-*-*uclibc*)
152 tm_defines="$tm_defines DEFAULT_LIBC=LIBC_UCLIBC"
153 ;;
154 + *-*-*musl*)
155 + tm_defines="$tm_defines DEFAULT_LIBC=LIBC_MUSL"
156 + ;;
157 *)
158 tm_defines="$tm_defines DEFAULT_LIBC=LIBC_GLIBC"
159 ;;
160 --- a/gcc/ginclude/stddef.h
161 +++ b/gcc/ginclude/stddef.h
162 @@ -183,6 +183,7 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t;
163 #ifndef _GCC_SIZE_T
164 #ifndef _SIZET_
165 #ifndef __size_t
166 +#ifndef __DEFINED_size_t /* musl */
167 #define __size_t__ /* BeOS */
168 #define __SIZE_T__ /* Cray Unicos/Mk */
169 #define _SIZE_T
170 @@ -199,6 +200,7 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t;
171 #define ___int_size_t_h
172 #define _GCC_SIZE_T
173 #define _SIZET_
174 +#define __DEFINED_size_t /* musl */
175 #if defined (__FreeBSD__) && (__FreeBSD__ >= 5)
176 /* __size_t is a typedef on FreeBSD 5!, must not trash it. */
177 #else
178 @@ -213,6 +215,7 @@ typedef __SIZE_TYPE__ size_t;
179 typedef long ssize_t;
180 #endif /* __BEOS__ */
181 #endif /* !(defined (__GNUG__) && defined (size_t)) */
182 +#endif /* __DEFINED_size_t */
183 #endif /* __size_t */
184 #endif /* _SIZET_ */
185 #endif /* _GCC_SIZE_T */
186 --- a/libgomp/config/posix/time.c
187 +++ b/libgomp/config/posix/time.c
188 @@ -28,6 +28,8 @@
189 The following implementation uses the most simple POSIX routines.
190 If present, POSIX 4 clocks should be used instead. */
191
192 +#define _POSIX_C_SOURCE 199309L /* for clocks */
193 +
194 #include "libgomp.h"
195 #include <unistd.h>
196 #if TIME_WITH_SYS_TIME
197 --- a/libstdc++-v3/configure.host
198 +++ b/libstdc++-v3/configure.host
199 @@ -236,6 +236,13 @@ case "${host_os}" in
200 os_include_dir="os/bsd/freebsd"
201 ;;
202 gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu)
203 + # check for musl by target
204 + case "${host_os}" in
205 + *-musl*)
206 + os_include_dir="os/generic"
207 + ;;
208 + *)
209 +
210 if [ "$uclibc" = "yes" ]; then
211 os_include_dir="os/uclibc"
212 elif [ "$bionic" = "yes" ]; then
213 @@ -244,6 +251,9 @@ case "${host_os}" in
214 os_include_dir="os/gnu-linux"
215 fi
216 ;;
217 +
218 + esac
219 + ;;
220 hpux*)
221 os_include_dir="os/hpux"
222 ;;