From mboxrd@z Thu Jan 1 00:00:00 1970 From: abramsh@acm.org To: gcc-gnats@gcc.gnu.org Subject: c++/3993: dynamic_cast<>() fails in simple test case w/ dynamic loading Date: Fri, 10 Aug 2001 22:56:00 -0000 Message-id: <20010811055240.27212.qmail@sourceware.cygnus.com> X-SW-Source: 2001-08/msg00193.html List-Id: >Number: 3993 >Category: c++ >Synopsis: dynamic_cast<>() fails in simple test case w/ dynamic loading >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: sw-bug >Submitter-Id: net >Arrival-Date: Fri Aug 10 22:56:00 PDT 2001 >Closed-Date: >Last-Modified: >Originator: Howard Abrams >Release: gcc version 3.0 >Organization: >Environment: Linux blah.voidstar.org 2.4.2-2 #1 Sun Apr 8 20:41:30 EDT 2001 i686 unknown on i686-pc-linux-gnu >Description: When using "dlopen" to load a library, gcc seems to NOT merge type_info symbols from the library. The result is dynamic casts fail, as well as type_info::operator== for object that they should not fail on. Below is simple source to reproduce this problem. Also note that on version 2.96 (Red Hat Linux 7.1 2.96-81) (I know, you don't support that... ) this works fine. >How-To-Repeat: To reproduce this there are three small files. Compile with the following two lines: g++ -g -o test2.so -shared test2.cpp g++ -g -o testcase test.cpp -ldl The files are as follows: classb.h ======== struct a { virtual ~a() {} }; struct b : public a { virtual ~b() {} }; test2.cpp ========= #include #include "classb.h" extern "C" { a *getnewb() { return new b; } const std::type_info &gettypeb() { return typeid( b ); } } test.cpp ======== #include #include #include #include "classb.h" int main() { a *(*func)(void); const std::type_info &(*type)(void); void *handle = dlopen( "test2.so", RTLD_NOW ); func = (a *(*)(void))dlsym( handle, "getnewb" ); type = (const std::type_info &(*)(void))dlsym( handle, "gettypeb" ); a *a_ptr = (*func)(); const std::type_info &t = (*type)(); assert ( dynamic_cast( a_ptr ) ); assert ( typeid( b ) == t ); } >Fix: >Release-Note: >Audit-Trail: >Unformatted: