From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from xry111.site (xry111.site [IPv6:2001:470:683e::1]) by sourceware.org (Postfix) with ESMTPS id 11CAB38582BE for ; Wed, 24 Aug 2022 05:57:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 11CAB38582BE Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1661320639; bh=6aKECdBPcXyf23/VlxFR/uO81BTFi4ounp+rkDZ/SiU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=AeIE135dyoOIQ/awDEISBgD5E+wcPHOQxt1eC8VFkmzkAL3iuuWXJc3EehlYzMrA8 PnlzaQjUBBx69fNHAEV6UIBo/Sx8mJoUfMFRd49/FI4lSqKJxTmK75Dw3t+h11G7Y5 xQJVB7t13UTh+Z8XaTjFIgoZBdWyep5S8LYPHdFI= Received: from [IPv6:240e:358:113a:9c00:dc73:854d:832e:3] (unknown [IPv6:240e:358:113a:9c00:dc73:854d:832e:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384)) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id AEF1C66849; Wed, 24 Aug 2022 01:57:12 -0400 (EDT) Message-ID: Subject: Re: [PATCH] MIPS: improve -march=native arch detection From: Xi Ruoyao To: YunQiang Su , gcc-patches@gcc.gnu.org Cc: macro@orcam.me.uk Date: Wed, 24 Aug 2022 13:56:50 +0800 In-Reply-To: <20220802111009.35536-1-yunqiang.su@cipunited.com> References: <20220802111009.35536-1-yunqiang.su@cipunited.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.45.2 MIME-Version: 1.0 X-Spam-Status: No, score=0.7 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FROM_SUSPICIOUS_NTLD,LIKELY_SPAM_FROM,PDS_OTHER_BAD_TLD,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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: > =C2=A0 1. getauxval(AT_BASE_PLATFORM), introduced since Linux 5.7 > =C2=A0 2. _MIPS_ARCH from host compiler. >=20 > This can fix the wrong loader usage on r5/r6 platform with > =C2=A0-march=3Dnative. /* snip */ > =C2=A0=C2=A0 if (argc < 1) > -=C2=A0=C2=A0=C2=A0 return NULL; > +=C2=A0=C2=A0=C2=A0 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. > =C2=A0=C2=A0 arch =3D strcmp (argv[0], "arch") =3D=3D 0; > =C2=A0=C2=A0 if (!arch && strcmp (argv[0], "tune")) > -=C2=A0=C2=A0=C2=A0 return NULL; > +=C2=A0=C2=A0=C2=A0 goto fallback_cpu; Likewise. > =C2=A0=C2=A0 f =3D fopen ("/proc/cpuinfo", "r"); > =C2=A0=C2=A0 if (f =3D=3D NULL) > -=C2=A0=C2=A0=C2=A0 return NULL; > +=C2=A0=C2=A0=C2=A0 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__ > +=C2=A0 /*Note: getauxval may return NULL as: > +=C2=A0=C2=A0 * AT_BASE_PLATFORM is supported since Linux 5.7 > +=C2=A0=C2=A0 * Or from older version of qemu-user > +=C2=A0=C2=A0 * */ > +=C2=A0 if (cpu =3D=3D NULL) > +=C2=A0=C2=A0=C2=A0 cpu =3D (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 > + > =C2=A0=C2=A0 if (cpu =3D=3D NULL) > +#if defined (_MIPS_ARCH) > +=C2=A0=C2=A0=C2=A0 cpu =3D _MIPS_ARCH; > +#else Ok. > =C2=A0=C2=A0=C2=A0=C2=A0 return NULL; > +#endif > =C2=A0 > =C2=A0=C2=A0 return concat ("-m", argv[0], "=3D", cpu, NULL); > =C2=A0}