The cirros image was rebuilt against the 3.13.0-83 kernel, drivers e1000e, igbvf...
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / buildroot-2015.05 / package / gcc / 4.7.4 / 900-musl-support.patch
1 Add musl support to gcc
2
3 This patch comes from the musl-cross project at
4 https://bitbucket.org/GregorR/musl-cross/src. Compared to the upstream version:
5
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.
9
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.
15
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.
21
22 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
23 ---
24
25 # HG changeset patch
26 # Parent f50bb54f331f73405131a30b4f353cfda1c70304
27 Use the generic implementation of libstdc++ primitives when we're on musl, not the glibc one.
28
29 Index: b/libstdc++-v3/configure.host
30 ===================================================================
31 --- a/libstdc++-v3/configure.host
32 +++ b/libstdc++-v3/configure.host
33 @@ -243,6 +243,13 @@
34      os_include_dir="os/bsd/freebsd"
35      ;;
36    gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu)
37 +    # check for musl by target
38 +    case "${host_os}" in
39 +      *-musl*)
40 +        os_include_dir="os/generic"
41 +        ;;
42 +      *)
43 +
44      if [ "$uclibc" = "yes" ]; then
45        os_include_dir="os/uclibc"
46      elif [ "$bionic" = "yes" ]; then
47 @@ -251,6 +258,9 @@
48        os_include_dir="os/gnu-linux"
49      fi
50      ;;
51 +
52 +    esac
53 +    ;;
54    hpux*)
55      os_include_dir="os/hpux"
56      ;;
57 Index: b/gcc/config.gcc
58 ===================================================================
59 --- a/gcc/config.gcc
60 +++ b/gcc/config.gcc
61 @@ -522,7 +522,7 @@
62  esac
63  
64  # Common C libraries.
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"
67  
68  # Common parts for widely ported systems.
69  case ${target} in
70 @@ -625,6 +625,9 @@
71      *-*-*uclibc*)
72        tm_defines="$tm_defines DEFAULT_LIBC=LIBC_UCLIBC"
73        ;;
74 +    *-*-*musl*)
75 +      tm_defines="$tm_defines DEFAULT_LIBC=LIBC_MUSL"
76 +      ;;
77      *)
78        tm_defines="$tm_defines DEFAULT_LIBC=LIBC_GLIBC"
79        ;;
80 @@ -2091,6 +2094,10 @@
81             powerpc*-*-linux*paired*)
82                 tm_file="${tm_file} rs6000/750cl.h" ;;
83         esac
84 +        case ${target} in
85 +            *-linux*-musl*)
86 +                enable_secureplt=yes ;;
87 +        esac
88         if test x${enable_secureplt} = xyes; then
89                 tm_file="rs6000/secureplt.h ${tm_file}"
90         fi
91 Index: b/gcc/config/linux.h
92 ===================================================================
93 --- a/gcc/config/linux.h
94 +++ b/gcc/config/linux.h
95 @@ -33,10 +33,12 @@
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)
100  #else
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)
105  #endif
106  
107  #define GNU_USER_TARGET_OS_CPP_BUILTINS()                      \
108 @@ -54,18 +56,21 @@
109     uClibc or Bionic is the default C library and whether
110     -muclibc or -mglibc or -mbionic has been passed to change the default.  */
111  
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 "}}}"
116  
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)
135  #else
136  #error "Unsupported DEFAULT_LIBC"
137  #endif /* DEFAULT_LIBC */
138 @@ -83,23 +88,32 @@
139  #define BIONIC_DYNAMIC_LINKER64 "/system/bin/linker64"
140  #define BIONIC_DYNAMIC_LINKERX32 "/system/bin/linkerx32"
141  
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"
150 +
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)
167  
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)
173  
174  /* Whether we have sincos that follows the GNU extension.  */
175  #undef TARGET_HAS_SINCOS
176 @@ -108,3 +122,74 @@
177  /* Whether we have Bionic libc runtime */
178  #undef TARGET_HAS_BIONIC
179  #define TARGET_HAS_BIONIC (OPTION_BIONIC)
180 +
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 },
191 +
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 },
196 +#else
197 +#define INCLUDE_DEFAULTS_MUSL_LOCAL
198 +#endif
199 +
200 +#ifdef PREFIX_INCLUDE_DIR
201 +#define INCLUDE_DEFAULTS_MUSL_PREFIX                   \
202 +    { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0},
203 +#else
204 +#define INCLUDE_DEFAULTS_MUSL_PREFIX
205 +#endif
206 +
207 +#ifdef CROSS_INCLUDE_DIR
208 +#define INCLUDE_DEFAULTS_MUSL_CROSS                    \
209 +    { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0},
210 +#else
211 +#define INCLUDE_DEFAULTS_MUSL_CROSS
212 +#endif
213 +
214 +#ifdef TOOL_INCLUDE_DIR
215 +#define INCLUDE_DEFAULTS_MUSL_TOOL                     \
216 +    { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0},
217 +#else
218 +#define INCLUDE_DEFAULTS_MUSL_TOOL
219 +#endif
220 +
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 },
225 +#else
226 +#define INCLUDE_DEFAULTS_MUSL_NATIVE
227 +#endif
228 +
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
234 +#else
235 +# undef INCLUDE_DEFAULTS_MUSL_CROSS
236 +# define INCLUDE_DEFAULTS_MUSL_CROSS
237 +#endif
238 +
239 +#undef INCLUDE_DEFAULTS
240 +#define INCLUDE_DEFAULTS                               \
241 +  {                                                    \
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 }                               \
249 +  }
250 +#endif
251 Index: b/gcc/config/linux.opt
252 ===================================================================
253 --- a/gcc/config/linux.opt
254 +++ b/gcc/config/linux.opt
255 @@ -30,3 +30,7 @@
256  muclibc
257  Target Report RejectNegative Var(linux_libc,LIBC_UCLIBC) Negative(mbionic)
258  Use uClibc C library
259 +
260 +mmusl
261 +Target Report RejectNegative Var(linux_libc,LIBC_MUSL) Negative(mglibc)
262 +Use musl C library
263 Index: b/gcc/ginclude/stddef.h
264 ===================================================================
265 --- a/gcc/ginclude/stddef.h
266 +++ b/gcc/ginclude/stddef.h
267 @@ -184,6 +184,7 @@
268  #ifndef _GCC_SIZE_T
269  #ifndef _SIZET_
270  #ifndef __size_t
271 +#ifndef __DEFINED_size_t /* musl */
272  #define __size_t__     /* BeOS */
273  #define __SIZE_T__     /* Cray Unicos/Mk */
274  #define _SIZE_T
275 @@ -200,6 +201,7 @@
276  #define ___int_size_t_h
277  #define _GCC_SIZE_T
278  #define _SIZET_
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. */
283 @@ -215,6 +217,7 @@
284  typedef long ssize_t;
285  #endif /* __BEOS__ */
286  #endif /* !(defined (__GNUG__) && defined (size_t)) */
287 +#endif /* __DEFINED_size_t */
288  #endif /* __size_t */
289  #endif /* _SIZET_ */
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
295 @@ -28,6 +28,8 @@
296     The following implementation uses the most simple POSIX routines.
297     If present, POSIX 4 clocks should be used instead.  */
298  
299 +#define _POSIX_C_SOURCE 199309L /* for clocks */
300 +
301  #include "libgomp.h"
302  #include <unistd.h>
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
308 @@ -71,6 +71,13 @@
309  # define USE_PT_GNU_EH_FRAME
310  #endif
311  
312 +/* For musl libc, TARGET_DL_ITERATE_PHDR gets defined by the configure
313 +   script. */
314 +#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
315 +    && defined(TARGET_DL_ITERATE_PHDR)
316 +# define USE_PT_GNU_EH_FRAME
317 +#endif
318 +
319  #if defined(USE_PT_GNU_EH_FRAME)
320  
321  #include <link.h>
322 Index: b/gcc/configure
323 ===================================================================
324 --- a/gcc/configure
325 +++ b/gcc/configure
326 @@ -26791,6 +26791,9 @@
327  else
328    gcc_cv_libc_provides_ssp=no
329      case "$target" in
330 +       *-*-musl*)
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
346      fi
347      ;;
348 +  *-linux-musl*)
349 +    gcc_cv_target_dl_iterate_phdr=yes
350 +    ;;
351  esac
352  
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
361      case "$target" in
362 +       *-*-musl*)
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
378      fi
379      ;;
380 +  *-linux-musl*)
381 +    gcc_cv_target_dl_iterate_phdr=yes
382 +    ;;
383  esac
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
390 @@ -20,7 +20,8 @@
391      powerpc-*-eabi*    | \
392      powerpc-*-rtems*   | \
393      powerpcle-*-eabisim* | \
394 -    powerpcle-*-eabi* )
395 +    powerpcle-*-eabi* | \
396 +    *-musl* )
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
404 @@ -22,3 +22,5 @@
405  
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
414 @@ -31,3 +31,10 @@
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"
418 +
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
429 @@ -25,16 +25,19 @@
430  #ifndef LIBITM_X86_TLS_H
431  #define LIBITM_X86_TLS_H 1
432  
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
440  #endif
441 +#endif
442  
443  #include "config/generic/tls.h"
444  
445 -#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
446 +#if defined(__GLIBC_PREREQ)
447 +#if __GLIBC_PREREQ(2, 10)
448  namespace GTM HIDDEN {
449  
450  #ifdef __x86_64__
451 @@ -101,5 +104,6 @@
452  
453  } // namespace GTM
454  #endif /* >= GLIBC 2.10 */
455 +#endif
456  
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
462 @@ -64,6 +64,23 @@
463  #undef  GLIBC_DYNAMIC_LINKER
464  #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.3"
465  
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}"
477 +#else
478 +#define MUSL_DYNAMIC_LINKER_E "%{mbig-endian:eb}"
479 +#endif
480 +#define MUSL_DYNAMIC_LINKER \
481 +  "/lib/ld-musl-arm" MUSL_DYNAMIC_LINKER_E "%{mfloat-abi=hard:hf}.so.1"
482 +
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.  */
485  #undef  LINK_SPEC
486 Index: b/libitm/config/arm/hwcap.cc
487 ===================================================================
488 --- a/libitm/config/arm/hwcap.cc
489 +++ b/libitm/config/arm/hwcap.cc
490 @@ -40,7 +40,11 @@
491  
492  #ifdef __linux__
493  #include <unistd.h>
494 +#ifdef __GLIBC__
495  #include <sys/fcntl.h>
496 +#else
497 +#include <fcntl.h>
498 +#endif
499  #include <elf.h>
500  
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
506 @@ -19,3 +19,11 @@
507  <http://www.gnu.org/licenses/>.  */
508  
509  #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
510 +
511 +#if TARGET_ENDIAN_DEFAULT == 0 /* LE */
512 +#define MUSL_DYNAMIC_LINKER_E "%{EB:;:el}"
513 +#else
514 +#define MUSL_DYNAMIC_LINKER_E "%{EL:el}"
515 +#endif
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 "}}"
538  #else
539  #error "Unsupported DEFAULT_LIBC"
540  #endif
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)
547  
548  
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
554 @@ -18,3 +18,4 @@
555  <http://www.gnu.org/licenses/>.  */
556  
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
563 @@ -566,6 +566,9 @@
564  #ifndef CC1_SECURE_PLT_DEFAULT_SPEC
565  #define CC1_SECURE_PLT_DEFAULT_SPEC ""
566  #endif
567 +#ifndef LINK_SECURE_PLT_DEFAULT_SPEC
568 +#define LINK_SECURE_PLT_DEFAULT_SPEC ""
569 +#endif
570  
571  /* Pass -G xxx to the compiler and set correct endian mode.  */
572  #define        CC1_SPEC "%{G*} %(cc1_cpu) \
573 @@ -626,7 +629,8 @@
574  %{mlittle: --oformat elf32-powerpcle } %{mlittle-endian: --oformat elf32-powerpcle } \
575  %{!mlittle: %{!mlittle-endian: %{!mbig: %{!mbig-endian: \
576      %{mcall-i960-old: --oformat elf32-powerpcle} \
577 -  }}}}"
578 +  }}}} \
579 +%{!mbss-plt: %{!msecure-plt: %(link_secure_plt_default)}}"
580  
581  /* Any specific OS flags.  */
582  #define LINK_OS_SPEC "\
583 @@ -804,15 +808,19 @@
584  
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 "}}"
597  #else
598  #error "Unsupported DEFAULT_LIBC"
599  #endif
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)
603  
604  #define LINK_OS_LINUX_SPEC "-m elf32ppclinux %{!shared: %{!static: \
605    %{rdynamic:-export-dynamic} \
606 @@ -938,6 +946,7 @@
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
618 @@ -30,4 +30,4 @@
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)