Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 Jun 2014 13:41:17 +0100
From:      David Chisnall <theraven@FreeBSD.org>
To:        Kai Wang <kaiw@FreeBSD.org>
Cc:        Ryan Stone <rysto32@gmail.com>, freebsd-toolchain@FreeBSD.org
Subject:   Re: abi::__cxa_demangle provides invalid result on non-mangled symbols
Message-ID:  <281D8767-7B24-4B58-8669-CF60C597E58E@FreeBSD.org>
In-Reply-To: <20140611123054.GA2777@soulhacker>
References:  <CAFMmRNw_9hS3YuDbjFJH0btvoPADJ7_4=L13z2sK71gctPzXhQ@mail.gmail.com> <CAPyFy2Buh4BUEuYW5nfQFdEMio9=yaDAkivg1zXPnEBzr_CzJQ@mail.gmail.com> <9BDAE8E2-0573-4526-9136-97D3492D7DEF@FreeBSD.org> <20140611123054.GA2777@soulhacker>

next in thread | previous in thread | raw e-mail | index | archive | help
On 11 Jun 2014, at 13:30, Kai Wang <kaiw@FreeBSD.org> wrote:

> On Tue, Jun 10, 2014 at 07:38:19AM +0100, David Chisnall wrote:
>> On 10 Jun 2014, at 03:44, Ed Maste <emaste@freebsd.org> wrote:
>>=20
>>> 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.
>>>=20
>>> For reference the LLVM review for the change is here:
>>> http://reviews.llvm.org/D2552
>>>=20
>>> 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.
>>=20
>> If you know that the thing that you are demangling is a symbol name, =
then you can use the _Z check, which isn't really a hack - it's a marker =
added to identify C++ symbols.  Note that, if you're writing portable =
code, you need to remember that some systems prepend an underscore to =
all compiler-generated symbols, so you may also need to check for __Z =
and trim the leading _.
>>=20
>> The __cxa_demangle() function has to handle things that are not just =
symbols (types and so on) and so can't do this test itself.  Its most =
common use is generating a human-friendly error for an uncaught =
exception, where it is just parsing a type encoding.
>>=20
>> The demangler that we ship is from libelftc.  It also fails on a =
number of C++11 types and doesn't handle some complex template cases. =20=

>=20
> Hi David,
>=20
> If possible, could you list a few examples that the demangler can not
> handle?  Maybe we can fix this in libelftc and merge it back later.

Your best reference for this is the libc++abi test suite:

=
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/test_demangle.cpp=
?revision=3D208611&view=3Dmarkup

New C++11 additions and template arguments that are forward references =
are not very well handled.  It would be great if there were any =
improvements.

It would also be good for libcxxrt if the demangler could avoid having =
to allocate any memory except on the stack, as one of the places where =
it's used is in reporting out-of-memory conditions.

David





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?281D8767-7B24-4B58-8669-CF60C597E58E>