diff options
Diffstat (limited to 'lib/Linker')
-rw-r--r-- | lib/Linker/LinkArchives.cpp | 30 | ||||
-rw-r--r-- | lib/Linker/LinkItems.cpp | 18 | ||||
-rw-r--r-- | lib/Linker/LinkModules.cpp | 36 | ||||
-rw-r--r-- | lib/Linker/Linker.cpp | 28 |
4 files changed, 56 insertions, 56 deletions
diff --git a/lib/Linker/LinkArchives.cpp b/lib/Linker/LinkArchives.cpp index af15e0b1ad..5165bad199 100644 --- a/lib/Linker/LinkArchives.cpp +++ b/lib/Linker/LinkArchives.cpp @@ -1,10 +1,10 @@ //===- lib/Linker/LinkArchives.cpp - Link LLVM objects and libraries ------===// -// +// // The LLVM Compiler Infrastructure // // This file was developed by the LLVM research group and is distributed under // the University of Illinois Open Source License. See LICENSE.TXT for details. -// +// //===----------------------------------------------------------------------===// // // This file contains routines to handle linking together LLVM bytecode files, @@ -26,7 +26,7 @@ using namespace llvm; /// GetAllDefinedSymbols - Modifies its parameter DefinedSymbols to contain the /// name of each externally-visible symbol defined in M. /// -static void +static void GetAllDefinedSymbols(Module *M, std::set<std::string> &DefinedSymbols) { for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) if (I->hasName() && !I->isExternal() && !I->hasInternalLinkage()) @@ -60,7 +60,7 @@ GetAllUndefinedSymbols(Module *M, std::set<std::string> &UndefinedSymbols) { Function *Main = M->getMainFunction(); if (Main == 0 || Main->isExternal()) UndefinedSymbols.insert("main"); - + for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) if (I->hasName()) { if (I->isExternal()) @@ -76,7 +76,7 @@ GetAllUndefinedSymbols(Module *M, std::set<std::string> &UndefinedSymbols) { else if (!I->hasInternalLinkage()) DefinedSymbols.insert(I->getName()); } - + // Prune out any defined symbols from the undefined symbols set... for (std::set<std::string>::iterator I = UndefinedSymbols.begin(); I != UndefinedSymbols.end(); ) @@ -95,7 +95,7 @@ GetAllUndefinedSymbols(Module *M, std::set<std::string> &UndefinedSymbols) { /// Return Value: /// TRUE - An error occurred. /// FALSE - No errors. -bool +bool Linker::LinkInArchive(const sys::Path &Filename) { // Make sure this is an archive file we're dealing with @@ -110,9 +110,9 @@ Linker::LinkInArchive(const sys::Path &Filename) { // no reason to link in any archive files. std::set<std::string> UndefinedSymbols; GetAllUndefinedSymbols(Composite, UndefinedSymbols); - + if (UndefinedSymbols.empty()) { - verbose("No symbols undefined, skipping library '" + + verbose("No symbols undefined, skipping library '" + Filename.toString() + "'"); return false; // No need to link anything in! } @@ -124,7 +124,7 @@ Linker::LinkInArchive(const sys::Path &Filename) { Archive* arch = AutoArch.get(); if (!arch) - return error("Cannot read archive '" + Filename.toString() + + return error("Cannot read archive '" + Filename.toString() + "': " + ErrMsg); // Save a set of symbols that are not defined by the archive. Since we're @@ -133,13 +133,13 @@ Linker::LinkInArchive(const sys::Path &Filename) { std::set<std::string> NotDefinedByArchive; // While we are linking in object files, loop. - while (true) { + while (true) { // Find the modules we need to link into the target module std::set<ModuleProvider*> Modules; arch->findModulesDefiningSymbols(UndefinedSymbols, Modules); - // If we didn't find any more modules to link this time, we are done + // If we didn't find any more modules to link this time, we are done // searching this archive. if (Modules.empty()) break; @@ -162,7 +162,7 @@ Linker::LinkInArchive(const sys::Path &Filename) { // Link it in if (LinkInModule(aModule)) - return error("Cannot link in module '" + + return error("Cannot link in module '" + aModule->getModuleIdentifier() + "': " + Error); } @@ -171,17 +171,17 @@ Linker::LinkInArchive(const sys::Path &Filename) { GetAllUndefinedSymbols(Composite, UndefinedSymbols); // At this point we have two sets of undefined symbols: UndefinedSymbols - // which holds the undefined symbols from all the modules, and + // which holds the undefined symbols from all the modules, and // NotDefinedByArchive which holds symbols we know the archive doesn't // define. There's no point searching for symbols that we won't find in the // archive so we subtract these sets. set_subtract(UndefinedSymbols, NotDefinedByArchive); - + // If there's no symbols left, no point in continuing to search the // archive. if (UndefinedSymbols.empty()) break; } - + return false; } diff --git a/lib/Linker/LinkItems.cpp b/lib/Linker/LinkItems.cpp index b3fb5b00cf..34677ce365 100644 --- a/lib/Linker/LinkItems.cpp +++ b/lib/Linker/LinkItems.cpp @@ -1,10 +1,10 @@ //===- lib/Linker/LinkItems.cpp - Link LLVM objects and libraries ---------===// -// +// // The LLVM Compiler Infrastructure // -// This file was developed by Reid Spencer and is distributed under the +// This file was developed by Reid Spencer and is distributed under the // University of Illinois Open Source License. See LICENSE.TXT for details. -// +// //===----------------------------------------------------------------------===// // // This file contains routines to handle linking together LLVM bytecode files, @@ -21,7 +21,7 @@ using namespace llvm; bool Linker::LinkInItems(const ItemList& Items) { // For each linkage item ... - for (ItemList::const_iterator I = Items.begin(), E = Items.end(); + for (ItemList::const_iterator I = Items.begin(), E = Items.end(); I != E; ++I) { if (I->second) { // Link in the library suggested. @@ -38,7 +38,7 @@ Linker::LinkInItems(const ItemList& Items) { // that module should also be aggregated with duplicates eliminated. This is // now the time to process the dependent libraries to resolve any remaining // symbols. - for (Module::lib_iterator I = Composite->lib_begin(), + for (Module::lib_iterator I = Composite->lib_begin(), E = Composite->lib_end(); I != E; ++I) if(LinkInLibrary(*I)) return true; @@ -95,9 +95,9 @@ bool Linker::LinkInLibraries(const std::vector<std::string> &Libraries) { // now the time to process the dependent libraries to resolve any remaining // symbols. const Module::LibraryListType& DepLibs = Composite->getLibraries(); - for (Module::LibraryListType::const_iterator I = DepLibs.begin(), - E = DepLibs.end(); I != E; ++I) - if (LinkInLibrary(*I)) + for (Module::LibraryListType::const_iterator I = DepLibs.begin(), + E = DepLibs.end(); I != E; ++I) + if (LinkInLibrary(*I)) return true; return false; @@ -130,7 +130,7 @@ bool Linker::LinkInFile(const sys::Path &File) { verbose("Linking bytecode file '" + File.toString() + "'"); std::auto_ptr<Module> M(LoadObject(File)); - if (M.get() == 0) + if (M.get() == 0) return error("Cannot load file '" + File.toString() + "'" + Error); if (LinkInModule(M.get())) return error("Cannot link file '" + File.toString() + "'" + Error); diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 627a38cd0f..6daf061048 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -1,10 +1,10 @@ //===- lib/Linker/LinkModules.cpp - Module Linker Implementation ----------===// -// +// // The LLVM Compiler Infrastructure // // This file was developed by the LLVM research group and is distributed under // the University of Illinois Open Source License. See LICENSE.TXT for details. -// +// //===----------------------------------------------------------------------===// // // This file implements the LLVM module linker. @@ -98,11 +98,11 @@ static bool RecursiveResolveTypesI(const PATypeHolder &DestTy, const Type *SrcTyT = SrcTy.get(); const Type *DestTyT = DestTy.get(); if (DestTyT == SrcTyT) return false; // If already equal, noop - + // If we found our opaque type, resolve it now! if (isa<OpaqueType>(DestTyT) || isa<OpaqueType>(SrcTyT)) return ResolveTypes(DestTyT, SrcTyT, DestST, Name); - + // Two types cannot be resolved together if they are of different primitive // type. For example, we cannot resolve an int to a float. if (DestTyT->getTypeID() != SrcTyT->getTypeID()) return true; @@ -123,7 +123,7 @@ static bool RecursiveResolveTypesI(const PATypeHolder &DestTy, return false; } case Type::StructTyID: { - if (getST(DestTy)->getNumContainedTypes() != + if (getST(DestTy)->getNumContainedTypes() != getST(SrcTy)->getNumContainedTypes()) return 1; for (unsigned i = 0, e = getST(DestTy)->getNumContainedTypes(); i != e; ++i) if (RecursiveResolveTypesI(getST(DestTy)->getContainedType(i), @@ -159,7 +159,7 @@ static bool RecursiveResolveTypesI(const PATypeHolder &DestTy, return Result; } default: assert(0 && "Unexpected type!"); return true; - } + } } static bool RecursiveResolveTypes(const PATypeHolder &DestTy, @@ -229,7 +229,7 @@ static bool LinkTypes(Module *Dest, const Module *Src, std::string *Err) { if (!RecursiveResolveTypes(T2, T1, DestST, Name)) { // We are making progress! DelayedTypesToResolve.erase(DelayedTypesToResolve.begin()+i); - + // Go back to the main loop, perhaps we can resolve directly by name // now... break; @@ -407,7 +407,7 @@ static bool GetLinkageResult(GlobalValue *Dest, GlobalValue *Src, } else { assert(Dest->hasExternalLinkage() && Src->hasExternalLinkage() && "Unexpected linkage type!"); - return Error(Err, "Linking globals named '" + Src->getName() + + return Error(Err, "Linking globals named '" + Src->getName() + "': symbol multiply defined!"); } return false; @@ -423,7 +423,7 @@ static bool LinkGlobals(Module *Dest, Module *Src, // We will need a module level symbol table if the src module has a module // level symbol table... SymbolTable *ST = (SymbolTable*)&Dest->getSymbolTable(); - + // Loop over all of the globals in the src module, mapping them over as we go for (Module::global_iterator I = Src->global_begin(), E = Src->global_end(); I != E; ++I) { GlobalVariable *SGV = I; @@ -541,11 +541,11 @@ static bool LinkGlobalInits(Module *Dest, const Module *Src, Constant *SInit = cast<Constant>(RemapOperand(SGV->getInitializer(), ValueMap)); - GlobalVariable *DGV = cast<GlobalVariable>(ValueMap[SGV]); + GlobalVariable *DGV = cast<GlobalVariable>(ValueMap[SGV]); if (DGV->hasInitializer()) { if (SGV->hasExternalLinkage()) { if (DGV->getInitializer() != SInit) - return Error(Err, "Global Variable Collision on '" + + return Error(Err, "Global Variable Collision on '" + ToStr(SGV->getType(), Src) +"':%"+SGV->getName()+ " - Global variables have different initializers"); } else if (DGV->hasLinkOnceLinkage() || DGV->hasWeakLinkage()) { @@ -577,7 +577,7 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src, std::map<std::string, GlobalValue*> &GlobalsByName, std::string *Err) { SymbolTable *ST = (SymbolTable*)&Dest->getSymbolTable(); - + // Loop over all of the functions in the src module, mapping them over as we // go for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) { @@ -637,8 +637,8 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src, "' have different linkage specifiers!"); } else if (SF->hasExternalLinkage()) { // The function is defined in both modules!! - return Error(Err, "Function '" + - ToStr(SF->getFunctionType(), Src) + "':\"" + + return Error(Err, "Function '" + + ToStr(SF->getFunctionType(), Src) + "':\"" + SF->getName() + "\" - Function is already defined!"); } else { assert(0 && "Unknown linkage configuration found!"); @@ -718,7 +718,7 @@ static bool LinkAppendingVars(Module *M, std::multimap<std::string, GlobalVariable *> &AppendingVars, std::string *ErrorMsg) { if (AppendingVars.empty()) return false; // Nothing to do. - + // Loop over the multimap of appending vars, processing any variables with the // same name, forming a new appending global variable with both of the // initializers merged together, then rewrite references to the old variables @@ -735,7 +735,7 @@ static bool LinkAppendingVars(Module *M, GlobalVariable *G1 = First->second, *G2 = Second->second; const ArrayType *T1 = cast<ArrayType>(G1->getType()->getElementType()); const ArrayType *T2 = cast<ArrayType>(G2->getType()->getElementType()); - + // Check to see that they two arrays agree on type... if (T1->getElementType() != T2->getElementType()) return Error(ErrorMsg, @@ -803,7 +803,7 @@ static bool LinkAppendingVars(Module *M, // error occurs, true is returned and ErrorMsg (if not null) is set to indicate // the problem. Upon failure, the Dest module could be in a modified state, and // shouldn't be relied on to be consistent. -bool +bool Linker::LinkModules(Module *Dest, Module *Src, std::string *ErrorMsg) { assert(Dest != 0 && "Invalid Destination module"); assert(Src != 0 && "Invalid Source Module"); @@ -824,7 +824,7 @@ Linker::LinkModules(Module *Dest, Module *Src, std::string *ErrorMsg) { if (!Src->getTargetTriple().empty() && Dest->getTargetTriple() != Src->getTargetTriple()) std::cerr << "WARNING: Linking two modules of different target triples!\n"; - + // Update the destination module's dependent libraries list with the libraries // from the source module. There's no opportunity for duplicates here as the // Module ensures that duplicate insertions are discarded. diff --git a/lib/Linker/Linker.cpp b/lib/Linker/Linker.cpp index 19fd861c4d..e09c788593 100644 --- a/lib/Linker/Linker.cpp +++ b/lib/Linker/Linker.cpp @@ -1,10 +1,10 @@ //===- lib/Linker/Linker.cpp - Basic Linker functionality ----------------===// -// +// // The LLVM Compiler Infrastructure // -// This file was developed by Reid Spencer and is distributed under the +// This file was developed by Reid Spencer and is distributed under the // University of Illinois Open Source License. See LICENSE.TXT for details. -// +// //===----------------------------------------------------------------------===// // // This file contains basic Linker functionality that all usages will need. @@ -42,7 +42,7 @@ Linker::~Linker() { delete Composite; } -bool +bool Linker::error(const std::string& message) { Error = message; if (!(Flags&QuietErrors)) { @@ -99,23 +99,23 @@ Linker::releaseModule() { } // LoadObject - Read in and parse the bytecode file named by FN and return the -// module it contains (wrapped in an auto_ptr), or auto_ptr<Module>() and set +// module it contains (wrapped in an auto_ptr), or auto_ptr<Module>() and set // Error if an error occurs. -std::auto_ptr<Module> +std::auto_ptr<Module> Linker::LoadObject(const sys::Path &FN) { std::string ParseErrorMessage; Module *Result = ParseBytecodeFile(FN.toString(), &ParseErrorMessage); - if (Result) + if (Result) return std::auto_ptr<Module>(Result); Error = "Bytecode file '" + FN.toString() + "' could not be loaded"; - if (ParseErrorMessage.size()) + if (ParseErrorMessage.size()) Error += ": " + ParseErrorMessage; return std::auto_ptr<Module>(); } -// IsLibrary - Determine if "Name" is a library in "Directory". Return +// IsLibrary - Determine if "Name" is a library in "Directory". Return // a non-empty sys::Path if its found, an empty one otherwise. -static inline sys::Path IsLibrary(const std::string& Name, +static inline sys::Path IsLibrary(const std::string& Name, const sys::Path& Directory) { assert(Directory.isDirectory() && "Need to specify a directory"); @@ -145,15 +145,15 @@ static inline sys::Path IsLibrary(const std::string& Name, /// FindLib - Try to convert Filename into the name of a file that we can open, /// if it does not already name a file we can open, by first trying to open /// Filename, then libFilename.[suffix] for each of a set of several common -/// library suffixes, in each of the directories in LibPaths. Returns an empty +/// library suffixes, in each of the directories in LibPaths. Returns an empty /// Path if no matching file can be found. /// -sys::Path -Linker::FindLib(const std::string &Filename) +sys::Path +Linker::FindLib(const std::string &Filename) { // Determine if the pathname can be found as it stands. sys::Path FilePath(Filename); - if (FilePath.readable() && + if (FilePath.readable() && (FilePath.isArchive() || FilePath.isDynamicLibrary())) return FilePath; |