0001-musl.diff 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  1. diff --git a/fixincludes/mkfixinc.sh b/fixincludes/mkfixinc.sh
  2. index 6653fed..0d96c8c 100755
  3. --- a/fixincludes/mkfixinc.sh
  4. +++ b/fixincludes/mkfixinc.sh
  5. @@ -19,7 +19,8 @@ case $machine in
  6. powerpc-*-eabi* | \
  7. powerpc-*-rtems* | \
  8. powerpcle-*-eabisim* | \
  9. - powerpcle-*-eabi* )
  10. + powerpcle-*-eabi* | \
  11. + *-musl* )
  12. # IF there is no include fixing,
  13. # THEN create a no-op fixer and exit
  14. (echo "#! /bin/sh" ; echo "exit 0" ) > ${target}
  15. diff --git a/gcc/config.gcc b/gcc/config.gcc
  16. index 3ede69b..d9eb8cf 100644
  17. --- a/gcc/config.gcc
  18. +++ b/gcc/config.gcc
  19. @@ -575,7 +575,7 @@ case ${target} in
  20. esac
  21. # Common C libraries.
  22. -tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3"
  23. +tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3 LIBC_MUSL=4"
  24. # 32-bit x86 processors supported by --with-arch=. Each processor
  25. # MUST be separated by exactly one space.
  26. @@ -720,6 +720,9 @@ case ${target} in
  27. *-*-*uclibc*)
  28. tm_defines="$tm_defines DEFAULT_LIBC=LIBC_UCLIBC"
  29. ;;
  30. + *-*-*musl*)
  31. + tm_defines="$tm_defines DEFAULT_LIBC=LIBC_MUSL"
  32. + ;;
  33. *)
  34. tm_defines="$tm_defines DEFAULT_LIBC=LIBC_GLIBC"
  35. ;;
  36. diff --git a/gcc/config/aarch64/aarch64-linux.h b/gcc/config/aarch64/aarch64-linux.h
  37. index ba7fc3b..1600a32 100644
  38. --- a/gcc/config/aarch64/aarch64-linux.h
  39. +++ b/gcc/config/aarch64/aarch64-linux.h
  40. @@ -23,6 +23,9 @@
  41. #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux-aarch64%{mbig-endian:_be}%{mabi=ilp32:_ilp32}.so.1"
  42. +#undef MUSL_DYNAMIC_LINKER
  43. +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-aarch64%{mbig-endian:_be}%{mabi=ilp32:_ilp32}.so.1"
  44. +
  45. #undef ASAN_CC1_SPEC
  46. #define ASAN_CC1_SPEC "%{%:sanitize(address):-funwind-tables}"
  47. diff --git a/gcc/config/alpha/linux.h b/gcc/config/alpha/linux.h
  48. index c567f43..475ea06 100644
  49. --- a/gcc/config/alpha/linux.h
  50. +++ b/gcc/config/alpha/linux.h
  51. @@ -61,10 +61,14 @@ along with GCC; see the file COPYING3. If not see
  52. #define OPTION_GLIBC (DEFAULT_LIBC == LIBC_GLIBC)
  53. #define OPTION_UCLIBC (DEFAULT_LIBC == LIBC_UCLIBC)
  54. #define OPTION_BIONIC (DEFAULT_LIBC == LIBC_BIONIC)
  55. +#undef OPTION_MUSL
  56. +#define OPTION_MUSL (DEFAULT_LIBC == LIBC_MUSL)
  57. #else
  58. #define OPTION_GLIBC (linux_libc == LIBC_GLIBC)
  59. #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
  60. #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
  61. +#undef OPTION_MUSL
  62. +#define OPTION_MUSL (linux_libc == LIBC_MUSL)
  63. #endif
  64. /* Determine what functions are present at the runtime;
  65. diff --git a/gcc/config/arm/linux-eabi.h b/gcc/config/arm/linux-eabi.h
  66. index e9d65dc..f12e6bd 100644
  67. --- a/gcc/config/arm/linux-eabi.h
  68. +++ b/gcc/config/arm/linux-eabi.h
  69. @@ -77,6 +77,23 @@
  70. %{mfloat-abi=soft*:" GLIBC_DYNAMIC_LINKER_SOFT_FLOAT "} \
  71. %{!mfloat-abi=*:" GLIBC_DYNAMIC_LINKER_DEFAULT "}"
  72. +/* For ARM musl currently supports four dynamic linkers:
  73. + - ld-musl-arm.so.1 - for the EABI-derived soft-float ABI
  74. + - ld-musl-armhf.so.1 - for the EABI-derived hard-float ABI
  75. + - ld-musl-armeb.so.1 - for the EABI-derived soft-float ABI, EB
  76. + - ld-musl-armebhf.so.1 - for the EABI-derived hard-float ABI, EB
  77. + musl does not support the legacy OABI mode.
  78. + All the dynamic linkers live in /lib.
  79. + We default to soft-float, EL. */
  80. +#undef MUSL_DYNAMIC_LINKER
  81. +#if TARGET_BIG_ENDIAN_DEFAULT
  82. +#define MUSL_DYNAMIC_LINKER_E "%{mlittle-endian:;:eb}"
  83. +#else
  84. +#define MUSL_DYNAMIC_LINKER_E "%{mbig-endian:eb}"
  85. +#endif
  86. +#define MUSL_DYNAMIC_LINKER \
  87. + "/lib/ld-musl-arm" MUSL_DYNAMIC_LINKER_E "%{mfloat-abi=hard:hf}.so.1"
  88. +
  89. /* At this point, bpabi.h will have clobbered LINK_SPEC. We want to
  90. use the GNU/Linux version, not the generic BPABI version. */
  91. #undef LINK_SPEC
  92. diff --git a/gcc/config/glibc-stdint.h b/gcc/config/glibc-stdint.h
  93. index 3fc67dc..98f4f04 100644
  94. --- a/gcc/config/glibc-stdint.h
  95. +++ b/gcc/config/glibc-stdint.h
  96. @@ -22,6 +22,12 @@ a copy of the GCC Runtime Library Exception along with this program;
  97. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  98. <http://www.gnu.org/licenses/>. */
  99. +/* Systems using musl libc should use this header and make sure
  100. + OPTION_MUSL is defined correctly before using the TYPE macros. */
  101. +#ifndef OPTION_MUSL
  102. +#define OPTION_MUSL 0
  103. +#endif
  104. +
  105. #define SIG_ATOMIC_TYPE "int"
  106. #define INT8_TYPE "signed char"
  107. @@ -43,12 +49,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  108. #define UINT_LEAST64_TYPE (LONG_TYPE_SIZE == 64 ? "long unsigned int" : "long long unsigned int")
  109. #define INT_FAST8_TYPE "signed char"
  110. -#define INT_FAST16_TYPE (LONG_TYPE_SIZE == 64 ? "long int" : "int")
  111. -#define INT_FAST32_TYPE (LONG_TYPE_SIZE == 64 ? "long int" : "int")
  112. +#define INT_FAST16_TYPE (LONG_TYPE_SIZE == 64 && !OPTION_MUSL ? "long int" : "int")
  113. +#define INT_FAST32_TYPE (LONG_TYPE_SIZE == 64 && !OPTION_MUSL ? "long int" : "int")
  114. #define INT_FAST64_TYPE (LONG_TYPE_SIZE == 64 ? "long int" : "long long int")
  115. #define UINT_FAST8_TYPE "unsigned char"
  116. -#define UINT_FAST16_TYPE (LONG_TYPE_SIZE == 64 ? "long unsigned int" : "unsigned int")
  117. -#define UINT_FAST32_TYPE (LONG_TYPE_SIZE == 64 ? "long unsigned int" : "unsigned int")
  118. +#define UINT_FAST16_TYPE (LONG_TYPE_SIZE == 64 && !OPTION_MUSL ? "long unsigned int" : "unsigned int")
  119. +#define UINT_FAST32_TYPE (LONG_TYPE_SIZE == 64 && !OPTION_MUSL ? "long unsigned int" : "unsigned int")
  120. #define UINT_FAST64_TYPE (LONG_TYPE_SIZE == 64 ? "long unsigned int" : "long long unsigned int")
  121. #define INTPTR_TYPE (LONG_TYPE_SIZE == 64 ? "long int" : "int")
  122. diff --git a/gcc/config/i386/linux.h b/gcc/config/i386/linux.h
  123. index a100963..385aefd 100644
  124. --- a/gcc/config/i386/linux.h
  125. +++ b/gcc/config/i386/linux.h
  126. @@ -21,3 +21,6 @@ along with GCC; see the file COPYING3. If not see
  127. #define GNU_USER_LINK_EMULATION "elf_i386"
  128. #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
  129. +
  130. +#undef MUSL_DYNAMIC_LINKER
  131. +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-i386.so.1"
  132. diff --git a/gcc/config/i386/linux64.h b/gcc/config/i386/linux64.h
  133. index a27d3be..e300480 100644
  134. --- a/gcc/config/i386/linux64.h
  135. +++ b/gcc/config/i386/linux64.h
  136. @@ -30,3 +30,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  137. #define GLIBC_DYNAMIC_LINKER32 "/lib/ld-linux.so.2"
  138. #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-linux-x86-64.so.2"
  139. #define GLIBC_DYNAMIC_LINKERX32 "/libx32/ld-linux-x32.so.2"
  140. +
  141. +#undef MUSL_DYNAMIC_LINKER32
  142. +#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-i386.so.1"
  143. +#undef MUSL_DYNAMIC_LINKER64
  144. +#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-x86_64.so.1"
  145. +#undef MUSL_DYNAMIC_LINKERX32
  146. +#define MUSL_DYNAMIC_LINKERX32 "/lib/ld-musl-x32.so.1"
  147. diff --git a/gcc/config/linux.h b/gcc/config/linux.h
  148. index 857389a..7bc87ab 100644
  149. --- a/gcc/config/linux.h
  150. +++ b/gcc/config/linux.h
  151. @@ -32,10 +32,14 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  152. #define OPTION_GLIBC (DEFAULT_LIBC == LIBC_GLIBC)
  153. #define OPTION_UCLIBC (DEFAULT_LIBC == LIBC_UCLIBC)
  154. #define OPTION_BIONIC (DEFAULT_LIBC == LIBC_BIONIC)
  155. +#undef OPTION_MUSL
  156. +#define OPTION_MUSL (DEFAULT_LIBC == LIBC_MUSL)
  157. #else
  158. #define OPTION_GLIBC (linux_libc == LIBC_GLIBC)
  159. #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
  160. #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
  161. +#undef OPTION_MUSL
  162. +#define OPTION_MUSL (linux_libc == LIBC_MUSL)
  163. #endif
  164. #define GNU_USER_TARGET_OS_CPP_BUILTINS() \
  165. @@ -50,21 +54,25 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  166. } while (0)
  167. /* Determine which dynamic linker to use depending on whether GLIBC or
  168. - uClibc or Bionic is the default C library and whether
  169. - -muclibc or -mglibc or -mbionic has been passed to change the default. */
  170. + uClibc or Bionic or musl is the default C library and whether
  171. + -muclibc or -mglibc or -mbionic or -mmusl has been passed to change
  172. + the default. */
  173. -#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LD1, LD2, LD3) \
  174. - "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:" LD1 "}}"
  175. +#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LIBC4, LD1, LD2, LD3, LD4) \
  176. + "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:%{" LIBC4 ":" LD4 ";:" LD1 "}}}"
  177. #if DEFAULT_LIBC == LIBC_GLIBC
  178. -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
  179. - CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", G, U, B)
  180. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  181. + CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", "mmusl", G, U, B, M)
  182. #elif DEFAULT_LIBC == LIBC_UCLIBC
  183. -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
  184. - CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", U, G, B)
  185. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  186. + CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", "mmusl", U, G, B, M)
  187. #elif DEFAULT_LIBC == LIBC_BIONIC
  188. -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
  189. - CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", B, G, U)
  190. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  191. + CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", "mmusl", B, G, U, M)
  192. +#elif DEFAULT_LIBC == LIBC_MUSL
  193. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  194. + CHOOSE_DYNAMIC_LINKER1 ("mmusl", "mglibc", "muclibc", "mbionic", M, G, U, B)
  195. #else
  196. #error "Unsupported DEFAULT_LIBC"
  197. #endif /* DEFAULT_LIBC */
  198. @@ -81,24 +89,100 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  199. #define BIONIC_DYNAMIC_LINKER32 "/system/bin/linker"
  200. #define BIONIC_DYNAMIC_LINKER64 "/system/bin/linker64"
  201. #define BIONIC_DYNAMIC_LINKERX32 "/system/bin/linkerx32"
  202. +/* Should be redefined for each target that supports musl. */
  203. +#define MUSL_DYNAMIC_LINKER "/dev/null"
  204. +#define MUSL_DYNAMIC_LINKER32 "/dev/null"
  205. +#define MUSL_DYNAMIC_LINKER64 "/dev/null"
  206. +#define MUSL_DYNAMIC_LINKERX32 "/dev/null"
  207. #define GNU_USER_DYNAMIC_LINKER \
  208. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, \
  209. - BIONIC_DYNAMIC_LINKER)
  210. + BIONIC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
  211. #define GNU_USER_DYNAMIC_LINKER32 \
  212. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, \
  213. - BIONIC_DYNAMIC_LINKER32)
  214. + BIONIC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
  215. #define GNU_USER_DYNAMIC_LINKER64 \
  216. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
  217. - BIONIC_DYNAMIC_LINKER64)
  218. + BIONIC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
  219. #define GNU_USER_DYNAMIC_LINKERX32 \
  220. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \
  221. - BIONIC_DYNAMIC_LINKERX32)
  222. + BIONIC_DYNAMIC_LINKERX32, MUSL_DYNAMIC_LINKERX32)
  223. /* Whether we have Bionic libc runtime */
  224. #undef TARGET_HAS_BIONIC
  225. #define TARGET_HAS_BIONIC (OPTION_BIONIC)
  226. +/* musl avoids problematic includes by rearranging the include directories.
  227. + * Unfortunately, this is mostly duplicated from cppdefault.c */
  228. +#if DEFAULT_LIBC == LIBC_MUSL
  229. +#define INCLUDE_DEFAULTS_MUSL_GPP \
  230. + { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, \
  231. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, \
  232. + { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1, \
  233. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 }, \
  234. + { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1, \
  235. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },
  236. +
  237. +#ifdef LOCAL_INCLUDE_DIR
  238. +#define INCLUDE_DEFAULTS_MUSL_LOCAL \
  239. + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 }, \
  240. + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 },
  241. +#else
  242. +#define INCLUDE_DEFAULTS_MUSL_LOCAL
  243. +#endif
  244. +
  245. +#ifdef PREFIX_INCLUDE_DIR
  246. +#define INCLUDE_DEFAULTS_MUSL_PREFIX \
  247. + { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0},
  248. +#else
  249. +#define INCLUDE_DEFAULTS_MUSL_PREFIX
  250. +#endif
  251. +
  252. +#ifdef CROSS_INCLUDE_DIR
  253. +#define INCLUDE_DEFAULTS_MUSL_CROSS \
  254. + { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0},
  255. +#else
  256. +#define INCLUDE_DEFAULTS_MUSL_CROSS
  257. +#endif
  258. +
  259. +#ifdef TOOL_INCLUDE_DIR
  260. +#define INCLUDE_DEFAULTS_MUSL_TOOL \
  261. + { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0},
  262. +#else
  263. +#define INCLUDE_DEFAULTS_MUSL_TOOL
  264. +#endif
  265. +
  266. +#ifdef NATIVE_SYSTEM_HEADER_DIR
  267. +#define INCLUDE_DEFAULTS_MUSL_NATIVE \
  268. + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 2 }, \
  269. + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 0 },
  270. +#else
  271. +#define INCLUDE_DEFAULTS_MUSL_NATIVE
  272. +#endif
  273. +
  274. +#if defined (CROSS_DIRECTORY_STRUCTURE) && !defined (TARGET_SYSTEM_ROOT)
  275. +# undef INCLUDE_DEFAULTS_MUSL_LOCAL
  276. +# define INCLUDE_DEFAULTS_MUSL_LOCAL
  277. +# undef INCLUDE_DEFAULTS_MUSL_NATIVE
  278. +# define INCLUDE_DEFAULTS_MUSL_NATIVE
  279. +#else
  280. +# undef INCLUDE_DEFAULTS_MUSL_CROSS
  281. +# define INCLUDE_DEFAULTS_MUSL_CROSS
  282. +#endif
  283. +
  284. +#undef INCLUDE_DEFAULTS
  285. +#define INCLUDE_DEFAULTS \
  286. + { \
  287. + INCLUDE_DEFAULTS_MUSL_GPP \
  288. + INCLUDE_DEFAULTS_MUSL_PREFIX \
  289. + INCLUDE_DEFAULTS_MUSL_CROSS \
  290. + INCLUDE_DEFAULTS_MUSL_TOOL \
  291. + INCLUDE_DEFAULTS_MUSL_NATIVE \
  292. + { GCC_INCLUDE_DIR, "GCC", 0, 1, 0, 0 }, \
  293. + { 0, 0, 0, 0, 0, 0 } \
  294. + }
  295. +#endif
  296. +
  297. #if (DEFAULT_LIBC == LIBC_UCLIBC) && defined (SINGLE_LIBC) /* uClinux */
  298. /* This is a *uclinux* target. We don't define below macros to normal linux
  299. versions, because doing so would require *uclinux* targets to include
  300. diff --git a/gcc/config/linux.opt b/gcc/config/linux.opt
  301. index c054338..ef055a7 100644
  302. --- a/gcc/config/linux.opt
  303. +++ b/gcc/config/linux.opt
  304. @@ -28,5 +28,9 @@ Target Report RejectNegative Var(linux_libc,LIBC_GLIBC) Negative(muclibc)
  305. Use GNU C library
  306. muclibc
  307. -Target Report RejectNegative Var(linux_libc,LIBC_UCLIBC) Negative(mbionic)
  308. +Target Report RejectNegative Var(linux_libc,LIBC_UCLIBC) Negative(mmusl)
  309. Use uClibc C library
  310. +
  311. +mmusl
  312. +Target Report RejectNegative Var(linux_libc,LIBC_MUSL) Negative(mbionic)
  313. +Use musl C library
  314. diff --git a/gcc/config/microblaze/linux.h b/gcc/config/microblaze/linux.h
  315. index 655a70f..a8a3f3e 100644
  316. --- a/gcc/config/microblaze/linux.h
  317. +++ b/gcc/config/microblaze/linux.h
  318. @@ -28,10 +28,20 @@
  319. #undef TLS_NEEDS_GOT
  320. #define TLS_NEEDS_GOT 1
  321. -#define DYNAMIC_LINKER "/lib/ld.so.1"
  322. +#define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
  323. +
  324. +#if TARGET_BIG_ENDIAN_DEFAULT == 0 /* LE */
  325. +#define MUSL_DYNAMIC_LINKER_E "%{mbig-endian:;:el}"
  326. +#else
  327. +#define MUSL_DYNAMIC_LINKER_E "%{mlittle-endian:el}"
  328. +#endif
  329. +
  330. +#undef MUSL_DYNAMIC_LINKER
  331. +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-microblaze" MUSL_DYNAMIC_LINKER_E ".so.1"
  332. +
  333. #undef SUBTARGET_EXTRA_SPECS
  334. #define SUBTARGET_EXTRA_SPECS \
  335. - { "dynamic_linker", DYNAMIC_LINKER }
  336. + { "dynamic_linker", GNU_USER_DYNAMIC_LINKER }
  337. #undef LINK_SPEC
  338. #define LINK_SPEC "%{shared:-shared} \
  339. diff --git a/gcc/config/mips/linux.h b/gcc/config/mips/linux.h
  340. index 91df261..fb358e2 100644
  341. --- a/gcc/config/mips/linux.h
  342. +++ b/gcc/config/mips/linux.h
  343. @@ -37,7 +37,13 @@ along with GCC; see the file COPYING3. If not see
  344. #define UCLIBC_DYNAMIC_LINKERN32 \
  345. "%{mnan=2008:/lib32/ld-uClibc-mipsn8.so.0;:/lib32/ld-uClibc.so.0}"
  346. +#undef MUSL_DYNAMIC_LINKER32
  347. +#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-mips%{EL:el}%{msoft-float:-sf}.so.1"
  348. +#undef MUSL_DYNAMIC_LINKER64
  349. +#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-mips64%{EL:el}%{msoft-float:-sf}.so.1"
  350. +#define MUSL_DYNAMIC_LINKERN32 "/lib/ld-musl-mipsn32%{EL:el}%{msoft-float:-sf}.so.1"
  351. +
  352. #define BIONIC_DYNAMIC_LINKERN32 "/system/bin/linker32"
  353. #define GNU_USER_DYNAMIC_LINKERN32 \
  354. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERN32, UCLIBC_DYNAMIC_LINKERN32, \
  355. - BIONIC_DYNAMIC_LINKERN32)
  356. + BIONIC_DYNAMIC_LINKERN32, MUSL_DYNAMIC_LINKERN32)
  357. diff --git a/gcc/config/rs6000/linux.h b/gcc/config/rs6000/linux.h
  358. index fe0ebd6..a68ff69 100644
  359. --- a/gcc/config/rs6000/linux.h
  360. +++ b/gcc/config/rs6000/linux.h
  361. @@ -30,10 +30,14 @@
  362. #define OPTION_GLIBC (DEFAULT_LIBC == LIBC_GLIBC)
  363. #define OPTION_UCLIBC (DEFAULT_LIBC == LIBC_UCLIBC)
  364. #define OPTION_BIONIC (DEFAULT_LIBC == LIBC_BIONIC)
  365. +#undef OPTION_MUSL
  366. +#define OPTION_MUSL (DEFAULT_LIBC == LIBC_MUSL)
  367. #else
  368. #define OPTION_GLIBC (linux_libc == LIBC_GLIBC)
  369. #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
  370. #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
  371. +#undef OPTION_MUSL
  372. +#define OPTION_MUSL (linux_libc == LIBC_MUSL)
  373. #endif
  374. /* Determine what functions are present at the runtime;
  375. diff --git a/gcc/config/rs6000/linux64.h b/gcc/config/rs6000/linux64.h
  376. index 0879e7e..6a7d435 100644
  377. --- a/gcc/config/rs6000/linux64.h
  378. +++ b/gcc/config/rs6000/linux64.h
  379. @@ -299,10 +299,14 @@ extern int dot_symbols;
  380. #define OPTION_GLIBC (DEFAULT_LIBC == LIBC_GLIBC)
  381. #define OPTION_UCLIBC (DEFAULT_LIBC == LIBC_UCLIBC)
  382. #define OPTION_BIONIC (DEFAULT_LIBC == LIBC_BIONIC)
  383. +#undef OPTION_MUSL
  384. +#define OPTION_MUSL (DEFAULT_LIBC == LIBC_MUSL)
  385. #else
  386. #define OPTION_GLIBC (linux_libc == LIBC_GLIBC)
  387. #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
  388. #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
  389. +#undef OPTION_MUSL
  390. +#define OPTION_MUSL (linux_libc == LIBC_MUSL)
  391. #endif
  392. /* Determine what functions are present at the runtime;
  393. @@ -365,17 +369,23 @@ extern int dot_symbols;
  394. #endif
  395. #define UCLIBC_DYNAMIC_LINKER32 "/lib/ld-uClibc.so.0"
  396. #define UCLIBC_DYNAMIC_LINKER64 "/lib/ld64-uClibc.so.0"
  397. +#define MUSL_DYNAMIC_LINKER32 \
  398. + "/lib/ld-musl-powerpc" MUSL_DYNAMIC_LINKER_E "%{msoft-float:-sf}.so.1"
  399. +#define MUSL_DYNAMIC_LINKER64 \
  400. + "/lib/ld-musl-powerpc64" MUSL_DYNAMIC_LINKER_E "%{msoft-float:-sf}.so.1"
  401. #if DEFAULT_LIBC == LIBC_UCLIBC
  402. -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
  403. +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
  404. #elif DEFAULT_LIBC == LIBC_GLIBC
  405. -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
  406. +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
  407. +#elif DEFAULT_LIBC == LIBC_MUSL
  408. +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
  409. #else
  410. #error "Unsupported DEFAULT_LIBC"
  411. #endif
  412. #define GNU_USER_DYNAMIC_LINKER32 \
  413. - CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32)
  414. + CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
  415. #define GNU_USER_DYNAMIC_LINKER64 \
  416. - CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64)
  417. + CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
  418. #undef DEFAULT_ASM_ENDIAN
  419. #if (TARGET_DEFAULT & MASK_LITTLE_ENDIAN)
  420. diff --git a/gcc/config/rs6000/secureplt.h b/gcc/config/rs6000/secureplt.h
  421. index b463463..77edf2a 100644
  422. --- a/gcc/config/rs6000/secureplt.h
  423. +++ b/gcc/config/rs6000/secureplt.h
  424. @@ -18,3 +18,4 @@ along with GCC; see the file COPYING3. If not see
  425. <http://www.gnu.org/licenses/>. */
  426. #define CC1_SECURE_PLT_DEFAULT_SPEC "-msecure-plt"
  427. +#define LINK_SECURE_PLT_DEFAULT_SPEC "--secure-plt"
  428. diff --git a/gcc/config/rs6000/sysv4.h b/gcc/config/rs6000/sysv4.h
  429. index 9917c2f..68365de 100644
  430. --- a/gcc/config/rs6000/sysv4.h
  431. +++ b/gcc/config/rs6000/sysv4.h
  432. @@ -537,6 +537,9 @@ ENDIAN_SELECT(" -mbig", " -mlittle", DEFAULT_ASM_ENDIAN)
  433. #ifndef CC1_SECURE_PLT_DEFAULT_SPEC
  434. #define CC1_SECURE_PLT_DEFAULT_SPEC ""
  435. #endif
  436. +#ifndef LINK_SECURE_PLT_DEFAULT_SPEC
  437. +#define LINK_SECURE_PLT_DEFAULT_SPEC ""
  438. +#endif
  439. /* Pass -G xxx to the compiler. */
  440. #undef CC1_SPEC
  441. @@ -586,7 +589,8 @@ ENDIAN_SELECT(" -mbig", " -mlittle", DEFAULT_ASM_ENDIAN)
  442. /* Override the default target of the linker. */
  443. #define LINK_TARGET_SPEC \
  444. - ENDIAN_SELECT("", " --oformat elf32-powerpcle", "")
  445. + ENDIAN_SELECT("", " --oformat elf32-powerpcle", "") \
  446. + "%{!mbss-plt: %{!msecure-plt: %(link_secure_plt_default)}}"
  447. /* Any specific OS flags. */
  448. #define LINK_OS_SPEC "\
  449. @@ -762,17 +766,23 @@ ENDIAN_SELECT(" -mbig", " -mlittle", DEFAULT_ASM_ENDIAN)
  450. #define LINK_START_LINUX_SPEC ""
  451. +#define MUSL_DYNAMIC_LINKER_E ENDIAN_SELECT("","le","")
  452. +
  453. #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
  454. #define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0"
  455. +#define MUSL_DYNAMIC_LINKER \
  456. + "/lib/ld-musl-powerpc" MUSL_DYNAMIC_LINKER_E "%{msoft-float:-sf}.so.1"
  457. #if DEFAULT_LIBC == LIBC_UCLIBC
  458. -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
  459. +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
  460. +#elif DEFAULT_LIBC == LIBC_MUSL
  461. +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
  462. #elif !defined (DEFAULT_LIBC) || DEFAULT_LIBC == LIBC_GLIBC
  463. -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
  464. +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
  465. #else
  466. #error "Unsupported DEFAULT_LIBC"
  467. #endif
  468. #define GNU_USER_DYNAMIC_LINKER \
  469. - CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER)
  470. + CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
  471. #define LINK_OS_LINUX_SPEC "-m elf32ppclinux %{!shared: %{!static: \
  472. %{rdynamic:-export-dynamic} \
  473. @@ -895,6 +905,7 @@ ncrtn.o%s"
  474. { "link_os_openbsd", LINK_OS_OPENBSD_SPEC }, \
  475. { "link_os_default", LINK_OS_DEFAULT_SPEC }, \
  476. { "cc1_secure_plt_default", CC1_SECURE_PLT_DEFAULT_SPEC }, \
  477. + { "link_secure_plt_default", LINK_SECURE_PLT_DEFAULT_SPEC }, \
  478. { "cpp_os_ads", CPP_OS_ADS_SPEC }, \
  479. { "cpp_os_yellowknife", CPP_OS_YELLOWKNIFE_SPEC }, \
  480. { "cpp_os_mvme", CPP_OS_MVME_SPEC }, \
  481. @@ -949,3 +960,72 @@ ncrtn.o%s"
  482. /* This target uses the sysv4.opt file. */
  483. #define TARGET_USES_SYSV4_OPT 1
  484. +/* Include order changes for musl, same as in generic linux.h. */
  485. +#if DEFAULT_LIBC == LIBC_MUSL
  486. +#define INCLUDE_DEFAULTS_MUSL_GPP \
  487. + { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, \
  488. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, \
  489. + { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1, \
  490. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 }, \
  491. + { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1, \
  492. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },
  493. +
  494. +#ifdef LOCAL_INCLUDE_DIR
  495. +#define INCLUDE_DEFAULTS_MUSL_LOCAL \
  496. + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 }, \
  497. + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 },
  498. +#else
  499. +#define INCLUDE_DEFAULTS_MUSL_LOCAL
  500. +#endif
  501. +
  502. +#ifdef PREFIX_INCLUDE_DIR
  503. +#define INCLUDE_DEFAULTS_MUSL_PREFIX \
  504. + { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0},
  505. +#else
  506. +#define INCLUDE_DEFAULTS_MUSL_PREFIX
  507. +#endif
  508. +
  509. +#ifdef CROSS_INCLUDE_DIR
  510. +#define INCLUDE_DEFAULTS_MUSL_CROSS \
  511. + { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0},
  512. +#else
  513. +#define INCLUDE_DEFAULTS_MUSL_CROSS
  514. +#endif
  515. +
  516. +#ifdef TOOL_INCLUDE_DIR
  517. +#define INCLUDE_DEFAULTS_MUSL_TOOL \
  518. + { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0},
  519. +#else
  520. +#define INCLUDE_DEFAULTS_MUSL_TOOL
  521. +#endif
  522. +
  523. +#ifdef NATIVE_SYSTEM_HEADER_DIR
  524. +#define INCLUDE_DEFAULTS_MUSL_NATIVE \
  525. + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 2 }, \
  526. + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 0 },
  527. +#else
  528. +#define INCLUDE_DEFAULTS_MUSL_NATIVE
  529. +#endif
  530. +
  531. +#if defined (CROSS_DIRECTORY_STRUCTURE) && !defined (TARGET_SYSTEM_ROOT)
  532. +# undef INCLUDE_DEFAULTS_MUSL_LOCAL
  533. +# define INCLUDE_DEFAULTS_MUSL_LOCAL
  534. +# undef INCLUDE_DEFAULTS_MUSL_NATIVE
  535. +# define INCLUDE_DEFAULTS_MUSL_NATIVE
  536. +#else
  537. +# undef INCLUDE_DEFAULTS_MUSL_CROSS
  538. +# define INCLUDE_DEFAULTS_MUSL_CROSS
  539. +#endif
  540. +
  541. +#undef INCLUDE_DEFAULTS
  542. +#define INCLUDE_DEFAULTS \
  543. + { \
  544. + INCLUDE_DEFAULTS_MUSL_GPP \
  545. + INCLUDE_DEFAULTS_MUSL_PREFIX \
  546. + INCLUDE_DEFAULTS_MUSL_CROSS \
  547. + INCLUDE_DEFAULTS_MUSL_TOOL \
  548. + INCLUDE_DEFAULTS_MUSL_NATIVE \
  549. + { GCC_INCLUDE_DIR, "GCC", 0, 1, 0, 0 }, \
  550. + { 0, 0, 0, 0, 0, 0 } \
  551. + }
  552. +#endif
  553. diff --git a/gcc/config/rs6000/sysv4le.h b/gcc/config/rs6000/sysv4le.h
  554. index 7b1d6a1..064323c 100644
  555. --- a/gcc/config/rs6000/sysv4le.h
  556. +++ b/gcc/config/rs6000/sysv4le.h
  557. @@ -35,3 +35,5 @@
  558. /* Little-endian PowerPC64 Linux uses the ELF v2 ABI by default. */
  559. #define LINUX64_DEFAULT_ABI_ELFv2
  560. +#undef MUSL_DYNAMIC_LINKER_E
  561. +#define MUSL_DYNAMIC_LINKER_E ENDIAN_SELECT("","le","le")
  562. diff --git a/gcc/config/sh/linux.h b/gcc/config/sh/linux.h
  563. index 0f5d614..4c167c6 100644
  564. --- a/gcc/config/sh/linux.h
  565. +++ b/gcc/config/sh/linux.h
  566. @@ -43,6 +43,29 @@ along with GCC; see the file COPYING3. If not see
  567. #define TARGET_ASM_FILE_END file_end_indicate_exec_stack
  568. +#if TARGET_ENDIAN_DEFAULT == MASK_LITTLE_ENDIAN
  569. +#define MUSL_DYNAMIC_LINKER_E "%{mb:eb}"
  570. +#else
  571. +#define MUSL_DYNAMIC_LINKER_E "%{!ml:eb}"
  572. +#endif
  573. +
  574. +#if TARGET_CPU_DEFAULT & ( MASK_HARD_SH2A_DOUBLE | MASK_SH4 )
  575. +/* "-nofpu" if any nofpu option is specified */
  576. +#define MUSL_DYNAMIC_LINKER_FP \
  577. + "%{m1|m2|m2a-nofpu|m3|m4-nofpu|m4-100-nofpu|m4-200-nofpu|m4-300-nofpu|" \
  578. + "m4-340|m4-400|m4-500|m4al|m5-32media-nofpu|m5-64media-nofpu|" \
  579. + "m5-compact-nofpu:-nofpu}"
  580. +#else
  581. +/* "-nofpu" if none of the hard fpu options are specified */
  582. +#define MUSL_DYNAMIC_LINKER_FP \
  583. + "%{m2a|m4|m4-100|m4-200|m4-300|m4a|m5-32media|m5-64media|m5-compact:;:-nofpu}"
  584. +#endif
  585. +
  586. +#undef MUSL_DYNAMIC_LINKER
  587. +#define MUSL_DYNAMIC_LINKER \
  588. + "/lib/ld-musl-sh" MUSL_DYNAMIC_LINKER_E MUSL_DYNAMIC_LINKER_FP \
  589. + "%{mfdpic:-fdpic}.so.1"
  590. +
  591. #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
  592. #undef SUBTARGET_LINK_EMUL_SUFFIX
  593. diff --git a/gcc/configure b/gcc/configure
  594. index 0037240..66aab9f 100755
  595. --- a/gcc/configure
  596. +++ b/gcc/configure
  597. @@ -27742,6 +27742,9 @@ if test "${gcc_cv_libc_provides_ssp+set}" = set; then :
  598. else
  599. gcc_cv_libc_provides_ssp=no
  600. case "$target" in
  601. + *-*-musl*)
  602. + # All versions of musl provide stack protector
  603. + gcc_cv_libc_provides_ssp=yes;;
  604. *-*-linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu)
  605. # glibc 2.4 and later provides __stack_chk_fail and
  606. # either __stack_chk_guard, or TLS access to stack guard canary.
  607. @@ -27774,6 +27777,7 @@ fi
  608. # <http://gcc.gnu.org/ml/gcc/2008-10/msg00130.html>) and for now
  609. # simply assert that glibc does provide this, which is true for all
  610. # realistically usable GNU/Hurd configurations.
  611. + # All supported versions of musl provide it as well
  612. gcc_cv_libc_provides_ssp=yes;;
  613. *-*-darwin* | *-*-freebsd*)
  614. ac_fn_c_check_func "$LINENO" "__stack_chk_fail" "ac_cv_func___stack_chk_fail"
  615. @@ -27870,6 +27874,9 @@ case "$target" in
  616. gcc_cv_target_dl_iterate_phdr=no
  617. fi
  618. ;;
  619. + *-linux-musl*)
  620. + gcc_cv_target_dl_iterate_phdr=yes
  621. + ;;
  622. esac
  623. if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
  624. diff --git a/gcc/configure.ac b/gcc/configure.ac
  625. index 6f38ba1..b81960c 100644
  626. --- a/gcc/configure.ac
  627. +++ b/gcc/configure.ac
  628. @@ -5229,6 +5229,9 @@ AC_CACHE_CHECK(__stack_chk_fail in target C library,
  629. gcc_cv_libc_provides_ssp,
  630. [gcc_cv_libc_provides_ssp=no
  631. case "$target" in
  632. + *-*-musl*)
  633. + # All versions of musl provide stack protector
  634. + gcc_cv_libc_provides_ssp=yes;;
  635. *-*-linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu)
  636. # glibc 2.4 and later provides __stack_chk_fail and
  637. # either __stack_chk_guard, or TLS access to stack guard canary.
  638. @@ -5255,6 +5258,7 @@ AC_CACHE_CHECK(__stack_chk_fail in target C library,
  639. # <http://gcc.gnu.org/ml/gcc/2008-10/msg00130.html>) and for now
  640. # simply assert that glibc does provide this, which is true for all
  641. # realistically usable GNU/Hurd configurations.
  642. + # All supported versions of musl provide it as well
  643. gcc_cv_libc_provides_ssp=yes;;
  644. *-*-darwin* | *-*-freebsd*)
  645. AC_CHECK_FUNC(__stack_chk_fail,[gcc_cv_libc_provides_ssp=yes],
  646. @@ -5328,6 +5332,9 @@ case "$target" in
  647. gcc_cv_target_dl_iterate_phdr=no
  648. fi
  649. ;;
  650. + *-linux-musl*)
  651. + gcc_cv_target_dl_iterate_phdr=yes
  652. + ;;
  653. esac
  654. GCC_TARGET_TEMPLATE([TARGET_DL_ITERATE_PHDR])
  655. if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
  656. diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
  657. index f84a199..ee9765b 100644
  658. --- a/gcc/doc/invoke.texi
  659. +++ b/gcc/doc/invoke.texi
  660. @@ -667,7 +667,7 @@ Objective-C and Objective-C++ Dialects}.
  661. -mcpu=@var{cpu}}
  662. @emph{GNU/Linux Options}
  663. -@gccoptlist{-mglibc -muclibc -mbionic -mandroid @gol
  664. +@gccoptlist{-mglibc -muclibc -mmusl -mbionic -mandroid @gol
  665. -tno-android-cc -tno-android-ld}
  666. @emph{H8/300 Options}
  667. @@ -15324,13 +15324,19 @@ These @samp{-m} options are defined for GNU/Linux targets:
  668. @item -mglibc
  669. @opindex mglibc
  670. Use the GNU C library. This is the default except
  671. -on @samp{*-*-linux-*uclibc*} and @samp{*-*-linux-*android*} targets.
  672. +on @samp{*-*-linux-*uclibc*}, @samp{*-*-linux-*musl*} and
  673. +@samp{*-*-linux-*android*} targets.
  674. @item -muclibc
  675. @opindex muclibc
  676. Use uClibc C library. This is the default on
  677. @samp{*-*-linux-*uclibc*} targets.
  678. +@item -mmusl
  679. +@opindex mmusl
  680. +Use the musl C library. This is the default on
  681. +@samp{*-*-linux-*musl*} targets.
  682. +
  683. @item -mbionic
  684. @opindex mbionic
  685. Use Bionic C library. This is the default on
  686. diff --git a/libcilkrts/runtime/os-unix.c b/libcilkrts/runtime/os-unix.c
  687. index cb582dd..e43d7d5 100644
  688. --- a/libcilkrts/runtime/os-unix.c
  689. +++ b/libcilkrts/runtime/os-unix.c
  690. @@ -51,6 +51,7 @@
  691. #if defined __linux__
  692. # include <sys/sysinfo.h>
  693. # include <sys/syscall.h>
  694. +# include <sched.h>
  695. #elif defined __APPLE__
  696. # include <sys/sysctl.h>
  697. // Uses sysconf(_SC_NPROCESSORS_ONLN) in verbose output
  698. @@ -400,28 +401,19 @@ COMMON_SYSDEP void __cilkrts_sleep(void)
  699. COMMON_SYSDEP void __cilkrts_yield(void)
  700. {
  701. -#if __APPLE__ || __FreeBSD__ || __VXWORKS__
  702. - // On MacOS, call sched_yield to yield quantum. I'm not sure why we
  703. - // don't do this on Linux also.
  704. - sched_yield();
  705. -#elif defined(__DragonFly__)
  706. - // On DragonFly BSD, call sched_yield to yield quantum.
  707. - sched_yield();
  708. -#elif defined(__MIC__)
  709. +#if defined(__MIC__)
  710. // On MIC, pthread_yield() really trashes things. Arch's measurements
  711. // showed that calling _mm_delay_32() (or doing nothing) was a better
  712. // option. Delaying 1024 clock cycles is a reasonable compromise between
  713. // giving up the processor and latency starting up when work becomes
  714. // available
  715. _mm_delay_32(1024);
  716. -#elif defined(__ANDROID__) || (defined(__sun__) && defined(__svr4__))
  717. - // On Android and Solaris, call sched_yield to yield quantum. I'm not
  718. - // sure why we don't do this on Linux also.
  719. - sched_yield();
  720. -#else
  721. - // On Linux, call pthread_yield (which in turn will call sched_yield)
  722. - // to yield quantum.
  723. +#elif defined(__sun__) && !defined(__svr4__)
  724. + // On old SunOS call pthread_yield to yield a quantum.
  725. pthread_yield();
  726. +#else
  727. + // On other platforms call sched_yield to yield a quantum.
  728. + sched_yield();
  729. #endif
  730. }
  731. diff --git a/libgcc/unwind-dw2-fde-dip.c b/libgcc/unwind-dw2-fde-dip.c
  732. index e1e566b..137dced 100644
  733. --- a/libgcc/unwind-dw2-fde-dip.c
  734. +++ b/libgcc/unwind-dw2-fde-dip.c
  735. @@ -59,6 +59,12 @@
  736. #if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
  737. && defined(TARGET_DL_ITERATE_PHDR) \
  738. + && defined(__linux__)
  739. +# define USE_PT_GNU_EH_FRAME
  740. +#endif
  741. +
  742. +#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
  743. + && defined(TARGET_DL_ITERATE_PHDR) \
  744. && (defined(__DragonFly__) || defined(__FreeBSD__))
  745. # define ElfW __ElfN
  746. # define USE_PT_GNU_EH_FRAME
  747. diff --git a/libgfortran/acinclude.m4 b/libgfortran/acinclude.m4
  748. index ba890f9..30b8b1a6 100644
  749. --- a/libgfortran/acinclude.m4
  750. +++ b/libgfortran/acinclude.m4
  751. @@ -100,7 +100,7 @@ void foo (void);
  752. [Define to 1 if the target supports #pragma weak])
  753. fi
  754. case "$host" in
  755. - *-*-darwin* | *-*-hpux* | *-*-cygwin* | *-*-mingw* )
  756. + *-*-darwin* | *-*-hpux* | *-*-cygwin* | *-*-mingw* | *-*-musl* )
  757. AC_DEFINE(GTHREAD_USE_WEAK, 0,
  758. [Define to 0 if the target shouldn't use #pragma weak])
  759. ;;
  760. diff --git a/libgfortran/configure b/libgfortran/configure
  761. index e1592f7..07542e1 100755
  762. --- a/libgfortran/configure
  763. +++ b/libgfortran/configure
  764. @@ -26447,7 +26447,7 @@ $as_echo "#define SUPPORTS_WEAK 1" >>confdefs.h
  765. fi
  766. case "$host" in
  767. - *-*-darwin* | *-*-hpux* | *-*-cygwin* | *-*-mingw* )
  768. + *-*-darwin* | *-*-hpux* | *-*-cygwin* | *-*-mingw* | *-*-musl* )
  769. $as_echo "#define GTHREAD_USE_WEAK 0" >>confdefs.h
  770. diff --git a/libitm/config/arm/hwcap.cc b/libitm/config/arm/hwcap.cc
  771. index a1c2cfd..ea8f023 100644
  772. --- a/libitm/config/arm/hwcap.cc
  773. +++ b/libitm/config/arm/hwcap.cc
  774. @@ -40,7 +40,7 @@ int GTM_hwcap HIDDEN = 0
  775. #ifdef __linux__
  776. #include <unistd.h>
  777. -#include <sys/fcntl.h>
  778. +#include <fcntl.h>
  779. #include <elf.h>
  780. static void __attribute__((constructor))
  781. diff --git a/libitm/config/linux/x86/tls.h b/libitm/config/linux/x86/tls.h
  782. index e731ab7..54ad8b6 100644
  783. --- a/libitm/config/linux/x86/tls.h
  784. +++ b/libitm/config/linux/x86/tls.h
  785. @@ -25,16 +25,19 @@
  786. #ifndef LIBITM_X86_TLS_H
  787. #define LIBITM_X86_TLS_H 1
  788. -#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
  789. +#if defined(__GLIBC_PREREQ)
  790. +#if __GLIBC_PREREQ(2, 10)
  791. /* Use slots in the TCB head rather than __thread lookups.
  792. GLIBC has reserved words 10 through 13 for TM. */
  793. #define HAVE_ARCH_GTM_THREAD 1
  794. #define HAVE_ARCH_GTM_THREAD_DISP 1
  795. #endif
  796. +#endif
  797. #include "config/generic/tls.h"
  798. -#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
  799. +#if defined(__GLIBC_PREREQ)
  800. +#if __GLIBC_PREREQ(2, 10)
  801. namespace GTM HIDDEN {
  802. #ifdef __x86_64__
  803. @@ -101,5 +104,6 @@ static inline void set_abi_disp(struct abi_dispatch *x)
  804. } // namespace GTM
  805. #endif /* >= GLIBC 2.10 */
  806. +#endif
  807. #endif // LIBITM_X86_TLS_H
  808. diff --git a/libstdc++-v3/config/os/generic/os_defines.h b/libstdc++-v3/config/os/generic/os_defines.h
  809. index 45bf52a..103ec0e 100644
  810. --- a/libstdc++-v3/config/os/generic/os_defines.h
  811. +++ b/libstdc++-v3/config/os/generic/os_defines.h
  812. @@ -33,4 +33,9 @@
  813. // System-specific #define, typedefs, corrections, etc, go here. This
  814. // file will come before all others.
  815. +// Disable the weak reference logic in gthr.h for os/generic because it
  816. +// is broken on every platform unless there is implementation specific
  817. +// workaround in gthr-posix.h and at link-time for static linking.
  818. +#define _GLIBCXX_GTHREAD_USE_WEAK 0
  819. +
  820. #endif
  821. diff --git a/libstdc++-v3/configure.host b/libstdc++-v3/configure.host
  822. index 640199c..106134e 100644
  823. --- a/libstdc++-v3/configure.host
  824. +++ b/libstdc++-v3/configure.host
  825. @@ -273,6 +273,9 @@ case "${host_os}" in
  826. freebsd*)
  827. os_include_dir="os/bsd/freebsd"
  828. ;;
  829. + linux-musl*)
  830. + os_include_dir="os/generic"
  831. + ;;
  832. gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu)
  833. if [ "$uclibc" = "yes" ]; then
  834. os_include_dir="os/uclibc"