[cfe-dev] Implementation of stdbool.h

Török Edwin edwintorok at gmail.com
Fri Feb 29 06:39:02 PST 2008

Keith Bauer wrote:
> On Fri, Feb 29, 2008 at 7:18 PM, Chris Lattner <clattner at apple.com> wrote:
>>  Actually, dladdr seems useful on unix'y systems.  Does this work on
>>  linux?
> A quick trip to Google suggests that dladdr is nonstandard,
> implemented on Solaris, Linux (glibc), Mac OS X, maybe FreeBSD,
> definitely not OpenBSD.

It depends on OpenBSD version, on 4.2 it works[*], but only if you pass
an address of a symbol from a dynamic libray, not the main executable.
So this works:
$ gcc -shared p.c -o p.so
$ gcc p.so
$ LD_LIBRARY_PATH=. ./a.out

Note that you'll get the path to the library!
[*] it looks like it works since OpenBSD 3.6 (2004): "Add dladdr(3)
<http://www.openbsd.org/cgi-bin/man.cgi?query=dladdr&sektion=3> support
to the dynamic loader" (http://www.openbsd.org/plus36.html)

Also on Linux you need to #define _GNU_SOURCE, otherwise you get a
compile error (Dl_info undeclared).

Have a look at dlloader.h from XFree86 (http://preview.tinyurl.com/3yxc9e)
#if (defined(linux) && defined(__GLIBC__)) || \

   (defined(__FreeBSD__) && defined(__ELF__)) || \
    defined(__NetBSD__) || \
    (defined(__OpenBSD__) && defined(OpenBSD) && OpenBSD >= 200411) || \
    (defined(sun) && defined(SVR4)) || \
#define *HAVE_DLADDR*

Best regards,

More information about the cfe-dev mailing list