Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp5912904rwl; Mon, 9 Jan 2023 01:20:29 -0800 (PST) X-Google-Smtp-Source: AMrXdXs9zkmMnST+XM9gZRGLqOjqdchMoh66ztENTITLpOzE1kT9BOOT9DM40dQMSKrvYpWXu7Fu X-Received: by 2002:a05:6402:4150:b0:47e:1b4a:5491 with SMTP id x16-20020a056402415000b0047e1b4a5491mr56731279eda.20.1673256029019; Mon, 09 Jan 2023 01:20:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673256029; cv=none; d=google.com; s=arc-20160816; b=Lu0iUOff5rJMCP5EJcu9llBVb5vaSMt0xvx1wl51ZyT4bude+2KJOvFU4XuS+xqs1e BJnidQKkTXCJRL8yGm9+elzrk6FhzwxKYhMXpKJGRjmbARIrrR/O7zrtePjIaPqX/aJZ 6BrVJzomCjjj6M86AXtgoO58SGoGegCVUUpOr+/dhPH2OaJ39geS3cxtJGH8IYnQ0BaX 9QqeSyv0uyXkjp3mYiDs0nB98WljsDtQDcSCszTLI4d+ZwtFso1/ezlit5QXR/h216aK BiUxf15hrQdpQyE16iy3uNqkxrzI2AFYwUqm/vwrgDOHftw0ZobI5+PQt0+Kyl4QHldo wh7w== 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=rYtmQVQzbB0JuKH436Xftsg2aFDd++3OJhA461dgIxhDVeB/4dulLT2zBupbOY7ogR 6hzh3vWxGiwQBv4v/OeMEfhkrvgfvKLejjEOn/si5RQs8/Njfq6FR4WoLP0AArxoI3Wc SfbeVmzVN/nX1gfA3GJCCpj+WXR37LgaiGIFPc46DAfZuo7l4VHy7m1GA/Ntn0RmYG6c 8jm3uk4zB2DUO/f/HjPwk15UpBj1e6cBwVLKs3PvTe9F5B6nLnzYeCnGyp26x3oUVCa+ scow7Pc1yklsjA2+w0mlD/hhKM4aSF3JgYtUdDDyVwpMLlFYQbaiAWbu7zvIuSVFMjBR uQWA== 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 h10-20020a056402280a00b00443088b40b7si11378822ede.123.2023.01.09.01.20.14; Mon, 09 Jan 2023 01:20:29 -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 S236932AbjAIInj (ORCPT + 54 others); Mon, 9 Jan 2023 03:43:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235659AbjAIIm3 (ORCPT ); Mon, 9 Jan 2023 03:42:29 -0500 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 20EAF13F64 for ; Mon, 9 Jan 2023 00:42:27 -0800 (PST) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 3098gDGl027432; Mon, 9 Jan 2023 09:42:13 +0100 From: Willy Tarreau To: "Paul E. McKenney" Cc: linux-kernel@vger.kernel.org, Willy Tarreau Subject: [PATCH 13/22] tools/nolibc: add auxiliary vector retrieval for i386 Date: Mon, 9 Jan 2023 09:41:59 +0100 Message-Id: <20230109084208.27355-14-w@1wt.eu> X-Mailer: git-send-email 2.17.5 In-Reply-To: <20230109084208.27355-1-w@1wt.eu> References: <20230109084208.27355-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 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 -- 2.17.5