[PATCH] Path: Recognize COFF import library file magic.

Rui Ueyama ruiu at google.com
Wed Nov 13 21:35:16 PST 2013


On Wed, Nov 13, 2013 at 8:01 PM, Rafael EspĂ­ndola <
rafael.espindola at gmail.com> wrote:

> you are not using coff_import_library anywhere in the test. You should
> also be able to add a more complete test, no? Can't you, for example,
> run llvm-readobj in a "import library"?


Sorry for the incomplete test. I will update the patch to use
coff_import_library in a test.

As to llvm-readobj, I think we don't have to write a test to run
llvm-readobj with an actual file reside on the file system. My test should
be sufficient as a unit test for the function that's being modified in the
patch. Actually I think this unit test would be better than tests using
llvm-readobj because it's more focused on identity_magic's functionality.
It's easy to write, understand, and debug.

On 13 November 2013 17:02, Rui Ueyama <ruiu at google.com> wrote:
>  >   - added a test
> >
> > Hi Bigcheese,
> >
> > http://llvm-reviews.chandlerc.com/D2165
> >
> > CHANGE SINCE LAST DIFF
> >   http://llvm-reviews.chandlerc.com/D2165?vs=5497&id=5518#toc
> >
> > Files:
> >   include/llvm/Support/FileSystem.h
> >   lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
> >   lib/Object/Binary.cpp
> >   lib/Object/ObjectFile.cpp
> >   lib/Support/Path.cpp
> >   unittests/Support/Path.cpp
> >
> > Index: include/llvm/Support/FileSystem.h
> > ===================================================================
> > --- include/llvm/Support/FileSystem.h
> > +++ include/llvm/Support/FileSystem.h
> > @@ -238,6 +238,7 @@
> >      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)
> >    };
> > Index: lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
> > ===================================================================
> > --- lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
> > +++ lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
> > @@ -584,6 +584,7 @@
> >      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:
> > Index: lib/Object/Binary.cpp
> > ===================================================================
> > --- lib/Object/Binary.cpp
> > +++ lib/Object/Binary.cpp
> > @@ -91,6 +91,7 @@
> >        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()));
> > Index: lib/Object/ObjectFile.cpp
> > ===================================================================
> > --- lib/Object/ObjectFile.cpp
> > +++ lib/Object/ObjectFile.cpp
> > @@ -69,6 +69,7 @@
> >    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);
> >    }
> > Index: lib/Support/Path.cpp
> > ===================================================================
> > --- lib/Support/Path.cpp
> > +++ lib/Support/Path.cpp
> > @@ -848,6 +848,10 @@
> >      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) &&
> > Index: unittests/Support/Path.cpp
> > ===================================================================
> > --- unittests/Support/Path.cpp
> > +++ unittests/Support/Path.cpp
> > @@ -418,6 +418,7 @@
> >
> >  const char archive[] = "!<arch>\x0A";
> >  const char bitcode[] = "\xde\xc0\x17\x0b";
> > +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";
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131113/db15c9fd/attachment.html>


More information about the llvm-commits mailing list