NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/49791: dlopen(0, and dlopened libraries



>Number:         49791
>Category:       lib
>Synopsis:       dlopen(0, and dlopened libraries
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Mar 26 23:45:00 +0000 2015
>Originator:     Patrick Welche
>Release:        NetBSD-7.99.7/amd64
>Organization:
>Environment:
>Description:
Back in 2004, Julio Merino points out in a glib bug

  https://bugzilla.gnome.org/show_bug.cgi?id=140329

that our dlopen() does (cf dlfcn(3))

     If the first argument is NULL, dlopen() returns a handle on the global
     symbol object.  This object provides access to all symbols from an
     ordered set of objects consisting of the original program image and any
     dependencies loaded during startup.

whereas accoding to posix in

  http://pubs.opengroup.org/onlinepubs/007904975/functions/dlopen.html

If the value of file is 0, dlopen() shall provide a handle on a global symbol object. This object shall provide access to the symbols from an ordered set of objects consisting of the original program image file, together with any objects loaded at program start-up as specified by that process image file (for example, shared libraries), and the set of objects loaded using a dlopen() operation together with the RTLD_GLOBAL flag. As the latter set of objects can change during execution, the set identified by handle can also change dynamically.


glib assumes the posix variant, and we have a patch in pkgsrc to detect ours as broken.
>How-To-Repeat:
Try:

#include <err.h>
#include <dlfcn.h>
#include <stdio.h>

int main()
{
    void *handle;

    handle = dlopen ("libm.so", RTLD_GLOBAL | RTLD_LAZY);
    if (handle == NULL)
        errx(1, "dlopen of libm failed (%s)", dlerror());

    handle = dlopen (NULL, 0);
    if (handle == NULL)
        errx(1, "dlopen of global symbol object failed (%s)", dlerror());

    handle = dlsym (handle, "sin");
    if (handle == NULL)
        errx(1, "sin() not found in libm (%s)", dlerror());

    return 0;
}


$ ./dltest
dltest: sin() not found in libm (Undefined symbol "sin")

>Fix:



Home | Main Index | Thread Index | Old Index