200-musl.patch 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. diff --git a/gcc/config.gcc b/gcc/config.gcc
  2. --- a/gcc/config.gcc
  3. +++ b/gcc/config.gcc
  4. @@ -522,7 +522,7 @@
  5. esac
  6. # Common C libraries.
  7. -tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3"
  8. +tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3 LIBC_MUSL=4"
  9. # Common parts for widely ported systems.
  10. case ${target} in
  11. @@ -625,6 +625,9 @@
  12. *-*-*uclibc*)
  13. tm_defines="$tm_defines DEFAULT_LIBC=LIBC_UCLIBC"
  14. ;;
  15. + *-*-*musl*)
  16. + tm_defines="$tm_defines DEFAULT_LIBC=LIBC_MUSL"
  17. + ;;
  18. *)
  19. tm_defines="$tm_defines DEFAULT_LIBC=LIBC_GLIBC"
  20. ;;
  21. @@ -1722,6 +1725,7 @@
  22. tm_file="${tm_file} dbxelf.h gnu-user.h linux.h microblaze/linux.h"
  23. c_target_objs="${c_target_objs} microblaze-c.o"
  24. cxx_target_objs="${cxx_target_objs} microblaze-c.o"
  25. + tmake_file="${tmake_file} microblaze/t-microblaze"
  26. ;;
  27. microblaze*-*-*)
  28. tm_file="${tm_file} dbxelf.h"
  29. diff --git a/gcc/config/arm/linux-eabi.h b/gcc/config/arm/linux-eabi.h
  30. --- a/gcc/config/arm/linux-eabi.h
  31. +++ b/gcc/config/arm/linux-eabi.h
  32. @@ -64,6 +64,10 @@
  33. #undef GLIBC_DYNAMIC_LINKER
  34. #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.3"
  35. +/* musl has no "classic" (i.e. broken) mode */
  36. +#undef MUSL_DYNAMIC_LINKER
  37. +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-arm.so.1"
  38. +
  39. /* At this point, bpabi.h will have clobbered LINK_SPEC. We want to
  40. use the GNU/Linux version, not the generic BPABI version. */
  41. #undef LINK_SPEC
  42. diff --git a/gcc/config/i386/linux.h b/gcc/config/i386/linux.h
  43. --- a/gcc/config/i386/linux.h
  44. +++ b/gcc/config/i386/linux.h
  45. @@ -22,3 +22,4 @@
  46. #define GNU_USER_LINK_EMULATION "elf_i386"
  47. #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
  48. +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-i386.so.1"
  49. diff --git a/gcc/config/i386/linux64.h b/gcc/config/i386/linux64.h
  50. --- a/gcc/config/i386/linux64.h
  51. +++ b/gcc/config/i386/linux64.h
  52. @@ -31,3 +31,7 @@
  53. #define GLIBC_DYNAMIC_LINKER32 "/lib/ld-linux.so.2"
  54. #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-linux-x86-64.so.2"
  55. #define GLIBC_DYNAMIC_LINKERX32 "/libx32/ld-linux-x32.so.2"
  56. +
  57. +#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-i386.so.1"
  58. +#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-x86_64.so.1"
  59. +#define MUSL_DYNAMIC_LINKERX32 "/lib/ld-musl-x32.so.1"
  60. diff --git a/gcc/config/linux.h b/gcc/config/linux.h
  61. --- a/gcc/config/linux.h
  62. +++ b/gcc/config/linux.h
  63. @@ -33,10 +33,12 @@
  64. #define OPTION_GLIBC (DEFAULT_LIBC == LIBC_GLIBC)
  65. #define OPTION_UCLIBC (DEFAULT_LIBC == LIBC_UCLIBC)
  66. #define OPTION_BIONIC (DEFAULT_LIBC == LIBC_BIONIC)
  67. +#define OPTION_MUSL (DEFAULT_LIBC == LIBC_MUSL)
  68. #else
  69. #define OPTION_GLIBC (linux_libc == LIBC_GLIBC)
  70. #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
  71. #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
  72. +#define OPTION_MUSL (linux_libc == LIBC_MUSL)
  73. #endif
  74. #define GNU_USER_TARGET_OS_CPP_BUILTINS() \
  75. @@ -54,18 +56,21 @@
  76. uClibc or Bionic is the default C library and whether
  77. -muclibc or -mglibc or -mbionic has been passed to change the default. */
  78. -#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LD1, LD2, LD3) \
  79. - "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:" LD1 "}}"
  80. +#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LIBC4, LD1, LD2, LD3, LD4) \
  81. + "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:%{" LIBC4 ":" LD4 ";:" LD1 "}}}"
  82. #if DEFAULT_LIBC == LIBC_GLIBC
  83. -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
  84. - CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", G, U, B)
  85. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  86. + CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", "mmusl", G, U, B, M)
  87. #elif DEFAULT_LIBC == LIBC_UCLIBC
  88. -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
  89. - CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", U, G, B)
  90. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  91. + CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", "mmusl", U, G, B, M)
  92. #elif DEFAULT_LIBC == LIBC_BIONIC
  93. -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
  94. - CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", B, G, U)
  95. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  96. + CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", "mmusl", B, G, U, M)
  97. +#elif DEFAULT_LIBC == LIBC_MUSL
  98. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  99. + CHOOSE_DYNAMIC_LINKER1 ("mmusl", "mglibc", "muclibc", "mbionic", M, G, U, B)
  100. #else
  101. #error "Unsupported DEFAULT_LIBC"
  102. #endif /* DEFAULT_LIBC */
  103. @@ -85,16 +90,16 @@
  104. #define GNU_USER_DYNAMIC_LINKER \
  105. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, \
  106. - BIONIC_DYNAMIC_LINKER)
  107. + BIONIC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
  108. #define GNU_USER_DYNAMIC_LINKER32 \
  109. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, \
  110. - BIONIC_DYNAMIC_LINKER32)
  111. + BIONIC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
  112. #define GNU_USER_DYNAMIC_LINKER64 \
  113. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
  114. - BIONIC_DYNAMIC_LINKER64)
  115. + BIONIC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
  116. #define GNU_USER_DYNAMIC_LINKERX32 \
  117. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \
  118. - BIONIC_DYNAMIC_LINKERX32)
  119. + BIONIC_DYNAMIC_LINKERX32, MUSL_DYNAMIC_LINKERX32)
  120. /* Determine whether the entire c99 runtime
  121. is present in the runtime library. */
  122. diff --git a/gcc/config/linux.opt b/gcc/config/linux.opt
  123. --- a/gcc/config/linux.opt
  124. +++ b/gcc/config/linux.opt
  125. @@ -30,3 +30,7 @@
  126. muclibc
  127. Target Report RejectNegative Var(linux_libc,LIBC_UCLIBC) Negative(mbionic)
  128. Use uClibc C library
  129. +
  130. +mmusl
  131. +Target Report RejectNegative Var(linux_libc,LIBC_MUSL) Negative(mglibc)
  132. +Use musl C library
  133. diff --git a/gcc/config/mips/linux.h b/gcc/config/mips/linux.h
  134. --- a/gcc/config/mips/linux.h
  135. +++ b/gcc/config/mips/linux.h
  136. @@ -19,3 +19,5 @@
  137. <http://www.gnu.org/licenses/>. */
  138. #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
  139. +
  140. +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-mips.so.1"
  141. diff --git a/gcc/config/rs6000/linux64.h b/gcc/config/rs6000/linux64.h
  142. --- a/gcc/config/rs6000/linux64.h
  143. +++ b/gcc/config/rs6000/linux64.h
  144. @@ -362,17 +362,21 @@
  145. #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld64.so.1"
  146. #define UCLIBC_DYNAMIC_LINKER32 "/lib/ld-uClibc.so.0"
  147. #define UCLIBC_DYNAMIC_LINKER64 "/lib/ld64-uClibc.so.0"
  148. +#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-powerpc.so.1"
  149. +#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-powerpc64.so.1"
  150. #if DEFAULT_LIBC == LIBC_UCLIBC
  151. -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
  152. +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
  153. #elif DEFAULT_LIBC == LIBC_GLIBC
  154. -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
  155. +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
  156. +#elif DEFAULT_LIBC == LIBC_MUSL
  157. +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
  158. #else
  159. #error "Unsupported DEFAULT_LIBC"
  160. #endif
  161. #define GNU_USER_DYNAMIC_LINKER32 \
  162. - CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32)
  163. + CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
  164. #define GNU_USER_DYNAMIC_LINKER64 \
  165. - CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64)
  166. + CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
  167. #define LINK_OS_LINUX_SPEC32 "-m elf32ppclinux %{!shared: %{!static: \
  168. diff --git a/gcc/config/rs6000/sysv4.h b/gcc/config/rs6000/sysv4.h
  169. --- a/gcc/config/rs6000/sysv4.h
  170. +++ b/gcc/config/rs6000/sysv4.h
  171. @@ -804,15 +804,18 @@
  172. #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
  173. #define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0"
  174. +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-powerpc.so.1"
  175. #if DEFAULT_LIBC == LIBC_UCLIBC
  176. -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
  177. +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
  178. +#elif DEFAULT_LIBC == LIBC_MUSL
  179. +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
  180. #elif !defined (DEFAULT_LIBC) || DEFAULT_LIBC == LIBC_GLIBC
  181. -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
  182. +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
  183. #else
  184. #error "Unsupported DEFAULT_LIBC"
  185. #endif
  186. #define GNU_USER_DYNAMIC_LINKER \
  187. - CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER)
  188. + CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
  189. #define LINK_OS_LINUX_SPEC "-m elf32ppclinux %{!shared: %{!static: \
  190. %{rdynamic:-export-dynamic} \
  191. diff --git a/gcc/ginclude/stddef.h b/gcc/ginclude/stddef.h
  192. --- a/gcc/ginclude/stddef.h
  193. +++ b/gcc/ginclude/stddef.h
  194. @@ -184,6 +184,7 @@
  195. #ifndef _GCC_SIZE_T
  196. #ifndef _SIZET_
  197. #ifndef __size_t
  198. +#ifndef __DEFINED_size_t /* musl */
  199. #define __size_t__ /* BeOS */
  200. #define __SIZE_T__ /* Cray Unicos/Mk */
  201. #define _SIZE_T
  202. @@ -200,6 +201,7 @@
  203. #define ___int_size_t_h
  204. #define _GCC_SIZE_T
  205. #define _SIZET_
  206. +#define __DEFINED_size_t /* musl */
  207. #if (defined (__FreeBSD__) && (__FreeBSD__ >= 5)) \
  208. || defined(__FreeBSD_kernel__)
  209. /* __size_t is a typedef on FreeBSD 5, must not trash it. */
  210. @@ -215,6 +217,7 @@
  211. typedef long ssize_t;
  212. #endif /* __BEOS__ */
  213. #endif /* !(defined (__GNUG__) && defined (size_t)) */
  214. +#endif /* __DEFINED_size_t */
  215. #endif /* __size_t */
  216. #endif /* _SIZET_ */
  217. #endif /* _GCC_SIZE_T */
  218. diff --git a/libgomp/config/posix/time.c b/libgomp/config/posix/time.c
  219. --- a/libgomp/config/posix/time.c
  220. +++ b/libgomp/config/posix/time.c
  221. @@ -28,6 +28,8 @@
  222. The following implementation uses the most simple POSIX routines.
  223. If present, POSIX 4 clocks should be used instead. */
  224. +#define _POSIX_C_SOURCE 199309L /* for clocks */
  225. +
  226. #include "libgomp.h"
  227. #include <unistd.h>
  228. #if TIME_WITH_SYS_TIME
  229. diff --git a/libitm/config/arm/hwcap.cc b/libitm/config/arm/hwcap.cc
  230. --- a/libitm/config/arm/hwcap.cc
  231. +++ b/libitm/config/arm/hwcap.cc
  232. @@ -40,7 +40,11 @@
  233. #ifdef __linux__
  234. #include <unistd.h>
  235. +#ifdef __GLIBC__
  236. #include <sys/fcntl.h>
  237. +#else
  238. +#include <fcntl.h>
  239. +#endif
  240. #include <elf.h>
  241. static void __attribute__((constructor))
  242. diff --git a/libitm/config/linux/x86/tls.h b/libitm/config/linux/x86/tls.h
  243. --- a/libitm/config/linux/x86/tls.h
  244. +++ b/libitm/config/linux/x86/tls.h
  245. @@ -25,16 +25,19 @@
  246. #ifndef LIBITM_X86_TLS_H
  247. #define LIBITM_X86_TLS_H 1
  248. -#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
  249. +#if defined(__GLIBC_PREREQ)
  250. +#if __GLIBC_PREREQ(2, 10)
  251. /* Use slots in the TCB head rather than __thread lookups.
  252. GLIBC has reserved words 10 through 13 for TM. */
  253. #define HAVE_ARCH_GTM_THREAD 1
  254. #define HAVE_ARCH_GTM_THREAD_DISP 1
  255. #endif
  256. +#endif
  257. #include "config/generic/tls.h"
  258. -#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
  259. +#if defined(__GLIBC_PREREQ)
  260. +#if __GLIBC_PREREQ(2, 10)
  261. namespace GTM HIDDEN {
  262. #ifdef __x86_64__
  263. @@ -101,5 +104,6 @@
  264. } // namespace GTM
  265. #endif /* >= GLIBC 2.10 */
  266. +#endif
  267. #endif // LIBITM_X86_TLS_H
  268. diff --git a/libstdc++-v3/configure.host b/libstdc++-v3/configure.host
  269. --- a/libstdc++-v3/configure.host
  270. +++ b/libstdc++-v3/configure.host
  271. @@ -243,6 +243,13 @@
  272. os_include_dir="os/bsd/freebsd"
  273. ;;
  274. gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu)
  275. + # check for musl by target
  276. + case "${host_os}" in
  277. + *-musl*)
  278. + os_include_dir="os/generic"
  279. + ;;
  280. + *)
  281. +
  282. if [ "$uclibc" = "yes" ]; then
  283. os_include_dir="os/uclibc"
  284. elif [ "$bionic" = "yes" ]; then
  285. @@ -251,6 +258,9 @@
  286. os_include_dir="os/gnu-linux"
  287. fi
  288. ;;
  289. +
  290. + esac
  291. + ;;
  292. hpux*)
  293. os_include_dir="os/hpux"
  294. ;;