diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp index ac4de273f45769..aa71998c2f6608 100644 --- a/llvm/tools/llvm-objdump/MachODump.cpp +++ b/llvm/tools/llvm-objdump/MachODump.cpp @@ -16,7 +16,6 @@ #include "llvm-c/Disassembler.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" -#include "llvm/ADT/StringSet.h" #include "llvm/ADT/Triple.h" #include "llvm/BinaryFormat/MachO.h" #include "llvm/Config/config.h" @@ -178,11 +177,7 @@ static cl::list ArchFlags("arch", cl::desc("architecture(s) from a Mach-O file to dump"), cl::ZeroOrMore, cl::cat(MachOCat)); -namespace llvm { - -extern StringSet<> FoundSectionSet; - -bool ArchAll = false; +static bool ArchAll = false; static std::string ThumbTripleName; @@ -224,6 +219,7 @@ static const Target *GetTarget(const MachOObjectFile *MachOObj, return nullptr; } +namespace { struct SymbolSorter { bool operator()(const SymbolRef &A, const SymbolRef &B) { Expected ATypeOrErr = A.getType(); @@ -239,6 +235,7 @@ struct SymbolSorter { return AAddr < BAddr; } }; +} // namespace // Types for the storted data in code table that is built before disassembly // and the predicate function to sort them. @@ -488,9 +485,9 @@ static void printRelocationTargetName(const MachOObjectFile *O, Fmt << S; } -Error getMachORelocationValueString(const MachOObjectFile *Obj, - const RelocationRef &RelRef, - SmallVectorImpl &Result) { +Error objdump::getMachORelocationValueString(const MachOObjectFile *Obj, + const RelocationRef &RelRef, + SmallVectorImpl &Result) { DataRefImpl Rel = RelRef.getRawDataRefImpl(); MachO::any_relocation_info RE = Obj->getRelocation(Rel); @@ -2313,7 +2310,7 @@ static bool ValidateArchFlags() { // -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 parseInputMachO(StringRef Filename) { +void objdump::parseInputMachO(StringRef Filename) { if (!ValidateArchFlags()) return; @@ -2371,7 +2368,7 @@ void parseInputMachO(StringRef Filename) { llvm_unreachable("Input object can't be invalid at this point"); } -void parseInputMachO(MachOUniversalBinary *UB) { +void objdump::parseInputMachO(MachOUniversalBinary *UB) { if (!ValidateArchFlags()) return; @@ -2557,6 +2554,7 @@ void parseInputMachO(MachOUniversalBinary *UB) { } } +namespace { // The block of info used by the Symbolizer call backs. struct DisassembleInfo { DisassembleInfo(MachOObjectFile *O, SymbolAddressMap *AddrMap, @@ -2576,6 +2574,7 @@ struct DisassembleInfo { std::unique_ptr bindtable; uint32_t depth = 0; }; +} // namespace // SymbolizerGetOpInfo() is the operand information call back function. // This is called to get the symbolic information for operand(s) of an @@ -3384,6 +3383,8 @@ static const char *get_symbol_32(uint32_t sect_offset, SectionRef S, return get_symbol_64(sect_offset, S, info, n_value64, ReferenceValue); } +namespace { + // These are structs in the Objective-C meta data and read to produce the // comments for disassembly. While these are part of the ABI they are no // public defintions. So the are here not in include/llvm/BinaryFormat/MachO.h @@ -3969,6 +3970,8 @@ inline void swapStruct(struct objc_method_description_t &md) { sys::swapByteOrder(md.types); } +} // namespace + static const char *get_dyld_bind_info_symbolname(uint64_t ReferenceValue, struct DisassembleInfo *info); @@ -6468,7 +6471,7 @@ static void DumpProtocolSection(MachOObjectFile *O, const char *sect, } #ifdef HAVE_LIBXAR -inline void swapStruct(struct xar_header &xar) { +static inline void swapStruct(struct xar_header &xar) { sys::swapByteOrder(xar.magic); sys::swapByteOrder(xar.size); sys::swapByteOrder(xar.version); @@ -8189,7 +8192,7 @@ static void printMachOUnwindInfoSection(const MachOObjectFile *Obj, } } -void printMachOUnwindInfo(const MachOObjectFile *Obj) { +void objdump::printMachOUnwindInfo(const MachOObjectFile *Obj) { std::map Symbols; for (const SymbolRef &SymRef : Obj->symbols()) { // Discard any undefined or absolute symbols. They're not going to take part @@ -10197,12 +10200,12 @@ static void PrintMachHeader(const MachOObjectFile *Obj, bool verbose) { } } -void printMachOFileHeader(const object::ObjectFile *Obj) { +void objdump::printMachOFileHeader(const object::ObjectFile *Obj) { const MachOObjectFile *file = dyn_cast(Obj); PrintMachHeader(file, !NonVerbose); } -void printMachOLoadCommands(const object::ObjectFile *Obj) { +void objdump::printMachOLoadCommands(const object::ObjectFile *Obj) { const MachOObjectFile *file = dyn_cast(Obj); uint32_t filetype = 0; uint32_t cputype = 0; @@ -10224,7 +10227,7 @@ void printMachOLoadCommands(const object::ObjectFile *Obj) { // export trie dumping //===----------------------------------------------------------------------===// -void printMachOExportsTrie(const object::MachOObjectFile *Obj) { +static void printMachOExportsTrie(const object::MachOObjectFile *Obj) { uint64_t BaseSegmentAddress = 0; for (const auto &Command : Obj->load_commands()) { if (Command.C.cmd == MachO::LC_SEGMENT) { @@ -10303,7 +10306,7 @@ void printMachOExportsTrie(const object::MachOObjectFile *Obj) { // rebase table dumping //===----------------------------------------------------------------------===// -void printMachORebaseTable(object::MachOObjectFile *Obj) { +static void printMachORebaseTable(object::MachOObjectFile *Obj) { outs() << "segment section address type\n"; Error Err = Error::success(); for (const object::MachORebaseEntry &Entry : Obj->rebaseTable(Err)) { @@ -10345,7 +10348,7 @@ static StringRef ordinalName(const object::MachOObjectFile *Obj, int Ordinal) { // bind table dumping //===----------------------------------------------------------------------===// -void printMachOBindTable(object::MachOObjectFile *Obj) { +static void printMachOBindTable(object::MachOObjectFile *Obj) { // Build table of sections so names can used in final output. outs() << "segment section address type " "addend dylib symbol\n"; @@ -10376,7 +10379,7 @@ void printMachOBindTable(object::MachOObjectFile *Obj) { // lazy bind table dumping //===----------------------------------------------------------------------===// -void printMachOLazyBindTable(object::MachOObjectFile *Obj) { +static void printMachOLazyBindTable(object::MachOObjectFile *Obj) { outs() << "segment section address " "dylib symbol\n"; Error Err = Error::success(); @@ -10401,7 +10404,7 @@ void printMachOLazyBindTable(object::MachOObjectFile *Obj) { // weak bind table dumping //===----------------------------------------------------------------------===// -void printMachOWeakBindTable(object::MachOObjectFile *Obj) { +static void printMachOWeakBindTable(object::MachOObjectFile *Obj) { outs() << "segment section address " "type addend symbol\n"; Error Err = Error::success(); @@ -10451,7 +10454,7 @@ static const char *get_dyld_bind_info_symbolname(uint64_t ReferenceValue, return !name.empty() ? name.data() : nullptr; } -void printLazyBindTable(ObjectFile *o) { +void objdump::printLazyBindTable(ObjectFile *o) { outs() << "Lazy bind table:\n"; if (MachOObjectFile *MachO = dyn_cast(o)) printMachOLazyBindTable(MachO); @@ -10461,7 +10464,7 @@ void printLazyBindTable(ObjectFile *o) { "for Mach-O executable files.\n"; } -void printWeakBindTable(ObjectFile *o) { +void objdump::printWeakBindTable(ObjectFile *o) { outs() << "Weak bind table:\n"; if (MachOObjectFile *MachO = dyn_cast(o)) printMachOWeakBindTable(MachO); @@ -10471,7 +10474,7 @@ void printWeakBindTable(ObjectFile *o) { "for Mach-O executable files.\n"; } -void printExportsTrie(const ObjectFile *o) { +void objdump::printExportsTrie(const ObjectFile *o) { outs() << "Exports trie:\n"; if (const MachOObjectFile *MachO = dyn_cast(o)) printMachOExportsTrie(MachO); @@ -10481,7 +10484,7 @@ void printExportsTrie(const ObjectFile *o) { "for Mach-O executable files.\n"; } -void printRebaseTable(ObjectFile *o) { +void objdump::printRebaseTable(ObjectFile *o) { outs() << "Rebase table:\n"; if (MachOObjectFile *MachO = dyn_cast(o)) printMachORebaseTable(MachO); @@ -10491,7 +10494,7 @@ void printRebaseTable(ObjectFile *o) { "for Mach-O executable files.\n"; } -void printBindTable(ObjectFile *o) { +void objdump::printBindTable(ObjectFile *o) { outs() << "Bind table:\n"; if (MachOObjectFile *MachO = dyn_cast(o)) printMachOBindTable(MachO); @@ -10500,4 +10503,3 @@ void printBindTable(ObjectFile *o) { << "This operation is only currently supported " "for Mach-O executable files.\n"; } -} // namespace llvm diff --git a/llvm/tools/llvm-objdump/MachODump.h b/llvm/tools/llvm-objdump/MachODump.h index 252b0f417af863..adf6c3404f7900 100644 --- a/llvm/tools/llvm-objdump/MachODump.h +++ b/llvm/tools/llvm-objdump/MachODump.h @@ -9,9 +9,21 @@ #ifndef LLVM_TOOLS_LLVM_OBJDUMP_MACHODUMP_H #define LLVM_TOOLS_LLVM_OBJDUMP_MACHODUMP_H +#include "llvm/ADT/SmallVector.h" #include "llvm/Support/CommandLine.h" namespace llvm { + +class Error; +class StringRef; + +namespace object { +class MachOObjectFile; +class MachOUniversalBinary; +class ObjectFile; +class RelocationRef; +} // namespace object + namespace objdump { // MachO specific options @@ -31,6 +43,23 @@ extern cl::opt Rebase; extern cl::opt UniversalHeaders; extern cl::opt WeakBind; +Error getMachORelocationValueString(const object::MachOObjectFile *Obj, + const object::RelocationRef &RelRef, + llvm::SmallVectorImpl &Result); + +void parseInputMachO(StringRef Filename); +void parseInputMachO(object::MachOUniversalBinary *UB); + +void printMachOUnwindInfo(const object::MachOObjectFile *O); +void printMachOFileHeader(const object::ObjectFile *O); +void printMachOLoadCommands(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); + } // namespace objdump } // namespace llvm diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 2f9c6f13ed1998..f407f149b5d696 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -345,10 +345,8 @@ static cl::alias WideShort("w", cl::Grouping, cl::aliasopt(Wide)); static cl::extrahelp HelpResponse("\nPass @FILE as argument to read options from FILE.\n"); -namespace llvm { - static StringSet<> DisasmSymbolSet; -StringSet<> FoundSectionSet; +StringSet<> objdump::FoundSectionSet; static StringRef ToolName; namespace { @@ -386,6 +384,8 @@ static FilterResult checkSectionFilter(object::SectionRef S) { /*IncrementIndex=*/true}; } +namespace llvm { + SectionFilter ToolSectionFilter(object::ObjectFile const &O, uint64_t *Idx) { // Start at UINT64_MAX so that the first index returned after an increment is // zero (after the unsigned wrap). diff --git a/llvm/tools/llvm-objdump/llvm-objdump.h b/llvm/tools/llvm-objdump/llvm-objdump.h index 5b74c1d883f00a..931ef02310228c 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.h +++ b/llvm/tools/llvm-objdump/llvm-objdump.h @@ -8,11 +8,12 @@ #ifndef LLVM_TOOLS_LLVM_OBJDUMP_LLVM_OBJDUMP_H #define LLVM_TOOLS_LLVM_OBJDUMP_LLVM_OBJDUMP_H +#include "llvm/ADT/StringSet.h" #include "llvm/DebugInfo/DIContext.h" +#include "llvm/Object/Archive.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/DataTypes.h" -#include "llvm/Object/Archive.h" namespace llvm { class StringRef; @@ -46,6 +47,8 @@ extern cl::opt SymbolTable; extern cl::opt TripleName; extern cl::opt UnwindInfo; +extern StringSet<> FoundSectionSet; + } // namespace objdump typedef std::function FilterPredicate; @@ -118,32 +121,14 @@ Error getELFRelocationValueString(const object::ELFObjectFileBase *Obj, Error getWasmRelocationValueString(const object::WasmObjectFile *Obj, const object::RelocationRef &RelRef, llvm::SmallVectorImpl &Result); -Error getMachORelocationValueString(const object::MachOObjectFile *Obj, - const object::RelocationRef &RelRef, - llvm::SmallVectorImpl &Result); uint64_t getELFSectionLMA(const object::ELFSectionRef& Sec); bool isRelocAddressLess(object::RelocationRef A, object::RelocationRef B); -void parseInputMachO(StringRef Filename); -void parseInputMachO(object::MachOUniversalBinary *UB); -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 printELFSymbolVersionInfo(const object::ObjectFile *Obj); -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);