For PR1302:

Implement file tests for both LinkInLibrary and LinkInFile to determine if
the file is native. Don't generate warnings if the file is native.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35653 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Reid Spencer 2007-04-04 06:33:17 +00:00
parent 58de557181
commit c8539731bd

View File

@ -33,14 +33,17 @@ Linker::LinkInItems(const ItemList& Items, ItemList& NativeItems) {
if (I->second) { if (I->second) {
// Link in the library suggested. // Link in the library suggested.
bool is_bytecode = true; bool is_bytecode = true;
if (LinkInLibrary(I->first,is_bytecode)) if (LinkInLibrary(I->first, is_bytecode))
return true; return true;
if (!is_bytecode) if (!is_bytecode)
NativeItems.push_back(*I); NativeItems.push_back(*I);
} else { } else {
// Link in the file suggested // Link in the file suggested
if (LinkInFile(sys::Path(I->first))) bool is_native = false;
if (LinkInFile(sys::Path(I->first), is_native))
return true; return true;
if (is_native)
NativeItems.push_back(*I);
} }
} }
@ -61,8 +64,8 @@ Linker::LinkInItems(const ItemList& Items, ItemList& NativeItems) {
/// LinkInLibrary - links one library into the HeadModule. /// LinkInLibrary - links one library into the HeadModule.
/// ///
bool Linker::LinkInLibrary(const std::string& Lib, bool& is_bytecode) { bool Linker::LinkInLibrary(const std::string& Lib, bool& is_native) {
is_bytecode = false; is_native = false;
// Determine where this library lives. // Determine where this library lives.
sys::Path Pathname = FindLib(Lib); sys::Path Pathname = FindLib(Lib);
if (Pathname.isEmpty()) if (Pathname.isEmpty())
@ -72,20 +75,27 @@ bool Linker::LinkInLibrary(const std::string& Lib, bool& is_bytecode) {
std::string Magic; std::string Magic;
Pathname.getMagicNumber(Magic, 64); Pathname.getMagicNumber(Magic, 64);
switch (sys::IdentifyFileType(Magic.c_str(), 64)) { switch (sys::IdentifyFileType(Magic.c_str(), 64)) {
case sys::BytecodeFileType: default: assert(0 && "Bad file type identification");
case sys::CompressedBytecodeFileType: case sys::Unknown_FileType:
return warning("Supposed library '" + Lib + "' isn't a library.");
case sys::Bytecode_FileType:
case sys::CompressedBytecode_FileType:
// LLVM ".so" file. // LLVM ".so" file.
if (LinkInFile(Pathname)) if (LinkInFile(Pathname, is_native))
return error("Cannot link file '" + Pathname.toString() + "'"); return error("Cannot link file '" + Pathname.toString() + "'");
is_bytecode = true;
break; break;
case sys::ArchiveFileType:
case sys::Archive_FileType:
if (LinkInArchive(Pathname)) if (LinkInArchive(Pathname))
return error("Cannot link archive '" + Pathname.toString() + "'"); return error("Cannot link archive '" + Pathname.toString() + "'");
is_bytecode = true;
break; break;
default:
return warning("Supposed library '" + Lib + "' isn't a library."); case sys::ELF_FileType:
case sys::Mach_O_FileType:
case sys::COFF_FileType:
is_native = true;
break;
} }
return false; return false;
} }
@ -135,19 +145,32 @@ bool Linker::LinkInLibraries(const std::vector<std::string> &Libraries) {
/// TRUE - An error occurred. /// TRUE - An error occurred.
/// FALSE - No errors. /// FALSE - No errors.
/// ///
bool Linker::LinkInFile(const sys::Path &File) { bool Linker::LinkInFile(const sys::Path &File, bool &is_native) {
is_native = false;
// Make sure we can at least read the file // Make sure we can at least read the file
if (!File.canRead()) if (!File.canRead())
return error("Cannot find linker input '" + File.toString() + "'"); return error("Cannot find linker input '" + File.toString() + "'");
// If its an archive, try to link it in
std::string Magic;
File.getMagicNumber(Magic, 64);
switch (sys::IdentifyFileType(Magic.c_str(), 64)) {
default: assert(0 && "Bad file type identification");
case sys::Unknown_FileType:
return warning("Supposed object file '" + File.toString() +
"' not recognized as such");
case sys::Archive_FileType:
// A user may specify an ar archive without -l, perhaps because it // A user may specify an ar archive without -l, perhaps because it
// is not installed as a library. Detect that and link the library. // is not installed as a library. Detect that and link the archive.
if (File.isArchive()) { verbose("Linking archive file '" + File.toString() + "'");
if (LinkInArchive(File)) if (LinkInArchive(File))
return error("Cannot link archive '" + File.toString() + "'"); return error("Cannot link archive '" + File.toString() + "'");
} else if (File.isBytecodeFile()) { break;
verbose("Linking bytecode file '" + File.toString() + "'");
case sys::Bytecode_FileType:
case sys::CompressedBytecode_FileType: {
verbose("Linking bytecode file '" + File.toString() + "'");
std::auto_ptr<Module> M(LoadObject(File)); std::auto_ptr<Module> M(LoadObject(File));
if (M.get() == 0) if (M.get() == 0)
return error("Cannot load file '" + File.toString() + "'" + Error); return error("Cannot load file '" + File.toString() + "'" + Error);
@ -155,8 +178,14 @@ bool Linker::LinkInFile(const sys::Path &File) {
return error("Cannot link file '" + File.toString() + "'" + Error); return error("Cannot link file '" + File.toString() + "'" + Error);
verbose("Linked in file '" + File.toString() + "'"); verbose("Linked in file '" + File.toString() + "'");
} else { break;
return warning("File of unknown type '" + File.toString() + "' ignored."); }
case sys::ELF_FileType:
case sys::Mach_O_FileType:
case sys::COFF_FileType:
is_native = true;
break;
} }
return false; return false;
} }
@ -175,8 +204,9 @@ bool Linker::LinkInFile(const sys::Path &File) {
/// TRUE - Some error occurred. /// TRUE - Some error occurred.
/// ///
bool Linker::LinkInFiles(const std::vector<sys::Path> &Files) { bool Linker::LinkInFiles(const std::vector<sys::Path> &Files) {
bool is_native;
for (unsigned i = 0; i < Files.size(); ++i) for (unsigned i = 0; i < Files.size(); ++i)
if (LinkInFile(Files[i])) if (LinkInFile(Files[i], is_native))
return true; return true;
return false; return false;
} }