[PATCH] D34668: llvm-nm: Add suport for symbol demangling (-C/--demangle)

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 29 10:40:46 PDT 2017


On Thu, Jun 29, 2017 at 10:22 AM, Jonathan Roelofs
<jonathan at codesourcery.com> wrote:
>
>
> On 6/27/17 6:35 PM, Rafael Avila de Espindola via llvm-commits wrote:
>>
>> Sam Clegg via Phabricator <reviews at reviews.llvm.org> writes:
>>>
>>> +static Optional<std::string> demangle(StringRef Name, bool
>>> StripUnderscore) {
>>> +  if (StripUnderscore && Name.size() > 0 && Name[0] == '_')
>>> +    Name = Name.substr(1);
>>> +
>>> +  if (Name.size() < 2 || !Name.startswith("_Z"))
>>> +    return None;
>>
>>
>> I don't think you need the .size() checks. It is safe to just use
>> startswith.
>>
>>
>>> @@ -724,6 +745,12 @@
>>>     for (SymbolListT::iterator I = SymbolList.begin(), E =
>>> SymbolList.end();
>>>          I != E; ++I) {
>>>       uint32_t SymFlags;
>>> +    std::string Name = I->Name.str();
>>> +    MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(&Obj);
>>> +    if (Demangle) {
>>> +      if (Optional<std::string> Opt = demangle(I->Name, MachO !=
>>> nullptr))
>>
>>
>> You can just use isa<MachOObjectFile>(Obj).
>
>
> MachO isn't the only target with a prefix of '_'. Shouldn't this be
> inspecting `DataLayout::getGlobalPrefix()` for that instead?
>
>

I didnt't know about that.  Any idea how I would go about getting a
DataLayout object?  Seems like its linked to the IR system and nm is
working with libObject binaries.

> Jon
>
>>
>> LGTM with that.
>>
>> Cheers,
>> Rafael
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>
>
> --
> Jon Roelofs
> jonathan at codesourcery.com
> CodeSourcery / Mentor Embedded / Siemens


More information about the llvm-commits mailing list