From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: X-Archive-Original-Message-ID: <199709121000.UAA11393@home.mariah.net.au> Date: Fri, 12 Sep 1997 07:54:33 -0400 From: Uncle George Subject: Re: dlsym() & multiple libs.so. how should it work This is a multi-part message in MIME format. --------------9B57471D21E984BA65D3E7FF Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Richard Henderson wrote: > > say for instance i have a main(), and a private .so (private because I > > created it for this pgm). in the private .so there is a global open() > > routine. ALSO in the private .so, in another routine, there is a call > > to dlsym(RTLD_NEXT, "OPEN"). > [...] > > What address should be returned - the open from my private .so, or the > > one from libc.so ?? if dlsym was called from private.so ?? > RTLD_NEXT returns the symbol from the shared object "next" on the > dependancy list from the location of call. Thus if main uses it, > it will find the symbol in private.so, and if private.so uses it, > it will find it in libc.so.6. > > Plz try this pgm. lemme know if this doesn't surprise u. According to u I should get open() from libc.so.6, but on axp ( i suspect i86 also ) u get open() from open.so --------------9B57471D21E984BA65D3E7FF Content-Type: text/plain; charset=us-ascii; name="c" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="c" ***************** c1.c ************************ #include int open ( int); typedef int (*sym)(); void * mydlsym( void *, char *); main () { sym thispgm = (sym) &open; sym libc_so = (sym) mydlsym(RTLD_NEXT, "open"); // put a breakpoint here // see what libc_so contains // rearrange the shared libs ( gdb/info share ) // you dont always get what u expect!!!!!! // Uncle George printf(" addr of open= %p, addr of dlsym = %p\n", thispgm, libc_so); return; open (21); } ****************** open.c ************************** #include open(i) { ; } void * mydlsym(opt,name) char *name; void * opt; { int (*p)() = dlsym( opt, name ); return p; } ************************************* cc -g -c open.c ld -G -o open.so open.o cc -g -c c1.c cc -o c1 c1.o open.so -ldl export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. gdb c1 --------------9B57471D21E984BA65D3E7FF-- -- To unsubscribe: send e-mail to axp-list-request@redhat.com with 'unsubscribe' as the subject. Do not send it to axp-list@redhat.com