Revert "Fix a nomenclature error in llvm-nm."
[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/COFF.h"
31 #include "llvm/Support/CommandLine.h"
32 #include "llvm/Support/FileSystem.h"
33 #include "llvm/Support/Format.h"
34 #include "llvm/Support/ManagedStatic.h"
35 #include "llvm/Support/MemoryBuffer.h"
36 #include "llvm/Support/PrettyStackTrace.h"
37 #include "llvm/Support/Program.h"
38 #include "llvm/Support/Signals.h"
39 #include "llvm/Support/raw_ostream.h"
40 #include "llvm/Support/system_error.h"
41 #include <algorithm>
42 #include <cctype>
43 #include <cerrno>
44 #include <cstring>
45 #include <vector>
46 using namespace llvm;
47 using namespace object;
48
49 namespace {
50 enum OutputFormatTy { bsd, sysv, posix };
51 cl::opt<OutputFormatTy> OutputFormat(
52     "format", cl::desc("Specify output format"),
53     cl::values(clEnumVal(bsd, "BSD format"), clEnumVal(sysv, "System V format"),
54                clEnumVal(posix, "POSIX.2 format"), clEnumValEnd),
55     cl::init(bsd));
56 cl::alias OutputFormat2("f", cl::desc("Alias for --format"),
57                         cl::aliasopt(OutputFormat));
58
59 cl::list<std::string> InputFilenames(cl::Positional, cl::desc("<input files>"),
60                                      cl::ZeroOrMore);
61
62 cl::opt<bool> UndefinedOnly("undefined-only",
63                             cl::desc("Show only undefined symbols"));
64 cl::alias UndefinedOnly2("u", cl::desc("Alias for --undefined-only"),
65                          cl::aliasopt(UndefinedOnly));
66
67 cl::opt<bool> DynamicSyms("dynamic",
68                           cl::desc("Display the dynamic symbols instead "
69                                    "of normal symbols."));
70 cl::alias DynamicSyms2("D", cl::desc("Alias for --dynamic"),
71                        cl::aliasopt(DynamicSyms));
72
73 cl::opt<bool> DefinedOnly("defined-only",
74                           cl::desc("Show only defined symbols"));
75
76 cl::opt<bool> ExternalOnly("extern-only",
77                            cl::desc("Show only external symbols"));
78 cl::alias ExternalOnly2("g", cl::desc("Alias for --extern-only"),
79                         cl::aliasopt(ExternalOnly));
80
81 cl::opt<bool> BSDFormat("B", cl::desc("Alias for --format=bsd"));
82 cl::opt<bool> POSIXFormat("P", cl::desc("Alias for --format=posix"));
83
84 cl::opt<bool> PrintFileName(
85     "print-file-name",
86     cl::desc("Precede each symbol with the object file it came from"));
87
88 cl::alias PrintFileNameA("A", cl::desc("Alias for --print-file-name"),
89                          cl::aliasopt(PrintFileName));
90 cl::alias PrintFileNameo("o", cl::desc("Alias for --print-file-name"),
91                          cl::aliasopt(PrintFileName));
92
93 cl::opt<bool> DebugSyms("debug-syms",
94                         cl::desc("Show all symbols, even debugger only"));
95 cl::alias DebugSymsa("a", cl::desc("Alias for --debug-syms"),
96                      cl::aliasopt(DebugSyms));
97
98 cl::opt<bool> NumericSort("numeric-sort", cl::desc("Sort symbols by address"));
99 cl::alias NumericSortn("n", cl::desc("Alias for --numeric-sort"),
100                        cl::aliasopt(NumericSort));
101 cl::alias NumericSortv("v", cl::desc("Alias for --numeric-sort"),
102                        cl::aliasopt(NumericSort));
103
104 cl::opt<bool> NoSort("no-sort", cl::desc("Show symbols in order encountered"));
105 cl::alias NoSortp("p", cl::desc("Alias for --no-sort"), cl::aliasopt(NoSort));
106
107 cl::opt<bool> PrintSize("print-size",
108                         cl::desc("Show symbol size instead of address"));
109 cl::alias PrintSizeS("S", cl::desc("Alias for --print-size"),
110                      cl::aliasopt(PrintSize));
111
112 cl::opt<bool> SizeSort("size-sort", cl::desc("Sort symbols by size"));
113
114 cl::opt<bool> WithoutAliases("without-aliases", cl::Hidden,
115                              cl::desc("Exclude aliases from output"));
116
117 cl::opt<bool> ArchiveMap("print-armap", cl::desc("Print the archive map"));
118 cl::alias ArchiveMaps("s", cl::desc("Alias for --print-armap"),
119                       cl::aliasopt(ArchiveMap));
120 bool PrintAddress = true;
121
122 bool MultipleFiles = false;
123
124 bool HadError = false;
125
126 std::string ToolName;
127 }
128
129 static void error(Twine Message, Twine Path = Twine()) {
130   HadError = true;
131   errs() << ToolName << ": " << Path << ": " << Message << ".\n";
132 }
133
134 static bool error(error_code EC, Twine Path = Twine()) {
135   if (EC) {
136     error(EC.message(), Path);
137     return true;
138   }
139   return false;
140 }
141
142 namespace {
143 struct NMSymbol {
144   uint64_t Address;
145   uint64_t Size;
146   char TypeChar;
147   StringRef Name;
148 };
149 }
150
151 static bool compareSymbolAddress(const NMSymbol &A, const NMSymbol &B) {
152   if (A.Address < B.Address)
153     return true;
154   else if (A.Address == B.Address && A.Name < B.Name)
155     return true;
156   else if (A.Address == B.Address && A.Name == B.Name && A.Size < B.Size)
157     return true;
158   else
159     return false;
160 }
161
162 static bool compareSymbolSize(const NMSymbol &A, const NMSymbol &B) {
163   if (A.Size < B.Size)
164     return true;
165   else if (A.Size == B.Size && A.Name < B.Name)
166     return true;
167   else if (A.Size == B.Size && A.Name == B.Name && A.Address < B.Address)
168     return true;
169   else
170     return false;
171 }
172
173 static bool compareSymbolName(const NMSymbol &A, const NMSymbol &B) {
174   if (A.Name < B.Name)
175     return true;
176   else if (A.Name == B.Name && A.Size < B.Size)
177     return true;
178   else if (A.Name == B.Name && A.Size == B.Size && A.Address < B.Address)
179     return true;
180   else
181     return false;
182 }
183
184 static StringRef CurrentFilename;
185 typedef std::vector<NMSymbol> SymbolListT;
186 static SymbolListT SymbolList;
187
188 static void sortAndPrintSymbolList() {
189   if (!NoSort) {
190     if (NumericSort)
191       std::sort(SymbolList.begin(), SymbolList.end(), compareSymbolAddress);
192     else if (SizeSort)
193       std::sort(SymbolList.begin(), SymbolList.end(), compareSymbolSize);
194     else
195       std::sort(SymbolList.begin(), SymbolList.end(), compareSymbolName);
196   }
197
198   if (OutputFormat == posix && MultipleFiles) {
199     outs() << '\n' << CurrentFilename << ":\n";
200   } else if (OutputFormat == bsd && MultipleFiles) {
201     outs() << "\n" << CurrentFilename << ":\n";
202   } else if (OutputFormat == sysv) {
203     outs() << "\n\nSymbols from " << CurrentFilename << ":\n\n"
204            << "Name                  Value   Class        Type"
205            << "         Size   Line  Section\n";
206   }
207
208   for (SymbolListT::iterator I = SymbolList.begin(), E = SymbolList.end();
209        I != E; ++I) {
210     if ((I->TypeChar != 'U') && UndefinedOnly)
211       continue;
212     if ((I->TypeChar == 'U') && DefinedOnly)
213       continue;
214     if (SizeSort && !PrintAddress && I->Size == UnknownAddressOrSize)
215       continue;
216
217     char SymbolAddrStr[10] = "";
218     char SymbolSizeStr[10] = "";
219
220     if (OutputFormat == sysv || I->Address == UnknownAddressOrSize)
221       strcpy(SymbolAddrStr, "        ");
222     if (OutputFormat == sysv)
223       strcpy(SymbolSizeStr, "        ");
224
225     if (I->Address != UnknownAddressOrSize)
226       format("%08" PRIx64, I->Address)
227           .print(SymbolAddrStr, sizeof(SymbolAddrStr));
228     if (I->Size != UnknownAddressOrSize)
229       format("%08" PRIx64, I->Size).print(SymbolSizeStr, sizeof(SymbolSizeStr));
230
231     if (OutputFormat == posix) {
232       outs() << I->Name << " " << I->TypeChar << " " << SymbolAddrStr
233              << SymbolSizeStr << "\n";
234     } else if (OutputFormat == bsd) {
235       if (PrintAddress)
236         outs() << SymbolAddrStr << ' ';
237       if (PrintSize) {
238         outs() << SymbolSizeStr;
239         if (I->Size != UnknownAddressOrSize)
240           outs() << ' ';
241       }
242       outs() << I->TypeChar << " " << I->Name << "\n";
243     } else if (OutputFormat == sysv) {
244       std::string PaddedName(I->Name);
245       while (PaddedName.length() < 20)
246         PaddedName += " ";
247       outs() << PaddedName << "|" << SymbolAddrStr << "|   " << I->TypeChar
248              << "  |                  |" << SymbolSizeStr << "|     |\n";
249     }
250   }
251
252   SymbolList.clear();
253 }
254
255 template <class ELFT>
256 static char getSymbolNMTypeChar(ELFObjectFile<ELFT> &Obj,
257                                 basic_symbol_iterator I) {
258   typedef typename ELFObjectFile<ELFT>::Elf_Sym Elf_Sym;
259   typedef typename ELFObjectFile<ELFT>::Elf_Shdr Elf_Shdr;
260
261   // OK, this is ELF
262   symbol_iterator SymI(I);
263
264   DataRefImpl Symb = I->getRawDataRefImpl();
265   const Elf_Sym *ESym = Obj.getSymbol(Symb);
266   const ELFFile<ELFT> &EF = *Obj.getELFFile();
267   const Elf_Shdr *ESec = EF.getSection(ESym);
268
269   if (ESec) {
270     switch (ESec->sh_type) {
271     case ELF::SHT_PROGBITS:
272     case ELF::SHT_DYNAMIC:
273       switch (ESec->sh_flags) {
274       case(ELF::SHF_ALLOC | ELF::SHF_EXECINSTR) :
275         return 't';
276       case(ELF::SHF_TLS | ELF::SHF_ALLOC | ELF::SHF_WRITE) :
277       case(ELF::SHF_ALLOC | ELF::SHF_WRITE) :
278         return 'd';
279       case ELF::SHF_ALLOC:
280       case(ELF::SHF_ALLOC | ELF::SHF_MERGE) :
281       case(ELF::SHF_ALLOC | ELF::SHF_MERGE | ELF::SHF_STRINGS) :
282         return 'r';
283       }
284       break;
285     case ELF::SHT_NOBITS:
286       return 'b';
287     }
288   }
289
290   if (ESym->getType() == ELF::STT_SECTION) {
291     StringRef Name;
292     if (error(SymI->getName(Name)))
293       return '?';
294     return StringSwitch<char>(Name)
295         .StartsWith(".debug", 'N')
296         .StartsWith(".note", 'n')
297         .Default('?');
298   }
299
300   return '?';
301 }
302
303 static char getSymbolNMTypeChar(COFFObjectFile &Obj, symbol_iterator I) {
304   const coff_symbol *Symb = Obj.getCOFFSymbol(*I);
305   // OK, this is COFF.
306   symbol_iterator SymI(I);
307
308   StringRef Name;
309   if (error(SymI->getName(Name)))
310     return '?';
311
312   char Ret = StringSwitch<char>(Name)
313                  .StartsWith(".debug", 'N')
314                  .StartsWith(".sxdata", 'N')
315                  .Default('?');
316
317   if (Ret != '?')
318     return Ret;
319
320   uint32_t Characteristics = 0;
321   if (!COFF::isReservedSectionNumber(Symb->SectionNumber)) {
322     section_iterator SecI = Obj.section_end();
323     if (error(SymI->getSection(SecI)))
324       return '?';
325     const coff_section *Section = Obj.getCOFFSection(*SecI);
326     Characteristics = Section->Characteristics;
327   }
328
329   switch (Symb->SectionNumber) {
330   case COFF::IMAGE_SYM_DEBUG:
331     return 'n';
332   default:
333     // Check section type.
334     if (Characteristics & COFF::IMAGE_SCN_CNT_CODE)
335       return 't';
336     else if (Characteristics & COFF::IMAGE_SCN_MEM_READ &&
337              ~Characteristics & COFF::IMAGE_SCN_MEM_WRITE) // Read only.
338       return 'r';
339     else if (Characteristics & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA)
340       return 'd';
341     else if (Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)
342       return 'b';
343     else if (Characteristics & COFF::IMAGE_SCN_LNK_INFO)
344       return 'i';
345
346     // Check for section symbol.
347     else if (Symb->isSectionDefinition())
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   std::unique_ptr<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   std::unique_ptr<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       std::unique_ptr<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       std::unique_ptr<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 }