boostboost-log

Boost log crashes with a simple example (Linux)


Ok, I know, this question sounds similar to other questions (none of them had been answered), but I cannot figure out why is failing. The simplest example possible is this:

#include <boost/log/trivial.hpp>

int main() {
  BOOST_LOG_TRIVIAL(info) << "hello world\n";
}

Of course, to compile this we need boost as a dependency, for this I decided to use Conan and this is the conanfile.txt:

[requires]
boost/1.75.0

[generators]
cmake_find_package

And, well, a simple CMake to build it all:

cmake_minimum_required(VERSION 3.15)
project(concurrency)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
find_package(Boost REQUIRED COMPONENTS log)

add_executable(concurrency main.cpp)
target_link_libraries(concurrency Boost::log)

This builds without problems in Windows, macOS and Linux (tested in Fedora 33 and Ubuntu rolling). If I run the simple log in Windows and macOS, it works without any problems at all, but in Linux it fails with segmentation fault (run in Fedora 33):

Reading symbols from concurrency...
(No debugging symbols found in concurrency)
(gdb) run
Starting program: /tmp/build/concurrency
warning: Error disabling address space randomization: Operation not permitted
Missing separate debuginfos, use: dnf debuginfo-install glibc-2.32-4.fc33.x86_64
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x00007f1aa97896a2 in __memmove_avx_unaligned_erms () from /lib64/libc.so.6
Missing separate debuginfos, use: dnf debuginfo-install libgcc-10.2.1-9.fc33.x86_64 libstdc++-10.2.1-9.fc33.x86_64
(gdb) where
#0  0x00007f1aa97896a2 in __memmove_avx_unaligned_erms () from /lib64/libc.so.6
#1  0x00007f1aa9a92ce0 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long) () from /lib64/libstdc++.so.6
#2  0x000000000040ee81 in boost::log::v2s_mt_posix::aux::basic_ostringstreambuf<char, std::char_traits<char>, std::allocator<char> >::append(char const*, unsigned long) ()
#3  0x000000000040ed15 in boost::log::v2s_mt_posix::basic_formatting_ostream<char, std::char_traits<char>, std::allocator<char> >::formatted_write(char const*, long) ()
#4  0x000000000040eaee in boost::log::v2s_mt_posix::basic_formatting_ostream<char, std::char_traits<char>, std::allocator<char> >::operator<<(char const*) ()
#5  0x000000000040e853 in boost::log::v2s_mt_posix::basic_record_ostream<char>::operator<<(char const*) ()
#6  0x000000000040e455 in main ()

Any idea what could be happening? I already tried including Boost::log_setup but same segfault is there.


Solution

  • @AndreySemashev suggestion helped me to find the issue. Apparently it is related to GCC ABI compatibility and versioning of the standard library.

    Conan documentation covers the issue pretty well (and how to solve it). So for my previous example the only thing I have to do is setting the standard lib in Linux at install time:

    conan install .. -s compiler.libcxx=libstdc++
    

    Apparently, Conan assumes the old standard library for GCC 5 (the default version set for Boost).

    I hope this helps someone else in the future.