[llvm] r362838 - [llvm-objdump] Add warning if --disassemble-functions specifies an unknown symbol
Michael Pozulp via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 7 13:34:32 PDT 2019
Author: pozulp
Date: Fri Jun 7 13:34:31 2019
New Revision: 362838
URL: http://llvm.org/viewvc/llvm-project?rev=362838&view=rev
Log:
[llvm-objdump] Add warning if --disassemble-functions specifies an unknown symbol
Summary:
Fixes Bug 41904 https://bugs.llvm.org/show_bug.cgi?id=41904
Re-land r362768 after it was reverted in r362826.
Reviewers: jhenderson, rupprecht, grimar, MaskRay
Reviewed By: jhenderson, rupprecht, MaskRay
Subscribers: dexonsmith, rupprecht, kristina, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D62275
Added:
llvm/trunk/test/tools/llvm-objdump/X86/warn-missing-disasm-func.test
Modified:
llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
Added: llvm/trunk/test/tools/llvm-objdump/X86/warn-missing-disasm-func.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/X86/warn-missing-disasm-func.test?rev=362838&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/X86/warn-missing-disasm-func.test (added)
+++ llvm/trunk/test/tools/llvm-objdump/X86/warn-missing-disasm-func.test Fri Jun 7 13:34:31 2019
@@ -0,0 +1,11 @@
+## 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
Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=362838&r1=362837&r2=362838&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Fri Jun 7 13:34:31 2019
@@ -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,10 @@ void warn(StringRef Message) {
errs().flush();
}
+void warn(Twine Message) {
+ WithColor::warning(errs(), ToolName) << Message << "\n";
+}
+
LLVM_ATTRIBUTE_NORETURN void report_error(StringRef File, Twine Message) {
WithColor::error(errs(), ToolName)
<< "'" << File << "': " << Message << ".\n";
@@ -1091,6 +1096,7 @@ static void disassembleObject(const Targ
// 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<const SectionRef, SectionSymbolsTy> &SecSyms : AllSymbols)
array_pod_sort(SecSyms.second.begin(), SecSyms.second.end());
array_pod_sort(AbsoluteSymbols.begin(), AbsoluteSymbols.end());
@@ -1182,6 +1188,8 @@ static void disassembleObject(const Targ
uint64_t Start = std::get<0>(Symbols[SI]);
if (Start < SectionAddr || StopAddress <= Start)
continue;
+ else
+ FoundDisasmFuncsSet.insert(std::get<1>(Symbols[SI]));
// The end is the section end, the beginning of the next symbol, or
// --stop-address.
@@ -1402,6 +1410,10 @@ static void disassembleObject(const Targ
}
}
}
+ StringSet<> MissingDisasmFuncsSet =
+ set_difference(DisasmFuncsSet, FoundDisasmFuncsSet);
+ for (StringRef MissingDisasmFunc : MissingDisasmFuncsSet.keys())
+ warn("failed to disassemble missing function " + MissingDisasmFunc);
}
static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
More information about the llvm-commits
mailing list