[PATCHv3] powerpc: Automatic CPU detection in preconfigure

Tulio Magno Quites Machado Filho tuliom@ascii.art.br
Mon Jun 8 19:07:21 GMT 2020

Matheus Castanho via Libc-alpha <libc-alpha@sourceware.org> writes:

> On 5/11/20 7:10 PM, Paul E. Murphy via Libc-alpha wrote:
>> +# 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.

This issue can only be reproduced on GCC >= 10.

I tested this patch on different combinations of distros, GCC versions and
ABIs confirming this works well, except for the issue that Matheus pointed out.
I modified that regex to "s/.*machine //" and it worked.

On a side note, on Debian ppc (32-bit), it does generate the right result, but
it isn't able to select a submachine because Debian's GCC is configured with
--with-cpu=default32, generating a `.machine ppc`.

LGTM with that issue fixed.

Tulio Magno

More information about the Libc-alpha mailing list