Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
From: moshel@yahoo.com (Moshe Livne)
Subject: dlopen() problem with symbols. very strange.
Date: 4 Dec 2001 06:53:09 -0800	[thread overview]
Message-ID: <fad7c371.0112040653.1909c7e5@posting.google.com> (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


             reply	other threads:[~2001-12-04 14:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-12-04 14:53 Moshe Livne [this message]
2001-12-05 12:23 ` dlopen() problem with symbols. very strange Moshe Livne
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