diff mbox

toolchain: improve SSP logic

Message ID 1457453323-11947-1-git-send-email-Vincent.Riera@imgtec.com
State Superseded
Headers show

Commit Message

Vicente Olivert Riera March 8, 2016, 4:08 p.m. UTC
Don't enable SSP support on toolchains just because they use glibc or
musl. Instead of that, make the toolchains to declare if they support
SSP or not. And also add a check to detect SSP support when using custom
external toolchains.

Signed-off-by: Vicente Olivert Riera <Vincent.Riera@imgtec.com>
---
 toolchain/Config.in                                |  2 --
 toolchain/helpers.mk                               | 17 ++++++++++++++++
 toolchain/toolchain-external/Config.in             | 23 ++++++++++++++++++++--
 toolchain/toolchain-external/toolchain-external.mk |  1 +
 4 files changed, 39 insertions(+), 4 deletions(-)

Comments

Thomas Petazzoni March 8, 2016, 4:13 p.m. UTC | #1
Hello Vicente,

On Tue, 8 Mar 2016 16:08:43 +0000, Vicente Olivert Riera wrote:
> Don't enable SSP support on toolchains just because they use glibc or
> musl. Instead of that, make the toolchains to declare if they support
> SSP or not. And also add a check to detect SSP support when using custom
> external toolchains.
> 
> Signed-off-by: Vicente Olivert Riera <Vincent.Riera@imgtec.com>
> ---
>  toolchain/Config.in                                |  2 --
>  toolchain/helpers.mk                               | 17 ++++++++++++++++
>  toolchain/toolchain-external/Config.in             | 23 ++++++++++++++++++++--
>  toolchain/toolchain-external/toolchain-external.mk |  1 +
>  4 files changed, 39 insertions(+), 4 deletions(-)
> 
> diff --git a/toolchain/Config.in b/toolchain/Config.in
> index fc30c6e..e0044c1 100644
> --- a/toolchain/Config.in
> +++ b/toolchain/Config.in
> @@ -15,7 +15,6 @@ config BR2_TOOLCHAIN_USES_GLIBC
>  	select BR2_TOOLCHAIN_HAS_THREADS_DEBUG
>  	select BR2_TOOLCHAIN_HAS_THREADS_NPTL
>  	select BR2_TOOLCHAIN_HAS_SHADOW_PASSWORDS
> -	select BR2_TOOLCHAIN_HAS_SSP
>  
>  config BR2_TOOLCHAIN_USES_UCLIBC
>  	bool
> @@ -27,7 +26,6 @@ config BR2_TOOLCHAIN_USES_MUSL
>  	select BR2_TOOLCHAIN_HAS_THREADS
>  	select BR2_TOOLCHAIN_HAS_THREADS_DEBUG
>  	select BR2_TOOLCHAIN_HAS_THREADS_NPTL
> -	select BR2_TOOLCHAIN_HAS_SSP
>  
>  choice
>  	prompt "Toolchain type"

I think this patch is incomplete because you are now saying that all
glibc and musl toolchains no longer have SSP support, and only
re-enable SSP support for external toolchains on a per-toolchain basis.
Sounds good for external toolchains.

But what about internal glibc and musl toolchains ?

Best regards,

Thomas
Vicente Olivert Riera March 8, 2016, 4:18 p.m. UTC | #2
Hello Thomas,

On 08/03/16 16:13, Thomas Petazzoni wrote:
> Hello Vicente,
> 
> On Tue, 8 Mar 2016 16:08:43 +0000, Vicente Olivert Riera wrote:
>> Don't enable SSP support on toolchains just because they use glibc or
>> musl. Instead of that, make the toolchains to declare if they support
>> SSP or not. And also add a check to detect SSP support when using custom
>> external toolchains.
>>
>> Signed-off-by: Vicente Olivert Riera <Vincent.Riera@imgtec.com>
>> ---
>>  toolchain/Config.in                                |  2 --
>>  toolchain/helpers.mk                               | 17 ++++++++++++++++
>>  toolchain/toolchain-external/Config.in             | 23 ++++++++++++++++++++--
>>  toolchain/toolchain-external/toolchain-external.mk |  1 +
>>  4 files changed, 39 insertions(+), 4 deletions(-)
>>
>> diff --git a/toolchain/Config.in b/toolchain/Config.in
>> index fc30c6e..e0044c1 100644
>> --- a/toolchain/Config.in
>> +++ b/toolchain/Config.in
>> @@ -15,7 +15,6 @@ config BR2_TOOLCHAIN_USES_GLIBC
>>  	select BR2_TOOLCHAIN_HAS_THREADS_DEBUG
>>  	select BR2_TOOLCHAIN_HAS_THREADS_NPTL
>>  	select BR2_TOOLCHAIN_HAS_SHADOW_PASSWORDS
>> -	select BR2_TOOLCHAIN_HAS_SSP
>>  
>>  config BR2_TOOLCHAIN_USES_UCLIBC
>>  	bool
>> @@ -27,7 +26,6 @@ config BR2_TOOLCHAIN_USES_MUSL
>>  	select BR2_TOOLCHAIN_HAS_THREADS
>>  	select BR2_TOOLCHAIN_HAS_THREADS_DEBUG
>>  	select BR2_TOOLCHAIN_HAS_THREADS_NPTL
>> -	select BR2_TOOLCHAIN_HAS_SSP
>>  
>>  choice
>>  	prompt "Toolchain type"
> 
> I think this patch is incomplete because you are now saying that all
> glibc and musl toolchains no longer have SSP support, and only
> re-enable SSP support for external toolchains on a per-toolchain basis.
> Sounds good for external toolchains.
> 
> But what about internal glibc and musl toolchains ?

you're right, I forgot about the internal ones! Ooops :P

Regards,

Vincent.

> Best regards,
> 
> Thomas
>
diff mbox

Patch

diff --git a/toolchain/Config.in b/toolchain/Config.in
index fc30c6e..e0044c1 100644
--- a/toolchain/Config.in
+++ b/toolchain/Config.in
@@ -15,7 +15,6 @@  config BR2_TOOLCHAIN_USES_GLIBC
 	select BR2_TOOLCHAIN_HAS_THREADS_DEBUG
 	select BR2_TOOLCHAIN_HAS_THREADS_NPTL
 	select BR2_TOOLCHAIN_HAS_SHADOW_PASSWORDS
-	select BR2_TOOLCHAIN_HAS_SSP
 
 config BR2_TOOLCHAIN_USES_UCLIBC
 	bool
@@ -27,7 +26,6 @@  config BR2_TOOLCHAIN_USES_MUSL
 	select BR2_TOOLCHAIN_HAS_THREADS
 	select BR2_TOOLCHAIN_HAS_THREADS_DEBUG
 	select BR2_TOOLCHAIN_HAS_THREADS_NPTL
-	select BR2_TOOLCHAIN_HAS_SSP
 
 choice
 	prompt "Toolchain type"
diff --git a/toolchain/helpers.mk b/toolchain/helpers.mk
index ee878e8..286b24c 100644
--- a/toolchain/helpers.mk
+++ b/toolchain/helpers.mk
@@ -421,6 +421,23 @@  check_unusable_toolchain = \
 	fi
 
 #
+# Check if the toolchain has SSP (stack smashing protector) support
+#
+# $1: cross-gcc path
+#
+check_toolchain_ssp = \
+	__CROSS_CC=$(strip $1) ; \
+	__HAS_SSP=`echo 'void main(){}' | $${__CROSS_CC} -fstack-protector -x c - > /dev/null 2>&1 && echo y` ; \
+	if [ "$(BR2_TOOLCHAIN_HAS_SSP)" != "y" -a "$${__HAS_SSP}" = "y" ] ; then \
+		echo "SSP support available in this toolchain, please enable BR2_TOOLCHAIN_EXTERNAL_HAS_SSP" ; \
+		exit 1 ; \
+	fi ; \
+	if [ "$(BR2_TOOLCHAIN_HAS_SSP)" = "y" -a "$${__HAS_SSP}" != "y" ] ; then \
+		echo "SSP support not available in this toolchain, please disable BR2_TOOLCHAIN_EXTERNAL_HAS_SSP" ; \
+		exit 1 ; \
+	fi
+
+#
 # Generate gdbinit file for use with Buildroot
 #
 gen_gdbinit_file = \
diff --git a/toolchain/toolchain-external/Config.in b/toolchain/toolchain-external/Config.in
index 0f9f7b8..2144055 100644
--- a/toolchain/toolchain-external/Config.in
+++ b/toolchain/toolchain-external/Config.in
@@ -22,6 +22,7 @@  config BR2_TOOLCHAIN_EXTERNAL_LINARO_ARM
 	depends on BR2_ARM_EABIHF
 	depends on !BR2_STATIC_LIBS
 	select BR2_TOOLCHAIN_EXTERNAL_GLIBC
+	select BR2_TOOLCHAIN_EXTERNAL_HAS_SSP
 	select BR2_TOOLCHAIN_HAS_NATIVE_RPC
 	select BR2_INSTALL_LIBSTDCPP
 	select BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_1
@@ -44,6 +45,7 @@  config BR2_TOOLCHAIN_EXTERNAL_LINARO_ARM
 	depends on BR2_ARM_EABIHF
 	depends on !BR2_STATIC_LIBS
 	select BR2_TOOLCHAIN_EXTERNAL_GLIBC
+	select BR2_TOOLCHAIN_EXTERNAL_HAS_SSP
 	select BR2_TOOLCHAIN_HAS_NATIVE_RPC
 	select BR2_INSTALL_LIBSTDCPP
 	select BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_0
@@ -66,6 +68,7 @@  config BR2_TOOLCHAIN_EXTERNAL_LINARO_ARMEB
 	depends on BR2_ARM_EABIHF
 	depends on !BR2_STATIC_LIBS
 	select BR2_TOOLCHAIN_EXTERNAL_GLIBC
+	select BR2_TOOLCHAIN_EXTERNAL_HAS_SSP
 	select BR2_TOOLCHAIN_HAS_NATIVE_RPC
 	select BR2_INSTALL_LIBSTDCPP
 	select BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_1
@@ -88,6 +91,7 @@  config BR2_TOOLCHAIN_EXTERNAL_LINARO_ARMEB
 	depends on BR2_ARM_EABIHF
 	depends on !BR2_STATIC_LIBS
 	select BR2_TOOLCHAIN_EXTERNAL_GLIBC
+	select BR2_TOOLCHAIN_EXTERNAL_HAS_SSP
 	select BR2_TOOLCHAIN_HAS_NATIVE_RPC
 	select BR2_INSTALL_LIBSTDCPP
 	select BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_0
@@ -108,6 +112,7 @@  config BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_ARM
 	depends on BR2_ARM_EABI
 	depends on !BR2_STATIC_LIBS
 	select BR2_TOOLCHAIN_EXTERNAL_GLIBC
+	select BR2_TOOLCHAIN_EXTERNAL_HAS_SSP
 	select BR2_TOOLCHAIN_HAS_NATIVE_RPC
 	select BR2_INSTALL_LIBSTDCPP
 	select BR2_HOSTARCH_NEEDS_IA32_LIBS
@@ -143,6 +148,7 @@  config BR2_TOOLCHAIN_EXTERNAL_ARAGO_ARMV7A
 	depends on BR2_ARM_CPU_HAS_VFPV3
 	depends on !BR2_STATIC_LIBS
 	select BR2_TOOLCHAIN_EXTERNAL_GLIBC
+	select BR2_TOOLCHAIN_EXTERNAL_HAS_SSP
 	select BR2_TOOLCHAIN_HAS_NATIVE_RPC
 	select BR2_INSTALL_LIBSTDCPP
 	select BR2_HOSTARCH_NEEDS_IA32_LIBS
@@ -166,6 +172,7 @@  config BR2_TOOLCHAIN_EXTERNAL_ARAGO_ARMV5TE
 	depends on BR2_ARM_EABI
 	depends on !BR2_STATIC_LIBS
 	select BR2_TOOLCHAIN_EXTERNAL_GLIBC
+	select BR2_TOOLCHAIN_EXTERNAL_HAS_SSP
 	select BR2_TOOLCHAIN_HAS_NATIVE_RPC
 	select BR2_INSTALL_LIBSTDCPP
 	select BR2_HOSTARCH_NEEDS_IA32_LIBS
@@ -185,6 +192,7 @@  config BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_MIPS
 	depends on !BR2_MIPS_NABI32
 	depends on !BR2_STATIC_LIBS
 	select BR2_TOOLCHAIN_EXTERNAL_GLIBC
+	select BR2_TOOLCHAIN_EXTERNAL_HAS_SSP
 	select BR2_TOOLCHAIN_HAS_NATIVE_RPC
 	select BR2_INSTALL_LIBSTDCPP
 	select BR2_HOSTARCH_NEEDS_IA32_LIBS
@@ -369,6 +377,7 @@  config BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_NIOSII
 	depends on BR2_HOSTARCH = "x86_64" || BR2_HOSTARCH = "x86"
 	depends on !BR2_STATIC_LIBS
 	select BR2_TOOLCHAIN_EXTERNAL_GLIBC
+	select BR2_TOOLCHAIN_EXTERNAL_HAS_SSP
 	select BR2_TOOLCHAIN_HAS_NATIVE_RPC
 	select BR2_INSTALL_LIBSTDCPP
 	select BR2_HOSTARCH_NEEDS_IA32_LIBS
@@ -386,6 +395,7 @@  config BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_POWERPC_E500V2
 	depends on BR2_HOSTARCH = "x86_64" || BR2_HOSTARCH = "x86"
 	depends on !BR2_STATIC_LIBS
 	select BR2_TOOLCHAIN_EXTERNAL_GLIBC
+	select BR2_TOOLCHAIN_EXTERNAL_HAS_SSP
 	select BR2_TOOLCHAIN_HAS_NATIVE_RPC
 	select BR2_INSTALL_LIBSTDCPP
 	select BR2_HOSTARCH_NEEDS_IA32_LIBS
@@ -404,6 +414,7 @@  config BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_POWERPC
 	depends on BR2_HOSTARCH = "x86_64" || BR2_HOSTARCH = "x86"
 	depends on !BR2_STATIC_LIBS
 	select BR2_TOOLCHAIN_EXTERNAL_GLIBC
+	select BR2_TOOLCHAIN_EXTERNAL_HAS_SSP
 	select BR2_TOOLCHAIN_HAS_NATIVE_RPC
 	select BR2_INSTALL_LIBSTDCPP
 	select BR2_HOSTARCH_NEEDS_IA32_LIBS
@@ -437,6 +448,7 @@  config BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_SH
 	depends on BR2_HOSTARCH = "x86_64" || BR2_HOSTARCH = "x86"
 	depends on !BR2_STATIC_LIBS
 	select BR2_TOOLCHAIN_EXTERNAL_GLIBC
+	select BR2_TOOLCHAIN_EXTERNAL_HAS_SSP
 	select BR2_TOOLCHAIN_HAS_NATIVE_RPC
 	select BR2_INSTALL_LIBSTDCPP
 	select BR2_HOSTARCH_NEEDS_IA32_LIBS
@@ -463,6 +475,7 @@  config BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_AMD64
 	depends on !BR2_STATIC_LIBS
 	depends on BR2_x86_jaguar || BR2_x86_steamroller
 	select BR2_TOOLCHAIN_EXTERNAL_GLIBC
+	select BR2_TOOLCHAIN_EXTERNAL_HAS_SSP
 	select BR2_TOOLCHAIN_HAS_NATIVE_RPC
 	select BR2_INSTALL_LIBSTDCPP
 	select BR2_HOSTARCH_NEEDS_IA32_LIBS
@@ -488,6 +501,7 @@  config BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_X86
 	depends on !BR2_x86_jaguar
 	depends on !BR2_x86_steamroller
 	select BR2_TOOLCHAIN_EXTERNAL_GLIBC
+	select BR2_TOOLCHAIN_EXTERNAL_HAS_SSP
 	select BR2_TOOLCHAIN_HAS_NATIVE_RPC
 	select BR2_INSTALL_LIBSTDCPP
 	select BR2_HOSTARCH_NEEDS_IA32_LIBS
@@ -533,6 +547,7 @@  config BR2_TOOLCHAIN_EXTERNAL_LINARO_AARCH64
 	depends on BR2_HOSTARCH = "x86"
 	depends on !BR2_STATIC_LIBS
 	select BR2_TOOLCHAIN_EXTERNAL_GLIBC
+	select BR2_TOOLCHAIN_EXTERNAL_HAS_SSP
 	select BR2_INSTALL_LIBSTDCPP
 	select BR2_TOOLCHAIN_HAS_NATIVE_RPC
 	select BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_7
@@ -548,6 +563,7 @@  config BR2_TOOLCHAIN_EXTERNAL_LINARO_AARCH64
 	depends on BR2_HOSTARCH = "x86_64"
 	depends on !BR2_STATIC_LIBS
 	select BR2_TOOLCHAIN_EXTERNAL_GLIBC
+	select BR2_TOOLCHAIN_EXTERNAL_HAS_SSP
 	select BR2_INSTALL_LIBSTDCPP
 	select BR2_TOOLCHAIN_HAS_NATIVE_RPC
 	select BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_0
@@ -562,6 +578,7 @@  config BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_AARCH64
 	depends on BR2_HOSTARCH = "x86_64" || BR2_HOSTARCH = "x86"
 	depends on !BR2_STATIC_LIBS
 	select BR2_TOOLCHAIN_EXTERNAL_GLIBC
+	select BR2_TOOLCHAIN_EXTERNAL_HAS_SSP
 	select BR2_INSTALL_LIBSTDCPP
 	select BR2_HOSTARCH_NEEDS_IA32_LIBS
 	select BR2_TOOLCHAIN_HAS_NATIVE_RPC
@@ -586,6 +603,7 @@  config BR2_TOOLCHAIN_EXTERNAL_MUSL_CROSS
 	# Unsupported for MIPS R6
 	depends on !BR2_mips_32r6 && !BR2_mips_64r6
 	select BR2_TOOLCHAIN_EXTERNAL_MUSL
+	select BR2_TOOLCHAIN_EXTERNAL_HAS_SSP
 	select BR2_INSTALL_LIBSTDCPP
 	select BR2_HOSTARCH_NEEDS_IA32_LIBS
 	select BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_12
@@ -975,17 +993,18 @@  config BR2_TOOLCHAIN_EXTERNAL_HAS_THREADS_NPTL
 
 endif # BR2_TOOLCHAIN_EXTERNAL_HAS_THREADS
 
+endif # BR2_TOOLCHAIN_EXTERNAL_CUSTOM_UCLIBC
+
 config BR2_TOOLCHAIN_EXTERNAL_HAS_SSP
 	bool "Toolchain has SSP support?"
 	select BR2_TOOLCHAIN_HAS_SSP
+	default y if BR2_TOOLCHAIN_EXTERNAL_GLIBC || BR2_TOOLCHAIN_EXTERNAL_MUSL
 	help
 	  Selection this option if your external toolchain has Stack
 	  Smashing Protection support enabled. If you don't know,
 	  leave the default value, Buildroot will tell you if it's
 	  correct or not.
 
-endif # BR2_TOOLCHAIN_EXTERNAL_CUSTOM_UCLIBC
-
 config BR2_TOOLCHAIN_EXTERNAL_INET_RPC
 	bool "Toolchain has RPC support?"
 	select BR2_TOOLCHAIN_HAS_NATIVE_RPC
diff --git a/toolchain/toolchain-external/toolchain-external.mk b/toolchain/toolchain-external/toolchain-external.mk
index 38bc59b..73ddac8 100644
--- a/toolchain/toolchain-external/toolchain-external.mk
+++ b/toolchain/toolchain-external/toolchain-external.mk
@@ -502,6 +502,7 @@  define TOOLCHAIN_EXTERNAL_CONFIGURE_CMDS
 	else \
 		$(call check_glibc,$${SYSROOT_DIR}) ; \
 	fi
+	$(Q)$(call check_toolchain_ssp,$(TOOLCHAIN_EXTERNAL_CC))
 endef
 
 # With the musl C library, the libc.so library directly plays the role