Skip to content

Commit ca09f77

Browse files
xmzzzpalmer-dabbelt
authored andcommitted
riscv: Handle zicsr/zifencei issue between gcc and binutils
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 6df2a01 ("riscv: fix build with binutils 2.38") commit e89c2e8 ("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 Reviewed-by: Conor Dooley <conor.dooley@microchip.com> Acked-by: Guo Ren <guoren@kernel.org> Cc: <stable@vger.kernel.org> Signed-off-by: Mingzheng Xing <xingmingzheng@iscas.ac.cn> Link: https://lore.kernel.org/r/20230809165648.21071-1-xingmingzheng@iscas.ac.cn Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 4b05b99 commit ca09f77

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

arch/riscv/Kconfig

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -570,24 +570,30 @@ config TOOLCHAIN_HAS_ZIHINTPAUSE
570570
config TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI
571571
def_bool y
572572
# https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=aed44286efa8ae8717a77d94b51ac3614e2ca6dc
573-
depends on AS_IS_GNU && AS_VERSION >= 23800
574-
help
575-
Newer binutils versions default to ISA spec version 20191213 which
576-
moves some instructions from the I extension to the Zicsr and Zifencei
577-
extensions.
573+
# https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=98416dbb0a62579d4a7a4a76bab51b5b52fec2cd
574+
depends on AS_IS_GNU && AS_VERSION >= 23600
575+
help
576+
Binutils-2.38 and GCC-12.1.0 bumped the default ISA spec to the newer
577+
20191213 version, which moves some instructions from the I extension to
578+
the Zicsr and Zifencei extensions. This requires explicitly specifying
579+
Zicsr and Zifencei when binutils >= 2.38 or GCC >= 12.1.0. Zicsr
580+
and Zifencei are supported in binutils from version 2.36 onwards.
581+
To make life easier, and avoid forcing toolchains that default to a
582+
newer ISA spec to version 2.2, relax the check to binutils >= 2.36.
583+
For clang < 17 or GCC < 11.1.0, for which this is not possible, this is
584+
dealt with in CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC.
578585

579586
config TOOLCHAIN_NEEDS_OLD_ISA_SPEC
580587
def_bool y
581588
depends on TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI
582589
# https://github.com/llvm/llvm-project/commit/22e199e6afb1263c943c0c0d4498694e15bf8a16
583-
depends on CC_IS_CLANG && CLANG_VERSION < 170000
584-
help
585-
Certain versions of clang do not support zicsr and zifencei via -march
586-
but newer versions of binutils require it for the reasons noted in the
587-
help text of CONFIG_TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI. This
588-
option causes an older ISA spec compatible with these older versions
589-
of clang to be passed to GAS, which has the same result as passing zicsr
590-
and zifencei to -march.
590+
# https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=b03be74bad08c382da47e048007a78fa3fb4ef49
591+
depends on (CC_IS_CLANG && CLANG_VERSION < 170000) || (CC_IS_GCC && GCC_VERSION < 110100)
592+
help
593+
Certain versions of clang and GCC do not support zicsr and zifencei via
594+
-march. This option causes an older ISA spec compatible with these older
595+
versions of clang and GCC to be passed to GAS, which has the same result
596+
as passing zicsr and zifencei to -march.
591597

592598
config FPU
593599
bool "FPU support"

arch/riscv/kernel/compat_vdso/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ compat_vdso-syms += flush_icache
1111
COMPAT_CC := $(CC)
1212
COMPAT_LD := $(LD)
1313

14-
COMPAT_CC_FLAGS := -march=rv32g -mabi=ilp32
14+
# binutils 2.35 does not support the zifencei extension, but in the ISA
15+
# spec 20191213, G stands for IMAFD_ZICSR_ZIFENCEI.
16+
ifdef CONFIG_TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI
17+
COMPAT_CC_FLAGS := -march=rv32g -mabi=ilp32
18+
else
19+
COMPAT_CC_FLAGS := -march=rv32imafd -mabi=ilp32
20+
endif
1521
COMPAT_LD_FLAGS := -melf32lriscv
1622

1723
# Disable attributes, as they're useless and break the build.

0 commit comments

Comments
 (0)