llvm.org GIT mirror llvm / 45d116d
[llvm-objdump] - Cleanup the code. NFCI. This is a cosmetic cleanup for the llvm-objdump code. This patch: * Renames things to match the official LLVM code style (lower case -> upper case). * Removes few obviously excessive variables. * Moves a few lines closer to the place of use, reorders the code a bit to simplify it, to avoid doing excessive returns and to avoid using 'else` after returns. I focused only on a llvm-objdump.h/llvm-objdump.cpp files. Few changes in the MachODump.cpp and COFFDump.cpp are a result of llvm-objdump.h modification. Differential revision: https://reviews.llvm.org/D56637 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351171 91177308-0d34-0410-b5e6-96231b3b80d8 George Rimar 7 months ago
4 changed file(s) with 297 addition(s) and 325 deletion(s). Raw diff Collapse all Expand all
454454 Rels.push_back(Reloc);
455455
456456 // Sort relocations by address.
457 llvm::sort(Rels, RelocAddressLess);
457 llvm::sort(Rels, isRelocAddressLess);
458458
459459 ArrayRef Contents;
460460 error(Obj->getSectionContents(Pdata, Contents));
16261626 if (Relocations)
16271627 PrintRelocations(MachOOF, !NonVerbose);
16281628 if (SectionHeaders)
1629 PrintSectionHeaders(MachOOF);
1629 printSectionHeaders(MachOOF);
16301630 if (SectionContents)
1631 PrintSectionContents(MachOOF);
1631 printSectionContents(MachOOF);
16321632 if (!FilterSections.empty())
16331633 DumpSectionContents(FileName, MachOOF, !NonVerbose);
16341634 if (InfoPlist)
16381638 if (DylibId)
16391639 PrintDylibs(MachOOF, true);
16401640 if (SymbolTable)
1641 PrintSymbolTable(MachOOF, ArchiveName, ArchitectureName);
1641 printSymbolTable(MachOOF, ArchiveName, ArchitectureName);
16421642 if (UnwindInfo)
16431643 printMachOUnwindInfo(MachOOF);
16441644 if (PrivateHeaders) {
19581958 // -arch flags selecting just those slices as specified by them and also parses
19591959 // archive files. Then for each individual Mach-O file ProcessMachO() is
19601960 // called to process the file based on the command line options.
1961 void llvm::ParseInputMachO(StringRef Filename) {
1961 void llvm::parseInputMachO(StringRef Filename) {
19621962 if (!ValidateArchFlags())
19631963 return;
19641964
19971997 return;
19981998 }
19991999 if (MachOUniversalBinary *UB = dyn_cast(&Bin)) {
2000 ParseInputMachO(UB);
2000 parseInputMachO(UB);
20012001 return;
20022002 }
20032003 if (ObjectFile *O = dyn_cast(&Bin)) {
20142014 llvm_unreachable("Input object can't be invalid at this point");
20152015 }
20162016
2017 void llvm::ParseInputMachO(MachOUniversalBinary *UB) {
2017 void llvm::parseInputMachO(MachOUniversalBinary *UB) {
20182018 if (!ValidateArchFlags())
20192019 return;
20202020
429429 // Figure out the target triple.
430430 llvm::Triple TheTriple("unknown-unknown-unknown");
431431 if (TripleName.empty()) {
432 if (Obj) {
432 if (Obj)
433433 TheTriple = Obj->makeTriple();
434 }
435434 } else {
436435 TheTriple.setTriple(Triple::normalize(TripleName));
437436
438437 // Use the triple, but also try to combine with ARM build attributes.
439438 if (Obj) {
440439 auto Arch = Obj->getArch();
441 if (Arch == Triple::arm || Arch == Triple::armeb) {
440 if (Arch == Triple::arm || Arch == Triple::armeb)
442441 Obj->setARMSubArch(TheTriple);
443 }
444442 }
445443 }
446444
460458 return TheTarget;
461459 }
462460
463 bool llvm::RelocAddressLess(RelocationRef a, RelocationRef b) {
464 return a.getOffset() < b.getOffset();
461 bool llvm::isRelocAddressLess(RelocationRef A, RelocationRef B) {
462 return A.getOffset() < B.getOffset();
465463 }
466464
467465 static std::string demangle(StringRef Name) {
483481 static std::error_code getRelocationValueString(const ELFObjectFile *Obj,
484482 const RelocationRef &RelRef,
485483 SmallVectorImpl &Result) {
486 DataRefImpl Rel = RelRef.getRawDataRefImpl();
487
488484 typedef typename ELFObjectFile::Elf_Sym Elf_Sym;
489485 typedef typename ELFObjectFile::Elf_Shdr Elf_Shdr;
490486 typedef typename ELFObjectFile::Elf_Rela Elf_Rela;
491487
492488 const ELFFile &EF = *Obj->getELFFile();
493
489 DataRefImpl Rel = RelRef.getRawDataRefImpl();
494490 auto SecOrErr = EF.getSection(Rel.d.a);
495491 if (!SecOrErr)
496492 return errorToErrorCode(SecOrErr.takeError());
508504 if (!StrTabOrErr)
509505 return errorToErrorCode(StrTabOrErr.takeError());
510506 StringRef StrTab = *StrTabOrErr;
511 int64_t addend = 0;
507 int64_t Addend = 0;
512508 // If there is no Symbol associated with the relocation, we set the undef
513509 // boolean value to 'true'. This will prevent us from calling functions that
514510 // requires the relocation to be associated with a symbol.
515 bool undef = false;
511 bool Undef = false;
516512 switch (Sec->sh_type) {
517513 default:
518514 return object_error::parse_failed;
522518 }
523519 case ELF::SHT_RELA: {
524520 const Elf_Rela *ERela = Obj->getRela(Rel);
525 addend = ERela->r_addend;
526 undef = ERela->getSymbol(false) == 0;
521 Addend = ERela->r_addend;
522 Undef = ERela->getSymbol(false) == 0;
527523 break;
528524 }
529525 }
530526 std::string Target;
531 if (!undef) {
527 if (!Undef) {
532528 symbol_iterator SI = RelRef.getSymbol();
533529 const Elf_Sym *symb = Obj->getSymbol(SI->getRawDataRefImpl());
534530 if (symb->getType() == ELF::STT_SECTION) {
554550
555551 // Default scheme is to print Target, as well as "+ " for nonzero
556552 // addend. Should be acceptable for all normal purposes.
557 std::string fmtbuf;
558 raw_string_ostream fmt(fmtbuf);
559 fmt << Target;
560 if (addend != 0)
561 fmt << (addend < 0 ? "" : "+") << addend;
562 fmt.flush();
563 Result.append(fmtbuf.begin(), fmtbuf.end());
553 std::string FmtBuf;
554 raw_string_ostream Fmt(FmtBuf);
555 Fmt << Target;
556 if (Addend != 0)
557 Fmt << (Addend < 0 ? "" : "+") << Addend;
558 Fmt.flush();
559 Result.append(FmtBuf.begin(), FmtBuf.end());
564560 return std::error_code();
565561 }
566562
591587
592588 static void printRelocationTargetName(const MachOObjectFile *O,
593589 const MachO::any_relocation_info &RE,
594 raw_string_ostream &fmt) {
595 bool IsScattered = O->isRelocationScattered(RE);
596
590 raw_string_ostream &Fmt) {
597591 // Target of a scattered relocation is an address. In the interest of
598592 // generating pretty output, scan through the symbol table looking for a
599593 // symbol that aligns with that address. If we find one, print it.
600594 // Otherwise, we just print the hex address of the target.
601 if (IsScattered) {
595 if (O->isRelocationScattered(RE)) {
602596 uint32_t Val = O->getPlainRelocationSymbolNum(RE);
603597
604598 for (const SymbolRef &Symbol : O->symbols()) {
605 std::error_code ec;
606599 Expected Addr = Symbol.getAddress();
607600 if (!Addr)
608601 report_error(O->getFileName(), Addr.takeError());
611604 Expected Name = Symbol.getName();
612605 if (!Name)
613606 report_error(O->getFileName(), Name.takeError());
614 fmt << *Name;
607 Fmt << *Name;
615608 return;
616609 }
617610
626619 continue;
627620 if ((ec = Section.getName(Name)))
628621 report_error(O->getFileName(), ec);
629 fmt << Name;
622 Fmt << Name;
630623 return;
631624 }
632625
633 fmt << format("0x%x", Val);
626 Fmt << format("0x%x", Val);
634627 return;
635628 }
636629
639632 uint64_t Val = O->getPlainRelocationSymbolNum(RE);
640633
641634 if (O->getAnyRelocationType(RE) == MachO::ARM64_RELOC_ADDEND) {
642 fmt << format("0x%0" PRIx64, Val);
635 Fmt << format("0x%0" PRIx64, Val);
643636 return;
644 } else if (isExtern) {
637 }
638
639 if (isExtern) {
645640 symbol_iterator SI = O->symbol_begin();
646641 advance(SI, Val);
647642 Expected SOrErr = SI->getName();
652647 section_iterator SI = O->section_begin();
653648 // Adjust for the fact that sections are 1-indexed.
654649 if (Val == 0) {
655 fmt << "0 (?,?)";
650 Fmt << "0 (?,?)";
656651 return;
657652 }
658 uint32_t i = Val - 1;
659 while (i != 0 && SI != O->section_end()) {
660 i--;
653 uint32_t I = Val - 1;
654 while (I != 0 && SI != O->section_end()) {
655 --I;
661656 advance(SI, 1);
662657 }
663658 if (SI == O->section_end())
664 fmt << Val << " (?,?)";
659 Fmt << Val << " (?,?)";
665660 else
666661 SI->getName(S);
667662 }
668663
669 fmt << S;
664 Fmt << S;
670665 }
671666
672667 static std::error_code getRelocationValueString(const WasmObjectFile *Obj,
674669 SmallVectorImpl &Result) {
675670 const wasm::WasmRelocation& Rel = Obj->getWasmRelocation(RelRef);
676671 symbol_iterator SI = RelRef.getSymbol();
677 std::string fmtbuf;
678 raw_string_ostream fmt(fmtbuf);
672 std::string FmtBuf;
673 raw_string_ostream Fmt(FmtBuf);
679674 if (SI == Obj->symbol_end()) {
680675 // Not all wasm relocations have symbols associated with them.
681676 // In particular R_WEBASSEMBLY_TYPE_INDEX_LEB.
682 fmt << Rel.Index;
677 Fmt << Rel.Index;
683678 } else {
684679 Expected SymNameOrErr = SI->getName();
685680 if (!SymNameOrErr)
687682 StringRef SymName = *SymNameOrErr;
688683 Result.append(SymName.begin(), SymName.end());
689684 }
690 fmt << (Rel.Addend < 0 ? "" : "+") << Rel.Addend;
691 fmt.flush();
692 Result.append(fmtbuf.begin(), fmtbuf.end());
685 Fmt << (Rel.Addend < 0 ? "" : "+") << Rel.Addend;
686 Fmt.flush();
687 Result.append(FmtBuf.begin(), FmtBuf.end());
693688 return std::error_code();
694689 }
695690
701696
702697 unsigned Arch = Obj->getArch();
703698
704 std::string fmtbuf;
705 raw_string_ostream fmt(fmtbuf);
699 std::string FmtBuf;
700 raw_string_ostream Fmt(FmtBuf);
706701 unsigned Type = Obj->getAnyRelocationType(RE);
707702 bool IsPCRel = Obj->getAnyRelocationPCRel(RE);
708703
711706
712707 // X86_64 has entirely custom relocation types.
713708 if (Arch == Triple::x86_64) {
714 bool isPCRel = Obj->getAnyRelocationPCRel(RE);
715
716709 switch (Type) {
717710 case MachO::X86_64_RELOC_GOT_LOAD:
718711 case MachO::X86_64_RELOC_GOT: {
719 printRelocationTargetName(Obj, RE, fmt);
720 fmt << "@GOT";
721 if (isPCRel)
722 fmt << "PCREL";
712 printRelocationTargetName(Obj, RE, Fmt);
713 Fmt << "@GOT";
714 if (IsPCRel)
715 Fmt << "PCREL";
723716 break;
724717 }
725718 case MachO::X86_64_RELOC_SUBTRACTOR: {
737730
738731 // The X86_64_RELOC_UNSIGNED contains the minuend symbol;
739732 // X86_64_RELOC_SUBTRACTOR contains the subtrahend.
740 printRelocationTargetName(Obj, RENext, fmt);
741 fmt << "-";
742 printRelocationTargetName(Obj, RE, fmt);
733 printRelocationTargetName(Obj, RENext, Fmt);
734 Fmt << "-";
735 printRelocationTargetName(Obj, RE, Fmt);
743736 break;
744737 }
745738 case MachO::X86_64_RELOC_TLV:
746 printRelocationTargetName(Obj, RE, fmt);
747 fmt << "@TLV";
748 if (isPCRel)
749 fmt << "P";
739 printRelocationTargetName(Obj, RE, Fmt);
740 Fmt << "@TLV";
741 if (IsPCRel)
742 Fmt << "P";
750743 break;
751744 case MachO::X86_64_RELOC_SIGNED_1:
752 printRelocationTargetName(Obj, RE, fmt);
753 fmt << "-1";
745 printRelocationTargetName(Obj, RE, Fmt);
746 Fmt << "-1";
754747 break;
755748 case MachO::X86_64_RELOC_SIGNED_2:
756 printRelocationTargetName(Obj, RE, fmt);
757 fmt << "-2";
749 printRelocationTargetName(Obj, RE, Fmt);
750 Fmt << "-2";
758751 break;
759752 case MachO::X86_64_RELOC_SIGNED_4:
760 printRelocationTargetName(Obj, RE, fmt);
761 fmt << "-4";
753 printRelocationTargetName(Obj, RE, Fmt);
754 Fmt << "-4";
762755 break;
763756 default:
764 printRelocationTargetName(Obj, RE, fmt);
757 printRelocationTargetName(Obj, RE, Fmt);
765758 break;
766759 }
767760 // X86 and ARM share some relocation types in common.
784777 report_error(Obj->getFileName(), "Expected GENERIC_RELOC_PAIR after "
785778 "GENERIC_RELOC_SECTDIFF.");
786779
787 printRelocationTargetName(Obj, RE, fmt);
788 fmt << "-";
789 printRelocationTargetName(Obj, RENext, fmt);
780 printRelocationTargetName(Obj, RE, Fmt);
781 Fmt << "-";
782 printRelocationTargetName(Obj, RENext, Fmt);
790783 break;
791784 }
792785 }
805798 report_error(Obj->getFileName(), "Expected GENERIC_RELOC_PAIR after "
806799 "GENERIC_RELOC_LOCAL_SECTDIFF.");
807800
808 printRelocationTargetName(Obj, RE, fmt);
809 fmt << "-";
810 printRelocationTargetName(Obj, RENext, fmt);
801 printRelocationTargetName(Obj, RE, Fmt);
802 Fmt << "-";
803 printRelocationTargetName(Obj, RENext, Fmt);
811804 break;
812805 }
813806 case MachO::GENERIC_RELOC_TLV: {
814 printRelocationTargetName(Obj, RE, fmt);
815 fmt << "@TLV";
807 printRelocationTargetName(Obj, RE, Fmt);
808 Fmt << "@TLV";
816809 if (IsPCRel)
817 fmt << "P";
810 Fmt << "P";
818811 break;
819812 }
820813 default:
821 printRelocationTargetName(Obj, RE, fmt);
814 printRelocationTargetName(Obj, RE, Fmt);
822815 }
823816 } else { // ARM-specific relocations
824817 switch (Type) {
829822 bool isUpper = (Obj->getAnyRelocationLength(RE) & 0x1) == 1;
830823
831824 if (isUpper)
832 fmt << ":upper16:(";
825 Fmt << ":upper16:(";
833826 else
834 fmt << ":lower16:(";
835 printRelocationTargetName(Obj, RE, fmt);
827 Fmt << ":lower16:(";
828 printRelocationTargetName(Obj, RE, Fmt);
836829
837830 DataRefImpl RelNext = Rel;
838831 Obj->moveRelocationNext(RelNext);
853846 // ARM_RELOC_HALF_SECTDIFF encodes the second section in the
854847 // symbol/section pointer of the follow-on relocation.
855848 if (Type == MachO::ARM_RELOC_HALF_SECTDIFF) {
856 fmt << "-";
857 printRelocationTargetName(Obj, RENext, fmt);
849 Fmt << "-";
850 printRelocationTargetName(Obj, RENext, Fmt);
858851 }
859852
860 fmt << ")";
853 Fmt << ")";
861854 break;
862855 }
863 default: { printRelocationTargetName(Obj, RE, fmt); }
856 default: { printRelocationTargetName(Obj, RE, Fmt); }
864857 }
865858 }
866859 } else
867 printRelocationTargetName(Obj, RE, fmt);
868
869 fmt.flush();
870 Result.append(fmtbuf.begin(), fmtbuf.end());
860 printRelocationTargetName(Obj, RE, Fmt);
861
862 Fmt.flush();
863 Result.append(FmtBuf.begin(), FmtBuf.end());
871864 return std::error_code();
872865 }
873866
889882 /// relocations, usually because it is the trailing part of a multipart
890883 /// relocation that will be printed as part of the leading relocation.
891884 static bool getHidden(RelocationRef RelRef) {
892 const ObjectFile *Obj = RelRef.getObject();
893 auto *MachO = dyn_cast(Obj);
885 auto *MachO = dyn_cast(RelRef.getObject());
894886 if (!MachO)
895887 return false;
896888
900892
901893 // On arches that use the generic relocations, GENERIC_RELOC_PAIR
902894 // is always hidden.
903 if (Arch == Triple::x86 || Arch == Triple::arm || Arch == Triple::ppc) {
904 if (Type == MachO::GENERIC_RELOC_PAIR)
905 return true;
906 } else if (Arch == Triple::x86_64) {
895 if (Arch == Triple::x86 || Arch == Triple::arm || Arch == Triple::ppc)
896 return Type == MachO::GENERIC_RELOC_PAIR;
897
898 if (Arch == Triple::x86_64) {
907899 // On x86_64, X86_64_RELOC_UNSIGNED is hidden only when it follows
908900 // an X86_64_RELOC_SUBTRACTOR.
909901 if (Type == MachO::X86_64_RELOC_UNSIGNED && Rel.d.a > 0) {
10781070 auto Preamble = " { ";
10791071 auto Separator = "";
10801072 StringRef Fmt = "\t\t\t%08" PRIx64 ": ";
1081 std::vector::const_iterator rel_cur = Rels->begin();
1082 std::vector::const_iterator rel_end = Rels->end();
1073 std::vector::const_iterator RelCur = Rels->begin();
1074 std::vector::const_iterator RelEnd = Rels->end();
10831075
10841076 // Hexagon's packets require relocations to be inline rather than
10851077 // clustered at the end of the packet.
10861078 auto PrintReloc = [&]() -> void {
1087 while ((rel_cur != rel_end) && (rel_cur->getOffset() <= Address)) {
1088 if (rel_cur->getOffset() == Address) {
1089 SmallString<16> name;
1090 SmallString<32> val;
1091 rel_cur->getTypeName(name);
1092 error(getRelocationValueString(*rel_cur, val));
1093 OS << Separator << format(Fmt.data(), Address) << name << "\t" << val
1079 while ((RelCur != RelEnd) && (RelCur->getOffset() <= Address)) {
1080 if (RelCur->getOffset() == Address) {
1081 SmallString<16> Name;
1082 SmallString<32> Val;
1083 RelCur->getTypeName(Name);
1084 error(getRelocationValueString(*RelCur, Val));
1085 OS << Separator << format(Fmt.data(), Address) << Name << "\t" << Val
10941086 << "\n";
10951087 return;
10961088 }
1097 rel_cur++;
1089 ++RelCur;
10981090 }
10991091 };
11001092
1101 while(!HeadTail.first.empty()) {
1093 while (!HeadTail.first.empty()) {
11021094 OS << Separator;
11031095 Separator = "\n";
11041096 if (SP && (PrintSource || PrintLines))
11081100 Preamble = " ";
11091101 StringRef Inst;
11101102 auto Duplex = HeadTail.first.split('\v');
1111 if(!Duplex.second.empty()){
1103 if (!Duplex.second.empty()) {
11121104 OS << Duplex.first;
11131105 OS << "; ";
11141106 Inst = Duplex.second;
12401232 Expected AddressOrErr = Symbol.getAddress();
12411233 if (!AddressOrErr)
12421234 report_error(Obj->getFileName(), AddressOrErr.takeError());
1243 uint64_t Address = *AddressOrErr;
12441235
12451236 Expected Name = Symbol.getName();
12461237 if (!Name)
12551246 if (SecI == Obj->section_end())
12561247 continue;
12571248
1258 AllSymbols[*SecI].emplace_back(Address, *Name, SymbolType);
1249 AllSymbols[*SecI].emplace_back(*AddressOrErr, *Name, SymbolType);
12591250 }
12601251 }
12611252
12911282 if (auto *ElfObj = dyn_cast(Obj)) {
12921283 for (auto PltEntry : ElfObj->getPltAddresses()) {
12931284 SymbolRef Symbol(PltEntry.first, ElfObj);
1294
12951285 uint8_t SymbolType = getElfSymbolType(Obj, Symbol);
12961286
12971287 Expected NameOrErr = Symbol.getName();
13291319 return N & ~0x3;
13301320 }
13311321
1332 static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
1322 static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
13331323 if (StartAddress > StopAddress)
13341324 error("Start address should be less than stop address");
13351325
13371327
13381328 // Package up features to be passed to target/subtarget
13391329 SubtargetFeatures Features = Obj->getFeatures();
1340 if (!MAttrs.empty()) {
1341 for (unsigned i = 0; i != MAttrs.size(); ++i)
1342 Features.AddFeature(MAttrs[i]);
1343 }
1330 if (!MAttrs.empty())
1331 for (unsigned I = 0; I != MAttrs.size(); ++I)
1332 Features.AddFeature(MAttrs[I]);
13441333
13451334 std::unique_ptr MRI(
13461335 TheTarget->createMCRegInfo(TripleName));
15351524 }
15361525
15371526 // Sort relocations by address.
1538 llvm::sort(Rels, RelocAddressLess);
1527 llvm::sort(Rels, isRelocAddressLess);
15391528
15401529 StringRef SegmentName = "";
15411530 if (const MachOObjectFile *MachO = dyn_cast(Obj)) {
15651554 uint64_t Index;
15661555 bool PrintedSection = false;
15671556
1568 std::vector::const_iterator rel_cur = Rels.begin();
1569 std::vector::const_iterator rel_end = Rels.end();
1557 std::vector::const_iterator RelCur = Rels.begin();
1558 std::vector::const_iterator RelEnd = Rels.end();
15701559 // Disassemble symbol by symbol.
1571 for (unsigned si = 0, se = Symbols.size(); si != se; ++si) {
1572 uint64_t Start = std::get<0>(Symbols[si]) - SectionAddr;
1560 for (unsigned SI = 0, SE = Symbols.size(); SI != SE; ++SI) {
1561 uint64_t Start = std::get<0>(Symbols[SI]) - SectionAddr;
15731562 // The end is either the section end or the beginning of the next
15741563 // symbol.
1575 uint64_t End =
1576 (si == se - 1) ? SectSize : std::get<0>(Symbols[si + 1]) - SectionAddr;
1564 uint64_t End = (SI == SE - 1)
1565 ? SectSize
1566 : std::get<0>(Symbols[SI + 1]) - SectionAddr;
15771567 // Don't try to disassemble beyond the end of section contents.
15781568 if (End > SectSize)
15791569 End = SectSize;
15901580
15911581 /// Skip if user requested specific symbols and this is not in the list
15921582 if (!DisasmFuncsSet.empty() &&
1593 !DisasmFuncsSet.count(std::get<1>(Symbols[si])))
1583 !DisasmFuncsSet.count(std::get<1>(Symbols[SI])))
15941584 continue;
15951585
15961586 if (!PrintedSection) {
16061596 End = StopAddress - SectionAddr;
16071597
16081598 if (Obj->isELF() && Obj->getArch() == Triple::amdgcn) {
1609 if (std::get<2>(Symbols[si]) == ELF::STT_AMDGPU_HSA_KERNEL) {
1599 if (std::get<2>(Symbols[SI]) == ELF::STT_AMDGPU_HSA_KERNEL) {
16101600 // skip amd_kernel_code_t at the begining of kernel symbol (256 bytes)
16111601 Start += 256;
16121602 }
1613 if (si == se - 1 ||
1614 std::get<2>(Symbols[si + 1]) == ELF::STT_AMDGPU_HSA_KERNEL) {
1603 if (SI == SE - 1 ||
1604 std::get<2>(Symbols[SI + 1]) == ELF::STT_AMDGPU_HSA_KERNEL) {
16151605 // cut trailing zeroes at the end of kernel
16161606 // cut up to 256 bytes
16171607 const uint64_t EndAlign = 256;
16261616 if (!NoLeadingAddr)
16271617 outs() << format("%016" PRIx64 " ", SectionAddr + Start);
16281618
1629 StringRef SymbolName = std::get<1>(Symbols[si]);
1619 StringRef SymbolName = std::get<1>(Symbols[SI]);
16301620 if (Demangle)
16311621 outs() << demangle(SymbolName) << ":\n";
16321622 else
16581648 // same section. We rely on the markers introduced to
16591649 // understand what we need to dump. If the data marker is within a
16601650 // function, it is denoted as a word/short etc
1661 if (isArmElf(Obj) && std::get<2>(Symbols[si]) != ELF::STT_OBJECT &&
1651 if (isArmElf(Obj) && std::get<2>(Symbols[SI]) != ELF::STT_OBJECT &&
16621652 !DisassembleAll) {
16631653 uint64_t Stride = 0;
16641654
17221712 // disassembling text (applicable all architectures),
17231713 // we are in a situation where we must print the data and not
17241714 // disassemble it.
1725 if (Obj->isELF() && std::get<2>(Symbols[si]) == ELF::STT_OBJECT &&
1715 if (Obj->isELF() && std::get<2>(Symbols[SI]) == ELF::STT_OBJECT &&
17261716 !DisassembleAll && Section.isText()) {
17271717 // print out data up to 8 bytes at a time in hex and ascii
17281718 uint8_t AsciiData[9] = {'\0'};
18491839 // Hexagon does this in pretty printer
18501840 if (Obj->getArch() != Triple::hexagon)
18511841 // Print relocation for instruction.
1852 while (rel_cur != rel_end) {
1853 bool hidden = getHidden(*rel_cur);
1854 uint64_t addr = rel_cur->getOffset();
1855 SmallString<16> name;
1856 SmallString<32> val;
1842 while (RelCur != RelEnd) {
1843 uint64_t Addr = RelCur->getOffset();
1844 SmallString<16> Name;
1845 SmallString<32> Val;
18571846
18581847 // If this relocation is hidden, skip it.
1859 if (hidden || ((SectionAddr + addr) < StartAddress)) {
1860 ++rel_cur;
1848 if (getHidden(*RelCur) || ((SectionAddr + Addr) < StartAddress)) {
1849 ++RelCur;
18611850 continue;
18621851 }
18631852
18641853 // Stop when rel_cur's address is past the current instruction.
1865 if (addr >= Index + Size) break;
1866 rel_cur->getTypeName(name);
1867 error(getRelocationValueString(*rel_cur, val));
1868 outs() << format(Fmt.data(), SectionAddr + addr) << name
1869 << "\t" << val << "\n";
1870 ++rel_cur;
1854 if (Addr >= Index + Size)
1855 break;
1856 RelCur->getTypeName(Name);
1857 error(getRelocationValueString(*RelCur, Val));
1858 outs() << format(Fmt.data(), SectionAddr + Addr) << Name << "\t"
1859 << Val << "\n";
1860 ++RelCur;
18711861 }
18721862 }
18731863 }
18741864 }
18751865 }
18761866
1877 void llvm::PrintRelocations(const ObjectFile *Obj) {
1867 void llvm::printRelocations(const ObjectFile *Obj) {
18781868 StringRef Fmt = Obj->getBytesInAddress() > 4 ? "%016" PRIx64 :
18791869 "%08" PRIx64;
18801870 // Regular objdump doesn't print relocations in non-relocatable object
18851875 for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
18861876 if (Section.relocation_begin() == Section.relocation_end())
18871877 continue;
1888 StringRef secname;
1889 error(Section.getName(secname));
1890 outs() << "RELOCATION RECORDS FOR [" << secname << "]:\n";
1878 StringRef SecName;
1879 error(Section.getName(SecName));
1880 outs() << "RELOCATION RECORDS FOR [" << SecName << "]:\n";
18911881 for (const RelocationRef &Reloc : Section.relocations()) {
1892 bool hidden = getHidden(Reloc);
1893 uint64_t address = Reloc.getOffset();
1894 SmallString<32> relocname;
1895 SmallString<32> valuestr;
1896 if (address < StartAddress || address > StopAddress || hidden)
1882 uint64_t Address = Reloc.getOffset();
1883 SmallString<32> RelocName;
1884 SmallString<32> ValueStr;
1885 if (Address < StartAddress || Address > StopAddress || getHidden(Reloc))
18971886 continue;
1898 Reloc.getTypeName(relocname);
1899 error(getRelocationValueString(Reloc, valuestr));
1900 outs() << format(Fmt.data(), address) << " " << relocname << " "
1901 << valuestr << "\n";
1887 Reloc.getTypeName(RelocName);
1888 error(getRelocationValueString(Reloc, ValueStr));
1889 outs() << format(Fmt.data(), Address) << " " << RelocName << " "
1890 << ValueStr << "\n";
19021891 }
19031892 outs() << "\n";
19041893 }
19051894 }
19061895
1907 void llvm::PrintDynamicRelocations(const ObjectFile *Obj) {
1908
1896 void llvm::printDynamicRelocations(const ObjectFile *Obj) {
19091897 // For the moment, this option is for ELF only
19101898 if (!Obj->isELF())
19111899 return;
19121900
19131901 const auto *Elf = dyn_cast(Obj);
1914
19151902 if (!Elf || Elf->getEType() != ELF::ET_DYN) {
19161903 error("not a dynamic object");
19171904 return;
19181905 }
19191906
1920 StringRef Fmt = Obj->getBytesInAddress() > 4 ? "%016" PRIx64 : "%08" PRIx64;
1921
19221907 std::vector DynRelSec = Obj->dynamic_relocation_sections();
19231908 if (DynRelSec.empty())
19241909 return;
19251910
19261911 outs() << "DYNAMIC RELOCATION RECORDS\n";
1912 StringRef Fmt = Obj->getBytesInAddress() > 4 ? "%016" PRIx64 : "%08" PRIx64;
19271913 for (const SectionRef &Section : DynRelSec) {
19281914 if (Section.relocation_begin() == Section.relocation_end())
19291915 continue;
19301916 for (const RelocationRef &Reloc : Section.relocations()) {
1931 uint64_t address = Reloc.getOffset();
1932 SmallString<32> relocname;
1933 SmallString<32> valuestr;
1934 Reloc.getTypeName(relocname);
1935 error(getRelocationValueString(Reloc, valuestr));
1936 outs() << format(Fmt.data(), address) << " " << relocname << " "
1937 << valuestr << "\n";
1938 }
1939 }
1940 }
1941
1942 void llvm::PrintSectionHeaders(const ObjectFile *Obj) {
1917 uint64_t Address = Reloc.getOffset();
1918 SmallString<32> RelocName;
1919 SmallString<32> ValueStr;
1920 Reloc.getTypeName(RelocName);
1921 error(getRelocationValueString(Reloc, ValueStr));
1922 outs() << format(Fmt.data(), Address) << " " << RelocName << " "
1923 << ValueStr << "\n";
1924 }
1925 }
1926 }
1927
1928 void llvm::printSectionHeaders(const ObjectFile *Obj) {
19431929 outs() << "Sections:\n"
19441930 "Idx Name Size Address Type\n";
19451931 for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
19591945 outs() << "\n";
19601946 }
19611947
1962 void llvm::PrintSectionContents(const ObjectFile *Obj) {
1948 void llvm::printSectionContents(const ObjectFile *Obj) {
19631949 std::error_code EC;
19641950 for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
19651951 StringRef Name;
19811967 error(Section.getContents(Contents));
19821968
19831969 // Dump out the content as hex and printable ascii characters.
1984 for (std::size_t addr = 0, end = Contents.size(); addr < end; addr += 16) {
1985 outs() << format(" %04" PRIx64 " ", BaseAddr + addr);
1970 for (std::size_t Addr = 0, End = Contents.size(); Addr < End; Addr += 16) {
1971 outs() << format(" %04" PRIx64 " ", BaseAddr + Addr);
19861972 // Dump line of hex.
1987 for (std::size_t i = 0; i < 16; ++i) {
1988 if (i != 0 && i % 4 == 0)
1973 for (std::size_t I = 0; I < 16; ++I) {
1974 if (I != 0 && I % 4 == 0)
19891975 outs() << ' ';
1990 if (addr + i < end)
1991 outs() << hexdigit((Contents[addr + i] >> 4) & 0xF, true)
1992 << hexdigit(Contents[addr + i] & 0xF, true);
1976 if (Addr + I < End)
1977 outs() << hexdigit((Contents[Addr + I] >> 4) & 0xF, true)
1978 << hexdigit(Contents[Addr + I] & 0xF, true);
19931979 else
19941980 outs() << " ";
19951981 }
19961982 // Print ascii.
19971983 outs() << " ";
1998 for (std::size_t i = 0; i < 16 && addr + i < end; ++i) {
1999 if (isPrint(static_cast(Contents[addr + i]) & 0xFF))
2000 outs() << Contents[addr + i];
1984 for (std::size_t I = 0; I < 16 && Addr + I < End; ++I) {
1985 if (isPrint(static_cast(Contents[Addr + I]) & 0xFF))
1986 outs() << Contents[Addr + I];
20011987 else
20021988 outs() << ".";
20031989 }
20061992 }
20071993 }
20081994
2009 void llvm::PrintSymbolTable(const ObjectFile *o, StringRef ArchiveName,
1995 void llvm::printSymbolTable(const ObjectFile *O, StringRef ArchiveName,
20101996 StringRef ArchitectureName) {
20111997 outs() << "SYMBOL TABLE:\n";
20121998
2013 if (const COFFObjectFile *coff = dyn_cast(o)) {
2014 printCOFFSymbolTable(coff);
1999 if (const COFFObjectFile *Coff = dyn_cast(O)) {
2000 printCOFFSymbolTable(Coff);
20152001 return;
20162002 }
20172003
2018 for (auto I = o->symbol_begin(), E = o->symbol_end(); I != E; ++I) {
2004 for (auto I = O->symbol_begin(), E = O->symbol_end(); I != E; ++I) {
20192005 // Skip printing the special zero symbol when dumping an ELF file.
20202006 // This makes the output consistent with the GNU objdump.
2021 if (I == o->symbol_begin() && isa(o))
2007 if (I == O->symbol_begin() && isa(O))
20222008 continue;
20232009
20242010 const SymbolRef &Symbol = *I;
20252011 Expected AddressOrError = Symbol.getAddress();
20262012 if (!AddressOrError)
2027 report_error(ArchiveName, o->getFileName(), AddressOrError.takeError(),
2013 report_error(ArchiveName, O->getFileName(), AddressOrError.takeError(),
20282014 ArchitectureName);
20292015 uint64_t Address = *AddressOrError;
20302016 if ((Address < StartAddress) || (Address > StopAddress))
20312017 continue;
20322018 Expected TypeOrError = Symbol.getType();
20332019 if (!TypeOrError)
2034 report_error(ArchiveName, o->getFileName(), TypeOrError.takeError(),
2020 report_error(ArchiveName, O->getFileName(), TypeOrError.takeError(),
20352021 ArchitectureName);
20362022 SymbolRef::Type Type = *TypeOrError;
20372023 uint32_t Flags = Symbol.getFlags();
20382024 Expected SectionOrErr = Symbol.getSection();
20392025 if (!SectionOrErr)
2040 report_error(ArchiveName, o->getFileName(), SectionOrErr.takeError(),
2026 report_error(ArchiveName, O->getFileName(), SectionOrErr.takeError(),
20412027 ArchitectureName);
20422028 section_iterator Section = *SectionOrErr;
20432029 StringRef Name;
2044 if (Type == SymbolRef::ST_Debug && Section != o->section_end()) {
2030 if (Type == SymbolRef::ST_Debug && Section != O->section_end()) {
20452031 Section->getName(Name);
20462032 } else {
20472033 Expected NameOrErr = Symbol.getName();
20482034 if (!NameOrErr)
2049 report_error(ArchiveName, o->getFileName(), NameOrErr.takeError(),
2035 report_error(ArchiveName, O->getFileName(), NameOrErr.takeError(),
20502036 ArchitectureName);
20512037 Name = *NameOrErr;
20522038 }
20702056 else if (Type == SymbolRef::ST_Data)
20712057 FileFunc = 'O';
20722058
2073 const char *Fmt = o->getBytesInAddress() > 4 ? "%016" PRIx64 :
2059 const char *Fmt = O->getBytesInAddress() > 4 ? "%016" PRIx64 :
20742060 "%08" PRIx64;
20752061
20762062 outs() << format(Fmt, Address) << " "
20862072 outs() << "*ABS*";
20872073 } else if (Common) {
20882074 outs() << "*COM*";
2089 } else if (Section == o->section_end()) {
2075 } else if (Section == O->section_end()) {
20902076 outs() << "*UND*";
20912077 } else {
20922078 if (const MachOObjectFile *MachO =
2093 dyn_cast(o)) {
2079 dyn_cast(O)) {
20942080 DataRefImpl DR = Section->getRawDataRefImpl();
20952081 StringRef SegmentName = MachO->getSectionFinalSegmentName(DR);
20962082 outs() << SegmentName << ",";
21012087 }
21022088
21032089 outs() << '\t';
2104 if (Common || isa(o)) {
2090 if (Common || isa(O)) {
21052091 uint64_t Val =
21062092 Common ? Symbol.getAlignment() : ELFSymbolRef(Symbol).getSize();
21072093 outs() << format("\t %08" PRIx64 " ", Val);
21082094 }
21092095
2110 if (Hidden) {
2096 if (Hidden)
21112097 outs() << ".hidden ";
2112 }
21132098
21142099 if (Demangle)
21152100 outs() << demangle(Name) << '\n';
21182103 }
21192104 }
21202105
2121 static void PrintUnwindInfo(const ObjectFile *o) {
2106 static void printUnwindInfo(const ObjectFile *O) {
21222107 outs() << "Unwind info:\n\n";
21232108
2124 if (const COFFObjectFile *coff = dyn_cast(o)) {
2125 printCOFFUnwindInfo(coff);
2126 } else if (const MachOObjectFile *MachO = dyn_cast(o))
2109 if (const COFFObjectFile *Coff = dyn_cast(O))
2110 printCOFFUnwindInfo(Coff);
2111 else if (const MachOObjectFile *MachO = dyn_cast(O))
21272112 printMachOUnwindInfo(MachO);
2128 else {
2113 else
21292114 // TODO: Extract DWARF dump tool to objdump.
21302115 WithColor::error(errs(), ToolName)
21312116 << "This operation is only currently supported "
21322117 "for COFF and MachO object files.\n";
2133 return;
2134 }
21352118 }
21362119
21372120 void llvm::printExportsTrie(const ObjectFile *o) {
21382121 outs() << "Exports trie:\n";
21392122 if (const MachOObjectFile *MachO = dyn_cast(o))
21402123 printMachOExportsTrie(MachO);
2141 else {
2124 else
21422125 WithColor::error(errs(), ToolName)
21432126 << "This operation is only currently supported "
21442127 "for Mach-O executable files.\n";
2145 return;
2146 }
21472128 }
21482129
21492130 void llvm::printRebaseTable(ObjectFile *o) {
21502131 outs() << "Rebase table:\n";
21512132 if (MachOObjectFile *MachO = dyn_cast(o))
21522133 printMachORebaseTable(MachO);
2153 else {
2134 else
21542135 WithColor::error(errs(), ToolName)
21552136 << "This operation is only currently supported "
21562137 "for Mach-O executable files.\n";
2157 return;
2158 }
21592138 }
21602139
21612140 void llvm::printBindTable(ObjectFile *o) {
21622141 outs() << "Bind table:\n";
21632142 if (MachOObjectFile *MachO = dyn_cast(o))
21642143 printMachOBindTable(MachO);
2165 else {
2144 else
21662145 WithColor::error(errs(), ToolName)
21672146 << "This operation is only currently supported "
21682147 "for Mach-O executable files.\n";
2169 return;
2170 }
21712148 }
21722149
21732150 void llvm::printLazyBindTable(ObjectFile *o) {
21742151 outs() << "Lazy bind table:\n";
21752152 if (MachOObjectFile *MachO = dyn_cast(o))
21762153 printMachOLazyBindTable(MachO);
2177 else {
2154 else
21782155 WithColor::error(errs(), ToolName)
21792156 << "This operation is only currently supported "
21802157 "for Mach-O executable files.\n";
2181 return;
2182 }
21832158 }
21842159
21852160 void llvm::printWeakBindTable(ObjectFile *o) {
21862161 outs() << "Weak bind table:\n";
21872162 if (MachOObjectFile *MachO = dyn_cast(o))
21882163 printMachOWeakBindTable(MachO);
2189 else {
2164 else
21902165 WithColor::error(errs(), ToolName)
21912166 << "This operation is only currently supported "
21922167 "for Mach-O executable files.\n";
2193 return;
2194 }
21952168 }
21962169
21972170 /// Dump the raw contents of the __clangast section so the output can be piped
22292202 }
22302203
22312204 static void printFaultMaps(const ObjectFile *Obj) {
2232 const char *FaultMapSectionName = nullptr;
2205 StringRef FaultMapSectionName;
22332206
22342207 if (isa(Obj)) {
22352208 FaultMapSectionName = ".llvm_faultmaps";
22692242 outs() << FMP;
22702243 }
22712244
2272 static void printPrivateFileHeaders(const ObjectFile *o, bool onlyFirst) {
2273 if (o->isELF()) {
2274 printELFFileHeader(o);
2275 return printELFDynamicSection(o);
2276 }
2277 if (o->isCOFF())
2278 return printCOFFFileHeader(o);
2279 if (o->isWasm())
2280 return printWasmFileHeader(o);
2281 if (o->isMachO()) {
2282 printMachOFileHeader(o);
2283 if (!onlyFirst)
2284 printMachOLoadCommands(o);
2245 static void printPrivateFileHeaders(const ObjectFile *O, bool OnlyFirst) {
2246 if (O->isELF()) {
2247 printELFFileHeader(O);
2248 return printELFDynamicSection(O);
2249 }
2250 if (O->isCOFF())
2251 return printCOFFFileHeader(O);
2252 if (O->isWasm())
2253 return printWasmFileHeader(O);
2254 if (O->isMachO()) {
2255 printMachOFileHeader(O);
2256 if (!OnlyFirst)
2257 printMachOLoadCommands(O);
22852258 return;
22862259 }
2287 report_error(o->getFileName(), "Invalid/Unsupported object file format");
2288 }
2289
2290 static void printFileHeaders(const ObjectFile *o) {
2291 if (!o->isELF() && !o->isCOFF())
2292 report_error(o->getFileName(), "Invalid/Unsupported object file format");
2293
2294 Triple::ArchType AT = o->getArch();
2260 report_error(O->getFileName(), "Invalid/Unsupported object file format");
2261 }
2262
2263 static void printFileHeaders(const ObjectFile *O) {
2264 if (!O->isELF() && !O->isCOFF())
2265 report_error(O->getFileName(), "Invalid/Unsupported object file format");
2266
2267 Triple::ArchType AT = O->getArch();
22952268 outs() << "architecture: " << Triple::getArchTypeName(AT) << "\n";
2296 Expected StartAddrOrErr = o->getStartAddress();
2269 Expected StartAddrOrErr = O->getStartAddress();
22972270 if (!StartAddrOrErr)
2298 report_error(o->getFileName(), StartAddrOrErr.takeError());
2299
2300 StringRef Fmt = o->getBytesInAddress() > 4 ? "%016" PRIx64 : "%08" PRIx64;
2271 report_error(O->getFileName(), StartAddrOrErr.takeError());
2272
2273 StringRef Fmt = O->getBytesInAddress() > 4 ? "%016" PRIx64 : "%08" PRIx64;
23012274 uint64_t Address = StartAddrOrErr.get();
23022275 outs() << "start address: "
23032276 << "0x" << format(Fmt.data(), Address) << "\n\n";
23672340 outs() << Name << "\n";
23682341 }
23692342
2370 static void DumpObject(ObjectFile *o, const Archive *a = nullptr,
2371 const Archive::Child *c = nullptr) {
2372 StringRef ArchiveName = a != nullptr ? a->getFileName() : "";
2343 static void dumpObject(ObjectFile *O, const Archive *A = nullptr,
2344 const Archive::Child *C = nullptr) {
23732345 // Avoid other output when using a raw option.
23742346 if (!RawClangAST) {
23752347 outs() << '\n';
2376 if (a)
2377 outs() << a->getFileName() << "(" << o->getFileName() << ")";
2348 if (A)
2349 outs() << A->getFileName() << "(" << O->getFileName() << ")";
23782350 else
2379 outs() << o->getFileName();
2380 outs() << ":\tfile format " << o->getFileFormatName() << "\n\n";
2381 }
2382
2351 outs() << O->getFileName();
2352 outs() << ":\tfile format " << O->getFileFormatName() << "\n\n";
2353 }
2354
2355 StringRef ArchiveName = A ? A->getFileName() : "";
23832356 if (FileHeaders)
2384 printFileHeaders(o);
2385 if (ArchiveHeaders && !MachOOpt && c)
2386 printArchiveChild(ArchiveName, *c);
2357 printFileHeaders(O);
2358 if (ArchiveHeaders && !MachOOpt && C)
2359 printArchiveChild(ArchiveName, *C);
23872360 if (Disassemble)
2388 DisassembleObject(o, Relocations);
2361 disassembleObject(O, Relocations);
23892362 if (Relocations && !Disassemble)
2390 PrintRelocations(o);
2363 printRelocations(O);
23912364 if (DynamicRelocations)
2392 PrintDynamicRelocations(o);
2365 printDynamicRelocations(O);
23932366 if (SectionHeaders)
2394 PrintSectionHeaders(o);
2367 printSectionHeaders(O);
23952368 if (SectionContents)
2396 PrintSectionContents(o);
2369 printSectionContents(O);
23972370 if (SymbolTable)
2398 PrintSymbolTable(o, ArchiveName);
2371 printSymbolTable(O, ArchiveName);
23992372 if (UnwindInfo)
2400 PrintUnwindInfo(o);
2373 printUnwindInfo(O);
24012374 if (PrivateHeaders || FirstPrivateHeader)
2402 printPrivateFileHeaders(o, FirstPrivateHeader);
2375 printPrivateFileHeaders(O, FirstPrivateHeader);
24032376 if (ExportsTrie)
2404 printExportsTrie(o);
2377 printExportsTrie(O);
24052378 if (Rebase)
2406 printRebaseTable(o);
2379 printRebaseTable(O);
24072380 if (Bind)
2408 printBindTable(o);
2381 printBindTable(O);
24092382 if (LazyBind)
2410 printLazyBindTable(o);
2383 printLazyBindTable(O);
24112384 if (WeakBind)
2412 printWeakBindTable(o);
2385 printWeakBindTable(O);
24132386 if (RawClangAST)
2414 printRawClangAST(o);
2387 printRawClangAST(O);
24152388 if (PrintFaultMaps)
2416 printFaultMaps(o);
2389 printFaultMaps(O);
24172390 if (DwarfDumpType != DIDT_Null) {
2418 std::unique_ptr DICtx = DWARFContext::create(*o);
2391 std::unique_ptr DICtx = DWARFContext::create(*O);
24192392 // Dump the complete DWARF structure.
24202393 DIDumpOptions DumpOpts;
24212394 DumpOpts.DumpType = DwarfDumpType;
24232396 }
24242397 }
24252398
2426 static void DumpObject(const COFFImportFile *I, const Archive *A,
2399 static void dumpObject(const COFFImportFile *I, const Archive *A,
24272400 const Archive::Child *C = nullptr) {
24282401 StringRef ArchiveName = A ? A->getFileName() : "";
24292402
24412414 }
24422415
24432416 /// Dump each object file in \a a;
2444 static void DumpArchive(const Archive *a) {
2417 static void dumpArchive(const Archive *A) {
24452418 Error Err = Error::success();
2446 for (auto &C : a->children(Err)) {
2419 for (auto &C : A->children(Err)) {
24472420 Expected> ChildOrErr = C.getAsBinary();
24482421 if (!ChildOrErr) {
24492422 if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
2450 report_error(a->getFileName(), C, std::move(E));
2423 report_error(A->getFileName(), C, std::move(E));
24512424 continue;
24522425 }
2453 if (ObjectFile *o = dyn_cast(&*ChildOrErr.get()))
2454 DumpObject(o, a, &C);
2426 if (ObjectFile *O = dyn_cast(&*ChildOrErr.get()))
2427 dumpObject(O, A, &C);
24552428 else if (COFFImportFile *I = dyn_cast(&*ChildOrErr.get()))
2456 DumpObject(I, a, &C);
2429 dumpObject(I, A, &C);
24572430 else
2458 report_error(a->getFileName(), object_error::invalid_file_type);
2431 report_error(A->getFileName(), object_error::invalid_file_type);
24592432 }
24602433 if (Err)
2461 report_error(a->getFileName(), std::move(Err));
2434 report_error(A->getFileName(), std::move(Err));
24622435 }
24632436
24642437 /// Open file and figure out how to dump it.
2465 static void DumpInput(StringRef file) {
2466
2438 static void dumpInput(StringRef file) {
24672439 // If we are using the Mach-O specific object file parser, then let it parse
24682440 // the file and process the command line options. So the -arch flags can
24692441 // be used to select specific slices, etc.
24702442 if (MachOOpt) {
2471 ParseInputMachO(file);
2443 parseInputMachO(file);
24722444 return;
24732445 }
24742446
24782450 report_error(file, BinaryOrErr.takeError());
24792451 Binary &Binary = *BinaryOrErr.get().getBinary();
24802452
2481 if (Archive *a = dyn_cast(&Binary))
2482 DumpArchive(a);
2483 else if (ObjectFile *o = dyn_cast(&Binary))
2484 DumpObject(o);
2453 if (Archive *A = dyn_cast(&Binary))
2454 dumpArchive(A);
2455 else if (ObjectFile *O = dyn_cast(&Binary))
2456 dumpObject(O);
24852457 else if (MachOUniversalBinary *UB = dyn_cast(&Binary))
2486 ParseInputMachO(UB);
2458 parseInputMachO(UB);
24872459 else
24882460 report_error(file, object_error::invalid_file_type);
24892461 }
25492521 DisasmFuncsSet.insert(DisassembleFunctions.begin(),
25502522 DisassembleFunctions.end());
25512523
2552 llvm::for_each(InputFilenames, DumpInput);
2524 llvm::for_each(InputFilenames, dumpInput);
25532525
25542526 return EXIT_SUCCESS;
25552527 }
6969
7070 // Various helper functions.
7171 void error(std::error_code ec);
72 bool RelocAddressLess(object::RelocationRef a, object::RelocationRef b);
73 void ParseInputMachO(StringRef Filename);
74 void ParseInputMachO(object::MachOUniversalBinary *UB);
75 void printCOFFUnwindInfo(const object::COFFObjectFile* o);
76 void printMachOUnwindInfo(const object::MachOObjectFile* o);
77 void printMachOExportsTrie(const object::MachOObjectFile* o);
78 void printMachORebaseTable(object::MachOObjectFile* o);
79 void printMachOBindTable(object::MachOObjectFile* o);
80 void printMachOLazyBindTable(object::MachOObjectFile* o);
81 void printMachOWeakBindTable(object::MachOObjectFile* o);
82 void printELFFileHeader(const object::ObjectFile *o);
72 bool isRelocAddressLess(object::RelocationRef A, object::RelocationRef B);
73 void parseInputMachO(StringRef Filename);
74 void parseInputMachO(object::MachOUniversalBinary *UB);
75 void printCOFFUnwindInfo(const object::COFFObjectFile *O);
76 void printMachOUnwindInfo(const object::MachOObjectFile *O);
77 void printMachOExportsTrie(const object::MachOObjectFile *O);
78 void printMachORebaseTable(object::MachOObjectFile *O);
79 void printMachOBindTable(object::MachOObjectFile *O);
80 void printMachOLazyBindTable(object::MachOObjectFile *O);
81 void printMachOWeakBindTable(object::MachOObjectFile *O);
82 void printELFFileHeader(const object::ObjectFile *O);
8383 void printELFDynamicSection(const object::ObjectFile *Obj);
84 void printCOFFFileHeader(const object::ObjectFile *o);
85 void printCOFFSymbolTable(const object::COFFImportFile *i);
86 void printCOFFSymbolTable(const object::COFFObjectFile *o);
87 void printMachOFileHeader(const object::ObjectFile *o);
88 void printMachOLoadCommands(const object::ObjectFile *o);
89 void printWasmFileHeader(const object::ObjectFile *o);
90 void printExportsTrie(const object::ObjectFile *o);
91 void printRebaseTable(object::ObjectFile *o);
92 void printBindTable(object::ObjectFile *o);
93 void printLazyBindTable(object::ObjectFile *o);
94 void printWeakBindTable(object::ObjectFile *o);
95 void printRawClangAST(const object::ObjectFile *o);
96 void PrintRelocations(const object::ObjectFile *o);
97 void PrintDynamicRelocations(const object::ObjectFile *o);
98 void PrintSectionHeaders(const object::ObjectFile *o);
99 void PrintSectionContents(const object::ObjectFile *o);
100 void PrintSymbolTable(const object::ObjectFile *o, StringRef ArchiveName,
84 void printCOFFFileHeader(const object::ObjectFile *O);
85 void printCOFFSymbolTable(const object::COFFImportFile *I);
86 void printCOFFSymbolTable(const object::COFFObjectFile *O);
87 void printMachOFileHeader(const object::ObjectFile *O);
88 void printMachOLoadCommands(const object::ObjectFile *O);
89 void printWasmFileHeader(const object::ObjectFile *O);
90 void printExportsTrie(const object::ObjectFile *O);
91 void printRebaseTable(object::ObjectFile *O);
92 void printBindTable(object::ObjectFile *O);
93 void printLazyBindTable(object::ObjectFile *O);
94 void printWeakBindTable(object::ObjectFile *O);
95 void printRawClangAST(const object::ObjectFile *O);
96 void printRelocations(const object::ObjectFile *O);
97 void printDynamicRelocations(const object::ObjectFile *O);
98 void printSectionHeaders(const object::ObjectFile *O);
99 void printSectionContents(const object::ObjectFile *O);
100 void printSymbolTable(const object::ObjectFile *O, StringRef ArchiveName,
101101 StringRef ArchitectureName = StringRef());
102102 void warn(StringRef Message);
103103 LLVM_ATTRIBUTE_NORETURN void error(Twine Message);