From Bugzilla Helper: User-Agent: Mozilla/4.78 [en] (X11; U; Linux 2.4.9-21 i686) Description of problem: If you dlopen a library, dlsym will successfully return a pointer to symbols from not just the opened lib, but any dependency libs. This may be more a feature than bug. IRIX's dlsym will only return symbols from the dlopened lib. I think that's how it is supposed to work. Version-Release number of selected component (if applicable): How reproducible: Always Steps to Reproduce: 1. printf("XNextEvent via libGL=%x\n", dlsym(dlopen("libGL.so", RTLD_LAZY | RTLD_LOCAL ), "XNextEvent")); 2. 3. Actual Results: XNextEvent via GL=4021d564 Expected Results: XNextEvent via GL=0 Additional info: It doesn't matter which dlopen flags I use. I can even get at _dl_init from /lib/ld-linux.so.6, which is a second level of dependency via libc.so. Here is a simple example test code: #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()); }
Checking some docs from LSB, dlopen is supposed load dependency libraries, but it never defines whether dlsym should return symbols from those dependency libraries. So that could be just a feature that differs by OS. The problem that does exist is that objects opened with RTLD_LOCAL are globally available, so you get the same result as when using RTLD_GLOBAL. This doesn't interefere with typical dlopen usage, so it's only a minor problem.
I think this is NOTABUG. I checked and found that RTLD_GLOBAL/LOCAL differences work OK. Availability of symbols in dependent objects is different from IRIX, but I think IRIX is wrong. However, it would be helpful to explain this in the man page. Here's an example from the HP dlsym manpage that agrees w/ Linux: dlsym searches for the named symbol in all shared objects loaded automatically as a result of loading the object referenced by handle (see dlopen(3c)).