commit:     6f6e58bd266a7e82f2eff29703a5a819b20ce8f7
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Fri Nov 24 17:42:25 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Nov 24 18:35:04 2023 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=6f6e58bd

go-env.eclass: fix GO386 handling

Go 1.16 dropped explicit support for 386 FP and relies on software
emulation instead in the absence of SSE2.

* First, check if cpu_flags_x86_sse2 is used in the ebuild. If it is and it's
enabled, then act in SSE2 mode.

* If not, fall back to checking whether the compiler has __SSE2__ defined via
e.g. -march in CFLAGS.

* Failing that, use softfloat mode.

Fixes the issue mentioned in 5718f8440197298e0aa1df2a88a66057d2cdaf83 (where
we tried to use a USE flag which isn't implicit).

Signed-off-by: Sam James <sam <AT> gentoo.org>

 eclass/go-env.eclass | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/eclass/go-env.eclass b/eclass/go-env.eclass
index 4bc8c4b15c65..1f950db06930 100644
--- a/eclass/go-env.eclass
+++ b/eclass/go-env.eclass
@@ -31,7 +31,7 @@ go-env_set_compile_environment() {
 
        export GOARCH="$(go-env_goarch)"
        use arm && export GOARM=$(go-env_goarm)
-       use x86 && export GO386=$(usex cpu_flags_x86_sse2 '' 'softfloat')
+       use x86 && export GO386=$(go-env_go386)
 
        export CGO_CFLAGS="${CGO_CFLAGS:-$CFLAGS}"
        export CGO_CPPFLAGS="${CGO_CPPFLAGS:-$CPPFLAGS}"
@@ -62,6 +62,27 @@ go-env_goarch() {
        esac
 }
 
+# @FUNCTION: go-env_go386
+# @DESCRIPTION:
+# Returns the appropriate GO386 setting for the CFLAGS in use.
+go-env_go386() {
+       # Piggy-back off any existing CPU_FLAGS_X86 usage in the ebuild if
+       # it's there.
+       if in_iuse cpu_flags_x86_sse2 && use cpu_flags_x86_sse2 ; then
+               echo 'sse2'
+               return
+       fi
+
+       if tc-cpp-is-true "defined(__SSE2__)" ${CFLAGS} ${CXXFLAGS} ; then
+               echo 'sse2'
+               return
+       fi
+
+       # Go 1.16 dropped explicit support for 386 FP and relies on software
+       # emulation instead in the absence of SSE2.
+       echo 'softfloat'
+}
+
 # @FUNCTION: go-env_goarm
 # @USAGE: [CHOST-value]
 # @DESCRIPTION:

Reply via email to