libcxx: support typeids across DLL boundary

Reid Kleckner rnk at google.com
Fri Nov 22 14:10:30 PST 2013


One other thing to think about is: are typeid names of internal types
unique?  MSVC seems to get it wrong, as in this prints 1:

$ cat t.cpp
#include <typeinfo>
#ifdef CONFIG_1
namespace { struct Foo { int a; }; }
const std::type_info &tu1() { return typeid(Foo); }
#else
namespace { struct Foo { float b; }; }
const std::type_info &tu1();
const std::type_info &tu2() { return typeid(Foo); }
extern "C" void printf(const char *, ...);
int main() {
  printf("tu1() == tu2(): %d\n", tu1() == tu2());
}
#endif

$ cl -c t.cpp && cl -c -DCONFIG_1 t.cpp -Fot2.obj && cl t.obj t2.obj &&
./t.exe
...
tu1() == tu2(): 1


On Fri, Nov 22, 2013 at 1:48 PM, Yaron Keren <yaron.keren at gmail.com> wrote:

> OK, fixed.
>
>
>
> 2013/11/22 Reid Kleckner <rnk at google.com>
>
>> Yes, this is just a property of COFF, so it should be _WIN32.
>
>
>
> On Fri, Nov 22, 2013 at 5:18 AM, Yaron Keren <yaron.keren at gmail.com>wrote:
>
>> 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
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131122/03151ee5/attachment.html>


More information about the cfe-commits mailing list