blob: e9f96cbd87253ad463bdaf6af561572f83e845dc [file] [log] [blame]
Michael J. Spencer2670c252011-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. Spencerd7e70032013-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. Spencer2670c252011-01-20 06:39:06 +000017//===----------------------------------------------------------------------===//
18
Benjamin Kramer43a772e2011-09-19 17:56:04 +000019#include "llvm-objdump.h"
Sanjoy Das6f567a42015-06-22 18:03:02 +000020#include "llvm/ADT/Optional.h"
Chandler Carruth4d88a1c2012-12-04 10:44:52 +000021#include "llvm/ADT/STLExtras.h"
Michael J. Spencer4e25c022011-10-17 17:13:22 +000022#include "llvm/ADT/StringExtras.h"
Michael J. Spencer2670c252011-01-20 06:39:06 +000023#include "llvm/ADT/Triple.h"
Sanjoy Das3f1bc3b2015-06-23 20:09:03 +000024#include "llvm/CodeGen/FaultMaps.h"
Michael J. Spencer2670c252011-01-20 06:39:06 +000025#include "llvm/MC/MCAsmInfo.h"
Ahmed Bougachaad1084d2013-05-24 00:39:57 +000026#include "llvm/MC/MCContext.h"
Michael J. Spencer2670c252011-01-20 06:39:06 +000027#include "llvm/MC/MCDisassembler.h"
28#include "llvm/MC/MCInst.h"
29#include "llvm/MC/MCInstPrinter.h"
Ahmed Bougachaaa790682013-05-24 01:07:04 +000030#include "llvm/MC/MCInstrAnalysis.h"
Craig Topper54bfde72012-04-02 06:09:36 +000031#include "llvm/MC/MCInstrInfo.h"
Ahmed Bougachaad1084d2013-05-24 00:39:57 +000032#include "llvm/MC/MCObjectFileInfo.h"
Jim Grosbachfd93a592012-03-05 19:33:20 +000033#include "llvm/MC/MCRegisterInfo.h"
Ahmed Bougachaad1084d2013-05-24 00:39:57 +000034#include "llvm/MC/MCRelocationInfo.h"
Ahmed Bougachaaa790682013-05-24 01:07:04 +000035#include "llvm/MC/MCSubtargetInfo.h"
Chandler Carruth4d88a1c2012-12-04 10:44:52 +000036#include "llvm/Object/Archive.h"
Rafael Espindola37070a52015-06-03 04:48:06 +000037#include "llvm/Object/ELFObjectFile.h"
Chandler Carruth4d88a1c2012-12-04 10:44:52 +000038#include "llvm/Object/COFF.h"
Rafael Espindolaa9f810b2012-12-21 03:47:03 +000039#include "llvm/Object/MachO.h"
Chandler Carruth4d88a1c2012-12-04 10:44:52 +000040#include "llvm/Object/ObjectFile.h"
Michael J. Spencerba4a3622011-10-08 00:18:30 +000041#include "llvm/Support/Casting.h"
Michael J. Spencer2670c252011-01-20 06:39:06 +000042#include "llvm/Support/CommandLine.h"
43#include "llvm/Support/Debug.h"
Alexey Samsonov50d0fbd2015-06-04 18:34:11 +000044#include "llvm/Support/Errc.h"
Michael J. Spencerba4a3622011-10-08 00:18:30 +000045#include "llvm/Support/FileSystem.h"
Michael J. Spencer2670c252011-01-20 06:39:06 +000046#include "llvm/Support/Format.h"
Benjamin Kramerbf115312011-07-25 23:04:36 +000047#include "llvm/Support/GraphWriter.h"
Michael J. Spencer2670c252011-01-20 06:39:06 +000048#include "llvm/Support/Host.h"
49#include "llvm/Support/ManagedStatic.h"
50#include "llvm/Support/MemoryBuffer.h"
Michael J. Spencer2670c252011-01-20 06:39:06 +000051#include "llvm/Support/PrettyStackTrace.h"
52#include "llvm/Support/Signals.h"
53#include "llvm/Support/SourceMgr.h"
Evan Cheng2bb40352011-08-24 18:08:43 +000054#include "llvm/Support/TargetRegistry.h"
55#include "llvm/Support/TargetSelect.h"
Michael J. Spencer2670c252011-01-20 06:39:06 +000056#include "llvm/Support/raw_ostream.h"
Michael J. Spencer2670c252011-01-20 06:39:06 +000057#include <algorithm>
Benjamin Kramera5177e62012-03-23 11:49:32 +000058#include <cctype>
Michael J. Spencer2670c252011-01-20 06:39:06 +000059#include <cstring>
Rafael Espindolaa6e9c3e2014-06-12 17:38:55 +000060#include <system_error>
Ahmed Bougacha17926472013-08-21 07:29:02 +000061
Michael J. Spencer2670c252011-01-20 06:39:06 +000062using namespace llvm;
63using namespace object;
64
Benjamin Kramer43a772e2011-09-19 17:56:04 +000065static cl::list<std::string>
66InputFilenames(cl::Positional, cl::desc("<input object files>"),cl::ZeroOrMore);
Michael J. Spencer2670c252011-01-20 06:39:06 +000067
Kevin Enderbye2297dd2015-01-07 21:02:18 +000068cl::opt<bool>
69llvm::Disassemble("disassemble",
Benjamin Kramer43a772e2011-09-19 17:56:04 +000070 cl::desc("Display assembler mnemonics for the machine instructions"));
71static cl::alias
72Disassembled("d", cl::desc("Alias for --disassemble"),
Colin LeMahieu77804be2015-07-29 15:45:39 +000073 cl::aliasopt(Disassemble));
74
75cl::opt<bool>
76llvm::DisassembleAll("disassemble-all",
77 cl::desc("Display assembler mnemonics for the machine instructions"));
78static cl::alias
79DisassembleAlld("D", cl::desc("Alias for --disassemble-all"),
Colin LeMahieuf34933e2015-07-23 20:58:49 +000080 cl::aliasopt(DisassembleAll));
Michael J. Spencer2670c252011-01-20 06:39:06 +000081
Kevin Enderby98da6132015-01-20 21:47:46 +000082cl::opt<bool>
83llvm::Relocations("r", cl::desc("Display the relocation entries in the file"));
Michael J. Spencerba4a3622011-10-08 00:18:30 +000084
Kevin Enderby98da6132015-01-20 21:47:46 +000085cl::opt<bool>
86llvm::SectionContents("s", cl::desc("Display the content of each section"));
Michael J. Spencer4e25c022011-10-17 17:13:22 +000087
Kevin Enderby98da6132015-01-20 21:47:46 +000088cl::opt<bool>
89llvm::SymbolTable("t", cl::desc("Display the symbol table"));
Michael J. Spencerbfa06782011-10-18 19:32:17 +000090
Kevin Enderbye2297dd2015-01-07 21:02:18 +000091cl::opt<bool>
92llvm::ExportsTrie("exports-trie", cl::desc("Display mach-o exported symbols"));
Nick Kledzikd04bc352014-08-30 00:20:14 +000093
Kevin Enderbye2297dd2015-01-07 21:02:18 +000094cl::opt<bool>
95llvm::Rebase("rebase", cl::desc("Display mach-o rebasing info"));
Nick Kledzikac431442014-09-12 21:34:15 +000096
Kevin Enderbye2297dd2015-01-07 21:02:18 +000097cl::opt<bool>
98llvm::Bind("bind", cl::desc("Display mach-o binding info"));
Nick Kledzik56ebef42014-09-16 01:41:51 +000099
Kevin Enderbye2297dd2015-01-07 21:02:18 +0000100cl::opt<bool>
101llvm::LazyBind("lazy-bind", cl::desc("Display mach-o lazy binding info"));
Nick Kledzik56ebef42014-09-16 01:41:51 +0000102
Kevin Enderbye2297dd2015-01-07 21:02:18 +0000103cl::opt<bool>
104llvm::WeakBind("weak-bind", cl::desc("Display mach-o weak binding info"));
Nick Kledzik56ebef42014-09-16 01:41:51 +0000105
Adrian Prantl437105a2015-07-08 02:04:15 +0000106cl::opt<bool>
107llvm::RawClangAST("raw-clang-ast",
108 cl::desc("Dump the raw binary contents of the clang AST section"));
109
Nick Kledzik56ebef42014-09-16 01:41:51 +0000110static cl::opt<bool>
Rafael Espindolaa9f810b2012-12-21 03:47:03 +0000111MachOOpt("macho", cl::desc("Use MachO specific object file parser"));
Benjamin Kramer43a772e2011-09-19 17:56:04 +0000112static cl::alias
Rafael Espindolaa9f810b2012-12-21 03:47:03 +0000113MachOm("m", cl::desc("Alias for --macho"), cl::aliasopt(MachOOpt));
Benjamin Kramer87ee76c2011-07-20 19:37:35 +0000114
Benjamin Kramer43a772e2011-09-19 17:56:04 +0000115cl::opt<std::string>
116llvm::TripleName("triple", cl::desc("Target triple to disassemble for, "
117 "see -version for available targets"));
118
119cl::opt<std::string>
Kevin Enderbyc9595622014-08-06 23:24:41 +0000120llvm::MCPU("mcpu",
121 cl::desc("Target a specific cpu type (-mcpu=help for details)"),
122 cl::value_desc("cpu-name"),
123 cl::init(""));
124
125cl::opt<std::string>
Kevin Enderbyef3ad2f2014-12-04 23:56:27 +0000126llvm::ArchName("arch-name", cl::desc("Target arch to disassemble for, "
Michael J. Spencer2670c252011-01-20 06:39:06 +0000127 "see -version for available targets"));
128
Kevin Enderby98da6132015-01-20 21:47:46 +0000129cl::opt<bool>
130llvm::SectionHeaders("section-headers", cl::desc("Display summaries of the "
131 "headers for each section."));
Nick Lewyckyfcf84622011-10-10 21:21:34 +0000132static cl::alias
133SectionHeadersShort("headers", cl::desc("Alias for --section-headers"),
134 cl::aliasopt(SectionHeaders));
135static cl::alias
136SectionHeadersShorter("h", cl::desc("Alias for --section-headers"),
137 cl::aliasopt(SectionHeaders));
Colin LeMahieufcc32762015-07-29 19:08:10 +0000138
Colin LeMahieu77804be2015-07-29 15:45:39 +0000139cl::list<std::string>
Colin LeMahieufcc32762015-07-29 19:08:10 +0000140llvm::FilterSections("section", cl::desc("Operate on the specified sections only. "
141 "With -macho dump segment,section"));
142cl::alias
143static FilterSectionsj("j", cl::desc("Alias for --section"),
144 cl::aliasopt(llvm::FilterSections));
Nick Lewyckyfcf84622011-10-10 21:21:34 +0000145
Kevin Enderbyc9595622014-08-06 23:24:41 +0000146cl::list<std::string>
147llvm::MAttrs("mattr",
Jack Carter551efd72012-08-28 19:24:49 +0000148 cl::CommaSeparated,
149 cl::desc("Target specific attributes"),
150 cl::value_desc("a1,+a2,-a3,..."));
151
Kevin Enderbybf246f52014-09-24 23:08:22 +0000152cl::opt<bool>
153llvm::NoShowRawInsn("no-show-raw-insn", cl::desc("When disassembling "
154 "instructions, do not print "
155 "the instruction bytes."));
Eli Bendersky3a6808c2012-11-20 22:57:02 +0000156
Kevin Enderby98da6132015-01-20 21:47:46 +0000157cl::opt<bool>
158llvm::UnwindInfo("unwind-info", cl::desc("Display unwind information"));
Michael J. Spencer0c6ec482012-12-05 20:12:35 +0000159
160static cl::alias
161UnwindInfoShort("u", cl::desc("Alias for --unwind-info"),
162 cl::aliasopt(UnwindInfo));
163
Kevin Enderbye2297dd2015-01-07 21:02:18 +0000164cl::opt<bool>
165llvm::PrivateHeaders("private-headers",
166 cl::desc("Display format specific file headers"));
Michael J. Spencer209565db2013-01-06 03:56:49 +0000167
168static cl::alias
169PrivateHeadersShort("p", cl::desc("Alias for --private-headers"),
170 cl::aliasopt(PrivateHeaders));
171
Colin LeMahieu14ec76e2015-06-07 21:07:17 +0000172cl::opt<bool>
173 llvm::PrintImmHex("print-imm-hex",
174 cl::desc("Use hex format for immediate values"));
175
Sanjoy Das6f567a42015-06-22 18:03:02 +0000176cl::opt<bool> PrintFaultMaps("fault-map-section",
177 cl::desc("Display contents of faultmap section"));
178
Benjamin Kramer43a772e2011-09-19 17:56:04 +0000179static StringRef ToolName;
Michael J. Spencer2670c252011-01-20 06:39:06 +0000180
Colin LeMahieu77804be2015-07-29 15:45:39 +0000181namespace {
Colin LeMahieufcc32762015-07-29 19:08:10 +0000182typedef std::function<bool(llvm::object::SectionRef const &)> FilterPredicate;
Colin LeMahieu77804be2015-07-29 15:45:39 +0000183
184class SectionFilterIterator {
185public:
186 SectionFilterIterator(FilterPredicate P,
187 llvm::object::section_iterator const &I,
188 llvm::object::section_iterator const &E)
189 : Predicate(P), Iterator(I), End(E) {
190 ScanPredicate();
191 }
Benjamin Kramerac9257b2015-09-24 14:52:52 +0000192 const llvm::object::SectionRef &operator*() const { return *Iterator; }
Colin LeMahieu77804be2015-07-29 15:45:39 +0000193 SectionFilterIterator &operator++() {
194 ++Iterator;
195 ScanPredicate();
196 return *this;
197 }
198 bool operator!=(SectionFilterIterator const &Other) const {
199 return Iterator != Other.Iterator;
200 }
201
202private:
203 void ScanPredicate() {
Colin LeMahieuda1723f2015-07-29 19:21:13 +0000204 while (Iterator != End && !Predicate(*Iterator)) {
Colin LeMahieu77804be2015-07-29 15:45:39 +0000205 ++Iterator;
206 }
207 }
208 FilterPredicate Predicate;
209 llvm::object::section_iterator Iterator;
210 llvm::object::section_iterator End;
211};
212
213class SectionFilter {
214public:
215 SectionFilter(FilterPredicate P, llvm::object::ObjectFile const &O)
216 : Predicate(P), Object(O) {}
217 SectionFilterIterator begin() {
218 return SectionFilterIterator(Predicate, Object.section_begin(),
219 Object.section_end());
220 }
221 SectionFilterIterator end() {
222 return SectionFilterIterator(Predicate, Object.section_end(),
223 Object.section_end());
224 }
225
226private:
227 FilterPredicate Predicate;
228 llvm::object::ObjectFile const &Object;
229};
230SectionFilter ToolSectionFilter(llvm::object::ObjectFile const &O) {
Colin LeMahieu77804be2015-07-29 15:45:39 +0000231 return SectionFilter([](llvm::object::SectionRef const &S) {
Colin LeMahieufcc32762015-07-29 19:08:10 +0000232 if(FilterSections.empty())
Colin LeMahieuda1723f2015-07-29 19:21:13 +0000233 return true;
Colin LeMahieu77804be2015-07-29 15:45:39 +0000234 llvm::StringRef String;
235 std::error_code error = S.getName(String);
Colin LeMahieufcc32762015-07-29 19:08:10 +0000236 if (error)
Colin LeMahieuda1723f2015-07-29 19:21:13 +0000237 return false;
Colin LeMahieufcc32762015-07-29 19:08:10 +0000238 return std::find(FilterSections.begin(),
239 FilterSections.end(),
Colin LeMahieuda1723f2015-07-29 19:21:13 +0000240 String) != FilterSections.end();
Colin LeMahieu77804be2015-07-29 15:45:39 +0000241 },
242 O);
243}
244}
245
Davide Italianoccd53fe2015-08-05 07:18:31 +0000246void llvm::error(std::error_code EC) {
Mark Seaborneb03ac52014-01-25 00:32:01 +0000247 if (!EC)
Davide Italianoccd53fe2015-08-05 07:18:31 +0000248 return;
Michael J. Spencer1d6167f2011-06-25 17:55:23 +0000249
Mark Seaborneb03ac52014-01-25 00:32:01 +0000250 outs() << ToolName << ": error reading file: " << EC.message() << ".\n";
Benjamin Kramer43a772e2011-09-19 17:56:04 +0000251 outs().flush();
Davide Italiano7f6c3012015-08-06 00:18:52 +0000252 exit(1);
Michael J. Spencer2670c252011-01-20 06:39:06 +0000253}
254
Alexey Samsonov50d0fbd2015-06-04 18:34:11 +0000255static void report_error(StringRef File, std::error_code EC) {
256 assert(EC);
257 errs() << ToolName << ": '" << File << "': " << EC.message() << ".\n";
Davide Italianoccd53fe2015-08-05 07:18:31 +0000258 exit(1);
Alexey Samsonov50d0fbd2015-06-04 18:34:11 +0000259}
260
Craig Toppere6cb63e2014-04-25 04:24:47 +0000261static const Target *getTarget(const ObjectFile *Obj = nullptr) {
Michael J. Spencer2670c252011-01-20 06:39:06 +0000262 // Figure out the target triple.
Kevin Enderbyfe3d0052012-05-08 23:38:45 +0000263 llvm::Triple TheTriple("unknown-unknown-unknown");
Michael J. Spencer05350e6d2011-01-20 07:22:04 +0000264 if (TripleName.empty()) {
Ahmed Bougachaad1084d2013-05-24 00:39:57 +0000265 if (Obj) {
Kevin Enderbyfe3d0052012-05-08 23:38:45 +0000266 TheTriple.setArch(Triple::ArchType(Obj->getArch()));
Ahmed Bougachaad1084d2013-05-24 00:39:57 +0000267 // TheTriple defaults to ELF, and COFF doesn't have an environment:
268 // the best we can do here is indicate that it is mach-o.
269 if (Obj->isMachO())
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000270 TheTriple.setObjectFormat(Triple::MachO);
Saleem Abdulrasool98938f12014-04-17 06:17:23 +0000271
272 if (Obj->isCOFF()) {
273 const auto COFFObj = dyn_cast<COFFObjectFile>(Obj);
274 if (COFFObj->getArch() == Triple::thumb)
275 TheTriple.setTriple("thumbv7-windows");
276 }
Ahmed Bougachaad1084d2013-05-24 00:39:57 +0000277 }
Michael J. Spencer05350e6d2011-01-20 07:22:04 +0000278 } else
Kevin Enderbyfe3d0052012-05-08 23:38:45 +0000279 TheTriple.setTriple(Triple::normalize(TripleName));
Michael J. Spencer2670c252011-01-20 06:39:06 +0000280
281 // Get the target specific parser.
282 std::string Error;
Kevin Enderbyfe3d0052012-05-08 23:38:45 +0000283 const Target *TheTarget = TargetRegistry::lookupTarget(ArchName, TheTriple,
284 Error);
285 if (!TheTarget) {
286 errs() << ToolName << ": " << Error;
Craig Toppere6cb63e2014-04-25 04:24:47 +0000287 return nullptr;
Kevin Enderbyfe3d0052012-05-08 23:38:45 +0000288 }
Michael J. Spencer2670c252011-01-20 06:39:06 +0000289
Kevin Enderbyfe3d0052012-05-08 23:38:45 +0000290 // Update the triple name and return the found target.
291 TripleName = TheTriple.getTriple();
292 return TheTarget;
Michael J. Spencer2670c252011-01-20 06:39:06 +0000293}
294
Michael J. Spencer0c6ec482012-12-05 20:12:35 +0000295bool llvm::RelocAddressLess(RelocationRef a, RelocationRef b) {
Rafael Espindola704cd842015-07-06 15:47:43 +0000296 return a.getOffset() < b.getOffset();
Michael J. Spencer51862b32011-10-13 22:17:18 +0000297}
298
Colin LeMahieufb76b002015-05-28 19:07:14 +0000299namespace {
300class PrettyPrinter {
301public:
Colin LeMahieu0b5890d2015-05-28 20:59:08 +0000302 virtual ~PrettyPrinter(){}
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000303 virtual void printInst(MCInstPrinter &IP, const MCInst *MI,
Colin LeMahieufb76b002015-05-28 19:07:14 +0000304 ArrayRef<uint8_t> Bytes, uint64_t Address,
305 raw_ostream &OS, StringRef Annot,
306 MCSubtargetInfo const &STI) {
307 outs() << format("%8" PRIx64 ":", Address);
308 if (!NoShowRawInsn) {
309 outs() << "\t";
310 dumpBytes(Bytes, outs());
311 }
312 IP.printInst(MI, outs(), "", STI);
313 }
314};
315PrettyPrinter PrettyPrinterInst;
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000316class HexagonPrettyPrinter : public PrettyPrinter {
317public:
318 void printLead(ArrayRef<uint8_t> Bytes, uint64_t Address,
319 raw_ostream &OS) {
320 uint32_t opcode =
321 (Bytes[3] << 24) | (Bytes[2] << 16) | (Bytes[1] << 8) | Bytes[0];
322 OS << format("%8" PRIx64 ":", Address);
323 if (!NoShowRawInsn) {
324 OS << "\t";
325 dumpBytes(Bytes.slice(0, 4), OS);
326 OS << format("%08" PRIx32, opcode);
327 }
328 }
329 void printInst(MCInstPrinter &IP, const MCInst *MI,
330 ArrayRef<uint8_t> Bytes, uint64_t Address,
331 raw_ostream &OS, StringRef Annot,
332 MCSubtargetInfo const &STI) override {
333 std::string Buffer;
334 {
335 raw_string_ostream TempStream(Buffer);
336 IP.printInst(MI, TempStream, "", STI);
337 }
338 StringRef Contents(Buffer);
339 // Split off bundle attributes
340 auto PacketBundle = Contents.rsplit('\n');
341 // Split off first instruction from the rest
342 auto HeadTail = PacketBundle.first.split('\n');
343 auto Preamble = " { ";
344 auto Separator = "";
345 while(!HeadTail.first.empty()) {
346 OS << Separator;
347 Separator = "\n";
348 printLead(Bytes, Address, OS);
349 OS << Preamble;
350 Preamble = " ";
351 StringRef Inst;
352 auto Duplex = HeadTail.first.split('\v');
353 if(!Duplex.second.empty()){
354 OS << Duplex.first;
355 OS << "; ";
356 Inst = Duplex.second;
357 }
358 else
359 Inst = HeadTail.first;
360 OS << Inst;
361 Bytes = Bytes.slice(4);
362 Address += 4;
363 HeadTail = HeadTail.second.split('\n');
364 }
365 OS << " } " << PacketBundle.second;
366 }
367};
368HexagonPrettyPrinter HexagonPrettyPrinterInst;
Colin LeMahieu35436a22015-05-29 14:48:25 +0000369PrettyPrinter &selectPrettyPrinter(Triple const &Triple) {
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000370 switch(Triple.getArch()) {
371 default:
372 return PrettyPrinterInst;
373 case Triple::hexagon:
374 return HexagonPrettyPrinterInst;
375 }
Colin LeMahieufb76b002015-05-28 19:07:14 +0000376}
377}
378
Rafael Espindola37070a52015-06-03 04:48:06 +0000379template <class ELFT>
Rafael Espindola37070a52015-06-03 04:48:06 +0000380static std::error_code getRelocationValueString(const ELFObjectFile<ELFT> *Obj,
Rafael Espindolaa01ff222015-08-10 20:50:40 +0000381 const RelocationRef &RelRef,
Rafael Espindola37070a52015-06-03 04:48:06 +0000382 SmallVectorImpl<char> &Result) {
Rafael Espindolaa01ff222015-08-10 20:50:40 +0000383 DataRefImpl Rel = RelRef.getRawDataRefImpl();
384
Rafael Espindola37070a52015-06-03 04:48:06 +0000385 typedef typename ELFObjectFile<ELFT>::Elf_Sym Elf_Sym;
386 typedef typename ELFObjectFile<ELFT>::Elf_Shdr Elf_Shdr;
Rafael Espindola7f162ec2015-07-02 14:21:38 +0000387 typedef typename ELFObjectFile<ELFT>::Elf_Rela Elf_Rela;
388
Rafael Espindola37070a52015-06-03 04:48:06 +0000389 const ELFFile<ELFT> &EF = *Obj->getELFFile();
390
Rafael Espindola6def3042015-07-01 12:56:27 +0000391 ErrorOr<const Elf_Shdr *> SecOrErr = EF.getSection(Rel.d.a);
392 if (std::error_code EC = SecOrErr.getError())
393 return EC;
394 const Elf_Shdr *Sec = *SecOrErr;
395 ErrorOr<const Elf_Shdr *> SymTabOrErr = EF.getSection(Sec->sh_link);
396 if (std::error_code EC = SymTabOrErr.getError())
397 return EC;
398 const Elf_Shdr *SymTab = *SymTabOrErr;
Rafael Espindola719dc7c2015-06-29 12:38:31 +0000399 assert(SymTab->sh_type == ELF::SHT_SYMTAB ||
400 SymTab->sh_type == ELF::SHT_DYNSYM);
Rafael Espindola6def3042015-07-01 12:56:27 +0000401 ErrorOr<const Elf_Shdr *> StrTabSec = EF.getSection(SymTab->sh_link);
402 if (std::error_code EC = StrTabSec.getError())
403 return EC;
404 ErrorOr<StringRef> StrTabOrErr = EF.getStringTable(*StrTabSec);
Rafael Espindola6a1bfb22015-06-29 14:39:25 +0000405 if (std::error_code EC = StrTabOrErr.getError())
406 return EC;
407 StringRef StrTab = *StrTabOrErr;
Rafael Espindolaa01ff222015-08-10 20:50:40 +0000408 uint8_t type = RelRef.getType();
Rafael Espindola37070a52015-06-03 04:48:06 +0000409 StringRef res;
410 int64_t addend = 0;
Rafael Espindola6def3042015-07-01 12:56:27 +0000411 switch (Sec->sh_type) {
Rafael Espindola37070a52015-06-03 04:48:06 +0000412 default:
413 return object_error::parse_failed;
414 case ELF::SHT_REL: {
Rafael Espindola37070a52015-06-03 04:48:06 +0000415 // TODO: Read implicit addend from section data.
416 break;
417 }
418 case ELF::SHT_RELA: {
Rafael Espindola7f162ec2015-07-02 14:21:38 +0000419 const Elf_Rela *ERela = Obj->getRela(Rel);
Rafael Espindola7f162ec2015-07-02 14:21:38 +0000420 addend = ERela->r_addend;
Rafael Espindola37070a52015-06-03 04:48:06 +0000421 break;
422 }
423 }
Rafael Espindolaa01ff222015-08-10 20:50:40 +0000424 symbol_iterator SI = RelRef.getSymbol();
425 const Elf_Sym *symb = Obj->getSymbol(SI->getRawDataRefImpl());
Rafael Espindola75d5b542015-06-03 05:14:22 +0000426 StringRef Target;
Rafael Espindola75d5b542015-06-03 05:14:22 +0000427 if (symb->getType() == ELF::STT_SECTION) {
Rafael Espindolaa01ff222015-08-10 20:50:40 +0000428 ErrorOr<section_iterator> SymSI = SI->getSection();
429 if (std::error_code EC = SymSI.getError())
430 return EC;
431 const Elf_Shdr *SymSec = Obj->getSection((*SymSI)->getRawDataRefImpl());
432 ErrorOr<StringRef> SecName = EF.getSectionName(SymSec);
Rafael Espindola75d5b542015-06-03 05:14:22 +0000433 if (std::error_code EC = SecName.getError())
434 return EC;
435 Target = *SecName;
436 } else {
Rafael Espindola44c28712015-06-29 21:24:55 +0000437 ErrorOr<StringRef> SymName = symb->getName(StrTab);
Rafael Espindola75d5b542015-06-03 05:14:22 +0000438 if (!SymName)
439 return SymName.getError();
440 Target = *SymName;
441 }
Rafael Espindola37070a52015-06-03 04:48:06 +0000442 switch (EF.getHeader()->e_machine) {
443 case ELF::EM_X86_64:
444 switch (type) {
445 case ELF::R_X86_64_PC8:
446 case ELF::R_X86_64_PC16:
447 case ELF::R_X86_64_PC32: {
448 std::string fmtbuf;
449 raw_string_ostream fmt(fmtbuf);
Rafael Espindola75d5b542015-06-03 05:14:22 +0000450 fmt << Target << (addend < 0 ? "" : "+") << addend << "-P";
Rafael Espindola37070a52015-06-03 04:48:06 +0000451 fmt.flush();
452 Result.append(fmtbuf.begin(), fmtbuf.end());
453 } break;
454 case ELF::R_X86_64_8:
455 case ELF::R_X86_64_16:
456 case ELF::R_X86_64_32:
457 case ELF::R_X86_64_32S:
458 case ELF::R_X86_64_64: {
459 std::string fmtbuf;
460 raw_string_ostream fmt(fmtbuf);
Rafael Espindola75d5b542015-06-03 05:14:22 +0000461 fmt << Target << (addend < 0 ? "" : "+") << addend;
Rafael Espindola37070a52015-06-03 04:48:06 +0000462 fmt.flush();
463 Result.append(fmtbuf.begin(), fmtbuf.end());
464 } break;
465 default:
466 res = "Unknown";
467 }
468 break;
469 case ELF::EM_AARCH64: {
470 std::string fmtbuf;
471 raw_string_ostream fmt(fmtbuf);
Rafael Espindola75d5b542015-06-03 05:14:22 +0000472 fmt << Target;
Rafael Espindola37070a52015-06-03 04:48:06 +0000473 if (addend != 0)
474 fmt << (addend < 0 ? "" : "+") << addend;
475 fmt.flush();
476 Result.append(fmtbuf.begin(), fmtbuf.end());
477 break;
478 }
479 case ELF::EM_386:
480 case ELF::EM_ARM:
481 case ELF::EM_HEXAGON:
482 case ELF::EM_MIPS:
Rafael Espindola75d5b542015-06-03 05:14:22 +0000483 res = Target;
Rafael Espindola37070a52015-06-03 04:48:06 +0000484 break;
485 default:
486 res = "Unknown";
487 }
488 if (Result.empty())
489 Result.append(res.begin(), res.end());
Rui Ueyama7d099192015-06-09 15:20:42 +0000490 return std::error_code();
Rafael Espindola37070a52015-06-03 04:48:06 +0000491}
492
493static std::error_code getRelocationValueString(const ELFObjectFileBase *Obj,
Rafael Espindolaa01ff222015-08-10 20:50:40 +0000494 const RelocationRef &Rel,
Rafael Espindola37070a52015-06-03 04:48:06 +0000495 SmallVectorImpl<char> &Result) {
Rafael Espindola37070a52015-06-03 04:48:06 +0000496 if (auto *ELF32LE = dyn_cast<ELF32LEObjectFile>(Obj))
497 return getRelocationValueString(ELF32LE, Rel, Result);
498 if (auto *ELF64LE = dyn_cast<ELF64LEObjectFile>(Obj))
499 return getRelocationValueString(ELF64LE, Rel, Result);
500 if (auto *ELF32BE = dyn_cast<ELF32BEObjectFile>(Obj))
501 return getRelocationValueString(ELF32BE, Rel, Result);
502 auto *ELF64BE = cast<ELF64BEObjectFile>(Obj);
503 return getRelocationValueString(ELF64BE, Rel, Result);
504}
505
506static std::error_code getRelocationValueString(const COFFObjectFile *Obj,
507 const RelocationRef &Rel,
508 SmallVectorImpl<char> &Result) {
509 symbol_iterator SymI = Rel.getSymbol();
Rafael Espindola5d0c2ff2015-07-02 20:55:21 +0000510 ErrorOr<StringRef> SymNameOrErr = SymI->getName();
511 if (std::error_code EC = SymNameOrErr.getError())
Rafael Espindola37070a52015-06-03 04:48:06 +0000512 return EC;
Rafael Espindola5d0c2ff2015-07-02 20:55:21 +0000513 StringRef SymName = *SymNameOrErr;
Rafael Espindola37070a52015-06-03 04:48:06 +0000514 Result.append(SymName.begin(), SymName.end());
Rui Ueyama7d099192015-06-09 15:20:42 +0000515 return std::error_code();
Rafael Espindola37070a52015-06-03 04:48:06 +0000516}
517
518static void printRelocationTargetName(const MachOObjectFile *O,
519 const MachO::any_relocation_info &RE,
520 raw_string_ostream &fmt) {
521 bool IsScattered = O->isRelocationScattered(RE);
522
523 // Target of a scattered relocation is an address. In the interest of
524 // generating pretty output, scan through the symbol table looking for a
525 // symbol that aligns with that address. If we find one, print it.
526 // Otherwise, we just print the hex address of the target.
527 if (IsScattered) {
528 uint32_t Val = O->getPlainRelocationSymbolNum(RE);
529
530 for (const SymbolRef &Symbol : O->symbols()) {
531 std::error_code ec;
Rafael Espindolaed067c42015-07-03 18:19:00 +0000532 ErrorOr<uint64_t> Addr = Symbol.getAddress();
533 if ((ec = Addr.getError()))
Rafael Espindola37070a52015-06-03 04:48:06 +0000534 report_fatal_error(ec.message());
Rafael Espindolaed067c42015-07-03 18:19:00 +0000535 if (*Addr != Val)
Rafael Espindola37070a52015-06-03 04:48:06 +0000536 continue;
Rafael Espindolaed067c42015-07-03 18:19:00 +0000537 ErrorOr<StringRef> Name = Symbol.getName();
Rafael Espindola5d0c2ff2015-07-02 20:55:21 +0000538 if (std::error_code EC = Name.getError())
539 report_fatal_error(EC.message());
540 fmt << *Name;
Rafael Espindola37070a52015-06-03 04:48:06 +0000541 return;
542 }
543
544 // If we couldn't find a symbol that this relocation refers to, try
545 // to find a section beginning instead.
Colin LeMahieu77804be2015-07-29 15:45:39 +0000546 for (const SectionRef &Section : ToolSectionFilter(*O)) {
Rafael Espindola37070a52015-06-03 04:48:06 +0000547 std::error_code ec;
548
549 StringRef Name;
550 uint64_t Addr = Section.getAddress();
551 if (Addr != Val)
552 continue;
553 if ((ec = Section.getName(Name)))
554 report_fatal_error(ec.message());
555 fmt << Name;
556 return;
557 }
558
559 fmt << format("0x%x", Val);
560 return;
561 }
562
563 StringRef S;
564 bool isExtern = O->getPlainRelocationExternal(RE);
565 uint64_t Val = O->getPlainRelocationSymbolNum(RE);
566
567 if (isExtern) {
568 symbol_iterator SI = O->symbol_begin();
569 advance(SI, Val);
Rafael Espindola5d0c2ff2015-07-02 20:55:21 +0000570 ErrorOr<StringRef> SOrErr = SI->getName();
Davide Italianoccd53fe2015-08-05 07:18:31 +0000571 error(SOrErr.getError());
572 S = *SOrErr;
Rafael Espindola37070a52015-06-03 04:48:06 +0000573 } else {
574 section_iterator SI = O->section_begin();
575 // Adjust for the fact that sections are 1-indexed.
576 advance(SI, Val - 1);
577 SI->getName(S);
578 }
579
580 fmt << S;
581}
582
583static std::error_code getRelocationValueString(const MachOObjectFile *Obj,
584 const RelocationRef &RelRef,
585 SmallVectorImpl<char> &Result) {
586 DataRefImpl Rel = RelRef.getRawDataRefImpl();
587 MachO::any_relocation_info RE = Obj->getRelocation(Rel);
588
589 unsigned Arch = Obj->getArch();
590
591 std::string fmtbuf;
592 raw_string_ostream fmt(fmtbuf);
593 unsigned Type = Obj->getAnyRelocationType(RE);
594 bool IsPCRel = Obj->getAnyRelocationPCRel(RE);
595
596 // Determine any addends that should be displayed with the relocation.
597 // These require decoding the relocation type, which is triple-specific.
598
599 // X86_64 has entirely custom relocation types.
600 if (Arch == Triple::x86_64) {
601 bool isPCRel = Obj->getAnyRelocationPCRel(RE);
602
603 switch (Type) {
604 case MachO::X86_64_RELOC_GOT_LOAD:
605 case MachO::X86_64_RELOC_GOT: {
606 printRelocationTargetName(Obj, RE, fmt);
607 fmt << "@GOT";
608 if (isPCRel)
609 fmt << "PCREL";
610 break;
611 }
612 case MachO::X86_64_RELOC_SUBTRACTOR: {
613 DataRefImpl RelNext = Rel;
614 Obj->moveRelocationNext(RelNext);
615 MachO::any_relocation_info RENext = Obj->getRelocation(RelNext);
616
617 // X86_64_RELOC_SUBTRACTOR must be followed by a relocation of type
618 // X86_64_RELOC_UNSIGNED.
619 // NOTE: Scattered relocations don't exist on x86_64.
620 unsigned RType = Obj->getAnyRelocationType(RENext);
621 if (RType != MachO::X86_64_RELOC_UNSIGNED)
622 report_fatal_error("Expected X86_64_RELOC_UNSIGNED after "
623 "X86_64_RELOC_SUBTRACTOR.");
624
625 // The X86_64_RELOC_UNSIGNED contains the minuend symbol;
626 // X86_64_RELOC_SUBTRACTOR contains the subtrahend.
627 printRelocationTargetName(Obj, RENext, fmt);
628 fmt << "-";
629 printRelocationTargetName(Obj, RE, fmt);
630 break;
631 }
632 case MachO::X86_64_RELOC_TLV:
633 printRelocationTargetName(Obj, RE, fmt);
634 fmt << "@TLV";
635 if (isPCRel)
636 fmt << "P";
637 break;
638 case MachO::X86_64_RELOC_SIGNED_1:
639 printRelocationTargetName(Obj, RE, fmt);
640 fmt << "-1";
641 break;
642 case MachO::X86_64_RELOC_SIGNED_2:
643 printRelocationTargetName(Obj, RE, fmt);
644 fmt << "-2";
645 break;
646 case MachO::X86_64_RELOC_SIGNED_4:
647 printRelocationTargetName(Obj, RE, fmt);
648 fmt << "-4";
649 break;
650 default:
651 printRelocationTargetName(Obj, RE, fmt);
652 break;
653 }
654 // X86 and ARM share some relocation types in common.
655 } else if (Arch == Triple::x86 || Arch == Triple::arm ||
656 Arch == Triple::ppc) {
657 // Generic relocation types...
658 switch (Type) {
659 case MachO::GENERIC_RELOC_PAIR: // prints no info
Rui Ueyama7d099192015-06-09 15:20:42 +0000660 return std::error_code();
Rafael Espindola37070a52015-06-03 04:48:06 +0000661 case MachO::GENERIC_RELOC_SECTDIFF: {
662 DataRefImpl RelNext = Rel;
663 Obj->moveRelocationNext(RelNext);
664 MachO::any_relocation_info RENext = Obj->getRelocation(RelNext);
665
666 // X86 sect diff's must be followed by a relocation of type
667 // GENERIC_RELOC_PAIR.
668 unsigned RType = Obj->getAnyRelocationType(RENext);
669
670 if (RType != MachO::GENERIC_RELOC_PAIR)
671 report_fatal_error("Expected GENERIC_RELOC_PAIR after "
672 "GENERIC_RELOC_SECTDIFF.");
673
674 printRelocationTargetName(Obj, RE, fmt);
675 fmt << "-";
676 printRelocationTargetName(Obj, RENext, fmt);
677 break;
678 }
679 }
680
681 if (Arch == Triple::x86 || Arch == Triple::ppc) {
682 switch (Type) {
683 case MachO::GENERIC_RELOC_LOCAL_SECTDIFF: {
684 DataRefImpl RelNext = Rel;
685 Obj->moveRelocationNext(RelNext);
686 MachO::any_relocation_info RENext = Obj->getRelocation(RelNext);
687
688 // X86 sect diff's must be followed by a relocation of type
689 // GENERIC_RELOC_PAIR.
690 unsigned RType = Obj->getAnyRelocationType(RENext);
691 if (RType != MachO::GENERIC_RELOC_PAIR)
692 report_fatal_error("Expected GENERIC_RELOC_PAIR after "
693 "GENERIC_RELOC_LOCAL_SECTDIFF.");
694
695 printRelocationTargetName(Obj, RE, fmt);
696 fmt << "-";
697 printRelocationTargetName(Obj, RENext, fmt);
698 break;
699 }
700 case MachO::GENERIC_RELOC_TLV: {
701 printRelocationTargetName(Obj, RE, fmt);
702 fmt << "@TLV";
703 if (IsPCRel)
704 fmt << "P";
705 break;
706 }
707 default:
708 printRelocationTargetName(Obj, RE, fmt);
709 }
710 } else { // ARM-specific relocations
711 switch (Type) {
712 case MachO::ARM_RELOC_HALF:
713 case MachO::ARM_RELOC_HALF_SECTDIFF: {
714 // Half relocations steal a bit from the length field to encode
715 // whether this is an upper16 or a lower16 relocation.
716 bool isUpper = Obj->getAnyRelocationLength(RE) >> 1;
717
718 if (isUpper)
719 fmt << ":upper16:(";
720 else
721 fmt << ":lower16:(";
722 printRelocationTargetName(Obj, RE, fmt);
723
724 DataRefImpl RelNext = Rel;
725 Obj->moveRelocationNext(RelNext);
726 MachO::any_relocation_info RENext = Obj->getRelocation(RelNext);
727
728 // ARM half relocs must be followed by a relocation of type
729 // ARM_RELOC_PAIR.
730 unsigned RType = Obj->getAnyRelocationType(RENext);
731 if (RType != MachO::ARM_RELOC_PAIR)
732 report_fatal_error("Expected ARM_RELOC_PAIR after "
733 "ARM_RELOC_HALF");
734
735 // NOTE: The half of the target virtual address is stashed in the
736 // address field of the secondary relocation, but we can't reverse
737 // engineer the constant offset from it without decoding the movw/movt
738 // instruction to find the other half in its immediate field.
739
740 // ARM_RELOC_HALF_SECTDIFF encodes the second section in the
741 // symbol/section pointer of the follow-on relocation.
742 if (Type == MachO::ARM_RELOC_HALF_SECTDIFF) {
743 fmt << "-";
744 printRelocationTargetName(Obj, RENext, fmt);
745 }
746
747 fmt << ")";
748 break;
749 }
750 default: { printRelocationTargetName(Obj, RE, fmt); }
751 }
752 }
753 } else
754 printRelocationTargetName(Obj, RE, fmt);
755
756 fmt.flush();
757 Result.append(fmtbuf.begin(), fmtbuf.end());
Rui Ueyama7d099192015-06-09 15:20:42 +0000758 return std::error_code();
Rafael Espindola37070a52015-06-03 04:48:06 +0000759}
760
761static std::error_code getRelocationValueString(const RelocationRef &Rel,
762 SmallVectorImpl<char> &Result) {
Rafael Espindola854038e2015-06-26 14:51:16 +0000763 const ObjectFile *Obj = Rel.getObject();
Rafael Espindola37070a52015-06-03 04:48:06 +0000764 if (auto *ELF = dyn_cast<ELFObjectFileBase>(Obj))
765 return getRelocationValueString(ELF, Rel, Result);
766 if (auto *COFF = dyn_cast<COFFObjectFile>(Obj))
767 return getRelocationValueString(COFF, Rel, Result);
768 auto *MachO = cast<MachOObjectFile>(Obj);
769 return getRelocationValueString(MachO, Rel, Result);
770}
771
Rafael Espindola0ad71d92015-06-30 03:41:26 +0000772/// @brief Indicates whether this relocation should hidden when listing
773/// relocations, usually because it is the trailing part of a multipart
774/// relocation that will be printed as part of the leading relocation.
775static bool getHidden(RelocationRef RelRef) {
776 const ObjectFile *Obj = RelRef.getObject();
777 auto *MachO = dyn_cast<MachOObjectFile>(Obj);
778 if (!MachO)
779 return false;
780
781 unsigned Arch = MachO->getArch();
782 DataRefImpl Rel = RelRef.getRawDataRefImpl();
783 uint64_t Type = MachO->getRelocationType(Rel);
784
785 // On arches that use the generic relocations, GENERIC_RELOC_PAIR
786 // is always hidden.
787 if (Arch == Triple::x86 || Arch == Triple::arm || Arch == Triple::ppc) {
788 if (Type == MachO::GENERIC_RELOC_PAIR)
789 return true;
790 } else if (Arch == Triple::x86_64) {
791 // On x86_64, X86_64_RELOC_UNSIGNED is hidden only when it follows
792 // an X86_64_RELOC_SUBTRACTOR.
793 if (Type == MachO::X86_64_RELOC_UNSIGNED && Rel.d.a > 0) {
794 DataRefImpl RelPrev = Rel;
795 RelPrev.d.a--;
796 uint64_t PrevType = MachO->getRelocationType(RelPrev);
797 if (PrevType == MachO::X86_64_RELOC_SUBTRACTOR)
798 return true;
799 }
800 }
801
802 return false;
803}
804
Michael J. Spencer51862b32011-10-13 22:17:18 +0000805static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
Jim Grosbachaf9aec02012-08-07 17:53:14 +0000806 const Target *TheTarget = getTarget(Obj);
807 // getTarget() will have already issued a diagnostic if necessary, so
808 // just bail here if it failed.
809 if (!TheTarget)
Michael J. Spencer2670c252011-01-20 06:39:06 +0000810 return;
Michael J. Spencer2670c252011-01-20 06:39:06 +0000811
Jack Carter551efd72012-08-28 19:24:49 +0000812 // Package up features to be passed to target/subtarget
813 std::string FeaturesStr;
814 if (MAttrs.size()) {
815 SubtargetFeatures Features;
816 for (unsigned i = 0; i != MAttrs.size(); ++i)
817 Features.AddFeature(MAttrs[i]);
818 FeaturesStr = Features.getString();
819 }
820
Ahmed Charles56440fd2014-03-06 05:51:42 +0000821 std::unique_ptr<const MCRegisterInfo> MRI(
822 TheTarget->createMCRegInfo(TripleName));
Ahmed Bougacha0835ca12013-05-16 21:28:23 +0000823 if (!MRI) {
824 errs() << "error: no register info for target " << TripleName << "\n";
825 return;
826 }
827
828 // Set up disassembler.
Ahmed Charles56440fd2014-03-06 05:51:42 +0000829 std::unique_ptr<const MCAsmInfo> AsmInfo(
830 TheTarget->createMCAsmInfo(*MRI, TripleName));
Ahmed Bougacha0835ca12013-05-16 21:28:23 +0000831 if (!AsmInfo) {
832 errs() << "error: no assembly info for target " << TripleName << "\n";
833 return;
834 }
835
Ahmed Charles56440fd2014-03-06 05:51:42 +0000836 std::unique_ptr<const MCSubtargetInfo> STI(
Kevin Enderbyc9595622014-08-06 23:24:41 +0000837 TheTarget->createMCSubtargetInfo(TripleName, MCPU, FeaturesStr));
Ahmed Bougacha0835ca12013-05-16 21:28:23 +0000838 if (!STI) {
839 errs() << "error: no subtarget info for target " << TripleName << "\n";
840 return;
841 }
842
Ahmed Charles56440fd2014-03-06 05:51:42 +0000843 std::unique_ptr<const MCInstrInfo> MII(TheTarget->createMCInstrInfo());
Ahmed Bougacha0835ca12013-05-16 21:28:23 +0000844 if (!MII) {
845 errs() << "error: no instruction info for target " << TripleName << "\n";
846 return;
847 }
848
Lang Hamesa1bc0f52014-04-15 04:40:56 +0000849 std::unique_ptr<const MCObjectFileInfo> MOFI(new MCObjectFileInfo);
850 MCContext Ctx(AsmInfo.get(), MRI.get(), MOFI.get());
851
852 std::unique_ptr<MCDisassembler> DisAsm(
853 TheTarget->createMCDisassembler(*STI, Ctx));
854
Ahmed Bougachaad1084d2013-05-24 00:39:57 +0000855 if (!DisAsm) {
856 errs() << "error: no disassembler for target " << TripleName << "\n";
857 return;
858 }
859
Ahmed Charles56440fd2014-03-06 05:51:42 +0000860 std::unique_ptr<const MCInstrAnalysis> MIA(
861 TheTarget->createMCInstrAnalysis(MII.get()));
Ahmed Bougachaaa790682013-05-24 01:07:04 +0000862
Ahmed Bougacha0835ca12013-05-16 21:28:23 +0000863 int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
Daniel Sanders50f17232015-09-15 16:17:27 +0000864 std::unique_ptr<MCInstPrinter> IP(TheTarget->createMCInstPrinter(
865 Triple(TripleName), AsmPrinterVariant, *AsmInfo, *MII, *MRI));
Ahmed Bougacha0835ca12013-05-16 21:28:23 +0000866 if (!IP) {
867 errs() << "error: no instruction printer for target " << TripleName
868 << '\n';
869 return;
870 }
Colin LeMahieu14ec76e2015-06-07 21:07:17 +0000871 IP->setPrintImmHex(PrintImmHex);
Colin LeMahieu35436a22015-05-29 14:48:25 +0000872 PrettyPrinter &PIP = selectPrettyPrinter(Triple(TripleName));
Ahmed Bougacha0835ca12013-05-16 21:28:23 +0000873
Greg Fitzgerald18432272014-03-20 22:55:15 +0000874 StringRef Fmt = Obj->getBytesInAddress() > 4 ? "\t\t%016" PRIx64 ": " :
875 "\t\t\t%08" PRIx64 ": ";
876
Mark Seaborn0929d3d2014-01-25 17:38:19 +0000877 // Create a mapping, RelocSecs = SectionRelocMap[S], where sections
878 // in RelocSecs contain the relocations for section S.
Rafael Espindola4453e42942014-06-13 03:07:50 +0000879 std::error_code EC;
Alexey Samsonov48803e52014-03-13 14:37:36 +0000880 std::map<SectionRef, SmallVector<SectionRef, 1>> SectionRelocMap;
Colin LeMahieu77804be2015-07-29 15:45:39 +0000881 for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
Alexey Samsonov48803e52014-03-13 14:37:36 +0000882 section_iterator Sec2 = Section.getRelocatedSection();
Rafael Espindolab5155a52014-02-10 20:24:04 +0000883 if (Sec2 != Obj->section_end())
Alexey Samsonov48803e52014-03-13 14:37:36 +0000884 SectionRelocMap[*Sec2].push_back(Section);
Mark Seaborn0929d3d2014-01-25 17:38:19 +0000885 }
886
David Majnemer81afca62015-07-07 22:06:59 +0000887 // Create a mapping from virtual address to symbol name. This is used to
888 // pretty print the target of a call.
889 std::vector<std::pair<uint64_t, StringRef>> AllSymbols;
890 if (MIA) {
891 for (const SymbolRef &Symbol : Obj->symbols()) {
David Majnemer2603a8fa2015-07-09 18:11:40 +0000892 if (Symbol.getType() != SymbolRef::ST_Function)
893 continue;
894
David Majnemer81afca62015-07-07 22:06:59 +0000895 ErrorOr<uint64_t> AddressOrErr = Symbol.getAddress();
Davide Italianoccd53fe2015-08-05 07:18:31 +0000896 error(AddressOrErr.getError());
David Majnemer81afca62015-07-07 22:06:59 +0000897 uint64_t Address = *AddressOrErr;
898
899 ErrorOr<StringRef> Name = Symbol.getName();
Davide Italianoccd53fe2015-08-05 07:18:31 +0000900 error(Name.getError());
David Majnemer81afca62015-07-07 22:06:59 +0000901 if (Name->empty())
902 continue;
903 AllSymbols.push_back(std::make_pair(Address, *Name));
904 }
905
906 array_pod_sort(AllSymbols.begin(), AllSymbols.end());
907 }
908
Colin LeMahieu77804be2015-07-29 15:45:39 +0000909 for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
Colin LeMahieuf34933e2015-07-23 20:58:49 +0000910 if (!DisassembleAll && (!Section.isText() || Section.isVirtual()))
Mark Seaborneb03ac52014-01-25 00:32:01 +0000911 continue;
Michael J. Spencer1d6167f2011-06-25 17:55:23 +0000912
Rafael Espindola80291272014-10-08 15:28:58 +0000913 uint64_t SectionAddr = Section.getAddress();
914 uint64_t SectSize = Section.getSize();
David Majnemer185b5b12014-11-11 09:58:25 +0000915 if (!SectSize)
916 continue;
Simon Atanasyan2b614e12014-02-24 22:12:11 +0000917
Benjamin Kramere0dda9c2011-07-15 18:39:24 +0000918 // Make a list of all the symbols in this section.
Alexey Samsonov464d2e42014-03-17 07:28:19 +0000919 std::vector<std::pair<uint64_t, StringRef>> Symbols;
920 for (const SymbolRef &Symbol : Obj->symbols()) {
Rafael Espindola80291272014-10-08 15:28:58 +0000921 if (Section.containsSymbol(Symbol)) {
Rafael Espindolaed067c42015-07-03 18:19:00 +0000922 ErrorOr<uint64_t> AddressOrErr = Symbol.getAddress();
Davide Italianoccd53fe2015-08-05 07:18:31 +0000923 error(AddressOrErr.getError());
Rafael Espindolaed067c42015-07-03 18:19:00 +0000924 uint64_t Address = *AddressOrErr;
Cameron Zwarich07f0f772012-02-03 04:13:37 +0000925 Address -= SectionAddr;
Simon Atanasyan2b614e12014-02-24 22:12:11 +0000926 if (Address >= SectSize)
927 continue;
Cameron Zwarich07f0f772012-02-03 04:13:37 +0000928
Rafael Espindola5d0c2ff2015-07-02 20:55:21 +0000929 ErrorOr<StringRef> Name = Symbol.getName();
Davide Italianoccd53fe2015-08-05 07:18:31 +0000930 error(Name.getError());
Rafael Espindola5d0c2ff2015-07-02 20:55:21 +0000931 Symbols.push_back(std::make_pair(Address, *Name));
Benjamin Kramere0dda9c2011-07-15 18:39:24 +0000932 }
933 }
934
935 // Sort the symbols by address, just in case they didn't come in that way.
936 array_pod_sort(Symbols.begin(), Symbols.end());
937
Michael J. Spencer51862b32011-10-13 22:17:18 +0000938 // Make a list of all the relocations for this section.
939 std::vector<RelocationRef> Rels;
940 if (InlineRelocs) {
Alexey Samsonovaa4d2952014-03-14 14:22:49 +0000941 for (const SectionRef &RelocSec : SectionRelocMap[Section]) {
942 for (const RelocationRef &Reloc : RelocSec.relocations()) {
943 Rels.push_back(Reloc);
944 }
Michael J. Spencer51862b32011-10-13 22:17:18 +0000945 }
946 }
947
948 // Sort relocations by address.
949 std::sort(Rels.begin(), Rels.end(), RelocAddressLess);
950
Rafael Espindolaa9f810b2012-12-21 03:47:03 +0000951 StringRef SegmentName = "";
Mark Seaborneb03ac52014-01-25 00:32:01 +0000952 if (const MachOObjectFile *MachO = dyn_cast<const MachOObjectFile>(Obj)) {
Alexey Samsonov48803e52014-03-13 14:37:36 +0000953 DataRefImpl DR = Section.getRawDataRefImpl();
Rafael Espindola56f976f2013-04-18 18:08:55 +0000954 SegmentName = MachO->getSectionFinalSegmentName(DR);
Rafael Espindolaa9f810b2012-12-21 03:47:03 +0000955 }
Michael J. Spencer1d6167f2011-06-25 17:55:23 +0000956 StringRef name;
Davide Italianoccd53fe2015-08-05 07:18:31 +0000957 error(Section.getName(name));
Rafael Espindolaa9f810b2012-12-21 03:47:03 +0000958 outs() << "Disassembly of section ";
959 if (!SegmentName.empty())
960 outs() << SegmentName << ",";
961 outs() << name << ':';
Benjamin Kramere0dda9c2011-07-15 18:39:24 +0000962
Rafael Espindola7884c952015-06-04 15:01:05 +0000963 // If the section has no symbol at the start, just insert a dummy one.
964 if (Symbols.empty() || Symbols[0].first != 0)
965 Symbols.insert(Symbols.begin(), std::make_pair(0, name));
Alp Tokere69170a2014-06-26 22:52:05 +0000966
967 SmallString<40> Comments;
968 raw_svector_ostream CommentStream(Comments);
Ahmed Bougachaad1084d2013-05-24 00:39:57 +0000969
Rafael Espindola7fc5b872014-11-12 02:04:27 +0000970 StringRef BytesStr;
Davide Italianoccd53fe2015-08-05 07:18:31 +0000971 error(Section.getContents(BytesStr));
Aaron Ballman106fd7b2014-11-12 14:01:17 +0000972 ArrayRef<uint8_t> Bytes(reinterpret_cast<const uint8_t *>(BytesStr.data()),
973 BytesStr.size());
Rafael Espindola7fc5b872014-11-12 02:04:27 +0000974
Michael J. Spencer2670c252011-01-20 06:39:06 +0000975 uint64_t Size;
976 uint64_t Index;
977
Michael J. Spencer51862b32011-10-13 22:17:18 +0000978 std::vector<RelocationRef>::const_iterator rel_cur = Rels.begin();
979 std::vector<RelocationRef>::const_iterator rel_end = Rels.end();
Benjamin Kramere0dda9c2011-07-15 18:39:24 +0000980 // Disassemble symbol by symbol.
981 for (unsigned si = 0, se = Symbols.size(); si != se; ++si) {
Rafael Espindolae45c7402014-08-17 16:31:39 +0000982
Benjamin Kramere0dda9c2011-07-15 18:39:24 +0000983 uint64_t Start = Symbols[si].first;
Rafael Espindolae45c7402014-08-17 16:31:39 +0000984 // The end is either the section end or the beginning of the next symbol.
985 uint64_t End = (si == se - 1) ? SectSize : Symbols[si + 1].first;
986 // If this symbol has the same address as the next symbol, then skip it.
987 if (Start == End)
Michael J. Spenceree84f642011-10-13 20:37:08 +0000988 continue;
989
Benjamin Kramere0dda9c2011-07-15 18:39:24 +0000990 outs() << '\n' << Symbols[si].second << ":\n";
Michael J. Spencer2670c252011-01-20 06:39:06 +0000991
Benjamin Kramere0dda9c2011-07-15 18:39:24 +0000992#ifndef NDEBUG
Mark Seaborneb03ac52014-01-25 00:32:01 +0000993 raw_ostream &DebugOut = DebugFlag ? dbgs() : nulls();
Benjamin Kramere0dda9c2011-07-15 18:39:24 +0000994#else
Mark Seaborneb03ac52014-01-25 00:32:01 +0000995 raw_ostream &DebugOut = nulls();
Benjamin Kramere0dda9c2011-07-15 18:39:24 +0000996#endif
997
Benjamin Kramer43a772e2011-09-19 17:56:04 +0000998 for (Index = Start; Index < End; Index += Size) {
999 MCInst Inst;
Owen Andersona0c3b972011-09-15 23:38:46 +00001000
Rafael Espindola7fc5b872014-11-12 02:04:27 +00001001 if (DisAsm->getInstruction(Inst, Size, Bytes.slice(Index),
1002 SectionAddr + Index, DebugOut,
1003 CommentStream)) {
Colin LeMahieu68d967d2015-05-29 14:44:13 +00001004 PIP.printInst(*IP, &Inst,
Colin LeMahieufb76b002015-05-28 19:07:14 +00001005 Bytes.slice(Index, Size),
1006 SectionAddr + Index, outs(), "", *STI);
Alp Tokere69170a2014-06-26 22:52:05 +00001007 outs() << CommentStream.str();
Ahmed Bougachaad1084d2013-05-24 00:39:57 +00001008 Comments.clear();
David Majnemer2603a8fa2015-07-09 18:11:40 +00001009 if (MIA && (MIA->isCall(Inst) || MIA->isUnconditionalBranch(Inst) ||
1010 MIA->isConditionalBranch(Inst))) {
David Majnemer81afca62015-07-07 22:06:59 +00001011 uint64_t Target;
1012 if (MIA->evaluateBranch(Inst, SectionAddr + Index, Size, Target)) {
David Majnemer2603a8fa2015-07-09 18:11:40 +00001013 auto TargetSym = std::upper_bound(
1014 AllSymbols.begin(), AllSymbols.end(), Target,
Daniel Jasper0f70ee92015-07-10 07:09:20 +00001015 [](uint64_t LHS, const std::pair<uint64_t, StringRef> &RHS) {
David Majnemer2603a8fa2015-07-09 18:11:40 +00001016 return LHS < RHS.first;
1017 });
1018 if (TargetSym != AllSymbols.begin())
1019 --TargetSym;
1020 else
1021 TargetSym = AllSymbols.end();
1022
David Majnemer81afca62015-07-07 22:06:59 +00001023 if (TargetSym != AllSymbols.end()) {
1024 outs() << " <" << TargetSym->second;
David Majnemer2603a8fa2015-07-09 18:11:40 +00001025 uint64_t Disp = Target - TargetSym->first;
David Majnemer81afca62015-07-07 22:06:59 +00001026 if (Disp)
David Majnemer2603a8fa2015-07-09 18:11:40 +00001027 outs() << '+' << utohexstr(Disp);
David Majnemer81afca62015-07-07 22:06:59 +00001028 outs() << '>';
1029 }
1030 }
1031 }
Benjamin Kramer43a772e2011-09-19 17:56:04 +00001032 outs() << "\n";
1033 } else {
1034 errs() << ToolName << ": warning: invalid instruction encoding\n";
1035 if (Size == 0)
1036 Size = 1; // skip illegible bytes
Benjamin Kramere0dda9c2011-07-15 18:39:24 +00001037 }
Michael J. Spencer51862b32011-10-13 22:17:18 +00001038
1039 // Print relocation for instruction.
1040 while (rel_cur != rel_end) {
Rafael Espindola0ad71d92015-06-30 03:41:26 +00001041 bool hidden = getHidden(*rel_cur);
Rafael Espindola96d071c2015-06-29 23:29:12 +00001042 uint64_t addr = rel_cur->getOffset();
Michael J. Spencer51862b32011-10-13 22:17:18 +00001043 SmallString<16> name;
1044 SmallString<32> val;
Owen Andersonfa3e5202011-10-25 20:35:53 +00001045
1046 // If this relocation is hidden, skip it.
Owen Andersonfa3e5202011-10-25 20:35:53 +00001047 if (hidden) goto skip_print_rel;
1048
Michael J. Spencer51862b32011-10-13 22:17:18 +00001049 // Stop when rel_cur's address is past the current instruction.
Owen Andersonf20e3e52011-10-25 20:15:39 +00001050 if (addr >= Index + Size) break;
Rafael Espindola41bb4322015-06-30 04:08:37 +00001051 rel_cur->getTypeName(name);
Davide Italianoccd53fe2015-08-05 07:18:31 +00001052 error(getRelocationValueString(*rel_cur, val));
Greg Fitzgerald18432272014-03-20 22:55:15 +00001053 outs() << format(Fmt.data(), SectionAddr + addr) << name
Benjamin Kramer82803112012-03-10 02:04:38 +00001054 << "\t" << val << "\n";
Michael J. Spencer51862b32011-10-13 22:17:18 +00001055
1056 skip_print_rel:
1057 ++rel_cur;
1058 }
Benjamin Kramer87ee76c2011-07-20 19:37:35 +00001059 }
Michael J. Spencer2670c252011-01-20 06:39:06 +00001060 }
1061 }
1062}
1063
Kevin Enderby98da6132015-01-20 21:47:46 +00001064void llvm::PrintRelocations(const ObjectFile *Obj) {
Greg Fitzgerald18432272014-03-20 22:55:15 +00001065 StringRef Fmt = Obj->getBytesInAddress() > 4 ? "%016" PRIx64 :
1066 "%08" PRIx64;
Rafael Espindolac66d7612014-08-17 19:09:37 +00001067 // Regular objdump doesn't print relocations in non-relocatable object
1068 // files.
1069 if (!Obj->isRelocatableObject())
1070 return;
1071
Colin LeMahieu77804be2015-07-29 15:45:39 +00001072 for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
Alexey Samsonov48803e52014-03-13 14:37:36 +00001073 if (Section.relocation_begin() == Section.relocation_end())
Michael J. Spencerba4a3622011-10-08 00:18:30 +00001074 continue;
1075 StringRef secname;
Davide Italianoccd53fe2015-08-05 07:18:31 +00001076 error(Section.getName(secname));
Michael J. Spencerba4a3622011-10-08 00:18:30 +00001077 outs() << "RELOCATION RECORDS FOR [" << secname << "]:\n";
Alexey Samsonovaa4d2952014-03-14 14:22:49 +00001078 for (const RelocationRef &Reloc : Section.relocations()) {
Rafael Espindola0ad71d92015-06-30 03:41:26 +00001079 bool hidden = getHidden(Reloc);
Rafael Espindola96d071c2015-06-29 23:29:12 +00001080 uint64_t address = Reloc.getOffset();
Michael J. Spencerba4a3622011-10-08 00:18:30 +00001081 SmallString<32> relocname;
1082 SmallString<32> valuestr;
Alexey Samsonovaa4d2952014-03-14 14:22:49 +00001083 if (hidden)
1084 continue;
Rafael Espindola41bb4322015-06-30 04:08:37 +00001085 Reloc.getTypeName(relocname);
Davide Italianoccd53fe2015-08-05 07:18:31 +00001086 error(getRelocationValueString(Reloc, valuestr));
Greg Fitzgerald18432272014-03-20 22:55:15 +00001087 outs() << format(Fmt.data(), address) << " " << relocname << " "
1088 << valuestr << "\n";
Michael J. Spencerba4a3622011-10-08 00:18:30 +00001089 }
1090 outs() << "\n";
1091 }
1092}
1093
Kevin Enderby98da6132015-01-20 21:47:46 +00001094void llvm::PrintSectionHeaders(const ObjectFile *Obj) {
Nick Lewyckyfcf84622011-10-10 21:21:34 +00001095 outs() << "Sections:\n"
1096 "Idx Name Size Address Type\n";
Nick Lewyckyfcf84622011-10-10 21:21:34 +00001097 unsigned i = 0;
Colin LeMahieu77804be2015-07-29 15:45:39 +00001098 for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
Nick Lewyckyfcf84622011-10-10 21:21:34 +00001099 StringRef Name;
Davide Italianoccd53fe2015-08-05 07:18:31 +00001100 error(Section.getName(Name));
Rafael Espindola80291272014-10-08 15:28:58 +00001101 uint64_t Address = Section.getAddress();
1102 uint64_t Size = Section.getSize();
1103 bool Text = Section.isText();
1104 bool Data = Section.isData();
1105 bool BSS = Section.isBSS();
Nick Lewyckyfcf84622011-10-10 21:21:34 +00001106 std::string Type = (std::string(Text ? "TEXT " : "") +
Michael J. Spencer8f67d472011-10-13 20:37:20 +00001107 (Data ? "DATA " : "") + (BSS ? "BSS" : ""));
Alexey Samsonov48803e52014-03-13 14:37:36 +00001108 outs() << format("%3d %-13s %08" PRIx64 " %016" PRIx64 " %s\n", i,
1109 Name.str().c_str(), Size, Address, Type.c_str());
Nick Lewyckyfcf84622011-10-10 21:21:34 +00001110 ++i;
1111 }
1112}
1113
Kevin Enderby98da6132015-01-20 21:47:46 +00001114void llvm::PrintSectionContents(const ObjectFile *Obj) {
Rafael Espindola4453e42942014-06-13 03:07:50 +00001115 std::error_code EC;
Colin LeMahieu77804be2015-07-29 15:45:39 +00001116 for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
Michael J. Spencer4e25c022011-10-17 17:13:22 +00001117 StringRef Name;
1118 StringRef Contents;
Davide Italianoccd53fe2015-08-05 07:18:31 +00001119 error(Section.getName(Name));
Rafael Espindola80291272014-10-08 15:28:58 +00001120 uint64_t BaseAddr = Section.getAddress();
David Majnemer185b5b12014-11-11 09:58:25 +00001121 uint64_t Size = Section.getSize();
1122 if (!Size)
1123 continue;
Michael J. Spencer4e25c022011-10-17 17:13:22 +00001124
1125 outs() << "Contents of section " << Name << ":\n";
David Majnemer185b5b12014-11-11 09:58:25 +00001126 if (Section.isBSS()) {
Alexey Samsonov209095c2013-04-16 10:53:11 +00001127 outs() << format("<skipping contents of bss section at [%04" PRIx64
David Majnemer8f6b04c2014-07-14 16:20:14 +00001128 ", %04" PRIx64 ")>\n",
1129 BaseAddr, BaseAddr + Size);
Alexey Samsonov209095c2013-04-16 10:53:11 +00001130 continue;
1131 }
Michael J. Spencer4e25c022011-10-17 17:13:22 +00001132
Davide Italianoccd53fe2015-08-05 07:18:31 +00001133 error(Section.getContents(Contents));
David Majnemer8f6b04c2014-07-14 16:20:14 +00001134
Michael J. Spencer4e25c022011-10-17 17:13:22 +00001135 // Dump out the content as hex and printable ascii characters.
1136 for (std::size_t addr = 0, end = Contents.size(); addr < end; addr += 16) {
Benjamin Kramer82803112012-03-10 02:04:38 +00001137 outs() << format(" %04" PRIx64 " ", BaseAddr + addr);
Michael J. Spencer4e25c022011-10-17 17:13:22 +00001138 // Dump line of hex.
1139 for (std::size_t i = 0; i < 16; ++i) {
1140 if (i != 0 && i % 4 == 0)
1141 outs() << ' ';
1142 if (addr + i < end)
1143 outs() << hexdigit((Contents[addr + i] >> 4) & 0xF, true)
1144 << hexdigit(Contents[addr + i] & 0xF, true);
1145 else
1146 outs() << " ";
1147 }
1148 // Print ascii.
1149 outs() << " ";
1150 for (std::size_t i = 0; i < 16 && addr + i < end; ++i) {
Guy Benyei83c74e92013-02-12 21:21:59 +00001151 if (std::isprint(static_cast<unsigned char>(Contents[addr + i]) & 0xFF))
Michael J. Spencer4e25c022011-10-17 17:13:22 +00001152 outs() << Contents[addr + i];
1153 else
1154 outs() << ".";
1155 }
1156 outs() << "\n";
1157 }
1158 }
1159}
1160
Michael J. Spencerbfa06782011-10-18 19:32:17 +00001161static void PrintCOFFSymbolTable(const COFFObjectFile *coff) {
David Majnemer44f51e52014-09-10 12:51:52 +00001162 for (unsigned SI = 0, SE = coff->getNumberOfSymbols(); SI != SE; ++SI) {
1163 ErrorOr<COFFSymbolRef> Symbol = coff->getSymbol(SI);
Saleem Abdulrasool7050eed2014-04-14 02:37:28 +00001164 StringRef Name;
Davide Italianoccd53fe2015-08-05 07:18:31 +00001165 error(Symbol.getError());
1166 error(coff->getSymbolName(*Symbol, Name));
Saleem Abdulrasool7050eed2014-04-14 02:37:28 +00001167
1168 outs() << "[" << format("%2d", SI) << "]"
David Majnemer44f51e52014-09-10 12:51:52 +00001169 << "(sec " << format("%2d", int(Symbol->getSectionNumber())) << ")"
Saleem Abdulrasool7050eed2014-04-14 02:37:28 +00001170 << "(fl 0x00)" // Flag bits, which COFF doesn't have.
David Majnemer44f51e52014-09-10 12:51:52 +00001171 << "(ty " << format("%3x", unsigned(Symbol->getType())) << ")"
1172 << "(scl " << format("%3x", unsigned(Symbol->getStorageClass())) << ") "
1173 << "(nx " << unsigned(Symbol->getNumberOfAuxSymbols()) << ") "
1174 << "0x" << format("%08x", unsigned(Symbol->getValue())) << " "
Saleem Abdulrasool7050eed2014-04-14 02:37:28 +00001175 << Name << "\n";
1176
David Majnemer44f51e52014-09-10 12:51:52 +00001177 for (unsigned AI = 0, AE = Symbol->getNumberOfAuxSymbols(); AI < AE; ++AI, ++SI) {
Saleem Abdulrasool7050eed2014-04-14 02:37:28 +00001178 if (Symbol->isSectionDefinition()) {
Michael J. Spencerbfa06782011-10-18 19:32:17 +00001179 const coff_aux_section_definition *asd;
Davide Italianoccd53fe2015-08-05 07:18:31 +00001180 error(coff->getAuxSymbol<coff_aux_section_definition>(SI + 1, asd));
Saleem Abdulrasool9ede5c72014-04-13 03:11:08 +00001181
David Majnemer4d571592014-09-15 19:42:42 +00001182 int32_t AuxNumber = asd->getNumber(Symbol->isBigObj());
1183
Michael J. Spencerbfa06782011-10-18 19:32:17 +00001184 outs() << "AUX "
1185 << format("scnlen 0x%x nreloc %d nlnno %d checksum 0x%x "
1186 , unsigned(asd->Length)
1187 , unsigned(asd->NumberOfRelocations)
1188 , unsigned(asd->NumberOfLinenumbers)
1189 , unsigned(asd->CheckSum))
1190 << format("assoc %d comdat %d\n"
David Majnemer4d571592014-09-15 19:42:42 +00001191 , unsigned(AuxNumber)
Michael J. Spencerbfa06782011-10-18 19:32:17 +00001192 , unsigned(asd->Selection));
Saleem Abdulrasool7050eed2014-04-14 02:37:28 +00001193 } else if (Symbol->isFileRecord()) {
David Majnemer44f51e52014-09-10 12:51:52 +00001194 const char *FileName;
Davide Italianoccd53fe2015-08-05 07:18:31 +00001195 error(coff->getAuxSymbol<char>(SI + 1, FileName));
Saleem Abdulrasoold38c6b12014-04-14 02:37:23 +00001196
David Majnemer44f51e52014-09-10 12:51:52 +00001197 StringRef Name(FileName, Symbol->getNumberOfAuxSymbols() *
1198 coff->getSymbolTableEntrySize());
Saleem Abdulrasoold38c6b12014-04-14 02:37:23 +00001199 outs() << "AUX " << Name.rtrim(StringRef("\0", 1)) << '\n';
Saleem Abdulrasool13a3f692014-04-14 16:38:25 +00001200
David Majnemer44f51e52014-09-10 12:51:52 +00001201 SI = SI + Symbol->getNumberOfAuxSymbols();
Saleem Abdulrasool13a3f692014-04-14 16:38:25 +00001202 break;
Saleem Abdulrasoold38c6b12014-04-14 02:37:23 +00001203 } else {
1204 outs() << "AUX Unknown\n";
Saleem Abdulrasool9ede5c72014-04-13 03:11:08 +00001205 }
Michael J. Spencerbfa06782011-10-18 19:32:17 +00001206 }
1207 }
1208}
1209
Kevin Enderby98da6132015-01-20 21:47:46 +00001210void llvm::PrintSymbolTable(const ObjectFile *o) {
Michael J. Spencerbfa06782011-10-18 19:32:17 +00001211 outs() << "SYMBOL TABLE:\n";
1212
Rui Ueyama4e39f712014-03-18 18:58:51 +00001213 if (const COFFObjectFile *coff = dyn_cast<const COFFObjectFile>(o)) {
Michael J. Spencerbfa06782011-10-18 19:32:17 +00001214 PrintCOFFSymbolTable(coff);
Rui Ueyama4e39f712014-03-18 18:58:51 +00001215 return;
1216 }
1217 for (const SymbolRef &Symbol : o->symbols()) {
Rafael Espindolaed067c42015-07-03 18:19:00 +00001218 ErrorOr<uint64_t> AddressOrError = Symbol.getAddress();
Davide Italianoccd53fe2015-08-05 07:18:31 +00001219 error(AddressOrError.getError());
Rafael Espindolaed067c42015-07-03 18:19:00 +00001220 uint64_t Address = *AddressOrError;
Rafael Espindola2fa80cc2015-06-26 12:18:49 +00001221 SymbolRef::Type Type = Symbol.getType();
Rui Ueyama4e39f712014-03-18 18:58:51 +00001222 uint32_t Flags = Symbol.getFlags();
Rafael Espindola8bab8892015-08-07 23:27:14 +00001223 ErrorOr<section_iterator> SectionOrErr = Symbol.getSection();
1224 error(SectionOrErr.getError());
1225 section_iterator Section = *SectionOrErr;
Rafael Espindola75d5b542015-06-03 05:14:22 +00001226 StringRef Name;
1227 if (Type == SymbolRef::ST_Debug && Section != o->section_end()) {
1228 Section->getName(Name);
Rafael Espindola5d0c2ff2015-07-02 20:55:21 +00001229 } else {
1230 ErrorOr<StringRef> NameOrErr = Symbol.getName();
Davide Italianoccd53fe2015-08-05 07:18:31 +00001231 error(NameOrErr.getError());
Rafael Espindola5d0c2ff2015-07-02 20:55:21 +00001232 Name = *NameOrErr;
Rafael Espindola75d5b542015-06-03 05:14:22 +00001233 }
Michael J. Spencerbfa06782011-10-18 19:32:17 +00001234
Rui Ueyama4e39f712014-03-18 18:58:51 +00001235 bool Global = Flags & SymbolRef::SF_Global;
1236 bool Weak = Flags & SymbolRef::SF_Weak;
1237 bool Absolute = Flags & SymbolRef::SF_Absolute;
Colin LeMahieubc2f47a2015-01-23 20:06:24 +00001238 bool Common = Flags & SymbolRef::SF_Common;
Davide Italianocd2514d2015-04-30 23:08:53 +00001239 bool Hidden = Flags & SymbolRef::SF_Hidden;
David Meyer1df4b842012-02-28 23:47:53 +00001240
Rui Ueyama4e39f712014-03-18 18:58:51 +00001241 char GlobLoc = ' ';
1242 if (Type != SymbolRef::ST_Unknown)
1243 GlobLoc = Global ? 'g' : 'l';
1244 char Debug = (Type == SymbolRef::ST_Debug || Type == SymbolRef::ST_File)
1245 ? 'd' : ' ';
1246 char FileFunc = ' ';
1247 if (Type == SymbolRef::ST_File)
1248 FileFunc = 'f';
1249 else if (Type == SymbolRef::ST_Function)
1250 FileFunc = 'F';
Michael J. Spencerbfa06782011-10-18 19:32:17 +00001251
Rui Ueyama4e39f712014-03-18 18:58:51 +00001252 const char *Fmt = o->getBytesInAddress() > 4 ? "%016" PRIx64 :
1253 "%08" PRIx64;
Michael J. Spencerd857c1c2013-01-10 22:40:50 +00001254
Rui Ueyama4e39f712014-03-18 18:58:51 +00001255 outs() << format(Fmt, Address) << " "
1256 << GlobLoc // Local -> 'l', Global -> 'g', Neither -> ' '
1257 << (Weak ? 'w' : ' ') // Weak?
1258 << ' ' // Constructor. Not supported yet.
1259 << ' ' // Warning. Not supported yet.
1260 << ' ' // Indirect reference to another symbol.
1261 << Debug // Debugging (d) or dynamic (D) symbol.
1262 << FileFunc // Name of function (F), file (f) or object (O).
1263 << ' ';
1264 if (Absolute) {
1265 outs() << "*ABS*";
Colin LeMahieubc2f47a2015-01-23 20:06:24 +00001266 } else if (Common) {
1267 outs() << "*COM*";
Rui Ueyama4e39f712014-03-18 18:58:51 +00001268 } else if (Section == o->section_end()) {
1269 outs() << "*UND*";
1270 } else {
1271 if (const MachOObjectFile *MachO =
1272 dyn_cast<const MachOObjectFile>(o)) {
1273 DataRefImpl DR = Section->getRawDataRefImpl();
1274 StringRef SegmentName = MachO->getSectionFinalSegmentName(DR);
1275 outs() << SegmentName << ",";
Michael J. Spencerbfa06782011-10-18 19:32:17 +00001276 }
Rui Ueyama4e39f712014-03-18 18:58:51 +00001277 StringRef SectionName;
Davide Italianoccd53fe2015-08-05 07:18:31 +00001278 error(Section->getName(SectionName));
Rui Ueyama4e39f712014-03-18 18:58:51 +00001279 outs() << SectionName;
Michael J. Spencerbfa06782011-10-18 19:32:17 +00001280 }
Rafael Espindola5f7ade22015-06-23 15:45:38 +00001281
1282 outs() << '\t';
Rafael Espindolaae3ac082015-06-23 18:34:25 +00001283 if (Common || isa<ELFObjectFileBase>(o)) {
Rafael Espindoladbb6bd32015-06-25 22:10:04 +00001284 uint64_t Val =
1285 Common ? Symbol.getAlignment() : ELFSymbolRef(Symbol).getSize();
Rafael Espindolaae3ac082015-06-23 18:34:25 +00001286 outs() << format("\t %08" PRIx64 " ", Val);
1287 }
Rafael Espindola5f7ade22015-06-23 15:45:38 +00001288
Davide Italianocd2514d2015-04-30 23:08:53 +00001289 if (Hidden) {
1290 outs() << ".hidden ";
1291 }
1292 outs() << Name
Rui Ueyama4e39f712014-03-18 18:58:51 +00001293 << '\n';
Michael J. Spencerbfa06782011-10-18 19:32:17 +00001294 }
1295}
1296
Michael J. Spencer0c6ec482012-12-05 20:12:35 +00001297static void PrintUnwindInfo(const ObjectFile *o) {
1298 outs() << "Unwind info:\n\n";
1299
1300 if (const COFFObjectFile *coff = dyn_cast<COFFObjectFile>(o)) {
1301 printCOFFUnwindInfo(coff);
Tim Northover4bd286a2014-08-01 13:07:19 +00001302 } else if (const MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o))
1303 printMachOUnwindInfo(MachO);
1304 else {
Michael J. Spencer0c6ec482012-12-05 20:12:35 +00001305 // TODO: Extract DWARF dump tool to objdump.
1306 errs() << "This operation is only currently supported "
Tim Northover4bd286a2014-08-01 13:07:19 +00001307 "for COFF and MachO object files.\n";
Michael J. Spencer0c6ec482012-12-05 20:12:35 +00001308 return;
1309 }
1310}
1311
Kevin Enderbye2297dd2015-01-07 21:02:18 +00001312void llvm::printExportsTrie(const ObjectFile *o) {
Nick Kledzikd04bc352014-08-30 00:20:14 +00001313 outs() << "Exports trie:\n";
1314 if (const MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o))
1315 printMachOExportsTrie(MachO);
1316 else {
1317 errs() << "This operation is only currently supported "
1318 "for Mach-O executable files.\n";
1319 return;
1320 }
1321}
1322
Kevin Enderbye2297dd2015-01-07 21:02:18 +00001323void llvm::printRebaseTable(const ObjectFile *o) {
Nick Kledzikac431442014-09-12 21:34:15 +00001324 outs() << "Rebase table:\n";
1325 if (const MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o))
1326 printMachORebaseTable(MachO);
1327 else {
1328 errs() << "This operation is only currently supported "
1329 "for Mach-O executable files.\n";
1330 return;
1331 }
1332}
1333
Kevin Enderbye2297dd2015-01-07 21:02:18 +00001334void llvm::printBindTable(const ObjectFile *o) {
Nick Kledzik56ebef42014-09-16 01:41:51 +00001335 outs() << "Bind table:\n";
1336 if (const MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o))
1337 printMachOBindTable(MachO);
1338 else {
1339 errs() << "This operation is only currently supported "
1340 "for Mach-O executable files.\n";
1341 return;
1342 }
1343}
1344
Kevin Enderbye2297dd2015-01-07 21:02:18 +00001345void llvm::printLazyBindTable(const ObjectFile *o) {
Nick Kledzik56ebef42014-09-16 01:41:51 +00001346 outs() << "Lazy bind table:\n";
1347 if (const MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o))
1348 printMachOLazyBindTable(MachO);
1349 else {
1350 errs() << "This operation is only currently supported "
1351 "for Mach-O executable files.\n";
1352 return;
1353 }
1354}
1355
Kevin Enderbye2297dd2015-01-07 21:02:18 +00001356void llvm::printWeakBindTable(const ObjectFile *o) {
Nick Kledzik56ebef42014-09-16 01:41:51 +00001357 outs() << "Weak bind table:\n";
1358 if (const MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o))
1359 printMachOWeakBindTable(MachO);
1360 else {
1361 errs() << "This operation is only currently supported "
1362 "for Mach-O executable files.\n";
1363 return;
1364 }
1365}
Nick Kledzikac431442014-09-12 21:34:15 +00001366
Adrian Prantl437105a2015-07-08 02:04:15 +00001367/// Dump the raw contents of the __clangast section so the output can be piped
1368/// into llvm-bcanalyzer.
1369void llvm::printRawClangAST(const ObjectFile *Obj) {
1370 if (outs().is_displayed()) {
1371 errs() << "The -raw-clang-ast option will dump the raw binary contents of "
1372 "the clang ast section.\n"
1373 "Please redirect the output to a file or another program such as "
1374 "llvm-bcanalyzer.\n";
1375 return;
1376 }
1377
1378 StringRef ClangASTSectionName("__clangast");
1379 if (isa<COFFObjectFile>(Obj)) {
1380 ClangASTSectionName = "clangast";
1381 }
1382
1383 Optional<object::SectionRef> ClangASTSection;
Colin LeMahieu77804be2015-07-29 15:45:39 +00001384 for (auto Sec : ToolSectionFilter(*Obj)) {
Adrian Prantl437105a2015-07-08 02:04:15 +00001385 StringRef Name;
1386 Sec.getName(Name);
1387 if (Name == ClangASTSectionName) {
1388 ClangASTSection = Sec;
1389 break;
1390 }
1391 }
1392 if (!ClangASTSection)
1393 return;
1394
1395 StringRef ClangASTContents;
Davide Italianoccd53fe2015-08-05 07:18:31 +00001396 error(ClangASTSection.getValue().getContents(ClangASTContents));
Adrian Prantl437105a2015-07-08 02:04:15 +00001397 outs().write(ClangASTContents.data(), ClangASTContents.size());
1398}
1399
Sanjoy Das6f567a42015-06-22 18:03:02 +00001400static void printFaultMaps(const ObjectFile *Obj) {
1401 const char *FaultMapSectionName = nullptr;
1402
1403 if (isa<ELFObjectFileBase>(Obj)) {
1404 FaultMapSectionName = ".llvm_faultmaps";
1405 } else if (isa<MachOObjectFile>(Obj)) {
1406 FaultMapSectionName = "__llvm_faultmaps";
1407 } else {
1408 errs() << "This operation is only currently supported "
1409 "for ELF and Mach-O executable files.\n";
1410 return;
1411 }
1412
1413 Optional<object::SectionRef> FaultMapSection;
1414
Colin LeMahieu77804be2015-07-29 15:45:39 +00001415 for (auto Sec : ToolSectionFilter(*Obj)) {
Sanjoy Das6f567a42015-06-22 18:03:02 +00001416 StringRef Name;
1417 Sec.getName(Name);
1418 if (Name == FaultMapSectionName) {
1419 FaultMapSection = Sec;
1420 break;
1421 }
1422 }
1423
1424 outs() << "FaultMap table:\n";
1425
1426 if (!FaultMapSection.hasValue()) {
1427 outs() << "<not found>\n";
1428 return;
1429 }
1430
1431 StringRef FaultMapContents;
Davide Italianoccd53fe2015-08-05 07:18:31 +00001432 error(FaultMapSection.getValue().getContents(FaultMapContents));
Sanjoy Das6f567a42015-06-22 18:03:02 +00001433
1434 FaultMapParser FMP(FaultMapContents.bytes_begin(),
1435 FaultMapContents.bytes_end());
1436
1437 outs() << FMP;
1438}
1439
Rui Ueyamac2bed422013-09-27 21:04:00 +00001440static void printPrivateFileHeader(const ObjectFile *o) {
1441 if (o->isELF()) {
1442 printELFFileHeader(o);
1443 } else if (o->isCOFF()) {
1444 printCOFFFileHeader(o);
Kevin Enderbyb76d3862014-08-22 20:35:18 +00001445 } else if (o->isMachO()) {
1446 printMachOFileHeader(o);
Rui Ueyamac2bed422013-09-27 21:04:00 +00001447 }
1448}
1449
Michael J. Spencerba4a3622011-10-08 00:18:30 +00001450static void DumpObject(const ObjectFile *o) {
Adrian Prantl437105a2015-07-08 02:04:15 +00001451 // Avoid other output when using a raw option.
1452 if (!RawClangAST) {
1453 outs() << '\n';
1454 outs() << o->getFileName()
1455 << ":\tfile format " << o->getFileFormatName() << "\n\n";
1456 }
Michael J. Spencer4e25c022011-10-17 17:13:22 +00001457
Michael J. Spencerba4a3622011-10-08 00:18:30 +00001458 if (Disassemble)
Michael J. Spencer51862b32011-10-13 22:17:18 +00001459 DisassembleObject(o, Relocations);
1460 if (Relocations && !Disassemble)
Michael J. Spencerba4a3622011-10-08 00:18:30 +00001461 PrintRelocations(o);
Nick Lewyckyfcf84622011-10-10 21:21:34 +00001462 if (SectionHeaders)
1463 PrintSectionHeaders(o);
Michael J. Spencer4e25c022011-10-17 17:13:22 +00001464 if (SectionContents)
1465 PrintSectionContents(o);
Michael J. Spencerbfa06782011-10-18 19:32:17 +00001466 if (SymbolTable)
1467 PrintSymbolTable(o);
Michael J. Spencer0c6ec482012-12-05 20:12:35 +00001468 if (UnwindInfo)
1469 PrintUnwindInfo(o);
Rui Ueyamac2bed422013-09-27 21:04:00 +00001470 if (PrivateHeaders)
1471 printPrivateFileHeader(o);
Nick Kledzikd04bc352014-08-30 00:20:14 +00001472 if (ExportsTrie)
1473 printExportsTrie(o);
Nick Kledzikac431442014-09-12 21:34:15 +00001474 if (Rebase)
1475 printRebaseTable(o);
Nick Kledzik56ebef42014-09-16 01:41:51 +00001476 if (Bind)
1477 printBindTable(o);
1478 if (LazyBind)
1479 printLazyBindTable(o);
1480 if (WeakBind)
1481 printWeakBindTable(o);
Adrian Prantl437105a2015-07-08 02:04:15 +00001482 if (RawClangAST)
1483 printRawClangAST(o);
Sanjoy Das6f567a42015-06-22 18:03:02 +00001484 if (PrintFaultMaps)
1485 printFaultMaps(o);
Michael J. Spencerba4a3622011-10-08 00:18:30 +00001486}
1487
1488/// @brief Dump each object file in \a a;
1489static void DumpArchive(const Archive *a) {
Davide Italiano95dd3cb2015-08-03 21:46:32 +00001490 for (const Archive::Child &C : a->children()) {
1491 ErrorOr<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
Davide Italianoccd53fe2015-08-05 07:18:31 +00001492 if (std::error_code EC = ChildOrErr.getError())
Mark Seaborneb03ac52014-01-25 00:32:01 +00001493 if (EC != object_error::invalid_file_type)
Alexey Samsonov50d0fbd2015-06-04 18:34:11 +00001494 report_error(a->getFileName(), EC);
Rafael Espindolaae460022014-06-16 16:08:36 +00001495 if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get()))
Michael J. Spencerba4a3622011-10-08 00:18:30 +00001496 DumpObject(o);
1497 else
Alexey Samsonov50d0fbd2015-06-04 18:34:11 +00001498 report_error(a->getFileName(), object_error::invalid_file_type);
Michael J. Spencerba4a3622011-10-08 00:18:30 +00001499 }
1500}
1501
1502/// @brief Open file and figure out how to dump it.
1503static void DumpInput(StringRef file) {
1504 // If file isn't stdin, check that it exists.
Davide Italianoccd53fe2015-08-05 07:18:31 +00001505 if (file != "-" && !sys::fs::exists(file))
Alexey Samsonov50d0fbd2015-06-04 18:34:11 +00001506 report_error(file, errc::no_such_file_or_directory);
Michael J. Spencerba4a3622011-10-08 00:18:30 +00001507
Kevin Enderbye2297dd2015-01-07 21:02:18 +00001508 // If we are using the Mach-O specific object file parser, then let it parse
1509 // the file and process the command line options. So the -arch flags can
1510 // be used to select specific slices, etc.
1511 if (MachOOpt) {
1512 ParseInputMachO(file);
Michael J. Spencerba4a3622011-10-08 00:18:30 +00001513 return;
1514 }
1515
1516 // Attempt to open the binary.
Rafael Espindola48af1c22014-08-19 18:44:46 +00001517 ErrorOr<OwningBinary<Binary>> BinaryOrErr = createBinary(file);
Davide Italianoccd53fe2015-08-05 07:18:31 +00001518 if (std::error_code EC = BinaryOrErr.getError())
Alexey Samsonov50d0fbd2015-06-04 18:34:11 +00001519 report_error(file, EC);
Rafael Espindola48af1c22014-08-19 18:44:46 +00001520 Binary &Binary = *BinaryOrErr.get().getBinary();
Michael J. Spencerba4a3622011-10-08 00:18:30 +00001521
Rafael Espindola3f6481d2014-08-01 14:31:55 +00001522 if (Archive *a = dyn_cast<Archive>(&Binary))
Michael J. Spencerba4a3622011-10-08 00:18:30 +00001523 DumpArchive(a);
Rafael Espindola3f6481d2014-08-01 14:31:55 +00001524 else if (ObjectFile *o = dyn_cast<ObjectFile>(&Binary))
Michael J. Spencerba4a3622011-10-08 00:18:30 +00001525 DumpObject(o);
Jim Grosbachaf9aec02012-08-07 17:53:14 +00001526 else
Alexey Samsonov50d0fbd2015-06-04 18:34:11 +00001527 report_error(file, object_error::invalid_file_type);
Michael J. Spencerba4a3622011-10-08 00:18:30 +00001528}
1529
Michael J. Spencer2670c252011-01-20 06:39:06 +00001530int main(int argc, char **argv) {
1531 // Print a stack trace if we signal out.
1532 sys::PrintStackTraceOnErrorSignal();
1533 PrettyStackTraceProgram X(argc, argv);
1534 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
1535
1536 // Initialize targets and assembly printers/parsers.
1537 llvm::InitializeAllTargetInfos();
Evan Cheng8c886a42011-07-22 21:58:54 +00001538 llvm::InitializeAllTargetMCs();
Michael J. Spencer2670c252011-01-20 06:39:06 +00001539 llvm::InitializeAllAsmParsers();
1540 llvm::InitializeAllDisassemblers();
1541
Pete Cooper28fb4fc2012-05-03 23:20:10 +00001542 // Register the target printer for --version.
1543 cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion);
1544
Michael J. Spencer2670c252011-01-20 06:39:06 +00001545 cl::ParseCommandLineOptions(argc, argv, "llvm object file dumper\n");
1546 TripleName = Triple::normalize(TripleName);
1547
1548 ToolName = argv[0];
1549
1550 // Defaults to a.out if no filenames specified.
1551 if (InputFilenames.size() == 0)
1552 InputFilenames.push_back("a.out");
1553
Colin LeMahieuf34933e2015-07-23 20:58:49 +00001554 if (DisassembleAll)
1555 Disassemble = true;
Michael J. Spencerbfa06782011-10-18 19:32:17 +00001556 if (!Disassemble
1557 && !Relocations
1558 && !SectionHeaders
1559 && !SectionContents
Michael J. Spencer0c6ec482012-12-05 20:12:35 +00001560 && !SymbolTable
Michael J. Spencer209565db2013-01-06 03:56:49 +00001561 && !UnwindInfo
Nick Kledzikd04bc352014-08-30 00:20:14 +00001562 && !PrivateHeaders
Nick Kledzikac431442014-09-12 21:34:15 +00001563 && !ExportsTrie
Nick Kledzik56ebef42014-09-16 01:41:51 +00001564 && !Rebase
1565 && !Bind
1566 && !LazyBind
Kevin Enderby131d1772015-01-09 19:22:37 +00001567 && !WeakBind
Adrian Prantl437105a2015-07-08 02:04:15 +00001568 && !RawClangAST
Kevin Enderby13023a12015-01-15 23:19:11 +00001569 && !(UniversalHeaders && MachOOpt)
Kevin Enderbya7bdc7e2015-01-22 18:55:27 +00001570 && !(ArchiveHeaders && MachOOpt)
Kevin Enderby69fe98d2015-01-23 18:52:17 +00001571 && !(IndirectSymbols && MachOOpt)
Kevin Enderby9a509442015-01-27 21:28:24 +00001572 && !(DataInCode && MachOOpt)
Kevin Enderbyf6d25852015-01-31 00:37:11 +00001573 && !(LinkOptHints && MachOOpt)
Kevin Enderbycd66be52015-03-11 22:06:32 +00001574 && !(InfoPlist && MachOOpt)
Kevin Enderbybc847fa2015-03-16 20:08:09 +00001575 && !(DylibsUsed && MachOOpt)
1576 && !(DylibId && MachOOpt)
Kevin Enderby0fc11822015-04-01 20:57:01 +00001577 && !(ObjcMetaData && MachOOpt)
Colin LeMahieufcc32762015-07-29 19:08:10 +00001578 && !(FilterSections.size() != 0 && MachOOpt)
Sanjoy Das6f567a42015-06-22 18:03:02 +00001579 && !PrintFaultMaps) {
Michael J. Spencer2670c252011-01-20 06:39:06 +00001580 cl::PrintHelpMessage();
1581 return 2;
1582 }
1583
Michael J. Spencerba4a3622011-10-08 00:18:30 +00001584 std::for_each(InputFilenames.begin(), InputFilenames.end(),
1585 DumpInput);
Michael J. Spencer2670c252011-01-20 06:39:06 +00001586
Davide Italianoccd53fe2015-08-05 07:18:31 +00001587 return EXIT_SUCCESS;
Michael J. Spencer2670c252011-01-20 06:39:06 +00001588}