logo

live-bootstrap

Mirror of <https://github.com/fosslinux/live-bootstrap>

0005-musl-libc-config.patch (10608B)


  1. SPDX-FileCopyrightText: 2022 Dor Askayo <dor.askayo@gmail.com>
  2. SPDX-FileCopyrightText: 2015 Gregor Richards <gregor.richards@uwaterloo.ca>
  3. SPDX-FileCopyrightText: 2015 Szabolcs Nagy <szabolcs.nagy@arm.com>
  4. SPDX-License-Identifier: GPL-2.0-or-later
  5. Backported from upstream commit 755658a56b57beca14b5fb70afdf1e588a058f7f
  6. musl libc config
  7. 2015-05-08 Gregor Richards <gregor.richards@uwaterloo.ca>
  8. Szabolcs Nagy <szabolcs.nagy@arm.com>
  9. * config.gcc (LIBC_MUSL): New tm_defines macro.
  10. * config/linux.h (OPTION_MUSL): Define.
  11. (MUSL_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER32,)
  12. (MUSL_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKERX32,)
  13. (INCLUDE_DEFAULTS_MUSL_GPP, INCLUDE_DEFAULTS_MUSL_LOCAL,)
  14. (INCLUDE_DEFAULTS_MUSL_PREFIX, INCLUDE_DEFAULTS_MUSL_CROSS,)
  15. (INCLUDE_DEFAULTS_MUSL_TOOL, INCLUDE_DEFAULTS_MUSL_NATIVE): Define.
  16. * config/linux.opt (mmusl): New option.
  17. * doc/invoke.texi (GNU/Linux Options): Document -mmusl.
  18. * configure.ac (gcc_cv_libc_provides_ssp): Add *-*-musl*.
  19. (gcc_cv_target_dl_iterate_phdr): Add *-linux-musl*.
  20. * configure: Regenerate.
  21. Co-Authored-By: Szabolcs Nagy <szabolcs.nagy@arm.com>
  22. From-SVN: r222904
  23. --- gcc-4.7.4/gcc/config.gcc
  24. +++ gcc-4.7.4/gcc/config.gcc
  25. @@ -522,7 +522,7 @@ case ${target} in
  26. esac
  27. # Common C libraries.
  28. -tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3"
  29. +tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3 LIBC_MUSL=4"
  30. # Common parts for widely ported systems.
  31. case ${target} in
  32. @@ -625,6 +625,9 @@ case ${target} in
  33. *-*-*uclibc*)
  34. tm_defines="$tm_defines DEFAULT_LIBC=LIBC_UCLIBC"
  35. ;;
  36. + *-*-*musl*)
  37. + tm_defines="$tm_defines DEFAULT_LIBC=LIBC_MUSL"
  38. + ;;
  39. *)
  40. tm_defines="$tm_defines DEFAULT_LIBC=LIBC_GLIBC"
  41. ;;
  42. --- gcc-4.7.4/gcc/config/linux.h
  43. +++ gcc-4.7.4/gcc/config/linux.h
  44. @@ -33,10 +33,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  45. #define OPTION_GLIBC (DEFAULT_LIBC == LIBC_GLIBC)
  46. #define OPTION_UCLIBC (DEFAULT_LIBC == LIBC_UCLIBC)
  47. #define OPTION_BIONIC (DEFAULT_LIBC == LIBC_BIONIC)
  48. +#define OPTION_MUSL (DEFAULT_LIBC == LIBC_MUSL)
  49. #else
  50. #define OPTION_GLIBC (linux_libc == LIBC_GLIBC)
  51. #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
  52. #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
  53. +#define OPTION_MUSL (linux_libc == LIBC_MUSL)
  54. #endif
  55. #define GNU_USER_TARGET_OS_CPP_BUILTINS() \
  56. @@ -51,21 +53,25 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  57. } while (0)
  58. /* Determine which dynamic linker to use depending on whether GLIBC or
  59. - uClibc or Bionic is the default C library and whether
  60. - -muclibc or -mglibc or -mbionic has been passed to change the default. */
  61. + uClibc or Bionic or musl is the default C library and whether
  62. + -muclibc or -mglibc or -mbionic or -mmusl has been passed to change
  63. + the default. */
  64. -#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LD1, LD2, LD3) \
  65. - "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:" LD1 "}}"
  66. +#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LIBC4, LD1, LD2, LD3, LD4) \
  67. + "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:%{" LIBC4 ":" LD4 ";:" LD1 "}}}"
  68. #if DEFAULT_LIBC == LIBC_GLIBC
  69. -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
  70. - CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", G, U, B)
  71. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  72. + CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", "mmusl", G, U, B, M)
  73. #elif DEFAULT_LIBC == LIBC_UCLIBC
  74. -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
  75. - CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", U, G, B)
  76. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  77. + CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", "mmusl", U, G, B, M)
  78. #elif DEFAULT_LIBC == LIBC_BIONIC
  79. -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
  80. - CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", B, G, U)
  81. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  82. + CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", "mmusl", B, G, U, M)
  83. +#elif DEFAULT_LIBC == LIBC_MUSL
  84. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  85. + CHOOSE_DYNAMIC_LINKER1 ("mmusl", "mglibc", "muclibc", "mbionic", M, G, U, B)
  86. #else
  87. #error "Unsupported DEFAULT_LIBC"
  88. #endif /* DEFAULT_LIBC */
  89. @@ -82,19 +88,24 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  90. #define BIONIC_DYNAMIC_LINKER32 "/system/bin/linker"
  91. #define BIONIC_DYNAMIC_LINKER64 "/system/bin/linker64"
  92. #define BIONIC_DYNAMIC_LINKERX32 "/system/bin/linkerx32"
  93. +/* Should be redefined for each target that supports musl. */
  94. +#define MUSL_DYNAMIC_LINKER "/dev/null"
  95. +#define MUSL_DYNAMIC_LINKER32 "/dev/null"
  96. +#define MUSL_DYNAMIC_LINKER64 "/dev/null"
  97. +#define MUSL_DYNAMIC_LINKERX32 "/dev/null"
  98. #define GNU_USER_DYNAMIC_LINKER \
  99. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, \
  100. - BIONIC_DYNAMIC_LINKER)
  101. + BIONIC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
  102. #define GNU_USER_DYNAMIC_LINKER32 \
  103. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, \
  104. - BIONIC_DYNAMIC_LINKER32)
  105. + BIONIC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
  106. #define GNU_USER_DYNAMIC_LINKER64 \
  107. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
  108. - BIONIC_DYNAMIC_LINKER64)
  109. + BIONIC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
  110. #define GNU_USER_DYNAMIC_LINKERX32 \
  111. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \
  112. - BIONIC_DYNAMIC_LINKERX32)
  113. + BIONIC_DYNAMIC_LINKERX32, MUSL_DYNAMIC_LINKERX32)
  114. /* Determine whether the entire c99 runtime
  115. is present in the runtime library. */
  116. @@ -108,3 +119,74 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  117. /* Whether we have Bionic libc runtime */
  118. #undef TARGET_HAS_BIONIC
  119. #define TARGET_HAS_BIONIC (OPTION_BIONIC)
  120. +
  121. +/* musl avoids problematic includes by rearranging the include directories.
  122. + * Unfortunately, this is mostly duplicated from cppdefault.c */
  123. +#if DEFAULT_LIBC == LIBC_MUSL
  124. +#define INCLUDE_DEFAULTS_MUSL_GPP \
  125. + { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, \
  126. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, \
  127. + { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1, \
  128. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 }, \
  129. + { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1, \
  130. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },
  131. +
  132. +#ifdef LOCAL_INCLUDE_DIR
  133. +#define INCLUDE_DEFAULTS_MUSL_LOCAL \
  134. + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 }, \
  135. + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 },
  136. +#else
  137. +#define INCLUDE_DEFAULTS_MUSL_LOCAL
  138. +#endif
  139. +
  140. +#ifdef PREFIX_INCLUDE_DIR
  141. +#define INCLUDE_DEFAULTS_MUSL_PREFIX \
  142. + { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0},
  143. +#else
  144. +#define INCLUDE_DEFAULTS_MUSL_PREFIX
  145. +#endif
  146. +
  147. +#ifdef CROSS_INCLUDE_DIR
  148. +#define INCLUDE_DEFAULTS_MUSL_CROSS \
  149. + { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0},
  150. +#else
  151. +#define INCLUDE_DEFAULTS_MUSL_CROSS
  152. +#endif
  153. +
  154. +#ifdef TOOL_INCLUDE_DIR
  155. +#define INCLUDE_DEFAULTS_MUSL_TOOL \
  156. + { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0},
  157. +#else
  158. +#define INCLUDE_DEFAULTS_MUSL_TOOL
  159. +#endif
  160. +
  161. +#ifdef NATIVE_SYSTEM_HEADER_DIR
  162. +#define INCLUDE_DEFAULTS_MUSL_NATIVE \
  163. + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 2 }, \
  164. + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 0 },
  165. +#else
  166. +#define INCLUDE_DEFAULTS_MUSL_NATIVE
  167. +#endif
  168. +
  169. +#if defined (CROSS_DIRECTORY_STRUCTURE) && !defined (TARGET_SYSTEM_ROOT)
  170. +# undef INCLUDE_DEFAULTS_MUSL_LOCAL
  171. +# define INCLUDE_DEFAULTS_MUSL_LOCAL
  172. +# undef INCLUDE_DEFAULTS_MUSL_NATIVE
  173. +# define INCLUDE_DEFAULTS_MUSL_NATIVE
  174. +#else
  175. +# undef INCLUDE_DEFAULTS_MUSL_CROSS
  176. +# define INCLUDE_DEFAULTS_MUSL_CROSS
  177. +#endif
  178. +
  179. +#undef INCLUDE_DEFAULTS
  180. +#define INCLUDE_DEFAULTS \
  181. + { \
  182. + INCLUDE_DEFAULTS_MUSL_GPP \
  183. + INCLUDE_DEFAULTS_MUSL_PREFIX \
  184. + INCLUDE_DEFAULTS_MUSL_CROSS \
  185. + INCLUDE_DEFAULTS_MUSL_TOOL \
  186. + INCLUDE_DEFAULTS_MUSL_NATIVE \
  187. + { GCC_INCLUDE_DIR, "GCC", 0, 1, 0, 0 }, \
  188. + { 0, 0, 0, 0, 0, 0 } \
  189. + }
  190. +#endif
  191. --- gcc-4.7.4/gcc/config/linux.opt
  192. +++ gcc-4.7.4/gcc/config/linux.opt
  193. @@ -28,5 +28,9 @@ Target Report RejectNegative Var(linux_libc,LIBC_GLIBC) Negative(muclibc)
  194. Use GNU C library
  195. muclibc
  196. -Target Report RejectNegative Var(linux_libc,LIBC_UCLIBC) Negative(mbionic)
  197. +Target Report RejectNegative Var(linux_libc,LIBC_UCLIBC) Negative(mmusl)
  198. Use uClibc C library
  199. +
  200. +mmusl
  201. +Target Report RejectNegative Var(linux_libc,LIBC_MUSL) Negative(mbionic)
  202. +Use musl C library
  203. --- gcc-4.7.4/gcc/configure.ac
  204. +++ gcc-4.7.4/gcc/configure.ac
  205. @@ -4669,6 +4669,9 @@ AC_CACHE_CHECK(__stack_chk_fail in target C library,
  206. gcc_cv_libc_provides_ssp,
  207. [gcc_cv_libc_provides_ssp=no
  208. case "$target" in
  209. + *-*-musl*)
  210. + # All versions of musl provide stack protector
  211. + gcc_cv_libc_provides_ssp=yes;;
  212. *-*-linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu)
  213. [# glibc 2.4 and later provides __stack_chk_fail and
  214. # either __stack_chk_guard, or TLS access to stack guard canary.
  215. @@ -4702,6 +4705,7 @@ AC_CACHE_CHECK(__stack_chk_fail in target C library,
  216. # <http://gcc.gnu.org/ml/gcc/2008-10/msg00130.html>) and for now
  217. # simply assert that glibc does provide this, which is true for all
  218. # realistically usable GNU/Hurd configurations.
  219. + # All supported versions of musl provide it as well
  220. gcc_cv_libc_provides_ssp=yes;;
  221. *-*-darwin* | *-*-freebsd*)
  222. AC_CHECK_FUNC(__stack_chk_fail,[gcc_cv_libc_provides_ssp=yes],
  223. @@ -4767,6 +4771,9 @@ case "$target" in
  224. gcc_cv_target_dl_iterate_phdr=no
  225. fi
  226. ;;
  227. + *-linux-musl*)
  228. + gcc_cv_target_dl_iterate_phdr=yes
  229. + ;;
  230. esac
  231. GCC_TARGET_TEMPLATE([TARGET_DL_ITERATE_PHDR])
  232. if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
  233. --- gcc-4.7.4/gcc/doc/invoke.texi
  234. +++ gcc-4.7.4/gcc/doc/invoke.texi
  235. @@ -595,7 +595,7 @@ Objective-C and Objective-C++ Dialects}.
  236. -mcpu=@var{cpu}}
  237. @emph{GNU/Linux Options}
  238. -@gccoptlist{-mglibc -muclibc -mbionic -mandroid @gol
  239. +@gccoptlist{-mglibc -muclibc -mmusl -mbionic -mandroid @gol
  240. -tno-android-cc -tno-android-ld}
  241. @emph{H8/300 Options}
  242. @@ -12879,13 +12879,19 @@ These @samp{-m} options are defined for GNU/Linux targets:
  243. @item -mglibc
  244. @opindex mglibc
  245. Use the GNU C library. This is the default except
  246. -on @samp{*-*-linux-*uclibc*} and @samp{*-*-linux-*android*} targets.
  247. +on @samp{*-*-linux-*uclibc*}, @samp{*-*-linux-*musl*} and
  248. +@samp{*-*-linux-*android*} targets.
  249. @item -muclibc
  250. @opindex muclibc
  251. Use uClibc C library. This is the default on
  252. @samp{*-*-linux-*uclibc*} targets.
  253. +@item -mmusl
  254. +@opindex mmusl
  255. +Use the musl C library. This is the default on
  256. +@samp{*-*-linux-*musl*} targets.
  257. +
  258. @item -mbionic
  259. @opindex mbionic
  260. Use Bionic C library. This is the default on