blob: bfde7906bb11f9983b49719c63d80d96ff9dcc4c [file] [log] [blame]
Reid Spencer7a87ce02004-12-13 03:00:04 +00001//===- lib/Linker/LinkLibraries.cpp - Link LLVM libraries -----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Reid Spencerff5f3ab2004-12-13 03:23:13 +00005// This file was developed by Reid Spencer and is distributed under the
Reid Spencer7a87ce02004-12-13 03:00:04 +00006// University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file contains routines to handle finding libraries and linking them in.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/Linker.h"
15#include "llvm/Module.h"
16
17using namespace llvm;
18
19/// LinkInLibrary - links one library into the HeadModule
20bool
21Linker::LinkInLibrary(const std::string& Lib)
22{
23 // Determine where this library lives.
24 sys::Path Pathname = FindLib(Lib);
25 if (Pathname.isEmpty())
26 return warning("Cannot find library '" + Lib + "'");
27
28 // If its an archive, try to link it in
29 if (Pathname.isArchive()) {
30 if (LinkInArchive(Pathname)) {
31 return error("Cannot link archive '" + Pathname.toString() + "'");
32 }
33 } else {
34 return warning("Supposed library '" + Lib + "' isn't a library.");
35 }
36 return false;
37}
38
39/// LinkLibraries - takes the specified library files and links them into the
40/// main bytecode object file.
41///
42/// Inputs:
43/// Libraries - The list of libraries to link into the module.
44///
45/// Return value:
46/// FALSE - No error.
47/// TRUE - Error.
48///
49bool
50Linker::LinkInLibraries(const std::vector<std::string> &Libraries) {
51
52 // Process the set of libraries we've been provided
53 for (unsigned i = 0; i < Libraries.size(); ++i) {
54 if (LinkInLibrary(Libraries[i]))
55 return true;
56 }
57
58 // At this point we have processed all the libraries provided to us. Since
59 // we have an aggregated module at this point, the dependent libraries in
60 // that module should also be aggregated with duplicates eliminated. This is
61 // now the time to process the dependent libraries to resolve any remaining
62 // symbols.
63 const Module::LibraryListType& DepLibs = Composite->getLibraries();
64 for (Module::LibraryListType::const_iterator I = DepLibs.begin(),
65 E = DepLibs.end(); I != E; ++I) {
66 if (LinkInLibrary(*I))
67 return true;
68 }
69 return false;
70}