[llvm] r198441 - For disassembly when adding a symbolic operand that is a C++

Reid Kleckner rnk at google.com
Fri Jan 3 16:44:59 PST 2014


Sounds like delegating back through the C API with a new reference type is
the way to go.  Thanks!


On Fri, Jan 3, 2014 at 4:08 PM, Kevin Enderby <enderby at apple.com> wrote:

> Also note, this is simply adding a comment to the disassembled output like
> this:
>
> % otool -tV /Volumes/SandBox/build-llvm/Debug+Asserts/bin/llvm-mc
> ...
> 0000000100001034        callq
> __ZNK4llvm6Target20createMCDisassemblerERKNS_15MCSubtargetInfoE ##
> llvm::Target::createMCDisassembler(llvm::MCSubtargetInfo const&) const
>
> And it is just an aid to the reader.
>
> We could hide the demangling as a new ReferenceType, say
> LLVMDisassembler_ReferenceType_DeMangled_Name, and return it indirectly via
> ReferenceName to the SymbolLookUp() call back.  That way if the user of the
> C API wants to do a demangling of the name it could be done there.  Happy
> to implement this in this way and that leaves it to the user of the C API.
>
> My thoughts,
> Kev
>
>
> On Jan 3, 2014, at 3:49 PM, Reid Kleckner <rnk at google.com> wrote:
>
> OTOH a disassembler is not a compiler.  It's just a debugging aid.  While
> it's conceptually nice that llvm-c-test --disassemble produces the same
> outputs on all platforms, it's not as important as being able to do perfect
> cross compilation.
>
> Is there a way to structure this so that the symbolization is delegated to
> the user of the C API, or is that too disruptive?
>
>
> On Fri, Jan 3, 2014 at 3:37 PM, David Majnemer <david.majnemer at gmail.com>wrote:
>
>> Unless I am mistaken, the correct thing to do would be to provide an
>> implementation of symbol demangling within LLVM itself.
>> This way we could demangle Itanium-style symbols without relying on
>> ::abi::__cxa_demangle and MSVC-style symbols without relying on
>> ::UnDecorateSymbolName.
>>
>> Relying on the host's ABI details to help disassemble code for a target
>> seems like the wrong approach.
>>
>>
>> On Fri, Jan 3, 2014 at 12:06 PM, Howard Hinnant <hhinnant at apple.com>wrote:
>>
>>> abi::__cxa_demangle and <cxxabi.h> are part of the Itanium ABI.  MS
>>> doesn't support this unofficial standard.  Sorry, I don't know how to
>>> demangle names on Windows.  I believe that their type_info.name()
>>> returns an demangled name.  But I don't know that this info helps.
>>>
>>> Howard
>>>
>>> On Jan 3, 2014, at 3:02 PM, Kevin Enderby <enderby at apple.com> wrote:
>>>
>>> > Hi Reid,
>>> >
>>> > Sorry about that.  I'll revert my change.
>>> >
>>> > Not sure the best way to get this done if an ifdef is not acceptable.
>>>  Maybe Howard or others will have better suggestions.
>>> >
>>> > It does not have any tests as this is used by darwin's otool(1) that
>>> links with the llvm disassembler.  We have had this problem with this part
>>> of the disassembler since day one.  So I'm not sure the best way to address
>>> that either.
>>> >
>>> > Kev
>>> >
>>> > On Jan 3, 2014, at 11:54 AM, Reid Kleckner <rnk at google.com> wrote:
>>> >
>>> >> Microsoft doesn't ship a <cxxabi.h> header:
>>> >>
>>> http://lab.llvm.org:8011/builders/lld-x86_64-win7/builds/5504/steps/build_Lld/logs/stdio
>>> >> MCExternalSymbolizer.cpp(16): fatal error C1083: Cannot open include
>>> file: 'cxxabi.h': No such file or directory
>>> >>
>>> >> I'm not familiar with this code, but it seems bad to make the result
>>> of LLVMDisasmInstruction dependent on the target platform, so throwing this
>>> behind a quick ifdef isn't necessarily right either.
>>> >>
>>> >> This also doesn't have any tests.
>>> >>
>>> >>
>>> >> On Fri, Jan 3, 2014 at 11:33 AM, Kevin Enderby <enderby at apple.com>
>>> wrote:
>>> >> Author: enderby
>>> >> Date: Fri Jan  3 13:33:09 2014
>>> >> New Revision: 198441
>>> >>
>>> >> URL: http://llvm.org/viewvc/llvm-project?rev=198441&view=rev
>>> >> Log:
>>> >> For disassembly when adding a symbolic operand that is a C++
>>> >> symbol name, also put the human readable name in a comment.
>>> >>
>>> >> Also fix a bug in LLVMDisasmInstruction() that was not flushing
>>> >> the raw_svector_ostream for the disassembled instruction string
>>> >> before copying it to the output buffer that was causing truncation
>>> >> of the output.
>>> >>
>>> >> rdar://10173828
>>> >>
>>> >> Modified:
>>> >>     llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp
>>> >>     llvm/trunk/lib/MC/MCExternalSymbolizer.cpp
>>> >>
>>> >> Modified: llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp
>>> >> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp?rev=198441&r1=198440&r2=198441&view=diff
>>> >>
>>> ==============================================================================
>>> >> --- llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp (original)
>>> >> +++ llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp Fri Jan  3
>>> 13:33:09 2014
>>> >> @@ -298,6 +298,7 @@ size_t LLVMDisasmInstruction(LLVMDisasmC
>>> >>        emitLatency(DC, Inst);
>>> >>
>>> >>      emitComments(DC, FormattedOS);
>>> >> +    OS.flush();
>>> >>
>>> >>      assert(OutStringSize != 0 && "Output buffer cannot be zero
>>> size");
>>> >>      size_t OutputSize = std::min(OutStringSize-1, InsnStr.size());
>>> >>
>>> >> Modified: llvm/trunk/lib/MC/MCExternalSymbolizer.cpp
>>> >> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCExternalSymbolizer.cpp?rev=198441&r1=198440&r2=198441&view=diff
>>> >>
>>> ==============================================================================
>>> >> --- llvm/trunk/lib/MC/MCExternalSymbolizer.cpp (original)
>>> >> +++ llvm/trunk/lib/MC/MCExternalSymbolizer.cpp Fri Jan  3 13:33:09
>>> 2014
>>> >> @@ -13,6 +13,7 @@
>>> >>  #include "llvm/MC/MCInst.h"
>>> >>  #include "llvm/Support/raw_ostream.h"
>>> >>  #include <cstring>
>>> >> +#include <cxxabi.h>
>>> >>
>>> >>  using namespace llvm;
>>> >>
>>> >> @@ -56,6 +57,14 @@ bool MCExternalSymbolizer::tryAddingSymb
>>> >>      if (Name) {
>>> >>        SymbolicOp.AddSymbol.Name <http://symbolicop.addsymbol.name/>= Name;
>>> >>        SymbolicOp.AddSymbol.Present = true;
>>> >> +      // If Name is a C++ symbol name put the human readable name in
>>> a comment.
>>> >> +      if (strncmp(Name, "__Z", 3) == 0) {
>>> >> +        char *demangled = abi::__cxa_demangle(Name + 1, 0, 0, 0);
>>> >> +       if (demangled) {
>>> >> +          cStream << demangled;
>>> >> +          free(demangled);
>>> >> +        }
>>> >> +      }
>>> >>      }
>>> >>      // For branches always create an MCExpr so it gets printed as
>>> hex address.
>>> >>      else if (IsBranch) {
>>> >>
>>> >>
>>> >> _______________________________________________
>>> >> llvm-commits mailing list
>>> >> llvm-commits at cs.uiuc.edu
>>> >> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>> >>
>>> >
>>>
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>>
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>>
> _______________________________________________
> 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/20140103/8fae4455/attachment.html>


More information about the llvm-commits mailing list