Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7410333rwl; Mon, 9 Jan 2023 23:56:52 -0800 (PST) X-Google-Smtp-Source: AMrXdXtORqphdAHJR51oRGYEQ1LYjvSNTWWfL3HNpN9xFRjNGGkmQTGdRXSD5Hj00ePoJiRIT6jo X-Received: by 2002:a05:6a00:4c82:b0:582:8d34:7253 with SMTP id eb2-20020a056a004c8200b005828d347253mr29527158pfb.20.1673337412117; Mon, 09 Jan 2023 23:56:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673337412; cv=none; d=google.com; s=arc-20160816; b=lHb8c2fRaQChvGqupy9md5qDgbXtbPTicndB2b3jVWhzn6YCiWGCQr+4rMVGHrlY05 ID63SoBl1eMgar1EWqnnVgeDWS2MuW5UxI2QXKLKnbPN8y2RARDbat2EvDmgjp+0GgI1 TK/xFVmIXTOr/FNUhw0unYy5bFa294HwEaskIKCN/v+1Ru+F6T9SVqebfxADqxbj6T61 Y8uIduAbRi60JvzKiojykFZaXRAONocgUc13oCGrGo2H5TpfKcjnWrDj6oSiw4azKpsF FWyY1yGSK4uo0Mewd0BvNptD0W5JgWyGoiczNyjLJoJ7eOtEasfJAuEQqpQSdrqRseaM XJ9w== 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=5zMlOt74cQnFQHDnTkFunnAOUin+NAK3pV2mpt8G4iA=; b=JhF1h6NucYrZCwJZPMhNIYnYnGGHN9OK5a84y9Df2BJKcp5HsFWKxmu441QGzdKrBI aOEdvb5ybJUoAXSx77GnQzGAk5+7W/0Rh4uO/i/m97uepZXfSbglkSEhlpRG5GkAlsK7 oCu3tXU/EFabvinAuLOb6x1h7eL4EbDHRYycmCoBCjgD8ahom2sb+Z+4q1rFijf0L2PU IpBpox0ch8tm4DS9QF06pei43wtYZN5U0OwXvZDKzxG+9WkiFxIlsOV82aU2F0aPNb10 tY7IGs4m8S9Jru7i+0Js4iJkEWExftTp6ZFeOiyUGzOQWPhuy2pd9gIvBGn5CJxLY+jO wjww== 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 t20-20020a056a0021d400b00582d07e6db7si12360117pfj.6.2023.01.09.23.56.45; Mon, 09 Jan 2023 23:56:52 -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 S237858AbjAJH2X (ORCPT + 53 others); Tue, 10 Jan 2023 02:28:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237832AbjAJH1i (ORCPT ); Tue, 10 Jan 2023 02:27:38 -0500 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2B5B9B86B for ; Mon, 9 Jan 2023 23:26:11 -0800 (PST) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 30A7OcFv003935; 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 08/22] tools/nolibc: export environ as a weak symbol on arm64 Date: Tue, 10 Jan 2023 08:24:20 +0100 Message-Id: <20230110072434.3863-9-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 both with environ inherited from _start and extracted from envp. Signed-off-by: Willy Tarreau --- tools/include/nolibc/arch-aarch64.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/include/nolibc/arch-aarch64.h b/tools/include/nolibc/arch-aarch64.h index f480993159ec..2e3d9adc4c4c 100644 --- a/tools/include/nolibc/arch-aarch64.h +++ b/tools/include/nolibc/arch-aarch64.h @@ -169,6 +169,8 @@ struct sys_stat_struct { _arg1; \ }) +char **environ __attribute__((weak)); + /* startup code */ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void) { @@ -178,6 +180,8 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void) "lsl x2, x0, 3\n" // envp (x2) = 8*argc ... "add x2, x2, 8\n" // + 8 (skip null) "add x2, x2, x1\n" // + argv + "adrp x3, environ\n" // x3 = &environ (high bits) + "str x2, [x3, #:lo12:environ]\n" // store envp into environ "and sp, x1, -16\n" // sp must be 16-byte aligned in the callee "bl main\n" // main() returns the status code, we'll exit with it. "mov x8, 93\n" // NR_exit == 93 -- 2.17.5