From: David Majnemer Date: Thu, 9 Jul 2015 18:11:40 +0000 (+0000) Subject: [llvm-objdump] Require that jump targets shown in -d are functions X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=f2c71ff7a896cd0fca2d4d8b982c849b91dc3e2e;p=oota-llvm.git [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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241830 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/MC/X86/AlignedBundling/nesting.s b/test/MC/X86/AlignedBundling/nesting.s index d83c423a56e..16ed5a44da5 100644 --- a/test/MC/X86/AlignedBundling/nesting.s +++ b/test/MC/X86/AlignedBundling/nesting.s @@ -7,6 +7,7 @@ .bundle_align_mode 4 .text # CHECK-LABEL: foo: +.type foo,@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,@function bar: callq foo callq foo @@ -39,6 +41,7 @@ bar: # CHECK-NEXT: 3b: callq {{.*}} # CHECK-LABEL: baz: +.type baz,@function baz: callq foo callq foo @@ -54,6 +57,7 @@ baz: # CHECK-NEXT: 5b: callq {{.*}} # CHECK-LABEL: quux +.type quux,@function quux: callq bar callq bar diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index c61bd98e9eb..8d906daecc0 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -817,6 +817,9 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { std::vector> AllSymbols; if (MIA) { for (const SymbolRef &Symbol : Obj->symbols()) { + if (Symbol.getType() != SymbolRef::ST_Function) + continue; + ErrorOr AddressOrErr = Symbol.getAddress(); if (error(AddressOrErr.getError())) break; @@ -937,17 +940,25 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { 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 &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() << '>'; } }