llvm.org GIT mirror llvm / 0ea2470
[llvm-objdump] Wrap things in namespace llvm git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358417 91177308-0d34-0410-b5e6-96231b3b80d8 Fangrui Song 6 months ago
5 changed file(s) with 110 addition(s) and 116 deletion(s). Raw diff Collapse all Expand all
2323 #include "llvm/Support/WithColor.h"
2424 #include "llvm/Support/raw_ostream.h"
2525
26 using namespace llvm;
27 using namespace object;
26 using namespace llvm::object;
2827 using namespace llvm::Win64EH;
2928
29 namespace llvm {
3030 // Returns the name of the unwind code.
3131 static StringRef getUnwindCodeTypeName(uint8_t Code) {
3232 switch(Code) {
217217 return Error::success();
218218 }
219219
220 static void printCOFFSymbolAddress(llvm::raw_ostream &Out,
220 static void printCOFFSymbolAddress(raw_ostream &Out,
221221 const std::vector &Rels,
222222 uint64_t Offset, uint32_t Disp) {
223223 StringRef Sym;
467467 return false;
468468 }
469469
470 Error llvm::getCOFFRelocationValueString(const COFFObjectFile *Obj,
470 Error getCOFFRelocationValueString(const COFFObjectFile *Obj,
471471 const RelocationRef &Rel,
472472 SmallVectorImpl &Result) {
473473 symbol_iterator SymI = Rel.getSymbol();
588588 printWin64EHUnwindInfo(UI);
589589 }
590590
591 void llvm::printCOFFUnwindInfo(const COFFObjectFile *Obj) {
591 void printCOFFUnwindInfo(const COFFObjectFile *Obj) {
592592 if (Obj->getMachine() != COFF::IMAGE_FILE_MACHINE_AMD64) {
593593 WithColor::error(errs(), "llvm-objdump")
594594 << "unsupported image machine type "
617617 }
618618 }
619619
620 void llvm::printCOFFFileHeader(const object::ObjectFile *Obj) {
620 void printCOFFFileHeader(const object::ObjectFile *Obj) {
621621 const COFFObjectFile *file = dyn_cast(Obj);
622622 printTLSDirectory(file);
623623 printLoadConfiguration(file);
625625 printExportTable(file);
626626 }
627627
628 void llvm::printCOFFSymbolTable(const object::COFFImportFile *i) {
628 void printCOFFSymbolTable(const object::COFFImportFile *i) {
629629 unsigned Index = 0;
630630 bool IsCode = i->getCOFFImportHeader()->getType() == COFF::IMPORT_CODE;
631631
648648 }
649649 }
650650
651 void llvm::printCOFFSymbolTable(const COFFObjectFile *coff) {
651 void printCOFFSymbolTable(const COFFObjectFile *coff) {
652652 for (unsigned SI = 0, SE = coff->getNumberOfSymbols(); SI != SE; ++SI) {
653653 Expected Symbol = coff->getSymbol(SI);
654654 StringRef Name;
719719 }
720720 }
721721 }
722 } // namespace llvm
1717 #include "llvm/Support/MathExtras.h"
1818 #include "llvm/Support/raw_ostream.h"
1919
20 using namespace llvm;
2120 using namespace llvm::object;
2221
23 template
24 Expected getDynamicStrTab(const ELFFile *Elf) {
22 namespace llvm {
23 template
24 static Expected getDynamicStrTab(const ELFFile *Elf) {
2525 auto DynamicEntriesOrError = Elf->dynamicEntries();
2626 if (!DynamicEntriesOrError)
2727 return DynamicEntriesOrError.takeError();
112112 return Error::success();
113113 }
114114
115 Error llvm::getELFRelocationValueString(const ELFObjectFileBase *Obj,
116 const RelocationRef &Rel,
117 SmallVectorImpl &Result) {
115 Error getELFRelocationValueString(const ELFObjectFileBase *Obj,
116 const RelocationRef &Rel,
117 SmallVectorImpl &Result) {
118118 if (auto *ELF32LE = dyn_cast(Obj))
119119 return getRelocationValueString(ELF32LE, Rel, Result);
120120 if (auto *ELF64LE = dyn_cast(Obj))
143143 return Sec.getAddress();
144144 }
145145
146 uint64_t llvm::getELFSectionLMA(const object::ELFSectionRef &Sec) {
146 uint64_t getELFSectionLMA(const object::ELFSectionRef &Sec) {
147147 if (const auto *ELFObj = dyn_cast(Sec.getObject()))
148148 return getSectionLMA(ELFObj->getELFFile(), Sec);
149149 else if (const auto *ELFObj = dyn_cast(Sec.getObject()))
327327 }
328328 }
329329
330 void llvm::printELFFileHeader(const object::ObjectFile *Obj) {
330 void printELFFileHeader(const object::ObjectFile *Obj) {
331331 if (const auto *ELFObj = dyn_cast(Obj))
332332 printProgramHeaders(ELFObj->getELFFile());
333333 else if (const auto *ELFObj = dyn_cast(Obj))
338338 printProgramHeaders(ELFObj->getELFFile());
339339 }
340340
341 void llvm::printELFDynamicSection(const object::ObjectFile *Obj) {
341 void printELFDynamicSection(const object::ObjectFile *Obj) {
342342 if (const auto *ELFObj = dyn_cast(Obj))
343343 printDynamicSection(ELFObj->getELFFile(), Obj->getFileName());
344344 else if (const auto *ELFObj = dyn_cast(Obj))
349349 printDynamicSection(ELFObj->getELFFile(), Obj->getFileName());
350350 }
351351
352 void llvm::printELFSymbolVersionInfo(const object::ObjectFile *Obj) {
352 void printELFSymbolVersionInfo(const object::ObjectFile *Obj) {
353353 if (const auto *ELFObj = dyn_cast(Obj))
354354 printSymbolVersionInfo(ELFObj->getELFFile(), Obj->getFileName());
355355 else if (const auto *ELFObj = dyn_cast(Obj))
359359 else if (const auto *ELFObj = dyn_cast(Obj))
360360 printSymbolVersionInfo(ELFObj->getELFFile(), Obj->getFileName());
361361 }
362 } // namespace llvm
5454 }
5555 #endif
5656
57 using namespace llvm;
58 using namespace object;
57 using namespace llvm::object;
5958
6059 namespace llvm {
6160
165164 static cl::list
166165 ArchFlags("arch", cl::desc("architecture(s) from a Mach-O file to dump"),
167166 cl::ZeroOrMore);
168 } // namespace llvm
169167
170168 bool ArchAll = false;
171169
175173 const char **McpuDefault,
176174 const Target **ThumbTarget) {
177175 // Figure out the target triple.
178 llvm::Triple TT(TripleName);
176 Triple TT(TripleName);
179177 if (TripleName.empty()) {
180178 TT = MachOObj->getArchTriple(McpuDefault);
181179 TripleName = TT.str();
184182 if (TT.getArch() == Triple::arm) {
185183 // We've inferred a 32-bit ARM target from the object file. All MachO CPUs
186184 // that support ARM are also capable of Thumb mode.
187 llvm::Triple ThumbTriple = TT;
185 Triple ThumbTriple = TT;
188186 std::string ThumbName = (Twine("thumb") + TT.getArchName().substr(3)).str();
189187 ThumbTriple.setArchName(ThumbName);
190188 ThumbTripleName = ThumbTriple.str();
444442 Fmt << S;
445443 }
446444
447 Error llvm::getMachORelocationValueString(const MachOObjectFile *Obj,
448 const RelocationRef &RelRef,
449 SmallVectorImpl &Result) {
445 Error getMachORelocationValueString(const MachOObjectFile *Obj,
446 const RelocationRef &RelRef,
447 SmallVectorImpl &Result) {
450448 DataRefImpl Rel = RelRef.getRawDataRefImpl();
451449 MachO::any_relocation_info RE = Obj->getRelocation(Rel);
452450
787785 static void PrintRLength(const uint64_t cputype, const unsigned r_type,
788786 const unsigned r_length, const bool previous_arm_half){
789787 if (cputype == MachO::CPU_TYPE_ARM &&
790 (r_type == llvm::MachO::ARM_RELOC_HALF ||
791 r_type == llvm::MachO::ARM_RELOC_HALF_SECTDIFF ||
792 previous_arm_half == true)) {
788 (r_type == MachO::ARM_RELOC_HALF ||
789 r_type == MachO::ARM_RELOC_HALF_SECTDIFF || previous_arm_half == true)) {
793790 if ((r_length & 0x1) == 0)
794791 outs() << "lo/";
795792 else
850847 if (verbose) {
851848 // scattered: address
852849 if ((cputype == MachO::CPU_TYPE_I386 &&
853 r_type == llvm::MachO::GENERIC_RELOC_PAIR) ||
854 (cputype == MachO::CPU_TYPE_ARM &&
855 r_type == llvm::MachO::ARM_RELOC_PAIR))
850 r_type == MachO::GENERIC_RELOC_PAIR) ||
851 (cputype == MachO::CPU_TYPE_ARM && r_type == MachO::ARM_RELOC_PAIR))
856852 outs() << " ";
857853 else
858854 outs() << format("%08x ", (unsigned int)r_address);
874870 outs() << format("True 0x%08x", (unsigned int)r_value);
875871 if (previous_sectdiff == false) {
876872 if ((cputype == MachO::CPU_TYPE_ARM &&
877 r_type == llvm::MachO::ARM_RELOC_PAIR))
873 r_type == MachO::ARM_RELOC_PAIR))
878874 outs() << format(" half = 0x%04x ", (unsigned int)r_address);
879 }
880 else if (cputype == MachO::CPU_TYPE_ARM &&
881 sectdiff_r_type == llvm::MachO::ARM_RELOC_HALF_SECTDIFF)
875 } else if (cputype == MachO::CPU_TYPE_ARM &&
876 sectdiff_r_type == MachO::ARM_RELOC_HALF_SECTDIFF)
882877 outs() << format(" other_half = 0x%04x ", (unsigned int)r_address);
883878 if ((cputype == MachO::CPU_TYPE_I386 &&
884 (r_type == llvm::MachO::GENERIC_RELOC_SECTDIFF ||
885 r_type == llvm::MachO::GENERIC_RELOC_LOCAL_SECTDIFF)) ||
879 (r_type == MachO::GENERIC_RELOC_SECTDIFF ||
880 r_type == MachO::GENERIC_RELOC_LOCAL_SECTDIFF)) ||
886881 (cputype == MachO::CPU_TYPE_ARM &&
887 (sectdiff_r_type == llvm::MachO::ARM_RELOC_SECTDIFF ||
888 sectdiff_r_type == llvm::MachO::ARM_RELOC_LOCAL_SECTDIFF ||
889 sectdiff_r_type == llvm::MachO::ARM_RELOC_HALF_SECTDIFF))) {
890 previous_sectdiff = true;
891 sectdiff_r_type = r_type;
892 }
893 else {
882 (sectdiff_r_type == MachO::ARM_RELOC_SECTDIFF ||
883 sectdiff_r_type == MachO::ARM_RELOC_LOCAL_SECTDIFF ||
884 sectdiff_r_type == MachO::ARM_RELOC_HALF_SECTDIFF))) {
885 previous_sectdiff = true;
886 sectdiff_r_type = r_type;
887 } else {
894888 previous_sectdiff = false;
895889 sectdiff_r_type = 0;
896890 }
897891 if (cputype == MachO::CPU_TYPE_ARM &&
898 (r_type == llvm::MachO::ARM_RELOC_HALF ||
899 r_type == llvm::MachO::ARM_RELOC_HALF_SECTDIFF))
892 (r_type == MachO::ARM_RELOC_HALF ||
893 r_type == MachO::ARM_RELOC_HALF_SECTDIFF))
900894 previous_arm_half = true;
901895 else
902896 previous_arm_half = false;
912906 else {
913907 if (verbose) {
914908 // plain: address
915 if (cputype == MachO::CPU_TYPE_ARM &&
916 r_type == llvm::MachO::ARM_RELOC_PAIR)
909 if (cputype == MachO::CPU_TYPE_ARM && r_type == MachO::ARM_RELOC_PAIR)
917910 outs() << " ";
918911 else
919912 outs() << format("%08x ", (unsigned int)r_address);
955948 outs() << "False ";
956949
957950 // plain: symbolnum/value
958 if (cputype == MachO::CPU_TYPE_ARM &&
959 r_type == llvm::MachO::ARM_RELOC_PAIR)
951 if (cputype == MachO::CPU_TYPE_ARM && r_type == MachO::ARM_RELOC_PAIR)
960952 outs() << format("other_half = 0x%04x\n", (unsigned int)r_address);
961953 else if (cputype == MachO::CPU_TYPE_ARM64 &&
962 r_type == llvm::MachO::ARM64_RELOC_ADDEND)
954 r_type == MachO::ARM64_RELOC_ADDEND)
963955 outs() << format("addend = 0x%06x\n", (unsigned int)r_symbolnum);
964956 else {
965957 outs() << format("%d ", r_symbolnum);
966 if (r_symbolnum == llvm::MachO::R_ABS)
958 if (r_symbolnum == MachO::R_ABS)
967959 outs() << "R_ABS\n";
968960 else {
969961 // in this case, r_symbolnum is actually a 1-based section number
970962 uint32_t nsects = O->section_end()->getRawDataRefImpl().d.a;
971963 if (r_symbolnum > 0 && r_symbolnum <= nsects) {
972 llvm::object::DataRefImpl DRI;
964 object::DataRefImpl DRI;
973965 DRI.d.a = r_symbolnum-1;
974966 StringRef SegName = O->getSectionFinalSegmentName(DRI);
975967 StringRef SectName;
985977 }
986978 }
987979 if (cputype == MachO::CPU_TYPE_ARM &&
988 (r_type == llvm::MachO::ARM_RELOC_HALF ||
989 r_type == llvm::MachO::ARM_RELOC_HALF_SECTDIFF))
980 (r_type == MachO::ARM_RELOC_HALF ||
981 r_type == MachO::ARM_RELOC_HALF_SECTDIFF))
990982 previous_arm_half = true;
991983 else
992984 previous_arm_half = false;
22232215 // -arch flags selecting just those slices as specified by them and also parses
22242216 // archive files. Then for each individual Mach-O file ProcessMachO() is
22252217 // called to process the file based on the command line options.
2226 void llvm::parseInputMachO(StringRef Filename) {
2218 void parseInputMachO(StringRef Filename) {
22272219 if (!ValidateArchFlags())
22282220 return;
22292221
22792271 llvm_unreachable("Input object can't be invalid at this point");
22802272 }
22812273
2282 void llvm::parseInputMachO(MachOUniversalBinary *UB) {
2274 void parseInputMachO(MachOUniversalBinary *UB) {
22832275 if (!ValidateArchFlags())
22842276 return;
22852277
80047996 }
80057997 }
80067998
8007 void llvm::printMachOUnwindInfo(const MachOObjectFile *Obj) {
7999 void printMachOUnwindInfo(const MachOObjectFile *Obj) {
80088000 std::map Symbols;
80098001 for (const SymbolRef &SymRef : Obj->symbols()) {
80108002 // Discard any undefined or absolute symbols. They're not going to take part
99969988 }
99979989 }
99989990
9999 void llvm::printMachOFileHeader(const object::ObjectFile *Obj) {
9991 void printMachOFileHeader(const object::ObjectFile *Obj) {
100009992 const MachOObjectFile *file = dyn_cast(Obj);
100019993 PrintMachHeader(file, !NonVerbose);
100029994 }
100039995
10004 void llvm::printMachOLoadCommands(const object::ObjectFile *Obj) {
9996 void printMachOLoadCommands(const object::ObjectFile *Obj) {
100059997 const MachOObjectFile *file = dyn_cast(Obj);
100069998 uint32_t filetype = 0;
100079999 uint32_t cputype = 0;
1002310015 // export trie dumping
1002410016 //===----------------------------------------------------------------------===//
1002510017
10026 void llvm::printMachOExportsTrie(const object::MachOObjectFile *Obj) {
10018 void printMachOExportsTrie(const object::MachOObjectFile *Obj) {
1002710019 uint64_t BaseSegmentAddress = 0;
1002810020 for (const auto &Command : Obj->load_commands()) {
1002910021 if (Command.C.cmd == MachO::LC_SEGMENT) {
1004110033 }
1004210034 }
1004310035 Error Err = Error::success();
10044 for (const llvm::object::ExportEntry &Entry : Obj->exports(Err)) {
10036 for (const object::ExportEntry &Entry : Obj->exports(Err)) {
1004510037 uint64_t Flags = Entry.flags();
1004610038 bool ReExport = (Flags & MachO::EXPORT_SYMBOL_FLAGS_REEXPORT);
1004710039 bool WeakDef = (Flags & MachO::EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION);
1010210094 // rebase table dumping
1010310095 //===----------------------------------------------------------------------===//
1010410096
10105 void llvm::printMachORebaseTable(object::MachOObjectFile *Obj) {
10097 void printMachORebaseTable(object::MachOObjectFile *Obj) {
1010610098 outs() << "segment section address type\n";
1010710099 Error Err = Error::success();
10108 for (const llvm::object::MachORebaseEntry &Entry : Obj->rebaseTable(Err)) {
10100 for (const object::MachORebaseEntry &Entry : Obj->rebaseTable(Err)) {
1010910101 StringRef SegmentName = Entry.segmentName();
1011010102 StringRef SectionName = Entry.sectionName();
1011110103 uint64_t Address = Entry.address();
1014410136 // bind table dumping
1014510137 //===----------------------------------------------------------------------===//
1014610138
10147 void llvm::printMachOBindTable(object::MachOObjectFile *Obj) {
10139 void printMachOBindTable(object::MachOObjectFile *Obj) {
1014810140 // Build table of sections so names can used in final output.
1014910141 outs() << "segment section address type "
1015010142 "addend dylib symbol\n";
1015110143 Error Err = Error::success();
10152 for (const llvm::object::MachOBindEntry &Entry : Obj->bindTable(Err)) {
10144 for (const object::MachOBindEntry &Entry : Obj->bindTable(Err)) {
1015310145 StringRef SegmentName = Entry.segmentName();
1015410146 StringRef SectionName = Entry.sectionName();
1015510147 uint64_t Address = Entry.address();
1017510167 // lazy bind table dumping
1017610168 //===----------------------------------------------------------------------===//
1017710169
10178 void llvm::printMachOLazyBindTable(object::MachOObjectFile *Obj) {
10170 void printMachOLazyBindTable(object::MachOObjectFile *Obj) {
1017910171 outs() << "segment section address "
1018010172 "dylib symbol\n";
1018110173 Error Err = Error::success();
10182 for (const llvm::object::MachOBindEntry &Entry : Obj->lazyBindTable(Err)) {
10174 for (const object::MachOBindEntry &Entry : Obj->lazyBindTable(Err)) {
1018310175 StringRef SegmentName = Entry.segmentName();
1018410176 StringRef SectionName = Entry.sectionName();
1018510177 uint64_t Address = Entry.address();
1020010192 // weak bind table dumping
1020110193 //===----------------------------------------------------------------------===//
1020210194
10203 void llvm::printMachOWeakBindTable(object::MachOObjectFile *Obj) {
10195 void printMachOWeakBindTable(object::MachOObjectFile *Obj) {
1020410196 outs() << "segment section address "
1020510197 "type addend symbol\n";
1020610198 Error Err = Error::success();
10207 for (const llvm::object::MachOBindEntry &Entry : Obj->weakBindTable(Err)) {
10199 for (const object::MachOBindEntry &Entry : Obj->weakBindTable(Err)) {
1020810200 // Strong symbols don't have a location to update.
1020910201 if (Entry.flags() & MachO::BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION) {
1021010202 outs() << " strong "
1023710229 if (info->bindtable == nullptr) {
1023810230 info->bindtable = llvm::make_unique();
1023910231 Error Err = Error::success();
10240 for (const llvm::object::MachOBindEntry &Entry : info->O->bindTable(Err)) {
10232 for (const object::MachOBindEntry &Entry : info->O->bindTable(Err)) {
1024110233 uint64_t Address = Entry.address();
1024210234 StringRef name = Entry.symbolName();
1024310235 if (!name.empty())
1025010242 return !name.empty() ? name.data() : nullptr;
1025110243 }
1025210244
10253 void llvm::printLazyBindTable(ObjectFile *o) {
10245 void printLazyBindTable(ObjectFile *o) {
1025410246 outs() << "Lazy bind table:\n";
1025510247 if (MachOObjectFile *MachO = dyn_cast(o))
1025610248 printMachOLazyBindTable(MachO);
1026010252 "for Mach-O executable files.\n";
1026110253 }
1026210254
10263 void llvm::printWeakBindTable(ObjectFile *o) {
10255 void printWeakBindTable(ObjectFile *o) {
1026410256 outs() << "Weak bind table:\n";
1026510257 if (MachOObjectFile *MachO = dyn_cast(o))
1026610258 printMachOWeakBindTable(MachO);
1027010262 "for Mach-O executable files.\n";
1027110263 }
1027210264
10273 void llvm::printExportsTrie(const ObjectFile *o) {
10265 void printExportsTrie(const ObjectFile *o) {
1027410266 outs() << "Exports trie:\n";
1027510267 if (const MachOObjectFile *MachO = dyn_cast(o))
1027610268 printMachOExportsTrie(MachO);
1028010272 "for Mach-O executable files.\n";
1028110273 }
1028210274
10283 void llvm::printRebaseTable(ObjectFile *o) {
10275 void printRebaseTable(ObjectFile *o) {
1028410276 outs() << "Rebase table:\n";
1028510277 if (MachOObjectFile *MachO = dyn_cast(o))
1028610278 printMachORebaseTable(MachO);
1029010282 "for Mach-O executable files.\n";
1029110283 }
1029210284
10293 void llvm::printBindTable(ObjectFile *o) {
10285 void printBindTable(ObjectFile *o) {
1029410286 outs() << "Bind table:\n";
1029510287 if (MachOObjectFile *MachO = dyn_cast(o))
1029610288 printMachOBindTable(MachO);
1029910291 << "This operation is only currently supported "
1030010292 "for Mach-O executable files.\n";
1030110293 }
10294 } // namespace llvm
1313 #include "llvm-objdump.h"
1414 #include "llvm/Object/Wasm.h"
1515
16 using namespace llvm;
17 using namespace object;
16 using namespace llvm::object;
1817
19 void llvm::printWasmFileHeader(const object::ObjectFile *Obj) {
18 namespace llvm {
19 void printWasmFileHeader(const object::ObjectFile *Obj) {
2020 const auto *File = dyn_cast(Obj);
2121
2222 outs() << "Program Header:\n";
2525 outs() << "\n";
2626 }
2727
28 Error llvm::getWasmRelocationValueString(const WasmObjectFile *Obj,
28 Error getWasmRelocationValueString(const WasmObjectFile *Obj,
2929 const RelocationRef &RelRef,
3030 SmallVectorImpl &Result) {
3131 const wasm::WasmRelocation &Rel = Obj->getWasmRelocation(RelRef);
4848 Result.append(FmtBuf.begin(), FmtBuf.end());
4949 return Error::success();
5050 }
51 } // namespace llvm
6666 #include
6767 #include
6868
69 using namespace llvm;
70 using namespace object;
69 using namespace llvm::object;
7170
7271 namespace llvm {
7372
297296 static cl::opt
298297 Wide("wide", cl::desc("Ignored for compatibility with GNU objdump"));
299298 static cl::alias WideShort("w", cl::Grouping, cl::aliasopt(Wide));
300 } // namespace llvm
301299
302300 static StringSet<> DisasmFuncsSet;
303301 static StringRef ToolName;
304302
305303 typedef std::vector> SectionSymbolsTy;
306304
307 SectionFilter llvm::ToolSectionFilter(llvm::object::ObjectFile const &O) {
305 SectionFilter ToolSectionFilter(object::ObjectFile const &O) {
308306 return SectionFilter(
309 [](llvm::object::SectionRef const &S) {
307 [](object::SectionRef const &S) {
310308 if (FilterSections.empty())
311309 return true;
312 llvm::StringRef String;
310 StringRef String;
313311 std::error_code error = S.getName(String);
314312 if (error)
315313 return false;
318316 O);
319317 }
320318
321 void llvm::error(std::error_code EC) {
319 void error(std::error_code EC) {
322320 if (!EC)
323321 return;
324322 WithColor::error(errs(), ToolName)
327325 exit(1);
328326 }
329327
330 void llvm::error(Error E) {
328 void error(Error E) {
331329 if (!E)
332330 return;
333331 WithColor::error(errs(), ToolName) << toString(std::move(E));
334332 exit(1);
335333 }
336334
337 LLVM_ATTRIBUTE_NORETURN void llvm::error(Twine Message) {
335 LLVM_ATTRIBUTE_NORETURN void error(Twine Message) {
338336 WithColor::error(errs(), ToolName) << Message << ".\n";
339337 errs().flush();
340338 exit(1);
341339 }
342340
343 void llvm::warn(StringRef Message) {
341 void warn(StringRef Message) {
344342 WithColor::warning(errs(), ToolName) << Message << ".\n";
345343 errs().flush();
346344 }
347345
348 LLVM_ATTRIBUTE_NORETURN void llvm::report_error(StringRef File,
349 Twine Message) {
346 LLVM_ATTRIBUTE_NORETURN void report_error(StringRef File, Twine Message) {
350347 WithColor::error(errs(), ToolName)
351348 << "'" << File << "': " << Message << ".\n";
352349 exit(1);
353350 }
354351
355 LLVM_ATTRIBUTE_NORETURN void llvm::report_error(Error E, StringRef File) {
352 LLVM_ATTRIBUTE_NORETURN void report_error(Error E, StringRef File) {
356353 assert(E);
357354 std::string Buf;
358355 raw_string_ostream OS(Buf);
362359 exit(1);
363360 }
364361
365 LLVM_ATTRIBUTE_NORETURN void llvm::report_error(Error E, StringRef ArchiveName,
366 StringRef FileName,
367 StringRef ArchitectureName) {
362 LLVM_ATTRIBUTE_NORETURN void report_error(Error E, StringRef ArchiveName,
363 StringRef FileName,
364 StringRef ArchitectureName) {
368365 assert(E);
369366 WithColor::error(errs(), ToolName);
370367 if (ArchiveName != "")
381378 exit(1);
382379 }
383380
384 LLVM_ATTRIBUTE_NORETURN void llvm::report_error(Error E, StringRef ArchiveName,
385 const object::Archive::Child &C,
386 StringRef ArchitectureName) {
381 LLVM_ATTRIBUTE_NORETURN void report_error(Error E, StringRef ArchiveName,
382 const object::Archive::Child &C,
383 StringRef ArchitectureName) {
387384 Expected NameOrErr = C.getName();
388385 // TODO: if we have a error getting the name then it would be nice to print
389386 // the index of which archive member this is and or its offset in the
390387 // archive instead of "???" as the name.
391388 if (!NameOrErr) {
392389 consumeError(NameOrErr.takeError());
393 llvm::report_error(std::move(E), ArchiveName, "???", ArchitectureName);
390 report_error(std::move(E), ArchiveName, "???", ArchitectureName);
394391 } else
395 llvm::report_error(std::move(E), ArchiveName, NameOrErr.get(),
396 ArchitectureName);
392 report_error(std::move(E), ArchiveName, NameOrErr.get(), ArchitectureName);
397393 }
398394
399395 static const Target *getTarget(const ObjectFile *Obj = nullptr) {
400396 // Figure out the target triple.
401 llvm::Triple TheTriple("unknown-unknown-unknown");
397 Triple TheTriple("unknown-unknown-unknown");
402398 if (TripleName.empty()) {
403399 if (Obj)
404400 TheTriple = Obj->makeTriple();
429425 return TheTarget;
430426 }
431427
432 bool llvm::isRelocAddressLess(RelocationRef A, RelocationRef B) {
428 bool isRelocAddressLess(RelocationRef A, RelocationRef B) {
433429 return A.getOffset() < B.getOffset();
434430 }
435431
892888
893889 // Returns a map from sections to their relocations.
894890 static std::map>
895 getRelocsMap(llvm::object::ObjectFile const &Obj) {
891 getRelocsMap(object::ObjectFile const &Obj) {
896892 std::map> Ret;
897893 for (const SectionRef &Section : ToolSectionFilter(Obj)) {
898894 section_iterator RelSec = Section.getRelocatedSection();
14521448 STI.get(), PIP, SP, InlineRelocs);
14531449 }
14541450
1455 void llvm::printRelocations(const ObjectFile *Obj) {
1451 void printRelocations(const ObjectFile *Obj) {
14561452 StringRef Fmt = Obj->getBytesInAddress() > 4 ? "%016" PRIx64 :
14571453 "%08" PRIx64;
14581454 // Regular objdump doesn't print relocations in non-relocatable object
14811477 }
14821478 }
14831479
1484 void llvm::printDynamicRelocations(const ObjectFile *Obj) {
1480 void printDynamicRelocations(const ObjectFile *Obj) {
14851481 // For the moment, this option is for ELF only
14861482 if (!Obj->isELF())
14871483 return;
15251521 return ShowLMA;
15261522 }
15271523
1528 void llvm::printSectionHeaders(const ObjectFile *Obj) {
1524 void printSectionHeaders(const ObjectFile *Obj) {
15291525 bool HasLMAColumn = shouldDisplayLMA(Obj);
15301526 if (HasLMAColumn)
15311527 outs() << "Sections:\n"
15621558 outs() << "\n";
15631559 }
15641560
1565 void llvm::printSectionContents(const ObjectFile *Obj) {
1561 void printSectionContents(const ObjectFile *Obj) {
15661562 for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
15671563 StringRef Name;
15681564 StringRef Contents;
16081604 }
16091605 }
16101606
1611 void llvm::printSymbolTable(const ObjectFile *O, StringRef ArchiveName,
1612 StringRef ArchitectureName) {
1607 void printSymbolTable(const ObjectFile *O, StringRef ArchiveName,
1608 StringRef ArchitectureName) {
16131609 outs() << "SYMBOL TABLE:\n";
16141610
16151611 if (const COFFObjectFile *Coff = dyn_cast(O)) {
17231719
17241720 /// Dump the raw contents of the __clangast section so the output can be piped
17251721 /// into llvm-bcanalyzer.
1726 void llvm::printRawClangAST(const ObjectFile *Obj) {
1722 void printRawClangAST(const ObjectFile *Obj) {
17271723 if (outs().is_displayed()) {
17281724 WithColor::error(errs(), ToolName)
17291725 << "The -raw-clang-ast option will dump the raw binary contents of "
19951991 else
19961992 report_error(errorCodeToError(object_error::invalid_file_type), file);
19971993 }
1994 } // namespace llvm
19981995
19991996 int main(int argc, char **argv) {
1997 using namespace llvm;
20001998 InitLLVM X(argc, argv);
20011999
20022000 // Initialize targets and assembly printers/parsers.
2003 llvm::InitializeAllTargetInfos();
2004 llvm::InitializeAllTargetMCs();
2005 llvm::InitializeAllDisassemblers();
2001 InitializeAllTargetInfos();
2002 InitializeAllTargetMCs();
2003 InitializeAllDisassemblers();
20062004
20072005 // Register the target printer for --version.
20082006 cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion);