blob: 23b3df3d3b2357d6b334b59cdf1841b8716a461e [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"
Gabor Greifa99be512007-07-05 17:07:56 +000069 " [k] - always print bitcode files (default is to skip them)\n"
Reid Spencerbede5832004-11-16 06:41:09 +000070 " [N] - use instance [count] of name\n"
71 " [o] - preserve original dates\n"
72 " [P] - use full path names when matching\n"
73 " [R] - recurse through directories when inserting\n"
74 " [s] - create an archive index (cf. ranlib)\n"
75 " [S] - do not build a symbol table\n"
76 " [u] - update only files newer than archive contents\n"
Reid Spencerbede5832004-11-16 06:41:09 +000077 "\nMODIFIERS (generic):\n"
78 " [c] - do not warn if the library had to be created\n"
79 " [v] - be verbose about actions taken\n"
80 " [V] - be *really* verbose about actions taken\n"
81);
82
Reid Spencer3a1582b2004-11-14 22:20:07 +000083// This enumeration delineates the kinds of operations on an archive
84// that are permitted.
85enum ArchiveOperation {
86 NoOperation, ///< An operation hasn't been specified
87 Print, ///< Print the contents of the archive
88 Delete, ///< Delete the specified members
89 Move, ///< Move members to end or as given by {a,b,i} modifiers
90 QuickAppend, ///< Quickly append to end of archive
91 ReplaceOrInsert, ///< Replace or Insert members
92 DisplayTable, ///< Display the table of contents
Chris Lattnerd74ea2b2006-05-24 17:04:05 +000093 Extract ///< Extract files back to file system
Tanya Lattner57bd7962003-12-06 23:01:25 +000094};
Tanya Lattner14baebf2003-08-28 15:22:38 +000095
Reid Spencer3a1582b2004-11-14 22:20:07 +000096// Modifiers to follow operation to vary behavior
97bool AddAfter = false; ///< 'a' modifier
98bool AddBefore = false; ///< 'b' modifier
Misha Brukman3da94ae2005-04-22 00:00:37 +000099bool Create = false; ///< 'c' modifier
Reid Spencer3a1582b2004-11-14 22:20:07 +0000100bool TruncateNames = false; ///< 'f' modifier
101bool InsertBefore = false; ///< 'i' modifier
Gabor Greifa99be512007-07-05 17:07:56 +0000102bool DontSkipBitcode = false; ///< 'k' modifier
Reid Spencer3a1582b2004-11-14 22:20:07 +0000103bool UseCount = false; ///< 'N' modifier
104bool OriginalDates = false; ///< 'o' modifier
105bool FullPath = false; ///< 'P' modifier
Reid Spencer3a1582b2004-11-14 22:20:07 +0000106bool SymTable = true; ///< 's' & 'S' modifiers
107bool OnlyUpdate = false; ///< 'u' modifier
108bool Verbose = false; ///< 'v' modifier
Tanya Lattner14baebf2003-08-28 15:22:38 +0000109
Reid Spencer3a1582b2004-11-14 22:20:07 +0000110// Relative Positional Argument (for insert/move). This variable holds
111// the name of the archive member to which the 'a', 'b' or 'i' modifier
112// refers. Only one of 'a', 'b' or 'i' can be specified so we only need
113// one variable.
114std::string RelPos;
Tanya Lattner57bd7962003-12-06 23:01:25 +0000115
Reid Spencer3a1582b2004-11-14 22:20:07 +0000116// Select which of multiple entries in the archive with the same name should be
117// used (specified with -N) for the delete and extract operations.
118int Count = 1;
Tanya Lattner57bd7962003-12-06 23:01:25 +0000119
Reid Spencer3a1582b2004-11-14 22:20:07 +0000120// This variable holds the name of the archive file as given on the
121// command line.
122std::string ArchiveName;
Tanya Lattner57bd7962003-12-06 23:01:25 +0000123
Reid Spencer3a1582b2004-11-14 22:20:07 +0000124// This variable holds the list of member files to proecess, as given
125// on the command line.
126std::vector<std::string> Members;
Tanya Lattner57bd7962003-12-06 23:01:25 +0000127
Reid Spencer3a1582b2004-11-14 22:20:07 +0000128// This variable holds the (possibly expanded) list of path objects that
129// correspond to files we will
Rafael Espindola4d07abb2013-06-19 15:45:37 +0000130std::set<std::string> Paths;
Tanya Lattner57bd7962003-12-06 23:01:25 +0000131
Reid Spencer3a1582b2004-11-14 22:20:07 +0000132// The Archive object to which all the editing operations will be sent.
133Archive* TheArchive = 0;
Tanya Lattner57bd7962003-12-06 23:01:25 +0000134
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000135// The name this program was invoked as.
136static const char *program_name;
137
138// show_help - Show the error message, the help message and exit.
139LLVM_ATTRIBUTE_NORETURN static void
140show_help(const std::string &msg) {
141 errs() << program_name << ": " << msg << "\n\n";
142 cl::PrintHelpMessage();
143 if (TheArchive)
144 delete TheArchive;
145 std::exit(1);
146}
147
148// fail - Show the error message and exit.
149LLVM_ATTRIBUTE_NORETURN static void
150fail(const std::string &msg) {
151 errs() << program_name << ": " << msg << "\n\n";
152 if (TheArchive)
153 delete TheArchive;
154 std::exit(1);
155}
156
Reid Spencer3a1582b2004-11-14 22:20:07 +0000157// getRelPos - Extract the member filename from the command line for
158// the [relpos] argument associated with a, b, and i modifiers
Tanya Lattner57bd7962003-12-06 23:01:25 +0000159void getRelPos() {
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000160 if(RestOfArgs.size() == 0)
161 show_help("Expected [relpos] for a, b, or i modifier");
162 RelPos = RestOfArgs[0];
163 RestOfArgs.erase(RestOfArgs.begin());
Tanya Lattner57bd7962003-12-06 23:01:25 +0000164}
165
Misha Brukman3da94ae2005-04-22 00:00:37 +0000166// getCount - Extract the [count] argument associated with the N modifier
Reid Spencer3a1582b2004-11-14 22:20:07 +0000167// from the command line and check its value.
Tanya Lattner57bd7962003-12-06 23:01:25 +0000168void getCount() {
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000169 if(RestOfArgs.size() == 0)
170 show_help("Expected [count] value with N modifier");
171
172 Count = atoi(RestOfArgs[0].c_str());
173 RestOfArgs.erase(RestOfArgs.begin());
Reid Spencer3a1582b2004-11-14 22:20:07 +0000174
175 // Non-positive counts are not allowed
176 if (Count < 1)
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000177 show_help("Invalid [count] value (not a positive integer)");
Tanya Lattner57bd7962003-12-06 23:01:25 +0000178}
179
Reid Spencer3a1582b2004-11-14 22:20:07 +0000180// getArchive - Get the archive file name from the command line
Tanya Lattner57bd7962003-12-06 23:01:25 +0000181void getArchive() {
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000182 if(RestOfArgs.size() == 0)
183 show_help("An archive name must be specified");
184 ArchiveName = RestOfArgs[0];
185 RestOfArgs.erase(RestOfArgs.begin());
Tanya Lattner57bd7962003-12-06 23:01:25 +0000186}
187
Reid Spencer3a1582b2004-11-14 22:20:07 +0000188// getMembers - Copy over remaining items in RestOfArgs to our Members vector
189// This is just for clarity.
Tanya Lattner57bd7962003-12-06 23:01:25 +0000190void getMembers() {
Reid Spencer3a1582b2004-11-14 22:20:07 +0000191 if(RestOfArgs.size() > 0)
Misha Brukman3da94ae2005-04-22 00:00:37 +0000192 Members = std::vector<std::string>(RestOfArgs);
Tanya Lattner57bd7962003-12-06 23:01:25 +0000193}
194
Reid Spencer3a1582b2004-11-14 22:20:07 +0000195// parseCommandLine - Parse the command line options as presented and return the
Misha Brukman3da94ae2005-04-22 00:00:37 +0000196// operation specified. Process all modifiers and check to make sure that
Reid Spencer3a1582b2004-11-14 22:20:07 +0000197// constraints on modifier/operation pairs have not been violated.
198ArchiveOperation parseCommandLine() {
Tanya Lattner57bd7962003-12-06 23:01:25 +0000199
Reid Spencer3a1582b2004-11-14 22:20:07 +0000200 // Keep track of number of operations. We can only specify one
201 // per execution.
Tanya Lattner57bd7962003-12-06 23:01:25 +0000202 unsigned NumOperations = 0;
203
Reid Spencer3a1582b2004-11-14 22:20:07 +0000204 // Keep track of the number of positional modifiers (a,b,i). Only
205 // one can be specified.
206 unsigned NumPositional = 0;
207
208 // Keep track of which operation was requested
209 ArchiveOperation Operation = NoOperation;
210
Tanya Lattner57bd7962003-12-06 23:01:25 +0000211 for(unsigned i=0; i<Options.size(); ++i) {
212 switch(Options[i]) {
Reid Spencer3a1582b2004-11-14 22:20:07 +0000213 case 'd': ++NumOperations; Operation = Delete; break;
214 case 'm': ++NumOperations; Operation = Move ; break;
215 case 'p': ++NumOperations; Operation = Print; break;
Seo Sanghyeondc32d192007-12-25 13:53:47 +0000216 case 'q': ++NumOperations; Operation = QuickAppend; break;
Misha Brukman3da94ae2005-04-22 00:00:37 +0000217 case 'r': ++NumOperations; Operation = ReplaceOrInsert; break;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000218 case 't': ++NumOperations; Operation = DisplayTable; break;
219 case 'x': ++NumOperations; Operation = Extract; break;
220 case 'c': Create = true; break;
221 case 'f': TruncateNames = true; break;
Gabor Greifa99be512007-07-05 17:07:56 +0000222 case 'k': DontSkipBitcode = true; break;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000223 case 'l': /* accepted but unused */ break;
224 case 'o': OriginalDates = true; break;
Rafael Espindola6f2c88a2013-06-20 13:00:30 +0000225 case 's': break; // Ignore for now.
226 case 'S': break; // Ignore for now.
Reid Spencer3a1582b2004-11-14 22:20:07 +0000227 case 'P': FullPath = true; break;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000228 case 'u': OnlyUpdate = true; break;
229 case 'v': Verbose = true; break;
Tanya Lattner57bd7962003-12-06 23:01:25 +0000230 case 'a':
Tanya Lattner57bd7962003-12-06 23:01:25 +0000231 getRelPos();
Reid Spencer3a1582b2004-11-14 22:20:07 +0000232 AddAfter = true;
233 NumPositional++;
Tanya Lattner57bd7962003-12-06 23:01:25 +0000234 break;
235 case 'b':
Tanya Lattner57bd7962003-12-06 23:01:25 +0000236 getRelPos();
Reid Spencer3a1582b2004-11-14 22:20:07 +0000237 AddBefore = true;
238 NumPositional++;
Tanya Lattner57bd7962003-12-06 23:01:25 +0000239 break;
240 case 'i':
Tanya Lattner57bd7962003-12-06 23:01:25 +0000241 getRelPos();
Reid Spencer3a1582b2004-11-14 22:20:07 +0000242 InsertBefore = true;
243 NumPositional++;
Tanya Lattner57bd7962003-12-06 23:01:25 +0000244 break;
245 case 'N':
Misha Brukman3da94ae2005-04-22 00:00:37 +0000246 getCount();
Tanya Lattner57bd7962003-12-06 23:01:25 +0000247 UseCount = true;
Tanya Lattner57bd7962003-12-06 23:01:25 +0000248 break;
249 default:
Reid Spencerbede5832004-11-16 06:41:09 +0000250 cl::PrintHelpMessage();
Tanya Lattner57bd7962003-12-06 23:01:25 +0000251 }
252 }
253
Misha Brukman3da94ae2005-04-22 00:00:37 +0000254 // At this point, the next thing on the command line must be
Reid Spencer3a1582b2004-11-14 22:20:07 +0000255 // the archive name.
Tanya Lattner57bd7962003-12-06 23:01:25 +0000256 getArchive();
Reid Spencer3a1582b2004-11-14 22:20:07 +0000257
258 // Everything on the command line at this point is a member.
Tanya Lattner57bd7962003-12-06 23:01:25 +0000259 getMembers();
260
Reid Spencer3a1582b2004-11-14 22:20:07 +0000261 // Perform various checks on the operation/modifier specification
262 // to make sure we are dealing with a legal request.
263 if (NumOperations == 0)
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000264 show_help("You must specify at least one of the operations");
Reid Spencer3a1582b2004-11-14 22:20:07 +0000265 if (NumOperations > 1)
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000266 show_help("Only one operation may be specified");
Reid Spencer3a1582b2004-11-14 22:20:07 +0000267 if (NumPositional > 1)
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000268 show_help("You may only specify one of a, b, and i modifiers");
269 if (AddAfter || AddBefore || InsertBefore) {
Reid Spencer3a1582b2004-11-14 22:20:07 +0000270 if (Operation != Move && Operation != ReplaceOrInsert)
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000271 show_help("The 'a', 'b' and 'i' modifiers can only be specified with "
272 "the 'm' or 'r' operations");
273 }
Reid Spencer3a1582b2004-11-14 22:20:07 +0000274 if (OriginalDates && Operation != Extract)
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000275 show_help("The 'o' modifier is only applicable to the 'x' operation");
Reid Spencer3a1582b2004-11-14 22:20:07 +0000276 if (TruncateNames && Operation!=QuickAppend && Operation!=ReplaceOrInsert)
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000277 show_help("The 'f' modifier is only applicable to the 'q' and 'r' "
278 "operations");
Reid Spencer3a1582b2004-11-14 22:20:07 +0000279 if (OnlyUpdate && Operation != ReplaceOrInsert)
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000280 show_help("The 'u' modifier is only applicable to the 'r' operation");
Reid Spencer3a1582b2004-11-14 22:20:07 +0000281 if (Count > 1 && Members.size() > 1)
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000282 show_help("Only one member name may be specified with the 'N' modifier");
Reid Spencer3a1582b2004-11-14 22:20:07 +0000283
284 // Return the parsed operation to the caller
285 return Operation;
Tanya Lattner57bd7962003-12-06 23:01:25 +0000286}
Tanya Lattner14baebf2003-08-28 15:22:38 +0000287
Reid Spencer3a1582b2004-11-14 22:20:07 +0000288// buildPaths - Convert the strings in the Members vector to sys::Path objects
Misha Brukman3da94ae2005-04-22 00:00:37 +0000289// and make sure they are valid and exist exist. This check is only needed for
Reid Spencer3a1582b2004-11-14 22:20:07 +0000290// the operations that add/replace files to the archive ('q' and 'r')
Reid Spencer142ca8e2006-08-23 06:56:27 +0000291bool buildPaths(bool checkExistence, std::string* ErrMsg) {
Reid Spencer3a1582b2004-11-14 22:20:07 +0000292 for (unsigned i = 0; i < Members.size(); i++) {
Rafael Espindola436cd0c2013-06-20 11:59:19 +0000293 std::string aPath = Members[i];
Reid Spencer3a1582b2004-11-14 22:20:07 +0000294 if (checkExistence) {
Rafael Espindola436cd0c2013-06-20 11:59:19 +0000295 bool IsDirectory;
296 error_code EC = sys::fs::is_directory(aPath, IsDirectory);
297 if (EC)
298 fail(aPath + ": " + EC.message());
299 if (IsDirectory)
300 fail(aPath + " Is a directory");
Rafael Espindola8fe960e2013-06-19 14:58:16 +0000301
Rafael Espindola436cd0c2013-06-20 11:59:19 +0000302 Paths.insert(aPath);
Reid Spencer3a1582b2004-11-14 22:20:07 +0000303 } else {
Rafael Espindola436cd0c2013-06-20 11:59:19 +0000304 Paths.insert(aPath);
Reid Spencer3a1582b2004-11-14 22:20:07 +0000305 }
306 }
Reid Spencer142ca8e2006-08-23 06:56:27 +0000307 return false;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000308}
309
310// doPrint - Implements the 'p' operation. This function traverses the archive
311// looking for members that match the path list. It is careful to uncompress
Gabor Greifa99be512007-07-05 17:07:56 +0000312// things that should be and to skip bitcode files unless the 'k' modifier was
Reid Spencer3a1582b2004-11-14 22:20:07 +0000313// given.
Reid Spencer142ca8e2006-08-23 06:56:27 +0000314bool doPrint(std::string* ErrMsg) {
315 if (buildPaths(false, ErrMsg))
316 return true;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000317 unsigned countDown = Count;
Misha Brukman3da94ae2005-04-22 00:00:37 +0000318 for (Archive::iterator I = TheArchive->begin(), E = TheArchive->end();
Reid Spencer3a1582b2004-11-14 22:20:07 +0000319 I != E; ++I ) {
Misha Brukman3da94ae2005-04-22 00:00:37 +0000320 if (Paths.empty() ||
Reid Spencer3a1582b2004-11-14 22:20:07 +0000321 (std::find(Paths.begin(), Paths.end(), I->getPath()) != Paths.end())) {
322 if (countDown == 1) {
323 const char* data = reinterpret_cast<const char*>(I->getData());
324
325 // Skip things that don't make sense to print
Rafael Espindola250bfb12013-06-14 23:25:53 +0000326 if (I->isSVR4SymbolTable() ||
Gabor Greife75ca3d2007-07-06 13:38:17 +0000327 I->isBSD4SymbolTable() || (!DontSkipBitcode && I->isBitcode()))
Reid Spencer3a1582b2004-11-14 22:20:07 +0000328 continue;
329
330 if (Verbose)
Chris Lattner424a04e2010-11-29 23:02:20 +0000331 outs() << "Printing " << I->getPath().str() << "\n";
Reid Spencer3a1582b2004-11-14 22:20:07 +0000332
Chris Lattner44dadff2007-05-06 09:29:57 +0000333 unsigned len = I->getSize();
Chris Lattner424a04e2010-11-29 23:02:20 +0000334 outs().write(data, len);
Reid Spencer3a1582b2004-11-14 22:20:07 +0000335 } else {
336 countDown--;
337 }
338 }
339 }
Reid Spencer142ca8e2006-08-23 06:56:27 +0000340 return false;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000341}
342
343// putMode - utility function for printing out the file mode when the 't'
344// operation is in verbose mode.
Michael J. Spencer83a113b2011-01-10 02:34:40 +0000345void
Reid Spencer142ca8e2006-08-23 06:56:27 +0000346printMode(unsigned mode) {
Misha Brukman3da94ae2005-04-22 00:00:37 +0000347 if (mode & 004)
Chris Lattner424a04e2010-11-29 23:02:20 +0000348 outs() << "r";
Reid Spencer3a1582b2004-11-14 22:20:07 +0000349 else
Chris Lattner424a04e2010-11-29 23:02:20 +0000350 outs() << "-";
Reid Spencer3a1582b2004-11-14 22:20:07 +0000351 if (mode & 002)
Chris Lattner424a04e2010-11-29 23:02:20 +0000352 outs() << "w";
Reid Spencer3a1582b2004-11-14 22:20:07 +0000353 else
Chris Lattner424a04e2010-11-29 23:02:20 +0000354 outs() << "-";
Reid Spencer3a1582b2004-11-14 22:20:07 +0000355 if (mode & 001)
Chris Lattner424a04e2010-11-29 23:02:20 +0000356 outs() << "x";
Reid Spencer3a1582b2004-11-14 22:20:07 +0000357 else
Chris Lattner424a04e2010-11-29 23:02:20 +0000358 outs() << "-";
Reid Spencer3a1582b2004-11-14 22:20:07 +0000359}
360
361// doDisplayTable - Implement the 't' operation. This function prints out just
362// the file names of each of the members. However, if verbose mode is requested
363// ('v' modifier) then the file type, permission mode, user, group, size, and
364// modification time are also printed.
Michael J. Spencer83a113b2011-01-10 02:34:40 +0000365bool
Reid Spencer142ca8e2006-08-23 06:56:27 +0000366doDisplayTable(std::string* ErrMsg) {
367 if (buildPaths(false, ErrMsg))
368 return true;
Misha Brukman3da94ae2005-04-22 00:00:37 +0000369 for (Archive::iterator I = TheArchive->begin(), E = TheArchive->end();
Reid Spencer3a1582b2004-11-14 22:20:07 +0000370 I != E; ++I ) {
Misha Brukman3da94ae2005-04-22 00:00:37 +0000371 if (Paths.empty() ||
Reid Spencer3a1582b2004-11-14 22:20:07 +0000372 (std::find(Paths.begin(), Paths.end(), I->getPath()) != Paths.end())) {
373 if (Verbose) {
374 // FIXME: Output should be this format:
375 // Zrw-r--r-- 500/ 500 525 Nov 8 17:42 2004 Makefile
Gabor Greife75ca3d2007-07-06 13:38:17 +0000376 if (I->isBitcode())
Chris Lattner424a04e2010-11-29 23:02:20 +0000377 outs() << "b";
Reid Spencer3a1582b2004-11-14 22:20:07 +0000378 else
Chris Lattner424a04e2010-11-29 23:02:20 +0000379 outs() << " ";
Reid Spencer3a1582b2004-11-14 22:20:07 +0000380 unsigned mode = I->getMode();
Reid Spencerbede5832004-11-16 06:41:09 +0000381 printMode((mode >> 6) & 007);
382 printMode((mode >> 3) & 007);
383 printMode(mode & 007);
Chris Lattner424a04e2010-11-29 23:02:20 +0000384 outs() << " " << format("%4u", I->getUser());
385 outs() << "/" << format("%4u", I->getGroup());
386 outs() << " " << format("%8u", I->getSize());
387 outs() << " " << format("%20s", I->getModTime().str().substr(4).c_str());
388 outs() << " " << I->getPath().str() << "\n";
Reid Spencer3a1582b2004-11-14 22:20:07 +0000389 } else {
Chris Lattner424a04e2010-11-29 23:02:20 +0000390 outs() << I->getPath().str() << "\n";
Reid Spencer3a1582b2004-11-14 22:20:07 +0000391 }
392 }
393 }
Reid Spencer142ca8e2006-08-23 06:56:27 +0000394 return false;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000395}
396
397// doExtract - Implement the 'x' operation. This function extracts files back to
Rafael Espindola94bc2462012-08-10 01:57:52 +0000398// the file system.
Michael J. Spencer83a113b2011-01-10 02:34:40 +0000399bool
Reid Spencer142ca8e2006-08-23 06:56:27 +0000400doExtract(std::string* ErrMsg) {
401 if (buildPaths(false, ErrMsg))
402 return true;
Misha Brukman3da94ae2005-04-22 00:00:37 +0000403 for (Archive::iterator I = TheArchive->begin(), E = TheArchive->end();
Reid Spencer3a1582b2004-11-14 22:20:07 +0000404 I != E; ++I ) {
405 if (Paths.empty() ||
406 (std::find(Paths.begin(), Paths.end(), I->getPath()) != Paths.end())) {
407
Reid Spencer3a1582b2004-11-14 22:20:07 +0000408 // Open up a file stream for writing
Rafael Espindola11ca2e52013-06-20 20:56:14 +0000409 int OpenFlags = O_TRUNC | O_WRONLY | O_CREAT;
410#ifdef O_BINARY
411 OpenFlags |= O_BINARY;
412#endif
Reid Spencer3a1582b2004-11-14 22:20:07 +0000413
Rafael Espindola11ca2e52013-06-20 20:56:14 +0000414 int FD = open(I->getPath().str().c_str(), OpenFlags, 0664);
415 if (FD < 0)
416 return true;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000417
Rafael Espindola11ca2e52013-06-20 20:56:14 +0000418 {
419 raw_fd_ostream file(FD, false);
Reid Spencer3a1582b2004-11-14 22:20:07 +0000420
Rafael Espindola11ca2e52013-06-20 20:56:14 +0000421 // Get the data and its length
422 const char* data = reinterpret_cast<const char*>(I->getData());
423 unsigned len = I->getSize();
424
425 // Write the data.
426 file.write(data, len);
427 }
Rafael Espindola27ff1f32013-06-19 19:17:15 +0000428
429 // Retain the original mode.
Rafael Espindola11ca2e52013-06-20 20:56:14 +0000430 sys::fs::perms Mode = sys::fs::perms(I->getMode());
Rafael Espindola8874cc22013-06-20 22:04:56 +0000431 // FIXME: at least on posix we should be able to reuse FD (fchmod).
Rafael Espindola11ca2e52013-06-20 20:56:14 +0000432 error_code EC = sys::fs::permissions(I->getPath(), Mode);
433 if (EC)
434 fail(EC.message());
Rafael Espindola27ff1f32013-06-19 19:17:15 +0000435
Reid Spencer3a1582b2004-11-14 22:20:07 +0000436 // If we're supposed to retain the original modification times, etc. do so
437 // now.
Rafael Espindola11ca2e52013-06-20 20:56:14 +0000438 if (OriginalDates) {
439 EC = sys::fs::setLastModificationAndAccessTime(FD, I->getModTime());
440 if (EC)
441 fail(EC.message());
442 }
443 if (close(FD))
444 return true;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000445 }
446 }
Reid Spencere5c9cb52006-08-23 00:39:35 +0000447 return false;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000448}
449
450// doDelete - Implement the delete operation. This function deletes zero or more
451// members from the archive. Note that if the count is specified, there should
452// be no more than one path in the Paths list or else this algorithm breaks.
453// That check is enforced in parseCommandLine (above).
Michael J. Spencer83a113b2011-01-10 02:34:40 +0000454bool
Reid Spencer142ca8e2006-08-23 06:56:27 +0000455doDelete(std::string* ErrMsg) {
456 if (buildPaths(false, ErrMsg))
457 return true;
Michael J. Spencer83a113b2011-01-10 02:34:40 +0000458 if (Paths.empty())
Reid Spencer142ca8e2006-08-23 06:56:27 +0000459 return false;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000460 unsigned countDown = Count;
Misha Brukman3da94ae2005-04-22 00:00:37 +0000461 for (Archive::iterator I = TheArchive->begin(), E = TheArchive->end();
Reid Spencer3a1582b2004-11-14 22:20:07 +0000462 I != E; ) {
463 if (std::find(Paths.begin(), Paths.end(), I->getPath()) != Paths.end()) {
464 if (countDown == 1) {
465 Archive::iterator J = I;
466 ++I;
Reid Spencerbede5832004-11-16 06:41:09 +0000467 TheArchive->erase(J);
Reid Spencer3a1582b2004-11-14 22:20:07 +0000468 } else
469 countDown--;
470 } else {
471 ++I;
472 }
473 }
474
475 // We're done editting, reconstruct the archive.
Rafael Espindola6f2c88a2013-06-20 13:00:30 +0000476 if (TheArchive->writeToDisk(TruncateNames,ErrMsg))
Reid Spencer142ca8e2006-08-23 06:56:27 +0000477 return true;
Reid Spencer142ca8e2006-08-23 06:56:27 +0000478 return false;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000479}
480
481// doMore - Implement the move operation. This function re-arranges just the
482// order of the archive members so that when the archive is written the move
483// of the members is accomplished. Note the use of the RelPos variable to
484// determine where the items should be moved to.
Michael J. Spencer83a113b2011-01-10 02:34:40 +0000485bool
Reid Spencer142ca8e2006-08-23 06:56:27 +0000486doMove(std::string* ErrMsg) {
Michael J. Spencer83a113b2011-01-10 02:34:40 +0000487 if (buildPaths(false, ErrMsg))
Reid Spencer142ca8e2006-08-23 06:56:27 +0000488 return true;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000489
490 // By default and convention the place to move members to is the end of the
491 // archive.
492 Archive::iterator moveto_spot = TheArchive->end();
493
494 // However, if the relative positioning modifiers were used, we need to scan
495 // the archive to find the member in question. If we don't find it, its no
496 // crime, we just move to the end.
497 if (AddBefore || InsertBefore || AddAfter) {
Misha Brukman3da94ae2005-04-22 00:00:37 +0000498 for (Archive::iterator I = TheArchive->begin(), E= TheArchive->end();
Reid Spencer3a1582b2004-11-14 22:20:07 +0000499 I != E; ++I ) {
Chris Lattner74382b72009-08-23 22:45:37 +0000500 if (RelPos == I->getPath().str()) {
Reid Spencer3a1582b2004-11-14 22:20:07 +0000501 if (AddAfter) {
502 moveto_spot = I;
503 moveto_spot++;
504 } else {
505 moveto_spot = I;
506 }
507 break;
508 }
509 }
510 }
511
512 // Keep a list of the paths remaining to be moved
Rafael Espindola4d07abb2013-06-19 15:45:37 +0000513 std::set<std::string> remaining(Paths);
Reid Spencer3a1582b2004-11-14 22:20:07 +0000514
515 // Scan the archive again, this time looking for the members to move to the
516 // moveto_spot.
Misha Brukman3da94ae2005-04-22 00:00:37 +0000517 for (Archive::iterator I = TheArchive->begin(), E= TheArchive->end();
Reid Spencer3a1582b2004-11-14 22:20:07 +0000518 I != E && !remaining.empty(); ++I ) {
Rafael Espindola4d07abb2013-06-19 15:45:37 +0000519 std::set<std::string>::iterator found =
520 std::find(remaining.begin(),remaining.end(), I->getPath());
Reid Spencer3a1582b2004-11-14 22:20:07 +0000521 if (found != remaining.end()) {
Misha Brukman3da94ae2005-04-22 00:00:37 +0000522 if (I != moveto_spot)
Reid Spencerbede5832004-11-16 06:41:09 +0000523 TheArchive->splice(moveto_spot,*TheArchive,I);
Reid Spencer3a1582b2004-11-14 22:20:07 +0000524 remaining.erase(found);
525 }
526 }
527
528 // We're done editting, reconstruct the archive.
Rafael Espindola6f2c88a2013-06-20 13:00:30 +0000529 if (TheArchive->writeToDisk(TruncateNames,ErrMsg))
Reid Spencer142ca8e2006-08-23 06:56:27 +0000530 return true;
Reid Spencer142ca8e2006-08-23 06:56:27 +0000531 return false;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000532}
533
534// doQuickAppend - Implements the 'q' operation. This function just
535// indiscriminantly adds the members to the archive and rebuilds it.
Michael J. Spencer83a113b2011-01-10 02:34:40 +0000536bool
Reid Spencer142ca8e2006-08-23 06:56:27 +0000537doQuickAppend(std::string* ErrMsg) {
Reid Spencer3a1582b2004-11-14 22:20:07 +0000538 // Get the list of paths to append.
Reid Spencer142ca8e2006-08-23 06:56:27 +0000539 if (buildPaths(true, ErrMsg))
540 return true;
Michael J. Spencer83a113b2011-01-10 02:34:40 +0000541 if (Paths.empty())
Reid Spencer142ca8e2006-08-23 06:56:27 +0000542 return false;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000543
544 // Append them quickly.
Rafael Espindola4d07abb2013-06-19 15:45:37 +0000545 for (std::set<std::string>::iterator PI = Paths.begin(), PE = Paths.end();
Reid Spencer3a1582b2004-11-14 22:20:07 +0000546 PI != PE; ++PI) {
Rafael Espindola13f4fd72013-06-19 17:49:07 +0000547 if (TheArchive->addFileBefore(*PI, TheArchive->end(), ErrMsg))
Reid Spencer0ff2d312006-08-24 23:45:08 +0000548 return true;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000549 }
550
551 // We're done editting, reconstruct the archive.
Rafael Espindola6f2c88a2013-06-20 13:00:30 +0000552 if (TheArchive->writeToDisk(TruncateNames,ErrMsg))
Reid Spencer142ca8e2006-08-23 06:56:27 +0000553 return true;
Reid Spencer142ca8e2006-08-23 06:56:27 +0000554 return false;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000555}
556
557// doReplaceOrInsert - Implements the 'r' operation. This function will replace
Misha Brukman3da94ae2005-04-22 00:00:37 +0000558// any existing files or insert new ones into the archive.
Michael J. Spencer83a113b2011-01-10 02:34:40 +0000559bool
Reid Spencer142ca8e2006-08-23 06:56:27 +0000560doReplaceOrInsert(std::string* ErrMsg) {
Reid Spencer3a1582b2004-11-14 22:20:07 +0000561
562 // Build the list of files to be added/replaced.
Reid Spencer142ca8e2006-08-23 06:56:27 +0000563 if (buildPaths(true, ErrMsg))
564 return true;
Michael J. Spencer83a113b2011-01-10 02:34:40 +0000565 if (Paths.empty())
Reid Spencer142ca8e2006-08-23 06:56:27 +0000566 return false;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000567
568 // Keep track of the paths that remain to be inserted.
Rafael Espindola4d07abb2013-06-19 15:45:37 +0000569 std::set<std::string> remaining(Paths);
Reid Spencer3a1582b2004-11-14 22:20:07 +0000570
571 // Default the insertion spot to the end of the archive
572 Archive::iterator insert_spot = TheArchive->end();
573
574 // Iterate over the archive contents
575 for (Archive::iterator I = TheArchive->begin(), E = TheArchive->end();
576 I != E && !remaining.empty(); ++I ) {
577
578 // Determine if this archive member matches one of the paths we're trying
579 // to replace.
Reid Spencer0de66b52004-12-02 09:21:55 +0000580
Rafael Espindola4d07abb2013-06-19 15:45:37 +0000581 std::set<std::string>::iterator found = remaining.end();
582 for (std::set<std::string>::iterator RI = remaining.begin(),
Reid Spencer0de66b52004-12-02 09:21:55 +0000583 RE = remaining.end(); RI != RE; ++RI ) {
Rafael Espindolaeb729e02013-06-20 18:30:37 +0000584 std::string compare(sys::path::filename(*RI));
Reid Spencer0de66b52004-12-02 09:21:55 +0000585 if (TruncateNames && compare.length() > 15) {
586 const char* nm = compare.c_str();
587 unsigned len = compare.length();
588 size_t slashpos = compare.rfind('/');
589 if (slashpos != std::string::npos) {
590 nm += slashpos + 1;
591 len -= slashpos +1;
592 }
Misha Brukman3da94ae2005-04-22 00:00:37 +0000593 if (len > 15)
Reid Spencer0de66b52004-12-02 09:21:55 +0000594 len = 15;
595 compare.assign(nm,len);
596 }
Chris Lattner74382b72009-08-23 22:45:37 +0000597 if (compare == I->getPath().str()) {
Reid Spencer0de66b52004-12-02 09:21:55 +0000598 found = RI;
599 break;
600 }
601 }
602
Reid Spencer3a1582b2004-11-14 22:20:07 +0000603 if (found != remaining.end()) {
Rafael Espindola29c17db2013-06-20 18:42:04 +0000604 sys::fs::file_status Status;
605 error_code EC = sys::fs::status(*found, Status);
606 if (EC)
Reid Spencer0ff2d312006-08-24 23:45:08 +0000607 return true;
Rafael Espindola29c17db2013-06-20 18:42:04 +0000608 if (!sys::fs::is_directory(Status)) {
Reid Spencerbede5832004-11-16 06:41:09 +0000609 if (OnlyUpdate) {
610 // Replace the item only if it is newer.
Rafael Espindola29c17db2013-06-20 18:42:04 +0000611 if (Status.getLastModificationTime() > I->getModTime())
Rafael Espindola13f4fd72013-06-19 17:49:07 +0000612 if (I->replaceWith(*found, ErrMsg))
Reid Spencer0ff2d312006-08-24 23:45:08 +0000613 return true;
Reid Spencerbede5832004-11-16 06:41:09 +0000614 } else {
615 // Replace the item regardless of time stamp
Rafael Espindola13f4fd72013-06-19 17:49:07 +0000616 if (I->replaceWith(*found, ErrMsg))
Reid Spencer0ff2d312006-08-24 23:45:08 +0000617 return true;
Reid Spencerbede5832004-11-16 06:41:09 +0000618 }
Reid Spencer3a1582b2004-11-14 22:20:07 +0000619 } else {
Reid Spencerbede5832004-11-16 06:41:09 +0000620 // We purposefully ignore directories.
Reid Spencer3a1582b2004-11-14 22:20:07 +0000621 }
622
623 // Remove it from our "to do" list
624 remaining.erase(found);
625 }
626
627 // Determine if this is the place where we should insert
Chris Lattner74382b72009-08-23 22:45:37 +0000628 if ((AddBefore || InsertBefore) && RelPos == I->getPath().str())
Reid Spencer3a1582b2004-11-14 22:20:07 +0000629 insert_spot = I;
Chris Lattner74382b72009-08-23 22:45:37 +0000630 else if (AddAfter && RelPos == I->getPath().str()) {
Reid Spencer3a1582b2004-11-14 22:20:07 +0000631 insert_spot = I;
632 insert_spot++;
633 }
634 }
635
636 // If we didn't replace all the members, some will remain and need to be
637 // inserted at the previously computed insert-spot.
638 if (!remaining.empty()) {
Rafael Espindola4d07abb2013-06-19 15:45:37 +0000639 for (std::set<std::string>::iterator PI = remaining.begin(),
Reid Spencer3a1582b2004-11-14 22:20:07 +0000640 PE = remaining.end(); PI != PE; ++PI) {
Rafael Espindola13f4fd72013-06-19 17:49:07 +0000641 if (TheArchive->addFileBefore(*PI, insert_spot, ErrMsg))
Reid Spencer0ff2d312006-08-24 23:45:08 +0000642 return true;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000643 }
644 }
645
646 // We're done editting, reconstruct the archive.
Rafael Espindola6f2c88a2013-06-20 13:00:30 +0000647 if (TheArchive->writeToDisk(TruncateNames,ErrMsg))
Reid Spencer142ca8e2006-08-23 06:56:27 +0000648 return true;
Reid Spencer142ca8e2006-08-23 06:56:27 +0000649 return false;
Reid Spencer3a1582b2004-11-14 22:20:07 +0000650}
651
652// main - main program for llvm-ar .. see comments in the code
Tanya Lattner14baebf2003-08-28 15:22:38 +0000653int main(int argc, char **argv) {
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000654 program_name = argv[0];
Chris Lattnercc14d252009-03-06 05:34:10 +0000655 // Print a stack trace if we signal out.
656 sys::PrintStackTraceOnErrorSignal();
657 PrettyStackTraceProgram X(argc, argv);
Owen Anderson0d7c6952009-07-15 22:16:10 +0000658 LLVMContext &Context = getGlobalContext();
Chris Lattnercc14d252009-03-06 05:34:10 +0000659 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
Reid Spencer3a1582b2004-11-14 22:20:07 +0000660
Reid Spencer3a1582b2004-11-14 22:20:07 +0000661 // Have the command line options parsed and handle things
662 // like --help and --version.
663 cl::ParseCommandLineOptions(argc, argv,
Dan Gohman82a13c92007-10-08 15:45:12 +0000664 "LLVM Archiver (llvm-ar)\n\n"
Gabor Greifa99be512007-07-05 17:07:56 +0000665 " This program archives bitcode files into single libraries\n"
Reid Spencer3a1582b2004-11-14 22:20:07 +0000666 );
667
Reid Spencer3a1582b2004-11-14 22:20:07 +0000668 int exitCode = 0;
Tanya Lattner14baebf2003-08-28 15:22:38 +0000669
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000670 // Do our own parsing of the command line because the CommandLine utility
671 // can't handle the grouped positional parameters without a dash.
672 ArchiveOperation Operation = parseCommandLine();
Tanya Lattner14baebf2003-08-28 15:22:38 +0000673
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000674 // Create or open the archive object.
675 bool Exists;
Rafael Espindola201c66c2013-06-20 18:55:44 +0000676 if (llvm::sys::fs::exists(ArchiveName, Exists) || !Exists) {
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000677 // Produce a warning if we should and we're creating the archive
678 if (!Create)
Rafael Espindola201c66c2013-06-20 18:55:44 +0000679 errs() << argv[0] << ": creating " << ArchiveName << "\n";
680 TheArchive = Archive::CreateEmpty(ArchiveName, Context);
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000681 TheArchive->writeToDisk();
682 } else {
683 std::string Error;
Rafael Espindola201c66c2013-06-20 18:55:44 +0000684 TheArchive = Archive::OpenAndLoad(ArchiveName, Context, &Error);
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000685 if (TheArchive == 0) {
Rafael Espindola201c66c2013-06-20 18:55:44 +0000686 errs() << argv[0] << ": error loading '" << ArchiveName << "': "
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000687 << Error << "!\n";
Reid Spencer142ca8e2006-08-23 06:56:27 +0000688 return 1;
689 }
Reid Spencer3a1582b2004-11-14 22:20:07 +0000690 }
691
Joerg Sonnenberger975bc072012-10-26 10:49:15 +0000692 // Make sure we're not fooling ourselves.
693 assert(TheArchive && "Unable to instantiate the archive");
694
695 // Perform the operation
696 std::string ErrMsg;
697 bool haveError = false;
698 switch (Operation) {
699 case Print: haveError = doPrint(&ErrMsg); break;
700 case Delete: haveError = doDelete(&ErrMsg); break;
701 case Move: haveError = doMove(&ErrMsg); break;
702 case QuickAppend: haveError = doQuickAppend(&ErrMsg); break;
703 case ReplaceOrInsert: haveError = doReplaceOrInsert(&ErrMsg); break;
704 case DisplayTable: haveError = doDisplayTable(&ErrMsg); break;
705 case Extract: haveError = doExtract(&ErrMsg); break;
706 case NoOperation:
707 errs() << argv[0] << ": No operation was selected.\n";
708 break;
709 }
710 if (haveError) {
711 errs() << argv[0] << ": " << ErrMsg << "\n";
712 return 1;
713 }
714
715 delete TheArchive;
716 TheArchive = 0;
717
Reid Spencer3a1582b2004-11-14 22:20:07 +0000718 // Return result code back to operating system.
719 return exitCode;
Tanya Lattner14baebf2003-08-28 15:22:38 +0000720}