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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. From bf92b290556b7050df0a001cc7ae43cf79990456 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: Submitted [https://gcc.gnu.org/pipermail/gcc-patches/2023-April/615317.html]
  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 c921cf6ef63..32e1bc1ae2d 100644
  23. --- a/gcc/config/linux.h
  24. +++ b/gcc/config/linux.h
  25. @@ -195,6 +195,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 5d21befe8e4..1248a68e4ca 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 2ddab7c99c1..9641580fc83 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} \