200-musl_config.patch 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. --- a/gcc/config.gcc
  2. +++ b/gcc/config.gcc
  3. @@ -595,7 +595,7 @@ case ${target} in
  4. esac
  5. # Common C libraries.
  6. -tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3"
  7. +tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3 LIBC_MUSL=4"
  8. # 32-bit x86 processors supported by --with-arch=. Each processor
  9. # MUST be separated by exactly one space.
  10. @@ -720,6 +720,9 @@ case ${target} in
  11. *-*-*uclibc*)
  12. tm_defines="$tm_defines DEFAULT_LIBC=LIBC_UCLIBC"
  13. ;;
  14. + *-*-*musl*)
  15. + tm_defines="$tm_defines DEFAULT_LIBC=LIBC_MUSL"
  16. + ;;
  17. *)
  18. tm_defines="$tm_defines DEFAULT_LIBC=LIBC_GLIBC"
  19. ;;
  20. --- a/gcc/config/linux.h
  21. +++ b/gcc/config/linux.h
  22. @@ -32,10 +32,12 @@ see the files COPYING3 and COPYING.RUNTI
  23. #define OPTION_GLIBC (DEFAULT_LIBC == LIBC_GLIBC)
  24. #define OPTION_UCLIBC (DEFAULT_LIBC == LIBC_UCLIBC)
  25. #define OPTION_BIONIC (DEFAULT_LIBC == LIBC_BIONIC)
  26. +#define OPTION_MUSL (DEFAULT_LIBC == LIBC_MUSL)
  27. #else
  28. #define OPTION_GLIBC (linux_libc == LIBC_GLIBC)
  29. #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
  30. #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
  31. +#define OPTION_MUSL (linux_libc == LIBC_MUSL)
  32. #endif
  33. #define GNU_USER_TARGET_OS_CPP_BUILTINS() \
  34. @@ -53,18 +55,21 @@ see the files COPYING3 and COPYING.RUNTI
  35. uClibc or Bionic is the default C library and whether
  36. -muclibc or -mglibc or -mbionic has been passed to change the default. */
  37. -#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LD1, LD2, LD3) \
  38. - "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:" LD1 "}}"
  39. +#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LIBC4, LD1, LD2, LD3, LD4) \
  40. + "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:%{" LIBC4 ":" LD4 ";:" LD1 "}}}"
  41. #if DEFAULT_LIBC == LIBC_GLIBC
  42. -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
  43. - CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", G, U, B)
  44. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  45. + CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", "mmusl", G, U, B, M)
  46. #elif DEFAULT_LIBC == LIBC_UCLIBC
  47. -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
  48. - CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", U, G, B)
  49. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  50. + CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", "mmusl", U, G, B, M)
  51. #elif DEFAULT_LIBC == LIBC_BIONIC
  52. -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
  53. - CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", B, G, U)
  54. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  55. + CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", "mmusl", B, G, U, M)
  56. +#elif DEFAULT_LIBC == LIBC_MUSL
  57. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  58. + CHOOSE_DYNAMIC_LINKER1 ("mmusl", "mglibc", "muclibc", "mbionic", M, G, U, B)
  59. #else
  60. #error "Unsupported DEFAULT_LIBC"
  61. #endif /* DEFAULT_LIBC */
  62. @@ -84,21 +89,92 @@ see the files COPYING3 and COPYING.RUNTI
  63. #define GNU_USER_DYNAMIC_LINKER \
  64. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, \
  65. - BIONIC_DYNAMIC_LINKER)
  66. + BIONIC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
  67. #define GNU_USER_DYNAMIC_LINKER32 \
  68. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, \
  69. - BIONIC_DYNAMIC_LINKER32)
  70. + BIONIC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
  71. #define GNU_USER_DYNAMIC_LINKER64 \
  72. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
  73. - BIONIC_DYNAMIC_LINKER64)
  74. + BIONIC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
  75. #define GNU_USER_DYNAMIC_LINKERX32 \
  76. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \
  77. - BIONIC_DYNAMIC_LINKERX32)
  78. + BIONIC_DYNAMIC_LINKERX32, MUSL_DYNAMIC_LINKERX32)
  79. /* Whether we have Bionic libc runtime */
  80. #undef TARGET_HAS_BIONIC
  81. #define TARGET_HAS_BIONIC (OPTION_BIONIC)
  82. +/* musl avoids problematic includes by rearranging the include directories.
  83. + * Unfortunately, this is mostly duplicated from cppdefault.c */
  84. +#if DEFAULT_LIBC == LIBC_MUSL
  85. +#define INCLUDE_DEFAULTS_MUSL_GPP \
  86. + { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, \
  87. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, \
  88. + { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1, \
  89. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 }, \
  90. + { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1, \
  91. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },
  92. +
  93. +#ifdef LOCAL_INCLUDE_DIR
  94. +#define INCLUDE_DEFAULTS_MUSL_LOCAL \
  95. + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 }, \
  96. + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 },
  97. +#else
  98. +#define INCLUDE_DEFAULTS_MUSL_LOCAL
  99. +#endif
  100. +
  101. +#ifdef PREFIX_INCLUDE_DIR
  102. +#define INCLUDE_DEFAULTS_MUSL_PREFIX \
  103. + { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0},
  104. +#else
  105. +#define INCLUDE_DEFAULTS_MUSL_PREFIX
  106. +#endif
  107. +
  108. +#ifdef CROSS_INCLUDE_DIR
  109. +#define INCLUDE_DEFAULTS_MUSL_CROSS \
  110. + { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0},
  111. +#else
  112. +#define INCLUDE_DEFAULTS_MUSL_CROSS
  113. +#endif
  114. +
  115. +#ifdef TOOL_INCLUDE_DIR
  116. +#define INCLUDE_DEFAULTS_MUSL_TOOL \
  117. + { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0},
  118. +#else
  119. +#define INCLUDE_DEFAULTS_MUSL_TOOL
  120. +#endif
  121. +
  122. +#ifdef NATIVE_SYSTEM_HEADER_DIR
  123. +#define INCLUDE_DEFAULTS_MUSL_NATIVE \
  124. + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 2 }, \
  125. + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 0 },
  126. +#else
  127. +#define INCLUDE_DEFAULTS_MUSL_NATIVE
  128. +#endif
  129. +
  130. +#if defined (CROSS_DIRECTORY_STRUCTURE) && !defined (TARGET_SYSTEM_ROOT)
  131. +# undef INCLUDE_DEFAULTS_MUSL_LOCAL
  132. +# define INCLUDE_DEFAULTS_MUSL_LOCAL
  133. +# undef INCLUDE_DEFAULTS_MUSL_NATIVE
  134. +# define INCLUDE_DEFAULTS_MUSL_NATIVE
  135. +#else
  136. +# undef INCLUDE_DEFAULTS_MUSL_CROSS
  137. +# define INCLUDE_DEFAULTS_MUSL_CROSS
  138. +#endif
  139. +
  140. +#undef INCLUDE_DEFAULTS
  141. +#define INCLUDE_DEFAULTS \
  142. + { \
  143. + INCLUDE_DEFAULTS_MUSL_GPP \
  144. + INCLUDE_DEFAULTS_MUSL_PREFIX \
  145. + INCLUDE_DEFAULTS_MUSL_CROSS \
  146. + INCLUDE_DEFAULTS_MUSL_TOOL \
  147. + INCLUDE_DEFAULTS_MUSL_NATIVE \
  148. + { GCC_INCLUDE_DIR, "GCC", 0, 1, 0, 0 }, \
  149. + { 0, 0, 0, 0, 0, 0 } \
  150. + }
  151. +#endif
  152. +
  153. #if (DEFAULT_LIBC == LIBC_UCLIBC) && defined (SINGLE_LIBC) /* uClinux */
  154. /* This is a *uclinux* target. We don't define below macros to normal linux
  155. versions, because doing so would require *uclinux* targets to include
  156. --- a/gcc/config/linux.opt
  157. +++ b/gcc/config/linux.opt
  158. @@ -30,3 +30,7 @@ Use GNU C library
  159. muclibc
  160. Target Report RejectNegative Var(linux_libc,LIBC_UCLIBC) Negative(mbionic)
  161. Use uClibc C library
  162. +
  163. +mmusl
  164. +Target Report RejectNegative Var(linux_libc,LIBC_MUSL) Negative(mglibc)
  165. +Use musl C library
  166. --- a/gcc/ginclude/stddef.h
  167. +++ b/gcc/ginclude/stddef.h
  168. @@ -181,6 +181,7 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t;
  169. #ifndef _GCC_SIZE_T
  170. #ifndef _SIZET_
  171. #ifndef __size_t
  172. +#ifndef __DEFINED_size_t /* musl */
  173. #define __size_t__ /* BeOS */
  174. #define __SIZE_T__ /* Cray Unicos/Mk */
  175. #define _SIZE_T
  176. @@ -197,6 +198,7 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t;
  177. #define ___int_size_t_h
  178. #define _GCC_SIZE_T
  179. #define _SIZET_
  180. +#define __DEFINED_size_t /* musl */
  181. #if (defined (__FreeBSD__) && (__FreeBSD__ >= 5)) \
  182. || defined(__FreeBSD_kernel__)
  183. /* __size_t is a typedef on FreeBSD 5, must not trash it. */
  184. @@ -214,6 +216,7 @@ typedef __SIZE_TYPE__ size_t;
  185. typedef long ssize_t;
  186. #endif /* __BEOS__ */
  187. #endif /* !(defined (__GNUG__) && defined (size_t)) */
  188. +#endif /* __DEFINED_size_t */
  189. #endif /* __size_t */
  190. #endif /* _SIZET_ */
  191. #endif /* _GCC_SIZE_T */