From owner-freebsd-toolchain@FreeBSD.ORG Wed Jun 11 20:53:42 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 EA890F01; Wed, 11 Jun 2014 20:53:42 +0000 (UTC) Received: from mail-qa0-x22b.google.com (mail-qa0-x22b.google.com [IPv6:2607:f8b0:400d:c00::22b]) (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 9A366250B; Wed, 11 Jun 2014 20:53:42 +0000 (UTC) Received: by mail-qa0-f43.google.com with SMTP id k15so459434qaq.30 for ; Wed, 11 Jun 2014 13:53:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type:content-transfer-encoding; bh=k03J2+VevTGLQSWK3BxpZNERpIJhA8c+HP0yvv29Auw=; b=Y8sQhgxHaOUgLDy6z00vMGbg19UjHmRw9kWNlBaVhme2zkpbGGHusWtVM7vGVx2T5K hTop3oZIK1TU9F8T8x7zWpP49KArE1yEpI+ziadsxCgodafKDJX6RYvwYmy7ing+8IF2 xQs7BGrulCBFh5ws+4rpFXmqL0r2nwsuCwDHba/zVhryK2k0llm2xLz64IOd4ggES77R xt88HbGbeOXdpplo8b+U2rUfiw1ZfAXtjmywu2mTYmOyyQdHvfWyghI0LCqbIphVrZhc +/Ozze5ixj3oHHoHK8TKFBNLJTdHOD8BVUjoQepWVH42tSeBr+kMLyf0agi4vONTnpY/ F5cg== MIME-Version: 1.0 X-Received: by 10.229.220.197 with SMTP id hz5mr54963104qcb.9.1402520021483; Wed, 11 Jun 2014 13:53:41 -0700 (PDT) Sender: carpeddiem@gmail.com Received: by 10.140.49.239 with HTTP; Wed, 11 Jun 2014 13:53:41 -0700 (PDT) In-Reply-To: <9BDAE8E2-0573-4526-9136-97D3492D7DEF@FreeBSD.org> References: <9BDAE8E2-0573-4526-9136-97D3492D7DEF@FreeBSD.org> Date: Wed, 11 Jun 2014 16:53:41 -0400 X-Google-Sender-Auth: AbbszqL4ZY0k7PscuplUS2HVd5w Message-ID: Subject: Re: abi::__cxa_demangle provides invalid result on non-mangled symbols From: Ed Maste To: David Chisnall Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: Wed, 11 Jun 2014 20:53:43 -0000 On 10 June 2014 02:38, David Chisnall wrote: > > 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 n= eed to remember that some systems prepend an underscore to all compiler-gen= erated symbols, so you may also need to check for __Z and trim the leading = _. Right, it just feels hackish to have to know this detail of the ABI. I think I'd like an explicit __cxa_demangle_symbol interface, or perhaps __cxa_is_mangled_symbol to query a string. > The __cxa_demangle() function has to handle things that are not just symb= ols (types and so on) and so can't do this test itself. Its most common us= e is generating a human-friendly error for an uncaught exception, where it = is just parsing a type encoding. My use, and I suspect Ryan's, is demangling symbols obtained from introspection interfaces like backtrace_symbols(3). In any case, our libelftc __cxa_demangle accepts strings that are neither symbols nor NTBS manglings, and can return a bogus demangled name for them. Of course, it's a mistake to rely on __cxa_demangle rejecting these for arbitrary input.