[PATCH] D73586: Suppress spurious warnings when parsing Mach-O bianries.
Michael Trent via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 28 14:43:58 PST 2020
mtrent created this revision.
mtrent added reviewers: pete, ab, lhames, jhenderson, grimar, MaskRay, ychen.
Herald added subscribers: llvm-commits, rupprecht.
Herald added a project: LLVM.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D73586
Files:
llvm/test/tools/llvm-objdump/X86/macho-cstring-dump.test
llvm/tools/llvm-objdump/MachODump.cpp
llvm/tools/llvm-objdump/llvm-objdump.cpp
Index: llvm/tools/llvm-objdump/llvm-objdump.cpp
===================================================================
--- llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ 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<std::tuple<uint64_t, StringRef, uint8_t>> SectionSymbolsTy;
Index: llvm/tools/llvm-objdump/MachODump.cpp
===================================================================
--- llvm/tools/llvm-objdump/MachODump.cpp
+++ 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<StringRef> 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) &&
Index: llvm/test/tools/llvm-objdump/X86/macho-cstring-dump.test
===================================================================
--- llvm/test/tools/llvm-objdump/X86/macho-cstring-dump.test
+++ 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73586.241001.patch
Type: text/x-patch
Size: 3045 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200128/6bcdd39e/attachment.bin>
More information about the llvm-commits
mailing list