BaseTools/GenFw: Set the PE/COFF attribute BaseOfData with the address of the first '.data' section

Before this change the alignment of the first data section was not taken into account.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Erik Bjorge <erik.c.bjorge@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16831 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Erik Bjorge 2015-02-11 08:20:17 +00:00 committed by lgao4
parent d8043ce905
commit 234f9ff96e
2 changed files with 33 additions and 12 deletions

View File

@ -267,12 +267,10 @@ ScanSections32 (
EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr; EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr;
UINT32 CoffEntry; UINT32 CoffEntry;
UINT32 SectionCount; UINT32 SectionCount;
BOOLEAN FoundText; BOOLEAN FoundSection;
CoffEntry = 0; CoffEntry = 0;
mCoffOffset = 0; mCoffOffset = 0;
mTextOffset = 0;
FoundText = FALSE;
// //
// Coff file start with a DOS header. // Coff file start with a DOS header.
@ -297,6 +295,8 @@ ScanSections32 (
// First text sections. // First text sections.
// //
mCoffOffset = CoffAlign(mCoffOffset); mCoffOffset = CoffAlign(mCoffOffset);
mTextOffset = mCoffOffset;
FoundSection = FALSE;
SectionCount = 0; SectionCount = 0;
for (i = 0; i < mEhdr->e_shnum; i++) { for (i = 0; i < mEhdr->e_shnum; i++) {
Elf_Shdr *shdr = GetShdrByIndex(i); Elf_Shdr *shdr = GetShdrByIndex(i);
@ -324,9 +324,9 @@ ScanSections32 (
// //
// Set mTextOffset with the offset of the first '.text' section // Set mTextOffset with the offset of the first '.text' section
// //
if (!FoundText) { if (!FoundSection) {
mTextOffset = mCoffOffset; mTextOffset = mCoffOffset;
FoundText = TRUE; FoundSection = TRUE;
} }
mCoffSectionsOffset[i] = mCoffOffset; mCoffSectionsOffset[i] = mCoffOffset;
@ -335,7 +335,7 @@ ScanSections32 (
} }
} }
if (!FoundText) { if (!FoundSection) {
Error (NULL, 0, 3000, "Invalid", "Did not find any '.text' section."); Error (NULL, 0, 3000, "Invalid", "Did not find any '.text' section.");
assert (FALSE); assert (FALSE);
} }
@ -352,6 +352,7 @@ ScanSections32 (
// Then data sections. // Then data sections.
// //
mDataOffset = mCoffOffset; mDataOffset = mCoffOffset;
FoundSection = FALSE;
SectionCount = 0; SectionCount = 0;
for (i = 0; i < mEhdr->e_shnum; i++) { for (i = 0; i < mEhdr->e_shnum; i++) {
Elf_Shdr *shdr = GetShdrByIndex(i); Elf_Shdr *shdr = GetShdrByIndex(i);
@ -369,6 +370,15 @@ ScanSections32 (
Error (NULL, 0, 3000, "Invalid", "Unsupported section alignment."); Error (NULL, 0, 3000, "Invalid", "Unsupported section alignment.");
} }
} }
//
// Set mDataOffset with the offset of the first '.data' section
//
if (!FoundSection) {
mDataOffset = mCoffOffset;
FoundSection = TRUE;
}
mCoffSectionsOffset[i] = mCoffOffset; mCoffSectionsOffset[i] = mCoffOffset;
mCoffOffset += shdr->sh_size; mCoffOffset += shdr->sh_size;
SectionCount ++; SectionCount ++;
@ -401,6 +411,7 @@ ScanSections32 (
} }
} }
if (shdr->sh_size != 0) { if (shdr->sh_size != 0) {
mHiiRsrcOffset = mCoffOffset;
mCoffSectionsOffset[i] = mCoffOffset; mCoffSectionsOffset[i] = mCoffOffset;
mCoffOffset += shdr->sh_size; mCoffOffset += shdr->sh_size;
mCoffOffset = CoffAlign(mCoffOffset); mCoffOffset = CoffAlign(mCoffOffset);

View File

@ -260,12 +260,10 @@ ScanSections64 (
EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr; EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr;
UINT32 CoffEntry; UINT32 CoffEntry;
UINT32 SectionCount; UINT32 SectionCount;
BOOLEAN FoundText; BOOLEAN FoundSection;
CoffEntry = 0; CoffEntry = 0;
mCoffOffset = 0; mCoffOffset = 0;
mTextOffset = 0;
FoundText = FALSE;
// //
// Coff file start with a DOS header. // Coff file start with a DOS header.
@ -291,6 +289,8 @@ ScanSections64 (
// First text sections. // First text sections.
// //
mCoffOffset = CoffAlign(mCoffOffset); mCoffOffset = CoffAlign(mCoffOffset);
mTextOffset = mCoffOffset;
FoundSection = FALSE;
SectionCount = 0; SectionCount = 0;
for (i = 0; i < mEhdr->e_shnum; i++) { for (i = 0; i < mEhdr->e_shnum; i++) {
Elf_Shdr *shdr = GetShdrByIndex(i); Elf_Shdr *shdr = GetShdrByIndex(i);
@ -318,9 +318,9 @@ ScanSections64 (
// //
// Set mTextOffset with the offset of the first '.text' section // Set mTextOffset with the offset of the first '.text' section
// //
if (!FoundText) { if (!FoundSection) {
mTextOffset = mCoffOffset; mTextOffset = mCoffOffset;
FoundText = TRUE; FoundSection = TRUE;
} }
mCoffSectionsOffset[i] = mCoffOffset; mCoffSectionsOffset[i] = mCoffOffset;
@ -329,7 +329,7 @@ ScanSections64 (
} }
} }
if (!FoundText) { if (!FoundSection) {
Error (NULL, 0, 3000, "Invalid", "Did not find any '.text' section."); Error (NULL, 0, 3000, "Invalid", "Did not find any '.text' section.");
assert (FALSE); assert (FALSE);
} }
@ -346,6 +346,7 @@ ScanSections64 (
// Then data sections. // Then data sections.
// //
mDataOffset = mCoffOffset; mDataOffset = mCoffOffset;
FoundSection = FALSE;
SectionCount = 0; SectionCount = 0;
for (i = 0; i < mEhdr->e_shnum; i++) { for (i = 0; i < mEhdr->e_shnum; i++) {
Elf_Shdr *shdr = GetShdrByIndex(i); Elf_Shdr *shdr = GetShdrByIndex(i);
@ -363,6 +364,14 @@ ScanSections64 (
Error (NULL, 0, 3000, "Invalid", "Unsupported section alignment."); Error (NULL, 0, 3000, "Invalid", "Unsupported section alignment.");
} }
} }
//
// Set mDataOffset with the offset of the first '.data' section
//
if (!FoundSection) {
mDataOffset = mCoffOffset;
FoundSection = TRUE;
}
mCoffSectionsOffset[i] = mCoffOffset; mCoffSectionsOffset[i] = mCoffOffset;
mCoffOffset += (UINT32) shdr->sh_size; mCoffOffset += (UINT32) shdr->sh_size;
SectionCount ++; SectionCount ++;
@ -395,6 +404,7 @@ ScanSections64 (
} }
} }
if (shdr->sh_size != 0) { if (shdr->sh_size != 0) {
mHiiRsrcOffset = mCoffOffset;
mCoffSectionsOffset[i] = mCoffOffset; mCoffSectionsOffset[i] = mCoffOffset;
mCoffOffset += (UINT32) shdr->sh_size; mCoffOffset += (UINT32) shdr->sh_size;
mCoffOffset = CoffAlign(mCoffOffset); mCoffOffset = CoffAlign(mCoffOffset);