diff --git a/releasenotes/notes/rtloader-use-execinfo-only-on-glibc-5b734df32fc1555a.yaml b/releasenotes/notes/rtloader-use-execinfo-only-on-glibc-5b734df32fc1555a.yaml new file mode 100644 index 0000000000000..a7337ddc044d9 --- /dev/null +++ b/releasenotes/notes/rtloader-use-execinfo-only-on-glibc-5b734df32fc1555a.yaml @@ -0,0 +1,13 @@ +# Each section from every release note are combined when the +# CHANGELOG.rst is rendered. So the text needs to be worded so that +# it does not depend on any information only available in another +# section. This may mean repeating some details, but each section +# must be readable independently of the other. +# +# Each section note must be formatted as reStructuredText. +--- +fixes: + - | + rtloader: Use `execinfo` only if provided to fix builds on + C libraries like `musl`. + diff --git a/rtloader/rtloader/CMakeLists.txt b/rtloader/rtloader/CMakeLists.txt index 8cb06c7e799d1..a830f18c995c3 100644 --- a/rtloader/rtloader/CMakeLists.txt +++ b/rtloader/rtloader/CMakeLists.txt @@ -32,6 +32,7 @@ add_library(datadog-agent-rtloader SHARED find_library(EXECINFO execinfo) if(EXECINFO) target_link_libraries(datadog-agent-rtloader execinfo) + add_compile_definitions(HAS_BACKTRACE_LIB) endif() endif() @@ -39,6 +40,7 @@ endif() if(${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD) find_package(Backtrace REQUIRED) target_link_libraries(datadog-agent-rtloader ${Backtrace_LIBRARIES}) + add_compile_definitions(HAS_BACKTRACE_LIB) endif() set_target_properties(datadog-agent-rtloader PROPERTIES diff --git a/rtloader/rtloader/api.cpp b/rtloader/rtloader/api.cpp index af5fe74b5972b..f150be80d06fd 100644 --- a/rtloader/rtloader/api.cpp +++ b/rtloader/rtloader/api.cpp @@ -12,7 +12,9 @@ #ifndef _WIN32 // clang-format off // handler stuff +#ifdef HAS_BACKTRACE_LIB #include +#endif #include #include #include @@ -371,11 +373,14 @@ static inline void core(int sig) # define STACKTRACE_SIZE 500 void signalHandler(int sig, siginfo_t *, void *) { +# ifdef HAS_BACKTRACE_LIB void *buffer[STACKTRACE_SIZE]; char **symbols; size_t nptrs = backtrace(buffer, STACKTRACE_SIZE); +# endif std::cerr << "HANDLER CAUGHT signal Error: signal " << sig << std::endl; +# ifdef HAS_BACKTRACE_LIB symbols = backtrace_symbols(buffer, nptrs); if (symbols == NULL) { std::cerr << "Error getting backtrace symbols" << std::endl; @@ -387,6 +392,7 @@ void signalHandler(int sig, siginfo_t *, void *) _free(symbols); } +# endif // dump core if so configured __sync_synchronize();