17#if !defined(_MSC_VER) && !defined(__MINGW32__)
36 switch ((
unsigned char)Magic[0]) {
42 if (Magic.size() < MinSize)
113 if (
startswith(Magic,
"\177ELF") && Magic.size() >= 18) {
114 bool Data2MSB = Magic[5] == 2;
115 unsigned high = Data2MSB ? 16 : 17;
116 unsigned low = Data2MSB ? 17 : 16;
117 if (Magic[high] == 0) {
118 switch (Magic[low]) {
141 if (Magic.size() >= 8 && Magic[7] < 43)
157 if (Magic[3] ==
char(0xCE))
161 if (Magic.size() >= MinSize)
162 type = Magic[12] << 24 | Magic[13] << 12 | Magic[14] << 8 | Magic[15];
163 }
else if (
startswith(Magic,
"\xCE\xFA\xED\xFE") ||
167 if (Magic[0] ==
char(0xCE))
171 if (Magic.size() >= MinSize)
172 type = Magic[15] << 24 | Magic[14] << 12 | Magic[13] << 8 | Magic[12];
215 if (Magic[1] == 0x01)
221 if (Magic[1] == 0x02)
227 if (
startswith(Magic,
"MZ") && Magic.size() >= 0x3c + 4) {
230 if (Magic.substr(off).starts_with(
234 if (Magic.starts_with(
"Microsoft C/C++ MSF 7.00\r\n"))
241 if (Magic[1] ==
char(0x86) || Magic[1] ==
char(0xaa))
259 if (Magic[1] ==
char(0xA6))
264 if (Magic[1] ==
char(0xA6))
269 const char OBMagic[] =
"__CLANG_OFFLOAD_BUNDLE__";
270 if (Magic.size() >=
sizeof(OBMagic) &&
startswith(Magic, OBMagic))
285 return FileOrError.getError();
287 std::unique_ptr<MemoryBuffer> FileBuffer = std::move(*FileOrError);
290 return std::error_code();
#define offsetof(TYPE, MEMBER)
static bool startswith(StringRef Magic, const char(&S)[N])
Merge contiguous icmps into a memcmp
std::pair< llvm::MachO::Target, std::string > UUID
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static const char ClGlObjMagic[]
static const char WinResMagic[]
static const char BigObjMagic[]
static const char PEMagic[]
uint32_t read32le(const void *P)
This is an optimization pass for GlobalISel generic memory operations.
file_magic identify_magic(StringRef magic)
Identify the type of a binary file based on how magical it is.
file_magic - An "enum class" enumeration of file types based on magic (the first N bytes of the file)...
@ coff_import_library
COFF import library.
@ pdb
Windows PDB debug info file.
@ spirv_object
A binary SPIR-V file.
@ elf_relocatable
ELF Relocatable object file.
@ archive
ar style archive file
@ elf_shared_object
ELF dynamically linked shared lib.
@ goff_object
GOFF object file.
@ minidump
Windows minidump file.
@ macho_dynamically_linked_shared_lib
Mach-O dynlinked shared lib.
@ xcoff_object_64
64-bit XCOFF object file
@ elf_executable
ELF Executable image.
@ macho_dynamically_linked_shared_lib_stub
Mach-O Shared lib stub.
@ macho_preload_executable
Mach-O Preloaded Executable.
@ offload_bundle
Clang offload bundle file.
@ offload_bundle_compressed
Compressed clang offload bundle file.
@ macho_file_set
Mach-O file set binary.
@ dxcontainer_object
DirectX container file.
@ macho_kext_bundle
Mach-O kext bundle file.
@ pecoff_executable
PECOFF executable file.
@ offload_binary
LLVM offload object file.
@ macho_universal_binary
Mach-O universal binary.
@ macho_core
Mach-O Core File.
@ wasm_object
WebAssembly Object file.
@ xcoff_object_32
32-bit XCOFF object file
@ windows_resource
Windows compiled resource file (.res)
@ clang_ast
Clang PCH or PCM.
@ elf_core
ELF core image.
@ macho_object
Mach-O Object file.
@ coff_object
COFF object file.
@ macho_bundle
Mach-O Bundle file.
@ coff_cl_gl_object
Microsoft cl.exe's intermediate code file.
@ cuda_fatbinary
CUDA Fatbinary object file.
@ macho_executable
Mach-O Executable.
@ macho_dsym_companion
Mach-O dSYM companion file.
@ unknown
Unrecognized file.
@ macho_fixed_virtual_memory_shared_lib
Mach-O Shared Lib, FVM.
@ macho_dynamic_linker
The Mach-O dynamic linker.
@ tapi_file
Text-based Dynamic Library Stub file.