Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7410090rwl; Mon, 9 Jan 2023 23:56:31 -0800 (PST) X-Google-Smtp-Source: AMrXdXsy/IBLXpudayVwmCx7ZBGH7jZ+DsEEtsV8WJ/liCMQ167AnVIYW8EvvpWWh1AipvV/9HbL X-Received: by 2002:a17:902:6bcb:b0:192:eb8d:4d62 with SMTP id m11-20020a1709026bcb00b00192eb8d4d62mr19502316plt.13.1673337390993; Mon, 09 Jan 2023 23:56:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673337390; cv=none; d=google.com; s=arc-20160816; b=K18AJ6AG7j2H4Hd3ZAQTUnn2JT+lPw6YCaBzNYhY25QVtrYNW7DzszbOVmikccMOAU usggck1I2L1WqCIkys96JYyLdRBk11zDMf+Grn+IFSD0B/5lBGKkuSYnR1Eg0bnpuKrE iE4/H+Otmc2st7e4lDA+VVZX04EaiMpxCjOk2fpk0ts8S4fJCMsnw7v/MbxfD4iH/on8 K+Y3fBYxDmZHnFFTqhtyh9uITZ3S4DcbZnYbGYpH8uVdYy3WR6kAOmxnhRyI9GDAfBBZ G4iv/CQRfRAVVtGLbh4Xv6uIPlXMbj+Yhdv2TFKy1iLNmBnoTNGYenQDJnyXaZLtnUFh ICzg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z6-20020a170903018600b001787f1922a7si12015204plg.19.2023.01.09.23.56.24; Mon, 09 Jan 2023 23:56:30 -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 + 53 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 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. -- 2.17.5