]> git.ipfire.org Git - thirdparty/man-pages.git/commit - man3/dlopen.3
dlopen.3: Describe confusing dladdr() behavior
authorPetr Baudis <pasky@suse.cz>
Fri, 5 Dec 2008 22:45:53 +0000 (17:45 -0500)
committerMichael Kerrisk <mtk.manpages@gmail.com>
Sat, 6 Dec 2008 03:47:25 +0000 (22:47 -0500)
commit27a61e86221af314a68747f929faa8aba4884101
treeb921215cfdc21f63d4db56e1d4d9324e82dfef84
parentdcaec854fef93d2b5379af59af31dda492211a5f
dlopen.3: Describe confusing dladdr() behavior

dladdr() will act unexpectedly if called from non-pic code on a
compile-time-generated function pointer:

    /* test_dladdr.c */

    #define _GNU_SOURCE
    #include <dlfcn.h>
    #include <stdio.h>

    int
    main(void)
    {
        void *func;
        Dl_info info = {};

        func = printf;
        dladdr(func, &info);
        printf("%s at %p resolved from %s\n", info.dli_sname,
                func, info.dli_fname);

        return 0;
    }

    $ cc test_dladdr.c -ldl
    $ ./a.out
    printf at 0x804838c resolved from ./a.out
    $ cc -fPIC test_dladdr.c -ldl
    $ ./a.out
    _IO_printf at 0xb7f71c30 resolved from /lib/libc.so.6

In the long term, it might make sense to make dladdr() recognize
plt pointers and recurse, but I'm too afraid of Ulrich ;-)
(and he seems to be heavy proponent of pic code anyway, so
the chances for that to be accepted probably aren't high).

Signed-off-by: Petr Baudis <pasky@suse.cz>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
man3/dlopen.3