From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.byosoft.com.cn (mail.byosoft.com.cn [58.240.74.242]) by mx.groups.io with SMTP id smtpd.web12.3511.1646099515869601082 for ; Mon, 28 Feb 2022 17:51:56 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=none, err=permanent DNS error (domain: byosoft.com.cn, ip: 58.240.74.242, mailfrom: gaoliming@byosoft.com.cn) Received: from DESKTOPS6D0PVI ([58.246.60.130]) (envelope-sender ) by 192.168.6.13 with ESMTP for ; Tue, 01 Mar 2022 09:51:52 +0800 X-WM-Sender: gaoliming@byosoft.com.cn X-Originating-IP: 58.246.60.130 X-WM-AuthFlag: YES X-WM-AuthUser: gaoliming@byosoft.com.cn From: "gaoliming" To: , Cc: "'Bob Feng'" , "'Yuwei Chen'" References: <20220228011411.3450-1-lisa.huang@intel.com> In-Reply-To: <20220228011411.3450-1-lisa.huang@intel.com> Subject: =?UTF-8?B?5Zue5aSNOiBbZWRrMi1kZXZlbF0gW1BBVENIIHYyXSBCYXNlVG9vbHMvR2VuRnc6IEVuaGFuY2UgR2VuRncgdG8gc3VwcG9ydCBQUk0gR0NDIGJ1aWxk?= Date: Tue, 1 Mar 2022 09:51:53 +0800 Message-ID: <02d701d82d0e$ecf682c0$c6e38840$@byosoft.com.cn> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQMtsNWFzOQvEmlEndNJ8zHV5knH7an+u+QA Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: quoted-printable Content-Language: zh-cn Lisa: Please add BZ link for this patch.=20 And, if PRM option currently only supports DXE RUNTIME driver and X64 arch,=20 does GenFw report error message if PRM option is specified for other = arch or other module type? Thanks Liming > -----=D3=CA=BC=FE=D4=AD=BC=FE----- > =B7=A2=BC=FE=C8=CB: devel@edk2.groups.io = =B4=FA=B1=ED Huang, Li-Xia > =B7=A2=CB=CD=CA=B1=BC=E4: 2022=C4=EA2=D4=C228=C8=D5 9:14 > =CA=D5=BC=FE=C8=CB: devel@edk2.groups.io > =B3=AD=CB=CD: Lixia Huang ; Liming Gao > ; Bob Feng ; Yuwei = Chen > > =D6=F7=CC=E2: [edk2-devel] [PATCH v2] BaseTools/GenFw: Enhance GenFw = to support > PRM GCC build >=20 > Since PRM module needs to support export table in PE-COFF, we'll > enhance GenFw tool to support this. >=20 > Add one export flag in GenFw tool. If export flag is set: > Step1: Scan ELF symbol table based on PRM module descriptor to get > descriptor 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. >=20 > PRM option currently only supports DXE RUNTIME driver and X64 arch. >=20 > Change-Id: I479b7c8b23beea12b5c567677688aef6f7af2085 > 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(-) >=20 > diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c > b/BaseTools/Source/C/GenFw/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 >=20 > ); >=20 >=20 >=20 > +STATIC >=20 > +VOID >=20 > +WriteExport64 ( >=20 > + VOID >=20 > + ); >=20 > + >=20 > STATIC >=20 > VOID >=20 > SetImageSize64 ( >=20 > @@ -106,7 +112,7 @@ STATIC UINT32 mCoffAlignment =3D 0x20; > // >=20 > // PE section alignment. >=20 > // >=20 > -STATIC const UINT16 mCoffNbrSections =3D 4; >=20 > +STATIC UINT16 mCoffNbrSections =3D 4; >=20 >=20 >=20 > // >=20 > // ELF sections to offset in Coff file. >=20 > @@ -122,7 +128,7 @@ STATIC UINT32 mDataOffset; > STATIC UINT32 mHiiRsrcOffset; >=20 > STATIC UINT32 mRelocOffset; >=20 > STATIC UINT32 mDebugOffset; >=20 > - >=20 > +STATIC UINT32 mExportOffset; >=20 > // >=20 > // Used for RISC-V relocations. >=20 > // >=20 > @@ -132,6 +138,14 @@ STATIC Elf64_Half mRiscVPass1SymSecIndex =3D 0; > STATIC INT32 mRiscVPass1Offset; >=20 > STATIC INT32 mRiscVPass1GotFixup; >=20 >=20 >=20 > +// >=20 > +// Used for Export section. >=20 > +// >=20 > +STATIC UINT32 mExportSize; >=20 > +STATIC UINT32 > mExportRVA[PRM_MODULE_EXPORT_SYMBOL_NUM]; >=20 > +STATIC UINT32 mExportSymNum; >=20 > +STATIC CHAR8 > mExportSymName[PRM_MODULE_EXPORT_SYMBOL_NUM][PRM_HANDLE > R_NAME_MAXIMUM_LENGTH]; >=20 > + >=20 > // >=20 > // Initialization Function >=20 > // >=20 > @@ -171,6 +185,13 @@ InitializeElf64 ( > return FALSE; >=20 > } >=20 >=20 >=20 > + if (mExportFlag) { >=20 > + if (mEhdr->e_machine !=3D EM_X86_64) { >=20 > + Error (NULL, 0, 3000, "Unsupported", "--prm option currently = only > supports X64 arch."); >=20 > + return FALSE; >=20 > + } >=20 > + } >=20 > + >=20 > // >=20 > // Update section header pointers >=20 > // >=20 > @@ -200,6 +221,11 @@ InitializeElf64 ( > ElfFunctions->SetImageSize =3D SetImageSize64; >=20 > ElfFunctions->CleanUp =3D CleanUp64; >=20 >=20 >=20 > + if (mExportFlag) { >=20 > + mCoffNbrSections ++; >=20 > + ElfFunctions->WriteExport =3D WriteExport64; >=20 > + } >=20 > + >=20 > return TRUE; >=20 > } >=20 >=20 >=20 > @@ -263,6 +289,17 @@ IsHiiRsrcShdr ( > return (BOOLEAN) (strcmp((CHAR8*)mEhdr + Namedr->sh_offset + > Shdr->sh_name, ELF_HII_SECTION_NAME) =3D=3D 0); >=20 > } >=20 >=20 >=20 > +STATIC >=20 > +BOOLEAN >=20 > +IsSymbolShdr ( >=20 > + Elf_Shdr *Shdr >=20 > + ) >=20 > +{ >=20 > + Elf_Shdr *Namehdr =3D GetShdrByIndex(mEhdr->e_shstrndx); >=20 > + >=20 > + return (BOOLEAN) (strcmp((CHAR8*)mEhdr + Namehdr->sh_offset + > Shdr->sh_name, ELF_SYMBOL_SECTION_NAME) =3D=3D 0); >=20 > +} >=20 > + >=20 > STATIC >=20 > BOOLEAN >=20 > IsDataShdr ( >=20 > @@ -335,6 +372,37 @@ GetSymName ( > return StrtabContents + Sym->st_name; >=20 > } >=20 >=20 >=20 > +// >=20 > +// Get Prm Handler number and name >=20 > +// >=20 > +STATIC >=20 > +VOID >=20 > +FindPrmHandler ( >=20 > + UINT64 Offset >=20 > + ) >=20 > +{ >=20 > + PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT_HEADER *PrmExport; >=20 > + PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT *PrmHandler; >=20 > + UINT32 HandlerNum; >=20 > + >=20 > + PrmExport =3D > (PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT_HEADER*)((UINT8*)mEhdr > + Offset); >=20 > + PrmHandler =3D (PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT > *)(PrmExport + 1); >=20 > + >=20 > + for (HandlerNum =3D 0; HandlerNum < PrmExport->NumberPrmHandlers; > HandlerNum++) { >=20 > + strcpy(mExportSymName[mExportSymNum], > PrmHandler->PrmHandlerName); >=20 > + mExportSymNum ++; >=20 > + PrmHandler +=3D 1; >=20 > + >=20 > + // >=20 > + // Check if PRM handler number is larger than > (PRM_MODULE_EXPORT_SYMBOL_NUM - 1) >=20 > + // >=20 > + if (mExportSymNum >=3D (PRM_MODULE_EXPORT_SYMBOL_NUM - 1)) { >=20 > + Error (NULL, 0, 3000, "Invalid", "FindPrmHandler: Number %u is = too > high.", mExportSymNum); >=20 > + exit(EXIT_FAILURE); >=20 > + } >=20 > + } >=20 > +} >=20 > + >=20 > // >=20 > // Find the ELF section hosting the GOT from an ELF Rva >=20 > // of a single GOT entry. Normally, GOT is placed in >=20 > @@ -717,6 +785,7 @@ ScanSections64 ( > UINT32 CoffEntry; >=20 > UINT32 SectionCount; >=20 > BOOLEAN FoundSection; >=20 > + UINT32 Offset; >=20 >=20 >=20 > CoffEntry =3D 0; >=20 > mCoffOffset =3D 0; >=20 > @@ -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); >=20 > } >=20 >=20 >=20 > + // >=20 > + // The Symbol sections. >=20 > + // >=20 > + if (mExportFlag) { >=20 > + UINT32 SymIndex; >=20 > + Elf_Sym *Sym; >=20 > + UINT64 SymNum; >=20 > + const UINT8 *SymName; >=20 > + >=20 > + mExportOffset =3D mCoffOffset; >=20 > + mExportSize =3D sizeof(EFI_IMAGE_EXPORT_DIRECTORY) + > strlen(mInImageName) + 1; >=20 > + >=20 > + for (i =3D 0; i < mEhdr->e_shnum; i++) { >=20 > + >=20 > + // >=20 > + // Determine if this is a symbol section. >=20 > + // >=20 > + Elf_Shdr *shdr =3D GetShdrByIndex(i); >=20 > + if (!IsSymbolShdr(shdr)) { >=20 > + continue; >=20 > + } >=20 > + >=20 > + UINT8 *Symtab =3D (UINT8*)mEhdr + shdr->sh_offset; >=20 > + SymNum =3D (shdr->sh_size) / (shdr->sh_entsize); >=20 > + >=20 > + // >=20 > + // First Get PrmModuleExportDescriptor >=20 > + // >=20 > + for (SymIndex =3D 0; SymIndex < SymNum; SymIndex++) { >=20 > + Sym =3D (Elf_Sym *)(Symtab + SymIndex * shdr->sh_entsize); >=20 > + SymName =3D GetSymName(Sym); >=20 > + if (SymName =3D=3D NULL) { >=20 > + continue; >=20 > + } >=20 > + >=20 > + if (strcmp((CHAR8*)SymName, > PRM_MODULE_EXPORT_DESCRIPTOR_NAME) =3D=3D 0) { >=20 > + // >=20 > + // Find PrmHandler Number and Name >=20 > + // >=20 > + FindPrmHandler(Sym->st_value); >=20 > + >=20 > + strcpy(mExportSymName[mExportSymNum], > (CHAR8*)SymName); >=20 > + mExportRVA[mExportSymNum] =3D (UINT32)(Sym->st_value); >=20 > + mExportSize +=3D 2 * EFI_IMAGE_EXPORT_ADDR_SIZE + > EFI_IMAGE_EXPORT_ORDINAL_SIZE + strlen((CHAR8 *)SymName) + 1; >=20 > + mExportSymNum ++; >=20 > + break; >=20 > + } >=20 > + } >=20 > + >=20 > + // >=20 > + // Second Get PrmHandler >=20 > + // >=20 > + for (SymIndex =3D 0; SymIndex < SymNum; SymIndex++) { >=20 > + UINT32 ExpIndex; >=20 > + Sym =3D (Elf_Sym *)(Symtab + SymIndex * shdr->sh_entsize); >=20 > + SymName =3D GetSymName(Sym); >=20 > + if (SymName =3D=3D NULL) { >=20 > + continue; >=20 > + } >=20 > + >=20 > + for (ExpIndex =3D 0; ExpIndex < (mExportSymNum -1); = ExpIndex++) { >=20 > + if (strcmp((CHAR8*)SymName, mExportSymName[ExpIndex]) !=3D > 0) { >=20 > + continue; >=20 > + } >=20 > + mExportRVA[ExpIndex] =3D (UINT32)(Sym->st_value); >=20 > + mExportSize +=3D 2 * EFI_IMAGE_EXPORT_ADDR_SIZE + > EFI_IMAGE_EXPORT_ORDINAL_SIZE + strlen((CHAR8 *)SymName) + 1; >=20 > + } >=20 > + } >=20 > + >=20 > + break; >=20 > + } >=20 > + >=20 > + mCoffOffset +=3D mExportSize; >=20 > + mCoffOffset =3D CoffAlign(mCoffOffset); >=20 > + } >=20 > + >=20 > // >=20 > // The HII resource sections. >=20 > // >=20 > @@ -989,8 +1134,17 @@ ScanSections64 ( > NtHdr->Pe32Plus.FileHeader.NumberOfSections--; >=20 > } >=20 >=20 >=20 > + // >=20 > + // If found symbol, add edata section between data and rsrc section >=20 > + // >=20 > + if(mExportFlag) { >=20 > + Offset =3D mExportOffset; >=20 > + } else { >=20 > + Offset =3D mHiiRsrcOffset; >=20 > + } >=20 > + >=20 > if ((mHiiRsrcOffset - mDataOffset) > 0) { >=20 > - CreateSectionHeader (".data", mDataOffset, mHiiRsrcOffset - > mDataOffset, >=20 > + CreateSectionHeader (".data", mDataOffset, Offset - mDataOffset, >=20 > EFI_IMAGE_SCN_CNT_INITIALIZED_DATA >=20 > | EFI_IMAGE_SCN_MEM_WRITE >=20 > | EFI_IMAGE_SCN_MEM_READ); >=20 > @@ -999,6 +1153,20 @@ ScanSections64 ( > NtHdr->Pe32Plus.FileHeader.NumberOfSections--; >=20 > } >=20 >=20 >=20 > + if(mExportFlag) { >=20 > + if ((mHiiRsrcOffset - mExportOffset) > 0) { >=20 > + CreateSectionHeader (".edata", mExportOffset, mHiiRsrcOffset - > mExportOffset, >=20 > + EFI_IMAGE_SCN_CNT_INITIALIZED_DATA >=20 > + | EFI_IMAGE_SCN_MEM_READ); >=20 > + > NtHdr->Pe32Plus.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_EN > TRY_EXPORT].Size =3D mHiiRsrcOffset - mExportOffset; >=20 > + > NtHdr->Pe32Plus.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_EN > TRY_EXPORT].VirtualAddress =3D mExportOffset; >=20 > + >=20 > + } else { >=20 > + // Don't make a section of size 0. >=20 > + NtHdr->Pe32Plus.FileHeader.NumberOfSections--; >=20 > + } >=20 > + } >=20 > + >=20 > if ((mRelocOffset - mHiiRsrcOffset) > 0) { >=20 > CreateSectionHeader (".rsrc", mHiiRsrcOffset, mRelocOffset - > mHiiRsrcOffset, >=20 > EFI_IMAGE_SCN_CNT_INITIALIZED_DATA >=20 > @@ -1757,4 +1925,72 @@ CleanUp64 ( > } >=20 > } >=20 >=20 >=20 > +STATIC >=20 > +VOID >=20 > +WriteExport64 ( >=20 > + VOID >=20 > + ) >=20 > +{ >=20 > + EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr; >=20 > + EFI_IMAGE_EXPORT_DIRECTORY *ExportDir; >=20 > + EFI_IMAGE_DATA_DIRECTORY *DataDir; >=20 > + UINT32 FileNameOffset; >=20 > + UINT32 NameOffset; >=20 > + UINT16 Index; >=20 > + UINT8 *Tdata =3D NULL; >=20 > + >=20 > + ExportDir =3D (EFI_IMAGE_EXPORT_DIRECTORY*)(mCoffFile + > mExportOffset); >=20 > + ExportDir->Characteristics =3D 0; >=20 > + ExportDir->TimeDateStamp =3D 0; >=20 > + ExportDir->MajorVersion =3D 0; >=20 > + ExportDir->MinorVersion =3D0; >=20 > + ExportDir->Name =3D 0; >=20 > + ExportDir->NumberOfFunctions =3D mExportSymNum; >=20 > + ExportDir->NumberOfNames =3D mExportSymNum; >=20 > + ExportDir->Base =3D EFI_IMAGE_EXPORT_ORDINAL_BASE; >=20 > + ExportDir->AddressOfFunctions =3D mExportOffset + > sizeof(EFI_IMAGE_EXPORT_DIRECTORY); >=20 > + ExportDir->AddressOfNames =3D ExportDir->AddressOfFunctions + > EFI_IMAGE_EXPORT_ADDR_SIZE * mExportSymNum; >=20 > + ExportDir->AddressOfNameOrdinals =3D ExportDir->AddressOfNames + > EFI_IMAGE_EXPORT_ADDR_SIZE * mExportSymNum; >=20 > + >=20 > + FileNameOffset =3D ExportDir->AddressOfNameOrdinals + > EFI_IMAGE_EXPORT_ORDINAL_SIZE * mExportSymNum; >=20 > + NameOffset =3D FileNameOffset + strlen(mInImageName) + 1; >=20 > + >=20 > + // Write Input image Name RVA >=20 > + ExportDir->Name =3D FileNameOffset; >=20 > + >=20 > + // Write Input image Name >=20 > + strcpy((char *)(mCoffFile + FileNameOffset), mInImageName); >=20 > + >=20 > + for (Index =3D 0; Index < mExportSymNum; Index++) { >=20 > + // >=20 > + // Write Export Address Table >=20 > + // >=20 > + Tdata =3D mCoffFile + ExportDir->AddressOfFunctions + Index * > EFI_IMAGE_EXPORT_ADDR_SIZE; >=20 > + *(UINT32 *)Tdata =3D mExportRVA[Index]; >=20 > + >=20 > + // >=20 > + // Write Export Name Pointer Table >=20 > + // >=20 > + Tdata =3D mCoffFile + ExportDir->AddressOfNames + Index * > EFI_IMAGE_EXPORT_ADDR_SIZE; >=20 > + *(UINT32 *)Tdata =3D NameOffset; >=20 > + >=20 > + // >=20 > + // Write Export Ordinal table >=20 > + // >=20 > + Tdata =3D mCoffFile + ExportDir->AddressOfNameOrdinals + Index * > EFI_IMAGE_EXPORT_ORDINAL_SIZE; >=20 > + *(UINT16 *)Tdata =3D Index; >=20 > + >=20 > + // >=20 > + // Write Export Name Table >=20 > + // >=20 > + strcpy((char *)(mCoffFile + NameOffset), mExportSymName[Index]); >=20 > + NameOffset +=3D strlen(mExportSymName[Index]) + 1; >=20 > + } >=20 > + >=20 > + NtHdr =3D (EFI_IMAGE_OPTIONAL_HEADER_UNION *)(mCoffFile + > mNtHdrOffset); >=20 > + DataDir =3D > &NtHdr->Pe32Plus.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_E > NTRY_EXPORT]; >=20 > + DataDir->VirtualAddress =3D mExportOffset; >=20 > + DataDir->Size =3D mExportSize; >=20 > + >=20 > +} >=20 >=20 >=20 > 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."); >=20 > ElfFunctions.WriteDebug (); >=20 >=20 >=20 > + // >=20 > + // For PRM Driver to Write export info. >=20 > + // >=20 > + if (mExportFlag) { >=20 > + VerboseMsg ("Write export info."); >=20 > + ElfFunctions.WriteExport (); >=20 > + } >=20 > + >=20 > // >=20 > // Make sure image size is correct before returning the new image. >=20 > // >=20 > diff --git a/BaseTools/Source/C/GenFw/ElfConvert.h > b/BaseTools/Source/C/GenFw/ElfConvert.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; >=20 > extern UINT32 mOutImageType; >=20 > extern UINT32 mFileBufferSize; >=20 > +extern BOOLEAN mExportFlag; >=20 >=20 >=20 > // >=20 > // Common EFI specific data. >=20 > @@ -31,6 +32,44 @@ extern UINT32 mFileBufferSize; > #define ELF_HII_SECTION_NAME ".hii" >=20 > #define ELF_STRTAB_SECTION_NAME ".strtab" >=20 > #define MAX_COFF_ALIGNMENT 0x10000 >=20 > +#define ELF_SYMBOL_SECTION_NAME ".symtab" >=20 > + >=20 > +// >=20 > +// Platform Runtime Mechanism (PRM) specific data. >=20 > +// >=20 > +#define PRM_MODULE_EXPORT_SYMBOL_NUM 256 >=20 > + >=20 > +// to include PRM header directly once PrmPkg is in main repo >=20 > +#define PRM_HANDLER_NAME_MAXIMUM_LENGTH 128 >=20 > + >=20 > +#define PRM_MODULE_EXPORT_DESCRIPTOR_NAME > "PrmModuleExportDescriptor" >=20 > +#define PRM_MODULE_EXPORT_DESCRIPTOR_SIGNATURE > SIGNATURE_64 ('P', 'R', 'M', '_', 'M', 'E', 'D', 'T') >=20 > +#define PRM_MODULE_EXPORT_REVISION 0x0 >=20 > + >=20 > +// >=20 > +// Platform Runtime Mechanism (PRM) Export Descriptor Structures >=20 > +// >=20 > +#pragma pack(push, 1) >=20 > + >=20 > +typedef struct { >=20 > + EFI_GUID PrmHandlerGuid; >=20 > + CHAR8 > PrmHandlerName[PRM_HANDLER_NAME_MAXIMUM_LENGTH]; >=20 > +} PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT; >=20 > + >=20 > +typedef struct { >=20 > + UINT64 Signature; >=20 > + UINT16 Revision; >=20 > + UINT16 NumberPrmHandlers; >=20 > + EFI_GUID PlatformGuid; >=20 > + EFI_GUID ModuleGuid; >=20 > +} PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT_HEADER; >=20 > + >=20 > +typedef struct { >=20 > + PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT_HEADER Header; >=20 > + PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT > PrmHandlerExportDescriptors[1]; >=20 > +} PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT; >=20 > + >=20 > +#pragma pack(pop) >=20 >=20 >=20 > // >=20 > // Filter Types >=20 > @@ -38,7 +77,8 @@ extern UINT32 mFileBufferSize; > typedef enum { >=20 > SECTION_TEXT, >=20 > SECTION_HII, >=20 > - SECTION_DATA >=20 > + SECTION_DATA, >=20 > + SECTION_SYMBOL >=20 >=20 >=20 > } SECTION_FILTER_TYPES; >=20 >=20 >=20 > @@ -50,6 +90,7 @@ typedef struct { > BOOLEAN (*WriteSections) (SECTION_FILTER_TYPES FilterType); >=20 > VOID (*WriteRelocations) (); >=20 > VOID (*WriteDebug) (); >=20 > + VOID (*WriteExport) (); >=20 > VOID (*SetImageSize) (); >=20 > VOID (*CleanUp) (); >=20 >=20 >=20 > diff --git a/BaseTools/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; >=20 > UINT32 mOutImageType =3D FW_DUMMY_IMAGE; >=20 > BOOLEAN mIsConvertXip =3D FALSE; >=20 > - >=20 > +BOOLEAN mExportFlag =3D FALSE; >=20 >=20 >=20 > STATIC >=20 > EFI_STATUS >=20 > @@ -279,6 +279,10 @@ Returns: > except for -o or -r option. It is a action > option.\n\ >=20 > If it is combined with other action options, = the > later\n\ >=20 > input action option will override the = previous > one.\n"); >=20 > + fprintf (stdout, " --prm Scan symbol section from > ELF image and \n\ >=20 > + write export table into PE-COFF.\n\ >=20 > + This option can be used together with -e.\n\ >=20 > + It doesn't work for other options.\n"); >=20 > fprintf (stdout, " -v, --verbose Turn on verbose output = with > informational messages.\n"); >=20 > fprintf (stdout, " -q, --quiet Disable all messages = except key > message and fatal error\n"); >=20 > fprintf (stdout, " -d, --debug level Enable debug messages, at input > debug level.\n"); >=20 > @@ -1436,6 +1440,20 @@ Returns: > continue; >=20 > } >=20 >=20 >=20 > + if (stricmp (argv[0], "--prm") =3D=3D 0) { >=20 > + if (stricmp (ModuleType, "DXE_RUNTIME_DRIVER") !=3D 0 ){ >=20 > + Error (NULL, 0, 1001, "Invalid", "--prm option only supports = DXE > RUNTIME driver."); >=20 > + goto Finish; >=20 > + } >=20 > + >=20 > + if (!mExportFlag) { >=20 > + mExportFlag =3D TRUE; >=20 > + } >=20 > + argc --; >=20 > + argv ++; >=20 > + continue; >=20 > + } >=20 > + >=20 > if (argv[0][0] =3D=3D '-') { >=20 > Error (NULL, 0, 1000, "Unknown option", argv[0]); >=20 > goto Finish; >=20 > diff --git a/BaseTools/Source/C/Include/IndustryStandard/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; >=20 > } EFI_IMAGE_EXPORT_DIRECTORY; >=20 >=20 >=20 > +// >=20 > +// Based export types. >=20 > +// >=20 > +#define EFI_IMAGE_EXPORT_ORDINAL_BASE 1 >=20 > +#define EFI_IMAGE_EXPORT_ADDR_SIZE 4 >=20 > +#define EFI_IMAGE_EXPORT_ORDINAL_SIZE 2 >=20 > + >=20 > /// >=20 > /// DLL support. >=20 > /// Import Format >=20 > -- > 2.26.2.windows.1 >=20 >=20 >=20 > -=3D-=3D-=3D-=3D-=3D-=3D > Groups.io Links: You receive all messages sent to this group. > View/Reply Online (#87040): = https://edk2.groups.io/g/devel/message/87040 > Mute This Topic: https://groups.io/mt/89441499/4905953 > Group Owner: devel+owner@edk2.groups.io > Unsubscribe: https://edk2.groups.io/g/devel/unsub > [gaoliming@byosoft.com.cn] > -=3D-=3D-=3D-=3D-=3D-=3D >=20