From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web11.3882.1642140711240569054 for ; Thu, 13 Jan 2022 22:11:51 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=EPqyv/Ox; spf=pass (domain: intel.com, ip: 192.55.52.88, mailfrom: bob.c.feng@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642140711; x=1673676711; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=Gtn6mVv65Xm4OK5qSdqOALUwooPzTDIUYiiC9bqBW4I=; b=EPqyv/OxryGm17oNZvReFHDCeD7M/DUf6JSmjax8hxsE5gG8pfPo+lTv 5gc5dtRZNwLeO+PSyoEpxROpkqn9caEW+ZbKaFsmSpjll23a7OqLm2JxL cmJYJL9wW5irq5KSzQQNjyOvzrgOUrZJvVH4UyVSRb5nwYmTA8v/em5yK 9MGYa9veVzrarqe4c4LubwH0u2ogbIAJV2eeKWc9+p6TYpENcqRMtXpP9 4kZHzGPGmLsHMx3jJ8S5fR/M/tkzWT7hE1T7u2pQUpA/8popWWnghue6b FhqHCfdDjdvpde0LPrNHcmPsYEtrCnU3qrOpwzXsUNUePP3C3hlQflFwD w==; X-IronPort-AV: E=McAfee;i="6200,9189,10226"; a="268552724" X-IronPort-AV: E=Sophos;i="5.88,287,1635231600"; d="scan'208";a="268552724" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2022 22:11:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,287,1635231600"; d="scan'208";a="692086706" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orsmga005.jf.intel.com with ESMTP; 13 Jan 2022 22:11:48 -0800 Received: from orsmsx609.amr.corp.intel.com (10.22.229.22) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Thu, 13 Jan 2022 22:11:48 -0800 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx609.amr.corp.intel.com (10.22.229.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20 via Frontend Transport; Thu, 13 Jan 2022 22:11:48 -0800 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.106) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.20; Thu, 13 Jan 2022 22:11:39 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=appg1OfIkR2pagHM2gVg7+21RMchZ4lhwCR9jSM5VezPx/VzLjiR3ZT4ImUs0C1JundDSd7uvhvoov4j2GnrnkDNLEego4cJx7F2Ga7MfeNqRh7fO1IOGGYhcOEgzbJTccyx2dxTPfw7/Sid17jTW4nFZh+hCf1YFqRqYHDvAr0EM9v2HqtC2hy+p+8QocQasfqzFPHXNgcg6DjflBPUhr1y24lZvM2kADLraaBgiBvzdVsDVqY6PAMochuyHf0t1yLj7EcetTNI5cuNpKEerXe4ixdMZGJeI0uPt69CFOEwsPmhvdDPwQqr5ZpnWnR6eVTYhQsW8UqCpGwOqBMW0Q== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=oKVo9PcUN7a5MTJUT8XooRBZv3ywJ9GCgJP7i5j8Z+o=; b=VVALkKeuzWWxU83PzHaWNzaEXvs8D3YILvYN6mve/GAbu3W86LkvwU6jMPFEVM2Ms2tYDnYBVN/uTV8eIHHZXralJRtKYoE4GaJi24mmFfDYHWi3tsMISlenydcwxF6fnciGcJJF5jCakW2dANQ3gkh+fWoBfvy8wjDfakW76WnoD0uYU8iSrMDWQdvzJaQQJGQK9tAHRbV28coDRIp44zBJKxzMy56UhNb5fOCPT0IeHVmBNuO7f/Fi3ik+xNma7gmIq+YyYr3tHIIq7WxkA3nXPUTomewzJhN/8X5MZvxQ0wno1ckd2b3TGuBbDzjKsYbdW/V8USDKFSJcuIjkxw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from PH7PR11MB5863.namprd11.prod.outlook.com (2603:10b6:510:135::11) by DM6PR11MB2905.namprd11.prod.outlook.com (2603:10b6:5:62::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.10; Fri, 14 Jan 2022 06:11:37 +0000 Received: from PH7PR11MB5863.namprd11.prod.outlook.com ([fe80::3593:10ef:94ba:830]) by PH7PR11MB5863.namprd11.prod.outlook.com ([fe80::3593:10ef:94ba:830%7]) with mapi id 15.20.4888.012; Fri, 14 Jan 2022 06:11:37 +0000 From: "Bob Feng" To: "Huang, Li-Xia" , "devel@edk2.groups.io" CC: "Gao, Liming" , "Chen, Christine" Subject: Re: [edk2-devel][PATCH] BaseTools/GenFw: Enhance to add export table in PE-COFF Thread-Topic: [edk2-devel][PATCH] BaseTools/GenFw: Enhance to add export table in PE-COFF Thread-Index: AQHYB4g+xlV3y0/qKkSR61iBGMxRYqxiCoYA Date: Fri, 14 Jan 2022 06:11:37 +0000 Message-ID: References: <20220112074423.5075-1-lisa.huang@intel.com> In-Reply-To: <20220112074423.5075-1-lisa.huang@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 6a65177b-4686-4afa-376c-08d9d724b929 x-ms-traffictypediagnostic: DM6PR11MB2905:EE_ x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4941; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 8ejjMPeBQVsS1Rje4EN2UIjiKe6PDbjeqq1BGB0yF3Le3tNs4XH27Rs4M0mmJTwFaNKfq7zXfkVTRQPfEN0KArYjG7GVRrD8/tOmxFUqffdQOCPPvzXTLhP0eNmVEWk+tXAUOyJxenAHYMHiavFGIhQcgufo0jwztSb/BTLVKr1tkt08zyNu3CkUxmigyOYzb1fqJ1vsuRH97eirqDzyKu/i14rMwwEZcUyZpTbzbvMPmPw3fA8zDQJCNObLxwT3b0fItB/I50PiWosD3qLFKQe2b4YpAXD9V3YEkTHcNApSPOUmkeZGUTMoBsUJD4Ac1aFdVKaD9FIgzrWCSFLm7RUk9anAgznONUsApX25uJOYTT84SZFliyhlWNC5bkJeth0oU74bwLklmdpyune3566MgdE12ykP3H34ITejh1jqP7MiHQMRBFZ/eGwqG1GObU9AatsBarkXQ2Aau9W4Mz18eY0fM3xZVMTcXvFIKNOkCBHVawxVGLIFw7saCP/I6mQ83XpivtYVuHi4wgQdafflGdyM1HmaOPrjoZ2b6/K6IhLw2UUg/PWaj5JztP5ChpSl1G+lTgm/17snNhMtqp5F2265dT5TYEP0Z05m/1TL2eEXh4UPYK2967yQ1EdTPFrrW+ZhRhJNlYkXkLo6phBLWHo8THooxVJ8Ya9DmPDJ8QTTl8cHCR2yKogooLbwYeL4Sor5FJJX/ZLmtmkG+gNY1qMxAobA9yAZfvlCT+auHnpe6navT42tVXP4dpEXlP5XVWNdRMwIOORkrVbjZFY3MWyBXytZPe5s+f/u5t8= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH7PR11MB5863.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(966005)(5660300002)(71200400001)(54906003)(316002)(508600001)(110136005)(66446008)(26005)(66946007)(66476007)(64756008)(82960400001)(66556008)(38100700002)(19627235002)(83380400001)(33656002)(107886003)(4326008)(86362001)(30864003)(52536014)(76116006)(122000001)(38070700005)(7696005)(186003)(9686003)(8936002)(8676002)(53546011)(6506007)(2906002)(55016003);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?kuHjhZY9Ui/nBwehaaIoxXgXRt+eZ/5ueNLIz5ACvy1jwB6xVBalSa5opmaf?= =?us-ascii?Q?U/Nni+ozH9Zsr6HE5DL9Waq6158AAHx/KPuOQMvZ1iW1Jv56vSKehbPJn1Zb?= =?us-ascii?Q?RNstgjxOPS30JVH57/9D08hsmEEIS15eK+LJzlPfIBlzhV/9O5mEKJcXKxYY?= =?us-ascii?Q?KNdVCo3VZ7Kf38nBLW/dFJXQx4GM/mKVX4WM/u/MSZC+RgUMxUx9j8Hiby6y?= =?us-ascii?Q?2KGLKRGdT7sLX8WlOSlJTHnvhdQkEvaTTd88dVA7Twj/ENahiZGhN7OmhFQj?= =?us-ascii?Q?MKu+3VDte/ZimYZm6Mwa2afxTh+4jnemRtczlq5sObaniFxTrOsUCDWMIiOs?= =?us-ascii?Q?Z+MPqx67ETsLa7rixA+EN1pWzeqzrwPbRUGdfHQYhzUkJ0JpP3/TNIkNBn1y?= =?us-ascii?Q?PQEbg/iTJFvi8GsMbOjS7DcYfeVvmJoN92ELVnOjrVSnABHCYzOzkFrf4t09?= =?us-ascii?Q?B6XNotzKzS5Vz4TScmjX9nBVzMpjJOxLwHvktUobicfwNxpBELiucda+HxfP?= =?us-ascii?Q?dCCk0btmLUqjMPcyGaqim2pUjfIkYdOc6oRdcLzi3t6DfdekKjK77NpaJPb0?= =?us-ascii?Q?kV+B7ZCjg+cxdC8jinzuZYftjbY87p/c4zfR1Bry9AzW1YZidr/v3FiCfSBH?= =?us-ascii?Q?y/U1F+t5QgKFkgSS4aOWuRo20j6E1ys5+DRoLGZZKvJZtPZCdVvH5kpPArtl?= =?us-ascii?Q?1bxquzy8uMHziYCP5zR+jHE/r2Ml5LughrnfcQh8GxFpkq7SMtSD1wX22I5q?= =?us-ascii?Q?LTHBiAMUgmvJWQlvdCUWsJ1ymaL7Zr69NigkBaNPAz8gBhTUeVhDSi1L7bVJ?= =?us-ascii?Q?v2VD37LCBrv7OJrDk1LuubpmlZFQhk1PELefwml352zDbWBmMGLGUUEOgbj9?= =?us-ascii?Q?BviazX3MHbKJe9P8Zdp6p8U97ZqidbZHROWzokARW85+L+rnyUvAqQhrg68C?= =?us-ascii?Q?FePjRwCZ7E2JlDCiuuP+g0enPNRZpfVidAImQNO6lNH2qXzCtHN6KEG3Txnf?= =?us-ascii?Q?LRZMJePAlUCAhFlL1bxAJz2FAsFgPfPlpDiNzm253Vld1Ml2OwEa40rzeDrh?= =?us-ascii?Q?sDXC6YuJQqY67DKlo5Pw6dzgsaraB0gMxkRmfhytieaIdJBh+dxkA6u8bpqY?= =?us-ascii?Q?MwJY5IffrpuDsiCWYLXQRjVYUeja5CiP0gpIz6rL5ZObF7OsUIxWf1tNyUWL?= =?us-ascii?Q?kDQq8lHr14MNtLGICQWLnD4gcpSNPbxkXdETI6s2MzFouL4FmmqTKIFEmWug?= =?us-ascii?Q?dcriwDbQG/m+/FSNmsHmMwXWjQlW7Jxma5Z88X2HbCsH/0WO3Vf8DCkIZsbQ?= =?us-ascii?Q?IPqstd8c3W/2ioKPuscHLl6vwA0/jyTM5iABihS+REBHSYf8OUeDAy0N75jy?= =?us-ascii?Q?LgQxyABpTZ3IzGouvHztFfQdybgMBM2Tsi0Hw54Ri3+xfBiqxepNZ4ZUCSJ9?= =?us-ascii?Q?lNAmxdnl+j3EZGP/cZEsNMY/6kvfOYZAO1PT/h3Pbxe5/yC3XfF2L4JyTtpo?= =?us-ascii?Q?2GE62EBuPttfb4fuN6MXM6kJtJAC5FS2xJdB63kocWykpi6nNYNGV8hxbgng?= =?us-ascii?Q?itdAWF8d8ERZ1RIqeIkgyqoVCM1UQkFUKjzFzBAJZ2wRkl0TwsHNHZPlcsEF?= =?us-ascii?Q?0mGF/s49dnAk7SyHmTzQYf0=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PH7PR11MB5863.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6a65177b-4686-4afa-376c-08d9d724b929 X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Jan 2022 06:11:37.3823 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: WvIEJD1jBeK1HWtcJlJi3nXBrkDawH7Dw6rrLoLNktlK1/NefZXTzVbmwWU4ohcMV9wxkGM8OptcP+OC++S4wA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB2905 Return-Path: bob.c.feng@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Lixia, This patch introduce a new command line option --PRM. Could you add the hel= p information about --PRM? Could you provide more information about the below change? Would there be s= ide-effect? @@ -750,7 +818,7 @@ ScanSections64 ( if (shdr->sh_addralign <=3D mCoffAlignment) { continue; } - if (IsTextShdr(shdr) || IsDataShdr(shdr) || IsHiiRsrcShdr(shdr)) { + if (IsTextShdr(shdr) || IsDataShdr(shdr) || IsHiiRsrcShdr(shdr) || IsS= ymbolShdr(shdr)) { mCoffAlignment =3D (UINT32)shdr->sh_addralign; } } Thanks, Bob=20 -----Original Message----- From: Huang, Li-Xia =20 Sent: Wednesday, January 12, 2022 3:44 PM To: devel@edk2.groups.io Cc: Huang, Li-Xia ; Gao, Liming ; Feng, Bob C ; Chen, Christine Subject: [edk2-devel][PATCH] BaseTools/GenFw: Enhance to add export table i= n PE-COFF REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3802 Since PRM module needs to support export table in PE-COFF, we'll enhance Ge= nFw tool to support this. Add one export flag in GenFw tool. If export flag is set: Step1: Scan ELF symbol table based on PRM module descriptor to get descript= or offset address; Step2: Find PRM handlers number and name in COFF file based on the address = from step1; Step3: Write PRM info such as handler name and export RVA into COFF export = table. Cc: Liming Gao Cc: Bob Feng Cc: Yuwei Chen Signed-off-by: Lixia Huang --- BaseTools/Source/C/GenFw/Elf64Convert.c | 254 +++++++++++++++++- BaseTools/Source/C/GenFw/ElfConvert.c | 10 + BaseTools/Source/C/GenFw/ElfConvert.h | 42 ++- BaseTools/Source/C/GenFw/GenFw.c | 11 +- .../C/Include/IndustryStandard/PeImage.h | 7 + 5 files changed, 318 insertions(+), 6 deletions(-) diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/G= enFw/Elf64Convert.c index 0bb3ead228..0079507356 100644 --- a/BaseTools/Source/C/GenFw/Elf64Convert.c +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c @@ -56,6 +56,18 @@ WriteDebug64 ( VOID ); +STATIC+VOID+ScanSymbol64 (+ VOID+ );++STATIC+VOID+WriteExpo= rt64 (+ VOID+ );+ STATIC VOID SetImageSize64 (@@ -122,7 +134,7 @@ STATIC = UINT32 mDataOffset; STATIC UINT32 mHiiRsrcOffset; STATIC UINT32 mRelocOffset; STATIC UINT32 mD= ebugOffset;-+STATIC UINT32 mExportOffset; // // Used for RISC-V relocations= . //@@ -132,6 +144,14 @@ STATIC Elf64_Half mRiscVPass1SymSecIndex =3D 0; STATIC INT32 mRiscVPass1Offset; STATIC INT32 mRiscVPass1GotFix= up; +//+// Used for Export section.+//+STATIC UINT32 mExportSize;+STAT= IC UINT32 mExportRVA[PRM_MODULE_EXPORT_SYMBOL_NUM];+STATIC UINT32 = mExportSymNum;+STATIC CHAR8 mExportSymName[PRM_MODULE_EXPORT_SYMBOL_= NUM][PRM_HANDLER_NAME_MAXIMUM_LENGTH];+ // // Initialization Function //@@ = -200,6 +220,10 @@ InitializeElf64 ( ElfFunctions->SetImageSize =3D SetImageSize64; ElfFunctions->CleanUp = =3D CleanUp64; + if (mExportFlag) {+ ElfFunctions->ScanSymbol =3D ScanS= ymbol64;+ ElfFunctions->WriteExport =3D WriteExport64;+ } return TRUE= ; } @@ -263,6 +287,17 @@ IsHiiRsrcShdr ( return (BOOLEAN) (strcmp((CHAR8*)mEhdr + Namedr->sh_offset + Shdr->sh_na= me, ELF_HII_SECTION_NAME) =3D=3D 0); } +STATIC+BOOLEAN+IsSymbolShdr (+ Elf= _Shdr *Shdr+ )+{+ Elf_Shdr *Namehdr =3D GetShdrByIndex(mEhdr->e_shstrndx)= ;++ return (BOOLEAN) (strcmp((CHAR8*)mEhdr + Namehdr->sh_offset + Shdr->sh= _name, ELF_SYMBOL_SECTION_NAME) =3D=3D 0);+}+ STATIC BOOLEAN IsDataShdr (@@= -335,6 +370,38 @@ GetSymName ( return StrtabContents + Sym->st_name; } +//+// Get Prm Handler number an= d name+//+STATIC+VOID+FindPrmHandler (+ UINT64 Offset+ )+{+ PRM_MODULE_E= XPORT_DESCRIPTOR_STRUCT_HEADER *PrmExport;+ UINT32 NameOffset;+ UINT32 = HandlerNum;+ UINT32 Index;+ UINT8 SymName[PRM_HANDLER_NAME_MAXIMUM= _LENGTH];++ PrmExport =3D (PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT_HEADER*)(mC= offFile + Offset);+ NameOffset =3D sizeof(PRM_MODULE_EXPORT_DESCRIPTOR_STR= UCT_HEADER) + sizeof(EFI_GUID);++ for (HandlerNum =3D 0; HandlerNum < PrmE= xport->NumberPrmHandlers; HandlerNum++) {+ for (Index =3D 0; Index < PRM= _HANDLER_NAME_MAXIMUM_LENGTH; Index++) {+ SymName[Index] =3D *((UINT8 = *)PrmExport + NameOffset + Index);+ if (SymName[Index] =3D=3D 0) {+ = break;+ }+ }++ strcpy(mExportSymName[mExportSymNum], (CHAR8= *)SymName);+ NameOffset +=3D PRM_HANDLER_NAME_MAXIMUM_LENGTH + sizeof(EF= I_GUID);+ mExportSymNum ++;+ }+}+ // // Find the ELF section hosting th= e GOT from an ELF Rva // of a single GOT entry. Normally, GOT is placed = in@@ -717,6 +784,7 @@ ScanSections64 ( UINT32 CoffEntry; UINT32 = SectionCount; BOOLEAN FoundSection;+ UINT32= Offset; CoffEntry =3D 0; mCoffOffset =3D 0;@= @ -750,7 +818,7 @@ ScanSections64 ( if (shdr->sh_addralign <=3D mCoffAlignment) { continue; }- = if (IsTextShdr(shdr) || IsDataShdr(shdr) || IsHiiRsrcShdr(shdr)) {+ if= (IsTextShdr(shdr) || IsDataShdr(shdr) || IsHiiRsrcShdr(shdr) || IsSymbolSh= dr(shdr)) { mCoffAlignment =3D (UINT32)shdr->sh_addralign; } }@= @ -880,6 +948,16 @@ ScanSections64 ( Warning (NULL, 0, 0, NULL, "Multiple sections in %s are merged into 1 = data section. Source level debug might not work correctly.", mInImageName);= } + //+ // The Symbol sections.+ //+ if (mExportFlag) {+ mExport= Offset =3D mCoffOffset;+ mExportSize =3D sizeof(EFI_IMAGE_EXPORT_DIRECTO= RY) + strlen(mInImageName) + 1;+ mCoffOffset +=3D mExportSize;+ mCoff= Offset =3D CoffAlign(mCoffOffset);+ }+ // // The HII resource section= s. //@@ -962,7 +1040,11 @@ ScanSections64 ( | EFI_IMAGE_FILE_LARGE_ADDRESS_AWARE; NtHdr->Pe32Plus.OptionalHeade= r.SizeOfCode =3D mDataOffset - mTextOffset;- NtHdr->Pe32Plus.OptionalHeade= r.SizeOfInitializedData =3D mRelocOffset - mDataOffset;+ if(mExportFlag) {= + NtHdr->Pe32Plus.OptionalHeader.SizeOfInitializedData =3D mRelocOffset = - mExportOffset;+ } else {+ NtHdr->Pe32Plus.OptionalHeader.SizeOfInitia= lizedData =3D mRelocOffset - mDataOffset;+ } NtHdr->Pe32Plus.OptionalHea= der.SizeOfUninitializedData =3D 0; NtHdr->Pe32Plus.OptionalHeader.Address= OfEntryPoint =3D CoffEntry; @@ -989,8 +1071,17 @@ ScanSections64 ( NtHdr->Pe32Plus.FileHeader.NumberOfSections--; } + //+ // If found= symbol, add edata section between data and rsrc section+ //+ if(mExportF= lag) {+ Offset =3D mExportOffset;+ } else {+ Offset =3D mHiiRsrcOffs= et;+ }+ if ((mHiiRsrcOffset - mDataOffset) > 0) {- CreateSectionHeade= r (".data", mDataOffset, mHiiRsrcOffset - mDataOffset,+ CreateSectionHea= der (".data", mDataOffset, Offset - mDataOffset, EFI_IMAGE_SCN_= CNT_INITIALIZED_DATA | EFI_IMAGE_SCN_MEM_WRITE | EF= I_IMAGE_SCN_MEM_READ);@@ -999,6 +1090,20 @@ ScanSections64 ( NtHdr->Pe32Plus.FileHeader.NumberOfSections--; } + if(mExportFlag) = {+ if ((mHiiRsrcOffset - mExportOffset) > 0) {+ CreateSectionHeader= (".edata", mExportOffset, mHiiRsrcOffset - mExportOffset,+ EF= I_IMAGE_SCN_CNT_INITIALIZED_DATA+ | EFI_IMAGE_SCN_MEM_READ);+ = NtHdr->Pe32Plus.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY= _EXPORT].Size =3D mHiiRsrcOffset - mExportOffset;+ NtHdr->Pe32Plus.Opt= ionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress = =3D mExportOffset;+ NtHdr->Pe32Plus.FileHeader.NumberOfSections++;+ = } else {+ // Don't make a section of size 0.+ NtHdr->Pe32Plus.Fi= leHeader.NumberOfSections--;+ }+ }+ if ((mRelocOffset - mHiiRsrcOffse= t) > 0) { CreateSectionHeader (".rsrc", mHiiRsrcOffset, mRelocOffset - = mHiiRsrcOffset, EFI_IMAGE_SCN_CNT_INITIALIZED_DATA@@ -1757,4 +1= 862,145 @@ CleanUp64 ( } } +STATIC+VOID+ScanSymbol64 (+ VOID+ )+{+ UINT32 shIndex;+ UI= NT32 SymIndex;+ Elf_Sym *Sym;+ UINT64 SymNum;+ const UINT8= *SymName;++ for (shIndex =3D 0; shIndex < mEhdr->e_shnum; shIndex++) {+ = //+ // Determine if this is a symbol section.+ //+ Elf_Shdr *shd= r =3D GetShdrByIndex(shIndex);+ if (!IsSymbolShdr(shdr)) {+ continu= e;+ }++ UINT8 *Symtab =3D (UINT8*)mEhdr + shdr->sh_offset;+ Sym= Num =3D (shdr->sh_size) / (shdr->sh_entsize);++ //+ // First Get PrmM= oduleExportDescriptor+ //+ for (SymIndex =3D 0; SymIndex < SymNum; Sy= mIndex++) {+ Sym =3D (Elf_Sym *)(Symtab + SymIndex * shdr->sh_entsize)= ;+ SymName =3D GetSymName(Sym);+ if (SymName =3D=3D NULL) {+ = continue;+ }++ if (strcmp((CHAR8*)SymName, PRM_MODULE_EXPORT= _DESCRIPTOR_NAME) =3D=3D 0) {+ //+ // Find PrmHandler Number = and Name+ //+ FindPrmHandler(Sym->st_value);++ strcpy(= mExportSymName[mExportSymNum], (CHAR8*)SymName);+ mExportRVA[mExport= SymNum] =3D (UINT32)(Sym->st_value);+ mExportSize +=3D 2 * EFI_IMAGE= _EXPORT_ADDR_SIZE + EFI_IMAGE_EXPORT_ORDINAL_SIZE + strlen((CHAR8 *)SymName= ) + 1;+ mExportSymNum ++;+ break;+ }+ }++ //+ /= / Second Get PrmHandler+ //+ for (SymIndex =3D 0; SymIndex < SymNum; = SymIndex++) {+ UINT32 ExpIndex;+ Sym =3D (Elf_Sym *)(Symtab + S= ymIndex * shdr->sh_entsize);+ SymName =3D GetSymName(Sym);+ if (S= ymName =3D=3D NULL) {+ continue;+ }++ for (ExpIndex =3D = 0; ExpIndex < (mExportSymNum -1); ExpIndex++) {+ if (strcmp((CHAR8*)= SymName, mExportSymName[ExpIndex]) !=3D 0) {+ continue;+ }+= mExportRVA[ExpIndex] =3D (UINT32)(Sym->st_value);+ mExportSi= ze +=3D 2 * EFI_IMAGE_EXPORT_ADDR_SIZE + EFI_IMAGE_EXPORT_ORDINAL_SIZE + st= rlen((CHAR8 *)SymName) + 1;+ }+ }++ break;+ }+}++STATIC+VOID+Wr= iteExport64 (+ VOID+ )+{+ EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr;+ = EFI_IMAGE_EXPORT_DIRECTORY *ExportDir;+ EFI_IMAGE_DATA_DIRECTORY = *DataDir;+ UINT32 FileNameOffset;+= UINT32 FuncOffset;+ UINT16 = Index;+ UINT8 *Tdata =3D NULL;+= + ExportDir =3D (EFI_IMAGE_EXPORT_DIRECTORY*)(mCoffFile + mExportOffset);+= ExportDir->Characteristics =3D 0;+ ExportDir->TimeDateStamp =3D 0;+ Exp= ortDir->MajorVersion =3D 0;+ ExportDir->MinorVersion =3D0;+ ExportDir->Na= me =3D 0;+ ExportDir->NumberOfFunctions =3D mExportSymNum;+ ExportDir->Nu= mberOfNames =3D mExportSymNum;+ ExportDir->Base =3D EFI_IMAGE_EXPORT_ORDIN= AL_BASE;+ ExportDir->AddressOfFunctions =3D mExportOffset + sizeof(EFI_IMA= GE_EXPORT_DIRECTORY);+ ExportDir->AddressOfNames =3D ExportDir->AddressOfF= unctions + EFI_IMAGE_EXPORT_ADDR_SIZE * mExportSymNum;+ ExportDir->Address= OfNameOrdinals =3D ExportDir->AddressOfNames + EFI_IMAGE_EXPORT_ADDR_SIZE *= mExportSymNum;++ FileNameOffset =3D ExportDir->AddressOfNameOrdinals + EF= I_IMAGE_EXPORT_ORDINAL_SIZE * mExportSymNum;+ FuncOffset =3D FileNameOffse= t + strlen(mInImageName) + 1;++ // Write Input image Name RVA+ Tdata =3D = mCoffFile + 12;+ *(UINT32 *)Tdata =3D FileNameOffset;++ // Write Input im= age Name+ strcpy((char *)(mCoffFile + FileNameOffset), mInImageName);++ f= or (Index =3D 0; Index < mExportSymNum; Index++) {+ //+ // Write Expo= rt Address Table+ //+ Tdata =3D mCoffFile + ExportDir->AddressOfFunct= ions + Index * EFI_IMAGE_EXPORT_ADDR_SIZE;+ *(UINT32 *)Tdata =3D mExport= RVA[Index];++ //+ // Write Export Name Pointer Table+ //+ Tdata= =3D mCoffFile + ExportDir->AddressOfNames + Index * EFI_IMAGE_EXPORT_ADDR_= SIZE;+ *(UINT32 *)Tdata =3D FuncOffset;++ //+ // Write Export Ordi= nal table+ //+ Tdata =3D mCoffFile + ExportDir->AddressOfNameOrdinals= + Index * EFI_IMAGE_EXPORT_ORDINAL_SIZE;+ *(UINT16 *)Tdata =3D Index;++= //+ // Write Export Name Table+ //+ strcpy((char *)(mCoffFile = + FuncOffset), mExportSymName[Index]);+ FuncOffset +=3D strlen(mExportSy= mName[Index]) + 1;+ }++ NtHdr =3D (EFI_IMAGE_OPTIONAL_HEADER_UNION *)(mCo= ffFile + mNtHdrOffset);+ DataDir =3D &NtHdr->Pe32Plus.OptionalHeader.DataD= irectory[EFI_IMAGE_DIRECTORY_ENTRY_EXPORT];+ DataDir->VirtualAddress =3D m= ExportOffset;+ DataDir->Size =3D mExportSize;++} diff --git a/BaseTools/So= urce/C/GenFw/ElfConvert.c b/BaseTools/Source/C/GenFw/ElfConvert.c index 7db8721167..795cdbd743 100644 --- a/BaseTools/Source/C/GenFw/ElfConvert.c +++ b/BaseTools/Source/C/GenFw/ElfConvert.c @@ -223,6 +223,16 @@ ConvertElf ( VerboseMsg ("Write debug info."); ElfFunctions.WriteDebug (); + //+ = // For PRM Driver to Write export info.+ //+ if (mExportFlag) {+ Verbo= seMsg ("Scan symbol info.");+ ElfFunctions.ScanSymbol ();+ VerboseMsg= ("Write export info.");+ ElfFunctions.WriteExport ();+ }+ // // Ma= ke sure image size is correct before returning the new image. //diff --gi= t a/BaseTools/Source/C/GenFw/ElfConvert.h b/BaseTools/Source/C/GenFw/ElfCon= vert.h index 801e8de4a2..7920765fbb 100644 --- a/BaseTools/Source/C/GenFw/ElfConvert.h +++ b/BaseTools/Source/C/GenFw/ElfConvert.h @@ -24,6 +24,7 @@ extern UINT8 *mCoffFile; extern UINT32 mTableOffset; ex= tern UINT32 mOutImageType; extern UINT32 mFileBufferSize;+extern BOOLEAN mE= xportFlag; // // Common EFI specific data.@@ -31,6 +32,42 @@ extern UINT32= mFileBufferSize; #define ELF_HII_SECTION_NAME ".hii" #define ELF_STRTAB_SECTION_NAME ".strt= ab" #define MAX_COFF_ALIGNMENT 0x10000+#define ELF_SYMBOL_SECTION_NAME ".sy= mtab"++//+// Platform Runtime Mechanism (PRM) specific data.+//+#define PRM= _MODULE_EXPORT_SYMBOL_NUM 10+#define PRM_HANDLER_NAME_MAXIMUM_LENGTH 128++#= define PRM_MODULE_EXPORT_DESCRIPTOR_NAME "PrmModuleExportDescriptor= "+#define PRM_MODULE_EXPORT_DESCRIPTOR_SIGNATURE SIGNATURE_64 ('P', 'R',= 'M', '_', 'M', 'E', 'D', 'T')+#define PRM_MODULE_EXPORT_REVISION = 0x0++//+// Platform Runtime Mechanism (PRM) Export Descriptor Structu= res+//+#pragma pack(push, 1)++typedef struct {+ EFI_GUID = PrmHandlerGuid;+ CHAR8 PrmHand= lerName[PRM_HANDLER_NAME_MAXIMUM_LENGTH];+} PRM_HANDLER_EXPORT_DESCRIPTOR_S= TRUCT;++typedef struct {+ UINT64 Signature;= + UINT16 Revision;+ UINT16 = NumberPrmHandlers;+ EFI_GUID = PlatformGuid;+ EFI_GUID ModuleGuid;+} PRM_MOD= ULE_EXPORT_DESCRIPTOR_STRUCT_HEADER;++typedef struct {+ PRM_MODULE_EXPORT_= DESCRIPTOR_STRUCT_HEADER Header;+ PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT = PrmHandlerExportDescriptors[1];+} PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT;= ++#pragma pack(pop) // // Filter Types@@ -38,7 +75,8 @@ extern UINT32 mFil= eBufferSize; typedef enum { SECTION_TEXT, SECTION_HII,- SECTION_DATA+ SECTION_DAT= A,+ SECTION_SYMBOL } SECTION_FILTER_TYPES; @@ -50,6 +88,8 @@ typedef stru= ct { BOOLEAN (*WriteSections) (SECTION_FILTER_TYPES FilterType); VOID (= *WriteRelocations) (); VOID (*WriteDebug) ();+ VOID (*ScanSymbol) = ();+ VOID (*WriteExport) (); VOID (*SetImageSize) (); VOID (*= CleanUp) (); diff --git a/BaseTools/Source/C/GenFw/GenFw.c b/BaseTools/Sour= ce/C/GenFw/GenFw.c index 8cab70ba4d..c7de5b89d8 100644 --- a/BaseTools/Source/C/GenFw/GenFw.c +++ b/BaseTools/Source/C/GenFw/GenFw.c @@ -87,7 +87,7 @@ UINT32 mImageTimeStamp =3D 0; UINT32 mImageSize =3D 0; UINT32 mOutImageType =3D FW_DUMMY_IMAGE; BOOLEAN = mIsConvertXip =3D FALSE;-+BOOLEAN mExportFlag =3D FALSE; STATIC EFI_STATUS= @@ -1436,6 +1436,15 @@ Returns: continue; } + if (stricmp (argv[0], "--PRM") =3D=3D 0) {+ = if (!mExportFlag) {+ mExportFlag =3D TRUE;+ }+ argc --;+= argv ++;+ continue;+ }+ if (argv[0][0] =3D=3D '-') { = Error (NULL, 0, 1000, "Unknown option", argv[0]); goto Finish;diff = --git a/BaseTools/Source/C/Include/IndustryStandard/PeImage.h b/BaseTools/S= ource/C/Include/IndustryStandard/PeImage.h index f17b8ee19b..21c968e650 100644 --- a/BaseTools/Source/C/Include/IndustryStandard/PeImage.h +++ b/BaseTools/Source/C/Include/IndustryStandard/PeImage.h @@ -571,6 +571,13 @@ typedef struct { UINT32 AddressOfNameOrdinals; } EFI_IMAGE_EXPORT_DIRECTORY; +//+// Base= d export types.+//+#define EFI_IMAGE_EXPORT_ORDINAL_BASE 1+#define EFI_= IMAGE_EXPORT_ADDR_SIZE 4+#define EFI_IMAGE_EXPORT_ORDINAL_SIZE 2= + /// /// DLL support. /// Import Format--=20 2.26.2.windows.1