diff --git a/llvm/test/tools/llvm-objdump/X86/macho-cstring-dump.test b/llvm/test/tools/llvm-objdump/X86/macho-cstring-dump.test --- a/llvm/test/tools/llvm-objdump/X86/macho-cstring-dump.test +++ b/llvm/test/tools/llvm-objdump/X86/macho-cstring-dump.test @@ -1,9 +1,11 @@ -RUN: llvm-objdump -m -section __TEXT,__cstring %p/Inputs/hello.obj.macho-x86_64 | FileCheck %s +RUN: llvm-objdump -m -section __TEXT,__cstring %p/Inputs/hello.obj.macho-x86_64 2>&1 | FileCheck %s RUN: llvm-objdump -m -section __TEXT,__cstring -no-leading-addr %p/Inputs/hello.obj.macho-x86_64 | FileCheck %s -check-prefix=NO_ADDR RUN: llvm-objdump -m -section __TEXT,__cstring -non-verbose %p/Inputs/hello.obj.macho-x86_64 | FileCheck %s -check-prefix=NON_VERBOSE +CHECK-NOT: warning: section '__TEXT,__cstring' mentioned in a -j/--section option, but not found in any input file CHECK: Contents of (__TEXT,__cstring) section -CHECK: 000000000000003b Hello world\n +CHECK-NEXT: 000000000000003b Hello world\n +CHECK-NOT: warning: section '__TEXT,__cstring' mentioned in a -j/--section option, but not found in any input file NO_ADDR: Contents of (__TEXT,__cstring) section NO_ADDR: Hello world\n diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp --- a/llvm/tools/llvm-objdump/MachODump.cpp +++ b/llvm/tools/llvm-objdump/MachODump.cpp @@ -14,6 +14,7 @@ #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" @@ -191,6 +192,8 @@ ArchFlags("arch", cl::desc("architecture(s) from a Mach-O file to dump"), cl::ZeroOrMore, cl::cat(MachOCat)); +extern StringSet<> FoundSectionSet; + bool ArchAll = false; static std::string ThumbTripleName; @@ -1747,13 +1750,16 @@ DumpSectName = DumpSegSectName.first; } for (const SectionRef &Section : O->sections()) { - StringRef SectName; + StringRef SectName = StringRef(); Expected SecNameOrErr = Section.getName(); if (SecNameOrErr) SectName = *SecNameOrErr; else consumeError(SecNameOrErr.takeError()); + if (!DumpSection.empty()) + FoundSectionSet.insert(DumpSection); + DataRefImpl Ref = Section.getRawDataRefImpl(); StringRef SegName = O->getSectionFinalSegmentName(Ref); if ((DumpSegName.empty() || SegName == DumpSegName) && diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -338,7 +338,7 @@ HelpResponse("\nPass @FILE as argument to read options from FILE.\n"); static StringSet<> DisasmFuncsSet; -static StringSet<> FoundSectionSet; +StringSet<> FoundSectionSet; static StringRef ToolName; typedef std::vector> SectionSymbolsTy;