On 3/24/26 12:02, Shuah Khan wrote:
On 3/18/26 18:08, 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
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/[email protected]/
Suggested-by: Aqib Faruqui <[email protected]>
Signed-off-by: Hisam Mehboob <[email protected]>
---
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
> Is __GLIBC__ defined in musl-gcc? Looks like that is the case with the
error?
If __GLIBC__ isn't there you shouldn't see this error because the include
is in - this error doesn't make sense if __GLIBC__ isn't defined. What
am I missing?
+#ifdef __GLIBC__
#include <execinfo.h>
+#endif
Also check tools/testing/selftests/bpf/test_progs.c - I think backtrace()
stub needs be defined only for the !__GLIBC__ case
thanks,
-- Shuah