The backtrace() function is a GNU extension available in glibc but may not be present in non-glibc libraries. KVM selftests use backtrace() for error reporting and debugging.
Add conditional inclusion of execinfo.h only for glibc builds and provide a weak stub implementation of backtrace() that returns 0 (stack trace empty) for non-glibc systems.
Signed-off-by: Aqib Faruqui aqibaf@amazon.com --- tools/testing/selftests/kvm/lib/assert.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/kvm/lib/assert.c b/tools/testing/selftests/kvm/lib/assert.c index b49690658..c9778dc6c 100644 --- a/tools/testing/selftests/kvm/lib/assert.c +++ b/tools/testing/selftests/kvm/lib/assert.c @@ -6,11 +6,19 @@ */ #include "test_util.h"
-#include <execinfo.h> #include <sys/syscall.h>
+#ifdef __GLIBC__ +#include <execinfo.h> /* backtrace */ +#endif + #include "kselftest.h"
+int __attribute__((weak)) backtrace(void **buffer, int size) +{ + return 0; +} + /* Dumps the current stack trace to stderr. */ static void __attribute__((noinline)) test_dump_stack(void); static void test_dump_stack(void)
linux-kselftest-mirror@lists.linaro.org