[PATCHv3] powerpc: Automatic CPU detection in preconfigure
Matheus Castanho
msc@linux.ibm.com
Mon Jun 8 15:15:01 GMT 2020
Hi Paul,
On 5/11/20 7:10 PM, Paul E. Murphy via Libc-alpha wrote:
> Changes for 3:
> * update conditional to avoid running on non-ppc machines
>
> Followup from
> <https://sourceware.org/pipermail/libc-alpha/2020-May/113765.html>
>
> Changes:
> * Scan for the first instance of .machine or -mcpu= within the
> generated assembly file.
> * Don't try to be smart when guessing. Only choose valid targets.
> * Don't make any extra noise
> * Remove comment about trying to pretty print an error message, just
> fail in the usual autoconf way.
>
> 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 | 62 +++++++++++++++++++++++++++++----
> sysdeps/powerpc/preconfigure.ac | 58 ++++++++++++++++++++++++++++++
> 2 files changed, 113 insertions(+), 7 deletions(-)
> create mode 100644 sysdeps/powerpc/preconfigure.ac
>
[..]
> +# Lets ask the compiler which Power processor we've got, in case the user did
> +# not choose a --with-cpu value. Scan a trivial generated assembly program
> +# and scrape the first
> +# .machine <machine>
> +# or
> +# .ascii "-mcpu=<machine>"
> +# directive which shows up, and try using it.
> +case "${machine}:${submachine}" in
> +*powerpc*:)
> + archcpu=`echo "int foo () { return 0; }" \
> + | $CC $CFLAGS $CPPFLAGS -S -frecord-gcc-switches -xc -o - - \
> + | grep -E "mcpu=|[.]machine" -m 1 \
> + | sed -e "s/.*machine /mcpu=/" -e "s/.*mcpu=\(.*\)\"/\1/"`
I believe this last pattern is not parsing the machine name correctly
when .machine is used. I found the problem when testing with actual
output from GCC, but below I'm just emulating the problem with a simple
echo.
With .ascii it's OK:
$ echo '.ascii "-mcpu=power9"' | grep -E "mcpu=|[.]machine" -m 1 | sed
-e "s/.*machine /mcpu=/" -e "s/.*mcpu=\(.*\)\"/\1/"
power9
But when .machine is used:
$ echo '.machine power9' | grep -E "mcpu=|[.]machine" -m 1 | sed -e
"s/.*machine /mcpu=/" -e "s/.*mcpu=\(.*\)\"/\1/"
mcpu=power9
The last pattern expects a closing ", which the .machine case does not
have. You could drop the \" and just remove all quotes prior to invoking
sed:
$ echo '.machine power9' | grep -E "mcpu=|[.]machine" -m 1 | tr -d '"' |
sed -e "s/.*machine /mcpu=/" -e "s/.*mcpu=\(.*\)/\1/"
power9
$ echo '.ascii "-mcpu=power9"' | grep -E "mcpu=|[.]machine" -m 1 | tr
-d '"' | sed -e "s/.*machine /mcpu=/" -e "s/.*mcpu=\(.*\)/\1/"
power9
Instead of using tr, an extra -e 's/"//g' before the others should also
do the trick.
--
Matheus Castanho
More information about the Libc-alpha
mailing list