From patchwork Sat Jul 8 15:34:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 117449 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp4007774vqx; Sat, 8 Jul 2023 09:09:09 -0700 (PDT) X-Google-Smtp-Source: APBJJlEAAO9Q4U4gfoZLCtcbWv1bTyVeQAgB7nEwuZU4H5wFVvIW3SzX9c8OqtO7rYP74SMQjkwq X-Received: by 2002:a2e:9015:0:b0:2b6:de41:b72f with SMTP id h21-20020a2e9015000000b002b6de41b72fmr6331951ljg.4.1688832548885; Sat, 08 Jul 2023 09:09:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688832548; cv=none; d=google.com; s=arc-20160816; b=B7xeKC/R1hVy7smBZ6vK1uD74f0E9wwVY+K5pBP5iK4rq9hRh5oiPTRkHpUz6E7Bha XJL8ZUWgSPXgI5s0Cmepr0I6yR969Vhkt2RieHCRJwvBXf8GI1Hf2Rbd+W+0wF+vIGak Tf22KBzAl33bI9oafIA+RJ6EWGdiUHS3iCy0TZTivI1ID9H1V1t/aPba1rQVGlElLnyV KcHtYGAvstUgQ4Cz1dCov2Ad8a52tYM2ONwyRnBl58LgZRQG4jwNoA7xYK74xpmaSqjg eD2rkSVRyQKdlZDZxqC2ObUdF/Zy5wEsqp70BiJP5cHmF/uTYUnMnsiDUpeYmVW41vdy blQw== 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=4aeJh1AWrezyMo3e9FjdiVa9uO9fbeMk8aUaJ3uvA10=; fh=kgRNfNE6xRCHBUX3iUlrLhv5pQPglsdZFzOkxo2Fhpc=; b=wn7APwAn3Xt0GcfxXt94MueL5dmSTDfU47lXHv5UCMvioA7KmLXc4bVF3UBsiDD1jy YhhllcoIxpxA0WrjL/BWPUiN45HWd9KtS48msvRkui0PF/qMNKHvz9eKc1tCHcLGWZZ2 Rc+tqjJ9qpiMG3ACSAUuIdx42t10JMSLuH+liwA7E4TKnCG0iH4S7XAPkfHhf7A/c/3b cv7qnsvSRICyHb3cJQRP0+aCdxM1QdW2zdN4chwLPi2StX5cOM/zam22XZvl7bqZZoM5 KOZvuL2LLPCIDOJ6pVnQ8Idwdjd7QQLyV82SfNgeQTp6+yYoYJ0r8gxyWs+/sa4VSRnz D6DQ== 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 pv20-20020a170907209400b00977ca821ed8si3643539ejb.584.2023.07.08.09.08.44; Sat, 08 Jul 2023 09:09:08 -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 S230354AbjGHPeh (ORCPT + 99 others); Sat, 8 Jul 2023 11:34:37 -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 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_MSPIKE_H2, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770869278515828888?= X-GMAIL-MSGID: =?utf-8?q?1770869278515828888?= 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_64/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-frame-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 before call */ - "call main\n" /* main() returns the status code, we'll exit with it. */ - "mov %eax, %edi\n" /* retrieve exit code (32 bit) */ - "mov $60, %eax\n" /* NR_exit == 60 */ - "syscall\n" /* really exit */ - "hlt\n" /* ensure it does not return */ + "xor %ebp, %ebp\n" /* zero the stack frame */ + "mov %rsp, %rdi\n" /* save stack pointer to %rdi, as arg1 of _start_c */ + "and $-16, %rsp\n" /* %rsp must be 16-byte aligned before call */ + "call _start_c\n" /* transfer to c runtime */ + "hlt\n" /* ensure it does not return */ ); __builtin_unreachable(); + } #endif /* _NOLIBC_X86_64_CRT_H */