From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mx.groups.io with SMTP id smtpd.web10.23601.1647240274988953798 for ; Sun, 13 Mar 2022 23:44:35 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=ZJlU/aPk; spf=pass (domain: intel.com, ip: 192.55.52.93, 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=1647240275; x=1678776275; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=J+fpfaThBVSeb3ksxXB3OMJ4QoBhunO6H8HJT0h4p74=; b=ZJlU/aPkjjervCYn6y2Gcs/Irj3p+pDkmXnXZhTVh1nQgYooP7eo8S+P VrLm6ZVLXlkchErLPhjJFwckvM8brjv+/JSrqoUnPOoWscSAE+GnWRVfw 6l6R6bR1a1nRfbssEW1VFYKiDcY+HTCj9TcvhcWZVsnDSJBkZzMKSOfPm dSlOfplfWA5DLrP2US8LvvMmXKW/HAx2H/cMSAmhPxMrMfmHAsA17XiaG QOr1lth0pOLnJBOpnoNN2I9tNvCY79jEodfcRBN9rEMnNniwRSpe/uwaM uSvdWyevS9Q9aqNF5ww4WWnG5XSt/Fxdrs1IzJr6ghRdWjw7UtIhhlePY Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10285"; a="253509164" X-IronPort-AV: E=Sophos;i="5.90,179,1643702400"; d="scan'208";a="253509164" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2022 23:44:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,179,1643702400"; d="scan'208";a="818701994" Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82]) by fmsmga005.fm.intel.com with ESMTP; 13 Mar 2022 23:44:34 -0700 Received: from fmsmsx603.amr.corp.intel.com (10.18.126.83) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Sun, 13 Mar 2022 23:44:33 -0700 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21 via Frontend Transport; Sun, 13 Mar 2022 23:44:33 -0700 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.174) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.21; Sun, 13 Mar 2022 23:44:33 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DJnG8IysvunfNcgf2GYUBBNgiw3lqgpUANwgKfIzxnNn4ZB3xlVVTLoM2FvgWrmlCJt98knKY3Kwn91qOO/KDtK9bGAtXi0tA7/7rcewwWQ2g+PanjndhbdDALGIL9EL39e9v9q+aEZusxo/9n3gY3rSR2mYHyDgb5IAVtGuDc48bkCn23sc1NIjyjmRdwlkQWYV/gC+aboYh6wzpQpVgwMnRPRkKI+UVYu8laLF8LcJ2wYUkc/8MwJiL4hdmlNN/CqVMSnOnyKBHoL2DVt43vzP8p1n311Nqb/JmsiJKXfwmtNV1Qy7YqqQwbzn/fiwijg1hoSTe6EeOzfc1ZacQg== 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=4H5Seax+YI75+kDnDParlAcJgoETNbPMuyDJnzJgrZk=; b=F823RxMjrjLPEeGbxHhBgkb0MQqLGPx6V5Zey3pNWSatR/jjOOu7hk4nQNygR+ewYJw12v7Lq8jq82oy1ktf2xFwwwTiD1INL9KljlPDblfXT7y5HGOxP3v6MdA+bVoW8ZNaJyzK6cy4EXHDA7iFW5FgUexl09YUTydfENRdyEeUkC0RPderbzqpFE+6CEYfUnsv6+LEW2bkpT0xi3TCncrhSIvX5lnyb0I43/9Ic4bu/Q1m4dVZzKddk7qXMk+N2waZuVXSRIhHdAOZ0I1+pofId9fUEx9e8Qo5eHUg+kMHVs686cpuA58vCqHq8sfvNe3esVyM6hDUxztTBhEO0Q== 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 BL1PR11MB5383.namprd11.prod.outlook.com (2603:10b6:208:318::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.21; Mon, 14 Mar 2022 06:44:31 +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 06:44:31 +0000 From: "Bob Feng" To: "Huang, Li-Xia" , "devel@edk2.groups.io" 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+bv3Q Date: Mon, 14 Mar 2022 06:44:31 +0000 Message-ID: References: <20220314052721.3755-1-lisa.huang@intel.com> In-Reply-To: <20220314052721.3755-1-lisa.huang@intel.com> 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: 0d3556dd-2081-4738-2914-08da05861830 x-ms-traffictypediagnostic: BL1PR11MB5383: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: PhtHtsswn3T4aofYYKbgDGbNiXEKJ0bZCHD5Fky3qQ5sqHCy3c5qIAspRDHfYo+L6J+bB+4ALxHyuU9s7PsrJGHtODO7kekPZLS36YMPwF9QqpukIU2V09uqa6Yh3ilfYTBgmV//EQGvnOcRaSqoECjFkYl5GpfFEnu2N6bamRcS9cMCwq4VLtuo+0lNvEmTSUrJPQlPsXY1GbhKIoWtSSy4GRfoSCW2lo+3AeCmk1vLPf7TN2r7cigHrxBWCWasApTW1e1Jg8jY1n60KqrE6PdGh4FE3iOWs0lqpmdDvF8fyI8ANkvyzednKmDIB4wn6GjGNRSQ4PBAkJPSn60vMAz+AZoOjbD0dkX1kHd6M3a5DFou9FFjyYhQWi0zj6bmww7P/RmjostuD9kWyAZLwfP2FLK/jucfSqE5LYBTmbktdWrO87HcTOuPHCaU2VOMCLatziMojVTnwndgbb3avcn3UYIqXNsXUa47vrcl+/7zeUsAJ9dyv5LtmmpM6XIl8jf+W5OnfWbeWI8tsBqglCvEwDyvQKwa94/xxpBrd03m9lgq2iH1c9gu5LK03Cd1DgXeCFkbYaSacVM70zUTxSW00Tno8xgH2XCo2/u9u0nniJ4r9erEV+wk2W0GnDqJUkVtuCQX+u+RH/ROQyUer4NbIgw064J+1N+clVbtu/yvYM4ROUT4sclaoFrZEXf7wovz77ACDNIQeXw2NK1URm/D+AHNYCyD6VnXPWqXOmtc2ZLvTYFQTWdD0tRUey5pkNYC4CkwjLnv5OavW8qjsg+d/SkWIf3YFENw+6a9qFA= 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)(5660300002)(55016003)(9686003)(107886003)(33656002)(30864003)(2906002)(83380400001)(122000001)(66446008)(8936002)(38070700005)(66476007)(66556008)(4326008)(64756008)(82960400001)(26005)(76116006)(186003)(8676002)(71200400001)(66946007)(53546011)(52536014)(38100700002)(6506007)(86362001)(7696005)(19627235002)(316002)(54906003)(110136005)(966005)(508600001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?SqY71LW1JKBArBQmxAYyNZLEpOiVDDwFw2Gi7ts9WYA500nQA6r0y6tUG4tn?= =?us-ascii?Q?KpKRwgV0D1UBTIvxzc1T45bSlsv1FFXPRHhbvGgvlqilIajEnRWBBtduuMCs?= =?us-ascii?Q?fdAI7XufVs7J4FeDE0GLUlv9LryhPm1CjvjqiKkaeGSAZ64npEQHb9AYm4dw?= =?us-ascii?Q?fak8n4y8TMvSF3uUet6MGso7djbIefdMat2+hqAiFyhYAeonNxqg+2CyBGoc?= =?us-ascii?Q?/HSkAwJ7gi6PWH3wIzCFrBHob1eggWhsGsrqKWYwdnIQutZTT2CMfNLszugB?= =?us-ascii?Q?gIWdcCCy702NVMHtzd/7elYOy8PlrNLZMaxiNINzfnPO9b1gN2op6tZCZBVP?= =?us-ascii?Q?RIeTaYUs6woUjr4mgWTxoseelXkaYF4u+7jLn+Rvw1zZWMM/bLy6yD3x6FG7?= =?us-ascii?Q?43NnGJld/1H/mOVwg9wIpIr9LkvSZZgNV4aN8Uj7452p52PCdQN9HzFOWtzU?= =?us-ascii?Q?BV3WF9ahvmZEfV+Dx08whkZqiR32wrecVk/VJsydwKIkqOtTi2te7axgSlxF?= =?us-ascii?Q?go9dYOcC91mo9xT+L+go5cBJlAVJw0aqIALiKafF9mi21Fopfxy9x0VyT32T?= =?us-ascii?Q?H8H2WsT/J0++DfuIgqM1ThuKpqllBTKaRBhUXOUgEUKvqqL7oKStvomn8k1E?= =?us-ascii?Q?2WWSCP4PGqr1mEW9PxBMMiij14c+9DOQTGB9maUyiHUXYejBquywxICBu2fj?= =?us-ascii?Q?0A6nN2LtEOslvvrtHxGyz0JsX4v0SoWaGxbW45x8StQqmN82vi3/10GpBfN8?= =?us-ascii?Q?hPulj+zFdcYlHq/ElyTTj3REMi+m6EZXxQIYhjbDNvLv4CTR0u2Saapnr3Wj?= =?us-ascii?Q?2T9DPpe9mAbBRhnQT65JQA0XvkUtW5EMrc21UZJ1GVnRsG1B5XulFdLrEu7s?= =?us-ascii?Q?kJvSV/vLGiwKUvD3ntXjTRGUa0OR4FlH9l8eEg2vCXHwxoIXqAe1bv1hzQoL?= =?us-ascii?Q?3O4dxRjPobmp2eFGXXO3Z41hBTNo8F9do/sxhxFDWwtzp8FfJNZJ6hu8iBZV?= =?us-ascii?Q?RWR3UtboXZXJHsSAYDr++s4J6UwUsb4gWG5bd1ZXuXXx7GUqv/nBBIfp7nmU?= =?us-ascii?Q?jf+DI3Jr2yvdkLFGyiVAdez4Riomr8B04JaWXsEUP36B+o/kRNjI89wNzWhL?= =?us-ascii?Q?N8dpDGSAl7rvRR0WU5v6wjA+T4/GWyhldnj/36pObqhfNH7ZbWBEEdutQ291?= =?us-ascii?Q?TkViUEPpY6pOpRPIxdHVr6tAzyMOroF3rtsmBvbiQKfQZNhdxPLG89hAShVm?= =?us-ascii?Q?6rar8S2J3h1ZJMFC4hr8vt3+Q9W1sC1zHAAQxLQdUZWHYTZkm7+k7nJv3ih9?= =?us-ascii?Q?TkiYgE7cF/VzjUbYfO8qhp19sw1PTlpAxYzqbNyXx7h6PH6XiosAnBbSdaM+?= =?us-ascii?Q?4wTa87wARDTDDiiYIMRnzk1h0pfLVLRIyb81EjuRQspY5MYVqs/zLlkCqd4C?= =?us-ascii?Q?QWBguBOH8E5PrBvrDdxwIgZJb8Gtz6FO?= 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: 0d3556dd-2081-4738-2914-08da05861830 X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Mar 2022 06:44:31.5131 (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: s51SB/1YjZ1J8E0u+mHmPce3VNTP5+ytALrAB6H7vY+t96dCUNaMGNt4po1SV3wyVLpvB7lFivwz/qOTPUM6yg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR11MB5383 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 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