public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [arm17] [PATCH 0/3] toolchain-funcs.eclass: tc-is-softfloat for ARM and associated functions
@ 2018-08-14 20:33 James Le Cuirot
  2018-08-14 20:33 ` [gentoo-dev] [arm17] [PATCH 1/3] toolchain-funcs.eclass: New tc-getTARGET_CPP function James Le Cuirot
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: James Le Cuirot @ 2018-08-14 20:33 UTC (permalink / raw
  To: gentoo-dev; +Cc: James Le Cuirot

I previously sent a single patch to this list entitled
"Update tc-is-softfloat for new ARM tuples" but I have now added two
further patches following the initial feedback.

For the additional background behind these changes, please see:
https://archives.gentoo.org/gentoo-dev/message/b55b141e76ae1e08279d6f5b33be8151

James Le Cuirot (3):
  toolchain-funcs.eclass: New tc-getTARGET_CPP function
  toolchain-funcs.eclass: tc-cpp-is-true function to simplify helpers
  toolchain-funcs.eclass: Update tc-is-softfloat for new ARM tuples

 eclass/toolchain-funcs.eclass | 138 +++++++++++++++++++++++-----------
 1 file changed, 96 insertions(+), 42 deletions(-)

-- 
2.17.0



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

* [gentoo-dev] [arm17] [PATCH 1/3] toolchain-funcs.eclass: New tc-getTARGET_CPP function
  2018-08-14 20:33 [gentoo-dev] [arm17] [PATCH 0/3] toolchain-funcs.eclass: tc-is-softfloat for ARM and associated functions James Le Cuirot
@ 2018-08-14 20:33 ` James Le Cuirot
  2018-08-14 20:33 ` [gentoo-dev] [arm17] [PATCH 2/3] toolchain-funcs.eclass: tc-cpp-is-true function to simplify helpers James Le Cuirot
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: James Le Cuirot @ 2018-08-14 20:33 UTC (permalink / raw
  To: gentoo-dev; +Cc: James Le Cuirot

This returns the name of the C preprocessor for the toolchain being
built if CTARGET is defined, or the toolchain being used otherwise. It
is primarily intended to determine characteristics about an existing
toolchain's target as these may differ from what the tuple suggests.

It is not necessary to add the full set of tc-getTARGET_* helper
functions as this is probably the only reason we would ever invoke a
toolchain in the context of CTARGET.
---
 eclass/toolchain-funcs.eclass | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
index cea8949b45d7..fbd1a8d5e2bf 100644
--- a/eclass/toolchain-funcs.eclass
+++ b/eclass/toolchain-funcs.eclass
@@ -167,6 +167,17 @@ tc-getBUILD_OBJCOPY() { tc-getBUILD_PROG OBJCOPY objcopy "$@"; }
 # @RETURN: name of the pkg-config tool for building binaries to run on the build machine
 tc-getBUILD_PKG_CONFIG() { tc-getBUILD_PROG PKG_CONFIG pkg-config "$@"; }
 
+# @FUNCTION: tc-getTARGET_CPP
+# @USAGE: [toolchain prefix]
+# @RETURN: name of the C preprocessor for the toolchain being built (or used)
+tc-getTARGET_CPP() {
+	if [[ -n ${CTARGET} ]]; then
+		_tc-getPROG CTARGET TARGET_CPP "gcc -E" "$@"
+	else
+		tc-getCPP "$@"
+	fi
+}
+
 # @FUNCTION: tc-export
 # @USAGE: <list of toolchain variables>
 # @DESCRIPTION:
-- 
2.17.0



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

* [gentoo-dev] [arm17] [PATCH 2/3] toolchain-funcs.eclass: tc-cpp-is-true function to simplify helpers
  2018-08-14 20:33 [gentoo-dev] [arm17] [PATCH 0/3] toolchain-funcs.eclass: tc-is-softfloat for ARM and associated functions James Le Cuirot
  2018-08-14 20:33 ` [gentoo-dev] [arm17] [PATCH 1/3] toolchain-funcs.eclass: New tc-getTARGET_CPP function James Le Cuirot
@ 2018-08-14 20:33 ` James Le Cuirot
  2018-08-14 20:33 ` [gentoo-dev] [arm17] [PATCH v2 3/3] toolchain-funcs.eclass: Update tc-is-softfloat for new ARM tuples James Le Cuirot
  2018-08-21 20:38 ` [gentoo-dev] [arm17] [PATCH 0/3] toolchain-funcs.eclass: tc-is-softfloat for ARM and associated functions James Le Cuirot
  3 siblings, 0 replies; 6+ messages in thread
From: James Le Cuirot @ 2018-08-14 20:33 UTC (permalink / raw
  To: gentoo-dev; +Cc: James Le Cuirot

CTARGET is used, if defined, otherwise CHOST. CHOST was previously
assumed but this should not affect existing usage of these helpers.
---
 eclass/toolchain-funcs.eclass | 53 +++++++++++++++++------------------
 1 file changed, 25 insertions(+), 28 deletions(-)

diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
index fbd1a8d5e2bf..d9a37c91a8ef 100644
--- a/eclass/toolchain-funcs.eclass
+++ b/eclass/toolchain-funcs.eclass
@@ -196,6 +196,27 @@ tc-is-cross-compiler() {
 	[[ ${CBUILD:-${CHOST}} != ${CHOST} ]]
 }
 
+# @FUNCTION: tc-cpp-is-true
+# @USAGE: <condition> [cpp flags]
+# @RETURN: Shell true if the condition is true, shell false otherwise.
+# @DESCRIPTION:
+# Evaluate the given condition using the C preprocessor for CTARGET, if
+# defined, or CHOST. Additional arguments are passed through to the cpp
+# command. A typical condition would be in the form defined(__FOO__).
+tc-cpp-is-true() {
+	local CONDITION=${1}
+	shift
+
+	local RESULT=$($(tc-getTARGET_CPP) "${@}" -P - <<-EOF 2>/dev/null
+			#if ${CONDITION}
+			true
+			#endif
+		EOF
+	)
+
+	[[ ${RESULT} == true ]]
+}
+
 # @FUNCTION: tc-is-softfloat
 # @DESCRIPTION:
 # See if this toolchain is a softfloat based one.
@@ -837,13 +858,7 @@ gcc-specs-stack-check() {
 # 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 | grep '^true$'
-		#if defined(__PIE__)
-		true
-		#endif
-		EOF
-	)"
-	[[ ${ret} == true ]]
+	tc-cpp-is-true "defined(__PIE__)" ${CPPFLAGS} ${CFLAGS}
 }
 
 # @FUNCTION: tc-enables-ssp
@@ -855,13 +870,7 @@ tc-enables-pie() {
 #  -fstack-protector-strong
 #  -fstack-protector-all
 tc-enables-ssp() {
-	local ret="$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null | grep '^true$'
-		#if defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__)
-		true
-		#endif
-		EOF
-	)"
-	[[ ${ret} == true ]]
+	tc-cpp-is-true "defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS}
 }
 
 # @FUNCTION: tc-enables-ssp-strong
@@ -872,13 +881,7 @@ tc-enables-ssp() {
 #  -fstack-protector-strong
 #  -fstack-protector-all
 tc-enables-ssp-strong() {
-	local ret="$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null | grep '^true$'
-		#if defined(__SSP_STRONG__) || defined(__SSP_ALL__)
-		true
-		#endif
-		EOF
-	)"
-	[[ ${ret} == true ]]
+	tc-cpp-is-true "defined(__SSP_STRONG__) || defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS}
 }
 
 # @FUNCTION: tc-enables-ssp-all
@@ -888,13 +891,7 @@ tc-enables-ssp-strong() {
 # 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 | grep '^true$'
-		#if defined(__SSP_ALL__)
-		true
-		#endif
-		EOF
-	)"
-	[[ ${ret} == true ]]
+	tc-cpp-is-true "defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS}
 }
 
 
-- 
2.17.0



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

* [gentoo-dev] [arm17] [PATCH v2 3/3] toolchain-funcs.eclass: Update tc-is-softfloat for new ARM tuples
  2018-08-14 20:33 [gentoo-dev] [arm17] [PATCH 0/3] toolchain-funcs.eclass: tc-is-softfloat for ARM and associated functions James Le Cuirot
  2018-08-14 20:33 ` [gentoo-dev] [arm17] [PATCH 1/3] toolchain-funcs.eclass: New tc-getTARGET_CPP function James Le Cuirot
  2018-08-14 20:33 ` [gentoo-dev] [arm17] [PATCH 2/3] toolchain-funcs.eclass: tc-cpp-is-true function to simplify helpers James Le Cuirot
@ 2018-08-14 20:33 ` James Le Cuirot
  2018-08-21 20:38 ` [gentoo-dev] [arm17] [PATCH 0/3] toolchain-funcs.eclass: tc-is-softfloat for ARM and associated functions James Le Cuirot
  3 siblings, 0 replies; 6+ messages in thread
From: James Le Cuirot @ 2018-08-14 20:33 UTC (permalink / raw
  To: gentoo-dev; +Cc: James Le Cuirot

ARM tuples will change from armv7a-hardfloat-linux-gnueabi to
armv7a-unknown-linux-gnueabihf or similar in the 17.0 profiles. The
function already treated the latter as hardfloat but this commit will
now treat ambiguous tuples such as arm-unknown-linux-gnueabi as
softfloat rather than hardfloat. This brings Gentoo in line with most
of the ARM Linux community. However, the function will now check
existing toolchains to avoid breaking existing systems, if possible.

This has been achieved by splitting the function in three,
tc-detect-is-softfloat for checking existing toolchains,
tc-tuple-is-softfloat for checking just the tuple, and the new
tc-is-softfloat that calls the first two. The output from the first
two could be compared to inform the user that they are not using a
recommended tuple.
---
 eclass/toolchain-funcs.eclass | 74 ++++++++++++++++++++++++++++-------
 1 file changed, 60 insertions(+), 14 deletions(-)

diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
index d9a37c91a8ef..3fa32820151c 100644
--- a/eclass/toolchain-funcs.eclass
+++ b/eclass/toolchain-funcs.eclass
@@ -217,6 +217,65 @@ tc-cpp-is-true() {
 	[[ ${RESULT} == true ]]
 }
 
+# @FUNCTION: tc-detect-is-softfloat
+# @RETURN:
+# Shell true if (positive or negative) detection was possible, shell
+# false otherwise. Also outputs a string when detection succeeds, see
+# tc-is-softfloat for the possible values.
+# @DESCRIPTION:
+# Detect whether the CTARGET (or CHOST) toolchain is a softfloat based
+# one by examining the toolchain's output, if possible.
+tc-detect-is-softfloat() {
+	# If fetching CPP falls back to the default (gcc -E) then fail
+	# detection as this may not be the correct toolchain.
+	[[ $(tc-getTARGET_CPP) == "gcc -E" ]] && return 1
+
+	case ${CTARGET:-${CHOST}} in
+		# arm-unknown-linux-gnueabi is ambiguous. We used to treat it as
+		# hardfloat but we now treat it as softfloat like most everyone
+		# else. Check existing toolchains to respect existing systems.
+		arm*)
+			if tc-cpp-is-true "defined(__ARM_PCS_VFP)"; then
+				echo "no"
+			else
+				# Confusingly __SOFTFP__ is defined only when
+				# -mfloat-abi is soft, not softfp.
+				if tc-cpp-is-true "defined(__SOFTFP__)"; then
+					echo "yes"
+				else
+					echo "softfp"
+				fi
+			fi
+
+			return 0 ;;
+		*)
+			return 1 ;;
+	esac
+}
+
+# @FUNCTION: tc-tuple-is-softfloat
+# @RETURN: See tc-is-softfloat for the possible values.
+# @DESCRIPTION:
+# Determine whether the CTARGET (or CHOST) toolchain is a softfloat
+# based one solely from the tuple.
+tc-tuple-is-softfloat() {
+	local CTARGET=${CTARGET:-${CHOST}}
+	case ${CTARGET//_/-} in
+		bfin*|h8300*)
+			echo "only" ;;
+		*-softfloat-*)
+			echo "yes" ;;
+		*-softfp-*)
+			echo "softfp" ;;
+		arm*-hardfloat-*|arm*eabihf)
+			echo "no" ;;
+		arm*)
+			echo "yes" ;;
+		*)
+			echo "no" ;;
+	esac
+}
+
 # @FUNCTION: tc-is-softfloat
 # @DESCRIPTION:
 # See if this toolchain is a softfloat based one.
@@ -231,20 +290,7 @@ tc-cpp-is-true() {
 # softfloat flags in the case where support is optional, but
 # rejects softfloat flags where the target always lacks an fpu.
 tc-is-softfloat() {
-	local CTARGET=${CTARGET:-${CHOST}}
-	case ${CTARGET} in
-		bfin*|h8300*)
-			echo "only" ;;
-		*)
-			if [[ ${CTARGET//_/-} == *-softfloat-* ]] ; then
-				echo "yes"
-			elif [[ ${CTARGET//_/-} == *-softfp-* ]] ; then
-				echo "softfp"
-			else
-				echo "no"
-			fi
-			;;
-	esac
+	tc-detect-is-softfloat || tc-tuple-is-softfloat
 }
 
 # @FUNCTION: tc-is-static-only
-- 
2.17.0



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

* Re: [gentoo-dev] [arm17] [PATCH 0/3] toolchain-funcs.eclass: tc-is-softfloat for ARM and associated functions
  2018-08-14 20:33 [gentoo-dev] [arm17] [PATCH 0/3] toolchain-funcs.eclass: tc-is-softfloat for ARM and associated functions James Le Cuirot
                   ` (2 preceding siblings ...)
  2018-08-14 20:33 ` [gentoo-dev] [arm17] [PATCH v2 3/3] toolchain-funcs.eclass: Update tc-is-softfloat for new ARM tuples James Le Cuirot
@ 2018-08-21 20:38 ` James Le Cuirot
  2018-08-21 21:27   ` M. J. Everitt
  3 siblings, 1 reply; 6+ messages in thread
From: James Le Cuirot @ 2018-08-21 20:38 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 895 bytes --]

On Tue, 14 Aug 2018 21:33:01 +0100
James Le Cuirot <chewi@gentoo.org> wrote:

> I previously sent a single patch to this list entitled
> "Update tc-is-softfloat for new ARM tuples" but I have now added two
> further patches following the initial feedback.
> 
> For the additional background behind these changes, please see:
> https://archives.gentoo.org/gentoo-dev/message/b55b141e76ae1e08279d6f5b33be8151
> 
> James Le Cuirot (3):
>   toolchain-funcs.eclass: New tc-getTARGET_CPP function
>   toolchain-funcs.eclass: tc-cpp-is-true function to simplify helpers
>   toolchain-funcs.eclass: Update tc-is-softfloat for new ARM tuples
> 
>  eclass/toolchain-funcs.eclass | 138 +++++++++++++++++++++++-----------
>  1 file changed, 96 insertions(+), 42 deletions(-)

There were no further comments so this has been pushed.

-- 
James Le Cuirot (chewi)
Gentoo Linux Developer

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 981 bytes --]

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

* Re: [gentoo-dev] [arm17] [PATCH 0/3] toolchain-funcs.eclass: tc-is-softfloat for ARM and associated functions
  2018-08-21 20:38 ` [gentoo-dev] [arm17] [PATCH 0/3] toolchain-funcs.eclass: tc-is-softfloat for ARM and associated functions James Le Cuirot
@ 2018-08-21 21:27   ` M. J. Everitt
  0 siblings, 0 replies; 6+ messages in thread
From: M. J. Everitt @ 2018-08-21 21:27 UTC (permalink / raw
  To: gentoo-dev


[-- Attachment #1.1: Type: text/plain, Size: 1045 bytes --]

On 21/08/18 21:38, James Le Cuirot wrote:
> On Tue, 14 Aug 2018 21:33:01 +0100
> James Le Cuirot <chewi@gentoo.org> wrote:
>
>> I previously sent a single patch to this list entitled
>> "Update tc-is-softfloat for new ARM tuples" but I have now added two
>> further patches following the initial feedback.
>>
>> For the additional background behind these changes, please see:
>> https://archives.gentoo.org/gentoo-dev/message/b55b141e76ae1e08279d6f5b33be8151
>>
>> James Le Cuirot (3):
>>   toolchain-funcs.eclass: New tc-getTARGET_CPP function
>>   toolchain-funcs.eclass: tc-cpp-is-true function to simplify helpers
>>   toolchain-funcs.eclass: Update tc-is-softfloat for new ARM tuples
>>
>>  eclass/toolchain-funcs.eclass | 138 +++++++++++++++++++++++-----------
>>  1 file changed, 96 insertions(+), 42 deletions(-)
> There were no further comments so this has been pushed.
>
<nitpick>

A commit id is often popular - not because we don't believe you pushed,
but for any potential future reference :).
</nitpick>


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

end of thread, other threads:[~2018-08-21 21:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-14 20:33 [gentoo-dev] [arm17] [PATCH 0/3] toolchain-funcs.eclass: tc-is-softfloat for ARM and associated functions James Le Cuirot
2018-08-14 20:33 ` [gentoo-dev] [arm17] [PATCH 1/3] toolchain-funcs.eclass: New tc-getTARGET_CPP function James Le Cuirot
2018-08-14 20:33 ` [gentoo-dev] [arm17] [PATCH 2/3] toolchain-funcs.eclass: tc-cpp-is-true function to simplify helpers James Le Cuirot
2018-08-14 20:33 ` [gentoo-dev] [arm17] [PATCH v2 3/3] toolchain-funcs.eclass: Update tc-is-softfloat for new ARM tuples James Le Cuirot
2018-08-21 20:38 ` [gentoo-dev] [arm17] [PATCH 0/3] toolchain-funcs.eclass: tc-is-softfloat for ARM and associated functions James Le Cuirot
2018-08-21 21:27   ` M. J. Everitt

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