Bug:Boost: Use shlibs instead of header-only for call_stack::top_

This symbol is defined as a static member object inside of a
boost detail header. When boost headers are used in a project
that uses Boost in both the main binary as well as dlopen()'d
shlibs, the top_ symbol gets duplicated and the metadata gets
partitioned.

We use the Boost shlib to unify both the main binary and the
shlibs to use the same memory address for top_.

This involves marking the templated object call_stack::top_ as
"extern" and then declaring to Boost that we intend to use the
shlibs.
This commit is contained in:
2025-11-03 22:18:45 -04:00
parent 6ea90c2dae
commit 5845f1a41d
22 changed files with 156 additions and 15 deletions
+22 -5
View File
@@ -4,6 +4,7 @@ project(salmanoff VERSION 0.01.000 LANGUAGES CXX)
include(CMakeDependentOption)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/DAPSS.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/DebugOpts.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/VerifyBoostDynamic.cmake)
# Set C++ standard
set(CMAKE_CXX_STANDARD 20)
@@ -87,10 +88,19 @@ include_directories(
)
# Find core dependencies
# Boost 1.72.0 is required to ensure that a certain bug where boost::asio
# objects depend on specific copies of symbols, and boost will cause a segfault
# if boost::asio objects are used inside of a dlopen()'d library, is fixed.
find_package(Boost 1.73.0 REQUIRED COMPONENTS system)
# We cannot use header-only Boost.Asio because we need both our dlopen()'d
# libraries and the main binary to refer to the same instances of boost::asio's
# metadata. If we use header-only Boost.Asio, each dlopen()'d library will have
# its own copy of boost::asio's metadata, which will cause a segfault if
# boost::asio objects are used inside of a dlopen()'d library.
#
# Honestly, I never liked this whole "header-only" idea so I'm happy to be rid
# of it.
#
# Tell CMake we're linking against the shared library (not header-only)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_HEADER_ONLY OFF)
find_package(Boost REQUIRED COMPONENTS system log)
find_package(PkgConfig REQUIRED)
find_package(FLEX REQUIRED)
find_package(BISON REQUIRED)
@@ -116,11 +126,18 @@ add_subdirectory(devices)
# Main executable
add_executable(salmanoff main.cpp)
target_link_libraries(salmanoff
Boost::system Boost::log
smocore
${Boost_LIBRARIES}
${DL_LIBRARY}
)
# Verify Boost dynamic dependencies after build
add_custom_command(TARGET salmanoff POST_BUILD
COMMAND ${CMAKE_COMMAND} -DVERIFY_FILE="$<TARGET_FILE:salmanoff>"
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/VerifyBoostDynamic.cmake
COMMENT "Verifying Boost dynamic dependencies for salmanoff"
)
# Add all registered DAPSS targets as dependencies
add_all_daps_dependencies()