Bug 64042

Summary: dlsym open symbols from dependency libraries
Product: [Retired] Red Hat Linux Reporter: Joe Krahn <krahn>
Component: glibcAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact: Brian Brock <bbrock>
Severity: low Docs Contact:
Priority: medium    
Version: 7.2CC: fweimer
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2002-12-15 20:02:06 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Joe Krahn 2002-04-24 11:47:24 UTC
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());

}

Comment 1 Joe Krahn 2002-04-25 12:33:40 UTC
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.

Comment 2 Joe Krahn 2002-05-07 02:31:02 UTC
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)).