diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-04-04 06:30:26 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-04-04 06:30:26 +0000 |
commit | 8bb5fd17f9a715ac9ce87619f3b6c1066a244859 (patch) | |
tree | bf299dd6eefc6762d26ab53844ccbfa6a52db546 /lib/System | |
parent | 73ca166145fe2de4e1eadbcc25bacc4a5ad95346 (diff) | |
download | external_llvm-8bb5fd17f9a715ac9ce87619f3b6c1066a244859.zip external_llvm-8bb5fd17f9a715ac9ce87619f3b6c1066a244859.tar.gz external_llvm-8bb5fd17f9a715ac9ce87619f3b6c1066a244859.tar.bz2 |
For PR1302:
Implement recognition of COFF, ELF and Mach-O object/shared lib files.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35650 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System')
-rw-r--r-- | lib/System/Path.cpp | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/lib/System/Path.cpp b/lib/System/Path.cpp index 1246038..b599c9c 100644 --- a/lib/System/Path.cpp +++ b/lib/System/Path.cpp @@ -44,25 +44,54 @@ sys::IdentifyFileType(const char*magic, unsigned length) { assert(length >=4 && "Invalid magic number length"); switch (magic[0]) { case 'l': - if (magic[1] == 'l' && magic[2] == 'v') { + if (magic[1] == 'l' && magic[2] == 'v') if (magic[3] == 'c') - return CompressedBytecodeFileType; + return CompressedBytecode_FileType; else if (magic[3] == 'm') - return BytecodeFileType; - } + return Bytecode_FileType; break; - case '!': - if (length >= 8) { + if (length >= 8) if (memcmp(magic,"!<arch>\n",8) == 0) - return ArchiveFileType; - } + return Archive_FileType; + break; + + case '\177': + if (magic[1] == 'E' && magic[2] == 'L' && magic[3] == 'F') + return ELF_FileType; + break; + + case 0xCE: + case 0xCF: + // This is complicated by an overlap with Java class files. + // See the Mach-O section in /usr/share/file/magic for details. + if (magic[1] == char(0xFA) && magic[2] == char(0xED) && + magic[3] == char(0xFE)) + if (length >= 15) + if (magic[15] == 1 || magic[15] == 3 || magic[15] == 6 || + magic[15] == 9) + return Mach_O_FileType; + break; + + case 0xF0: // PowerPC Windows + case 0x83: // Alpha 32-bit + case 0x84: // Alpha 64-bit + case 0x66: // MPS R4000 Windows + case 0x50: // mc68K + case 0x4c: // 80386 Windows + if (magic[1] == 0x01) + return COFF_FileType; + + case 0x90: // PA-RISC Windows + case 0x68: // mc68K Windows + if (magic[1] == 0x02) + return COFF_FileType; break; default: break; } - return UnknownFileType; + return Unknown_FileType; } bool |