- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Linux 2.6.18-238.1.1.el5 #1 SMP Tue Jan 4 13:32:19 EST 2011 x86_64 x86_64 x86_64 GNU/Linux
Intel C++ Intel 64 Compiler XE for applications running on Intel 64, Version 12.0.0.084 Build 20101006
We have got exception "terminate called after throwing an instance of 'std::bad_typeid'" in the following situation.
This test has been created by Sela Lerer, I have added SHOW_PTR and SHOW_TYPEID.
Any suggestions?
Thanks
>>>>>> 1. SOURCE FILES <<<<<<
------ File libdef.cpp ------
class Base
{
public:
Base(){}
virtual void func(){}
};
class Derived : public Base
{
public: Derived(){}
};
extern "C" Base* CreateDerived()
{
Base* pBase = new Derived();
return pBase;
}
-----------------------------
------ File libdyn.cpp ------
#include
#include
#define SHOW_PTR(p) std::cerr << __FILE__ << ": " << #p << " = " << std::hex << std::showbase << p << std::dec << std::endl
#define SHOW_TYPEID(x) std::cerr << __FILE__ << ": " << "typeid(" << #x << ") = " << typeid(x).name() << std::endl
class Base
{
public:
Base(){}
virtual void func(){}
};
class Derived : public Base
{
public: Derived(){}
};
extern "C" void TryDynCast(Base* pBase)
{
Derived* pDerived = dynamic_cast
SHOW_PTR(pBase);
SHOW_TYPEID(Base);
SHOW_TYPEID(Base*);
SHOW_TYPEID(pBase);
SHOW_TYPEID(*pBase);
SHOW_TYPEID(Derived);
SHOW_TYPEID(Derived*);
SHOW_TYPEID(pDerived);
SHOW_TYPEID(*pDerived);
if (0 != pDerived)
{
std::cout << "CAST SUCCEEDED" << std::endl;
} // if
else
{
std::cout << "CAST FAILED" << std::endl;
} // else
} // ()
-----------------------------
----- File main.cpp ----
#include
class Base;
class Derived;
typedef Base* (*CreateFunc)();
typedef void (*TryCastFunc)(Base*);
int main()
{
void* pDefLib = dlopen("libdef.so", RTLD_NOW | RTLD_LOCAL);
void* pDynLib = dlopen("libdyn.so", RTLD_NOW | RTLD_LOCAL);
CreateFunc pCreate = (CreateFunc) dlsym(pDefLib, "CreateDerived");
TryCastFunc pCast = (TryCastFunc) dlsym(pDynLib, "TryDynCast");
if (0 == pCreate || 0 == pCast)
{
return 3;
}
pCast(pCreate());
}
------------------------
>>>>>> 2. MAKEFILE <<<<<<
------------------------
test: libdef.so libdyn.so main.cpp
icpc -o test main.cpp
libdef.so: libdef.cpp
icpc -o libdef.so libdef.cpp -shared -fPIC
libdyn.so: libdyn.cpp libdef.so
icpc -o libdyn.so libdyn.cpp -shared -fPIC -L. -ldef
------------------------
>>>>>> 3. COMPILATION <<<<<<
------------------------
> setenv LD_LIBRARY_PATH .
> make
icpc -o libdef.so libdef.cpp -shared -fPIC
icpc -o libdyn.so libdyn.cpp -shared -fPIC -L. -ldef
icpc -o test main.cpp
------------------------
>>>>>> 4. RUNNING <<<<<<
--------- Running ---------
> ./test
libdyn.cpp: pBase = 0x1dd7e40
libdyn.cpp: typeid(Base) = 4Base
libdyn.cpp: typeid(Base*) = P4Base
libdyn.cpp: typeid(pBase) = P4Base
libdyn.cpp: typeid(*pBase) = 7Derived // *pBase is OK
libdyn.cpp: typeid(Derived) = 7Derived
libdyn.cpp: typeid(Derived*) = P7Derived
libdyn.cpp: typeid(pDerived) = P7Derived
libdyn.cpp: typeid(*pDerived) = terminate called after throwing an instance of 'std::bad_typeid'
what(): St10bad_typeid
Abort
--------------------------
>>>>>> 4. CALLSTACK <<<<<<
> gdb ./test core
GNU gdb (GDB) Red Hat Enterprise Linux (7.0.1-32.el5_6.2)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <>>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<>>...
Reading symbols from /devjuser/jp/ccjp/avinokur/tmp_dlopen/sela_test/test...(no debugging symbols found)...done.
Reading symbols from /lib64/libm.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib64/libm.so.6
Reading symbols from /usr/lib64/libstdc++.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib64/libstdc++.so.6
Reading symbols from /lib64/libgcc_s.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/libgcc_s.so.1
Reading symbols from /lib64/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib64/libc.so.6
Reading symbols from /lib64/libdl.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/libdl.so.2
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Reading symbols from ./libdef.so...(no debugging symbols found)...done.
Loaded symbols for ./libdef.so
Reading symbols from /opt/intel/compiler/lib/intel64/libimf.so...(no debugging symbols found)...done.
Loaded symbols for /opt/intel/compiler/lib/intel64/libimf.so
Reading symbols from /opt/intel/compiler/lib/intel64/libsvml.so...(no debugging symbols found)...done.
Loaded symbols for /opt/intel/compiler/lib/intel64/libsvml.so
Reading symbols from /opt/intel/compiler/lib/intel64/libintlc.so.5...(no debugging symbols found)...done.
Loaded symbols for /opt/intel/compiler/lib/intel64/libintlc.so.5
Reading symbols from ./libdyn.so...(no debugging symbols found)...done.
Loaded symbols for ./libdyn.so
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7fffc53fc000
Core was generated by `./test'.
Program terminated with signal 6, Aborted.
#0 0x00000031b3430265 in raise () from /lib64/libc.so.6
(gdb) where
#0 0x00000031b3430265 in raise () from /lib64/libc.so.6
#1 0x00000031b3431d10 in abort () from /lib64/libc.so.6
#2 0x00000031c42bed14 in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib64/libstdc++.so.6
#3 0x00000031c42bce16 in ?? () from /usr/lib64/libstdc++.so.6
#4 0x00000031c42bce43 in std::terminate() () from /usr/lib64/libstdc++.so.6
#5 0x00000031c42bcf2a in __cxa_throw () from /usr/lib64/libstdc++.so.6
#6 0x00000031c42bc152 in __cxa_bad_typeid () from /usr/lib64/libstdc++.so.6
#7 0x00002b637c91c6f4 in TryDynCast () from ./libdyn.so
#8 0x0000000000400aa2 in main ()
(gdb)
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If RTLD_GLOBAL is used instead of RTLD_LOCAL (in main.cpp) then no exception occurs.
Alex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
$ cat Makefile
test: libdef.so libdyn.so main.cpp
icpc -c main.cpp
icpc -o test main.o -L. -ldyn
libdef.so: libdef.cpp
icpc -o libdef.so libdef.cpp -shared -fPIC
libdyn.so: libdyn.cpp libdef.so
icpc -o libdyn.so libdyn.cpp -shared -fPIC -L. -ldef
clean:
rm test main.o libdef.so libdyn.so
$ ./test
libdyn.cpp: pBase = 0x2581180
libdyn.cpp: typeid(Base) = 4Base
libdyn.cpp: typeid(Base*) = P4Base
libdyn.cpp: typeid(pBase) = P4Base
libdyn.cpp: typeid(*pBase) = 7Derived
libdyn.cpp: typeid(Derived) = 7Derived
libdyn.cpp: typeid(Derived*) = P7Derived
libdyn.cpp: typeid(pDerived) = P7Derived
libdyn.cpp: typeid(*pDerived) = 7Derived
CAST SUCCEEDED
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Om, thank you very much.
Alex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Only icpc-linker requires L. -ldyn while linkage of executable files.
Other linkers produce valid typeid() without L. -ldyn while using RTLD_LOCAL.
Is there any option in icpc to guarantee such behavior (without L. -ldyn)?
Thanks,
Alex V.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm having an issue similar to this with the newer "icpc" compiler. uname -a Linux linux-xsic.site 3.4.33-2.24-desktop #1 SMP PREEMPT Tue Feb 26 03:34:33 UTC 2013 (5f00a32) x86_64 x86_64 x86_64 GNU/Linux icpc -V Intel(R) C++ Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 13.1.0.146 Build 20130121 Copyright (C) 1985-2013 Intel Corporation. All rights reserved. #include using namespace std; int main() { try { throw 1; } catch(...) { cout << "Error" << endl; } } icpc throwtest.c -o throwtest ./throwtest terminate called after throwing an instance of 'int' Abort (core dumped) g++ -v gcc version 4.7.1 20120723 [gcc-4_7-branch revision 189773] (SUSE Linux) g++ throwtest.c -o throwtest ./throwtest Error Looks like g++ works but the intel C++ compiler does not, any ideas?

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page