0018-Add-ssp_nonshared-to-link-commandline-for-musl-targe.patch 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. From d7dc2861840e88a4592817a398a054a886c3f3ee Mon Sep 17 00:00:00 2001
  2. From: Khem Raj <raj.khem@gmail.com>
  3. Date: Tue, 27 Jun 2017 18:10:54 -0700
  4. Subject: [PATCH] Add ssp_nonshared to link commandline for musl targets
  5. when -fstack-protector options are enabled we need to
  6. link with ssp_shared on musl since it does not provide
  7. the __stack_chk_fail_local() so essentially it provides
  8. libssp but not libssp_nonshared something like
  9. TARGET_LIBC_PROVIDES_SSP_BUT_NOT_SSP_NONSHARED
  10. where-as for glibc the needed symbols
  11. are already present in libc_nonshared library therefore
  12. we do not need any library helper on glibc based systems
  13. but musl needs the libssp_noshared from gcc
  14. Upstream-Status: Pending
  15. Signed-off-by: Khem Raj <raj.khem@gmail.com>
  16. ---
  17. gcc/config/linux.h | 7 +++++++
  18. gcc/config/rs6000/linux.h | 10 ++++++++++
  19. gcc/config/rs6000/linux64.h | 10 ++++++++++
  20. 3 files changed, 27 insertions(+)
  21. diff --git a/gcc/config/linux.h b/gcc/config/linux.h
  22. index 58143dff731..d2409ccac26 100644
  23. --- a/gcc/config/linux.h
  24. +++ b/gcc/config/linux.h
  25. @@ -208,6 +208,13 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  26. { GCC_INCLUDE_DIRVAR, "GCC", 0, 1, 0, 0 }, \
  27. { 0, 0, 0, 0, 0, 0 } \
  28. }
  29. +#ifdef TARGET_LIBC_PROVIDES_SSP
  30. +#undef LINK_SSP_SPEC
  31. +#define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \
  32. + "|fstack-protector-strong|fstack-protector-explicit" \
  33. + ":-lssp_nonshared}"
  34. +#endif
  35. +
  36. #endif
  37. #if (DEFAULT_LIBC == LIBC_UCLIBC) && defined (SINGLE_LIBC) /* uClinux */
  38. diff --git a/gcc/config/rs6000/linux.h b/gcc/config/rs6000/linux.h
  39. index 8c9039ac1e5..259cd485973 100644
  40. --- a/gcc/config/rs6000/linux.h
  41. +++ b/gcc/config/rs6000/linux.h
  42. @@ -99,6 +99,16 @@
  43. " -m elf32ppclinux")
  44. #endif
  45. +/* link libssp_nonshared.a with musl */
  46. +#if DEFAULT_LIBC == LIBC_MUSL
  47. +#ifdef TARGET_LIBC_PROVIDES_SSP
  48. +#undef LINK_SSP_SPEC
  49. +#define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \
  50. + "|fstack-protector-strong|fstack-protector-explicit" \
  51. + ":-lssp_nonshared}"
  52. +#endif
  53. +#endif
  54. +
  55. #undef LINK_OS_LINUX_SPEC
  56. #define LINK_OS_LINUX_SPEC LINK_OS_LINUX_EMUL " %{!shared: %{!static: \
  57. %{!static-pie: \
  58. diff --git a/gcc/config/rs6000/linux64.h b/gcc/config/rs6000/linux64.h
  59. index 364c1a5b155..e33d9ae98e0 100644
  60. --- a/gcc/config/rs6000/linux64.h
  61. +++ b/gcc/config/rs6000/linux64.h
  62. @@ -372,6 +372,16 @@ extern int dot_symbols;
  63. " -m elf64ppc")
  64. #endif
  65. +/* link libssp_nonshared.a with musl */
  66. +#if DEFAULT_LIBC == LIBC_MUSL
  67. +#ifdef TARGET_LIBC_PROVIDES_SSP
  68. +#undef LINK_SSP_SPEC
  69. +#define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \
  70. + "|fstack-protector-strong|fstack-protector-explicit" \
  71. + ":-lssp_nonshared}"
  72. +#endif
  73. +#endif
  74. +
  75. #define LINK_OS_LINUX_SPEC32 LINK_OS_LINUX_EMUL32 " %{!shared: %{!static: \
  76. %{!static-pie: \
  77. %{rdynamic:-export-dynamic} \