From 8a631b2cbe2f8621eb3679a4898205da577453b7 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 15 Nov 2013 21:22:02 +0000 Subject: [PATCH] Path: Recognize COFF import library file magic. Summary: Make identify_magic to recognize COFF import file. Reviewers: Bigcheese CC: llvm-commits Differential Revision: http://llvm-reviews.chandlerc.com/D2165 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194852 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/FileSystem.h | 1 + lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp | 1 + lib/Object/Binary.cpp | 1 + lib/Object/ObjectFile.cpp | 1 + lib/Support/Path.cpp | 4 ++++ test/tools/llvm-readobj/Inputs/magic.coff-importlib | Bin 0 -> 40 bytes test/tools/llvm-readobj/file-headers.test | 17 +++++++++++++++++ unittests/Support/Path.cpp | 2 ++ 8 files changed, 27 insertions(+) create mode 100644 test/tools/llvm-readobj/Inputs/magic.coff-importlib diff --git a/include/llvm/Support/FileSystem.h b/include/llvm/Support/FileSystem.h index 48ff224bcd3..d301f842ea9 100644 --- a/include/llvm/Support/FileSystem.h +++ b/include/llvm/Support/FileSystem.h @@ -238,6 +238,7 @@ struct file_magic { macho_dsym_companion, ///< Mach-O dSYM companion file macho_universal_binary, ///< Mach-O universal binary coff_object, ///< COFF object file + coff_import_library, ///< COFF import library pecoff_executable, ///< PECOFF executable file windows_resource ///< Windows compiled resource file (.rc) }; diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp index 6aa6576e2ec..2c068be970e 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp @@ -584,6 +584,7 @@ ObjectImage *RuntimeDyld::loadObject(ObjectBuffer *InputBuffer) { case sys::fs::file_magic::bitcode: case sys::fs::file_magic::archive: case sys::fs::file_magic::coff_object: + case sys::fs::file_magic::coff_import_library: case sys::fs::file_magic::pecoff_executable: case sys::fs::file_magic::macho_universal_binary: case sys::fs::file_magic::windows_resource: diff --git a/lib/Object/Binary.cpp b/lib/Object/Binary.cpp index d0a70091444..de57b4c9a74 100644 --- a/lib/Object/Binary.cpp +++ b/lib/Object/Binary.cpp @@ -91,6 +91,7 @@ error_code object::createBinary(MemoryBuffer *Source, return object_error::success; } case sys::fs::file_magic::coff_object: + case sys::fs::file_magic::coff_import_library: case sys::fs::file_magic::pecoff_executable: { OwningPtr ret( ObjectFile::createCOFFObjectFile(scopedSource.take())); diff --git a/lib/Object/ObjectFile.cpp b/lib/Object/ObjectFile.cpp index 59395c640ff..0e626d650fb 100644 --- a/lib/Object/ObjectFile.cpp +++ b/lib/Object/ObjectFile.cpp @@ -69,6 +69,7 @@ ObjectFile *ObjectFile::createObjectFile(MemoryBuffer *Object) { case sys::fs::file_magic::macho_dsym_companion: return createMachOObjectFile(Object); case sys::fs::file_magic::coff_object: + case sys::fs::file_magic::coff_import_library: case sys::fs::file_magic::pecoff_executable: return createCOFFObjectFile(Object); } diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp index dfa18aaa6d2..c869b30a8e2 100644 --- a/lib/Support/Path.cpp +++ b/lib/Support/Path.cpp @@ -848,6 +848,10 @@ error_code has_magic(const Twine &path, const Twine &magic, bool &result) { return file_magic::unknown; switch ((unsigned char)Magic[0]) { case 0x00: { + // COFF short import library file + if (Magic[1] == (char)0x00 && Magic[2] == (char)0xff && + Magic[3] == (char)0xff) + return file_magic::coff_import_library; // Windows resource file const char Expected[] = { 0, 0, 0, 0, '\x20', 0, 0, 0, '\xff' }; if (Magic.size() >= sizeof(Expected) && diff --git a/test/tools/llvm-readobj/Inputs/magic.coff-importlib b/test/tools/llvm-readobj/Inputs/magic.coff-importlib new file mode 100644 index 0000000000000000000000000000000000000000..b934afb41a8da900abb8da0f1c9bd0570024fa9f GIT binary patch literal 40 rcmZQz`2U}Q!H4m+Q)`e20|;<1#HW?!B{QVt +COFF-IMPORTLIB-NEXT: Arch: unknown +COFF-IMPORTLIB-NEXT: AddressSize: 32bit +COFF-IMPORTLIB-NEXT: ImageFileHeader { +COFF-IMPORTLIB-NEXT: Machine: IMAGE_FILE_MACHINE_UNKNOWN (0x0) +COFF-IMPORTLIB-NEXT: SectionCount: 65535 +COFF-IMPORTLIB-NEXT: TimeDateStamp: 1970-09-09 19:52:32 (0x14C0000) +COFF-IMPORTLIB-NEXT: PointerToSymbolTable: 0x528542EB +COFF-IMPORTLIB-NEXT: SymbolCount: 20 +COFF-IMPORTLIB-NEXT: OptionalHeaderSize: 0 +COFF-IMPORTLIB-NEXT: Characteristics [ (0x8) +COFF-IMPORTLIB-NEXT: IMAGE_FILE_LOCAL_SYMS_STRIPPED (0x8) +COFF-IMPORTLIB-NEXT: ] +COFF-IMPORTLIB-NEXT: } diff --git a/unittests/Support/Path.cpp b/unittests/Support/Path.cpp index 2323029b589..031624162d0 100644 --- a/unittests/Support/Path.cpp +++ b/unittests/Support/Path.cpp @@ -419,6 +419,7 @@ TEST_F(FileSystemTest, DirectoryIteration) { const char archive[] = "!\x0A"; const char bitcode[] = "\xde\xc0\x17\x0b"; const char coff_object[] = "\x00\x00......"; +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 macho_universal_binary[] = "\xca\xfe\xba\xbe...\0x00"; @@ -447,6 +448,7 @@ TEST_F(FileSystemTest, Magic) { DEFINE(archive), DEFINE(bitcode), DEFINE(coff_object), + DEFINE(coff_import_library), DEFINE(elf_relocatable), DEFINE(macho_universal_binary), DEFINE(macho_object), -- 2.11.0