blob: eadb5f43403ba3cbea37b6e633c6aedc6de9871d [file] [log] [blame]
Chris Lattner10970eb2003-04-19 22:44:38 +00001//===- gccld.cpp - LLVM 'ld' compatible linker ----------------------------===//
Chris Lattnere7fca512002-01-24 19:12:12 +00002//
3// This utility is intended to be compatible with GCC, and follows standard
Chris Lattner10970eb2003-04-19 22:44:38 +00004// system 'ld' conventions. As such, the default output file is ./a.out.
Chris Lattnere7fca512002-01-24 19:12:12 +00005// Additionally, this program outputs a shell script that is used to invoke LLI
6// to execute the program. In this manner, the generated executable (a.out for
7// example), is directly executable, whereas the bytecode file actually lives in
8// the a.out.bc file generated by this program. Also, Force is on by default.
9//
10// Note that if someone (or a script) deletes the executable program generated,
11// the .bc file will be left around. Considering that this is a temporary hack,
Brian Gaeke69a79602003-05-23 20:27:07 +000012// I'm not too worried about this.
Chris Lattnere7fca512002-01-24 19:12:12 +000013//
14//===----------------------------------------------------------------------===//
15
Chris Lattnerc8cc4cb2002-05-07 18:36:35 +000016#include "llvm/Transforms/Utils/Linker.h"
Chris Lattnere7fca512002-01-24 19:12:12 +000017#include "llvm/Module.h"
Chris Lattnerad202a02002-04-08 00:14:58 +000018#include "llvm/PassManager.h"
19#include "llvm/Bytecode/Reader.h"
20#include "llvm/Bytecode/WriteBytecodePass.h"
Chris Lattner9c3b55e2003-04-24 19:13:02 +000021#include "llvm/Target/TargetData.h"
Chris Lattnerd9d8c072002-07-23 22:04:43 +000022#include "llvm/Transforms/IPO.h"
Chris Lattnerd9d8c072002-07-23 22:04:43 +000023#include "llvm/Transforms/Scalar.h"
Chris Lattnere7fca512002-01-24 19:12:12 +000024#include "Support/CommandLine.h"
Chris Lattner76d12292002-04-18 19:55:25 +000025#include "Support/Signals.h"
Chris Lattnere7fca512002-01-24 19:12:12 +000026#include <fstream>
27#include <memory>
Chris Lattner10970eb2003-04-19 22:44:38 +000028#include <set>
Chris Lattner41c34652002-03-11 17:49:53 +000029#include <algorithm>
Chris Lattnere7fca512002-01-24 19:12:12 +000030#include <sys/types.h> // For FileExists
31#include <sys/stat.h>
Chris Lattnere7fca512002-01-24 19:12:12 +000032
Chris Lattnerf3d4f172003-04-18 23:01:25 +000033namespace {
34 cl::list<std::string>
35 InputFilenames(cl::Positional, cl::desc("<input bytecode files>"),
36 cl::OneOrMore);
Chris Lattner5ff62e92002-07-22 02:10:13 +000037
Chris Lattnerf3d4f172003-04-18 23:01:25 +000038 cl::opt<std::string>
39 OutputFilename("o", cl::desc("Override output filename"), cl::init("a.out"),
40 cl::value_desc("filename"));
Chris Lattner5ff62e92002-07-22 02:10:13 +000041
Chris Lattnerf3d4f172003-04-18 23:01:25 +000042 cl::opt<bool>
43 Verbose("v", cl::desc("Print information about actions taken"));
44
45 cl::list<std::string>
46 LibPaths("L", cl::desc("Specify a library search path"), cl::Prefix,
47 cl::value_desc("directory"));
Chris Lattner5ff62e92002-07-22 02:10:13 +000048
Chris Lattnerf3d4f172003-04-18 23:01:25 +000049 cl::list<std::string>
50 Libraries("l", cl::desc("Specify libraries to link to"), cl::Prefix,
51 cl::value_desc("library prefix"));
Chris Lattner5ff62e92002-07-22 02:10:13 +000052
Chris Lattnerf3d4f172003-04-18 23:01:25 +000053 cl::opt<bool>
54 Strip("s", cl::desc("Strip symbol info from executable"));
Chris Lattner5ff62e92002-07-22 02:10:13 +000055
Chris Lattnerf3d4f172003-04-18 23:01:25 +000056 cl::opt<bool>
57 NoInternalize("disable-internalize",
58 cl::desc("Do not mark all symbols as internal"));
Chris Lattnera856db22003-04-18 23:38:22 +000059
Chris Lattner10970eb2003-04-19 22:44:38 +000060 cl::opt<bool>
61 LinkAsLibrary("link-as-library", cl::desc("Link the .bc files together as a"
62 " library, not an executable"));
63
Chris Lattnera856db22003-04-18 23:38:22 +000064 // Compatibility options that are ignored, but support by LD
65 cl::opt<std::string>
66 CO3("soname", cl::Hidden, cl::desc("Compatibility option: ignored"));
67 cl::opt<std::string>
68 CO4("version-script", cl::Hidden, cl::desc("Compatibility option: ignored"));
69 cl::opt<bool>
70 CO5("eh-frame-hdr", cl::Hidden, cl::desc("Compatibility option: ignored"));
Chris Lattner6ac79d12003-05-27 19:15:11 +000071 cl::opt<bool>
72 CO6("r", cl::Hidden, cl::desc("Compatibility option: ignored"));
Chris Lattnerf3d4f172003-04-18 23:01:25 +000073}
Chris Lattnere7fca512002-01-24 19:12:12 +000074
75// FileExists - Return true if the specified string is an openable file...
76static inline bool FileExists(const std::string &FN) {
77 struct stat StatBuf;
78 return stat(FN.c_str(), &StatBuf) != -1;
79}
80
Chris Lattnere7fca512002-01-24 19:12:12 +000081
Chris Lattner10970eb2003-04-19 22:44:38 +000082// LoadObject - Read the specified "object file", which should not search the
83// library path to find it.
Chris Lattner7cb77e12003-05-13 22:14:13 +000084static inline std::auto_ptr<Module> LoadObject(std::string FN,
Chris Lattner10970eb2003-04-19 22:44:38 +000085 std::string &OutErrorMessage) {
86 if (Verbose) std::cerr << "Loading '" << FN << "'\n";
87 if (!FileExists(FN)) {
Chris Lattner7cb77e12003-05-13 22:14:13 +000088 // Attempt to load from the LLVM_LIB_SEARCH_PATH directory... if we would
89 // otherwise fail. This is used to locate objects like crtend.o.
90 //
91 char *SearchPath = getenv("LLVM_LIB_SEARCH_PATH");
92 if (SearchPath && FileExists(std::string(SearchPath)+"/"+FN))
93 FN = std::string(SearchPath)+"/"+FN;
94 else {
95 OutErrorMessage = "could not find input file '" + FN + "'!";
96 return std::auto_ptr<Module>();
97 }
Chris Lattnere7fca512002-01-24 19:12:12 +000098 }
99
Chris Lattner10970eb2003-04-19 22:44:38 +0000100 std::string ErrorMessage;
101 Module *Result = ParseBytecodeFile(FN, &ErrorMessage);
102 if (Result) return std::auto_ptr<Module>(Result);
103
104 OutErrorMessage = "Bytecode file '" + FN + "' corrupt!";
105 if (ErrorMessage.size()) OutErrorMessage += ": " + ErrorMessage;
Chris Lattnere7fca512002-01-24 19:12:12 +0000106 return std::auto_ptr<Module>();
107}
108
109
Chris Lattner10970eb2003-04-19 22:44:38 +0000110static Module *LoadSingleLibraryObject(const std::string &Filename) {
111 std::string ErrorMessage;
112 std::auto_ptr<Module> M = LoadObject(Filename, ErrorMessage);
113 if (M.get() == 0 && Verbose) {
114 std::cerr << "Error loading '" + Filename + "'";
115 if (!ErrorMessage.empty()) std::cerr << ": " << ErrorMessage;
116 std::cerr << "\n";
117 }
118
119 return M.release();
120}
121
Brian Gaeke69a79602003-05-23 20:27:07 +0000122// IsArchive - Returns true iff FILENAME appears to be the name of an ar
123// archive file. It determines this by checking the magic string at the
124// beginning of the file.
Chris Lattnere68e4d52003-05-29 15:13:15 +0000125static bool IsArchive(const std::string &filename) {
126 std::string ArchiveMagic("!<arch>\012");
127 char buf[1 + ArchiveMagic.size()];
128 std::ifstream f(filename.c_str());
129 f.read(buf, ArchiveMagic.size());
130 buf[ArchiveMagic.size()] = '\0';
131 return ArchiveMagic == buf;
Brian Gaeke69a79602003-05-23 20:27:07 +0000132}
Chris Lattner10970eb2003-04-19 22:44:38 +0000133
Brian Gaeke69a79602003-05-23 20:27:07 +0000134// LoadLibraryExactName - This looks for a file with a known name and tries to
135// load it, similarly to LoadLibraryFromDirectory().
Chris Lattnere68e4d52003-05-29 15:13:15 +0000136static inline bool LoadLibraryExactName(const std::string &FileName,
Brian Gaeke69a79602003-05-23 20:27:07 +0000137 std::vector<Module*> &Objects, bool &isArchive) {
138 if (Verbose) std::cerr << " Considering '" << FileName << "'\n";
139 if (FileExists(FileName)) {
Chris Lattnere68e4d52003-05-29 15:13:15 +0000140 if (IsArchive(FileName)) {
Brian Gaeke69a79602003-05-23 20:27:07 +0000141 std::string ErrorMessage;
142 if (Verbose) std::cerr << " Loading '" << FileName << "'\n";
143 if (!ReadArchiveFile(FileName, Objects, &ErrorMessage)) {
144 isArchive = true;
145 return false; // Success!
146 }
147 if (Verbose) {
148 std::cerr << " Error loading archive '" + FileName + "'";
149 if (!ErrorMessage.empty()) std::cerr << ": " << ErrorMessage;
150 std::cerr << "\n";
151 }
152 } else {
153 if (Module *M = LoadSingleLibraryObject(FileName)) {
154 isArchive = false;
155 Objects.push_back(M);
156 return false;
157 }
Chris Lattner10970eb2003-04-19 22:44:38 +0000158 }
159 }
Chris Lattner10970eb2003-04-19 22:44:38 +0000160 return true;
161}
162
Brian Gaeke69a79602003-05-23 20:27:07 +0000163// LoadLibrary - Try to load a library named LIBNAME that contains
164// LLVM bytecode. If SEARCH is true, then search for a file named
165// libLIBNAME.{a,so,bc} in the current library search path. Otherwise,
166// assume LIBNAME is the real name of the library file. This method puts
167// the loaded modules into the Objects list, and sets isArchive to true if
168// a .a file was loaded. It returns true if no library is found or if an
169// error occurs; otherwise it returns false.
Chris Lattner10970eb2003-04-19 22:44:38 +0000170//
171static inline bool LoadLibrary(const std::string &LibName,
172 std::vector<Module*> &Objects, bool &isArchive,
Brian Gaeke69a79602003-05-23 20:27:07 +0000173 bool search, std::string &ErrorMessage) {
174 if (search) {
175 // First, try the current directory. Then, iterate over the
176 // directories in LibPaths, looking for a suitable match for LibName
177 // in each one.
178 for (unsigned NextLibPathIdx = 0; NextLibPathIdx != LibPaths.size();
Chris Lattnere68e4d52003-05-29 15:13:15 +0000179 ++NextLibPathIdx) {
Brian Gaeke69a79602003-05-23 20:27:07 +0000180 std::string Directory = LibPaths[NextLibPathIdx] + "/";
181 if (!LoadLibraryExactName(Directory + "lib" + LibName + ".a",
182 Objects, isArchive))
183 return false;
184 if (!LoadLibraryExactName(Directory + "lib" + LibName + ".so",
185 Objects, isArchive))
186 return false;
187 if (!LoadLibraryExactName(Directory + "lib" + LibName + ".bc",
188 Objects, isArchive))
189 return false;
190 }
191 } else {
192 // If they said no searching, then assume LibName is the real name.
193 if (!LoadLibraryExactName(LibName, Objects, isArchive))
Chris Lattner10970eb2003-04-19 22:44:38 +0000194 return false;
Chris Lattner10970eb2003-04-19 22:44:38 +0000195 }
Chris Lattner10970eb2003-04-19 22:44:38 +0000196 ErrorMessage = "error linking library '-l" + LibName+ "': library not found!";
197 return true;
198}
199
200static void GetAllDefinedSymbols(Module *M,
201 std::set<std::string> &DefinedSymbols) {
202 for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
203 if (I->hasName() && !I->isExternal() && !I->hasInternalLinkage())
204 DefinedSymbols.insert(I->getName());
205 for (Module::giterator I = M->gbegin(), E = M->gend(); I != E; ++I)
206 if (I->hasName() && !I->isExternal() && !I->hasInternalLinkage())
207 DefinedSymbols.insert(I->getName());
208}
209
210// GetAllUndefinedSymbols - This calculates the set of undefined symbols that
211// still exist in an LLVM module. This is a bit tricky because there may be two
212// symbols with the same name, but different LLVM types that will be resolved to
213// each other, but aren't currently (thus we need to treat it as resolved).
214//
215static void GetAllUndefinedSymbols(Module *M,
216 std::set<std::string> &UndefinedSymbols) {
217 std::set<std::string> DefinedSymbols;
218 UndefinedSymbols.clear(); // Start out empty
219
220 for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
221 if (I->hasName()) {
222 if (I->isExternal())
223 UndefinedSymbols.insert(I->getName());
224 else if (!I->hasInternalLinkage())
225 DefinedSymbols.insert(I->getName());
226 }
227 for (Module::giterator I = M->gbegin(), E = M->gend(); I != E; ++I)
228 if (I->hasName()) {
229 if (I->isExternal())
230 UndefinedSymbols.insert(I->getName());
231 else if (!I->hasInternalLinkage())
232 DefinedSymbols.insert(I->getName());
233 }
234
235 // Prune out any defined symbols from the undefined symbols set...
236 for (std::set<std::string>::iterator I = UndefinedSymbols.begin();
237 I != UndefinedSymbols.end(); )
238 if (DefinedSymbols.count(*I))
239 UndefinedSymbols.erase(I++); // This symbol really is defined!
240 else
241 ++I; // Keep this symbol in the undefined symbols list
242}
243
244
245static bool LinkLibrary(Module *M, const std::string &LibName,
Brian Gaeke69a79602003-05-23 20:27:07 +0000246 bool search, std::string &ErrorMessage) {
Chris Lattner7cb77e12003-05-13 22:14:13 +0000247 std::set<std::string> UndefinedSymbols;
248 GetAllUndefinedSymbols(M, UndefinedSymbols);
249 if (UndefinedSymbols.empty()) {
250 if (Verbose) std::cerr << " No symbols undefined, don't link library!\n";
251 return false; // No need to link anything in!
252 }
253
Chris Lattner10970eb2003-04-19 22:44:38 +0000254 std::vector<Module*> Objects;
255 bool isArchive;
Brian Gaeke69a79602003-05-23 20:27:07 +0000256 if (LoadLibrary(LibName, Objects, isArchive, search, ErrorMessage))
257 return true;
Chris Lattner10970eb2003-04-19 22:44:38 +0000258
259 // Figure out which symbols are defined by all of the modules in the .a file
260 std::vector<std::set<std::string> > DefinedSymbols;
261 DefinedSymbols.resize(Objects.size());
262 for (unsigned i = 0; i != Objects.size(); ++i)
263 GetAllDefinedSymbols(Objects[i], DefinedSymbols[i]);
264
Chris Lattner10970eb2003-04-19 22:44:38 +0000265 bool Linked = true;
266 while (Linked) { // While we are linking in object files, loop.
267 Linked = false;
268
269 for (unsigned i = 0; i != Objects.size(); ++i) {
270 // Consider whether we need to link in this module... we only need to
271 // link it in if it defines some symbol which is so far undefined.
272 //
273 const std::set<std::string> &DefSymbols = DefinedSymbols[i];
274
275 bool ObjectRequired = false;
276 for (std::set<std::string>::iterator I = UndefinedSymbols.begin(),
277 E = UndefinedSymbols.end(); I != E; ++I)
278 if (DefSymbols.count(*I)) {
279 if (Verbose)
280 std::cerr << " Found object providing symbol '" << *I << "'...\n";
281 ObjectRequired = true;
282 break;
283 }
284
285 // We DO need to link this object into the program...
286 if (ObjectRequired) {
287 if (LinkModules(M, Objects[i], &ErrorMessage))
288 return true; // Couldn't link in the right object file...
289
290 // Since we have linked in this object, delete it from the list of
291 // objects to consider in this archive file.
292 std::swap(Objects[i], Objects.back());
293 std::swap(DefinedSymbols[i], DefinedSymbols.back());
294 Objects.pop_back();
295 DefinedSymbols.pop_back();
296 --i; // Do not skip an entry
297
298 // The undefined symbols set should have shrunk.
299 GetAllUndefinedSymbols(M, UndefinedSymbols);
300 Linked = true; // We have linked something in!
301 }
302 }
303 }
304
305 return false;
306}
307
308static int PrintAndReturn(const char *progname, const std::string &Message,
309 const std::string &Extra = "") {
310 std::cerr << progname << Extra << ": " << Message << "\n";
311 return 1;
312}
313
314
Chris Lattnere7fca512002-01-24 19:12:12 +0000315int main(int argc, char **argv) {
Chris Lattner5ff62e92002-07-22 02:10:13 +0000316 cl::ParseCommandLineOptions(argc, argv, " llvm linker for GCC\n");
Chris Lattnere7fca512002-01-24 19:12:12 +0000317
Chris Lattnere7fca512002-01-24 19:12:12 +0000318 std::string ErrorMessage;
Chris Lattner10970eb2003-04-19 22:44:38 +0000319 std::auto_ptr<Module> Composite(LoadObject(InputFilenames[0], ErrorMessage));
320 if (Composite.get() == 0)
321 return PrintAndReturn(argv[0], ErrorMessage);
Chris Lattnere7fca512002-01-24 19:12:12 +0000322
Brian Gaeke69a79602003-05-23 20:27:07 +0000323 // We always look first in the current directory when searching for libraries.
324 LibPaths.insert(LibPaths.begin(), ".");
325
Chris Lattnerd34a51d2003-04-21 19:53:24 +0000326 // If the user specied an extra search path in their environment, respect it.
327 if (char *SearchPath = getenv("LLVM_LIB_SEARCH_PATH"))
328 LibPaths.push_back(SearchPath);
329
Chris Lattner10970eb2003-04-19 22:44:38 +0000330 for (unsigned i = 1; i < InputFilenames.size(); ++i) {
Brian Gaeke69a79602003-05-23 20:27:07 +0000331 // A user may specify an ar archive without -l, perhaps because it
332 // is not installed as a library. Detect that and link the library.
Chris Lattnere68e4d52003-05-29 15:13:15 +0000333 if (IsArchive(InputFilenames[i])) {
Brian Gaeke69a79602003-05-23 20:27:07 +0000334 if (Verbose) std::cerr << "Linking archive '" << InputFilenames[i]
335 << "'\n";
Chris Lattnere68e4d52003-05-29 15:13:15 +0000336 if (LinkLibrary(Composite.get(), InputFilenames[i], false, ErrorMessage))
Brian Gaeke69a79602003-05-23 20:27:07 +0000337 return PrintAndReturn(argv[0], ErrorMessage,
338 ": error linking in '" + InputFilenames[i] + "'");
339 continue;
340 }
341
Chris Lattner10970eb2003-04-19 22:44:38 +0000342 std::auto_ptr<Module> M(LoadObject(InputFilenames[i], ErrorMessage));
343 if (M.get() == 0)
344 return PrintAndReturn(argv[0], ErrorMessage);
Chris Lattnere7fca512002-01-24 19:12:12 +0000345
Chris Lattnerf3d4f172003-04-18 23:01:25 +0000346 if (Verbose) std::cerr << "Linking in '" << InputFilenames[i] << "'\n";
Chris Lattnere7fca512002-01-24 19:12:12 +0000347
Chris Lattner10970eb2003-04-19 22:44:38 +0000348 if (LinkModules(Composite.get(), M.get(), &ErrorMessage))
349 return PrintAndReturn(argv[0], ErrorMessage,
350 ": error linking in '" + InputFilenames[i] + "'");
351 }
352
Chris Lattnerc65b1042003-04-19 23:07:33 +0000353 // Remove any consecutive duplicates of the same library...
354 Libraries.erase(std::unique(Libraries.begin(), Libraries.end()),
355 Libraries.end());
356
Chris Lattner10970eb2003-04-19 22:44:38 +0000357 // Link in all of the libraries next...
358 for (unsigned i = 0; i != Libraries.size(); ++i) {
359 if (Verbose) std::cerr << "Linking in library: -l" << Libraries[i] << "\n";
Brian Gaeke69a79602003-05-23 20:27:07 +0000360 if (LinkLibrary(Composite.get(), Libraries[i], true, ErrorMessage))
Chris Lattner10970eb2003-04-19 22:44:38 +0000361 return PrintAndReturn(argv[0], ErrorMessage);
Chris Lattnere7fca512002-01-24 19:12:12 +0000362 }
363
Chris Lattnerf8b90ee2002-04-10 20:37:47 +0000364 // In addition to just linking the input from GCC, we also want to spiff it up
Chris Lattnerad202a02002-04-08 00:14:58 +0000365 // a little bit. Do this now.
366 //
367 PassManager Passes;
368
Chris Lattner9c3b55e2003-04-24 19:13:02 +0000369 // Add an appropriate TargetData instance for this module...
370 Passes.add(new TargetData("gccas", Composite.get()));
371
Chris Lattnerad202a02002-04-08 00:14:58 +0000372 // Linking modules together can lead to duplicated global constants, only keep
373 // one copy of each constant...
374 //
375 Passes.add(createConstantMergePass());
376
Chris Lattner2b598372002-04-08 05:18:12 +0000377 // If the -s command line option was specified, strip the symbols out of the
378 // resulting program to make it smaller. -s is a GCC option that we are
379 // supporting.
380 //
381 if (Strip)
382 Passes.add(createSymbolStrippingPass());
383
Chris Lattnerf8b90ee2002-04-10 20:37:47 +0000384 // Often if the programmer does not specify proper prototypes for the
385 // functions they are calling, they end up calling a vararg version of the
386 // function that does not get a body filled in (the real function has typed
387 // arguments). This pass merges the two functions.
388 //
389 Passes.add(createFunctionResolvingPass());
390
Chris Lattnerdabaa462003-04-16 21:43:22 +0000391 if (!NoInternalize) {
392 // Now that composite has been compiled, scan through the module, looking
393 // for a main function. If main is defined, mark all other functions
394 // internal.
395 //
396 Passes.add(createInternalizePass());
397 }
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000398
Chris Lattnera34f4402003-06-18 16:29:02 +0000399 // Remove unused arguments from functions...
400 //
401 Passes.add(createDeadArgEliminationPass());
402
Chris Lattnerad202a02002-04-08 00:14:58 +0000403 // Now that we have optimized the program, discard unreachable functions...
404 //
405 Passes.add(createGlobalDCEPass());
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000406
Chris Lattnerdccb6d02003-06-19 17:03:51 +0000407 // The FuncResolve pass may leave cruft around if functions were prototyped
408 // differently than they were defined. Remove this cruft.
409 //
410 Passes.add(createInstructionCombiningPass());
411
Chris Lattnerad202a02002-04-08 00:14:58 +0000412 // Add the pass that writes bytecode to the output file...
Chris Lattner10970eb2003-04-19 22:44:38 +0000413 std::string RealBytecodeOutput = OutputFilename;
414 if (!LinkAsLibrary) RealBytecodeOutput += ".bc";
415 std::ofstream Out(RealBytecodeOutput.c_str());
416 if (!Out.good())
417 return PrintAndReturn(argv[0], "error opening '" + RealBytecodeOutput +
418 "' for writing!");
Chris Lattnerad202a02002-04-08 00:14:58 +0000419 Passes.add(new WriteBytecodePass(&Out)); // Write bytecode to file...
Chris Lattnere7fca512002-01-24 19:12:12 +0000420
Chris Lattner76d12292002-04-18 19:55:25 +0000421 // Make sure that the Out file gets unlink'd from the disk if we get a SIGINT
Chris Lattner10970eb2003-04-19 22:44:38 +0000422 RemoveFileOnSignal(RealBytecodeOutput);
Chris Lattner76d12292002-04-18 19:55:25 +0000423
Chris Lattnerad202a02002-04-08 00:14:58 +0000424 // Run our queue of passes all at once now, efficiently.
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000425 Passes.run(*Composite.get());
Chris Lattnere7fca512002-01-24 19:12:12 +0000426 Out.close();
427
Chris Lattner10970eb2003-04-19 22:44:38 +0000428 if (!LinkAsLibrary) {
429 // Output the script to start the program...
430 std::ofstream Out2(OutputFilename.c_str());
431 if (!Out2.good())
432 return PrintAndReturn(argv[0], "error opening '" + OutputFilename +
433 "' for writing!");
434 Out2 << "#!/bin/sh\nlli -q -abort-on-exception $0.bc $*\n";
435 Out2.close();
Chris Lattnere7fca512002-01-24 19:12:12 +0000436
Chris Lattner10970eb2003-04-19 22:44:38 +0000437 // Make the script executable...
438 chmod(OutputFilename.c_str(), 0755);
439 }
Chris Lattnere7fca512002-01-24 19:12:12 +0000440
441 return 0;
442}