Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: Uncle George <gatgul@voicenet.com>
Subject: Re: dlsym() &amp; multiple libs.so. how should it work
Date: Fri, 12 Sep 1997 07:54:33 -0400	[thread overview]
Message-ID: <fe7cf5ac0e7040a30bba12ee617a7451.axp-list@archive.invalid> (raw)

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 <dlfcn.h>

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 <dlfcn.h>

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

             reply	other threads:[~1997-09-12 11:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-09-12 11:54 Uncle George [this message]
     [not found] <34187B6A.6F7DE1E0@voicenet.com>
1997-09-12  3:20 ` dlsym() &amp; multiple libs.so. how should it work Richard Henderson
  -- strict thread matches above, loose matches on Subject: below --
1997-09-11 23:14 Uncle George
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox