Index: llvm/trunk/tools/llvm-objdump/COFFDump.cpp =================================================================== --- llvm/trunk/tools/llvm-objdump/COFFDump.cpp +++ llvm/trunk/tools/llvm-objdump/COFFDump.cpp @@ -455,7 +455,7 @@ Rels.push_back(Reloc); // Sort relocations by address. - llvm::sort(Rels, RelocAddressLess); + llvm::sort(Rels, isRelocAddressLess); ArrayRef Contents; error(Obj->getSectionContents(Pdata, Contents)); Index: llvm/trunk/tools/llvm-objdump/MachODump.cpp =================================================================== --- llvm/trunk/tools/llvm-objdump/MachODump.cpp +++ llvm/trunk/tools/llvm-objdump/MachODump.cpp @@ -1627,9 +1627,9 @@ if (Relocations) PrintRelocations(MachOOF, !NonVerbose); if (SectionHeaders) - PrintSectionHeaders(MachOOF); + printSectionHeaders(MachOOF); if (SectionContents) - PrintSectionContents(MachOOF); + printSectionContents(MachOOF); if (!FilterSections.empty()) DumpSectionContents(FileName, MachOOF, !NonVerbose); if (InfoPlist) @@ -1639,7 +1639,7 @@ if (DylibId) PrintDylibs(MachOOF, true); if (SymbolTable) - PrintSymbolTable(MachOOF, ArchiveName, ArchitectureName); + printSymbolTable(MachOOF, ArchiveName, ArchitectureName); if (UnwindInfo) printMachOUnwindInfo(MachOOF); if (PrivateHeaders) { @@ -1959,7 +1959,7 @@ // -arch flags selecting just those slices as specified by them and also parses // archive files. Then for each individual Mach-O file ProcessMachO() is // called to process the file based on the command line options. -void llvm::ParseInputMachO(StringRef Filename) { +void llvm::parseInputMachO(StringRef Filename) { if (!ValidateArchFlags()) return; @@ -1998,7 +1998,7 @@ return; } if (MachOUniversalBinary *UB = dyn_cast(&Bin)) { - ParseInputMachO(UB); + parseInputMachO(UB); return; } if (ObjectFile *O = dyn_cast(&Bin)) { @@ -2015,7 +2015,7 @@ llvm_unreachable("Input object can't be invalid at this point"); } -void llvm::ParseInputMachO(MachOUniversalBinary *UB) { +void llvm::parseInputMachO(MachOUniversalBinary *UB) { if (!ValidateArchFlags()) return; Index: llvm/trunk/tools/llvm-objdump/llvm-objdump.h =================================================================== --- llvm/trunk/tools/llvm-objdump/llvm-objdump.h +++ llvm/trunk/tools/llvm-objdump/llvm-objdump.h @@ -70,35 +70,35 @@ // Various helper functions. void error(std::error_code ec); -bool RelocAddressLess(object::RelocationRef a, object::RelocationRef b); -void ParseInputMachO(StringRef Filename); -void ParseInputMachO(object::MachOUniversalBinary *UB); -void printCOFFUnwindInfo(const object::COFFObjectFile* o); -void printMachOUnwindInfo(const object::MachOObjectFile* o); -void printMachOExportsTrie(const object::MachOObjectFile* o); -void printMachORebaseTable(object::MachOObjectFile* o); -void printMachOBindTable(object::MachOObjectFile* o); -void printMachOLazyBindTable(object::MachOObjectFile* o); -void printMachOWeakBindTable(object::MachOObjectFile* o); -void printELFFileHeader(const object::ObjectFile *o); +bool isRelocAddressLess(object::RelocationRef A, object::RelocationRef B); +void parseInputMachO(StringRef Filename); +void parseInputMachO(object::MachOUniversalBinary *UB); +void printCOFFUnwindInfo(const object::COFFObjectFile *O); +void printMachOUnwindInfo(const object::MachOObjectFile *O); +void printMachOExportsTrie(const object::MachOObjectFile *O); +void printMachORebaseTable(object::MachOObjectFile *O); +void printMachOBindTable(object::MachOObjectFile *O); +void printMachOLazyBindTable(object::MachOObjectFile *O); +void printMachOWeakBindTable(object::MachOObjectFile *O); +void printELFFileHeader(const object::ObjectFile *O); void printELFDynamicSection(const object::ObjectFile *Obj); -void printCOFFFileHeader(const object::ObjectFile *o); -void printCOFFSymbolTable(const object::COFFImportFile *i); -void printCOFFSymbolTable(const object::COFFObjectFile *o); -void printMachOFileHeader(const object::ObjectFile *o); -void printMachOLoadCommands(const object::ObjectFile *o); -void printWasmFileHeader(const object::ObjectFile *o); -void printExportsTrie(const object::ObjectFile *o); -void printRebaseTable(object::ObjectFile *o); -void printBindTable(object::ObjectFile *o); -void printLazyBindTable(object::ObjectFile *o); -void printWeakBindTable(object::ObjectFile *o); -void printRawClangAST(const object::ObjectFile *o); -void PrintRelocations(const object::ObjectFile *o); -void PrintDynamicRelocations(const object::ObjectFile *o); -void PrintSectionHeaders(const object::ObjectFile *o); -void PrintSectionContents(const object::ObjectFile *o); -void PrintSymbolTable(const object::ObjectFile *o, StringRef ArchiveName, +void printCOFFFileHeader(const object::ObjectFile *O); +void printCOFFSymbolTable(const object::COFFImportFile *I); +void printCOFFSymbolTable(const object::COFFObjectFile *O); +void printMachOFileHeader(const object::ObjectFile *O); +void printMachOLoadCommands(const object::ObjectFile *O); +void printWasmFileHeader(const object::ObjectFile *O); +void printExportsTrie(const object::ObjectFile *O); +void printRebaseTable(object::ObjectFile *O); +void printBindTable(object::ObjectFile *O); +void printLazyBindTable(object::ObjectFile *O); +void printWeakBindTable(object::ObjectFile *O); +void printRawClangAST(const object::ObjectFile *O); +void printRelocations(const object::ObjectFile *O); +void printDynamicRelocations(const object::ObjectFile *O); +void printSectionHeaders(const object::ObjectFile *O); +void printSectionContents(const object::ObjectFile *O); +void printSymbolTable(const object::ObjectFile *O, StringRef ArchiveName, StringRef ArchitectureName = StringRef()); void warn(StringRef Message); LLVM_ATTRIBUTE_NORETURN void error(Twine Message); Index: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp =================================================================== --- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp +++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp @@ -430,18 +430,16 @@ // Figure out the target triple. llvm::Triple TheTriple("unknown-unknown-unknown"); if (TripleName.empty()) { - if (Obj) { + if (Obj) TheTriple = Obj->makeTriple(); - } } else { TheTriple.setTriple(Triple::normalize(TripleName)); // Use the triple, but also try to combine with ARM build attributes. if (Obj) { auto Arch = Obj->getArch(); - if (Arch == Triple::arm || Arch == Triple::armeb) { + if (Arch == Triple::arm || Arch == Triple::armeb) Obj->setARMSubArch(TheTriple); - } } } @@ -461,8 +459,8 @@ return TheTarget; } -bool llvm::RelocAddressLess(RelocationRef a, RelocationRef b) { - return a.getOffset() < b.getOffset(); +bool llvm::isRelocAddressLess(RelocationRef A, RelocationRef B) { + return A.getOffset() < B.getOffset(); } static std::string demangle(StringRef Name) { @@ -484,14 +482,12 @@ static std::error_code getRelocationValueString(const ELFObjectFile *Obj, const RelocationRef &RelRef, SmallVectorImpl &Result) { - DataRefImpl Rel = RelRef.getRawDataRefImpl(); - typedef typename ELFObjectFile::Elf_Sym Elf_Sym; typedef typename ELFObjectFile::Elf_Shdr Elf_Shdr; typedef typename ELFObjectFile::Elf_Rela Elf_Rela; const ELFFile &EF = *Obj->getELFFile(); - + DataRefImpl Rel = RelRef.getRawDataRefImpl(); auto SecOrErr = EF.getSection(Rel.d.a); if (!SecOrErr) return errorToErrorCode(SecOrErr.takeError()); @@ -509,11 +505,11 @@ if (!StrTabOrErr) return errorToErrorCode(StrTabOrErr.takeError()); StringRef StrTab = *StrTabOrErr; - int64_t addend = 0; + int64_t Addend = 0; // If there is no Symbol associated with the relocation, we set the undef // boolean value to 'true'. This will prevent us from calling functions that // requires the relocation to be associated with a symbol. - bool undef = false; + bool Undef = false; switch (Sec->sh_type) { default: return object_error::parse_failed; @@ -523,13 +519,13 @@ } case ELF::SHT_RELA: { const Elf_Rela *ERela = Obj->getRela(Rel); - addend = ERela->r_addend; - undef = ERela->getSymbol(false) == 0; + Addend = ERela->r_addend; + Undef = ERela->getSymbol(false) == 0; break; } } std::string Target; - if (!undef) { + if (!Undef) { symbol_iterator SI = RelRef.getSymbol(); const Elf_Sym *symb = Obj->getSymbol(SI->getRawDataRefImpl()); if (symb->getType() == ELF::STT_SECTION) { @@ -555,13 +551,13 @@ // Default scheme is to print Target, as well as "+ " for nonzero // addend. Should be acceptable for all normal purposes. - std::string fmtbuf; - raw_string_ostream fmt(fmtbuf); - fmt << Target; - if (addend != 0) - fmt << (addend < 0 ? "" : "+") << addend; - fmt.flush(); - Result.append(fmtbuf.begin(), fmtbuf.end()); + std::string FmtBuf; + raw_string_ostream Fmt(FmtBuf); + Fmt << Target; + if (Addend != 0) + Fmt << (Addend < 0 ? "" : "+") << Addend; + Fmt.flush(); + Result.append(FmtBuf.begin(), FmtBuf.end()); return std::error_code(); } @@ -592,18 +588,15 @@ static void printRelocationTargetName(const MachOObjectFile *O, const MachO::any_relocation_info &RE, - raw_string_ostream &fmt) { - bool IsScattered = O->isRelocationScattered(RE); - + raw_string_ostream &Fmt) { // Target of a scattered relocation is an address. In the interest of // generating pretty output, scan through the symbol table looking for a // symbol that aligns with that address. If we find one, print it. // Otherwise, we just print the hex address of the target. - if (IsScattered) { + if (O->isRelocationScattered(RE)) { uint32_t Val = O->getPlainRelocationSymbolNum(RE); for (const SymbolRef &Symbol : O->symbols()) { - std::error_code ec; Expected Addr = Symbol.getAddress(); if (!Addr) report_error(O->getFileName(), Addr.takeError()); @@ -612,7 +605,7 @@ Expected Name = Symbol.getName(); if (!Name) report_error(O->getFileName(), Name.takeError()); - fmt << *Name; + Fmt << *Name; return; } @@ -627,11 +620,11 @@ continue; if ((ec = Section.getName(Name))) report_error(O->getFileName(), ec); - fmt << Name; + Fmt << Name; return; } - fmt << format("0x%x", Val); + Fmt << format("0x%x", Val); return; } @@ -640,9 +633,11 @@ uint64_t Val = O->getPlainRelocationSymbolNum(RE); if (O->getAnyRelocationType(RE) == MachO::ARM64_RELOC_ADDEND) { - fmt << format("0x%0" PRIx64, Val); + Fmt << format("0x%0" PRIx64, Val); return; - } else if (isExtern) { + } + + if (isExtern) { symbol_iterator SI = O->symbol_begin(); advance(SI, Val); Expected SOrErr = SI->getName(); @@ -653,21 +648,21 @@ section_iterator SI = O->section_begin(); // Adjust for the fact that sections are 1-indexed. if (Val == 0) { - fmt << "0 (?,?)"; + Fmt << "0 (?,?)"; return; } - uint32_t i = Val - 1; - while (i != 0 && SI != O->section_end()) { - i--; + uint32_t I = Val - 1; + while (I != 0 && SI != O->section_end()) { + --I; advance(SI, 1); } if (SI == O->section_end()) - fmt << Val << " (?,?)"; + Fmt << Val << " (?,?)"; else SI->getName(S); } - fmt << S; + Fmt << S; } static std::error_code getRelocationValueString(const WasmObjectFile *Obj, @@ -675,12 +670,12 @@ SmallVectorImpl &Result) { const wasm::WasmRelocation& Rel = Obj->getWasmRelocation(RelRef); symbol_iterator SI = RelRef.getSymbol(); - std::string fmtbuf; - raw_string_ostream fmt(fmtbuf); + std::string FmtBuf; + raw_string_ostream Fmt(FmtBuf); if (SI == Obj->symbol_end()) { // Not all wasm relocations have symbols associated with them. // In particular R_WEBASSEMBLY_TYPE_INDEX_LEB. - fmt << Rel.Index; + Fmt << Rel.Index; } else { Expected SymNameOrErr = SI->getName(); if (!SymNameOrErr) @@ -688,9 +683,9 @@ StringRef SymName = *SymNameOrErr; Result.append(SymName.begin(), SymName.end()); } - fmt << (Rel.Addend < 0 ? "" : "+") << Rel.Addend; - fmt.flush(); - Result.append(fmtbuf.begin(), fmtbuf.end()); + Fmt << (Rel.Addend < 0 ? "" : "+") << Rel.Addend; + Fmt.flush(); + Result.append(FmtBuf.begin(), FmtBuf.end()); return std::error_code(); } @@ -702,8 +697,8 @@ unsigned Arch = Obj->getArch(); - std::string fmtbuf; - raw_string_ostream fmt(fmtbuf); + std::string FmtBuf; + raw_string_ostream Fmt(FmtBuf); unsigned Type = Obj->getAnyRelocationType(RE); bool IsPCRel = Obj->getAnyRelocationPCRel(RE); @@ -712,15 +707,13 @@ // X86_64 has entirely custom relocation types. if (Arch == Triple::x86_64) { - bool isPCRel = Obj->getAnyRelocationPCRel(RE); - switch (Type) { case MachO::X86_64_RELOC_GOT_LOAD: case MachO::X86_64_RELOC_GOT: { - printRelocationTargetName(Obj, RE, fmt); - fmt << "@GOT"; - if (isPCRel) - fmt << "PCREL"; + printRelocationTargetName(Obj, RE, Fmt); + Fmt << "@GOT"; + if (IsPCRel) + Fmt << "PCREL"; break; } case MachO::X86_64_RELOC_SUBTRACTOR: { @@ -738,31 +731,31 @@ // The X86_64_RELOC_UNSIGNED contains the minuend symbol; // X86_64_RELOC_SUBTRACTOR contains the subtrahend. - printRelocationTargetName(Obj, RENext, fmt); - fmt << "-"; - printRelocationTargetName(Obj, RE, fmt); + printRelocationTargetName(Obj, RENext, Fmt); + Fmt << "-"; + printRelocationTargetName(Obj, RE, Fmt); break; } case MachO::X86_64_RELOC_TLV: - printRelocationTargetName(Obj, RE, fmt); - fmt << "@TLV"; - if (isPCRel) - fmt << "P"; + printRelocationTargetName(Obj, RE, Fmt); + Fmt << "@TLV"; + if (IsPCRel) + Fmt << "P"; break; case MachO::X86_64_RELOC_SIGNED_1: - printRelocationTargetName(Obj, RE, fmt); - fmt << "-1"; + printRelocationTargetName(Obj, RE, Fmt); + Fmt << "-1"; break; case MachO::X86_64_RELOC_SIGNED_2: - printRelocationTargetName(Obj, RE, fmt); - fmt << "-2"; + printRelocationTargetName(Obj, RE, Fmt); + Fmt << "-2"; break; case MachO::X86_64_RELOC_SIGNED_4: - printRelocationTargetName(Obj, RE, fmt); - fmt << "-4"; + printRelocationTargetName(Obj, RE, Fmt); + Fmt << "-4"; break; default: - printRelocationTargetName(Obj, RE, fmt); + printRelocationTargetName(Obj, RE, Fmt); break; } // X86 and ARM share some relocation types in common. @@ -785,9 +778,9 @@ report_error(Obj->getFileName(), "Expected GENERIC_RELOC_PAIR after " "GENERIC_RELOC_SECTDIFF."); - printRelocationTargetName(Obj, RE, fmt); - fmt << "-"; - printRelocationTargetName(Obj, RENext, fmt); + printRelocationTargetName(Obj, RE, Fmt); + Fmt << "-"; + printRelocationTargetName(Obj, RENext, Fmt); break; } } @@ -806,20 +799,20 @@ report_error(Obj->getFileName(), "Expected GENERIC_RELOC_PAIR after " "GENERIC_RELOC_LOCAL_SECTDIFF."); - printRelocationTargetName(Obj, RE, fmt); - fmt << "-"; - printRelocationTargetName(Obj, RENext, fmt); + printRelocationTargetName(Obj, RE, Fmt); + Fmt << "-"; + printRelocationTargetName(Obj, RENext, Fmt); break; } case MachO::GENERIC_RELOC_TLV: { - printRelocationTargetName(Obj, RE, fmt); - fmt << "@TLV"; + printRelocationTargetName(Obj, RE, Fmt); + Fmt << "@TLV"; if (IsPCRel) - fmt << "P"; + Fmt << "P"; break; } default: - printRelocationTargetName(Obj, RE, fmt); + printRelocationTargetName(Obj, RE, Fmt); } } else { // ARM-specific relocations switch (Type) { @@ -830,10 +823,10 @@ bool isUpper = (Obj->getAnyRelocationLength(RE) & 0x1) == 1; if (isUpper) - fmt << ":upper16:("; + Fmt << ":upper16:("; else - fmt << ":lower16:("; - printRelocationTargetName(Obj, RE, fmt); + Fmt << ":lower16:("; + printRelocationTargetName(Obj, RE, Fmt); DataRefImpl RelNext = Rel; Obj->moveRelocationNext(RelNext); @@ -854,21 +847,21 @@ // ARM_RELOC_HALF_SECTDIFF encodes the second section in the // symbol/section pointer of the follow-on relocation. if (Type == MachO::ARM_RELOC_HALF_SECTDIFF) { - fmt << "-"; - printRelocationTargetName(Obj, RENext, fmt); + Fmt << "-"; + printRelocationTargetName(Obj, RENext, Fmt); } - fmt << ")"; + Fmt << ")"; break; } - default: { printRelocationTargetName(Obj, RE, fmt); } + default: { printRelocationTargetName(Obj, RE, Fmt); } } } } else - printRelocationTargetName(Obj, RE, fmt); + printRelocationTargetName(Obj, RE, Fmt); - fmt.flush(); - Result.append(fmtbuf.begin(), fmtbuf.end()); + Fmt.flush(); + Result.append(FmtBuf.begin(), FmtBuf.end()); return std::error_code(); } @@ -890,8 +883,7 @@ /// relocations, usually because it is the trailing part of a multipart /// relocation that will be printed as part of the leading relocation. static bool getHidden(RelocationRef RelRef) { - const ObjectFile *Obj = RelRef.getObject(); - auto *MachO = dyn_cast(Obj); + auto *MachO = dyn_cast(RelRef.getObject()); if (!MachO) return false; @@ -901,10 +893,10 @@ // On arches that use the generic relocations, GENERIC_RELOC_PAIR // is always hidden. - if (Arch == Triple::x86 || Arch == Triple::arm || Arch == Triple::ppc) { - if (Type == MachO::GENERIC_RELOC_PAIR) - return true; - } else if (Arch == Triple::x86_64) { + if (Arch == Triple::x86 || Arch == Triple::arm || Arch == Triple::ppc) + return Type == MachO::GENERIC_RELOC_PAIR; + + if (Arch == Triple::x86_64) { // On x86_64, X86_64_RELOC_UNSIGNED is hidden only when it follows // an X86_64_RELOC_SUBTRACTOR. if (Type == MachO::X86_64_RELOC_UNSIGNED && Rel.d.a > 0) { @@ -1079,27 +1071,27 @@ auto Preamble = " { "; auto Separator = ""; StringRef Fmt = "\t\t\t%08" PRIx64 ": "; - std::vector::const_iterator rel_cur = Rels->begin(); - std::vector::const_iterator rel_end = Rels->end(); + std::vector::const_iterator RelCur = Rels->begin(); + std::vector::const_iterator RelEnd = Rels->end(); // Hexagon's packets require relocations to be inline rather than // clustered at the end of the packet. auto PrintReloc = [&]() -> void { - while ((rel_cur != rel_end) && (rel_cur->getOffset() <= Address)) { - if (rel_cur->getOffset() == Address) { - SmallString<16> name; - SmallString<32> val; - rel_cur->getTypeName(name); - error(getRelocationValueString(*rel_cur, val)); - OS << Separator << format(Fmt.data(), Address) << name << "\t" << val + while ((RelCur != RelEnd) && (RelCur->getOffset() <= Address)) { + if (RelCur->getOffset() == Address) { + SmallString<16> Name; + SmallString<32> Val; + RelCur->getTypeName(Name); + error(getRelocationValueString(*RelCur, Val)); + OS << Separator << format(Fmt.data(), Address) << Name << "\t" << Val << "\n"; return; } - rel_cur++; + ++RelCur; } }; - while(!HeadTail.first.empty()) { + while (!HeadTail.first.empty()) { OS << Separator; Separator = "\n"; if (SP && (PrintSource || PrintLines)) @@ -1109,7 +1101,7 @@ Preamble = " "; StringRef Inst; auto Duplex = HeadTail.first.split('\v'); - if(!Duplex.second.empty()){ + if (!Duplex.second.empty()) { OS << Duplex.first; OS << "; "; Inst = Duplex.second; @@ -1241,7 +1233,6 @@ Expected AddressOrErr = Symbol.getAddress(); if (!AddressOrErr) report_error(Obj->getFileName(), AddressOrErr.takeError()); - uint64_t Address = *AddressOrErr; Expected Name = Symbol.getName(); if (!Name) @@ -1256,7 +1247,7 @@ if (SecI == Obj->section_end()) continue; - AllSymbols[*SecI].emplace_back(Address, *Name, SymbolType); + AllSymbols[*SecI].emplace_back(*AddressOrErr, *Name, SymbolType); } } @@ -1292,7 +1283,6 @@ if (auto *ElfObj = dyn_cast(Obj)) { for (auto PltEntry : ElfObj->getPltAddresses()) { SymbolRef Symbol(PltEntry.first, ElfObj); - uint8_t SymbolType = getElfSymbolType(Obj, Symbol); Expected NameOrErr = Symbol.getName(); @@ -1330,7 +1320,7 @@ return N & ~0x3; } -static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { +static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) { if (StartAddress > StopAddress) error("Start address should be less than stop address"); @@ -1338,10 +1328,9 @@ // Package up features to be passed to target/subtarget SubtargetFeatures Features = Obj->getFeatures(); - if (!MAttrs.empty()) { - for (unsigned i = 0; i != MAttrs.size(); ++i) - Features.AddFeature(MAttrs[i]); - } + if (!MAttrs.empty()) + for (unsigned I = 0; I != MAttrs.size(); ++I) + Features.AddFeature(MAttrs[I]); std::unique_ptr MRI( TheTarget->createMCRegInfo(TripleName)); @@ -1536,7 +1525,7 @@ } // Sort relocations by address. - llvm::sort(Rels, RelocAddressLess); + llvm::sort(Rels, isRelocAddressLess); StringRef SegmentName = ""; if (const MachOObjectFile *MachO = dyn_cast(Obj)) { @@ -1566,15 +1555,16 @@ uint64_t Index; bool PrintedSection = false; - std::vector::const_iterator rel_cur = Rels.begin(); - std::vector::const_iterator rel_end = Rels.end(); + std::vector::const_iterator RelCur = Rels.begin(); + std::vector::const_iterator RelEnd = Rels.end(); // Disassemble symbol by symbol. - for (unsigned si = 0, se = Symbols.size(); si != se; ++si) { - uint64_t Start = std::get<0>(Symbols[si]) - SectionAddr; + for (unsigned SI = 0, SE = Symbols.size(); SI != SE; ++SI) { + uint64_t Start = std::get<0>(Symbols[SI]) - SectionAddr; // The end is either the section end or the beginning of the next // symbol. - uint64_t End = - (si == se - 1) ? SectSize : std::get<0>(Symbols[si + 1]) - SectionAddr; + uint64_t End = (SI == SE - 1) + ? SectSize + : std::get<0>(Symbols[SI + 1]) - SectionAddr; // Don't try to disassemble beyond the end of section contents. if (End > SectSize) End = SectSize; @@ -1591,7 +1581,7 @@ /// Skip if user requested specific symbols and this is not in the list if (!DisasmFuncsSet.empty() && - !DisasmFuncsSet.count(std::get<1>(Symbols[si]))) + !DisasmFuncsSet.count(std::get<1>(Symbols[SI]))) continue; if (!PrintedSection) { @@ -1607,12 +1597,12 @@ End = StopAddress - SectionAddr; if (Obj->isELF() && Obj->getArch() == Triple::amdgcn) { - if (std::get<2>(Symbols[si]) == ELF::STT_AMDGPU_HSA_KERNEL) { + if (std::get<2>(Symbols[SI]) == ELF::STT_AMDGPU_HSA_KERNEL) { // skip amd_kernel_code_t at the begining of kernel symbol (256 bytes) Start += 256; } - if (si == se - 1 || - std::get<2>(Symbols[si + 1]) == ELF::STT_AMDGPU_HSA_KERNEL) { + if (SI == SE - 1 || + std::get<2>(Symbols[SI + 1]) == ELF::STT_AMDGPU_HSA_KERNEL) { // cut trailing zeroes at the end of kernel // cut up to 256 bytes const uint64_t EndAlign = 256; @@ -1627,7 +1617,7 @@ if (!NoLeadingAddr) outs() << format("%016" PRIx64 " ", SectionAddr + Start); - StringRef SymbolName = std::get<1>(Symbols[si]); + StringRef SymbolName = std::get<1>(Symbols[SI]); if (Demangle) outs() << demangle(SymbolName) << ":\n"; else @@ -1659,7 +1649,7 @@ // same section. We rely on the markers introduced to // understand what we need to dump. If the data marker is within a // function, it is denoted as a word/short etc - if (isArmElf(Obj) && std::get<2>(Symbols[si]) != ELF::STT_OBJECT && + if (isArmElf(Obj) && std::get<2>(Symbols[SI]) != ELF::STT_OBJECT && !DisassembleAll) { uint64_t Stride = 0; @@ -1723,7 +1713,7 @@ // disassembling text (applicable all architectures), // we are in a situation where we must print the data and not // disassemble it. - if (Obj->isELF() && std::get<2>(Symbols[si]) == ELF::STT_OBJECT && + if (Obj->isELF() && std::get<2>(Symbols[SI]) == ELF::STT_OBJECT && !DisassembleAll && Section.isText()) { // print out data up to 8 bytes at a time in hex and ascii uint8_t AsciiData[9] = {'\0'}; @@ -1850,32 +1840,32 @@ // Hexagon does this in pretty printer if (Obj->getArch() != Triple::hexagon) // Print relocation for instruction. - while (rel_cur != rel_end) { - bool hidden = getHidden(*rel_cur); - uint64_t addr = rel_cur->getOffset(); - SmallString<16> name; - SmallString<32> val; + while (RelCur != RelEnd) { + uint64_t Addr = RelCur->getOffset(); + SmallString<16> Name; + SmallString<32> Val; // If this relocation is hidden, skip it. - if (hidden || ((SectionAddr + addr) < StartAddress)) { - ++rel_cur; + if (getHidden(*RelCur) || ((SectionAddr + Addr) < StartAddress)) { + ++RelCur; continue; } // Stop when rel_cur's address is past the current instruction. - if (addr >= Index + Size) break; - rel_cur->getTypeName(name); - error(getRelocationValueString(*rel_cur, val)); - outs() << format(Fmt.data(), SectionAddr + addr) << name - << "\t" << val << "\n"; - ++rel_cur; + if (Addr >= Index + Size) + break; + RelCur->getTypeName(Name); + error(getRelocationValueString(*RelCur, Val)); + outs() << format(Fmt.data(), SectionAddr + Addr) << Name << "\t" + << Val << "\n"; + ++RelCur; } } } } } -void llvm::PrintRelocations(const ObjectFile *Obj) { +void llvm::printRelocations(const ObjectFile *Obj) { StringRef Fmt = Obj->getBytesInAddress() > 4 ? "%016" PRIx64 : "%08" PRIx64; // Regular objdump doesn't print relocations in non-relocatable object @@ -1886,61 +1876,57 @@ for (const SectionRef &Section : ToolSectionFilter(*Obj)) { if (Section.relocation_begin() == Section.relocation_end()) continue; - StringRef secname; - error(Section.getName(secname)); - outs() << "RELOCATION RECORDS FOR [" << secname << "]:\n"; + StringRef SecName; + error(Section.getName(SecName)); + outs() << "RELOCATION RECORDS FOR [" << SecName << "]:\n"; for (const RelocationRef &Reloc : Section.relocations()) { - bool hidden = getHidden(Reloc); - uint64_t address = Reloc.getOffset(); - SmallString<32> relocname; - SmallString<32> valuestr; - if (address < StartAddress || address > StopAddress || hidden) + uint64_t Address = Reloc.getOffset(); + SmallString<32> RelocName; + SmallString<32> ValueStr; + if (Address < StartAddress || Address > StopAddress || getHidden(Reloc)) continue; - Reloc.getTypeName(relocname); - error(getRelocationValueString(Reloc, valuestr)); - outs() << format(Fmt.data(), address) << " " << relocname << " " - << valuestr << "\n"; + Reloc.getTypeName(RelocName); + error(getRelocationValueString(Reloc, ValueStr)); + outs() << format(Fmt.data(), Address) << " " << RelocName << " " + << ValueStr << "\n"; } outs() << "\n"; } } -void llvm::PrintDynamicRelocations(const ObjectFile *Obj) { - +void llvm::printDynamicRelocations(const ObjectFile *Obj) { // For the moment, this option is for ELF only if (!Obj->isELF()) return; const auto *Elf = dyn_cast(Obj); - if (!Elf || Elf->getEType() != ELF::ET_DYN) { error("not a dynamic object"); return; } - StringRef Fmt = Obj->getBytesInAddress() > 4 ? "%016" PRIx64 : "%08" PRIx64; - std::vector DynRelSec = Obj->dynamic_relocation_sections(); if (DynRelSec.empty()) return; outs() << "DYNAMIC RELOCATION RECORDS\n"; + StringRef Fmt = Obj->getBytesInAddress() > 4 ? "%016" PRIx64 : "%08" PRIx64; for (const SectionRef &Section : DynRelSec) { if (Section.relocation_begin() == Section.relocation_end()) continue; for (const RelocationRef &Reloc : Section.relocations()) { - uint64_t address = Reloc.getOffset(); - SmallString<32> relocname; - SmallString<32> valuestr; - Reloc.getTypeName(relocname); - error(getRelocationValueString(Reloc, valuestr)); - outs() << format(Fmt.data(), address) << " " << relocname << " " - << valuestr << "\n"; + uint64_t Address = Reloc.getOffset(); + SmallString<32> RelocName; + SmallString<32> ValueStr; + Reloc.getTypeName(RelocName); + error(getRelocationValueString(Reloc, ValueStr)); + outs() << format(Fmt.data(), Address) << " " << RelocName << " " + << ValueStr << "\n"; } } } -void llvm::PrintSectionHeaders(const ObjectFile *Obj) { +void llvm::printSectionHeaders(const ObjectFile *Obj) { outs() << "Sections:\n" "Idx Name Size Address Type\n"; for (const SectionRef &Section : ToolSectionFilter(*Obj)) { @@ -1960,7 +1946,7 @@ outs() << "\n"; } -void llvm::PrintSectionContents(const ObjectFile *Obj) { +void llvm::printSectionContents(const ObjectFile *Obj) { std::error_code EC; for (const SectionRef &Section : ToolSectionFilter(*Obj)) { StringRef Name; @@ -1982,23 +1968,23 @@ error(Section.getContents(Contents)); // Dump out the content as hex and printable ascii characters. - for (std::size_t addr = 0, end = Contents.size(); addr < end; addr += 16) { - outs() << format(" %04" PRIx64 " ", BaseAddr + addr); + for (std::size_t Addr = 0, End = Contents.size(); Addr < End; Addr += 16) { + outs() << format(" %04" PRIx64 " ", BaseAddr + Addr); // Dump line of hex. - for (std::size_t i = 0; i < 16; ++i) { - if (i != 0 && i % 4 == 0) + for (std::size_t I = 0; I < 16; ++I) { + if (I != 0 && I % 4 == 0) outs() << ' '; - if (addr + i < end) - outs() << hexdigit((Contents[addr + i] >> 4) & 0xF, true) - << hexdigit(Contents[addr + i] & 0xF, true); + if (Addr + I < End) + outs() << hexdigit((Contents[Addr + I] >> 4) & 0xF, true) + << hexdigit(Contents[Addr + I] & 0xF, true); else outs() << " "; } // Print ascii. outs() << " "; - for (std::size_t i = 0; i < 16 && addr + i < end; ++i) { - if (isPrint(static_cast(Contents[addr + i]) & 0xFF)) - outs() << Contents[addr + i]; + for (std::size_t I = 0; I < 16 && Addr + I < End; ++I) { + if (isPrint(static_cast(Contents[Addr + I]) & 0xFF)) + outs() << Contents[Addr + I]; else outs() << "."; } @@ -2007,47 +1993,47 @@ } } -void llvm::PrintSymbolTable(const ObjectFile *o, StringRef ArchiveName, +void llvm::printSymbolTable(const ObjectFile *O, StringRef ArchiveName, StringRef ArchitectureName) { outs() << "SYMBOL TABLE:\n"; - if (const COFFObjectFile *coff = dyn_cast(o)) { - printCOFFSymbolTable(coff); + if (const COFFObjectFile *Coff = dyn_cast(O)) { + printCOFFSymbolTable(Coff); return; } - for (auto I = o->symbol_begin(), E = o->symbol_end(); I != E; ++I) { + for (auto I = O->symbol_begin(), E = O->symbol_end(); I != E; ++I) { // Skip printing the special zero symbol when dumping an ELF file. // This makes the output consistent with the GNU objdump. - if (I == o->symbol_begin() && isa(o)) + if (I == O->symbol_begin() && isa(O)) continue; const SymbolRef &Symbol = *I; Expected AddressOrError = Symbol.getAddress(); if (!AddressOrError) - report_error(ArchiveName, o->getFileName(), AddressOrError.takeError(), + report_error(ArchiveName, O->getFileName(), AddressOrError.takeError(), ArchitectureName); uint64_t Address = *AddressOrError; if ((Address < StartAddress) || (Address > StopAddress)) continue; Expected TypeOrError = Symbol.getType(); if (!TypeOrError) - report_error(ArchiveName, o->getFileName(), TypeOrError.takeError(), + report_error(ArchiveName, O->getFileName(), TypeOrError.takeError(), ArchitectureName); SymbolRef::Type Type = *TypeOrError; uint32_t Flags = Symbol.getFlags(); Expected SectionOrErr = Symbol.getSection(); if (!SectionOrErr) - report_error(ArchiveName, o->getFileName(), SectionOrErr.takeError(), + report_error(ArchiveName, O->getFileName(), SectionOrErr.takeError(), ArchitectureName); section_iterator Section = *SectionOrErr; StringRef Name; - if (Type == SymbolRef::ST_Debug && Section != o->section_end()) { + if (Type == SymbolRef::ST_Debug && Section != O->section_end()) { Section->getName(Name); } else { Expected NameOrErr = Symbol.getName(); if (!NameOrErr) - report_error(ArchiveName, o->getFileName(), NameOrErr.takeError(), + report_error(ArchiveName, O->getFileName(), NameOrErr.takeError(), ArchitectureName); Name = *NameOrErr; } @@ -2071,7 +2057,7 @@ else if (Type == SymbolRef::ST_Data) FileFunc = 'O'; - const char *Fmt = o->getBytesInAddress() > 4 ? "%016" PRIx64 : + const char *Fmt = O->getBytesInAddress() > 4 ? "%016" PRIx64 : "%08" PRIx64; outs() << format(Fmt, Address) << " " @@ -2087,11 +2073,11 @@ outs() << "*ABS*"; } else if (Common) { outs() << "*COM*"; - } else if (Section == o->section_end()) { + } else if (Section == O->section_end()) { outs() << "*UND*"; } else { if (const MachOObjectFile *MachO = - dyn_cast(o)) { + dyn_cast(O)) { DataRefImpl DR = Section->getRawDataRefImpl(); StringRef SegmentName = MachO->getSectionFinalSegmentName(DR); outs() << SegmentName << ","; @@ -2102,15 +2088,14 @@ } outs() << '\t'; - if (Common || isa(o)) { + if (Common || isa(O)) { uint64_t Val = Common ? Symbol.getAlignment() : ELFSymbolRef(Symbol).getSize(); outs() << format("\t %08" PRIx64 " ", Val); } - if (Hidden) { + if (Hidden) outs() << ".hidden "; - } if (Demangle) outs() << demangle(Name) << '\n'; @@ -2119,80 +2104,68 @@ } } -static void PrintUnwindInfo(const ObjectFile *o) { +static void printUnwindInfo(const ObjectFile *O) { outs() << "Unwind info:\n\n"; - if (const COFFObjectFile *coff = dyn_cast(o)) { - printCOFFUnwindInfo(coff); - } else if (const MachOObjectFile *MachO = dyn_cast(o)) + if (const COFFObjectFile *Coff = dyn_cast(O)) + printCOFFUnwindInfo(Coff); + else if (const MachOObjectFile *MachO = dyn_cast(O)) printMachOUnwindInfo(MachO); - else { + else // TODO: Extract DWARF dump tool to objdump. WithColor::error(errs(), ToolName) << "This operation is only currently supported " "for COFF and MachO object files.\n"; - return; - } } void llvm::printExportsTrie(const ObjectFile *o) { outs() << "Exports trie:\n"; if (const MachOObjectFile *MachO = dyn_cast(o)) printMachOExportsTrie(MachO); - else { + else WithColor::error(errs(), ToolName) << "This operation is only currently supported " "for Mach-O executable files.\n"; - return; - } } void llvm::printRebaseTable(ObjectFile *o) { outs() << "Rebase table:\n"; if (MachOObjectFile *MachO = dyn_cast(o)) printMachORebaseTable(MachO); - else { + else WithColor::error(errs(), ToolName) << "This operation is only currently supported " "for Mach-O executable files.\n"; - return; - } } void llvm::printBindTable(ObjectFile *o) { outs() << "Bind table:\n"; if (MachOObjectFile *MachO = dyn_cast(o)) printMachOBindTable(MachO); - else { + else WithColor::error(errs(), ToolName) << "This operation is only currently supported " "for Mach-O executable files.\n"; - return; - } } void llvm::printLazyBindTable(ObjectFile *o) { outs() << "Lazy bind table:\n"; if (MachOObjectFile *MachO = dyn_cast(o)) printMachOLazyBindTable(MachO); - else { + else WithColor::error(errs(), ToolName) << "This operation is only currently supported " "for Mach-O executable files.\n"; - return; - } } void llvm::printWeakBindTable(ObjectFile *o) { outs() << "Weak bind table:\n"; if (MachOObjectFile *MachO = dyn_cast(o)) printMachOWeakBindTable(MachO); - else { + else WithColor::error(errs(), ToolName) << "This operation is only currently supported " "for Mach-O executable files.\n"; - return; - } } /// Dump the raw contents of the __clangast section so the output can be piped @@ -2230,7 +2203,7 @@ } static void printFaultMaps(const ObjectFile *Obj) { - const char *FaultMapSectionName = nullptr; + StringRef FaultMapSectionName; if (isa(Obj)) { FaultMapSectionName = ".llvm_faultmaps"; @@ -2270,35 +2243,35 @@ outs() << FMP; } -static void printPrivateFileHeaders(const ObjectFile *o, bool onlyFirst) { - if (o->isELF()) { - printELFFileHeader(o); - return printELFDynamicSection(o); - } - if (o->isCOFF()) - return printCOFFFileHeader(o); - if (o->isWasm()) - return printWasmFileHeader(o); - if (o->isMachO()) { - printMachOFileHeader(o); - if (!onlyFirst) - printMachOLoadCommands(o); +static void printPrivateFileHeaders(const ObjectFile *O, bool OnlyFirst) { + if (O->isELF()) { + printELFFileHeader(O); + return printELFDynamicSection(O); + } + if (O->isCOFF()) + return printCOFFFileHeader(O); + if (O->isWasm()) + return printWasmFileHeader(O); + if (O->isMachO()) { + printMachOFileHeader(O); + if (!OnlyFirst) + printMachOLoadCommands(O); return; } - report_error(o->getFileName(), "Invalid/Unsupported object file format"); + report_error(O->getFileName(), "Invalid/Unsupported object file format"); } -static void printFileHeaders(const ObjectFile *o) { - if (!o->isELF() && !o->isCOFF()) - report_error(o->getFileName(), "Invalid/Unsupported object file format"); +static void printFileHeaders(const ObjectFile *O) { + if (!O->isELF() && !O->isCOFF()) + report_error(O->getFileName(), "Invalid/Unsupported object file format"); - Triple::ArchType AT = o->getArch(); + Triple::ArchType AT = O->getArch(); outs() << "architecture: " << Triple::getArchTypeName(AT) << "\n"; - Expected StartAddrOrErr = o->getStartAddress(); + Expected StartAddrOrErr = O->getStartAddress(); if (!StartAddrOrErr) - report_error(o->getFileName(), StartAddrOrErr.takeError()); + report_error(O->getFileName(), StartAddrOrErr.takeError()); - StringRef Fmt = o->getBytesInAddress() > 4 ? "%016" PRIx64 : "%08" PRIx64; + StringRef Fmt = O->getBytesInAddress() > 4 ? "%016" PRIx64 : "%08" PRIx64; uint64_t Address = StartAddrOrErr.get(); outs() << "start address: " << "0x" << format(Fmt.data(), Address) << "\n\n"; @@ -2368,55 +2341,55 @@ outs() << Name << "\n"; } -static void DumpObject(ObjectFile *o, const Archive *a = nullptr, - const Archive::Child *c = nullptr) { - StringRef ArchiveName = a != nullptr ? a->getFileName() : ""; +static void dumpObject(ObjectFile *O, const Archive *A = nullptr, + const Archive::Child *C = nullptr) { // Avoid other output when using a raw option. if (!RawClangAST) { outs() << '\n'; - if (a) - outs() << a->getFileName() << "(" << o->getFileName() << ")"; + if (A) + outs() << A->getFileName() << "(" << O->getFileName() << ")"; else - outs() << o->getFileName(); - outs() << ":\tfile format " << o->getFileFormatName() << "\n\n"; + outs() << O->getFileName(); + outs() << ":\tfile format " << O->getFileFormatName() << "\n\n"; } + StringRef ArchiveName = A ? A->getFileName() : ""; if (FileHeaders) - printFileHeaders(o); - if (ArchiveHeaders && !MachOOpt && c) - printArchiveChild(ArchiveName, *c); + printFileHeaders(O); + if (ArchiveHeaders && !MachOOpt && C) + printArchiveChild(ArchiveName, *C); if (Disassemble) - DisassembleObject(o, Relocations); + disassembleObject(O, Relocations); if (Relocations && !Disassemble) - PrintRelocations(o); + printRelocations(O); if (DynamicRelocations) - PrintDynamicRelocations(o); + printDynamicRelocations(O); if (SectionHeaders) - PrintSectionHeaders(o); + printSectionHeaders(O); if (SectionContents) - PrintSectionContents(o); + printSectionContents(O); if (SymbolTable) - PrintSymbolTable(o, ArchiveName); + printSymbolTable(O, ArchiveName); if (UnwindInfo) - PrintUnwindInfo(o); + printUnwindInfo(O); if (PrivateHeaders || FirstPrivateHeader) - printPrivateFileHeaders(o, FirstPrivateHeader); + printPrivateFileHeaders(O, FirstPrivateHeader); if (ExportsTrie) - printExportsTrie(o); + printExportsTrie(O); if (Rebase) - printRebaseTable(o); + printRebaseTable(O); if (Bind) - printBindTable(o); + printBindTable(O); if (LazyBind) - printLazyBindTable(o); + printLazyBindTable(O); if (WeakBind) - printWeakBindTable(o); + printWeakBindTable(O); if (RawClangAST) - printRawClangAST(o); + printRawClangAST(O); if (PrintFaultMaps) - printFaultMaps(o); + printFaultMaps(O); if (DwarfDumpType != DIDT_Null) { - std::unique_ptr DICtx = DWARFContext::create(*o); + std::unique_ptr DICtx = DWARFContext::create(*O); // Dump the complete DWARF structure. DIDumpOptions DumpOpts; DumpOpts.DumpType = DwarfDumpType; @@ -2424,7 +2397,7 @@ } } -static void DumpObject(const COFFImportFile *I, const Archive *A, +static void dumpObject(const COFFImportFile *I, const Archive *A, const Archive::Child *C = nullptr) { StringRef ArchiveName = A ? A->getFileName() : ""; @@ -2442,34 +2415,33 @@ } /// Dump each object file in \a a; -static void DumpArchive(const Archive *a) { +static void dumpArchive(const Archive *A) { Error Err = Error::success(); - for (auto &C : a->children(Err)) { + for (auto &C : A->children(Err)) { Expected> ChildOrErr = C.getAsBinary(); if (!ChildOrErr) { if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError())) - report_error(a->getFileName(), C, std::move(E)); + report_error(A->getFileName(), C, std::move(E)); continue; } - if (ObjectFile *o = dyn_cast(&*ChildOrErr.get())) - DumpObject(o, a, &C); + if (ObjectFile *O = dyn_cast(&*ChildOrErr.get())) + dumpObject(O, A, &C); else if (COFFImportFile *I = dyn_cast(&*ChildOrErr.get())) - DumpObject(I, a, &C); + dumpObject(I, A, &C); else - report_error(a->getFileName(), object_error::invalid_file_type); + report_error(A->getFileName(), object_error::invalid_file_type); } if (Err) - report_error(a->getFileName(), std::move(Err)); + report_error(A->getFileName(), std::move(Err)); } /// Open file and figure out how to dump it. -static void DumpInput(StringRef file) { - +static void dumpInput(StringRef file) { // If we are using the Mach-O specific object file parser, then let it parse // the file and process the command line options. So the -arch flags can // be used to select specific slices, etc. if (MachOOpt) { - ParseInputMachO(file); + parseInputMachO(file); return; } @@ -2479,12 +2451,12 @@ report_error(file, BinaryOrErr.takeError()); Binary &Binary = *BinaryOrErr.get().getBinary(); - if (Archive *a = dyn_cast(&Binary)) - DumpArchive(a); - else if (ObjectFile *o = dyn_cast(&Binary)) - DumpObject(o); + if (Archive *A = dyn_cast(&Binary)) + dumpArchive(A); + else if (ObjectFile *O = dyn_cast(&Binary)) + dumpObject(O); else if (MachOUniversalBinary *UB = dyn_cast(&Binary)) - ParseInputMachO(UB); + parseInputMachO(UB); else report_error(file, object_error::invalid_file_type); } @@ -2550,7 +2522,7 @@ DisasmFuncsSet.insert(DisassembleFunctions.begin(), DisassembleFunctions.end()); - llvm::for_each(InputFilenames, DumpInput); + llvm::for_each(InputFilenames, dumpInput); return EXIT_SUCCESS; }