This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Symbols collision not reported
- From: Matteo Foppiano <matteo dot foppy at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 6 Oct 2011 11:24:18 +0200
- Subject: Symbols collision not reported
- Reply-to: Matteo Foppiano <matteo dot foppy at gmail dot com>
Hi guys,
I had a problem during a C application development because of a
collision between symbols NOT reported (no warnings or errors)
by the linker.
. The application uses libmysqlclient library.
. The applcation declares a global int variable named shutdown:
/* mysql_test.c file */
int shutdwon;
. libmysqlclient declares a function, named vio_close(), that calls
the shutdown() function placed in the libc shared library;
When linking using libmysqlclient as shared library everything is fine.
When linking using libmysqlclient as static library the linker uses the
shutdown variable address instead of shutdown() function address inside
vio_close() without reporting any warning or error.
The application is built using:
gcc -lm -g mysql_test.c libmysqlclient.a -o mysql_test
Debugging with gdb:
(gdb) break vio_close
Breakpoint 1 at 0x8077862: file viosocket.c, line 268.
(gdb) run
Breakpoint 1, vio_close (vio=0x81ee0b0) at viosocket.c:268
268 viosocket.c: No such file or directory.
in viosocket.c
(gdb) disassemble
Dump of assembler code for function vio_close:
. . . CUT . . .
0x08077883 <vio_close+51>: call 0x81ec610 <shutdown>
. . . CUT . . .
End of assembler dump.
(gdb) print &'mysql_test.c'::shutdown
$1 = (int *) 0x81ec610
Ok, the solution is to declare the global shutdown variable static,
since it is used only inside mysql_test.c, but what I wanna know is if
it is correct that in this situation the linker is not able to
recognise the right symbol, or if this not-reported collision is a
linker bug.
Matteo