[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
Thu Sep 21 11:19:21 PDT 2023


DiggerLin marked an inline comment as done.
DiggerLin added a comment.

In D139864#4641608 <https://reviews.llvm.org/D139864#4641608>, @jhenderson wrote:

> My opinion hasn't changed that it's a mistake to put the dot demangling in llvm-cxxfilt specifically. That will mean you'll need to make the same change in llvm-nm, llvm-readelf, llvm-objdump and probably other tools too. Code duplication is bad. The next tool to be added might not realise that they can't just use the main demangler library as-is to do their name demangling.
>
> If there is tool code that conflicts with that behaviour (such as the llvm-nm mach-o code), perhaps it's that tool code that should change instead, or perhaps we need to enhance the demangler library a little further, for example by adding an optional "strip underscore" behaviour to it. Adding @MaskRay as a reviewer in case he's got a different opinion.



  I think it is difficult to llvm::demangle for the llvm-cxxfilt , since there is option `--strip-underscore` , please see the comment in https://reviews.llvm.org/D110664#inline-1063385 , the llvm-nm, llvm-readelf, llvm-objdump can share the same llvm::demangle() 

std::string llvm::demangle(std::string_view MangledName) {

  std::string Result;
  
  if (nonMicrosoftDemangle(MangledName, Result))
    return Result;
  
  if (starts_with(MangledName, '_') &&
      nonMicrosoftDemangle(MangledName.substr(1), Result))
    return Result;
   
  if (char *Demangled = microsoftDemangle(MangledName, nullptr, nullptr)) {
    Result = Demangled;
    std::free(Demangled);
  } else {
    Result = MangledName;
  }
  return Result;

}



================
Comment at: llvm/test/tools/llvm-cxxfilt/delimiters.test:36
+RUN:      '_Z3Foo$ _Z3f.0v' \
+## Show that the llvm-cxxfilt does not consider the prefix dot as part of the demangled symbol name.
+RUN:      '._Z3Foo ._Z3f.0v' \
----------------
jhenderson wrote:
> That being said, this isn't the right place for these new test cases. The only thing that should change in this test is related to the `._Z3Foo` string - see below.
> 
> This test is about testing which characters are treated as delimiters, i.e. characters that separate sequences of names that are to be demangled individually. It is not about testing how things are demangled in the presence of ".". You should add that testing in a new test file.
> 
> With the change in behaviour of leading dot prefixes, this test itself doesn't actually test the intended behaviour. The intention was to show that a dot was treated as part of the mangled name, rather than a separator between the previous character sequence (in this case simply the preceding space), and the subsequent mangled name (`_Z3Foo`). If the dot was treated as a delimiter, the `_Z3Foo` would have been demangled, resulting in the final part of the output being `_Z3Foo$ .Foo`. As you can see, this is indistinguishable from the case where `._Z3Foo` as a whole is demangled (to `.Foo`). Instead, this bit of the bit of the check should be modified such that the new code can't demangle it still, but if instead the dot was treated as delimiter, it could be. For example, you could have two valid name manglings separated by a single ".", e.g. `_Z3Foo._Z3Bar`. If the dot were a delimiter, that would result in an output of `Foo.Bar`, but since it isn't, the original input should be emitted to the output (i.e. `_Z3Foo._Z3Bar`).
> 
> I hope that makes sense!
> The intention was to show that a dot was treated as part of the mangled name

`._Z3Foo` is a symbol name in AIX , but the  `._Z3Foo` is not a mangle name ,only  `_Z3Foo` is a mangle name, we put the dot in front of the `_Z3Foo` to generate the entry label symbol of function in AIX.



> but if instead the dot was treated as delimiter, it could be. For example, you could have two valid name manglings separated by a single ".", e.g. _Z3Foo._Z3Ba

 according to the https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling , the dot maybe part of symbol (but in the middle of the mangled name, not the front of the mangle name).

So we have to do some special for the front dot of symbol name for AIX.


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