From nobody Mon Feb 9 05:38:38 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 AC35BEB64DD for ; Sat, 8 Jul 2023 15:27:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230183AbjGHP06 (ORCPT ); Sat, 8 Jul 2023 11:26:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229783AbjGHP05 (ORCPT ); Sat, 8 Jul 2023 11:26:57 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 046D990; Sat, 8 Jul 2023 08:26:54 -0700 (PDT) X-QQ-mid: bizesmtp83t1688830004tyw675ms Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 23:26:42 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: +ynUkgUhZJmVRUXV+L2xeVyf6+vqmM7j9a2ASDPK312opbgF4bOwDsoGStEyF OXQxMtEdNxFS7Ym41TWHTCmiKwVLZyWlxLECcbgdfVdGQPGC7pqNGVKtK/L+64tubQblPP7 oczPdTp8NDntGYKd/lgVkGmpshZVJ4DKHKsE9NofnaAC48iM6oo1wfJd6mq88fmii3W1kbs dRxpVsWe5Hoqs/YKlCXHrfRmP6kqBWSpGi6UVkiJ7tiYEt15r9BgLZW0KkHOFpmDp5irziD KRKgA4lBunL75GYf4Fr1fv4MirIxsqdRnfbUdcemPNoLl4ctqsZ7ujufvavhYLxXXY7F2sD QWAIFaAj76zc+ISdWwRE/bNlf6udwxpzKsPqHbJ0fZfQMYF5S7cnMq+3op7U8F0grLoRRVX X-QQ-GoodBg: 0 X-BIZMAIL-ID: 16386265970965724467 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 v2 01/12] tools/nolibc: rename arch-.h to /arch.h Date: Sat, 8 Jul 2023 23:26:42 +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" Currently, the architecture specific arch.h has two parts, one is the syscall declarations for sys.h, another is the _start code definition for startup support. The coming crt.h will provide the startup support with a new common _start_c(), it will replace most of the assembly _start code and shrink the original _start code to be minimal, as a result, _start_c() and the left minimal _start code will work together to provide the startup support, therefore, the left _start code will be only required by crt.h. So, the syscall declarations part of arch.h can be split to sys_arch.h and the _start code part of arch.h can be split to crt_arch.h and then, they should only be included in sys.h and crt.h respectively. At the same time, the architecture specific arch-.h should be split to /crt.h and /sys.h. As a preparation, this creates the architecture specific directory and moves tools/include/nolibc/arch-.h to tools/include/nolibc//arch.h. Signed-off-by: Zhangjin Wu --- tools/include/nolibc/Makefile | 10 +++++----- .../nolibc/{arch-aarch64.h =3D> aarch64/arch.h} | 6 +++--- tools/include/nolibc/arch.h | 16 ++++++++-------- tools/include/nolibc/{arch-arm.h =3D> arm/arch.h} | 6 +++--- .../include/nolibc/{arch-i386.h =3D> i386/arch.h} | 6 +++--- .../{arch-loongarch.h =3D> loongarch/arch.h} | 6 +++--- .../include/nolibc/{arch-mips.h =3D> mips/arch.h} | 6 +++--- .../nolibc/{arch-riscv.h =3D> riscv/arch.h} | 6 +++--- .../include/nolibc/{arch-s390.h =3D> s390/arch.h} | 6 +++--- .../nolibc/{arch-x86_64.h =3D> x86_64/arch.h} | 6 +++--- 10 files changed, 37 insertions(+), 37 deletions(-) rename tools/include/nolibc/{arch-aarch64.h =3D> aarch64/arch.h} (99%) rename tools/include/nolibc/{arch-arm.h =3D> arm/arch.h} (99%) rename tools/include/nolibc/{arch-i386.h =3D> i386/arch.h} (99%) rename tools/include/nolibc/{arch-loongarch.h =3D> loongarch/arch.h} (99%) rename tools/include/nolibc/{arch-mips.h =3D> mips/arch.h} (99%) rename tools/include/nolibc/{arch-riscv.h =3D> riscv/arch.h} (99%) rename tools/include/nolibc/{arch-s390.h =3D> s390/arch.h} (98%) rename tools/include/nolibc/{arch-x86_64.h =3D> x86_64/arch.h} (99%) diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 64d67b080744..ce21ace8210e 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -24,7 +24,7 @@ Q=3D@ endif =20 nolibc_arch :=3D $(patsubst arm64,aarch64,$(ARCH)) -arch_file :=3D arch-$(nolibc_arch).h +arch_file :=3D $(nolibc_arch)/arch.h all_files :=3D \ compiler.h \ ctype.h \ @@ -70,11 +70,11 @@ headers: $(Q)cp $(all_files) $(OUTPUT)sysroot/include/ $(Q)if [ "$(ARCH)" =3D "x86" ]; then \ sed -e \ - 's,^#ifndef _NOLIBC_ARCH_X86_64_H,#if !defined(_NOLIBC_ARCH_X86_64_H) = \&\& defined(__x86_64__),' \ - arch-x86_64.h; \ + 's,^#ifndef _NOLIBC_X86_64_ARCH_H,#if !defined(_NOLIBC_X86_64_ARCH_H) = \&\& defined(__x86_64__),' \ + x86_64/arch.h; \ sed -e \ - 's,^#ifndef _NOLIBC_ARCH_I386_H,#if !defined(_NOLIBC_ARCH_I386_H) \&\&= !defined(__x86_64__),' \ - arch-i386.h; \ + 's,^#ifndef _NOLIBC_I386_ARCH_H,#if !defined(_NOLIBC_I386_ARCH_H) \&\&= !defined(__x86_64__),' \ + i386/arch.h; \ elif [ -e "$(arch_file)" ]; then \ cat $(arch_file); \ else \ diff --git a/tools/include/nolibc/arch-aarch64.h b/tools/include/nolibc/aar= ch64/arch.h similarity index 99% rename from tools/include/nolibc/arch-aarch64.h rename to tools/include/nolibc/aarch64/arch.h index 6227b77a4a09..7d38da13c72b 100644 --- a/tools/include/nolibc/arch-aarch64.h +++ b/tools/include/nolibc/aarch64/arch.h @@ -4,8 +4,8 @@ * Copyright (C) 2017-2022 Willy Tarreau */ =20 -#ifndef _NOLIBC_ARCH_AARCH64_H -#define _NOLIBC_ARCH_AARCH64_H +#ifndef _NOLIBC_AARCH64_ARCH_H +#define _NOLIBC_AARCH64_ARCH_H =20 #include "compiler.h" =20 @@ -201,4 +201,4 @@ void __attribute__((weak,noreturn,optimize("omit-frame-= pointer"))) __no_stack_pr ); __builtin_unreachable(); } -#endif /* _NOLIBC_ARCH_AARCH64_H */ +#endif /* _NOLIBC_AARCH64_ARCH_H */ diff --git a/tools/include/nolibc/arch.h b/tools/include/nolibc/arch.h index 82b43935650f..f98616f5b219 100644 --- a/tools/include/nolibc/arch.h +++ b/tools/include/nolibc/arch.h @@ -16,21 +16,21 @@ #define _NOLIBC_ARCH_H =20 #if defined(__x86_64__) -#include "arch-x86_64.h" +#include "x86_64/arch.h" #elif defined(__i386__) || defined(__i486__) || defined(__i586__) || defin= ed(__i686__) -#include "arch-i386.h" +#include "i386/arch.h" #elif defined(__ARM_EABI__) -#include "arch-arm.h" +#include "arm/arch.h" #elif defined(__aarch64__) -#include "arch-aarch64.h" +#include "aarch64/arch.h" #elif defined(__mips__) && defined(_ABIO32) -#include "arch-mips.h" +#include "mips/arch.h" #elif defined(__riscv) -#include "arch-riscv.h" +#include "riscv/arch.h" #elif defined(__s390x__) -#include "arch-s390.h" +#include "s390/arch.h" #elif defined(__loongarch__) -#include "arch-loongarch.h" +#include "loongarch/arch.h" #endif =20 #endif /* _NOLIBC_ARCH_H */ diff --git a/tools/include/nolibc/arch-arm.h b/tools/include/nolibc/arm/arc= h.h similarity index 99% rename from tools/include/nolibc/arch-arm.h rename to tools/include/nolibc/arm/arch.h index 4d4887a5f04b..473d2c000740 100644 --- a/tools/include/nolibc/arch-arm.h +++ b/tools/include/nolibc/arm/arch.h @@ -4,8 +4,8 @@ * Copyright (C) 2017-2022 Willy Tarreau */ =20 -#ifndef _NOLIBC_ARCH_ARM_H -#define _NOLIBC_ARCH_ARM_H +#ifndef _NOLIBC_ARM_ARCH_H +#define _NOLIBC_ARM_ARCH_H =20 #include "compiler.h" =20 @@ -267,4 +267,4 @@ void __attribute__((weak,noreturn,optimize("omit-frame-= pointer"))) __no_stack_pr __builtin_unreachable(); } =20 -#endif /* _NOLIBC_ARCH_ARM_H */ +#endif /* _NOLIBC_ARM_ARCH_H */ diff --git a/tools/include/nolibc/arch-i386.h b/tools/include/nolibc/i386/a= rch.h similarity index 99% rename from tools/include/nolibc/arch-i386.h rename to tools/include/nolibc/i386/arch.h index 4c6b7c04e2e7..66052742763e 100644 --- a/tools/include/nolibc/arch-i386.h +++ b/tools/include/nolibc/i386/arch.h @@ -4,8 +4,8 @@ * Copyright (C) 2017-2022 Willy Tarreau */ =20 -#ifndef _NOLIBC_ARCH_I386_H -#define _NOLIBC_ARCH_I386_H +#ifndef _NOLIBC_I386_ARCH_H +#define _NOLIBC_I386_ARCH_H =20 #include "compiler.h" =20 @@ -221,4 +221,4 @@ void __attribute__((weak,noreturn,optimize("omit-frame-= pointer"))) __no_stack_pr __builtin_unreachable(); } =20 -#endif /* _NOLIBC_ARCH_I386_H */ +#endif /* _NOLIBC_I386_ARCH_H */ diff --git a/tools/include/nolibc/arch-loongarch.h b/tools/include/nolibc/l= oongarch/arch.h similarity index 99% rename from tools/include/nolibc/arch-loongarch.h rename to tools/include/nolibc/loongarch/arch.h index 8aa7724fe38e..63fee1e8f4d9 100644 --- a/tools/include/nolibc/arch-loongarch.h +++ b/tools/include/nolibc/loongarch/arch.h @@ -4,8 +4,8 @@ * Copyright (C) 2023 Loongson Technology Corporation Limited */ =20 -#ifndef _NOLIBC_ARCH_LOONGARCH_H -#define _NOLIBC_ARCH_LOONGARCH_H +#ifndef _NOLIBC_LOONGARCH_ARCH_H +#define _NOLIBC_LOONGARCH_ARCH_H =20 #include "compiler.h" =20 @@ -197,4 +197,4 @@ void __attribute__((weak,noreturn,optimize("omit-frame-= pointer"))) __no_stack_pr __builtin_unreachable(); } =20 -#endif /* _NOLIBC_ARCH_LOONGARCH_H */ +#endif /* _NOLIBC_LOONGARCH_ARCH_H */ diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/mips/a= rch.h similarity index 99% rename from tools/include/nolibc/arch-mips.h rename to tools/include/nolibc/mips/arch.h index a2bfdf57b957..1581b721b714 100644 --- a/tools/include/nolibc/arch-mips.h +++ b/tools/include/nolibc/mips/arch.h @@ -4,8 +4,8 @@ * Copyright (C) 2017-2022 Willy Tarreau */ =20 -#ifndef _NOLIBC_ARCH_MIPS_H -#define _NOLIBC_ARCH_MIPS_H +#ifndef _NOLIBC_MIPS_ARCH_H +#define _NOLIBC_MIPS_ARCH_H =20 #include "compiler.h" =20 @@ -250,4 +250,4 @@ void __attribute__((weak,noreturn,optimize("omit-frame-= pointer"))) __no_stack_pr __builtin_unreachable(); } =20 -#endif /* _NOLIBC_ARCH_MIPS_H */ +#endif /* _NOLIBC_MIPS_ARCH_H */ diff --git a/tools/include/nolibc/arch-riscv.h b/tools/include/nolibc/riscv= /arch.h similarity index 99% rename from tools/include/nolibc/arch-riscv.h rename to tools/include/nolibc/riscv/arch.h index cd958b2f4b1b..de68759f5959 100644 --- a/tools/include/nolibc/arch-riscv.h +++ b/tools/include/nolibc/riscv/arch.h @@ -4,8 +4,8 @@ * Copyright (C) 2017-2022 Willy Tarreau */ =20 -#ifndef _NOLIBC_ARCH_RISCV_H -#define _NOLIBC_ARCH_RISCV_H +#ifndef _NOLIBC_RISCV_ARCH_H +#define _NOLIBC_RISCV_ARCH_H =20 #include "compiler.h" =20 @@ -214,4 +214,4 @@ void __attribute__((weak,noreturn,optimize("omit-frame-= pointer"))) __no_stack_pr __builtin_unreachable(); } =20 -#endif /* _NOLIBC_ARCH_RISCV_H */ +#endif /* _NOLIBC_RISCV_ARCH_H */ diff --git a/tools/include/nolibc/arch-s390.h b/tools/include/nolibc/s390/a= rch.h similarity index 98% rename from tools/include/nolibc/arch-s390.h rename to tools/include/nolibc/s390/arch.h index a644ecd361c0..a7b512e81234 100644 --- a/tools/include/nolibc/arch-s390.h +++ b/tools/include/nolibc/s390/arch.h @@ -3,8 +3,8 @@ * s390 specific definitions for NOLIBC */ =20 -#ifndef _NOLIBC_ARCH_S390_H -#define _NOLIBC_ARCH_S390_H +#ifndef _NOLIBC_S390_ARCH_H +#define _NOLIBC_S390_ARCH_H #include #include =20 @@ -234,4 +234,4 @@ pid_t sys_fork(void) } #define sys_fork sys_fork =20 -#endif /* _NOLIBC_ARCH_S390_H */ +#endif /* _NOLIBC_S390_ARCH_H */ diff --git a/tools/include/nolibc/arch-x86_64.h b/tools/include/nolibc/x86_= 64/arch.h similarity index 99% rename from tools/include/nolibc/arch-x86_64.h rename to tools/include/nolibc/x86_64/arch.h index e69113742a99..602791c3461a 100644 --- a/tools/include/nolibc/arch-x86_64.h +++ b/tools/include/nolibc/x86_64/arch.h @@ -4,8 +4,8 @@ * Copyright (C) 2017-2022 Willy Tarreau */ =20 -#ifndef _NOLIBC_ARCH_X86_64_H -#define _NOLIBC_ARCH_X86_64_H +#ifndef _NOLIBC_X86_64_ARCH_H +#define _NOLIBC_X86_64_ARCH_H =20 #include "compiler.h" =20 @@ -217,4 +217,4 @@ void __attribute__((weak,noreturn,optimize("omit-frame-= pointer"))) __no_stack_pr __builtin_unreachable(); } =20 -#endif /* _NOLIBC_ARCH_X86_64_H */ +#endif /* _NOLIBC_X86_64_ARCH_H */ --=20 2.25.1 From nobody Mon Feb 9 05:38:38 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 CBC2DEB64DC for ; Sat, 8 Jul 2023 15:28:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230346AbjGHP2F (ORCPT ); Sat, 8 Jul 2023 11:28:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229726AbjGHP2E (ORCPT ); Sat, 8 Jul 2023 11:28:04 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5081D90; Sat, 8 Jul 2023 08:27:59 -0700 (PDT) X-QQ-mid: bizesmtp64t1688830069t3f4s4z0 Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 23:27:48 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: 5q30pvLz2ieFIXb+tjFEowNd/SSn3BVGFKmYiPWKnKwS2aby9tbkXrD72pwFA 5eR44ukBDRfi9cdCVi7+5U9NS5grhGYAjwbRnzjX915TSOiXFEkZgn6MM6ra8zDZc/tBa5g 4u5vN6dg02hvJt7BTMaVFiamd6U0KE3o1PMs60EVFlakbKFHsZa9JlP32zecHAcDPTuLa9q zP2P2ARCpOIj1lJr2bdv4xUsW0ZIWqY7h67pXkd8yitPtKTMakcpFH5S/4Kq02BTupECizw bnqatWkWSAhjEyaNa5as/715prKhMsR4o1q9VQuBuFysL97tiDji4NRyVB6UVf1E3GBNC97 i7rzCnbyBsybOe2gV2tKIKvrwShehBnW9NZ3sdNH+4HViwyB3m34+t8OjN51V3uRi3u3X4c X-QQ-GoodBg: 0 X-BIZMAIL-ID: 7756912049918278529 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 v2 02/12] tools/nolibc: split arch.h to crt.h and sys.h Date: Sat, 8 Jul 2023 23:27:48 +0800 Message-Id: <50fb6551e3845ad04bdf4563b71d3e7ecaf70641.1688828139.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" For each architecture, arch.h has the syscall declarations and the _start code definition, let's split it to sys.h and crt.h respectively: - local : /arch.h -> /{sys.h, crt.h} - global: arch.h -> sys_arch.h, crt_arch.h And then, we can include the architecture specific file to the common file like this: - crt.h: #include "crt_arch.h" - sys.h: #include "sys_arch.h" At last, the "arch.h" header can be removed from all of the other headers, instead, we only need to include "sys.h" and "crt.h" on demand. BTW, the following errors reported by scripts/checkpatch.pl are fixed: ERROR: space required after that ',' (ctx:VxV) #1327: FILE: tools/include/nolibc/x86_64/crt.h:17: +void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __n= o_stack_protector _start(void) Signed-off-by: Zhangjin Wu --- tools/include/nolibc/Makefile | 36 +++++++---- tools/include/nolibc/aarch64/crt.h | 37 +++++++++++ .../include/nolibc/aarch64/{arch.h =3D> sys.h} | 40 ++---------- tools/include/nolibc/arch.h | 36 ----------- tools/include/nolibc/arm/crt.h | 53 +++++++++++++++ tools/include/nolibc/arm/{arch.h =3D> sys.h} | 59 ++--------------- tools/include/nolibc/crt.h | 16 +++++ tools/include/nolibc/crt_arch.h | 32 ++++++++++ tools/include/nolibc/i386/crt.h | 48 ++++++++++++++ tools/include/nolibc/i386/{arch.h =3D> sys.h} | 51 ++------------- tools/include/nolibc/loongarch/crt.h | 61 ++++++++++++++++++ .../nolibc/loongarch/{arch.h =3D> sys.h} | 64 ++----------------- tools/include/nolibc/mips/crt.h | 56 ++++++++++++++++ tools/include/nolibc/mips/{arch.h =3D> sys.h} | 59 ++--------------- tools/include/nolibc/nolibc.h | 2 +- tools/include/nolibc/riscv/crt.h | 57 +++++++++++++++++ tools/include/nolibc/riscv/{arch.h =3D> sys.h} | 60 ++--------------- tools/include/nolibc/s390/crt.h | 45 +++++++++++++ tools/include/nolibc/s390/{arch.h =3D> sys.h} | 49 ++------------ tools/include/nolibc/signal.h | 1 - tools/include/nolibc/stdio.h | 1 - tools/include/nolibc/stdlib.h | 2 +- tools/include/nolibc/sys.h | 2 +- tools/include/nolibc/sys_arch.h | 32 ++++++++++ tools/include/nolibc/time.h | 1 - tools/include/nolibc/unistd.h | 1 - tools/include/nolibc/x86_64/crt.h | 44 +++++++++++++ tools/include/nolibc/x86_64/{arch.h =3D> sys.h} | 47 ++------------ 28 files changed, 539 insertions(+), 453 deletions(-) create mode 100644 tools/include/nolibc/aarch64/crt.h rename tools/include/nolibc/aarch64/{arch.h =3D> sys.h} (82%) delete mode 100644 tools/include/nolibc/arch.h create mode 100644 tools/include/nolibc/arm/crt.h rename tools/include/nolibc/arm/{arch.h =3D> sys.h} (81%) create mode 100644 tools/include/nolibc/crt.h create mode 100644 tools/include/nolibc/crt_arch.h create mode 100644 tools/include/nolibc/i386/crt.h rename tools/include/nolibc/i386/{arch.h =3D> sys.h} (79%) create mode 100644 tools/include/nolibc/loongarch/crt.h rename tools/include/nolibc/loongarch/{arch.h =3D> sys.h} (73%) create mode 100644 tools/include/nolibc/mips/crt.h rename tools/include/nolibc/mips/{arch.h =3D> sys.h} (79%) create mode 100644 tools/include/nolibc/riscv/crt.h rename tools/include/nolibc/riscv/{arch.h =3D> sys.h} (78%) create mode 100644 tools/include/nolibc/s390/crt.h rename tools/include/nolibc/s390/{arch.h =3D> sys.h} (78%) create mode 100644 tools/include/nolibc/sys_arch.h create mode 100644 tools/include/nolibc/x86_64/crt.h rename tools/include/nolibc/x86_64/{arch.h =3D> sys.h} (81%) diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index ce21ace8210e..e23c816598dc 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -24,9 +24,13 @@ Q=3D@ endif =20 nolibc_arch :=3D $(patsubst arm64,aarch64,$(ARCH)) -arch_file :=3D $(nolibc_arch)/arch.h +arch_files :=3D \ + $(nolibc_arch)/crt.h \ + $(nolibc_arch)/sys.h + all_files :=3D \ compiler.h \ + crt.h \ ctype.h \ errno.h \ nolibc.h \ @@ -68,19 +72,23 @@ headers: $(Q)mkdir -p $(OUTPUT)sysroot $(Q)mkdir -p $(OUTPUT)sysroot/include $(Q)cp $(all_files) $(OUTPUT)sysroot/include/ - $(Q)if [ "$(ARCH)" =3D "x86" ]; then \ - sed -e \ - 's,^#ifndef _NOLIBC_X86_64_ARCH_H,#if !defined(_NOLIBC_X86_64_ARCH_H) = \&\& defined(__x86_64__),' \ - x86_64/arch.h; \ - sed -e \ - 's,^#ifndef _NOLIBC_I386_ARCH_H,#if !defined(_NOLIBC_I386_ARCH_H) \&\&= !defined(__x86_64__),' \ - i386/arch.h; \ - elif [ -e "$(arch_file)" ]; then \ - cat $(arch_file); \ - else \ - echo "Fatal: architecture $(ARCH) not yet supported by nolibc." >&2; \ - exit 1; \ - fi > $(OUTPUT)sysroot/include/arch.h + $(Q)for arch_file in $(arch_files); do \ + base_file=3D$$(basename $$arch_file); \ + arch_header=3D$$(echo $$base_file | sed -e 's/\.h$$/_arch.h/g'); \ + if [ "$(ARCH)" =3D "x86" ]; then \ + sed -e \ + 's,^#ifndef _NOLIBC_X86_64_\([^_]*\)_H,#if !defined(_NOLIBC_X86_64_\1= _H) \&\& defined(__x86_64__),' \ + x86_64/$$base_file; \ + sed -e \ + 's,^#ifndef _NOLIBC_I386_\([^_]*\)_H,#if !defined(_NOLIBC_I386_\1_H) = \&\& !defined(__x86_64__),' \ + i386/$$base_file; \ + elif [ -e "$$arch_file" ]; then \ + cat $$arch_file; \ + else \ + echo "Fatal: architecture $(ARCH) not yet supported by nolibc." >&2; \ + exit 1; \ + fi > $(OUTPUT)sysroot/include/$$arch_header; \ + done =20 headers_standalone: headers $(Q)$(MAKE) -C $(srctree) headers diff --git a/tools/include/nolibc/aarch64/crt.h b/tools/include/nolibc/aarc= h64/crt.h new file mode 100644 index 000000000000..6c81d81cf31f --- /dev/null +++ b/tools/include/nolibc/aarch64/crt.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * AARCH64 specific startup code for NOLIBC + * Copyright (C) 2017-2022 Willy Tarreau + */ + +#ifndef _NOLIBC_AARCH64_CRT_H +#define _NOLIBC_AARCH64_CRT_H + +/* 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 = */ +#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" + ); + __builtin_unreachable(); +} +#endif /* _NOLIBC_AARCH64_CRT_H */ diff --git a/tools/include/nolibc/aarch64/arch.h b/tools/include/nolibc/aar= ch64/sys.h similarity index 82% rename from tools/include/nolibc/aarch64/arch.h rename to tools/include/nolibc/aarch64/sys.h index 7d38da13c72b..b79d6a35ec37 100644 --- a/tools/include/nolibc/aarch64/arch.h +++ b/tools/include/nolibc/aarch64/sys.h @@ -1,13 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1 OR MIT */ /* - * AARCH64 specific definitions for NOLIBC + * AARCH64 specific syscall declarations for NOLIBC * Copyright (C) 2017-2022 Willy Tarreau */ =20 -#ifndef _NOLIBC_AARCH64_ARCH_H -#define _NOLIBC_AARCH64_ARCH_H - -#include "compiler.h" +#ifndef _NOLIBC_AARCH64_SYS_H +#define _NOLIBC_AARCH64_SYS_H =20 /* The struct returned by the newfstatat() syscall. Differs slightly from = the * x86_64's stat one by field ordering, so be careful. @@ -171,34 +169,4 @@ struct sys_stat_struct { _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 = */ -#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" - ); - __builtin_unreachable(); -} -#endif /* _NOLIBC_AARCH64_ARCH_H */ +#endif /* _NOLIBC_AARCH64_SYS_H */ diff --git a/tools/include/nolibc/arch.h b/tools/include/nolibc/arch.h deleted file mode 100644 index f98616f5b219..000000000000 --- a/tools/include/nolibc/arch.h +++ /dev/null @@ -1,36 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ -/* - * Copyright (C) 2017-2022 Willy Tarreau - */ - -/* Below comes the architecture-specific code. For each architecture, we h= ave - * the syscall declarations and the _start code definition. This is the on= ly - * global part. On all architectures the kernel puts everything in the sta= ck - * before jumping to _start just above us, without any return address (_st= art - * is not a function but an entry point). So at the stack pointer we find = argc. - * Then argv[] begins, and ends at the first NULL. Then we have envp which - * starts and ends with a NULL as well. So envp=3Dargv+argc+1. - */ - -#ifndef _NOLIBC_ARCH_H -#define _NOLIBC_ARCH_H - -#if defined(__x86_64__) -#include "x86_64/arch.h" -#elif defined(__i386__) || defined(__i486__) || defined(__i586__) || defin= ed(__i686__) -#include "i386/arch.h" -#elif defined(__ARM_EABI__) -#include "arm/arch.h" -#elif defined(__aarch64__) -#include "aarch64/arch.h" -#elif defined(__mips__) && defined(_ABIO32) -#include "mips/arch.h" -#elif defined(__riscv) -#include "riscv/arch.h" -#elif defined(__s390x__) -#include "s390/arch.h" -#elif defined(__loongarch__) -#include "loongarch/arch.h" -#endif - -#endif /* _NOLIBC_ARCH_H */ diff --git a/tools/include/nolibc/arm/crt.h b/tools/include/nolibc/arm/crt.h new file mode 100644 index 000000000000..7b3b9e21e5c4 --- /dev/null +++ b/tools/include/nolibc/arm/crt.h @@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * ARM specific startup code for NOLIBC + * Copyright (C) 2017-2022 Willy Tarreau + */ + +#ifndef _NOLIBC_ARM_CRT_H +#define _NOLIBC_ARM_CRT_H + +/* 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 = */ +#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" + ); + __builtin_unreachable(); +} + +#endif /* _NOLIBC_ARM_CRT_H */ diff --git a/tools/include/nolibc/arm/arch.h b/tools/include/nolibc/arm/sys= .h similarity index 81% rename from tools/include/nolibc/arm/arch.h rename to tools/include/nolibc/arm/sys.h index 473d2c000740..79173f860948 100644 --- a/tools/include/nolibc/arm/arch.h +++ b/tools/include/nolibc/arm/sys.h @@ -1,13 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1 OR MIT */ /* - * ARM specific definitions for NOLIBC + * ARM specific syscall declarations for NOLIBC * Copyright (C) 2017-2022 Willy Tarreau */ =20 -#ifndef _NOLIBC_ARM_ARCH_H -#define _NOLIBC_ARM_ARCH_H - -#include "compiler.h" +#ifndef _NOLIBC_ARM_SYS_H +#define _NOLIBC_ARM_SYS_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 @@ -69,7 +67,7 @@ struct sys_stat_struct { * * Also, ARM supports the old_select syscall if newselect is not available */ -#define __ARCH_WANT_SYS_OLD_SELECT +#define __SYS_WANT_SYS_OLD_SELECT =20 #if (defined(__THUMBEB__) || defined(__THUMBEL__)) && \ !defined(NOLIBC_OMIT_FRAME_POINTER) @@ -220,51 +218,4 @@ struct sys_stat_struct { _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 = */ -#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" - ); - __builtin_unreachable(); -} - -#endif /* _NOLIBC_ARM_ARCH_H */ +#endif /* _NOLIBC_ARM_SYS_H */ diff --git a/tools/include/nolibc/crt.h b/tools/include/nolibc/crt.h new file mode 100644 index 000000000000..221b7c5346ca --- /dev/null +++ b/tools/include/nolibc/crt.h @@ -0,0 +1,16 @@ +/* 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 + +#include "compiler.h" +#include "crt_arch.h" + +char **environ __attribute__((weak)); +const unsigned long *_auxv __attribute__((weak)); + +#endif /* _NOLIBC_CRT_H */ diff --git a/tools/include/nolibc/crt_arch.h b/tools/include/nolibc/crt_arc= h.h new file mode 100644 index 000000000000..741402557bd0 --- /dev/null +++ b/tools/include/nolibc/crt_arch.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * Copyright (C) 2017-2022 Willy Tarreau + */ + +/* Below comes the architecture-specific code. For each architecture, we h= ave + * the syscall declarations and the _start code definition. This is the gl= obal + * part for _start code definition. + */ + +#ifndef _NOLIBC_CRT_ARCH_H +#define _NOLIBC_CRT_ARCH_H + +#if defined(__x86_64__) +#include "x86_64/crt.h" +#elif defined(__i386__) || defined(__i486__) || defined(__i586__) || defin= ed(__i686__) +#include "i386/crt.h" +#elif defined(__ARM_EABI__) +#include "arm/crt.h" +#elif defined(__aarch64__) +#include "aarch64/crt.h" +#elif defined(__mips__) && defined(_ABIO32) +#include "mips/crt.h" +#elif defined(__riscv) +#include "riscv/crt.h" +#elif defined(__s390x__) +#include "s390/crt.h" +#elif defined(__loongarch__) +#include "loongarch/crt.h" +#endif + +#endif /* _NOLIBC_CRT_ARCH_H */ diff --git a/tools/include/nolibc/i386/crt.h b/tools/include/nolibc/i386/cr= t.h new file mode 100644 index 000000000000..0b88f7c887ae --- /dev/null +++ b/tools/include/nolibc/i386/crt.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * i386 specific startup code for NOLIBC + * Copyright (C) 2017-2022 Willy Tarreau + */ + +#ifndef _NOLIBC_I386_CRT_H +#define _NOLIBC_I386_CRT_H + +/* startup code */ +/* + * i386 System V ABI mandates: + * 1) last pushed argument must be 16-byte aligned. + * 2) The deepest stack frame should be set to zero + * + */ +void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_= stack_protector _start(void) +{ + __asm__ volatile ( +#ifdef _NOLIBC_STACKPROTECTOR + "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 = */ + ); + __builtin_unreachable(); +} + +#endif /* _NOLIBC_I386_CRT_H */ diff --git a/tools/include/nolibc/i386/arch.h b/tools/include/nolibc/i386/s= ys.h similarity index 79% rename from tools/include/nolibc/i386/arch.h rename to tools/include/nolibc/i386/sys.h index 66052742763e..c626cf2b145a 100644 --- a/tools/include/nolibc/i386/arch.h +++ b/tools/include/nolibc/i386/sys.h @@ -1,13 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1 OR MIT */ /* - * i386 specific definitions for NOLIBC + * i386 specific syscall declarations for NOLIBC * Copyright (C) 2017-2022 Willy Tarreau */ =20 -#ifndef _NOLIBC_I386_ARCH_H -#define _NOLIBC_I386_ARCH_H - -#include "compiler.h" +#ifndef _NOLIBC_I386_SYS_H +#define _NOLIBC_I386_SYS_H =20 /* The struct returned by the stat() syscall, 32-bit only, the syscall ret= urns * exactly 56 bytes (stops before the unused array). @@ -180,45 +178,4 @@ struct sys_stat_struct { _eax; \ }) =20 -char **environ __attribute__((weak)); -const unsigned long *_auxv __attribute__((weak)); - -/* startup code */ -/* - * i386 System V ABI mandates: - * 1) last pushed argument must be 16-byte aligned. - * 2) The deepest stack frame should be set to zero - * - */ -void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_st= ack_protector _start(void) -{ - __asm__ volatile ( -#ifdef _NOLIBC_STACKPROTECTOR - "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 = */ - ); - __builtin_unreachable(); -} - -#endif /* _NOLIBC_I386_ARCH_H */ +#endif /* _NOLIBC_I386_SYS_H */ diff --git a/tools/include/nolibc/loongarch/crt.h b/tools/include/nolibc/lo= ongarch/crt.h new file mode 100644 index 000000000000..253d2fccea1e --- /dev/null +++ b/tools/include/nolibc/loongarch/crt.h @@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * LoongArch specific startup code for NOLIBC + * Copyright (C) 2023 Loongson Technology Corporation Limited + */ + +#ifndef _NOLIBC_LOONGARCH_CRT_H +#define _NOLIBC_LOONGARCH_CRT_H + +#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 + +/* 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 = */ +#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" + ); + __builtin_unreachable(); +} + +#endif /* _NOLIBC_LOONGARCH_CRT_H */ diff --git a/tools/include/nolibc/loongarch/arch.h b/tools/include/nolibc/l= oongarch/sys.h similarity index 73% rename from tools/include/nolibc/loongarch/arch.h rename to tools/include/nolibc/loongarch/sys.h index 63fee1e8f4d9..98d47b5823dc 100644 --- a/tools/include/nolibc/loongarch/arch.h +++ b/tools/include/nolibc/loongarch/sys.h @@ -1,13 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1 OR MIT */ /* - * LoongArch specific definitions for NOLIBC + * LoongArch specific syscall declarations for NOLIBC * Copyright (C) 2023 Loongson Technology Corporation Limited */ =20 -#ifndef _NOLIBC_LOONGARCH_ARCH_H -#define _NOLIBC_LOONGARCH_ARCH_H - -#include "compiler.h" +#ifndef _NOLIBC_LOONGARCH_SYS_H +#define _NOLIBC_LOONGARCH_SYS_H =20 /* Syscalls for LoongArch : * - stack is 16-byte aligned @@ -143,58 +141,4 @@ _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 - -/* 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 = */ -#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" - ); - __builtin_unreachable(); -} - -#endif /* _NOLIBC_LOONGARCH_ARCH_H */ +#endif /* _NOLIBC_LOONGARCH_SYS_H */ diff --git a/tools/include/nolibc/mips/crt.h b/tools/include/nolibc/mips/cr= t.h new file mode 100644 index 000000000000..38df52d8ec16 --- /dev/null +++ b/tools/include/nolibc/mips/crt.h @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * MIPS specific startup code for NOLIBC + * Copyright (C) 2017-2022 Willy Tarreau + */ + +#ifndef _NOLIBC_MIPS_CRT_H +#define _NOLIBC_MIPS_CRT_H + +/* 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" + ".option pic0\n" +#ifdef _NOLIBC_STACKPROTECTOR + "jal __stack_chk_init\n" /* initialize stack protector = */ + "nop\n" /* delayed slot = */ +#endif + /*".ent __start\n"*/ + /*"__start:\n"*/ + "lw $a0,($sp)\n" /* argc was in the stack = */ + "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"*/ + ".set pop\n" + ); + __builtin_unreachable(); +} + +#endif /* _NOLIBC_MIPS_CRT_H */ diff --git a/tools/include/nolibc/mips/arch.h b/tools/include/nolibc/mips/s= ys.h similarity index 79% rename from tools/include/nolibc/mips/arch.h rename to tools/include/nolibc/mips/sys.h index 1581b721b714..13dfbf3e6a3d 100644 --- a/tools/include/nolibc/mips/arch.h +++ b/tools/include/nolibc/mips/sys.h @@ -1,13 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1 OR MIT */ /* - * MIPS specific definitions for NOLIBC + * MIPS specific syscall declarations for NOLIBC * Copyright (C) 2017-2022 Willy Tarreau */ =20 -#ifndef _NOLIBC_MIPS_ARCH_H -#define _NOLIBC_MIPS_ARCH_H - -#include "compiler.h" +#ifndef _NOLIBC_MIPS_SYS_H +#define _NOLIBC_MIPS_SYS_H =20 /* The struct returned by the stat() syscall. 88 bytes are returned by the * syscall. @@ -201,53 +199,4 @@ struct sys_stat_struct { _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" - ".option pic0\n" -#ifdef _NOLIBC_STACKPROTECTOR - "jal __stack_chk_init\n" /* initialize stack protector = */ - "nop\n" /* delayed slot = */ -#endif - /*".ent __start\n"*/ - /*"__start:\n"*/ - "lw $a0,($sp)\n" /* argc was in the stack = */ - "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"*/ - ".set pop\n" - ); - __builtin_unreachable(); -} - -#endif /* _NOLIBC_MIPS_ARCH_H */ +#endif /* _NOLIBC_MIPS_SYS_H */ diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h index 1f8d821000ac..096a18b71923 100644 --- a/tools/include/nolibc/nolibc.h +++ b/tools/include/nolibc/nolibc.h @@ -93,8 +93,8 @@ #define _NOLIBC_H =20 #include "std.h" -#include "arch.h" #include "types.h" +#include "crt.h" #include "sys.h" #include "ctype.h" #include "signal.h" diff --git a/tools/include/nolibc/riscv/crt.h b/tools/include/nolibc/riscv/= crt.h new file mode 100644 index 000000000000..1f81a2e47a48 --- /dev/null +++ b/tools/include/nolibc/riscv/crt.h @@ -0,0 +1,57 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * RISCV (32 and 64) specific startup code for NOLIBC + * Copyright (C) 2017-2022 Willy Tarreau + */ + +#ifndef _NOLIBC_RISCV_CRT_H +#define _NOLIBC_RISCV_CRT_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 + +/* 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" + ".option pop\n" +#ifdef _NOLIBC_STACKPROTECTOR + "call __stack_chk_init\n" /* initialize stack protector = */ +#endif + REG_L" a0, 0(sp)\n" /* argc (a0) was in the stack = */ + "add a1, sp, "SZREG"\n" /* argv (a1) =3D sp = */ + "slli a2, a0, "PTRLOG"\n" /* envp (a2) =3D SZREG*argc ... = */ + "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" + ); + __builtin_unreachable(); +} + +#endif /* _NOLIBC_RISCV_CRT_H */ diff --git a/tools/include/nolibc/riscv/arch.h b/tools/include/nolibc/riscv= /sys.h similarity index 78% rename from tools/include/nolibc/riscv/arch.h rename to tools/include/nolibc/riscv/sys.h index de68759f5959..aa15b86c919f 100644 --- a/tools/include/nolibc/riscv/arch.h +++ b/tools/include/nolibc/riscv/sys.h @@ -1,13 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1 OR MIT */ /* - * RISCV (32 and 64) specific definitions for NOLIBC + * RISCV (32 and 64) specific syscall declarations for NOLIBC * Copyright (C) 2017-2022 Willy Tarreau */ =20 -#ifndef _NOLIBC_RISCV_ARCH_H -#define _NOLIBC_RISCV_ARCH_H - -#include "compiler.h" +#ifndef _NOLIBC_RISCV_SYS_H +#define _NOLIBC_RISCV_SYS_H =20 struct sys_stat_struct { unsigned long st_dev; /* Device. */ @@ -32,18 +30,6 @@ struct sys_stat_struct { unsigned int __unused5; }; =20 -#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 - /* Syscalls for RISCV : * - stack is 16-byte aligned * - syscall number is passed in a7 @@ -176,42 +162,4 @@ struct sys_stat_struct { _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" - ".option pop\n" -#ifdef _NOLIBC_STACKPROTECTOR - "call __stack_chk_init\n" /* initialize stack protector = */ -#endif - REG_L" a0, 0(sp)\n" /* argc (a0) was in the stack = */ - "add a1, sp, "SZREG"\n" /* argv (a1) =3D sp = */ - "slli a2, a0, "PTRLOG"\n" /* envp (a2) =3D SZREG*argc ... = */ - "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" - ); - __builtin_unreachable(); -} - -#endif /* _NOLIBC_RISCV_ARCH_H */ +#endif /* _NOLIBC_RISCV_SYS_H */ diff --git a/tools/include/nolibc/s390/crt.h b/tools/include/nolibc/s390/cr= t.h new file mode 100644 index 000000000000..8580f615d525 --- /dev/null +++ b/tools/include/nolibc/s390/crt.h @@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * s390 specific startup code for NOLIBC + */ + +#ifndef _NOLIBC_S390_CRT_H +#define _NOLIBC_S390_CRT_H + +/* 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" + ); + __builtin_unreachable(); +} + +#endif /* _NOLIBC_S390_CRT_H */ diff --git a/tools/include/nolibc/s390/arch.h b/tools/include/nolibc/s390/s= ys.h similarity index 78% rename from tools/include/nolibc/s390/arch.h rename to tools/include/nolibc/s390/sys.h index a7b512e81234..041f4ecb7922 100644 --- a/tools/include/nolibc/s390/arch.h +++ b/tools/include/nolibc/s390/sys.h @@ -1,15 +1,13 @@ /* SPDX-License-Identifier: LGPL-2.1 OR MIT */ /* - * s390 specific definitions for NOLIBC + * s390 specific syscall declarations for NOLIBC */ =20 -#ifndef _NOLIBC_S390_ARCH_H -#define _NOLIBC_S390_ARCH_H +#ifndef _NOLIBC_S390_SYS_H +#define _NOLIBC_S390_SYS_H #include #include =20 -#include "compiler.h" - /* The struct returned by the stat() syscall, equivalent to stat64(). The * syscall returns 116 bytes and stops in the middle of __unused. */ @@ -162,45 +160,6 @@ struct sys_stat_struct { _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" - ); - __builtin_unreachable(); -} - struct s390_mmap_arg_struct { unsigned long addr; unsigned long len; @@ -234,4 +193,4 @@ pid_t sys_fork(void) } #define sys_fork sys_fork =20 -#endif /* _NOLIBC_S390_ARCH_H */ +#endif /* _NOLIBC_S390_SYS_H */ diff --git a/tools/include/nolibc/signal.h b/tools/include/nolibc/signal.h index 137552216e46..687c4c13a1d9 100644 --- a/tools/include/nolibc/signal.h +++ b/tools/include/nolibc/signal.h @@ -8,7 +8,6 @@ #define _NOLIBC_SIGNAL_H =20 #include "std.h" -#include "arch.h" #include "types.h" #include "sys.h" =20 diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h index 0eef91daf289..ee5b3f3b79e6 100644 --- a/tools/include/nolibc/stdio.h +++ b/tools/include/nolibc/stdio.h @@ -10,7 +10,6 @@ #include =20 #include "std.h" -#include "arch.h" #include "errno.h" #include "types.h" #include "sys.h" diff --git a/tools/include/nolibc/stdlib.h b/tools/include/nolibc/stdlib.h index 902162f80337..2f9b4b3c6d26 100644 --- a/tools/include/nolibc/stdlib.h +++ b/tools/include/nolibc/stdlib.h @@ -8,8 +8,8 @@ #define _NOLIBC_STDLIB_H =20 #include "std.h" -#include "arch.h" #include "types.h" +#include "crt.h" #include "sys.h" #include "string.h" #include diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index dee56894a811..e84ed57f3a63 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -23,7 +23,7 @@ #include /* for statx() */ #include =20 -#include "arch.h" +#include "sys_arch.h" #include "errno.h" #include "types.h" =20 diff --git a/tools/include/nolibc/sys_arch.h b/tools/include/nolibc/sys_arc= h.h new file mode 100644 index 000000000000..b073051c7713 --- /dev/null +++ b/tools/include/nolibc/sys_arch.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * Copyright (C) 2017-2022 Willy Tarreau + */ + +/* Below comes the architecture-specific code. For each architecture, we h= ave + * the syscall declarations and the _start code definition. This is the gl= obal + * part for syscall declarations. + */ + +#ifndef _NOLIBC_SYS_ARCH_H +#define _NOLIBC_SYS_ARCH_H + +#if defined(__x86_64__) +#include "x86_64/sys.h" +#elif defined(__i386__) || defined(__i486__) || defined(__i586__) || defin= ed(__i686__) +#include "i386/sys.h" +#elif defined(__ARM_EABI__) +#include "arm/sys.h" +#elif defined(__aarch64__) +#include "aarch64/sys.h" +#elif defined(__mips__) && defined(_ABIO32) +#include "mips/sys.h" +#elif defined(__riscv) +#include "riscv/sys.h" +#elif defined(__s390x__) +#include "s390/sys.h" +#elif defined(__loongarch__) +#include "loongarch/sys.h" +#endif + +#endif /* _NOLIBC_SYS_ARCH_H */ diff --git a/tools/include/nolibc/time.h b/tools/include/nolibc/time.h index 84655361b9ad..127ac60706b2 100644 --- a/tools/include/nolibc/time.h +++ b/tools/include/nolibc/time.h @@ -8,7 +8,6 @@ #define _NOLIBC_TIME_H =20 #include "std.h" -#include "arch.h" #include "types.h" #include "sys.h" =20 diff --git a/tools/include/nolibc/unistd.h b/tools/include/nolibc/unistd.h index e38f3660c051..219cc5ea319a 100644 --- a/tools/include/nolibc/unistd.h +++ b/tools/include/nolibc/unistd.h @@ -8,7 +8,6 @@ #define _NOLIBC_UNISTD_H =20 #include "std.h" -#include "arch.h" #include "types.h" #include "sys.h" =20 diff --git a/tools/include/nolibc/x86_64/crt.h b/tools/include/nolibc/x86_6= 4/crt.h new file mode 100644 index 000000000000..6fede1235efc --- /dev/null +++ b/tools/include/nolibc/x86_64/crt.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * x86_64 specific startup code for NOLIBC + * Copyright (C) 2017-2022 Willy Tarreau + */ + +#ifndef _NOLIBC_X86_64_CRT_H +#define _NOLIBC_X86_64_CRT_H + +/* startup code */ +/* + * x86-64 System V ABI mandates: + * 1) %rsp must be 16-byte aligned right before the function call. + * 2) The deepest stack frame should be zero (the %rbp). + * + */ +void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_= stack_protector _start(void) +{ + __asm__ volatile ( +#ifdef _NOLIBC_STACKPROTECTOR + "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 = */ + ); + __builtin_unreachable(); +} + +#endif /* _NOLIBC_X86_64_CRT_H */ diff --git a/tools/include/nolibc/x86_64/arch.h b/tools/include/nolibc/x86_= 64/sys.h similarity index 81% rename from tools/include/nolibc/x86_64/arch.h rename to tools/include/nolibc/x86_64/sys.h index 602791c3461a..c761c97dccf8 100644 --- a/tools/include/nolibc/x86_64/arch.h +++ b/tools/include/nolibc/x86_64/sys.h @@ -1,13 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1 OR MIT */ /* - * x86_64 specific definitions for NOLIBC + * x86_64 specific syscall declarations for NOLIBC * Copyright (C) 2017-2022 Willy Tarreau */ =20 -#ifndef _NOLIBC_X86_64_ARCH_H -#define _NOLIBC_X86_64_ARCH_H - -#include "compiler.h" +#ifndef _NOLIBC_X86_64_SYS_H +#define _NOLIBC_X86_64_SYS_H =20 /* The struct returned by the stat() syscall, equivalent to stat64(). The * syscall returns 116 bytes and stops in the middle of __unused. @@ -180,41 +178,4 @@ struct sys_stat_struct { _ret; \ }) =20 -char **environ __attribute__((weak)); -const unsigned long *_auxv __attribute__((weak)); - -/* startup code */ -/* - * x86-64 System V ABI mandates: - * 1) %rsp must be 16-byte aligned right before the function call. - * 2) The deepest stack frame should be zero (the %rbp). - * - */ -void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_st= ack_protector _start(void) -{ - __asm__ volatile ( -#ifdef _NOLIBC_STACKPROTECTOR - "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 = */ - ); - __builtin_unreachable(); -} - -#endif /* _NOLIBC_X86_64_ARCH_H */ +#endif /* _NOLIBC_X86_64_SYS_H */ --=20 2.25.1 From nobody Mon Feb 9 05:38:38 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 42335EB64DD for ; Sat, 8 Jul 2023 15:29:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230350AbjGHP3J (ORCPT ); Sat, 8 Jul 2023 11:29:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229726AbjGHP3H (ORCPT ); Sat, 8 Jul 2023 11:29:07 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 083E41709; Sat, 8 Jul 2023 08:29:04 -0700 (PDT) X-QQ-mid: bizesmtp67t1688830134tnbci13y Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 23:28:53 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: wbizDlKcf6k2E2Tlh93dI0gtZr19CNzGMJQHCuHAOD58RfG1bYwL5a3TOroCj p7gWNciZgMLgnQAnBGlH3zMrTYN1shrLRItJf6iLT4tYKET4UJSAIMUzPeB7x71oqVQcl+V IqGvfxRk+vvruHGtb4QUPlcf1iNghiDdmmSELpV39e7EQ802u1tdrBoAfhJLFz5xA6/uMM+ tVskNr3coNMxLKaOcRgCP80aFmfy+c5JNV5jelcm5nzcTqKK4PSLsCQv+3/9VxVCnU86FF/ TdtTMtWp2MUctNypr9haTACDXKIi0UhF5M4Rbt0XAs6RWgTbx0ZGk6u13m3iQ3vBgxMDjBs +LQ3C1Jv8JGsIDWE/FLMZvbmWwJPHveEAismH+/mP6+zhJUxtbhSGDRhU/Puchw4wXHD8NM X-QQ-GoodBg: 0 X-BIZMAIL-ID: 8368633829245986870 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 v2 03/12] tools/nolibc: sys.h: remove the old sys_stat support Date: Sat, 8 Jul 2023 23:28:53 +0800 Message-Id: <759c5674a2a354312729893116168637135ac173.1688828139.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/aarch64/sys.h | 28 ------------- tools/include/nolibc/arm/sys.h | 37 ------------------ tools/include/nolibc/i386/sys.h | 26 ------------ tools/include/nolibc/mips/sys.h | 28 ------------- tools/include/nolibc/riscv/sys.h | 23 ----------- tools/include/nolibc/s390/sys.h | 25 ------------ tools/include/nolibc/sys.h | 63 ++++++------------------------ tools/include/nolibc/types.h | 4 +- tools/include/nolibc/x86_64/sys.h | 27 ------------- 9 files changed, 13 insertions(+), 248 deletions(-) diff --git a/tools/include/nolibc/aarch64/sys.h b/tools/include/nolibc/aarc= h64/sys.h index b79d6a35ec37..43df164b8796 100644 --- a/tools/include/nolibc/aarch64/sys.h +++ b/tools/include/nolibc/aarch64/sys.h @@ -7,34 +7,6 @@ #ifndef _NOLIBC_AARCH64_SYS_H #define _NOLIBC_AARCH64_SYS_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/arm/sys.h b/tools/include/nolibc/arm/sys.h index 79173f860948..db8846ff3eda 100644 --- a/tools/include/nolibc/arm/sys.h +++ b/tools/include/nolibc/arm/sys.h @@ -7,43 +7,6 @@ #ifndef _NOLIBC_ARM_SYS_H #define _NOLIBC_ARM_SYS_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/i386/sys.h b/tools/include/nolibc/i386/sy= s.h index c626cf2b145a..d2d0eeccb8fc 100644 --- a/tools/include/nolibc/i386/sys.h +++ b/tools/include/nolibc/i386/sys.h @@ -7,32 +7,6 @@ #ifndef _NOLIBC_I386_SYS_H #define _NOLIBC_I386_SYS_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/mips/sys.h b/tools/include/nolibc/mips/sy= s.h index 13dfbf3e6a3d..c3c245682e5d 100644 --- a/tools/include/nolibc/mips/sys.h +++ b/tools/include/nolibc/mips/sys.h @@ -7,34 +7,6 @@ #ifndef _NOLIBC_MIPS_SYS_H #define _NOLIBC_MIPS_SYS_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/riscv/sys.h b/tools/include/nolibc/riscv/= sys.h index aa15b86c919f..682bf9c0165b 100644 --- a/tools/include/nolibc/riscv/sys.h +++ b/tools/include/nolibc/riscv/sys.h @@ -7,29 +7,6 @@ #ifndef _NOLIBC_RISCV_SYS_H #define _NOLIBC_RISCV_SYS_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; -}; - /* Syscalls for RISCV : * - stack is 16-byte aligned * - syscall number is passed in a7 diff --git a/tools/include/nolibc/s390/sys.h b/tools/include/nolibc/s390/sy= s.h index 041f4ecb7922..4373c4dc1e8a 100644 --- a/tools/include/nolibc/s390/sys.h +++ b/tools/include/nolibc/s390/sys.h @@ -8,31 +8,6 @@ #include #include =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/sys.h b/tools/include/nolibc/sys.h index e84ed57f3a63..8c7fc9f5abd1 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 diff --git a/tools/include/nolibc/x86_64/sys.h b/tools/include/nolibc/x86_6= 4/sys.h index c761c97dccf8..ac3e8811b7d1 100644 --- a/tools/include/nolibc/x86_64/sys.h +++ b/tools/include/nolibc/x86_64/sys.h @@ -7,33 +7,6 @@ #ifndef _NOLIBC_X86_64_SYS_H #define _NOLIBC_X86_64_SYS_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 --=20 2.25.1 From nobody Mon Feb 9 05:38:38 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 9516FEB64DC for ; Sat, 8 Jul 2023 15:30:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230499AbjGHPaN (ORCPT ); Sat, 8 Jul 2023 11:30:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229726AbjGHPaL (ORCPT ); Sat, 8 Jul 2023 11:30:11 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78DFF90; Sat, 8 Jul 2023 08:30:09 -0700 (PDT) X-QQ-mid: bizesmtp90t1688830199tddli4lm Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 23:29:58 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: eSZ1CZgv+JDNSYVWcvAqpj0rMV65FuCWvkiqEsX0QCaJ3cmGvGHwqt4FW1NPz xtLYKx4fWntTwjgdLuKBjSAmdBqltgnFcnpV0Gg+dSUFOBuhWgGtMIVtlDJuRSOakTaDPyf DteElzUduQbDJaKPkaiv65kbJIwnbKHkk9XhbF7riP1SVSVYoxY855+ZD2A+7Kyh5RALGtG zeeesVIfP5H0OAey6/2Pp+ARRSKgkAwVv0n0wkl3AZDqzEyuojwi0WP8cSU2snSHpbwpFMf C/QtfST4aIERx7pL/R9uECvdoTwV9p5F2Zo/LtJSLRMdjKmijl9YEoGocgpClxQWlw6II3G 0TZNWf1ltkWlZULHAwSeTkDHf2JIuhfDfKj0rx2TIG3R52KWmXc2oQ7zS748Q== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 10107616674853176489 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 v2 04/12] tools/nolibc: crt.h: add _start_c Date: Sat, 8 Jul 2023 23:29:58 +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" 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. Signed-off-by: Zhangjin Wu --- tools/include/nolibc/crt.h | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tools/include/nolibc/crt.h b/tools/include/nolibc/crt.h index 221b7c5346ca..b269294e9664 100644 --- a/tools/include/nolibc/crt.h +++ b/tools/include/nolibc/crt.h @@ -13,4 +13,48 @@ char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); =20 +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 =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(main(argc, argv, envp)); +} + #endif /* _NOLIBC_CRT_H */ --=20 2.25.1 From nobody Mon Feb 9 05:38:38 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 00912EB64DD for ; Sat, 8 Jul 2023 15:31:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229707AbjGHPbS (ORCPT ); Sat, 8 Jul 2023 11:31:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229552AbjGHPbQ (ORCPT ); Sat, 8 Jul 2023 11:31:16 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 361E890; Sat, 8 Jul 2023 08:31:15 -0700 (PDT) X-QQ-mid: bizesmtp86t1688830265t9d8l2g9 Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 23:31:03 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: eEaWPhs2DhvhZjsqAkJMMlzDeo2Sh5soRzY51O43vfpZnHRFckDc/KC+Whroj xugcXLSy7ICVFoiqSeTqCxTxDobCGlqVytmjm0QCDA4tguduQfJzEfDRcxmIlotOOEJXxoc Szs+owZ8ZdluFmUsrVqHiJdJRNXczXWNaeeYPWWWTKlBKPSwP4H3fmn6kDuV7Jgf7IhvcyF Y8jIw9/qDAPT3SPiuBrsnURgvLq+VWA9y/xT93260LoCPfi+IHVypNKboYor7z24/ElvVLv p5L1kmZJ/ainACsUtabnDfg1JQfM14itwmu6i6doAuz2mSNSJfH/hiigypC77vcvFbn4tFc DiYkkoHr/ovqEbIBaEx5pATYUoVOXFT9LNZQ7ULn54b9FrgnXEpUdehQ8s64qqtJLxkPGgf X-QQ-GoodBg: 0 X-BIZMAIL-ID: 5492700503261273189 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 v2 05/12] tools/nolibc: arm/crt.h: shrink _start with _start_c Date: Sat, 8 Jul 2023 23:31:03 +0800 Message-Id: <3b38249bfc9d36db3f33e44b42d34740b9de100a.1688828139.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/arm/crt.h | 38 +++++----------------------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/tools/include/nolibc/arm/crt.h b/tools/include/nolibc/arm/crt.h index 7b3b9e21e5c4..75c097027a80 100644 --- a/tools/include/nolibc/arm/crt.h +++ b/tools/include/nolibc/arm/crt.h @@ -12,40 +12,12 @@ void __attribute__((weak, noreturn, optimize("omit-fram= e-pointer"))) __no_stack_ { __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 Mon Feb 9 05:38:38 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 58A83EB64DD for ; Sat, 8 Jul 2023 15:32:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229826AbjGHPcY (ORCPT ); Sat, 8 Jul 2023 11:32:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229552AbjGHPcV (ORCPT ); Sat, 8 Jul 2023 11:32:21 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1167E183; Sat, 8 Jul 2023 08:32:19 -0700 (PDT) X-QQ-mid: bizesmtp80t1688830330tnbi25mx Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 23:32:09 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: SFhf6fKhx/9392JZYlaBcqX7N+KA6AjdqY1MUs2G5hwRQSRVRqVb4QisWKQCO HfhGqBYbrXmkVF/kYZsdUHeGXXQhKWidRRUaqBB1u8jAKIlSClrHsv3QmEPoBm6bTCau/uE YJSj4Dac4bu8YDSDODE2VmpPIgcaXvEpHZyVWD6j84onxlxz/KhIWyGwJZtvoMZrXMxa79+ n9FTpbOp45V7syHlg8/MdkC8BXeTYttJduk3gdqrOClUB8tDBeiKf5AdYlxPQe21Z2e1mRk mz2DU8cSRnzoDThE4vWcjevDWjg3AiClpBwUr/z2DevYJrfDGc9ceFyjA/0pCyiL0X2k9cl yMqtgMU65tz8L4kJ7mJOXSKE5Naiz1UsNYY3DtFBW0gTxMX35najJkiiICOYw== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 9503456289267630914 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 v2 06/12] tools/nolibc: aarch64/crt.h: shrink _start with _start_c Date: Sat, 8 Jul 2023 23:32:09 +0800 Message-Id: <45f8e3a6bef02996cdd97b672b3e350a9a90b626.1688828139.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/aarch64/crt.h | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/tools/include/nolibc/aarch64/crt.h b/tools/include/nolibc/aarc= h64/crt.h index 6c81d81cf31f..4e04c421ab63 100644 --- a/tools/include/nolibc/aarch64/crt.h +++ b/tools/include/nolibc/aarch64/crt.h @@ -12,26 +12,13 @@ void __attribute__((weak, noreturn, optimize("omit-fram= e-pointer"))) __no_stack_ { __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(); + } #endif /* _NOLIBC_AARCH64_CRT_H */ --=20 2.25.1 From nobody Mon Feb 9 05:38:38 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 11696EB64DD for ; Sat, 8 Jul 2023 15:33:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229483AbjGHPdf (ORCPT ); Sat, 8 Jul 2023 11:33:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229552AbjGHPdd (ORCPT ); Sat, 8 Jul 2023 11:33:33 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0048B9; Sat, 8 Jul 2023 08:33:29 -0700 (PDT) X-QQ-mid: bizesmtp82t1688830400tnw4fqr8 Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 23:33:18 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: 3M0okmaRx3jTqNLxLrG6yWpv/QJkh0QmhXcU6YGQmBWSV1xDrAf8EYRJGwJ1H jFLLY1hdkIYFfiWtjxPWqL4fpLl5ROyNnZa6oi5Ocy4gBF5PyzWpNuOROyrfaJZrWzajfT0 Z1KUfOnxJfg7NGpnCzo3ke0Vgddbhr0tk4Lsq7tuiFulTd45o7nBQkvFmDAJd2o59fk4Glj HJ2o7jzru/Crcxa8NKuvMl4/rZ5FoHq1MtamPbm3c23KExrLG3wZb3N2ohpDQo/1Wg0+Ch+ O4/CEyE/Ftx3UVwnoabRLrg61w4z7yvoE2SbV7zdAH0guEAXtXhKtCEdKQLSU8ee7OQ5aqF aSURZqTnuoqUgHLd2iN9kdjOy2z+/48M1eu7TA/hlSoKGrlun46VibjUfXzwQ== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 7735536925553347546 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 v2 07/12] tools/nolibc: i386/crt.h: shrink _start with _start_c Date: Sat, 8 Jul 2023 23:33:14 +0800 Message-Id: <1ca8535cdd8a6473c1bb6c8c7a8e4ff45e558ea3.1688828139.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/i386/crt.h | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/tools/include/nolibc/i386/crt.h b/tools/include/nolibc/i386/cr= t.h index 0b88f7c887ae..87f31bc253a3 100644 --- a/tools/include/nolibc/i386/crt.h +++ b/tools/include/nolibc/i386/crt.h @@ -18,29 +18,14 @@ void __attribute__((weak, noreturn, optimize("omit-fram= e-pointer"))) __no_stack_ { __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 Mon Feb 9 05:38:38 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 4A789EB64DD for ; Sat, 8 Jul 2023 15:34:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230394AbjGHPei (ORCPT ); Sat, 8 Jul 2023 11:34:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbjGHPeg (ORCPT ); Sat, 8 Jul 2023 11:34:36 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CDB3B9; Sat, 8 Jul 2023 08:34:34 -0700 (PDT) X-QQ-mid: bizesmtp71t1688830464t9qr84v5 Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 23:34:24 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: RmDZc/K2LPGrTc+Pc4Z2+3faJnbCPSy2B/cQnsYjS8cIDt3lndFeaPYMb6dVv 66TIx8pcxIbgWY06emMhGeUkT53LMFTNGUbLANkvUosh4MvYKjoocDa18HkvXgsNohOk+wC bHUNoPa5KHa6/cZleWKjVTEjELQEGDzT+B8opn1vLcA6YjeBD7WDtm7FTeVzmGk63TiST8I 2DLzl8HMSz8vMBGSCp5wu+c+RHImsN+H+fHEVmNtVFYBYJWeu7B+Uj8q1FEAMEW3+OKO09B CbdCIUjolq+sJuYPJiNBmepGT44pYKlTR8q2AVDDxPAEg5RB5zUzTo1lOnrXhVaOEMncfIa i2eTVLw9VQkzBgX0cztOgs6mKU/Ygs8LVo2hYUa+iqsmYIM9dHPMwRLAsrR0A== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 10461963764472987799 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 v2 08/12] tools/nolibc: x86_64/crt.h: shrink _start with _start_c Date: Sat, 8 Jul 2023 23:34:23 +0800 Message-Id: <190ba3df4d2be93a220a8f83a902785adcc4c302.1688828139.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/x86_64/crt.h | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/tools/include/nolibc/x86_64/crt.h b/tools/include/nolibc/x86_6= 4/crt.h index 6fede1235efc..03899042854e 100644 --- a/tools/include/nolibc/x86_64/crt.h +++ b/tools/include/nolibc/x86_64/crt.h @@ -18,27 +18,16 @@ void __attribute__((weak, noreturn, optimize("omit-fram= e-pointer"))) __no_stack_ { __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 #endif /* _NOLIBC_X86_64_CRT_H */ --=20 2.25.1 From nobody Mon Feb 9 05:38:38 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 111D8EB64DC for ; Sat, 8 Jul 2023 15:35:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230523AbjGHPfn (ORCPT ); Sat, 8 Jul 2023 11:35:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbjGHPfl (ORCPT ); Sat, 8 Jul 2023 11:35:41 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33595B9; Sat, 8 Jul 2023 08:35:39 -0700 (PDT) X-QQ-mid: bizesmtp64t1688830529tddkhgwo Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 23:35:28 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: SFhf6fKhx/8MNvygIFrN5Ea7ntRZXkmkNIkR/K+V5n83hDBFmZTb/GNM4JKdB 3pLoKQYJFayAbbQVDEHt1sPPe2SJsrbCY36y7lRh4Z8SAlqSFwoOozouaXGMHwqB0/5sYoT 09Y2nTr9XT1/GBc2Cp4f/PpRj1/e/QvzYIQBV5RIOvJezSaF7WwEAk+eztGDPlgGS2grtyH luGNPXiPr320kjyzVQTrbFhoU5YyYIRduR6fp+OpJ42jTMYk8VCZKH5Ik3tO6hEwyf7E+p4 oU/J2BPZG3Oc6wclKBPLwKHg3a4Qd5RtL7fGspx1G+d5jv8vyoStsfBE00wE+yoUku4pTX0 k9lPSI+Np5AaTo31XGYcowaGH///UZRzFCJbSBUwyJv83YVawQzy/0NNwlxqw== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 5730267673946759822 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 v2 09/12] tools/nolibc: mips/crt.h: shrink _start with _start_c Date: Sat, 8 Jul 2023 23:35:28 +0800 Message-Id: <26b030bd7e0d48e60350c1b325dd0668f0caf803.1688828139.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(). Also clean up the instructions in delay slots. Signed-off-by: Zhangjin Wu --- tools/include/nolibc/mips/crt.h | 42 +++++++-------------------------- 1 file changed, 9 insertions(+), 33 deletions(-) diff --git a/tools/include/nolibc/mips/crt.h b/tools/include/nolibc/mips/cr= t.h index 38df52d8ec16..a49632b64fdd 100644 --- a/tools/include/nolibc/mips/crt.h +++ b/tools/include/nolibc/mips/crt.h @@ -11,43 +11,19 @@ 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 =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 Mon Feb 9 05:38:38 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 3BEDFEB64DD for ; Sat, 8 Jul 2023 15:36:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230143AbjGHPgy (ORCPT ); Sat, 8 Jul 2023 11:36:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbjGHPgx (ORCPT ); Sat, 8 Jul 2023 11:36:53 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D25CFB8; Sat, 8 Jul 2023 08:36:50 -0700 (PDT) X-QQ-mid: bizesmtp86t1688830599tw66g3er Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 23:36:37 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: W+onFc5Tw4Pe9rZqENKFEXMbSRh7Eb3+Jr9OU9bz39iaWL+qI45aWo7EyeNr5 vz/B5cB4JSaGvK2qJUl6k2KQNV3MGBN6Uj84RTUkDwdW2jEEp3Hz9lm5A7br7JwDjuZASLD wRsVyB6VsMDvRVOGmaOgXLxG1OkaU1/AlC56GNg5PI5O7M45DLBXrPNKO9+Ten5f6DiC6m3 ivOeaBse7tvOVGGif1d1+qQsGTYRZk93BsQBDX8PoIsojSAXqWy//4mKs0yLQbQ4akgIokO ilS870OH4IeIpSYz9UfkjAID068mm54T0k+ga4VCzPvwdu+OHNmA/ISEYEhpnrRJUE65MrI VnGwkdNzlRmZ3A2fwhM/CKPln7zQFLwE4SYbElvYflo2nofzwdZEvNnX1s8gMEQdAPH/SGu X-QQ-GoodBg: 0 X-BIZMAIL-ID: 3025394520600983061 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 v2 10/12] tools/nolibc: loongarch/crt.h: shrink _start with _start_c Date: Sat, 8 Jul 2023 23:36:33 +0800 Message-Id: <47893d501e6d4ededa233e2596ac32f219480270.1688828139.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/loongarch/crt.h | 39 +++------------------------- 1 file changed, 4 insertions(+), 35 deletions(-) diff --git a/tools/include/nolibc/loongarch/crt.h b/tools/include/nolibc/lo= ongarch/crt.h index 253d2fccea1e..00bfc36b0747 100644 --- a/tools/include/nolibc/loongarch/crt.h +++ b/tools/include/nolibc/loongarch/crt.h @@ -8,22 +8,8 @@ #define _NOLIBC_LOONGARCH_CRT_H =20 #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 @@ -32,28 +18,11 @@ void __attribute__((weak, noreturn, optimize("omit-fram= e-pointer"))) __no_stack_ { __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 Mon Feb 9 05:38:38 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 089A0EB64DD for ; Sat, 8 Jul 2023 15:38:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229665AbjGHPiE (ORCPT ); Sat, 8 Jul 2023 11:38:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229890AbjGHPh4 (ORCPT ); Sat, 8 Jul 2023 11:37:56 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FCCFB8; Sat, 8 Jul 2023 08:37:54 -0700 (PDT) X-QQ-mid: bizesmtp90t1688830664t3wo1csv Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 23:37:43 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: ILHsT53NKPhgnsUgVDz2srbYQCVF7irYB8/gpXVXYeOJXG3utdg0qHYBiAiGX bhoNiWLXPcmqeL426w5U3+Eaa3MCeWLJ0Zn/Tav1QL3t7wnrGMIqQzmN/aRyzW4ktmt7wfs ndhkkHeuMR1R0zevTJ6pefES/orySXRx9B4BPbaZ15g875YxxSmZGQq7VLzo5oh3qvBWgMy ICwr0fwm+YuWjr5XHeJ7DPZNU70KUIw+a8l4xM8blSZXyElZBZWzjsc7ISekOnLXct22G50 6bdFQj1eVNchTz0I5iByAHaFrK5OqS1+kHHYREW+dWAwO0dGlMhUL4WJd23IQpWE5G2jpOU /0DqYPgWEZyx/EKtawUeoyaFhUZqfFcl59TNgC35rXC/uQujKuP/gfYc23TbjwsArS07kjC X-QQ-GoodBg: 0 X-BIZMAIL-ID: 2342700909173157500 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 v2 11/12] tools/nolibc: riscv/crt.h: shrink _start with _start_c Date: Sat, 8 Jul 2023 23:37:43 +0800 Message-Id: <1b7959f4aa03f6e0c797a891322d1db6f65688d3.1688828139.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/riscv/crt.h | 39 ++++---------------------------- 1 file changed, 5 insertions(+), 34 deletions(-) diff --git a/tools/include/nolibc/riscv/crt.h b/tools/include/nolibc/riscv/= crt.h index 1f81a2e47a48..2b8df4c478d5 100644 --- a/tools/include/nolibc/riscv/crt.h +++ b/tools/include/nolibc/riscv/crt.h @@ -7,49 +7,20 @@ #ifndef _NOLIBC_RISCV_CRT_H #define _NOLIBC_RISCV_CRT_H =20 -#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 - /* 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) =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 Mon Feb 9 05:38:38 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 5373CEB64DD for ; Sat, 8 Jul 2023 15:39:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230394AbjGHPjG (ORCPT ); Sat, 8 Jul 2023 11:39:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229726AbjGHPjE (ORCPT ); Sat, 8 Jul 2023 11:39:04 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39524B8; Sat, 8 Jul 2023 08:39:03 -0700 (PDT) X-QQ-mid: bizesmtp71t1688830733tbhmnxv4 Received: from linux-lab-host.localdomain ( [116.30.131.119]) by bizesmtp.qq.com (ESMTP) with id ; Sat, 08 Jul 2023 23:38:52 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: ILHsT53NKPj1pTbEW3cPZlkLOwrV+fGbJKEBPIc2JzMF7eUUvTSN4H7yOyRW/ q6dpW6rJNwJNf6fmcyoIOQnxkgBR3KRPHTMICJC0Nn4SxSx1dsTKJM9saahEdexOS7Q4RP2 AdpI0AOV2AnDC+HkYFWOI8R8GuGkUy4WN/taowligDlWKPNmCR3RebTa6KnFNI8qi302goO UzODrofo+Ge7Ow8LVLD2biPRl0ab1hJsTD60f/XnYKVh08+Bf1FlzFpGFcMS5ByfBSsNUgc GvN1FlIT3K8LZDaJAYIXdBereDfuOYXH4LwEEikTXV5bV159dtfc5CgRF/i+Im/KzVI/Tdw bKAUK9jk2e9N/zwm8TZayklWGlcXsTsQqrbgxQlbw3ehK21FFADWMfmGLA9Og== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 13069921436544709072 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 v2 12/12] tools/nolibc: s390/crt.h: shrink _start with _start_c Date: Sat, 8 Jul 2023 23:38:48 +0800 Message-Id: <7246cc6042073168817a6fe36d8ff3c0c508e684.1688828139.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/s390/crt.h | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/tools/include/nolibc/s390/crt.h b/tools/include/nolibc/s390/cr= t.h index 8580f615d525..e247b8a37475 100644 --- a/tools/include/nolibc/s390/crt.h +++ b/tools/include/nolibc/s390/crt.h @@ -10,34 +10,10 @@ 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" /* 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