0026-compiler-rt-Do-not-use-backtrace-APIs-on-non-glibc-l.patch 2.3 KB

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