From nobody Wed Apr 1 20:39:07 2026 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83E3E36308B for ; Wed, 1 Apr 2026 15:07:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775056054; cv=none; b=AF9VkIGqMgcET/qvKFBlS4Tvy8X+xoxSMknwJG6/wDeiU/iztSbf7lINHw6Ys5O6eCbSwEROSvuzjR4gxVfCTIvIFH6dMgjt6NOBhcUkk6UFEzeNO/mhOTNJDFTXmLXAWM+iv31+mNtsJ4+9fYjAaUW5X95DjFMRW00ZI9+TFIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775056054; c=relaxed/simple; bh=dj4a7yIFkUuuOErayl1USgUNCE2PkTOo08S0tvg3kp0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=j/jw9G0R+A5MSLRSENoyocOvNVGFIRbvSfZwM8j4HxHjnm10Lv3atZkNyU1pTzQ5fUHlXlVwWtJmhdhnZPSDueL7TzPVPfSMS/vDHCUYIAU7Qxt8vCUfXBrPZybLIKARka/mvngX9w7q/dGxgfu11eJ+6AnsQBY/cSLUBjNPM3w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=CsjUxl6O; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="CsjUxl6O" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1775056050; bh=dj4a7yIFkUuuOErayl1USgUNCE2PkTOo08S0tvg3kp0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=CsjUxl6ODSyH+kAcxLlp1LZhBvhjtanp4LyrBW960MEZMOW7xq3lgcGOcFLD/+SIw GSBoW8870dlWS75EKKeCrvLeYtgxjjFktjyxlKfnSCFYawgzgkcpBvLMTvsXxxvrCG xnYP79yyn8Ppj42XMv9RlhKVeFa9B1Qv3PStPVjE= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 01 Apr 2026 17:07:27 +0200 Subject: [PATCH 1/3] tools/nolibc: use __builtin_offsetof() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260401-nolibc-asprintf-v1-1-46292313439f@weissschuh.net> References: <20260401-nolibc-asprintf-v1-0-46292313439f@weissschuh.net> In-Reply-To: <20260401-nolibc-asprintf-v1-0-46292313439f@weissschuh.net> To: Willy Tarreau Cc: linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.15.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775056050; l=916; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=dj4a7yIFkUuuOErayl1USgUNCE2PkTOo08S0tvg3kp0=; b=BWOAmifYTfooOp/hwM6OaQMepahdTB3crDfRTQAdnSK8yi0GKvlRAW/uW281DpyEG3QN0yf8x wys5bOecVagCvaugEPWAIIVga4qFjvepx6CPNTyi5YY+V47nnHAhCZx X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The current custom implementation of offsetof() fails UBSAN: runtime error: member access within null pointer of type 'struct ...' This means that all its users, including container_of(), free() and realloc(), fail. Use __builtin_offsetof() instead which does not have this issue and has been available since GCC 4 and clang 4. Signed-off-by: Thomas Wei=C3=9Fschuh --- tools/include/nolibc/stddef.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/include/nolibc/stddef.h b/tools/include/nolibc/stddef.h index ecbd13eab1f5..a3976341afdd 100644 --- a/tools/include/nolibc/stddef.h +++ b/tools/include/nolibc/stddef.h @@ -18,7 +18,7 @@ #endif =20 #ifndef offsetof -#define offsetof(TYPE, FIELD) ((size_t) &((TYPE *)0)->FIELD) +#define offsetof(TYPE, FIELD) __builtin_offsetof(TYPE, FIELD) #endif =20 #endif /* _NOLIBC_STDDEF_H */ --=20 2.53.0 From nobody Wed Apr 1 20:39:07 2026 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83F3037AA72 for ; Wed, 1 Apr 2026 15:07:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775056054; cv=none; b=kMJ8UgyeQLyWxejsoKRO2WrlrfLpxoCq4dFAIhqEYfQLasMr8ih3UmL2MeP7JdpzWcp6i8TD9pt+bbsXHQKqzRFmiYUQGS5P79bVJwTt05Uva72EJlSVXO59ww8F/417/zmya7H2mLq8GEEQgSOCPwc36tmaM0mZbL11MDjt6/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775056054; c=relaxed/simple; bh=fpzsIRMbryf+nK9NF52ngLB8833ix8t2jhIwCD6eTfo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QpThJEnEWiBNk2TxNksMRe70WguCn73TAV+qDqXfUN6UUxnn8zobGIsCeieESN+sh7RLhzjgIm98O7zCRWbpwwDibyyvbOisgTD2iCkOYfzMJXlE1MwU1426+OPGjF0TQFKeNhJSgvSecMAndAU7w6KBaV3rMF1XuO8O+A+KExM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=CqZ856PW; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="CqZ856PW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1775056050; bh=fpzsIRMbryf+nK9NF52ngLB8833ix8t2jhIwCD6eTfo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=CqZ856PWKB3hlZZRGRGPIEkeFJ53DDA+YWzcVS+YkjGLdNlpjnsb9YfPx28ys1cop /CwwodAE1Rsp6ik1pu+WbfiGoieyRUlsX2+h2rBN9/eqON9rj7oyxRDDI8pfhnivu5 Jd+IyiVQN7h6L3pFlHszZ59IaWK1RxDX4WPLoc+w= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 01 Apr 2026 17:07:28 +0200 Subject: [PATCH 2/3] selftests/nolibc: test the memory allocator Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260401-nolibc-asprintf-v1-2-46292313439f@weissschuh.net> References: <20260401-nolibc-asprintf-v1-0-46292313439f@weissschuh.net> In-Reply-To: <20260401-nolibc-asprintf-v1-0-46292313439f@weissschuh.net> To: Willy Tarreau Cc: linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.15.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775056050; l=1453; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=fpzsIRMbryf+nK9NF52ngLB8833ix8t2jhIwCD6eTfo=; b=lPdWGbEtRNjnmFwczM13yT59bbmyt5sg4NsLKxMQb+OPKyZFVZX/qIH2tm/qG/QbOrzjs9PhO EwgZsxKa5zQBrdb9h8B+pSrJOEaCrgEBi+RdoFqc/uNtPOHyAe+ZDy7 X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The memory allocator has not seen any testing so far. Add a simple testcase for it. Signed-off-by: Thomas Wei=C3=9Fschuh --- tools/testing/selftests/nolibc/nolibc-test.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index 1efd10152e83..c888e13c6bd8 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1554,6 +1554,30 @@ int test_time_types(void) return 0; } =20 +int test_malloc(void) +{ + void *ptr1, *ptr2, *ptr3; + + ptr1 =3D malloc(100); + if (!ptr1) + return 1; + + ptr2 =3D realloc(ptr1, 200); + if (!ptr2) { + free(ptr1); + return 2; + } + + ptr3 =3D realloc(ptr2, 2 * getpagesize()); + if (!ptr3) { + free(ptr2); + return 3; + } + + free(ptr3); + return 0; +} + int run_stdlib(int min, int max) { int test; @@ -1680,6 +1704,7 @@ int run_stdlib(int min, int max) CASE_TEST(memchr_foobar6_o); EXPECT_STREQ(1, memchr("foobar", 'o'= , 6), "oobar"); break; CASE_TEST(memchr_foobar3_b); EXPECT_STRZR(1, memchr("foobar", 'b'= , 3)); break; CASE_TEST(time_types); EXPECT_ZR(is_nolibc, test_time_types= ()); break; + CASE_TEST(malloc); EXPECT_ZR(1, test_malloc()); break; =20 case __LINE__: return ret; /* must be last */ --=20 2.53.0 From nobody Wed Apr 1 20:39:07 2026 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB59A3914EE for ; Wed, 1 Apr 2026 15:07:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775056054; cv=none; b=jqgcGMWwMqaIubRbhi6sh4uSu0RkkBYYKHMgLTASj1wD0NkG/UUKPUXGtNJ/4z3DQq+H3AHm5q43Yp8LBnB+KrXmwzyKE5XkN8zdjBQLjuFsNSk7EBLD8nMm1we7VNyOYqURMb+vQFVLy1AW8ZCqc2d9LHSrTBX5CYlLApOJW+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775056054; c=relaxed/simple; bh=JekqylOBeeqBB6rFz7yuelSxcSQTDabaAxJ2sB62JgI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PU1alQaYgzok0p9ABw+wiY2f59RzXMIHuJUlESmPfXk+hhD0uFpLEm+CDu9QFd4SilXJTWc15VuMQm84vjunPxYabC11I0Lge9hjYJt9CQrQ+g1FajPb5pIZnsxlOn1ZXcH6OL266Sl/5BxsNSFqt+u30IlGqChLJls73MQMKi8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=Uk5YNa/W; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="Uk5YNa/W" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1775056050; bh=JekqylOBeeqBB6rFz7yuelSxcSQTDabaAxJ2sB62JgI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Uk5YNa/W0fZFxHfS3bbwYLYjaIBEL5b7IyeghELYTLz8VbahaayoopvQhzzbvr0q6 LWSyydlGe+Vsb/7nFbz30bprMOEr73i6f8ZeXI8Rxp1L/B5zq2B98nxFV7TtXpcKMu w6SSHQLQYbu4xnd80Qamccc3xHiIBujOAgpa4R0E= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 01 Apr 2026 17:07:29 +0200 Subject: [PATCH 3/3] tools/nolibc: add support for asprintf() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260401-nolibc-asprintf-v1-3-46292313439f@weissschuh.net> References: <20260401-nolibc-asprintf-v1-0-46292313439f@weissschuh.net> In-Reply-To: <20260401-nolibc-asprintf-v1-0-46292313439f@weissschuh.net> To: Willy Tarreau Cc: linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.15.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775056050; l=2880; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=JekqylOBeeqBB6rFz7yuelSxcSQTDabaAxJ2sB62JgI=; b=MEfJ2WrU+begf5tQW7IseLOQvzfGJfkoi32lBxafkM/FekxIy/h4atJwJ6MZxLlrJuvEgB9+7 CTyMSXNcvtWCP3DNuuwM6VsgYJUm4orMjnSQGi6N4oVbxcMm8Y0RCFi X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Add support for dynamically allocating formatted strings through asprintf() and vasprintf(). Signed-off-by: Thomas Wei=C3=9Fschuh --- tools/include/nolibc/stdio.h | 50 ++++++++++++++++++++++++= ++++ tools/testing/selftests/nolibc/nolibc-test.c | 24 +++++++++++++ 2 files changed, 74 insertions(+) diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h index 8f7e1948a651..1c9287b558f0 100644 --- a/tools/include/nolibc/stdio.h +++ b/tools/include/nolibc/stdio.h @@ -787,6 +787,56 @@ int sprintf(char *buf, const char *fmt, ...) return ret; } =20 +static __attribute__((unused, format(printf, 2, 0))) +int __nolibc_vasprintf(char **strp, const char *fmt, va_list args1, va_lis= t args2) +{ + char *buf; + int len; + + len =3D vsnprintf(NULL, 0, fmt, args1); + if (len < 0) + return -1; + + buf =3D malloc(len + 1); + if (!buf) + return -1; + + len =3D vsnprintf(buf, len + 1, fmt, args2); + if (len < 0) { + free(buf); + return -1; + } + + *strp =3D buf; + return len; +} + +static __attribute__((unused, format(printf, 2, 0))) +int vasprintf(char **strp, const char *fmt, va_list args) +{ + va_list args2; + int ret; + + va_copy(args2, args); + ret =3D __nolibc_vasprintf(strp, fmt, args, args2); + va_end(args2); + + return ret; +} + +static __attribute__((unused, format(printf, 2, 3))) +int asprintf(char **strp, const char *fmt, ...) +{ + va_list args; + int ret; + + va_start(args, fmt); + ret =3D vasprintf(strp, fmt, args); + va_end(args); + + return ret; +} + static __attribute__((unused)) int vsscanf(const char *str, const char *format, va_list args) { diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index c888e13c6bd8..98070b805e49 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1859,6 +1859,29 @@ static int test_printf_error(void) return 0; } =20 +int test_asprintf(void) +{ + char *str; + int ret; + + ret =3D asprintf(&str, "foo%s", "bar"); + if (ret =3D=3D -1) + return 1; + + if (ret !=3D 6) { + free(str); + return 2; + } + + if (memcmp(str, "foobar", 6) !=3D 0) { + free(str); + return 3; + } + + free(str); + return 0; +} + static int run_printf(int min, int max) { int test; @@ -1921,6 +1944,7 @@ static int run_printf(int min, int max) CASE_TEST(errno-neg); errno =3D -22; EXPECT_VFPRINTF(is_nolibc, "errn= o=3D-22 ", "%-12m"); break; CASE_TEST(scanf); EXPECT_ZR(1, test_scanf()); break; CASE_TEST(printf_error); EXPECT_ZR(1, test_printf_error()); break; + CASE_TEST(asprintf); EXPECT_ZR(1, test_asprintf()); break; case __LINE__: return ret; /* must be last */ /* note: do not set any defaults so as to permit holes above */ --=20 2.53.0