0

As stated in the title, I have a seg fault occurring and I have no idea why. The closest maybe-related issue that I could dig up is this. My system specs are as follows:

  • RHELv5u8
  • icpc version 12.1.0 (gcc version 4.1.2 compatibility)
  • arch = x86_64

And the problem doesn't seem to occur when compiling with g++.

I have isolated the problem to a relatively small snippet of code:

#include <iostream>
#include <cstdio>
#include <vector>

#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/vector.hpp>
#include <string>
#include <fstream>

using namespace std;

int main()
{   
  cout << "Testing ... ";

  vector<int> outVect(10);

  //  Save the data
  std::ofstream outputFile_("archive.txt");
  outputFile_ << std::scientific;
  boost::archive::text_oarchive textOutArchive_(outputFile_);
  cout << "chk1" << endl;
  textOutArchive_ & BOOST_SERIALIZATION_NVP(outVect);
  cout << "chk2" << endl;
  return 0;
}   

And I am compiling thusly:

icpc -g -static -openmp standalone.cc -o minimal -lboost_serialization ; ./minimal

Any ideas?

Valgrind gives me the following:

Testing ... chk1
==24519== Jump to the invalid address stated on the next line
==24519==    at 0x0: ??? 
==24519==    by 0x403100: boost::serialization::detail::extended_type_info_typeid_1<std::vector<int, std::allocator<int> > const>::get_instance() (extended_type_info_typeid.hpp:96)
==24519==    by 0x4027C0: boost::archive::detail::oserializer<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::oserializer() (oserializer.hpp:106)
==24519==    by 0x402934: boost::archive::detail::oserializer<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::instantiate() (oserializer.hpp:135)
==24519==    by 0x402764: boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::save_standard::invoke(boost::archive::text_oarchive&, std::vector<int, std::allocator<int> > const&) (oserializer.hpp:264)
==24519==    by 0x4027AA: boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::save_conditional::invoke(boost::archive::text_oarchive&, std::vector<int, std::allocator<int> > const&) (oserializer.hpp:273)
==24519==    by 0x40274A: boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::invoke(boost::archive::text_oarchive&, std::vector<int, std::allocator<int> > const&) (oserializer.hpp:322)
==24519==    by 0x40364E: void boost::archive::save<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >(boost::archive::text_oarchive&, std::vector<int, std::allocator<int> > const&) (oserializer.hpp:536)
==24519==    by 0x401A85: void boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::save_override<std::vector<int, std::allocator<int> > const>(std::vector<int, std::allocator<int> > const&, int) (basic_text_oarchive.hpp:78)
==24519==    by 0x4021D5: boost::archive::text_oarchive& boost::archive::detail::interface_oarchive<boost::archive::text_oarchive>::operator<< <std::vector<int, std::allocator<int> > const>(std::vector<int, std::allocator<int> > const&) (interface_oarchive.hpp:78)
==24519==    by 0x402E49: void boost::serialization::nvp<std::vector<int, std::allocator<int> > >::save<boost::archive::text_oarchive>(boost::archive::text_oarchive&, unsigned int) const (nvp.hpp:77)
==24519==    by 0x402C9E: void boost::serialization::access::member_save<boost::archive::text_oarchive, boost::serialization::nvp<std::vector<int, std::allocator<int> > > const>(boost::archive::text_oarchive&, boost::serialization::nvp<std::vector<int, std::allocator<int> > > const&, unsigned int) (access.hpp:93)
==24519==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==24519==    
==24519==    
==24519== Process terminating with default action of signal 11 (SIGSEGV)
==24519==  Bad permissions for mapped region at address 0x0
==24519==    at 0x0: ???
==24519==    by 0x403100: boost::serialization::detail::extended_type_info_typeid_1<std::vector<int, std::allocator<int> > const>::get_instance() (extended_type_info_typeid.hpp:96)
==24519==    by 0x4027C0: boost::archive::detail::oserializer<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::oserializer() (oserializer.hpp:106)
==24519==    by 0x402934: boost::archive::detail::oserializer<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::instantiate() (oserializer.hpp:135)
==24519==    by 0x402764: boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::save_standard::invoke(boost::archive::text_oarchive&, std::vector<int, std::allocator<int> > const&) (oserializer.hpp:264)
==24519==    by 0x4027AA: boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::save_conditional::invoke(boost::archive::text_oarchive&, std::vector<int, std::allocator<int> > const&) (oserializer.hpp:273)
==24519==    by 0x40274A: boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::invoke(boost::archive::text_oarchive&, std::vector<int, std::allocator<int> > const&) (oserializer.hpp:322)
==24519==    by 0x40364E: void boost::archive::save<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >(boost::archive::text_oarchive&, std::vector<int, std::allocator<int> > const&) (oserializer.hpp:536)
==24519==    by 0x401A85: void boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::save_override<std::vector<int, std::allocator<int> > const>(std::vector<int, std::allocator<int> > const&, int) (basic_text_oarchive.hpp:78)
==24519==    by 0x4021D5: boost::archive::text_oarchive& boost::archive::detail::interface_oarchive<boost::archive::text_oarchive>::operator<< <std::vector<int, std::allocator<int> > const>(std::vector<int, std::allocator<int> > const&) (interface_oarchive.hpp:78)
==24519==    by 0x402E49: void boost::serialization::nvp<std::vector<int, std::allocator<int> > >::save<boost::archive::text_oarchive>(boost::archive::text_oarchive&, unsigned int) const (nvp.hpp:77)
==24519==    by 0x402C9E: void boost::serialization::access::member_save<boost::archive::text_oarchive, boost::serialization::nvp<std::vector<int, std::allocator<int> > > const>(boost::archive::text_oarchive&, boost::serialization::nvp<std::vector<int, std::allocator<int> > > const&, unsigned int) (access.hpp:93)
==24519== 
Ethereal
  • 2,604
  • 1
  • 20
  • 20

1 Answers1

0

Long comment:

Statically linking with pthreads (used by the OpenMP run-time) never works correctly unless the whole libpthreads.a archive is linked in. To work around it you should append -Wl,--whole-archive -lpthreads -Wl,--no-whole-archive to the compilation options.

But then, I see no parallel regions in your code so activating OpenMP is redundant. Besides, it looks more like RTTI is failing with icpc as the error occurs in something, called from inside extended_type_info_typeid.hpp.

Hristo Iliev
  • 72,659
  • 12
  • 135
  • 186
  • Thanks, after reading up on the static linking with openmp issue (referenced [here](http://gcc.gnu.org/onlinedocs/gfortran/OpenMP.html)) it seems clear that your solution is appropriate in this case. For some backstory, I initially used intel's "-fast" compiler directive which asserts various flags geared toward performance. After going through the flags that it asserts and narrowing the offending combination down to it's assertion of "-static" with my use of "-opnemp" I tried to reproduce the problem with gcc but it never fails. What leads you to believe it is an RTTI issue? – Ethereal Sep 13 '12 at 14:31
  • I haven't run into this with my other code as of yet. Perhaps my best option is to unroll the -fast flag to exclude -static, but I was under the impression that there was some tangible benefit to statically linking from a performance perspective. Edit: [static vs dymanic linkage](http://stackoverflow.com/questions/1993390/static-linking-vs-dynamic-linking) – Ethereal Sep 13 '12 at 14:34
  • At the top of the call stack is some `boost` method for dealing with typeid's. Those are part of the C++ RTTI and that's why I suspect that RTTI is the culprint. I don't see how `pthreads` could be involved, but I'm not a heavy user of `boost` after all. – Hristo Iliev Sep 13 '12 at 15:33