From nobody Mon Jun 15 10:51:47 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 A302A28469F for ; Thu, 9 Apr 2026 15:55:38 +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=1775750140; cv=none; b=ks65VGzLpMopxn7akYpFCdNgna7XXuKttvI1W9ncMpsLOiFOUvyOOOgkiOWv5GsdLXin2Tl4BjzA1x77ag6IwOanzhWSwDqIzBvDeErB/oo2307UVsCpbtlOvhv5qQju/Af3Dh/8vjmeSwbhUPNLR5JTKuwOA1D086KI6KWcW9Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775750140; c=relaxed/simple; bh=3SHG7POFDFimOOjR8HMqW+NMX/9QLUfUmL/a6cG1Uwo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=o1hjhQyJjY3W2jj/MMfqC5elcF/2hST6rpZpU+a6hrgi8d5wtoaFxgFwTn7nh7wvkuqG6xBeNYuItfyJJGqy06IR3Th5B+5pvlVugfAQS8PW09Qj6OJagts9lPIwgi8PrPuhtg/R3MH08WYfWoRuft3qVYqHhRdxojkORPOUyYA= 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=PM/RxTJe; 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="PM/RxTJe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1775750132; bh=3SHG7POFDFimOOjR8HMqW+NMX/9QLUfUmL/a6cG1Uwo=; h=From:Date:Subject:To:Cc:From; b=PM/RxTJeDXPFylSNTmaUP6JwQ6jVpx2A3LcUe/V2qfPnP0D3taCcjCLiN9Be4xa5k aI5smQuU+VxCnL5c58CA4vkdoQcjyGiumsEWUlwbinKS2HQQowGfspuXNVMyGr0aXm sjiOJmeBC+HMPZ7jaRAXxxhP0xcKXC0/wYJJCrHU= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 09 Apr 2026 17:55:28 +0200 Subject: [PATCH] tools/nolibc: add alloca() 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: <20260409-nolibc-alloca-v1-1-ed02f68dfaf9@weissschuh.net> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDIzMDEwNL3bz8nMykZN3EnJz85ERdA4NkM1MjC6CkcZoSUE9BUWpaZgXYvOh YCL+4NCkrNbkEZIhSbS0AjD46JHEAAAA= X-Change-ID: 20260409-nolibc-alloca-00c65280263f 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=1775750131; l=3444; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=3SHG7POFDFimOOjR8HMqW+NMX/9QLUfUmL/a6cG1Uwo=; b=64ggf9HdD5M1y6m4eU8JYTinAKOtkWr1pMd+zxfzZmLKc0gXiK1n3Wnifu0ob5qy1ySO0ICzL 0vB8a4BvfvQAJ1DKGNmkOtWnvztCO8N9qvOvVRcsaToIiT0mX70sxt2 X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Add the wide-used alloca() function. As it is highly machine and compiler dependent, just defer to the compiler builtin. This has been available since GCC 4 and clang 3. Signed-off-by: Thomas Wei=C3=9Fschuh Acked-by: Willy Tarreau --- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/alloca.h | 15 +++++++++++++++ tools/include/nolibc/nolibc.h | 1 + tools/testing/selftests/nolibc/nolibc-test.c | 14 ++++++++++++++ 4 files changed, 31 insertions(+) diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 7455097cff69..039ba9d59dfa 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -20,6 +20,7 @@ OUTPUT ?=3D $(CURDIR)/ architectures :=3D arm arm64 loongarch m68k mips powerpc riscv s390 sh spa= rc x86 arch_files :=3D arch.h $(addsuffix .h, $(addprefix arch-, $(architectures)= )) all_files :=3D \ + alloca.h \ byteswap.h \ compiler.h \ crt.h \ diff --git a/tools/include/nolibc/alloca.h b/tools/include/nolibc/alloca.h new file mode 100644 index 000000000000..448233a79e6e --- /dev/null +++ b/tools/include/nolibc/alloca.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * alloca() for NOLIBC + * Copyright (C) 2026 Thomas Wei=C3=9Fschuh + */ + +/* make sure to include all global symbols */ +#include "nolibc.h" + +#ifndef _NOLIBC_ALLOCA_H +#define _NOLIBC_ALLOCA_H + +#define alloca(size) __builtin_alloca(size) + +#endif /* _NOLIBC_ALLOCA_H */ diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h index f4120f65fe79..e93b9c18b48c 100644 --- a/tools/include/nolibc/nolibc.h +++ b/tools/include/nolibc/nolibc.h @@ -133,6 +133,7 @@ #include "err.h" #include "byteswap.h" #include "endian.h" +#include "alloca.h" =20 /* Used by programs to avoid std includes */ #define NOLIBC diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index d3c4facb54c0..cfb797bf416c 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -45,6 +45,7 @@ #include #include #include +#include =20 #pragma GCC diagnostic ignored "-Wmissing-prototypes" =20 @@ -1516,6 +1517,18 @@ int run_syscall(int min, int max) return ret; } =20 +int test_alloca(void) +{ + uint64_t *x; + + x =3D alloca(sizeof(*x)); + + *x =3D 0x1234; + __asm__ ("" : "+r" (x)); + + return *x - 0x1234; +} + int test_difftime(void) { if (difftime(200., 100.) !=3D 100.) @@ -1731,6 +1744,7 @@ int run_stdlib(int min, int max) CASE_TEST(toupper_noop); EXPECT_EQ(1, toupper('A'), 'A'); bre= ak; CASE_TEST(abs); EXPECT_EQ(1, abs(-10), 10); break; CASE_TEST(abs_noop); EXPECT_EQ(1, abs(10), 10); break; + CASE_TEST(alloca); EXPECT_ZR(1, test_alloca()); break; CASE_TEST(difftime); EXPECT_ZR(1, test_difftime()); break; 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; --- base-commit: 598b670af347bc8d998866b1e795e40a3bb168de change-id: 20260409-nolibc-alloca-00c65280263f Best regards, -- =20 Thomas Wei=C3=9Fschuh