Bug 222562 - c++filt and libelftc do not demangle names correctly
Summary: c++filt and libelftc do not demangle names correctly
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 12.2-STABLE
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-toolchain (Nobody)
URL:
Keywords:
Depends on:
Blocks: 231027
  Show dependency treegraph
 
Reported: 2017-09-24 17:07 UTC by Ian Lepore
Modified: 2024-11-02 19:39 UTC (History)
2 users (show)

See Also:


Attachments
Small c++ program to demonstrate the problem (523 bytes, text/x-c++src)
2017-09-24 17:07 UTC, Ian Lepore
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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