1
0

gcc.musl 25 KB

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