From: Sun Yuechi Date: Sat, 20 Jun 2026 07:17:26 +0000 (+0800) Subject: cmake: define BOOST_USE_UCONTEXT tree-wide under ASan X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5166ec6f064fcc9a3299022ccebfdf69c8f6ec93;p=ceph.git cmake: define BOOST_USE_UCONTEXT tree-wide under ASan Under WITH_ASAN Boost.Context is built ucontext-only, so consumers that include its headers without linking Boost::context (e.g. libosd) were still built for the fcontext backend and broke the link: mold: error: undefined symbol: boost::context::detail::make_fcontext Define the backend tree-wide so every consumer agrees on it. riscv64's ASan runtime mis-handles makecontext/swapcontext, so the ucontext fiber backend reports false-positive heap-buffer-overflows on fiber switch that can't be suppressed. So exclude it. Signed-off-by: Sun Yuechi --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 46a0efc680d..99e389ff3e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -817,6 +817,17 @@ else() include(BuildBoost) build_boost(1.87 COMPONENTS ${BOOST_COMPONENTS} ${BOOST_HEADER_COMPONENTS}) + if(WITH_ASAN) + # Boost.Context is built ucontext-only here (context-impl=ucontext); define + # the matching backend tree-wide so every Boost.Context/Coroutine2 consumer + # agrees on it, instead of relying on per-target propagation that is easy to miss. + # Except riscv64: its ASan mis-handles ucontext, so it keeps fcontext. + if(CMAKE_SYSTEM_PROCESSOR MATCHES "riscv") + add_compile_definitions(BOOST_USE_ASAN) + else() + add_compile_definitions(BOOST_USE_ASAN BOOST_USE_UCONTEXT) + endif() + endif() endif() include_directories(BEFORE SYSTEM ${Boost_INCLUDE_DIRS}) add_library(Boost::asio INTERFACE IMPORTED) diff --git a/cmake/modules/BuildBoost.cmake b/cmake/modules/BuildBoost.cmake index d47e1eeb471..6f409dcdce1 100644 --- a/cmake/modules/BuildBoost.cmake +++ b/cmake/modules/BuildBoost.cmake @@ -146,7 +146,8 @@ function(do_build_boost root_dir version) endif() set(b2_targets headers stage) set(b2_install_targets install) - if(WITH_ASAN) + # Except riscv64: its ASan mis-handles ucontext, so it keeps fcontext. + if(WITH_ASAN AND NOT (CMAKE_SYSTEM_PROCESSOR MATCHES "riscv")) list(APPEND b2 context-impl=ucontext) # `context-impl` is declared in libs/context/build/Jamfile.v2; the headers/stage # and install targets never load it, so b2 aborts with `unknown feature @@ -262,10 +263,8 @@ macro(build_boost version) set_target_properties(Boost::${c} PROPERTIES INTERFACE_COMPILE_DEFINITIONS "BOOST_USE_VALGRIND") endif() - if((c MATCHES "context") AND (WITH_ASAN)) - set_target_properties(Boost::${c} PROPERTIES - INTERFACE_COMPILE_DEFINITIONS "BOOST_USE_ASAN;BOOST_USE_UCONTEXT") - endif() + # ASan's BOOST_USE_ASAN/BOOST_USE_UCONTEXT are defined tree-wide in the + # top-level CMakeLists.txt, not per-target. list(APPEND Boost_LIBRARIES ${Boost_${upper_c}_LIBRARY}) endforeach() foreach(c ${Boost_BUILD_COMPONENTS})