Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime double free occurs when using system-installed boost_filesystem without specifying shared libraries #6399

Open
Doekin opened this issue Feb 20, 2025 · 4 comments
Labels

Comments

@Doekin
Copy link
Contributor

Doekin commented Feb 20, 2025

Xmake Version

xmake v2.9.8+20250204

Operating System Version and Architecture

Arch Linux

Describe Bug

This issue occurs when using the system-installed boost libraries. If boost is built from source via XMake, this issue does not occur because XMake automatically defines BOOST_ALL_DYN_LINK when building shared libraries. However, with system-installed shared boost libraries, if BOOST_FILESYSTEM_DYN_LINK=1 (or BOOST_ALL_DYN_LINK) is not defined, it results in a runtime error: free(): double free detected in tcache 2.

When using system-installed boost_filesystem via:

add_requires("boost", {configs = {filesystem = true}})

a runtime double free error occurs. The error message is:

free(): double free detected in tcache 2

However, if we specify boost as a shared library with:

add_requires("boost", {configs = {shared = true, filesystem = true}})

the issue disappears.

Expected Behavior

If system-installed shared boost libraries are being used, XMake should automatically define BOOST_FILESYSTEM_DYN_LINK=1 (or BOOST_ALL_DYN_LINK).

Project Configuration

xrepo install boostdep

Additional Information and Error Logs

free(): double free detected in tcache 2
@Doekin Doekin added the bug label Feb 20, 2025
@waruqi
Copy link
Member

waruqi commented Feb 20, 2025

This seems to be a boost issue. Alternatively, you can define BOOST_FILESYSTEM_DYN_LINK yourself via add_cxflags

@Doekin
Copy link
Contributor Author

Doekin commented Feb 20, 2025

Thank you for the suggestion! However, when using xrepo to install packages like xrepo install boostdep, this isn't feasible.

@Doekin
Copy link
Contributor Author

Doekin commented Feb 20, 2025

Apologies, I misidentified the cause of this issue. The problem is not related to the absence of the BOOST_FILESYSTEM_DYN_LINK=1 macro.

The issue occurs when we use system-installed boost like this:

add_requires("boost", {configs = {filesystem = true}})

However, if we explicitly specify shared boost, the issue disappears:

add_requires("boost", {configs = {shared = true, filesystem = true}})

The difference seems to be that additional libraries are linked when using the static version. For example, here are the compile commands for both cases:

With add_requires("boost", {configs = {filesystem = true}}):

/usr/bin/gcc -c -m64 -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wextra -Wpedantic -O3 -DNDEBUG -o build/.objs/boost_fs/linux/x86_64/release/src/boost_fs.cpp.o src/boost_fs.cpp
/usr/bin/g++ -o build/linux/x86_64/release/boost_fs build/.objs/boost_fs/linux/x86_64/release/src/boost_fs.cpp.o -m64 -L/usr/lib -s -lpython3 -lboost_wave -lboost_url -lboost_type_erasure -lboost_timer -lboost_prg_exec_monitor -lboost_unit_test_framework -lboost_test_exec_monitor -lboost_stacktrace_noop -lboost_stacktrace_addr2line -lboost_stacktrace_basic -lboost_program_options -lboost_process -lboost_nowide -lboost_log -lboost_log_setup -lboost_locale -lboost_json -lboost_iostreams -lboost_graph_parallel -lboost_mpi -lboost_python313 -lboost_numpy313 -lboost_graph -lboost_wserialization -lboost_serialization -lboost_regex -lboost_random -lboost_fiber -lboost_filesystem -lboost_coroutine -lboost_contract -lboost_thread -lboost_date_time -lboost_exception -lboost_cobalt -lboost_context -lboost_container -lboost_chrono -lboost_system -lboost_charconv -lboost_atomic

With add_requires("boost", {configs = {shared = true, filesystem = true}}):

/usr/bin/gcc -c -m64 -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wextra -Wpedantic -O3 -DNDEBUG -o build/.objs/boost_fs/linux/x86_64/release/src/boost_fs.cpp.o src/boost_fs.cpp
/usr/bin/g++ -o build/linux/x86_64/release/boost_fs build/.objs/boost_fs/linux/x86_64/release/src/boost_fs.cpp.o -m64 -L/usr/lib -s -lpython3 -lboost_wave -lboost_url -lboost_type_erasure -lboost_timer -lboost_prg_exec_monitor -lboost_unit_test_framework -lboost_stacktrace_noop -lboost_stacktrace_addr2line -lboost_stacktrace_basic -lboost_program_options -lboost_process -lboost_nowide -lboost_log -lboost_log_setup -lboost_locale -lboost_json -lboost_iostreams -lboost_graph_parallel -lboost_mpi -lboost_python313 -lboost_numpy313 -lboost_graph -lboost_wserialization -lboost_serialization -lboost_regex -lboost_random -lboost_fiber -lboost_filesystem -lboost_coroutine -lboost_contract -lboost_thread -lboost_date_time -lboost_cobalt -lboost_context -lboost_container -lboost_chrono -lboost_system -lboost_charconv -lboost_atomic

It seems that in the static version, additional libraries like boost_test_exec_monitor and boost_exception are linked.

@Doekin Doekin changed the title Using boost_filesystem shared lib without BOOST_FILESYSTEM_DYN_LINK=1 defined results in runtime double free Runtime double free occurs when using system-installed boost_filesystem without specifying shared libraries Feb 20, 2025
@Doekin
Copy link
Contributor Author

Doekin commented Feb 21, 2025

I’ve discovered some additional information regarding this issue:

Arch Linux provides both static and shared libraries for most boost modules. However, there are exceptions: libboost_test_exec_monitor and libboost_exception are only available as static libraries.

Given that shared libraries generally take priority during linking, it’s possible that the issue arises from mixing these static libraries (boost_test_exec_monitor and boost_exception) with other shared boost libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants