[PATCH v2] KVM: selftests: Guard execinfo.h inclusion for non-glibc builds

Hisam Mehboob posted 1 patch 2 months ago
tools/testing/selftests/kvm/lib/assert.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
[PATCH v2] KVM: selftests: Guard execinfo.h inclusion for non-glibc builds
Posted by Hisam Mehboob 2 months ago
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

Fix this by guarding the inclusion of execinfo.h and the stack dumping
logic under #ifdef __GLIBC__. For non-glibc builds, provide a local
stub for test_dump_stack().

Suggested-by: Aqib Faruqui <aqibaf@amazon.com>
Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Hisam Mehboob <hisamshar@gmail.com>
---
Changes in v2:
- Replaced the __weak stub approach with a single #ifdef __GLIBC__
  and a local stub inside assert.c as suggested by Sean Christopherson.

 tools/testing/selftests/kvm/lib/assert.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/kvm/lib/assert.c b/tools/testing/selftests/kvm/lib/assert.c
index b49690658c60..8be0d09ecf0f 100644
--- a/tools/testing/selftests/kvm/lib/assert.c
+++ b/tools/testing/selftests/kvm/lib/assert.c
@@ -6,11 +6,14 @@
  */
 #include "test_util.h"
 
-#include <execinfo.h>
+
 #include <sys/syscall.h>
 
 #include "kselftest.h"
 
+#ifdef __GLIBC__
+#include <execinfo.h>
+
 /* Dumps the current stack trace to stderr. */
 static void __attribute__((noinline)) test_dump_stack(void);
 static void test_dump_stack(void)
@@ -57,6 +60,9 @@ static void test_dump_stack(void)
 	system(cmd);
 #pragma GCC diagnostic pop
 }
+#else
+static void test_dump_stack(void) {}
+#endif
 
 static pid_t _gettid(void)
 {
-- 
2.51.0
Re: [PATCH v2] KVM: selftests: Guard execinfo.h inclusion for non-glibc builds
Posted by Sean Christopherson 3 weeks, 2 days ago
On Thu, 09 Apr 2026 20:38:47 +0500, Hisam Mehboob wrote:
> 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
> 
> Fix this by guarding the inclusion of execinfo.h and the stack dumping
> logic under #ifdef __GLIBC__. For non-glibc builds, provide a local
> stub for test_dump_stack().
> 
> [...]

Applied to kvm-x86 fixes, thanks!

[1/1] KVM: selftests: Guard execinfo.h inclusion for non-glibc builds
      https://github.com/kvm-x86/linux/commit/34065a5f3cf9

--
https://github.com/kvm-x86/linux/tree/next