Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp5894995rwl; Mon, 9 Jan 2023 01:02:09 -0800 (PST) X-Google-Smtp-Source: AMrXdXvT3C8osXj4RTSrSxZ35jO0KlhMC4lnJHloSFwy3Ok7dspjPqJgRAOvuq71Ni1zauaE+BGm X-Received: by 2002:a17:907:c712:b0:7bd:6372:fdb4 with SMTP id ty18-20020a170907c71200b007bd6372fdb4mr75611347ejc.41.1673254928987; Mon, 09 Jan 2023 01:02:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673254928; cv=none; d=google.com; s=arc-20160816; b=gVqYiFZni9/r9vqDbrNwZVQbz/3xZKZuODoLuhkuAVVzBy30fowNcTIEzkPz6AqguP f1L/zhyunMXnW7uyINwOu1MW7A/wkHP1BwRG1FhYGG0CGK45NLlaNIBZNLrbKXSZty36 dBaaVY19DNQNPlfM5JAsqnw8TfUBwDr0EPqmkesaxjxXHYiFYaVb/wkdTjTe0jbuxy6C Bf+OaxX6levb9K+G3XGJlv9kxh32SGRGEjuMuxZYJaKENuuPp0VyGqtcNhQlVPgWXRxC QyDDqYOFvDowY1zlW4TWPlg2mBNrz5Pea8ZbLs3xuw/PRg6fBypDANiJijzuM57dbVuC uZ3w== 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=iV/ieYMeuCaoyjfpp90ruwD9n3af0GhC9Ub7E6nkEFuD/w0BdyVTr7xehVev0qJPZI +Yv6Jib4gweCK47JzB8g7vmuwJWU5vPqOcPGFpjTYy2+KslK7RceI+BLfvQSB1dqB2bd 22Wlo/RsMhSjecV49LWizIzuFTyGhrxNmPG2xyl1w+SWWH7WjSfdIomUYLL8Y6+7LSqf xzwapOaup3R/J+74Ty3tFvGseSS1wWrSGnj5lvpUixZdVI5NHM2OXCvH+wCXvtT7A0Oo a5F/QLAj89uxWrDYbtCqdNuwhTDurZupOLa70XAI5fJGR/YHAF6ELaas2bdGlF2mrApd +QYQ== 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 hd41-20020a17090796a900b007c0c0d7c4c8si9121203ejc.44.2023.01.09.01.01.55; Mon, 09 Jan 2023 01:02:08 -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 S236740AbjAIIo5 (ORCPT + 56 others); Mon, 9 Jan 2023 03:44:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236812AbjAIIms (ORCPT ); Mon, 9 Jan 2023 03:42:48 -0500 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5C6F813F49 for ; Mon, 9 Jan 2023 00:42:36 -0800 (PST) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 3098gE6N027433; Mon, 9 Jan 2023 09:42:14 +0100 From: Willy Tarreau To: "Paul E. McKenney" Cc: linux-kernel@vger.kernel.org, Willy Tarreau Subject: [PATCH 14/22] tools/nolibc: add auxiliary vector retrieval for x86_64 Date: Mon, 9 Jan 2023 09:42:00 +0100 Message-Id: <20230109084208.27355-15-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-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