From patchwork Tue Jan 10 07:24:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Willy Tarreau X-Patchwork-Id: 41325 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2602867wrt; Mon, 9 Jan 2023 23:28:36 -0800 (PST) X-Google-Smtp-Source: AMrXdXsfJHjoH9JlaH5vIIVB39EF/SPuCHUEi9YvtpzPA0kp338WSKUbQ1+zZJqXsTysnbHnZ1F1 X-Received: by 2002:a62:1b42:0:b0:581:eca3:fd05 with SMTP id b63-20020a621b42000000b00581eca3fd05mr38113398pfb.16.1673335715150; Mon, 09 Jan 2023 23:28:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673335715; cv=none; d=google.com; s=arc-20160816; b=zS0T4tVsEf/+VUlpp3bL1ri/U6W49dpGW7IDr5dUW5S1FP3r1rLm4QRhXfeVZd1KOV DHtV4f7fu9GHV0Vn8nA1LIl+jZFtsL10TI0BQQXBAHZO/r5WGaFbfyRvx5RfTbSOPi9m Dzz6RnTrr1zkdlCk7ne5qLgxAyqVUPK5OvxXruSTKXAKUW0Y3Jv+rJOuxasX/2HuTeHn o0GSrrOa/4Ih8uv/HF+Qdgl5lFH9qNiIYbEBirz0XvDyfgkA6nHyXemZuFAN8D57fp41 RU3QIl0G+iOG2K6fefR3On/mFHe4jLl0tl0f3WDVB3aGujy4dNOV+iF0REJEgjTb3Buq faWQ== 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=5baS9e94+s3bR5xvkWrdQk4kSeX5K0xUhMvUMgQjFBI=; b=Qy9cWt/UxMyU+EYaly3MhZpLyw+aTxxXImYC2l0HtI827NvLwLPE2A9FceqWNlK+i5 OFq5avSu7EZL9pWtcRNyeKtZeq2F/Jz2e8sQVwiwoCcyVp1w3+MpNOpzhSmvilpQCnv8 dB5T9ReLVluGsEgRnnyfKPck5M9xnhlEadVe4p0+rchW5lv84MoH7rc59LoA6YvxeNBC DcUkidgIsuc/ZtuG+p6kjXrNFdqxmLJBe63AI82VodT5vFsWcFDVchxNYbtMo3YLzqTl KMM1uAXgNix++968Sv65ds1OSXQzajiqa8p7WP5SA34U2nSNRG+koRWxpqbcgMzgacQR 3POA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ct24-20020a056a000f9800b0057881f4a31fsi11020456pfb.137.2023.01.09.23.28.23; Mon, 09 Jan 2023 23:28:35 -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 S237727AbjAJH1e (ORCPT + 99 others); Tue, 10 Jan 2023 02:27:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237854AbjAJH1K (ORCPT ); Tue, 10 Jan 2023 02:27:10 -0500 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0C9CCBA0 for ; Mon, 9 Jan 2023 23:25:54 -0800 (PST) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 30A7Obfv003933; Tue, 10 Jan 2023 08:24:37 +0100 From: Willy Tarreau To: "Paul E. McKenney" Cc: linux-kernel@vger.kernel.org, Willy Tarreau Subject: [PATCH v2 06/22] tools/nolibc: export environ as a weak symbol on x86_64 Date: Tue, 10 Jan 2023 08:24:18 +0100 Message-Id: <20230110072434.3863-7-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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754619670830026337?= X-GMAIL-MSGID: =?utf-8?q?1754619670830026337?= 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-x86_64.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/include/nolibc/arch-x86_64.h b/tools/include/nolibc/arch-x86_64.h index 8d482505c347..683702a16a61 100644 --- a/tools/include/nolibc/arch-x86_64.h +++ b/tools/include/nolibc/arch-x86_64.h @@ -178,6 +178,8 @@ struct sys_stat_struct { _ret; \ }) +char **environ __attribute__((weak)); + /* startup code */ /* * x86-64 System V ABI mandates: @@ -191,6 +193,7 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void) "pop %rdi\n" // argc (first arg, %rdi) "mov %rsp, %rsi\n" // argv[] (second arg, %rsi) "lea 8(%rsi,%rdi,8),%rdx\n" // then a NULL then envp (third arg, %rdx) + "mov %rdx, environ\n" // save environ "xor %ebp, %ebp\n" // zero the stack frame "and $-16, %rsp\n" // x86 ABI : esp must be 16-byte aligned before call "call main\n" // main() returns the status code, we'll exit with it.