* [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 2026-04-09 15:38 ` [PATCH v2] " Hisam Mehboob 0 siblings, 2 replies; 9+ 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 [flat|nested] 9+ messages in thread
* Re: [PATCH] KVM: selftests: Guard execinfo.h inclusion for non-glibc builds 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-04-09 15:38 ` [PATCH v2] " Hisam Mehboob 1 sibling, 1 reply; 9+ messages in thread From: Shuah Khan @ 2026-03-24 18:02 UTC (permalink / raw) To: Hisam Mehboob, pbonzini, seanjc Cc: kvm, linux-kselftest, linux-kernel, Aqib Faruqui, Shuah Khan, shuah 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/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 Is __GLIBC__ defined in musl-gcc? Looks like that is the case with the error? Check a couple of things first: did you run "make headers" and do you have the correct packages installed on your system? thanks, -- Shuah ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] KVM: selftests: Guard execinfo.h inclusion for non-glibc builds 2026-03-24 18:02 ` Shuah Khan @ 2026-03-25 18:03 ` Shuah Khan 2026-03-25 18:47 ` Hisam Mehboob 0 siblings, 1 reply; 9+ messages in thread From: Shuah Khan @ 2026-03-25 18:03 UTC (permalink / raw) To: Hisam Mehboob Cc: kvm, linux-kselftest, linux-kernel, Aqib Faruqui, shuah, Shuah Khan, pbonzini, seanjc 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/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 > > 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 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] KVM: selftests: Guard execinfo.h inclusion for non-glibc builds 2026-03-25 18:03 ` Shuah Khan @ 2026-03-25 18:47 ` Hisam Mehboob 2026-03-31 23:09 ` Shuah Khan 0 siblings, 1 reply; 9+ messages in thread From: Hisam Mehboob @ 2026-03-25 18:47 UTC (permalink / raw) To: Shuah Khan Cc: kvm, linux-kselftest, linux-kernel, Aqib Faruqui, shuah, pbonzini, seanjc, hisamshar On 3/25/26 23:03, Shuah Khan wrote: > 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/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 >> > 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? > To clarify the compiler error you mentioned: the error log in the commit message shows the failure that occurs before this patch is applied. Because musl-gcc doesn't define __GLIBC__, the original unconditional <execinfo.h> inclusion causes the build to fail. The #ifdef in my patch was intended to fix that exact failure. > +#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 > Looking at how bpf/test_progs.c handles it, I agree the weak stub approach is much cleaner. I will implement it so that it still prints an explicit warning message when a trace is unavailable. If you are okay with this, I will move forward with a v2 patch. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] KVM: selftests: Guard execinfo.h inclusion for non-glibc builds 2026-03-25 18:47 ` Hisam Mehboob @ 2026-03-31 23:09 ` Shuah Khan 2026-04-01 14:01 ` Sean Christopherson 0 siblings, 1 reply; 9+ messages in thread From: Shuah Khan @ 2026-03-31 23:09 UTC (permalink / raw) To: Hisam Mehboob Cc: kvm, linux-kselftest, linux-kernel, Aqib Faruqui, shuah, pbonzini, seanjc, Shuah Khan On 3/25/26 12:47, Hisam Mehboob wrote: > On 3/25/26 23:03, Shuah Khan wrote: >> 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/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 >>> > 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? >> > > To clarify the compiler error you mentioned: the error log in the commit message shows the failure that occurs before this patch is applied. Because musl-gcc doesn't define __GLIBC__, the original unconditional <execinfo.h> inclusion causes the build to fail. The #ifdef in my patch was intended to fix that exact failure. > >> +#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 >> > > Looking at how bpf/test_progs.c handles it, I agree the weak stub approach is much cleaner. I will implement it so that it still prints an explicit warning message when a trace is unavailable. > > If you are okay with this, I will move forward with a v2 patch. > Ultimately kvm maintainers make the call - send v2 patch thanks, -- Shuah ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] KVM: selftests: Guard execinfo.h inclusion for non-glibc builds 2026-03-31 23:09 ` Shuah Khan @ 2026-04-01 14:01 ` Sean Christopherson 2026-04-09 11:53 ` Hisam Mehboob 0 siblings, 1 reply; 9+ messages in thread From: Sean Christopherson @ 2026-04-01 14:01 UTC (permalink / raw) To: Shuah Khan Cc: Hisam Mehboob, kvm, linux-kselftest, linux-kernel, Aqib Faruqui, shuah, pbonzini On Tue, Mar 31, 2026, Shuah Khan wrote: > On 3/25/26 12:47, Hisam Mehboob wrote: > > On 3/25/26 23:03, Shuah Khan wrote: > > > 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/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 > > > > > 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? > > > > > > > To clarify the compiler error you mentioned: the error log in the commit > > message shows the failure that occurs before this patch is applied. Because > > musl-gcc doesn't define __GLIBC__, the original unconditional <execinfo.h> > > inclusion causes the build to fail. The #ifdef in my patch was intended to > > fix that exact failure. > > > > > +#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 > > > > > > > Looking at how bpf/test_progs.c handles it, I agree the weak stub approach > > is much cleaner. I will implement it so that it still prints an explicit > > warning message when a trace is unavailable. I disagree. _If_ we didn't need the __GLIBC__ #ifdef, then I would be in favor of __weak, but since the #ifdeffery is needed, using an #ifdef and a __weak symbol is double the ugliness. IMO, the way to make this less ugly is to using a single #ifdef and a local stub. diff --git a/tools/testing/selftests/kvm/lib/assert.c b/tools/testing/selftests/kvm/lib/assert.c index b49690658c60..315175ca49f1 100644 --- a/tools/testing/selftests/kvm/lib/assert.c +++ b/tools/testing/selftests/kvm/lib/assert.c @@ -6,11 +6,13 @@ */ #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 +59,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) { ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] KVM: selftests: Guard execinfo.h inclusion for non-glibc builds 2026-04-01 14:01 ` Sean Christopherson @ 2026-04-09 11:53 ` Hisam Mehboob 0 siblings, 0 replies; 9+ messages in thread From: Hisam Mehboob @ 2026-04-09 11:53 UTC (permalink / raw) To: Sean Christopherson, Shuah Khan Cc: kvm, linux-kselftest, linux-kernel, Aqib Faruqui, shuah, pbonzini On 4/1/26 19:01, Sean Christopherson wrote: > On Tue, Mar 31, 2026, Shuah Khan wrote: >> On 3/25/26 12:47, Hisam Mehboob wrote: >>> On 3/25/26 23:03, Shuah Khan wrote: >>>> 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/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 >>>>>> 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? >>>> >>> >>> To clarify the compiler error you mentioned: the error log in the commit >>> message shows the failure that occurs before this patch is applied. Because >>> musl-gcc doesn't define __GLIBC__, the original unconditional <execinfo.h> >>> inclusion causes the build to fail. The #ifdef in my patch was intended to >>> fix that exact failure. >>> >>>> +#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 >>>> >>> >>> Looking at how bpf/test_progs.c handles it, I agree the weak stub approach >>> is much cleaner. I will implement it so that it still prints an explicit >>> warning message when a trace is unavailable. > > I disagree. _If_ we didn't need the __GLIBC__ #ifdef, then I would be in favor > of __weak, but since the #ifdeffery is needed, using an #ifdef and a __weak symbol > is double the ugliness. > > IMO, the way to make this less ugly is to using a single #ifdef and a local stub. > > diff --git a/tools/testing/selftests/kvm/lib/assert.c b/tools/testing/selftests/kvm/lib/assert.c > index b49690658c60..315175ca49f1 100644 > --- a/tools/testing/selftests/kvm/lib/assert.c > +++ b/tools/testing/selftests/kvm/lib/assert.c > @@ -6,11 +6,13 @@ > */ > #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 +59,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) > { Thanks for the suggestion. I will send a v2 implementing this approach. ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2] KVM: selftests: Guard execinfo.h inclusion for non-glibc builds 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-04-09 15:38 ` Hisam Mehboob 2026-05-19 0:40 ` Sean Christopherson 1 sibling, 1 reply; 9+ messages in thread From: Hisam Mehboob @ 2026-04-09 15:38 UTC (permalink / raw) To: Sean Christopherson, Shuah Khan Cc: kvm, linux-kselftest, linux-kernel, Aqib Faruqui, shuah, pbonzini, Hisam Mehboob 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 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] KVM: selftests: Guard execinfo.h inclusion for non-glibc builds 2026-04-09 15:38 ` [PATCH v2] " Hisam Mehboob @ 2026-05-19 0:40 ` Sean Christopherson 0 siblings, 0 replies; 9+ messages in thread From: Sean Christopherson @ 2026-05-19 0:40 UTC (permalink / raw) To: Sean Christopherson, Shuah Khan, Hisam Mehboob Cc: kvm, linux-kselftest, linux-kernel, Aqib Faruqui, shuah, pbonzini 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 ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-05-19 0:40 UTC | newest] Thread overview: 9+ 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 2026-04-09 11:53 ` Hisam Mehboob 2026-04-09 15:38 ` [PATCH v2] " Hisam Mehboob 2026-05-19 0:40 ` Sean Christopherson
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox