blob: 9e17853fd51326f86f6b7e37959695150e323197 [file] [log] [blame]
Chris Lattner97f752f2003-12-30 07:45:46 +00001//===-- llvm-ar.cpp - LLVM archive librarian utility ----------------------===//
Misha Brukman3da94ae2005-04-22 00:00:37 +00002//
John Criswell7c0e0222003-10-20 17:47:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner21c62da2007-12-29 20:44:31 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukman3da94ae2005-04-22 00:00:37 +00007//
John Criswell7c0e0222003-10-20 17:47:21 +00008//===----------------------------------------------------------------------===//
Tanya Lattner14baebf2003-08-28 15:22:38 +00009//
Misha Brukman3da94ae2005-04-22 00:00:37 +000010// Builds up (relatively) standard unix archive files (.a) containing LLVM
Gabor Greifa99be512007-07-05 17:07:56 +000011// bitcode or other files.
Tanya Lattner14baebf2003-08-28 15:22:38 +000012//
13//===----------------------------------------------------------------------===//
Brian Gaeke4fa9fd32003-10-10 18:47:08 +000014
Rafael Espindola8496fae2013-06-17 15:47:20 +000015#include "Archive.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000016#include "llvm/IR/LLVMContext.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000017#include "llvm/IR/Module.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000018#include "llvm/Support/CommandLine.h"
Michael J. Spencer54453f22011-01-10 02:34:23 +000019#include "llvm/Support/FileSystem.h"
Chandler Carruthf010c462012-12-04 10:44:52 +000020#include "llvm/Support/Format.h"
Chris Lattnerc30598b2006-12-06 01:18:01 +000021#include "llvm/Support/ManagedStatic.h"
Chris Lattnercc14d252009-03-06 05:34:10 +000022#include "llvm/Support/PrettyStackTrace.h"
Michael J. Spencer1f6efa32010-11-29 18:16:10 +000023#include "llvm/Support/Signals.h"
Chandler Carruthf010c462012-12-04 10:44:52 +000024#include "llvm/Support/raw_ostream.h"
Reid Spencer3a1582b2004-11-14 22:20:07 +000025#include <algorithm>
Joerg Sonnenberger975bc072012-10-26 10:49:15 +000026#include <cstdlib>
Rafael Espindola11ca2e52013-06-20 20:56:14 +000027#include <fcntl.h>
Chandler Carruthf010c462012-12-04 10:44:52 +000028#include <memory>
Rafael Espindola11ca2e52013-06-20 20:56:14 +000029
30#if !defined(_MSC_VER) && !defined(__MINGW32__)
31#include <unistd.h>
32#else
33#include <io.h>
34#endif
35
Brian Gaeked0fde302003-11-11 22:41:34 +000036using namespace llvm;
37
Dan Gohman82f209e2007-10-15 21:10:03 +000038// Option for compatibility with AIX, not used but must allow it to be present.
Misha Brukman3da94ae2005-04-22 00:00:37 +000039static cl::opt<bool>
40X32Option ("X32_64", cl::Hidden,
Reid Spencerbede5832004-11-16 06:41:09 +000041 cl::desc("Ignored option for compatibility with AIX"));
Tanya Lattner14baebf2003-08-28 15:22:38 +000042
Reid Spencerbede5832004-11-16 06:41:09 +000043// llvm-ar operation code and modifier flags. This must come first.
Misha Brukman3da94ae2005-04-22 00:00:37 +000044static cl::opt<std::string>
Reid Spencer3a1582b2004-11-14 22:20:07 +000045Options(cl::Positional, cl::Required, cl::desc("{operation}[modifiers]..."));
Tanya Lattner14baebf2003-08-28 15:22:38 +000046
Reid Spencerbede5832004-11-16 06:41:09 +000047// llvm-ar remaining positional arguments.
Misha Brukman3da94ae2005-04-22 00:00:37 +000048static cl::list<std::string>
49RestOfArgs(cl::Positional, cl::OneOrMore,
Reid Spencer3a1582b2004-11-14 22:20:07 +000050 cl::desc("[relpos] [count] <archive-file> [members]..."));
Tanya Lattner14baebf2003-08-28 15:22:38 +000051
Reid Spencerbede5832004-11-16 06:41:09 +000052// MoreHelp - Provide additional help output explaining the operations and
53// modifiers of llvm-ar. This object instructs the CommandLine library
54// to print the text of the constructor when the --help option is given.
55static cl::extrahelp MoreHelp(
Misha Brukman3da94ae2005-04-22 00:00:37 +000056 "\nOPERATIONS:\n"
Reid Spencerbede5832004-11-16 06:41:09 +000057 " d[NsS] - delete file(s) from the archive\n"
58 " m[abiSs] - move file(s) in the archive\n"
59 " p[kN] - print file(s) found in the archive\n"
60 " q[ufsS] - quick append file(s) to the archive\n"
Rafael Espindola94bc2462012-08-10 01:57:52 +000061 " r[abfiuRsS] - replace or insert file(s) into the archive\n"
Reid Spencerbede5832004-11-16 06:41:09 +000062 " t - display contents of archive\n"
63 " x[No] - extract file(s) from the archive\n"
64 "\nMODIFIERS (operation specific):\n"
65 " [a] - put file(s) after [relpos]\n"
66 " [b] - put file(s) before [relpos] (same as [i])\n"
67 " [f] - truncate inserted file names\n"
68 " [i] - put file(s) before [relpos] (same as [b])\n"
Reid Spencerbede5832004-11-16 06:41:09 +000069 " [N] - use instance [count] of name\n"
70 " [o] - preserve original dates\n"
71 " [P] - use full path names when matching\n"
Reid Spencerbede5832004-11-16 06:41:09 +000072 " [s] - create an archive index (cf. ranlib)\n"
73 " [S] - do not build a symbol table\n"
74 " [u] - update only files newer than archive contents\n"
Reid Spencerbede5832004-11-16 06:41:09 +000075 "\nMODIFIERS (generic):\n"
76 " [c] - do not warn if the library had to be created\n"
77 " [v] - be verbose about actions taken\n"
Reid Spencerbede5832004-11-16 06:41:09 +000078);
79
Reid Spencer3a1582b2004-11-14 22:20:07 +000080// This enumeration delineates the kinds of operations on an archive
81// that are permitted.
82enum ArchiveOperation {
Reid Spencer3a1582b2004-11-14 22:20:07 +000083 Print, ///< Print the contents of the archive
84 Delete, ///< Delete the specified members
85 Move, ///< Move members to end or as given by {a,b,i} modifiers
86 QuickAppend, ///< Quickly append to end of archive
87 ReplaceOrInsert, ///< Replace or Insert members
88 DisplayTable, ///< Display the table of contents
Chris Lattnerd74ea2b2006-05-24 17:04:05 +000089 Extract ///< Extract files back to file system
Tanya Lattner57bd7962003-12-06 23:01:25 +000090};
Tanya Lattner14baebf2003-08-28 15:22:38 +000091
Reid Spencer3a1582b2004-11-14 22:20:07 +000092// Modifiers to follow operation to vary behavior
93bool AddAfter = false; ///< 'a' modifier
94bool AddBefore = false; ///< 'b' modifier
Misha Brukman3da94ae2005-04-22 00:00:37 +000095bool Create = false; ///< 'c' modifier
Reid Spencer3a1582b2004-11-14 22:20:07 +000096bool TruncateNames = false; ///< 'f' modifier
97bool InsertBefore = false; ///< 'i' modifier
Reid Spencer3a1582b2004-11-14 22:20:07 +000098bool UseCount = false; ///< 'N' modifier
99bool OriginalDates = false; ///< 'o' modifier
100bool FullPath = false; ///< 'P' modifier
Reid Spencer3a1582b2004-11-14 22:20:07 +0000101bool SymTable = true; ///< 's' & 'S' modifiers
102bool OnlyUpdate = false; ///< 'u' modifier
103bool Verbose = false; ///< 'v' modifier
Tanya Lattner14baebf2003-08-28 15:22:38 +0000104
Reid Spencer3a1582b2004-11-14 22:20:07 +0000105// Relative Positional Argument (for insert/move). This variable holds
106// the name of the archive member to which the 'a', 'b' or 'i' modifier
107// refers. Only one of 'a', 'b' or 'i' can be specified so we only need
108// one variable.
109std::string RelPos;
Tanya Lattner57bd7962003-12-06 23:01:25 +0000110
Reid Spencer3a1582b2004-11-14 22:20:07 +0000111// Select which of multiple entries in the archive with the same name should be
112// used (specified with -N) for the delete and extract operations.
113int Count = 1;
Tanya Lattner57bd7962003-12-06 23:01:25 +0000114
Reid Spencer3a1582b2004-11-14 22:20:07 +0000115// This variable holds the name of the archive file as given on the
116// command line.
117std::string ArchiveName;
Tanya Lattner57bd7962003-12-06 23:01:25 +0000118
Reid Spencer3a1582b2004-11-14 22:20:07 +0000119// This variable holds the list of member files to proecess, as given
120// on the command line.
121std::vector<std::string> Members;
Tanya Lattner57bd7962003-12-06 23:01:25 +0000122
Reid Spencer3a1582b2004-11-14 22:20:07 +0000123// This variable holds the (possibly expanded) list of path objects that
124// correspond to files we will
Rafael Espindola4d07abb2013-06-19 15:45:37 +0000125std::set<std::string> Paths;
Tanya Lattner57bd7962003-12-06 23:01:25 +0000126
Reid Spencer3a1582b2004-11-14 22:20:07 +0000127// The Archive object to which all the editing operations will be sent.
128Archive* TheArchive = 0;
Tanya Lattner57bd7962003-12-06 23:01:25 +0000129
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000130// The name this program was invoked as.
131static const char *program_name;
132
133// show_help - Show the error message, the help message and exit.
134LLVM_ATTRIBUTE_NORETURN static void
135show_help(const std::string &msg) {
136 errs() << program_name << ": " << msg << "\n\n";
137 cl::PrintHelpMessage();
138 if (TheArchive)
139 delete TheArchive;
140 std::exit(1);
141}
142
143// fail - Show the error message and exit.
144LLVM_ATTRIBUTE_NORETURN static void
145fail(const std::string &msg) {
146 errs() << program_name << ": " << msg << "\n\n";
147 if (TheArchive)
148 delete TheArchive;
149 std::exit(1);
150}
151
Reid Spencer3a1582b2004-11-14 22:20:07 +0000152// getRelPos - Extract the member filename from the command line for
153// the [relpos] argument associated with a, b, and i modifiers
Tanya Lattner57bd7962003-12-06 23:01:25 +0000154void getRelPos() {
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000155 if(RestOfArgs.size() == 0)
156 show_help("Expected [relpos] for a, b, or i modifier");
157 RelPos = RestOfArgs[0];
158 RestOfArgs.erase(RestOfArgs.begin());
Tanya Lattner57bd7962003-12-06 23:01:25 +0000159}
160
Misha Brukman3da94ae2005-04-22 00:00:37 +0000161// getCount - Extract the [count] argument associated with the N modifier
Reid Spencer3a1582b2004-11-14 22:20:07 +0000162// from the command line and check its value.
Tanya Lattner57bd7962003-12-06 23:01:25 +0000163void getCount() {
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000164 if(RestOfArgs.size() == 0)
165 show_help("Expected [count] value with N modifier");
166
167 Count = atoi(RestOfArgs[0].c_str());
168 RestOfArgs.erase(RestOfArgs.begin());
Reid Spencer3a1582b2004-11-14 22:20:07 +0000169
170 // Non-positive counts are not allowed
171 if (Count < 1)
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000172 show_help("Invalid [count] value (not a positive integer)");
Tanya Lattner57bd7962003-12-06 23:01:25 +0000173}
174
Reid Spencer3a1582b2004-11-14 22:20:07 +0000175// getArchive - Get the archive file name from the command line
Tanya Lattner57bd7962003-12-06 23:01:25 +0000176void getArchive() {
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000177 if(RestOfArgs.size() == 0)
178 show_help("An archive name must be specified");
179 ArchiveName = RestOfArgs[0];
180 RestOfArgs.erase(RestOfArgs.begin());
Tanya Lattner57bd7962003-12-06 23:01:25 +0000181}
182
Reid Spencer3a1582b2004-11-14 22:20:07 +0000183// getMembers - Copy over remaining items in RestOfArgs to our Members vector
184// This is just for clarity.
Tanya Lattner57bd7962003-12-06 23:01:25 +0000185void getMembers() {
Reid Spencer3a1582b2004-11-14 22:20:07 +0000186 if(RestOfArgs.size() > 0)
Misha Brukman3da94ae2005-04-22 00:00:37 +0000187 Members = std::vector<std::string>(RestOfArgs);
Tanya Lattner57bd7962003-12-06 23:01:25 +0000188}
189
Reid Spencer3a1582b2004-11-14 22:20:07 +0000190// parseCommandLine - Parse the command line options as presented and return the
Misha Brukman3da94ae2005-04-22 00:00:37 +0000191// operation specified. Process all modifiers and check to make sure that
Reid Spencer3a1582b2004-11-14 22:20:07 +0000192// constraints on modifier/operation pairs have not been violated.
193ArchiveOperation parseCommandLine() {
Tanya Lattner57bd7962003-12-06 23:01:25 +0000194
Reid Spencer3a1582b2004-11-14 22:20:07 +0000195 // Keep track of number of operations. We can only specify one
196 // per execution.
Tanya Lattner57bd7962003-12-06 23:01:25 +0000197 unsigned NumOperations = 0;
198
Reid Spencer3a1582b2004-11-14 22:20:07 +0000199 // Keep track of the number of positional modifiers (a,b,i). Only
200 // one can be specified.
201 unsigned NumPositional = 0;
202
203 // Keep track of which operation was requested
Rafael Espindola87b8a7f92013-07-05 12:12:43 +0000204 ArchiveOperation Operation;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000205
Tanya Lattner57bd7962003-12-06 23:01:25 +0000206 for(unsigned i=0; i<Options.size(); ++i) {
207 switch(Options[i]) {
Reid Spencer3a1582b2004-11-14 22:20:07 +0000208 case 'd': ++NumOperations; Operation = Delete; break;
209 case 'm': ++NumOperations; Operation = Move ; break;
210 case 'p': ++NumOperations; Operation = Print; break;
Seo Sanghyeondc32d192007-12-25 13:53:47 +0000211 case 'q': ++NumOperations; Operation = QuickAppend; break;
Misha Brukman3da94ae2005-04-22 00:00:37 +0000212 case 'r': ++NumOperations; Operation = ReplaceOrInsert; break;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000213 case 't': ++NumOperations; Operation = DisplayTable; break;
214 case 'x': ++NumOperations; Operation = Extract; break;
215 case 'c': Create = true; break;
216 case 'f': TruncateNames = true; break;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000217 case 'l': /* accepted but unused */ break;
218 case 'o': OriginalDates = true; break;
Rafael Espindola6f2c88a2013-06-20 13:00:30 +0000219 case 's': break; // Ignore for now.
220 case 'S': break; // Ignore for now.
Reid Spencer3a1582b2004-11-14 22:20:07 +0000221 case 'P': FullPath = true; break;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000222 case 'u': OnlyUpdate = true; break;
223 case 'v': Verbose = true; break;
Tanya Lattner57bd7962003-12-06 23:01:25 +0000224 case 'a':
Tanya Lattner57bd7962003-12-06 23:01:25 +0000225 getRelPos();
Reid Spencer3a1582b2004-11-14 22:20:07 +0000226 AddAfter = true;
227 NumPositional++;
Tanya Lattner57bd7962003-12-06 23:01:25 +0000228 break;
229 case 'b':
Tanya Lattner57bd7962003-12-06 23:01:25 +0000230 getRelPos();
Reid Spencer3a1582b2004-11-14 22:20:07 +0000231 AddBefore = true;
232 NumPositional++;
Tanya Lattner57bd7962003-12-06 23:01:25 +0000233 break;
234 case 'i':
Tanya Lattner57bd7962003-12-06 23:01:25 +0000235 getRelPos();
Reid Spencer3a1582b2004-11-14 22:20:07 +0000236 InsertBefore = true;
237 NumPositional++;
Tanya Lattner57bd7962003-12-06 23:01:25 +0000238 break;
239 case 'N':
Misha Brukman3da94ae2005-04-22 00:00:37 +0000240 getCount();
Tanya Lattner57bd7962003-12-06 23:01:25 +0000241 UseCount = true;
Tanya Lattner57bd7962003-12-06 23:01:25 +0000242 break;
243 default:
Reid Spencerbede5832004-11-16 06:41:09 +0000244 cl::PrintHelpMessage();
Tanya Lattner57bd7962003-12-06 23:01:25 +0000245 }
246 }
247
Misha Brukman3da94ae2005-04-22 00:00:37 +0000248 // At this point, the next thing on the command line must be
Reid Spencer3a1582b2004-11-14 22:20:07 +0000249 // the archive name.
Tanya Lattner57bd7962003-12-06 23:01:25 +0000250 getArchive();
Reid Spencer3a1582b2004-11-14 22:20:07 +0000251
252 // Everything on the command line at this point is a member.
Tanya Lattner57bd7962003-12-06 23:01:25 +0000253 getMembers();
254
Reid Spencer3a1582b2004-11-14 22:20:07 +0000255 // Perform various checks on the operation/modifier specification
256 // to make sure we are dealing with a legal request.
257 if (NumOperations == 0)
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000258 show_help("You must specify at least one of the operations");
Reid Spencer3a1582b2004-11-14 22:20:07 +0000259 if (NumOperations > 1)
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000260 show_help("Only one operation may be specified");
Reid Spencer3a1582b2004-11-14 22:20:07 +0000261 if (NumPositional > 1)
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000262 show_help("You may only specify one of a, b, and i modifiers");
263 if (AddAfter || AddBefore || InsertBefore) {
Reid Spencer3a1582b2004-11-14 22:20:07 +0000264 if (Operation != Move && Operation != ReplaceOrInsert)
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000265 show_help("The 'a', 'b' and 'i' modifiers can only be specified with "
266 "the 'm' or 'r' operations");
267 }
Reid Spencer3a1582b2004-11-14 22:20:07 +0000268 if (OriginalDates && Operation != Extract)
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000269 show_help("The 'o' modifier is only applicable to the 'x' operation");
Reid Spencer3a1582b2004-11-14 22:20:07 +0000270 if (TruncateNames && Operation!=QuickAppend && Operation!=ReplaceOrInsert)
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000271 show_help("The 'f' modifier is only applicable to the 'q' and 'r' "
272 "operations");
Reid Spencer3a1582b2004-11-14 22:20:07 +0000273 if (OnlyUpdate && Operation != ReplaceOrInsert)
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000274 show_help("The 'u' modifier is only applicable to the 'r' operation");
Reid Spencer3a1582b2004-11-14 22:20:07 +0000275 if (Count > 1 && Members.size() > 1)
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000276 show_help("Only one member name may be specified with the 'N' modifier");
Reid Spencer3a1582b2004-11-14 22:20:07 +0000277
278 // Return the parsed operation to the caller
279 return Operation;
Tanya Lattner57bd7962003-12-06 23:01:25 +0000280}
Tanya Lattner14baebf2003-08-28 15:22:38 +0000281
Reid Spencer3a1582b2004-11-14 22:20:07 +0000282// buildPaths - Convert the strings in the Members vector to sys::Path objects
Misha Brukman3da94ae2005-04-22 00:00:37 +0000283// and make sure they are valid and exist exist. This check is only needed for
Reid Spencer3a1582b2004-11-14 22:20:07 +0000284// the operations that add/replace files to the archive ('q' and 'r')
Reid Spencer142ca8e2006-08-23 06:56:27 +0000285bool buildPaths(bool checkExistence, std::string* ErrMsg) {
Reid Spencer3a1582b2004-11-14 22:20:07 +0000286 for (unsigned i = 0; i < Members.size(); i++) {
Rafael Espindola436cd0c2013-06-20 11:59:19 +0000287 std::string aPath = Members[i];
Reid Spencer3a1582b2004-11-14 22:20:07 +0000288 if (checkExistence) {
Rafael Espindola436cd0c2013-06-20 11:59:19 +0000289 bool IsDirectory;
290 error_code EC = sys::fs::is_directory(aPath, IsDirectory);
291 if (EC)
292 fail(aPath + ": " + EC.message());
293 if (IsDirectory)
294 fail(aPath + " Is a directory");
Rafael Espindola8fe960e2013-06-19 14:58:16 +0000295
Rafael Espindola436cd0c2013-06-20 11:59:19 +0000296 Paths.insert(aPath);
Reid Spencer3a1582b2004-11-14 22:20:07 +0000297 } else {
Rafael Espindola436cd0c2013-06-20 11:59:19 +0000298 Paths.insert(aPath);
Reid Spencer3a1582b2004-11-14 22:20:07 +0000299 }
300 }
Reid Spencer142ca8e2006-08-23 06:56:27 +0000301 return false;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000302}
303
304// doPrint - Implements the 'p' operation. This function traverses the archive
305// looking for members that match the path list. It is careful to uncompress
Gabor Greifa99be512007-07-05 17:07:56 +0000306// things that should be and to skip bitcode files unless the 'k' modifier was
Reid Spencer3a1582b2004-11-14 22:20:07 +0000307// given.
Reid Spencer142ca8e2006-08-23 06:56:27 +0000308bool doPrint(std::string* ErrMsg) {
309 if (buildPaths(false, ErrMsg))
310 return true;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000311 unsigned countDown = Count;
Misha Brukman3da94ae2005-04-22 00:00:37 +0000312 for (Archive::iterator I = TheArchive->begin(), E = TheArchive->end();
Reid Spencer3a1582b2004-11-14 22:20:07 +0000313 I != E; ++I ) {
Misha Brukman3da94ae2005-04-22 00:00:37 +0000314 if (Paths.empty() ||
Reid Spencer3a1582b2004-11-14 22:20:07 +0000315 (std::find(Paths.begin(), Paths.end(), I->getPath()) != Paths.end())) {
316 if (countDown == 1) {
317 const char* data = reinterpret_cast<const char*>(I->getData());
318
319 // Skip things that don't make sense to print
Rafael Espindola24663f62013-07-05 04:19:32 +0000320 if (I->isSVR4SymbolTable() || I->isBSD4SymbolTable())
Reid Spencer3a1582b2004-11-14 22:20:07 +0000321 continue;
322
323 if (Verbose)
Chris Lattner424a04e2010-11-29 23:02:20 +0000324 outs() << "Printing " << I->getPath().str() << "\n";
Reid Spencer3a1582b2004-11-14 22:20:07 +0000325
Chris Lattner44dadff2007-05-06 09:29:57 +0000326 unsigned len = I->getSize();
Chris Lattner424a04e2010-11-29 23:02:20 +0000327 outs().write(data, len);
Reid Spencer3a1582b2004-11-14 22:20:07 +0000328 } else {
329 countDown--;
330 }
331 }
332 }
Reid Spencer142ca8e2006-08-23 06:56:27 +0000333 return false;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000334}
335
336// putMode - utility function for printing out the file mode when the 't'
337// operation is in verbose mode.
Michael J. Spencer83a113b2011-01-10 02:34:40 +0000338void
Reid Spencer142ca8e2006-08-23 06:56:27 +0000339printMode(unsigned mode) {
Misha Brukman3da94ae2005-04-22 00:00:37 +0000340 if (mode & 004)
Chris Lattner424a04e2010-11-29 23:02:20 +0000341 outs() << "r";
Reid Spencer3a1582b2004-11-14 22:20:07 +0000342 else
Chris Lattner424a04e2010-11-29 23:02:20 +0000343 outs() << "-";
Reid Spencer3a1582b2004-11-14 22:20:07 +0000344 if (mode & 002)
Chris Lattner424a04e2010-11-29 23:02:20 +0000345 outs() << "w";
Reid Spencer3a1582b2004-11-14 22:20:07 +0000346 else
Chris Lattner424a04e2010-11-29 23:02:20 +0000347 outs() << "-";
Reid Spencer3a1582b2004-11-14 22:20:07 +0000348 if (mode & 001)
Chris Lattner424a04e2010-11-29 23:02:20 +0000349 outs() << "x";
Reid Spencer3a1582b2004-11-14 22:20:07 +0000350 else
Chris Lattner424a04e2010-11-29 23:02:20 +0000351 outs() << "-";
Reid Spencer3a1582b2004-11-14 22:20:07 +0000352}
353
354// doDisplayTable - Implement the 't' operation. This function prints out just
355// the file names of each of the members. However, if verbose mode is requested
356// ('v' modifier) then the file type, permission mode, user, group, size, and
357// modification time are also printed.
Michael J. Spencer83a113b2011-01-10 02:34:40 +0000358bool
Reid Spencer142ca8e2006-08-23 06:56:27 +0000359doDisplayTable(std::string* ErrMsg) {
360 if (buildPaths(false, ErrMsg))
361 return true;
Misha Brukman3da94ae2005-04-22 00:00:37 +0000362 for (Archive::iterator I = TheArchive->begin(), E = TheArchive->end();
Reid Spencer3a1582b2004-11-14 22:20:07 +0000363 I != E; ++I ) {
Misha Brukman3da94ae2005-04-22 00:00:37 +0000364 if (Paths.empty() ||
Reid Spencer3a1582b2004-11-14 22:20:07 +0000365 (std::find(Paths.begin(), Paths.end(), I->getPath()) != Paths.end())) {
366 if (Verbose) {
367 // FIXME: Output should be this format:
368 // Zrw-r--r-- 500/ 500 525 Nov 8 17:42 2004 Makefile
Rafael Espindola24663f62013-07-05 04:19:32 +0000369 outs() << " ";
Reid Spencer3a1582b2004-11-14 22:20:07 +0000370 unsigned mode = I->getMode();
Reid Spencerbede5832004-11-16 06:41:09 +0000371 printMode((mode >> 6) & 007);
372 printMode((mode >> 3) & 007);
373 printMode(mode & 007);
Chris Lattner424a04e2010-11-29 23:02:20 +0000374 outs() << " " << format("%4u", I->getUser());
375 outs() << "/" << format("%4u", I->getGroup());
376 outs() << " " << format("%8u", I->getSize());
377 outs() << " " << format("%20s", I->getModTime().str().substr(4).c_str());
378 outs() << " " << I->getPath().str() << "\n";
Reid Spencer3a1582b2004-11-14 22:20:07 +0000379 } else {
Chris Lattner424a04e2010-11-29 23:02:20 +0000380 outs() << I->getPath().str() << "\n";
Reid Spencer3a1582b2004-11-14 22:20:07 +0000381 }
382 }
383 }
Reid Spencer142ca8e2006-08-23 06:56:27 +0000384 return false;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000385}
386
387// doExtract - Implement the 'x' operation. This function extracts files back to
Rafael Espindola94bc2462012-08-10 01:57:52 +0000388// the file system.
Michael J. Spencer83a113b2011-01-10 02:34:40 +0000389bool
Reid Spencer142ca8e2006-08-23 06:56:27 +0000390doExtract(std::string* ErrMsg) {
391 if (buildPaths(false, ErrMsg))
392 return true;
Misha Brukman3da94ae2005-04-22 00:00:37 +0000393 for (Archive::iterator I = TheArchive->begin(), E = TheArchive->end();
Reid Spencer3a1582b2004-11-14 22:20:07 +0000394 I != E; ++I ) {
395 if (Paths.empty() ||
396 (std::find(Paths.begin(), Paths.end(), I->getPath()) != Paths.end())) {
397
Reid Spencer3a1582b2004-11-14 22:20:07 +0000398 // Open up a file stream for writing
Rafael Espindola11ca2e52013-06-20 20:56:14 +0000399 int OpenFlags = O_TRUNC | O_WRONLY | O_CREAT;
400#ifdef O_BINARY
401 OpenFlags |= O_BINARY;
402#endif
Reid Spencer3a1582b2004-11-14 22:20:07 +0000403
Rafael Espindola35637fc2013-07-08 16:16:51 +0000404 // Retain the original mode.
405 sys::fs::perms Mode = sys::fs::perms(I->getMode());
406
407 int FD = open(I->getPath().str().c_str(), OpenFlags, Mode);
Rafael Espindola11ca2e52013-06-20 20:56:14 +0000408 if (FD < 0)
409 return true;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000410
Rafael Espindola11ca2e52013-06-20 20:56:14 +0000411 {
412 raw_fd_ostream file(FD, false);
Reid Spencer3a1582b2004-11-14 22:20:07 +0000413
Rafael Espindola11ca2e52013-06-20 20:56:14 +0000414 // Get the data and its length
415 const char* data = reinterpret_cast<const char*>(I->getData());
416 unsigned len = I->getSize();
417
418 // Write the data.
419 file.write(data, len);
420 }
Rafael Espindola27ff1f32013-06-19 19:17:15 +0000421
Reid Spencer3a1582b2004-11-14 22:20:07 +0000422 // If we're supposed to retain the original modification times, etc. do so
423 // now.
Rafael Espindola11ca2e52013-06-20 20:56:14 +0000424 if (OriginalDates) {
Rafael Espindola35637fc2013-07-08 16:16:51 +0000425 error_code EC =
426 sys::fs::setLastModificationAndAccessTime(FD, I->getModTime());
Rafael Espindola11ca2e52013-06-20 20:56:14 +0000427 if (EC)
428 fail(EC.message());
429 }
430 if (close(FD))
431 return true;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000432 }
433 }
Reid Spencere5c9cb52006-08-23 00:39:35 +0000434 return false;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000435}
436
437// doDelete - Implement the delete operation. This function deletes zero or more
438// members from the archive. Note that if the count is specified, there should
439// be no more than one path in the Paths list or else this algorithm breaks.
440// That check is enforced in parseCommandLine (above).
Michael J. Spencer83a113b2011-01-10 02:34:40 +0000441bool
Reid Spencer142ca8e2006-08-23 06:56:27 +0000442doDelete(std::string* ErrMsg) {
443 if (buildPaths(false, ErrMsg))
444 return true;
Michael J. Spencer83a113b2011-01-10 02:34:40 +0000445 if (Paths.empty())
Reid Spencer142ca8e2006-08-23 06:56:27 +0000446 return false;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000447 unsigned countDown = Count;
Misha Brukman3da94ae2005-04-22 00:00:37 +0000448 for (Archive::iterator I = TheArchive->begin(), E = TheArchive->end();
Reid Spencer3a1582b2004-11-14 22:20:07 +0000449 I != E; ) {
450 if (std::find(Paths.begin(), Paths.end(), I->getPath()) != Paths.end()) {
451 if (countDown == 1) {
452 Archive::iterator J = I;
453 ++I;
Reid Spencerbede5832004-11-16 06:41:09 +0000454 TheArchive->erase(J);
Reid Spencer3a1582b2004-11-14 22:20:07 +0000455 } else
456 countDown--;
457 } else {
458 ++I;
459 }
460 }
461
462 // We're done editting, reconstruct the archive.
Rafael Espindola6f2c88a2013-06-20 13:00:30 +0000463 if (TheArchive->writeToDisk(TruncateNames,ErrMsg))
Reid Spencer142ca8e2006-08-23 06:56:27 +0000464 return true;
Reid Spencer142ca8e2006-08-23 06:56:27 +0000465 return false;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000466}
467
468// doMore - Implement the move operation. This function re-arranges just the
469// order of the archive members so that when the archive is written the move
470// of the members is accomplished. Note the use of the RelPos variable to
471// determine where the items should be moved to.
Michael J. Spencer83a113b2011-01-10 02:34:40 +0000472bool
Reid Spencer142ca8e2006-08-23 06:56:27 +0000473doMove(std::string* ErrMsg) {
Michael J. Spencer83a113b2011-01-10 02:34:40 +0000474 if (buildPaths(false, ErrMsg))
Reid Spencer142ca8e2006-08-23 06:56:27 +0000475 return true;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000476
477 // By default and convention the place to move members to is the end of the
478 // archive.
479 Archive::iterator moveto_spot = TheArchive->end();
480
481 // However, if the relative positioning modifiers were used, we need to scan
482 // the archive to find the member in question. If we don't find it, its no
483 // crime, we just move to the end.
484 if (AddBefore || InsertBefore || AddAfter) {
Misha Brukman3da94ae2005-04-22 00:00:37 +0000485 for (Archive::iterator I = TheArchive->begin(), E= TheArchive->end();
Reid Spencer3a1582b2004-11-14 22:20:07 +0000486 I != E; ++I ) {
Chris Lattner74382b72009-08-23 22:45:37 +0000487 if (RelPos == I->getPath().str()) {
Reid Spencer3a1582b2004-11-14 22:20:07 +0000488 if (AddAfter) {
489 moveto_spot = I;
490 moveto_spot++;
491 } else {
492 moveto_spot = I;
493 }
494 break;
495 }
496 }
497 }
498
499 // Keep a list of the paths remaining to be moved
Rafael Espindola4d07abb2013-06-19 15:45:37 +0000500 std::set<std::string> remaining(Paths);
Reid Spencer3a1582b2004-11-14 22:20:07 +0000501
502 // Scan the archive again, this time looking for the members to move to the
503 // moveto_spot.
Misha Brukman3da94ae2005-04-22 00:00:37 +0000504 for (Archive::iterator I = TheArchive->begin(), E= TheArchive->end();
Reid Spencer3a1582b2004-11-14 22:20:07 +0000505 I != E && !remaining.empty(); ++I ) {
Rafael Espindola4d07abb2013-06-19 15:45:37 +0000506 std::set<std::string>::iterator found =
507 std::find(remaining.begin(),remaining.end(), I->getPath());
Reid Spencer3a1582b2004-11-14 22:20:07 +0000508 if (found != remaining.end()) {
Misha Brukman3da94ae2005-04-22 00:00:37 +0000509 if (I != moveto_spot)
Reid Spencerbede5832004-11-16 06:41:09 +0000510 TheArchive->splice(moveto_spot,*TheArchive,I);
Reid Spencer3a1582b2004-11-14 22:20:07 +0000511 remaining.erase(found);
512 }
513 }
514
515 // We're done editting, reconstruct the archive.
Rafael Espindola6f2c88a2013-06-20 13:00:30 +0000516 if (TheArchive->writeToDisk(TruncateNames,ErrMsg))
Reid Spencer142ca8e2006-08-23 06:56:27 +0000517 return true;
Reid Spencer142ca8e2006-08-23 06:56:27 +0000518 return false;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000519}
520
521// doQuickAppend - Implements the 'q' operation. This function just
522// indiscriminantly adds the members to the archive and rebuilds it.
Michael J. Spencer83a113b2011-01-10 02:34:40 +0000523bool
Reid Spencer142ca8e2006-08-23 06:56:27 +0000524doQuickAppend(std::string* ErrMsg) {
Reid Spencer3a1582b2004-11-14 22:20:07 +0000525 // Get the list of paths to append.
Reid Spencer142ca8e2006-08-23 06:56:27 +0000526 if (buildPaths(true, ErrMsg))
527 return true;
Michael J. Spencer83a113b2011-01-10 02:34:40 +0000528 if (Paths.empty())
Reid Spencer142ca8e2006-08-23 06:56:27 +0000529 return false;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000530
531 // Append them quickly.
Rafael Espindola4d07abb2013-06-19 15:45:37 +0000532 for (std::set<std::string>::iterator PI = Paths.begin(), PE = Paths.end();
Reid Spencer3a1582b2004-11-14 22:20:07 +0000533 PI != PE; ++PI) {
Rafael Espindola13f4fd72013-06-19 17:49:07 +0000534 if (TheArchive->addFileBefore(*PI, TheArchive->end(), ErrMsg))
Reid Spencer0ff2d312006-08-24 23:45:08 +0000535 return true;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000536 }
537
538 // We're done editting, reconstruct the archive.
Rafael Espindola6f2c88a2013-06-20 13:00:30 +0000539 if (TheArchive->writeToDisk(TruncateNames,ErrMsg))
Reid Spencer142ca8e2006-08-23 06:56:27 +0000540 return true;
Reid Spencer142ca8e2006-08-23 06:56:27 +0000541 return false;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000542}
543
544// doReplaceOrInsert - Implements the 'r' operation. This function will replace
Misha Brukman3da94ae2005-04-22 00:00:37 +0000545// any existing files or insert new ones into the archive.
Michael J. Spencer83a113b2011-01-10 02:34:40 +0000546bool
Reid Spencer142ca8e2006-08-23 06:56:27 +0000547doReplaceOrInsert(std::string* ErrMsg) {
Reid Spencer3a1582b2004-11-14 22:20:07 +0000548
549 // Build the list of files to be added/replaced.
Reid Spencer142ca8e2006-08-23 06:56:27 +0000550 if (buildPaths(true, ErrMsg))
551 return true;
Michael J. Spencer83a113b2011-01-10 02:34:40 +0000552 if (Paths.empty())
Reid Spencer142ca8e2006-08-23 06:56:27 +0000553 return false;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000554
555 // Keep track of the paths that remain to be inserted.
Rafael Espindola4d07abb2013-06-19 15:45:37 +0000556 std::set<std::string> remaining(Paths);
Reid Spencer3a1582b2004-11-14 22:20:07 +0000557
558 // Default the insertion spot to the end of the archive
559 Archive::iterator insert_spot = TheArchive->end();
560
561 // Iterate over the archive contents
562 for (Archive::iterator I = TheArchive->begin(), E = TheArchive->end();
563 I != E && !remaining.empty(); ++I ) {
564
565 // Determine if this archive member matches one of the paths we're trying
566 // to replace.
Reid Spencer0de66b52004-12-02 09:21:55 +0000567
Rafael Espindola4d07abb2013-06-19 15:45:37 +0000568 std::set<std::string>::iterator found = remaining.end();
569 for (std::set<std::string>::iterator RI = remaining.begin(),
Reid Spencer0de66b52004-12-02 09:21:55 +0000570 RE = remaining.end(); RI != RE; ++RI ) {
Rafael Espindolaeb729e02013-06-20 18:30:37 +0000571 std::string compare(sys::path::filename(*RI));
Reid Spencer0de66b52004-12-02 09:21:55 +0000572 if (TruncateNames && compare.length() > 15) {
573 const char* nm = compare.c_str();
574 unsigned len = compare.length();
575 size_t slashpos = compare.rfind('/');
576 if (slashpos != std::string::npos) {
577 nm += slashpos + 1;
578 len -= slashpos +1;
579 }
Misha Brukman3da94ae2005-04-22 00:00:37 +0000580 if (len > 15)
Reid Spencer0de66b52004-12-02 09:21:55 +0000581 len = 15;
582 compare.assign(nm,len);
583 }
Chris Lattner74382b72009-08-23 22:45:37 +0000584 if (compare == I->getPath().str()) {
Reid Spencer0de66b52004-12-02 09:21:55 +0000585 found = RI;
586 break;
587 }
588 }
589
Reid Spencer3a1582b2004-11-14 22:20:07 +0000590 if (found != remaining.end()) {
Rafael Espindola29c17db2013-06-20 18:42:04 +0000591 sys::fs::file_status Status;
592 error_code EC = sys::fs::status(*found, Status);
593 if (EC)
Reid Spencer0ff2d312006-08-24 23:45:08 +0000594 return true;
Rafael Espindola29c17db2013-06-20 18:42:04 +0000595 if (!sys::fs::is_directory(Status)) {
Reid Spencerbede5832004-11-16 06:41:09 +0000596 if (OnlyUpdate) {
597 // Replace the item only if it is newer.
Rafael Espindola29c17db2013-06-20 18:42:04 +0000598 if (Status.getLastModificationTime() > I->getModTime())
Rafael Espindola13f4fd72013-06-19 17:49:07 +0000599 if (I->replaceWith(*found, ErrMsg))
Reid Spencer0ff2d312006-08-24 23:45:08 +0000600 return true;
Reid Spencerbede5832004-11-16 06:41:09 +0000601 } else {
602 // Replace the item regardless of time stamp
Rafael Espindola13f4fd72013-06-19 17:49:07 +0000603 if (I->replaceWith(*found, ErrMsg))
Reid Spencer0ff2d312006-08-24 23:45:08 +0000604 return true;
Reid Spencerbede5832004-11-16 06:41:09 +0000605 }
Reid Spencer3a1582b2004-11-14 22:20:07 +0000606 } else {
Reid Spencerbede5832004-11-16 06:41:09 +0000607 // We purposefully ignore directories.
Reid Spencer3a1582b2004-11-14 22:20:07 +0000608 }
609
610 // Remove it from our "to do" list
611 remaining.erase(found);
612 }
613
614 // Determine if this is the place where we should insert
Chris Lattner74382b72009-08-23 22:45:37 +0000615 if ((AddBefore || InsertBefore) && RelPos == I->getPath().str())
Reid Spencer3a1582b2004-11-14 22:20:07 +0000616 insert_spot = I;
Chris Lattner74382b72009-08-23 22:45:37 +0000617 else if (AddAfter && RelPos == I->getPath().str()) {
Reid Spencer3a1582b2004-11-14 22:20:07 +0000618 insert_spot = I;
619 insert_spot++;
620 }
621 }
622
623 // If we didn't replace all the members, some will remain and need to be
624 // inserted at the previously computed insert-spot.
625 if (!remaining.empty()) {
Rafael Espindola4d07abb2013-06-19 15:45:37 +0000626 for (std::set<std::string>::iterator PI = remaining.begin(),
Reid Spencer3a1582b2004-11-14 22:20:07 +0000627 PE = remaining.end(); PI != PE; ++PI) {
Rafael Espindola13f4fd72013-06-19 17:49:07 +0000628 if (TheArchive->addFileBefore(*PI, insert_spot, ErrMsg))
Reid Spencer0ff2d312006-08-24 23:45:08 +0000629 return true;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000630 }
631 }
632
633 // We're done editting, reconstruct the archive.
Rafael Espindola6f2c88a2013-06-20 13:00:30 +0000634 if (TheArchive->writeToDisk(TruncateNames,ErrMsg))
Reid Spencer142ca8e2006-08-23 06:56:27 +0000635 return true;
Reid Spencer142ca8e2006-08-23 06:56:27 +0000636 return false;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000637}
638
Rafael Espindola61de1422013-07-05 13:03:07 +0000639bool shouldCreateArchive(ArchiveOperation Op) {
640 switch (Op) {
641 case Print:
642 case Delete:
643 case Move:
644 case DisplayTable:
645 case Extract:
646 return false;
647
648 case QuickAppend:
649 case ReplaceOrInsert:
650 return true;
651 }
Michael Gottesman2be430d2013-07-06 02:39:51 +0000652
653 llvm_unreachable("Missing entry in covered switch.");
Rafael Espindola61de1422013-07-05 13:03:07 +0000654}
655
Reid Spencer3a1582b2004-11-14 22:20:07 +0000656// main - main program for llvm-ar .. see comments in the code
Tanya Lattner14baebf2003-08-28 15:22:38 +0000657int main(int argc, char **argv) {
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000658 program_name = argv[0];
Chris Lattnercc14d252009-03-06 05:34:10 +0000659 // Print a stack trace if we signal out.
660 sys::PrintStackTraceOnErrorSignal();
661 PrettyStackTraceProgram X(argc, argv);
Owen Anderson0d7c6952009-07-15 22:16:10 +0000662 LLVMContext &Context = getGlobalContext();
Chris Lattnercc14d252009-03-06 05:34:10 +0000663 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
Reid Spencer3a1582b2004-11-14 22:20:07 +0000664
Reid Spencer3a1582b2004-11-14 22:20:07 +0000665 // Have the command line options parsed and handle things
666 // like --help and --version.
667 cl::ParseCommandLineOptions(argc, argv,
Dan Gohman82a13c92007-10-08 15:45:12 +0000668 "LLVM Archiver (llvm-ar)\n\n"
Gabor Greifa99be512007-07-05 17:07:56 +0000669 " This program archives bitcode files into single libraries\n"
Reid Spencer3a1582b2004-11-14 22:20:07 +0000670 );
671
Reid Spencer3a1582b2004-11-14 22:20:07 +0000672 int exitCode = 0;
Tanya Lattner14baebf2003-08-28 15:22:38 +0000673
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000674 // Do our own parsing of the command line because the CommandLine utility
675 // can't handle the grouped positional parameters without a dash.
676 ArchiveOperation Operation = parseCommandLine();
Tanya Lattner14baebf2003-08-28 15:22:38 +0000677
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000678 // Create or open the archive object.
Rafael Espindola61de1422013-07-05 13:03:07 +0000679 if (shouldCreateArchive(Operation) && !llvm::sys::fs::exists(ArchiveName)) {
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000680 // Produce a warning if we should and we're creating the archive
681 if (!Create)
Rafael Espindola201c66c2013-06-20 18:55:44 +0000682 errs() << argv[0] << ": creating " << ArchiveName << "\n";
683 TheArchive = Archive::CreateEmpty(ArchiveName, Context);
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000684 TheArchive->writeToDisk();
Rafael Espindola61de1422013-07-05 13:03:07 +0000685 }
686
687 if (!TheArchive) {
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000688 std::string Error;
Rafael Espindola201c66c2013-06-20 18:55:44 +0000689 TheArchive = Archive::OpenAndLoad(ArchiveName, Context, &Error);
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000690 if (TheArchive == 0) {
Rafael Espindola201c66c2013-06-20 18:55:44 +0000691 errs() << argv[0] << ": error loading '" << ArchiveName << "': "
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000692 << Error << "!\n";
Reid Spencer142ca8e2006-08-23 06:56:27 +0000693 return 1;
694 }
Reid Spencer3a1582b2004-11-14 22:20:07 +0000695 }
696
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000697 // Make sure we're not fooling ourselves.
698 assert(TheArchive && "Unable to instantiate the archive");
699
700 // Perform the operation
701 std::string ErrMsg;
702 bool haveError = false;
703 switch (Operation) {
704 case Print: haveError = doPrint(&ErrMsg); break;
705 case Delete: haveError = doDelete(&ErrMsg); break;
706 case Move: haveError = doMove(&ErrMsg); break;
707 case QuickAppend: haveError = doQuickAppend(&ErrMsg); break;
708 case ReplaceOrInsert: haveError = doReplaceOrInsert(&ErrMsg); break;
709 case DisplayTable: haveError = doDisplayTable(&ErrMsg); break;
710 case Extract: haveError = doExtract(&ErrMsg); break;
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000711 }
712 if (haveError) {
713 errs() << argv[0] << ": " << ErrMsg << "\n";
714 return 1;
715 }
716
717 delete TheArchive;
718 TheArchive = 0;
719
Reid Spencer3a1582b2004-11-14 22:20:07 +0000720 // Return result code back to operating system.
721 return exitCode;
Tanya Lattner14baebf2003-08-28 15:22:38 +0000722}