summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-objdump
diff options
context:
space:
mode:
authorYuanfang Chen <yuanfang.chen@sony.com>2019-07-02 18:38:17 +0000
committerYuanfang Chen <yuanfang.chen@sony.com>2019-07-02 18:38:17 +0000
commitd16c162c9453db855503134fe29ae4a3c0bec936 (patch)
tree7001de08035406756f971c28b712aeca36571b07 /llvm/tools/llvm-objdump
parenteee944e7f9e60df44714eb547d0b876ee5dc7290 (diff)
downloadbcm5719-llvm-d16c162c9453db855503134fe29ae4a3c0bec936.tar.gz
bcm5719-llvm-d16c162c9453db855503134fe29ae4a3c0bec936.zip
[llvm-objdump] Warn if no user specified sections (-j) are not found.
Match GNU objdump. https://bugs.llvm.org/show_bug.cgi?id=41898 Reviewers: jhenderson, grimar, MaskRay, rupprecht Reviewed by: jhenderson, grimar, MaskRay Differential Revision: https://reviews.llvm.org/D63779 llvm-svn: 364955
Diffstat (limited to 'llvm/tools/llvm-objdump')
-rw-r--r--llvm/tools/llvm-objdump/llvm-objdump.cpp29
1 files changed, 26 insertions, 3 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index f45559b5497..8045b942402 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -336,6 +336,7 @@ static cl::extrahelp
HelpResponse("\nPass @FILE as argument to read options from FILE.\n");
static StringSet<> DisasmFuncsSet;
+static StringSet<> FoundSectionSet;
static StringRef ToolName;
typedef std::vector<std::tuple<uint64_t, StringRef, uint8_t>> SectionSymbolsTy;
@@ -343,11 +344,15 @@ typedef std::vector<std::tuple<uint64_t, StringRef, uint8_t>> SectionSymbolsTy;
static bool shouldKeep(object::SectionRef S) {
if (FilterSections.empty())
return true;
- StringRef String;
- std::error_code error = S.getName(String);
+ StringRef SecName;
+ std::error_code error = S.getName(SecName);
if (error)
return false;
- return is_contained(FilterSections, String);
+ // StringSet does not allow empty key so avoid adding sections with
+ // no name (such as the section with index 0) here.
+ if (!SecName.empty())
+ FoundSectionSet.insert(SecName);
+ return is_contained(FilterSections, SecName);
}
SectionFilter ToolSectionFilter(object::ObjectFile const &O) {
@@ -434,6 +439,22 @@ LLVM_ATTRIBUTE_NORETURN void report_error(Error E, StringRef ArchiveName,
report_error(std::move(E), ArchiveName, NameOrErr.get(), ArchitectureName);
}
+static void warnOnNoMatchForSections() {
+ SetVector<StringRef> MissingSections;
+ for (StringRef S : FilterSections) {
+ if (FoundSectionSet.count(S))
+ return;
+ // User may specify a unnamed section. Don't warn for it.
+ if (!S.empty())
+ MissingSections.insert(S);
+ }
+
+ // Warn only if no section in FilterSections is matched.
+ for (StringRef S : MissingSections)
+ warn("section '" + S + "' mentioned in a -j/--section option, but not "
+ "found in any input file");
+}
+
static const Target *getTarget(const ObjectFile *Obj = nullptr) {
// Figure out the target triple.
Triple TheTriple("unknown-unknown-unknown");
@@ -2157,5 +2178,7 @@ int main(int argc, char **argv) {
llvm::for_each(InputFilenames, dumpInput);
+ warnOnNoMatchForSections();
+
return EXIT_SUCCESS;
}
OpenPOWER on IntegriCloud