diff options
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r-- | llvm/tools/llvm-objdump/llvm-objdump.cpp | 29 |
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 f45559b..8045b94 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; } |