summaryrefslogtreecommitdiff
path: root/lib/Linker
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2004-12-02 09:52:10 +0000
committerReid Spencer <rspencer@reidspencer.com>2004-12-02 09:52:10 +0000
commitbe0b356593c5d87c93e83250a99878878fc62c31 (patch)
tree132ece3092bb9b48edc98d5eaa56fc77d33e11c1 /lib/Linker
parent8aa9a8ca989c9e5c14e278550f17521a35a781cb (diff)
downloadllvm-be0b356593c5d87c93e83250a99878878fc62c31.tar.gz
llvm-be0b356593c5d87c93e83250a99878878fc62c31.tar.bz2
llvm-be0b356593c5d87c93e83250a99878878fc62c31.tar.xz
PR466:
* Make the linker find lib*.bca files now instead of lib*.bc since those are what the makefiles now generate for bytecode archives. * Make sure the linker only links archives when LinkLibraries is called. Previously if it found a lib*.bc file and that file was a bytecode file, it would link in the entire bytecode. This could make -lc -lc fail with duplicate symbols error but it shouldn't as searching multiple libraries, even the same one more than once, is permitted. * Now that the above problems are corrected, implement the dependent libs feature. After the module is linked with all specified libraries, the LinkLibraries function will obtain the set of dependent libraries from the linked modules and attemp to find and link against those libraries. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18428 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Linker')
-rw-r--r--lib/Linker/LinkArchives.cpp95
1 files changed, 54 insertions, 41 deletions
diff --git a/lib/Linker/LinkArchives.cpp b/lib/Linker/LinkArchives.cpp
index af17ff31b8..9476ca56d2 100644
--- a/lib/Linker/LinkArchives.cpp
+++ b/lib/Linker/LinkArchives.cpp
@@ -57,8 +57,8 @@ std::string llvm::FindLib(const std::string &Filename,
for (unsigned Index = 0; Index != Paths.size(); ++Index) {
std::string Directory = Paths[Index] + "/";
- if (!SharedObjectOnly && FileOpenable(Directory + LibName + ".bc"))
- return Directory + LibName + ".bc";
+ if (!SharedObjectOnly && FileOpenable(Directory + LibName + ".bca"))
+ return Directory + LibName + ".bca";
if (FileOpenable(Directory + LibName + LTDL_SHLIB_EXT))
return Directory + LibName + LTDL_SHLIB_EXT;
@@ -352,6 +352,46 @@ bool llvm::LinkFiles(const char *progname, Module *HeadModule,
return false;
}
+/// LinkOneLibrary - links one library of any kind into the HeadModule
+static inline void 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 -l"
+ << Lib << "\n";
+ return;
+ }
+ }
+
+ // 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";
+ exit(1);
+ }
+ } else {
+ std::cerr << progname << ": WARNING: Supposed library -l"
+ << Lib << " isn't a library.\n";
+ }
+}
+
/// LinkLibraries - takes the specified library files and links them into the
/// main bytecode object file.
///
@@ -374,47 +414,20 @@ void llvm::LinkLibraries(const char *progname, Module *HeadModule,
const std::vector<std::string> &Libraries,
const std::vector<std::string> &LibPaths,
bool Verbose, bool Native) {
- // String in which to receive error messages.
- std::string ErrorMessage;
+ // Process the set of libraries we've been provided
for (unsigned i = 0; i < Libraries.size(); ++i) {
- // Determine where this library lives.
- std::string Pathname = FindLib(Libraries[i], LibPaths);
- if (Pathname.empty()) {
- // If the pathname does not exist, then continue to the next one if
- // we're doing a native link and give an error if we're doing a bytecode
- // link.
- if (!Native) {
- std::cerr << progname << ": WARNING: Cannot find library -l"
- << Libraries[i] << "\n";
- continue;
- }
- }
-
- // 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"
- << Libraries[i] << ")\n";
-
- if (LinkInArchive(HeadModule, Pathname, &ErrorMessage, Verbose)) {
- std::cerr << progname << ": " << ErrorMessage
- << ": Error linking in archive '" << Pathname << "' (-l"
- << Libraries[i] << ")\n";
- exit(1);
- }
- } else if (IsBytecode(Pathname)) {
- if (Verbose)
- std::cerr << "Trying to link bytecode file '" << Pathname
- << "' (-l" << Libraries[i] << ")\n";
+ LinkOneLibrary(progname,HeadModule,Libraries[i],LibPaths,Verbose,Native);
+ }
- if (LinkInFile(HeadModule, Pathname, ErrorMessage, Verbose)) {
- std::cerr << progname << ": " << ErrorMessage
- << ": error linking in bytecode file '" << Pathname << "' (-l"
- << Libraries[i] << ")\n";
- exit(1);
- }
- }
+ // At this point we have processed all the libraries provided to us. Since
+ // we have an aggregated module at this point, the dependent libraries in
+ // 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();
+ for (Module::LibraryListType::const_iterator I = DepLibs.begin(),
+ E = DepLibs.end(); I != E; ++I) {
+ LinkOneLibrary(progname,HeadModule,*I,LibPaths,Verbose,Native);
}
}