Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7430412rwl; Tue, 10 Jan 2023 00:16:19 -0800 (PST) X-Google-Smtp-Source: AMrXdXtC1HLd2hN2pm0CjQuvcjNXCnP4B4tr9rFl6eQWFqQp6rHBnBjQNXAdxHwJU6NloLrLQqQc X-Received: by 2002:a17:906:9f07:b0:7ec:27d7:1838 with SMTP id fy7-20020a1709069f0700b007ec27d71838mr72887887ejc.22.1673338579367; Tue, 10 Jan 2023 00:16:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673338579; cv=none; d=google.com; s=arc-20160816; b=zUvgq532aR39wC8RKHOvB3zlS+e96kLFaPH3PrLqFDWPCg9ZYXE2njeF1swwyq4xaL N//kJ1WASIvXxlIOM0aYMa/nzg80zJbe+A+N81neo2chmg26Jr6XrfgNefo/3riv0/WI MFNXNMCH0YBWqk//L4n+kUXY1HH48nu2y14bsgjiEWVjHTg5wFHqbNGNn8sypI/Seiog rV2PBNlF3rP9wW4deU2Bf5Pa0xgdtqQgdOUktz4FSTTzfxJeEMEh6w+4+DgrvmZh5Oz3 //oFEvBYT26m8KqHBvfnLqWuJicdm295Z4wtdcA2lPflwoG4ycYJUlLDUhBejTltMNiI 6ntA== 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=erAxCIz/7mL2jdlpQGGkw10TQhsUi5FAR4sLsjQFAx0=; b=D+rNZ55+PzCbslqdP7ZrHe8r1AgE37WP3MQYKqotV+Y+swKHd1im1wzfOFaOfXRmI5 X10tx2ZqcEzGTuqMF+2Pe7DZD9g/O/VGdZdGz6Ekd+UIfMbDmQ7U+XP+FQfHwARxtHX+ rJthvRH2ebNiKlRuhf/GGu1lZzTcA684vwgQ+/x0GKPGdTE1CRADUf/0bqEswlxpQpNb 85E3RrzlOHDb6x90WyunOYVH832AF+vu5mMXLolDKFB5RIet2qPJ/AOg/HHn91AHgHmZ I0MvGL8PJSQH+rs25NY2g2tHdKw59NDEsF0MccJhHa13GR3LbHsi2XEgDgK1pfiqlasq a2Lg== 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 xg11-20020a170907320b00b00715867834e3si11557080ejb.506.2023.01.10.00.16.06; Tue, 10 Jan 2023 00:16:19 -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 S237980AbjAJH3g (ORCPT + 53 others); Tue, 10 Jan 2023 02:29:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237970AbjAJH3C (ORCPT ); Tue, 10 Jan 2023 02:29:02 -0500 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AC9AF496E4 for ; Mon, 9 Jan 2023 23:26:51 -0800 (PST) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 30A7Oc7V003937; 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 10/22] tools/nolibc: export environ as a weak symbol on mips Date: Tue, 10 Jan 2023 08:24:22 +0100 Message-Id: <20230110072434.3863-11-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 with mips24kc (BE) both with environ inherited from _start and extracted from envp. Signed-off-by: Willy Tarreau --- tools/include/nolibc/arch-mips.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-mips.h index a3764f6d267e..7d22f7bc38b3 100644 --- a/tools/include/nolibc/arch-mips.h +++ b/tools/include/nolibc/arch-mips.h @@ -176,6 +176,8 @@ struct sys_stat_struct { _arg4 ? -_num : _num; \ }) +char **environ __attribute__((weak)); + /* startup code, note that it's called __start on MIPS */ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __start(void) { @@ -191,6 +193,9 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __start(void) "sll $a2, $a0, 2\n" // a2 = argc * 4 "add $a2, $a2, $a1\n" // envp = argv + 4*argc ... "addiu $a2, $a2, 4\n" // ... + 4 + "lui $a3, %hi(environ)\n" // load environ into a3 (hi) + "addiu $a3, %lo(environ)\n" // load environ into a3 (lo) + "sw $a2,($a3)\n" // store envp(a2) into environ "li $t0, -8\n" "and $sp, $sp, $t0\n" // sp must be 8-byte aligned "addiu $sp,$sp,-16\n" // the callee expects to save a0..a3 there! -- 2.17.5