mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-02 07:11:49 +00:00
Teach sys::Path how to recognize different kinds of object files for ELF
and Mach-O systems. Additionally, correct the Mach-O logic code to look at byte 12 not byte 15. Hopefully this fixes the llvm-ld warning on Darwin. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35876 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
f4b1818728
commit
947aa7de67
@ -597,13 +597,24 @@ namespace sys {
|
||||
|
||||
/// This enumeration delineates the kinds of files that LLVM knows about.
|
||||
enum LLVMFileType {
|
||||
Unknown_FileType = 0, ///< Unrecognized file
|
||||
Bytecode_FileType = 1, ///< Uncompressed bytecode file
|
||||
CompressedBytecode_FileType = 2, ///< Compressed bytecode file
|
||||
Archive_FileType = 3, ///< ar style archive file
|
||||
ELF_FileType = 4, ///< Native ELF object file or lib
|
||||
Mach_O_FileType = 5, ///< Native Mach-O object file or lib
|
||||
COFF_FileType = 6 ///< COFF object file or lib
|
||||
Unknown_FileType = 0, ///< Unrecognized file
|
||||
Bytecode_FileType, ///< Uncompressed bytecode file
|
||||
CompressedBytecode_FileType, ///< Compressed bytecode file
|
||||
Archive_FileType, ///< ar style archive file
|
||||
ELF_Relocatable_FileType, ///< ELF Relocatable object file
|
||||
ELF_Executable_FileType, ///< ELF Executable image
|
||||
ELF_SharedObject_FileType, ///< ELF dynamically linked shared lib
|
||||
ELF_Core_FileType, ///< ELF core image
|
||||
Mach_O_Object_FileType, ///< Mach-O Object file
|
||||
Mach_O_Executable_FileType, ///< Mach-O Executable
|
||||
Mach_O_FixedVirtualMemorySharedLib_FileType, ///< Mach-O Shared Lib, FVM
|
||||
Mach_O_Core_FileType, ///< Mach-O Core File
|
||||
Mach_O_PreloadExectuable_FileType, ///< Mach-O Preloaded Executable
|
||||
Mach_O_DynamicallyLinkedSharedLib_FileType, ///< Mach-O dynlinked shared lib
|
||||
Mach_O_DynamicLinker_FileType, ///< The Mach-O dynamic linker
|
||||
Mach_O_Bundle_FileType, ///< Mach-O Bundle file
|
||||
Mach_O_DynamicallyLinkedSharedLibStub_FileType, ///< Mach-O Shared lib stub
|
||||
COFF_FileType ///< COFF object file or lib
|
||||
};
|
||||
|
||||
/// This utility function allows any memory block to be examined in order
|
||||
|
@ -58,7 +58,14 @@ sys::IdentifyFileType(const char*magic, unsigned length) {
|
||||
|
||||
case '\177':
|
||||
if (magic[1] == 'E' && magic[2] == 'L' && magic[3] == 'F')
|
||||
return ELF_FileType;
|
||||
if (length >= 18 && magic[17] == 0)
|
||||
switch (magic[16]) {
|
||||
default: break;
|
||||
case 1: return ELF_Relocatable_FileType;
|
||||
case 2: return ELF_Executable_FileType;
|
||||
case 3: return ELF_SharedObject_FileType;
|
||||
case 4: return ELF_Core_FileType;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0xCE:
|
||||
@ -67,10 +74,19 @@ sys::IdentifyFileType(const char*magic, unsigned length) {
|
||||
// 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;
|
||||
if (length >= 14 && magic[13] == 0)
|
||||
switch (magic[12]) {
|
||||
default: break;
|
||||
case 1: return Mach_O_Object_FileType;
|
||||
case 2: return Mach_O_Executable_FileType;
|
||||
case 3: return Mach_O_FixedVirtualMemorySharedLib_FileType;
|
||||
case 4: return Mach_O_Core_FileType;
|
||||
case 5: return Mach_O_PreloadExectuable_FileType;
|
||||
case 6: return Mach_O_DynamicallyLinkedSharedLib_FileType;
|
||||
case 7: return Mach_O_DynamicLinker_FileType;
|
||||
case 8: return Mach_O_Bundle_FileType;
|
||||
case 9: return Mach_O_DynamicallyLinkedSharedLibStub_FileType;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0xF0: // PowerPC Windows
|
||||
@ -108,8 +124,10 @@ Path::isDynamicLibrary() const {
|
||||
if (getMagicNumber(Magic, 64))
|
||||
switch (IdentifyFileType(Magic.c_str(), Magic.length())) {
|
||||
default: return false;
|
||||
case ELF_FileType:
|
||||
case Mach_O_FileType:
|
||||
case Mach_O_FixedVirtualMemorySharedLib_FileType:
|
||||
case Mach_O_DynamicallyLinkedSharedLib_FileType:
|
||||
case Mach_O_DynamicallyLinkedSharedLibStub_FileType:
|
||||
case ELF_SharedObject_FileType:
|
||||
case COFF_FileType: return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user