Skip to content

link correct lib for asan - #286

Merged
thweetkomputer merged 4 commits into
mainfrom
asan_boost
Dec 12, 2025
Merged

link correct lib for asan#286
thweetkomputer merged 4 commits into
mainfrom
asan_boost

Conversation

@thweetkomputer

@thweetkomputer thweetkomputer commented Dec 12, 2025

Copy link
Copy Markdown
Collaborator

Here are some reminders before you submit the pull request

  • Add tests for the change
  • Document changes
  • Reference the link of issue using fixes eloqdb/tx_service#issue_id
  • Reference the link of RFC if exists
  • Pass ./mtr --suite=mono_main,mono_multi,mono_basic

Summary by CodeRabbit

  • Chores
    • Added support for address sanitizer builds to improve memory-debugging and error detection.
    • Introduced a flexible linkage target for the context library to allow alternative resolutions during build.
    • Conditional build paths now select the appropriate context library for ASAN vs non-ASAN builds.
    • Improved build configurability and cross-environment robustness.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Dec 12, 2025

Copy link
Copy Markdown

Walkthrough

Adds conditional ASAN support to the eloq data store build: introduces compile definitions for ASAN, selects an ASAN-specific Boost.Context library when requested, and abstracts Boost.Context linkage behind a new BOOST_CONTEXT_TARGET variable used by targets.

Changes

Cohort / File(s) Summary
ASAN compile defs
store_handler/eloq_data_store_service/CMakeLists.txt
Add BOOST_USE_ASAN and BOOST_USE_UCONTEXT compile definitions when ASAN is enabled.
Boost.Context linkage abstraction
store_handler/eloq_data_store_service/CMakeLists.txt, store_handler/eloq_data_store_service/build_eloq_store.cmake
Introduce BOOST_CONTEXT_TARGET variable; when WITH_ASAN is set, set ASAN flags and resolve a specific boost_context library path and assign it to BOOST_CONTEXT_TARGET; otherwise use Boost::context. Replace direct Boost::context usage with ${BOOST_CONTEXT_TARGET}.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Pay attention to: correct assignment of BOOST_CONTEXT_TARGET in both code paths.
  • Verify find_library path and portability for the ASAN-specific boost_context.
  • Confirm ASAN compiler/linker flags and the BOOST_USE_* definitions propagate to dependent targets.

Poem

🐰 I hop through CMake, neat and spry,
I tuck in flags where bugs might lie.
BOOST_CONTEXT_TARGET leads the way,
ASAN guards night and day.
Build hops safe — a carrot-coded sigh.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description is incomplete; it contains only the template checklist with no substantive explanation of the changes or the rationale for the modification. Add a detailed description explaining what changed (conditional Boost.Context resolution for ASAN), why it was needed, and any relevant testing/documentation details.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'link correct lib for asan' directly relates to the main change: conditionally linking the correct Boost.Context library based on ASAN configuration.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch asan_boost

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
store_handler/eloq_data_store_service/build_eloq_store.cmake (1)

19-34: Add error handling for missing ASAN Boost library and make path configurable.

Two concerns with this block:

  1. Hardcoded path: The path $ENV{HOME}/boost_ucontext_asan assumes a specific directory structure in the user's home. Consider making this a configurable cache variable with a default.

  2. Missing error check: find_library sets Boost_CONTEXT_LIBRARY to NOTFOUND if the library isn't found, which will cause a confusing link error later rather than a clear configuration error.

 if(WITH_ASAN)
     message("build eloqstore with ASAN: ${WITH_ASAN}")
-    set(BOOST_CONTEXT_ASAN_PATH "$ENV{HOME}/boost_ucontext_asan")
+    set(BOOST_CONTEXT_ASAN_PATH "$ENV{HOME}/boost_ucontext_asan" CACHE PATH "Path to ASAN-compatible Boost.Context installation")
     add_compile_definitions(BOOST_USE_ASAN)
     add_compile_definitions(BOOST_USE_UCONTEXT)

     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
     find_library(Boost_CONTEXT_LIBRARY
             NAMES boost_context
             PATHS ${BOOST_CONTEXT_ASAN_PATH}/lib
             NO_DEFAULT_PATH)
+    if(NOT Boost_CONTEXT_LIBRARY)
+        message(FATAL_ERROR "Failed to find ASAN-compatible boost_context in ${BOOST_CONTEXT_ASAN_PATH}/lib")
+    endif()
     set(BOOST_CONTEXT_TARGET ${Boost_CONTEXT_LIBRARY})
 else ()
store_handler/eloq_data_store_service/CMakeLists.txt (1)

151-152: Duplicate compile definitions.

BOOST_USE_ASAN and BOOST_USE_UCONTEXT are also added in build_eloq_store.cmake (lines 22-23) when WITH_ASAN is enabled. While duplicate definitions don't cause build failures, this redundancy could lead to maintenance confusion if one location is updated but not the other.

Consider removing these from one location to maintain a single source of truth.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bc10f60 and f00cf21.

📒 Files selected for processing (2)
  • store_handler/eloq_data_store_service/CMakeLists.txt (2 hunks)
  • store_handler/eloq_data_store_service/build_eloq_store.cmake (2 hunks)
🔇 Additional comments (2)
store_handler/eloq_data_store_service/build_eloq_store.cmake (1)

120-120: LGTM!

The linkage correctly uses the new ${BOOST_CONTEXT_TARGET} variable, which abstracts the Boost.Context dependency for both ASAN and non-ASAN builds.

store_handler/eloq_data_store_service/CMakeLists.txt (1)

353-356: LGTM!

The conditional block correctly uses ${BOOST_CONTEXT_TARGET} which is defined by the included build_eloq_store.cmake when WITH_DATA_STORE is ELOQDSS_ELOQSTORE. The guard condition ensures the variable is always defined when this code path executes.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f00cf21 and db1fdff.

📒 Files selected for processing (1)
  • store_handler/eloq_data_store_service/build_eloq_store.cmake (2 hunks)
🔇 Additional comments (1)
store_handler/eloq_data_store_service/build_eloq_store.cmake (1)

121-121: BOOST_CONTEXT_TARGET abstraction is a nice simplification—verify it’s always non-empty in both branches.

Linking via ${BOOST_CONTEXT_TARGET} is fine (target in non-ASAN, absolute library path in ASAN). Just ensure configuration fails early when WITH_ASAN=ON and the library isn’t found (otherwise this line becomes a confusing link error later).

Comment on lines +19 to 35
if(WITH_ASAN)
message("build eloqstore with ASAN: ${WITH_ASAN}")
set(BOOST_CONTEXT_ASAN_PATH "$ENV{HOME}/boost_ucontext_asan")
# https://www.boost.org/doc/libs/master/libs/context/doc/html/context/stack/sanitizers.html
add_compile_definitions(BOOST_USE_ASAN)
add_compile_definitions(BOOST_USE_UCONTEXT)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
find_library(Boost_CONTEXT_LIBRARY
NAMES boost_context
PATHS ${BOOST_CONTEXT_ASAN_PATH}/lib
NO_DEFAULT_PATH)
set(BOOST_CONTEXT_TARGET ${Boost_CONTEXT_LIBRARY})
else ()
find_package(Boost REQUIRED COMPONENTS context)
set(BOOST_CONTEXT_TARGET Boost::context)
endif()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, locate and examine the file
find . -name "build_eloq_store.cmake" -type f

Repository: eloqdata/tx_service

Length of output: 125


🏁 Script executed:

# Read the entire file to understand context
cat -n store_handler/eloq_data_store_service/build_eloq_store.cmake

Repository: eloqdata/tx_service

Length of output: 5714


🏁 Script executed:

# Check if there's any code before line 19 that might set Boost_INCLUDE_DIRS for ASAN
head -20 store_handler/eloq_data_store_service/build_eloq_store.cmake | tail -10

Repository: eloqdata/tx_service

Length of output: 330


🏁 Script executed:

# Check if this file is included from a parent CMakeLists that might set Boost_INCLUDE_DIRS
find . -name "CMakeLists.txt" | xargs grep -l "build_eloq_store.cmake" 2>/dev/null | head -3

Repository: eloqdata/tx_service

Length of output: 134


🏁 Script executed:

# Check the parent CMakeLists to see if Boost is set up there
find . -path "./store_handler/eloq_data_store_service" -prune -o -name "CMakeLists.txt" -type f -print | head -5

Repository: eloqdata/tx_service

Length of output: 219


🏁 Script executed:

# Check what's in the store_handler CMakeLists
cat store_handler/eloq_data_store_service/CMakeLists.txt

Repository: eloqdata/tx_service

Length of output: 16038


🏁 Script executed:

# Check root CMakeLists for Boost setup
head -100 CMakeLists.txt

Repository: eloqdata/tx_service

Length of output: 5670


🏁 Script executed:

# Final verification: check if Boost_INCLUDE_DIRS is ever set before line 77 in build_eloq_store.cmake
# by searching for any find_package(Boost or Boost_INCLUDE_DIRS assignment before it
grep -n "Boost_INCLUDE_DIRS\|find_package.*Boost" store_handler/eloq_data_store_service/build_eloq_store.cmake | head -20

Repository: eloqdata/tx_service

Length of output: 146


🏁 Script executed:

# Verify that line 77 unconditionally uses Boost_INCLUDE_DIRS without checking ASAN path first
sed -n '70,85p' store_handler/eloq_data_store_service/build_eloq_store.cmake

Repository: eloqdata/tx_service

Length of output: 542


Add missing Boost.Context resolution in ASAN branch and harden find_library checks.

Lines 19-35 lack error handling and header discovery:

  • find_library(Boost_CONTEXT_LIBRARY ...) at line 27 has no NOTFOUND guard, risking silent linkage failure.
  • ASAN branch never sets Boost_INCLUDE_DIRS, but line 77 unconditionally uses it in ELOQ_STORE_INCLUDE, causing compilation to fail with missing Boost headers.
  • Hard-coded $ENV{HOME}/boost_ucontext_asan (line 21) is non-portable for CI and shared machines.

Suggested fix:

 if(WITH_ASAN)
     message("build eloqstore with ASAN: ${WITH_ASAN}")
-    set(BOOST_CONTEXT_ASAN_PATH "$ENV{HOME}/boost_ucontext_asan")
+    set(BOOST_CONTEXT_ASAN_PATH "$ENV{HOME}/boost_ucontext_asan" CACHE PATH "Prefix of ASAN-built Boost (expects include/ and lib/)")
     # https://www.boost.org/doc/libs/master/libs/context/doc/html/context/stack/sanitizers.html
     add_compile_definitions(BOOST_USE_ASAN)
     add_compile_definitions(BOOST_USE_UCONTEXT)

     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
+    find_path(Boost_INCLUDE_DIRS
+            NAMES boost/config.hpp
+            PATHS ${BOOST_CONTEXT_ASAN_PATH}/include
+            NO_DEFAULT_PATH)
+    if (NOT Boost_INCLUDE_DIRS)
+        message(FATAL_ERROR "Fail to find Boost headers under ${BOOST_CONTEXT_ASAN_PATH}/include (required for WITH_ASAN)")
+    endif()
     find_library(Boost_CONTEXT_LIBRARY
             NAMES boost_context
             PATHS ${BOOST_CONTEXT_ASAN_PATH}/lib
             NO_DEFAULT_PATH)
+    if (NOT Boost_CONTEXT_LIBRARY)
+        message(FATAL_ERROR "Fail to find boost_context under ${BOOST_CONTEXT_ASAN_PATH}/lib (required for WITH_ASAN)")
+    endif()
     set(BOOST_CONTEXT_TARGET ${Boost_CONTEXT_LIBRARY})
 else ()
     find_package(Boost REQUIRED COMPONENTS context)
     set(BOOST_CONTEXT_TARGET Boost::context)
 endif()

Also move BOOST_USE_ASAN, BOOST_USE_UCONTEXT, and sanitizer flags from global scope to target-level (via target_compile_definitions, target_compile_options, target_link_options) once eloqstore target is created, ensuring the final link step reliably gets -fsanitize=address without contaminating unrelated targets.

🤖 Prompt for AI Agents
In store_handler/eloq_data_store_service/build_eloq_store.cmake around lines 19
to 35, the ASAN branch currently hardcodes an ENV path, doesn't resolve Boost
include dirs, and doesn't guard against find_library failing; update it to (1)
allow an overridable ASAN boost path via a CMake variable (with the prior ENV
value as a default) instead of hardcoding $ENV{HOME}, (2) use find_path to
locate Boost_INCLUDE_DIRS (or derive include from the found library path) and
set Boost_INCLUDE_DIRS when the ASAN build is chosen so ELOQ_STORE_INCLUDE is
valid, (3) check the result of find_library and call message(FATAL_ERROR ...)
(or message(STATUS)+return) if the library was not found to avoid silent linkage
failure, and (4) remove global add_compile_definitions and global
CMAKE_CXX_FLAGS changes and instead plan to apply
BOOST_USE_ASAN/BOOST_USE_UCONTEXT and sanitizer compiler/link flags with
target_compile_definitions/target_compile_options/target_link_options on the
eloqstore target after it is created.

@thweetkomputer
thweetkomputer merged commit 3164008 into main Dec 12, 2025
4 checks passed
@thweetkomputer
thweetkomputer deleted the asan_boost branch December 12, 2025 07:43
@coderabbitai coderabbitai Bot mentioned this pull request Mar 23, 2026
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants