1
0

200-musl_config.patch 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. From: ktkachov <ktkachov@138bc75d-0d04-0410-961f-82ee72b054a4>
  2. Date: Fri, 8 May 2015 08:25:47 +0000 (+0000)
  3. Subject: [PATCH 2/13] musl libc config
  4. X-Git-Url: https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff_plain;h=a9173ceabaf29c16f8ef226fbf98af373a4b2ceb
  5. [PATCH 2/13] musl libc config
  6. 2015-05-08 Gregor Richards <gregor.richards@uwaterloo.ca>
  7. Szabolcs Nagy <szabolcs.nagy@arm.com>
  8. * config.gcc (LIBC_MUSL): New tm_defines macro.
  9. * config/linux.h (OPTION_MUSL): Define.
  10. (MUSL_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER32,)
  11. (MUSL_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKERX32,)
  12. (INCLUDE_DEFAULTS_MUSL_GPP, INCLUDE_DEFAULTS_MUSL_LOCAL,)
  13. (INCLUDE_DEFAULTS_MUSL_PREFIX, INCLUDE_DEFAULTS_MUSL_CROSS,)
  14. (INCLUDE_DEFAULTS_MUSL_TOOL, INCLUDE_DEFAULTS_MUSL_NATIVE): Define.
  15. * config/linux.opt (mmusl): New option.
  16. * doc/invoke.texi (GNU/Linux Options): Document -mmusl.
  17. * configure.ac (gcc_cv_libc_provides_ssp): Add *-*-musl*.
  18. (gcc_cv_target_dl_iterate_phdr): Add *-linux-musl*.
  19. * configure: Regenerate.
  20. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@222904 138bc75d-0d04-0410-961f-82ee72b054a4
  21. ---
  22. --- a/gcc/config.gcc
  23. +++ b/gcc/config.gcc
  24. @@ -575,7 +575,7 @@ case ${target} in
  25. esac
  26. # Common C libraries.
  27. -tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3"
  28. +tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3 LIBC_MUSL=4"
  29. # 32-bit x86 processors supported by --with-arch=. Each processor
  30. # MUST be separated by exactly one space.
  31. @@ -720,6 +720,9 @@ case ${target} in
  32. *-*-*uclibc*)
  33. tm_defines="$tm_defines DEFAULT_LIBC=LIBC_UCLIBC"
  34. ;;
  35. + *-*-*musl*)
  36. + tm_defines="$tm_defines DEFAULT_LIBC=LIBC_MUSL"
  37. + ;;
  38. *)
  39. tm_defines="$tm_defines DEFAULT_LIBC=LIBC_GLIBC"
  40. ;;
  41. --- a/gcc/config/linux.h
  42. +++ b/gcc/config/linux.h
  43. @@ -32,10 +32,12 @@ see the files COPYING3 and COPYING.RUNTI
  44. #define OPTION_GLIBC (DEFAULT_LIBC == LIBC_GLIBC)
  45. #define OPTION_UCLIBC (DEFAULT_LIBC == LIBC_UCLIBC)
  46. #define OPTION_BIONIC (DEFAULT_LIBC == LIBC_BIONIC)
  47. +#define OPTION_MUSL (DEFAULT_LIBC == LIBC_MUSL)
  48. #else
  49. #define OPTION_GLIBC (linux_libc == LIBC_GLIBC)
  50. #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
  51. #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
  52. +#define OPTION_MUSL (linux_libc == LIBC_MUSL)
  53. #endif
  54. #define GNU_USER_TARGET_OS_CPP_BUILTINS() \
  55. @@ -50,21 +52,25 @@ see the files COPYING3 and COPYING.RUNTI
  56. } while (0)
  57. /* Determine which dynamic linker to use depending on whether GLIBC or
  58. - uClibc or Bionic is the default C library and whether
  59. - -muclibc or -mglibc or -mbionic has been passed to change the default. */
  60. + uClibc or Bionic or musl is the default C library and whether
  61. + -muclibc or -mglibc or -mbionic or -mmusl has been passed to change
  62. + the default. */
  63. -#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LD1, LD2, LD3) \
  64. - "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:" LD1 "}}"
  65. +#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LIBC4, LD1, LD2, LD3, LD4) \
  66. + "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:%{" LIBC4 ":" LD4 ";:" LD1 "}}}"
  67. #if DEFAULT_LIBC == LIBC_GLIBC
  68. -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
  69. - CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", G, U, B)
  70. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  71. + CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", "mmusl", G, U, B, M)
  72. #elif DEFAULT_LIBC == LIBC_UCLIBC
  73. -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
  74. - CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", U, G, B)
  75. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  76. + CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", "mmusl", U, G, B, M)
  77. #elif DEFAULT_LIBC == LIBC_BIONIC
  78. -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
  79. - CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", B, G, U)
  80. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  81. + CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", "mmusl", B, G, U, M)
  82. +#elif DEFAULT_LIBC == LIBC_MUSL
  83. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  84. + CHOOSE_DYNAMIC_LINKER1 ("mmusl", "mglibc", "muclibc", "mbionic", M, G, U, B)
  85. #else
  86. #error "Unsupported DEFAULT_LIBC"
  87. #endif /* DEFAULT_LIBC */
  88. @@ -81,24 +87,100 @@ see the files COPYING3 and COPYING.RUNTI
  89. #define BIONIC_DYNAMIC_LINKER32 "/system/bin/linker"
  90. #define BIONIC_DYNAMIC_LINKER64 "/system/bin/linker64"
  91. #define BIONIC_DYNAMIC_LINKERX32 "/system/bin/linkerx32"
  92. +/* Should be redefined for each target that supports musl. */
  93. +#define MUSL_DYNAMIC_LINKER "/dev/null"
  94. +#define MUSL_DYNAMIC_LINKER32 "/dev/null"
  95. +#define MUSL_DYNAMIC_LINKER64 "/dev/null"
  96. +#define MUSL_DYNAMIC_LINKERX32 "/dev/null"
  97. #define GNU_USER_DYNAMIC_LINKER \
  98. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, \
  99. - BIONIC_DYNAMIC_LINKER)
  100. + BIONIC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
  101. #define GNU_USER_DYNAMIC_LINKER32 \
  102. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, \
  103. - BIONIC_DYNAMIC_LINKER32)
  104. + BIONIC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
  105. #define GNU_USER_DYNAMIC_LINKER64 \
  106. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
  107. - BIONIC_DYNAMIC_LINKER64)
  108. + BIONIC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
  109. #define GNU_USER_DYNAMIC_LINKERX32 \
  110. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \
  111. - BIONIC_DYNAMIC_LINKERX32)
  112. + BIONIC_DYNAMIC_LINKERX32, MUSL_DYNAMIC_LINKERX32)
  113. /* Whether we have Bionic libc runtime */
  114. #undef TARGET_HAS_BIONIC
  115. #define TARGET_HAS_BIONIC (OPTION_BIONIC)
  116. +/* musl avoids problematic includes by rearranging the include directories.
  117. + * Unfortunately, this is mostly duplicated from cppdefault.c */
  118. +#if DEFAULT_LIBC == LIBC_MUSL
  119. +#define INCLUDE_DEFAULTS_MUSL_GPP \
  120. + { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, \
  121. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, \
  122. + { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1, \
  123. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 }, \
  124. + { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1, \
  125. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },
  126. +
  127. +#ifdef LOCAL_INCLUDE_DIR
  128. +#define INCLUDE_DEFAULTS_MUSL_LOCAL \
  129. + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 }, \
  130. + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 },
  131. +#else
  132. +#define INCLUDE_DEFAULTS_MUSL_LOCAL
  133. +#endif
  134. +
  135. +#ifdef PREFIX_INCLUDE_DIR
  136. +#define INCLUDE_DEFAULTS_MUSL_PREFIX \
  137. + { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0},
  138. +#else
  139. +#define INCLUDE_DEFAULTS_MUSL_PREFIX
  140. +#endif
  141. +
  142. +#ifdef CROSS_INCLUDE_DIR
  143. +#define INCLUDE_DEFAULTS_MUSL_CROSS \
  144. + { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0},
  145. +#else
  146. +#define INCLUDE_DEFAULTS_MUSL_CROSS
  147. +#endif
  148. +
  149. +#ifdef TOOL_INCLUDE_DIR
  150. +#define INCLUDE_DEFAULTS_MUSL_TOOL \
  151. + { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0},
  152. +#else
  153. +#define INCLUDE_DEFAULTS_MUSL_TOOL
  154. +#endif
  155. +
  156. +#ifdef NATIVE_SYSTEM_HEADER_DIR
  157. +#define INCLUDE_DEFAULTS_MUSL_NATIVE \
  158. + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 2 }, \
  159. + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 0 },
  160. +#else
  161. +#define INCLUDE_DEFAULTS_MUSL_NATIVE
  162. +#endif
  163. +
  164. +#if defined (CROSS_DIRECTORY_STRUCTURE) && !defined (TARGET_SYSTEM_ROOT)
  165. +# undef INCLUDE_DEFAULTS_MUSL_LOCAL
  166. +# define INCLUDE_DEFAULTS_MUSL_LOCAL
  167. +# undef INCLUDE_DEFAULTS_MUSL_NATIVE
  168. +# define INCLUDE_DEFAULTS_MUSL_NATIVE
  169. +#else
  170. +# undef INCLUDE_DEFAULTS_MUSL_CROSS
  171. +# define INCLUDE_DEFAULTS_MUSL_CROSS
  172. +#endif
  173. +
  174. +#undef INCLUDE_DEFAULTS
  175. +#define INCLUDE_DEFAULTS \
  176. + { \
  177. + INCLUDE_DEFAULTS_MUSL_GPP \
  178. + INCLUDE_DEFAULTS_MUSL_PREFIX \
  179. + INCLUDE_DEFAULTS_MUSL_CROSS \
  180. + INCLUDE_DEFAULTS_MUSL_TOOL \
  181. + INCLUDE_DEFAULTS_MUSL_NATIVE \
  182. + { GCC_INCLUDE_DIR, "GCC", 0, 1, 0, 0 }, \
  183. + { 0, 0, 0, 0, 0, 0 } \
  184. + }
  185. +#endif
  186. +
  187. #if (DEFAULT_LIBC == LIBC_UCLIBC) && defined (SINGLE_LIBC) /* uClinux */
  188. /* This is a *uclinux* target. We don't define below macros to normal linux
  189. versions, because doing so would require *uclinux* targets to include
  190. --- a/gcc/config/linux.opt
  191. +++ b/gcc/config/linux.opt
  192. @@ -28,5 +28,9 @@ Target Report RejectNegative Var(linux_l
  193. Use GNU C library
  194. muclibc
  195. -Target Report RejectNegative Var(linux_libc,LIBC_UCLIBC) Negative(mbionic)
  196. +Target Report RejectNegative Var(linux_libc,LIBC_UCLIBC) Negative(mmusl)
  197. Use uClibc C library
  198. +
  199. +mmusl
  200. +Target Report RejectNegative Var(linux_libc,LIBC_MUSL) Negative(mbionic)
  201. +Use musl C library
  202. --- a/gcc/configure
  203. +++ b/gcc/configure
  204. @@ -27833,6 +27833,9 @@ if test "${gcc_cv_libc_provides_ssp+set}
  205. else
  206. gcc_cv_libc_provides_ssp=no
  207. case "$target" in
  208. + *-*-musl*)
  209. + # All versions of musl provide stack protector
  210. + gcc_cv_libc_provides_ssp=yes;;
  211. *-*-linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu)
  212. # glibc 2.4 and later provides __stack_chk_fail and
  213. # either __stack_chk_guard, or TLS access to stack guard canary.
  214. @@ -27865,6 +27868,7 @@ fi
  215. # <http://gcc.gnu.org/ml/gcc/2008-10/msg00130.html>) and for now
  216. # simply assert that glibc does provide this, which is true for all
  217. # realistically usable GNU/Hurd configurations.
  218. + # All supported versions of musl provide it as well
  219. gcc_cv_libc_provides_ssp=yes;;
  220. *-*-darwin* | *-*-freebsd*)
  221. ac_fn_c_check_func "$LINENO" "__stack_chk_fail" "ac_cv_func___stack_chk_fail"
  222. @@ -27961,6 +27965,9 @@ case "$target" in
  223. gcc_cv_target_dl_iterate_phdr=no
  224. fi
  225. ;;
  226. + *-linux-musl*)
  227. + gcc_cv_target_dl_iterate_phdr=yes
  228. + ;;
  229. esac
  230. if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
  231. --- a/gcc/configure.ac
  232. +++ b/gcc/configure.ac
  233. @@ -5287,6 +5287,9 @@ AC_CACHE_CHECK(__stack_chk_fail in targe
  234. gcc_cv_libc_provides_ssp,
  235. [gcc_cv_libc_provides_ssp=no
  236. case "$target" in
  237. + *-*-musl*)
  238. + # All versions of musl provide stack protector
  239. + gcc_cv_libc_provides_ssp=yes;;
  240. *-*-linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu)
  241. # glibc 2.4 and later provides __stack_chk_fail and
  242. # either __stack_chk_guard, or TLS access to stack guard canary.
  243. @@ -5313,6 +5316,7 @@ AC_CACHE_CHECK(__stack_chk_fail in targe
  244. # <http://gcc.gnu.org/ml/gcc/2008-10/msg00130.html>) and for now
  245. # simply assert that glibc does provide this, which is true for all
  246. # realistically usable GNU/Hurd configurations.
  247. + # All supported versions of musl provide it as well
  248. gcc_cv_libc_provides_ssp=yes;;
  249. *-*-darwin* | *-*-freebsd*)
  250. AC_CHECK_FUNC(__stack_chk_fail,[gcc_cv_libc_provides_ssp=yes],
  251. @@ -5386,6 +5390,9 @@ case "$target" in
  252. gcc_cv_target_dl_iterate_phdr=no
  253. fi
  254. ;;
  255. + *-linux-musl*)
  256. + gcc_cv_target_dl_iterate_phdr=yes
  257. + ;;
  258. esac
  259. GCC_TARGET_TEMPLATE([TARGET_DL_ITERATE_PHDR])
  260. if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
  261. --- a/gcc/doc/invoke.texi
  262. +++ b/gcc/doc/invoke.texi
  263. @@ -668,7 +668,7 @@ Objective-C and Objective-C++ Dialects}.
  264. -mcpu=@var{cpu}}
  265. @emph{GNU/Linux Options}
  266. -@gccoptlist{-mglibc -muclibc -mbionic -mandroid @gol
  267. +@gccoptlist{-mglibc -muclibc -mmusl -mbionic -mandroid @gol
  268. -tno-android-cc -tno-android-ld}
  269. @emph{H8/300 Options}
  270. @@ -15351,13 +15351,19 @@ These @samp{-m} options are defined for
  271. @item -mglibc
  272. @opindex mglibc
  273. Use the GNU C library. This is the default except
  274. -on @samp{*-*-linux-*uclibc*} and @samp{*-*-linux-*android*} targets.
  275. +on @samp{*-*-linux-*uclibc*}, @samp{*-*-linux-*musl*} and
  276. +@samp{*-*-linux-*android*} targets.
  277. @item -muclibc
  278. @opindex muclibc
  279. Use uClibc C library. This is the default on
  280. @samp{*-*-linux-*uclibc*} targets.
  281. +@item -mmusl
  282. +@opindex mmusl
  283. +Use the musl C library. This is the default on
  284. +@samp{*-*-linux-*musl*} targets.
  285. +
  286. @item -mbionic
  287. @opindex mbionic
  288. Use Bionic C library. This is the default on