Opened 7 years ago
Last modified 7 years ago
#11403 new Bugs
exception_ptr.hpp causes crash when .NET tries to unload a DLL that uses boost
Reported by: | Owned by: | Emil Dotchevski | |
---|---|---|---|
Milestone: | To Be Determined | Component: | exception |
Version: | Boost 1.56.0 | Severity: | Problem |
Keywords: | Cc: | emildotchevski@… |
Description
Hello, I posted this on the gmane board and Emil Dotchevski said I should open a ticket for this.
We are working with Visual Studio 2013 and have a plain c++ lib that uses boost. To test it, we wrote a (non clr) console program and a WPF GUI for further use.
This WPF GUI contains a clr dll as a wrapper between the .NET world and the plain c++ libs.
At startup, both console and WPF call some function pointers in _initterm in crt0dat.c, especially these two:
dynamic initializer for 'boost::exception_detail::exception_ptr_static_exception_object<boost::exception_detail::bad_alloc_>::e(void)
dynamic initializer for 'boost::exception_detail::exception_ptr_static_exception_object<boost::exception_detail::bad_exception_>::e(void)
The console terminates cleanly. But the GUI causes an exception in crtdll.c, _CRT_INIT, line 414:
/* call the function, which can eventually change onexitbegin and onexitend */
(*function_to_call)();
The debugger says the value of *function_to_call is
*function_to_call _t2m@???Fep@?1???$get_static_exception_object@Ubad_exception_@exception_detail@boost@@@exception_detail@boost@@YA?AVexception_ptr@1@XZ@YAXXZ@?A0xd1be0c67@@YAXXZ
and causes an unhandled exception at 0x74c7c42d (KernelBase.dll), The String binding is invalid.
However, if I change (remove the static keyword) line 130 in exception_ptr.hpp from
static exception_ptr ep(shared_ptr<exception_detail::clone_base const>(new exception_detail::clone_impl<Exception>(c)));
to
exception_ptr ep(shared_ptr<exception_detail::clone_base const>(new exception_detail::clone_impl<Exception>(c)));
the GUI exits cleanly.
Best regards,
Markus Pieper
Change History (3)
comment:1 by , 7 years ago
comment:2 by , 7 years ago
How can we prevent exception_ptr.hpp from being included in any managed C++ code?
comment:3 by , 7 years ago
I am also facing this issue when one third party library having boost static linkage is used on system having boost as shared library & other modules using shared library boost. What is best possible way to resolve this issue ? /usr/lib/libboost_thread.so.1.51.0(_ZN5boost16exception_detail27get_static_exception_objectINS0_10bad_alloc_EEENS_13exception_ptrEv+0x254) i.e boost::exception_ptr boost::exception_detail::get_static_exception_object<boost::exception_detail::bad_alloc_>() /usr/lib/libboost_thread.so.1.51.0 /lib/ld-linux.so.3 /lib/ld-linux.so.3 /lib/ld-linux.so.3 /lib/ld-linux.so.3 /lib/ld-linux.so.3 /lib/libdl.so.2 /lib/ld-linux.so.3 /lib/libdl.so.2 /lib/libdl.so.2(dlopen+0x3c)
I have seen the same issue. Another workaround is too prevent
exception_ptr.hpp
from being included in any managed C++ code.