powerpc: Automatic CPU detection in preconfigure
Commit Message
Followup from <https://sourceware.org/legacy-ml/libc-alpha/2017-02/msg00164.html>
---8<---
Added a check to detect the CPU value in preconfigure, so that glibc is
built with the correct --with-cpu value. And move existing checks into
preconfigure.ac.
Co-Authored-By: Carlos Eduardo Seo <cseo@linux.vnet.ibm.com>
Co-Authored-By: Tulio Magno Quites Machado Filho <tuliom@linux.vnet.ibm.com>
---
sysdeps/powerpc/preconfigure | 42 +++++++++++++++++++++++---
sysdeps/powerpc/preconfigure.ac | 52 +++++++++++++++++++++++++++++++++
2 files changed, 90 insertions(+), 4 deletions(-)
create mode 100644 sysdeps/powerpc/preconfigure.ac
Comments
* Paul E. Murphy via Libc-alpha:
> +# Lets ask the compiler which Power processor we've got, in case the user did
> +# not choose a --with-cpu value.
> +if test -z "$with_cpu"; then
> + AC_MSG_NOTICE([--with-cpu not set. Trying to detect CPU.])
> + archcpu=`echo "int foo () { return 0; }" \
> + | $CC $CFLAGS $CPPFLAGS -S -frecord-gcc-switches -xc -o - - \
> + | grep -E "\.ascii.*mcpu" | sed "s/.*mcpu=\(.*\)\"/\1/"`
> + # Set --with-cpu as appropriate.
> + # Note if you add patterns here you must ensure that an appropriate
> + # directory exists in sysdeps/powerpc.
> + case "$archcpu" in
> + 4??|4??fp)
> + submachine=${archcpu%fp}
> + # The submachine is now inferred. However the generic submachine
> + # check will not respect the soft/hard fp choice. Fill the cache
> + # to skip the unneeded check which unconditionally sets
> + # -m{cpu,arch}=${submachine}.
> + AC_CACHE_VAL(libc_cv_cc_submachine,libc_cv_cc_submachine="")
> + ;;
> + a2|970|power*)
> + submachine=${archcpu}
> + ;;
> + *)
> + AC_WARN([CPU not identified; using default])
> + ;;
> + esac
> +fi
This looks like a forward-compatibility trap. If GCC supports -mfuture
(under the real name), an appropriate directory may not yet exist under
sysdeps/powerpc.
I also do not think this works as expected if GCC itself is built with
--with-cpu. Maybe extracting the .machine argument works instead?
Thanks,
Florian
On 5/8/20 3:31 PM, Florian Weimer wrote:
> * Paul E. Murphy via Libc-alpha:
>
>> +# Lets ask the compiler which Power processor we've got, in case the user did
>> +# not choose a --with-cpu value.
>> +if test -z "$with_cpu"; then
>> + AC_MSG_NOTICE([--with-cpu not set. Trying to detect CPU.])
>> + archcpu=`echo "int foo () { return 0; }" \
>> + | $CC $CFLAGS $CPPFLAGS -S -frecord-gcc-switches -xc -o - - \
>> + | grep -E "\.ascii.*mcpu" | sed "s/.*mcpu=\(.*\)\"/\1/"`
>> + # Set --with-cpu as appropriate.
>> + # Note if you add patterns here you must ensure that an appropriate
>> + # directory exists in sysdeps/powerpc.
>> + case "$archcpu" in
>> + 4??|4??fp)
>> + submachine=${archcpu%fp}
>> + # The submachine is now inferred. However the generic submachine
>> + # check will not respect the soft/hard fp choice. Fill the cache
>> + # to skip the unneeded check which unconditionally sets
>> + # -m{cpu,arch}=${submachine}.
>> + AC_CACHE_VAL(libc_cv_cc_submachine,libc_cv_cc_submachine="")
>> + ;;
>> + a2|970|power*)
>> + submachine=${archcpu}
>> + ;;
>> + *)
>> + AC_WARN([CPU not identified; using default])
>> + ;;
>> + esac
>> +fi
> This looks like a forward-compatibility trap. If GCC supports -mfuture
> (under the real name), an appropriate directory may not yet exist under
> sysdeps/powerpc.
Ack, the "power[4-9]|power5+|power6x" is less exciting, but won't overreach.
>
> I also do not think this works as expected if GCC itself is built with
> --with-cpu. Maybe extracting the .machine argument works instead?
Actually, I think the opposite holds. If the toolchain isn't built with
--with-cpu and no cpu is specified, it will fail and the generic target
used. On the build-many-glibcs.py ppc64le toolchain, this only emits a
machine directive if no cpu is specified. I think we should check for
both an choose the first:
grep -E "mcpu=|[.]machine" -m 1 | sed -e "s/.*machine /mcpu=/" -e
"s/.*mcpu=\(.*\)\"/\1/"
Attached is a V2 with the above changes and less verbosity.
All preconfigure fragments are always sourced by configure; code in a
preconfigure fragment needs to be inside a case statement or other check
that $machine is a system for which that fragment is applicable
(preconfigure fragments are part of the mechanism that maps from
configured machine names to the list of sysdeps directories relevant to
that configuration).
Thus, the 'if test -z "$submachine"; then' code added by this patch all
needs to be conditioned so it only runs for powerpc.
@@ -1,4 +1,5 @@
-# preconfigure fragment for powerpc.
+# This file is generated from configure.ac by Autoconf. DO NOT EDIT!
+ # Local preconfigure fragment for sysdeps/powerpc
case "$machine" in
powerpc64le)
@@ -16,10 +17,43 @@ powerpc*)
# We can't use AC_MSG_ERROR here.
# The parent script is in the middle of printing the
# "checking for sysdeps preconfigure fragments" line.
- echo >&2
- echo "Host system type $host is no longer supported." >&2
- exit 1
+ as_fn_error $? "Host system type $host is no longer supported." "$LINENO" 5
;;
esac
;;
esac
+
+# Lets ask the compiler which Power processor we've got, in case the user did
+# not choose a --with-cpu value.
+if test -z "$with_cpu"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: --with-cpu not set. Trying to detect CPU." >&5
+$as_echo "$as_me: --with-cpu not set. Trying to detect CPU." >&6;}
+ archcpu=`echo "int foo () { return 0; }" \
+ | $CC $CFLAGS $CPPFLAGS -S -frecord-gcc-switches -xc -o - - \
+ | grep -E "\.ascii.*mcpu" | sed "s/.*mcpu=\(.*\)\"/\1/"`
+ # Set --with-cpu as appropriate.
+ # Note if you add patterns here you must ensure that an appropriate
+ # directory exists in sysdeps/powerpc.
+ case "$archcpu" in
+ 4??|4??fp)
+ submachine=${archcpu%fp}
+ # The submachine is now inferred. However the generic submachine
+ # check will not respect the soft/hard fp choice. Fill the cache
+ # to skip the unneeded check which unconditionally sets
+ # -m{cpu,arch}=${submachine}.
+ if ${libc_cv_cc_submachine+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ libc_cv_cc_submachine=""
+fi
+
+ ;;
+ a2|970|power*)
+ submachine=${archcpu}
+ ;;
+ *)
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: CPU not identified; using default" >&5
+$as_echo "$as_me: WARNING: CPU not identified; using default" >&2;}
+ ;;
+ esac
+fi
new file mode 100644
@@ -0,0 +1,52 @@
+GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
+# Local preconfigure fragment for sysdeps/powerpc
+
+case "$machine" in
+powerpc64le)
+ base_machine=powerpc machine=powerpc/powerpc64/le
+ ;;
+powerpc64*)
+ base_machine=powerpc machine=powerpc/powerpc64/be
+ ;;
+powerpc*)
+ base_machine=powerpc machine=powerpc/powerpc32
+ with_fp_cond="!defined __NO_FPRS__"
+ case "$host_os" in
+ *gnuspe*)
+ # SPE support was dropped in glibc 2.30.
+ # We can't use AC_MSG_ERROR here.
+ # The parent script is in the middle of printing the
+ # "checking for sysdeps preconfigure fragments" line.
+ AC_MSG_ERROR([Host system type $host is no longer supported.])
+ ;;
+ esac
+ ;;
+esac
+
+# Lets ask the compiler which Power processor we've got, in case the user did
+# not choose a --with-cpu value.
+if test -z "$with_cpu"; then
+ AC_MSG_NOTICE([--with-cpu not set. Trying to detect CPU.])
+ archcpu=`echo "int foo () { return 0; }" \
+ | $CC $CFLAGS $CPPFLAGS -S -frecord-gcc-switches -xc -o - - \
+ | grep -E "\.ascii.*mcpu" | sed "s/.*mcpu=\(.*\)\"/\1/"`
+ # Set --with-cpu as appropriate.
+ # Note if you add patterns here you must ensure that an appropriate
+ # directory exists in sysdeps/powerpc.
+ case "$archcpu" in
+ 4??|4??fp)
+ submachine=${archcpu%fp}
+ # The submachine is now inferred. However the generic submachine
+ # check will not respect the soft/hard fp choice. Fill the cache
+ # to skip the unneeded check which unconditionally sets
+ # -m{cpu,arch}=${submachine}.
+ AC_CACHE_VAL(libc_cv_cc_submachine,libc_cv_cc_submachine="")
+ ;;
+ a2|970|power*)
+ submachine=${archcpu}
+ ;;
+ *)
+ AC_WARN([CPU not identified; using default])
+ ;;
+ esac
+fi