From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by mx.groups.io with SMTP id smtpd.web11.9991.1663247856398522259 for ; Thu, 15 Sep 2022 06:17:36 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@ventanamicro.com header.s=google header.b=KEywxz0T; spf=pass (domain: ventanamicro.com, ip: 209.85.214.169, mailfrom: sunilvl@ventanamicro.com) Received: by mail-pl1-f169.google.com with SMTP id w13so2671650plp.1 for ; Thu, 15 Sep 2022 06:17:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=E2uyiXCD1isCaTAjz//vOfM7aWDr1tfqzBs9KlkklYk=; b=KEywxz0TMtjO1G2WAKh3ZLfzltgOSOiNZ9dY0VXPrpNc+FNe0zXlpbcqt9ubm0D6h6 ngXtEMzNEzpv3w72vJLkBrIfCeR8AUa9JTubHHJyer+uWGFYNlxK8vpPQ/nyeLJQtOHR 8Zm9M8mHzFRawfzYcOwFbNWvpN78dfLDzJtRoSxQFIlsxXRLwNbecEUHQ9t4d7gCAp0I gEbWYzmBPfDYWVwITojAxZiIMr6FJoKPTgqX2Hw36msIegkJOyoyMr8/2OKMaUZJO4ma EeGLDUqZo2V3TJVbgUQlRBiqYo/0VT2zFRldSUtKvvD5ONY53hH1MzY2lfqky7VTkiQZ 607g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=E2uyiXCD1isCaTAjz//vOfM7aWDr1tfqzBs9KlkklYk=; b=OiD/WpViVjqJVrz4ruH009qKKGBeujkgNgMdV/+mtcxYQI59FmdYxdgdEMQWX0SA3U 9xANXrHwwxHMLp53TF2FJzcjSVb+EVLG4mPyEajIbQTAHa+IOOcRVGauV3sjv/oWjcXm ZL+ccgUWQ89wiFmE1nLUDTLH6UAnKebr6p8Dr3gdzVxQcoEsLDtTRYJS2zVWuW2asMTY mbg5RWAoewZVRTt5I4++vHZ0w2aqN0nctu41W16gyRTApT7ZuGPX/lHVlJs+Cq2HvdTm wFY64wh4CQdt9vclWlf8M6aZ18VhNaVwI2L3oS1ct25TXFT0oO7JKQS2ovBzagdnqgxV wiIw== X-Gm-Message-State: ACrzQf1E4ol3+3NdOV9lsZeb+pSPrD7/X6w/kTuBCqiIj8kQhSDEdEzp tiu8k/+4Rvp/12xIOMn+8DeNiTv2sOI5NQ== X-Google-Smtp-Source: AMsMyM5WyR3aKTkPnV59S4n5m1r/c4reJ+u+E/C9NtcAovyPIIsX/5uTVVR+DSIBf8XZ++l0hvo4Fg== X-Received: by 2002:a17:90b:1e02:b0:203:21f3:f233 with SMTP id pg2-20020a17090b1e0200b0020321f3f233mr7490484pjb.189.1663247855686; Thu, 15 Sep 2022 06:17:35 -0700 (PDT) Return-Path: Received: from sunil-laptop.. ([49.206.11.215]) by smtp.gmail.com with ESMTPSA id q7-20020a17090311c700b00174f7d10a03sm13138773plh.86.2022.09.15.06.17.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 06:17:35 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Sunil V L , Bob Feng , Liming Gao , Yuwei Chen Subject: [PATCH 1/1] BaseTools: Fix RISC-V build failure with binutils 2.38+ Date: Thu, 15 Sep 2022 18:47:31 +0530 Message-Id: <20220915131731.50958-1-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Cc: Liming Gao Cc: Yuwei Chen Signed-off-by: Sunil V L --- 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