blob: d15afaf85d6791fa6f8a53063625a7edcadcb622 [file] [log] [blame]
Reid Spencerc408c452004-11-12 20:34:32 +00001//===- lib/Linker/LinkArchives.cpp - Link LLVM objects and libraries ------===//
John Criswell7c0e0222003-10-20 17:47:21 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
John Criswell71478b72003-09-19 20:24:23 +00009//
Chris Lattnera58d2be2003-09-30 03:24:28 +000010// This file contains routines to handle linking together LLVM bytecode files,
11// and to handle annoying things like static libraries.
John Criswell71478b72003-09-19 20:24:23 +000012//
13//===----------------------------------------------------------------------===//
14
Reid Spencer8bbb17a2004-11-14 22:02:27 +000015#include "llvm/Linker.h"
John Criswell71478b72003-09-19 20:24:23 +000016#include "llvm/Module.h"
Reid Spencer8bbb17a2004-11-14 22:02:27 +000017#include "llvm/ModuleProvider.h"
John Criswell71478b72003-09-19 20:24:23 +000018#include "llvm/PassManager.h"
Reid Spencer3cf2c322004-11-19 03:13:25 +000019#include "llvm/ADT/SetOperations.h"
John Criswell71478b72003-09-19 20:24:23 +000020#include "llvm/Bytecode/Reader.h"
Reid Spencer8bbb17a2004-11-14 22:02:27 +000021#include "llvm/Bytecode/Archive.h"
John Criswell71478b72003-09-19 20:24:23 +000022#include "llvm/Bytecode/WriteBytecodePass.h"
23#include "llvm/Target/TargetData.h"
24#include "llvm/Transforms/IPO.h"
25#include "llvm/Transforms/Scalar.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000026#include "llvm/Config/config.h"
27#include "llvm/Support/CommandLine.h"
28#include "llvm/Support/FileUtilities.h"
Reid Spencer3cf2c322004-11-19 03:13:25 +000029#include "llvm/Support/Timer.h"
Chris Lattnerbed85ff2004-05-27 05:41:36 +000030#include "llvm/System/Signals.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000031#include "llvm/Support/SystemUtils.h"
Misha Brukman17dc4ce2003-09-29 22:16:43 +000032#include <algorithm>
John Criswell71478b72003-09-19 20:24:23 +000033#include <fstream>
34#include <memory>
35#include <set>
Chris Lattner6cc8ca92003-11-28 07:44:09 +000036using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000037
Brian Gaeke0d723ac2003-11-11 21:54:01 +000038/// FindLib - Try to convert Filename into the name of a file that we can open,
39/// if it does not already name a file we can open, by first trying to open
Misha Brukman7a46e4c2004-04-15 15:23:45 +000040/// Filename, then libFilename.[suffix] for each of a set of several common
Brian Gaeke0d723ac2003-11-11 21:54:01 +000041/// library suffixes, in each of the directories in Paths and the directory
42/// named by the value of the environment variable LLVM_LIB_SEARCH_PATH. Returns
43/// an empty string if no matching file can be found.
Misha Brukman5208ba12003-09-30 18:09:32 +000044///
Chris Lattner6cc8ca92003-11-28 07:44:09 +000045std::string llvm::FindLib(const std::string &Filename,
46 const std::vector<std::string> &Paths,
47 bool SharedObjectOnly) {
John Criswell71478b72003-09-19 20:24:23 +000048 // Determine if the pathname can be found as it stands.
Brian Gaekeee8adb12003-11-11 18:27:37 +000049 if (FileOpenable(Filename))
John Criswell71478b72003-09-19 20:24:23 +000050 return Filename;
John Criswell71478b72003-09-19 20:24:23 +000051
John Criswell71478b72003-09-19 20:24:23 +000052 // If that doesn't work, convert the name into a library name.
John Criswell71478b72003-09-19 20:24:23 +000053 std::string LibName = "lib" + Filename;
54
John Criswell71478b72003-09-19 20:24:23 +000055 // Iterate over the directories in Paths to see if we can find the library
56 // there.
Misha Brukman17dc4ce2003-09-29 22:16:43 +000057 for (unsigned Index = 0; Index != Paths.size(); ++Index) {
John Criswell71478b72003-09-19 20:24:23 +000058 std::string Directory = Paths[Index] + "/";
59
Misha Brukman84fbc652003-11-20 19:08:06 +000060 if (!SharedObjectOnly && FileOpenable(Directory + LibName + ".bc"))
John Criswell71478b72003-09-19 20:24:23 +000061 return Directory + LibName + ".bc";
John Criswell71478b72003-09-19 20:24:23 +000062
John Criswell7f7d16b2004-01-26 20:59:41 +000063 if (FileOpenable(Directory + LibName + SHLIBEXT))
64 return Directory + LibName + SHLIBEXT;
John Criswell71478b72003-09-19 20:24:23 +000065
Misha Brukman84fbc652003-11-20 19:08:06 +000066 if (!SharedObjectOnly && FileOpenable(Directory + LibName + ".a"))
John Criswell71478b72003-09-19 20:24:23 +000067 return Directory + LibName + ".a";
John Criswell71478b72003-09-19 20:24:23 +000068 }
69
John Criswell71478b72003-09-19 20:24:23 +000070 // One last hope: Check LLVM_LIB_SEARCH_PATH.
John Criswell71478b72003-09-19 20:24:23 +000071 char *SearchPath = getenv("LLVM_LIB_SEARCH_PATH");
72 if (SearchPath == NULL)
Misha Brukman17dc4ce2003-09-29 22:16:43 +000073 return std::string();
John Criswell71478b72003-09-19 20:24:23 +000074
75 LibName = std::string(SearchPath) + "/" + LibName;
Brian Gaekeee8adb12003-11-11 18:27:37 +000076 if (FileOpenable(LibName))
John Criswell71478b72003-09-19 20:24:23 +000077 return LibName;
John Criswell71478b72003-09-19 20:24:23 +000078
79 return std::string();
80}
81
Brian Gaeke3b3640a2003-11-05 22:12:52 +000082/// GetAllDefinedSymbols - Modifies its parameter DefinedSymbols to contain the
83/// name of each externally-visible symbol defined in M.
Misha Brukman5208ba12003-09-30 18:09:32 +000084///
Chris Lattner6cc8ca92003-11-28 07:44:09 +000085void llvm::GetAllDefinedSymbols(Module *M,
86 std::set<std::string> &DefinedSymbols) {
John Criswell71478b72003-09-19 20:24:23 +000087 for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
88 if (I->hasName() && !I->isExternal() && !I->hasInternalLinkage())
89 DefinedSymbols.insert(I->getName());
90 for (Module::giterator I = M->gbegin(), E = M->gend(); I != E; ++I)
91 if (I->hasName() && !I->isExternal() && !I->hasInternalLinkage())
92 DefinedSymbols.insert(I->getName());
93}
94
Misha Brukman5208ba12003-09-30 18:09:32 +000095/// GetAllUndefinedSymbols - calculates the set of undefined symbols that still
96/// exist in an LLVM module. This is a bit tricky because there may be two
97/// symbols with the same name but different LLVM types that will be resolved to
98/// each other but aren't currently (thus we need to treat it as resolved).
99///
100/// Inputs:
101/// M - The module in which to find undefined symbols.
102///
103/// Outputs:
104/// UndefinedSymbols - A set of C++ strings containing the name of all
105/// undefined symbols.
106///
John Criswell71478b72003-09-19 20:24:23 +0000107void
Chris Lattner6cc8ca92003-11-28 07:44:09 +0000108llvm::GetAllUndefinedSymbols(Module *M,
109 std::set<std::string> &UndefinedSymbols) {
John Criswell71478b72003-09-19 20:24:23 +0000110 std::set<std::string> DefinedSymbols;
Reid Spencer3cf2c322004-11-19 03:13:25 +0000111 UndefinedSymbols.clear();
John Criswell71478b72003-09-19 20:24:23 +0000112
113 for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
114 if (I->hasName()) {
115 if (I->isExternal())
116 UndefinedSymbols.insert(I->getName());
117 else if (!I->hasInternalLinkage())
118 DefinedSymbols.insert(I->getName());
119 }
120 for (Module::giterator I = M->gbegin(), E = M->gend(); I != E; ++I)
121 if (I->hasName()) {
122 if (I->isExternal())
123 UndefinedSymbols.insert(I->getName());
124 else if (!I->hasInternalLinkage())
125 DefinedSymbols.insert(I->getName());
126 }
127
128 // Prune out any defined symbols from the undefined symbols set...
129 for (std::set<std::string>::iterator I = UndefinedSymbols.begin();
130 I != UndefinedSymbols.end(); )
131 if (DefinedSymbols.count(*I))
132 UndefinedSymbols.erase(I++); // This symbol really is defined!
133 else
134 ++I; // Keep this symbol in the undefined symbols list
135}
136
137
Brian Gaeke0d723ac2003-11-11 21:54:01 +0000138/// LoadObject - Read in and parse the bytecode file named by FN and return the
139/// module it contains (wrapped in an auto_ptr), or 0 and set ErrorMessage if an
140/// error occurs.
Misha Brukman5208ba12003-09-30 18:09:32 +0000141///
Reid Spencer8bbb17a2004-11-14 22:02:27 +0000142static std::auto_ptr<Module> LoadObject(const std::string &FN,
Chris Lattner6cc8ca92003-11-28 07:44:09 +0000143 std::string &ErrorMessage) {
Brian Gaeke0d723ac2003-11-11 21:54:01 +0000144 std::string ParserErrorMessage;
145 Module *Result = ParseBytecodeFile(FN, &ParserErrorMessage);
John Criswell71478b72003-09-19 20:24:23 +0000146 if (Result) return std::auto_ptr<Module>(Result);
Brian Gaeke0d723ac2003-11-11 21:54:01 +0000147 ErrorMessage = "Bytecode file '" + FN + "' could not be loaded";
148 if (ParserErrorMessage.size()) ErrorMessage += ": " + ParserErrorMessage;
John Criswell71478b72003-09-19 20:24:23 +0000149 return std::auto_ptr<Module>();
150}
151
Misha Brukman5208ba12003-09-30 18:09:32 +0000152/// LinkInArchive - opens an archive library and link in all objects which
153/// provide symbols that are currently undefined.
154///
155/// Inputs:
156/// M - The module in which to link the archives.
157/// Filename - The pathname of the archive.
158/// Verbose - Flags whether verbose messages should be printed.
159///
160/// Outputs:
161/// ErrorMessage - A C++ string detailing what error occurred, if any.
162///
163/// Return Value:
164/// TRUE - An error occurred.
165/// FALSE - No errors.
166///
Reid Spencer8bbb17a2004-11-14 22:02:27 +0000167bool llvm::LinkInArchive(Module *M,
Reid Spencer99d36042004-11-16 06:47:41 +0000168 const std::string &Filename,
169 std::string* ErrorMessage,
170 bool Verbose)
John Criswell71478b72003-09-19 20:24:23 +0000171{
John Criswell71478b72003-09-19 20:24:23 +0000172 // Find all of the symbols currently undefined in the bytecode program.
173 // If all the symbols are defined, the program is complete, and there is
174 // no reason to link in any archive files.
John Criswell71478b72003-09-19 20:24:23 +0000175 std::set<std::string> UndefinedSymbols;
Misha Brukmane6763132003-09-29 22:26:24 +0000176 GetAllUndefinedSymbols(M, UndefinedSymbols);
Reid Spencer3cf2c322004-11-19 03:13:25 +0000177
Misha Brukman17dc4ce2003-09-29 22:16:43 +0000178 if (UndefinedSymbols.empty()) {
John Criswell71478b72003-09-19 20:24:23 +0000179 if (Verbose) std::cerr << " No symbols undefined, don't link library!\n";
180 return false; // No need to link anything in!
181 }
182
Reid Spencer8bbb17a2004-11-14 22:02:27 +0000183 // Open the archive file
Brian Gaeke3b3640a2003-11-05 22:12:52 +0000184 if (Verbose) std::cerr << " Loading archive file '" << Filename << "'\n";
Reid Spencer99d36042004-11-16 06:47:41 +0000185 std::auto_ptr<Archive> AutoArch (
186 Archive::OpenAndLoadSymbols(sys::Path(Filename)));
187
188 Archive* arch = AutoArch.get();
John Criswell71478b72003-09-19 20:24:23 +0000189
Reid Spencer3cf2c322004-11-19 03:13:25 +0000190 // Save a set of symbols that are not defined by the archive. Since we're
191 // entering a loop, there's no point searching for these multiple times. This
192 // variable is used to "set_subtract" from the set of undefined symbols.
193 std::set<std::string> NotDefinedByArchive;
194
John Criswell71478b72003-09-19 20:24:23 +0000195 // While we are linking in object files, loop.
Reid Spencer8bbb17a2004-11-14 22:02:27 +0000196 while (true) {
Reid Spencer3cf2c322004-11-19 03:13:25 +0000197
198 // Find the modules we need to link into the target module
Reid Spencer8bbb17a2004-11-14 22:02:27 +0000199 std::set<ModuleProvider*> Modules;
Reid Spencer99d36042004-11-16 06:47:41 +0000200 arch->findModulesDefiningSymbols(UndefinedSymbols, Modules);
John Criswell71478b72003-09-19 20:24:23 +0000201
Reid Spencer3cf2c322004-11-19 03:13:25 +0000202 // If we didn't find any more modules to link this time, we are done
203 // searching this archive.
Reid Spencer8bbb17a2004-11-14 22:02:27 +0000204 if (Modules.empty())
205 break;
John Criswell71478b72003-09-19 20:24:23 +0000206
Reid Spencer3cf2c322004-11-19 03:13:25 +0000207 // Any symbols remaining in UndefinedSymbols after
208 // findModulesDefiningSymbols are ones that the archive does not define. So
209 // we add them to the NotDefinedByArchive variable now.
210 NotDefinedByArchive.insert(UndefinedSymbols.begin(),
211 UndefinedSymbols.end());;
212
Reid Spencer8bbb17a2004-11-14 22:02:27 +0000213 // Loop over all the ModuleProviders that we got back from the archive
214 for (std::set<ModuleProvider*>::iterator I=Modules.begin(), E=Modules.end();
215 I != E; ++I) {
Reid Spencer3cf2c322004-11-19 03:13:25 +0000216
Reid Spencer8bbb17a2004-11-14 22:02:27 +0000217 // Get the module we must link in.
Reid Spencer99d36042004-11-16 06:47:41 +0000218 std::auto_ptr<Module> AutoModule( (*I)->releaseModule() );
Reid Spencer99d36042004-11-16 06:47:41 +0000219 Module* aModule = AutoModule.get();
220
221 // Link it in
222 if (LinkModules(M, aModule, ErrorMessage))
Reid Spencer3cf2c322004-11-19 03:13:25 +0000223 return true; // Couldn't link in the module
John Criswell71478b72003-09-19 20:24:23 +0000224 }
Reid Spencer8bbb17a2004-11-14 22:02:27 +0000225
Reid Spencer3cf2c322004-11-19 03:13:25 +0000226 // Get the undefined symbols from the aggregate module. This recomputes the
227 // symbols we still need after the new modules have been linked in.
Reid Spencer8bbb17a2004-11-14 22:02:27 +0000228 GetAllUndefinedSymbols(M, UndefinedSymbols);
Reid Spencer3cf2c322004-11-19 03:13:25 +0000229
230 // At this point we have two sets of undefined symbols: UndefinedSymbols
231 // which holds the undefined symbols from all the modules, and
232 // NotDefinedByArchive which holds symbols we know the archive doesn't
233 // define. There's no point searching for symbols that we won't find in the
234 // archive so we subtract these sets.
235 set_subtract<std::set<std::string>,std::set<std::string> >(
236 UndefinedSymbols,NotDefinedByArchive);
237
238 // If there's no symbols left, no point in continuing to search the
239 // archive.
240 if (UndefinedSymbols.empty())
241 break;
John Criswell71478b72003-09-19 20:24:23 +0000242 }
243
244 return false;
245}
246
Brian Gaeke3b3640a2003-11-05 22:12:52 +0000247/// LinkInFile - opens a bytecode file and links in all objects which
Misha Brukman5208ba12003-09-30 18:09:32 +0000248/// provide symbols that are currently undefined.
249///
250/// Inputs:
Brian Gaeke3b3640a2003-11-05 22:12:52 +0000251/// HeadModule - The module in which to link the bytecode file.
252/// Filename - The pathname of the bytecode file.
Misha Brukman5208ba12003-09-30 18:09:32 +0000253/// Verbose - Flags whether verbose messages should be printed.
254///
255/// Outputs:
256/// ErrorMessage - A C++ string detailing what error occurred, if any.
257///
258/// Return Value:
259/// TRUE - An error occurred.
260/// FALSE - No errors.
261///
Misha Brukmane6763132003-09-29 22:26:24 +0000262static bool LinkInFile(Module *HeadModule,
263 const std::string &Filename,
264 std::string &ErrorMessage,
265 bool Verbose)
John Criswell71478b72003-09-19 20:24:23 +0000266{
267 std::auto_ptr<Module> M(LoadObject(Filename, ErrorMessage));
Misha Brukman17dc4ce2003-09-29 22:16:43 +0000268 if (M.get() == 0) return true;
Brian Gaeke3b3640a2003-11-05 22:12:52 +0000269 bool Result = LinkModules(HeadModule, M.get(), &ErrorMessage);
270 if (Verbose) std::cerr << "Linked in bytecode file '" << Filename << "'\n";
271 return Result;
John Criswell71478b72003-09-19 20:24:23 +0000272}
273
Misha Brukman5208ba12003-09-30 18:09:32 +0000274/// LinkFiles - takes a module and a list of files and links them all together.
275/// It locates the file either in the current directory, as its absolute
276/// or relative pathname, or as a file somewhere in LLVM_LIB_SEARCH_PATH.
277///
278/// Inputs:
279/// progname - The name of the program (infamous argv[0]).
280/// HeadModule - The module under which all files will be linked.
281/// Files - A vector of C++ strings indicating the LLVM bytecode filenames
282/// to be linked. The names can refer to a mixture of pure LLVM
283/// bytecode files and archive (ar) formatted files.
284/// Verbose - Flags whether verbose output should be printed while linking.
285///
286/// Outputs:
287/// HeadModule - The module will have the specified LLVM bytecode files linked
288/// in.
289///
290/// Return value:
291/// FALSE - No errors.
292/// TRUE - Some error occurred.
293///
Chris Lattner6cc8ca92003-11-28 07:44:09 +0000294bool llvm::LinkFiles(const char *progname, Module *HeadModule,
295 const std::vector<std::string> &Files, bool Verbose) {
John Criswell71478b72003-09-19 20:24:23 +0000296 // String in which to receive error messages.
297 std::string ErrorMessage;
298
299 // Full pathname of the file
300 std::string Pathname;
301
302 // Get the library search path from the environment
303 char *SearchPath = getenv("LLVM_LIB_SEARCH_PATH");
304
Brian Gaeke3b3640a2003-11-05 22:12:52 +0000305 for (unsigned i = 0; i < Files.size(); ++i) {
John Criswell71478b72003-09-19 20:24:23 +0000306 // Determine where this file lives.
Brian Gaekeee8adb12003-11-11 18:27:37 +0000307 if (FileOpenable(Files[i])) {
John Criswell71478b72003-09-19 20:24:23 +0000308 Pathname = Files[i];
Misha Brukman17dc4ce2003-09-29 22:16:43 +0000309 } else {
310 if (SearchPath == NULL) {
Brian Gaeke608e75c2003-10-08 19:09:30 +0000311 std::cerr << progname << ": Cannot find linker input file '"
312 << Files[i] << "'\n";
Brian Gaeke3b3640a2003-11-05 22:12:52 +0000313 std::cerr << progname
314 << ": Warning: Your LLVM_LIB_SEARCH_PATH is unset.\n";
John Criswell71478b72003-09-19 20:24:23 +0000315 return true;
316 }
317
318 Pathname = std::string(SearchPath)+"/"+Files[i];
Brian Gaekeee8adb12003-11-11 18:27:37 +0000319 if (!FileOpenable(Pathname)) {
Brian Gaeke608e75c2003-10-08 19:09:30 +0000320 std::cerr << progname << ": Cannot find linker input file '"
321 << Files[i] << "'\n";
John Criswell71478b72003-09-19 20:24:23 +0000322 return true;
323 }
324 }
325
John Criswell71478b72003-09-19 20:24:23 +0000326 // A user may specify an ar archive without -l, perhaps because it
327 // is not installed as a library. Detect that and link the library.
Misha Brukman17dc4ce2003-09-29 22:16:43 +0000328 if (IsArchive(Pathname)) {
John Criswell71478b72003-09-19 20:24:23 +0000329 if (Verbose)
Brian Gaeke3b3640a2003-11-05 22:12:52 +0000330 std::cerr << "Trying to link archive '" << Pathname << "'\n";
John Criswell71478b72003-09-19 20:24:23 +0000331
Reid Spencer8bbb17a2004-11-14 22:02:27 +0000332 if (LinkInArchive(HeadModule, Pathname, &ErrorMessage, Verbose)) {
Chris Lattner0ebee742004-06-02 00:22:24 +0000333 std::cerr << progname << ": Error linking in archive '" << Pathname
334 << "': " << ErrorMessage << "\n";
John Criswell71478b72003-09-19 20:24:23 +0000335 return true;
336 }
Brian Gaekeee8adb12003-11-11 18:27:37 +0000337 } else if (IsBytecode(Pathname)) {
John Criswell71478b72003-09-19 20:24:23 +0000338 if (Verbose)
Brian Gaeke3b3640a2003-11-05 22:12:52 +0000339 std::cerr << "Trying to link bytecode file '" << Pathname << "'\n";
John Criswell71478b72003-09-19 20:24:23 +0000340
Misha Brukmane6763132003-09-29 22:26:24 +0000341 if (LinkInFile(HeadModule, Pathname, ErrorMessage, Verbose)) {
Chris Lattner0ebee742004-06-02 00:22:24 +0000342 std::cerr << progname << ": Error linking in bytecode file '"
343 << Pathname << "': " << ErrorMessage << "\n";
John Criswell71478b72003-09-19 20:24:23 +0000344 return true;
345 }
Misha Brukmaneda20f92004-11-08 22:03:10 +0000346 } else {
Misha Brukman669b5242004-11-09 04:24:59 +0000347 std::cerr << progname << ": Warning: invalid file `" << Pathname
348 << "' ignored.\n";
John Criswell71478b72003-09-19 20:24:23 +0000349 }
350 }
351
352 return false;
353}
354
Misha Brukman5208ba12003-09-30 18:09:32 +0000355/// LinkLibraries - takes the specified library files and links them into the
356/// main bytecode object file.
357///
358/// Inputs:
359/// progname - The name of the program (infamous argv[0]).
360/// HeadModule - The module into which all necessary libraries will be linked.
361/// Libraries - The list of libraries to link into the module.
362/// LibPaths - The list of library paths in which to find libraries.
363/// Verbose - Flags whether verbose messages should be printed.
364/// Native - Flags whether native code is being generated.
365///
366/// Outputs:
367/// HeadModule - The module will have all necessary libraries linked in.
368///
369/// Return value:
370/// FALSE - No error.
371/// TRUE - Error.
372///
Chris Lattner6cc8ca92003-11-28 07:44:09 +0000373void llvm::LinkLibraries(const char *progname, Module *HeadModule,
374 const std::vector<std::string> &Libraries,
375 const std::vector<std::string> &LibPaths,
376 bool Verbose, bool Native) {
John Criswell71478b72003-09-19 20:24:23 +0000377 // String in which to receive error messages.
378 std::string ErrorMessage;
379
Brian Gaekef1fce082003-10-21 21:07:12 +0000380 for (unsigned i = 0; i < Libraries.size(); ++i) {
John Criswell71478b72003-09-19 20:24:23 +0000381 // Determine where this library lives.
Misha Brukman17dc4ce2003-09-29 22:16:43 +0000382 std::string Pathname = FindLib(Libraries[i], LibPaths);
383 if (Pathname.empty()) {
John Criswell71478b72003-09-19 20:24:23 +0000384 // If the pathname does not exist, then continue to the next one if
385 // we're doing a native link and give an error if we're doing a bytecode
386 // link.
Misha Brukman17dc4ce2003-09-29 22:16:43 +0000387 if (!Native) {
Chris Lattner6cc8ca92003-11-28 07:44:09 +0000388 std::cerr << progname << ": WARNING: Cannot find library -l"
389 << Libraries[i] << "\n";
390 continue;
John Criswell71478b72003-09-19 20:24:23 +0000391 }
392 }
393
John Criswell71478b72003-09-19 20:24:23 +0000394 // A user may specify an ar archive without -l, perhaps because it
395 // is not installed as a library. Detect that and link the library.
Misha Brukman17dc4ce2003-09-29 22:16:43 +0000396 if (IsArchive(Pathname)) {
John Criswell71478b72003-09-19 20:24:23 +0000397 if (Verbose)
Brian Gaeke2282ae12003-11-16 23:07:13 +0000398 std::cerr << "Trying to link archive '" << Pathname << "' (-l"
399 << Libraries[i] << ")\n";
John Criswell71478b72003-09-19 20:24:23 +0000400
Reid Spencer8bbb17a2004-11-14 22:02:27 +0000401 if (LinkInArchive(HeadModule, Pathname, &ErrorMessage, Verbose)) {
Chris Lattner6cc8ca92003-11-28 07:44:09 +0000402 std::cerr << progname << ": " << ErrorMessage
403 << ": Error linking in archive '" << Pathname << "' (-l"
404 << Libraries[i] << ")\n";
405 exit(1);
John Criswell71478b72003-09-19 20:24:23 +0000406 }
Brian Gaekeee8adb12003-11-11 18:27:37 +0000407 } else if (IsBytecode(Pathname)) {
John Criswell71478b72003-09-19 20:24:23 +0000408 if (Verbose)
Brian Gaeke2282ae12003-11-16 23:07:13 +0000409 std::cerr << "Trying to link bytecode file '" << Pathname
410 << "' (-l" << Libraries[i] << ")\n";
John Criswell71478b72003-09-19 20:24:23 +0000411
Misha Brukman17dc4ce2003-09-29 22:16:43 +0000412 if (LinkInFile(HeadModule, Pathname, ErrorMessage, Verbose)) {
Chris Lattner6cc8ca92003-11-28 07:44:09 +0000413 std::cerr << progname << ": " << ErrorMessage
414 << ": error linking in bytecode file '" << Pathname << "' (-l"
415 << Libraries[i] << ")\n";
416 exit(1);
John Criswell71478b72003-09-19 20:24:23 +0000417 }
418 }
419 }
John Criswell71478b72003-09-19 20:24:23 +0000420}