[PATCH] D26645: Add a file magic for CL.exe's object file created with /GL.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 14 17:04:51 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL286919: Add a file magic for CL.exe's object file created with /GL. (authored by ruiu).

Changed prior to commit:
  https://reviews.llvm.org/D26645?vs=77902&id=77923#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26645

Files:
  llvm/trunk/include/llvm/Support/COFF.h
  llvm/trunk/include/llvm/Support/FileSystem.h
  llvm/trunk/lib/Object/ObjectFile.cpp
  llvm/trunk/lib/Support/Path.cpp


Index: llvm/trunk/include/llvm/Support/FileSystem.h
===================================================================
--- llvm/trunk/include/llvm/Support/FileSystem.h
+++ llvm/trunk/include/llvm/Support/FileSystem.h
@@ -258,6 +258,7 @@
     macho_dsym_companion,     ///< Mach-O dSYM companion file
     macho_kext_bundle,        ///< Mach-O kext bundle file
     macho_universal_binary,   ///< Mach-O universal binary
+    coff_cl_gl_object,        ///< Microsoft cl.exe's intermediate code file
     coff_object,              ///< COFF object file
     coff_import_library,      ///< COFF import library
     pecoff_executable,        ///< PECOFF executable file
Index: llvm/trunk/include/llvm/Support/COFF.h
===================================================================
--- llvm/trunk/include/llvm/Support/COFF.h
+++ llvm/trunk/include/llvm/Support/COFF.h
@@ -41,6 +41,11 @@
       '\xaf', '\x20', '\xfa', '\xf6', '\x6a', '\xa4', '\xdc', '\xb8',
   };
 
+  static const char ClGlObjMagic[] = {
+      '\x38', '\xfe', '\xb3', '\x0c', '\xa5', '\xd9', '\xab', '\x4d',
+      '\xac', '\x9b', '\xd6', '\xb6', '\x22', '\x26', '\x53', '\xc2',
+  };
+
   // Sizes in bytes of various things in the COFF format.
   enum {
     Header16Size   = 20,
Index: llvm/trunk/lib/Object/ObjectFile.cpp
===================================================================
--- llvm/trunk/lib/Object/ObjectFile.cpp
+++ llvm/trunk/lib/Object/ObjectFile.cpp
@@ -78,6 +78,7 @@
   switch (Type) {
   case sys::fs::file_magic::unknown:
   case sys::fs::file_magic::bitcode:
+  case sys::fs::file_magic::coff_cl_gl_object:
   case sys::fs::file_magic::archive:
   case sys::fs::file_magic::macho_universal_binary:
   case sys::fs::file_magic::windows_resource:
Index: llvm/trunk/lib/Support/Path.cpp
===================================================================
--- llvm/trunk/lib/Support/Path.cpp
+++ llvm/trunk/lib/Support/Path.cpp
@@ -986,22 +986,18 @@
     return file_magic::unknown;
   switch ((unsigned char)Magic[0]) {
     case 0x00: {
-      // COFF bigobj or short import library file
-      if (Magic[1] == (char)0x00 && Magic[2] == (char)0xff &&
-          Magic[3] == (char)0xff) {
+      // COFF bigobj, CL.exe's LTO object file, or short import library file
+      if (memcmp(Magic.data() + 1, "\0\xFF\xFF", 3) == 0) {
         size_t MinSize = offsetof(COFF::BigObjHeader, UUID) + sizeof(COFF::BigObjMagic);
         if (Magic.size() < MinSize)
           return file_magic::coff_import_library;
 
-        int BigObjVersion = read16le(
-            Magic.data() + offsetof(COFF::BigObjHeader, Version));
-        if (BigObjVersion < COFF::BigObjHeader::MinBigObjectVersion)
-          return file_magic::coff_import_library;
-
         const char *Start = Magic.data() + offsetof(COFF::BigObjHeader, UUID);
-        if (memcmp(Start, COFF::BigObjMagic, sizeof(COFF::BigObjMagic)) != 0)
-          return file_magic::coff_import_library;
-        return file_magic::coff_object;
+        if (memcmp(Start, COFF::BigObjMagic, sizeof(COFF::BigObjMagic)) == 0)
+          return file_magic::coff_object;
+        if (memcmp(Start, COFF::ClGlObjMagic, sizeof(COFF::BigObjMagic)) == 0)
+          return file_magic::coff_cl_gl_object;
+        return file_magic::coff_import_library;
       }
       // Windows resource file
       const char Expected[] = { 0, 0, 0, 0, '\x20', 0, 0, 0, '\xff' };


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26645.77923.patch
Type: text/x-patch
Size: 3397 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161115/44744253/attachment.bin>


More information about the llvm-commits mailing list