Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7400850rwl; Mon, 9 Jan 2023 23:45:37 -0800 (PST) X-Google-Smtp-Source: AMrXdXspEVfifTeAYLcgAzeSdMAE/d+eglZcHA5BGozIU+kMLhvKs5DISStfY5V9TDsAa1m8YAMi X-Received: by 2002:a17:90a:6c88:b0:227:252c:7d26 with SMTP id y8-20020a17090a6c8800b00227252c7d26mr3646676pjj.8.1673336737581; Mon, 09 Jan 2023 23:45:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673336737; cv=none; d=google.com; s=arc-20160816; b=Jjfeu7MRshZudgBsFBDU9VTZfj5yjkzXACTYrUWyHanqM+ZGVZYHSBLGnQv3eh1Xze Vnf04ZdSVrpLmuJLXJ2OWeQlzJlInHdePab/o+d6pkl8cctB3KMJdeVSIC/JfjN/kGks Xa0TOMoYOjcxjk3AMWaGGZL107Q0uNNtveqtUT+XpOa+a5rEjv/xsYUhlzNGXZ/EAsgh 0rp3TCBqDrDycYIit9epCjuI17+1EfBORB3BrFN+tLoRtEs73HQ4NjC92k0+/7n3Av/i 8+H5Mv1w9l8TV2T1a/E81nFTfvNrAKDLS/MrSdSua2bTjjcsvH0SYNl0VzEpMWvJTYld PQXQ== 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=+kGb+G4+QayoVCS4jM2wFsYvYZPok+bVn4CB1miyWk8=; b=D1KqIwtpRmxMY1KJS2msMoopntHquymE9LMaA973MwMff5nnliEID6QFT9G8/EzZFV gIx0mGZcG3DU1rCgD8rXSH/LbuO/FmT8k7jewERi3u5LOppkiCwR4TFa2s5cHsiy3I8R OJ+t5SU+ql3uN0md5IV6KkaEyhNhWrGtUf1lHoUt32dXiI3Is2harqLRQbF+Zx2g7Uuv f4B0e4YC7L4tX8cxq4LV0mwfk6t6EVhxNlOjIrbEDir66GjWzshY9QYkLZSzhgDVS3DU eI+V9gGX+qTfXVR+HZ+m1YqpMQXnPo73YjTUKp9J4TnqVZPikpE9EKYNIZCc3aU24cg3 3yHw== 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 bg2-20020a17090b0d8200b00225a37e6dc9si14486759pjb.4.2023.01.09.23.45.28; Mon, 09 Jan 2023 23:45:37 -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 S237862AbjAJH3w (ORCPT + 55 others); Tue, 10 Jan 2023 02:29:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237835AbjAJH3X (ORCPT ); Tue, 10 Jan 2023 02:29:23 -0500 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 193C453711 for ; Mon, 9 Jan 2023 23:27:02 -0800 (PST) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 30A7OcjL003938; 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 11/22] tools/nolibc: export environ as a weak symbol on riscv Date: Tue, 10 Jan 2023 08:24:23 +0100 Message-Id: <20230110072434.3863-12-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 on riscv64 both with environ inherited from _start and extracted from envp. Signed-off-by: Willy Tarreau --- tools/include/nolibc/arch-riscv.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/include/nolibc/arch-riscv.h b/tools/include/nolibc/arch-riscv.h index c2b5db383d96..1608e6bd94b9 100644 --- a/tools/include/nolibc/arch-riscv.h +++ b/tools/include/nolibc/arch-riscv.h @@ -170,6 +170,8 @@ struct sys_stat_struct { _arg1; \ }) +char **environ __attribute__((weak)); + /* startup code */ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void) { @@ -183,6 +185,8 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void) "slli a2, a0, "PTRLOG"\n" // envp (a2) = SZREG*argc ... "add a2, a2, "SZREG"\n" // + SZREG (skip null) "add a2,a2,a1\n" // + argv + "lui a3, %hi(environ)\n" // a3 = &environ (high bits) + "sd a2,%lo(environ)(a3)\n" // store envp(a2) into environ "andi sp,a1,-16\n" // sp must be 16-byte aligned "call main\n" // main() returns the status code, we'll exit with it. "li a7, 93\n" // NR_exit == 93 -- 2.17.5