This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
How to make gcc give a check about symbol conflicts in shared libraries it links?
- From: "xiaxia347work"<xiaxia347work at 163 dot com>
- To: "gcc-help"<gcc-help at gcc dot gnu dot org>
- Date: Mon, 7 Nov 2011 15:44:14 +0800
- Subject: 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