From owner-freebsd-toolchain@FreeBSD.ORG Tue Jun 10 06:58:36 2014 Return-Path: Delivered-To: freebsd-toolchain@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B223BE19; Tue, 10 Jun 2014 06:58:36 +0000 (UTC) Received: from theravensnest.org (theraven.freebsd.your.org [216.14.102.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "cloud.theravensnest.org", Issuer "StartCom Class 1 Primary Intermediate Server CA" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 7E3582114; Tue, 10 Jun 2014 06:58:35 +0000 (UTC) Received: from [192.168.0.96] (cpc14-cmbg15-2-0-cust307.5-4.cable.virginm.net [82.26.1.52]) (authenticated bits=0) by theravensnest.org (8.14.7/8.14.7) with ESMTP id s5A6wHYF051813 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Tue, 10 Jun 2014 06:58:22 GMT (envelope-from theraven@FreeBSD.org) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 7.2 \(1874\)) Subject: Re: abi::__cxa_demangle provides invalid result on non-mangled symbols From: David Chisnall In-Reply-To: Date: Tue, 10 Jun 2014 07:38:19 +0100 Content-Transfer-Encoding: quoted-printable Message-Id: <9BDAE8E2-0573-4526-9136-97D3492D7DEF@FreeBSD.org> References: To: Ed Maste X-Mailer: Apple Mail (2.1874) Cc: freebsd-toolchain@freebsd.org, Ryan Stone X-BeenThere: freebsd-toolchain@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Maintenance of FreeBSD's integrated toolchain List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Jun 2014 06:58:36 -0000 On 10 Jun 2014, at 03:44, Ed Maste wrote: > 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. 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 _. 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. 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 David