libcxx: support typeids across DLL boundary

Yaron Keren yaron.keren at gmail.com
Fri Nov 22 05:18:47 PST 2013


On Windows, typeids are different between DLLs and EXEs, so comparing
type_info* will work for typeids from the same compiled file but fail for
typeids from a DLL and an executable. Among other things, exceptions are
not caught by handlers since can_catch() returns false.

Defining _LIBCXX_DYNAMIC_FALLBACK does not help since can_catch() calls
is_equal() with use_strcmp=false so the string names are not compared.

This patch compares typeids first (cheap) and only they are different calls
strcmp.

If libcxxabi with Visual C++ has the same problem, __MINGW32__ should be
replaced with _WIN32 in both locations.

Yaron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131122/0b5f1eea/attachment.html>
-------------- next part --------------
Index: private_typeinfo.cpp
===================================================================
--- private_typeinfo.cpp	(revision 195452)
+++ private_typeinfo.cpp	(working copy)
@@ -40,6 +40,21 @@
 #include <sys/syslog.h>
 #endif
 
+// On Windows, typeids are different between DLLs and EXEs, so comparing
+// type_info* will work for typeids from the same compiled file but fail
+// for typeids from a DLL and an executable. Among other things, exceptions
+// are not caught by handlers since can_catch() returns false.
+//
+// Defining _LIBCXX_DYNAMIC_FALLBACK does not help since can_catch() calls 
+// is_equal() with use_strcmp=false so the string names are not compared.
+//
+// If libcxxabi with Visual C++ has the same problem, __MINGW32__ should be
+// replaced with _WIN32 both here and below in is_equal().
+
+#ifdef __MINGW32__
+#include <string.h>
+#endif
+
 namespace __cxxabiv1
 {
 
@@ -62,7 +77,11 @@
 bool
 is_equal(const std::type_info* x, const std::type_info* y, bool)
 {
+#ifndef __MINGW32__
     return x == y;
+#else
+    return (x == y) || (strcmp(x->name(), y->name()) == 0);
+#endif    
 }
 
 #endif  // _LIBCXX_DYNAMIC_FALLBACK


More information about the cfe-commits mailing list