From owner-freebsd-toolchain@FreeBSD.ORG Tue Jun 10 01:48:09 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 7AC5C7C7 for ; Tue, 10 Jun 2014 01:48:09 +0000 (UTC) Received: from mail-ob0-x233.google.com (mail-ob0-x233.google.com [IPv6:2607:f8b0:4003:c01::233]) (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 4997728AE for ; Tue, 10 Jun 2014 01:48:09 +0000 (UTC) Received: by mail-ob0-f179.google.com with SMTP id uz6so1979227obc.24 for ; Mon, 09 Jun 2014 18:48:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=z/+NqzMpDMLWDRuaLkvElrovvKwlibEuMIPooBjgZJw=; b=hKlxJZV+va0CY6GkqtJDoDW/K+VyS/VUymJFIZbOfkOxFOeKUGeVySl70XAgAYQWw4 XkzOpiPuj/FQ5K7ltsGVLaW8xkOmLXC6cGt3lsxVshuXOQZydLhZjtT1A0PvlH0l3cMp 9wE5NOYvP/52OYuWPyQklxuBKN7+jpau6Yv/7tkaM/rdibIS7GW55yC/RolW3ZMPMYew 90Rb/9VpL3voNurEYZTEx6rXwzQTfcW9nuyBc9/cEghoixWZV2TCNYbYRxZIbErUtY30 BEvYQdFBj3BAeTPyzMOvBKjDxQznciRx/cCfuzpXfWF7FFY6ZFIuL5S5NQKMqTK2pKT1 v7vA== MIME-Version: 1.0 X-Received: by 10.60.62.174 with SMTP id z14mr13018369oer.61.1402364888420; Mon, 09 Jun 2014 18:48:08 -0700 (PDT) Received: by 10.76.23.130 with HTTP; Mon, 9 Jun 2014 18:48:08 -0700 (PDT) Date: Mon, 9 Jun 2014 21:48:08 -0400 Message-ID: Subject: abi::__cxa_demangle provides invalid result on non-mangled symbols From: Ryan Stone To: freebsd-toolchain@freebsd.org Content-Type: text/plain; charset=UTF-8 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 01:48:09 -0000 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. The sample program below demonstrates the problem. I note that __cxa_demangle seems to work correctly on symbols that start with an underscore, so I guess that I can use that as a workaround, but it would be nice if this worked without hackery (plus I'm not at all confident that all mangled symbols must start with an underscore). #include #include #include int main(int argc, char **argv) { const char *symbol; char *demangled; size_t len; int status; if (argc != 2) { fprintf(stderr, "Usage: %s \n", argv[0]); return (1); } symbol = argv[1]; len = 0; status = 0; demangled = abi::__cxa_demangle(symbol, NULL, &len, &status); printf("__cxa_demangle(\"%s\") = \"%s\", status=%d\n", symbol, demangled, status); return (0); } [rstone@rstone-server demangle]uname -a FreeBSD rstone-server 11.0-CURRENT FreeBSD 11.0-CURRENT #0 r254461+992b524(server_config): Thu May 22 22:19:47 EDT 2014 root@rstone-server:/usr/obj/usr/src/sys/STOCK amd64 [rstone@rstone-server demangle]./demangle memcmp __cxa_demangle("memcmp") = "unsigned long", status=0 [rstone@rstone-server demangle]./demangle _start __cxa_demangle("_start") = "(null)", status=-2 [rstone@rstone-desktop shm]uname -a Linux rstone-desktop 3.13.0-29-generic #53-Ubuntu SMP Wed Jun 4 21:00:20 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux [rstone@rstone-desktop shm]./demangle __cxa_demangle("memcmp") = "(null)", status=-2