public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* How to make gcc give a check about symbol conflicts in shared libraries it links?
@ 2011-11-07  7:44 xiaxia347work
  2011-11-07 15:33 ` Ian Lance Taylor
  0 siblings, 1 reply; 5+ messages in thread
From: xiaxia347work @ 2011-11-07  7:44 UTC (permalink / raw)
  To: gcc-help

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  

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

end of thread, other threads:[~2011-11-08  6:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-07  7:44 How to make gcc give a check about symbol conflicts in shared libraries it links? xiaxia347work
2011-11-07 15:33 ` Ian Lance Taylor
2011-11-08  2:22   ` xiaxia347work
2011-11-08  5:57     ` Ian Lance Taylor
2011-11-08  6:13       ` 回复: " xiaxia347work

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).