0001-musl.diff 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. diff --git a/config.sub b/config.sub
  2. index fab0aa3..b83660a 100755
  3. --- a/config.sub
  4. +++ b/config.sub
  5. @@ -120,7 +120,7 @@ esac
  6. # Here we must recognize all the valid KERNEL-OS combinations.
  7. maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
  8. case $maybe_os in
  9. - nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \
  10. + nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | linux-musl* | \
  11. uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \
  12. storm-chaos* | os2-emx* | rtmk-nova*)
  13. os=-$maybe_os
  14. @@ -1211,7 +1211,7 @@ case $os in
  15. | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
  16. | -chorusos* | -chorusrdb* \
  17. | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
  18. - | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \
  19. + | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* | -linux-musl* \
  20. | -uxpv* | -beos* | -mpeix* | -udk* \
  21. | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
  22. | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
  23. diff --git a/fixincludes/mkfixinc.sh b/fixincludes/mkfixinc.sh
  24. index ef048f7..f1cb8a5 100755
  25. --- a/fixincludes/mkfixinc.sh
  26. +++ b/fixincludes/mkfixinc.sh
  27. @@ -28,7 +28,8 @@ case $machine in
  28. powerpc-*-eabi* | \
  29. powerpc-*-rtems* | \
  30. powerpcle-*-eabisim* | \
  31. - powerpcle-*-eabi* )
  32. + powerpcle-*-eabi* | \
  33. + *-musl* )
  34. # IF there is no include fixing,
  35. # THEN create a no-op fixer and exit
  36. (echo "#! /bin/sh" ; echo "exit 0" ) > ${target}
  37. diff --git a/gcc/config.gcc b/gcc/config.gcc
  38. index 9a142e2..25136b7 100644
  39. --- a/gcc/config.gcc
  40. +++ b/gcc/config.gcc
  41. @@ -468,11 +468,14 @@ case ${target} in
  42. esac
  43. tmake_file="t-slibgcc-elf-ver t-linux"
  44. case ${target} in
  45. + *-*-*musl*)
  46. + tm_defines="${tm_defines} UCLIBC_DEFAULT=0 MUSL_DEFAULT=1"
  47. + ;;
  48. *-*-*uclibc*)
  49. - tm_defines="${tm_defines} UCLIBC_DEFAULT=1"
  50. + tm_defines="${tm_defines} UCLIBC_DEFAULT=1 MUSL_DEFAULT=0"
  51. ;;
  52. *)
  53. - tm_defines="${tm_defines} UCLIBC_DEFAULT=0"
  54. + tm_defines="${tm_defines} UCLIBC_DEFAULT=0 MUSL_DEFAULT=0"
  55. ;;
  56. esac
  57. # Assume that glibc or uClibc are being used and so __cxa_atexit is provided.
  58. diff --git a/gcc/config/arm/linux-eabi.h b/gcc/config/arm/linux-eabi.h
  59. index 6612f74..f2ce735 100644
  60. --- a/gcc/config/arm/linux-eabi.h
  61. +++ b/gcc/config/arm/linux-eabi.h
  62. @@ -55,6 +55,23 @@
  63. #undef GLIBC_DYNAMIC_LINKER
  64. #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.3"
  65. +/* For ARM musl currently supports four dynamic linkers:
  66. + - ld-musl-arm.so.1 - for the EABI-derived soft-float ABI
  67. + - ld-musl-armhf.so.1 - for the EABI-derived hard-float ABI
  68. + - ld-musl-armeb.so.1 - for the EABI-derived soft-float ABI, EB
  69. + - ld-musl-armebhf.so.1 - for the EABI-derived hard-float ABI, EB
  70. + musl does not support the legacy OABI mode.
  71. + All the dynamic linkers live in /lib.
  72. + We default to soft-float, EL. */
  73. +#undef MUSL_DYNAMIC_LINKER
  74. +#if TARGET_BIG_ENDIAN_DEFAULT
  75. +#define MUSL_DYNAMIC_LINKER_E "%{mlittle-endian:;:eb}"
  76. +#else
  77. +#define MUSL_DYNAMIC_LINKER_E "%{mbig-endian:eb}"
  78. +#endif
  79. +#define MUSL_DYNAMIC_LINKER \
  80. + "/lib/ld-musl-arm" MUSL_DYNAMIC_LINKER_E "%{mfloat-abi=hard:hf}.so.1"
  81. +
  82. /* At this point, bpabi.h will have clobbered LINK_SPEC. We want to
  83. use the GNU/Linux version, not the generic BPABI version. */
  84. #undef LINK_SPEC
  85. diff --git a/gcc/config/i386/linux.h b/gcc/config/i386/linux.h
  86. index 7eb2395..213b586 100644
  87. --- a/gcc/config/i386/linux.h
  88. +++ b/gcc/config/i386/linux.h
  89. @@ -103,6 +103,9 @@ Boston, MA 02110-1301, USA. */
  90. #define LINK_EMULATION "elf_i386"
  91. #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
  92. +#undef MUSL_DYNAMIC_LINKER
  93. +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-i386.so.1"
  94. +
  95. #undef SUBTARGET_EXTRA_SPECS
  96. #define SUBTARGET_EXTRA_SPECS \
  97. { "link_emulation", LINK_EMULATION },\
  98. diff --git a/gcc/config/i386/linux64.h b/gcc/config/i386/linux64.h
  99. index cc8ed16..f0f025e 100644
  100. --- a/gcc/config/i386/linux64.h
  101. +++ b/gcc/config/i386/linux64.h
  102. @@ -52,6 +52,13 @@ Boston, MA 02110-1301, USA. */
  103. #define GLIBC_DYNAMIC_LINKER32 "/lib/ld-linux.so.2"
  104. #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-linux-x86-64.so.2"
  105. +#undef MUSL_DYNAMIC_LINKER32
  106. +#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-i386.so.1"
  107. +#undef MUSL_DYNAMIC_LINKER64
  108. +#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-x86_64.so.1"
  109. +#undef MUSL_DYNAMIC_LINKERX32
  110. +#define MUSL_DYNAMIC_LINKERX32 "/lib/ld-musl-x32.so.1"
  111. +
  112. #undef LINK_SPEC
  113. #define LINK_SPEC "%{!m32:-m elf_x86_64} %{m32:-m elf_i386} \
  114. %{shared:-shared} \
  115. diff --git a/gcc/config/linux.h b/gcc/config/linux.h
  116. index 59e3e85..1967b46 100644
  117. --- a/gcc/config/linux.h
  118. +++ b/gcc/config/linux.h
  119. @@ -102,10 +102,12 @@ Boston, MA 02110-1301, USA. */
  120. /* Determine which dynamic linker to use depending on whether GLIBC or
  121. uClibc is the default C library and whether -muclibc or -mglibc has
  122. been passed to change the default. */
  123. -#if UCLIBC_DEFAULT
  124. -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:%{muclibc:%e-mglibc and -muclibc used together}" G ";:" U "}"
  125. +#if MUSL_DEFAULT
  126. +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";muclibc:" U ";:" M "}"
  127. +#elif UCLIBC_DEFAULT
  128. +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";mmusl:" M ";:" U "}"
  129. #else
  130. -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:%{mglibc:%e-mglibc and -muclibc used together}" U ";:" G "}"
  131. +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mmusl:" M ";muclibc:" U ";:" G "}"
  132. #endif
  133. /* For most targets the following definitions suffice;
  134. @@ -115,15 +117,89 @@ Boston, MA 02110-1301, USA. */
  135. #define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0"
  136. #define UCLIBC_DYNAMIC_LINKER32 "/lib/ld-uClibc.so.0"
  137. #define UCLIBC_DYNAMIC_LINKER64 "/lib/ld64-uClibc.so.0"
  138. +/* Should be redefined for each target that supports musl. */
  139. +#define MUSL_DYNAMIC_LINKER "/dev/null"
  140. +#define MUSL_DYNAMIC_LINKER32 "/dev/null"
  141. +#define MUSL_DYNAMIC_LINKER64 "/dev/null"
  142. +#define MUSL_DYNAMIC_LINKERX32 "/dev/null"
  143. +
  144. #define LINUX_DYNAMIC_LINKER \
  145. - CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER)
  146. + CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
  147. #define LINUX_DYNAMIC_LINKER32 \
  148. - CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32)
  149. + CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
  150. #define LINUX_DYNAMIC_LINKER64 \
  151. - CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64)
  152. + CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
  153. /* Determine whether the entire c99 runtime
  154. is present in the runtime library. */
  155. #define TARGET_C99_FUNCTIONS (OPTION_GLIBC)
  156. #define TARGET_POSIX_IO
  157. +
  158. +/* musl avoids problematic includes by rearranging the include directories.
  159. + * Unfortunately, this is mostly duplicated from cppdefault.c */
  160. +#if MUSL_DEFAULT
  161. +#define INCLUDE_DEFAULTS_MUSL_GPP \
  162. + { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, 0, 0 }, \
  163. + { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1, 0, 1 }, \
  164. + { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1, 0, 0 },
  165. +
  166. +#ifdef LOCAL_INCLUDE_DIR
  167. +#define INCLUDE_DEFAULTS_MUSL_LOCAL \
  168. + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 }, \
  169. + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 },
  170. +#else
  171. +#define INCLUDE_DEFAULTS_MUSL_LOCAL
  172. +#endif
  173. +
  174. +#ifdef PREFIX_INCLUDE_DIR
  175. +#define INCLUDE_DEFAULTS_MUSL_PREFIX \
  176. + { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0},
  177. +#else
  178. +#define INCLUDE_DEFAULTS_MUSL_PREFIX
  179. +#endif
  180. +
  181. +#ifdef CROSS_INCLUDE_DIR
  182. +#define INCLUDE_DEFAULTS_MUSL_CROSS \
  183. + { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0},
  184. +#else
  185. +#define INCLUDE_DEFAULTS_MUSL_CROSS
  186. +#endif
  187. +
  188. +#ifdef TOOL_INCLUDE_DIR
  189. +#define INCLUDE_DEFAULTS_MUSL_TOOL \
  190. + { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0},
  191. +#else
  192. +#define INCLUDE_DEFAULTS_MUSL_TOOL
  193. +#endif
  194. +
  195. +#ifdef NATIVE_SYSTEM_HEADER_DIR
  196. +#define INCLUDE_DEFAULTS_MUSL_NATIVE \
  197. + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 2 }, \
  198. + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 0 },
  199. +#else
  200. +#define INCLUDE_DEFAULTS_MUSL_NATIVE
  201. +#endif
  202. +
  203. +#if defined (CROSS_DIRECTORY_STRUCTURE) && !defined (TARGET_SYSTEM_ROOT)
  204. +# undef INCLUDE_DEFAULTS_MUSL_LOCAL
  205. +# define INCLUDE_DEFAULTS_MUSL_LOCAL
  206. +# undef INCLUDE_DEFAULTS_MUSL_NATIVE
  207. +# define INCLUDE_DEFAULTS_MUSL_NATIVE
  208. +#else
  209. +# undef INCLUDE_DEFAULTS_MUSL_CROSS
  210. +# define INCLUDE_DEFAULTS_MUSL_CROSS
  211. +#endif
  212. +
  213. +#undef INCLUDE_DEFAULTS
  214. +#define INCLUDE_DEFAULTS \
  215. + { \
  216. + INCLUDE_DEFAULTS_MUSL_GPP \
  217. + INCLUDE_DEFAULTS_MUSL_PREFIX \
  218. + INCLUDE_DEFAULTS_MUSL_CROSS \
  219. + INCLUDE_DEFAULTS_MUSL_TOOL \
  220. + INCLUDE_DEFAULTS_MUSL_NATIVE \
  221. + { GCC_INCLUDE_DIR, "GCC", 0, 1, 0, 0 }, \
  222. + { 0, 0, 0, 0, 0, 0 } \
  223. + }
  224. +#endif
  225. diff --git a/gcc/config/linux.opt b/gcc/config/linux.opt
  226. index 3f615bb..31fb21b 100644
  227. --- a/gcc/config/linux.opt
  228. +++ b/gcc/config/linux.opt
  229. @@ -27,3 +27,7 @@ Use uClibc instead of GNU libc
  230. mglibc
  231. Target RejectNegative Report InverseMask(UCLIBC, GLIBC) Var(linux_uclibc) VarExists
  232. Use GNU libc instead of uClibc
  233. +
  234. +mmusl
  235. +Target RejectNegative Report Var(linux_musl)
  236. +Use musl C library
  237. diff --git a/gcc/config/mips/linux.h b/gcc/config/mips/linux.h
  238. index ff268d4..97bfc38 100644
  239. --- a/gcc/config/mips/linux.h
  240. +++ b/gcc/config/mips/linux.h
  241. @@ -179,3 +179,9 @@ Boston, MA 02110-1301, USA. */
  242. %{profile:-lc_p} %{!profile: -lc}}"
  243. #define MD_UNWIND_SUPPORT "config/mips/linux-unwind.h"
  244. +
  245. +#undef MUSL_DYNAMIC_LINKER32
  246. +#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-mips%{EL:el}%{msoft-float:-sf}.so.1"
  247. +#undef MUSL_DYNAMIC_LINKER64
  248. +#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-mips64%{EL:el}%{msoft-float:-sf}.so.1"
  249. +#define MUSL_DYNAMIC_LINKERN32 "/lib/ld-musl-mipsn32%{EL:el}%{msoft-float:-sf}.so.1"
  250. diff --git a/gcc/config/sh/linux-unwind.h b/gcc/config/sh/linux-unwind.h
  251. index de84a77..98d1661 100644
  252. --- a/gcc/config/sh/linux-unwind.h
  253. +++ b/gcc/config/sh/linux-unwind.h
  254. @@ -80,10 +80,10 @@ shmedia_fallback_frame_state (struct _Unwind_Context *context,
  255. && (*(unsigned long *) (pc+11) == 0x6ff0fff0))
  256. {
  257. struct rt_sigframe {
  258. - struct siginfo *pinfo;
  259. + siginfo_t *pinfo;
  260. void *puc;
  261. - struct siginfo info;
  262. - struct ucontext uc;
  263. + siginfo_t info;
  264. + ucontext_t uc;
  265. } *rt_ = context->cfa;
  266. /* The void * cast is necessary to avoid an aliasing warning.
  267. The aliasing warning is correct, but should not be a problem
  268. @@ -179,8 +179,8 @@ sh_fallback_frame_state (struct _Unwind_Context *context,
  269. && (*(unsigned short *) (pc+14) == 0x00ad))))
  270. {
  271. struct rt_sigframe {
  272. - struct siginfo info;
  273. - struct ucontext uc;
  274. + siginfo_t info;
  275. + ucontext_t uc;
  276. } *rt_ = context->cfa;
  277. /* The void * cast is necessary to avoid an aliasing warning.
  278. The aliasing warning is correct, but should not be a problem
  279. diff --git a/gcc/config/sh/linux.h b/gcc/config/sh/linux.h
  280. index 94c3166..306a08c 100644
  281. --- a/gcc/config/sh/linux.h
  282. +++ b/gcc/config/sh/linux.h
  283. @@ -48,6 +48,29 @@ Boston, MA 02110-1301, USA. */
  284. #define TARGET_ASM_FILE_END file_end_indicate_exec_stack
  285. +#if TARGET_ENDIAN_DEFAULT == MASK_LITTLE_ENDIAN
  286. +#define MUSL_DYNAMIC_LINKER_E "%{mb:eb}"
  287. +#else
  288. +#define MUSL_DYNAMIC_LINKER_E "%{!ml:eb}"
  289. +#endif
  290. +
  291. +#if TARGET_CPU_DEFAULT & ( MASK_HARD_SH2A_DOUBLE | MASK_SH4 )
  292. +/* "-nofpu" if any nofpu option is specified */
  293. +#define MUSL_DYNAMIC_LINKER_FP \
  294. + "%{m1|m2|m2a-nofpu|m3|m4-nofpu|m4-100-nofpu|m4-200-nofpu|m4-300-nofpu|" \
  295. + "m4-340|m4-400|m4-500|m4al|m5-32media-nofpu|m5-64media-nofpu|" \
  296. + "m5-compact-nofpu:-nofpu}"
  297. +#else
  298. +/* "-nofpu" if none of the hard fpu options are specified */
  299. +#define MUSL_DYNAMIC_LINKER_FP \
  300. + "%{m2a|m4|m4-100|m4-200|m4-300|m4a|m5-32media|m5-64media|m5-compact:;:-nofpu}"
  301. +#endif
  302. +
  303. +#undef MUSL_DYNAMIC_LINKER
  304. +#define MUSL_DYNAMIC_LINKER \
  305. + "/lib/ld-musl-sh" MUSL_DYNAMIC_LINKER_E MUSL_DYNAMIC_LINKER_FP \
  306. + "%{mfdpic:-fdpic}.so.1"
  307. +
  308. #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
  309. #undef SUBTARGET_LINK_EMUL_SUFFIX
  310. diff --git a/gcc/unwind-dw2-fde-glibc.c b/gcc/unwind-dw2-fde-glibc.c
  311. index 25bf2bb..59f7615 100644
  312. --- a/gcc/unwind-dw2-fde-glibc.c
  313. +++ b/gcc/unwind-dw2-fde-glibc.c
  314. @@ -49,7 +49,7 @@
  315. #include "gthr.h"
  316. #if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
  317. - && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) \
  318. + && (!defined(__GLIBC__) || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) \
  319. || (__GLIBC__ == 2 && __GLIBC_MINOR__ == 2 && defined(DT_CONFIG)))
  320. #ifndef __RELOC_POINTER
  321. diff --git a/libstdc++-v3/config/os/generic/os_defines.h b/libstdc++-v3/config/os/generic/os_defines.h
  322. index bcc533c..a9bfded 100644
  323. --- a/libstdc++-v3/config/os/generic/os_defines.h
  324. +++ b/libstdc++-v3/config/os/generic/os_defines.h
  325. @@ -38,4 +38,9 @@
  326. // System-specific #define, typedefs, corrections, etc, go here. This
  327. // file will come before all others.
  328. +// Disable the weak reference logic in gthr.h for os/generic because it
  329. +// is broken on every platform unless there is implementation specific
  330. +// workaround in gthr-posix.h and at link-time for static linking.
  331. +#define _GLIBCXX_GTHREAD_USE_WEAK 0
  332. +
  333. #endif
  334. diff --git a/libstdc++-v3/configure.host b/libstdc++-v3/configure.host
  335. index 441eb4c..37e80ab 100644
  336. --- a/libstdc++-v3/configure.host
  337. +++ b/libstdc++-v3/configure.host
  338. @@ -210,6 +210,9 @@ case "${host_os}" in
  339. freebsd*)
  340. os_include_dir="os/bsd/freebsd"
  341. ;;
  342. + linux-musl*)
  343. + os_include_dir="os/generic"
  344. + ;;
  345. gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu)
  346. if [ "$uclibc" = "yes" ]; then
  347. os_include_dir="os/uclibc"