From patchwork Tue Jan 10 07:24:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Willy Tarreau X-Patchwork-Id: 41316 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2602349wrt; Mon, 9 Jan 2023 23:26:57 -0800 (PST) X-Google-Smtp-Source: AMrXdXsjsKqme37JA0ORbtVY0/aAQzwkyCK35etBV+TxfkjGEGikKZR50HteMtvd9OiRqCpPFSCg X-Received: by 2002:a17:90b:3557:b0:219:bd64:8e60 with SMTP id lt23-20020a17090b355700b00219bd648e60mr71698540pjb.34.1673335617152; Mon, 09 Jan 2023 23:26:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673335617; cv=none; d=google.com; s=arc-20160816; b=z0eHdyN9SNHGNoV/u7TARdtUCtkzl7tcK7xpTB9MjaFJP+FPDIXwFsZDEgk9+BjiG2 ODc4m6w5QM08jpQQ4jGa/hZngVHZRPJfvos6Rl/CeD//Gmu96HlXJ2x9CehEC7WLfVZv hEQo0OB4GWxYmrN1sKJvymGlZQbgjDu8G+4myc2wh0GecqKRSLEAS3HCXPQy/iR1T0uf Nq3HhM2IATUyFl5rUMAcPnmx9vXGDQ62w942jkkMbDEDeE9mD3NKgCVnSiL4n/dk8D/8 Fn+dRwq8cxP7XzLNf5VkdaRCq1+MCIm+eUX0tHWqoB+qmCplaAXGBfFUfbBbr3YDgHYc oWVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=EHxnPe0LEfd6o21akm0SqVhKBTmZKFZUHiNlzkjitu4=; b=LabMies7lxmblr7Zk62oa55urgirMJeXFi+umOq16VGUsFn/ImBKBOuNY3rM1OQwze DF4aV6DIyHCbs9I56bzK7kmN5bKmSxFV2k9Qb8nMB1yTBxlpJG4kDFKdA91zHBvkH+gn vzdLf3S1tm4vnftETKZvbZMiWpP6TaP9IXd8TCyYgkNQ02bElzE2TpiQsXTwnP98Czxh nlpPUSrAsWQQTS1UCSsg8LdEsm5BEpJoCJzPa4NLI7vOv5Pl2wM9J/iL5gOSruZCwVv2 rths1IDN3z0+wepfMr5dsJzPXymVC7Lxob4qpOzmBmtPjurMF0p2aLYeeA8YWQEj2TVc LJHQ== 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 lb12-20020a17090b4a4c00b002194ca43255si12160548pjb.50.2023.01.09.23.26.44; Mon, 09 Jan 2023 23:26:57 -0800 (PST) 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 S230312AbjAJHZr (ORCPT + 99 others); Tue, 10 Jan 2023 02:25:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237597AbjAJHZZ (ORCPT ); Tue, 10 Jan 2023 02:25:25 -0500 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8E5294915C for ; Mon, 9 Jan 2023 23:25:08 -0800 (PST) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 30A7OcxI003940; Tue, 10 Jan 2023 08:24:39 +0100 From: Willy Tarreau To: "Paul E. McKenney" Cc: linux-kernel@vger.kernel.org, Willy Tarreau Subject: [PATCH v2 13/22] tools/nolibc: add auxiliary vector retrieval for i386 Date: Tue, 10 Jan 2023 08:24:25 +0100 Message-Id: <20230110072434.3863-14-w@1wt.eu> X-Mailer: git-send-email 2.17.5 In-Reply-To: <20230110072434.3863-1-w@1wt.eu> References: <20230110072434.3863-1-w@1wt.eu> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS 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?1754619568306680846?= X-GMAIL-MSGID: =?utf-8?q?1754619568306680846?= In the _start block we now iterate over envp to find the auxiliary vector after the NULL. The pointer is saved into an _auxv variable that is marked as weak so that it's accessible from multiple units. Signed-off-by: Willy Tarreau --- tools/include/nolibc/arch-i386.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/include/nolibc/arch-i386.h b/tools/include/nolibc/arch-i386.h index 60b586120727..e8d0cf545bf1 100644 --- a/tools/include/nolibc/arch-i386.h +++ b/tools/include/nolibc/arch-i386.h @@ -179,6 +179,7 @@ struct sys_stat_struct { }) char **environ __attribute__((weak)); +const unsigned long *_auxv __attribute__((weak)); /* startup code */ /* @@ -195,6 +196,12 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void) "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