Created attachment 186671 [details] Small c++ program to demonstrate the problem The attached small c++ program should print the demangled names of a couple symbols when it runs, but it does not: # make tester && ./tester c++ -O -pipe tester.cc -o tester name '3Foo' = '3Foo' status=-2 name 'Z4mainE3Bar' = '(null)' status=-2 The current demangling code in libcxxrt is a snapshot of the libelftc demangler from 10-ish years ago. If you replace it with the current libelftc demangling code and make some other small changes you can get abi::__cxa_demangle() to the point where it returns the same slightly-less-wrong results as c++filt (see PR 222562). Part of the problem with abi::__cxa_demangle() is that it is not correctly glued to the libelftc demangling code. The demangler wants to see a prefix on the symbol name, like what you see in nm(1) output. That is, typeid(bar).name() returns "Z4mainE3Bar" and the demangle code expects "_ZTSZ4mainE3Bar". (This is the small change I referred to above.) One potential fix for this would be to examine llvm's libcxxabi and possibly import its demangler (or maybe the entire library). I gather this libcxxabi didn't exist when we created/imported libcxxrt.
I ran into this today while trying to get code using `abi::__cxa_demangle` to work on freebsd-13.0 which was working successfully prior, e.g., in freebsd-12.2. I see some work was done for `c++filt` (e.g., bug 222562, bug 252443), but I still seem unable to execute `abi::__cxa_demangle` myself. It would be great if whatever work done over there could be folded into the infrastructure behind that library function.
(In reply to Benjamin Bannier from comment #1) Can you test with a 13.1 RC image? commit d4a0c102a237beb5650a2de4cc80f1aa496601d7 includes a change to contrib/libcxxrt/libelftc_dem_gnu3.c that I suspect addresses your issue. On stable/13 tester.cc now produces 'Foo' for '3Foo' but still fails to demangle Z4mainE3Bar.
(In reply to Ed Maste from comment #2) I checked with 9470a2f7da488f3c14051e39691fbfddcf2aa0fe (which includes d4a0c102a237beb5650a2de4cc80f1aa496601d7) and it looks like it does indeed fix the problem I was seeing. Sorry for not checking the RC first.