[C++11] Replace OwningPtr::take() with OwningPtr::release().
[oota-llvm.git] / tools / llvm-nm / llvm-nm.cpp
1 //===-- llvm-nm.cpp - Symbol table dumping utility for llvm ---------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This program is a utility that works like traditional Unix "nm", that is, it
11 // prints out the names of symbols in a bitcode or object file, along with some
12 // information about each symbol.
13 //
14 // This "nm" supports many of the features of GNU "nm", including its different
15 // output formats.
16 //
17 //===----------------------------------------------------------------------===//
18
19 #include "llvm/IR/Function.h"
20 #include "llvm/IR/GlobalAlias.h"
21 #include "llvm/IR/GlobalVariable.h"
22 #include "llvm/IR/LLVMContext.h"
23 #include "llvm/Object/Archive.h"
24 #include "llvm/Object/COFF.h"
25 #include "llvm/Object/ELFObjectFile.h"
26 #include "llvm/Object/IRObjectFile.h"
27 #include "llvm/Object/MachO.h"
28 #include "llvm/Object/MachOUniversal.h"
29 #include "llvm/Object/ObjectFile.h"
30 #include "llvm/Support/CommandLine.h"
31 #include "llvm/Support/FileSystem.h"
32 #include "llvm/Support/Format.h"
33 #include "llvm/Support/ManagedStatic.h"
34 #include "llvm/Support/MemoryBuffer.h"
35 #include "llvm/Support/PrettyStackTrace.h"
36 #include "llvm/Support/Program.h"
37 #include "llvm/Support/Signals.h"
38 #include "llvm/Support/raw_ostream.h"
39 #include "llvm/Support/system_error.h"
40 #include <algorithm>
41 #include <cctype>
42 #include <cerrno>
43 #include <cstring>
44 #include <vector>
45 using namespace llvm;
46 using namespace object;
47
48 namespace {
49 enum OutputFormatTy { bsd, sysv, posix };
50 cl::opt<OutputFormatTy> OutputFormat(
51     "format", cl::desc("Specify output format"),
52     cl::values(clEnumVal(bsd, "BSD format"), clEnumVal(sysv, "System V format"),
53                clEnumVal(posix, "POSIX.2 format"), clEnumValEnd),
54     cl::init(bsd));
55 cl::alias OutputFormat2("f", cl::desc("Alias for --format"),
56                         cl::aliasopt(OutputFormat));
57
58 cl::list<std::string> InputFilenames(cl::Positional, cl::desc("<input files>"),
59                                      cl::ZeroOrMore);
60
61 cl::opt<bool> UndefinedOnly("undefined-only",
62                             cl::desc("Show only undefined symbols"));
63 cl::alias UndefinedOnly2("u", cl::desc("Alias for --undefined-only"),
64                          cl::aliasopt(UndefinedOnly));
65
66 cl::opt<bool> DynamicSyms("dynamic",
67                           cl::desc("Display the dynamic symbols instead "
68                                    "of normal symbols."));
69 cl::alias DynamicSyms2("D", cl::desc("Alias for --dynamic"),
70                        cl::aliasopt(DynamicSyms));
71
72 cl::opt<bool> DefinedOnly("defined-only",
73                           cl::desc("Show only defined symbols"));
74
75 cl::opt<bool> ExternalOnly("extern-only",
76                            cl::desc("Show only external symbols"));
77 cl::alias ExternalOnly2("g", cl::desc("Alias for --extern-only"),
78                         cl::aliasopt(ExternalOnly));
79
80 cl::opt<bool> BSDFormat("B", cl::desc("Alias for --format=bsd"));
81 cl::opt<bool> POSIXFormat("P", cl::desc("Alias for --format=posix"));
82
83 cl::opt<bool> PrintFileName(
84     "print-file-name",
85     cl::desc("Precede each symbol with the object file it came from"));
86
87 cl::alias PrintFileNameA("A", cl::desc("Alias for --print-file-name"),
88                          cl::aliasopt(PrintFileName));
89 cl::alias PrintFileNameo("o", cl::desc("Alias for --print-file-name"),
90                          cl::aliasopt(PrintFileName));
91
92 cl::opt<bool> DebugSyms("debug-syms",
93                         cl::desc("Show all symbols, even debugger only"));
94 cl::alias DebugSymsa("a", cl::desc("Alias for --debug-syms"),
95                      cl::aliasopt(DebugSyms));
96
97 cl::opt<bool> NumericSort("numeric-sort", cl::desc("Sort symbols by address"));
98 cl::alias NumericSortn("n", cl::desc("Alias for --numeric-sort"),
99                        cl::aliasopt(NumericSort));
100 cl::alias NumericSortv("v", cl::desc("Alias for --numeric-sort"),
101                        cl::aliasopt(NumericSort));
102
103 cl::opt<bool> NoSort("no-sort", cl::desc("Show symbols in order encountered"));
104 cl::alias NoSortp("p", cl::desc("Alias for --no-sort"), cl::aliasopt(NoSort));
105
106 cl::opt<bool> PrintSize("print-size",
107                         cl::desc("Show symbol size instead of address"));
108 cl::alias PrintSizeS("S", cl::desc("Alias for --print-size"),
109                      cl::aliasopt(PrintSize));
110
111 cl::opt<bool> SizeSort("size-sort", cl::desc("Sort symbols by size"));
112
113 cl::opt<bool> WithoutAliases("without-aliases", cl::Hidden,
114                              cl::desc("Exclude aliases from output"));
115
116 cl::opt<bool> ArchiveMap("print-armap", cl::desc("Print the archive map"));
117 cl::alias ArchiveMaps("s", cl::desc("Alias for --print-armap"),
118                       cl::aliasopt(ArchiveMap));
119 bool PrintAddress = true;
120
121 bool MultipleFiles = false;
122
123 bool HadError = false;
124
125 std::string ToolName;
126 }
127
128 static void error(Twine Message, Twine Path = Twine()) {
129   HadError = true;
130   errs() << ToolName << ": " << Path << ": " << Message << ".\n";
131 }
132
133 static bool error(error_code EC, Twine Path = Twine()) {
134   if (EC) {
135     error(EC.message(), Path);
136     return true;
137   }
138   return false;
139 }
140
141 namespace {
142 struct NMSymbol {
143   uint64_t Address;
144   uint64_t Size;
145   char TypeChar;
146   StringRef Name;
147 };
148 }
149
150 static bool compareSymbolAddress(const NMSymbol &A, const NMSymbol &B) {
151   if (A.Address < B.Address)
152     return true;
153   else if (A.Address == B.Address && A.Name < B.Name)
154     return true;
155   else if (A.Address == B.Address && A.Name == B.Name && A.Size < B.Size)
156     return true;
157   else
158     return false;
159 }
160
161 static bool compareSymbolSize(const NMSymbol &A, const NMSymbol &B) {
162   if (A.Size < B.Size)
163     return true;
164   else if (A.Size == B.Size && A.Name < B.Name)
165     return true;
166   else if (A.Size == B.Size && A.Name == B.Name && A.Address < B.Address)
167     return true;
168   else
169     return false;
170 }
171
172 static bool compareSymbolName(const NMSymbol &A, const NMSymbol &B) {
173   if (A.Name < B.Name)
174     return true;
175   else if (A.Name == B.Name && A.Size < B.Size)
176     return true;
177   else if (A.Name == B.Name && A.Size == B.Size && A.Address < B.Address)
178     return true;
179   else
180     return false;
181 }
182
183 static StringRef CurrentFilename;
184 typedef std::vector<NMSymbol> SymbolListT;
185 static SymbolListT SymbolList;
186
187 static void sortAndPrintSymbolList() {
188   if (!NoSort) {
189     if (NumericSort)
190       std::sort(SymbolList.begin(), SymbolList.end(), compareSymbolAddress);
191     else if (SizeSort)
192       std::sort(SymbolList.begin(), SymbolList.end(), compareSymbolSize);
193     else
194       std::sort(SymbolList.begin(), SymbolList.end(), compareSymbolName);
195   }
196
197   if (OutputFormat == posix && MultipleFiles) {
198     outs() << '\n' << CurrentFilename << ":\n";
199   } else if (OutputFormat == bsd && MultipleFiles) {
200     outs() << "\n" << CurrentFilename << ":\n";
201   } else if (OutputFormat == sysv) {
202     outs() << "\n\nSymbols from " << CurrentFilename << ":\n\n"
203            << "Name                  Value   Class        Type"
204            << "         Size   Line  Section\n";
205   }
206
207   for (SymbolListT::iterator I = SymbolList.begin(), E = SymbolList.end();
208        I != E; ++I) {
209     if ((I->TypeChar != 'U') && UndefinedOnly)
210       continue;
211     if ((I->TypeChar == 'U') && DefinedOnly)
212       continue;
213     if (SizeSort && !PrintAddress && I->Size == UnknownAddressOrSize)
214       continue;
215
216     char SymbolAddrStr[10] = "";
217     char SymbolSizeStr[10] = "";
218
219     if (OutputFormat == sysv || I->Address == UnknownAddressOrSize)
220       strcpy(SymbolAddrStr, "        ");
221     if (OutputFormat == sysv)
222       strcpy(SymbolSizeStr, "        ");
223
224     if (I->Address != UnknownAddressOrSize)
225       format("%08" PRIx64, I->Address)
226           .print(SymbolAddrStr, sizeof(SymbolAddrStr));
227     if (I->Size != UnknownAddressOrSize)
228       format("%08" PRIx64, I->Size).print(SymbolSizeStr, sizeof(SymbolSizeStr));
229
230     if (OutputFormat == posix) {
231       outs() << I->Name << " " << I->TypeChar << " " << SymbolAddrStr
232              << SymbolSizeStr << "\n";
233     } else if (OutputFormat == bsd) {
234       if (PrintAddress)
235         outs() << SymbolAddrStr << ' ';
236       if (PrintSize) {
237         outs() << SymbolSizeStr;
238         if (I->Size != UnknownAddressOrSize)
239           outs() << ' ';
240       }
241       outs() << I->TypeChar << " " << I->Name << "\n";
242     } else if (OutputFormat == sysv) {
243       std::string PaddedName(I->Name);
244       while (PaddedName.length() < 20)
245         PaddedName += " ";
246       outs() << PaddedName << "|" << SymbolAddrStr << "|   " << I->TypeChar
247              << "  |                  |" << SymbolSizeStr << "|     |\n";
248     }
249   }
250
251   SymbolList.clear();
252 }
253
254 template <class ELFT>
255 static char getSymbolNMTypeChar(ELFObjectFile<ELFT> &Obj,
256                                 basic_symbol_iterator I) {
257   typedef typename ELFObjectFile<ELFT>::Elf_Sym Elf_Sym;
258   typedef typename ELFObjectFile<ELFT>::Elf_Shdr Elf_Shdr;
259
260   // OK, this is ELF
261   symbol_iterator SymI(I);
262
263   DataRefImpl Symb = I->getRawDataRefImpl();
264   const Elf_Sym *ESym = Obj.getSymbol(Symb);
265   const ELFFile<ELFT> &EF = *Obj.getELFFile();
266   const Elf_Shdr *ESec = EF.getSection(ESym);
267
268   if (ESec) {
269     switch (ESec->sh_type) {
270     case ELF::SHT_PROGBITS:
271     case ELF::SHT_DYNAMIC:
272       switch (ESec->sh_flags) {
273       case(ELF::SHF_ALLOC | ELF::SHF_EXECINSTR) :
274         return 't';
275       case(ELF::SHF_TLS | ELF::SHF_ALLOC | ELF::SHF_WRITE) :
276       case(ELF::SHF_ALLOC | ELF::SHF_WRITE) :
277         return 'd';
278       case ELF::SHF_ALLOC:
279       case(ELF::SHF_ALLOC | ELF::SHF_MERGE) :
280       case(ELF::SHF_ALLOC | ELF::SHF_MERGE | ELF::SHF_STRINGS) :
281         return 'r';
282       }
283       break;
284     case ELF::SHT_NOBITS:
285       return 'b';
286     }
287   }
288
289   if (ESym->getType() == ELF::STT_SECTION) {
290     StringRef Name;
291     if (error(SymI->getName(Name)))
292       return '?';
293     return StringSwitch<char>(Name)
294         .StartsWith(".debug", 'N')
295         .StartsWith(".note", 'n')
296         .Default('?');
297   }
298
299   return '?';
300 }
301
302 static char getSymbolNMTypeChar(COFFObjectFile &Obj, symbol_iterator I) {
303   const coff_symbol *Symb = Obj.getCOFFSymbol(I);
304   // OK, this is COFF.
305   symbol_iterator SymI(I);
306
307   StringRef Name;
308   if (error(SymI->getName(Name)))
309     return '?';
310
311   char Ret = StringSwitch<char>(Name)
312                  .StartsWith(".debug", 'N')
313                  .StartsWith(".sxdata", 'N')
314                  .Default('?');
315
316   if (Ret != '?')
317     return Ret;
318
319   uint32_t Characteristics = 0;
320   if (Symb->SectionNumber > 0) {
321     section_iterator SecI = Obj.section_end();
322     if (error(SymI->getSection(SecI)))
323       return '?';
324     const coff_section *Section = Obj.getCOFFSection(SecI);
325     Characteristics = Section->Characteristics;
326   }
327
328   switch (Symb->SectionNumber) {
329   case COFF::IMAGE_SYM_DEBUG:
330     return 'n';
331   default:
332     // Check section type.
333     if (Characteristics & COFF::IMAGE_SCN_CNT_CODE)
334       return 't';
335     else if (Characteristics & COFF::IMAGE_SCN_MEM_READ &&
336              ~Characteristics & COFF::IMAGE_SCN_MEM_WRITE) // Read only.
337       return 'r';
338     else if (Characteristics & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA)
339       return 'd';
340     else if (Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)
341       return 'b';
342     else if (Characteristics & COFF::IMAGE_SCN_LNK_INFO)
343       return 'i';
344
345     // Check for section symbol.
346     else if (Symb->StorageClass == COFF::IMAGE_SYM_CLASS_STATIC &&
347              Symb->Value == 0)
348       return 's';
349   }
350
351   return '?';
352 }
353
354 static uint8_t getNType(MachOObjectFile &Obj, DataRefImpl Symb) {
355   if (Obj.is64Bit()) {
356     MachO::nlist_64 STE = Obj.getSymbol64TableEntry(Symb);
357     return STE.n_type;
358   }
359   MachO::nlist STE = Obj.getSymbolTableEntry(Symb);
360   return STE.n_type;
361 }
362
363 static char getSymbolNMTypeChar(MachOObjectFile &Obj, basic_symbol_iterator I) {
364   DataRefImpl Symb = I->getRawDataRefImpl();
365   uint8_t NType = getNType(Obj, Symb);
366
367   switch (NType & MachO::N_TYPE) {
368   case MachO::N_ABS:
369     return 's';
370   case MachO::N_SECT: {
371     section_iterator Sec = Obj.section_end();
372     Obj.getSymbolSection(Symb, Sec);
373     DataRefImpl Ref = Sec->getRawDataRefImpl();
374     StringRef SectionName;
375     Obj.getSectionName(Ref, SectionName);
376     StringRef SegmentName = Obj.getSectionFinalSegmentName(Ref);
377     if (SegmentName == "__TEXT" && SectionName == "__text")
378       return 't';
379     else
380       return 's';
381   }
382   }
383
384   return '?';
385 }
386
387 static char getSymbolNMTypeChar(const GlobalValue &GV) {
388   if (isa<Function>(GV))
389     return 't';
390   // FIXME: should we print 'b'? At the IR level we cannot be sure if this
391   // will be in bss or not, but we could approximate.
392   if (isa<GlobalVariable>(GV))
393     return 'd';
394   const GlobalAlias *GA = cast<GlobalAlias>(&GV);
395   const GlobalValue *AliasedGV = GA->getAliasedGlobal();
396   return getSymbolNMTypeChar(*AliasedGV);
397 }
398
399 static char getSymbolNMTypeChar(IRObjectFile &Obj, basic_symbol_iterator I) {
400   const GlobalValue &GV = Obj.getSymbolGV(I->getRawDataRefImpl());
401   return getSymbolNMTypeChar(GV);
402 }
403
404 template <class ELFT>
405 static bool isObject(ELFObjectFile<ELFT> &Obj, symbol_iterator I) {
406   typedef typename ELFObjectFile<ELFT>::Elf_Sym Elf_Sym;
407
408   DataRefImpl Symb = I->getRawDataRefImpl();
409   const Elf_Sym *ESym = Obj.getSymbol(Symb);
410
411   return ESym->getType() == ELF::STT_OBJECT;
412 }
413
414 static bool isObject(SymbolicFile *Obj, basic_symbol_iterator I) {
415   if (ELF32LEObjectFile *ELF = dyn_cast<ELF32LEObjectFile>(Obj))
416     return isObject(*ELF, I);
417   if (ELF64LEObjectFile *ELF = dyn_cast<ELF64LEObjectFile>(Obj))
418     return isObject(*ELF, I);
419   if (ELF32BEObjectFile *ELF = dyn_cast<ELF32BEObjectFile>(Obj))
420     return isObject(*ELF, I);
421   if (ELF64BEObjectFile *ELF = dyn_cast<ELF64BEObjectFile>(Obj))
422     return isObject(*ELF, I);
423   return false;
424 }
425
426 static char getNMTypeChar(SymbolicFile *Obj, basic_symbol_iterator I) {
427   uint32_t Symflags = I->getFlags();
428   if ((Symflags & object::SymbolRef::SF_Weak) && !isa<MachOObjectFile>(Obj)) {
429     char Ret = isObject(Obj, I) ? 'v' : 'w';
430     if (!(Symflags & object::SymbolRef::SF_Undefined))
431       Ret = toupper(Ret);
432     return Ret;
433   }
434
435   if (Symflags & object::SymbolRef::SF_Undefined)
436     return 'U';
437
438   if (Symflags & object::SymbolRef::SF_Common)
439     return 'C';
440
441   char Ret = '?';
442   if (Symflags & object::SymbolRef::SF_Absolute)
443     Ret = 'a';
444   else if (IRObjectFile *IR = dyn_cast<IRObjectFile>(Obj))
445     Ret = getSymbolNMTypeChar(*IR, I);
446   else if (COFFObjectFile *COFF = dyn_cast<COFFObjectFile>(Obj))
447     Ret = getSymbolNMTypeChar(*COFF, I);
448   else if (MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(Obj))
449     Ret = getSymbolNMTypeChar(*MachO, I);
450   else if (ELF32LEObjectFile *ELF = dyn_cast<ELF32LEObjectFile>(Obj))
451     Ret = getSymbolNMTypeChar(*ELF, I);
452   else if (ELF64LEObjectFile *ELF = dyn_cast<ELF64LEObjectFile>(Obj))
453     Ret = getSymbolNMTypeChar(*ELF, I);
454   else if (ELF32BEObjectFile *ELF = dyn_cast<ELF32BEObjectFile>(Obj))
455     Ret = getSymbolNMTypeChar(*ELF, I);
456   else
457     Ret = getSymbolNMTypeChar(*cast<ELF64BEObjectFile>(Obj), I);
458
459   if (Symflags & object::SymbolRef::SF_Global)
460     Ret = toupper(Ret);
461
462   return Ret;
463 }
464
465 static void dumpSymbolNamesFromObject(SymbolicFile *Obj) {
466   basic_symbol_iterator IBegin = Obj->symbol_begin();
467   basic_symbol_iterator IEnd = Obj->symbol_end();
468   if (DynamicSyms) {
469     if (!Obj->isELF()) {
470       error("File format has no dynamic symbol table", Obj->getFileName());
471       return;
472     }
473     std::pair<symbol_iterator, symbol_iterator> IDyn =
474         getELFDynamicSymbolIterators(Obj);
475     IBegin = IDyn.first;
476     IEnd = IDyn.second;
477   }
478   std::string NameBuffer;
479   raw_string_ostream OS(NameBuffer);
480   for (basic_symbol_iterator I = IBegin; I != IEnd; ++I) {
481     uint32_t SymFlags = I->getFlags();
482     if (!DebugSyms && (SymFlags & SymbolRef::SF_FormatSpecific))
483       continue;
484     if (WithoutAliases) {
485       if (IRObjectFile *IR = dyn_cast<IRObjectFile>(Obj)) {
486         const GlobalValue &GV = IR->getSymbolGV(I->getRawDataRefImpl());
487         if(isa<GlobalAlias>(GV))
488           continue;
489       }
490     }
491     NMSymbol S;
492     S.Size = UnknownAddressOrSize;
493     S.Address = UnknownAddressOrSize;
494     if ((PrintSize || SizeSort) && isa<ObjectFile>(Obj)) {
495       symbol_iterator SymI = I;
496       if (error(SymI->getSize(S.Size)))
497         break;
498     }
499     if (PrintAddress && isa<ObjectFile>(Obj))
500       if (error(symbol_iterator(I)->getAddress(S.Address)))
501         break;
502     S.TypeChar = getNMTypeChar(Obj, I);
503     if (error(I->printName(OS)))
504       break;
505     OS << '\0';
506     SymbolList.push_back(S);
507   }
508
509   OS.flush();
510   const char *P = NameBuffer.c_str();
511   for (unsigned I = 0; I < SymbolList.size(); ++I) {
512     SymbolList[I].Name = P;
513     P += strlen(P) + 1;
514   }
515
516   CurrentFilename = Obj->getFileName();
517   sortAndPrintSymbolList();
518 }
519
520 static void dumpSymbolNamesFromFile(std::string &Filename) {
521   OwningPtr<MemoryBuffer> Buffer;
522   if (error(MemoryBuffer::getFileOrSTDIN(Filename, Buffer), Filename))
523     return;
524
525   LLVMContext &Context = getGlobalContext();
526   ErrorOr<Binary *> BinaryOrErr = createBinary(Buffer.release(), &Context);
527   if (error(BinaryOrErr.getError(), Filename))
528     return;
529   OwningPtr<Binary> Bin(BinaryOrErr.get());
530
531   if (Archive *A = dyn_cast<Archive>(Bin.get())) {
532     if (ArchiveMap) {
533       Archive::symbol_iterator I = A->symbol_begin();
534       Archive::symbol_iterator E = A->symbol_end();
535       if (I != E) {
536         outs() << "Archive map\n";
537         for (; I != E; ++I) {
538           Archive::child_iterator C;
539           StringRef SymName;
540           StringRef FileName;
541           if (error(I->getMember(C)))
542             return;
543           if (error(I->getName(SymName)))
544             return;
545           if (error(C->getName(FileName)))
546             return;
547           outs() << SymName << " in " << FileName << "\n";
548         }
549         outs() << "\n";
550       }
551     }
552
553     for (Archive::child_iterator I = A->child_begin(), E = A->child_end();
554          I != E; ++I) {
555       OwningPtr<Binary> Child;
556       if (I->getAsBinary(Child, &Context))
557         continue;
558       if (SymbolicFile *O = dyn_cast<SymbolicFile>(Child.get())) {
559         outs() << O->getFileName() << ":\n";
560         dumpSymbolNamesFromObject(O);
561       }
562     }
563     return;
564   }
565   if (MachOUniversalBinary *UB = dyn_cast<MachOUniversalBinary>(Bin.get())) {
566     for (MachOUniversalBinary::object_iterator I = UB->begin_objects(),
567                                                E = UB->end_objects();
568          I != E; ++I) {
569       OwningPtr<ObjectFile> Obj;
570       if (!I->getAsObjectFile(Obj)) {
571         outs() << Obj->getFileName() << ":\n";
572         dumpSymbolNamesFromObject(Obj.get());
573       }
574     }
575     return;
576   }
577   if (SymbolicFile *O = dyn_cast<SymbolicFile>(Bin.get())) {
578     dumpSymbolNamesFromObject(O);
579     return;
580   }
581   error("unrecognizable file type", Filename);
582   return;
583 }
584
585 int main(int argc, char **argv) {
586   // Print a stack trace if we signal out.
587   sys::PrintStackTraceOnErrorSignal();
588   PrettyStackTraceProgram X(argc, argv);
589
590   llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
591   cl::ParseCommandLineOptions(argc, argv, "llvm symbol table dumper\n");
592
593   // llvm-nm only reads binary files.
594   if (error(sys::ChangeStdinToBinary()))
595     return 1;
596
597   ToolName = argv[0];
598   if (BSDFormat)
599     OutputFormat = bsd;
600   if (POSIXFormat)
601     OutputFormat = posix;
602
603   // The relative order of these is important. If you pass --size-sort it should
604   // only print out the size. However, if you pass -S --size-sort, it should
605   // print out both the size and address.
606   if (SizeSort && !PrintSize)
607     PrintAddress = false;
608   if (OutputFormat == sysv || SizeSort)
609     PrintSize = true;
610
611   switch (InputFilenames.size()) {
612   case 0:
613     InputFilenames.push_back("-");
614   case 1:
615     break;
616   default:
617     MultipleFiles = true;
618   }
619
620   std::for_each(InputFilenames.begin(), InputFilenames.end(),
621                 dumpSymbolNamesFromFile);
622
623   if (HadError)
624     return 1;
625
626   return 0;
627 }