This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

How to make gcc give a check about symbol conflicts in shared libraries it links?


Hi,   
     I got a tricky problem when I link my exe program with 2 shared libraries,
 the global variable with same name in the  2 .so file may be linked to the same
 address, resulting problem that is hard to find.  
    
here is the situation:
  
test1.c:  
int global = 1;  
void func1(void) {  
    printf("test1 : %d.\n", global);  
}  
gcc -shared -o test1.so test1.c  

test2.c:  
int global = 2;  
void func2(void) {  
    printf("test2 : %d.\n", global);  
}  
gcc -shared -o test2.so test2.c  

main.c  
int main()  
{  
    func1();  
    func2();  
}  
gcc -c -o main.o main.c  
gcc -o main main.o test1.so test2.so  

then the result would show that the global is set to 1 , one address. something like following is printed:   
"test1 1."  
"test2 1."  

I know this is not a standard way to create shared library for thatit exports all symbols,
 but what I am looking for is  when the main program link the shared libraries, it
 should do a check about whether there is some fucntions/global variables have
 the same name. If that is true, report that or at least give a warning. I have searched
 quite a lot of pages but get no answer, maybe there is an option for gcc could do this?
 otherwise I think there is really some risk when linking shared libraries that
 is not written well.  

Best Regards  
                                                            Wayne Xia  


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]