From 20cd799e518c25e41de9cf6ce1bec1429fda2749 Mon Sep 17 00:00:00 2001 From: ltrk2 <107155950+ltrk2@users.noreply.github.com> Date: Fri, 5 May 2023 16:26:53 +0000 Subject: [PATCH] Add CMake option for BOOST_USE_UCONTEXT --- base/base/defines.h | 12 ----------- contrib/boost-cmake/CMakeLists.txt | 33 +++++++++++++++++------------- src/CMakeLists.txt | 3 ++- 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/base/base/defines.h b/base/base/defines.h index 91c35dc28b6..6abf8155b95 100644 --- a/base/base/defines.h +++ b/base/base/defines.h @@ -73,18 +73,6 @@ # endif #endif -#if defined(ADDRESS_SANITIZER) -# define BOOST_USE_ASAN 1 -# define BOOST_USE_UCONTEXT 1 -#endif - -#if defined(THREAD_SANITIZER) -# define BOOST_USE_TSAN 1 -# define BOOST_USE_UCONTEXT 1 -#endif - -/// TODO: Strange enough, there is no way to detect UB sanitizer. - /// Explicitly allow undefined behaviour for certain functions. Use it as a function attribute. /// It is useful in case when compiler cannot see (and exploit) it, but UBSan can. /// Example: multiplication of signed integers with possibility of overflow when both sides are from user input. diff --git a/contrib/boost-cmake/CMakeLists.txt b/contrib/boost-cmake/CMakeLists.txt index 2a70c25ffe1..c9a759eab9c 100644 --- a/contrib/boost-cmake/CMakeLists.txt +++ b/contrib/boost-cmake/CMakeLists.txt @@ -92,6 +92,8 @@ add_library (boost::system ALIAS _boost_system) target_include_directories (_boost_system PRIVATE ${LIBRARY_DIR}) # context +option (BOOST_USE_UCONTEXT "Use ucontext_t for context switching of boost::fiber within boost::context" OFF) + enable_language(ASM) SET(ASM_OPTIONS "-x assembler-with-cpp") @@ -100,20 +102,6 @@ set (SRCS_CONTEXT "${LIBRARY_DIR}/libs/context/src/posix/stack_traits.cpp" ) -if (SANITIZE AND (SANITIZE STREQUAL "address" OR SANITIZE STREQUAL "thread")) - add_compile_definitions(BOOST_USE_UCONTEXT) - - if (SANITIZE STREQUAL "address") - add_compile_definitions(BOOST_USE_ASAN) - elseif (SANITIZE STREQUAL "thread") - add_compile_definitions(BOOST_USE_TSAN) - endif() - - set (SRCS_CONTEXT ${SRCS_CONTEXT} - "${LIBRARY_DIR}/libs/context/src/fiber.cpp" - "${LIBRARY_DIR}/libs/context/src/continuation.cpp" - ) -endif() if (ARCH_AARCH64) set (SRCS_CONTEXT ${SRCS_CONTEXT} "${LIBRARY_DIR}/libs/context/src/asm/jump_arm64_aapcs_elf_gas.S" @@ -152,10 +140,27 @@ else() ) endif() +if (SANITIZE OR BOOST_USE_UCONTEXT) + list (APPEND SRCS_CONTEXT + "${LIBRARY_DIR}/libs/context/src/fiber.cpp" + "${LIBRARY_DIR}/libs/context/src/continuation.cpp" + ) +endif() + add_library (_boost_context ${SRCS_CONTEXT}) add_library (boost::context ALIAS _boost_context) target_include_directories (_boost_context PRIVATE ${LIBRARY_DIR}) +if (SANITIZE OR BOOST_USE_UCONTEXT) + target_compile_definitions(_boost_context PUBLIC BOOST_USE_UCONTEXT) +endif() + +if (SANITIZE STREQUAL "address") + target_compile_definitions(_boost_context PUBLIC BOOST_USE_ASAN) +elseif (SANITIZE STREQUAL "thread") + target_compile_definitions(_boost_context PUBLIC BOOST_USE_TSAN) +endif() + # coroutine set (SRCS_COROUTINE diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9b1968c7d82..76a67ade99c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -544,7 +544,8 @@ if (TARGET ch_contrib::qpl) dbms_target_link_libraries(PUBLIC ch_contrib::qpl) endif () -dbms_target_link_libraries(PRIVATE _boost_context) +target_link_libraries(clickhouse_common_io PUBLIC boost::context) +dbms_target_link_libraries(PUBLIC boost::context) if (ENABLE_NLP) dbms_target_link_libraries (PUBLIC ch_contrib::stemmer)