llvm.org GIT mirror llvm / 947aa7d
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 Reid Spencer 13 years ago
2 changed file(s) with 43 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
596596
597597 /// This enumeration delineates the kinds of files that LLVM knows about.
598598 enum LLVMFileType {
599 Unknown_FileType = 0, ///< Unrecognized file
600 Bytecode_FileType = 1, ///< Uncompressed bytecode file
601 CompressedBytecode_FileType = 2, ///< Compressed bytecode file
602 Archive_FileType = 3, ///< ar style archive file
603 ELF_FileType = 4, ///< Native ELF object file or lib
604 Mach_O_FileType = 5, ///< Native Mach-O object file or lib
605 COFF_FileType = 6 ///< COFF object file or lib
599 Unknown_FileType = 0, ///< Unrecognized file
600 Bytecode_FileType, ///< Uncompressed bytecode file
601 CompressedBytecode_FileType, ///< Compressed bytecode file
602 Archive_FileType, ///< ar style archive file
603 ELF_Relocatable_FileType, ///< ELF Relocatable object file
604 ELF_Executable_FileType, ///< ELF Executable image
605 ELF_SharedObject_FileType, ///< ELF dynamically linked shared lib
606 ELF_Core_FileType, ///< ELF core image
607 Mach_O_Object_FileType, ///< Mach-O Object file
608 Mach_O_Executable_FileType, ///< Mach-O Executable
609 Mach_O_FixedVirtualMemorySharedLib_FileType, ///< Mach-O Shared Lib, FVM
610 Mach_O_Core_FileType, ///< Mach-O Core File
611 Mach_O_PreloadExectuable_FileType, ///< Mach-O Preloaded Executable
612 Mach_O_DynamicallyLinkedSharedLib_FileType, ///< Mach-O dynlinked shared lib
613 Mach_O_DynamicLinker_FileType, ///< The Mach-O dynamic linker
614 Mach_O_Bundle_FileType, ///< Mach-O Bundle file
615 Mach_O_DynamicallyLinkedSharedLibStub_FileType, ///< Mach-O Shared lib stub
616 COFF_FileType ///< COFF object file or lib
606617 };
607618
608619 /// This utility function allows any memory block to be examined in order
5757
5858 case '\177':
5959 if (magic[1] == 'E' && magic[2] == 'L' && magic[3] == 'F')
60 return ELF_FileType;
60 if (length >= 18 && magic[17] == 0)
61 switch (magic[16]) {
62 default: break;
63 case 1: return ELF_Relocatable_FileType;
64 case 2: return ELF_Executable_FileType;
65 case 3: return ELF_SharedObject_FileType;
66 case 4: return ELF_Core_FileType;
67 }
6168 break;
6269
6370 case 0xCE:
6673 // See the Mach-O section in /usr/share/file/magic for details.
6774 if (magic[1] == char(0xFA) && magic[2] == char(0xED) &&
6875 magic[3] == char(0xFE))
69 if (length >= 15)
70 if (magic[15] == 1 || magic[15] == 3 || magic[15] == 6 ||
71 magic[15] == 9)
72 return Mach_O_FileType;
76 if (length >= 14 && magic[13] == 0)
77 switch (magic[12]) {
78 default: break;
79 case 1: return Mach_O_Object_FileType;
80 case 2: return Mach_O_Executable_FileType;
81 case 3: return Mach_O_FixedVirtualMemorySharedLib_FileType;
82 case 4: return Mach_O_Core_FileType;
83 case 5: return Mach_O_PreloadExectuable_FileType;
84 case 6: return Mach_O_DynamicallyLinkedSharedLib_FileType;
85 case 7: return Mach_O_DynamicLinker_FileType;
86 case 8: return Mach_O_Bundle_FileType;
87 case 9: return Mach_O_DynamicallyLinkedSharedLibStub_FileType;
88 }
7389 break;
7490
7591 case 0xF0: // PowerPC Windows
107123 if (getMagicNumber(Magic, 64))
108124 switch (IdentifyFileType(Magic.c_str(), Magic.length())) {
109125 default: return false;
110 case ELF_FileType:
111 case Mach_O_FileType:
126 case Mach_O_FixedVirtualMemorySharedLib_FileType:
127 case Mach_O_DynamicallyLinkedSharedLib_FileType:
128 case Mach_O_DynamicallyLinkedSharedLibStub_FileType:
129 case ELF_SharedObject_FileType:
112130 case COFF_FileType: return true;
113131 }
114132 }