[llvm] r217627 - Support: improve identify_magic to recognize COFF bigobj
David Majnemer
david.majnemer at gmail.com
Thu Sep 11 14:55:10 PDT 2014
On Thu, Sep 11, 2014 at 5:09 PM, Rui Ueyama <ruiu at google.com> wrote:
> Author: ruiu
> Date: Thu Sep 11 16:09:57 2014
> New Revision: 217627
>
> URL: http://llvm.org/viewvc/llvm-project?rev=217627&view=rev
> Log:
> Support: improve identify_magic to recognize COFF bigobj
>
> identify_magic recognized a COFF bigobj as an import library file.
> This patch fixes that.
>
>
> Modified:
> llvm/trunk/lib/Support/Path.cpp
> llvm/trunk/unittests/Support/Path.cpp
>
> Modified: llvm/trunk/lib/Support/Path.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Path.cpp?rev=217627&r1=217626&r2=217627&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Support/Path.cpp (original)
> +++ llvm/trunk/lib/Support/Path.cpp Thu Sep 11 16:09:57 2014
> @@ -901,10 +901,16 @@ file_magic identify_magic(StringRef Magi
> return file_magic::unknown;
> switch ((unsigned char)Magic[0]) {
> case 0x00: {
> - // COFF short import library file
> + // COFF bigobj or short import library file
> if (Magic[1] == (char)0x00 && Magic[2] == (char)0xff &&
> - Magic[3] == (char)0xff)
> - return file_magic::coff_import_library;
> + Magic[3] == (char)0xff) {
> + const char BigobjMagic[] =
> +
> "\xc7\xa1\xba\xd1\xee\xba\xa9\x4b\xaf\x20\xfa\xf6\x6a\xa4\xdc\xb8";
>
Why not use llvm::COFF::BigObjMagic instead?
Also, you aren't checking the version number.
> + if (Magic.size() >= 28 &&
> + memcmp(Magic.data() + 12, BigobjMagic, sizeof(BigobjMagic))
> == 0)
> + return file_magic::coff_object;
> + 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) &&
>
> Modified: llvm/trunk/unittests/Support/Path.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/Path.cpp?rev=217627&r1=217626&r2=217627&view=diff
>
> ==============================================================================
> --- llvm/trunk/unittests/Support/Path.cpp (original)
> +++ llvm/trunk/unittests/Support/Path.cpp Thu Sep 11 16:09:57 2014
> @@ -483,6 +483,8 @@ 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_bigobj[] = "\x00\x00\xff\xff........"
> + "\xc7\xa1\xba\xd1\xee\xba\xa9\x4b\xaf\x20\xfa\xf6\x6a\xa4\xdc\xb8";
> 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 };
> @@ -512,6 +514,7 @@ TEST_F(FileSystemTest, Magic) {
> DEFINE(archive),
> DEFINE(bitcode),
> DEFINE(coff_object),
> + { "coff_bigobj", coff_bigobj, sizeof(coff_bigobj),
> fs::file_magic::coff_object },
> DEFINE(coff_import_library),
> DEFINE(elf_relocatable),
> DEFINE(macho_universal_binary),
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140911/20cc7e36/attachment.html>
More information about the llvm-commits
mailing list