[llvm] 0ad18bf - [llvm-objdump] Suppress spurious warnings when parsing Mach-O binaries.
Michael Trent via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 3 10:59:43 PST 2020
Author: Michael Trent
Date: 2020-02-03T10:59:36-08:00
New Revision: 0ad18bf37b2d4f6a619f2ebdd6cfbe0ac617a2e5
URL: https://github.com/llvm/llvm-project/commit/0ad18bf37b2d4f6a619f2ebdd6cfbe0ac617a2e5
DIFF: https://github.com/llvm/llvm-project/commit/0ad18bf37b2d4f6a619f2ebdd6cfbe0ac617a2e5.diff
LOG: [llvm-objdump] Suppress spurious warnings when parsing Mach-O binaries.
Summary:
llvm-objdump started warning when asked to disassemble a section that
isn't present in the input files, in Yuanfang Chen's change:
d16c162c9453db855503134fe29ae4a3c0bec936. The problem is that the
logic was restricted only to the generic llvm-objdump parser, not to the
Mach-O-specific parser used for Apple toolchain compatibility. The
solution is to log section names from the Mach-O parser.
The macho-cstring-dump.test has been updated to fail if it encounters
this new warning in the future.
Reviewers: pete, ab, lhames, jhenderson, grimar, MaskRay, ychen
Reviewed By: jhenderson, grimar
Subscribers: rupprecht, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73586
Added:
Modified:
llvm/test/tools/llvm-objdump/X86/macho-cstring-dump.test
llvm/tools/llvm-objdump/MachODump.cpp
llvm/tools/llvm-objdump/llvm-objdump.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-objdump/X86/macho-cstring-dump.test b/llvm/test/tools/llvm-objdump/X86/macho-cstring-dump.test
index 0e19f51d6a63..ae472076cdfe 100644
--- 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,9 @@
-RUN: llvm-objdump -m -section __TEXT,__cstring %p/Inputs/hello.obj.macho-x86_64 | 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
+RUN: llvm-objdump -m -section __TEXT,__cstring %p/Inputs/hello.obj.macho-x86_64 2>&1 | FileCheck %s --implicit-check-not="warning:"
+RUN: llvm-objdump -m -section __TEXT,__cstring -no-leading-addr %p/Inputs/hello.obj.macho-x86_64 | FileCheck %s -check-prefix=NO_ADDR --implicit-check-not="warning:"
+RUN: llvm-objdump -m -section __TEXT,__cstring -non-verbose %p/Inputs/hello.obj.macho-x86_64 | FileCheck %s -check-prefix=NON_VERBOSE --implicit-check-not="warning:"
CHECK: Contents of (__TEXT,__cstring) section
-CHECK: 000000000000003b Hello world\n
+CHECK-NEXT: 000000000000003b Hello world\n
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
index a55ddb70e2c4..354aa1ba156b 100644
--- 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 @@ static cl::list<std::string>
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;
@@ -1754,6 +1757,9 @@ static void DumpSectionContents(StringRef Filename, MachOObjectFile *O,
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
index 6c95d366040f..dc8a4b705c53 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -338,7 +338,7 @@ static cl::extrahelp
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<std::tuple<uint64_t, StringRef, uint8_t>> SectionSymbolsTy;
More information about the llvm-commits
mailing list