1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- From 3c6139afa9d15fac7ace71763c2d557e52e39510 Mon Sep 17 00:00:00 2001
- From: Jun Yuan Tan <junyuan.tan@starfivetech.com>
- Date: Tue, 9 Nov 2021 10:53:27 +0800
- Subject: [PATCH 26/34] compiler-rt: Do not use backtrace APIs on non-glibc
- linux
- musl e.g. does not provide backtrace APIs
- Rebased to LLVM 14.0.0 by Jun Yuan Tan
- Signed-off-by: Khem Raj <raj.khem@gmail.com>
- Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
- ---
- .../lib/gwp_asan/optional/backtrace_linux_libc.cpp | 13 ++++++++++++-
- 1 file changed, 12 insertions(+), 1 deletion(-)
- diff --git a/compiler-rt/lib/gwp_asan/optional/backtrace_linux_libc.cpp b/compiler-rt/lib/gwp_asan/optional/backtrace_linux_libc.cpp
- index ea8e72be287d..0344074dd254 100644
- --- a/compiler-rt/lib/gwp_asan/optional/backtrace_linux_libc.cpp
- +++ b/compiler-rt/lib/gwp_asan/optional/backtrace_linux_libc.cpp
- @@ -7,7 +7,9 @@
- //===----------------------------------------------------------------------===//
-
- #include <assert.h>
- +#ifdef __GLIBC__
- #include <execinfo.h>
- +#endif
- #include <stddef.h>
- #include <stdint.h>
- #include <stdlib.h>
- @@ -21,8 +23,11 @@
- namespace {
- size_t Backtrace(uintptr_t *TraceBuffer, size_t Size) {
- static_assert(sizeof(uintptr_t) == sizeof(void *), "uintptr_t is not void*");
- -
- +#ifdef __GLIBC__
- return backtrace(reinterpret_cast<void **>(TraceBuffer), Size);
- +#else
- + return -1;
- +#endif
- }
-
- // We don't need any custom handling for the Segv backtrace - the libc unwinder
- @@ -30,7 +35,11 @@ size_t Backtrace(uintptr_t *TraceBuffer, size_t Size) {
- // to avoid the additional frame.
- GWP_ASAN_ALWAYS_INLINE size_t SegvBacktrace(uintptr_t *TraceBuffer, size_t Size,
- void * /*Context*/) {
- +#ifdef __GLIBC__
- return Backtrace(TraceBuffer, Size);
- +#else
- + return -1;
- +#endif
- }
-
- static void PrintBacktrace(uintptr_t *Trace, size_t TraceLength,
- @@ -40,6 +49,7 @@ static void PrintBacktrace(uintptr_t *Trace, size_t TraceLength,
- return;
- }
-
- +#ifdef __GLIBC__
- char **BacktraceSymbols =
- backtrace_symbols(reinterpret_cast<void **>(Trace), TraceLength);
-
- @@ -53,6 +63,7 @@ static void PrintBacktrace(uintptr_t *Trace, size_t TraceLength,
- Printf("\n");
- if (BacktraceSymbols)
- free(BacktraceSymbols);
- +#endif
- }
- } // anonymous namespace
-
- --
- 2.33.1
|