Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7430900rwl; Tue, 10 Jan 2023 00:16:50 -0800 (PST) X-Google-Smtp-Source: AMrXdXtNsij6yjVEEczkx0JTCJ0hcBlETkP/kBDd4U2W5RVGjPZzVLtMrruWlx43HHQkyajxuXTi X-Received: by 2002:a05:6402:f17:b0:489:5852:fbb5 with SMTP id i23-20020a0564020f1700b004895852fbb5mr39842370eda.16.1673338610308; Tue, 10 Jan 2023 00:16:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673338610; cv=none; d=google.com; s=arc-20160816; b=J8ivYoSuLlvNVrqQyVxDe1r8F4NeFcrOx/Nqi5GeFj+6e9+VfchnXKk0iXYvk+e8pn R2sV4/HM2m7wAkZuz2VLM5nLA8SSu/aXz84VEJR5iHVDlUaqPE84ApVUA+uFh+W85j4O Io2XUzmmRgQ8+YQzL0YNLcsntih/xwjrxPy1vdLPcp8mKJqUVkg7ZXmubaTBYqz/6N79 5qOSxMCyJqsWpQP329V9PllALLRqk3VGmT+AVei3daSdEUZXn4XFh+8UshsBo60Fg+ga sl+uvX+htpE1hUrKVE6RhkZwqbKQVHfRY+sgQ5dXkqpETUsLKzBQEgHNkFhn3sa9tHMX uxKA== 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=2o97gx3vAAucIxl09hxICgH08EcHe4WNZNSNhyDJUs8=; b=L8qodbVXb5gcXDQRZ8JGIifRuGjFLepNWOqtJOz56kLYvG2Fdtjg2Im84z6JWGPG4Q lV/FaaS5DV7tpz/tcTriwhPGStrezvgQXKNf77Tc07xxClJ9ixvjfX1LKTBdIxsFzxIZ RI78neMB/nmJAWjq08lztYM4JUyWsvUnZ/LofMsxfjzPzuKv0lGk76HyhOozfJ+6Fg0R +GPmsptTjEcAlKUqW0EIhi1dJ02hkyHjZxblKtSYJ+2ECVg9SZbaS/CB/NetrKkvkpxA ZhHIGCdHBEhcivpMy9aVrkebxRL4BZwebzsrlriC/gPV3YoMAuk2N4FwOpXR7jRwX1Dm FgDw== 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 o17-20020aa7c7d1000000b0047035379d79si10571049eds.556.2023.01.10.00.16.37; Tue, 10 Jan 2023 00:16:50 -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 S237885AbjAJHaD (ORCPT + 53 others); Tue, 10 Jan 2023 02:30:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237952AbjAJH3b (ORCPT ); Tue, 10 Jan 2023 02:29:31 -0500 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7C76453704 for ; Mon, 9 Jan 2023 23:27:06 -0800 (PST) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 30A7Odop003941; 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 14/22] tools/nolibc: add auxiliary vector retrieval for x86_64 Date: Tue, 10 Jan 2023 08:24:26 +0100 Message-Id: <20230110072434.3863-15-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 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-x86_64.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/include/nolibc/arch-x86_64.h b/tools/include/nolibc/arch-x86_64.h index 683702a16a61..17f6751208e7 100644 --- a/tools/include/nolibc/arch-x86_64.h +++ b/tools/include/nolibc/arch-x86_64.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 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) -- 2.17.5