abi::__cxa_demangle provides invalid result on non-mangled symbols
Ryan Stone
rysto32 at gmail.com
Tue Jun 10 03:01:51 UTC 2014
On Mon, Jun 9, 2014 at 10:44 PM, Ed Maste <emaste at freebsd.org> wrote:
> On 9 June 2014 21:48, Ryan Stone <rysto32 at gmail.com> wrote:
>> abi::__cxa_demangle is giving me an invalid result if I pass it a
>> symbol that is not mangled. This is causing me problems as in my
>> application, I'm getting symbol names from libelf and have no way of
>> know a priori whether a symbol is mangled or not.
>
> I had the same issue in LLVM, and as hacky as it seems, the solution
> is to check that the name starts with "_Z" before passing it to
> __cxa_demangle.
>
> For reference the LLVM review for the change is here:
> http://reviews.llvm.org/D2552
>
> I didn't get around to testing it on Linux; since you have a test
> application ready it would be interesting to see the result of
> __cxa_demangle("f") there.
You're right, it is a problem in Linux:
[rstone at rstone-desktop shm]./demangle f
__cxa_demangle("f") = "float", status=0
[rstone at rstone-desktop shm]./demangle i
__cxa_demangle("i") = "int", status=0
[rstone at rstone-desktop shm]./demangle m
__cxa_demangle("m") = "unsigned long", status=0
[rstone at rstone-desktop shm]./demangle main
__cxa_demangle("main") = "(null)", status=-2
The GNU version is just a little smarter about erroring out properly
on "main", but there's nothing stopping anybody from using a function
called "f" so I'll use your recommended workaround. Thanks.
More information about the freebsd-toolchain
mailing list