diff mbox

powerpc: Automatic CPU detection in preconfigure

Message ID 1486559603-13798-1-git-send-email-tuliom@linux.vnet.ibm.com
State New
Headers show

Commit Message

Tulio Magno Quites Machado Filho Feb. 8, 2017, 1:13 p.m. UTC
From: Carlos Eduardo Seo <cseo@linux.vnet.ibm.com>

Added a check to detect the CPU value in preconfigure, so that glibc is
built with the correct --with-cpu value.

2017-02-08  Carlos Eduardo Seo  <cseo@linux.vnet.ibm.com>
	    Tulio Magno Quites Machado Filho  <tuliom@linux.vnet.ibm.com>

	* sysdeps/powerpc/preconfigure: Automatically configure
	--with-cpu value based on compiler target cpu.
---
 sysdeps/powerpc/preconfigure | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

Comments

Joseph Myers Feb. 8, 2017, 5:13 p.m. UTC | #1
On Wed, 8 Feb 2017, Tulio Magno Quites Machado Filho wrote:

> Added a check to detect the CPU value in preconfigure, so that glibc is
> built with the correct --with-cpu value.

I don't think setting submachine as you do here is appropriate; it will 
result in the logic that tried using -mcpu=$submachine being activated, 
which will override the compiler defaults you've just detected (e.g. 
result in -mcpu=476 being passed when the default is -mcpu=476fp, so 
wrongly changing the ABI to soft-float).

Ratherm you should append appropriately to the machine setting in cases 
where there are relevant sysdeps directories.  (Make sure this does 
achieve the desired effects regarding use of sysdeps/powerpc/power7 etc. 
directories not just those under powerpc64 or powerpc32.)

> +  { $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;}

This is using Autoconf internals.  If you want to send messages like that, 
don't hardcode details of Autoconf internals in a preconfigure script.  
Rather, move powerpc to using preconfigure.ac, and use the appropriate 
AC_* macros there.

> +  e500mc|e500mc64)
> +    submachine="e500"
> +    ;;

No, the e500 sysdeps directories are strictly for classic e500, not e500mc 
or e500mc64.

> +  a2|464|970|power*)
> +    submachine=${archcpu}

And you may want the power* logic to be smarter to map power10, power11 
etc. to power9 sysdeps directories until there are sysdeps directories for 
such future architecture variants.
diff mbox

Patch

diff --git a/sysdeps/powerpc/preconfigure b/sysdeps/powerpc/preconfigure
index 0c6fdde..e269616 100644
--- a/sysdeps/powerpc/preconfigure
+++ b/sysdeps/powerpc/preconfigure
@@ -15,3 +15,39 @@  powerpc*)
   rm -f conftest.i
   ;;
 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
+  405|405fp)
+    submachine="405"
+    ;;
+  440|440fp)
+    submachine="440"
+    ;;
+  476|476fp)
+    submachine="476"
+    ;;
+  e500mc|e500mc64)
+    submachine="e500"
+    ;;
+  a2|464|970|power*)
+    submachine=${archcpu}
+    ;;
+  *)
+  submachine=""
+    { $as_echo "$as_me:${as_lineno-$LINENO}: CPU not identified; using default" >&5
+      $as_echo "$as_me:  CPU not identified; using default" >&6;}
+    ;;
+  esac
+fi