Bug 222562 - c++filt and libelftc do not demangle names correctly
Summary: c++filt and libelftc do not demangle names correctly
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-toolchain mailing list
URL:
Keywords:
Depends on:
Blocks: 231027
  Show dependency treegraph
 
Reported: 2017-09-24 17:07 UTC by Ian Lepore
Modified: 2019-03-29 14:53 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 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 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 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