toolchain/gcc: upgrade Linaro GCC 4.9 to 4.9-2015.03
[openwrt/openwrt.git] / toolchain / gcc / patches / 4.9-linaro / 200-musl_config.patch
1 --- a/gcc/config.gcc
2 +++ b/gcc/config.gcc
3 @@ -595,7 +595,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 # 32-bit x86 processors supported by --with-arch=. Each processor
11 # MUST be separated by exactly one space.
12 @@ -720,6 +720,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/linux.h
23 +++ b/gcc/config/linux.h
24 @@ -32,10 +32,12 @@ see the files COPYING3 and COPYING.RUNTI
25 #define OPTION_GLIBC (DEFAULT_LIBC == LIBC_GLIBC)
26 #define OPTION_UCLIBC (DEFAULT_LIBC == LIBC_UCLIBC)
27 #define OPTION_BIONIC (DEFAULT_LIBC == LIBC_BIONIC)
28 +#define OPTION_MUSL (DEFAULT_LIBC == LIBC_MUSL)
29 #else
30 #define OPTION_GLIBC (linux_libc == LIBC_GLIBC)
31 #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
32 #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
33 +#define OPTION_MUSL (linux_libc == LIBC_MUSL)
34 #endif
35
36 #define GNU_USER_TARGET_OS_CPP_BUILTINS() \
37 @@ -53,18 +55,21 @@ see the files COPYING3 and COPYING.RUNTI
38 uClibc or Bionic is the default C library and whether
39 -muclibc or -mglibc or -mbionic has been passed to change the default. */
40
41 -#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LD1, LD2, LD3) \
42 - "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:" LD1 "}}"
43 +#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LIBC4, LD1, LD2, LD3, LD4) \
44 + "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:%{" LIBC4 ":" LD4 ";:" LD1 "}}}"
45
46 #if DEFAULT_LIBC == LIBC_GLIBC
47 -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
48 - CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", G, U, B)
49 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
50 + CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", "mmusl", G, U, B, M)
51 #elif DEFAULT_LIBC == LIBC_UCLIBC
52 -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
53 - CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", U, G, B)
54 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
55 + CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", "mmusl", U, G, B, M)
56 #elif DEFAULT_LIBC == LIBC_BIONIC
57 -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
58 - CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", B, G, U)
59 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
60 + CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", "mmusl", B, G, U, M)
61 +#elif DEFAULT_LIBC == LIBC_MUSL
62 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
63 + CHOOSE_DYNAMIC_LINKER1 ("mmusl", "mglibc", "muclibc", "mbionic", M, G, U, B)
64 #else
65 #error "Unsupported DEFAULT_LIBC"
66 #endif /* DEFAULT_LIBC */
67 @@ -84,21 +89,92 @@ see the files COPYING3 and COPYING.RUNTI
68
69 #define GNU_USER_DYNAMIC_LINKER \
70 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, \
71 - BIONIC_DYNAMIC_LINKER)
72 + BIONIC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
73 #define GNU_USER_DYNAMIC_LINKER32 \
74 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, \
75 - BIONIC_DYNAMIC_LINKER32)
76 + BIONIC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
77 #define GNU_USER_DYNAMIC_LINKER64 \
78 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
79 - BIONIC_DYNAMIC_LINKER64)
80 + BIONIC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
81 #define GNU_USER_DYNAMIC_LINKERX32 \
82 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \
83 - BIONIC_DYNAMIC_LINKERX32)
84 + BIONIC_DYNAMIC_LINKERX32, MUSL_DYNAMIC_LINKERX32)
85
86 /* Whether we have Bionic libc runtime */
87 #undef TARGET_HAS_BIONIC
88 #define TARGET_HAS_BIONIC (OPTION_BIONIC)
89
90 +/* musl avoids problematic includes by rearranging the include directories.
91 + * Unfortunately, this is mostly duplicated from cppdefault.c */
92 +#if DEFAULT_LIBC == LIBC_MUSL
93 +#define INCLUDE_DEFAULTS_MUSL_GPP \
94 + { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, \
95 + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, \
96 + { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1, \
97 + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 }, \
98 + { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1, \
99 + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },
100 +
101 +#ifdef LOCAL_INCLUDE_DIR
102 +#define INCLUDE_DEFAULTS_MUSL_LOCAL \
103 + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 }, \
104 + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 },
105 +#else
106 +#define INCLUDE_DEFAULTS_MUSL_LOCAL
107 +#endif
108 +
109 +#ifdef PREFIX_INCLUDE_DIR
110 +#define INCLUDE_DEFAULTS_MUSL_PREFIX \
111 + { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0},
112 +#else
113 +#define INCLUDE_DEFAULTS_MUSL_PREFIX
114 +#endif
115 +
116 +#ifdef CROSS_INCLUDE_DIR
117 +#define INCLUDE_DEFAULTS_MUSL_CROSS \
118 + { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0},
119 +#else
120 +#define INCLUDE_DEFAULTS_MUSL_CROSS
121 +#endif
122 +
123 +#ifdef TOOL_INCLUDE_DIR
124 +#define INCLUDE_DEFAULTS_MUSL_TOOL \
125 + { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0},
126 +#else
127 +#define INCLUDE_DEFAULTS_MUSL_TOOL
128 +#endif
129 +
130 +#ifdef NATIVE_SYSTEM_HEADER_DIR
131 +#define INCLUDE_DEFAULTS_MUSL_NATIVE \
132 + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 2 }, \
133 + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 0 },
134 +#else
135 +#define INCLUDE_DEFAULTS_MUSL_NATIVE
136 +#endif
137 +
138 +#if defined (CROSS_DIRECTORY_STRUCTURE) && !defined (TARGET_SYSTEM_ROOT)
139 +# undef INCLUDE_DEFAULTS_MUSL_LOCAL
140 +# define INCLUDE_DEFAULTS_MUSL_LOCAL
141 +# undef INCLUDE_DEFAULTS_MUSL_NATIVE
142 +# define INCLUDE_DEFAULTS_MUSL_NATIVE
143 +#else
144 +# undef INCLUDE_DEFAULTS_MUSL_CROSS
145 +# define INCLUDE_DEFAULTS_MUSL_CROSS
146 +#endif
147 +
148 +#undef INCLUDE_DEFAULTS
149 +#define INCLUDE_DEFAULTS \
150 + { \
151 + INCLUDE_DEFAULTS_MUSL_GPP \
152 + INCLUDE_DEFAULTS_MUSL_PREFIX \
153 + INCLUDE_DEFAULTS_MUSL_CROSS \
154 + INCLUDE_DEFAULTS_MUSL_TOOL \
155 + INCLUDE_DEFAULTS_MUSL_NATIVE \
156 + { GCC_INCLUDE_DIR, "GCC", 0, 1, 0, 0 }, \
157 + { 0, 0, 0, 0, 0, 0 } \
158 + }
159 +#endif
160 +
161 #if (DEFAULT_LIBC == LIBC_UCLIBC) && defined (SINGLE_LIBC) /* uClinux */
162 /* This is a *uclinux* target. We don't define below macros to normal linux
163 versions, because doing so would require *uclinux* targets to include
164 --- a/gcc/config/linux.opt
165 +++ b/gcc/config/linux.opt
166 @@ -30,3 +30,7 @@ Use GNU C library
167 muclibc
168 Target Report RejectNegative Var(linux_libc,LIBC_UCLIBC) Negative(mbionic)
169 Use uClibc C library
170 +
171 +mmusl
172 +Target Report RejectNegative Var(linux_libc,LIBC_MUSL) Negative(mglibc)
173 +Use musl C library
174 --- a/gcc/ginclude/stddef.h
175 +++ b/gcc/ginclude/stddef.h
176 @@ -181,6 +181,7 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t;
177 #ifndef _GCC_SIZE_T
178 #ifndef _SIZET_
179 #ifndef __size_t
180 +#ifndef __DEFINED_size_t /* musl */
181 #define __size_t__ /* BeOS */
182 #define __SIZE_T__ /* Cray Unicos/Mk */
183 #define _SIZE_T
184 @@ -197,6 +198,7 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t;
185 #define ___int_size_t_h
186 #define _GCC_SIZE_T
187 #define _SIZET_
188 +#define __DEFINED_size_t /* musl */
189 #if (defined (__FreeBSD__) && (__FreeBSD__ >= 5)) \
190 || defined(__FreeBSD_kernel__)
191 /* __size_t is a typedef on FreeBSD 5, must not trash it. */
192 @@ -214,6 +216,7 @@ typedef __SIZE_TYPE__ size_t;
193 typedef long ssize_t;
194 #endif /* __BEOS__ */
195 #endif /* !(defined (__GNUG__) && defined (size_t)) */
196 +#endif /* __DEFINED_size_t */
197 #endif /* __size_t */
198 #endif /* _SIZET_ */
199 #endif /* _GCC_SIZE_T */