From nobody Mon Feb 9 04:30:47 2026 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 EFF55C7EE43 for ; Mon, 12 Jun 2023 20:47:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236841AbjFLUr2 (ORCPT ); Mon, 12 Jun 2023 16:47:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232473AbjFLUqv (ORCPT ); Mon, 12 Jun 2023 16:46:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C8281BE8 for ; Mon, 12 Jun 2023 13:46:24 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9C60C62953 for ; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B93CC433EF; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602716; bh=zEjOj9DdUomfDLsrKXBstSrS7dzFFqc89ym3/GOXT1g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LE1LcIYwMJvI71eAa4GoeB4kWpGGfgWaTbiAYVXU0qUoCLzO5MmgqhfKK7P2GCkGC btl1nZaTARSST2jONdpLc4gyzl0eUp+GU+Bs6A04MhrE11HlApUNBKRYiCiH0J+etB dQ6SYNKsnA/8IKz+AsgVaDo8/NHDJqe5B1M7PVoW/xyA23SZ50QvTlDxbl1a5R+nCa YSOluy0GD5XhknNvzSU9rzNX0ydf4jSe/qv0wjeeDRXD8EtZzbjcZTlZbhFBLqOOJQ 1xfrhDRt/REVx1PmbXambLE7+1qCS9RI0uJmi3FYgVK0BgERrdYSqcmZtxwJrD3HO/ lvsDqhtAqjGtw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id AA609CE09E7; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Alexey Dobriyan , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 01/53] tools/nolibc: tests: use volatile to force stack smashing Date: Mon, 12 Jun 2023 13:44:22 -0700 Message-Id: <20230612204514.292087-1-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh Use a volatile pointer to write outside the buffer so the compiler can't optimize it away. Reported-by: Alexey Dobriyan Link: https://lore.kernel.org/lkml/c0584807-511c-4496-b062-1263ea38f349@p18= 3/ Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/testing/selftests/nolibc/nolibc-test.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index 21bacc928bf7..47013b78972e 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -667,17 +667,13 @@ int run_stdlib(int min, int max) return ret; } =20 -#if defined(__clang__) -__attribute__((optnone)) -#elif defined(__GNUC__) -__attribute__((optimize("O0"))) -#endif static int smash_stack(void) { char buf[100]; + volatile char *ptr =3D buf; =20 for (size_t i =3D 0; i < 200; i++) - buf[i] =3D 'P'; + ptr[i] =3D 'P'; =20 return 1; } --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 5F4D9C7EE43 for ; Mon, 12 Jun 2023 20:47:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237471AbjFLUrb (ORCPT ); Mon, 12 Jun 2023 16:47:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233679AbjFLUqx (ORCPT ); Mon, 12 Jun 2023 16:46:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6809A211C for ; Mon, 12 Jun 2023 13:46:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id ABCF0628F5 for ; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 143D4C4339B; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602716; bh=Ks2BcB2HxSbBY7mPbJIjN33LPo2/4OOsJWgK+op14zY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qKsK0qaswOjIPy/bfoiU2TOM1/2acMdTaVJYOdvnom0Yvol6riU4QsLoeVugqdzJd ytjj4vt8Zs/NSkQUQZ0cqq8s2ugQCzt0I02kbarHRczMelvrtC5C00E1Dh+S4sadFj loHr247JnuzICjBnjykJCDoYd/c1P0uUeA/BiuDfVufh1s1YbKL/nqCeU3sldQXakf HjpT3AJDXX44dDApGiDiSW7oQZUFZG+JoT1NTJROAmgJWAHftzC6+BUk60qN065crr yUacKFoSUeA5PETCpDvGWv98FFZXWYTzSNXeCgedrfEabEngh29Gbit/FY/OQsN4l8 61Kx7OOKqbAww== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id ACF14CE0563; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, Willy Tarreau , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , "Paul E . McKenney" Subject: [PATCH v2 nolibc 02/53] tools/nolibc: tests: fix build on non-c99 compliant compilers Date: Mon, 12 Jun 2023 13:44:23 -0700 Message-Id: <20230612204514.292087-2-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Willy Tarreau Commit 9735716830f2 ("tools/nolibc: tests: add test for -fstack-protector") brought a declaration inside the initialization statement of a for loop, which breaks the build on compilers that do not default to c99 compatibility, making it more difficult to validate that the lib still builds on such compilers. The fix is trivial, so let's move the declaration to the variables block of the function instead. No backport is needed. Cc: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/testing/selftests/nolibc/nolibc-test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index 47013b78972e..6f2f109569a3 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -671,8 +671,9 @@ static int smash_stack(void) { char buf[100]; volatile char *ptr =3D buf; + size_t i; =20 - for (size_t i =3D 0; i < 200; i++) + for (i =3D 0; i < 200; i++) ptr[i] =3D 'P'; =20 return 1; --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 1F2E8C7EE2F for ; Mon, 12 Jun 2023 20:47:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232230AbjFLUrg (ORCPT ); Mon, 12 Jun 2023 16:47:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231896AbjFLUqy (ORCPT ); Mon, 12 Jun 2023 16:46:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73D651FC1 for ; Mon, 12 Jun 2023 13:46:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BD9CF62B14 for ; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22CFBC433D2; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602716; bh=cN3q9iCF/gJ/uPtCwHUQPd6CHzRDYrNdYVOXcOrOK64=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jqJAR6cT6U5vORSu/lKpIHbxnWn4m/pIWbHlkeNzpTBxTFkJdovV1JOPilMWiMl1O duTEq89VRWTqGgBqAzCoFJo1UgJbtf91SlxQEzdtovckvGef3UrLFwxvnahYMEoBSo iCrWvfz0/pYDNZPsd7PvU40VZFk0bIOD0vdFTXz1/zcoUtF5+pY4EyrB9FkYSZAcTm jqjliWWDhhGei8kCVo27MVfhFfbBL1SCFi7/l6a0ttVs6eKb5VwMBD7qosMpjRB+MR f0NulZoYA2TplRnke1eXxQO7oUOUTfqzeDJDLpUDNledJVtK/FZvR7avJKgPirB7zu pZiuw0zReKz4w== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id AF9C3CE3A1D; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, Willy Tarreau , Vincent Dagonneau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 03/53] tools/nolibc: fix build of the test case using glibc Date: Mon, 12 Jun 2023 13:44:24 -0700 Message-Id: <20230612204514.292087-3-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Willy Tarreau Some extra tests for various integer types and limits were added by commit d1209597ff00 ("tools/nolibc: add tests for the integer limits in stdint.h"), but we forgot to retest with glibc. Stddef and stdint are now needed for the program to build there. Cc: Vincent Dagonneau Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/testing/selftests/nolibc/nolibc-test.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index 6f2f109569a3..1bafbd8da6af 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include #endif #endif --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 5AE32C7EE43 for ; Mon, 12 Jun 2023 20:47:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237573AbjFLUrj (ORCPT ); Mon, 12 Jun 2023 16:47:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234860AbjFLUqz (ORCPT ); Mon, 12 Jun 2023 16:46:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E9651FC3 for ; Mon, 12 Jun 2023 13:46:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D3D2C62B22 for ; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39158C4339C; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602716; bh=C0Q9VdND465nWzuW7Df4EbGHS4KOUK1apvejVVAdFFE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a6fYIoJGMAm3UTo2yCUg3fgy7OIk/4lbO/m4uQ+SBzI55BlWwzUSeTUQ+cGFjMAdj 44ZI6dKQ65olNT7ZqX4pTfbluehPWrbtlYjrRsei2mKkt9RctqwK4TD/vH51IYjBV2 BHPQiBJgrzivsCMsyrT5XyaJuBT2f2wAHec/mtlLxd4/awVHi4aXr3TdqzFJdqnAIq SF9WmLkwiIJcB8ubljzjIKj5Dos88OKP62o5nH1sC5IlgTmPxyk0fylzuVIytR3dIU mx/2S1gM5enhpoUd7TNnCTa7UNdVtgrmJ5GpBn0VcFPPOR0DhqUS2CLQv10yJPp/Ag cMiEj+pPyq9vw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id B1F69CE3A1E; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 04/53] tools/nolibc: add libc-test binary Date: Mon, 12 Jun 2023 13:44:25 -0700 Message-Id: <20230612204514.292087-4-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh This can be used to easily compare the behavior of nolibc to the system libc. Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/testing/selftests/nolibc/.gitignore | 1 + tools/testing/selftests/nolibc/Makefile | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/tools/testing/selftests/nolibc/.gitignore b/tools/testing/self= tests/nolibc/.gitignore index 4696df589d68..52f613cdad54 100644 --- a/tools/testing/selftests/nolibc/.gitignore +++ b/tools/testing/selftests/nolibc/.gitignore @@ -1,4 +1,5 @@ /initramfs/ +/libc-test /nolibc-test /run.out /sysroot/ diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selfte= sts/nolibc/Makefile index bbce57420465..0cbe13809b37 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -94,6 +94,7 @@ help: @echo " help this help" @echo " sysroot create the nolibc sysroot here (uses \$$ARCH)" @echo " nolibc-test build the executable (uses \$$CC and \$$CROSS_COMPI= LE)" + @echo " libc-test build an executable using the compiler's default li= bc instead" @echo " run-user runs the executable under QEMU (uses \$$ARCH, \$$TE= ST)" @echo " initramfs prepare the initramfs with nolibc-test" @echo " defconfig create a fresh new default config (uses \$$ARCH)" @@ -128,6 +129,9 @@ nolibc-test: nolibc-test.c sysroot/$(ARCH)/include $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \ -nostdlib -static -Isysroot/$(ARCH)/include $< -lgcc =20 +libc-test: nolibc-test.c + $(QUIET_CC)$(CC) -o $@ $< + # qemu user-land test run-user: nolibc-test $(Q)qemu-$(QEMU_ARCH) ./nolibc-test > "$(CURDIR)/run.out" || : @@ -159,6 +163,8 @@ clean: $(Q)rm -rf sysroot $(call QUIET_CLEAN, nolibc-test) $(Q)rm -f nolibc-test + $(call QUIET_CLEAN, libc-test) + $(Q)rm -f libc-test $(call QUIET_CLEAN, initramfs) $(Q)rm -rf initramfs $(call QUIET_CLEAN, run.out) --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 A4DA8C7EE2F for ; Mon, 12 Jun 2023 20:47:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237682AbjFLUrr (ORCPT ); Mon, 12 Jun 2023 16:47:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236764AbjFLUqz (ORCPT ); Mon, 12 Jun 2023 16:46:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BA202127 for ; Mon, 12 Jun 2023 13:46:27 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D954B62B2F for ; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43409C433A0; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602716; bh=thHRx3gNkEts77+ULbTuRFI/XccuwcFtR++swDbxeA8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IIyRNxNo1pgSe1Dn8b4snZ4lkloc99dpMH5LjxJD09XIZhMLinvsM6aCNqRkPudK9 iDAHvmG/6AKVDvCEEaoOihPjy7/15YbJKo4UJZPLk7qLz+EiR8cQPCqWNhs9VJNq+M DyC7HuB7mg4tENGb/XCHuiAB+yKXtEqsEZQWHFlX5zivcdMriGnVO38bKHjKAsLIx+ e79wp1RiRUOc06c36NOCJQ2nwemqKeTseG/dIYgsTkeYKnFuEGNW2iSm/HGVqP5Jbi a0JhheIZMYY77d+ZPR6ysl8Z43aBXyTMPusrR4QclpuA9gvqlDq7ydPOiWtvdQmID4 wFvHN6MFlWm0g== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id B4267CE3A22; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 05/53] tools/nolibc: add wrapper for memfd_create Date: Mon, 12 Jun 2023 13:44:26 -0700 Message-Id: <20230612204514.292087-5-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh This is useful for users and will also be used by a future testcase. Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/sys.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 5d624dc63a42..bea9760dbd16 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -1365,6 +1365,29 @@ ssize_t write(int fd, const void *buf, size_t count) return ret; } =20 + +/* + * int memfd_create(const char *name, unsigned int flags); + */ + +static __attribute__((unused)) +int sys_memfd_create(const char *name, unsigned int flags) +{ + return my_syscall2(__NR_memfd_create, name, flags); +} + +static __attribute__((unused)) +int memfd_create(const char *name, unsigned int flags) +{ + ssize_t ret =3D sys_memfd_create(name, flags); + + if (ret < 0) { + SET_ERRNO(-ret); + ret =3D -1; + } + return ret; +} + /* make sure to include all global symbols */ #include "nolibc.h" =20 --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 408CFC7EE43 for ; Mon, 12 Jun 2023 20:47:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232681AbjFLUrn (ORCPT ); Mon, 12 Jun 2023 16:47:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236810AbjFLUq4 (ORCPT ); Mon, 12 Jun 2023 16:46:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC8D2212D for ; Mon, 12 Jun 2023 13:46:27 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3A5D862BE6 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66E8EC4339E; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602716; bh=fkkJpit5a3ZlIC5i/D5UeQi47Yy3csUMhtA5gdos6Dc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PmeopVKP2WJ1NEq6kcgJClk7k0JMV+ne7n8eOyk24uxhoBlYQ6lwWJyLOvbrsm/91 cnNp9KRqzC7cWHAldCR8BbCGoFTukelLxJ8Em6+4Z8pshSIbpXYAYaXW6anrqAuPo/ GbDgEF7AvgY0ufDwZ+UEhqf3ks2Qo9Ws8yNnb+VL2Sc6EndEHEuywqDCGfeUJdMBpc 6B32RYs+Qe+8rp5cQCUHzlcRzzQVlvAG2qxC9q2/f/HHGfg+tETPFqyeBKhe9f2vvL EA+osJnQcCeSSUdqEXgXVCnFPH5/fjIJRdLo3kRs0zGKJLcnu94qklxGvJ4zSyntcT jUTR6N2nvuCrg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id B65BECE3A3B; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 06/53] tools/nolibc: implement fd-based FILE streams Date: Mon, 12 Jun 2023 13:44:27 -0700 Message-Id: <20230612204514.292087-6-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh This enables the usage of the stream APIs with arbitrary filedescriptors. It will be used by a future testcase. Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/stdio.h | 95 ++++++++++++++++++++++++++---------- 1 file changed, 68 insertions(+), 27 deletions(-) diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h index 6cbbb52836a0..0eef91daf289 100644 --- a/tools/include/nolibc/stdio.h +++ b/tools/include/nolibc/stdio.h @@ -21,17 +21,75 @@ #define EOF (-1) #endif =20 -/* just define FILE as a non-empty type */ +/* just define FILE as a non-empty type. The value of the pointer gives + * the FD: FILE=3D~fd for fd>=3D0 or NULL for fd<0. This way positive FILE + * are immediately identified as abnormal entries (i.e. possible copies + * of valid pointers to something else). + */ typedef struct FILE { char dummy[1]; } FILE; =20 -/* We define the 3 common stdio files as constant invalid pointers that - * are easily recognized. - */ -static __attribute__((unused)) FILE* const stdin =3D (FILE*)-3; -static __attribute__((unused)) FILE* const stdout =3D (FILE*)-2; -static __attribute__((unused)) FILE* const stderr =3D (FILE*)-1; +static __attribute__((unused)) FILE* const stdin =3D (FILE*)(intptr_t)~ST= DIN_FILENO; +static __attribute__((unused)) FILE* const stdout =3D (FILE*)(intptr_t)~ST= DOUT_FILENO; +static __attribute__((unused)) FILE* const stderr =3D (FILE*)(intptr_t)~ST= DERR_FILENO; + +/* provides a FILE* equivalent of fd. The mode is ignored. */ +static __attribute__((unused)) +FILE *fdopen(int fd, const char *mode __attribute__((unused))) +{ + if (fd < 0) { + SET_ERRNO(EBADF); + return NULL; + } + return (FILE*)(intptr_t)~fd; +} + +/* provides the fd of stream. */ +static __attribute__((unused)) +int fileno(FILE *stream) +{ + intptr_t i =3D (intptr_t)stream; + + if (i >=3D 0) { + SET_ERRNO(EBADF); + return -1; + } + return ~i; +} + +/* flush a stream. */ +static __attribute__((unused)) +int fflush(FILE *stream) +{ + intptr_t i =3D (intptr_t)stream; + + /* NULL is valid here. */ + if (i > 0) { + SET_ERRNO(EBADF); + return -1; + } + + /* Don't do anything, nolibc does not support buffering. */ + return 0; +} + +/* flush a stream. */ +static __attribute__((unused)) +int fclose(FILE *stream) +{ + intptr_t i =3D (intptr_t)stream; + + if (i >=3D 0) { + SET_ERRNO(EBADF); + return -1; + } + + if (close(~i)) + return EOF; + + return 0; +} =20 /* getc(), fgetc(), getchar() */ =20 @@ -41,14 +99,8 @@ static __attribute__((unused)) int fgetc(FILE* stream) { unsigned char ch; - int fd; =20 - if (stream < stdin || stream > stderr) - return EOF; - - fd =3D 3 + (long)stream; - - if (read(fd, &ch, 1) <=3D 0) + if (read(fileno(stream), &ch, 1) <=3D 0) return EOF; return ch; } @@ -68,14 +120,8 @@ static __attribute__((unused)) int fputc(int c, FILE* stream) { unsigned char ch =3D c; - int fd; - - if (stream < stdin || stream > stderr) - return EOF; - - fd =3D 3 + (long)stream; =20 - if (write(fd, &ch, 1) <=3D 0) + if (write(fileno(stream), &ch, 1) <=3D 0) return EOF; return ch; } @@ -96,12 +142,7 @@ static __attribute__((unused)) int _fwrite(const void *buf, size_t size, FILE *stream) { ssize_t ret; - int fd; - - if (stream < stdin || stream > stderr) - return EOF; - - fd =3D 3 + (long)stream; + int fd =3D fileno(stream); =20 while (size) { ret =3D write(fd, buf, size); --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 3AB69C88CB2 for ; Mon, 12 Jun 2023 20:47:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237034AbjFLUrz (ORCPT ); Mon, 12 Jun 2023 16:47:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232399AbjFLUq5 (ORCPT ); Mon, 12 Jun 2023 16:46:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96125268A for ; Mon, 12 Jun 2023 13:46:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4C19662E51 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B0AAC433A7; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602716; bh=gpgpcEtunmdu9Bwe6EgvPNpLf5lDxIDNN1gL/ShrEz4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UKi7Ip0YKj3ZCMbDJ6qFgh7yQ1pabyK6igSPYEUX1TvERq8WM1fdqzMMVZobOyU4W qFVLkTH7HZv/uhFztJitULPsa5203YsV3xYKJD5pq35Xsz0g58cRcY+J3kBL37Q9gp WgjpUd2Xj57QjBvbhfFDDyOxSe+EksgLdYBus8NJQk4giUqyuisKnZIzzmiJhh3/DT rK9tIJ2+I072wuaJHeVsG6S9d7G+R8wPk7Sqks86CKMGjLBvKvYhGdW5IGR53mOb23 asYAXtlqBP++m/fjkA76taODg0ObJehQ3PVOrUqiW5gtKWIRedwVmE0FbtIMIQ4bnn RzGPZIDjuV+Iw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id B888ACE3A41; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 07/53] tools/nolibc: add testcases for vfprintf Date: Mon, 12 Jun 2023 13:44:28 -0700 Message-Id: <20230612204514.292087-7-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh vfprintf() is complex and so far did not have proper tests. Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/testing/selftests/nolibc/nolibc-test.c | 86 ++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index 1bafbd8da6af..888da60eb5ba 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -669,6 +670,90 @@ int run_stdlib(int min, int max) return ret; } =20 +#define EXPECT_VFPRINTF(c, expected, fmt, ...) \ + ret +=3D expect_vfprintf(llen, c, expected, fmt, ##__VA_ARGS__) + +static int expect_vfprintf(int llen, size_t c, const char *expected, const= char *fmt, ...) +{ + int ret, fd, w, r; + char buf[100]; + FILE *memfile; + va_list args; + + fd =3D memfd_create("vfprintf", 0); + if (fd =3D=3D -1) { + pad_spc(llen, 64, "[FAIL]\n"); + return 1; + } + + memfile =3D fdopen(fd, "w+"); + if (!memfile) { + pad_spc(llen, 64, "[FAIL]\n"); + return 1; + } + + va_start(args, fmt); + w =3D vfprintf(memfile, fmt, args); + va_end(args); + + if (w !=3D c) { + llen +=3D printf(" written(%d) !=3D %d", w, (int) c); + pad_spc(llen, 64, "[FAIL]\n"); + return 1; + } + + fflush(memfile); + lseek(fd, 0, SEEK_SET); + + r =3D read(fd, buf, sizeof(buf) - 1); + buf[r] =3D '\0'; + + fclose(memfile); + + if (r !=3D w) { + llen +=3D printf(" written(%d) !=3D read(%d)", w, r); + pad_spc(llen, 64, "[FAIL]\n"); + return 1; + } + + llen +=3D printf(" \"%s\" =3D \"%s\"", expected, buf); + ret =3D strncmp(expected, buf, c); + + pad_spc(llen, 64, ret ? "[FAIL]\n" : " [OK]\n"); + return ret; +} + +static int run_vfprintf(int min, int max) +{ + int test; + int tmp; + int ret =3D 0; + void *p1, *p2; + + for (test =3D min; test >=3D 0 && test <=3D max; test++) { + int llen =3D 0; // line length + + /* avoid leaving empty lines below, this will insert holes into + * test numbers. + */ + switch (test + __LINE__ + 1) { + CASE_TEST(empty); EXPECT_VFPRINTF(0, "", ""); break; + CASE_TEST(simple); EXPECT_VFPRINTF(3, "foo", "foo"); break; + CASE_TEST(string); EXPECT_VFPRINTF(3, "foo", "%s", "foo"); break; + CASE_TEST(number); EXPECT_VFPRINTF(4, "1234", "%d", 1234); break; + CASE_TEST(negnumber); EXPECT_VFPRINTF(5, "-1234", "%d", -1234); break; + CASE_TEST(unsigned); EXPECT_VFPRINTF(5, "12345", "%u", 12345); break; + CASE_TEST(char); EXPECT_VFPRINTF(1, "c", "%c", 'c'); break; + CASE_TEST(hex); EXPECT_VFPRINTF(1, "f", "%x", 0xf); break; + CASE_TEST(pointer); EXPECT_VFPRINTF(3, "0x1", "%p", (void *) 0x1); = break; + case __LINE__: + return ret; /* must be last */ + /* note: do not set any defaults so as to permit holes above */ + } + } + return ret; +} + static int smash_stack(void) { char buf[100]; @@ -777,6 +862,7 @@ static const struct test test_names[] =3D { /* add new tests here */ { .name =3D "syscall", .func =3D run_syscall }, { .name =3D "stdlib", .func =3D run_stdlib }, + { .name =3D "vfprintf", .func =3D run_vfprintf }, { .name =3D "protection", .func =3D run_protection }, { 0 } }; --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 4BD50C88CB2 for ; Mon, 12 Jun 2023 20:47:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235620AbjFLUru (ORCPT ); Mon, 12 Jun 2023 16:47:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235728AbjFLUq5 (ORCPT ); Mon, 12 Jun 2023 16:46:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 339642136 for ; Mon, 12 Jun 2023 13:46:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 488AF62BE7 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B055C433A4; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602716; bh=jzpYLjEQ1FslRejmeBHfDXFdJyRjrM8plGg590LqYRA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U9vW3AFRclszObUvNLAm+ePi9P+liWKoXayNX7uV/LvNTgdPic7sz0zzwoKP3V9I9 tBJE2YMEPnZoXJ2VrFlmmxhqYHX1ZQ7BtLnmAyOxDDquFieMvXFhmkTRaZdtCH1P/2 fNnd5K2xvnS9tN3y17DR893eJ5t1ZnaHvWfh4/8tA9ielv3sAwgvEj6L8VMIVU4dKp Vl72HWnUiz5nyD8gH+Zm4idD5T7jmDhEtsj1yvvtVu2JiqQeELU4qvn1s4ptWEz+gE dMsd9dstt9OT8p3CrM5L3C3CAZQMEMJmCHe7fHcDgqrfZLiPGsHHlfLYoidMtD2HMC e8N4f5Sj7g6JQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id BAB9ACE3A42; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, Mark Brown , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 08/53] tools/nolibc: Fix build of stdio.h due to header ordering Date: Mon, 12 Jun 2023 13:44:29 -0700 Message-Id: <20230612204514.292087-8-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Mark Brown When we added fd based file streams we created references to STx_FILENO in stdio.h but these constants are declared in unistd.h which is the last file included by the top level nolibc.h meaning those constants are not defined when we try to build stdio.h. This causes programs using nolibc.h to fail to build. Reorder the headers to avoid this issue. Fixes: d449546c957f ("tools/nolibc: implement fd-based FILE streams") Signed-off-by: Mark Brown Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/nolibc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h index 04739a6293c4..05a228a6ee78 100644 --- a/tools/include/nolibc/nolibc.h +++ b/tools/include/nolibc/nolibc.h @@ -99,11 +99,11 @@ #include "sys.h" #include "ctype.h" #include "signal.h" +#include "unistd.h" #include "stdio.h" #include "stdlib.h" #include "string.h" #include "time.h" -#include "unistd.h" #include "stackprotector.h" =20 /* Used by programs to avoid std includes */ --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 E3B74C88CB5 for ; Mon, 12 Jun 2023 20:48:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231586AbjFLUr7 (ORCPT ); Mon, 12 Jun 2023 16:47:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236284AbjFLUq5 (ORCPT ); Mon, 12 Jun 2023 16:46:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1B5B26AD for ; Mon, 12 Jun 2023 13:46:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5155462E42 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D848C433A8; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602716; bh=gd5sfN1vi5rnkiQ19By4Dp4+vXMweeEIcbPWx+T5fUQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iVs7ROr0TZZJk5hr4p7bgRe7Ixi61cLbu+KRjwMiHHTow/NC+eOTRiyA8L5Jt/Wl7 b16b2/iOAaHRDgCCRdAwcJ3fObzTGPrkJX5QugC2mQ8XHdvXGw5oVm5DPfy7/W/WqO nBM2PR0TFpfs35JkZvRYTijzun9NnHmKTScDWeuldOVRecI1Y9uCYmOAJ3JI/OlJgW TzQuYe3l7iG9fUrnGVr/inL+csVTq6ixmZhCKaOzl5E5B1cJDWv+hhv7gcNv8lSAdi MvjBDBqSYW6ZTj+AFRZ+vB0pKWIO9hDRZPeoeStrFEMHilbHEtgG3C8GhEefLxHZtE oACspl2wu0gsw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id BCFA9CE3A49; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 09/53] tools/nolibc: use standard __asm__ statements Date: Mon, 12 Jun 2023 13:44:30 -0700 Message-Id: <20230612204514.292087-9-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh Most of the code was migrated to C99-conformant __asm__ statements before. It seems string.h was missed. Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/string.h | 4 ++-- tools/testing/selftests/nolibc/nolibc-test.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/include/nolibc/string.h b/tools/include/nolibc/string.h index fffdaf6ff467..0c2e06c7c477 100644 --- a/tools/include/nolibc/string.h +++ b/tools/include/nolibc/string.h @@ -90,7 +90,7 @@ void *memset(void *dst, int b, size_t len) =20 while (len--) { /* prevent gcc from recognizing memset() here */ - asm volatile(""); + __asm__ volatile(""); *(p++) =3D b; } return dst; @@ -139,7 +139,7 @@ size_t strlen(const char *str) size_t len; =20 for (len =3D 0; str[len]; len++) - asm(""); + __asm__(""); return len; } =20 diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index 888da60eb5ba..e692be98973a 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -984,7 +984,7 @@ int main(int argc, char **argv, char **envp) #else else if (ioperm(0x501, 1, 1) =3D=3D 0) #endif - asm volatile ("outb %%al, %%dx" :: "d"(0x501), "a"(0)); + __asm__ volatile ("outb %%al, %%dx" :: "d"(0x501), "a"(0)); /* if it does nothing, fall back to the regular panic */ #endif } --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 9D308C7EE2F for ; Mon, 12 Jun 2023 20:48:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237796AbjFLUsC (ORCPT ); Mon, 12 Jun 2023 16:48:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235868AbjFLUq6 (ORCPT ); Mon, 12 Jun 2023 16:46:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E823426B0 for ; Mon, 12 Jun 2023 13:46:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5D72B62ED6 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 86B58C433AC; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602716; bh=rJ8Zak39w7CtOYLtgafcmk/YeBO+i/iIqJ6y3UtNwdo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rZ+mTlhmRBd5hNyKaf7X0M7PtkE9osT1W3pDsVzygd+Y85/ftwauPhtnHoEPchJ23 BkGL6D2G/c93qHi1+iP5M5Lcq9dBmlqwS9YgyX3wT14sitm4sLLF+zdzntyjKUdkmu a4DHtrvFaGCJub0ze1hqiwDnmFphwxRuvLTKQ0F+r3/6WT6uV+7sNms5K2fri1M8FI rZP97iDAR9LsYNQ0tDjExteIbyoktZSH3v7kVwCZZ+cpfJAoDK9aHVqedsMsIf74Bp dUEUBHrUg4Goe4rpw+R0Y0qB6oikvybpC1QwDjk9dTgyGL4K9+EJJzKkqrbyXcNtUW CjRNae30NWuyg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id BF3B6CE3A4B; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 10/53] tools/nolibc: use __inline__ syntax Date: Mon, 12 Jun 2023 13:44:31 -0700 Message-Id: <20230612204514.292087-10-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh When building in strict C89 mode the "inline" keyword is unknown. While "__inline__" is non-standard it is used by the kernel headers themselves. So the used compilers would have to support it or the users shim it with a #define. Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/stdlib.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/include/nolibc/stdlib.h b/tools/include/nolibc/stdlib.h index 894c955d027e..902162f80337 100644 --- a/tools/include/nolibc/stdlib.h +++ b/tools/include/nolibc/stdlib.h @@ -102,7 +102,7 @@ char *_getenv(const char *name, char **environ) return NULL; } =20 -static inline __attribute__((unused,always_inline)) +static __inline__ __attribute__((unused,always_inline)) char *getenv(const char *name) { extern char **environ; @@ -231,7 +231,7 @@ int utoh_r(unsigned long in, char *buffer) /* converts unsigned long to an hex string using the static itoa_buff= er * and returns the pointer to that string. */ -static inline __attribute__((unused)) +static __inline__ __attribute__((unused)) char *utoh(unsigned long in) { utoh_r(in, itoa_buffer); @@ -293,7 +293,7 @@ int itoa_r(long in, char *buffer) /* for historical compatibility, same as above but returns the pointer to = the * buffer. */ -static inline __attribute__((unused)) +static __inline__ __attribute__((unused)) char *ltoa_r(long in, char *buffer) { itoa_r(in, buffer); @@ -303,7 +303,7 @@ char *ltoa_r(long in, char *buffer) /* converts long integer to a string using the static itoa_buffer and * returns the pointer to that string. */ -static inline __attribute__((unused)) +static __inline__ __attribute__((unused)) char *itoa(long in) { itoa_r(in, itoa_buffer); @@ -313,7 +313,7 @@ char *itoa(long in) /* converts long integer to a string using the static itoa_buffer and * returns the pointer to that string. Same as above, for compatibility. */ -static inline __attribute__((unused)) +static __inline__ __attribute__((unused)) char *ltoa(long in) { itoa_r(in, itoa_buffer); @@ -323,7 +323,7 @@ char *ltoa(long in) /* converts unsigned long integer to a string using the static itoa_b= uffer * and returns the pointer to that string. */ -static inline __attribute__((unused)) +static __inline__ __attribute__((unused)) char *utoa(unsigned long in) { utoa_r(in, itoa_buffer); @@ -367,7 +367,7 @@ int u64toh_r(uint64_t in, char *buffer) /* converts uint64_t to an hex string using the static itoa_buffer and * returns the pointer to that string. */ -static inline __attribute__((unused)) +static __inline__ __attribute__((unused)) char *u64toh(uint64_t in) { u64toh_r(in, itoa_buffer); @@ -429,7 +429,7 @@ int i64toa_r(int64_t in, char *buffer) /* converts int64_t to a string using the static itoa_buffer and retu= rns * the pointer to that string. */ -static inline __attribute__((unused)) +static __inline__ __attribute__((unused)) char *i64toa(int64_t in) { i64toa_r(in, itoa_buffer); @@ -439,7 +439,7 @@ char *i64toa(int64_t in) /* converts uint64_t to a string using the static itoa_buffer and ret= urns * the pointer to that string. */ -static inline __attribute__((unused)) +static __inline__ __attribute__((unused)) char *u64toa(uint64_t in) { u64toa_r(in, itoa_buffer); --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 5DD12C88CB2 for ; Mon, 12 Jun 2023 20:48:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237705AbjFLUsK (ORCPT ); Mon, 12 Jun 2023 16:48:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236849AbjFLUrA (ORCPT ); Mon, 12 Jun 2023 16:47:00 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2875F26B1 for ; Mon, 12 Jun 2023 13:46:29 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6315662ED7 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8AD54C433AE; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602716; bh=EWN17qREk8YC1MUcrW1F8VdO7n3Z0vTPmJeNoge1tUA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lBdMI4IEsReS6lw0j9yEgZ4SBNdenZo/YroqOKNKNDmqz5iUI8RDgcy3chvgHp8i9 RNch6iHYgBEMvvLioOldc8oVprZ1AVBuEbq8cIsq+boishEIPvTIXdK53vHCsWq5gG lWDyQoeGfdpYHIkmPK2Fhx/lAfNFpEzH0IH0k8z4jOmGR0tWsE9+HRhcNfp2l9LxAj Uz06gU/hXS8p7x2xFeCqZczng23rlND0E1PyqTcuUP1y+dxC2+FcUAGtqyA6W24dbe aVBw8mgrd3Fb5bSNPjIid1wlwPvh3RyhmTZPfVYQzA/njeiWYQt1IRdJR2qsWgNKeR 8vTaLDXMJUxEg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id C1EDFCE3A4F; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 11/53] tools/nolibc: use C89 comment syntax Date: Mon, 12 Jun 2023 13:44:32 -0700 Message-Id: <20230612204514.292087-11-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh Most of nolibc is already using C89 comments. Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/arch-aarch64.h | 32 +++++------ tools/include/nolibc/arch-arm.h | 44 +++++++-------- tools/include/nolibc/arch-i386.h | 40 +++++++------- tools/include/nolibc/arch-loongarch.h | 38 ++++++------- tools/include/nolibc/arch-mips.h | 56 ++++++++++---------- tools/include/nolibc/arch-riscv.h | 40 +++++++------- tools/include/nolibc/arch-s390.h | 2 +- tools/include/nolibc/arch-x86_64.h | 34 ++++++------ tools/include/nolibc/stackprotector.h | 4 +- tools/include/nolibc/sys.h | 8 +-- tools/testing/selftests/nolibc/nolibc-test.c | 12 ++--- 11 files changed, 155 insertions(+), 155 deletions(-) diff --git a/tools/include/nolibc/arch-aarch64.h b/tools/include/nolibc/arc= h-aarch64.h index 383baddef701..76ef26520c85 100644 --- a/tools/include/nolibc/arch-aarch64.h +++ b/tools/include/nolibc/arch-aarch64.h @@ -176,24 +176,24 @@ const unsigned long *_auxv __attribute__((weak)); void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(= void) { __asm__ volatile ( - "ldr x0, [sp]\n" // argc (x0) was in the stack - "add x1, sp, 8\n" // argv (x1) =3D sp - "lsl x2, x0, 3\n" // envp (x2) =3D 8*argc ... - "add x2, x2, 8\n" // + 8 (skip null) - "add x2, x2, x1\n" // + argv - "adrp x3, environ\n" // x3 =3D &environ (high bits) - "str x2, [x3, #:lo12:environ]\n" // store envp into environ - "mov x4, x2\n" // search for auxv (follows NULL after last env) + "ldr x0, [sp]\n" /* argc (x0) was in the stack = */ + "add x1, sp, 8\n" /* argv (x1) =3D sp = */ + "lsl x2, x0, 3\n" /* envp (x2) =3D 8*argc ... = */ + "add x2, x2, 8\n" /* + 8 (skip null) = */ + "add x2, x2, x1\n" /* + argv = */ + "adrp x3, environ\n" /* x3 =3D &environ (high bits) = */ + "str x2, [x3, #:lo12:environ]\n" /* store envp into environ = */ + "mov x4, x2\n" /* search for auxv (follows NULL after last env) = */ "0:\n" - "ldr x5, [x4], 8\n" // x5 =3D *x4; x4 +=3D 8 - "cbnz x5, 0b\n" // and stop at NULL after last env - "adrp x3, _auxv\n" // x3 =3D &_auxv (high bits) - "str x4, [x3, #:lo12:_auxv]\n" // store x4 into _auxv - "and sp, x1, -16\n" // sp must be 16-byte aligned in the callee - "bl main\n" // main() returns the status code, we'll exit with = it. - "mov x8, 93\n" // NR_exit =3D=3D 93 + "ldr x5, [x4], 8\n" /* x5 =3D *x4; x4 +=3D 8 = */ + "cbnz x5, 0b\n" /* and stop at NULL after last env = */ + "adrp x3, _auxv\n" /* x3 =3D &_auxv (high bits) = */ + "str x4, [x3, #:lo12:_auxv]\n" /* store x4 into _auxv = */ + "and sp, x1, -16\n" /* sp must be 16-byte aligned in the callee = */ + "bl main\n" /* main() returns the status code, we'll exit with = it. */ + "mov x8, 93\n" /* NR_exit =3D=3D 93 = */ "svc #0\n" ); __builtin_unreachable(); } -#endif // _NOLIBC_ARCH_AARCH64_H +#endif /* _NOLIBC_ARCH_AARCH64_H */ diff --git a/tools/include/nolibc/arch-arm.h b/tools/include/nolibc/arch-ar= m.h index 42499f23e73c..2eab1aef321b 100644 --- a/tools/include/nolibc/arch-arm.h +++ b/tools/include/nolibc/arch-arm.h @@ -203,34 +203,34 @@ const unsigned long *_auxv __attribute__((weak)); void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(= void) { __asm__ volatile ( - "pop {%r0}\n" // argc was in the stack - "mov %r1, %sp\n" // argv =3D sp + "pop {%r0}\n" /* argc was in the stack = */ + "mov %r1, %sp\n" /* argv =3D sp = */ =20 - "add %r2, %r0, $1\n" // envp =3D (argc + 1) ... - "lsl %r2, %r2, $2\n" // * 4 ... - "add %r2, %r2, %r1\n" // + argv - "ldr %r3, 1f\n" // r3 =3D &environ (see below) - "str %r2, [r3]\n" // store envp into environ + "add %r2, %r0, $1\n" /* envp =3D (argc + 1) ... = */ + "lsl %r2, %r2, $2\n" /* * 4 ... = */ + "add %r2, %r2, %r1\n" /* + argv = */ + "ldr %r3, 1f\n" /* r3 =3D &environ (see below) = */ + "str %r2, [r3]\n" /* store envp into environ = */ =20 - "mov r4, r2\n" // search for auxv (follows NULL after las= t env) + "mov r4, r2\n" /* search for auxv (follows NULL after las= t env) */ "0:\n" - "mov r5, r4\n" // r5 =3D r4 - "add r4, r4, #4\n" // r4 +=3D 4 - "ldr r5,[r5]\n" // r5 =3D *r5 =3D *(r4-4) - "cmp r5, #0\n" // and stop at NULL after last env + "mov r5, r4\n" /* r5 =3D r4 = */ + "add r4, r4, #4\n" /* r4 +=3D 4 = */ + "ldr r5,[r5]\n" /* r5 =3D *r5 =3D *(r4-4) = */ + "cmp r5, #0\n" /* and stop at NULL after last env = */ "bne 0b\n" - "ldr %r3, 2f\n" // r3 =3D &_auxv (low bits) - "str r4, [r3]\n" // store r4 into _auxv + "ldr %r3, 2f\n" /* r3 =3D &_auxv (low bits) = */ + "str r4, [r3]\n" /* store r4 into _auxv = */ =20 - "mov %r3, $8\n" // AAPCS : sp must be 8-byte aligned in the - "neg %r3, %r3\n" // callee, and bl doesn't push (lr= =3Dpc) - "and %r3, %r3, %r1\n" // so we do sp =3D r1(=3Dsp) & r3(=3D-8); - "mov %sp, %r3\n" // + "mov %r3, $8\n" /* AAPCS : sp must be 8-byte aligned in th= e */ + "neg %r3, %r3\n" /* callee, and bl doesn't push (lr= =3Dpc) */ + "and %r3, %r3, %r1\n" /* so we do sp =3D r1(=3Dsp) & r3(=3D-8); = */ + "mov %sp, %r3\n" =20 - "bl main\n" // main() returns the status code, we'll e= xit with it. - "movs r7, $1\n" // NR_exit =3D=3D 1 + "bl main\n" /* main() returns the status code, we'll e= xit with it. */ + "movs r7, $1\n" /* NR_exit =3D=3D 1 = */ "svc $0x00\n" - ".align 2\n" // below are the pointers to a few variabl= es + ".align 2\n" /* below are the pointers to a few variabl= es */ "1:\n" ".word environ\n" "2:\n" @@ -239,4 +239,4 @@ void __attribute__((weak,noreturn,optimize("omit-frame-= pointer"))) _start(void) __builtin_unreachable(); } =20 -#endif // _NOLIBC_ARCH_ARM_H +#endif /* _NOLIBC_ARCH_ARM_H */ diff --git a/tools/include/nolibc/arch-i386.h b/tools/include/nolibc/arch-i= 386.h index 2d98d78fd3f3..7c41897a08ce 100644 --- a/tools/include/nolibc/arch-i386.h +++ b/tools/include/nolibc/arch-i386.h @@ -194,31 +194,31 @@ void __attribute__((weak,noreturn,optimize("omit-fram= e-pointer"),no_stack_protec { __asm__ volatile ( #ifdef NOLIBC_STACKPROTECTOR - "call __stack_chk_init\n" // initialize stack protector + "call __stack_chk_init\n" /* initialize stack protector = */ #endif - "pop %eax\n" // argc (first arg, %eax) - "mov %esp, %ebx\n" // argv[] (second arg, %ebx) - "lea 4(%ebx,%eax,4),%ecx\n" // then a NULL then envp (third arg, %ecx) - "mov %ecx, environ\n" // save environ - "xor %ebp, %ebp\n" // zero the stack frame - "mov %ecx, %edx\n" // search for auxv (follows NULL after last = env) + "pop %eax\n" /* argc (first arg, %eax) = */ + "mov %esp, %ebx\n" /* argv[] (second arg, %ebx) = */ + "lea 4(%ebx,%eax,4),%ecx\n" /* then a NULL then envp (third arg, %ecx) = */ + "mov %ecx, environ\n" /* save environ = */ + "xor %ebp, %ebp\n" /* zero the stack frame = */ + "mov %ecx, %edx\n" /* search for auxv (follows NULL after last = env) */ "0:\n" - "add $4, %edx\n" // search for auxv using edx, it follows the - "cmp -4(%edx), %ebp\n" // ... NULL after last env (ebp is zero here) + "add $4, %edx\n" /* search for auxv using edx, it follows the= */ + "cmp -4(%edx), %ebp\n" /* ... NULL after last env (ebp is zero here= ) */ "jnz 0b\n" - "mov %edx, _auxv\n" // save it into _auxv - "and $-16, %esp\n" // x86 ABI : esp must be 16-byte aligned bef= ore - "sub $4, %esp\n" // the call instruction (args are aligned) - "push %ecx\n" // push all registers on the stack so that we - "push %ebx\n" // support both regparm and plain stack modes + "mov %edx, _auxv\n" /* save it into _auxv = */ + "and $-16, %esp\n" /* x86 ABI : esp must be 16-byte aligned bef= ore */ + "sub $4, %esp\n" /* the call instruction (args are aligned) = */ + "push %ecx\n" /* push all registers on the stack so that w= e */ + "push %ebx\n" /* support both regparm and plain stack mode= s */ "push %eax\n" - "call main\n" // main() returns the status code in %eax - "mov %eax, %ebx\n" // retrieve exit code (32-bit int) - "movl $1, %eax\n" // NR_exit =3D=3D 1 - "int $0x80\n" // exit now - "hlt\n" // ensure it does not + "call main\n" /* main() returns the status code in %eax = */ + "mov %eax, %ebx\n" /* retrieve exit code (32-bit int) = */ + "movl $1, %eax\n" /* NR_exit =3D=3D 1 = */ + "int $0x80\n" /* exit now = */ + "hlt\n" /* ensure it does not = */ ); __builtin_unreachable(); } =20 -#endif // _NOLIBC_ARCH_I386_H +#endif /* _NOLIBC_ARCH_I386_H */ diff --git a/tools/include/nolibc/arch-loongarch.h b/tools/include/nolibc/a= rch-loongarch.h index 029ee3cd6baf..ec3b46a991a9 100644 --- a/tools/include/nolibc/arch-loongarch.h +++ b/tools/include/nolibc/arch-loongarch.h @@ -158,7 +158,7 @@ const unsigned long *_auxv __attribute__((weak)); #define LONG_ADDI "addi.w" #define LONG_SLL "slli.w" #define LONG_BSTRINS "bstrins.w" -#else // __loongarch_grlen =3D=3D 64 +#else /* __loongarch_grlen =3D=3D 64 */ #define LONGLOG "3" #define SZREG "8" #define REG_L "ld.d" @@ -173,28 +173,28 @@ const unsigned long *_auxv __attribute__((weak)); void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(= void) { __asm__ volatile ( - REG_L " $a0, $sp, 0\n" // argc (a0) was in the stack - LONG_ADDI " $a1, $sp, "SZREG"\n" // argv (a1) =3D sp + SZREG - LONG_SLL " $a2, $a0, "LONGLOG"\n" // envp (a2) =3D SZREG*argc ... - LONG_ADDI " $a2, $a2, "SZREG"\n" // + SZREG (skip null) - LONG_ADD " $a2, $a2, $a1\n" // + argv + REG_L " $a0, $sp, 0\n" /* argc (a0) was in the stack = */ + LONG_ADDI " $a1, $sp, "SZREG"\n" /* argv (a1) =3D sp + SZREG = */ + LONG_SLL " $a2, $a0, "LONGLOG"\n" /* envp (a2) =3D SZREG*argc ... = */ + LONG_ADDI " $a2, $a2, "SZREG"\n" /* + SZREG (skip null)= */ + LONG_ADD " $a2, $a2, $a1\n" /* + argv = */ =20 - "move $a3, $a2\n" // iterate a3 over envp to find au= xv (after NULL) - "0:\n" // do { - REG_L " $a4, $a3, 0\n" // a4 =3D *a3; - LONG_ADDI " $a3, $a3, "SZREG"\n" // a3 +=3D sizeof(void*); - "bne $a4, $zero, 0b\n" // } while (a4); - "la.pcrel $a4, _auxv\n" // a4 =3D &_auxv - LONG_S " $a3, $a4, 0\n" // store a3 into _auxv + "move $a3, $a2\n" /* iterate a3 over envp to find au= xv (after NULL) */ + "0:\n" /* do { = */ + REG_L " $a4, $a3, 0\n" /* a4 =3D *a3; = */ + LONG_ADDI " $a3, $a3, "SZREG"\n" /* a3 +=3D sizeof(void*); = */ + "bne $a4, $zero, 0b\n" /* } while (a4); = */ + "la.pcrel $a4, _auxv\n" /* a4 =3D &_auxv = */ + LONG_S " $a3, $a4, 0\n" /* store a3 into _auxv = */ =20 - "la.pcrel $a3, environ\n" // a3 =3D &environ - LONG_S " $a2, $a3, 0\n" // store envp(a2) into environ - LONG_BSTRINS " $sp, $zero, 3, 0\n" // sp must be 16-byte aligned - "bl main\n" // main() returns the status code,= we'll exit with it. - "li.w $a7, 93\n" // NR_exit =3D=3D 93 + "la.pcrel $a3, environ\n" /* a3 =3D &environ = */ + LONG_S " $a2, $a3, 0\n" /* store envp(a2) into environ = */ + LONG_BSTRINS " $sp, $zero, 3, 0\n" /* sp must be 16-byte aligned = */ + "bl main\n" /* main() returns the status code,= we'll exit with it. */ + "li.w $a7, 93\n" /* NR_exit =3D=3D 93 = */ "syscall 0\n" ); __builtin_unreachable(); } =20 -#endif // _NOLIBC_ARCH_LOONGARCH_H +#endif /* _NOLIBC_ARCH_LOONGARCH_H */ diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-m= ips.h index bf83432d23ed..8822f150e72f 100644 --- a/tools/include/nolibc/arch-mips.h +++ b/tools/include/nolibc/arch-mips.h @@ -183,42 +183,42 @@ const unsigned long *_auxv __attribute__((weak)); void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __start= (void) { __asm__ volatile ( - //".set nomips16\n" + /*".set nomips16\n"*/ ".set push\n" ".set noreorder\n" ".option pic0\n" - //".ent __start\n" - //"__start:\n" - "lw $a0,($sp)\n" // argc was in the stack - "addiu $a1, $sp, 4\n" // argv =3D sp + 4 - "sll $a2, $a0, 2\n" // a2 =3D argc * 4 - "add $a2, $a2, $a1\n" // envp =3D argv + 4*argc ... - "addiu $a2, $a2, 4\n" // ... + 4 - "lui $a3, %hi(environ)\n" // load environ into a3 (hi) - "addiu $a3, %lo(environ)\n" // load environ into a3 (lo) - "sw $a2,($a3)\n" // store envp(a2) into environ - - "move $t0, $a2\n" // iterate t0 over envp, look for NULL - "0:" // do { - "lw $a3, ($t0)\n" // a3=3D*(t0); - "bne $a3, $0, 0b\n" // } while (a3); - "addiu $t0, $t0, 4\n" // delayed slot: t0+=3D4; - "lui $a3, %hi(_auxv)\n" // load _auxv into a3 (hi) - "addiu $a3, %lo(_auxv)\n" // load _auxv into a3 (lo) - "sw $t0, ($a3)\n" // store t0 into _auxv + /*".ent __start\n"*/ + /*"__start:\n"*/ + "lw $a0,($sp)\n" /* argc was in the stack = */ + "addiu $a1, $sp, 4\n" /* argv =3D sp + 4 = */ + "sll $a2, $a0, 2\n" /* a2 =3D argc * 4 = */ + "add $a2, $a2, $a1\n" /* envp =3D argv + 4*argc ... = */ + "addiu $a2, $a2, 4\n" /* ... + 4 = */ + "lui $a3, %hi(environ)\n" /* load environ into a3 (hi) = */ + "addiu $a3, %lo(environ)\n" /* load environ into a3 (lo) = */ + "sw $a2,($a3)\n" /* store envp(a2) into environ = */ + + "move $t0, $a2\n" /* iterate t0 over envp, look for NULL = */ + "0:" /* do { = */ + "lw $a3, ($t0)\n" /* a3=3D*(t0); = */ + "bne $a3, $0, 0b\n" /* } while (a3); = */ + "addiu $t0, $t0, 4\n" /* delayed slot: t0+=3D4; = */ + "lui $a3, %hi(_auxv)\n" /* load _auxv into a3 (hi) = */ + "addiu $a3, %lo(_auxv)\n" /* load _auxv into a3 (lo) = */ + "sw $t0, ($a3)\n" /* store t0 into _auxv = */ =20 "li $t0, -8\n" - "and $sp, $sp, $t0\n" // sp must be 8-byte aligned - "addiu $sp,$sp,-16\n" // the callee expects to save a0..a3 there! - "jal main\n" // main() returns the status code, we'll exit wi= th it. - "nop\n" // delayed slot - "move $a0, $v0\n" // retrieve 32-bit exit code from v0 - "li $v0, 4001\n" // NR_exit =3D=3D 4001 + "and $sp, $sp, $t0\n" /* sp must be 8-byte aligned = */ + "addiu $sp,$sp,-16\n" /* the callee expects to save a0..a3 there! = */ + "jal main\n" /* main() returns the status code, we'll exit wi= th it. */ + "nop\n" /* delayed slot = */ + "move $a0, $v0\n" /* retrieve 32-bit exit code from v0 = */ + "li $v0, 4001\n" /* NR_exit =3D=3D 4001 = */ "syscall\n" - //".end __start\n" + /*".end __start\n"*/ ".set pop\n" ); __builtin_unreachable(); } =20 -#endif // _NOLIBC_ARCH_MIPS_H +#endif /* _NOLIBC_ARCH_MIPS_H */ diff --git a/tools/include/nolibc/arch-riscv.h b/tools/include/nolibc/arch-= riscv.h index e197fcb10ac0..0d5f15fdedc4 100644 --- a/tools/include/nolibc/arch-riscv.h +++ b/tools/include/nolibc/arch-riscv.h @@ -181,28 +181,28 @@ void __attribute__((weak,noreturn,optimize("omit-fram= e-pointer"))) _start(void) ".option norelax\n" "lla gp, __global_pointer$\n" ".option pop\n" - "lw a0, 0(sp)\n" // argc (a0) was in the stack - "add a1, sp, "SZREG"\n" // argv (a1) =3D sp - "slli a2, a0, "PTRLOG"\n" // envp (a2) =3D SZREG*argc ... - "add a2, a2, "SZREG"\n" // + SZREG (skip null) - "add a2,a2,a1\n" // + argv - - "add a3, a2, zero\n" // iterate a3 over envp to find auxv (after= NULL) - "0:\n" // do { - "ld a4, 0(a3)\n" // a4 =3D *a3; - "add a3, a3, "SZREG"\n" // a3 +=3D sizeof(void*); - "bne a4, zero, 0b\n" // } while (a4); - "lui a4, %hi(_auxv)\n" // a4 =3D &_auxv (high bits) - "sd a3, %lo(_auxv)(a4)\n" // store a3 into _auxv - - "lui a3, %hi(environ)\n" // a3 =3D &environ (high bits) - "sd a2,%lo(environ)(a3)\n" // store envp(a2) into environ - "andi sp,a1,-16\n" // sp must be 16-byte aligned - "call main\n" // main() returns the status code, we'll ex= it with it. - "li a7, 93\n" // NR_exit =3D=3D 93 + "lw a0, 0(sp)\n" /* argc (a0) was in the stack = */ + "add a1, sp, "SZREG"\n" /* argv (a1) =3D sp = */ + "slli a2, a0, "PTRLOG"\n" /* envp (a2) =3D SZREG*argc ... = */ + "add a2, a2, "SZREG"\n" /* + SZREG (skip null) = */ + "add a2,a2,a1\n" /* + argv = */ + + "add a3, a2, zero\n" /* iterate a3 over envp to find auxv (after= NULL) */ + "0:\n" /* do { = */ + "ld a4, 0(a3)\n" /* a4 =3D *a3; = */ + "add a3, a3, "SZREG"\n" /* a3 +=3D sizeof(void*); = */ + "bne a4, zero, 0b\n" /* } while (a4); = */ + "lui a4, %hi(_auxv)\n" /* a4 =3D &_auxv (high bits) = */ + "sd a3, %lo(_auxv)(a4)\n" /* store a3 into _auxv = */ + + "lui a3, %hi(environ)\n" /* a3 =3D &environ (high bits) = */ + "sd a2,%lo(environ)(a3)\n" /* store envp(a2) into environ = */ + "andi sp,a1,-16\n" /* sp must be 16-byte aligned = */ + "call main\n" /* main() returns the status code, we'll ex= it with it. */ + "li a7, 93\n" /* NR_exit =3D=3D 93 = */ "ecall\n" ); __builtin_unreachable(); } =20 -#endif // _NOLIBC_ARCH_RISCV_H +#endif /* _NOLIBC_ARCH_RISCV_H */ diff --git a/tools/include/nolibc/arch-s390.h b/tools/include/nolibc/arch-s= 390.h index 6b0e54ed543d..c62ee2472407 100644 --- a/tools/include/nolibc/arch-s390.h +++ b/tools/include/nolibc/arch-s390.h @@ -223,4 +223,4 @@ void *sys_mmap(void *addr, size_t length, int prot, int= flags, int fd, return (void *)my_syscall1(__NR_mmap, &args); } #define sys_mmap sys_mmap -#endif // _NOLIBC_ARCH_S390_H +#endif /* _NOLIBC_ARCH_S390_H */ diff --git a/tools/include/nolibc/arch-x86_64.h b/tools/include/nolibc/arch= -x86_64.h index f7f2a11d4c3b..d98f6c89d143 100644 --- a/tools/include/nolibc/arch-x86_64.h +++ b/tools/include/nolibc/arch-x86_64.h @@ -194,27 +194,27 @@ void __attribute__((weak,noreturn,optimize("omit-fram= e-pointer"))) _start(void) { __asm__ volatile ( #ifdef NOLIBC_STACKPROTECTOR - "call __stack_chk_init\n" // initialize stack protector + "call __stack_chk_init\n" /* initialize stack protector = */ #endif - "pop %rdi\n" // argc (first arg, %rdi) - "mov %rsp, %rsi\n" // argv[] (second arg, %rsi) - "lea 8(%rsi,%rdi,8),%rdx\n" // then a NULL then envp (third arg, %rdx) - "mov %rdx, environ\n" // save environ - "xor %ebp, %ebp\n" // zero the stack frame - "mov %rdx, %rax\n" // search for auxv (follows NULL after last = env) + "pop %rdi\n" /* argc (first arg, %rdi) = */ + "mov %rsp, %rsi\n" /* argv[] (second arg, %rsi) = */ + "lea 8(%rsi,%rdi,8),%rdx\n" /* then a NULL then envp (third arg, %rdx) = */ + "mov %rdx, environ\n" /* save environ = */ + "xor %ebp, %ebp\n" /* zero the stack frame = */ + "mov %rdx, %rax\n" /* search for auxv (follows NULL after last = env) */ "0:\n" - "add $8, %rax\n" // search for auxv using rax, it follows the - "cmp -8(%rax), %rbp\n" // ... NULL after last env (rbp is zero here) + "add $8, %rax\n" /* search for auxv using rax, it follows the= */ + "cmp -8(%rax), %rbp\n" /* ... NULL after last env (rbp is zero here= ) */ "jnz 0b\n" - "mov %rax, _auxv\n" // save it into _auxv - "and $-16, %rsp\n" // x86 ABI : esp must be 16-byte aligned bef= ore call - "call main\n" // main() returns the status code, we'll exi= t with it. - "mov %eax, %edi\n" // retrieve exit code (32 bit) - "mov $60, %eax\n" // NR_exit =3D=3D 60 - "syscall\n" // really exit - "hlt\n" // ensure it does not return + "mov %rax, _auxv\n" /* save it into _auxv = */ + "and $-16, %rsp\n" /* x86 ABI : esp must be 16-byte aligned bef= ore call */ + "call main\n" /* main() returns the status code, we'll exi= t with it. */ + "mov %eax, %edi\n" /* retrieve exit code (32 bit) = */ + "mov $60, %eax\n" /* NR_exit =3D=3D 60 = */ + "syscall\n" /* really exit = */ + "hlt\n" /* ensure it does not return = */ ); __builtin_unreachable(); } =20 -#endif // _NOLIBC_ARCH_X86_64_H +#endif /* _NOLIBC_ARCH_X86_64_H */ diff --git a/tools/include/nolibc/stackprotector.h b/tools/include/nolibc/s= tackprotector.h index d119cbbbc256..77e5251c4490 100644 --- a/tools/include/nolibc/stackprotector.h +++ b/tools/include/nolibc/stackprotector.h @@ -48,6 +48,6 @@ void __stack_chk_init(void) /* a bit more randomness in case getrandom() fails */ __stack_chk_guard ^=3D (uintptr_t) &__stack_chk_guard; } -#endif // defined(NOLIBC_STACKPROTECTOR) +#endif /* defined(NOLIBC_STACKPROTECTOR) */ =20 -#endif // _NOLIBC_STACKPROTECTOR_H +#endif /* _NOLIBC_STACKPROTECTOR_H */ diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index bea9760dbd16..1b9b91cd8b57 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -12,15 +12,15 @@ =20 /* system includes */ #include -#include // for SIGCHLD +#include /* for SIGCHLD */ #include #include #include #include #include #include -#include // for O_* and AT_* -#include // for statx() +#include /* for O_* and AT_* */ +#include /* for statx() */ =20 #include "arch.h" #include "errno.h" @@ -322,7 +322,7 @@ static __attribute__((noreturn,unused)) void sys_exit(int status) { my_syscall1(__NR_exit, status & 255); - while(1); // shut the "noreturn" warnings. + while(1); /* shut the "noreturn" warnings. */ } =20 static __attribute__((noreturn,unused)) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index e692be98973a..f06b38cfe38a 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +/* SPDX-License-Identifier: GPL-2.0 */ =20 #define _GNU_SOURCE =20 @@ -46,8 +46,8 @@ char **environ; =20 /* definition of a series of tests */ struct test { - const char *name; // test name - int (*func)(int min, int max); // handler + const char *name; /* test name */ + int (*func)(int min, int max); /* handler */ }; =20 #ifndef _NOLIBC_STDLIB_H @@ -494,7 +494,7 @@ int run_syscall(int min, int max) euid0 =3D geteuid() =3D=3D 0; =20 for (test =3D min; test >=3D 0 && test <=3D max; test++) { - int llen =3D 0; // line length + int llen =3D 0; /* line length */ =20 /* avoid leaving empty lines below, this will insert holes into * test numbers. @@ -584,7 +584,7 @@ int run_stdlib(int min, int max) void *p1, *p2; =20 for (test =3D min; test >=3D 0 && test <=3D max; test++) { - int llen =3D 0; // line length + int llen =3D 0; /* line length */ =20 /* avoid leaving empty lines below, this will insert holes into * test numbers. @@ -731,7 +731,7 @@ static int run_vfprintf(int min, int max) void *p1, *p2; =20 for (test =3D min; test >=3D 0 && test <=3D max; test++) { - int llen =3D 0; // line length + int llen =3D 0; /* line length */ =20 /* avoid leaving empty lines below, this will insert holes into * test numbers. --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 36194C88CB2 for ; Mon, 12 Jun 2023 20:48:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237835AbjFLUsF (ORCPT ); Mon, 12 Jun 2023 16:48:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236337AbjFLUq6 (ORCPT ); Mon, 12 Jun 2023 16:46:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BB232717 for ; Mon, 12 Jun 2023 13:46:29 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 73C4762EFA for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8AD2AC433AA; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602716; bh=qXNtbl8qeb3lbiMWDYS0tmfhxByKNfAQg29LsRRZRZE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BcCBXjUcDQw7GvBvkqk0czuJCHO1gukX0JAC3d/WjGUujdUEvo+WDUTQo5twRklUw szkNyVBvvA4QJI6yyxu6qBZoW1Env4oGVEzi1U4Ruh5uGbvhLiYe8uasqLHWDa0gBu Bj/VEHxQXlZeE/pTmjjvru76AxG4n3a8P9fHl/je5VYCCOvwo9m8R09RfLXq9nVSAJ 2YhMfzLuGe4mfdc3igIJ7W23UzwVR0kVre9jXcAQK5tKbSr+Z28y0KDNzaqQEFTsiZ BzPfa9nOr6mgYY/f6e0Y5f69lbem0B9GMuEwLS6JImoL6tmkgqOabmqPbNZoKIcECL GnjPYOlViTD7A== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id C416ECE3A51; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 12/53] tools/nolibc: validate C89 compatibility Date: Mon, 12 Jun 2023 13:44:33 -0700 Message-Id: <20230612204514.292087-12-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh To make sure no non-compatible changes are introduced accidentally validate the language standard when building the tests. Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/testing/selftests/nolibc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selfte= sts/nolibc/Makefile index 0cbe13809b37..423d22f353a0 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -83,7 +83,7 @@ CFLAGS_STKP_i386 =3D $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_x86_64 =3D $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_x86 =3D $(CFLAGS_STACKPROTECTOR) CFLAGS_s390 =3D -m64 -CFLAGS ?=3D -Os -fno-ident -fno-asynchronous-unwind-tables \ +CFLAGS ?=3D -Os -fno-ident -fno-asynchronous-unwind-tables -std=3Dc89 \ $(call cc-option,-fno-stack-protector) \ $(CFLAGS_STKP_$(ARCH)) $(CFLAGS_$(ARCH)) LDFLAGS :=3D -s --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 BF5DFC7EE43 for ; Mon, 12 Jun 2023 20:48:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237873AbjFLUsH (ORCPT ); Mon, 12 Jun 2023 16:48:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235960AbjFLUrA (ORCPT ); Mon, 12 Jun 2023 16:47:00 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0FE42943 for ; Mon, 12 Jun 2023 13:46:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 76B8E62EFB for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9696CC433AF; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602716; bh=oC2jzfNDP3qXofDBVXlAqaNEq75nX/bGi7jR4v97zaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rp57k+kruEmbcOONSC0w6AF6KVWffRId/t95pE3udygnwZ5N50WYldwWdIBSJkpWD lTwzdRlcY02MhuwOah7Da+oDyOVilf+uasSrQMjnF/3FCmqAWFm0AJ+OeO8xFwymG6 AcZXbmflqTQl5W9sGG7um/Lgq2UdQlKIG8Ktbw5OtNUNfWNVsCCP0PXNBtmYHXbUr6 hwuiqPFxXiDuKZbqhn94XvSt241uYv6dSoPpb4IcIg5G68Ig/kh1aJePhdJbvotND/ pMZaeNpnSxbOSO1si3aZL3Opx3I1pHpfZYSvfZ4A3QDKt7z/d0Ts+r1BPl9OAxSk9X 9H0CsrT9ix0Pw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id C637DCE3A53; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Sven Schnelle , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 13/53] tools/nolibc: s390: provide custom implementation for sys_fork Date: Mon, 12 Jun 2023 13:44:34 -0700 Message-Id: <20230612204514.292087-13-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh On s390 the first two arguments to the clone() syscall are swapped, as documented in clone(2). Signed-off-by: Thomas Wei=C3=9Fschuh Cc: Sven Schnelle Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/arch-s390.h | 9 +++++++++ tools/include/nolibc/sys.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/tools/include/nolibc/arch-s390.h b/tools/include/nolibc/arch-s= 390.h index c62ee2472407..a738e7f3f8e8 100644 --- a/tools/include/nolibc/arch-s390.h +++ b/tools/include/nolibc/arch-s390.h @@ -5,6 +5,7 @@ =20 #ifndef _NOLIBC_ARCH_S390_H #define _NOLIBC_ARCH_S390_H +#include #include =20 /* The struct returned by the stat() syscall, equivalent to stat64(). The @@ -223,4 +224,12 @@ void *sys_mmap(void *addr, size_t length, int prot, in= t flags, int fd, return (void *)my_syscall1(__NR_mmap, &args); } #define sys_mmap sys_mmap + +static __attribute__((unused)) +pid_t sys_fork(void) +{ + return my_syscall5(__NR_clone, 0, SIGCHLD, 0, 0, 0); +} +#define sys_fork sys_fork + #endif /* _NOLIBC_ARCH_S390_H */ diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 1b9b91cd8b57..60dffb1cbf96 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -336,6 +336,7 @@ void exit(int status) * pid_t fork(void); */ =20 +#ifndef sys_fork static __attribute__((unused)) pid_t sys_fork(void) { @@ -351,6 +352,7 @@ pid_t sys_fork(void) #error Neither __NR_clone nor __NR_fork defined, cannot implement sys_fork= () #endif } +#endif =20 static __attribute__((unused)) pid_t fork(void) --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 D22A7C7EE43 for ; Mon, 12 Jun 2023 20:48:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232148AbjFLUsR (ORCPT ); Mon, 12 Jun 2023 16:48:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237076AbjFLUrC (ORCPT ); Mon, 12 Jun 2023 16:47:02 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA0FB2949 for ; Mon, 12 Jun 2023 13:46:31 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 786E962EF7 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ADF81C433A1; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602716; bh=UfezgJW4qV6A3Fx5ZwnvEgO/thFwlCGX/qvaitn6eGs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u15Yhmho/ODVrrDCvteOLPvwc4BoC7BhZuidW45OCP0Ox8Qcc0UnW89wIiPTVmhS+ E06JhpTd0YLubxzyAcTmWxeb3LAzZ85q70nNN6gvFor/kZ96/0YXPX4lWiZurjsAyd akUsvrdWBpMHiLCOnthz07eHsYPU6IFBymefVkJHzhInWyE56KXdTd/QOOwWqBLBar gjSihqsRW15ZNowwcOdI8bprRNm1f7gH7qIdb/gSnNPtxozISUYB8LiPEtxtedpt/k 6LvEuQ4cxEKEfusaWM+gdo3ncIhz0S9ZkgGTT+yvgiKVqNHHEP1M1FiLH9XlbSgxjf OMz1fX0AEAF+A== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id C88CBCE3A55; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 14/53] tools/nolibc: add testcase for fork()/waitpid() Date: Mon, 12 Jun 2023 13:44:35 -0700 Message-Id: <20230612204514.292087-14-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh On s390 the arguments to clone() which is used by fork() are different than other archs. Make sure everything works correctly. Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/testing/selftests/nolibc/nolibc-test.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index f06b38cfe38a..f042a6436b6b 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -474,6 +474,25 @@ static int test_getpagesize(void) return !c; } =20 +static int test_fork(void) +{ + int status; + pid_t pid =3D fork(); + + switch (pid) { + case -1: + return 1; + + case 0: + exit(123); + + default: + pid =3D waitpid(pid, &status, 0); + + return pid =3D=3D -1 || !WIFEXITED(status) || WEXITSTATUS(status) !=3D 1= 23; + } +} + /* Run syscall tests between IDs and . * Return 0 on success, non-zero on failure. */ @@ -530,6 +549,7 @@ int run_syscall(int min, int max) CASE_TEST(dup3_0); tmp =3D dup3(0, 100, 0); EXPECT_SYSNE(1, = tmp, -1); close(tmp); break; CASE_TEST(dup3_m1); tmp =3D dup3(-1, 100, 0); EXPECT_SYSER(1, = tmp, -1, EBADF); if (tmp !=3D -1) close(tmp); break; CASE_TEST(execve_root); EXPECT_SYSER(1, execve("/", (char*[]){ [0]= =3D "/", [1] =3D NULL }, NULL), -1, EACCES); break; + CASE_TEST(fork); EXPECT_SYSZR(1, test_fork()); break; CASE_TEST(getdents64_root); EXPECT_SYSNE(1, test_getdents64("/"), -1);= break; CASE_TEST(getdents64_null); EXPECT_SYSER(1, test_getdents64("/dev/null= "), -1, ENOTDIR); break; CASE_TEST(gettimeofday_null); EXPECT_SYSZR(1, gettimeofday(NULL, NULL));= break; --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 94C67C7EE43 for ; Mon, 12 Jun 2023 20:48:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237337AbjFLUsa (ORCPT ); Mon, 12 Jun 2023 16:48:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237100AbjFLUr0 (ORCPT ); Mon, 12 Jun 2023 16:47:26 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC9072956 for ; Mon, 12 Jun 2023 13:46:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7D7CB62F02 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3993C433B0; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602716; bh=aYadX67GYiG+Nuff8Hdg1wAWmzTfTdurTxNUVvBVt1c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=agyfhPJYVc0kbRjDsZN7YsXptG8VkUsAwx0AOQgpsw68zsjgDkvW/O/PHyC8v73zP Mv7zeQ8mtAtabnhDqyZHb/tO4A0ckb6YbsJHih2kZH0O60Aoj/SqWFWJbqTCNmmtgR IwkAOjwkOUtQ1+eL2Mh7f7rOD87s0nTgbCnPBhqYZYKomZtgDyklK+K5jNPM6NQfDo P7sz9BR/HKOsjpSX1HNu+xoY7TxJFc7xSXr3T/T9TdhZaYuwjedjnen4UKD3hvu6iU xxnoAaF6Ijd0Wqf4ga7PSs6N/igt1FCcRwM8QBSIOCDjXGKel01BI6OKz513fMvvik jXx3PrvcOZu8A== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id CAE30CE3A56; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 15/53] tools/nolibc: remove LINUX_REBOOT_ constants Date: Mon, 12 Jun 2023 13:44:36 -0700 Message-Id: <20230612204514.292087-15-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh The same constants and some more have been exposed to userspace via linux/reboot.h for a long time. To avoid conflicts and trim down nolibc a bit drop the custom definitions. Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/sys.h | 1 + tools/include/nolibc/types.h | 8 -------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 60dffb1cbf96..d5792a5de70b 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -21,6 +21,7 @@ #include #include /* for O_* and AT_* */ #include /* for statx() */ +#include /* for LINUX_REBOOT_* */ =20 #include "arch.h" #include "errno.h" diff --git a/tools/include/nolibc/types.h b/tools/include/nolibc/types.h index aedd7d9e3f64..15b0baffd336 100644 --- a/tools/include/nolibc/types.h +++ b/tools/include/nolibc/types.h @@ -86,14 +86,6 @@ #define SEEK_CUR 1 #define SEEK_END 2 =20 -/* cmd for reboot() */ -#define LINUX_REBOOT_MAGIC1 0xfee1dead -#define LINUX_REBOOT_MAGIC2 0x28121969 -#define LINUX_REBOOT_CMD_HALT 0xcdef0123 -#define LINUX_REBOOT_CMD_POWER_OFF 0x4321fedc -#define LINUX_REBOOT_CMD_RESTART 0x01234567 -#define LINUX_REBOOT_CMD_SW_SUSPEND 0xd000fce2 - /* Macros used on waitpid()'s return status */ #define WEXITSTATUS(status) (((status) & 0xff00) >> 8) #define WIFEXITED(status) (((status) & 0x7f) =3D=3D 0) --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 26904C7EE2F for ; Mon, 12 Jun 2023 20:48:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235438AbjFLUsM (ORCPT ); Mon, 12 Jun 2023 16:48:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236971AbjFLUrC (ORCPT ); Mon, 12 Jun 2023 16:47:02 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9BD12947 for ; Mon, 12 Jun 2023 13:46:31 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7891762EFF for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C0971C433B4; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602716; bh=fq9Novytq9EKJSJOpiX99BQ9yCRZSIhHk3PPBCKpdpY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jkSeDAmaew4avDeeKGbVMWmJIg8UX9nNJdjMiuk1Fx30gwqYD40eUrLLhLve/qfB9 7i2b265TDipJXOgn8Rj/LCefmQvvlQ3AchyTC5SunbYhD68VLY5FVWQW1M9EWPMPF9 CeR4dNYL/T6pui29UWb+t6/tuTJ3JYNLY5Az3PuIZBoQJTAZMTF2z0cbJQ1kJPKL0y bvmTbiwEOMiXA0amQ7pF6nM0n1mAR/4RqbiUFmR57OhPaspoGTbzF4hCBC3p1ln+8k o5Kj8ZrxrCagR1EpTlkINX2wzXYgS9ygFYQrua/8MkpELY6oT/R5vv/lQ3i7xQ96E7 kvr+uOK0xhMNw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id CD581CE3A57; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, Zhangjin Wu , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 16/53] tools/nolibc: riscv: Fix up load/store instructions for rv32 Date: Mon, 12 Jun 2023 13:44:37 -0700 Message-Id: <20230612204514.292087-16-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Zhangjin Wu When compile nolibc application for rv32, we got such errors: nolibc/sysroot/riscv/include/arch.h:190: Error: unrecognized opcode `ld a= 4,0(a3)' nolibc/sysroot/riscv/include/arch.h:194: Error: unrecognized opcode `sd a= 3,%lo(_auxv)(a4)' nolibc/sysroot/riscv/include/arch.h:196: Error: unrecognized opcode `sd a= 2,%lo(environ)(a3)' Refer to arch/riscv/include/asm/asm.h and add REG_L/REG_S macros here to let rv32 uses its own lw/sw instructions. Signed-off-by: Zhangjin Wu Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/arch-riscv.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/include/nolibc/arch-riscv.h b/tools/include/nolibc/arch-= riscv.h index 0d5f15fdedc4..992a1739dd9c 100644 --- a/tools/include/nolibc/arch-riscv.h +++ b/tools/include/nolibc/arch-riscv.h @@ -33,9 +33,13 @@ struct sys_stat_struct { #if __riscv_xlen =3D=3D 64 #define PTRLOG "3" #define SZREG "8" +#define REG_L "ld" +#define REG_S "sd" #elif __riscv_xlen =3D=3D 32 #define PTRLOG "2" #define SZREG "4" +#define REG_L "lw" +#define REG_S "sw" #endif =20 /* Syscalls for RISCV : @@ -181,7 +185,7 @@ void __attribute__((weak,noreturn,optimize("omit-frame-= pointer"))) _start(void) ".option norelax\n" "lla gp, __global_pointer$\n" ".option pop\n" - "lw a0, 0(sp)\n" /* argc (a0) was in the stack = */ + REG_L" a0, 0(sp)\n" /* argc (a0) was in the stack = */ "add a1, sp, "SZREG"\n" /* argv (a1) =3D sp = */ "slli a2, a0, "PTRLOG"\n" /* envp (a2) =3D SZREG*argc ... = */ "add a2, a2, "SZREG"\n" /* + SZREG (skip null) = */ @@ -189,14 +193,14 @@ void __attribute__((weak,noreturn,optimize("omit-fram= e-pointer"))) _start(void) =20 "add a3, a2, zero\n" /* iterate a3 over envp to find auxv (after= NULL) */ "0:\n" /* do { = */ - "ld a4, 0(a3)\n" /* a4 =3D *a3; = */ + REG_L" a4, 0(a3)\n" /* a4 =3D *a3; = */ "add a3, a3, "SZREG"\n" /* a3 +=3D sizeof(void*); = */ "bne a4, zero, 0b\n" /* } while (a4); = */ "lui a4, %hi(_auxv)\n" /* a4 =3D &_auxv (high bits) = */ - "sd a3, %lo(_auxv)(a4)\n" /* store a3 into _auxv = */ + REG_S" a3, %lo(_auxv)(a4)\n" /* store a3 into _auxv = */ =20 - "lui a3, %hi(environ)\n" /* a3 =3D &environ (high bits) = */ - "sd a2,%lo(environ)(a3)\n" /* store envp(a2) into environ = */ + "lui a3, %hi(environ)\n" /* a3 =3D &environ (high bits) = */ + REG_S" a2,%lo(environ)(a3)\n"/* store envp(a2) into environ = */ "andi sp,a1,-16\n" /* sp must be 16-byte aligned = */ "call main\n" /* main() returns the status code, we'll ex= it with it. */ "li a7, 93\n" /* NR_exit =3D=3D 93 = */ --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 2C951C7EE43 for ; Mon, 12 Jun 2023 20:48:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233100AbjFLUsZ (ORCPT ); Mon, 12 Jun 2023 16:48:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232236AbjFLUrR (ORCPT ); Mon, 12 Jun 2023 16:47:17 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EFE8198E for ; Mon, 12 Jun 2023 13:46:33 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7B56B62F01 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8314C433EF; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602716; bh=gQgf+u3NBWRBckdfBH59WpO3TYAdJrxhNyjBgomyf/M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z4tZYLuGu9qQc2msHRhMR2GA/ycznYe5DLVs0YBXqDL+91RFnKWySPRk4Uy59aGTn ee0mJ4EU6Iutt+Msxb7t1LwiLP9NLeauzS81LAUKJjL+hdQ3M2ei3ryIr7RulwmiqQ X3hmBvpGVi+OhtkBxPyw5+0cOgjINMWRz1O+kmmaQrBiGvCX9WSBs2DCMlv1lV8E5t ZfUhPazdoTmtFCv6U9EdUDo0dYY58ni+tj14U/8C4URTPZ7Umu3MFkE8mKR51iHGjj q/MXI3FP7s3SKNykmPVSIvqwCrkrshSAl73DmBfcYcxodpBNnsAJLnjh6ryOXyeXYR fcQrhr1hpGT1A== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id CF971CE3A59; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 17/53] tools/nolibc/unistd: add syscall() Date: Mon, 12 Jun 2023 13:44:38 -0700 Message-Id: <20230612204514.292087-17-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh syscall() is used by "normal" libcs to allow users to directly call syscalls. By having the same syntax inside nolibc users can more easily write code that works with different libcs. The macro logic is adapted from systemtaps STAP_PROBEV() macro that is released in the public domain / CC0. Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/unistd.h | 15 +++++++++++++++ tools/testing/selftests/nolibc/nolibc-test.c | 2 ++ 2 files changed, 17 insertions(+) diff --git a/tools/include/nolibc/unistd.h b/tools/include/nolibc/unistd.h index ac7d53d986cd..0e832e10a0b2 100644 --- a/tools/include/nolibc/unistd.h +++ b/tools/include/nolibc/unistd.h @@ -56,6 +56,21 @@ int tcsetpgrp(int fd, pid_t pid) return ioctl(fd, TIOCSPGRP, &pid); } =20 +#define _syscall(N, ...) = \ +({ = \ + long _ret =3D my_syscall##N(__VA_ARGS__); \ + if (_ret < 0) { \ + SET_ERRNO(-_ret); \ + _ret =3D -1; \ + } \ + _ret; \ +}) + +#define _syscall_narg(...) __syscall_narg(__VA_ARGS__, 6, 5, 4, 3, 2, 1, 0) +#define __syscall_narg(_0, _1, _2, _3, _4, _5, _6, N, ...) N +#define _syscall_n(N, ...) _syscall(N, __VA_ARGS__) +#define syscall(...) _syscall_n(_syscall_narg(__VA_ARGS__), ##__VA_ARGS__) + /* make sure to include all global symbols */ #include "nolibc.h" =20 diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index f042a6436b6b..54bf91847af3 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -588,6 +588,8 @@ int run_syscall(int min, int max) CASE_TEST(waitpid_child); EXPECT_SYSER(1, waitpid(getpid(), &tmp, WN= OHANG), -1, ECHILD); break; CASE_TEST(write_badf); EXPECT_SYSER(1, write(-1, &tmp, 1), -1, EB= ADF); break; CASE_TEST(write_zero); EXPECT_SYSZR(1, write(1, &tmp, 0)); break; + CASE_TEST(syscall_noargs); EXPECT_SYSEQ(1, syscall(__NR_getpid), getp= id()); break; + CASE_TEST(syscall_args); EXPECT_SYSER(1, syscall(__NR_fstat, 0, NUL= L), -1, EFAULT); break; case __LINE__: return ret; /* must be last */ /* note: do not set any defaults so as to permit holes above */ --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 A5612C7EE2F for ; Mon, 12 Jun 2023 20:48:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237952AbjFLUsV (ORCPT ); Mon, 12 Jun 2023 16:48:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237084AbjFLUrD (ORCPT ); Mon, 12 Jun 2023 16:47:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D35A3294B for ; Mon, 12 Jun 2023 13:46:31 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7A6A162F00 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE4F2C433B3; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602716; bh=TZGVRE+NeaqSEa0Q3SOYtOQ0/O9QiuguihBm45XSgyg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N54+BxjFof+z3ODfbDdCCogqYrE3BfP1vvgBz7JnqzXFxwuyL2klOYH45hsWYn6+J VMT97KD1wDUgEJ8d2jDg64jUnEjDoPJWByJ54BJ5uLKYtGCV9lVVaU+NKgpgv9WSTK uTVJ9U//hB8I04iGw/WAdr2lJbKWmIzYmz/zs4fnJYcVQN9ZAr2gjQv/feuVM+y45U asAYZ2/0nRh0tUONSoaqjnbC9fcVpumNx/G2u15nWX9g/8d9Hldh0znMA4CT5vH3qS a5Z42qJp6LcOQqGYC2pu/lBVAjIw4ChRLC1Zqb3ulR7RlO8U/edXDQ+LJbowM/XgVL 907PHrbgSLI+w== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id D2092CE3A5B; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, Zhangjin Wu , Arnd Bergmann , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 18/53] selftests/nolibc: syscall_args: use generic __NR_statx Date: Mon, 12 Jun 2023 13:44:39 -0700 Message-Id: <20230612204514.292087-18-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhangjin Wu Compiling nolibc-test.c for rv32 got such error: tools/testing/selftests/nolibc/nolibc-test.c:599:57: error: =E2=80=98__= NR_fstat=E2=80=99 undeclared (first use in this function) 599 | CASE_TEST(syscall_args); EXPECT_SYSER(1, syscall(__NR_fs= tat, 0, NULL), -1, EFAULT); break; The generic include/uapi/asm-generic/unistd.h used by rv32 doesn't support __NR_fstat, use the more generic __NR_statx instead: Running test 'syscall' 69 syscall_noargs =3D 1 [OK] 70 syscall_args =3D -1 EFAULT [OK] __NR_statx has been added from v4.10: commit a528d35e8bfc ("statx: Add a system call to make enhanced file in= fo available") It has been supported by all of the platforms since at least from v4.20. Suggested-by: Arnd Bergmann Link: https://lore.kernel.org/linux-riscv/ee8b1f02-ded1-488b-a3a5-68774f034= 9b5@app.fastmail.com/ Signed-off-by: Zhangjin Wu Reviewed-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/testing/selftests/nolibc/nolibc-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index 54bf91847af3..0e2ee513b273 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -589,7 +589,7 @@ int run_syscall(int min, int max) CASE_TEST(write_badf); EXPECT_SYSER(1, write(-1, &tmp, 1), -1, EB= ADF); break; CASE_TEST(write_zero); EXPECT_SYSZR(1, write(1, &tmp, 0)); break; CASE_TEST(syscall_noargs); EXPECT_SYSEQ(1, syscall(__NR_getpid), getp= id()); break; - CASE_TEST(syscall_args); EXPECT_SYSER(1, syscall(__NR_fstat, 0, NUL= L), -1, EFAULT); break; + CASE_TEST(syscall_args); EXPECT_SYSER(1, syscall(__NR_statx, 0, NUL= L, 0, 0, NULL), -1, EFAULT); break; case __LINE__: return ret; /* must be last */ /* note: do not set any defaults so as to permit holes above */ --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 84462C7EE43 for ; Mon, 12 Jun 2023 20:51:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238468AbjFLUvX (ORCPT ); Mon, 12 Jun 2023 16:51:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238036AbjFLUsc (ORCPT ); Mon, 12 Jun 2023 16:48:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C43811994 for ; Mon, 12 Jun 2023 13:46:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E295562F21 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D24D3C4339B; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602716; bh=0qJdSevT2VoXww6IrwA93sMpGwJeGq5YXuzo0c9WoWA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cynU8Xf5FJnDfOAnabitMNyvFJkhhcCXHGbcwxntjMwhbsKshbGgNoH6S6n1gP6xl 2CEU0PsJNg2qXIAHRRyrtYLFch/0YwNigLS/6IjQdmdi6kb6mWC/41AhG+zTD6iTe3 Ixc7CdRDTH/5abH3RDFKoY9KTjzhmGOU3s12ZqYkfwBmu3/MuUSz+C7rAeOF7L0oKP w2eT32B/0NNyTloYi7f+oCv2VvLfqylDGnY0SJJCpEUZR8BAjeiYoLEMhkXzq+I+kx TS4EoDAoBI8M3vdVmpC5t5XvPaWiUcfvoK5Kt369lCYpNE2VVIxAB6d+s77KPcTXj2 QEy8hQ149y68g== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id D42B3CE3A5C; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 19/53] selftests/nolibc: reduce syscalls during space padding Date: Mon, 12 Jun 2023 13:44:40 -0700 Message-Id: <20230612204514.292087-19-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh Previously each space character used for alignment during test execution was written in a single write() call. This would make the output from strace fairly unreadable. Coalesce all spaces into a single call to write(). Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/testing/selftests/nolibc/nolibc-test.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index 0e2ee513b273..d5d4dea63cd6 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -111,19 +111,26 @@ const char *errorname(int err) } } =20 +static void putcharn(char c, size_t n) +{ + char buf[64]; + + memset(buf, c, n); + buf[n] =3D '\0'; + fputs(buf, stdout); +} + static int pad_spc(int llen, int cnt, const char *fmt, ...) { va_list args; - int len; int ret; =20 - for (len =3D 0; len < cnt - llen; len++) - putchar(' '); + putcharn(' ', cnt - llen); =20 va_start(args, fmt); ret =3D vfprintf(stdout, fmt, args); va_end(args); - return ret < 0 ? ret : ret + len; + return ret < 0 ? ret : ret + cnt - llen; } =20 /* The tests below are intended to be used by the macroes, which evaluate --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 AAD65C7EE2F for ; Mon, 12 Jun 2023 20:51:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238528AbjFLUvf (ORCPT ); Mon, 12 Jun 2023 16:51:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238119AbjFLUtI (ORCPT ); Mon, 12 Jun 2023 16:49:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8F13170C for ; Mon, 12 Jun 2023 13:46:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F068E62F28 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D86F5C43442; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602716; bh=Z+V/mSZIwxrjw/qqhnVpPLMMERUm+X+LueBoG1mUtCQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RK8MCXjUF86Tz9XjkMAPMucGpoVut1ztAAj5YLlv4KxmkwZAm8IU12lTlY9PRfqsA SEq2+yngy61rZNNWtPUk1WJ8dyMr0wHd+VLOKdxspoKLNtKOLD1H4IbfRFlGrs8tUA EBjjdVzsK32ZaLquy5p/99FwSgFfoa/V/pUcTqSSEreiXTfRLz3omhxegdooi5uDKD dE0jkahXPzuNWYl2fpPN7MKMHSi9zsqQixE8YnHBK4z0xGQF+duuURF8lUHl5ueQj+ lkBDj2aMKu6h9Zai8NO7RmAfC+gNdPqj7b2LAdb8L+THa6mycBCzS/jat1N0HK1Lpo JM5pn/FLaj8RQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id D64D0CE3A5E; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 20/53] tools/nolibc: aarch64: add stackprotector support Date: Mon, 12 Jun 2023 13:44:41 -0700 Message-Id: <20230612204514.292087-20-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/arch-aarch64.h | 7 ++++++- tools/testing/selftests/nolibc/Makefile | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/include/nolibc/arch-aarch64.h b/tools/include/nolibc/arc= h-aarch64.h index 76ef26520c85..6a859131c530 100644 --- a/tools/include/nolibc/arch-aarch64.h +++ b/tools/include/nolibc/arch-aarch64.h @@ -172,10 +172,15 @@ struct sys_stat_struct { char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); =20 +#define __ARCH_SUPPORTS_STACK_PROTECTOR + /* startup code */ -void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(= void) +void __attribute__((weak,noreturn,optimize("omit-frame-pointer"),no_stack_= protector)) _start(void) { __asm__ volatile ( +#ifdef NOLIBC_STACKPROTECTOR + "bl __stack_chk_init\n" /* initialize stack protector = */ +#endif "ldr x0, [sp]\n" /* argc (x0) was in the stack = */ "add x1, sp, 8\n" /* argv (x1) =3D sp = */ "lsl x2, x0, 3\n" /* envp (x2) =3D 8*argc ... = */ diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selfte= sts/nolibc/Makefile index 423d22f353a0..fa0075479a26 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -82,6 +82,7 @@ CFLAGS_STACKPROTECTOR =3D -DNOLIBC_STACKPROTECTOR \ CFLAGS_STKP_i386 =3D $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_x86_64 =3D $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_x86 =3D $(CFLAGS_STACKPROTECTOR) +CFLAGS_STKP_arm64 =3D $(CFLAGS_STACKPROTECTOR) CFLAGS_s390 =3D -m64 CFLAGS ?=3D -Os -fno-ident -fno-asynchronous-unwind-tables -std=3Dc89 \ $(call cc-option,-fno-stack-protector) \ --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 5F06EC7EE43 for ; Mon, 12 Jun 2023 20:49:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236250AbjFLUtC (ORCPT ); Mon, 12 Jun 2023 16:49:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237397AbjFLUra (ORCPT ); Mon, 12 Jun 2023 16:47:30 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8ADE2295D for ; Mon, 12 Jun 2023 13:46:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 897D1628DD for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB265C433D2; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602716; bh=EDCKj1t3cMrbH8q5QIPGb5JPV2twW1putED5vpkf138=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FO82VxxSEFUyIv6IbL2j/ZwF7wqdxAxZCuySjIOEYZpFm+iRPSQqlVhd7cK1iLu9z PUtQOtQ5+xf3gQ1ueYU/aEfYEcgOoi6b8DpNVWv19fjjaWvjHU4udUOj315FB9sFvU cTY0UT2JC76ydSvsX7GtX6MGSp4TeaRUiWSJZCiSbD+/cdUkkbJxuhu2mGtfXyf6Kj o8f76w7/xcrkM4Ei+e/yrMAvzGAinWrUxxA73tyXl4K4604fZlMfKhC5cJc8NXuwEf tZ8ZyM66Aq7yun6zbn+QpU0VzT1B+yz+489IdHkesRAZrKz7UQae91TpS82ad1ppGl F/F0LCEohcKTA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id D8799CE3A64; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 21/53] tools/nolibc: arm: add stackprotector support Date: Mon, 12 Jun 2023 13:44:42 -0700 Message-Id: <20230612204514.292087-21-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/arch-arm.h | 7 ++++++- tools/testing/selftests/nolibc/Makefile | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/include/nolibc/arch-arm.h b/tools/include/nolibc/arch-ar= m.h index 2eab1aef321b..202e64f537dc 100644 --- a/tools/include/nolibc/arch-arm.h +++ b/tools/include/nolibc/arch-arm.h @@ -199,10 +199,15 @@ struct sys_stat_struct { char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); =20 +#define __ARCH_SUPPORTS_STACK_PROTECTOR + /* startup code */ -void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(= void) +void __attribute__((weak,noreturn,optimize("omit-frame-pointer"),no_stack_= protector)) _start(void) { __asm__ volatile ( +#ifdef NOLIBC_STACKPROTECTOR + "bl __stack_chk_init\n" /* initialize stack protector = */ +#endif "pop {%r0}\n" /* argc was in the stack = */ "mov %r1, %sp\n" /* argv =3D sp = */ =20 diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selfte= sts/nolibc/Makefile index fa0075479a26..7585035cbb0d 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -83,6 +83,7 @@ CFLAGS_STKP_i386 =3D $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_x86_64 =3D $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_x86 =3D $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_arm64 =3D $(CFLAGS_STACKPROTECTOR) +CFLAGS_STKP_arm =3D $(CFLAGS_STACKPROTECTOR) CFLAGS_s390 =3D -m64 CFLAGS ?=3D -Os -fno-ident -fno-asynchronous-unwind-tables -std=3Dc89 \ $(call cc-option,-fno-stack-protector) \ --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 D53A7C7EE2F for ; Mon, 12 Jun 2023 20:51:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238515AbjFLUvc (ORCPT ); Mon, 12 Jun 2023 16:51:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238186AbjFLUtX (ORCPT ); Mon, 12 Jun 2023 16:49:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FE531BCA for ; Mon, 12 Jun 2023 13:46:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0043A62F2A for ; Mon, 12 Jun 2023 20:45:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB36DC43446; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=I2MKwbUvzTuvTg2VmUjHO7LHWoQiT/tq3IBYoDNtSDk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sepdplrRhQWPURYc5Eqxn1hVYV8IEGy/GYobS/5P/D2fHijzw8lby2q0YTYxZpYzo GZ7SWBWY8UUB4tkTStczqsAssWZQuy7j698x1Nk57vNGcwMx6NuT7jZKWKIOfYPRC6 5O/ik1/GEeLjn4G+JRPnr8JwvcuGTw8dombfevh2SJUl09C/0yFB3iSBDuK+OdutPk cyN5dOTO5P4yg2hSOoH0oYGKgwUDl9XLrn4NL9UcojSCGSktvSE+7E3uqv6+L6Am99 cf3FJ2fL0sJIJiCt5XGaE3YdPhNr+VBggsVzmMFx2fo2fG/e0fJDPxgZnwm8y/IPw2 s7Jd4pMZ8hEng== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id DA96DCE3A66; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 22/53] tools/nolibc: loongarch: add stackprotector support Date: Mon, 12 Jun 2023 13:44:43 -0700 Message-Id: <20230612204514.292087-22-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/arch-loongarch.h | 7 ++++++- tools/testing/selftests/nolibc/Makefile | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/include/nolibc/arch-loongarch.h b/tools/include/nolibc/a= rch-loongarch.h index ec3b46a991a9..07e3b1fd7262 100644 --- a/tools/include/nolibc/arch-loongarch.h +++ b/tools/include/nolibc/arch-loongarch.h @@ -149,6 +149,8 @@ char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); =20 +#define __ARCH_SUPPORTS_STACK_PROTECTOR + #if __loongarch_grlen =3D=3D 32 #define LONGLOG "2" #define SZREG "4" @@ -170,9 +172,12 @@ const unsigned long *_auxv __attribute__((weak)); #endif =20 /* startup code */ -void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(= void) +void __attribute__((weak,noreturn,optimize("omit-frame-pointer"),no_stack_= protector)) _start(void) { __asm__ volatile ( +#ifdef NOLIBC_STACKPROTECTOR + "bl __stack_chk_init\n" /* initialize stack protector = */ +#endif REG_L " $a0, $sp, 0\n" /* argc (a0) was in the stack = */ LONG_ADDI " $a1, $sp, "SZREG"\n" /* argv (a1) =3D sp + SZREG = */ LONG_SLL " $a2, $a0, "LONGLOG"\n" /* envp (a2) =3D SZREG*argc ... = */ diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selfte= sts/nolibc/Makefile index 7585035cbb0d..ab6e7c0c2494 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -84,6 +84,7 @@ CFLAGS_STKP_x86_64 =3D $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_x86 =3D $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_arm64 =3D $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_arm =3D $(CFLAGS_STACKPROTECTOR) +CFLAGS_STKP_loongarch =3D $(CFLAGS_STACKPROTECTOR) CFLAGS_s390 =3D -m64 CFLAGS ?=3D -Os -fno-ident -fno-asynchronous-unwind-tables -std=3Dc89 \ $(call cc-option,-fno-stack-protector) \ --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 8CABAC7EE2F for ; Mon, 12 Jun 2023 20:49:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238071AbjFLUs7 (ORCPT ); Mon, 12 Jun 2023 16:48:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233586AbjFLUra (ORCPT ); Mon, 12 Jun 2023 16:47:30 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2394F295A for ; Mon, 12 Jun 2023 13:46:37 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8517262F03 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D8AFBC43443; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602716; bh=tOuRtkHYs9MNwpbcUTDT/8K9pnXHgkjL97lAfJJGhgY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZNnxDU1TXOuRT3FMSlYGWrX0TkT4AnPHvMcSbWXHi5JWoxLutDnUjo15h76iV4cKW qslqvv7be++VpA8Zr3gwFpBBSiOqQblpmO5Zmed38F94zw01qMYj0ShI3GVKjca1Uk zMSSY+BHp81+3g7VxTFbVp3LEZibSYBeoubXkpLFBZsLnQ/vyPASWFl/ljpH0kHC2P SMu+jlclqrf6MsdDE++4fzt0ZmYc4NGhtLSfb3xf+CTQmSlcZdk3CGDz9cV8NKfnBd f/WP4YI79WjskRDkr5yz6J2y2Ir5xmayucKTJbE2o5qjFNuBT2bW7C/V9MSnNTMuT8 xOoUzA2A1ILZA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id DD080CE3A68; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 23/53] tools/nolibc: mips: add stackprotector support Date: Mon, 12 Jun 2023 13:44:44 -0700 Message-Id: <20230612204514.292087-23-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/arch-mips.h | 8 +++++++- tools/testing/selftests/nolibc/Makefile | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-m= ips.h index 8822f150e72f..65c19ccc7f9d 100644 --- a/tools/include/nolibc/arch-mips.h +++ b/tools/include/nolibc/arch-mips.h @@ -179,14 +179,20 @@ struct sys_stat_struct { char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); =20 +#define __ARCH_SUPPORTS_STACK_PROTECTOR + /* startup code, note that it's called __start on MIPS */ -void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __start= (void) +void __attribute__((weak,noreturn,optimize("omit-frame-pointer"),no_stack_= protector)) __start(void) { __asm__ volatile ( /*".set nomips16\n"*/ ".set push\n" ".set noreorder\n" ".option pic0\n" +#ifdef NOLIBC_STACKPROTECTOR + "jal __stack_chk_init\n" /* initialize stack protector = */ + "nop\n" /* delayed slot = */ +#endif /*".ent __start\n"*/ /*"__start:\n"*/ "lw $a0,($sp)\n" /* argc was in the stack = */ diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selfte= sts/nolibc/Makefile index ab6e7c0c2494..6d660d922240 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -84,6 +84,7 @@ CFLAGS_STKP_x86_64 =3D $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_x86 =3D $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_arm64 =3D $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_arm =3D $(CFLAGS_STACKPROTECTOR) +CFLAGS_STKP_mips =3D $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_loongarch =3D $(CFLAGS_STACKPROTECTOR) CFLAGS_s390 =3D -m64 CFLAGS ?=3D -Os -fno-ident -fno-asynchronous-unwind-tables -std=3Dc89 \ --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 55770C7EE43 for ; Mon, 12 Jun 2023 20:51:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238481AbjFLUvZ (ORCPT ); Mon, 12 Jun 2023 16:51:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238095AbjFLUtC (ORCPT ); Mon, 12 Jun 2023 16:49:02 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DCB6296B for ; Mon, 12 Jun 2023 13:46:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EEDDF62F26 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFB9DC43444; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602716; bh=GOuO4QtR996HCmcdYQAWMIyqhycVTQWVHdyq4/4h32g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hlX9DSdeVteob3wFd4346DXdfp9KfFrfNJiGAadHUIRiM6b+gRTHNEz55OCXoCxeu wcmoVXHUN/Rm6bbMMhM6nv2BgUopEg1fxrK0EwG6Qfsv524xW7vZR32zJvrsb8zDX1 S8Kct9/+0fmKNRLv2YDiwFcTcb9SCf/7yo6HKe8os/YoFWVDuwi6vTCTfRAK7ToMxu gzxchzk2GJFjeehNtu691BdXiQTsE+u4Y5NRS2nrvXgt+j7MqGtNdR/YHsRVlZiF3p thnz5Qdwc0gC3C1nxga7E+bdlSOGiRDL+LpnoNNv6T+9VKLsj3vIysP4BCnl7B97d2 T/jxKSuR7M0Eg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id DF9B1CE3A6A; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Palmer Dabbelt , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 24/53] tools/nolibc: riscv: add stackprotector support Date: Mon, 12 Jun 2023 13:44:45 -0700 Message-Id: <20230612204514.292087-24-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh Signed-off-by: Thomas Wei=C3=9Fschuh Acked-by: Palmer Dabbelt Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/arch-riscv.h | 7 ++++++- tools/testing/selftests/nolibc/Makefile | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/include/nolibc/arch-riscv.h b/tools/include/nolibc/arch-= riscv.h index 992a1739dd9c..d0439249c9c9 100644 --- a/tools/include/nolibc/arch-riscv.h +++ b/tools/include/nolibc/arch-riscv.h @@ -177,14 +177,19 @@ struct sys_stat_struct { char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); =20 +#define __ARCH_SUPPORTS_STACK_PROTECTOR + /* startup code */ -void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(= void) +void __attribute__((weak,noreturn,optimize("omit-frame-pointer"),no_stack_= protector)) _start(void) { __asm__ volatile ( ".option push\n" ".option norelax\n" "lla gp, __global_pointer$\n" ".option pop\n" +#ifdef NOLIBC_STACKPROTECTOR + "call __stack_chk_init\n" /* initialize stack protector = */ +#endif REG_L" a0, 0(sp)\n" /* argc (a0) was in the stack = */ "add a1, sp, "SZREG"\n" /* argv (a1) =3D sp = */ "slli a2, a0, "PTRLOG"\n" /* envp (a2) =3D SZREG*argc ... = */ diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selfte= sts/nolibc/Makefile index 6d660d922240..bd41102ea299 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -85,6 +85,7 @@ CFLAGS_STKP_x86 =3D $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_arm64 =3D $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_arm =3D $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_mips =3D $(CFLAGS_STACKPROTECTOR) +CFLAGS_STKP_riscv =3D $(CFLAGS_STACKPROTECTOR) CFLAGS_STKP_loongarch =3D $(CFLAGS_STACKPROTECTOR) CFLAGS_s390 =3D -m64 CFLAGS ?=3D -Os -fno-ident -fno-asynchronous-unwind-tables -std=3Dc89 \ --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 44752C7EE2F for ; Mon, 12 Jun 2023 20:51:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238575AbjFLUvl (ORCPT ); Mon, 12 Jun 2023 16:51:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238220AbjFLUtZ (ORCPT ); Mon, 12 Jun 2023 16:49:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69C5E170E for ; Mon, 12 Jun 2023 13:46:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 02CD862F2B for ; Mon, 12 Jun 2023 20:45:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2696C4339C; Mon, 12 Jun 2023 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=m54V3BXYYYooIJldJgkaYR8kVbGMqD7cVsRVfWDay0k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=spOZrdvFz0K6d+kGIjeQcrpII7KW8yKKYd3Eil3uZOUEzveFbILDXlD5w5K7Lg8Bq hRdvCF0ixWbdTjOmrpX38iUzhYwOvHj+9uput8ThlpyvdH66IIii+s37IhvOqvTEDH JnOdBnoOhwrfO4THp0cLeteQ6cpE8Wc/O5Bu/L527m/5eU61ujDV7JU3S885blSJFj lGgORVDdTGgEbx736hhMrtT0SXyeVWaV0buRAYW8glK2Cmml7FpCK/d8/98MIY56Cm +06vGQ87LDWghnGzILPya3Kt2waQ7KvmRx7ONWHeREkEVVYDqRSJ+AzTtePfv2tpDL gwqY5RIq1PtPw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id E1C2DCE3A6B; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 25/53] tools/nolibc: fix typo pint -> point Date: Mon, 12 Jun 2023 13:44:46 -0700 Message-Id: <20230612204514.292087-25-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/arch.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/include/nolibc/arch.h b/tools/include/nolibc/arch.h index 2d5386a8d6aa..82b43935650f 100644 --- a/tools/include/nolibc/arch.h +++ b/tools/include/nolibc/arch.h @@ -7,7 +7,7 @@ * the syscall declarations and the _start code definition. This is the on= ly * global part. On all architectures the kernel puts everything in the sta= ck * before jumping to _start just above us, without any return address (_st= art - * is not a function but an entry pint). So at the stack pointer we find a= rgc. + * is not a function but an entry point). So at the stack pointer we find = argc. * Then argv[] begins, and ends at the first NULL. Then we have envp which * starts and ends with a NULL as well. So envp=3Dargv+argc+1. */ --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 6986FC88CB2 for ; Mon, 12 Jun 2023 20:48:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238053AbjFLUse (ORCPT ); Mon, 12 Jun 2023 16:48:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237384AbjFLUra (ORCPT ); Mon, 12 Jun 2023 16:47:30 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A710295C for ; Mon, 12 Jun 2023 13:46:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9E46062F0B for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03E8FC433A0; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=XFbVAoZliJCAsIZtC3pxKZbS9h6xeSTohI3SMPpRFt0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T6chP21R/i3XiGgRmPpX4CX4ZHFRyynO1aN1tCDAHDWdODS/Js2M72FfrxexZqBso QRBqdL9SShZFknnwRIWjCoyKVDy5e2sQPVBWViDoK1zIcgEFsCj6PyzmoE6syLm9Kv 8nroR2RR9jbX7Q63pxcYbmSqHhtht01/wi6xutzJmA37TmjYt6yCUpXCleG3Ir8HKE yfugWe9O8lnJwAxLEdGpxj7WdWbRXKR5u0wnqhqCDHVoTGg+DrFrXX4TUBYyWLQRf7 YJWLOLq5hSW37D8CZPhRAUOQqglKKLTcr8pFZ1tCzUwgrMCs+d6K05/QNNX7xWA0XT dxBrYLAJ5mGpA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id E40AACE3A6C; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 26/53] tools/nolibc: x86_64: disable stack protector for _start Date: Mon, 12 Jun 2023 13:44:47 -0700 Message-Id: <20230612204514.292087-26-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh This was forgotten in the original submission. It is unknown why it worked for x86_64 on some compiler without this attribute. Reported-by: Willy Tarreau Closes: https://lore.kernel.org/lkml/20230520133237.GA27501@1wt.eu/ Fixes: 0d8c461adbc4 ("tools/nolibc: x86_64: add stackprotector support") Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/arch-x86_64.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/include/nolibc/arch-x86_64.h b/tools/include/nolibc/arch= -x86_64.h index d98f6c89d143..e201af15e142 100644 --- a/tools/include/nolibc/arch-x86_64.h +++ b/tools/include/nolibc/arch-x86_64.h @@ -190,7 +190,7 @@ const unsigned long *_auxv __attribute__((weak)); * 2) The deepest stack frame should be zero (the %rbp). * */ -void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(= void) +void __attribute__((weak,noreturn,optimize("omit-frame-pointer"),no_stack_= protector)) _start(void) { __asm__ volatile ( #ifdef NOLIBC_STACKPROTECTOR --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 10169C7EE43 for ; Mon, 12 Jun 2023 20:51:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236417AbjFLUvu (ORCPT ); Mon, 12 Jun 2023 16:51:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238233AbjFLUt2 (ORCPT ); Mon, 12 Jun 2023 16:49:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 358B31BFB for ; Mon, 12 Jun 2023 13:47:03 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1125062F2D for ; Mon, 12 Jun 2023 20:45:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0AFE2C43445; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=m6VW9L1DfLWVSVi0RNl6hit3N3enOx/+urG9Qu9XTN8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p0Ohgdl5koVAi4NEWD3gyKQla9v1Znt/dlMhMqbKNxXuOrDZyMlTGgp2OhL4j31H7 DdLqVvl+gc1fSiIiLDYbCL95Clf3cwRZHI40wnNnURs3TQQjPOA366vHS51bY1+V09 u3CbgcCz1kVQfKkkSkOaHn9vku+k2BWUT1ZQl16sEZXSzoUaJEAyymSmvdOhMhJfo6 HJ6dtFzW3PKq3wMkZsPUy37BJXepc8L+fkb7B90ABwOwKgSpEYvdPfTZ0IWUfzGvN9 G1Vv332VaM6wGTw+jY4jgG+571m9h+7N6yT5CFPzLVDDSd1NH0ZHgsSkmNVk3SjhTH xXSq+V8IpCQkg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id E6798CE3A6F; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 27/53] tools/nolibc: ensure stack protector guard is never zero Date: Mon, 12 Jun 2023 13:44:48 -0700 Message-Id: <20230612204514.292087-27-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh The all-zero pattern is one of the more probable out-of-bound writes so add a special case to not accidentally accept it. Also it enables the reliable detection of stack protector initialization during testing. Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/stackprotector.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/include/nolibc/stackprotector.h b/tools/include/nolibc/s= tackprotector.h index 77e5251c4490..b0156fc077a0 100644 --- a/tools/include/nolibc/stackprotector.h +++ b/tools/include/nolibc/stackprotector.h @@ -45,8 +45,9 @@ __attribute__((weak,no_stack_protector,section(".text.nol= ibc_stack_chk"))) void __stack_chk_init(void) { my_syscall3(__NR_getrandom, &__stack_chk_guard, sizeof(__stack_chk_guard)= , 0); - /* a bit more randomness in case getrandom() fails */ - __stack_chk_guard ^=3D (uintptr_t) &__stack_chk_guard; + /* a bit more randomness in case getrandom() fails, ensure the guard is n= ever 0 */ + if (__stack_chk_guard !=3D (uintptr_t) &__stack_chk_guard) + __stack_chk_guard ^=3D (uintptr_t) &__stack_chk_guard; } #endif /* defined(NOLIBC_STACKPROTECTOR) */ =20 --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 4F080C7EE43 for ; Mon, 12 Jun 2023 20:49:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238114AbjFLUtH (ORCPT ); Mon, 12 Jun 2023 16:49:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233679AbjFLUrd (ORCPT ); Mon, 12 Jun 2023 16:47:33 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C074919A7 for ; Mon, 12 Jun 2023 13:46:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A38D062F0F for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E9BFC4331E; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=NIJsLUCkPm+SlEyAKKZ+JWMSEL2gT9Xxru+zz8R8kig=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qdpXve/ZQctJnAKEwXta+3CR84M0ydiwRgzAwsMvH+1IVHWwYSAf8I9HzbiRvUT6W nEL3XqqPScLydNBucfB4/Cb4mpR/g1Y7Vtna80a8ClLUjqDHRezODsChULKNiX/6ei luDd3+JfPrEVZx35Vol9KWiwWvMGJQyvjjiweLJtztuodVVrYaLIMO51atRhVQHFkK qFpZ5OnQPZ7rbvCIAgYjoeeAHPrbiLeftANE8uGxkAbFZoM4PJPF5b7a9jekXnMmyq uEVUTxmMD17Xrm85eTlMWXeDc0vigOnVMnGYXpA/FtSVSUaG9/jJqfCit1c3KMqxKo 9f0Tw0/Q+ABew== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id E89F0CE3A70; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 28/53] tools/nolibc: add test for __stack_chk_guard initialization Date: Mon, 12 Jun 2023 13:44:49 -0700 Message-Id: <20230612204514.292087-28-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/testing/selftests/nolibc/nolibc-test.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index d5d4dea63cd6..861b9a74b71f 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -808,6 +808,14 @@ static int run_protection(int min, int max) return 0; #endif =20 +#if defined(NOLIBC_STACKPROTECTOR) + if (!__stack_chk_guard) { + llen +=3D printf("__stack_chk_guard not initialized"); + pad_spc(llen, 64, "[FAIL]\n"); + return 1; + } +#endif + pid =3D -1; pid =3D fork(); =20 --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 23E9BC7EE43 for ; Mon, 12 Jun 2023 20:49:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238127AbjFLUtL (ORCPT ); Mon, 12 Jun 2023 16:49:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235028AbjFLUrf (ORCPT ); Mon, 12 Jun 2023 16:47:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1E9E1FE0 for ; Mon, 12 Jun 2023 13:46:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A5D2D62F0C for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 155F6C4331D; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=gUcb6xxKECKBFd/6RrJssqZdkk+hQheiI8GLvg8JYiM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H0l6AqtOGHF0a1f6kc2WjhvUoZDmzs9x4t6FUnGRMy/hJj7F0i/T9ht6bsJzUByR2 3wHFaIry48mj1NL1QU0cQWu7t8j7fAA6EGG6XomAO1UgKCm7IkeUAzqIa1cdHlyhpT S+GQcQDCPZYyOkhNMmRPYTD3WC9Ndd5JhjoE7GYvzw5Y1TE4rhIW69H1QJ0RvuwSbw 1pjL1Hyxlvd0qSlO1KcN/6oE3H1yorCuipKjXlCdj3HRJbuZILl5h0JWgMg1YMkjfD juODaxffU2TKdSEdiiV5mCbrw6R1Kv6AtMDr63Gged8vbzcw9PSsRUa5q/D+3CmB/x PdFlxh+d+JF5w== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id EAD18CE3A78; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 29/53] tools/nolibc: reformat list of headers to be installed Date: Mon, 12 Jun 2023 13:44:50 -0700 Message-Id: <20230612204514.292087-29-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh This makes it easier to add and remove more entries in the future without creating spurious diff hunks. Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/Makefile | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 9839feafd38a..e37c3ac86e23 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -25,8 +25,22 @@ endif =20 nolibc_arch :=3D $(patsubst arm64,aarch64,$(ARCH)) arch_file :=3D arch-$(nolibc_arch).h -all_files :=3D ctype.h errno.h nolibc.h signal.h stackprotector.h std.h st= dint.h \ - stdio.h stdlib.h string.h sys.h time.h types.h unistd.h +all_files :=3D \ + ctype.h \ + errno.h \ + nolibc.h \ + signal.h \ + stackprotector.h \ + std.h \ + stdint.h \ + stdlib.h \ + string.h \ + sys.h \ + time.h \ + types.h \ + unistd.h \ + stdio.h \ + =20 # install all headers needed to support a bare-metal compiler all: headers --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 2D2EAC7EE2F for ; Mon, 12 Jun 2023 20:50:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237901AbjFLUtm (ORCPT ); Mon, 12 Jun 2023 16:49:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236417AbjFLUrs (ORCPT ); Mon, 12 Jun 2023 16:47:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C3D72962 for ; Mon, 12 Jun 2023 13:46:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A5F2862F13 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1806DC43321; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=Mw35BFUR7+ZznSmU98NqwI0YjsJ69pjYjKZIJHsUNFM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gocSLvBAODbkBcNotQbuYpw/q2jI3zbOB3NP3dScshtfaldm2FnQ0oOtHZUWOEQHn fsoPqwLPOQVmE1R6sdPkY653AuD6K6faZ4Dx9zDky63p98U6AkM+TWdQqnKsUipVtu 9zo41kijZOQFC6Hvg5AwM3PbBIfaM+BSv+vjv/eT9/LKe3vQLfWb9C5PU5WaCGHRV2 0YFZ+FJymFxZITVYkvE4hw/BWHqmgWaq752rDEggTXsiLJRtF7LBNugAgABUTbK21d QxtnTcM8wfu43iCMrw3N9yfV1TExIwqbMqNEbi57KXTxWwSBtcma87oOMBbptDgx83 kjiP37OUltaRQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id ED2B9CE3A79; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 30/53] tools/nolibc: add autodetection for stackprotector support Date: Mon, 12 Jun 2023 13:44:51 -0700 Message-Id: <20230612204514.292087-30-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh The stackprotector support in nolibc should be enabled iff it is also enabled in the compiler. Use the preprocessor defines added by gcc and clang if stackprotector support is enable to automatically do so in nolibc. This completely removes the need for any user-visible API. To avoid inlining the lengthy preprocessor check into every user introduce a new header compiler.h that abstracts the logic away. As the define NOLIBC_STACKPROTECTOR is now not user-relevant anymore prefix it with an underscore. Suggested-by: Willy Tarreau Link: https://lore.kernel.org/lkml/20230520133237.GA27501@1wt.eu/ Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/arch-aarch64.h | 6 +++--- tools/include/nolibc/arch-arm.h | 6 +++--- tools/include/nolibc/arch-i386.h | 6 +++--- tools/include/nolibc/arch-loongarch.h | 6 +++--- tools/include/nolibc/arch-mips.h | 6 +++--- tools/include/nolibc/arch-riscv.h | 6 +++--- tools/include/nolibc/arch-x86_64.h | 6 +++--- tools/include/nolibc/compiler.h | 15 +++++++++++++++ tools/include/nolibc/stackprotector.h | 10 +++------- tools/testing/selftests/nolibc/nolibc-test.c | 4 ++-- 11 files changed, 42 insertions(+), 30 deletions(-) create mode 100644 tools/include/nolibc/compiler.h diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index e37c3ac86e23..64d67b080744 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -26,6 +26,7 @@ endif nolibc_arch :=3D $(patsubst arm64,aarch64,$(ARCH)) arch_file :=3D arch-$(nolibc_arch).h all_files :=3D \ + compiler.h \ ctype.h \ errno.h \ nolibc.h \ diff --git a/tools/include/nolibc/arch-aarch64.h b/tools/include/nolibc/arc= h-aarch64.h index 6a859131c530..64ec65b4ee38 100644 --- a/tools/include/nolibc/arch-aarch64.h +++ b/tools/include/nolibc/arch-aarch64.h @@ -7,6 +7,8 @@ #ifndef _NOLIBC_ARCH_AARCH64_H #define _NOLIBC_ARCH_AARCH64_H =20 +#include "compiler.h" + /* The struct returned by the newfstatat() syscall. Differs slightly from = the * x86_64's stat one by field ordering, so be careful. */ @@ -172,13 +174,11 @@ struct sys_stat_struct { char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); =20 -#define __ARCH_SUPPORTS_STACK_PROTECTOR - /* startup code */ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"),no_stack_= protector)) _start(void) { __asm__ volatile ( -#ifdef NOLIBC_STACKPROTECTOR +#ifdef _NOLIBC_STACKPROTECTOR "bl __stack_chk_init\n" /* initialize stack protector = */ #endif "ldr x0, [sp]\n" /* argc (x0) was in the stack = */ diff --git a/tools/include/nolibc/arch-arm.h b/tools/include/nolibc/arch-ar= m.h index 202e64f537dc..924169522cf7 100644 --- a/tools/include/nolibc/arch-arm.h +++ b/tools/include/nolibc/arch-arm.h @@ -7,6 +7,8 @@ #ifndef _NOLIBC_ARCH_ARM_H #define _NOLIBC_ARCH_ARM_H =20 +#include "compiler.h" + /* The struct returned by the stat() syscall, 32-bit only, the syscall ret= urns * exactly 56 bytes (stops before the unused array). In big endian, the fo= rmat * differs as devices are returned as short only. @@ -199,13 +201,11 @@ struct sys_stat_struct { char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); =20 -#define __ARCH_SUPPORTS_STACK_PROTECTOR - /* startup code */ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"),no_stack_= protector)) _start(void) { __asm__ volatile ( -#ifdef NOLIBC_STACKPROTECTOR +#ifdef _NOLIBC_STACKPROTECTOR "bl __stack_chk_init\n" /* initialize stack protector = */ #endif "pop {%r0}\n" /* argc was in the stack = */ diff --git a/tools/include/nolibc/arch-i386.h b/tools/include/nolibc/arch-i= 386.h index 7c41897a08ce..37f813912957 100644 --- a/tools/include/nolibc/arch-i386.h +++ b/tools/include/nolibc/arch-i386.h @@ -7,6 +7,8 @@ #ifndef _NOLIBC_ARCH_I386_H #define _NOLIBC_ARCH_I386_H =20 +#include "compiler.h" + /* The struct returned by the stat() syscall, 32-bit only, the syscall ret= urns * exactly 56 bytes (stops before the unused array). */ @@ -181,8 +183,6 @@ struct sys_stat_struct { char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); =20 -#define __ARCH_SUPPORTS_STACK_PROTECTOR - /* startup code */ /* * i386 System V ABI mandates: @@ -193,7 +193,7 @@ const unsigned long *_auxv __attribute__((weak)); void __attribute__((weak,noreturn,optimize("omit-frame-pointer"),no_stack_= protector)) _start(void) { __asm__ volatile ( -#ifdef NOLIBC_STACKPROTECTOR +#ifdef _NOLIBC_STACKPROTECTOR "call __stack_chk_init\n" /* initialize stack protector = */ #endif "pop %eax\n" /* argc (first arg, %eax) = */ diff --git a/tools/include/nolibc/arch-loongarch.h b/tools/include/nolibc/a= rch-loongarch.h index 07e3b1fd7262..d8ea7e787df4 100644 --- a/tools/include/nolibc/arch-loongarch.h +++ b/tools/include/nolibc/arch-loongarch.h @@ -7,6 +7,8 @@ #ifndef _NOLIBC_ARCH_LOONGARCH_H #define _NOLIBC_ARCH_LOONGARCH_H =20 +#include "compiler.h" + /* Syscalls for LoongArch : * - stack is 16-byte aligned * - syscall number is passed in a7 @@ -149,8 +151,6 @@ char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); =20 -#define __ARCH_SUPPORTS_STACK_PROTECTOR - #if __loongarch_grlen =3D=3D 32 #define LONGLOG "2" #define SZREG "4" @@ -175,7 +175,7 @@ const unsigned long *_auxv __attribute__((weak)); void __attribute__((weak,noreturn,optimize("omit-frame-pointer"),no_stack_= protector)) _start(void) { __asm__ volatile ( -#ifdef NOLIBC_STACKPROTECTOR +#ifdef _NOLIBC_STACKPROTECTOR "bl __stack_chk_init\n" /* initialize stack protector = */ #endif REG_L " $a0, $sp, 0\n" /* argc (a0) was in the stack = */ diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-m= ips.h index 65c19ccc7f9d..9860236e5340 100644 --- a/tools/include/nolibc/arch-mips.h +++ b/tools/include/nolibc/arch-mips.h @@ -7,6 +7,8 @@ #ifndef _NOLIBC_ARCH_MIPS_H #define _NOLIBC_ARCH_MIPS_H =20 +#include "compiler.h" + /* The struct returned by the stat() syscall. 88 bytes are returned by the * syscall. */ @@ -179,8 +181,6 @@ struct sys_stat_struct { char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); =20 -#define __ARCH_SUPPORTS_STACK_PROTECTOR - /* startup code, note that it's called __start on MIPS */ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"),no_stack_= protector)) __start(void) { @@ -189,7 +189,7 @@ void __attribute__((weak,noreturn,optimize("omit-frame-= pointer"),no_stack_protec ".set push\n" ".set noreorder\n" ".option pic0\n" -#ifdef NOLIBC_STACKPROTECTOR +#ifdef _NOLIBC_STACKPROTECTOR "jal __stack_chk_init\n" /* initialize stack protector = */ "nop\n" /* delayed slot = */ #endif diff --git a/tools/include/nolibc/arch-riscv.h b/tools/include/nolibc/arch-= riscv.h index d0439249c9c9..86616aeb77a0 100644 --- a/tools/include/nolibc/arch-riscv.h +++ b/tools/include/nolibc/arch-riscv.h @@ -7,6 +7,8 @@ #ifndef _NOLIBC_ARCH_RISCV_H #define _NOLIBC_ARCH_RISCV_H =20 +#include "compiler.h" + struct sys_stat_struct { unsigned long st_dev; /* Device. */ unsigned long st_ino; /* File serial number. */ @@ -177,8 +179,6 @@ struct sys_stat_struct { char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); =20 -#define __ARCH_SUPPORTS_STACK_PROTECTOR - /* startup code */ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"),no_stack_= protector)) _start(void) { @@ -187,7 +187,7 @@ void __attribute__((weak,noreturn,optimize("omit-frame-= pointer"),no_stack_protec ".option norelax\n" "lla gp, __global_pointer$\n" ".option pop\n" -#ifdef NOLIBC_STACKPROTECTOR +#ifdef _NOLIBC_STACKPROTECTOR "call __stack_chk_init\n" /* initialize stack protector = */ #endif REG_L" a0, 0(sp)\n" /* argc (a0) was in the stack = */ diff --git a/tools/include/nolibc/arch-x86_64.h b/tools/include/nolibc/arch= -x86_64.h index e201af15e142..485a7ff72a87 100644 --- a/tools/include/nolibc/arch-x86_64.h +++ b/tools/include/nolibc/arch-x86_64.h @@ -7,6 +7,8 @@ #ifndef _NOLIBC_ARCH_X86_64_H #define _NOLIBC_ARCH_X86_64_H =20 +#include "compiler.h" + /* The struct returned by the stat() syscall, equivalent to stat64(). The * syscall returns 116 bytes and stops in the middle of __unused. */ @@ -181,8 +183,6 @@ struct sys_stat_struct { char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); =20 -#define __ARCH_SUPPORTS_STACK_PROTECTOR - /* startup code */ /* * x86-64 System V ABI mandates: @@ -193,7 +193,7 @@ const unsigned long *_auxv __attribute__((weak)); void __attribute__((weak,noreturn,optimize("omit-frame-pointer"),no_stack_= protector)) _start(void) { __asm__ volatile ( -#ifdef NOLIBC_STACKPROTECTOR +#ifdef _NOLIBC_STACKPROTECTOR "call __stack_chk_init\n" /* initialize stack protector = */ #endif "pop %rdi\n" /* argc (first arg, %rdi) = */ diff --git a/tools/include/nolibc/compiler.h b/tools/include/nolibc/compile= r.h new file mode 100644 index 000000000000..57da75cea799 --- /dev/null +++ b/tools/include/nolibc/compiler.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * NOLIBC compiler support header + * Copyright (C) 2023 Thomas Wei=C3=9Fschuh + */ +#ifndef _NOLIBC_COMPILER_H +#define _NOLIBC_COMPILER_H + +#if defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__) ||= defined(__SSP_EXPLICIT__) + +#define _NOLIBC_STACKPROTECTOR + +#endif /* defined(__SSP__) ... */ + +#endif /* _NOLIBC_COMPILER_H */ diff --git a/tools/include/nolibc/stackprotector.h b/tools/include/nolibc/s= tackprotector.h index b0156fc077a0..0a89e2b89ca6 100644 --- a/tools/include/nolibc/stackprotector.h +++ b/tools/include/nolibc/stackprotector.h @@ -7,13 +7,9 @@ #ifndef _NOLIBC_STACKPROTECTOR_H #define _NOLIBC_STACKPROTECTOR_H =20 -#include "arch.h" +#include "compiler.h" =20 -#if defined(NOLIBC_STACKPROTECTOR) - -#if !defined(__ARCH_SUPPORTS_STACK_PROTECTOR) -#error "nolibc does not support stack protectors on this arch" -#endif +#if defined(_NOLIBC_STACKPROTECTOR) =20 #include "sys.h" #include "stdlib.h" @@ -49,6 +45,6 @@ void __stack_chk_init(void) if (__stack_chk_guard !=3D (uintptr_t) &__stack_chk_guard) __stack_chk_guard ^=3D (uintptr_t) &__stack_chk_guard; } -#endif /* defined(NOLIBC_STACKPROTECTOR) */ +#endif /* defined(_NOLIBC_STACKPROTECTOR) */ =20 #endif /* _NOLIBC_STACKPROTECTOR_H */ diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index 861b9a74b71f..b50b5a8bcc90 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -802,13 +802,13 @@ static int run_protection(int min, int max) =20 llen +=3D printf("0 -fstackprotector "); =20 -#if !defined(NOLIBC_STACKPROTECTOR) +#if !defined(_NOLIBC_STACKPROTECTOR) llen +=3D printf("not supported"); pad_spc(llen, 64, "[SKIPPED]\n"); return 0; #endif =20 -#if defined(NOLIBC_STACKPROTECTOR) +#if defined(_NOLIBC_STACKPROTECTOR) if (!__stack_chk_guard) { llen +=3D printf("__stack_chk_guard not initialized"); pad_spc(llen, 64, "[FAIL]\n"); --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 42562C7EE2F for ; Mon, 12 Jun 2023 20:49:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238143AbjFLUtO (ORCPT ); Mon, 12 Jun 2023 16:49:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230095AbjFLUrf (ORCPT ); Mon, 12 Jun 2023 16:47:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5783B1FDD for ; Mon, 12 Jun 2023 13:46:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A4FB662F10 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1F55AC4331F; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=RJIxQIPv98cFdGnQ5M/j79pA+ccw3K7v8tVhytUfcWc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gdmqTYvSUtUw3pB9G4iaZtzICMezEbOlxH6Bnzksv0VfFchRRj6VfiF/CoPMuMR98 lhrv+xcBc/gDnBOkPiJiO1fs1PAaxSWIt+/VmMeW9EgqxRCX6868XqlxwjdwXRnZ4k AnLMDQkh/kdSjsYmlXySZJNsLPlTT15DdZo57zw7smoZLkSH5yM14WUdDGYxHrm4rD wxmmJ/dUSVvPQBM7afo4CT4t1MAdIpLs9GSR7qg6xXabsiVmazTOVKNHsJv1UbqJMB 9DFApRo9x5zixvARzzF6lK9ukRWqzWHbl8kpPKwJ1GR956dOSuRHUtwmkoIxvDEahT x+LP+fsFUurhA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id EF55FCE3A7A; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 31/53] tools/nolibc: simplify stackprotector compiler flags Date: Mon, 12 Jun 2023 13:44:52 -0700 Message-Id: <20230612204514.292087-31-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh Now that nolibc enable stackprotector support automatically when the compiler enables it we only have to get the -fstack-protector flags correct. The cc-options are structured so that -fstack-protector-all is only enabled if -mstack-protector=3Dguard works, as that is the only mode supported by nolibc. Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/testing/selftests/nolibc/Makefile | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selfte= sts/nolibc/Makefile index bd41102ea299..47c3c89092e4 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -76,21 +76,11 @@ else Q=3D@ endif =20 -CFLAGS_STACKPROTECTOR =3D -DNOLIBC_STACKPROTECTOR \ - $(call cc-option,-mstack-protector-guard=3Dglobal) \ - $(call cc-option,-fstack-protector-all) -CFLAGS_STKP_i386 =3D $(CFLAGS_STACKPROTECTOR) -CFLAGS_STKP_x86_64 =3D $(CFLAGS_STACKPROTECTOR) -CFLAGS_STKP_x86 =3D $(CFLAGS_STACKPROTECTOR) -CFLAGS_STKP_arm64 =3D $(CFLAGS_STACKPROTECTOR) -CFLAGS_STKP_arm =3D $(CFLAGS_STACKPROTECTOR) -CFLAGS_STKP_mips =3D $(CFLAGS_STACKPROTECTOR) -CFLAGS_STKP_riscv =3D $(CFLAGS_STACKPROTECTOR) -CFLAGS_STKP_loongarch =3D $(CFLAGS_STACKPROTECTOR) CFLAGS_s390 =3D -m64 +CFLAGS_STACKPROTECTOR ?=3D $(call cc-option,-mstack-protector-guard=3Dglob= al $(call cc-option,-fstack-protector-all)) CFLAGS ?=3D -Os -fno-ident -fno-asynchronous-unwind-tables -std=3Dc89 \ $(call cc-option,-fno-stack-protector) \ - $(CFLAGS_STKP_$(ARCH)) $(CFLAGS_$(ARCH)) + $(CFLAGS_$(ARCH)) $(CFLAGS_STACKPROTECTOR) LDFLAGS :=3D -s =20 help: --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 45842C88CB2 for ; Mon, 12 Jun 2023 20:51:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238651AbjFLUvz (ORCPT ); Mon, 12 Jun 2023 16:51:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238348AbjFLUtt (ORCPT ); Mon, 12 Jun 2023 16:49:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 270461FF9 for ; Mon, 12 Jun 2023 13:47:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 17C8362F2F for ; Mon, 12 Jun 2023 20:45:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 222A1C43322; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=bQS8cm6R4ZJj57jb4seR4/kdTmFK/qogLto2vrQ2RK0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gvuc8+uYT+WCMgiB9xsi9XD7tpYo8Zq6fFhBt/EZw2SAoh8Ol5VXxiF1htD3HsNAh eJezIx3fKjwXlVsowJhWJPGhFua79KnPlRTK6pb+8lBPZ3+OMobgL2NUWJpLVzU5cv hcIYxaB4njxK6k8SX6RM9f/flHgseejA/rqyMZxcY/dKbdHl90+o46a5SX8irQj98Z oP0wRyHKAXnxkCw69P72lqI2eGtZ7aT71nA+3HQPHZUK9x0y+q/tzsXj/1Uy135SFj jFz58wjWAMBWP8dfU9Xe4jf44GbonmDGIU+VrEfJSQ5BqU7gmZYm+q7FBIuijy8oX7 6RvLz+1g7HxMA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id F1AD2CE3A7B; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 32/53] tools/nolibc: fix segfaults on compilers without attribute no_stack_protector Date: Mon, 12 Jun 2023 13:44:53 -0700 Message-Id: <20230612204514.292087-32-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh Not all compilers, notably GCC < 10, have support for __attribute__((no_stack_protector)). Fall back to a mechanism that also works there. Tested with GCC 9.5.0 from kernel.org crosstools. Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/arch-aarch64.h | 2 +- tools/include/nolibc/arch-arm.h | 2 +- tools/include/nolibc/arch-i386.h | 2 +- tools/include/nolibc/arch-loongarch.h | 2 +- tools/include/nolibc/arch-mips.h | 2 +- tools/include/nolibc/arch-riscv.h | 2 +- tools/include/nolibc/arch-x86_64.h | 2 +- tools/include/nolibc/compiler.h | 10 ++++++++++ tools/include/nolibc/stackprotector.h | 2 +- 9 files changed, 18 insertions(+), 8 deletions(-) diff --git a/tools/include/nolibc/arch-aarch64.h b/tools/include/nolibc/arc= h-aarch64.h index 64ec65b4ee38..11f294a406b7 100644 --- a/tools/include/nolibc/arch-aarch64.h +++ b/tools/include/nolibc/arch-aarch64.h @@ -175,7 +175,7 @@ char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); =20 /* startup code */ -void __attribute__((weak,noreturn,optimize("omit-frame-pointer"),no_stack_= protector)) _start(void) +void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_st= ack_protector _start(void) { __asm__ volatile ( #ifdef _NOLIBC_STACKPROTECTOR diff --git a/tools/include/nolibc/arch-arm.h b/tools/include/nolibc/arch-ar= m.h index 924169522cf7..45b89ffe8247 100644 --- a/tools/include/nolibc/arch-arm.h +++ b/tools/include/nolibc/arch-arm.h @@ -202,7 +202,7 @@ char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); =20 /* startup code */ -void __attribute__((weak,noreturn,optimize("omit-frame-pointer"),no_stack_= protector)) _start(void) +void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_st= ack_protector _start(void) { __asm__ volatile ( #ifdef _NOLIBC_STACKPROTECTOR diff --git a/tools/include/nolibc/arch-i386.h b/tools/include/nolibc/arch-i= 386.h index 37f813912957..3d672d925e9e 100644 --- a/tools/include/nolibc/arch-i386.h +++ b/tools/include/nolibc/arch-i386.h @@ -190,7 +190,7 @@ const unsigned long *_auxv __attribute__((weak)); * 2) The deepest stack frame should be set to zero * */ -void __attribute__((weak,noreturn,optimize("omit-frame-pointer"),no_stack_= protector)) _start(void) +void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_st= ack_protector _start(void) { __asm__ volatile ( #ifdef _NOLIBC_STACKPROTECTOR diff --git a/tools/include/nolibc/arch-loongarch.h b/tools/include/nolibc/a= rch-loongarch.h index d8ea7e787df4..ad3f266e7093 100644 --- a/tools/include/nolibc/arch-loongarch.h +++ b/tools/include/nolibc/arch-loongarch.h @@ -172,7 +172,7 @@ const unsigned long *_auxv __attribute__((weak)); #endif =20 /* startup code */ -void __attribute__((weak,noreturn,optimize("omit-frame-pointer"),no_stack_= protector)) _start(void) +void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_st= ack_protector _start(void) { __asm__ volatile ( #ifdef _NOLIBC_STACKPROTECTOR diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-m= ips.h index 9860236e5340..db24e0837a39 100644 --- a/tools/include/nolibc/arch-mips.h +++ b/tools/include/nolibc/arch-mips.h @@ -182,7 +182,7 @@ char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); =20 /* startup code, note that it's called __start on MIPS */ -void __attribute__((weak,noreturn,optimize("omit-frame-pointer"),no_stack_= protector)) __start(void) +void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_st= ack_protector __start(void) { __asm__ volatile ( /*".set nomips16\n"*/ diff --git a/tools/include/nolibc/arch-riscv.h b/tools/include/nolibc/arch-= riscv.h index 86616aeb77a0..a2e8564e66d6 100644 --- a/tools/include/nolibc/arch-riscv.h +++ b/tools/include/nolibc/arch-riscv.h @@ -180,7 +180,7 @@ char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); =20 /* startup code */ -void __attribute__((weak,noreturn,optimize("omit-frame-pointer"),no_stack_= protector)) _start(void) +void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_st= ack_protector _start(void) { __asm__ volatile ( ".option push\n" diff --git a/tools/include/nolibc/arch-x86_64.h b/tools/include/nolibc/arch= -x86_64.h index 485a7ff72a87..6fc4d8392742 100644 --- a/tools/include/nolibc/arch-x86_64.h +++ b/tools/include/nolibc/arch-x86_64.h @@ -190,7 +190,7 @@ const unsigned long *_auxv __attribute__((weak)); * 2) The deepest stack frame should be zero (the %rbp). * */ -void __attribute__((weak,noreturn,optimize("omit-frame-pointer"),no_stack_= protector)) _start(void) +void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_st= ack_protector _start(void) { __asm__ volatile ( #ifdef _NOLIBC_STACKPROTECTOR diff --git a/tools/include/nolibc/compiler.h b/tools/include/nolibc/compile= r.h index 57da75cea799..beddc3665d69 100644 --- a/tools/include/nolibc/compiler.h +++ b/tools/include/nolibc/compiler.h @@ -12,4 +12,14 @@ =20 #endif /* defined(__SSP__) ... */ =20 +#if defined(__has_attribute) +# if __has_attribute(no_stack_protector) +# define __no_stack_protector __attribute__((no_stack_protector)) +# else +# define __no_stack_protector __attribute__((__optimize__("-fno-stack-p= rotector"))) +# endif +#else +# define __no_stack_protector __attribute__((__optimize__("-fno-stack-pro= tector"))) +#endif /* defined(__has_attribute) */ + #endif /* _NOLIBC_COMPILER_H */ diff --git a/tools/include/nolibc/stackprotector.h b/tools/include/nolibc/s= tackprotector.h index 0a89e2b89ca6..88f7b2d098ff 100644 --- a/tools/include/nolibc/stackprotector.h +++ b/tools/include/nolibc/stackprotector.h @@ -37,7 +37,7 @@ void __stack_chk_fail_local(void) __attribute__((weak,section(".data.nolibc_stack_chk"))) uintptr_t __stack_chk_guard; =20 -__attribute__((weak,no_stack_protector,section(".text.nolibc_stack_chk"))) +__attribute__((weak,section(".text.nolibc_stack_chk"))) __no_stack_protect= or void __stack_chk_init(void) { my_syscall3(__NR_getrandom, &__stack_chk_guard, sizeof(__stack_chk_guard)= , 0); --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 50082C7EE2F for ; Mon, 12 Jun 2023 20:49:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238160AbjFLUtR (ORCPT ); Mon, 12 Jun 2023 16:49:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235962AbjFLUrh (ORCPT ); Mon, 12 Jun 2023 16:47:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83A201981 for ; Mon, 12 Jun 2023 13:46:43 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A91AD62F14 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2284FC43324; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=651zibUdG42x8RfDbrif5fkpzpSwW8yz5Rd3sGWo/wk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a82OsQVlu7us9TzK3FQuGOYW/U69y0waSi8CHJl+1cQ/k8Zrh2qSO6nyHbJbtGOo/ U738RkKgw7v9ZZlrNS+SDLTXUZ0TB8/KqSDtfoQxK0hPrtyyFDULmNCtmKD4WtqAQL Akg0Sg4YXl6jaMbbLkFs9iLuw+vo+VkCnknM+Z6KagWZpn+bfkjnRd+vB7jEyB0Yks xc1l1aB3YpbB1pjK6UVysvg4CautgASiGi5Ym7FByQf/X+Ttb9EordiGoJz8hLiE40 CIn0GU7VNKfudSq4tbFS7ujQokszZK+F2zYTSiq/VZR5ER//IVK+Q6OVIJVtA+tWq7 sBo+bB2MYKaFw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id F3E23CE3A7C; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 33/53] tools/nolibc: s390: disable stackprotector in _start Date: Mon, 12 Jun 2023 13:44:54 -0700 Message-Id: <20230612204514.292087-33-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh s390 does not support the "global" stack protector mode that is implemented in nolibc. Now that nolibc detects if stack protectors are enabled at runtime it could happen that a future compiler does indeed use global mode on and nolibc would compile but segfault at runtime. To avoid this hypothetic case and to align s390 with the other architectures disable stack protectors when compiling _start(). Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/arch-s390.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/include/nolibc/arch-s390.h b/tools/include/nolibc/arch-s= 390.h index a738e7f3f8e8..516dff5bff8b 100644 --- a/tools/include/nolibc/arch-s390.h +++ b/tools/include/nolibc/arch-s390.h @@ -8,6 +8,8 @@ #include #include =20 +#include "compiler.h" + /* The struct returned by the stat() syscall, equivalent to stat64(). The * syscall returns 116 bytes and stops in the middle of __unused. */ @@ -164,7 +166,7 @@ char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); =20 /* startup code */ -void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(= void) +void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_st= ack_protector _start(void) { __asm__ volatile ( "lg %r2,0(%r15)\n" /* argument count */ --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 375CDC88CB2 for ; Mon, 12 Jun 2023 20:49:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238180AbjFLUtU (ORCPT ); Mon, 12 Jun 2023 16:49:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237673AbjFLUrq (ORCPT ); Mon, 12 Jun 2023 16:47:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D52C1BE5 for ; Mon, 12 Jun 2023 13:46:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A99C062F16 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2BDEBC43325; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=N9vHg92hQf/Gt8IdTsnnfWQj4zqBnDUs4128W6vih/M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iBqkFKk36EhtaWtPZU3rgUuxmTtfv97JaYZTgokAM7xcRt/22Jd6rGrNGFPWOBG63 xO4W8Cww3Yh5hfTupDtDNm0birqBzS4PNmnAtJpZnPST7SAICqEIZPgQO6HIoAp0qG H2F2Yt6Ef/HxDEyry02VutbT0YRSKV1RnwldHrd+caLpGfUxGTULdxUZUtbDHZF0WU +Z7ltdnbFdZvH7aPjVONZJQVNBWSg1QqWspwR+//JJQSslcD1lklBs/5DpQ0ZNQ4G7 TjlsYXhWa3n0PN1oLzbza6wdU3Z8zjZVYgai71XbHhyAiUQUfyhAHYpeilM1hrOhSj uNLF9+M2qEsCA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 01E0ACE3A7D; Mon, 12 Jun 2023 13:45:16 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 34/53] tools/nolibc: add support for prctl() Date: Mon, 12 Jun 2023 13:44:55 -0700 Message-Id: <20230612204514.292087-34-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh It will be used to disable core dumps from the child spawned to validate the stack protector functionality. Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/sys.h | 27 ++++++++++++++++++++ tools/testing/selftests/nolibc/nolibc-test.c | 2 ++ 2 files changed, 29 insertions(+) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index d5792a5de70b..c688b410f9e4 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -22,6 +22,7 @@ #include /* for O_* and AT_* */ #include /* for statx() */ #include /* for LINUX_REBOOT_* */ +#include =20 #include "arch.h" #include "errno.h" @@ -875,6 +876,32 @@ int open(const char *path, int flags, ...) } =20 =20 +/* + * int prctl(int option, unsigned long arg2, unsigned long arg3, + * unsigned long arg4, unsigned long arg5); + */ + +static __attribute__((unused)) +int sys_prctl(int option, unsigned long arg2, unsigned long arg3, + unsigned long arg4, unsigned long arg5) +{ + return my_syscall5(__NR_prctl, option, arg2, arg3, arg4, arg5); +} + +static __attribute__((unused)) +int prctl(int option, unsigned long arg2, unsigned long arg3, + unsigned long arg4, unsigned long arg5) +{ + int ret =3D sys_prctl(option, arg2, arg3, arg4, arg5); + + if (ret < 0) { + SET_ERRNO(-ret); + ret =3D -1; + } + return ret; +} + + /* * int pivot_root(const char *new, const char *old); */ diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index b50b5a8bcc90..6db788603a34 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -580,6 +581,7 @@ int run_syscall(int min, int max) CASE_TEST(poll_null); EXPECT_SYSZR(1, poll(NULL, 0, 0)); break; CASE_TEST(poll_stdout); EXPECT_SYSNE(1, ({ struct pollfd fds =3D {= 1, POLLOUT, 0}; poll(&fds, 1, 0); }), -1); break; CASE_TEST(poll_fault); EXPECT_SYSER(1, poll((void *)1, 1, 0), -1,= EFAULT); break; + CASE_TEST(prctl); EXPECT_SYSER(1, prctl(PR_SET_NAME, (unsign= ed long)NULL, 0, 0, 0), -1, EFAULT); break; CASE_TEST(read_badf); EXPECT_SYSER(1, read(-1, &tmp, 1), -1, EBA= DF); break; CASE_TEST(sched_yield); EXPECT_SYSZR(1, sched_yield()); break; CASE_TEST(select_null); EXPECT_SYSZR(1, ({ struct timeval tv =3D {= 0 }; select(0, NULL, NULL, NULL, &tv); })); break; --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 BAB4CC7EE43 for ; Mon, 12 Jun 2023 20:51:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236654AbjFLUvw (ORCPT ); Mon, 12 Jun 2023 16:51:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238368AbjFLUtu (ORCPT ); Mon, 12 Jun 2023 16:49:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 500482106 for ; Mon, 12 Jun 2023 13:47:06 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1E5E262BED for ; Mon, 12 Jun 2023 20:45:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E690C43323; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=YSnDd8eIZWAVVkXrAR2iFLMVAjImLZBexFy3GV2smU4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jqPbOGExUPnvOck2RN1WO9wxecIiO7nVEipYAmWrLM6powvhfty5dd2arfDL8o8MK +rnU6nV/FKY19zKCzDsWkSXE6UYVNpsn6S7qpgOF8tmC2zYLG1iainbN3FyMQm2+GQ swvICHPmRQp/6/PWmXyRORqLAO/z97YwdosPE6+0ippOcXn3wfmL/2RniVpZurM0Yk GUzVjbI/A5s6waLiD7OXvNYdy8Fdh9dSRtJSyaqU5Q7pVkFfB03vmEETUyG8GzYxEK 3pC5b7u8lReTcOx2+b0rqrvkoFUDwip9ZwcxnDGnC9eWQYQq8O5dvmejxGTmVW5X6I meIOnIg89Zmrw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 0423DCE3A7E; Mon, 12 Jun 2023 13:45:16 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 35/53] selftests/nolibc: prevent coredumps during test execution Date: Mon, 12 Jun 2023 13:44:56 -0700 Message-Id: <20230612204514.292087-35-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh The child process forked during stackprotector tests intentionally gets killed with SIGABRT. By default this will trigger writing a coredump. The writing of the coredump can spam the systems coredump machinery and take some time. Timings for the full run of nolibc-test: Before: 200ms After: 20ms This is on a desktop x86 system with systemd-coredumpd enabled. Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/testing/selftests/nolibc/nolibc-test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index 6db788603a34..84a1b02eb6f9 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -831,6 +831,7 @@ static int run_protection(int min, int max) close(STDOUT_FILENO); close(STDERR_FILENO); =20 + prctl(PR_SET_DUMPABLE, 0, 0, 0, 0); smash_stack(); return 1; =20 --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 15E6DC7EE43 for ; Mon, 12 Jun 2023 20:49:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238251AbjFLUte (ORCPT ); Mon, 12 Jun 2023 16:49:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237701AbjFLUrs (ORCPT ); Mon, 12 Jun 2023 16:47:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33E0E2960 for ; Mon, 12 Jun 2023 13:46:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id ACDD662F12 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30C26C43327; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=3kluAJ78NXxdpTo6ccwYTg3Vy1h0KV1jojs/dLdw/p4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ray7trlhxNf6u6xWdY2QyahrNaycAxH2B3GGOIJ9T/7ng6GBQXBqg+XlfB6IubxPY zoFomVawpHhbXE0PbDJXzSdBX5ZGBq1WLAigivSc7ckUSr4f41omcDrX3uXiBB2GV6 S3cDwlALZ88dbGzeTstLX2KSetup29fS867VpfcD9pUhK5oXEfWikaCQ9fx2irB8sl Y3t703NcJ6Nz5X4Kda+lEmlDviz7VoPnhtjX02nXL47fU3nFa0Xj3jysXO1jy7fuTJ 18t3MBsb+lony/zEmPGBEwVp+UbcPalcc4CgLaZCQjfSSMtU+M7gH4ibCmtkNkuhI4 +05wDlBsYi/Xg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 06B33CE3A7F; Mon, 12 Jun 2023 13:45:16 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Zhangjin Wu , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 36/53] tools/nolibc: support nanoseconds in stat() Date: Mon, 12 Jun 2023 13:44:57 -0700 Message-Id: <20230612204514.292087-36-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh Keep backwards compatibility through unions. The compatibility macros like #define st_atime st_atim.tv_sec as documented in stat(3type) don't work for nolibc because it would break with other stat-like structures that contain the field st_atime. The stx_atime, stx_mtime, stx_ctime are in type of 'struct statx_timestamp', which is incompatible with 'struct timespec', should be converted explicitly. /* include/uapi/linux/stat.h */ struct statx_timestamp { __s64 tv_sec; __u32 tv_nsec; __s32 __reserved; }; /* include/uapi/linux/time.h */ struct timespec { __kernel_old_time_t tv_sec; /* seconds */ long tv_nsec; /* nanoseconds */ }; Signed-off-by: Thomas Wei=C3=9Fschuh Link: https://lore.kernel.org/linux-riscv/3a3edd48-1ace-4c89-89e8-9c594dd1b= 3c9@t-8ch.de/ Co-authored-by: Zhangjin Wu Signed-off-by: Zhangjin Wu [wt: squashed Zhangjin & Thomas' patches into one to preserve "bisectabilit= y"] Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/sys.h | 66 +++++++++++--------- tools/include/nolibc/types.h | 6 +- tools/testing/selftests/nolibc/nolibc-test.c | 23 +++++++ 3 files changed, 62 insertions(+), 33 deletions(-) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index c688b410f9e4..7836d7e7760d 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -1161,23 +1161,26 @@ int sys_stat(const char *path, struct stat *buf) long ret; =20 ret =3D sys_statx(AT_FDCWD, path, AT_NO_AUTOMOUNT, STATX_BASIC_STATS, &st= atx); - buf->st_dev =3D ((statx.stx_dev_minor & 0xff) - | (statx.stx_dev_major << 8) - | ((statx.stx_dev_minor & ~0xff) << 12)); - buf->st_ino =3D statx.stx_ino; - buf->st_mode =3D statx.stx_mode; - buf->st_nlink =3D statx.stx_nlink; - buf->st_uid =3D statx.stx_uid; - buf->st_gid =3D statx.stx_gid; - buf->st_rdev =3D ((statx.stx_rdev_minor & 0xff) - | (statx.stx_rdev_major << 8) - | ((statx.stx_rdev_minor & ~0xff) << 12)); - buf->st_size =3D statx.stx_size; - buf->st_blksize =3D statx.stx_blksize; - buf->st_blocks =3D statx.stx_blocks; - buf->st_atime =3D statx.stx_atime.tv_sec; - buf->st_mtime =3D statx.stx_mtime.tv_sec; - buf->st_ctime =3D statx.stx_ctime.tv_sec; + buf->st_dev =3D ((statx.stx_dev_minor & 0xff) + | (statx.stx_dev_major << 8) + | ((statx.stx_dev_minor & ~0xff) << 12)); + buf->st_ino =3D statx.stx_ino; + buf->st_mode =3D statx.stx_mode; + buf->st_nlink =3D statx.stx_nlink; + buf->st_uid =3D statx.stx_uid; + buf->st_gid =3D statx.stx_gid; + buf->st_rdev =3D ((statx.stx_rdev_minor & 0xff) + | (statx.stx_rdev_major << 8) + | ((statx.stx_rdev_minor & ~0xff) << 12)); + buf->st_size =3D statx.stx_size; + buf->st_blksize =3D statx.stx_blksize; + buf->st_blocks =3D statx.stx_blocks; + buf->st_atim.tv_sec =3D statx.stx_atime.tv_sec; + buf->st_atim.tv_nsec =3D statx.stx_atime.tv_nsec; + buf->st_mtim.tv_sec =3D statx.stx_mtime.tv_sec; + buf->st_mtim.tv_nsec =3D statx.stx_mtime.tv_nsec; + buf->st_ctim.tv_sec =3D statx.stx_ctime.tv_sec; + buf->st_ctim.tv_nsec =3D statx.stx_ctime.tv_nsec; return ret; } #else @@ -1195,19 +1198,22 @@ int sys_stat(const char *path, struct stat *buf) #else #error Neither __NR_newfstatat nor __NR_stat defined, cannot implement sys= _stat() #endif - buf->st_dev =3D stat.st_dev; - buf->st_ino =3D stat.st_ino; - buf->st_mode =3D stat.st_mode; - buf->st_nlink =3D stat.st_nlink; - buf->st_uid =3D stat.st_uid; - buf->st_gid =3D stat.st_gid; - buf->st_rdev =3D stat.st_rdev; - buf->st_size =3D stat.st_size; - buf->st_blksize =3D stat.st_blksize; - buf->st_blocks =3D stat.st_blocks; - buf->st_atime =3D stat.st_atime; - buf->st_mtime =3D stat.st_mtime; - buf->st_ctime =3D stat.st_ctime; + buf->st_dev =3D stat.st_dev; + buf->st_ino =3D stat.st_ino; + buf->st_mode =3D stat.st_mode; + buf->st_nlink =3D stat.st_nlink; + buf->st_uid =3D stat.st_uid; + buf->st_gid =3D stat.st_gid; + buf->st_rdev =3D stat.st_rdev; + buf->st_size =3D stat.st_size; + buf->st_blksize =3D stat.st_blksize; + buf->st_blocks =3D stat.st_blocks; + buf->st_atim.tv_sec =3D stat.st_atime; + buf->st_atim.tv_nsec =3D stat.st_atime_nsec; + buf->st_mtim.tv_sec =3D stat.st_mtime; + buf->st_mtim.tv_nsec =3D stat.st_mtime_nsec; + buf->st_ctim.tv_sec =3D stat.st_ctime; + buf->st_ctim.tv_nsec =3D stat.st_ctime_nsec; return ret; } #endif diff --git a/tools/include/nolibc/types.h b/tools/include/nolibc/types.h index 15b0baffd336..f96e28bff4ba 100644 --- a/tools/include/nolibc/types.h +++ b/tools/include/nolibc/types.h @@ -198,9 +198,9 @@ struct stat { off_t st_size; /* total size, in bytes */ blksize_t st_blksize; /* blocksize for file system I/O */ blkcnt_t st_blocks; /* number of 512B blocks allocated */ - time_t st_atime; /* time of last access */ - time_t st_mtime; /* time of last modification */ - time_t st_ctime; /* time of last status change */ + union { time_t st_atime; struct timespec st_atim; }; /* time of last acce= ss */ + union { time_t st_mtime; struct timespec st_mtim; }; /* time of last modi= fication */ + union { time_t st_ctime; struct timespec st_ctim; }; /* time of last stat= us change */ }; =20 /* WARNING, it only deals with the 4096 first majors and 256 first minors = */ diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index 84a1b02eb6f9..0d76790ffb0d 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -501,6 +501,28 @@ static int test_fork(void) } } =20 +static int test_stat_timestamps(void) +{ + struct stat st; + + if (sizeof(st.st_atim.tv_sec) !=3D sizeof(st.st_atime)) + return 1; + + if (stat("/proc/self/", &st)) + return 1; + + if (st.st_atim.tv_sec !=3D st.st_atime || st.st_atim.tv_nsec > 1000000000) + return 1; + + if (st.st_mtim.tv_sec !=3D st.st_mtime || st.st_mtim.tv_nsec > 1000000000) + return 1; + + if (st.st_ctim.tv_sec !=3D st.st_ctime || st.st_ctim.tv_nsec > 1000000000) + return 1; + + return 0; +} + /* Run syscall tests between IDs and . * Return 0 on success, non-zero on failure. */ @@ -589,6 +611,7 @@ int run_syscall(int min, int max) CASE_TEST(select_fault); EXPECT_SYSER(1, select(1, (void *)1, NULL,= NULL, 0), -1, EFAULT); break; CASE_TEST(stat_blah); EXPECT_SYSER(1, stat("/proc/self/blah", &s= tat_buf), -1, ENOENT); break; CASE_TEST(stat_fault); EXPECT_SYSER(1, stat(NULL, &stat_buf), -1,= EFAULT); break; + CASE_TEST(stat_timestamps); EXPECT_SYSZR(1, test_stat_timestamps()); b= reak; CASE_TEST(symlink_root); EXPECT_SYSER(1, symlink("/", "/"), -1, EEX= IST); break; CASE_TEST(unlink_root); EXPECT_SYSER(1, unlink("/"), -1, EISDIR); = break; CASE_TEST(unlink_blah); EXPECT_SYSER(1, unlink("/proc/self/blah"),= -1, ENOENT); break; --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 EECF4C7EE2F for ; Mon, 12 Jun 2023 20:52:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237673AbjFLUwD (ORCPT ); Mon, 12 Jun 2023 16:52:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238401AbjFLUtw (ORCPT ); Mon, 12 Jun 2023 16:49:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D10C92970 for ; Mon, 12 Jun 2023 13:47:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 21C9E62F32 for ; Mon, 12 Jun 2023 20:45:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3604FC43326; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=9y+4Vs4tWIeKkTf1j6wqeFXVqgqDpdnK6mjpgkb8zFc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OrRYsNW5i87RnzyJNUNbdbN80H+bXi6JFft5tA+X7QuwV7VwKSBcmV7H7S26d/pFU Vyx4wVzzcuWPaOvDQfAi5KXJeIWwTkoedCtRSt5SsKIAQ1+RN1dU/Se13wWW07y8hm 7q0ctKCyXYJrogFIQCt/EVmEOT9cCCKwM2REz9I8CkvR9z9WOUZcNfDQk3oCduv3xr jcSKGVgWrwdU5ZalP9I07PvQ1Qn4Q55Snzr9ckt0vQJdOyYJ92Ca9Lvwbkq2/o0Mng HVWb1Apw1iPs8AlaETBsEbdPduPGRcclmbdquSXJDi5lHHlwxM1zmHly1Cn3uZnskR XtDvwQ4S8YePQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 090E6CE3A80; Mon, 12 Jun 2023 13:45:16 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, Zhangjin Wu , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 37/53] selftests/nolibc: print name instead of number for EOVERFLOW Date: Mon, 12 Jun 2023 13:44:58 -0700 Message-Id: <20230612204514.292087-37-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhangjin Wu EOVERFLOW will be used in the coming time64 syscalls support. Signed-off-by: Zhangjin Wu Reviewed-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/testing/selftests/nolibc/nolibc-test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index 0d76790ffb0d..ffdf1e8c305c 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -107,6 +107,7 @@ const char *errorname(int err) CASE_ERR(EDOM); CASE_ERR(ERANGE); CASE_ERR(ENOSYS); + CASE_ERR(EOVERFLOW); default: return itoa(err); } --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 398C5C7EE2F for ; Mon, 12 Jun 2023 20:49:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229639AbjFLUt3 (ORCPT ); Mon, 12 Jun 2023 16:49:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237693AbjFLUrs (ORCPT ); Mon, 12 Jun 2023 16:47:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BEC02961 for ; Mon, 12 Jun 2023 13:46:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B336362F17 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 390DEC43329; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=xokCziXLY0wg8Xt5fKYpSkuWrnPGYJ0bTQ1zvGDvk1o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hcNK4cKfVeMexgNye0UAvuYqAGadB2wQUEiBAVuVCQ2Ti00E1VtWUueWjjmZVJ32g Xc7gzAyo3SVELeUx5SZ+uQV5ljrYTdAq6f+IcKYkOFOTGdAxE9+AGxwb7nBVGRlq75 x/AFXKv9vN/UWtNWjzAvNJHkUzzK7MEqNnkpa6rCLZ9o8ccU6Jsjz8aZI7rkvtQM2D W12VSeTG4MyLYXQ9OnDpCTeqe3OyjJ+ifQHDZVkWOpXKqrB8zEv5EB6RvQAdpUQ2sD p4pXcRBbmxGnGGsyrGxGIy+BIt06VEarzV8jHL4uZbqtWb/h7gMl6MBofLjedLBLeR CErAd6NPDo/PQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 0BAD4CE3A81; Mon, 12 Jun 2023 13:45:16 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, Zhangjin Wu , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 38/53] selftests/nolibc: remove the duplicated gettimeofday_bad2 Date: Mon, 12 Jun 2023 13:44:59 -0700 Message-Id: <20230612204514.292087-38-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Zhangjin Wu There were two exactly similar occurrences of this test. Signed-off-by: Zhangjin Wu Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/testing/selftests/nolibc/nolibc-test.c | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index ffdf1e8c305c..d417ca5d976f 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -587,7 +587,6 @@ int run_syscall(int min, int max) #ifdef NOLIBC CASE_TEST(gettimeofday_bad1); EXPECT_SYSER(1, gettimeofday((void *)1, NU= LL), -1, EFAULT); break; CASE_TEST(gettimeofday_bad2); EXPECT_SYSER(1, gettimeofday(NULL, (void *= )1), -1, EFAULT); break; - CASE_TEST(gettimeofday_bad2); EXPECT_SYSER(1, gettimeofday(NULL, (void *= )1), -1, EFAULT); break; #endif CASE_TEST(getpagesize); EXPECT_SYSZR(1, test_getpagesize()); break; CASE_TEST(ioctl_tiocinq); EXPECT_SYSZR(1, ioctl(0, TIOCINQ, &tmp)); = break; --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 780B6C7EE2F for ; Mon, 12 Jun 2023 20:51:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238664AbjFLUv6 (ORCPT ); Mon, 12 Jun 2023 16:51:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238402AbjFLUtw (ORCPT ); Mon, 12 Jun 2023 16:49:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E170E296F for ; Mon, 12 Jun 2023 13:47:07 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 220A162F35 for ; Mon, 12 Jun 2023 20:45:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FBCEC43328; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=/HEE7wLoU0aARylBa78hxj5pmV8p3SLHOC7ItTxKH/E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tihZiaNXAFPQV8WTdLoz1e8HNDHvHyM/vmV+hRjqOcMSvSXozg1Dvc/PBJG3aQrNh EL7VCkgaO/qD379Ji2euUx5IyGyf6FcxXy9/zgmcly7JIKwsgyFs/o3tX2PtLDY6h/ Z6D6Te0V3tPh4qYsJP3DPJp4OWWLbfYqVMTqLsH2xrwblhYckqtBPeydIafUqJdLcI +4ADVLzjaw1LoPuEBMTJLKKxN0LfMUyRcCELguDn3+RbqkLI16rkiFY37HTR3nunn8 jHGVbXr/MDczb+1vXBoB0WA8K07MvowhhJfEwIxLRFIM4EB3tPJFX4Iri60T4JvEqL kGarpICXDGIzA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 0DE96CE3A84; Mon, 12 Jun 2023 13:45:16 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, Zhangjin Wu , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 39/53] tools/nolibc: ppoll/ppoll_time64: add a missing argument Date: Mon, 12 Jun 2023 13:45:00 -0700 Message-Id: <20230612204514.292087-39-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Zhangjin Wu The ppoll and ppoll_time64 syscalls have 5 arguments, but we only provide 4, align with kernel and add the missing sigsetsize argument. Because the sigmask is NULL, the last sigsetsize argument is ignored, keep it as 0 here is safe enough. Signed-off-by: Zhangjin Wu Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/sys.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 7836d7e7760d..0160605444e7 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -939,7 +939,7 @@ int sys_poll(struct pollfd *fds, int nfds, int timeout) t.tv_sec =3D timeout / 1000; t.tv_nsec =3D (timeout % 1000) * 1000000; } - return my_syscall4(__NR_ppoll, fds, nfds, (timeout >=3D 0) ? &t : NULL, N= ULL); + return my_syscall5(__NR_ppoll, fds, nfds, (timeout >=3D 0) ? &t : NULL, N= ULL, 0); #elif defined(__NR_poll) return my_syscall3(__NR_poll, fds, nfds, timeout); #else --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 A4F87C7EE43 for ; Mon, 12 Jun 2023 20:50:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238319AbjFLUtr (ORCPT ); Mon, 12 Jun 2023 16:49:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232598AbjFLUrs (ORCPT ); Mon, 12 Jun 2023 16:47:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 172CF2967 for ; Mon, 12 Jun 2023 13:46:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B66AB62F18 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42767C4332A; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=0zt8I95z1HUq9EJL6kDDSqhW2E6bfWG/BgIkZcsxQ8U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WX9V9qKLsrktkGY0S+pZbFzmbFyCgZjOfy8DMZKbSGE+YoFb3FPDQCpbgLs+Dxyfs ATd7B767sG4SF1yANN+ZOAcNqeawVfzRtZae3RHkoTsytEbvlLurC1P6tsl28JACzW CuPsVGv1peAkwoZ1Qoy8hMk28mfZVyH6q212xIH4vAuyv9VyMIQK+4a0I6kJe7aUf2 h6Pa1HFguJCyUpstDl3nePUREzp/QG6kWfev3YWSBqJ82Kpf2T3i7nM7JhZEhAKj1K cdznNUPJxW7S2jeuqIUWJ3g2Au6A9WCCyHHtAd+NaMdRz1jbkC8KfGRHE73coZdt+u amTfMpPOlTfxg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 10216CE3A85; Mon, 12 Jun 2023 13:45:16 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, Zhangjin Wu , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 40/53] selftests/nolibc: test_fork: fix up duplicated print Date: Mon, 12 Jun 2023 13:45:01 -0700 Message-Id: <20230612204514.292087-40-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhangjin Wu running nolibc-test with glibc on x86_64 got such print issue: 29 execve_root =3D -1 EACCES [OK] 30 fork30 fork =3D 0 = [OK] 31 getdents64_root =3D 712 [OK] The fork test case has three printf calls: (1) llen +=3D printf("%d %s", test, #name); (2) llen +=3D printf(" =3D %d %s ", expr, errorname(errno)); (3) llen +=3D pad_spc(llen, 64, "[FAIL]\n"); --> vfprintf() In the following scene, the above issue happens: (a) The parent calls (1) (b) The parent calls fork() (c) The child runs and shares the print buffer of (1) (d) The child exits, flushs the print buffer and closes its own stdout/= stderr * "30 fork" is printed at the first time. (e) The parent calls (2) and (3), with "\n" in (3), it flushs the whole= buffer * "30 fork =3D 0 ..." is printed Therefore, there are two "30 fork" in the stdout. Between (a) and (b), if flush the stdout (and the sterr), the child in stage (c) will not be able to 'see' the print buffer. Signed-off-by: Zhangjin Wu Reviewed-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/testing/selftests/nolibc/nolibc-test.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index d417ca5d976f..fa18e7dc35c8 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -486,7 +486,13 @@ static int test_getpagesize(void) static int test_fork(void) { int status; - pid_t pid =3D fork(); + pid_t pid; + + /* flush the printf buffer to avoid child flush it */ + fflush(stdout); + fflush(stderr); + + pid =3D fork(); =20 switch (pid) { case -1: --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 C056FC88CB2 for ; Mon, 12 Jun 2023 20:50:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237521AbjFLUul (ORCPT ); Mon, 12 Jun 2023 16:50:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237755AbjFLUrv (ORCPT ); Mon, 12 Jun 2023 16:47:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7261E173F for ; Mon, 12 Jun 2023 13:46:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CB39362F1A for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47E32C4332C; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=cIY3z+FHEm5CXeXJFEW47PhAl46oQsi60a/jd0EmyWE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RdDvE1MHbzjwsOvF9ffDd4djh30bJj4Nt1XVHwaApJzI3jj+u1EVHFDuxPTG5uDgz 42XXJFBqWA54x7GAP8pY31gUSUqGC2ZQLz46cJDfj5RlcJQomu8jYwnBaDBkq/LIlz uvQH3GUYCNVZ3EVJyioBColBqkRw0xA6UVE5VvZbZ6NWfoFpTuogithxrcS7LfCM3K OL9zZ95/NdEyLwZ8M0X9yweu5IE8uP0WzsECGjgljxnkWOXLVKrMIllOYS5Rdt01ZY 3EAuI1Zk2numgEWMiZBqwLq/4MHgA0+4IFcV1NEyaN3gBjSM0bnhQkeGLnTztSLyVz 5pkzeqdqYAOOQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 12608CE3A86; Mon, 12 Jun 2023 13:45:16 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 41/53] tools/nolibc: ensure fast64 integer types have 64 bits Date: Mon, 12 Jun 2023 13:45:02 -0700 Message-Id: <20230612204514.292087-41-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh On 32bit platforms size_t is not enough to represent [u]int_fast64_t. Fixes: 3e9fd4e9a1d5 ("tools/nolibc: add integer types and integer limit mac= ros") Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/stdint.h | 10 +++++----- tools/testing/selftests/nolibc/nolibc-test.c | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/include/nolibc/stdint.h b/tools/include/nolibc/stdint.h index c1ce4f5e0603..661d942862c0 100644 --- a/tools/include/nolibc/stdint.h +++ b/tools/include/nolibc/stdint.h @@ -36,8 +36,8 @@ typedef ssize_t int_fast16_t; typedef size_t uint_fast16_t; typedef ssize_t int_fast32_t; typedef size_t uint_fast32_t; -typedef ssize_t int_fast64_t; -typedef size_t uint_fast64_t; +typedef int64_t int_fast64_t; +typedef uint64_t uint_fast64_t; =20 typedef int64_t intmax_t; typedef uint64_t uintmax_t; @@ -84,16 +84,16 @@ typedef uint64_t uintmax_t; #define INT_FAST8_MIN INT8_MIN #define INT_FAST16_MIN INTPTR_MIN #define INT_FAST32_MIN INTPTR_MIN -#define INT_FAST64_MIN INTPTR_MIN +#define INT_FAST64_MIN INT64_MIN =20 #define INT_FAST8_MAX INT8_MAX #define INT_FAST16_MAX INTPTR_MAX #define INT_FAST32_MAX INTPTR_MAX -#define INT_FAST64_MAX INTPTR_MAX +#define INT_FAST64_MAX INT64_MAX =20 #define UINT_FAST8_MAX UINT8_MAX #define UINT_FAST16_MAX SIZE_MAX #define UINT_FAST32_MAX SIZE_MAX -#define UINT_FAST64_MAX SIZE_MAX +#define UINT_FAST64_MAX UINT64_MAX =20 #endif /* _NOLIBC_STDINT_H */ diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index fa18e7dc35c8..bfcbc05e6b5b 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -702,9 +702,9 @@ int run_stdlib(int min, int max) CASE_TEST(limit_int_fast32_min); EXPECT_EQ(1, INT_FAST32_MIN, (int_= fast32_t) INTPTR_MIN); break; CASE_TEST(limit_int_fast32_max); EXPECT_EQ(1, INT_FAST32_MAX, (int_= fast32_t) INTPTR_MAX); break; CASE_TEST(limit_uint_fast32_max); EXPECT_EQ(1, UINT_FAST32_MAX, (uint= _fast32_t) UINTPTR_MAX); break; - CASE_TEST(limit_int_fast64_min); EXPECT_EQ(1, INT_FAST64_MIN, (int_= fast64_t) INTPTR_MIN); break; - CASE_TEST(limit_int_fast64_max); EXPECT_EQ(1, INT_FAST64_MAX, (int_= fast64_t) INTPTR_MAX); break; - CASE_TEST(limit_uint_fast64_max); EXPECT_EQ(1, UINT_FAST64_MAX, (uint= _fast64_t) UINTPTR_MAX); break; + CASE_TEST(limit_int_fast64_min); EXPECT_EQ(1, INT_FAST64_MIN, (int_= fast64_t) INT64_MIN); break; + CASE_TEST(limit_int_fast64_max); EXPECT_EQ(1, INT_FAST64_MAX, (int_= fast64_t) INT64_MAX); break; + CASE_TEST(limit_uint_fast64_max); EXPECT_EQ(1, UINT_FAST64_MAX, (uint= _fast64_t) UINT64_MAX); break; #if __SIZEOF_LONG__ =3D=3D 8 CASE_TEST(limit_intptr_min); EXPECT_EQ(1, INTPTR_MIN, (intp= tr_t) 0x8000000000000000LL); break; CASE_TEST(limit_intptr_max); EXPECT_EQ(1, INTPTR_MAX, (intp= tr_t) 0x7fffffffffffffffLL); break; --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 434E3C7EE2F for ; Mon, 12 Jun 2023 20:50:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237975AbjFLUur (ORCPT ); Mon, 12 Jun 2023 16:50:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236908AbjFLUry (ORCPT ); Mon, 12 Jun 2023 16:47:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A46A171E for ; Mon, 12 Jun 2023 13:46:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D265462F19 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E3B8C4332B; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=YVU6ViEp2LQfYkR6nErcvVF9nbi+sEIEq44A4g2Ftxc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z/o2kExgd26Xw+2rLZPzH96UptXHJ1CfLwRVO8+dBY+Db2nxb7NguhRpH4eZ/UB8O T7lVY1TKf5LRe3YaG41uC2bu+JSQwkd1RcBJSL9nV86eyHnexyc6QONab5DBXoBSQ2 WBioouK8JsTvLZrtJ9JIW8okCS3LdBSjovmlNtdmqrI63dQeTYVpIJebfNX1FA7laL l7Abo/Pbg6JJk7E4z7Dw3TcgYElgv2HWQbW23zJ/0m0myg6/vrOM+TghcD09QJAUaG QBLkRXWTn+Serkpnpjl0sTQRDblEsjfxo4gZ6hN041pZWquNSGQpnHTabBH0PaenbH 07YZU5m+LYmYg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 149F4CE3A87; Mon, 12 Jun 2023 13:45:16 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 42/53] selftests/nolibc: remove test gettimeofday_null Date: Mon, 12 Jun 2023 13:45:03 -0700 Message-Id: <20230612204514.292087-42-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Wei=C3=9Fschuh gettimeofday() is not guaranteed by posix to handle a NULL value as first argument gracefully. On glibc for example it crashes. (When not going through the vdso) Link: https://lore.kernel.org/lkml/96f1134d-ce6e-4d82-ae00-1cd4038809c4@t-8= ch.de/ Signed-off-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/testing/selftests/nolibc/nolibc-test.c | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index bfcbc05e6b5b..cfc7b270c397 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -589,7 +589,6 @@ int run_syscall(int min, int max) CASE_TEST(fork); EXPECT_SYSZR(1, test_fork()); break; CASE_TEST(getdents64_root); EXPECT_SYSNE(1, test_getdents64("/"), -1);= break; CASE_TEST(getdents64_null); EXPECT_SYSER(1, test_getdents64("/dev/null= "), -1, ENOTDIR); break; - CASE_TEST(gettimeofday_null); EXPECT_SYSZR(1, gettimeofday(NULL, NULL));= break; #ifdef NOLIBC CASE_TEST(gettimeofday_bad1); EXPECT_SYSER(1, gettimeofday((void *)1, NU= LL), -1, EFAULT); break; CASE_TEST(gettimeofday_bad2); EXPECT_SYSER(1, gettimeofday(NULL, (void *= )1), -1, EFAULT); break; --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 71177C7EE2F for ; Mon, 12 Jun 2023 20:50:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238118AbjFLUuw (ORCPT ); Mon, 12 Jun 2023 16:50:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237816AbjFLUsD (ORCPT ); Mon, 12 Jun 2023 16:48:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A565119AB for ; Mon, 12 Jun 2023 13:46:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D2DD062F1C for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FAF5C4332E; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=aVqOtwmx537eWDCmSDJwrEESzYvq7/Do2SB85XSCprw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M0m4+Gw20RtEfRWkpnsxaIZ4QVmx9svEupWtYqPIuH09CgLPYnTyS/dws3buXQOMf qEltOAQJeHpPfJtHSFVVY92O6BQ0WmyvZlr6Ln77x7o1ISW7nicsJMpGQ2EikcMqET niDWnICFABYmCvpc+VZgMZUj2ZJd+x5O+nlm07CKOz3gNdQHQywzKKfpAJTyNTQTfW mdhJJ9BwrntgNTnBkeB6q0Ed+YZetfLyFU+v1T7IoFKwpE+s84MzsDZROlVW/p1VpQ U586gEuzIL1b/3ijOLbItcXr2OyU00ja5ZhzUxqdcW4FlSIIb72oZl1RUXIlVGeWDF e8bOvRMsEG7CQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 1706ECE3A8A; Mon, 12 Jun 2023 13:45:16 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, Zhangjin Wu , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 43/53] selftests/nolibc: allow specify extra arguments for qemu Date: Mon, 12 Jun 2023 13:45:04 -0700 Message-Id: <20230612204514.292087-43-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhangjin Wu The opensbi package from Ubuntu 20.04 only provides rv64 firmwares: $ dpkg -S opensbi | grep -E "fw_.*bin|fw_.*elf" | uniq opensbi: /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_dynamic.bin opensbi: /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.bin opensbi: /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_dynamic.elf opensbi: /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf To run this nolibc test for rv32, users must build opensbi or download a prebuilt one from qemu repository: https://gitlab.com/qemu-project/qemu/-/blob/master/pc-bios/opensbi-risc= v32-generic-fw_dynamic.bin And then use -bios to tell qemu use it to avoid such failure: $ qemu-system-riscv32 -display none -no-reboot -kernel /path/to/arch/ri= scv/boot/Image -serial stdio -M virt -append "console=3DttyS0 panic=3D-1" qemu-system-riscv32: Unable to load the RISC-V firmware "opensbi-riscv3= 2-generic-fw_dynamic.bin" To run from makefile, QEMU_ARGS_EXTRA is added to allow pass extra arguments like -bios: $ make run QEMU_ARGS_EXTRA=3D"-bios /path/to/opensbi-riscv32-generic-fw= _dynamic.bin" ... Suggested-by: Thomas Wei=C3=9Fschuh Link: https://lore.kernel.org/linux-riscv/2ab94136-d341-4a26-964e-6d6c32e66= c9b@t-8ch.de/ Signed-off-by: Zhangjin Wu Reviewed-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/testing/selftests/nolibc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selfte= sts/nolibc/Makefile index 47c3c89092e4..44088535682e 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -64,7 +64,7 @@ QEMU_ARGS_mips =3D -M malta -append "panic=3D-1 $(T= EST:%=3DNOLIBC_TEST=3D%)" QEMU_ARGS_riscv =3D -M virt -append "console=3DttyS0 panic=3D-1 $(TES= T:%=3DNOLIBC_TEST=3D%)" QEMU_ARGS_s390 =3D -M s390-ccw-virtio -m 1G -append "console=3DttyS0= panic=3D-1 $(TEST:%=3DNOLIBC_TEST=3D%)" QEMU_ARGS_loongarch =3D -M virt -append "console=3DttyS0,115200 panic=3D-= 1 $(TEST:%=3DNOLIBC_TEST=3D%)" -QEMU_ARGS =3D $(QEMU_ARGS_$(ARCH)) +QEMU_ARGS =3D $(QEMU_ARGS_$(ARCH)) $(QEMU_ARGS_EXTRA) =20 # OUTPUT is only set when run from the main makefile, otherwise # it defaults to this nolibc directory. --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 E006AC7EE2F for ; Mon, 12 Jun 2023 20:51:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238351AbjFLUvC (ORCPT ); Mon, 12 Jun 2023 16:51:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237206AbjFLUsU (ORCPT ); Mon, 12 Jun 2023 16:48:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F91AD3 for ; Mon, 12 Jun 2023 13:46:50 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D714262F1F for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 595BBC43334; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=DzYPgHEaJn6SEGOBtodqcjbqpjhlzL55/SWXEc/knwE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IvGcN0gxBTT+XU2HPuSuQbXLjG+mnfG6Q2psrHCyj64CJyKcNhq3l8g7t3qrX5Trf urpV9lf7GROl1/e9QkDepjlU2BOWAFxgJDMIKjDXwKZbneGGgs5DIJkjAI49FwTf4o jBSeGtpaMmUqAUfM9nHW46ijV7OB8OKpbjpXQPwoFKzR6OUb0wAIP1DDD0bjKDA4vU oZMjP8K/MbvkJPB9XdJ95CS1swF7bZeArSWyyncVLAbKIozkSiEmAPnmnWFulrgK6d acSczQw5J0xzYsFvUtcwPFbl+/PYAnXE+D9ZrIVq6Sj5YVYqEcLfol8CX3kTW7WLD9 CfPCd+QC/EcnA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 193E9CE3A8B; Mon, 12 Jun 2023 13:45:16 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, Zhangjin Wu , Willy Tarreau , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , "Paul E . McKenney" Subject: [PATCH v2 nolibc 44/53] selftests/nolibc: fix up compile warning with glibc on x86_64 Date: Mon, 12 Jun 2023 13:45:05 -0700 Message-Id: <20230612204514.292087-44-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhangjin Wu Compiling nolibc-test.c with gcc on x86_64 got such warning: tools/testing/selftests/nolibc/nolibc-test.c: In function =E2=80=98expect_e= q=E2=80=99: tools/testing/selftests/nolibc/nolibc-test.c:177:24: warning: format =E2=80= =98%lld=E2=80=99 expects argument of type =E2=80=98long long int=E2=80=99, = but argument 2 has type =E2=80=98uint64_t=E2=80=99 {aka =E2=80=98long unsig= ned int=E2=80=99} [-Wformat=3D] 177 | llen +=3D printf(" =3D %lld ", expr); | ~~~^ ~~~~ | | | | | uint64_t {aka long unsigned int} | long long int | %ld It because that glibc defines uint64_t as "unsigned long int" when word size (means sizeof(long)) is 64bit (see include/bits/types.h), but nolibc directly use the 64bit "unsigned long long" (see tools/include/nolibc/stdint.h), which is simpler, seems kernel uses it too (include/uapi/asm-generic/int-ll64.h). use a simple conversion to solve it. Suggested-by: Willy Tarreau Link: https://lore.kernel.org/linux-riscv/20230529130449.GA2813@1wt.eu/ Signed-off-by: Zhangjin Wu Reviewed-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/testing/selftests/nolibc/nolibc-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index cfc7b270c397..dcb0bd079d15 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -174,7 +174,7 @@ static int expect_eq(uint64_t expr, int llen, uint64_t = val) { int ret =3D !(expr =3D=3D val); =20 - llen +=3D printf(" =3D %lld ", expr); + llen +=3D printf(" =3D %lld ", (long long)expr); pad_spc(llen, 64, ret ? "[FAIL]\n" : " [OK]\n"); return ret; } --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 CF12FC7EE43 for ; Mon, 12 Jun 2023 20:50:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238256AbjFLUuz (ORCPT ); Mon, 12 Jun 2023 16:50:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237907AbjFLUsR (ORCPT ); Mon, 12 Jun 2023 16:48:17 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABD4419B4 for ; Mon, 12 Jun 2023 13:46:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D359862F1E for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 542E8C4332D; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=fEUn7QI6ZM1/RSV/3DLiY1bJ6vwD3honS9s4B5UVY1A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nypZtV0mt3yn7CvHpsUwcJHJWaFRW4DnjvUp81bNqkgoRZ7CYwp9qjxSNxAr2l4rZ PAx+Z6ZZ4XQGoOHBvYUyTIqtpagyBS5sBQ1a/VmEQ4QPp7l95VKrMDCIXIW4w8IpkL pRYYkXyI+5Sm0Aug/Q2PuCB5J9Rz3+XaNtke5If/56SPZ8IC8O4YhpZr7lUWiIR9Oo SUkBbIFaBLezxgJu9Jq7QUgI/Pzd+JbBUDunJ4JTioRnlVXtRZgaAfc8GeWAYDduYW fpDXWOGu4MGe3ePrUnxLbGD/asj3TJVBP/2Ce2NAz1o9jYPoo55YZhX7SICjDmxsyV /NKfU+Ngxyycw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 1B79DCE3A8C; Mon, 12 Jun 2023 13:45:16 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, Zhangjin Wu , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 45/53] selftests/nolibc: not include limits.h for nolibc Date: Mon, 12 Jun 2023 13:45:06 -0700 Message-Id: <20230612204514.292087-45-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhangjin Wu When compile nolibc-test.c with 2.31 glibc, we got such error: In file included from /usr/riscv64-linux-gnu/include/sys/cdefs.h:452, from /usr/riscv64-linux-gnu/include/features.h:461, from /usr/riscv64-linux-gnu/include/bits/libc-header-s= tart.h:33, from /usr/riscv64-linux-gnu/include/limits.h:26, from /usr/lib/gcc-cross/riscv64-linux-gnu/9/include/li= mits.h:194, from /usr/lib/gcc-cross/riscv64-linux-gnu/9/include/sy= slimits.h:7, from /usr/lib/gcc-cross/riscv64-linux-gnu/9/include/li= mits.h:34, from /labs/linux-lab/src/linux-stable/tools/testing/se= lftests/nolibc/nolibc-test.c:6: /usr/riscv64-linux-gnu/include/bits/wordsize.h:28:3: error: #error "rv3= 2i-based targets are not supported" 28 | # error "rv32i-based targets are not supported" Glibc (>=3D 2.33) commit 5b6113d62efa ("RISC-V: Support the 32-bit ABI implementation") fixed up above error. As suggested by Thomas, defining INT_MIN/INT_MAX for nolibc can remove the including of limits.h, and therefore no above error. of course, the other libcs still require limits.h, move it to the right place. The LONG_MIN/LONG_MAX are also defined too. Suggested-by: Thomas Wei=C3=9Fschuh Link: https://lore.kernel.org/linux-riscv/09d60dc2-e298-4c22-8e2f-8375861bd= 9be@t-8ch.de/ Signed-off-by: Zhangjin Wu Reviewed-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/stdint.h | 14 ++++++++++++++ tools/testing/selftests/nolibc/nolibc-test.c | 4 +--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/tools/include/nolibc/stdint.h b/tools/include/nolibc/stdint.h index 661d942862c0..4b282435a59a 100644 --- a/tools/include/nolibc/stdint.h +++ b/tools/include/nolibc/stdint.h @@ -96,4 +96,18 @@ typedef uint64_t uintmax_t; #define UINT_FAST32_MAX SIZE_MAX #define UINT_FAST64_MAX UINT64_MAX =20 +#ifndef INT_MIN +#define INT_MIN (-__INT_MAX__ - 1) +#endif +#ifndef INT_MAX +#define INT_MAX __INT_MAX__ +#endif + +#ifndef LONG_MIN +#define LONG_MIN (-__LONG_MAX__ - 1) +#endif +#ifndef LONG_MAX +#define LONG_MAX __LONG_MAX__ +#endif + #endif /* _NOLIBC_STDINT_H */ diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index dcb0bd079d15..7d4b8d12050d 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -2,9 +2,6 @@ =20 #define _GNU_SOURCE =20 -/* platform-specific include files coming from the compiler */ -#include - /* libc-specific include files * The program may be built in 3 ways: * $(CC) -nostdlib -include /path/to/nolibc.h =3D> NOLIBC already defined @@ -39,6 +36,7 @@ #include #include #include +#include #endif #endif =20 --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 8797EC7EE2F for ; Mon, 12 Jun 2023 20:51:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238443AbjFLUvL (ORCPT ); Mon, 12 Jun 2023 16:51:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236013AbjFLUsZ (ORCPT ); Mon, 12 Jun 2023 16:48:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B410109 for ; Mon, 12 Jun 2023 13:46:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DCB2262F1B for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A8D9C43332; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=j0LQ24TQ8hn7bjW10yO2qmeOU+M13OFAUcFTpL2cefU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lCuC8fh+QlxTCY5xG4i8JuKCqO6tlVs/PbKHrohOTgt7hDdpeMUPOI/iz7Ng7D2t8 78IW6X+b+68e7mvsqzIGcxl0JheD7E0GAPAporUUanzCkR57d5jxMcigGsZr3ZZGMV 0smqwOPlKxXQv3skFuB4e5qCjSmoRxyGSsquzu5HgIQ7T/1uktnJAORlPRbHRprpg3 ABx65KvMs0jAd0Ce2AtSYrzgtMGBZY4pB++FO2LdfLyCfi2A+7/H1ANlwoaTA3PVbP Ptj0a5Hfwjco3Z0zXj5f3cnwEWbw5lxNw2yj6rJ464VPzJCpuoJTnu9vQyOak43Jmd f0vfmf9vw2NpA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 1DB65CE3A8D; Mon, 12 Jun 2023 13:45:16 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, Zhangjin Wu , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 46/53] selftests/nolibc: use INT_MAX instead of __INT_MAX__ Date: Mon, 12 Jun 2023 13:45:07 -0700 Message-Id: <20230612204514.292087-46-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhangjin Wu nolibc now has INT_MAX in stdint.h, so, don't mix INT_MAX and __INT_MAX__, unify them to INT_MAX. Signed-off-by: Zhangjin Wu Reviewed-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/testing/selftests/nolibc/nolibc-test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index 7d4b8d12050d..ff3da9539809 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -936,7 +936,7 @@ static const struct test test_names[] =3D { int main(int argc, char **argv, char **envp) { int min =3D 0; - int max =3D __INT_MAX__; + int max =3D INT_MAX; int ret =3D 0; int err; int idx; @@ -984,7 +984,7 @@ int main(int argc, char **argv, char **envp) * here, which defaults to the full range. */ do { - min =3D 0; max =3D __INT_MAX__; + min =3D 0; max =3D INT_MAX; value =3D colon; if (value && *value) { colon =3D strchr(value, ':'); --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 D1DDCC7EE43 for ; Mon, 12 Jun 2023 20:51:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238336AbjFLUu7 (ORCPT ); Mon, 12 Jun 2023 16:50:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232117AbjFLUsR (ORCPT ); Mon, 12 Jun 2023 16:48:17 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABBF919B3 for ; Mon, 12 Jun 2023 13:46:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D792762F20 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58847C43333; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=ujkkeF6CcwcL8JLlTc5iUkI9cAxPzJGXzBROQQtoy1s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=de0Ij0MsBENh8xMB3pYY6EZViEWela8BfBAsysvMNUIvg2yZhKeyFYZiEwkXrWuv8 ge54p3sKsyTZWknh/NpW1yHg1sDETCOQBOwBAg0uGI76I5P01s3iDiVJmvo35uHbYr BUHxY8RsIUEFNtb5TxIo29lr2IvvxkXad9ALk67kKZ4jxZMWjjf4JEa+VLgQ4ARP1g oISwYta3Dk97PsSA6mikU55RwTZejoLyv7KavLt2CgP7IP52bdAuaHW9u/f6hC4vfR C5xin0VMtowPRnosRed+L+rryBO7+ii5Ozt3dcriHIqL8bgWKzmUWHCdedGZUwRu4c Az5SzCrPvrIOw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 20401CE3A90; Mon, 12 Jun 2023 13:45:16 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, Zhangjin Wu , Arnd Bergmann , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 47/53] tools/nolibc: arm: add missing my_syscall6 Date: Mon, 12 Jun 2023 13:45:08 -0700 Message-Id: <20230612204514.292087-47-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhangjin Wu This is required by the coming removal of the oldselect and newselect support. pselect6/pselect6_time64 will be used unconditionally, they have 6 arguments. Suggested-by: Arnd Bergmann Link: https://lore.kernel.org/linux-riscv/bf3e07c1-75f5-425b-9124-f3f2b230e= 63a@app.fastmail.com/ Signed-off-by: Zhangjin Wu Reviewed-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/arch-arm.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tools/include/nolibc/arch-arm.h b/tools/include/nolibc/arch-ar= m.h index 45b89ffe8247..ca4c66987497 100644 --- a/tools/include/nolibc/arch-arm.h +++ b/tools/include/nolibc/arch-arm.h @@ -198,6 +198,29 @@ struct sys_stat_struct { _arg1; \ }) =20 +#define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) = \ +({ = \ + register long _num __asm__(_NOLIBC_SYSCALL_REG) =3D (num); \ + register long _arg1 __asm__ ("r0") =3D (long)(arg1); \ + register long _arg2 __asm__ ("r1") =3D (long)(arg2); \ + register long _arg3 __asm__ ("r2") =3D (long)(arg3); \ + register long _arg4 __asm__ ("r3") =3D (long)(arg4); \ + register long _arg5 __asm__ ("r4") =3D (long)(arg5); \ + register long _arg6 __asm__ ("r5") =3D (long)(arg6); \ + \ + __asm__ volatile ( \ + _NOLIBC_THUMB_SET_R7 \ + "svc #0\n" \ + _NOLIBC_THUMB_RESTORE_R7 \ + : "=3Dr"(_arg1), "=3Dr" (_num) \ + : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \ + "r"(_arg6), "r"(_num) \ + : "memory", "cc", "lr" \ + ); \ + _arg1; \ +}) + + char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); =20 --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 BF14AC7EE2F for ; Mon, 12 Jun 2023 20:51:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238403AbjFLUvI (ORCPT ); Mon, 12 Jun 2023 16:51:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238014AbjFLUs1 (ORCPT ); Mon, 12 Jun 2023 16:48:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4622610DC for ; Mon, 12 Jun 2023 13:46:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E217E62F22 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63406C4339E; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=Ztog5VulF0m7oJUFFCX3inDjV0jHrtLC2NTdl6UI15w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GViwPJckT5wfjzpiiSHs4J+q62lMGTpuSLIgPFUTk7YT6Ps9gLKM0a583L7rwRY0V yRwERywFicxoSU0Mayl0N8XpcDEOCQZm9vE3W7mXaXTahaxKQZtuEgMPH13DFEIIzS R7a23FMC5YK5NCyKn5rqjsMS+iyO7CV77pnxteu2Xkwa+pKPr53C3PgojrGQnuxlwn QNxFm/asS5HzAH56mDqZ5fKVTTigEQyWEuGeE6y3+9cF1sR3fypWYrsKgb0iVFrHaL PkNe0ncwdXZ+C2OJvTElBGw0VLLIVnb4pIbOBE41AfnHJbCeW1hdv50dfMHL6tIz4b 6lt24zdyo5EzQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 22678CE3A91; Mon, 12 Jun 2023 13:45:16 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, Zhangjin Wu , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 48/53] tools/nolibc: open: fix up compile warning for arm Date: Mon, 12 Jun 2023 13:45:09 -0700 Message-Id: <20230612204514.292087-48-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhangjin Wu In function =E2=80=98open=E2=80=99: nolibc/sysroot/arm/include/sys.h:919:23: warning: =E2=80=98mode_t=E2=80= =99 {aka =E2=80=98short unsigned int=E2=80=99} is promoted to =E2=80=98int= =E2=80=99 when passed through =E2=80=98...=E2=80=99 919 | mode =3D va_arg(args, mode_t); | ^ nolibc/sysroot/arm/include/sys.h:919:23: note: (so you should pass =E2= =80=98int=E2=80=99 not =E2=80=98mode_t=E2=80=99 {aka =E2=80=98short unsigne= d int=E2=80=99} to =E2=80=98va_arg=E2=80=99) nolibc/sysroot/arm/include/sys.h:919:23: note: if this code is reached,= the program will abort Signed-off-by: Zhangjin Wu Reviewed-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/sys.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 0160605444e7..856249a11890 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -862,7 +862,7 @@ int open(const char *path, int flags, ...) va_list args; =20 va_start(args, flags); - mode =3D va_arg(args, mode_t); + mode =3D va_arg(args, int); va_end(args); } =20 --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 F3B8CC7EE2F for ; Mon, 12 Jun 2023 20:51:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238375AbjFLUvF (ORCPT ); Mon, 12 Jun 2023 16:51:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237309AbjFLUs1 (ORCPT ); Mon, 12 Jun 2023 16:48:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 489C61BC0 for ; Mon, 12 Jun 2023 13:46:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E30A162F25 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69403C433A7; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=3mb1rxDwK9cr6fcOzlDmnJ3xR72KXLUFJMoKYnLILJ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mwdZ0t0b39BPc5o50RFl54UQdD61/ytGpKB+FK1kL111Fn8m/JfAgyQvZFZxEZZQZ 7PtDNIZCqwNg5wkwkAvf1NXqBJkJuKfPw2IbFWVhkMM4yVVJrnYtgn3CrB/ZEjnx7e D4d8Uu6mnPLL8X481+fOe15uaQRiW6yfqxp1/oBPaKwLZk/CQGZWQnJ2TukfqY4LAq ZCL+j4XVrpGr9YWJ2hq4ja+GN/prKLRtX9K9iTIusOL5uhR/aNwr3rcXx8g9SwW3jQ s/aXPLp4mBSGsxNYTS4Ntn0/p10seF2hv4Vy8t3kdADhSgjT97hC4OC1dyk9qWwPU7 1BeZNP2X518Qg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 24B09CE3A1C; Mon, 12 Jun 2023 13:45:16 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, Zhangjin Wu , Willy Tarreau , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , "Paul E . McKenney" Subject: [PATCH v2 nolibc 49/53] selftests/nolibc: support two errnos with EXPECT_SYSER2() Date: Mon, 12 Jun 2023 13:45:10 -0700 Message-Id: <20230612204514.292087-49-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhangjin Wu Some functions may be implemented with different syscalls in different platforms, these syscalls may set different errnos for the same arguments, let's support such cases. Suggested-by: Willy Tarreau Link: https://lore.kernel.org/linux-riscv/20230528113325.GJ1956@1wt.eu/ Signed-off-by: Zhangjin Wu Reviewed-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/testing/selftests/nolibc/nolibc-test.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index ff3da9539809..7896bc3f609e 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -300,18 +300,24 @@ static int expect_sysne(int expr, int llen, int val) } =20 =20 +#define EXPECT_SYSER2(cond, expr, expret, experr1, experr2) \ + do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret +=3D expect_sy= serr2(expr, expret, experr1, experr2, llen); } while (0) + #define EXPECT_SYSER(cond, expr, expret, experr) \ - do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret +=3D expect_sy= serr(expr, expret, experr, llen); } while (0) + EXPECT_SYSER2(cond, expr, expret, experr, 0) =20 -static int expect_syserr(int expr, int expret, int experr, int llen) +static int expect_syserr2(int expr, int expret, int experr1, int experr2, = int llen) { int ret =3D 0; int _errno =3D errno; =20 llen +=3D printf(" =3D %d %s ", expr, errorname(_errno)); - if (expr !=3D expret || _errno !=3D experr) { + if (expr !=3D expret || (_errno !=3D experr1 && _errno !=3D experr2)) { ret =3D 1; - llen +=3D printf(" !=3D (%d %s) ", expret, errorname(experr)); + if (experr2 =3D=3D 0) + llen +=3D printf(" !=3D (%d %s) ", expret, errorname(experr1)); + else + llen +=3D printf(" !=3D (%d %s %s) ", expret, errorname(experr1), error= name(experr2)); llen +=3D pad_spc(llen, 64, "[FAIL]\n"); } else { llen +=3D pad_spc(llen, 64, " [OK]\n"); --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 E3E19C7EE2F for ; Mon, 12 Jun 2023 20:51:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238494AbjFLUv3 (ORCPT ); Mon, 12 Jun 2023 16:51:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235972AbjFLUtA (ORCPT ); Mon, 12 Jun 2023 16:49:00 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D80C71FEF for ; Mon, 12 Jun 2023 13:46:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E2FD462F24 for ; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6678BC433A4; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=UfVmyxrW4sUICr3wEMH37xShjLNOPo5lV2yjbch7arw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CZg9DHFhLfiw1sKYA+IDtBUBoVhx0kedHv2DFQ9QdHIUoyAi2TMbwhHp6plOrw0Uh 5pNqnM6cvthSZqj7hfWhaM4wF1iWKoVWTux8b8HKow2YqEqxn9hdAfjfQ8mhfCxuuf 7wEcMuA5Orc1YQVkp8J+jHWodTPbPOJykHuJ7Gur1JEibNbW+F1Y9tpoaJULbMgs1M q/Hm3+mhWPaW22J1BOzk79xRs5zc+OMcPYhTuOaTxab2qSKXQALKbHA3edS/a8zM9c 073lg/mS2ceyKAAIVhjf83i+xphkEM8RdizLXYWE2zkVdJXC3AtceGZU5G2DvspCO1 /5ugQXSPp94sw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 26FA1CE3A92; Mon, 12 Jun 2023 13:45:16 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, Zhangjin Wu , Willy Tarreau , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , "Paul E . McKenney" Subject: [PATCH v2 nolibc 50/53] selftests/nolibc: remove gettimeofday_bad1/2 completely Date: Mon, 12 Jun 2023 13:45:11 -0700 Message-Id: <20230612204514.292087-50-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhangjin Wu In the clock_gettime / clock_gettime64 syscalls based gettimeofday(), there is no way to let kernel space 'fixup' the invalid data pointer of 'struct timeval' and 'struct timezone' for us for we need to read timespec from kernel space and then convert to timeval in user-space ourselves and also we need to simply ignore and reset timezone in user-space. Without this removal, the invalid (void *)1 address will trigger a sigsegv (signum =3D 11) signal and stop the whole test. Suggested-by: Willy Tarreau Link: https://lore.kernel.org/linux-riscv/20230528113325.GJ1956@1wt.eu/ Signed-off-by: Zhangjin Wu Reviewed-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/testing/selftests/nolibc/nolibc-test.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index 7896bc3f609e..b1f3ad25de35 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -593,10 +593,6 @@ int run_syscall(int min, int max) CASE_TEST(fork); EXPECT_SYSZR(1, test_fork()); break; CASE_TEST(getdents64_root); EXPECT_SYSNE(1, test_getdents64("/"), -1);= break; CASE_TEST(getdents64_null); EXPECT_SYSER(1, test_getdents64("/dev/null= "), -1, ENOTDIR); break; -#ifdef NOLIBC - CASE_TEST(gettimeofday_bad1); EXPECT_SYSER(1, gettimeofday((void *)1, NU= LL), -1, EFAULT); break; - CASE_TEST(gettimeofday_bad2); EXPECT_SYSER(1, gettimeofday(NULL, (void *= )1), -1, EFAULT); break; -#endif CASE_TEST(getpagesize); EXPECT_SYSZR(1, test_getpagesize()); break; CASE_TEST(ioctl_tiocinq); EXPECT_SYSZR(1, ioctl(0, TIOCINQ, &tmp)); = break; CASE_TEST(ioctl_tiocinq); EXPECT_SYSZR(1, ioctl(0, TIOCINQ, &tmp)); = break; --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 2B2CFC7EE43 for ; Mon, 12 Jun 2023 20:51:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238545AbjFLUvi (ORCPT ); Mon, 12 Jun 2023 16:51:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238225AbjFLUt0 (ORCPT ); Mon, 12 Jun 2023 16:49:26 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6189410FA for ; Mon, 12 Jun 2023 13:47:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 05FEB62F2C for ; Mon, 12 Jun 2023 20:45:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E8F6C433A8; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=169K0FYgwINVjwhMoliOpWOqrdexyS9jQw6SkXAUMq8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TFlmnBI++Cbbi6mA9MNQOX7y2dKwK2tr7gq6Rr5+noFltmNnqvuZ9VEIKS5RwqSlg +2TXs4igXdebipyGxk9hwotbhqRPavFWP8o2hshow0oG8UBWClDNjWD5ZFTKyBZoug Fc/qdSUAfP/q4/+2mPWBx1zR+jD55cNDPXkJCJQ/8Px1KkIvFUlU72YdCmlIWMVUgq TBjhc9JN7Zv5sQTmBof1xp6SNUuaU91q1JFvW5pZW5xWQIYq+QgX0/Fz76S+TI71v3 QvBGgigXXUFt0/OJ9H/HZFx3iN6u6re2Vyt6S1zbcwuGg3bT2zYm8lIqyKMcRF3ClA hY1JZwX9rvldw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 292D4CE3A93; Mon, 12 Jun 2023 13:45:16 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, Zhangjin Wu , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 51/53] selftests/nolibc: add new gettimeofday test cases Date: Mon, 12 Jun 2023 13:45:12 -0700 Message-Id: <20230612204514.292087-51-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhangjin Wu These 2 test cases are added to cover the normal using scenes of gettimeofday(). They have been used to trigger and fix up such issue with nolibc: nolibc-test.c:(.text.gettimeofday+0x54): undefined reference to `__aeab= i_ldivmod' This issue happens while there is no "unsigned int" conversion in the coming new clock_gettime / clock_gettime64 syscall path of gettimeofday(): tv->tv_usec =3D ts.tv_nsec / 1000; Suggested-by: Thomas Wei=C3=9Fschuh Link: https://lore.kernel.org/linux-riscv/280867a8-7601-4a96-9b85-87668e1f1= 282@t-8ch.de/ Signed-off-by: Zhangjin Wu Reviewed-by: Thomas Wei=C3=9Fschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/testing/selftests/nolibc/nolibc-test.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index b1f3ad25de35..486334981e60 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -539,6 +539,8 @@ static int test_stat_timestamps(void) */ int run_syscall(int min, int max) { + struct timeval tv; + struct timezone tz; struct stat stat_buf; int euid0; int proc; @@ -593,6 +595,8 @@ int run_syscall(int min, int max) CASE_TEST(fork); EXPECT_SYSZR(1, test_fork()); break; CASE_TEST(getdents64_root); EXPECT_SYSNE(1, test_getdents64("/"), -1);= break; CASE_TEST(getdents64_null); EXPECT_SYSER(1, test_getdents64("/dev/null= "), -1, ENOTDIR); break; + CASE_TEST(gettimeofday_tv); EXPECT_SYSZR(1, gettimeofday(&tv, NULL)); = break; + CASE_TEST(gettimeofday_tv_tz);EXPECT_SYSZR(1, gettimeofday(&tv, &tz)); b= reak; CASE_TEST(getpagesize); EXPECT_SYSZR(1, test_getpagesize()); break; CASE_TEST(ioctl_tiocinq); EXPECT_SYSZR(1, ioctl(0, TIOCINQ, &tmp)); = break; CASE_TEST(ioctl_tiocinq); EXPECT_SYSZR(1, ioctl(0, TIOCINQ, &tmp)); = break; --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 93453C7EE2F for ; Mon, 12 Jun 2023 20:51:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238614AbjFLUvr (ORCPT ); Mon, 12 Jun 2023 16:51:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237707AbjFLUt1 (ORCPT ); Mon, 12 Jun 2023 16:49:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E91A81BDB for ; Mon, 12 Jun 2023 13:47:01 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0C0F462F29 for ; Mon, 12 Jun 2023 20:45:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 765A9C43335; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=Evs3XQM2ptmnQVe5RZ3I1FeVEzlmruXYwu3iSmSz9lg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ixa3VUIP4/MWYPGOP9kEqnHyLPqFhnHm/9+xZofBjXuUTnfR1pB+oJ0gyij4vtoZg eMKZ9pmrD9GXtfwY8aUWURwdBrqwnM5axbQBV7jeGZdUtotgbCnSazSnwWQFIac0Zf ol7hDyD+eX6jpJphumP6D25tgCWMtJ9wXDs6y9DCjjCZ7IvvQE5HeIz1xpc0CxFa3O GZaiS2lmOrfxBFVpEW/GZV/3ADTlFYBh22LfQcZB9l42fjGxdLldprrDtHnxPHEzM6 uuCRleCOpFB4sCZagzDNcey7pxCnODSmcKkqjPDDLEJFPSXpaQaZ6quL1BdDAhD93Q ppNY/zSDYRzeg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 2B562CE09E7; Mon, 12 Jun 2023 13:45:16 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 52/53] selftests/nolibc: also count skipped and failed tests in output Date: Mon, 12 Jun 2023 13:45:13 -0700 Message-Id: <20230612204514.292087-52-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Willy Tarreau Right now skipped and failed test counts are not reported, and a few times already we missed skipped ones that ought not to. Let's now count each category and continue to invite the user to check the report file when skipped+fail > 0. E.g: $ make run-user (...) CC nolibc-test 136 test(s) passed, 2 skipped, 0 failed. See all results in .../run.out Note that it's important to be careful about the trailing \r on the qemu output (thanks Zhangjin for noticing). Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/testing/selftests/nolibc/Makefile | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selfte= sts/nolibc/Makefile index 44088535682e..4a3a105e1fdf 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -130,7 +130,10 @@ libc-test: nolibc-test.c # qemu user-land test run-user: nolibc-test $(Q)qemu-$(QEMU_ARCH) ./nolibc-test > "$(CURDIR)/run.out" || : - $(Q)grep -w FAIL "$(CURDIR)/run.out" && echo "See all results in $(CURDIR= )/run.out" || echo "$$(grep -c ^[0-9].*OK $(CURDIR)/run.out) test(s) passed= ." + $(Q)awk '/\[OK\][\r]*$$/{p++} /\[FAIL\][\r]*$$/{f++} /\[SKIPPED\][\r]*$$/= {s++} \ + END{ printf("%d test(s) passed, %d skipped, %d failed.", p, s, f= ); \ + if (s+f > 0) printf(" See all results in %s\n", ARGV[1]); else p= rint; }' \ + $(CURDIR)/run.out =20 initramfs: nolibc-test $(QUIET_MKDIR)mkdir -p initramfs @@ -146,12 +149,18 @@ kernel: initramfs # run the tests after building the kernel run: kernel $(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(srctree)= /$(IMAGE)" -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out" - $(Q)grep -w FAIL "$(CURDIR)/run.out" && echo "See all results in $(CURDIR= )/run.out" || echo "$$(grep -c ^[0-9].*OK $(CURDIR)/run.out) test(s) passed= ." + $(Q)awk '/\[OK\][\r]*$$/{p++} /\[FAIL\][\r]*$$/{f++} /\[SKIPPED\][\r]*$$/= {s++} \ + END{ printf("%d test(s) passed, %d skipped, %d failed.", p, s, f= ); \ + if (s+f > 0) printf(" See all results in %s\n", ARGV[1]); else p= rint; }' \ + $(CURDIR)/run.out =20 # re-run the tests from an existing kernel rerun: $(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(srctree)= /$(IMAGE)" -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out" - $(Q)grep -w FAIL "$(CURDIR)/run.out" && echo "See all results in $(CURDIR= )/run.out" || echo "$$(grep -c ^[0-9].*OK $(CURDIR)/run.out) test(s) passed= ." + $(Q)awk '/\[OK\][\r]*$$/{p++} /\[FAIL\][\r]*$$/{f++} /\[SKIPPED\][\r]*$$/= {s++} \ + END{ printf("%d test(s) passed, %d skipped, %d failed.", p, s, f= ); \ + if (s+f > 0) printf(" See all results in %s\n", ARGV[1]); else p= rint; }' \ + $(CURDIR)/run.out =20 clean: $(call QUIET_CLEAN, sysroot) --=20 2.40.1 From nobody Mon Feb 9 04:30:47 2026 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 E705BC7EE2F for ; Mon, 12 Jun 2023 20:51:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238603AbjFLUvn (ORCPT ); Mon, 12 Jun 2023 16:51:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237708AbjFLUt1 (ORCPT ); Mon, 12 Jun 2023 16:49:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EEFA1BF1 for ; Mon, 12 Jun 2023 13:47:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0C9CE62F2E for ; Mon, 12 Jun 2023 20:45:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 757E5C433AC; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=fUMXY6pyixSpxlndYjLR4VYqCyPqno/RiVwO5z9bIu8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CWZ76t1UE0jXqLcLWFJaQr3fM7S/jUG4p39IndUX7Nvpf5q3qh0YXTv8oWMJhLaPl 2zcynq08acBH3UHNqKPMFc4TqQJjWPOnRl17fAMTaUfpG8/drblQNso8l30gXHoISJ Gm+OzY2e98bRKztzorGGlwn2NQGk2z/xfZM8k1VY6VNIjG2slWonTKTP7fP+p+7pqW ugM0X62bm2hRYNgvX4WfZuBbl3P/E41U9yuiG8+5tCUjowmezPw7n3k5DaPkvDM+mL LuKyV8H+RxwvpwdUYeacTZzWCLrR3wGy2sPb2IEjD5PUqiFW21DkJKjg4nTPTgAwFV /9EiLZZgzkjsA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 2D761CE3A95; Mon, 12 Jun 2023 13:45:16 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 53/53] selftests/nolibc: make sure gcc always use little endian on MIPS Date: Mon, 12 Jun 2023 13:45:14 -0700 Message-Id: <20230612204514.292087-53-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Willy Tarreau The test on MIPS stopped working after I upgraded some of my toolchains to use the ones from kernel.org because the mips toolchain defaults to big endian, even though it supports both endians. Let's just add an explicit -EL to make sure it always succeeds like the kernel does. Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/testing/selftests/nolibc/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selfte= sts/nolibc/Makefile index 4a3a105e1fdf..1b7b3c82f8ad 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -77,6 +77,7 @@ Q=3D@ endif =20 CFLAGS_s390 =3D -m64 +CFLAGS_mips =3D -EL CFLAGS_STACKPROTECTOR ?=3D $(call cc-option,-mstack-protector-guard=3Dglob= al $(call cc-option,-fstack-protector-all)) CFLAGS ?=3D -Os -fno-ident -fno-asynchronous-unwind-tables -std=3Dc89 \ $(call cc-option,-fno-stack-protector) \ --=20 2.40.1