Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp4768294rwo; Tue, 25 Jul 2023 10:35:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlGhbZxYJ4ngi/ZAGQIkM25Z9uF10HlR9n1KGGoJ6P4OGNGnlC1v0stozGLoIFD0ZMOydbtI X-Received: by 2002:a17:902:ced0:b0:1b8:3936:7b64 with SMTP id d16-20020a170902ced000b001b839367b64mr1762266plg.1.1690306543385; Tue, 25 Jul 2023 10:35:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690306543; cv=none; d=google.com; s=arc-20160816; b=Ttw8it9gZ811jTkeIZTn4o1HmILtkxE1qCbKyS2GzRKsJFPcRm5GCjTf9etM0TCYaw 7HQAXQjfOVvUH6LRWVpmzXSuTPqE3zCTG4L95+2eLxJ+z4PwdKtW/1UCT8cUqUGM4OoE wLdzPGOLbzG50O/aRgu388kF2sNyulGQ0PqC5+wg29VPrrpU997XGFnKPC3FVmz3RPb6 FBXoRLkZsSyBobCDa6qsJ+dZaDdcoLBqdes2XsDIuqFnbjKPuCjUozSMX6fGxH16Glsq Y9Kkk5IRsJsKyfj8z3KT3YVh0IdmRA5bcJyAo0aOQ7gnrUcwNd7dQ5JDMvVttj4i1lCv z/Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=oq2ZFsxsi1DDmy/TRJ3GsvqMXz5j2GRk+zBxhqlft00=; fh=E0EWc4AOnvizl/DK/MTmEoBA9Xgs4lVNxv7/f4kSck8=; b=hWwhGum6/9sto4MefFsj2q9wkDAVhS3xumlumYoCQizRhjf5T6jOKwyqx9AWvtkTKD 341+q2aXS1bJx4S/9wwfclvk2fr4KCLqrYkdcCOMF2bpy0g/GuX+BjhNZihDqq3tCoXF nGlAU3Vgr46oMTxEsX5950lvffCfU4aEOLHPaTJPOnEqYZYjnAguJ1kVqeu6v0mxmHnZ oEZv3OICvvE4nBMhmZ/c66edkrO7WTzBx5JS2NrCLwqv27MAshsaXLagUpoghSKS4Rsx xvHbTB2sA/IGB1ZewwuBqzI/xz8XbOqIe/j1nKAFMPXDQxMD/IoxhcGvwyi4rA4k5THl edfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ugy6AoAC; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lo5-20020a170903434500b001b67bdc438csi11282516plb.376.2023.07.25.10.35.30; Tue, 25 Jul 2023 10:35:43 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ugy6AoAC; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232067AbjGYRYC (ORCPT + 99 others); Tue, 25 Jul 2023 13:24:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231536AbjGYRXt (ORCPT ); Tue, 25 Jul 2023 13:23:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 489DF137 for ; Tue, 25 Jul 2023 10:23:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D6F2161839 for ; Tue, 25 Jul 2023 17:23:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B01B2C433C7; Tue, 25 Jul 2023 17:23:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690305827; bh=A9c+EsCAmnw3iswaBvqbsGUpM3ibnJmuEfJXVPakIrI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Ugy6AoAC5WOplFFIoUW4OI+9FRlA9fthFFMsS0tiPrLONUWMa7uxKDf8kS4vVIyq+ Fqtyk7vFFcMypv9Zh03lafjNRf/i7IcJdcr1a9SwXkVrmP0U129vFKYsxFr9hXDNda ZMfOrRMbOsiCVHm/zIJV5DCa9lZZ0mmqvAvBcyaxfvftPqu2HlbZTNl4yQMq/bnEVD 6+AWw8/a6quspwFv8Fi88DP7/jJEfVc73h/TqfqVjLlDzVCsOXV6m0JCrh421ICoV+ OLIXNdR8Q9LeuKHKvxlMb/WTjnzCSf9IgLg6g1ADI61ie51brc7y+DX8kNjUakyOd3 4c8muDb3p3ZIQ== Date: Tue, 25 Jul 2023 10:23:44 -0700 From: Nathan Chancellor To: Mingzheng Xing Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Nick Desaulniers , Tom Rix , Bin Meng , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH] riscv: Handle zicsr/zifencei issue between gcc and binutils Message-ID: <20230725172344.GA1445373@dev-arch.thelio-3990X> References: <20230725170405.251011-1-xingmingzheng@iscas.ac.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230725170405.251011-1-xingmingzheng@iscas.ac.cn> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,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 Hi Mingzheng, Thanks for the patch! On Wed, Jul 26, 2023 at 01:04:05AM +0800, Mingzheng Xing wrote: > When compiling the kernel with the toolchain composed of GCC >= 12.1.0 and > binutils < 2.38, default ISA spec used when building binutils and GCC, the > following build failure will appear because the > CONFIG_TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI is not turned on. > (i.e, gcc-12.1.0 and binutils-2.36, or gcc-12.3.0 and binutils-2.37, use > default ISA spec.) > > CC arch/riscv/kernel/vdso/vgettimeofday.o > <>/arch/riscv/include/asm/vdso/gettimeofday.h: Assembler messages: > <>/arch/riscv/include/asm/vdso/gettimeofday.h:79: Error: unrecognized opcode `csrr a5,0xc01' The gift that keeps on giving :/ > Binutils has updated the default ISA spec version, and the community has > responded well to this[1][2][3], but it appears that this is not over yet. > > We also need to consider the situation of binutils < 2.38 but > GCC >= 12.1.0, since the combination between different versions of GCC and > binutils is not unique, which is to some extent flexible. GCC release > 12.1.0 updated the default ISA spec version in GCC commit[4]. I suspect this combination is not too common because binutils 2.38 came out before GCC 12.1.0 but as you note, it is obviously possible. What toolchain has this combination in the wild, which would be helpful for documentation purposes? > 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") > > [1]: https://groups.google.com/a/groups.riscv.org/g/sw-dev/c/aE1ZeHHCYf4 > [2]: https://lore.kernel.org/all/20230308220842.1231003-1-conor@kernel.org > [3]: https://lore.kernel.org/all/20230223220546.52879-1-conor@kernel.org > [4]: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=98416dbb0a62579d4a7a4a76bab51b5b52fec2cd > > Signed-off-by: Mingzheng Xing > --- > arch/riscv/Kconfig | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > index 4c07b9189c86..b49cea30f6cc 100644 > --- a/arch/riscv/Kconfig > +++ b/arch/riscv/Kconfig > @@ -570,11 +570,15 @@ 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 > + # https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=98416dbb0a62579d4a7a4a76bab51b5b52fec2cd > + depends on CC_IS_GCC && GCC_VERSION >= 120100 || \ > + AS_IS_GNU && AS_VERSION >= 23800 GCC_VERSION will be 0 for clang, so you don't need the CC_IS_GCC check. With that change, this should be able to stay on one line: depends on GCC_VERSION >= 120100 || (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. > + Similarly, GCC release 12.1.0 has changed the default ISA spec version to > + 20191213, so the above situation requires this option to be enabled. > > config TOOLCHAIN_NEEDS_OLD_ISA_SPEC > def_bool y > -- > 2.34.1 > Cheers, Nathan