Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp19639806rwd; Wed, 28 Jun 2023 12:01:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ79Jk2pJfJK7cwRD65qrnX/M7HSIBAkyYb4I25kGOPIHEMLC0Chm0n8fRUTSmXc2YuWqSlo X-Received: by 2002:a05:6a20:8408:b0:115:1c73:83f5 with SMTP id c8-20020a056a20840800b001151c7383f5mr29995470pzd.26.1687978919007; Wed, 28 Jun 2023 12:01:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687978918; cv=none; d=google.com; s=arc-20160816; b=J+IAZC9U/TmCjztjop6k+PMi8EoRwt2e2m0pHKS3IBEthVNNDV4660Qtk/3CLcIeGk 8lbp6fC0jtU8QH3tcLY8SrYOzC3KgyaZkijAca6JeRs64YSlD8TIgcjQNkt+FVkHCi6j JoL+QmfDIXEpd5xqmGPulCXis6hYfCO5KCLkCfNlTfzjsP006y12ExcLMc9Dqps5zN2E PCauQw6m7LYb4Wr7+1xvuBoa97m82vh/pzbKcGFUZRyT4dHx1iVmMKhzwLZvDGofd1IX FbvP+jD4oOUwRBXyLendheFOt97Y/5bD6NR5sNnD4giecdD/F/G59fXmn6ysyQOxqWrC InpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=/xO0vhrob/IxLFWsQOw0gVuxnzd8Y+W0Hl59pkQyhfs=; fh=jGpRxxGHkcGZyN2ZnaDwhUy8S6joixew3DGGT1L/CuQ=; b=nWF12FL5rjBjrHfZ4UDEaW0BYMrp9gdOrX+6cAG1GLYJUxJFmIEZkNPRYjU2dD7i4V V/zCjARqPmBcbMW7oYnJE6ZSYKBYYRQSpYdLoYONVCPx/IwKNn7TBCpCMdZWChkATL2C QOgRkYOFswnfEFJ71Htt1Ms70anAwlvdRBTRUsRgs44PqT8u+U6RVIIle0palH+UvLLC nSezTNlGJMjeNeNLtrBVLEYQmlsGm/LoaKJDQEvGMmq0rRsNwPeREMSQYYXiJrSzi6gd rBL6dMJpFZ5/I1cp12nR0aZhPJoFf9HcEVJBdzH5NkLXheamE05yy7Q/BwnuvS/ebQ6I 6ATg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a19-20020a63e413000000b00553a56f7b31si9635152pgi.330.2023.06.28.12.01.38; Wed, 28 Jun 2023 12:01:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230315AbjF1TAn (ORCPT + 99 others); Wed, 28 Jun 2023 15:00:43 -0400 Received: from bg4.exmail.qq.com ([43.154.54.12]:64558 "EHLO bg4.exmail.qq.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232277AbjF1S7E (ORCPT ); Wed, 28 Jun 2023 14:59:04 -0400 X-QQ-mid: bizesmtp78t1687978735t1k8oxv4 Received: from linux-lab-host.localdomain ( [116.30.129.193]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 29 Jun 2023 02:58:53 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: znfcQSa1hKbNtlJaExe6GfPAoc0Ow5+wEWHtPLG7/Q1ge+0ox0JyU9wMZjrJB FtypQUSuK8tr3GynT9yFI2sUEDe1ixy87NqzzYo8mCDDjD4dEQp9RNDNmknFPKNEDwCqTTl rBh23PghpE0BeEpgR9KmVOl+x6kRiFqrD1NrVUE2gl94i2AKJsaWbJp3ZeZGKvRlk+DQ4Ua uOO9ts/jzsDuTn2eozBWxv4Ec183BmS/Dt8SsvwS8U3L/XhRTcoe1D9KbI2yDgvp4zNzmoO wqXMiCqMx94azMgzMWL/tOLzm3ucmctRTOQ1QXkNIK3OZP5rMZuFMNFnotyiTvh7b8t7Bx6 uFwXiRjLkfGw04uw1vIX0ZKUEPWkOUAKqz01NmfaznPq3tpd5uMtTO+IyQZMw== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 10494488464373133128 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v1 06/11] tools/nolibc: i386: shrink _start with _start_c Date: Thu, 29 Jun 2023 02:58:43 +0800 Message-Id: <27783ab1bed69fd99319aa52e03e204ef1160d74.1687976753.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Let's move most of the _start operations to _start_c(). Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-i386.h | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/tools/include/nolibc/arch-i386.h b/tools/include/nolibc/arch-i386.h index 418554435545..b56046f1d0c0 100644 --- a/tools/include/nolibc/arch-i386.h +++ b/tools/include/nolibc/arch-i386.h @@ -154,9 +154,6 @@ _eax; \ }) -char **environ __attribute__((weak)); -const unsigned long *_auxv __attribute__((weak)); - /* startup code */ /* * i386 System V ABI mandates: @@ -168,29 +165,14 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_stack_pr { __asm__ volatile ( #ifdef _NOLIBC_STACKPROTECTOR - "call __stack_chk_init\n" /* initialize stack protector */ + "call __stack_chk_init\n" /* initialize stack protector */ #endif - "pop %eax\n" /* argc (first arg, %eax) */ - "mov %esp, %ebx\n" /* argv[] (second arg, %ebx) */ - "lea 4(%ebx,%eax,4),%ecx\n" /* then a NULL then envp (third arg, %ecx) */ - "mov %ecx, environ\n" /* save environ */ - "xor %ebp, %ebp\n" /* zero the stack frame */ - "mov %ecx, %edx\n" /* search for auxv (follows NULL after last env) */ - "0:\n" - "add $4, %edx\n" /* search for auxv using edx, it follows the */ - "cmp -4(%edx), %ebp\n" /* ... NULL after last env (ebp is zero here) */ - "jnz 0b\n" - "mov %edx, _auxv\n" /* save it into _auxv */ - "and $-16, %esp\n" /* x86 ABI : esp must be 16-byte aligned before */ - "sub $4, %esp\n" /* the call instruction (args are aligned) */ - "push %ecx\n" /* push all registers on the stack so that we */ - "push %ebx\n" /* support both regparm and plain stack modes */ - "push %eax\n" - "call main\n" /* main() returns the status code in %eax */ - "mov %eax, %ebx\n" /* retrieve exit code (32-bit int) */ - "movl $1, %eax\n" /* NR_exit == 1 */ - "int $0x80\n" /* exit now */ - "hlt\n" /* ensure it does not */ + "xor %ebp, %ebp\n" /* zero the stack frame */ + "mov %esp, %eax\n" /* save stack pointer to eax, as arg1 of _start_c */ + "and $-16, %esp\n" /* last pushed argument must be 16-byte aligned */ + "push %eax\n" /* push arg1 on stack to support plain stack modes too */ + "call _start_c\n" /* transfer to c runtime */ + "hlt\n" /* ensure it does not return */ ); __builtin_unreachable(); } -- 2.25.1