public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] MIPS: improve -march=native arch detection
@ 2022-08-02 11:10 YunQiang Su
  2022-08-14 10:36 ` YunQiang Su
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: YunQiang Su @ 2022-08-02 11:10 UTC (permalink / raw)
  To: gcc-patches; +Cc: macro, YunQiang Su

If we cannot get info from options and cpuinfo, we try to get from:
  1. getauxval(AT_BASE_PLATFORM), introduced since Linux 5.7
  2. _MIPS_ARCH from host compiler.

This can fix the wrong loader usage on r5/r6 platform with
 -march=native.

gcc/ChangeLog:
	* config/mips/driver-native.cc (host_detect_local_cpu):
	  try getauxval(AT_BASE_PLATFORM) and _MIPS_ARCH, too.
---
 gcc/config/mips/driver-native.cc | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/gcc/config/mips/driver-native.cc b/gcc/config/mips/driver-native.cc
index 47627f85ce1..9aa7044c0b8 100644
--- a/gcc/config/mips/driver-native.cc
+++ b/gcc/config/mips/driver-native.cc
@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3.  If not see
 
 #define IN_TARGET_CODE 1
 
+#include <sys/auxv.h>
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
@@ -46,15 +47,15 @@ host_detect_local_cpu (int argc, const char **argv)
   bool arch;
 
   if (argc < 1)
-    return NULL;
+    goto fallback_cpu;
 
   arch = strcmp (argv[0], "arch") == 0;
   if (!arch && strcmp (argv[0], "tune"))
-    return NULL;
+    goto fallback_cpu;
 
   f = fopen ("/proc/cpuinfo", "r");
   if (f == NULL)
-    return NULL;
+    goto fallback_cpu;
 
   while (fgets (buf, sizeof (buf), f) != NULL)
     if (startswith (buf, "cpu model"))
@@ -84,8 +85,23 @@ host_detect_local_cpu (int argc, const char **argv)
 
   fclose (f);
 
+fallback_cpu:
+/*FIXME: how about other OSes, like FreeBSD? */
+#ifdef __linux__
+  /*Note: getauxval may return NULL as:
+   * AT_BASE_PLATFORM is supported since Linux 5.7
+   * Or from older version of qemu-user
+   * */
+  if (cpu == NULL)
+    cpu = (const char *) getauxval (AT_BASE_PLATFORM);
+#endif
+
   if (cpu == NULL)
+#if defined (_MIPS_ARCH)
+    cpu = _MIPS_ARCH;
+#else
     return NULL;
+#endif
 
   return concat ("-m", argv[0], "=", cpu, NULL);
 }
-- 
2.30.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-09-16 12:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-02 11:10 [PATCH] MIPS: improve -march=native arch detection YunQiang Su
2022-08-14 10:36 ` YunQiang Su
2022-08-24  4:14 ` YunQiang Su
2022-08-24  5:56 ` Xi Ruoyao
2022-09-16 12:23 ` [PATCH v2] " YunQiang Su

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).