[Boost-bugs] [Boost C++ Libraries] #12017: Segfault with Boost program_options 1.60 debug libraries on OSX

Subject: [Boost-bugs] [Boost C++ Libraries] #12017: Segfault with Boost program_options 1.60 debug libraries on OSX
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-02-24 17:24:26


#12017: Segfault with Boost program_options 1.60 debug libraries on OSX
-----------------------+------------------------------
 Reporter: anonymous | Type: Bugs
   Status: new | Milestone: To Be Determined
Component: None | Version: Boost 1.60.0
 Severity: Problem | Keywords:
-----------------------+------------------------------
 Hi,

 I'm using Boost 1.60.0_1 (installed from Brew) and am trying to compile
 the following file:


 {{{
 //mytest.cpp:
 #include <boost/program_options.hpp>
 #include <string>

 namespace po = boost::program_options;

 int main(int argc, char *argv[])
 {
     po::variables_map vm;
     po::options_description desc;

     desc.add_options()
     ("test,t", po::value<std::string>()->default_value("something"))
     ;

     po::store(po::parse_command_line(argc, argv, desc), vm);
     po::notify(vm);
     return 0;
 }
 }}}

 I'm using CMake to compile. When compiling in Release mode, everything
 works fine. But when compiling in Debug mode, i get a segfault in the
 store() function when I run the program without the -t option:

 {{{
 (lldb) bt
 * thread #1: tid = 0x5f2ad5, 0x000000010001b9c3
 mytest`boost::program_options::value_semantic_codecvt_helper<char>::parse(boost::any&,
 std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>,
 std::__1::allocator<char> >,
 std::__1::allocator<std::__1::basic_string<char,
 std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, bool)
 const [inlined] std::__1::vector<std::__1::basic_string<char,
 std::__1::char_traits<char>, std::__1::allocator<char> >,
 std::__1::allocator<std::__1::basic_string<char,
 std::__1::char_traits<char>, std::__1::allocator<char> > >
>::size(this=0xffffffffffffffd5 size=0) const at vector:653, queue =
 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1,
 address=0xffffffffffffffd5)
   * frame #0: 0x000000010001b9c3
 mytest`boost::program_options::value_semantic_codecvt_helper<char>::parse(boost::any&,
 std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>,
 std::__1::allocator<char> >,
 std::__1::allocator<std::__1::basic_string<char,
 std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, bool)
 const [inlined] std::__1::vector<std::__1::basic_string<char,
 std::__1::char_traits<char>, std::__1::allocator<char> >,
 std::__1::allocator<std::__1::basic_string<char,
 std::__1::char_traits<char>, std::__1::allocator<char> > >
>::size(this=0xffffffffffffffd5 size=0) const at vector:653
     frame #1: 0x000000010001b9c3
 mytest`boost::program_options::value_semantic_codecvt_helper<char>::parse(this=0x0000000100103740,
 value_store=0x00007fff5fbff408, new_tokens=size=0, utf8=<unavailable>)
 const + 51 at value_semantic.cpp:45
     frame #2: 0x000000010001934d
 mytest`boost::program_options::store(options=0x00007fff5fbff5c8,
 xm=0x00007fff5fbff6c8, utf8=<unavailable>) + 1207 at variables_map.cpp:125
     frame #3: 0x0000000100000cad mytest`main + 445
     frame #4: 0x00007fff92a5e5ad libdyld.dylib`start + 1
 }}}

 I noticed this happens only if the binary is linked with the static debug
 libraries, i.e libboost_program_options-d.a and libboost_program_options-
 mt-d.a. To reproduce without CMake:

 {{{
 $ c++ mytest.cpp -I/usr/local/include
 /usr/local/lib/libboost_program_options-d.a -o mytest && ./mytest
 [1] 83707 segmentation fault ./mytest

 $ c++ mytest.cpp -DDEBUG -I/usr/local/include
 /usr/local/lib/libboost_program_options-d.a -o mytest && ./mytest
 [1] 83709 segmentation fault ./mytest
 }}}

 It crashes only when run without the -t argument; If I provide it, it
 works fine:
 {{{
 $ ./mytest -t test
 }}}

 It does not crash when linked statically with a non-debug library:
 {{{
 $ c++ mytest.cpp -DDEBUG -I/usr/local/include
 /usr/local/lib/libboost_program_options.a -o mytest && ./mytest
 $ c++ mytest.cpp -DDEBUG -I/usr/local/include /usr/local/lib
 /libboost_program_options-mt.a -o mytest && ./mytest
 }}}

 Or when linked dynamically with one of the shared libraries:
 {{{
 $ c++ mytest.cpp -I/usr/local/include
 /usr/local/opt/boost/lib/libboost_program_options.dylib -o mytest &&
 ./mytest
 $ c++ mytest.cpp -I/usr/local/include /usr/local/opt/boost/lib
 /libboost_program_options-mt.dylib -o mytest && ./mytest
 }}}

 The only workaround I found in order to compile a working debug binary
 with CMake is to use -DBoost_USE_STATIC_RUNTIME=ON because for some reason
 it tells the compiler to link with the shared library).

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/12017>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:19 UTC