public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH 1/5] toolchain-funcs.eclass: add tc-enables-fortify-source for FORTIFY_SOURCE
@ 2023-01-30  1:47 Sam James
  2023-01-30  1:47 ` [gentoo-dev] [PATCH 2/5] toolchain-funcs.eclass: add tc-enables-cxx-assertions Sam James
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Sam James @ 2023-01-30  1:47 UTC (permalink / raw
  To: gentoo-dev; +Cc: toolchain, Sam James

As Zero_Chaos reported on IRC, the check we had wasn't good enough in systemd*
(before we were able to remove it), as it wouldn't fire for e.g. -Os. While we
could've changed it to fail safe (always unset, then set a lower F_S if possible),
let's add a proper helper instead to the eclass.

Bug: https://bugs.gentoo.org/841770
Bug: https://bugs.gentoo.org/847148
Bug: https://bugs.gentoo.org/876893
Signed-off-by: Sam James <sam@gentoo.org>
---
 eclass/toolchain-funcs.eclass | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
index bfcd6819ed0b0..b9e956098b3e2 100644
--- a/eclass/toolchain-funcs.eclass
+++ b/eclass/toolchain-funcs.eclass
@@ -1,4 +1,4 @@
-# Copyright 2002-2022 Gentoo Authors
+# Copyright 2002-2023 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 # @ECLASS: toolchain-funcs.eclass
@@ -1006,6 +1006,15 @@ tc-enables-pie() {
 	tc-cpp-is-true "defined(__PIE__)" ${CPPFLAGS} ${CFLAGS}
 }
 
+# @FUNCTION: tc-enables-fortify-source
+# @RETURN: Truth if the current compiler enables FORTIFY_SOURCE at any level
+# @DESCRIPTION:
+# Return truth if the current compiler enables fortification (FORTIFY_SOURCE)
+# at any level (-D_FORTIFY_SOURCE).
+tc-enables-fortify-source() {
+	tc-cpp-is-true "defined(_FORTIFY_SOURCE)" ${CPPFLAGS} ${CFLAGS} ${CXXFLAGS}
+}
+
 # @FUNCTION: tc-enables-ssp
 # @RETURN: Truth if the current compiler enables stack smashing protection (SSP) on at least minimal level
 # @DESCRIPTION:
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [gentoo-dev] [PATCH 2/5] toolchain-funcs.eclass: add tc-enables-cxx-assertions
  2023-01-30  1:47 [gentoo-dev] [PATCH 1/5] toolchain-funcs.eclass: add tc-enables-fortify-source for FORTIFY_SOURCE Sam James
@ 2023-01-30  1:47 ` Sam James
  2023-01-30  1:47 ` [gentoo-dev] [PATCH 3/5] toolchain-funcs.eclass: include CXXFLAGS in various tc-enables-* checks Sam James
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Sam James @ 2023-01-30  1:47 UTC (permalink / raw
  To: gentoo-dev; +Cc: toolchain, Sam James

Bug: https://bugs.gentoo.org/884417
Bug: https://bugs.gentoo.org/876895
Signed-off-by: Sam James <sam@gentoo.org>
---
 eclass/toolchain-funcs.eclass | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
index b9e956098b3e2..d46104275f8e6 100644
--- a/eclass/toolchain-funcs.eclass
+++ b/eclass/toolchain-funcs.eclass
@@ -996,6 +996,15 @@ gcc-specs-stack-check() {
 	[[ "${directive/\{!fno-stack-check:}" != "${directive}" ]]
 }
 
+# @FUNCTION: tc-enables-cxx-assertions
+# @RETURN: Truth if the current compiler enables assertions in the C++ standard library
+# @DESCRIPTION:
+# Return truth if the current compiler enables assertions in the C++ standard
+# library. For libstdc++, this is -D_GLIBCXX_ASSERTIONS, and for libcxx/libc++,
+# this is -D_LIBCPP_ENABLE_ASSERTIONS.
+tc-enables-cxx-assertions() {
+	tc-cpp-is-true "defined(_GLIBCXX_ASSERTIONS) || defined(_LIBCPP_ENABLE_ASSERTIONS)" ${CPPFLAGS} ${CXXFLAGS}
+}
 
 # @FUNCTION: tc-enables-pie
 # @RETURN: Truth if the current compiler generates position-independent code (PIC) which can be linked into executables
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [gentoo-dev] [PATCH 3/5] toolchain-funcs.eclass: include CXXFLAGS in various tc-enables-* checks
  2023-01-30  1:47 [gentoo-dev] [PATCH 1/5] toolchain-funcs.eclass: add tc-enables-fortify-source for FORTIFY_SOURCE Sam James
  2023-01-30  1:47 ` [gentoo-dev] [PATCH 2/5] toolchain-funcs.eclass: add tc-enables-cxx-assertions Sam James
@ 2023-01-30  1:47 ` Sam James
  2023-01-30  1:47 ` [gentoo-dev] [PATCH 4/5] toolchain-funcs.eclass: style tweaks Sam James
  2023-01-30  1:47 ` [gentoo-dev] [PATCH 5/5] toolchain-funcs.eclass: consistently pass CPPFLAGS before C{,XX}FLAGS Sam James
  3 siblings, 0 replies; 5+ messages in thread
From: Sam James @ 2023-01-30  1:47 UTC (permalink / raw
  To: gentoo-dev; +Cc: toolchain, Sam James

SSP and PIE are relevant to C++ too.

Signed-off-by: Sam James <sam@gentoo.org>
---
 eclass/toolchain-funcs.eclass | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
index d46104275f8e6..840111f6cc30d 100644
--- a/eclass/toolchain-funcs.eclass
+++ b/eclass/toolchain-funcs.eclass
@@ -1012,7 +1012,7 @@ tc-enables-cxx-assertions() {
 # Return truth if the current compiler generates position-independent code (PIC)
 # which can be linked into executables.
 tc-enables-pie() {
-	tc-cpp-is-true "defined(__PIE__)" ${CPPFLAGS} ${CFLAGS}
+	tc-cpp-is-true "defined(__PIE__)" ${CPPFLAGS} ${CFLAGS} ${CXXFLAGS}
 }
 
 # @FUNCTION: tc-enables-fortify-source
@@ -1033,7 +1033,7 @@ tc-enables-fortify-source() {
 #  -fstack-protector-strong
 #  -fstack-protector-all
 tc-enables-ssp() {
-	tc-cpp-is-true "defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS}
+	tc-cpp-is-true "defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS} ${CXXFLAGS}
 }
 
 # @FUNCTION: tc-enables-ssp-strong
@@ -1044,7 +1044,7 @@ tc-enables-ssp() {
 #  -fstack-protector-strong
 #  -fstack-protector-all
 tc-enables-ssp-strong() {
-	tc-cpp-is-true "defined(__SSP_STRONG__) || defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS}
+	tc-cpp-is-true "defined(__SSP_STRONG__) || defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS} ${CXXFLAGS}
 }
 
 # @FUNCTION: tc-enables-ssp-all
@@ -1054,7 +1054,7 @@ tc-enables-ssp-strong() {
 # on level corresponding to any of the following options:
 #  -fstack-protector-all
 tc-enables-ssp-all() {
-	tc-cpp-is-true "defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS}
+	tc-cpp-is-true "defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS} ${CXXFLAGS}
 }
 
 
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [gentoo-dev] [PATCH 4/5] toolchain-funcs.eclass: style tweaks
  2023-01-30  1:47 [gentoo-dev] [PATCH 1/5] toolchain-funcs.eclass: add tc-enables-fortify-source for FORTIFY_SOURCE Sam James
  2023-01-30  1:47 ` [gentoo-dev] [PATCH 2/5] toolchain-funcs.eclass: add tc-enables-cxx-assertions Sam James
  2023-01-30  1:47 ` [gentoo-dev] [PATCH 3/5] toolchain-funcs.eclass: include CXXFLAGS in various tc-enables-* checks Sam James
@ 2023-01-30  1:47 ` Sam James
  2023-01-30  1:47 ` [gentoo-dev] [PATCH 5/5] toolchain-funcs.eclass: consistently pass CPPFLAGS before C{,XX}FLAGS Sam James
  3 siblings, 0 replies; 5+ messages in thread
From: Sam James @ 2023-01-30  1:47 UTC (permalink / raw
  To: gentoo-dev; +Cc: toolchain, Sam James

Signed-off-by: Sam James <sam@gentoo.org>
---
 eclass/toolchain-funcs.eclass | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
index 840111f6cc30d..9bb660e4f71f3 100644
--- a/eclass/toolchain-funcs.eclass
+++ b/eclass/toolchain-funcs.eclass
@@ -422,19 +422,19 @@ tc-env_build() {
 # src_configure() {
 # 	ECONF_SOURCE=${S}
 # 	if tc-is-cross-compiler ; then
-# 		mkdir "${WORKDIR}"/${CBUILD}
-# 		pushd "${WORKDIR}"/${CBUILD} >/dev/null
+# 		mkdir "${WORKDIR}"/${CBUILD} || die
+# 		pushd "${WORKDIR}"/${CBUILD} >/dev/null || die
 # 		econf_build --disable-some-unused-stuff
-# 		popd >/dev/null
+# 		popd >/dev/null || die
 # 	fi
 # 	... normal build paths ...
 # }
 # src_compile() {
 # 	if tc-is-cross-compiler ; then
-# 		pushd "${WORKDIR}"/${CBUILD} >/dev/null
+# 		pushd "${WORKDIR}"/${CBUILD} >/dev/null || die
 # 		emake one-or-two-build-tools
-# 		ln/mv build-tools to normal build paths in ${S}/
-# 		popd >/dev/null
+# 		ln/mv build-tools to normal build paths in ${S}/ || die
+# 		popd >/dev/null || die
 # 	fi
 # 	... normal build paths ...
 # }
@@ -676,7 +676,7 @@ tc-has-tls() {
 # Parse information from CBUILD/CHOST/CTARGET rather than
 # use external variables from the profile.
 tc-ninja_magic_to_arch() {
-ninj() { [[ ${type} == "kern" ]] && echo $1 || echo $2 ; }
+	ninj() { [[ ${type} == "kern" ]] && echo $1 || echo $2 ; }
 
 	local type=$1
 	local host=$2
@@ -815,8 +815,8 @@ tc-get-compiler-type() {
 	case ${res} in
 		*HAVE_PATHCC*)	echo pathcc;;
 		*HAVE_CLANG*)	echo clang;;
-		*HAVE_GCC*)		echo gcc;;
-		*)				echo unknown;;
+		*HAVE_GCC*)	echo gcc;;
+		*)		echo unknown;;
 	esac
 }
 
@@ -834,11 +834,11 @@ tc-is-clang() {
 
 # Internal func.  The first argument is the version info to expand.
 # Query the preprocessor to improve compatibility across different
-# compilers rather than maintaining a --version flag matrix. #335943
+# compilers rather than maintaining a --version flag matrix, bug #335943.
 _gcc_fullversion() {
 	local ver="$1"; shift
 	set -- $($(tc-getCPP "$@") -E -P - <<<"__GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__")
-	eval echo "$ver"
+	eval echo "${ver}"
 }
 
 # @FUNCTION: gcc-fullversion
@@ -871,7 +871,7 @@ gcc-micro-version() {
 _clang_fullversion() {
 	local ver="$1"; shift
 	set -- $($(tc-getCPP "$@") -E -P - <<<"__clang_major__ __clang_minor__ __clang_patchlevel__")
-	eval echo "$ver"
+	eval echo "${ver}"
 }
 
 # @FUNCTION: clang-fullversion
@@ -1098,7 +1098,7 @@ gen_usr_ldscript() {
 	# is referenced ... makes multilib saner
 	local flags=( ${CFLAGS} ${LDFLAGS} -Wl,--verbose )
 	if $(tc-getLD) --version | grep -q 'GNU gold' ; then
-		# If they're using gold, manually invoke the old bfd. #487696
+		# If they're using gold, manually invoke the old bfd, bug #487696
 		local d="${T}/bfd-linker"
 		mkdir -p "${d}"
 		ln -sf $(type -P ${CHOST}-ld.bfd) "${d}"/ld
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [gentoo-dev] [PATCH 5/5] toolchain-funcs.eclass: consistently pass CPPFLAGS before C{,XX}FLAGS
  2023-01-30  1:47 [gentoo-dev] [PATCH 1/5] toolchain-funcs.eclass: add tc-enables-fortify-source for FORTIFY_SOURCE Sam James
                   ` (2 preceding siblings ...)
  2023-01-30  1:47 ` [gentoo-dev] [PATCH 4/5] toolchain-funcs.eclass: style tweaks Sam James
@ 2023-01-30  1:47 ` Sam James
  3 siblings, 0 replies; 5+ messages in thread
From: Sam James @ 2023-01-30  1:47 UTC (permalink / raw
  To: gentoo-dev; +Cc: toolchain, Sam James

This is generally what we do in patches and such.

Signed-off-by: Sam James <sam@gentoo.org>
---
 eclass/toolchain-funcs.eclass | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
index 9bb660e4f71f3..c2c2d1199155d 100644
--- a/eclass/toolchain-funcs.eclass
+++ b/eclass/toolchain-funcs.eclass
@@ -1211,7 +1211,7 @@ tc-get-cxx-stdlib() {
 #endif
 '
 	local res=$(
-		$(tc-getCXX) ${CXXFLAGS} ${CPPFLAGS} -x c++ -E -P - \
+		$(tc-getCXX) ${CPPFLAGS} ${CXXFLAGS} -x c++ -E -P - \
 			<<<"${code}" 2>/dev/null
 	)
 
@@ -1239,7 +1239,7 @@ tc-get-cxx-stdlib() {
 # If the runtime is not recognized, the function returns 1.
 tc-get-c-rtlib() {
 	local res=$(
-		$(tc-getCC) ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} \
+		$(tc-getCC) ${CPPFLAGS} ${CFLAGS} ${LDFLAGS} \
 			-print-libgcc-file-name 2>/dev/null
 	)
 
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-01-30  1:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-30  1:47 [gentoo-dev] [PATCH 1/5] toolchain-funcs.eclass: add tc-enables-fortify-source for FORTIFY_SOURCE Sam James
2023-01-30  1:47 ` [gentoo-dev] [PATCH 2/5] toolchain-funcs.eclass: add tc-enables-cxx-assertions Sam James
2023-01-30  1:47 ` [gentoo-dev] [PATCH 3/5] toolchain-funcs.eclass: include CXXFLAGS in various tc-enables-* checks Sam James
2023-01-30  1:47 ` [gentoo-dev] [PATCH 4/5] toolchain-funcs.eclass: style tweaks Sam James
2023-01-30  1:47 ` [gentoo-dev] [PATCH 5/5] toolchain-funcs.eclass: consistently pass CPPFLAGS before C{,XX}FLAGS Sam James

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox