Skip to content

Commit 1ff958c

Browse files
committed
[llvm-cxxfilt] Do not consider the prefix dot as part of the demangled symbol name.
Summary: In AIX OS, function entry label are begin with '.', it can not be decoded currently. we support to decode the name in this patch for all OS. Reviewers: Fangrui Song, James Henderson, Differential Revision: https://reviews.llvm.org/D139864
1 parent aecb580 commit 1ff958c

File tree

6 files changed

+31
-14
lines changed

6 files changed

+31
-14
lines changed

llvm/include/llvm/Demangle/Demangle.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ char *dlangDemangle(std::string_view MangledName);
6767
/// demangling occurred.
6868
std::string demangle(std::string_view MangledName);
6969

70-
bool nonMicrosoftDemangle(std::string_view MangledName, std::string &Result);
70+
bool nonMicrosoftDemangle(std::string_view MangledName, std::string &Result,
71+
bool CanHaveLeadingDot = true);
7172

7273
/// "Partial" demangler. This supports demangling a string into an AST
7374
/// (typically an intermediate stage in itaniumDemangle) and querying certain

llvm/lib/Demangle/Demangle.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ std::string llvm::demangle(std::string_view MangledName) {
2424
return Result;
2525

2626
if (starts_with(MangledName, '_') &&
27-
nonMicrosoftDemangle(MangledName.substr(1), Result))
27+
nonMicrosoftDemangle(MangledName.substr(1), Result,
28+
/*CanHaveLeadingDot=*/false))
2829
return Result;
2930

3031
if (char *Demangled = microsoftDemangle(MangledName, nullptr, nullptr)) {
@@ -46,8 +47,15 @@ static bool isRustEncoding(std::string_view S) { return starts_with(S, "_R"); }
4647
static bool isDLangEncoding(std::string_view S) { return starts_with(S, "_D"); }
4748

4849
bool llvm::nonMicrosoftDemangle(std::string_view MangledName,
49-
std::string &Result) {
50+
std::string &Result, bool CanHaveLeadingDot) {
5051
char *Demangled = nullptr;
52+
53+
// Do not consider the dot prefix as part of the demangled symbol name.
54+
if (CanHaveLeadingDot && MangledName.size() > 0 && MangledName[0] == '.') {
55+
MangledName.remove_prefix(1);
56+
Result = ".";
57+
}
58+
5159
if (isItaniumEncoding(MangledName))
5260
Demangled = itaniumDemangle(MangledName);
5361
else if (isRustEncoding(MangledName))
@@ -58,7 +66,7 @@ bool llvm::nonMicrosoftDemangle(std::string_view MangledName,
5866
if (!Demangled)
5967
return false;
6068

61-
Result = Demangled;
69+
Result += Demangled;
6270
std::free(Demangled);
6371
return true;
6472
}

llvm/test/tools/llvm-cxxfilt/delimiters.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ RUN: '_Z3Foo,,_Z3Bar::_Z3Baz _Z3Foo,_Z3Bar:_Z3Baz' \
3232
COM: Piping the echo output causes '⦙' to be converted to '?' in some
3333
COM: builds/environments. Redirect echo output to and from %t to work
3434
COM: around this. See D111072.
35-
RUN: '_Z3Foo$ ._Z3Foo' > %t
35+
RUN: '_Z3Foo$ Foo._Z3Bar' > %t
3636
RUN: llvm-cxxfilt -n < %t | FileCheck %s
3737

3838
CHECK: ,,Foo!
@@ -66,4 +66,4 @@ CHECK: Foo}
6666
CHECK: Foo~,,
6767
CHECK: Foo⦙Bar
6868
CHECK: Foo,,Bar::Baz Foo,Bar:Baz
69-
CHECK: _Z3Foo$ ._Z3Foo
69+
CHECK: _Z3Foo$ Foo._Z3Bar
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Show that the llvm-cxxfilt does not consider the dot prefix to be part of the symbol name to be demangled.
2+
RUN: llvm-cxxfilt -n ._ZL5func0v | FileCheck %s
3+
4+
CHECK: .func0()
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
## Show the behaviour of --[no-]strip-underscore. This test does not test
22
## the platform-specific default behaviour. This is tested elsewhere.
33

4-
RUN: llvm-cxxfilt -_ __ZN2ns1fE _ZSt1f _f | FileCheck %s -check-prefix CHECK-STRIPPED
5-
RUN: llvm-cxxfilt --strip-underscore __ZN2ns1fE _ZSt1f _f | FileCheck %s -check-prefix CHECK-STRIPPED
6-
RUN: llvm-cxxfilt -n __ZN2ns1fE _ZSt1f _f | FileCheck %s -check-prefix CHECK-UNSTRIPPED
7-
RUN: llvm-cxxfilt --no-strip-underscore __ZN2ns1fE _ZSt1f _f | FileCheck %s -check-prefix CHECK-UNSTRIPPED
4+
RUN: llvm-cxxfilt -_ __ZN2ns1fE _ZSt1f _f _._Z3f.0v | FileCheck %s -check-prefix CHECK-STRIPPED
5+
RUN: llvm-cxxfilt --strip-underscore __ZN2ns1fE _ZSt1f _f _._Z3f.0v | FileCheck %s -check-prefix CHECK-STRIPPED
6+
RUN: llvm-cxxfilt -n __ZN2ns1fE _ZSt1f _f _._Z3f.0v | FileCheck %s -check-prefix CHECK-UNSTRIPPED
7+
RUN: llvm-cxxfilt --no-strip-underscore __ZN2ns1fE _ZSt1f _f _._Z3f.0v | FileCheck %s -check-prefix CHECK-UNSTRIPPED
88

99
CHECK-STRIPPED: ns::f
1010
CHECK-STRIPPED: _ZSt1f
1111
CHECK-STRIPPED: _f
12+
CHECK-STRIPPED: ._Z3f.0v
1213

1314
CHECK-UNSTRIPPED: __ZN2ns1fE
1415
CHECK-UNSTRIPPED: std::f
1516
CHECK-UNSTRIPPED: _f
17+
CHECK-UNSTRIPPED: _._Z3f.0v

llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ static void error(const Twine &Message) {
6767
static std::string demangle(const std::string &Mangled) {
6868
using llvm::itanium_demangle::starts_with;
6969
std::string_view DecoratedStr = Mangled;
70-
if (StripUnderscore)
71-
if (DecoratedStr[0] == '_')
72-
DecoratedStr.remove_prefix(1);
70+
bool CanHaveLeadingDot = true;
71+
if (StripUnderscore && DecoratedStr[0] == '_') {
72+
DecoratedStr.remove_prefix(1);
73+
CanHaveLeadingDot = false;
74+
}
7375

7476
std::string Result;
75-
if (nonMicrosoftDemangle(DecoratedStr, Result))
77+
if (nonMicrosoftDemangle(DecoratedStr, Result, CanHaveLeadingDot))
7678
return Result;
7779

7880
std::string Prefix;

0 commit comments

Comments
 (0)