0022-compiler-rt-Do-not-use-backtrace-APIs-on-non-glibc-l.patch 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. From f8ee0a66ba5b81f5489d8954dfc521f6b2612c6d Mon Sep 17 00:00:00 2001
  2. From: Khem Raj <raj.khem@gmail.com>
  3. Date: Wed, 19 May 2021 17:32:13 -0700
  4. Subject: [PATCH] compiler-rt: Do not use backtrace APIs on non-glibc linux
  5. musl e.g. does not provide backtrace APIs
  6. Upstream-Status: Pending
  7. Signed-off-by: Khem Raj <raj.khem@gmail.com>
  8. ---
  9. .../lib/gwp_asan/optional/backtrace_linux_libc.cpp | 13 ++++++++++++-
  10. 1 file changed, 12 insertions(+), 1 deletion(-)
  11. diff --git a/compiler-rt/lib/gwp_asan/optional/backtrace_linux_libc.cpp b/compiler-rt/lib/gwp_asan/optional/backtrace_linux_libc.cpp
  12. index ea8e72be287d..0344074dd254 100644
  13. --- a/compiler-rt/lib/gwp_asan/optional/backtrace_linux_libc.cpp
  14. +++ b/compiler-rt/lib/gwp_asan/optional/backtrace_linux_libc.cpp
  15. @@ -7,7 +7,9 @@
  16. //===----------------------------------------------------------------------===//
  17. #include <assert.h>
  18. +#ifdef __GLIBC__
  19. #include <execinfo.h>
  20. +#endif
  21. #include <stddef.h>
  22. #include <stdint.h>
  23. #include <stdlib.h>
  24. @@ -21,8 +23,11 @@
  25. namespace {
  26. size_t Backtrace(uintptr_t *TraceBuffer, size_t Size) {
  27. static_assert(sizeof(uintptr_t) == sizeof(void *), "uintptr_t is not void*");
  28. -
  29. +#ifdef __GLIBC__
  30. return backtrace(reinterpret_cast<void **>(TraceBuffer), Size);
  31. +#else
  32. + return -1;
  33. +#endif
  34. }
  35. // We don't need any custom handling for the Segv backtrace - the libc unwinder
  36. @@ -30,7 +35,11 @@ size_t Backtrace(uintptr_t *TraceBuffer, size_t Size) {
  37. // to avoid the additional frame.
  38. GWP_ASAN_ALWAYS_INLINE size_t SegvBacktrace(uintptr_t *TraceBuffer, size_t Size,
  39. void * /*Context*/) {
  40. +#ifdef __GLIBC__
  41. return Backtrace(TraceBuffer, Size);
  42. +#else
  43. + return -1;
  44. +#endif
  45. }
  46. static void PrintBacktrace(uintptr_t *Trace, size_t TraceLength,
  47. @@ -40,6 +49,7 @@ static void PrintBacktrace(uintptr_t *Trace, size_t TraceLength,
  48. return;
  49. }
  50. +#ifdef __GLIBC__
  51. char **BacktraceSymbols =
  52. backtrace_symbols(reinterpret_cast<void **>(Trace), TraceLength);
  53. @@ -53,6 +63,7 @@ static void PrintBacktrace(uintptr_t *Trace, size_t TraceLength,
  54. Printf("\n");
  55. if (BacktraceSymbols)
  56. free(BacktraceSymbols);
  57. +#endif
  58. }
  59. } // anonymous namespace