From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 8664E139694 for ; Wed, 14 Jun 2017 23:17:08 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 362DB21C1E9; Wed, 14 Jun 2017 23:16:01 +0000 (UTC) Received: from tsukuyomi.43-1.org (tsukuyomi.43-1.org [188.40.248.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id D991821C1D7 for ; Wed, 14 Jun 2017 23:15:57 +0000 (UTC) From: Matthias Maier To: gentoo-dev@lists.gentoo.org Cc: toolchain@gentoo.org, embedded@gentoo.org, Matthias Maier Subject: [gentoo-dev] [PATCH 1/5] toolchain-funcs.eclass: Add functions for detection of PIE / SSP in way compatible with GCC >=6. Date: Wed, 14 Jun 2017 18:15:37 -0500 Message-Id: <20170614231541.29719-2-tamiko@gentoo.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170614231541.29719-1-tamiko@gentoo.org> References: <20170614231541.29719-1-tamiko@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Archives-Salt: ee99df51-8301-47e4-a963-bcb00944678d X-Archives-Hash: 1d75a50a8aa6a0de566f6e535d4c5538 From: Arfrever Frehtes Taifersar Arahesis Newly added tc-enables-pie(), tc-enables-ssp(), tc-enables-ssp-strong() and tc-enables-ssp-all() check macros instead of specs. This solution also works with older GCC and with Clang. Signed-off-by: Matthias Maier --- eclass/toolchain-funcs.eclass | 71 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass index a0c359a950..3658c40518 100644 --- a/eclass/toolchain-funcs.eclass +++ b/eclass/toolchain-funcs.eclass @@ -792,6 +792,77 @@ gcc-specs-stack-check() { } +# @FUNCTION: tc-enables-pie +# @RETURN: Truth if the current compiler generates position-independent code (PIC) which can be linked into executables +# @DESCRIPTION: +# Return truth if the current compiler generates position-independent code (PIC) +# which can be linked into executables. +tc-enables-pie() { + $($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null + #if defined(__PIE__) + true + #else + false + #endif + EOF + ) +} + +# @FUNCTION: tc-enables-ssp +# @RETURN: Truth if the current compiler enables stack smashing protection (SSP) on at least minimal level +# @DESCRIPTION: +# Return truth if the current compiler enables stack smashing protection (SSP) +# on level corresponding to any of the following options: +# -fstack-protector +# -fstack-protector-strong +# -fstack-protector-all +tc-enables-ssp() { + $($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null + #if defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__) + true + #else + false + #endif + EOF + ) +} + +# @FUNCTION: tc-enables-ssp-strong +# @RETURN: Truth if the current compiler enables stack smashing protection (SSP) on at least middle level +# @DESCRIPTION: +# Return truth if the current compiler enables stack smashing protection (SSP) +# on level corresponding to any of the following options: +# -fstack-protector-strong +# -fstack-protector-all +tc-enables-ssp-strong() { + $($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null + #if defined(__SSP_STRONG__) || defined(__SSP_ALL__) + true + #else + false + #endif + EOF + ) +} + +# @FUNCTION: tc-enables-ssp-all +# @RETURN: Truth if the current compiler enables stack smashing protection (SSP) on maximal level +# @DESCRIPTION: +# Return truth if the current compiler enables stack smashing protection (SSP) +# on level corresponding to any of the following options: +# -fstack-protector-all +tc-enables-ssp-all() { + $($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null + #if defined(__SSP_ALL__) + true + #else + false + #endif + EOF + ) +} + + # @FUNCTION: gen_usr_ldscript # @USAGE: [-a] # @DESCRIPTION: -- 2.13.0