problem with dynamic_cast

Kris Thielemans kris.thielemans@ic.ac.uk
Fri Sep 8 04:48:00 GMT 2000


> -----Original Message-----
> From: Chris Faylor [ mailto:cgf@cygnus.com ]
> Sent: 07 September 2000 17:01
> To: Gnuwin
> Cc: kris.thielemans@csc.mrc.ac.uk
> Subject: Re: problem with dynamic_cast
>
>
> This is a c++ problem.  You should probably report this to a c++
> mailing list.

I doubt it really, but I send this to a C++ mailing list anyway. I've been
able to boil it down to something really simple. If the latest gcc
distribution is that broken, we're all in trouble.

Summarising: in cygwin 1.1.4, or the gcc (or ld) distributed with it (I've
installed 1.1.4 yesterday), there is a conflict with using RTTI and using
the math library.


Attached is a VERY simple C++ program that uses RTTI, but nothing else.
Compile it with

g++ dynamic_cast.cxx -lm

When you run it, it crashes in the dynamic_cast statement. On the other
hand, compile it with

g++ dynamic_cast.cxx

-> it runs fine (i.e. does essentially nothing).




More details:

I'm running NT 4.0 sp5 and cygwin 1.1.4.

screendump of running g++ -v:

$ g++ dynamic_cast.cxx -lm -v
Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/2.95.2/specs
gcc version 2.95.2 19991024 (release-2)

/usr/lib/gcc-lib/i686-pc-cygwin/2.95.2/cpp.exe -lang-c++ -v -D__GNUC__=2 -D_
_GN
UG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -Di386 -D_X86=1 -D__STDC__=1 -D__st
dcal
l=__attribute__((__stdcall__)) -D__cdecl=__attribute__((__cdecl__)) -D__decl
spec
(x)=__attribute__((x)) -D__i386__ -D_X86=1 -D__STDC__=1 -D__stdcall=__attrib
ute_
_((__stdcall__)) -D__cdecl=__attribute__((__cdecl__)) -D__declspec(x)=__attr
ibut
e__((x)) -D__i386 -Asystem(winnt) -Acpu(i386) -Amachine(i386) -D__EXCEPTIONS
 -re
map -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -Di686 -Dpentiump
ro -
D__i686 -D__i686__ -D__pentiumpro -D__pentiumpro__ -D__CYGWIN32__ -D__CYGWIN
__ -
Dunix -D_WIN32 -DWINNT dynamic_cast.cxx /cygdrive/c/TMP/ccpF3zVU.ii
GNU CPP version 2.95.2 19991024 (release-2) (80386, BSD syntax)
#include "..." search starts here:
#include <...> search starts here:
 /usr/include
 /usr/lib/gcc-lib/i686-pc-cygwin/2.95.2/../../../../include/g++-3
 /usr/lib/gcc-lib/i686-pc-cygwin/2.95.2/../../../../include
 /usr/include
 /usr/lib/gcc-lib/i686-pc-cygwin/2.95.2/include
 /usr/include
End of search list.
The following default directories have been omitted from the search path:
 /usr/include/g++
 /usr/X11R6.4/include
 /usr/local/include
End of omitted list.
 /usr/lib/gcc-lib/i686-pc-cygwin/2.95.2/cc1plus.exe
/cygdrive/c/TMP/ccpF3zVU.ii
-quiet -dumpbase dynamic_cast.cc -version -o /cygdrive/c/TMP/ccKbIuaN.s
GNU C++ version 2.95.2 19991024 (release-2) (i686-pc-cygwin) compiled by GNU
C v
ersion 2.95.2 19991024 (release-2).
 as -o /cygdrive/c/TMP/cc7g2nmV.o /cygdrive/c/TMP/ccKbIuaN.s
 /usr/lib/gcc-lib/i686-pc-cygwin/2.95.2/collect2.exe -Bdynamic
/usr/lib/crt0.o -
L/usr/lib/gcc-lib/i686-pc-cygwin/2.95.2
/cygdrive/c/TMP/cc7g2nmV.o -lstdc++ -lm
-lgcc -lcygwin -luser32 -lkernel32 -ladvapi32 -lshell32 -lgcc

ld.dump attached is a screendump from running ld --verbose explicitly, after
removing as much libraries and options I could, while still reproducing the
crash.


gdb.dump is a screendump from running gdb on the file
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dynamic_cast.cxx
Type: text/x-c++
Size: 328 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20000908/749e1735/attachment.bin>
-------------- next part --------------
(gdb) r
Starting program: /home/kris/C++/test-gcc/a.exe

Program received signal SIGSEGV, Segmentation fault.
0x80d0 in ?? ()
(gdb) info stack
#0  0x80d0 in ?? ()
#1  0x402054 in __si_type_info::dcast (this=0x4070f4, to=@0x4070e4,
    require_public=1, addr=0x241fd90, sub=0x4070d4, subptr=0x241fd90)
    at /cygnus/netrel/src/gcc-2.95.2-2/gcc/cp/tinfo.cc:76
#2  0x4022a3 in __dynamic_cast (from=0x4059c4 <C type_info function>,
    to=0x405988 <B type_info function>, require_public=1, address=0x241fd90,
    sub=0x405958 <A type_info function>, subptr=0x241fd90)
    at /cygnus/netrel/src/gcc-2.95.2-2/gcc/cp/tinfo2.cc:38
#3  0x40107a in f (aptr=0x241fd90) at dynamic_cast.cxx:25
#4  0x4010fc in main () at dynamic_cast.cxx:43
#5  0x61002272 in _size_of_stack_reserve__ ()
#6  0x61002805 in _size_of_stack_reserve__ ()
#7  0x61002843 in _size_of_stack_reserve__ ()
#8  0x40117d in cygwin_crt0 () at dynamic_cast.cxx:45
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ld.dump
Type: text/x-asm
Size: 4541 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20000908/749e1735/attachment-0001.bin>


More information about the Cygwin mailing list