[PATCH] Path: Recognize Windows compiled resource file.

Rui Ueyama ruiu at google.com
Tue Oct 15 14:04:58 PDT 2013


Hi Bigcheese,

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.

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

Files:
  include/llvm/Support/FileSystem.h
  lib/Support/Path.cpp

Index: include/llvm/Support/FileSystem.h
===================================================================
--- include/llvm/Support/FileSystem.h
+++ include/llvm/Support/FileSystem.h
@@ -238,7 +238,8 @@
     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
+    resource,                 ///< Windows compiled resource file (.rc)
   };
 
   bool is_object() const {
Index: lib/Support/Path.cpp
===================================================================
--- lib/Support/Path.cpp
+++ lib/Support/Path.cpp
@@ -847,6 +847,14 @@
   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::resource;
+      break;
+    }
     case 0xDE:  // 0x0B17C0DE = BC wraper
       if (Magic[1] == (char)0xC0 && Magic[2] == (char)0x17 &&
           Magic[3] == (char)0x0B)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1943.1.patch
Type: text/x-patch
Size: 1290 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131015/c8ec946f/attachment.bin>


More information about the llvm-commits mailing list