diff options
author | Chris Lattner <sabre@nondot.org> | 2003-05-13 22:14:13 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-05-13 22:14:13 +0000 |
commit | 7cb77e188f52b61f3a71ca361704d88e6d146d03 (patch) | |
tree | f43b2b8045f27df4b164e6cacf4d0cd1ea81257f /tools/gccld | |
parent | 0ec3590664dda705ac9039de403460cca5b947c1 (diff) | |
download | external_llvm-7cb77e188f52b61f3a71ca361704d88e6d146d03.zip external_llvm-7cb77e188f52b61f3a71ca361704d88e6d146d03.tar.gz external_llvm-7cb77e188f52b61f3a71ca361704d88e6d146d03.tar.bz2 |
Search LLVM_LIB_SEARCH_PATH for objects to allow it to find crtend.o
Implement minor library linking optimization.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6181 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/gccld')
-rw-r--r-- | tools/gccld/gccld.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/tools/gccld/gccld.cpp b/tools/gccld/gccld.cpp index 24c624e..6be78c2 100644 --- a/tools/gccld/gccld.cpp +++ b/tools/gccld/gccld.cpp @@ -79,12 +79,20 @@ static inline bool FileExists(const std::string &FN) { // LoadObject - Read the specified "object file", which should not search the // library path to find it. -static inline std::auto_ptr<Module> LoadObject(const std::string &FN, +static inline std::auto_ptr<Module> LoadObject(std::string FN, std::string &OutErrorMessage) { if (Verbose) std::cerr << "Loading '" << FN << "'\n"; if (!FileExists(FN)) { - OutErrorMessage = "could not find input file '" + FN + "'!"; - return std::auto_ptr<Module>(); + // Attempt to load from the LLVM_LIB_SEARCH_PATH directory... if we would + // otherwise fail. This is used to locate objects like crtend.o. + // + char *SearchPath = getenv("LLVM_LIB_SEARCH_PATH"); + if (SearchPath && FileExists(std::string(SearchPath)+"/"+FN)) + FN = std::string(SearchPath)+"/"+FN; + else { + OutErrorMessage = "could not find input file '" + FN + "'!"; + return std::auto_ptr<Module>(); + } } std::string ErrorMessage; @@ -224,6 +232,13 @@ static void GetAllUndefinedSymbols(Module *M, static bool LinkLibrary(Module *M, const std::string &LibName, std::string &ErrorMessage) { + std::set<std::string> UndefinedSymbols; + GetAllUndefinedSymbols(M, UndefinedSymbols); + if (UndefinedSymbols.empty()) { + if (Verbose) std::cerr << " No symbols undefined, don't link library!\n"; + return false; // No need to link anything in! + } + std::vector<Module*> Objects; bool isArchive; if (LoadLibrary(LibName, Objects, isArchive, ErrorMessage)) return true; @@ -234,9 +249,6 @@ static bool LinkLibrary(Module *M, const std::string &LibName, for (unsigned i = 0; i != Objects.size(); ++i) GetAllDefinedSymbols(Objects[i], DefinedSymbols[i]); - std::set<std::string> UndefinedSymbols; - GetAllUndefinedSymbols(M, UndefinedSymbols); - bool Linked = true; while (Linked) { // While we are linking in object files, loop. Linked = false; |