diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2004-12-13 02:59:52 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2004-12-13 02:59:52 +0000 |
commit | e84de29663f4b8fc0540218540b93b74ca145e1b (patch) | |
tree | 9ffc601edcdca3b5f867e94fbe2ed7b6b973b3fc /lib/Linker | |
parent | 3ece6397cbb3179b15bb7446a97bbe9883cbbed6 (diff) |
For PR351: \
* Remove redundant static function LinkOneLibrary. \
* Remove unneded #includes \
* Convert FileSupport usage to sys::Path instead
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18857 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Linker')
-rw-r--r-- | lib/Linker/LinkItems.cpp | 134 |
1 files changed, 12 insertions, 122 deletions
diff --git a/lib/Linker/LinkItems.cpp b/lib/Linker/LinkItems.cpp index d055a4d028..f43166c861 100644 --- a/lib/Linker/LinkItems.cpp +++ b/lib/Linker/LinkItems.cpp @@ -14,98 +14,22 @@ #include "llvm/Linker.h" #include "llvm/Module.h" -#include "llvm/ModuleProvider.h" -#include "llvm/PassManager.h" -#include "llvm/ADT/SetOperations.h" -#include "llvm/Bytecode/Reader.h" -#include "llvm/Bytecode/Archive.h" -#include "llvm/Bytecode/WriteBytecodePass.h" -#include "llvm/Target/TargetData.h" -#include "llvm/Transforms/IPO.h" -#include "llvm/Transforms/Scalar.h" -#include "llvm/Config/config.h" -#include "llvm/Support/CommandLine.h" -#include "llvm/Support/FileUtilities.h" -#include "llvm/Support/Timer.h" -#include "llvm/System/Signals.h" -#include "llvm/Support/SystemUtils.h" -#include <algorithm> -#include <fstream> -#include <memory> -#include <set> -using namespace llvm; - -static bool -LinkOneLibrary(const char*progname, Module* HeadModule, - const std::string& Lib, - const std::vector<std::string>& LibPaths, - bool Verbose, bool Native) { - - // String in which to receive error messages. - std::string ErrorMessage; - - // Determine where this library lives. - std::string Pathname = FindLib(Lib, LibPaths); - if (Pathname.empty()) { - // If the pathname does not exist, then simply return if we're doing a - // native link and give a warning if we're doing a bytecode link. - if (!Native) { - std::cerr << progname << ": warning: Cannot find library '" - << Lib << "'\n"; - return false; - } - } - - // 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 (IsArchive(Pathname)) { - if (Verbose) - std::cerr << "Trying to link archive '" << Pathname << "' (-l" - << Lib << ")\n"; - if (LinkInArchive(HeadModule, Pathname, &ErrorMessage, Verbose)) { - std::cerr << progname << ": " << ErrorMessage - << ": Error linking in archive '" << Pathname << "' (-l" - << Lib << ")\n"; - return true; - } - } else { - std::cerr << progname << ": WARNING: Supposed library -l" - << Lib << " isn't a library.\n"; - } - return false; -} +using namespace llvm; // LinkItems - preserve link order for an arbitrary set of linkage items. -Module* -llvm::LinkItems(const char *progname, const LinkItemList& Items, - const std::vector<std::string>& LibPaths, - bool Verbose, bool Native) { - - // Construct the HeadModule to contain the result of the linkage - std::auto_ptr<Module> HeadModule(new Module(progname)); - - // Construct a mutable path list we can add paths to. This list will always - // have LLVM_LIB_SEARCH_PATH at the end so we place it there now. - std::vector<std::string> MyLibPaths(LibPaths); - MyLibPaths.insert(MyLibPaths.begin(),"."); - char* SearchPath = getenv("LLVM_LIB_SEARCH_PATH"); - if (SearchPath) - MyLibPaths.push_back(SearchPath); - +bool +Linker::LinkInItems(const ItemList& Items) { // For each linkage item ... - for (LinkItemList::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. - if (LinkOneLibrary(progname,HeadModule.get(),I->first,MyLibPaths, - Verbose,Native)) - return 0; + if (LinkInLibrary(I->first)) + return true; } else { - std::vector<std::string> Files; - Files.push_back(I->first); - if (LinkFiles(progname,HeadModule.get(),Files,Verbose)) - return 0; + if (LinkInFile(sys::Path(I->first))) + return true; } } @@ -114,46 +38,12 @@ llvm::LinkItems(const char *progname, const LinkItemList& 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. - const Module::LibraryListType& DepLibs = HeadModule->getLibraries(); + const Module::LibraryListType& DepLibs = Composite->getLibraries(); for (Module::LibraryListType::const_iterator I = DepLibs.begin(), E = DepLibs.end(); I != E; ++I) { - if(LinkOneLibrary(progname,HeadModule.get(),*I,MyLibPaths,Verbose,Native)) - return 0; + if(LinkInLibrary(*I)) + return true; } - return HeadModule.release(); -} - -// BuildLinkItems -- This function -void llvm::BuildLinkItems( - LinkItemList& Items, - const cl::list<std::string>& Files, - const cl::list<std::string>& Libraries) { - - // Build the list of linkage items for LinkItems. - - cl::list<std::string>::const_iterator fileIt = Files.begin(); - cl::list<std::string>::const_iterator libIt = Libraries.begin(); - - int libPos = -1, filePos = -1; - while ( 1 ) { - if (libIt != Libraries.end()) - libPos = Libraries.getPosition(libIt - Libraries.begin()); - else - libPos = -1; - if (fileIt != Files.end()) - filePos = Files.getPosition(fileIt - Files.begin()); - else - filePos = -1; - - if (filePos != -1 && (libPos == -1 || filePos < libPos)) { - // Add a source file - Items.push_back(std::make_pair(*fileIt++, false)); - } else if (libPos != -1 && (filePos == -1 || libPos < filePos)) { - // Add a library - Items.push_back(std::make_pair(*libIt++, true)); - } else { - break; // we're done with the list - } - } + return false; } |