200-musl_config.patch 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. --- a/gcc/config.gcc
  2. +++ b/gcc/config.gcc
  3. @@ -559,7 +559,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. # Common parts for widely ported systems.
  9. case ${target} in
  10. @@ -662,6 +662,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,21 @@ 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. /* Determine whether the entire c99 runtime
  80. is present in the runtime library. */
  81. #undef TARGET_C99_FUNCTIONS
  82. -#define TARGET_C99_FUNCTIONS (OPTION_GLIBC)
  83. +#define TARGET_C99_FUNCTIONS (OPTION_GLIBC || OPTION_MUSL)
  84. /* Whether we have sincos that follows the GNU extension. */
  85. #undef TARGET_HAS_SINCOS
  86. @@ -107,3 +112,74 @@ see the files COPYING3 and COPYING.RUNTI
  87. /* Whether we have Bionic libc runtime */
  88. #undef TARGET_HAS_BIONIC
  89. #define TARGET_HAS_BIONIC (OPTION_BIONIC)
  90. +
  91. +/* musl avoids problematic includes by rearranging the include directories.
  92. + * Unfortunately, this is mostly duplicated from cppdefault.c */
  93. +#if DEFAULT_LIBC == LIBC_MUSL
  94. +#define INCLUDE_DEFAULTS_MUSL_GPP \
  95. + { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, \
  96. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, \
  97. + { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1, \
  98. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 }, \
  99. + { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1, \
  100. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },
  101. +
  102. +#ifdef LOCAL_INCLUDE_DIR
  103. +#define INCLUDE_DEFAULTS_MUSL_LOCAL \
  104. + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 }, \
  105. + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 },
  106. +#else
  107. +#define INCLUDE_DEFAULTS_MUSL_LOCAL
  108. +#endif
  109. +
  110. +#ifdef PREFIX_INCLUDE_DIR
  111. +#define INCLUDE_DEFAULTS_MUSL_PREFIX \
  112. + { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0},
  113. +#else
  114. +#define INCLUDE_DEFAULTS_MUSL_PREFIX
  115. +#endif
  116. +
  117. +#ifdef CROSS_INCLUDE_DIR
  118. +#define INCLUDE_DEFAULTS_MUSL_CROSS \
  119. + { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0},
  120. +#else
  121. +#define INCLUDE_DEFAULTS_MUSL_CROSS
  122. +#endif
  123. +
  124. +#ifdef TOOL_INCLUDE_DIR
  125. +#define INCLUDE_DEFAULTS_MUSL_TOOL \
  126. + { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0},
  127. +#else
  128. +#define INCLUDE_DEFAULTS_MUSL_TOOL
  129. +#endif
  130. +
  131. +#ifdef NATIVE_SYSTEM_HEADER_DIR
  132. +#define INCLUDE_DEFAULTS_MUSL_NATIVE \
  133. + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 2 }, \
  134. + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 0 },
  135. +#else
  136. +#define INCLUDE_DEFAULTS_MUSL_NATIVE
  137. +#endif
  138. +
  139. +#if defined (CROSS_DIRECTORY_STRUCTURE) && !defined (TARGET_SYSTEM_ROOT)
  140. +# undef INCLUDE_DEFAULTS_MUSL_LOCAL
  141. +# define INCLUDE_DEFAULTS_MUSL_LOCAL
  142. +# undef INCLUDE_DEFAULTS_MUSL_NATIVE
  143. +# define INCLUDE_DEFAULTS_MUSL_NATIVE
  144. +#else
  145. +# undef INCLUDE_DEFAULTS_MUSL_CROSS
  146. +# define INCLUDE_DEFAULTS_MUSL_CROSS
  147. +#endif
  148. +
  149. +#undef INCLUDE_DEFAULTS
  150. +#define INCLUDE_DEFAULTS \
  151. + { \
  152. + INCLUDE_DEFAULTS_MUSL_GPP \
  153. + INCLUDE_DEFAULTS_MUSL_PREFIX \
  154. + INCLUDE_DEFAULTS_MUSL_CROSS \
  155. + INCLUDE_DEFAULTS_MUSL_TOOL \
  156. + INCLUDE_DEFAULTS_MUSL_NATIVE \
  157. + { GCC_INCLUDE_DIR, "GCC", 0, 1, 0, 0 }, \
  158. + { 0, 0, 0, 0, 0, 0 } \
  159. + }
  160. +#endif
  161. --- a/gcc/config/linux.opt
  162. +++ b/gcc/config/linux.opt
  163. @@ -30,3 +30,7 @@ Use GNU C library
  164. muclibc
  165. Target Report RejectNegative Var(linux_libc,LIBC_UCLIBC) Negative(mbionic)
  166. Use uClibc C library
  167. +
  168. +mmusl
  169. +Target Report RejectNegative Var(linux_libc,LIBC_MUSL) Negative(mglibc)
  170. +Use musl C library
  171. --- a/gcc/ginclude/stddef.h
  172. +++ b/gcc/ginclude/stddef.h
  173. @@ -181,6 +181,7 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t;
  174. #ifndef _GCC_SIZE_T
  175. #ifndef _SIZET_
  176. #ifndef __size_t
  177. +#ifndef __DEFINED_size_t /* musl */
  178. #define __size_t__ /* BeOS */
  179. #define __SIZE_T__ /* Cray Unicos/Mk */
  180. #define _SIZE_T
  181. @@ -197,6 +198,7 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t;
  182. #define ___int_size_t_h
  183. #define _GCC_SIZE_T
  184. #define _SIZET_
  185. +#define __DEFINED_size_t /* musl */
  186. #if (defined (__FreeBSD__) && (__FreeBSD__ >= 5)) \
  187. || defined(__FreeBSD_kernel__)
  188. /* __size_t is a typedef on FreeBSD 5, must not trash it. */
  189. @@ -214,6 +216,7 @@ typedef __SIZE_TYPE__ size_t;
  190. typedef long ssize_t;
  191. #endif /* __BEOS__ */
  192. #endif /* !(defined (__GNUG__) && defined (size_t)) */
  193. +#endif /* __DEFINED_size_t */
  194. #endif /* __size_t */
  195. #endif /* _SIZET_ */
  196. #endif /* _GCC_SIZE_T */