From 6cc8ca92291c8b18d8aa88d43c50dd25d0740ca4 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 28 Nov 2003 07:44:09 +0000 Subject: [PATCH] * The return value of LinkLibraries is ignored, so remove it. * Finegrainify namespacification of Linker.cpp * If linking a library in fails, do not STOP LINKING IN LIBRARIES AND CONTINUE ANYWAY! Instead, just output the warning, and keep going. :) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10249 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Linker/LinkArchives.cpp | 63 ++++++++++++++++--------------------- tools/gccld/Linker.cpp | 63 ++++++++++++++++--------------------- tools/gccld/gccld.h | 11 +++---- 3 files changed, 58 insertions(+), 79 deletions(-) diff --git a/lib/Linker/LinkArchives.cpp b/lib/Linker/LinkArchives.cpp index a009cf59d69..c230206d7e0 100644 --- a/lib/Linker/LinkArchives.cpp +++ b/lib/Linker/LinkArchives.cpp @@ -29,8 +29,7 @@ #include #include #include - -namespace llvm { +using namespace llvm; /// 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 @@ -39,9 +38,9 @@ namespace llvm { /// named by the value of the environment variable LLVM_LIB_SEARCH_PATH. Returns /// an empty string if no matching file can be found. /// -std::string FindLib(const std::string &Filename, - const std::vector &Paths, - bool SharedObjectOnly) { +std::string llvm::FindLib(const std::string &Filename, + const std::vector &Paths, + bool SharedObjectOnly) { // Determine if the pathname can be found as it stands. if (FileOpenable(Filename)) return Filename; @@ -79,7 +78,8 @@ std::string FindLib(const std::string &Filename, /// GetAllDefinedSymbols - Modifies its parameter DefinedSymbols to contain the /// name of each externally-visible symbol defined in M. /// -void GetAllDefinedSymbols(Module *M, std::set &DefinedSymbols) { +void llvm::GetAllDefinedSymbols(Module *M, + std::set &DefinedSymbols) { for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) if (I->hasName() && !I->isExternal() && !I->hasInternalLinkage()) DefinedSymbols.insert(I->getName()); @@ -101,7 +101,8 @@ void GetAllDefinedSymbols(Module *M, std::set &DefinedSymbols) { /// undefined symbols. /// void -GetAllUndefinedSymbols(Module *M, std::set &UndefinedSymbols) { +llvm::GetAllUndefinedSymbols(Module *M, + std::set &UndefinedSymbols) { std::set DefinedSymbols; UndefinedSymbols.clear(); // Start out empty @@ -134,8 +135,8 @@ GetAllUndefinedSymbols(Module *M, std::set &UndefinedSymbols) { /// module it contains (wrapped in an auto_ptr), or 0 and set ErrorMessage if an /// error occurs. /// -std::auto_ptr LoadObject(const std::string &FN, - std::string &ErrorMessage) { +std::auto_ptr llvm::LoadObject(const std::string &FN, + std::string &ErrorMessage) { std::string ParserErrorMessage; Module *Result = ParseBytecodeFile(FN, &ParserErrorMessage); if (Result) return std::auto_ptr(Result); @@ -280,11 +281,8 @@ static bool LinkInFile(Module *HeadModule, /// FALSE - No errors. /// TRUE - Some error occurred. /// -bool LinkFiles(const char *progname, - Module *HeadModule, - const std::vector &Files, - bool Verbose) -{ +bool llvm::LinkFiles(const char *progname, Module *HeadModule, + const std::vector &Files, bool Verbose) { // String in which to receive error messages. std::string ErrorMessage; @@ -359,13 +357,10 @@ bool LinkFiles(const char *progname, /// FALSE - No error. /// TRUE - Error. /// -bool LinkLibraries(const char *progname, - Module *HeadModule, - const std::vector &Libraries, - const std::vector &LibPaths, - bool Verbose, - bool Native) -{ +void llvm::LinkLibraries(const char *progname, Module *HeadModule, + const std::vector &Libraries, + const std::vector &LibPaths, + bool Verbose, bool Native) { // String in which to receive error messages. std::string ErrorMessage; @@ -377,9 +372,9 @@ bool LinkLibraries(const char *progname, // we're doing a native link and give an error if we're doing a bytecode // link. if (!Native) { - PrintAndReturn(progname, "Cannot find library -l" + Libraries[i] - + "\n"); - return true; + std::cerr << progname << ": WARNING: Cannot find library -l" + << Libraries[i] << "\n"; + continue; } } @@ -391,10 +386,10 @@ bool LinkLibraries(const char *progname, << Libraries[i] << ")\n"; if (LinkInArchive(HeadModule, Pathname, ErrorMessage, Verbose)) { - PrintAndReturn(progname, ErrorMessage, - ": Error linking in archive '" + Pathname - + "' (-l" + Libraries[i] + ")"); - return true; + std::cerr << progname << ": " << ErrorMessage + << ": Error linking in archive '" << Pathname << "' (-l" + << Libraries[i] << ")\n"; + exit(1); } } else if (IsBytecode(Pathname)) { if (Verbose) @@ -402,15 +397,11 @@ bool LinkLibraries(const char *progname, << "' (-l" << Libraries[i] << ")\n"; if (LinkInFile(HeadModule, Pathname, ErrorMessage, Verbose)) { - PrintAndReturn(progname, ErrorMessage, - ": error linking in bytecode file '" + Pathname - + "' (-l" + Libraries[i] + ")"); - return true; + std::cerr << progname << ": " << ErrorMessage + << ": error linking in bytecode file '" << Pathname << "' (-l" + << Libraries[i] << ")\n"; + exit(1); } } } - - return false; } - -} // End llvm namespace diff --git a/tools/gccld/Linker.cpp b/tools/gccld/Linker.cpp index a009cf59d69..c230206d7e0 100644 --- a/tools/gccld/Linker.cpp +++ b/tools/gccld/Linker.cpp @@ -29,8 +29,7 @@ #include #include #include - -namespace llvm { +using namespace llvm; /// 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 @@ -39,9 +38,9 @@ namespace llvm { /// named by the value of the environment variable LLVM_LIB_SEARCH_PATH. Returns /// an empty string if no matching file can be found. /// -std::string FindLib(const std::string &Filename, - const std::vector &Paths, - bool SharedObjectOnly) { +std::string llvm::FindLib(const std::string &Filename, + const std::vector &Paths, + bool SharedObjectOnly) { // Determine if the pathname can be found as it stands. if (FileOpenable(Filename)) return Filename; @@ -79,7 +78,8 @@ std::string FindLib(const std::string &Filename, /// GetAllDefinedSymbols - Modifies its parameter DefinedSymbols to contain the /// name of each externally-visible symbol defined in M. /// -void GetAllDefinedSymbols(Module *M, std::set &DefinedSymbols) { +void llvm::GetAllDefinedSymbols(Module *M, + std::set &DefinedSymbols) { for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) if (I->hasName() && !I->isExternal() && !I->hasInternalLinkage()) DefinedSymbols.insert(I->getName()); @@ -101,7 +101,8 @@ void GetAllDefinedSymbols(Module *M, std::set &DefinedSymbols) { /// undefined symbols. /// void -GetAllUndefinedSymbols(Module *M, std::set &UndefinedSymbols) { +llvm::GetAllUndefinedSymbols(Module *M, + std::set &UndefinedSymbols) { std::set DefinedSymbols; UndefinedSymbols.clear(); // Start out empty @@ -134,8 +135,8 @@ GetAllUndefinedSymbols(Module *M, std::set &UndefinedSymbols) { /// module it contains (wrapped in an auto_ptr), or 0 and set ErrorMessage if an /// error occurs. /// -std::auto_ptr LoadObject(const std::string &FN, - std::string &ErrorMessage) { +std::auto_ptr llvm::LoadObject(const std::string &FN, + std::string &ErrorMessage) { std::string ParserErrorMessage; Module *Result = ParseBytecodeFile(FN, &ParserErrorMessage); if (Result) return std::auto_ptr(Result); @@ -280,11 +281,8 @@ static bool LinkInFile(Module *HeadModule, /// FALSE - No errors. /// TRUE - Some error occurred. /// -bool LinkFiles(const char *progname, - Module *HeadModule, - const std::vector &Files, - bool Verbose) -{ +bool llvm::LinkFiles(const char *progname, Module *HeadModule, + const std::vector &Files, bool Verbose) { // String in which to receive error messages. std::string ErrorMessage; @@ -359,13 +357,10 @@ bool LinkFiles(const char *progname, /// FALSE - No error. /// TRUE - Error. /// -bool LinkLibraries(const char *progname, - Module *HeadModule, - const std::vector &Libraries, - const std::vector &LibPaths, - bool Verbose, - bool Native) -{ +void llvm::LinkLibraries(const char *progname, Module *HeadModule, + const std::vector &Libraries, + const std::vector &LibPaths, + bool Verbose, bool Native) { // String in which to receive error messages. std::string ErrorMessage; @@ -377,9 +372,9 @@ bool LinkLibraries(const char *progname, // we're doing a native link and give an error if we're doing a bytecode // link. if (!Native) { - PrintAndReturn(progname, "Cannot find library -l" + Libraries[i] - + "\n"); - return true; + std::cerr << progname << ": WARNING: Cannot find library -l" + << Libraries[i] << "\n"; + continue; } } @@ -391,10 +386,10 @@ bool LinkLibraries(const char *progname, << Libraries[i] << ")\n"; if (LinkInArchive(HeadModule, Pathname, ErrorMessage, Verbose)) { - PrintAndReturn(progname, ErrorMessage, - ": Error linking in archive '" + Pathname - + "' (-l" + Libraries[i] + ")"); - return true; + std::cerr << progname << ": " << ErrorMessage + << ": Error linking in archive '" << Pathname << "' (-l" + << Libraries[i] << ")\n"; + exit(1); } } else if (IsBytecode(Pathname)) { if (Verbose) @@ -402,15 +397,11 @@ bool LinkLibraries(const char *progname, << "' (-l" << Libraries[i] << ")\n"; if (LinkInFile(HeadModule, Pathname, ErrorMessage, Verbose)) { - PrintAndReturn(progname, ErrorMessage, - ": error linking in bytecode file '" + Pathname - + "' (-l" + Libraries[i] + ")"); - return true; + std::cerr << progname << ": " << ErrorMessage + << ": error linking in bytecode file '" << Pathname << "' (-l" + << Libraries[i] << ")\n"; + exit(1); } } } - - return false; } - -} // End llvm namespace diff --git a/tools/gccld/gccld.h b/tools/gccld/gccld.h index a2d2eb8d6ad..e5b865e3a4f 100644 --- a/tools/gccld/gccld.h +++ b/tools/gccld/gccld.h @@ -62,13 +62,10 @@ std::string FindLib(const std::string &Filename, const std::vector &Paths, bool SharedObjectOnly = false); -bool -LinkLibraries (const char * progname, - Module * HeadModule, - const std::vector & Libraries, - const std::vector & LibPaths, - bool Verbose, - bool Native); +void LinkLibraries (const char * progname, Module* HeadModule, + const std::vector & Libraries, + const std::vector & LibPaths, + bool Verbose, bool Native); bool LinkFiles (const char * progname, Module * HeadModule, -- 2.34.1