]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: define BOOST_USE_UCONTEXT tree-wide under ASan 69622/head
authorSun Yuechi <sunyuechi@iscas.ac.cn>
Sat, 20 Jun 2026 07:17:26 +0000 (15:17 +0800)
committerSun Yuechi <sunyuechi@iscas.ac.cn>
Mon, 22 Jun 2026 05:26:12 +0000 (13:26 +0800)
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 <sunyuechi@iscas.ac.cn>
CMakeLists.txt
cmake/modules/BuildBoost.cmake

index 46a0efc680d15dd8a6c062bdde61bef139846c41..99e389ff3e6c3e32af3936bc20256f76bf7edcd6 100644 (file)
@@ -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)
index d47e1eeb471796b7a48ee576af2628d181936d50..6f409dcdce1404c35497333ba27583016e6c3492 100644 (file)
@@ -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})