gcc.musl 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. diff -Nur gcc-5.3.0.orig/fixincludes/mkfixinc.sh gcc-5.3.0/fixincludes/mkfixinc.sh
  2. --- gcc-5.3.0.orig/fixincludes/mkfixinc.sh 2012-10-28 22:42:48.000000000 +0100
  3. +++ gcc-5.3.0/fixincludes/mkfixinc.sh 2015-12-08 05:53:22.243521385 +0100
  4. @@ -19,7 +19,8 @@
  5. powerpc-*-eabi* | \
  6. powerpc-*-rtems* | \
  7. powerpcle-*-eabisim* | \
  8. - powerpcle-*-eabi* )
  9. + powerpcle-*-eabi* | \
  10. + *-musl* )
  11. # IF there is no include fixing,
  12. # THEN create a no-op fixer and exit
  13. (echo "#! /bin/sh" ; echo "exit 0" ) > ${target}
  14. diff -Nur gcc-5.3.0.orig/gcc/config/aarch64/aarch64-linux.h gcc-5.3.0/gcc/config/aarch64/aarch64-linux.h
  15. --- gcc-5.3.0.orig/gcc/config/aarch64/aarch64-linux.h 2015-07-24 18:00:26.000000000 +0200
  16. +++ gcc-5.3.0/gcc/config/aarch64/aarch64-linux.h 2015-12-08 05:53:22.243521385 +0100
  17. @@ -29,6 +29,8 @@
  18. #undef CC1_SPEC
  19. #define CC1_SPEC GNU_USER_TARGET_CC1_SPEC ASAN_CC1_SPEC
  20. +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-aarch64.so.1"
  21. +
  22. #define CPP_SPEC "%{pthread:-D_REENTRANT}"
  23. #define LINUX_TARGET_LINK_SPEC "%{h*} \
  24. diff -Nur gcc-5.3.0.orig/gcc/config/arm/linux-eabi.h gcc-5.3.0/gcc/config/arm/linux-eabi.h
  25. --- gcc-5.3.0.orig/gcc/config/arm/linux-eabi.h 2015-01-05 13:33:28.000000000 +0100
  26. +++ gcc-5.3.0/gcc/config/arm/linux-eabi.h 2015-12-08 05:53:22.243521385 +0100
  27. @@ -77,6 +77,23 @@
  28. %{mfloat-abi=soft*:" GLIBC_DYNAMIC_LINKER_SOFT_FLOAT "} \
  29. %{!mfloat-abi=*:" GLIBC_DYNAMIC_LINKER_DEFAULT "}"
  30. +/* For ARM musl currently supports four dynamic linkers:
  31. + - ld-musl-arm.so.1 - for the EABI-derived soft-float ABI
  32. + - ld-musl-armhf.so.1 - for the EABI-derived hard-float ABI
  33. + - ld-musl-armeb.so.1 - for the EABI-derived soft-float ABI, EB
  34. + - ld-musl-armebhf.so.1 - for the EABI-derived hard-float ABI, EB
  35. + musl does not support the legacy OABI mode.
  36. + All the dynamic linkers live in /lib.
  37. + We default to soft-float, EL. */
  38. +#undef MUSL_DYNAMIC_LINKER
  39. +#if TARGET_BIG_ENDIAN_DEFAULT
  40. +#define MUSL_DYNAMIC_LINKER_E "%{mlittle-endian:;:eb}"
  41. +#else
  42. +#define MUSL_DYNAMIC_LINKER_E "%{mbig-endian:eb}"
  43. +#endif
  44. +#define MUSL_DYNAMIC_LINKER \
  45. + "/lib/ld-musl-arm" MUSL_DYNAMIC_LINKER_E "%{mfloat-abi=hard:hf}.so.1"
  46. +
  47. /* At this point, bpabi.h will have clobbered LINK_SPEC. We want to
  48. use the GNU/Linux version, not the generic BPABI version. */
  49. #undef LINK_SPEC
  50. diff -Nur gcc-5.3.0.orig/gcc/config/i386/linux64.h gcc-5.3.0/gcc/config/i386/linux64.h
  51. --- gcc-5.3.0.orig/gcc/config/i386/linux64.h 2015-01-05 13:33:28.000000000 +0100
  52. +++ gcc-5.3.0/gcc/config/i386/linux64.h 2015-12-08 05:53:22.243521385 +0100
  53. @@ -30,3 +30,7 @@
  54. #define GLIBC_DYNAMIC_LINKER32 "/lib/ld-linux.so.2"
  55. #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-linux-x86-64.so.2"
  56. #define GLIBC_DYNAMIC_LINKERX32 "/libx32/ld-linux-x32.so.2"
  57. +
  58. +#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-i386.so.1"
  59. +#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-x86_64.so.1"
  60. +#define MUSL_DYNAMIC_LINKERX32 "/lib/ld-musl-x32.so.1"
  61. diff -Nur gcc-5.3.0.orig/gcc/config/i386/linux.h gcc-5.3.0/gcc/config/i386/linux.h
  62. --- gcc-5.3.0.orig/gcc/config/i386/linux.h 2015-01-05 13:33:28.000000000 +0100
  63. +++ gcc-5.3.0/gcc/config/i386/linux.h 2015-12-08 05:53:22.243521385 +0100
  64. @@ -21,3 +21,4 @@
  65. #define GNU_USER_LINK_EMULATION "elf_i386"
  66. #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
  67. +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-i386.so.1"
  68. diff -Nur gcc-5.3.0.orig/gcc/config/linux.h gcc-5.3.0/gcc/config/linux.h
  69. --- gcc-5.3.0.orig/gcc/config/linux.h 2015-01-05 13:33:28.000000000 +0100
  70. +++ gcc-5.3.0/gcc/config/linux.h 2015-12-08 05:53:22.243521385 +0100
  71. @@ -32,10 +32,12 @@
  72. #define OPTION_GLIBC (DEFAULT_LIBC == LIBC_GLIBC)
  73. #define OPTION_UCLIBC (DEFAULT_LIBC == LIBC_UCLIBC)
  74. #define OPTION_BIONIC (DEFAULT_LIBC == LIBC_BIONIC)
  75. +#define OPTION_MUSL (DEFAULT_LIBC == LIBC_MUSL)
  76. #else
  77. #define OPTION_GLIBC (linux_libc == LIBC_GLIBC)
  78. #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
  79. #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
  80. +#define OPTION_MUSL (linux_libc == LIBC_MUSL)
  81. #endif
  82. #define GNU_USER_TARGET_OS_CPP_BUILTINS() \
  83. @@ -53,18 +55,21 @@
  84. uClibc or Bionic is the default C library and whether
  85. -muclibc or -mglibc or -mbionic has been passed to change the default. */
  86. -#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LD1, LD2, LD3) \
  87. - "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:" LD1 "}}"
  88. +#define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LIBC4, LD1, LD2, LD3, LD4) \
  89. + "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:%{" LIBC4 ":" LD4 ";:" LD1 "}}}"
  90. #if DEFAULT_LIBC == LIBC_GLIBC
  91. -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
  92. - CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", G, U, B)
  93. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  94. + CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", "mmusl", G, U, B, M)
  95. #elif DEFAULT_LIBC == LIBC_UCLIBC
  96. -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
  97. - CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", U, G, B)
  98. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  99. + CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", "mmusl", U, G, B, M)
  100. #elif DEFAULT_LIBC == LIBC_BIONIC
  101. -#define CHOOSE_DYNAMIC_LINKER(G, U, B) \
  102. - CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", B, G, U)
  103. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  104. + CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", "mmusl", B, G, U, M)
  105. +#elif DEFAULT_LIBC == LIBC_MUSL
  106. +#define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  107. + CHOOSE_DYNAMIC_LINKER1 ("mmusl", "mglibc", "muclibc", "mbionic", M, G, U, B)
  108. #else
  109. #error "Unsupported DEFAULT_LIBC"
  110. #endif /* DEFAULT_LIBC */
  111. @@ -84,21 +89,92 @@
  112. #define GNU_USER_DYNAMIC_LINKER \
  113. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, \
  114. - BIONIC_DYNAMIC_LINKER)
  115. + BIONIC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
  116. #define GNU_USER_DYNAMIC_LINKER32 \
  117. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, \
  118. - BIONIC_DYNAMIC_LINKER32)
  119. + BIONIC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
  120. #define GNU_USER_DYNAMIC_LINKER64 \
  121. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
  122. - BIONIC_DYNAMIC_LINKER64)
  123. + BIONIC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
  124. #define GNU_USER_DYNAMIC_LINKERX32 \
  125. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \
  126. - BIONIC_DYNAMIC_LINKERX32)
  127. + BIONIC_DYNAMIC_LINKERX32, MUSL_DYNAMIC_LINKERX32)
  128. /* Whether we have Bionic libc runtime */
  129. #undef TARGET_HAS_BIONIC
  130. #define TARGET_HAS_BIONIC (OPTION_BIONIC)
  131. +/* musl avoids problematic includes by rearranging the include directories.
  132. + * Unfortunately, this is mostly duplicated from cppdefault.c */
  133. +#if DEFAULT_LIBC == LIBC_MUSL
  134. +#define INCLUDE_DEFAULTS_MUSL_GPP \
  135. + { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, \
  136. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, \
  137. + { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1, \
  138. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 }, \
  139. + { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1, \
  140. + GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },
  141. +
  142. +#ifdef LOCAL_INCLUDE_DIR
  143. +#define INCLUDE_DEFAULTS_MUSL_LOCAL \
  144. + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 }, \
  145. + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 },
  146. +#else
  147. +#define INCLUDE_DEFAULTS_MUSL_LOCAL
  148. +#endif
  149. +
  150. +#ifdef PREFIX_INCLUDE_DIR
  151. +#define INCLUDE_DEFAULTS_MUSL_PREFIX \
  152. + { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0},
  153. +#else
  154. +#define INCLUDE_DEFAULTS_MUSL_PREFIX
  155. +#endif
  156. +
  157. +#ifdef CROSS_INCLUDE_DIR
  158. +#define INCLUDE_DEFAULTS_MUSL_CROSS \
  159. + { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0},
  160. +#else
  161. +#define INCLUDE_DEFAULTS_MUSL_CROSS
  162. +#endif
  163. +
  164. +#ifdef TOOL_INCLUDE_DIR
  165. +#define INCLUDE_DEFAULTS_MUSL_TOOL \
  166. + { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0},
  167. +#else
  168. +#define INCLUDE_DEFAULTS_MUSL_TOOL
  169. +#endif
  170. +
  171. +#ifdef NATIVE_SYSTEM_HEADER_DIR
  172. +#define INCLUDE_DEFAULTS_MUSL_NATIVE \
  173. + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 2 }, \
  174. + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 0 },
  175. +#else
  176. +#define INCLUDE_DEFAULTS_MUSL_NATIVE
  177. +#endif
  178. +
  179. +#if defined (CROSS_DIRECTORY_STRUCTURE) && !defined (TARGET_SYSTEM_ROOT)
  180. +# undef INCLUDE_DEFAULTS_MUSL_LOCAL
  181. +# define INCLUDE_DEFAULTS_MUSL_LOCAL
  182. +# undef INCLUDE_DEFAULTS_MUSL_NATIVE
  183. +# define INCLUDE_DEFAULTS_MUSL_NATIVE
  184. +#else
  185. +# undef INCLUDE_DEFAULTS_MUSL_CROSS
  186. +# define INCLUDE_DEFAULTS_MUSL_CROSS
  187. +#endif
  188. +
  189. +#undef INCLUDE_DEFAULTS
  190. +#define INCLUDE_DEFAULTS \
  191. + { \
  192. + INCLUDE_DEFAULTS_MUSL_GPP \
  193. + INCLUDE_DEFAULTS_MUSL_PREFIX \
  194. + INCLUDE_DEFAULTS_MUSL_CROSS \
  195. + INCLUDE_DEFAULTS_MUSL_TOOL \
  196. + INCLUDE_DEFAULTS_MUSL_NATIVE \
  197. + { GCC_INCLUDE_DIR, "GCC", 0, 1, 0, 0 }, \
  198. + { 0, 0, 0, 0, 0, 0 } \
  199. + }
  200. +#endif
  201. +
  202. #if (DEFAULT_LIBC == LIBC_UCLIBC) && defined (SINGLE_LIBC) /* uClinux */
  203. /* This is a *uclinux* target. We don't define below macros to normal linux
  204. versions, because doing so would require *uclinux* targets to include
  205. diff -Nur gcc-5.3.0.orig/gcc/config/linux.opt gcc-5.3.0/gcc/config/linux.opt
  206. --- gcc-5.3.0.orig/gcc/config/linux.opt 2015-01-05 13:33:28.000000000 +0100
  207. +++ gcc-5.3.0/gcc/config/linux.opt 2015-12-08 05:53:22.243521385 +0100
  208. @@ -30,3 +30,7 @@
  209. muclibc
  210. Target Report RejectNegative Var(linux_libc,LIBC_UCLIBC) Negative(mbionic)
  211. Use uClibc C library
  212. +
  213. +mmusl
  214. +Target Report RejectNegative Var(linux_libc,LIBC_MUSL) Negative(mglibc)
  215. +Use musl C library
  216. diff -Nur gcc-5.3.0.orig/gcc/config/microblaze/linux.h gcc-5.3.0/gcc/config/microblaze/linux.h
  217. --- gcc-5.3.0.orig/gcc/config/microblaze/linux.h 2015-05-28 16:08:19.000000000 +0200
  218. +++ gcc-5.3.0/gcc/config/microblaze/linux.h 2015-12-08 05:53:22.243521385 +0100
  219. @@ -28,7 +28,22 @@
  220. #undef TLS_NEEDS_GOT
  221. #define TLS_NEEDS_GOT 1
  222. -#define DYNAMIC_LINKER "/lib/ld.so.1"
  223. +#if TARGET_BIG_ENDIAN_DEFAULT == 0 /* LE */
  224. +#define MUSL_DYNAMIC_LINKER_E "%{EB:;:el}"
  225. +#else
  226. +#define MUSL_DYNAMIC_LINKER_E "%{EL:el}"
  227. +#endif
  228. +
  229. +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-microblaze" MUSL_DYNAMIC_LINKER_E ".so.1"
  230. +#define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
  231. +
  232. +#if DEFAULT_LIBC == LIBC_MUSL
  233. +#define DYNAMIC_LINKER MUSL_DYNAMIC_LINKER
  234. +#else
  235. +#define DYNAMIC_LINKER GLIBC_DYNAMIC_LINKER
  236. +#endif
  237. +
  238. +
  239. #undef SUBTARGET_EXTRA_SPECS
  240. #define SUBTARGET_EXTRA_SPECS \
  241. { "dynamic_linker", DYNAMIC_LINKER }
  242. diff -Nur gcc-5.3.0.orig/gcc/config/microblaze/microblaze.h gcc-5.3.0/gcc/config/microblaze/microblaze.h
  243. --- gcc-5.3.0.orig/gcc/config/microblaze/microblaze.h 2015-01-05 13:33:28.000000000 +0100
  244. +++ gcc-5.3.0/gcc/config/microblaze/microblaze.h 2015-12-08 05:53:22.243521385 +0100
  245. @@ -218,6 +218,12 @@
  246. #undef PTRDIFF_TYPE
  247. #define PTRDIFF_TYPE "int"
  248. +#undef SIZE_TYPE
  249. +#define SIZE_TYPE "unsigned int"
  250. +
  251. +#undef PTRDIFF_TYPE
  252. +#define PTRDIFF_TYPE "int"
  253. +
  254. #define CONSTANT_ALIGNMENT(EXP, ALIGN) \
  255. ((TREE_CODE (EXP) == STRING_CST || TREE_CODE (EXP) == CONSTRUCTOR) \
  256. && (ALIGN) < BITS_PER_WORD \
  257. diff -Nur gcc-5.3.0.orig/gcc/config/mips/linux.h gcc-5.3.0/gcc/config/mips/linux.h
  258. --- gcc-5.3.0.orig/gcc/config/mips/linux.h 2015-01-05 13:33:28.000000000 +0100
  259. +++ gcc-5.3.0/gcc/config/mips/linux.h 2015-12-08 05:53:22.243521385 +0100
  260. @@ -31,13 +31,26 @@
  261. #undef UCLIBC_DYNAMIC_LINKER32
  262. #define UCLIBC_DYNAMIC_LINKER32 \
  263. "%{mnan=2008:/lib/ld-uClibc-mipsn8.so.0;:/lib/ld-uClibc.so.0}"
  264. +
  265. +#if TARGET_ENDIAN_DEFAULT == 0 /* LE */
  266. +#define MUSL_DYNAMIC_LINKER_E "%{EB:;:el}"
  267. +#else
  268. +#define MUSL_DYNAMIC_LINKER_E "%{EL:el}"
  269. +#endif
  270. +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-mips" MUSL_DYNAMIC_LINKER_E "%{msoft-float:-sf}.so.1"
  271. #undef UCLIBC_DYNAMIC_LINKER64
  272. #define UCLIBC_DYNAMIC_LINKER64 \
  273. "%{mnan=2008:/lib/ld64-uClibc-mipsn8.so.0;:/lib/ld64-uClibc.so.0}"
  274. #define UCLIBC_DYNAMIC_LINKERN32 \
  275. "%{mnan=2008:/lib32/ld-uClibc-mipsn8.so.0;:/lib32/ld-uClibc.so.0}"
  276. +#undef MUSL_DYNAMIC_LINKER32
  277. +#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-mips%{EL:el}%{msoft-float:-sf}.so.1"
  278. +#undef MUSL_DYNAMIC_LINKER64
  279. +#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-mips64%{EL:el}%{msoft-float:-sf}.so.1"
  280. +#define MUSL_DYNAMIC_LINKERN32 "/lib/ld-musl-mipsn32%{EL:el}%{msoft-float:-sf}.so.1"
  281. +
  282. #define BIONIC_DYNAMIC_LINKERN32 "/system/bin/linker32"
  283. #define GNU_USER_DYNAMIC_LINKERN32 \
  284. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERN32, UCLIBC_DYNAMIC_LINKERN32, \
  285. - BIONIC_DYNAMIC_LINKERN32)
  286. + BIONIC_DYNAMIC_LINKERN32, MUSL_DYNAMIC_LINKERN32)
  287. diff -Nur gcc-5.3.0.orig/gcc/config/rs6000/linux64.h gcc-5.3.0/gcc/config/rs6000/linux64.h
  288. --- gcc-5.3.0.orig/gcc/config/rs6000/linux64.h 2015-03-10 00:18:57.000000000 +0100
  289. +++ gcc-5.3.0/gcc/config/rs6000/linux64.h 2015-12-08 05:53:22.243521385 +0100
  290. @@ -365,17 +365,21 @@
  291. #endif
  292. #define UCLIBC_DYNAMIC_LINKER32 "/lib/ld-uClibc.so.0"
  293. #define UCLIBC_DYNAMIC_LINKER64 "/lib/ld64-uClibc.so.0"
  294. +#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-powerpc.so.1"
  295. +#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-powerpc64.so.1"
  296. #if DEFAULT_LIBC == LIBC_UCLIBC
  297. -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
  298. +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
  299. #elif DEFAULT_LIBC == LIBC_GLIBC
  300. -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
  301. +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
  302. +#elif DEFAULT_LIBC == LIBC_MUSL
  303. +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
  304. #else
  305. #error "Unsupported DEFAULT_LIBC"
  306. #endif
  307. #define GNU_USER_DYNAMIC_LINKER32 \
  308. - CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32)
  309. + CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
  310. #define GNU_USER_DYNAMIC_LINKER64 \
  311. - CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64)
  312. + CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
  313. #undef DEFAULT_ASM_ENDIAN
  314. #if (TARGET_DEFAULT & MASK_LITTLE_ENDIAN)
  315. diff -Nur gcc-5.3.0.orig/gcc/config/rs6000/secureplt.h gcc-5.3.0/gcc/config/rs6000/secureplt.h
  316. --- gcc-5.3.0.orig/gcc/config/rs6000/secureplt.h 2015-01-05 13:33:28.000000000 +0100
  317. +++ gcc-5.3.0/gcc/config/rs6000/secureplt.h 2015-12-08 05:53:22.243521385 +0100
  318. @@ -18,3 +18,4 @@
  319. <http://www.gnu.org/licenses/>. */
  320. #define CC1_SECURE_PLT_DEFAULT_SPEC "-msecure-plt"
  321. +#define LINK_SECURE_PLT_DEFAULT_SPEC "--secure-plt"
  322. diff -Nur gcc-5.3.0.orig/gcc/config/rs6000/sysv4.h gcc-5.3.0/gcc/config/rs6000/sysv4.h
  323. --- gcc-5.3.0.orig/gcc/config/rs6000/sysv4.h 2015-09-24 15:46:45.000000000 +0200
  324. +++ gcc-5.3.0/gcc/config/rs6000/sysv4.h 2015-12-08 05:53:22.243521385 +0100
  325. @@ -537,6 +537,9 @@
  326. #ifndef CC1_SECURE_PLT_DEFAULT_SPEC
  327. #define CC1_SECURE_PLT_DEFAULT_SPEC ""
  328. #endif
  329. +#ifndef LINK_SECURE_PLT_DEFAULT_SPEC
  330. +#define LINK_SECURE_PLT_DEFAULT_SPEC ""
  331. +#endif
  332. /* Pass -G xxx to the compiler. */
  333. #undef CC1_SPEC
  334. @@ -759,15 +762,18 @@
  335. #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
  336. #define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0"
  337. +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-powerpc.so.1"
  338. #if DEFAULT_LIBC == LIBC_UCLIBC
  339. -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{mglibc:" G ";:" U "}"
  340. +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{mmusl:" M ";:" U "}}"
  341. +#elif DEFAULT_LIBC == LIBC_MUSL
  342. +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{mglibc:" G ";:%{muclibc:" U ";:" M "}}"
  343. #elif !defined (DEFAULT_LIBC) || DEFAULT_LIBC == LIBC_GLIBC
  344. -#define CHOOSE_DYNAMIC_LINKER(G, U) "%{muclibc:" U ";:" G "}"
  345. +#define CHOOSE_DYNAMIC_LINKER(G, U, M) "%{muclibc:" U ";:%{mmusl:" M ";:" G "}}"
  346. #else
  347. #error "Unsupported DEFAULT_LIBC"
  348. #endif
  349. #define GNU_USER_DYNAMIC_LINKER \
  350. - CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER)
  351. + CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
  352. #define LINK_OS_LINUX_SPEC "-m elf32ppclinux %{!shared: %{!static: \
  353. %{rdynamic:-export-dynamic} \
  354. @@ -889,6 +895,7 @@
  355. { "link_os_openbsd", LINK_OS_OPENBSD_SPEC }, \
  356. { "link_os_default", LINK_OS_DEFAULT_SPEC }, \
  357. { "cc1_secure_plt_default", CC1_SECURE_PLT_DEFAULT_SPEC }, \
  358. + { "link_secure_plt_default", LINK_SECURE_PLT_DEFAULT_SPEC }, \
  359. { "cpp_os_ads", CPP_OS_ADS_SPEC }, \
  360. { "cpp_os_yellowknife", CPP_OS_YELLOWKNIFE_SPEC }, \
  361. { "cpp_os_mvme", CPP_OS_MVME_SPEC }, \
  362. diff -Nur gcc-5.3.0.orig/gcc/config/sh/linux.h gcc-5.3.0/gcc/config/sh/linux.h
  363. --- gcc-5.3.0.orig/gcc/config/sh/linux.h 2015-01-05 13:33:28.000000000 +0100
  364. +++ gcc-5.3.0/gcc/config/sh/linux.h 2015-12-08 05:53:22.243521385 +0100
  365. @@ -43,7 +43,14 @@
  366. #define TARGET_ASM_FILE_END file_end_indicate_exec_stack
  367. +#if TARGET_BIG_ENDIAN_DEFAULT /* BE */
  368. +#define MUSL_DYNAMIC_LINKER_E "eb"
  369. +#else
  370. +#define MUSL_DYNAMIC_LINKER_E
  371. +#endif
  372. +
  373. #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
  374. +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-sh" MUSL_DYNAMIC_LINKER_E ".so.1"
  375. #undef SUBTARGET_LINK_EMUL_SUFFIX
  376. #define SUBTARGET_LINK_EMUL_SUFFIX "_linux"
  377. diff -Nur gcc-5.3.0.orig/gcc/config.gcc gcc-5.3.0/gcc/config.gcc
  378. --- gcc-5.3.0.orig/gcc/config.gcc 2015-09-10 16:17:53.000000000 +0200
  379. +++ gcc-5.3.0/gcc/config.gcc 2015-12-08 05:53:22.247521539 +0100
  380. @@ -575,7 +575,7 @@
  381. esac
  382. # Common C libraries.
  383. -tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3"
  384. +tm_defines="$tm_defines LIBC_GLIBC=1 LIBC_UCLIBC=2 LIBC_BIONIC=3 LIBC_MUSL=4"
  385. # 32-bit x86 processors supported by --with-arch=. Each processor
  386. # MUST be separated by exactly one space.
  387. @@ -720,6 +720,9 @@
  388. *-*-*uclibc*)
  389. tm_defines="$tm_defines DEFAULT_LIBC=LIBC_UCLIBC"
  390. ;;
  391. + *-*-*musl*)
  392. + tm_defines="$tm_defines DEFAULT_LIBC=LIBC_MUSL"
  393. + ;;
  394. *)
  395. tm_defines="$tm_defines DEFAULT_LIBC=LIBC_GLIBC"
  396. ;;
  397. @@ -2413,6 +2416,10 @@
  398. powerpc*-*-linux*paired*)
  399. tm_file="${tm_file} rs6000/750cl.h" ;;
  400. esac
  401. + case ${target} in
  402. + *-linux*-musl*)
  403. + enable_secureplt=yes ;;
  404. + esac
  405. if test x${enable_secureplt} = xyes; then
  406. tm_file="rs6000/secureplt.h ${tm_file}"
  407. fi
  408. diff -Nur gcc-5.3.0.orig/gcc/configure gcc-5.3.0/gcc/configure
  409. --- gcc-5.3.0.orig/gcc/configure 2015-11-19 14:32:10.000000000 +0100
  410. +++ gcc-5.3.0/gcc/configure 2015-12-08 05:53:22.251521693 +0100
  411. @@ -27802,6 +27802,9 @@
  412. else
  413. gcc_cv_libc_provides_ssp=no
  414. case "$target" in
  415. + *-*-musl*)
  416. + # All versions of musl provide stack protector
  417. + gcc_cv_libc_provides_ssp=yes;;
  418. *-*-linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu)
  419. # glibc 2.4 and later provides __stack_chk_fail and
  420. # either __stack_chk_guard, or TLS access to stack guard canary.
  421. @@ -27834,6 +27837,7 @@
  422. # <http://gcc.gnu.org/ml/gcc/2008-10/msg00130.html>) and for now
  423. # simply assert that glibc does provide this, which is true for all
  424. # realistically usable GNU/Hurd configurations.
  425. + # All supported versions of musl provide it as well
  426. gcc_cv_libc_provides_ssp=yes;;
  427. *-*-darwin* | *-*-freebsd*)
  428. ac_fn_c_check_func "$LINENO" "__stack_chk_fail" "ac_cv_func___stack_chk_fail"
  429. @@ -27930,6 +27934,9 @@
  430. gcc_cv_target_dl_iterate_phdr=no
  431. fi
  432. ;;
  433. + *-linux-musl*)
  434. + gcc_cv_target_dl_iterate_phdr=yes
  435. + ;;
  436. esac
  437. if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
  438. diff -Nur gcc-5.3.0.orig/gcc/configure.ac gcc-5.3.0/gcc/configure.ac
  439. --- gcc-5.3.0.orig/gcc/configure.ac 2015-11-19 14:32:10.000000000 +0100
  440. +++ gcc-5.3.0/gcc/configure.ac 2015-12-08 05:53:22.255521847 +0100
  441. @@ -5282,6 +5282,9 @@
  442. gcc_cv_libc_provides_ssp,
  443. [gcc_cv_libc_provides_ssp=no
  444. case "$target" in
  445. + *-*-musl*)
  446. + # All versions of musl provide stack protector
  447. + gcc_cv_libc_provides_ssp=yes;;
  448. *-*-linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu)
  449. # glibc 2.4 and later provides __stack_chk_fail and
  450. # either __stack_chk_guard, or TLS access to stack guard canary.
  451. @@ -5308,6 +5311,7 @@
  452. # <http://gcc.gnu.org/ml/gcc/2008-10/msg00130.html>) and for now
  453. # simply assert that glibc does provide this, which is true for all
  454. # realistically usable GNU/Hurd configurations.
  455. + # All supported versions of musl provide it as well
  456. gcc_cv_libc_provides_ssp=yes;;
  457. *-*-darwin* | *-*-freebsd*)
  458. AC_CHECK_FUNC(__stack_chk_fail,[gcc_cv_libc_provides_ssp=yes],
  459. @@ -5381,6 +5385,9 @@
  460. gcc_cv_target_dl_iterate_phdr=no
  461. fi
  462. ;;
  463. + *-linux-musl*)
  464. + gcc_cv_target_dl_iterate_phdr=yes
  465. + ;;
  466. esac
  467. GCC_TARGET_TEMPLATE([TARGET_DL_ITERATE_PHDR])
  468. if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
  469. diff -Nur gcc-5.3.0.orig/gcc/gcc.c gcc-5.3.0/gcc/gcc.c
  470. --- gcc-5.3.0.orig/gcc/gcc.c 2015-03-10 10:37:41.000000000 +0100
  471. +++ gcc-5.3.0/gcc/gcc.c 2015-12-08 05:53:22.255521847 +0100
  472. @@ -729,7 +729,7 @@
  473. #ifndef LINK_SSP_SPEC
  474. #ifdef TARGET_LIBC_PROVIDES_SSP
  475. #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \
  476. - "|fstack-protector-strong|fstack-protector-explicit:}"
  477. + "|fstack-protector-strong|fstack-protector-explicit:-lssp_nonshared}"
  478. #else
  479. #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \
  480. "|fstack-protector-strong|fstack-protector-explicit" \
  481. diff -Nur gcc-5.3.0.orig/gcc/ginclude/stddef.h gcc-5.3.0/gcc/ginclude/stddef.h
  482. --- gcc-5.3.0.orig/gcc/ginclude/stddef.h 2015-01-05 13:33:28.000000000 +0100
  483. +++ gcc-5.3.0/gcc/ginclude/stddef.h 2015-12-08 05:53:22.255521847 +0100
  484. @@ -184,6 +184,7 @@
  485. #ifndef _GCC_SIZE_T
  486. #ifndef _SIZET_
  487. #ifndef __size_t
  488. +#ifndef __DEFINED_size_t /* musl */
  489. #define __size_t__ /* BeOS */
  490. #define __SIZE_T__ /* Cray Unicos/Mk */
  491. #define _SIZE_T
  492. @@ -200,6 +201,7 @@
  493. #define ___int_size_t_h
  494. #define _GCC_SIZE_T
  495. #define _SIZET_
  496. +#define __DEFINED_size_t /* musl */
  497. #if (defined (__FreeBSD__) && (__FreeBSD__ >= 5)) \
  498. || defined(__DragonFly__) \
  499. || defined(__FreeBSD_kernel__)
  500. @@ -218,6 +220,7 @@
  501. typedef long ssize_t;
  502. #endif /* __BEOS__ */
  503. #endif /* !(defined (__GNUG__) && defined (size_t)) */
  504. +#endif /* __DEFINED_size_t */
  505. #endif /* __size_t */
  506. #endif /* _SIZET_ */
  507. #endif /* _GCC_SIZE_T */
  508. diff -Nur gcc-5.3.0.orig/libgcc/unwind-dw2-fde-dip.c gcc-5.3.0/libgcc/unwind-dw2-fde-dip.c
  509. --- gcc-5.3.0.orig/libgcc/unwind-dw2-fde-dip.c 2015-01-27 11:02:26.000000000 +0100
  510. +++ gcc-5.3.0/libgcc/unwind-dw2-fde-dip.c 2015-12-08 05:53:22.255521847 +0100
  511. @@ -46,6 +46,10 @@
  512. #include "unwind-compat.h"
  513. #include "gthr.h"
  514. +#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) && defined(TARGET_DL_ITERATE_PHDR)
  515. +# define USE_PT_GNU_EH_FRAME
  516. +#endif
  517. +
  518. #if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
  519. && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) \
  520. || (__GLIBC__ == 2 && __GLIBC_MINOR__ == 2 && defined(DT_CONFIG)))
  521. diff -Nur gcc-5.3.0.orig/libgomp/config/posix/time.c gcc-5.3.0/libgomp/config/posix/time.c
  522. --- gcc-5.3.0.orig/libgomp/config/posix/time.c 2015-01-10 20:10:37.000000000 +0100
  523. +++ gcc-5.3.0/libgomp/config/posix/time.c 2015-12-08 05:53:22.255521847 +0100
  524. @@ -29,6 +29,8 @@
  525. The following implementation uses the most simple POSIX routines.
  526. If present, POSIX 4 clocks should be used instead. */
  527. +#define _POSIX_C_SOURCE 199309L /* for clocks */
  528. +
  529. #include "libgomp.h"
  530. #include <unistd.h>
  531. #if TIME_WITH_SYS_TIME
  532. diff -Nur gcc-5.3.0.orig/libitm/config/arm/hwcap.cc gcc-5.3.0/libitm/config/arm/hwcap.cc
  533. --- gcc-5.3.0.orig/libitm/config/arm/hwcap.cc 2015-01-05 13:33:28.000000000 +0100
  534. +++ gcc-5.3.0/libitm/config/arm/hwcap.cc 2015-12-08 05:53:22.255521847 +0100
  535. @@ -40,7 +40,11 @@
  536. #ifdef __linux__
  537. #include <unistd.h>
  538. +#ifdef __GLIBC__
  539. #include <sys/fcntl.h>
  540. +#else
  541. +#include <fcntl.h>
  542. +#endif
  543. #include <elf.h>
  544. static void __attribute__((constructor))
  545. diff -Nur gcc-5.3.0.orig/libitm/config/linux/x86/tls.h gcc-5.3.0/libitm/config/linux/x86/tls.h
  546. --- gcc-5.3.0.orig/libitm/config/linux/x86/tls.h 2015-01-05 13:33:28.000000000 +0100
  547. +++ gcc-5.3.0/libitm/config/linux/x86/tls.h 2015-12-08 05:53:22.255521847 +0100
  548. @@ -25,16 +25,19 @@
  549. #ifndef LIBITM_X86_TLS_H
  550. #define LIBITM_X86_TLS_H 1
  551. -#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
  552. +#if defined(__GLIBC_PREREQ)
  553. +#if __GLIBC_PREREQ(2, 10)
  554. /* Use slots in the TCB head rather than __thread lookups.
  555. GLIBC has reserved words 10 through 13 for TM. */
  556. #define HAVE_ARCH_GTM_THREAD 1
  557. #define HAVE_ARCH_GTM_THREAD_DISP 1
  558. #endif
  559. +#endif
  560. #include "config/generic/tls.h"
  561. -#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10)
  562. +#if defined(__GLIBC_PREREQ)
  563. +#if __GLIBC_PREREQ(2, 10)
  564. namespace GTM HIDDEN {
  565. #ifdef __x86_64__
  566. @@ -101,5 +104,6 @@
  567. } // namespace GTM
  568. #endif /* >= GLIBC 2.10 */
  569. +#endif
  570. #endif // LIBITM_X86_TLS_H
  571. diff -Nur gcc-5.3.0.orig/libstdc++-v3/configure.host gcc-5.3.0/libstdc++-v3/configure.host
  572. --- gcc-5.3.0.orig/libstdc++-v3/configure.host 2015-06-24 11:59:28.000000000 +0200
  573. +++ gcc-5.3.0/libstdc++-v3/configure.host 2015-12-08 05:53:22.255521847 +0100
  574. @@ -274,6 +274,13 @@
  575. os_include_dir="os/bsd/freebsd"
  576. ;;
  577. gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu)
  578. + # check for musl by target
  579. + case "${host_os}" in
  580. + *-musl*)
  581. + os_include_dir="os/generic"
  582. + ;;
  583. + *)
  584. +
  585. if [ "$uclibc" = "yes" ]; then
  586. os_include_dir="os/uclibc"
  587. elif [ "$bionic" = "yes" ]; then
  588. @@ -282,6 +289,9 @@
  589. os_include_dir="os/gnu-linux"
  590. fi
  591. ;;
  592. +
  593. + esac
  594. + ;;
  595. hpux*)
  596. os_include_dir="os/hpux"
  597. ;;