Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7418821rwl; Tue, 10 Jan 2023 00:04:39 -0800 (PST) X-Google-Smtp-Source: AMrXdXs7QOXZN3kU4aJXuJrJzm1GNOptxwIOM1+FEZmc7qbaoKJ+MPlHANBBFkX3cGhwdmK1iPuv X-Received: by 2002:a05:6402:530d:b0:47e:f535:e9a0 with SMTP id eo13-20020a056402530d00b0047ef535e9a0mr56383313edb.24.1673337879525; Tue, 10 Jan 2023 00:04:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673337879; cv=none; d=google.com; s=arc-20160816; b=ei8v5eZs5wmpA9BQ9TxQ0P9+vusqXPHvhDKdfzSRtJ+YlKX96knsRgLXAPu6hooxYT /YweP4jgjVZiNI8D0wAPso6YI9QWoF/FYgDtR56tNH24+hZTlrXag9TsjXBReIu9WZKH ef1tZlGsr+fPTHkY8MkV62tp6zZ5BHYx1n2rGlGepRQolSVHIw/2CQKf+U0fTk3yvEpo t/+DDiA0mKh4edBfkKyCk1Jm9Sbxx8RTziN6/zUVuUJ9yiIy171xq3lux3XZAZo2RFK9 aP3krg8GcyzAPo+ixF48VDFaWnj+zvHAyNFwuDLWbLNhrl9WInaLTf+J9vdkLH37C9QR N7nQ== 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=2PakoP/R0gv6P5CG7WgyzC4RUZZWPwEw6lNssPPXIE0=; b=bgbrWMjSn16vdGcltXfnlFA0ouxyiNO1dKIbCbh084Sdi+XEy5WsI33Ryb1mlq8jVn t0cTf+0iVjCTjrASyjF+ZtJy0lhG772cUnrSXuUUR+lLVvZQoXljifPvDNm9uJa8vjSZ x13IVI4u+s4HJI1xEhxSaVR6sSPpqe9ClHEuunJTkVJ9Q1EoY6/f9GWmmKMAYDLAawh0 TsW395X1P2lqiR3wGp51ZoEYsYMSa3gqeeD30tSsRnxNRDQ3gCYvHMzHwyQEHBv2T71n qnSM+GUGcv2SimXgu8+ZJniaXXHrGQaqpz8gQi7iZTI+OmzVVVi+qyWJSEIgOCBGHJd/ YDNg== 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 i9-20020a0564020f0900b0048371af9a90si11569279eda.397.2023.01.10.00.04.26; Tue, 10 Jan 2023 00:04:39 -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 S237748AbjAJH3K (ORCPT + 53 others); Tue, 10 Jan 2023 02:29:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237664AbjAJH2o (ORCPT ); Tue, 10 Jan 2023 02:28:44 -0500 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8DC9B4FCC2 for ; Mon, 9 Jan 2023 23:26:35 -0800 (PST) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 30A7OcXA003936; Tue, 10 Jan 2023 08:24:38 +0100 From: Willy Tarreau To: "Paul E. McKenney" Cc: linux-kernel@vger.kernel.org, Willy Tarreau Subject: [PATCH v2 09/22] tools/nolibc: export environ as a weak symbol on arm Date: Tue, 10 Jan 2023 08:24:21 +0100 Message-Id: <20230110072434.3863-10-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 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-arm.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; \ }) +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 = (argc + 1) ... "lsl %r2, %r2, $2\n" // * 4 ... "add %r2, %r2, %r1\n" // + argv + "ldr %r3, 1f\n" // r3 = &environ (see below) + "str %r2, [r3]\n" // store envp into environ "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) @@ -215,7 +219,10 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void) "bl main\n" // main() returns the status code, we'll exit with it. "movs r7, $1\n" // NR_exit == 1 "svc $0x00\n" - ); + ".align 2\n" // below are the pointers to a few variables + "1:\n" + ".word environ\n" + ); __builtin_unreachable(); } -- 2.17.5