From patchwork Wed Jul 12 09:20:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 119016 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1025553vqm; Wed, 12 Jul 2023 02:35:34 -0700 (PDT) X-Google-Smtp-Source: APBJJlHjvlhJKUis/j+vybB0fDsiNdw82N9sVEANokt3YjrEetj75xqQIetiVk9E6edCWMvt0b8N X-Received: by 2002:a05:6a00:2301:b0:657:bdf1:cce1 with SMTP id h1-20020a056a00230100b00657bdf1cce1mr23021875pfh.25.1689154533879; Wed, 12 Jul 2023 02:35:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689154533; cv=none; d=google.com; s=arc-20160816; b=d3Zmtg0EztlH2CoAFDmh25Fjb7TBepnMuz41f3auVLdE/+cgDQa/5p7ANPjmKSnuSu F5ZRCAM6SrR62U9zwItqOo3i/xP3aq558/GgoOKK0SM0MA7/Tu+dcUvkr4AjnPmzJT+x DbE6kakj+N0RS18FXgBaUEWpVatmGW71oKpPkb5BT6Vc15QHeJ9vA17O/ihCuLiU8l+e WnbYMu2ZTEJnAzBEFuC/siV1DsyBcek1Aiw5Xkg0HxkAqhJOCfXSaz44h90ae22ADVpl +PvXkB5pd/JQ0Y1tWBW8CJOWLqWVGLxnC1GDqLgEQGczJVKUCYDPB1POLp/apUsimJjj wj4g== 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=pagKlhqJnpiKKf5yhU30/hiw6u0Zi1eq02twznhMgOI=; fh=kgRNfNE6xRCHBUX3iUlrLhv5pQPglsdZFzOkxo2Fhpc=; b=oe3ooEdIWWp1725oq72RwwADFmE3HQqppMEbQCRISsRmIqXf6WFv3XeGS8MGhBkxnf Wc/lAksOetTFgJD35L/YZMgedhYzqyBw5+4ZMsn6vHFWLiDl7JyvFnVQ77o4Jqn1SWBv 0/1dkPkoV/oaUPoZnrpvNiVmtGl9lr65W6tOtG/0uu8GXaF9ElOlI2Qyk4ca24n5C+kf B8m+qh7d+d1EV0zeLX1KCuwaWSqnqk7czsaU5rc4hsnEMnXATPcOUUbKbgbUV7BltBHu A6je3q/QWQssQcD79CaK0puwgOyZkBfSBsz2xPy4iXw98KLU6+KMUVmXu/JGI5b8dlSJ QBVQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e192-20020a6369c9000000b0054ff42dff19si2881607pgc.121.2023.07.12.02.35.21; Wed, 12 Jul 2023 02:35:33 -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 S232320AbjGLJWn (ORCPT + 99 others); Wed, 12 Jul 2023 05:22:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232190AbjGLJW2 (ORCPT ); Wed, 12 Jul 2023 05:22:28 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21D43E5F; Wed, 12 Jul 2023 02:21:44 -0700 (PDT) X-QQ-mid: bizesmtp66t1689153656te3bxl5e Received: from linux-lab-host.localdomain ( [116.30.126.249]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 12 Jul 2023 17:20:55 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: f0e3nd0UjDMWyqMb2OvZ3nICQJEiN23es6rzV5wC4cahNSci93zk5avdkN9io q6BYdGJoZRmuMT5rlrQMLsTfYs1JDiRGxLhXm10fh6zUHduZJaJzzdEtPFbZO2sRNnVY/Uf 8Skorwq/S+JEevTOwGrg/t8gy1kUoX5xgEbi/iZ+uiG1SnDVRlw5OroSC880NrikfhbX63H w4zF2E/cFDLmhtmGtHgNB6jMVLFmBbcIZL/11fBfv0u3A3oWwXw+n6Xv6ZP87Z0k4MjQdUV qHnx5Qzfeg5RQdshjphvVgMsmNaMXJ6oh04J6bswf9QBTwjTrkRx8j2hcVC8HUQt2ZNFPHr UkhFXblDdj8PllkZNal2brCfOMD9kbgKoDfE18K77we3a08FPPu8rZmNG75hdxty3rf8GWg X-QQ-GoodBg: 0 X-BIZMAIL-ID: 2211699565622657830 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de Subject: [PATCH v3 05/11] tools/nolibc: i386: shrink _start with _start_c Date: Wed, 12 Jul 2023 17:20:55 +0800 Message-Id: <29e5222e81983e46c0dd8c043db66820ed80638b.1689150149.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771206904104162030 X-GMAIL-MSGID: 1771206904104162030 move most of the _start operations to _start_c(). Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-i386.h | 33 ++++++++------------------------ 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/tools/include/nolibc/arch-i386.h b/tools/include/nolibc/arch-i386.h index 1d4b683bc2cd..f0d0f5c364b8 100644 --- a/tools/include/nolibc/arch-i386.h +++ b/tools/include/nolibc/arch-i386.h @@ -8,6 +8,7 @@ #define _NOLIBC_ARCH_I386_H #include "compiler.h" +#include "crt.h" /* Syscalls for i386 : * - mostly similar to x86_64 @@ -154,9 +155,6 @@ _eax; \ }) -char **environ __attribute__((weak)); -const unsigned long *_auxv __attribute__((weak)); - /* startup code */ /* * i386 System V ABI mandates: @@ -168,29 +166,14 @@ void __attribute__((weak,noreturn,optimize("omit-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(); }