[SystemZ][z/OS] Add GOFF support to file magic identification

- This patch adds in the GOFF format to the file magic identification logic in LLVM
- Currently, for the object file support, GOFF is marked as having as an error
- However, this is only temporary until https://reviews.llvm.org/D98437 is merged in

Reviewed By: abhina.sreeskantharajan

Differential Revision: https://reviews.llvm.org/D105993
This commit is contained in:
Anirudh Prasad 2021-07-20 10:50:18 -04:00
parent fd855c24c7
commit 0977f31cec
6 changed files with 13 additions and 0 deletions
llvm
include/llvm/BinaryFormat
lib
unittests/BinaryFormat

View File

@ -27,6 +27,7 @@ struct file_magic {
elf_executable, ///< ELF Executable image elf_executable, ///< ELF Executable image
elf_shared_object, ///< ELF dynamically linked shared lib elf_shared_object, ///< ELF dynamically linked shared lib
elf_core, ///< ELF core image elf_core, ///< ELF core image
goff_object, ///< GOFF object file
macho_object, ///< Mach-O Object file macho_object, ///< Mach-O Object file
macho_executable, ///< Mach-O Executable macho_executable, ///< Mach-O Executable
macho_fixed_virtual_memory_shared_lib, ///< Mach-O Shared Lib, FVM macho_fixed_virtual_memory_shared_lib, ///< Mach-O Shared Lib, FVM

View File

@ -71,6 +71,11 @@ file_magic llvm::identify_magic(StringRef Magic) {
return file_magic::xcoff_object_64; return file_magic::xcoff_object_64;
break; break;
case 0x03:
if (startswith(Magic, "\x03\xF0\x00"))
return file_magic::goff_object;
break;
case 0xDE: // 0x0B17C0DE = BC wraper case 0xDE: // 0x0B17C0DE = BC wraper
if (startswith(Magic, "\xDE\xC0\x17\x0B")) if (startswith(Magic, "\xDE\xC0\x17\x0B"))
return file_magic::bitcode; return file_magic::bitcode;

View File

@ -56,6 +56,7 @@ Expected<std::unique_ptr<Binary>> object::createBinary(MemoryBufferRef Buffer,
case file_magic::elf_executable: case file_magic::elf_executable:
case file_magic::elf_shared_object: case file_magic::elf_shared_object:
case file_magic::elf_core: case file_magic::elf_core:
case file_magic::goff_object:
case file_magic::macho_object: case file_magic::macho_object:
case file_magic::macho_executable: case file_magic::macho_executable:
case file_magic::macho_fixed_virtual_memory_shared_lib: case file_magic::macho_fixed_virtual_memory_shared_lib:

View File

@ -145,6 +145,7 @@ ObjectFile::createObjectFile(MemoryBufferRef Object, file_magic Type,
case file_magic::windows_resource: case file_magic::windows_resource:
case file_magic::pdb: case file_magic::pdb:
case file_magic::minidump: case file_magic::minidump:
case file_magic::goff_object:
return errorCodeToError(object_error::invalid_file_type); return errorCodeToError(object_error::invalid_file_type);
case file_magic::tapi_file: case file_magic::tapi_file:
return errorCodeToError(object_error::invalid_file_type); return errorCodeToError(object_error::invalid_file_type);

View File

@ -53,6 +53,7 @@ SymbolicFile::createSymbolicFile(MemoryBufferRef Object, file_magic Type,
case file_magic::elf_executable: case file_magic::elf_executable:
case file_magic::elf_shared_object: case file_magic::elf_shared_object:
case file_magic::elf_core: case file_magic::elf_core:
case file_magic::goff_object:
case file_magic::macho_executable: case file_magic::macho_executable:
case file_magic::macho_fixed_virtual_memory_shared_lib: case file_magic::macho_fixed_virtual_memory_shared_lib:
case file_magic::macho_core: case file_magic::macho_core:
@ -102,6 +103,7 @@ bool SymbolicFile::isSymbolicFile(file_magic Type, const LLVMContext *Context) {
case file_magic::elf_executable: case file_magic::elf_executable:
case file_magic::elf_shared_object: case file_magic::elf_shared_object:
case file_magic::elf_core: case file_magic::elf_core:
case file_magic::goff_object:
case file_magic::macho_executable: case file_magic::macho_executable:
case file_magic::macho_fixed_virtual_memory_shared_lib: case file_magic::macho_fixed_virtual_memory_shared_lib:
case file_magic::macho_core: case file_magic::macho_core:

View File

@ -54,6 +54,8 @@ const char coff_bigobj[] =
const char coff_import_library[] = "\x00\x00\xff\xff...."; const char coff_import_library[] = "\x00\x00\xff\xff....";
const char elf_relocatable[] = {0x7f, 'E', 'L', 'F', 1, 2, 1, 0, 0, const char elf_relocatable[] = {0x7f, 'E', 'L', 'F', 1, 2, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1}; 0, 0, 0, 0, 0, 0, 0, 0, 1};
const char goff_object[] = "\x03\xF0\x00";
const char macho_universal_binary[] = "\xca\xfe\xba\xbe...\x00"; const char macho_universal_binary[] = "\xca\xfe\xba\xbe...\x00";
const char macho_object[] = const char macho_object[] =
"\xfe\xed\xfa\xce........\x00\x00\x00\x01............"; "\xfe\xed\xfa\xce........\x00\x00\x00\x01............";
@ -100,6 +102,7 @@ TEST_F(MagicTest, Magic) {
file_magic::coff_object}, file_magic::coff_object},
DEFINE(coff_import_library), DEFINE(coff_import_library),
DEFINE(elf_relocatable), DEFINE(elf_relocatable),
DEFINE(goff_object),
DEFINE(macho_universal_binary), DEFINE(macho_universal_binary),
DEFINE(macho_object), DEFINE(macho_object),
DEFINE(macho_executable), DEFINE(macho_executable),