Update FwImage to zero .xdata information if the image type is X64 and all debug information has been stripped.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1659 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
mdkinney 2006-10-04 23:02:50 +00:00
parent 9bae46a555
commit 307fd19702
1 changed files with 17 additions and 22 deletions

View File

@ -164,12 +164,16 @@ Returns:
EFI_IMAGE_DOS_HEADER BackupDosHdr;
ULONG Index;
ULONG Index1;
ULONG Index2;
ULONG Index3;
BOOLEAN TimeStampPresent;
UINTN AllignedRelocSize;
UINTN Delta;
EFI_IMAGE_SECTION_HEADER *SectionHeader;
UINT8 *FileBuffer;
UINTN FileLength;
RUNTIME_FUNCTION *RuntimeFunction;
UNWIND_INFO *UnwindInfo;
SetUtilityName (UTILITY_NAME);
//
@ -373,26 +377,6 @@ Returns:
Optional32->SizeOfHeapReserve = 0;
Optional32->SizeOfHeapCommit = 0;
//
// Zero the .pdata section if the machine type is X64 and the Debug Directoty entry is empty
//
if (PeHdr->FileHeader.Machine == 0x8664) { // X64
if (Optional32->NumberOfRvaAndSizes >= 4) {
if (Optional32->NumberOfRvaAndSizes < 7 || (Optional32->NumberOfRvaAndSizes >= 7 && Optional32->DataDirectory[6].Size == 0)) {
SectionHeader = (EFI_IMAGE_SECTION_HEADER *)(FileBuffer + DosHdr->e_lfanew + sizeof(UINT32) + sizeof (EFI_IMAGE_FILE_HEADER) + PeHdr->FileHeader.SizeOfOptionalHeader);
for (Index = 0; Index < PeHdr->FileHeader.NumberOfSections; Index++, SectionHeader++) {
if (SectionHeader->VirtualAddress == Optional32->DataDirectory[3].VirtualAddress) {
for (Index1 = 0; Index1 < Optional32->DataDirectory[3].Size; Index1++) {
FileBuffer[SectionHeader->PointerToRawData + Index1] = 0;
}
}
}
Optional32->DataDirectory[3].Size = 0;
Optional32->DataDirectory[3].VirtualAddress = 0;
}
}
}
//
// Strip zero padding at the end of the .reloc section
//
@ -454,8 +438,19 @@ Returns:
SectionHeader = (EFI_IMAGE_SECTION_HEADER *)(FileBuffer + DosHdr->e_lfanew + sizeof(UINT32) + sizeof (EFI_IMAGE_FILE_HEADER) + PeHdr->FileHeader.SizeOfOptionalHeader);
for (Index = 0; Index < PeHdr->FileHeader.NumberOfSections; Index++, SectionHeader++) {
if (SectionHeader->VirtualAddress == Optional64->DataDirectory[3].VirtualAddress) {
for (Index1 = 0; Index1 < Optional64->DataDirectory[3].Size; Index1++) {
FileBuffer[SectionHeader->PointerToRawData + Index1] = 0;
RuntimeFunction = (RUNTIME_FUNCTION *)(FileBuffer + SectionHeader->PointerToRawData);
for (Index1 = 0; Index1 < Optional64->DataDirectory[3].Size / sizeof (RUNTIME_FUNCTION); Index1++, RuntimeFunction++) {
SectionHeader = (EFI_IMAGE_SECTION_HEADER *)(FileBuffer + DosHdr->e_lfanew + sizeof(UINT32) + sizeof (EFI_IMAGE_FILE_HEADER) + PeHdr->FileHeader.SizeOfOptionalHeader);
for (Index2 = 0; Index2 < PeHdr->FileHeader.NumberOfSections; Index2++, SectionHeader++) {
if (RuntimeFunction->UnwindInfoAddress > SectionHeader->VirtualAddress && RuntimeFunction->UnwindInfoAddress < (SectionHeader->VirtualAddress + SectionHeader->SizeOfRawData)) {
UnwindInfo = (UNWIND_INFO *)(FileBuffer + SectionHeader->PointerToRawData + (RuntimeFunction->UnwindInfoAddress - SectionHeader->VirtualAddress));
if (UnwindInfo->Version == 1) {
memset (UnwindInfo + 1, 0, UnwindInfo->CountOfUnwindCodes * sizeof (UINT16));
memset (UnwindInfo, 0, sizeof (UNWIND_INFO));
}
}
}
memset (RuntimeFunction, 0, sizeof (RUNTIME_FUNCTION));
}
}
}