[llvm] r194852 - Path: Recognize COFF import library file magic.
Rui Ueyama
ruiu at google.com
Fri Nov 15 13:22:03 PST 2013
Author: ruiu
Date: Fri Nov 15 15:22:02 2013
New Revision: 194852
URL: http://llvm.org/viewvc/llvm-project?rev=194852&view=rev
Log:
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
Added:
llvm/trunk/test/tools/llvm-readobj/Inputs/magic.coff-importlib
Modified:
llvm/trunk/include/llvm/Support/FileSystem.h
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
llvm/trunk/lib/Object/Binary.cpp
llvm/trunk/lib/Object/ObjectFile.cpp
llvm/trunk/lib/Support/Path.cpp
llvm/trunk/test/tools/llvm-readobj/file-headers.test
llvm/trunk/unittests/Support/Path.cpp
Modified: llvm/trunk/include/llvm/Support/FileSystem.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileSystem.h?rev=194852&r1=194851&r2=194852&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/FileSystem.h (original)
+++ llvm/trunk/include/llvm/Support/FileSystem.h Fri Nov 15 15:22:02 2013
@@ -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)
};
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp?rev=194852&r1=194851&r2=194852&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp Fri Nov 15 15:22:02 2013
@@ -584,6 +584,7 @@ ObjectImage *RuntimeDyld::loadObject(Obj
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:
Modified: llvm/trunk/lib/Object/Binary.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/Binary.cpp?rev=194852&r1=194851&r2=194852&view=diff
==============================================================================
--- llvm/trunk/lib/Object/Binary.cpp (original)
+++ llvm/trunk/lib/Object/Binary.cpp Fri Nov 15 15:22:02 2013
@@ -91,6 +91,7 @@ error_code object::createBinary(MemoryBu
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<Binary> ret(
ObjectFile::createCOFFObjectFile(scopedSource.take()));
Modified: llvm/trunk/lib/Object/ObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ObjectFile.cpp?rev=194852&r1=194851&r2=194852&view=diff
==============================================================================
--- llvm/trunk/lib/Object/ObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/ObjectFile.cpp Fri Nov 15 15:22:02 2013
@@ -69,6 +69,7 @@ ObjectFile *ObjectFile::createObjectFile
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);
}
Modified: llvm/trunk/lib/Support/Path.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Path.cpp?rev=194852&r1=194851&r2=194852&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Path.cpp (original)
+++ llvm/trunk/lib/Support/Path.cpp Fri Nov 15 15:22:02 2013
@@ -848,6 +848,10 @@ error_code has_magic(const Twine &path,
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) &&
Added: llvm/trunk/test/tools/llvm-readobj/Inputs/magic.coff-importlib
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/Inputs/magic.coff-importlib?rev=194852&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/llvm-readobj/Inputs/magic.coff-importlib (added) and llvm/trunk/test/tools/llvm-readobj/Inputs/magic.coff-importlib Fri Nov 15 15:22:02 2013 differ
Modified: llvm/trunk/test/tools/llvm-readobj/file-headers.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/file-headers.test?rev=194852&r1=194851&r2=194852&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/file-headers.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/file-headers.test Fri Nov 15 15:22:02 2013
@@ -10,6 +10,8 @@ RUN: llvm-readobj -h %p/Inputs/trivial.o
RUN: | FileCheck %s -check-prefix ELF64
RUN: llvm-readobj -h %p/Inputs/magic.coff-unknown \
RUN: | FileCheck %s -check-prefix COFF-UNKNOWN
+RUN: llvm-readobj -h %p/Inputs/magic.coff-importlib \
+RUN: | FileCheck %s -check-prefix COFF-IMPORTLIB
COFF32: File: {{(.*[/\\])?}}trivial.obj.coff-i386
COFF32-NEXT: Format: COFF-i386
@@ -199,3 +201,18 @@ COFF-UNKNOWN-NEXT: OptionalHeaderSize:
COFF-UNKNOWN-NEXT: Characteristics [ (0x0)
COFF-UNKNOWN-NEXT: ]
COFF-UNKNOWN-NEXT: }
+
+COFF-IMPORTLIB: Format: COFF-<unknown arch>
+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: }
Modified: llvm/trunk/unittests/Support/Path.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/Path.cpp?rev=194852&r1=194851&r2=194852&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/Path.cpp (original)
+++ llvm/trunk/unittests/Support/Path.cpp Fri Nov 15 15:22:02 2013
@@ -419,6 +419,7 @@ TEST_F(FileSystemTest, DirectoryIteratio
const char archive[] = "!<arch>\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),
More information about the llvm-commits
mailing list