Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7409707rwl; Mon, 9 Jan 2023 23:56:01 -0800 (PST) X-Google-Smtp-Source: AMrXdXsErfqzm7NWMCBrcsioUOl4OJScTw1g4r9hi6qJbromiApNXh4sj7RlTdsqoXg0Uie3BMCw X-Received: by 2002:a17:903:1091:b0:192:4904:afae with SMTP id u17-20020a170903109100b001924904afaemr55267932pld.24.1673337360932; Mon, 09 Jan 2023 23:56:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673337360; cv=none; d=google.com; s=arc-20160816; b=RB/VR6fpcpDVwksfIAknHacwSr7OQ4wkUjXEdE/O787Id+pxjBWq9be3MB19cyravE jWpLrxf26AcNwoAHHPdFrUzwtkmFf4/S/J6YUluDY8MGNNU6PnjAxSC0u5rpHaQRoF4W R3Vpds5M7QGvCirXq4T44kxcCa134WkxGnoxfy92/MZ5be+Bhiq/Kf0Wp7gN6jw5Pbff 9hpiR0xbRwS7eAbCyPJBP/vos1M0RuhpymVDaOGxcbAiPrb1r381lIzB5SaBT3yxEYj7 fqy/kwaQEuT6y9YU1JUgEZw6x3Lobj/vEjiQiWly4dOlj5FxbkRd5WiEpgy5fxEVfmrO Qz/w== 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=S4XS/maGf+EUDbl4Z5m+2naWzBs8nk+mNqdUbfzl9nw=; b=ftW0Js9/FfHyD8QHsKntWvGXzln11lZvFFAGODecNRMFNYP85uOuQ/YO6SfzFnhuy+ 1R/DlZXq+BLZA4pOQlKYHyz+8cNMrrGE5W1/+BkUh1r3AQEOZufy2kkDK3L4qKos0Vu/ //3hYU4Wc/i2/AbG5Qgt7jcsSPivzdcK8WkMcubErvnvTAOjdB/PZQYjUpMjLl1RB4Bt 7LnxS/HEhe2wyZKbaSMa8krfAXiOw12AtvR8IRo18kXys6bQ4Pd6t3+E9Y+jX+973ywZ A6pMu27v11pPk+MGqr29DDeoUEXIUexx+cfQzRKqBWHdn/hI6O97ibIM7MP9deRD0MyQ hgsQ== 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 z6-20020a170903018600b001787f1922a7si12015204plg.19.2023.01.09.23.55.54; Mon, 09 Jan 2023 23:56:00 -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 S235172AbjAJHZL (ORCPT + 53 others); Tue, 10 Jan 2023 02:25:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230177AbjAJHZB (ORCPT ); Tue, 10 Jan 2023 02:25:01 -0500 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7DBA949160 for ; Mon, 9 Jan 2023 23:24:53 -0800 (PST) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 30A7OdnY003943; 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 16/22] tools/nolibc: add auxiliary vector retrieval for arm Date: Tue, 10 Jan 2023 08:24:28 +0100 Message-Id: <20230110072434.3863-17-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 It was tested in arm, thumb1 and thumb2 modes. --- tools/include/nolibc/arch-arm.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tools/include/nolibc/arch-arm.h b/tools/include/nolibc/arch-arm.h index 79666b590e87..42499f23e73c 100644 --- a/tools/include/nolibc/arch-arm.h +++ b/tools/include/nolibc/arch-arm.h @@ -197,6 +197,7 @@ struct sys_stat_struct { }) char **environ __attribute__((weak)); +const unsigned long *_auxv __attribute__((weak)); /* startup code */ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void) @@ -211,6 +212,16 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void) "ldr %r3, 1f\n" // r3 = &environ (see below) "str %r2, [r3]\n" // store envp into environ + "mov r4, r2\n" // search for auxv (follows NULL after last env) + "0:\n" + "mov r5, r4\n" // r5 = r4 + "add r4, r4, #4\n" // r4 += 4 + "ldr r5,[r5]\n" // r5 = *r5 = *(r4-4) + "cmp r5, #0\n" // and stop at NULL after last env + "bne 0b\n" + "ldr %r3, 2f\n" // r3 = &_auxv (low bits) + "str r4, [r3]\n" // store r4 into _auxv + "mov %r3, $8\n" // AAPCS : sp must be 8-byte aligned in the "neg %r3, %r3\n" // callee, and bl doesn't push (lr=pc) "and %r3, %r3, %r1\n" // so we do sp = r1(=sp) & r3(=-8); @@ -222,6 +233,8 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void) ".align 2\n" // below are the pointers to a few variables "1:\n" ".word environ\n" + "2:\n" + ".word _auxv\n" ); __builtin_unreachable(); } -- 2.17.5