904-musl-libc-config.patch 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. Index: b/gcc/config.gcc
  23. ===================================================================
  24. --- a/gcc/config.gcc
  25. +++ b/gcc/config.gcc
  26. @@ -575,7 +575,7 @@
  27. esac
  28. # Common C libraries.
  29. -tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3"
  30. +tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3 LIBC_MUSL=4"
  31. # 32-bit x86 processors supported by --with-arch=. Each processor
  32. # MUST be separated by exactly one space.
  33. @@ -720,6 +720,9 @@
  34. *-*-*uclibc*)
  35. tm_defines="$tm_defines DEFAULT_LIBC=LIBC_UCLIBC"
  36. ;;
  37. + *-*-*musl*)
  38. + tm_defines="$tm_defines DEFAULT_LIBC=LIBC_MUSL"
  39. + ;;
  40. *)
  41. tm_defines="$tm_defines DEFAULT_LIBC=LIBC_GLIBC"
  42. ;;
  43. Index: b/gcc/config/linux.h
  44. ===================================================================
  45. --- a/gcc/config/linux.h
  46. +++ b/gcc/config/linux.h
  47. @@ -32,10 +32,12 @@
  48. #define OPTION_GLIBC (DEFAULT_LIBC == LIBC_GLIBC)
  49. #define OPTION_UCLIBC (DEFAULT_LIBC == LIBC_UCLIBC)
  50. #define OPTION_BIONIC (DEFAULT_LIBC == LIBC_BIONIC)
  51. +#define OPTION_MUSL (DEFAULT_LIBC == LIBC_MUSL)
  52. #else
  53. #define OPTION_GLIBC (linux_libc == LIBC_GLIBC)
  54. #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
  55. #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
  56. +#define OPTION_MUSL (linux_libc == LIBC_MUSL)
  57. #endif
  58. #define GNU_USER_TARGET_OS_CPP_BUILTINS() \
  59. @@ -50,21 +52,25 @@
  60. } while (0)
  61. /* Determine which dynamic linker to use depending on whether GLIBC or
  62. - uClibc or Bionic is the default C library and whether
  63. - -muclibc or -mglibc or -mbionic has been passed to change the default. */
  64. + uClibc or Bionic or musl is the default C library and whether
  65. + -muclibc or -mglibc or -mbionic or -mmusl has been passed to change
  66. + the default. */
  67. -#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LD1, LD2, LD3) \
  68. - "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:" LD1 "}}"
  69. +#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LIBC4, LD1, LD2, LD3, LD4) \
  70. + "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:%{" LIBC4 ":" LD4 ";:" LD1 "}}}"
  71. #if DEFAULT_LIBC == LIBC_GLIBC
  72. -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
  73. - CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", G, U, B)
  74. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  75. + CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", "mmusl", G, U, B, M)
  76. #elif DEFAULT_LIBC == LIBC_UCLIBC
  77. -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
  78. - CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", U, G, B)
  79. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  80. + CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", "mmusl", U, G, B, M)
  81. #elif DEFAULT_LIBC == LIBC_BIONIC
  82. -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
  83. - CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", B, G, U)
  84. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  85. + CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", "mmusl", B, G, U, M)
  86. +#elif DEFAULT_LIBC == LIBC_MUSL
  87. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  88. + CHOOSE_DYNAMIC_LINKER1 ("mmusl", "mglibc", "muclibc", "mbionic", M, G, U, B)
  89. #else
  90. #error "Unsupported DEFAULT_LIBC"
  91. #endif /* DEFAULT_LIBC */
  92. @@ -81,24 +87,100 @@
  93. #define BIONIC_DYNAMIC_LINKER32 "/system/bin/linker"
  94. #define BIONIC_DYNAMIC_LINKER64 "/system/bin/linker64"
  95. #define BIONIC_DYNAMIC_LINKERX32 "/system/bin/linkerx32"
  96. +/* Should be redefined for each target that supports musl. */
  97. +#define MUSL_DYNAMIC_LINKER "/dev/null"
  98. +#define MUSL_DYNAMIC_LINKER32 "/dev/null"
  99. +#define MUSL_DYNAMIC_LINKER64 "/dev/null"
  100. +#define MUSL_DYNAMIC_LINKERX32 "/dev/null"
  101. #define GNU_USER_DYNAMIC_LINKER \
  102. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, \
  103. - BIONIC_DYNAMIC_LINKER)
  104. + BIONIC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
  105. #define GNU_USER_DYNAMIC_LINKER32 \
  106. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, \
  107. - BIONIC_DYNAMIC_LINKER32)
  108. + BIONIC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
  109. #define GNU_USER_DYNAMIC_LINKER64 \
  110. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
  111. - BIONIC_DYNAMIC_LINKER64)
  112. + BIONIC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
  113. #define GNU_USER_DYNAMIC_LINKERX32 \
  114. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \
  115. - BIONIC_DYNAMIC_LINKERX32)
  116. + BIONIC_DYNAMIC_LINKERX32, MUSL_DYNAMIC_LINKERX32)
  117. /* Whether we have Bionic libc runtime */
  118. #undef TARGET_HAS_BIONIC
  119. #define TARGET_HAS_BIONIC (OPTION_BIONIC)
  120. +/* musl avoids problematic includes by rearranging the include directories.
  121. + * Unfortunately, this is mostly duplicated from cppdefault.c */
  122. +#if DEFAULT_LIBC == LIBC_MUSL
  123. +#define INCLUDE_DEFAULTS_MUSL_GPP \
  124. + { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, \
  125. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, \
  126. + { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1, \
  127. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 }, \
  128. + { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1, \
  129. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },
  130. +
  131. +#ifdef LOCAL_INCLUDE_DIR
  132. +#define INCLUDE_DEFAULTS_MUSL_LOCAL \
  133. + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 }, \
  134. + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 },
  135. +#else
  136. +#define INCLUDE_DEFAULTS_MUSL_LOCAL
  137. +#endif
  138. +
  139. +#ifdef PREFIX_INCLUDE_DIR
  140. +#define INCLUDE_DEFAULTS_MUSL_PREFIX \
  141. + { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0},
  142. +#else
  143. +#define INCLUDE_DEFAULTS_MUSL_PREFIX
  144. +#endif
  145. +
  146. +#ifdef CROSS_INCLUDE_DIR
  147. +#define INCLUDE_DEFAULTS_MUSL_CROSS \
  148. + { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0},
  149. +#else
  150. +#define INCLUDE_DEFAULTS_MUSL_CROSS
  151. +#endif
  152. +
  153. +#ifdef TOOL_INCLUDE_DIR
  154. +#define INCLUDE_DEFAULTS_MUSL_TOOL \
  155. + { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0},
  156. +#else
  157. +#define INCLUDE_DEFAULTS_MUSL_TOOL
  158. +#endif
  159. +
  160. +#ifdef NATIVE_SYSTEM_HEADER_DIR
  161. +#define INCLUDE_DEFAULTS_MUSL_NATIVE \
  162. + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 2 }, \
  163. + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 0 },
  164. +#else
  165. +#define INCLUDE_DEFAULTS_MUSL_NATIVE
  166. +#endif
  167. +
  168. +#if defined (CROSS_DIRECTORY_STRUCTURE) && !defined (TARGET_SYSTEM_ROOT)
  169. +# undef INCLUDE_DEFAULTS_MUSL_LOCAL
  170. +# define INCLUDE_DEFAULTS_MUSL_LOCAL
  171. +# undef INCLUDE_DEFAULTS_MUSL_NATIVE
  172. +# define INCLUDE_DEFAULTS_MUSL_NATIVE
  173. +#else
  174. +# undef INCLUDE_DEFAULTS_MUSL_CROSS
  175. +# define INCLUDE_DEFAULTS_MUSL_CROSS
  176. +#endif
  177. +
  178. +#undef INCLUDE_DEFAULTS
  179. +#define INCLUDE_DEFAULTS \
  180. + { \
  181. + INCLUDE_DEFAULTS_MUSL_GPP \
  182. + INCLUDE_DEFAULTS_MUSL_PREFIX \
  183. + INCLUDE_DEFAULTS_MUSL_CROSS \
  184. + INCLUDE_DEFAULTS_MUSL_TOOL \
  185. + INCLUDE_DEFAULTS_MUSL_NATIVE \
  186. + { GCC_INCLUDE_DIR, "GCC", 0, 1, 0, 0 }, \
  187. + { 0, 0, 0, 0, 0, 0 } \
  188. + }
  189. +#endif
  190. +
  191. #if (DEFAULT_LIBC == LIBC_UCLIBC) && defined (SINGLE_LIBC) /* uClinux */
  192. /* This is a *uclinux* target. We don't define below macros to normal linux
  193. versions, because doing so would require *uclinux* targets to include
  194. Index: b/gcc/config/linux.opt
  195. ===================================================================
  196. --- a/gcc/config/linux.opt
  197. +++ b/gcc/config/linux.opt
  198. @@ -28,5 +28,9 @@
  199. Use GNU C library
  200. muclibc
  201. -Target Report RejectNegative Var(linux_libc,LIBC_UCLIBC) Negative(mbionic)
  202. +Target Report RejectNegative Var(linux_libc,LIBC_UCLIBC) Negative(mmusl)
  203. Use uClibc C library
  204. +
  205. +mmusl
  206. +Target Report RejectNegative Var(linux_libc,LIBC_MUSL) Negative(mbionic)
  207. +Use musl C library
  208. Index: b/gcc/configure
  209. ===================================================================
  210. --- a/gcc/configure
  211. +++ b/gcc/configure
  212. @@ -27809,6 +27813,9 @@
  213. gcc_cv_target_dl_iterate_phdr=no
  214. fi
  215. ;;
  216. + *-linux-musl*)
  217. + gcc_cv_target_dl_iterate_phdr=yes
  218. + ;;
  219. esac
  220. if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
  221. Index: b/gcc/configure.ac
  222. ===================================================================
  223. --- a/gcc/configure.ac
  224. +++ b/gcc/configure.ac
  225. @@ -5298,6 +5302,9 @@
  226. gcc_cv_target_dl_iterate_phdr=no
  227. fi
  228. ;;
  229. + *-linux-musl*)
  230. + gcc_cv_target_dl_iterate_phdr=yes
  231. + ;;
  232. esac
  233. GCC_TARGET_TEMPLATE([TARGET_DL_ITERATE_PHDR])
  234. if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
  235. Index: b/gcc/doc/invoke.texi
  236. ===================================================================
  237. --- a/gcc/doc/invoke.texi
  238. +++ b/gcc/doc/invoke.texi
  239. @@ -667,7 +667,7 @@
  240. -mcpu=@var{cpu}}
  241. @emph{GNU/Linux Options}
  242. -@gccoptlist{-mglibc -muclibc -mbionic -mandroid @gol
  243. +@gccoptlist{-mglibc -muclibc -mmusl -mbionic -mandroid @gol
  244. -tno-android-cc -tno-android-ld}
  245. @emph{H8/300 Options}
  246. @@ -15324,13 +15324,19 @@
  247. @item -mglibc
  248. @opindex mglibc
  249. Use the GNU C library. This is the default except
  250. -on @samp{*-*-linux-*uclibc*} and @samp{*-*-linux-*android*} targets.
  251. +on @samp{*-*-linux-*uclibc*}, @samp{*-*-linux-*musl*} and
  252. +@samp{*-*-linux-*android*} targets.
  253. @item -muclibc
  254. @opindex muclibc
  255. Use uClibc C library. This is the default on
  256. @samp{*-*-linux-*uclibc*} targets.
  257. +@item -mmusl
  258. +@opindex mmusl
  259. +Use the musl C library. This is the default on
  260. +@samp{*-*-linux-*musl*} targets.
  261. +
  262. @item -mbionic
  263. @opindex mbionic
  264. Use Bionic C library. This is the default on