OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

285 lines
12 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: package/.../musl/pkg/gcc/0005-On-linux-targets-pass-as-needed-by-default-to-the-li.patch
  5. # Copyright (C) 2020 The OpenSDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  9. # This patch file is dual-licensed. It is available under the license the
  10. # patched project is licensed under, as long as it is an OpenSource license
  11. # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
  12. # of the GNU General Public License as published by the Free Software
  13. # Foundation; either version 2 of the License, or (at your option) any later
  14. # version.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. From 872e0a15a2b74cd6b6ba58e2e7e1605543ea36bd Mon Sep 17 00:00:00 2001
  17. From: Ariadne Conill <ariadne@dereferenced.org>
  18. Date: Fri, 21 Aug 2020 06:46:56 +0000
  19. Subject: [PATCH 05/30] On linux targets pass --as-needed by default to the
  20. linker, but always link the sanitizer libraries with --no-as-needed.
  21. ---
  22. gcc/config/aarch64/aarch64-linux.h | 1 +
  23. gcc/config/alpha/linux-elf.h | 2 +-
  24. gcc/config/arm/linux-elf.h | 1 +
  25. gcc/config/gnu-user.h | 6 +++---
  26. gcc/config/i386/gnu-user.h | 2 +-
  27. gcc/config/i386/gnu-user64.h | 1 +
  28. gcc/config/ia64/linux.h | 2 +-
  29. gcc/config/mips/gnu-user.h | 1 +
  30. gcc/config/riscv/linux.h | 1 +
  31. gcc/config/rs6000/linux64.h | 4 ++--
  32. gcc/config/rs6000/sysv4.h | 2 +-
  33. gcc/config/s390/linux.h | 2 +-
  34. gcc/config/sparc/linux.h | 2 +-
  35. gcc/gcc.c | 28 ++++++++++++++++++++--------
  36. 14 files changed, 36 insertions(+), 19 deletions(-)
  37. diff --git a/gcc/config/aarch64/aarch64-linux.h b/gcc/config/aarch64/aarch64-linux.h
  38. index e587e2e9ad6..1d1017aa523 100644
  39. --- a/gcc/config/aarch64/aarch64-linux.h
  40. +++ b/gcc/config/aarch64/aarch64-linux.h
  41. @@ -35,6 +35,7 @@
  42. #define CPP_SPEC "%{pthread:-D_REENTRANT}"
  43. #define LINUX_TARGET_LINK_SPEC "%{h*} \
  44. + --as-needed \
  45. %{static:-Bstatic} \
  46. %{shared:-shared} \
  47. %{symbolic:-Bsymbolic} \
  48. diff --git a/gcc/config/alpha/linux-elf.h b/gcc/config/alpha/linux-elf.h
  49. index e25fcac3c59..22b2f7b0d14 100644
  50. --- a/gcc/config/alpha/linux-elf.h
  51. +++ b/gcc/config/alpha/linux-elf.h
  52. @@ -37,7 +37,7 @@ along with GCC; see the file COPYING3. If not see
  53. #define ELF_DYNAMIC_LINKER GNU_USER_DYNAMIC_LINKER
  54. -#define LINK_SPEC "-m elf64alpha %{G*} %{relax:-relax} \
  55. +#define LINK_SPEC "-m elf64alpha --as-needed %{G*} %{relax:-relax} \
  56. %{O*:-O3} %{!O*:-O1} \
  57. %{shared:-shared} \
  58. %{!shared: \
  59. diff --git a/gcc/config/arm/linux-elf.h b/gcc/config/arm/linux-elf.h
  60. index 0ec3aa53189..f8bda84de2a 100644
  61. --- a/gcc/config/arm/linux-elf.h
  62. +++ b/gcc/config/arm/linux-elf.h
  63. @@ -70,6 +70,7 @@
  64. %{rdynamic:-export-dynamic} \
  65. %{!shared:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}} \
  66. -X \
  67. + --as-needed \
  68. %{mbig-endian:-EB} %{mlittle-endian:-EL}" \
  69. SUBTARGET_EXTRA_LINK_SPEC
  70. diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h
  71. index ff2e880b1fa..7f30c363e4a 100644
  72. --- a/gcc/config/gnu-user.h
  73. +++ b/gcc/config/gnu-user.h
  74. @@ -136,17 +136,17 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  75. #define LIBASAN_EARLY_SPEC "%{!shared:libasan_preinit%O%s} " \
  76. "%{static-libasan:%{!shared:" \
  77. LD_STATIC_OPTION " --whole-archive -lasan --no-whole-archive " \
  78. - LD_DYNAMIC_OPTION "}}%{!static-libasan:-lasan}"
  79. + LD_DYNAMIC_OPTION "}}%{!static-libasan:%{!fuse-ld=gold:--push-state} --no-as-needed -lasan %{fuse-ld=gold:--as-needed;:--pop-state}}"
  80. #undef LIBTSAN_EARLY_SPEC
  81. #define LIBTSAN_EARLY_SPEC "%{!shared:libtsan_preinit%O%s} " \
  82. "%{static-libtsan:%{!shared:" \
  83. LD_STATIC_OPTION " --whole-archive -ltsan --no-whole-archive " \
  84. - LD_DYNAMIC_OPTION "}}%{!static-libtsan:-ltsan}"
  85. + LD_DYNAMIC_OPTION "}}%{!static-libtsan:%{!fuse-ld=gold:--push-state} --no-as-needed -ltsan %{fuse-ld=gold:--as-needed;:--pop-state}}"
  86. #undef LIBLSAN_EARLY_SPEC
  87. #define LIBLSAN_EARLY_SPEC "%{!shared:liblsan_preinit%O%s} " \
  88. "%{static-liblsan:%{!shared:" \
  89. LD_STATIC_OPTION " --whole-archive -llsan --no-whole-archive " \
  90. - LD_DYNAMIC_OPTION "}}%{!static-liblsan:-llsan}"
  91. + LD_DYNAMIC_OPTION "}}%{!static-liblsan:%{!fuse-ld=gold:--push-state} --no-as-needed -llsan %{fuse-ld=gold:--as-needed;:--pop-state}}"
  92. #endif
  93. #undef TARGET_F951_OPTIONS
  94. diff --git a/gcc/config/i386/gnu-user.h b/gcc/config/i386/gnu-user.h
  95. index ae4aa844f02..54b91c0492a 100644
  96. --- a/gcc/config/i386/gnu-user.h
  97. +++ b/gcc/config/i386/gnu-user.h
  98. @@ -74,7 +74,7 @@ along with GCC; see the file COPYING3. If not see
  99. { "link_emulation", GNU_USER_LINK_EMULATION },\
  100. { "dynamic_linker", GNU_USER_DYNAMIC_LINKER }
  101. -#define GNU_USER_TARGET_LINK_SPEC "-m %(link_emulation) %{shared:-shared} \
  102. +#define GNU_USER_TARGET_LINK_SPEC "-m %(link_emulation) --as-needed %{shared:-shared} \
  103. %{!shared: \
  104. %{!static: \
  105. %{!static-pie: \
  106. diff --git a/gcc/config/i386/gnu-user64.h b/gcc/config/i386/gnu-user64.h
  107. index 785c68220b8..21dd66b412a 100644
  108. --- a/gcc/config/i386/gnu-user64.h
  109. +++ b/gcc/config/i386/gnu-user64.h
  110. @@ -56,6 +56,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  111. "%{" SPEC_64 ":-m " GNU_USER_LINK_EMULATION64 "} \
  112. %{" SPEC_32 ":-m " GNU_USER_LINK_EMULATION32 "} \
  113. %{" SPEC_X32 ":-m " GNU_USER_LINK_EMULATIONX32 "} \
  114. + --as-needed \
  115. %{shared:-shared} \
  116. %{!shared: \
  117. %{!static: \
  118. diff --git a/gcc/config/ia64/linux.h b/gcc/config/ia64/linux.h
  119. index ee38e218aec..0325971d818 100644
  120. --- a/gcc/config/ia64/linux.h
  121. +++ b/gcc/config/ia64/linux.h
  122. @@ -58,7 +58,7 @@ do { \
  123. #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux-ia64.so.2"
  124. #undef LINK_SPEC
  125. -#define LINK_SPEC "\
  126. +#define LINK_SPEC " --as-needed \
  127. %{shared:-shared} \
  128. %{!shared: \
  129. %{!static: \
  130. diff --git a/gcc/config/mips/gnu-user.h b/gcc/config/mips/gnu-user.h
  131. index 5d0782100bb..4be5fbb2191 100644
  132. --- a/gcc/config/mips/gnu-user.h
  133. +++ b/gcc/config/mips/gnu-user.h
  134. @@ -55,6 +55,7 @@ along with GCC; see the file COPYING3. If not see
  135. #undef GNU_USER_TARGET_LINK_SPEC
  136. #define GNU_USER_TARGET_LINK_SPEC "\
  137. %{G*} %{EB} %{EL} %{mips*} %{shared} \
  138. + -as-needed \
  139. %{!shared: \
  140. %{!static: \
  141. %{rdynamic:-export-dynamic} \
  142. diff --git a/gcc/config/riscv/linux.h b/gcc/config/riscv/linux.h
  143. index 4afef7c228c..ba1a6e60e05 100644
  144. --- a/gcc/config/riscv/linux.h
  145. +++ b/gcc/config/riscv/linux.h
  146. @@ -58,6 +58,7 @@ along with GCC; see the file COPYING3. If not see
  147. "%{mabi=ilp32:_ilp32}"
  148. #define LINK_SPEC "\
  149. +-as-needed \
  150. -melf" XLEN_SPEC "lriscv" LD_EMUL_SUFFIX " \
  151. %{mno-relax:--no-relax} \
  152. %{shared} \
  153. diff --git a/gcc/config/rs6000/linux64.h b/gcc/config/rs6000/linux64.h
  154. index 2ded3301282..a1e44ddcc0d 100644
  155. --- a/gcc/config/rs6000/linux64.h
  156. +++ b/gcc/config/rs6000/linux64.h
  157. @@ -457,13 +457,13 @@ extern int dot_symbols;
  158. " -m elf64ppc")
  159. #endif
  160. -#define LINK_OS_LINUX_SPEC32 LINK_OS_LINUX_EMUL32 " %{!shared: %{!static: \
  161. +#define LINK_OS_LINUX_SPEC32 LINK_OS_LINUX_EMUL32 " --as-needed %{!shared: %{!static: \
  162. %{!static-pie: \
  163. %{rdynamic:-export-dynamic} \
  164. -dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "}}} \
  165. %(link_os_extra_spec32)"
  166. -#define LINK_OS_LINUX_SPEC64 LINK_OS_LINUX_EMUL64 " %{!shared: %{!static: \
  167. +#define LINK_OS_LINUX_SPEC64 LINK_OS_LINUX_EMUL64 " --as-needed %{!shared: %{!static: \
  168. %{!static-pie: \
  169. %{rdynamic:-export-dynamic} \
  170. -dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "}}} \
  171. diff --git a/gcc/config/rs6000/sysv4.h b/gcc/config/rs6000/sysv4.h
  172. index 9ade72114e9..9490b84a153 100644
  173. --- a/gcc/config/rs6000/sysv4.h
  174. +++ b/gcc/config/rs6000/sysv4.h
  175. @@ -789,7 +789,7 @@ GNU_USER_TARGET_CC1_SPEC
  176. #define GNU_USER_DYNAMIC_LINKER GLIBC_DYNAMIC_LINKER
  177. #endif
  178. -#define LINK_OS_LINUX_SPEC "-m elf32ppclinux %{!shared: %{!static: \
  179. +#define LINK_OS_LINUX_SPEC "-m elf32ppclinux --as-needed %{!shared: %{!static: \
  180. %{rdynamic:-export-dynamic} \
  181. -dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}"
  182. diff --git a/gcc/config/s390/linux.h b/gcc/config/s390/linux.h
  183. index 6919b468f06..56d52d41b31 100644
  184. --- a/gcc/config/s390/linux.h
  185. +++ b/gcc/config/s390/linux.h
  186. @@ -82,7 +82,7 @@ along with GCC; see the file COPYING3. If not see
  187. #undef LINK_SPEC
  188. #define LINK_SPEC \
  189. - "%{m31:-m elf_s390}%{m64:-m elf64_s390} \
  190. + "%{m31:-m elf_s390}%{m64:-m elf64_s390} --as-needed \
  191. %{shared:-shared} \
  192. %{!shared: \
  193. %{static:-static} \
  194. diff --git a/gcc/config/sparc/linux.h b/gcc/config/sparc/linux.h
  195. index 81201e67a2f..6477d7ec52e 100644
  196. --- a/gcc/config/sparc/linux.h
  197. +++ b/gcc/config/sparc/linux.h
  198. @@ -87,7 +87,7 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
  199. #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
  200. #undef LINK_SPEC
  201. -#define LINK_SPEC "-m elf32_sparc %{shared:-shared} \
  202. +#define LINK_SPEC "-m elf32_sparc --as-needed %{shared:-shared} \
  203. %{!mno-relax:%{!r:-relax}} \
  204. %{!shared: \
  205. %{!static: \
  206. diff --git a/gcc/gcc.c b/gcc/gcc.c
  207. index 625c9ab7902..7aec9d3a016 100644
  208. --- a/gcc/gcc.c
  209. +++ b/gcc/gcc.c
  210. @@ -695,8 +695,11 @@ proper position among the other output files. */
  211. #ifdef LIBASAN_EARLY_SPEC
  212. #define LIBASAN_SPEC STATIC_LIBASAN_LIBS
  213. #elif defined(HAVE_LD_STATIC_DYNAMIC)
  214. -#define LIBASAN_SPEC "%{static-libasan:" LD_STATIC_OPTION \
  215. - "} -lasan %{static-libasan:" LD_DYNAMIC_OPTION "}" \
  216. +#define LIBASAN_SPEC "%{static-libasan:" LD_STATIC_OPTION "}" \
  217. + " %{!static-libasan:%{!fuse-ld=gold:--push-state }--no-as-needed}" \
  218. + " -lasan " \
  219. + " %{static-libasan:" LD_DYNAMIC_OPTION "}" \
  220. + " %{!static-libasan:%{fuse-ld=gold:--as-needed;:--pop-state}}" \
  221. STATIC_LIBASAN_LIBS
  222. #else
  223. #define LIBASAN_SPEC "-lasan" STATIC_LIBASAN_LIBS
  224. @@ -713,8 +716,11 @@ proper position among the other output files. */
  225. #ifdef LIBTSAN_EARLY_SPEC
  226. #define LIBTSAN_SPEC STATIC_LIBTSAN_LIBS
  227. #elif defined(HAVE_LD_STATIC_DYNAMIC)
  228. -#define LIBTSAN_SPEC "%{static-libtsan:" LD_STATIC_OPTION \
  229. - "} -ltsan %{static-libtsan:" LD_DYNAMIC_OPTION "}" \
  230. +#define LIBTSAN_SPEC "%{static-libtsan:" LD_STATIC_OPTION "}" \
  231. + " %{!static-libtsan:%{!fuse-ld=gold:--push-state }--no-as-needed}" \
  232. + " -ltsan " \
  233. + " %{static-libtsan:" LD_DYNAMIC_OPTION "}" \
  234. + " %{!static-libtsan:%{fuse-ld=gold:--as-needed;:--pop-state}}" \
  235. STATIC_LIBTSAN_LIBS
  236. #else
  237. #define LIBTSAN_SPEC "-ltsan" STATIC_LIBTSAN_LIBS
  238. @@ -731,8 +737,11 @@ proper position among the other output files. */
  239. #ifdef LIBLSAN_EARLY_SPEC
  240. #define LIBLSAN_SPEC STATIC_LIBLSAN_LIBS
  241. #elif defined(HAVE_LD_STATIC_DYNAMIC)
  242. -#define LIBLSAN_SPEC "%{static-liblsan:" LD_STATIC_OPTION \
  243. - "} -llsan %{static-liblsan:" LD_DYNAMIC_OPTION "}" \
  244. +#define LIBLSAN_SPEC "%{static-liblsan:" LD_STATIC_OPTION "}" \
  245. + " %{!static-liblsan:%{!fuse-ld=gold:--push-state }--no-as-needed}" \
  246. + " -llsan " \
  247. + " %{static-liblsan:" LD_DYNAMIC_OPTION "}" \
  248. + " %{!static-liblsan:%{fuse-ld=gold:--as-needed;:--pop-state}}" \
  249. STATIC_LIBLSAN_LIBS
  250. #else
  251. #define LIBLSAN_SPEC "-llsan" STATIC_LIBLSAN_LIBS
  252. @@ -747,8 +756,11 @@ proper position among the other output files. */
  253. #define STATIC_LIBUBSAN_LIBS \
  254. " %{static-libubsan|static:%:include(libsanitizer.spec)%(link_libubsan)}"
  255. #ifdef HAVE_LD_STATIC_DYNAMIC
  256. -#define LIBUBSAN_SPEC "%{static-libubsan:" LD_STATIC_OPTION \
  257. - "} -lubsan %{static-libubsan:" LD_DYNAMIC_OPTION "}" \
  258. +#define LIBUBSAN_SPEC "%{static-libubsan:" LD_STATIC_OPTION "}" \
  259. + " %{!static-libubsan:%{!fuse-ld=gold:--push-state }--no-as-needed}" \
  260. + " -lubsan " \
  261. + " %{static-libubsan:" LD_DYNAMIC_OPTION "}" \
  262. + " %{!static-libubsan:%{fuse-ld=gold:--as-needed;:--pop-state}}" \
  263. STATIC_LIBUBSAN_LIBS
  264. #else
  265. #define LIBUBSAN_SPEC "-lubsan" STATIC_LIBUBSAN_LIBS
  266. --
  267. 2.27.0