test_multi_shared_lib.cpp 1.4 KB

123456789101112131415161718192021222324252627282930
  1. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  2. // test_multi_shared_lib.cpp: test that implementation of extented_type_info
  3. // works when using multiple shared libraries
  4. //
  5. // This reproduces a crash that occurred when multiple shared libraries were
  6. // using Boost.Serialization built statically. That causes core singletons to be
  7. // instantiated in each shared library separately. Due to some destruction order
  8. // mixup in the context of shared libraries on linux it is possible, that
  9. // singletons accessed in destructors of other singletons are already destructed.
  10. // Accessing them will then lead to a crash or memory corruption.
  11. // For this we need 2 shared libraries, linked against static boost. They need to
  12. // instantiate extended_type_info_typeid with different types, either by serializing
  13. // 2 types (which will do that internally) or by accessing the singletons directly.
  14. // (C) Copyright 2018 Alexander Grund
  15. // Use, modification and distribution is subject to the Boost Software
  16. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  17. // http://www.boost.org/LICENSE_1_0.txt)
  18. #include <boost/serialization/config.hpp>
  19. // Both shall instantiate different(!) singletons and return true
  20. BOOST_SYMBOL_IMPORT bool f();
  21. BOOST_SYMBOL_IMPORT bool g();
  22. int main(int argc, char**){
  23. if(f() && g())
  24. return 0;
  25. return 1;
  26. }