From patchwork Tue Aug 2 11:10:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: YunQiang Su X-Patchwork-Id: 347 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:b5d6:b0:2b9:3548:2db5 with SMTP id v22csp2903571pxt; Tue, 2 Aug 2022 04:11:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sjj7pm9mFkZAKE+bDXMUW8bIAU+Rvt8aOAQAzBFbzne9ZaLYkZlUFA1tFzL+UlR/KDNEir X-Received: by 2002:a17:907:d28:b0:72b:5cc9:99c with SMTP id gn40-20020a1709070d2800b0072b5cc9099cmr15890318ejc.228.1659438683441; Tue, 02 Aug 2022 04:11:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1659438683; cv=pass; d=google.com; s=arc-20160816; b=r0rye3gd26Vy4TBWVI/GJN1/nuv4gvFtCyLJazuPFl0C57SU/hu2YbGNsEYySdJBj3 7xsNfEeQtu7vzUinRWkJ1c90YYQp/bgcNYKy0Q9o0M7Kynt5GflLMdF9HcCq5nW708Mn Bdjk5suSQ+VXqznIe7GZ12dtlLI2p+NjjcKTiXaqI7YyftvNE5zt4N6Xnp7Ybc9MKVqd jAT4fyabKgURazvmHN5Q5BNEJI7Ph1lKktjiiQY8U5rzQE75g5HCVBqpSmynjLfe7T9L p4JFnGdAVJSSSjfuUmlPa91KH0w88tTSSf0z6D3XAK1mM3dRkSjwqzhGzGjZZu3u1c6k Sr6A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version :content-transfer-encoding:message-id:date:subject:to:from :dkim-signature:dmarc-filter:delivered-to; bh=QWyviEQv8s8zBwTDB6QzxJarG58gzzjP9UqofUVA8Pw=; b=C1Txe6p+BAMSi3zBVT85o/nKknugpo0lNJf/kPb60beBshb01byKEkHlV52hGJlN6M Zll4F5iGF8yXnPVH48n5jCaEVetOameIrBAKIhbuTkr3sUHwTUSckqat3xaZhKxVlSfK 5mt7VjMC0d/UIRCA5UBVSMKhgo2h6gL/PUJIB3L4G7mcuZLnb0cl8emtPCEUAbebWQrD UcUJhrglZtA/ki7hmv7FP/Z9ummvaj0eYCoMFCvZBGir7kmfB97vdwqxf+1h/x3Bkd2f hcIK2gIJ96SBjYlvEclU2A51TdxiuFyzHYNIBXNNpDX15P98EsDu8z/9FQj0+4pwd5zc 4bOg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cipunited.onmicrosoft.com header.s=selector1-cipunited-onmicrosoft-com header.b="tL7/vDjy"; arc=pass (i=1 spf=pass spfdomain=cipunited.com dkim=pass dkdomain=cipunited.com dmarc=pass fromdomain=cipunited.com); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id hf6-20020a1709072c4600b006ffe48f0c5bsi9802460ejc.346.2022.08.02.04.11.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 04:11:23 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@cipunited.onmicrosoft.com header.s=selector1-cipunited-onmicrosoft-com header.b="tL7/vDjy"; arc=pass (i=1 spf=pass spfdomain=cipunited.com dkim=pass dkdomain=cipunited.com dmarc=pass fromdomain=cipunited.com); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1F4F1385AE4F for ; Tue, 2 Aug 2022 11:11:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2096.outbound.protection.outlook.com [40.107.215.96]) by sourceware.org (Postfix) with ESMTPS id BCBD33856DDE for ; Tue, 2 Aug 2022 11:10:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BCBD33856DDE 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=SvgA0XJcWREztQWXmCYMH24kfZGMV9Gf4FrJVNSZukwKjU9veIKON3v0+VJc2CeFbATTV9fjNBN2KWu/JK+orFvfC31Ree0BK+18RcovFYVXBNGMjUEjpSfw/NHuU43Yq9KHCvqCrIsME3cpB7QQRWDFv5jNkOp64jq6xVLLO7N4k80nC62Xxz5wZoZmM30BY+I4QGCDZHpiyd5T4pdo9e5EGoCDHV11qirSMfXYFT+QMZse50Z38At4INRi1Vq5axRcVFU9yyT8lZCRGZEX1+B1CBDm7fuc9T2S2OU9Ut512TQTxZVXiDNSoBzeCP3wihLoRN6f6ssz4tPlv8h8sw== 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=QWyviEQv8s8zBwTDB6QzxJarG58gzzjP9UqofUVA8Pw=; b=U0kNHLx1o0B7TAPRJsSSwUHDCU6Tbh3Ip4zaqku/xdO4O9IqqIMjc5TVDvlev35cMtWCCnnB1a5fOPP9Na/hOpa3LbPCKVUDJ7wBzz0e89l3IeOSJGnSepBWUsxYUiAjZFPoICCy6kxua9nQhY3ta4Q3oF5UVTIjoGTzLbI5hM5zoXbUHuMYt5zgtWXA/hfseemBcUjY9MCt7SdyZxteXWqNTOxrSXV8RC/Ly1BmXfAaol4aoPVbjZ0bjOwDTCTXRCYGI7MFBp+oVo31BFzRFUt1g53Ts0Hmz4s3WCCAkAIXdzNGNmLX1nRu5WngkBYSyj3rfMdaspX/1m/SPYMkMg== 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=QWyviEQv8s8zBwTDB6QzxJarG58gzzjP9UqofUVA8Pw=; b=tL7/vDjydwsov2fQYuwnB3uU/y/GNoMorOeTxnPf/CxYznocry/1n5ny+b8Z5jJGu3nFOhKzPwKQpIsnLNRe4zePytoh1St1oGfqQWVkYlfD5q8NL7zHsMvqfZdrlIHCfO7ny3SWXRBSkOhEIjWvs96u9V07tcpcgjTsf89kxik= 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 TYZPR04MB4654.apcprd04.prod.outlook.com (2603:1096:400:59::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5482.11; Tue, 2 Aug 2022 11:10:45 +0000 Received: from HKAPR04MB3956.apcprd04.prod.outlook.com ([fe80::a553:a63a:459a:363e]) by HKAPR04MB3956.apcprd04.prod.outlook.com ([fe80::a553:a63a:459a:363e%5]) with mapi id 15.20.5482.016; Tue, 2 Aug 2022 11:10:45 +0000 From: YunQiang Su To: gcc-patches@gcc.gnu.org Subject: [PATCH] MIPS: improve -march=native arch detection Date: Tue, 2 Aug 2022 11:10:09 +0000 Message-Id: <20220802111009.35536-1-yunqiang.su@cipunited.com> X-Mailer: git-send-email 2.30.2 X-ClientProxiedBy: BY5PR17CA0049.namprd17.prod.outlook.com (2603:10b6:a03:167::26) To HKAPR04MB3956.apcprd04.prod.outlook.com (2603:1096:203:d5::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1fa4b22f-b684-4ae8-533c-08da7477a4ff X-MS-TrafficTypeDiagnostic: TYZPR04MB4654:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: K940Nc03jLvv34Se/p9BV6Ek0i7rZ8qxsDze32YqNaJf882GznojWX4C01zQ/M5YXrJRfHFe9ynNnFcxgZZFNuL5w/XiVFk/8vx8Ypy1nNHkCk2pMedus24IqfeK8vbWmT7xVtVLz6SuTl2K2iq1h69yO6gYdMCnT97FhvI9M57lptdArCnE4HAj63mpJIMyvashE/eGL+FLdFN6+iXQp/TFlO45hlYIuA2vuZb5lXUlyNgeHZ3UGt53BDbQOQHTHdgOt/qGrKcxfi2iW3zOgu6aI9UdJvrxFpsf+2XKvH4JHlQMmjjJNS5hlFdW8TlA3aMcMEIaLfTfKQYNMdHMBQdvAmMfVNVe9STSAuX5ySll4ikqZ0hqQEuk8Rrt3tlDr1Qw5DVOK9wxEHxmYNmtwko9nUEnv/2FORdFpZcebWUcDrtTHrFFNP4blEa5fVIrtKnpWf/A93ZV9EKQ/c8N+0sYvt97QagpMiwbXUMe+VRZ30peNgzxTvfE3zU6oPpou+0OIMqRqvIvMaVUNz/l+aEG4N9hAsZelOMoZUWVleehRmOYoCRNt230FKecW7hfrzr7KNzPlVUbWSzMAzFv6fJ1nxGCxnUCn1JbPWjeV/FP0ttbtRJljPpUsO3S9a3lqT5RUfQFVqTC5LrZg0sskubQVfV1vcJi/efMhNWvHrUum/Jrt5N/nGO7+M9Jy7kPuZ2ZUe35aMOekoT6Lkk3wmAwC5o4PF0gHGkV344oSrXjYWnz3m5k7pBW/kIBWp37 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:(13230016)(396003)(39830400003)(136003)(366004)(376002)(346002)(41300700001)(52116002)(6666004)(6506007)(6512007)(316002)(6916009)(86362001)(478600001)(6486002)(38100700002)(1076003)(107886003)(83380400001)(186003)(4326008)(2616005)(2906002)(36756003)(66946007)(66556008)(8676002)(66476007)(8936002)(5660300002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WL0cUEfvcVF0eZ220lLeSrhDOinr4ruuG+jf0WgHMvyZ9vJimOnTyOANqG04eVV3RVRDF6U725WD24zjLJMcD7cGbPU4I2Xva+mLyv4AbI348icTuyeFJNNqa4LMqJ7sOtJfIYawrSUCX+r0gtf9s+IJLR1roRqHHzl3q/ODevgz3ad7cIjq+jTcLJOLobV/BKUSIekeLKSVuK19rA6U3XrT4JCX1MqulHUbyoQSwSGlI47wb31BTi/x/alYPl1Djz9ZLDq2r83Lot/prPkjegjaVpQwR91BX1zK22gS9EjrueITlacsoDgP7VS5MlSvrrRLWfYp9AYuBVPmvL1+i3qb/gmxjb95Q7VeZwtuYP7ssGn5kkmNHo28EHmX7jWXi8Dra3NJmZ3gNLv3swY2/rJ8aS9L+2NsSlNqbq/E8GB36xxkqqu3b3gaoBcgkDQCnJkpFjgGytVWiDOjTMD5WBIkm7uQWwm8D6Cg378SAKKryC3R0viA0uLfxYEuq4bovrPZfkOWBrvSHyT6bg6m5JajwdAhVp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NM+AcwGED/rzLvqM1Ci7bQokwF5fER9v7Ln1UyQkHwdpf6A== X-OriginatorOrg: cipunited.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1fa4b22f-b684-4ae8-533c-08da7477a4ff X-MS-Exchange-CrossTenant-AuthSource: HKAPR04MB3956.apcprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Aug 2022 11:10:44.8847 (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: sZPiJGGWYLYVxcqnNwo8JnLggPObfr6aotIOOL/TdPQIRQpZxd8o9oZJIZUEo5QBZj2/OR7hpB/iKXCCHEPsGzlr53Jc72kJamg+W6Hl24Q= X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR04MB4654 X-Spam-Status: No, score=-12.8 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: YunQiang Su , macro@orcam.me.uk Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1740047576977500699?= X-GMAIL-MSGID: =?utf-8?q?1740047576977500699?= 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 #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); }