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