]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/GenFw/Elf64Convert.c
BaseTools/GenFw: Set the PE/COFF attribute BaseOfData with the address of the first...
[mirror_edk2.git] / BaseTools / Source / C / GenFw / Elf64Convert.c
index 526ab5d41f3dbf47918958735dc9e1f8d21c68bd..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
@@ -710,13 +720,15 @@ WriteSections64 (
             break;\r
 \r
           case R_AARCH64_CALL26:\r
-            if  (Rel->r_addend != 0 ) { /* TODO */\r
-              Error (NULL, 0, 3000, "Invalid", "AArch64: R_AARCH64_CALL26 Need to fixup with addend!.");\r
-            }\r
-            break;\r
-\r
           case R_AARCH64_JUMP26:\r
-            if  (Rel->r_addend != 0 ) { /* TODO : AArch64 '-O2' optimisation. */\r
+            if  (Rel->r_addend != 0 ) {\r
+              // Some references to static functions sometime start at the base of .text + addend.\r
+              // It is safe to ignore these relocations because they patch a `BL` instructions that\r
+              // contains an offset from the instruction itself and there is only a single .text section.\r
+              // So we check if the symbol is a "section symbol"\r
+              if (ELF64_ST_TYPE (Sym->st_info) == STT_SECTION) {\r
+                break;\r
+              }\r
               Error (NULL, 0, 3000, "Invalid", "AArch64: R_AARCH64_JUMP26 Need to fixup with addend!.");\r
             }\r
             break;\r