[pkg-boost-devel] Bug#537680: boost: linking 2 files compiled with different NDEBUG causes segfault
Török Edwin
edwintorok at gmail.com
Mon Jul 20 07:27:51 UTC 2009
Package: libboost-date-time-dev
Version: 1.38.1
Severity: normal
Linking x1.o and x2.o compiled as below causes the resulting executable to
segfault and show valgrind errors.
x1.o defines NDEBUG before including a boost header, x2.o doesn't.
If both define NDEBUG, or both don't then linking them produces an executable
that runs, and shows no valgrind errors.
This is y1.cpp:
#define NDEBUG 1
#include <boost/date_time/posix_time/posix_time.hpp>
#include <iostream>
void foobar() {
boost::posix_time::time_duration td(0, 0, 1, 0);
std::stringstream ss;
ss << td;
}
void bar(void);
int main()
{
bar();
return 0;
}
This is y2.cpp:
#include <boost/date_time/posix_time/posix_time.hpp>
void bar(void) {
std::cerr<<boost::posix_time::second_clock::local_time()<<' ';
}
Fails:
$ g++ y1.cpp y2.cpp && ./a.out
Segmentation fault
$ valgrind ./a.out
==19873== Use of uninitialised value of size 8
==19873== at 0x30052A45BB: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&) (in /usr/lib/libstdc++.so.6.0.12)
==19873== by 0x4070B0: boost::iterator_range<boost::range_iterator<std::string const>::type> boost::as_literal<std::string>(std::string const&) (in /home/edwin/lux/n/objllvmgcc/a.out)
==19873== by 0x413D02: boost::algorithm::detail::first_finderF<boost::range_const_iterator<std::string>::type, boost::algorithm::is_equal> boost::algorithm::first_finder<std::string>(std::string const&) (in /home/edwin/lux/n/objllvmgcc/a.out)
==19873== by 0x414245: void boost::algorithm::erase_all<std::string, std::string>(std::string&, std::string const&) (in /home/edwin/lux/n/objllvmgcc/a.out)
==19873== by 0x415172: boost::date_time::time_facet<boost::posix_time::ptime, char, std::ostreambuf_iterator<char, std::char_traits<char> > >::put(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, boost::posix_time::ptime const&) const (in /home/edwin/lux/n/objllvmgcc/a.out)
==19873== by 0x415C6F: std::basic_ostream<char, std::char_traits<char> >& boost::posix_time::operator<< <char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, boost::posix_time::ptime const&) (in /home/edwin/lux/n/objllvmgcc/a.out)
==19873== by 0x40E3DE: bar() (in /home/edwin/lux/n/objllvmgcc/a.out)
==19873== by 0x4030D0: main (in /home/edwin/lux/n/objllvmgcc/a.out)
........
==19873== Process terminating with default action of signal 11 (SIGSEGV)
==19873== Bad permissions for mapped region at address 0x30052124A0
==19873== at 0x30052A4611: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&) (in /usr/lib/libstdc++.so.6.0.12)
==19873== by 0x4070B0: boost::iterator_range<boost::range_iterator<std::string const>::type> boost::as_literal<std::string>(std::string const&) (in /home/edwin/lux/n/objllvmgcc/a.out)
==19873== by 0x413D02: boost::algorithm::detail::first_finderF<boost::range_const_iterator<std::string>::type, boost::algorithm::is_equal> boost::algorithm::first_finder<std::string>(std::string const&) (in /home/edwin/lux/n/objllvmgcc/a.out)
==19873== by 0x414245: void boost::algorithm::erase_all<std::string, std::string>(std::string&, std::string const&) (in /home/edwin/lux/n/objllvmgcc/a.out)
==19873== by 0x415172: boost::date_time::time_facet<boost::posix_time::ptime, char, std::ostreambuf_iterator<char, std::char_traits<char> > >::put(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, boost::posix_time::ptime const&) const (in /home/edwin/lux/n/objllvmgcc/a.out)
==19873== by 0x415C6F: std::basic_ostream<char, std::char_traits<char> >& boost::posix_time::operator<< <char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, boost::posix_time::ptime const&) (in /home/edwin/lux/n/objllvmgcc/a.out)
==19873== by 0x40E3DE: bar() (in /home/edwin/lux/n/objllvmgcc/a.out)
==19873== by 0x4030D0: main (in /home/edwin/lux/n/objllvmgcc/a.out)
Works:
Edit y2.cpp, add #define NDEBUG 1
$ g++ y1.cpp y2.cpp && ./a.out
2009-Jul-20 10:27:33
-- System Information:
Debian Release: squeeze/sid
APT prefers unstable
APT policy: (990, 'unstable'), (500, 'stable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Kernel: Linux 2.6.30.1 (SMP w/4 CPU cores; PREEMPT)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Versions of packages libboost-date-time-dev depends on:
ii libboost-date-time1.38-dev 1.38.0-7 set of date-time libraries based o
libboost-date-time-dev recommends no packages.
libboost-date-time-dev suggests no packages.
-- no debconf information
More information about the pkg-boost-devel
mailing list