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