public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: selftests: Guard execinfo.h inclusion for non-glibc builds
@ 2026-03-19  0:08 Hisam Mehboob
  2026-03-24 18:02 ` Shuah Khan
  0 siblings, 1 reply; 6+ messages in thread
From: Hisam Mehboob @ 2026-03-19  0:08 UTC (permalink / raw)
  To: pbonzini, shuah, seanjc
  Cc: kvm, linux-kselftest, linux-kernel, Hisam Mehboob, Aqib Faruqui

The backtrace() function and execinfo.h are GNU extensions available
in glibc but not in non-glibc C libraries such as musl. Building KVM
selftests with musl-gcc fails with:

  lib/assert.c:9:10: fatal error: execinfo.h: No such file or directory

Guard the inclusion of execinfo.h under #ifdef __GLIBC__, and wrap
all backtrace() usage under the same guard with a fallback message
for non-glibc builds indicating that stack traces are not available.

Unlike the approach of adding a weak stub for backtrace(), this
explicitly handles the non-glibc case rather than silently providing
an empty implementation.

Link: https://lore.kernel.org/kvm/20250829142556.72577-7-aqibaf@amazon.com/

Suggested-by: Aqib Faruqui <aqibaf@amazon.com>
Signed-off-by: Hisam Mehboob <hisamshar@gmail.com>
---
 tools/testing/selftests/kvm/lib/assert.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tools/testing/selftests/kvm/lib/assert.c b/tools/testing/selftests/kvm/lib/assert.c
index b49690658c60..3442b80c37c1 100644
--- a/tools/testing/selftests/kvm/lib/assert.c
+++ b/tools/testing/selftests/kvm/lib/assert.c
@@ -6,7 +6,9 @@
  */
 #include "test_util.h"
 
+#ifdef __GLIBC__
 #include <execinfo.h>
+#endif
 #include <sys/syscall.h>
 
 #include "kselftest.h"
@@ -15,6 +17,7 @@
 static void __attribute__((noinline)) test_dump_stack(void);
 static void test_dump_stack(void)
 {
+#ifdef __GLIBC__
 	/*
 	 * Build and run this command:
 	 *
@@ -56,6 +59,10 @@ static void test_dump_stack(void)
 #pragma GCC diagnostic ignored "-Wunused-result"
 	system(cmd);
 #pragma GCC diagnostic pop
+
+#else /* !__GLIBC__ */
+	fputs("  (stack trace not available: compiled without glibc)\n", stderr);
+#endif
 }
 
 static pid_t _gettid(void)
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-04-01 14:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-19  0:08 [PATCH] KVM: selftests: Guard execinfo.h inclusion for non-glibc builds Hisam Mehboob
2026-03-24 18:02 ` Shuah Khan
2026-03-25 18:03   ` Shuah Khan
2026-03-25 18:47     ` Hisam Mehboob
2026-03-31 23:09       ` Shuah Khan
2026-04-01 14:01         ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox