aboutsummaryrefslogtreecommitdiff
path: root/gcc/config/mips
diff options
context:
space:
mode:
authorYunQiang Su <yunqiang.su@cipunited.com>2022-08-02 10:57:18 +0000
committerYunQiang Su <yunqiang.su@cipunited.com>2022-10-09 06:39:04 +0000
commit66c48be23e0fa5ee7474b4b078e013f901c71eed (patch)
treed8e437b2fb99d5820c2f84a8bbc01e4a1848f1ea /gcc/config/mips
parentd7346a3bf6554ddaef9853c1b0fb770c4a3cd9d2 (diff)
downloadgcc-66c48be23e0fa5ee7474b4b078e013f901c71eed.zip
gcc-66c48be23e0fa5ee7474b4b078e013f901c71eed.tar.gz
gcc-66c48be23e0fa5ee7474b4b078e013f901c71eed.tar.bz2
MIPS: improve -march=native arch detection
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. mnan=2008 option is also used if __mips_nan2008__ is used. This can fix the wrong loader usage on r5/r6 platform with -march=native. gcc/ChangeLog: * config.gcc: set with_arch to default_mips_arch if no defined. * config/mips/driver-native.cc (host_detect_local_cpu): try getauxval(AT_BASE_PLATFORM) and _MIPS_ARCH, too. pass -mnan=2008 if __mips_nan2008__ is defined. * config.in: define HAVE_SYS_AUXV_H and HAVE_GETAUXVAL. * configure.ac: detect sys/auxv.h and getauxval. * configure: regenerated.
Diffstat (limited to 'gcc/config/mips')
-rw-r--r--gcc/config/mips/driver-native.cc25
1 files changed, 22 insertions, 3 deletions
diff --git a/gcc/config/mips/driver-native.cc b/gcc/config/mips/driver-native.cc
index 47627f8..327ad25 100644
--- a/gcc/config/mips/driver-native.cc
+++ b/gcc/config/mips/driver-native.cc
@@ -23,6 +23,9 @@ along with GCC; see the file COPYING3. If not see
#include "system.h"
#include "coretypes.h"
#include "tm.h"
+#ifdef HAVE_SYS_AUXV_H
+#include <sys/auxv.h>
+#endif
/* This will be called by the spec parser in gcc.cc when it sees
a %:local_cpu_detect(args) construct. Currently it will be called
@@ -41,6 +44,7 @@ const char *
host_detect_local_cpu (int argc, const char **argv)
{
const char *cpu = NULL;
+ char *ret = NULL;
char buf[128];
FILE *f;
bool arch;
@@ -54,7 +58,7 @@ host_detect_local_cpu (int argc, const char **argv)
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 +88,23 @@ host_detect_local_cpu (int argc, const char **argv)
fclose (f);
+fallback_cpu:
+#if defined (__mips_nan2008)
+ ret = reconcat (ret, " -mnan=2008 ", NULL);
+#endif
+
+#ifdef HAVE_GETAUXVAL
if (cpu == NULL)
- return NULL;
+ cpu = (const char *) getauxval (AT_BASE_PLATFORM);
+#endif
+
+#if defined (_MIPS_ARCH)
+ if (cpu == NULL)
+ cpu = _MIPS_ARCH;
+#endif
+
+ if (cpu)
+ ret = reconcat (ret, ret, "-m", argv[0], "=", cpu, NULL);
- return concat ("-m", argv[0], "=", cpu, NULL);
+ return ret;
}