]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/GenFw/ElfConvert.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / BaseTools / Source / C / GenFw / ElfConvert.c
index 6211389ba1695458ec9e82faee470e1108910b68..be98544056ec49416c844d21f266c5868f4cea84 100644 (file)
@@ -1,15 +1,9 @@
 /** @file\r
 Elf convert solution\r
 \r
-Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>\r
 \r
-This program and the accompanying materials are licensed and made available \r
-under the terms and conditions of the BSD License which accompanies this \r
-distribution.  The full text of the license may be found at \r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -24,6 +18,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <string.h>\r
 #include <time.h>\r
 #include <ctype.h>\r
+#include <assert.h>\r
 \r
 #include <Common/UefiBaseTypes.h>\r
 #include <IndustryStandard/PeImage.h>\r
@@ -56,6 +51,11 @@ UINT32 mCoffOffset;
 //\r
 UINT32 mTableOffset;\r
 \r
+//\r
+//mFileBufferSize\r
+//\r
+UINT32 mFileBufferSize;\r
+\r
 //\r
 //*****************************************************************************\r
 // Common ELF Functions\r
@@ -86,7 +86,7 @@ CoffAddFixup(
       // Add a null entry (is it required ?)\r
       //\r
       CoffAddFixupEntry (0);\r
-      \r
+\r
       //\r
       // Pad for alignment.\r
       //\r
@@ -98,6 +98,10 @@ CoffAddFixup(
       mCoffFile,\r
       mCoffOffset + sizeof(EFI_IMAGE_BASE_RELOCATION) + 2 * MAX_COFF_ALIGNMENT\r
       );\r
+    if (mCoffFile == NULL) {\r
+      Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
+    }\r
+    assert (mCoffFile != NULL);\r
     memset (\r
       mCoffFile + mCoffOffset, 0,\r
       sizeof(EFI_IMAGE_BASE_RELOCATION) + 2 * MAX_COFF_ALIGNMENT\r
@@ -153,7 +157,7 @@ IsElfHeader (
   UINT8  *FileBuffer\r
 )\r
 {\r
-  return (FileBuffer[EI_MAG0] == ELFMAG0 && \r
+  return (FileBuffer[EI_MAG0] == ELFMAG0 &&\r
           FileBuffer[EI_MAG1] == ELFMAG1 &&\r
           FileBuffer[EI_MAG2] == ELFMAG2 &&\r
           FileBuffer[EI_MAG3] == ELFMAG3);\r
@@ -168,6 +172,7 @@ ConvertElf (
   ELF_FUNCTION_TABLE              ElfFunctions;\r
   UINT8                           EiClass;\r
 \r
+  mFileBufferSize = *FileLength;\r
   //\r
   // Determine ELF type and set function table pointer correctly.\r
   //\r
@@ -188,7 +193,7 @@ ConvertElf (
 \r
   //\r
   // Compute sections new address.\r
-  //  \r
+  //\r
   VerboseMsg ("Compute sections new address.");\r
   ElfFunctions.ScanSections ();\r
 \r
@@ -196,9 +201,15 @@ ConvertElf (
   // Write and relocate sections.\r
   //\r
   VerboseMsg ("Write and relocate sections.");\r
-  ElfFunctions.WriteSections (SECTION_TEXT);\r
-  ElfFunctions.WriteSections (SECTION_DATA);\r
-  ElfFunctions.WriteSections (SECTION_HII);\r
+  if (!ElfFunctions.WriteSections (SECTION_TEXT)) {\r
+    return FALSE;\r
+  }\r
+  if (!ElfFunctions.WriteSections (SECTION_DATA)) {\r
+    return FALSE;\r
+  }\r
+  if (!ElfFunctions.WriteSections (SECTION_HII)) {\r
+    return FALSE;\r
+  }\r
 \r
   //\r
   // Translate and write relocations.\r
@@ -212,6 +223,14 @@ ConvertElf (
   VerboseMsg ("Write debug info.");\r
   ElfFunctions.WriteDebug ();\r
 \r
+  //\r
+  // For PRM Driver to Write export info.\r
+  //\r
+  if (mExportFlag) {\r
+    VerboseMsg ("Write export info.");\r
+    ElfFunctions.WriteExport ();\r
+  }\r
+\r
   //\r
   // Make sure image size is correct before returning the new image.\r
   //\r
@@ -229,6 +248,6 @@ ConvertElf (
   // Free resources used by ELF functions.\r
   //\r
   ElfFunctions.CleanUp ();\r
-  \r
+\r
   return TRUE;\r
 }\r