BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4061
>From version 2.38, binutils adheres to RISC-V ISA spec version 20191213. This means that the csr read/write (csrr*/csrw*) instructions and fence.i instruction are separated from the `I` extension, become two standalone extensions: Zicsr and Zifencei. As the edk2 uses those instructions, this causes the following build failure: .../RiscV64/FlushCache.iiii:16: Error: unrecognized opcode `fence.i' Hence, different -march strings are needed for different versions of the toolchain. To support both types of the toolchains, detect the capability of the toolchain while creating tools_def.txt from the template and update the tools_def.txt with a different -march string matching the toolchain capabilities. Cc: Bob Feng <bob.c.f...@intel.com> Cc: Liming Gao <gaolim...@byosoft.com.cn> Cc: Yuwei Chen <yuwei.c...@intel.com> Signed-off-by: Sunil V L <suni...@ventanamicro.com> --- BaseTools/BuildEnv | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/BaseTools/BuildEnv b/BaseTools/BuildEnv index 275f4c5901aa..08ab28107d89 100755 --- a/BaseTools/BuildEnv +++ b/BaseTools/BuildEnv @@ -213,6 +213,26 @@ AddEdkToolsToPath() { } +UpdateRiscVToolsDefFile() { + + # binutils 2.38+ needs zicsr_zifencei in -march + # To support older toolchain, run gcc with latest -march + # and check if it succeeds + ${GCC5_RISCV64_PREFIX}gcc -march=rv64imafdc_zicsr_zifencei -x c -c /dev/null \ + -o $CONF_PATH/TmpZicsrZifencei > /dev/null 2>&1 + ZicsrZifenceiNeeded=$? + + if [ $ZicsrZifenceiNeeded -eq 0 ] + then + echo "Updating $CONF_PATH/tools_def.txt" + sed -i 's/rv64imafdc/rv64imafdc_zicsr_zifencei/g' $CONF_PATH/tools_def.txt + + # Remove the temporary file + rm $CONF_PATH/TmpZicsrZifencei + fi + +} + CopySingleTemplateFile() { SRC_FILENAME=Conf/$1.template @@ -228,6 +248,15 @@ CopySingleTemplateFile() { SRC_FILENAME=$EDK_TOOLS_PATH/$SRC_FILENAME cp $SRC_FILENAME $DST_FILENAME + # Update RISC-V definitions based on toolchain capabilities + if [ "$1" = "tools_def" ] + then + if ! [ -z ${GCC5_RISCV64_PREFIX} ] + then + UpdateRiscVToolsDefFile + fi + fi + } CopyTemplateFiles() { -- 2.34.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#93831): https://edk2.groups.io/g/devel/message/93831 Mute This Topic: https://groups.io/mt/93699575/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-