Bug 222562

Summary: c++filt and libelftc do not demangle names correctly
Product: Base System Reporter: Ian Lepore <ian>
Component: binAssignee: freebsd-toolchain (Nobody) <toolchain>
Status: Open ---    
Severity: Affects Many People CC: cem, emaste
Priority: ---    
Version: 12.2-STABLE   
Hardware: Any   
OS: Any   
See Also: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=222563
Bug Depends on:    
Bug Blocks: 231027    
Attachments:
Description Flags
Small c++ program to demonstrate the problem none

Description Ian Lepore freebsd_committer freebsd_triage 2017-09-24 17:07:55 UTC
Created attachment 186669 [details]
Small c++ program to demonstrate the problem

If you compile the attached tester.cc source (just "make tester.o") then use nm(1) on the .o file, the nm output includes two mangled symbol names:

00000000 V _ZTS3Foo
00000000 r _ZTSZ4mainE3Bar

Running them through c++filt gives: 

# c++filt _ZTS3Foo _ZTSZ4mainE3Bar
typeinfo name for Foo
_ZTSZ4mainE3Bar

(The program also produces wrong output when it runs, but that will be handled in a separate PR, becuase our current libcxxrt uses different demangling code than libelftc).
Comment 1 Ed Maste freebsd_committer freebsd_triage 2018-08-01 14:50:16 UTC
GNU c++filt demangles the 2nd as `typeinfo name for main::Bar`

Related test case _ZZ4mainE3Bar, which GNU demangles as main::Bar and elftoolchain's fails with an assertion:

% c++filt _ZZ4mainE3Bar 
Assertion failed: (ddata->output.size > 0), function cpp_demangle_read_sname, file /usr/home/emaste/src/freebsd-wip/contrib/elftoolchain/libelftc/libelftc_dem_gnu3.c, line 2139.

The assertion failure can also be triggered attempting to demangle (invalid) symbol _ZZ1
Comment 2 Ed Maste freebsd_committer freebsd_triage 2019-03-29 14:53:04 UTC
With an up-to-date (as of today) ELF Tool Chain build on x86:

% ./c++filt _ZTS3Foo _ZTSZ4mainE3Bar _ZZ4mainE3Bar
typeinfo name for Foo
_ZTSZ4mainE3Bar
Assertion failed: (ddata->output.size > 0), function cpp_demangle_read_sname, file libelftc_dem_gnu3.c, line 2137.
zsh: abort (core dumped)  ./c++filt _ZTS3Foo _ZTSZ4mainE3Bar _ZZ4mainE3Bar
Comment 3 Ed Maste freebsd_committer freebsd_triage 2021-07-28 00:40:36 UTC
Work is in progress to migrate to some LLVM binutils replacements; WITH_LLVM_CXXFILT is enabled by default in main and 13

$ c++filt _ZTS3Foo _ZTSZ4mainE3Bar _ZZ4mainE3Bar
typeinfo name for Foo
typeinfo name for main::Bar
main::Bar