]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/GenFw/Elf32Convert.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / BaseTools / Source / C / GenFw / Elf32Convert.c
index 3d7de6d5c123c66ea632ec117fbd224a754c6cac..87d7f133f1326ef9f2c6ae5de02142fee1b47c92 100644 (file)
@@ -1,16 +1,11 @@
 /** @file\r
 Elf32 Convert solution\r
 \r
-Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2021, Intel Corporation. All rights reserved.<BR>\r
 Portions copyright (c) 2013, ARM Ltd. All rights reserved.<BR>\r
+Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP. 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
@@ -74,7 +69,7 @@ CleanUp32 (
   );\r
 \r
 //\r
-// Rename ELF32 strucutres to common names to help when porting to ELF64.\r
+// Rename ELF32 structures to common names to help when porting to ELF64.\r
 //\r
 typedef Elf32_Shdr Elf_Shdr;\r
 typedef Elf32_Ehdr Elf_Ehdr;\r
@@ -147,9 +142,8 @@ InitializeElf32 (
     Error (NULL, 0, 3000, "Unsupported", "ELF e_type not ET_EXEC or ET_DYN");\r
     return FALSE;\r
   }\r
-  if (!((mEhdr->e_machine == EM_386) || (mEhdr->e_machine == EM_ARM))) {\r
-    Error (NULL, 0, 3000, "Unsupported", "ELF e_machine not EM_386 or EM_ARM");\r
-    return FALSE;\r
+  if (!((mEhdr->e_machine == EM_386) || (mEhdr->e_machine == EM_ARM) || (mEhdr->e_machine == EM_RISCV))) {\r
+    Warning (NULL, 0, 3000, "Unsupported", "ELF e_machine is not Elf32 machine.");\r
   }\r
   if (mEhdr->e_version != EV_CURRENT) {\r
     Error (NULL, 0, 3000, "Unsupported", "ELF e_version (%u) not EV_CURRENT (%d)", (unsigned) mEhdr->e_version, EV_CURRENT);\r
@@ -244,7 +238,8 @@ IsTextShdr (
   Elf_Shdr *Shdr\r
   )\r
 {\r
-  return (BOOLEAN) ((Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) == SHF_ALLOC);\r
+  return (BOOLEAN) (((Shdr->sh_flags & (SHF_EXECINSTR | SHF_ALLOC)) == (SHF_EXECINSTR | SHF_ALLOC)) ||\r
+                   ((Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) == SHF_ALLOC));\r
 }\r
 \r
 STATIC\r
@@ -267,7 +262,7 @@ IsDataShdr (
   if (IsHiiRsrcShdr(Shdr)) {\r
     return FALSE;\r
   }\r
-  return (BOOLEAN) (Shdr->sh_flags & (SHF_WRITE | SHF_ALLOC)) == (SHF_ALLOC | SHF_WRITE);\r
+  return (BOOLEAN) (Shdr->sh_flags & (SHF_EXECINSTR | SHF_WRITE | SHF_ALLOC)) == (SHF_ALLOC | SHF_WRITE);\r
 }\r
 \r
 STATIC\r
@@ -361,7 +356,7 @@ ScanSections32 (
     mCoffOffset += sizeof (EFI_IMAGE_NT_HEADERS32);\r
   break;\r
   default:\r
-    VerboseMsg ("%s unknown e_machine type. Assume IA-32", (UINTN)mEhdr->e_machine);\r
+    VerboseMsg ("%u unknown e_machine type. Assume IA-32", (UINTN)mEhdr->e_machine);\r
     mCoffOffset += sizeof (EFI_IMAGE_NT_HEADERS32);\r
   break;\r
   }\r
@@ -441,7 +436,7 @@ ScanSections32 (
     }\r
   }\r
 \r
-  if (!FoundSection) {\r
+  if (!FoundSection && mOutImageType != FW_ACPI_IMAGE) {\r
     Error (NULL, 0, 3000, "Invalid", "Did not find any '.text' section.");\r
     assert (FALSE);\r
   }\r
@@ -450,7 +445,7 @@ ScanSections32 (
   mCoffOffset = CoffAlign(mCoffOffset);\r
 \r
   if (SectionCount > 1 && mOutImageType == FW_EFI_IMAGE) {\r
-    Warning (NULL, 0, 0, NULL, "Mulitple sections in %s are merged into 1 text section. Source level debug might not work correctly.", mInImageName);\r
+    Warning (NULL, 0, 0, NULL, "Multiple sections in %s are merged into 1 text section. Source level debug might not work correctly.", mInImageName);\r
   }\r
 \r
   //\r
@@ -487,7 +482,7 @@ ScanSections32 (
   }\r
 \r
   if (SectionCount > 1 && mOutImageType == FW_EFI_IMAGE) {\r
-    Warning (NULL, 0, 0, NULL, "Mulitple sections in %s are merged into 1 data section. Source level debug might not work correctly.", mInImageName);\r
+    Warning (NULL, 0, 0, NULL, "Multiple sections in %s are merged into 1 data section. Source level debug might not work correctly.", mInImageName);\r
   }\r
 \r
   //\r
@@ -688,7 +683,7 @@ WriteSections32 (
 \r
       default:\r
         //\r
-        //  Ignore for unkown section type.\r
+        //  Ignore for unknown section type.\r
         //\r
         VerboseMsg ("%s unknown section type %x. We ignore this unknown section type.", mInImageName, (unsigned)Shdr->sh_type);\r
         break;\r
@@ -755,13 +750,7 @@ WriteSections32 (
           if (SymName == NULL) {\r
             SymName = (const UINT8 *)"<unknown>";\r
           }\r
-\r
-          Error (NULL, 0, 3000, "Invalid",\r
-                 "%s: Bad definition for symbol '%s'@%#x or unsupported symbol type.  "\r
-                 "For example, absolute and undefined symbols are not supported.",\r
-                 mInImageName, SymName, Sym->st_value);\r
-\r
-          exit(EXIT_FAILURE);\r
+          continue;\r
         }\r
         SymShdr = GetShdrByIndex(Sym->st_shndx);\r
 \r
@@ -837,7 +826,6 @@ WriteSections32 (
           case R_ARM_LDC_PC_G0:\r
           case R_ARM_LDC_PC_G1:\r
           case R_ARM_LDC_PC_G2:\r
-          case R_ARM_GOT_PREL:\r
           case R_ARM_THM_JUMP11:\r
           case R_ARM_THM_JUMP8:\r
           case R_ARM_TLS_GD32:\r
@@ -964,7 +952,6 @@ WriteRelocations32 (
             case R_ARM_LDC_PC_G0:\r
             case R_ARM_LDC_PC_G1:\r
             case R_ARM_LDC_PC_G2:\r
-            case R_ARM_GOT_PREL:\r
             case R_ARM_THM_JUMP11:\r
             case R_ARM_THM_JUMP8:\r
             case R_ARM_TLS_GD32:\r
@@ -1092,7 +1079,7 @@ WriteRelocations32 (
             break;\r
 \r
           default:\r
-            Error (NULL, 0, 3000, "Invalid", "%s bad ARM dynamic relocations, unkown type %d.", mInImageName, ELF32_R_TYPE (Rel->r_info));\r
+            Error (NULL, 0, 3000, "Invalid", "%s bad ARM dynamic relocations, unknown type %d.", mInImageName, ELF32_R_TYPE (Rel->r_info));\r
             break;\r
           }\r
         }\r