blob: 122ac833987e6d29c1be1d8e26b397c0f93a5ce8 [file] [log] [blame]
Michael J. Spencer92e1deb2011-01-20 06:39:06 +00001//===-- llvm-objdump.cpp - Object file 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 binutils "objdump", that is, it
11// dumps out a plethora of information about an object file depending on the
12// flags.
13//
Michael J. Spencerdd3aa9e2013-02-05 20:27:22 +000014// The flags and output of this program should be near identical to those of
15// binutils objdump.
16//
Michael J. Spencer92e1deb2011-01-20 06:39:06 +000017//===----------------------------------------------------------------------===//
18
Benjamin Kramer0b8b7712011-09-19 17:56:04 +000019#include "llvm-objdump.h"
Michael J. Spencer92e1deb2011-01-20 06:39:06 +000020#include "llvm/ADT/OwningPtr.h"
Chandler Carruthf010c462012-12-04 10:44:52 +000021#include "llvm/ADT/STLExtras.h"
Michael J. Spencer1e8ba3f2011-10-17 17:13:22 +000022#include "llvm/ADT/StringExtras.h"
Michael J. Spencer92e1deb2011-01-20 06:39:06 +000023#include "llvm/ADT/Triple.h"
24#include "llvm/MC/MCAsmInfo.h"
Ahmed Bougachaef993562013-05-24 01:07:04 +000025#include "llvm/MC/MCAtom.h"
Ahmed Bougacha2c94d0f2013-05-24 00:39:57 +000026#include "llvm/MC/MCContext.h"
Michael J. Spencer92e1deb2011-01-20 06:39:06 +000027#include "llvm/MC/MCDisassembler.h"
Ahmed Bougachaef993562013-05-24 01:07:04 +000028#include "llvm/MC/MCFunction.h"
Michael J. Spencer92e1deb2011-01-20 06:39:06 +000029#include "llvm/MC/MCInst.h"
30#include "llvm/MC/MCInstPrinter.h"
Ahmed Bougachaef993562013-05-24 01:07:04 +000031#include "llvm/MC/MCInstrAnalysis.h"
Craig Topper17463b32012-04-02 06:09:36 +000032#include "llvm/MC/MCInstrInfo.h"
Ahmed Bougachaef993562013-05-24 01:07:04 +000033#include "llvm/MC/MCModule.h"
34#include "llvm/MC/MCObjectDisassembler.h"
Ahmed Bougacha2c94d0f2013-05-24 00:39:57 +000035#include "llvm/MC/MCObjectFileInfo.h"
36#include "llvm/MC/MCObjectSymbolizer.h"
Jim Grosbachc6449b62012-03-05 19:33:20 +000037#include "llvm/MC/MCRegisterInfo.h"
Ahmed Bougacha2c94d0f2013-05-24 00:39:57 +000038#include "llvm/MC/MCRelocationInfo.h"
Ahmed Bougachaef993562013-05-24 01:07:04 +000039#include "llvm/MC/MCSubtargetInfo.h"
Chandler Carruthf010c462012-12-04 10:44:52 +000040#include "llvm/Object/Archive.h"
41#include "llvm/Object/COFF.h"
Rafael Espindolacef81b32012-12-21 03:47:03 +000042#include "llvm/Object/MachO.h"
Chandler Carruthf010c462012-12-04 10:44:52 +000043#include "llvm/Object/ObjectFile.h"
Michael J. Spencer27781b72011-10-08 00:18:30 +000044#include "llvm/Support/Casting.h"
Michael J. Spencer92e1deb2011-01-20 06:39:06 +000045#include "llvm/Support/CommandLine.h"
46#include "llvm/Support/Debug.h"
Michael J. Spencer27781b72011-10-08 00:18:30 +000047#include "llvm/Support/FileSystem.h"
Michael J. Spencer92e1deb2011-01-20 06:39:06 +000048#include "llvm/Support/Format.h"
Benjamin Kramer853b0fd2011-07-25 23:04:36 +000049#include "llvm/Support/GraphWriter.h"
Michael J. Spencer92e1deb2011-01-20 06:39:06 +000050#include "llvm/Support/Host.h"
51#include "llvm/Support/ManagedStatic.h"
52#include "llvm/Support/MemoryBuffer.h"
Michael J. Spencer92e1deb2011-01-20 06:39:06 +000053#include "llvm/Support/MemoryObject.h"
54#include "llvm/Support/PrettyStackTrace.h"
55#include "llvm/Support/Signals.h"
56#include "llvm/Support/SourceMgr.h"
Evan Cheng3e74d6f2011-08-24 18:08:43 +000057#include "llvm/Support/TargetRegistry.h"
58#include "llvm/Support/TargetSelect.h"
Michael J. Spencer92e1deb2011-01-20 06:39:06 +000059#include "llvm/Support/raw_ostream.h"
Michael J. Spencer92e1deb2011-01-20 06:39:06 +000060#include "llvm/Support/system_error.h"
Michael J. Spencer92e1deb2011-01-20 06:39:06 +000061#include <algorithm>
Benjamin Kramer81bbdfd2012-03-23 11:49:32 +000062#include <cctype>
Michael J. Spencer92e1deb2011-01-20 06:39:06 +000063#include <cstring>
Michael J. Spencer92e1deb2011-01-20 06:39:06 +000064using namespace llvm;
65using namespace object;
66
Benjamin Kramer0b8b7712011-09-19 17:56:04 +000067static cl::list<std::string>
68InputFilenames(cl::Positional, cl::desc("<input object files>"),cl::ZeroOrMore);
Michael J. Spencer92e1deb2011-01-20 06:39:06 +000069
Benjamin Kramer0b8b7712011-09-19 17:56:04 +000070static cl::opt<bool>
71Disassemble("disassemble",
72 cl::desc("Display assembler mnemonics for the machine instructions"));
73static cl::alias
74Disassembled("d", cl::desc("Alias for --disassemble"),
75 cl::aliasopt(Disassemble));
Michael J. Spencer92e1deb2011-01-20 06:39:06 +000076
Benjamin Kramer0b8b7712011-09-19 17:56:04 +000077static cl::opt<bool>
Michael J. Spencer27781b72011-10-08 00:18:30 +000078Relocations("r", cl::desc("Display the relocation entries in the file"));
79
80static cl::opt<bool>
Michael J. Spencer1e8ba3f2011-10-17 17:13:22 +000081SectionContents("s", cl::desc("Display the content of each section"));
82
83static cl::opt<bool>
Michael J. Spencer22ff0f32011-10-18 19:32:17 +000084SymbolTable("t", cl::desc("Display the symbol table"));
85
86static cl::opt<bool>
Rafael Espindolacef81b32012-12-21 03:47:03 +000087MachOOpt("macho", cl::desc("Use MachO specific object file parser"));
Benjamin Kramer0b8b7712011-09-19 17:56:04 +000088static cl::alias
Rafael Espindolacef81b32012-12-21 03:47:03 +000089MachOm("m", cl::desc("Alias for --macho"), cl::aliasopt(MachOOpt));
Benjamin Kramer685a2502011-07-20 19:37:35 +000090
Benjamin Kramer0b8b7712011-09-19 17:56:04 +000091cl::opt<std::string>
92llvm::TripleName("triple", cl::desc("Target triple to disassemble for, "
93 "see -version for available targets"));
94
95cl::opt<std::string>
96llvm::ArchName("arch", cl::desc("Target arch to disassemble for, "
Michael J. Spencer92e1deb2011-01-20 06:39:06 +000097 "see -version for available targets"));
98
Nick Lewycky023bb152011-10-10 21:21:34 +000099static cl::opt<bool>
100SectionHeaders("section-headers", cl::desc("Display summaries of the headers "
101 "for each section."));
102static cl::alias
103SectionHeadersShort("headers", cl::desc("Alias for --section-headers"),
104 cl::aliasopt(SectionHeaders));
105static cl::alias
106SectionHeadersShorter("h", cl::desc("Alias for --section-headers"),
107 cl::aliasopt(SectionHeaders));
108
Jack Carterfd6d1652012-08-28 19:24:49 +0000109static cl::list<std::string>
110MAttrs("mattr",
111 cl::CommaSeparated,
112 cl::desc("Target specific attributes"),
113 cl::value_desc("a1,+a2,-a3,..."));
114
Eli Bendersky8b9da532012-11-20 22:57:02 +0000115static cl::opt<bool>
116NoShowRawInsn("no-show-raw-insn", cl::desc("When disassembling instructions, "
117 "do not print the instruction bytes."));
118
Michael J. Spencereef7b622012-12-05 20:12:35 +0000119static cl::opt<bool>
120UnwindInfo("unwind-info", cl::desc("Display unwind information"));
121
122static cl::alias
123UnwindInfoShort("u", cl::desc("Alias for --unwind-info"),
124 cl::aliasopt(UnwindInfo));
125
Michael J. Spencerb2c064c2013-01-06 03:56:49 +0000126static cl::opt<bool>
127PrivateHeaders("private-headers",
128 cl::desc("Display format specific file headers"));
129
130static cl::alias
131PrivateHeadersShort("p", cl::desc("Alias for --private-headers"),
132 cl::aliasopt(PrivateHeaders));
133
Ahmed Bougacha2c94d0f2013-05-24 00:39:57 +0000134static cl::opt<bool>
135Symbolize("symbolize", cl::desc("When disassembling instructions, "
136 "try to symbolize operands."));
137
Ahmed Bougachaef993562013-05-24 01:07:04 +0000138static cl::opt<bool>
139CFG("cfg", cl::desc("Create a CFG for every function found in the object"
140 " and write it to a graphviz file"));
141
Benjamin Kramer0b8b7712011-09-19 17:56:04 +0000142static StringRef ToolName;
Michael J. Spencer92e1deb2011-01-20 06:39:06 +0000143
Michael J. Spencereef7b622012-12-05 20:12:35 +0000144bool llvm::error(error_code ec) {
Benjamin Kramer0b8b7712011-09-19 17:56:04 +0000145 if (!ec) return false;
Michael J. Spencer25b15772011-06-25 17:55:23 +0000146
Benjamin Kramer0b8b7712011-09-19 17:56:04 +0000147 outs() << ToolName << ": error reading file: " << ec.message() << ".\n";
148 outs().flush();
149 return true;
Michael J. Spencer92e1deb2011-01-20 06:39:06 +0000150}
151
Jim Grosbach3f5d1a22012-08-07 17:53:14 +0000152static const Target *getTarget(const ObjectFile *Obj = NULL) {
Michael J. Spencer92e1deb2011-01-20 06:39:06 +0000153 // Figure out the target triple.
Kevin Enderby9ed9e5d2012-05-08 23:38:45 +0000154 llvm::Triple TheTriple("unknown-unknown-unknown");
Michael J. Spencerd11699d2011-01-20 07:22:04 +0000155 if (TripleName.empty()) {
Ahmed Bougacha2c94d0f2013-05-24 00:39:57 +0000156 if (Obj) {
Kevin Enderby9ed9e5d2012-05-08 23:38:45 +0000157 TheTriple.setArch(Triple::ArchType(Obj->getArch()));
Ahmed Bougacha2c94d0f2013-05-24 00:39:57 +0000158 // TheTriple defaults to ELF, and COFF doesn't have an environment:
159 // the best we can do here is indicate that it is mach-o.
160 if (Obj->isMachO())
161 TheTriple.setEnvironment(Triple::MachO);
162 }
Michael J. Spencerd11699d2011-01-20 07:22:04 +0000163 } else
Kevin Enderby9ed9e5d2012-05-08 23:38:45 +0000164 TheTriple.setTriple(Triple::normalize(TripleName));
Michael J. Spencer92e1deb2011-01-20 06:39:06 +0000165
166 // Get the target specific parser.
167 std::string Error;
Kevin Enderby9ed9e5d2012-05-08 23:38:45 +0000168 const Target *TheTarget = TargetRegistry::lookupTarget(ArchName, TheTriple,
169 Error);
170 if (!TheTarget) {
171 errs() << ToolName << ": " << Error;
172 return 0;
173 }
Michael J. Spencer92e1deb2011-01-20 06:39:06 +0000174
Kevin Enderby9ed9e5d2012-05-08 23:38:45 +0000175 // Update the triple name and return the found target.
176 TripleName = TheTriple.getTriple();
177 return TheTarget;
Michael J. Spencer92e1deb2011-01-20 06:39:06 +0000178}
179
Ahmed Bougachaef993562013-05-24 01:07:04 +0000180// Write a graphviz file for the CFG inside an MCFunction.
181static void emitDOTFile(const char *FileName, const MCFunction &f,
182 MCInstPrinter *IP) {
183 // Start a new dot file.
184 std::string Error;
185 raw_fd_ostream Out(FileName, Error);
186 if (!Error.empty()) {
187 errs() << "llvm-objdump: warning: " << Error << '\n';
188 return;
189 }
190
191 Out << "digraph \"" << f.getName() << "\" {\n";
192 Out << "graph [ rankdir = \"LR\" ];\n";
193 for (MCFunction::const_iterator i = f.begin(), e = f.end(); i != e; ++i) {
194 // Only print blocks that have predecessors.
195 bool hasPreds = (*i)->pred_begin() != (*i)->pred_end();
196
197 if (!hasPreds && i != f.begin())
198 continue;
199
200 Out << '"' << (*i)->getInsts()->getBeginAddr() << "\" [ label=\"<a>";
201 // Print instructions.
202 for (unsigned ii = 0, ie = (*i)->getInsts()->size(); ii != ie;
203 ++ii) {
204 if (ii != 0) // Not the first line, start a new row.
205 Out << '|';
206 if (ii + 1 == ie) // Last line, add an end id.
207 Out << "<o>";
208
209 // Escape special chars and print the instruction in mnemonic form.
210 std::string Str;
211 raw_string_ostream OS(Str);
212 IP->printInst(&(*i)->getInsts()->at(ii).Inst, OS, "");
213 Out << DOT::EscapeString(OS.str());
214 }
215 Out << "\" shape=\"record\" ];\n";
216
217 // Add edges.
218 for (MCBasicBlock::succ_const_iterator si = (*i)->succ_begin(),
219 se = (*i)->succ_end(); si != se; ++si)
220 Out << (*i)->getInsts()->getBeginAddr() << ":o -> "
221 << (*si)->getInsts()->getBeginAddr() << ":a\n";
222 }
223 Out << "}\n";
224}
David Blaikie2d24e2a2011-12-20 02:50:00 +0000225
Benjamin Kramer0b8b7712011-09-19 17:56:04 +0000226void llvm::DumpBytes(StringRef bytes) {
227 static const char hex_rep[] = "0123456789abcdef";
Michael J. Spencer92e1deb2011-01-20 06:39:06 +0000228 // FIXME: The real way to do this is to figure out the longest instruction
229 // and align to that size before printing. I'll fix this when I get
230 // around to outputting relocations.
231 // 15 is the longest x86 instruction
232 // 3 is for the hex rep of a byte + a space.
233 // 1 is for the null terminator.
234 enum { OutputSize = (15 * 3) + 1 };
235 char output[OutputSize];
236
237 assert(bytes.size() <= 15
238 && "DumpBytes only supports instructions of up to 15 bytes");
239 memset(output, ' ', sizeof(output));
240 unsigned index = 0;
241 for (StringRef::iterator i = bytes.begin(),
242 e = bytes.end(); i != e; ++i) {
243 output[index] = hex_rep[(*i & 0xF0) >> 4];
244 output[index + 1] = hex_rep[*i & 0xF];
245 index += 3;
246 }
247
248 output[sizeof(output) - 1] = 0;
249 outs() << output;
250}
251
Michael J. Spencereef7b622012-12-05 20:12:35 +0000252bool llvm::RelocAddressLess(RelocationRef a, RelocationRef b) {
Michael J. Spencer942eb002011-10-13 22:17:18 +0000253 uint64_t a_addr, b_addr;
Rafael Espindola956ca722013-04-25 12:28:45 +0000254 if (error(a.getOffset(a_addr))) return false;
255 if (error(b.getOffset(b_addr))) return false;
Michael J. Spencer942eb002011-10-13 22:17:18 +0000256 return a_addr < b_addr;
257}
258
259static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
Jim Grosbach3f5d1a22012-08-07 17:53:14 +0000260 const Target *TheTarget = getTarget(Obj);
261 // getTarget() will have already issued a diagnostic if necessary, so
262 // just bail here if it failed.
263 if (!TheTarget)
Michael J. Spencer92e1deb2011-01-20 06:39:06 +0000264 return;
Michael J. Spencer92e1deb2011-01-20 06:39:06 +0000265
Jack Carterfd6d1652012-08-28 19:24:49 +0000266 // Package up features to be passed to target/subtarget
267 std::string FeaturesStr;
268 if (MAttrs.size()) {
269 SubtargetFeatures Features;
270 for (unsigned i = 0; i != MAttrs.size(); ++i)
271 Features.AddFeature(MAttrs[i]);
272 FeaturesStr = Features.getString();
273 }
274
Ahmed Bougacha27a33ad2013-05-16 21:28:23 +0000275 OwningPtr<const MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TripleName));
276 if (!MRI) {
277 errs() << "error: no register info for target " << TripleName << "\n";
278 return;
279 }
280
281 // Set up disassembler.
282 OwningPtr<const MCAsmInfo> AsmInfo(
283 TheTarget->createMCAsmInfo(*MRI, TripleName));
Ahmed Bougacha27a33ad2013-05-16 21:28:23 +0000284 if (!AsmInfo) {
285 errs() << "error: no assembly info for target " << TripleName << "\n";
286 return;
287 }
288
289 OwningPtr<const MCSubtargetInfo> STI(
290 TheTarget->createMCSubtargetInfo(TripleName, "", FeaturesStr));
Ahmed Bougacha27a33ad2013-05-16 21:28:23 +0000291 if (!STI) {
292 errs() << "error: no subtarget info for target " << TripleName << "\n";
293 return;
294 }
295
Ahmed Bougacha27a33ad2013-05-16 21:28:23 +0000296 OwningPtr<const MCInstrInfo> MII(TheTarget->createMCInstrInfo());
297 if (!MII) {
298 errs() << "error: no instruction info for target " << TripleName << "\n";
299 return;
300 }
301
Ahmed Bougacha2c94d0f2013-05-24 00:39:57 +0000302 OwningPtr<MCDisassembler> DisAsm(TheTarget->createMCDisassembler(*STI));
303 if (!DisAsm) {
304 errs() << "error: no disassembler for target " << TripleName << "\n";
305 return;
306 }
307
308 OwningPtr<const MCObjectFileInfo> MOFI;
309 OwningPtr<MCContext> Ctx;
310
311 if (Symbolize) {
312 MOFI.reset(new MCObjectFileInfo);
Bill Wendling99cb6222013-06-18 07:20:20 +0000313 Ctx.reset(new MCContext(AsmInfo.get(), MRI.get(), MOFI.get()));
Ahmed Bougacha2c94d0f2013-05-24 00:39:57 +0000314 OwningPtr<MCRelocationInfo> RelInfo(
315 TheTarget->createMCRelocationInfo(TripleName, *Ctx.get()));
316 if (RelInfo) {
317 OwningPtr<MCSymbolizer> Symzer(
318 MCObjectSymbolizer::createObjectSymbolizer(*Ctx.get(), RelInfo, Obj));
319 if (Symzer)
320 DisAsm->setSymbolizer(Symzer);
321 }
322 }
323
Ahmed Bougachaef993562013-05-24 01:07:04 +0000324 OwningPtr<const MCInstrAnalysis>
325 MIA(TheTarget->createMCInstrAnalysis(MII.get()));
326
Ahmed Bougacha27a33ad2013-05-16 21:28:23 +0000327 int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
328 OwningPtr<MCInstPrinter> IP(TheTarget->createMCInstPrinter(
329 AsmPrinterVariant, *AsmInfo, *MII, *MRI, *STI));
330 if (!IP) {
331 errs() << "error: no instruction printer for target " << TripleName
332 << '\n';
333 return;
334 }
335
Ahmed Bougachaef993562013-05-24 01:07:04 +0000336 if (CFG) {
337 OwningPtr<MCObjectDisassembler> OD(
338 new MCObjectDisassembler(*Obj, *DisAsm, *MIA));
339 OwningPtr<MCModule> Mod(OD->buildModule(/* withCFG */ true));
340 for (MCModule::const_atom_iterator AI = Mod->atom_begin(),
341 AE = Mod->atom_end();
342 AI != AE; ++AI) {
343 outs() << "Atom " << (*AI)->getName() << ": \n";
344 if (const MCTextAtom *TA = dyn_cast<MCTextAtom>(*AI)) {
345 for (MCTextAtom::const_iterator II = TA->begin(), IE = TA->end();
346 II != IE;
347 ++II) {
348 IP->printInst(&II->Inst, outs(), "");
349 outs() << "\n";
350 }
351 }
352 }
353 for (MCModule::const_func_iterator FI = Mod->func_begin(),
354 FE = Mod->func_end();
355 FI != FE; ++FI) {
356 static int filenum = 0;
357 emitDOTFile((Twine((*FI)->getName()) + "_" +
NAKAMURA Takumid1c99b22013-05-27 00:02:48 +0000358 utostr(filenum) + ".dot").str().c_str(),
Ahmed Bougachaef993562013-05-24 01:07:04 +0000359 **FI, IP.get());
NAKAMURA Takumid1c99b22013-05-27 00:02:48 +0000360 ++filenum;
Ahmed Bougachaef993562013-05-24 01:07:04 +0000361 }
362 }
363
364
Michael J. Spencer25b15772011-06-25 17:55:23 +0000365 error_code ec;
Michael J. Spencer4344b1e2011-10-07 19:25:32 +0000366 for (section_iterator i = Obj->begin_sections(),
Michael J. Spencer27781b72011-10-08 00:18:30 +0000367 e = Obj->end_sections();
368 i != e; i.increment(ec)) {
Michael J. Spencer25b15772011-06-25 17:55:23 +0000369 if (error(ec)) break;
370 bool text;
371 if (error(i->isText(text))) break;
372 if (!text) continue;
373
Michael J. Spencer942eb002011-10-13 22:17:18 +0000374 uint64_t SectionAddr;
375 if (error(i->getAddress(SectionAddr))) break;
376
Benjamin Kramer739b65b2011-07-15 18:39:24 +0000377 // Make a list of all the symbols in this section.
378 std::vector<std::pair<uint64_t, StringRef> > Symbols;
Michael J. Spencer4344b1e2011-10-07 19:25:32 +0000379 for (symbol_iterator si = Obj->begin_symbols(),
Michael J. Spencer27781b72011-10-08 00:18:30 +0000380 se = Obj->end_symbols();
381 si != se; si.increment(ec)) {
Benjamin Kramer739b65b2011-07-15 18:39:24 +0000382 bool contains;
383 if (!error(i->containsSymbol(*si, contains)) && contains) {
384 uint64_t Address;
Danil Malyshevb0436a72011-11-29 17:40:10 +0000385 if (error(si->getAddress(Address))) break;
Eric Christopher99ff2ba2013-04-03 18:31:23 +0000386 if (Address == UnknownAddressOrSize) continue;
Cameron Zwarichaab21912012-02-03 04:13:37 +0000387 Address -= SectionAddr;
388
Benjamin Kramer739b65b2011-07-15 18:39:24 +0000389 StringRef Name;
390 if (error(si->getName(Name))) break;
391 Symbols.push_back(std::make_pair(Address, Name));
392 }
393 }
394
395 // Sort the symbols by address, just in case they didn't come in that way.
396 array_pod_sort(Symbols.begin(), Symbols.end());
397
Michael J. Spencer942eb002011-10-13 22:17:18 +0000398 // Make a list of all the relocations for this section.
399 std::vector<RelocationRef> Rels;
400 if (InlineRelocs) {
401 for (relocation_iterator ri = i->begin_relocations(),
402 re = i->end_relocations();
Jim Grosbach3f5d1a22012-08-07 17:53:14 +0000403 ri != re; ri.increment(ec)) {
Michael J. Spencer942eb002011-10-13 22:17:18 +0000404 if (error(ec)) break;
405 Rels.push_back(*ri);
406 }
407 }
408
409 // Sort relocations by address.
410 std::sort(Rels.begin(), Rels.end(), RelocAddressLess);
411
Rafael Espindolacef81b32012-12-21 03:47:03 +0000412 StringRef SegmentName = "";
Rafael Espindolafd7aa382013-04-18 18:08:55 +0000413 if (const MachOObjectFile *MachO =
414 dyn_cast<const MachOObjectFile>(Obj)) {
Rafael Espindolacef81b32012-12-21 03:47:03 +0000415 DataRefImpl DR = i->getRawDataRefImpl();
Rafael Espindolafd7aa382013-04-18 18:08:55 +0000416 SegmentName = MachO->getSectionFinalSegmentName(DR);
Rafael Espindolacef81b32012-12-21 03:47:03 +0000417 }
Michael J. Spencer25b15772011-06-25 17:55:23 +0000418 StringRef name;
419 if (error(i->getName(name))) break;
Rafael Espindolacef81b32012-12-21 03:47:03 +0000420 outs() << "Disassembly of section ";
421 if (!SegmentName.empty())
422 outs() << SegmentName << ",";
423 outs() << name << ':';
Benjamin Kramer739b65b2011-07-15 18:39:24 +0000424
425 // If the section has no symbols just insert a dummy one and disassemble
426 // the whole section.
427 if (Symbols.empty())
428 Symbols.push_back(std::make_pair(0, name));
Michael J. Spencer92e1deb2011-01-20 06:39:06 +0000429
Ahmed Bougacha2c94d0f2013-05-24 00:39:57 +0000430
431 SmallString<40> Comments;
432 raw_svector_ostream CommentStream(Comments);
433
Michael J. Spencer25b15772011-06-25 17:55:23 +0000434 StringRef Bytes;
435 if (error(i->getContents(Bytes))) break;
Ahmed Bougacha2c94d0f2013-05-24 00:39:57 +0000436 StringRefMemoryObject memoryObject(Bytes, SectionAddr);
Michael J. Spencer92e1deb2011-01-20 06:39:06 +0000437 uint64_t Size;
438 uint64_t Index;
Benjamin Kramer739b65b2011-07-15 18:39:24 +0000439 uint64_t SectSize;
440 if (error(i->getSize(SectSize))) break;
Michael J. Spencer92e1deb2011-01-20 06:39:06 +0000441
Michael J. Spencer942eb002011-10-13 22:17:18 +0000442 std::vector<RelocationRef>::const_iterator rel_cur = Rels.begin();
443 std::vector<RelocationRef>::const_iterator rel_end = Rels.end();
Benjamin Kramer739b65b2011-07-15 18:39:24 +0000444 // Disassemble symbol by symbol.
445 for (unsigned si = 0, se = Symbols.size(); si != se; ++si) {
446 uint64_t Start = Symbols[si].first;
Michael J. Spencer178dbd42011-10-13 20:37:08 +0000447 uint64_t End;
448 // The end is either the size of the section or the beginning of the next
449 // symbol.
450 if (si == se - 1)
451 End = SectSize;
452 // Make sure this symbol takes up space.
453 else if (Symbols[si + 1].first != Start)
454 End = Symbols[si + 1].first - 1;
455 else
456 // This symbol has the same address as the next symbol. Skip it.
457 continue;
458
Benjamin Kramer739b65b2011-07-15 18:39:24 +0000459 outs() << '\n' << Symbols[si].second << ":\n";
Michael J. Spencer92e1deb2011-01-20 06:39:06 +0000460
Benjamin Kramer739b65b2011-07-15 18:39:24 +0000461#ifndef NDEBUG
462 raw_ostream &DebugOut = DebugFlag ? dbgs() : nulls();
463#else
464 raw_ostream &DebugOut = nulls();
465#endif
466
Benjamin Kramer0b8b7712011-09-19 17:56:04 +0000467 for (Index = Start; Index < End; Index += Size) {
468 MCInst Inst;
Owen Anderson98c5dda2011-09-15 23:38:46 +0000469
Ahmed Bougacha2c94d0f2013-05-24 00:39:57 +0000470 if (DisAsm->getInstruction(Inst, Size, memoryObject,
471 SectionAddr + Index,
472 DebugOut, CommentStream)) {
Eli Bendersky8b9da532012-11-20 22:57:02 +0000473 outs() << format("%8" PRIx64 ":", SectionAddr + Index);
474 if (!NoShowRawInsn) {
475 outs() << "\t";
476 DumpBytes(StringRef(Bytes.data() + Index, Size));
477 }
Benjamin Kramer0b8b7712011-09-19 17:56:04 +0000478 IP->printInst(&Inst, outs(), "");
Ahmed Bougacha2c94d0f2013-05-24 00:39:57 +0000479 outs() << CommentStream.str();
480 Comments.clear();
Benjamin Kramer0b8b7712011-09-19 17:56:04 +0000481 outs() << "\n";
482 } else {
483 errs() << ToolName << ": warning: invalid instruction encoding\n";
484 if (Size == 0)
485 Size = 1; // skip illegible bytes
Benjamin Kramer739b65b2011-07-15 18:39:24 +0000486 }
Michael J. Spencer942eb002011-10-13 22:17:18 +0000487
488 // Print relocation for instruction.
489 while (rel_cur != rel_end) {
Owen Anderson0685e942011-10-25 20:35:53 +0000490 bool hidden = false;
Michael J. Spencer942eb002011-10-13 22:17:18 +0000491 uint64_t addr;
492 SmallString<16> name;
493 SmallString<32> val;
Owen Anderson0685e942011-10-25 20:35:53 +0000494
495 // If this relocation is hidden, skip it.
496 if (error(rel_cur->getHidden(hidden))) goto skip_print_rel;
497 if (hidden) goto skip_print_rel;
498
Rafael Espindola956ca722013-04-25 12:28:45 +0000499 if (error(rel_cur->getOffset(addr))) goto skip_print_rel;
Michael J. Spencer942eb002011-10-13 22:17:18 +0000500 // Stop when rel_cur's address is past the current instruction.
Owen Anderson34749ce2011-10-25 20:15:39 +0000501 if (addr >= Index + Size) break;
Michael J. Spencer942eb002011-10-13 22:17:18 +0000502 if (error(rel_cur->getTypeName(name))) goto skip_print_rel;
503 if (error(rel_cur->getValueString(val))) goto skip_print_rel;
504
Benjamin Kramer51cf8662012-03-10 02:04:38 +0000505 outs() << format("\t\t\t%8" PRIx64 ": ", SectionAddr + addr) << name
506 << "\t" << val << "\n";
Michael J. Spencer942eb002011-10-13 22:17:18 +0000507
508 skip_print_rel:
509 ++rel_cur;
510 }
Benjamin Kramer685a2502011-07-20 19:37:35 +0000511 }
Michael J. Spencer92e1deb2011-01-20 06:39:06 +0000512 }
513 }
514}
515
Michael J. Spencer27781b72011-10-08 00:18:30 +0000516static void PrintRelocations(const ObjectFile *o) {
517 error_code ec;
518 for (section_iterator si = o->begin_sections(), se = o->end_sections();
519 si != se; si.increment(ec)){
520 if (error(ec)) return;
521 if (si->begin_relocations() == si->end_relocations())
522 continue;
523 StringRef secname;
524 if (error(si->getName(secname))) continue;
525 outs() << "RELOCATION RECORDS FOR [" << secname << "]:\n";
526 for (relocation_iterator ri = si->begin_relocations(),
527 re = si->end_relocations();
528 ri != re; ri.increment(ec)) {
529 if (error(ec)) return;
530
Owen Anderson0685e942011-10-25 20:35:53 +0000531 bool hidden;
Michael J. Spencer27781b72011-10-08 00:18:30 +0000532 uint64_t address;
533 SmallString<32> relocname;
534 SmallString<32> valuestr;
Owen Anderson0685e942011-10-25 20:35:53 +0000535 if (error(ri->getHidden(hidden))) continue;
536 if (hidden) continue;
Michael J. Spencer27781b72011-10-08 00:18:30 +0000537 if (error(ri->getTypeName(relocname))) continue;
Rafael Espindola956ca722013-04-25 12:28:45 +0000538 if (error(ri->getOffset(address))) continue;
Michael J. Spencer27781b72011-10-08 00:18:30 +0000539 if (error(ri->getValueString(valuestr))) continue;
540 outs() << address << " " << relocname << " " << valuestr << "\n";
541 }
542 outs() << "\n";
543 }
544}
545
Nick Lewycky023bb152011-10-10 21:21:34 +0000546static void PrintSectionHeaders(const ObjectFile *o) {
547 outs() << "Sections:\n"
548 "Idx Name Size Address Type\n";
549 error_code ec;
550 unsigned i = 0;
551 for (section_iterator si = o->begin_sections(), se = o->end_sections();
552 si != se; si.increment(ec)) {
553 if (error(ec)) return;
554 StringRef Name;
555 if (error(si->getName(Name))) return;
556 uint64_t Address;
557 if (error(si->getAddress(Address))) return;
558 uint64_t Size;
559 if (error(si->getSize(Size))) return;
560 bool Text, Data, BSS;
561 if (error(si->isText(Text))) return;
562 if (error(si->isData(Data))) return;
563 if (error(si->isBSS(BSS))) return;
564 std::string Type = (std::string(Text ? "TEXT " : "") +
Michael J. Spencer14a5f462011-10-13 20:37:20 +0000565 (Data ? "DATA " : "") + (BSS ? "BSS" : ""));
Michael J. Spencer27b2b1b2013-01-10 22:40:50 +0000566 outs() << format("%3d %-13s %08" PRIx64 " %016" PRIx64 " %s\n",
Benjamin Kramer51cf8662012-03-10 02:04:38 +0000567 i, Name.str().c_str(), Size, Address, Type.c_str());
Nick Lewycky023bb152011-10-10 21:21:34 +0000568 ++i;
569 }
570}
571
Michael J. Spencer1e8ba3f2011-10-17 17:13:22 +0000572static void PrintSectionContents(const ObjectFile *o) {
573 error_code ec;
574 for (section_iterator si = o->begin_sections(),
575 se = o->end_sections();
576 si != se; si.increment(ec)) {
577 if (error(ec)) return;
578 StringRef Name;
579 StringRef Contents;
580 uint64_t BaseAddr;
Alexey Samsonov0eaa6f62013-04-16 10:53:11 +0000581 bool BSS;
Michael J. Spencer1e8ba3f2011-10-17 17:13:22 +0000582 if (error(si->getName(Name))) continue;
583 if (error(si->getContents(Contents))) continue;
584 if (error(si->getAddress(BaseAddr))) continue;
Alexey Samsonov0eaa6f62013-04-16 10:53:11 +0000585 if (error(si->isBSS(BSS))) continue;
Michael J. Spencer1e8ba3f2011-10-17 17:13:22 +0000586
587 outs() << "Contents of section " << Name << ":\n";
Alexey Samsonov0eaa6f62013-04-16 10:53:11 +0000588 if (BSS) {
589 outs() << format("<skipping contents of bss section at [%04" PRIx64
590 ", %04" PRIx64 ")>\n", BaseAddr,
591 BaseAddr + Contents.size());
592 continue;
593 }
Michael J. Spencer1e8ba3f2011-10-17 17:13:22 +0000594
595 // Dump out the content as hex and printable ascii characters.
596 for (std::size_t addr = 0, end = Contents.size(); addr < end; addr += 16) {
Benjamin Kramer51cf8662012-03-10 02:04:38 +0000597 outs() << format(" %04" PRIx64 " ", BaseAddr + addr);
Michael J. Spencer1e8ba3f2011-10-17 17:13:22 +0000598 // Dump line of hex.
599 for (std::size_t i = 0; i < 16; ++i) {
600 if (i != 0 && i % 4 == 0)
601 outs() << ' ';
602 if (addr + i < end)
603 outs() << hexdigit((Contents[addr + i] >> 4) & 0xF, true)
604 << hexdigit(Contents[addr + i] & 0xF, true);
605 else
606 outs() << " ";
607 }
608 // Print ascii.
609 outs() << " ";
610 for (std::size_t i = 0; i < 16 && addr + i < end; ++i) {
Guy Benyei87d0b9e2013-02-12 21:21:59 +0000611 if (std::isprint(static_cast<unsigned char>(Contents[addr + i]) & 0xFF))
Michael J. Spencer1e8ba3f2011-10-17 17:13:22 +0000612 outs() << Contents[addr + i];
613 else
614 outs() << ".";
615 }
616 outs() << "\n";
617 }
618 }
619}
620
Michael J. Spencer22ff0f32011-10-18 19:32:17 +0000621static void PrintCOFFSymbolTable(const COFFObjectFile *coff) {
622 const coff_file_header *header;
623 if (error(coff->getHeader(header))) return;
624 int aux_count = 0;
625 const coff_symbol *symbol = 0;
626 for (int i = 0, e = header->NumberOfSymbols; i != e; ++i) {
627 if (aux_count--) {
628 // Figure out which type of aux this is.
629 if (symbol->StorageClass == COFF::IMAGE_SYM_CLASS_STATIC
630 && symbol->Value == 0) { // Section definition.
631 const coff_aux_section_definition *asd;
632 if (error(coff->getAuxSymbol<coff_aux_section_definition>(i, asd)))
633 return;
634 outs() << "AUX "
635 << format("scnlen 0x%x nreloc %d nlnno %d checksum 0x%x "
636 , unsigned(asd->Length)
637 , unsigned(asd->NumberOfRelocations)
638 , unsigned(asd->NumberOfLinenumbers)
639 , unsigned(asd->CheckSum))
640 << format("assoc %d comdat %d\n"
641 , unsigned(asd->Number)
642 , unsigned(asd->Selection));
Jim Grosbach3f5d1a22012-08-07 17:53:14 +0000643 } else
Michael J. Spencer22ff0f32011-10-18 19:32:17 +0000644 outs() << "AUX Unknown\n";
Michael J. Spencer22ff0f32011-10-18 19:32:17 +0000645 } else {
646 StringRef name;
647 if (error(coff->getSymbol(i, symbol))) return;
648 if (error(coff->getSymbolName(symbol, name))) return;
649 outs() << "[" << format("%2d", i) << "]"
650 << "(sec " << format("%2d", int(symbol->SectionNumber)) << ")"
651 << "(fl 0x00)" // Flag bits, which COFF doesn't have.
652 << "(ty " << format("%3x", unsigned(symbol->Type)) << ")"
653 << "(scl " << format("%3x", unsigned(symbol->StorageClass)) << ") "
654 << "(nx " << unsigned(symbol->NumberOfAuxSymbols) << ") "
655 << "0x" << format("%08x", unsigned(symbol->Value)) << " "
656 << name << "\n";
657 aux_count = symbol->NumberOfAuxSymbols;
658 }
659 }
660}
661
662static void PrintSymbolTable(const ObjectFile *o) {
663 outs() << "SYMBOL TABLE:\n";
664
665 if (const COFFObjectFile *coff = dyn_cast<const COFFObjectFile>(o))
666 PrintCOFFSymbolTable(coff);
667 else {
668 error_code ec;
669 for (symbol_iterator si = o->begin_symbols(),
670 se = o->end_symbols(); si != se; si.increment(ec)) {
671 if (error(ec)) return;
672 StringRef Name;
Danil Malyshevb0436a72011-11-29 17:40:10 +0000673 uint64_t Address;
Michael J. Spencer22ff0f32011-10-18 19:32:17 +0000674 SymbolRef::Type Type;
Michael J. Spencer22ff0f32011-10-18 19:32:17 +0000675 uint64_t Size;
David Meyerc46255a2012-02-28 23:47:53 +0000676 uint32_t Flags;
Michael J. Spencer22ff0f32011-10-18 19:32:17 +0000677 section_iterator Section = o->end_sections();
678 if (error(si->getName(Name))) continue;
Danil Malyshevb0436a72011-11-29 17:40:10 +0000679 if (error(si->getAddress(Address))) continue;
David Meyerc46255a2012-02-28 23:47:53 +0000680 if (error(si->getFlags(Flags))) continue;
Michael J. Spencer22ff0f32011-10-18 19:32:17 +0000681 if (error(si->getType(Type))) continue;
Michael J. Spencer22ff0f32011-10-18 19:32:17 +0000682 if (error(si->getSize(Size))) continue;
683 if (error(si->getSection(Section))) continue;
684
David Meyerc46255a2012-02-28 23:47:53 +0000685 bool Global = Flags & SymbolRef::SF_Global;
686 bool Weak = Flags & SymbolRef::SF_Weak;
687 bool Absolute = Flags & SymbolRef::SF_Absolute;
688
Danil Malyshevb0436a72011-11-29 17:40:10 +0000689 if (Address == UnknownAddressOrSize)
690 Address = 0;
691 if (Size == UnknownAddressOrSize)
692 Size = 0;
Michael J. Spencer22ff0f32011-10-18 19:32:17 +0000693 char GlobLoc = ' ';
David Meyer2c677272012-02-29 02:11:55 +0000694 if (Type != SymbolRef::ST_Unknown)
Michael J. Spencer22ff0f32011-10-18 19:32:17 +0000695 GlobLoc = Global ? 'g' : 'l';
696 char Debug = (Type == SymbolRef::ST_Debug || Type == SymbolRef::ST_File)
697 ? 'd' : ' ';
698 char FileFunc = ' ';
699 if (Type == SymbolRef::ST_File)
700 FileFunc = 'f';
701 else if (Type == SymbolRef::ST_Function)
702 FileFunc = 'F';
703
Michael J. Spencer27b2b1b2013-01-10 22:40:50 +0000704 const char *Fmt = o->getBytesInAddress() > 4 ? "%016" PRIx64 :
705 "%08" PRIx64;
706
707 outs() << format(Fmt, Address) << " "
Michael J. Spencer22ff0f32011-10-18 19:32:17 +0000708 << GlobLoc // Local -> 'l', Global -> 'g', Neither -> ' '
709 << (Weak ? 'w' : ' ') // Weak?
710 << ' ' // Constructor. Not supported yet.
711 << ' ' // Warning. Not supported yet.
712 << ' ' // Indirect reference to another symbol.
713 << Debug // Debugging (d) or dynamic (D) symbol.
714 << FileFunc // Name of function (F), file (f) or object (O).
715 << ' ';
716 if (Absolute)
717 outs() << "*ABS*";
718 else if (Section == o->end_sections())
719 outs() << "*UND*";
720 else {
Rafael Espindolafd7aa382013-04-18 18:08:55 +0000721 if (const MachOObjectFile *MachO =
722 dyn_cast<const MachOObjectFile>(o)) {
Rafael Espindolacef81b32012-12-21 03:47:03 +0000723 DataRefImpl DR = Section->getRawDataRefImpl();
Rafael Espindolafd7aa382013-04-18 18:08:55 +0000724 StringRef SegmentName = MachO->getSectionFinalSegmentName(DR);
Rafael Espindolacef81b32012-12-21 03:47:03 +0000725 outs() << SegmentName << ",";
726 }
Michael J. Spencer22ff0f32011-10-18 19:32:17 +0000727 StringRef SectionName;
728 if (error(Section->getName(SectionName)))
729 SectionName = "";
730 outs() << SectionName;
731 }
732 outs() << '\t'
Benjamin Kramer51cf8662012-03-10 02:04:38 +0000733 << format("%08" PRIx64 " ", Size)
Michael J. Spencer22ff0f32011-10-18 19:32:17 +0000734 << Name
735 << '\n';
736 }
737 }
738}
739
Michael J. Spencereef7b622012-12-05 20:12:35 +0000740static void PrintUnwindInfo(const ObjectFile *o) {
741 outs() << "Unwind info:\n\n";
742
743 if (const COFFObjectFile *coff = dyn_cast<COFFObjectFile>(o)) {
744 printCOFFUnwindInfo(coff);
745 } else {
746 // TODO: Extract DWARF dump tool to objdump.
747 errs() << "This operation is only currently supported "
748 "for COFF object files.\n";
749 return;
750 }
751}
752
Michael J. Spencer27781b72011-10-08 00:18:30 +0000753static void DumpObject(const ObjectFile *o) {
Michael J. Spencer1e8ba3f2011-10-17 17:13:22 +0000754 outs() << '\n';
755 outs() << o->getFileName()
756 << ":\tfile format " << o->getFileFormatName() << "\n\n";
757
Michael J. Spencer27781b72011-10-08 00:18:30 +0000758 if (Disassemble)
Michael J. Spencer942eb002011-10-13 22:17:18 +0000759 DisassembleObject(o, Relocations);
760 if (Relocations && !Disassemble)
Michael J. Spencer27781b72011-10-08 00:18:30 +0000761 PrintRelocations(o);
Nick Lewycky023bb152011-10-10 21:21:34 +0000762 if (SectionHeaders)
763 PrintSectionHeaders(o);
Michael J. Spencer1e8ba3f2011-10-17 17:13:22 +0000764 if (SectionContents)
765 PrintSectionContents(o);
Michael J. Spencer22ff0f32011-10-18 19:32:17 +0000766 if (SymbolTable)
767 PrintSymbolTable(o);
Michael J. Spencereef7b622012-12-05 20:12:35 +0000768 if (UnwindInfo)
769 PrintUnwindInfo(o);
Michael J. Spencerb2c064c2013-01-06 03:56:49 +0000770 if (PrivateHeaders && o->isELF())
771 printELFFileHeader(o);
Michael J. Spencer27781b72011-10-08 00:18:30 +0000772}
773
774/// @brief Dump each object file in \a a;
775static void DumpArchive(const Archive *a) {
776 for (Archive::child_iterator i = a->begin_children(),
777 e = a->end_children(); i != e; ++i) {
778 OwningPtr<Binary> child;
779 if (error_code ec = i->getAsBinary(child)) {
Michael J. Spencerf81285c2011-11-16 01:24:41 +0000780 // Ignore non-object files.
781 if (ec != object_error::invalid_file_type)
782 errs() << ToolName << ": '" << a->getFileName() << "': " << ec.message()
783 << ".\n";
Michael J. Spencer27781b72011-10-08 00:18:30 +0000784 continue;
785 }
786 if (ObjectFile *o = dyn_cast<ObjectFile>(child.get()))
787 DumpObject(o);
788 else
789 errs() << ToolName << ": '" << a->getFileName() << "': "
790 << "Unrecognized file type.\n";
791 }
792}
793
794/// @brief Open file and figure out how to dump it.
795static void DumpInput(StringRef file) {
796 // If file isn't stdin, check that it exists.
797 if (file != "-" && !sys::fs::exists(file)) {
798 errs() << ToolName << ": '" << file << "': " << "No such file\n";
799 return;
800 }
801
Rafael Espindolacef81b32012-12-21 03:47:03 +0000802 if (MachOOpt && Disassemble) {
Michael J. Spencer27781b72011-10-08 00:18:30 +0000803 DisassembleInputMachO(file);
804 return;
805 }
806
807 // Attempt to open the binary.
808 OwningPtr<Binary> binary;
809 if (error_code ec = createBinary(file, binary)) {
810 errs() << ToolName << ": '" << file << "': " << ec.message() << ".\n";
811 return;
812 }
813
Jim Grosbach3f5d1a22012-08-07 17:53:14 +0000814 if (Archive *a = dyn_cast<Archive>(binary.get()))
Michael J. Spencer27781b72011-10-08 00:18:30 +0000815 DumpArchive(a);
Jim Grosbach3f5d1a22012-08-07 17:53:14 +0000816 else if (ObjectFile *o = dyn_cast<ObjectFile>(binary.get()))
Michael J. Spencer27781b72011-10-08 00:18:30 +0000817 DumpObject(o);
Jim Grosbach3f5d1a22012-08-07 17:53:14 +0000818 else
Michael J. Spencer27781b72011-10-08 00:18:30 +0000819 errs() << ToolName << ": '" << file << "': " << "Unrecognized file type.\n";
Michael J. Spencer27781b72011-10-08 00:18:30 +0000820}
821
Michael J. Spencer92e1deb2011-01-20 06:39:06 +0000822int main(int argc, char **argv) {
823 // Print a stack trace if we signal out.
824 sys::PrintStackTraceOnErrorSignal();
825 PrettyStackTraceProgram X(argc, argv);
826 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
827
828 // Initialize targets and assembly printers/parsers.
829 llvm::InitializeAllTargetInfos();
Evan Chenge78085a2011-07-22 21:58:54 +0000830 llvm::InitializeAllTargetMCs();
Michael J. Spencer92e1deb2011-01-20 06:39:06 +0000831 llvm::InitializeAllAsmParsers();
832 llvm::InitializeAllDisassemblers();
833
Pete Cooperff204962012-05-03 23:20:10 +0000834 // Register the target printer for --version.
835 cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion);
836
Michael J. Spencer92e1deb2011-01-20 06:39:06 +0000837 cl::ParseCommandLineOptions(argc, argv, "llvm object file dumper\n");
838 TripleName = Triple::normalize(TripleName);
839
840 ToolName = argv[0];
841
842 // Defaults to a.out if no filenames specified.
843 if (InputFilenames.size() == 0)
844 InputFilenames.push_back("a.out");
845
Michael J. Spencer22ff0f32011-10-18 19:32:17 +0000846 if (!Disassemble
847 && !Relocations
848 && !SectionHeaders
849 && !SectionContents
Michael J. Spencereef7b622012-12-05 20:12:35 +0000850 && !SymbolTable
Michael J. Spencerb2c064c2013-01-06 03:56:49 +0000851 && !UnwindInfo
852 && !PrivateHeaders) {
Michael J. Spencer92e1deb2011-01-20 06:39:06 +0000853 cl::PrintHelpMessage();
854 return 2;
855 }
856
Michael J. Spencer27781b72011-10-08 00:18:30 +0000857 std::for_each(InputFilenames.begin(), InputFilenames.end(),
858 DumpInput);
Michael J. Spencer92e1deb2011-01-20 06:39:06 +0000859
860 return 0;
861}