From nobody Sat Feb 7 15:05:56 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 122D5EB64DD for ; Wed, 12 Jul 2023 09:16:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232190AbjGLJQv (ORCPT ); Wed, 12 Jul 2023 05:16:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230236AbjGLJQs (ORCPT ); Wed, 12 Jul 2023 05:16:48 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5043EFB; Wed, 12 Jul 2023 02:16:46 -0700 (PDT) X-QQ-mid: bizesmtp83t1689153395tb1nck5x Received: from linux-lab-host.localdomain ( [116.30.126.249]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 12 Jul 2023 17:16:34 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: CR3LFp2JE4nT8qdANOII8GmrjA+hnLAPGHEEPLoGCag9o2963Xr0GjrqWzWN9 WMwzd4ekNHQopiESDkN6CjdwEqG1dzBb4hAVEVkUsUmD3M40h0cEbmhjALOHbkzNAJvWazw ahhwXDpAV80V4UjDa7MSsxeonEFdIo8r7sKTIQFDyYllue97Idwli52h6dMhl10a4+xujTc gjaa4r5jW5aJ9SUJGx6SXrTdQtETlTDxILaOZp9uSCn+Mxxz+FxfP7HpRt2LaWbjXO43LIH lsOxGoHOPzMFc4mnsvSLcQ8YOslEv3FEG8eZMNNlTLxl/U7Yn3zJ1sPDCofev1W5lG8aXfA SjYmEiWSGzcKRhnBcitYF57A10xXx9ZwdDsaK+AaH1oEg4tanXVQFnhmLXfNY7MeyzOvix9 X-QQ-GoodBg: 0 X-BIZMAIL-ID: 13879393070408931290 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de Subject: [PATCH v3 01/11] tools/nolibc: remove the old sys_stat support Date: Wed, 12 Jul 2023 17:16:34 +0800 Message-Id: <5319451b7e01f1d101b94dcecf195c734eb74ebc.1689150149.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" __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 and glibc 2.28. Let's remove the old arch related and dependent sys_stat support completely. This is friendly to the future new architecture porting. Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-aarch64.h | 28 ------------- tools/include/nolibc/arch-arm.h | 37 ----------------- tools/include/nolibc/arch-i386.h | 26 ------------ tools/include/nolibc/arch-mips.h | 28 ------------- tools/include/nolibc/arch-riscv.h | 23 ----------- tools/include/nolibc/arch-s390.h | 25 ------------ tools/include/nolibc/arch-x86_64.h | 27 ------------- tools/include/nolibc/sys.h | 63 +++++------------------------ tools/include/nolibc/types.h | 4 +- 9 files changed, 13 insertions(+), 248 deletions(-) diff --git a/tools/include/nolibc/arch-aarch64.h b/tools/include/nolibc/arc= h-aarch64.h index 6227b77a4a09..1bf122cd5966 100644 --- a/tools/include/nolibc/arch-aarch64.h +++ b/tools/include/nolibc/arch-aarch64.h @@ -9,34 +9,6 @@ =20 #include "compiler.h" =20 -/* The struct returned by the newfstatat() syscall. Differs slightly from = the - * x86_64's stat one by field ordering, so be careful. - */ -struct sys_stat_struct { - unsigned long st_dev; - unsigned long st_ino; - unsigned int st_mode; - unsigned int st_nlink; - unsigned int st_uid; - unsigned int st_gid; - - unsigned long st_rdev; - unsigned long __pad1; - long st_size; - int st_blksize; - int __pad2; - - long st_blocks; - long st_atime; - unsigned long st_atime_nsec; - long st_mtime; - - unsigned long st_mtime_nsec; - long st_ctime; - unsigned long st_ctime_nsec; - unsigned int __unused[2]; -}; - /* Syscalls for AARCH64 : * - registers are 64-bit * - stack is 16-byte aligned diff --git a/tools/include/nolibc/arch-arm.h b/tools/include/nolibc/arch-ar= m.h index 4d4887a5f04b..ea723596ed23 100644 --- a/tools/include/nolibc/arch-arm.h +++ b/tools/include/nolibc/arch-arm.h @@ -9,43 +9,6 @@ =20 #include "compiler.h" =20 -/* 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. - */ -struct sys_stat_struct { -#if defined(__ARMEB__) - unsigned short st_dev; - unsigned short __pad1; -#else - unsigned long st_dev; -#endif - unsigned long st_ino; - unsigned short st_mode; - unsigned short st_nlink; - unsigned short st_uid; - unsigned short st_gid; - -#if defined(__ARMEB__) - unsigned short st_rdev; - unsigned short __pad2; -#else - unsigned long st_rdev; -#endif - unsigned long st_size; - unsigned long st_blksize; - unsigned long st_blocks; - - unsigned long st_atime; - unsigned long st_atime_nsec; - unsigned long st_mtime; - unsigned long st_mtime_nsec; - - unsigned long st_ctime; - unsigned long st_ctime_nsec; - unsigned long __unused[2]; -}; - /* Syscalls for ARM in ARM or Thumb modes : * - registers are 32-bit * - stack is 8-byte aligned diff --git a/tools/include/nolibc/arch-i386.h b/tools/include/nolibc/arch-i= 386.h index 4c6b7c04e2e7..1d4b683bc2cd 100644 --- a/tools/include/nolibc/arch-i386.h +++ b/tools/include/nolibc/arch-i386.h @@ -9,32 +9,6 @@ =20 #include "compiler.h" =20 -/* The struct returned by the stat() syscall, 32-bit only, the syscall ret= urns - * exactly 56 bytes (stops before the unused array). - */ -struct sys_stat_struct { - unsigned long st_dev; - unsigned long st_ino; - unsigned short st_mode; - unsigned short st_nlink; - unsigned short st_uid; - unsigned short st_gid; - - unsigned long st_rdev; - unsigned long st_size; - unsigned long st_blksize; - unsigned long st_blocks; - - unsigned long st_atime; - unsigned long st_atime_nsec; - unsigned long st_mtime; - unsigned long st_mtime_nsec; - - unsigned long st_ctime; - unsigned long st_ctime_nsec; - unsigned long __unused[2]; -}; - /* Syscalls for i386 : * - mostly similar to x86_64 * - registers are 32-bit diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-m= ips.h index a2bfdf57b957..ae40d5268793 100644 --- a/tools/include/nolibc/arch-mips.h +++ b/tools/include/nolibc/arch-mips.h @@ -9,34 +9,6 @@ =20 #include "compiler.h" =20 -/* The struct returned by the stat() syscall. 88 bytes are returned by the - * syscall. - */ -struct sys_stat_struct { - unsigned int st_dev; - long st_pad1[3]; - unsigned long st_ino; - unsigned int st_mode; - unsigned int st_nlink; - unsigned int st_uid; - unsigned int st_gid; - unsigned int st_rdev; - long st_pad2[2]; - long st_size; - long st_pad3; - - long st_atime; - long st_atime_nsec; - long st_mtime; - long st_mtime_nsec; - - long st_ctime; - long st_ctime_nsec; - long st_blksize; - long st_blocks; - long st_pad4[14]; -}; - /* Syscalls for MIPS ABI O32 : * - WARNING! there's always a delayed slot! * - WARNING again, the syntax is different, registers take a '$' and nu= mbers diff --git a/tools/include/nolibc/arch-riscv.h b/tools/include/nolibc/arch-= riscv.h index cd958b2f4b1b..2b89ea59c5e4 100644 --- a/tools/include/nolibc/arch-riscv.h +++ b/tools/include/nolibc/arch-riscv.h @@ -9,29 +9,6 @@ =20 #include "compiler.h" =20 -struct sys_stat_struct { - unsigned long st_dev; /* Device. */ - unsigned long st_ino; /* File serial number. */ - unsigned int st_mode; /* File mode. */ - unsigned int st_nlink; /* Link count. */ - unsigned int st_uid; /* User ID of the file's owner. */ - unsigned int st_gid; /* Group ID of the file's group. */ - unsigned long st_rdev; /* Device number, if device. */ - unsigned long __pad1; - long st_size; /* Size of file, in bytes. */ - int st_blksize; /* Optimal block size for I/O. */ - int __pad2; - long st_blocks; /* Number 512-byte blocks allocated. */ - long st_atime; /* Time of last access. */ - unsigned long st_atime_nsec; - long st_mtime; /* Time of last modification. */ - unsigned long st_mtime_nsec; - long st_ctime; /* Time of last status change. */ - unsigned long st_ctime_nsec; - unsigned int __unused4; - unsigned int __unused5; -}; - #if __riscv_xlen =3D=3D 64 #define PTRLOG "3" #define SZREG "8" diff --git a/tools/include/nolibc/arch-s390.h b/tools/include/nolibc/arch-s= 390.h index a644ecd361c0..a40424ba043e 100644 --- a/tools/include/nolibc/arch-s390.h +++ b/tools/include/nolibc/arch-s390.h @@ -10,31 +10,6 @@ =20 #include "compiler.h" =20 -/* The struct returned by the stat() syscall, equivalent to stat64(). The - * syscall returns 116 bytes and stops in the middle of __unused. - */ - -struct sys_stat_struct { - unsigned long st_dev; - unsigned long st_ino; - unsigned long st_nlink; - unsigned int st_mode; - unsigned int st_uid; - unsigned int st_gid; - unsigned int __pad1; - unsigned long st_rdev; - unsigned long st_size; - unsigned long st_atime; - unsigned long st_atime_nsec; - unsigned long st_mtime; - unsigned long st_mtime_nsec; - unsigned long st_ctime; - unsigned long st_ctime_nsec; - unsigned long st_blksize; - long st_blocks; - unsigned long __unused[3]; -}; - /* Syscalls for s390: * - registers are 64-bit * - syscall number is passed in r1 diff --git a/tools/include/nolibc/arch-x86_64.h b/tools/include/nolibc/arch= -x86_64.h index e69113742a99..e980ca5417d0 100644 --- a/tools/include/nolibc/arch-x86_64.h +++ b/tools/include/nolibc/arch-x86_64.h @@ -9,33 +9,6 @@ =20 #include "compiler.h" =20 -/* The struct returned by the stat() syscall, equivalent to stat64(). The - * syscall returns 116 bytes and stops in the middle of __unused. - */ -struct sys_stat_struct { - unsigned long st_dev; - unsigned long st_ino; - unsigned long st_nlink; - unsigned int st_mode; - unsigned int st_uid; - - unsigned int st_gid; - unsigned int __pad0; - unsigned long st_rdev; - long st_size; - long st_blksize; - - long st_blocks; - unsigned long st_atime; - unsigned long st_atime_nsec; - unsigned long st_mtime; - - unsigned long st_mtime_nsec; - unsigned long st_ctime; - unsigned long st_ctime_nsec; - long __unused[3]; -}; - /* Syscalls for x86_64 : * - registers are 64-bit * - syscall number is passed in rax diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index dee56894a811..8bfe7db20b80 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -943,15 +943,19 @@ pid_t setsid(void) return __sysret(sys_setsid()); } =20 -#if defined(__NR_statx) /* * int statx(int fd, const char *path, int flags, unsigned int mask, struc= t statx *buf); + * int stat(const char *path, struct stat *buf); */ =20 static __attribute__((unused)) int sys_statx(int fd, const char *path, int flags, unsigned int mask, stru= ct statx *buf) { +#ifdef __NR_statx return my_syscall5(__NR_statx, fd, path, flags, mask, buf); +#else + return -ENOSYS; +#endif } =20 static __attribute__((unused)) @@ -959,24 +963,18 @@ int statx(int fd, const char *path, int flags, unsign= ed int mask, struct statx * { return __sysret(sys_statx(fd, path, flags, mask, buf)); } -#endif =20 -/* - * int stat(const char *path, struct stat *buf); - * Warning: the struct stat's layout is arch-dependent. - */ =20 -#if defined(__NR_statx) && !defined(__NR_newfstatat) && !defined(__NR_stat) -/* - * Maybe we can just use statx() when available for all architectures? - */ static __attribute__((unused)) -int sys_stat(const char *path, struct stat *buf) +int stat(const char *path, struct stat *buf) { struct statx statx; long ret; =20 - ret =3D sys_statx(AT_FDCWD, path, AT_NO_AUTOMOUNT, STATX_BASIC_STATS, &st= atx); + ret =3D __sysret(sys_statx(AT_FDCWD, path, AT_NO_AUTOMOUNT, STATX_BASIC_S= TATS, &statx)); + if (ret =3D=3D -1) + return ret; + buf->st_dev =3D ((statx.stx_dev_minor & 0xff) | (statx.stx_dev_major << 8) | ((statx.stx_dev_minor & ~0xff) << 12)); @@ -997,47 +995,8 @@ int sys_stat(const char *path, struct stat *buf) 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 -static __attribute__((unused)) -int sys_stat(const char *path, struct stat *buf) -{ - struct sys_stat_struct stat; - long ret; - -#ifdef __NR_newfstatat - /* only solution for arm64 */ - ret =3D my_syscall4(__NR_newfstatat, AT_FDCWD, path, &stat, 0); -#elif defined(__NR_stat) - ret =3D my_syscall2(__NR_stat, path, &stat); -#else - return -ENOSYS; -#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_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 =20 -static __attribute__((unused)) -int stat(const char *path, struct stat *buf) -{ - return __sysret(sys_stat(path, buf)); + return 0; } =20 =20 diff --git a/tools/include/nolibc/types.h b/tools/include/nolibc/types.h index 23963e48d8ee..8cfc4c860fa4 100644 --- a/tools/include/nolibc/types.h +++ b/tools/include/nolibc/types.h @@ -15,8 +15,8 @@ =20 =20 /* Only the generic macros and types may be defined here. The arch-specific - * ones such as the O_RDONLY and related macros used by fcntl() and open()= , or - * the layout of sys_stat_struct must not be defined here. + * ones such as the O_RDONLY and related macros used by fcntl() and open() + * must not be defined here. */ =20 /* stat flags (WARNING, octal here). We need to check for an existing --=20 2.25.1 From nobody Sat Feb 7 15:05:56 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 7493BEB64D9 for ; Wed, 12 Jul 2023 09:18:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231920AbjGLJSH (ORCPT ); Wed, 12 Jul 2023 05:18:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231600AbjGLJRw (ORCPT ); Wed, 12 Jul 2023 05:17:52 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56CAB11D; Wed, 12 Jul 2023 02:17:50 -0700 (PDT) X-QQ-mid: bizesmtp62t1689153460t6fqn0jb Received: from linux-lab-host.localdomain ( [116.30.126.249]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 12 Jul 2023 17:17:39 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: k0mQ4ihyJQOSubvL2shrPA/LW4atE5uOf3i0CK3EnGdQf0viNxC21BnUmaM3X HwVGiywAmFeUbqHVOieSjk+LDTytitz9TsRFkNTe2ErraPTqLYFx9dJuD2UemllBPmqYHEz 9p1w2Tz0tz8jgvM/Sx/SYPYxU5LHY2ni5EdU3M5C6tSZpyFaoa5FzsSQkMcCutoy8UvdCRg QlR7mP6Mo0Dc0PVgRrFH0/1vHBBde+PiAh1IqMyilOioHaNX8k6gpTR46/wjL9u2Ch1aHDk xXASOab4L2E9M7TKSK4ciHT0LYiBKp91+4OdVJ4oWfyVsiwjRIrnF++PmV2EWvsuTYVBkwh DIAcdZOcyjnn3W4ia5tN9uainmlOCBT/Lt9dgBJTkwNPGDCXqImvd8w0X0Z4ySEQ5ceDNH3 RTdEGLLEdTM= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 4436459021916993005 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Subject: [PATCH v3 02/11] tools/nolibc: add new crt.h with _start_c Date: Wed, 12 Jul 2023 17:17:39 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As the environ and _auxv support added for nolibc, the assembly _start function becomes more and more complex and therefore makes the porting of nolibc to new architectures harder and harder. To simplify portability, this C version of _start_c() is added to do most of the assembly start operations in C, which reduces the complexity a lot and will eventually simplify the porting of nolibc to the new architectures. The new _start_c() only requires a stack pointer argument, it will find argv, envp and _auxv for us, and then call main(), finally, it exit() with main's return status. With this new _start_c(), the future new architectures only require to add very few assembly instructions. As suggested by Thomas, users may use a different signature of main (e.g. void main(void)), a _nolibc_main alias is added for main to silence the warning about potential conflicting types. Suggested-by: Thomas Wei=C3=9Fschuh Link: https://lore.kernel.org/lkml/90fdd255-32f4-4caf-90ff-06456b53dac3@t-8= ch.de/ Signed-off-by: Zhangjin Wu --- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/crt.h | 59 +++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 tools/include/nolibc/crt.h diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 64d67b080744..909b6eb500fe 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -27,6 +27,7 @@ nolibc_arch :=3D $(patsubst arm64,aarch64,$(ARCH)) arch_file :=3D arch-$(nolibc_arch).h all_files :=3D \ compiler.h \ + crt.h \ ctype.h \ errno.h \ nolibc.h \ diff --git a/tools/include/nolibc/crt.h b/tools/include/nolibc/crt.h new file mode 100644 index 000000000000..f9db2389acd2 --- /dev/null +++ b/tools/include/nolibc/crt.h @@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * C Run Time support for NOLIBC + * Copyright (C) 2023 Zhangjin Wu + */ + +#ifndef _NOLIBC_CRT_H +#define _NOLIBC_CRT_H + +char **environ __attribute__((weak)); +const unsigned long *_auxv __attribute__((weak)); + +typedef int (_nolibc_main_fn)(int, char **, char **); +static void exit(int); + +void _start_c(long *sp) +{ + int argc, i; + char **argv; + char **envp; + /* silence potential warning: conflicting types for 'main' */ + _nolibc_main_fn _nolibc_main __asm__ ("main"); + + /* + * sp : argc <-- argument count, required by main() + * argv: argv[0] <-- argument vector, required by main() + * argv[1] + * ... + * argv[argc-1] + * null + * envp: envp[0] <-- environment variables, required by main() and= getenv() + * envp[1] + * ... + * null + * _auxv: auxv[0] <-- auxiliary vector, required by getauxval() + * auxv[1] + * ... + * null + */ + + /* assign argc and argv */ + argc =3D sp[0]; + argv =3D (void *)(sp + 1); + + /* find envp */ + envp =3D argv + argc + 1; + environ =3D envp; + + /* find auxv */ + i =3D 0; + while (envp[i]) + i++; + _auxv =3D (void *)(envp + i + 1); + + /* go to application */ + exit(_nolibc_main(argc, argv, envp)); +} + +#endif /* _NOLIBC_CRT_H */ --=20 2.25.1 From nobody Sat Feb 7 15:05:56 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 94141EB64D9 for ; Wed, 12 Jul 2023 09:19:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232492AbjGLJTM (ORCPT ); Wed, 12 Jul 2023 05:19:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232603AbjGLJTA (ORCPT ); Wed, 12 Jul 2023 05:19:00 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C48BF1998; Wed, 12 Jul 2023 02:18:55 -0700 (PDT) X-QQ-mid: bizesmtp85t1689153526tjyf6k0s Received: from linux-lab-host.localdomain ( [116.30.126.249]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 12 Jul 2023 17:18:45 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: zT6n3Y95oi1Q7MFa1CSS57hNQnv1/10jeqfsHZAQQpZlJ7diAVk+VgwixNHdq pPfLew8XIjf5N6Y6zQDz0VgwQbg0pOxJBb/7Y9Ns4t1fUKIfnMoL+f+OhNv8jE5PinsTe/+ 6Ob8p8vQ51rivPl6WQQcDxak7bsvxbRn/FzV64sqW7YGjqFKlJfu0iSY89VZ4EYpSizGJer xhB2OPJSGLH8ORqD3cO+8BVNxlKeBfqtdHpI/tdsl2NTFx1tnsjZ4NDuFgwKZdPmSOY0YhE t+BDN0u+0jKvxQQRtxa6rGKCZOdI1hbC+EFpjK2yF6YW6DWYMOL0flgKqqFQAe4MAyRX6Cw ix+dMWsCIoFvThWzd/fk7lpBhbKO9kTk5Saox0V7DiWHElQNs9RRU8A4ZvbexEqFKh42b/7 X-QQ-GoodBg: 0 X-BIZMAIL-ID: 11721497453081374856 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de Subject: [PATCH v3 03/11] tools/nolibc: arm: shrink _start with _start_c Date: Wed, 12 Jul 2023 17:18:44 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" move most of the _start operations to _start_c(). Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-arm.h | 43 +++++---------------------------- 1 file changed, 6 insertions(+), 37 deletions(-) diff --git a/tools/include/nolibc/arch-arm.h b/tools/include/nolibc/arch-ar= m.h index ea723596ed23..74773ddcf4ca 100644 --- a/tools/include/nolibc/arch-arm.h +++ b/tools/include/nolibc/arch-arm.h @@ -8,6 +8,7 @@ #define _NOLIBC_ARCH_ARM_H =20 #include "compiler.h" +#include "crt.h" =20 /* Syscalls for ARM in ARM or Thumb modes : * - registers are 32-bit @@ -183,49 +184,17 @@ _arg1; \ }) =20 - -char **environ __attribute__((weak)); -const unsigned long *_auxv __attribute__((weak)); - /* startup code */ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_st= ack_protector _start(void) { __asm__ volatile ( #ifdef _NOLIBC_STACKPROTECTOR - "bl __stack_chk_init\n" /* initialize stack protector = */ + "bl __stack_chk_init\n" /* initialize stack protector = */ #endif - "pop {%r0}\n" /* argc was in the stack = */ - "mov %r1, %sp\n" /* argv =3D sp = */ - - "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 = */ - - "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 = */ - "bne 0b\n" - "ldr %r3, 2f\n" /* r3 =3D &_auxv (low bits) = */ - "str r4, [r3]\n" /* store r4 into _auxv = */ - - "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" - - "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 */ - "1:\n" - ".word environ\n" - "2:\n" - ".word _auxv\n" + "mov %r0, sp\n" /* save stack pointer to %r0, as arg1 of _start_= c */ + "and ip, %r0, #-8\n" /* sp must be 8-byte aligned in the callee = */ + "mov sp, ip\n" + "bl _start_c\n" /* transfer to c runtime = */ ); __builtin_unreachable(); } --=20 2.25.1 From nobody Sat Feb 7 15:05:56 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 4F4EFEB64DD for ; Wed, 12 Jul 2023 09:20:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231407AbjGLJUI (ORCPT ); Wed, 12 Jul 2023 05:20:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231578AbjGLJUC (ORCPT ); Wed, 12 Jul 2023 05:20:02 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70C89139; Wed, 12 Jul 2023 02:20:00 -0700 (PDT) X-QQ-mid: bizesmtp75t1689153591t4m7hhbh Received: from linux-lab-host.localdomain ( [116.30.126.249]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 12 Jul 2023 17:19:50 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: uGhnJwy6xZIttFNE7Y1G6BS+94JXqZJfIlXFCaabP2xXLECfQZ3BaGBSMm/IR NGCzIYlWnLkXTYKMoCzHgVtI1SBTHE9zAuWjLHH9wKFzqJuFZHLCr4fL45h4/YMd5ju4dIZ 5ABy2E/ms4YpCXYwtpJ+Ri6OwV0W0JZNuRO0p78K1tySDRnhvVYkIerPi5oJ+ZrTErnqtZD ldIr8vumsmcR2TGV09ciofi67DbgZjSLpaOSJqhqwD91vpoDD8AQcnJb91AK6VTO/8oOP4v a1cXAFizdBzZHVJJASYpRXPQslKbYvozXKwNbq20vudoZncGqCqkdlEVf0EkQmbUbyzYODd ECJDStT5M2CNQFnqbjA0OLuScaUJhgbCQPcjyTbZh0MH3OJ7iQFb0giFTpN3w== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 5769694176344349855 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de Subject: [PATCH v3 04/11] tools/nolibc: aarch64: shrink _start with _start_c Date: Wed, 12 Jul 2023 17:19:50 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" move most of the _start operations to _start_c(). Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-aarch64.h | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/tools/include/nolibc/arch-aarch64.h b/tools/include/nolibc/arc= h-aarch64.h index 1bf122cd5966..e52fa5a20d71 100644 --- a/tools/include/nolibc/arch-aarch64.h +++ b/tools/include/nolibc/arch-aarch64.h @@ -8,6 +8,7 @@ #define _NOLIBC_ARCH_AARCH64_H =20 #include "compiler.h" +#include "crt.h" =20 /* Syscalls for AARCH64 : * - registers are 64-bit @@ -143,33 +144,16 @@ _arg1; \ }) =20 -char **environ __attribute__((weak)); -const unsigned long *_auxv __attribute__((weak)); - /* startup code */ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_st= ack_protector _start(void) { __asm__ volatile ( #ifdef _NOLIBC_STACKPROTECTOR - "bl __stack_chk_init\n" /* initialize stack protector = */ + "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 ... = */ - "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 = */ - "svc #0\n" + "mov x0, sp\n" /* save stack pointer to x0, as arg1 of _start_c= */ + "and sp, x0, -16\n" /* sp must be 16-byte aligned in the callee = */ + "bl _start_c\n" /* transfer to c runtime = */ ); __builtin_unreachable(); } --=20 2.25.1 From nobody Sat Feb 7 15:05:56 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 1E2DCEB64DD for ; Wed, 12 Jul 2023 09:22:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231308AbjGLJWo (ORCPT ); Wed, 12 Jul 2023 05:22:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232190AbjGLJW2 (ORCPT ); Wed, 12 Jul 2023 05:22:28 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21D43E5F; Wed, 12 Jul 2023 02:21:44 -0700 (PDT) X-QQ-mid: bizesmtp66t1689153656te3bxl5e Received: from linux-lab-host.localdomain ( [116.30.126.249]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 12 Jul 2023 17:20:55 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: f0e3nd0UjDMWyqMb2OvZ3nICQJEiN23es6rzV5wC4cahNSci93zk5avdkN9io q6BYdGJoZRmuMT5rlrQMLsTfYs1JDiRGxLhXm10fh6zUHduZJaJzzdEtPFbZO2sRNnVY/Uf 8Skorwq/S+JEevTOwGrg/t8gy1kUoX5xgEbi/iZ+uiG1SnDVRlw5OroSC880NrikfhbX63H w4zF2E/cFDLmhtmGtHgNB6jMVLFmBbcIZL/11fBfv0u3A3oWwXw+n6Xv6ZP87Z0k4MjQdUV qHnx5Qzfeg5RQdshjphvVgMsmNaMXJ6oh04J6bswf9QBTwjTrkRx8j2hcVC8HUQt2ZNFPHr UkhFXblDdj8PllkZNal2brCfOMD9kbgKoDfE18K77we3a08FPPu8rZmNG75hdxty3rf8GWg X-QQ-GoodBg: 0 X-BIZMAIL-ID: 2211699565622657830 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de Subject: [PATCH v3 05/11] tools/nolibc: i386: shrink _start with _start_c Date: Wed, 12 Jul 2023 17:20:55 +0800 Message-Id: <29e5222e81983e46c0dd8c043db66820ed80638b.1689150149.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" move most of the _start operations to _start_c(). Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-i386.h | 33 ++++++++------------------------ 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/tools/include/nolibc/arch-i386.h b/tools/include/nolibc/arch-i= 386.h index 1d4b683bc2cd..f0d0f5c364b8 100644 --- a/tools/include/nolibc/arch-i386.h +++ b/tools/include/nolibc/arch-i386.h @@ -8,6 +8,7 @@ #define _NOLIBC_ARCH_I386_H =20 #include "compiler.h" +#include "crt.h" =20 /* Syscalls for i386 : * - mostly similar to x86_64 @@ -154,9 +155,6 @@ _eax; \ }) =20 -char **environ __attribute__((weak)); -const unsigned long *_auxv __attribute__((weak)); - /* startup code */ /* * i386 System V ABI mandates: @@ -168,29 +166,14 @@ void __attribute__((weak,noreturn,optimize("omit-fram= e-pointer"))) __no_stack_pr { __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) */ - "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= ) */ - "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 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 = */ + "xor %ebp, %ebp\n" /* zero the stack frame = */ + "mov %esp, %eax\n" /* save stack pointer to %eax, as arg1 of _sta= rt_c */ + "and $-16, %esp\n" /* last pushed argument must be 16-byte aligne= d */ + "push %eax\n" /* push arg1 on stack to support plain stack m= odes too */ + "call _start_c\n" /* transfer to c runtime = */ + "hlt\n" /* ensure it does not return = */ ); __builtin_unreachable(); } --=20 2.25.1 From nobody Sat Feb 7 15:05:56 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 5792CEB64DD for ; Wed, 12 Jul 2023 09:28:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232971AbjGLJ2y (ORCPT ); Wed, 12 Jul 2023 05:28:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232142AbjGLJ2u (ORCPT ); Wed, 12 Jul 2023 05:28:50 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1546139; Wed, 12 Jul 2023 02:28:48 -0700 (PDT) X-QQ-mid: bizesmtp64t1689153721th57ji5d Received: from linux-lab-host.localdomain ( [116.30.126.249]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 12 Jul 2023 17:22:00 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: ILHsT53NKPjtB6FRZNFER3rcR7JDnPatbvx5VZiH7Ka3nO5WQOLWEFZpPEe8B Yg20t6QwyoFCV7b02MyegxMbyGupz2otIOof0G6QMVqebibWpCYSMNtwV2M05N2VPvYciuL jF5v/Go5WOVHowGe5VRc1vEC41oiM+YrlHt+5weearunvpqX1+GxfH0v7Syit0E+URdtohu 9hwfCZcaKT3NdX/a/Ps8iFWFV2qcRE0U7fuz5iTPfe/tlJk3Xw30z1Y2BGkAYdt8EwEnHr+ 1D/z5iJXvKaMQlS54kqs6mjGkWD1h3QFRBbwa6cUKarbLnaykhdxAmgGnkbFZy0WopMoW+8 apB15xrFXXrVeJf4imx2XhfhUHdkT8KcK0gALHVxGN9UEKsEoDXvi4foD2v5W+1himpDZ7d X-QQ-GoodBg: 0 X-BIZMAIL-ID: 13879264576707349728 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de Subject: [PATCH v3 06/11] tools/nolibc: x86_64: shrink _start with _start_c Date: Wed, 12 Jul 2023 17:22:00 +0800 Message-Id: <8bdc96799300a5c5a40320d4f66ad54e97b4b9de.1689150149.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" move most of the _start operations to _start_c(). Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-x86_64.h | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/tools/include/nolibc/arch-x86_64.h b/tools/include/nolibc/arch= -x86_64.h index e980ca5417d0..0048adf6b11f 100644 --- a/tools/include/nolibc/arch-x86_64.h +++ b/tools/include/nolibc/arch-x86_64.h @@ -8,6 +8,7 @@ #define _NOLIBC_ARCH_X86_64_H =20 #include "compiler.h" +#include "crt.h" =20 /* Syscalls for x86_64 : * - registers are 64-bit @@ -153,9 +154,6 @@ _ret; \ }) =20 -char **environ __attribute__((weak)); -const unsigned long *_auxv __attribute__((weak)); - /* startup code */ /* * x86-64 System V ABI mandates: @@ -167,25 +165,13 @@ void __attribute__((weak,noreturn,optimize("omit-fram= e-pointer"))) __no_stack_pr { __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) */ - "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= ) */ - "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 = */ + "xor %ebp, %ebp\n" /* zero the stack frame = */ + "mov %rsp, %rdi\n" /* save stack pointer to %rdi, as arg1 of _sta= rt_c */ + "and $-16, %rsp\n" /* %rsp must be 16-byte aligned before call = */ + "call _start_c\n" /* transfer to c runtime = */ + "hlt\n" /* ensure it does not return = */ ); __builtin_unreachable(); } --=20 2.25.1 From nobody Sat Feb 7 15:05:56 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 68322EB64D9 for ; Wed, 12 Jul 2023 09:24:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232099AbjGLJYP (ORCPT ); Wed, 12 Jul 2023 05:24:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231970AbjGLJX6 (ORCPT ); Wed, 12 Jul 2023 05:23:58 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80C5519A7; Wed, 12 Jul 2023 02:23:36 -0700 (PDT) X-QQ-mid: bizesmtp81t1689153787ta408fla Received: from linux-lab-host.localdomain ( [116.30.126.249]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 12 Jul 2023 17:23:05 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: 239gR2IZrlvYgW4Z4Y00+uFld0r6zVlb6HKvXNeighaOY+7tVJQt96XqmH/mk sYLWUoLD6gE+zFqzo7zSHQh6qE6Pg6q/MZliaTZ3tN0ZBAQv+Sd25QUu9CkLQqjlzjO4iBL AwWjEf4FgSGRtVRSarzqA9PqIsKjX5M2H7TX7DKbz5gVxJ4fqq45DqQWiV/WEOPxODqf2hP B+ssXhUMVmgfP64JPBLhYN0L33/lQoM7WRuCpdxOAWUjKue+gDeoNB2XytT/4KPt/JNHbxY x9ultFO9qk848rTdoYdz2Ykhx1IywSNwk7mH/Q1vWUQgHtFmoQaZy6v+S7Bd5TdrLiWQVT8 g9DtCugDJoXSAYyYX+6wTLa3c1zreP5gOxVsqi8Uits20diOA61dS6O2ESgsA== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 9583563646986004817 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de Subject: [PATCH v3 07/11] tools/nolibc: mips: shrink _start with _start_c Date: Wed, 12 Jul 2023 17:23:05 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" move most of the _start operations to _start_c(). Also clean up the instructions in delayed slots. Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-mips.h | 46 +++++++------------------------- 1 file changed, 10 insertions(+), 36 deletions(-) diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-m= ips.h index ae40d5268793..b1c070c5b24a 100644 --- a/tools/include/nolibc/arch-mips.h +++ b/tools/include/nolibc/arch-mips.h @@ -8,6 +8,7 @@ #define _NOLIBC_ARCH_MIPS_H =20 #include "compiler.h" +#include "crt.h" =20 /* Syscalls for MIPS ABI O32 : * - WARNING! there's always a delayed slot! @@ -173,50 +174,23 @@ _arg4 ? -_num : _num; \ }) =20 -char **environ __attribute__((weak)); -const unsigned long *_auxv __attribute__((weak)); - /* startup code, note that it's called __start on MIPS */ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_st= ack_protector __start(void) { __asm__ volatile ( - /*".set nomips16\n"*/ ".set push\n" - ".set noreorder\n" + ".set noreorder\n" ".option pic0\n" #ifdef _NOLIBC_STACKPROTECTOR - "jal __stack_chk_init\n" /* initialize stack protector = */ - "nop\n" /* delayed slot = */ + "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 = */ - "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 = */ - - "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 = */ - "syscall\n" - /*".end __start\n"*/ + "move $a0, $sp\n" /* save stack pointer to $a0, as arg1 of _start= _c */ + "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 _start_c\n" /* transfer to c runtime = */ + " nop\n" /* delayed slot = */ ".set pop\n" ); __builtin_unreachable(); --=20 2.25.1 From nobody Sat Feb 7 15:05:56 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 47371EB64D9 for ; Wed, 12 Jul 2023 09:24:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232240AbjGLJYt (ORCPT ); Wed, 12 Jul 2023 05:24:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232475AbjGLJYm (ORCPT ); Wed, 12 Jul 2023 05:24:42 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 508741995; Wed, 12 Jul 2023 02:24:21 -0700 (PDT) X-QQ-mid: bizesmtp74t1689153852t7x4q3lf Received: from linux-lab-host.localdomain ( [116.30.126.249]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 12 Jul 2023 17:24:11 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: 7jw2iSiCazrYV30tqA3rE/xk9YB446MUEUfOtIQC4wAExzPRDbLzHgqE9b1Zm I2p1W+qGWca7sApfHy5SvhFkO0VunsETK7Kh6N1KjRgGEML/roQB+/F3p2X5KQi+yZ6I6pn VDhAESpTzlhYjfrbcCTKuk4qQFv7NakQVLs4DfRuKxJh94TpZ7f/Kfze+ix2Xvs3jwywbGh f86pV5ZP07NUwLipz5WQ1YsOO/PAZ0TTVe3dRXV30dTX+lpkzmsAHxwlV9K+XTzy7sTPCSm wqpSMKNNifEA6EKAOzW318c5AIxixFcA2fUwQcFlp16BhrNTYFL+oUyy85nhbLZ/4ptyTw9 hPYb/Sy2GUraSshYqx8VlvVnSuSoesUATEcQTFy1SUGVO/JwtkBoFZJkkUM5A== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 17383144857410459709 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de Subject: [PATCH v3 08/11] tools/nolibc: loongarch: shrink _start with _start_c Date: Wed, 12 Jul 2023 17:24:10 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" move most of the _start operations to _start_c(). Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-loongarch.h | 43 ++++----------------------- 1 file changed, 5 insertions(+), 38 deletions(-) diff --git a/tools/include/nolibc/arch-loongarch.h b/tools/include/nolibc/a= rch-loongarch.h index 8aa7724fe38e..9db70d6f2c31 100644 --- a/tools/include/nolibc/arch-loongarch.h +++ b/tools/include/nolibc/arch-loongarch.h @@ -8,6 +8,7 @@ #define _NOLIBC_ARCH_LOONGARCH_H =20 #include "compiler.h" +#include "crt.h" =20 /* Syscalls for LoongArch : * - stack is 16-byte aligned @@ -143,26 +144,9 @@ _arg1; \ }) =20 -char **environ __attribute__((weak)); -const unsigned long *_auxv __attribute__((weak)); - #if __loongarch_grlen =3D=3D 32 -#define LONGLOG "2" -#define SZREG "4" -#define REG_L "ld.w" -#define LONG_S "st.w" -#define LONG_ADD "add.w" -#define LONG_ADDI "addi.w" -#define LONG_SLL "slli.w" #define LONG_BSTRINS "bstrins.w" #else /* __loongarch_grlen =3D=3D 64 */ -#define LONGLOG "3" -#define SZREG "8" -#define REG_L "ld.d" -#define LONG_S "st.d" -#define LONG_ADD "add.d" -#define LONG_ADDI "addi.d" -#define LONG_SLL "slli.d" #define LONG_BSTRINS "bstrins.d" #endif =20 @@ -171,28 +155,11 @@ void __attribute__((weak,noreturn,optimize("omit-fram= e-pointer"))) __no_stack_pr { __asm__ volatile ( #ifdef _NOLIBC_STACKPROTECTOR - "bl __stack_chk_init\n" /* initialize stack protector = */ + "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 ... = */ - LONG_ADDI " $a2, $a2, "SZREG"\n" /* + SZREG (skip null)= */ - LONG_ADD " $a2, $a2, $a1\n" /* + argv = */ - - "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 = */ - - "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" + "move $a0, $sp\n" /* save stack pointer to $a0, as arg1= of _start_c */ + LONG_BSTRINS " $sp, $zero, 3, 0\n" /* $sp must be 16-byte aligned = */ + "bl _start_c\n" /* transfer to c runtime = */ ); __builtin_unreachable(); } --=20 2.25.1 From nobody Sat Feb 7 15:05:56 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 A1762EB64DA for ; Wed, 12 Jul 2023 09:25:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232364AbjGLJZh (ORCPT ); Wed, 12 Jul 2023 05:25:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232263AbjGLJZ2 (ORCPT ); Wed, 12 Jul 2023 05:25:28 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6199E11D; Wed, 12 Jul 2023 02:25:27 -0700 (PDT) X-QQ-mid: bizesmtp88t1689153918teu0uwlk Received: from linux-lab-host.localdomain ( [116.30.126.249]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 12 Jul 2023 17:25:16 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: 239gR2IZrltKqPhg8ID3o5Pz4jyanvYhDcSzbwRy7HgWu927QkXaP4ef5OeRN qtA9Ik35h1ELNf5DWNXSj7UaPkRlJGClZXDclFLxWUvN7KYVyo83R+DOFY7E3AdM+TNayuy SaxbUW6yO0YCJcRelPEYJCsdW/6qQAEJCIgLIaG6+H7toJ8VV2DoHLkZKcG9NduG5oRIISv KcHn7LkesJ/IKzGbXcvQx3e2SJCFID2ajOR9LQOrwlLP3+LFuGka6gfsl8fE/wSaNB3kQuW 6F8sNOemZ2blYajmIvx7sSPXS8XShYwFwvHJbF14LQKNzJqisl7xnvJTpihGc/VfsVCkDxi kQQHgX4gJ/qH+IxomMFe677EKQIx7GjPvFkKvIF1HyBv1/q3lXej7b6FudZP7TvpdOVejS9 X-QQ-GoodBg: 0 X-BIZMAIL-ID: 86389509092924257 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de Subject: [PATCH v3 09/11] tools/nolibc: riscv: shrink _start with _start_c Date: Wed, 12 Jul 2023 17:25:15 +0800 Message-Id: <29559df55935d61e7ca774bb36fa3c73e2011090.1689150149.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" move most of the _start operations to _start_c(). Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-riscv.h | 43 +++++-------------------------- 1 file changed, 6 insertions(+), 37 deletions(-) diff --git a/tools/include/nolibc/arch-riscv.h b/tools/include/nolibc/arch-= riscv.h index 2b89ea59c5e4..2e3fcf925ae9 100644 --- a/tools/include/nolibc/arch-riscv.h +++ b/tools/include/nolibc/arch-riscv.h @@ -8,18 +8,7 @@ #define _NOLIBC_ARCH_RISCV_H =20 #include "compiler.h" - -#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 +#include "crt.h" =20 /* Syscalls for RISCV : * - stack is 16-byte aligned @@ -153,40 +142,20 @@ _arg1; \ }) =20 -char **environ __attribute__((weak)); -const unsigned long *_auxv __attribute__((weak)); - /* startup code */ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_st= ack_protector _start(void) { __asm__ volatile ( ".option push\n" ".option norelax\n" - "lla gp, __global_pointer$\n" + "lla gp, __global_pointer$\n" ".option pop\n" #ifdef _NOLIBC_STACKPROTECTOR - "call __stack_chk_init\n" /* initialize stack protector = */ + "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 ... = */ - "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 { = */ - 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) = */ - REG_S" a3, %lo(_auxv)(a4)\n" /* store a3 into _auxv = */ - - "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 = */ - "ecall\n" + "mv a0, sp\n" /* save stack pointer to a0, as arg1 of _start= _c */ + "andi sp, a0, -16\n" /* sp must be 16-byte aligned = */ + "call _start_c\n" /* transfer to c runtime = */ ); __builtin_unreachable(); } --=20 2.25.1 From nobody Sat Feb 7 15:05:56 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 4F4B4EB64DD for ; Wed, 12 Jul 2023 09:26:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232761AbjGLJ0i (ORCPT ); Wed, 12 Jul 2023 05:26:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231472AbjGLJ0f (ORCPT ); Wed, 12 Jul 2023 05:26:35 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C2CE139; Wed, 12 Jul 2023 02:26:33 -0700 (PDT) X-QQ-mid: bizesmtp65t1689153983tfw3ppgx Received: from linux-lab-host.localdomain ( [116.30.126.249]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 12 Jul 2023 17:26:22 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: J5JfekO1WsgRU4ygyCVjfG7z8UE8RA1iZUoq0kLH35rSYGgxoEMOUOGjZ5p1S EdO21pohjNWgfdEETq7vfqSMT1owM1Rdi71J+ZJmkdlGW/Zz7Jt3AGGIB+RqUQf4j5RjjKu eLb1toMwR1qyBM+Esohypdl02V/1Px26IX0V46DbxxPteDN9pkG7DD4HD1uMibcVipDMiZD KuVDwTCTzF5hoSD3L4JYMfAz2qMwXk3Gw/wA9yV4Dn3zLL/BtMg6s7QMqfS+Blz46X9Tzha G2XBXoqtkHyTf/2s5ehE+oBn/4VSqRAaangw7FZjoa7u+NswjcyWmHj12xiCIG5bfjlXokA ZJa70BSv2jwFF8eIFar5bHpaFvFdCRgsJjZWI24y7kwnZCpKwKCAPPobMppDeQoi+xoecy1 X-QQ-GoodBg: 0 X-BIZMAIL-ID: 17537015007484594219 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de Subject: [PATCH v3 10/11] tools/nolibc: s390: shrink _start with _start_c Date: Wed, 12 Jul 2023 17:26:21 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" move most of the _start operations to _start_c(). Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-s390.h | 36 +++++--------------------------- 1 file changed, 5 insertions(+), 31 deletions(-) diff --git a/tools/include/nolibc/arch-s390.h b/tools/include/nolibc/arch-s= 390.h index a40424ba043e..051f3f4ed19b 100644 --- a/tools/include/nolibc/arch-s390.h +++ b/tools/include/nolibc/arch-s390.h @@ -9,6 +9,7 @@ #include =20 #include "compiler.h" +#include "crt.h" =20 /* Syscalls for s390: * - registers are 64-bit @@ -137,41 +138,14 @@ _arg1; \ }) =20 -char **environ __attribute__((weak)); -const unsigned long *_auxv __attribute__((weak)); - /* startup code */ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_st= ack_protector _start(void) { __asm__ volatile ( - "lg %r2,0(%r15)\n" /* argument count */ - "la %r3,8(%r15)\n" /* argument pointers */ - - "xgr %r0,%r0\n" /* r0 will be our NULL value */ - /* search for envp */ - "lgr %r4,%r3\n" /* start at argv */ - "0:\n" - "clg %r0,0(%r4)\n" /* entry zero? */ - "la %r4,8(%r4)\n" /* advance pointer */ - "jnz 0b\n" /* no -> test next pointer */ - /* yes -> r4 now contains start of envp */ - "larl %r1,environ\n" - "stg %r4,0(%r1)\n" - - /* search for auxv */ - "lgr %r5,%r4\n" /* start at envp */ - "1:\n" - "clg %r0,0(%r5)\n" /* entry zero? */ - "la %r5,8(%r5)\n" /* advance pointer */ - "jnz 1b\n" /* no -> test next pointer */ - "larl %r1,_auxv\n" /* yes -> store value in _auxv */ - "stg %r5,0(%r1)\n" - - "aghi %r15,-160\n" /* allocate new stackframe */ - "xc 0(8,%r15),0(%r15)\n" /* clear backchain */ - "brasl %r14,main\n" /* ret value of main is arg to exit */ - "lghi %r1,1\n" /* __NR_exit */ - "svc 0\n" + "lgr %r2, %r15\n" /* save stack pointer to %r2, as arg1 of _sta= rt_c */ + "aghi %r15, -160\n" /* allocate new stackframe = */ + "xc 0(8,%r15), 0(%r15)\n" /* clear backchain = */ + "brasl %r14, _start_c\n" /* transfer to c runtime = */ ); __builtin_unreachable(); } --=20 2.25.1 From nobody Sat Feb 7 15:05:56 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 15772EB64D9 for ; Wed, 12 Jul 2023 09:27:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232835AbjGLJ1p (ORCPT ); Wed, 12 Jul 2023 05:27:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232772AbjGLJ1m (ORCPT ); Wed, 12 Jul 2023 05:27:42 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF6CBFB; Wed, 12 Jul 2023 02:27:40 -0700 (PDT) X-QQ-mid: bizesmtp76t1689154051tknq755c Received: from linux-lab-host.localdomain ( [116.30.126.249]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 12 Jul 2023 17:27:30 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: 0nVv8wOro77vy4UoA7x+7BKA4KP17B5ePOoos9KdPSu4lX3g/jQWX5p5bQe81 uk1rep7yGkn3ZK0WeEiENotC+WSBpA+y8mcpeQu3yRB++8mz9Q3eEoyOGCpryRpqclGX02t HIcCXYxqyTQNggTEnh3RXxIsofcYfY6euv7vve37dHQqnzwtngwneexKq0EHaruHVpN9otS jgBXB4djg1LSLZaTH27xE+gT4zzs58Cn31MvRCJCAuNWMIOqQj9A1471dpCZ2ZXrcykWVuT yUng3g53nFtiz8gty0yP5fvvsCGj1Sqm1R2eATEWObbRnWtOtdpTD563Vh2B2KJqbV9Nm1H p+K7+VK+6CIsHrlobIXJKohHySC/XHgdUIUZCKFvo//cV0jMrTZb75KpH2y+Id00uE7CPPJ X-QQ-GoodBg: 0 X-BIZMAIL-ID: 8164517920057648241 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de Subject: [PATCH v3 11/11] tools/nolibc: arch-*.h: add missing space after ',' Date: Wed, 12 Jul 2023 17:27:26 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Fix up such errors reported by scripts/checkpatch.pl: ERROR: space required after that ',' (ctx:VxV) #148: FILE: tools/include/nolibc/arch-aarch64.h:148: +void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __n= o_stack_protector _start(void) ^ ERROR: space required after that ',' (ctx:VxV) #148: FILE: tools/include/nolibc/arch-aarch64.h:148: +void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __n= o_stack_protector _start(void) ^ Signed-off-by: Zhangjin Wu --- 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-s390.h | 2 +- tools/include/nolibc/arch-x86_64.h | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/include/nolibc/arch-aarch64.h b/tools/include/nolibc/arc= h-aarch64.h index e52fa5a20d71..c94fdca9ace6 100644 --- a/tools/include/nolibc/arch-aarch64.h +++ b/tools/include/nolibc/arch-aarch64.h @@ -145,7 +145,7 @@ }) =20 /* startup code */ -void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_st= ack_protector _start(void) +void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_= stack_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 74773ddcf4ca..5f8bfc24e9c7 100644 --- a/tools/include/nolibc/arch-arm.h +++ b/tools/include/nolibc/arch-arm.h @@ -185,7 +185,7 @@ }) =20 /* startup code */ -void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_st= ack_protector _start(void) +void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_= stack_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 f0d0f5c364b8..915f0e77629e 100644 --- a/tools/include/nolibc/arch-i386.h +++ b/tools/include/nolibc/arch-i386.h @@ -162,7 +162,7 @@ * 2) The deepest stack frame should be set to zero * */ -void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_st= ack_protector _start(void) +void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_= stack_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 9db70d6f2c31..6edec94538e0 100644 --- a/tools/include/nolibc/arch-loongarch.h +++ b/tools/include/nolibc/arch-loongarch.h @@ -151,7 +151,7 @@ #endif =20 /* startup code */ -void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_st= ack_protector _start(void) +void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_= stack_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 b1c070c5b24a..36d4bf0c6aaa 100644 --- a/tools/include/nolibc/arch-mips.h +++ b/tools/include/nolibc/arch-mips.h @@ -175,7 +175,7 @@ }) =20 /* startup code, note that it's called __start on MIPS */ -void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_st= ack_protector __start(void) +void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_= stack_protector __start(void) { __asm__ volatile ( ".set push\n" diff --git a/tools/include/nolibc/arch-riscv.h b/tools/include/nolibc/arch-= riscv.h index 2e3fcf925ae9..043e2fd85ab0 100644 --- a/tools/include/nolibc/arch-riscv.h +++ b/tools/include/nolibc/arch-riscv.h @@ -143,7 +143,7 @@ }) =20 /* startup code */ -void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_st= ack_protector _start(void) +void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_= stack_protector _start(void) { __asm__ volatile ( ".option push\n" diff --git a/tools/include/nolibc/arch-s390.h b/tools/include/nolibc/arch-s= 390.h index 051f3f4ed19b..705576d8fd15 100644 --- a/tools/include/nolibc/arch-s390.h +++ b/tools/include/nolibc/arch-s390.h @@ -139,7 +139,7 @@ }) =20 /* startup code */ -void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_st= ack_protector _start(void) +void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_= stack_protector _start(void) { __asm__ volatile ( "lgr %r2, %r15\n" /* save stack pointer to %r2, as arg1 of _sta= rt_c */ diff --git a/tools/include/nolibc/arch-x86_64.h b/tools/include/nolibc/arch= -x86_64.h index 0048adf6b11f..f5614a67f05a 100644 --- a/tools/include/nolibc/arch-x86_64.h +++ b/tools/include/nolibc/arch-x86_64.h @@ -161,7 +161,7 @@ * 2) The deepest stack frame should be zero (the %rbp). * */ -void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_st= ack_protector _start(void) +void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_= stack_protector _start(void) { __asm__ volatile ( #ifdef _NOLIBC_STACKPROTECTOR --=20 2.25.1