[llvm] r241830 - [llvm-objdump] Require that jump targets shown in -d are functions

David Majnemer david.majnemer at gmail.com
Thu Jul 9 11:11:40 PDT 2015


Author: majnemer
Date: Thu Jul  9 13:11:40 2015
New Revision: 241830

URL: http://llvm.org/viewvc/llvm-project?rev=241830&view=rev
Log:
[llvm-objdump] Require that jump targets shown in -d are functions

Don't let the disassembler pick call <.text> if a function happens to
live at the start of the section by only using function symbols.

Modified:
    llvm/trunk/test/MC/X86/AlignedBundling/nesting.s
    llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp

Modified: llvm/trunk/test/MC/X86/AlignedBundling/nesting.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/X86/AlignedBundling/nesting.s?rev=241830&r1=241829&r2=241830&view=diff
==============================================================================
--- llvm/trunk/test/MC/X86/AlignedBundling/nesting.s (original)
+++ llvm/trunk/test/MC/X86/AlignedBundling/nesting.s Thu Jul  9 13:11:40 2015
@@ -7,6 +7,7 @@
   .bundle_align_mode 4
   .text
 # CHECK-LABEL: foo:
+.type   foo, at function
 foo:
 # Test that bundle alignment mode can be set more than once.
   .bundle_align_mode 4
@@ -24,6 +25,7 @@ foo:
 
   .p2align 4
 # CHECK-LABEL: bar:
+.type   bar, at function
 bar:
   callq foo
   callq foo
@@ -39,6 +41,7 @@ bar:
 # CHECK-NEXT: 3b: callq {{.*}} <bar>
 
 # CHECK-LABEL: baz:
+.type   baz, at function
 baz:
   callq foo
   callq foo
@@ -54,6 +57,7 @@ baz:
 # CHECK-NEXT: 5b: callq {{.*}} <bar>
 
 # CHECK-LABEL: quux
+.type   quux, at function
 quux:
   callq bar
   callq bar

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=241830&r1=241829&r2=241830&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Thu Jul  9 13:11:40 2015
@@ -817,6 +817,9 @@ static void DisassembleObject(const Obje
   std::vector<std::pair<uint64_t, StringRef>> AllSymbols;
   if (MIA) {
     for (const SymbolRef &Symbol : Obj->symbols()) {
+      if (Symbol.getType() != SymbolRef::ST_Function)
+        continue;
+
       ErrorOr<uint64_t> AddressOrErr = Symbol.getAddress();
       if (error(AddressOrErr.getError()))
         break;
@@ -937,17 +940,25 @@ static void DisassembleObject(const Obje
                         SectionAddr + Index, outs(), "", *STI);
           outs() << CommentStream.str();
           Comments.clear();
-          if (MIA && (MIA->isCall(Inst) || MIA->isUnconditionalBranch(Inst))) {
+          if (MIA && (MIA->isCall(Inst) || MIA->isUnconditionalBranch(Inst) ||
+                      MIA->isConditionalBranch(Inst))) {
             uint64_t Target;
             if (MIA->evaluateBranch(Inst, SectionAddr + Index, Size, Target)) {
-              const auto &TargetSym =
-                  std::lower_bound(AllSymbols.begin(), AllSymbols.end(),
-                                   std::make_pair(Target, StringRef()));
+              auto TargetSym = std::upper_bound(
+                  AllSymbols.begin(), AllSymbols.end(), Target,
+                  [](uint64_t LHS, std::pair<uint64_t, StringRef> &RHS) {
+                    return LHS < RHS.first;
+                  });
+              if (TargetSym != AllSymbols.begin())
+                --TargetSym;
+              else
+                TargetSym = AllSymbols.end();
+
               if (TargetSym != AllSymbols.end()) {
                 outs() << " <" << TargetSym->second;
-                uint64_t Disp = TargetSym->first - Target;
+                uint64_t Disp = Target - TargetSym->first;
                 if (Disp)
-                  outs() << '-' << Disp;
+                  outs() << '+' << utohexstr(Disp);
                 outs() << '>';
               }
             }





More information about the llvm-commits mailing list