open-plc-utils: new package
[buildroot-gz.git] / package / gcc / 4.9.2 / 900-musl-support.patch
blob56502b882c650e52dfadc0d64ca128f2d6c83e3b
1 Add musl support to gcc
3 This patch comes from the musl-cross project at
4 https://bitbucket.org/GregorR/musl-cross/src. Compared to the upstream version:
6 * the config.sub modifications have been removed, because Buildroot
7 already overwrites all config.sub with a more recent config.sub
8 that has musl support.
10 * change to ensure that a dummy dynamic linker path
11 MUSL_DYNAMIC_LINKER<foo> is defined for all architectures,
12 otherwise building gcc for architectures not supported by musl was
13 causing build failure. Bug reported upstream at
14 https://bitbucket.org/GregorR/musl-gcc-patches/issue/4/musl-gcc-patches-break-the-build-on.
16 * change the USE_PT_GNU_EH_FRAME logic to keep the existing gcc logic
17 and only add the musl one as an addition, not as a replacement. Not
18 doing this breaks C++ exception handling with glibc, because
19 USE_PT_GNU_EH_FRAME doesn't get defined due to the configure script
20 not testing dl_iterate_phdr() on any system except Solaris.
22 [Gustavo: remove upstream applied gcc/config/sh/sh.c chunk for 4.9.1]
23 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
24 ---
26 Index: b/fixincludes/mkfixinc.sh
27 ===================================================================
28 --- a/fixincludes/mkfixinc.sh
29 +++ b/fixincludes/mkfixinc.sh
30 @@ -19,7 +19,8 @@
31 powerpc-*-eabi* | \
32 powerpc-*-rtems* | \
33 powerpcle-*-eabisim* | \
34 - powerpcle-*-eabi* )
35 + powerpcle-*-eabi* | \
36 + *-musl* )
37 # IF there is no include fixing,
38 # THEN create a no-op fixer and exit
39 (echo "#! /bin/sh" ; echo "exit 0" ) > ${target}
40 Index: b/gcc/config.gcc
41 ===================================================================
42 --- a/gcc/config.gcc
43 +++ b/gcc/config.gcc
44 @@ -594,7 +594,7 @@
45 esac
47 # Common C libraries.
48 -tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3"
49 +tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3 LIBC_MUSL=4"
51 # 32-bit x86 processors supported by --with-arch=. Each processor
52 # MUST be separated by exactly one space.
53 @@ -719,6 +719,9 @@
54 *-*-*uclibc*)
55 tm_defines="$tm_defines DEFAULT_LIBC=LIBC_UCLIBC"
57 + *-*-*musl*)
58 + tm_defines="$tm_defines DEFAULT_LIBC=LIBC_MUSL"
59 + ;;
61 tm_defines="$tm_defines DEFAULT_LIBC=LIBC_GLIBC"
63 @@ -2322,6 +2325,10 @@
64 powerpc*-*-linux*paired*)
65 tm_file="${tm_file} rs6000/750cl.h" ;;
66 esac
67 + case ${target} in
68 + *-linux*-musl*)
69 + enable_secureplt=yes ;;
70 + esac
71 if test x${enable_secureplt} = xyes; then
72 tm_file="rs6000/secureplt.h ${tm_file}"
74 Index: b/gcc/config/aarch64/aarch64-linux.h
75 ===================================================================
76 --- a/gcc/config/aarch64/aarch64-linux.h
77 +++ b/gcc/config/aarch64/aarch64-linux.h
78 @@ -22,6 +22,8 @@
79 #define GCC_AARCH64_LINUX_H
81 #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux-aarch64%{mbig-endian:_be}.so.1"
82 +#undef MUSL_DYNAMIC_LINKER
83 +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-aarch64.so.1"
85 #define CPP_SPEC "%{pthread:-D_REENTRANT}"
87 Index: b/gcc/config/arm/linux-eabi.h
88 ===================================================================
89 --- a/gcc/config/arm/linux-eabi.h
90 +++ b/gcc/config/arm/linux-eabi.h
91 @@ -77,6 +77,23 @@
92 %{mfloat-abi=soft*:" GLIBC_DYNAMIC_LINKER_SOFT_FLOAT "} \
93 %{!mfloat-abi=*:" GLIBC_DYNAMIC_LINKER_DEFAULT "}"
95 +/* For ARM musl currently supports four dynamic linkers:
96 + - ld-musl-arm.so.1 - for the EABI-derived soft-float ABI
97 + - ld-musl-armhf.so.1 - for the EABI-derived hard-float ABI
98 + - ld-musl-armeb.so.1 - for the EABI-derived soft-float ABI, EB
99 + - ld-musl-armebhf.so.1 - for the EABI-derived hard-float ABI, EB
100 + musl does not support the legacy OABI mode.
101 + All the dynamic linkers live in /lib.
102 + We default to soft-float, EL. */
103 +#undef MUSL_DYNAMIC_LINKER
104 +#if TARGET_BIG_ENDIAN_DEFAULT
105 +#define MUSL_DYNAMIC_LINKER_E "%{mlittle-endian:;:eb}"
106 +#else
107 +#define MUSL_DYNAMIC_LINKER_E "%{mbig-endian:eb}"
108 +#endif
109 +#define MUSL_DYNAMIC_LINKER \
110 + "/lib/ld-musl-arm" MUSL_DYNAMIC_LINKER_E "%{mfloat-abi=hard:hf}.so.1"
112 /* At this point, bpabi.h will have clobbered LINK_SPEC. We want to
113 use the GNU/Linux version, not the generic BPABI version. */
114 #undef LINK_SPEC
115 Index: b/gcc/config/i386/linux.h
116 ===================================================================
117 --- a/gcc/config/i386/linux.h
118 +++ b/gcc/config/i386/linux.h
119 @@ -21,3 +21,5 @@
121 #define GNU_USER_LINK_EMULATION "elf_i386"
122 #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
123 +#undef MUSL_DYNAMIC_LINKER
124 +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-i386.so.1"
125 Index: b/gcc/config/i386/linux64.h
126 ===================================================================
127 --- a/gcc/config/i386/linux64.h
128 +++ b/gcc/config/i386/linux64.h
129 @@ -30,3 +30,10 @@
130 #define GLIBC_DYNAMIC_LINKER32 "/lib/ld-linux.so.2"
131 #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-linux-x86-64.so.2"
132 #define GLIBC_DYNAMIC_LINKERX32 "/libx32/ld-linux-x32.so.2"
134 +#undef MUSL_DYNAMIC_LINKER32
135 +#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-i386.so.1"
136 +#undef MUSL_DYNAMIC_LINKER64
137 +#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-x86_64.so.1"
138 +#undef MUSL_DYNAMIC_LINKERX32
139 +#define MUSL_DYNAMIC_LINKERX32 "/lib/ld-musl-x32.so.1"
140 Index: b/gcc/config/linux.h
141 ===================================================================
142 --- a/gcc/config/linux.h
143 +++ b/gcc/config/linux.h
144 @@ -32,10 +32,12 @@
145 #define OPTION_GLIBC (DEFAULT_LIBC == LIBC_GLIBC)
146 #define OPTION_UCLIBC (DEFAULT_LIBC == LIBC_UCLIBC)
147 #define OPTION_BIONIC (DEFAULT_LIBC == LIBC_BIONIC)
148 +#define OPTION_MUSL (DEFAULT_LIBC == LIBC_MUSL)
149 #else
150 #define OPTION_GLIBC (linux_libc == LIBC_GLIBC)
151 #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
152 #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
153 +#define OPTION_MUSL (linux_libc == LIBC_MUSL)
154 #endif
156 #define GNU_USER_TARGET_OS_CPP_BUILTINS() \
157 @@ -53,18 +55,21 @@
158 uClibc or Bionic is the default C library and whether
159 -muclibc or -mglibc or -mbionic has been passed to change the default. */
161 -#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LD1, LD2, LD3) \
162 - "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:" LD1 "}}"
163 +#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LIBC4, LD1, LD2, LD3, LD4) \
164 + "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:%{" LIBC4 ":" LD4 ";:" LD1 "}}}"
166 #if DEFAULT_LIBC == LIBC_GLIBC
167 -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
168 - CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", G, U, B)
169 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
170 + CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", "mmusl", G, U, B, M)
171 #elif DEFAULT_LIBC == LIBC_UCLIBC
172 -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
173 - CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", U, G, B)
174 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
175 + CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", "mmusl", U, G, B, M)
176 #elif DEFAULT_LIBC == LIBC_BIONIC
177 -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
178 - CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", B, G, U)
179 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
180 + CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", "mmusl", B, G, U, M)
181 +#elif DEFAULT_LIBC == LIBC_MUSL
182 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
183 + CHOOSE_DYNAMIC_LINKER1 ("mmusl", "mglibc", "muclibc", "mbionic", M, G, U, B)
184 #else
185 #error "Unsupported DEFAULT_LIBC"
186 #endif /* DEFAULT_LIBC */
187 @@ -82,23 +87,103 @@
188 #define BIONIC_DYNAMIC_LINKER64 "/system/bin/linker64"
189 #define BIONIC_DYNAMIC_LINKERX32 "/system/bin/linkerx32"
191 +/* Musl dynamic linker paths must be defined on a per-architecture
192 + basis, for each architecture supported by Musl. However, in order
193 + to let other architectures continue to build with other C
194 + libraries, we provide a dummy definition of the following defines. */
195 +#define MUSL_DYNAMIC_LINKER "invalid"
196 +#define MUSL_DYNAMIC_LINKER32 "invalid"
197 +#define MUSL_DYNAMIC_LINKER64 "invalid"
198 +#define MUSL_DYNAMIC_LINKERX32 "invalid"
200 #define GNU_USER_DYNAMIC_LINKER \
201 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, \
202 - BIONIC_DYNAMIC_LINKER)
203 + BIONIC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
204 #define GNU_USER_DYNAMIC_LINKER32 \
205 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, \
206 - BIONIC_DYNAMIC_LINKER32)
207 + BIONIC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
208 #define GNU_USER_DYNAMIC_LINKER64 \
209 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
210 - BIONIC_DYNAMIC_LINKER64)
211 + BIONIC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
212 #define GNU_USER_DYNAMIC_LINKERX32 \
213 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \
214 - BIONIC_DYNAMIC_LINKERX32)
215 + BIONIC_DYNAMIC_LINKERX32, MUSL_DYNAMIC_LINKER32)
217 /* Whether we have Bionic libc runtime */
218 #undef TARGET_HAS_BIONIC
219 #define TARGET_HAS_BIONIC (OPTION_BIONIC)
221 +/* musl avoids problematic includes by rearranging the include directories.
222 + * Unfortunately, this is mostly duplicated from cppdefault.c */
223 +#if DEFAULT_LIBC == LIBC_MUSL
224 +#define INCLUDE_DEFAULTS_MUSL_GPP \
225 + { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, \
226 + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, \
227 + { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1, \
228 + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 }, \
229 + { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1, \
230 + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },
232 +#ifdef LOCAL_INCLUDE_DIR
233 +#define INCLUDE_DEFAULTS_MUSL_LOCAL \
234 + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 }, \
235 + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 },
236 +#else
237 +#define INCLUDE_DEFAULTS_MUSL_LOCAL
238 +#endif
240 +#ifdef PREFIX_INCLUDE_DIR
241 +#define INCLUDE_DEFAULTS_MUSL_PREFIX \
242 + { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0},
243 +#else
244 +#define INCLUDE_DEFAULTS_MUSL_PREFIX
245 +#endif
247 +#ifdef CROSS_INCLUDE_DIR
248 +#define INCLUDE_DEFAULTS_MUSL_CROSS \
249 + { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0},
250 +#else
251 +#define INCLUDE_DEFAULTS_MUSL_CROSS
252 +#endif
254 +#ifdef TOOL_INCLUDE_DIR
255 +#define INCLUDE_DEFAULTS_MUSL_TOOL \
256 + { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0},
257 +#else
258 +#define INCLUDE_DEFAULTS_MUSL_TOOL
259 +#endif
261 +#ifdef NATIVE_SYSTEM_HEADER_DIR
262 +#define INCLUDE_DEFAULTS_MUSL_NATIVE \
263 + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 2 }, \
264 + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 0 },
265 +#else
266 +#define INCLUDE_DEFAULTS_MUSL_NATIVE
267 +#endif
269 +#if defined (CROSS_DIRECTORY_STRUCTURE) && !defined (TARGET_SYSTEM_ROOT)
270 +# undef INCLUDE_DEFAULTS_MUSL_LOCAL
271 +# define INCLUDE_DEFAULTS_MUSL_LOCAL
272 +# undef INCLUDE_DEFAULTS_MUSL_NATIVE
273 +# define INCLUDE_DEFAULTS_MUSL_NATIVE
274 +#else
275 +# undef INCLUDE_DEFAULTS_MUSL_CROSS
276 +# define INCLUDE_DEFAULTS_MUSL_CROSS
277 +#endif
279 +#undef INCLUDE_DEFAULTS
280 +#define INCLUDE_DEFAULTS \
281 + { \
282 + INCLUDE_DEFAULTS_MUSL_GPP \
283 + INCLUDE_DEFAULTS_MUSL_PREFIX \
284 + INCLUDE_DEFAULTS_MUSL_CROSS \
285 + INCLUDE_DEFAULTS_MUSL_TOOL \
286 + INCLUDE_DEFAULTS_MUSL_NATIVE \
287 + { GCC_INCLUDE_DIR, "GCC", 0, 1, 0, 0 }, \
288 + { 0, 0, 0, 0, 0, 0 } \
290 +#endif
292 #if (DEFAULT_LIBC == LIBC_UCLIBC) && defined (SINGLE_LIBC) /* uClinux */
293 /* This is a *uclinux* target. We don't define below macros to normal linux
294 versions, because doing so would require *uclinux* targets to include
295 Index: b/gcc/config/linux.opt
296 ===================================================================
297 --- a/gcc/config/linux.opt
298 +++ b/gcc/config/linux.opt
299 @@ -30,3 +30,7 @@
300 muclibc
301 Target Report RejectNegative Var(linux_libc,LIBC_UCLIBC) Negative(mbionic)
302 Use uClibc C library
304 +mmusl
305 +Target Report RejectNegative Var(linux_libc,LIBC_MUSL) Negative(mglibc)
306 +Use musl C library
307 Index: b/gcc/config/microblaze/linux.h
308 ===================================================================
309 --- a/gcc/config/microblaze/linux.h
310 +++ b/gcc/config/microblaze/linux.h
311 @@ -25,7 +25,23 @@
312 #undef TLS_NEEDS_GOT
313 #define TLS_NEEDS_GOT 1
315 -#define DYNAMIC_LINKER "/lib/ld.so.1"
316 +#if TARGET_BIG_ENDIAN_DEFAULT == 0 /* LE */
317 +#define MUSL_DYNAMIC_LINKER_E "%{EB:;:el}"
318 +#else
319 +#define MUSL_DYNAMIC_LINKER_E "%{EL:el}"
320 +#endif
322 +#undef MUSL_DYNAMIC_LINKER
323 +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-microblaze" MUSL_DYNAMIC_LINKER_E ".so.1"
324 +#define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
326 +#if DEFAULT_LIBC == LIBC_MUSL
327 +#define DYNAMIC_LINKER MUSL_DYNAMIC_LINKER
328 +#else
329 +#define DYNAMIC_LINKER GLIBC_DYNAMIC_LINKER
330 +#endif
333 #undef SUBTARGET_EXTRA_SPECS
334 #define SUBTARGET_EXTRA_SPECS \
335 { "dynamic_linker", DYNAMIC_LINKER }
336 Index: b/gcc/config/rs6000/linux64.h
337 ===================================================================
338 --- a/gcc/config/rs6000/linux64.h
339 +++ b/gcc/config/rs6000/linux64.h
340 @@ -375,17 +375,23 @@
341 #endif
342 #define UCLIBC_DYNAMIC_LINKER32 "/lib/ld-uClibc.so.0"
343 #define UCLIBC_DYNAMIC_LINKER64 "/lib/ld64-uClibc.so.0"
344 +#undef MUSL_DYNAMIC_LINKER32
345 +#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-powerpc.so.1"
346 +#undef MUSL_DYNAMIC_LINKER64
347 +#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-powerpc64.so.1"
348 #if DEFAULT_LIBC == LIBC_UCLIBC
349 -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
350 +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
351 #elif DEFAULT_LIBC == LIBC_GLIBC
352 -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
353 +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
354 +#elif DEFAULT_LIBC == LIBC_MUSL
355 +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
356 #else
357 #error "Unsupported DEFAULT_LIBC"
358 #endif
359 #define GNU_USER_DYNAMIC_LINKER32 \
360 - CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32)
361 + CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
362 #define GNU_USER_DYNAMIC_LINKER64 \
363 - CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64)
364 + CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
366 #undef DEFAULT_ASM_ENDIAN
367 #if (TARGET_DEFAULT & MASK_LITTLE_ENDIAN)
368 Index: b/gcc/config/rs6000/secureplt.h
369 ===================================================================
370 --- a/gcc/config/rs6000/secureplt.h
371 +++ b/gcc/config/rs6000/secureplt.h
372 @@ -18,3 +18,4 @@
373 <http://www.gnu.org/licenses/>. */
375 #define CC1_SECURE_PLT_DEFAULT_SPEC "-msecure-plt"
376 +#define LINK_SECURE_PLT_DEFAULT_SPEC "--secure-plt"
377 Index: b/gcc/config/rs6000/sysv4.h
378 ===================================================================
379 --- a/gcc/config/rs6000/sysv4.h
380 +++ b/gcc/config/rs6000/sysv4.h
381 @@ -537,6 +537,9 @@
382 #ifndef CC1_SECURE_PLT_DEFAULT_SPEC
383 #define CC1_SECURE_PLT_DEFAULT_SPEC ""
384 #endif
385 +#ifndef LINK_SECURE_PLT_DEFAULT_SPEC
386 +#define LINK_SECURE_PLT_DEFAULT_SPEC ""
387 +#endif
389 /* Pass -G xxx to the compiler. */
390 #define CC1_SPEC "%{G*} %(cc1_cpu)" \
391 @@ -585,7 +588,8 @@
393 /* Override the default target of the linker. */
394 #define LINK_TARGET_SPEC \
395 - ENDIAN_SELECT("", " --oformat elf32-powerpcle", "")
396 + ENDIAN_SELECT("", " --oformat elf32-powerpcle", "") \
397 + "%{!mbss-plt: %{!msecure-plt: %(link_secure_plt_default)}}"
399 /* Any specific OS flags. */
400 #define LINK_OS_SPEC "\
401 @@ -763,15 +767,18 @@
403 #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
404 #define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0"
405 +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-powerpc.so.1"
406 #if DEFAULT_LIBC == LIBC_UCLIBC
407 -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
408 +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
409 +#elif DEFAULT_LIBC == LIBC_MUSL
410 +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
411 #elif !defined (DEFAULT_LIBC) || DEFAULT_LIBC == LIBC_GLIBC
412 -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
413 +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
414 #else
415 #error "Unsupported DEFAULT_LIBC"
416 #endif
417 #define GNU_USER_DYNAMIC_LINKER \
418 - CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER)
419 + CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
421 #define LINK_OS_LINUX_SPEC "-m elf32ppclinux %{!shared: %{!static: \
422 %{rdynamic:-export-dynamic} \
423 @@ -894,6 +901,7 @@
424 { "link_os_openbsd", LINK_OS_OPENBSD_SPEC }, \
425 { "link_os_default", LINK_OS_DEFAULT_SPEC }, \
426 { "cc1_secure_plt_default", CC1_SECURE_PLT_DEFAULT_SPEC }, \
427 + { "link_secure_plt_default", LINK_SECURE_PLT_DEFAULT_SPEC }, \
428 { "cpp_os_ads", CPP_OS_ADS_SPEC }, \
429 { "cpp_os_yellowknife", CPP_OS_YELLOWKNIFE_SPEC }, \
430 { "cpp_os_mvme", CPP_OS_MVME_SPEC }, \
431 Index: b/gcc/config/sh/linux.h
432 ===================================================================
433 --- a/gcc/config/sh/linux.h
434 +++ b/gcc/config/sh/linux.h
435 @@ -43,7 +43,15 @@
437 #define TARGET_ASM_FILE_END file_end_indicate_exec_stack
439 +#if TARGET_BIG_ENDIAN_DEFAULT /* BE */
440 +#define MUSL_DYNAMIC_LINKER_E "eb"
441 +#else
442 +#define MUSL_DYNAMIC_LINKER_E
443 +#endif
445 #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
446 +#undef MUSL_DYNAMIC_LINKER
447 +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-sh" MUSL_DYNAMIC_LINKER_E ".so.1"
449 #undef SUBTARGET_LINK_EMUL_SUFFIX
450 #define SUBTARGET_LINK_EMUL_SUFFIX "_linux"
451 Index: b/gcc/configure
452 ===================================================================
453 --- a/gcc/configure
454 +++ b/gcc/configure
455 @@ -27328,6 +27328,9 @@
456 else
457 gcc_cv_libc_provides_ssp=no
458 case "$target" in
459 + *-*-musl*)
460 + # All versions of musl provide stack protector
461 + gcc_cv_libc_provides_ssp=yes;;
462 *-*-linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu)
463 # glibc 2.4 and later provides __stack_chk_fail and
464 # either __stack_chk_guard, or TLS access to stack guard canary.
465 @@ -27360,6 +27363,7 @@
466 # <http://gcc.gnu.org/ml/gcc/2008-10/msg00130.html>) and for now
467 # simply assert that glibc does provide this, which is true for all
468 # realistically usable GNU/Hurd configurations.
469 + # All supported versions of musl provide it as well
470 gcc_cv_libc_provides_ssp=yes;;
471 *-*-darwin* | *-*-freebsd*)
472 ac_fn_c_check_func "$LINENO" "__stack_chk_fail" "ac_cv_func___stack_chk_fail"
473 @@ -27449,6 +27453,9 @@
474 gcc_cv_target_dl_iterate_phdr=no
477 + *-linux-musl*)
478 + gcc_cv_target_dl_iterate_phdr=yes
479 + ;;
480 esac
482 if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
483 Index: b/gcc/configure.ac
484 ===================================================================
485 --- a/gcc/configure.ac
486 +++ b/gcc/configure.ac
487 @@ -5016,6 +5016,9 @@
488 gcc_cv_libc_provides_ssp,
489 [gcc_cv_libc_provides_ssp=no
490 case "$target" in
491 + *-*-musl*)
492 + # All versions of musl provide stack protector
493 + gcc_cv_libc_provides_ssp=yes;;
494 *-*-linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu)
495 # glibc 2.4 and later provides __stack_chk_fail and
496 # either __stack_chk_guard, or TLS access to stack guard canary.
497 @@ -5042,6 +5045,7 @@
498 # <http://gcc.gnu.org/ml/gcc/2008-10/msg00130.html>) and for now
499 # simply assert that glibc does provide this, which is true for all
500 # realistically usable GNU/Hurd configurations.
501 + # All supported versions of musl provide it as well
502 gcc_cv_libc_provides_ssp=yes;;
503 *-*-darwin* | *-*-freebsd*)
504 AC_CHECK_FUNC(__stack_chk_fail,[gcc_cv_libc_provides_ssp=yes],
505 @@ -5108,6 +5112,9 @@
506 gcc_cv_target_dl_iterate_phdr=no
509 + *-linux-musl*)
510 + gcc_cv_target_dl_iterate_phdr=yes
511 + ;;
512 esac
513 GCC_TARGET_TEMPLATE([TARGET_DL_ITERATE_PHDR])
514 if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
515 Index: b/gcc/ginclude/stddef.h
516 ===================================================================
517 --- a/gcc/ginclude/stddef.h
518 +++ b/gcc/ginclude/stddef.h
519 @@ -181,6 +181,7 @@
520 #ifndef _GCC_SIZE_T
521 #ifndef _SIZET_
522 #ifndef __size_t
523 +#ifndef __DEFINED_size_t /* musl */
524 #define __size_t__ /* BeOS */
525 #define __SIZE_T__ /* Cray Unicos/Mk */
526 #define _SIZE_T
527 @@ -197,6 +198,7 @@
528 #define ___int_size_t_h
529 #define _GCC_SIZE_T
530 #define _SIZET_
531 +#define __DEFINED_size_t /* musl */
532 #if (defined (__FreeBSD__) && (__FreeBSD__ >= 5)) \
533 || defined(__FreeBSD_kernel__)
534 /* __size_t is a typedef on FreeBSD 5, must not trash it. */
535 @@ -214,6 +216,7 @@
536 typedef long ssize_t;
537 #endif /* __BEOS__ */
538 #endif /* !(defined (__GNUG__) && defined (size_t)) */
539 +#endif /* __DEFINED_size_t */
540 #endif /* __size_t */
541 #endif /* _SIZET_ */
542 #endif /* _GCC_SIZE_T */
543 Index: b/libgcc/unwind-dw2-fde-dip.c
544 ===================================================================
545 --- a/libgcc/unwind-dw2-fde-dip.c
546 +++ b/libgcc/unwind-dw2-fde-dip.c
547 @@ -73,6 +73,13 @@
548 && defined(TARGET_DL_ITERATE_PHDR) \
549 && defined(__sun__) && defined(__svr4__)
550 # define USE_PT_GNU_EH_FRAME
551 + #endif
553 +/* For musl libc, TARGET_DL_ITERATE_PHDR gets defined by the configure
554 + script. */
555 +#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
556 + && defined(TARGET_DL_ITERATE_PHDR)
557 +# define USE_PT_GNU_EH_FRAME
558 #endif
560 #if defined(USE_PT_GNU_EH_FRAME)
561 Index: b/libgomp/config/posix/time.c
562 ===================================================================
563 --- a/libgomp/config/posix/time.c
564 +++ b/libgomp/config/posix/time.c
565 @@ -28,6 +28,8 @@
566 The following implementation uses the most simple POSIX routines.
567 If present, POSIX 4 clocks should be used instead. */
569 +#define _POSIX_C_SOURCE 199309L /* for clocks */
571 #include "libgomp.h"
572 #include <unistd.h>
573 #if TIME_WITH_SYS_TIME
574 Index: b/libitm/config/arm/hwcap.cc
575 ===================================================================
576 --- a/libitm/config/arm/hwcap.cc
577 +++ b/libitm/config/arm/hwcap.cc
578 @@ -40,7 +40,11 @@
580 #ifdef __linux__
581 #include <unistd.h>
582 +#ifdef __GLIBC__
583 #include <sys/fcntl.h>
584 +#else
585 +#include <fcntl.h>
586 +#endif
587 #include <elf.h>
589 static void __attribute__((constructor))
590 Index: b/libitm/config/linux/x86/tls.h
591 ===================================================================
592 --- a/libitm/config/linux/x86/tls.h
593 +++ b/libitm/config/linux/x86/tls.h
594 @@ -25,16 +25,19 @@
595 #ifndef LIBITM_X86_TLS_H
596 #define LIBITM_X86_TLS_H 1
598 -#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
599 +#if defined(__GLIBC_PREREQ)
600 +#if __GLIBC_PREREQ(2, 10)
601 /* Use slots in the TCB head rather than __thread lookups.
602 GLIBC has reserved words 10 through 13 for TM. */
603 #define HAVE_ARCH_GTM_THREAD 1
604 #define HAVE_ARCH_GTM_THREAD_DISP 1
605 #endif
606 +#endif
608 #include "config/generic/tls.h"
610 -#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
611 +#if defined(__GLIBC_PREREQ)
612 +#if __GLIBC_PREREQ(2, 10)
613 namespace GTM HIDDEN {
615 #ifdef __x86_64__
616 @@ -101,5 +104,6 @@
618 } // namespace GTM
619 #endif /* >= GLIBC 2.10 */
620 +#endif
622 #endif // LIBITM_X86_TLS_H
623 Index: b/libstdc++-v3/configure.host
624 ===================================================================
625 --- a/libstdc++-v3/configure.host
626 +++ b/libstdc++-v3/configure.host
627 @@ -264,6 +264,13 @@
628 os_include_dir="os/bsd/freebsd"
630 gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu)
631 + # check for musl by target
632 + case "${host_os}" in
633 + *-musl*)
634 + os_include_dir="os/generic"
635 + ;;
636 + *)
638 if [ "$uclibc" = "yes" ]; then
639 os_include_dir="os/uclibc"
640 elif [ "$bionic" = "yes" ]; then
641 @@ -272,6 +279,9 @@
642 os_include_dir="os/gnu-linux"
646 + esac
647 + ;;
648 hpux*)
649 os_include_dir="os/hpux"
651 Index: b/gcc/config/mips/linux64.h
652 ===================================================================
653 --- a/gcc/config/mips/linux64.h
654 +++ b/gcc/config/mips/linux64.h
655 @@ -41,4 +41,4 @@
656 #define BIONIC_DYNAMIC_LINKERN32 "/system/bin/linker32"
657 #define GNU_USER_DYNAMIC_LINKERN32 \
658 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERN32, UCLIBC_DYNAMIC_LINKERN32, \
659 - BIONIC_DYNAMIC_LINKERN32)
660 + BIONIC_DYNAMIC_LINKERN32, MUSL_DYNAMIC_LINKER)
661 Index: b/gcc/config/mips/linux.h
662 ===================================================================
663 --- a/gcc/config/mips/linux.h
664 +++ b/gcc/config/mips/linux.h
665 @@ -23,3 +23,11 @@
666 #undef UCLIBC_DYNAMIC_LINKER
667 #define UCLIBC_DYNAMIC_LINKER \
668 "%{mnan=2008:/lib/ld-uClibc-mipsn8.so.0;:/lib/ld-uClibc.so.0}"
670 +#if TARGET_ENDIAN_DEFAULT == 0 /* LE */
671 +#define MUSL_DYNAMIC_LINKER_E "%{EB:;:el}"
672 +#else
673 +#define MUSL_DYNAMIC_LINKER_E "%{EL:el}"
674 +#endif
675 +#undef MUSL_DYNAMIC_LINKER
676 +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-mips" MUSL_DYNAMIC_LINKER_E ".so.1"