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.web10.4160.1647301591844621315 for ; Mon, 14 Mar 2022 16:46:32 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=G6lYv1XA; 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=1647301591; x=1678837591; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=dJNbyLe6X5ZLvhyS2t2SlaWNme4n4uXk9k3bA8eeutE=; b=G6lYv1XAsTotD06FHL3xPUSpfGyItLdieC28ncKODcJhtol9lEBvrnju PuANGyFsWfvYJUqC634ny5va0Zej6fW8fD0zDfbXDfOIs0hTUqWHi79G0 8HVFmhWXQbtJrvyWelwYO6kkL2VUYdhqAK9CVO7da4stvQDJo3AllM4uM JLdd6cilicoMl4T53R+knv4Oul56z07Tib/1iAhYxWQPDCHDyujQHhARu dHieI/pKdlqJzlUSXDgWtywlGYPrsuyRMVCE/mdNTyF81Ukc5ObWNzV/2 uIEM5H5eASD5hrd/fgcKcArD7IuixO/WyY5EyU1R2GiUfAbmCkoFUL+nL g==; X-IronPort-AV: E=McAfee;i="6200,9189,10286"; a="280939100" X-IronPort-AV: E=Sophos;i="5.90,181,1643702400"; d="scan'208";a="280939100" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Mar 2022 16:46:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,181,1643702400"; d="scan'208";a="556670985" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga008.jf.intel.com with ESMTP; 14 Mar 2022 16:46:30 -0700 Received: from fmsmsx601.amr.corp.intel.com (10.18.126.81) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Mon, 14 Mar 2022 16:46:30 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21 via Frontend Transport; Mon, 14 Mar 2022 16:46:30 -0700 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.103) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.21; Mon, 14 Mar 2022 16:46:30 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Add/mjjyLOSncvtkhbkP6lfg7Qm42jsTFNqOAEsXraYp0kSiICWLHDpSjAs+IGHJKBn7EEXy4pzkNU1QRV50t2PjNWhwR6urt6a2WQOY0tK8yJcoGLgYoPOQmUDYZuyOK7pScxCNye5YGKzG9PUmsCwbyxskbNCbOAkp13pGt4B2TJxIrFKw+fR/3kwyX7Ly4NVJmPUktN90y/jCi/pgg3UQBOszEdijhcGvUxPaZsJC0mimn/6u1kIRd0lWNVStEN2dNw33//DzVGyZzuiDZyRrqQVkpL4KHCfrp6o69O1dmBMAVSru/jOsp3Onk6xKv/rD45lkeFVaT1QsaIITeg== 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=n7ZwcwjqDuIx8PXvx+q8x6DD/rcoYVbspPjAvkoznbw=; b=KCfk7YnqTXQ8eLO0PcPryRlq+HJ73RSO9ijFxXqefc6jR8THZ8duRc1aknI1RrosHU0F5sZGqd6qg6u8zgwBkztt4zDJHthPcPCRBDoNu0QR7FARgbn4LGH09s8ErmtLvRcMjTuDDUwCaC2Xd+MWRFj6d14tYb5ACH5z5Nl7le1CU78PbriZfTdFLSy7E+nqOHSCVEPNA2YGfnJAl0gVgleUYTVz/L5mci5MXfmzUwdQByu++ycjHnqXfRNXT1e4ILgz6gNsrQz504ibbyFZcNyC2yU719CTx1SKMGb9A540R8JyZ3JoKwjdN3Rv2XzUL1ODA+WeDvGMZKttIlZ8gg== 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 BN0PR11MB5711.namprd11.prod.outlook.com (2603:10b6:408:14b::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Mon, 14 Mar 2022 23:46:27 +0000 Received: from PH7PR11MB5863.namprd11.prod.outlook.com ([fe80::e5:8ef1:3d8:874]) by PH7PR11MB5863.namprd11.prod.outlook.com ([fe80::e5:8ef1:3d8:874%9]) with mapi id 15.20.5061.026; Mon, 14 Mar 2022 23:46:27 +0000 From: "Bob Feng" To: "devel@edk2.groups.io" , "Feng, Bob C" , "Huang, Li-Xia" CC: "Gao, Liming" , "Chen, Christine" Subject: Re: [edk2-devel] [PATCH v2] BaseTools/GenFw: Enhance GenFw to support PRM GCC build Thread-Topic: [edk2-devel] [PATCH v2] BaseTools/GenFw: Enhance GenFw to support PRM GCC build Thread-Index: AQHYN2RP/ZFm76jfQkuSQ5Yi7Q304ay+bv3QgAEdlfA= Date: Mon, 14 Mar 2022 23:46:26 +0000 Message-ID: References: <20220314052721.3755-1-lisa.huang@intel.com> <16DC2C4DB8F2565E.23528@groups.io> In-Reply-To: <16DC2C4DB8F2565E.23528@groups.io> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-version: 11.6.401.20 dlp-product: dlpe-windows dlp-reaction: no-action 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: b64e914f-7bd2-4755-2d2b-08da0614db48 x-ms-traffictypediagnostic: BN0PR11MB5711:EE_ x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: qXZ7zOkABe5EPc09r6FCUdkJQRLmJI6gNj97gEsvNO6fc3E58OyHJOMQyCXNMI9AZ0VRB/wS/PudTPk7RAzuuHVO589KLtu88uDFdWbPjTs/a8S5gHkdhUZ65HQtkMX/BehyYsF1vD6tZ7/r1/catJtW6bC12XspeEeGcQZQ7CAMuEH8VLtE2PBkPl27O0mCnBgrx85sj5vXWrasbQL9mvlsHwgIPcT6IQxqb4zrVCzGzaMw1Tv4oCLIF4btVpFDsOc2ZgKtflguzYOhT+z6kyBHLRdttDrQWZi4/wV6rlu7eswcpsQotVNCwM+juxe8QSWIJXAC0JYCa63c3W8smwZHJbTWEPZDE9WSJiz0Z9Ibk+9m3DU34PmDot6a0HrlT+Y4WBIhdZsBusrR8QEsYUR/BPCmmyMvm4o6RJhsL8BX9lcurvdMYxIXZobWBeCdCPBcVmmRWMGyMa5MiqLkfCCCDMoZMsohQEjhr6XTOpe3+TPY2zJVxrlyiyeARa5r97jdtROWn3ZlUXhJd6UFOJrezbhpxbDldpJHTeiHsyjC/gPBLlZBiJ05++XjHjfhqrEJM6C3uYgpr7w8zfFphOa/b0EYgIIbSt4MgluNyMh2BcUa2b7ciQ8Xc1rkHbI6WfMbeBMOCwGliI2spNQR4nwuS1a7EnDh8FNWg1h5LJuvusgSd57TBzuU1gp6RMGWkURNmV2EzyUa7i79o90omwM72UTZUBbOZyCmzFXL18bQjTjXNnDl0wuPCrHKHzB1fih8r7DibmMsGAwnCFBrCnK2zrWA8h5YHoxw6iRoMnSjGBwDMZjpC1fHDKJRKAuJyIjrpQThxRl9XJbLsJR/BadzsvlLowCI/vDE3qNZfVHJy3ZQRFGU5fl86cnHUMJd 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:(13230001)(366004)(55016003)(966005)(508600001)(4326008)(8936002)(38070700005)(76116006)(8676002)(26005)(52536014)(66946007)(86362001)(66556008)(5660300002)(66446008)(30864003)(66476007)(64756008)(71200400001)(6636002)(19627235002)(122000001)(110136005)(186003)(82960400001)(53546011)(9686003)(7696005)(6506007)(83380400001)(107886003)(38100700002)(316002)(2906002)(33656002)(54906003);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?iEkRriPkJVolUsO2jE4kyz9mnYfvBcbAG9Jd62tRPwswhq98VH+w0E1QYX7y?= =?us-ascii?Q?VFpohvs5UuZ6jAXo8A5YhJsRoLWY6jsDOwroC4mfST/RC2rLcSw5SZk+KOfi?= =?us-ascii?Q?BD+ggGIJ0EXFU+bQYXpMURlwA0gGz8vrt+/M4dMuCkQFC7WQavBsYJmXkACt?= =?us-ascii?Q?CXXWhTNS7D7WrotdH8AqckaJIn+OrHwRbub2Rh7eISfwP7x8lz2dvlKgfF0X?= =?us-ascii?Q?ZVtdW3QSoJy54/LqKwIPNcOcF67lHLVyhY454rGp+Y4SL2Pl8t9OtwI2wCQ4?= =?us-ascii?Q?zyzL7chQ+xXX5Gw0/s3Wq45AFipeOe8Qyk6OZ2aOciufzfVUfFIe7lhhdVoN?= =?us-ascii?Q?HZhxxDJy6pjTIqF1KNSdZUTtuy0JRZsuyflF/vqOUw+dEWG+e5LOU1sD591H?= =?us-ascii?Q?dH9yAlGSWDFf/wyak4urnMlBJX2Iz+GkRgUDHC+Y8c/nBAJ1+LhXP7yi7jyQ?= =?us-ascii?Q?j7glc9pOEexaQC57hnPU/HtkmgdXFY9W+00ztV3eJCISlBwnAvUupgOy07id?= =?us-ascii?Q?FQduwbkPc5HBYgNlcMSnL3cw3Csqu5ey+lqyeTYvkuRVrd0fZ9rXQwKT+kll?= =?us-ascii?Q?CvklLRjl5VMcfRln6AvpofRsNq6KKzNgswzcKclm3fyD147eHC+wFDc1az+m?= =?us-ascii?Q?uXT5oWVbw2jNWsPNAuYaOxSrhzKbgkQAL04QU2f/R9sFlYrbfxJDCM+b6MOY?= =?us-ascii?Q?fVhdhy7Sjz9IDHM9W0yM3qyphgG2HZdbDJyYU3bhVj0PZyvguJMRli8M8O2r?= =?us-ascii?Q?dgFyTK6Poh4/xm3G3GgCKwscLf1DIg+HvU1rUomLPPwGgUAkL970wF3YKxFM?= =?us-ascii?Q?l17D7CgSvGLoToIgYhxhBzUyjpI7G7itQFw6Usd995EEDwGN+CaKnbJqT+Bx?= =?us-ascii?Q?+e7cVRUvewIYXP3u4c+PZTncdeam+zDAyNkSUMszfjpdxKpZai9U15309R3i?= =?us-ascii?Q?IVGhXFWpfWbWb11H6vxfUvuh6jWP3ujnITAWH8le1aAl57WK5dV94D+7YLyS?= =?us-ascii?Q?xgIKQfZONd0pvlXEMBmEQ49tJTwrpqBWcyiXRl8gJPxFTEc7GPDPndHeqY7x?= =?us-ascii?Q?DsT7EjTrlHP7cN4R0PY+Y+GI0IKa1Xsw2kEmxozEzlbAwxa8k3+l6KzvOByW?= =?us-ascii?Q?YkNVebZrBcogBxjh47utnsIv+KZ+gaRhfXfVMp5gdjW9kXShNLfhEm+YcdXX?= =?us-ascii?Q?+0KjR8pdqTvYwIr9GcyiQj2wdYn8pFuXzJFImN9y4eMLVkW/c0ixIqCdWTPA?= =?us-ascii?Q?ViD2twsiiyanZwYM0cqkF2pksf/v3hWWDf6TjfflAbRxbRRKUE6UYOisr2Fm?= =?us-ascii?Q?NHj3ormOUnTqeIy56CdBPbdZ1vHgz5t5H69t1zp5qESB1mN065KfXBjuIJZc?= =?us-ascii?Q?aSUWztaQMXm+P6HAE9AvruSaF40NELomNOODkWDsqw85xJmBRhFnu8qPftrO?= =?us-ascii?Q?KdJBznvqnSzEiXlv72i8pHSmBpVhlEzH/DiylY1XvlsvV6FJGxiD1EcJrunN?= =?us-ascii?Q?Ptxpp1GsedGHes9QUjFUsOVDQr0LpJKacMvQDOlbS9xNQs/ulI3FIivnsRDC?= =?us-ascii?Q?Zrsz+O57qKC/IysSfNCg5HMZP2kNfDpzsxlc+QeL2ocIdr15ghN+gzx2qt6B?= =?us-ascii?Q?73WrDWVjQD3S+T3mzTiBeLU=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: b64e914f-7bd2-4755-2d2b-08da0614db48 X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Mar 2022 23:46:27.0013 (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: XoFyF7vjFIh/eAr7hrQtL3yERul0NtSLsFZAOI5OzL7uEMCxGHtsRH2NPg2X4jC54KtnJy/w950Mi3SJ4CVCYw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR11MB5711 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 Created a PR: https://github.com/tianocore/edk2/pull/2622 -----Original Message----- From: devel@edk2.groups.io On Behalf Of Bob Feng Sent: Monday, March 14, 2022 2:45 PM To: Huang, Li-Xia ; devel@edk2.groups.io Cc: Gao, Liming ; Chen, Christine Subject: Re: [edk2-devel] [PATCH v2] BaseTools/GenFw: Enhance GenFw to supp= ort PRM GCC build This patch looks good to me. Reviewed-by: Bob Feng -----Original Message----- From: Huang, Li-Xia =20 Sent: Monday, March 14, 2022 1:27 PM To: devel@edk2.groups.io Cc: Huang, Li-Xia ; Gao, Liming ; Feng, Bob C ; Chen, Christine Subject: [edk2-devel] [PATCH v2] BaseTools/GenFw: Enhance GenFw to support = PRM GCC build 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. PRM option currently only supports DXE RUNTIME driver and X64 arch. Cc: Liming Gao Cc: Bob Feng Cc: Yuwei Chen Signed-off-by: Lixia Huang --- BaseTools/Source/C/GenFw/Elf64Convert.c | 242 +++++++++++++++++- BaseTools/Source/C/GenFw/ElfConvert.c | 8 + BaseTools/Source/C/GenFw/ElfConvert.h | 43 +++- BaseTools/Source/C/GenFw/GenFw.c | 20 +- .../C/Include/IndustryStandard/PeImage.h | 7 + 5 files changed, 315 insertions(+), 5 deletions(-) diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/G= enFw/Elf64Convert.c index 0bb3ead228..2aa9bfcc94 100644 --- a/BaseTools/Source/C/GenFw/Elf64Convert.c +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c @@ -56,6 +56,12 @@ WriteDebug64 ( VOID ); +STATIC+VOID+WriteExport64 (+ VOID+ );+ STATIC VOID SetImage= Size64 (@@ -106,7 +112,7 @@ STATIC UINT32 mCoffAlignment =3D 0x20; // // PE section alignment. //-STATIC const UINT16 mCoffNbrSections =3D 4;= +STATIC UINT16 mCoffNbrSections =3D 4; // // ELF sections to offset in Cof= f file.@@ -122,7 +128,7 @@ STATIC UINT32 mDataOffset; STATIC UINT32 mHiiRs= rcOffset; STATIC UINT32 mRelocOffset; STATIC UINT32 mDebugOffset;-+STATIC U= INT32 mExportOffset; // // Used for RISC-V relocations. //@@ -132,6 +138,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 //@@ = -171,6 +185,13 @@ InitializeElf64 ( return FALSE; } + if (mExportFlag) {+ if (mEhdr->e_machine !=3D = EM_X86_64) {+ Error (NULL, 0, 3000, "Unsupported", "--prm option curre= ntly only supports X64 arch.");+ return FALSE;+ }+ }+ // // Up= date section header pointers //@@ -200,6 +221,11 @@ InitializeElf64 ( ElfFunctions->SetImageSize =3D SetImageSize64; ElfFunctions->CleanUp = =3D CleanUp64; + if (mExportFlag) {+ mCoffNbrSections ++;+ ElfFuncti= ons->WriteExport =3D WriteExport64;+ }+ return TRUE; } @@ -263,6 +289,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 +372,37 @@ 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;+ PRM_HANDLER_EXPORT_DESCRIPTOR_= STRUCT *PrmHandler;+ UINT32 HandlerNum;++ PrmExport =3D (PRM_MODU= LE_EXPORT_DESCRIPTOR_STRUCT_HEADER*)((UINT8*)mEhdr + Offset);+ PrmHandler = =3D (PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT *)(PrmExport + 1);++ for (Handle= rNum =3D 0; HandlerNum < PrmExport->NumberPrmHandlers; HandlerNum++) {+ = strcpy(mExportSymName[mExportSymNum], PrmHandler->PrmHandlerName);+ mExp= ortSymNum ++;+ PrmHandler +=3D 1;++ //+ // Check if PRM handler nu= mber is larger than (PRM_MODULE_EXPORT_SYMBOL_NUM - 1)+ //+ if (mExpo= rtSymNum >=3D (PRM_MODULE_EXPORT_SYMBOL_NUM - 1)) {+ Error (NULL, 0, 3= 000, "Invalid", "FindPrmHandler: Number %u is too high.", mExportSymNum);+ = exit(EXIT_FAILURE);+ }+ }+}+ // // Find the ELF section hosting th= e GOT from an ELF Rva // of a single GOT entry. Normally, GOT is placed = in@@ -717,6 +785,7 @@ ScanSections64 ( UINT32 CoffEntry; UINT32 = SectionCount; BOOLEAN FoundSection;+ UINT32= Offset; CoffEntry =3D 0; mCoffOffset =3D 0;@= @ -880,6 +949,82 @@ 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) {+ UINT32 = SymIndex;+ Elf_Sym *Sym;+ UINT64 SymNum;+ const UINT= 8 *SymName;++ mExportOffset =3D mCoffOffset;+ mExportSize =3D sizeof(= EFI_IMAGE_EXPORT_DIRECTORY) + strlen(mInImageName) + 1;++ for (i =3D 0; = i < mEhdr->e_shnum; i++) {++ //+ // Determine if this is a symbol= section.+ //+ Elf_Shdr *shdr =3D GetShdrByIndex(i);+ if (!I= sSymbolShdr(shdr)) {+ continue;+ }++ UINT8 *Symtab =3D = (UINT8*)mEhdr + shdr->sh_offset;+ SymNum =3D (shdr->sh_size) / (shdr->= sh_entsize);++ //+ // First Get PrmModuleExportDescriptor+ /= /+ for (SymIndex =3D 0; SymIndex < SymNum; SymIndex++) {+ 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(mE= xportSymName[mExportSymNum], (CHAR8*)SymName);+ mExportRVA[mExport= SymNum] =3D (UINT32)(Sym->st_value);+ mExportSize +=3D 2 * EFI_IMA= GE_EXPORT_ADDR_SIZE + EFI_IMAGE_EXPORT_ORDINAL_SIZE + strlen((CHAR8 *)SymNa= me) + 1;+ mExportSymNum ++;+ break;+ }+ }++ = //+ // Second Get PrmHandler+ //+ for (SymIndex =3D 0; S= ymIndex < SymNum; SymIndex++) {+ UINT32 ExpIndex;+ Sym =3D = (Elf_Sym *)(Symtab + SymIndex * shdr->sh_entsize);+ SymName =3D GetS= ymName(Sym);+ if (SymName =3D=3D NULL) {+ continue;+ = }++ for (ExpIndex =3D 0; ExpIndex < (mExportSymNum -1); ExpIndex+= +) {+ if (strcmp((CHAR8*)SymName, mExportSymName[ExpIndex]) !=3D 0= ) {+ continue;+ }+ mExportRVA[ExpIndex] =3D (U= INT32)(Sym->st_value);+ mExportSize +=3D 2 * EFI_IMAGE_EXPORT_ADDR= _SIZE + EFI_IMAGE_EXPORT_ORDINAL_SIZE + strlen((CHAR8 *)SymName) + 1;+ = }+ }++ break;+ }++ mCoffOffset +=3D mExportSize;+ mCo= ffOffset =3D CoffAlign(mCoffOffset);+ }+ // // The HII resource secti= ons. //@@ -989,8 +1134,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 +1153,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;++ } else {+ // Don't make a section of size 0.+ = NtHdr->Pe32Plus.FileHeader.NumberOfSections--;+ }+ }+ if ((mRelo= cOffset - mHiiRsrcOffset) > 0) { CreateSectionHeader (".rsrc", mHiiRsrc= Offset, mRelocOffset - mHiiRsrcOffset, EFI_IMAGE_SCN_CNT_INITIA= LIZED_DATA@@ -1757,4 +1925,72 @@ CleanUp64 ( } } +STATIC+VOID+WriteExport64 (+ VOID+ )+{+ EFI_IMAGE_OPTIONAL_HEADE= R_UNION *NtHdr;+ EFI_IMAGE_EXPORT_DIRECTORY *ExportDir;+ EFI= _IMAGE_DATA_DIRECTORY *DataDir;+ UINT32 = FileNameOffset;+ UINT32 NameOffset;+ U= INT16 Index;+ UINT8 = *Tdata =3D NULL;++ ExportDir =3D (EFI_IMAGE_EXPORT_DIRECTORY*)(mCoffF= ile + mExportOffset);+ ExportDir->Characteristics =3D 0;+ ExportDir->Time= DateStamp =3D 0;+ ExportDir->MajorVersion =3D 0;+ ExportDir->MinorVersion= =3D0;+ ExportDir->Name =3D 0;+ ExportDir->NumberOfFunctions =3D mExportS= ymNum;+ ExportDir->NumberOfNames =3D mExportSymNum;+ ExportDir->Base =3D = EFI_IMAGE_EXPORT_ORDINAL_BASE;+ ExportDir->AddressOfFunctions =3D mExportO= ffset + sizeof(EFI_IMAGE_EXPORT_DIRECTORY);+ ExportDir->AddressOfNames =3D= ExportDir->AddressOfFunctions + EFI_IMAGE_EXPORT_ADDR_SIZE * mExportSymNum= ;+ ExportDir->AddressOfNameOrdinals =3D ExportDir->AddressOfNames + EFI_IM= AGE_EXPORT_ADDR_SIZE * mExportSymNum;++ FileNameOffset =3D ExportDir->Addr= essOfNameOrdinals + EFI_IMAGE_EXPORT_ORDINAL_SIZE * mExportSymNum;+ NameOf= fset =3D FileNameOffset + strlen(mInImageName) + 1;++ // Write Input image= Name RVA+ ExportDir->Name =3D FileNameOffset;++ // Write Input image Nam= e+ strcpy((char *)(mCoffFile + FileNameOffset), mInImageName);++ for (Ind= ex =3D 0; Index < mExportSymNum; Index++) {+ //+ // Write Export Addr= ess Table+ //+ Tdata =3D mCoffFile + ExportDir->AddressOfFunctions + = Index * EFI_IMAGE_EXPORT_ADDR_SIZE;+ *(UINT32 *)Tdata =3D mExportRVA[Ind= ex];++ //+ // Write Export Name Pointer Table+ //+ Tdata =3D mC= offFile + ExportDir->AddressOfNames + Index * EFI_IMAGE_EXPORT_ADDR_SIZE;+ = *(UINT32 *)Tdata =3D NameOffset;++ //+ // Write Export Ordinal tab= le+ //+ Tdata =3D mCoffFile + ExportDir->AddressOfNameOrdinals + Inde= x * EFI_IMAGE_EXPORT_ORDINAL_SIZE;+ *(UINT16 *)Tdata =3D Index;++ //+= // Write Export Name Table+ //+ strcpy((char *)(mCoffFile + NameO= ffset), mExportSymName[Index]);+ NameOffset +=3D strlen(mExportSymName[I= ndex]) + 1;+ }++ NtHdr =3D (EFI_IMAGE_OPTIONAL_HEADER_UNION *)(mCoffFile = + mNtHdrOffset);+ DataDir =3D &NtHdr->Pe32Plus.OptionalHeader.DataDirector= y[EFI_IMAGE_DIRECTORY_ENTRY_EXPORT];+ DataDir->VirtualAddress =3D mExportO= ffset;+ DataDir->Size =3D mExportSize;++} diff --git a/BaseTools/Source/C/= GenFw/ElfConvert.c b/BaseTools/Source/C/GenFw/ElfConvert.c index 7db8721167..be98544056 100644 --- a/BaseTools/Source/C/GenFw/ElfConvert.c +++ b/BaseTools/Source/C/GenFw/ElfConvert.c @@ -223,6 +223,14 @@ ConvertElf ( VerboseMsg ("Write debug info."); ElfFunctions.WriteDebug (); + //+ = // For PRM Driver to Write export info.+ //+ if (mExportFlag) {+ Verbo= seMsg ("Write export info.");+ ElfFunctions.WriteExport ();+ }+ // = // Make sure image size is correct before returning the new image. //diff= --git a/BaseTools/Source/C/GenFw/ElfConvert.h b/BaseTools/Source/C/GenFw/E= lfConvert.h index 801e8de4a2..6ab4605227 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,44 @@ 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 256++// to include PRM header directly on= ce PrmPkg is in main repo+#define PRM_HANDLER_NAME_MAXIMUM_LENGTH 128++#def= ine 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 Structures= +//+#pragma pack(push, 1)++typedef struct {+ EFI_GUID = PrmHandlerGuid;+ CHAR8 PrmHandler= Name[PRM_HANDLER_NAME_MAXIMUM_LENGTH];+} PRM_HANDLER_EXPORT_DESCRIPTOR_STRU= CT;++typedef struct {+ UINT64 Signature;+ = UINT16 Revision;+ UINT16 = NumberPrmHandlers;+ EFI_GUID Pla= tformGuid;+ EFI_GUID ModuleGuid;+} PRM_MODULE= _EXPORT_DESCRIPTOR_STRUCT_HEADER;++typedef struct {+ PRM_MODULE_EXPORT_DES= CRIPTOR_STRUCT_HEADER Header;+ PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT = PrmHandlerExportDescriptors[1];+} PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT;++#= pragma pack(pop) // // Filter Types@@ -38,7 +77,8 @@ extern UINT32 mFileBu= fferSize; typedef enum { SECTION_TEXT, SECTION_HII,- SECTION_DATA+ SECTION_DAT= A,+ SECTION_SYMBOL } SECTION_FILTER_TYPES; @@ -50,6 +90,7 @@ typedef stru= ct { BOOLEAN (*WriteSections) (SECTION_FILTER_TYPES FilterType); VOID (= *WriteRelocations) (); VOID (*WriteDebug) ();+ VOID (*WriteExport)= (); VOID (*SetImageSize) (); VOID (*CleanUp) (); diff --git a/Ba= seTools/Source/C/GenFw/GenFw.c b/BaseTools/Source/C/GenFw/GenFw.c index 8cab70ba4d..6f61f16788 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= @@ -279,6 +279,10 @@ Returns: except for -o or -r option. It is a action option.= \n\ If it is combined with other action options, th= e later\n\ input action option will override the pr= evious one.\n");+ fprintf (stdout, " --prm Scan symbol se= ction from ELF image and \n\+ write export table int= o PE-COFF.\n\+ This option can be used together with= -e.\n\+ It doesn't work for other options.\n"); f= printf (stdout, " -v, --verbose Turn on verbose output with inform= ational messages.\n"); fprintf (stdout, " -q, --quiet Disable = all messages except key message and fatal error\n"); fprintf (stdout, " = -d, --debug level Enable debug messages, at input debug level.\n");@@ -= 1436,6 +1440,20 @@ Returns: continue; } + if (stricmp (argv[0], "--prm") =3D=3D 0) {+ = if (stricmp (ModuleType, "DXE_RUNTIME_DRIVER") !=3D 0 ){+ Error (N= ULL, 0, 1001, "Invalid", "--prm option only supports DXE RUNTIME driver.");= + goto Finish;+ }++ if (!mExportFlag) {+ mExportFla= g =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/Indus= tryStandard/PeImage.h b/BaseTools/Source/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