From patchwork Wed Jun 28 18:51:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 114001 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9138206vqr; Wed, 28 Jun 2023 11:53:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ68LOHjAAGs2z7KYeqJjm9uM7uGvvCtmzFnH+h3vAd/k3L1kMQDITQrrvCGXaRxRQN38YDs X-Received: by 2002:a17:90b:1bc2:b0:258:9621:913f with SMTP id oa2-20020a17090b1bc200b002589621913fmr42474323pjb.3.1687978425932; Wed, 28 Jun 2023 11:53:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687978425; cv=none; d=google.com; s=arc-20160816; b=hKl2VMslW3Dv0aP0Qfc1hETaQKs5dbuDEt2LFs/7hZMAIwNPaaEnI76+rZdOPqM+wQ tcbQY2Twwo+Q+A6uCeq1ED9oDjz3kuT8L6//jhKU4+CZffz1ae3miq05NxJaiYk+KOn1 GF3xCR9l5am8GCwRgIFuURmHTYQeT68JETkcQKTLJaMko+zAO3Eep83zRRL+4m6FdO73 xMwMv/th9X0h2OlRCLLpaProoSm9j1SZQRRlTe+xUe93zyOTanFaBRzILqlpLh+fda+b 0mYA8Y1kzuISPsnV9fud9AxZmYZlpJPCKcMeCtYIeqfgkwxH2KRId86E01u/3mik20vy +OjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=FnRCFhBYW/0IQUejSJoekFpszjQ1Vwd9H/JVWmY5kmk=; fh=jGpRxxGHkcGZyN2ZnaDwhUy8S6joixew3DGGT1L/CuQ=; b=qxlec6hKiJJEsaxE16xChImC4Gao7qb/OEs1iUua1kyD4JuhMpx7zXWjG47i7BcBeU 5D9c39+bqyzP4wGQz2oWq8p3JWwZnifT59GjeXpPeZDj5qFa4JdicbCAyZ/dEOsFBVhb zH8Ci5F0oEi1x9FpXa44DdstEEXGjm5eYZH6AN5UtHxMXaFdyqNj7Zgb8w9F9fcDa5Qh SbPLwgkOaF0rjRnnd868BnIJ1cSL4LjZPSWnidMzvPaFHy6sxRiYyagWe2Hnpl7ZwAN0 bBl8bQMqD7R9GfwXiHsH06eSD9IRS2ElyFtcTuaUlboU9XcVvKuXN8YOkJN8pP5mvHT1 TR0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t11-20020a170902d14b00b001aae905065csi8677613plt.284.2023.06.28.11.53.33; Wed, 28 Jun 2023 11:53:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231848AbjF1Swp (ORCPT + 99 others); Wed, 28 Jun 2023 14:52:45 -0400 Received: from bg4.exmail.qq.com ([43.155.65.254]:38608 "EHLO bg4.exmail.qq.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232618AbjF1SwZ (ORCPT ); Wed, 28 Jun 2023 14:52:25 -0400 X-QQ-mid: bizesmtp67t1687978334t02f1mza Received: from linux-lab-host.localdomain ( [116.30.129.193]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 29 Jun 2023 02:52:13 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: Xz3VOcA7Mr3gM7j2N3URL6OULX8Nwl8kP/OduJla9sUz4N4Rq2L64QPEi4OLN IzHLEmbg5hoGslKAm4D2iHE8kn5y2r00VH6R9Ywjjd37yrrL9Nryze8CCQIMQI9S6Af4GXj B2B41Ti5fHWQj4qLOe76pBbaYQaRmXSstZ0y6Xz6Zt041C9s3P8gURVH4FeRILaLvzn0yEv rdOM2sIhfkhEA0C3aXmF2IE1/BkZCD5mbhJGUR1fEHbKd88QATM25tUV6LhLKjImw3q/WEo iYTUzKw8aRBCXs3w0Mzq46yiilid8F8X9zukTKMN+24xG3GpLBjiUvkVQ1BUYJacLyEt4KE +PQdwUJGUUPDMOcfitP9AGFx4oG5CI6AHfK8vCp47Aiz7g5F3jojLSDqheWgw== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 11973228627114072650 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v1 01/11] tools/nolibc: remove old arch specific stat support Date: Thu, 29 Jun 2023 02:51:52 +0800 Message-Id: <77442e760bec4a99946db64ad4e17dbc353b8979.1687976753.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769973666235593914?= X-GMAIL-MSGID: =?utf-8?q?1769973666235593914?= __NR_statx has been added from v4.10: commit a528d35e8bfc ("statx: Add a system call to make enhanced file info 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 specific 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/arch-aarch64.h index e30056f996db..4a8a6f386865 100644 --- a/tools/include/nolibc/arch-aarch64.h +++ b/tools/include/nolibc/arch-aarch64.h @@ -9,34 +9,6 @@ #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. - */ -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-arm.h index 7a64290fc518..a2ea5756cef2 100644 --- a/tools/include/nolibc/arch-arm.h +++ b/tools/include/nolibc/arch-arm.h @@ -9,43 +9,6 @@ #include "compiler.h" -/* The struct returned by the stat() syscall, 32-bit only, the syscall returns - * exactly 56 bytes (stops before the unused array). In big endian, the format - * 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-i386.h index c2e75ba91b6b..418554435545 100644 --- a/tools/include/nolibc/arch-i386.h +++ b/tools/include/nolibc/arch-i386.h @@ -9,32 +9,6 @@ #include "compiler.h" -/* The struct returned by the stat() syscall, 32-bit only, the syscall returns - * 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-mips.h index a8b33d6914a4..ecf912a1938f 100644 --- a/tools/include/nolibc/arch-mips.h +++ b/tools/include/nolibc/arch-mips.h @@ -9,34 +9,6 @@ #include "compiler.h" -/* 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 numbers diff --git a/tools/include/nolibc/arch-riscv.h b/tools/include/nolibc/arch-riscv.h index 4f21e862b412..7f4abcc15206 100644 --- a/tools/include/nolibc/arch-riscv.h +++ b/tools/include/nolibc/arch-riscv.h @@ -9,29 +9,6 @@ #include "compiler.h" -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 == 64 #define PTRLOG "3" #define SZREG "8" diff --git a/tools/include/nolibc/arch-s390.h b/tools/include/nolibc/arch-s390.h index 8cff5b05e841..5139e0e37e56 100644 --- a/tools/include/nolibc/arch-s390.h +++ b/tools/include/nolibc/arch-s390.h @@ -10,31 +10,6 @@ #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. - */ - -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 1dc8b60f5153..4c0192815a59 100644 --- a/tools/include/nolibc/arch-x86_64.h +++ b/tools/include/nolibc/arch-x86_64.h @@ -9,33 +9,6 @@ #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. - */ -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 e0ac95a4bfa1..2c302f3feb71 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -914,15 +914,19 @@ pid_t setsid(void) return __sysret(sys_setsid()); } -#if defined(__NR_statx) /* * int statx(int fd, const char *path, int flags, unsigned int mask, struct statx *buf); + * int stat(const char *path, struct stat *buf); */ static __attribute__((unused)) int sys_statx(int fd, const char *path, int flags, unsigned int mask, struct statx *buf) { +#ifdef __NR_statx return my_syscall5(__NR_statx, fd, path, flags, mask, buf); +#else + return -ENOSYS; +#endif } static __attribute__((unused)) @@ -930,24 +934,18 @@ int statx(int fd, const char *path, int flags, unsigned int mask, struct statx * { return __sysret(sys_statx(fd, path, flags, mask, buf)); } -#endif -/* - * int stat(const char *path, struct stat *buf); - * Warning: the struct stat's layout is arch-dependent. - */ -#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; - ret = sys_statx(AT_FDCWD, path, AT_NO_AUTOMOUNT, STATX_BASIC_STATS, &statx); + ret = __sysret(sys_statx(AT_FDCWD, path, AT_NO_AUTOMOUNT, STATX_BASIC_STATS, &statx)); + if (ret == -1) + return ret; + buf->st_dev = ((statx.stx_dev_minor & 0xff) | (statx.stx_dev_major << 8) | ((statx.stx_dev_minor & ~0xff) << 12)); @@ -968,47 +966,8 @@ int sys_stat(const char *path, struct stat *buf) buf->st_mtim.tv_nsec = statx.stx_mtime.tv_nsec; buf->st_ctim.tv_sec = statx.stx_ctime.tv_sec; buf->st_ctim.tv_nsec = 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 = my_syscall4(__NR_newfstatat, AT_FDCWD, path, &stat, 0); -#elif defined(__NR_stat) - ret = my_syscall2(__NR_stat, path, &stat); -#else - return -ENOSYS; -#endif - buf->st_dev = stat.st_dev; - buf->st_ino = stat.st_ino; - buf->st_mode = stat.st_mode; - buf->st_nlink = stat.st_nlink; - buf->st_uid = stat.st_uid; - buf->st_gid = stat.st_gid; - buf->st_rdev = stat.st_rdev; - buf->st_size = stat.st_size; - buf->st_blksize = stat.st_blksize; - buf->st_blocks = stat.st_blocks; - buf->st_atim.tv_sec = stat.st_atime; - buf->st_atim.tv_nsec = stat.st_atime_nsec; - buf->st_mtim.tv_sec = stat.st_mtime; - buf->st_mtim.tv_nsec = stat.st_mtime_nsec; - buf->st_ctim.tv_sec = stat.st_ctime; - buf->st_ctim.tv_nsec = stat.st_ctime_nsec; - return ret; -} -#endif -static __attribute__((unused)) -int stat(const char *path, struct stat *buf) -{ - return __sysret(sys_stat(path, buf)); + return 0; } diff --git a/tools/include/nolibc/types.h b/tools/include/nolibc/types.h index bed62da7877c..7c794ec21b46 100644 --- a/tools/include/nolibc/types.h +++ b/tools/include/nolibc/types.h @@ -14,8 +14,8 @@ /* 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. */ /* stat flags (WARNING, octal here). We need to check for an existing From patchwork Wed Jun 28 18:53:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 114006 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9139779vqr; Wed, 28 Jun 2023 11:57:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6F75To1H1uZSRphku5QXNL8ZmpnbplRQXQET91drMERRw1Nonoc65sXvat2x9Zd18JRbfN X-Received: by 2002:a05:6a20:6a0c:b0:125:943f:cf02 with SMTP id p12-20020a056a206a0c00b00125943fcf02mr22765465pzk.6.1687978620133; Wed, 28 Jun 2023 11:57:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687978620; cv=none; d=google.com; s=arc-20160816; b=ZeE7A7xno9HDnzIBNCz4dB1qDxgxe/cnnnAjakKeT/+TujYDltZvz9sK3uM0ARt9nB UQIr6aqKgbVtAbSiHkfJbkvUkww34ypNuEqVqOlkGtVouBc8txogFUh1jXudQSamiXeQ vnkfrHTpGKKcJu3iTl3KdBwjnd9piG+eIUyz5kxnTCg9+SRMYZYKVPOxGStPDhO3mDoo 5/QgeZEpYxHl+sxmY/5HIkSOkalovXQ5ZoiMkAI4Jq00tkToOT4PB6Ubc9F1z9wKITVX TUrIUD6R/w4ZaV6pwCHwIFZPM/YyZ7lAl4ASMe4ekSBMxXk8rC7ut7BE+LTUNixprJZL Jdnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=5PqRNk7b2/BJzAUKRRRiXuuaxddP6P+RKe1Q+bM+k4c=; fh=jGpRxxGHkcGZyN2ZnaDwhUy8S6joixew3DGGT1L/CuQ=; b=AOOESkIiRbYMnsL8wGzCsqDsbH1rugubsSZUUbdDS1MYFimVLBb4V+GPXLBYFhsqpX SXKSy/8lO0PwPEx00qqwt5wdAGJUgXBKiUqe1RB5cxxDKL/dG7n6bdI+FtaDcqK1ag2v rOKc+oHUglljYTZUqXwcXHJ5JoNuAZ43HD3W5TOL5W0A7ffZHAO3oYSF1K7Zf98LTx7I 4KrMuyHAG62zr4SneJn+9bWlfhgN2R/qksZW0e/dDJ+Jyz76ipXeky71kwQSBfr7r6H8 YPNwZnD3RskvRIHzyUIzKveeHyRjBPV9V0f18jwLzM/BaKvDWLlOWcLr5q1SDbh6gubK LcIA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e4-20020aa78c44000000b006735cb33a69si7153391pfd.65.2023.06.28.11.56.45; Wed, 28 Jun 2023 11:57:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231522AbjF1SzL (ORCPT + 99 others); Wed, 28 Jun 2023 14:55:11 -0400 Received: from bg4.exmail.qq.com ([43.155.65.254]:32295 "EHLO bg4.exmail.qq.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231454AbjF1Sxk (ORCPT ); Wed, 28 Jun 2023 14:53:40 -0400 X-QQ-mid: bizesmtp68t1687978411t0a7h12q Received: from linux-lab-host.localdomain ( [116.30.129.193]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 29 Jun 2023 02:53:30 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: mhgCCnGOC3zHQx6jmcB1kz2NwHDP18v38JyGZQAiWr5o2Az3hiwOxWqJkj3sr al8QuuOwy8FjxN1au85JUw6DW1Wb/vHX+2GC8XTjfP+O1t3S8qORnqLdPM4Cf3pGlaNlChX IHySjIMY6PzNPzCMg+XhHGFJZdwOJjXNsPKyYq9th7KpBU9mTcFUUeq4Sd4P+9ywNxuj/kp QXH2k7KkcaMDqTnkd4C35V2UHyfP7DbRQBaqLYhMy0H3EM5JlWAOt5xoIudinQAR0jwiSBJ 40AtcWRh83++0lXsOvsW4Jkmh6pGtR+4nBRcL1IOSR0yfiq5l+cw6ZOed+Sl5CuENCqT1a2 z8R4BsBETw1oB5lmDLIPriksbujqTB7Rf8E6RzmmPTuI8MlY10= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 10897143188466502564 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v1 02/11] tools/nolibc: add new crt.h with _start_c Date: Thu, 29 Jun 2023 02:53:18 +0800 Message-Id: <0976471a36cd4facf712bc02e733f669f1697083.1687976753.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769973869665421867?= X-GMAIL-MSGID: =?utf-8?q?1769973869665421867?= 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 crt.h is added to do most of the assembly start operations in C function: _start_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. It may also easier the future init/fini support. Signed-off-by: Zhangjin Wu --- tools/include/nolibc/crt.h | 57 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tools/include/nolibc/crt.h diff --git a/tools/include/nolibc/crt.h b/tools/include/nolibc/crt.h new file mode 100644 index 000000000000..698fe1084d26 --- /dev/null +++ b/tools/include/nolibc/crt.h @@ -0,0 +1,57 @@ +/* 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)); + +int main(int argc, char *argv[], char **envp); +static void exit(int); + +void _start_c(long *sp) +{ + int argc, i; + char **argv; + char **envp; + + /* + * 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 = sp[0]; + argv = (void *)(sp + 1); + + /* find envp */ + envp = argv + argc + 1; + environ = envp; + + /* find auxv */ + i = 0; + while (envp[i]) + i++; + _auxv = (void *)(envp + i + 1); + + /* go to application */ + exit(main(argc, argv, envp)); +} + +#endif /* _NOLIBC_CRT_H */ From patchwork Wed Jun 28 18:54:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 114014 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9141026vqr; Wed, 28 Jun 2023 11:59:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7XZSG0zz0bI4g9ZHLm4jU1Xlei80vogrRlJBEsIoVmVuA3t3KqITm7LI27MU9n5tmPSL6v X-Received: by 2002:a05:6a00:2305:b0:66d:d03e:3493 with SMTP id h5-20020a056a00230500b0066dd03e3493mr13481607pfh.2.1687978779761; Wed, 28 Jun 2023 11:59:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687978779; cv=none; d=google.com; s=arc-20160816; b=wy3LRWpbeK0OilyE2G1/s7XWZUXJNFplxh+/7eCscEE+jE4QdkmvePOx++D0w5pIsB aGeS/ajgwgEFFj8b/bcVT66u5Cl18fxOhZg1rfzdfeV4opC7kLp2+r0dWs9EITfHIWxs eEo2yRUjeRkHnzS6AggoIkK2kTHe/Sl+6fzHeIjzV8+re0mkxlKVa7MhKYPHpdhdDRya oMhbGpPYgKc2349GdxH/4oZqrLSkj7sd9lrHRpdl85JAV+12cCW0/DPZQQOKSI5hXDmZ pj2B0ffHqF6HGmcqR3R4JQlX9+aASUehVYANgBfGSKG8V4xdgAk1N6QGeMr0kjNrtKPX tQCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=8kJtPv+7v4FOyjCBhvCGoDkEzp/T+VoIB1NbPt9MmPQ=; fh=jGpRxxGHkcGZyN2ZnaDwhUy8S6joixew3DGGT1L/CuQ=; b=PaU5Roc1vkKG6X07HDn3ZvFQlnpozrKCbk/zJkMyKRYZzAltZ9oMdoQs4MZaBxcGXC 4163pxvY+B2OxCJZN/18MbZJzx2MIl+NU6dvWG1YXpMjuUgoHnFf41Nlm6/b7r6e1DCi XP5Uj1JotXuBsWO98ocxISaOBVQfVVod8D0+H+gLkGOlUjx2C6MhuA/72hsDy4AKPdVi BqqSR2z+q7bjJRVtWT+zkNp40v/hBW94nd+9lO7OkjSEDAqZ5P4dY+5yLIdCVKwD09e1 2FkqOW94sYdbFI/4cjJdCdCFiWjzM3TnVZ6p7Wc6LvrKvZKMtMAtZiEV6XO5Ea+i974W B5HA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l70-20020a639149000000b005481915c0d1si9693536pge.45.2023.06.28.11.59.25; Wed, 28 Jun 2023 11:59:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232060AbjF1S51 (ORCPT + 99 others); Wed, 28 Jun 2023 14:57:27 -0400 Received: from bg4.exmail.qq.com ([43.155.65.254]:17826 "EHLO bg4.exmail.qq.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233094AbjF1Syx (ORCPT ); Wed, 28 Jun 2023 14:54:53 -0400 X-QQ-mid: bizesmtp90t1687978484tji35iud Received: from linux-lab-host.localdomain ( [116.30.129.193]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 29 Jun 2023 02:54:42 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: Lc4bMlOoZUGkpC/7Ifsyooy6DUcO5i0KRvgdG3YbtX646PzLWnBy6Qxr2/y+U ozNqeIN24oj33/Fotsv6FXjKjhpcf5dts1f4iXPVGjLEOyao8iLruCcBq410/Itbx/yQ82D 4a/DbSH5mlYrgjNVPOh+05Z7F8YWqIAq1qjLT4KMXlyNwrpo7QCsU1QCoKz7cIBCFcrr/Ty IDCMxPgLOJFrecb2pQfzxgO73wk3O0vG3Jcs9W5Sk1Bx2FAaefhT0X35wITWlcT1vqd/uvw bUFlzoPMtnjOpFjHio6NpWI5h0Xj5DFbj2dO5JQCyMdvzC+NNyc+s2q5cad0Yuidf0no2SX kpAAdeYqkgMSQGSZPfd5ki6h4+yttF3ULm1K+4MDPrKxb1Fr2gGOQLmqydKkQ== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 5556601059308245209 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v1 03/11] tools/nolibc: include crt.h before arch.h Date: Thu, 29 Jun 2023 02:54:35 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769974036998417226?= X-GMAIL-MSGID: =?utf-8?q?1769974036998417226?= The crt.h provides a new _start_c() function, which is required by the new assembly _start entry of arch-.h (included by arch.h), let's include crt.h before arch.h. This '#include "crt.h"' doesn't let the new _start_c() work immediately, but it is a base of the coming patches to move most of the assembly _start operations to the _start_c() function for every supported architecture. Signed-off-by: Zhangjin Wu --- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/nolibc.h | 1 + tools/include/nolibc/signal.h | 1 + tools/include/nolibc/stdio.h | 1 + tools/include/nolibc/stdlib.h | 1 + tools/include/nolibc/sys.h | 1 + tools/include/nolibc/time.h | 1 + tools/include/nolibc/unistd.h | 1 + 8 files changed, 8 insertions(+) diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 875e13e3c851..00471e59b11e 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -37,6 +37,7 @@ NARCH = $(or $(NARCH_$(ARCH)),$(ARCH)) arch_file := arch-$(NARCH).h all_files := \ compiler.h \ + crt.h \ ctype.h \ errno.h \ nolibc.h \ diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h index 1f8d821000ac..2cc9ccd90d56 100644 --- a/tools/include/nolibc/nolibc.h +++ b/tools/include/nolibc/nolibc.h @@ -93,6 +93,7 @@ #define _NOLIBC_H #include "std.h" +#include "crt.h" #include "arch.h" #include "types.h" #include "sys.h" diff --git a/tools/include/nolibc/signal.h b/tools/include/nolibc/signal.h index 137552216e46..f0a1418c1cb2 100644 --- a/tools/include/nolibc/signal.h +++ b/tools/include/nolibc/signal.h @@ -8,6 +8,7 @@ #define _NOLIBC_SIGNAL_H #include "std.h" +#include "crt.h" #include "arch.h" #include "types.h" #include "sys.h" diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h index 0eef91daf289..89d3749b3620 100644 --- a/tools/include/nolibc/stdio.h +++ b/tools/include/nolibc/stdio.h @@ -10,6 +10,7 @@ #include #include "std.h" +#include "crt.h" #include "arch.h" #include "errno.h" #include "types.h" diff --git a/tools/include/nolibc/stdlib.h b/tools/include/nolibc/stdlib.h index 902162f80337..0ff7fac40bd4 100644 --- a/tools/include/nolibc/stdlib.h +++ b/tools/include/nolibc/stdlib.h @@ -8,6 +8,7 @@ #define _NOLIBC_STDLIB_H #include "std.h" +#include "crt.h" #include "arch.h" #include "types.h" #include "sys.h" diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 2c302f3feb71..b6c33c40c037 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -24,6 +24,7 @@ #include /* for LINUX_REBOOT_* */ #include +#include "crt.h" #include "arch.h" #include "errno.h" #include "types.h" diff --git a/tools/include/nolibc/time.h b/tools/include/nolibc/time.h index 84655361b9ad..bbe8f9aa3e9b 100644 --- a/tools/include/nolibc/time.h +++ b/tools/include/nolibc/time.h @@ -8,6 +8,7 @@ #define _NOLIBC_TIME_H #include "std.h" +#include "crt.h" #include "arch.h" #include "types.h" #include "sys.h" diff --git a/tools/include/nolibc/unistd.h b/tools/include/nolibc/unistd.h index e38f3660c051..f1677224bb5a 100644 --- a/tools/include/nolibc/unistd.h +++ b/tools/include/nolibc/unistd.h @@ -8,6 +8,7 @@ #define _NOLIBC_UNISTD_H #include "std.h" +#include "crt.h" #include "arch.h" #include "types.h" #include "sys.h" From patchwork Wed Jun 28 18:55:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 114015 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9142199vqr; Wed, 28 Jun 2023 12:01:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6EemCJpgZZx4aUgbzAKARNDb0lQCQjMYqAnszyQH11pBJJnNd2722cYh9Ze6mPMHCx4/wy X-Received: by 2002:a17:902:ecc6:b0:1ae:1364:6086 with SMTP id a6-20020a170902ecc600b001ae13646086mr43296431plh.2.1687978878912; Wed, 28 Jun 2023 12:01:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687978878; cv=none; d=google.com; s=arc-20160816; b=mWXMVsVu0MNdYQiydtHrIicFN6UPeUbAuyZsnOrvTogO/rV7LeFejhmYp6RLmt75t6 xKKc2cYfD/gSho0hOiQXhMEwhVbCfxU9D1fI+eW+wc8o03U5SCIoqjIAWAk2Tz4iWRMg RBP1K1KqGc2kUZ1Blglbe7UdvMsRFZh6k5ILBWx3y+0Zv8HBiy5reBkdO6Oc5X8HKBmT xGiCf2+xLubZIC5Iavi1jNL4A0SYD5O0yo1kA8v0C1aYZ2n/MKkPA9/ut1rvlTHF4o/+ BVfRbJ4tcFwRhWx56w5VpO94PrdFbdSwSGz1RdPdJ+Lw2b9hpP+1aZKdK0TMQxrNB4UY EpQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=iXhOr+/rLWCQLqDgmgJtouYb9IZRw0BbvSJjnGp+slg=; fh=jGpRxxGHkcGZyN2ZnaDwhUy8S6joixew3DGGT1L/CuQ=; b=JV4fwUJ7OJuCB4kiUa1cUqPTG/ewZurOKREYXl4K9pbbXo1b6punqyUKJXWaB7CvG/ 4Qk4SBnKtURSg2wwa9041xjbQ09kFLKK5owgO+3OJrbGsrsx7JG++UlG49Jhme6na4hS PvEY/Uvi+PM5FpRHPbT2THcq84KSiRuOFNkPDvjeGpGH5LAoGM7geArdkmIPQzgphoQa z+2sItyAR99E3RmYR3WE8Ny4Y6THQSUJX0lNwCQb80I09fLJmbw3mVAy4KGUmYxsmMo1 3oYaI4XNzGd6WewvoYkaKlIpRmVhaAsnga9s+uQi3/wxy3v8zFQHdBEL6XFPyhNzQ6Nn 3cyA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j9-20020a170902da8900b001b80a89dcc0si6119052plx.143.2023.06.28.12.00.39; Wed, 28 Jun 2023 12:01:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231140AbjF1S61 (ORCPT + 99 others); Wed, 28 Jun 2023 14:58:27 -0400 Received: from bg4.exmail.qq.com ([43.155.65.254]:22828 "EHLO bg4.exmail.qq.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232414AbjF1S4a (ORCPT ); Wed, 28 Jun 2023 14:56:30 -0400 X-QQ-mid: bizesmtp66t1687978579tbslkfmx Received: from linux-lab-host.localdomain ( [116.30.129.193]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 29 Jun 2023 02:56:18 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: CR3LFp2JE4myL95Bwy4YA+PlVj9c4rCxTO0cf3tpSnq4AppLl9rYNCM+pxYWU 85WwvNW4tuBtdM9saYd8fKHWyVNTzgqBFOQ7Tj573N32L3L1hma3fsXS3oAm9gSuKH5AlVo 1u5B3rl7TURqs7ZPJv1OvrdgdefC0C2rpabwBjDRYuzh3a9DpjzBIpMdzyxF0JI3wfddcDj uUXMsItEirc4c2MVlSNMaqgOIKlKB0UQdoQOlBSNOkT7vrAHYpAloMkgLUBN4kDzl2fJ0FX /DCeTcsJQUsNseXiYNiJ1Hf0b47baGzRqIoVb5tN/PKl0Cj8RCn4vMkP7eQHzi7Eu/LXNOU PHrAGTFqRGq3xyDEU4qlJPzKdstMgA8zU1cFTjbSr9TWNOl0jg= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 15633203404087285430 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v1 04/11] tools/nolibc: arm: shrink _start with _start_c Date: Thu, 29 Jun 2023 02:55:48 +0800 Message-Id: <30376b12e786f10ac8735431c35bc629f92a7d32.1687976753.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769974140766075700?= X-GMAIL-MSGID: =?utf-8?q?1769974140766075700?= Let's move most of the _start operations to _start_c(). Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-arm.h | 42 ++++----------------------------- 1 file changed, 5 insertions(+), 37 deletions(-) diff --git a/tools/include/nolibc/arch-arm.h b/tools/include/nolibc/arch-arm.h index a2ea5756cef2..573f8fe31cee 100644 --- a/tools/include/nolibc/arch-arm.h +++ b/tools/include/nolibc/arch-arm.h @@ -183,49 +183,17 @@ _arg1; \ }) - -char **environ __attribute__((weak)); -const unsigned long *_auxv __attribute__((weak)); - /* startup code */ 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 */ + "bl __stack_chk_init\n" /* initialize stack protector */ #endif - "pop {%r0}\n" /* argc was in the stack */ - "mov %r1, %sp\n" /* argv = sp */ - - "add %r2, %r0, $1\n" /* envp = (argc + 1) ... */ - "lsl %r2, %r2, $2\n" /* * 4 ... */ - "add %r2, %r2, %r1\n" /* + argv */ - "ldr %r3, 1f\n" /* r3 = &environ (see below) */ - "str %r2, [r3]\n" /* store envp into environ */ - - "mov r4, r2\n" /* search for auxv (follows NULL after last env) */ - "0:\n" - "mov r5, r4\n" /* r5 = r4 */ - "add r4, r4, #4\n" /* r4 += 4 */ - "ldr r5,[r5]\n" /* r5 = *r5 = *(r4-4) */ - "cmp r5, #0\n" /* and stop at NULL after last env */ - "bne 0b\n" - "ldr %r3, 2f\n" /* r3 = &_auxv (low bits) */ - "str r4, [r3]\n" /* store r4 into _auxv */ - - "mov %r3, $8\n" /* AAPCS : sp must be 8-byte aligned in the */ - "neg %r3, %r3\n" /* callee, and bl doesn't push (lr=pc) */ - "and %r3, %r3, %r1\n" /* so we do sp = r1(=sp) & r3(=-8); */ - "mov %sp, %r3\n" - - "bl main\n" /* main() returns the status code, we'll exit with it. */ - "movs r7, $1\n" /* NR_exit == 1 */ - "svc $0x00\n" - ".align 2\n" /* below are the pointers to a few variables */ - "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(); } From patchwork Wed Jun 28 18:57:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 114016 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9142260vqr; Wed, 28 Jun 2023 12:01:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6LN/0WKYT238H6gQIV1D5LhKZkBMDpYAMdCFfbSuvBpO9PD6vGKeE643tDTJAKElxyTEDm X-Received: by 2002:a05:6a00:190d:b0:668:834d:4bd with SMTP id y13-20020a056a00190d00b00668834d04bdmr833435pfi.0.1687978882007; Wed, 28 Jun 2023 12:01:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687978881; cv=none; d=google.com; s=arc-20160816; b=Dj42rFRSk+6rhLCMvH9WjvXujL49DsGUTVhg5zplAC5uEU1ws2T6P99tXwOOVQNBqx Htas39vN5jcuXGSSzCirZMhvIkI0DD1EaTOc/pSCtfonowieMGfMdsv2voqnskrwKIel yqMv/4Ye0fM/Fv21Kpue4xRRaYOP+QtCuHSCY8LDTbXD2J8DVHbJt++uhJ+zsPLUgu44 C7qFdxviOJ8V4kLkdQqe0kciiTbACmtJGUuyJ/zAWgdRoTc4cUxgFiVzGUXHmdXtq27t ftLm08dpDE99rLL5l8T9wa10QydJpL9uBzjL2e4emZFfLY+fhPJikj6Qz/kfrtAeM/Rx Qqzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=UN+wB9mvLwuXS3dVHwI51X0WagjslngzfPQSiybfTeg=; fh=jGpRxxGHkcGZyN2ZnaDwhUy8S6joixew3DGGT1L/CuQ=; b=hFfLbYE45WlDx/WvqCB8F1GGQZ1R2sDyQS/JgN9UrFoQWb+hjJfHmA8OtmZsdHf97G CUHg1Lr6livTRDMS4RtipToQEvIY8SVobdjnGVH09v+OjoKzuA/Fxq+HWApD2A1NJWFq fFx4gvR7WpUlJLF1liGCvOh0KO37NrKpKDGkK/1O7CDQ9BnqtteqUk17E/d3ZZSfoBGr haX9kOX+MsVecukkGzRDz9p7H7tgcc3BLn8WQh8HMMYkCMFfCv5lZsTnLRgr2ajYF9GT cNigtTK3ftV+NKF1HPfDgdVSdocB/N7EbpZVL2i+lhDaYBSzd7lcPmloHzvZZqE6iigY 9NMA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q3-20020a656843000000b0054ff67d6666si9038188pgt.512.2023.06.28.12.01.05; Wed, 28 Jun 2023 12:01:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231404AbjF1S73 (ORCPT + 99 others); Wed, 28 Jun 2023 14:59:29 -0400 Received: from bg4.exmail.qq.com ([43.155.65.254]:50950 "EHLO bg4.exmail.qq.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232762AbjF1S5s (ORCPT ); Wed, 28 Jun 2023 14:57:48 -0400 X-QQ-mid: bizesmtp72t1687978659t3keb3dh Received: from linux-lab-host.localdomain ( [116.30.129.193]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 29 Jun 2023 02:57:38 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: KvvwR/hcPA35iAr8TQYDvxZOkDcgAM3TIY87E/9m40p4dKpVt+fphBTPFnApg cm8CqegYIrMMP7buadH2bcEjPZgnbPX4xzvowbn6G1s+64nmmgJaOe9ns+CWK3tXfrlH+cs /MjQq3sTuUJ5KDFemeGMQPH4c5BE3EkCn7au7Ro17HXjdLJ3FIkMo5p4R+YpMp4wCF7EGMv JaxQCrRYQnno7PmRxBlxC1Q9VJSKY8nwTHVpXkzkHibixC4A2T4aqs6tAIJZ1BNHC91ec0f hmkHi0Te9PGaNE4g7qedn3c3t0lD1E0O0BLd5mr1MnbtknEIdnVRCjLsHVEzxmEUSR67QiS 20y+PWFkCrx46YGTbC6zNW4jIwi1YGYyTROXXfQi5Nvnw3mKqQ= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 2412116737021503385 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v1 05/11] tools/nolibc: aarch64: shrink _start with _start_c Date: Thu, 29 Jun 2023 02:57:23 +0800 Message-Id: <1adc51e395e76ad05e15b5d41b6460a191d10997.1687976753.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769974144164459517?= X-GMAIL-MSGID: =?utf-8?q?1769974144164459517?= Let's move most of the _start operations to _start_c(). Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-aarch64.h | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/tools/include/nolibc/arch-aarch64.h b/tools/include/nolibc/arch-aarch64.h index 4a8a6f386865..ef98a751783f 100644 --- a/tools/include/nolibc/arch-aarch64.h +++ b/tools/include/nolibc/arch-aarch64.h @@ -143,33 +143,16 @@ _arg1; \ }) -char **environ __attribute__((weak)); -const unsigned long *_auxv __attribute__((weak)); - /* startup code */ 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 */ + "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) = sp */ - "lsl x2, x0, 3\n" /* envp (x2) = 8*argc ... */ - "add x2, x2, 8\n" /* + 8 (skip null) */ - "add x2, x2, x1\n" /* + argv */ - "adrp x3, environ\n" /* x3 = &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 = *x4; x4 += 8 */ - "cbnz x5, 0b\n" /* and stop at NULL after last env */ - "adrp x3, _auxv\n" /* x3 = &_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 == 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(); } From patchwork Wed Jun 28 18:58:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 114017 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9142592vqr; Wed, 28 Jun 2023 12:01:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4HCLyJUN68BoeReA8ZLgG21xE+fXHKB9yGZ1F2EeMl3UAo38jAWdBMhbUUYq1mUxaHg+o7 X-Received: by 2002:a17:90b:1bc2:b0:258:9621:913f with SMTP id oa2-20020a17090b1bc200b002589621913fmr42491708pjb.3.1687978906443; Wed, 28 Jun 2023 12:01:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687978906; cv=none; d=google.com; s=arc-20160816; b=ENIMqno014037O0O2pj4/QU7mScT9vIs8pRQm5atWSftXR8kP9PJhhgh8B6ra/Eavi rlWTe3ZiJjoA/GQN+Ns0q+Eq7odXLq0rrq7mqxz4wELAJtj7Ry/b1zN/IDHkQBg1DI0t hjxfVgX3XddeztAMPXxi9CahMCIdi6lPfO6h8twnOBaWz5XyNiXMUIzaPgOHASM9Do5q Of+k62rkSWybAF0mKZmr96/RGwqL7llWiF9POLfEVtiJ7AfKfyGLD7tQfFseo4Hhqf6z Q2HLxuHW9u9bVj+0lQWaVCnPzvH/T4qFj6n1oU8tkERhmuPdGa+3Z6fkMUtw7luN972o l1OQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=/xO0vhrob/IxLFWsQOw0gVuxnzd8Y+W0Hl59pkQyhfs=; fh=jGpRxxGHkcGZyN2ZnaDwhUy8S6joixew3DGGT1L/CuQ=; b=nWF12FL5rjBjrHfZ4UDEaW0BYMrp9gdOrX+6cAG1GLYJUxJFmIEZkNPRYjU2dD7i4V V/zCjARqPmBcbMW7oYnJE6ZSYKBYYRQSpYdLoYONVCPx/IwKNn7TBCpCMdZWChkATL2C QOgRkYOFswnfEFJ71Htt1Ms70anAwlvdRBTRUsRgs44PqT8u+U6RVIIle0palH+UvLLC nSezTNlGJMjeNeNLtrBVLEYQmlsGm/LoaKJDQEvGMmq0rRsNwPeREMSQYYXiJrSzi6gd rBL6dMJpFZ5/I1cp12nR0aZhPJoFf9HcEVJBdzH5NkLXheamE05yy7Q/BwnuvS/ebQ6I 6ATg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q14-20020a170902bd8e00b001ab1279d418si8582222pls.474.2023.06.28.12.01.32; Wed, 28 Jun 2023 12:01:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231179AbjF1TAp (ORCPT + 99 others); Wed, 28 Jun 2023 15:00:45 -0400 Received: from bg4.exmail.qq.com ([43.154.54.12]:64558 "EHLO bg4.exmail.qq.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232277AbjF1S7E (ORCPT ); Wed, 28 Jun 2023 14:59:04 -0400 X-QQ-mid: bizesmtp78t1687978735t1k8oxv4 Received: from linux-lab-host.localdomain ( [116.30.129.193]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 29 Jun 2023 02:58:53 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: znfcQSa1hKbNtlJaExe6GfPAoc0Ow5+wEWHtPLG7/Q1ge+0ox0JyU9wMZjrJB FtypQUSuK8tr3GynT9yFI2sUEDe1ixy87NqzzYo8mCDDjD4dEQp9RNDNmknFPKNEDwCqTTl rBh23PghpE0BeEpgR9KmVOl+x6kRiFqrD1NrVUE2gl94i2AKJsaWbJp3ZeZGKvRlk+DQ4Ua uOO9ts/jzsDuTn2eozBWxv4Ec183BmS/Dt8SsvwS8U3L/XhRTcoe1D9KbI2yDgvp4zNzmoO wqXMiCqMx94azMgzMWL/tOLzm3ucmctRTOQ1QXkNIK3OZP5rMZuFMNFnotyiTvh7b8t7Bx6 uFwXiRjLkfGw04uw1vIX0ZKUEPWkOUAKqz01NmfaznPq3tpd5uMtTO+IyQZMw== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 10494488464373133128 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v1 06/11] tools/nolibc: i386: shrink _start with _start_c Date: Thu, 29 Jun 2023 02:58:43 +0800 Message-Id: <27783ab1bed69fd99319aa52e03e204ef1160d74.1687976753.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769974169668417149?= X-GMAIL-MSGID: =?utf-8?q?1769974169668417149?= Let's move most of the _start operations to _start_c(). Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-i386.h | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/tools/include/nolibc/arch-i386.h b/tools/include/nolibc/arch-i386.h index 418554435545..b56046f1d0c0 100644 --- a/tools/include/nolibc/arch-i386.h +++ b/tools/include/nolibc/arch-i386.h @@ -154,9 +154,6 @@ _eax; \ }) -char **environ __attribute__((weak)); -const unsigned long *_auxv __attribute__((weak)); - /* startup code */ /* * i386 System V ABI mandates: @@ -168,29 +165,14 @@ void __attribute__((weak,noreturn,optimize("omit-frame-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 before */ - "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 */ - "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 == 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 _start_c */ + "and $-16, %esp\n" /* last pushed argument must be 16-byte aligned */ + "push %eax\n" /* push arg1 on stack to support plain stack modes too */ + "call _start_c\n" /* transfer to c runtime */ + "hlt\n" /* ensure it does not return */ ); __builtin_unreachable(); } From patchwork Wed Jun 28 18:59:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 114019 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9145909vqr; Wed, 28 Jun 2023 12:06:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4wg38LnQMMpxZqoHj/grG/6u8tqlO/2IDMG4En8aeMAGhIOhs23P7p3MlzcXjlAgCu2/Cp X-Received: by 2002:a05:6a00:26da:b0:67f:ff0a:1bbb with SMTP id p26-20020a056a0026da00b0067fff0a1bbbmr3461806pfw.1.1687979180844; Wed, 28 Jun 2023 12:06:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687979180; cv=none; d=google.com; s=arc-20160816; b=mpMa5oHgnSmCJtOPdS9bC24FKoKo49m8qdHwDEuWp7O+6PHWuNCuTuHHwfWzOxtQTi 5gzHwA+HtBWYwrynrHFM5IgbawhMULw12MdlT0b+e+g8s3PiCyyaSnUuXtDqbWZ26kQ8 uDvrKBqIrM9vQYwmoxRU9DXoL3HXeANm7np3tbo7awohA9j1k5NLeRw/7TbXjWGPs/pU yVMOvSJOHqXxW2gEaDiHpZT1S+bXhxn78/alqdz2yVb7lP2cd7DIQUL2SCfAS6cbJpx5 upP/vzcFXUQxpv4RJqgDwFi6mCmA8XtW+/NrDHT4jrrVqSZWub7wj2TFxwvo4MNCm9yd MlsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=Iz0uENKU/nJkvyYZsNHJDgimzqELUd5u2ZRTmQIKCWw=; fh=jGpRxxGHkcGZyN2ZnaDwhUy8S6joixew3DGGT1L/CuQ=; b=eh1EbwLKOkZKJRcfBfv3q/FbN7w6qDci92gLjx1u+HGw10DSnbj4cw9O0OwZpKKopB IK5qEgsCLE9B7Qa0VcHeMamEFyH3DAvc2/dbmE9lCjHQ9oNcWwVuznFylYRx9wXWXZ+O adqT6WY9i4/pnjUD+ebU0FgBWOkhsxoPmH469pInS077+67JigBr5oQ0/ZKVvOXbxmM2 sAMfpvbVp76ici4fvLxsocjrVpc1DVVrcQjlboS0OsiSxa41k3l7fHeGC0Q3B1TLLwL6 XkwUSxSllEl+h4HBlEyBku78QLDR/fqM4yb5ySNs8wQI5QqugNkITuy0Fo5U0NkrKyDs mFnQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 10-20020a62190a000000b0066844d4ec59si8996360pfz.168.2023.06.28.12.06.04; Wed, 28 Jun 2023 12:06:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231303AbjF1TBU (ORCPT + 99 others); Wed, 28 Jun 2023 15:01:20 -0400 Received: from bg4.exmail.qq.com ([43.154.54.12]:35030 "EHLO bg4.exmail.qq.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232772AbjF1TAU (ORCPT ); Wed, 28 Jun 2023 15:00:20 -0400 X-QQ-mid: bizesmtp86t1687978810tf2ar9vw Received: from linux-lab-host.localdomain ( [116.30.129.193]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 29 Jun 2023 03:00:08 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: +ynUkgUhZJneCqf/WiFIlQeErW4hE9O+nEPddl2PRkjGlBZEniPrcbaTTc7s2 5f7+aA6vYP9PgLSC4T+j0tcUHwDVAnq8K7wx2MCiGSfUIbExALiKcxf1iKlDVqafqQCqd7u w6L2PnJbHsPLcw/lQuF2hvLgUlEij/5DAIfSAqE1oRd1Y5ZtWZoW+kxKtrEEg616wwLLjoF 3yRqaVk1PLD1I42O+doEPlLna5UF0Ob/6v7p7L7gjJVYrJVWrIr8SAIrcz/RsiRD27lBnl5 TElxw/lGgBlRGo6OFU0/aBHG2qDnPSoZHBD6UI8D2fq8Cje2g2Dm5BiBWqCmJr2l+N/eX6q xVeXxjtbPRXqoMegPcU9CcfyiG5e0xQGVdKth5kBBUlzsUSr6bbfGY2eD8fsg== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 10657381781421926358 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v1 07/11] tools/nolibc: x86_64: shrink _start with _start_c Date: Thu, 29 Jun 2023 02:59:59 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769974457734723616?= X-GMAIL-MSGID: =?utf-8?q?1769974457734723616?= Let's move most of the _start operations to _start_c(). Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-x86_64.h | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/tools/include/nolibc/arch-x86_64.h b/tools/include/nolibc/arch-x86_64.h index 4c0192815a59..116dcd8e1413 100644 --- a/tools/include/nolibc/arch-x86_64.h +++ b/tools/include/nolibc/arch-x86_64.h @@ -153,9 +153,6 @@ _ret; \ }) -char **environ __attribute__((weak)); -const unsigned long *_auxv __attribute__((weak)); - /* startup code */ /* * x86-64 System V ABI mandates: @@ -167,25 +164,13 @@ void __attribute__((weak,noreturn,optimize("omit-frame-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 before call */ - "call main\n" /* main() returns the status code, we'll exit with it. */ - "mov %eax, %edi\n" /* retrieve exit code (32 bit) */ - "mov $60, %eax\n" /* NR_exit == 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 _start_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(); } From patchwork Wed Jun 28 19:01:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 114020 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9147109vqr; Wed, 28 Jun 2023 12:08:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4/saYkFkZ0TG99Na2HngFOrZmLiiyPulxdaB2OQzNgbcOHkRYxlCud6vD1nTXgnnuCRsuX X-Received: by 2002:a05:6402:5202:b0:51d:ab6c:c2b4 with SMTP id s2-20020a056402520200b0051dab6cc2b4mr5399802edd.0.1687979294264; Wed, 28 Jun 2023 12:08:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687979294; cv=none; d=google.com; s=arc-20160816; b=UXG5lny8NyrSPW9PTcVW09h6zx7zZIg0+MAXpI83fNo194DZe/6DKkISLxLwKpQ+r6 TIqU1aBKTGPPHdLH0A2u5TeMkmM92pulwbm+xbrJj05KbZzWMOso6i9U/ieKS/TsBT1o BDjzzjgksHXfS1b/0Kyz3uGz+iaqtqXTMkzD/g9SV8bRGVkURfLs8Andt/nXwx+OsGy0 rc83AgIHC88txbvTIatyHp7cmXNs3I2p7iGb0C0vC2yLeLzNCPl0qGJP8NdewTDSTJUt 8KNhEFUBYlqAA4QybPFJ/RJ7h9zEnj0F8jVpgn05wriWplJULS0U37J2vCvJZtO0SEHn gKbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=jDrhHYH1yBiLlG1N128LOmkeeYbjosuLHgO6JlE5az8=; fh=jGpRxxGHkcGZyN2ZnaDwhUy8S6joixew3DGGT1L/CuQ=; b=jy0AXp32m0yT77jkz0Ck88/tVwQlhtorS256gqUMG6H11F02T9MaaAiLotJ2eestzO a1pKDLde3L+9HETSmWhyopiPJZSc8Evs50gvAWStlRVs2z8t6a14KewYbmvtFngR5Ynb Z4xpgfPr7vEnqWp22+rpAUm2tFpcvt/7zfqldtxk1fZ3hm4Zv85EfoKFvGVPHIiXAPfI SPKB3k4gvQnQlnZBNXa4M09xzwPoxJvavt0lnFh2Pn6mBxjP1yU1iUZFXxxuEERHEIEk AUoHAMmk/QT7YRKjOkz3PCBYCy7w24CA3CBv0NazXIw+9ZLJ3AX/4XO2otIyaE2p7XhM keew== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k16-20020aa7d8d0000000b0051bfa32f8dfsi5804931eds.30.2023.06.28.12.07.32; Wed, 28 Jun 2023 12:08:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232125AbjF1TCc (ORCPT + 99 others); Wed, 28 Jun 2023 15:02:32 -0400 Received: from bg4.exmail.qq.com ([43.154.54.12]:18931 "EHLO bg4.exmail.qq.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232308AbjF1TBe (ORCPT ); Wed, 28 Jun 2023 15:01:34 -0400 X-QQ-mid: bizesmtp89t1687978884tr421dbg Received: from linux-lab-host.localdomain ( [116.30.129.193]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 29 Jun 2023 03:01:22 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: ILHsT53NKPjPXjqsNEc9WBpKx63aH6ekhXt41at7lejx0jr9AWFyR18ehAl08 bHwqwkh7ymPLXY51CXtEBbfJ81cFMb2N0GSZHiCmbuOThu+5KQkwU0LEAvuiO8wiXR40au+ 4X2xjRXPLeh32yf38Zo9qZZfNIKaLF8phJjBU3yxPar+YY8Q/0663gzWqLw6pqlfMnXWEA7 gTgLLrDNjI9hGBUWpUIFGbyjQcfZ0/DBlfkyKdyU4lJdu2IgREZqdq3GexHqZ7UxX9ULcnk 8Nwu5hA13KXbNIxvJoE4xEcbre+ivYBN/aw3H4A6wPt2RirdsH9F4qQv0RfGlMvp6PDRNlU Iev1qO3zLEoA/9++tmAJvh8F3qMV8zXatpRjX/HatGjBbl0UxI= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 4007669029372385518 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v1 08/11] tools/nolibc: mips: shrink _start with _start_c Date: Thu, 29 Jun 2023 03:01:14 +0800 Message-Id: <0d650309e0cf79fee1a87995d3fcae083b96b150.1687976753.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769974576413890072?= X-GMAIL-MSGID: =?utf-8?q?1769974576413890072?= Let's move most of the _start operations to _start_c(). Also clean up the instructions in delay slots. Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-mips.h | 45 +++++++------------------------- 1 file changed, 9 insertions(+), 36 deletions(-) diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-mips.h index ecf912a1938f..d0f73f03bfa1 100644 --- a/tools/include/nolibc/arch-mips.h +++ b/tools/include/nolibc/arch-mips.h @@ -173,50 +173,23 @@ _arg4 ? -_num : _num; \ }) -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_stack_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 = sp + 4 */ - "sll $a2, $a0, 2\n" /* a2 = argc * 4 */ - "add $a2, $a2, $a1\n" /* envp = 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=*(t0); */ - "bne $a3, $0, 0b\n" /* } while (a3); */ - "addiu $t0, $t0, 4\n" /* delayed slot: t0+=4; */ - "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 with it. */ - "nop\n" /* delayed slot */ - "move $a0, $v0\n" /* retrieve 32-bit exit code from v0 */ - "li $v0, 4001\n" /* NR_exit == 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(); From patchwork Wed Jun 28 19:02:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 114021 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9147224vqr; Wed, 28 Jun 2023 12:08:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6lRCdEBGUq/cqu5Lt7KYp0D9GMoTnbMu1e3+a75Gt6fCFCd4M+vpBzzij6JQOfLEcIe7G1 X-Received: by 2002:a17:906:73cc:b0:98d:b10f:f3cd with SMTP id n12-20020a17090673cc00b0098db10ff3cdmr9220404ejl.7.1687979304878; Wed, 28 Jun 2023 12:08:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687979304; cv=none; d=google.com; s=arc-20160816; b=sqyDaAjyrXEd4pkmSvz4VVGUQBN8y4paUYhty6Q1b1OI1F1WVyuFb8l9vwGoLrNr4W hQMVYXKmrb50tLoVlEmTxUUA7x2Ng/yr32B+NXGoOOVxQowCe7YklWGuuWcaqRSL6dHN Ew7NvKnJy+X14ogVfXLS0wwoBIUkj5ErISUMvz3yna41I01DJ8wZDHhRE+EW4JSnXRTJ ltTKl6rSg4HB8xW+rkiiW3uf+KbQQ+PaKC8RfBTtWCiT9hT2SyB8aa8C2DC9gdQ1Uwl3 Mk0qCsnFhvq2VtJ1Eyj2woSwdFEbNguVXGfFuEpXgsANhjN3IMWmaPMpXwQbBeApuho+ lzkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=W7UNnnFVdIc/TKqQz36OlyYto66FhsQ0NfyOu0f+7CI=; fh=jGpRxxGHkcGZyN2ZnaDwhUy8S6joixew3DGGT1L/CuQ=; b=SqDIpS/ORMCFgsSvNfGBQdJNdSBH2x4J6/CKq0Ei5g4dl9GcxqHc/K2f6ZGnj9j2oV IxwL9Cs4OaHDn9kDtYbhXnLifv5N5NczPxDrgbCmgzRQiBVeUoliQ4UOMOK2EKusjCrT l8fiTfZbZHrCPpoUFvocWTeGWNm7WetBRzbtTNF+BYIeustSG2D0aKU5YW50WdJLyq1a 1FD7MC6rJgeZb9PBujhFRdMkyWKxnAT9smwafrUd2maUm1TXWOWbzILL7hjL5p5nZumY p7rrlp+R4rcz/03v53p2BT0uzEKZBJpzMTrNgbNRZ6NbUXGffTGaKczEIngXKgSR1lbc nXEA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lr26-20020a170906fb9a00b0099207b3bc48si2713077ejb.224.2023.06.28.12.07.56; Wed, 28 Jun 2023 12:08:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231637AbjF1TD6 (ORCPT + 99 others); Wed, 28 Jun 2023 15:03:58 -0400 Received: from bg4.exmail.qq.com ([43.155.65.254]:6174 "EHLO bg4.exmail.qq.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232397AbjF1TDR (ORCPT ); Wed, 28 Jun 2023 15:03:17 -0400 X-QQ-mid: bizesmtp85t1687978987tlvjj2iy Received: from linux-lab-host.localdomain ( [116.30.129.193]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 29 Jun 2023 03:03:06 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: 30t4+KEGo2kqMzIzajseusyLF7DGV3trcgVIZWDyeuDiPdn9oiQdoe9C6XJAD vRYykuFZb8aw+newmuj0ZpRZbq0olfDeXM0x7P3WWiHkTf+RxIC6e0va5PbFtdi31S7emfy BgWC8COyFGZmilAgD/mTUgkxKuUbRPK1ZBCcw4yTh1Um5vGJptGF1X/y/y+2bxUYydm8Hys 1rxzCBDgc9rUTPxmLdlt6TDy2B+4s0BQEA8E5kMilhmEU4iFzpsThdNQUe5tOB8Uogv5JB5 EOAMYtW4/Jp5C/kEwJY4Ll8PZad+UsXQW1qxIjYDjIZ3FxqazztHdJGRH78+TnxowJqO00q e7IYl+PYRC4K9WgitssfviOC/U+GsgbUhQD8FLxCWtM9SHztqs= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 2025772407350311878 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v1 09/11] tools/nolibc: loongarch: shrink _start with _start_c Date: Thu, 29 Jun 2023 03:02:29 +0800 Message-Id: <3304844b9d5c02416d08aaffd2f009941b38163c.1687976753.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769974587261044312?= X-GMAIL-MSGID: =?utf-8?q?1769974587261044312?= Let's move most of the _start operations to _start_c(). Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-loongarch.h | 42 +++------------------------ 1 file changed, 4 insertions(+), 38 deletions(-) diff --git a/tools/include/nolibc/arch-loongarch.h b/tools/include/nolibc/arch-loongarch.h index fbb4844f7993..f5cac2e81a13 100644 --- a/tools/include/nolibc/arch-loongarch.h +++ b/tools/include/nolibc/arch-loongarch.h @@ -145,26 +145,9 @@ _arg1; \ }) -char **environ __attribute__((weak)); -const unsigned long *_auxv __attribute__((weak)); - #if __loongarch_grlen == 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 == 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 @@ -173,28 +156,11 @@ void __attribute__((weak,noreturn,optimize("omit-frame-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) = sp + SZREG */ - LONG_SLL " $a2, $a0, "LONGLOG"\n" /* envp (a2) = 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 auxv (after NULL) */ - "0:\n" /* do { */ - REG_L " $a4, $a3, 0\n" /* a4 = *a3; */ - LONG_ADDI " $a3, $a3, "SZREG"\n" /* a3 += sizeof(void*); */ - "bne $a4, $zero, 0b\n" /* } while (a4); */ - "la.pcrel $a4, _auxv\n" /* a4 = &_auxv */ - LONG_S " $a3, $a4, 0\n" /* store a3 into _auxv */ - - "la.pcrel $a3, environ\n" /* a3 = &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 == 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(); } From patchwork Wed Jun 28 19:04:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 114023 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9148952vqr; Wed, 28 Jun 2023 12:11:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5ZUzngf2ZIPOVkbssrI9wwFYWd9a7Z2etMf722oFnUol7xo+HBcTFQMBxbRKG7qOmHMiT6 X-Received: by 2002:a17:906:2d2:b0:992:387:44d1 with SMTP id 18-20020a17090602d200b00992038744d1mr407682ejk.7.1687979478582; Wed, 28 Jun 2023 12:11:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687979478; cv=none; d=google.com; s=arc-20160816; b=pQDcKaAb4Zmtn5X72TGZfgmqUP8djUtZh+eirgUnvnsQfvqpRPuxsPyppkRIOQNCoP 5NnSqUd1OQYY1fnawZLuo7VXex5CHEBB4ENdKjFj18opY6e12FnBl5v7PzpmDig8nFS5 nxd9BSHWxrQMo5hYxYMKSnc5+a0w+Q5rJjuJEdSDuBDy08e3Nid5Yop/r4+d2w6UrzI4 1tGDJZSEmyQ8D9MOSf9VrBdMqUePn0OXxKm/GRdM8A8lB3cLz0LFbCKZ1/PYchd1NMOF ulKW1O68Q/pIluzHEfX6glZlMoR6M94Lqt8Rrps6dXRhahnZhpf+qB0VYfNrfY4EBLLU xdDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=xSxXyDHvz8/HvpTh/iaWOa1W2gwxylugFSeIzlfXJpQ=; fh=jGpRxxGHkcGZyN2ZnaDwhUy8S6joixew3DGGT1L/CuQ=; b=nt0s4MMOIGyMt93b9Kq4IRv2F2dIh/Ww0aLXUOt80+ZPHUfUu8p6tZiWUZ20w93CY7 PEbk+3/4EXg1Apq7aGBMK+nr3VNT59rlbLIJqeBOQsbNLohj8jVO3yvD/42Yg1MWm+JY 8ETwCU2MI6Mp01NOCOAqzQXdCAe6uzvRq9PKWREPBxiy5cjaQ6q0Q2mP6fLeVsoQS2iU F6uACaZR1WeoQtSKooZTUmLL9g+Wlm7+HlkXZMcWKlgBv+4FTLR9SlOp0o0LL+u6Y6uh HcK/q/P8baiB+EmZrIYSBrxSmtvR6RT/Y65GnhNTFuDjvpQTzBOU3OY2uhFjSIKZ+ti6 DpQA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lu13-20020a170906facd00b009929d998ab3si494915ejb.734.2023.06.28.12.10.48; Wed, 28 Jun 2023 12:11:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230038AbjF1TGI (ORCPT + 99 others); Wed, 28 Jun 2023 15:06:08 -0400 Received: from bg4.exmail.qq.com ([43.155.65.254]:51133 "EHLO bg4.exmail.qq.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231614AbjF1TFt (ORCPT ); Wed, 28 Jun 2023 15:05:49 -0400 X-QQ-mid: bizesmtp81t1687979140twy3oz5l Received: from linux-lab-host.localdomain ( [116.30.129.193]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 29 Jun 2023 03:05:38 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: QityeSR92A0ivM8Oe5i1P8PgBPy/0WKQrP/bau1yZUyBIMxZ5v5/nq5XSmhEo YaCWksBQ8b9i4Oiy0QKM2HQhJUQxhtH6I0PmpEJH68qNQ2/UUaq1iQcgOX+RFZ7zBKo7g2i 8fglSXNIJqe1lroojRhULNzSXIilkUv2ECoShgSwtnYMb8eO2nqScTXKGmhyfnDiF9jnlDx EoLxIAA7wqjl9DMajcD+s3Rmv+4Agv5M+PyV3e1dbGHOM6kMSvcfKligJTkTbcrf1Q4vzhI RHzPS9ot3goSP+6inAJpovN0PDWV+1j5DgDpGx20+T9RNlw8H3wOshH2sdaJnutu92MSj60 JpBup9/hmlDjscis/Y5N6ZqzwwRTzi7UX5BHcqVDB3wJsLZSWcsAmohQngzAg== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 17283120326487235982 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v1 10/11] tools/nolibc: riscv: shrink _start with _start_c Date: Thu, 29 Jun 2023 03:04:12 +0800 Message-Id: <4a6e7245c3aa07eb20fd6c6aa43bc663e480e0c5.1687976753.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769974769982793882?= X-GMAIL-MSGID: =?utf-8?q?1769974769982793882?= Let's move most of the _start operations to _start_c(). Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-riscv.h | 42 ++++--------------------------- 1 file changed, 5 insertions(+), 37 deletions(-) diff --git a/tools/include/nolibc/arch-riscv.h b/tools/include/nolibc/arch-riscv.h index 7f4abcc15206..ec0f9c597d0b 100644 --- a/tools/include/nolibc/arch-riscv.h +++ b/tools/include/nolibc/arch-riscv.h @@ -9,18 +9,6 @@ #include "compiler.h" -#if __riscv_xlen == 64 -#define PTRLOG "3" -#define SZREG "8" -#define REG_L "ld" -#define REG_S "sd" -#elif __riscv_xlen == 32 -#define PTRLOG "2" -#define SZREG "4" -#define REG_L "lw" -#define REG_S "sw" -#endif - /* Syscalls for RISCV : * - stack is 16-byte aligned * - syscall number is passed in a7 @@ -153,40 +141,20 @@ _arg1; \ }) -char **environ __attribute__((weak)); -const unsigned long *_auxv __attribute__((weak)); - /* startup code */ 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" + "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) = sp */ - "slli a2, a0, "PTRLOG"\n" /* envp (a2) = 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 = *a3; */ - "add a3, a3, "SZREG"\n" /* a3 += sizeof(void*); */ - "bne a4, zero, 0b\n" /* } while (a4); */ - "lui a4, %hi(_auxv)\n" /* a4 = &_auxv (high bits) */ - REG_S" a3, %lo(_auxv)(a4)\n" /* store a3 into _auxv */ - - "lui a3, %hi(environ)\n" /* a3 = &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 exit with it. */ - "li a7, 93\n" /* NR_exit == 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(); } From patchwork Wed Jun 28 19:06:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 114026 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9151046vqr; Wed, 28 Jun 2023 12:14:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7F27UhOUj5Bt6WI+Nt/+JoGCSXbgg0BIwqPGMPx9mOBV6irvWDiAmvZMeAKHLjq0RG8ht0 X-Received: by 2002:a17:906:779c:b0:988:815c:b9fa with SMTP id s28-20020a170906779c00b00988815cb9famr22558430ejm.3.1687979686059; Wed, 28 Jun 2023 12:14:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687979686; cv=none; d=google.com; s=arc-20160816; b=mmr7sEy2TqAhbok7rnZ/8Ied+G6wApS6Kz/UaDFgvf3LolxIB1HLO4Oqg/gV5M7o2W 0BhuzVp6OeU2d9chsGlTa4qevMz/U1ycxNxQ0SvZW70E3MudDFU+RBieBqAxUkacBH1Q x5E9Dzl0jKHcO1uXCopXJ0E5ruONhgtPRnY9kRTeZkqwh3pPzXhzJc0lW4yasN5Wwed6 juhLcaroXM3Oe6xlivzEfno24lTtyCJr/ViPyuIITrX2DmBARfLQZK9fLk9KpPPk+wTA zIQPf/YXGcpwlAlodooE6nQPR0yjWyQP2mGkfxrWoHiNZTDuWs6bJtEJz2y2k8A72CqM G7kA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=Hg2wKGhzi/c0SZRQEpJ+LXHSCcE7uRo/DKVX5ICM67g=; fh=jGpRxxGHkcGZyN2ZnaDwhUy8S6joixew3DGGT1L/CuQ=; b=q3Y65hKnXzMThZEj1ujM/63Sgl2G+DG4NW5rKbFyIhD6TnbBD5vaPw/2yILsBIw4mO 3drcR+2EyTUpQzAXS753hLGKKXOvPSmEboIyok4GeKdRSi86PcJ0K+4+7ZbmXqj/FU6U /6gQHontpunwtAX+hd6puuVbWhgb7v6ypF4j1GMnKI7F/zZFoHg+oIdnuO4PvURg+1V+ TzCvIhrzGCw5cW/7FtP1kHnkzCIJAZ6aLObWqkfA14/YS6HOL1OrlI/IT1/e8TzVLFjM ZkAx7LoqIQfNAkGp0QRCbOF/xFdU/kBdYJKz68dO0MvBAzYVEnRcMWRqapxB3GU0dywQ IdKw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lu13-20020a170906facd00b009929d998ab3si494915ejb.734.2023.06.28.12.14.16; Wed, 28 Jun 2023 12:14:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232194AbjF1TH3 (ORCPT + 99 others); Wed, 28 Jun 2023 15:07:29 -0400 Received: from bg4.exmail.qq.com ([43.154.54.12]:53345 "EHLO bg4.exmail.qq.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232160AbjF1THG (ORCPT ); Wed, 28 Jun 2023 15:07:06 -0400 X-QQ-mid: bizesmtp79t1687979217ti593xid Received: from linux-lab-host.localdomain ( [116.30.129.193]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 29 Jun 2023 03:06:55 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: D2GZf6M6C/jblY5+ez24uRSJrc6onlFKbVGlqPu9gz4C5VaEsHfPYV/+NbYNT M1xzvZvpUGVdU4m30V11Y032mXFLtuUBz/mtlNUDT78V8fQ/lc5cTGseyv0F/f0q/eI4FDb B2FbUnR/M5UMRVoi8g9xzAxpolnLJoudK9vMmMuJQ7xcbx68I+AHVvjOFo7ArkDBmY72K17 WpFiuGChYRn7DpN7ps7SrQCzwKzxAB0mOSMBUknzBEI0mP+u/OoB2NsfF4nMJXSIwPhcSgK uX/3Z74F0cX7AiF4lVQeTGYbg+K8doDPqbNQ/9SiL4iEP7soaPyeIgLaT2FvFSs8jnE9qSo Xd1YNJ9b6NQ4Od4okJQhNXhT4z0+qHgCdh0Nj/WbL1NR+KM2wI= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 18249731880678126887 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v1 11/11] tools/nolibc: s390: shrink _start with _start_c Date: Thu, 29 Jun 2023 03:06:44 +0800 Message-Id: <2a63942b938ce0f016f3411f7c0d4b0c0d512e74.1687976753.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769974987278060684?= X-GMAIL-MSGID: =?utf-8?q?1769974987278060684?= Let's move most of the _start operations to _start_c(). Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-s390.h | 35 ++++---------------------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/tools/include/nolibc/arch-s390.h b/tools/include/nolibc/arch-s390.h index 5139e0e37e56..a28f94aa28ca 100644 --- a/tools/include/nolibc/arch-s390.h +++ b/tools/include/nolibc/arch-s390.h @@ -137,41 +137,14 @@ _arg1; \ }) -char **environ __attribute__((weak)); -const unsigned long *_auxv __attribute__((weak)); - /* startup code */ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_stack_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" /* initialize stack protector */ + "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(); }