]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/GenFw: Set the PE/COFF attribute BaseOfData with the address of the first...
authorErik Bjorge <erik.c.bjorge@intel.com>
Wed, 11 Feb 2015 08:20:17 +0000 (08:20 +0000)
committerlgao4 <lgao4@Edk2>
Wed, 11 Feb 2015 08:20:17 +0000 (08:20 +0000)
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

BaseTools/Source/C/GenFw/Elf32Convert.c
BaseTools/Source/C/GenFw/Elf64Convert.c

index 85e8ba6614086e72411a2216033c8c782bbc0f9c..5c7b689ee868c182d6dded209f55347b00f91760 100644 (file)
@@ -267,12 +267,10 @@ ScanSections32 (
   EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr;\r
   UINT32                          CoffEntry;\r
   UINT32                          SectionCount;\r
-  BOOLEAN                         FoundText;\r
+  BOOLEAN                         FoundSection;\r
 \r
   CoffEntry = 0;\r
   mCoffOffset = 0;\r
-  mTextOffset = 0;\r
-  FoundText = FALSE;\r
 \r
   //\r
   // Coff file start with a DOS header.\r
@@ -297,6 +295,8 @@ ScanSections32 (
   // First text sections.\r
   //\r
   mCoffOffset = CoffAlign(mCoffOffset);\r
+  mTextOffset = mCoffOffset;\r
+  FoundSection = FALSE;\r
   SectionCount = 0;\r
   for (i = 0; i < mEhdr->e_shnum; i++) {\r
     Elf_Shdr *shdr = GetShdrByIndex(i);\r
@@ -324,9 +324,9 @@ ScanSections32 (
       //\r
       // Set mTextOffset with the offset of the first '.text' section\r
       //\r
-      if (!FoundText) {\r
+      if (!FoundSection) {\r
         mTextOffset = mCoffOffset;\r
-        FoundText = TRUE;\r
+        FoundSection = TRUE;\r
       }\r
 \r
       mCoffSectionsOffset[i] = mCoffOffset;\r
@@ -335,7 +335,7 @@ ScanSections32 (
     }\r
   }\r
 \r
-  if (!FoundText) {\r
+  if (!FoundSection) {\r
     Error (NULL, 0, 3000, "Invalid", "Did not find any '.text' section.");\r
     assert (FALSE);\r
   }\r
@@ -352,6 +352,7 @@ ScanSections32 (
   //  Then data sections.\r
   //\r
   mDataOffset = mCoffOffset;\r
+  FoundSection = FALSE;\r
   SectionCount = 0;\r
   for (i = 0; i < mEhdr->e_shnum; i++) {\r
     Elf_Shdr *shdr = GetShdrByIndex(i);\r
@@ -369,6 +370,15 @@ ScanSections32 (
           Error (NULL, 0, 3000, "Invalid", "Unsupported section alignment.");\r
         }\r
       }\r
+\r
+      //\r
+      // Set mDataOffset with the offset of the first '.data' section\r
+      //\r
+      if (!FoundSection) {\r
+        mDataOffset = mCoffOffset;\r
+        FoundSection = TRUE;\r
+      }\r
+\r
       mCoffSectionsOffset[i] = mCoffOffset;\r
       mCoffOffset += shdr->sh_size;\r
       SectionCount ++;\r
@@ -401,6 +411,7 @@ ScanSections32 (
         }\r
       }\r
       if (shdr->sh_size != 0) {\r
+        mHiiRsrcOffset = mCoffOffset;\r
         mCoffSectionsOffset[i] = mCoffOffset;\r
         mCoffOffset += shdr->sh_size;\r
         mCoffOffset = CoffAlign(mCoffOffset);\r
index 290f04cb9837ca88121b998a7c11753ff2b9513e..25b90e2f7b51089526bf1cbcad8a64b0a0b65f9b 100644 (file)
@@ -260,12 +260,10 @@ ScanSections64 (
   EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr;\r
   UINT32                          CoffEntry;\r
   UINT32                          SectionCount;\r
-  BOOLEAN                         FoundText;\r
+  BOOLEAN                         FoundSection;\r
 \r
   CoffEntry = 0;\r
   mCoffOffset = 0;\r
-  mTextOffset = 0;\r
-  FoundText = FALSE;\r
 \r
   //\r
   // Coff file start with a DOS header.\r
@@ -291,6 +289,8 @@ ScanSections64 (
   // First text sections.\r
   //\r
   mCoffOffset = CoffAlign(mCoffOffset);\r
+  mTextOffset = mCoffOffset;\r
+  FoundSection = FALSE;\r
   SectionCount = 0;\r
   for (i = 0; i < mEhdr->e_shnum; i++) {\r
     Elf_Shdr *shdr = GetShdrByIndex(i);\r
@@ -318,9 +318,9 @@ ScanSections64 (
       //\r
       // Set mTextOffset with the offset of the first '.text' section\r
       //\r
-      if (!FoundText) {\r
+      if (!FoundSection) {\r
         mTextOffset = mCoffOffset;\r
-        FoundText = TRUE;\r
+        FoundSection = TRUE;\r
       }\r
 \r
       mCoffSectionsOffset[i] = mCoffOffset;\r
@@ -329,7 +329,7 @@ ScanSections64 (
     }\r
   }\r
 \r
-  if (!FoundText) {\r
+  if (!FoundSection) {\r
     Error (NULL, 0, 3000, "Invalid", "Did not find any '.text' section.");\r
     assert (FALSE);\r
   }\r
@@ -346,6 +346,7 @@ ScanSections64 (
   //  Then data sections.\r
   //\r
   mDataOffset = mCoffOffset;\r
+  FoundSection = FALSE;\r
   SectionCount = 0;\r
   for (i = 0; i < mEhdr->e_shnum; i++) {\r
     Elf_Shdr *shdr = GetShdrByIndex(i);\r
@@ -363,6 +364,14 @@ ScanSections64 (
           Error (NULL, 0, 3000, "Invalid", "Unsupported section alignment.");\r
         }\r
       }\r
+\r
+      //\r
+      // Set mDataOffset with the offset of the first '.data' section\r
+      //\r
+      if (!FoundSection) {\r
+        mDataOffset = mCoffOffset;\r
+        FoundSection = TRUE;\r
+      }\r
       mCoffSectionsOffset[i] = mCoffOffset;\r
       mCoffOffset += (UINT32) shdr->sh_size;\r
       SectionCount ++;\r
@@ -395,6 +404,7 @@ ScanSections64 (
         }\r
       }\r
       if (shdr->sh_size != 0) {\r
+        mHiiRsrcOffset = mCoffOffset;\r
         mCoffSectionsOffset[i] = mCoffOffset;\r
         mCoffOffset += (UINT32) shdr->sh_size;\r
         mCoffOffset = CoffAlign(mCoffOffset);\r