From nobody Fri Dec 19 18:53:50 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6498C5479D for ; Mon, 9 Jan 2023 08:49:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236852AbjAIIts (ORCPT ); Mon, 9 Jan 2023 03:49:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236943AbjAIIsV (ORCPT ); Mon, 9 Jan 2023 03:48:21 -0500 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C43B5167DF for ; Mon, 9 Jan 2023 00:43:47 -0800 (PST) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 3098gDS7027428; 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 09/22] tools/nolibc: export environ as a weak symbol on arm Date: Mon, 9 Jan 2023 09:41:55 +0100 Message-Id: <20230109084208.27355-10-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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The environ is retrieved from the _start code and is easy to store at this moment. Let's declare the variable weak and store the value into it. By not being static it will be visible to all units. By being weak, if some programs already declared it, they will continue to be able to use it. This was tested in arm and thumb1 and thumb2 modes, and for each mode, both with environ inherited from _start and extracted from envp. Signed-off-by: Willy Tarreau --- tools/include/nolibc/arch-arm.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/include/nolibc/arch-arm.h b/tools/include/nolibc/arch-ar= m.h index 48bd95492c87..79666b590e87 100644 --- a/tools/include/nolibc/arch-arm.h +++ b/tools/include/nolibc/arch-arm.h @@ -196,6 +196,8 @@ struct sys_stat_struct { _arg1; \ }) =20 +char **environ __attribute__((weak)); + /* startup code */ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(= void) { @@ -206,6 +208,8 @@ void __attribute__((weak,noreturn,optimize("omit-frame-= pointer"))) _start(void) "add %r2, %r0, $1\n" // envp =3D (argc + 1) ... "lsl %r2, %r2, $2\n" // * 4 ... "add %r2, %r2, %r1\n" // + argv + "ldr %r3, 1f\n" // r3 =3D &environ (see below) + "str %r2, [r3]\n" // store envp into environ =20 "mov %r3, $8\n" // AAPCS : sp must be 8-byte aligned in the "neg %r3, %r3\n" // callee, and bl doesn't push (lr= =3Dpc) @@ -215,7 +219,10 @@ void __attribute__((weak,noreturn,optimize("omit-frame= -pointer"))) _start(void) "bl main\n" // main() returns the status code, we'll e= xit with it. "movs r7, $1\n" // NR_exit =3D=3D 1 "svc $0x00\n" - ); + ".align 2\n" // below are the pointers to a few variabl= es + "1:\n" + ".word environ\n" + ); __builtin_unreachable(); } =20 --=20 2.17.5