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. @@ -574,7 +577,8 @@
  442. %{R*} \
  443. %(link_shlib) \
  444. %{!T*: %(link_start) } \
  445. -%(link_os)"
  446. +%(link_os) \
  447. +%{!mbss-plt: %{!msecure-plt: %(link_secure_plt_default)}}"
  448. /* Shared libraries are not default. */
  449. #define LINK_SHLIB_SPEC "\
  450. @@ -762,17 +766,23 @@ ENDIAN_SELECT(" -mbig", " -mlittle", DEFAULT_ASM_ENDIAN)
  451. #define LINK_START_LINUX_SPEC ""
  452. +#define MUSL_DYNAMIC_LINKER_E ENDIAN_SELECT("","le","")
  453. +
  454. #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
  455. #define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0"
  456. +#define MUSL_DYNAMIC_LINKER \
  457. + "/lib/ld-musl-powerpc" MUSL_DYNAMIC_LINKER_E "%{msoft-float:-sf}.so.1"
  458. #if DEFAULT_LIBC == LIBC_UCLIBC
  459. -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
  460. +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
  461. +#elif DEFAULT_LIBC == LIBC_MUSL
  462. +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
  463. #elif !defined (DEFAULT_LIBC) || DEFAULT_LIBC == LIBC_GLIBC
  464. -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
  465. +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
  466. #else
  467. #error "Unsupported DEFAULT_LIBC"
  468. #endif
  469. #define GNU_USER_DYNAMIC_LINKER \
  470. - CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER)
  471. + CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
  472. #define LINK_OS_LINUX_SPEC "-m elf32ppclinux %{!shared: %{!static: \
  473. %{rdynamic:-export-dynamic} \
  474. @@ -895,6 +905,7 @@ ncrtn.o%s"
  475. { "link_os_openbsd", LINK_OS_OPENBSD_SPEC }, \
  476. { "link_os_default", LINK_OS_DEFAULT_SPEC }, \
  477. { "cc1_secure_plt_default", CC1_SECURE_PLT_DEFAULT_SPEC }, \
  478. + { "link_secure_plt_default", LINK_SECURE_PLT_DEFAULT_SPEC }, \
  479. { "cpp_os_ads", CPP_OS_ADS_SPEC }, \
  480. { "cpp_os_yellowknife", CPP_OS_YELLOWKNIFE_SPEC }, \
  481. { "cpp_os_mvme", CPP_OS_MVME_SPEC }, \
  482. @@ -949,3 +960,72 @@ ncrtn.o%s"
  483. /* This target uses the sysv4.opt file. */
  484. #define TARGET_USES_SYSV4_OPT 1
  485. +/* Include order changes for musl, same as in generic linux.h. */
  486. +#if DEFAULT_LIBC == LIBC_MUSL
  487. +#define INCLUDE_DEFAULTS_MUSL_GPP \
  488. + { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, \
  489. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, \
  490. + { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1, \
  491. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 }, \
  492. + { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1, \
  493. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },
  494. +
  495. +#ifdef LOCAL_INCLUDE_DIR
  496. +#define INCLUDE_DEFAULTS_MUSL_LOCAL \
  497. + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 }, \
  498. + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 },
  499. +#else
  500. +#define INCLUDE_DEFAULTS_MUSL_LOCAL
  501. +#endif
  502. +
  503. +#ifdef PREFIX_INCLUDE_DIR
  504. +#define INCLUDE_DEFAULTS_MUSL_PREFIX \
  505. + { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0},
  506. +#else
  507. +#define INCLUDE_DEFAULTS_MUSL_PREFIX
  508. +#endif
  509. +
  510. +#ifdef CROSS_INCLUDE_DIR
  511. +#define INCLUDE_DEFAULTS_MUSL_CROSS \
  512. + { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0},
  513. +#else
  514. +#define INCLUDE_DEFAULTS_MUSL_CROSS
  515. +#endif
  516. +
  517. +#ifdef TOOL_INCLUDE_DIR
  518. +#define INCLUDE_DEFAULTS_MUSL_TOOL \
  519. + { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0},
  520. +#else
  521. +#define INCLUDE_DEFAULTS_MUSL_TOOL
  522. +#endif
  523. +
  524. +#ifdef NATIVE_SYSTEM_HEADER_DIR
  525. +#define INCLUDE_DEFAULTS_MUSL_NATIVE \
  526. + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 2 }, \
  527. + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 0 },
  528. +#else
  529. +#define INCLUDE_DEFAULTS_MUSL_NATIVE
  530. +#endif
  531. +
  532. +#if defined (CROSS_DIRECTORY_STRUCTURE) && !defined (TARGET_SYSTEM_ROOT)
  533. +# undef INCLUDE_DEFAULTS_MUSL_LOCAL
  534. +# define INCLUDE_DEFAULTS_MUSL_LOCAL
  535. +# undef INCLUDE_DEFAULTS_MUSL_NATIVE
  536. +# define INCLUDE_DEFAULTS_MUSL_NATIVE
  537. +#else
  538. +# undef INCLUDE_DEFAULTS_MUSL_CROSS
  539. +# define INCLUDE_DEFAULTS_MUSL_CROSS
  540. +#endif
  541. +
  542. +#undef INCLUDE_DEFAULTS
  543. +#define INCLUDE_DEFAULTS \
  544. + { \
  545. + INCLUDE_DEFAULTS_MUSL_GPP \
  546. + INCLUDE_DEFAULTS_MUSL_PREFIX \
  547. + INCLUDE_DEFAULTS_MUSL_CROSS \
  548. + INCLUDE_DEFAULTS_MUSL_TOOL \
  549. + INCLUDE_DEFAULTS_MUSL_NATIVE \
  550. + { GCC_INCLUDE_DIR, "GCC", 0, 1, 0, 0 }, \
  551. + { 0, 0, 0, 0, 0, 0 } \
  552. + }
  553. +#endif
  554. diff --git a/gcc/config/rs6000/sysv4le.h b/gcc/config/rs6000/sysv4le.h
  555. index 7b1d6a1..064323c 100644
  556. --- a/gcc/config/rs6000/sysv4le.h
  557. +++ b/gcc/config/rs6000/sysv4le.h
  558. @@ -35,3 +35,5 @@
  559. /* Little-endian PowerPC64 Linux uses the ELF v2 ABI by default. */
  560. #define LINUX64_DEFAULT_ABI_ELFv2
  561. +#undef MUSL_DYNAMIC_LINKER_E
  562. +#define MUSL_DYNAMIC_LINKER_E ENDIAN_SELECT("","le","le")
  563. diff --git a/gcc/config/sh/linux.h b/gcc/config/sh/linux.h
  564. index 0f5d614..4c167c6 100644
  565. --- a/gcc/config/sh/linux.h
  566. +++ b/gcc/config/sh/linux.h
  567. @@ -43,6 +43,29 @@ along with GCC; see the file COPYING3. If not see
  568. #define TARGET_ASM_FILE_END file_end_indicate_exec_stack
  569. +#if TARGET_ENDIAN_DEFAULT == MASK_LITTLE_ENDIAN
  570. +#define MUSL_DYNAMIC_LINKER_E "%{mb:eb}"
  571. +#else
  572. +#define MUSL_DYNAMIC_LINKER_E "%{!ml:eb}"
  573. +#endif
  574. +
  575. +#if TARGET_CPU_DEFAULT & ( MASK_HARD_SH2A_DOUBLE | MASK_SH4 )
  576. +/* "-nofpu" if any nofpu option is specified */
  577. +#define MUSL_DYNAMIC_LINKER_FP \
  578. + "%{m1|m2|m2a-nofpu|m3|m4-nofpu|m4-100-nofpu|m4-200-nofpu|m4-300-nofpu|" \
  579. + "m4-340|m4-400|m4-500|m4al|m5-32media-nofpu|m5-64media-nofpu|" \
  580. + "m5-compact-nofpu:-nofpu}"
  581. +#else
  582. +/* "-nofpu" if none of the hard fpu options are specified */
  583. +#define MUSL_DYNAMIC_LINKER_FP \
  584. + "%{m2a|m4|m4-100|m4-200|m4-300|m4a|m5-32media|m5-64media|m5-compact:;:-nofpu}"
  585. +#endif
  586. +
  587. +#undef MUSL_DYNAMIC_LINKER
  588. +#define MUSL_DYNAMIC_LINKER \
  589. + "/lib/ld-musl-sh" MUSL_DYNAMIC_LINKER_E MUSL_DYNAMIC_LINKER_FP \
  590. + "%{mfdpic:-fdpic}.so.1"
  591. +
  592. #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
  593. #undef SUBTARGET_LINK_EMUL_SUFFIX
  594. diff --git a/gcc/configure b/gcc/configure
  595. index 0037240..66aab9f 100755
  596. --- a/gcc/configure
  597. +++ b/gcc/configure
  598. @@ -27742,6 +27742,9 @@ if test "${gcc_cv_libc_provides_ssp+set}" = set; then :
  599. else
  600. gcc_cv_libc_provides_ssp=no
  601. case "$target" in
  602. + *-*-musl*)
  603. + # All versions of musl provide stack protector
  604. + gcc_cv_libc_provides_ssp=yes;;
  605. *-*-linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu)
  606. # glibc 2.4 and later provides __stack_chk_fail and
  607. # either __stack_chk_guard, or TLS access to stack guard canary.
  608. @@ -27774,6 +27777,7 @@ fi
  609. # <http://gcc.gnu.org/ml/gcc/2008-10/msg00130.html>) and for now
  610. # simply assert that glibc does provide this, which is true for all
  611. # realistically usable GNU/Hurd configurations.
  612. + # All supported versions of musl provide it as well
  613. gcc_cv_libc_provides_ssp=yes;;
  614. *-*-darwin* | *-*-freebsd*)
  615. ac_fn_c_check_func "$LINENO" "__stack_chk_fail" "ac_cv_func___stack_chk_fail"
  616. @@ -27870,6 +27874,9 @@ case "$target" in
  617. gcc_cv_target_dl_iterate_phdr=no
  618. fi
  619. ;;
  620. + *-linux-musl*)
  621. + gcc_cv_target_dl_iterate_phdr=yes
  622. + ;;
  623. esac
  624. if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
  625. diff --git a/gcc/configure.ac b/gcc/configure.ac
  626. index 6f38ba1..b81960c 100644
  627. --- a/gcc/configure.ac
  628. +++ b/gcc/configure.ac
  629. @@ -5229,6 +5229,9 @@ AC_CACHE_CHECK(__stack_chk_fail in target C library,
  630. gcc_cv_libc_provides_ssp,
  631. [gcc_cv_libc_provides_ssp=no
  632. case "$target" in
  633. + *-*-musl*)
  634. + # All versions of musl provide stack protector
  635. + gcc_cv_libc_provides_ssp=yes;;
  636. *-*-linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu)
  637. # glibc 2.4 and later provides __stack_chk_fail and
  638. # either __stack_chk_guard, or TLS access to stack guard canary.
  639. @@ -5255,6 +5258,7 @@ AC_CACHE_CHECK(__stack_chk_fail in target C library,
  640. # <http://gcc.gnu.org/ml/gcc/2008-10/msg00130.html>) and for now
  641. # simply assert that glibc does provide this, which is true for all
  642. # realistically usable GNU/Hurd configurations.
  643. + # All supported versions of musl provide it as well
  644. gcc_cv_libc_provides_ssp=yes;;
  645. *-*-darwin* | *-*-freebsd*)
  646. AC_CHECK_FUNC(__stack_chk_fail,[gcc_cv_libc_provides_ssp=yes],
  647. @@ -5328,6 +5332,9 @@ case "$target" in
  648. gcc_cv_target_dl_iterate_phdr=no
  649. fi
  650. ;;
  651. + *-linux-musl*)
  652. + gcc_cv_target_dl_iterate_phdr=yes
  653. + ;;
  654. esac
  655. GCC_TARGET_TEMPLATE([TARGET_DL_ITERATE_PHDR])
  656. if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
  657. diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
  658. index f84a199..ee9765b 100644
  659. --- a/gcc/doc/invoke.texi
  660. +++ b/gcc/doc/invoke.texi
  661. @@ -667,7 +667,7 @@ Objective-C and Objective-C++ Dialects}.
  662. -mcpu=@var{cpu}}
  663. @emph{GNU/Linux Options}
  664. -@gccoptlist{-mglibc -muclibc -mbionic -mandroid @gol
  665. +@gccoptlist{-mglibc -muclibc -mmusl -mbionic -mandroid @gol
  666. -tno-android-cc -tno-android-ld}
  667. @emph{H8/300 Options}
  668. @@ -15324,13 +15324,19 @@ These @samp{-m} options are defined for GNU/Linux targets:
  669. @item -mglibc
  670. @opindex mglibc
  671. Use the GNU C library. This is the default except
  672. -on @samp{*-*-linux-*uclibc*} and @samp{*-*-linux-*android*} targets.
  673. +on @samp{*-*-linux-*uclibc*}, @samp{*-*-linux-*musl*} and
  674. +@samp{*-*-linux-*android*} targets.
  675. @item -muclibc
  676. @opindex muclibc
  677. Use uClibc C library. This is the default on
  678. @samp{*-*-linux-*uclibc*} targets.
  679. +@item -mmusl
  680. +@opindex mmusl
  681. +Use the musl C library. This is the default on
  682. +@samp{*-*-linux-*musl*} targets.
  683. +
  684. @item -mbionic
  685. @opindex mbionic
  686. Use Bionic C library. This is the default on
  687. diff --git a/libcilkrts/runtime/os-unix.c b/libcilkrts/runtime/os-unix.c
  688. index cb582dd..e43d7d5 100644
  689. --- a/libcilkrts/runtime/os-unix.c
  690. +++ b/libcilkrts/runtime/os-unix.c
  691. @@ -51,6 +51,7 @@
  692. #if defined __linux__
  693. # include <sys/sysinfo.h>
  694. # include <sys/syscall.h>
  695. +# include <sched.h>
  696. #elif defined __APPLE__
  697. # include <sys/sysctl.h>
  698. // Uses sysconf(_SC_NPROCESSORS_ONLN) in verbose output
  699. @@ -400,28 +401,19 @@ COMMON_SYSDEP void __cilkrts_sleep(void)
  700. COMMON_SYSDEP void __cilkrts_yield(void)
  701. {
  702. -#if __APPLE__ || __FreeBSD__ || __VXWORKS__
  703. - // On MacOS, call sched_yield to yield quantum. I'm not sure why we
  704. - // don't do this on Linux also.
  705. - sched_yield();
  706. -#elif defined(__DragonFly__)
  707. - // On DragonFly BSD, call sched_yield to yield quantum.
  708. - sched_yield();
  709. -#elif defined(__MIC__)
  710. +#if defined(__MIC__)
  711. // On MIC, pthread_yield() really trashes things. Arch's measurements
  712. // showed that calling _mm_delay_32() (or doing nothing) was a better
  713. // option. Delaying 1024 clock cycles is a reasonable compromise between
  714. // giving up the processor and latency starting up when work becomes
  715. // available
  716. _mm_delay_32(1024);
  717. -#elif defined(__ANDROID__) || (defined(__sun__) && defined(__svr4__))
  718. - // On Android and Solaris, call sched_yield to yield quantum. I'm not
  719. - // sure why we don't do this on Linux also.
  720. - sched_yield();
  721. -#else
  722. - // On Linux, call pthread_yield (which in turn will call sched_yield)
  723. - // to yield quantum.
  724. +#elif defined(__sun__) && !defined(__svr4__)
  725. + // On old SunOS call pthread_yield to yield a quantum.
  726. pthread_yield();
  727. +#else
  728. + // On other platforms call sched_yield to yield a quantum.
  729. + sched_yield();
  730. #endif
  731. }
  732. diff --git a/libgcc/unwind-dw2-fde-dip.c b/libgcc/unwind-dw2-fde-dip.c
  733. index e1e566b..137dced 100644
  734. --- a/libgcc/unwind-dw2-fde-dip.c
  735. +++ b/libgcc/unwind-dw2-fde-dip.c
  736. @@ -59,6 +59,12 @@
  737. #if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
  738. && defined(TARGET_DL_ITERATE_PHDR) \
  739. + && defined(__linux__)
  740. +# define USE_PT_GNU_EH_FRAME
  741. +#endif
  742. +
  743. +#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
  744. + && defined(TARGET_DL_ITERATE_PHDR) \
  745. && (defined(__DragonFly__) || defined(__FreeBSD__))
  746. # define ElfW __ElfN
  747. # define USE_PT_GNU_EH_FRAME
  748. diff --git a/libgfortran/acinclude.m4 b/libgfortran/acinclude.m4
  749. index ba890f9..30b8b1a6 100644
  750. --- a/libgfortran/acinclude.m4
  751. +++ b/libgfortran/acinclude.m4
  752. @@ -100,7 +100,7 @@ void foo (void);
  753. [Define to 1 if the target supports #pragma weak])
  754. fi
  755. case "$host" in
  756. - *-*-darwin* | *-*-hpux* | *-*-cygwin* | *-*-mingw* )
  757. + *-*-darwin* | *-*-hpux* | *-*-cygwin* | *-*-mingw* | *-*-musl* )
  758. AC_DEFINE(GTHREAD_USE_WEAK, 0,
  759. [Define to 0 if the target shouldn't use #pragma weak])
  760. ;;
  761. diff --git a/libgfortran/configure b/libgfortran/configure
  762. index e1592f7..07542e1 100755
  763. --- a/libgfortran/configure
  764. +++ b/libgfortran/configure
  765. @@ -26447,7 +26447,7 @@ $as_echo "#define SUPPORTS_WEAK 1" >>confdefs.h
  766. fi
  767. case "$host" in
  768. - *-*-darwin* | *-*-hpux* | *-*-cygwin* | *-*-mingw* )
  769. + *-*-darwin* | *-*-hpux* | *-*-cygwin* | *-*-mingw* | *-*-musl* )
  770. $as_echo "#define GTHREAD_USE_WEAK 0" >>confdefs.h
  771. diff --git a/libitm/config/arm/hwcap.cc b/libitm/config/arm/hwcap.cc
  772. index a1c2cfd..ea8f023 100644
  773. --- a/libitm/config/arm/hwcap.cc
  774. +++ b/libitm/config/arm/hwcap.cc
  775. @@ -40,7 +40,7 @@ int GTM_hwcap HIDDEN = 0
  776. #ifdef __linux__
  777. #include <unistd.h>
  778. -#include <sys/fcntl.h>
  779. +#include <fcntl.h>
  780. #include <elf.h>
  781. static void __attribute__((constructor))
  782. diff --git a/libitm/config/linux/x86/tls.h b/libitm/config/linux/x86/tls.h
  783. index e731ab7..54ad8b6 100644
  784. --- a/libitm/config/linux/x86/tls.h
  785. +++ b/libitm/config/linux/x86/tls.h
  786. @@ -25,16 +25,19 @@
  787. #ifndef LIBITM_X86_TLS_H
  788. #define LIBITM_X86_TLS_H 1
  789. -#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
  790. +#if defined(__GLIBC_PREREQ)
  791. +#if __GLIBC_PREREQ(2, 10)
  792. /* Use slots in the TCB head rather than __thread lookups.
  793. GLIBC has reserved words 10 through 13 for TM. */
  794. #define HAVE_ARCH_GTM_THREAD 1
  795. #define HAVE_ARCH_GTM_THREAD_DISP 1
  796. #endif
  797. +#endif
  798. #include "config/generic/tls.h"
  799. -#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
  800. +#if defined(__GLIBC_PREREQ)
  801. +#if __GLIBC_PREREQ(2, 10)
  802. namespace GTM HIDDEN {
  803. #ifdef __x86_64__
  804. @@ -101,5 +104,6 @@ static inline void set_abi_disp(struct abi_dispatch *x)
  805. } // namespace GTM
  806. #endif /* >= GLIBC 2.10 */
  807. +#endif
  808. #endif // LIBITM_X86_TLS_H
  809. diff --git a/libstdc++-v3/config/os/generic/os_defines.h b/libstdc++-v3/config/os/generic/os_defines.h
  810. index 45bf52a..103ec0e 100644
  811. --- a/libstdc++-v3/config/os/generic/os_defines.h
  812. +++ b/libstdc++-v3/config/os/generic/os_defines.h
  813. @@ -33,4 +33,9 @@
  814. // System-specific #define, typedefs, corrections, etc, go here. This
  815. // file will come before all others.
  816. +// Disable the weak reference logic in gthr.h for os/generic because it
  817. +// is broken on every platform unless there is implementation specific
  818. +// workaround in gthr-posix.h and at link-time for static linking.
  819. +#define _GLIBCXX_GTHREAD_USE_WEAK 0
  820. +
  821. #endif
  822. diff --git a/libstdc++-v3/configure.host b/libstdc++-v3/configure.host
  823. index 640199c..106134e 100644
  824. --- a/libstdc++-v3/configure.host
  825. +++ b/libstdc++-v3/configure.host
  826. @@ -273,6 +273,9 @@ case "${host_os}" in
  827. freebsd*)
  828. os_include_dir="os/bsd/freebsd"
  829. ;;
  830. + linux-musl*)
  831. + os_include_dir="os/generic"
  832. + ;;
  833. gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu)
  834. if [ "$uclibc" = "yes" ]; then
  835. os_include_dir="os/uclibc"