From d2079574c7fe1d47b4b33434a33bb6510a97202a Mon Sep 17 00:00:00 2001 From: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com> Date: Thu, 19 Mar 2026 11:18:14 +0000 Subject: [PATCH] fix: Build Boost.Context with ucontext backend for TSAN builds TSAN cannot instrument fcontext (assembly) context switches, causing undefined symbol errors for fiber_activation_record::current(). Add Conan build options and CMake defines to use the ucontext backend for TSAN, matching the existing ASAN configuration. Co-Authored-By: Claude Opus 4.6 --- cmake/deps/Boost.cmake | 11 +++++++++++ conan/profiles/sanitizers | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/cmake/deps/Boost.cmake b/cmake/deps/Boost.cmake index 7594ddc806..3b4e165dcf 100644 --- a/cmake/deps/Boost.cmake +++ b/cmake/deps/Boost.cmake @@ -61,3 +61,14 @@ if(enable_asan) INTERFACE BOOST_USE_ASAN BOOST_USE_UCONTEXT ) endif() + +# TSAN also requires the ucontext backend so that Boost.Context uses +# POSIX ucontext (not fcontext assembly) for fiber switching. This +# allows TSAN to properly track context switches and avoids false positives. +# These defines must match what Boost was compiled with (see conan/profiles/sanitizers). +if(enable_tsan) + target_compile_definitions( + xrpl_boost + INTERFACE BOOST_USE_TSAN BOOST_USE_UCONTEXT + ) +endif() diff --git a/conan/profiles/sanitizers b/conan/profiles/sanitizers index 6d37425f43..6af5565bcb 100644 --- a/conan/profiles/sanitizers +++ b/conan/profiles/sanitizers @@ -82,5 +82,12 @@ tools.info.package_id:confs+=["tools.build:cxxflags", "tools.build:exelinkflags" boost/*:without_context=False # Boost stacktrace fails to build with some sanitizers boost/*:without_stacktrace=True + {% elif "thread" in sanitizers %} + # Build Boost.Context with ucontext backend (not fcontext) so that + # TSAN can instrument fiber/context switches. fcontext uses raw assembly + # which TSAN cannot intercept, causing false positives and link errors. + boost/*:extra_b2_flags=context-impl=ucontext thread-sanitizer=on define=BOOST_USE_TSAN=1 + boost/*:without_context=False + boost/*:without_stacktrace=True {% endif %} {% endif %}