[compiler-rt][GWP-ASan] Use no-op backtrace if execinfo.h missing (#201266) Guard backtrace_linux_libc.cpp with __has_include(<execinfo.h>) so that targets without it (e.g. musl libc) get null stubs instead of a build failure. GitOrigin-RevId: 252ad2052409a33eff59a149053ec90f7fae03df
diff --git a/optional/backtrace_linux_libc.cpp b/optional/backtrace_linux_libc.cpp index ea8e72b..80ba2e2 100644 --- a/optional/backtrace_linux_libc.cpp +++ b/optional/backtrace_linux_libc.cpp
@@ -7,7 +7,6 @@ //===----------------------------------------------------------------------===// #include <assert.h> -#include <execinfo.h> #include <stddef.h> #include <stdint.h> #include <stdlib.h> @@ -18,6 +17,9 @@ #include "gwp_asan/optional/printf.h" #include "gwp_asan/options.h" +#if __has_include(<execinfo.h>) +#include <execinfo.h> + namespace { size_t Backtrace(uintptr_t *TraceBuffer, size_t Size) { static_assert(sizeof(uintptr_t) == sizeof(void *), "uintptr_t is not void*"); @@ -65,3 +67,19 @@ } // namespace backtrace } // namespace gwp_asan + +#else // !__has_include(<execinfo.h>) + +// No execinfo.h (e.g. musl libc) -- provide null stubs so GWP-ASan still +// functions as a guard allocator without stack-trace capture. +namespace gwp_asan { +namespace backtrace { + +options::Backtrace_t getBacktraceFunction() { return nullptr; } +PrintBacktrace_t getPrintBacktraceFunction() { return nullptr; } +SegvBacktrace_t getSegvBacktraceFunction() { return nullptr; } + +} // namespace backtrace +} // namespace gwp_asan + +#endif // __has_include(<execinfo.h>)