[PATCH] D139864: [llvm-cxxfilt] Not consider the prefix dot as part of the demangled symbol name.

Digger Lin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 2 10:55:48 PDT 2023


DiggerLin added a comment.

In D139864#4311067 <https://reviews.llvm.org/D139864#4311067>, @hubert.reinterpretcast wrote:

> In D139864#4310484 <https://reviews.llvm.org/D139864#4310484>, @DiggerLin wrote:
>
>>   I think it is difficult to implement the functionality in LLVMDemangle, for example, if I implement the functionality in the function llvm::nonMicrosoftDemangle(const char *MangledName, std::string &Result)
>>
>> it will cause the symbol name "_._Z3f.0v" to be demangled as ".f.0()"  in some place.
>>
>> for example ,in the file Demangle.cpp
>>
>>   std::string llvm::demangle(const std::string &MangledName) {
>>     std::string Result;
>>     const char *S = MangledName.c_str();
>>   
>>     if (nonMicrosoftDemangle(S, Result))
>>       return Result;
>>   
>>     if (S[0] == '_' && nonMicrosoftDemangle(S + 1, Result))
>>       return Result;
>>   ....
>>   }
>
> Would adding a `if (S[0] == '.' && nonMicrosoftDemangle(S + 1, Result))` case there be appropriate?

if I change something like as your suggestion

  std::string llvm::demangle(const std::string &MangledName) {
    std::string Result;
    const char *S = MangledName.c_str();
  
    if (nonMicrosoftDemangle(S, Result))
      return Result;
  
    if (S[0] == '_' && S[1] != '.' && nonMicrosoftDemangle(S + 1, Result))
      return Result;
  
    if (char *Demangled = microsoftDemangle(S, nullptr, nullptr)) {
      Result = Demangled;
      std::free(Demangled);
      return Result;
    }
  
    return MangledName;
  }
  
  bool llvm::nonMicrosoftDemangle(const char *MangledName, std::string &Result) {
    char *Demangled = nullptr;
  
    // Not consider the prefix dot as part of the demangled symbol name.
    if (MangledName[0] == '.') {
      ++MangledName;
      Result = ".";
    }
  
    if (isItaniumEncoding(MangledName))
      Demangled = itaniumDemangle(MangledName, nullptr, nullptr, nullptr);
    else if (isRustEncoding(MangledName))
      Demangled = rustDemangle(MangledName);
    else if (isDLangEncoding(MangledName))
      Demangled = dlangDemangle(MangledName);
  
    if (!Demangled)
      return false;
  
    Result += Demangled;
    std::free(Demangled);
    return true;

it will be have problem in the function  demangleMachO llvm-nm.cpp

static std::optional<std::string> demangle(StringRef Name) {

  std::string Demangled;
  if (nonMicrosoftDemangle(Name.str().c_str(), Demangled))
    return Demangled;
  return std::nullopt;

}

static std::optional<std::string> demangleMachO(StringRef Name) {

  if (!Name.empty() && Name[0] == '_')
    Name = Name.drop_front();
  return demangle(Name);

}

the function  demangleMachO   still will decode
symbol name "_._Z3f.0v" to be demangled as ".f.0()"

so my suggestion is putting the removing and adding prefix 'dot' back in demangle() function of in each llvm tools.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139864/new/

https://reviews.llvm.org/D139864



More information about the llvm-commits mailing list