From: curt <mi...@no...> - 2013-12-30 01:42:09
|
Just ported some libraries of mine to a new project and one of the well-used one choked and died. After some sluthing I found the problem appears to be thing mingw linker getting confused on what to call. Simplified example: #include <stdio.h> #include <stdarg.h> void polyCrash( const char* format, ... ) { va_list arg; va_start( arg, format ); char buf[80]; vsnprintf( buf, 80, format, arg ); va_end( arg ); } void polyCrash( const char* format, va_list arg ) { char buf[80]; vsnprintf( buf, 80, format, arg ); } int main( int argc,char *argv[] ) { polyCrash( "%s", (char *)"crash" } compile with a simple: gcc -o t test.cpp and boom crash, dump looks like this: cygwin$ gcc src/main.cpp -O0 -ggdb -o test cygwin$ gdb test GNU gdb (GDB) 7.6.1 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "mingw32". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from C:\curt\dot\fl\world\test.exe...done. (gdb) run Starting program: C:\curt\dot\fl\world/test.exe [New Thread 5564.0x668] Program received signal SIGSEGV, Segmentation fault. 0x75de43df in strlen () from C:\Windows\syswow64\msvcrt.dll (gdb) where #0 0x75de43df in strlen () from C:\Windows\syswow64\msvcrt.dll #1 0x00404dd7 in __pformat_puts (stream=0x28fdfc, s=0x73617263 <Address 0x73617263 out of bounds>) at ../mingwrt-4.0.3-1-mingw32-src/misc/src/libcrt/stdio/pformat.c:338 #2 __mingw_pformat (flags=flags@entry=0, dest=dest@entry=0x28fe80, max=max@entry=79, fmt=0x40a06c <__register_frame_info+4235372> "", fmt@entry=0x40a06a <__register_frame_info+4235370> "%s", argv=0x40a068 <__register_frame_info+4235368> "h", argv@entry=0x40a064 <__register_frame_info+4235364> "crash") at ../mingwrt-4.0.3-1-mingw32-src/misc/src/libcrt/stdio/pformat.c:1786 #3 0x00402c18 in __mingw_vsnprintf (buf=0x28fe80 "ŠŠ(", length=79, fmt=0x40a06a <__register_frame_info+4235370> "%s", argv=0x40a064 <__register_frame_info+4235364> "crash") at ../mingwrt-4.0.3-1-mingw32-src/src/libcrt/stdio/vsnprintf.c:58 #4 0x00401706 in polyCrash ( format=0x40a06a <__register_frame_info+4235370> "%s", arg=0x40a064 <__register_frame_info+4235364> "crash") at src/main.cpp:22 #5 0x0040172a in main (argc=1, argv=0xa12b28) at src/main.cpp:31 (gdb) |