diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -267,6 +267,7 @@ make(mbref, withLOption ? path::filename(path) : path)); return; case file_magic::bitcode: + case file_magic::fatlto_object: case file_magic::elf_relocatable: if (inLib) files.push_back(createLazyFile(mbref, "", 0)); diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -380,6 +380,10 @@ return identify_magic(mb.getBuffer()) == llvm::file_magic::bitcode; } +inline bool isFatLTOObject(MemoryBufferRef mb) { + return identify_magic(mb.getBuffer()) == llvm::file_magic::fatlto_object; +} + std::string replaceThinLTOSuffix(StringRef path); } // namespace elf 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 @@ -54,6 +54,7 @@ cuda_fatbinary, ///< CUDA Fatbinary object file offload_binary, ///< LLVM offload object file dxcontainer_object, ///< DirectX container file + fatlto_object, ///< FatLTO 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 @@ -79,6 +79,12 @@ return file_magic::offload_binary; break; + case 0xFA: + if (startswith(Magic, "\xFAtl\x70")) { + return file_magic::fatlto_object; + } + break; + case 0xDE: // 0x0B17C0DE = BC wraper if (startswith(Magic, "\xDE\xC0\x17\x0B")) return file_magic::bitcode; 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 @@ -55,6 +55,7 @@ case file_magic::elf_executable: case file_magic::elf_shared_object: case file_magic::elf_core: + case file_magic::fatlto_object: case file_magic::goff_object: case file_magic::macho_object: case file_magic::macho_executable: 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 @@ -157,6 +157,7 @@ case file_magic::elf_executable: case file_magic::elf_shared_object: case file_magic::elf_core: + case file_magic::fatlto_object: return createELFObjectFile(Object, InitContent); case file_magic::macho_object: case file_magic::macho_executable: