board/csky: fixup gdb instructions in readme.txt
[buildroot-gz.git] / package / gcc / 4.8.5 / 900-musl-support.patch
blob6840fccea444dba8ed2af9fe3e7aebc4b0059859
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 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
23 [Gustavo: Update for gcc 4.8.3]
25 Index: b/fixincludes/mkfixinc.sh
26 ===================================================================
27 --- a/fixincludes/mkfixinc.sh
28 +++ b/fixincludes/mkfixinc.sh
29 @@ -19,7 +19,8 @@
30 powerpc-*-eabi* | \
31 powerpc-*-rtems* | \
32 powerpcle-*-eabisim* | \
33 - powerpcle-*-eabi* )
34 + powerpcle-*-eabi* | \
35 + *-musl* )
36 # IF there is no include fixing,
37 # THEN create a no-op fixer and exit
38 (echo "#! /bin/sh" ; echo "exit 0" ) > ${target}
39 Index: b/gcc/config/aarch64/aarch64-linux.h
40 ===================================================================
41 --- a/gcc/config/aarch64/aarch64-linux.h
42 +++ b/gcc/config/aarch64/aarch64-linux.h
43 @@ -21,7 +21,12 @@
44 #ifndef GCC_AARCH64_LINUX_H
45 #define GCC_AARCH64_LINUX_H
47 +/* The AArch64 port currently supports two dynamic linkers:
48 + - ld-linux-aarch64.so.1 - GLIBC dynamic linker
49 + - ld-musl-aarch64.so.1 - musl libc dynamic linker */
50 #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux-aarch64.so.1"
51 +#undef MUSL_DYNAMIC_LINKER
52 +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-aarch64.so.1"
54 #define CPP_SPEC "%{pthread:-D_REENTRANT}"
56 Index: b/gcc/config/arm/linux-eabi.h
57 ===================================================================
58 --- a/gcc/config/arm/linux-eabi.h
59 +++ b/gcc/config/arm/linux-eabi.h
60 @@ -77,6 +77,23 @@
61 %{mfloat-abi=soft*:" GLIBC_DYNAMIC_LINKER_SOFT_FLOAT "} \
62 %{!mfloat-abi=*:" GLIBC_DYNAMIC_LINKER_DEFAULT "}"
64 +/* For ARM musl currently supports four dynamic linkers:
65 + - ld-musl-arm.so.1 - for the EABI-derived soft-float ABI
66 + - ld-musl-armhf.so.1 - for the EABI-derived hard-float ABI
67 + - ld-musl-armeb.so.1 - for the EABI-derived soft-float ABI, EB
68 + - ld-musl-armebhf.so.1 - for the EABI-derived hard-float ABI, EB
69 + musl does not support the legacy OABI mode.
70 + All the dynamic linkers live in /lib.
71 + We default to soft-float, EL. */
72 +#undef MUSL_DYNAMIC_LINKER
73 +#if TARGET_BIG_ENDIAN_DEFAULT
74 +#define MUSL_DYNAMIC_LINKER_E "%{mlittle-endian:;:eb}"
75 +#else
76 +#define MUSL_DYNAMIC_LINKER_E "%{mbig-endian:eb}"
77 +#endif
78 +#define MUSL_DYNAMIC_LINKER \
79 + "/lib/ld-musl-arm" MUSL_DYNAMIC_LINKER_E "%{mfloat-abi=hard:hf}.so.1"
81 /* At this point, bpabi.h will have clobbered LINK_SPEC. We want to
82 use the GNU/Linux version, not the generic BPABI version. */
83 #undef LINK_SPEC
84 Index: b/gcc/config/i386/linux64.h
85 ===================================================================
86 --- a/gcc/config/i386/linux64.h
87 +++ b/gcc/config/i386/linux64.h
88 @@ -30,3 +30,10 @@
89 #define GLIBC_DYNAMIC_LINKER32 "/lib/ld-linux.so.2"
90 #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-linux-x86-64.so.2"
91 #define GLIBC_DYNAMIC_LINKERX32 "/libx32/ld-linux-x32.so.2"
93 +#undef MUSL_DYNAMIC_LINKER32
94 +#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-i386.so.1"
95 +#undef MUSL_DYNAMIC_LINKER64
96 +#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-x86_64.so.1"
97 +#undef MUSL_DYNAMIC_LINKERX32
98 +#define MUSL_DYNAMIC_LINKERX32 "/lib/ld-musl-x32.so.1"
99 Index: b/gcc/config/i386/linux.h
100 ===================================================================
101 --- a/gcc/config/i386/linux.h
102 +++ b/gcc/config/i386/linux.h
103 @@ -21,3 +21,5 @@
105 #define GNU_USER_LINK_EMULATION "elf_i386"
106 #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
107 +#undef MUSL_DYNAMIC_LINKER
108 +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-i386.so.1"
109 Index: b/gcc/config/linux.h
110 ===================================================================
111 --- a/gcc/config/linux.h
112 +++ b/gcc/config/linux.h
113 @@ -32,10 +32,12 @@
114 #define OPTION_GLIBC (DEFAULT_LIBC == LIBC_GLIBC)
115 #define OPTION_UCLIBC (DEFAULT_LIBC == LIBC_UCLIBC)
116 #define OPTION_BIONIC (DEFAULT_LIBC == LIBC_BIONIC)
117 +#define OPTION_MUSL (DEFAULT_LIBC == LIBC_MUSL)
118 #else
119 #define OPTION_GLIBC (linux_libc == LIBC_GLIBC)
120 #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
121 #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
122 +#define OPTION_MUSL (linux_libc == LIBC_MUSL)
123 #endif
125 #define GNU_USER_TARGET_OS_CPP_BUILTINS() \
126 @@ -53,18 +55,21 @@
127 uClibc or Bionic is the default C library and whether
128 -muclibc or -mglibc or -mbionic has been passed to change the default. */
130 -#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LD1, LD2, LD3) \
131 - "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:" LD1 "}}"
132 +#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LIBC4, LD1, LD2, LD3, LD4) \
133 + "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:%{" LIBC4 ":" LD4 ";:" LD1 "}}}"
135 #if DEFAULT_LIBC == LIBC_GLIBC
136 -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
137 - CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", G, U, B)
138 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
139 + CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", "mmusl", G, U, B, M)
140 #elif DEFAULT_LIBC == LIBC_UCLIBC
141 -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
142 - CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", U, G, B)
143 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
144 + CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", "mmusl", U, G, B, M)
145 #elif DEFAULT_LIBC == LIBC_BIONIC
146 -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
147 - CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", B, G, U)
148 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
149 + CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", "mmusl", B, G, U, M)
150 +#elif DEFAULT_LIBC == LIBC_MUSL
151 +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
152 + CHOOSE_DYNAMIC_LINKER1 ("mmusl", "mglibc", "muclibc", "mbionic", M, G, U, B)
153 #else
154 #error "Unsupported DEFAULT_LIBC"
155 #endif /* DEFAULT_LIBC */
156 @@ -82,23 +87,32 @@
157 #define BIONIC_DYNAMIC_LINKER64 "/system/bin/linker64"
158 #define BIONIC_DYNAMIC_LINKERX32 "/system/bin/linkerx32"
160 +/* Musl dynamic linker paths must be defined on a per-architecture
161 + basis, for each architecture supported by Musl. However, in order
162 + to let other architectures continue to build with other C
163 + libraries, we provide a dummy definition of the following defines. */
164 +#define MUSL_DYNAMIC_LINKER "invalid"
165 +#define MUSL_DYNAMIC_LINKER32 "invalid"
166 +#define MUSL_DYNAMIC_LINKER64 "invalid"
167 +#define MUSL_DYNAMIC_LINKERX32 "invalid"
169 #define GNU_USER_DYNAMIC_LINKER \
170 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, \
171 - BIONIC_DYNAMIC_LINKER)
172 + BIONIC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
173 #define GNU_USER_DYNAMIC_LINKER32 \
174 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, \
175 - BIONIC_DYNAMIC_LINKER32)
176 + BIONIC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
177 #define GNU_USER_DYNAMIC_LINKER64 \
178 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
179 - BIONIC_DYNAMIC_LINKER64)
180 + BIONIC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
181 #define GNU_USER_DYNAMIC_LINKERX32 \
182 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \
183 - BIONIC_DYNAMIC_LINKERX32)
184 + BIONIC_DYNAMIC_LINKERX32, MUSL_DYNAMIC_LINKERX32)
186 /* Determine whether the entire c99 runtime
187 is present in the runtime library. */
188 #undef TARGET_C99_FUNCTIONS
189 -#define TARGET_C99_FUNCTIONS (OPTION_GLIBC)
190 +#define TARGET_C99_FUNCTIONS (OPTION_GLIBC || OPTION_MUSL)
192 /* Whether we have sincos that follows the GNU extension. */
193 #undef TARGET_HAS_SINCOS
194 @@ -107,3 +121,74 @@
195 /* Whether we have Bionic libc runtime */
196 #undef TARGET_HAS_BIONIC
197 #define TARGET_HAS_BIONIC (OPTION_BIONIC)
199 +/* musl avoids problematic includes by rearranging the include directories.
200 + * Unfortunately, this is mostly duplicated from cppdefault.c */
201 +#if DEFAULT_LIBC == LIBC_MUSL
202 +#define INCLUDE_DEFAULTS_MUSL_GPP \
203 + { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, \
204 + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, \
205 + { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1, \
206 + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 }, \
207 + { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1, \
208 + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },
210 +#ifdef LOCAL_INCLUDE_DIR
211 +#define INCLUDE_DEFAULTS_MUSL_LOCAL \
212 + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 }, \
213 + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 },
214 +#else
215 +#define INCLUDE_DEFAULTS_MUSL_LOCAL
216 +#endif
218 +#ifdef PREFIX_INCLUDE_DIR
219 +#define INCLUDE_DEFAULTS_MUSL_PREFIX \
220 + { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0},
221 +#else
222 +#define INCLUDE_DEFAULTS_MUSL_PREFIX
223 +#endif
225 +#ifdef CROSS_INCLUDE_DIR
226 +#define INCLUDE_DEFAULTS_MUSL_CROSS \
227 + { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0},
228 +#else
229 +#define INCLUDE_DEFAULTS_MUSL_CROSS
230 +#endif
232 +#ifdef TOOL_INCLUDE_DIR
233 +#define INCLUDE_DEFAULTS_MUSL_TOOL \
234 + { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0},
235 +#else
236 +#define INCLUDE_DEFAULTS_MUSL_TOOL
237 +#endif
239 +#ifdef NATIVE_SYSTEM_HEADER_DIR
240 +#define INCLUDE_DEFAULTS_MUSL_NATIVE \
241 + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 2 }, \
242 + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 0 },
243 +#else
244 +#define INCLUDE_DEFAULTS_MUSL_NATIVE
245 +#endif
247 +#if defined (CROSS_DIRECTORY_STRUCTURE) && !defined (TARGET_SYSTEM_ROOT)
248 +# undef INCLUDE_DEFAULTS_MUSL_LOCAL
249 +# define INCLUDE_DEFAULTS_MUSL_LOCAL
250 +# undef INCLUDE_DEFAULTS_MUSL_NATIVE
251 +# define INCLUDE_DEFAULTS_MUSL_NATIVE
252 +#else
253 +# undef INCLUDE_DEFAULTS_MUSL_CROSS
254 +# define INCLUDE_DEFAULTS_MUSL_CROSS
255 +#endif
257 +#undef INCLUDE_DEFAULTS
258 +#define INCLUDE_DEFAULTS \
259 + { \
260 + INCLUDE_DEFAULTS_MUSL_GPP \
261 + INCLUDE_DEFAULTS_MUSL_PREFIX \
262 + INCLUDE_DEFAULTS_MUSL_CROSS \
263 + INCLUDE_DEFAULTS_MUSL_TOOL \
264 + INCLUDE_DEFAULTS_MUSL_NATIVE \
265 + { GCC_INCLUDE_DIR, "GCC", 0, 1, 0, 0 }, \
266 + { 0, 0, 0, 0, 0, 0 } \
268 +#endif
269 Index: b/gcc/config/linux.opt
270 ===================================================================
271 --- a/gcc/config/linux.opt
272 +++ b/gcc/config/linux.opt
273 @@ -30,3 +30,7 @@
274 muclibc
275 Target Report RejectNegative Var(linux_libc,LIBC_UCLIBC) Negative(mbionic)
276 Use uClibc C library
278 +mmusl
279 +Target Report RejectNegative Var(linux_libc,LIBC_MUSL) Negative(mglibc)
280 +Use musl C library
281 Index: b/gcc/config/microblaze/linux.h
282 ===================================================================
283 --- a/gcc/config/microblaze/linux.h
284 +++ b/gcc/config/microblaze/linux.h
285 @@ -25,7 +25,23 @@
286 #undef TLS_NEEDS_GOT
287 #define TLS_NEEDS_GOT 1
289 -#define DYNAMIC_LINKER "/lib/ld.so.1"
290 +#if TARGET_BIG_ENDIAN_DEFAULT == 0 /* LE */
291 +#define MUSL_DYNAMIC_LINKER_E "%{EB:;:el}"
292 +#else
293 +#define MUSL_DYNAMIC_LINKER_E "%{EL:el}"
294 +#endif
296 +#undef MUSL_DYNAMIC_LINKER
297 +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-microblaze" MUSL_DYNAMIC_LINKER_E ".so.1"
298 +#define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
300 +#if DEFAULT_LIBC == LIBC_MUSL
301 +#define DYNAMIC_LINKER MUSL_DYNAMIC_LINKER
302 +#else
303 +#define DYNAMIC_LINKER GLIBC_DYNAMIC_LINKER
304 +#endif
307 #undef SUBTARGET_EXTRA_SPECS
308 #define SUBTARGET_EXTRA_SPECS \
309 { "dynamic_linker", DYNAMIC_LINKER }
310 Index: b/gcc/config/mips/linux64.h
311 ===================================================================
312 --- a/gcc/config/mips/linux64.h
313 +++ b/gcc/config/mips/linux64.h
314 @@ -29,4 +29,4 @@
315 #define BIONIC_DYNAMIC_LINKERN32 "/system/bin/linker32"
316 #define GNU_USER_DYNAMIC_LINKERN32 \
317 CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERN32, UCLIBC_DYNAMIC_LINKERN32, \
318 - BIONIC_DYNAMIC_LINKERN32)
319 + BIONIC_DYNAMIC_LINKERN32, MUSL_DYNAMIC_LINKER)
320 Index: b/gcc/config/mips/linux.h
321 ===================================================================
322 --- a/gcc/config/mips/linux.h
323 +++ b/gcc/config/mips/linux.h
324 @@ -18,3 +18,11 @@
325 <http://www.gnu.org/licenses/>. */
327 #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
329 +#if TARGET_ENDIAN_DEFAULT == 0 /* LE */
330 +#define MUSL_DYNAMIC_LINKER_E "%{EB:;:el}"
331 +#else
332 +#define MUSL_DYNAMIC_LINKER_E "%{EL:el}"
333 +#endif
334 +#undef MUSL_DYNAMIC_LINKER
335 +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-mips" MUSL_DYNAMIC_LINKER_E "%{msoft-float:-sf}.so.1"
336 Index: b/gcc/config/rs6000/linux64.h
337 ===================================================================
338 --- a/gcc/config/rs6000/linux64.h
339 +++ b/gcc/config/rs6000/linux64.h
340 @@ -374,17 +374,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/config.gcc
452 ===================================================================
453 --- a/gcc/config.gcc
454 +++ b/gcc/config.gcc
455 @@ -550,7 +550,7 @@
456 esac
458 # Common C libraries.
459 -tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3"
460 +tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3 LIBC_MUSL=4"
462 # Common parts for widely ported systems.
463 case ${target} in
464 @@ -653,6 +653,9 @@
465 *-*-*uclibc*)
466 tm_defines="$tm_defines DEFAULT_LIBC=LIBC_UCLIBC"
468 + *-*-*musl*)
469 + tm_defines="$tm_defines DEFAULT_LIBC=LIBC_MUSL"
470 + ;;
472 tm_defines="$tm_defines DEFAULT_LIBC=LIBC_GLIBC"
474 @@ -2135,6 +2138,10 @@
475 powerpc*-*-linux*paired*)
476 tm_file="${tm_file} rs6000/750cl.h" ;;
477 esac
478 + case ${target} in
479 + *-linux*-musl*)
480 + enable_secureplt=yes ;;
481 + esac
482 if test x${enable_secureplt} = xyes; then
483 tm_file="rs6000/secureplt.h ${tm_file}"
485 Index: b/gcc/configure
486 ===================================================================
487 --- a/gcc/configure
488 +++ b/gcc/configure
489 @@ -26936,6 +26940,9 @@
490 gcc_cv_target_dl_iterate_phdr=no
493 + *-linux-musl*)
494 + gcc_cv_target_dl_iterate_phdr=yes
495 + ;;
496 esac
498 if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
499 Index: b/gcc/configure.ac
500 ===================================================================
501 --- a/gcc/configure.ac
502 +++ b/gcc/configure.ac
503 @@ -4848,6 +4852,9 @@
504 gcc_cv_target_dl_iterate_phdr=no
507 + *-linux-musl*)
508 + gcc_cv_target_dl_iterate_phdr=yes
509 + ;;
510 esac
511 GCC_TARGET_TEMPLATE([TARGET_DL_ITERATE_PHDR])
512 if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
513 Index: b/gcc/ginclude/stddef.h
514 ===================================================================
515 --- a/gcc/ginclude/stddef.h
516 +++ b/gcc/ginclude/stddef.h
517 @@ -181,6 +181,7 @@
518 #ifndef _GCC_SIZE_T
519 #ifndef _SIZET_
520 #ifndef __size_t
521 +#ifndef __DEFINED_size_t /* musl */
522 #define __size_t__ /* BeOS */
523 #define __SIZE_T__ /* Cray Unicos/Mk */
524 #define _SIZE_T
525 @@ -197,6 +198,7 @@
526 #define ___int_size_t_h
527 #define _GCC_SIZE_T
528 #define _SIZET_
529 +#define __DEFINED_size_t /* musl */
530 #if (defined (__FreeBSD__) && (__FreeBSD__ >= 5)) \
531 || defined(__FreeBSD_kernel__)
532 /* __size_t is a typedef on FreeBSD 5, must not trash it. */
533 @@ -214,6 +216,7 @@
534 typedef long ssize_t;
535 #endif /* __BEOS__ */
536 #endif /* !(defined (__GNUG__) && defined (size_t)) */
537 +#endif /* __DEFINED_size_t */
538 #endif /* __size_t */
539 #endif /* _SIZET_ */
540 #endif /* _GCC_SIZE_T */
541 Index: b/libgcc/unwind-dw2-fde-dip.c
542 ===================================================================
543 --- a/libgcc/unwind-dw2-fde-dip.c
544 +++ b/libgcc/unwind-dw2-fde-dip.c
545 @@ -75,6 +75,13 @@
546 # define USE_PT_GNU_EH_FRAME
547 #endif
549 +/* For musl libc, TARGET_DL_ITERATE_PHDR gets defined by the configure
550 + script. */
551 +#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
552 + && defined(TARGET_DL_ITERATE_PHDR)
553 +# define USE_PT_GNU_EH_FRAME
554 +#endif
556 #if defined(USE_PT_GNU_EH_FRAME)
558 #include <link.h>
559 Index: b/libgomp/config/posix/time.c
560 ===================================================================
561 --- a/libgomp/config/posix/time.c
562 +++ b/libgomp/config/posix/time.c
563 @@ -28,6 +28,8 @@
564 The following implementation uses the most simple POSIX routines.
565 If present, POSIX 4 clocks should be used instead. */
567 +#define _POSIX_C_SOURCE 199309L /* for clocks */
569 #include "libgomp.h"
570 #include <unistd.h>
571 #if TIME_WITH_SYS_TIME
572 Index: b/libitm/config/arm/hwcap.cc
573 ===================================================================
574 --- a/libitm/config/arm/hwcap.cc
575 +++ b/libitm/config/arm/hwcap.cc
576 @@ -40,7 +40,11 @@
578 #ifdef __linux__
579 #include <unistd.h>
580 +#ifdef __GLIBC__
581 #include <sys/fcntl.h>
582 +#else
583 +#include <fcntl.h>
584 +#endif
585 #include <elf.h>
587 static void __attribute__((constructor))
588 Index: b/libitm/config/linux/x86/tls.h
589 ===================================================================
590 --- a/libitm/config/linux/x86/tls.h
591 +++ b/libitm/config/linux/x86/tls.h
592 @@ -25,16 +25,19 @@
593 #ifndef LIBITM_X86_TLS_H
594 #define LIBITM_X86_TLS_H 1
596 -#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
597 +#if defined(__GLIBC_PREREQ)
598 +#if __GLIBC_PREREQ(2, 10)
599 /* Use slots in the TCB head rather than __thread lookups.
600 GLIBC has reserved words 10 through 13 for TM. */
601 #define HAVE_ARCH_GTM_THREAD 1
602 #define HAVE_ARCH_GTM_THREAD_DISP 1
603 #endif
604 +#endif
606 #include "config/generic/tls.h"
608 -#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
609 +#if defined(__GLIBC_PREREQ)
610 +#if __GLIBC_PREREQ(2, 10)
611 namespace GTM HIDDEN {
613 #ifdef __x86_64__
614 @@ -101,5 +104,6 @@
616 } // namespace GTM
617 #endif /* >= GLIBC 2.10 */
618 +#endif
620 #endif // LIBITM_X86_TLS_H
621 Index: b/libstdc++-v3/configure.host
622 ===================================================================
623 --- a/libstdc++-v3/configure.host
624 +++ b/libstdc++-v3/configure.host
625 @@ -264,6 +264,13 @@
626 os_include_dir="os/bsd/freebsd"
628 gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu)
629 + # check for musl by target
630 + case "${host_os}" in
631 + *-musl*)
632 + os_include_dir="os/generic"
633 + ;;
634 + *)
636 if [ "$uclibc" = "yes" ]; then
637 os_include_dir="os/uclibc"
638 elif [ "$bionic" = "yes" ]; then
639 @@ -272,6 +279,9 @@
640 os_include_dir="os/gnu-linux"
644 + esac
645 + ;;
646 hpux*)
647 os_include_dir="os/hpux"