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