diff --git a/llvm/include/llvm/BinaryFormat/Magic.h b/llvm/include/llvm/BinaryFormat/Magic.h --- a/llvm/include/llvm/BinaryFormat/Magic.h +++ b/llvm/include/llvm/BinaryFormat/Magic.h @@ -51,6 +51,7 @@ wasm_object, ///< WebAssembly Object file pdb, ///< Windows PDB debug info file tapi_file, ///< Text-based Dynamic Library Stub file + cuda_fatbinary, ///< CUDA Fatbinary object file }; bool is_object() const { return V != unknown; } diff --git a/llvm/lib/BinaryFormat/Magic.cpp b/llvm/lib/BinaryFormat/Magic.cpp --- a/llvm/lib/BinaryFormat/Magic.cpp +++ b/llvm/lib/BinaryFormat/Magic.cpp @@ -185,6 +185,10 @@ case 0x84: // Alpha 64-bit case 0x66: // MPS R4000 Windows case 0x50: // mc68K + if (startswith(Magic, "\x50\xed\x55\xba")) + return file_magic::cuda_fatbinary; + LLVM_FALLTHROUGH; + case 0x4c: // 80386 Windows case 0xc4: // ARMNT Windows if (Magic[1] == 0x01) diff --git a/llvm/lib/Object/Binary.cpp b/llvm/lib/Object/Binary.cpp --- a/llvm/lib/Object/Binary.cpp +++ b/llvm/lib/Object/Binary.cpp @@ -82,6 +82,7 @@ // PDB does not support the Binary interface. return errorCodeToError(object_error::invalid_file_type); case file_magic::unknown: + case file_magic::cuda_fatbinary: case file_magic::coff_cl_gl_object: // Unrecognized object file format. return errorCodeToError(object_error::invalid_file_type); diff --git a/llvm/lib/Object/ObjectFile.cpp b/llvm/lib/Object/ObjectFile.cpp --- a/llvm/lib/Object/ObjectFile.cpp +++ b/llvm/lib/Object/ObjectFile.cpp @@ -146,6 +146,7 @@ case file_magic::pdb: case file_magic::minidump: case file_magic::goff_object: + case file_magic::cuda_fatbinary: return errorCodeToError(object_error::invalid_file_type); case file_magic::tapi_file: return errorCodeToError(object_error::invalid_file_type);