dlsym bug?

Joe Krahn jkrahn@nc.rr.com
Wed Apr 24 05:36:00 GMT 2002


If I dlopen a library, dlsym will return pointers to
symbols not only from the dlopened lib, but from any
of it's dependency libraries. I don't think it is
supposed to work that way. IRIX, for example, won't
return dependency lib symbols.

Example code follows. It dlopens libGL, and is then
able to access XNextEvent from libX11, and even
_dl_init from ld-linux.so.6, which is loaded by libc.
It doesn't matter which dlopen flags are used.

Is this a bug or feature? Is it gcc or glibc?

Thanks, Joe Krahn


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

int main(int argc, char *argv[]){

    void *GL_handle, *func;

    GL_handle = dlopen("libGL.so", RTLD_LAZY | RTLD_LOCAL );
    printf("GL Handle=%x [dlerror=%s]\n",GL_handle,dlerror());

    func = dlsym(GL_handle, "XNextEvent");
    printf("XNextEvent via GL =%x [dlerror=%s]\n",func,dlerror());

    func = dlsym(GL_handle, "_dl_init");
    printf("_dl_init via GL =%x [dlerror=%s]\n",func,dlerror());

}



More information about the Gcc-bugs mailing list