[llvm] 0977f31 - [SystemZ][z/OS] Add GOFF support to file magic identification
Anirudh Prasad via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 20 07:50:54 PDT 2021
Author: Anirudh Prasad
Date: 2021-07-20T10:50:47-04:00
New Revision: 0977f31cecf8aa4ad1be72748179f4d6a902daf4
URL: https://github.com/llvm/llvm-project/commit/0977f31cecf8aa4ad1be72748179f4d6a902daf4
DIFF: https://github.com/llvm/llvm-project/commit/0977f31cecf8aa4ad1be72748179f4d6a902daf4.diff
LOG: [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
Added:
Modified:
llvm/include/llvm/BinaryFormat/Magic.h
llvm/lib/BinaryFormat/Magic.cpp
llvm/lib/Object/Binary.cpp
llvm/lib/Object/ObjectFile.cpp
llvm/lib/Object/SymbolicFile.cpp
llvm/unittests/BinaryFormat/TestFileMagic.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/BinaryFormat/Magic.h b/llvm/include/llvm/BinaryFormat/Magic.h
index 78227ddbe0954..6988b2dde656a 100644
--- a/llvm/include/llvm/BinaryFormat/Magic.h
+++ b/llvm/include/llvm/BinaryFormat/Magic.h
@@ -27,6 +27,7 @@ struct file_magic {
elf_executable, ///< ELF Executable image
elf_shared_object, ///< ELF dynamically linked shared lib
elf_core, ///< ELF core image
+ goff_object, ///< GOFF object file
macho_object, ///< Mach-O Object file
macho_executable, ///< Mach-O Executable
macho_fixed_virtual_memory_shared_lib, ///< Mach-O Shared Lib, FVM
diff --git a/llvm/lib/BinaryFormat/Magic.cpp b/llvm/lib/BinaryFormat/Magic.cpp
index 591da4877479f..8c7f7b7043a04 100644
--- a/llvm/lib/BinaryFormat/Magic.cpp
+++ b/llvm/lib/BinaryFormat/Magic.cpp
@@ -71,6 +71,11 @@ file_magic llvm::identify_magic(StringRef Magic) {
return file_magic::xcoff_object_64;
break;
+ case 0x03:
+ if (startswith(Magic, "\x03\xF0\x00"))
+ return file_magic::goff_object;
+ break;
+
case 0xDE: // 0x0B17C0DE = BC wraper
if (startswith(Magic, "\xDE\xC0\x17\x0B"))
return file_magic::bitcode;
diff --git a/llvm/lib/Object/Binary.cpp b/llvm/lib/Object/Binary.cpp
index 71c0446302235..143554344256a 100644
--- a/llvm/lib/Object/Binary.cpp
+++ b/llvm/lib/Object/Binary.cpp
@@ -56,6 +56,7 @@ Expected<std::unique_ptr<Binary>> object::createBinary(MemoryBufferRef Buffer,
case file_magic::elf_executable:
case file_magic::elf_shared_object:
case file_magic::elf_core:
+ case file_magic::goff_object:
case file_magic::macho_object:
case file_magic::macho_executable:
case file_magic::macho_fixed_virtual_memory_shared_lib:
diff --git a/llvm/lib/Object/ObjectFile.cpp b/llvm/lib/Object/ObjectFile.cpp
index 7b17c8e00ece9..5c894439ff67f 100644
--- a/llvm/lib/Object/ObjectFile.cpp
+++ b/llvm/lib/Object/ObjectFile.cpp
@@ -145,6 +145,7 @@ ObjectFile::createObjectFile(MemoryBufferRef Object, file_magic Type,
case file_magic::windows_resource:
case file_magic::pdb:
case file_magic::minidump:
+ case file_magic::goff_object:
return errorCodeToError(object_error::invalid_file_type);
case file_magic::tapi_file:
return errorCodeToError(object_error::invalid_file_type);
diff --git a/llvm/lib/Object/SymbolicFile.cpp b/llvm/lib/Object/SymbolicFile.cpp
index 34a2c5e1c125f..58db5b672914f 100644
--- a/llvm/lib/Object/SymbolicFile.cpp
+++ b/llvm/lib/Object/SymbolicFile.cpp
@@ -53,6 +53,7 @@ SymbolicFile::createSymbolicFile(MemoryBufferRef Object, file_magic Type,
case file_magic::elf_executable:
case file_magic::elf_shared_object:
case file_magic::elf_core:
+ case file_magic::goff_object:
case file_magic::macho_executable:
case file_magic::macho_fixed_virtual_memory_shared_lib:
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_shared_object:
case file_magic::elf_core:
+ case file_magic::goff_object:
case file_magic::macho_executable:
case file_magic::macho_fixed_virtual_memory_shared_lib:
case file_magic::macho_core:
diff --git a/llvm/unittests/BinaryFormat/TestFileMagic.cpp b/llvm/unittests/BinaryFormat/TestFileMagic.cpp
index 0919abe2a523f..81c5f08cdafa2 100644
--- a/llvm/unittests/BinaryFormat/TestFileMagic.cpp
+++ b/llvm/unittests/BinaryFormat/TestFileMagic.cpp
@@ -54,6 +54,8 @@ const char coff_bigobj[] =
const char coff_import_library[] = "\x00\x00\xff\xff....";
const char elf_relocatable[] = {0x7f, 'E', 'L', 'F', 1, 2, 1, 0, 0,
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_object[] =
"\xfe\xed\xfa\xce........\x00\x00\x00\x01............";
@@ -100,6 +102,7 @@ TEST_F(MagicTest, Magic) {
file_magic::coff_object},
DEFINE(coff_import_library),
DEFINE(elf_relocatable),
+ DEFINE(goff_object),
DEFINE(macho_universal_binary),
DEFINE(macho_object),
DEFINE(macho_executable),
More information about the llvm-commits
mailing list