bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

DLOPEN : glibc-2.3.1 / 31 Jan 05


From: PERRAUD JeanClaude
Subject: DLOPEN : glibc-2.3.1 / 31 Jan 05
Date: Wed, 09 Feb 2005 16:50:41 +0100

<address@hidden>     PROBLEM   :  DLOPEN  :  glibc-2.3.1   / 31 Jan
05 

   note : this problem exists  also in the previous  libc .... 


  ***************************************************************
  * problem : from a STATIC executable , dlopen() cannot  link  *
  * if exists some "extern" variable in  the shared lib to link *
  * with some global  variable of the main programme            *
  ***************************************************************



######################### LINUX  references  
#######################################################

#
uname -a
#
Linux pcperraud2 2.4.21-0.13mdk #1 Fri Mar 14 15:08:06 EST 2003 i686
unknown unknown GNU/Linux
#
gcc -v
#
Reading specs from
/usr//bin/../lib/gcc-lib/i586-mandrake-linux-gnu/3.2.2/specs
Configured with: ../configure --prefix=/usr --libdir=/usr/lib
--with-slibdir=/lib 
--mandir=/usr/share/man --infodir=/usr/share/info --enable-shared
--enable-threads=posix 
--disable-checking --enable-long-long --enable-__cxa_atexit
--enable-languages=c,c++,ada,f77,objc,java 
--host=i586-mandrake-linux-gnu --with-system-zlib
Thread model: posix
gcc version 3.2.2 (Mandrake Linux 9.1 3.2.2-3mdk)
#

######################  Shared LIB : file : libso.c
################################################## 

#include <stdio.h>   
  
extern   int    SpiceDebugMode ;  
 
int    
exfunc( ) 
{   
   fprintf(stderr,"*******************  OK  exfunc   START  
SpiceDebugMode=%d\n", SpiceDebugMode);   

   return ( SpiceDebugMode ) ;          
}

#######################################################################################################

#  create the shared lib libso.so
# 
gcc -g  -Wall  -shared -fPIC   libso.c  -Wl,-E -lm -lc -o  libso.so 
# 


###################### Executable : file : loadso.c
################################################### 
  

#include <stdio.h>   
#include <dlfcn.h>  
 
int    SpiceDebugMode  ;  
void   *handle = NULL   ; 

int    
main( argc, argv )
        int     argc;
        char    **argv;
{   
   char    *name; 
   int     res; 

    fprintf( stderr, " !! main Start \n" );  
    SpiceDebugMode = 4321 ; 
    fprintf( stderr, " !! main 1 \n" );  
    name =  "./libso.so";    

    handle = dlopen( name , (RTLD_NOW | RTLD_GLOBAL));
  
    printf("load file(0) \"%s\"  handle:%#10x error:\"%s\"  \n", 
             name , (int) handle , dlerror() );  
    if (handle == NULL) 
       {
       printf("couldn't load file \"%s\" \n",  name );
       exit(1); 
       }

   printf("*******************  OK load file \"%s\"  handle%#10x \n", 
name,  (int)handle);  
   fprintf( stderr, " !! END  \n" ); 

   exit(0);
                
}

########################################################################################################


#  create the  DYNAMIC  executable loadso.exe
# 
gcc -g  -rdynamic   loadso.c /usr/lib/libdl.a -lc   -lm -o loadso.exe 
# 

########################################################################################################


#  EXEC  the  DYNAMIC  executable loadso.exe    : OK
# 
loadso.exe
 !! main Start 
 !! main 1 
load file(0) "./libso.so"  handle: 0x804a2d0 error:"(null)"  
*******************  OK load file "./libso.so"  handle 0x804a2d0 
 !! END  

########################################################################################################
 
########################################################################################################


#  create the STATIC  executable loadso.exe
# 
gcc -g  -rdynamic  loadso.c  -Wl,-a,archive -ldl  -o loadso.exe 
#  OR
gcc -g  -rdynamic  loadso.c  -Wl,-a,archive -ldl  -lc_nonshared -lc
-lc_pic -lm -o loadso.exe 
# 

########################################################################################################


#  EXEC  the  STATIC  executable loadso.exe     : ERROR
# 
loadso.exe   
 !! main Start 
 !! main 1 
load file(0) "./libso.so"  handle:         0 error:"./libso.so:
undefined symbol: SpiceDebugMode"  
couldn't load file "./libso.so" 
  


########################################################################################################
 
conclusion :
************

  ***************************************************************
  * problem : from a STATIC executable , dlopen() cannot  link  *
  * if exists some "extern" variable in  the shared lib to link *
  * with some global  variable of the main programme            *
  ***************************************************************

  from a STATIC executable , dlopen() cannot  link :

     => C  :  "Extern  variable"   used in a shared library 
to a
     => C  :  "Global variable    defined in the STATIC executable ...



   note  : from a  DYNAMIC  executable , dlopen()  works !!!


########################################################################################################


    Jean Claude PERRAUD  31 JAN 2005    /  address@hidden


#############################         EOF      
########################################################




reply via email to

[Prev in Thread] Current Thread [Next in Thread]