Skip to content

Commit

Permalink
rtloader: Use execinfo only on glibc (#15256)
Browse files Browse the repository at this point in the history
Use execinfo only on glibc.
Functions in execinfo.h are GNU extensions and not available on other C libraries like musl.

We used to use libexecinfo package (A quick-n-dirty BSD licensed clone of the GNU libc backtrace facility.) of Alpine Linux to build datadog-agent on Alpine, but it has been removed since Alpine 3.17.
This PR allow to build datadog-agent on Alpine Linux and other non-glibc environments.
  • Loading branch information
at-wat authored Jun 9, 2023
1 parent 09f72d2 commit 2d93fc1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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`.
2 changes: 2 additions & 0 deletions rtloader/rtloader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ 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()

## Backtrace
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
Expand Down
6 changes: 6 additions & 0 deletions rtloader/rtloader/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#ifndef _WIN32
// clang-format off
// handler stuff
#ifdef HAS_BACKTRACE_LIB
#include <execinfo.h>
#endif
#include <csignal>
#include <cstring>
#include <sys/types.h>
Expand Down Expand Up @@ -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;
Expand All @@ -387,6 +392,7 @@ void signalHandler(int sig, siginfo_t *, void *)

_free(symbols);
}
# endif

// dump core if so configured
__sync_synchronize();
Expand Down

0 comments on commit 2d93fc1

Please sign in to comment.