1 //===- lib/Linker/LinkFiles.cpp - Link LLVM bytecode files ---------------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Reid Spencer and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains routines to handle linking together LLVM bytecode files.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Linker.h"
15 #include "llvm/Module.h"
19 /// LinkInFile - opens a bytecode file and links in all objects which
20 /// provide symbols that are currently undefined.
23 /// File - The pathname of the bytecode file.
26 /// ErrorMessage - A C++ string detailing what error occurred, if any.
29 /// TRUE - An error occurred.
30 /// FALSE - No errors.
33 Linker::LinkInFile(const sys::Path &File)
35 // Make sure we can at least read the file
37 return error("Cannot find linker input '" + File.toString() + "'");
39 // A user may specify an ar archive without -l, perhaps because it
40 // is not installed as a library. Detect that and link the library.
41 if (File.isArchive()) {
42 if (LinkInArchive(File))
43 return error("Cannot link archive '" + File.toString() + "'");
44 } else if (File.isBytecodeFile()) {
45 verbose("Linking bytecode file '" + File.toString() + "'");
47 std::auto_ptr<Module> M(LoadObject(File));
49 return error("Cannot load file '" + File.toString() + "'" + Error);
50 if (LinkInModule(M.get()))
51 return error("Cannot link file '" + File.toString() + "'" + Error);
53 verbose("Linked in file '" + File.toString() + "'");
55 return warning("File of unknown type '" + File.toString() + "' ignored.");
60 /// LinkFiles - takes a module and a list of files and links them all together.
61 /// It locates the file either in the current directory, as its absolute
62 /// or relative pathname, or as a file somewhere in LLVM_LIB_SEARCH_PATH.
65 /// Files - A vector of sys::Path indicating the LLVM bytecode filenames
66 /// to be linked. The names can refer to a mixture of pure LLVM
67 /// bytecode files and archive (ar) formatted files.
70 /// FALSE - No errors.
71 /// TRUE - Some error occurred.
74 Linker::LinkInFiles(const std::vector<sys::Path> &Files)
76 for (unsigned i = 0; i < Files.size(); ++i) {
77 if (LinkInFile(Files[i]))