diff options
author | Arfrever Frehtes Taifersar Arahesis <Arfrever@Apache.Org> | 2017-06-14 16:23:15 +0200 |
---|---|---|
committer | Matthias Maier <tamiko@gentoo.org> | 2017-06-16 03:23:13 -0500 |
commit | d20b5a7065950144775848c1401c4f61a44ecd43 (patch) | |
tree | 787371704b41bbdb280850c57ed1c75123633705 /eclass | |
parent | dev-python/backports-functools-lru-cache: ia64 stable, bug #606288 (diff) | |
download | gentoo-d20b5a7065950144775848c1401c4f61a44ecd43.tar.gz gentoo-d20b5a7065950144775848c1401c4f61a44ecd43.tar.bz2 gentoo-d20b5a7065950144775848c1401c4f61a44ecd43.zip |
toolchain-funcs.eclass: Add functions for detection of PIE / SSP in way compatible with GCC >=6.
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 <tamiko@gentoo.org>
Diffstat (limited to 'eclass')
-rw-r--r-- | eclass/toolchain-funcs.eclass | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass index a0c359a950b2..121db46e62b5 100644 --- a/eclass/toolchain-funcs.eclass +++ b/eclass/toolchain-funcs.eclass @@ -792,6 +792,73 @@ 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() { + local ret="$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null + #if defined(__PIE__) + true + #endif + EOF + )" + [[ ${ret} == true ]] +} + +# @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() { + local ret="$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null + #if defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__) + true + #endif + EOF + )" + [[ ${ret} == true ]] +} + +# @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() { + local ret="$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null + #if defined(__SSP_STRONG__) || defined(__SSP_ALL__) + true + #endif + EOF + )" + [[ ${ret} == true ]] +} + +# @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() { + local ret="$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null + #if defined(__SSP_ALL__) + true + #endif + EOF + )" + [[ ${ret} == true ]] +} + + # @FUNCTION: gen_usr_ldscript # @USAGE: [-a] <list of libs to create linker scripts for> # @DESCRIPTION: |