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
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 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
26 # Parent f50bb54f331f73405131a30b4f353cfda1c70304
27 Use the generic implementation of libstdc++ primitives when we're on musl, not the glibc one.
29 Index: b/libstdc++-v3/configure.host
30 ===================================================================
31 --- a/libstdc++-v3/configure.host
32 +++ b/libstdc++-v3/configure.host
34 os_include_dir="os/bsd/freebsd"
36 gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu)
37 + # check for musl by target
38 + case "${host_os}" in
40 + os_include_dir="os/generic"
44 if [ "$uclibc" = "yes" ]; then
45 os_include_dir="os/uclibc"
46 elif [ "$bionic" = "yes" ]; then
48 os_include_dir="os/gnu-linux"
55 os_include_dir="os/hpux"
57 Index: b/gcc/config.gcc
58 ===================================================================
65 -tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3"
66 +tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3 LIBC_MUSL=4"
68 # Common parts for widely ported systems.
72 tm_defines="$tm_defines DEFAULT_LIBC=LIBC_UCLIBC"
75 + tm_defines="$tm_defines DEFAULT_LIBC=LIBC_MUSL"
78 tm_defines="$tm_defines DEFAULT_LIBC=LIBC_GLIBC"
80 @@ -2091,6 +2094,10 @@
81 powerpc*-*-linux*paired*)
82 tm_file="${tm_file} rs6000/750cl.h" ;;
86 + enable_secureplt=yes ;;
88 if test x${enable_secureplt} = xyes; then
89 tm_file="rs6000/secureplt.h ${tm_file}"
91 Index: b/gcc/config/linux.h
92 ===================================================================
93 --- a/gcc/config/linux.h
94 +++ b/gcc/config/linux.h
96 #define OPTION_GLIBC (DEFAULT_LIBC == LIBC_GLIBC)
97 #define OPTION_UCLIBC (DEFAULT_LIBC == LIBC_UCLIBC)
98 #define OPTION_BIONIC (DEFAULT_LIBC == LIBC_BIONIC)
99 +#define OPTION_MUSL (DEFAULT_LIBC == LIBC_MUSL)
101 #define OPTION_GLIBC (linux_libc == LIBC_GLIBC)
102 #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
103 #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
104 +#define OPTION_MUSL (linux_libc == LIBC_MUSL)
107 #define GNU_USER_TARGET_OS_CPP_BUILTINS() \
109 uClibc or Bionic is the default C library and whether
110 -muclibc or -mglibc or -mbionic has been passed to change the default. */
112 -#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LD1, LD2, LD3) \
113 - "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:" LD1 "}}"
114 +#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LIBC4, LD1, LD2, LD3, LD4) \
115 + "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:%{" LIBC4 ":" LD4 ";:" LD1 "}}}"
117 #if DEFAULT_LIBC == LIBC_GLIBC
118 -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
119 - CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", G, U, B)
120 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
121 + CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", "mmusl", G, U, B, M)
122 #elif DEFAULT_LIBC == LIBC_UCLIBC
123 -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
124 - CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", U, G, B)
125 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
126 + CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", "mmusl", U, G, B, M)
127 #elif DEFAULT_LIBC == LIBC_BIONIC
128 -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
129 - CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", B, G, U)
130 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
131 + CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", "mmusl", B, G, U, M)
132 +#elif DEFAULT_LIBC == LIBC_MUSL
133 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
134 + CHOOSE_DYNAMIC_LINKER1 ("mmusl", "mglibc", "muclibc", "mbionic", M, G, U, B)
136 #error "Unsupported DEFAULT_LIBC"
137 #endif /* DEFAULT_LIBC */
139 #define BIONIC_DYNAMIC_LINKER64 "/system/bin/linker64"
140 #define BIONIC_DYNAMIC_LINKERX32 "/system/bin/linkerx32"
142 +/* Musl dynamic linker paths must be defined on a per-architecture
143 + basis, for each architecture supported by Musl. However, in order
144 + to let other architectures continue to build with other C
145 + libraries, we provide a dummy definition of the following defines. */
146 +#define MUSL_DYNAMIC_LINKER "invalid"
147 +#define MUSL_DYNAMIC_LINKER32 "invalid"
148 +#define MUSL_DYNAMIC_LINKER64 "invalid"
149 +#define MUSL_DYNAMIC_LINKERX32 "invalid"
151 #define GNU_USER_DYNAMIC_LINKER \
152 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, \
153 - BIONIC_DYNAMIC_LINKER)
154 + BIONIC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
155 #define GNU_USER_DYNAMIC_LINKER32 \
156 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, \
157 - BIONIC_DYNAMIC_LINKER32)
158 + BIONIC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
159 #define GNU_USER_DYNAMIC_LINKER64 \
160 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
161 - BIONIC_DYNAMIC_LINKER64)
162 + BIONIC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
163 #define GNU_USER_DYNAMIC_LINKERX32 \
164 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \
165 - BIONIC_DYNAMIC_LINKERX32)
166 + BIONIC_DYNAMIC_LINKERX32, MUSL_DYNAMIC_LINKERX32)
168 /* Determine whether the entire c99 runtime
169 is present in the runtime library. */
170 #undef TARGET_C99_FUNCTIONS
171 -#define TARGET_C99_FUNCTIONS (OPTION_GLIBC)
172 +#define TARGET_C99_FUNCTIONS (OPTION_GLIBC || OPTION_MUSL)
174 /* Whether we have sincos that follows the GNU extension. */
175 #undef TARGET_HAS_SINCOS
177 /* Whether we have Bionic libc runtime */
178 #undef TARGET_HAS_BIONIC
179 #define TARGET_HAS_BIONIC (OPTION_BIONIC)
181 +/* musl avoids problematic includes by rearranging the include directories.
182 + * Unfortunately, this is mostly duplicated from cppdefault.c */
183 +#if DEFAULT_LIBC == LIBC_MUSL
184 +#define INCLUDE_DEFAULTS_MUSL_GPP \
185 + { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, \
186 + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, \
187 + { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1, \
188 + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 }, \
189 + { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1, \
190 + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },
192 +#ifdef LOCAL_INCLUDE_DIR
193 +#define INCLUDE_DEFAULTS_MUSL_LOCAL \
194 + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 }, \
195 + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 },
197 +#define INCLUDE_DEFAULTS_MUSL_LOCAL
200 +#ifdef PREFIX_INCLUDE_DIR
201 +#define INCLUDE_DEFAULTS_MUSL_PREFIX \
202 + { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0},
204 +#define INCLUDE_DEFAULTS_MUSL_PREFIX
207 +#ifdef CROSS_INCLUDE_DIR
208 +#define INCLUDE_DEFAULTS_MUSL_CROSS \
209 + { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0},
211 +#define INCLUDE_DEFAULTS_MUSL_CROSS
214 +#ifdef TOOL_INCLUDE_DIR
215 +#define INCLUDE_DEFAULTS_MUSL_TOOL \
216 + { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0},
218 +#define INCLUDE_DEFAULTS_MUSL_TOOL
221 +#ifdef NATIVE_SYSTEM_HEADER_DIR
222 +#define INCLUDE_DEFAULTS_MUSL_NATIVE \
223 + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 2 }, \
224 + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 0 },
226 +#define INCLUDE_DEFAULTS_MUSL_NATIVE
229 +#if defined (CROSS_DIRECTORY_STRUCTURE) && !defined (TARGET_SYSTEM_ROOT)
230 +# undef INCLUDE_DEFAULTS_MUSL_LOCAL
231 +# define INCLUDE_DEFAULTS_MUSL_LOCAL
232 +# undef INCLUDE_DEFAULTS_MUSL_NATIVE
233 +# define INCLUDE_DEFAULTS_MUSL_NATIVE
235 +# undef INCLUDE_DEFAULTS_MUSL_CROSS
236 +# define INCLUDE_DEFAULTS_MUSL_CROSS
239 +#undef INCLUDE_DEFAULTS
240 +#define INCLUDE_DEFAULTS \
242 + INCLUDE_DEFAULTS_MUSL_GPP \
243 + INCLUDE_DEFAULTS_MUSL_PREFIX \
244 + INCLUDE_DEFAULTS_MUSL_CROSS \
245 + INCLUDE_DEFAULTS_MUSL_TOOL \
246 + INCLUDE_DEFAULTS_MUSL_NATIVE \
247 + { GCC_INCLUDE_DIR, "GCC", 0, 1, 0, 0 }, \
248 + { 0, 0, 0, 0, 0, 0 } \
251 Index: b/gcc/config/linux.opt
252 ===================================================================
253 --- a/gcc/config/linux.opt
254 +++ b/gcc/config/linux.opt
257 Target Report RejectNegative Var(linux_libc,LIBC_UCLIBC) Negative(mbionic)
261 +Target Report RejectNegative Var(linux_libc,LIBC_MUSL) Negative(mglibc)
263 Index: b/gcc/ginclude/stddef.h
264 ===================================================================
265 --- a/gcc/ginclude/stddef.h
266 +++ b/gcc/ginclude/stddef.h
271 +#ifndef __DEFINED_size_t /* musl */
272 #define __size_t__ /* BeOS */
273 #define __SIZE_T__ /* Cray Unicos/Mk */
276 #define ___int_size_t_h
279 +#define __DEFINED_size_t /* musl */
280 #if (defined (__FreeBSD__) && (__FreeBSD__ >= 5)) \
281 || defined(__FreeBSD_kernel__)
282 /* __size_t is a typedef on FreeBSD 5, must not trash it. */
284 typedef long ssize_t;
285 #endif /* __BEOS__ */
286 #endif /* !(defined (__GNUG__) && defined (size_t)) */
287 +#endif /* __DEFINED_size_t */
288 #endif /* __size_t */
290 #endif /* _GCC_SIZE_T */
291 Index: b/libgomp/config/posix/time.c
292 ===================================================================
293 --- a/libgomp/config/posix/time.c
294 +++ b/libgomp/config/posix/time.c
296 The following implementation uses the most simple POSIX routines.
297 If present, POSIX 4 clocks should be used instead. */
299 +#define _POSIX_C_SOURCE 199309L /* for clocks */
303 #if TIME_WITH_SYS_TIME
304 Index: b/libgcc/unwind-dw2-fde-dip.c
305 ===================================================================
306 --- a/libgcc/unwind-dw2-fde-dip.c
307 +++ b/libgcc/unwind-dw2-fde-dip.c
309 # define USE_PT_GNU_EH_FRAME
312 +/* For musl libc, TARGET_DL_ITERATE_PHDR gets defined by the configure
314 +#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
315 + && defined(TARGET_DL_ITERATE_PHDR)
316 +# define USE_PT_GNU_EH_FRAME
319 #if defined(USE_PT_GNU_EH_FRAME)
322 Index: b/gcc/configure
323 ===================================================================
326 @@ -26791,6 +26791,9 @@
328 gcc_cv_libc_provides_ssp=no
331 + # All versions of musl provide stack protector
332 + gcc_cv_libc_provides_ssp=yes;;
333 *-*-linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu)
334 # glibc 2.4 and later provides __stack_chk_fail and
335 # either __stack_chk_guard, or TLS access to stack guard canary.
336 @@ -26824,6 +26827,7 @@
337 # <http://gcc.gnu.org/ml/gcc/2008-10/msg00130.html>) and for now
338 # simply assert that glibc does provide this, which is true for all
339 # realistically usable GNU/Hurd configurations.
340 + # All supported versions of musl provide it as well
341 gcc_cv_libc_provides_ssp=yes;;
342 *-*-darwin* | *-*-freebsd*)
343 ac_fn_c_check_func "$LINENO" "__stack_chk_fail" "ac_cv_func___stack_chk_fail"
344 @@ -26906,6 +26910,9 @@
345 gcc_cv_target_dl_iterate_phdr=no
349 + gcc_cv_target_dl_iterate_phdr=yes
353 if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
354 Index: b/gcc/configure.ac
355 ===================================================================
356 --- a/gcc/configure.ac
357 +++ b/gcc/configure.ac
358 @@ -4669,6 +4669,9 @@
359 gcc_cv_libc_provides_ssp,
360 [gcc_cv_libc_provides_ssp=no
363 + # All versions of musl provide stack protector
364 + gcc_cv_libc_provides_ssp=yes;;
365 *-*-linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu)
366 [# glibc 2.4 and later provides __stack_chk_fail and
367 # either __stack_chk_guard, or TLS access to stack guard canary.
368 @@ -4702,6 +4705,7 @@
369 # <http://gcc.gnu.org/ml/gcc/2008-10/msg00130.html>) and for now
370 # simply assert that glibc does provide this, which is true for all
371 # realistically usable GNU/Hurd configurations.
372 + # All supported versions of musl provide it as well
373 gcc_cv_libc_provides_ssp=yes;;
374 *-*-darwin* | *-*-freebsd*)
375 AC_CHECK_FUNC(__stack_chk_fail,[gcc_cv_libc_provides_ssp=yes],
376 @@ -4767,6 +4771,9 @@
377 gcc_cv_target_dl_iterate_phdr=no
381 + gcc_cv_target_dl_iterate_phdr=yes
384 GCC_TARGET_TEMPLATE([TARGET_DL_ITERATE_PHDR])
385 if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
386 Index: b/fixincludes/mkfixinc.sh
387 ===================================================================
388 --- a/fixincludes/mkfixinc.sh
389 +++ b/fixincludes/mkfixinc.sh
393 powerpcle-*-eabisim* | \
394 - powerpcle-*-eabi* )
395 + powerpcle-*-eabi* | \
397 # IF there is no include fixing,
398 # THEN create a no-op fixer and exit
399 (echo "#! /bin/sh" ; echo "exit 0" ) > ${target}
400 Index: b/gcc/config/i386/linux.h
401 ===================================================================
402 --- a/gcc/config/i386/linux.h
403 +++ b/gcc/config/i386/linux.h
406 #define GNU_USER_LINK_EMULATION "elf_i386"
407 #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
408 +#undef MUSL_DYNAMIC_LINKER
409 +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-i386.so.1"
410 Index: b/gcc/config/i386/linux64.h
411 ===================================================================
412 --- a/gcc/config/i386/linux64.h
413 +++ b/gcc/config/i386/linux64.h
415 #define GLIBC_DYNAMIC_LINKER32 "/lib/ld-linux.so.2"
416 #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-linux-x86-64.so.2"
417 #define GLIBC_DYNAMIC_LINKERX32 "/libx32/ld-linux-x32.so.2"
419 +#undef MUSL_DYNAMIC_LINKER32
420 +#undef MUSL_DYNAMIC_LINKER64
421 +#undef MUSL_DYNAMIC_LINKERX32
422 +#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-i386.so.1"
423 +#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-x86_64.so.1"
424 +#define MUSL_DYNAMIC_LINKERX32 "/lib/ld-musl-x32.so.1"
425 Index: b/libitm/config/linux/x86/tls.h
426 ===================================================================
427 --- a/libitm/config/linux/x86/tls.h
428 +++ b/libitm/config/linux/x86/tls.h
430 #ifndef LIBITM_X86_TLS_H
431 #define LIBITM_X86_TLS_H 1
433 -#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
434 +#if defined(__GLIBC_PREREQ)
435 +#if __GLIBC_PREREQ(2, 10)
436 /* Use slots in the TCB head rather than __thread lookups.
437 GLIBC has reserved words 10 through 13 for TM. */
438 #define HAVE_ARCH_GTM_THREAD 1
439 #define HAVE_ARCH_GTM_THREAD_DISP 1
443 #include "config/generic/tls.h"
445 -#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
446 +#if defined(__GLIBC_PREREQ)
447 +#if __GLIBC_PREREQ(2, 10)
448 namespace GTM HIDDEN {
454 #endif /* >= GLIBC 2.10 */
457 #endif // LIBITM_X86_TLS_H
458 Index: b/gcc/config/arm/linux-eabi.h
459 ===================================================================
460 --- a/gcc/config/arm/linux-eabi.h
461 +++ b/gcc/config/arm/linux-eabi.h
463 #undef GLIBC_DYNAMIC_LINKER
464 #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.3"
466 +/* For ARM musl currently supports four dynamic linkers:
467 + - ld-musl-arm.so.1 - for the EABI-derived soft-float ABI
468 + - ld-musl-armhf.so.1 - for the EABI-derived hard-float ABI
469 + - ld-musl-armeb.so.1 - for the EABI-derived soft-float ABI, EB
470 + - ld-musl-armebhf.so.1 - for the EABI-derived hard-float ABI, EB
471 + musl does not support the legacy OABI mode.
472 + All the dynamic linkers live in /lib.
473 + We default to soft-float, EL. */
474 +#undef MUSL_DYNAMIC_LINKER
475 +#if TARGET_BIG_ENDIAN_DEFAULT
476 +#define MUSL_DYNAMIC_LINKER_E "%{mlittle-endian:;:eb}"
478 +#define MUSL_DYNAMIC_LINKER_E "%{mbig-endian:eb}"
480 +#define MUSL_DYNAMIC_LINKER \
481 + "/lib/ld-musl-arm" MUSL_DYNAMIC_LINKER_E "%{mfloat-abi=hard:hf}.so.1"
483 /* At this point, bpabi.h will have clobbered LINK_SPEC. We want to
484 use the GNU/Linux version, not the generic BPABI version. */
486 Index: b/libitm/config/arm/hwcap.cc
487 ===================================================================
488 --- a/libitm/config/arm/hwcap.cc
489 +++ b/libitm/config/arm/hwcap.cc
495 #include <sys/fcntl.h>
501 static void __attribute__((constructor))
502 Index: b/gcc/config/mips/linux.h
503 ===================================================================
504 --- a/gcc/config/mips/linux.h
505 +++ b/gcc/config/mips/linux.h
507 <http://www.gnu.org/licenses/>. */
509 #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
511 +#if TARGET_ENDIAN_DEFAULT == 0 /* LE */
512 +#define MUSL_DYNAMIC_LINKER_E "%{EB:;:el}"
514 +#define MUSL_DYNAMIC_LINKER_E "%{EL:el}"
516 +#undef MUSL_DYNAMIC_LINKER
517 +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-mips" MUSL_DYNAMIC_LINKER_E ".so.1"
518 Index: b/gcc/config/rs6000/linux64.h
519 ===================================================================
520 --- a/gcc/config/rs6000/linux64.h
521 +++ b/gcc/config/rs6000/linux64.h
522 @@ -362,17 +362,23 @@
523 #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld64.so.1"
524 #define UCLIBC_DYNAMIC_LINKER32 "/lib/ld-uClibc.so.0"
525 #define UCLIBC_DYNAMIC_LINKER64 "/lib/ld64-uClibc.so.0"
526 +#undef MUSL_DYNAMIC_LINKER32
527 +#undef MUSL_DYNAMIC_LINKER64
528 +#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-powerpc.so.1"
529 +#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-powerpc64.so.1"
530 #if DEFAULT_LIBC == LIBC_UCLIBC
531 -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
532 +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
533 #elif DEFAULT_LIBC == LIBC_GLIBC
534 -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
535 +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
536 +#elif DEFAULT_LIBC == LIBC_MUSL
537 +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
539 #error "Unsupported DEFAULT_LIBC"
541 #define GNU_USER_DYNAMIC_LINKER32 \
542 - CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32)
543 + CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
544 #define GNU_USER_DYNAMIC_LINKER64 \
545 - CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64)
546 + CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
549 #define LINK_OS_LINUX_SPEC32 "-m elf32ppclinux %{!shared: %{!static: \
550 Index: b/gcc/config/rs6000/secureplt.h
551 ===================================================================
552 --- a/gcc/config/rs6000/secureplt.h
553 +++ b/gcc/config/rs6000/secureplt.h
555 <http://www.gnu.org/licenses/>. */
557 #define CC1_SECURE_PLT_DEFAULT_SPEC "-msecure-plt"
558 +#define LINK_SECURE_PLT_DEFAULT_SPEC "--secure-plt"
559 Index: b/gcc/config/rs6000/sysv4.h
560 ===================================================================
561 --- a/gcc/config/rs6000/sysv4.h
562 +++ b/gcc/config/rs6000/sysv4.h
564 #ifndef CC1_SECURE_PLT_DEFAULT_SPEC
565 #define CC1_SECURE_PLT_DEFAULT_SPEC ""
567 +#ifndef LINK_SECURE_PLT_DEFAULT_SPEC
568 +#define LINK_SECURE_PLT_DEFAULT_SPEC ""
571 /* Pass -G xxx to the compiler and set correct endian mode. */
572 #define CC1_SPEC "%{G*} %(cc1_cpu) \
574 %{mlittle: --oformat elf32-powerpcle } %{mlittle-endian: --oformat elf32-powerpcle } \
575 %{!mlittle: %{!mlittle-endian: %{!mbig: %{!mbig-endian: \
576 %{mcall-i960-old: --oformat elf32-powerpcle} \
579 +%{!mbss-plt: %{!msecure-plt: %(link_secure_plt_default)}}"
581 /* Any specific OS flags. */
582 #define LINK_OS_SPEC "\
583 @@ -804,15 +808,19 @@
585 #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
586 #define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0"
587 +#undef MUSL_DYNAMIC_LINKER
588 +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-powerpc.so.1"
589 #if DEFAULT_LIBC == LIBC_UCLIBC
590 -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
591 +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
592 +#elif DEFAULT_LIBC == LIBC_MUSL
593 +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
594 #elif !defined (DEFAULT_LIBC) || DEFAULT_LIBC == LIBC_GLIBC
595 -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
596 +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
598 #error "Unsupported DEFAULT_LIBC"
600 #define GNU_USER_DYNAMIC_LINKER \
601 - CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER)
602 + CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
604 #define LINK_OS_LINUX_SPEC "-m elf32ppclinux %{!shared: %{!static: \
605 %{rdynamic:-export-dynamic} \
607 { "cc1_endian_little", CC1_ENDIAN_LITTLE_SPEC }, \
608 { "cc1_endian_default", CC1_ENDIAN_DEFAULT_SPEC }, \
609 { "cc1_secure_plt_default", CC1_SECURE_PLT_DEFAULT_SPEC }, \
610 + { "link_secure_plt_default", LINK_SECURE_PLT_DEFAULT_SPEC }, \
611 { "cpp_os_ads", CPP_OS_ADS_SPEC }, \
612 { "cpp_os_yellowknife", CPP_OS_YELLOWKNIFE_SPEC }, \
613 { "cpp_os_mvme", CPP_OS_MVME_SPEC }, \
614 Index: b/gcc/config/mips/linux64.h
615 ===================================================================
616 --- a/gcc/config/mips/linux64.h
617 +++ b/gcc/config/mips/linux64.h
619 #define BIONIC_DYNAMIC_LINKERN32 "/system/bin/linker32"
620 #define GNU_USER_DYNAMIC_LINKERN32 \
621 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERN32, UCLIBC_DYNAMIC_LINKERN32, \
622 - BIONIC_DYNAMIC_LINKERN32)
623 + BIONIC_DYNAMIC_LINKERN32, MUSL_DYNAMIC_LINKER)