This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/3993: dynamic_cast<>() fails in simple test case w/ dynamic loading
- To: gcc-gnats at gcc dot gnu dot org
- Subject: c++/3993: dynamic_cast<>() fails in simple test case w/ dynamic loading
- From: abramsh at acm dot org
- Date: 11 Aug 2001 05:52:40 -0000
- Reply-To: abramsh at acm dot org
>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 <typeinfo>
#include "classb.h"
extern "C" {
a *getnewb() { return new b; }
const std::type_info &gettypeb() { return typeid( b ); }
}
test.cpp
========
#include <dlfcn.h>
#include <typeinfo>
#include <cassert>
#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<b*>( a_ptr ) );
assert ( typeid( b ) == t );
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: