Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rtloader: Use execinfo only on glibc #15256

Merged
merged 5 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`.

1 change: 1 addition & 0 deletions rtloader/rtloader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is great, but we also need this a few lines below in the ## Backtrace section for FreeBSD as well. According to the freebsd man pages, the Backtrace package also provides execinfo.h

endif()
endif()

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