From owner-freebsd-toolchain@FreeBSD.ORG Tue Jun 10 03:01:51 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 48CAB6DB; Tue, 10 Jun 2014 03:01:51 +0000 (UTC) Received: from mail-oa0-x234.google.com (mail-oa0-x234.google.com [IPv6:2607:f8b0:4003:c02::234]) (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 07C9A2EBB; Tue, 10 Jun 2014 03:01:50 +0000 (UTC) Received: by mail-oa0-f52.google.com with SMTP id j17so3310064oag.39 for ; Mon, 09 Jun 2014 20:01:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=fii2aP0Y9j7hLKnKnmb9aWIS9qL3b3Iyuwhzk1B8fJY=; b=dgmxddjqKAK2RCCibAQNnugpfoEnvePokHsTKdmcrOXvbEd5KTtQNvKXger74BNk4I gGNcBlP8qZYiVPxaAFPLuwPw9mfSeMQC4XKxRxbbUaWfCJ2LcK39r+Hw1/1d6qgjzcw/ k7Qrb30spTETz/GHkxMqGncaxQsdqbTH1WUMtRQm3Q2nn2bKVXCT+I6trPtL+I1yRZlr gIXTH/iEY1BPJ7xVWKqot7UwqmN4DJtLtY/wt1Vt2CETJ+bTaVMCyxv65ZJzBzUlmmT9 02dkt8vzt0umdh4jFQazGFbnsGTiRLhsgwLcBFyOheByBjvooE0DdPjtKDlrz7U+GWJ+ l4EA== MIME-Version: 1.0 X-Received: by 10.60.45.130 with SMTP id n2mr30157121oem.12.1402369310218; Mon, 09 Jun 2014 20:01:50 -0700 (PDT) Received: by 10.76.23.130 with HTTP; Mon, 9 Jun 2014 20:01:50 -0700 (PDT) In-Reply-To: References: Date: Mon, 9 Jun 2014 23:01:50 -0400 Message-ID: Subject: Re: abi::__cxa_demangle provides invalid result on non-mangled symbols From: Ryan Stone To: Ed Maste Content-Type: text/plain; charset=UTF-8 Cc: 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: Tue, 10 Jun 2014 03:01:51 -0000 On Mon, Jun 9, 2014 at 10:44 PM, Ed Maste wrote: > On 9 June 2014 21:48, Ryan Stone 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@rstone-desktop shm]./demangle f __cxa_demangle("f") = "float", status=0 [rstone@rstone-desktop shm]./demangle i __cxa_demangle("i") = "int", status=0 [rstone@rstone-desktop shm]./demangle m __cxa_demangle("m") = "unsigned long", status=0 [rstone@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.