From c534f0fae5365b1d911aae06543c85dfdd28a51b Mon Sep 17 00:00:00 2001 From: Taegyun Kim Date: Fri, 11 Oct 2024 11:34:36 +0200 Subject: [PATCH] fix(profiling): explicitly link with thread library [backport-2.12] Manual backport of #10994 to 2.12 python:3.11-bookworm image for aarch64 has `pthread_atfork` in static libpthread.a not in libpthread.so so need to explicitly link for those cases. Otherwise, we get undefined symbol `pthread_atfork`. --- .../datadog/profiling/dd_wrapper/CMakeLists.txt | 11 ++++++++--- .../datadog/profiling/stack_v2/CMakeLists.txt | 17 ++++++++++++++--- ...filing-pthread-aarch64-d4548fd1842d0665.yaml | 6 ++++++ 3 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 releasenotes/notes/profiling-pthread-aarch64-d4548fd1842d0665.yaml diff --git a/ddtrace/internal/datadog/profiling/dd_wrapper/CMakeLists.txt b/ddtrace/internal/datadog/profiling/dd_wrapper/CMakeLists.txt index 2c292863df7..51dbc126dc1 100644 --- a/ddtrace/internal/datadog/profiling/dd_wrapper/CMakeLists.txt +++ b/ddtrace/internal/datadog/profiling/dd_wrapper/CMakeLists.txt @@ -20,6 +20,13 @@ include(FindCppcheck) include(FindInfer) include(CheckSymbolExists) +set(THREADS_PREFER_PTHREAD_FLAG ON) +find_package(Threads REQUIRED) + +if(NOT Threads_FOUND OR NOT CMAKE_USE_PTHREADS_INIT) + message(FATAL_ERROR "pthread compatible library not found") +endif() + # Library sources add_library(dd_wrapper SHARED src/uploader_builder.cpp @@ -46,9 +53,7 @@ target_include_directories(dd_wrapper PRIVATE ${Datadog_INCLUDE_DIRS} ) -target_link_libraries(dd_wrapper PRIVATE - ${Datadog_LIBRARIES} -) +target_link_libraries(dd_wrapper PRIVATE ${Datadog_LIBRARIES} Threads::Threads) # Figure out the suffix. Try to approximate the cpython way of doing things. ## C library diff --git a/ddtrace/internal/datadog/profiling/stack_v2/CMakeLists.txt b/ddtrace/internal/datadog/profiling/stack_v2/CMakeLists.txt index f31639fabd7..47a88292173 100644 --- a/ddtrace/internal/datadog/profiling/stack_v2/CMakeLists.txt +++ b/ddtrace/internal/datadog/profiling/stack_v2/CMakeLists.txt @@ -20,11 +20,19 @@ include(FindCppcheck) # but whether or not we keep that design is unknown. Hack it for now. add_subdirectory(../dd_wrapper ${CMAKE_CURRENT_BINARY_DIR}/../dd_wrapper_build) +find_package(Python3 COMPONENTS Interpreter Development) # Make sure we have necessary Python variables if (NOT Python3_INCLUDE_DIRS) message(FATAL_ERROR "Python3_INCLUDE_DIRS not found") endif() +set(THREADS_PREFER_PTHREAD_FLAG ON) +find_package(Threads REQUIRED) + +if(NOT Threads_FOUND OR NOT CMAKE_USE_PTHREADS_INIT) + message(FATAL_ERROR "pthread compatible library not found") +endif() + # Add echion set(ECHION_COMMIT "b2f2d49f2f5d5c4dd78d1d9b83280db8ac2949c0" CACHE STRING "Commit hash of echion to use") FetchContent_Declare( @@ -90,9 +98,12 @@ set_target_properties(${EXTENSION_NAME} PROPERTIES SUFFIX "") # RPATH is needed for sofile discovery at runtime, since Python packages are not # installed in the system path. This is typical. set_target_properties(${EXTENSION_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN/..") -target_link_libraries(${EXTENSION_NAME} PRIVATE - dd_wrapper -) + +target_link_libraries(${EXTENSION_NAME} PRIVATE dd_wrapper Threads::Threads) + +if(Python3_LIBRARIES) + target_link_libraries(${EXTENSION_NAME} PRIVATE ${Python3_LIBRARIES}) +endif() # Extensions are built as dynamic libraries, so PIC is required. set_target_properties(${EXTENSION_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) diff --git a/releasenotes/notes/profiling-pthread-aarch64-d4548fd1842d0665.yaml b/releasenotes/notes/profiling-pthread-aarch64-d4548fd1842d0665.yaml new file mode 100644 index 00000000000..cd7eeb08900 --- /dev/null +++ b/releasenotes/notes/profiling-pthread-aarch64-d4548fd1842d0665.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + profiling: fixes an issue where stack v2 couldn't be enabled as pthread + was not properly linked on some debian based images for aarch64 architecture. +