diff --git a/test/tools/llvm-objdump/section-filter.test b/test/tools/llvm-objdump/section-filter.test index 911ff5b4252..9c7ab31b0d7 100644 --- a/test/tools/llvm-objdump/section-filter.test +++ b/test/tools/llvm-objdump/section-filter.test @@ -1,6 +1,6 @@ // This test checks that --section works correctly // RUN: llvm-objdump -h %p/Inputs/section-filter.obj -j=.text \ -// RUN: -j=.bss | FileCheck %s +// RUN: --section=.bss | FileCheck %s # CHECK: .text # CHECK-NOT: .data diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index 04c72f4856c..7b868fa9d0d 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -97,11 +97,6 @@ cl::opt cl::desc("Print the linker optimization hints for " "Mach-O objects (requires -macho)")); -cl::list - llvm::DumpSections("section", - cl::desc("Prints the specified segment,section for " - "Mach-O objects (requires -macho)")); - cl::opt llvm::InfoPlist("info-plist", cl::desc("Print the info plist section as strings for " @@ -1006,8 +1001,8 @@ static void DumpSectionContents(StringRef Filename, MachOObjectFile *O, if (verbose) CreateSymbolAddressMap(O, &AddrMap); - for (unsigned i = 0; i < DumpSections.size(); ++i) { - StringRef DumpSection = DumpSections[i]; + for (unsigned i = 0; i < FilterSections.size(); ++i) { + StringRef DumpSection = FilterSections[i]; std::pair DumpSegSectName; DumpSegSectName = DumpSection.split(','); StringRef DumpSegName, DumpSectName; @@ -1171,7 +1166,7 @@ static void ProcessMachO(StringRef Filename, MachOObjectFile *MachOOF, // UniversalHeaders or ArchiveHeaders. if (Disassemble || PrivateHeaders || ExportsTrie || Rebase || Bind || LazyBind || WeakBind || IndirectSymbols || DataInCode || LinkOptHints || - DylibsUsed || DylibId || ObjcMetaData || (DumpSections.size() != 0)) { + DylibsUsed || DylibId || ObjcMetaData || (FilterSections.size() != 0)) { outs() << Filename; if (!ArchiveMemberName.empty()) outs() << '(' << ArchiveMemberName << ')'; @@ -1194,7 +1189,7 @@ static void ProcessMachO(StringRef Filename, MachOObjectFile *MachOOF, PrintSectionHeaders(MachOOF); if (SectionContents) PrintSectionContents(MachOOF); - if (DumpSections.size() != 0) + if (FilterSections.size() != 0) DumpSectionContents(Filename, MachOOF, !NonVerbose); if (InfoPlist) DumpInfoPlistSectionContents(Filename, MachOOF); @@ -6065,7 +6060,7 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF, diContext.reset(new DWARFContextInMemory(*DbgObj)); } - if (DumpSections.size() == 0) + if (FilterSections.size() == 0) outs() << "(" << DisSegName << "," << DisSectName << ") section\n"; for (unsigned SectIdx = 0; SectIdx != Sections.size(); SectIdx++) { diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index af8bc4a44b8..97243cb8016 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -135,8 +135,13 @@ SectionHeadersShort("headers", cl::desc("Alias for --section-headers"), static cl::alias SectionHeadersShorter("h", cl::desc("Alias for --section-headers"), cl::aliasopt(SectionHeaders)); + cl::list -llvm::Sections("j", cl::desc("Operate on the specified sections only")); +llvm::FilterSections("section", cl::desc("Operate on the specified sections only. " + "With -macho dump segment,section")); +cl::alias +static FilterSectionsj("j", cl::desc("Alias for --section"), + cl::aliasopt(llvm::FilterSections)); cl::list llvm::MAttrs("mattr", @@ -175,7 +180,7 @@ static StringRef ToolName; static int ReturnValue = EXIT_SUCCESS; namespace { -typedef std::function FilterPredicate; +typedef std::function FilterPredicate; class SectionFilterIterator { public: @@ -224,20 +229,16 @@ private: llvm::object::ObjectFile const &Object; }; SectionFilter ToolSectionFilter(llvm::object::ObjectFile const &O) { - if (Sections.empty()) { - return SectionFilter([](llvm::object::SectionRef const &) { return 0; }, O); - } return SectionFilter([](llvm::object::SectionRef const &S) { + if(FilterSections.empty()) + return false; llvm::StringRef String; std::error_code error = S.getName(String); - if (error) { - return error.value(); - } - if (std::find(Sections.begin(), Sections.end(), - String) != Sections.end()) { - return 0; - } - return 1; + if (error) + return true; + return std::find(FilterSections.begin(), + FilterSections.end(), + String) == FilterSections.end(); }, O); } @@ -1616,7 +1617,7 @@ int main(int argc, char **argv) { && !(DylibsUsed && MachOOpt) && !(DylibId && MachOOpt) && !(ObjcMetaData && MachOOpt) - && !(DumpSections.size() != 0 && MachOOpt) + && !(FilterSections.size() != 0 && MachOOpt) && !PrintFaultMaps) { cl::PrintHelpMessage(); return 2; diff --git a/tools/llvm-objdump/llvm-objdump.h b/tools/llvm-objdump/llvm-objdump.h index de737f5d2e9..b19c515d3c5 100644 --- a/tools/llvm-objdump/llvm-objdump.h +++ b/tools/llvm-objdump/llvm-objdump.h @@ -25,8 +25,7 @@ extern cl::opt TripleName; extern cl::opt ArchName; extern cl::opt MCPU; extern cl::list MAttrs; -extern cl::list Sections; -extern cl::list DumpSections; +extern cl::list FilterSections; extern cl::opt Disassemble; extern cl::opt DisassembleAll; extern cl::opt NoShowRawInsn;