Revision: 16831
          http://sourceforge.net/p/edk2/code/16831
Author:   lgao4
Date:     2015-02-11 08:20:17 +0000 (Wed, 11 Feb 2015)
Log Message:
-----------
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 <[email protected]>
Reviewed-by: Liming Gao <[email protected]>

Modified Paths:
--------------
    trunk/edk2/BaseTools/Source/C/GenFw/Elf32Convert.c
    trunk/edk2/BaseTools/Source/C/GenFw/Elf64Convert.c

Modified: trunk/edk2/BaseTools/Source/C/GenFw/Elf32Convert.c
===================================================================
--- trunk/edk2/BaseTools/Source/C/GenFw/Elf32Convert.c  2015-02-11 08:11:44 UTC 
(rev 16830)
+++ trunk/edk2/BaseTools/Source/C/GenFw/Elf32Convert.c  2015-02-11 08:20:17 UTC 
(rev 16831)
@@ -267,12 +267,10 @@
   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 @@
   // 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 @@
       //
       // 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 @@
     }
   }
 
-  if (!FoundText) {
+  if (!FoundSection) {
     Error (NULL, 0, 3000, "Invalid", "Did not find any '.text' section.");
     assert (FALSE);
   }
@@ -352,6 +352,7 @@
   //  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 @@
           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 @@
         }
       }
       if (shdr->sh_size != 0) {
+        mHiiRsrcOffset = mCoffOffset;
         mCoffSectionsOffset[i] = mCoffOffset;
         mCoffOffset += shdr->sh_size;
         mCoffOffset = CoffAlign(mCoffOffset);

Modified: trunk/edk2/BaseTools/Source/C/GenFw/Elf64Convert.c
===================================================================
--- trunk/edk2/BaseTools/Source/C/GenFw/Elf64Convert.c  2015-02-11 08:11:44 UTC 
(rev 16830)
+++ trunk/edk2/BaseTools/Source/C/GenFw/Elf64Convert.c  2015-02-11 08:20:17 UTC 
(rev 16831)
@@ -260,12 +260,10 @@
   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 @@
   // 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 @@
       //
       // 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 @@
     }
   }
 
-  if (!FoundText) {
+  if (!FoundSection) {
     Error (NULL, 0, 3000, "Invalid", "Did not find any '.text' section.");
     assert (FALSE);
   }
@@ -346,6 +346,7 @@
   //  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 @@
           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 @@
         }
       }
       if (shdr->sh_size != 0) {
+        mHiiRsrcOffset = mCoffOffset;
         mCoffSectionsOffset[i] = mCoffOffset;
         mCoffOffset += (UINT32) shdr->sh_size;
         mCoffOffset = CoffAlign(mCoffOffset);


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to