Skip to content

Commit 02f0a06

Browse files
committed
compiler-rt: Do not use backtrace APIs on non-glibc linux
musl e.g. does not provide backtrace APIs Upstream-Status: Pending Signed-off-by: Khem Raj <[email protected]>
1 parent bcf231f commit 02f0a06

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

compiler-rt/lib/gwp_asan/optional/backtrace_linux_libc.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
//===----------------------------------------------------------------------===//
88

99
#include <assert.h>
10+
#ifdef __GLIBC__
1011
#include <execinfo.h>
12+
#endif
1113
#include <stddef.h>
1214
#include <stdint.h>
1315
#include <stdlib.h>
@@ -21,16 +23,23 @@
2123
namespace {
2224
size_t Backtrace(uintptr_t *TraceBuffer, size_t Size) {
2325
static_assert(sizeof(uintptr_t) == sizeof(void *), "uintptr_t is not void*");
24-
26+
#ifdef __GLIBC__
2527
return backtrace(reinterpret_cast<void **>(TraceBuffer), Size);
28+
#else
29+
return -1;
30+
#endif
2631
}
2732

2833
// We don't need any custom handling for the Segv backtrace - the libc unwinder
2934
// has no problems with unwinding through a signal handler. Force inlining here
3035
// to avoid the additional frame.
3136
GWP_ASAN_ALWAYS_INLINE size_t SegvBacktrace(uintptr_t *TraceBuffer, size_t Size,
3237
void * /*Context*/) {
38+
#ifdef __GLIBC__
3339
return Backtrace(TraceBuffer, Size);
40+
#else
41+
return -1;
42+
#endif
3443
}
3544

3645
static void PrintBacktrace(uintptr_t *Trace, size_t TraceLength,
@@ -40,6 +49,7 @@ static void PrintBacktrace(uintptr_t *Trace, size_t TraceLength,
4049
return;
4150
}
4251

52+
#ifdef __GLIBC__
4353
char **BacktraceSymbols =
4454
backtrace_symbols(reinterpret_cast<void **>(Trace), TraceLength);
4555

@@ -53,6 +63,7 @@ static void PrintBacktrace(uintptr_t *Trace, size_t TraceLength,
5363
Printf("\n");
5464
if (BacktraceSymbols)
5565
free(BacktraceSymbols);
66+
#endif
5667
}
5768
} // anonymous namespace
5869

0 commit comments

Comments
 (0)