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 [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>
26 Index: b/fixincludes/mkfixinc.sh
27 ===================================================================
28 --- a/fixincludes/mkfixinc.sh
29 +++ b/fixincludes/mkfixinc.sh
33 powerpcle-*-eabisim* | \
35 + powerpcle-*-eabi* | \
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 ===================================================================
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.
55 tm_defines="$tm_defines DEFAULT_LIBC=LIBC_UCLIBC"
58 + tm_defines="$tm_defines DEFAULT_LIBC=LIBC_MUSL"
61 tm_defines="$tm_defines DEFAULT_LIBC=LIBC_GLIBC"
63 @@ -2338,6 +2341,10 @@
64 powerpc*-*-linux*paired*)
65 tm_file="${tm_file} rs6000/750cl.h" ;;
69 + enable_secureplt=yes ;;
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
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
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}"
107 +#define MUSL_DYNAMIC_LINKER_E "%{mbig-endian:eb}"
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. */
115 Index: b/gcc/config/i386/linux.h
116 ===================================================================
117 --- a/gcc/config/i386/linux.h
118 +++ b/gcc/config/i386/linux.h
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
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
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)
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)
156 #define GNU_USER_TARGET_OS_CPP_BUILTINS() \
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)
185 #error "Unsupported DEFAULT_LIBC"
186 #endif /* DEFAULT_LIBC */
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 },
237 +#define INCLUDE_DEFAULTS_MUSL_LOCAL
240 +#ifdef PREFIX_INCLUDE_DIR
241 +#define INCLUDE_DEFAULTS_MUSL_PREFIX \
242 + { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0},
244 +#define INCLUDE_DEFAULTS_MUSL_PREFIX
247 +#ifdef CROSS_INCLUDE_DIR
248 +#define INCLUDE_DEFAULTS_MUSL_CROSS \
249 + { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0},
251 +#define INCLUDE_DEFAULTS_MUSL_CROSS
254 +#ifdef TOOL_INCLUDE_DIR
255 +#define INCLUDE_DEFAULTS_MUSL_TOOL \
256 + { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0},
258 +#define INCLUDE_DEFAULTS_MUSL_TOOL
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 },
266 +#define INCLUDE_DEFAULTS_MUSL_NATIVE
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
275 +# undef INCLUDE_DEFAULTS_MUSL_CROSS
276 +# define INCLUDE_DEFAULTS_MUSL_CROSS
279 +#undef INCLUDE_DEFAULTS
280 +#define INCLUDE_DEFAULTS \
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 } \
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
301 Target Report RejectNegative Var(linux_libc,LIBC_UCLIBC) Negative(mbionic)
305 +Target Report RejectNegative Var(linux_libc,LIBC_MUSL) Negative(mglibc)
307 Index: b/gcc/config/microblaze/linux.h
308 ===================================================================
309 --- a/gcc/config/microblaze/linux.h
310 +++ b/gcc/config/microblaze/linux.h
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}"
319 +#define MUSL_DYNAMIC_LINKER_E "%{EL:el}"
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
329 +#define DYNAMIC_LINKER GLIBC_DYNAMIC_LINKER
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 @@ -371,17 +371,23 @@
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 "}}"
357 #error "Unsupported DEFAULT_LIBC"
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
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
382 #ifndef CC1_SECURE_PLT_DEFAULT_SPEC
383 #define CC1_SECURE_PLT_DEFAULT_SPEC ""
385 +#ifndef LINK_SECURE_PLT_DEFAULT_SPEC
386 +#define LINK_SECURE_PLT_DEFAULT_SPEC ""
389 /* Pass -G xxx to the compiler. */
390 #define CC1_SPEC "%{G*} %(cc1_cpu)" \
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 "}}"
415 #error "Unsupported DEFAULT_LIBC"
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} \
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
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"
442 +#define MUSL_DYNAMIC_LINKER_E
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 ===================================================================
455 @@ -27601,6 +27601,9 @@
456 gcc_cv_target_dl_iterate_phdr=no
460 + gcc_cv_target_dl_iterate_phdr=yes
464 if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
465 Index: b/gcc/configure.ac
466 ===================================================================
467 --- a/gcc/configure.ac
468 +++ b/gcc/configure.ac
469 @@ -5173,6 +5173,9 @@
470 gcc_cv_target_dl_iterate_phdr=no
474 + gcc_cv_target_dl_iterate_phdr=yes
477 GCC_TARGET_TEMPLATE([TARGET_DL_ITERATE_PHDR])
478 if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
479 Index: b/gcc/ginclude/stddef.h
480 ===================================================================
481 --- a/gcc/ginclude/stddef.h
482 +++ b/gcc/ginclude/stddef.h
487 +#ifndef __DEFINED_size_t /* musl */
488 #define __size_t__ /* BeOS */
489 #define __SIZE_T__ /* Cray Unicos/Mk */
492 #define ___int_size_t_h
495 +#define __DEFINED_size_t /* musl */
496 #if (defined (__FreeBSD__) && (__FreeBSD__ >= 5)) \
497 || defined(__FreeBSD_kernel__)
498 /* __size_t is a typedef on FreeBSD 5, must not trash it. */
500 typedef long ssize_t;
501 #endif /* __BEOS__ */
502 #endif /* !(defined (__GNUG__) && defined (size_t)) */
503 +#endif /* __DEFINED_size_t */
504 #endif /* __size_t */
506 #endif /* _GCC_SIZE_T */
507 Index: b/libgcc/unwind-dw2-fde-dip.c
508 ===================================================================
509 --- a/libgcc/unwind-dw2-fde-dip.c
510 +++ b/libgcc/unwind-dw2-fde-dip.c
512 && defined(TARGET_DL_ITERATE_PHDR) \
513 && defined(__sun__) && defined(__svr4__)
514 # define USE_PT_GNU_EH_FRAME
517 +/* For musl libc, TARGET_DL_ITERATE_PHDR gets defined by the configure
519 +#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
520 + && defined(TARGET_DL_ITERATE_PHDR)
521 +# define USE_PT_GNU_EH_FRAME
524 #if defined(USE_PT_GNU_EH_FRAME)
525 Index: b/libgomp/config/posix/time.c
526 ===================================================================
527 --- a/libgomp/config/posix/time.c
528 +++ b/libgomp/config/posix/time.c
530 The following implementation uses the most simple POSIX routines.
531 If present, POSIX 4 clocks should be used instead. */
533 +#define _POSIX_C_SOURCE 199309L /* for clocks */
537 #if TIME_WITH_SYS_TIME
538 Index: b/libitm/config/arm/hwcap.cc
539 ===================================================================
540 --- a/libitm/config/arm/hwcap.cc
541 +++ b/libitm/config/arm/hwcap.cc
547 #include <sys/fcntl.h>
553 static void __attribute__((constructor))
554 Index: b/libitm/config/linux/x86/tls.h
555 ===================================================================
556 --- a/libitm/config/linux/x86/tls.h
557 +++ b/libitm/config/linux/x86/tls.h
559 #ifndef LIBITM_X86_TLS_H
560 #define LIBITM_X86_TLS_H 1
562 -#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
563 +#if defined(__GLIBC_PREREQ)
564 +#if __GLIBC_PREREQ(2, 10)
565 /* Use slots in the TCB head rather than __thread lookups.
566 GLIBC has reserved words 10 through 13 for TM. */
567 #define HAVE_ARCH_GTM_THREAD 1
568 #define HAVE_ARCH_GTM_THREAD_DISP 1
572 #include "config/generic/tls.h"
574 -#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
575 +#if defined(__GLIBC_PREREQ)
576 +#if __GLIBC_PREREQ(2, 10)
577 namespace GTM HIDDEN {
583 #endif /* >= GLIBC 2.10 */
586 #endif // LIBITM_X86_TLS_H
587 Index: b/libstdc++-v3/configure.host
588 ===================================================================
589 --- a/libstdc++-v3/configure.host
590 +++ b/libstdc++-v3/configure.host
592 os_include_dir="os/bsd/freebsd"
594 gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu)
595 + # check for musl by target
596 + case "${host_os}" in
598 + os_include_dir="os/generic"
602 if [ "$uclibc" = "yes" ]; then
603 os_include_dir="os/uclibc"
604 elif [ "$bionic" = "yes" ]; then
606 os_include_dir="os/gnu-linux"
613 os_include_dir="os/hpux"
615 Index: b/gcc/config/mips/linux64.h
616 ===================================================================
617 --- a/gcc/config/mips/linux64.h
618 +++ b/gcc/config/mips/linux64.h
620 #define BIONIC_DYNAMIC_LINKERN32 "/system/bin/linker32"
621 #define GNU_USER_DYNAMIC_LINKERN32 \
622 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERN32, UCLIBC_DYNAMIC_LINKERN32, \
623 - BIONIC_DYNAMIC_LINKERN32)
624 + BIONIC_DYNAMIC_LINKERN32, MUSL_DYNAMIC_LINKER)
625 Index: b/gcc/config/mips/linux.h
626 ===================================================================
627 --- a/gcc/config/mips/linux.h
628 +++ b/gcc/config/mips/linux.h
630 #undef UCLIBC_DYNAMIC_LINKER
631 #define UCLIBC_DYNAMIC_LINKER \
632 "%{mnan=2008:/lib/ld-uClibc-mipsn8.so.0;:/lib/ld-uClibc.so.0}"
634 +#if TARGET_ENDIAN_DEFAULT == 0 /* LE */
635 +#define MUSL_DYNAMIC_LINKER_E "%{EB:;:el}"
637 +#define MUSL_DYNAMIC_LINKER_E "%{EL:el}"
639 +#undef MUSL_DYNAMIC_LINKER
640 +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-mips" MUSL_DYNAMIC_LINKER_E "%{msoft-float:-sf}.so.1"