From: Xi Ruoyao <xry111@xry111.site>
To: YunQiang Su <yunqiang.su@cipunited.com>, gcc-patches@gcc.gnu.org
Cc: macro@orcam.me.uk
Subject: Re: [PATCH] MIPS: improve -march=native arch detection
Date: Wed, 24 Aug 2022 13:56:50 +0800 [thread overview]
Message-ID: <c40416d5600d6b0c411a2bfb4e8f9a891df51832.camel@xry111.site> (raw)
In-Reply-To: <20220802111009.35536-1-yunqiang.su@cipunited.com>
On Tue, 2022-08-02 at 11:10 +0000, YunQiang Su wrote:
> 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.
/* snip */
> if (argc < 1)
> - return NULL;
> + goto fallback_cpu;
I don't think this should be changed, if argc < 1 it means the spec
(disambiguation: the thing printed by "gcc -dumpspecs", hard coded in
gnu-user.h) is wrong. It cannot happen with the built-in spec, but if a
user specifies a bad custom spec with "-spec", we shouldn't be tricked.
> arch = strcmp (argv[0], "arch") == 0;
> if (!arch && strcmp (argv[0], "tune"))
> - return NULL;
> + goto fallback_cpu;
Likewise.
> f = fopen ("/proc/cpuinfo", "r");
> if (f == NULL)
> - return NULL;
> + goto fallback_cpu;
OK.
> +fallback_cpu:
> +/*FIXME: how about other OSes, like FreeBSD? */
https://reviews.freebsd.org/D12743 added elf_aux_info as a counterpart
of getauxinfo, but it looks like FreeBSD does not have AT_BASE_PLATFORM.
> +#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);
getauxval is added in Glibc-2.16 so it will fail to build on hosts with
old glibc or other libc implementation. Check if getauxval and
AT_BASE_PLATFORM are available (in gcc/configure.ac) instead of an
inaccurate "#ifdef __linux__".
> +#endif
> +
> if (cpu == NULL)
> +#if defined (_MIPS_ARCH)
> + cpu = _MIPS_ARCH;
> +#else
Ok.
> return NULL;
> +#endif
>
> return concat ("-m", argv[0], "=", cpu, NULL);
> }
next prev parent reply other threads:[~2022-08-24 5:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-02 11:10 YunQiang Su
2022-08-14 10:36 ` YunQiang Su
2022-08-24 4:14 ` YunQiang Su
2022-08-24 5:56 ` Xi Ruoyao [this message]
2022-09-16 12:23 ` [PATCH v2] " YunQiang Su
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c40416d5600d6b0c411a2bfb4e8f9a891df51832.camel@xry111.site \
--to=xry111@xry111.site \
--cc=gcc-patches@gcc.gnu.org \
--cc=macro@orcam.me.uk \
--cc=yunqiang.su@cipunited.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).