900-musl-support.patch 22 KB

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