[llvm] r192742 - Path: Recognize Windows compiled resource file.

Rui Ueyama ruiu at google.com
Tue Oct 15 15:45:38 PDT 2013


Author: ruiu
Date: Tue Oct 15 17:45:38 2013
New Revision: 192742

URL: http://llvm.org/viewvc/llvm-project?rev=192742&view=rev
Log:
Path: Recognize Windows compiled resource file.

Some background: One can pass compiled resource files (.res files) directly
to the linker on Windows. If a resource file is given, the linker will run
"cvtres" command in background to convert the resource file to a COFF file
to link it.

What I'm trying to do with this patch is to make the linker to recognize
the resource file by file magic, so that it can run cvtres command.

Differential Revision: http://llvm-reviews.chandlerc.com/D1943

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

Modified: llvm/trunk/include/llvm/Support/FileSystem.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileSystem.h?rev=192742&r1=192741&r2=192742&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/FileSystem.h (original)
+++ llvm/trunk/include/llvm/Support/FileSystem.h Tue Oct 15 17:45:38 2013
@@ -238,7 +238,8 @@ struct file_magic {
     macho_dsym_companion,     ///< Mach-O dSYM companion file
     macho_universal_binary,   ///< Mach-O universal binary
     coff_object,              ///< COFF object file
-    pecoff_executable         ///< PECOFF executable file
+    pecoff_executable,        ///< PECOFF executable file
+    windows_resource,         ///< Windows compiled resource file (.rc)
   };
 
   bool is_object() const {

Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp?rev=192742&r1=192741&r2=192742&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp Tue Oct 15 17:45:38 2013
@@ -553,6 +553,7 @@ ObjectImage *RuntimeDyld::loadObject(Obj
     case sys::fs::file_magic::coff_object:
     case sys::fs::file_magic::pecoff_executable:
     case sys::fs::file_magic::macho_universal_binary:
+    case sys::fs::file_magic::windows_resource:
       report_fatal_error("Incompatible object format!");
     }
   } else {

Modified: llvm/trunk/lib/Object/Binary.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/Binary.cpp?rev=192742&r1=192741&r2=192742&view=diff
==============================================================================
--- llvm/trunk/lib/Object/Binary.cpp (original)
+++ llvm/trunk/lib/Object/Binary.cpp Tue Oct 15 17:45:38 2013
@@ -100,7 +100,8 @@ error_code object::createBinary(MemoryBu
       return object_error::success;
     }
     case sys::fs::file_magic::unknown:
-    case sys::fs::file_magic::bitcode: {
+    case sys::fs::file_magic::bitcode:
+    case sys::fs::file_magic::windows_resource: {
       // Unrecognized object file format.
       return object_error::invalid_file_type;
     }

Modified: llvm/trunk/lib/Object/ObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ObjectFile.cpp?rev=192742&r1=192741&r2=192742&view=diff
==============================================================================
--- llvm/trunk/lib/Object/ObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/ObjectFile.cpp Tue Oct 15 17:45:38 2013
@@ -49,6 +49,7 @@ ObjectFile *ObjectFile::createObjectFile
   case sys::fs::file_magic::bitcode:
   case sys::fs::file_magic::archive:
   case sys::fs::file_magic::macho_universal_binary:
+  case sys::fs::file_magic::windows_resource:
     delete Object;
     return 0;
   case sys::fs::file_magic::elf_relocatable:

Modified: llvm/trunk/lib/Support/Path.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Path.cpp?rev=192742&r1=192741&r2=192742&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Path.cpp (original)
+++ llvm/trunk/lib/Support/Path.cpp Tue Oct 15 17:45:38 2013
@@ -847,6 +847,14 @@ error_code has_magic(const Twine &path,
   if (Magic.size() < 4)
     return file_magic::unknown;
   switch ((unsigned char)Magic[0]) {
+    case 0x00: {
+      // Windows resource file
+      const char Expected[] = "\0\0\0\0\x20\0\0\0\xff";
+      if (Magic.size() >= sizeof(Expected) &&
+          memcmp(Magic.data(), Expected, sizeof(Expected)) == 0)
+        return file_magic::windows_resource;
+      break;
+    }
     case 0xDE:  // 0x0B17C0DE = BC wraper
       if (Magic[1] == (char)0xC0 && Magic[2] == (char)0x17 &&
           Magic[3] == (char)0x0B)





More information about the llvm-commits mailing list