From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFB9C2D9ECA for ; Wed, 1 Apr 2026 14:01:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775052081; cv=none; b=HOe0awvhua4681DHtr4xl9yEpAEKrbXedX0Fa1OiTWPGuRzSwiq99DQiOYQ8Mxy2UKU9N3B7apLRm1pArEDgOIkmAMRb10MpIeXGtPmWgLG3PYWY5RNz9aZprXPM3OeYSpukTsVVQPFuPf2njEfUb3hbTMO4YqQN21dIsRTJNmk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775052081; c=relaxed/simple; bh=Z4WlmMfJ0XDGS7BS32s/UsiiKs7WV2opdSLaVHXL2x0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LTFq1iW2fK0ilMQp3ipVKTrg5YQO0DpaoHw3I5Qu14h0s1CyeW9SP83hlkvMTMuaja8FDW1CGA5mbJYLtUP7/JKp53C7zvaj3Q2wv9zQdrNsVpWSTkUN4K2fxLms8JRYoWxFpa3GFmg9KOVXKTpWFYJ2+IjgnKWQFqunQBz17Cc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=CkLNugw1; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CkLNugw1" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-c7424d91b2dso4320473a12.1 for ; Wed, 01 Apr 2026 07:01:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775052080; x=1775656880; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=4Of6IXR9kF08fb3y1GD1Duw1/k8Epn7khL83oxb2ObA=; b=CkLNugw1r+4em7BO186nX6SYSN2UfxFuc8ZhuHyZWYVdpfFfiFDewksp1+Qk57+aCE e+hMOejXl7bWL/0j8I4SEBR/NZDQng8GB9Hs9GtFx1iRyTxHqla7djJHNujDdknh2zsp k1DUcMYSdrWuQ5k59Z+7+AX4Mi0ff1cNmb3Y6T6xly90cpQ1KYCTxEamQw72d41ypv1M bg7qYaQo+YLuKhgsu3w/YrUdjTfT4iVljTfPcV24YddoDrr4VcRGb5+lHb2FALHZRn1l vgXy/BS6eTyiWitc/RCRvAmEpc1IWvpucPXCfpcqyyqPKzwQC68gvLJC/h8ixqSHLKpZ WnSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775052080; x=1775656880; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=4Of6IXR9kF08fb3y1GD1Duw1/k8Epn7khL83oxb2ObA=; b=mYZJ3nSJyy5CjhM2qS5ZnNWLeZlLQWWSc9NUqRWf/GES2Coh+XQMNhlqm60YR1kK2G GJnQa9Q9csJA05dzbwA+0kjhkHwabXdqy65ScuDz1U5Oqxmm5T+iQ6TsQNDSSjzTcjN0 KqfF4CxCaCjDRK1Fyqzm1mvA6U0jYL4DSnUQzYgSTTIterBeac8a0v2rmZQy895uBhBG zGhib0ucL/nfUvwbjjrOApEVsR99rOA6ilFaNhxNtHI/asoYqEywY2ed8xyHhXnGSTMn qx/Scxx7W4OWQP6W8ru8Xnf7Ku00xsW+ZnYt/3In/139JhPzHA1inR10uupLYMzeNsEq ZnSw== X-Forwarded-Encrypted: i=1; AJvYcCVj4rt1bCXyunIVak/x6thffjEt2J515/bG8YEGu9/jlNphHgnHV3nANAZDs2V13EItu4i5i7h9RbHFkII=@vger.kernel.org X-Gm-Message-State: AOJu0YzQwaO98LHWYC0fJQ0qvPBR1hs1MbRbwumG/hDC2HqQyQ6Kp2Ps pVyd4U0vXQso62Ntinu9LigmGouxaOmx8wTu8sTQIqljjStjT6IGIM9r/d+n8w0KCxFh1/zj3KX O+p1wOg== X-Received: from pfop13.prod.google.com ([2002:a05:6a00:b4d:b0:82c:6f5f:fa9]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:998e:b0:39c:787:f197 with SMTP id adf61e73a8af0-39ef7688196mr4030395637.36.1775052079691; Wed, 01 Apr 2026 07:01:19 -0700 (PDT) Date: Wed, 1 Apr 2026 07:01:18 -0700 In-Reply-To: <4334432d-982e-4450-9281-de739c25ebfd@linuxfoundation.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260319000842.1213426-2-hisamshar@gmail.com> <091f264f-21f1-464d-913a-1500643728c7@linuxfoundation.org> <137f63af-a993-4b1c-a9e9-931718a47343@linuxfoundation.org> <4334432d-982e-4450-9281-de739c25ebfd@linuxfoundation.org> Message-ID: Subject: Re: [PATCH] KVM: selftests: Guard execinfo.h inclusion for non-glibc builds From: Sean Christopherson To: Shuah Khan Cc: Hisam Mehboob , kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Aqib Faruqui , shuah@kernel.org, pbonzini@redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 availa= ble > > > > > in glibc but not in non-glibc C libraries such as musl. Building = KVM > > > > > selftests with musl-gcc fails with: > > > > >=20 > > > > > =C2=A0=C2=A0 lib/assert.c:9:10: fatal error: execinfo.h: No such = file or directory > > > > >=20 > > > > > Guard the inclusion of execinfo.h under #ifdef __GLIBC__, and wra= p > > > > > all backtrace() usage under the same guard with a fallback messag= e > > > > > for non-glibc builds indicating that stack traces are not availab= le. > > > > >=20 > > > > > Unlike the approach of adding a weak stub for backtrace(), this > > > > > explicitly handles the non-glibc case rather than silently provid= ing > > > > > an empty implementation. > > > > >=20 > > > > > Link: https://lore.kernel.org/kvm/20250829142556.72577-7- aqibaf@= amazon.com/ > > > > >=20 > > > > > Suggested-by: Aqib Faruqui > > > > > Signed-off-by: Hisam Mehboob > > > > > --- > > > > > =C2=A0 tools/testing/selftests/kvm/lib/assert.c | 7 +++++++ > > > > > =C2=A0 1 file changed, 7 insertions(+) > > > > >=20 > > > > > diff --git a/tools/testing/selftests/kvm/lib/assert.c b/tools/ te= sting/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 @@ > > > > > =C2=A0=C2=A0 */ > > > > > =C2=A0 #include "test_util.h" > > > > > +#ifdef __GLIBC__ > > > > > =C2=A0 #include > > > > > +#endif > > > > > Is __GLIBC__ defined in musl-gcc? Looks like that is the case wit= h the > > > > error? > > >=20 > > > If __GLIBC__ isn't there you shouldn't see this error because the inc= lude > > > is in - this error doesn't make sense if __GLIBC__ isn't defined. Wha= t > > > am I missing? > > >=20 > >=20 > > To clarify the compiler error you mentioned: the error log in the commi= t > > message shows the failure that occurs before this patch is applied. Bec= ause > > musl-gcc doesn't define __GLIBC__, the original unconditional > > inclusion causes the build to fail. The #ifdef in my patch was intended= to > > fix that exact failure. > >=20 > > > +#ifdef __GLIBC__ > > > =C2=A0=C2=A0#include > > > +#endif > > >=20 > > > Also check tools/testing/selftests/bpf/test_progs.c - I think backtra= ce() > > > stub needs be defined only for the !__GLIBC__ case > > >=20 > >=20 > > Looking at how bpf/test_progs.c handles it, I agree the weak stub appro= ach > > is much cleaner. I will implement it so that it still prints an explici= t > > warning message when a trace is unavailable. I disagree. _If_ we didn't need the __GLIBC__ #ifdef, then I would be in f= avor 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/selft= ests/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" =20 -#include #include =20 #include "kselftest.h" =20 +#ifdef __GLIBC__ +#include + /* 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 =20 static pid_t _gettid(void) {