From fc149a69cf43009c8f174ef80af1cb396ffcca37 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Tue, 15 Oct 2013 22:45:38 +0000 Subject: 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 llvm-svn: 192742 --- llvm/lib/Support/Path.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'llvm/lib/Support/Path.cpp') diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp index 8d707aedded..390614b9a5b 100644 --- a/llvm/lib/Support/Path.cpp +++ b/llvm/lib/Support/Path.cpp @@ -847,6 +847,14 @@ error_code has_magic(const Twine &path, const Twine &magic, bool &result) { 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) -- cgit v1.2.3