diff options
author | Erik Bjorge <erik.c.bjorge@intel.com> | 2015-02-11 08:20:17 +0000 |
---|---|---|
committer | lgao4 <lgao4@Edk2> | 2015-02-11 08:20:17 +0000 |
commit | 234f9ff96e2179e552463dd09ccc515b1c4a6119 (patch) | |
tree | 2762eaa78cb51d115ad56f4340540f0bc9e1fb81 /BaseTools/Source | |
parent | d8043ce905a5832f911361ef30be28765afbdc6b (diff) | |
download | edk2-platforms-234f9ff96e2179e552463dd09ccc515b1c4a6119.tar.xz |
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
Diffstat (limited to 'BaseTools/Source')
-rw-r--r-- | BaseTools/Source/C/GenFw/Elf32Convert.c | 23 | ||||
-rw-r--r-- | BaseTools/Source/C/GenFw/Elf64Convert.c | 22 |
2 files changed, 33 insertions, 12 deletions
diff --git a/BaseTools/Source/C/GenFw/Elf32Convert.c b/BaseTools/Source/C/GenFw/Elf32Convert.c index 85e8ba6614..5c7b689ee8 100644 --- a/BaseTools/Source/C/GenFw/Elf32Convert.c +++ b/BaseTools/Source/C/GenFw/Elf32Convert.c @@ -267,12 +267,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.
@@ -297,6 +295,8 @@ ScanSections32 ( // 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);
@@ -324,9 +324,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;
@@ -335,7 +335,7 @@ ScanSections32 ( }
}
- if (!FoundText) {
+ if (!FoundSection) {
Error (NULL, 0, 3000, "Invalid", "Did not find any '.text' section.");
assert (FALSE);
}
@@ -352,6 +352,7 @@ ScanSections32 ( // Then data sections.
//
mDataOffset = mCoffOffset;
+ FoundSection = FALSE;
SectionCount = 0;
for (i = 0; i < mEhdr->e_shnum; i++) {
Elf_Shdr *shdr = GetShdrByIndex(i);
@@ -369,6 +370,15 @@ ScanSections32 ( 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;
mCoffOffset += shdr->sh_size;
SectionCount ++;
@@ -401,6 +411,7 @@ ScanSections32 ( }
}
if (shdr->sh_size != 0) {
+ mHiiRsrcOffset = mCoffOffset;
mCoffSectionsOffset[i] = mCoffOffset;
mCoffOffset += shdr->sh_size;
mCoffOffset = CoffAlign(mCoffOffset);
diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/GenFw/Elf64Convert.c index 290f04cb98..25b90e2f7b 100644 --- a/BaseTools/Source/C/GenFw/Elf64Convert.c +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c @@ -260,12 +260,10 @@ ScanSections64 ( 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.
@@ -291,6 +289,8 @@ ScanSections64 ( // 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);
@@ -318,9 +318,9 @@ ScanSections64 ( //
// Set mTextOffset with the offset of the first '.text' section
//
- if (!FoundText) {
+ if (!FoundSection) {
mTextOffset = mCoffOffset;
- FoundText = TRUE;
+ FoundSection = TRUE;
}
mCoffSectionsOffset[i] = mCoffOffset;
@@ -329,7 +329,7 @@ ScanSections64 ( }
}
- if (!FoundText) {
+ if (!FoundSection) {
Error (NULL, 0, 3000, "Invalid", "Did not find any '.text' section.");
assert (FALSE);
}
@@ -346,6 +346,7 @@ ScanSections64 ( // Then data sections.
//
mDataOffset = mCoffOffset;
+ FoundSection = FALSE;
SectionCount = 0;
for (i = 0; i < mEhdr->e_shnum; i++) {
Elf_Shdr *shdr = GetShdrByIndex(i);
@@ -363,6 +364,14 @@ ScanSections64 ( 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;
mCoffOffset += (UINT32) shdr->sh_size;
SectionCount ++;
@@ -395,6 +404,7 @@ ScanSections64 ( }
}
if (shdr->sh_size != 0) {
+ mHiiRsrcOffset = mCoffOffset;
mCoffSectionsOffset[i] = mCoffOffset;
mCoffOffset += (UINT32) shdr->sh_size;
mCoffOffset = CoffAlign(mCoffOffset);
|