/** @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
);\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
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
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
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
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
}\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
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
}\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
\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
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
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