Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp4237128rwb; Mon, 31 Jul 2023 04:00:57 -0700 (PDT) X-Google-Smtp-Source: APBJJlGcZnaEjcFQHLoz1bo7lsOJdKtfVr/lpWf6zuvXGGPT6kHtxf/OfD/pKC9Izk7r1WVA/J92 X-Received: by 2002:a05:6a00:21c5:b0:66a:386c:e6a6 with SMTP id t5-20020a056a0021c500b0066a386ce6a6mr9236895pfj.6.1690801257117; Mon, 31 Jul 2023 04:00:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690801257; cv=none; d=google.com; s=arc-20160816; b=ymnaK8wc2W/OKq2z7DbkkWCDJNyAEPK+4aKZH1gOBMny381Li5tC8KyCPeeD6WIxO+ fTEC8jpyIhof+z19xSFcOZW5VGBsgs/+5tu7p+ZH6vMrjp8osqyaBysxp5vTj4LM2apq 0SuMGA2UCoKTe/2fCdElSLu0B/3xJvBMqLiCnjJnE5Hdz/jOM3T9VC9UV0hxL+/9IN9B 5ZbVIv9yJGFSpyvUm3vaWL8eZT69nnczdEdACPWkSZbvdAUxGQxMU+wj2d2eYrc41M1K L57Jo9eEjDSGUZqhnybOLwUBgqNM8ieMeZdZZWhgTh/wZoqOZ3eqOOJ5GAS6bdaDLqZs +2mA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=CuXPp6whRpodywGswa3L1NBUnbDKwmzTi9wTePAB9aM=; fh=6VkC3jmja5xXBiMrcKSCplhanbCgLleEU3Rj7GrYD+A=; b=NE8SR+hBkrMfTXU1igxPCMkW4ejEYUe5txIHoxIr06KvyCFGhGEZqEYe4Zrfa/rGtd S2DrRGgXXwlEZs5yP2Sg/g9oBk0z4auql7/M7ImdBcEh6xkkgSYsHmTq/hZajBNII8os EomajSthJRCuS6WG0iF8+0i9rOSUMlkYf1hS345pVzRG/vZPRjf0UKf7eWTj6y7tw9Po jlVlE3OXuQYV95JnLN0pk8xvbSAtkKfHoBNvzm8dcpVwg5BQfM1SutDdqjDEG9WwaVYC eJyZlquFS0OjjHRqrvr3ab7YUcdhccPbWM8V8A7P/Akzo2FnwU5mTNUD7fDpmV+yO6Np t75Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l19-20020a637013000000b00563519244dbsi6983004pgc.169.2023.07.31.04.00.44; Mon, 31 Jul 2023 04:00:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231164AbjGaKD3 (ORCPT + 99 others); Mon, 31 Jul 2023 06:03:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232544AbjGaKDJ (ORCPT ); Mon, 31 Jul 2023 06:03:09 -0400 Received: from cstnet.cn (smtp81.cstnet.cn [159.226.251.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C35644A8; Mon, 31 Jul 2023 03:00:44 -0700 (PDT) Received: from xmz-huawei.. (unknown [111.197.209.91]) by APP-03 (Coremail) with SMTP id rQCowAB3fmYVhsdkcricDw--.15360S2; Mon, 31 Jul 2023 17:59:49 +0800 (CST) From: Mingzheng Xing To: Conor Dooley , Paul Walmsley , Palmer Dabbelt , Albert Ou , Nathan Chancellor , Nick Desaulniers , Tom Rix Cc: Bin Meng , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, stable@vger.kernel.org, Guo Ren , Mingzheng Xing Subject: [PATCH v3] riscv: Handle zicsr/zifencei issue between gcc and binutils Date: Mon, 31 Jul 2023 17:59:36 +0800 Message-Id: <20230731095936.23397-1-xingmingzheng@iscas.ac.cn> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: rQCowAB3fmYVhsdkcricDw--.15360S2 X-Coremail-Antispam: 1UD129KBjvJXoWxuw4UGFyrury5GFWfKF1rJFb_yoW7tr4xpr ZxCryDCrsYg3y8Gr1fJw4UWw1Yvrs3J3yFgayjkw1UWrnxJFyDKrZYkw47XFyUZFn3K390 vw1I9FsYg3ZrAaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUv014x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r4j6ryUM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j 6F4UM28EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Cr 1j6rxdM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj 6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr 0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E 8cxan2IY04v7MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I 8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8 ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x 0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_ Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUb XdbUUUUUU== X-Originating-IP: [111.197.209.91] X-CM-SenderInfo: 50lqwzhlqj6xxhqjqxpvfd2hldfou0/1tbiBwcJCmTHZ+JhaAABst X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Binutils-2.38 and GCC-12.1.0 bumped[0][1] the default ISA spec to the newer 20191213 version which moves some instructions from the I extension to the Zicsr and Zifencei extensions. So if one of the binutils and GCC exceeds that version, we should explicitly specifying Zicsr and Zifencei via -march to cope with the new changes. but this only occurs when binutils >= 2.36 and GCC >= 11.1.0. It's a different story when binutils < 2.36. binutils-2.36 supports the Zifencei extension[2] and splits Zifencei and Zicsr from I[3]. GCC-11.1.0 is particular[4] because it add support Zicsr and Zifencei extension for -march. binutils-2.35 does not support the Zifencei extension, and does not need to specify Zicsr and Zifencei when working with GCC >= 12.1.0. To make our lives easier, let's relax the check to binutils >= 2.36 in CONFIG_TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI. For the other two cases, where clang < 17 or GCC < 11.1.0, we will deal with them in CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC. For more information, please refer to: commit 6df2a016c0c8 ("riscv: fix build with binutils 2.38") commit e89c2e815e76 ("riscv: Handle zicsr/zifencei issues between clang and binutils") Link: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=aed44286efa8ae8717a77d94b51ac3614e2ca6dc [0] Link: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=98416dbb0a62579d4a7a4a76bab51b5b52fec2cd [1] Link: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=5a1b31e1e1cee6e9f1c92abff59cdcfff0dddf30 [2] Link: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=729a53530e86972d1143553a415db34e6e01d5d2 [3] Link: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=b03be74bad08c382da47e048007a78fa3fb4ef49 [4] Link: https://lore.kernel.org/all/20230308220842.1231003-1-conor@kernel.org Link: https://lore.kernel.org/all/20230223220546.52879-1-conor@kernel.org Signed-off-by: Mingzheng Xing --- v3: - Relax the check to binutils >= 2.36. - Update the Kconfig help text and commit message. v2: - Update the Kconfig help text and commit message. - Add considerations for low version gcc case. arch/riscv/Kconfig | 33 ++++++++++++++++---------- arch/riscv/kernel/compat_vdso/Makefile | 8 ++++++- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 4c07b9189c86..2704bd91dfb5 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -570,24 +570,31 @@ config TOOLCHAIN_HAS_ZIHINTPAUSE config TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI def_bool y # https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=aed44286efa8ae8717a77d94b51ac3614e2ca6dc - depends on AS_IS_GNU && AS_VERSION >= 23800 - help - Newer binutils versions default to ISA spec version 20191213 which - moves some instructions from the I extension to the Zicsr and Zifencei - extensions. + # https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=98416dbb0a62579d4a7a4a76bab51b5b52fec2cd + depends on AS_IS_GNU && AS_VERSION >= 23600 + help + Binutils-2.38 and GCC-12.1.0 bumped the default ISA spec to the newer + 20191213 version, which moves some instructions from the I extension to + the Zicsr and Zifencei extensions. This requires explicitly specifying + zicsr and zifencei when binutils >= 2.38 or GCC >= 12.1.0, but this only + occurs when binutils >= 2.36 and GCC >= 11.1.0. It's a different story + when binutils < 2.36. Also, we have to consider the case of clang paired + with binutils. + To make our lives easier, we relax the check to binutils >= 2.36. For + the other two cases, where clang < 17 or GCC < 11.1.0, we will deal with + them in CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC. config TOOLCHAIN_NEEDS_OLD_ISA_SPEC def_bool y depends on TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI # https://github.com/llvm/llvm-project/commit/22e199e6afb1263c943c0c0d4498694e15bf8a16 - depends on CC_IS_CLANG && CLANG_VERSION < 170000 - help - Certain versions of clang do not support zicsr and zifencei via -march - but newer versions of binutils require it for the reasons noted in the - help text of CONFIG_TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI. This - option causes an older ISA spec compatible with these older versions - of clang to be passed to GAS, which has the same result as passing zicsr - and zifencei to -march. + # https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=b03be74bad08c382da47e048007a78fa3fb4ef49 + depends on (CC_IS_CLANG && CLANG_VERSION < 170000) || (CC_IS_GCC && GCC_VERSION < 110100) + help + Certain versions of clang and GCC do not support zicsr and zifencei via + -march. This option causes an older ISA spec compatible with these older + versions of clang and GCC to be passed to GAS, which has the same result + as passing zicsr and zifencei to -march. config FPU bool "FPU support" diff --git a/arch/riscv/kernel/compat_vdso/Makefile b/arch/riscv/kernel/compat_vdso/Makefile index 189345773e7e..b86e5e2c3aea 100644 --- a/arch/riscv/kernel/compat_vdso/Makefile +++ b/arch/riscv/kernel/compat_vdso/Makefile @@ -11,7 +11,13 @@ compat_vdso-syms += flush_icache COMPAT_CC := $(CC) COMPAT_LD := $(LD) -COMPAT_CC_FLAGS := -march=rv32g -mabi=ilp32 +# binutils 2.35 does not support the zifencei extension, but in the ISA +# spec 20191213, G stands for IMAFD_ZICSR_ZIFENCEI. +ifdef CONFIG_TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI + COMPAT_CC_FLAGS := -march=rv32g -mabi=ilp32 +else + COMPAT_CC_FLAGS := -march=rv32imafd -mabi=ilp32 +endif COMPAT_LD_FLAGS := -melf32lriscv # Disable attributes, as they're useless and break the build. -- 2.34.1