From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-002e3701.pphosted.com (mx0a-002e3701.pphosted.com [148.163.147.86]) by mx.groups.io with SMTP id smtpd.web10.4076.1623724054300192954 for ; Mon, 14 Jun 2021 19:27:34 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=UJa3gW4O; spf=permerror, err=parse error for token &{10 18 %{ir}.%{v}.%{d}.spf.has.pphosted.com}: invalid domain name (domain: hpe.com, ip: 148.163.147.86, mailfrom: prvs=0800a047eb=daniel.schaefer@hpe.com) Received: from pps.filterd (m0148663.ppops.net [127.0.0.1]) by mx0a-002e3701.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 15F2DaxT006911; Tue, 15 Jun 2021 02:27:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : mime-version; s=pps0720; bh=C/o8odzhZOMb3S95AE1rxbxIXVIquYwrUTHdgxa7mHc=; b=UJa3gW4OGQF6xa7+yAvhA647dcFEoWk3xnncEO6pgKYNaPZzBkt9pwsMt1f/SZUrLnlG Cc9M+nlVAfWzaF97NsrJ79GhsFcsqd0XHxV/4Y0htBkuJuosuYauzEDWCgpJxcRO+Iy+ ZNWjttVbzIC+yuDjGGak4nx1Jn4vjaAAtXDkTqQPyBG99CM3AedEIj8XwL+kVIFp9GTp CqAbclFB+f5KquRcTjPQTDgCXK3ZKQL8RJadBK9lMfgSIpwoOXPhqX1gXk0H9DyNmVUC 1a/OjRwEzgFQgoIYe21QV0ZJRvTiVcZlApWQZZ3FxU+SITyOm/X4J+EmqxnuhFCWb/kC JQ== Received: from g9t5008.houston.hpe.com (g9t5008.houston.hpe.com [15.241.48.72]) by mx0a-002e3701.pphosted.com with ESMTP id 39692bcmg9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 15 Jun 2021 02:27:26 +0000 Received: from G2W6311.americas.hpqcorp.net (g2w6311.austin.hp.com [16.197.64.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by g9t5008.houston.hpe.com (Postfix) with ESMTPS id BE3DA96; Tue, 15 Jun 2021 02:27:23 +0000 (UTC) Received: from G9W8672.americas.hpqcorp.net (16.220.49.31) by G2W6311.americas.hpqcorp.net (16.197.64.53) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Tue, 15 Jun 2021 02:26:56 +0000 Received: from G1W8106.americas.hpqcorp.net (16.193.72.61) by G9W8672.americas.hpqcorp.net (16.220.49.31) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Tue, 15 Jun 2021 02:26:55 +0000 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (15.241.52.13) by G1W8106.americas.hpqcorp.net (16.193.72.61) with Microsoft SMTP Server (TLS) id 15.0.1497.18 via Frontend Transport; Tue, 15 Jun 2021 02:26:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oHM/i0g3xttchLlwjvHTHfVX4pOwHvKgOEVvYkDz9R1pVLICYRpH2utIujPEt7OzRazONY23FeqUXEUr98qunBHYzuX90Xy43ww3OVXlG6xcyfSB8nzESKgGFu4t2UPNA9vPQWOJJp2gNwnonEF4gE1J1A8szSWDqLJieS7/zcpvMQVwW+wc7NamBEaZwyUwtIeJKbZrFAsKR2gZTl4Kp2a6eyTo+8Fp0wAbTSM+bPHsv859/e6DRx1NpDxSgk+BtDa4fmmHB34CHyvxFvhFU8pXTQYvmjdBsc1HTInfEVxwS/fstmEWI2lrnALxKno+oZBW9GKfB/kuXshA+CqZjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=95trCm70CYqDxJG3PiypHG+m6B6btpRDxlHre1xq40A=; b=MklguodJn5RVXbfwJeMhWAziszA8UnLATw2bnjNl1pzNUtZdIk0VHVLw/363PxYAs3ELz+ZBkeCjiTzjytAqeHuspStjPTkv1OwffzJqX055Ct0vf/BTQzcLOWZYmmY61W7AR1r1vuTcpN1iPh9irt23fPLNU8i4P6ieIX7Hlesu9me3h3EKC/BtiOqyKyNKimHgbIZqmOHxrAJZ+bsqGnV7FcMnNWFfT7TujZEiVzFdBrTw26hXpm7I4X8doKUORM5QUQ/D86szG9o3GYn2KbsqfdiO1ARa9K8Z/FKMDr2IC/GdHkpdLMFJ1kxVsOOKePS/uYD/VL/wo5lj+4FhpQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=hpe.com; dmarc=pass action=none header.from=hpe.com; dkim=pass header.d=hpe.com; arc=none Received: from DF4PR8401MB0444.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:760d::23) by DF4PR8401MB0346.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:760a::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.21; Tue, 15 Jun 2021 02:26:53 +0000 Received: from DF4PR8401MB0444.NAMPRD84.PROD.OUTLOOK.COM ([fe80::5d6b:82a:7bf3:baa]) by DF4PR8401MB0444.NAMPRD84.PROD.OUTLOOK.COM ([fe80::5d6b:82a:7bf3:baa%9]) with mapi id 15.20.4219.025; Tue, 15 Jun 2021 02:26:53 +0000 From: "Daniel Schaefer" To: Sunil V L , "devel@edk2.groups.io" CC: "Chang, Abner (HPS SW/FW Technologist)" , Bob Feng , Liming Gao , Yuwei Chen , Heinrich Schuchardt Subject: Re: [RESEND PATCH v2] BaseTools: Add support for RISCV GOT/PLT relocations Thread-Topic: [RESEND PATCH v2] BaseTools: Add support for RISCV GOT/PLT relocations Thread-Index: AQHXXstArKXQaqv/80OV9JFoChTrcqsUXGoQ Date: Tue, 15 Jun 2021 02:26:53 +0000 Message-ID: References: <20210611140503.28409-1-sunilvl@ventanamicro.com>,<20210611140807.GA28471@sunil-ThinkPad-T490> In-Reply-To: <20210611140807.GA28471@sunil-ThinkPad-T490> Accept-Language: en-US, de-DE X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: ventanamicro.com; dkim=none (message not signed) header.d=none;ventanamicro.com; dmarc=none action=none header.from=hpe.com; x-originating-ip: [123.193.59.220] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: c821b822-550e-43c7-f610-08d92fa50a56 x-ms-traffictypediagnostic: DF4PR8401MB0346: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7219; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: jtC28jSIPgYP6dmtU++fNhxPpUnRP4OzITVcvmQYh8hW2Tvwh3hOc4UaSXoMW0uwFCCnlTZzs9JBTH7qzTROyt/Ntr/TfT+wFE86j7IisJn8c5Rl2YbZ4Gl5lw4VgCUDuyMIrxCAeNSQuQgqLyVqIiHN61a01cOXY/R8SYx4ASWmtonnlBSmIJEM+kwGKAAXaUM6n0vOgmckjFobRtQI04yDsxKGXYUgLb+tjjGehOLzyujO8451nRKJovv9/cfuaJ8OxEu36fdcPBpy20fIt+U5Ztbe2iLnp1qzCgiLS6vRNQfX86UHtLpJqe7TxD6VL6lax2eFs2jD0n0tHLHmtXvOXNksTbfwSNyUsiqUT+bxAj+XJB5EQF+bCB61HiiZq9LEvfe0F9NbGe74iKkoLQHSJxNj/WeG/K20Om2cuGujvkUZlem6eyh0NzmPpfFFzNE1QaUEofNeKQY2gY9QUOc7Uht8tveDzCh434E3E8ZQJTd0HpzUnJ9K+9MPVJ9rVRFAGaJJtFlGgjfZb0otOQo2iuwmcYyHg4oL4pp7Oo+KDkhfkQIqJxTySag+srnO72z0pfYshzJ1ah+q6K+zUe0oJXLEDn8c/b19Y4kTuG57FEjqgjHIPN8TOW+Vgk40sSjrlRhEKIxIvL/hGWvmsOMtNFh2jcKwNTPWwK7xgx7hoTePbgbwpU6ouAoGaRDEqSaY50eV/JL2wF3MWsunVSKDrawZHh9oBlETNiLFWWLB6rcjTkZ6cgSRq5ZxHo8B x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DF4PR8401MB0444.NAMPRD84.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(396003)(346002)(376002)(366004)(39860400002)(136003)(83380400001)(316002)(166002)(38100700002)(54906003)(26005)(8676002)(66446008)(478600001)(66946007)(19627235002)(64756008)(66556008)(8936002)(33656002)(52536014)(66476007)(7696005)(6506007)(86362001)(9686003)(19627405001)(186003)(55016002)(71200400001)(91956017)(2906002)(966005)(53546011)(76116006)(110136005)(122000001)(4326008)(5660300002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?1OlTDx2oNhc889BFQiWZblM/7eek2jOucBhLp1hOYRfJNYz7fLaBb2u7GURx?= =?us-ascii?Q?ErsESUtHFzgqVqTmEzP4iTaQPcTM7xZTrLo+tvP6gfRmhwv81lwya8vg6XEC?= =?us-ascii?Q?CWzrVWC2IjInOfpES7rKtzrylu4DqPxbF5A7GyxIaKsmJ1t5uJZoH7pxeRrR?= =?us-ascii?Q?+MvvUZjo6SY/RUn/w/9RBk+x0xKPuewXF6YVnFVGm8dn3rYsVCXgwHVH2lkt?= =?us-ascii?Q?7JmSX2VYAFeYCleqR6z3y9oMLwwhXmO/Ed5puOExXRDJ8v/G577HLNasqCP0?= =?us-ascii?Q?fwrKurMEY/npYggz2In/zLOI1ORlrXKFRKvtA3iERQO77K4lgWfN/CxzKmPa?= =?us-ascii?Q?FZ02dzBtsB02A3JKuM4YlBX6vABcRKNG4EN6HdlKxDNDw9c27Krzx7y6WJsW?= =?us-ascii?Q?hcuwJFIEAlHYCCcH+00aEbNj+5+AqLwbKbdm6nfo22GTHy4zB0J8CV6wq1Q5?= =?us-ascii?Q?DMTZ9bs1dQ6WtutLFGGIHP9MLYB4PMfKa+hsR+x0sJDn2bNa7Zq0biNo4dWA?= =?us-ascii?Q?IF13t0plFrxDB21AvN2egl6XmsBMeudSQgPGfhYyzdS2VftrtjAym9D4S1Qu?= =?us-ascii?Q?LZdtE71ySHIBnxUQHbyP+625sANHS1O+f8bcLQGqIarBKJya8oxBbWy1EXoZ?= =?us-ascii?Q?hwCiG0gDGiDlzPQQxtjs/n+WNLOFoIWGtTM/YyxG50vPJqzdHp31bxrCKgAL?= =?us-ascii?Q?W/ZHHRms74v7IwWV3caIYZqGnwImD5zvYLSk7c5HaZqK6/hKZhA/0UVj4QTg?= =?us-ascii?Q?L8bJt8Q8QcBCRIdnIDbFY+7l7QQduOHJT/EuJcgo+VwgvjV2oa6Lx39hCLem?= =?us-ascii?Q?xyaE3/LS97lQ3oRfoQ415jUMJY2DP24FqB9/QTC6Qmc59yM0Nec3r8Rf60Vm?= =?us-ascii?Q?C+VkOzgI757+pLDrZlYiQIfqDnzyRRcBxIf/pptfWG9500OPRNp1pn6ObVgG?= =?us-ascii?Q?4n0aP684FE0dLmxZUnjChoA+V3JdQok5SWbRB8KiM0TGE18cnsopcbWG3L9p?= =?us-ascii?Q?+QLdOkvSlRObhQVC262ZGWFxmv/GmkmCnSpbol6Eitj/dMF8llyg+1UCaOEz?= =?us-ascii?Q?OeF6nDS+wYxgpPLrberDsr22m0Y8GQp0cfhT9d5x4GPPG9BFEUPWrgnJJ3Pi?= =?us-ascii?Q?5b1JcZL5oF3zXwOjGJtMgpmlQ0Qms5qdiT5CkhuMJOKc6F2XHjWJeQo8U4yB?= =?us-ascii?Q?FCRxFGtrnwSjGs4dKd8ZpgRTaExxETYAh8DVvLBzrkpZOXDZtc9xRDn1+4n7?= =?us-ascii?Q?TpmI/t79lIy4fWe9xi86Gy30Qhw3gcD9oewtofb7vat27q1Yz2c0eu9ocCv5?= =?us-ascii?Q?kjQi698WvJl+Gi5gBBP1hUZ8?= X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DF4PR8401MB0444.NAMPRD84.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: c821b822-550e-43c7-f610-08d92fa50a56 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Jun 2021 02:26:53.7667 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: ZnBHZIVKPulZQx115jMo9Jw64kwLoUogKf3q93IK/Mw4Tw76UZ8zel6T2aI2Zkrh1Qp2vOLDlX3051kJ6BN8eA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DF4PR8401MB0346 X-OriginatorOrg: hpe.com X-Proofpoint-ORIG-GUID: IPB6cV5QCv88MBngCp7Ur2n_xmqHEIM9 X-Proofpoint-GUID: IPB6cV5QCv88MBngCp7Ur2n_xmqHEIM9 X-Proofpoint-UnRewURL: 4 URL's were un-rewritten MIME-Version: 1.0 X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-06-14_14:2021-06-14,2021-06-14 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 suspectscore=0 adultscore=0 mlxlogscore=999 mlxscore=0 priorityscore=1501 clxscore=1015 spamscore=0 malwarescore=0 lowpriorityscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2106150013 Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_DF4PR8401MB04447B3FAD40F876349B7E42E0309DF4PR8401MB0444_" --_000_DF4PR8401MB04447B3FAD40F876349B7E42E0309DF4PR8401MB0444_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Great commit message, thanks Sunil! Maintainers, please take a look and let us know if there's any other concer= n. This patch lets us build the RISC-V platforms using modern toolchains that = are provided directly by the distributions, rather than building your own f= rom source. Thanks, Daniel ________________________________ From: Sunil V L Sent: Friday, June 11, 2021 22:08 To: devel@edk2.groups.io Cc: Chang, Abner (HPS SW/FW Technologist) ; Schaefer, = Daniel ; Bob Feng ; Liming G= ao ; Yuwei Chen ; Heinrich = Schuchardt Subject: Re: [RESEND PATCH v2] BaseTools: Add support for RISCV GOT/PLT rel= ocations Hi, I just edited the commit message to indicate the module and CC the maintainers. Could I get the feedback please? Thanks Sunil On Fri, Jun 11, 2021 at 07:35:03PM +0530, Sunil V L wrote: > Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3096 > > This patch adds support for R_RISCV_CALL_PLT and R_RISCV_GOT_HI20 > relocations generated by PIE enabled compiler. This also needed > changes to R_RISCV_32 and R_RISCV_64 relocations as explained in > https://github.com/riscv/riscv-gnu-toolchain/issues/905#issuecomment-8466= 82710 > > Changes in v2: > - Addressed Daniel's comment on formatting > > Testing: > 1) Debian GCC 8.3.0 and booted sifive_u and QMEU virt models. > 2) Debian 10.2.0 and booted QEMU virt model. > 3) riscv-gnu-tool chain 9.2 and booted QEMU virt model. > > Signed-off-by: Sunil V L > > Acked-by: Abner Chang > Reviewed-by: Daniel Schaefer > Tested-by: > > Cc: Bob Feng > Cc: Liming Gao > Cc: Yuwei Chen > Cc: Heinrich Schuchardt > --- > BaseTools/Source/C/GenFw/Elf64Convert.c | 44 +++++++++++++++++++++---- > 1 file changed, 38 insertions(+), 6 deletions(-) > > diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C= /GenFw/Elf64Convert.c > index d097db8632..d684318269 100644 > --- a/BaseTools/Source/C/GenFw/Elf64Convert.c > +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c > @@ -129,6 +129,8 @@ STATIC UINT32 mDebugOffset; > STATIC UINT8 *mRiscVPass1Targ =3D NULL; > STATIC Elf_Shdr *mRiscVPass1Sym =3D NULL; > STATIC Elf64_Half mRiscVPass1SymSecIndex =3D 0; > +STATIC INT32 mRiscVPass1Offset; > +STATIC INT32 mRiscVPass1GotFixup; > > // > // Initialization Function > @@ -479,11 +481,11 @@ WriteSectionRiscV64 ( > break; > > case R_RISCV_32: > - *(UINT32 *)Targ =3D (UINT32)((UINT64)(*(UINT32 *)Targ) - SymShdr->sh= _addr + mCoffSectionsOffset[Sym->st_shndx]); > + *(UINT64 *)Targ =3D Sym->st_value + Rel->r_addend; > break; > > case R_RISCV_64: > - *(UINT64 *)Targ =3D *(UINT64 *)Targ - SymShdr->sh_addr + mCoffSectio= nsOffset[Sym->st_shndx]; > + *(UINT64 *)Targ =3D Sym->st_value + Rel->r_addend; > break; > > case R_RISCV_HI20: > @@ -533,6 +535,18 @@ WriteSectionRiscV64 ( > mRiscVPass1SymSecIndex =3D 0; > break; > > + case R_RISCV_GOT_HI20: > + Value =3D (Sym->st_value - Rel->r_offset); > + mRiscVPass1Offset =3D RV_X(Value, 0, 12); > + Value =3D RV_X(Value, 12, 20); > + *(UINT32 *)Targ =3D (Value << 12) | (RV_X(*(UINT32*)Targ, 0, 12)); > + > + mRiscVPass1Targ =3D Targ; > + mRiscVPass1Sym =3D SymShdr; > + mRiscVPass1SymSecIndex =3D Sym->st_shndx; > + mRiscVPass1GotFixup =3D 1; > + break; > + > case R_RISCV_PCREL_HI20: > mRiscVPass1Targ =3D Targ; > mRiscVPass1Sym =3D SymShdr; > @@ -545,11 +559,17 @@ WriteSectionRiscV64 ( > if (mRiscVPass1Targ !=3D NULL && mRiscVPass1Sym !=3D NULL && mRiscVP= ass1SymSecIndex !=3D 0) { > int i; > Value2 =3D (UINT32)(RV_X(*(UINT32 *)mRiscVPass1Targ, 12, 20)); > - Value =3D (UINT32)(RV_X(*(UINT32 *)Targ, 20, 12)); > - if(Value & (RISCV_IMM_REACH/2)) { > - Value |=3D ~(RISCV_IMM_REACH-1); > + > + if(mRiscVPass1GotFixup) { > + Value =3D (UINT32)(mRiscVPass1Offset); > + } else { > + Value =3D (UINT32)(RV_X(*(UINT32 *)Targ, 20, 12)); > + if(Value & (RISCV_IMM_REACH/2)) { > + Value |=3D ~(RISCV_IMM_REACH-1); > + } > } > Value =3D Value - (UINT32)mRiscVPass1Sym->sh_addr + mCoffSectionsO= ffset[mRiscVPass1SymSecIndex]; > + > if(-2048 > (INT32)Value) { > i =3D (((INT32)Value * -1) / 4096); > Value2 -=3D i; > @@ -569,12 +589,21 @@ WriteSectionRiscV64 ( > } > } > > - *(UINT32 *)Targ =3D (RV_X(Value, 0, 12) << 20) | (RV_X(*(UINT32*)T= arg, 0, 20)); > + if(mRiscVPass1GotFixup) { > + *(UINT32 *)Targ =3D (RV_X((UINT32)Value, 0, 12) << 20) > + | (RV_X(*(UINT32*)Targ, 0, 20)); > + /* Convert LD instruction to ADDI */ > + *(UINT32 *)Targ =3D ((*(UINT32 *)Targ & ~0x707f) | 0x13); > + } else { > + *(UINT32 *)Targ =3D (RV_X(Value, 0, 12) << 20) | (RV_X(*(UINT32*= )Targ, 0, 20)); > + } > *(UINT32 *)mRiscVPass1Targ =3D (RV_X(Value2, 0, 20)<<12) | (RV_X(*= (UINT32 *)mRiscVPass1Targ, 0, 12)); > } > mRiscVPass1Sym =3D NULL; > mRiscVPass1Targ =3D NULL; > mRiscVPass1SymSecIndex =3D 0; > + mRiscVPass1Offset =3D 0; > + mRiscVPass1GotFixup =3D 0; > break; > > case R_RISCV_ADD64: > @@ -586,6 +615,7 @@ WriteSectionRiscV64 ( > case R_RISCV_GPREL_I: > case R_RISCV_GPREL_S: > case R_RISCV_CALL: > + case R_RISCV_CALL_PLT: > case R_RISCV_RVC_BRANCH: > case R_RISCV_RVC_JUMP: > case R_RISCV_RELAX: > @@ -1528,6 +1558,7 @@ WriteRelocations64 ( > case R_RISCV_GPREL_I: > case R_RISCV_GPREL_S: > case R_RISCV_CALL: > + case R_RISCV_CALL_PLT: > case R_RISCV_RVC_BRANCH: > case R_RISCV_RVC_JUMP: > case R_RISCV_RELAX: > @@ -1537,6 +1568,7 @@ WriteRelocations64 ( > case R_RISCV_SET16: > case R_RISCV_SET32: > case R_RISCV_PCREL_HI20: > + case R_RISCV_GOT_HI20: > case R_RISCV_PCREL_LO12_I: > break; > > -- > 2.25.1 > --_000_DF4PR8401MB04447B3FAD40F876349B7E42E0309DF4PR8401MB0444_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
Great commit message, thanks Sunil!
Maintainers, please take a look and let us know if there's any other concer= n.
This patch lets us build the RISC-V platforms using modern toolchains that = are provided directly by the distributions, rather than building your own f= rom source.

Thanks,
Daniel

From: Sunil V L <sunilvl= @ventanamicro.com>
Sent: Friday, June 11, 2021 22:08
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: Chang, Abner (HPS SW/FW Technologist) <abner.chang@hpe.com>= ;; Schaefer, Daniel <daniel.schaefer@hpe.com>; Bob Feng <bob.c.fen= g@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>; Yuwei Chen &l= t;yuwei.chen@intel.com>; Heinrich Schuchardt <xypron.glpk@gmx.de><= br> Subject: Re: [RESEND PATCH v2] BaseTools: Add support for RISCV GOT/= PLT relocations
 
Hi,
    I just edited the commit message to indicate the module = and CC the
    maintainers. Could I get the feedback please?
Thanks
Sunil

On Fri, Jun 11, 2021 at 07:35:03PM +0530, Sunil V L wrote:
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3096
>
> This patch adds support for R_RISCV_CALL_PLT and R_RISCV_GOT_HI20
> relocations generated by PIE enabled compiler. This also needed
> changes to R_RISCV_32 and R_RISCV_64 relocations as explained in
> https://github.com/riscv/riscv-gnu-toolchain/issues/90= 5#issuecomment-846682710
>
> Changes in v2:
>   - Addressed Daniel's comment on formatting
>
> Testing:
> 1) Debian GCC 8.3.0 and booted sifive_u and QMEU virt models.
> 2) Debian 10.2.0 and booted QEMU virt model.
> 3) riscv-gnu-tool chain 9.2 and booted QEMU virt model.
>
> Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
>
> Acked-by: Abner Chang <abner.chang@hpe.com>
> Reviewed-by: Daniel Schaefer <daniel.schaefer@hpe.com>
> Tested-by: <daniel.schaefer@hpe.com>
>
> Cc: Bob Feng <bob.c.feng@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Yuwei Chen <yuwei.chen@intel.com>
> Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
>  BaseTools/Source/C/GenFw/Elf64Convert.c | 44 +++++++++++++++++++= ++----
>  1 file changed, 38 insertions(+), 6 deletions(-)
>
> diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Sourc= e/C/GenFw/Elf64Convert.c
> index d097db8632..d684318269 100644
> --- a/BaseTools/Source/C/GenFw/Elf64Convert.c
> +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c
> @@ -129,6 +129,8 @@ STATIC UINT32 mDebugOffset;
>  STATIC UINT8       *mRiscVPass1Tar= g =3D NULL;
>  STATIC Elf_Shdr    *mRiscVPass1Sym =3D NULL;
>  STATIC Elf64_Half  mRiscVPass1SymSecIndex =3D 0;
> +STATIC INT32       mRiscVPass1Offset; > +STATIC INT32       mRiscVPass1GotFixup;=

>  //
>  // Initialization Function
> @@ -479,11 +481,11 @@ WriteSectionRiscV64 (
>      break;

>    case R_RISCV_32:
> -    *(UINT32 *)Targ =3D (UINT32)((UINT64)(*(UINT32 *)T= arg) - SymShdr->sh_addr + mCoffSectionsOffset[Sym->st_shndx]);
> +    *(UINT64 *)Targ =3D Sym->st_value + Rel->r_a= ddend;
>      break;

>    case R_RISCV_64:
> -    *(UINT64 *)Targ =3D *(UINT64 *)Targ - SymShdr->= sh_addr + mCoffSectionsOffset[Sym->st_shndx];
> +    *(UINT64 *)Targ =3D Sym->st_value + Rel->r_a= ddend;
>      break;

>    case R_RISCV_HI20:
> @@ -533,6 +535,18 @@ WriteSectionRiscV64 (
>      mRiscVPass1SymSecIndex =3D 0;
>      break;

> +  case R_RISCV_GOT_HI20:
> +    Value =3D (Sym->st_value - Rel->r_offset); > +    mRiscVPass1Offset =3D RV_X(Value, 0, 12);
> +    Value =3D RV_X(Value, 12, 20);
> +    *(UINT32 *)Targ =3D (Value << 12) | (RV_X(*(= UINT32*)Targ, 0, 12));
> +
> +    mRiscVPass1Targ =3D Targ;
> +    mRiscVPass1Sym =3D SymShdr;
> +    mRiscVPass1SymSecIndex =3D Sym->st_shndx;
> +    mRiscVPass1GotFixup =3D 1;
> +    break;
> +
>    case R_RISCV_PCREL_HI20:
>      mRiscVPass1Targ =3D Targ;
>      mRiscVPass1Sym =3D SymShdr;
> @@ -545,11 +559,17 @@ WriteSectionRiscV64 (
>      if (mRiscVPass1Targ !=3D NULL &&= mRiscVPass1Sym !=3D NULL && mRiscVPass1SymSecIndex !=3D 0) {
>        int i;
>        Value2 =3D (UINT32)(RV_X(*(U= INT32 *)mRiscVPass1Targ, 12, 20));
> -      Value =3D (UINT32)(RV_X(*(UINT32 *)Tar= g, 20, 12));
> -      if(Value & (RISCV_IMM_REACH/2)) {<= br> > -        Value |=3D ~(RISCV_IMM_REA= CH-1);
> +
> +      if(mRiscVPass1GotFixup) {
> +        Value =3D (UINT32)(mRiscVP= ass1Offset);
> +      } else {
> +        Value =3D (UINT32)(RV_X(*(= UINT32 *)Targ, 20, 12));
> +        if(Value & (RISCV_IMM_= REACH/2)) {
> +          Value |=3D ~(R= ISCV_IMM_REACH-1);
> +        }
>        }
>        Value =3D Value - (UINT32)mR= iscVPass1Sym->sh_addr + mCoffSectionsOffset[mRiscVPass1SymSecIndex];
> +
>        if(-2048 > (INT32)Value) = {
>          i =3D (((INT32)V= alue * -1) / 4096);
>          Value2 -=3D i; > @@ -569,12 +589,21 @@ WriteSectionRiscV64 (
>          }
>        }

> -      *(UINT32 *)Targ =3D (RV_X(Value, 0, 12= ) << 20) | (RV_X(*(UINT32*)Targ, 0, 20));
> +      if(mRiscVPass1GotFixup) {
> +        *(UINT32 *)Targ =3D (RV_X(= (UINT32)Value, 0, 12) << 20)
> +           &nb= sp;            =     | (RV_X(*(UINT32*)Targ, 0, 20));
> +        /* Convert LD instruction = to ADDI */
> +        *(UINT32 *)Targ =3D ((*(UI= NT32 *)Targ & ~0x707f) | 0x13);
> +      } else {
> +        *(UINT32 *)Targ =3D (RV_X(= Value, 0, 12) << 20) | (RV_X(*(UINT32*)Targ, 0, 20));
> +      }
>        *(UINT32 *)mRiscVPass1Targ = =3D (RV_X(Value2, 0, 20)<<12) | (RV_X(*(UINT32 *)mRiscVPass1Targ, 0, = 12));
>      }
>      mRiscVPass1Sym =3D NULL;
>      mRiscVPass1Targ =3D NULL;
>      mRiscVPass1SymSecIndex =3D 0;
> +    mRiscVPass1Offset =3D 0;
> +    mRiscVPass1GotFixup =3D 0;
>      break;

>    case R_RISCV_ADD64:
> @@ -586,6 +615,7 @@ WriteSectionRiscV64 (
>    case R_RISCV_GPREL_I:
>    case R_RISCV_GPREL_S:
>    case R_RISCV_CALL:
> +  case R_RISCV_CALL_PLT:
>    case R_RISCV_RVC_BRANCH:
>    case R_RISCV_RVC_JUMP:
>    case R_RISCV_RELAX:
> @@ -1528,6 +1558,7 @@ WriteRelocations64 (
>            = ;  case R_RISCV_GPREL_I:
>            = ;  case R_RISCV_GPREL_S:
>            = ;  case R_RISCV_CALL:
> +            ca= se R_RISCV_CALL_PLT:
>            = ;  case R_RISCV_RVC_BRANCH:
>            = ;  case R_RISCV_RVC_JUMP:
>            = ;  case R_RISCV_RELAX:
> @@ -1537,6 +1568,7 @@ WriteRelocations64 (
>            = ;  case R_RISCV_SET16:
>            = ;  case R_RISCV_SET32:
>            = ;  case R_RISCV_PCREL_HI20:
> +            ca= se R_RISCV_GOT_HI20:
>            = ;  case R_RISCV_PCREL_LO12_I:
>            = ;    break;

> --
> 2.25.1
>
--_000_DF4PR8401MB04447B3FAD40F876349B7E42E0309DF4PR8401MB0444_--