1
0

gcc.musl 25 KB

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