diff --git a/include/llvm/BinaryFormat/Magic.h b/include/llvm/BinaryFormat/Magic.h index c0e23db5e1a..4ac826e4c50 100644 --- a/include/llvm/BinaryFormat/Magic.h +++ b/include/llvm/BinaryFormat/Magic.h @@ -45,7 +45,8 @@ struct file_magic { coff_import_library, ///< COFF import library pecoff_executable, ///< PECOFF executable file windows_resource, ///< Windows compiled resource file (.res) - wasm_object ///< WebAssembly Object file + wasm_object, ///< WebAssembly Object file + pdb, ///< Windows PDB debug info file }; bool is_object() const { return V != unknown; } diff --git a/lib/BinaryFormat/Magic.cpp b/lib/BinaryFormat/Magic.cpp index 42546eaa732..22ea2280433 100644 --- a/lib/BinaryFormat/Magic.cpp +++ b/lib/BinaryFormat/Magic.cpp @@ -181,7 +181,7 @@ file_magic llvm::identify_magic(StringRef Magic) { return file_magic::coff_object; break; - case 'M': // Possible MS-DOS stub on Windows PE file + case 'M': // Possible MS-DOS stub on Windows PE file or MSF/PDB file. if (startswith(Magic, "MZ") && Magic.size() >= 0x3c + 4) { uint32_t off = read32le(Magic.data() + 0x3c); // PE/COFF file, either EXE or DLL. @@ -189,6 +189,8 @@ file_magic llvm::identify_magic(StringRef Magic) { StringRef(COFF::PEMagic, sizeof(COFF::PEMagic)))) return file_magic::pecoff_executable; } + if (Magic.startswith("Microsoft C/C++ MSF 7.00\r\n")) + return file_magic::pdb; break; case 0x64: // x86-64 or ARM64 Windows. diff --git a/unittests/BinaryFormat/TestFileMagic.cpp b/unittests/BinaryFormat/TestFileMagic.cpp index ca4ca9a2728..5f132ba4144 100644 --- a/unittests/BinaryFormat/TestFileMagic.cpp +++ b/unittests/BinaryFormat/TestFileMagic.cpp @@ -81,6 +81,8 @@ const char windows_resource[] = const char macho_dynamically_linked_shared_lib_stub[] = "\xfe\xed\xfa\xce........\x00\x00\x00\x09............"; const char ms_dos_stub_broken[] = "\x4d\x5a\x20\x20"; +const char pdb[] = "Microsoft C/C++ MSF 7.00\r\n\x1a" + "DS\x00\x00\x00"; TEST_F(MagicTest, Magic) { struct type { @@ -110,6 +112,7 @@ TEST_F(MagicTest, Magic) { DEFINE(macho_dsym_companion), DEFINE(macho_kext_bundle), DEFINE(windows_resource), + DEFINE(pdb), {"ms_dos_stub_broken", ms_dos_stub_broken, sizeof(ms_dos_stub_broken), file_magic::unknown}, #undef DEFINE