This is the mail archive of the cygwin-apps@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

GCC 3.1 dynamic_cast fails with DLLs


Can the __GXX_MERGED_TYPEINFO_NAMES patch (alternative #2) proposed by
Jason Merrill at

http://gcc.gnu.org/ml/gcc/2002-05/msg01970.html

be revisited?

The following 3.1 bug was reported by Colin Peters to Mingw list. It
is also a bug on Cygwin GCC 3.1 

"When attempting to use dynamic_cast in an 
executable to cast a base class pointer to an instance 
produced in a DLL to a derived class dynamic_cast 
fails, returning zero. e.g.

 class cFoo { ... };
 class cBar : public cFoo { ... };

 cFoo* pfoo = CreateBarInDLLAndCastToFoo();
 cBar* pbar = dynamic_cast<cBar*>(pfoo);

pbar ends up zero."

A complete testcase, also due to Colin Peters is attached.  Sample output is
included for "make test"  with gcc 2.95.3 (old.out) and gcc 3.1 (new.out).

The .linkonce semantics works for typeinfo objects in static libs, but
does not work for objects exported from pe DLLs. Variable symbols
are prefixed with _imp_ in the import lib. While we can arrange that
user-defined objects in client apps also have the _imp_ prefix, by using
__attribute__((dllimport)), this is awkward for typeinfo objects
generated by the compiler.

The problem can be fixed by reverting to more conservative string comparisons
to determine typeinfo equality.  Rebuilding libstdc++ with this local hack will
fix: 


--- typeinfo.orig	Sun Apr 21 01:22:22 2002
+++ typeinfo	Fri Jun 28 09:22:34 2002
@@ -44,7 +44,7 @@ namespace __cxxabiv1
   class __class_type_info;
 } // namespace __cxxabiv1
 
-#if !__GXX_WEAK__
+#if !__GXX_WEAK__ || defined (__MINGW32__) || defined (__CYGWIN__)
   // If weak symbols are not supported, typeinfo names are not merged.
   #define __GXX_MERGED_TYPEINFO_NAMES 0
 #else


However, the patch suggested by Jason Merrill provides a much cleaner
interface.


Danny


http://www.sold.com.au - SOLD.com.au
- Find yourself a bargain!

Attachment: dyn_cast.tar.gz
Description: dyn_cast.tar.gz


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]