Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 9 Jun 2014 21:48:08 -0400
From:      Ryan Stone <rysto32@gmail.com>
To:        freebsd-toolchain@freebsd.org
Subject:   abi::__cxa_demangle provides invalid result on non-mangled symbols
Message-ID:  <CAFMmRNw_9hS3YuDbjFJH0btvoPADJ7_4=L13z2sK71gctPzXhQ@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
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 <cxxabi.h>
#include <stdio.h>
#include <stdlib.h>

int
main(int argc, char **argv)
{
        const char *symbol;
        char *demangled;
        size_t len;
        int status;

        if (argc != 2) {
                fprintf(stderr, "Usage: %s <symbol>\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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAFMmRNw_9hS3YuDbjFJH0btvoPADJ7_4=L13z2sK71gctPzXhQ>