Skip to content

Commit 0977f31

Browse files
committed
[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
1 parent fd855c2 commit 0977f31

File tree

6 files changed

+13
-0
lines changed

6 files changed

+13
-0
lines changed

llvm/include/llvm/BinaryFormat/Magic.h

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ struct file_magic {
2727
elf_executable, ///< ELF Executable image
2828
elf_shared_object, ///< ELF dynamically linked shared lib
2929
elf_core, ///< ELF core image
30+
goff_object, ///< GOFF object file
3031
macho_object, ///< Mach-O Object file
3132
macho_executable, ///< Mach-O Executable
3233
macho_fixed_virtual_memory_shared_lib, ///< Mach-O Shared Lib, FVM

llvm/lib/BinaryFormat/Magic.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ file_magic llvm::identify_magic(StringRef Magic) {
7171
return file_magic::xcoff_object_64;
7272
break;
7373

74+
case 0x03:
75+
if (startswith(Magic, "\x03\xF0\x00"))
76+
return file_magic::goff_object;
77+
break;
78+
7479
case 0xDE: // 0x0B17C0DE = BC wraper
7580
if (startswith(Magic, "\xDE\xC0\x17\x0B"))
7681
return file_magic::bitcode;

llvm/lib/Object/Binary.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Expected<std::unique_ptr<Binary>> object::createBinary(MemoryBufferRef Buffer,
5656
case file_magic::elf_executable:
5757
case file_magic::elf_shared_object:
5858
case file_magic::elf_core:
59+
case file_magic::goff_object:
5960
case file_magic::macho_object:
6061
case file_magic::macho_executable:
6162
case file_magic::macho_fixed_virtual_memory_shared_lib:

llvm/lib/Object/ObjectFile.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ ObjectFile::createObjectFile(MemoryBufferRef Object, file_magic Type,
145145
case file_magic::windows_resource:
146146
case file_magic::pdb:
147147
case file_magic::minidump:
148+
case file_magic::goff_object:
148149
return errorCodeToError(object_error::invalid_file_type);
149150
case file_magic::tapi_file:
150151
return errorCodeToError(object_error::invalid_file_type);

llvm/lib/Object/SymbolicFile.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ SymbolicFile::createSymbolicFile(MemoryBufferRef Object, file_magic Type,
5353
case file_magic::elf_executable:
5454
case file_magic::elf_shared_object:
5555
case file_magic::elf_core:
56+
case file_magic::goff_object:
5657
case file_magic::macho_executable:
5758
case file_magic::macho_fixed_virtual_memory_shared_lib:
5859
case file_magic::macho_core:
@@ -102,6 +103,7 @@ bool SymbolicFile::isSymbolicFile(file_magic Type, const LLVMContext *Context) {
102103
case file_magic::elf_executable:
103104
case file_magic::elf_shared_object:
104105
case file_magic::elf_core:
106+
case file_magic::goff_object:
105107
case file_magic::macho_executable:
106108
case file_magic::macho_fixed_virtual_memory_shared_lib:
107109
case file_magic::macho_core:

llvm/unittests/BinaryFormat/TestFileMagic.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ const char coff_bigobj[] =
5454
const char coff_import_library[] = "\x00\x00\xff\xff....";
5555
const char elf_relocatable[] = {0x7f, 'E', 'L', 'F', 1, 2, 1, 0, 0,
5656
0, 0, 0, 0, 0, 0, 0, 0, 1};
57+
58+
const char goff_object[] = "\x03\xF0\x00";
5759
const char macho_universal_binary[] = "\xca\xfe\xba\xbe...\x00";
5860
const char macho_object[] =
5961
"\xfe\xed\xfa\xce........\x00\x00\x00\x01............";
@@ -100,6 +102,7 @@ TEST_F(MagicTest, Magic) {
100102
file_magic::coff_object},
101103
DEFINE(coff_import_library),
102104
DEFINE(elf_relocatable),
105+
DEFINE(goff_object),
103106
DEFINE(macho_universal_binary),
104107
DEFINE(macho_object),
105108
DEFINE(macho_executable),

0 commit comments

Comments
 (0)