From nobody Mon Jun 15 10:48:44 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 B9CBC3CC9F3 for ; Thu, 9 Apr 2026 16:22:12 +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=1775751735; cv=none; b=OyijgIVVRx5/kv+uuO2dr7N1XNdAZUVDFp7bq5WQrw4wOMQnT7dNH+rDeH8vHPRsS8BZTSU0LMg8txJLyKDat4eqb7USE4W/QyDidfj5tK/X3rSM8Eyq7520ZoXa6aelvRd/fo28gj8DRozVm1I0xZCtuHeGoEgcQHl29aYC/Kg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775751735; c=relaxed/simple; bh=Hv/pZ6DSJgiwufoWqIEkUCDzCVhjx8wUXeYnUkhjLjo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=rbC++vU9ujAAOFynS8atKADIP+wI9fE5sxN+4qaTPtxb9CGiEFoq7DR6Mm/p5KX09ENZfAZERVcUBF/yIp5JgV/pHPk7pf83xmGCn63J/jU+h5ShfHSPuus9clo2YifHRymgFTIf3q2MfZBKCuSx8a++Klx12RX5czdBJ3U/I1Q= 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=uT81Z8LM; 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="uT81Z8LM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1775751729; bh=Hv/pZ6DSJgiwufoWqIEkUCDzCVhjx8wUXeYnUkhjLjo=; h=From:Date:Subject:To:Cc:From; b=uT81Z8LM/Bt3NjZdrQCFZHyxzTiUbwYi/z6I14cXdyQdN7aSIBG7MxLNYDd9AuUUU VsGeYfW5vB5lMgPp/XLmBsXajQHWOQysVw98mmU0tgzmY/LJ93RJzbM4/rvudxVcYd GC+zDQOKvLuY0aY3Vh/pMYCrlK2u2kI4ms917t5k= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 09 Apr 2026 18:22:08 +0200 Subject: [PATCH] tools/nolibc: add assert() and assert.h 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-assert-v1-1-42da8b367e23@weissschuh.net> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/yXMQQ5AMBBA0avIrDWphiZcRSzaGoxISQeRSO+uW L7F/zcwBkKGJrsh4ElMq08o8gzcZPyIgvpkUFJpWcpa+HUh64ThFO6iROuUKWSlrYHUbAEHur5 f2/3mw87o9ncCMT5MdTNUcQAAAA== X-Change-ID: 20260409-nolibc-assert-4ebc2a1056ba 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=1775751729; l=2351; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=Hv/pZ6DSJgiwufoWqIEkUCDzCVhjx8wUXeYnUkhjLjo=; b=8E/QePS5bvMJotmP8S+4rzoJYP+/7X5R3oEQsviIEYp8Gu+pSSPOXJqU9AvwNGKdvctFwpSid /JElBYTVxMrCcF9WVeDCvA5G8kCeFP/LXzif8ch8UXI1wMWFA5tdM/o X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Add the standard assert() macro from the assert.h header. Signed-off-by: Thomas Wei=C3=9Fschuh Acked-by: Willy Tarreau --- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/assert.h | 36 ++++++++++++++++++++++++++++++++++++ tools/include/nolibc/nolibc.h | 1 + 3 files changed, 38 insertions(+) diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 7455097cff69..f0e6e71e8335 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 \ + assert.h \ byteswap.h \ compiler.h \ crt.h \ diff --git a/tools/include/nolibc/assert.h b/tools/include/nolibc/assert.h new file mode 100644 index 000000000000..84ff8ad9ab07 --- /dev/null +++ b/tools/include/nolibc/assert.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * Assert for NOLIBC + * Copyright (C) 2026 Thomas Wei=C3=9Fschuh + */ + +/* make sure to include all global symbols */ +#include "nolibc.h" + +#ifndef _NOLIBC_ASSERT_H +#define _NOLIBC_ASSERT_H + +#include "errno.h" +#include "stdio.h" +#include "stdlib.h" + +#endif /* _NOLIBC_ASSERT_H */ + +/* NDEBUG needs to be evaluated on *each* inclusion */ +#ifdef assert +#undef assert +#endif + +#ifndef NDEBUG +#define assert(expr) \ +({ \ + if (!(expr)) { \ + fprintf(stderr, "%s: %s:%d: %s: Assertion `%s' failed.\n", \ + program_invocation_short_name, __FILE__, __LINE__, __func__, \ + #expr); \ + abort(); \ + } \ +}) +#else +#define assert(expr) ((void)0) +#endif diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h index f4120f65fe79..4b99795d7a65 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 "assert.h" =20 /* Used by programs to avoid std includes */ #define NOLIBC --- base-commit: 598b670af347bc8d998866b1e795e40a3bb168de change-id: 20260409-nolibc-assert-4ebc2a1056ba Best regards, -- =20 Thomas Wei=C3=9Fschuh