Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp2674838rwb; Sat, 29 Jul 2023 11:21:22 -0700 (PDT) X-Google-Smtp-Source: APBJJlFfGOyrtNweRPyCxYgKf8a+ThIeqyB0+bM61g4QsZhZDPf0A3LYXzZ5aMvrzt9b5zQLvEsQ X-Received: by 2002:aa7:d48b:0:b0:522:580f:8c75 with SMTP id b11-20020aa7d48b000000b00522580f8c75mr5418414edr.17.1690654882034; Sat, 29 Jul 2023 11:21:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690654882; cv=none; d=google.com; s=arc-20160816; b=QWFjguM+J6tqqOX2EAnTJ0zc9izd7qN055pCYwY+C/TtjHqkVYWKUTkIzqjhiowhXN wIERh/b/XfJSnneRSx43QBMsW7oYhMzEt+DiAlTzuiKNoUU4UPAtCn2+LXbZ1rR0Xcz0 LKSLmC1U6FG3BqIG6Fimwyf3/VcseTt4G1frBhONF+zrKnu7IuTLmBarG9sZCvKhDs4J EsMJovqvi2sT4+pcpMYvryqzZ+rgGnaqIBHyFShVoofJBxW5/tVI9w3NAV1+nW4gFvgB ERqionKmaNjsnyj/P4j4Gf7p0e2CLP8P+DiLX7splPjmz+WMreG64RYJ+65/bwPn/m5V w5rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id; bh=UV8oTHGEjOW7+0bxjY44U8Yd4gs3Bl0GYj7QHzH0IuY=; fh=tMvkx44n2T7f7VZvSmj07JsGu6FbmEjHSo102g5qPBQ=; b=LbR2xAy/tkJRhzH0j3P48nPpjQtf1hkIAsm2Elk3HudB2fP11U/2hcn8ExvVqkfEje o4i92D9o+8JTBOcg8/BzRnxc8cfAne52hyxAJIMDSTVGGZDjsjDNN4cI06+eEXjNaSIc lyKRDbQGiVc7Z1FK6mnoPI26lRRJfazxeDZJC4sh2DDa40ZiQXCHFOD5/6ptOik9B2zO Q75MxjI6sMoHNZjhgiUyHsGDpwUR9Dw730MzoyTKYYU7daJhj0rMmtHGUABoIqXKAgK8 2I8yYYn7DnMEyNgCMakbrobSFao3cm5bqch82omASZKJmb854O0UQV/mEfUoN/FWRfVP e+UA== 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 p23-20020a056402045700b005227b130182si4592020edw.452.2023.07.29.11.20.57; Sat, 29 Jul 2023 11:21:22 -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 S229541AbjG2Rhf (ORCPT + 99 others); Sat, 29 Jul 2023 13:37:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbjG2Rhd (ORCPT ); Sat, 29 Jul 2023 13:37:33 -0400 Received: from cstnet.cn (smtp84.cstnet.cn [159.226.251.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AE9435A5; Sat, 29 Jul 2023 10:37:30 -0700 (PDT) Received: from [192.168.0.107] (unknown [111.197.209.91]) by APP-05 (Coremail) with SMTP id zQCowAC3vxcxTsVkKoC_Dw--.18514S2; Sun, 30 Jul 2023 01:36:49 +0800 (CST) Message-ID: Date: Sun, 30 Jul 2023 01:36:49 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH v2] riscv: Handle zicsr/zifencei issue between gcc and binutils Content-Language: en-US To: Conor Dooley Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Nathan Chancellor , Nick Desaulniers , Tom Rix , Bin Meng , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, stable@vger.kernel.org, Guo Ren References: <20230726174524.340952-1-xingmingzheng@iscas.ac.cn> <20230726-outclass-parade-2ccea9f6688a@spud> <10231b81-ea42-26d0-4c11-92851229e658@iscas.ac.cn> <20230726-armchair-evasive-427dd245a9fe@spud> <20230727-briskness-sappy-e2d9e4c1ef36@spud> From: Mingzheng Xing Organization: ISCAS In-Reply-To: <20230727-briskness-sappy-e2d9e4c1ef36@spud> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID: zQCowAC3vxcxTsVkKoC_Dw--.18514S2 X-Coremail-Antispam: 1UD129KBjvJXoW3Cr48KFW3Ary8XryUurWDCFg_yoWkGrWkpr WkCr1DGry8Xr18Jr4xJw1UW34UJr15J34UJr45JF1UGrykGr1jqrykXr12gr1UJF4rtr4r Ar1I9w1rZrn8AaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvlb7Iv0xC_Kw4lb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWUJVW8JwA2z4x0Y4vEx4 A2jsIEc7CjxVAFwI0_Gr0_Gr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI 64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8Jw Am72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l c7I2V7IY0VAS07AlzVAYIcxG8wCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJV W8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF 1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6x IIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvE x4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvj DU0xZFpf9x07beAp5UUUUU= X-Originating-IP: [111.197.209.91] X-CM-SenderInfo: 50lqwzhlqj6xxhqjqxpvfd2hldfou0/1tbiCggHCmTFGJdK4AAAsL X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,NICE_REPLY_A, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 On 7/27/23 15:53, Conor Dooley wrote: > On Wed, Jul 26, 2023 at 08:41:55PM +0100, Conor Dooley wrote: >> On Thu, Jul 27, 2023 at 03:34:16AM +0800, Mingzheng Xing wrote: >>> On 7/27/23 02:02, Conor Dooley wrote: >>>> This is still broken for: >>>> CONFIG_CLANG_VERSION=0 >>>> CONFIG_AS_IS_GNU=y >>>> CONFIG_AS_VERSION=23500 >>>> CONFIG_LD_IS_BFD=y >>>> CONFIG_LD_VERSION=23500 >>> Do you mean that these CONFIG_* will cause kernel >>> compilation errors when paired with certain versions of GCC? >>> Or perhaps I misunderstood your meaning. >> No, this section is generated by kconfig, although I messed up my >> trimming of the list & accidentally removed the gcc version, rather >> than the clang version. Here's the full thing: >> >> CONFIG_CC_VERSION_TEXT="riscv64-unknown-linux-gnu-gcc (g2ee5e430018) 12.2.0" >> CONFIG_CC_IS_GCC=y >> CONFIG_GCC_VERSION=120200 >> CONFIG_CLANG_VERSION=0 >> CONFIG_AS_IS_GNU=y >> CONFIG_AS_VERSION=23500 >> CONFIG_LD_IS_BFD=y >> CONFIG_LD_VERSION=23500 >> CONFIG_LLD_VERSION=0 >> CONFIG_CC_CAN_LINK=y >> CONFIG_CC_CAN_LINK_STATIC=y >> CONFIG_CC_HAS_ASM_GOTO_OUTPUT=y >> CONFIG_CC_HAS_ASM_GOTO_TIED_OUTPUT=y >> CONFIG_CC_HAS_ASM_INLINE=y >> CONFIG_CC_HAS_NO_PROFILE_FN_ATTR=y >> CONFIG_PAHOLE_VERSION=0 >> CONFIG_CONSTRUCTORS=y >> CONFIG_IRQ_WORK=y >> CONFIG_BUILDTIME_TABLE_SORT=y > I think this should sort things out for the even-older binutils case. I > took the opportunity to fix some grammatical issues that seem to have > snuck into the help text in your patch & to drop the \, since the > depends on fits in one line. hi, Conor. I reproduced the error with gcc-12.2.0 and binutils-2.35. I tried a different solution, which I think makes the logic easier. Showing the new patch code: diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 4c07b9189c86..a6fa1eed895c 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -569,25 +569,24 @@ 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 +       depends on AS_IS_GNU && AS_VERSION >= 23600         help -         Newer binutils versions default to ISA spec version 20191213 which -         moves some instructions from the I extension to the Zicsr and Zifencei -         extensions. +         Binutils has supported zicsr and zifencei extensions since version 2.36, +         try to adapt to the changes by using explicit zicsr and zifencei via +         -march. For two special 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 Here are the results of my tests: gcc          binutils       patched         no patch(test on master) 11.4.0     2.35            ok                  ok 11.4.0     2.36            ok                  ok 11.4.0     2.38            ok                  ok 12.2.0     2.35            ok                  error[1] 12.2.0     2.36            ok                  error[2] 12.2.0     2.38            ok                  ok 10.5.0     2.35            ok                  ok 10.5.0     2.36            ok                  ok 10.5.0     2.38            ok                  error[3] 11.1.0     2.35            ok                  ok 11.1.0     2.36            ok                  ok 11.1.0     2.38            ok                  ok 11.2.0     2.35            ok                  ok 11.2.0     2.36            ok                  ok 11.2.0     2.38            ok                  ok [1] Assembler messages: Fatal error: -march=rv32imafd_zicsr_zifencei: Invalid or unknown z ISA extension: 'zifencei' make[2]: *** [arch/riscv/kernel/compat_vdso/Makefile:47: arch/riscv/kernel/compat_vdso/rt_sigreturn.o] Error 1 [2] ./arch/riscv/include/asm/vdso/gettimeofday.h: Assembler messages: ./arch/riscv/include/asm/vdso/gettimeofday.h:79: Error: unrecognized opcode `csrr a5,0xc01' ./arch/riscv/include/asm/vdso/gettimeofday.h:79: Error: unrecognized opcode `csrr a5,0xc01' ./arch/riscv/include/asm/vdso/gettimeofday.h:79: Error: unrecognized opcode `csrr a5,0xc01' ./arch/riscv/include/asm/vdso/gettimeofday.h:79: Error: unrecognized opcode `csrr a5,0xc01' make[2]: *** [scripts/Makefile.build:243: arch/riscv/kernel/vdso/vgettimeofday.o] Error 1 [3] cc1: error: '-march=rv64imac_zicsr_zifencei': unsupported ISA subset 'z' cc1: error: ABI requires '-march=rv64' make[2]: *** [scripts/Makefile.build:243: scripts/mod/empty.o] Error 1 make[2]: *** Waiting for unfinished jobs.... cc1: error: '-march=rv64imac_zicsr_zifencei': unsupported ISA subset 'z' cc1: error: ABI requires '-march=rv64' > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > index e1b66ee88323..2d0d89213c97 100644 > --- a/arch/riscv/Kconfig > +++ b/arch/riscv/Kconfig > @@ -571,25 +571,27 @@ config TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI > def_bool y > # https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=aed44286efa8ae8717a77d94b51ac3614e2ca6dc > # https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=98416dbb0a62579d4a7a4a76bab51b5b52fec2cd > - depends on GCC_VERSION >= 120100 || (AS_IS_GNU && AS_VERSION >= 23800) > + depends on AS_IS_GNU > + depends on (GCC_VERSION >= 120100 && AS_VERSION >= 23600) || AS_VERSION >= 23800 Tests verified that explicit _ZICSR_ZIFENCEI via -march is required for gcc>=12.1.0, but this only happens for binutils>=2.36, binutils 2.35 + gcc>=12.1.0 does not need that. Considering binutils 2.35 together complicates things. So what do you think of the above new version patch? Some more info: - The commit[4] for patch changes. - binutils 2.36 supports the zifencei extension[5] and splits zifencei and zicsr from I[6]. [4] commit 0715372a06ce ("riscv: compat: vdso: Add COMPAT_VDSO base code implementation") [5] https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=5a1b31e1e1cee6e9f1c92abff59cdcfff0dddf30 [6] https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=729a53530e86972d1143553a415db34e6e01d5d2 Thanks, Mingzheng. > help > - Binutils-2.38 and GCC-12.1.0 bump default ISA spec to newer version > + Binutils-2.38 and GCC-12.1.0 bump the default ISA spec to version > 20191213 which moves some instructions from the I extension to the > - Zicsr and Zifencei extensions. > + Zicsr and Zifencei extensions. On the other hand, Binutils prior to > + 2.35 does not understand these arguments and will error if they are > + passed. > > config TOOLCHAIN_NEEDS_OLD_ISA_SPEC > def_bool y > depends on TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI > # https://github.com/llvm/llvm-project/commit/22e199e6afb1263c943c0c0d4498694e15bf8a16 > # 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) > + depends on (CC_IS_CLANG && CLANG_VERSION < 170000) || (CC_IS_GCC && GCC_VERSION < 110100) > help > - Certain versions of clang (or GCC) do not support zicsr and zifencei via > + Certain versions of clang and GCC 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 (or GCC) to be passed to GAS, which has the same result as > + of clang and GCC to be passed to GAS, which has the same result as > passing zicsr and zifencei to -march. > > config FPU > > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv