From patchwork Wed Aug 30 15:07:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13370483 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8293FC83F01 for ; Wed, 30 Aug 2023 18:37:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232799AbjH3ShQ (ORCPT ); Wed, 30 Aug 2023 14:37:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245304AbjH3PHX (ORCPT ); Wed, 30 Aug 2023 11:07:23 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [IPv6:2a01:4f8:c010:41de::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1DA01A4; Wed, 30 Aug 2023 08:07:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1693408036; bh=8FIja9IFIvy0ghblU2pMnjY5DcbONT7SKYZbKgOAbVY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=B4a8ElQ83YuPnV6polCeO4SrrT9XumGWQZUfyHL307vjC52fc0POVPfoLO1v8+ioU tZYfa/Xy/XC2H8ZFWxuHsQ+9sCA8jO+5coszHm2HiTsn3JrLcxufMGZo87ry+IlNzR kl7MQpTgsq24H+hprf3DZK7XRbG8t4ZrCtAn81ic= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 30 Aug 2023 17:07:12 +0200 Subject: [PATCH v2 1/2] tools/nolibc: add stdarg.h header MIME-Version: 1.0 Message-Id: <20230830-nolibc-nostdinc-v2-1-c5b1387b4a77@weissschuh.net> References: <20230830-nolibc-nostdinc-v2-0-c5b1387b4a77@weissschuh.net> In-Reply-To: <20230830-nolibc-nostdinc-v2-0-c5b1387b4a77@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: Zhangjin Wu , Yuan Tan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Th?= =?utf-8?q?omas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1693408035; l=3407; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=8FIja9IFIvy0ghblU2pMnjY5DcbONT7SKYZbKgOAbVY=; b=0H2FPq1DK3HALGiANLknXK96oNZsN2fGV3pIP3M0i55YkJEHHW3DeizcEAi2e/LBE7LCq8DvL Qcn32rg9lOMBd/I9wLuzSmTbUBzigjZM4QUHC/V9WVXJEK4+2zp6+EX X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org This allows nolic to work with `-nostdinc` avoiding any reliance on system headers. The implementation has been lifted from musl libc 1.2.4. There is already an implementation of stdarg.h in include/linux/stdarg.h but that is GPL licensed and therefore not suitable for nolibc. The used compiler builtins have been validated to be at least available since GCC 4.1.2 and clang 3.0.0. Signed-off-by: Thomas Weißschuh --- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/nolibc.h | 4 ++-- tools/include/nolibc/stdarg.h | 16 ++++++++++++++++ tools/include/nolibc/stdio.h | 3 +-- tools/include/nolibc/sys.h | 2 +- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 909b6eb500fe..e69c26abe1ea 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -34,6 +34,7 @@ all_files := \ signal.h \ stackprotector.h \ std.h \ + stdarg.h \ stdint.h \ stdlib.h \ string.h \ diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h index 1f8d821000ac..989e707263a4 100644 --- a/tools/include/nolibc/nolibc.h +++ b/tools/include/nolibc/nolibc.h @@ -74,10 +74,10 @@ * -I../nolibc -o hello hello.c -lgcc * * The available standard (but limited) include files are: - * ctype.h, errno.h, signal.h, stdio.h, stdlib.h, string.h, time.h + * ctype.h, errno.h, signal.h, stdarg.h, stdio.h, stdlib.h, string.h, time.h * * In addition, the following ones are expected to be provided by the compiler: - * float.h, stdarg.h, stddef.h + * float.h, stddef.h * * The following ones which are part to the C standard are not provided: * assert.h, locale.h, math.h, setjmp.h, limits.h diff --git a/tools/include/nolibc/stdarg.h b/tools/include/nolibc/stdarg.h new file mode 100644 index 000000000000..c628b5783da6 --- /dev/null +++ b/tools/include/nolibc/stdarg.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * Variadic argument support for NOLIBC + * Copyright (C) 2005-2020 Rich Felker, et al. + */ + +#ifndef _NOLIBC_STDARG_H +#define _NOLIBC_STDARG_H + +typedef __builtin_va_list va_list; +#define va_start(v, l) __builtin_va_start(v, l) +#define va_end(v) __builtin_va_end(v) +#define va_arg(v, l) __builtin_va_arg(v, l) +#define va_copy(d, s) __builtin_va_copy(d, s) + +#endif /* _NOLIBC_STDARG_H */ diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h index cae402c11e57..d7ef43973916 100644 --- a/tools/include/nolibc/stdio.h +++ b/tools/include/nolibc/stdio.h @@ -7,13 +7,12 @@ #ifndef _NOLIBC_STDIO_H #define _NOLIBC_STDIO_H -#include - #include "std.h" #include "arch.h" #include "errno.h" #include "types.h" #include "sys.h" +#include "stdarg.h" #include "stdlib.h" #include "string.h" diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index fdb6bd6c0e2f..b478750c9004 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -7,7 +7,6 @@ #ifndef _NOLIBC_SYS_H #define _NOLIBC_SYS_H -#include #include "std.h" /* system includes */ @@ -25,6 +24,7 @@ #include "arch.h" #include "errno.h" +#include "stdarg.h" #include "types.h" From patchwork Wed Aug 30 15:07:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13370568 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 056D4C83F17 for ; Wed, 30 Aug 2023 18:45:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238348AbjH3Shi (ORCPT ); Wed, 30 Aug 2023 14:37:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245303AbjH3PHX (ORCPT ); Wed, 30 Aug 2023 11:07:23 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A135B1A3; Wed, 30 Aug 2023 08:07:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1693408036; bh=Xgp/Sfptd9jpyjywWiXrXHLawX5jayOTlAK64aJOzLU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=QdEuQ+5ZOv6Rp138bQNGOc+hSqRvrIvmQ1DT6bRibhaEY+rnLvGJIztHA1Or2lEje n3jdgyOU1Xa7XvQz7L6yv3BBqds8jhu4FypaYeaAhmZ5E6OSAzAp3IRFpS/vjGN6jB hQdD+PPN1fzNGwnFuGzlJt437yeoP9LLXTduT1go= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 30 Aug 2023 17:07:13 +0200 Subject: [PATCH v2 2/2] selftests/nolibc: use -nostdinc for nolibc-test MIME-Version: 1.0 Message-Id: <20230830-nolibc-nostdinc-v2-2-c5b1387b4a77@weissschuh.net> References: <20230830-nolibc-nostdinc-v2-0-c5b1387b4a77@weissschuh.net> In-Reply-To: <20230830-nolibc-nostdinc-v2-0-c5b1387b4a77@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: Zhangjin Wu , Yuan Tan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Th?= =?utf-8?q?omas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1693408035; l=849; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=Xgp/Sfptd9jpyjywWiXrXHLawX5jayOTlAK64aJOzLU=; b=Dc9hL0LMEkss2c9eMh/RAVONEIMrf3J8gsydIve0CGvKGilsLpclGAtc2KbZYVcjbPCpWWaDl RLiKxBCKm0oCl057HRNlYqOjikFNnxz3TAgppEr3ibg5WU7EU7B1fhl X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Avoid any accidental reliance on system includes. Signed-off-by: Thomas Weißschuh --- tools/testing/selftests/nolibc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile index dfe66776a331..689658f81a19 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -170,7 +170,7 @@ sysroot/$(ARCH)/include: ifneq ($(NOLIBC_SYSROOT),0) nolibc-test: nolibc-test.c sysroot/$(ARCH)/include $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \ - -nostdlib -static -Isysroot/$(ARCH)/include $< -lgcc + -nostdlib -nostdinc -static -Isysroot/$(ARCH)/include $< -lgcc else nolibc-test: nolibc-test.c $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \