X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FC%2FGenFw%2FElf32Convert.c;h=af5ff9396ecf7c06656b057ee3f4f23e5d179621;hp=97c9380c8dc21cbbc1c56230abf7816c8f81887f;hb=f7496d717357b9af78414d19679b073403812340;hpb=f51461c829c124288a930829a78e2a5a799f4039
diff --git a/BaseTools/Source/C/GenFw/Elf32Convert.c b/BaseTools/Source/C/GenFw/Elf32Convert.c
index 97c9380c8d..af5ff9396e 100644
--- a/BaseTools/Source/C/GenFw/Elf32Convert.c
+++ b/BaseTools/Source/C/GenFw/Elf32Convert.c
@@ -1,6 +1,7 @@
/** @file
+Elf32 Convert solution
-Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.
+Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.
Portions copyright (c) 2013, ARM Ltd. All rights reserved.
This program and the accompanying materials are licensed and made available
@@ -95,12 +96,12 @@ STATIC Elf_Phdr *mPhdrBase;
//
// Coff information
//
-STATIC const UINT32 mCoffAlignment = 0x20;
+STATIC UINT32 mCoffAlignment = 0x20;
//
// PE section alignment.
//
-STATIC const UINT16 mCoffNbrSections = 5;
+STATIC const UINT16 mCoffNbrSections = 4;
//
// ELF sections to offset in Coff file.
@@ -115,6 +116,7 @@ STATIC UINT32 mTextOffset;
STATIC UINT32 mDataOffset;
STATIC UINT32 mHiiRsrcOffset;
STATIC UINT32 mRelocOffset;
+STATIC UINT32 mDebugOffset;
//
// Initialization Function
@@ -128,7 +130,7 @@ InitializeElf32 (
//
// Initialize data pointer and structures.
//
- mEhdr = (Elf_Ehdr*) FileBuffer;
+ mEhdr = (Elf_Ehdr*) FileBuffer;
//
// Check the ELF32 specific header information.
@@ -140,12 +142,12 @@ InitializeElf32 (
if (mEhdr->e_ident[EI_DATA] != ELFDATA2LSB) {
Error (NULL, 0, 3000, "Unsupported", "ELF EI_DATA not ELFDATA2LSB");
return FALSE;
- }
+ }
if ((mEhdr->e_type != ET_EXEC) && (mEhdr->e_type != ET_DYN)) {
Error (NULL, 0, 3000, "Unsupported", "ELF e_type not ET_EXEC or ET_DYN");
return FALSE;
}
- if (!((mEhdr->e_machine == EM_386) || (mEhdr->e_machine == EM_ARM))) {
+ if (!((mEhdr->e_machine == EM_386) || (mEhdr->e_machine == EM_ARM))) {
Error (NULL, 0, 3000, "Unsupported", "ELF e_machine not EM_386 or EM_ARM");
return FALSE;
}
@@ -153,17 +155,21 @@ InitializeElf32 (
Error (NULL, 0, 3000, "Unsupported", "ELF e_version (%u) not EV_CURRENT (%d)", (unsigned) mEhdr->e_version, EV_CURRENT);
return FALSE;
}
-
+
//
// Update section header pointers
//
mShdrBase = (Elf_Shdr *)((UINT8 *)mEhdr + mEhdr->e_shoff);
mPhdrBase = (Elf_Phdr *)((UINT8 *)mEhdr + mEhdr->e_phoff);
-
+
//
// Create COFF Section offset buffer and zero.
//
mCoffSectionsOffset = (UINT32 *)malloc(mEhdr->e_shnum * sizeof (UINT32));
+ if (mCoffSectionsOffset == NULL) {
+ Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");
+ return FALSE;
+ }
memset(mCoffSectionsOffset, 0, mEhdr->e_shnum * sizeof(UINT32));
//
@@ -189,8 +195,11 @@ GetShdrByIndex (
UINT32 Num
)
{
- if (Num >= mEhdr->e_shnum)
- return NULL;
+ if (Num >= mEhdr->e_shnum) {
+ Error (NULL, 0, 3000, "Invalid", "GetShdrByIndex: Index %u is too high.", Num);
+ exit(EXIT_FAILURE);
+ }
+
return (Elf_Shdr*)((UINT8*)mShdrBase + Num * mEhdr->e_shentsize);
}
@@ -201,7 +210,8 @@ GetPhdrByIndex (
)
{
if (num >= mEhdr->e_phnum) {
- return NULL;
+ Error (NULL, 0, 3000, "Invalid", "GetPhdrByIndex: Index %u is too high.", num);
+ exit(EXIT_FAILURE);
}
return (Elf_Phdr *)((UINT8*)mPhdrBase + num * mEhdr->e_phentsize);
@@ -216,6 +226,15 @@ CoffAlign (
return (Offset + mCoffAlignment - 1) & ~(mCoffAlignment - 1);
}
+STATIC
+UINT32
+DebugRvaAlign (
+ UINT32 Offset
+ )
+{
+ return (Offset + 3) & ~3;
+}
+
//
// filter functions
//
@@ -251,6 +270,66 @@ IsDataShdr (
return (BOOLEAN) (Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) == (SHF_ALLOC | SHF_WRITE);
}
+STATIC
+BOOLEAN
+IsStrtabShdr (
+ Elf_Shdr *Shdr
+ )
+{
+ Elf_Shdr *Namedr = GetShdrByIndex(mEhdr->e_shstrndx);
+
+ return (BOOLEAN) (strcmp((CHAR8*)mEhdr + Namedr->sh_offset + Shdr->sh_name, ELF_STRTAB_SECTION_NAME) == 0);
+}
+
+STATIC
+Elf_Shdr *
+FindStrtabShdr (
+ VOID
+ )
+{
+ UINT32 i;
+ for (i = 0; i < mEhdr->e_shnum; i++) {
+ Elf_Shdr *shdr = GetShdrByIndex(i);
+ if (IsStrtabShdr(shdr)) {
+ return shdr;
+ }
+ }
+ return NULL;
+}
+
+STATIC
+const UINT8 *
+GetSymName (
+ Elf_Sym *Sym
+ )
+{
+ Elf_Shdr *StrtabShdr;
+ UINT8 *StrtabContents;
+ BOOLEAN foundEnd;
+ UINT32 i;
+
+ if (Sym->st_name == 0) {
+ return NULL;
+ }
+
+ StrtabShdr = FindStrtabShdr();
+ if (StrtabShdr == NULL) {
+ return NULL;
+ }
+
+ assert(Sym->st_name < StrtabShdr->sh_size);
+
+ StrtabContents = (UINT8*)mEhdr + StrtabShdr->sh_offset;
+
+ foundEnd = FALSE;
+ for (i = Sym->st_name; (i < StrtabShdr->sh_size) && !foundEnd; i++) {
+ foundEnd = (BOOLEAN)(StrtabContents[i] == 0);
+ }
+ assert(foundEnd);
+
+ return StrtabContents + Sym->st_name;
+}
+
//
// Elf functions interface implementation
//
@@ -266,12 +345,10 @@ ScanSections32 (
EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr;
UINT32 CoffEntry;
UINT32 SectionCount;
- BOOLEAN FoundText;
+ BOOLEAN FoundSection;
CoffEntry = 0;
mCoffOffset = 0;
- mTextOffset = 0;
- FoundText = FALSE;
//
// Coff file start with a DOS header.
@@ -292,10 +369,44 @@ ScanSections32 (
mTableOffset = mCoffOffset;
mCoffOffset += mCoffNbrSections * sizeof(EFI_IMAGE_SECTION_HEADER);
+ //
+ // Set mCoffAlignment to the maximum alignment of the input sections
+ // we care about
+ //
+ for (i = 0; i < mEhdr->e_shnum; i++) {
+ Elf_Shdr *shdr = GetShdrByIndex(i);
+ if (shdr->sh_addralign <= mCoffAlignment) {
+ continue;
+ }
+ if (IsTextShdr(shdr) || IsDataShdr(shdr) || IsHiiRsrcShdr(shdr)) {
+ mCoffAlignment = (UINT32)shdr->sh_addralign;
+ }
+ }
+
+ //
+ // Check if mCoffAlignment is larger than MAX_COFF_ALIGNMENT
+ //
+ if (mCoffAlignment > MAX_COFF_ALIGNMENT) {
+ Error (NULL, 0, 3000, "Invalid", "Section alignment is larger than MAX_COFF_ALIGNMENT.");
+ assert (FALSE);
+ }
+
+ //
+ // Move the PE/COFF header right before the first section. This will help us
+ // save space when converting to TE.
+ //
+ if (mCoffAlignment > mCoffOffset) {
+ mNtHdrOffset += mCoffAlignment - mCoffOffset;
+ mTableOffset += mCoffAlignment - mCoffOffset;
+ mCoffOffset = mCoffAlignment;
+ }
+
//
// First text sections.
//
mCoffOffset = CoffAlign(mCoffOffset);
+ mTextOffset = mCoffOffset;
+ FoundSection = FALSE;
SectionCount = 0;
for (i = 0; i < mEhdr->e_shnum; i++) {
Elf_Shdr *shdr = GetShdrByIndex(i);
@@ -305,12 +416,8 @@ ScanSections32 (
if ((shdr->sh_addr & (shdr->sh_addralign - 1)) == 0) {
// if the section address is aligned we must align PE/COFF
mCoffOffset = (mCoffOffset + shdr->sh_addralign - 1) & ~(shdr->sh_addralign - 1);
- } else if ((shdr->sh_addr % shdr->sh_addralign) != (mCoffOffset % shdr->sh_addralign)) {
- // ARM RVCT tools have behavior outside of the ELF specification to try
- // and make images smaller. If sh_addr is not aligned to sh_addralign
- // then the section needs to preserve sh_addr MOD sh_addralign.
- // Normally doing nothing here works great.
- Error (NULL, 0, 3000, "Invalid", "Unsupported section alignment.");
+ } else {
+ Error (NULL, 0, 3000, "Invalid", "Section address not aligned to its own alignment.");
}
}
@@ -323,9 +430,9 @@ ScanSections32 (
//
// Set mTextOffset with the offset of the first '.text' section
//
- if (!FoundText) {
+ if (!FoundSection) {
mTextOffset = mCoffOffset;
- FoundText = TRUE;
+ FoundSection = TRUE;
}
mCoffSectionsOffset[i] = mCoffOffset;
@@ -334,14 +441,13 @@ ScanSections32 (
}
}
- if (!FoundText) {
+ if (!FoundSection) {
Error (NULL, 0, 3000, "Invalid", "Did not find any '.text' section.");
assert (FALSE);
}
- if (mEhdr->e_machine != EM_ARM) {
- mCoffOffset = CoffAlign(mCoffOffset);
- }
+ mDebugOffset = DebugRvaAlign(mCoffOffset);
+ mCoffOffset = CoffAlign(mCoffOffset);
if (SectionCount > 1 && mOutImageType == FW_EFI_IMAGE) {
Warning (NULL, 0, 0, NULL, "Mulitple sections in %s are merged into 1 text section. Source level debug might not work correctly.", mInImageName);
@@ -351,6 +457,7 @@ ScanSections32 (
// Then data sections.
//
mDataOffset = mCoffOffset;
+ FoundSection = FALSE;
SectionCount = 0;
for (i = 0; i < mEhdr->e_shnum; i++) {
Elf_Shdr *shdr = GetShdrByIndex(i);
@@ -360,25 +467,47 @@ ScanSections32 (
if ((shdr->sh_addr & (shdr->sh_addralign - 1)) == 0) {
// if the section address is aligned we must align PE/COFF
mCoffOffset = (mCoffOffset + shdr->sh_addralign - 1) & ~(shdr->sh_addralign - 1);
- } else if ((shdr->sh_addr % shdr->sh_addralign) != (mCoffOffset % shdr->sh_addralign)) {
- // ARM RVCT tools have behavior outside of the ELF specification to try
- // and make images smaller. If sh_addr is not aligned to sh_addralign
- // then the section needs to preserve sh_addr MOD sh_addralign.
- // Normally doing nothing here works great.
- Error (NULL, 0, 3000, "Invalid", "Unsupported section alignment.");
+ } else {
+ Error (NULL, 0, 3000, "Invalid", "Section address not aligned to its own alignment.");
}
}
+
+ //
+ // Set mDataOffset with the offset of the first '.data' section
+ //
+ if (!FoundSection) {
+ mDataOffset = mCoffOffset;
+ FoundSection = TRUE;
+ }
+
mCoffSectionsOffset[i] = mCoffOffset;
mCoffOffset += shdr->sh_size;
SectionCount ++;
}
}
- mCoffOffset = CoffAlign(mCoffOffset);
if (SectionCount > 1 && mOutImageType == FW_EFI_IMAGE) {
Warning (NULL, 0, 0, NULL, "Mulitple sections in %s are merged into 1 data section. Source level debug might not work correctly.", mInImageName);
}
+ //
+ // Make room for .debug data in .data (or .text if .data is empty) instead of
+ // putting it in a section of its own. This is explicitly allowed by the
+ // PE/COFF spec, and prevents bloat in the binary when using large values for
+ // section alignment.
+ //
+ if (SectionCount > 0) {
+ mDebugOffset = DebugRvaAlign(mCoffOffset);
+ }
+ mCoffOffset = mDebugOffset + sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY) +
+ sizeof(EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY) +
+ strlen(mInImageName) + 1;
+
+ mCoffOffset = CoffAlign(mCoffOffset);
+ if (SectionCount == 0) {
+ mDataOffset = mCoffOffset;
+ }
+
//
// The HII resource sections.
//
@@ -391,15 +520,12 @@ ScanSections32 (
if ((shdr->sh_addr & (shdr->sh_addralign - 1)) == 0) {
// if the section address is aligned we must align PE/COFF
mCoffOffset = (mCoffOffset + shdr->sh_addralign - 1) & ~(shdr->sh_addralign - 1);
- } else if ((shdr->sh_addr % shdr->sh_addralign) != (mCoffOffset % shdr->sh_addralign)) {
- // ARM RVCT tools have behavior outside of the ELF specification to try
- // and make images smaller. If sh_addr is not aligned to sh_addralign
- // then the section needs to preserve sh_addr MOD sh_addralign.
- // Normally doing nothing here works great.
- Error (NULL, 0, 3000, "Invalid", "Unsupported section alignment.");
+ } else {
+ Error (NULL, 0, 3000, "Invalid", "Section address not aligned to its own alignment.");
}
}
if (shdr->sh_size != 0) {
+ mHiiRsrcOffset = mCoffOffset;
mCoffSectionsOffset[i] = mCoffOffset;
mCoffOffset += shdr->sh_size;
mCoffOffset = CoffAlign(mCoffOffset);
@@ -415,6 +541,10 @@ ScanSections32 (
// Allocate base Coff file. Will be expanded later for relocations.
//
mCoffFile = (UINT8 *)malloc(mCoffOffset);
+ if (mCoffFile == NULL) {
+ Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");
+ }
+ assert (mCoffFile != NULL);
memset(mCoffFile, 0, mCoffOffset);
//
@@ -438,7 +568,7 @@ ScanSections32 (
NtHdr->Pe32.OptionalHeader.Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC;
break;
default:
- VerboseMsg ("%s unknown e_machine type. Assume IA-32", (UINTN)mEhdr->e_machine);
+ VerboseMsg ("%s unknown e_machine type %hu. Assume IA-32", mInImageName, mEhdr->e_machine);
NtHdr->Pe32.FileHeader.Machine = EFI_IMAGE_MACHINE_IA32;
NtHdr->Pe32.OptionalHeader.Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC;
}
@@ -544,6 +674,9 @@ WriteSections32 (
switch (Shdr->sh_type) {
case SHT_PROGBITS:
/* Copy. */
+ if (Shdr->sh_offset + Shdr->sh_size > mFileBufferSize) {
+ return FALSE;
+ }
memcpy(mCoffFile + mCoffSectionsOffset[Idx],
(UINT8*)mEhdr + Shdr->sh_offset,
Shdr->sh_size);
@@ -574,20 +707,20 @@ WriteSections32 (
if ((RelShdr->sh_type != SHT_REL) && (RelShdr->sh_type != SHT_RELA)) {
continue;
}
-
+
//
// Relocation section found. Now extract section information that the relocations
// apply to in the ELF data and the new COFF data.
//
SecShdr = GetShdrByIndex(RelShdr->sh_info);
SecOffset = mCoffSectionsOffset[RelShdr->sh_info];
-
+
//
// Only process relocations for the current filter type.
//
if (RelShdr->sh_type == SHT_REL && (*Filter)(SecShdr)) {
UINT32 RelOffset;
-
+
//
// Determine the symbol table referenced by the relocation data.
//
@@ -602,31 +735,40 @@ WriteSections32 (
// Set pointer to relocation entry
//
Elf_Rel *Rel = (Elf_Rel *)((UINT8*)mEhdr + RelShdr->sh_offset + RelOffset);
-
+
//
// Set pointer to symbol table entry associated with the relocation entry.
//
Elf_Sym *Sym = (Elf_Sym *)(Symtab + ELF_R_SYM(Rel->r_info) * SymtabShdr->sh_entsize);
-
+
Elf_Shdr *SymShdr;
UINT8 *Targ;
UINT16 Address;
//
- // Check section header index found in symbol table and get the section
+ // Check section header index found in symbol table and get the section
// header location.
//
if (Sym->st_shndx == SHN_UNDEF
- || Sym->st_shndx == SHN_ABS
- || Sym->st_shndx > mEhdr->e_shnum) {
- Error (NULL, 0, 3000, "Invalid", "%s bad symbol definition.", mInImageName);
+ || Sym->st_shndx >= mEhdr->e_shnum) {
+ const UINT8 *SymName = GetSymName(Sym);
+ if (SymName == NULL) {
+ SymName = (const UINT8 *)"";
+ }
+
+ Error (NULL, 0, 3000, "Invalid",
+ "%s: Bad definition for symbol '%s'@%#x or unsupported symbol type. "
+ "For example, absolute and undefined symbols are not supported.",
+ mInImageName, SymName, Sym->st_value);
+
+ exit(EXIT_FAILURE);
}
SymShdr = GetShdrByIndex(Sym->st_shndx);
//
// Convert the relocation data to a pointer into the coff file.
//
- // Note:
+ // Note:
// r_offset is the virtual address of the storage unit to be relocated.
// sh_addr is the virtual address for the base of the section.
//
@@ -666,14 +808,15 @@ WriteSections32 (
// break skipped
case R_ARM_PC24:
+ case R_ARM_REL32:
case R_ARM_XPC25:
case R_ARM_THM_PC22:
case R_ARM_THM_JUMP19:
case R_ARM_CALL:
case R_ARM_JMP24:
- case R_ARM_THM_JUMP24:
- case R_ARM_PREL31:
- case R_ARM_MOVW_PREL_NC:
+ case R_ARM_THM_JUMP24:
+ case R_ARM_PREL31:
+ case R_ARM_MOVW_PREL_NC:
case R_ARM_MOVT_PREL:
case R_ARM_THM_MOVW_PREL_NC:
case R_ARM_THM_MOVT_PREL:
@@ -753,9 +896,7 @@ WriteRelocations32 (
UINTN RelSize;
UINTN RelOffset;
UINTN K;
- UINT8 *Targ;
Elf32_Phdr *DynamicSegment;
- Elf32_Phdr *TargetSegment;
for (Index = 0, FoundRelocations = FALSE; Index < mEhdr->e_shnum; Index++) {
Elf_Shdr *RelShdr = GetShdrByIndex(Index);
@@ -766,9 +907,9 @@ WriteRelocations32 (
FoundRelocations = TRUE;
for (RelIdx = 0; RelIdx < RelShdr->sh_size; RelIdx += RelShdr->sh_entsize) {
- Elf_Rel *Rel = (Elf_Rel *)((UINT8*)mEhdr + RelShdr->sh_offset + RelIdx);
+ Rel = (Elf_Rel *)((UINT8*)mEhdr + RelShdr->sh_offset + RelIdx);
- if (mEhdr->e_machine == EM_386) {
+ if (mEhdr->e_machine == EM_386) {
switch (ELF_R_TYPE(Rel->r_info)) {
case R_386_NONE:
case R_386_PC32:
@@ -794,14 +935,15 @@ WriteRelocations32 (
// break skipped
case R_ARM_PC24:
+ case R_ARM_REL32:
case R_ARM_XPC25:
case R_ARM_THM_PC22:
case R_ARM_THM_JUMP19:
case R_ARM_CALL:
case R_ARM_JMP24:
- case R_ARM_THM_JUMP24:
- case R_ARM_PREL31:
- case R_ARM_MOVW_PREL_NC:
+ case R_ARM_THM_JUMP24:
+ case R_ARM_PREL31:
+ case R_ARM_MOVW_PREL_NC:
case R_ARM_MOVT_PREL:
case R_ARM_THM_MOVW_PREL_NC:
case R_ARM_THM_MOVT_PREL:
@@ -905,6 +1047,31 @@ WriteRelocations32 (
Error (NULL, 0, 3000, "Invalid", "%s bad ARM dynamic relocations.", mInImageName);
}
+ for (Index = 0; Index < mEhdr->e_shnum; Index++) {
+ Elf_Shdr *shdr = GetShdrByIndex(Index);
+
+ //
+ // The PT_DYNAMIC section contains DT_REL relocations whose r_offset
+ // field is relative to the base of a segment (or the entire image),
+ // and not to the base of an ELF input section as is the case for
+ // SHT_REL sections. This means that we cannot fix up such relocations
+ // unless we cross-reference ELF sections and segments, considering
+ // that the output placement recorded in mCoffSectionsOffset[] is
+ // section based, not segment based.
+ //
+ // Fortunately, there is a simple way around this: we require that the
+ // in-memory layout of the ELF and PE/COFF versions of the binary is
+ // identical. That way, r_offset will retain its validity as a PE/COFF
+ // image offset, and we can record it in the COFF fixup table
+ // unmodified.
+ //
+ if (shdr->sh_addr != mCoffSectionsOffset[Index]) {
+ Error (NULL, 0, 3000,
+ "Invalid", "%s: PT_DYNAMIC relocations require identical ELF and PE/COFF section offsets.",
+ mInImageName);
+ }
+ }
+
for (K = 0; K < RelSize; K += RelElementSize) {
if (DynamicSegment->p_paddr == 0) {
@@ -921,16 +1088,9 @@ WriteRelocations32 (
break;
case R_ARM_RABS32:
- TargetSegment = GetPhdrByIndex (ELF32_R_SYM (Rel->r_info) - 1);
-
- // Note: r_offset in a memory address. Convert it to a pointer in the coff file.
- Targ = mCoffFile + mCoffSectionsOffset[ ELF32_R_SYM( Rel->r_info ) ] + Rel->r_offset - TargetSegment->p_vaddr;
-
- *(UINT32 *)Targ = *(UINT32 *)Targ + mCoffSectionsOffset [ELF32_R_SYM( Rel->r_info )];
-
- CoffAddFixup (mCoffSectionsOffset[ELF32_R_SYM (Rel->r_info)] + (Rel->r_offset - TargetSegment->p_vaddr), EFI_IMAGE_REL_BASED_HIGHLOW);
+ CoffAddFixup (Rel->r_offset, EFI_IMAGE_REL_BASED_HIGHLOW);
break;
-
+
default:
Error (NULL, 0, 3000, "Invalid", "%s bad ARM dynamic relocations, unkown type %d.", mInImageName, ELF32_R_TYPE (Rel->r_info));
break;
@@ -972,28 +1132,18 @@ WriteDebug32 (
)
{
UINT32 Len;
- UINT32 DebugOffset;
EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr;
EFI_IMAGE_DATA_DIRECTORY *DataDir;
EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *Dir;
EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY *Nb10;
Len = strlen(mInImageName) + 1;
- DebugOffset = mCoffOffset;
- mCoffOffset += sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY)
- + sizeof(EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY)
- + Len;
- mCoffOffset = CoffAlign(mCoffOffset);
-
- mCoffFile = realloc(mCoffFile, mCoffOffset);
- memset(mCoffFile + DebugOffset, 0, mCoffOffset - DebugOffset);
-
- Dir = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY*)(mCoffFile + DebugOffset);
+ Dir = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY*)(mCoffFile + mDebugOffset);
Dir->Type = EFI_IMAGE_DEBUG_TYPE_CODEVIEW;
Dir->SizeOfData = sizeof(EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY) + Len;
- Dir->RVA = DebugOffset + sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY);
- Dir->FileOffset = DebugOffset + sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY);
+ Dir->RVA = mDebugOffset + sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY);
+ Dir->FileOffset = mDebugOffset + sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY);
Nb10 = (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY*)(Dir + 1);
Nb10->Signature = CODEVIEW_SIGNATURE_NB10;
@@ -1002,20 +1152,8 @@ WriteDebug32 (
NtHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)(mCoffFile + mNtHdrOffset);
DataDir = &NtHdr->Pe32.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG];
- DataDir->VirtualAddress = DebugOffset;
- DataDir->Size = mCoffOffset - DebugOffset;
- if (DataDir->Size == 0) {
- // If no debug, null out the directory entry and don't add the .debug section
- DataDir->VirtualAddress = 0;
- NtHdr->Pe32.FileHeader.NumberOfSections--;
- } else {
- DataDir->VirtualAddress = DebugOffset;
- CreateSectionHeader (".debug", DebugOffset, mCoffOffset - DebugOffset,
- EFI_IMAGE_SCN_CNT_INITIALIZED_DATA
- | EFI_IMAGE_SCN_MEM_DISCARDABLE
- | EFI_IMAGE_SCN_MEM_READ);
-
- }
+ DataDir->VirtualAddress = mDebugOffset;
+ DataDir->Size = sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY);
}
STATIC
@@ -1025,7 +1163,7 @@ SetImageSize32 (
)
{
EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr;
-
+
//
// Set image size
//