Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
* dlopen() problem with symbols. very strange.
@ 2001-12-04 14:53 Moshe Livne
  2001-12-05 12:23 ` Moshe Livne
  0 siblings, 1 reply; 2+ messages in thread
From: Moshe Livne @ 2001-12-04 14:53 UTC (permalink / raw)


Hi,

We noticed that when loading a dynamic library using dlopen on Tru64,
if a symbol exist on both the library and the main, the symbols inside
the library are resolved to the symbols in the main program. so, if I
have a function a() in my main. I am loading a library that has
function a() inside it as well, dynamically resolve b() (that calls
a()) from the library, call it, it will call a() from the main.

As I think I managed to confuse myself as well, I am including a super
simple source that demonstrates the problem:

dll_main.c:
#include <stdio.h>


void a()
{
        printf("in a in dll_main\n");
}

void dll_stam()
{
        printf("in dll_stam\n");
        a();
}

********** compile with 
cc -c dll_main.c
ld dll_main.o -shared -o dll.so -lc -lpthread
********************************************************

test.c:
#include <stdio.h>
#include <dlfcn.h>
#include <pthread.h>
#include <errno.h>

void (*dll_f)() ;

void a() {
        printf("a in main!\n");
}


main()
{
   void *dll_handle ;

   dll_handle = dlopen("./dll.so" , RTLD_LOCAL) ;
   if ( dll_handle == NULL )
   {
      printf("failed to load dll2.so, error is %s\n" , dlerror()) ;
      return(1) ;
   }

   dll_f = (void *)dlsym(dll_handle , "dll_stam") ;
   if ( dll_f == NULL )
   {
      printf("failed to map dll_f\n") ;
      return(2) ;
   }


   (*dll_f)();

   dlclose(dll_handle) ;

   return(0) ;
}
******** compile with cc test.c -o test -lpthread 

the output I get:
bash-2.01# ./test
in dll_stam
a in main!


As you can see, the wrong a() was called.

Thanks,
Moshe


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: dlopen() problem with symbols. very strange.
  2001-12-04 14:53 dlopen() problem with symbols. very strange Moshe Livne
@ 2001-12-05 12:23 ` Moshe Livne
  0 siblings, 0 replies; 2+ messages in thread
From: Moshe Livne @ 2001-12-05 12:23 UTC (permalink / raw)


solved - used the -B symbolic in the ld command


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-12-05 12:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-12-04 14:53 dlopen() problem with symbols. very strange Moshe Livne
2001-12-05 12:23 ` Moshe Livne

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