- if (!File.readable())
- return error("Cannot find linker input '" + File.toString() + "'");
-
- // A user may specify an ar archive without -l, perhaps because it
- // is not installed as a library. Detect that and link the library.
- if (File.isArchive()) {
- if (LinkInArchive(File))
- return error("Cannot link archive '" + File.toString() + "'");
- } else if (File.isBytecodeFile()) {
- verbose("Linking bytecode file '" + File.toString() + "'");
-
- std::auto_ptr<Module> M(LoadObject(File));
- if (M.get() == 0)
- return error("Cannot load file '" + File.toString() + "'" + Error);
- if (LinkInModule(M.get()))
- return error("Cannot link file '" + File.toString() + "'" + Error);
-
- verbose("Linked in file '" + File.toString() + "'");
- } else {
- return warning("File of unknown type '" + File.toString() + "' ignored.");
+ if (!File.canRead())
+ return error("Cannot find linker input '" + File.str() + "'");
+
+ // If its an archive, try to link it in
+ std::string Magic;
+ File.getMagicNumber(Magic, 64);
+ switch (sys::IdentifyFileType(Magic.c_str(), 64)) {
+ default: llvm_unreachable("Bad file type identification");
+ case sys::Unknown_FileType:
+ return warning("Ignoring file '" + File.str() +
+ "' because does not contain bitcode.");
+
+ case sys::Archive_FileType:
+ // A user may specify an ar archive without -l, perhaps because it
+ // is not installed as a library. Detect that and link the archive.
+ verbose("Linking archive file '" + File.str() + "'");
+ if (LinkInArchive(File, is_native))
+ return true;
+ break;
+
+ case sys::Bitcode_FileType: {
+ verbose("Linking bitcode file '" + File.str() + "'");
+ std::auto_ptr<Module> M(LoadObject(File));
+ if (M.get() == 0)
+ return error("Cannot load file '" + File.str() + "': " + Error);
+ if (LinkInModule(M.get(), &Error))
+ return error("Cannot link file '" + File.str() + "': " + Error);
+
+ verbose("Linked in file '" + File.str() + "'");
+ break;
+ }
+
+ case sys::ELF_Relocatable_FileType:
+ case sys::ELF_SharedObject_FileType:
+ case sys::Mach_O_Object_FileType:
+ case sys::Mach_O_FixedVirtualMemorySharedLib_FileType:
+ case sys::Mach_O_DynamicallyLinkedSharedLib_FileType:
+ case sys::Mach_O_DynamicallyLinkedSharedLibStub_FileType:
+ case sys::COFF_FileType:
+ is_native = true;
+ break;