From owner-freebsd-toolchain@FreeBSD.ORG Wed Jun 11 12:31:00 2014 Return-Path: Delivered-To: freebsd-toolchain@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 2210F99A; Wed, 11 Jun 2014 12:31:00 +0000 (UTC) Received: from mail-lb0-x22e.google.com (mail-lb0-x22e.google.com [IPv6:2a00:1450:4010:c04::22e]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3D0E921F3; Wed, 11 Jun 2014 12:30:59 +0000 (UTC) Received: by mail-lb0-f174.google.com with SMTP id n15so4764660lbi.19 for ; Wed, 11 Jun 2014 05:30:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=WeUaqeH1hlW7ahbngi0itQv2+pN0GBUK2bc1lEnWMqc=; b=GZQruKrh4yLsu1O4GQBTMcMnXNlR7DEEoujJWkY9IbAxqRoJ3hcj92q/C+i/F7oQLn vHYAu34agtXBpN3/QZRzLa8X/7J+kW4tu087kWK9z571GhGExJSzib57pWu/RmbnlwTm gzDou8CBI5JcjIu8jSD0h0wej57GK2D4R4MT9pyLeSLIzgxFzRgM3bdWZ9eStg14tkHq RFJf/NCdqxGn58+Ituy7mRNym/fgUBzzVCPQBUsm4KSxZ+VFVlqGF5BP1VPwU/4K1Jtc A0wMioVYOcKwz+P85uN11fX+PoZIBPeY5+RkodQOIuvDAleOHnLSFSIYCTdiCPov7KFa bV1A== X-Received: by 10.112.34.210 with SMTP id b18mr11326242lbj.42.1402489857129; Wed, 11 Jun 2014 05:30:57 -0700 (PDT) Received: from localhost (s83-179-26-16.cust.tele2.se. [83.179.26.16]) by mx.google.com with ESMTPSA id lq20sm24733095lbb.24.2014.06.11.05.30.55 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 11 Jun 2014 05:30:56 -0700 (PDT) Sender: Kai Wang Received: from localhost.localdomain ([127.0.0.1] helo=localhost.my.domain) by localhost with esmtp (Exim 4.80.1 (FreeBSD)) (envelope-from ) id 1Wuhg6-0000j1-Gl; Wed, 11 Jun 2014 14:30:54 +0200 Received: (from kaiw@localhost) by localhost.my.domain (8.14.5/8.14.5/Submit) id s5BCUsPg002790; Wed, 11 Jun 2014 14:30:54 +0200 (CEST) (envelope-from kaiw@FreeBSD.org) X-Authentication-Warning: localhost.my.domain: kaiw set sender to kaiw@FreeBSD.org using -f Date: Wed, 11 Jun 2014 14:30:54 +0200 From: Kai Wang To: David Chisnall Subject: Re: abi::__cxa_demangle provides invalid result on non-mangled symbols Message-ID: <20140611123054.GA2777@soulhacker> References: <9BDAE8E2-0573-4526-9136-97D3492D7DEF@FreeBSD.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <9BDAE8E2-0573-4526-9136-97D3492D7DEF@FreeBSD.org> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: Ryan Stone , freebsd-toolchain@FreeBSD.org 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: Wed, 11 Jun 2014 12:31:00 -0000 On Tue, Jun 10, 2014 at 07:38:19AM +0100, David Chisnall wrote: > 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. > > > > 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. > > 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. Hi David, 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. Thanks, Kai