[llvm] r241631 - [llvm-objdump] Print the call target next to the instruction

David Majnemer david.majnemer at gmail.com
Tue Jul 7 21:34:39 PDT 2015


On Tue, Jul 7, 2015 at 9:00 PM, Sean Silva <chisophugis at gmail.com> wrote:

> Nice!
>
> But I thought that an MCSymbolizer would automatically get us this too?
> (along with symbolizing e.g. addresses of constants which the current
> commit won't do)
>

I'm not sure, I didn't think that machinery knows about expressions
involving symbols in object files but patches are always welcome.


>
> -- Sean Silva
>
> On Tue, Jul 7, 2015 at 3:06 PM, David Majnemer <david.majnemer at gmail.com>
> wrote:
>
>> Author: majnemer
>> Date: Tue Jul  7 17:06:59 2015
>> New Revision: 241631
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=241631&view=rev
>> Log:
>> [llvm-objdump] Print the call target next to the instruction
>>
>> GNU binutils provides this behavior.  objdump -r doesn't really help
>> when you aren't dealing with relocation object files.
>>
>> 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=241631&r1=241630&r2=241631&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/test/MC/X86/AlignedBundling/nesting.s (original)
>> +++ llvm/trunk/test/MC/X86/AlignedBundling/nesting.s Tue Jul  7 17:06:59
>> 2015
>> @@ -6,7 +6,7 @@
>>  # Will be bundle-aligning to 16 byte boundaries
>>    .bundle_align_mode 4
>>    .text
>> -# CHECK-LABEL: foo
>> +# CHECK-LABEL: foo:
>>  foo:
>>  # Test that bundle alignment mode can be set more than once.
>>    .bundle_align_mode 4
>> @@ -19,11 +19,11 @@ foo:
>>    callq bar
>>    .bundle_unlock
>>    .bundle_unlock
>> -# CHECK:      10: callq
>> -# CHECK-NEXT: 15: callq
>> +# CHECK:      10: callq {{.*}} <bar>
>> +# CHECK-NEXT: 15: callq {{.*}} <bar>
>>
>>    .p2align 4
>> -# CHECK-LABEL: bar
>> +# CHECK-LABEL: bar:
>>  bar:
>>    callq foo
>>    callq foo
>> @@ -35,10 +35,10 @@ bar:
>>    callq bar
>>    .bundle_unlock
>>    .bundle_unlock
>> -# CHECK:      36: callq
>> -# CHECK-NEXT: 3b: callq
>> +# CHECK:      36: callq {{.*}} <bar>
>> +# CHECK-NEXT: 3b: callq {{.*}} <bar>
>>
>> -# CHECK-LABEL: baz
>> +# CHECK-LABEL: baz:
>>  baz:
>>    callq foo
>>    callq foo
>> @@ -50,8 +50,8 @@ baz:
>>    callq bar
>>    .bundle_unlock
>>    .bundle_unlock
>> -# CHECK:      56: callq
>> -# CHECK-NEXT: 5b: callq
>> +# CHECK:      56: callq {{.*}} <bar>
>> +# CHECK-NEXT: 5b: callq {{.*}} <bar>
>>
>>  # CHECK-LABEL: quux
>>  quux:
>> @@ -65,5 +65,5 @@ quux:
>>    .bundle_unlock
>>  # Check that the calls are bundled together when the second one is after
>> the
>>  # inner nest is closed.
>> -# CHECK:      70: callq
>> -# CHECK-NEXT: 75: callq
>> +# CHECK:      70: callq {{.*}} <bar>
>> +# CHECK-NEXT: 75: 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=241631&r1=241630&r2=241631&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
>> +++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Tue Jul  7 17:06:59
>> 2015
>> @@ -808,6 +808,27 @@ static void DisassembleObject(const Obje
>>        SectionRelocMap[*Sec2].push_back(Section);
>>    }
>>
>> +  // Create a mapping from virtual address to symbol name.  This is used
>> to
>> +  // pretty print the target of a call.
>> +  std::vector<std::pair<uint64_t, StringRef>> AllSymbols;
>> +  if (MIA) {
>> +    for (const SymbolRef &Symbol : Obj->symbols()) {
>> +      ErrorOr<uint64_t> AddressOrErr = Symbol.getAddress();
>> +      if (error(AddressOrErr.getError()))
>> +        break;
>> +      uint64_t Address = *AddressOrErr;
>> +
>> +      ErrorOr<StringRef> Name = Symbol.getName();
>> +      if (error(Name.getError()))
>> +        break;
>> +      if (Name->empty())
>> +        continue;
>> +      AllSymbols.push_back(std::make_pair(Address, *Name));
>> +    }
>> +
>> +    array_pod_sort(AllSymbols.begin(), AllSymbols.end());
>> +  }
>> +
>>    for (const SectionRef &Section : Obj->sections()) {
>>      if (!Section.isText() || Section.isVirtual())
>>        continue;
>> @@ -912,6 +933,21 @@ static void DisassembleObject(const Obje
>>                          SectionAddr + Index, outs(), "", *STI);
>>            outs() << CommentStream.str();
>>            Comments.clear();
>> +          if (MIA && (MIA->isCall(Inst) ||
>> MIA->isUnconditionalBranch(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()));
>> +              if (TargetSym != AllSymbols.end()) {
>> +                outs() << " <" << TargetSym->second;
>> +                uint64_t Disp = TargetSym->first - Target;
>> +                if (Disp)
>> +                  outs() << '-' << Disp;
>> +                outs() << '>';
>> +              }
>> +            }
>> +          }
>>            outs() << "\n";
>>          } else {
>>            errs() << ToolName << ": warning: invalid instruction
>> encoding\n";
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150707/986cfd24/attachment.html>


More information about the llvm-commits mailing list