Index: llvm/include/llvm/ADT/StringMap.h =================================================================== --- llvm/include/llvm/ADT/StringMap.h +++ llvm/include/llvm/ADT/StringMap.h @@ -359,6 +359,11 @@ return find(Key) == end() ? 0 : 1; } + template + size_type count(const StringMapEntry &MapEntry) const { + return count(MapEntry.getKey()); + } + /// insert - Insert the specified key/value pair into the map. If the key /// already exists in the map, return false and ignore the request, otherwise /// insert it and return true. Index: llvm/include/llvm/ADT/StringSet.h =================================================================== --- llvm/include/llvm/ADT/StringSet.h +++ llvm/include/llvm/ADT/StringSet.h @@ -45,6 +45,12 @@ for (auto It = Begin; It != End; ++It) base::insert(std::make_pair(*It, '\0')); } + + template + std::pair + insert(const StringMapEntry &MapEntry) { + return insert(MapEntry.getKey()); + } }; } // end namespace llvm Index: llvm/test/tools/llvm-objdump/X86/warn-missing-disasm-func.test =================================================================== --- /dev/null +++ llvm/test/tools/llvm-objdump/X86/warn-missing-disasm-func.test @@ -0,0 +1,12 @@ +## Warn if --disassemble-functions specifies an unknown symbol +# RUN: yaml2obj %s | llvm-objdump - --disassemble-functions=foo 2>&1 | FileCheck %s + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +... + +# CHECK: warning: Failed to disassemble missing function foo. Index: llvm/tools/llvm-objdump/llvm-objdump.cpp =================================================================== --- llvm/tools/llvm-objdump/llvm-objdump.cpp +++ llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -18,6 +18,7 @@ #include "llvm-objdump.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SetOperations.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSet.h" #include "llvm/ADT/Triple.h" @@ -375,6 +376,11 @@ errs().flush(); } +void warn(const Twine &Message) { + SmallVector MessageVec; + warn(Message.toStringRef(MessageVec)); +} + LLVM_ATTRIBUTE_NORETURN void report_error(StringRef File, Twine Message) { WithColor::error(errs(), ToolName) << "'" << File << "': " << Message << ".\n"; @@ -1090,6 +1096,7 @@ // Sort all the symbols, this allows us to use a simple binary search to find // a symbol near an address. + StringSet<> FoundDisasmFuncsSet; for (std::pair &SecSyms : AllSymbols) array_pod_sort(SecSyms.second.begin(), SecSyms.second.end()); array_pod_sort(AbsoluteSymbols.begin(), AbsoluteSymbols.end()); @@ -1176,6 +1183,8 @@ if (!DisasmFuncsSet.empty() && !DisasmFuncsSet.count(std::get<1>(Symbols[SI]))) continue; + else + FoundDisasmFuncsSet.insert(std::get<1>(Symbols[SI])); uint64_t Start = std::get<0>(Symbols[SI]); if (Start < SectionAddr || StopAddress <= Start) @@ -1400,6 +1409,11 @@ } } } + auto MissingDisasmFuncsSet = + set_difference(DisasmFuncsSet, FoundDisasmFuncsSet); + if (!MissingDisasmFuncsSet.empty()) + for (const StringRef &MissingDisasmFunc : MissingDisasmFuncsSet.keys()) + warn("Failed to disassemble missing function " + MissingDisasmFunc); } static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) {