From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2125.outbound.protection.outlook.com [40.107.117.125]) by sourceware.org (Postfix) with ESMTPS id 4C55E384D168 for ; Fri, 16 Sep 2022 12:23:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4C55E384D168 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=cipunited.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=cipunited.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cmnaagABHZ5xa1WX6eBN9O8XI339pCbiLLORuF2NdnHcainWzSJWEvcSTL/PmArjVz930ZbJrDrebM/x7FtlqVYXNKMyQAES2PDK4rX/JPINqyIW/9OXhb25l6OqJ0xFe8l21R+RYaZM9OAl3YReWTc+GHwzMtYJ/oauBbdNrfSPGChriFxSW4y2Ey9ovEj8D0XOT6rFwJ5xIB6iB/ZUvq0gms2RzpFV2wnlmBpwVYn6T5Pdw8XN2wspR3bUy70U6Su6C1pESbDDwl4siRpsrD1+sjOR6Fiiz6Jh8CGQrS4qarGjtHvLjcsNnTiAZv6aFFtnsHlg5QKrxFsolEkcmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NfW0BNRdAgF4Rn/vO+Y67N9FgDAoqcI6Q/ym8MTmSTg=; b=UdZzVIaB7FXwX1suaoz5eI8K5cYiQuRDB04fyRPjTZ9EPXGlhISklcP5Kj26fyDGhFLiERhcIr54ENJ2XcjlnuR2fHFH6s90x/w9LQ6Wwc8JT+R5ISmpa/sDBLwNuG2A+HOHO2PZPP4Agz4emq+VDSHFIcY3UwpSrQuZ51ahn1NjBpp6vlx0J9EZAqHzzwlkuDCHTU+ij0djeTGBKrpW140gndRxvStQlh1wK1A6o6OkDYOgGjsl698QBxz3dDCBNOMBu3fHWGYzx8nzFlr8GP279TlHgG9AGYYvub7GgcCD6As15P1f5T4NVg7adwxNzfHpYDvSBHjfP2c5t3aobg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=cipunited.com; dmarc=pass action=none header.from=cipunited.com; dkim=pass header.d=cipunited.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cipunited.onmicrosoft.com; s=selector1-cipunited-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NfW0BNRdAgF4Rn/vO+Y67N9FgDAoqcI6Q/ym8MTmSTg=; b=ON12n2Y6DAcNgIBv22hzoAVMZ1LVDipZtbV+MbKvGlJ990K6JE4NBEkPDMaInrnRa3ZrAU+B1s+Ebd4ZuZGUUKNTVvLsjHqqdgsOpwuwAAq1C+xSgUXuirrM4rJLlqHymsbuLE7cw1JRGacw4AjidbpaDh3/ewUYNCiONTQexrA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=cipunited.com; Received: from HKAPR04MB3956.apcprd04.prod.outlook.com (2603:1096:203:d5::13) by KL1PR0401MB4115.apcprd04.prod.outlook.com (2603:1096:820:27::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.17; Fri, 16 Sep 2022 12:23:48 +0000 Received: from HKAPR04MB3956.apcprd04.prod.outlook.com ([fe80::b49a:e8b:f907:610]) by HKAPR04MB3956.apcprd04.prod.outlook.com ([fe80::b49a:e8b:f907:610%9]) with mapi id 15.20.5632.016; Fri, 16 Sep 2022 12:23:48 +0000 From: YunQiang Su To: gcc-patches@gcc.gnu.org Cc: macro@orcam.me.uk, xry111@xry111.site, YunQiang Su Subject: [PATCH v2] MIPS: improve -march=native arch detection Date: Fri, 16 Sep 2022 12:23:14 +0000 Message-Id: <20220916122314.3826744-1-yunqiang.su@cipunited.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220802111009.35536-1-yunqiang.su@cipunited.com> References: <20220802111009.35536-1-yunqiang.su@cipunited.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: TYWP286CA0001.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:178::12) To HKAPR04MB3956.apcprd04.prod.outlook.com (2603:1096:203:d5::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HKAPR04MB3956:EE_|KL1PR0401MB4115:EE_ X-MS-Office365-Filtering-Correlation-Id: 4c11bd70-9644-46a4-24eb-08da97de4e2a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cc368XrvUwAwuiZjFz1ezvr6dknPazx25I6hwGlvIhECpmvxlUHonwF5TS6M0oGQxcYxRgDTou150ePCP6Vkc0T3KMTB7EYDEFrbdnaFHEcDLARKK42b15E5WSoVvywnWTWyweg4flKVP29xwbFbJyFgyAWS8TF+4RXnGpQoYvw+kGoOH+7dySgBJq4IRX1P3OBKhdeifGZBQGoQSA5dVzo4z28OuY+CIzbp0Nw0W537Wdsy8+iXRPKbSRXbeYYT0e+FiCMexnzNIgZsfCflwUF2+xE5tStWnsUsrjlqHO0EUh7mgxg2m1Uvg9YKJUMa9MGN/yrfcSqxbxdC5jEpGChB06eJ5Z/uvy3/h6fei0HRULDwrJSv0lCdI1D97zU3Q8DAkXjciO8B9S2BM3R3j37juXFkk1cWvH4BnLm8n1yg8158NVF7p0wNTBiIZUkD6qO8BaQ7sHmcVC2lEoJ0cbnelegdIAUS9F+k/EhNw3du6tZk2/7xVsSgq9pwsw2d9KD69W1ky9rK2WKARPAYulD806Kxnx0VetSs3aUid34/DhcdByhpHZLUHMbCB5YLpKqO/8GrfNRsyKi/8dreVL32U8m4l5sseEx/ERXc+SYhc43UWtRT9c/d9+w3CQyVHHLVd9dPmt1GPYWsf7VY/cRIKKpgpr4DFZv7yMmwDO5dWKZLxP9jmCIT6ZiNYhPf6IpZM6qXHTTV2n8lHzXvMbeAWNmo9EI/s+0ak22JwEgDc5r4MC1PcqGl+WrgLhHViIBCAmq8IARJX/QF2Izu+g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:HKAPR04MB3956.apcprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(136003)(366004)(396003)(376002)(39830400003)(346002)(451199015)(52116002)(6486002)(6506007)(478600001)(107886003)(6666004)(41300700001)(83380400001)(6512007)(26005)(1076003)(186003)(2616005)(5660300002)(2906002)(316002)(8676002)(6916009)(4326008)(8936002)(66556008)(66476007)(66946007)(38350700002)(38100700002)(36756003)(86362001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?dO17dsvrrudNkbw4WPuxXVt1TxUo0HD/CFbmZtSO3/Om3+wE9LfY77IV/9xG?= =?us-ascii?Q?zkM7cN9J+f/k9fI+a+PGWA2yHSMiWm0KsADbA/hCTUgwsnojO543xtN8N+Hr?= =?us-ascii?Q?n8szeYkCV5V6ss0RvcRHfuPr9gOqZ4RgKueve9qW7EPV9Q5UYopvNcDjtsDO?= =?us-ascii?Q?tKFY1Zf99cvtuFwnU0kXpJ9AjdwQbLCkXrwVhAC88dmw5tqs6eZmSI+61VqJ?= =?us-ascii?Q?8K5rhZCegaoOf7bxrPITZCqiNvF6pfXN9AhE5AWaZ08ibzjo1MjEW0U7qTkp?= =?us-ascii?Q?DeDDBx+3OFomoKuXV9i/Y7TSRhNc+0tq+/McEnH8lFTqYFH/Nda5LtAdw+bZ?= =?us-ascii?Q?RKOmFAPcItslLpB67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us-ascii?Q?NXHtUe1AXNFgok//gWw7kq2P0J0QDGV0WHBWHRPa3rEkvkdIJuTMzXWVGiR8?= =?us-ascii?Q?+Rb6jT3y3xgft8e7Qf5dlzP9bA6sGSws6kSPzYUwuUlec+TJBFBT7AVIp6ov?= =?us-ascii?Q?onuEKNsULurzoSqm+MBJRvczupyjS6W250aoQ1XRjCauW3VIxW9yBlpO5Uny?= =?us-ascii?Q?SJB2WrK7zqK0Tfg15sYTG2+IMVj/6Hxqo3rMsbH0K3tzhhO5wucs7r4B27lR?= =?us-ascii?Q?1I1Ga4w9mxh5JYDNcq3kzjPUauZhXd0lXUTgCHuPdq04ms/aDd/QI3nqSdnu?= =?us-ascii?Q?/DtaugBLFzH+A/K7Vf2sqjY+hvr1E8JSEAlVZE44XYACgwFfXxTFKuB9+M3T?= =?us-ascii?Q?iw=3D=3D?= X-OriginatorOrg: cipunited.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4c11bd70-9644-46a4-24eb-08da97de4e2a X-MS-Exchange-CrossTenant-AuthSource: HKAPR04MB3956.apcprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Sep 2022 12:23:47.9389 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: e31cf5b5-ee69-4d5f-9c69-edeeda2458c0 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: oUYZz+PvzfUvpm+ngjoK0q6s4+DZgqEVm/0Kh3M8LfpRFMphnWDCwE29Tsr7GamhPzOivqB5R2sTtLNwbW73xC0Xm9XiDQFiQglnm07Bdlc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR0401MB4115 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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. --- gcc/config.gcc | 2 ++ gcc/config.in | 10 ++++++++++ gcc/config/mips/driver-native.cc | 25 ++++++++++++++++++++++--- gcc/configure | 4 ++-- gcc/configure.ac | 4 ++-- 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/gcc/config.gcc b/gcc/config.gcc index f4e757bd853..181a062825d 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -5590,6 +5590,8 @@ case ${target} in esac if test x$with_arch != x; then default_mips_arch=$with_arch + else + with_arch=$default_mips_arch fi if test x$with_abi != x; then default_mips_abi=$with_abi diff --git a/gcc/config.in b/gcc/config.in index 6ac17be189e..cc217b94e0c 100644 --- a/gcc/config.in +++ b/gcc/config.in @@ -1939,6 +1939,12 @@ #endif +/* Define to 1 if you have the header file. */ +#ifndef USED_FOR_TARGET +#undef HAVE_SYS_AUXV_H +#endif + + /* Define to 1 if you have the header file. */ #ifndef USED_FOR_TARGET #undef HAVE_SYS_FILE_H @@ -2672,3 +2678,7 @@ #undef vfork #endif +/* Define to 1 if you have the `getauxval' function. */ +#ifndef USED_FOR_TARGET +#undef HAVE_GETAUXVAL +#endif diff --git a/gcc/config/mips/driver-native.cc b/gcc/config/mips/driver-native.cc index 47627f85ce1..327ad255c3e 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 +#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; } diff --git a/gcc/configure b/gcc/configure index 817d765568e..a419ac66576 100755 --- a/gcc/configure +++ b/gcc/configure @@ -9327,7 +9327,7 @@ $as_echo "#define GWINSZ_IN_SYS_IOCTL 1" >>confdefs.h fi for ac_header in limits.h stddef.h string.h strings.h stdlib.h time.h iconv.h \ - fcntl.h ftw.h unistd.h sys/file.h sys/time.h sys/mman.h \ + fcntl.h ftw.h unistd.h sys/auxv.h sys/file.h sys/time.h sys/mman.h \ sys/resource.h sys/param.h sys/times.h sys/stat.h sys/locking.h \ direct.h malloc.h langinfo.h ldfcn.h locale.h wchar.h do : @@ -10622,7 +10622,7 @@ fi for ac_func in times clock kill getrlimit setrlimit atoq \ popen sysconf strsignal getrusage nl_langinfo \ gettimeofday mbstowcs wcswidth mmap posix_fallocate setlocale \ - clearerr_unlocked feof_unlocked ferror_unlocked fflush_unlocked fgetc_unlocked fgets_unlocked fileno_unlocked fprintf_unlocked fputc_unlocked fputs_unlocked fread_unlocked fwrite_unlocked getchar_unlocked getc_unlocked putchar_unlocked putc_unlocked madvise mallinfo mallinfo2 fstatat + clearerr_unlocked feof_unlocked ferror_unlocked fflush_unlocked fgetc_unlocked fgets_unlocked fileno_unlocked fprintf_unlocked fputc_unlocked fputs_unlocked fread_unlocked fwrite_unlocked getchar_unlocked getc_unlocked putchar_unlocked putc_unlocked madvise mallinfo mallinfo2 fstatat getauxval do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_cxx_check_func "$LINENO" "$ac_func" "$as_ac_var" diff --git a/gcc/configure.ac b/gcc/configure.ac index 59f205a1781..b9cc0dda571 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -1307,7 +1307,7 @@ ACX_HEADER_STRING AC_HEADER_SYS_WAIT AC_HEADER_TIOCGWINSZ AC_CHECK_HEADERS(limits.h stddef.h string.h strings.h stdlib.h time.h iconv.h \ - fcntl.h ftw.h unistd.h sys/file.h sys/time.h sys/mman.h \ + fcntl.h ftw.h unistd.h sys/auxv.h sys/file.h sys/time.h sys/mman.h \ sys/resource.h sys/param.h sys/times.h sys/stat.h sys/locking.h \ direct.h malloc.h langinfo.h ldfcn.h locale.h wchar.h) @@ -1525,7 +1525,7 @@ define(gcc_UNLOCKED_FUNCS, clearerr_unlocked feof_unlocked dnl AC_CHECK_FUNCS(times clock kill getrlimit setrlimit atoq \ popen sysconf strsignal getrusage nl_langinfo \ gettimeofday mbstowcs wcswidth mmap posix_fallocate setlocale \ - gcc_UNLOCKED_FUNCS madvise mallinfo mallinfo2 fstatat) + gcc_UNLOCKED_FUNCS madvise mallinfo mallinfo2 fstatat getauxval) if test x$ac_cv_func_mbstowcs = xyes; then AC_CACHE_CHECK(whether mbstowcs works, gcc_cv_func_mbstowcs_works, -- 2.30.2